Skip to content

Commit 4f8d81b

Browse files
lategoodbyedavem330
authored andcommitted
net: bcmgenet: Refactor register access in bcmgenet_mii_config
The register access in bcmgenet_mii_config() is a little bit opaque and not easy to extend. In preparation for the missing RGMII PHY modes move all the phy name assignments into the switch statement and the register access to the end of the function. This make the code easier to read and extend. Signed-off-by: Stefan Wahren <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a50e3a9 commit 4f8d81b

File tree

1 file changed

+20
-22
lines changed
  • drivers/net/ethernet/broadcom/genet

1 file changed

+20
-22
lines changed

drivers/net/ethernet/broadcom/genet/bcmmii.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
213213
udelay(2);
214214
}
215215

216-
priv->ext_phy = !priv->internal_phy &&
217-
(priv->phy_interface != PHY_INTERFACE_MODE_MOCA);
218-
219216
switch (priv->phy_interface) {
220217
case PHY_INTERFACE_MODE_INTERNAL:
218+
phy_name = "internal PHY";
219+
/* fall through */
221220
case PHY_INTERFACE_MODE_MOCA:
222221
/* Irrespective of the actually configured PHY speed (100 or
223222
* 1000) GENETv4 only has an internal GPHY so we will just end
@@ -229,11 +228,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
229228
else
230229
port_ctrl = PORT_MODE_INT_EPHY;
231230

232-
bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
233-
234-
if (priv->internal_phy) {
235-
phy_name = "internal PHY";
236-
} else if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) {
231+
if (!phy_name) {
237232
phy_name = "MoCA";
238233
bcmgenet_moca_phy_setup(priv);
239234
}
@@ -242,11 +237,7 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
242237
case PHY_INTERFACE_MODE_MII:
243238
phy_name = "external MII";
244239
phy_set_max_speed(phydev, SPEED_100);
245-
bcmgenet_sys_writel(priv,
246-
PORT_MODE_EXT_EPHY, SYS_PORT_CTRL);
247-
/* Restore the MII PHY after isolation */
248-
if (bmcr >= 0)
249-
phy_write(phydev, MII_BMCR, bmcr);
240+
port_ctrl = PORT_MODE_EXT_EPHY;
250241
break;
251242

252243
case PHY_INTERFACE_MODE_REVMII:
@@ -261,31 +252,38 @@ int bcmgenet_mii_config(struct net_device *dev, bool init)
261252
port_ctrl = PORT_MODE_EXT_RVMII_50;
262253
else
263254
port_ctrl = PORT_MODE_EXT_RVMII_25;
264-
bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
265255
break;
266256

267257
case PHY_INTERFACE_MODE_RGMII:
268258
/* RGMII_NO_ID: TXC transitions at the same time as TXD
269259
* (requires PCB or receiver-side delay)
270-
* RGMII: Add 2ns delay on TXC (90 degree shift)
271260
*
272261
* ID is implicitly disabled for 100Mbps (RG)MII operation.
273262
*/
263+
phy_name = "external RGMII (no delay)";
274264
id_mode_dis = BIT(16);
275-
/* fall through */
265+
port_ctrl = PORT_MODE_EXT_GPHY;
266+
break;
267+
276268
case PHY_INTERFACE_MODE_RGMII_TXID:
277-
if (id_mode_dis)
278-
phy_name = "external RGMII (no delay)";
279-
else
280-
phy_name = "external RGMII (TX delay)";
281-
bcmgenet_sys_writel(priv,
282-
PORT_MODE_EXT_GPHY, SYS_PORT_CTRL);
269+
/* RGMII_TXID: Add 2ns delay on TXC (90 degree shift) */
270+
phy_name = "external RGMII (TX delay)";
271+
port_ctrl = PORT_MODE_EXT_GPHY;
283272
break;
284273
default:
285274
dev_err(kdev, "unknown phy mode: %d\n", priv->phy_interface);
286275
return -EINVAL;
287276
}
288277

278+
bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
279+
280+
/* Restore the MII PHY after isolation */
281+
if (bmcr >= 0)
282+
phy_write(phydev, MII_BMCR, bmcr);
283+
284+
priv->ext_phy = !priv->internal_phy &&
285+
(priv->phy_interface != PHY_INTERFACE_MODE_MOCA);
286+
289287
/* This is an external PHY (xMII), so we need to enable the RGMII
290288
* block for the interface to work
291289
*/

0 commit comments

Comments
 (0)