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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,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 0AA64C5519F for ; Sun, 22 Nov 2020 23:11:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8A82420771 for ; Sun, 22 Nov 2020 23:11:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q4nNi5BK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A82420771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=K5GEVWqsQot6QoTkT89f0cKvqNa+49BysMpm6E/BD54=; b=q4nNi5BK2z1ERgUpNKHOZrUVk xGRbV0o0ntN3woX/kIWfCTF7ULIoEd8MktoD3nyLWvFxxW/Lq0XpDRpaGXJiXHlvcB/prsbLbWnSP f+WflU8JNiumeCZinseZxxUu2uUuUDykaeS5b+HfJt1zWks+ZO185W4AJb5FZthdzGxXidF4urXBG 3n8usHT02q6Bqcenx/1YeFZim+T/3kpnHtK48RRemtVwHNYXiNxZgKDSnfRcn3MgjPss+qtKr4SmC YMX2DWESsyqegyhDn0/E9pic1UnStu4DLoPpX6OwHBHB1CJroERbf4zsnAKS+DRNLLJcHwScOx5/a XyYqA0s+Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kgyVh-00060X-Iv; Sun, 22 Nov 2020 23:11:09 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kgyVZ-0005zb-7s for linux-arm-kernel@lists.infradead.org; Sun, 22 Nov 2020 23:11:05 +0000 X-Originating-IP: 86.194.74.19 Received: from localhost (lfbn-lyo-1-997-19.w86-194.abo.wanadoo.fr [86.194.74.19]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 7F3591BF206; Sun, 22 Nov 2020 23:10:54 +0000 (UTC) Date: Mon, 23 Nov 2020 00:10:54 +0100 From: Alexandre Belloni To: Jonathan =?iso-8859-1?Q?Neusch=E4fer?= Subject: Re: [PATCH v4 5/7] rtc: New driver for RTC in Netronix embedded controller Message-ID: <20201122231054.GH348979@piout.net> References: <20201122222739.1455132-1-j.neuschaefer@gmx.net> <20201122222739.1455132-6-j.neuschaefer@gmx.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201122222739.1455132-6-j.neuschaefer@gmx.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201122_181101_487833_3732ED65 X-CRM114-Status: GOOD ( 20.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , devicetree@vger.kernel.org, Linus Walleij , Thierry Reding , Fabio Estevam , linux-rtc@vger.kernel.org, Arnd Bergmann , Mauro Carvalho Chehab , Sam Ravnborg , Daniel Palmer , Andy Shevchenko , Andreas Kemnade , NXP Linux Team , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , linux-pwm@vger.kernel.org, Stephan Gerhold , allen , Sascha Hauer , Lubomir Rintel , Rob Herring , Lee Jones , linux-arm-kernel@lists.infradead.org, Alessandro Zummo , linux-kernel@vger.kernel.org, Mark Brown , Pengutronix Kernel Team , Heiko Stuebner , Josua Mayer , Shawn Guo , "David S. Miller" Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On 22/11/2020 23:27:37+0100, Jonathan Neusch=E4fer wrote: > With this driver, mainline Linux can keep its time and date in sync with > the vendor kernel. > = > Advanced functionality like alarm and automatic power-on is not yet > supported. > = > Signed-off-by: Jonathan Neusch=E4fer Acked-by: Alexandre Belloni However, two comments below: > +static int ntxec_set_time(struct device *dev, struct rtc_time *tm) > +{ > + struct ntxec_rtc *rtc =3D dev_get_drvdata(dev); > + int res =3D 0; > + > + /* > + * To avoid time overflows while we're writing the full date/time, > + * set the seconds field to zero before doing anything else. For the > + * next 59 seconds (plus however long it takes until the RTC's next > + * update of the second field), the seconds field will not overflow > + * into the other fields. > + */ > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_SECOND, ntxec_reg= 8(0)); > + if (res) > + return res; > + > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_YEAR, ntxec_reg8(= tm->tm_year - 100)); > + if (res) > + return res; > + > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_MONTH, ntxec_reg8= (tm->tm_mon + 1)); > + if (res) > + return res; > + > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_DAY, ntxec_reg8(t= m->tm_mday)); > + if (res) > + return res; > + > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_HOUR, ntxec_reg8(= tm->tm_hour)); > + if (res) > + return res; > + > + res =3D regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_MINUTE, ntxec_reg= 8(tm->tm_min)); > + if (res) > + return res; > + > + return regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_SECOND, ntxec_reg8= (tm->tm_sec)); Couldn't you do a regmap_block_write or a regmap_multi_reg_write which would be more efficient as they would be locking the regmap only once. > +} > + > +static const struct rtc_class_ops ntxec_rtc_ops =3D { > + .read_time =3D ntxec_read_time, > + .set_time =3D ntxec_set_time, > +}; > + > +static int ntxec_rtc_probe(struct platform_device *pdev) > +{ > + struct rtc_device *dev; > + struct ntxec_rtc *rtc; > + > + rtc =3D devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); > + if (!rtc) > + return -ENOMEM; > + > + rtc->dev =3D &pdev->dev; > + rtc->ec =3D dev_get_drvdata(pdev->dev.parent); > + platform_set_drvdata(pdev, rtc); > + > + dev =3D devm_rtc_allocate_device(&pdev->dev); > + if (IS_ERR(dev)) > + return PTR_ERR(dev); > + > + dev->ops =3D &ntxec_rtc_ops; > + dev->range_min =3D RTC_TIMESTAMP_BEGIN_2000; > + dev->range_max =3D 9025257599LL; /* 2255-12-31 23:59:59 */ > + > + return rtc_register_device(dev); Note that this won't compile after https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?= id=3Dfdcfd854333be5b30377dc5daa9cd0fa1643a979 We can solve that with immutable branches though. -- = Alexandre Belloni, 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