diff options
Diffstat (limited to 'main/dev/smsc911x.c')
-rw-r--r-- | main/dev/smsc911x.c | 134 |
1 files changed, 69 insertions, 65 deletions
diff --git a/main/dev/smsc911x.c b/main/dev/smsc911x.c index bf4e7d0..418313a 100644 --- a/main/dev/smsc911x.c +++ b/main/dev/smsc911x.c @@ -2,10 +2,10 @@ // // smsc911x.c // -// +// // // Author(s): Jay Monkman <jtm@lopingdog.com> -// Contributors: +// Contributors: // Date: 06-07-2007 // Description: Driver for the SMSC 911x and 912x families of // ethernet controllers @@ -28,13 +28,13 @@ //-------------------------------------------------------------------------- static ulong smsc911x_mac_read(int reg) { - while (MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { + while(MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { continue; } MAC_CSR_CMD = MAC_RD_CMD(reg); - while (MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { + while(MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { continue; } @@ -48,14 +48,14 @@ static ulong smsc911x_mac_read(int reg) //-------------------------------------------------------------------------- static void smsc911x_mac_write(int reg, ulong val) { - while (MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { + while(MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { continue; } MAC_CSR_DATA = val; MAC_CSR_CMD = MAC_WR_CMD(reg); - while (MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { + while(MAC_CSR_CMD & MAC_CSR_CMD_CSR_BUSY) { continue; } } @@ -63,18 +63,18 @@ static void smsc911x_mac_write(int reg, ulong val) //-------------------------------------------------------------------------- // smsc911x_phy_read() // -// Reads a PHY register +// Reads a PHY register //-------------------------------------------------------------------------- #if 0 static ulong smsc911x_phy_read(int reg) { - while (smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { + while(smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { continue; } smsc911x_mac_write(MII_ACC, MII_ACC_ADDR(1) | MII_ACC_REG(reg)); - while (smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { + while(smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { continue; } @@ -89,17 +89,17 @@ static ulong smsc911x_phy_read(int reg) //-------------------------------------------------------------------------- static void smsc911x_phy_write(int reg, ushort val) { - while (smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { + while(smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { continue; } smsc911x_mac_write(MII_DATA, val); - smsc911x_mac_write(MII_ACC, (MII_ACC_ADDR(1) | - MII_ACC_REG(reg) | + smsc911x_mac_write(MII_ACC, (MII_ACC_ADDR(1) | + MII_ACC_REG(reg) | MII_ACC_WR)); - while (smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { + while(smsc911x_mac_read(MII_ACC) & MII_ACC_BUSY) { continue; } } @@ -115,14 +115,14 @@ void smsc911x_reset(void) HW_CFG |= HW_CFG_SRST; /* Wait for it */ - while (HW_CFG & HW_CFG_SRST) { + while(HW_CFG & HW_CFG_SRST) { continue; } PMT_CTRL |= PMT_CTRL_PHY_RST; /* Wait for it */ - while (PMT_CTRL & PMT_CTRL_PHY_RST) { + while(PMT_CTRL & PMT_CTRL_PHY_RST) { continue; } } @@ -135,7 +135,7 @@ void smsc911x_reset(void) static void smsc911x_set_mac(void) { ulong i; - + i = ((BinEnetAddr[5] << 8) | (BinEnetAddr[4] << 0)); smsc911x_mac_write(ADDRH, i); @@ -166,21 +166,25 @@ int smsc911x_init(void) switch(ID_REV) { case ID_REV_CHIP_9118: - if (EtherVerbose & SHOW_DRIVER_DEBUG) - printf("Found SMSC9118\n"); - break; + if(EtherVerbose & SHOW_DRIVER_DEBUG) { + printf("Found SMSC9118\n"); + } + break; case ID_REV_CHIP_9211: - if (EtherVerbose & SHOW_DRIVER_DEBUG) - printf("Found SMSC9211\n"); - break; + if(EtherVerbose & SHOW_DRIVER_DEBUG) { + printf("Found SMSC9211\n"); + } + break; case ID_REV_CHIP_9215: - if (EtherVerbose & SHOW_DRIVER_DEBUG) - printf("Found SMSC9215\n"); - break; + if(EtherVerbose & SHOW_DRIVER_DEBUG) { + printf("Found SMSC9215\n"); + } + break; case ID_REV_CHIP_9218: - if (EtherVerbose & SHOW_DRIVER_DEBUG) - printf("Found SMSC9218\n"); - break; + if(EtherVerbose & SHOW_DRIVER_DEBUG) { + printf("Found SMSC9218\n"); + } + break; default: printf("Unidentified Ethernet controller: 0x%x\n", ID_REV); return -1; @@ -197,22 +201,22 @@ int smsc911x_init(void) AFC_CFG_BACK_DUR(0x4)); /* Configure the GPIOs as LEDs */ - GPIO_CFG = (GPIO_CFG_LED3_EN | - GPIO_CFG_LED2_EN | - GPIO_CFG_LED1_EN | + GPIO_CFG = (GPIO_CFG_LED3_EN | + GPIO_CFG_LED2_EN | + GPIO_CFG_LED1_EN | GPIO_CFG_GPIOBUF(2) | GPIO_CFG_GPIOBUF(1) | GPIO_CFG_GPIOBUF(0)); /* Configure PHY to advertise all speeds */ - smsc911x_phy_write(PHY_ANAR, (PHY_ANAR_100TX_FD | + smsc911x_phy_write(PHY_ANAR, (PHY_ANAR_100TX_FD | PHY_ANAR_100TX | PHY_ANAR_10T_FD | PHY_ANAR_10T | PHY_ANAR_SF)); /* Enable auto negotiation */ - smsc911x_phy_write(PHY_BCR, (PHY_BCR_ANE | + smsc911x_phy_write(PHY_BCR, (PHY_BCR_ANE | PHY_BCR_RAN)); /* Set the controller to buffer entire packets */ @@ -230,7 +234,7 @@ int smsc911x_init(void) RX_CFG = 0; - return 0; + return 0; } void @@ -307,37 +311,37 @@ int smsc911x_tx(uchar *txbuf, ulong len) /* Wait until space is available for the packet */ do { avail = TX_FIFO_INF & TX_FIFO_TDFREE_MASK; - } while (avail < len); + } while(avail < len); - cmda = (TX_CMD_FS | - TX_CMD_LS | - TX_CMD_BS(len)); + cmda = (TX_CMD_FS | + TX_CMD_LS | + TX_CMD_BS(len)); - cmdb = TX_CMD_PKTLEN(len); + cmdb = TX_CMD_PKTLEN(len); - TX_FIFO_PORT = cmda; - TX_FIFO_PORT = cmdb; - p = (ulong*)txbuf; + TX_FIFO_PORT = cmda; + TX_FIFO_PORT = cmdb; + p = (ulong *)txbuf; - for (i = 0; i < (len/4); i++) { - TX_FIFO_PORT = p[i]; - - } + for(i = 0; i < (len/4); i++) { + TX_FIFO_PORT = p[i]; - if ((len & 0x3) != 0) { - int index = len & ~3; - int num = len & 3; - ulong last = 0; + } - for (i = 0; i < num; i++) { - last |= (txbuf[index + i] << (i * 8)); - } + if((len & 0x3) != 0) { + int index = len & ~3; + int num = len & 3; + ulong last = 0; - TX_FIFO_PORT = last; - } + for(i = 0; i < num; i++) { + last |= (txbuf[index + i] << (i * 8)); + } + TX_FIFO_PORT = last; + } - return 0; + + return 0; } //-------------------------------------------------------------------------- @@ -354,39 +358,39 @@ int smsc911x_rx(uchar *pktbuf) ulong inf = RX_FIFO_INF; ulong *p = (ulong *)pktbuf; - if (((inf >> 16) & 0xffff) == 0) { + if(((inf >> 16) & 0xffff) == 0) { return 0; } status = RX_STATUS_FIFO_PORT; size = (status & RX_STATUS_PL_MASK) >> RX_STATUS_PL_SHIFT; - if (size == 0) { + if(size == 0) { return 0; } - if ((status & RX_STATUS_ES) == 0) { - for (i = 0; i < ((size + 3) / 4); i++) { + if((status & RX_STATUS_ES) == 0) { + for(i = 0; i < ((size + 3) / 4); i++) { p[i] = RX_FIFO_PORT; } return size - 4; } else { /* Fast forward */ - if (size >= 16) { + if(size >= 16) { RX_DP_CTL = RX_DP_RX_FFWD; - while (RX_DP_CTL & RX_DP_RX_FFWD) { + while(RX_DP_CTL & RX_DP_RX_FFWD) { continue; } } else { ulong tmp; - for (i = 0; i < ((size + 3)/4); i++) { + for(i = 0; i < ((size + 3)/4); i++) { tmp = RX_FIFO_PORT; } - tmp = tmp; // eliminate 'set-but-not-unused' warning + tmp = tmp; // eliminate 'set-but-not-unused' warning } return 0; } } - + #endif // INCLUDE_ETHERNET |