Now 1-wire and DS18B20 works

I want to run DS18B20 on the Rock PI S device using the default pin “GPIO0_C1”.

The devicetree file “rk3308-w1-gpio.dts” contains this:

// Definitions for w1-gpio module (without external pullup)
/dts-v1/;
/plugin/;

/ {
    compatible = "rockchip,rk3308";

    fragment@0 {
        target-path = "/";
        __overlay__ {

            w1: onewire@0 {
                compatible = "w1-gpio";
                pinctrl-names = "default";
                gpios = <&gpio0 17 0 0xae>; // GPIO0_C1
                status = "okay";
            };
        };
    };
};

So at startup the pin used for 1-wire is “GPIO0_C1”.

Then I activate the overlay in the “uEnv.txt” file:

overlays=rk3308-uart0 rk3308-w1-gpio
param_w1_pin=GPIO0_C1

I verify that the “/etc/modules” file contains:

# 1-wire temperature
w1-gpio
w1-therm

Everything looks fine, I reboot.

On restart I check if everything is configured correctly.

Pin configuration at boot:

Applying kernel provided DT fixup script (rockchip-fixup.scr)
## Executing script at 05000000
tmp_pinctrl=0
tmp_bank=C
tmp_pin=1
GPIO0_C1 ---> pinctrl = 0
GPIO0_C1 ---> bank = 10
GPIO0_C1 ---> pin = 11
GPIO0_C1 ---> tmp_pinctrl = /pinctrl/gpio0@ff220000
GPIO0_C1 ---> tmp_phandle = 0x00000075

Loading kernel modules:

~$ lsmod
Module                  Size  Used by
w1_therm               16384  0
w1_gpio                16384  0
wire                   28672  2 w1_gpio,w1_therm
cn                     16384  1 wire

I check if the hardware pin is used by 1-wire:

~$ sudo cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/pinctrl, gpio0:
 gpio-2   (                    |reset               ) out hi
 gpio-5   (                    |?                   ) out lo
 gpio-6   (                    |?                   ) out hi
 gpio-7   (                    |mdio-reset          ) out hi
 gpio-11  (                    |w1                  ) in  hi
 gpio-21  (                    |vcc_otg_vbus        ) out hi

GPIOs 32-63, platform/pinctrl, gpio1:

GPIOs 64-95, platform/pinctrl, gpio2:

GPIOs 96-127, platform/pinctrl, gpio3:

GPIOs 128-159, platform/pinctrl, gpio4:
 gpio-135 (                    |bt_default_rts      ) out hi
 gpio-139 (                    |bt_default_poweron  ) out hi
 gpio-140 (                    |bt_default_wake_host) in  hi
 gpio-158 (                    |vcc_sd              ) out lo

The pin “gpio-11” is used by “w1” but it’s wrong it should be “gpio-17”.

I have 3 DS18B20 probes, checking if they are recognized:

~$ ls /sys/bus/w1/devices/
w1_bus_master1

No 1-wire probes are recognized (on Raspberry PI, they are recognized regularly)

After some trial and error, I removed the pin configuration “param_w1_pin = GPIO0_C1” from the “uEnv.txt” file, leaving only the overlay:

overlays=rk3308-uart0 rk3308-w1-gpio

Reboot the device and double check:

~$ lsmod
Module                  Size  Used by
w1_therm               16384  0
w1_gpio                16384  0
wire                   28672  2 w1_gpio,w1_therm
cn                     16384  1 wire

~$ sudo cat /sys/kernel/debug/gpio
GPIOs 0-31, platform/pinctrl, gpio0:
 gpio-2   (                    |reset               ) out hi
 gpio-5   (                    |?                   ) out lo
 gpio-6   (                    |?                   ) out hi
 gpio-7   (                    |mdio-reset          ) out hi
 gpio-17  (                    |w1                  ) in  hi
 gpio-21  (                    |vcc_otg_vbus        ) out hi

GPIOs 32-63, platform/pinctrl, gpio1:

GPIOs 64-95, platform/pinctrl, gpio2:

GPIOs 96-127, platform/pinctrl, gpio3:

