]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/enc28j60.c
net: designware: Add phy supply support
[u-boot] / drivers / net / enc28j60.c
index 6c161b632f4165b87e7939c5ae494f736d72e855..588a84d7a919449e17a0ea5801caa30301f70660 100644 (file)
@@ -4,20 +4,7 @@
  * Martin Krause, Martin.Krause@tqs.de
  * reworked original enc28j60.c
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -34,8 +21,8 @@
  * enc_miiphy_read(), enc_miiphy_write(), enc_write_hwaddr(),
  * enc_init(), enc_recv(), enc_send(), enc_halt()
  * ALL other functions assume that the bus has already been claimed!
- * Since NetReceive() might call enc_send() in return, the bus must be
- * released, NetReceive() called and claimed again.
+ * Since net_process_received_packet() might call enc_send() in return, the bus
+ * must be released, net_process_received_packet() called and claimed again.
  */
 
 /*
@@ -314,7 +301,7 @@ static void enc_release_bus(enc_dev_t *enc)
 /*
  * Read PHY register
  */
-static u16 phy_read(enc_dev_t *enc, const u8 addr)
+static u16 enc_phy_read(enc_dev_t *enc, const u8 addr)
 {
        uint64_t etime;
        u8 status;
@@ -339,7 +326,7 @@ static u16 phy_read(enc_dev_t *enc, const u8 addr)
 /*
  * Write PHY register
  */
-static void phy_write(enc_dev_t *enc, const u8 addr, const u16 data)
+static void enc_phy_write(enc_dev_t *enc, const u8 addr, const u16 data)
 {
        uint64_t etime;
        u8 status;
@@ -374,7 +361,7 @@ static int enc_phy_link_wait(enc_dev_t *enc)
 
 #ifdef CONFIG_ENC_SILENTLINK
        /* check if we have a link, then just return */
-       status = phy_read(enc, PHY_REG_PHSTAT1);
+       status = enc_phy_read(enc, PHY_REG_PHSTAT1);
        if (status & ENC_PHSTAT1_LLSTAT)
                return 0;
 #endif
@@ -382,10 +369,10 @@ static int enc_phy_link_wait(enc_dev_t *enc)
        /* wait for link with 1 second timeout */
        etime = get_ticks() + get_tbclk();
        while (get_ticks() <= etime) {
-               status = phy_read(enc, PHY_REG_PHSTAT1);
+               status = enc_phy_read(enc, PHY_REG_PHSTAT1);
                if (status & ENC_PHSTAT1_LLSTAT) {
                        /* now we have a link */
-                       status = phy_read(enc, PHY_REG_PHSTAT2);
+                       status = enc_phy_read(enc, PHY_REG_PHSTAT2);
                        duplex = (status & ENC_PHSTAT2_DPXSTAT) ? 1 : 0;
                        printf("%s: link up, 10Mbps %s-duplex\n",
                                enc->dev->name, duplex ? "full" : "half");
@@ -394,7 +381,7 @@ static int enc_phy_link_wait(enc_dev_t *enc)
                udelay(1000);
        }
 
-       /* timeout occured */
+       /* timeout occurred */
        printf("%s: link down\n", enc->dev->name);
        return 1;
 }
@@ -428,11 +415,10 @@ static void enc_reset_rx_call(enc_dev_t *enc)
  */
 static void enc_receive(enc_dev_t *enc)
 {
-       u8 *packet = (u8 *)NetRxPackets[0];
+       u8 *packet = (u8 *)net_rx_packets[0];
        u16 pkt_len;
        u16 copy_len;
        u16 status;
-       u8 eir_reg;
        u8 pkt_cnt = 0;
        u16 rxbuf_rdpt;
        u8 hbuf[6];
@@ -476,20 +462,21 @@ static void enc_receive(enc_dev_t *enc)
                /* read pktcnt */
                pkt_cnt = enc_r8(enc, CTL_REG_EPKTCNT);
                if (copy_len == 0) {
-                       eir_reg = enc_r8(enc, CTL_REG_EIR);
+                       (void)enc_r8(enc, CTL_REG_EIR);
                        enc_reset_rx(enc);
                        printf("%s: receive copy_len=0\n", enc->dev->name);
                        continue;
                }
                /*
-                * Because NetReceive() might call enc_send(), we need to
-                * release the SPI bus, call NetReceive(), reclaim the bus
+                * Because net_process_received_packet() might call enc_send(),
+                * we need to release the SPI bus, call
+                * net_process_received_packet(), reclaim the bus.
                 */
                enc_release_bus(enc);
-               NetReceive(packet, pkt_len);
+               net_process_received_packet(packet, pkt_len);
                if (enc_claim_bus(enc))
                        return;
-               eir_reg = enc_r8(enc, CTL_REG_EIR);
+               (void)enc_r8(enc, CTL_REG_EIR);
        } while (pkt_cnt);
        /* Use EPKTCNT not EIR.PKTIF flag, see errata pt. 6 */
 }
@@ -500,14 +487,9 @@ static void enc_receive(enc_dev_t *enc)
 static void enc_poll(enc_dev_t *enc)
 {
        u8 eir_reg;
-       u8 estat_reg;
        u8 pkt_cnt;
 
-#ifdef CONFIG_USE_IRQ
-       /* clear global interrupt enable bit in enc28j60 */
-       enc_bclr(enc, CTL_REG_EIE, ENC_EIE_INTIE);
-#endif
-       estat_reg = enc_r8(enc, CTL_REG_ESTAT);
+       (void)enc_r8(enc, CTL_REG_ESTAT);
        eir_reg = enc_r8(enc, CTL_REG_EIR);
        if (eir_reg & ENC_EIR_TXIF) {
                /* clear TXIF bit in EIR */
@@ -534,10 +516,6 @@ static void enc_poll(enc_dev_t *enc)
                printf("%s: tx error\n", enc->dev->name);
                enc_bclr(enc, CTL_REG_EIR, ENC_EIR_TXERIF);
        }
-#ifdef CONFIG_USE_IRQ
-       /* set global interrupt enable bit in enc28j60 */
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_INTIE);
-#endif
 }
 
 /*
@@ -678,8 +656,8 @@ static int enc_setup(enc_dev_t *enc)
        enc->bank = 0xff;       /* invalidate current bank in enc28j60 */
 
        /* verify PHY identification */
