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.
Motivation is to support indirect access to register space where selector register is located.
For example, Lattice FPGA LFD2NX-40 device, being connected through PCIe bus provides SPI or LPC bus logic through PCIe-to-SPI or PCIe-to-LPC bridging. Thus, FPGA operates a as host controller and some slave devices can be connected to it. For example:
- CPU (PCIe) -> FPGA (PCIe-to-SPI bridge) -> CPLD or another FPGA.
- CPU (PCIe) -> FPGA (PCIe-to-LPC bridge) -> CPLD or another FPGA. Where 1-st FPGA connected to PCIe is located on carrier board, while 2-nd programming logic device is located on some switch board and cannot be connected to CPU PCIe root complex.
In case mux selector register is located within the 2-nd device, SPI or LPC transactions are sent indirectly through pre-defined protocol.
To support such protocol reg_read()/reg_write() callbacks are provided to 'regmap' object and these callback implements required indirect access.
For example, flow in reg_write() will be as following:
- Verify there is no pending transactions.
- Set address in PCIe register space.
- Set data to be written in PCIe register space.
- Activate write operation in PCIe register space.
- LPC or SPI write transaction is performed.
--- drivers/i2c/muxes/Kconfig | 12 ++ drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-regmap.c | 123 +++++++++++++++++++ include/linux/platform_data/i2c-mux-regmap.h | 34 +++++ 4 files changed, 170 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
@@ -119,4 +119,16 @@ config I2C_MUX_MLXCPLD This driver can also be built as a module. If so, the module will be called i2c-mux-mlxcpld. +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. + endmenu
drivers/i2c/muxes/Makefile +1 -0
@@ -14,5 +14,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 +123 -0
123 lines not on this page · raw message
include/linux/platform_data/i2c-mux-regmap.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* +* Regmap i2c mux driver +* +* Copyright (C) 2023 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 space +* @reg_size: register size in bytes +* @handle: handle to be passed by callback +* @completion_notify: callback to notify when all the adapters are created +*/ +struct i2c_mux_regmap_platform_data { +void *regmap; +int parent; +const unsigned int *chan_ids; +int num_adaps; +int sel_reg_addr; +u8 reg_size; +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.20.1