Skip to contentSkip to conversation

media: Add a helper for obtaining the clock producer

PATCH In review Mehdi Djait 7 participants 72 messages Jun 26, 2025 – Aug 15, 2025

Subsystems (41)
lore
Share & tools
lore
#0 lore raw

v2 cover media: Add a helper for obtaining the clock producer

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/[email protected]/

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/[email protected]/
[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/[email protected]/

RFC v2 -> RFC v3:
- Added #ifdef CONFIG_COMMON_CLK for the ACPI case
Link v2: https://lore.kernel.org/linux-media/[email protected]/

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/[email protected]

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(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH v2 1/48 media: v4l2-common: Add a helper for obtaining the clock producer

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +52 -0
index bd160a8c9efe..ac98895b0394 100644
@@ -34,6 +34,9 @@
  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -673,3 +676,52 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_link_freq_to_bitmap);
+
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
+{
+	const char *clk_id __free(kfree) = NULL;
+	struct clk_hw *clk_hw;
+	struct clk *clk;
+	bool of_node;
+	u32 rate;
+	int ret;
+
+	clk = devm_clk_get_optional(dev, id);
+	ret = device_property_read_u32(dev, "clock-frequency", &rate);
+	of_node = is_of_node(dev_fwnode(dev));
+
+	if (clk) {
+		if (!ret && !of_node) {
+			ret = clk_set_rate(clk, rate);
+			if (ret) {
+				dev_err(dev, "Failed to set clock rate: %u\n",
+					rate);
+				return ERR_PTR(ret);
+			}
+		}
+		return clk;
+	}
+
+	if (PTR_ERR(clk) == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	if (!IS_ENABLED(CONFIG_COMMON_CLK) || of_node)
+		return ERR_PTR(-ENOENT);
+
+	if (ret)
+		return ERR_PTR(ret == -EINVAL ? -EPROBE_DEFER : ret);
+
+	if (!id) {
+		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
+		if (!clk_id)
+			return ERR_PTR(-ENOMEM);
+		id = clk_id;
+	}
+
+	clk_hw = devm_clk_hw_register_fixed_rate(dev, id, NULL, 0, rate);
+	if (IS_ERR(clk_hw))
+		return ERR_CAST(clk_hw);
+
+	return clk_hw->clk;
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_sensor_clk_get);
include/media/v4l2-common.h +27 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() 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-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.
+ *
+ * Returns a pointer to a struct clk on success or an error pointer on failure.
+ */
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
 	/*
Signature · 1 line
2.49.0
maintainer
#2 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Mehdi,

Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Quoted 122 lines

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

---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +52 -0
index bd160a8c9efe..ac98895b0394 100644
@@ -34,6 +34,9 @@
  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -673,3 +676,52 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_link_freq_to_bitmap);
+
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
+{
+	const char *clk_id __free(kfree) = NULL;
+	struct clk_hw *clk_hw;
+	struct clk *clk;
+	bool of_node;
+	u32 rate;
+	int ret;
+
+	clk = devm_clk_get_optional(dev, id);
+	ret = device_property_read_u32(dev, "clock-frequency", &rate);
+	of_node = is_of_node(dev_fwnode(dev));
+
+	if (clk) {
+		if (!ret && !of_node) {
+			ret = clk_set_rate(clk, rate);
+			if (ret) {
+				dev_err(dev, "Failed to set clock rate: %u\n",
+					rate);
+				return ERR_PTR(ret);
+			}
+		}
+		return clk;
+	}
+
+	if (PTR_ERR(clk) == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	if (!IS_ENABLED(CONFIG_COMMON_CLK) || of_node)
+		return ERR_PTR(-ENOENT);
+
+	if (ret)
+		return ERR_PTR(ret == -EINVAL ? -EPROBE_DEFER : ret);
+
+	if (!id) {
+		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
+		if (!clk_id)
+			return ERR_PTR(-ENOMEM);
+		id = clk_id;
+	}
+
+	clk_hw = devm_clk_hw_register_fixed_rate(dev, id, NULL, 0, rate);
+	if (IS_ERR(clk_hw))
+		return ERR_CAST(clk_hw);
+
+	return clk_hw->clk;
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_sensor_clk_get);
include/media/v4l2-common.h +27 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() 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-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.
+ *
+ * Returns a pointer to a struct clk on success or an error pointer on failure.
+ */
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
 	/*
Signature · 3 lines
Regards,

Sakari Ailus
#3 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Sakari,

Quoted 18 lines · Sakari Ailus

Hi Mehdi,

Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Quoted 5 lines

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Two things before applying:

- A missing Signed-off-by: Laurent Pinchart <[email protected]> for the Documentation patch -> [PATCH 02/48]

- We still need to agree on how to proceed for the sensor drivers I mentioned in the cover Letter:

1) drivers/media/i2c/s5k5baf.c
Always returns -EPROBE_DEFER if getting the clock fails ?!

2) 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 ?

3) 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.

--
Kind Regards
Mehdi Djait

maintainer
#4 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Mehdi,

Quoted 24 lines · Mehdi Djait

Hi Sakari,

Quoted 21 lines · Sakari Ailus

Hi Mehdi,

Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

Quoted 7 lines
Quoted 2 lines

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Two things before applying:

- A missing Signed-off-by: Laurent Pinchart <[email protected]> for the Documentation patch -> [PATCH 02/48]

Is Co-developed-by: also relevant?

Quoted 6 lines

- We still need to agree on how to proceed for the sensor drivers I mentioned in the cover Letter:

1) drivers/media/i2c/s5k5baf.c
Always returns -EPROBE_DEFER if getting the clock fails ?!

This can be fixed later on IMO.

Quoted 5 lines

2) 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 ?

There are no DT bindings. I wonder if this is still relevant. Maybe Jacopo has an idea?

Quoted 4 lines

3) 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.

Isn't this a similar case than the other sensor (which I can't remember anymore), where effectively the rate set couldn't be different than the clock already had?

I think this also could be handled after this set.

Signature · 3 lines
Kind regards,

Sakari Ailus
maintainer
#5 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Sakari, Mehdi,

Quoted 47 lines · Sakari Ailus

Hi Mehdi,

Quoted 24 lines · Mehdi Djait

Hi Sakari,

Quoted 21 lines · Sakari Ailus

Hi Mehdi,

Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

Quoted 7 lines
Quoted 2 lines

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Two things before applying:

- A missing Signed-off-by: Laurent Pinchart <[email protected]> for the Documentation patch -> [PATCH 02/48]

Is Co-developed-by: also relevant?

Quoted 6 lines

- We still need to agree on how to proceed for the sensor drivers I mentioned in the cover Letter:

1) drivers/media/i2c/s5k5baf.c
Always returns -EPROBE_DEFER if getting the clock fails ?!

This can be fixed later on IMO.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

2) 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 ?

There are no DT bindings. I wonder if this is still relevant. Maybe Jacopo has an idea?

Not really, the driver has been ported to be a regular i2c driver from its soc-camera-based legacy implementation but has seen basically no development since then, if not for sub-system wide changes or odd fixes.

Looking at the implementatio, the driver indeed seems to implement what _optional() does already, so it might be more opportune to convert it to _optional() first maybe ? However in my understanding your patch doesn't change the current behaviour, doesn't it ? In this case I think you can go ahead.

Thanks
j

Quoted 17 lines
Quoted 5 lines

3) 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.

Isn't this a similar case than the other sensor (which I can't remember anymore), where effectively the rate set couldn't be different than the clock already had?

I think this also could be handled after this set.

--
Kind regards,

Sakari Ailus

maintainer
#6 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Quoted 22 lines · Jacopo Mondi
Quoted 21 lines · Sakari Ailus
Quoted 20 lines · Mehdi Djait
Quoted 19 lines · Sakari Ailus
Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Two things before applying:

- A missing Signed-off-by: Laurent Pinchart <[email protected]> for the Documentation patch -> [PATCH 02/48]

Fixed.

Quoted 9 lines
Quoted 9 lines

Is Co-developed-by: also relevant?

Quoted 5 lines

- We still need to agree on how to proceed for the sensor drivers I mentioned in the cover Letter:

1) drivers/media/i2c/s5k5baf.c
Always returns -EPROBE_DEFER if getting the clock fails ?!

This can be fixed later on IMO.

Agreed.

Quoted 13 lines
Quoted 8 lines
Quoted 5 lines

2) 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 ?

There are no DT bindings. I wonder if this is still relevant. Maybe Jacopo has an idea?

Not really, the driver has been ported to be a regular i2c driver from its soc-camera-based legacy implementation but has seen basically no development since then, if not for sub-system wide changes or odd fixes.

Quoted 5 lines

Looking at the implementatio, the driver indeed seems to implement what _optional() does already, so it might be more opportune to convert it to _optional() first maybe ? However in my understanding your patch doesn't change the current behaviour, doesn't it ? In this case I think you can go ahead.

Agreed too.

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

3) 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.

Isn't this a similar case than the other sensor (which I can't remember anymore), where effectively the rate set couldn't be different than the clock already had?

I think this also could be handled after this set.

Ideally we should stop setting the rate and simplify the driver, but we have to be careful about regressions. I agree with Sakari, we can address this later.

Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hello everyone,

Quoted 26 lines · Laurent Pinchart
Quoted 25 lines · Jacopo Mondi
Quoted 24 lines · Sakari Ailus
Quoted 23 lines · Mehdi Djait
Quoted 21 lines · Sakari Ailus
Quoted 6 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

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

Quoted 8 lines

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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
A reference to the clock producer is present, where the clock is provided by a camera sensor PMIC driver (e.g. int3472/tps68470.c)

Missing leading dot. You could also rewrap this paragraph, using longer lines up to 75 characters.

If there's not going to be further versions of the patch, I'll just rewrap this while applying.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Two things before applying:

- A missing Signed-off-by: Laurent Pinchart <[email protected]> for the Documentation patch -> [PATCH 02/48]

Fixed.

Thanks!

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Is Co-developed-by: also relevant?

Yes it is relevant for that patch.

Quoted 39 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

- We still need to agree on how to proceed for the sensor drivers I mentioned in the cover Letter:

1) drivers/media/i2c/s5k5baf.c
Always returns -EPROBE_DEFER if getting the clock fails ?!

This can be fixed later on IMO.

Agreed.

Quoted 13 lines
Quoted 8 lines
Quoted 5 lines

2) 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 ?

There are no DT bindings. I wonder if this is still relevant. Maybe Jacopo has an idea?

Not really, the driver has been ported to be a regular i2c driver from its soc-camera-based legacy implementation but has seen basically no development since then, if not for sub-system wide changes or odd fixes.

Quoted 5 lines

Looking at the implementatio, the driver indeed seems to implement what _optional() does already, so it might be more opportune to convert it to _optional() first maybe ? However in my understanding your patch doesn't change the current behaviour, doesn't it ? In this case I think you can go ahead.

Agreed too.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

3) 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.

Isn't this a similar case than the other sensor (which I can't remember anymore), where effectively the rate set couldn't be different than the clock already had?

Quoted 6 lines
Quoted 1 line
Quoted 1 line

I think this also could be handled after this set.

Ideally we should stop setting the rate and simplify the driver, but we have to be careful about regressions. I agree with Sakari, we can address this later.

Ok, good to know.

Thank you everyone for the reviews!

--
Kind Regards
Mehdi Djait

maintainer
#8 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

In reply to Mehdi Djait

Hi Mehdi,

One more comment.

Quoted 43 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +4 -0
index bd160a8c9efe..ac98895b0394 100644
@@ -34,6 +34,9 @@
  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -673,3 +676,52 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_link_freq_to_bitmap);
+

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 689

Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10 -0
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
+{
+	const char *clk_id __free(kfree) = NULL;
+	struct clk_hw *clk_hw;
+	struct clk *clk;
+	bool of_node;
+	u32 rate;
+	int ret;
+
+	clk = devm_clk_get_optional(dev, id);

Shouldn't your return here if there's an error ?

	if (IS_ERR(clk))
		return clk;

because ...

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 695

Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +6 -0
+	ret = device_property_read_u32(dev, "clock-frequency", &rate);
+	of_node = is_of_node(dev_fwnode(dev));
+
+	if (clk) {
+		if (!ret && !of_node) {
+			ret = clk_set_rate(clk, rate);

... here clk_set_rate() will dereference clk and crash if it's an error pointer ...

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 706

Quoted 11 lines
drivers/media/v4l2-core/v4l2-common.c +11 -0
+			if (ret) {
+				dev_err(dev, "Failed to set clock rate: %u\n",
+					rate);
+				return ERR_PTR(ret);
+			}
+		}
+		return clk;
+	}
+
+	if (PTR_ERR(clk) == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);

... and this will never be reached.

Quoted 26 lines
drivers/media/v4l2-core/v4l2-common.c +21 -0
+
+	if (!IS_ENABLED(CONFIG_COMMON_CLK) || of_node)
+		return ERR_PTR(-ENOENT);
+
+	if (ret)
+		return ERR_PTR(ret == -EINVAL ? -EPROBE_DEFER : ret);
+
+	if (!id) {
+		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
+		if (!clk_id)
+			return ERR_PTR(-ENOMEM);
+		id = clk_id;
+	}
+
+	clk_hw = devm_clk_hw_register_fixed_rate(dev, id, NULL, 0, rate);
+	if (IS_ERR(clk_hw))
+		return ERR_CAST(clk_hw);
+
+	return clk_hw->clk;
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_sensor_clk_get);
include/media/v4l2-common.h +0 -0
index 0a43f56578bc..1c79ca4d5c73 100644

include/media/v4l2-common.h int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, · line 103

Quoted 4 lines
include/media/v4l2-common.h +1 -0
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;

Please keep forward declarations sorted.

You don't need to resubmit the whole series for this, but it would be useful if you could retest it, and then send a new version of just this patch.

Quoted 36 lines
include/media/v4l2-common.h +26 -0
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() 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-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.
+ *
+ * Returns a pointer to a struct clk on success or an error pointer on failure.
+ */
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
 	/*
Signature · 3 lines
Regards,

Laurent Pinchart
#9 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Laurent,

Thank you for the review!

Quoted 66 lines · Laurent Pinchart

Hi Mehdi,

One more comment.

Quoted 43 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +4 -0
index bd160a8c9efe..ac98895b0394 100644
@@ -34,6 +34,9 @@
  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -673,3 +676,52 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_link_freq_to_bitmap);
+

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 689

Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +10 -0
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
+{
+	const char *clk_id __free(kfree) = NULL;
+	struct clk_hw *clk_hw;
+	struct clk *clk;
+	bool of_node;
+	u32 rate;
+	int ret;
+
+	clk = devm_clk_get_optional(dev, id);

Shouldn't your return here if there's an error ?

	if (IS_ERR(clk))
		return clk;

because ...

Quoted 10 lines

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 695

Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +6 -0
+	ret = device_property_read_u32(dev, "clock-frequency", &rate);
+	of_node = is_of_node(dev_fwnode(dev));
+
+	if (clk) {
+		if (!ret && !of_node) {
+			ret = clk_set_rate(clk, rate);

... here clk_set_rate() will dereference clk and crash if it's an error pointer ...

Ack.

Quoted 5 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-common.c +5 -0
+			if (ret) {
+				dev_err(dev, "Failed to set clock rate: %u\n",
+					rate);
+				return ERR_PTR(ret);
+			}
Quoted 9 lines

drivers/media/v4l2-core/v4l2-common.c int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 706

Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +6 -0
+		}
+		return clk;
+	}
+
+	if (PTR_ERR(clk) == -EPROBE_DEFER)
+		return ERR_PTR(-EPROBE_DEFER);

... and this will never be reached.

Ack.

Quoted 33 lines
Quoted 26 lines
drivers/media/v4l2-core/v4l2-common.c +21 -0
+
+	if (!IS_ENABLED(CONFIG_COMMON_CLK) || of_node)
+		return ERR_PTR(-ENOENT);
+
+	if (ret)
+		return ERR_PTR(ret == -EINVAL ? -EPROBE_DEFER : ret);
+
+	if (!id) {
+		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
+		if (!clk_id)
+			return ERR_PTR(-ENOMEM);
+		id = clk_id;
+	}
+
+	clk_hw = devm_clk_hw_register_fixed_rate(dev, id, NULL, 0, rate);
+	if (IS_ERR(clk_hw))
+		return ERR_CAST(clk_hw);
+
+	return clk_hw->clk;
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_sensor_clk_get);
include/media/v4l2-common.h +0 -0
index 0a43f56578bc..1c79ca4d5c73 100644

include/media/v4l2-common.h int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, · line 103

Quoted 4 lines
include/media/v4l2-common.h +1 -0
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;

Please keep forward declarations sorted.

Quoted 3 lines

You don't need to resubmit the whole series for this, but it would be useful if you could retest it, and then send a new version of just this patch.

You are totally right about the comment.

@Sakari: I will send the patch as a reply to this, I went ahead and added the missing leading dots you mentioned in your reply. Tell me if this okay for you when you pick up the patches or should I send you the complete v3 ?

--
Kind Regards
Mehdi Djait

#10 lore raw

PATCH v3 1/1 media: v4l2-common: Add a helper for obtaining the clock producer

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

This function also handles the special ACPI-based system case where:
. The clock-frequency _DSD property is present.
. 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.

---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +52 -0
index bd160a8c9efe..fedb21a74671 100644
@@ -34,6 +34,9 @@
  * Added Gerd Knorrs v4l1 enhancements (Justin Schoeman)
  */
 
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -673,3 +676,52 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 	return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_link_freq_to_bitmap);
+
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id)
+{
+	const char *clk_id __free(kfree) = NULL;
+	struct clk_hw *clk_hw;
+	struct clk *clk;
+	bool of_node;
+	u32 rate;
+	int ret;
+
+	clk = devm_clk_get_optional(dev, id);
+	if (IS_ERR(clk))
+		return clk;
+
+	ret = device_property_read_u32(dev, "clock-frequency", &rate);
+	of_node = is_of_node(dev_fwnode(dev));
+
+	if (clk) {
+		if (!ret && !of_node) {
+			ret = clk_set_rate(clk, rate);
+			if (ret) {
+				dev_err(dev, "Failed to set clock rate: %u\n",
+					rate);
+				return ERR_PTR(ret);
+			}
+		}
+		return clk;
+	}
+
+	if (!IS_ENABLED(CONFIG_COMMON_CLK) || of_node)
+		return ERR_PTR(-ENOENT);
+
+	if (ret)
+		return ERR_PTR(ret == -EINVAL ? -EPROBE_DEFER : ret);
+
+	if (!id) {
+		clk_id = kasprintf(GFP_KERNEL, "clk-%s", dev_name(dev));
+		if (!clk_id)
+			return ERR_PTR(-ENOMEM);
+		id = clk_id;
+	}
+
+	clk_hw = devm_clk_hw_register_fixed_rate(dev, id, NULL, 0, rate);
+	if (IS_ERR(clk_hw))
+		return ERR_CAST(clk_hw);
+
+	return clk_hw->clk;
+}
+EXPORT_SYMBOL_GPL(devm_v4l2_sensor_clk_get);
include/media/v4l2-common.h +27 -0
index 0a43f56578bc..9d6c236e8f14 100644
@@ -97,6 +97,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 
 /* ------------------------------------------------------------------------- */
 
