Merge tag 'uniphier-v2019.07' of git://git.denx.de/u-boot-uniphier
[oweals/u-boot.git] / drivers / net / sh_eth.c
index 6f48e93ab53d2376575e5f928b6a54c98f5ea9e7..4646f2ba4ec4ae213109f5cd588f2b1a408840ea 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>
@@ -769,19 +769,9 @@ static int sh_ether_start(struct udevice *dev)
        struct sh_eth_dev *eth = &priv->shdev;
        int ret;
 
-       ret = clk_enable(&priv->clk);
-       if (ret)
-               return ret;
-
        ret = sh_eth_init_common(eth, pdata->enetaddr);
        if (ret)
-               goto err_clk;
-
-       ret = sh_eth_phy_config(dev);
-       if (ret) {
-               printf(SHETHER_NAME ": phy config timeout\n");
-               goto err_start;
-       }
+               return ret;
 
        ret = sh_eth_start_common(eth);
        if (ret)
@@ -792,17 +782,17 @@ static int sh_ether_start(struct udevice *dev)
 err_start:
        sh_eth_tx_desc_free(eth);
        sh_eth_rx_desc_free(eth);
-err_clk:
-       clk_disable(&priv->clk);
        return ret;
 }
 
 static void sh_ether_stop(struct udevice *dev)
 {
        struct sh_ether_priv *priv = dev_get_priv(dev);
+       struct sh_eth_dev *eth = &priv->shdev;
+       struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
+       phy_shutdown(port_info->phydev);
        sh_eth_stop(&priv->shdev);
-       clk_disable(&priv->clk);
 }
 
 static int sh_ether_probe(struct udevice *udev)
@@ -810,6 +800,7 @@ 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;
        int ret;
 
@@ -819,8 +810,16 @@ static int sh_ether_probe(struct udevice *udev)
        if (ret < 0)
                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) {
@@ -844,8 +843,20 @@ static int sh_ether_probe(struct udevice *udev)
        eth->port_info[eth->port].iobase =
                (void __iomem *)(BASE_IO_ADDR + 0x800 * eth->port);
 
+       ret = clk_enable(&priv->clk);
+       if (ret)
+               goto err_mdio_register;
+
+       ret = sh_eth_phy_config(udev);
+       if (ret) {
+               printf(SHETHER_NAME ": phy config timeout\n");
+               goto err_phy_config;
+       }
+
        return 0;
 
+err_phy_config:
+       clk_disable(&priv->clk);
 err_mdio_register:
        mdio_free(mdiodev);
        return ret;
@@ -857,6 +868,7 @@ static int sh_ether_remove(struct udevice *udev)
        struct sh_eth_dev *eth = &priv->shdev;
        struct sh_eth_info *port_info = &eth->port_info[eth->port];
 
+       clk_disable(&priv->clk);
        free(port_info->phydev);
        mdio_unregister(priv->bus);
        mdio_free(priv->bus);
@@ -905,7 +917,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" },
        { }
 };