GPIOs 128-159, platform/pinctrl, gpio4:
 gpio-135 (                    |bt_default_rts      ) out hi
 gpio-139 (                    |bt_default_poweron  ) out hi
 gpio-140 (                    |bt_default_wake_host) in  hi
 gpio-158 (                    |vcc_sd              ) out lo

The pin “gpio-17” is the correct one and used by “w1”.

I have 3 DS18B20 probes, checking if they are recognized:

~# ls /sys/bus/w1/devices/
28-3c01d6175060  28-3c01d6175930  28-3c01d6176090  w1_bus_master1

From this I deduce that the “rockchip-fixup.scr” script has some problem calculating the right hardware pin:

Applying kernel provided DT fixup script (rockchip-fixup.scr)
## Executing script at 05000000
tmp_pinctrl=0
tmp_bank=C
tmp_pin=1
GPIO0_C1 ---> pinctrl = 0
GPIO0_C1 ---> bank = 10
GPIO0_C1 ---> pin = 11
GPIO0_C1 ---> tmp_pinctrl = /pinctrl/gpio0@ff220000
GPIO0_C1 ---> tmp_phandle = 0x00000075

The “bank” should perhaps be “0” and the “pin” 17 ", don’t you think ?

Source of the “rockchip-fixup.scr” script:

# overlays fixup script
# implements (or rather substitutes) overlay arguments functionality
# using u-boot scripting, environment variables and "fdt" command

setenv decompose_pin 'setexpr tmp_pinctrl sub "GPIO(0|1|2|3|4)_\\S\\d+" "\\1";
setexpr tmp_bank sub "GPIO\\d_(\\S)\\d+" "\\1";
test "${tmp_bank}" = "A" && setenv tmp_bank 0;
test "${tmp_bank}" = "B" && setenv tmp_bank 1;
test "${tmp_bank}" = "C" && setenv tmp_bank 2;
test "${tmp_bank}" = "D" && setenv tmp_bank 3;
setexpr tmp_pin sub "GPIO\\d_\\S(\\d+)" "\\1";
setexpr tmp_bank ${tmp_bank} * 8;
setexpr tmp_pin ${tmp_bank} + ${tmp_pin}'

if test -n "${param_spidev_spi_bus}"; then
    test "${param_spidev_spi_bus}" = "0" && setenv tmp_spi_path "spi@ff120000"
    test "${param_spidev_spi_bus}" = "1" && setenv tmp_spi_path "spi@ff130000"
    test "${param_spidev_spi_bus}" = "2" && setenv tmp_spi_path "spi@ff140000"
    fdt set /${tmp_spi_path} status "okay"
    fdt set /${tmp_spi_path}/spidev status "okay"
    if test -n "${param_spidev_max_freq}"; then
        fdt set /${tmp_spi_path}/spidev spi-max-frequency "<${param_spidev_max_freq}>"
    fi
fi

if test -n "${param_w1_pin}"; then
    setenv tmp_pinctrl "${param_w1_pin}"
    setenv tmp_bank "${param_w1_pin}"
    setenv tmp_pin "${param_w1_pin}"
    run decompose_pin
    echo "${param_w1_pin} ---> pinctrl = ${tmp_pinctrl}"
    echo "${param_w1_pin} ---> bank = ${tmp_bank}"
    echo "${param_w1_pin} ---> pin = ${tmp_pin}"
    fdt get value tmp_pinctrl /__symbols__	gpio${tmp_pinctrl}
    echo "${param_w1_pin} ---> tmp_pinctrl = ${tmp_pinctrl}"
    fdt get value tmp_phandle ${tmp_pinctrl} phandle
    echo "${param_w1_pin} ---> tmp_phandle = ${tmp_phandle}"
    fdt set /onewire@0 gpios "<${tmp_phandle} ${tmp_pin} 0 0>"
    env delete tmp_pinctrl tmp_bank tmp_pin tmp_phandle
fi

Does anyone know the “uboot” language to verify the script and maybe correct it ?

debugasm

I cant help you, but I have a question:

Is 1wire now working stable at your device?