]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/net/rtl8169.c
Moved initialization of plb2800 Ethernet driver to board_eth_init
[karo-tx-uboot.git] / drivers / net / rtl8169.c
index d71323f7f41858942b5373bfa04641c96e57d415..e9f6391b3c1f57f77a9df7c6939075a82e9f59fc 100644 (file)
 #include <common.h>
 #include <malloc.h>
 #include <net.h>
+#include <netdev.h>
 #include <asm/io.h>
 #include <pci.h>
 
-#if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI) && \
-       defined(CONFIG_RTL8169)
-
 #undef DEBUG_RTL8169
 #undef DEBUG_RTL8169_TX
 #undef DEBUG_RTL8169_RX
@@ -115,8 +113,10 @@ static int media[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 enum RTL8169_registers {
        MAC0 = 0,               /* Ethernet hardware address. */
        MAR0 = 8,               /* Multicast filter. */
-       TxDescStartAddr = 0x20,
-       TxHDescStartAddr = 0x28,
+       TxDescStartAddrLow = 0x20,
+       TxDescStartAddrHigh = 0x24,
+       TxHDescStartAddrLow = 0x28,
+       TxHDescStartAddrHigh = 0x2c,
        FLASH = 0x30,
        ERSR = 0x36,
        ChipCmd = 0x37,
@@ -141,7 +141,8 @@ enum RTL8169_registers {
        PHYstatus = 0x6C,
        RxMaxSize = 0xDA,
        CPlusCmd = 0xE0,
-       RxDescStartAddr = 0xE4,
+       RxDescStartAddrLow = 0xE4,
+       RxDescStartAddrHigh = 0xE8,
        EarlyTxThres = 0xEC,
        FuncEvent = 0xF0,
        FuncEventMask = 0xF4,
@@ -247,6 +248,15 @@ static struct {
 } rtl_chip_info[] = {
        {"RTL-8169", 0x00, 0xff7e1880,},
        {"RTL-8169", 0x04, 0xff7e1880,},
+       {"RTL-8169", 0x00, 0xff7e1880,},
+       {"RTL-8169s/8110s",     0x02, 0xff7e1880,},
+       {"RTL-8169s/8110s",     0x04, 0xff7e1880,},
+       {"RTL-8169sb/8110sb",   0x10, 0xff7e1880,},
+       {"RTL-8169sc/8110sc",   0x18, 0xff7e1880,},
+       {"RTL-8168b/8111sb",    0x30, 0xff7e1880,},
+       {"RTL-8168b/8111sb",    0x38, 0xff7e1880,},
+       {"RTL-8101e",           0x34, 0xff7e1880,},
+       {"RTL-8100e",           0x32, 0xff7e1880,},
 };
 
 enum _DescStatusBit {
@@ -312,6 +322,7 @@ static const unsigned int rtl8169_rx_config =
     (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
 
 static struct pci_device_id supported[] = {
+       {PCI_VENDOR_ID_REALTEK, 0x8167},
        {PCI_VENDOR_ID_REALTEK, 0x8169},
        {}
 };
@@ -385,7 +396,7 @@ static int rtl8169_init_board(struct eth_device *dev)
 
        /* if unknown chip, assume array element #0, original RTL-8169 in this case */
        printf("PCI device %s: unknown chip version, assuming RTL-8169\n", dev->name);
-       printf("PCI device: TxConfig = 0x%hX\n", (unsigned long) RTL_R32(TxConfig));
+       printf("PCI device: TxConfig = 0x%lX\n", (unsigned long) RTL_R32(TxConfig));
        tpc->chipset = 0;
 
 match:
@@ -425,7 +436,7 @@ static int rtl_recv(struct eth_device *dev)
                                tpc->RxDescArray[cur_rx].status =
                                        cpu_to_le32(OWNbit + RX_BUF_SIZE);
                        tpc->RxDescArray[cur_rx].buf_addr =
-                               cpu_to_le32(tpc->RxBufferRing[cur_rx]);
+                               cpu_to_le32((unsigned long)tpc->RxBufferRing[cur_rx]);
                } else {
                        puts("Error Rx");
                }
@@ -433,6 +444,10 @@ static int rtl_recv(struct eth_device *dev)
                tpc->cur_rx = cur_rx;
                return 1;
 
+       } else {
+               ushort sts = RTL_R8(IntrStatus);
+               RTL_W8(IntrStatus, sts & ~(TxErr | RxErr | SYSErr));
+               udelay(100);    /* wait */
        }
        tpc->cur_rx = cur_rx;
        return (0);             /* initially as this is called to flush the input */
@@ -467,7 +482,8 @@ static int rtl_send(struct eth_device *dev, volatile void *packet, int length)
        while (len < ETH_ZLEN)
                ptxb[len++] = '\0';
 
-       tpc->TxDescArray[entry].buf_addr = cpu_to_le32(ptxb);
+       tpc->TxDescArray[entry].buf_Haddr = 0;
+       tpc->TxDescArray[entry].buf_addr = cpu_to_le32((unsigned long)ptxb);
        if (entry != (NUM_TX_DESC - 1)) {
                tpc->TxDescArray[entry].status =
                        cpu_to_le32((OWNbit | FSbit | LSbit) |
@@ -547,7 +563,11 @@ static void rtl8169_hw_start(struct eth_device *dev)
 #endif
 
        RTL_W8(Cfg9346, Cfg9346_Unlock);
-       RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
+
+       /* RTL-8169sb/8110sb or previous version */
+       if (tpc->chipset <= 5)
+               RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
+
        RTL_W8(EarlyTxThres, EarlyTxThld);
 
        /* For gigabit rtl8169 */
@@ -565,8 +585,15 @@ static void rtl8169_hw_start(struct eth_device *dev)
 
        tpc->cur_rx = 0;
 
-       RTL_W32(TxDescStartAddr, tpc->TxDescArray);
-       RTL_W32(RxDescStartAddr, tpc->RxDescArray);
+       RTL_W32(TxDescStartAddrLow, (unsigned long)tpc->TxDescArray);
+       RTL_W32(TxDescStartAddrHigh, (unsigned long)0);
+       RTL_W32(RxDescStartAddrLow, (unsigned long)tpc->RxDescArray);
+       RTL_W32(RxDescStartAddrHigh, (unsigned long)0);
+
+       /* RTL-8169sc/8110sc or later version */
+       if (tpc->chipset > 5)
+               RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
+
        RTL_W8(Cfg9346, Cfg9346_Lock);
        udelay(10);
 
@@ -611,7 +638,7 @@ static void rtl8169_init_ring(struct eth_device *dev)
 
                tpc->RxBufferRing[i] = &rxb[i * RX_BUF_SIZE];
                tpc->RxDescArray[i].buf_addr =
-                       cpu_to_le32(tpc->RxBufferRing[i]);
+                       cpu_to_le32((unsigned long)tpc->RxBufferRing[i]);
        }
 
 #ifdef DEBUG_RTL8169
@@ -726,6 +753,7 @@ static int rtl_init(struct eth_device *dev, bd_t *bis)
                bis->bi_enetaddr[i] = dev->enetaddr[i] = RTL_R8(MAC0 + i);
 
 #ifdef DEBUG_RTL8169
+       printf("chipset = %d\n", tpc->chipset);
        printf("MAC Address");
        for (i = 0; i < MAC_ADDR_LEN; i++)
                printf(":%02x", dev->enetaddr[i]);
@@ -873,5 +901,3 @@ int rtl8169_initialize(bd_t *bis)
        }
        return card_number;
 }
-
-#endif