From patchwork Mon Aug 12 23:28:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 171138 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp155126ily; Mon, 12 Aug 2019 16:28:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZ9+25hZYwIJB3kHmCeURnIOQbqmQSxPDKlyTi3sP+SxImtjsPNSagUDkEW9GJMYxNU5ey X-Received: by 2002:a17:90a:17c4:: with SMTP id q62mr1579037pja.104.1565652537264; Mon, 12 Aug 2019 16:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565652537; cv=none; d=google.com; s=arc-20160816; b=oXPx/qbJ8kRqae44WnJO8QtU9DM+71ETfFMYsHSZLSBj/bzQJGaShCZS9pIZY5VZtr NNfHV+NF4DgEKPcdfyfaC3yk6R0cm9dMn/IqwsF3oU11xXTJwU6hGf8tVCsBdW4HtwYi cogrfWyNUe2U3yG3CnH+1cQLMnvwS4Wy5CANjCgVc8AiMk7gdlWu5Wx4ZbJbXS+25zQV 8jXzGD4EjcoPEcIJKJFDF1h6fhHLPVYFimCflmjuaRRSdGYv/TcDchFvGrBw6itgbBXO zlBIjdNRvs3PK8ZTWwpe2UvF2CuJPo0BV18x4s2Sz5j3IsIXQ4EgZnyKoibR9Zmx0DZl 6CWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XzEGbzEmita+DXCkrbItCIBcB/DYrIF/tf1+4Ixwpp4=; b=jCkQf8LeoX/jb+GoARtZNhmHFgGKKDXuTRJV1pR6fc6Dleo32Av/0OBY8e+CKY0oQ/ b9fiPsjFloqbxjSwsHAU+7hFwfc+dZpISq4U2u17wNhcMRoncT/sqT63oOVo4aRADLWn xBCdux92iy/ildW/5JKpfXeGt0x9IEjR71ii6X1AjCj1Qwvubj5yJO1CKg7qkE7hLl2/ dqEpSPoXsEqc69tzvO9UfpKSwO4z1LwwpBuyMsdURqWiGiTcntly569VjL8tL2lsb6jH 46muOHFtIxLNMevBXLDSsBcy0x6M0/+RTIKAa40yHl/4Ikk13LGnN7pwPBVjNTMy1bV+ GGdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fhcs+cU9; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si6748918pgg.188.2019.08.12.16.28.57; Mon, 12 Aug 2019 16:28:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fhcs+cU9; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbfHLX24 (ORCPT + 8 others); Mon, 12 Aug 2019 19:28:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:60012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfHLX24 (ORCPT ); Mon, 12 Aug 2019 19:28:56 -0400 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 4246220665; Mon, 12 Aug 2019 23:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565652535; bh=o501tcSZ8iwEdK+K1S+CV9iMf5gZNuQYUaXGpk1a0Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhcs+cU9QcwB87J3Vj953PKrW2TYjyRygJOYfxP1LOzTzRG9HBIrZ1QRbnREbUjW9 4PyFx6h+i2MgDMscGpwWA+R5bQk8fpjTv6kEzSW4yh6iP3DLx2NJ705vBuTDjYeZB/ wN6Zefwp4c0kpOMEg9Cql01iPmbuivK+OrXF/2bQ= From: Kevin Hilman To: Alexandre Belloni , linux-rtc@vger.kernel.org Cc: linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong , devicetree@vger.kernel.org Subject: [PATCH v3 1/2] dt-bindings: rtc: new binding for Amlogic VRTC Date: Mon, 12 Aug 2019 16:28:49 -0700 Message-Id: <20190812232850.8016-2-khilman@kernel.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190812232850.8016-1-khilman@kernel.org> References: <20190812232850.8016-1-khilman@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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. Reviewed-by: Rob Herring Signed-off-by: Kevin Hilman --- .../bindings/rtc/rtc-meson-vrtc.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt -- 2.22.0 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..c014f54a9853 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt @@ -0,0 +1,22 @@ +* 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 (in seconds) is to be written. + +Required properties: +- compatible: should be "amlogic,meson-vrtc" +- reg: physical address for the alarm register + +The alarm register is a simple scratch register shared between the +application processors (AP) and the secure co-processor (SCP.) When +the AP suspends, the SCP will use the value of this register to +program an always-on timer before going sleep. When the timer expires, +the SCP will wake up and will then wake the AP. + +Example: + + vrtc: rtc@0a8 { + compatible = "amlogic,meson-vrtc"; + reg = <0x0 0x000a8 0x0 0x4>; + }; From patchwork Mon Aug 12 23:28:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 171139 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp155167ily; Mon, 12 Aug 2019 16:29:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzF8PAVRorjETLpKnFqtfWsSpGtKFqU05Sp9at6f7WyXCc97DAs2m9xlx1xjmgdRW6GzkXA X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr1536640pjp.103.1565652540330; Mon, 12 Aug 2019 16:29:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565652540; cv=none; d=google.com; s=arc-20160816; b=U6Ou1raK8d7QSC1N2uPkVWkqzpYd5GaU4/1Ou9x+KZoiYSMpiti60V4PyeFsWcwJta oeZkAd2vqvXllXWYEKMrfkNyvPv5zs6M6D5IhgcHOc2GfLiI1tPhhwz/+JC+uHHYwk/h lqL8S4TslLKkPITj+rjwgXQg/bGdN1lpHnjDCxAkWSElHIbOxnIRnkQeMLLau19G0COV 7G1eydlbrEWeRpdGH/14j5QFFFmk5O+gwaRoepYPhrjvaxkvPOdEE58ZOB15/uf1sxeV HWhtqnU3T0/cBRVWRuuIXA0LHJQ6ISEGxPGZDAWEYb6Mp4M2lejHAoh1nvUCQ7QGOfeI 8MTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IRYZwNH/946XAD8BX1EHfwKWyK1B9q7UAIYApQUQGL4=; b=FvPYDvrY9TV7/XyQWcZKzlUm/62lsnovVxYgjcJ0RD1Awy4NX5zNpbGhxRqreplRx+ aeKBgz3ChxatuXhFDynZOsYw4iMbLVhA2Bl4b8VCcaQEKDp+U/iuph7oDB6/Z/n0+vJp md5PvLLj4Lj/78SutDlbyZu95m6eVgI+GO/zonhTx/oc+CgpeZeP0S1s2FP5opqkERwU Ot/AK4ocFW5PNveKEzExkUxbBFK11gACalQOuKni3mmp0QI1SUx/eAwVIcgXzuhvrFoE T0+uELcitHAEq4ixaWYTZGozA14uzq8cjy/cZIAW+IKx9opIAp71I9Yzh/uMx1boHWcw ucvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+YYfz1z; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si6748918pgg.188.2019.08.12.16.29.00; Mon, 12 Aug 2019 16:29:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+YYfz1z; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726483AbfHLX27 (ORCPT + 8 others); Mon, 12 Aug 2019 19:28:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:60052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfHLX27 (ORCPT ); Mon, 12 Aug 2019 19:28:59 -0400 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 ABD3B2070C; Mon, 12 Aug 2019 23:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565652537; bh=8DGYsZ2vpwHRKpuHggefj6/H5D3EzUYWO9120Yp/h0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0+YYfz1zJ/m+zWzz8czp4mTt82CPqhqbRI6XkD2KzPKeYZOdwBxgshULUS5KciOsH 78VMjZJKurXfvGNjIFQ0b71bmk6t/mwNreR5SspAmP3Dupc39G75CGTQKEJTpML6qJ PkatQ8DCC+v9alprNV2+EldgGAytz5c2ptn+7qd4= From: Kevin Hilman To: Alexandre Belloni , linux-rtc@vger.kernel.org Cc: linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong , devicetree@vger.kernel.org Subject: [PATCH v3 2/2] rtc: Add Amlogic Virtual Wake RTC Date: Mon, 12 Aug 2019 16:28:50 -0700 Message-Id: <20190812232850.8016-3-khilman@kernel.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190812232850.8016-1-khilman@kernel.org> References: <20190812232850.8016-1-khilman@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Neil Armstrong The Amlogic Meson GX 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.3-rc, rework and modernization] Signed-off-by: Kevin Hilman --- MAINTAINERS | 1 + drivers/rtc/Kconfig | 11 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-meson-vrtc.c | 156 +++++++++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 drivers/rtc/rtc-meson-vrtc.c -- 2.22.0 diff --git a/MAINTAINERS b/MAINTAINERS index 783569e3c4b4..2ae83e1acb05 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1443,6 +1443,7 @@ F: arch/arm64/boot/dts/amlogic/ F: drivers/pinctrl/meson/ F: drivers/mmc/host/meson* F: drivers/soc/amlogic/ +F: drivers/rtc/rtc-meson* N: meson ARM/Amlogic Meson SoC Sound Drivers diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e72f65b61176..7cd325ecc10b 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/RK809/RK817/RK818 RTC" depends on MFD_RK808 diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 6b09c21dc1b6..b50fd3aa81b3 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -102,6 +102,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..4621a4715179 --- /dev/null +++ b/drivers/rtc/rtc-meson-vrtc.c @@ -0,0 +1,156 @@ +// 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 { + void __iomem *io_alarm; + struct rtc_device *rtc; + unsigned long alarm_time; + bool enabled; +}; + +static int meson_vrtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct timespec64 time; + + dev_dbg(dev, "%s\n", __func__); + ktime_get_raw_ts64(&time); + rtc_time64_to_tm(time.tv_sec, tm); + + return 0; +} + +static void meson_vrtc_set_wakeup_time(struct meson_vrtc_data *vrtc, + unsigned long time) +{ + writel_relaxed(time, vrtc->io_alarm); +} + +static int meson_vrtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + + dev_dbg(dev, "%s: alarm->enabled=%d\n", __func__, alarm->enabled); + if (alarm->enabled) + vrtc->alarm_time = rtc_tm_to_time64(&alarm->time); + else + vrtc->alarm_time = 0; + + return 0; +} + +static int meson_vrtc_alarm_irq_enable(struct device *dev, unsigned int enabled) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + + vrtc->enabled = enabled; + return 0; +} + +static const struct rtc_class_ops meson_vrtc_ops = { + .read_time = meson_vrtc_read_time, + .set_alarm = meson_vrtc_set_alarm, + .alarm_irq_enable = meson_vrtc_alarm_irq_enable, +}; + +static int meson_vrtc_probe(struct platform_device *pdev) +{ + struct meson_vrtc_data *vrtc; + int ret; + + vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL); + if (!vrtc) + return -ENOMEM; + + vrtc->io_alarm = devm_platform_ioremap_resource(pdev, 0); + 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_allocate_device(&pdev->dev); + if (IS_ERR(vrtc->rtc)) + return PTR_ERR(vrtc->rtc); + + vrtc->rtc->ops = &meson_vrtc_ops; + ret = rtc_register_device(vrtc->rtc); + if (ret) + return ret; + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int meson_vrtc_suspend(struct device *dev) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + + dev_dbg(dev, "%s\n", __func__); + if (vrtc->alarm_time) { + unsigned long local_time; + long alarm_secs; + struct timespec64 time; + + ktime_get_raw_ts64(&time); + local_time = time.tv_sec; + + dev_dbg(dev, "alarm_time = %lus, local_time=%lus\n", + vrtc->alarm_time, local_time); + alarm_secs = vrtc->alarm_time - local_time; + if (alarm_secs > 0) { + meson_vrtc_set_wakeup_time(vrtc, alarm_secs); + dev_dbg(dev, "system will wakeup in %lds.\n", + alarm_secs); + } else { + dev_err(dev, "alarm time already passed: %lds.\n", + alarm_secs); + } + } + + return 0; +} + +static int meson_vrtc_resume(struct device *dev) +{ + struct meson_vrtc_data *vrtc = dev_get_drvdata(dev); + + dev_dbg(dev, "%s\n", __func__); + + vrtc->alarm_time = 0; + meson_vrtc_set_wakeup_time(vrtc, 0); + return 0; +} +#endif +static SIMPLE_DEV_PM_OPS(meson_vrtc_pm_ops, + meson_vrtc_suspend, meson_vrtc_resume); + +static const struct of_device_id meson_vrtc_dt_match[] = { + { .compatible = "amlogic,meson-vrtc"}, + {}, +}; +MODULE_DEVICE_TABLE(of, meson_vrtc_dt_match); + +static struct platform_driver meson_vrtc_driver = { + .probe = meson_vrtc_probe, + .driver = { + .name = "meson-vrtc", + .of_match_table = meson_vrtc_dt_match, + .pm = &meson_vrtc_pm_ops, + }, +}; + +module_platform_driver(meson_vrtc_driver); + +MODULE_DESCRIPTION("Amlogic Virtual Wakeup RTC Timer driver"); +MODULE_LICENSE("GPL");