dt-bindings: rtc: new binding for Amlogic VRTC
PATCH 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.
--- .../devicetree/bindings/rtc/rtc-meson-vrtc.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt
Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt new file +16 -0
@@ -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>; + };
Signature · 1 line
2.21.0
PATCH 2/2 rtc: Add Amlogic Virtual Wake RTC
From: Neil Armstrong <[email protected]>
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.
---
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/[email protected]/
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
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/RK818 RTC" depends on MFD_RK808
drivers/rtc/Makefile +1 -0
@@ -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
drivers/rtc/rtc-meson-vrtc.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.21.0
Alexandre Belloni
maintainerRe: [PATCH 2/2] rtc: Add Amlogic Virtual Wake RTC
Hello Kevin,
drivers/rtc/rtc-meson-vrtc.c line 27
Quoted 7 lines · Kevin Hilman
drivers/rtc/rtc-meson-vrtc.c new file +7
-0+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 );
The RTC is supposed to be set to UTC so the TZ adjustment is not necessary.
Review
Quoted 2 lines
(quoted diff) +2
-0+ rtc_time_to_tm(local_time, tm); +
Please use the 64 bit version.
Quoted 14 lines
drivers/rtc/rtc-meson-vrtc.c new file +14
-0+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);
drivers/rtc/rtc-meson-vrtc.c line 53
Quoted 10 lines
drivers/rtc/rtc-meson-vrtc.c new file +10
-0+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; +
Use the 64bit version which makes it clear that it never fails (checking ret is useless).
drivers/rtc/rtc-meson-vrtc.c line 59
Quoted 6 lines
drivers/rtc/rtc-meson-vrtc.c new file +6
-0+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) {
This is already ensured by the core so no need to check here.
Quoted 9 lines
drivers/rtc/rtc-meson-vrtc.c new file +9
-0+ 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 );
drivers/rtc/rtc-meson-vrtc.c line 78
Quoted 10 lines
drivers/rtc/rtc-meson-vrtc.c new file +10
-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) {
I think this test is inverted.
Quoted 30 lines
drivers/rtc/rtc-meson-vrtc.c new file +30
-0+ 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);
drivers/rtc/rtc-meson-vrtc.c line 118
Quoted 10 lines
drivers/rtc/rtc-meson-vrtc.c new file +10
-0+ +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); +
Please use devm_rtc_allocate_device and rtc_register_device. This doesn't help much but my plan is to get rid of devm_rtc_device_register.
I suppose you don't get any interrupt for the alarm?
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 6 lines · Kevin Hilman
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.
Quoted 6 lines
Signed-off-by Kevin Hilman <[email protected]>--- .../devicetree/bindings/rtc/rtc-meson-vrtc.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-meson-vrtc.txt