linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/48] media: Add a helper for obtaining the clock producer
@ 2025-06-26 13:33 Mehdi Djait
  2025-06-26 13:33 ` [PATCH v2 01/48] media: v4l2-common: " Mehdi Djait
                   ` (47 more replies)
  0 siblings, 48 replies; 72+ messages in thread
From: Mehdi Djait @ 2025-06-26 13:33 UTC (permalink / raw)
  To: laurent.pinchart, sakari.ailus
  Cc: stanislaw.gruszka, hdegoede, arnd, alain.volmat, andrzej.hajda,
	benjamin.mugnier, dave.stevenson, hansg, hverkuil, jacopo.mondi,
	kieran.bingham, khalasa, mani, m.felsch, matthias.fend, mchehab,
	mehdi.djait, michael.riesch, naush, nicholas, nicolas.dufresne,
	paul.elder, dan.scally, pavel, rashanmu, ribalda, slongerbeam,
	tomi.valkeinen, umang.jain, linux-media

Hello everyone,

Here is my v2 for the new helper v4l2_devm_sensor_clk_get()

I took this opportunity to make all the drivers that I touched with this
series return dev_err_probe() when the helper fails: the complete list
is below in the HISTORY. I noticed some odd drivers:

drivers/media/i2c/s5k5baf.c -> always returns -EPROBE_DEFER if getting the clock fails

drivers/media/i2c/mt9t112.c -> this drivers seems to be implementing
	the behaviour of devm_clk_get_optional() while using devm_clk_get():
	remove it from the list of changed drivers ?


drivers/media/i2c/ov8856.c -> getting the clock, setting the rate,
getting the optional gpio and the regulator_bulk is only when the fwnode
is NOT acpi.

Any testing of the patches is GREATLY APPRECIATED!

Especially the two drivers with the special ACPI case:
1) OV8865
2) OV2680


Background
----------

A reference to the clock producer is not available to the kernel
in ACPI-based platforms but the sensor drivers still need them.

devm_clk_get() will return an error and the probe function will fail.


Solution
--------

Introduce a generic helper for v4l2 sensor drivers on both DT- and ACPI-based
platforms.

This helper behaves the same as clk_get_optional() except where there is
no clock producer like in ACPI-based platforms.

For ACPI-based platforms the function will read the "clock-frequency"
ACPI _DSD property and register a fixed frequency clock with the frequency
indicated in the property.


Solution for special ACPI case
------------------------------

This function also handles the special ACPI-based system case where:

1) The clock-frequency _DSD property is present.
2) A reference to the clock producer is present, where the clock is provided
by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

In this case try to set the clock-frequency value to the provided clock.

History
-------

v1 -> v2:
- Added a check to !of_node instead of acpi_node as !of_node will cover
both acpi nodes and software nodes (currently used by AMD camera setup)

Changed the following drivers to use dev_err_probe() when the helper
fails:
	s5k6a3.c
	s5c73m3/s5c73m3-core.c

	mt9m001.c
	mt9m111.c
	mt9p031.c
	mt9m114.c
	mt9v032.c
	mt9v111.c

	ov2659.c
	ov2685.c
	ov5640.c
	ov5647.c
	ov5648.c
	ov5695.c
	ov6650.c
	ov7740.c
	ov9282.c
	ov9640.c
	ov9650.c

	imx412.c
	imx335.c

	hi846.c
	et8ek8/et8ek8_driver.c
	ar0521.c

Suggested by Laurent:
	- changed clk_get_optional() to devm_clk_get() in the commit msg
	  and kernel-doc of the helper function
	- improved the kernel-doc of the function
	- added forward declaration of struct clk in include/media/v4l2-common.h
	- changed the Documentation in the [PATCH 02/48]
	- dropped the comment in ov2680.c
	- removed the following drivers that are not camera sensors:
		ds90ub913: Video Serializer
		ds90ub960: Video Deserializer
		st-mipid02: CSI-2 to PARALLEL bridge
		tc358743: HDMI to CSI-2 bridge
		tc358746: PARALLEL to CSI-2 bridge
		thp7312: External Camera ISP

Suggested by Sakari:
	- added the handling for when devm_clk_get_optional() returns
	  -EPROBE_DEFER
	- added handling for when devm_clk_get_optional() returns
	  -EINVAL. The helper will return -EPROBE_DEFER signaling that
	  some software components are still needed before the sensor
	  driver can get probed (e.g. int3472 or the AMD ISP)

