Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gary Yang" <gary.yang@cixtech.com>
Cc: linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, vkoul@kernel.org,
	neil.armstrong@linaro.org, olteanv@gmail.com
Subject: Re: [PATCH v8 2/2] phy: cix: add Sky1 USB/DP combo PHY driver
Date: Thu, 03 Dec 2026 11:12:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-247654@kernel.org> (raw)
In-Reply-To: <20261203104915.231202-3-gary.yang@cixtech.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] phy: cix: udphy_dp_phy_set_rate() ignores dp->ssc leaving SSC
  always enabled
- [Medium] phy: cix: premature PHY provider registration in
  cix_udphy_probe()
- [Medium] phy: cix: udphy_dp_phy_set_rate() under-waits PLL1 lock and
  PMA ready
--

commit 29c5fede3844afcbadc8c1146b5c8f3d0bf0f9e2
Author: Gary Yang <gary.yang@cixtech.com>

phy: cix: add Sky1 USB/DP combo PHY driver

This commit adds a driver for the CIX Sky1 USB/DP combo PHY, exposing
separate USB3 and DisplayPort PHYs and registering a Type-C orientation
switch and mode mux.

> diff --git a/drivers/phy/cix/phy-cix-usbdp.c b/drivers/phy/cix/phy-cix-usbdp.c
> new file mode 100644
> index 0000000000000..6d655cc0ac076
> --- /dev/null
> +++ b/drivers/phy/cix/phy-cix-usbdp.c

[ ... ]

> +static int udphy_dp_phy_set_rate(struct cix_udphy *udphy,
> +				 struct phy_configure_opts_dp *dp)
> +{

[ ... ]

> +	udphy_update_bits(udphy, PHY_PMA_PLL_CTRL, BIT(1), 0x0);
> +	usleep_range(10, 20);
> +
> +	udphy_write_table(udphy, conf->seq, conf->num_seq);
> +
> +	/*
> +	 * Program the divider of every lane assigned to DisplayPort, not just
> +	 * the lanes of the previous configuration: the caller may raise the
> +	 * lane count in a separate phy_configure() call, without repeating the
> +	 * rate update.
> +	 */
> +	for (i = 0; i < udphy_dplane_get(udphy); i++) {
> +		u32 lane = udphy_dp_lane_to_pma(udphy, i);
> +		u32 reg = XCVR_DIAG_HSCLK_DIV_LANE0 + lane * PHY_LANE_STRIDE;
> +
> +		writel(conf->hsclk_div, udphy->base + reg * 4);
> +	}
> +
> +	writel(conf->pll_intdiv, udphy->base + CMN_PLL1_INTDIV_M0 * 4);
> +	writel(conf->pll_fracdivl, udphy->base + CMN_PLL1_FRACDIVL_M0 * 4);
> +	writel(conf->pll_high_thr, udphy->base + CMN_PLL1_HIGH_THR_M0 * 4);
> +	writel(conf->clk_sel, udphy->base + CMN_PDIAG_PLL1_CLK_SEL_M0 * 4);

[Severity: Medium]
Should udphy_dp_phy_set_rate() also program CMN_PLL1_SS_CTRL1_M0 according
to dp->ssc?

All three mode tables unconditionally write 0x0001 to
CMN_PLL1_SS_CTRL1_M0, so SSC stays enabled on PLL1 even when a
DisplayPort sink does not support downspread (dp->ssc == 0).

struct phy_configure_opts_dp expects set_rate to apply both link_rate
and ssc, and driving SSC on a non-SSC sink can break link training.  The
sibling driver in drivers/phy/cix/phy-cix-dp.c toggles the same offset
(0x00d8) between 0x0001 and 0x0000 in cix_dp_phy_set_ssc().

> +
> +	udphy_update_bits(udphy, PHY_PMA_PLL_CTRL, BIT(1), BIT(1));
> +	usleep_range(10, 20);
> +
> +	return 0;
> +}

[Severity: Medium]
Is usleep_range(10, 20) long enough here, instead of polling the PMA
status registers for PLL1 disable and lock?

At the 24 MHz reference clock implied by link_cfg[], the PLL1 startup,
VCO calibration, and lock timers programmed in the mode tables sum to at
least 61 us for a single calibration iteration.  Reprogramming PLL1 before
it disables or returning before it locks can break DP link training.

Similarly, after a deferred sky1_udphy_reinit() in
udphy_dp_phy_configure(), udphy_dp_phy_set_rate() runs right after
deasserting udphy->reset without waiting for PMA common readiness.

Both drivers/phy/cix/phy-cix-dp.c (cix_dp_pll_raw_ctrl_ack()) and
drivers/phy/cadence/phy-cadence-torrent.c poll PHY_PMA_CMN_CTRL2 (0xe001)
for PLL disable/ready and wait for PMA common readiness after reset.

[ ... ]

> +	phy_provider = devm_of_phy_provider_register(dev, cix_udphy_phy_xlate);
> +	if (IS_ERR(phy_provider))
> +		return dev_err_probe(dev, PTR_ERR(phy_provider),
> +				     "failed to register PHY provider\n");
> +
> +	/*
> +	 * Register with the Type-C class only once the PHYs and the provider
> +	 * are in place, so that the switch and mux callbacks cannot run before
> +	 * the driver is fully set up.
> +	 */
> +	if (device_property_present(dev, "orientation-switch")) {
> +		ret = udphy_setup_orien_switch(udphy);
> +		if (ret)
> +			return ret;
> +
> +		ret = devm_add_action_or_reset(dev,
> +					       udphy_orien_switch_unregister,
> +					       udphy);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	if (device_property_present(dev, "mode-switch")) {
> +		ret = udphy_setup_typec_mux(udphy);
> +		if (ret)
> +			return ret;
> +
> +		ret = devm_add_action_or_reset(dev, udphy_typec_mux_unregister,
> +					       udphy);
> +		if (ret)
> +			return ret;
> +	}

[Severity: Medium]
Can registering the PHY provider before the Type-C orientation switch and
mux cause a use-after-free if one of those registrations fails?

Because the OF graph ports between this PHY and its USB3/DP consumers
form a cycle with the phys links, fw_devlink relaxes them and a consumer
can probe as soon as devm_of_phy_provider_register() publishes the
provider:

CPU0                                CPU1
cix_udphy_probe()
  devm_of_phy_provider_register()
                                    consumer probe
                                      phy_get() -> u3_phy
                                      phy_init(u3_phy)
  udphy_setup_typec_mux() fails
  devres_release_all()
    phy_destroy(u3_phy)
    devm_kfree(udphy)
                                      phy_exit(u3_phy)
                                        cix_u3phy_exit()
                                          &udphy->mutex  <-- use-after-free

phy_destroy() calls device_unregister() without revoking active consumer
references, so devres frees struct cix_udphy (and puts apb_clk while
still enabled) while the consumer still holds u3_phy.

Moving devm_of_phy_provider_register() to the end of cix_udphy_probe(),
after the Type-C switch and mux registrations, closes this window since
their callbacks only need u3_phy and dp_phy from devm_phy_create().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203104915.231202-1-gary.yang@cixtech.com?part=2

      reply	other threads:[~2026-12-03 11:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:49 [PATCH v8 0/2] phy: cix: add Sky1 USB/DP combo PHY support Gary Yang
2026-12-03 10:49 ` [PATCH v8 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY Gary Yang
2026-12-03 11:04   ` sashiko-bot
2026-12-03 10:49 ` [PATCH v8 2/2] phy: cix: add Sky1 USB/DP combo PHY driver Gary Yang
2026-12-03 11:12   ` sashiko-bot [this message]

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=sashiko-outbox-247654@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gary.yang@cixtech.com \
    --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