mdio: add subcommand 'up' to check for link

- performs a phy startup sequence and checks result
- returns 0 when link is up, 1 if no link could be established

BugzID: 55019
This commit is contained in:
Rene Straub 2019-01-05 12:06:08 +01:00
parent 84189ee455
commit 377367a723
1 changed files with 38 additions and 2 deletions

View File

@ -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 <devad>.<reg>\n"
"mdio wx <phydev> [<devad>.]<reg> <data> - "
"write PHY's extended register at <devad>.<reg>\n"
"mdio up <phydev> - wait for PHY link to become ready (up)\n"
"<phydev> may be:\n"
" <busname> <addr>\n"
" <addr>\n"