[U-Boot-Users] [PATCH] TSEC driver: Change MDIO support to allow access to any PHYs on the MDIO bus

The current TSEC driver limits MDIO access to the devices that have been configured as attached to a TSEC MAC. This patch allows access to any PHY device on the MDIO bus through the 'mii' commands.
Signed-off-by: Michael Firth michael.firth@bt.com
diff -urN u-boot-1.3.1-orig/drivers/net/tsec.c u-boot-1.3.1/drivers/net/tsec.c --- u-boot-1.3.1-orig/drivers/net/tsec.c 2007-12-06 09:21:19.000000000 +0000 +++ u-boot-1.3.1/drivers/net/tsec.c 2008-01-09 20:19:36.000000000 +0000 @@ -241,10 +244,9 @@ * It will wait for the write to be done (or for a timeout to * expire) before exiting */ -void write_phy_reg(struct tsec_private *priv, uint regnum, uint value) +void write_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum, uint value) { volatile tsec_t *regbase = priv->phyregs; - uint phyid = priv->phyaddr; int timeout = 1000000;
regbase->miimadd = (phyid << 8) | regnum; @@ -255,17 +257,19 @@ while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ; }
+/* #define to provide old write_phy_reg functionality without duplicating code */ +#define write_phy_reg(priv, regnum, value) write_any_phy_reg(priv,priv->phyaddr,regnum,value) + /* Reads register regnum on the device's PHY through the * registers specified in priv. It lowers and raises the read * command, and waits for the data to become valid (miimind * notvalid bit cleared), and the bus to cease activity (miimind * busy bit cleared), and then returns the value */ -uint read_phy_reg(struct tsec_private *priv, uint regnum) +uint read_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum) { uint value; volatile tsec_t *regbase = priv->phyregs; - uint phyid = priv->phyaddr;
/* Put the address of the phy, and the register * number into MIIMADD */ @@ -288,6 +292,9 @@ return value; }
+/* #define to provide old read_phy_reg functionality without duplicating code */ +#define read_phy_reg(priv,regnum) read_any_phy_reg(priv,priv->phyaddr,regnum) + /* Discover which PHY is attached to the device, and configure it * properly. If the PHY is not recognized, then return 0 * (failure). Otherwise, return 1 @@ -1487,18 +1494,6 @@ #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ && !defined(BITBANGMII)
-struct tsec_private *get_priv_for_phy(unsigned char phyaddr) -{ - int i; - - for (i = 0; i < MAXCONTROLLERS; i++) { - if (privlist[i]->phyaddr == phyaddr) - return privlist[i]; - } - - return NULL; -} - /* * Read a MII PHY register. * @@ -1509,14 +1504,14 @@ unsigned char reg, unsigned short *value) { unsigned short ret; - struct tsec_private *priv = get_priv_for_phy(addr); + struct tsec_private *priv = privlist[0];
if (NULL == priv) { printf("Can't read PHY at address %d\n", addr); return -1; }
- ret = (unsigned short)read_phy_reg(priv, reg); + ret = (unsigned short)read_any_phy_reg(priv, addr, reg); *value = ret;
return 0; @@ -1531,14 +1526,14 @@ static int tsec_miiphy_write(char *devname, unsigned char addr, unsigned char reg, unsigned short value) { - struct tsec_private *priv = get_priv_for_phy(addr); + struct tsec_private *priv = privlist[0];
if (NULL == priv) { printf("Can't write PHY at address %d\n", addr); return -1; }
- write_phy_reg(priv, reg, value); + write_any_phy_reg(priv, addr, reg, value);
return 0; }

On Jan 16, 2008 5:40 AM, michael.firth@bt.com wrote:
The current TSEC driver limits MDIO access to the devices that have been configured as attached to a TSEC MAC. This patch allows access to any PHY device on the MDIO bus through the 'mii' commands.
Signed-off-by: Michael Firth michael.firth@bt.com
Acked-by: Andy Fleming afleming@freescale.com
participants (2)
-
Andy Fleming
-
michael.firth@bt.com