20 设备树里声明i2c设备

参考内核源码目录里的Documentation/i2c/instantiating-devices
文档里主要的内容:

Method 1b: Declare the I2C devices via devicetree
-------------------------------------------------

This method has the same implications as method 1a. The declaration of I2C
devices is here done via devicetree as subnodes of the master controller.

Example:

    i2c1: i2c@400a0000 {
        /* ... master properties skipped ... */
        clock-frequency = <100000>;   

        flash@50 {
            compatible = "atmel,24c256";
            reg = <0x50>;
        };

        pca9532: gpio@60 {
            compatible = "nxp,pca9532";
            gpio-controller;
            #gpio-cells = <2>;
            reg = <0x60>;
        };
    };

通过文档里的内容, 可以得知: i2c设备节点需要作为i2c控制器节点的子节点.
i2c设备节点的compatible属性值除了用于与设备驱动匹配以外,还作为设备名.
reg属性值为设备地址.也可以在设备节点里加入额外的属性.


如dht12接在第0个i2c控制器上,则修改内核源码目录arch/arm64/boot/dts/allwinner/sunxi-h3-h5.dts:

        i2c0: i2c@01c2ac00 {  /* 控制器的设备节点 */
            compatible = "allwinner,sun6i-a31-i2c";
            reg = <0x01c2ac00 0x400>;
            interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&ccu CLK_BUS_I2C0>;
            resets = <&ccu RST_BUS_I2C0>;
            pinctrl-names = "default";
            pinctrl-0 = <&i2c0_pins>;
            status = "disabled";
            #address-cells = <1>;
            #size-cells = <0>;

            mydht12 {   /* 增加的设备子节点  */
                compatible = "mydht12";
                reg = <0x5c>; /* 设备地址 */

        /*  额外增加的属性,供i2c设备驱动使用  */
                led-gpios = <&pio 0 17 GPIO_ACTIVE_HIGH>; 
            };

        };

重编设备树并更新,重启系统后:

^_^ / # ls /sys/bus/i2c/devices/
0-005c/  0-0068/  i2c-0/   i2c-1/   i2c-2/
^_^ / # cat /sys/bus/i2c/devices/0-005c/name 
mydht12
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值