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 v4 2/2] phy: cix: add Sky1 USB/DP combo PHY driver
Date: Mon, 30 Nov 2026 11:06:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-240909@kernel.org> (raw)
In-Reply-To: <20261130104511.3639267-3-gary.yang@cixtech.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] phy: cix: unbalanced apb_clk enable in udphy_dp_phy_power_off()
- [High] phy: cix: missing USB3 power restore in usbdp_typec_mux_set()
- [High] phy: cix: broken 4-lane DP state tracking in
udphy_dp_phy_power_on()
--
commit ba11e5e2f539f4ea948cc4e505266c0f107df2b2
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..341ae5d62b0b6
> --- /dev/null
> +++ b/drivers/phy/cix/phy-cix-usbdp.c
[ ... ]
> +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);
> + bool usb_attach;
> + 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;
> + }
> +
> + /*
> + * USB operation requested by the connector driver or by the DP
> + * altmode driver when the sink switches from DisplayPort to USB, as
> + * opposed to the safe states signalled around an alternate mode
> + * switch.
> + */
> + usb_attach = state->mode == TYPEC_STATE_USB;
> +
> + 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;
> +
> + if (usb_attach) {
> + ret = udphy_restore_usb(udphy);
> + if (ret)
> + return ret;
> + }
> +
> + return udphy_sync_mode(udphy);
> +}
[Severity: High]
Can gating udphy_restore_usb() on state->mode == TYPEC_STATE_USB leave
the combo PHY powered down when switching out of 4-lane DisplayPort?
If the DP PHY powers off while in 4-lane UDPHY_MODE_DP,
udphy_dp_phy_power_off() powers down the combo PHY and sets
udphy->cur_mode to UDPHY_MODE_NONE while udphy->u3_initialized remains
true. When the connector later reconfigures to 2-lane DP+USB
(TYPEC_DP_STATE_B/D/F) or disconnects via TYPEC_STATE_SAFE, usb_attach
is false, so udphy_restore_usb() is skipped and udphy_sync_mode() does
nothing because udphy->cur_mode is UDPHY_MODE_NONE, leaving the USB3
controller attached to an unpowered PHY.
[ ... ]
> +static int udphy_dp_phy_power_on(struct phy *phy)
> +{
> + struct cix_udphy *udphy = phy_get_drvdata(phy);
> + int ret;
> +
> + guard(mutex)(&udphy->mutex);
> +
> + if (!(udphy->next_mode & UDPHY_MODE_DP))
> + return 0;
> +
> + udphy->dp_lanes = udphy_dplane_get(udphy);
> +
> + ret = cix_usbdp_phy_power_on(udphy);
> + if (ret)
> + return ret;
> +
> + /*
> + * With 4-lane DisplayPort the DP PHY owns the PMA lanes, so the USB3
> + * function cannot be active anymore even if its consumer still holds
> + * phy_init(). Drop the USB bit here so that the combo PHY can really
> + * be powered off once the DP PHY releases the lanes.
> + */
> + if (udphy->next_mode == UDPHY_MODE_DP)
> + udphy->cur_mode &= ~UDPHY_MODE_USB;
> +
> + phy_set_bus_width(phy, udphy->dp_lanes);
> + udphy->cur_mode |= UDPHY_MODE_DP;
> +
> + /*
> + * In the USB+DP modes the USB3 controller keeps using its lanes, so
> + * keep the USB mode accounted for while its consumer is initialized.
> + */
> + if ((udphy->next_mode & UDPHY_MODE_USB) && udphy->u3_initialized)
> + udphy->cur_mode |= UDPHY_MODE_USB;
> +
> + return 0;
> +}
[Severity: High]
What happens when a 4-lane DisplayPort transition races with
udphy_dp_phy_power_on()?
During DP Alt Mode configuration, the DP altmode driver first signals
TYPEC_STATE_SAFE (which usbdp_typec_mux_set() maps to UDPHY_MODE_DP_USB)
and reports HPD before notifying TYPEC_DP_STATE_A/C/E. If
udphy_dp_phy_power_on() runs in that window, it sees udphy->next_mode ==
UDPHY_MODE_DP_USB, programs only 2 DP lanes with the USB+DP register
table, and keeps UDPHY_MODE_USB set in udphy->cur_mode. When
TYPEC_DP_STATE_A/C/E then arrives, udphy_sync_mode() returns early
because UDPHY_MODE_DP is already set in udphy->cur_mode, so 4-lane DP is
never programmed into the hardware, 4-lane phy_configure() calls fail
with -EINVAL in udphy_dp_phy_verify_lanes(), and udphy_dp_phy_power_off()
later sees UDPHY_MODE_USB still set in udphy->cur_mode, reprograms the
PHY to sky1_udphy_dp_conf via udphy_sync_mode(), and skips powering the
PHY off.
Conversely, if TYPEC_DP_STATE_A/C/E arrives while only USB3 is active
(udphy->cur_mode == UDPHY_MODE_USB) before udphy_dp_phy_power_on() runs,
udphy_sync_mode() immediately reprograms the hardware to
sky1_udphy_dp_conf without clearing UDPHY_MODE_USB from udphy->cur_mode,
disconnecting USB3 while leaving the PHY and apb_clk powered on even if
DP never powers on.
> +
> +static int udphy_dp_phy_power_off(struct phy *phy)
> +{
> + struct cix_udphy *udphy = phy_get_drvdata(phy);
> + int ret;
> +
> + guard(mutex)(&udphy->mutex);
> +
> + if (!(udphy->cur_mode & UDPHY_MODE_DP))
> + return 0;
> +
> + udphy->cur_mode &= ~UDPHY_MODE_DP;
> + phy_set_bus_width(phy, 0);
> +
> + if (udphy->cur_mode != UDPHY_MODE_NONE)
> + return udphy_sync_mode(udphy);
> +
> + /*
> + * The connector or the DP altmode driver might have requested USB while
> + * the DP PHY still owned the lanes, so the mux notification could not
> + * power the PHY back up. Do it now instead of powering down a PHY that
> + * the USB3 controller still holds initialized.
> + */
> + ret = udphy_restore_usb(udphy);
> + if (ret)
> + return ret;
> +
> + if (udphy->cur_mode == UDPHY_MODE_NONE)
> + return cix_usbdp_phy_power_off(udphy);
> +
> + return udphy_sync_mode(udphy);
> +}
[Severity: High]
Does clearing UDPHY_MODE_DP before calling udphy_restore_usb() leak a
prepare/enable reference on udphy->apb_clk?
When exiting 4-lane DP after the mux has already switched
udphy->next_mode back to a mode with UDPHY_MODE_USB set, clearing
UDPHY_MODE_DP sets udphy->cur_mode to UDPHY_MODE_NONE while the hardware
and udphy->apb_clk are still enabled. udphy_restore_usb() then calls
cix_usbdp_phy_power_on(), which sees udphy->cur_mode == UDPHY_MODE_NONE
and runs sky1_udphy_init() instead of sky1_udphy_reinit(), calling
clk_prepare_enable(udphy->apb_clk) a second time and setting
UDPHY_MODE_USB so cix_usbdp_phy_power_off() is skipped. If
cix_usbdp_phy_power_on() fails, udphy_dp_phy_power_off() also returns
early with udphy->cur_mode == UDPHY_MODE_NONE while the PHY and clock
remain enabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130104511.3639267-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-11-30 11:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:45 [PATCH v4 0/2] phy: cix: add Sky1 USB/DP combo PHY support Gary Yang
2026-11-30 10:45 ` [PATCH v4 1/2] dt-bindings: phy: add CIX Sky1 USB/DP combo PHY Gary Yang
2026-11-30 10:45 ` [PATCH v4 2/2] phy: cix: add Sky1 USB/DP combo PHY driver Gary Yang
2026-11-30 11:06 ` 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-240909@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