rtc: sunxi: use external 32k oscillator if provided
Subsystems (2)
RFC PATCH 1/1 rtc: sunxi: use external 32k oscillator if provided
Set the OSC32K_SRC_SEL bit in the LOSC control register if a clock is specified in the devicetree.
---
The newer sun6i rtc driver is a proper clk provider with parent selection. Doing the same thing in this driver would be difficult while staying compatible with existing devicetrees. For that reason, this simpler approach seems reasonable.
--- drivers/rtc/rtc-sunxi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/rtc/rtc-sunxi.c +12 -0
@@ -5,6 +5,7 @@* Copyright (c) 2013, Carlo Caione <[email protected]> */ +#include <linux/clk.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/fs.h>
@@ -21,8 +22,10 @@#include <linux/types.h> #define SUNXI_LOSC_CTRL 0x0000 +#define SUNXI_LOSC_CTRL_KEY (0x16aa << 16)#define SUNXI_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUNXI_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUNXI_LOSC_CTRL_OSC32K_SRC_SEL BIT(0)#define SUNXI_RTC_YMD 0x0004
@@ -422,6 +425,7 @@ MODULE_DEVICE_TABLE(of, sunxi_rtc_dt_ids);static int sunxi_rtc_probe (struct platform_device *pdev) {struct sunxi_rtc_dev *chip; +struct clk *extclk;int ret; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );
@@ -455,6 +459,14 @@ static int sunxi_rtc_probe(struct platform_device *pdev)return -ENODEV ; } +/* use external oscillator if present */ + extclk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); +if (IS_ERR (extclk)) +return PTR_ERR (extclk); +if (extclk) +writel (SUNXI_LOSC_CTRL_KEY |SUNXI_LOSC_CTRL_OSC32K_SRC_SEL , + chip->base +SUNXI_LOSC_CTRL ); +/* clear the alarm count value */ writel (0 , chip->base +SUNXI_ALRM_DHMS );
Signature · 1 line
2.41.0
Hi Mans,
Quoted 45 lines · Mans Rullgard
Set the
OSC32K_SRC_SELbit in the LOSC control register if a clock is specified in the devicetree.Signed-off-by Mans Rullgard <[email protected]>---
The newer sun6i rtc driver is a proper clk provider with parent selection. Doing the same thing in this driver would be difficult while staying compatible with existing devicetrees. For that reason, this simpler approach seems reasonable.--- drivers/rtc/rtc-sunxi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/rtc/rtc-sunxi.c +4
-0@@ -5,6 +5,7 @@* Copyright (c) 2013, Carlo Caione <[email protected]> */ +#include <linux/clk.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/fs.h> @@ -21,8 +22,10 @@#include <linux/types.h> #define SUNXI_LOSC_CTRL 0x0000 +#define SUNXI_LOSC_CTRL_KEY (0x16aa << 16)#define SUNXI_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUNXI_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUNXI_LOSC_CTRL_OSC32K_SRC_SEL BIT(0)#define SUNXI_RTC_YMD 0x0004@@ -422,6 +425,7 @@ MODULE_DEVICE_TABLE(of, sunxi_rtc_dt_ids);static int sunxi_rtc_probe (struct platform_device *pdev) {struct sunxi_rtc_dev *chip; +struct clk *extclk;int ret; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );
drivers/rtc/rtc-sunxi.c static int sunxi_rtc_probe(struct platform_device *pdev) · line 468
Quoted 10 lines
drivers/rtc/rtc-sunxi.c +7
-0@@ -455,6 +459,14 @@ static int sunxi_rtc_probe(struct platform_device *pdev)return -ENODEV ; } +/* use external oscillator if present */ + extclk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); +if (IS_ERR (extclk)) +return PTR_ERR (extclk); +if (extclk) +writel (SUNXI_LOSC_CTRL_KEY |SUNXI_LOSC_CTRL_OSC32K_SRC_SEL , + chip->base +SUNXI_LOSC_CTRL );
This should be a read-modify-write operation, since we don't want to disturb other bits in this register.
In general this looks OK to me, but would need to be documented in the bindings docs, to allow an optional clocks property.
Cheers,
Andre
Quoted 4 lines
drivers/rtc/rtc-sunxi.c +1
-0+/* clear the alarm count value */ writel (0 , chip->base +SUNXI_ALRM_DHMS );
Quoted 45 lines · Andre Przywara
Hi Mans,
Quoted 42 lines · Mans Rullgard
Set the
OSC32K_SRC_SELbit in the LOSC control register if a clock is specified in the devicetree.Signed-off-by Mans Rullgard <[email protected]>---
The newer sun6i rtc driver is a proper clk provider with parent selection. Doing the same thing in this driver would be difficult while staying compatible with existing devicetrees. For that reason, this simpler approach seems reasonable.--- drivers/rtc/rtc-sunxi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/rtc/rtc-sunxi.c +2
-0@@ -5,6 +5,7 @@* Copyright (c) 2013, Carlo Caione <[email protected]> */ +#include <linux/clk.h>#include <linux/delay.h> #include <linux/err.h> #include <linux/fs.h> @@ -21,8 +22,10 @@#include <linux/types.h> #define SUNXI_LOSC_CTRL 0x0000 +#define SUNXI_LOSC_CTRL_KEY (0x16aa << 16)#define SUNXI_LOSC_CTRL_RTC_HMS_ACC BIT(8)#define SUNXI_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUNXI_LOSC_CTRL_OSC32K_SRC_SEL BIT(0)#define SUNXI_RTC_YMD 0x0004 @@ -422,6 +425,7 @@ MODULE_DEVICE_TABLE(of, sunxi_rtc_dt_ids);static int sunxi_rtc_probe (struct platform_device *pdev) {struct
sunxi_rtc_dev*chip;drivers/rtc/rtc-sunxi.c +2
-0+struct clk *extclk;int ret; chip =devm_kzalloc (&pdev->dev,sizeof (*chip),GFP_KERNEL );@@ -455,6 +459,14 @@ static int sunxi_rtc_probe(struct platform_device *pdev)return -ENODEV ; } +/* use external oscillator if present */ + extclk =devm_clk_get_optional_enabled (&pdev->dev,NULL );
Quoted 8 lines
drivers/rtc/rtc-sunxi.c static int sunxi_rtc_probe(struct platform_device *pdev) · line 468
Quoted 5 lines
drivers/rtc/rtc-sunxi.c +5
-0+if (IS_ERR (extclk)) +return PTR_ERR (extclk); +if (extclk) +writel (SUNXI_LOSC_CTRL_KEY |SUNXI_LOSC_CTRL_OSC32K_SRC_SEL , + chip->base +SUNXI_LOSC_CTRL );This should be a read-modify-write operation, since we don't want to disturb other bits in this register.
Good point. I guess it's best to leave everything untouched if the clock isn't specified, just in case someone has a bootloader that sets this bit.
Quoted 2 lines
In general this looks OK to me, but would need to be documented in the bindings docs, to allow an optional clocks property.
Sure, I'll make a patch for that as well.
Signature · 1 line
Måns Rullgård