Suggested by Michael Riesch:
	- made the imx415 clock name NULL

Link v1: https://lore.kernel.org/linux-media/cover.1750352394.git.mehdi.djait@linux.intel.com/

RFC History
-----------

RFC v4 -> RFC v5:
Suggested by Arnd Bergmann:
	- removed IS_REACHABLE(CONFIG_COMMON_CLK). IS_REACHABLE() is actually
	discouraged [1]. COFIG_COMMON_CLK is a bool, so IS_ENABLED() will be the
	right solution here
Suggested by Hans de Goede:
	- added handling for the special ACPI-based system case, where
	  both a reference to the clock-provider and the _DSD
	  clock-frequency are present.
	- updated the function's kernel-doc and the commit msg
	  to mention this special case.
Link RFC v4: https://lore.kernel.org/linux-media/20250321130329.342236-1-mehdi.djait@linux.intel.com/
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/Documentation/kbuild/kconfig-language.rst?h=next-20250513&id=700bd25bd4f47a0f4e02e0a25dde05f1a6b16eea

RFC v3 -> RFC v4:
Suggested by Laurent:
	- removed the #ifdef to use IS_REACHABLE(CONFIG_COMMON_CLK)
	- changed to kasprintf() to allocate the clk name when id is NULL and
	  used the __free(kfree) scope-based cleanup helper when
	  defining the variable to hold the allocated name
Link v3: https://lore.kernel.org/linux-media/20250321093814.18159-1-mehdi.djait@linux.intel.com/

RFC v2 -> RFC v3:
- Added #ifdef CONFIG_COMMON_CLK for the ACPI case
Link v2: https://lore.kernel.org/linux-media/20250310122305.209534-1-mehdi.djait@linux.intel.com/

RFC v1 -> RFC v2:
Suggested by Sakari:
    - removed clk_name
    - removed the IS_ERR() check
    - improved the kernel-doc comment and commit msg
Link v1: https://lore.kernel.org/linux-media/20250227092643.113939-1-mehdi.djait@linux.intel.com

