]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/smc911x.c
net: smc911x.c: Add LAN9211 to chip_ids[] array
[karo-tx-uboot.git] / drivers / net / smc911x.c
index 6d93bf07497847f4f60e912041c4415ab3c3c8d1..9cc4fce0024701bd8b0375954e04dd832ba5a22c 100644 (file)
@@ -23,9 +23,6 @@
  */
 
 #include <common.h>
-
-#ifdef CONFIG_DRIVER_SMC911X
-
 #include <command.h>
 #include <net.h>
 #include <miiphy.h>
        CONFIG_DRIVER_SMC911X_16_BIT shall be set"
 #endif
 
-#ifdef CONFIG_DRIVER_SMC911X_32_BIT
-static inline u32 reg_read(u32 addr)
+#if defined (CONFIG_DRIVER_SMC911X_32_BIT)
+static inline u32 __smc911x_reg_read(u32 addr)
 {
        return *(volatile u32*)addr;
 }
-static inline void reg_write(u32 addr, u32 val)
+u32 smc911x_reg_read(u32 addr) __attribute__((weak, alias("__smc911x_reg_read")));
+
+static inline void __smc911x_reg_write(u32 addr, u32 val)
 {
        *(volatile u32*)addr = val;
 }
-#elif CONFIG_DRIVER_SMC911X_16_BIT
-static inline u32 reg_read(u32 addr)
+void smc911x_reg_write(u32 addr, u32 val) __attribute__((weak, alias("__smc911x_reg_write")));
+#elif defined (CONFIG_DRIVER_SMC911X_16_BIT)
+static inline u32 smc911x_reg_read(u32 addr)
 {
        volatile u16 *addr_16 = (u16 *)addr;
        return ((*addr_16 & 0x0000ffff) | (*(addr_16 + 1) << 16));
 }
