From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE80FEB64DC for ; Sun, 25 Jun 2023 23:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=usP7+gvUNo5yyOp86aFXhDbi12Aldn34aOWJpPP+GZA=; b=Xo3wV043uNSFLp SoWg4jWIXvME9iCOsy0O2i0DxGOwMvn7ZA6RW48NV/2l3hHTfnqvOnvL4PrpozK1Yi2zmEd19ZOvz kgoONri9srpNjEOysq3mIVR4vI10+lBt9e+CGcsXreUqnK5kAMcNUnFqyWj2N5sY1mNBg+brSbDBG 4ARy6lBobJfuK3pkLGdxO3MK5fs/GWKmxM4QpYmRUeHgt2+LDhbLycP/1yKLzsCAX00h5jllrA5rq 5RyTglsenodw5bC+mvWbOp7b2hCRYXaQJESf2wLHBs1Y1F2AxzwcqepZmUROMgWl2K8GzICs7ht1b H5ufupM9btu0mBj+Vo9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qDYwk-008tTR-1c; Sun, 25 Jun 2023 23:15:06 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qDYwf-008tS8-33 for linux-arm-kernel@lists.infradead.org; Sun, 25 Jun 2023 23:15:04 +0000 X-GND-Sasl: alexandre.belloni@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687734897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QXB3ySiP1de3WZqGb+ujHYxIctkJUAMjkXFXMWV8wQw=; b=K6oEXDIIzo/uBtJGuZQTFMHpanMsRe1ukRJVKiWBxvXbYm2wdoBUr4KtoNxoflqg7AGjST BwPSXjMT84psoWjg3B5muVLSmXWuDTQRgSz+sFFA+jinEXlFbYyG6TBLMhQG9mdGezKRaS NYZBzrEM3/Eo4IjHnW/cW21Id+Js2vQnD3WQRxiHkyHVtxrWKJxSa7LLGe3Mxx1wscuUYd 6fbpWn5YTj9iHvm9G0Fs9hMKUgJtpS5QBIhfJVwLsZbB19xnBeIoj8NhtAn7dpx1WCgaqA gcxpb3eMXvjodaQHIuolSWiL3Eg7T2ymE8jQs2M/zd/hgX+qFrUwlRB9R4ShSw== X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com X-GND-Sasl: alexandre.belloni@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id A23391BF203; Sun, 25 Jun 2023 23:14:55 +0000 (UTC) Date: Mon, 26 Jun 2023 01:14:54 +0200 From: Alexandre Belloni To: Valentin Caron Cc: Alessandro Zummo , Alexandre Torgue , Antonio Borneo , Christophe Guibout , Gabriel Fernandez , linux-rtc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/7] rtc: stm32: improve rtc precision Message-ID: <20230625231454d53ad0e0@mail.local> References: <20230615092753.323844-1-valentin.caron@foss.st.com> <20230615092753.323844-4-valentin.caron@foss.st.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230615092753.323844-4-valentin.caron@foss.st.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230625_161502_532146_41DCCD7A X-CRM114-Status: GOOD ( 25.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 15/06/2023 11:27:49+0200, Valentin Caron wrote: > From: Christophe Guibout > > The rtc is used to update the stgen counter on wake up from > low power modes, so it needs to be as much accurate as possible. > > The maximization of asynchronous divider leads to a 4ms rtc > precision clock. > By decreasing pred_a to 0, it will have pred_s=32767 (when > need_accuracy is true), so stgen clock becomes more accurate > with 30us precision. > Nevertheless this will leads to an increase of power consumption. > > Signed-off-by: Christophe Guibout > Signed-off-by: Valentin Caron > --- > drivers/rtc/rtc-stm32.c | 26 ++++++++++++++++++++++---- > 1 file changed, 22 insertions(+), 4 deletions(-) > > diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c > index bd7a59a07537..cad88668bcfb 100644 > --- a/drivers/rtc/rtc-stm32.c > +++ b/drivers/rtc/rtc-stm32.c > @@ -114,6 +114,7 @@ struct stm32_rtc_data { > void (*clear_events)(struct stm32_rtc *rtc, unsigned int flags); > bool has_pclk; > bool need_dbp; > + bool need_accuracy; > }; > > struct stm32_rtc { > @@ -545,6 +546,7 @@ static void stm32_rtc_clear_events(struct stm32_rtc *rtc, > static const struct stm32_rtc_data stm32_rtc_data = { > .has_pclk = false, > .need_dbp = true, > + .need_accuracy = false, > .regs = { > .tr = 0x00, > .dr = 0x04, > @@ -566,6 +568,7 @@ static const struct stm32_rtc_data stm32_rtc_data = { > static const struct stm32_rtc_data stm32h7_rtc_data = { > .has_pclk = true, > .need_dbp = true, > + .need_accuracy = false, > .regs = { > .tr = 0x00, > .dr = 0x04, > @@ -596,6 +599,7 @@ static void stm32mp1_rtc_clear_events(struct stm32_rtc *rtc, > static const struct stm32_rtc_data stm32mp1_data = { > .has_pclk = true, > .need_dbp = false, > + .need_accuracy = true, > .regs = { > .tr = 0x00, > .dr = 0x04, > @@ -636,11 +640,25 @@ static int stm32_rtc_init(struct platform_device *pdev, > pred_a_max = STM32_RTC_PRER_PRED_A >> STM32_RTC_PRER_PRED_A_SHIFT; > pred_s_max = STM32_RTC_PRER_PRED_S >> STM32_RTC_PRER_PRED_S_SHIFT; > > - for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { > - pred_s = (rate / (pred_a + 1)) - 1; > + if (rate > (pred_a_max + 1) * (pred_s_max + 1)) { > + dev_err(&pdev->dev, "rtc_ck rate is too high: %dHz\n", rate); What is the expect user action after seeing this message? > + return -EINVAL; > + } > + > + if (rtc->data->need_accuracy) { > + for (pred_a = 0; pred_a <= pred_a_max; pred_a++) { > + pred_s = (rate / (pred_a + 1)) - 1; > > - if (((pred_s + 1) * (pred_a + 1)) == rate) > - break; > + if (pred_s <= pred_s_max && ((pred_s + 1) * (pred_a + 1)) == rate) > + break; > + } > + } else { > + for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { > + pred_s = (rate / (pred_a + 1)) - 1; > + > + if (((pred_s + 1) * (pred_a + 1)) == rate) > + break; > + } > } > > /* > -- > 2.25.1 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel