Revert "ARM64: zynqmp: Added broken-tuning property to SD, eMMC nodes"
[oweals/u-boot.git] / drivers / net / designware.c
index 16731674e44b935a9ecf431f2b6d8ea1387d92eb..9e6d7261844323827039cc2ad7c4bf0b0d2cd3ec 100644 (file)
@@ -24,7 +24,12 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
 {
+#ifdef CONFIG_DM_ETH
+       struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv);
+       struct eth_mac_regs *mac_p = priv->mac_regs_p;
+#else
        struct eth_mac_regs *mac_p = bus->priv;
+#endif
        ulong start;
        u16 miiaddr;
        int timeout = CONFIG_MDIO_TIMEOUT;
@@ -47,7 +52,12 @@ static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
 static int dw_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
                        u16 val)
 {
+#ifdef CONFIG_DM_ETH
+       struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv);
+       struct eth_mac_regs *mac_p = priv->mac_regs_p;
+#else
        struct eth_mac_regs *mac_p = bus->priv;
+#endif
        ulong start;
        u16 miiaddr;
        int ret = -ETIMEDOUT, timeout = CONFIG_MDIO_TIMEOUT;
@@ -70,7 +80,41 @@ static int dw_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
        return ret;
 }
 
-static int dw_mdio_init(const char *name, struct eth_mac_regs *mac_regs_p)
+#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO)
+static int dw_mdio_reset(struct mii_dev *bus)
+{
+       struct udevice *dev = bus->priv;
+       struct dw_eth_dev *priv = dev_get_priv(dev);
+       struct dw_eth_pdata *pdata = dev_get_platdata(dev);
+       int ret;
+
+       if (!dm_gpio_is_valid(&priv->reset_gpio))
+               return 0;
+
+       /* reset the phy */
+       ret = dm_gpio_set_value(&priv->reset_gpio, 0);
+       if (ret)
+               return ret;
+
+       udelay(pdata->reset_delays[0]);
+
+       ret = dm_gpio_set_value(&priv->reset_gpio, 1);
+       if (ret)
+               return ret;
+
+       udelay(pdata->reset_delays[1]);
+
+       ret = dm_gpio_set_value(&priv->reset_gpio, 0);
+       if (ret)
+               return ret;
+
+       udelay(pdata->reset_delays[2]);
+
+       return 0;
+}
+#endif
+
+static int dw_mdio_init(const char *name, void *priv)
 {
        struct mii_dev *bus = mdio_alloc();
 
@@ -82,8 +126,11 @@ static int dw_mdio_init(const char *name, struct eth_mac_regs *mac_regs_p)
        bus->read = dw_mdio_read;
        bus->write = dw_mdio_write;
        snprintf(bus->name, sizeof(bus->name), "%s", name);
+#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO)
+       bus->reset = dw_mdio_reset;
+#endif
 
-       bus->priv = (void *)mac_regs_p;
+       bus->priv = priv;
 
        return mdio_register(bus);
 }
@@ -611,7 +658,7 @@ static int designware_eth_probe(struct udevice *dev)
        priv->interface = pdata->phy_interface;
        priv->max_speed = pdata->max_speed;
 
-       dw_mdio_init(dev->name, priv->mac_regs_p);
+       dw_mdio_init(dev->name, dev);
        priv->bus = miiphy_get_dev_by_name(dev->name);
 
        ret = dw_phy_init(priv, dev);
@@ -642,9 +689,17 @@ static const struct eth_ops designware_eth_ops = {
 
 static int designware_eth_ofdata_to_platdata(struct udevice *dev)
 {
-       struct eth_pdata *pdata = dev_get_platdata(dev);
+       struct dw_eth_pdata *dw_pdata = dev_get_platdata(dev);
+#ifdef CONFIG_DM_GPIO
+       struct dw_eth_dev *priv = dev_get_priv(dev);
+#endif
+       struct eth_pdata *pdata = &dw_pdata->eth_pdata;
        const char *phy_mode;
        const fdt32_t *cell;
+#ifdef CONFIG_DM_GPIO
+       int reset_flags = GPIOD_IS_OUT;
+#endif
+       int ret = 0;
 
        pdata->iobase = dev_get_addr(dev);
        pdata->phy_interface = -1;
@@ -661,12 +716,28 @@ static int designware_eth_ofdata_to_platdata(struct udevice *dev)
        if (cell)
                pdata->max_speed = fdt32_to_cpu(*cell);
 
-       return 0;
+#ifdef CONFIG_DM_GPIO
+       if (fdtdec_get_bool(gd->fdt_blob, dev->of_offset,
+                           "snps,reset-active-low"))
+               reset_flags |= GPIOD_ACTIVE_LOW;
+
+       ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
+               &priv->reset_gpio, reset_flags);
+       if (ret == 0) {
+               ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
+                       "snps,reset-delays-us", dw_pdata->reset_delays, 3);
+       } else if (ret == -ENOENT) {
+               ret = 0;
+       }
+#endif
+
+       return ret;
 }
 
 static const struct udevice_id designware_eth_ids[] = {
        { .compatible = "allwinner,sun7i-a20-gmac" },
        { .compatible = "altr,socfpga-stmmac" },
+       { .compatible = "amlogic,meson6-dwmac" },
        { }
 };
 
@@ -680,7 +751,7 @@ U_BOOT_DRIVER(eth_designware) = {
        .remove = designware_eth_remove,
        .ops    = &designware_eth_ops,
        .priv_auto_alloc_size = sizeof(struct dw_eth_dev),
-       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+       .platdata_auto_alloc_size = sizeof(struct dw_eth_pdata),
        .flags = DM_FLAG_ALLOC_PRIV_DMA,
 };