-static inline void reg_write(u32 addr, u32 val)
+static inline void smc911x_reg_write(u32 addr, u32 val)
 {
        *(volatile u16*)addr = (u16)val;
        *(volatile u16*)(addr + 2) = (u16)(val >> 16);
@@ -60,6 +60,11 @@ static inline void reg_write(u32 addr, u32 val)
 #error "SMC911X: undefined bus width"
 #endif /* CONFIG_DRIVER_SMC911X_16_BIT */
 
+u32 pkt_data_pull(u32 addr) \
+       __attribute__ ((weak, alias ("smc911x_reg_read")));
+void pkt_data_push(u32 addr, u32 val) \
+       __attribute__ ((weak, alias ("smc911x_reg_write")));
+
 #define mdelay(n)       udelay((n)*1000)
 
 /* Below are the register offsets and bit definitions
@@ -379,6 +384,7 @@ static inline void reg_write(u32 addr, u32 val)
 #define CHIP_9116      0x116
 #define CHIP_9117      0x117
 #define CHIP_9118      0x118
+#define CHIP_9211      0x9211
 #define CHIP_9215      0x115a
 #define CHIP_9216      0x116a
 #define CHIP_9217      0x117a
@@ -394,6 +400,7 @@ static const struct chip_id chip_ids[] =  {
        { CHIP_9116, "LAN9116" },
        { CHIP_9117, "LAN9117" },
        { CHIP_9118, "LAN9118" },
+       { CHIP_9211, "LAN9211" },
        { CHIP_9215, "LAN9215" },
        { CHIP_9216, "LAN9216" },
        { CHIP_9217, "LAN9217" },
@@ -405,22 +412,22 @@ static const struct chip_id chip_ids[] =  {
 
 u32 smc911x_get_mac_csr(u8 reg)
 {
-       while (reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
+       while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
                ;
-       reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | MAC_CSR_CMD_R_NOT_W | reg);
-       while (reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
+       smc911x_reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | MAC_CSR_CMD_R_NOT_W | reg);
+       while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
                ;
 
-       return reg_read(MAC_CSR_DATA);
+       return smc911x_reg_read(MAC_CSR_DATA);
 }
 
 void smc911x_set_mac_csr(u8 reg, u32 data)
 {
-       while (reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
+       while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
                ;
-       reg_write(MAC_CSR_DATA, data);
-       reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | reg);
-       while (reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
+       smc911x_reg_write(MAC_CSR_DATA, data);
+       smc911x_reg_write(MAC_CSR_CMD, MAC_CSR_CMD_CSR_BUSY | reg);
+       while (smc911x_reg_read(MAC_CSR_CMD) & MAC_CSR_CMD_CSR_BUSY)
                ;
 }
 
@@ -494,10 +501,10 @@ static int smc911x_phy_reset(void)
 {
        u32 reg;
 
-       reg = reg_read(PMT_CTRL);
+       reg = smc911x_reg_read(PMT_CTRL);
        reg &= ~0xfffff030;
        reg |= PMT_CTRL_PHY_RST;
-       reg_write(PMT_CTRL, reg);
+       smc911x_reg_write(PMT_CTRL, reg);
 
        mdelay(100);
 
@@ -539,13 +546,13 @@ static void smc911x_reset(void)
        int timeout;
 
        /* Take out of PM setting first */
-       if (reg_read(PMT_CTRL) & PMT_CTRL_READY) {
+       if (smc911x_reg_read(PMT_CTRL) & PMT_CTRL_READY) {
                /* Write to the bytetest will take out of powerdown */
-               reg_write(BYTE_TEST, 0x0);
+               smc911x_reg_write(BYTE_TEST, 0x0);
 
                timeout = 10;
 
-               while (timeout-- && !(reg_read(PMT_CTRL) & PMT_CTRL_READY))
+               while (timeout-- && !(smc911x_reg_read(PMT_CTRL) & PMT_CTRL_READY))
                        udelay(10);
                if (!timeout) {
                        printf(DRIVERNAME
@@ -555,12 +562,12 @@ static void smc911x_reset(void)
        }
 
        /* Disable interrupts */
-       reg_write(INT_EN, 0);
+       smc911x_reg_write(INT_EN, 0);
 
-       reg_write(HW_CFG, HW_CFG_SRST);
+       smc911x_reg_write(HW_CFG, HW_CFG_SRST);
 
        timeout = 1000;
-       while (timeout-- && reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY)
+       while (timeout-- && smc911x_reg_read(E2P_CMD) & E2P_CMD_EPC_BUSY)
                udelay(10);
 
        if (!timeout) {
@@ -570,23 +577,23 @@ static void smc911x_reset(void)
 
        /* Reset the FIFO level and flow control settings */
        smc911x_set_mac_csr(FLOW, FLOW_FCPT | FLOW_FCEN);
-       reg_write(AFC_CFG, 0x0050287F);
+       smc911x_reg_write(AFC_CFG, 0x0050287F);
 
        /* Set to LED outputs */
-       reg_write(GPIO_CFG, 0x70070000);
+       smc911x_reg_write(GPIO_CFG, 0x70070000);
 }
 
 static void smc911x_enable(void)
 {
        /* Enable TX */
-       reg_write(HW_CFG, 8 << 16 | HW_CFG_SF);
+       smc911x_reg_write(HW_CFG, 8 << 16 | HW_CFG_SF);
 
-       reg_write(GPT_CFG, GPT_CFG_TIMER_EN | 10000);
+       smc911x_reg_write(GPT_CFG, GPT_CFG_TIMER_EN | 10000);
 
-       reg_write(TX_CFG, TX_CFG_TX_ON);
+       smc911x_reg_write(TX_CFG, TX_CFG_TX_ON);
 
        /* no padding to start of packets */
-       reg_write(RX_CFG, 0);
+       smc911x_reg_write(RX_CFG, 0);
 
        smc911x_set_mac_csr(MAC_CR, MAC_CR_TXEN | MAC_CR_RXEN | MAC_CR_HBDIS);
 
@@ -598,18 +605,18 @@ int eth_init(bd_t *bd)
 
        printf(DRIVERNAME ": initializing\n");
 
-       val = reg_read(BYTE_TEST);
+       val = smc911x_reg_read(BYTE_TEST);
        if (val != 0x87654321) {
-               printf(DRIVERNAME ": Invalid chip endian 0x08%x\n", val);
+               printf(DRIVERNAME ": Invalid chip endian 0x%08lx\n", val);
                goto err_out;
        }
 
-       val = reg_read(ID_REV) >> 16;
+       val = smc911x_reg_read(ID_REV) >> 16;
        for (i = 0; chip_ids[i].id != 0; i++) {
                if (chip_ids[i].id == val) break;
        }
        if (!chip_ids[i].id) {
-               printf(DRIVERNAME ": Unknown chip ID %04x\n", val);
+               printf(DRIVERNAME ": Unknown chip ID %04lx\n", val);
                goto err_out;
        }
 
@@ -638,21 +645,21 @@ int eth_send(volatile void *packet, int length)
        u32 tmplen;
        u32 status;
 
-       reg_write(TX_DATA_FIFO, TX_CMD_A_INT_FIRST_SEG | TX_CMD_A_INT_LAST_SEG | length);
-       reg_write(TX_DATA_FIFO, length);
+       smc911x_reg_write(TX_DATA_FIFO, TX_CMD_A_INT_FIRST_SEG | TX_CMD_A_INT_LAST_SEG | length);
+       smc911x_reg_write(TX_DATA_FIFO, length);
 
        tmplen = (length + 3) / 4;
 
        while (tmplen--)
-               reg_write(TX_DATA_FIFO, *data++);
+               pkt_data_push(TX_DATA_FIFO, *data++);
 
        /* wait for transmission */
-       while (!((reg_read(TX_FIFO_INF) & TX_FIFO_INF_TSUSED) >> 16));
+       while (!((smc911x_reg_read(TX_FIFO_INF) & TX_FIFO_INF_TSUSED) >> 16));
 
        /* get status. Ignore 'no carrier' error, it has no meaning for
         * full duplex operation
         */
-       status = reg_read(TX_STATUS_FIFO) & (TX_STS_LOC | TX_STS_LATE_COLL |
+       status = smc911x_reg_read(TX_STATUS_FIFO) & (TX_STS_LOC | TX_STS_LATE_COLL |
                TX_STS_MANY_COLL | TX_STS_MANY_DEFER | TX_STS_UNDERRUN);
 
        if (!status)
@@ -679,15 +686,15 @@ int eth_rx(void)
        u32 pktlen, tmplen;
        u32 status;
 
-       if ((reg_read(RX_FIFO_INF) & RX_FIFO_INF_RXSUSED) >> 16) {
-               status = reg_read(RX_STATUS_FIFO);
+       if ((smc911x_reg_read(RX_FIFO_INF) & RX_FIFO_INF_RXSUSED) >> 16) {
+               status = smc911x_reg_read(RX_STATUS_FIFO);
                pktlen = (status & RX_STS_PKT_LEN) >> 16;
 
-               reg_write(RX_CFG, 0);
+               smc911x_reg_write(RX_CFG, 0);
 
                tmplen = (pktlen + 2+ 3) / 4;
                while (tmplen--)
-                       *data++ = reg_read(RX_DATA_FIFO);
+                       *data++ = pkt_data_pull(RX_DATA_FIFO);
 
                if (status & RX_STS_ES)
                        printf(DRIVERNAME
@@ -699,5 +706,3 @@ int eth_rx(void)
 
        return 0;
 }
-
-#endif                         /* CONFIG_DRIVER_SMC911X */