Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
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 v3 3/5] phy: apple: atc: Add initial M3 series support
Date: Wed, 25 Nov 2026 21:38:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-234190@kernel.org> (raw)
In-Reply-To: <20261125-t8122-phy-v3-3-196e20b3537e@chaosmail.tech>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: apple: atc: stale atcphy->mode on
  atcphy_wait_rcal1_done_t8122() failure
--

commit 5502f6b851712985ca558c7a0dd17a0358624746
Author: Sasha Finkelstein <k@chaosmail.tech>

phy: apple: atc: Add initial M3 series support

This commit adds initial support for the Apple t8122 (M3) Type-C PHY,
covering USB and Thunderbolt modes through a per-SoC hardware operations
structure.

> diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c
> index 45f1280a6faa3..68fc93a88f41a 100644
> --- a/drivers/phy/apple/atc.c
> +++ b/drivers/phy/apple/atc.c
[ ... ]
> @@ -1792,18 +1929,93 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode)
[ ... ]
> +static int atcphy_wait_rcal1_done_t8122(struct apple_atcphy *atcphy, enum atcphy_mode mode)
> +{
> +	int ret = 0;
> +	u32 reg;
> +
> +	if (atcphy_modes[mode].pipehandler_state == ATCPHY_PIPEHANDLER_STATE_USB3) {
> +		ret = readl_poll_timeout(atcphy->regs.core + AUS_COMMON_DIG_RCAL1, reg,
> +					 (reg & AUS_COMMON_DIG_RCAL1_ALL_CODES_DONE), 10, 100000);
> +		if (ret) {
> +			atcphy_power_off(atcphy);
> +			dev_err(atcphy->dev, "Failed to wait for RCAL1 done\n");
> +			return ret;
> +		}
> +	}
> +	return ret;
> +}
> +
> +static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode)
> +{
> +	int ret = 0;
> +
> +	lockdep_assert_held(&atcphy->lock);
> +
> +	if (mode == APPLE_ATCPHY_MODE_OFF) {
> +		ret = atcphy_power_off(atcphy);
> +		atcphy->mode = mode;
> +		return ret;
> +	}
> +
> +	ret = atcphy_power_on(atcphy);
> +	if (ret)
> +		return ret;
> +
> +	atcphy_apply_tunables(atcphy, mode);
> +	atcphy->hw->configure_post_tunable(atcphy, mode);
>  
>  	/* Setup AUX channel if DP altmode is requested */
>  	if (atcphy_modes[mode].enable_dp_aux)
>  		atcphy_enable_dp_aux(atcphy);
>  
>  	/* Enable clocks and configure lanes */
> -	core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_PCLK_EN);
> -	core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_REFCLK_EN);
> +	if (atcphy->hw->enable_cio3pll_clk)
> +		atcphy->hw->enable_cio3pll_clk(atcphy);
> +
>  	atcphy_configure_lanes(atcphy, mode);
>  
>  	/* Take the USB3 PHY out of reset */
>  	core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N);
> +	/*
> +	 * NOTE: Not what macos does, it takes the phy out of reset right before writing to
> +	 * ACIOPHY_CFG0_COMMON_SMALL does lane configuration with phy out of reset, and the poll is
> +	 * right after AUS_COMMON_SHIM_BLK_BIAS_REG write. Does not seem to matter, but if something
> +	 * does not work, consider re-ordering things to macos order.
> +	 */
> +	if (atcphy->hw->wait_rcal1_done) {
> +		ret = atcphy->hw->wait_rcal1_done(atcphy, mode);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	atcphy->mode = mode;

[Severity: Medium]
Does failing in atcphy_wait_rcal1_done_t8122() leave atcphy->mode out of
sync with the hardware state?

When the RCAL1 poll times out, atcphy_wait_rcal1_done_t8122() calls
atcphy_power_off(), and atcphy_configure() returns early without updating
atcphy->mode.  If atcphy->mode was already a non-OFF mode (such as
APPLE_ATCPHY_MODE_USB2) before transitioning to a USB3 mode, atcphy->mode
retains that previous active mode while the PHY hardware is powered off
and held in reset.  A subsequent atcphy_mux_set() back to that previous
mode will then see atcphy->mode == target_mode and return 0 without
powering the PHY back on.  Should atcphy->mode be reset to
APPLE_ATCPHY_MODE_OFF when atcphy_power_off() is called on this error
path?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-t8122-phy-v3-0-196e20b3537e@chaosmail.tech?part=3

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-11-25 21:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 13:11 [PATCH v3 0/5] phy: apple: atc: Add M3 support Sasha Finkelstein
2026-11-25 13:11 ` [PATCH v3 1/5] dt-bindings: phy: atcphy: Add M3 series Sasha Finkelstein
2026-11-25 23:44   ` Janne Grunau
2026-11-25 13:11 ` [PATCH v3 2/5] soc: apple: tunable: Allow passing NULL to tunable_apply Sasha Finkelstein
2026-11-25 13:11 ` [PATCH v3 3/5] phy: apple: atc: Add initial M3 series support Sasha Finkelstein
2026-11-25 21:38   ` sashiko-bot [this message]
2026-11-25 13:11 ` [PATCH v3 4/5] phy: apple: atc: Add T8122 DisplayPort support Sasha Finkelstein
2026-11-25 21:39   ` 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=sashiko-outbox-234190@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=k@chaosmail.tech \
    --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