4a6952476157c76a58b3a0a96ccca0aaf8a2fa3f
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 075-0005-net-ethernet-bgmac-Add-platform-device-support.patch
1 From f6a95a24957aec5bb488c3f978c4ed508177998f Mon Sep 17 00:00:00 2001
2 From: Jon Mason <jon.mason@broadcom.com>
3 Date: Thu, 7 Jul 2016 19:08:57 -0400
4 Subject: [PATCH 5/5] net: ethernet: bgmac: Add platform device support
5
6 The bcma portion of the driver has been split off into a bcma specific
7 driver. This has been mirrored for the platform driver. The last
8 references to the bcma core struct have been changed into a generic
9 function call. These function calls are wrappers to either the original
10 bcma code or new platform functions that access the same areas via MMIO.
11 This necessitated adding function pointers for both platform and bcma to
12 hide which backend is being used from the generic bgmac code.
13
14 Signed-off-by: Jon Mason <jon.mason@broadcom.com>
15 Acked-by: Arnd Bergmann <arnd@arndb.de>
16 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
17 Tested-by: Florian Fainelli <f.fainelli@gmail.com>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
19 ---
20 drivers/net/ethernet/broadcom/Kconfig | 23 +-
21 drivers/net/ethernet/broadcom/Makefile | 4 +-
22 drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 2 +
23 drivers/net/ethernet/broadcom/bgmac-bcma.c | 315 +++++++++++++++++++++++
24 drivers/net/ethernet/broadcom/bgmac-platform.c | 189 ++++++++++++++
25 drivers/net/ethernet/broadcom/bgmac.c | 329 ++++--------------------
26 drivers/net/ethernet/broadcom/bgmac.h | 73 +++++-
27 7 files changed, 650 insertions(+), 285 deletions(-)
28 create mode 100644 drivers/net/ethernet/broadcom/bgmac-bcma.c
29 create mode 100644 drivers/net/ethernet/broadcom/bgmac-platform.c
30
31 --- a/drivers/net/ethernet/broadcom/Kconfig
32 +++ b/drivers/net/ethernet/broadcom/Kconfig
33 @@ -150,10 +150,18 @@ config BNX2X_VXLAN
34 Virtual eXtensible Local Area Network (VXLAN) in the driver.
35
36 config BGMAC
37 - tristate "BCMA bus GBit core support"
38 + tristate
39 + help
40 + This enables the integrated ethernet controller support for many
41 + Broadcom (mostly iProc) SoCs. An appropriate bus interface driver
42 + needs to be enabled to select this.
43 +
44 +config BGMAC_BCMA
45 + tristate "Broadcom iProc GBit BCMA support"
46 depends on BCMA && BCMA_HOST_SOC
47 depends on HAS_DMA
48 depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST
49 + select BGMAC
50 select PHYLIB
51 select FIXED_PHY
52 ---help---
53 @@ -162,6 +170,19 @@ config BGMAC
54 In case of using this driver on BCM4706 it's also requires to enable
55 BCMA_DRIVER_GMAC_CMN to make it work.
56
57 +config BGMAC_PLATFORM
58 + tristate "Broadcom iProc GBit platform support"
59 + depends on HAS_DMA
60 + depends on ARCH_BCM_IPROC || COMPILE_TEST
61 + depends on OF
62 + select BGMAC
63 + select PHYLIB
64 + select FIXED_PHY
65 + default ARCH_BCM_IPROC
66 + ---help---
67 + Say Y here if you want to use the Broadcom iProc Gigabit Ethernet
68 + controller through the generic platform interface
69 +
70 config SYSTEMPORT
71 tristate "Broadcom SYSTEMPORT internal MAC support"
72 depends on OF
73 --- a/drivers/net/ethernet/broadcom/Makefile
74 +++ b/drivers/net/ethernet/broadcom/Makefile
75 @@ -10,6 +10,8 @@ obj-$(CONFIG_CNIC) += cnic.o
76 obj-$(CONFIG_BNX2X) += bnx2x/
77 obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o
78 obj-$(CONFIG_TIGON3) += tg3.o
79 -obj-$(CONFIG_BGMAC) += bgmac.o bgmac-bcma-mdio.o
80 +obj-$(CONFIG_BGMAC) += bgmac.o
81 +obj-$(CONFIG_BGMAC_BCMA) += bgmac-bcma.o bgmac-bcma-mdio.o
82 +obj-$(CONFIG_BGMAC_PLATFORM) += bgmac-platform.o
83 obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o
84 obj-$(CONFIG_BNXT) += bnxt/
85 --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
86 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
87 @@ -255,6 +255,7 @@ err:
88 kfree(bcma_mdio);
89 return ERR_PTR(err);
90 }
91 +EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
92
93 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
94 {
95 @@ -270,6 +271,7 @@ void bcma_mdio_mii_unregister(struct mii
96 mdiobus_free(mii_bus);
97 kfree(bcma_mdio);
98 }
99 +EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
100
101 MODULE_AUTHOR("Rafał Miłecki");
102 MODULE_LICENSE("GPL");
103 --- /dev/null
104 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
105 @@ -0,0 +1,315 @@
106 +/*
107 + * Driver for (BCM4706)? GBit MAC core on BCMA bus.
108 + *
109 + * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
110 + *
111 + * Licensed under the GNU/GPL. See COPYING for details.
112 + */
113 +
114 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
115 +
116 +#include <linux/bcma/bcma.h>
117 +#include <linux/brcmphy.h>
118 +#include <linux/etherdevice.h>
119 +#include "bgmac.h"
120 +
121 +static inline bool bgmac_is_bcm4707_family(struct bcma_device *core)
122 +{
123 + switch (core->bus->chipinfo.id) {
124 + case BCMA_CHIP_ID_BCM4707:
125 + case BCMA_CHIP_ID_BCM47094:
126 + case BCMA_CHIP_ID_BCM53018:
127 + return true;
128 + default:
129 + return false;
130 + }
131 +}
132 +
133 +/**************************************************
134 + * BCMA bus ops
135 + **************************************************/
136 +
137 +static u32 bcma_bgmac_read(struct bgmac *bgmac, u16 offset)
138 +{
139 + return bcma_read32(bgmac->bcma.core, offset);
140 +}
141 +
142 +static void bcma_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
143 +{
144 + bcma_write32(bgmac->bcma.core, offset, value);
145 +}
146 +
147 +static u32 bcma_bgmac_idm_read(struct bgmac *bgmac, u16 offset)
148 +{
149 + return bcma_aread32(bgmac->bcma.core, offset);
150 +}
151 +
152 +static void bcma_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
153 +{
154 + return bcma_awrite32(bgmac->bcma.core, offset, value);
155 +}
156 +
157 +static bool bcma_bgmac_clk_enabled(struct bgmac *bgmac)
158 +{
159 + return bcma_core_is_enabled(bgmac->bcma.core);
160 +}
161 +
162 +static void bcma_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
163 +{
164 + bcma_core_enable(bgmac->bcma.core, flags);
165 +}
166 +
167 +static void bcma_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
168 + u32 mask, u32 set)
169 +{
170 + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
171 +
172 + bcma_chipco_chipctl_maskset(cc, offset, mask, set);
173 +}
174 +
175 +static u32 bcma_bgmac_get_bus_clock(struct bgmac *bgmac)
176 +{
177 + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
178 +
179 + return bcma_pmu_get_bus_clock(cc);
180 +}
181 +
182 +static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask,
183 + u32 set)
184 +{
185 + bcma_maskset32(bgmac->bcma.cmn, offset, mask, set);
186 +}
187 +
188 +static const struct bcma_device_id bgmac_bcma_tbl[] = {
189 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT,
190 + BCMA_ANY_REV, BCMA_ANY_CLASS),
191 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV,
192 + BCMA_ANY_CLASS),
193 + {},
194 +};
195 +MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
196 +
197 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
198 +static int bgmac_probe(struct bcma_device *core)
199 +{
200 + struct ssb_sprom *sprom = &core->bus->sprom;
201 + struct mii_bus *mii_bus;
202 + struct bgmac *bgmac;
203 + u8 *mac;
204 + int err;
205 +
206 + bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL);
207 + if (!bgmac)
208 + return -ENOMEM;
209 +
210 + bgmac->bcma.core = core;
211 + bgmac->dev = &core->dev;
212 + bgmac->dma_dev = core->dma_dev;
213 + bgmac->irq = core->irq;
214 +
215 + bcma_set_drvdata(core, bgmac);
216 +
217 + switch (core->core_unit) {
218 + case 0:
219 + mac = sprom->et0mac;
220 + break;
221 + case 1:
222 + mac = sprom->et1mac;
223 + break;
224 + case 2:
225 + mac = sprom->et2mac;
226 + break;
227 + default:
228 + dev_err(bgmac->dev, "Unsupported core_unit %d\n",
229 + core->core_unit);
230 + err = -ENOTSUPP;
231 + goto err;
232 + }
233 +
234 + ether_addr_copy(bgmac->mac_addr, mac);
235 +
236 + /* On BCM4706 we need common core to access PHY */
237 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
238 + !core->bus->drv_gmac_cmn.core) {
239 + dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n");
240 + err = -ENODEV;
241 + goto err;
242 + }
243 + bgmac->bcma.cmn = core->bus->drv_gmac_cmn.core;
244 +
245 + switch (core->core_unit) {
246 + case 0:
247 + bgmac->phyaddr = sprom->et0phyaddr;
248 + break;
249 + case 1:
250 + bgmac->phyaddr = sprom->et1phyaddr;
251 + break;
252 + case 2:
253 + bgmac->phyaddr = sprom->et2phyaddr;
254 + break;
255 + }
256 + bgmac->phyaddr &= BGMAC_PHY_MASK;
257 + if (bgmac->phyaddr == BGMAC_PHY_MASK) {
258 + dev_err(bgmac->dev, "No PHY found\n");
259 + err = -ENODEV;
260 + goto err;
261 + }
262 + dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr,
263 + bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
264 +
265 + if (!bgmac_is_bcm4707_family(core)) {
266 + mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
267 + if (!IS_ERR(mii_bus)) {
268 + err = PTR_ERR(mii_bus);
269 + goto err;
270 + }
271 +
272 + bgmac->mii_bus = mii_bus;
273 + }
274 +
275 + if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) {
276 + dev_err(bgmac->dev, "PCI setup not implemented\n");
277 + err = -ENOTSUPP;
278 + goto err1;
279 + }
280 +
281 + bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
282 + BGMAC_BFL_ENETROBO);
283 + if (bgmac->has_robosw)
284 + dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n");
285 +
286 + if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM)
287 + dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n");
288 +
289 + /* Feature Flags */
290 + switch (core->bus->chipinfo.id) {
291 + case BCMA_CHIP_ID_BCM5357:
292 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
293 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
294 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
295 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
296 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) {
297 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
298 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
299 + }
300 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358)
301 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII;
302 + break;
303 + case BCMA_CHIP_ID_BCM53572:
304 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
305 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
306 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
307 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
308 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) {
309 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
310 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
311 + }
312 + break;
313 + case BCMA_CHIP_ID_BCM4749:
314 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
315 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
316 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
317 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
318 + if (core->bus->chipinfo.pkg == 10) {
319 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
320 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
321 + }
322 + break;
323 + case BCMA_CHIP_ID_BCM4716:
324 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
325 + /* fallthrough */
326 + case BCMA_CHIP_ID_BCM47162:
327 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2;
328 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
329 + break;
330 + /* bcm4707_family */
331 + case BCMA_CHIP_ID_BCM4707:
332 + case BCMA_CHIP_ID_BCM47094:
333 + case BCMA_CHIP_ID_BCM53018:
334 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
335 + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
336 + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
337 + break;
338 + default:
339 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
340 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
341 + }
342 +
343 + if (!bgmac_is_bcm4707_family(core) && core->id.rev > 2)
344 + bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ;
345 +
346 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT) {
347 + bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL;
348 + bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB;
349 + }
350 +
351 + if (core->id.rev >= 4) {
352 + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
353 + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
354 + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
355 + }
356 +
357 + bgmac->read = bcma_bgmac_read;
358 + bgmac->write = bcma_bgmac_write;
359 + bgmac->idm_read = bcma_bgmac_idm_read;
360 + bgmac->idm_write = bcma_bgmac_idm_write;
361 + bgmac->clk_enabled = bcma_bgmac_clk_enabled;
362 + bgmac->clk_enable = bcma_bgmac_clk_enable;
363 + bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset;
364 + bgmac->get_bus_clock = bcma_bgmac_get_bus_clock;
365 + bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32;
366 +
367 + err = bgmac_enet_probe(bgmac);
368 + if (err)
369 + goto err1;
370 +
371 + return 0;
372 +
373 +err1:
374 + bcma_mdio_mii_unregister(bgmac->mii_bus);
375 +err:
376 + kfree(bgmac);
377 + bcma_set_drvdata(core, NULL);
378 +
379 + return err;
380 +}
381 +
382 +static void bgmac_remove(struct bcma_device *core)
383 +{
384 + struct bgmac *bgmac = bcma_get_drvdata(core);
385 +
386 + bcma_mdio_mii_unregister(bgmac->mii_bus);
387 + bgmac_enet_remove(bgmac);
388 + bcma_set_drvdata(core, NULL);
389 + kfree(bgmac);
390 +}
391 +
392 +static struct bcma_driver bgmac_bcma_driver = {
393 + .name = KBUILD_MODNAME,
394 + .id_table = bgmac_bcma_tbl,
395 + .probe = bgmac_probe,
396 + .remove = bgmac_remove,
397 +};
398 +
399 +static int __init bgmac_init(void)
400 +{
401 + int err;
402 +
403 + err = bcma_driver_register(&bgmac_bcma_driver);
404 + if (err)
405 + return err;
406 + pr_info("Broadcom 47xx GBit MAC driver loaded\n");
407 +
408 + return 0;
409 +}
410 +
411 +static void __exit bgmac_exit(void)
412 +{
413 + bcma_driver_unregister(&bgmac_bcma_driver);
414 +}
415 +
416 +module_init(bgmac_init)
417 +module_exit(bgmac_exit)
418 +
419 +MODULE_AUTHOR("Rafał Miłecki");
420 +MODULE_LICENSE("GPL");
421 --- /dev/null
422 +++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
423 @@ -0,0 +1,189 @@
424 +/*
425 + * Copyright (C) 2016 Broadcom
426 + *
427 + * This program is free software; you can redistribute it and/or
428 + * modify it under the terms of the GNU General Public License as
429 + * published by the Free Software Foundation version 2.
430 + *
431 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
432 + * kind, whether express or implied; without even the implied warranty
433 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
434 + * GNU General Public License for more details.
435 + */
436 +
437 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
438 +
439 +#include <linux/bcma/bcma.h>
440 +#include <linux/etherdevice.h>
441 +#include <linux/of_address.h>
442 +#include <linux/of_net.h>
443 +#include "bgmac.h"
444 +
445 +static u32 platform_bgmac_read(struct bgmac *bgmac, u16 offset)
446 +{
447 + return readl(bgmac->plat.base + offset);
448 +}
449 +
450 +static void platform_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
451 +{
452 + writel(value, bgmac->plat.base + offset);
453 +}
454 +
455 +static u32 platform_bgmac_idm_read(struct bgmac *bgmac, u16 offset)
456 +{
457 + return readl(bgmac->plat.idm_base + offset);
458 +}
459 +
460 +static void platform_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
461 +{
462 + return writel(value, bgmac->plat.idm_base + offset);
463 +}
464 +
465 +static bool platform_bgmac_clk_enabled(struct bgmac *bgmac)
466 +{
467 + if ((bgmac_idm_read(bgmac, BCMA_IOCTL) &
468 + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC)) != BCMA_IOCTL_CLK)
469 + return false;
470 + if (bgmac_idm_read(bgmac, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
471 + return false;
472 + return true;
473 +}
474 +
475 +static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
476 +{
477 + bgmac_idm_write(bgmac, BCMA_IOCTL,
478 + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
479 + bgmac_idm_read(bgmac, BCMA_IOCTL);
480 +
481 + bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0);
482 + bgmac_idm_read(bgmac, BCMA_RESET_CTL);
483 + udelay(1);
484 +
485 + bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
486 + bgmac_idm_read(bgmac, BCMA_IOCTL);
487 + udelay(1);
488 +}
489 +
490 +static void platform_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
491 + u32 mask, u32 set)
492 +{
493 + /* This shouldn't be encountered */
494 + WARN_ON(1);
495 +}
496 +
497 +static u32 platform_bgmac_get_bus_clock(struct bgmac *bgmac)
498 +{
499 + /* This shouldn't be encountered */
500 + WARN_ON(1);
501 +
502 + return 0;
503 +}
504 +
505 +static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
506 + u32 mask, u32 set)
507 +{
508 + /* This shouldn't be encountered */
509 + WARN_ON(1);
510 +}
511 +
512 +static int bgmac_probe(struct platform_device *pdev)
513 +{
514 + struct device_node *np = pdev->dev.of_node;
515 + struct bgmac *bgmac;
516 + struct resource *regs;
517 + const u8 *mac_addr;
518 +
519 + bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL);
520 + if (!bgmac)
521 + return -ENOMEM;
522 +
523 + platform_set_drvdata(pdev, bgmac);
524 +
525 + /* Set the features of the 4707 family */
526 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
527 + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
528 + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
529 + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
530 + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
531 + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
532 +
533 + bgmac->dev = &pdev->dev;
534 + bgmac->dma_dev = &pdev->dev;
535 +
536 + mac_addr = of_get_mac_address(np);
537 + if (mac_addr)
538 + ether_addr_copy(bgmac->mac_addr, mac_addr);
539 + else
540 + dev_warn(&pdev->dev, "MAC address not present in device tree\n");
541 +
542 + bgmac->irq = platform_get_irq(pdev, 0);
543 + if (bgmac->irq < 0) {
544 + dev_err(&pdev->dev, "Unable to obtain IRQ\n");
545 + return bgmac->irq;
546 + }
547 +
548 + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "amac_base");
549 + if (!regs) {
550 + dev_err(&pdev->dev, "Unable to obtain base resource\n");
551 + return -EINVAL;
552 + }
553 +
554 + bgmac->plat.base = devm_ioremap_resource(&pdev->dev, regs);
555 + if (IS_ERR(bgmac->plat.base)) {
556 + dev_err(&pdev->dev, "Unable to map base resource\n");
557 + return PTR_ERR(bgmac->plat.base);
558 + }
559 +
560 + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "idm_base");
561 + if (!regs) {
562 + dev_err(&pdev->dev, "Unable to obtain idm resource\n");
563 + return -EINVAL;
564 + }
565 +
566 + bgmac->plat.idm_base = devm_ioremap_resource(&pdev->dev, regs);
567 + if (!bgmac->plat.idm_base) {
568 + dev_err(&pdev->dev, "Unable to map idm resource\n");
569 + return PTR_ERR(bgmac->plat.idm_base);
570 + }
571 +
572 + bgmac->read = platform_bgmac_read;
573 + bgmac->write = platform_bgmac_write;
574 + bgmac->idm_read = platform_bgmac_idm_read;
575 + bgmac->idm_write = platform_bgmac_idm_write;
576 + bgmac->clk_enabled = platform_bgmac_clk_enabled;
577 + bgmac->clk_enable = platform_bgmac_clk_enable;
578 + bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
579 + bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
580 + bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
581 +
582 + return bgmac_enet_probe(bgmac);
583 +}
584 +
585 +static int bgmac_remove(struct platform_device *pdev)
586 +{
587 + struct bgmac *bgmac = platform_get_drvdata(pdev);
588 +
589 + bgmac_enet_remove(bgmac);
590 +
591 + return 0;
592 +}
593 +
594 +static const struct of_device_id bgmac_of_enet_match[] = {
595 + {.compatible = "brcm,amac",},
596 + {.compatible = "brcm,nsp-amac",},
597 + {},
598 +};
599 +
600 +MODULE_DEVICE_TABLE(of, bgmac_of_enet_match);
601 +
602 +static struct platform_driver bgmac_enet_driver = {
603 + .driver = {
604 + .name = "bgmac-enet",
605 + .of_match_table = bgmac_of_enet_match,
606 + },
607 + .probe = bgmac_probe,
608 + .remove = bgmac_remove,
609 +};
610 +
611 +module_platform_driver(bgmac_enet_driver);
612 +MODULE_LICENSE("GPL");
613 --- a/drivers/net/ethernet/broadcom/bgmac.c
614 +++ b/drivers/net/ethernet/broadcom/bgmac.c
615 @@ -6,51 +6,27 @@
616 * Licensed under the GNU/GPL. See COPYING for details.
617 */
618
619 -#include "bgmac.h"
620
621 -#include <linux/kernel.h>
622 -#include <linux/module.h>
623 -#include <linux/delay.h>
624 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
625 +
626 +#include <linux/bcma/bcma.h>
627 #include <linux/etherdevice.h>
628 -#include <linux/mii.h>
629 -#include <linux/phy.h>
630 -#include <linux/phy_fixed.h>
631 -#include <linux/interrupt.h>
632 -#include <linux/dma-mapping.h>
633 #include <linux/bcm47xx_nvram.h>
634 +#include "bgmac.h"
635
636 -static const struct bcma_device_id bgmac_bcma_tbl[] = {
637 - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
638 - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
639 - {},
640 -};
641 -MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
642 -
643 -static inline bool bgmac_is_bcm4707_family(struct bgmac *bgmac)
644 -{
645 - switch (bgmac->core->bus->chipinfo.id) {
646 - case BCMA_CHIP_ID_BCM4707:
647 - case BCMA_CHIP_ID_BCM47094:
648 - case BCMA_CHIP_ID_BCM53018:
649 - return true;
650 - default:
651 - return false;
652 - }
653 -}
654 -
655 -static bool bgmac_wait_value(struct bcma_device *core, u16 reg, u32 mask,
656 +static bool bgmac_wait_value(struct bgmac *bgmac, u16 reg, u32 mask,
657 u32 value, int timeout)
658 {
659 u32 val;
660 int i;
661
662 for (i = 0; i < timeout / 10; i++) {
663 - val = bcma_read32(core, reg);
664 + val = bgmac_read(bgmac, reg);
665 if ((val & mask) == value)
666 return true;
667 udelay(10);
668 }
669 - dev_err(&core->dev, "Timeout waiting for reg 0x%X\n", reg);
670 + dev_err(bgmac->dev, "Timeout waiting for reg 0x%X\n", reg);
671 return false;
672 }
673
674 @@ -89,7 +65,7 @@ static void bgmac_dma_tx_reset(struct bg
675
676 /* Remove SUSPEND bit */
677 bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL, 0);
678 - if (!bgmac_wait_value(bgmac->core,
679 + if (!bgmac_wait_value(bgmac,
680 ring->mmio_base + BGMAC_DMA_TX_STATUS,
681 BGMAC_DMA_TX_STAT, BGMAC_DMA_TX_STAT_DISABLED,
682 10000)) {
683 @@ -317,7 +293,7 @@ static void bgmac_dma_rx_reset(struct bg
684 return;
685
686 bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL, 0);
687 - if (!bgmac_wait_value(bgmac->core,
688 + if (!bgmac_wait_value(bgmac,
689 ring->mmio_base + BGMAC_DMA_RX_STATUS,
690 BGMAC_DMA_RX_STAT, BGMAC_DMA_RX_STAT_DISABLED,
691 10000))
692 @@ -640,7 +616,7 @@ static int bgmac_dma_alloc(struct bgmac
693 BUILD_BUG_ON(BGMAC_MAX_TX_RINGS > ARRAY_SIZE(ring_base));
694 BUILD_BUG_ON(BGMAC_MAX_RX_RINGS > ARRAY_SIZE(ring_base));
695
696 - if (!(bcma_aread32(bgmac->core, BCMA_IOST) & BCMA_IOST_DMA64)) {
697 + if (!(bgmac_idm_read(bgmac, BCMA_IOST) & BCMA_IOST_DMA64)) {
698 dev_err(bgmac->dev, "Core does not report 64-bit DMA\n");
699 return -ENOTSUPP;
700 }
701 @@ -872,12 +848,10 @@ static void bgmac_mac_speed(struct bgmac
702
703 static void bgmac_miiconfig(struct bgmac *bgmac)
704 {
705 - struct bcma_device *core = bgmac->core;
706 -
707 if (bgmac->feature_flags & BGMAC_FEAT_FORCE_SPEED_2500) {
708 - bcma_awrite32(core, BCMA_IOCTL,
709 - bcma_aread32(core, BCMA_IOCTL) | 0x40 |
710 - BGMAC_BCMA_IOCTL_SW_CLKEN);
711 + bgmac_idm_write(bgmac, BCMA_IOCTL,
712 + bgmac_idm_read(bgmac, BCMA_IOCTL) | 0x40 |
713 + BGMAC_BCMA_IOCTL_SW_CLKEN);
714 bgmac->mac_speed = SPEED_2500;
715 bgmac->mac_duplex = DUPLEX_FULL;
716 bgmac_mac_speed(bgmac);
717 @@ -897,12 +871,11 @@ static void bgmac_miiconfig(struct bgmac
718 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipreset */
719 static void bgmac_chip_reset(struct bgmac *bgmac)
720 {
721 - struct bcma_device *core = bgmac->core;
722 u32 cmdcfg_sr;
723 u32 iost;
724 int i;
725
726 - if (bcma_core_is_enabled(core)) {
727 + if (bgmac_clk_enabled(bgmac)) {
728 if (!bgmac->stats_grabbed) {
729 /* bgmac_chip_stats_update(bgmac); */
730 bgmac->stats_grabbed = true;
731 @@ -920,7 +893,7 @@ static void bgmac_chip_reset(struct bgma
732 /* TODO: Clear software multicast filter list */
733 }
734
735 - iost = bcma_aread32(core, BCMA_IOST);
736 + iost = bgmac_idm_read(bgmac, BCMA_IOST);
737 if (bgmac->feature_flags & BGMAC_FEAT_IOST_ATTACHED)
738 iost &= ~BGMAC_BCMA_IOST_ATTACHED;
739
740 @@ -932,21 +905,20 @@ static void bgmac_chip_reset(struct bgma
741 if (!bgmac->has_robosw)
742 flags |= BGMAC_BCMA_IOCTL_SW_RESET;
743 }
744 - bcma_core_enable(core, flags);
745 + bgmac_clk_enable(bgmac, flags);
746 }
747
748 /* Request Misc PLL for corerev > 2 */
749 if (bgmac->feature_flags & BGMAC_FEAT_MISC_PLL_REQ) {
750 bgmac_set(bgmac, BCMA_CLKCTLST,
751 BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ);
752 - bgmac_wait_value(bgmac->core, BCMA_CLKCTLST,
753 + bgmac_wait_value(bgmac, BCMA_CLKCTLST,
754 BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
755 BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
756 1000);
757 }
758
759 if (bgmac->feature_flags & BGMAC_FEAT_SW_TYPE_PHY) {
760 - struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
761 u8 et_swtype = 0;
762 u8 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHY |
763 BGMAC_CHIPCTL_1_IF_TYPE_MII;
764 @@ -965,16 +937,15 @@ static void bgmac_chip_reset(struct bgma
765 sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII |
766 BGMAC_CHIPCTL_1_SW_TYPE_RGMII;
767 }
768 - bcma_chipco_chipctl_maskset(cc, 1,
769 - ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
770 - BGMAC_CHIPCTL_1_SW_TYPE_MASK),
771 - sw_type);
772 + bgmac_cco_ctl_maskset(bgmac, 1, ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
773 + BGMAC_CHIPCTL_1_SW_TYPE_MASK),
774 + sw_type);
775 }
776
777 if (iost & BGMAC_BCMA_IOST_ATTACHED && !bgmac->has_robosw)
778 - bcma_awrite32(core, BCMA_IOCTL,
779 - bcma_aread32(core, BCMA_IOCTL) &
780 - ~BGMAC_BCMA_IOCTL_SW_RESET);
781 + bgmac_idm_write(bgmac, BCMA_IOCTL,
782 + bgmac_idm_read(bgmac, BCMA_IOCTL) &
783 + ~BGMAC_BCMA_IOCTL_SW_RESET);
784
785 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_reset
786 * Specs don't say about using BGMAC_CMDCFG_SR, but in this routine
787 @@ -1010,8 +981,8 @@ static void bgmac_chip_reset(struct bgma
788
789 bgmac_clear_mib(bgmac);
790 if (bgmac->feature_flags & BGMAC_FEAT_CMN_PHY_CTL)
791 - bcma_maskset32(bgmac->cmn, BCMA_GMAC_CMN_PHY_CTL, ~0,
792 - BCMA_GMAC_CMN_PC_MTE);
793 + bgmac_cmn_maskset32(bgmac, BCMA_GMAC_CMN_PHY_CTL, ~0,
794 + BCMA_GMAC_CMN_PC_MTE);
795 else
796 bgmac_set(bgmac, BGMAC_PHY_CNTL, BGMAC_PC_MTE);
797 bgmac_miiconfig(bgmac);
798 @@ -1056,8 +1027,8 @@ static void bgmac_enable(struct bgmac *b
799 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST || mode != 0)
800 bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
801 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST && mode == 2)
802 - bcma_chipco_chipctl_maskset(&bgmac->core->bus->drv_cc, 1, ~0,
803 - BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
804 + bgmac_cco_ctl_maskset(bgmac, 1, ~0,
805 + BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
806
807 if (bgmac->feature_flags & (BGMAC_FEAT_FLW_CTRL1 |
808 BGMAC_FEAT_FLW_CTRL2)) {
809 @@ -1079,8 +1050,7 @@ static void bgmac_enable(struct bgmac *b
810
811 rxq_ctl = bgmac_read(bgmac, BGMAC_RXQ_CTL);
812 rxq_ctl &= ~BGMAC_RXQ_CTL_MDP_MASK;
813 - bp_clk = bcma_pmu_get_bus_clock(&bgmac->core->bus->drv_cc) /
814 - 1000000;
815 + bp_clk = bgmac_get_bus_clock(bgmac) / 1000000;
816 mdp = (bp_clk * 128 / 1000) - 3;
817 rxq_ctl |= (mdp << BGMAC_RXQ_CTL_MDP_SHIFT);
818 bgmac_write(bgmac, BGMAC_RXQ_CTL, rxq_ctl);
819 @@ -1175,7 +1145,7 @@ static int bgmac_open(struct net_device
820 /* Specs say about reclaiming rings here, but we do that in DMA init */
821 bgmac_chip_init(bgmac);
822
823 - err = request_irq(bgmac->core->irq, bgmac_interrupt, IRQF_SHARED,
824 + err = request_irq(bgmac->irq, bgmac_interrupt, IRQF_SHARED,
825 KBUILD_MODNAME, net_dev);
826 if (err < 0) {
827 dev_err(bgmac->dev, "IRQ request error: %d!\n", err);
828 @@ -1201,7 +1171,7 @@ static int bgmac_stop(struct net_device
829
830 napi_disable(&bgmac->napi);
831 bgmac_chip_intrs_off(bgmac);
832 - free_irq(bgmac->core->irq, net_dev);
833 + free_irq(bgmac->irq, net_dev);
834
835 bgmac_chip_reset(bgmac);
836 bgmac_dma_cleanup(bgmac);
837 @@ -1396,7 +1366,7 @@ static void bgmac_get_drvinfo(struct net
838 struct ethtool_drvinfo *info)
839 {
840 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
841 - strlcpy(info->bus_info, "BCMA", sizeof(info->bus_info));
842 + strlcpy(info->bus_info, "AXI", sizeof(info->bus_info));
843 }
844
845 static const struct ethtool_ops bgmac_ethtool_ops = {
846 @@ -1480,116 +1450,41 @@ static int bgmac_phy_connect(struct bgma
847 return 0;
848 }
849
850 -static int bgmac_probe(struct bcma_device *core)
851 +int bgmac_enet_probe(struct bgmac *info)
852 {
853 struct net_device *net_dev;
854 struct bgmac *bgmac;
855 - struct ssb_sprom *sprom = &core->bus->sprom;
856 - u8 *mac;
857 int err;
858
859 - switch (core->core_unit) {
860 - case 0:
861 - mac = sprom->et0mac;
862 - break;
863 - case 1:
864 - mac = sprom->et1mac;
865 - break;
866 - case 2:
867 - mac = sprom->et2mac;
868 - break;
869 - default:
870 - dev_err(&core->dev, "Unsupported core_unit %d\n",
871 - core->core_unit);
872 - return -ENOTSUPP;
873 - }
874 -
875 - if (!is_valid_ether_addr(mac)) {
876 - dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac);
877 - eth_random_addr(mac);
878 - dev_warn(&core->dev, "Using random MAC: %pM\n", mac);
879 - }
880 -
881 - /* This (reset &) enable is not preset in specs or reference driver but
882 - * Broadcom does it in arch PCI code when enabling fake PCI device.
883 - */
884 - bcma_core_enable(core, 0);
885 -
886 /* Allocation and references */
887 net_dev = alloc_etherdev(sizeof(*bgmac));
888 if (!net_dev)
889 return -ENOMEM;
890 +
891 net_dev->netdev_ops = &bgmac_netdev_ops;
892 - net_dev->irq = core->irq;
893 net_dev->ethtool_ops = &bgmac_ethtool_ops;
894 bgmac = netdev_priv(net_dev);
895 - bgmac->dev = &core->dev;
896 - bgmac->dma_dev = core->dma_dev;
897 + memcpy(bgmac, info, sizeof(*bgmac));
898 bgmac->net_dev = net_dev;
899 - bgmac->core = core;
900 - bcma_set_drvdata(core, bgmac);
901 - SET_NETDEV_DEV(net_dev, &core->dev);
902 -
903 - /* Defaults */
904 - memcpy(bgmac->net_dev->dev_addr, mac, ETH_ALEN);
905 -
906 - /* On BCM4706 we need common core to access PHY */
907 - if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
908 - !core->bus->drv_gmac_cmn.core) {
909 - dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n");
910 - err = -ENODEV;
911 - goto err_netdev_free;
912 - }
913 - bgmac->cmn = core->bus->drv_gmac_cmn.core;
914 + net_dev->irq = bgmac->irq;
915 + SET_NETDEV_DEV(net_dev, bgmac->dev);
916
917 - switch (core->core_unit) {
918 - case 0:
919 - bgmac->phyaddr = sprom->et0phyaddr;
920 - break;
921 - case 1:
922 - bgmac->phyaddr = sprom->et1phyaddr;
923 - break;
924 - case 2:
925 - bgmac->phyaddr = sprom->et2phyaddr;
926 - break;
927 + if (!is_valid_ether_addr(bgmac->mac_addr)) {
928 + dev_err(bgmac->dev, "Invalid MAC addr: %pM\n",
929 + bgmac->mac_addr);
930 + eth_random_addr(bgmac->mac_addr);
931 + dev_warn(bgmac->dev, "Using random MAC: %pM\n",
932 + bgmac->mac_addr);
933 }
934 - bgmac->phyaddr &= BGMAC_PHY_MASK;
935 - if (bgmac->phyaddr == BGMAC_PHY_MASK) {
936 - dev_err(bgmac->dev, "No PHY found\n");
937 - err = -ENODEV;
938 - goto err_netdev_free;
939 - }
940 - dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr,
941 - bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
942 + ether_addr_copy(net_dev->dev_addr, bgmac->mac_addr);
943
944 - if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) {
945 - dev_err(bgmac->dev, "PCI setup not implemented\n");
946 - err = -ENOTSUPP;
947 - goto err_netdev_free;
948 - }
949 + /* This (reset &) enable is not preset in specs or reference driver but
950 + * Broadcom does it in arch PCI code when enabling fake PCI device.
951 + */
952 + bgmac_clk_enable(bgmac, 0);
953
954 bgmac_chip_reset(bgmac);
955
956 - /* For Northstar, we have to take all GMAC core out of reset */
957 - if (bgmac_is_bcm4707_family(bgmac)) {
958 - struct bcma_device *ns_core;
959 - int ns_gmac;
960 -
961 - /* Northstar has 4 GMAC cores */
962 - for (ns_gmac = 0; ns_gmac < 4; ns_gmac++) {
963 - /* As Northstar requirement, we have to reset all GMACs
964 - * before accessing one. bgmac_chip_reset() call
965 - * bcma_core_enable() for this core. Then the other
966 - * three GMACs didn't reset. We do it here.
967 - */
968 - ns_core = bcma_find_core_unit(core->bus,
969 - BCMA_CORE_MAC_GBIT,
970 - ns_gmac);
971 - if (ns_core && !bcma_core_is_enabled(ns_core))
972 - bcma_core_enable(ns_core, 0);
973 - }
974 - }
975 -
976 err = bgmac_dma_alloc(bgmac);
977 if (err) {
978 dev_err(bgmac->dev, "Unable to alloc memory for DMA\n");
979 @@ -1600,103 +1495,15 @@ static int bgmac_probe(struct bcma_devic
980 if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
981 bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
982
983 - bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
984 - BGMAC_BFL_ENETROBO);
985 - if (bgmac->has_robosw)
986 - dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n");
987 -
988 - if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM)
989 - dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n");
990 -
991 - /* Feature Flags */
992 - switch (core->bus->chipinfo.id) {
993 - case BCMA_CHIP_ID_BCM5357:
994 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
995 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
996 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
997 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
998 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) {
999 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
1000 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
1001 - }
1002 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358)
1003 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII;
1004 - break;
1005 - case BCMA_CHIP_ID_BCM53572:
1006 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
1007 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
1008 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
1009 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
1010 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) {
1011 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
1012 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
1013 - }
1014 - break;
1015 - case BCMA_CHIP_ID_BCM4749:
1016 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
1017 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
1018 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1;
1019 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY;
1020 - if (core->bus->chipinfo.pkg == 10) {
1021 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII;
1022 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED;
1023 - }
1024 - break;
1025 - case BCMA_CHIP_ID_BCM4716:
1026 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
1027 - /* fallthrough */
1028 - case BCMA_CHIP_ID_BCM47162:
1029 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2;
1030 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
1031 - break;
1032 - /* bcm4707_family */
1033 - case BCMA_CHIP_ID_BCM4707:
1034 - case BCMA_CHIP_ID_BCM47094:
1035 - case BCMA_CHIP_ID_BCM53018:
1036 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
1037 - bgmac->feature_flags |= BGMAC_FEAT_NO_RESET;
1038 - bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;
1039 - break;
1040 - default:
1041 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST;
1042 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK;
1043 - }
1044 -
1045 - if (!bgmac_is_bcm4707_family(bgmac) && core->id.rev > 2)
1046 - bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ;
1047 -
1048 - if (core->id.id == BCMA_CORE_4706_MAC_GBIT) {
1049 - bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL;
1050 - bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB;
1051 - }
1052 -
1053 - if (core->id.rev >= 4) {
1054 - bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4;
1055 - bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP;
1056 - bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP;
1057 - }
1058 -
1059 netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
1060
1061 - if (!bgmac_is_bcm4707_family(bgmac)) {
1062 - struct mii_bus *mii_bus;
1063 -
1064 - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
1065 - if (!IS_ERR(mii_bus)) {
1066 - err = PTR_ERR(mii_bus);
1067 - goto err_dma_free;
1068 - }
1069 -
1070 - bgmac->mii_bus = mii_bus;
1071 - }
1072 -
1073 if (!bgmac->mii_bus)
1074 err = bgmac_phy_connect_direct(bgmac);
1075 else
1076 err = bgmac_phy_connect(bgmac);
1077 if (err) {
1078 dev_err(bgmac->dev, "Cannot connect to phy\n");
1079 - goto err_mii_unregister;
1080 + goto err_dma_free;
1081 }
1082
1083 net_dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1084 @@ -1715,56 +1522,24 @@ static int bgmac_probe(struct bcma_devic
1085
1086 err_phy_disconnect:
1087 phy_disconnect(net_dev->phydev);
1088 -err_mii_unregister:
1089 - bcma_mdio_mii_unregister(bgmac->mii_bus);
1090 err_dma_free:
1091 bgmac_dma_free(bgmac);
1092 err_netdev_free:
1093 - bcma_set_drvdata(core, NULL);
1094 free_netdev(net_dev);
1095
1096 return err;
1097 }
1098 +EXPORT_SYMBOL_GPL(bgmac_enet_probe);
1099
1100 -static void bgmac_remove(struct bcma_device *core)
1101 +void bgmac_enet_remove(struct bgmac *bgmac)
1102 {
1103 - struct bgmac *bgmac = bcma_get_drvdata(core);
1104 -
1105 unregister_netdev(bgmac->net_dev);
1106 phy_disconnect(bgmac->net_dev->phydev);
1107 - bcma_mdio_mii_unregister(bgmac->mii_bus);
1108 netif_napi_del(&bgmac->napi);
1109 bgmac_dma_free(bgmac);
1110 - bcma_set_drvdata(core, NULL);
1111 free_netdev(bgmac->net_dev);
1112 }
1113 -
1114 -static struct bcma_driver bgmac_bcma_driver = {
1115 - .name = KBUILD_MODNAME,
1116 - .id_table = bgmac_bcma_tbl,
1117 - .probe = bgmac_probe,
1118 - .remove = bgmac_remove,
1119 -};
1120 -
1121 -static int __init bgmac_init(void)
1122 -{
1123 - int err;
1124 -
1125 - err = bcma_driver_register(&bgmac_bcma_driver);
1126 - if (err)
1127 - return err;
1128 - pr_info("Broadcom 47xx GBit MAC driver loaded\n");
1129 -
1130 - return 0;
1131 -}
1132 -
1133 -static void __exit bgmac_exit(void)
1134 -{
1135 - bcma_driver_unregister(&bgmac_bcma_driver);
1136 -}
1137 -
1138 -module_init(bgmac_init)
1139 -module_exit(bgmac_exit)
1140 +EXPORT_SYMBOL_GPL(bgmac_enet_remove);
1141
1142 MODULE_AUTHOR("Rafał Miłecki");
1143 MODULE_LICENSE("GPL");
1144 --- a/drivers/net/ethernet/broadcom/bgmac.h
1145 +++ b/drivers/net/ethernet/broadcom/bgmac.h
1146 @@ -1,8 +1,6 @@
1147 #ifndef _BGMAC_H
1148 #define _BGMAC_H
1149
1150 -#include <linux/bcma/bcma.h>
1151 -#include <linux/brcmphy.h>
1152 #include <linux/netdevice.h>
1153
1154 #define BGMAC_DEV_CTL 0x000
1155 @@ -442,11 +440,21 @@ struct bgmac_rx_header {
1156 };
1157
1158 struct bgmac {
1159 - struct bcma_device *core;
1160 - struct bcma_device *cmn; /* Reference to CMN core for BCM4706 */
1161 + union {
1162 + struct {
1163 + void *base;
1164 + void *idm_base;
1165 + } plat;
1166 + struct {
1167 + struct bcma_device *core;
1168 + /* Reference to CMN core for BCM4706 */
1169 + struct bcma_device *cmn;
1170 + } bcma;
1171 + };
1172
1173 struct device *dev;
1174 struct device *dma_dev;
1175 + unsigned char mac_addr[ETH_ALEN];
1176 u32 feature_flags;
1177
1178 struct net_device *net_dev;
1179 @@ -463,6 +471,7 @@ struct bgmac {
1180 u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS];
1181
1182 /* Int */
1183 + int irq;
1184 u32 int_mask;
1185
1186 /* Current MAC state */
1187 @@ -473,19 +482,71 @@ struct bgmac {
1188 bool has_robosw;
1189
1190 bool loopback;
1191 +
1192 + u32 (*read)(struct bgmac *bgmac, u16 offset);
1193 + void (*write)(struct bgmac *bgmac, u16 offset, u32 value);
1194 + u32 (*idm_read)(struct bgmac *bgmac, u16 offset);
1195 + void (*idm_write)(struct bgmac *bgmac, u16 offset, u32 value);
1196 + bool (*clk_enabled)(struct bgmac *bgmac);
1197 + void (*clk_enable)(struct bgmac *bgmac, u32 flags);
1198 + void (*cco_ctl_maskset)(struct bgmac *bgmac, u32 offset, u32 mask,
1199 + u32 set);
1200 + u32 (*get_bus_clock)(struct bgmac *bgmac);
1201 + void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask,
1202 + u32 set);
1203 };
1204
1205 +int bgmac_enet_probe(struct bgmac *info);
1206 +void bgmac_enet_remove(struct bgmac *bgmac);
1207 +
1208 struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
1209 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
1210
1211 static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)
1212 {
1213 - return bcma_read32(bgmac->core, offset);
1214 + return bgmac->read(bgmac, offset);
1215 }
1216
1217 static inline void bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
1218 {
1219 - bcma_write32(bgmac->core, offset, value);
1220 + bgmac->write(bgmac, offset, value);
1221 +}
1222 +
1223 +static inline u32 bgmac_idm_read(struct bgmac *bgmac, u16 offset)
1224 +{
1225 + return bgmac->idm_read(bgmac, offset);
1226 +}
1227 +
1228 +static inline void bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value)
1229 +{
1230 + bgmac->idm_write(bgmac, offset, value);
1231 +}
1232 +
1233 +static inline bool bgmac_clk_enabled(struct bgmac *bgmac)
1234 +{
1235 + return bgmac->clk_enabled(bgmac);
1236 +}
1237 +
1238 +static inline void bgmac_clk_enable(struct bgmac *bgmac, u32 flags)
1239 +{
1240 + bgmac->clk_enable(bgmac, flags);
1241 +}
1242 +
1243 +static inline void bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset,
1244 + u32 mask, u32 set)
1245 +{
1246 + bgmac->cco_ctl_maskset(bgmac, offset, mask, set);
1247 +}
1248 +
1249 +static inline u32 bgmac_get_bus_clock(struct bgmac *bgmac)
1250 +{
1251 + return bgmac->get_bus_clock(bgmac);
1252 +}
1253 +
1254 +static inline void bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset,
1255 + u32 mask, u32 set)
1256 +{
1257 + bgmac->cmn_maskset32(bgmac, offset, mask, set);
1258 }
1259
1260 static inline void bgmac_maskset(struct bgmac *bgmac, u16 offset, u32 mask,