7a6f3454d1fe981ba82344d4413456b3286fcf59
[openwrt/staging/lynxis.git] /
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Tue, 31 Jan 2017 19:37:55 +0100
3 Subject: [PATCH] net: bgmac: drop struct bcma_mdio we don't need anymore
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 Adding struct bcma_mdio was a workaround for bcma code not having access
9 to the struct bgmac used in the core code. Now we don't duplicate this
10 struct we can just use it internally in bcma code.
11
12 This simplifies code & allows access to all bgmac driver details from
13 all places in bcma code.
14
15 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
16 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
18 ---
19
20 --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
21 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
22 @@ -159,7 +159,7 @@ static int bgmac_probe(struct bcma_devic
23
24 if (!bgmac_is_bcm4707_family(core) &&
25 !(ci->id == BCMA_CHIP_ID_BCM53573 && core->core_unit == 1)) {
26 - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr);
27 + mii_bus = bcma_mdio_mii_register(bgmac);
28 if (IS_ERR(mii_bus)) {
29 err = PTR_ERR(mii_bus);
30 goto err;
31 --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
32 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
33 @@ -12,11 +12,6 @@
34 #include <linux/brcmphy.h>
35 #include "bgmac.h"
36
37 -struct bcma_mdio {
38 - struct bcma_device *core;
39 - u8 phyaddr;
40 -};
41 -
42 static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask,
43 u32 value, int timeout)
44 {
45 @@ -37,7 +32,7 @@ static bool bcma_mdio_wait_value(struct
46 * PHY ops
47 **************************************************/
48
49 -static u16 bcma_mdio_phy_read(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg)
50 +static u16 bcma_mdio_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
51 {
52 struct bcma_device *core;
53 u16 phy_access_addr;
54 @@ -56,12 +51,12 @@ static u16 bcma_mdio_phy_read(struct bcm
55 BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
56 BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
57
58 - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
59 - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
60 + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
61 + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
62 phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
63 phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
64 } else {
65 - core = bcma_mdio->core;
66 + core = bgmac->bcma.core;
67 phy_access_addr = BGMAC_PHY_ACCESS;
68 phy_ctl_addr = BGMAC_PHY_CNTL;
69 }
70 @@ -87,7 +82,7 @@ static u16 bcma_mdio_phy_read(struct bcm
71 }
72
73 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
74 -static int bcma_mdio_phy_write(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg,
75 +static int bcma_mdio_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg,
76 u16 value)
77 {
78 struct bcma_device *core;
79 @@ -95,12 +90,12 @@ static int bcma_mdio_phy_write(struct bc
80 u16 phy_ctl_addr;
81 u32 tmp;
82
83 - if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
84 - core = bcma_mdio->core->bus->drv_gmac_cmn.core;
85 + if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) {
86 + core = bgmac->bcma.core->bus->drv_gmac_cmn.core;
87 phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
88 phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
89 } else {
90 - core = bcma_mdio->core;
91 + core = bgmac->bcma.core;
92 phy_access_addr = BGMAC_PHY_ACCESS;
93 phy_ctl_addr = BGMAC_PHY_CNTL;
94 }
95 @@ -110,8 +105,8 @@ static int bcma_mdio_phy_write(struct bc
96 tmp |= phyaddr;
97 bcma_write32(core, phy_ctl_addr, tmp);
98
99 - bcma_write32(bcma_mdio->core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
100 - if (bcma_read32(bcma_mdio->core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
101 + bcma_write32(bgmac->bcma.core, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
102 + if (bcma_read32(bgmac->bcma.core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
103 dev_warn(&core->dev, "Error setting MDIO int\n");
104
105 tmp = BGMAC_PA_START;
106 @@ -132,39 +127,39 @@ static int bcma_mdio_phy_write(struct bc
107 }
108
109 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
110 -static void bcma_mdio_phy_init(struct bcma_mdio *bcma_mdio)
111 +static void bcma_mdio_phy_init(struct bgmac *bgmac)
112 {
113 - struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo;
114 + struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo;
115 u8 i;
116
117 if (ci->id == BCMA_CHIP_ID_BCM5356) {
118 for (i = 0; i < 5; i++) {
119 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x008b);
120 - bcma_mdio_phy_write(bcma_mdio, i, 0x15, 0x0100);
121 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
122 - bcma_mdio_phy_write(bcma_mdio, i, 0x12, 0x2aaa);
123 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
124 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x008b);
125 + bcma_mdio_phy_write(bgmac, i, 0x15, 0x0100);
126 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
127 + bcma_mdio_phy_write(bgmac, i, 0x12, 0x2aaa);
128 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
129 }
130 }
131 if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
132 (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
133 (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
134 - struct bcma_drv_cc *cc = &bcma_mdio->core->bus->drv_cc;
135 + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc;
136
137 bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
138 bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
139 for (i = 0; i < 5; i++) {
140 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
141 - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5284);
142 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
143 - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x0010);
144 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f);
145 - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5296);
146 - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x1073);
147 - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9073);
148 - bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x52b6);
149 - bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9273);
150 - bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b);
151 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
152 + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5284);
153 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
154 + bcma_mdio_phy_write(bgmac, i, 0x17, 0x0010);
155 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f);
156 + bcma_mdio_phy_write(bgmac, i, 0x16, 0x5296);
157 + bcma_mdio_phy_write(bgmac, i, 0x17, 0x1073);
158 + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9073);
159 + bcma_mdio_phy_write(bgmac, i, 0x16, 0x52b6);
160 + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9273);
161 + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b);
162 }
163 }
164 }
165 @@ -172,17 +167,17 @@ static void bcma_mdio_phy_init(struct bc
166 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
167 static int bcma_mdio_phy_reset(struct mii_bus *bus)
168 {
169 - struct bcma_mdio *bcma_mdio = bus->priv;
170 - u8 phyaddr = bcma_mdio->phyaddr;
171 + struct bgmac *bgmac = bus->priv;
172 + u8 phyaddr = bgmac->phyaddr;
173
174 - if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS)
175 + if (phyaddr == BGMAC_PHY_NOREGS)
176 return 0;
177
178 - bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET);
179 + bcma_mdio_phy_write(bgmac, phyaddr, MII_BMCR, BMCR_RESET);
180 udelay(100);
181 - if (bcma_mdio_phy_read(bcma_mdio, phyaddr, MII_BMCR) & BMCR_RESET)
182 - dev_err(&bcma_mdio->core->dev, "PHY reset failed\n");
183 - bcma_mdio_phy_init(bcma_mdio);
184 + if (bcma_mdio_phy_read(bgmac, phyaddr, MII_BMCR) & BMCR_RESET)
185 + dev_err(bgmac->dev, "PHY reset failed\n");
186 + bcma_mdio_phy_init(bgmac);
187
188 return 0;
189 }
190 @@ -202,16 +197,12 @@ static int bcma_mdio_mii_write(struct mi
191 return bcma_mdio_phy_write(bus->priv, mii_id, regnum, value);
192 }
193
194 -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr)
195 +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac)
196 {
197 - struct bcma_mdio *bcma_mdio;
198 + struct bcma_device *core = bgmac->bcma.core;
199 struct mii_bus *mii_bus;
200 int err;
201
202 - bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL);
203 - if (!bcma_mdio)
204 - return ERR_PTR(-ENOMEM);
205 -
206 mii_bus = mdiobus_alloc();
207 if (!mii_bus) {
208 err = -ENOMEM;
209 @@ -221,15 +212,12 @@ struct mii_bus *bcma_mdio_mii_register(s
210 mii_bus->name = "bcma_mdio mii bus";
211 sprintf(mii_bus->id, "%s-%d-%d", "bcma_mdio", core->bus->num,
212 core->core_unit);
213 - mii_bus->priv = bcma_mdio;
214 + mii_bus->priv = bgmac;
215 mii_bus->read = bcma_mdio_mii_read;
216 mii_bus->write = bcma_mdio_mii_write;
217 mii_bus->reset = bcma_mdio_phy_reset;
218 mii_bus->parent = &core->dev;
219 - mii_bus->phy_mask = ~(1 << phyaddr);
220 -
221 - bcma_mdio->core = core;
222 - bcma_mdio->phyaddr = phyaddr;
223 + mii_bus->phy_mask = ~(1 << bgmac->phyaddr);
224
225 err = mdiobus_register(mii_bus);
226 if (err) {
227 @@ -242,23 +230,17 @@ struct mii_bus *bcma_mdio_mii_register(s
228 err_free_bus:
229 mdiobus_free(mii_bus);
230 err:
231 - kfree(bcma_mdio);
232 return ERR_PTR(err);
233 }
234 EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
235
236 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
237 {
238 - struct bcma_mdio *bcma_mdio;
239 -
240 if (!mii_bus)
241 return;
242
243 - bcma_mdio = mii_bus->priv;
244 -
245 mdiobus_unregister(mii_bus);
246 mdiobus_free(mii_bus);
247 - kfree(bcma_mdio);
248 }
249 EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
250
251 --- a/drivers/net/ethernet/broadcom/bgmac.h
252 +++ b/drivers/net/ethernet/broadcom/bgmac.h
253 @@ -519,7 +519,7 @@ struct bgmac *bgmac_alloc(struct device
254 int bgmac_enet_probe(struct bgmac *bgmac);
255 void bgmac_enet_remove(struct bgmac *bgmac);
256
257 -struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr);
258 +struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac);
259 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus);
260
261 static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)