Commit 54195f1a authored by Maxime Ripard's avatar Maxime Ripard Committed by Sasha Levin

rtc: sun6i: Switch to the external oscillator

[ Upstream commit fb61bb82 ]

The RTC is clocked from either an internal, imprecise, oscillator or an
external one, which is usually much more accurate.

The difference perceived between the time elapsed and the time reported by
the RTC is in a 10% scale, which prevents the RTC from being useful at all.

Fortunately, the external oscillator is reported to be mandatory in the
Allwinner datasheet, so we can just switch to it.

Cc: stable@vger.kernel.org
Fixes: 9765d2d9 ("rtc: sun6i: Add sun6i RTC driver")
Signed-off-by: default avatarMaxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
parent cdb2a7f2
...@@ -37,9 +37,11 @@ ...@@ -37,9 +37,11 @@
/* Control register */ /* Control register */
#define SUN6I_LOSC_CTRL 0x0000 #define SUN6I_LOSC_CTRL 0x0000
#define SUN6I_LOSC_CTRL_KEY (0x16aa << 16)
#define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9) #define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9)
#define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8) #define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8)
#define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) #define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7)
#define SUN6I_LOSC_CTRL_EXT_OSC BIT(0)
#define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7) #define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7)
/* RTC */ /* RTC */
...@@ -417,6 +419,10 @@ static int sun6i_rtc_probe(struct platform_device *pdev) ...@@ -417,6 +419,10 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
/* disable alarm wakeup */ /* disable alarm wakeup */
writel(0, chip->base + SUN6I_ALARM_CONFIG); writel(0, chip->base + SUN6I_ALARM_CONFIG);
/* switch to the external, more precise, oscillator */
writel(SUN6I_LOSC_CTRL_KEY | SUN6I_LOSC_CTRL_EXT_OSC,
chip->base + SUN6I_LOSC_CTRL);
chip->rtc = rtc_device_register("rtc-sun6i", &pdev->dev, chip->rtc = rtc_device_register("rtc-sun6i", &pdev->dev,
&sun6i_rtc_ops, THIS_MODULE); &sun6i_rtc_ops, THIS_MODULE);
if (IS_ERR(chip->rtc)) { if (IS_ERR(chip->rtc)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment