#ifdef CONFIG_MII
-#undef DEBUG /* define for more debug messages */
-
-
/*****************************************************************************
*
* Read the OUI, manufacture's model number, and revision number.
* Returns:
* 0 on success
*/
-int miiphy_info(unsigned char addr,
- unsigned int *oui,
- unsigned char *model,
- unsigned char *rev)
+int miiphy_info (unsigned char addr,
+ unsigned int *oui,
+ unsigned char *model, unsigned char *rev)
{
- unsigned int reg;
-
- /*
- * 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 *)®) != 0)
- {
-# ifdef DEBUG
- printf("PHY ID register 2 read failed\n");
-# endif
- return(-1);
- }
- reg >>= 16;
- if(miiphy_read(addr, PHY_PHYIDR1, (unsigned short *)®) != 0)
- {
-# ifdef DEBUG
- printf("PHY ID register 1 read failed\n");
-# endif
- return(-1);
- }
- *oui = (reg >> 10);
- *model = (unsigned char)((reg >> 4) & 0x0000003F);
- *rev = (unsigned char)( reg & 0x0000000F);
- return(0);
+ unsigned int reg = 0;
+
+ /*
+ * 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 *) ®) != 0) {
+#ifdef DEBUG
+ printf ("PHY ID register 2 read failed\n");
+#endif
+ return (-1);
+ }
+ reg >>= 16;
+#ifdef DEBUG
+ printf ("PHY_PHYIDR2 @ 0x%x = 0x%04x\n", addr, reg);
+#endif
+
+ if (miiphy_read (addr, PHY_PHYIDR1, (unsigned short *) ®) != 0) {
+#ifdef DEBUG
+ printf ("PHY ID register 1 read failed\n");
+#endif
+ return (-1);
+ }
+#ifdef DEBUG
+ printf ("PHY_PHYIDR[1,2] @ 0x%x = 0x%08x\n", addr, reg);
+#endif
+ *oui = ( reg >> 10);
+ *model = (unsigned char) ((reg >> 4) & 0x0000003F);
+ *rev = (unsigned char) ( reg & 0x0000000F);
+ return (0);
}
* Returns:
* 0 on success
*/
-int miiphy_reset(unsigned char addr)
+int miiphy_reset (unsigned char addr)
{
- unsigned short reg;
- int loop_cnt;
-
- if(miiphy_write(addr, PHY_BMCR, 0x8000) != 0)
- {
-# ifdef DEBUG
- printf("PHY reset failed\n");
-# endif
- return(-1);
- }
-
- /*
- * Poll the control register for the reset bit to go to 0 (it is
- * auto-clearing). This should happen within 0.5 seconds per the
- * IEEE spec.
- */
- loop_cnt = 0;
- reg = 0x8000;
- while(((reg & 0x8000) != 0) && (loop_cnt++ < 1000000))
- {
- if(miiphy_read(addr, PHY_BMCR, ®) != 0)
- {
+ unsigned short reg;
+ int loop_cnt;
+
+ if (miiphy_write (addr, PHY_BMCR, 0x8000) != 0) {
+#ifdef DEBUG
+ printf ("PHY reset failed\n");
+#endif
+ return (-1);
+ }
+
+ /*
+ * Poll the control register for the reset bit to go to 0 (it is
+ * auto-clearing). This should happen within 0.5 seconds per the
+ * IEEE spec.
+ */
+ loop_cnt = 0;
+ reg = 0x8000;
+ while (((reg & 0x8000) != 0) && (loop_cnt++ < 1000000)) {
+ if (miiphy_read (addr, PHY_BMCR, ®) != 0) {
# ifdef DEBUG
- printf("PHY status read failed\n");
+ printf ("PHY status read failed\n");
# endif
- return(-1);
- }
- }
- if((reg & 0x8000) == 0)
- {
- return(0);
- }
- else
- {
- printf("PHY reset timed out\n");
- return(-1);
- }
- return(0);
+ return (-1);
+ }
+ }
+ if ((reg & 0x8000) == 0) {
+ return (0);
+ } else {
+ printf ("PHY reset timed out\n");
+ return (-1);
+ }
+ return (0);
}
*
* Determine the ethernet speed (10/100).
*/
-int miiphy_speed(unsigned char addr)
+int miiphy_speed (unsigned char addr)
{
- unsigned short reg;
-
- if(miiphy_read(addr, PHY_ANLPAR, ®))
- {
- printf("PHY speed1 read failed, assuming 10bT\n");
- return(_10BASET);
- }
-
- if((reg & PHY_ANLPAR_100) != 0)
- {
- return(_100BASET);
- }
- else
- {
- return(_10BASET);
- }
+ unsigned short reg;
+
+ if (miiphy_read (addr, PHY_ANLPAR, ®)) {
+ printf ("PHY speed1 read failed, assuming 10bT\n");
+ return (_10BASET);
+ }
+
+ if ((reg & PHY_ANLPAR_100) != 0) {
+ return (_100BASET);
+ } else {
+ return (_10BASET);
+ }
}
*
* Determine full/half duplex.
*/
-int miiphy_duplex(unsigned char addr)
+int miiphy_duplex (unsigned char addr)
{
- unsigned short reg;
-
- if(miiphy_read(addr, PHY_ANLPAR, ®))
- {
- printf("PHY duplex read failed, assuming half duplex\n");
- return(HALF);
- }
-
- if((reg & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD)) != 0)
- {
- return(FULL);
- }
- else
- {
- return(HALF);
- }
+ unsigned short reg;
+
+ if (miiphy_read (addr, PHY_ANLPAR, ®)) {
+ printf ("PHY duplex read failed, assuming half duplex\n");
+ return (HALF);
+ }
+
+ if ((reg & (PHY_ANLPAR_10FD | PHY_ANLPAR_TXFD)) != 0) {
+ return (FULL);
+ } else {
+ return (HALF);
+ }
}
-#endif /* CONFIG_MII */
-
+#endif /* CONFIG_MII */