From: Marek Vasut <marek.vasut@mailbox.org>
To: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Thanh Quan <thanh.quan.xn@renesas.com>,
Phong Hoang <phong.hoang.wz@renesas.com>,
Hai Pham <hai.pham.ud@renesas.com>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
Arnd Bergmann <arnd@arndb.de>,
Biju Das <biju.das.jz@bp.renesas.com>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Magnus Damm <magnus.damm@gmail.com>,
Manivannan Sadhasivam <mani@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Rob Herring <robh@kernel.org>,
Tam Nguyen <tam.nguyen.xa@renesas.com>,
Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>,
Vinh Nguyen <vinh.nguyen.xz@renesas.com>,
Vinod Koul <vkoul@kernel.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org
Subject: Re: [PATCH v2 2/3] phy: renesas: Add Renesas Multi-Protocol PHY driver for R-Car X5H
Date: Tue, 1 Dec 2026 00:01:40 +0100 [thread overview]
Message-ID: <76cc2ebc-9e5c-48eb-8219-4577045f01ac@mailbox.org> (raw)
In-Reply-To: <8e77b7aa-b5cb-4e60-9a01-a37bd6791b22@app.fastmail.com>
On 11/30/26 5:42 PM, Geert Uytterhoeven wrote:
Hello Geert,
>> +static void mp_phy_init_pcie4_ch_req(struct mp_phy_priv *priv, const int chs, const int chd,
>
> unsigned int first, unsigned int last
>
>> + const u32 cntxt2, const u32 txreq)
>
> No need for all the consts
>
>> +{
>> + int ch;
>> +
>> + for (ch = chs; ch <= chd; ch++) {
>
> unsigned int ch = ...
>
> Or perhaps drop ch and just increase first?
Can you please clarify this "Or perhaps ..." part ?
>> + regmap_set_bits(priv->map, MPPHY_PXCNTXT1(ch), 0x2010002);
>> + regmap_set_bits(priv->map, MPPHY_PXCNTXT2(ch), cntxt2);
>> + regmap_set_bits(priv->map, MPPHY_PXTXREQ(ch), txreq);
>> + }
>> +}
[...]
>> +static int mp_phy_init_pcie4(struct phy *phy)
>> +{
>> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
>> +
>> + if (priv->num_lanes[phy->id] == 2) {
>
> switch ()?
>
> However, I am wondering if the below can be refactored / simplified.
> The loops seem to run from 0 to num_lanes / 2 - 1, with a.o. some
> special handling for the first iteration?
This is the refactored outcome already.
Yes, channel 0 is special. In case of x2/x4 mode, channels 0 or 2 / 0+1
or 2+3 are used for PCIe0 or PCIe1 respectively ; in case of x8 mode,
all four channels are used for PCIe0. But there are exceptions regarding
the reset pulses and clock settings, please see comments in the code below.
>> + if (phy->id == 0) {
>> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x80004);
>> + mp_phy_init_pcie4_ch_clk(priv, 0, 0);
>> + mp_phy_init_pcie4_ch_rst(priv, 0, 0);
>> + } else if (phy->id == 1) {
>> + mp_phy_init_pcie4_ch_req(priv, 2, 2, 0x2020202, 0x8);
>> + mp_phy_init_pcie4_ch_clk(priv, 2, 2);
>> + mp_phy_init_pcie4_ch_rst(priv, 2, 2);
>> + }
>> + } else if (priv->num_lanes[phy->id] == 4) {
>> + if (phy->id == 0) {
>> + mp_phy_init_pcie4_ch_req(priv, 0, 1, 0x2020201, 0x80008);
>> + mp_phy_init_pcie4_ch_clk(priv, 0, 1);
>> + /* No reset pulse here. */
>> + } else if (phy->id == 1) {
>> + mp_phy_init_pcie4_ch_req(priv, 2, 3, 0x2020202, 0x8);
>> + mp_phy_init_pcie4_ch_clk(priv, 2, 3);
>> + mp_phy_init_pcie4_ch_rst(priv, 2, 3);
>> + }
>> + } else if (priv->num_lanes[phy->id] == 8) {
>> + mp_phy_init_pcie4_ch_req(priv, 0, 0, 0x2020201, 0x8);
>> + mp_phy_init_pcie4_ch_req(priv, 1, 3, 0x2020202, 0x8);
>> + /* No clk settings here. */
>> + mp_phy_init_pcie4_ch_rst(priv, 0, 3);
>> + }
>> +
>> + return 0;
>> +}
>
>> +static int mp_phy_init(struct phy *phy)
>> +{
>> + struct mp_phy_priv *priv = phy_get_drvdata(phy);
>> + struct mp_phy_chan_priv *chan = &priv->chan[phy->id];
>> + int ret;
>> +
>> + if (chan->initialized)
>> + return 0;
>> +
>> + /*
>> + * Note: Current source code support for Ethernet, PCIe initialization
>> + * is based on the bare metal code shared by the board team.
>> + */
>> + ret = pm_runtime_get_sync(priv->pd_list->pd_devs[phy->id]);
>> + if (ret < 0) {
>> + dev_err(priv->dev,
>> + "Failed to power on domain for channel %d: %d\n",
>> + phy->id, ret);
>
> %pe and ERR_PTR(ret)?
pm_runtime_get_sync() does not return error pointer ?
[...]
>> +static int mp_phy_parse_dt(struct platform_device *pdev, struct mp_phy_priv *priv)
>> +{
>> + u32 phy_type[2 * MPPHY_NUM_CHANNELS];
>> + u32 ext_ref_clk[MPPHY_NUM_CHANNELS];
>> + u32 out_ref_clk[MPPHY_NUM_CHANNELS];
>> + struct device *dev = &pdev->dev;
>> + int i, ret;
>
> unsigned int i
>
>> +
>> + ret = device_property_read_u32_array(dev, "renesas,phy-type", phy_type, 8);
>> + if (ret < 0)
>> + return dev_err_probe(dev, -EINVAL, "Failed to read PHY configuration\n");
>> +
>> + ret = device_property_read_u32_array(dev, "renesas,external-ref-clock",
>> + ext_ref_clk, 4);
>> + if (ret < 0)
>> + return dev_err_probe(dev, -EINVAL, "Failed to read PHY clock configuration\n");
>> +
>> + ret = device_property_read_u32_array(dev, "renesas,output-repeat-ref-clock",
>> + out_ref_clk, 4);
>> + if (ret < 0)
>> + return dev_err_probe(dev, -EINVAL, "Failed to read PHY clock out configuration\n");
>> +
>> + /* Test whether the supplied configuration is valid. */
>> + for (i = 0; i < ARRAY_SIZE(mp_phy_valid_configs); i++) {
>> + if (phy_type[0] == mp_phy_valid_configs[i].phy_type[0] &&
>> + phy_type[1] == mp_phy_valid_configs[i].phy_type[1] &&
>> + phy_type[2] == mp_phy_valid_configs[i].phy_type[2] &&
>> + phy_type[3] == mp_phy_valid_configs[i].phy_type[3] &&
>> + phy_type[4] == mp_phy_valid_configs[i].phy_type[4] &&
>> + phy_type[5] == mp_phy_valid_configs[i].phy_type[5] &&
>> + phy_type[6] == mp_phy_valid_configs[i].phy_type[6] &&
>> + phy_type[7] == mp_phy_valid_configs[i].phy_type[7])
>
> memcmp()
The phy_type[] array on the left is u32[], but the
mp_phy_valid_configs[i].phy_type array on the right is u8[] to conserve
space, so memcmp() won't work here. I could convert the former into u8[]
but I'm not convinced doing it only for the sake of using memcmp() is
good. Then again, this conditional also does not look great.
[...]
--
Best regards,
Marek Vasut
next prev parent reply other threads:[~2026-11-30 23:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 17:37 [PATCH v2 1/3] dt-bindings: phy: Document " Marek Vasut
2026-11-29 17:37 ` [PATCH v2 2/3] phy: renesas: Add " Marek Vasut
2026-11-30 1:05 ` kernel test robot
2026-11-30 1:38 ` kernel test robot
2026-11-30 16:42 ` Geert Uytterhoeven
2026-11-30 23:01 ` Marek Vasut [this message]
2026-11-29 17:37 ` [PATCH v2 3/3] phy: renesas: rcar-gen5-mpphy: Document how to obtain firmware Marek Vasut
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=76cc2ebc-9e5c-48eb-8219-4577045f01ac@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=arnd@arndb.de \
--cc=biju.das.jz@bp.renesas.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=hai.pham.ud@renesas.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=phong.hoang.wz@renesas.com \
--cc=robh@kernel.org \
--cc=tam.nguyen.xa@renesas.com \
--cc=thanh.quan.xn@renesas.com \
--cc=tommaso.merciai.xr@bp.renesas.com \
--cc=vinh.nguyen.xz@renesas.com \
--cc=vkoul@kernel.org \
--cc=yoshihiro.shimoda.uh@renesas.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
all inboxes | Powered by JetHome®