]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/net/macb.c
net:macb: add line break
[karo-tx-uboot.git] / drivers / net / macb.c
index af0409bd2cf0347bfe7c74c6264edcff35808cce..ba172775f561c23125ca7106faadc3ff291cdf23 100644 (file)
@@ -42,6 +42,7 @@
 #include <net.h>
 #include <netdev.h>
 #include <malloc.h>
+#include <miiphy.h>
 
 #include <linux/mii.h>
 #include <asm/io.h>
@@ -164,10 +165,39 @@ static u16 macb_mdio_read(struct macb_device *macb, u8 reg)
        return MACB_BFEXT(DATA, frame);
 }
 
+#if defined(CONFIG_CMD_MII)
+
+int macb_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
+{
+       struct eth_device *dev = eth_get_dev_by_name(devname);
+       struct macb_device *macb = to_macb(dev);
+
+       if ( macb->phy_addr != phy_adr )
+               return -1;
+
+       *value = macb_mdio_read(macb, reg);
+
+       return 0;
+}
+
+int macb_miiphy_write(const char *devname, u8 phy_adr, u8 reg, u16 value)
+{
+       struct eth_device *dev = eth_get_dev_by_name(devname);
+       struct macb_device *macb = to_macb(dev);
+
+       if ( macb->phy_addr != phy_adr )
+               return -1;
+
+       macb_mdio_write(macb, reg, value);
+
+       return 0;
+}
+#endif
+
+
 #if defined(CONFIG_CMD_NET)
 
-static int macb_send(struct eth_device *netdev, volatile void *packet,
-                    int length)
+static int macb_send(struct eth_device *netdev, void *packet, int length)
 {
        struct macb_device *macb = to_macb(netdev);
        unsigned long paddr, ctrl;
@@ -334,7 +364,7 @@ static int macb_phy_find(struct macb_device *macb)
        }
 
        /* PHY isn't up to snuff */
-       printf("%s: PHY not found", macb->netdev.name);
+       printf("%s: PHY not found\n", macb->netdev.name);
 
        return 0;
 }
@@ -408,8 +438,6 @@ static int macb_init(struct eth_device *netdev, bd_t *bd)
 {
        struct macb_device *macb = to_macb(netdev);
        unsigned long paddr;
-       u32 hwaddr_bottom;
-       u16 hwaddr_top;
        int i;
 
        /*
@@ -438,23 +466,21 @@ static int macb_init(struct eth_device *netdev, bd_t *bd)
        macb_writel(macb, RBQP, macb->rx_ring_dma);
        macb_writel(macb, TBQP, macb->tx_ring_dma);
 
-       /* set hardware address */
-       hwaddr_bottom = cpu_to_le32(*((u32 *)netdev->enetaddr));
-       macb_writel(macb, SA1B, hwaddr_bottom);
-       hwaddr_top = cpu_to_le16(*((u16 *)(netdev->enetaddr + 4)));
-       macb_writel(macb, SA1T, hwaddr_top);
-
        /* choose RMII or MII mode. This depends on the board */
 #ifdef CONFIG_RMII
-#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
-    defined(CONFIG_AT91SAM9263)
+#if    defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
+       defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
+       defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
+       defined(CONFIG_AT91SAM9XE)
        macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN));
 #else
        macb_writel(macb, USRIO, 0);
 #endif
 #else
-#if defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
-    defined(CONFIG_AT91SAM9263)
+#if    defined(CONFIG_AT91CAP9) || defined(CONFIG_AT91SAM9260) || \
+       defined(CONFIG_AT91SAM9263) || defined(CONFIG_AT91SAM9G20) || \
+       defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
+       defined(CONFIG_AT91SAM9XE)
        macb_writel(macb, USRIO, MACB_BIT(CLKEN));
 #else
        macb_writel(macb, USRIO, MACB_BIT(MII));
@@ -488,6 +514,21 @@ static void macb_halt(struct eth_device *netdev)
        macb_writel(macb, NCR, MACB_BIT(CLRSTAT));
 }
 
