From: Mans Rullgard <mans@mansr.com>
To: Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>
Cc: linux-rtc@vger.kernel.org, linux-sunxi@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [RFC][PATCH] rtc: sunxi: use external 32k oscillator if provided
Date: Thu, 27 Jul 2023 16:01:23 +0100 [thread overview]
Message-ID: <20230727150156.29691-1-mans@mansr.com> (raw)
Set the OSC32K_SRC_SEL bit in the LOSC control register if a clock is
specified in the devicetree.
Signed-off-by: Mans Rullgard <mans@mansr.com>
---
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(+)
diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c
index 5d019e3a835a..4f1053eab778 100644
--- a/drivers/rtc/rtc-sunxi.c
+++ b/drivers/rtc/rtc-sunxi.c
@@ -5,6 +5,7 @@
* Copyright (c) 2013, Carlo Caione <carlo.caione@gmail.com>
*/
+#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);
--
2.41.0
next reply other threads:[~2023-07-27 15:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 15:01 Mans Rullgard [this message]
2023-07-27 16:53 ` [RFC][PATCH] rtc: sunxi: use external 32k oscillator if provided Andre Przywara
2023-07-27 18:35 ` Måns Rullgård
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=20230727150156.29691-1-mans@mansr.com \
--to=mans@mansr.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=samuel@sholland.org \
--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