rtc: add new Amlogic Virtual Wake RTC
v2 cover rtc: add new Amlogic Virtual Wake RTC
From: Kevin Hilman <[email protected]>
Add a new driver for the virtual wake RTC on Amlogic SoCs.
The RTC is virtual from the Linux side because it's a hardware timer managed by firmware on the secure co-processor (SCP.) The interface is 1 register where a wakeup time (in seconds) is written. The SCP then uses this value to program an always-on timer.
Changes since v1:
- add MAINTAINERS entry
- add nop ->alarm_irq_enable() (workaround for RTC core limitation pointed out by Alexandre Belloni)
- remove unused ->read_alarm()
- fix statics
- move resume to dev_pm_ops
- add suspend hook
- don't calculate (or write) the alarm timer value until suspend time
Changes since Neil's original version
- move from do_gettimeofday() to ktime_get()
Kevin Hilman (1): dt-bindings: rtc: new binding for Amlogic VRTC
Neil Armstrong (1):
rtc: Add Amlogic Virtual Wake RTC
.../bindings/rtc/rtc-meson-vrtc.txt | 22 +++ drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-meson-vrtc.c | 149 ++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt create mode 100644 drivers/rtc/rtc-meson-vrtc.c
Signature · 1 line
2.22.0
PATCH v2 1/2 dt-bindings: rtc: new binding for Amlogic VRTC
From: Kevin Hilman <[email protected]>
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.
--- .../bindings/rtc/rtc-meson-vrtc.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt
Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt new file +22 -0
@@ -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>; + };
Signature · 1 line
2.22.0
PATCH v2 2/2 rtc: Add Amlogic Virtual Wake RTC
In reply to Kevin HilmanFrom: Neil Armstrong <[email protected]>
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.
--- MAINTAINERS | 1 + drivers/rtc/Kconfig | 11 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-meson-vrtc.c | 153 +++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 drivers/rtc/rtc-meson-vrtc.c
MAINTAINERS +1 -0
@@ -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
drivers/rtc/Kconfig +11 -0
@@ -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
drivers/rtc/Makefile +1 -0
@@ -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
drivers/rtc/rtc-meson-vrtc.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.22.0
Alexandre Belloni
maintainerRe: [PATCH v2 2/2] rtc: Add Amlogic Virtual Wake RTC
drivers/rtc/rtc-meson-vrtc.c line 75
Quoted 11 lines · Kevin Hilman
drivers/rtc/rtc-meson-vrtc.c new file +11
-0+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 ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + vrtc->io_alarm =devm_ioremap_resource (&pdev->dev, res);
You could use devm_platform_ioremap_resource.
drivers/rtc/rtc-meson-vrtc.c line 84
Quoted 9 lines
drivers/rtc/rtc-meson-vrtc.c new file +9
-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_device_register (&pdev->dev,"meson-vrtc" , + &meson_vrtc_ops,THIS_MODULE );
Please use devm_rtc_allocate_device and rtc_register_device.
Quoted 6 lines
drivers/rtc/rtc-meson-vrtc.c new file +6
-0+if (IS_ERR (vrtc->rtc)) +return PTR_ERR (vrtc->rtc); + +return 0 ; +} +
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Kevin Hilman
maintainerRe: [PATCH v2 2/2] rtc: Add Amlogic Virtual Wake RTC
Quoted 15 lines · Alexandre Belloni
drivers/rtc/rtc-meson-vrtc.c line 75
Quoted 11 lines · Kevin Hilman
drivers/rtc/rtc-meson-vrtc.c new file +11
-0+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 ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + vrtc->io_alarm =devm_ioremap_resource (&pdev->dev, res);You could use
devm_platform_ioremap_resource.
Quoted 12 lines
drivers/rtc/rtc-meson-vrtc.c line 84
Quoted 9 lines
drivers/rtc/rtc-meson-vrtc.c new file +9
-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_device_register (&pdev->dev,"meson-vrtc" , + &meson_vrtc_ops,THIS_MODULE );Please use
devm_rtc_allocate_deviceandrtc_register_device.
OK, will update both and send a v3.
Thanks for the review,
Kevin