From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Mehdi Djait <mehdi.djait@linux.intel.com>,
dave.stevenson@raspberrypi.com, linux-media@vger.kernel.org
Subject: Re: [PATCH] media: i2c: imx219: Add support for 'clock-frequency' parsing
Date: Mon, 24 Feb 2025 20:19:35 +0200 [thread overview]
Message-ID: <20250224181935.GC6778@pendragon.ideasonboard.com> (raw)
In-Reply-To: <Z7ynKZOIaUQUZVHn@kekkonen.localdomain>
On Mon, Feb 24, 2025 at 05:06:49PM +0000, Sakari Ailus wrote:
> Hi Laurent,
>
> On Mon, Feb 24, 2025 at 06:34:21PM +0200, Laurent Pinchart wrote:
> > On Mon, Feb 24, 2025 at 04:28:47PM +0000, Sakari Ailus wrote:
> > > On Mon, Feb 24, 2025 at 06:16:40PM +0200, Laurent Pinchart wrote:
> > > > On Mon, Feb 24, 2025 at 02:38:35PM +0000, Sakari Ailus wrote:
> > > > > On Mon, Feb 24, 2025 at 03:25:36PM +0200, Laurent Pinchart wrote:
> > > > > > On Mon, Feb 24, 2025 at 12:49:48PM +0000, Sakari Ailus wrote:
> > > > > > > On Mon, Feb 24, 2025 at 02:24:29PM +0200, Tomi Valkeinen wrote:
> > > > > > > > On 24/02/2025 13:54, Mehdi Djait wrote:
> > > > > > > > > On Mon, Feb 24, 2025 at 09:42:12AM +0000, Sakari Ailus wrote:
> > > > > > > > > > On Mon, Feb 24, 2025 at 08:59:34AM +0100, Mehdi Djait wrote:
> > > > > > > > > > > On Mon, Feb 24, 2025 at 01:06:49AM +0200, Laurent Pinchart wrote:
> > > > > > > > > > > > On Thu, Feb 20, 2025 at 04:49:09PM +0100, Mehdi Djait wrote:
> > > > > > > > > > > > > Make the clock producer reference lookup optional
> > > > > > > > > > > > >
> > > > > > > > > > > > > Add support for ACPI-based platforms by parsing the 'clock-frequency'
> > > > > > > > > > > > > property when no clock producer is available
> > > > > > > > > > > > >
> > > > > > > > > > > > > Signed-off-by: Mehdi Djait <mehdi.djait@linux.intel.com>
> > > > > > > > > > > > > ---
> > > > > > > > > > > > > drivers/media/i2c/imx219.c | 14 ++++++++++++--
> > > > > > > > > > > > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > > > > > > > > > > > > index 2d54cea113e1..a876a6d80a47 100644
> > > > > > > > > > > > > --- a/drivers/media/i2c/imx219.c
> > > > > > > > > > > > > +++ b/drivers/media/i2c/imx219.c
> > > > > > > > > > > > > @@ -1103,12 +1103,22 @@ 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_clk_get_optional(dev, NULL);
> > > > > > > > > > > > > if (IS_ERR(imx219->xclk))
> > > > > > > > > > > > > return dev_err_probe(dev, PTR_ERR(imx219->xclk),
> > > > > > > > > > > > > "failed to get xclk\n");
> > > > > > > > > > > > > - imx219->xclk_freq = clk_get_rate(imx219->xclk);
> > > > > > > > > > > > > + if (imx219->xclk) {
> > > > > > > > > > > > > + imx219->xclk_freq = clk_get_rate(imx219->xclk);
> > > > > > > > > > > > > + } else {
> > > > > > > > > > > > > + ret = fwnode_property_read_u32(dev_fwnode(dev),
> > > > > > > > > > > > > + "clock-frequency",
> > > > > > > > > > > > > + &imx219->xclk_freq);
> > > > > > > > > > > > > + if (ret)
> > > > > > > > > > > > > + return dev_err_probe(dev, ret,
> > > > > > > > > > > > > + "failed to get clock frequency");
> > > > > > > > > > > > > + }
> > > > > > > > > > > > > +
> > > > > > > > > > > >
> > > > > > > > > > > > This doesn't seem specific to the imx219 driver. Could you turn this
> > > > > > > > > > > > into a generic V4L2 sensor helper that would take a struct device and a
> > > > > > > > > > > > clock name, and return the frequency, either retrieved from the clock,
> > > > > > > > > > > > or from the clock-frequency property as a fallback ?
> > > > > > > > > > > >
> > > > > > > > > > > > Some drivers will also need to control the clock, so the clock should
> > > > > > > > > > > > probably be returned too.
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Yes, I saw that many sensor drivers have the same issue.
> > > > > > > > > > >
> > > > > > > > > > > I will try to make it into a generic V4L2 helper and send the patches.
> > > > > > > > > >
> > > > > > > > > > There are other such functions in drivers/media/v4l2-core/v4l2-common.c.
> > > > > > > > > > Perhaps this is where the new helper could be located as well?
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > > I was thinking about drivers/media/v4l2-core/v4l2-fwnode.c but if
> > > > > > > > > v4l2-common.c is more appropriate we can go with that.
> > > > > > > >
> > > > > > > > I admit I have no clue about ACPI, but why is this v4l2 specific? Why
> > > > > > > > doesn't clock framework do this for us?
> > > > > > >
> > > > > > > The "clock-frequency" isn't really specific to ACPI but it's used on some
> > > > > > > boards with DT, too, that precede the current clock bindings. Clocks aren't
> > > > > > > generally available to OS in ACPI either but the sensor drivers still need
> > > > > > > them. DisCo for Imaging uses "mipi-img-clock-frequency" which DisCo for
> > > > > > > Imaging code deep down in the ACPI framework will offer to drivers as
> > > > > > > "clock-frequency". A lot of this is actually specific to cameras. On top of
> > > > > > > that, camera sensors tend to be devices that are used equally on both DT
> > > > > > > and ACPI systems, it's quite uncommon elsewhere. Therefore I do think the
> > > > > > > natural place for this code is actually the V4L2 framework.
> > > > > >
> > > > > > Can ACPI devices support programmable sensor clock frequency ?
> > > > >
> > > > > Do you mean sensor's external clock or PLL? And do you mean programmable
> > > > > as configured in system firmware or at runtime?
> > > >
> > > > I mean external clock, and configurable at runtime.
> > >
> > > There's basically no standard API to change a clock's frequency at runtime
> > > (as there is no API to handle clocks) -- which is why we have a property
> > > instead of that presumed API.
> >
> > I wonder, for ACPI devices that have a clock-frequency property, could
> > we automatically register a fixed-frequency clock ?
>
> That's an interesting idea.
>
> It still could have potential to break something even if it may be
> unlikely. I don't know what others are doing with clocks (if anything)
> outside cameras on ACPI.
>
> Maybe a case for an RFC? Doing this would be nice as we could get rid of
> one of the few remaining DT/ACPI differences in sensor drivers.
>
> That being said, this should not hold back merging the patch.
An RFC sounds good. For this specific patch, I think we agree we need a
helper function. I wonder if the helper could register a fixed clock if
there's no clocks property, that way we could easily change the
implementation later while minimizing changes to drivers. Some sort of
struct clk *devm_v4l2_sensor_clk_get(struct device *dev, const char *name);
that sensor drivers would call instead of devm_clk_get(). There may be
issues I don't foresee though, but maybe worth trying ?
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2025-02-24 18:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 15:49 [PATCH] media: i2c: imx219: Add support for 'clock-frequency' parsing Mehdi Djait
2025-02-23 23:06 ` Laurent Pinchart
2025-02-24 7:59 ` Mehdi Djait
2025-02-24 9:42 ` Sakari Ailus
2025-02-24 11:54 ` Mehdi Djait
2025-02-24 12:24 ` Sakari Ailus
2025-02-24 12:24 ` Tomi Valkeinen
2025-02-24 12:49 ` Sakari Ailus
2025-02-24 13:25 ` Laurent Pinchart
2025-02-24 14:38 ` Sakari Ailus
2025-02-24 16:16 ` Laurent Pinchart
2025-02-24 16:28 ` Sakari Ailus
2025-02-24 16:34 ` Laurent Pinchart
2025-02-24 17:06 ` Sakari Ailus
2025-02-24 18:19 ` Laurent Pinchart [this message]
2025-02-24 18:28 ` Mehdi Djait
2025-02-25 11:11 ` Mehdi Djait
2025-02-25 11:43 ` Sakari Ailus
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=20250224181935.GC6778@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=linux-media@vger.kernel.org \
--cc=mehdi.djait@linux.intel.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.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