mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Mehdi Djait <mehdi.djait@linux.intel.com>
Cc: sakari.ailus@linux.intel.com, akinobu.mita@gmail.com,
	stanislaw.gruszka@linux.intel.com, hdegoede@redhat.com,
	arnd@arndb.de, alain.volmat@foss.st.com, andrzej.hajda@intel.com,
	benjamin.mugnier@foss.st.com, dave.stevenson@raspberrypi.com,
	hansg@kernel.org, hverkuil@xs4all.nl,
	jacopo.mondi@ideasonboard.com, jonas@kwiboo.se,
	kieran.bingham@ideasonboard.com, khalasa@piap.pl,
	prabhakar.csengg@gmail.com, mani@kernel.org,
	m.felsch@pengutronix.de, martink@posteo.de,
	mattwmajewski@gmail.com, matthias.fend@emfend.at,
	mchehab@kernel.org, michael.riesch@collabora.com,
	naush@raspberrypi.com, nicholas@rothemail.net,
	nicolas.dufresne@collabora.com, paul.elder@ideasonboard.com,
	dan.scally@ideasonboard.com, pavel@kernel.org,
	petrcvekcz@gmail.com, rashanmu@gmail.com, ribalda@chromium.org,
	rmfrfs@gmail.com, zhengsq@rock-chips.com, slongerbeam@gmail.com,
	sylvain.petinot@foss.st.com, s.nawrocki@samsung.com,
	tomi.valkeinen@ideasonboard.com, umang.jain@ideasonboard.com,
	zhi.mao@mediatek.com, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH v1 01/55] media: v4l2-common: Add a helper for obtaining the clock producer
Date: Fri, 20 Jun 2025 01:07:23 +0300	[thread overview]
Message-ID: <20250619220723.GU22102@pendragon.ideasonboard.com> (raw)
In-Reply-To: <1f8a0bb1896a57e818fad30a236b350127689be6.1750352394.git.mehdi.djait@linux.intel.com>

Hi Mehdi,

Thank you for the patch.

On Thu, Jun 19, 2025 at 07:58:54PM +0200, Mehdi Djait wrote:
> 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 clk_get_optional() except where there is

It actually behaves like devm_clk_get(). The _optional variant returns
NULL when the clok is not found, while the helper here return
ERR_PTR(-ENOENT).

> 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.
> 
> Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com>
> 
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index bd160a8c9efe..c53221165c5a 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -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,49 @@ 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 acpi_node;
> +	u32 rate;
> +	int ret;
> +
> +	clk = devm_clk_get_optional(dev, id);
> +	ret = device_property_read_u32(dev, "clock-frequency", &rate);
> +	acpi_node = is_acpi_node(dev_fwnode(dev));
> +
> +	if (clk) {
> +		if (!ret && acpi_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 (ret)
> +		return ERR_PTR(ret);
> +
> +	if (!IS_ENABLED(CONFIG_COMMON_CLK) || !acpi_node)
> +		return ERR_PTR(-ENOENT);
> +
> +	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);
> diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
> index 0a43f56578bc..72d8fcc6057f 100644
> --- a/include/media/v4l2-common.h
> +++ b/include/media/v4l2-common.h
> @@ -620,6 +620,31 @@ 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 an optional clock
> + *			      producer for a camera sensor.
> + *
> + * @dev: device for v4l2 sensor clock "consumer"
> + * @id: clock consumer ID
> + *
> + * This function behaves the same way as clk_get_optional() except where there

s/clk_get_optional/devm_clk_get/

> + * 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.

 * 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.

to get proper formatting in the generated documentation.

> + *
> + * Return:
> + * * pointer to a struct clk on success or an error code on failure.

 * 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);
> +

Please add a forward declaration of struct clk towards the top of the
file, with the other forwar declarations.

