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 v6 2/2] phy: cix: add Sky1 USB/DP combo PHY driver
Date: Tue, 01 Dec 2026 05:34:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-242610@kernel.org> (raw)
In-Reply-To: <20261201051629.3862739-3-gary.yang@cixtech.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] phy: cix-usbdp: stale DP bus_width in usbdp_typec_mux_set()
when DP is powered
- [Medium] phy: cix-usbdp: deferred reinit in udphy_dp_phy_configure()
corrupts lanes
- [Medium] phy: cix-usbdp: udphy_dp_phy_set_rate() skips HSCLK_DIV when
lanes increase
--
commit aaf1ea0adb7ea7807dcca74ff32ca474d68f46cb
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
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..ddca327694cf5
> --- /dev/null
> +++ b/drivers/phy/cix/phy-cix-usbdp.c
> @@ -1,1665 +1,1665 @@
[ ... ]
> +static int udphy_orien_sw_set(struct typec_switch_dev *sw,
> + enum typec_orientation orien)
> +{
> + struct cix_udphy *udphy = typec_switch_get_drvdata(sw);
> + bool flip;
> +
> + guard(mutex)(&udphy->mutex);
> +
> + if (orien == TYPEC_ORIENTATION_NONE)
> + return 0;
> +
> + flip = (orien == TYPEC_ORIENTATION_REVERSE);
> + if (udphy->flip != flip) {
> + dev_dbg(udphy->dev, "plug orientation changed, re-init required\n");
> + udphy->needs_reinit = true;
> + }
> +
> + udphy->flip = flip;
> +
> + return udphy_sync_mode(udphy);
> +}
[ ... ]
> +static int usbdp_typec_mux_set(struct typec_mux_dev *mux,
> + struct typec_mux_state *state)
> +{
> + struct cix_udphy *udphy = typec_mux_get_drvdata(mux);
> + u8 mode;
> + int ret;
> +
> + /* Ignore mux events not involving USB or DisplayPort */
> + if (!usbdp_typec_is_supported_mode(state)) {
> + dev_dbg(udphy->dev, "ignore mux event with mode=%lu\n",
> + state->mode);
> + return 0;
> + }
> +
> + if (state->mode < TYPEC_STATE_MODAL) {
> + /*
> + * The DP altmode driver signals the safe and USB states
> + * around a mode switch. The USB and the USB+DP modes share
> + * one register table, so keep the DP lanes available for
> + * those notifications.
> + */
> + if (state->alt && state->alt->svid == USB_TYPEC_DP_SID)
> + mode = UDPHY_MODE_DP_USB;
> + else
> + mode = UDPHY_MODE_USB;
> + } else {
> + switch (state->mode) {
> + case TYPEC_DP_STATE_A:
> + case TYPEC_DP_STATE_C:
> + case TYPEC_DP_STATE_E:
> + mode = UDPHY_MODE_DP;
> + break;
> + case TYPEC_DP_STATE_B:
> + case TYPEC_DP_STATE_D:
> + case TYPEC_DP_STATE_F:
> + mode = UDPHY_MODE_DP_USB;
> + break;
> + default:
> + return 0;
> + }
> + }
> +
> + guard(mutex)(&udphy->mutex);
> +
> + if (udphy->next_mode != mode) {
> + dev_dbg(udphy->dev, "new mode: %u\n", mode);
> +
> + /*
> + * The USB and the USB+DP modes share one register table, only
> + * the DP-only mode needs a different one.
> + */
> + if (mode == UDPHY_MODE_DP || udphy->next_mode == UDPHY_MODE_DP)
> + udphy->needs_reinit = true;
> + }
> +
> + udphy->next_mode = mode;
> +
> + /*
> + * The DP controller may have powered the PHY on before the mux
> + * notification selecting the DisplayPort mode arrived. Complete that
> + * power-on now that the lanes are available. The PHY core already
> + * holds the power reference, so keep dp_powered set when this fails
> + * and retry on the next notification.
> + */
> + if (udphy->dp_powered && (udphy->next_mode & UDPHY_MODE_DP) &&
> + !(udphy->cur_mode & UDPHY_MODE_DP)) {
> + ret = udphy_dp_phy_power_on_locked(udphy);
> + if (ret)
> + return ret;
> + }
[Severity: Medium]
Should usbdp_typec_mux_set() also update phy_set_bus_width(udphy->dp_phy,
udphy_dplane_get(udphy)) when UDPHY_MODE_DP is already set in
udphy->cur_mode?
When the mux switches between 2-lane (UDPHY_MODE_DP_USB) and 4-lane
(UDPHY_MODE_DP) DisplayPort modes while the DP PHY is already powered on,
udphy->dp_phy->attrs.bus_width stays at the old lane count until
udphy_dp_phy_configure() runs with set_rate set. DisplayPort controllers
query phy_get_bus_width() before calling phy_configure() to determine the
maximum lane count. On a 2-lane (or TYPEC_STATE_SAFE) to 4-lane switch,
the controller reads a bus_width of 2 and caps link training to 2 lanes;
on a 4-lane to 2-lane switch, it passes dp->lanes = 4 to phy_configure(),
which udphy_dp_phy_verify_lanes() rejects with -EINVAL before the
deferred reinit in udphy_dp_phy_configure() is reached.
[ ... ]
> +static int udphy_dp_phy_set_rate(struct cix_udphy *udphy,
> + struct phy_configure_opts_dp *dp)
> +{
> + const struct phy_link_cfg *conf;
> + u32 i;
> +
> + switch (dp->link_rate) {
> + case 1620:
> + conf = &link_cfg[0];
> + break;
> + case 2700:
> + conf = &link_cfg[1];
> + break;
> + case 5400:
> + conf = &link_cfg[2];
> + break;
> + case 8100:
> + conf = &link_cfg[3];
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + dev_dbg(udphy->dev, "lane %u, rate %u\n", udphy->dp_lanes,
> + dp->link_rate);
> +
> + udphy_update_bits(udphy, PHY_PMA_PLL_CTRL, BIT(1), 0x0);
> + usleep_range(10, 20);
> +
> + udphy_write_table(udphy, conf->seq, conf->num_seq);
> +
> + for (i = 0; i < udphy->dp_lanes; 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);
> + }
[Severity: Medium]
Can this loop leave XCVR_DIAG_HSCLK_DIV unprogrammed on newly enabled
lanes if a consumer configures the link rate and lane count in separate
phy_configure() calls?
If an earlier link training run reduced udphy->dp_lanes (for example to 1
or 2 lanes) and a later run calls phy_configure() with set_rate first and
a second phy_configure() with set_lanes to increase the lane count,
udphy_dp_phy_set_rate() only updates XCVR_DIAG_HSCLK_DIV for the old
udphy->dp_lanes count, and the set_lanes call only updates
udphy->dp_lanes in software. Programming XCVR_DIAG_HSCLK_DIV across
udphy_dplane_get(udphy) lanes would keep all DP-assigned lanes at the new
rate's divider.
[ ... ]
> +static int udphy_dp_phy_configure(struct phy *phy,
> + union phy_configure_opts *opts)
> +{
> + struct cix_udphy *udphy = phy_get_drvdata(phy);
> + struct phy_configure_opts_dp *dp = &opts->dp;
> + int ret;
[ ... ]
> + if (dp->set_rate && udphy->needs_reinit) {
> + ret = udphy->cfg->udphy_reinit(udphy);
> + if (ret) {
> + dev_err(udphy->dev, "failed to reconfigure udphy\n");
> + return ret;
> + }
> +
> + udphy->needs_reinit = false;
> +
> + /*
> + * The mux may have taken lanes away from or given lanes back
> + * to USB3. The DP controller does not necessarily report the
> + * new lane count on the rate-setting call, so derive it from
> + * the mode, and keep the bus width and the USB3 mode bit in
> + * sync as udphy_dp_phy_power_on() does.
> + */
> + if (!dp->set_lanes)
> + udphy->dp_lanes = udphy_dplane_get(udphy);
> +
> + phy_set_bus_width(phy, udphy_dplane_get(udphy));
> +
> + if (udphy->next_mode == UDPHY_MODE_DP)
> + udphy->cur_mode &= ~UDPHY_MODE_USB;
> + else if (udphy->u3_initialized)
> + udphy->cur_mode |= UDPHY_MODE_USB;
> + }
> +
> + /* All of the options are valid, so they can be applied now. */
> + if (dp->set_lanes)
> + udphy->dp_lanes = dp->lanes;
[Severity: Medium]
Can deferring udphy_reinit() until dp->set_rate cause
udphy_dp_phy_set_voltages() to program the USB3 PMA lanes when
udphy->flip changes?
udphy_orien_sw_set() updates udphy->flip immediately while setting
udphy->needs_reinit = true if DisplayPort is active. If a consumer calls
phy_configure() with set_voltages = true and set_rate = false while
needs_reinit is pending, udphy_reinit() is skipped so the hardware keeps
the old orientation, but udphy_dp_phy_set_voltages() maps lanes with
udphy_dp_lane_to_pma() using the new udphy->flip and writes DP TX swing
registers onto the PMA lanes routed to USB3.
In addition, if a consumer configures a reduced lane count (such as 1 or
2 lanes) in a separate phy_configure() call with set_lanes = true before
calling phy_configure() with set_rate = true while needs_reinit is set,
the !dp->set_lanes assignment overwrites the configured udphy->dp_lanes
with udphy_dplane_get(udphy).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201051629.3862739-1-gary.yang@cixtech.com?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
prev parent reply other threads:[~2026-12-01 5:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 5:16 [PATCH v6 0/2] phy: cix: add Sky1 USB/DP combo PHY support Gary Yang
2026-12-01 5:16 ` [PATCH v6 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY Gary Yang
2026-12-01 5:16 ` [PATCH v6 2/2] phy: cix: add Sky1 USB/DP combo PHY driver Gary Yang
2026-12-01 5:34 ` 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-242610@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