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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0444CC2D0F0 for ; Mon, 30 Mar 2020 20:19:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCFED2072E for ; Mon, 30 Mar 2020 20:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727437AbgC3UTN (ORCPT ); Mon, 30 Mar 2020 16:19:13 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:53759 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727170AbgC3UTN (ORCPT ); Mon, 30 Mar 2020 16:19:13 -0400 Received: from localhost (lfbn-lyo-1-9-35.w86-202.abo.wanadoo.fr [86.202.105.35]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id AA2F8240004; Mon, 30 Mar 2020 20:19:10 +0000 (UTC) Date: Mon, 30 Mar 2020 22:19:10 +0200 From: Alexandre Belloni To: Alessandro Zummo , Maxime Ripard , Chen-Yu Tsai Cc: linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] rtc: sun6i: let the core handle rtc range Message-ID: <20200330201910.GA752154@piout.net> References: <20200330201510.861217-1-alexandre.belloni@bootlin.com> <20200330201510.861217-2-alexandre.belloni@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200330201510.861217-2-alexandre.belloni@bootlin.com> Sender: linux-rtc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rtc@vger.kernel.org This was en unattended resend. On 30/03/2020 22:15:09+0200, Alexandre Belloni wrote: > Let the rtc core check the date/time against the RTC range. > > Signed-off-by: Alexandre Belloni > --- > drivers/rtc/rtc-sun6i.c | 25 ++++++++++--------------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c > index 415a20a936e4..446ce38c1592 100644 > --- a/drivers/rtc/rtc-sun6i.c > +++ b/drivers/rtc/rtc-sun6i.c > @@ -108,7 +108,6 @@ > * driver, even though it is somewhat limited. > */ > #define SUN6I_YEAR_MIN 1970 > -#define SUN6I_YEAR_MAX 2033 > #define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900) > > /* > @@ -569,14 +568,6 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm) > struct sun6i_rtc_dev *chip = dev_get_drvdata(dev); > u32 date = 0; > u32 time = 0; > - int year; > - > - year = rtc_tm->tm_year + 1900; > - if (year < SUN6I_YEAR_MIN || year > SUN6I_YEAR_MAX) { > - dev_err(dev, "rtc only supports year in range %d - %d\n", > - SUN6I_YEAR_MIN, SUN6I_YEAR_MAX); > - return -EINVAL; > - } > > rtc_tm->tm_year -= SUN6I_YEAR_OFF; > rtc_tm->tm_mon += 1; > @@ -585,7 +576,7 @@ static int sun6i_rtc_settime(struct device *dev, struct rtc_time *rtc_tm) > SUN6I_DATE_SET_MON_VALUE(rtc_tm->tm_mon) | > SUN6I_DATE_SET_YEAR_VALUE(rtc_tm->tm_year); > > - if (is_leap_year(year)) > + if (is_leap_year(rtc_tm->tm_year + SUN6I_YEAR_MIN)) > date |= SUN6I_LEAP_SET_VALUE(1); > > time = SUN6I_TIME_SET_SEC_VALUE(rtc_tm->tm_sec) | > @@ -726,12 +717,16 @@ static int sun6i_rtc_probe(struct platform_device *pdev) > > device_init_wakeup(&pdev->dev, 1); > > - chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i", > - &sun6i_rtc_ops, THIS_MODULE); > - if (IS_ERR(chip->rtc)) { > - dev_err(&pdev->dev, "unable to register device\n"); > + chip->rtc = devm_rtc_allocate_device(&pdev->dev); > + if (IS_ERR(chip->rtc)) > return PTR_ERR(chip->rtc); > - } > + > + chip->rtc->ops = &sun6i_rtc_ops; > + chip->rtc->range_max = 2019686399LL; /* 2033-12-31 23:59:59 */ > + > + ret = rtc_register_device(chip->rtc); > + if (ret) > + return ret; > > dev_info(&pdev->dev, "RTC enabled\n"); > > -- > 2.25.1 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com