[PATCH v7 2/5] i2c: mux: add support for per channel bus frequency

Andy Shevchenko andriy.shevchenko at intel.com
Mon Feb 23 06:57:47 PST 2026


On Mon, Feb 23, 2026 at 03:33:51PM +0100, Marcus Folkesson wrote:
> There may be several reasons why you may need to use a certain speed
> on an I2C bus. E.g.
> 
> - When several devices are attached to the bus, the speed must be
>   selected according to the slowest device.
> 
> - Electrical conditions may limit the usuable speed on the bus for
>   different reasons.
> 
> With an I2C multiplexer, it is possible to group the attached devices
> after their preferred speed by e.g. put all "slow" devices on a separate
> channel on the multiplexer.
> 
> Consider the following topology:
> 
>                       .----------. 100kHz .--------.
>     .--------. 400kHz |          |--------| dev D1 |
>     |  root  |--+-----| I2C MUX  |        '--------'
>     '--------'  |     |          |--. 400kHz .--------.
>                 |     '----------'  '-------| dev D2 |
>                 |  .--------.               '--------'
>                 '--| dev D3 |
>                    '--------'
> 
> One requirement with this design is that a multiplexer may only use the
> same or lower bus speed as its parent.
> Otherwise, if the multiplexer would have to increase the bus frequency,
> then all siblings (D3 in this case) would run into a clock speed it may
> not support.
> 
> The bus frequency for each channel is set in the devicetree. As the
> i2c-mux bindings import the i2c-controller schema, the clock-frequency
> property is already allowed.
> If no clock-frequency property is set, the channel inherit their parent
> bus speed.
> 
> The following example uses dt bindings to illustrate the topology above:
> 
>     i2c {
> 	clock-frequency = <400000>;
> 
>         i2c-mux {
>             i2c at 0 {
>                 clock-frequency = <100000>;
> 
>                 D1 {
>                     ...
>                 };
>             };
> 
>             i2c at 1 {
>                 D2 {
>                   ...
>                 };
>             };
>         };
> 
>         D3 {
>             ...
>         }
>     };

...

> +static int i2c_mux_select_chan(struct i2c_adapter *adap, u32 chan_id, u32 *oldclock)
> +{
> +	struct i2c_mux_priv *priv = adap->algo_data;
> +	struct i2c_mux_core *muxc = priv->muxc;
> +	struct i2c_adapter *parent = muxc->parent;
> +	int ret;
> +
> +	if (priv->adap.clock_hz && priv->adap.clock_hz < parent->clock_hz) {
> +		*oldclock = parent->clock_hz;
> +
> +		if (muxc->mux_locked)
> +			ret = i2c_adapter_set_clk_freq(parent, priv->adap.clock_hz);
> +		else
> +			ret = __i2c_adapter_set_clk_freq(parent, priv->adap.clock_hz);
> +
> +		dev_dbg(&adap->dev, "Set clock frequency %dHz on %s\n",
> +			priv->adap.clock_hz, parent->name);

%u

> +		if (ret)
> +			dev_err(&adap->dev,
> +				"Failed to set clock frequency %dHz on adapter %s: %d\n",
> +				*oldclock, parent->name, ret);

%u

Oh, and so on...

Please, carefully inspect all printf() specifiers in the patches.

> +	}
> +
> +	return muxc->select(muxc, priv->chan_id);
> +}

-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list