diff --git a/cmd/mdio.c b/cmd/mdio.c index fb13d05075..46048c90cd 100644 --- a/cmd/mdio.c +++ b/cmd/mdio.c @@ -24,6 +24,29 @@ static uint last_devad_hi; static uint last_reg_lo; static uint last_reg_hi; + +static int mdio_wait_for_link(struct phy_device *phydev, struct mii_dev *bus) +{ + int link; + int res; + + printf("waiting for link up on %s\n", bus->name); + + phy_startup(phydev); + + link = phydev->link; + if (link) { + printf("link up\n"); + res = 0; + } + else { + printf("no link\n"); + res = 1; + } + + return res; +} + static int extract_range(char *input, int *plo, int *phi) { char *end; @@ -191,6 +214,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 res = 0; if (argc < 2) return CMD_RET_USAGE; @@ -213,7 +237,14 @@ 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]; - if (strlen(argv[1]) > 1) { + if (strcmp(argv[1], "up") == 0) { + if (argc >= 3) { + phydev = mdio_phydev_for_ethname(argv[2]); + } else { + return CMD_RET_USAGE; + } + } + else if (strlen(argv[1]) > 1) { op[1] = argv[1][1]; if (op[1] == 'x') { phydev = mdio_phydev_for_ethname(argv[2]); @@ -274,6 +305,10 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) mdio_read_ranges(phydev, bus, addrlo, addrhi, devadlo, devadhi, reglo, reghi, extended); break; + + case 'u': + res = mdio_wait_for_link(phydev, bus); + break; } /* @@ -288,7 +323,7 @@ static int do_mdio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) last_reg_hi = reghi; last_data = data; - return 0; + return res; } /***************************************************/ @@ -305,6 +340,7 @@ U_BOOT_CMD( "read PHY's extended register at .\n" "mdio wx [.] - " "write PHY's extended register at .\n" + "mdio up - wait for PHY link to become ready (up)\n" " may be:\n" " \n" " \n"