lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250619220723.GU22102@pendragon.ideasonboard.com>
Date: Fri, 20 Jun 2025 01:07:23 +0300
From: Laurent Pinchart <laurent.pinchart@...asonboard.com>
To: Mehdi Djait <mehdi.djait@...ux.intel.com>
Cc: sakari.ailus@...ux.intel.com, akinobu.mita@...il.com,
	stanislaw.gruszka@...ux.intel.com, hdegoede@...hat.com,
	arnd@...db.de, alain.volmat@...s.st.com, andrzej.hajda@...el.com,
	benjamin.mugnier@...s.st.com, dave.stevenson@...pberrypi.com,
	hansg@...nel.org, hverkuil@...all.nl, jacopo.mondi@...asonboard.com,
	jonas@...boo.se, kieran.bingham@...asonboard.com, khalasa@...p.pl,
	prabhakar.csengg@...il.com, mani@...nel.org,
	m.felsch@...gutronix.de, martink@...teo.de, mattwmajewski@...il.com,
	matthias.fend@...end.at, mchehab@...nel.org,
	michael.riesch@...labora.com, naush@...pberrypi.com,
	nicholas@...hemail.net, nicolas.dufresne@...labora.com,
	paul.elder@...asonboard.com, dan.scally@...asonboard.com,
	pavel@...nel.org, petrcvekcz@...il.com, rashanmu@...il.com,
	ribalda@...omium.org, rmfrfs@...il.com, zhengsq@...k-chips.com,
	slongerbeam@...il.com, sylvain.petinot@...s.st.com,
	s.nawrocki@...sung.com, tomi.valkeinen@...asonboard.com,
	umang.jain@...asonboard.com, zhi.mao@...iatek.com,
	linux-kernel@...r.kernel.org, linux-media@...r.kernel.org
Subject: Re: [PATCH v1 01/55] media: v4l2-common: Add a helper for obtaining
 the clock producer

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@...ux.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@...asonboard.com>

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

-- 
Regards,

Laurent Pinchart

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