devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>,
	"Théo Lebrun" <theo.lebrun@bootlin.com>,
	"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
	"Grégory Clement" <gregory.clement@bootlin.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org,
	linux-clk@vger.kernel.org,
	"Benoît Monin" <benoit.monin@bootlin.com>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v4 2/7] phy: Add driver for EyeQ5 Ethernet PHY wrapper
Date: Mon, 15 Dec 2025 16:08:38 +0100	[thread overview]
Message-ID: <DEYVVCWBOZSH.2ZY41YCHLS8FU@bootlin.com> (raw)
In-Reply-To: <DEUNYYW0Y23E.2SA0SOCS99NA0@bootlin.com>

Hello Luca,

On Wed Dec 10, 2025 at 5:06 PM CET, Luca Ceresoli wrote:
> On Mon Nov 24, 2025 at 3:41 PM CET, Théo Lebrun wrote:
>> EyeQ5 embeds a system-controller called OLB. It features many unrelated
>> registers, and some of those are registers used to configure the
>> integration of the RGMII/SGMII Cadence PHY used by MACB/GEM instances.
>>
>> Wrap in a neat generic PHY provider, exposing two PHYs with standard
>> phy_init() / phy_set_mode() / phy_power_on() operations.
>>
>> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
>
> [...]
>
>> --- /dev/null
>> +++ b/drivers/phy/phy-eyeq5-eth.c
>> @@ -0,0 +1,254 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +
>> +#include <linux/array_size.h>
>> +#include <linux/auxiliary_bus.h>
>> +#include <linux/bitfield.h>
>> +#include <linux/bits.h>
>> +#include <linux/bug.h>
>> +#include <linux/cleanup.h>
>> +#include <linux/container_of.h>
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/errno.h>
>> +#include <linux/init.h>
>> +#include <linux/io.h>
>> +#include <linux/iopoll.h>
>> +#include <linux/lockdep.h>
>> +#include <linux/mod_devicetable.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of.h>
>> +#include <linux/phy.h>
>> +#include <linux/phy/phy.h>
>> +#include <linux/slab.h>
>> +#include <linux/types.h>
>
> Are all these include files really needed? At a quick glance bitfield.h,
> cleanup.h and lockdep.h look unused in this file.

Yes good catch, after having checked all symbols used, updates are:
- Add delay.h for udelay(), gfp_types.h for GFP_* alloc flags,
  module.h for MODULE_* macros.
- Drop array_size.h, bug.h, cleanup.h, container_of.h, lockdep.h,
  mutex.h.

We do need bitfield.h for FIELD_PREP().

>
>> +#define EQ5_PHY_COUNT	2
>
> [...]
>
>> +static const struct phy_ops eq5_phy_ops = {
>> +	.init		= eq5_phy_init,
>> +	.exit		= eq5_phy_exit,
>> +	.set_mode	= eq5_phy_set_mode,
>> +	.power_on	= eq5_phy_power_on,
>> +	.power_off	= eq5_phy_power_off,
>> +};
>> +
>> +static struct phy *eq5_phy_xlate(struct device *dev,
>> +				 const struct of_phandle_args *args)
>> +{
>> +	struct eq5_phy_private *priv = dev_get_drvdata(dev);
>> +
>> +	if (args->args_count != 1 || args->args[0] > 1)
>
> Maybe, for better clarity:
>
> 	if (args->args_count != 1 || args->args[0] >= EQ5_PHY_COUNT)

Done, indeed the old magic value was not a good idea.

>
>> +		return ERR_PTR(-EINVAL);
>> +
>> +	return priv->phys[args->args[0]].phy;
>> +}
>> +
>> +static int eq5_phy_probe_phy(struct eq5_phy_private *priv, unsigned int index,
>> +			     void __iomem *base, unsigned int gp,
>> +			     unsigned int sgmii)
>> +{
>> +	struct eq5_phy_inst *inst = &priv->phys[index];
>> +	struct device *dev = priv->dev;
>> +	struct phy *phy;
>> +
>> +	phy = devm_phy_create(dev, dev->of_node, &eq5_phy_ops);
>> +	if (IS_ERR(phy)) {
>> +		dev_err(dev, "failed to create PHY %u\n", index);
>> +		return PTR_ERR(phy);
>> +	}
>
> Why not dev_err_probe()? It would make code more concise too:
>
> 	phy = devm_phy_create(dev, dev->of_node, &eq5_phy_ops);
> 	if (IS_ERR(phy))
> 		return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY %u\n", index);

Because I had forgotten. :-) Thanks!

