[U-Boot] [PATCH 18/51] cmd: mdio: Add 'driver' subcommand

Mario Six mario.six at gdsys.cc
Fri Jul 14 12:55:04 UTC 2017


For debug purposes it is sometimes useful to have the ability to
interact with the driver functionality of a phy from the command line
(e.g. to manually issue startup, configuration, or shutdown commands to
the phy device).

This patch adds such a command, which allows issuing the following
commands to a phy:
 * getting the driver's name
 * running the phy's configuration procedure (via calling phy_config)
 * running the phy's startup procedure (via calling phy_startup)
 * running the phy's shutdown procedure (via calling phy_shutdown)

Signed-off-by: Mario Six <mario.six at gdsys.cc>
---

 cmd/Kconfig |  6 ++++++
 cmd/mdio.c  | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 322e466313..6425c425d6 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -835,6 +835,12 @@ config CMD_MII
 	help
 	  Enable MII utility commands.
 
+config CMD_MII_DRIVER
+	bool "mii driver"
+	depends on CMD_MII
+	help
+	  Enable MII driver utility command.
+
 config CMD_PING
 	bool "ping"
 	help
diff --git a/cmd/mdio.c b/cmd/mdio.c
index 3f11963006..abd763ef1c 100644
--- a/cmd/mdio.c
+++ b/cmd/mdio.c
@@ -180,6 +180,37 @@ static int extract_phy_range(char *const argv[], int argc, struct mii_dev **bus,
 	return extract_range(argv[0], addrlo, addrhi);
 }
 
+#ifdef CONFIG_CMD_MII_DRIVER
+static struct phy_device *extract_phydev(char *const argv[], int argc)
+{
+	struct phy_device *phydev;
+	struct mii_dev *bus;
+	int addr;
+
+	if (argc == 1) {
+		phydev = mdio_phydev_for_ethname(argv[0]);
+
+		if (phydev)
+			return phydev;
+
+		bus = mdio_get_current_dev();
+	} else {
+		bus = miiphy_get_dev_by_name(argv[0]);
+	}
+
+	if (!bus)
+		return NULL;
+
+	addr = simple_strtol(argv[1], NULL, 0);
+	if (addr >= PHY_MAX_ADDR)
+		return NULL;
+
+	phydev = bus->phymap[addr];
+
+	return phydev;
+}
+#endif
+
 /* ---------------------------------------------------------------- */
 static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -212,6 +243,36 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (flag & CMD_FLAG_REPEAT)
 		op[0] = last_op[0];
 
+#ifdef CONFIG_CMD_MII_DRIVER
+	if (op[0] == 'd') {
+		if ((argc < 4) || (argc > 5) || (strlen(argv[2]) < 2))
+			return CMD_RET_USAGE;
+
+		phydev = extract_phydev(&argv[3], argc - 3);
+		if (!phydev)
+			return CMD_RET_USAGE;
+
+		switch (argv[2][1]) {
+		case 'e': /* g'e't */
+			printf("driver: ");
+			if (phydev->drv)
+				printf("%s", phydev->drv->name);
+			printf("\n");
+			break;
+		case 'o': /* c'o'nfig */
+			phy_config(phydev);
+			break;
+		case 't': /* s't'artup */
+			phy_startup(phydev);
+			break;
+		case 'h': /* s'h'utdown */
+			phy_shutdown(phydev);
+			break;
+		}
+		return 0;
+	}
+#endif
+
 	if (strlen(argv[1]) > 1) {
 		op[1] = argv[1][1];
 		if (op[1] == 'x') {
@@ -304,6 +365,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"
+#ifdef CONFIG_CMD_MII_DRIVER
+	"mdio driver <get | config | startup | shutdown> <phydev> - "
+		"<get | config | startup | shutdown> phy driver\n"
+#endif
 	"<phydev> may be:\n"
 	"   <busname>  <addr>\n"
 	"   <addr>\n"
-- 
2.11.0



More information about the U-Boot mailing list