Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: sun6i: Switch to the external oscillator

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: 9765d2d94309 ("rtc: sun6i: Add sun6i RTC driver")
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Maxime Ripard and committed by
Alexandre Belloni
fb61bb82 a9422a19

+6
+6
drivers/rtc/rtc-sun6i.c
··· 37 37 38 38 /* Control register */ 39 39 #define SUN6I_LOSC_CTRL 0x0000 40 + #define SUN6I_LOSC_CTRL_KEY (0x16aa << 16) 40 41 #define SUN6I_LOSC_CTRL_ALM_DHMS_ACC BIT(9) 41 42 #define SUN6I_LOSC_CTRL_RTC_HMS_ACC BIT(8) 42 43 #define SUN6I_LOSC_CTRL_RTC_YMD_ACC BIT(7) 44 + #define SUN6I_LOSC_CTRL_EXT_OSC BIT(0) 43 45 #define SUN6I_LOSC_CTRL_ACC_MASK GENMASK(9, 7) 44 46 45 47 /* RTC */ ··· 418 416 419 417 /* disable alarm wakeup */ 420 418 writel(0, chip->base + SUN6I_ALARM_CONFIG); 419 + 420 + /* switch to the external, more precise, oscillator */ 421 + writel(SUN6I_LOSC_CTRL_KEY | SUN6I_LOSC_CTRL_EXT_OSC, 422 + chip->base + SUN6I_LOSC_CTRL); 421 423 422 424 chip->rtc = rtc_device_register("rtc-sun6i", &pdev->dev, 423 425 &sun6i_rtc_ops, THIS_MODULE);