>
>> +
>> +	inst->priv = priv;
>> +	inst->phy = phy;
>> +	inst->gp = base + gp;
>> +	inst->sgmii = base + sgmii;
>> +	inst->phy_interface = PHY_INTERFACE_MODE_NA;
>> +	phy_set_drvdata(phy, inst);
>> +
>> +	return 0;
>> +}
>> +
>> +static int eq5_phy_probe(struct auxiliary_device *adev,
>> +			 const struct auxiliary_device_id *id)
>> +{
>> +	struct device *dev = &adev->dev;
>> +	struct phy_provider *provider;
>> +	struct eq5_phy_private *priv;
>> +	void __iomem *base;
>> +	int ret;
>> +
>> +	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> +	if (!priv)
>> +		return -ENOMEM;
>> +
>> +	priv->dev = dev;
>> +	dev_set_drvdata(dev, priv);
>> +
>> +	base = (void __iomem *)dev_get_platdata(dev);
>> +
>> +	ret = eq5_phy_probe_phy(priv, 0, base, EQ5_PHY0_GP, EQ5_PHY0_SGMII);
>> +	if (ret)
>> +		return ret;
>> +
>> +	ret = eq5_phy_probe_phy(priv, 1, base, EQ5_PHY1_GP, EQ5_PHY1_SGMII);
>> +	if (ret)
>> +		return ret;
>> +
>> +	provider = devm_of_phy_provider_register(dev, eq5_phy_xlate);
>> +	if (IS_ERR(provider)) {
>> +		dev_err(dev, "registering provider failed\n");
>> +		return PTR_ERR(provider);
>> +	}
>
> As above, why not dev_err_probe()?

Good idea once again.

> Other than the above minor issues, LGTM. This driver looks cleanly
> implemented.

Thanks for the review. Does that imply I can append your Rb trailer?

Thanks Luca,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2025-12-15 15:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 14:41 [PATCH v4 0/7] Add generic PHY driver used by MACB/GEM on EyeQ5 Théo Lebrun
2025-11-24 14:41 ` [PATCH v4 1/7] dt-bindings: soc: mobileye: OLB is an Ethernet PHY provider " Théo Lebrun
2025-11-24 14:41 ` [PATCH v4 2/7] phy: Add driver for EyeQ5 Ethernet PHY wrapper Théo Lebrun
2025-12-10 16:06   ` Luca Ceresoli
2025-12-15 15:08     ` Théo Lebrun [this message]
2025-12-15 15:11       ` Luca Ceresoli
2025-12-15 16:30         ` Théo Lebrun
2025-12-15 18:15           ` Luca Ceresoli
2025-11-24 14:41 ` [PATCH v4 3/7] clk: eyeq: use the auxiliary device creation helper Théo Lebrun
2025-12-10 16:06   ` Luca Ceresoli
2025-11-24 14:41 ` [PATCH v4 4/7] clk: eyeq: add EyeQ5 children auxiliary device for generic PHYs Théo Lebrun
2025-12-10 16:06   ` Luca Ceresoli
2025-11-24 14:41 ` [PATCH v4 5/7] reset: eyeq: drop device_set_of_node_from_dev() done by parent Théo Lebrun
2025-11-24 14:41 ` [PATCH v4 6/7] MIPS: mobileye: eyeq5: add two Cadence GEM Ethernet controllers Théo Lebrun
2025-11-28  9:49   ` Gregory CLEMENT
2025-11-28  9:53     ` Thomas Bogendoerfer
2025-11-28 10:47       ` Gregory CLEMENT
2025-11-28 11:35         ` Thomas Bogendoerfer
2025-11-24 14:41 ` [PATCH v4 7/7] MIPS: mobileye: eyeq5-epm: add two Cadence GEM Ethernet PHYs Théo Lebrun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DEYVVCWBOZSH.2ZY41YCHLS8FU@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=benoit.monin@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=kishon@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mturquette@baylibre.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tawfik.bayouk@mobileye.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tsbogend@alpha.franken.de \
    --cc=vkoul@kernel.org \
    --cc=vladimir.kondratiev@mobileye.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).