Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2506469rwb; Thu, 27 Jul 2023 08:07:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1OeCqyoYDaqwGPPUtjZ77H1x84R6E3t2Em3TQ9jFEuY20rAXxzesaxFjzQq99fIniUAME X-Received: by 2002:a17:903:124c:b0:1b9:d38d:efb1 with SMTP id u12-20020a170903124c00b001b9d38defb1mr3526386plh.8.1690470423299; Thu, 27 Jul 2023 08:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690470423; cv=none; d=google.com; s=arc-20160816; b=rfrSz8Axk6Z6fLDKFGw/DJQF10xZoJhbUVbQ+XhGCHNafuX2ICgau+/qeQvPWYMQQB fUTYTo8cU1sYVIi5nbfFrCtvUfO47Rq9n0dn/Nebx5NwI9rd6gYN2ujCgN6LaV+Ur9d6 1SSkuPW/lHb65hrCVGYMQ64ll97O3tfTymh6aMCGRYeiltbPqWRrodbBO38u3wKlkleK EhsutWMmYKnb9QAfo5AwzM0oaEAC71KEumP+j2goY6TjrwslzRbvDWD5Zugn4sAMrRGU 15HPBwx4VRaOVrtMXjUG9EiFUrlsDcgvP300BjG8tbBq8YMb2IMvf4EiOrvHkBHxXltg 7+QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=21jwZkXibx0jiLxFTKuLbxot/nm2fqDI1CVOPYnZxMI=; fh=+HECXHytwoPHJpX4eBtu3Yee2WQeJhotU+2llwYNuqs=; b=llZ8bYJFsgLJ7vUxglQK1+ApHsIWX/IvXk2AwDJKl3l0bJVoMudDlPCIbYBEe1FjOW AkfvWYNowOjO4FRTVuYJ46EliUjffqUg6FzvASfQA001VpE9FAXibweP37veZ4HkN5Gk Ff2AwMKf/VL+fJO+TBpWAH743tKKqAqMqixGaXdKoAWB+EgoMkTUddd0zMRmFWLZgcZr AGbUbRG/cn/lgDDBFCRj6HY/if/WJpl9iqaCIzJI1qL9PDIAD+xs+WhY5191JdduAeBB uSRSAkofDU+NAP69Moiyd8qXRSowZ9yBhiK4BM96L1Wyr4/M9P54sA5l1ZyeGke+Joze fuqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id le4-20020a170902fb0400b001b8a3894576si1364585plb.64.2023.07.27.08.06.50; Thu, 27 Jul 2023 08:07:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233949AbjG0PC3 (ORCPT + 99 others); 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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ +#include #include #include #include @@ -21,8 +22,10 @@ #include #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