From patchwork Sat Jun 20 22:42:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 11618335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D880161F for ; Mon, 22 Jun 2020 16:06:35 +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 E90E020738 for ; Mon, 22 Jun 2020 16:06:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fMY6VgCa"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=gmx.net header.i=@gmx.net header.b="L0TS6ZsL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E90E020738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gmx.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AZX2EDP1Pdzw569D8bh681NLzOdiJR72/d0MlocXXOI=; b=fMY6VgCaXbD/iUkxRcC9ZAWY3 LRqFDFhmnZiCGOouMGZdGSJK21276WJu9jtk5Oi1BjGozNW8HQwMc0+Yn3Ek+xr3E1okmw7NJ93Rn RxZqJKn6XFp+G7eHq8NuIuvxYX/19UeBnZbQH95UUOZp1Uu5jVxHH/eMUu6FiLwfukRVKJ+Zg1See N2xOkSTD/hrreazRUNAxJYiI5jdYJJyzIwh/IXb3LrIcmkoZ8cGI0dM+RJRqLp2YmJUQDlZg0yJ9B B7k0l8IvVEk9MKUjw9Hqmx6P6jPwMBuqmLKDW8S0vqPrwzHh78mdu3He5TdNOBjI1eNq2MTN0uHJU C+K8Edosw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnOwH-0003m9-Db; Mon, 22 Jun 2020 16:04:53 +0000 Received: from mout.gmx.net ([212.227.17.22]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jmmCo-0007Yn-ML for linux-arm-kernel@lists.infradead.org; Sat, 20 Jun 2020 22:43:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1592692962; bh=SJkG9V9Ioa9d4mEs8B+Ts1mrBz/DoBrNbjbG0YqcoW8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=L0TS6ZsL9wzNE0nZD/qm5ZJjxYPd9mb0bHz+Wc89GxEVngTEO1oEtUnBDPVvqWDSW utlwhk8cyNqJfnConKj8VnRLNbAfPwQZqnawGcKdQqeFVaDWjUrjK7rrApjllI0D3p O3UGHr8naeDiHytOMobzDZmzy8GMBiHrY6pwXuwk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from longitude ([5.146.194.186]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N1wll-1ilEJH1IF7-012Gjq; Sun, 21 Jun 2020 00:42:42 +0200 From: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 08/10] rtc: New driver for RTC in Netronix embedded controller Date: Sun, 21 Jun 2020 00:42:19 +0200 Message-Id: <20200620224222.1312520-7-j.neuschaefer@gmx.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200620224222.1312520-1-j.neuschaefer@gmx.net> References: <20200620224222.1312520-1-j.neuschaefer@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZySx5t2KwCOIhxVvsNRQk0BHTuvPhh9i+aJrLHsgVrp4vASHns/ K/Sng6XDPFxIADTuQhRqPpAiIQTxA/wGOa2PSbQbB4sTuJ0aojUJGE8Ag92fPQLXO9nJD6G QLoS+fsnoA5cMrwfz9npyau2UOADYu9551W2HpisS3/JZwVYAkM5yt+jitcvhvxSNHOoB3r YTQOJ2gOZPtscWai0xOvQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:qUgUBIrzrMw=:9fm4eUEqTt5MBiuFfEhduT mWFDkntqpgEtUv2Z+wMPuN4r6bAeq4tndR38mrmzCTTwLZB0Bno3n8/u/bYcNzbzPW7js1XHK IH0+7IJFAo8/zNkJueuIs2Vm5K4HlDYNbSYdeuZWeiyeHGQJrnlTjqxQpaeQpKgGUsFi+uD6m 9Bo5bpxpM+l8enZ8zhHQak2cDovMNvBpPButuelU02VA9txy2JesT0BiCHjVezk6zEYs06tPp 64+TFHcukjJBVKgBGAbDcY9pmRVV2nebwkJPRsOym1se7tp8pE2rcl0h8b5m3lyvx4Au3ymqI aywGleTVEctLo2I17590XnBgKJ9AMqT0hex7+F4ksL0KL0KBecxuNZfTOMgjqWMcBXhsi7ZLd WM7y8jYuqrIlRp6Lnx0xvzh06TpAhJ4RjsESjmxksmj0uIKsMMwKy4UAPmY+AfBG59ABCTSgF W0Ibt/Rj7q6q1EqWOCZQRpPo7NZYmmNFT9W/5LUqPjCZaSe9gtWVlbE0uaJsikLno8UESeCIj YpMuokn3nRJl3P96FPGYYAIIDesCD+zukBOBbMCIpz67yrL00VEvdVCAO9Xb0H4dzjFkbUltM q3NUyH0qYR7hKkuZdzXvNm2BWzGd5NY7wvH1U0VvjTieArI5kK2wzKvdNCuMUzPizgkrBzuBr lfQpEoOHXG+S1di3VAODVLI1OfETY6qkhihTLJxFAxwQXcToKgWd8fG5WgvBH/zYKDNenF6uz N6SL36afGnNQyz2ZWH4V3XgYysSE3xrxVpJqEHhLGb10h7iA5cXsqc4w7OIJDw1pb/Wl/2r/Z 8Q+eGujEiDuRBivpi2Cz1mpICTIOQs30isN5H6gO73nZOV2Bp8oTCCBrRVv4RJ7HqFf3VmR5g QEJ8aA8sej17imekBzYUVZecSxj8fHMUAqp5Oppdjlt3Hm5ciaR211/cKwzJx2Nt28jA4rnPP GK5hbGIXWMeKvBD0o8p+szrDJtPl+u+cH80iRBr8jJ+PA/3Q5QGZ660fK6hjyEb16NG22QKVP L/ECG3hvFjnJdNMaNEpqNriFUDIsWnGaW1J5qp3ugwvB5F4zU5R1NTJGAWdbN2r5o1BjNABnH cwybOOoZixgQqd50QSyGd2l4h3JcHriVwhM+qV3h9yKHVwkp74WsYomw9NMRgSDY3RMzOMMJP S6uvfUe03QAQM/EL+X7vKcQ1HWp91d21pH3T7c2goOl7w0GVtcclM4l3ke8BskRkHXeih4Yqh PA7OqZbtxvORAmFOC X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [212.227.17.22 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [j.neuschaefer[at]gmx.net] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [212.227.17.22 listed in wl.mailspike.net] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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: Alexandre Belloni , Heiko Stuebner , linux-pwm@vger.kernel.org, Linus Walleij , Thierry Reding , Fabio Estevam , linux-rtc@vger.kernel.org, Mauro Carvalho Chehab , Sam Ravnborg , Andreas Kemnade , NXP Linux Team , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , devicetree@vger.kernel.org, Stephan Gerhold , allen , Sascha Hauer , =?utf-8?q?Jonathan_Neusch=C3=A4fer?= , Lubomir Rintel , Rob Herring , Lee Jones , linux-arm-kernel@lists.infradead.org, Alessandro Zummo , Mark Brown , Pengutronix Kernel Team , Heiko Stuebner , Josua Mayer , Shawn Guo , "David S. Miller" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 --- 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 -- 2.27.0 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 + 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 + +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); + if (IS_ERR(rtcdev)) + return PTR_ERR(rtc); + + return 0; +} + +static const struct of_device_id ntxec_rtc_of_match[] = { + { .compatible = "netronix,ntxec-rtc" }, + { }, +}; +MODULE_DEVICE_TABLE(of, ntxec_rtc_of_match); + +static struct platform_driver ntxec_rtc_driver = { + .driver = { + .name = "ntxec-rtc", + .of_match_table = ntxec_rtc_of_match, + }, + .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");