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
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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.
13 This simplifies code & allows access to all bgmac driver details from
14 all places in bcma code.
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>
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(-)
25 --- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
26 +++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
28 #include <linux/brcmphy.h>
32 - struct bcma_device *core;
36 static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask,
37 u32 value, int timeout)
39 @@ -37,7 +32,7 @@ static bool bcma_mdio_wait_value(struct
41 **************************************************/
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)
46 struct bcma_device *core;
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);
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;
59 - core = bcma_mdio->core;
60 + core = bgmac->bcma.core;
61 phy_access_addr = BGMAC_PHY_ACCESS;
62 phy_ctl_addr = BGMAC_PHY_CNTL;
64 @@ -87,7 +82,7 @@ static u16 bcma_mdio_phy_read(struct bcm
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,
72 struct bcma_device *core;
73 @@ -95,12 +90,12 @@ static int bcma_mdio_phy_write(struct bc
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;
84 - core = bcma_mdio->core;
85 + core = bgmac->bcma.core;
86 phy_access_addr = BGMAC_PHY_ACCESS;
87 phy_ctl_addr = BGMAC_PHY_CNTL;
89 @@ -110,8 +105,8 @@ static int bcma_mdio_phy_write(struct bc
91 bcma_write32(core, phy_ctl_addr, tmp);
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");
100 @@ -132,39 +127,39 @@ static int bcma_mdio_phy_write(struct bc
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)
107 - struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo;
108 + struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo;
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);
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;
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);
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)
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;
168 - if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS)
169 + if (phyaddr == BGMAC_PHY_NOREGS)
172 - bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET);
173 + bcma_mdio_phy_write(bgmac, phyaddr, MII_BMCR, BMCR_RESET);
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);
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);
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)
191 - struct bcma_mdio *bcma_mdio;
192 + struct bcma_device *core = bgmac->bcma.core;
193 struct mii_bus *mii_bus;
196 - bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL);
198 - return ERR_PTR(-ENOMEM);
200 mii_bus = mdiobus_alloc();
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,
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);
216 mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
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;
222 - bcma_mdio->core = core;
223 - bcma_mdio->phyaddr = phyaddr;
225 err = mdiobus_register(mii_bus);
227 dev_err(&core->dev, "Registration of mii bus failed\n");
228 @@ -252,24 +240,18 @@ err_free_irq:
230 mdiobus_free(mii_bus);
235 EXPORT_SYMBOL_GPL(bcma_mdio_mii_register);
237 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus)
239 - struct bcma_mdio *bcma_mdio;
244 - bcma_mdio = mii_bus->priv;
246 mdiobus_unregister(mii_bus);
248 mdiobus_free(mii_bus);
251 EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister);
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
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);
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);
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);
274 static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)