Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp965547pxk; Fri, 25 Sep 2020 02:38:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqWT3UMgOMfbFx9E9GtT7fBufgDTb89jwyb2rCLKBRnp5+ESbgVrNJ1i/ZG7vSFXUGYjOs X-Received: by 2002:a50:fa88:: with SMTP id w8mr305204edr.179.1601026687323; Fri, 25 Sep 2020 02:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601026687; cv=none; d=google.com; s=arc-20160816; b=uB9k86hiID0ivGasFafwjJJbZEqnWEO4RKR6NoyMiLgWCeb21Y8drzhOl8JDh7i7gz KrmQLjUqSgU7C+GxIHgjOVqSxxACCietVaifOIPboKKUlgDAPTp0jhPBR0mUeQ9obOzq kQ6Q8kiJeIXBCA+go00iclhM3BHzHqcXiSkTmwhl6VLACbBVDCP8QR+Y9JHsjsOmsr5M qy2yMppxSXO85/mMwLFQf2CVUzD/MNpH9N73EBMw9AP0mWe5TDlTDHgdzla0R4rha3bC arR4KXl+MVFx2KYuJ1M8noiHU/1nplImeFcw8ehKs/+iDQNLylPbRmMlgUm/geWVP06m 1nLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/RdeVKOiZMKJViP0DUy3UmSc6/mm7c8cZxk8m6Juu7g=; b=VBVSVvdaOWILcF6OpUCaQxamtuMQ56+oMGu0jLPFTi8ipIz15JZNabvC04QUlF/a5W ZNFUyHf8Pk97SVxGme9NSo81fdXn5oBaAmQP17ZcN4KJn3Dc0GNVm2G1wbEgj947HmgB 7LeD9oxV3YnYlii/DWIxtLIF/zaZJ8VQ6c2QuU3AZzLp1gGjvJXruqFSmHKLbHW+05sn 0FTLXgMM6QWe4MzELvuc0adWLq8OCwuuu7kBLY3fEAVl3IDkdb1i+sjZJEX6DDjGf1wy QmybDg2YU1BaGlT1iCO3bJ5V6i3Bm2WIkdJv3YSPAqnT5RvMxNscxy9d7xaCERssPw2b 6y+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si1417880ejx.47.2020.09.25.02.37.43; Fri, 25 Sep 2020 02:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbgIYJgc (ORCPT + 99 others); Fri, 25 Sep 2020 05:36:32 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:39531 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727648AbgIYJgX (ORCPT ); Fri, 25 Sep 2020 05:36:23 -0400 X-Originating-IP: 90.65.88.165 Received: from localhost (lfbn-lyo-1-1908-165.w90-65.abo.wanadoo.fr [90.65.88.165]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 4F9B3FF809; Fri, 25 Sep 2020 09:36:15 +0000 (UTC) Date: Fri, 25 Sep 2020 11:36:14 +0200 From: Alexandre Belloni To: Jonathan =?iso-8859-1?Q?Neusch=E4fer?= Cc: linux-kernel@vger.kernel.org, Lee Jones , Rob Herring , Thierry Reding , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Alessandro Zummo , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Sam Ravnborg , Linus Walleij , Heiko Stuebner , Stephan Gerhold , Lubomir Rintel , Mark Brown , allen , Mauro Carvalho Chehab , "David S. Miller" , devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Heiko Stuebner , Josua Mayer , Andreas Kemnade , Arnd Bergmann , Daniel Palmer , Andy Shevchenko Subject: Re: [PATCH v3 5/7] rtc: New driver for RTC in Netronix embedded controller Message-ID: <20200925093614.GZ9675@piout.net> References: <20200924192455.2484005-1-j.neuschaefer@gmx.net> <20200924192455.2484005-6-j.neuschaefer@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200924192455.2484005-6-j.neuschaefer@gmx.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 24/09/2020 21:24:53+0200, Jonathan Neusch?fer 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?fer > --- > > v3: > - Add email address to copyright line > - Remove OF compatible string and don't include linux/of_device.h > - Don't use a comma after sentinels > - Avoid ret |= ... pattern > - Move 8-bit register conversion to ntxec.h > - Relicense as GPLv2 or later I don't think you had to relicense. The kernel is GPL 2 only, you are free to license your code under GPL 2 only if that is what you desire. > > v2: > - https://lore.kernel.org/lkml/20200905133230.1014581-7-j.neuschaefer@gmx.net/ > - Rework top-of-file comment [Lee Jones] > - Sort the #include lines [Alexandre Belloni] > - don't align = signs in struct initializers [Uwe Kleine-K?nig] > - Switch to regmap > - Fix register number used to read minutes and seconds > - Prefix registers with NTXEC_REG_ > - Add help text to the Kconfig option > - Use devm_rtc_allocate_device and rtc_register_device, set ->range_min and ->range_max > --- > drivers/rtc/Kconfig | 8 +++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-ntxec.c | 132 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 141 insertions(+) > create mode 100644 drivers/rtc/rtc-ntxec.c > > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig > index 48c536acd777f..ae8f3dc36c9a3 100644 > --- a/drivers/rtc/Kconfig > +++ b/drivers/rtc/Kconfig > @@ -1301,6 +1301,14 @@ config RTC_DRV_CROS_EC > This driver can also be built as a module. If so, the module > will be called rtc-cros-ec. > > +config RTC_DRV_NTXEC > + tristate "Netronix embedded controller RTC driver" > + depends on MFD_NTXEC > + help > + Say yes here if you want to support the RTC functionality of the > + embedded controller found in certain e-book readers designed by the > + ODM Netronix. > + > comment "on-CPU RTC drivers" > > config RTC_DRV_ASM9260 > diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile > index 880e08a409c3d..733479db18896 100644 > --- a/drivers/rtc/Makefile > +++ b/drivers/rtc/Makefile > @@ -111,6 +111,7 @@ obj-$(CONFIG_RTC_DRV_MT7622) += rtc-mt7622.o > obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o > obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o > obj-$(CONFIG_RTC_DRV_MXC_V2) += rtc-mxc_v2.o > +obj-$(CONFIG_RTC_DRV_NTXEC) += rtc-ntxec.o > obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o > obj-$(CONFIG_RTC_DRV_OPAL) += rtc-opal.o > obj-$(CONFIG_RTC_DRV_PALMAS) += rtc-palmas.o > diff --git a/drivers/rtc/rtc-ntxec.c b/drivers/rtc/rtc-ntxec.c > new file mode 100644 > index 0000000000000..af23c7cc76544 > --- /dev/null > +++ b/drivers/rtc/rtc-ntxec.c > @@ -0,0 +1,132 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * The Netronix embedded controller is a microcontroller found in some > + * e-book readers designed by the ODM Netronix, Inc. It contains RTC, > + * battery monitoring, system power management, and PWM functionality. > + * > + * This driver implements access to the RTC time and date. > + * > + * Copyright 2020 Jonathan Neusch?fer > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct ntxec_rtc { > + struct device *dev; > + struct ntxec *ec; > +}; > + > +#define NTXEC_REG_WRITE_YEAR 0x10 > +#define NTXEC_REG_WRITE_MONTH 0x11 > +#define NTXEC_REG_WRITE_DAY 0x12 > +#define NTXEC_REG_WRITE_HOUR 0x13 > +#define NTXEC_REG_WRITE_MINUTE 0x14 > +#define NTXEC_REG_WRITE_SECOND 0x15 > + > +#define NTXEC_REG_READ_YM 0x20 > +#define NTXEC_REG_READ_DH 0x21 > +#define NTXEC_REG_READ_MS 0x23 > + > +static int ntxec_read_time(struct device *dev, struct rtc_time *tm) > +{ > + struct ntxec_rtc *rtc = dev_get_drvdata(dev); > + unsigned int value; > + int res; > + > + res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_YM, &value); > + if (res < 0) > + return res; > + > + tm->tm_year = (value >> 8) + 100; > + tm->tm_mon = (value & 0xff) - 1; > + > + res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_DH, &value); > + if (res < 0) > + return res; > + > + tm->tm_mday = value >> 8; > + tm->tm_hour = value & 0xff; > + > + res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_MS, &value); > + if (res < 0) > + return res; > + > + tm->tm_min = value >> 8; > + tm->tm_sec = value & 0xff; > + > + return 0; > +} > + > +static int ntxec_set_time(struct device *dev, struct rtc_time *tm) > +{ > + struct ntxec_rtc *rtc = dev_get_drvdata(dev); > + int res = 0; > + > + res = regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_YEAR, ntxec_reg8(tm->tm_year - 100)); > + if (res) > + return res; > + > + res = regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_MONTH, ntxec_reg8(tm->tm_mon + 1)); > + if (res) > + return res; > + > + res = regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_DAY, ntxec_reg8(tm->tm_mday)); > + if (res) > + return res; > + > + res = regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_HOUR, ntxec_reg8(tm->tm_hour)); > + if (res) > + return res; > + > + res = regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_MINUTE, ntxec_reg8(tm->tm_min)); > + if (res) > + return res; > + > + return regmap_write(rtc->ec->regmap, NTXEC_REG_WRITE_SECOND, ntxec_reg8(tm->tm_sec)); > +} > + > +static const struct rtc_class_ops ntxec_rtc_ops = { > + .read_time = ntxec_read_time, > + .set_time = ntxec_set_time, > +}; > + > +static int ntxec_rtc_probe(struct platform_device *pdev) > +{ > + struct rtc_device *dev; > + struct ntxec_rtc *rtc; > + > + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); > + if (!rtc) > + return -ENOMEM; > + > + rtc->dev = &pdev->dev; > + rtc->ec = dev_get_drvdata(pdev->dev.parent); > + platform_set_drvdata(pdev, rtc); > + > + dev = devm_rtc_allocate_device(&pdev->dev); > + if (IS_ERR(dev)) > + return PTR_ERR(dev); > + > + dev->ops = &ntxec_rtc_ops; > + dev->range_min = RTC_TIMESTAMP_BEGIN_2000; > + dev->range_max = 9025257599LL; /* 2255-12-31 23:59:59 */ > + > + return rtc_register_device(dev); > +} > + > +static struct platform_driver ntxec_rtc_driver = { > + .driver = { > + .name = "ntxec-rtc", > + }, > + .probe = ntxec_rtc_probe, > +}; > +module_platform_driver(ntxec_rtc_driver); > + > +MODULE_AUTHOR("Jonathan Neusch?fer "); > +MODULE_DESCRIPTION("RTC driver for Netronix EC"); > +MODULE_LICENSE("GPL"); > -- > 2.28.0 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com