diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/Makefile | 7 | ||||
-rw-r--r-- | drivers/cs8900.c | 304 | ||||
-rw-r--r-- | drivers/tigon3.c | 2 |
3 files changed, 178 insertions, 135 deletions
diff --git a/drivers/Makefile b/drivers/Makefile index afea752..65de8b5 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -28,12 +28,13 @@ include $(TOPDIR)/config.mk LIB = libdrivers.a OBJS = 3c589.o 5701rls.o bcm570x.o bcm570x_autoneg.o \ - cfb_console.o cs8900.o dc2114x.o eepro100.o \ - i8042.o natsemi.o ns16550.o ns8382x.o ns87308.o \ + cfb_console.o cs8900.o ct69000.o dc2114x.o \ + eepro100.o i8042.o inca-ip_sw.o \ + natsemi.o ns16550.o ns8382x.o ns87308.o \ pci.o pci_auto.o pci_indirect.o \ pcnet.o sed13806.o serial.o \ smc91111.o smiLynxEM.o sym53c8xx.o \ - tigon3.o w83c553f.o ct69000.o + tigon3.o w83c553f.o all: $(LIB) diff --git a/drivers/cs8900.c b/drivers/cs8900.c index ecc7c13..7165d60 100644 --- a/drivers/cs8900.c +++ b/drivers/cs8900.c @@ -1,6 +1,10 @@ /* * Cirrus Logic CS8900A Ethernet * + * (C) 2003 Wolfgang Denk, wd@denx.de + * Extension to synchronize ethaddr environment variable + * against value in EEPROM + * * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Marius Groeger <mgroeger@sysgo.de> @@ -48,188 +52,226 @@ /* we don't need 16 bit initialisation on 32 bit bus */ #define get_reg_init_bus(x) get_reg((x)) #else -static unsigned short get_reg_init_bus(int regno) +static unsigned short get_reg_init_bus (int regno) { - /* force 16 bit busmode */ - volatile unsigned char c; - c = CS8900_BUS16_0; - c = CS8900_BUS16_1; - c = CS8900_BUS16_0; - c = CS8900_BUS16_1; - c = CS8900_BUS16_0; - - CS8900_PPTR = regno; - return (unsigned short) CS8900_PDATA; + /* force 16 bit busmode */ + volatile unsigned char c; + + c = CS8900_BUS16_0; + c = CS8900_BUS16_1; + c = CS8900_BUS16_0; + c = CS8900_BUS16_1; + c = CS8900_BUS16_0; + + CS8900_PPTR = regno; + return (unsigned short) CS8900_PDATA; } #endif -static unsigned short -get_reg(int regno) +static unsigned short get_reg (int regno) { - CS8900_PPTR = regno; - return (unsigned short) CS8900_PDATA; + CS8900_PPTR = regno; + return (unsigned short) CS8900_PDATA; } -static void put_reg(int regno, unsigned short val) +static void put_reg (int regno, unsigned short val) { - CS8900_PPTR = regno; - CS8900_PDATA = val; + CS8900_PPTR = regno; + CS8900_PDATA = val; } -static void eth_reset(void) +static void eth_reset (void) { - int tmo; - unsigned short us; + int tmo; + unsigned short us; - /* reset NIC */ - put_reg(PP_SelfCTL, get_reg(PP_SelfCTL) | PP_SelfCTL_Reset ); + /* reset NIC */ + put_reg (PP_SelfCTL, get_reg (PP_SelfCTL) | PP_SelfCTL_Reset); - /* wait for 200ms */ - udelay(200000); - /* Wait until the chip is reset */ + /* wait for 200ms */ + udelay (200000); + /* Wait until the chip is reset */ - tmo = get_timer(0) + 1 * CFG_HZ; - while ((((us = get_reg_init_bus(PP_SelfSTAT)) & PP_SelfSTAT_InitD) == 0) - && tmo < get_timer(0)) - /*NOP*/; + tmo = get_timer (0) + 1 * CFG_HZ; + while ((((us = get_reg_init_bus (PP_SelfSTAT)) & PP_SelfSTAT_InitD) == 0) + && tmo < get_timer (0)) + /*NOP*/; } -void cs8900_get_enetaddr (uchar *addr) +void cs8900_get_enetaddr (uchar * addr) { - int i; - /* verify chip id */ - if (get_reg_init_bus(PP_ChipID) != 0x630e) - return; - eth_reset(); - if ((get_reg(PP_SelfST) & (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) == - (PP_SelfSTAT_EEPROM|PP_SelfSTAT_EEPROM_OK)) { - /* Load the MAC from EEPROM */ - for (i=0; i<6/2; i++) { - unsigned int Addr; - Addr = get_reg(PP_IA+i*2); - addr[i*2] = Addr & 0xFF; - addr[i*2+1] = Addr >> 8; + int i; + unsigned char env_enetaddr[6]; + char *tmp = getenv ("ethaddr"); + char *end; + + for (i=0; i<6; i++) { + env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; + if (tmp) + tmp = (*end) ? end+1 : end; + } + + /* verify chip id */ + if (get_reg_init_bus (PP_ChipID) != 0x630e) + return; + eth_reset (); + if ((get_reg (PP_SelfST) & (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) == + (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) { + + /* Load the MAC from EEPROM */ + for (i = 0; i < 6 / 2; i++) { + unsigned int Addr; + + Addr = get_reg (PP_IA + i * 2); + addr[i * 2] = Addr & 0xFF; + addr[i * 2 + 1] = Addr >> 8; + } + + if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6) != 0 && + memcmp(env_enetaddr, addr, 6) != 0) { + printf ("\nWarning: MAC addresses don't match:\n"); + printf ("\tHW MAC address: " + "%02X:%02X:%02X:%02X:%02X:%02X\n", + addr[0], addr[1], + addr[2], addr[3], + addr[4], addr[5] ); + printf ("\t\"ethaddr\" value: " + "%02X:%02X:%02X:%02X:%02X:%02X\n", + env_enetaddr[0], env_enetaddr[1], + env_enetaddr[2], env_enetaddr[3], + env_enetaddr[4], env_enetaddr[5]) ; + debug ("### Set MAC addr from environment\n"); + memcpy (addr, env_enetaddr, 6); + } + if (!tmp) { + char ethaddr[20]; + sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X", + addr[0], addr[1], + addr[2], addr[3], + addr[4], addr[5]) ; + debug ("### Set environment from HW MAC addr = \"%s\"\n", ethaddr); + setenv ("ethaddr", ethaddr); + } + } - } } -void eth_halt( void ) +void eth_halt (void) { - /* disable transmitter/receiver mode */ - put_reg(PP_LineCTL, 0); + /* disable transmitter/receiver mode */ + put_reg (PP_LineCTL, 0); - /* "shutdown" to show ChipID or kernel wouldn't find he cs8900 ... */ - get_reg_init_bus(PP_ChipID); + /* "shutdown" to show ChipID or kernel wouldn't find he cs8900 ... */ + get_reg_init_bus (PP_ChipID); } -int eth_init( bd_t *bd ) +int eth_init (bd_t * bd) { - /* verify chip id */ - if (get_reg_init_bus(PP_ChipID) != 0x630e) - { - printf( "CS8900 Ethernet chip not found?!\n" ); - return 0; - } + /* verify chip id */ + if (get_reg_init_bus (PP_ChipID) != 0x630e) { + printf ("CS8900 Ethernet chip not found?!\n"); + return 0; + } - eth_reset(); - /* set the ethernet address */ - put_reg(PP_IA + 0, bd->bi_enetaddr[0] | (bd->bi_enetaddr[1] << 8)); - put_reg(PP_IA + 2, bd->bi_enetaddr[2] | (bd->bi_enetaddr[3] << 8)); - put_reg(PP_IA + 4, bd->bi_enetaddr[4] | (bd->bi_enetaddr[5] << 8)); + eth_reset (); + /* set the ethernet address */ + put_reg (PP_IA + 0, bd->bi_enetaddr[0] | (bd->bi_enetaddr[1] << 8)); + put_reg (PP_IA + 2, bd->bi_enetaddr[2] | (bd->bi_enetaddr[3] << 8)); + put_reg (PP_IA + 4, bd->bi_enetaddr[4] | (bd->bi_enetaddr[5] << 8)); - /* receive only error free packets addressed to this card */ - put_reg(PP_RxCTL, PP_RxCTL_IA | PP_RxCTL_Broadcast | PP_RxCTL_RxOK); + /* receive only error free packets addressed to this card */ + put_reg (PP_RxCTL, PP_RxCTL_IA | PP_RxCTL_Broadcast | PP_RxCTL_RxOK); - /* do not generate any interrupts on receive operations */ - put_reg(PP_RxCFG, 0); + /* do not generate any interrupts on receive operations */ + put_reg (PP_RxCFG, 0); - /* do not generate any interrupts on transmit operations */ - put_reg(PP_TxCFG, 0); + /* do not generate any interrupts on transmit operations */ + put_reg (PP_TxCFG, 0); - /* do not generate any interrupts on buffer operations */ - put_reg(PP_BufCFG, 0); + /* do not generate any interrupts on buffer operations */ + put_reg (PP_BufCFG, 0); - /* enable transmitter/receiver mode */ - put_reg(PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx); + /* enable transmitter/receiver mode */ + put_reg (PP_LineCTL, PP_LineCTL_Rx | PP_LineCTL_Tx); - return 0; + return 0; } /* Get a data block via Ethernet */ -extern int eth_rx(void) +extern int eth_rx (void) { - int i; - unsigned short rxlen; - unsigned short *addr; - unsigned short status; + int i; + unsigned short rxlen; + unsigned short *addr; + unsigned short status; - status = get_reg(PP_RER); + status = get_reg (PP_RER); - if ((status & PP_RER_RxOK) == 0) - return 0; + if ((status & PP_RER_RxOK) == 0) + return 0; - status = CS8900_RTDATA; /* stat */ - rxlen = CS8900_RTDATA; /* len */ + status = CS8900_RTDATA; /* stat */ + rxlen = CS8900_RTDATA; /* len */ - if(rxlen > PKTSIZE_ALIGN + PKTALIGN) - printf("packet too big!\n"); + if (rxlen > PKTSIZE_ALIGN + PKTALIGN) + printf ("packet too big!\n"); - for(addr = (unsigned short *)NetRxPackets[0], i = rxlen >> 1; i > 0; i-- ) - *addr++ = CS8900_RTDATA; - if(rxlen & 1) - *addr++ = CS8900_RTDATA; + for (addr = (unsigned short *) NetRxPackets[0], i = rxlen >> 1; i > 0; + i--) + *addr++ = CS8900_RTDATA; + if (rxlen & 1) + *addr++ = CS8900_RTDATA; - /* Pass the packet up to the protocol layers. */ - NetReceive(NetRxPackets[0], rxlen); + /* Pass the packet up to the protocol layers. */ + NetReceive (NetRxPackets[0], rxlen); - return rxlen; + return rxlen; } /* Send a data block via Ethernet. */ -extern int eth_send(volatile void *packet, int length) +extern int eth_send (volatile void *packet, int length) { - volatile unsigned short *addr; - int tmo; - unsigned short s; + volatile unsigned short *addr; + int tmo; + unsigned short s; retry: - /* initiate a transmit sequence */ - CS8900_TxCMD = PP_TxCmd_TxStart_Full; - CS8900_TxLEN = length; - - /* Test to see if the chip has allocated memory for the packet */ - if ((get_reg(PP_BusSTAT) & PP_BusSTAT_TxRDY) == 0) { - /* Oops... this should not happen! */ - printf("cs: unable to send packet; retrying...\n"); - for (tmo = get_timer(0) + 5 * CFG_HZ; get_timer(0) < tmo; ) - /*NOP*/; - eth_reset(); - goto retry; - } - - /* Write the contents of the packet */ - /* assume even number of bytes */ - for(addr = packet; length > 0; length -= 2 ) - CS8900_RTDATA = *addr++; - - /* wait for transfer to succeed */ - tmo = get_timer(0) + 5 * CFG_HZ; - while((s = get_reg(PP_TER) & ~0x1F) == 0) - { - if (get_timer(0) >= tmo) - break; - } - - /* nothing */ ; - if ((s & (PP_TER_CRS | PP_TER_TxOK)) != PP_TER_TxOK) { - printf("\ntransmission error %#x\n", s); - } - - return 0; + /* initiate a transmit sequence */ + CS8900_TxCMD = PP_TxCmd_TxStart_Full; + CS8900_TxLEN = length; + + /* Test to see if the chip has allocated memory for the packet */ + if ((get_reg (PP_BusSTAT) & PP_BusSTAT_TxRDY) == 0) { + /* Oops... this should not happen! */ + printf ("cs: unable to send packet; retrying...\n"); + for (tmo = get_timer (0) + 5 * CFG_HZ; get_timer (0) < tmo;) + /*NOP*/; + eth_reset (); + goto retry; + } + + /* Write the contents of the packet */ + /* assume even number of bytes */ + for (addr = packet; length > 0; length -= 2) + CS8900_RTDATA = *addr++; + + /* wait for transfer to succeed */ + tmo = get_timer (0) + 5 * CFG_HZ; + while ((s = get_reg (PP_TER) & ~0x1F) == 0) { + if (get_timer (0) >= tmo) + break; + } + + /* nothing */ ; + if ((s & (PP_TER_CRS | PP_TER_TxOK)) != PP_TER_TxOK) { + printf ("\ntransmission error %#x\n", s); + } + + return 0; } -#endif /* COMMANDS & CFG_NET */ +#endif /* COMMANDS & CFG_NET */ -#endif /* CONFIG_DRIVER_CS8900 */ +#endif /* CONFIG_DRIVER_CS8900 */ diff --git a/drivers/tigon3.c b/drivers/tigon3.c index 5883744..c20dbe5 100644 --- a/drivers/tigon3.c +++ b/drivers/tigon3.c @@ -11,7 +11,6 @@ /* History: */ /******************************************************************************/ #include <common.h> -#include "bcm570x_mm.h" #include <asm/types.h> #if (CONFIG_COMMANDS & CFG_CMD_NET) && !defined(CONFIG_NET_MULTI) && \ defined(CONFIG_TIGON3) @@ -20,6 +19,7 @@ #endif #include <malloc.h> #include <linux/byteorder/big_endian.h> +#include "bcm570x_mm.h" #define EMBEDDED 1 /******************************************************************************/ |