update b44 driver for brcm-2.4 and 2.6, fix #214
[openwrt.git] / openwrt / target / linux / brcm-2.4 / patches / 008-b44_bcm47xx_support.patch
1 diff -urN linux.old/drivers/net/b44.c linux.dev/drivers/net/b44.c
2 --- linux.old/drivers/net/b44.c 2006-01-16 21:10:55.873911750 +0100
3 +++ linux.dev/drivers/net/b44.c 2006-01-16 21:16:02.041046000 +0100
4 @@ -1,7 +1,9 @@
5 /* b44.c: Broadcom 4400 device driver.
6 *
7 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
8 - * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
9 + * Copyright (C) 2004 Pekka Pietikainen (pp@ee.oulu.fi)
10 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
11 + * Copyright (C) 2006 Felix Fietkau (nbd@openwrt.org)
12 *
13 * Distribute under GPL.
14 */
15 @@ -25,6 +27,41 @@
16
17 #include "b44.h"
18
19 +#include <typedefs.h>
20 +#include <bcmdevs.h>
21 +#include <bcmutils.h>
22 +#include <osl.h>
23 +#include <bcmutils.h>
24 +#include <bcmnvram.h>
25 +#include <sbconfig.h>
26 +#include <sbchipc.h>
27 +#include <sflash.h>
28 +
29 +#ifdef CONFIG_BCM947XX
30 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
31 +
32 +static inline void e_aton(char *str, char *dest)
33 +{
34 + int i = 0;
35 + u16 *d = (u16 *) dest;
36 +
37 + if (str == NULL) {
38 + memset(dest, 0, 6);
39 + return;
40 + }
41 +
42 + for (;;) {
43 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
44 + str += 2;
45 + if (!*str++ || i == 6)
46 + break;
47 + }
48 +}
49 +
50 +static int instance = 0;
51 +#endif
52 +
53 +
54 #define DRV_MODULE_NAME "b44"
55 #define PFX DRV_MODULE_NAME ": "
56 #define DRV_MODULE_VERSION "0.93"
57 @@ -75,7 +112,7 @@
58 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
59
60 MODULE_AUTHOR("David S. Miller (davem@redhat.com)");
61 -MODULE_DESCRIPTION("Broadcom 4400 10/100 PCI ethernet driver");
62 +MODULE_DESCRIPTION("Broadcom 4400/47xx 10/100 PCI ethernet driver");
63 MODULE_LICENSE("GPL");
64 MODULE_PARM(b44_debug, "i");
65 MODULE_PARM_DESC(b44_debug, "B44 bitmapped debugging message enable value");
66 @@ -89,6 +126,8 @@
67 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
68 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4401B1,
69 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
70 + { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_BCM4713,
71 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
72 { } /* terminate list with empty entry */
73 };
74
75 @@ -236,6 +275,8 @@
76 udelay(1);
77 }
78
79 +static int b44_4713_instance;
80 +
81 static int ssb_core_unit(struct b44 *bp)
82 {
83 #if 0
84 @@ -258,6 +299,9 @@
85 break;
86 };
87 #endif
88 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
89 + return b44_4713_instance++;
90 + else
91 return 0;
92 }
93
94 @@ -267,6 +311,28 @@
95 == SBTMSLOW_CLOCK);
96 }
97
98 +static inline void __b44_cam_read(struct b44 *bp, unsigned char *data, int index)
99 +{
100 + u32 val;
101 +
102 + bw32(B44_CAM_CTRL, (CAM_CTRL_READ |
103 + (index << CAM_CTRL_INDEX_SHIFT)));
104 +
105 + b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1);
106 +
107 + val = br32(B44_CAM_DATA_LO);
108 +
109 + data[2] = (val >> 24) & 0xFF;
110 + data[3] = (val >> 16) & 0xFF;
111 + data[4] = (val >> 8) & 0xFF;
112 + data[5] = (val >> 0) & 0xFF;
113 +
114 + val = br32(B44_CAM_DATA_HI);
115 +
116 + data[0] = (val >> 8) & 0xFF;
117 + data[1] = (val >> 0) & 0xFF;
118 +}
119 +
120 static void __b44_cam_write(struct b44 *bp, unsigned char *data, int index)
121 {
122 u32 val;
123 @@ -303,14 +369,14 @@
124 bw32(B44_IMASK, bp->imask);
125 }
126
127 -static int b44_readphy(struct b44 *bp, int reg, u32 *val)
128 +static int __b44_readphy(struct b44 *bp, int phy_addr, int reg, u32 *val)
129 {
130 int err;
131
132 bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
133 bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
134 (MDIO_OP_READ << MDIO_DATA_OP_SHIFT) |
135 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
136 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
137 (reg << MDIO_DATA_RA_SHIFT) |
138 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT)));
139 err = b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
140 @@ -319,23 +385,42 @@
141 return err;
142 }
143
144 -static int b44_writephy(struct b44 *bp, int reg, u32 val)
145 +static int b44_readphy(struct b44 *bp, int reg, u32 *val)
146 +{
147 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
148 + return 0;
149 +
150 + return __b44_readphy(bp, bp->phy_addr, reg, val);
151 +}
152 +
153 +static int __b44_writephy(struct b44 *bp, int phy_addr, int reg, u32 val)
154 {
155 bw32(B44_EMAC_ISTAT, EMAC_INT_MII);
156 bw32(B44_MDIO_DATA, (MDIO_DATA_SB_START |
157 (MDIO_OP_WRITE << MDIO_DATA_OP_SHIFT) |
158 - (bp->phy_addr << MDIO_DATA_PMD_SHIFT) |
159 + (phy_addr << MDIO_DATA_PMD_SHIFT) |
160 (reg << MDIO_DATA_RA_SHIFT) |
161 (MDIO_TA_VALID << MDIO_DATA_TA_SHIFT) |
162 (val & MDIO_DATA_DATA)));
163 return b44_wait_bit(bp, B44_EMAC_ISTAT, EMAC_INT_MII, 100, 0);
164 }
165
166 +static int b44_writephy(struct b44 *bp, int reg, u32 val)
167 +{
168 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
169 + return 0;
170 +
171 + return __b44_writephy(bp, bp->phy_addr, reg, val);
172 +}
173 +
174 static int b44_phy_reset(struct b44 *bp)
175 {
176 u32 val;
177 int err;
178
179 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
180 + return 0;
181 +
182 err = b44_writephy(bp, MII_BMCR, BMCR_RESET);
183 if (err)
184 return err;
185 @@ -405,6 +490,24 @@
186 {
187 u32 val;
188 int err;
189 + char *s;
190 +
191 +#ifdef CONFIG_BCM947XX
192 + /*
193 + * workaround for bad hardware design in Linksys WAP54G v1.0
194 + * see https://dev.openwrt.org/ticket/146
195 + * check and reset bit "isolate"
196 + */
197 + if ((bp->pdev->device == PCI_DEVICE_ID_BCM4713) &&
198 + (atoi(nvram_get("boardnum")) == 2) &&
199 + (__b44_readphy(bp, 0, MII_BMCR, &val) == 0) &&
200 + (val & BMCR_ISOLATE) &&
201 + (__b44_writephy(bp, 0, MII_BMCR, val & ~BMCR_ISOLATE) != 0)) {
202 + printk(KERN_WARNING PFX "PHY: cannot reset MII transceiver isolate bit.\n");
203 + }
204 +#endif
205 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY)
206 + return 0;
207
208 if ((err = b44_readphy(bp, B44_MII_ALEDCTRL, &val)) != 0)
209 goto out;
210 @@ -498,6 +601,19 @@
211 {
212 u32 bmsr, aux;
213
214 + if (bp->phy_addr == B44_PHY_ADDR_NO_PHY) {
215 + bp->flags |= B44_FLAG_100_BASE_T;
216 + bp->flags |= B44_FLAG_FULL_DUPLEX;
217 + if (!netif_carrier_ok(bp->dev)) {
218 + u32 val = br32(B44_TX_CTRL);
219 + val |= TX_CTRL_DUPLEX;
220 + bw32(B44_TX_CTRL, val);
221 + netif_carrier_on(bp->dev);
222 + b44_link_report(bp);
223 + }
224 + return;
225 + }
226 +
227 if (!b44_readphy(bp, MII_BMSR, &bmsr) &&
228 !b44_readphy(bp, B44_MII_AUXCTRL, &aux) &&
229 (bmsr != 0xffff)) {
230 @@ -1092,6 +1208,8 @@
231 /* bp->lock is held. */
232 static void b44_chip_reset(struct b44 *bp)
233 {
234 + unsigned int sb_clock;
235 +
236 if (ssb_is_core_up(bp)) {
237 bw32(B44_RCV_LAZY, 0);
238 bw32(B44_ENET_CTRL, ENET_CTRL_DISABLE);
239 @@ -1105,9 +1223,10 @@
240 bw32(B44_DMARX_CTRL, 0);
241 bp->rx_prod = bp->rx_cons = 0;
242 } else {
243 - ssb_pci_setup(bp, (bp->core_unit == 0 ?
244 - SBINTVEC_ENET0 :
245 - SBINTVEC_ENET1));
246 + /*if (bp->pdev->device != PCI_DEVICE_ID_BCM4713)*/
247 + ssb_pci_setup(bp, (bp->core_unit == 0 ?
248 + SBINTVEC_ENET0 :
249 + SBINTVEC_ENET1));
250 }
251
252 ssb_core_reset(bp);
253 @@ -1115,6 +1234,11 @@
254 b44_clear_stats(bp);
255
256 /* Make PHY accessible. */
257 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713)
258 + sb_clock = 100000000; /* 100 MHz */
259 + else
260 + sb_clock = 62500000; /* 62.5 MHz */
261 +
262 bw32(B44_MDIO_CTRL, (MDIO_CTRL_PREAMBLE |
263 (0x0d & MDIO_CTRL_MAXF_MASK)));
264 br32(B44_MDIO_CTRL);
265 @@ -1628,7 +1752,7 @@
266 u32 mii_regval;
267
268 spin_lock_irq(&bp->lock);
269 - err = b44_readphy(bp, data->reg_num & 0x1f, &mii_regval);
270 + err = __b44_readphy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, &mii_regval);
271 spin_unlock_irq(&bp->lock);
272
273 data->val_out = mii_regval;
274 @@ -1641,7 +1765,7 @@
275 return -EPERM;
276
277 spin_lock_irq(&bp->lock);
278 - err = b44_writephy(bp, data->reg_num & 0x1f, data->val_in);
279 + err = __b44_writephy(bp, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in);
280 spin_unlock_irq(&bp->lock);
281
282 return err;
283 @@ -1668,21 +1792,52 @@
284 static int __devinit b44_get_invariants(struct b44 *bp)
285 {
286 u8 eeprom[128];
287 + u8 buf[32];
288 int err;
289 + unsigned long flags;
290
291 - err = b44_read_eeprom(bp, &eeprom[0]);
292 - if (err)
293 - goto out;
294 + if (bp->pdev->device == PCI_DEVICE_ID_BCM4713) {
295 + /*
296 + * BCM47xx boards don't have a EEPROM. The MAC is stored in
297 + * a NVRAM area somewhere in the flash memory.
298 + */
299 + sprintf(buf, "et%dmacaddr", b44_4713_instance);
300 + if (nvram_get(buf)) {
301 + e_aton(nvram_get(buf), bp->dev->dev_addr);
302 + } else {
303 + /*
304 + * Getting the MAC out of NVRAM failed. To make it work
305 + * here, we simply rely on the bootloader to write the
306 + * MAC into the CAM.
307 + */
308 + spin_lock_irqsave(&bp->lock, flags);
309 + __b44_cam_read(bp, bp->dev->dev_addr, 0);
310 + spin_unlock_irqrestore(&bp->lock, flags);
311 + }
312
313 - bp->dev->dev_addr[0] = eeprom[79];
314 - bp->dev->dev_addr[1] = eeprom[78];
315 - bp->dev->dev_addr[2] = eeprom[81];
316 - bp->dev->dev_addr[3] = eeprom[80];
317 - bp->dev->dev_addr[4] = eeprom[83];
318 - bp->dev->dev_addr[5] = eeprom[82];
319
320 - bp->phy_addr = eeprom[90] & 0x1f;
321 - bp->mdc_port = (eeprom[90] >> 14) & 0x1;
322 + /*
323 + * BCM47xx boards don't have a PHY. Usually there is a switch
324 + * chip with multiple PHYs connected to the PHY port.
325 + */
326 + bp->phy_addr = B44_PHY_ADDR_NO_PHY;
327 + bp->dma_offset = 0;
328 + } else {
329 + err = b44_read_eeprom(bp, &eeprom[0]);
330 + if (err)
331 + return err;
332 +
333 + bp->dev->dev_addr[0] = eeprom[79];
334 + bp->dev->dev_addr[1] = eeprom[78];
335 + bp->dev->dev_addr[2] = eeprom[81];
336 + bp->dev->dev_addr[3] = eeprom[80];
337 + bp->dev->dev_addr[4] = eeprom[83];
338 + bp->dev->dev_addr[5] = eeprom[82];
339 +
340 + bp->phy_addr = eeprom[90] & 0x1f;
341 + bp->dma_offset = SB_PCI_DMA;
342 + bp->mdc_port = (eeprom[90] >> 14) & 0x1;
343 + }
344
345 /* With this, plus the rx_header prepended to the data by the
346 * hardware, we'll land the ethernet header on a 2-byte boundary.
347 @@ -1692,13 +1847,12 @@
348 bp->imask = IMASK_DEF;
349
350 bp->core_unit = ssb_core_unit(bp);
351 - bp->dma_offset = ssb_get_addr(bp, SBID_PCI_DMA, 0);
352
353 /* XXX - really required?
354 bp->flags |= B44_FLAG_BUGGY_TXPTR;
355 */
356 -out:
357 - return err;
358 +
359 + return 0;
360 }
361
362 static int __devinit b44_init_one(struct pci_dev *pdev,
363 @@ -1710,6 +1864,10 @@
364 struct b44 *bp;
365 int err, i;
366
367 +#ifdef CONFIG_BCM947XX
368 + instance++;
369 +#endif
370 +
371 if (b44_version_printed++ == 0)
372 printk(KERN_INFO "%s", version);
373
374 @@ -1819,11 +1977,17 @@
375
376 pci_save_state(bp->pdev, bp->pci_cfg_state);
377
378 - printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
379 + printk(KERN_INFO "%s: Broadcom %s 10/100BaseT Ethernet ", dev->name,
380 + (pdev->device == PCI_DEVICE_ID_BCM4713) ? "47xx" : "4400");
381 for (i = 0; i < 6; i++)
382 printk("%2.2x%c", dev->dev_addr[i],
383 i == 5 ? '\n' : ':');
384
385 + /* Initialize phy */
386 + spin_lock_irq(&bp->lock);
387 + b44_chip_reset(bp);
388 + spin_unlock_irq(&bp->lock);
389 +
390 return 0;
391
392 err_out_iounmap:
393 diff -urN linux.old/drivers/net/b44.h linux.dev/drivers/net/b44.h
394 --- linux.old/drivers/net/b44.h 2006-01-16 21:10:55.881912250 +0100
395 +++ linux.dev/drivers/net/b44.h 2006-01-16 21:02:38.018249750 +0100
396 @@ -229,8 +229,6 @@
397 #define SBIPSFLAG_IMASK4 0x3f000000 /* Which sbflags --> mips interrupt 4 */
398 #define SBIPSFLAG_ISHIFT4 24
399 #define B44_SBTPSFLAG 0x0F18UL /* SB Target Port OCP Slave Flag */
400 -#define SBTPS_NUM0_MASK 0x0000003f
401 -#define SBTPS_F0EN0 0x00000040
402 #define B44_SBADMATCH3 0x0F60UL /* SB Address Match 3 */
403 #define B44_SBADMATCH2 0x0F68UL /* SB Address Match 2 */
404 #define B44_SBADMATCH1 0x0F70UL /* SB Address Match 1 */
405 @@ -461,6 +459,8 @@
406 };
407
408 #define B44_MCAST_TABLE_SIZE 32
409 +#define B44_PHY_ADDR_NO_PHY 30
410 +#define B44_MDC_RATIO 5000000
411
412 /* SW copy of device statistics, kept up to date by periodic timer
413 * which probes HW values. Must have same relative layout as HW
414 diff -urN linux.old/include/linux/pci_ids.h linux.dev/include/linux/pci_ids.h
415 --- linux.old/include/linux/pci_ids.h 2006-01-16 21:10:55.901913500 +0100
416 +++ linux.dev/include/linux/pci_ids.h 2006-01-16 21:02:38.034250750 +0100
417 @@ -1741,6 +1741,7 @@
418 #define PCI_DEVICE_ID_TIGON3_5901_2 0x170e
419 #define PCI_DEVICE_ID_BCM4401 0x4401
420 #define PCI_DEVICE_ID_BCM4401B0 0x4402
421 +#define PCI_DEVICE_ID_BCM4713 0x4713
422
423 #define PCI_VENDOR_ID_ENE 0x1524
424 #define PCI_DEVICE_ID_ENE_1211 0x1211
This page took 0.074705 seconds and 5 git commands to generate.