]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/lan91c96.c
at91: Introduction of at91sam9g45 SOC.
[u-boot] / drivers / net / lan91c96.c
index ecdcbd9b32b10c27aba0281c7cfa43d8f4cff487..65565bcb01d27ddd5138318addf8a7fc6f5bc9b4 100644 (file)
  *   AUI/TP selection  ( mine has 10Base2/10BaseT select )
  *
  * Arguments:
- *     io      = for the base address
+ *     io      = for the base address
  *     irq     = for the IRQ
  *
  * author:
- *     Erik Stahlman                           ( erik@vt.edu )
- *     Daris A Nevil                           ( dnevil@snmc.com )
+ *     Erik Stahlman                           ( erik@vt.edu )
+ *     Daris A Nevil                           ( dnevil@snmc.com )
  *
  *
  * Hardware multicast code from Peter Cammaert ( pc@denkart.be )
@@ -53,7 +53,7 @@
  *    o   lan91c96.c (Intel Diagnostic Manager driver)
  *
  * History:
- *     04/30/03  Mathijs Haarman       Modified smc91111.c (u-boot version)
+ *     04/30/03  Mathijs Haarman       Modified smc91111.c (u-boot version)
  *                                     for lan91c96
  *---------------------------------------------------------------------------
  */
 #include "lan91c96.h"
 #include <net.h>
 
