From: Stephan Roslen <stephan@roslen.de>
To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com,
maxime.ripard@free-electrons.com, wens@csie.org,
rtc-linux@googlegroups.com
Subject: [rtc-linux] [PATCH] rtc: sunxi: use external oscillator
Date: Wed, 6 Jul 2016 10:43:00 +0200 [thread overview]
Message-ID: <577CC494.8020103@roslen.de> (raw)
We noticed some serious drift problems in Allwinner A20 RTCs. I found out, that the oscillator source needs to be set to an external 32.768 KHz oscillator instead of the internal 32.000 KHz oscillator.
Signed-off-by: Stephan Roslen <stephan@roslen.de>
---
drivers/rtc/rtc-sunxi.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c
index abada60..001256e 100644
--- a/drivers/rtc/rtc-sunxi.c
+++ b/drivers/rtc/rtc-sunxi.c
@@ -34,9 +34,19 @@
#include <linux/types.h>
#define SUNXI_LOSC_CTRL 0x0000
+
+/* magic number required to set bit 0 */
+#define SUNXI_LOSC_CTRL_KEY 0x16AA0000
+
+#define SUNXI_LOSC_CTRL_AUTO_SWT_EN BIT(14)
+
#define SUNXI_LOSC_CTRL_RTC_HMS_ACC BIT(8)
#define SUNXI_LOSC_CTRL_RTC_YMD_ACC BIT(7)
+#define SUNXI_LOSC_CTRL_EXT_GSM1 BIT(3)
+#define SUNXI_LOSC_CTRL_EXT_GSM0 BIT(2)
+#define SUNXI_LOSC_CTRL_SRC_SEL BIT(0)
+
#define SUNXI_RTC_YMD 0x0004
#define SUNXI_RTC_HMS 0x0008
@@ -438,6 +448,8 @@ static int sunxi_rtc_probe(struct platform_device *pdev)
struct resource *res;
int ret;
+ uint32_t loscctrl;
+
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;
@@ -468,6 +480,19 @@ static int sunxi_rtc_probe(struct platform_device *pdev)
return -ENODEV;
}
+ loscctrl = readl(chip->base + SUNXI_LOSC_CTRL);
+ loscctrl &= ~(SUNXI_LOSC_CTRL_AUTO_SWT_EN);
+ loscctrl |= (SUNXI_LOSC_CTRL_SRC_SEL | SUNXI_LOSC_CTRL_KEY);
+ loscctrl |= SUNXI_LOSC_CTRL_EXT_GSM1;
+ writel(loscctrl, chip->base + SUNXI_LOSC_CTRL);
+ udelay(100);
+
+ loscctrl = readl(chip->base + SUNXI_LOSC_CTRL);
+ if (!(loscctrl & SUNXI_LOSC_CTRL_SRC_SEL)) {
+ dev_err(&pdev->dev, "Error: Set LOSC to external failed.\n");
+ dev_err(&pdev->dev, "Warning: RTC time will be wrong!\n");
+ }
+
/* clear the alarm count value */
writel(0, chip->base + SUNXI_ALRM_DHMS);
--
2.7.4
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
next reply other threads:[~2016-07-06 8:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-06 8:43 Stephan Roslen [this message]
2016-07-06 20:20 ` [rtc-linux] Re: [PATCH] rtc: sunxi: use external oscillator Maxime Ripard
2016-07-07 4:50 ` Stephan Roslen
2016-07-07 4:53 ` Chen-Yu Tsai
2016-07-07 6:12 ` Stephan Roslen
2016-07-07 7:08 ` Maxime Ripard
2016-07-07 6:42 ` Maxime Ripard
2016-07-07 5:11 ` Stephan Roslen
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=577CC494.8020103@roslen.de \
--to=stephan@roslen.de \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@free-electrons.com \
--cc=maxime.ripard@free-electrons.com \
--cc=rtc-linux@googlegroups.com \
--cc=wens@csie.org \
/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