1-wire

From Tinker Board Wiki
Jump to: navigation, search

1-wire

Config for 1-wire Driver

1.1 Add CONFIG_W1=y (kernel/arch/arm/configs/miniarm-rk3288_defconfig)

CONFIG_W1=y

Driver Source Code: kernel/drivers/w1/*.*
Result: Generate /sys/bus/w1

1.2 Add CONFIG_W1_MASTER_GPIO=y (kernel/arch/arm/configs/miniarm-rk3288_defconfig)

CONFIG_W1_MASTER_GPIO=y

Driver Source Code: kernel/drivers/w1/masters/w1-gpio.c
Result: Generate /sys/bus/w1/devices/w1_bus_master1

Device Tree Overlay

2.1 Add w1-gpio-overlay.dts (kernel/arch/arm/boot/dts/overlays/w1-gpio-overlay.dts)

/dts-v1/;
/plugin/;

/ {
    compatible = "rockchip,rk3288-miniarm", "rockchip,rk3288";
    fragment@0 {
        target-path = "/";
        __overlay__ {
            w1: onewire@0 {
                compatible = "w1-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <&w1_pins>;
                gpios = <&gpio0 17 0>;
                status = "okay";
            };
        };
    };

    fragment@1 {
        target = <&gpio5>;
        __overlay__ {
            w1_pins: w1_pins@0 {
                rockchip,pins = <0 17 0 &pcfg_pull_up>;
            };
        };
    };
};
  • The dts file sets the gpio0-17(gpio 17) as w1-gpio's pin.

Gpio bank.png


2.2 Add w1-gpio.dtbo into Makefile (kernel/arch/arm/boot/dts/overlays/Makefile)

dtbo-$(CONFIG_ARCH_ROCKCHIP) += \
        ... \
        w1-gpio.dtbo \

hw_intf.conf

3.1 Add intf:dtoverlay=w1-gpio so that w1-gpio.dtbo is loaded. (/boot/hw_intf.conf)

intf:dtoverlay=w1-gpio

* Reboot tinkerboard and the /sys/bus/w1/devices/w1_bus_master1 is generated.

Note

Make sure that the cpu frequency is over 600,000 Hz. You can modify the MIN_SPEED to "600000" at the /etc/init.d/cpufrequtils to achieve this goal.