Skip to contentSkip to conversation

rtc: Add RK808 PMIC RTC

PATCH In review Jagan Teki 3 participants 10 messages Jul 10, 2020 – Jul 21, 2020

Subsystems (3)
lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

v4 cover rtc: Add RK808 PMIC RTC

This series support RK808 PMIC RTC on rk3399.

Changes for v4:
- rebase on master
- cleanup of style changes

Any inputs?
Jagan.

Suniel Mahesh (4):
arm: dts: rockchip: rk3399-roc-pc: Add RTC child node for RK808 PMIC
power: pmic: rk8xx: bind rk808 RTC
rtc: rk8xx: Add base support for the RK808 PMIC RTC
roc-rk3399-pc: Enable DM RTC

 arch/arm/dts/rk3399-roc-pc-u-boot.dtsi    |   8 +
 configs/roc-pc-mezzanine-rk3399_defconfig |   1 +
 configs/roc-pc-rk3399_defconfig           |   1 +
 drivers/power/pmic/rk8xx.c                |  19 ++-
 drivers/rtc/Kconfig                       |   8 +
 drivers/rtc/Makefile                      |   1 +
 drivers/rtc/rk808-rtc.c                   | 173 ++++++++++++++++++++++
 7 files changed, 210 insertions(+), 1 deletion(-)
 create mode 100644 drivers/rtc/rk808-rtc.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v4 1/4 arm: dts: rockchip: rk3399-roc-pc: Add RTC child node for RK808 PMIC

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC is a multi function device which hosts a Real Time Clock along with other devices. Add a child RTC node so that it can be bound and probed once the master pmic node completes probe.

---
Change for v4:
- none

 arch/arm/dts/rk3399-roc-pc-u-boot.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/dts/rk3399-roc-pc-u-boot.dtsi +8 -0
index fc155e6903..16d6417160 100644
@@ -44,6 +44,14 @@
 	vin-supply = <&vcc_vbus_typec0>;
 };
 
