linux设备树(二)

设备树使用

通用的文件(iic)写在imx6ull.dtsi,具体的设备(mpu6050)写到imx6ull-alientek-emmc.dts

向节点追加或修改

&i2c1 {
    /* 要追加或修改的内容 */
};

&i2c1 表示要访问 i2c1 这个 label 所对应的节点,也就是 imx6ull.dtsi 中的“i2c1:i2c@021a0000”

&i2c1 {
    clock-frequency = <100000>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_i2c1>;
    status = "okay";
    mag3110@0e {
        compatible = "fsl,mag3110";
        reg = <0x0e>;
        position = <2>;
    };
    fxls8471@1e {
        compatible = "fsl,fxls8471";
        reg = <0x1e>;
        position = <0>;
        interrupt-parent = <&gpio5>;
        interrupts = <0 8>;
    };
};

属性“clock-frequency就表示 i2c1 时钟为 100KHz

status 属性的值由原来的 disabled 改为 okay

mag3110 添加的子节点

fxls8471 添加的子节点

一、创建设备树节点

alphaled {
    #address-cells = <1>;
    #size-cells = <1>;
    compatible = "atkalpha-led";
    status = "okay";
    reg = < 0X020C406C 0X04 /* CCM_CCGR1_BASE */
            0X020E0068 0X04 /* SW_MUX_GPIO1_IO03_BASE */
            0X020E02F4 0X04 /* SW_PAD_GPIO1_IO03_BASE */
            0X0209C000 0X04 /* GPIO1_DR_BASE */
            0X0209C004 0X04 >; /* GPIO1_GDIR_BASE */
};

编译设备树 make dtbs。查看是否添加成功

二、从驱动函数中调用设备树值

/* 1、获取设备节点:alphaled */
dtsled.nd = of_find_node_by_path("/alphaled");
/* 2、获取compatible属性内容 */
of_find_property(dtsled.nd, "compatible", NULL);
/* 3、获取status属性内容 */
of_property_read_string(dtsled.nd, "status", &str);
/* 4、获取reg属性内容 */
of_property_read_u32_array(dtsled.nd, "reg", regdata, 10);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值