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