Re: [PATCH v12 1/7] i2c: core: add callback to change bus frequency
Marcus Folkesson <[email protected]> Thu, 23 Jul 2026 13:36:29 +0200
| Newsgroups | org.kernel.vger.linux-i2c,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Hi Peter!
On Thu, Jul 23, 2026 at 01:03:53PM +0200, Peter Rosin wrote:
> > + *
> > + * @set_clk_freq: Set clock frequency for the adapter. Returns the actual set frequency.
> > + * This function is optional.
> > */
> > struct i2c_adapter {
> > struct module *owner;
> > @@ -742,6 +745,8 @@ struct i2c_adapter {
> > struct rt_mutex mux_lock;
> >
> > int timeout; /* in jiffies */
> > + u32 clock_Hz; /* bus clock speed */
> > + int (*set_clk_freq)(struct i2c_adapter *adap, u32 clock_Hz); /* Optional */
>
> To expand on the comment from v9 by Wolfram [1], I too think it
> would be good if this function pointer did not live directly in
> i2c_adapter but instead in some other struct so that the actual
> pointer could live in read-only memory. I.e. if i2c_algorithm
> does not fit for some reason, a new function pointer struct might
> be called for?
My objection to move it to i2c_algorithm, was mostly based on that the
algorithm should not be aware of the current clock frequency. When I
reread the comment from Wolfram (and you), I realize that we are only
talking about the function pointer, which is fine to put into the
i2c_algorithm struct.
Sorry for the misinterpretation, I will move the pointer to
i2c_algorithm and keep clock_Hz in i2c_adapter.
>
> Also, returning int instead of unsigned hints that the function
> might return a negative error code, but the new code in 3/7 does
> not handle errors. So, either change to unsigned int, or update
> the support code in 3/7 to handle errors. I think the latter is
> the better approach.
Agree, thanks.
>
> Cheers,
> Peter
>
> [1] https://lore.kernel.org/all/ahX44_rzaRlTLSLU@shikoro/
>
> > int retries;
> > struct device dev; /* the adapter device */
> > unsigned long locked_flags; /* owned by the I2C core */
> >
>
Best regards,
Marcus Folkesson
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEBVGi6LZstU1kwSxliIBOb1ldUjIFAmph/LgACgkQiIBOb1ld UjImNA//dFlLVBf+3iuSWVyzi5/TaqJrTyo993+vC/Iq8vZPYcabFRIM7vl7+adb +df/fj8ph8NtPZAmGiaq+da6i6bKEdVowVEgrD/sactK6PRAcxFxeNMdHpKgsaY7 HnOAf8YEFcwjZ0QPoQimY5Idh/Qv0NTw8Pf7iPIvPfFxBuwVKT5XDB2ncoccxjMW ezPMdzk3sBED7xPcys/Z6Qeh41EdP4ez2uRfWdDaPBBJ94kEY3LTuEDX0oCnIoCS y7MBafA2mqwT1bAuZYKOAqBCzqgkx9oiGN9gWH7DWrPpj8l7sGO3BcsPzJ0JlFNo VabrYsyPA84qPo3Z6ZAb9uRbnrIlVmr+3sfAmBJfJ//1uSRfY3RWqelps7XZrt6d oO0NX19S1rXeChsLEcT+YfCGXE2a3Jdnsy53PDvCduUaVyUs/euPjMacICzOfbQm Hbv5fUTEq+rej6BmwBpAcQxaap0liwf4qBF7vzgKJIxpsMa826qM83q7x4fbhUgn Ph/2jvBQFX0v5vdME4J18smKjXQalggtU9dxREWJ/cQ42JYh7eG5iaTD8wr+7K4y Ing9Tm5Y5kRBUAs3oRvgyAoPQkpxQagvaqJ7H0fzDNTF5djqX4F7h14uk+zB2XOm qDrt7QPJNmHqdzSBAj5okLUlhMIp9mFuMiAPlCc920QS2yfBSms= =nf2D -----END PGP SIGNATURE-----