]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/sh_eth.c
sf: add paired dev info for winbond w25q16jv
[u-boot] / drivers / net / sh_eth.c
index 5a5c6bc39ebb13ce65d4af7529504314bf0db319..2e1123c488a37ee8eed544a20f65abf872adcf55 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * sh_eth.c - Driver for Renesas ethernet controller.
  *
@@ -5,12 +6,11 @@
  * Copyright (c) 2008, 2011, 2014 2014 Nobuhiro Iwamatsu
  * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com>
  * Copyright (C) 2013, 2014 Renesas Electronics Corporation
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
 #include <common.h>
+#include <environment.h>
 #include <malloc.h>
 #include <net.h>
 #include <netdev.h>
@@ -63,8 +63,8 @@
 
 static int sh_eth_send_common(struct sh_eth_dev *eth, void *packet, int len)
 {
-       int port = eth->port, ret = 0, timeout;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       int ret = 0, timeout;
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
        if (!packet || len > 0xffff) {
                printf(SHETHER_NAME ": %s: Invalid argument\n", __func__);
@@ -120,8 +120,7 @@ err:
 
 static int sh_eth_recv_start(struct sh_eth_dev *eth)
 {
-       int port = eth->port, len = 0;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
        /* Check if the rx descriptor is ready */
        invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s));
@@ -132,9 +131,7 @@ static int sh_eth_recv_start(struct sh_eth_dev *eth)
        if (port_info->rx_desc_cur->rd0 & RD_RFE)
                return -EINVAL;
 
-       len = port_info->rx_desc_cur->rd1 & 0xffff;
-
-       return len;
+       return port_info->rx_desc_cur->rd1 & 0xffff;
 }
 
 static void sh_eth_recv_finish(struct sh_eth_dev *eth)
@@ -182,7 +179,7 @@ static int sh_eth_reset(struct sh_eth_dev *eth)
        return ret;
 #else
        sh_eth_write(port_info, sh_eth_read(port_info, EDMR) | EDMR_SRST, EDMR);
-       udelay(3000);
+       mdelay(3);
        sh_eth_write(port_info,
                     sh_eth_read(port_info, EDMR) & ~EDMR_SRST, EDMR);
 