+struct clk;
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() 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-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.
+ *
+ * Returns a pointer to a struct clk on success or an error pointer on failure.
+ */
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
 	/*
Signature · 1 line
2.49.0
maintainer
#11 lore raw

Re: [PATCH v3] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Mehdi,

Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
. The clock-frequency _DSD property is present.
. 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.

How about adding

	select COMMON_CLK if ACPI && !HAVE_LEGACY_CLK

to menuconfig VIDEO_CAMERA_SENSOR, in order to ensure COMMON_CLK is enabled on ACPI platforms where it becomes a necessity for sensors?

This should probably be a new patch?

Signature · 3 lines
Regards,

Sakari Ailus
#12 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

In reply to Mehdi Djait

Hi Mehdi, Sakari, Laurent,

Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

I made a suggestion below.

Quoted 10 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Better suggestions are welcome.

If it is just adding a paragraph, then I can just add that manually. If the change is more involved, then a v2.1 for just this patch should be posted.

Other than this, the series looks good.

Regards,

Hans

Quoted 8 lines
include/media/v4l2-common.h +5 -0
+ *
+ * Returns a pointer to a struct clk on success or an error pointer on failure.
+ */
+struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
 	/*
maintainer
#13 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Hans,

Quoted 23 lines · Hans Verkuil

Hi Mehdi, Sakari, Laurent,

Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

Quoted 5 lines

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

Quoted 59 lines

I made a suggestion below.

Quoted 10 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

How about:

* This function may be used in camera sensor drivers only.

Quoted 5 lines

If it is just adding a paragraph, then I can just add that manually. If the change is more involved, then a v2.1 for just this patch should be posted.

Other than this, the series looks good.

Signature · 3 lines
Kind regards,

Sakari Ailus
maintainer
#14 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Quoted 25 lines · Sakari Ailus
Quoted 24 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

Quoted 6 lines
Quoted 2 lines

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

Quoted 57 lines
Quoted 57 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

Quoted 12 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

How about:

* This function may be used in camera sensor drivers only.

Quoted 4 lines

If it is just adding a paragraph, then I can just add that manually. If the change is more involved, then a v2.1 for just this patch should be posted.

Other than this, the series looks good.

Signature · 3 lines
Regards,

Laurent Pinchart
#15 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Quoted 29 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 26 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Quoted 6 lines
Quoted 3 lines

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

I'd like to have the rationale of why this is a sensor-only function documented. If I wondered about that, then someone else will likely have the same question.

Quoted 58 lines
Quoted 58 lines
Quoted 58 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 14 lines
Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

Quoted 7 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

How about:

* This function may be used in camera sensor drivers only.

That just restates what is also in the function name. It's the 'why' that I'd like to know. Even if you simply don't know if this will work for non-sensor driver, just stating that will help.

Regards,

Hans

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

If it is just adding a paragraph, then I can just add that manually. If the change is more involved, then a v2.1 for just this patch should be posted.

Other than this, the series looks good.

maintainer
#16 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Hans,

Quoted 110 lines · Hans Verkuil
Quoted 29 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 26 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Quoted 6 lines
Quoted 3 lines

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

I'd like to have the rationale of why this is a sensor-only function documented. If I wondered about that, then someone else will likely have the same question.

Quoted 69 lines
Quoted 58 lines
Quoted 58 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

Quoted 4 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

How about:

* This function may be used in camera sensor drivers only.

That just restates what is also in the function name. It's the 'why' that I'd like to know. Even if you simply don't know if this will work for non-sensor driver, just stating that will help.

As I replied on #linux-media:

devm_v4l2_sensor_clk_get() in practice provides a clock to camera sensors which is what they need; other types of devices generally don't care much about clocks. Why camera sensors are special is that they have a PLL and a CSI-2 RX the configuration of which depend on the external clock.

Is something like this what you're looking for, or something more elaborate? There are different ways the clock can be obtained but I'm not sure we'll need to go to that in the function documentation.

Signature · 3 lines
Regards,

Sakari Ailus
#17 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Quoted 123 lines · Sakari Ailus

Hi Hans,

Quoted 110 lines · Hans Verkuil
Quoted 29 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 26 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Quoted 6 lines
Quoted 3 lines

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

I'd like to have the rationale of why this is a sensor-only function documented. If I wondered about that, then someone else will likely have the same question.

Quoted 69 lines
Quoted 58 lines
Quoted 58 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

Quoted 4 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

How about:

* This function may be used in camera sensor drivers only.

That just restates what is also in the function name. It's the 'why' that I'd like to know. Even if you simply don't know if this will work for non-sensor driver, just stating that will help.

As I replied on #linux-media:

Quoted 9 lines

devm_v4l2_sensor_clk_get() in practice provides a clock to camera sensors which is what they need; other types of devices generally don't care much about clocks. Why camera sensors are special is that they have a PLL and a CSI-2 RX the configuration of which depend on the external clock.

Is something like this what you're looking for, or something more elaborate? There are different ways the clock can be obtained but I'm not sure we'll need to go to that in the function documentation.

Yes, that's sufficient. If you can make a patch adding that, then I'll add it to the PR. No need to make a new PR for this, I can just add it myself.

Regards,

Hans

maintainer
#18 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

Hi Hans,

Quoted 129 lines · Hans Verkuil
Quoted 128 lines · Sakari Ailus

Hi Hans,

Quoted 110 lines · Hans Verkuil
Quoted 29 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 26 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Quoted 6 lines
Quoted 3 lines

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

I'd like to have the rationale of why this is a sensor-only function documented. If I wondered about that, then someone else will likely have the same question.

Quoted 69 lines
Quoted 58 lines
Quoted 58 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

Quoted 4 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

How about:

* This function may be used in camera sensor drivers only.

That just restates what is also in the function name. It's the 'why' that I'd like to know. Even if you simply don't know if this will work for non-sensor driver, just stating that will help.

As I replied on #linux-media:

devm_v4l2_sensor_clk_get() in practice provides a clock to camera sensors which is what they need; other types of devices generally don't care much about clocks. Why camera sensors are special is that they have a PLL and a CSI-2 RX the configuration of which depend on the external clock.

Quoted 7 lines
Quoted 4 lines

Is something like this what you're looking for, or something more elaborate? There are different ways the clock can be obtained but I'm not sure we'll need to go to that in the function documentation.

Yes, that's sufficient. If you can make a patch adding that, then I'll add it to the PR. No need to make a new PR for this, I can just add it myself.

Ack, Ḯ'll post the patch tomorrow.

Signature · 3 lines
Regards,

Sakari Ailus
maintainer
#19 lore raw

PATCH 1/1 media: v4l2-common: Improve devm_v4l2_sensor_clk_get() documentation

In reply to Hans Verkuil

Remove the extra leading period and provide more elaborate explanation for why devm_v4l2_sensor_clk_get() is only allowed to be used on camera sensor devices.

---
 include/media/v4l2-common.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
include/media/v4l2-common.h +9 -1
index 9d6c236e8f14..39dd0c78d70f 100644
@@ -623,7 +623,7 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 
 /**
  * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
- *	for a camera sensor.
+ *	for a camera sensor
  *
  * @dev: device for v4l2 sensor clock "consumer"
  * @id: clock consumer ID
@@ -643,6 +643,14 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
  *
  * In this case try to set the clock-frequency value to the provided clock.
  *
+ * As the name indicates, this function may only be used on camera sensor
+ * devices. This is because generally only camera sensors do need a clock to
+ * query the frequency from, due to the requirement to configure the PLL for a
+ * given CSI-2 interface frequency where the sensor's external clock frequency
+ * is a factor. Additionally, the clock frequency tends to be available on ACPI
+ * firmware based systems for camera sensors specifically (if e.g. DisCo for
+ * Imaging compliant).
+ *
  * Returns a pointer to a struct clk on success or an error pointer on failure.
  */
 struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *id);
