]> Git Repo - J-u-boot.git/blobdiff - drivers/net/phy/phy.c
net: phy: Replace PHY_ANEG_TIMEOUT with Kconfig symbol
[J-u-boot.git] / drivers / net / phy / phy.c
index 9cec04a0c94191668c298da668abe73cdca1603c..716a1d461115e2e353a568c77c379d822bdbd3ac 100644 (file)
@@ -7,7 +7,6 @@
  *
  * Based loosely off of Linux's PHY Lib
  */
-#include <common.h>
 #include <console.h>
 #include <dm.h>
 #include <log.h>
@@ -18,6 +17,8 @@
 #include <phy.h>
 #include <errno.h>
 #include <asm/global_data.h>
+#include <asm-generic/gpio.h>
+#include <dm/device_compat.h>
 #include <dm/of_extra.h>
 #include <linux/bitops.h>
 #include <linux/delay.h>
@@ -249,7 +250,7 @@ int genphy_update_link(struct phy_device *phydev)
                        /*
                         * Timeout reached ?
                         */
-                       if (i > (PHY_ANEG_TIMEOUT / 50)) {
+                       if (i > (CONFIG_PHY_ANEG_TIMEOUT / 50)) {
                                printf(" TIMEOUT !\n");
                                phydev->link = 0;
                                return -ETIMEDOUT;
@@ -769,6 +770,59 @@ int miiphy_reset(const char *devname, unsigned char addr)
        return phy_reset(phydev);
 }
 
+#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_REAL) && \
+    !IS_ENABLED(CONFIG_DM_ETH_PHY)
+int phy_gpio_reset(struct udevice *dev)
+{
+       struct ofnode_phandle_args phandle_args;
+       struct gpio_desc gpio;
+       u32 assert, deassert;
+       ofnode node;
+       int ret;
+
+       ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+                                        &phandle_args);
+       /* No PHY handle is OK */
+       if (ret)
+               return 0;
+
+       node = phandle_args.node;
+       if (!ofnode_valid(node))
+               return -EINVAL;
+
+       ret = gpio_request_by_name_nodev(node, "reset-gpios", 0, &gpio,
+                                        GPIOD_IS_OUT | GPIOD_ACTIVE_LOW);
+       /* No PHY reset GPIO is OK */
+       if (ret)
+               return 0;
+
+       assert = ofnode_read_u32_default(node, "reset-assert-us", 20000);
+       deassert = ofnode_read_u32_default(node, "reset-deassert-us", 1000);
+       ret = dm_gpio_set_value(&gpio, 1);
+       if (ret) {
+               dev_err(dev, "Failed assert gpio, err: %d\n", ret);
+               return ret;
+       }
+
+       udelay(assert);
+
+       ret = dm_gpio_set_value(&gpio, 0);
+       if (ret) {
+               dev_err(dev, "Failed deassert gpio, err: %d\n", ret);
+               return ret;
+       }
+
+       udelay(deassert);
+
+       return 0;
+}
+#else
+int phy_gpio_reset(struct udevice *dev)
+{
+       return 0;
+}
+#endif
+
 struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask)
 {
        /* Reset the bus */
This page took 0.026185 seconds and 4 git commands to generate.