Re: [U-Boot] [PATCH 02/17] GRETH: Added support for selecting PHY address from config, PHY address was always set to zero before.

2010-05-26 Thread Wolfgang Denk
Dear Daniel Hellstrom,

In message 1274194143-8994-1-git-send-email-dan...@gaisler.com you wrote:
 Signed-off-by: Daniel Hellstrom dan...@gaisler.com
 ---
  drivers/net/greth.c |   69 +++---
  1 files changed, 43 insertions(+), 26 deletions(-)

Sorry for the late review...

 +#ifdef CONFIG_SYS_GRLIB_GRETH_PHYADDR
 + int phyaddr = CONFIG_SYS_GRLIB_GRETH_PHYADDR;
 +#else
 + int phyaddr = 0;
 +#endif

Please make this:

#ifndef CONFIG_SYS_GRLIB_GRETH_PHYADDR
#define CONFIG_SYS_GRLIB_GRETH_PHYADDR  0
#endif
int phyaddr = CONFIG_SYS_GRLIB_GRETH_PHYADDR;


 +#ifdef DEBUG
 + printf(greth_init_phy: PHY read 1 failed\n);
 +#endif
...
 +#ifdef DEBUG
 + printf(greth_init_phy: PHY read 2 failed\n);
 +#endif

Please change all these into debug() calls and drop the #ifdef's.

Also, this patch needs to go through Ben's networking repository.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Do you suppose the reason the ends of the `Intel Inside'  logo  don't
match up is that it was drawn on a Pentium?
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 02/17] GRETH: Added support for selecting PHY address from config, PHY address was always set to zero before.

2010-05-18 Thread Daniel Hellstrom
Signed-off-by: Daniel Hellstrom dan...@gaisler.com
---
 drivers/net/greth.c |   69 +++---
 1 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/drivers/net/greth.c b/drivers/net/greth.c
index 79bc4d9..a1a88f9 100644
--- a/drivers/net/greth.c
+++ b/drivers/net/greth.c
@@ -45,7 +45,7 @@
 /* ByPass Cache when reading regs */
 #define GRETH_REGLOAD(addr)SPARC_NOCACHE_READ(addr)
 /* Write-through cache == no bypassing needed on writes */
-#define GRETH_REGSAVE(addr,data)   (*(unsigned int *)(addr) = (data))
+#define GRETH_REGSAVE(addr,data) (*(volatile unsigned int *)(addr) = (data))
 #define GRETH_REGORIN(addr,data) GRETH_REGSAVE(addr,GRETH_REGLOAD(addr)|data)
 #define GRETH_REGANDIN(addr,data) GRETH_REGSAVE(addr,GRETH_REGLOAD(addr)data)
 
@@ -102,12 +102,12 @@ typedef struct {
 } greth_priv;
 
 /* Read MII register 'addr' from core 'regs' */
-static int read_mii(int addr, volatile greth_regs * regs)
+static int read_mii(int phyaddr, int regaddr, volatile greth_regs * regs)
 {
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
 
-   GRETH_REGSAVE(regs-mdio, (0  11) | ((addr  0x1F)  6) | 2);
+   GRETH_REGSAVE(regs-mdio, ((phyaddr  0x1F)  11) | ((regaddr  0x1F) 
 6) | 2);
 
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
@@ -119,14 +119,14 @@ static int read_mii(int addr, volatile greth_regs * regs)
}
 }
 
-static void write_mii(int addr, int data, volatile greth_regs * regs)
+static void write_mii(int phyaddr, int regaddr, int data, volatile greth_regs 
* regs)
 {
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
 
GRETH_REGSAVE(regs-mdio,
- ((data  0x)  16) | (0  11) | ((addr  0x1F)  6)
- | 1);
+ ((data  0x)  16) | ((phyaddr  0x1F)  11) |
+ ((regaddr  0x1F)  6) | 1);
 
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
@@ -146,8 +146,6 @@ int greth_init(struct eth_device *dev, bd_t * bis)
printf(greth_init\n);
 #endif
 
-   GRETH_REGSAVE(regs-control, 0);
-
if (!greth-rxbd_base) {
 
/* allocate descriptors */
@@ -161,6 +159,7 @@ int greth_init(struct eth_device *dev, bd_t * bis)
malloc(GRETH_RXBUF_EFF_SIZE * GRETH_RXBD_CNT);
}
 