Signature · 1 line
2.39.5
#20 lore raw

Re: [PATCH 1/1] media: v4l2-common: Improve devm_v4l2_sensor_clk_get() documentation

Hi Sakari,

Thank you for the patch!

Quoted 24 lines · Sakari Ailus

Remove the extra leading period and provide more elaborate explanation for why devm_v4l2_sensor_clk_get() is only allowed to be used on camera sensor devices.

---
 include/media/v4l2-common.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
include/media/v4l2-common.h +1 -1
index 9d6c236e8f14..39dd0c78d70f 100644
@@ -623,7 +623,7 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 
 /**
  * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
- *	for a camera sensor.
+ *	for a camera sensor
  *
  * @dev: device for v4l2 sensor clock "consumer"
  * @id: clock consumer ID
@@ -643,6 +643,14 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
  *

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 653

Quoted 10 lines
include/media/v4l2-common.h +8 -0
  * In this case try to set the clock-frequency value to the provided clock.
  *
+ * As the name indicates, this function may only be used on camera sensor
+ * devices. This is because generally only camera sensors do need a clock to
+ * query the frequency from, due to the requirement to configure the PLL for a
+ * given CSI-2 interface frequency where the sensor's external clock frequency
+ * is a factor. Additionally, the clock frequency tends to be available on ACPI
+ * firmware based systems for camera sensors specifically (if e.g. DisCo for
+ * Imaging compliant).
+ *

I don't know about the last sentence about ACPI. Does it help explain why this helper is intended only for camera sensors ?

--
Kind Regards
Mehdi Djait

maintainer
#21 lore raw

Re: [PATCH 1/1] media: v4l2-common: Improve devm_v4l2_sensor_clk_get() documentation

Hi Mehdi,

Quoted 34 lines · Mehdi Djait

Hi Sakari,

Thank you for the patch!

Quoted 29 lines · Sakari Ailus

Remove the extra leading period and provide more elaborate explanation for why devm_v4l2_sensor_clk_get() is only allowed to be used on camera sensor devices.

---
 include/media/v4l2-common.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
include/media/v4l2-common.h +4 -1
index 9d6c236e8f14..39dd0c78d70f 100644
@@ -623,7 +623,7 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 
 /**
  * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
- *	for a camera sensor.
+ *	for a camera sensor
  *
  * @dev: device for v4l2 sensor clock "consumer"
  * @id: clock consumer ID
@@ -643,6 +643,14 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
  *
  * In this case try to set the clock-frequency value to the provided clock.
  *
+ * As the name indicates, this function may only be used on camera sensor
+ * devices. This is because generally only camera sensors do need a clock to
+ * query the frequency from, due to the requirement to configure the PLL for a
Quoted 8 lines

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 653

Quoted 5 lines
include/media/v4l2-common.h +5 -0
+ * given CSI-2 interface frequency where the sensor's external clock frequency
+ * is a factor. Additionally, the clock frequency tends to be available on ACPI
+ * firmware based systems for camera sensors specifically (if e.g. DisCo for
+ * Imaging compliant).
+ *

I don't know about the last sentence about ACPI. Does it help explain why this helper is intended only for camera sensors ?

There couldn't be a generic function to do this due to how the firmware is implemented, that's because I think it's relevant.

I think we could later on support ACPI clock input resource descriptors but I'd wait for actual use first -- or DisCo for Imaging update advocating them instead of the clock-frequency property. In ACPI clock handling in general takes place through power resources so unless drivers are interested in a particular frequency, there's no need to provide that. Of course some cases could be up to a debate at least to some degree.

Signature · 3 lines
Regards,

Sakari Ailus
maintainer
#22 lore raw

Re: [PATCH v2 01/48] media: v4l2-common: Add a helper for obtaining the clock producer

In reply to Laurent Pinchart

Hi Laurent,

Quoted 29 lines · Laurent Pinchart
Quoted 28 lines · Sakari Ailus
Quoted 26 lines · Hans Verkuil
Quoted 10 lines · Mehdi Djait

Introduce a helper for v4l2 sensor drivers on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

This helper behaves the same as devm_clk_get() 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.

Quoted 5 lines

This function also handles the special ACPI-based system case where:
The clock-frequency _DSD property is present.
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.

On irc I wondered about the name of the new function since it is sensor specific, and if it can also be used for e.g. video receivers, then it should be renamed to something more generic.

According to Laurent there is no ACPI standard for video receivers, so that's the reason this is sensor specific.

I'd like to see that documented in this patch. Either in the commit log, or, preferred, in the header in the function description.

Quoted 6 lines
Quoted 3 lines

Given this patch has been around for quite some time and I've sent a PR on it, I'd prefer to proceed with the current PR. I'm fine with adding more documentation though if you think we should do that.

How about a separate patch that Hans can merge just on top of your PR ? Could you send one ?

Sure. Let's try to agree on what it should contain. :-)

Quoted 58 lines
Quoted 58 lines
Quoted 58 lines

I made a suggestion below.

Quoted 9 lines
---
 drivers/media/v4l2-core/v4l2-common.c | 52 +++++++++++++++++++++++++++
 include/media/v4l2-common.h           | 27 ++++++++++++++
 2 files changed, 79 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +0 -0

<snip>

Quoted 27 lines
include/media/v4l2-common.h +12 -0
index 0a43f56578bc..1c79ca4d5c73 100644
@@ -100,6 +100,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
 struct v4l2_device;
 struct v4l2_subdev;
 struct v4l2_subdev_ops;
+struct clk;
 
 /* I2C Helper functions */
 #include <linux/i2c.h>