With those small issues fixed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
>  {
>  	/*

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2025-06-19 22:07 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19 17:58 [PATCH v1 00/55] media: " Mehdi Djait
2025-06-19 17:58 ` [PATCH v1 01/55] media: v4l2-common: " Mehdi Djait
2025-06-19 22:07   ` Laurent Pinchart [this message]
2025-06-19 17:58 ` [PATCH v1 02/55] Documentation: media: camera-sensor: Mention v4l2_devm_sensor_clk_get() for obtaining the clock Mehdi Djait
2025-06-19 21:47   ` Laurent Pinchart
2025-06-23 10:49     ` Sakari Ailus
2025-06-19 17:58 ` [PATCH v1 03/55] media: i2c: ar0521: Use the v4l2 helper " Mehdi Djait
2025-06-21 10:21   ` Krzysztof Hałasa | Łukasiewicz – PIAP
2025-06-19 17:58 ` [PATCH v1 04/55] media: i2c: ds90ub913: " Mehdi Djait
2025-06-19 17:58 ` [PATCH v1 05/55] media: i2c: ds90ub960: " Mehdi Djait
2025-06-19 17:58 ` [PATCH v1 06/55] media: i2c: et8ek8: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 07/55] media: i2c: gc05a2: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 08/55] media: i2c: gc08a3: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 09/55] media: i2c: gc2145: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 10/55] media: i2c: hi846: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 11/55] media: i2c: imx214: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 12/55] media: i2c: imx219: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 13/55] media: i2c: imx283: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 14/55] media: i2c: imx290: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 15/55] media: i2c: imx296: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 16/55] media: i2c: imx334: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 17/55] media: i2c: imx335: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 18/55] media: i2c: imx412: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 19/55] media: i2c: imx415: " Mehdi Djait
2025-06-21 14:23   ` Michael Riesch
2025-06-19 17:59 ` [PATCH v1 20/55] media: i2c: max2175: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 21/55] media: i2c: mt9m001: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 22/55] media: i2c: mt9m111: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 23/55] media: i2c: mt9m114: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 24/55] media: i2c: mt9p031: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 25/55] media: i2c: mt9t112: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 26/55] media: i2c: mt9v032: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 27/55] media: i2c: mt9v111: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 28/55] media: i2c: ov02a10: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 29/55] media: i2c: ov2659: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 30/55] media: i2c: ov2685: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 31/55] media: i2c: ov5640: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 32/55] media: i2c: ov5645: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 33/55] media: i2c: ov5647: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 34/55] media: i2c: ov5648: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 35/55] media: i2c: ov5695: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 36/55] media: i2c: ov64a40: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 37/55] media: i2c: ov6650: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 38/55] media: i2c: ov7740: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 39/55] media: i2c: ov8856: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 40/55] media: i2c: ov8858: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 41/55] media: i2c: ov8865: " Mehdi Djait
2025-06-19 21:57   ` Laurent Pinchart
2025-06-19 21:59     ` Laurent Pinchart
2025-06-21  7:58       ` Sakari Ailus
2025-06-21  8:27         ` Hans de Goede
2025-06-19 17:59 ` [PATCH v1 42/55] media: i2c: ov9282: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 43/55] media: i2c: ov9640: " Mehdi Djait
2025-06-19 17:59 ` [PATCH v1 44/55] media: i2c: ov9650: " Mehdi Djait
2025-06-19 18:09 ` [PATCH v1 45/55] media: i2c: s5c73m3: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 46/55] media: i2c: s5k5baf: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 47/55] media: i2c: s5k6a3: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 48/55] media: i2c: st-mipid02: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 50/55] media: i2c: tc358746: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 51/55] media: i2c: thp7312: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 52/55] media: i2c: vd55g1: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 53/55] media: i2c: vd56g3: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 54/55] media: i2c: vgxy61: " Mehdi Djait
2025-06-19 18:11 ` [PATCH v1 55/55] media: i2c: ov2680: " Mehdi Djait
2025-06-19 22:00   ` Laurent Pinchart
2025-06-19 18:15 ` [PATCH v1 49/55] media: i2c: tc358743: " Mehdi Djait
2025-06-19 21:26 ` [PATCH v1 00/55] media: Add a helper for obtaining the clock producer Laurent Pinchart
2025-06-21 14:28 ` Michael Riesch
2025-06-22 11:45   ` Hans de Goede
2025-06-24 20:34 ` Lad, Prabhakar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250619220723.GU22102@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=akinobu.mita@gmail.com \
    --cc=alain.volmat@foss.st.com \
    --cc=andrzej.hajda@intel.com \
    --cc=arnd@arndb.de \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=hansg@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=jonas@kwiboo.se \
    --cc=khalasa@piap.pl \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.felsch@pengutronix.de \
    --cc=mani@kernel.org \
    --cc=martink@posteo.de \
    --cc=matthias.fend@emfend.at \
    --cc=mattwmajewski@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=mehdi.djait@linux.intel.com \
    --cc=michael.riesch@collabora.com \
    --cc=naush@raspberrypi.com \
    --cc=nicholas@rothemail.net \
    --cc=nicolas.dufresne@collabora.com \
    --cc=paul.elder@ideasonboard.com \
    --cc=pavel@kernel.org \
    --cc=petrcvekcz@gmail.com \
    --cc=prabhakar.csengg@gmail.com \
    --cc=rashanmu@gmail.com \
    --cc=ribalda@chromium.org \
    --cc=rmfrfs@gmail.com \
    --cc=s.nawrocki@samsung.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=slongerbeam@gmail.com \
    --cc=stanislaw.gruszka@linux.intel.com \
    --cc=sylvain.petinot@foss.st.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    --cc=umang.jain@ideasonboard.com \
    --cc=zhengsq@rock-chips.com \
    --cc=zhi.mao@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®