]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/ravb.c
net: ravb: Add R8A77965 M3N entries
[u-boot] / drivers / net / ravb.c
index 8db127ba06fa71077e9731d20947facb6cb32428..ae120e59ba6e5f4f04889f4fdfd244433dd8e8b1 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/mii.h>
 #include <wait_bit.h>
 #include <asm/io.h>
+#include <asm/gpio.h>
 
 /* Registers */
 #define RAVB_REG_CCC           0x000
@@ -122,6 +123,7 @@ struct ravb_priv {
        struct mii_dev          *bus;
        void __iomem            *iobase;
        struct clk              clk;
+       struct gpio_desc        reset_gpio;
 };
 
 static inline void ravb_flush_dcache(u32 addr, u32 len)
@@ -220,8 +222,8 @@ static int ravb_reset(struct udevice *dev)
        writel(CCC_OPC_CONFIG, eth->iobase + RAVB_REG_CCC);
 
        /* Check the operating mode is changed to the config mode. */
-       return wait_for_bit(dev->name, (void *)eth->iobase + RAVB_REG_CSR,
-                           CSR_OPS_CONFIG, true, 100, true);
+       return wait_for_bit_le32(eth->iobase + RAVB_REG_CSR,
+                                CSR_OPS_CONFIG, true, 100, true);
 }
 
 static void ravb_base_desc_init(struct ravb_priv *eth)
@@ -302,6 +304,13 @@ static int ravb_phy_config(struct udevice *dev)
        struct phy_device *phydev;
        int mask = 0xffffffff, reg;
 
+       if (dm_gpio_is_valid(&eth->reset_gpio)) {
+               dm_gpio_set_value(&eth->reset_gpio, 1);
+               mdelay(20);
+               dm_gpio_set_value(&eth->reset_gpio, 0);
+               mdelay(1);
+       }
+
        phydev = phy_find_by_mask(eth->bus, mask, pdata->phy_interface);
        if (!phydev)
                return -ENODEV;
@@ -390,7 +399,7 @@ static int ravb_dmac_init(struct udevice *dev)
 static int ravb_config(struct udevice *dev)
 {
        struct ravb_priv *eth = dev_get_priv(dev);
-       struct phy_device *phy;
+       struct phy_device *phy = eth->phydev;
        u32 mask = ECMR_CHG_DM | ECMR_RE | ECMR_TE;
        int ret;
 
@@ -401,13 +410,6 @@ static int ravb_config(struct udevice *dev)
        ravb_mac_init(eth);
        ravb_write_hwaddr(dev);
 
-       /* Configure phy */
-       ret = ravb_phy_config(dev);
-       if (ret)
-               return ret;
-
-       phy = eth->phydev;
-
        ret = phy_startup(phy);
        if (ret)
                return ret;
@@ -429,15 +431,11 @@ static int ravb_config(struct udevice *dev)
        return 0;
 }
 
-int ravb_start(struct udevice *dev)
+static int ravb_start(struct udevice *dev)
 {
        struct ravb_priv *eth = dev_get_priv(dev);
        int ret;
 
-       ret = clk_enable(&eth->clk);
-       if (ret)
-               return ret;
-
        ret = ravb_reset(dev);
        if (ret)
                goto err;
@@ -464,8 +462,8 @@ static void ravb_stop(struct udevice *dev)
 {
        struct ravb_priv *eth = dev_get_priv(dev);
 
+       phy_shutdown(eth->phydev);
        ravb_reset(dev);
-       clk_disable(&eth->clk);
 }
 
 static int ravb_probe(struct udevice *dev)
@@ -483,6 +481,9 @@ static int ravb_probe(struct udevice *dev)
        if (ret < 0)
                goto err_mdio_alloc;
 
+       gpio_request_by_name(dev, "reset-gpios", 0, &eth->reset_gpio,
+                            GPIOD_IS_OUT);
+
        mdiodev = mdio_alloc();
        if (!mdiodev) {
                ret = -ENOMEM;
@@ -500,8 +501,23 @@ static int ravb_probe(struct udevice *dev)
 
        eth->bus = miiphy_get_dev_by_name(dev->name);
 
+       /* Bring up PHY */
+       ret = clk_enable(&eth->clk);
+       if (ret)
+               goto err_mdio_register;
+
+       ret = ravb_reset(dev);
+       if (ret)
+               goto err_mdio_reset;
+
+       ret = ravb_phy_config(dev);
+       if (ret)
+               goto err_mdio_reset;
+
        return 0;
 
+err_mdio_reset:
+       clk_disable(&eth->clk);
 err_mdio_register:
        mdio_free(mdiodev);
 err_mdio_alloc:
@@ -513,9 +529,13 @@ static int ravb_remove(struct udevice *dev)
 {
        struct ravb_priv *eth = dev_get_priv(dev);
 
+       clk_disable(&eth->clk);
+
        free(eth->phydev);
        mdio_unregister(eth->bus);
        mdio_free(eth->bus);
+       if (dm_gpio_is_valid(&eth->reset_gpio))
+               dm_gpio_free(dev, &eth->reset_gpio);
        unmap_physmem(eth->iobase, MAP_NOCACHE);
 
        return 0;
@@ -638,6 +658,9 @@ int ravb_ofdata_to_platdata(struct udevice *dev)
 static const struct udevice_id ravb_ids[] = {
        { .compatible = "renesas,etheravb-r8a7795" },
        { .compatible = "renesas,etheravb-r8a7796" },
+       { .compatible = "renesas,etheravb-r8a77965" },
+       { .compatible = "renesas,etheravb-r8a77970" },
+       { .compatible = "renesas,etheravb-r8a77995" },
        { .compatible = "renesas,etheravb-rcar-gen3" },
        { }
 };