summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-07-27 18:35:10 -0400
committerBen Warren <biggerbadderben@gmail.com>2010-08-09 11:52:30 -0700
commitede16ea32da7a37f892bf63dcb43c16118ba39d6 (patch)
treec3bf1533645b7f30824e8d2649f3ee46ad0dff6a
parent0daac97801fa5989d3740487aa824fbab9ff0503 (diff)
downloadu-boot-imx-ede16ea32da7a37f892bf63dcb43c16118ba39d6.zip
u-boot-imx-ede16ea32da7a37f892bf63dcb43c16118ba39d6.tar.gz
u-boot-imx-ede16ea32da7a37f892bf63dcb43c16118ba39d6.tar.bz2
miiphy: leverage current_mii cache more
For code that uses miiphy_{read,write}, every call invokes a full look up of the mii list. There is already a "current_mii" cache that is used by some code, but have the miiphy_{read,write} function use it as well. This does increase the code size slightly, but I think it's worth it. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
-rw-r--r--common/miiphyutil.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index e055c08..9cf845f 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 <value> from the PHY attached to device <devname>,
@@ -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);