+static int macb_write_hwaddr(struct eth_device *dev)
+{
+       struct macb_device *macb = to_macb(dev);
+       u32 hwaddr_bottom;
+       u16 hwaddr_top;
+
+       /* set hardware address */
+       hwaddr_bottom = dev->enetaddr[0] | dev->enetaddr[1] << 8 |
+                       dev->enetaddr[2] << 16 | dev->enetaddr[3] << 24;
+       macb_writel(macb, SA1B, hwaddr_bottom);
+       hwaddr_top = dev->enetaddr[4] | dev->enetaddr[5] << 8;
+       macb_writel(macb, SA1T, hwaddr_top);
+       return 0;
+}
+
 int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 {
        struct macb_device *macb;
@@ -521,6 +562,7 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
        netdev->halt = macb_halt;
        netdev->send = macb_send;
        netdev->recv = macb_recv;
+       netdev->write_hwaddr = macb_write_hwaddr;
 
        /*
         * Do some basic initialization so that we at least can talk
@@ -540,84 +582,9 @@ int macb_eth_initialize(int id, void *regs, unsigned int phy_addr)
 
        eth_register(netdev);
 
-       return 0;
-}
-
-#endif
-
 #if defined(CONFIG_CMD_MII)
-
-int miiphy_read(unsigned char addr, unsigned char reg, unsigned short *value)
-{
-       unsigned long netctl;
-       unsigned long netstat;
-       unsigned long frame;
-       int iflag;
-
-       iflag = disable_interrupts();
-       netctl = macb_readl(&macb, EMACB_NCR);
-       netctl |= MACB_BIT(MPE);
-       macb_writel(&macb, EMACB_NCR, netctl);
-       if (iflag)
-               enable_interrupts();
-
-       frame = (MACB_BF(SOF, 1)
-                | MACB_BF(RW, 2)
-                | MACB_BF(PHYA, addr)
-                | MACB_BF(REGA, reg)
-                | MACB_BF(CODE, 2));
-       macb_writel(&macb, EMACB_MAN, frame);
-
-       do {
-               netstat = macb_readl(&macb, EMACB_NSR);
-       } while (!(netstat & MACB_BIT(IDLE)));
-
-       frame = macb_readl(&macb, EMACB_MAN);
-       *value = MACB_BFEXT(DATA, frame);
-
-       iflag = disable_interrupts();
-       netctl = macb_readl(&macb, EMACB_NCR);
-       netctl &= ~MACB_BIT(MPE);
-       macb_writel(&macb, EMACB_NCR, netctl);
-       if (iflag)
-               enable_interrupts();
-
-       return 0;
-}
-
-int miiphy_write(unsigned char addr, unsigned char reg, unsigned short value)
-{
-       unsigned long netctl;
-       unsigned long netstat;
-       unsigned long frame;
-       int iflag;
-
-       iflag = disable_interrupts();
-       netctl = macb_readl(&macb, EMACB_NCR);
-       netctl |= MACB_BIT(MPE);
-       macb_writel(&macb, EMACB_NCR, netctl);
-       if (iflag)
-               enable_interrupts();
-
-       frame = (MACB_BF(SOF, 1)
-                | MACB_BF(RW, 1)
-                | MACB_BF(PHYA, addr)
-                | MACB_BF(REGA, reg)
-                | MACB_BF(CODE, 2)
-                | MACB_BF(DATA, value));
-       macb_writel(&macb, EMACB_MAN, frame);
-
-       do {
-               netstat = macb_readl(&macb, EMACB_NSR);
-       } while (!(netstat & MACB_BIT(IDLE)));
-
-       iflag = disable_interrupts();
-       netctl = macb_readl(&macb, EMACB_NCR);
-       netctl &= ~MACB_BIT(MPE);
-       macb_writel(&macb, EMACB_NCR, netctl);
-       if (iflag)
-               enable_interrupts();
-
+       miiphy_register(netdev->name, macb_miiphy_read, macb_miiphy_write);
+#endif
        return 0;
 }