Subject: [PATCH] net: support MII commands on QE UEC

From: Kim Phillips <[email-masked]>
Date: Tue, 4 Dec 2007 16:03:56 -0600

Add uec miiphy read and write functions, and register them if MII commands
are configured.

From: Dan Malek <[email-masked]>
Signed-off-by: Kim Phillips <[email-masked]>
---
 drivers/qe/uec.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/drivers/qe/uec.c b/drivers/qe/uec.c
index a27c12a..ae7a5c1 100644
--- a/drivers/qe/uec.c
+++ b/drivers/qe/uec.c
@@ -21,6 +21,7 @@
 
 #include "common.h"
 #include "net.h"
+#include "miiphy.h"
 #include "malloc.h"
 #include "asm/errno.h"
 #include "asm/io.h"
@@ -88,6 +89,9 @@ static uec_info_t eth3_uec_info = {
 };
 #endif
 
+/* needed for the u-boot mii command interface */
+static struct eth_device	*eth_devs[2];
+
 static int uec_mac_enable(uec_private_t *uec, comm_dir_e mode)
 {
 	uec_t		*uec_regs;
@@ -1228,6 +1232,50 @@ static int uec_recv(struct eth_device* dev)
 	return 1;
 }
 
+/*
+ * Read a MII PHY register.
+ *
+ * Returns:
+ *  0 on success
+ */
+static int uec_miiphy_read(char *devname, unsigned char addr,
+			    unsigned char reg, unsigned short *value)
+{
+	unsigned short	ret;
+	int		index;
+	struct eth_device	*dev;
+
+	/* devname is 'FSL UECn', so generate an index from that */
+	index = devname[7] - '0';
+	dev = eth_devs[index];
+
+	ret = (unsigned short)uec_read_phy_reg(dev, addr, reg);
+	*value = ret;
+
+	return 0;
+}
+
+/*
+ * Write a MII PHY register.
+ *
+ * Returns:
+ *  0 on success
+ */
+static int uec_miiphy_write(char *devname, unsigned char addr,
+			     unsigned char reg, unsigned short value)
+{
+	int		index;
+	struct eth_device	*dev;
+
+	/* devname is 'FSL UECn', so generate an index from that */
+	index = devname[7] - '0';
+	dev = eth_devs[index];
+
+	uec_write_phy_reg(dev, addr, reg, value);
+
+	return 0;
+}
+
 int uec_initialize(int index)
 {
 	struct eth_device	*dev;
@@ -1282,12 +1330,17 @@ int uec_initialize(int index)
 
 	eth_register(dev);
 
+	eth_devs[index] = dev;
+
 	err = uec_startup(uec);
 	if (err) {
 		printf("%s: Cannot configure net device, aborting.",dev->name);
 		return err;
 	}
 
+#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) && !defined(BITBANGMII)
+	miiphy_register(dev->name, uec_miiphy_read, uec_miiphy_write);
+#endif
 	err = init_phy(dev);
 	if (err) {
 		printf("%s: Cannot initialize PHY, aborting.\n", dev->name);
-- 
1.5.3