From nobody Sat Feb 7 19:45:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F4AEC04A6A for ; Thu, 27 Jul 2023 15:02:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234071AbjG0PC3 (ORCPT ); Thu, 27 Jul 2023 11:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234098AbjG0PCU (ORCPT ); Thu, 27 Jul 2023 11:02:20 -0400 Received: from unicorn.mansr.com (unicorn.mansr.com [81.2.72.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007641BD1; Thu, 27 Jul 2023 08:02:16 -0700 (PDT) Received: from raven.mansr.com (raven.mansr.com [IPv6:2001:8b0:ca0d:1::3]) by unicorn.mansr.com (Postfix) with ESMTPS id 70D7D15360; Thu, 27 Jul 2023 16:02:13 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id 62DC6221D92; Thu, 27 Jul 2023 16:02:13 +0100 (BST) From: Mans Rullgard To: Alessandro Zummo , Alexandre Belloni , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland 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 Message-ID: <20230727150156.29691-1-mans@mansr.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Set the OSC32K_SRC_SEL bit in the LOSC control register if a clock is specified in the devicetree. Signed-off-by: Mans Rullgard --- 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 */ =20 +#include #include #include #include @@ -21,8 +22,10 @@ #include =20 #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) =20 #define SUNXI_RTC_YMD 0x0004 =20 @@ -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; =20 chip =3D devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); @@ -455,6 +459,14 @@ static int sunxi_rtc_probe(struct platform_device *pde= v) return -ENODEV; } =20 + /* use external oscillator if present */ + extclk =3D 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); =20 --=20 2.41.0