-#ifdef CONFIG_DRIVER_LAN91C96
-
-#if defined(CONFIG_CMD_NET)
-
 /*------------------------------------------------------------------------
  *
  * Configuration options, for the experienced user to change.
@@ -271,7 +267,7 @@ static void smc_shutdown (void);
 
 static int poll4int (byte mask, int timeout)
 {
-       int tmo = get_timer (0) + timeout * CFG_HZ;
+       int tmo = get_timer (0) + timeout * CONFIG_SYS_HZ;
        int is_timeout = 0;
        word old_bank = SMC_inw (LAN91C96_BANK_SELECT);
 
@@ -296,8 +292,8 @@ static int poll4int (byte mask, int timeout)
 /*
  * Function: smc_reset( void )
  * Purpose:
- *     This sets the SMC91111 chip to its normal state, hopefully from whatever
- *     mess that any other DOS driver has put it in.
+ *     This sets the SMC91111 chip to its normal state, hopefully from whatever
+ *     mess that any other DOS driver has put it in.
  *
  * Maybe I should reset more registers to defaults in here?  SOFTRST  should
  * do that for me.
@@ -397,7 +393,7 @@ static void smc_shutdown ()
  *     This sends the actual packet to the SMC9xxx chip.
  *
  * Algorithm:
- *     First, see if a saved_skb is available.
+ *     First, see if a saved_skb is available.
  *             ( this should NOT be called if there is no 'saved_skb'
  *     Now, find the packet number that the chip allocated
  *     Point the data pointers at it in memory
@@ -405,9 +401,9 @@ static void smc_shutdown ()
  *     Dump the packet to chip memory
  *     Check if a last byte is needed ( odd length packet )
  *             if so, set the control flag right
- *     Tell the card to send it
+ *     Tell the card to send it
  *     Enable the transmit interrupt, so I know if it failed
- *     Free the kernel data if I actually sent it.
+ *     Free the kernel data if I actually sent it.
  */
 static int smc_send_packet (volatile void *packet, int packet_length)
 {
@@ -610,10 +606,8 @@ static int smc_open (bd_t *bd)
        SMC_SELECT_BANK (1);
 
        err = smc_get_ethaddr (bd);     /* set smc_mac_addr, and sync it with u-boot globals */
-       if (err < 0) {
-               memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */
-               return (-1);    /* upper code ignores this, but NOT bi_enetaddr */
-       }
+       if (err < 0)
+               return -1;
 #ifdef USE_32_BIT
        for (i = 0; i < 6; i += 2) {
                word address;
@@ -865,9 +859,6 @@ static int smc_hw_init ()
 }
 #endif /* 0 */
 
-#endif /* COMMANDS & CFG_NET */
-
-
 /* smc_get_ethaddr (bd_t * bd)
  *
  * This checks both the environment and the ROM for an ethernet address. If
@@ -876,69 +867,20 @@ static int smc_hw_init ()
 
 int smc_get_ethaddr (bd_t * bd)
 {
-       int env_size = 0;
-       int rom_valid = 0;
-       int env_present = 0;
-       int reg = 0;
-       char *s = NULL;
-       char *e = NULL;
-       char *v_mac, es[] = "11:22:33:44:55:66";
-       char s_env_mac[64];
-       uchar v_env_mac[6];
-       uchar v_rom_mac[6];
-
-       env_size = getenv_r ("ethaddr", s_env_mac, sizeof (s_env_mac));
-       if (env_size != sizeof(es)) {   /* Ignore if env is bad or not set */
-               printf ("\n*** Warning: ethaddr is not set properly, ignoring!!\n");
-       } else {
-               env_present = 1;
-               s = s_env_mac;
+       uchar v_mac[6];
 
-               for (reg = 0; reg < 6; ++reg) { /* turn string into mac value */
-                       v_env_mac[reg] = s ? simple_strtoul (s, &e, 16) : 0;
-                       if (s)
-                               s = (*e) ? e + 1 : e;
+       if (!eth_getenv_enetaddr("ethaddr", v_mac)) {
+               /* get ROM mac value if any */
+               if (!get_rom_mac(v_mac)) {
+                       printf("\n*** ERROR: ethaddr is NOT set !!\n");
+                       return -1;
                }
+               eth_setenv_enetaddr("ethaddr", v_mac);
        }
 
-       rom_valid = get_rom_mac (v_rom_mac);    /* get ROM mac value if any */
-
-       if (!env_present) {     /* if NO env */
-               if (rom_valid) {        /* but ROM is valid */
-                       v_mac = (char *)v_rom_mac;
-                       sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",
-                                v_mac[0], v_mac[1], v_mac[2], v_mac[3],
-                                v_mac[4], v_mac[5]);
-                       setenv ("ethaddr", s_env_mac);
-               } else {        /* no env, bad ROM */
-                       printf ("\n*** ERROR: ethaddr is NOT set !!\n");
-                       return (-1);
-               }
-       } else {                /* good env, don't care ROM */
-               v_mac = (char *)v_env_mac;      /* always use a good env over a ROM */
-       }
-
-       if (env_present && rom_valid) { /* if both env and ROM are good */
-               if (memcmp (v_env_mac, v_rom_mac, 6) != 0) {
-                       printf ("\nWarning: MAC addresses don't match:\n");
-                       printf ("\tHW MAC address:  "
-                               "%02X:%02X:%02X:%02X:%02X:%02X\n",
-                               v_rom_mac[0], v_rom_mac[1],
-                               v_rom_mac[2], v_rom_mac[3],
-                               v_rom_mac[4], v_rom_mac[5] );
-                       printf ("\t\"ethaddr\" value: "
-                               "%02X:%02X:%02X:%02X:%02X:%02X\n",
-                               v_env_mac[0], v_env_mac[1],
-                               v_env_mac[2], v_env_mac[3],
-                               v_env_mac[4], v_env_mac[5]) ;
-                       debug ("### Set MAC addr from environment\n");
-               }
-       }
-       memcpy (bd->bi_enetaddr, v_mac, 6);     /* update global address to match env (allows env changing) */
-       smc_set_mac_addr ((unsigned char *)v_mac); /* use old function to update smc default */
-       PRINTK("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n", v_mac[0], v_mac[1],
-               v_mac[2], v_mac[3], v_mac[4], v_mac[5]);
-       return (0);
+       smc_set_mac_addr(v_mac); /* use old function to update smc default */
+       PRINTK("Using MAC Address %pM\n", v_mac);
+       return 0;
 }
 
 /*
@@ -963,5 +905,3 @@ int get_rom_mac (unsigned char *v_rom_mac)
        return (1);
 #endif
 }
-
-#endif /* CONFIG_DRIVER_LAN91C96 */