Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1642064ybt; Sat, 20 Jun 2020 17:13:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4oV1fhZMDmt/sU6uLiBZHeZV111EAZtkOGkHUzvd/oXkYKe6YEzqsIk+CRhwYslmrdRSQ X-Received: by 2002:a05:6402:b5c:: with SMTP id bx28mr10204861edb.145.1592698421881; Sat, 20 Jun 2020 17:13:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592698421; cv=none; d=google.com; s=arc-20160816; b=gfB5qDrHl523CvIX1Btrxf1oq1qFGa799ATNpohkoPSRSvjpgrde9z20yPlRcnQPbo fMZ/iFXVBUJ7A4ZAwjd5LWYTTR8puuvwWN9cRHshJbXg+e5M7D7NMLEdR2N+Ui/Ymbkf hYtxGtpQRcdROYl9lctvLefhLmACdFrbYajy8g5zHrVTuQ6XZ89mIzhzw1I6T+2XA833 l5jBl1De8WgM3YeunVsgunkImnGhZ8M3yRKVBrs4b99qNPRFLEGo9Oq4hqAWFPnS7XF7 nbLgyJy86YRu5vSP55wdtMA80bmDkLbLOi4WijebMPfhZehhcVvjqCBmlC79MQXpkb50 9P0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xIVXMGFeQn9Eh5556ROJpo2f0sZrI5I4uB6BhYlCKI0=; b=P4pS3UxYJcVCTYpEjXWBOF8E/uv/cYJRKFnUYci88+KAV/jgKybwExJH1xBEiDXxsh qlLirxzC/oqj+V5gtfdVG9d0QBGVaPShN8y4uZL+pHbCeikWE/WynFBVhrFTDsUcCwKK //E+SDds6SPz/c49stGiI0GaZ4viZ8ZSyKqjQwV0tzwqq6qV/DjFuCd+RfrySDywEjkY YLquIauG15E+MBKuoNEq4dUNtvF3ckhEk0s1m/dkhSCBSQrNYsD3MV0ZgRLZpFwVuIg4 4rHdpdrffW/GGPJoIxRb97uSmxT+W7Ub1ntui1utN/CoJ+Xp0NIgWBzPkFFcsUasE1A6 TOSg== 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 n6si6714593ejz.660.2020.06.20.17.13.16; Sat, 20 Jun 2020 17:13:41 -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 S1728578AbgFUALS (ORCPT + 99 others); Sat, 20 Jun 2020 20:11:18 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:33317 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728480AbgFUALS (ORCPT ); Sat, 20 Jun 2020 20:11:18 -0400 X-Originating-IP: 86.202.110.81 Received: from localhost (lfbn-lyo-1-15-81.w86-202.abo.wanadoo.fr [86.202.110.81]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id AE2151C0005; Sun, 21 Jun 2020 00:11:07 +0000 (UTC) Date: Sun, 21 Jun 2020 02:11:06 +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 Subject: Re: [RFC PATCH 08/10] rtc: New driver for RTC in Netronix embedded controller Message-ID: <20200621001106.GC131826@piout.net> References: <20200620224222.1312520-1-j.neuschaefer@gmx.net> <20200620224222.1312520-7-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: <20200620224222.1312520-7-j.neuschaefer@gmx.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/06/2020 00:42:19+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. > Please report the results of rtctest (from the kernel tree) and rtc-range (https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c) > Signed-off-by: Jonathan Neusch?fer > --- > drivers/rtc/Kconfig | 4 ++ > drivers/rtc/Makefile | 1 + > drivers/rtc/rtc-ntxec.c | 115 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 120 insertions(+) > create mode 100644 drivers/rtc/rtc-ntxec.c > > diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig > index b54d87d45c89b..2310d08933f9c 100644 > --- a/drivers/rtc/Kconfig > +++ b/drivers/rtc/Kconfig > @@ -1300,6 +1300,10 @@ 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 > + This should get an help section. > comment "on-CPU RTC drivers" > > config RTC_DRV_ASM9260 > diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile > index 0721752c6ed4c..8653d04aefa99 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..44d5a5eedb597 > --- /dev/null > +++ b/drivers/rtc/rtc-ntxec.c > @@ -0,0 +1,115 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +// Copyright 2020 Jonathan Neusch?fer > + > +#include > +#include > +#include > +#include > +#include > +#include Please sort the includes. > + > +struct ntxec_rtc { > + struct device *dev; > + struct ntxec *ec; > +}; > + > +#define NTXEC_WRITE_YEAR 0x10 > +#define NTXEC_WRITE_MONTH 0x11 > +#define NTXEC_WRITE_DAY 0x12 > +#define NTXEC_WRITE_HOUR 0x13 > +#define NTXEC_WRITE_MINUTE 0x14 > +#define NTXEC_WRITE_SECOND 0x15 > + > +#define NTXEC_READ_YM 0x20 > +#define NTXEC_READ_DH 0x21 > +#define NTXEC_READ_MS 0x22 > + > + > +static int ntxec_read_time(struct device *dev, struct rtc_time *tm) > +{ > + struct ntxec_rtc *rtc = dev_get_drvdata(dev); > + int res; > + > + res = ntxec_read16(rtc->ec, NTXEC_READ_YM); > + if (res < 0) > + return res; > + > + tm->tm_year = (res >> 8) + 100; > + tm->tm_mon = (res & 0xff) - 1; > + > + res = ntxec_read16(rtc->ec, NTXEC_READ_DH); > + if (res < 0) > + return res; > + > + tm->tm_mday = res >> 8; > + tm->tm_hour = res & 0xff; > + > + res = ntxec_read16(rtc->ec, NTXEC_READ_MS); > + if (res < 0) > + return res; > + > + tm->tm_min = res >> 8; > + tm->tm_sec = res & 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 |= ntxec_write8(rtc->ec, NTXEC_WRITE_YEAR, tm->tm_year - 100); > + res |= ntxec_write8(rtc->ec, NTXEC_WRITE_MONTH, tm->tm_mon + 1); > + res |= ntxec_write8(rtc->ec, NTXEC_WRITE_DAY, tm->tm_mday); > + res |= ntxec_write8(rtc->ec, NTXEC_WRITE_HOUR, tm->tm_hour); > + res |= ntxec_write8(rtc->ec, NTXEC_WRITE_MINUTE, tm->tm_min); > + res |= ntxec_write8(rtc->ec, NTXEC_WRITE_SECOND, tm->tm_sec); > + > + return (res < 0)? -EIO : 0; > +} > + > +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 *rtcdev; > + 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); > + > + rtcdev = devm_rtc_device_register(&pdev->dev, "ntxec-rtc", > + &ntxec_rtc_ops, THIS_MODULE); Please use devm_rtc_allocate_device and rtc_register_device. Also, set the supported range (->range_min and ->range_max). -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com