From patchwork Fri Jun 7 19:43:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 10982699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29C4976 for ; Fri, 7 Jun 2019 19:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1870D28B65 for ; Fri, 7 Jun 2019 19:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C04028B73; Fri, 7 Jun 2019 19:43:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B1E7428B68 for ; Fri, 7 Jun 2019 19:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=DiV8sojb8lCZGzCLiGkowHj3qz7H8pzf64gSd6FacAs=; b=WkSjEgfrvpKpiR ADTP1j+j2Wh9FuSZQq+3+bq7/ZUKJChqoVduJpODUudP4ssGD2cNN1FWVE39tLmc9lAEm0ukD29Bw 76bThZNHODDybskXyzHa116mYrDFWZa+MQ+PUQEwpaJDO0eiX2D6BGVqNqXDaaVazLQgiv6eUxVZE BFzE8WNiE5x1MfOxGPDSpx/tWELonp2mFDXG3G7dEG7ld1x3/F1wKt13H02v634BwB7VlO6RyijY4 BsMjkx6syeCFEZrnWQF53bi3tS/QZIP9AHJE5Wrac4wfwaoqLkEoxUBZbflnK3T7weMTb+7unY/iy xg4FsVKgvrTyuYnBXpEg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZKmB-00007s-9S; Fri, 07 Jun 2019 19:43:47 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZKm8-00006d-Dy; Fri, 07 Jun 2019 19:43:45 +0000 Received: from localhost (c-71-197-186-152.hsd1.wa.comcast.net [71.197.186.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACD9720868; Fri, 7 Jun 2019 19:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559936623; bh=tFAX1TrUh+zWhm4cmBHIYK3G5smuy2djcrTGV59Ksuw=; h=From:To:Cc:Subject:Date:From; b=0oUCfe4AFMgIqpLhsK2SHdwXSoWkt+P20/GrYCplr6QfJXa76J7i7SRSkPx2TloI3 epYMnraxb41OXVZvSeBI71eWnQWkNU/VlY0qfL2tTCNmFOX2EkIT+SS6RFNmF7ui3p cbaYb85XTpJX3G1h3pDJN5LREahcfvbK12lP7dns= From: Kevin Hilman To: linux-rtc@vger.kernel.org, Alexandre Belloni Subject: [PATCH 1/2] dt-bindings: rtc: new binding for Amlogic VRTC Date: Fri, 7 Jun 2019 12:43:42 -0700 Message-Id: <20190607194343.18359-1-khilman@kernel.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190607_124344_492116_A98D31F6 X-CRM114-Status: UNSURE ( 9.34 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, Kevin Hilman , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kevin Hilman Add binding fo the new VRTC driver for Amlogic SoCs. The 64-bit family of SoCs only has an RTC managed by firmware, and this VRTC driver provides the simple, one-register firmware interface. Signed-off-by: Kevin Hilman Reviewed-by: Rob Herring --- .../devicetree/bindings/rtc/rtc-meson-vrtc.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt diff --git a/Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt b/Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt new file mode 100644 index 000000000000..f02886179788 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt @@ -0,0 +1,16 @@ +* Amlogic Virtual RTC (VRTC) + +This is a Linux interface to an RTC managed by firmware, hence it's +virtual from a Linux perspective. The interface is 1 register where +an alarm time is to be written. + +Required properties: +- compatible: should be "amlogic,meson-vrtc" +- reg: physical address for the alarm register + +Example: + + vrtc: rtc@0a8 { + compatible = "amlogic,meson-vrtc"; + reg = <0x0 0x000a8 0x0 0x4>; + }; From patchwork Fri Jun 7 19:43:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 10982703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C7DA6C5 for ; Fri, 7 Jun 2019 19:43:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09A1528B65 for ; Fri, 7 Jun 2019 19:43:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1B1428B70; Fri, 7 Jun 2019 19:43:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E49A28B65 for ; Fri, 7 Jun 2019 19:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=mZfYibnT1muHpvnaxYe4L7PgGyN/pHFg6ibFPMwSBew=; b=dnf9zEYKcVX0WI XWbaP3U3ue81aa1lJhb/CMfCLRshs8tRvCs1GzNefCVdPTGODOd0DB9sPiZ/NoMCj2ak7C1xmFp3f 6fJmXFMhZpRKN2/9YgFF+nxGv5csiR+d/W3J1HGZOcdDXCHOGjS5f7zT7CisN7fGgRrTHugUZ4OJV GeHoI6weMUVt3bTJdDfkkJQ/clYKm/fyRRzFQV94QVVaCPX3Lj0g7dKGL8nZwxsfWnsgxulfiJ9pl xqybPHuAMj6xSyxY4G83PJHBYsTMJahHHclFJ8SNzDtP6LDpEaOIlgtQku2udcR32jCYLEfK3IRBs K1EktxdLs1ZcUQTWtTXw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZKmJ-0000Iw-Qj; Fri, 07 Jun 2019 19:43:55 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZKm8-00006e-K9; Fri, 07 Jun 2019 19:43:46 +0000 Received: from localhost (c-71-197-186-152.hsd1.wa.comcast.net [71.197.186.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B8D9208E3; Fri, 7 Jun 2019 19:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559936624; bh=GJ+QUPOmqyMWmUxURQkzA0pp+rSOKSz2pl7nJLh+RMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SKbOO26sT5XEOapBMw/AuZoThvOSfFkw4w9M+A34WaTRQf2fVb96J4g2vDEXOAzak InAy+7qukY1NEhd03LB2wkKeFPQ5jcQYSZPjZQ17s6z0vjd+mmY8vkthUwH6LwXzos cmRifOzaftSYPLrS42G4d5K+vNt5ZDLsGZJD9V8g= From: Kevin Hilman To: linux-rtc@vger.kernel.org, Alexandre Belloni Subject: [PATCH 2/2] rtc: Add Amlogic Virtual Wake RTC Date: Fri, 7 Jun 2019 12:43:43 -0700 Message-Id: <20190607194343.18359-2-khilman@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607194343.18359-1-khilman@kernel.org> References: <20190607194343.18359-1-khilman@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190607_124344_694465_FBF098E5 X-CRM114-Status: GOOD ( 18.77 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Neil Armstrong , Kevin Hilman , linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Neil Armstrong The 64-bit Amlogic SoCs uses a special register to store the time in seconds to wakeup after a system suspend. In order to be able to reuse the RTC wakealarm feature, this driver implements a fake RTC device which uses the system time to deduce a suspend delay. Signed-off-by: Neil Armstrong [khilman: rebase to v5.2-rc, moved from do_gettimeofday()] Tested-by: Kevin Hilman Signed-off-by: Kevin Hilman --- Originally written/sumbmitted by Neil as part of a broader/suspend resume series[1] for the GXBB family. Newer SoCs support PSCI properly, so don't need the PSCI changes there, and this driver alone enables RTC wakeups from suspend. [1] https://lore.kernel.org/lkml/1478183365-23708-1-git-send-email-narmstrong@baylibre.com/ drivers/rtc/Kconfig | 11 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-meson-vrtc.c | 149 +++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 drivers/rtc/rtc-meson-vrtc.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 5c0790eed656..78d2967d5ee3 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -373,6 +373,17 @@ config RTC_DRV_MAX77686 This driver can also be built as a module. If so, the module will be called rtc-max77686. +config RTC_DRV_MESON_VRTC + tristate "Amlogic Meson Virtual RTC" + depends on ARCH_MESON || COMPILE_TEST + default m if ARCH_MESON + help + If you say yes here you will get support for the + Virtual RTC of Amlogic SoCs. + + This driver can also be built as a module. If so, the module + will be called rtc-meson-vrtc. + config RTC_DRV_RK808 tristate "Rockchip RK805/RK808/RK818 RTC" depends on MFD_RK808 diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 9d997faa2c26..9485fb46b023 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -101,6 +101,7 @@ obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o obj-$(CONFIG_RTC_DRV_MAX8997) += rtc-max8997.o obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o +obj-$(CONFIG_RTC_DRV_MESON_VRTC)+= rtc-meson-vrtc.o obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o obj-$(CONFIG_RTC_DRV_MCP795) += rtc-mcp795.o obj-$(CONFIG_RTC_DRV_MESON) += rtc-meson.o diff --git a/drivers/rtc/rtc-meson-vrtc.c b/drivers/rtc/rtc-meson-vrtc.c new file mode 100644 index 000000000000..f695f65ab199 --- /dev/null +++ b/drivers/rtc/rtc-meson-vrtc.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 BayLibre, SAS + * Author: Neil Armstrong + * Copyright (C) 2015 Amlogic, Inc. All rights reserved. + */ +#include +#include +#include +#include +#include +#include + +struct meson_vrtc_data { + struct platform_device *pdev; + void __iomem *io_alarm; + struct rtc_device *rtc; + unsigned long alarm_time; +}; + +static int meson_vrtc_read_time(struct device *dev, struct rtc_time *tm) +{ + unsigned long local_time; + struct timespec64 time; + + ktime_get_raw_ts64(&time); + local_time = time.tv_sec - (sys_tz.tz_minuteswest * 60); + rtc_time_to_tm(local_time, tm); + + return 0; +} + +static void meson_vrtc_set_wakeup_time(struct meson_vrtc_data *vrtc, + unsigned long time) +{ + writel_relaxed(time, vrtc->io_alarm); + + dev_dbg(&vrtc->pdev->dev, "set_wakeup_time: %lu\n", time); +} + +static int meson_vrtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + struct timespec64 time; + unsigned long local_time; + unsigned long alarm_secs; + int ret; + + if (alarm->enabled) { + ret = rtc_tm_to_time(&alarm->time, &alarm_secs); + if (ret) + return ret; + + ktime_get_raw_ts64(&time); + local_time = time.tv_sec - (sys_tz.tz_minuteswest * 60); + + vrtc->alarm_time = alarm_secs; + + if (alarm_secs >= local_time) { + alarm_secs = alarm_secs - local_time; + + meson_vrtc_set_wakeup_time(vrtc, alarm_secs); + + pr_debug("system will wakeup %lus later\n", alarm_secs); + } + } else { + vrtc->alarm_time = 0; + meson_vrtc_set_wakeup_time(vrtc, 0); + } + + return 0; +} + +static int meson_vrtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + + if (!vrtc->alarm_time) { + alm->enabled = true; + + rtc_time_to_tm(vrtc->alarm_time, &alm->time); + } + + return 0; +} + +static const struct rtc_class_ops meson_vrtc_ops = { + .read_time = meson_vrtc_read_time, + .set_alarm = meson_vrtc_set_alarm, + .read_alarm = meson_vrtc_read_alarm, +}; + +static int meson_vrtc_probe(struct platform_device *pdev) +{ + struct meson_vrtc_data *vrtc; + struct resource *res; + + vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL); + if (!vrtc) + return -ENOMEM; + + vrtc->pdev = pdev; + + /* Alarm registers */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + vrtc->io_alarm = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(vrtc->io_alarm)) + return PTR_ERR(vrtc->io_alarm); + + device_init_wakeup(&pdev->dev, 1); + + platform_set_drvdata(pdev, vrtc); + + vrtc->rtc = devm_rtc_device_register(&pdev->dev, "meson-vrtc", + &meson_vrtc_ops, THIS_MODULE); + if (IS_ERR(vrtc->rtc)) + return PTR_ERR(vrtc->rtc); + + return 0; +} + +int meson_vrtc_resume(struct platform_device *pdev) +{ + struct meson_vrtc_data *vrtc = platform_get_drvdata(pdev); + + meson_vrtc_set_wakeup_time(vrtc, 0); + + return 0; +} + +static const struct of_device_id meson_vrtc_dt_match[] = { + { .compatible = "amlogic,meson-vrtc"}, + {}, +}; +MODULE_DEVICE_TABLE(of, meson_vrtc_dt_match); + +struct platform_driver meson_vrtc_driver = { + .driver = { + .name = "meson-vrtc", + .of_match_table = meson_vrtc_dt_match, + }, + .probe = meson_vrtc_probe, + .resume = meson_vrtc_resume, +}; + +module_platform_driver(meson_vrtc_driver); + +MODULE_DESCRIPTION("Amlogic Virtual Wakeup RTC Timer driver"); +MODULE_LICENSE("GPL");