i2c: mux: Add register map based mux driver
Subsystems (2)
PATCH v2 1/1 i2c: mux: Add register map based mux driver
Add 'regmap' mux driver to allow virtual bus switching by setting a single selector register.
The 'regmap' is supposed to be passed to driver within a platform data by parent platform driver.
Unlike i2c-mux-reg, this driver relies on regmap abstraction instead of direct MMIO access, allowing the mux selector register to be accessed through arbitrary transport mechanisms supported by regmap callbacks, including indirect PCIe-to-SPI and PCIe-to-LPC transactions.
The regmap instance is expected to be provided through platform data by the parent platform driver.
Motivation is to support mux selector registers accessed indirectly through transport-specific protocols.
For example, an FPGA connected through PCIe may expose SPI or LPC bridges used to access downstream CPLDs or secondary FPGAs located on another board. In such configurations the mux selector register is not directly memory-mapped and access is performed through regmap reg_read()/reg_write() callbacks implementing the required indirect transaction protocol.
---
v2:
- Initialize mux to NULL to avoid uninitialized warning reported by kernel test robot.
Note:
Originally proposed in 2023:
https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/
Reworked against current upstream.
--- drivers/i2c/muxes/Kconfig | 12 ++ drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-regmap.c | 150 +++++++++++++++++++ include/linux/platform_data/i2c-mux-regmap.h | 37 +++++ 4 files changed, 200 insertions(+) create mode 100644 drivers/i2c/muxes/i2c-mux-regmap.c create mode 100644 include/linux/platform_data/i2c-mux-regmap.h
drivers/i2c/muxes/Kconfig +12 -0
@@ -99,6 +99,18 @@ config I2C_MUX_REG This driver can also be built as a module. If so, the module will be called i2c-mux-reg. +config I2C_MUX_REGMAP + tristate "Register map based I2C multiplexer" + depends on REGMAP + help + If you say yes to this option, support will be included for a + register map based I2C multiplexer. This driver provides access to + I2C busses connected through a MUX, which is controlled + by a single register through the regmap. + + This driver can also be built as a module. If so, the module + will be called i2c-mux-regmap. + config I2C_DEMUX_PINCTRL tristate "pinctrl-based I2C demultiplexer" depends on PINCTRL && OF
drivers/i2c/muxes/Makefile +1 -0
@@ -15,5 +15,6 @@ obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o obj-$(CONFIG_I2C_MUX_REG) += i2c-mux-reg.o +obj-$(CONFIG_I2C_MUX_REGMAP) += i2c-mux-regmap.o ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
drivers/i2c/muxes/i2c-mux-regmap.c new file +150 -0
150 lines not on this page · raw message
include/linux/platform_data/i2c-mux-regmap.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* +* Regmap i2c mux driver +* +* Copyright (C) 2026 Nvidia Technologies Ltd. +*/ + +#ifndef __LINUX_PLATFORM_DATA_I2C_MUX_REGMAP_H +#define __LINUX_PLATFORM_DATA_I2C_MUX_REGMAP_H + +/** +* struct i2c_mux_regmap_platform_data - Platform-dependent data for i2c-mux-regmap +* @regmap: register map of parent device; +* @parent: Parent I2C bus adapter number +* @chan_ids: channels array +* @num_adaps: number of adapters +* @sel_reg_addr: mux select register offset in CPLD/FPGA space +* @handle: handle to be passed by callback +* @completion_notify: callback invoked after all child adapters are +* created. May also be invoked once with @adapters set to NULL if +* probe fails after parent adapter acquisition, so waiters can +* unblock. +* The adapters array is owned by mux core, remains valid until mux +* removal, and contains @num_adaps entries. +*/ +struct i2c_mux_regmap_platform_data { +struct regmap *regmap; +int parent; +const unsigned int *chan_ids; +int num_adaps; +int sel_reg_addr; +void *handle; +int (*completion_notify)(void *handle,struct i2c_adapter *parent, +struct i2c_adapter *adapters[]); +}; + +#endif /* __LINUX_PLATFORM_DATA_I2C_MUX_REGMAP_H */
Signature · 1 line
2.34.1