driver/i2c/mux: Add register based mux i2c-mux-reg
Subsystems (3)
PATCH v2 1/1 driver/i2c/mux: Add register based mux i2c-mux-reg
Based on i2c-mux-gpio driver, similarly the register based mux switch from one bus to another by setting a single register. The register can be on PCIe bus, local bus, or any memory-mapped address.
---
Change log:
v2: Update to GPLv2+ licence header
Use iowrite instead of direct dereference the pointer to write register Add support of difference register size of 1/2/4 bytes Remove i2c_put_adapter(parent) in probe fucntion
Replace multiple dev_info() with dev_dbg()
Add idle_in_use variable to gate using idle value
Add __iomem for register pointer
Move platform data header file to include/linux/platform_data/
.../devicetree/bindings/i2c/i2c-mux-reg.txt | 71 ++++++ drivers/i2c/muxes/Kconfig | 11 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-reg.c | 266 ++++++++++++++++++++ include/linux/platform_data/i2c-mux-reg.h | 40 +++ 5 files changed, 389 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt create mode 100644 drivers/i2c/muxes/i2c-mux-reg.c create mode 100644 include/linux/platform_data/i2c-mux-reg.h
Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt new file +71 -0
@@ -0,0 +1,71 @@ +Register-based I2C Bus Mux + +This binding describes an I2C bus multiplexer that uses a single register +to route the I2C signals. + +Required properties: +- compatible: i2c-mux-reg +- i2c-parent: The phandle of the I2C bus that this multiplexer's master-side + port is connected to. +* Standard I2C mux properties. See mux.txt in this directory. +* I2C child bus nodes. See mux.txt in this directory. + +Optional properties: +- reg: this pair of <offset size> specifies the register to control the mux. + The <offset size> depends on its parent node. It can be any memory-mapped + address. The size must be either 1, 2, or 4 bytes. If reg is omitted, the + resource of this device will be used. +- idle-state: value to set the muxer to when idle. When no value is + given, it defaults to the last value used. + +For each i2c child node, an I2C child bus will be created. They will +be numbered based on their order in the device tree. + +Whenever an access is made to a device on a child bus, the value set +in the revelant node's reg property will be output to the register. + +If an idle state is defined, using the idle-state (optional) property, +whenever an access is not being made to a device on a child bus, the +register will be set according to the idle value. + +If an idle state is not defined, the most recently used value will be +left programmed into the register. + +Example of a mux on PCIe card, the host is a powerpc SoC (big endian): + + i2c-mux { + /* the <offset size> depends on the address translation + * of the parent device. If omitted, device resource + * will be used instead. The size is to determine + * whether iowrite32, iowrite16, or iowrite8 will be used. + */ + reg = <0x6028 0x4>; + compatible = "i2c-mux-reg"; + #address-cells = <1>; + #size-cells = <0>; + i2c-parent = <&i2c1>; + i2c@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + si5338: clock-generator@70 { + compatible = "silabs,si5338"; + reg = <0x70>; + /* other stuff */ + }; + }; + + i2c@1 { + /* data is written using iowrite32 */ + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + si5338: clock-generator@70 { + compatible = "silabs,si5338"; + reg = <0x70>; + /* other stuff */ + }; + }; + };
drivers/i2c/muxes/Kconfig +11 -0
@@ -29,6 +29,17 @@ config I2C_MUX_GPIO This driver can also be built as a module. If so, the module will be called i2c-mux-gpio. +config I2C_MUX_REG + tristate "Register-based I2C multiplexer" + help + If you say yes to this option, support will be included for a + register based I2C multiplexer. This driver provides access to + I2C busses connected through a MUX, which is controlled + by a sinple register. + + This driver can also be built as a module. If so, the module + will be called i2c-mux-reg. + config I2C_MUX_PCA9541 tristate "NXP PCA9541 I2C Master Selector" help
drivers/i2c/muxes/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o +obj-$(CONFIG_I2C_MUX_REG) += i2c-mux-reg.o 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
drivers/i2c/muxes/i2c-mux-reg.c new file +266 -0
266 lines not on this page · raw message
include/linux/platform_data/i2c-mux-reg.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* I2C multiplexer using a single register +* +* Copyright 2015 Freescale Semiconductor +* York Sun <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#ifndef __LINUX_PLATFORM_DATA_I2C_MUX_REG_H +#define __LINUX_PLATFORM_DATA_I2C_MUX_REG_H + +/** +* struct i2c_mux_reg_platform_data - Platform-dependent data for i2c-mux-reg +* @parent: Parent I2C bus adapter number +* @base_nr: Base I2C bus number to number adapters from or zero for dynamic +* @values: Array of value for each channel +* @n_values: Number of multiplexer channels +* @classes: Optional I2C auto-detection classes +* @idle: Value to write to mux when idle +* @idle_in_use: indicate if idle value is in use +* @reg: Virtual address of the register to switch channel +* @reg_size: register size in bytes +*/ +struct i2c_mux_reg_platform_data { +int parent; +int base_nr; +const unsigned int *values; +int n_values; +const unsigned int *classes; +u32 idle; +bool idle_in_use; +void __iomem *reg; +resource_size_t reg_size; +}; + +#endif /* __LINUX_PLATFORM_DATA_I2C_MUX_REG_H */
Signature · 1 line
1.7.9.5
Hello!
drivers/i2c/muxes/i2c-mux-reg.c line 43
Quoted 10 lines · ext York Sun
drivers/i2c/muxes/i2c-mux-reg.c new file +10
-0+switch (mux->data.reg_size) { +case 4 : +iowrite32 (mux->data.values[chan], mux->data.reg); +break ; +case 2 : +iowrite16 (mux->data.values[chan], mux->data.reg); +break ; +case 1 : +iowrite8 (mux->data.values[chan], mux->data.reg); +break ;
I'd like to see at least [optional] read-back operation after each write. And if you stick with iowrite*(), maybe it desires a comment (in the Documentation/ file?), that write will be little-Endian, therefore BE users must take care...
Other than that it looks good to me...
Signature · 2 lines
Best regards, Alexander Sverdlin.
Quoted 15 lines · Alexander Sverdlin
Hello!
drivers/i2c/muxes/i2c-mux-reg.c line 43
Quoted 10 lines · ext York Sun
drivers/i2c/muxes/i2c-mux-reg.c new file +10
-0+switch (mux->data.reg_size) { +case 4 : +iowrite32 (mux->data.values[chan], mux->data.reg); +break ; +case 2 : +iowrite16 (mux->data.values[chan], mux->data.reg); +break ; +case 1 : +iowrite8 (mux->data.values[chan], mux->data.reg); +break ;I'd like to see at least [optional] read-back operation after each write.
Maybe I should add ioread after each write without using an option. I want to avoid additional option if possible.
Quoted 2 lines
And if you stick with iowrite*(), maybe it desires a comment (in the
Documentation/file?), that write will be little-Endian, therefore BE users must take care...
I am consulting with my colleagues. If I cannot come up with a native endianess solution, I will keep using iowrite and add a comment.
Quoted 3 lines
Other than that it looks good to me...
Thanks.
York