From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: neil.armstrong@linaro.org, olteanv@gmail.com,
devicetree@vger.kernel.org, vkoul@kernel.org,
linux-phy@lists.infradead.org, conor+dt@kernel.org,
robh@kernel.org
Subject: Re: [PATCH v2 2/2] phy: mediatek: Add support for PCI-Express Gen4 S-PHY
Date: Mon, 20 Jul 2026 14:13:00 +0000 [thread overview]
Message-ID: <20260720141301.482441F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260720135344.84183-3-angelogioacchino.delregno@collabora.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Improper handling of missing or unsupported NVMEM calibration data causes spurious error logs and hard probe failures.
- [Medium] A valid calibration value of 0 is incorrectly treated as missing data, discarding all calibrations.
- [Low] The TX_IMPSEL registers are updated twice with identical values during initialization.
- [Low] Macros for AEQ_EGEQ_RATIO are defined but unused in favor of literal magic numbers.
--
--- Patch [2]: [PATCH v2 2/2] phy: mediatek: Add support for PCI-Express Gen4 S-PHY ---
commit d91c6c0718440c44adc7e6a83f5aeca706a6c3d5
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Subject: phy: mediatek: Add support for PCI-Express Gen4 S-PHY
This patch adds support for the PCI-Express Gen4 S-PHY found in the latest
MediaTek SoCs, including MT8196 and MT8894.
> --- a/drivers/phy/mediatek/phy-mtk-pcie-sphy.c
> +++ b/drivers/phy/mediatek/phy-mtk-pcie-sphy.c
[ ... ]
> +#define PEXTP_DIG_LN_RX2_AEQ_EDGE_0 0x6004
> +# define RG_XTP_LN_RX_AEQ_EGEQ_RATIO_GEN3 GENMASK(21, 16)
> +# define RG_XTP_LN_RX_AEQ_EGEQ_RATIO_GEN4 GENMASK(29, 24)
> +# define AEQ_EGEQ_RATIO_GEN3_TO_22 0x16
> +# define AEQ_EGEQ_RATIO_GEN4_TO_22 0x16
[ ... ]
> + mtk_phy_update_field(sif_lane_base + PEXTP_DIG_LN_RX2_AEQ_EDGE_0,
> + RG_XTP_LN_RX_AEQ_EGEQ_RATIO_GEN3, 22);
> +
> + mtk_phy_update_field(sif_lane_base + PEXTP_DIG_LN_RX2_AEQ_EDGE_0,
> + RG_XTP_LN_RX_AEQ_EGEQ_RATIO_GEN4, 22);
[Severity: Low]
Is there a reason the literal 22 is used here instead of the
AEQ_EGEQ_RATIO_GEN3_TO_22 and AEQ_EGEQ_RATIO_GEN4_TO_22 macros defined
earlier?
[ ... ]
> +static void mtk_pcie_sphy_apply_calibration(struct mtk_pcie_sphy *pcie_sphy)
> +{
[ ... ]
> + mtk_phy_update_field(sif_lane_base + PEXTP_ANA_LN_TRX_A0,
> + RG_XTP_LN_TX_IMPSEL_PMOS, cal->tx_impsel.pmos);
> +
> + mtk_phy_update_field(sif_lane_base + PEXTP_ANA_LN_TRX_A0,
> + RG_XTP_LN_TX_IMPSEL_NMOS, cal->tx_impsel.nmos);
> + }
> +}
> +
[ ... ]
> +static int mtk_pcie_sphy_init(struct phy *phy)
> +{
[ ... ]
> + if (pcie_sphy->calibration.supported) {
> + mtk_pcie_sphy_apply_calibration(pcie_sphy);
> +
> + tx_impsel.pmos = pcie_sphy->calibration.tx_impsel.pmos;
> + tx_impsel.nmos = pcie_sphy->calibration.tx_impsel.nmos;
> + } else {
> + /* Set P=10, N=9 to prevent EMI if no calibration present */
> + tx_impsel.pmos = 10;
> + tx_impsel.nmos = 9;
> + }
> +
> + /* Select TX Impedance on N and P MOSFETs */
> + for (i = 0; i < pcie_sphy->num_lanes; i++) {
> + void __iomem *sif_lane_base = pcie_sphy->sif_base + PEXTP_REG_LANE(i);
> +
> + mtk_phy_update_field(sif_lane_base + PEXTP_ANA_LN_TRX_A0,
> + RG_XTP_LN_TX_IMPSEL_PMOS, tx_impsel.pmos);
> +
> + mtk_phy_update_field(sif_lane_base + PEXTP_ANA_LN_TRX_A0,
> + RG_XTP_LN_TX_IMPSEL_NMOS, tx_impsel.nmos);
> + }
[Severity: Low]
Are these register updates redundant?
When calibration is supported, mtk_pcie_sphy_apply_calibration() already
writes cal->tx_impsel.pmos and cal->tx_impsel.nmos to PEXTP_ANA_LN_TRX_A0.
Then this loop immediately overwrites the same registers with the exact same
values.
[ ... ]
> +static int mtk_pcie_sphy_get_one_cal_para(struct device *dev, const char *name, u8 max_val)
> +{
[ ... ]
> + ret = nvmem_cell_read_u8(dev, name, &tmp);
> + if (ret == 0)
> + buf = tmp;
> + else
> + ret = nvmem_cell_read_u16(dev, name, &buf);
> +
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Cannot get calibration data for %s\n", name);
[Severity: High]
Will this cause spurious error logs or fail the probe when calibration data is
missing or unsupported?
If the system does not have CONFIG_NVMEM enabled, nvmem_cell_read_u8() returns
-EOPNOTSUPP, which gets logged as an error here.
This error is then passed back up to mtk_pcie_sphy_get_calibration_data(),
where it is not caught. This will cause the entire driver probe to fail.
Similarly, if the cell is simply missing from the Device Tree, it returns
-ENOENT. This also triggers an error log via dev_err_probe(), even though
missing calibration data is explicitly documented as non-fatal and optional.
> +
> + if (buf == 0) {
> + dev_info(dev, "No calibration for %s. Using defaults\n", name);
> + return -ENOENT;
> + }
[Severity: Medium]
Is a value of 0 always indicative of missing calibration?
If a valid tuned calibration value is 0, this check will return -ENOENT and
cause mtk_pcie_sphy_get_calibration_data() to discard all calibrations entirely.
This also seems to prevent the quirk for cal-version == 0 from ever being
applied:
[ ... ]
> +static int mtk_pcie_sphy_get_calibration_data(struct mtk_pcie_sphy *pcie_sphy)
> +{
[ ... ]
> + ret = mtk_pcie_sphy_get_one_cal_para(dev, "cal-version", 15);
> + if (ret < 0)
> + goto end;
> + version = ret;
> +
> + /* Quirk for eFuse calibration table versions 0 to 4 */
> + if ((version <= MTK_PCIE_SPHY_CALIBRATION_LAST_QUIRK_VER) &&
> + cal->rx_leq_rl_ctle == 10) {
Because mtk_pcie_sphy_get_one_cal_para() returns -ENOENT when it reads a 0,
the version == 0 condition will never be reached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720135344.84183-1-angelogioacchino.delregno@collabora.com?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-07-20 14:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 13:53 [PATCH v2 0/2] PHY: Add MediaTek PCI-Express Gen4 S-PHY Driver AngeloGioacchino Del Regno
2026-07-20 13:53 ` [PATCH v2 1/2] dt-bindings: phy: Document MT8196 MediaTek PCI-Express Gen4 S-PHY AngeloGioacchino Del Regno
2026-07-20 14:01 ` sashiko-bot
2026-07-20 13:53 ` [PATCH v2 2/2] phy: mediatek: Add support for " AngeloGioacchino Del Regno
2026-07-20 14:13 ` sashiko-bot [this message]
2026-07-20 15:19 ` AngeloGioacchino Del Regno
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=20260720141301.482441F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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