-       phid1 = phy_read(enc, PHY_REG_PHID1);
-       phid2 = phy_read(enc, PHY_REG_PHID2) & ENC_PHID2_MASK;
+       phid1 = enc_phy_read(enc, PHY_REG_PHID1);
+       phid2 = enc_phy_read(enc, PHY_REG_PHID2) & ENC_PHID2_MASK;
        if (phid1 != ENC_PHID1_VALUE || phid2 != ENC_PHID2_VALUE) {
                printf("%s: failed to identify PHY. Found %04x:%04x\n",
                        enc->dev->name, phid1, phid2);
@@ -694,7 +672,7 @@ static int enc_setup(enc_dev_t *enc)
         * Prevent automatic loopback of data beeing transmitted by setting
         * ENC_PHCON2_HDLDIS
         */
-       phy_write(enc, PHY_REG_PHCON2, (1<<8));
+       enc_phy_write(enc, PHY_REG_PHCON2, (1<<8));
 
        /*
         * LEDs configuration
@@ -702,19 +680,10 @@ static int enc_setup(enc_dev_t *enc)
         * LEDB: LBCFG = 0111 -> display TX & RX activity
         * STRCH = 1 -> LED pulses
         */
-       phy_write(enc, PHY_REG_PHLCON, 0x0472);
+       enc_phy_write(enc, PHY_REG_PHLCON, 0x0472);
 
        /* Reset PDPXMD-bit => half duplex */
-       phy_write(enc, PHY_REG_PHCON1, 0);
-
-#ifdef CONFIG_USE_IRQ
-       /* enable interrupts */
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_PKTIE);
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_TXIE);
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_RXERIE);
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_TXERIE);
-       enc_bset(enc, CTL_REG_EIE, ENC_EIE_INTIE);
-#endif
+       enc_phy_write(enc, PHY_REG_PHCON1, 0);
 
        return 0;
 }
@@ -756,9 +725,10 @@ static int enc_initcheck(enc_dev_t *enc, const enum enc_initstate requiredstate)
  *
  * This function is registered with miiphy_register().
  */
-int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
+int enc_miiphy_read(struct mii_dev *bus, int phy_adr, int devad, int reg)
 {
-       struct eth_device *dev = eth_get_dev_by_name(devname);
+       u16 value = 0;
+       struct eth_device *dev = eth_get_dev_by_name(bus->name);
        enc_dev_t *enc;
 
        if (!dev || phy_adr != 0)
@@ -771,9 +741,9 @@ int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
                enc_release_bus(enc);
                return -1;
        }
-       *value = phy_read(enc, reg);
+       value = enc_phy_read(enc, reg);
        enc_release_bus(enc);
-       return 0;
+       return value;
 }
 
 /*
@@ -781,9 +751,10 @@ int enc_miiphy_read(const char *devname, u8 phy_adr, u8 reg, u16 *value)
  *
  * This function is registered with miiphy_register().
  */
-int enc_miiphy_write(const char *devname, u8 phy_adr, u8 reg, u16 value)
+int enc_miiphy_write(struct mii_dev *bus, int phy_adr, int devad, int reg,
+                    u16 value)
 {
-       struct eth_device *dev = eth_get_dev_by_name(devname);
+       struct eth_device *dev = eth_get_dev_by_name(bus->name);
        enc_dev_t *enc;
 
        if (!dev || phy_adr != 0)
@@ -796,7 +767,7 @@ int enc_miiphy_write(const char *devname, u8 phy_adr, u8 reg, u16 value)
                enc_release_bus(enc);
                return -1;
        }
-       phy_write(enc, reg, value);
+       enc_phy_write(enc, reg, value);
        enc_release_bus(enc);
        return 0;
 }
@@ -877,7 +848,7 @@ static int enc_recv(struct eth_device *dev)
  */
 static int enc_send(
        struct eth_device *dev,
-       volatile void *packet,
+       void *packet,
        int length)
 {
        enc_dev_t *enc = dev->priv;
@@ -972,7 +943,17 @@ int enc28j60_initialize(unsigned int bus, unsigned int cs,
        sprintf(dev->name, "enc%i.%i", bus, cs);
        eth_register(dev);
 #if defined(CONFIG_CMD_MII)
-       miiphy_register(dev->name, enc_miiphy_read, enc_miiphy_write);
+       int retval;
+       struct mii_dev *mdiodev = mdio_alloc();
+       if (!mdiodev)
+               return -ENOMEM;
+       strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
+       mdiodev->read = enc_miiphy_read;
+       mdiodev->write = enc_miiphy_write;
+
+       retval = mdio_register(mdiodev);
+       if (retval < 0)
+               return retval;
 #endif
        return 0;
 }