From ca8811172bdc2a8afc5ab62b0695a32baf6b5788 Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Tue, 24 Nov 2020 20:19:43 +0100 Subject: net: stmmac: dwmac-imx: add phy-supply Add an support for an optional regulator which powers an attached phy. Signed-off-by: Max Krummenacher --- .../devicetree/bindings/net/imx-dwmac.txt | 1 + drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c | 25 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/imx-dwmac.txt b/Documentation/devicetree/bindings/net/imx-dwmac.txt index 402885fc0992..4a1cd825d676 100644 --- a/Documentation/devicetree/bindings/net/imx-dwmac.txt +++ b/Documentation/devicetree/bindings/net/imx-dwmac.txt @@ -27,6 +27,7 @@ Required properties: Optional properties: - intf_mode: is optional for imx8dxl platform. +- phy-supply: regulator that powers the Ethernet PHY. - snps,rmii_refclk_ext: to select RMII reference clock from external. Example: diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c index f86d24af34c4..f79dcca08806 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,7 @@ struct imx_priv_data { struct clk *clk_tx; struct clk *clk_mem; struct regmap *intf_regmap; + struct regulator *regulator; u32 intf_reg_off; bool rmii_refclk_ext; @@ -176,6 +178,12 @@ static int imx_dwmac_init(struct platform_device *pdev, void *priv) goto intf_mode_failed; } + ret = regulator_enable(dwmac->regulator); + if (ret) { + dev_err(dwmac->dev, "fail to enable phy-supply\n"); + goto intf_mode_failed; + } + return 0; intf_mode_failed: @@ -205,6 +213,11 @@ static void imx_dwmac_exit(struct platform_device *pdev, void *priv) if (dwmac->clk_tx) clk_disable_unprepare(dwmac->clk_tx); clk_disable_unprepare(dwmac->clk_mem); + + ret = regulator_disable(dwmac->regulator); + if (ret) + dev_err(dwmac->dev, "fail to disable phy-supply\n"); + pm_runtime_put(&pdev->dev); } @@ -280,6 +293,15 @@ imx_dwmac_parse_dt(struct imx_priv_data *dwmac, struct device *dev) } } + dwmac->regulator = devm_regulator_get_optional(dev, "phy"); + if (IS_ERR(dwmac->regulator)) { + if (PTR_ERR(dwmac->regulator) == -EPROBE_DEFER) { + return -EPROBE_DEFER; + } + dev_err(dev, "no regulator found\n"); + dwmac->regulator = NULL; + } + return err; } @@ -315,7 +337,8 @@ static int imx_dwmac_probe(struct platform_device *pdev) ret = imx_dwmac_parse_dt(dwmac, &pdev->dev); if (ret) { - dev_err(&pdev->dev, "failed to parse OF data\n"); + if (ret != -EPROBE_DEFER) + dev_err(&pdev->dev, "failed to parse OF data\n"); goto err_parse_dt; } -- cgit v1.2.3