diff mbox series

[09/15] clk: sunxi-ng: r40: Force LOSC parent to RTC LOSC output

Message ID 20181128093013.24442-11-wens@csie.org (mailing list archive)
State Mainlined, archived
Headers show
Series rtc: sun6i: clock rework and pre-H6 SoC support | expand

Commit Message

Chen-Yu Tsai Nov. 28, 2018, 9:30 a.m. UTC
On the R40, in addition to a mux between the RTC's own RC oscillator and
an external 32768 Hz crystal, which are muxed inside the RTC module, the
CCU also has its own RC oscillator, which runs at around 2 MHz, and can
be muxed with the LOSC output from the RTC. This muxed output is called
"SYS 32K" in the module clock diagram, but otherwise referred to as the
LOSC throughout the CCU documentation.

The RC oscillator is not very accurate, even though it has an undocumented
calibration function. We really want a precise clock at 32768 Hz,
instead of something at around 32 KHz. This patch forces the SYS 32K
clock to use the RTC output as its parent, and doesn't bother
registering the internal oscillator nor a clock mux.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/clk/sunxi-ng/ccu-sun8i-r40.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Maxime Ripard Nov. 28, 2018, 10:25 a.m. UTC | #1
On Wed, Nov 28, 2018 at 05:30:07PM +0800, Chen-Yu Tsai wrote:
> On the R40, in addition to a mux between the RTC's own RC oscillator and
> an external 32768 Hz crystal, which are muxed inside the RTC module, the
> CCU also has its own RC oscillator, which runs at around 2 MHz, and can
> be muxed with the LOSC output from the RTC. This muxed output is called
> "SYS 32K" in the module clock diagram, but otherwise referred to as the
> LOSC throughout the CCU documentation.
> 
> The RC oscillator is not very accurate, even though it has an undocumented
> calibration function. We really want a precise clock at 32768 Hz,
> instead of something at around 32 KHz. This patch forces the SYS 32K
> clock to use the RTC output as its parent, and doesn't bother
> registering the internal oscillator nor a clock mux.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>

Maxime
Stephen Boyd Nov. 28, 2018, 9:29 p.m. UTC | #2
Quoting Chen-Yu Tsai (2018-11-28 01:30:07)
> On the R40, in addition to a mux between the RTC's own RC oscillator and
> an external 32768 Hz crystal, which are muxed inside the RTC module, the
> CCU also has its own RC oscillator, which runs at around 2 MHz, and can
> be muxed with the LOSC output from the RTC. This muxed output is called
> "SYS 32K" in the module clock diagram, but otherwise referred to as the
> LOSC throughout the CCU documentation.
> 
> The RC oscillator is not very accurate, even though it has an undocumented
> calibration function. We really want a precise clock at 32768 Hz,
> instead of something at around 32 KHz. This patch forces the SYS 32K
> clock to use the RTC output as its parent, and doesn't bother
> registering the internal oscillator nor a clock mux.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---

Acked-by: Stephen Boyd <sboyd@kernel.org>
Chen-Yu Tsai Nov. 30, 2018, 3:55 a.m. UTC | #3
On Thu, Nov 29, 2018 at 5:29 AM Stephen Boyd <sboyd@kernel.org> wrote:
>
> Quoting Chen-Yu Tsai (2018-11-28 01:30:07)
> > On the R40, in addition to a mux between the RTC's own RC oscillator and
> > an external 32768 Hz crystal, which are muxed inside the RTC module, the
> > CCU also has its own RC oscillator, which runs at around 2 MHz, and can
> > be muxed with the LOSC output from the RTC. This muxed output is called
> > "SYS 32K" in the module clock diagram, but otherwise referred to as the
> > LOSC throughout the CCU documentation.
> >
> > The RC oscillator is not very accurate, even though it has an undocumented
> > calibration function. We really want a precise clock at 32768 Hz,
> > instead of something at around 32 KHz. This patch forces the SYS 32K
> > clock to use the RTC output as its parent, and doesn't bother
> > registering the internal oscillator nor a clock mux.
> >
> > Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> > ---
>
> Acked-by: Stephen Boyd <sboyd@kernel.org>

Merged with acks from Maxime and Stephen.
diff mbox series

Patch

diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c
index 582ebd41d20d..a22d11aa38ba 100644
--- a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c
+++ b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c
@@ -1284,6 +1284,9 @@  static struct regmap_config sun8i_r40_ccu_regmap_config = {
 	.writeable_reg	= sun8i_r40_ccu_regmap_accessible_reg,
 };
 
+#define SUN8I_R40_SYS_32K_CLK_REG 0x310
+#define SUN8I_R40_SYS_32K_CLK_KEY (0x16AA << 16)
+
 static int sun8i_r40_ccu_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -1312,6 +1315,14 @@  static int sun8i_r40_ccu_probe(struct platform_device *pdev)
 	val &= ~GENMASK(25, 20);
 	writel(val, reg + SUN8I_R40_USB_CLK_REG);
 
+	/*
+	 * Force SYS 32k (otherwise known as LOSC throughout the CCU)
+	 * clock parent to LOSC output from RTC module instead of the
+	 * CCU's internal RC oscillator divided output.
+	 */
+	writel(SUN8I_R40_SYS_32K_CLK_KEY | BIT(8),
+	       reg + SUN8I_R40_SYS_32K_CLK_REG);
+
 	regmap = devm_regmap_init_mmio(&pdev->dev, reg,
 				       &sun8i_r40_ccu_regmap_config);
 	if (IS_ERR(regmap))