@@ -620,6 +621,32 @@ int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
 			     unsigned int num_of_driver_link_freqs,
 			     unsigned long *bitmap);
 
+/**
+ * devm_v4l2_sensor_clk_get - lookup and obtain a reference to a clock producer
+ *	for a camera sensor.
+ *
+ * @dev: device for v4l2 sensor clock "consumer"
+ * @id: clock consumer ID
+ *
+ * This function behaves the same way as devm_clk_get() except where there
+ * is no clock producer like in ACPI-based platforms.
+ *
+ * For ACPI-based platforms, the function will read the "clock-frequency"

include/media/v4l2-common.h int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs, · line 644

Quoted 10 lines
include/media/v4l2-common.h +10 -0
+ * ACPI _DSD property and register a fixed-clock with the frequency indicated
+ * in the property.
+ *
+ * This function also handles the special ACPI-based system case where:
+ *
+ * * The clock-frequency _DSD property is present.
+ * * 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.

*
* While ACPI has standardized sensor support, there is no standard support for
* e.g. video receivers. So this function is specific to sensors, hence the
* chosen function name.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Better suggestions are welcome.

ACPI itself does not standardise camera sensor support. What driver authors

But there's a de facto standard that makes this helper function suitable, isn't there ?

In this context DisCo for Imaging and Intel Windows ACPI camera description are worth mentioning. I wouldn't call the latter a "standard" though. But it doesn't matter whether it is or not, all the caller needs to know is that the function returns a usable clock.

Quoted 14 lines
Quoted 13 lines

should know indeed is that this function provides a clock that can be at least queried for frequency, independently of how that clock is controlled or how its frequency is configured.

How about:

* This function may be used in camera sensor drivers only.

Quoted 4 lines

If it is just adding a paragraph, then I can just add that manually. If the change is more involved, then a v2.1 for just this patch should be posted.

Other than this, the series looks good.

Signature · 3 lines
Regards,

Sakari Ailus
#23 lore raw

PATCH v2 2/48 Documentation: media: camera-sensor: Mention v4l2_devm_sensor_clk_get() for obtaining the clock

In reply to Mehdi Djait

Add the new v4l2 helper devm_v4l2_sensor_clk_get() to Documentation. the helper works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 .../driver-api/media/camera-sensor.rst        | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
Documentation/driver-api/media/camera-sensor.rst +17 -7
index c290833165e6..94bd1dae82d5 100644
@@ -29,21 +29,31 @@ used in the system. Using another frequency may cause harmful effects
 elsewhere. Therefore only the pre-determined frequencies are configurable by the
 user.
 
+The external clock frequency shall be retrieved by obtaining the external clock
+using the ``devm_v4l2_sensor_clk_get()`` helper function, and then getting its
+frequency with ``clk_get_rate()``. Usage of the helper function guarantees
+correct behaviour regardless of whether the sensor is integrated in a DT-based
+or ACPI-based system.
+
 ACPI
 ~~~~
 
-Read the ``clock-frequency`` _DSD property to denote the frequency. The driver
-can rely on this frequency being used.
+ACPI-based systems typically don't register the sensor external clock with the
+kernel, but specify the external clock frequency in the ``clock-frequency``
+_DSD property. The ``devm_v4l2_sensor_clk_get()`` helper creates and returns a
+fixed clock set at that rate.
 
 Devicetree
 ~~~~~~~~~~
 
-The preferred way to achieve this is using ``assigned-clocks``,
-``assigned-clock-parents`` and ``assigned-clock-rates`` properties. See the
-`clock device tree bindings
+Devicetree-based systems declare the sensor external clock in the device tree
+and reference it from the sensor node. The preferred way to select the external
+clock frequency is to use the ``assigned-clocks``, ``assigned-clock-parents``
+and ``assigned-clock-rates`` properties in the sensor node to set the clock
+rate. See the `clock device tree bindings
 <https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/clock/clock.yaml>`_
-for more information. The driver then gets the frequency using
-``clk_get_rate()``.
+for more information. The ``devm_v4l2_sensor_clk_get()`` helper retrieves and
+returns that clock.
 
 This approach has the drawback that there's no guarantee that the frequency
 hasn't been modified directly or indirectly by another driver, or supported by
Signature · 1 line
2.49.0
maintainer
#24 lore raw

Re: [PATCH v2 02/48] Documentation: media: camera-sensor: Mention v4l2_devm_sensor_clk_get() for obtaining the clock

Quoted 6 lines · Mehdi Djait

Add the new v4l2 helper devm_v4l2_sensor_clk_get() to Documentation. the helper works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

Quoted 49 lines
---
 .../driver-api/media/camera-sensor.rst        | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
Documentation/driver-api/media/camera-sensor.rst +17 -7
index c290833165e6..94bd1dae82d5 100644
@@ -29,21 +29,31 @@ used in the system. Using another frequency may cause harmful effects
 elsewhere. Therefore only the pre-determined frequencies are configurable by the
 user.
 
+The external clock frequency shall be retrieved by obtaining the external clock
+using the ``devm_v4l2_sensor_clk_get()`` helper function, and then getting its
+frequency with ``clk_get_rate()``. Usage of the helper function guarantees
+correct behaviour regardless of whether the sensor is integrated in a DT-based
+or ACPI-based system.
+
 ACPI
 ~~~~
 
-Read the ``clock-frequency`` _DSD property to denote the frequency. The driver
-can rely on this frequency being used.
+ACPI-based systems typically don't register the sensor external clock with the
+kernel, but specify the external clock frequency in the ``clock-frequency``
+_DSD property. The ``devm_v4l2_sensor_clk_get()`` helper creates and returns a
+fixed clock set at that rate.
 
 Devicetree
 ~~~~~~~~~~
 
-The preferred way to achieve this is using ``assigned-clocks``,
-``assigned-clock-parents`` and ``assigned-clock-rates`` properties. See the
-`clock device tree bindings
+Devicetree-based systems declare the sensor external clock in the device tree
+and reference it from the sensor node. The preferred way to select the external
+clock frequency is to use the ``assigned-clocks``, ``assigned-clock-parents``
+and ``assigned-clock-rates`` properties in the sensor node to set the clock
+rate. See the `clock device tree bindings
 <https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/clock/clock.yaml>`_
-for more information. The driver then gets the frequency using
-``clk_get_rate()``.
+for more information. The ``devm_v4l2_sensor_clk_get()`` helper retrieves and
+returns that clock.
 
 This approach has the drawback that there's no guarantee that the frequency
 hasn't been modified directly or indirectly by another driver, or supported by
Signature · 3 lines
Regards,

Laurent Pinchart
#25 lore raw

PATCH v2 3/48 media: i2c: ar0521: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ar0521.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/ar0521.c +4 -5
index 24873149096c..939bf590d4b2 100644
@@ -1077,11 +1077,10 @@ static int ar0521_probe(struct i2c_client *client)
 	}
 
 	/* Get master clock (extclk) */
-	sensor->extclk = devm_clk_get(dev, "extclk");
-	if (IS_ERR(sensor->extclk)) {
-		dev_err(dev, "failed to get extclk\n");
-		return PTR_ERR(sensor->extclk);
-	}
+	sensor->extclk = devm_v4l2_sensor_clk_get(dev, "extclk");
+	if (IS_ERR(sensor->extclk))
+		return dev_err_probe(dev, PTR_ERR(sensor->extclk),
+				     "failed to get extclk\n");
 
 	sensor->extclk_freq = clk_get_rate(sensor->extclk);
 
Signature · 1 line
2.49.0
#26 lore raw

PATCH v2 4/48 media: i2c: et8ek8: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/et8ek8/et8ek8_driver.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/et8ek8/et8ek8_driver.c +4 -5
index 7519863d77b1..4787b2c430f8 100644
@@ -1433,11 +1433,10 @@ static int et8ek8_probe(struct i2c_client *client)
 		return PTR_ERR(sensor->vana);
 	}
 
-	sensor->ext_clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(sensor->ext_clk)) {
-		dev_err(&client->dev, "could not get clock\n");
-		return PTR_ERR(sensor->ext_clk);
-	}
+	sensor->ext_clk = devm_v4l2_sensor_clk_get(dev, NULL);
+	if (IS_ERR(sensor->ext_clk))
+		return dev_err_probe(&client->dev, PTR_ERR(sensor->ext_clk),
+				     "could not get clock\n");
 
 	ret = of_property_read_u32(dev->of_node, "clock-frequency",
 				   &sensor->xclk_freq);
Signature · 1 line
2.49.0
#27 lore raw