+&rk808 {
+	rtc {
+		rkrtc: rk808-rtc {
+			status="okay";
+		};
+	};
+};
+
 &spi1 {
 	spi_flash: flash@0 {
 		u-boot,dm-pre-reloc;
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v4 2/4 power: pmic: rk8xx: bind rk808 RTC

In reply to Jagan Teki

From: Suniel Mahesh <[email protected]>

RK808 PMIC is a multi functional device with an RTC. In order to access RTC, bind to its parent device i.e. RK808 PMIC.

---
Change for v4:
- none

 drivers/power/pmic/rk8xx.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/power/pmic/rk8xx.c +18 -1
index 195884bde9..aea9272f8a 100644
@@ -25,6 +25,11 @@ static const struct pmic_child_info pmic_children_info[] = {
 	{ },
 };
 
+static const struct pmic_child_info rtc_info[] = {
+	{ .prefix = "rk808-rtc", .driver = "rk808_rtc"},
+	{ },
+};
+
 static int rk8xx_reg_count(struct udevice *dev)
 {
 	return RK808_NUM_OF_REGS;
@@ -60,7 +65,7 @@ static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
 static int rk8xx_bind(struct udevice *dev)
 {
-	ofnode regulators_node;
+	ofnode regulators_node, rtc_node;
 	int children;
 
 	regulators_node = dev_read_subnode(dev, "regulators");
@@ -76,6 +81,18 @@ static int rk8xx_bind(struct udevice *dev)
 	if (!children)
 		debug("%s: %s - no child found\n", __func__, dev->name);
 
+	rtc_node = dev_read_subnode(dev, "rtc");
+	if (!ofnode_valid(rtc_node)) {
+		debug("%s: %s rtc subnode not found!\n", __func__, dev->name);
+		return -ENXIO;
+	}
+
+	debug("%s: '%s' - found rtc subnode\n", __func__, dev->name);
+
+	children = pmic_bind_children(dev, rtc_node, rtc_info);
+	if (!children)
+		debug("%s: %s - no child found\n", __func__, dev->name);
+
 	/* Always return success for this device */
 	return 0;
 }
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v4 3/4 rtc: rk8xx: Add base support for the RK808 PMIC RTC

In reply to Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

---
Change for v4:
- rebase
- style fixes
- warning fixes

 drivers/rtc/Kconfig     |   8 ++
 drivers/rtc/Makefile    |   1 +
 drivers/rtc/rk808-rtc.c | 173 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 182 insertions(+)
 create mode 100644 drivers/rtc/rk808-rtc.c
drivers/rtc/Kconfig +8 -0
index 59e2fc44ba..a754d1b4f1 100644
@@ -75,6 +75,14 @@ config RTC_ISL1208
 	  This driver supports reading and writing the RTC/calendar and detects
 	  total power failures.
 
+config RTC_RK808
+	bool "Enable Rockchip RK8XX RTC driver"
+        depends on DM_RTC && PMIC_RK8XX
+	default y
+	help
+	  Basic support for Rockchip RK808 PMIC Real Time Clock devices for
+	  time and date.
+
 config RTC_RV3029
 	bool "Enable RV3029 driver"
 	depends on DM_RTC
drivers/rtc/Makefile +1 -0
index 12eb449583..63e2c3413d 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_PCF8563) += pcf8563.o
 obj-$(CONFIG_RTC_PCF2127) += pcf2127.o
 obj-$(CONFIG_RTC_PL031) += pl031.o
 obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
+obj-$(CONFIG_RTC_RK808) += rk808-rtc.o
 obj-$(CONFIG_RTC_RS5C372A) += rs5c372.o
 obj-$(CONFIG_RTC_RV3029) += rv3029.o
 obj-$(CONFIG_RTC_RV8803) += rv8803.o
drivers/rtc/rk808-rtc.c new file +173 -0

173 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v4 3/4] rtc: rk8xx: Add base support for the RK808 PMIC RTC

Quoted 8 lines · Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

---

Quoted 231 lines

Change for v4:
- rebase
- style fixes
- warning fixes

 drivers/rtc/Kconfig     |   8 ++
 drivers/rtc/Makefile    |   1 +
 drivers/rtc/rk808-rtc.c | 173 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 182 insertions(+)
 create mode 100644 drivers/rtc/rk808-rtc.c
drivers/rtc/Kconfig +0 -0
index 59e2fc44ba..a754d1b4f1 100644
@@ -75,6 +75,14 @@ config RTC_ISL1208
          This driver supports reading and writing the RTC/calendar and

detects
total power failures.

drivers/rtc/Kconfig +8 -0
+config RTC_RK808
+       bool "Enable Rockchip RK8XX RTC driver"
+        depends on DM_RTC && PMIC_RK8XX
+       default y
+       help
+         Basic support for Rockchip RK808 PMIC Real Time Clock devices for
+         time and date.
+
 config RTC_RV3029
        bool "Enable RV3029 driver"
        depends on DM_RTC
drivers/rtc/Makefile +1 -0
index 12eb449583..63e2c3413d 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_PCF8563) += pcf8563.o
 obj-$(CONFIG_RTC_PCF2127) += pcf2127.o
 obj-$(CONFIG_RTC_PL031) += pl031.o
 obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
+obj-$(CONFIG_RTC_RK808) += rk808-rtc.o
 obj-$(CONFIG_RTC_RS5C372A) += rs5c372.o
 obj-$(CONFIG_RTC_RV3029) += rv3029.o
 obj-$(CONFIG_RTC_RV8803) += rv8803.o
drivers/rtc/rk808-rtc.c new file +89 -0
new file mode 100644
index 0000000000..50cca4dd4b
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * RTC driver for Rockchip RK808 PMIC.
+ *
+ * Copyright (C) 2020 Amarula Solutions(India).
+ * Suniel Mahesh <[email protected]>
+ *
+ * Based on code from Linux kernel:
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ * Author: Chris Zhong <[email protected]>
+ * Author: Zhang Qing <[email protected]>
+ *
+ * Date & Time support (no alarms and interrupts)
+ */
+
+#include <command.h>
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <rtc.h>
+#include <power/rk8xx_pmic.h>
+#include <power/pmic.h>
+#include <linux/bitops.h>
+#include <linux/compat.h>
+
+/* RTC_CTRL_REG bitfields */
+#define BIT_RTC_CTRL_REG_STOP_RTC_M            BIT(0)
+
+/* RK808 has a shadowed register for saving a "frozen" RTC time.
+ * When user setting "GET_TIME" to 1, the time will save in this shadowed
+ * register. If set "READSEL" to 1, user read rtc time register, actually
+ * get the time of that moment. If we need the real time, clr this bit.
+ */
+
+#define BIT_RTC_CTRL_REG_RTC_GET_TIME          BIT(6)
+#define BIT_RTC_CTRL_REG_RTC_READSEL_M         BIT(7)
+#define RTC_STATUS_MASK                                0xFE
+
+#define SECONDS_REG_MSK                                0x7F
+#define MINUTES_REG_MAK                                0x7F
+#define HOURS_REG_MSK                          0x3F
+#define DAYS_REG_MSK                           0x3F
+#define MONTHS_REG_MSK                         0x1F
+#define YEARS_REG_MSK                          0xFF
+#define WEEKS_REG_MSK                          0x7
+
+/* REG_SECONDS_REG through REG_YEARS_REG is how many registers? */
+
+#define NUM_TIME_REGS  (REG_WEEKS - REG_SECONDS + 1)
+
+static int rk808_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+       u8 rtc_data[NUM_TIME_REGS];
+
+       debug("RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+             tm->tm_year, tm->tm_mon, tm->tm_mday,
+             tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+       rtc_data[0] = bin2bcd(tm->tm_sec);
+       rtc_data[1] = bin2bcd(tm->tm_min);
+       rtc_data[2] = bin2bcd(tm->tm_hour);
+       rtc_data[3] = bin2bcd(tm->tm_mday);
+       rtc_data[4] = bin2bcd(tm->tm_mon);
+       rtc_data[5] = bin2bcd(tm->tm_year - 2000);
+       rtc_data[6] = bin2bcd(tm->tm_wday);
+
+       /* Stop RTC while updating the RTC registers */
+       pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+                       BIT_RTC_CTRL_REG_STOP_RTC_M);
+       pmic_write(dev->parent, REG_SECONDS, rtc_data, NUM_TIME_REGS);
+
+       /* Start RTC again */
+       pmic_clrsetbits(dev->parent, REG_RTC_CTRL,
+                       BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
+
+       return 0;
+}
+
+static int rk808_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+       u8 rtc_data[NUM_TIME_REGS];
+
+       /* Force an update of the shadowed registers right now */
+       pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+                       BIT_RTC_CTRL_REG_RTC_GET_TIME);
+
+       /*
+        * After we set the GET_TIME bit, the rtc time can't be read
+        * immediately. So we should wait up to 31.25 us, about one cycle

of
+ * 32khz. If we clear the GET_TIME bit here, the time of i2c
transfer

drivers/rtc/rk808-rtc.c new file +16 -0
+        * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
+        */
+       pmic_clrsetbits(dev->parent, REG_RTC_CTRL,
+                       BIT_RTC_CTRL_REG_RTC_GET_TIME, 0);
+       pmic_read(dev->parent, REG_SECONDS, rtc_data, NUM_TIME_REGS);
+
+       tm->tm_sec = bcd2bin(rtc_data[0] & SECONDS_REG_MSK);
+       tm->tm_min = bcd2bin(rtc_data[1] & MINUTES_REG_MAK);
+       tm->tm_hour = bcd2bin(rtc_data[2] & HOURS_REG_MSK);
+       tm->tm_mday = bcd2bin(rtc_data[3] & DAYS_REG_MSK);
+       tm->tm_mon = (bcd2bin(rtc_data[4] & MONTHS_REG_MSK));
+       tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 2000;
+       tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK);
+
+       /*
+        * RK808 PMIC RTC h/w counts/has 31 days in november. This is

corrected
+ * when date cmd is invoked on prompt. checks for the current day
and

drivers/rtc/rk808-rtc.c new file +3 -0
+        * if it is 31 November, then adjusts it to 1 December.
+        *
+        * h/w also has weeks register which counts from 0 to

7(0(sun)-6(sat)).

drivers/rtc/rk808-rtc.c new file +63 -1
+        * 7 is an unknown state, reset it back to 0(sun).
+        */
+       if (tm->tm_mon == 11 && tm->tm_mday == 31) {
+               debug("correcting Nov 31st to Dec 1st (HW bug)\n");
+               tm->tm_mon += 1;
+               tm->tm_mday = 1;
+               if (tm->tm_wday == 7)
+                       tm->tm_wday = 0;
+               rk808_rtc_set(dev, tm);
+       }
+
+       if (tm->tm_wday == 7) {
+               tm->tm_wday = 0;
+               rk808_rtc_set(dev, tm);
+       }
+
+       debug("RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+             tm->tm_year, tm->tm_mon, tm->tm_mday,
+             tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+       return 0;
+}
+
+static int rk808_rtc_reset(struct udevice *dev)
+{
+/* Not needed */
+       return 0;
+}
+
+static int rk808_rtc_init(struct udevice *dev)
+{
+       struct rtc_time tm;
+
+       /* start rtc running by default, and use shadowed timer. */
+       pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+                       BIT_RTC_CTRL_REG_RTC_READSEL_M);
+       pmic_reg_write(dev->parent, REG_RTC_STATUS, RTC_STATUS_MASK);
+
+       /* set init time */
+       rk808_rtc_get(dev, &tm);
+
+       return 0;
+}
+
+static int rk808_rtc_probe(struct udevice *dev)
+{
+       rk808_rtc_init(dev);
+
+       return 0;
+}
+
+static const struct rtc_ops rk808_rtc_ops = {
+       .get = rk808_rtc_get,
+       .set = rk808_rtc_set,
+       .reset = rk808_rtc_reset,
+};
+
+U_BOOT_DRIVER(rk808_rtc) = {
+       .name     = "rk808_rtc",
+       .id       = UCLASS_RTC,
+       .ops      = &rk808_rtc_ops,
+       .probe    = rk808_rtc_probe,
+};
--

2.25.1

#5 lore raw

Re: [PATCH v4 3/4] rtc: rk8xx: Add base support for the RK808 PMIC RTC

In reply to Jagan Teki

Hi Jagan,

Quoted 6 lines · Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

Quoted 6 lines

---
Change for v4:
- rebase
- style fixes
- warning fixes

Seems like the change request by Elaine in previous version does not update ?

Thanks,

- Kever

Quoted 217 lines
  drivers/rtc/Kconfig     |   8 ++
  drivers/rtc/Makefile    |   1 +
  drivers/rtc/rk808-rtc.c | 173 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 182 insertions(+)

create mode 100644 drivers/rtc/rk808-rtc.c

drivers/rtc/Kconfig +8 -0
index 59e2fc44ba..a754d1b4f1 100644
@@ -75,6 +75,14 @@ config RTC_ISL1208
  	  This driver supports reading and writing the RTC/calendar and detects
  	  total power failures.
 
+config RTC_RK808
+	bool "Enable Rockchip RK8XX RTC driver"
+        depends on DM_RTC && PMIC_RK8XX
+	default y
+	help
+	  Basic support for Rockchip RK808 PMIC Real Time Clock devices for
+	  time and date.
+
  config RTC_RV3029
  	bool "Enable RV3029 driver"
  	depends on DM_RTC
drivers/rtc/Makefile +1 -0
index 12eb449583..63e2c3413d 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_RTC_PCF8563) += pcf8563.o
  obj-$(CONFIG_RTC_PCF2127) += pcf2127.o
  obj-$(CONFIG_RTC_PL031) += pl031.o
  obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
+obj-$(CONFIG_RTC_RK808) += rk808-rtc.o
  obj-$(CONFIG_RTC_RS5C372A) += rs5c372.o
  obj-$(CONFIG_RTC_RV3029) += rv3029.o
  obj-$(CONFIG_RTC_RV8803) += rv8803.o
drivers/rtc/rk808-rtc.c new file +173 -0
new file mode 100644
index 0000000000..50cca4dd4b
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * RTC driver for Rockchip RK808 PMIC.
+ *
+ * Copyright (C) 2020 Amarula Solutions(India).
+ * Suniel Mahesh <[email protected]>
+ *
+ * Based on code from Linux kernel:
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ * Author: Chris Zhong <[email protected]>
+ * Author: Zhang Qing <[email protected]>
+ *
+ * Date & Time support (no alarms and interrupts)
+ */
+
+#include <command.h>
+#include <common.h>
+#include <dm.h>
+#include <i2c.h>
+#include <rtc.h>
+#include <power/rk8xx_pmic.h>
+#include <power/pmic.h>
+#include <linux/bitops.h>
+#include <linux/compat.h>
+
+/* RTC_CTRL_REG bitfields */
+#define BIT_RTC_CTRL_REG_STOP_RTC_M		BIT(0)
+
+/* RK808 has a shadowed register for saving a "frozen" RTC time.
+ * When user setting "GET_TIME" to 1, the time will save in this shadowed
+ * register. If set "READSEL" to 1, user read rtc time register, actually
+ * get the time of that moment. If we need the real time, clr this bit.
+ */
+
+#define BIT_RTC_CTRL_REG_RTC_GET_TIME		BIT(6)
+#define BIT_RTC_CTRL_REG_RTC_READSEL_M		BIT(7)
+#define RTC_STATUS_MASK				0xFE
+
+#define SECONDS_REG_MSK				0x7F
+#define MINUTES_REG_MAK				0x7F
+#define HOURS_REG_MSK				0x3F
+#define DAYS_REG_MSK				0x3F
+#define MONTHS_REG_MSK				0x1F
+#define YEARS_REG_MSK				0xFF
+#define WEEKS_REG_MSK				0x7
+
+/* REG_SECONDS_REG through REG_YEARS_REG is how many registers? */
+
+#define NUM_TIME_REGS	(REG_WEEKS - REG_SECONDS + 1)
+
+static int rk808_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+	u8 rtc_data[NUM_TIME_REGS];
+
+	debug("RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+	      tm->tm_year, tm->tm_mon, tm->tm_mday,
+	      tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+	rtc_data[0] = bin2bcd(tm->tm_sec);
+	rtc_data[1] = bin2bcd(tm->tm_min);
+	rtc_data[2] = bin2bcd(tm->tm_hour);
+	rtc_data[3] = bin2bcd(tm->tm_mday);
+	rtc_data[4] = bin2bcd(tm->tm_mon);
+	rtc_data[5] = bin2bcd(tm->tm_year - 2000);
+	rtc_data[6] = bin2bcd(tm->tm_wday);
+
+	/* Stop RTC while updating the RTC registers */
+	pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+			BIT_RTC_CTRL_REG_STOP_RTC_M);
+	pmic_write(dev->parent, REG_SECONDS, rtc_data, NUM_TIME_REGS);
+
+	/* Start RTC again */
+	pmic_clrsetbits(dev->parent, REG_RTC_CTRL,
+			BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
+
+	return 0;
+}
+
+static int rk808_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+	u8 rtc_data[NUM_TIME_REGS];
+
+	/* Force an update of the shadowed registers right now */
+	pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+			BIT_RTC_CTRL_REG_RTC_GET_TIME);
+
+	/*
+	 * After we set the GET_TIME bit, the rtc time can't be read
+	 * immediately. So we should wait up to 31.25 us, about one cycle of
+	 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
+	 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
+	 */
+	pmic_clrsetbits(dev->parent, REG_RTC_CTRL,
+			BIT_RTC_CTRL_REG_RTC_GET_TIME, 0);
+	pmic_read(dev->parent, REG_SECONDS, rtc_data, NUM_TIME_REGS);
+
+	tm->tm_sec = bcd2bin(rtc_data[0] & SECONDS_REG_MSK);
+	tm->tm_min = bcd2bin(rtc_data[1] & MINUTES_REG_MAK);
+	tm->tm_hour = bcd2bin(rtc_data[2] & HOURS_REG_MSK);
+	tm->tm_mday = bcd2bin(rtc_data[3] & DAYS_REG_MSK);
+	tm->tm_mon = (bcd2bin(rtc_data[4] & MONTHS_REG_MSK));
+	tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 2000;
+	tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK);
+
+	/*
+	 * RK808 PMIC RTC h/w counts/has 31 days in november. This is corrected
+	 * when date cmd is invoked on prompt. checks for the current day and
+	 * if it is 31 November, then adjusts it to 1 December.
+	 *
+	 * h/w also has weeks register which counts from 0 to 7(0(sun)-6(sat)).
+	 * 7 is an unknown state, reset it back to 0(sun).
+	 */
+	if (tm->tm_mon == 11 && tm->tm_mday == 31) {
+		debug("correcting Nov 31st to Dec 1st (HW bug)\n");
+		tm->tm_mon += 1;
+		tm->tm_mday = 1;
+		if (tm->tm_wday == 7)
+			tm->tm_wday = 0;
+		rk808_rtc_set(dev, tm);
+	}
+
+	if (tm->tm_wday == 7) {
+		tm->tm_wday = 0;
+		rk808_rtc_set(dev, tm);
+	}
+
+	debug("RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
+	      tm->tm_year, tm->tm_mon, tm->tm_mday,
+	      tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+	return 0;
+}
+
+static int rk808_rtc_reset(struct udevice *dev)
+{
+/* Not needed */
+	return 0;
+}
+
+static int rk808_rtc_init(struct udevice *dev)
+{
+	struct rtc_time tm;
+
+	/* start rtc running by default, and use shadowed timer. */
+	pmic_clrsetbits(dev->parent, REG_RTC_CTRL, 0,
+			BIT_RTC_CTRL_REG_RTC_READSEL_M);
+	pmic_reg_write(dev->parent, REG_RTC_STATUS, RTC_STATUS_MASK);
+
+	/* set init time */
+	rk808_rtc_get(dev, &tm);
+
+	return 0;
+}
+
+static int rk808_rtc_probe(struct udevice *dev)
+{
+	rk808_rtc_init(dev);
+
+	return 0;
+}
+
+static const struct rtc_ops rk808_rtc_ops = {
+	.get = rk808_rtc_get,
+	.set = rk808_rtc_set,
+	.reset = rk808_rtc_reset,
+};
+
+U_BOOT_DRIVER(rk808_rtc) = {
+	.name     = "rk808_rtc",
+	.id       = UCLASS_RTC,
+	.ops      = &rk808_rtc_ops,
+	.probe    = rk808_rtc_probe,
+};
author
#6 lore raw

Re: [PATCH v4 3/4] rtc: rk8xx: Add base support for the RK808 PMIC RTC

Hi Kever,

Quoted 18 lines · Kever Yang

Hi Jagan,

Quoted 6 lines · Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

Quoted 6 lines

---
Change for v4:
- rebase
- style fixes
- warning fixes

Quoted 2 lines

Seems like the change request by Elaine in previous version does not update ?

Yes, It requires the additional function to add that feature. We are still working on it in proper shape and thinking this series as initial support. Can you push this so-that we can send that feature before rc2 or rc3?

Jagan.

#7 lore raw

PATCH v4 3/4 rtc: rk8xx: Add base support for the RK808 PMIC RTC

Quoted 19 lines · Jagan Teki

Hi Kever,

Quoted 16 lines · Kever Yang

Hi Jagan,

Quoted 12 lines · Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

---
Change for v4:
- rebase
- style fixes
- warning fixes

Quoted 3 lines
Quoted 2 lines

Seems like the change request by Elaine in previous version does not update ?

Yes, It requires the additional function to add that feature.

No only new feature required, but also wrong implementation for function.

Again, what do you want the RTC in U-Boot used for?

Thanks,

- Kever

Quoted 8 lines

We are
still working on it in proper shape and thinking this series as initial support. Can you push this so-that we can send that feature before rc2 or rc3?

Jagan.

#8 lore raw

PATCH v4 3/4 rtc: rk8xx: Add base support for the RK808 PMIC RTC

Hi kever,

Quoted 22 lines · Kever Yang
Quoted 3 lines · Jagan Teki

Hi Kever,

On Sat, Jul 18, 2020 at 5:41 PM Kever Yang <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines

Hi Jagan,

Quoted 12 lines · Jagan Teki

From: Suniel Mahesh <[email protected]>

Rockchip RK808 PMIC provides an integrated RTC module. It is commonly used with Rockchip SoCs. Add basic support to access date and time.

---
Change for v4:
- rebase
- style fixes
- warning fixes

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Seems like the change request by Elaine in previous version does not update ?

Yes, It requires the additional function to add that feature.

No only new feature required, but also wrong implementation for function.

Yes the implementation doesn't take into effect the hardware bug (31 days for november month).
Elaine also pointed out the same in the past.

Again, what do you want the RTC in U-Boot used for?

Quoted 1 line

The intention here is to add hardware driver support for any usage in uboot. Cant this
patch be considered as the initial support, we will send the corrections as per Linux ASAP.

Regards
Suniel

Quoted 17 lines

Thanks,

- Kever

Quoted 8 lines

We are
still working on it in proper shape and thinking this series as initial support. Can you push this so-that we can send that feature before rc2 or rc3?

Jagan.

author
#9 lore raw

PATCH v4 4/4 roc-rk3399-pc: Enable DM RTC

In reply to Jagan Teki

From: Suniel Mahesh <[email protected]>

Enable rtc driver DM for rk808 PMIC's.

---
Change for v4:
- drop CMD_DATE

 configs/roc-pc-mezzanine-rk3399_defconfig | 1 +
 configs/roc-pc-rk3399_defconfig           | 1 +
 2 files changed, 2 insertions(+)
configs/roc-pc-mezzanine-rk3399_defconfig +1 -0
index 3ceecf753f..20a0e03b12 100644
@@ -57,6 +57,7 @@ CONFIG_REGULATOR_RK8XX=y
 CONFIG_PWM_ROCKCHIP=y
 CONFIG_RAM_RK3399_LPDDR4=y
 CONFIG_DM_RESET=y
+CONFIG_DM_RTC=y
 CONFIG_BAUDRATE=1500000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_ROCKCHIP_SPI=y
configs/roc-pc-rk3399_defconfig +1 -0
index 6943d4fd54..e6627ac56a 100644
@@ -54,6 +54,7 @@ CONFIG_REGULATOR_RK8XX=y
 CONFIG_PWM_ROCKCHIP=y
 CONFIG_RAM_RK3399_LPDDR4=y
 CONFIG_DM_RESET=y
+CONFIG_DM_RTC=y
 CONFIG_BAUDRATE=1500000
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_ROCKCHIP_SPI=y
Signature · 1 line
2.25.1