Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'rtc-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni:
"This cycle, we have a new RTC driver, for the SpacemiT P1. The optee
driver gets alarm support. We also get a fix for a race condition that
was fairly rare unless while stress testing the alarms.

Subsystem:
- Fix race when setting alarm
- Ensure alarm irq is enabled when UIE is enabled
- remove unneeded 'fast_io' parameter in regmap_config

New driver:
- SpacemiT P1 RTC

Drivers:
- efi: Remove wakeup functionality
- optee: add alarms support
- s3c: Drop support for S3C2410
- zynqmp: Restore alarm functionality after kexec transition"

* tag 'rtc-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (29 commits)
rtc: interface: Ensure alarm irq is enabled when UIE is enabled
rtc: tps6586x: Fix initial enable_irq/disable_irq balance
rtc: cpcap: Fix initial enable_irq/disable_irq balance
rtc: isl12022: Fix initial enable_irq/disable_irq balance
rtc: interface: Fix long-standing race when setting alarm
rtc: pcf2127: fix watchdog interrupt mask on pcf2131
rtc: zynqmp: Restore alarm functionality after kexec transition
rtc: amlogic-a4: Optimize global variables
rtc: sd2405al: Add I2C address.
rtc: Kconfig: move symbols to proper section
rtc: optee: make optee_rtc_pm_ops static
rtc: optee: Fix error code in optee_rtc_read_alarm()
rtc: optee: fix error code in probe()
dt-bindings: rtc: Convert apm,xgene-rtc to DT schema
rtc: spacemit: support the SpacemiT P1 RTC
rtc: optee: add alarm related rtc ops to optee rtc driver
rtc: optee: remove unnecessary memory operations
rtc: optee: fix memory leak on driver removal
rtc: x1205: Fix Xicor X1205 vendor prefix
dt-bindings: rtc: Fix Xicor X1205 vendor prefix
...

+753 -354
+45
Documentation/devicetree/bindings/rtc/apm,xgene-rtc.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/rtc/apm,xgene-rtc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: APM X-Gene Real Time Clock 8 + 9 + maintainers: 10 + - Khuong Dinh <khuong@os.amperecomputing.com> 11 + 12 + properties: 13 + compatible: 14 + const: apm,xgene-rtc 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + maxItems: 1 21 + 22 + '#clock-cells': 23 + const: 1 24 + 25 + clocks: 26 + maxItems: 1 27 + 28 + required: 29 + - compatible 30 + - reg 31 + - interrupts 32 + - '#clock-cells' 33 + - clocks 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + rtc@10510000 { 40 + compatible = "apm,xgene-rtc"; 41 + reg = <0x10510000 0x400>; 42 + interrupts = <0x0 0x46 0x4>; 43 + #clock-cells = <1>; 44 + clocks = <&rtcclk 0>; 45 + };
-74
Documentation/devicetree/bindings/rtc/isil,isl12057.txt
··· 1 - Intersil ISL12057 I2C RTC/Alarm chip 2 - 3 - ISL12057 is a trivial I2C device (it has simple device tree bindings, 4 - consisting of a compatible field, an address and possibly an interrupt 5 - line). 6 - 7 - Nonetheless, it also supports an option boolean property 8 - ("wakeup-source") to handle the specific use-case found 9 - on at least three in-tree users of the chip (NETGEAR ReadyNAS 102, 104 10 - and 2120 ARM-based NAS); On those devices, the IRQ#2 pin of the chip 11 - (associated with the alarm supported by the driver) is not connected 12 - to the SoC but to a PMIC. It allows the device to be powered up when 13 - RTC alarm rings. In order to mark the device has a wakeup source and 14 - get access to the 'wakealarm' sysfs entry, this specific property can 15 - be set when the IRQ#2 pin of the chip is not connected to the SoC but 16 - can wake up the device. 17 - 18 - Required properties supported by the device: 19 - 20 - - "compatible": must be "isil,isl12057" 21 - - "reg": I2C bus address of the device 22 - 23 - Optional properties: 24 - 25 - - "wakeup-source": mark the chip as a wakeup source, independently of 26 - the availability of an IRQ line connected to the SoC. 27 - 28 - 29 - Example isl12057 node without IRQ#2 pin connected (no alarm support): 30 - 31 - isl12057: isl12057@68 { 32 - compatible = "isil,isl12057"; 33 - reg = <0x68>; 34 - }; 35 - 36 - 37 - Example isl12057 node with IRQ#2 pin connected to main SoC via MPP6 (note 38 - that the pinctrl-related properties below are given for completeness and 39 - may not be required or may be different depending on your system or 40 - SoC, and the main function of the MPP used as IRQ line, i.e. 41 - "interrupt-parent" and "interrupts" are usually sufficient): 42 - 43 - pinctrl { 44 - ... 45 - 46 - rtc_alarm_pin: rtc_alarm_pin { 47 - marvell,pins = "mpp6"; 48 - marvell,function = "gpio"; 49 - }; 50 - 51 - ... 52 - 53 - }; 54 - 55 - ... 56 - 57 - isl12057: isl12057@68 { 58 - compatible = "isil,isl12057"; 59 - reg = <0x68>; 60 - pinctrl-0 = <&rtc_alarm_pin>; 61 - pinctrl-names = "default"; 62 - interrupt-parent = <&gpio0>; 63 - interrupts = <6 IRQ_TYPE_EDGE_FALLING>; 64 - }; 65 - 66 - 67 - Example isl12057 node without IRQ#2 pin connected to the SoC but to a 68 - PMIC, allowing the device to be started based on configured alarm: 69 - 70 - isl12057: isl12057@68 { 71 - compatible = "isil,isl12057"; 72 - reg = <0x68>; 73 - wakeup-source; 74 - };
-10
Documentation/devicetree/bindings/rtc/nxp,pcf85063.yaml
··· 65 65 - if: 66 66 properties: 67 67 compatible: 68 - contains: 69 - enum: 70 - - nxp,pcf85063 71 - then: 72 - properties: 73 - quartz-load-femtofarads: 74 - const: 7000 75 - - if: 76 - properties: 77 - compatible: 78 68 not: 79 69 contains: 80 70 enum:
+3 -37
Documentation/devicetree/bindings/rtc/s3c-rtc.yaml
··· 13 13 compatible: 14 14 oneOf: 15 15 - enum: 16 - - samsung,s3c2410-rtc 17 - - samsung,s3c2416-rtc 18 - - samsung,s3c2443-rtc 19 16 - samsung,s3c6410-rtc 20 17 - items: 21 18 - enum: ··· 26 29 maxItems: 1 27 30 28 31 clocks: 29 - description: 30 - Must contain a list of phandle and clock specifier for the rtc 31 - clock and in the case of a s3c6410 compatible controller, also 32 - a source clock. 33 - minItems: 1 34 32 maxItems: 2 35 33 36 34 clock-names: 37 - description: 38 - Must contain "rtc" and for a s3c6410 compatible controller 39 - also "rtc_src". 40 - minItems: 1 41 - maxItems: 2 35 + items: 36 + - const: rtc 37 + - const: rtc_src 42 38 43 39 interrupts: 44 40 description: ··· 44 54 45 55 allOf: 46 56 - $ref: rtc.yaml# 47 - - if: 48 - properties: 49 - compatible: 50 - contains: 51 - enum: 52 - - samsung,s3c6410-rtc 53 - - samsung,exynos3250-rtc 54 - then: 55 - properties: 56 - clocks: 57 - minItems: 2 58 - maxItems: 2 59 - clock-names: 60 - items: 61 - - const: rtc 62 - - const: rtc_src 63 - else: 64 - properties: 65 - clocks: 66 - minItems: 1 67 - maxItems: 1 68 - clock-names: 69 - items: 70 - - const: rtc 71 57 72 58 unevaluatedProperties: false 73 59
+4 -2
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
··· 38 38 - dallas,ds1672 39 39 # Extremely Accurate I²C RTC with Integrated Crystal and SRAM 40 40 - dallas,ds3232 41 + # Dallas m41t00 Real-time Clock 42 + - dallas,m41t00 41 43 # SD2405AL Real-Time Clock 42 44 - dfrobot,sd2405al 43 45 # EM Microelectronic EM3027 RTC ··· 85 83 - via,vt8500-rtc 86 84 # I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC 87 85 - whwave,sd3078 88 - # Xircom X1205 I2C RTC 89 - - xircom,x1205 86 + # Xicor/Intersil X1205 I2C RTC 87 + - xicor,x1205 90 88 91 89 reg: 92 90 maxItems: 1
-28
Documentation/devicetree/bindings/rtc/xgene-rtc.txt
··· 1 - * APM X-Gene Real Time Clock 2 - 3 - RTC controller for the APM X-Gene Real Time Clock 4 - 5 - Required properties: 6 - - compatible : Should be "apm,xgene-rtc" 7 - - reg: physical base address of the controller and length of memory mapped 8 - region. 9 - - interrupts: IRQ line for the RTC. 10 - - #clock-cells: Should be 1. 11 - - clocks: Reference to the clock entry. 12 - 13 - Example: 14 - 15 - rtcclk: rtcclk { 16 - compatible = "fixed-clock"; 17 - #clock-cells = <1>; 18 - clock-frequency = <100000000>; 19 - clock-output-names = "rtcclk"; 20 - }; 21 - 22 - rtc: rtc@10510000 { 23 - compatible = "apm,xgene-rtc"; 24 - reg = <0x0 0x10510000 0x0 0x400>; 25 - interrupts = <0x0 0x46 0x4>; 26 - #clock-cells = <1>; 27 - clocks = <&rtcclk 0>; 28 - };
+24 -14
drivers/rtc/Kconfig
··· 406 406 This driver can also be built as a module. If so, the module 407 407 will be called rtc-max77686. 408 408 409 + config RTC_DRV_SPACEMIT_P1 410 + tristate "SpacemiT P1 RTC" 411 + depends on ARCH_SPACEMIT || COMPILE_TEST 412 + select MFD_SPACEMIT_P1 413 + default ARCH_SPACEMIT 414 + help 415 + Enable support for the RTC function in the SpacemiT P1 PMIC. 416 + This driver can also be built as a module, which will be called 417 + "spacemit-p1-rtc". 418 + 409 419 config RTC_DRV_NCT3018Y 410 420 tristate "Nuvoton NCT3018Y" 411 421 depends on OF ··· 2054 2044 This driver can also be built as a module, if so, the module 2055 2045 will be called "rtc-rtca3". 2056 2046 2057 - comment "HID Sensor RTC drivers" 2058 - 2059 - config RTC_DRV_HID_SENSOR_TIME 2060 - tristate "HID Sensor Time" 2061 - depends on USB_HID 2062 - depends on HID_SENSOR_HUB && IIO 2063 - select HID_SENSOR_IIO_COMMON 2064 - help 2065 - Say yes here to build support for the HID Sensors of type Time. 2066 - This drivers makes such sensors available as RTCs. 2067 - 2068 - If this driver is compiled as a module, it will be named 2069 - rtc-hid-sensor-time. 2070 - 2071 2047 config RTC_DRV_GOLDFISH 2072 2048 tristate "Goldfish Real Time Clock" 2073 2049 depends on HAS_IOMEM ··· 2127 2131 2128 2132 This RTC module can be used as a wakeup source. 2129 2133 Please note that it is not battery-powered. 2134 + 2135 + comment "HID Sensor RTC drivers" 2136 + 2137 + config RTC_DRV_HID_SENSOR_TIME 2138 + tristate "HID Sensor Time" 2139 + depends on USB_HID 2140 + depends on HID_SENSOR_HUB && IIO 2141 + select HID_SENSOR_IIO_COMMON 2142 + help 2143 + Say yes here to build support for the HID Sensors of type Time. 2144 + This drivers makes such sensors available as RTCs. 2145 + 2146 + If this driver is compiled as a module, it will be named 2147 + rtc-hid-sensor-time. 2130 2148 2131 2149 endif # RTC_CLASS
+1
drivers/rtc/Makefile
··· 172 172 obj-$(CONFIG_RTC_DRV_SD3078) += rtc-sd3078.o 173 173 obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 174 174 obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o 175 + obj-$(CONFIG_RTC_DRV_SPACEMIT_P1) += rtc-spacemit-p1.o 175 176 obj-$(CONFIG_RTC_DRV_SPEAR) += rtc-spear.o 176 177 obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o 177 178 obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
+27
drivers/rtc/interface.c
··· 443 443 else 444 444 err = rtc->ops->set_alarm(rtc->dev.parent, alarm); 445 445 446 + /* 447 + * Check for potential race described above. If the waiting for next 448 + * second, and the second just ticked since the check above, either 449 + * 450 + * 1) It ticked after the alarm was set, and an alarm irq should be 451 + * generated. 452 + * 453 + * 2) It ticked before the alarm was set, and alarm irq most likely will 454 + * not be generated. 455 + * 456 + * While we cannot easily check for which of these two scenarios we 457 + * are in, we can return -ETIME to signal that the timer has already 458 + * expired, which is true in both cases. 459 + */ 460 + if ((scheduled - now) <= 1) { 461 + err = __rtc_read_time(rtc, &tm); 462 + if (err) 463 + return err; 464 + now = rtc_tm_to_time64(&tm); 465 + if (scheduled <= now) 466 + return -ETIME; 467 + } 468 + 446 469 trace_rtc_set_alarm(rtc_tm_to_time64(&alarm->time), err); 447 470 return err; 448 471 } ··· 617 594 rtc->uie_rtctimer.node.expires = ktime_add(now, onesec); 618 595 rtc->uie_rtctimer.period = ktime_set(1, 0); 619 596 err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer); 597 + if (!err && rtc->ops && rtc->ops->alarm_irq_enable) 598 + err = rtc->ops->alarm_irq_enable(rtc->dev.parent, 1); 599 + if (err) 600 + goto out; 620 601 } else { 621 602 rtc_timer_remove(rtc, &rtc->uie_rtctimer); 622 603 }
+7 -7
drivers/rtc/rtc-amlogic-a4.c
··· 72 72 const struct aml_rtc_config *config; 73 73 }; 74 74 75 - static const struct regmap_config aml_rtc_regmap_config = { 76 - .reg_bits = 32, 77 - .val_bits = 32, 78 - .reg_stride = 4, 79 - .max_register = RTC_REAL_TIME, 80 - }; 81 - 82 75 static inline u32 gray_to_binary(u32 gray) 83 76 { 84 77 u32 bcd = gray; ··· 320 327 struct aml_rtc_data *rtc; 321 328 void __iomem *base; 322 329 int ret = 0; 330 + 331 + const struct regmap_config aml_rtc_regmap_config = { 332 + .reg_bits = 32, 333 + .val_bits = 32, 334 + .reg_stride = 4, 335 + .max_register = RTC_REAL_TIME, 336 + }; 323 337 324 338 rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL); 325 339 if (!rtc)
+1
drivers/rtc/rtc-cpcap.c
··· 268 268 return err; 269 269 270 270 rtc->alarm_irq = platform_get_irq(pdev, 0); 271 + rtc->alarm_enabled = true; 271 272 err = devm_request_threaded_irq(dev, rtc->alarm_irq, NULL, 272 273 cpcap_rtc_alarm_irq, 273 274 IRQF_TRIGGER_NONE | IRQF_ONESHOT,
+2 -74
drivers/rtc/rtc-efi.c
··· 112 112 return true; 113 113 } 114 114 115 - static int efi_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 116 - { 117 - efi_time_t eft; 118 - efi_status_t status; 119 - 120 - /* 121 - * As of EFI v1.10, this call always returns an unsupported status 122 - */ 123 - status = efi.get_wakeup_time((efi_bool_t *)&wkalrm->enabled, 124 - (efi_bool_t *)&wkalrm->pending, &eft); 125 - 126 - if (status != EFI_SUCCESS) 127 - return -EINVAL; 128 - 129 - if (!convert_from_efi_time(&eft, &wkalrm->time)) 130 - return -EIO; 131 - 132 - return rtc_valid_tm(&wkalrm->time); 133 - } 134 - 135 - static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 136 - { 137 - efi_time_t eft; 138 - efi_status_t status; 139 - 140 - convert_to_efi_time(&wkalrm->time, &eft); 141 - 142 - /* 143 - * XXX Fixme: 144 - * As of EFI 0.92 with the firmware I have on my 145 - * machine this call does not seem to work quite 146 - * right 147 - * 148 - * As of v1.10, this call always returns an unsupported status 149 - */ 150 - status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft); 151 - 152 - dev_warn(dev, "write status is %d\n", (int)status); 153 - 154 - return status == EFI_SUCCESS ? 0 : -EINVAL; 155 - } 156 - 157 115 static int efi_read_time(struct device *dev, struct rtc_time *tm) 158 116 { 159 117 efi_status_t status; ··· 146 188 147 189 static int efi_procfs(struct device *dev, struct seq_file *seq) 148 190 { 149 - efi_time_t eft, alm; 191 + efi_time_t eft; 150 192 efi_time_cap_t cap; 151 - efi_bool_t enabled, pending; 152 - struct rtc_device *rtc = dev_get_drvdata(dev); 153 193 154 194 memset(&eft, 0, sizeof(eft)); 155 - memset(&alm, 0, sizeof(alm)); 156 195 memset(&cap, 0, sizeof(cap)); 157 196 158 197 efi.get_time(&eft, &cap); 159 - efi.get_wakeup_time(&enabled, &pending, &alm); 160 198 161 199 seq_printf(seq, 162 200 "Time\t\t: %u:%u:%u.%09u\n" ··· 167 213 else 168 214 /* XXX fixme: convert to string? */ 169 215 seq_printf(seq, "Timezone\t: %u\n", eft.timezone); 170 - 171 - if (test_bit(RTC_FEATURE_ALARM, rtc->features)) { 172 - seq_printf(seq, 173 - "Alarm Time\t: %u:%u:%u.%09u\n" 174 - "Alarm Date\t: %u-%u-%u\n" 175 - "Alarm Daylight\t: %u\n" 176 - "Enabled\t\t: %s\n" 177 - "Pending\t\t: %s\n", 178 - alm.hour, alm.minute, alm.second, alm.nanosecond, 179 - alm.year, alm.month, alm.day, 180 - alm.daylight, 181 - enabled == 1 ? "yes" : "no", 182 - pending == 1 ? "yes" : "no"); 183 - 184 - if (alm.timezone == EFI_UNSPECIFIED_TIMEZONE) 185 - seq_puts(seq, "Timezone\t: unspecified\n"); 186 - else 187 - /* XXX fixme: convert to string? */ 188 - seq_printf(seq, "Timezone\t: %u\n", alm.timezone); 189 - } 190 216 191 217 /* 192 218 * now prints the capabilities ··· 183 249 static const struct rtc_class_ops efi_rtc_ops = { 184 250 .read_time = efi_read_time, 185 251 .set_time = efi_set_time, 186 - .read_alarm = efi_read_alarm, 187 - .set_alarm = efi_set_alarm, 188 252 .proc = efi_procfs, 189 253 }; 190 254 ··· 203 271 platform_set_drvdata(dev, rtc); 204 272 205 273 rtc->ops = &efi_rtc_ops; 206 - clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); 207 - if (efi_rt_services_supported(EFI_RT_SUPPORTED_WAKEUP_SERVICES)) 208 - set_bit(RTC_FEATURE_ALARM_WAKEUP_ONLY, rtc->features); 209 - else 210 - clear_bit(RTC_FEATURE_ALARM, rtc->features); 274 + clear_bit(RTC_FEATURE_ALARM, rtc->features); 211 275 212 276 device_init_wakeup(&dev->dev, true); 213 277
+1
drivers/rtc/rtc-isl12022.c
··· 413 413 if (ret) 414 414 return ret; 415 415 416 + isl12022->irq_enabled = true; 416 417 ret = devm_request_threaded_irq(dev, irq, NULL, 417 418 isl12022_rtc_interrupt, 418 419 IRQF_SHARED | IRQF_ONESHOT,
-1
drivers/rtc/rtc-meson.c
··· 72 72 .val_bits = 32, 73 73 .reg_stride = 4, 74 74 .max_register = RTC_REG4, 75 - .fast_io = true, 76 75 }; 77 76 78 77 /* RTC front-end serialiser controls */
+427 -38
drivers/rtc/rtc-optee.c
··· 5 5 6 6 #include <linux/device.h> 7 7 #include <linux/kernel.h> 8 + #include <linux/kthread.h> 8 9 #include <linux/module.h> 9 10 #include <linux/rtc.h> 10 11 #include <linux/tee_drv.h> 11 12 12 - #define RTC_INFO_VERSION 0x1 13 + #define RTC_INFO_VERSION 0x1 13 14 14 - #define TA_CMD_RTC_GET_INFO 0x0 15 - #define TA_CMD_RTC_GET_TIME 0x1 16 - #define TA_CMD_RTC_SET_TIME 0x2 17 - #define TA_CMD_RTC_GET_OFFSET 0x3 18 - #define TA_CMD_RTC_SET_OFFSET 0x4 15 + #define TA_RTC_FEATURE_CORRECTION BIT(0) 16 + #define TA_RTC_FEATURE_ALARM BIT(1) 17 + #define TA_RTC_FEATURE_WAKEUP_ALARM BIT(2) 19 18 20 - #define TA_RTC_FEATURE_CORRECTION BIT(0) 19 + enum rtc_optee_pta_cmd { 20 + /* PTA_CMD_RTC_GET_INFO - Get RTC information 21 + * 22 + * [out] memref[0] RTC buffer memory reference containing a struct pta_rtc_info 23 + */ 24 + PTA_CMD_RTC_GET_INF = 0x0, 25 + 26 + /* 27 + * PTA_CMD_RTC_GET_TIME - Get time from RTC 28 + * 29 + * [out] memref[0] RTC buffer memory reference containing a struct pta_rtc_time 30 + */ 31 + PTA_CMD_RTC_GET_TIME = 0x1, 32 + 33 + /* 34 + * PTA_CMD_RTC_SET_TIME - Set time from RTC 35 + * 36 + * [in] memref[0] RTC buffer memory reference containing a struct pta_rtc_time to be 37 + * used as RTC time 38 + */ 39 + PTA_CMD_RTC_SET_TIME = 0x2, 40 + 41 + /* 42 + * PTA_CMD_RTC_GET_OFFSET - Get RTC offset 43 + * 44 + * [out] value[0].a RTC offset (signed 32bit value) 45 + */ 46 + PTA_CMD_RTC_GET_OFFSET = 0x3, 47 + 48 + /* 49 + * PTA_CMD_RTC_SET_OFFSET - Set RTC offset 50 + * 51 + * [in] value[0].a RTC offset to be set (signed 32bit value) 52 + */ 53 + PTA_CMD_RTC_SET_OFFSET = 0x4, 54 + 55 + /* 56 + * PTA_CMD_RTC_READ_ALARM - Read RTC alarm 57 + * 58 + * [out] memref[0] RTC buffer memory reference containing a struct pta_rtc_alarm 59 + */ 60 + PTA_CMD_RTC_READ_ALARM = 0x5, 61 + 62 + /* 63 + * PTA_CMD_RTC_SET_ALARM - Set RTC alarm 64 + * 65 + * [in] memref[0] RTC buffer memory reference containing a struct pta_rtc_alarm to be 66 + * used as RTC alarm 67 + */ 68 + PTA_CMD_RTC_SET_ALARM = 0x6, 69 + 70 + /* 71 + * PTA_CMD_RTC_ENABLE_ALARM - Enable Alarm 72 + * 73 + * [in] value[0].a RTC IRQ flag (uint32_t), 0 to disable the alarm, 1 to enable 74 + */ 75 + PTA_CMD_RTC_ENABLE_ALARM = 0x7, 76 + 77 + /* 78 + * PTA_CMD_RTC_WAIT_ALARM - Get alarm event 79 + * 80 + * [out] value[0].a RTC wait alarm return status (uint32_t): 81 + * - 0: No alarm event 82 + * - 1: Alarm event occurred 83 + * - 2: Alarm event canceled 84 + */ 85 + PTA_CMD_RTC_WAIT_ALARM = 0x8, 86 + 87 + /* 88 + * PTA_CMD_RTC_CANCEL_WAIT - Cancel wait for alarm event 89 + */ 90 + PTA_CMD_RTC_CANCEL_WAIT = 0x9, 91 + 92 + /* 93 + * PTA_CMD_RTC_SET_WAKE_ALARM_STATUS - Set RTC wake alarm status flag 94 + * 95 + * [in] value[0].a RTC IRQ wake alarm flag (uint32_t), 0 to disable the wake up 96 + * capability, 1 to enable. 97 + */ 98 + PTA_CMD_RTC_SET_WAKE_ALARM_STATUS = 0xA, 99 + }; 100 + 101 + enum rtc_wait_alarm_status { 102 + WAIT_ALARM_RESET = 0x0, 103 + WAIT_ALARM_ALARM_OCCURRED = 0x1, 104 + WAIT_ALARM_CANCELED = 0x2, 105 + }; 21 106 22 107 struct optee_rtc_time { 23 108 u32 tm_sec; ··· 112 27 u32 tm_mon; 113 28 u32 tm_year; 114 29 u32 tm_wday; 30 + }; 31 + 32 + struct optee_rtc_alarm { 33 + u8 enabled; 34 + u8 pending; 35 + struct optee_rtc_time time; 115 36 }; 116 37 117 38 struct optee_rtc_info { ··· 132 41 * @dev: OP-TEE based RTC device. 133 42 * @ctx: OP-TEE context handler. 134 43 * @session_id: RTC TA session identifier. 44 + * @session2_id: RTC wait alarm session identifier. 135 45 * @shm: Memory pool shared with RTC device. 136 46 * @features: Bitfield of RTC features 47 + * @alarm_task: RTC wait alamr task. 48 + * @rtc: RTC device. 137 49 */ 138 50 struct optee_rtc { 139 51 struct device *dev; 140 52 struct tee_context *ctx; 141 53 u32 session_id; 54 + u32 session2_id; 142 55 struct tee_shm *shm; 143 56 u64 features; 57 + struct task_struct *alarm_task; 58 + struct rtc_device *rtc; 144 59 }; 145 60 146 61 static int optee_rtc_readtime(struct device *dev, struct rtc_time *tm) ··· 157 60 struct tee_param param[4] = {0}; 158 61 int ret; 159 62 160 - inv_arg.func = TA_CMD_RTC_GET_TIME; 63 + inv_arg.func = PTA_CMD_RTC_GET_TIME; 161 64 inv_arg.session = priv->session_id; 162 65 inv_arg.num_params = 4; 163 66 ··· 194 97 struct optee_rtc *priv = dev_get_drvdata(dev); 195 98 struct tee_ioctl_invoke_arg inv_arg = {0}; 196 99 struct tee_param param[4] = {0}; 197 - struct optee_rtc_time optee_tm; 198 - void *rtc_data; 100 + struct optee_rtc_time *optee_tm; 199 101 int ret; 200 102 201 - optee_tm.tm_sec = tm->tm_sec; 202 - optee_tm.tm_min = tm->tm_min; 203 - optee_tm.tm_hour = tm->tm_hour; 204 - optee_tm.tm_mday = tm->tm_mday; 205 - optee_tm.tm_mon = tm->tm_mon; 206 - optee_tm.tm_year = tm->tm_year + 1900; 207 - optee_tm.tm_wday = tm->tm_wday; 208 - 209 - inv_arg.func = TA_CMD_RTC_SET_TIME; 103 + inv_arg.func = PTA_CMD_RTC_SET_TIME; 210 104 inv_arg.session = priv->session_id; 211 105 inv_arg.num_params = 4; 212 106 ··· 205 117 param[0].u.memref.shm = priv->shm; 206 118 param[0].u.memref.size = sizeof(struct optee_rtc_time); 207 119 208 - rtc_data = tee_shm_get_va(priv->shm, 0); 209 - if (IS_ERR(rtc_data)) 210 - return PTR_ERR(rtc_data); 120 + optee_tm = tee_shm_get_va(priv->shm, 0); 121 + if (IS_ERR(optee_tm)) 122 + return PTR_ERR(optee_tm); 211 123 212 - memcpy(rtc_data, &optee_tm, sizeof(struct optee_rtc_time)); 124 + optee_tm->tm_min = tm->tm_min; 125 + optee_tm->tm_sec = tm->tm_sec; 126 + optee_tm->tm_hour = tm->tm_hour; 127 + optee_tm->tm_mday = tm->tm_mday; 128 + optee_tm->tm_mon = tm->tm_mon; 129 + optee_tm->tm_year = tm->tm_year + 1900; 130 + optee_tm->tm_wday = tm->tm_wday; 213 131 214 132 ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 215 133 if (ret < 0 || inv_arg.ret != 0) ··· 234 140 if (!(priv->features & TA_RTC_FEATURE_CORRECTION)) 235 141 return -EOPNOTSUPP; 236 142 237 - inv_arg.func = TA_CMD_RTC_GET_OFFSET; 143 + inv_arg.func = PTA_CMD_RTC_GET_OFFSET; 238 144 inv_arg.session = priv->session_id; 239 145 inv_arg.num_params = 4; 240 146 ··· 259 165 if (!(priv->features & TA_RTC_FEATURE_CORRECTION)) 260 166 return -EOPNOTSUPP; 261 167 262 - inv_arg.func = TA_CMD_RTC_SET_OFFSET; 168 + inv_arg.func = PTA_CMD_RTC_SET_OFFSET; 263 169 inv_arg.session = priv->session_id; 264 170 inv_arg.num_params = 4; 265 171 ··· 273 179 return 0; 274 180 } 275 181 182 + static int optee_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 183 + { 184 + struct optee_rtc *priv = dev_get_drvdata(dev); 185 + struct tee_ioctl_invoke_arg inv_arg = {0}; 186 + struct optee_rtc_alarm *optee_alarm; 187 + struct tee_param param[1] = {0}; 188 + int ret; 189 + 190 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 191 + return -EOPNOTSUPP; 192 + 193 + inv_arg.func = PTA_CMD_RTC_READ_ALARM; 194 + inv_arg.session = priv->session_id; 195 + inv_arg.num_params = 1; 196 + 197 + /* Fill invoke cmd params */ 198 + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; 199 + param[0].u.memref.shm = priv->shm; 200 + param[0].u.memref.size = sizeof(struct optee_rtc_alarm); 201 + 202 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 203 + if (ret < 0 || inv_arg.ret != 0) 204 + return ret ? ret : -EPROTO; 205 + 206 + optee_alarm = tee_shm_get_va(priv->shm, 0); 207 + if (IS_ERR(optee_alarm)) 208 + return PTR_ERR(optee_alarm); 209 + 210 + if (param[0].u.memref.size != sizeof(*optee_alarm)) 211 + return -EPROTO; 212 + 213 + alarm->enabled = optee_alarm->enabled; 214 + alarm->pending = optee_alarm->pending; 215 + alarm->time.tm_sec = optee_alarm->time.tm_sec; 216 + alarm->time.tm_min = optee_alarm->time.tm_min; 217 + alarm->time.tm_hour = optee_alarm->time.tm_hour; 218 + alarm->time.tm_mday = optee_alarm->time.tm_mday; 219 + alarm->time.tm_mon = optee_alarm->time.tm_mon; 220 + alarm->time.tm_year = optee_alarm->time.tm_year - 1900; 221 + alarm->time.tm_wday = optee_alarm->time.tm_wday; 222 + alarm->time.tm_yday = rtc_year_days(alarm->time.tm_mday, 223 + alarm->time.tm_mon, 224 + alarm->time.tm_year); 225 + 226 + return 0; 227 + } 228 + 229 + static int optee_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 230 + { 231 + struct optee_rtc *priv = dev_get_drvdata(dev); 232 + struct tee_ioctl_invoke_arg inv_arg = {0}; 233 + struct optee_rtc_alarm *optee_alarm; 234 + struct tee_param param[1] = {0}; 235 + int ret; 236 + 237 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 238 + return -EOPNOTSUPP; 239 + 240 + inv_arg.func = PTA_CMD_RTC_SET_ALARM; 241 + inv_arg.session = priv->session_id; 242 + inv_arg.num_params = 1; 243 + 244 + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; 245 + param[0].u.memref.shm = priv->shm; 246 + param[0].u.memref.size = sizeof(struct optee_rtc_alarm); 247 + 248 + optee_alarm = tee_shm_get_va(priv->shm, 0); 249 + if (IS_ERR(optee_alarm)) 250 + return PTR_ERR(optee_alarm); 251 + 252 + optee_alarm->enabled = alarm->enabled; 253 + optee_alarm->pending = alarm->pending; 254 + optee_alarm->time.tm_sec = alarm->time.tm_sec; 255 + optee_alarm->time.tm_min = alarm->time.tm_min; 256 + optee_alarm->time.tm_hour = alarm->time.tm_hour; 257 + optee_alarm->time.tm_mday = alarm->time.tm_mday; 258 + optee_alarm->time.tm_mon = alarm->time.tm_mon; 259 + optee_alarm->time.tm_year = alarm->time.tm_year + 1900; 260 + optee_alarm->time.tm_wday = alarm->time.tm_wday; 261 + 262 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 263 + if (ret < 0 || inv_arg.ret != 0) 264 + return ret ? ret : -EPROTO; 265 + 266 + return 0; 267 + } 268 + 269 + static int optee_rtc_enable_alarm(struct device *dev, unsigned int enabled) 270 + { 271 + struct optee_rtc *priv = dev_get_drvdata(dev); 272 + struct tee_ioctl_invoke_arg inv_arg = {0}; 273 + struct tee_param param[1] = {0}; 274 + int ret; 275 + 276 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 277 + return -EOPNOTSUPP; 278 + 279 + inv_arg.func = PTA_CMD_RTC_ENABLE_ALARM; 280 + inv_arg.session = priv->session_id; 281 + inv_arg.num_params = 1; 282 + 283 + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT; 284 + param[0].u.value.a = (bool)enabled; 285 + 286 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 287 + if (ret < 0 || inv_arg.ret != 0) 288 + return ret ? ret : -EPROTO; 289 + 290 + return 0; 291 + } 292 + 276 293 static const struct rtc_class_ops optee_rtc_ops = { 277 - .read_time = optee_rtc_readtime, 278 - .set_time = optee_rtc_settime, 279 - .set_offset = optee_rtc_setoffset, 280 - .read_offset = optee_rtc_readoffset, 294 + .read_time = optee_rtc_readtime, 295 + .set_time = optee_rtc_settime, 296 + .set_offset = optee_rtc_setoffset, 297 + .read_offset = optee_rtc_readoffset, 298 + .read_alarm = optee_rtc_read_alarm, 299 + .set_alarm = optee_rtc_set_alarm, 300 + .alarm_irq_enable = optee_rtc_enable_alarm, 281 301 }; 302 + 303 + static int optee_rtc_wait_alarm(struct device *dev, int *return_status) 304 + { 305 + struct optee_rtc *priv = dev_get_drvdata(dev); 306 + struct tee_ioctl_invoke_arg inv_arg = {0}; 307 + struct tee_param param[1] = {0}; 308 + int ret; 309 + 310 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 311 + return -EOPNOTSUPP; 312 + 313 + inv_arg.func = PTA_CMD_RTC_WAIT_ALARM; 314 + inv_arg.session = priv->session2_id; 315 + inv_arg.num_params = 1; 316 + 317 + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT; 318 + 319 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 320 + if (ret < 0 || inv_arg.ret != 0) 321 + return ret ? ret : -EPROTO; 322 + 323 + *return_status = param[0].u.value.a; 324 + 325 + return 0; 326 + } 327 + 328 + static int optee_rtc_cancel_wait_alarm(struct device *dev) 329 + { 330 + struct optee_rtc *priv = dev_get_drvdata(dev); 331 + struct tee_ioctl_invoke_arg inv_arg = {0}; 332 + struct tee_param param[1] = {0}; 333 + int ret; 334 + 335 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 336 + return -EOPNOTSUPP; 337 + 338 + inv_arg.func = PTA_CMD_RTC_CANCEL_WAIT; 339 + inv_arg.session = priv->session_id; 340 + inv_arg.num_params = 0; 341 + 342 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 343 + if (ret < 0 || inv_arg.ret != 0) 344 + return ret ? ret : -EPROTO; 345 + 346 + return 0; 347 + } 348 + 349 + static int optee_rtc_set_alarm_wake_status(struct device *dev, bool status) 350 + { 351 + struct optee_rtc *priv = dev_get_drvdata(dev); 352 + struct tee_ioctl_invoke_arg inv_arg = {0}; 353 + struct tee_param param[1] = {0}; 354 + int ret; 355 + 356 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 357 + return -EOPNOTSUPP; 358 + 359 + inv_arg.func = PTA_CMD_RTC_SET_WAKE_ALARM_STATUS; 360 + inv_arg.session = priv->session_id; 361 + inv_arg.num_params = 1; 362 + 363 + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT; 364 + param[0].u.value.a = status; 365 + 366 + ret = tee_client_invoke_func(priv->ctx, &inv_arg, param); 367 + 368 + if (ret < 0 || inv_arg.ret != 0) 369 + return ret ? ret : -EPROTO; 370 + 371 + return 0; 372 + } 373 + 374 + static int optee_rtc_handle_alarm_event(void *data) 375 + { 376 + struct optee_rtc *priv = (struct optee_rtc *)data; 377 + int wait_alarm_return_status = 0; 378 + int ret; 379 + 380 + while (!kthread_should_stop()) { 381 + ret = optee_rtc_wait_alarm(priv->dev, &wait_alarm_return_status); 382 + if (ret) { 383 + dev_err(priv->dev, "Failed to wait for alarm: %d\n", ret); 384 + return ret; 385 + } 386 + switch (wait_alarm_return_status) { 387 + case WAIT_ALARM_ALARM_OCCURRED: 388 + dev_dbg(priv->dev, "Alarm occurred\n"); 389 + rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_AF); 390 + break; 391 + case WAIT_ALARM_CANCELED: 392 + dev_dbg(priv->dev, "Alarm canceled\n"); 393 + break; 394 + default: 395 + dev_warn(priv->dev, "Unknown return status: %d\n", 396 + wait_alarm_return_status); 397 + break; 398 + } 399 + } 400 + 401 + return 0; 402 + } 282 403 283 404 static int optee_rtc_read_info(struct device *dev, struct rtc_device *rtc, 284 405 u64 *features) ··· 505 196 struct optee_rtc_time *tm; 506 197 int ret; 507 198 508 - inv_arg.func = TA_CMD_RTC_GET_INFO; 199 + inv_arg.func = PTA_CMD_RTC_GET_INF; 509 200 inv_arg.session = priv->session_id; 510 201 inv_arg.num_params = 4; 511 202 ··· 550 241 static int optee_rtc_probe(struct device *dev) 551 242 { 552 243 struct tee_client_device *rtc_device = to_tee_client_device(dev); 553 - struct tee_ioctl_open_session_arg sess_arg; 244 + struct tee_ioctl_open_session_arg sess2_arg = {0}; 245 + struct tee_ioctl_open_session_arg sess_arg = {0}; 554 246 struct optee_rtc *priv; 555 247 struct rtc_device *rtc; 556 248 struct tee_shm *shm; 557 249 int ret, err; 558 - 559 - memset(&sess_arg, 0, sizeof(sess_arg)); 560 250 561 251 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 562 252 if (!priv) ··· 565 257 if (IS_ERR(rtc)) 566 258 return PTR_ERR(rtc); 567 259 260 + priv->rtc = rtc; 261 + 568 262 /* Open context with TEE driver */ 569 263 priv->ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, NULL); 570 264 if (IS_ERR(priv->ctx)) 571 265 return -ENODEV; 572 266 573 - /* Open session with rtc Trusted App */ 267 + /* Open first session with rtc Pseudo Trusted App */ 574 268 export_uuid(sess_arg.uuid, &rtc_device->id.uuid); 575 269 sess_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL; 576 270 ··· 584 274 } 585 275 priv->session_id = sess_arg.session; 586 276 277 + /* 278 + * Shared memory is used for passing an instance of either struct optee_rtc_info, 279 + * struct optee_rtc_time or struct optee_rtc_alarm to OP-TEE service. 280 + * The former is by definition large enough to cover both parameter cases. 281 + */ 587 282 shm = tee_shm_alloc_kernel_buf(priv->ctx, sizeof(struct optee_rtc_info)); 588 283 if (IS_ERR(shm)) { 589 284 dev_err(priv->dev, "tee_shm_alloc_kernel_buf failed\n"); ··· 608 293 goto out_shm; 609 294 } 610 295 296 + /* Handle feature's related setup before registering to rtc framework */ 297 + if (priv->features & TA_RTC_FEATURE_ALARM) { 298 + priv->alarm_task = kthread_create(optee_rtc_handle_alarm_event, 299 + priv, "rtc_alarm_evt"); 300 + if (IS_ERR(priv->alarm_task)) { 301 + dev_err(dev, "Failed to create alarm thread\n"); 302 + err = PTR_ERR(priv->alarm_task); 303 + goto out_shm; 304 + } 305 + 306 + /* 307 + * In case of supported alarm feature on optee side, we create a kthread 308 + * that will, in a new optee session, call a PTA interface "rtc_wait_alarm". 309 + * This call return in case of alarm and in case of canceled alarm. 310 + * The new optee session is therefore only needed in this case as we cannot 311 + * use the same session for parallel calls to optee PTA. 312 + * Hence one session is reserved to wait for alarms and the other to make 313 + * standard calls to RTC PTA. 314 + */ 315 + 316 + /* Open second session with rtc Trusted App */ 317 + export_uuid(sess2_arg.uuid, &rtc_device->id.uuid); 318 + sess2_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL; 319 + 320 + ret = tee_client_open_session(priv->ctx, &sess2_arg, NULL); 321 + if (ret < 0 || sess2_arg.ret != 0) { 322 + dev_err(dev, "tee_client_open_session failed, err: %x\n", sess2_arg.ret); 323 + err = -EINVAL; 324 + goto out_thrd; 325 + } 326 + priv->session2_id = sess2_arg.session; 327 + 328 + if (priv->features & TA_RTC_FEATURE_WAKEUP_ALARM) 329 + device_init_wakeup(dev, true); 330 + } 331 + 611 332 err = devm_rtc_register_device(rtc); 612 333 if (err) 613 - goto out_shm; 334 + goto out_wk; 614 335 615 336 /* 616 - * We must clear this bit after registering because rtc_register_device 617 - * will set it if it sees that .set_offset is provided. 337 + * We must clear those bits after registering because registering a rtc_device 338 + * will set them if it sees that .set_offset and .set_alarm are provided. 618 339 */ 619 340 if (!(priv->features & TA_RTC_FEATURE_CORRECTION)) 620 341 clear_bit(RTC_FEATURE_CORRECTION, rtc->features); 342 + if (!(priv->features & TA_RTC_FEATURE_ALARM)) 343 + clear_bit(RTC_FEATURE_ALARM, rtc->features); 344 + 345 + /* Start the thread after the rtc is setup */ 346 + if (priv->alarm_task) { 347 + wake_up_process(priv->alarm_task); 348 + dev_dbg(dev, "Wait alarm thread successfully started\n"); 349 + } 621 350 622 351 return 0; 623 - 352 + out_wk: 353 + if (priv->features & TA_RTC_FEATURE_ALARM) { 354 + device_init_wakeup(dev, false); 355 + tee_client_close_session(priv->ctx, priv->session2_id); 356 + } 357 + out_thrd: 358 + if (priv->features & TA_RTC_FEATURE_ALARM) 359 + kthread_stop(priv->alarm_task); 624 360 out_shm: 625 361 tee_shm_free(priv->shm); 626 362 out_sess: ··· 686 320 { 687 321 struct optee_rtc *priv = dev_get_drvdata(dev); 688 322 323 + if (priv->features & TA_RTC_FEATURE_ALARM) { 324 + optee_rtc_cancel_wait_alarm(dev); 325 + kthread_stop(priv->alarm_task); 326 + device_init_wakeup(dev, false); 327 + tee_client_close_session(priv->ctx, priv->session2_id); 328 + } 329 + 330 + tee_shm_free(priv->shm); 689 331 tee_client_close_session(priv->ctx, priv->session_id); 690 332 tee_client_close_context(priv->ctx); 691 333 692 334 return 0; 693 335 } 336 + 337 + static int optee_rtc_suspend(struct device *dev) 338 + { 339 + int res = optee_rtc_set_alarm_wake_status(dev, device_may_wakeup(dev)); 340 + 341 + if (res) { 342 + dev_err(dev, "Unable to transmit wakeup information to optee rtc\n"); 343 + return res; 344 + } 345 + 346 + return 0; 347 + } 348 + 349 + static DEFINE_SIMPLE_DEV_PM_OPS(optee_rtc_pm_ops, optee_rtc_suspend, NULL); 694 350 695 351 static const struct tee_client_device_id optee_rtc_id_table[] = { 696 352 {UUID_INIT(0xf389f8c8, 0x845f, 0x496c, ··· 729 341 .bus = &tee_bus_type, 730 342 .probe = optee_rtc_probe, 731 343 .remove = optee_rtc_remove, 344 + .pm = pm_sleep_ptr(&optee_rtc_pm_ops), 732 345 }, 733 346 }; 734 347
+18 -1
drivers/rtc/rtc-pcf2127.c
··· 42 42 #define PCF2127_BIT_CTRL2_AF BIT(4) 43 43 #define PCF2127_BIT_CTRL2_TSF2 BIT(5) 44 44 #define PCF2127_BIT_CTRL2_WDTF BIT(6) 45 + #define PCF2127_BIT_CTRL2_MSF BIT(7) 45 46 /* Control register 3 */ 46 47 #define PCF2127_REG_CTRL3 0x02 47 48 #define PCF2127_BIT_CTRL3_BLIE BIT(0) ··· 97 96 #define PCF2127_CTRL2_IRQ_MASK ( \ 98 97 PCF2127_BIT_CTRL2_AF | \ 99 98 PCF2127_BIT_CTRL2_WDTF | \ 100 - PCF2127_BIT_CTRL2_TSF2) 99 + PCF2127_BIT_CTRL2_TSF2 | \ 100 + PCF2127_BIT_CTRL2_MSF) 101 101 102 102 #define PCF2127_MAX_TS_SUPPORTED 4 103 103 ··· 606 604 607 605 if (wdd_timeout) 608 606 set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); 607 + } 608 + 609 + /* 610 + * When using interrupt pin (INT A) as watchdog output, only allow 611 + * watchdog interrupt (PCF2131_BIT_INT_WD_CD) and disable (mask) all 612 + * other interrupts. 613 + */ 614 + if (pcf2127->cfg->type == PCF2131) { 615 + ret = regmap_write(pcf2127->regmap, 616 + PCF2131_REG_INT_A_MASK1, 617 + PCF2131_BIT_INT_BLIE | 618 + PCF2131_BIT_INT_BIE | 619 + PCF2131_BIT_INT_AIE | 620 + PCF2131_BIT_INT_SI | 621 + PCF2131_BIT_INT_MI); 609 622 } 610 623 611 624 return devm_watchdog_register_device(dev, &pcf2127->wdd);
+2 -47
drivers/rtc/rtc-s3c.c
··· 331 331 .alarm_irq_enable = s3c_rtc_setaie, 332 332 }; 333 333 334 - static void s3c24xx_rtc_enable(struct s3c_rtc *info) 334 + static void s3c6410_rtc_enable(struct s3c_rtc *info) 335 335 { 336 336 unsigned int con, tmp; 337 337 ··· 359 359 writew(tmp & ~S3C2410_RTCCON_CLKRST, 360 360 info->base + S3C2410_RTCCON); 361 361 } 362 - } 363 - 364 - static void s3c24xx_rtc_disable(struct s3c_rtc *info) 365 - { 366 - unsigned int con; 367 - 368 - con = readw(info->base + S3C2410_RTCCON); 369 - con &= ~S3C2410_RTCCON_RTCEN; 370 - writew(con, info->base + S3C2410_RTCCON); 371 - 372 - con = readb(info->base + S3C2410_TICNT); 373 - con &= ~S3C2410_TICNT_ENABLE; 374 - writeb(con, info->base + S3C2410_TICNT); 375 362 } 376 363 377 364 static void s3c6410_rtc_disable(struct s3c_rtc *info) ··· 525 538 #endif 526 539 static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume); 527 540 528 - static void s3c24xx_rtc_irq(struct s3c_rtc *info, int mask) 529 - { 530 - rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 531 - } 532 - 533 541 static void s3c6410_rtc_irq(struct s3c_rtc *info, int mask) 534 542 { 535 543 rtc_update_irq(info->rtc, 1, RTC_AF | RTC_IRQF); 536 544 writeb(mask, info->base + S3C2410_INTP); 537 545 } 538 546 539 - static const struct s3c_rtc_data s3c2410_rtc_data = { 540 - .irq_handler = s3c24xx_rtc_irq, 541 - .enable = s3c24xx_rtc_enable, 542 - .disable = s3c24xx_rtc_disable, 543 - }; 544 - 545 - static const struct s3c_rtc_data s3c2416_rtc_data = { 546 - .irq_handler = s3c24xx_rtc_irq, 547 - .enable = s3c24xx_rtc_enable, 548 - .disable = s3c24xx_rtc_disable, 549 - }; 550 - 551 - static const struct s3c_rtc_data s3c2443_rtc_data = { 552 - .irq_handler = s3c24xx_rtc_irq, 553 - .enable = s3c24xx_rtc_enable, 554 - .disable = s3c24xx_rtc_disable, 555 - }; 556 - 557 547 static const struct s3c_rtc_data s3c6410_rtc_data = { 558 548 .needs_src_clk = true, 559 549 .irq_handler = s3c6410_rtc_irq, 560 - .enable = s3c24xx_rtc_enable, 550 + .enable = s3c6410_rtc_enable, 561 551 .disable = s3c6410_rtc_disable, 562 552 }; 563 553 564 554 static const __maybe_unused struct of_device_id s3c_rtc_dt_match[] = { 565 555 { 566 - .compatible = "samsung,s3c2410-rtc", 567 - .data = &s3c2410_rtc_data, 568 - }, { 569 - .compatible = "samsung,s3c2416-rtc", 570 - .data = &s3c2416_rtc_data, 571 - }, { 572 - .compatible = "samsung,s3c2443-rtc", 573 - .data = &s3c2443_rtc_data, 574 - }, { 575 556 .compatible = "samsung,s3c6410-rtc", 576 557 .data = &s3c6410_rtc_data, 577 558 }, {
-19
drivers/rtc/rtc-s3c.h
··· 21 21 #define S3C2443_RTCCON_TICSEL (1 << 4) 22 22 #define S3C64XX_RTCCON_TICEN (1 << 8) 23 23 24 - #define S3C2410_TICNT S3C2410_RTCREG(0x44) 25 - #define S3C2410_TICNT_ENABLE (1 << 7) 26 - 27 - /* S3C2443: tick count is 15 bit wide 28 - * TICNT[6:0] contains upper 7 bits 29 - * TICNT1[7:0] contains lower 8 bits 30 - */ 31 - #define S3C2443_TICNT_PART(x) ((x & 0x7f00) >> 8) 32 - #define S3C2443_TICNT1 S3C2410_RTCREG(0x4C) 33 - #define S3C2443_TICNT1_PART(x) (x & 0xff) 34 - 35 - /* S3C2416: tick count is 32 bit wide 36 - * TICNT[6:0] contains bits [14:8] 37 - * TICNT1[7:0] contains lower 8 bits 38 - * TICNT2[16:0] contains upper 17 bits 39 - */ 40 - #define S3C2416_TICNT2 S3C2410_RTCREG(0x48) 41 - #define S3C2416_TICNT2_PART(x) ((x & 0xffff8000) >> 15) 42 - 43 24 #define S3C2410_RTCALM S3C2410_RTCREG(0x50) 44 25 #define S3C2410_RTCALM_ALMEN (1 << 6) 45 26 #define S3C2410_RTCALM_YEAREN (1 << 5)
+3 -1
drivers/rtc/rtc-sd2405al.c
··· 5 5 * Datasheet: 6 6 * https://image.dfrobot.com/image/data/TOY0021/SD2405AL%20datasheet%20(Angelo%20v0.1).pdf 7 7 * 8 - * Copyright (C) 2024 Tóth János <gomba007@gmail.com> 8 + * I2C slave address: 0x32 9 + * 10 + * Copyright (C) 2024-2025 Tóth János <gomba007@gmail.com> 9 11 */ 10 12 11 13 #include <linux/bcd.h>
+167
drivers/rtc/rtc-spacemit-p1.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Driver for the RTC found in the SpacemiT P1 PMIC 4 + * 5 + * Copyright (C) 2025 by RISCstar Solutions Corporation. All rights reserved. 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/device.h> 10 + #include <linux/module.h> 11 + #include <linux/platform_device.h> 12 + #include <linux/regmap.h> 13 + #include <linux/rtc.h> 14 + 15 + #define MOD_NAME "spacemit-p1-rtc" 16 + 17 + /* 18 + * Six consecutive 1-byte registers hold the seconds, minutes, hours, 19 + * day-of-month, month, and year (respectively). 20 + * 21 + * The range of values in these registers is: 22 + * seconds 0-59 23 + * minutes 0-59 24 + * hours 0-59 25 + * day 0-30 (struct tm is 1-31) 26 + * month 0-11 27 + * year years since 2000 (struct tm is since 1900) 28 + * 29 + * Note that the day and month must be converted after reading and 30 + * before writing. 31 + */ 32 + #define RTC_TIME 0x0d /* Offset of the seconds register */ 33 + 34 + #define RTC_CTRL 0x1d 35 + #define RTC_EN BIT(2) 36 + 37 + /* Number of attempts to read a consistent time stamp before giving up */ 38 + #define RTC_READ_TRIES 20 /* At least 1 */ 39 + 40 + struct p1_rtc { 41 + struct regmap *regmap; 42 + struct rtc_device *rtc; 43 + }; 44 + 45 + /* 46 + * The P1 hardware documentation states that the register values are 47 + * latched to ensure a consistent time snapshot within the registers, 48 + * but these are in fact unstable due to a bug in the hardware design. 49 + * So we loop until we get two identical readings. 50 + */ 51 + static int p1_rtc_read_time(struct device *dev, struct rtc_time *t) 52 + { 53 + struct p1_rtc *p1 = dev_get_drvdata(dev); 54 + struct regmap *regmap = p1->regmap; 55 + u32 count = RTC_READ_TRIES; 56 + u8 seconds; 57 + u8 time[6]; 58 + int ret; 59 + 60 + if (!regmap_test_bits(regmap, RTC_CTRL, RTC_EN)) 61 + return -EINVAL; /* RTC is disabled */ 62 + 63 + ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time)); 64 + if (ret) 65 + return ret; 66 + 67 + do { 68 + seconds = time[0]; 69 + ret = regmap_bulk_read(regmap, RTC_TIME, time, sizeof(time)); 70 + if (ret) 71 + return ret; 72 + } while (time[0] != seconds && --count); 73 + 74 + if (!count) 75 + return -EIO; /* Unable to get a consistent result */ 76 + 77 + t->tm_sec = time[0] & GENMASK(5, 0); 78 + t->tm_min = time[1] & GENMASK(5, 0); 79 + t->tm_hour = time[2] & GENMASK(4, 0); 80 + t->tm_mday = (time[3] & GENMASK(4, 0)) + 1; 81 + t->tm_mon = time[4] & GENMASK(3, 0); 82 + t->tm_year = (time[5] & GENMASK(5, 0)) + 100; 83 + 84 + return 0; 85 + } 86 + 87 + /* 88 + * The P1 hardware documentation states that values in the registers are 89 + * latched so when written they represent a consistent time snapshot. 90 + * Nevertheless, this is not guaranteed by the implementation, so we must 91 + * disable the RTC while updating it. 92 + */ 93 + static int p1_rtc_set_time(struct device *dev, struct rtc_time *t) 94 + { 95 + struct p1_rtc *p1 = dev_get_drvdata(dev); 96 + struct regmap *regmap = p1->regmap; 97 + u8 time[6]; 98 + int ret; 99 + 100 + time[0] = t->tm_sec; 101 + time[1] = t->tm_min; 102 + time[2] = t->tm_hour; 103 + time[3] = t->tm_mday - 1; 104 + time[4] = t->tm_mon; 105 + time[5] = t->tm_year - 100; 106 + 107 + /* Disable the RTC to update; re-enable again when done */ 108 + ret = regmap_clear_bits(regmap, RTC_CTRL, RTC_EN); 109 + if (ret) 110 + return ret; 111 + 112 + /* If something goes wrong, leave the RTC disabled */ 113 + ret = regmap_bulk_write(regmap, RTC_TIME, time, sizeof(time)); 114 + if (ret) 115 + return ret; 116 + 117 + return regmap_set_bits(regmap, RTC_CTRL, RTC_EN); 118 + } 119 + 120 + static const struct rtc_class_ops p1_rtc_class_ops = { 121 + .read_time = p1_rtc_read_time, 122 + .set_time = p1_rtc_set_time, 123 + }; 124 + 125 + static int p1_rtc_probe(struct platform_device *pdev) 126 + { 127 + struct device *dev = &pdev->dev; 128 + struct rtc_device *rtc; 129 + struct p1_rtc *p1; 130 + 131 + p1 = devm_kzalloc(dev, sizeof(*p1), GFP_KERNEL); 132 + if (!p1) 133 + return -ENOMEM; 134 + dev_set_drvdata(dev, p1); 135 + 136 + p1->regmap = dev_get_regmap(dev->parent, NULL); 137 + if (!p1->regmap) 138 + return dev_err_probe(dev, -ENODEV, "failed to get regmap\n"); 139 + 140 + rtc = devm_rtc_allocate_device(dev); 141 + if (IS_ERR(rtc)) 142 + return dev_err_probe(dev, PTR_ERR(rtc), 143 + "error allocating device\n"); 144 + p1->rtc = rtc; 145 + 146 + rtc->ops = &p1_rtc_class_ops; 147 + rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 148 + rtc->range_max = RTC_TIMESTAMP_END_2063; 149 + 150 + clear_bit(RTC_FEATURE_ALARM, rtc->features); 151 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features); 152 + 153 + return devm_rtc_register_device(rtc); 154 + } 155 + 156 + static struct platform_driver p1_rtc_driver = { 157 + .probe = p1_rtc_probe, 158 + .driver = { 159 + .name = MOD_NAME, 160 + }, 161 + }; 162 + 163 + module_platform_driver(p1_rtc_driver); 164 + 165 + MODULE_DESCRIPTION("SpacemiT P1 RTC driver"); 166 + MODULE_LICENSE("GPL"); 167 + MODULE_ALIAS("platform:" MOD_NAME);
+1
drivers/rtc/rtc-tps6586x.c
··· 258 258 259 259 irq_set_status_flags(rtc->irq, IRQ_NOAUTOEN); 260 260 261 + rtc->irq_en = true; 261 262 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 262 263 tps6586x_rtc_irq, 263 264 IRQF_ONESHOT,
+1 -1
drivers/rtc/rtc-x1205.c
··· 669 669 MODULE_DEVICE_TABLE(i2c, x1205_id); 670 670 671 671 static const struct of_device_id x1205_dt_ids[] = { 672 - { .compatible = "xircom,x1205", }, 672 + { .compatible = "xicor,x1205", }, 673 673 {}, 674 674 }; 675 675 MODULE_DEVICE_TABLE(of, x1205_dt_ids);
+19
drivers/rtc/rtc-zynqmp.c
··· 277 277 static int xlnx_rtc_probe(struct platform_device *pdev) 278 278 { 279 279 struct xlnx_rtc_dev *xrtcdev; 280 + bool is_alarm_set = false; 281 + u32 pending_alrm_irq; 282 + u32 current_time; 283 + u32 alarm_time; 280 284 int ret; 281 285 282 286 xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); ··· 299 295 xrtcdev->reg_base = devm_platform_ioremap_resource(pdev, 0); 300 296 if (IS_ERR(xrtcdev->reg_base)) 301 297 return PTR_ERR(xrtcdev->reg_base); 298 + 299 + /* Clear any pending alarm interrupts from previous kernel/boot */ 300 + pending_alrm_irq = readl(xrtcdev->reg_base + RTC_INT_STS) & RTC_INT_ALRM; 301 + if (pending_alrm_irq) 302 + writel(pending_alrm_irq, xrtcdev->reg_base + RTC_INT_STS); 303 + 304 + /* Check if a valid alarm is already set from previous kernel/boot */ 305 + alarm_time = readl(xrtcdev->reg_base + RTC_ALRM); 306 + current_time = readl(xrtcdev->reg_base + RTC_CUR_TM); 307 + if (alarm_time > current_time && alarm_time != 0) 308 + is_alarm_set = true; 302 309 303 310 xrtcdev->alarm_irq = platform_get_irq_byname(pdev, "alarm"); 304 311 if (xrtcdev->alarm_irq < 0) ··· 351 336 writel(xrtcdev->freq, (xrtcdev->reg_base + RTC_CALIB_WR)); 352 337 353 338 xlnx_init_rtc(xrtcdev); 339 + 340 + /* Re-enable alarm interrupt if a valid alarm was found */ 341 + if (is_alarm_set) 342 + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_EN); 354 343 355 344 device_init_wakeup(&pdev->dev, true); 356 345