[U-Boot] [PATCH v4 3/3] cmd: mdio: Add new parameter to access MMD PHY registers

Carlo Caione ccaione at baylibre.com
Thu Jan 24 08:56:00 UTC 2019


Two new parameters (rmmd and wmmd) are added to allow the `mdio` command
to access the content of the MMD PHY registers.

Signed-off-by: Carlo Caione <ccaione at baylibre.com>
Acked-by: Joe Hershberger <joe.hershberger at ni.com>
---
 cmd/mdio.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/cmd/mdio.c b/cmd/mdio.c
index 184868063a..5138db505a 100644
--- a/cmd/mdio.c
+++ b/cmd/mdio.c
@@ -43,7 +43,7 @@ static int mdio_write_ranges(struct phy_device *phydev, struct mii_dev *bus,
 			     int addrlo,
 			     int addrhi, int devadlo, int devadhi,
 			     int reglo, int reghi, unsigned short data,
-			     int extended)
+			     int extended, int mmd)
 {
 	int addr, devad, reg;
 	int err = 0;
@@ -51,12 +51,15 @@ static int mdio_write_ranges(struct phy_device *phydev, struct mii_dev *bus,
 	for (addr = addrlo; addr <= addrhi; addr++) {
 		for (devad = devadlo; devad <= devadhi; devad++) {
 			for (reg = reglo; reg <= reghi; reg++) {
-				if (!extended)
-					err = bus->write(bus, addr, devad,
-							 reg, data);
-				else
+				if (mmd)
+					err = phy_write_mmd(phydev, devad, reg,
+							    data);
+				else if (extended)
 					err = phydev->drv->writeext(phydev,
 							addr, devad, reg, data);
+				else
+					err = bus->write(bus, addr, devad,
+							 reg, data);
 
 				if (err)
 					goto err_out;
@@ -71,7 +74,7 @@ err_out:
 static int mdio_read_ranges(struct phy_device *phydev, struct mii_dev *bus,
 			    int addrlo,
 			    int addrhi, int devadlo, int devadhi,
-			    int reglo, int reghi, int extended)
+			    int reglo, int reghi, int extended, int mmd)
 {
 	int addr, devad, reg;
 
@@ -83,11 +86,13 @@ static int mdio_read_ranges(struct phy_device *phydev, struct mii_dev *bus,
 			for (reg = reglo; reg <= reghi; reg++) {
 				int val;
 
-				if (!extended)
-					val = bus->read(bus, addr, devad, reg);
-				else
+				if (mmd)
+					val = phy_read_mmd(phydev, devad, reg);
+				else if (extended)
 					val = phydev->drv->readext(phydev, addr,
 						devad, reg);
+				else
+					val = bus->read(bus, addr, devad, reg);
 
 				if (val < 0) {
 					printf("Error\n");
@@ -189,6 +194,7 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct mii_dev *bus;
 	struct phy_device *phydev = NULL;
 	int extended = 0;
+	int mmd = 0;
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
@@ -222,14 +228,26 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 				bus = phydev->bus;
 				extended = 1;
 			} else {
-				return -1;
+				return CMD_RET_FAILURE;
 			}
 
 			if (!phydev->drv ||
 			    (!phydev->drv->writeext && (op[0] == 'w')) ||
 			    (!phydev->drv->readext && (op[0] == 'r'))) {
 				puts("PHY does not have extended functions\n");
-				return -1;
+				return CMD_RET_FAILURE;
+			}
+		}
+		if (op[1] == 'm') {
+			phydev = mdio_phydev_for_ethname(argv[2]);
+
+			if (phydev) {
+				addrlo = phydev->addr;
+				addrhi = addrlo;
+				bus = phydev->bus;
+				mmd = 1;
+			} else {
+				return CMD_RET_FAILURE;
 			}
 		}
 	}
@@ -242,13 +260,13 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (pos > 1)
 			if (extract_reg_range(argv[pos--], &devadlo, &devadhi,
 					      &reglo, &reghi))
-				return -1;
+				return CMD_RET_FAILURE;
 
 	default:
 		if (pos > 1)
 			if (extract_phy_range(&argv[2], pos - 1, &bus,
 					      &phydev, &addrlo, &addrhi))
-				return -1;
+				return CMD_RET_FAILURE;
 
 		break;
 	}
@@ -265,12 +283,12 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	switch (op[0]) {
 	case 'w':
 		mdio_write_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
-				  reglo, reghi, data, extended);
+				  reglo, reghi, data, extended, mmd);
 		break;
 
 	case 'r':
 		mdio_read_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi,
-				 reglo, reghi, extended);
+				 reglo, reghi, extended, mmd);
 		break;
 	}
 
@@ -303,6 +321,10 @@ U_BOOT_CMD(
 		"read PHY's extended register at <devad>.<reg>\n"
 	"mdio wx <phydev> [<devad>.]<reg> <data> - "
 		"write PHY's extended register at <devad>.<reg>\n"
+	"mdio rmmd <phydev> [<devad>.]<reg> - "
+		"read PHY's extended register at <devad>.<reg>\n"
+	"mdio wmmd <phydev> [<devad>.]<reg> <data> - "
+		"write PHY's extended register at <devad>.<reg>\n"
 	"<phydev> may be:\n"
 	"   <busname>  <addr>\n"
 	"   <addr>\n"
-- 
2.19.1



More information about the U-Boot mailing list