From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796036774; b=Mje9NchM4FRpXbCvS1KQlZ2neRTZFxpL5qSJcP4zwaLiYloQqAcD1Mx9QAtd/+ykwKKB gtX5v6eI87s2qvsz577oSVPwRQ1SMThafGVaN8iKmsdQ0oBYe8kkB0Qu06HvGJPKGAeWj ttWp6TQQXmiRW4w62QBE1QJawnEeGdraclLgIQXLSe8bpYi6gctVH4fVh5suoYG/0vy4k vqXkkq+vbzo1KXscyQcGUUfRLJcZ0jEDEzfQX+b8b+hC5TtpGxYhOSMIxRIBEQLa58zjf 7BRmiH8NzuXQd8glh412zbf2lYur9BtUGPqVn9/Mc7epRql8yMWrs33RtC50Vn306dQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036774; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=oddVX59XOuOpVCPLBJ+TPlx7hwzHrVlMmHd5uRKPmUY=; b=tvJcYQSXXTq64bApy037YL+jUsDkCF+/Kh9CfmCdLILASnxGGzoIyHEs1dF5B41e2eWN off787zpuqaqtiH7ejPGXLigf1YI2ro1tOEWixDKBkjNE4Ks36QT7XocSc1efY1ZSBQpW nT5Gc5dQly25f3aGROVCY2vdclNM1AMq3p4YB6Vr3cmBMBfumcMDxUy6cQnvG8XFWnZA8 /xSvJ0esst2dtXP1vpwvt+fxc4hhHEJ5V4h8kLbNcXjOMyqn0EO9Qk9fPlKFh2UalXLov FllAxSn5IVqY0Z/MeLsYCceUyY+rSu00fCWfzOosGFj+/yDf6NL5VwEeMsj57h575ng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ATCPDtkZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24F6A606A31C for ; Mon, 30 Nov 2026 11:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ATCPDtkZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CDDC1F00897; Mon, 30 Nov 2026 11:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796036773; bh=oddVX59XOuOpVCPLBJ+TPlx7hwzHrVlMmHd5uRKPmUY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ATCPDtkZsDF7D1pTKWb+pm7/MEC7oIPOxD5rY4Nu0i6rW/4e7ibmJuTvkkKOdOXij 1bI/QAzqEC2ZIldFBkLlm2P1PHqQcQQoLs5ETb1jD/Mm1oLbztNmk6pgrOA4N1KowH hJCewBTxJxCZmO9f6P0hY8HMNXqftY6B2DGDX52ckoqKWNxBzDHVi3vJce15C+Td/r w7gXi7QUFa9h3Ho4W0ctGSgqh/32VEsdeXDM4KeYXLRMReTBEh5ChOZKuRfm22cRpy 3MmrjkbwTH6fFjAnnJuMzoY3lfqamJyxF6r2oHHeNbtjw6zWIZjRNB5WEHWw8qO1wx qb1xzAGSdezxQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/2] phy: cix: add Sky1 USB/DP combo PHY driver Reply-To: sashiko-reviews@lists.linux.dev To: "Gary Yang" 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 In-Reply-To: <20261130104511.3639267-3-gary.yang@cixtech.com> References: <20261130104511.3639267-1-gary.yang@cixtech.com> <20261130104511.3639267-3-gary.yang@cixtech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 11:06:12 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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-us= bdp.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 =3D 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=3D%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 =3D state->mode =3D=3D 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 =3D=3D USB_TYPEC_DP_SID) > + mode =3D UDPHY_MODE_DP_USB; > + else > + mode =3D UDPHY_MODE_USB; > + } else { > + switch (state->mode) { > + case TYPEC_DP_STATE_A: > + case TYPEC_DP_STATE_C: > + case TYPEC_DP_STATE_E: > + mode =3D UDPHY_MODE_DP; > + break; > + case TYPEC_DP_STATE_B: > + case TYPEC_DP_STATE_D: > + case TYPEC_DP_STATE_F: > + mode =3D UDPHY_MODE_DP_USB; > + break; > + default: > + return 0; > + } > + } > + > + guard(mutex)(&udphy->mutex); > + > + if (udphy->next_mode !=3D 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 =3D=3D UDPHY_MODE_DP || udphy->next_mode =3D=3D UDPHY_MODE_DP) > + udphy->needs_reinit =3D true; > + } > + > + udphy->next_mode =3D mode; > + > + if (usb_attach) { > + ret =3D udphy_restore_usb(udphy); > + if (ret) > + return ret; > + } > + > + return udphy_sync_mode(udphy); > +} [Severity: High] Can gating udphy_restore_usb() on state->mode =3D=3D 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 =3D phy_get_drvdata(phy); > + int ret; > + > + guard(mutex)(&udphy->mutex); > + > + if (!(udphy->next_mode & UDPHY_MODE_DP)) > + return 0; > + > + udphy->dp_lanes =3D udphy_dplane_get(udphy); > + > + ret =3D 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 =3D=3D UDPHY_MODE_DP) > + udphy->cur_mode &=3D ~UDPHY_MODE_USB; > + > + phy_set_bus_width(phy, udphy->dp_lanes); > + udphy->cur_mode |=3D 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 |=3D 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 =3D=3D 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 =3D=3D 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 =3D phy_get_drvdata(phy); > + int ret; > + > + guard(mutex)(&udphy->mutex); > + > + if (!(udphy->cur_mode & UDPHY_MODE_DP)) > + return 0; > + > + udphy->cur_mode &=3D ~UDPHY_MODE_DP; > + phy_set_bus_width(phy, 0); > + > + if (udphy->cur_mode !=3D 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 =3D udphy_restore_usb(udphy); > + if (ret) > + return ret; > + > + if (udphy->cur_mode =3D=3D 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 =3D=3D 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 =3D=3D UDPHY_MODE_NONE while the PHY and clock remain enabled. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130104511.3639= 267-1-gary.yang@cixtech.com?part=3D2