PATCH v2 5/48 media: i2c: gc05a2: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/gc05a2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/gc05a2.c +1 -1
index 3f7f3d5abeeb..4dadd25e6c90 100644
@@ -1235,7 +1235,7 @@ static int gc05a2_probe(struct i2c_client *client)
 		return dev_err_probe(dev, PTR_ERR(gc05a2->regmap),
 				     "failed to init CCI\n");
 
-	gc05a2->xclk = devm_clk_get(dev, NULL);
+	gc05a2->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(gc05a2->xclk))
 		return dev_err_probe(dev, PTR_ERR(gc05a2->xclk),
 				     "failed to get xclk\n");
Signature · 1 line
2.49.0
#28 lore raw

PATCH v2 6/48 media: i2c: gc08a3: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/gc08a3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/gc08a3.c +1 -1
index 938709a677b6..5d38dfa9878e 100644
@@ -1199,7 +1199,7 @@ static int gc08a3_probe(struct i2c_client *client)
 		return dev_err_probe(dev, PTR_ERR(gc08a3->regmap),
 				     "failed to init CCI\n");
 
-	gc08a3->xclk = devm_clk_get(dev, NULL);
+	gc08a3->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(gc08a3->xclk))
 		return dev_err_probe(dev, PTR_ERR(gc08a3->xclk),
 				     "failed to get xclk\n");
Signature · 1 line
2.49.0
#29 lore raw

PATCH v2 7/48 media: i2c: gc2145: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/gc2145.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/gc2145.c +1 -1
index ba02161d46e7..52d9387559c9 100644
@@ -1334,7 +1334,7 @@ static int gc2145_probe(struct i2c_client *client)
 		return -EINVAL;
 
 	/* Get system clock (xclk) */
-	gc2145->xclk = devm_clk_get(dev, NULL);
+	gc2145->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(gc2145->xclk))
 		return dev_err_probe(dev, PTR_ERR(gc2145->xclk),
 				     "failed to get xclk\n");
Signature · 1 line
2.49.0
#30 lore raw

PATCH v2 8/48 media: i2c: hi846: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/hi846.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/i2c/hi846.c +5 -6
index 172772decd3d..a3f77b8434ca 100644
@@ -2052,12 +2052,11 @@ static int hi846_probe(struct i2c_client *client)
 		return ret;
 	}
 
-	hi846->clock = devm_clk_get(&client->dev, NULL);
-	if (IS_ERR(hi846->clock)) {
-		dev_err(&client->dev, "failed to get clock: %pe\n",
-			hi846->clock);
-		return PTR_ERR(hi846->clock);
-	}
+	hi846->clock = devm_v4l2_sensor_clk_get(&client->dev, NULL);
+	if (IS_ERR(hi846->clock))
+		return dev_err_probe(&client->dev, PTR_ERR(hi846->clock),
+				     "failed to get clock: %pe\n",
+				     hi846->clock);
 
 	mclk_freq = clk_get_rate(hi846->clock);
 	if (mclk_freq != 25000000)
Signature · 1 line
2.49.0
#31 lore raw

PATCH v2 9/48 media: i2c: imx214: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx214.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx214.c +1 -1
index dd7bc45523d8..73e7bc2f85c0 100644
@@ -1271,7 +1271,7 @@ static int imx214_probe(struct i2c_client *client)
 
 	imx214->dev = dev;
 
-	imx214->xclk = devm_clk_get(dev, NULL);
+	imx214->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(imx214->xclk))
 		return dev_err_probe(dev, PTR_ERR(imx214->xclk),
 				     "failed to get xclk\n");
Signature · 1 line
2.49.0
#32 lore raw

PATCH v2 10/48 media: i2c: imx219: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx219.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx219.c +1 -1
index 3b4f68543342..bb7808515178 100644
@@ -1188,7 +1188,7 @@ static int imx219_probe(struct i2c_client *client)
 				     "failed to initialize CCI\n");
 
 	/* Get system clock (xclk) */
-	imx219->xclk = devm_clk_get(dev, NULL);
+	imx219->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(imx219->xclk))
 		return dev_err_probe(dev, PTR_ERR(imx219->xclk),
 				     "failed to get xclk\n");
Signature · 1 line
2.49.0
#33 lore raw

PATCH v2 11/48 media: i2c: imx283: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx283.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/i2c/imx283.c +2 -3
index da618c8cbadc..8bff5bf4df12 100644
@@ -1462,11 +1462,10 @@ static int imx283_probe(struct i2c_client *client)
 	}
 
 	/* Get system clock (xclk) */
-	imx283->xclk = devm_clk_get(imx283->dev, NULL);
-	if (IS_ERR(imx283->xclk)) {
+	imx283->xclk = devm_v4l2_sensor_clk_get(imx283->dev, NULL);
+	if (IS_ERR(imx283->xclk))
 		return dev_err_probe(imx283->dev, PTR_ERR(imx283->xclk),
 				     "failed to get xclk\n");
-	}
 
 	xclk_freq = clk_get_rate(imx283->xclk);
 	for (i = 0; i < ARRAY_SIZE(imx283_frequencies); i++) {
Signature · 1 line
2.49.0
#34 lore raw

PATCH v2 12/48 media: i2c: imx290: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx290.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx290.c +1 -1
index fbf7eba3d71d..759df6eb8545 100644
@@ -1600,7 +1600,7 @@ static int imx290_probe(struct i2c_client *client)
 		return ret;
 
 	/* Acquire resources. */
-	imx290->xclk = devm_clk_get(dev, "xclk");
+	imx290->xclk = devm_v4l2_sensor_clk_get(dev, "xclk");
 	if (IS_ERR(imx290->xclk))
 		return dev_err_probe(dev, PTR_ERR(imx290->xclk),
 				     "Could not get xclk\n");
Signature · 1 line
2.49.0
#35 lore raw

PATCH v2 13/48 media: i2c: imx296: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx296.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx296.c +1 -1
index f3bec16b527c..3795b75a4397 100644
@@ -1044,7 +1044,7 @@ static int imx296_probe(struct i2c_client *client)
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->reset),
 				     "failed to get reset GPIO\n");
 
-	sensor->clk = devm_clk_get(sensor->dev, "inck");
+	sensor->clk = devm_v4l2_sensor_clk_get(sensor->dev, "inck");
 	if (IS_ERR(sensor->clk))
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->clk),
 				     "failed to get clock\n");
Signature · 1 line
2.49.0
#36 lore raw

PATCH v2 14/48 media: i2c: imx334: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx334.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx334.c +1 -1
index 846b9928d4e8..7a9b14d102c9 100644
@@ -997,7 +997,7 @@ static int imx334_parse_hw_config(struct imx334 *imx334)
 				     "failed to get reset gpio\n");
 
 	/* Get sensor input clock */
-	imx334->inclk = devm_clk_get(imx334->dev, NULL);
+	imx334->inclk = devm_v4l2_sensor_clk_get(imx334->dev, NULL);
 	if (IS_ERR(imx334->inclk))
 		return dev_err_probe(imx334->dev, PTR_ERR(imx334->inclk),
 					 "could not get inclk\n");
Signature · 1 line
2.49.0
#37 lore raw

PATCH v2 15/48 media: i2c: imx335: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx335.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/imx335.c +4 -5
index 9b4db4cd4929..c043df2f15fb 100644
@@ -1026,11 +1026,10 @@ static int imx335_parse_hw_config(struct imx335 *imx335)
 	}
 
 	/* Get sensor input clock */
-	imx335->inclk = devm_clk_get(imx335->dev, NULL);
-	if (IS_ERR(imx335->inclk)) {
-		dev_err(imx335->dev, "could not get inclk\n");
-		return PTR_ERR(imx335->inclk);
-	}
+	imx335->inclk = devm_v4l2_sensor_clk_get(imx335->dev, NULL);
+	if (IS_ERR(imx335->inclk))
+		return dev_err_probe(imx335->dev, PTR_ERR(imx335->inclk),
+				     "could not get inclk\n");
 
 	rate = clk_get_rate(imx335->inclk);
 	if (rate != IMX335_INCLK_RATE) {
Signature · 1 line
2.49.0
#38 lore raw

PATCH v2 16/48 media: i2c: imx412: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx412.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/imx412.c +4 -5
index c74097a59c42..7bbd639a9ddf 100644
@@ -933,11 +933,10 @@ static int imx412_parse_hw_config(struct imx412 *imx412)
 	}
 
 	/* Get sensor input clock */
-	imx412->inclk = devm_clk_get(imx412->dev, NULL);
-	if (IS_ERR(imx412->inclk)) {
-		dev_err(imx412->dev, "could not get inclk\n");
-		return PTR_ERR(imx412->inclk);
-	}
+	imx412->inclk = devm_v4l2_sensor_clk_get(imx412->dev, NULL);
+	if (IS_ERR(imx412->inclk))
+		return dev_err_probe(imx412->dev, PTR_ERR(imx412->inclk),
+				     "could not get inclk\n");
 
 	rate = clk_get_rate(imx412->inclk);
 	if (rate != IMX412_INCLK_RATE) {
Signature · 1 line
2.49.0
#39 lore raw

PATCH v2 17/48 media: i2c: imx415: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/imx415.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx415.c +1 -1
index 9f37779bd611..2e206a671ed3 100644
@@ -1251,7 +1251,7 @@ static int imx415_parse_hw_config(struct imx415 *sensor)
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->reset),
 				     "failed to get reset GPIO\n");
 
-	sensor->clk = devm_clk_get(sensor->dev, "inck");
+	sensor->clk = devm_v4l2_sensor_clk_get(sensor->dev, NULL);
 	if (IS_ERR(sensor->clk))
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->clk),
 				     "failed to get clock\n");
Signature · 1 line
2.49.0
maintainer Reviewed-by on v2 17/48
#40 lore raw

Re: [PATCH v2 17/48] media: i2c: imx415: Use the v4l2 helper for obtaining the clock

Hi Mehdi,

Thanks for doing this!

Quoted 9 lines · Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

Quoted 10 lines
---
 drivers/media/i2c/imx415.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/imx415.c +0 -0
index 9f37779bd611..2e206a671ed3 100644

drivers/media/i2c/imx415.c static int imx415_parse_hw_config(struct imx415 *sensor) · line 1257

Quoted 8 lines
drivers/media/i2c/imx415.c +1 -1
@@ -1251,7 +1251,7 @@ static int imx415_parse_hw_config(struct imx415 *sensor)
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->reset),
 				     "failed to get reset GPIO\n");
 
