1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun drivers/net/ethernet/dec/tulip/eeprom.c
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun Copyright 2000,2001 The Linux Kernel Team
5*4882a593Smuzhiyun Written/copyright 1994-2001 by Donald Becker.
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun This software may be used and distributed according to the terms
8*4882a593Smuzhiyun of the GNU General Public License, incorporated herein by reference.
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun Please submit bug reports to http://bugzilla.kernel.org/.
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/pci.h>
14*4882a593Smuzhiyun #include <linux/slab.h>
15*4882a593Smuzhiyun #include "tulip.h"
16*4882a593Smuzhiyun #include <asm/unaligned.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /* Serial EEPROM section. */
21*4882a593Smuzhiyun /* The main routine to parse the very complicated SROM structure.
22*4882a593Smuzhiyun Search www.digital.com for "21X4 SROM" to get details.
23*4882a593Smuzhiyun This code is very complex, and will require changes to support
24*4882a593Smuzhiyun additional cards, so I'll be verbose about what is going on.
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /* Known cards that have old-style EEPROMs. */
28*4882a593Smuzhiyun static struct eeprom_fixup eeprom_fixups[] = {
29*4882a593Smuzhiyun {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c,
30*4882a593Smuzhiyun 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }},
31*4882a593Smuzhiyun {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f,
32*4882a593Smuzhiyun 0x0000, 0x009E, /* 10baseT */
33*4882a593Smuzhiyun 0x0004, 0x009E, /* 10baseT-FD */
34*4882a593Smuzhiyun 0x0903, 0x006D, /* 100baseTx */
35*4882a593Smuzhiyun 0x0905, 0x006D, /* 100baseTx-FD */ }},
36*4882a593Smuzhiyun {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f,
37*4882a593Smuzhiyun 0x0107, 0x8021, /* 100baseFx */
38*4882a593Smuzhiyun 0x0108, 0x8021, /* 100baseFx-FD */
39*4882a593Smuzhiyun 0x0100, 0x009E, /* 10baseT */
40*4882a593Smuzhiyun 0x0104, 0x009E, /* 10baseT-FD */
41*4882a593Smuzhiyun 0x0103, 0x006D, /* 100baseTx */
42*4882a593Smuzhiyun 0x0105, 0x006D, /* 100baseTx-FD */ }},
43*4882a593Smuzhiyun {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513,
44*4882a593Smuzhiyun 0x1001, 0x009E, /* 10base2, CSR12 0x10*/
45*4882a593Smuzhiyun 0x0000, 0x009E, /* 10baseT */
46*4882a593Smuzhiyun 0x0004, 0x009E, /* 10baseT-FD */
47*4882a593Smuzhiyun 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */
48*4882a593Smuzhiyun 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}},
49*4882a593Smuzhiyun {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F,
50*4882a593Smuzhiyun 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */
51*4882a593Smuzhiyun 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */
52*4882a593Smuzhiyun 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */
53*4882a593Smuzhiyun 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */
54*4882a593Smuzhiyun 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */
55*4882a593Smuzhiyun }},
56*4882a593Smuzhiyun {"NetWinder", 0x00, 0x10, 0x57,
57*4882a593Smuzhiyun /* Default media = MII
58*4882a593Smuzhiyun * MII block, reset sequence (3) = 0x0821 0x0000 0x0001, capabilities 0x01e1
59*4882a593Smuzhiyun */
60*4882a593Smuzhiyun { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 }
61*4882a593Smuzhiyun },
62*4882a593Smuzhiyun {"Cobalt Microserver", 0, 0x10, 0xE0, {0x1e00, /* 0 == controller #, 1e == offset */
63*4882a593Smuzhiyun 0x0000, /* 0 == high offset, 0 == gap */
64*4882a593Smuzhiyun 0x0800, /* Default Autoselect */
65*4882a593Smuzhiyun 0x8001, /* 1 leaf, extended type, bogus len */
66*4882a593Smuzhiyun 0x0003, /* Type 3 (MII), PHY #0 */
67*4882a593Smuzhiyun 0x0400, /* 0 init instr, 4 reset instr */
68*4882a593Smuzhiyun 0x0801, /* Set control mode, GP0 output */
69*4882a593Smuzhiyun 0x0000, /* Drive GP0 Low (RST is active low) */
70*4882a593Smuzhiyun 0x0800, /* control mode, GP0 input (undriven) */
71*4882a593Smuzhiyun 0x0000, /* clear control mode */
72*4882a593Smuzhiyun 0x7800, /* 100TX FDX + HDX, 10bT FDX + HDX */
73*4882a593Smuzhiyun 0x01e0, /* Advertise all above */
74*4882a593Smuzhiyun 0x5000, /* FDX all above */
75*4882a593Smuzhiyun 0x1800, /* Set fast TTM in 100bt modes */
76*4882a593Smuzhiyun 0x0000, /* PHY cannot be unplugged */
77*4882a593Smuzhiyun }},
78*4882a593Smuzhiyun {NULL}};
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun static const char *const block_name[] = {
82*4882a593Smuzhiyun "21140 non-MII",
83*4882a593Smuzhiyun "21140 MII PHY",
84*4882a593Smuzhiyun "21142 Serial PHY",
85*4882a593Smuzhiyun "21142 MII PHY",
86*4882a593Smuzhiyun "21143 SYM PHY",
87*4882a593Smuzhiyun "21143 reset method"
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun /**
92*4882a593Smuzhiyun * tulip_build_fake_mediatable - Build a fake mediatable entry.
93*4882a593Smuzhiyun * @tp: Ptr to the tulip private data.
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * Some cards like the 3x5 HSC cards (J3514A) do not have a standard
96*4882a593Smuzhiyun * srom and can not be handled under the fixup routine. These cards
97*4882a593Smuzhiyun * still need a valid mediatable entry for correct csr12 setup and
98*4882a593Smuzhiyun * mii handling.
99*4882a593Smuzhiyun *
100*4882a593Smuzhiyun * Since this is currently a parisc-linux specific function, the
101*4882a593Smuzhiyun * #ifdef __hppa__ should completely optimize this function away for
102*4882a593Smuzhiyun * non-parisc hardware.
103*4882a593Smuzhiyun */
tulip_build_fake_mediatable(struct tulip_private * tp)104*4882a593Smuzhiyun static void tulip_build_fake_mediatable(struct tulip_private *tp)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun #ifdef CONFIG_GSC
107*4882a593Smuzhiyun if (tp->flags & NEEDS_FAKE_MEDIA_TABLE) {
108*4882a593Smuzhiyun static unsigned char leafdata[] =
109*4882a593Smuzhiyun { 0x01, /* phy number */
110*4882a593Smuzhiyun 0x02, /* gpr setup sequence length */
111*4882a593Smuzhiyun 0x02, 0x00, /* gpr setup sequence */
112*4882a593Smuzhiyun 0x02, /* phy reset sequence length */
113*4882a593Smuzhiyun 0x01, 0x00, /* phy reset sequence */
114*4882a593Smuzhiyun 0x00, 0x78, /* media capabilities */
115*4882a593Smuzhiyun 0x00, 0xe0, /* nway advertisement */
116*4882a593Smuzhiyun 0x00, 0x05, /* fdx bit map */
117*4882a593Smuzhiyun 0x00, 0x06 /* ttm bit map */
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun tp->mtable = kmalloc(sizeof(struct mediatable) +
121*4882a593Smuzhiyun sizeof(struct medialeaf), GFP_KERNEL);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun if (tp->mtable == NULL)
124*4882a593Smuzhiyun return; /* Horrible, impossible failure. */
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun tp->mtable->defaultmedia = 0x800;
127*4882a593Smuzhiyun tp->mtable->leafcount = 1;
128*4882a593Smuzhiyun tp->mtable->csr12dir = 0x3f; /* inputs on bit7 for hsc-pci, bit6 for pci-fx */
129*4882a593Smuzhiyun tp->mtable->has_nonmii = 0;
130*4882a593Smuzhiyun tp->mtable->has_reset = 0;
131*4882a593Smuzhiyun tp->mtable->has_mii = 1;
132*4882a593Smuzhiyun tp->mtable->csr15dir = tp->mtable->csr15val = 0;
133*4882a593Smuzhiyun tp->mtable->mleaf[0].type = 1;
134*4882a593Smuzhiyun tp->mtable->mleaf[0].media = 11;
135*4882a593Smuzhiyun tp->mtable->mleaf[0].leafdata = &leafdata[0];
136*4882a593Smuzhiyun tp->flags |= HAS_PHY_IRQ;
137*4882a593Smuzhiyun tp->csr12_shadow = -1;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
tulip_parse_eeprom(struct net_device * dev)142*4882a593Smuzhiyun void tulip_parse_eeprom(struct net_device *dev)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun /*
145*4882a593Smuzhiyun dev is not registered at this point, so logging messages can't
146*4882a593Smuzhiyun use dev_<level> or netdev_<level> but dev->name is good via a
147*4882a593Smuzhiyun hack in the caller
148*4882a593Smuzhiyun */
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /* The last media info list parsed, for multiport boards. */
151*4882a593Smuzhiyun static struct mediatable *last_mediatable;
152*4882a593Smuzhiyun static unsigned char *last_ee_data;
153*4882a593Smuzhiyun static int controller_index;
154*4882a593Smuzhiyun struct tulip_private *tp = netdev_priv(dev);
155*4882a593Smuzhiyun unsigned char *ee_data = tp->eeprom;
156*4882a593Smuzhiyun int i;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun tp->mtable = NULL;
159*4882a593Smuzhiyun /* Detect an old-style (SA only) EEPROM layout:
160*4882a593Smuzhiyun memcmp(eedata, eedata+16, 8). */
161*4882a593Smuzhiyun for (i = 0; i < 8; i ++)
162*4882a593Smuzhiyun if (ee_data[i] != ee_data[16+i])
163*4882a593Smuzhiyun break;
164*4882a593Smuzhiyun if (i >= 8) {
165*4882a593Smuzhiyun if (ee_data[0] == 0xff) {
166*4882a593Smuzhiyun if (last_mediatable) {
167*4882a593Smuzhiyun controller_index++;
168*4882a593Smuzhiyun pr_info("%s: Controller %d of multiport board\n",
169*4882a593Smuzhiyun dev->name, controller_index);
170*4882a593Smuzhiyun tp->mtable = last_mediatable;
171*4882a593Smuzhiyun ee_data = last_ee_data;
172*4882a593Smuzhiyun goto subsequent_board;
173*4882a593Smuzhiyun } else
174*4882a593Smuzhiyun pr_info("%s: Missing EEPROM, this interface may not work correctly!\n",
175*4882a593Smuzhiyun dev->name);
176*4882a593Smuzhiyun return;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun /* Do a fix-up based on the vendor half of the station address prefix. */
179*4882a593Smuzhiyun for (i = 0; eeprom_fixups[i].name; i++) {
180*4882a593Smuzhiyun if (dev->dev_addr[0] == eeprom_fixups[i].addr0 &&
181*4882a593Smuzhiyun dev->dev_addr[1] == eeprom_fixups[i].addr1 &&
182*4882a593Smuzhiyun dev->dev_addr[2] == eeprom_fixups[i].addr2) {
183*4882a593Smuzhiyun if (dev->dev_addr[2] == 0xE8 && ee_data[0x1a] == 0x55)
184*4882a593Smuzhiyun i++; /* An Accton EN1207, not an outlaw Maxtech. */
185*4882a593Smuzhiyun memcpy(ee_data + 26, eeprom_fixups[i].newtable,
186*4882a593Smuzhiyun sizeof(eeprom_fixups[i].newtable));
187*4882a593Smuzhiyun pr_info("%s: Old format EEPROM on '%s' board. Using substitute media control info\n",
188*4882a593Smuzhiyun dev->name, eeprom_fixups[i].name);
189*4882a593Smuzhiyun break;
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun if (eeprom_fixups[i].name == NULL) { /* No fixup found. */
193*4882a593Smuzhiyun pr_info("%s: Old style EEPROM with no media selection information\n",
194*4882a593Smuzhiyun dev->name);
195*4882a593Smuzhiyun return;
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun controller_index = 0;
200*4882a593Smuzhiyun if (ee_data[19] > 1) { /* Multiport board. */
201*4882a593Smuzhiyun last_ee_data = ee_data;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun subsequent_board:
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun if (ee_data[27] == 0) { /* No valid media table. */
206*4882a593Smuzhiyun tulip_build_fake_mediatable(tp);
207*4882a593Smuzhiyun } else {
208*4882a593Smuzhiyun unsigned char *p = (void *)ee_data + ee_data[27];
209*4882a593Smuzhiyun unsigned char csr12dir = 0;
210*4882a593Smuzhiyun int count, new_advertise = 0;
211*4882a593Smuzhiyun struct mediatable *mtable;
212*4882a593Smuzhiyun u16 media = get_u16(p);
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun p += 2;
215*4882a593Smuzhiyun if (tp->flags & CSR12_IN_SROM)
216*4882a593Smuzhiyun csr12dir = *p++;
217*4882a593Smuzhiyun count = *p++;
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun /* there is no phy information, don't even try to build mtable */
220*4882a593Smuzhiyun if (count == 0) {
221*4882a593Smuzhiyun if (tulip_debug > 0)
222*4882a593Smuzhiyun pr_warn("%s: no phy info, aborting mtable build\n",
223*4882a593Smuzhiyun dev->name);
224*4882a593Smuzhiyun return;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun mtable = kmalloc(struct_size(mtable, mleaf, count), GFP_KERNEL);
228*4882a593Smuzhiyun if (mtable == NULL)
229*4882a593Smuzhiyun return; /* Horrible, impossible failure. */
230*4882a593Smuzhiyun last_mediatable = tp->mtable = mtable;
231*4882a593Smuzhiyun mtable->defaultmedia = media;
232*4882a593Smuzhiyun mtable->leafcount = count;
233*4882a593Smuzhiyun mtable->csr12dir = csr12dir;
234*4882a593Smuzhiyun mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0;
235*4882a593Smuzhiyun mtable->csr15dir = mtable->csr15val = 0;
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun pr_info("%s: EEPROM default media type %s\n",
238*4882a593Smuzhiyun dev->name,
239*4882a593Smuzhiyun media & 0x0800 ? "Autosense"
240*4882a593Smuzhiyun : medianame[media & MEDIA_MASK]);
241*4882a593Smuzhiyun for (i = 0; i < count; i++) {
242*4882a593Smuzhiyun struct medialeaf *leaf = &mtable->mleaf[i];
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */
245*4882a593Smuzhiyun leaf->type = 0;
246*4882a593Smuzhiyun leaf->media = p[0] & 0x3f;
247*4882a593Smuzhiyun leaf->leafdata = p;
248*4882a593Smuzhiyun if ((p[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */
249*4882a593Smuzhiyun mtable->has_mii = 1;
250*4882a593Smuzhiyun p += 4;
251*4882a593Smuzhiyun } else {
252*4882a593Smuzhiyun leaf->type = p[1];
253*4882a593Smuzhiyun if (p[1] == 0x05) {
254*4882a593Smuzhiyun mtable->has_reset = i;
255*4882a593Smuzhiyun leaf->media = p[2] & 0x0f;
256*4882a593Smuzhiyun } else if (tp->chip_id == DM910X && p[1] == 0x80) {
257*4882a593Smuzhiyun /* Hack to ignore Davicom delay period block */
258*4882a593Smuzhiyun mtable->leafcount--;
259*4882a593Smuzhiyun count--;
260*4882a593Smuzhiyun i--;
261*4882a593Smuzhiyun leaf->leafdata = p + 2;
262*4882a593Smuzhiyun p += (p[0] & 0x3f) + 1;
263*4882a593Smuzhiyun continue;
264*4882a593Smuzhiyun } else if (p[1] & 1) {
265*4882a593Smuzhiyun int gpr_len, reset_len;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun mtable->has_mii = 1;
268*4882a593Smuzhiyun leaf->media = 11;
269*4882a593Smuzhiyun gpr_len=p[3]*2;
270*4882a593Smuzhiyun reset_len=p[4+gpr_len]*2;
271*4882a593Smuzhiyun new_advertise |= get_u16(&p[7+gpr_len+reset_len]);
272*4882a593Smuzhiyun } else {
273*4882a593Smuzhiyun mtable->has_nonmii = 1;
274*4882a593Smuzhiyun leaf->media = p[2] & MEDIA_MASK;
275*4882a593Smuzhiyun /* Davicom's media number for 100BaseTX is strange */
276*4882a593Smuzhiyun if (tp->chip_id == DM910X && leaf->media == 1)
277*4882a593Smuzhiyun leaf->media = 3;
278*4882a593Smuzhiyun switch (leaf->media) {
279*4882a593Smuzhiyun case 0: new_advertise |= 0x0020; break;
280*4882a593Smuzhiyun case 4: new_advertise |= 0x0040; break;
281*4882a593Smuzhiyun case 3: new_advertise |= 0x0080; break;
282*4882a593Smuzhiyun case 5: new_advertise |= 0x0100; break;
283*4882a593Smuzhiyun case 6: new_advertise |= 0x0200; break;
284*4882a593Smuzhiyun }
285*4882a593Smuzhiyun if (p[1] == 2 && leaf->media == 0) {
286*4882a593Smuzhiyun if (p[2] & 0x40) {
287*4882a593Smuzhiyun u32 base15 = get_unaligned((u16*)&p[7]);
288*4882a593Smuzhiyun mtable->csr15dir =
289*4882a593Smuzhiyun (get_unaligned((u16*)&p[9])<<16) + base15;
290*4882a593Smuzhiyun mtable->csr15val =
291*4882a593Smuzhiyun (get_unaligned((u16*)&p[11])<<16) + base15;
292*4882a593Smuzhiyun } else {
293*4882a593Smuzhiyun mtable->csr15dir = get_unaligned((u16*)&p[3])<<16;
294*4882a593Smuzhiyun mtable->csr15val = get_unaligned((u16*)&p[5])<<16;
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun }
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun leaf->leafdata = p + 2;
299*4882a593Smuzhiyun p += (p[0] & 0x3f) + 1;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun if (tulip_debug > 1 && leaf->media == 11) {
302*4882a593Smuzhiyun unsigned char *bp = leaf->leafdata;
303*4882a593Smuzhiyun pr_info("%s: MII interface PHY %d, setup/reset sequences %d/%d long, capabilities %02x %02x\n",
304*4882a593Smuzhiyun dev->name,
305*4882a593Smuzhiyun bp[0], bp[1], bp[2 + bp[1]*2],
306*4882a593Smuzhiyun bp[5 + bp[2 + bp[1]*2]*2],
307*4882a593Smuzhiyun bp[4 + bp[2 + bp[1]*2]*2]);
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun pr_info("%s: Index #%d - Media %s (#%d) described by a %s (%d) block\n",
310*4882a593Smuzhiyun dev->name,
311*4882a593Smuzhiyun i, medianame[leaf->media & 15], leaf->media,
312*4882a593Smuzhiyun leaf->type < ARRAY_SIZE(block_name) ? block_name[leaf->type] : "<unknown>",
313*4882a593Smuzhiyun leaf->type);
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun if (new_advertise)
316*4882a593Smuzhiyun tp->sym_advertise = new_advertise;
317*4882a593Smuzhiyun }
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun /* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun /* EEPROM_Ctrl bits. */
322*4882a593Smuzhiyun #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
323*4882a593Smuzhiyun #define EE_CS 0x01 /* EEPROM chip select. */
324*4882a593Smuzhiyun #define EE_DATA_WRITE 0x04 /* Data from the Tulip to EEPROM. */
325*4882a593Smuzhiyun #define EE_WRITE_0 0x01
326*4882a593Smuzhiyun #define EE_WRITE_1 0x05
327*4882a593Smuzhiyun #define EE_DATA_READ 0x08 /* Data from the EEPROM chip. */
328*4882a593Smuzhiyun #define EE_ENB (0x4800 | EE_CS)
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun /* Delay between EEPROM clock transitions.
331*4882a593Smuzhiyun Even at 33Mhz current PCI implementations don't overrun the EEPROM clock.
332*4882a593Smuzhiyun We add a bus turn-around to insure that this remains true. */
333*4882a593Smuzhiyun #define eeprom_delay() ioread32(ee_addr)
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun /* The EEPROM commands include the alway-set leading bit. */
336*4882a593Smuzhiyun #define EE_READ_CMD (6)
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun /* Note: this routine returns extra data bits for size detection. */
tulip_read_eeprom(struct net_device * dev,int location,int addr_len)339*4882a593Smuzhiyun int tulip_read_eeprom(struct net_device *dev, int location, int addr_len)
340*4882a593Smuzhiyun {
341*4882a593Smuzhiyun int i;
342*4882a593Smuzhiyun unsigned retval = 0;
343*4882a593Smuzhiyun struct tulip_private *tp = netdev_priv(dev);
344*4882a593Smuzhiyun void __iomem *ee_addr = tp->base_addr + CSR9;
345*4882a593Smuzhiyun int read_cmd = location | (EE_READ_CMD << addr_len);
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun /* If location is past the end of what we can address, don't
348*4882a593Smuzhiyun * read some other location (ie truncate). Just return zero.
349*4882a593Smuzhiyun */
350*4882a593Smuzhiyun if (location > (1 << addr_len) - 1)
351*4882a593Smuzhiyun return 0;
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun iowrite32(EE_ENB & ~EE_CS, ee_addr);
354*4882a593Smuzhiyun iowrite32(EE_ENB, ee_addr);
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun /* Shift the read command bits out. */
357*4882a593Smuzhiyun for (i = 4 + addr_len; i >= 0; i--) {
358*4882a593Smuzhiyun short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
359*4882a593Smuzhiyun iowrite32(EE_ENB | dataval, ee_addr);
360*4882a593Smuzhiyun eeprom_delay();
361*4882a593Smuzhiyun iowrite32(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
362*4882a593Smuzhiyun eeprom_delay();
363*4882a593Smuzhiyun retval = (retval << 1) | ((ioread32(ee_addr) & EE_DATA_READ) ? 1 : 0);
364*4882a593Smuzhiyun }
365*4882a593Smuzhiyun iowrite32(EE_ENB, ee_addr);
366*4882a593Smuzhiyun eeprom_delay();
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun for (i = 16; i > 0; i--) {
369*4882a593Smuzhiyun iowrite32(EE_ENB | EE_SHIFT_CLK, ee_addr);
370*4882a593Smuzhiyun eeprom_delay();
371*4882a593Smuzhiyun retval = (retval << 1) | ((ioread32(ee_addr) & EE_DATA_READ) ? 1 : 0);
372*4882a593Smuzhiyun iowrite32(EE_ENB, ee_addr);
373*4882a593Smuzhiyun eeprom_delay();
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun /* Terminate the EEPROM access. */
377*4882a593Smuzhiyun iowrite32(EE_ENB & ~EE_CS, ee_addr);
378*4882a593Smuzhiyun return (tp->flags & HAS_SWAPPED_SEEPROM) ? swab16(retval) : retval;
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun
381