@@ -192,9 +189,9 @@ static int sh_eth_reset(struct sh_eth_dev *eth)
 
 static int sh_eth_tx_desc_init(struct sh_eth_dev *eth)
 {
-       int port = eth->port, i, ret = 0;
+       int i, ret = 0;
        u32 alloc_desc_size = NUM_TX_DESC * sizeof(struct tx_desc_s);
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
        struct tx_desc_s *cur_tx_desc;
 
        /*
@@ -245,9 +242,9 @@ err:
 
 static int sh_eth_rx_desc_init(struct sh_eth_dev *eth)
 {
-       int port = eth->port, i, ret = 0;
+       int i, ret = 0;
        u32 alloc_desc_size = NUM_RX_DESC * sizeof(struct rx_desc_s);
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
        struct rx_desc_s *cur_rx_desc;
        u8 *rx_buf;
 
@@ -318,8 +315,7 @@ err:
 
 static void sh_eth_tx_desc_free(struct sh_eth_dev *eth)
 {
-       int port = eth->port;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
        if (port_info->tx_desc_alloc) {
                free(port_info->tx_desc_alloc);
@@ -329,8 +325,7 @@ static void sh_eth_tx_desc_free(struct sh_eth_dev *eth)
 
 static void sh_eth_rx_desc_free(struct sh_eth_dev *eth)
 {
-       int port = eth->port;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
        if (port_info->rx_desc_alloc) {
                free(port_info->rx_desc_alloc);
@@ -522,8 +517,8 @@ static int sh_eth_start_common(struct sh_eth_dev *eth)
 #ifndef CONFIG_DM_ETH
 static int sh_eth_phy_config_legacy(struct sh_eth_dev *eth)
 {
-       int port = eth->port, ret = 0;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       int ret = 0;
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
        struct eth_device *dev = port_info->dev;
        struct phy_device *phydev;
 
@@ -545,8 +540,8 @@ static int sh_eth_send_legacy(struct eth_device *dev, void *packet, int len)
 
 static int sh_eth_recv_common(struct sh_eth_dev *eth)
 {
-       int port = eth->port, len = 0;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       int len = 0;
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
        uchar *packet = (uchar *)ADDR_TO_P2(port_info->rx_desc_cur->rd2);
 
        len = sh_eth_recv_start(eth);
@@ -680,7 +675,7 @@ struct sh_ether_priv {
        struct sh_eth_dev       shdev;
 
        struct mii_dev          *bus;
-       void __iomem            *iobase;
+       phys_addr_t             iobase;
        struct clk              clk;
        struct gpio_desc        reset_gpio;
 };
@@ -750,8 +745,8 @@ static int sh_eth_phy_config(struct udevice *dev)
        struct sh_ether_priv *priv = dev_get_priv(dev);
        struct eth_pdata *pdata = dev_get_platdata(dev);
        struct sh_eth_dev *eth = &priv->shdev;
-       int port = eth->port, ret = 0;
-       struct sh_eth_info *port_info = &eth->port_info[port];
+       int ret = 0;
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
        struct phy_device *phydev;
        int mask = 0xffffffff;
 
@@ -815,24 +810,31 @@ static int sh_ether_probe(struct udevice *udev)
        struct eth_pdata *pdata = dev_get_platdata(udev);
        struct sh_ether_priv *priv = dev_get_priv(udev);
        struct sh_eth_dev *eth = &priv->shdev;
+       struct ofnode_phandle_args phandle_args;
        struct mii_dev *mdiodev;
-       void __iomem *iobase;
        int ret;
 
-       iobase = map_physmem(pdata->iobase, 0x1000, MAP_NOCACHE);
-       priv->iobase = iobase;
+       priv->iobase = pdata->iobase;
 
        ret = clk_get_by_index(udev, 0, &priv->clk);
        if (ret < 0)
-               goto err_mdio_alloc;
+               return ret;
 
-       gpio_request_by_name(udev, "reset-gpios", 0, &priv->reset_gpio,
-                            GPIOD_IS_OUT);
+       ret = dev_read_phandle_with_args(udev, "phy-handle", NULL, 0, 0, &phandle_args);
+       if (!ret) {
+               gpio_request_by_name_nodev(phandle_args.node, "reset-gpios", 0,
+                                          &priv->reset_gpio, GPIOD_IS_OUT);
+       }
+
+       if (!dm_gpio_is_valid(&priv->reset_gpio)) {
+               gpio_request_by_name(udev, "reset-gpios", 0, &priv->reset_gpio,
+                                    GPIOD_IS_OUT);
+       }
 
        mdiodev = mdio_alloc();
        if (!mdiodev) {
                ret = -ENOMEM;
-               goto err_mdio_alloc;
+               return ret;
        }
 
        mdiodev->read = bb_miiphy_read;
@@ -855,8 +857,6 @@ static int sh_ether_probe(struct udevice *udev)
 
 err_mdio_register:
        mdio_free(mdiodev);
-err_mdio_alloc:
-       unmap_physmem(priv->iobase, MAP_NOCACHE);
        return ret;
 }
 
@@ -873,8 +873,6 @@ static int sh_ether_remove(struct udevice *udev)
        if (dm_gpio_is_valid(&priv->reset_gpio))
                dm_gpio_free(udev, &priv->reset_gpio);
 
-       unmap_physmem(priv->iobase, MAP_NOCACHE);
-
        return 0;
 }
 
@@ -916,7 +914,10 @@ int sh_ether_ofdata_to_platdata(struct udevice *dev)
 }
 
 static const struct udevice_id sh_ether_ids[] = {
+       { .compatible = "renesas,ether-r8a7790" },
        { .compatible = "renesas,ether-r8a7791" },
+       { .compatible = "renesas,ether-r8a7793" },
+       { .compatible = "renesas,ether-r8a7794" },
        { }
 };