Mehdi Djait (48):
  media: v4l2-common: Add a helper for obtaining the clock producer
  Documentation: media: camera-sensor: Mention
    v4l2_devm_sensor_clk_get() for obtaining the clock
  media: i2c: ar0521: Use the v4l2 helper for obtaining the clock
  media: i2c: et8ek8: Use the v4l2 helper for obtaining the clock
  media: i2c: gc05a2: Use the v4l2 helper for obtaining the clock
  media: i2c: gc08a3: Use the v4l2 helper for obtaining the clock
  media: i2c: gc2145: Use the v4l2 helper for obtaining the clock
  media: i2c: hi846: Use the v4l2 helper for obtaining the clock
  media: i2c: imx214: Use the v4l2 helper for obtaining the clock
  media: i2c: imx219: Use the v4l2 helper for obtaining the clock
  media: i2c: imx283: Use the v4l2 helper for obtaining the clock
  media: i2c: imx290: Use the v4l2 helper for obtaining the clock
  media: i2c: imx296: Use the v4l2 helper for obtaining the clock
  media: i2c: imx334: Use the v4l2 helper for obtaining the clock
  media: i2c: imx335: Use the v4l2 helper for obtaining the clock
  media: i2c: imx412: Use the v4l2 helper for obtaining the clock
  media: i2c: imx415: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9m001: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9m111: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9m114: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9p031: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9t112: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9v032: Use the v4l2 helper for obtaining the clock
  media: i2c: mt9v111: Use the v4l2 helper for obtaining the clock
  media: i2c: ov02a10: Use the v4l2 helper for obtaining the clock
  media: i2c: ov2659: Use the v4l2 helper for obtaining the clock
  media: i2c: ov2685: Use the v4l2 helper for obtaining the clock
  media: i2c: ov5640: Use the v4l2 helper for obtaining the clock
  media: i2c: ov5645: Use the v4l2 helper for obtaining the clock
  media: i2c: ov5647: Use the v4l2 helper for obtaining the clock
  media: i2c: ov5648: Use the v4l2 helper for obtaining the clock
  media: i2c: ov5695: Use the v4l2 helper for obtaining the clock
  media: i2c: ov64a40: Use the v4l2 helper for obtaining the clock
  media: i2c: ov6650: Use the v4l2 helper for obtaining the clock
  media: i2c: ov7740: Use the v4l2 helper for obtaining the clock
  media: i2c: ov8856: Use the v4l2 helper for obtaining the clock
  media: i2c: ov8858: Use the v4l2 helper for obtaining the clock
  media: i2c: ov8865: Use the v4l2 helper for obtaining the clock
  media: i2c: ov9282: Use the v4l2 helper for obtaining the clock
  media: i2c: ov9640: Use the v4l2 helper for obtaining the clock
  media: i2c: ov9650: Use the v4l2 helper for obtaining the clock
  media: i2c: s5c73m3: Use the v4l2 helper for obtaining the clock
  media: i2c: s5k5baf: Use the v4l2 helper for obtaining the clock
  media: i2c: s5k6a3: Use the v4l2 helper for obtaining the clock
  media: i2c: vd55g1: Use the v4l2 helper for obtaining the clock
  media: i2c: vd56g3: Use the v4l2 helper for obtaining the clock
  media: i2c: vgxy61: Use the v4l2 helper for obtaining the clock
  media: i2c: ov2680: Use the v4l2 helper for obtaining the clock

 .../driver-api/media/camera-sensor.rst        | 24 ++++++---
 drivers/media/i2c/ar0521.c                    |  9 ++--
 drivers/media/i2c/et8ek8/et8ek8_driver.c      |  9 ++--
 drivers/media/i2c/gc05a2.c                    |  2 +-
 drivers/media/i2c/gc08a3.c                    |  2 +-
 drivers/media/i2c/gc2145.c                    |  2 +-
 drivers/media/i2c/hi846.c                     | 11 ++--
 drivers/media/i2c/imx214.c                    |  2 +-
 drivers/media/i2c/imx219.c                    |  2 +-
 drivers/media/i2c/imx283.c                    |  5 +-
 drivers/media/i2c/imx290.c                    |  2 +-
 drivers/media/i2c/imx296.c                    |  2 +-
 drivers/media/i2c/imx334.c                    |  2 +-
 drivers/media/i2c/imx335.c                    |  9 ++--
 drivers/media/i2c/imx412.c                    |  9 ++--
 drivers/media/i2c/imx415.c                    |  2 +-
 drivers/media/i2c/mt9m001.c                   |  5 +-
 drivers/media/i2c/mt9m111.c                   |  5 +-
 drivers/media/i2c/mt9m114.c                   |  6 +--
 drivers/media/i2c/mt9p031.c                   |  5 +-
 drivers/media/i2c/mt9t112.c                   | 11 ++--
 drivers/media/i2c/mt9v032.c                   |  5 +-
 drivers/media/i2c/mt9v111.c                   |  5 +-
 drivers/media/i2c/ov02a10.c                   |  2 +-
 drivers/media/i2c/ov2659.c                    |  5 +-
 drivers/media/i2c/ov2680.c                    | 29 +----------
 drivers/media/i2c/ov2685.c                    | 10 ++--
 drivers/media/i2c/ov5640.c                    |  9 ++--
 drivers/media/i2c/ov5645.c                    |  2 +-
 drivers/media/i2c/ov5647.c                    |  9 ++--
 drivers/media/i2c/ov5648.c                    |  6 +--
 drivers/media/i2c/ov5695.c                    | 10 ++--
 drivers/media/i2c/ov64a40.c                   |  2 +-
 drivers/media/i2c/ov6650.c                    | 10 ++--
 drivers/media/i2c/ov7740.c                    | 11 ++--
 drivers/media/i2c/ov8856.c                    | 10 ++--
 drivers/media/i2c/ov8858.c                    |  2 +-
 drivers/media/i2c/ov8865.c                    | 36 ++-----------
 drivers/media/i2c/ov9282.c                    |  9 ++--
 drivers/media/i2c/ov9640.c                    |  5 +-
 drivers/media/i2c/ov9650.c                    |  5 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c      |  6 ++-
 drivers/media/i2c/s5k5baf.c                   |  2 +-
 drivers/media/i2c/s5k6a3.c                    |  5 +-
 drivers/media/i2c/vd55g1.c                    |  2 +-
 drivers/media/i2c/vd56g3.c                    |  2 +-
 drivers/media/i2c/vgxy61.c                    | 10 ++--
 drivers/media/v4l2-core/v4l2-common.c         | 52 +++++++++++++++++++
 include/media/v4l2-common.h                   | 27 ++++++++++
 49 files changed, 223 insertions(+), 191 deletions(-)

