X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fmiiphyutil.c;h=9cf845f605dca3940c821976247b647847a91636;hb=a80603598cef13ab8031b514a603ef1a6169d249;hp=e055c08fbd6aef22e907693b00952dd6657674b7;hpb=0daac97801fa5989d3740487aa824fbab9ff0503;p=u-boot diff --git a/common/miiphyutil.c b/common/miiphyutil.c index e055c08fbd..9cf845f605 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -162,6 +162,20 @@ const char *miiphy_get_current_dev(void) return NULL; } +static struct mii_dev *miiphy_get_active_dev(const char *devname) +{ + /* If the current mii is the one we want, return it */ + if (current_mii) + if (strcmp(current_mii->name, devname) == 0) + return current_mii; + + /* Otherwise, set the active one to the one we want */ + if (miiphy_set_current_dev(devname)) + return NULL; + else + return current_mii; +} + /***************************************************************************** * * Read to variable from the PHY attached to device , @@ -175,7 +189,7 @@ int miiphy_read(const char *devname, unsigned char addr, unsigned char reg, { struct mii_dev *dev; - dev = miiphy_get_dev_by_name(devname, 0); + dev = miiphy_get_active_dev(devname); if (dev) return dev->read(devname, addr, reg, value); @@ -195,7 +209,7 @@ int miiphy_write(const char *devname, unsigned char addr, unsigned char reg, { struct mii_dev *dev; - dev = miiphy_get_dev_by_name(devname, 0); + dev = miiphy_get_active_dev(devname); if (dev) return dev->write(devname, addr, reg, value);