DS3232 is an i2c RTC with 236 bytes of battery-backed SRAM.
Add an RTC driver for DS3232 device, which provides time and
date support. Also read and write functions are provided,
which can be used to access the SRAM memory.
Signed-off-by: Nandor Han
---
Notes:
Description
--
Add support for RTC DS3232 device.
Testing
--
1. Check that date/time can be reset: PASS
U-Boot> date reset
Reset RTC...
Date: 2000-01-01 (Saturday)Time: 0:00:00
2. Check that setting the date/time is successful: PASS
U-Boot> date 040114012019.00
Date: 2019-04-01 (Monday)Time: 14:01:00
3. Check that getting the date/time is successful: PASS
U-Boot> date
Date: 2019-04-01 (Monday)Time: 14:01:58
4. Verify that the date configured in U-Boot is the same read in Kernel.
doc/device-tree-bindings/rtc/ds3232.txt | 15 ++
drivers/rtc/Kconfig | 8 +
drivers/rtc/Makefile| 1 +
drivers/rtc/ds3232.c| 274
4 files changed, 298 insertions(+)
create mode 100644 doc/device-tree-bindings/rtc/ds3232.txt
create mode 100644 drivers/rtc/ds3232.c
diff --git a/doc/device-tree-bindings/rtc/ds3232.txt
b/doc/device-tree-bindings/rtc/ds3232.txt
new file mode 100644
index 00..254b7bc3c3
--- /dev/null
+++ b/doc/device-tree-bindings/rtc/ds3232.txt
@@ -0,0 +1,15 @@
+DS3232 Real-Time Clock with SRAM
+
+The RTC driver provides time and date functionality. Also read and write
+functions are provided that can be used to access the SRAM memory.
+
+Required properties:
+- compatible : should contain "dallas,ds3232"
+- reg: the I2C RTC address
+
+Example:
+
+rtc@68 {
+ compatible = "dallas,ds3232";
+ reg = <0x68>;
+};
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8778cc7b26..a82f79bf16 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -54,6 +54,14 @@ config RTC_DS1307
Support for Dallas Semiconductor (now Maxim) DS1307 and DS1338/9 and
compatible Real Time Clock devices.
+config RTC_DS3232
+ bool "Enable DS3232 driver"
+ depends on DM_RTC
+ depends on DM_I2C
+ help
+ Support for Dallas Semiconductor (now Maxim) DS3232 compatible
+ Real Time Clock devices.
+
config RTC_ISL1208
bool "Enable ISL1208 driver"
depends on DM_RTC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index f97a669982..e89de73b11 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_RTC_DS1556) += ds1556.o
obj-$(CONFIG_RTC_DS164x) += ds164x.o
obj-$(CONFIG_RTC_DS174x) += ds174x.o
obj-$(CONFIG_RTC_DS3231) += ds3231.o
+obj-$(CONFIG_RTC_DS3232) += ds3232.o
obj-$(CONFIG_RTC_FTRTC010) += ftrtc010.o
obj-$(CONFIG_SANDBOX) += i2c_rtc_emul.o
obj-$(CONFIG_RTC_IMXDI) += imxdi.o
diff --git a/drivers/rtc/ds3232.c b/drivers/rtc/ds3232.c
new file mode 100644
index 00..09a106aa4e
--- /dev/null
+++ b/drivers/rtc/ds3232.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019, Vaisala Oyj
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+/*
+ * RTC register addresses
+ */
+#define RTC_SEC_REG_ADDR 0x00
+#define RTC_MIN_REG_ADDR 0x01
+#define RTC_HR_REG_ADDR0x02
+#define RTC_DAY_REG_ADDR 0x03
+#define RTC_DATE_REG_ADDR 0x04
+#define RTC_MON_REG_ADDR 0x05
+#define RTC_YR_REG_ADDR0x06
+#define RTC_CTL_REG_ADDR 0x0e
+#define RTC_STAT_REG_ADDR 0x0f
+#define RTC_TEST_REG_ADDR 0x13
+
+/*
+ * RTC control register bits
+ */
+#define RTC_CTL_BIT_A1IE BIT(0) /* Alarm 1 interrupt enable */
+#define RTC_CTL_BIT_A2IE BIT(1) /* Alarm 2 interrupt enable */
+#define RTC_CTL_BIT_INTCN BIT(2) /* Interrupt control*/
+#define RTC_CTL_BIT_DOSC BIT(7) /* Disable Oscillator */
+
+/*
+ * RTC status register bits
+ */
+#define RTC_STAT_BIT_A1F BIT(0) /* Alarm 1 flag */
+#define RTC_STAT_BIT_A2F BIT(1) /* Alarm 2 flag */
+#define RTC_STAT_BIT_EN32KHZ BIT(3) /* Enable 32KHz Output */
+#define RTC_STAT_BIT_BB32KHZ BIT(6) /* Battery backed 32KHz Output */
+#define RTC_STAT_BIT_OSF BIT(7) /* Oscillator stop flag */
+
+/*
+ * RTC test register bits
+ */
+#define RTC_TEST_BIT_SWRST BIT(7) /* Software reset */
+
+#define RTC_DATE_TIME_REG_SIZE 7
+#define RTC_SRAM_START 0x14
+#define RTC_SRAM_END 0xFF
+#define RTC_SRAM_SIZE 236
+
+struct ds3232_priv_data {
+ u8 max_register;
+ u8 sram_start;
+ int sram_size;
+};
+
+static int ds3232_rtc_read8(struct udevice *dev, unsigned int reg)
+{
+ int ret;
+ u8 buf;
+ struct ds3232_priv_data *priv_data;
+
+ priv_data = dev_get_priv(dev);
+ if (!priv_data)
+ return -EINVAL;
+
+ if (reg >