drivers/rtc: prepare mvrtc for DM conversion
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@gmail.com>
Reviewed-by: Stefan Roese <sr@denx.de>
diff --git a/drivers/rtc/mvrtc.c b/drivers/rtc/mvrtc.c
index f2a2266..f7bf95c 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(®s->time);
/* read the date register */
- date = readl(&mvrtc_regs->date);
+ date = readl(®s->date);
/* test for 12 hour clock (can't tell if it's am/pm) */
if (time & MVRTC_HRFMT_MSK) {
@@ -57,13 +54,20 @@
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 @@
date |= (bin2bcd(t->tm_year % 100) & MVRTC_YEAR_MSK) << MVRTC_YEAR_SFT;
/* write the time register */
- writel(time, &mvrtc_regs->time);
+ writel(time, ®s->time);
/* write the date register */
- writel(date, &mvrtc_regs->date);
+ writel(date, ®s->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(®s->time);
sec = bcd2bin((time >> MVRTC_SEC_SFT) & MVRTC_SEC_MSK);
udelay(1000000);
- time = readl(&mvrtc_regs->time);
+ time = readl(®s->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 */