linux i2c-mux 使用

文章描述了一种使用GPIO来路由I2C信号的总线多路复用器。它列出了所需的属性,如兼容性、父I2C总线、GPIO引脚等,以及可选属性如空闲状态。示例展示了如何在设备树中配置这种多路复用器,以支持不同的I2C子总线,并在无访问时设置GPIO状态。
摘要由CSDN通过智能技术生成

参考文档:

i2c-mux-gpio.txt
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 used to control the muxer
* Standard I2C mux properties. See i2c-mux.txt in this directory.
* I2C child bus nodes. See i2c-mux.txt in this directory.

Optional properties:
- 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 relevant node's reg property will be output using the list of
GPIOs, the first in the list holding the least-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
GPIOs 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 hardware whenever no access is being made to 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@1 {
			reg = <1>;
			#address-cells = <1>;
			#size-cells = <0>;

			ssd1307: oled@3c {
				compatible = "solomon,ssd1307fb-i2c";
				reg = <0x3c>;
				pwms = <&pwm 4 3000>;
				reset-gpios = <&gpio2 7 1>;
				reset-active-low;
			};
		};

		i2c@3 {
			reg = <3>;
			#address-cells = <1>;
			#size-cells = <0>;

			pca9555: pca9555@20 {
				compatible = "nxp,pca9555";
				gpio-controller;
				#gpio-cells = <2>;
				reg = <0x20>;
			};
		};
	};
i2c-mux.txt
Common i2c bus multiplexer/switch properties.

An i2c bus multiplexer/switch will have several child busses that are
numbered uniquely in a device dependent manner.  The nodes for an i2c bus
multiplexer/switch will have one child node for each child bus.

Optional properties:
- #address-cells = <1>;
   This property is required is the i2c-mux child node does not exist.

- #size-cells = <0>;
   This property is required is the i2c-mux child node does not exist.

- i2c-mux
   For i2c multiplexers/switches that have child nodes that are a mixture
   of both i2c child busses and other child nodes, the 'i2c-mux' subnode
   can be used for populating the i2c child busses.  If an 'i2c-mux'
   subnode is present, only subnodes of this will be considered as i2c
   child busses.

Required properties for the i2c-mux child node:
- #address-cells = <1>;
- #size-cells = <0>;

Required properties for i2c child bus nodes:
- #address-cells = <1>;
- #size-cells = <0>;
- reg : The sub-bus number.

Optional properties for i2c child bus nodes:
- Other properties specific to the multiplexer/switch hardware.
- Child nodes conforming to i2c bus binding


Example :

	/*
	   An NXP pca9548 8 channel I2C multiplexer at address 0x70
	   with two NXP pca8574 GPIO expanders attached, one each to
	   ports 3 and 4.
	 */

	mux@70 {
		compatible = "nxp,pca9548";
		reg = <0x70>;
		#address-cells = <1>;
		#size-cells = <0>;

		i2c@3 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <3>;

			gpio1: gpio@38 {
				compatible = "nxp,pca8574";
				reg = <0x38>;
				#gpio-cells = <2>;
				gpio-controller;
			};
		};
		i2c@4 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <4>;

			gpio2: gpio@38 {
				compatible = "nxp,pca8574";
				reg = <0x38>;
				#gpio-cells = <2>;
				gpio-controller;
			};
		};
	};

使用方法:

  1. 重新编译内核,添加对GPIO-based I2C multiplexer的支持。

  2. 更改对应设备树,添加对i2cmux的启用。

示例:

       i2cmux{
                compatible = "i2c-mux-gpio";
		        #address-cells = <1>;
		        #size-cells = <0>;
                mux-gpios = <&gpio3 1 0 &gpio4 2 0 &gpio5 3 0 &gpio6 4 0>;
                i2c-parent = <&i2c1>;
                idle-state = <0>;

                i2c@1 {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <1>;
                         };
                i2c@2 {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <2>;
                        };
                i2c@3 {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <4>;
                        };
                i2c@4 {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <8>;
                        };
		};

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雲烟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值