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设备.
今天先到这里。
欢迎评论。