[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3RCG/Xt4y3OfisD@lunn.ch>
Date: Wed, 16 Nov 2022 02:51:23 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Corentin Labbe <clabbe@...libre.com>
Cc: broonie@...nel.org, calvin.johnson@....nxp.com,
davem@...emloft.net, edumazet@...gle.com, hkallweit1@...il.com,
jernej.skrabec@...il.com, krzysztof.kozlowski+dt@...aro.org,
kuba@...nel.org, lgirdwood@...il.com, linux@...linux.org.uk,
pabeni@...hat.com, robh+dt@...nel.org, samuel@...lland.org,
wens@...e.org, devicetree@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-sunxi@...ts.linux.dev, netdev@...r.kernel.org,
linux-sunxi@...glegroups.com
Subject: Re: [PATCH v4 2/3] phy: handle optional regulator for PHY
On Tue, Nov 15, 2022 at 07:36:02AM +0000, Corentin Labbe wrote:
> Add handling of optional regulators for PHY.
> Regulators need to be enabled before PHY scanning, so MDIO bus
> initiate this task.
>
> Signed-off-by: Corentin Labbe <clabbe@...libre.com>
> ---
> drivers/net/mdio/fwnode_mdio.c | 31 ++++++++++++++++++++++++++++++-
> drivers/net/phy/phy_device.c | 10 ++++++++++
> include/linux/phy.h | 3 +++
> 3 files changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
> index 689e728345ce..19a16072d4ca 100644
> --- a/drivers/net/mdio/fwnode_mdio.c
> +++ b/drivers/net/mdio/fwnode_mdio.c
> @@ -10,6 +10,7 @@
> #include <linux/fwnode_mdio.h>
> #include <linux/of.h>
> #include <linux/phy.h>
> +#include <linux/regulator/consumer.h>
> #include <linux/pse-pd/pse.h>
These headers are sorted, so please add regulator after pse.
>
> MODULE_AUTHOR("Calvin Johnson <calvin.johnson@....nxp.com>");
> @@ -116,7 +117,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
> struct phy_device *phy;
> bool is_c45 = false;
> u32 phy_id;
> - int rc;
> + int rc, reg_cnt = 0;
> + struct regulator_bulk_data *consumers = NULL;
> + struct device_node __maybe_unused *nchild = NULL;
Reverse Christmas tree.
>
> psec = fwnode_find_pse_control(child);
> if (IS_ERR(psec))
> @@ -133,6 +136,26 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
> if (rc >= 0)
> is_c45 = true;
>
> +#ifdef CONFIG_OF
Do you need this #ifdef ? Generally, all of_* functions should have
stubs if CONFIG_OF is not enabled. It would be nice to remove this, so
we get compile testing. And the __maybe_unused above is then probably
not needed.
> + for_each_child_of_node(bus->dev.of_node, nchild) {
> + u32 reg;
> +
> + of_property_read_u32(nchild, "reg", ®);
> + if (reg != addr)
> + continue;
> + reg_cnt = of_regulator_bulk_get_all(&bus->dev, nchild, &consumers);
> + if (reg_cnt > 0) {
> + rc = regulator_bulk_enable(reg_cnt, consumers);
> + if (rc)
> + return rc;
> + }
> + if (reg_cnt < 0) {
> + dev_err(&bus->dev, "Fail to regulator_bulk_get_all err=%d\n", reg_cnt);
> + return reg_cnt;
> + }
> + }
> +#endif
> +
Andrew
Powered by blists - more mailing lists