User avatar
Exaga
Posts: 11
Joined: Sat Dec 21, 2013 2:21 pm
Contact: Website

DS3234 RTC Device Tree overlay

Sat Apr 17, 2021 7:47 am

Hi folks,

I've installed a DS3234 RTC on a Raspberry Pi (which uses the SPI interface) and constructed a DT overlay for it. Everything is working as expected and there are no issues with regards to timekeeping on the system.

However, I'm very aware that my Device Tree programming skills are quite basic and hoped that someone, who is more au fait in this field of knowledge, would care to throw some suggestions or advice my way on the Device Tree source code below. What have I missed out, what have I done wrong, what should I have done differently, etc?

Code: Select all

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835";

	fragment@0 {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@1 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			ds3234@0 {
				compatible = "ds3234";
				spi-max-frequency = <5000000>;
				reg = <0>;
			};
		};
	};
};
Some time ago I read a post from PhilE on these forums suggesting to look at other DT overlays and see how they are constructed to get an idea of what's required. Alas, I can't seem to find that post now, but that's basically what I've done - I looked at '/boot/overlays/spi-rtc.dtbo' overlay, and read through https://www.raspberrypi.org/documentati ... ce-tree.md a few times, then played around with the code until I managed to get it working with the DS3234 on a Raspberry Pi 4 [4GB].

Any constructive criticism would be very much appreciated. Thanks.
---
SARPi Project - Slackware ARM on a Raspberry Pi
https://sarpi.penthux.net

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3854
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: DS3234 RTC Device Tree overlay

Sat Apr 17, 2021 4:03 pm

Don't change a thing - it looks perfect.

Are you going submit a Pull Request in our Linux repo (https://github.com/raspberrypi/linux/pulls)? If you are, you could copy the pattern of the i2c-rtc overlay (https://github.com/raspberrypi/linux/bl ... verlay.dts), call it "spi-rtc", and make it a container for any SPI RTCs.

User avatar
Exaga
Posts: 11
Joined: Sat Dec 21, 2013 2:21 pm
Contact: Website

Re: DS3234 RTC Device Tree overlay

Sat Apr 17, 2021 6:39 pm

PhilE wrote:
Sat Apr 17, 2021 4:03 pm
Don't change a thing - it looks perfect.

Are you going submit a Pull Request in our Linux repo (https://github.com/raspberrypi/linux/pulls)? If you are, you could copy the pattern of the i2c-rtc overlay (https://github.com/raspberrypi/linux/bl ... verlay.dts), call it "spi-rtc", and make it a container for any SPI RTCs.
Hi PhilE,

Thanks for your reply and opinion on the Device Tree source code for the DS3234 RTC. Very pleased (and somewhat surprised) to hear that the code is all good. My only objective here was an attempt to make the DS3234 DT source code the best it could be, because I will be distributing it as part of a DS3234 Real Time Clock on a Raspberry Pi mini-project to facilitate end-users and any interested parties.

I wasn't planning on making any Pull Request in your Linux repository. However, creating a related GitHub project would be a progressive step forward and thanks for this idea.

I know the DS3234-based RTC is not nearly as popular as the DS3231, DS1307, etc. but I was a little surprised that no DT overlay already existed or source was readily available to compile. Might it be a consideration the Raspberry Pi Linux kernel developers undertake at some point in the future?
---
SARPi Project - Slackware ARM on a Raspberry Pi
https://sarpi.penthux.net

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3854
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: DS3234 RTC Device Tree overlay

Sat Apr 17, 2021 6:56 pm

If you aren't ready to start a pull request, open an issue instead, including the source of your overlay and suggesting it could become a standard overlay. I guarantee it will be accepted.

User avatar
Exaga
Posts: 11
Joined: Sat Dec 21, 2013 2:21 pm
Contact: Website

Re: DS3234 RTC Device Tree overlay

Sat Apr 17, 2021 7:19 pm

PhilE wrote:
Sat Apr 17, 2021 6:56 pm
If you aren't ready to start a pull request, open an issue instead, including the source of your overlay and suggesting it could become a standard overlay. I guarantee it will be accepted.
Hi PhilE,

Will do. Thanks for your time and effort in this. Much appreciated.
---
SARPi Project - Slackware ARM on a Raspberry Pi
https://sarpi.penthux.net

Return to “Device Tree”