public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [U-boot] [PATCH 1/2] NET: QE: UEC: Make uec_miiphy_read() and uec_miiphy_write() use the devname arg.
@ 2008-08-18 19:46 richardretanubun
  2008-08-18 21:00 ` Ben Warren
  0 siblings, 1 reply; 11+ messages in thread
From: richardretanubun @ 2008-08-18 19:46 UTC (permalink / raw)
  To: u-boot

Added a new function uec_miiphy_find_dev_by_name to allow uec_miiphy_read 
and uec_miiphy_write to use the passed devname and not hardcoded to devlist[0]

Signed-off-by: Richard Retanubun <RichardRetanubun_at_ruggedcom.com>

diff --git a/drivers/qe/uec.c b/drivers/qe/uec.c
index 344c649..d14566e 100644
--- a/drivers/qe/uec.c
+++ b/drivers/qe/uec.c
@@ -639,6 +639,32 @@ static void phy_change(struct eth_device *dev)
 	&& !defined(BITBANGMII)
 
 /*
+ * Find a device index from the devlist by name
+ *
+ * Returns:
+ *  The index where the device is located, else 0
+ */
+static int uec_miiphy_find_dev_by_name(char *devname)
+{
+	int i = 0;
+
+
+	for (i = 0; i < MAXCONTROLLERS; i++) {
+		if (strncmp(devname, devlist[i]->name, strlen(devname)) == 0) {
+			break;
+		}
+	}
+
+	// If device cannot be found, default to 0
+	if (i == MAXCONTROLLERS) {
+		debug ("%s: device %s not found in devlist\n", __FUNCTION__, devname);
+		i = 0;
+	}
+
+	return (i);
+}
+
+/*
  * Read a MII PHY register.
  *
  * Returns:
@@ -647,8 +673,15 @@ static void phy_change(struct eth_device *dev)
 static int uec_miiphy_read(char *devname, unsigned char addr,
 			    unsigned char reg, unsigned short *value)
 {
-	*value = uec_read_phy_reg(devlist[0], addr, reg);
+	int i = 0;
+
 
+	if (devname == NULL || value == NULL) {
+		debug("%s: NULL pointer given\n", __FUNCTION__);
+	} else {
+		i = uec_miiphy_find_dev_by_name(devname);
+		*value = uec_read_phy_reg(devlist[i], addr, reg);
+	}
 	return 0;
 }
 
@@ -661,11 +694,17 @@ static int uec_miiphy_read(char *devname, unsigned char addr,
 static int uec_miiphy_write(char *devname, unsigned char addr,
 			     unsigned char reg, unsigned short value)
 {
-	uec_write_phy_reg(devlist[0], addr, reg, value);
+	int i = 0;
+
 
+	if (devname == NULL) {
+		debug("%s: NULL pointer given\n", __FUNCTION__);
+	} else {
+		i = uec_miiphy_find_dev_by_name(devname);
+		uec_write_phy_reg(devlist[i], addr, reg, value);
+	}
 	return 0;
 }
-
 #endif
 
 static int uec_set_mac_address(uec_private_t *uec, u8 *mac_addr)

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-10-14  5:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-18 19:46 [U-Boot] [U-boot] [PATCH 1/2] NET: QE: UEC: Make uec_miiphy_read() and uec_miiphy_write() use the devname arg richardretanubun
2008-08-18 21:00 ` Ben Warren
2008-08-18 22:28   ` [U-Boot] [U-boot] [PATCHv2 " richardretanubun
2008-09-05  4:30     ` Ben Warren
2008-09-16 12:49       ` richardretanubun
2008-09-24 22:10         ` richardretanubun
2008-09-26  6:46           ` Ben Warren
2008-09-26 12:52             ` richardretanubun
2008-09-26 12:59               ` richardretanubun
2008-10-06 19:36                 ` richardretanubun
2008-10-14  5:52                   ` Ben Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox