[U-Boot] [PATCH 1/2] drivers/rtc: prepare mvrtc for DM conversion

Chris Packham judge.packham at gmail.com
Mon May 28 11:39:57 UTC 2018


Split the rtc_{get,set,reset} functions so that the bodies can be used
in a DM driver.

Signed-off-by: Chris Packham <judge.packham at gmail.com>
---

 drivers/rtc/mvrtc.c | 57 +++++++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/drivers/rtc/mvrtc.c b/drivers/rtc/mvrtc.c
index f2a226650fc5..f7bf95c30292 100644
--- a/drivers/rtc/mvrtc.c
+++ b/drivers/rtc/mvrtc.c
@@ -17,19 +17,16 @@
 /* This RTC does not support century, so we assume 20 */
 #define CENTURY 20
 
-int rtc_get(struct rtc_time *t)
+static int __mv_rtc_get(struct mvrtc_registers *regs, struct rtc_time *t)
 {
 	u32 time;
 	u32 date;
-	struct mvrtc_registers *mvrtc_regs;
-
-	mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
 
 	/* read the time register */
-	time = readl(&mvrtc_regs->time);
+	time = readl(&regs->time);
 
 	/* read the date register */
-	date = readl(&mvrtc_regs->date);
+	date = readl(&regs->date);
 
 	/* test for 12 hour clock (can't tell if it's am/pm) */
 	if (time & MVRTC_HRFMT_MSK) {
@@ -57,13 +54,20 @@ int rtc_get(struct rtc_time *t)
 	return 0;
 }
 
-int rtc_set(struct rtc_time *t)
+#ifndef CONFIG_DM_RTC
+int rtc_get(struct rtc_time *t)
+{
+	struct mvrtc_registers *regs;
+
+	regs = (struct mvrtc_registers *)KW_RTC_BASE;
+	return __mv_rtc_get(regs, t);
+}
+#endif /* !CONFIG_DM_RTC */
+
+static int __mv_rtc_set(struct mvrtc_registers *regs, const struct rtc_time *t)
 {
 	u32 time = 0; /* sets hour format bit to zero, 24hr format. */
 	u32 date = 0;
-	struct mvrtc_registers *mvrtc_regs;
-
-	mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
 
 	/* check that this code isn't 80+ years old ;-) */
 	if ((t->tm_year / 100) != CENTURY)
@@ -81,28 +85,45 @@ int rtc_set(struct rtc_time *t)
 	date |= (bin2bcd(t->tm_year % 100) & MVRTC_YEAR_MSK) << MVRTC_YEAR_SFT;
 
 	/* write the time register */
-	writel(time, &mvrtc_regs->time);
+	writel(time, &regs->time);
 
 	/* write the date register */
-	writel(date, &mvrtc_regs->date);
+	writel(date, &regs->date);
 
 	return 0;
 }
 
-void rtc_reset(void)
+#ifndef CONFIG_DM_RTC
+int rtc_set(struct rtc_time *t)
+{
+	struct mvrtc_registers *regs;
+
+	regs = (struct mvrtc_registers *)KW_RTC_BASE;
+	return __mv_rtc_set(regs, t);
+}
+#endif /* !CONFIG_DM_RTC */
+
+static void __mv_rtc_reset(struct mvrtc_registers *regs)
 {
 	u32 time;
 	u32 sec;
-	struct mvrtc_registers *mvrtc_regs;
-
-	mvrtc_regs = (struct mvrtc_registers *)KW_RTC_BASE;
 
 	/* no init routine for this RTC needed, just check that it's working */
-	time = readl(&mvrtc_regs->time);
+	time = readl(&regs->time);
 	sec  = bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK);
 	udelay(1000000);
-	time = readl(&mvrtc_regs->time);
+	time = readl(&regs->time);
 
 	if (sec == bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK))
 		printf("Error: RTC did not increment.\n");
 }
+
+#ifndef CONFIG_DM_RTC
+void rtc_reset(void)
+{
+	struct mvrtc_registers *regs;
+
+	regs = (struct mvrtc_registers *)KW_RTC_BASE;
+	__mv_rtc_reset(regs);
+}
+#endif /* !CONFIG_DM_RTC */
-- 
2.17.0



More information about the U-Boot mailing list