-	sensor->clk = devm_clk_get(sensor->dev, "inck");
+	sensor->clk = devm_v4l2_sensor_clk_get(sensor->dev, NULL);
 	if (IS_ERR(sensor->clk))
 		return dev_err_probe(sensor->dev, PTR_ERR(sensor->clk),
 				     "failed to get clock\n");

Thanks and best regards,
Michael

#41 lore raw

PATCH v2 18/48 media: i2c: mt9m001: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9m001.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m001.c +3 -2
index 12d3e86bdc0f..7a6114d18dfc 100644
@@ -743,9 +743,10 @@ static int mt9m001_probe(struct i2c_client *client)
 	if (!mt9m001)
 		return -ENOMEM;
 
-	mt9m001->clk = devm_clk_get(&client->dev, NULL);
+	mt9m001->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 	if (IS_ERR(mt9m001->clk))
-		return PTR_ERR(mt9m001->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(mt9m001->clk),
+				     "failed to get the clock\n");
 
 	mt9m001->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
 							GPIOD_OUT_LOW);
Signature · 1 line
2.49.0
#42 lore raw

PATCH v2 19/48 media: i2c: mt9m111: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9m111.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m111.c +3 -2
index 9aa5dcda3805..05dcf37c6f01 100644
@@ -1279,9 +1279,10 @@ static int mt9m111_probe(struct i2c_client *client)
 			return ret;
 	}
 
-	mt9m111->clk = devm_clk_get(&client->dev, "mclk");
+	mt9m111->clk = devm_v4l2_sensor_clk_get(&client->dev, "mclk");
 	if (IS_ERR(mt9m111->clk))
-		return PTR_ERR(mt9m111->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(mt9m111->clk),
+				     "failed to get mclk\n");
 
 	mt9m111->regulator = devm_regulator_get(&client->dev, "vdd");
 	if (IS_ERR(mt9m111->regulator)) {
Signature · 1 line
2.49.0
#43 lore raw

PATCH v2 20/48 media: i2c: mt9m114: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9m114.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/mt9m114.c +3 -3
index 5f0b0ad8f885..f12d330c0a78 100644
@@ -2360,10 +2360,10 @@ static int mt9m114_probe(struct i2c_client *client)
 		return ret;
 
 	/* Acquire clocks, GPIOs and regulators. */
-	sensor->clk = devm_clk_get(dev, NULL);
+	sensor->clk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(sensor->clk)) {
-		ret = PTR_ERR(sensor->clk);
-		dev_err_probe(dev, ret, "Failed to get clock\n");
+		ret = dev_err_probe(dev, PTR_ERR(sensor->clk),
+				    "Failed to get clock\n");
 		goto error_ep_free;
 	}
 
Signature · 1 line
2.49.0
#44 lore raw

PATCH v2 21/48 media: i2c: mt9p031: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9p031.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9p031.c +3 -2
index 4ef5fb06131d..4df8f2be15f3 100644
@@ -233,9 +233,10 @@ static int mt9p031_clk_setup(struct mt9p031 *mt9p031)
 	unsigned long ext_freq;
 	int ret;
 
-	mt9p031->clk = devm_clk_get(&client->dev, NULL);
+	mt9p031->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 	if (IS_ERR(mt9p031->clk))
-		return PTR_ERR(mt9p031->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(mt9p031->clk),
+				     "failed to get the clock\n");
 
 	ret = clk_set_rate(mt9p031->clk, mt9p031->ext_freq);
 	if (ret < 0)
Signature · 1 line
2.49.0
#45 lore raw

PATCH v2 22/48 media: i2c: mt9t112: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9t112.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/i2c/mt9t112.c +5 -6
index 878dff9b7577..2d2c840fc002 100644
@@ -1078,13 +1078,12 @@ static int mt9t112_probe(struct i2c_client *client)
 
 	v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
 
-	priv->clk = devm_clk_get(&client->dev, "extclk");
-	if (PTR_ERR(priv->clk) == -ENOENT) {
+	priv->clk = devm_v4l2_sensor_clk_get(&client->dev, "extclk");
+	if (PTR_ERR(priv->clk) == -ENOENT)
 		priv->clk = NULL;
-	} else if (IS_ERR(priv->clk)) {
-		dev_err(&client->dev, "Unable to get clock \"extclk\"\n");
-		return PTR_ERR(priv->clk);
-	}
+	else if (IS_ERR(priv->clk))
+		return dev_err_probe(&client->dev, PTR_ERR(priv->clk),
+				     "Unable to get clock \"extclk\"\n");
 
 	priv->standby_gpio = devm_gpiod_get_optional(&client->dev, "standby",
 						     GPIOD_OUT_HIGH);
Signature · 1 line
2.49.0
#46 lore raw

PATCH v2 23/48 media: i2c: mt9v032: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9v032.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9v032.c +3 -2
index 302120ff125e..9f4b4cb9853e 100644
@@ -1058,9 +1058,10 @@ static int mt9v032_probe(struct i2c_client *client)
 	if (IS_ERR(mt9v032->regmap))
 		return PTR_ERR(mt9v032->regmap);
 
-	mt9v032->clk = devm_clk_get(&client->dev, NULL);
+	mt9v032->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 	if (IS_ERR(mt9v032->clk))
-		return PTR_ERR(mt9v032->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(mt9v032->clk),
+				     "failed to get the clock\n");
 
 	mt9v032->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
 						      GPIOD_OUT_HIGH);
Signature · 1 line
2.49.0
#47 lore raw

PATCH v2 24/48 media: i2c: mt9v111: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/mt9v111.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9v111.c +3 -2
index 723fe138e7bc..6aa80b504168 100644
@@ -1129,9 +1129,10 @@ static int mt9v111_probe(struct i2c_client *client)
 	mt9v111->dev = &client->dev;
 	mt9v111->client = client;
 
-	mt9v111->clk = devm_clk_get(&client->dev, NULL);
+	mt9v111->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 	if (IS_ERR(mt9v111->clk))
-		return PTR_ERR(mt9v111->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(mt9v111->clk),
+				     "failed to get the clock\n");
 
 	mt9v111->sysclk = clk_get_rate(mt9v111->clk);
 	if (mt9v111->sysclk > MT9V111_MAX_CLKIN)
Signature · 1 line
2.49.0
#48 lore raw

PATCH v2 25/48 media: i2c: ov02a10: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov02a10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov02a10.c +1 -1
index 6c30e1a0d814..74fc0687c849 100644
@@ -885,7 +885,7 @@ static int ov02a10_probe(struct i2c_client *client)
 		ov02a10->fmt.code = MEDIA_BUS_FMT_SRGGB10_1X10;
 	}
 
-	ov02a10->eclk = devm_clk_get(dev, "eclk");
+	ov02a10->eclk = devm_v4l2_sensor_clk_get(dev, "eclk");
 	if (IS_ERR(ov02a10->eclk))
 		return dev_err_probe(dev, PTR_ERR(ov02a10->eclk),
 				     "failed to get eclk\n");
Signature · 1 line
2.49.0
#49 lore raw

PATCH v2 26/48 media: i2c: ov2659: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov2659.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2659.c +3 -2
index 06b7896c3eaf..79d7f760f6dc 100644
@@ -1437,9 +1437,10 @@ static int ov2659_probe(struct i2c_client *client)
 	ov2659->pdata = pdata;
 	ov2659->client = client;
 
-	ov2659->clk = devm_clk_get(&client->dev, "xvclk");
+	ov2659->clk = devm_v4l2_sensor_clk_get(&client->dev, "xvclk");
 	if (IS_ERR(ov2659->clk))
-		return PTR_ERR(ov2659->clk);
+		return dev_err_probe(&client->dev, PTR_ERR(ov2659->clk),
+				     "failed to get xvclk\n");
 
 	ov2659->xvclk_frequency = clk_get_rate(ov2659->clk);
 	if (ov2659->xvclk_frequency < 6000000 ||
Signature · 1 line
2.49.0
#50 lore raw

PATCH v2 27/48 media: i2c: ov2685: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov2685.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/i2c/ov2685.c +5 -5
index 9b8481b8dcd4..c435799514b9 100644
@@ -783,11 +783,11 @@ static int ov2685_probe(struct i2c_client *client)
 	ov2685->client = client;
 	ov2685->cur_mode = &supported_modes[0];
 
-	ov2685->xvclk = devm_clk_get(dev, "xvclk");
-	if (IS_ERR(ov2685->xvclk)) {
-		dev_err(dev, "Failed to get xvclk\n");
-		return -EINVAL;
-	}
+	ov2685->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk");
+	if (IS_ERR(ov2685->xvclk))
+		return dev_err_probe(dev, PTR_ERR(ov2685->xvclk),
+				     "Failed to get xvclk\n");
+
 	ret = clk_set_rate(ov2685->xvclk, OV2685_XVCLK_FREQ);
 	if (ret < 0) {
 		dev_err(dev, "Failed to set xvclk rate (24MHz)\n");
Signature · 1 line
2.49.0
#51 lore raw

PATCH v2 28/48 media: i2c: ov5640: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov5640.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/ov5640.c +4 -5
index 0dae0438aa80..08ca366a22d7 100644
@@ -3898,11 +3898,10 @@ static int ov5640_probe(struct i2c_client *client)
 					       ov5640_dvp_default_fmt;
 
 	/* get system clock (xclk) */
-	sensor->xclk = devm_clk_get(dev, "xclk");
-	if (IS_ERR(sensor->xclk)) {
-		dev_err(dev, "failed to get xclk\n");
-		return PTR_ERR(sensor->xclk);
-	}
+	sensor->xclk = devm_v4l2_sensor_clk_get(dev, "xclk");
+	if (IS_ERR(sensor->xclk))
+		return dev_err_probe(dev, PTR_ERR(sensor->xclk),
+				     "failed to get xclk\n");
 
 	sensor->xclk_freq = clk_get_rate(sensor->xclk);
 	if (sensor->xclk_freq < OV5640_XCLK_MIN ||
Signature · 1 line
2.49.0
#52 lore raw

PATCH v2 29/48 media: i2c: ov5645: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov5645.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5645.c +1 -1
index 004d0ee5c3f5..70b4cdb1b9af 100644
@@ -1044,7 +1044,7 @@ static int ov5645_probe(struct i2c_client *client)
 				     "invalid bus type, must be CSI2\n");
 
 	/* get system clock (xclk) */
-	ov5645->xclk = devm_clk_get(dev, NULL);
+	ov5645->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(ov5645->xclk))
 		return dev_err_probe(dev, PTR_ERR(ov5645->xclk),
 				     "could not get xclk");
Signature · 1 line
2.49.0
#53 lore raw

PATCH v2 30/48 media: i2c: ov5647: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov5647.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/ov5647.c +4 -5
index a727beb9d57e..e193fef4fced 100644
@@ -1398,11 +1398,10 @@ static int ov5647_probe(struct i2c_client *client)
 		}
 	}
 
-	sensor->xclk = devm_clk_get(dev, NULL);
-	if (IS_ERR(sensor->xclk)) {
-		dev_err(dev, "could not get xclk");
-		return PTR_ERR(sensor->xclk);
-	}
+	sensor->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
+	if (IS_ERR(sensor->xclk))
+		return dev_err_probe(dev, PTR_ERR(sensor->xclk),
+				     "could not get xclk\n");
 
 	xclk_freq = clk_get_rate(sensor->xclk);
 	if (xclk_freq != 25000000) {
Signature · 1 line
2.49.0
#54 lore raw

PATCH v2 31/48 media: i2c: ov5648: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov5648.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/ov5648.c +3 -3
index 4b86d2631bd1..8a3190bf73da 100644
@@ -2521,10 +2521,10 @@ static int ov5648_probe(struct i2c_client *client)
 
 	/* External Clock */
 
-	sensor->xvclk = devm_clk_get(dev, NULL);
+	sensor->xvclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(sensor->xvclk)) {
-		dev_err(dev, "failed to get external clock\n");
-		ret = PTR_ERR(sensor->xvclk);
+		ret = dev_err_probe(dev, PTR_ERR(sensor->xvclk),
+				    "failed to get external clock\n");
 		goto error_endpoint;
 	}
 
Signature · 1 line
2.49.0
#55 lore raw

PATCH v2 32/48 media: i2c: ov5695: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov5695.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/i2c/ov5695.c +5 -5
index 663eccdfea6a..fe7ad7b2c05a 100644
@@ -1264,11 +1264,11 @@ static int ov5695_probe(struct i2c_client *client)
 	ov5695->client = client;
 	ov5695->cur_mode = &supported_modes[0];
 
-	ov5695->xvclk = devm_clk_get(dev, "xvclk");
-	if (IS_ERR(ov5695->xvclk)) {
-		dev_err(dev, "Failed to get xvclk\n");
-		return -EINVAL;
-	}
+	ov5695->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk");
+	if (IS_ERR(ov5695->xvclk))
+		return dev_err_probe(dev, PTR_ERR(ov5695->xvclk),
+				     "Failed to get xvclk\n");
+
 	ret = clk_set_rate(ov5695->xvclk, OV5695_XVCLK_FREQ);
 	if (ret < 0) {
 		dev_err(dev, "Failed to set xvclk rate (24MHz)\n");
Signature · 1 line
2.49.0
#56 lore raw

PATCH v2 33/48 media: i2c: ov64a40: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov64a40.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov64a40.c +1 -1
index a5da4fe47e0b..d7a13e855a41 100644
@@ -3550,7 +3550,7 @@ static int ov64a40_probe(struct i2c_client *client)
 		return PTR_ERR(ov64a40->cci);
 	}
 
-	ov64a40->xclk = devm_clk_get(&client->dev, NULL);
+	ov64a40->xclk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 	if (IS_ERR(ov64a40->xclk))
 		return dev_err_probe(&client->dev, PTR_ERR(ov64a40->xclk),
 				     "Failed to get clock\n");
Signature · 1 line
2.49.0
#57 lore raw

PATCH v2 34/48 media: i2c: ov6650: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov6650.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/i2c/ov6650.c +4 -6
index 9c7627161142..3e37a6436aeb 100644
@@ -898,12 +898,10 @@ static int ov6650_video_probe(struct v4l2_subdev *sd)
 	u8 pidh, pidl, midh, midl;
 	int i, ret = 0;
 
