# RPI3 one-wire GPIO pin



## aonishenko (Nov 7, 2017)

Hi!

I have RPI 3 and FreeBSD 12 installed on it. 
Unfortunatelly, there is no any dts file on kernel tree and I cannot define one-wire GPIO pin. Is it possible to define one-wire pi without recompilling kernel and dts\dtb files?


----------



## aragats (Nov 7, 2017)

You have to tell the kernel you pin configuration anyway. AFAIK DTSs/DTBs are platform independent. Also you can easily compile them with sysutils/dtc.


----------



## aonishenko (Nov 7, 2017)

aragats said:


> You have to tell the kernel you pin configuration anyway. AFAIK DTSs/DTBs are platform independent. Also you can easily compile them with sysutils/dtc.


So  that's means that I may get DTS even from Ubuntu and compile it with dtc in FreeBSD?


----------



## aragats (Nov 7, 2017)

aonishenko said:


> I may get DTS even from Ubuntu and compile it with dtc in FreeBSD


I believe so. The only thing I noticed that in the latest Ubuntu/Debian old DTBs (e.g. from 3.8 kernels) don't work properly and compiling the corresponding old DTSs doesn't help. That means there were some API changes in the past.


----------



## aonishenko (Nov 8, 2017)

aragats said:


> I believe so. The only thing I noticed that in the latest Ubuntu/Debian old DTBs (e.g. from 3.8 kernels) don't work properly and compiling the corresponding old DTSs doesn't help. That means there were some API changes in the past.


Going to check this - https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/bcm2837-rpi-3-b.dts

Thank you!


----------



## Phishfry (Nov 8, 2017)

aonishenko said:


> Unfortunatelly, there is no any dts file on kernel tree


There are DTS in the FreeBSD source.

Check this directory:
usr/src/sys/boot/fdt/dts/arm/

Perhaps you don't have the /src tree installed?

You will need to load ow and owc and ow-temp(if needed)
`kldload` will manually load them.


----------



## aonishenko (Nov 8, 2017)

Phishfry said:


> There are DTS in the FreeBSD source.
> 
> Check this directory:
> usr/src/sys/boot/fdt/dts/arm/
> ...


I have the source tree, but I haven't RPI3 DTS definition, only RPI2, but it not arm64 arch.


----------



## Phishfry (Nov 8, 2017)

Looks like there were some changes on -CURRENT
/usr/src/sys/gnu/dts/arm/

If there is a download available on the FreeBSD download page then the dts should be in source files.


----------



## aonishenko (Nov 9, 2017)

Phishfry said:


> Looks like there were some changes on -CURRENT
> /usr/src/sys/gnu/dts/arm/
> 
> If there is a download available on the FreeBSD download page then the dts should be in source files.


Yes, but also, there is no definition for RPI3


```
-rw-r--r--  1 root  wheel     513 15 сент. 13:22 bcm2835-rpi-a-plus.dts
-rw-r--r--  1 root  wheel     513 15 сент. 13:22 bcm2835-rpi-b-plus.dts
-rw-r--r--  1 root  wheel     392 15 сент. 13:22 bcm2835-rpi-b-rev2.dts
-rw-r--r--  1 root  wheel     256 15 сент. 13:22 bcm2835-rpi-b.dts
-rw-r--r--  1 root  wheel     825 15 сент. 13:22 bcm2835-rpi.dtsi
-rw-r--r--  1 root  wheel     550 15 сент. 13:22 bcm2836-rpi-2-b.dts
```


----------



## Phishfry (Nov 9, 2017)

Looking at the Crochet RPi3 board file they use this:
https://github.com/raspberrypi/firmware/tree/master/boot


----------



## Phishfry (Nov 9, 2017)

Checkout crochet board file:
https://github.com/freebsd/crochet/blob/master/board/RaspberryPi3/setup.sh

# Fetch the dtb
dtb="bcm2710-rpi-3-b.dtb"
fetch -o ${dtb} "${DTB_REPO}/${dtb}?raw=true"

# Fetch all the overlays we need
mkdir overlays
overlays="mmc.dtbo pi3-disable-bt.dtbo"
for i in ${overlays}; do
fetch -o overlays/${i} "${DTB_REPO}/overlays/${i}?raw=true"

So it looks like they are using the dtb which is precompiled.
Then they use DTBO to disable the GNU supported Bluetooth and MMC (FreeBSD uses different than Linux here).

So I would assume a similar method is needed from source.
Use the above github DTS and make you own DTSO with the OneWire definitions and compile into a DTBO.

You could use Crochet and inject your DTBO to save some legwork.
A user here has a nice write up on the dtso method on Beaglebone.
https://obsigna.net/?p=660
RPi3 will use the same method.


----------



## Phishfry (Nov 9, 2017)

Here is an OneWire DTSO you could give a try.
https://github.com/contactless/wb-hwconf-manager/blob/master/modules/wbe-i-w1.dtso
There are others online. You might need to try a few to find one that works.

Here is my RPi2 DTB entry. You should be able to save this as the DTSO as well.
https://forums.freebsd.org/posts/338333/
You will need the extra formatting as shown in obsigna 's blog for DTSO.


----------



## aonishenko (Nov 9, 2017)

Phishfry said:


> Here is an OneWire DTSO you could give a try.
> https://github.com/contactless/wb-hwconf-manager/blob/master/modules/wbe-i-w1.dtso
> There are others online. You might need to try a few to find one that works.



Going to check! Many thanks!


----------



## Phishfry (Dec 1, 2017)

So this overlay method did work with RPi3 with the DS3231 RTC module.

Here is the correct overlay for Pi with the official Linux w1-gpio DTS overlay.
https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/overlays/w1-gpio-overlay.dts
You must also add 'dtoverlay' entries to your Arm's config.txt
"dtoverlay=w1-gpio,gpiopin=4"

Here is a good discussion on w1-gpio on Pi.
https://www.raspberrypi.org/forums//viewtopic.php?f=107&t=156734
The w1-gpio-pullup-overlay confused me but this thread explains alot.

But the question remains can you dynamically load the kernel driver modules instead of recompiling the kernel.
Answer is, not for the RTC I got working... Still trying to get onewire overlay working on Pi3.

For my RTC dtso I also edited out all the other RTC modules and only kept ds3231.
Some of the RTC devices in the I2C-rtc overlay are not supported with a driver in FreeBSD.


----------

