From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: olteanv@gmail.com, neil.armstrong@linaro.org, vkoul@kernel.org,
devicetree@vger.kernel.org, conor+dt@kernel.org,
dri-devel@lists.freedesktop.org, linux-phy@lists.infradead.org,
robh@kernel.org
Subject: Re: [PATCH 08/12] phy: phy-mtk-dp: Add support for digital and analog calibration
Date: Wed, 01 Jul 2026 12:48:23 +0000 [thread overview]
Message-ID: <20260701124824.2C1241F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701122008.19509-9-angelogioacchino.delregno@collabora.com>
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider:
- [High] Pointer casting a 16-bit variable to a `u8 *` in `nvmem_cell_read_u8()` causes incorrect value retrieval on big-endian architectures.
- [High] `mtk_dp_phy_set_analog_calibration_params()` clears hardware registers due to missing bitwise shifts and ignores eFuse calibration.
- [High] Legacy probe path fails to initialize analog calibration parameters, breaking PHY transmission.
- [High] Driver probe fails unconditionally on platforms without NVMEM support due to unhandled `-EOPNOTSUPP`.
- [High] Missing `pm_runtime_put_sync()`, `pm_runtime_disable()`, and `phy_remove_lookup()` in driver removal, with unchecked `pm_runtime_get_sync()`.
- [High] Incorrect indexing of digital register array using an analog enum causes writes to the wrong offsets during power off.
- [Medium] Spams `dev_err` on boot when expected eFuse calibration data is not present.
- [Medium] Incorrect field mask used when validating N-MOSFET impedance values.
- [Low] The field `efuse_cal_present` is set but never read.
--
commit d7c70553eca35e13b77a951e8cbb9167598a5701
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
phy: phy-mtk-dp: Add support for digital and analog calibration
This commit adds support for reading digital and analog calibration
values from eFuse for the MediaTek DP PHY. If calibration values are
present, they are used; otherwise, the driver falls back to SoC-specific
defaults. It also implements hardware writes for the analog calibration.
> diff --git a/drivers/phy/mediatek/phy-mtk-dp.c b/drivers/phy/mediatek/phy-mtk-dp.c
> index 17d871530ccaf..cdcae861012c7 100644
> --- a/drivers/phy/mediatek/phy-mtk-dp.c
> +++ b/drivers/phy/mediatek/phy-mtk-dp.c
[ ... ]
> @@ -257,21 +257,21 @@
> +static int mtk_dp_phy_set_analog_calibration_params(struct mtk_dp_phy *dp_phy)
> +{
> + const struct mtk_dp_phy_pdata *pdata = dp_phy->pdata;
> + const u8 *regs_ana_glb = pdata->regs_ana_glb;
> + const u8 *regs_ana_lane = pdata->regs_ana_lane;
> + int i, ret;
> +
> + ret = regmap_update_bits(dp_phy->regmap,
> + pdata->off_ana_glb + regs_ana_glb[DP_PHYA_GLB_BIAS_GEN_0],
> + XTP_GLB_BIAS_INT_R_CTRL, pdata->ana_bias_r);
[Severity: High]
Does this clear the hardware registers instead of applying the calibrated
values?
The regmap_update_bits() call uses the static pdata->ana_bias_r defaults
instead of the calibrated dp_phy->ana_bias_r. Additionally, passing unshifted
values with the high-mask field XTP_GLB_BIAS_INT_R_CTRL results in a bitwise
AND that yields zero.
[ ... ]
> @@ -517,109 +517,109 @@
> +static int mtk_dp_phy_get_one_cal_para(struct device *dev, const char *name, u8 max_val)
> +{
> + u16 buf = 0;
> + int ret;
> +
> + /*
> + * All of the calibrations are always max 8 bits long, but some may
> + * be split between two different 8-bits cells: handle this corner
> + * case by retrying reading as u16.
> + */
> + ret = nvmem_cell_read_u8(dev, name, (u8 *)&buf);
> + if (ret)
> + ret = nvmem_cell_read_u16(dev, name, &buf);
[Severity: High]
Can this pointer cast corrupt the read value on big-endian architectures?
Casting the 16-bit buf variable to (u8 *) will write to the most significant
byte on big-endian systems. This shifts the 8-bit value left by 8 bits, which
will exceed max_val and cause an -ERANGE error.
> +
> + if (ret) {
> + dev_err(dev, "Cannot get calibration data for %s: %d\n", name, ret);
> + return ret;
> + };
[Severity: Medium]
Will this spam dev_err on boot when the eFuse calibration data is missing?
If the NVMEM cells are absent, this unconditionally prints an error before the
fallback logic can handle the -ENOENT return code.
[ ... ]
> +static int mtk_dp_phy_get_calibration_data(struct mtk_dp_phy *dp_phy)
> +{
> + char mtk_dp_cal_lane_imp_name[] = "impedance-laneXM";
> + struct device *dev = dp_phy->dev;
> + int i, ret;
[ ... ]
> + /* Get impedance params for each lane */
> + for (i = 0; i < MTK_DP_PHY_MAX_LANES; i++) {
> + /* P-MOSFET first */
[ ... ]
> + /* ...and then N-MOSFET too */
> + snprintf(mtk_dp_cal_lane_imp_name, ARRAY_SIZE(mtk_dp_cal_lane_imp_name),
> + "impedance-lane%dn", i);
> + ret = mtk_dp_phy_get_one_cal_para(dev, mtk_dp_cal_lane_imp_name,
> + FIELD_MAX(XTP_LN_TX_IMPSEL_PMOS));
[Severity: Medium]
Is this using the wrong mask for the N-MOSFET impedance values?
It passes FIELD_MAX(XTP_LN_TX_IMPSEL_PMOS) instead of NMOS. While they both
share a 4-bit width currently, this might cause semantic errors if the bit
widths change.
> + if (ret < 0)
> + goto end;
> + dp_phy->ana_impsel[i].nmos = ret;
> + }
> +end:
> + if (ret < 0) {
> + /*
> + * If any of the calibration values is missing, or if there
> + * is no calibration at all in the eFuses, copy the default
> + * one entirely (as partial values shall not be mixed!)
> + */
> + if (ret == -ENOENT) {
> + dev_info(dev, "Using calibration default values\n");
> + mtk_dp_phy_get_default_cal_data(dp_phy);
> + return 0;
> + }
> + return ret;
> + };
[Severity: High]
Will the driver probe fail unconditionally on platforms without NVMEM support?
If NVMEM is disabled, nvmem_cell_read_u8() returns -EOPNOTSUPP. The strict
check for -ENOENT means the default fallback is skipped and the driver probe
aborts.
> + dp_phy->efuse_cal_present = true;
[Severity: Low]
Is this flag actually used anywhere?
The efuse_cal_present field is populated here but does not seem to be
evaluated anywhere else in the code.
> +
> + return 0;
> +}
[ ... ]
> @@ -437,6 +661,7 @@ static int mtk_dp_phy_probe(struct platform_device *pdev)
> struct mtk_dp_phy *dp_phy;
> void __iomem *base;
> struct phy *phy;
> + int ret;
>
> dp_phy = devm_kzalloc(dev, sizeof(*dp_phy), GFP_KERNEL);
> if (!dp_phy)
> @@ -458,6 +683,10 @@ static int mtk_dp_phy_probe(struct platform_device *pdev)
>
> dp_phy->pdata = device_get_match_data(dev);
>
> + ret = mtk_dp_phy_get_calibration_data(dp_phy);
> + if (ret)
> + return ret;
> +
[Severity: High]
Does the legacy probe path also need to initialize the analog calibration
parameters?
If mtk_dp_phy_legacy_probe() bypasses calibration data loading,
dp_phy->ana_impsel is left entirely zeroed. These uninitialized zeroes will
then be written directly to the PHY registers, which breaks transmission on
legacy platforms.
[Severity: High]
Does the driver properly clean up runtime PM resources during removal?
The probe function acquires PM resources without verifying the result:
pm_runtime_enable(dev);
pm_runtime_get_sync(dev);
But there appears to be no corresponding .remove callback providing
pm_runtime_put_sync(), pm_runtime_disable(), or phy_remove_lookup().
[Severity: High]
Does mtk_dp_phy_power_off() access the wrong offset by indexing a digital
register array with an analog enum?
Looking at mtk_dp_phy_power_off() in phy-mtk-dp.c:
static int mtk_dp_phy_power_off(struct phy *phy)
{
...
const u8 *regs = pdata->regs_dig_glb;
...
ret = regmap_set_bits(dp_phy->regmap,
pdata->off_ana_glb + regs[DP_PHYA_GLB_FORCE_CTRL_1],
Using DP_PHYA_GLB_FORCE_CTRL_1 (which is an analog enum) to index regs
(which points to regs_dig_glb) writes to the wrong offsets during power off.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260701122008.19509-1-angelogioacchino.delregno@collabora.com?part=8
next prev parent reply other threads:[~2026-07-01 12:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 12:19 [PATCH 00/12] PHY: MediaTek DP PHY refactor and MT8196 eDP AngeloGioacchino Del Regno
2026-07-01 12:19 ` [PATCH 01/12] dt-bindings: phy: Document MT8195 and MT8196 DisplayPort PHYs AngeloGioacchino Del Regno
2026-07-01 12:27 ` sashiko-bot
2026-07-01 13:07 ` AngeloGioacchino Del Regno
2026-07-01 14:38 ` Rob Herring (Arm)
2026-07-01 12:19 ` [PATCH 02/12] phy: phy-mtk-dp: Rename regs to regmap in struct mtk_dp_phy AngeloGioacchino Del Regno
2026-07-01 12:26 ` sashiko-bot
2026-07-01 13:05 ` AngeloGioacchino Del Regno
2026-07-01 12:19 ` [PATCH 03/12] phy: phy-mtk-dp: Allow probing with devicetree match AngeloGioacchino Del Regno
2026-07-01 12:30 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 04/12] phy: phy-mtk-dp: Migrate register offsets to SoC specific pdata AngeloGioacchino Del Regno
2026-07-01 12:36 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 05/12] phy: phy-mtk-dp: Implement power_on and power_off PHY callbacks AngeloGioacchino Del Regno
2026-07-01 12:39 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 06/12] phy: phy-mtk-dp: Support set_lanes in configure and properly cleanup AngeloGioacchino Del Regno
2026-07-01 12:35 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 07/12] phy: phy-mtk-dp: Support setting volt swing and preemphasis values AngeloGioacchino Del Regno
2026-07-01 12:49 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 08/12] phy: phy-mtk-dp: Add support for digital and analog calibration AngeloGioacchino Del Regno
2026-07-01 12:48 ` sashiko-bot [this message]
2026-07-01 12:20 ` [PATCH 09/12] phy: phy-mtk-dp: Rewrite and document default driving param macros AngeloGioacchino Del Regno
2026-07-01 12:50 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 10/12] phy: phy-mtk-dp: Add bitrate register val definitions to SoC data AngeloGioacchino Del Regno
2026-07-01 13:02 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 11/12] phy: phy-mtk-dp: Add PHYD Lane EN register mask " AngeloGioacchino Del Regno
2026-07-01 13:07 ` sashiko-bot
2026-07-01 12:20 ` [PATCH 12/12] phy: phy-mtk-dp: Add support for MT8196 eDP PHY AngeloGioacchino Del Regno
2026-07-01 13:01 ` sashiko-bot
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=20260701124824.2C1241F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.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