mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: atomisp: csi2-bridge: Don't cycle the PMC clock if its rate is correct
@ 2026-11-16 17:33 Volodymyr Chapman
  2026-11-17 10:02 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Volodymyr Chapman @ 2026-11-16 17:33 UTC (permalink / raw)
  To: Hans de Goede, Mauro Carvalho Chehab
  Cc: Sakari Ailus, Andy Shevchenko, Greg Kroah-Hartman, linux-media,
	linux-staging, linux-kernel, Volodymyr Chapman

atomisp_csi2_set_pmc_clk_freq() enables and disables the sensor's PMC
platform clock to be able to change its rate to 19.2 MHz. ACPI however
also controls this clock, through the CLKx power resource in the sensor's
_PR0, and caches the state of that power resource. When ACPI has already
turned the clock on, the clk_disable_unprepare() turns it off underneath
ACPI. ACPI keeps considering the clock to be on, so a following power-on
of the sensor does not run the clock's _ON method and the sensor does
not respond on I2C.

On a Lenovo ThinkPad 10 (20C3) with an IMX175 rear sensor this makes the
sensor's probe fail intermittently, depending on probe ordering:

  atomisp-isp2 0000:00:03.0: Found supported sensor INTCF1A:00
  imx175 i2c-INTCF1A:00: Error reading reg 0x0000: -121
  imx175 i2c-INTCF1A:00: probe with driver imx175 failed with error -121

The effect of the clock cycle was also reproduced directly: with the
sensor powered through ACPI, a single clk_prepare_enable() +
clk_disable_unprepare() of pmc_plt_clk_0 makes it stop responding.

Only cycle the clock to change its rate when it does not already run at
19.2 MHz. The DSDT's CLKx._ON methods on this machine already select the
19.2 MHz PLL.

As a side effect, a clock which the firmware left enabled at 19.2 MHz is
no longer turned off by atomisp_csi2_set_pmc_clk_freq(). It is turned off
when ACPI powers down the sensor, e.g. when the sensor driver
runtime-suspends it.

Tested on a Lenovo ThinkPad 10 (20C3, Atom Z3795, BIOS GWET50WW 1.50),
with this file built out of tree against a 7.2.15 kernel: without this
change the IMX175 probe failed on 2 out of 10 boots, with it on 0 out of
10 boots. The probe failure and the direct reproduction above match;
the boot counts on their own are too small to be conclusive. This change
was also part of a media.git next kernel (7.4.0-rc1) built with the
pending IMX175 driver, on which the IMX175 probed on both boots tested.

The problem was investigated and this patch drafted with the help of an
AI coding assistant (Claude); the testing was done on the hardware by the
submitter.

Fixes: 0af9078315c1 ("media: atomisp: csi2-bridge: Set PMC clk-rate for sensors to 19.2 MHz")
Signed-off-by: Volodymyr Chapman <volodymyrchapman@gmail.com>
---
 .../staging/media/atomisp/pci/atomisp_csi2_bridge.c   | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index cca91c6d7..a49996e26 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -257,6 +257,17 @@ static int atomisp_csi2_set_pmc_clk_freq(struct acpi_device *adev, int clock_num
 		return ret;
 	}
 
+	/*
+	 * ACPI turns this clock on and off through the sensor's _PR0 power
+	 * resources, without the clk framework knowing. Cycling the clock
+	 * below turns it off underneath ACPI, which keeps considering it on,
+	 * so only do so when the rate must change.
+	 */
+	if (clk_get_rate(clk) == PMC_CLK_RATE_19_2MHZ) {
+		clk_put(clk);
+		return 0;
+	}
+
 	/*
 	 * The firmware might enable the clock at boot, to change
 	 * the rate we must ensure the clock is disabled.

base-commit: 3fc9303dba01676c2090768126e5327e341b7761
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-17 10:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 17:33 [PATCH] media: atomisp: csi2-bridge: Don't cycle the PMC clock if its rate is correct Volodymyr Chapman
2026-11-17 10:02 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®