-	priv->clk = devm_clk_get(&client->dev, NULL);
-	if (IS_ERR(priv->clk)) {
-		ret = PTR_ERR(priv->clk);
-		dev_err(&client->dev, "clk request err: %d\n", ret);
-		return ret;
-	}
+	priv->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
+	if (IS_ERR(priv->clk))
+		return dev_err_probe(&client->dev, PTR_ERR(priv->clk),
+				     "clk request err\n");
 
 	rate = clk_get_rate(priv->clk);
 	for (i = 0; rate && i < ARRAY_SIZE(ov6650_xclk); i++) {
Signature · 1 line
2.49.0
#58 lore raw

PATCH v2 35/48 media: i2c: ov7740: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov7740.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/media/i2c/ov7740.c +4 -7
index 1f1c0de8e510..632fb80469be 100644
@@ -1036,13 +1036,10 @@ static int ov7740_probe(struct i2c_client *client)
 	if (!ov7740)
 		return -ENOMEM;
 
-	ov7740->xvclk = devm_clk_get(&client->dev, "xvclk");
-	if (IS_ERR(ov7740->xvclk)) {
-		ret = PTR_ERR(ov7740->xvclk);
-		dev_err(&client->dev,
-			"OV7740: fail to get xvclk: %d\n", ret);
-		return ret;
-	}
+	ov7740->xvclk = devm_v4l2_sensor_clk_get(&client->dev, "xvclk");
+	if (IS_ERR(ov7740->xvclk))
+		return dev_err_probe(&client->dev, PTR_ERR(ov7740->xvclk),
+				     "OV7740: fail to get xvclk\n");
 
 	ret = ov7740_probe_dt(client, ov7740);
 	if (ret)
Signature · 1 line
2.49.0
#59 lore raw

PATCH v2 36/48 media: i2c: ov8856: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov8856.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/i2c/ov8856.c +4 -6
index 4b6874d2a104..b85051f053ff 100644
@@ -2274,12 +2274,10 @@ static int ov8856_get_hwcfg(struct ov8856 *ov8856, struct device *dev)
 		return ret;
 
 	if (!is_acpi_node(fwnode)) {
-		ov8856->xvclk = devm_clk_get(dev, "xvclk");
-		if (IS_ERR(ov8856->xvclk)) {
-			dev_err_probe(dev, PTR_ERR(ov8856->xvclk),
-				      "could not get xvclk clock\n");
-			return PTR_ERR(ov8856->xvclk);
-		}
+		ov8856->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk");
+		if (IS_ERR(ov8856->xvclk))
+			return dev_err_probe(dev, PTR_ERR(ov8856->xvclk),
+					     "could not get xvclk clock\n");
 
 		clk_set_rate(ov8856->xvclk, xvclk_rate);
 		xvclk_rate = clk_get_rate(ov8856->xvclk);
Signature · 1 line
2.49.0
#60 lore raw

PATCH v2 37/48 media: i2c: ov8858: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov8858.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov8858.c +1 -1
index 95f9ae794846..c1c6bea8a68b 100644
@@ -1877,7 +1877,7 @@ static int ov8858_probe(struct i2c_client *client)
 	if (!ov8858)
 		return -ENOMEM;
 
-	ov8858->xvclk = devm_clk_get(dev, "xvclk");
+	ov8858->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk");
 	if (IS_ERR(ov8858->xvclk))
 		return dev_err_probe(dev, PTR_ERR(ov8858->xvclk),
 				     "Failed to get xvclk\n");
Signature · 1 line
2.49.0
#61 lore raw

PATCH v2 38/48 media: i2c: ov8865: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov8865.c | 36 +++++-------------------------------
 1 file changed, 5 insertions(+), 31 deletions(-)
drivers/media/i2c/ov8865.c +5 -31
index 95ffe7536aa6..a5ea26337a76 100644
@@ -2956,7 +2956,6 @@ static int ov8865_probe(struct i2c_client *client)
 	struct ov8865_sensor *sensor;
 	struct v4l2_subdev *subdev;
 	struct media_pad *pad;
-	unsigned int rate = 0;
 	unsigned int i;
 	int ret;
 
@@ -3019,39 +3018,14 @@ static int ov8865_probe(struct i2c_client *client)
 
 	/* External Clock */
 
-	sensor->extclk = devm_clk_get(dev, NULL);
-	if (PTR_ERR(sensor->extclk) == -ENOENT) {
-		dev_info(dev, "no external clock found, continuing...\n");
-		sensor->extclk = NULL;
-	} else if (IS_ERR(sensor->extclk)) {
-		dev_err(dev, "failed to get external clock\n");
-		ret = PTR_ERR(sensor->extclk);
+	sensor->extclk = devm_v4l2_sensor_clk_get(dev, NULL);
+	if (IS_ERR(sensor->extclk)) {
+		ret = dev_err_probe(dev, PTR_ERR(sensor->extclk),
+				    "failed to get external clock\n");
 		goto error_endpoint;
 	}
 
-	/*
-	 * We could have either a 24MHz or 19.2MHz clock rate from either dt or
-	 * ACPI...but we also need to support the weird IPU3 case which will
-	 * have an external clock AND a clock-frequency property. Check for the
-	 * clock-frequency property and if found, set that rate if we managed
-	 * to acquire a clock. This should cover the ACPI case. If the system
-	 * uses devicetree then the configured rate should already be set, so
-	 * we can just read it.
-	 */
-	ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
-				       &rate);
-	if (!ret && sensor->extclk) {
-		ret = clk_set_rate(sensor->extclk, rate);
-		if (ret) {
-			dev_err_probe(dev, ret, "failed to set clock rate\n");
-			goto error_endpoint;
-		}
-	} else if (ret && !sensor->extclk) {
-		dev_err_probe(dev, ret, "invalid clock config\n");
-		goto error_endpoint;
-	}
-
-	sensor->extclk_rate = rate ? rate : clk_get_rate(sensor->extclk);
+	sensor->extclk_rate = clk_get_rate(sensor->extclk);
 
 	for (i = 0; i < ARRAY_SIZE(supported_extclk_rates); i++) {
 		if (sensor->extclk_rate == supported_extclk_rates[i])
Signature · 1 line
2.49.0
#62 lore raw

PATCH v2 39/48 media: i2c: ov9282: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov9282.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/media/i2c/ov9282.c +4 -5
index c882a021cf18..a9f6176e9729 100644
@@ -1135,11 +1135,10 @@ static int ov9282_parse_hw_config(struct ov9282 *ov9282)
 	}
 
 	/* Get sensor input clock */
-	ov9282->inclk = devm_clk_get(ov9282->dev, NULL);
-	if (IS_ERR(ov9282->inclk)) {
-		dev_err(ov9282->dev, "could not get inclk");
-		return PTR_ERR(ov9282->inclk);
-	}
+	ov9282->inclk = devm_v4l2_sensor_clk_get(ov9282->dev, NULL);
+	if (IS_ERR(ov9282->inclk))
+		return dev_err_probe(ov9282->dev, PTR_ERR(ov9282->inclk),
+				     "could not get inclk\n");
 
 	ret = ov9282_configure_regulators(ov9282);
 	if (ret)
Signature · 1 line
2.49.0
#63 lore raw

PATCH v2 40/48 media: i2c: ov9640: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov9640.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/ov9640.c +3 -2
index 01dbc0ba89c8..2190c52b1433 100644
@@ -718,9 +718,10 @@ static int ov9640_probe(struct i2c_client *client)
 
 	priv->subdev.ctrl_handler = &priv->hdl;
 
-	priv->clk = devm_clk_get(&client->dev, "mclk");
+	priv->clk = devm_v4l2_sensor_clk_get(&client->dev, "mclk");
 	if (IS_ERR(priv->clk)) {
-		ret = PTR_ERR(priv->clk);
+		ret = dev_err_probe(&client->dev, PTR_ERR(priv->clk),
+				    "failed to get mclk\n");
 		goto ectrlinit;
 	}
 
Signature · 1 line
2.49.0
#64 lore raw

PATCH v2 41/48 media: i2c: ov9650: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov9650.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/ov9650.c +3 -2
index 026ea34d6291..c94e8fe29f22 100644
@@ -1494,9 +1494,10 @@ static int ov965x_probe(struct i2c_client *client)
 	}
 
 	if (dev_fwnode(&client->dev)) {
-		ov965x->clk = devm_clk_get(&client->dev, NULL);
+		ov965x->clk = devm_v4l2_sensor_clk_get(&client->dev, NULL);
 		if (IS_ERR(ov965x->clk))
-			return PTR_ERR(ov965x->clk);
+			return dev_err_probe(&client->dev, PTR_ERR(ov965x->clk),
+					     "failed to get the clock\n");
 		ov965x->mclk_frequency = clk_get_rate(ov965x->clk);
 
 		ret = ov965x_configure_gpios(ov965x);
Signature · 1 line
2.49.0
#65 lore raw

PATCH v2 42/48 media: i2c: s5c73m3: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/s5c73m3/s5c73m3-core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/s5c73m3/s5c73m3-core.c +4 -2
index 7716dfe2b8c9..088184da5dea 100644
@@ -1556,9 +1556,11 @@ static int s5c73m3_get_dt_data(struct s5c73m3 *state)
 	if (!node)
 		return -EINVAL;
 
-	state->clock = devm_clk_get(dev, S5C73M3_CLK_NAME);
+	state->clock = devm_v4l2_sensor_clk_get(dev, S5C73M3_CLK_NAME);
 	if (IS_ERR(state->clock))
-		return PTR_ERR(state->clock);
+		return dev_err_probe(dev, PTR_ERR(state->clock),
+				     "Failed to get the clock %s\n",
+				     S5C73M3_CLK_NAME);
 
 	if (of_property_read_u32(node, "clock-frequency",
 				 &state->mclk_frequency)) {
Signature · 1 line
2.49.0
#66 lore raw

PATCH v2 43/48 media: i2c: s5k5baf: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/s5k5baf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/s5k5baf.c +1 -1
index 24f399cd2124..01d37f49e5ad 100644
@@ -1967,7 +1967,7 @@ static int s5k5baf_probe(struct i2c_client *c)
 	if (ret < 0)
 		goto err_me;
 
-	state->clock = devm_clk_get(state->sd.dev, S5K5BAF_CLK_NAME);
+	state->clock = devm_v4l2_sensor_clk_get(state->sd.dev, S5K5BAF_CLK_NAME);
 	if (IS_ERR(state->clock)) {
 		ret = -EPROBE_DEFER;
 		goto err_me;
Signature · 1 line
2.49.0
#67 lore raw

PATCH v2 44/48 media: i2c: s5k6a3: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/s5k6a3.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/s5k6a3.c +3 -2
index 0c2674115b7b..4bf5f122b113 100644
@@ -292,9 +292,10 @@ static int s5k6a3_probe(struct i2c_client *client)
 	mutex_init(&sensor->lock);
 	sensor->dev = dev;
 
-	sensor->clock = devm_clk_get(sensor->dev, S5K6A3_CLK_NAME);
+	sensor->clock = devm_v4l2_sensor_clk_get(sensor->dev, S5K6A3_CLK_NAME);
 	if (IS_ERR(sensor->clock))
-		return PTR_ERR(sensor->clock);
+		return dev_err_probe(sensor->dev, PTR_ERR(sensor->clock),
+				     "failed to get extclk\n");
 
 	sensor->gpio_reset = devm_gpiod_get(dev, NULL, GPIOD_OUT_HIGH);
 	ret = PTR_ERR_OR_ZERO(sensor->gpio_reset);
Signature · 1 line
2.49.0
#68 lore raw

PATCH v2 45/48 media: i2c: vd55g1: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/vd55g1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/vd55g1.c +1 -1
index 25e2fc88a036..693db225e04d 100644
@@ -1863,7 +1863,7 @@ static int vd55g1_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to get regulators\n");
 
-	sensor->xclk = devm_clk_get(dev, NULL);
+	sensor->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(sensor->xclk))
 		return dev_err_probe(dev, PTR_ERR(sensor->xclk),
 				     "Failed to get xclk\n");
Signature · 1 line
2.49.0
#69 lore raw

PATCH v2 46/48 media: i2c: vd56g3: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/vd56g3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/vd56g3.c +1 -1
index 5d951ad0b478..ac3e868dbb43 100644
@@ -1474,7 +1474,7 @@ static int vd56g3_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to get regulators\n");
 
-	sensor->xclk = devm_clk_get(dev, NULL);
+	sensor->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
 	if (IS_ERR(sensor->xclk))
 		return dev_err_probe(dev, PTR_ERR(sensor->xclk),
 				     "Failed to get xclk\n");
Signature · 1 line
2.49.0
#70 lore raw

PATCH v2 47/48 media: i2c: vgxy61: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

devm_clk_get() fails on ACPI-based platforms, where firmware does not provide a direct reference to the clock producer.

Replace devm_clk_get() with the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/vgxy61.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/i2c/vgxy61.c +5 -5
index 5b0479f3a3c0..3d001e0b646b 100644
@@ -1761,11 +1761,11 @@ static int vgxy61_probe(struct i2c_client *client)
 		return ret;
 	}
 
-	sensor->xclk = devm_clk_get(dev, NULL);
-	if (IS_ERR(sensor->xclk)) {
-		dev_err(dev, "failed to get xclk\n");
-		return PTR_ERR(sensor->xclk);
-	}
+	sensor->xclk = devm_v4l2_sensor_clk_get(dev, NULL);
+	if (IS_ERR(sensor->xclk))
+		return dev_err_probe(dev, PTR_ERR(sensor->xclk),
+				     "failed to get xclk\n");
+
 	sensor->clk_freq = clk_get_rate(sensor->xclk);
 	if (sensor->clk_freq < 6 * HZ_PER_MHZ ||
 	    sensor->clk_freq > 27 * HZ_PER_MHZ) {
Signature · 1 line
2.49.0
#71 lore raw

PATCH v2 48/48 media: i2c: ov2680: Use the v4l2 helper for obtaining the clock

In reply to Mehdi Djait

Use the new v4l2 helper devm_v4l2_sensor_clk_get() that works on both DT- and ACPI-based platforms to retrieve a reference to the clock producer from firmware.

---
 drivers/media/i2c/ov2680.c | 29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)
drivers/media/i2c/ov2680.c +2 -27
index 7237fb27ecd0..78e63bd1b35b 100644
@@ -1079,7 +1079,6 @@ static int ov2680_parse_dt(struct ov2680_dev *sensor)
 	struct device *dev = sensor->dev;
 	struct fwnode_handle *ep_fwnode;
 	struct gpio_desc *gpio;
-	unsigned int rate = 0;
 	int i, ret;
 
 	/*
@@ -1114,38 +1113,14 @@ static int ov2680_parse_dt(struct ov2680_dev *sensor)
 
 	sensor->pwdn_gpio = gpio;
 
-	sensor->xvclk = devm_clk_get_optional(dev, "xvclk");
+	sensor->xvclk = devm_v4l2_sensor_clk_get(dev, "xvclk");
 	if (IS_ERR(sensor->xvclk)) {
 		ret = dev_err_probe(dev, PTR_ERR(sensor->xvclk),
 				    "xvclk clock missing or invalid\n");
 		goto out_free_bus_cfg;
 	}
 
-	/*
-	 * We could have either a 24MHz or 19.2MHz clock rate from either DT or
-	 * ACPI... but we also need to support the weird IPU3 case which will
-	 * have an external clock AND a clock-frequency property. Check for the
-	 * clock-frequency property and if found, set that rate if we managed
-	 * to acquire a clock. This should cover the ACPI case. If the system
-	 * uses devicetree then the configured rate should already be set, so
-	 * we can just read it.
-	 */
-	ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
-				       &rate);
-	if (ret && !sensor->xvclk) {
-		dev_err_probe(dev, ret, "invalid clock config\n");
-		goto out_free_bus_cfg;
-	}
-
-	if (!ret && sensor->xvclk) {
-		ret = clk_set_rate(sensor->xvclk, rate);
-		if (ret) {
-			dev_err_probe(dev, ret, "failed to set clock rate\n");
-			goto out_free_bus_cfg;
-		}
-	}
-
-	sensor->xvclk_freq = rate ?: clk_get_rate(sensor->xvclk);
+	sensor->xvclk_freq = clk_get_rate(sensor->xvclk);
 
 	for (i = 0; i < ARRAY_SIZE(ov2680_xvclk_freqs); i++) {
 		if (sensor->xvclk_freq == ov2680_xvclk_freqs[i])
Signature · 1 line
2.49.0