[PATCH v13 1/8] i2c: core: add callback to change bus frequency

From: Marcus Folkesson

Date: Thu Oct 15 2026 - 07:03:20 EST


All devices on the same I2C bus share the same clock line and the bus
frequency must therefore be chosen so that all attached devices are able
to tolerate that clock rate. IOW, the bus speed must be set for the
slowest attached device.

With I2C multiplexers/switches on the other hand, it would be possible
to have different "domains" that run with different speeds.

Prepare for such a feature by providing an optional callback function to
change bus frequency.

As a side effect, several bus drivers keep the bus speed in a
private structure and can now have this value stored in a uniform way
instead.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
Signed-off-by: Marcus Folkesson <marcus.folkesson@xxxxxxxxx>
---
include/linux/i2c.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 6a847fc88d25..d2d60e937244 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -635,6 +635,15 @@ struct i2c_timings {
u32 analog_filter_cutoff_freq_hz;
};

+/**
+ * struct i2c_bus_ops - I2C bus control operations
+ * @set_clk_freq: Set clock frequency for the adapter.
+ * Returns negative errno, or 0 on success.
+ */
+struct i2c_bus_ops {
+ int (*set_clk_freq)(struct i2c_adapter *adap, u32 clock_Hz);
+};
+
/**
* struct i2c_bus_recovery_info - I2C bus recovery information
* @recover_bus: Recover routine. Either pass driver's recover_bus() routine, or
@@ -744,6 +753,7 @@ struct i2c_adapter_quirks {
/*
* i2c_adapter is the structure used to identify a physical i2c bus along
* with the access algorithms necessary to access it.
+ *
*/
struct i2c_adapter {
struct module *owner;
@@ -760,6 +770,7 @@ struct i2c_adapter {
#ifdef CONFIG_I2C_DYNAMIC_TIMEOUT
int user_timeout; /* I2C_TIMEOUT ioctl value in jiffies */
#endif
+ u32 clock_Hz; /* bus clock speed */
int retries;
struct device dev; /* the adapter device */
unsigned long locked_flags; /* owned by the I2C core */
@@ -774,6 +785,7 @@ struct i2c_adapter {
struct list_head userspace_clients;

struct i2c_bus_recovery_info *bus_recovery_info;
+ const struct i2c_bus_ops *bus_ops;
const struct i2c_adapter_quirks *quirks;

struct irq_domain *host_notify_domain;

--
2.55.0