linux kernel设备树中使用GPIO来模拟I2C Bus总线

0 : 先执行tree /sys/class/i2c-dev/,查看系统有多少I2C的Adapter:

在我的开发板上输出如下:

/sys/class/i2c-dev/
├── i2c-0 -> ../../devices/platform/ff3c0000.i2c/i2c-0/i2c-dev/i2c-0
├── i2c-1 -> ../../devices/platform/ff110000.i2c/i2c-1/i2c-dev/i2c-1
├── i2c-10 -> ../../devices/platform/fec00000.dp/i2c-10/i2c-dev/i2c-10
├── i2c-2 -> ../../devices/platform/ff120000.i2c/i2c-2/i2c-dev/i2c-2
├── i2c-4 -> ../../devices/platform/ff3d0000.i2c/i2c-4/i2c-dev/i2c-4
├── i2c-6 -> ../../devices/platform/ff150000.i2c/i2c-6/i2c-dev/i2c-6
├── i2c-7 -> ../../devices/platform/ff160000.i2c/i2c-7/i2c-dev/i2c-7
├── i2c-8 -> ../../devices/platform/ff3e0000.i2c/i2c-8/i2c-dev/i2c-8
└── i2c-9 -> ../../devices/platform/ff940000.hdmi/i2c-9/i2c-dev/i2c-9

9 directories, 0 files

留待后面对比。

下面是我们的正文:

1 在设备树加:

my_gpio_i2c {
	compatible = "i2c-gpio";
	gpios = <&gpio2 9 0 /* sda */
		 &gpio2 10 0 /* scl */
		>;
};
compatible = "i2c-gpio"; 指定了这是一个GPIO的I2c总线
。

然后编译,安装内核。

再次执行tree /sys/class/i2c-dev/**,输出如下:

/sys/class/i2c-dev/
├── i2c-0 -> ../../devices/platform/ff3c0000.i2c/i2c-0/i2c-dev/i2c-0
├── i2c-1 -> ../../devices/platform/ff110000.i2c/i2c-1/i2c-dev/i2c-1
├── i2c-10 -> ../../devices/platform/ff940000.hdmi/i2c-10/i2c-dev/i2c-10
├── i2c-11 -> ../../devices/platform/fec00000.dp/i2c-11/i2c-dev/i2c-11
├── i2c-2 -> ../../devices/platform/ff120000.i2c/i2c-2/i2c-dev/i2c-2
├── i2c-4 -> ../../devices/platform/ff3d0000.i2c/i2c-4/i2c-dev/i2c-4
├── i2c-6 -> ../../devices/platform/ff150000.i2c/i2c-6/i2c-dev/i2c-6
├── i2c-7 -> ../../devices/platform/ff160000.i2c/i2c-7/i2c-dev/i2c-7
├── i2c-8 -> ../../devices/platform/ff3e0000.i2c/i2c-8/i2c-dev/i2c-8
└── i2c-9 -> ../../devices/platform/my_gpio_i2c/i2c-9/i2c-dev/i2c-9

10 directories, 0 files

和我们第0步的对比,会发现把9和10 分别往后移动了一下,现在的i2c-9 是
my_gpio_i2c,这个就是我们在设备树添加的Adapter。
后面我们就可以在这个Adapter上添加GPIO设备.
今天先到这里。
欢迎评论。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值