public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] drivers/rtc: prepare mvrtc for DM conversion
Date: Mon, 28 May 2018 23:39:57 +1200	[thread overview]
Message-ID: <20180528113959.5317-1-judge.packham@gmail.com> (raw)

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>
---

 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

             reply	other threads:[~2018-05-28 11:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-28 11:39 Chris Packham [this message]
2018-05-28 11:39 ` [U-Boot] [PATCH 2/2] drivers/rtc: convert mvrtc to DM Chris Packham
2018-05-29  6:46   ` Stefan Roese
2018-06-06 11:16   ` [U-Boot] [U-Boot,2/2] " Tom Rini
2018-05-29  6:45 ` [U-Boot] [PATCH 1/2] drivers/rtc: prepare mvrtc for DM conversion Stefan Roese
2018-06-06 11:16 ` [U-Boot] [U-Boot, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180528113959.5317-1-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox