0c007569fbe22277bac3723029856bae53695978
[openwrt/staging/yousong.git] /
1 From 387b75f8b31437792e8334390fdf5cf060d1e3da Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Tue, 2 Feb 2016 07:47:14 +0100
4 Subject: [PATCH] bgmac: add helper checking for BCM4707 / BCM53018 chip id
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Chipsets with BCM4707 / BCM53018 ID require special handling at a few
10 places in the code. It's likely there will be more IDs to check in the
11 future. To simplify it add this trivial helper.
12
13 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
15 ---
16 drivers/net/ethernet/broadcom/bgmac.c | 30 ++++++++++++++++--------------
17 1 file changed, 16 insertions(+), 14 deletions(-)
18
19 --- a/drivers/net/ethernet/broadcom/bgmac.c
20 +++ b/drivers/net/ethernet/broadcom/bgmac.c
21 @@ -26,6 +26,17 @@ static const struct bcma_device_id bgmac
22 };
23 MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
24
25 +static inline bool bgmac_is_bcm4707_family(struct bgmac *bgmac)
26 +{
27 + switch (bgmac->core->bus->chipinfo.id) {
28 + case BCMA_CHIP_ID_BCM4707:
29 + case BCMA_CHIP_ID_BCM53018:
30 + return true;
31 + default:
32 + return false;
33 + }
34 +}
35 +
36 static bool bgmac_wait_value(struct bcma_device *core, u16 reg, u32 mask,
37 u32 value, int timeout)
38 {
39 @@ -990,11 +1001,9 @@ static void bgmac_mac_speed(struct bgmac
40 static void bgmac_miiconfig(struct bgmac *bgmac)
41 {
42 struct bcma_device *core = bgmac->core;
43 - struct bcma_chipinfo *ci = &core->bus->chipinfo;
44 u8 imode;
45
46 - if (ci->id == BCMA_CHIP_ID_BCM4707 ||
47 - ci->id == BCMA_CHIP_ID_BCM53018) {
48 + if (bgmac_is_bcm4707_family(bgmac)) {
49 bcma_awrite32(core, BCMA_IOCTL,
50 bcma_aread32(core, BCMA_IOCTL) | 0x40 |
51 BGMAC_BCMA_IOCTL_SW_CLKEN);
52 @@ -1058,9 +1067,7 @@ static void bgmac_chip_reset(struct bgma
53 }
54
55 /* Request Misc PLL for corerev > 2 */
56 - if (core->id.rev > 2 &&
57 - ci->id != BCMA_CHIP_ID_BCM4707 &&
58 - ci->id != BCMA_CHIP_ID_BCM53018) {
59 + if (core->id.rev > 2 && !bgmac_is_bcm4707_family(bgmac)) {
60 bgmac_set(bgmac, BCMA_CLKCTLST,
61 BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ);
62 bgmac_wait_value(bgmac->core, BCMA_CLKCTLST,
63 @@ -1196,8 +1203,7 @@ static void bgmac_enable(struct bgmac *b
64 break;
65 }
66
67 - if (ci->id != BCMA_CHIP_ID_BCM4707 &&
68 - ci->id != BCMA_CHIP_ID_BCM53018) {
69 + if (!bgmac_is_bcm4707_family(bgmac)) {
70 rxq_ctl = bgmac_read(bgmac, BGMAC_RXQ_CTL);
71 rxq_ctl &= ~BGMAC_RXQ_CTL_MDP_MASK;
72 bp_clk = bcma_pmu_get_bus_clock(&bgmac->core->bus->drv_cc) /
73 @@ -1475,14 +1481,12 @@ static int bgmac_fixed_phy_register(stru
74
75 static int bgmac_mii_register(struct bgmac *bgmac)
76 {
77 - struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo;
78 struct mii_bus *mii_bus;
79 struct phy_device *phy_dev;
80 char bus_id[MII_BUS_ID_SIZE + 3];
81 int i, err = 0;
82
83 - if (ci->id == BCMA_CHIP_ID_BCM4707 ||
84 - ci->id == BCMA_CHIP_ID_BCM53018)
85 + if (bgmac_is_bcm4707_family(bgmac))
86 return bgmac_fixed_phy_register(bgmac);
87
88 mii_bus = mdiobus_alloc();
89 @@ -1553,7 +1557,6 @@ static void bgmac_mii_unregister(struct
90 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
91 static int bgmac_probe(struct bcma_device *core)
92 {
93 - struct bcma_chipinfo *ci = &core->bus->chipinfo;
94 struct net_device *net_dev;
95 struct bgmac *bgmac;
96 struct ssb_sprom *sprom = &core->bus->sprom;
97 @@ -1634,8 +1637,7 @@ static int bgmac_probe(struct bcma_devic
98 bgmac_chip_reset(bgmac);
99
100 /* For Northstar, we have to take all GMAC core out of reset */
101 - if (ci->id == BCMA_CHIP_ID_BCM4707 ||
102 - ci->id == BCMA_CHIP_ID_BCM53018) {
103 + if (bgmac_is_bcm4707_family(bgmac)) {
104 struct bcma_device *ns_core;
105 int ns_gmac;
106