+   memset(greth-rxbuf_base, 0, GRETH_RXBUF_EFF_SIZE * GRETH_RXBD_CNT);
/* initate rx decriptors */
for (i = 0; i  GRETH_RXBD_CNT; i++) {
greth-rxbd_base[i].addr = (unsigned int)
@@ -219,6 +218,11 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
greth_regs *regs = dev-regs;
int tmp, tmp1, tmp2, i;
unsigned int start, timeout;
+#ifdef CONFIG_SYS_GRLIB_GRETH_PHYADDR
+   int phyaddr = CONFIG_SYS_GRLIB_GRETH_PHYADDR;
+#else
+   int phyaddr = 0;
+#endif
 
/* X msecs to ticks */
timeout = usec2ticks(GRETH_PHY_TIMEOUT_MS * 1000);
@@ -230,17 +234,25 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
 
/* get phy control register default values */
 
-   while ((tmp = read_mii(0, regs))  0x8000) {
-   if (get_timer(start)  timeout)
+   while ((tmp = read_mii(phyaddr, 0, regs))  0x8000) {
+   if (get_timer(start)  timeout) {
+#ifdef DEBUG
+   printf(greth_init_phy: PHY read 1 failed\n);
+#endif
return 1;   /* Fail */
+   }
}
 
/* reset PHY and wait for completion */
-   write_mii(0, 0x8000 | tmp, regs);
+   write_mii(phyaddr, 0, 0x8000 | tmp, regs);
 
-   while (((tmp = read_mii(0, regs)))  0x8000) {
-   if (get_timer(start)  timeout)
+   while (((tmp = read_mii(phyaddr, 0, regs)))  0x8000) {
+   if (get_timer(start)  timeout) {
+#ifdef DEBUG
+   printf(greth_init_phy: PHY read 2 failed\n);
+#endif
return 1;   /* Fail */
+   }
}
 
/* Check if PHY is autoneg capable and then determine operating
@@ -251,16 +263,16 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
dev-sp = 0;
dev-auto_neg = 0;
if (!((tmp  12)  1)) {
-   write_mii(0, 0, regs);
+   write_mii(phyaddr, 0, 0, regs);
} else {
/* wait for auto negotiation to complete and then check 
operating mode */
dev-auto_neg = 1;
i = 0;
-   while (!(((tmp = read_mii(1, regs))  5)  1)) {
+   while (!(((tmp = read_mii(phyaddr, 1, regs))  5)  1)) {
if (get_timer(start)  timeout) {
printf(Auto negotiation timed out. 
   Selecting default config\n);
-   tmp = read_mii(0, regs);
+   tmp = read_mii(phyaddr, 0, regs);

[U-Boot] [PATCH 02/17] GRETH: Added support for selecting PHY address from config, PHY address was always set to zero before.

2010-01-28 Thread Daniel Hellstrom
Signed-off-by: Daniel Hellstrom dan...@gaisler.com
---
 drivers/net/greth.c |   69 +++---
 1 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/drivers/net/greth.c b/drivers/net/greth.c
index 79bc4d9..833915d 100644
--- a/drivers/net/greth.c
+++ b/drivers/net/greth.c
@@ -45,7 +45,7 @@
 /* ByPass Cache when reading regs */
 #define GRETH_REGLOAD(addr)SPARC_NOCACHE_READ(addr)
 /* Write-through cache == no bypassing needed on writes */
-#define GRETH_REGSAVE(addr,data)   (*(unsigned int *)(addr) = (data))
+#define GRETH_REGSAVE(addr,data) (*(volatile unsigned int *)(addr) = (data))
 #define GRETH_REGORIN(addr,data) GRETH_REGSAVE(addr,GRETH_REGLOAD(addr)|data)
 #define GRETH_REGANDIN(addr,data) GRETH_REGSAVE(addr,GRETH_REGLOAD(addr)data)
 
@@ -102,12 +102,12 @@ typedef struct {
 } greth_priv;
 
 /* Read MII register 'addr' from core 'regs' */
-static int read_mii(int addr, volatile greth_regs * regs)
+static int read_mii(int phyaddr, int regaddr, volatile greth_regs * regs)
 {
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
 
-   GRETH_REGSAVE(regs-mdio, (0  11) | ((addr  0x1F)  6) | 2);
+   GRETH_REGSAVE(regs-mdio, ((phyaddr  0x1F)  11) | ((regaddr  0x1F) 
 6) | 2);
 
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
@@ -119,14 +119,14 @@ static int read_mii(int addr, volatile greth_regs * regs)
}
 }
 
-static void write_mii(int addr, int data, volatile greth_regs * regs)
+static void write_mii(int phyaddr, int regaddr, int data, volatile greth_regs 
* regs)
 {
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
 
GRETH_REGSAVE(regs-mdio,
- ((data  0x)  16) | (0  11) | ((addr  0x1F)  6)
- | 1);
+ ((data  0x)  16) | ((phyaddr  0x1F)  11) | 
+ ((regaddr  0x1F)  6) | 1);
 
while (GRETH_REGLOAD(regs-mdio)  GRETH_MII_BUSY) {
}
@@ -146,8 +146,6 @@ int greth_init(struct eth_device *dev, bd_t * bis)
printf(greth_init\n);
 #endif
 
-   GRETH_REGSAVE(regs-control, 0);
-
if (!greth-rxbd_base) {
 
/* allocate descriptors */
@@ -161,6 +159,7 @@ int greth_init(struct eth_device *dev, bd_t * bis)
malloc(GRETH_RXBUF_EFF_SIZE * GRETH_RXBD_CNT);
}
 
+   memset(greth-rxbuf_base, 0, GRETH_RXBUF_EFF_SIZE * GRETH_RXBD_CNT);
/* initate rx decriptors */
for (i = 0; i  GRETH_RXBD_CNT; i++) {
greth-rxbd_base[i].addr = (unsigned int)
@@ -219,6 +218,11 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
greth_regs *regs = dev-regs;
int tmp, tmp1, tmp2, i;
unsigned int start, timeout;
+#ifdef CONFIG_SYS_GRLIB_GRETH_PHYADDR
+   int phyaddr = CONFIG_SYS_GRLIB_GRETH_PHYADDR;
+#else
+   int phyaddr = 0;
+#endif
 
/* X msecs to ticks */
timeout = usec2ticks(GRETH_PHY_TIMEOUT_MS * 1000);
@@ -230,17 +234,25 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
 
/* get phy control register default values */
 
-   while ((tmp = read_mii(0, regs))  0x8000) {
-   if (get_timer(start)  timeout)
+   while ((tmp = read_mii(phyaddr, 0, regs))  0x8000) {
+   if (get_timer(start)  timeout) {
+#ifdef DEBUG
+   printf(greth_init_phy: PHY read 1 failed\n);
+#endif
return 1;   /* Fail */
+   }
}
 
/* reset PHY and wait for completion */
-   write_mii(0, 0x8000 | tmp, regs);
+   write_mii(phyaddr, 0, 0x8000 | tmp, regs);
 
-   while (((tmp = read_mii(0, regs)))  0x8000) {
-   if (get_timer(start)  timeout)
+   while (((tmp = read_mii(phyaddr, 0, regs)))  0x8000) {
+   if (get_timer(start)  timeout) {
+#ifdef DEBUG
+   printf(greth_init_phy: PHY read 2 failed\n);
+#endif
return 1;   /* Fail */
+   }
}
 
/* Check if PHY is autoneg capable and then determine operating
@@ -251,16 +263,16 @@ int greth_init_phy(greth_priv * dev, bd_t * bis)
dev-sp = 0;
dev-auto_neg = 0;
if (!((tmp  12)  1)) {
-   write_mii(0, 0, regs);
+   write_mii(phyaddr, 0, 0, regs);
} else {
/* wait for auto negotiation to complete and then check 
operating mode */
dev-auto_neg = 1;
i = 0;
-   while (!(((tmp = read_mii(1, regs))  5)  1)) {
+   while (!(((tmp = read_mii(phyaddr, 1, regs))  5)  1)) {
if (get_timer(start)  timeout) {
printf(Auto negotiation timed out. 
   Selecting default config\n);
-   tmp = read_mii(0, regs);
+   tmp = read_mii(phyaddr, 0, regs);