[PATCH] phy: samsung: exynos5250-sata: fix unreliable PLL lock timeout

Marek Szyprowski m.szyprowski at samsung.com
Wed Nov 18 11:12:31 PST 2026


On Arndale boards the SATA PHY occasionally fails to initialize, which
makes the AHCI controller probe fail and the attached disk disappear:

  phy phy-12170000.sata-phy.11: PHY PLL locking failed
  phy phy-12170000.sata-phy.11: phy init failed --> -14
  ahci-dwc 122f0000.sata: probe with driver ahci-dwc failed with error -14

The PLL lock is polled by wait_for_reg_status() with a timeout of
usecs_to_jiffies(1000). On ARM with the default HZ=100 that rounds up to
a single jiffy, so the effective timeout is anything between almost zero
and 10ms, depending on where in the tick period the wait starts. The
loop also does not re-check the status after the deadline has passed,
so an interrupt or preemption during polling can turn an already locked
PLL into a reported failure. Finally, -EFAULT is a misleading error code
for a timeout.

Replace the open-coded loop with readl_poll_timeout(), which measures
time with ktime, performs a final read after the timeout, and returns
-ETIMEDOUT. Use a 10ms timeout, matching the upper bound of the
previous behaviour with HZ=100.

Fixes: bcff4cba41bc ("PHY: Exynos: Add Exynos5250 SATA PHY driver")
Signed-off-by: Marek Szyprowski <m.szyprowski at samsung.com>
---
This patch has been developed with LLM assistance and have been tested
on the real Exynos5250-based Arndale board.

Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland
---
 drivers/phy/samsung/phy-exynos5250-sata.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/phy/samsung/phy-exynos5250-sata.c b/drivers/phy/samsung/phy-exynos5250-sata.c
index a88534eba2be..b55cbb3c47b3 100644
--- a/drivers/phy/samsung/phy-exynos5250-sata.c
+++ b/drivers/phy/samsung/phy-exynos5250-sata.c
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/i2c.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -43,7 +44,8 @@
 #define EXYNOS5_SATA_PHSATA_STATM	0xf0
 #define PHSTATM_PLL_LOCKED		BIT(0)
 
-#define PHY_PLL_TIMEOUT (usecs_to_jiffies(1000))
+#define PHY_PLL_POLL_US		10
+#define PHY_PLL_TIMEOUT_US	10000
 
 struct exynos_sata_phy {
 	struct phy *phy;
@@ -53,19 +55,6 @@ struct exynos_sata_phy {
 	struct i2c_client *client;
 };
 
-static int wait_for_reg_status(void __iomem *base, u32 reg, u32 checkbit,
-				u32 status)
-{
-	unsigned long timeout = jiffies + PHY_PLL_TIMEOUT;
-
-	while (time_before(jiffies, timeout)) {
-		if ((readl(base + reg) & checkbit) == status)
-			return 0;
-	}
-
-	return -EFAULT;
-}
-
 static int exynos_sata_phy_power_on(struct phy *phy)
 {
 	struct exynos_sata_phy *sata_phy = phy_get_drvdata(phy);
@@ -142,9 +131,9 @@ static int exynos_sata_phy_init(struct phy *phy)
 	val |= RESET_CMN_RST_N;
 	writel(val, sata_phy->regs + EXYNOS5_SATA_RESET);
 
-	ret = wait_for_reg_status(sata_phy->regs,
-				EXYNOS5_SATA_PHSATA_STATM,
-				PHSTATM_PLL_LOCKED, 1);
+	ret = readl_poll_timeout(sata_phy->regs + EXYNOS5_SATA_PHSATA_STATM,
+				 val, val & PHSTATM_PLL_LOCKED,
+				 PHY_PLL_POLL_US, PHY_PLL_TIMEOUT_US);
 	if (ret < 0)
 		dev_err(&sata_phy->phy->dev,
 			"PHY PLL locking failed\n");
-- 
2.43.0




More information about the linux-phy mailing list