Skip to contentSkip to conversation

Fix for MII utils

U-Boot-Users Steven Scholz 2 participants 6 messages Oct 20, 2003 – Dec 6, 2003

lore
Share & tools
lore
#0 lore raw

Hi there,

the attached patch addresses two MII related issues:
a) mii info <addr> ignored <addr> and always showed info for 32 PHYs
b) The "Trick" mentioned in miiphy_info():
" * Trick: we are reading two 16 registers into a 32 bit variable
* so we do a 16 read into the high order bits of the variable (big
* endian, you know), shift it down 16 bits, and the read the rest."
does obviously not work on little endian machines.

* Patch by Steven Scholz, 20 Oct 2003
- "mii info <addr>" now only shows the info for PHY "addr" as the help message already suggests
- Endian fix for miiphy_info()

Thanks,

Steven

#2 lore raw
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines

* Patch by Steven Scholz, 20 Oct 2003
- "mii info <addr>" now only shows the info for PHY "addr" as the help message already suggests
- Endian fix for miiphy_info()

Added. Sorry it took so long.

Best regards,

Wolfgang Denk

Signature · 5 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
Genius doesn't work on an assembly line basis.  You can't simply say,
"Today I will be brilliant."
	-- Kirk, "The Ultimate Computer", stardate 4731.3
#3 lore raw
In reply to Steven Scholz
Quoted 2 lines · In message <[email protected]> you wrote:

the attached patch addresses two MII related issues:

Patch missing.

Best regards,

Wolfgang Denk

Signature · 3 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd at denx.de
Eschew obfuscation.
#5 lore raw

Steven Scholz wrote:

Any comments on the patch?

Quoted 78 lines

------------------------------------------------------------------------

Index: common/cmd_mii.c
===================================================================
RCS file: /cvsroot/u-boot/u-boot/common/cmd_mii.c,v retrieving revision 1.4
diff -p -u -r1.4 cmd_mii.c

cmd_mii.c +8 -2
@@ -81,7 +81,7 @@ int do_mii (cmd_tbl_t * cmdtp, int flag,
 	 * check info/read/write.
 	 */
 	if (op == 'i') {
-		int j;
+		unsigned char j, start, end;
 		unsigned int oui;
 		unsigned char model;
 		unsigned char rev;
@@ -89,7 +89,13 @@ int do_mii (cmd_tbl_t * cmdtp, int flag,
 		/*
 		 * Look for any and all PHYs.  Valid addresses are 0..31.
 		 */
-		for (j = 0; j < 32; j++) {
+		if (argc >= 3) {
+			start = addr; end = addr + 1;
+		} else {
+			start = 0; end = 32;
+		}
+
+		for (j = start; j < end; j++) {
 			if (miiphy_info (j, &oui, &model, &rev) == 0) {
 				printf ("PHY 0x%02X: "
 					"OUI = 0x%04X, "

Index: common/miiphyutil.c
===================================================================
RCS file: /cvsroot/u-boot/u-boot/common/miiphyutil.c,v retrieving revision 1.2
diff -p -u -r1.2 miiphyutil.c

miiphyutil.c +5 -8
@@ -47,19 +47,15 @@ int miiphy_info (unsigned char addr,
 		 unsigned char *model, unsigned char *rev)
 {
 	unsigned int reg = 0;
+	unsigned short tmp;
 
-	/*
-	 * Trick: we are reading two 16 registers into a 32 bit variable
-	 * so we do a 16 read into the high order bits of the variable (big
-	 * endian, you know), shift it down 16 bits, and the read the rest.
-	 */
-	if (miiphy_read (addr, PHY_PHYIDR2, (unsigned short *) &reg) != 0) {
+	if (miiphy_read (addr, PHY_PHYIDR2, &tmp) != 0) {
 #ifdef DEBUG
 		printf ("PHY ID register 2 read failed\n");
 #endif
 		return (-1);
 	}
-	reg >>= 16;
+	reg = tmp;
 
 #ifdef DEBUG
 	printf ("PHY_PHYIDR2 @ 0x%x = 0x%04x\n", addr, reg);
@@ -69,12 +65,13 @@ int miiphy_info (unsigned char addr,
 		return (-1);
 	}
 
-	if (miiphy_read (addr, PHY_PHYIDR1, (unsigned short *) &reg) != 0) {
+	if (miiphy_read (addr, PHY_PHYIDR1, &tmp) != 0) {
 #ifdef DEBUG
 		printf ("PHY ID register 1 read failed\n");
 #endif
 		return (-1);
 	}
+	reg |= tmp << 16;
 #ifdef DEBUG
 	printf ("PHY_PHYIDR[1,2] @ 0x%x = 0x%08x\n", addr, reg);
 #endif
Signature · 8 lines
Steven Scholz

imc Measurement & Control               imc Me?systeme GmbH
Voltastr. 5                             Voltastr. 5
13355 Berlin                            13355 Berlin
Germany                                 Deutschland
fon: +49 30 467090-0                    Tel: 030 / 467090-0
fax: +49 30 4631576                     fax: 030 / 4631576