-- 
2.49.0


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

end of thread, other threads:[~2025-08-15  8:54 UTC | newest]

Thread overview: 72+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26 13:33 [PATCH v2 00/48] media: Add a helper for obtaining the clock producer Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 01/48] media: v4l2-common: " Mehdi Djait
2025-06-27  7:12   ` Sakari Ailus
2025-07-01  9:51     ` Mehdi Djait
2025-07-01 10:03       ` Sakari Ailus
2025-07-01 10:47         ` Jacopo Mondi
2025-07-01 11:17           ` Laurent Pinchart
2025-07-01 11:46             ` Mehdi Djait
2025-07-06  0:30   ` Laurent Pinchart
2025-07-07 14:30     ` Mehdi Djait
2025-07-07 14:32       ` [PATCH v3] " Mehdi Djait
2025-07-07 21:55         ` Sakari Ailus
2025-08-13 10:15   ` [PATCH v2 01/48] " Hans Verkuil
2025-08-13 12:59     ` Sakari Ailus
2025-08-13 13:08       ` Laurent Pinchart
2025-08-13 13:22         ` Sakari Ailus
2025-08-13 13:23         ` Hans Verkuil
2025-08-13 14:49           ` Sakari Ailus
2025-08-13 15:14             ` Hans Verkuil
2025-08-13 19:45               ` Sakari Ailus
2025-08-14 13:50               ` [PATCH 1/1] media: v4l2-common: Improve devm_v4l2_sensor_clk_get() documentation Sakari Ailus
2025-08-15  6:00                 ` Mehdi Djait
2025-08-15  8:53                   ` Sakari Ailus
2025-06-26 13:33 ` [PATCH v2 02/48] Documentation: media: camera-sensor: Mention v4l2_devm_sensor_clk_get() for obtaining the clock Mehdi Djait
2025-07-01 11:03   ` Laurent Pinchart
2025-06-26 13:33 ` [PATCH v2 03/48] media: i2c: ar0521: Use the v4l2 helper " Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 04/48] media: i2c: et8ek8: " Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 05/48] media: i2c: gc05a2: " Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 06/48] media: i2c: gc08a3: " Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 07/48] media: i2c: gc2145: " Mehdi Djait
2025-06-26 13:33 ` [PATCH v2 08/48] media: i2c: hi846: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 09/48] media: i2c: imx214: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 10/48] media: i2c: imx219: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 11/48] media: i2c: imx283: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 12/48] media: i2c: imx290: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 13/48] media: i2c: imx296: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 14/48] media: i2c: imx334: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 15/48] media: i2c: imx335: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 16/48] media: i2c: imx412: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 17/48] media: i2c: imx415: " Mehdi Djait
2025-06-26 13:41   ` Michael Riesch
2025-06-26 13:34 ` [PATCH v2 18/48] media: i2c: mt9m001: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 19/48] media: i2c: mt9m111: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 20/48] media: i2c: mt9m114: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 21/48] media: i2c: mt9p031: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 22/48] media: i2c: mt9t112: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 23/48] media: i2c: mt9v032: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 24/48] media: i2c: mt9v111: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 25/48] media: i2c: ov02a10: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 26/48] media: i2c: ov2659: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 27/48] media: i2c: ov2685: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 28/48] media: i2c: ov5640: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 29/48] media: i2c: ov5645: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 30/48] media: i2c: ov5647: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 31/48] media: i2c: ov5648: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 32/48] media: i2c: ov5695: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 33/48] media: i2c: ov64a40: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 34/48] media: i2c: ov6650: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 35/48] media: i2c: ov7740: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 36/48] media: i2c: ov8856: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 37/48] media: i2c: ov8858: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 38/48] media: i2c: ov8865: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 39/48] media: i2c: ov9282: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 40/48] media: i2c: ov9640: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 41/48] media: i2c: ov9650: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 42/48] media: i2c: s5c73m3: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 43/48] media: i2c: s5k5baf: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 44/48] media: i2c: s5k6a3: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 45/48] media: i2c: vd55g1: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 46/48] media: i2c: vd56g3: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 47/48] media: i2c: vgxy61: " Mehdi Djait
2025-06-26 13:34 ` [PATCH v2 48/48] media: i2c: ov2680: " Mehdi Djait

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).