net: dm: fec: Support the phy-supply binding
Configure the phy regulator if defined by the "phy-supply" DT phandle.
Signed-off-by: Martin Fuzzey <martin.fuzzey@flowbird.group>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index da970ef..d3a926d 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -15,6 +15,7 @@
#include <miiphy.h>
#include <net.h>
#include <netdev.h>
+#include <power/regulator.h>
#include <asm/io.h>
#include <linux/errno.h>
@@ -1272,6 +1273,16 @@
if (ret)
return ret;
+#ifdef CONFIG_DM_REGULATOR
+ if (priv->phy_supply) {
+ ret = regulator_autoset(priv->phy_supply);
+ if (ret) {
+ printf("%s: Error enabling phy supply\n", dev->name);
+ return ret;
+ }
+ }
+#endif
+
#ifdef CONFIG_DM_GPIO
fec_gpio_reset(priv);
#endif
@@ -1327,6 +1338,11 @@
mdio_unregister(priv->bus);
mdio_free(priv->bus);
+#ifdef CONFIG_DM_REGULATOR
+ if (priv->phy_supply)
+ regulator_set_enable(priv->phy_supply, false);
+#endif
+
return 0;
}
@@ -1350,6 +1366,10 @@
return -EINVAL;
}
+#ifdef CONFIG_DM_REGULATOR
+ device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply);
+#endif
+
#ifdef CONFIG_DM_GPIO
ret = gpio_request_by_name(dev, "phy-reset-gpios", 0,
&priv->phy_reset_gpio, GPIOD_IS_OUT);