This is a cache of https://discuss.96boards.org/t/1-wire-gpio-driver-for-ds18b20-temp-sensor/336. It is a snapshot of the page at 2024-10-31T03:04:28.097+0000.
1-Wire gpio driver for DS18B20 temp sensor - DragonBoard410c - 96Boards Forum

1-Wire gpio driver for DS18B20 temp sensor

Hi,
I want to use a DS18B20 temp sensor on my dragonboard through a bidirectional level shifter (1.8V low/5V high with the 4.7k pullup resistor on the high side for the data pin of the sensor). It uses the one-wire protocol and I see there is a kernel driver for enabling one wire on a gpio pin but I am not sure how to go about making it work. I’ve enabled the w1-gpio and w1-therm drivers but I don’t know how to enable it for a pin.

I’ve recompiled my kernel with these config options:
CONFIG_W1_MASTER_GPIO=y
CONFIG_W1=y
CONFIG_W1_SLAVE_THERM=y

and I see the directory under /sys/bus/w1on my device.

I think I need to modify a DTS to make a pin compatible with the driver (am very new to this).

The documentation says I need to add something like:
onewire@0 {
compatible = “w1-gpio”;
gpios = <&gpio 126 0>, <&gpio 105 0>;
};

but am not sure of:

  1. which dts to add it to (assuming arch/arm/boot/dts/qcom/apq8016-sbc.dtsi or arch/arm/boot/dts/qcom/msm8916-pinctrl.dtsi)
  2. which pin is okay to add this to (assuming unreserved gpio pins)
  3. if I have to disable some previous definition
  4. what the gpio address are of the pins etc. (I’ve looked through many qcom pdf files but nothing is popping out at me)

I’m pretty new to a lot of this stuff so it’d be really appreciative of an in depth explanation of what to do and why.

Thanks!

Hi,

For your DS18B20 temp sensor is giving directly digital output. so you can connect this to any pin’s of SoC and configure it as input.

So for that you need to add your node following node

onewire@0 {
compatible = “w1-gpio”;
gpios = &lt;&amp;gpio 126 0&gt;, &lt;&amp;gpio 105 0&gt;;
};

to arch/arm/boot/dts/qcom/apq8016-sbc.dtsi.
And also configure it’s pin-muxing like pin function, drive strength and biasing condition. to the following file.
arch/arm/boot/dts/qcom/msm8916-pinctrl.dtsi

Regards,
Deepak

Thanks for the reply Deepak,

I want to use GPIO_36 so I added the following:

msm8916-pinctrl.dtsi:

            /*General purpose pins*/
            gp: gp {
                    qcom,num-pins = &lt;122&gt;;
                    #qcom,pin-cells = &lt;1&gt;;
                    msm_gpio: msm_gpio {
                            compatible = "qcom,msm-tlmm-gp";
                            gpio-controller;
                            #gpio-cells = &lt;2&gt;;
                            interrupt-controller;
                            #interrupt-cells = &lt;2&gt;;
                            num_irqs = &lt;122&gt;;
                    };
            };

            /** BEGIN: Added for 1wire */

            onewire-pins {
                    qcom,pins = &lt;&amp;gp 36&gt;;
                    qcom,num-grp-pins = &lt;1&gt;;
                    qcom,pin-func = &lt;1&gt;;
                    label = "onewire-pins";
                    onewire_pins_defaut: default {
                            drive-strength = &lt;3&gt;;
                            bias-disable;
                    };
            };
            /** END: Added for 1wire */

and to apq8016-sbc.dtsi

&soc {
/** BEGIN: Added for 1wire /
onewire@0 {
compatible = “w1-gpio”;
gpios = <&msm_gpio 36 0>;
};
/
* END: Added for 1wire */

    i2c@78b6000 { /* BLSP1 QUP2 */

I now see the bus under w1 but not devices were discovered

pwd

/sys/bus/w1/devices/w1_bus_master1

ls -al

total 0
drwxr-xr-x 3 root root 0 1970-01-01 00:17 .
drwxr-xr-x 103 root root 0 1970-01-01 00:17 …
lrwxrwxrwx 1 root root 0 2015-12-21 16:10 driver → …/…/bus/w1/drivers/w1_master_driver
drwxr-xr-x 2 root root 0 1970-01-01 00:17 power
lrwxrwxrwx 1 root root 0 2015-12-21 16:10 subsystem → …/…/bus/w1
-rw-r–r-- 1 root root 4096 1970-01-01 00:17 uevent
-rw-rw-r-- 1 root root 4096 2015-12-21 16:10 w1_master_add
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_attempts
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_max_slave_count
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_name
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_pointer
-rw-rw-r-- 1 root root 4096 2015-12-21 16:10 w1_master_pullup
-rw-rw-r-- 1 root root 4096 2015-12-21 16:10 w1_master_remove
-rw-rw-r-- 1 root root 4096 2015-12-21 16:10 w1_master_search
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_slave_count
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_slaves
-r–r–r-- 1 root root 4096 2015-12-21 16:10 w1_master_timeout

Did my modifications to the DTSI’s look correct?

Thanks!
Will

FYI, I got this working by modifying the relevant device tree files:
=== Kernel config ===

CONFIG_W1_MASTER_GPIO=y
CONFIG_W1=y
CONFIG_W1_SLAVE_THERM=y

=== boot/dts/qcom/msm8916-pinctrl.dtsi ===

&amp;soc {
        tlmm_pinmux: pinctrl@1000000 {
                compatible = &quot;qcom,msm-tlmm-8916&quot;;
                reg = &lt;0x1000000 0x300000&gt;;
                interrupts = &lt;0 208 0&gt;;

                /*General purpose pins*/
                gp: gp {
                        qcom,num-pins = &lt;122&gt;;
                        #qcom,pin-cells = &lt;1&gt;;
                        msm_gpio: msm_gpio {
                                compatible = &quot;qcom,msm-tlmm-gp&quot;;
                                gpio-controller;
                                #gpio-cells = &lt;2&gt;;
                                interrupt-controller;
                                #interrupt-cells = &lt;2&gt;;
                                num_irqs = &lt;122&gt;;
                        };
                };

                onewire-pins {
                        qcom,pins = &lt;&amp;gp 36&gt;;
                        qcom,num-grp-pins = &lt;1&gt;;
                        qcom,pin-func = &lt;0&gt;;
                        label = &quot;onewire-pins&quot;;
                        onewire_pins_default: default {
                                drive-strength = &lt;4&gt;;
                                bias-disable;
                        };
                };

and this:
=== boot/dts/qcom/apq8016-sbc.dtsi ===

&amp;soc {
        onewire@0 {
                compatible = &quot;w1-gpio&quot;;
                gpios = &lt;&amp;msm_gpio 36 0&gt;;
                status = &quot;okay&quot;;
                pinctrl-names = &quot;default&quot;;
                pinctrl-0 = &lt;&amp;onewire_pins_default&gt;;
        };

Also initially I was using the TXB0108 level converter but that doesn’t support 1wire because of the pullup system that it uses. Everything started working when I switched to using BSS138 level converter though apparently that’s slower.