Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp257676rwb; Thu, 27 Jul 2023 12:14:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlGz3txC6AOg0Z/gW1m6Z8ipgBUgbwZAROjceE6ZYlM8B3fuAt46cyB0NaX4TRaj3IJBY1Dx X-Received: by 2002:a05:6a00:1898:b0:686:24b0:554b with SMTP id x24-20020a056a00189800b0068624b0554bmr50840pfh.22.1690485280822; Thu, 27 Jul 2023 12:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690485280; cv=none; d=google.com; s=arc-20160816; b=PQpLjDPL6w2JOXEmyyxCpvbYYGmDPYXP6KGfCG4+A7LmACj+vPf4bOAVBiouxBIKXe GE6Dl8apPmgX+sgMtFO4zylRSBb2rxDtgrhCDzr+/2eqKbUpPCCUIygrxx6CBgFOSPfq /H9mJuLDS4sqcPiaJeHh70IUwfptCozTTeWwM7cfeX+aVWqJoec+zGd/rbcxJrB/FsJA /j/xdClCGeLXkBEDApy6Nuf6T5E/E3z58J1E5Q8xm7+Z9aqix5cjDtybdjQPGn6cwCKr nU3O/Xp0OQAC0F62Vash77aWWZH1EteTJvFSy5PvHkZrlz5v8OCkx7Eh+fGTT+K9psMI qpbw== 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 :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from; bh=InI04w4U2f9rgzG7hMch00tdxGIcqTILth2U9WN16Ec=; fh=Sipj34MQNCDp/rMRub0XCiYz1QKITzsotvq29QE4iXc=; b=ZobuyuQG56V9c8PogLK/ZI8CCXug1GKW0pKtdI9MrQE81Ndw8LG57CnYNm5xqatEv7 19mYyXv/Tzrs3TrYmEEkI1knINXWK955h00WQ9Y52QxJ7HxuVQfyUrpZEhk4EyDSbSN+ 06WUDCBiu4xpKqiUfLnTPCJD+o6k7EXJPRXcxOiYrmo9ncYeuWDJRB/qhLM6LriPO1OD Ec5rbaGyiyU4raLlGDHAv0cU2ikxPTsFWYHPhYvNgzR+9hcSIolE81KUqaAZ3BpXRpSV JgF0sSqTPYWyN/xx3Y/5P9DgTtykdttpm64re7VP1z0bZOkPjKOVxzBCb8YE1dwO8ibC 2pow== 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 h21-20020a635755000000b0055fd1bfb109si1558489pgm.679.2023.07.27.12.14.28; Thu, 27 Jul 2023 12:14:40 -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 S229824AbjG0Sfg convert rfc822-to-8bit (ORCPT + 99 others); Thu, 27 Jul 2023 14:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbjG0Sfe (ORCPT ); Thu, 27 Jul 2023 14:35:34 -0400 Received: from unicorn.mansr.com (unicorn.mansr.com [81.2.72.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D28A2719; Thu, 27 Jul 2023 11:35:33 -0700 (PDT) Received: from raven.mansr.com (raven.mansr.com [81.2.72.235]) by unicorn.mansr.com (Postfix) with ESMTPS id 2CD0515360; Thu, 27 Jul 2023 19:35:28 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id B46A5221D92; Thu, 27 Jul 2023 19:35:27 +0100 (BST) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Andre Przywara Cc: Alessandro Zummo , Alexandre Belloni , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-rtc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [RFC][PATCH] rtc: sunxi: use external 32k oscillator if provided References: <20230727150156.29691-1-mans@mansr.com> <23f220fd-918e-0e3a-764c-14d11fdf8f4f@arm.com> Date: Thu, 27 Jul 2023 19:35:27 +0100 In-Reply-To: <23f220fd-918e-0e3a-764c-14d11fdf8f4f@arm.com> (Andre Przywara's message of "Thu, 27 Jul 2023 17:53:47 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 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 Andre Przywara writes: > Hi Mans, > > On 27/07/2023 16:01, Mans Rullgard wrote: >> 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); > > 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. > 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. -- M?ns Rullg?rd