Skip to contentSkip to conversation

max313xx RTC driver

PATCH In review Chris Packham 2 participants 5 messages Mar 19, 2023 – Mar 31, 2023 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

v2 cover max313xx RTC driver

This series is based on the in-flight linux patch that is adding support for this family of RTCs to linux[1]. The u-boot driver is a bit different due to some of the differences between Linux and u-boot and I've dropped the support for hwmon and clock source functions. Where possible I've tried to keep things such that the U-Boot and Linux versions can be compared and kept in sync.

For reference the datasheets are all available at

https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31328.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31329.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31331.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31334.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31341B-MAX31341C.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31342.pdf
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31343.pdf

[1] - https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Add note on which Linux version this came from
- Collect review from Simon
- Enable in sandbox for compile testing
- Note feature omissions in Kconfig
- Incorporate review comments from Simon
- Collect r-by from Simon

Chris Packham (2):
include: kernel.h: port find_closest() from Linux
drivers: rtc: add max313xx series rtc driver

 configs/sandbox_defconfig |   1 +
 drivers/rtc/Kconfig       |  13 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/max313xx.c    | 459 ++++++++++++++++++++++++++++++++++++++
 include/linux/kernel.h    |  24 ++
 5 files changed, 498 insertions(+)
 create mode 100644 drivers/rtc/max313xx.c
Signature · 1 line
2.40.0
#1 lore raw

PATCH v2 1/2 include: kernel.h: port find_closest() from Linux

The find_closest() macro can be used to find an element in a sorted array that is closest to an input value. Bring in this macro from Linux v6.3-rc1-2-g8ca09d5fa354.

---

Changes in v2:
- Add note on which Linux version this came from
- Collect review from Simon

 include/linux/kernel.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
include/linux/kernel.h +24 -0
index 3e71d61074b6..5cd6c9dc8219 100644
@@ -284,4 +284,28 @@
 	offsetof(struct structure, member) == (offset), \
 	"`struct " #structure "` offset for `" #member "` is not " #offset)
 
+#define __find_closest(x, a, as, op)					\
+({									\
+	typeof(as) __fc_i, __fc_as = (as) - 1;				\
+	typeof(x) __fc_x = (x);						\
+	typeof(*a) const *__fc_a = (a);					\
+	for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) {			\
+		if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] +	\
+						__fc_a[__fc_i + 1], 2))	\
+			break;						\
+	}								\
+	(__fc_i);							\
+})
+
+/**
+ * find_closest - locate the closest element in a sorted array
+ * @x: The reference value.
+ * @a: The array in which to look for the closest element. Must be sorted
+ *  in ascending order.
+ * @as: Size of 'a'.
+ *
+ * Returns the index of the element closest to 'x'.
+ */
+#define find_closest(x, a, as) __find_closest(x, a, as, <=)
+
 #endif
Signature · 1 line
2.40.0
#2 lore raw

Re: [PATCH v2 1/2] include: kernel.h: port find_closest() from Linux

Quoted 6 lines · Chris Packham

The find_closest() macro can be used to find an element in a sorted array that is closest to an input value. Bring in this macro from Linux v6.3-rc1-2-g8ca09d5fa354.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v2 2/2 drivers: rtc: add max313xx series rtc driver

In reply to Chris Packham

Adding support for Analog Devices MAX313XX series RTCs.

This is ported from the Linux driver and adapted for use in u-boot. Notable differences are
- handling of tm_year and tm_mon differ
- clock source support is omitted
- hwmon support for the MAX31328 and MAX31343 is omitted
- rtc_ops->reset is added

---

Changes in v2:
- Enable in sandbox for compile testing
- Note feature omissions in Kconfig
- Incorporate review comments from Simon
- Collect r-by from Simon

 configs/sandbox_defconfig |   1 +
 drivers/rtc/Kconfig       |  13 ++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/max313xx.c    | 459 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 474 insertions(+)
 create mode 100644 drivers/rtc/max313xx.c
configs/sandbox_defconfig +1 -0
index 77ade1f1d873..0c898df44672 100644
@@ -267,6 +267,7 @@ CONFIG_SANDBOX_RESET=y
 CONFIG_RESET_SYSCON=y
 CONFIG_RESET_SCMI=y
 CONFIG_DM_RTC=y
+CONFIG_RTC_MAX313XX=y
 CONFIG_RTC_RV8803=y
 CONFIG_RTC_HT1380=y
 CONFIG_SCSI=y
drivers/rtc/Kconfig +13 -0
index 35b6ed4d7c72..aae2ae61ba36 100644
@@ -134,6 +134,19 @@ config RTC_ISL1208
 	  This driver supports reading and writing the RTC/calendar and detects
 	  total power failures.
 
+config RTC_MAX313XX
+	bool "Analog Devices MAX313XX RTC driver"
+	depends on DM_RTC
+	depends on DM_I2C
+	help
+	  If you say yes here you will get support for the
+	  Analog Devices MAX313XX series RTC family.
+
+	  Chip features not currently supported:
+	  - Timestamp registers as SRAM
+	  - Temperature sensor
+	  - CLKOUT generation
+
 config RTC_PCF8563
 	tristate "Philips PCF8563"
 	help
drivers/rtc/Makefile +1 -0
index 447551e15aa2..adfa23f66702 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_RTC_HT1380) += ht1380.o
 obj-$(CONFIG_SANDBOX) += i2c_rtc_emul.o
 obj-$(CONFIG_RTC_ISL1208) += isl1208.o
 obj-$(CONFIG_RTC_M41T62) += m41t62.o
+obj-$(CONFIG_RTC_MAX313XX) += max313xx.o
 obj-$(CONFIG_RTC_MC13XXX) += mc13xxx-rtc.o
 obj-$(CONFIG_RTC_MC146818) += mc146818.o
 obj-$(CONFIG_MCFRTC) += mcfrtc.o
drivers/rtc/max313xx.c new file +459 -0

459 lines not on this page · raw message

Signature · 1 line
2.40.0
#4 lore raw

Re: [PATCH v2 2/2] drivers: rtc: add max313xx series rtc driver

Quoted 11 lines · Chris Packham

Adding support for Analog Devices MAX313XX series RTCs.

This is ported from the Linux driver and adapted for use in u-boot. Notable differences are
- handling of tm_year and tm_mon differ
- clock source support is omitted
- hwmon support for the MAX31328 and MAX31343 is omitted
- rtc_ops->reset is added

Applied to u-boot/next, thanks!

Signature · 1 line
Tom