i2c: mux: Add register map based mux driver
Subsystems (2)
PATCH 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 register may reside on any bus type or mapped memory, supported by 'regmap' infrastructure.
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.
---
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
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Vadim,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20260519]
url: https://github.com/intel-lab-lkp/linux/commits/Vadim-Pasternak/i2c-mux-Add-register-map-based-mux-driver/20260520-014530 base: next-20260519 patch link: https://lore.kernel.org/r/20260519174310.1128423-1-vadimp%40nvidia.com patch subject: [PATCH i2c-mux next 1/1] i2c: mux: Add register map based mux driver config: hexagon-randconfig-r061-20260520 (https://download.01.org/0day-ci/archive/20260520/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260520/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/i2c/muxes/i2c-mux-regmap.c:121:44: warning: variable 'mux' is uninitialized when used here [-Wuninitialized]
121 | i2c_mux_regmap_notify_probe_abandon(pdev, mux, muxc, parent, ret,
| ^~~
drivers/i2c/muxes/i2c-mux-regmap.c:72:28: note: initialize the variable 'mux' to silence this warning
72 | struct i2c_mux_regmap *mux;
| ^
| = NULL1 warning generated.
vim +/mux +121 drivers/i2c/muxes/i2c-mux-regmap.c
67
68 /* Probe/remove functions */
69 static int i2c_mux_regmap_probe(struct platform_device *pdev)
70 {
71 struct i2c_mux_regmap_platform_data *pdata = dev_get_platdata(&pdev->dev);
72 struct i2c_mux_regmap *mux;
73 struct i2c_adapter *parent;
74 struct i2c_mux_core *muxc = NULL;
75 bool user_notify_called = false;
76 int num, ret;
77
78 if (!pdata)
79 return -EINVAL;
80
81 parent = i2c_get_adapter(pdata->parent);
82 if (!parent)
83 return -EPROBE_DEFER;
84
85 muxc = i2c_mux_alloc(parent, &pdev->dev, pdata->num_adaps, sizeof(*mux), 0,
86 i2c_mux_regmap_select_chan, i2c_mux_regmap_deselect);
87 if (!muxc) {
88 ret = -ENOMEM;
89 goto err_put_parent;
90 }
91
92 mux = i2c_mux_priv(muxc);
93 memcpy(&mux->pdata, pdata, sizeof(*pdata));
94 platform_set_drvdata(pdev, muxc);
95 mux->last_val = -1; /* force the first selection */
96
97 /* Create an adapter for each channel. */
98 for (num = 0; num < pdata->num_adaps; num++) {
99 ret = i2c_mux_add_adapter(muxc, 0, pdata->chan_ids[num]);
100 if (ret)
101 goto err_i2c_mux_add_adapter;
102 }
103
104 /* Notify caller when all channels' adapters are created. */
105 if (pdata->completion_notify) {
106 ret = pdata->completion_notify(pdata->handle, muxc->parent,
107 muxc->adapter);
108 user_notify_called = true;
109 if (ret)
110 goto err_i2c_mux_add_adapter;
111 }
112
113 return 0;
114
115 err_i2c_mux_add_adapter:
116 i2c_mux_regmap_notify_probe_abandon(pdev, mux, muxc, parent, ret,
117 user_notify_called);
118 i2c_mux_del_adapters(muxc);
119 goto put_parent;
120 err_put_parent:
> 121 i2c_mux_regmap_notify_probe_abandon(pdev, mux, muxc, parent, ret, 122 user_notify_called);
123 put_parent:
124 i2c_put_adapter(parent);
125
126 return ret;
127 }
128
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki