ARM: I2C: Add device tree bindings to i2c-mux-gpio
Subsystems (5)
v2 cover ARM: I2C: Add device tree bindings to i2c-mux-gpio
Hi everyone,
This patchset adds the device tree entry to the CFA-10049 board of its i2c muxer. This muxer controls sub-buses that contains three Nuvoton NAU7802 ADCs and a NXP PCA955 GPIO expander. Support for these will be added eventually.
Thanks,
Maxime
Changes from v1:
- Fixed indentation in patch 1
- Fixed arrays allocation for the dt bindings
- Various fixes in the documentation
Maxime Ripard (3):
i2c: i2c-mux-gpio: Use devm_kzalloc instead of kzalloc
i2c: mux: Add dt support to i2c-mux-gpio driver
ARM: dts: cfa10049: Add the i2c muxer buses to the CFA-10049
.../devicetree/bindings/i2c/i2c-mux-gpio.txt | 81 +++++++++ arch/arm/boot/dts/imx28-cfa10049.dts | 33 ++++ drivers/i2c/muxes/i2c-mux-gpio.c | 172 +++++++++++++++----- 3 files changed, 243 insertions(+), 43 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-gpio.txt
Signature · 1 line
1.7.9.5
PATCH v2 1/3 i2c: i2c-mux-gpio: Use devm_kzalloc instead of kzalloc
Use the devm_kzalloc managed function to stripdown the error and remove code.
--- drivers/i2c/muxes/i2c-mux-gpio.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/i2c/muxes/i2c-mux-gpio.c +5 -9
@@ -71,7 +71,7 @@ static int __devinit i2c_mux_gpio_probe(struct platform_device *pdev)return -ENODEV ; } - mux =kzalloc (sizeof (*mux),GFP_KERNEL ); + mux =devm_kzalloc (&pdev->dev,sizeof (*mux),GFP_KERNEL );if (!mux) { ret = -ENOMEM ; goto alloc_failed;
@@ -79,11 +79,12 @@ static int __devinit i2c_mux_gpio_probe(struct platform_device *pdev) mux->parent = parent; mux->data = *pdata; - mux->adap =kzalloc (sizeof (struct i2c_adapter *) * pdata->n_values, -GFP_KERNEL ); + mux->adap =devm_kzalloc (&pdev->dev, +sizeof (*mux->adap) * pdata->n_values, +GFP_KERNEL );if (!mux->adap) { ret = -ENOMEM ; - goto alloc_failed2; + goto alloc_failed; }if (pdata->idle !=I2C_MUX_GPIO_NO_IDLE ) {
@@ -128,9 +129,6 @@ add_adapter_failed: err_request_gpio:for (; i >0 ; i--)gpio_free (pdata->gpios[i -1 ]); -kfree (mux->adap); -alloc_failed2: -kfree (mux); alloc_failed:i2c_put_adapter (parent);
@@ -150,8 +148,6 @@ static int __devexit i2c_mux_gpio_remove(struct platform_device *pdev)platform_set_drvdata (pdev,NULL );i2c_put_adapter (mux->parent); -kfree (mux->adap); -kfree (mux);return 0 ; }
Signature · 1 line
1.7.9.5
PATCH v2 2/3 i2c: mux: Add dt support to i2c-mux-gpio driver
Allow the i2c-mux-gpio to be used by a device tree enabled device. The bindings are inspired by the one found in the i2c-mux-pinctrl driver.
--- .../devicetree/bindings/i2c/i2c-mux-gpio.txt | 81 ++++++++++ drivers/i2c/muxes/i2c-mux-gpio.c | 160 +++++++++++++++----- 2 files changed, 206 insertions(+), 35 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-gpio.txt
Documentation/devicetree/bindings/i2c/i2c-mux-gpio.txt new file +81 -0
@@ -0,0 +1,81 @@ +GPIO-based I2C Bus Mux + +This binding describes an I2C bus multiplexer that uses GPIOs to +route the I2C signals. + + +-----+ +-----+ + | dev | | dev | + +------------+ +-----+ +-----+ + | SoC | | | + | | /--------+--------+ + | +------+ | +------+ child bus A, on GPIO value set to 0 + | | I2C |-|--| Mux | + | +------+ | +--+---+ child bus B, on GPIO value set to 1 + | | | \----------+--------+--------+ + | +------+ | | | | | + | | GPIO |-|-----+ +-----+ +-----+ +-----+ + | +------+ | | dev | | dev | | dev | + +------------+ +-----+ +-----+ +-----+ + +Required properties: +- compatible: i2c-mux-gpio +- i2c-parent: The phandle of the I2C bus that this multiplexer's master-side + port is connected to. +- mux-gpios: list of gpios to use to control the muxer +* Standard I2C mux properties. See mux.txt in this directory. +* I2C child bus nodes. See mux.txt in this directory. + +Optional properties: +- idle-state: value to set to the muxer when idle. When no value is + given, it defaults to the first value in the array. + +For each i2c child node, an I2C child bus will be created. They will +be numbered based on the reg property of each node. + +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 using the list of +GPIOs, the first in the list holding the most-significant value. + +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 +idle value will be programmed into the GPIOs. + +If an idle state is not defined, the most recently used value will be +left programmed into hardware whenever no access is being made of a +device on a child bus. + +Example: + i2cmux { + compatible = "i2c-mux-gpio"; + #address-cells = <1>; + #size-cells = <0>; + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; + i2c-parent = <&i2c1>; + + i2c at 1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + ssd1307: oled at 3c { + compatible = "solomon,ssd1307fb-i2c"; + reg = <0x3c>; + pwms = <&pwm 4 3000>; + reset-gpios = <&gpio2 7 1>; + reset-active-low; + }; + }; + + i2c at 3 { + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + + pca9555: pca9555 at 20 { + compatible = "nxp,pca9555"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x20>; + }; + }; + };
drivers/i2c/muxes/i2c-mux-gpio.c +125 -35
260 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 3/3 ARM: dts: cfa10049: Add the i2c muxer buses to the CFA-10049
In reply to Maxime RipardThis will allow to add the 3 Nuvoton NAU7802 ADCs and the NXP PCA9555 GPIO expander eventually.
--- arch/arm/boot/dts/imx28-cfa10049.dts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
arch/arm/boot/dts/imx28-cfa10049.dts +33 -0
@@ -76,6 +76,39 @@ status = "okay"; }; + i2cmux { + compatible = "i2c-mux-gpio"; + #address-cells = <1>; + #size-cells = <0>; + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; + i2c-parent = <&i2c1>; + + i2c at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + }; + + i2c at 1 { + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + }; + + i2c at 2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + i2c at 3 { + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + + }; + }; + usbphy1: usbphy at 8007e000 { status = "okay"; };
Signature · 1 line
1.7.9.5
PATCH 3/3 ARM: dts: cfa10049: Add the i2c muxer buses to the CFA-10049
Hello.
Quoted 17 lines · Maxime Ripard
This will allow to add the 3 Nuvoton NAU7802 ADCs and the NXP PCA9555 GPIO expander eventually.
Signed-off-by Maxime Ripard <[email protected]>--- arch/arm/boot/dts/imx28-cfa10049.dts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)arch/arm/boot/dts/imx28-cfa10049.dts +1
-0@@ -76,6 +76,39 @@ status = "okay"; }; + i2cmux {
arch/arm/boot/dts/imx28-cfa10049.dts line 89
Quoted 10 lines
arch/arm/boot/dts/imx28-cfa10049.dts +10
-0+ compatible = "i2c-mux-gpio"; + #address-cells = <1>; + #size-cells = <0>; + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; + i2c-parent = <&i2c1>; + + i2c at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>;
If you don't have any subnodes the above to props have no sense.
arch/arm/boot/dts/imx28-cfa10049.dts line 91
Quoted 2 lines
arch/arm/boot/dts/imx28-cfa10049.dts +2
-0+ }; +
WBR, Sergei
PATCH v2 3/3 ARM: dts: cfa10049: Add the i2c muxer buses to the CFA-10049
Hi
Le 24/09/2012 13:52, Sergei Shtylyov a ?crit :
Quoted 20 lines · Maxime Ripard
Quoted 19 lines
This will allow to add the 3 Nuvoton NAU7802 ADCs and the NXP PCA9555 GPIO expander eventually.
Signed-off-by Maxime Ripard <[email protected]>--- arch/arm/boot/dts/imx28-cfa10049.dts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)arch/arm/boot/dts/imx28-cfa10049.dts +0
-0@@ -76,6 +76,39 @@ status = "okay"; };
Quoted 13 lines
arch/arm/boot/dts/imx28-cfa10049.dts line 89
Quoted 11 lines
arch/arm/boot/dts/imx28-cfa10049.dts +11
-0+ i2cmux { + compatible = "i2c-mux-gpio"; + #address-cells = <1>; + #size-cells = <0>; + mux-gpios = <&gpio1 22 0 &gpio1 23 0>; + i2c-parent = <&i2c1>; + + i2c at 0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>;If you don't have any subnodes the above to props have no sense.
I will use them with subnodes eventually, with the 3 ADCs and the GPIO expander. So these nodes won't be left empty.
On another hand, I can add these props when I'll add the devices, I have no strong opinion here.
Maxime
Signature · 4 lines
Maxime Ripard, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com