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

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

Pull RTC updates from Alexandre Belloni:
"More cleanup this cycle, with the final goal of removing the
rtc_time_to_tm and rtc_tm_to_time wrappers. All the drivers that have
been modified for this now are ready for the end of times (whether it
happens in 2033, 2038, 2106, 2127 or even 4052). There is also a
single new driver and the usual fixes and features.

Summary:

Subsystem:

- The rtc_time_to_tm and rtc_tm_to_time wrappers have finally been
removed and only the 64bit version remain.

- hctosys now works with drivers compiled as modules

New driver:

- MediaTek MT2712 SoC based RTC

Drivers:

- set range for 88pm860x, au1xxx, cpcap, da9052, davinci, ds1305,
ds1374, mcp5121, pl030, pl031, pm8xxx, puv3, sa1100, sirfsoc,
starfire, sun6i

- ds1307: DS1388 oscillator failure detection and watchdog support

- jz4740: JZ4760 support

- pcf85063: clock out pin support

- sun6i: external 32k oscillator is now optional, the range is now
handled by the core, providing a solution for 2034"

* tag 'rtc-5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (87 commits)
rtc: ds1307: check for failed memory allocation on wdt
rtc: class: remove redundant assignment to variable err
rtc: remove rtc_time_to_tm and rtc_tm_to_time
rtc: sun6i: let the core handle rtc range
rtc: sun6i: switch to rtc_time64_to_tm/rtc_tm_to_time64
rtc: ds1307: add support for watchdog timer on ds1388
rtc: da9052: switch to rtc_time64_to_tm/rtc_tm_to_time64
rtc: da9052: set range
rtc: da9052: convert to devm_rtc_allocate_device
rtc: imx-sc: Align imx sc msg structs to 4
rtc: fsl-ftm-alarm: report alarm to core
rtc: pcf85063: Add pcf85063 clkout control to common clock framework
rtc: make definitions in include/uapi/linux/rtc.h actually useful for user space
rtc: class: avoid unnecessary lookup in hctosys
dt-bindings: rtc: Convert and update jz4740-rtc doc to YAML
rtc: jz4740: Rename vendor-specific DT properties
rtc: jz4740: Add support for JZ4760 SoC
rtc: class: support hctosys from modular RTC drivers
rtc: pm8xxx: clear alarm register when alarm is not enabled
rtc: omap: drop unused dt-bindings header
...

+1192 -574
-37
Documentation/devicetree/bindings/rtc/ingenic,jz4740-rtc.txt
··· 1 - JZ4740 and similar SoCs real-time clock driver 2 - 3 - Required properties: 4 - 5 - - compatible: One of: 6 - - "ingenic,jz4740-rtc" - for use with the JZ4740 SoC 7 - - "ingenic,jz4780-rtc" - for use with the JZ4780 SoC 8 - - reg: Address range of rtc register set 9 - - interrupts: IRQ number for the alarm interrupt 10 - - clocks: phandle to the "rtc" clock 11 - - clock-names: must be "rtc" 12 - 13 - Optional properties: 14 - - system-power-controller: To use this component as the 15 - system power controller 16 - - reset-pin-assert-time-ms: Reset pin low-level assertion 17 - time after wakeup (default 60ms; range 0-125ms if RTC clock 18 - at 32 kHz) 19 - - min-wakeup-pin-assert-time-ms: Minimum wakeup pin assertion 20 - time (default 100ms; range 0-2s if RTC clock at 32 kHz) 21 - 22 - Example: 23 - 24 - rtc@10003000 { 25 - compatible = "ingenic,jz4740-rtc"; 26 - reg = <0x10003000 0x40>; 27 - 28 - interrupt-parent = <&intc>; 29 - interrupts = <32>; 30 - 31 - clocks = <&rtc_clock>; 32 - clock-names = "rtc"; 33 - 34 - system-power-controller; 35 - reset-pin-assert-time-ms = <60>; 36 - min-wakeup-pin-assert-time-ms = <100>; 37 - };
+83
Documentation/devicetree/bindings/rtc/ingenic,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/ingenic,rtc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Ingenic SoCs Real-Time Clock DT bindings 8 + 9 + maintainers: 10 + - Paul Cercueil <paul@crapouillou.net> 11 + 12 + allOf: 13 + - $ref: rtc.yaml# 14 + 15 + properties: 16 + compatible: 17 + oneOf: 18 + - enum: 19 + - ingenic,jz4740-rtc 20 + - ingenic,jz4760-rtc 21 + - items: 22 + - const: ingenic,jz4725b-rtc 23 + - const: ingenic,jz4740-rtc 24 + - items: 25 + - enum: 26 + - ingenic,jz4770-rtc 27 + - ingenic,jz4780-rtc 28 + - const: ingenic,jz4760-rtc 29 + 30 + reg: 31 + maxItems: 1 32 + 33 + interrupts: 34 + maxItems: 1 35 + 36 + clocks: 37 + maxItems: 1 38 + 39 + clock-names: 40 + const: rtc 41 + 42 + system-power-controller: 43 + description: | 44 + Indicates that the RTC is responsible for powering OFF 45 + the system. 46 + type: boolean 47 + 48 + ingenic,reset-pin-assert-time-ms: 49 + minimum: 0 50 + maximum: 125 51 + default: 60 52 + description: | 53 + Reset pin low-level assertion time after wakeup 54 + (assuming RTC clock at 32 kHz) 55 + 56 + ingenic,min-wakeup-pin-assert-time-ms: 57 + minimum: 0 58 + maximum: 2000 59 + default: 100 60 + description: | 61 + Minimum wakeup pin assertion time 62 + (assuming RTC clock at 32 kHz) 63 + 64 + required: 65 + - compatible 66 + - reg 67 + - interrupts 68 + - clocks 69 + - clock-names 70 + 71 + examples: 72 + - | 73 + #include <dt-bindings/clock/jz4740-cgu.h> 74 + rtc_dev: rtc@10003000 { 75 + compatible = "ingenic,jz4740-rtc"; 76 + reg = <0x10003000 0x40>; 77 + 78 + interrupt-parent = <&intc>; 79 + interrupts = <15>; 80 + 81 + clocks = <&cgu JZ4740_CLK_RTC>; 82 + clock-names = "rtc"; 83 + };
+14
Documentation/devicetree/bindings/rtc/rtc-mt2712.txt
··· 1 + Device-Tree bindings for MediaTek SoC based RTC 2 + 3 + Required properties: 4 + - compatible : Should be "mediatek,mt2712-rtc" : for MT2712 SoC 5 + - reg : Specifies base physical address and size of the registers; 6 + - interrupts : Should contain the interrupt for RTC alarm; 7 + 8 + Example: 9 + 10 + rtc: rtc@10011000 { 11 + compatible = "mediatek,mt2712-rtc"; 12 + reg = <0 0x10011000 0 0x1000>; 13 + interrupts = <GIC_SPI 239 IRQ_TYPE_LEVEL_LOW>; 14 + };
+2
MAINTAINERS
··· 2015 2015 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2016 2016 L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 2017 2017 S: Maintained 2018 + F: Documentation/devicetree/bindings/rtc/rtc-mt2712.txt 2018 2019 F: Documentation/devicetree/bindings/rtc/rtc-mt7622.txt 2020 + F: drivers/rtc/rtc-mt2712.c 2019 2021 F: drivers/rtc/rtc-mt6397.c 2020 2022 F: drivers/rtc/rtc-mt7622.c 2021 2023
+13 -4
drivers/rtc/Kconfig
··· 41 41 device should record time in UTC, since the kernel won't do 42 42 timezone correction. 43 43 44 - The driver for this RTC device must be loaded before late_initcall 45 - functions run, so it must usually be statically linked. 46 - 47 44 This clock should be battery-backed, so that it reads the correct 48 45 time when the system boots from a power-off state. Otherwise, your 49 46 system will need an external clock source (like an NTP server). ··· 238 241 config RTC_DRV_DS1307 239 242 tristate "Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057" 240 243 select REGMAP_I2C 244 + select WATCHDOG_CORE if WATCHDOG 241 245 help 242 246 If you say yes here you get support for various compatible RTC 243 247 chips (often with battery backup) connected with I2C. This driver ··· 1333 1335 1334 1336 config RTC_DRV_FSL_FTM_ALARM 1335 1337 tristate "Freescale FlexTimer alarm timer" 1336 - depends on ARCH_LAYERSCAPE || SOC_LS1021A 1338 + depends on ARCH_LAYERSCAPE || SOC_LS1021A || COMPILE_TEST 1337 1339 help 1338 1340 For the FlexTimer in LS1012A, LS1021A, LS1028A, LS1043A, LS1046A, 1339 1341 LS1088A, LS208xA, we can use FTM as the wakeup source. ··· 1760 1762 config RTC_DRV_SNVS 1761 1763 tristate "Freescale SNVS RTC support" 1762 1764 select REGMAP_MMIO 1765 + depends on ARCH_MXC || COMPILE_TEST 1763 1766 depends on HAS_IOMEM 1764 1767 depends on OF 1765 1768 help ··· 1805 1806 1806 1807 This driver can also be built as a module. If so, the module 1807 1808 will be called rtc-moxart 1809 + 1810 + config RTC_DRV_MT2712 1811 + tristate "MediaTek MT2712 SoC based RTC" 1812 + depends on ARCH_MEDIATEK || COMPILE_TEST 1813 + help 1814 + This enables support for the real time clock built in the MediaTek 1815 + SoCs for MT2712. 1816 + 1817 + This drive can also be built as a module. If so, the module 1818 + will be called rtc-mt2712. 1808 1819 1809 1820 config RTC_DRV_MT6397 1810 1821 tristate "MediaTek PMIC based RTC"
+1 -1
drivers/rtc/Makefile
··· 6 6 ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG 7 7 8 8 obj-$(CONFIG_RTC_LIB) += lib.o 9 - obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 10 9 obj-$(CONFIG_RTC_SYSTOHC) += systohc.o 11 10 obj-$(CONFIG_RTC_CLASS) += rtc-core.o 12 11 obj-$(CONFIG_RTC_MC146818_LIB) += rtc-mc146818-lib.o ··· 105 106 obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o 106 107 obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o 107 108 obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 109 + obj-$(CONFIG_RTC_DRV_MT2712) += rtc-mt2712.o 108 110 obj-$(CONFIG_RTC_DRV_MT6397) += rtc-mt6397.o 109 111 obj-$(CONFIG_RTC_DRV_MT7622) += rtc-mt7622.o 110 112 obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o
+49
drivers/rtc/class.c
··· 34 34 #ifdef CONFIG_RTC_HCTOSYS_DEVICE 35 35 /* Result of the last RTC to system clock attempt. */ 36 36 int rtc_hctosys_ret = -ENODEV; 37 + 38 + /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary 39 + * whether it stores the most close value or the value with partial 40 + * seconds truncated. However, it is important that we use it to store 41 + * the truncated value. This is because otherwise it is necessary, 42 + * in an rtc sync function, to read both xtime.tv_sec and 43 + * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read 44 + * of >32bits is not possible. So storing the most close value would 45 + * slow down the sync API. So here we have the truncated value and 46 + * the best guess is to add 0.5s. 47 + */ 48 + 49 + static void rtc_hctosys(struct rtc_device *rtc) 50 + { 51 + int err; 52 + struct rtc_time tm; 53 + struct timespec64 tv64 = { 54 + .tv_nsec = NSEC_PER_SEC >> 1, 55 + }; 56 + 57 + err = rtc_read_time(rtc, &tm); 58 + if (err) { 59 + dev_err(rtc->dev.parent, 60 + "hctosys: unable to read the hardware clock\n"); 61 + goto err_read; 62 + } 63 + 64 + tv64.tv_sec = rtc_tm_to_time64(&tm); 65 + 66 + #if BITS_PER_LONG == 32 67 + if (tv64.tv_sec > INT_MAX) { 68 + err = -ERANGE; 69 + goto err_read; 70 + } 71 + #endif 72 + 73 + err = do_settimeofday64(&tv64); 74 + 75 + dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", 76 + &tm, (long long)tv64.tv_sec); 77 + 78 + err_read: 79 + rtc_hctosys_ret = err; 80 + } 37 81 #endif 38 82 39 83 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_RTC_HCTOSYS_DEVICE) ··· 418 374 rtc->registered = true; 419 375 dev_info(rtc->dev.parent, "registered as %s\n", 420 376 dev_name(&rtc->dev)); 377 + 378 + #ifdef CONFIG_RTC_HCTOSYS_DEVICE 379 + if (!strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE)) 380 + rtc_hctosys(rtc); 381 + #endif 421 382 422 383 return 0; 423 384 }
-69
drivers/rtc/hctosys.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * RTC subsystem, initialize system time on startup 4 - * 5 - * Copyright (C) 2005 Tower Technologies 6 - * Author: Alessandro Zummo <a.zummo@towertech.it> 7 - */ 8 - 9 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 10 - 11 - #include <linux/rtc.h> 12 - 13 - /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary 14 - * whether it stores the most close value or the value with partial 15 - * seconds truncated. However, it is important that we use it to store 16 - * the truncated value. This is because otherwise it is necessary, 17 - * in an rtc sync function, to read both xtime.tv_sec and 18 - * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read 19 - * of >32bits is not possible. So storing the most close value would 20 - * slow down the sync API. So here we have the truncated value and 21 - * the best guess is to add 0.5s. 22 - */ 23 - 24 - static int __init rtc_hctosys(void) 25 - { 26 - int err = -ENODEV; 27 - struct rtc_time tm; 28 - struct timespec64 tv64 = { 29 - .tv_nsec = NSEC_PER_SEC >> 1, 30 - }; 31 - struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 32 - 33 - if (!rtc) { 34 - pr_info("unable to open rtc device (%s)\n", 35 - CONFIG_RTC_HCTOSYS_DEVICE); 36 - goto err_open; 37 - } 38 - 39 - err = rtc_read_time(rtc, &tm); 40 - if (err) { 41 - dev_err(rtc->dev.parent, 42 - "hctosys: unable to read the hardware clock\n"); 43 - goto err_read; 44 - } 45 - 46 - tv64.tv_sec = rtc_tm_to_time64(&tm); 47 - 48 - #if BITS_PER_LONG == 32 49 - if (tv64.tv_sec > INT_MAX) { 50 - err = -ERANGE; 51 - goto err_read; 52 - } 53 - #endif 54 - 55 - err = do_settimeofday64(&tv64); 56 - 57 - dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n", 58 - &tm, (long long)tv64.tv_sec); 59 - 60 - err_read: 61 - rtc_class_close(rtc); 62 - 63 - err_open: 64 - rtc_hctosys_ret = err; 65 - 66 - return err; 67 - } 68 - 69 - late_initcall(rtc_hctosys);
+15 -89
drivers/rtc/rtc-88pm860x.c
··· 28 28 29 29 int irq; 30 30 int vrtc; 31 - int (*sync)(unsigned int ticks); 32 31 }; 33 32 34 33 #define REG_VRTC_MEAS1 0x7D ··· 75 76 return 0; 76 77 } 77 78 78 - /* 79 - * Calculate the next alarm time given the requested alarm time mask 80 - * and the current time. 81 - */ 82 - static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, 83 - struct rtc_time *alrm) 84 - { 85 - unsigned long next_time; 86 - unsigned long now_time; 87 - 88 - next->tm_year = now->tm_year; 89 - next->tm_mon = now->tm_mon; 90 - next->tm_mday = now->tm_mday; 91 - next->tm_hour = alrm->tm_hour; 92 - next->tm_min = alrm->tm_min; 93 - next->tm_sec = alrm->tm_sec; 94 - 95 - rtc_tm_to_time(now, &now_time); 96 - rtc_tm_to_time(next, &next_time); 97 - 98 - if (next_time < now_time) { 99 - /* Advance one day */ 100 - next_time += 60 * 60 * 24; 101 - rtc_time_to_tm(next_time, next); 102 - } 103 - } 104 - 105 79 static int pm860x_rtc_read_time(struct device *dev, struct rtc_time *tm) 106 80 { 107 81 struct pm860x_rtc_info *info = dev_get_drvdata(dev); ··· 95 123 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", 96 124 base, data, ticks); 97 125 98 - rtc_time_to_tm(ticks, tm); 126 + rtc_time64_to_tm(ticks, tm); 99 127 100 128 return 0; 101 129 } ··· 112 140 1900 + tm->tm_year); 113 141 return -EINVAL; 114 142 } 115 - rtc_tm_to_time(tm, &ticks); 143 + ticks = rtc_tm_to_time64(tm); 116 144 117 145 /* load 32-bit read-only counter */ 118 146 pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); ··· 127 155 pm860x_page_reg_write(info->i2c, REG2_DATA, (base >> 8) & 0xFF); 128 156 pm860x_page_reg_write(info->i2c, REG3_DATA, base & 0xFF); 129 157 130 - if (info->sync) 131 - info->sync(ticks); 132 158 return 0; 133 159 } 134 160 ··· 150 180 dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", 151 181 base, data, ticks); 152 182 153 - rtc_time_to_tm(ticks, &alrm->time); 183 + rtc_time64_to_tm(ticks, &alrm->time); 154 184 ret = pm860x_reg_read(info->i2c, PM8607_RTC1); 155 185 alrm->enabled = (ret & ALARM_EN) ? 1 : 0; 156 186 alrm->pending = (ret & (ALARM | ALARM_WAKEUP)) ? 1 : 0; ··· 160 190 static int pm860x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 161 191 { 162 192 struct pm860x_rtc_info *info = dev_get_drvdata(dev); 163 - struct rtc_time now_tm, alarm_tm; 164 193 unsigned long ticks, base, data; 165 194 unsigned char buf[8]; 166 195 int mask; ··· 172 203 base = ((unsigned long)buf[1] << 24) | (buf[3] << 16) | 173 204 (buf[5] << 8) | buf[7]; 174 205 175 - /* load 32-bit read-only counter */ 176 - pm860x_bulk_read(info->i2c, PM8607_RTC_COUNTER1, 4, buf); 177 - data = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | 178 - (buf[1] << 8) | buf[0]; 179 - ticks = base + data; 180 - dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n", 181 - base, data, ticks); 182 - 183 - rtc_time_to_tm(ticks, &now_tm); 184 - rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time); 185 - /* get new ticks for alarm in 24 hours */ 186 - rtc_tm_to_time(&alarm_tm, &ticks); 206 + ticks = rtc_tm_to_time64(&alrm->time); 187 207 data = ticks - base; 188 208 189 209 buf[0] = data & 0xff; ··· 267 309 return 0; 268 310 } 269 311 #else 270 - #define pm860x_rtc_dt_init(x, y) (-1) 312 + #define pm860x_rtc_dt_init(x, y) do { } while (0) 271 313 #endif 272 314 273 315 static int pm860x_rtc_probe(struct platform_device *pdev) 274 316 { 275 317 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 276 - struct pm860x_rtc_pdata *pdata = NULL; 277 318 struct pm860x_rtc_info *info; 278 - struct rtc_time tm; 279 - unsigned long ticks = 0; 280 319 int ret; 281 - 282 - pdata = dev_get_platdata(&pdev->dev); 283 320 284 321 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info), 285 322 GFP_KERNEL); ··· 288 335 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; 289 336 info->dev = &pdev->dev; 290 337 dev_set_drvdata(&pdev->dev, info); 338 + 339 + info->rtc_dev = devm_rtc_allocate_device(&pdev->dev); 340 + if (IS_ERR(info->rtc_dev)) 341 + return PTR_ERR(info->rtc_dev); 291 342 292 343 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, 293 344 rtc_update_handler, IRQF_ONESHOT, "rtc", ··· 308 351 pm860x_page_reg_write(info->i2c, REG2_ADDR, REG2_DATA); 309 352 pm860x_page_reg_write(info->i2c, REG3_ADDR, REG3_DATA); 310 353 311 - ret = pm860x_rtc_read_time(&pdev->dev, &tm); 312 - if (ret < 0) { 313 - dev_err(&pdev->dev, "Failed to read initial time.\n"); 314 - return ret; 315 - } 316 - if ((tm.tm_year < 70) || (tm.tm_year > 138)) { 317 - tm.tm_year = 70; 318 - tm.tm_mon = 0; 319 - tm.tm_mday = 1; 320 - tm.tm_hour = 0; 321 - tm.tm_min = 0; 322 - tm.tm_sec = 0; 323 - ret = pm860x_rtc_set_time(&pdev->dev, &tm); 324 - if (ret < 0) { 325 - dev_err(&pdev->dev, "Failed to set initial time.\n"); 326 - return ret; 327 - } 328 - } 329 - rtc_tm_to_time(&tm, &ticks); 330 - if (pm860x_rtc_dt_init(pdev, info)) { 331 - if (pdata && pdata->sync) { 332 - pdata->sync(ticks); 333 - info->sync = pdata->sync; 334 - } 335 - } 354 + pm860x_rtc_dt_init(pdev, info); 336 355 337 - info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm860x-rtc", 338 - &pm860x_rtc_ops, THIS_MODULE); 339 - ret = PTR_ERR(info->rtc_dev); 340 - if (IS_ERR(info->rtc_dev)) { 341 - dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 356 + info->rtc_dev->ops = &pm860x_rtc_ops; 357 + info->rtc_dev->range_max = U32_MAX; 358 + 359 + ret = rtc_register_device(info->rtc_dev); 360 + if (ret) 342 361 return ret; 343 - } 344 362 345 363 /* 346 364 * enable internal XO instead of internal 3.25MHz clock since it can ··· 325 393 326 394 #ifdef VRTC_CALIBRATION 327 395 /* <00> -- 2.7V, <01> -- 2.9V, <10> -- 3.1V, <11> -- 3.3V */ 328 - if (pm860x_rtc_dt_init(pdev, info)) { 329 - if (pdata && pdata->vrtc) 330 - info->vrtc = pdata->vrtc & 0x3; 331 - else 332 - info->vrtc = 1; 333 - } 334 396 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, MEAS2_VRTC); 335 397 336 398 /* calibrate VRTC */
+5 -5
drivers/rtc/rtc-ab8500.c
··· 100 100 secs = secs / COUNTS_PER_SEC; 101 101 secs = secs + (mins * 60); 102 102 103 - rtc_time_to_tm(secs, tm); 103 + rtc_time64_to_tm(secs, tm); 104 104 return 0; 105 105 } 106 106 ··· 110 110 unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; 111 111 unsigned long no_secs, no_mins, secs = 0; 112 112 113 - rtc_tm_to_time(tm, &secs); 113 + secs = rtc_tm_to_time64(tm); 114 114 115 115 no_mins = secs / 60; 116 116 ··· 168 168 mins = (buf[0] << 16) | (buf[1] << 8) | (buf[2]); 169 169 secs = mins * 60; 170 170 171 - rtc_time_to_tm(secs, &alarm->time); 171 + rtc_time64_to_tm(secs, &alarm->time); 172 172 173 173 return 0; 174 174 } ··· 188 188 struct rtc_time curtm; 189 189 190 190 /* Get the number of seconds since 1970 */ 191 - rtc_tm_to_time(&alarm->time, &secs); 191 + secs = rtc_tm_to_time64(&alarm->time); 192 192 193 193 /* 194 194 * Check whether alarm is set less than 1min. ··· 196 196 * return -EINVAL, so UIE EMUL can take it up, incase of UIE_ON 197 197 */ 198 198 ab8500_rtc_read_time(dev, &curtm); /* Read current time */ 199 - rtc_tm_to_time(&curtm, &cursec); 199 + cursec = rtc_tm_to_time64(&curtm); 200 200 if ((secs - cursec) < 59) { 201 201 dev_dbg(dev, "Alarm less than 1 minute not supported\r\n"); 202 202 return -EINVAL;
+11 -18
drivers/rtc/rtc-au1xxx.c
··· 34 34 35 35 t = alchemy_rdsys(AU1000_SYS_TOYREAD); 36 36 37 - rtc_time_to_tm(t, tm); 37 + rtc_time64_to_tm(t, tm); 38 38 39 39 return 0; 40 40 } ··· 43 43 { 44 44 unsigned long t; 45 45 46 - rtc_tm_to_time(tm, &t); 46 + t = rtc_tm_to_time64(tm); 47 47 48 48 alchemy_wrsys(t, AU1000_SYS_TOYWRITE); 49 49 ··· 65 65 { 66 66 struct rtc_device *rtcdev; 67 67 unsigned long t; 68 - int ret; 69 68 70 69 t = alchemy_rdsys(AU1000_SYS_CNTRCTRL); 71 70 if (!(t & CNTR_OK)) { 72 71 dev_err(&pdev->dev, "counters not working; aborting.\n"); 73 - ret = -ENODEV; 74 - goto out_err; 72 + return -ENODEV; 75 73 } 76 - 77 - ret = -ETIMEDOUT; 78 74 79 75 /* set counter0 tickrate to 1Hz if necessary */ 80 76 if (alchemy_rdsys(AU1000_SYS_TOYTRIM) != 32767) { ··· 84 88 * counters are unusable. 85 89 */ 86 90 dev_err(&pdev->dev, "timeout waiting for access\n"); 87 - goto out_err; 91 + return -ETIMEDOUT; 88 92 } 89 93 90 94 /* set 1Hz TOY tick rate */ ··· 95 99 while (alchemy_rdsys(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C0S) 96 100 msleep(1); 97 101 98 - rtcdev = devm_rtc_device_register(&pdev->dev, "rtc-au1xxx", 99 - &au1xtoy_rtc_ops, THIS_MODULE); 100 - if (IS_ERR(rtcdev)) { 101 - ret = PTR_ERR(rtcdev); 102 - goto out_err; 103 - } 102 + rtcdev = devm_rtc_allocate_device(&pdev->dev); 103 + if (IS_ERR(rtcdev)) 104 + return PTR_ERR(rtcdev); 105 + 106 + rtcdev->ops = &au1xtoy_rtc_ops; 107 + rtcdev->range_max = U32_MAX; 104 108 105 109 platform_set_drvdata(pdev, rtcdev); 106 110 107 - return 0; 108 - 109 - out_err: 110 - return ret; 111 + return rtc_register_device(rtcdev); 111 112 } 112 113 113 114 static struct platform_driver au1xrtc_driver = {
+1 -3
drivers/rtc/rtc-bd70528.c
··· 542 542 543 543 irq = platform_get_irq_byname(pdev, irq_name); 544 544 545 - if (irq < 0) { 546 - dev_err(&pdev->dev, "Failed to get irq\n"); 545 + if (irq < 0) 547 546 return irq; 548 - } 549 547 550 548 platform_set_drvdata(pdev, bd_rtc); 551 549
+3 -2
drivers/rtc/rtc-cmos.c
··· 649 649 650 650 static irqreturn_t cmos_interrupt(int irq, void *p) 651 651 { 652 + unsigned long flags; 652 653 u8 irqstat; 653 654 u8 rtc_control; 654 655 655 - spin_lock(&rtc_lock); 656 + spin_lock_irqsave(&rtc_lock, flags); 656 657 657 658 /* When the HPET interrupt handler calls us, the interrupt 658 659 * status is passed as arg1 instead of the irq number. But ··· 687 686 hpet_mask_rtc_irq_bit(RTC_AIE); 688 687 CMOS_READ(RTC_INTR_FLAGS); 689 688 } 690 - spin_unlock(&rtc_lock); 689 + spin_unlock_irqrestore(&rtc_lock, flags); 691 690 692 691 if (is_intr(irqstat)) { 693 692 rtc_update_irq(p, 1, irqstat);
+7 -6
drivers/rtc/rtc-cpcap.c
··· 56 56 tod = (cpcap->tod1 & TOD1_MASK) | ((cpcap->tod2 & TOD2_MASK) << 8); 57 57 time = tod + ((cpcap->day & DAY_MASK) * SECS_PER_DAY); 58 58 59 - rtc_time_to_tm(time, rtc); 59 + rtc_time64_to_tm(time, rtc); 60 60 } 61 61 62 62 static void rtc2cpcap_time(struct cpcap_time *cpcap, struct rtc_time *rtc) 63 63 { 64 64 unsigned long time; 65 65 66 - rtc_tm_to_time(rtc, &time); 66 + time = rtc_tm_to_time64(rtc); 67 67 68 68 cpcap->day = time / SECS_PER_DAY; 69 69 time %= SECS_PER_DAY; ··· 256 256 return -ENODEV; 257 257 258 258 platform_set_drvdata(pdev, rtc); 259 - rtc->rtc_dev = devm_rtc_device_register(dev, "cpcap_rtc", 260 - &cpcap_rtc_ops, THIS_MODULE); 261 - 259 + rtc->rtc_dev = devm_rtc_allocate_device(dev); 262 260 if (IS_ERR(rtc->rtc_dev)) 263 261 return PTR_ERR(rtc->rtc_dev); 262 + 263 + rtc->rtc_dev->ops = &cpcap_rtc_ops; 264 + rtc->rtc_dev->range_max = (1 << 14) * SECS_PER_DAY - 1; 264 265 265 266 err = cpcap_get_vendor(dev, rtc->regmap, &rtc->vendor); 266 267 if (err) ··· 299 298 /* ignore error and continue without wakeup support */ 300 299 } 301 300 302 - return 0; 301 + return rtc_register_device(rtc->rtc_dev); 303 302 } 304 303 305 304 static const struct of_device_id cpcap_rtc_of_match[] = {
+11 -7
drivers/rtc/rtc-da9052.c
··· 103 103 int ret; 104 104 uint8_t v[3]; 105 105 106 - ret = rtc_tm_to_time(rtc_tm, &alm_time); 107 - if (ret != 0) 108 - return ret; 106 + alm_time = rtc_tm_to_time64(rtc_tm); 109 107 110 108 if (rtc_tm->tm_sec > 0) { 111 109 alm_time += 60 - rtc_tm->tm_sec; 112 - rtc_time_to_tm(alm_time, rtc_tm); 110 + rtc_time64_to_tm(alm_time, rtc_tm); 113 111 } 114 112 BUG_ON(rtc_tm->tm_sec); /* it will cause repeated irqs if not zero */ 115 113 ··· 296 298 rtc_err(rtc, "Failed to disable TICKS: %d\n", ret); 297 299 298 300 device_init_wakeup(&pdev->dev, true); 299 - rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 300 - &da9052_rtc_ops, THIS_MODULE); 301 - 301 + rtc->rtc = devm_rtc_allocate_device(&pdev->dev); 302 302 if (IS_ERR(rtc->rtc)) 303 303 return PTR_ERR(rtc->rtc); 304 + 305 + rtc->rtc->ops = &da9052_rtc_ops; 306 + rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 307 + rtc->rtc->range_max = RTC_TIMESTAMP_END_2063; 308 + 309 + ret = rtc_register_device(rtc->rtc); 310 + if (ret) 311 + return ret; 304 312 305 313 ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM", 306 314 da9052_rtc_irq, rtc);
+13 -45
drivers/rtc/rtc-davinci.c
··· 227 227 return ret; 228 228 } 229 229 230 - static int convertfromdays(u16 days, struct rtc_time *tm) 230 + static void convertfromdays(u16 days, struct rtc_time *tm) 231 231 { 232 232 int tmp_days, year, mon; 233 233 ··· 250 250 break; 251 251 } 252 252 } 253 - return 0; 254 253 } 255 254 256 - static int convert2days(u16 *days, struct rtc_time *tm) 255 + static void convert2days(u16 *days, struct rtc_time *tm) 257 256 { 258 257 int i; 259 258 *days = 0; 260 - 261 - /* epoch == 1900 */ 262 - if (tm->tm_year < 100 || tm->tm_year > 199) 263 - return -EINVAL; 264 259 265 260 for (i = 2000; i < 1900 + tm->tm_year; i++) 266 261 *days += rtc_year_days(1, 12, i); 267 262 268 263 *days += rtc_year_days(tm->tm_mday, tm->tm_mon, 1900 + tm->tm_year); 269 - 270 - return 0; 271 264 } 272 265 273 266 static int davinci_rtc_read_time(struct device *dev, struct rtc_time *tm) ··· 293 300 days <<= 8; 294 301 days |= day0; 295 302 296 - if (convertfromdays(days, tm) < 0) 297 - return -EINVAL; 303 + convertfromdays(days, tm); 298 304 299 305 return 0; 300 306 } ··· 305 313 u8 rtc_cctrl; 306 314 unsigned long flags; 307 315 308 - if (convert2days(&days, tm) < 0) 309 - return -EINVAL; 316 + convert2days(&days, tm); 310 317 311 318 spin_lock_irqsave(&davinci_rtc_lock, flags); 312 319 ··· 387 396 days <<= 8; 388 397 days |= day0; 389 398 390 - if (convertfromdays(days, &alm->time) < 0) 391 - return -EINVAL; 399 + convertfromdays(days, &alm->time); 392 400 393 401 alm->pending = !!(rtcss_read(davinci_rtc, 394 402 PRTCSS_RTC_CCTRL) & ··· 403 413 unsigned long flags; 404 414 u16 days; 405 415 406 - if (alm->time.tm_mday <= 0 && alm->time.tm_mon < 0 407 - && alm->time.tm_year < 0) { 408 - struct rtc_time tm; 409 - unsigned long now, then; 410 - 411 - davinci_rtc_read_time(dev, &tm); 412 - rtc_tm_to_time(&tm, &now); 413 - 414 - alm->time.tm_mday = tm.tm_mday; 415 - alm->time.tm_mon = tm.tm_mon; 416 - alm->time.tm_year = tm.tm_year; 417 - rtc_tm_to_time(&alm->time, &then); 418 - 419 - if (then < now) { 420 - rtc_time_to_tm(now + 24 * 60 * 60, &tm); 421 - alm->time.tm_mday = tm.tm_mday; 422 - alm->time.tm_mon = tm.tm_mon; 423 - alm->time.tm_year = tm.tm_year; 424 - } 425 - } 426 - 427 - if (convert2days(&days, &alm->time) < 0) 428 - return -EINVAL; 416 + convert2days(&days, &alm->time); 429 417 430 418 spin_lock_irqsave(&davinci_rtc_lock, flags); 431 419 ··· 453 485 454 486 platform_set_drvdata(pdev, davinci_rtc); 455 487 456 - davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 457 - &davinci_rtc_ops, THIS_MODULE); 458 - if (IS_ERR(davinci_rtc->rtc)) { 459 - dev_err(dev, "unable to register RTC device, err %d\n", 460 - ret); 488 + davinci_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); 489 + if (IS_ERR(davinci_rtc->rtc)) 461 490 return PTR_ERR(davinci_rtc->rtc); 462 - } 491 + 492 + davinci_rtc->rtc->ops = &davinci_rtc_ops; 493 + davinci_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 494 + davinci_rtc->rtc->range_max = RTC_TIMESTAMP_BEGIN_2000 + (1 << 16) * 86400ULL - 1; 463 495 464 496 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG); 465 497 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN); ··· 484 516 485 517 device_init_wakeup(&pdev->dev, 0); 486 518 487 - return 0; 519 + return rtc_register_device(davinci_rtc->rtc); 488 520 } 489 521 490 522 static int __exit davinci_rtc_remove(struct platform_device *pdev)
+4 -6
drivers/rtc/rtc-ds1305.c
··· 325 325 u8 buf[1 + DS1305_ALM_LEN]; 326 326 327 327 /* convert desired alarm to time_t */ 328 - status = rtc_tm_to_time(&alm->time, &later); 329 - if (status < 0) 330 - return status; 328 + later = rtc_tm_to_time64(&alm->time); 331 329 332 330 /* Read current time as time_t */ 333 331 status = ds1305_get_time(dev, &tm); 334 332 if (status < 0) 335 333 return status; 336 - status = rtc_tm_to_time(&tm, &now); 337 - if (status < 0) 338 - return status; 334 + now = rtc_tm_to_time64(&tm); 339 335 340 336 /* make sure alarm fires within the next 24 hours */ 341 337 if (later <= now) ··· 690 694 return PTR_ERR(ds1305->rtc); 691 695 692 696 ds1305->rtc->ops = &ds1305_ops; 697 + ds1305->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 698 + ds1305->rtc->range_max = RTC_TIMESTAMP_END_2099; 693 699 694 700 ds1305_nvmem_cfg.priv = ds1305; 695 701 ds1305->rtc->nvram_old_abi = true;
+126
drivers/rtc/rtc-ds1307.c
··· 22 22 #include <linux/hwmon-sysfs.h> 23 23 #include <linux/clk-provider.h> 24 24 #include <linux/regmap.h> 25 + #include <linux/watchdog.h> 25 26 26 27 /* 27 28 * We can't determine type by probing, but if we expect pre-Linux code ··· 145 144 # define M41TXX_BIT_CALIB_SIGN BIT(5) 146 145 # define M41TXX_M_CALIBRATION GENMASK(4, 0) 147 146 147 + #define DS1388_REG_WDOG_HUN_SECS 0x08 148 + #define DS1388_REG_WDOG_SECS 0x09 149 + #define DS1388_REG_FLAG 0x0b 150 + # define DS1388_BIT_WF BIT(6) 151 + # define DS1388_BIT_OSF BIT(7) 152 + #define DS1388_REG_CONTROL 0x0c 153 + # define DS1388_BIT_RST BIT(0) 154 + # define DS1388_BIT_WDE BIT(1) 155 + 148 156 /* negative offset step is -2.034ppm */ 149 157 #define M41TXX_NEG_OFFSET_STEP_PPB 2034 150 158 /* positive offset step is +4.068ppm */ ··· 260 250 if (ret) 261 251 return ret; 262 252 if (tmp & DS1340_BIT_OSF) 253 + return -EINVAL; 254 + break; 255 + case ds_1388: 256 + ret = regmap_read(ds1307->regmap, DS1388_REG_FLAG, &tmp); 257 + if (ret) 258 + return ret; 259 + if (tmp & DS1388_BIT_OSF) 263 260 return -EINVAL; 264 261 break; 265 262 case mcp794xx: ··· 861 844 M41TXX_M_CALIBRATION | M41TXX_BIT_CALIB_SIGN, 862 845 ctrl_reg); 863 846 } 847 + 848 + #ifdef CONFIG_WATCHDOG_CORE 849 + static int ds1388_wdt_start(struct watchdog_device *wdt_dev) 850 + { 851 + struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); 852 + u8 regs[2]; 853 + int ret; 854 + 855 + ret = regmap_update_bits(ds1307->regmap, DS1388_REG_FLAG, 856 + DS1388_BIT_WF, 0); 857 + if (ret) 858 + return ret; 859 + 860 + ret = regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, 861 + DS1388_BIT_WDE | DS1388_BIT_RST, 0); 862 + if (ret) 863 + return ret; 864 + 865 + /* 866 + * watchdog timeouts are measured in seconds. So ignore hundredths of 867 + * seconds field. 868 + */ 869 + regs[0] = 0; 870 + regs[1] = bin2bcd(wdt_dev->timeout); 871 + 872 + ret = regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, 873 + sizeof(regs)); 874 + if (ret) 875 + return ret; 876 + 877 + return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, 878 + DS1388_BIT_WDE | DS1388_BIT_RST, 879 + DS1388_BIT_WDE | DS1388_BIT_RST); 880 + } 881 + 882 + static int ds1388_wdt_stop(struct watchdog_device *wdt_dev) 883 + { 884 + struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); 885 + 886 + return regmap_update_bits(ds1307->regmap, DS1388_REG_CONTROL, 887 + DS1388_BIT_WDE | DS1388_BIT_RST, 0); 888 + } 889 + 890 + static int ds1388_wdt_ping(struct watchdog_device *wdt_dev) 891 + { 892 + struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); 893 + u8 regs[2]; 894 + 895 + return regmap_bulk_read(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, 896 + sizeof(regs)); 897 + } 898 + 899 + static int ds1388_wdt_set_timeout(struct watchdog_device *wdt_dev, 900 + unsigned int val) 901 + { 902 + struct ds1307 *ds1307 = watchdog_get_drvdata(wdt_dev); 903 + u8 regs[2]; 904 + 905 + wdt_dev->timeout = val; 906 + regs[0] = 0; 907 + regs[1] = bin2bcd(wdt_dev->timeout); 908 + 909 + return regmap_bulk_write(ds1307->regmap, DS1388_REG_WDOG_HUN_SECS, regs, 910 + sizeof(regs)); 911 + } 912 + #endif 864 913 865 914 static const struct rtc_class_ops rx8130_rtc_ops = { 866 915 .read_time = ds1307_get_time, ··· 1650 1567 1651 1568 #endif /* CONFIG_COMMON_CLK */ 1652 1569 1570 + #ifdef CONFIG_WATCHDOG_CORE 1571 + static const struct watchdog_info ds1388_wdt_info = { 1572 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 1573 + .identity = "DS1388 watchdog", 1574 + }; 1575 + 1576 + static const struct watchdog_ops ds1388_wdt_ops = { 1577 + .owner = THIS_MODULE, 1578 + .start = ds1388_wdt_start, 1579 + .stop = ds1388_wdt_stop, 1580 + .ping = ds1388_wdt_ping, 1581 + .set_timeout = ds1388_wdt_set_timeout, 1582 + 1583 + }; 1584 + 1585 + static void ds1307_wdt_register(struct ds1307 *ds1307) 1586 + { 1587 + struct watchdog_device *wdt; 1588 + 1589 + if (ds1307->type != ds_1388) 1590 + return; 1591 + 1592 + wdt = devm_kzalloc(ds1307->dev, sizeof(*wdt), GFP_KERNEL); 1593 + if (!wdt) 1594 + return; 1595 + 1596 + wdt->info = &ds1388_wdt_info; 1597 + wdt->ops = &ds1388_wdt_ops; 1598 + wdt->timeout = 99; 1599 + wdt->max_timeout = 99; 1600 + wdt->min_timeout = 1; 1601 + 1602 + watchdog_init_timeout(wdt, 0, ds1307->dev); 1603 + watchdog_set_drvdata(wdt, ds1307); 1604 + devm_watchdog_register_device(ds1307->dev, wdt); 1605 + } 1606 + #else 1607 + static void ds1307_wdt_register(struct ds1307 *ds1307) 1608 + { 1609 + } 1610 + #endif /* CONFIG_WATCHDOG_CORE */ 1611 + 1653 1612 static const struct regmap_config regmap_config = { 1654 1613 .reg_bits = 8, 1655 1614 .val_bits = 8, ··· 1981 1856 1982 1857 ds1307_hwmon_register(ds1307); 1983 1858 ds1307_clks_register(ds1307); 1859 + ds1307_wdt_register(ds1307); 1984 1860 1985 1861 return 0; 1986 1862
+15 -12
drivers/rtc/rtc-ds1374.c
··· 164 164 165 165 ret = ds1374_read_rtc(client, &itime, DS1374_REG_TOD0, 4); 166 166 if (!ret) 167 - rtc_time_to_tm(itime, time); 167 + rtc_time64_to_tm(itime, time); 168 168 169 169 return ret; 170 170 } ··· 172 172 static int ds1374_set_time(struct device *dev, struct rtc_time *time) 173 173 { 174 174 struct i2c_client *client = to_i2c_client(dev); 175 - unsigned long itime; 175 + unsigned long itime = rtc_tm_to_time64(time); 176 176 177 - rtc_tm_to_time(time, &itime); 178 177 return ds1374_write_rtc(client, itime, DS1374_REG_TOD0, 4); 179 178 } 180 179 ··· 211 212 if (ret) 212 213 goto out; 213 214 214 - rtc_time_to_tm(now + cur_alarm, &alarm->time); 215 + rtc_time64_to_tm(now + cur_alarm, &alarm->time); 215 216 alarm->enabled = !!(cr & DS1374_REG_CR_WACE); 216 217 alarm->pending = !!(sr & DS1374_REG_SR_AF); 217 218 ··· 236 237 if (ret < 0) 237 238 return ret; 238 239 239 - rtc_tm_to_time(&alarm->time, &new_alarm); 240 - rtc_tm_to_time(&now, &itime); 240 + new_alarm = rtc_tm_to_time64(&alarm->time); 241 + itime = rtc_tm_to_time64(&now); 241 242 242 243 /* This can happen due to races, in addition to dates that are 243 244 * truly in the past. To avoid requiring the caller to check for ··· 619 620 if (!ds1374) 620 621 return -ENOMEM; 621 622 623 + ds1374->rtc = devm_rtc_allocate_device(&client->dev); 624 + if (IS_ERR(ds1374->rtc)) 625 + return PTR_ERR(ds1374->rtc); 626 + 622 627 ds1374->client = client; 623 628 i2c_set_clientdata(client, ds1374); 624 629 ··· 644 641 device_set_wakeup_capable(&client->dev, 1); 645 642 } 646 643 647 - ds1374->rtc = devm_rtc_device_register(&client->dev, client->name, 648 - &ds1374_rtc_ops, THIS_MODULE); 649 - if (IS_ERR(ds1374->rtc)) { 650 - dev_err(&client->dev, "unable to register the class device\n"); 651 - return PTR_ERR(ds1374->rtc); 652 - } 644 + ds1374->rtc->ops = &ds1374_rtc_ops; 645 + ds1374->rtc->range_max = U32_MAX; 646 + 647 + ret = rtc_register_device(ds1374->rtc); 648 + if (ret) 649 + return ret; 653 650 654 651 #ifdef CONFIG_RTC_DRV_DS1374_WDT 655 652 save_client = client;
+17 -6
drivers/rtc/rtc-fsl-ftm-alarm.c
··· 20 20 #include <linux/fsl/ftm.h> 21 21 #include <linux/rtc.h> 22 22 #include <linux/time.h> 23 + #include <linux/acpi.h> 23 24 24 25 #define FTM_SC_CLK(c) ((c) << FTM_SC_CLK_MASK_SHIFT) 25 26 ··· 152 151 { 153 152 struct ftm_rtc *rtc = dev; 154 153 154 + rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); 155 + 155 156 ftm_irq_acknowledge(rtc); 156 157 ftm_irq_disable(rtc); 157 158 ftm_clean_alarm(rtc); ··· 245 242 246 243 static int ftm_rtc_probe(struct platform_device *pdev) 247 244 { 248 - struct device_node *np = pdev->dev.of_node; 249 245 int irq; 250 246 int ret; 251 247 struct ftm_rtc *rtc; ··· 267 265 return PTR_ERR(rtc->base); 268 266 } 269 267 270 - irq = irq_of_parse_and_map(np, 0); 271 - if (irq <= 0) { 272 - dev_err(&pdev->dev, "unable to get IRQ from DT, %d\n", irq); 273 - return -EINVAL; 268 + irq = platform_get_irq(pdev, 0); 269 + if (irq < 0) { 270 + dev_err(&pdev->dev, "can't get irq number\n"); 271 + return irq; 274 272 } 275 273 276 274 ret = devm_request_irq(&pdev->dev, irq, ftm_rtc_alarm_interrupt, ··· 280 278 return ret; 281 279 } 282 280 283 - rtc->big_endian = of_property_read_bool(np, "big-endian"); 281 + rtc->big_endian = 282 + device_property_read_bool(&pdev->dev, "big-endian"); 283 + 284 284 rtc->alarm_freq = (u32)FIXED_FREQ_CLK / (u32)MAX_FREQ_DIV; 285 285 rtc->rtc_dev->ops = &ftm_rtc_ops; 286 286 ··· 309 305 { }, 310 306 }; 311 307 308 + static const struct acpi_device_id ftm_imx_acpi_ids[] = { 309 + {"NXP0011",}, 310 + { } 311 + }; 312 + MODULE_DEVICE_TABLE(acpi, ftm_imx_acpi_ids); 313 + 312 314 static struct platform_driver ftm_rtc_driver = { 313 315 .probe = ftm_rtc_probe, 314 316 .driver = { 315 317 .name = "ftm-alarm", 316 318 .of_match_table = ftm_rtc_match, 319 + .acpi_match_table = ACPI_PTR(ftm_imx_acpi_ids), 317 320 }, 318 321 }; 319 322
+1 -1
drivers/rtc/rtc-imx-sc.c
··· 37 37 u8 hour; 38 38 u8 min; 39 39 u8 sec; 40 - } __packed; 40 + } __packed __aligned(4); 41 41 42 42 static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm) 43 43 {
+6 -3
drivers/rtc/rtc-jz4740.c
··· 46 46 47 47 enum jz4740_rtc_type { 48 48 ID_JZ4740, 49 + ID_JZ4760, 49 50 ID_JZ4780, 50 51 }; 51 52 ··· 107 106 { 108 107 int ret = 0; 109 108 110 - if (rtc->type >= ID_JZ4780) 109 + if (rtc->type >= ID_JZ4760) 111 110 ret = jz4780_rtc_enable_write(rtc); 112 111 if (ret == 0) 113 112 ret = jz4740_rtc_wait_write_ready(rtc); ··· 299 298 300 299 static const struct of_device_id jz4740_rtc_of_match[] = { 301 300 { .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 }, 301 + { .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 }, 302 302 { .compatible = "ingenic,jz4780-rtc", .data = (void *)ID_JZ4780 }, 303 303 {}, 304 304 }; ··· 374 372 if (!pm_power_off) { 375 373 /* Default: 60ms */ 376 374 rtc->reset_pin_assert_time = 60; 377 - of_property_read_u32(np, "reset-pin-assert-time-ms", 375 + of_property_read_u32(np, 376 + "ingenic,reset-pin-assert-time-ms", 378 377 &rtc->reset_pin_assert_time); 379 378 380 379 /* Default: 100ms */ 381 380 rtc->min_wakeup_pin_assert_time = 100; 382 381 of_property_read_u32(np, 383 - "min-wakeup-pin-assert-time-ms", 382 + "ingenic,min-wakeup-pin-assert-time-ms", 384 383 &rtc->min_wakeup_pin_assert_time); 385 384 386 385 dev_for_power_off = &pdev->dev;
+1 -6
drivers/rtc/rtc-m48t35.c
··· 160 160 return -ENOMEM; 161 161 162 162 priv->size = resource_size(res); 163 - /* 164 - * kludge: remove the #ifndef after ioc3 resource 165 - * conflicts are resolved 166 - */ 167 - #ifndef CONFIG_SGI_IP27 168 163 if (!devm_request_mem_region(&pdev->dev, res->start, priv->size, 169 164 pdev->name)) 170 165 return -EBUSY; 171 - #endif 166 + 172 167 priv->baseaddr = res->start; 173 168 priv->reg = devm_ioremap(&pdev->dev, priv->baseaddr, priv->size); 174 169 if (!priv->reg)
+32 -29
drivers/rtc/rtc-mpc5121.c
··· 111 111 */ 112 112 now = in_be32(&regs->actual_time) + in_be32(&regs->target_time); 113 113 114 - rtc_time_to_tm(now, tm); 114 + rtc_time64_to_tm(now, tm); 115 115 116 116 /* 117 117 * update second minute hour registers ··· 126 126 { 127 127 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); 128 128 struct mpc5121_rtc_regs __iomem *regs = rtc->regs; 129 - int ret; 130 129 unsigned long now; 131 130 132 131 /* 133 132 * The actual_time register is read only so we write the offset 134 133 * between it and linux time to the target_time register. 135 134 */ 136 - ret = rtc_tm_to_time(tm, &now); 137 - if (ret == 0) 138 - out_be32(&regs->target_time, now - in_be32(&regs->actual_time)); 135 + now = rtc_tm_to_time64(tm); 136 + out_be32(&regs->target_time, now - in_be32(&regs->actual_time)); 139 137 140 138 /* 141 139 * update second minute hour registers ··· 313 315 if (!rtc) 314 316 return -ENOMEM; 315 317 316 - rtc->regs = of_iomap(op->dev.of_node, 0); 317 - if (!rtc->regs) { 318 + rtc->regs = devm_platform_ioremap_resource(op, 0); 319 + if (IS_ERR(rtc->regs)) { 318 320 dev_err(&op->dev, "%s: couldn't map io space\n", __func__); 319 321 return -ENOSYS; 320 322 } ··· 324 326 platform_set_drvdata(op, rtc); 325 327 326 328 rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1); 327 - err = request_irq(rtc->irq, mpc5121_rtc_handler, 0, 328 - "mpc5121-rtc", &op->dev); 329 + err = devm_request_irq(&op->dev, rtc->irq, mpc5121_rtc_handler, 0, 330 + "mpc5121-rtc", &op->dev); 329 331 if (err) { 330 332 dev_err(&op->dev, "%s: could not request irq: %i\n", 331 333 __func__, rtc->irq); ··· 333 335 } 334 336 335 337 rtc->irq_periodic = irq_of_parse_and_map(op->dev.of_node, 0); 336 - err = request_irq(rtc->irq_periodic, mpc5121_rtc_handler_upd, 337 - 0, "mpc5121-rtc_upd", &op->dev); 338 + err = devm_request_irq(&op->dev, rtc->irq_periodic, 339 + mpc5121_rtc_handler_upd, 0, "mpc5121-rtc_upd", 340 + &op->dev); 338 341 if (err) { 339 342 dev_err(&op->dev, "%s: could not request irq: %i\n", 340 343 __func__, rtc->irq_periodic); 341 344 goto out_dispose2; 342 345 } 346 + 347 + rtc->rtc = devm_rtc_allocate_device(&op->dev); 348 + if (IS_ERR(rtc->rtc)) { 349 + err = PTR_ERR(rtc->rtc); 350 + goto out_dispose2; 351 + } 352 + 353 + rtc->rtc->ops = &mpc5200_rtc_ops; 354 + rtc->rtc->uie_unsupported = 1; 355 + rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_0000; 356 + rtc->rtc->range_max = 65733206399ULL; /* 4052-12-31 23:59:59 */ 343 357 344 358 if (of_device_is_compatible(op->dev.of_node, "fsl,mpc5121-rtc")) { 345 359 u32 ka; ··· 361 351 "mpc5121-rtc: Battery or oscillator failure!\n"); 362 352 out_be32(&rtc->regs->keep_alive, ka); 363 353 } 364 - 365 - rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5121-rtc", 366 - &mpc5121_rtc_ops, THIS_MODULE); 367 - } else { 368 - rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5200-rtc", 369 - &mpc5200_rtc_ops, THIS_MODULE); 354 + rtc->rtc->ops = &mpc5121_rtc_ops; 355 + /* 356 + * This is a limitation of the driver that abuses the target 357 + * time register, the actual maximum year for the mpc5121 is 358 + * also 4052. 359 + */ 360 + rtc->rtc->range_min = 0; 361 + rtc->rtc->range_max = U32_MAX; 370 362 } 371 363 372 - if (IS_ERR(rtc->rtc)) { 373 - err = PTR_ERR(rtc->rtc); 374 - goto out_free_irq; 375 - } 376 - rtc->rtc->uie_unsupported = 1; 364 + err = rtc_register_device(rtc->rtc); 365 + if (err) 366 + goto out_dispose2; 377 367 378 368 return 0; 379 369 380 - out_free_irq: 381 - free_irq(rtc->irq_periodic, &op->dev); 382 370 out_dispose2: 383 371 irq_dispose_mapping(rtc->irq_periodic); 384 - free_irq(rtc->irq, &op->dev); 385 372 out_dispose: 386 373 irq_dispose_mapping(rtc->irq); 387 - iounmap(rtc->regs); 388 374 389 375 return err; 390 376 } ··· 394 388 out_8(&regs->alm_enable, 0); 395 389 out_8(&regs->int_enable, in_8(&regs->int_enable) & ~0x1); 396 390 397 - iounmap(rtc->regs); 398 - free_irq(rtc->irq, &op->dev); 399 - free_irq(rtc->irq_periodic, &op->dev); 400 391 irq_dispose_mapping(rtc->irq); 401 392 irq_dispose_mapping(rtc->irq_periodic); 402 393
+423
drivers/rtc/rtc-mt2712.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2019 MediaTek Inc. 4 + * Author: Ran Bi <ran.bi@mediatek.com> 5 + */ 6 + 7 + #include <linux/delay.h> 8 + #include <linux/init.h> 9 + #include <linux/io.h> 10 + #include <linux/irqdomain.h> 11 + #include <linux/module.h> 12 + #include <linux/of_address.h> 13 + #include <linux/of_irq.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/rtc.h> 16 + 17 + #define MT2712_BBPU 0x0000 18 + #define MT2712_BBPU_CLRPKY BIT(4) 19 + #define MT2712_BBPU_RELOAD BIT(5) 20 + #define MT2712_BBPU_CBUSY BIT(6) 21 + #define MT2712_BBPU_KEY (0x43 << 8) 22 + 23 + #define MT2712_IRQ_STA 0x0004 24 + #define MT2712_IRQ_STA_AL BIT(0) 25 + #define MT2712_IRQ_STA_TC BIT(1) 26 + 27 + #define MT2712_IRQ_EN 0x0008 28 + #define MT2712_IRQ_EN_AL BIT(0) 29 + #define MT2712_IRQ_EN_TC BIT(1) 30 + #define MT2712_IRQ_EN_ONESHOT BIT(2) 31 + 32 + #define MT2712_CII_EN 0x000c 33 + 34 + #define MT2712_AL_MASK 0x0010 35 + #define MT2712_AL_MASK_DOW BIT(4) 36 + 37 + #define MT2712_TC_SEC 0x0014 38 + #define MT2712_TC_MIN 0x0018 39 + #define MT2712_TC_HOU 0x001c 40 + #define MT2712_TC_DOM 0x0020 41 + #define MT2712_TC_DOW 0x0024 42 + #define MT2712_TC_MTH 0x0028 43 + #define MT2712_TC_YEA 0x002c 44 + 45 + #define MT2712_AL_SEC 0x0030 46 + #define MT2712_AL_MIN 0x0034 47 + #define MT2712_AL_HOU 0x0038 48 + #define MT2712_AL_DOM 0x003c 49 + #define MT2712_AL_DOW 0x0040 50 + #define MT2712_AL_MTH 0x0044 51 + #define MT2712_AL_YEA 0x0048 52 + 53 + #define MT2712_SEC_MASK 0x003f 54 + #define MT2712_MIN_MASK 0x003f 55 + #define MT2712_HOU_MASK 0x001f 56 + #define MT2712_DOM_MASK 0x001f 57 + #define MT2712_DOW_MASK 0x0007 58 + #define MT2712_MTH_MASK 0x000f 59 + #define MT2712_YEA_MASK 0x007f 60 + 61 + #define MT2712_POWERKEY1 0x004c 62 + #define MT2712_POWERKEY2 0x0050 63 + #define MT2712_POWERKEY1_KEY 0xa357 64 + #define MT2712_POWERKEY2_KEY 0x67d2 65 + 66 + #define MT2712_CON0 0x005c 67 + #define MT2712_CON1 0x0060 68 + 69 + #define MT2712_PROT 0x0070 70 + #define MT2712_PROT_UNLOCK1 0x9136 71 + #define MT2712_PROT_UNLOCK2 0x586a 72 + 73 + #define MT2712_WRTGR 0x0078 74 + 75 + #define MT2712_RTC_TIMESTAMP_END_2127 4985971199LL 76 + 77 + struct mt2712_rtc { 78 + struct rtc_device *rtc; 79 + void __iomem *base; 80 + int irq; 81 + u8 irq_wake_enabled; 82 + u8 powerlost; 83 + }; 84 + 85 + static inline u32 mt2712_readl(struct mt2712_rtc *mt2712_rtc, u32 reg) 86 + { 87 + return readl(mt2712_rtc->base + reg); 88 + } 89 + 90 + static inline void mt2712_writel(struct mt2712_rtc *mt2712_rtc, 91 + u32 reg, u32 val) 92 + { 93 + writel(val, mt2712_rtc->base + reg); 94 + } 95 + 96 + static void mt2712_rtc_write_trigger(struct mt2712_rtc *mt2712_rtc) 97 + { 98 + unsigned long timeout = jiffies + HZ / 10; 99 + 100 + mt2712_writel(mt2712_rtc, MT2712_WRTGR, 1); 101 + while (1) { 102 + if (!(mt2712_readl(mt2712_rtc, MT2712_BBPU) 103 + & MT2712_BBPU_CBUSY)) 104 + break; 105 + 106 + if (time_after(jiffies, timeout)) { 107 + dev_err(&mt2712_rtc->rtc->dev, 108 + "%s time out!\n", __func__); 109 + break; 110 + } 111 + cpu_relax(); 112 + } 113 + } 114 + 115 + static void mt2712_rtc_writeif_unlock(struct mt2712_rtc *mt2712_rtc) 116 + { 117 + mt2712_writel(mt2712_rtc, MT2712_PROT, MT2712_PROT_UNLOCK1); 118 + mt2712_rtc_write_trigger(mt2712_rtc); 119 + mt2712_writel(mt2712_rtc, MT2712_PROT, MT2712_PROT_UNLOCK2); 120 + mt2712_rtc_write_trigger(mt2712_rtc); 121 + } 122 + 123 + static irqreturn_t rtc_irq_handler_thread(int irq, void *data) 124 + { 125 + struct mt2712_rtc *mt2712_rtc = data; 126 + u16 irqsta; 127 + 128 + /* Clear interrupt */ 129 + irqsta = mt2712_readl(mt2712_rtc, MT2712_IRQ_STA); 130 + if (irqsta & MT2712_IRQ_STA_AL) { 131 + rtc_update_irq(mt2712_rtc->rtc, 1, RTC_IRQF | RTC_AF); 132 + return IRQ_HANDLED; 133 + } 134 + 135 + return IRQ_NONE; 136 + } 137 + 138 + static void __mt2712_rtc_read_time(struct mt2712_rtc *mt2712_rtc, 139 + struct rtc_time *tm, int *sec) 140 + { 141 + tm->tm_sec = mt2712_readl(mt2712_rtc, MT2712_TC_SEC) 142 + & MT2712_SEC_MASK; 143 + tm->tm_min = mt2712_readl(mt2712_rtc, MT2712_TC_MIN) 144 + & MT2712_MIN_MASK; 145 + tm->tm_hour = mt2712_readl(mt2712_rtc, MT2712_TC_HOU) 146 + & MT2712_HOU_MASK; 147 + tm->tm_mday = mt2712_readl(mt2712_rtc, MT2712_TC_DOM) 148 + & MT2712_DOM_MASK; 149 + tm->tm_mon = (mt2712_readl(mt2712_rtc, MT2712_TC_MTH) - 1) 150 + & MT2712_MTH_MASK; 151 + tm->tm_year = (mt2712_readl(mt2712_rtc, MT2712_TC_YEA) + 100) 152 + & MT2712_YEA_MASK; 153 + 154 + *sec = mt2712_readl(mt2712_rtc, MT2712_TC_SEC) & MT2712_SEC_MASK; 155 + } 156 + 157 + static int mt2712_rtc_read_time(struct device *dev, struct rtc_time *tm) 158 + { 159 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 160 + int sec; 161 + 162 + if (mt2712_rtc->powerlost) 163 + return -EINVAL; 164 + 165 + do { 166 + __mt2712_rtc_read_time(mt2712_rtc, tm, &sec); 167 + } while (sec < tm->tm_sec); /* SEC has carried */ 168 + 169 + return 0; 170 + } 171 + 172 + static int mt2712_rtc_set_time(struct device *dev, struct rtc_time *tm) 173 + { 174 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 175 + 176 + mt2712_writel(mt2712_rtc, MT2712_TC_SEC, tm->tm_sec & MT2712_SEC_MASK); 177 + mt2712_writel(mt2712_rtc, MT2712_TC_MIN, tm->tm_min & MT2712_MIN_MASK); 178 + mt2712_writel(mt2712_rtc, MT2712_TC_HOU, tm->tm_hour & MT2712_HOU_MASK); 179 + mt2712_writel(mt2712_rtc, MT2712_TC_DOM, tm->tm_mday & MT2712_DOM_MASK); 180 + mt2712_writel(mt2712_rtc, MT2712_TC_MTH, 181 + (tm->tm_mon + 1) & MT2712_MTH_MASK); 182 + mt2712_writel(mt2712_rtc, MT2712_TC_YEA, 183 + (tm->tm_year - 100) & MT2712_YEA_MASK); 184 + 185 + mt2712_rtc_write_trigger(mt2712_rtc); 186 + 187 + if (mt2712_rtc->powerlost) 188 + mt2712_rtc->powerlost = false; 189 + 190 + return 0; 191 + } 192 + 193 + static int mt2712_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 194 + { 195 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 196 + struct rtc_time *tm = &alm->time; 197 + u16 irqen; 198 + 199 + irqen = mt2712_readl(mt2712_rtc, MT2712_IRQ_EN); 200 + alm->enabled = !!(irqen & MT2712_IRQ_EN_AL); 201 + 202 + tm->tm_sec = mt2712_readl(mt2712_rtc, MT2712_AL_SEC) & MT2712_SEC_MASK; 203 + tm->tm_min = mt2712_readl(mt2712_rtc, MT2712_AL_MIN) & MT2712_MIN_MASK; 204 + tm->tm_hour = mt2712_readl(mt2712_rtc, MT2712_AL_HOU) & MT2712_HOU_MASK; 205 + tm->tm_mday = mt2712_readl(mt2712_rtc, MT2712_AL_DOM) & MT2712_DOM_MASK; 206 + tm->tm_mon = (mt2712_readl(mt2712_rtc, MT2712_AL_MTH) - 1) 207 + & MT2712_MTH_MASK; 208 + tm->tm_year = (mt2712_readl(mt2712_rtc, MT2712_AL_YEA) + 100) 209 + & MT2712_YEA_MASK; 210 + 211 + return 0; 212 + } 213 + 214 + static int mt2712_rtc_alarm_irq_enable(struct device *dev, 215 + unsigned int enabled) 216 + { 217 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 218 + u16 irqen; 219 + 220 + irqen = mt2712_readl(mt2712_rtc, MT2712_IRQ_EN); 221 + if (enabled) 222 + irqen |= MT2712_IRQ_EN_AL; 223 + else 224 + irqen &= ~MT2712_IRQ_EN_AL; 225 + mt2712_writel(mt2712_rtc, MT2712_IRQ_EN, irqen); 226 + mt2712_rtc_write_trigger(mt2712_rtc); 227 + 228 + return 0; 229 + } 230 + 231 + static int mt2712_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 232 + { 233 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 234 + struct rtc_time *tm = &alm->time; 235 + 236 + dev_dbg(&mt2712_rtc->rtc->dev, "set al time: %ptR, alm en: %d\n", 237 + tm, alm->enabled); 238 + 239 + mt2712_writel(mt2712_rtc, MT2712_AL_SEC, 240 + (mt2712_readl(mt2712_rtc, MT2712_AL_SEC) 241 + & ~(MT2712_SEC_MASK)) | (tm->tm_sec & MT2712_SEC_MASK)); 242 + mt2712_writel(mt2712_rtc, MT2712_AL_MIN, 243 + (mt2712_readl(mt2712_rtc, MT2712_AL_MIN) 244 + & ~(MT2712_MIN_MASK)) | (tm->tm_min & MT2712_MIN_MASK)); 245 + mt2712_writel(mt2712_rtc, MT2712_AL_HOU, 246 + (mt2712_readl(mt2712_rtc, MT2712_AL_HOU) 247 + & ~(MT2712_HOU_MASK)) | (tm->tm_hour & MT2712_HOU_MASK)); 248 + mt2712_writel(mt2712_rtc, MT2712_AL_DOM, 249 + (mt2712_readl(mt2712_rtc, MT2712_AL_DOM) 250 + & ~(MT2712_DOM_MASK)) | (tm->tm_mday & MT2712_DOM_MASK)); 251 + mt2712_writel(mt2712_rtc, MT2712_AL_MTH, 252 + (mt2712_readl(mt2712_rtc, MT2712_AL_MTH) 253 + & ~(MT2712_MTH_MASK)) 254 + | ((tm->tm_mon + 1) & MT2712_MTH_MASK)); 255 + mt2712_writel(mt2712_rtc, MT2712_AL_YEA, 256 + (mt2712_readl(mt2712_rtc, MT2712_AL_YEA) 257 + & ~(MT2712_YEA_MASK)) 258 + | ((tm->tm_year - 100) & MT2712_YEA_MASK)); 259 + 260 + /* mask day of week */ 261 + mt2712_writel(mt2712_rtc, MT2712_AL_MASK, MT2712_AL_MASK_DOW); 262 + mt2712_rtc_write_trigger(mt2712_rtc); 263 + 264 + mt2712_rtc_alarm_irq_enable(dev, alm->enabled); 265 + 266 + return 0; 267 + } 268 + 269 + /* Init RTC register */ 270 + static void mt2712_rtc_hw_init(struct mt2712_rtc *mt2712_rtc) 271 + { 272 + u32 p1, p2; 273 + 274 + mt2712_writel(mt2712_rtc, MT2712_BBPU, 275 + MT2712_BBPU_KEY | MT2712_BBPU_RELOAD); 276 + 277 + mt2712_writel(mt2712_rtc, MT2712_CII_EN, 0); 278 + mt2712_writel(mt2712_rtc, MT2712_AL_MASK, 0); 279 + /* necessary before set MT2712_POWERKEY */ 280 + mt2712_writel(mt2712_rtc, MT2712_CON0, 0x4848); 281 + mt2712_writel(mt2712_rtc, MT2712_CON1, 0x0048); 282 + 283 + mt2712_rtc_write_trigger(mt2712_rtc); 284 + 285 + p1 = mt2712_readl(mt2712_rtc, MT2712_POWERKEY1); 286 + p2 = mt2712_readl(mt2712_rtc, MT2712_POWERKEY2); 287 + if (p1 != MT2712_POWERKEY1_KEY || p2 != MT2712_POWERKEY2_KEY) { 288 + mt2712_rtc->powerlost = true; 289 + dev_dbg(&mt2712_rtc->rtc->dev, 290 + "powerkey not set (lost power)\n"); 291 + } else { 292 + mt2712_rtc->powerlost = false; 293 + } 294 + 295 + /* RTC need POWERKEY1/2 match, then goto normal work mode */ 296 + mt2712_writel(mt2712_rtc, MT2712_POWERKEY1, MT2712_POWERKEY1_KEY); 297 + mt2712_writel(mt2712_rtc, MT2712_POWERKEY2, MT2712_POWERKEY2_KEY); 298 + mt2712_rtc_write_trigger(mt2712_rtc); 299 + 300 + mt2712_rtc_writeif_unlock(mt2712_rtc); 301 + } 302 + 303 + static const struct rtc_class_ops mt2712_rtc_ops = { 304 + .read_time = mt2712_rtc_read_time, 305 + .set_time = mt2712_rtc_set_time, 306 + .read_alarm = mt2712_rtc_read_alarm, 307 + .set_alarm = mt2712_rtc_set_alarm, 308 + .alarm_irq_enable = mt2712_rtc_alarm_irq_enable, 309 + }; 310 + 311 + static int mt2712_rtc_probe(struct platform_device *pdev) 312 + { 313 + struct resource *res; 314 + struct mt2712_rtc *mt2712_rtc; 315 + int ret; 316 + 317 + mt2712_rtc = devm_kzalloc(&pdev->dev, 318 + sizeof(struct mt2712_rtc), GFP_KERNEL); 319 + if (!mt2712_rtc) 320 + return -ENOMEM; 321 + 322 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 323 + mt2712_rtc->base = devm_ioremap_resource(&pdev->dev, res); 324 + if (IS_ERR(mt2712_rtc->base)) 325 + return PTR_ERR(mt2712_rtc->base); 326 + 327 + /* rtc hw init */ 328 + mt2712_rtc_hw_init(mt2712_rtc); 329 + 330 + mt2712_rtc->irq = platform_get_irq(pdev, 0); 331 + if (mt2712_rtc->irq < 0) { 332 + dev_err(&pdev->dev, "No IRQ resource\n"); 333 + return mt2712_rtc->irq; 334 + } 335 + 336 + platform_set_drvdata(pdev, mt2712_rtc); 337 + 338 + mt2712_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); 339 + if (IS_ERR(mt2712_rtc->rtc)) 340 + return PTR_ERR(mt2712_rtc->rtc); 341 + 342 + ret = devm_request_threaded_irq(&pdev->dev, mt2712_rtc->irq, NULL, 343 + rtc_irq_handler_thread, 344 + IRQF_ONESHOT | IRQF_TRIGGER_LOW, 345 + dev_name(&mt2712_rtc->rtc->dev), 346 + mt2712_rtc); 347 + if (ret) { 348 + dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 349 + mt2712_rtc->irq, ret); 350 + return ret; 351 + } 352 + 353 + device_init_wakeup(&pdev->dev, true); 354 + 355 + mt2712_rtc->rtc->ops = &mt2712_rtc_ops; 356 + mt2712_rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 357 + mt2712_rtc->rtc->range_max = MT2712_RTC_TIMESTAMP_END_2127; 358 + 359 + ret = rtc_register_device(mt2712_rtc->rtc); 360 + if (ret) { 361 + dev_err(&pdev->dev, "register rtc device failed\n"); 362 + return ret; 363 + } 364 + 365 + return 0; 366 + } 367 + 368 + #ifdef CONFIG_PM_SLEEP 369 + static int mt2712_rtc_suspend(struct device *dev) 370 + { 371 + int wake_status = 0; 372 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 373 + 374 + if (device_may_wakeup(dev)) { 375 + wake_status = enable_irq_wake(mt2712_rtc->irq); 376 + if (!wake_status) 377 + mt2712_rtc->irq_wake_enabled = true; 378 + } 379 + 380 + return 0; 381 + } 382 + 383 + static int mt2712_rtc_resume(struct device *dev) 384 + { 385 + int wake_status = 0; 386 + struct mt2712_rtc *mt2712_rtc = dev_get_drvdata(dev); 387 + 388 + if (device_may_wakeup(dev) && mt2712_rtc->irq_wake_enabled) { 389 + wake_status = disable_irq_wake(mt2712_rtc->irq); 390 + if (!wake_status) 391 + mt2712_rtc->irq_wake_enabled = false; 392 + } 393 + 394 + return 0; 395 + } 396 + 397 + static SIMPLE_DEV_PM_OPS(mt2712_pm_ops, mt2712_rtc_suspend, 398 + mt2712_rtc_resume); 399 + #endif 400 + 401 + static const struct of_device_id mt2712_rtc_of_match[] = { 402 + { .compatible = "mediatek,mt2712-rtc", }, 403 + { }, 404 + }; 405 + 406 + MODULE_DEVICE_TABLE(of, mt2712_rtc_of_match); 407 + 408 + static struct platform_driver mt2712_rtc_driver = { 409 + .driver = { 410 + .name = "mt2712-rtc", 411 + .of_match_table = mt2712_rtc_of_match, 412 + #ifdef CONFIG_PM_SLEEP 413 + .pm = &mt2712_pm_ops, 414 + #endif 415 + }, 416 + .probe = mt2712_rtc_probe, 417 + }; 418 + 419 + module_platform_driver(mt2712_rtc_driver); 420 + 421 + MODULE_DESCRIPTION("MediaTek MT2712 SoC based RTC Driver"); 422 + MODULE_AUTHOR("Ran Bi <ran.bi@mediatek.com>"); 423 + MODULE_LICENSE("GPL");
+19 -27
drivers/rtc/rtc-mxc.c
··· 307 307 .alarm_irq_enable = mxc_rtc_alarm_irq_enable, 308 308 }; 309 309 310 + static void mxc_rtc_action(void *p) 311 + { 312 + struct rtc_plat_data *pdata = p; 313 + 314 + clk_disable_unprepare(pdata->clk_ref); 315 + clk_disable_unprepare(pdata->clk_ipg); 316 + } 317 + 310 318 static int mxc_rtc_probe(struct platform_device *pdev) 311 319 { 312 320 struct rtc_device *rtc; ··· 374 366 375 367 pdata->clk_ref = devm_clk_get(&pdev->dev, "ref"); 376 368 if (IS_ERR(pdata->clk_ref)) { 369 + clk_disable_unprepare(pdata->clk_ipg); 377 370 dev_err(&pdev->dev, "unable to get ref clock!\n"); 378 - ret = PTR_ERR(pdata->clk_ref); 379 - goto exit_put_clk_ipg; 371 + return PTR_ERR(pdata->clk_ref); 380 372 } 381 373 382 374 ret = clk_prepare_enable(pdata->clk_ref); 375 + if (ret) { 376 + clk_disable_unprepare(pdata->clk_ipg); 377 + return ret; 378 + } 379 + 380 + ret = devm_add_action_or_reset(&pdev->dev, mxc_rtc_action, pdata); 383 381 if (ret) 384 - goto exit_put_clk_ipg; 382 + return ret; 385 383 386 384 rate = clk_get_rate(pdata->clk_ref); 387 385 ··· 399 385 reg = RTC_INPUT_CLK_38400HZ; 400 386 else { 401 387 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate); 402 - ret = -EINVAL; 403 - goto exit_put_clk_ref; 388 + return -EINVAL; 404 389 } 405 390 406 391 reg |= RTC_ENABLE_BIT; 407 392 writew(reg, (pdata->ioaddr + RTC_RTCCTL)); 408 393 if (((readw(pdata->ioaddr + RTC_RTCCTL)) & RTC_ENABLE_BIT) == 0) { 409 394 dev_err(&pdev->dev, "hardware module can't be enabled!\n"); 410 - ret = -EIO; 411 - goto exit_put_clk_ref; 395 + return -EIO; 412 396 } 413 397 414 398 platform_set_drvdata(pdev, pdata); ··· 429 417 } 430 418 431 419 ret = rtc_register_device(rtc); 432 - if (ret) 433 - goto exit_put_clk_ref; 434 - 435 - return 0; 436 - 437 - exit_put_clk_ref: 438 - clk_disable_unprepare(pdata->clk_ref); 439 - exit_put_clk_ipg: 440 - clk_disable_unprepare(pdata->clk_ipg); 441 420 442 421 return ret; 443 - } 444 - 445 - static int mxc_rtc_remove(struct platform_device *pdev) 446 - { 447 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 448 - 449 - clk_disable_unprepare(pdata->clk_ref); 450 - clk_disable_unprepare(pdata->clk_ipg); 451 - 452 - return 0; 453 422 } 454 423 455 424 static struct platform_driver mxc_rtc_driver = { ··· 440 447 }, 441 448 .id_table = imx_rtc_devtype, 442 449 .probe = mxc_rtc_probe, 443 - .remove = mxc_rtc_remove, 444 450 }; 445 451 446 452 module_platform_driver(mxc_rtc_driver)
-1
drivers/rtc/rtc-omap.c
··· 9 9 * Copyright (C) 2014 Johan Hovold <johan@kernel.org> 10 10 */ 11 11 12 - #include <dt-bindings/gpio/gpio.h> 13 12 #include <linux/bcd.h> 14 13 #include <linux/clk.h> 15 14 #include <linux/delay.h>
+157
drivers/rtc/rtc-pcf85063.c
··· 9 9 * Copyright (C) 2019 Micro Crystal AG 10 10 * Author: Alexandre Belloni <alexandre.belloni@bootlin.com> 11 11 */ 12 + #include <linux/clk-provider.h> 12 13 #include <linux/i2c.h> 13 14 #include <linux/bcd.h> 14 15 #include <linux/rtc.h> ··· 45 44 #define PCF85063_OFFSET_STEP0 4340 46 45 #define PCF85063_OFFSET_STEP1 4069 47 46 47 + #define PCF85063_REG_CLKO_F_MASK 0x07 /* frequency mask */ 48 + #define PCF85063_REG_CLKO_F_32768HZ 0x00 49 + #define PCF85063_REG_CLKO_F_OFF 0x07 50 + 48 51 #define PCF85063_REG_RAM 0x03 49 52 50 53 #define PCF85063_REG_SC 0x04 /* datetime */ ··· 66 61 struct pcf85063 { 67 62 struct rtc_device *rtc; 68 63 struct regmap *regmap; 64 + #ifdef CONFIG_COMMON_CLK 65 + struct clk_hw clkout_hw; 66 + #endif 69 67 }; 70 68 71 69 static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) ··· 365 357 PCF85063_REG_CTRL1_CAP_SEL, reg); 366 358 } 367 359 360 + #ifdef CONFIG_COMMON_CLK 361 + /* 362 + * Handling of the clkout 363 + */ 364 + 365 + #define clkout_hw_to_pcf85063(_hw) container_of(_hw, struct pcf85063, clkout_hw) 366 + 367 + static int clkout_rates[] = { 368 + 32768, 369 + 16384, 370 + 8192, 371 + 4096, 372 + 2048, 373 + 1024, 374 + 1, 375 + 0 376 + }; 377 + 378 + static unsigned long pcf85063_clkout_recalc_rate(struct clk_hw *hw, 379 + unsigned long parent_rate) 380 + { 381 + struct pcf85063 *pcf85063 = clkout_hw_to_pcf85063(hw); 382 + unsigned int buf; 383 + int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); 384 + 385 + if (ret < 0) 386 + return 0; 387 + 388 + buf &= PCF85063_REG_CLKO_F_MASK; 389 + return clkout_rates[buf]; 390 + } 391 + 392 + static long pcf85063_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 393 + unsigned long *prate) 394 + { 395 + int i; 396 + 397 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 398 + if (clkout_rates[i] <= rate) 399 + return clkout_rates[i]; 400 + 401 + return 0; 402 + } 403 + 404 + static int pcf85063_clkout_set_rate(struct clk_hw *hw, unsigned long rate, 405 + unsigned long parent_rate) 406 + { 407 + struct pcf85063 *pcf85063 = clkout_hw_to_pcf85063(hw); 408 + int i; 409 + 410 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 411 + if (clkout_rates[i] == rate) 412 + return regmap_update_bits(pcf85063->regmap, 413 + PCF85063_REG_CTRL2, 414 + PCF85063_REG_CLKO_F_MASK, i); 415 + 416 + return -EINVAL; 417 + } 418 + 419 + static int pcf85063_clkout_control(struct clk_hw *hw, bool enable) 420 + { 421 + struct pcf85063 *pcf85063 = clkout_hw_to_pcf85063(hw); 422 + unsigned int buf; 423 + int ret; 424 + 425 + ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &buf); 426 + if (ret < 0) 427 + return ret; 428 + buf &= PCF85063_REG_CLKO_F_MASK; 429 + 430 + if (enable) { 431 + if (buf == PCF85063_REG_CLKO_F_OFF) 432 + buf = PCF85063_REG_CLKO_F_32768HZ; 433 + else 434 + return 0; 435 + } else { 436 + if (buf != PCF85063_REG_CLKO_F_OFF) 437 + buf = PCF85063_REG_CLKO_F_OFF; 438 + else 439 + return 0; 440 + } 441 + 442 + return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2, 443 + PCF85063_REG_CLKO_F_MASK, buf); 444 + } 445 + 446 + static int pcf85063_clkout_prepare(struct clk_hw *hw) 447 + { 448 + return pcf85063_clkout_control(hw, 1); 449 + } 450 + 451 + static void pcf85063_clkout_unprepare(struct clk_hw *hw) 452 + { 453 + pcf85063_clkout_control(hw, 0); 454 + } 455 + 456 + static int pcf85063_clkout_is_prepared(struct clk_hw *hw) 457 + { 458 + struct pcf85063 *pcf85063 = clkout_hw_to_pcf85063(hw); 459 + unsigned int buf; 460 + int ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf); 461 + 462 + if (ret < 0) 463 + return 0; 464 + 465 + return (buf & PCF85063_REG_CLKO_F_MASK) != PCF85063_REG_CLKO_F_OFF; 466 + } 467 + 468 + static const struct clk_ops pcf85063_clkout_ops = { 469 + .prepare = pcf85063_clkout_prepare, 470 + .unprepare = pcf85063_clkout_unprepare, 471 + .is_prepared = pcf85063_clkout_is_prepared, 472 + .recalc_rate = pcf85063_clkout_recalc_rate, 473 + .round_rate = pcf85063_clkout_round_rate, 474 + .set_rate = pcf85063_clkout_set_rate, 475 + }; 476 + 477 + static struct clk *pcf85063_clkout_register_clk(struct pcf85063 *pcf85063) 478 + { 479 + struct clk *clk; 480 + struct clk_init_data init; 481 + 482 + init.name = "pcf85063-clkout"; 483 + init.ops = &pcf85063_clkout_ops; 484 + init.flags = 0; 485 + init.parent_names = NULL; 486 + init.num_parents = 0; 487 + pcf85063->clkout_hw.init = &init; 488 + 489 + /* optional override of the clockname */ 490 + of_property_read_string(pcf85063->rtc->dev.of_node, 491 + "clock-output-names", &init.name); 492 + 493 + /* register the clock */ 494 + clk = devm_clk_register(&pcf85063->rtc->dev, &pcf85063->clkout_hw); 495 + 496 + if (!IS_ERR(clk)) 497 + of_clk_add_provider(pcf85063->rtc->dev.of_node, 498 + of_clk_src_simple_get, clk); 499 + 500 + return clk; 501 + } 502 + #endif 503 + 368 504 static const struct pcf85063_config pcf85063a_config = { 369 505 .regmap = { 370 506 .reg_bits = 8, ··· 608 456 609 457 nvmem_cfg.priv = pcf85063->regmap; 610 458 rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg); 459 + 460 + #ifdef CONFIG_COMMON_CLK 461 + /* register clk in common clk framework */ 462 + pcf85063_clkout_register_clk(pcf85063); 463 + #endif 611 464 612 465 return rtc_register_device(pcf85063->rtc); 613 466 }
+8 -19
drivers/rtc/rtc-pl030.c
··· 36 36 { 37 37 struct pl030_rtc *rtc = dev_get_drvdata(dev); 38 38 39 - rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time); 39 + rtc_time64_to_tm(readl(rtc->base + RTC_MR), &alrm->time); 40 40 return 0; 41 41 } 42 42 43 43 static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 44 44 { 45 45 struct pl030_rtc *rtc = dev_get_drvdata(dev); 46 - unsigned long time; 47 - int ret; 48 46 49 - /* 50 - * At the moment, we can only deal with non-wildcarded alarm times. 51 - */ 52 - ret = rtc_valid_tm(&alrm->time); 53 - if (ret == 0) 54 - ret = rtc_tm_to_time(&alrm->time, &time); 55 - if (ret == 0) 56 - writel(time, rtc->base + RTC_MR); 57 - return ret; 47 + writel(rtc_tm_to_time64(&alrm->time), rtc->base + RTC_MR); 48 + 49 + return 0; 58 50 } 59 51 60 52 static int pl030_read_time(struct device *dev, struct rtc_time *tm) 61 53 { 62 54 struct pl030_rtc *rtc = dev_get_drvdata(dev); 63 55 64 - rtc_time_to_tm(readl(rtc->base + RTC_DR), tm); 56 + rtc_time64_to_tm(readl(rtc->base + RTC_DR), tm); 65 57 66 58 return 0; 67 59 } ··· 69 77 static int pl030_set_time(struct device *dev, struct rtc_time *tm) 70 78 { 71 79 struct pl030_rtc *rtc = dev_get_drvdata(dev); 72 - unsigned long time; 73 - int ret; 74 80 75 - ret = rtc_tm_to_time(tm, &time); 76 - if (ret == 0) 77 - writel(time + 1, rtc->base + RTC_LR); 81 + writel(rtc_tm_to_time64(tm) + 1, rtc->base + RTC_LR); 78 82 79 - return ret; 83 + return 0; 80 84 } 81 85 82 86 static const struct rtc_class_ops pl030_ops = { ··· 104 116 } 105 117 106 118 rtc->rtc->ops = &pl030_ops; 119 + rtc->rtc->range_max = U32_MAX; 107 120 rtc->base = ioremap(dev->res.start, resource_size(&dev->res)); 108 121 if (!rtc->base) { 109 122 ret = -ENOMEM;
+20 -33
drivers/rtc/rtc-pl031.c
··· 80 80 bool clockwatch; 81 81 bool st_weekday; 82 82 unsigned long irqflags; 83 + time64_t range_min; 84 + timeu64_t range_max; 83 85 }; 84 86 85 87 struct pl031_local { ··· 125 123 return -EINVAL; 126 124 } else if (wday == -1) { 127 125 /* wday is not provided, calculate it here */ 128 - unsigned long time; 129 126 struct rtc_time calc_tm; 130 127 131 - rtc_tm_to_time(tm, &time); 132 - rtc_time_to_tm(time, &calc_tm); 128 + rtc_time64_to_tm(rtc_tm_to_time64(tm), &calc_tm); 133 129 wday = calc_tm.tm_wday; 134 130 } 135 131 ··· 210 210 unsigned long bcd_year; 211 211 int ret; 212 212 213 - /* At the moment, we can only deal with non-wildcarded alarm times. */ 214 - ret = rtc_valid_tm(&alarm->time); 213 + ret = pl031_stv2_tm_to_time(dev, &alarm->time, 214 + &time, &bcd_year); 215 215 if (ret == 0) { 216 - ret = pl031_stv2_tm_to_time(dev, &alarm->time, 217 - &time, &bcd_year); 218 - if (ret == 0) { 219 - writel(bcd_year, ldata->base + RTC_YMR); 220 - writel(time, ldata->base + RTC_MR); 216 + writel(bcd_year, ldata->base + RTC_YMR); 217 + writel(time, ldata->base + RTC_MR); 221 218 222 - pl031_alarm_irq_enable(dev, alarm->enabled); 223 - } 219 + pl031_alarm_irq_enable(dev, alarm->enabled); 224 220 } 225 221 226 222 return ret; ··· 244 248 { 245 249 struct pl031_local *ldata = dev_get_drvdata(dev); 246 250 247 - rtc_time_to_tm(readl(ldata->base + RTC_DR), tm); 251 + rtc_time64_to_tm(readl(ldata->base + RTC_DR), tm); 248 252 249 253 return 0; 250 254 } 251 255 252 256 static int pl031_set_time(struct device *dev, struct rtc_time *tm) 253 257 { 254 - unsigned long time; 255 258 struct pl031_local *ldata = dev_get_drvdata(dev); 256 - int ret; 257 259 258 - ret = rtc_tm_to_time(tm, &time); 260 + writel(rtc_tm_to_time64(tm), ldata->base + RTC_LR); 259 261 260 - if (ret == 0) 261 - writel(time, ldata->base + RTC_LR); 262 - 263 - return ret; 262 + return 0; 264 263 } 265 264 266 265 static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 267 266 { 268 267 struct pl031_local *ldata = dev_get_drvdata(dev); 269 268 270 - rtc_time_to_tm(readl(ldata->base + RTC_MR), &alarm->time); 269 + rtc_time64_to_tm(readl(ldata->base + RTC_MR), &alarm->time); 271 270 272 271 alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI; 273 272 alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI; ··· 273 282 static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 274 283 { 275 284 struct pl031_local *ldata = dev_get_drvdata(dev); 276 - unsigned long time; 277 - int ret; 278 285 279 - /* At the moment, we can only deal with non-wildcarded alarm times. */ 280 - ret = rtc_valid_tm(&alarm->time); 281 - if (ret == 0) { 282 - ret = rtc_tm_to_time(&alarm->time, &time); 283 - if (ret == 0) { 284 - writel(time, ldata->base + RTC_MR); 285 - pl031_alarm_irq_enable(dev, alarm->enabled); 286 - } 287 - } 286 + writel(rtc_tm_to_time64(&alarm->time), ldata->base + RTC_MR); 288 287 289 - return ret; 288 + return 0; 290 289 } 291 290 292 291 static int pl031_remove(struct amba_device *adev) ··· 364 383 return PTR_ERR(ldata->rtc); 365 384 366 385 ldata->rtc->ops = ops; 386 + ldata->rtc->range_min = vendor->range_min; 387 + ldata->rtc->range_max = vendor->range_max; 367 388 368 389 ret = rtc_register_device(ldata->rtc); 369 390 if (ret) ··· 396 413 .set_alarm = pl031_set_alarm, 397 414 .alarm_irq_enable = pl031_alarm_irq_enable, 398 415 }, 416 + .range_max = U32_MAX, 399 417 }; 400 418 401 419 /* The First ST derivative */ ··· 410 426 }, 411 427 .clockwatch = true, 412 428 .st_weekday = true, 429 + .range_max = U32_MAX, 413 430 }; 414 431 415 432 /* And the second ST derivative */ ··· 431 446 * remove IRQF_COND_SUSPEND 432 447 */ 433 448 .irqflags = IRQF_SHARED | IRQF_COND_SUSPEND, 449 + .range_min = RTC_TIMESTAMP_BEGIN_0000, 450 + .range_max = RTC_TIMESTAMP_END_9999, 434 451 }; 435 452 436 453 static const struct amba_id pl031_ids[] = {
+21 -19
drivers/rtc/rtc-pm8xxx.c
··· 84 84 if (!rtc_dd->allow_set_time) 85 85 return -EACCES; 86 86 87 - rtc_tm_to_time(tm, &secs); 87 + secs = rtc_tm_to_time64(tm); 88 88 89 89 dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs); 90 90 ··· 208 208 secs = value[0] | (value[1] << 8) | (value[2] << 16) | 209 209 ((unsigned long)value[3] << 24); 210 210 211 - rtc_time_to_tm(secs, tm); 211 + rtc_time64_to_tm(secs, tm); 212 212 213 213 dev_dbg(dev, "secs = %lu, h:m:s == %ptRt, y-m-d = %ptRdr\n", secs, tm, tm); 214 214 ··· 224 224 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); 225 225 const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; 226 226 227 - rtc_tm_to_time(&alarm->time, &secs); 227 + secs = rtc_tm_to_time64(&alarm->time); 228 228 229 229 for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) { 230 230 value[i] = secs & 0xFF; ··· 280 280 secs = value[0] | (value[1] << 8) | (value[2] << 16) | 281 281 ((unsigned long)value[3] << 24); 282 282 283 - rtc_time_to_tm(secs, &alarm->time); 284 - 285 - rc = rtc_valid_tm(&alarm->time); 286 - if (rc < 0) { 287 - dev_err(dev, "Invalid alarm time read from RTC\n"); 288 - return rc; 289 - } 283 + rtc_time64_to_tm(secs, &alarm->time); 290 284 291 285 dev_dbg(dev, "Alarm set for - h:m:s=%ptRt, y-m-d=%ptRdr\n", 292 286 &alarm->time, &alarm->time); ··· 295 301 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); 296 302 const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; 297 303 unsigned int ctrl_reg; 304 + u8 value[NUM_8_BIT_RTC_REGS] = {0}; 298 305 299 306 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); 300 307 ··· 312 317 if (rc) { 313 318 dev_err(dev, "Write to RTC control register failed\n"); 314 319 goto rtc_rw_fail; 320 + } 321 + 322 + /* Clear Alarm register */ 323 + if (!enable) { 324 + rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, 325 + sizeof(value)); 326 + if (rc) { 327 + dev_err(dev, "Clear RTC ALARM register failed\n"); 328 + goto rtc_rw_fail; 329 + } 315 330 } 316 331 317 332 rtc_rw_fail: ··· 491 486 device_init_wakeup(&pdev->dev, 1); 492 487 493 488 /* Register the RTC device */ 494 - rtc_dd->rtc = devm_rtc_device_register(&pdev->dev, "pm8xxx_rtc", 495 - &pm8xxx_rtc_ops, THIS_MODULE); 496 - if (IS_ERR(rtc_dd->rtc)) { 497 - dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n", 498 - __func__, PTR_ERR(rtc_dd->rtc)); 489 + rtc_dd->rtc = devm_rtc_allocate_device(&pdev->dev); 490 + if (IS_ERR(rtc_dd->rtc)) 499 491 return PTR_ERR(rtc_dd->rtc); 500 - } 492 + 493 + rtc_dd->rtc->ops = &pm8xxx_rtc_ops; 494 + rtc_dd->rtc->range_max = U32_MAX; 501 495 502 496 /* Request the alarm IRQ */ 503 497 rc = devm_request_any_context_irq(&pdev->dev, rtc_dd->rtc_alarm_irq, ··· 508 504 return rc; 509 505 } 510 506 511 - dev_dbg(&pdev->dev, "Probe success !!\n"); 512 - 513 - return 0; 507 + return rtc_register_device(rtc_dd->rtc); 514 508 } 515 509 516 510 #ifdef CONFIG_PM_SLEEP
+5 -9
drivers/rtc/rtc-puv3.c
··· 85 85 /* Time read/write */ 86 86 static int puv3_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) 87 87 { 88 - rtc_time_to_tm(readl(RTC_RCNR), rtc_tm); 88 + rtc_time64_to_tm(readl(RTC_RCNR), rtc_tm); 89 89 90 90 dev_dbg(dev, "read time %ptRr\n", rtc_tm); 91 91 ··· 94 94 95 95 static int puv3_rtc_settime(struct device *dev, struct rtc_time *tm) 96 96 { 97 - unsigned long rtc_count = 0; 98 - 99 97 dev_dbg(dev, "set time %ptRr\n", tm); 100 98 101 - rtc_tm_to_time(tm, &rtc_count); 102 - writel(rtc_count, RTC_RCNR); 99 + writel(rtc_tm_to_time64(tm), RTC_RCNR); 103 100 104 101 return 0; 105 102 } ··· 105 108 { 106 109 struct rtc_time *alm_tm = &alrm->time; 107 110 108 - rtc_time_to_tm(readl(RTC_RTAR), alm_tm); 111 + rtc_time64_to_tm(readl(RTC_RTAR), alm_tm); 109 112 110 113 alrm->enabled = readl(RTC_RTSR) & RTC_RTSR_ALE; 111 114 ··· 117 120 static int puv3_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 118 121 { 119 122 struct rtc_time *tm = &alrm->time; 120 - unsigned long rtcalarm_count = 0; 121 123 122 124 dev_dbg(dev, "set alarm: %d, %ptRr\n", alrm->enabled, tm); 123 125 124 - rtc_tm_to_time(tm, &rtcalarm_count); 125 - writel(rtcalarm_count, RTC_RTAR); 126 + writel(rtc_tm_to_time64(tm), RTC_RTAR); 126 127 127 128 puv3_rtc_setaie(dev, alrm->enabled); 128 129 ··· 229 234 230 235 /* register RTC and exit */ 231 236 rtc->ops = &puv3_rtcops; 237 + rtc->range_max = U32_MAX; 232 238 ret = rtc_register_device(rtc); 233 239 if (ret) 234 240 goto err_nortc;
+18 -24
drivers/rtc/rtc-sa1100.c
··· 111 111 { 112 112 struct sa1100_rtc *info = dev_get_drvdata(dev); 113 113 114 - rtc_time_to_tm(readl_relaxed(info->rcnr), tm); 114 + rtc_time64_to_tm(readl_relaxed(info->rcnr), tm); 115 115 return 0; 116 116 } 117 117 118 118 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm) 119 119 { 120 120 struct sa1100_rtc *info = dev_get_drvdata(dev); 121 - unsigned long time; 122 - int ret; 123 121 124 - ret = rtc_tm_to_time(tm, &time); 125 - if (ret == 0) 126 - writel_relaxed(time, info->rcnr); 127 - return ret; 122 + writel_relaxed(rtc_tm_to_time64(tm), info->rcnr); 123 + 124 + return 0; 128 125 } 129 126 130 127 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ··· 138 141 static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 139 142 { 140 143 struct sa1100_rtc *info = dev_get_drvdata(dev); 141 - unsigned long time; 142 - int ret; 143 144 144 145 spin_lock_irq(&info->lock); 145 - ret = rtc_tm_to_time(&alrm->time, &time); 146 - if (ret != 0) 147 - goto out; 148 146 writel_relaxed(readl_relaxed(info->rtsr) & 149 147 (RTSR_HZE | RTSR_ALE | RTSR_AL), info->rtsr); 150 - writel_relaxed(time, info->rtar); 148 + writel_relaxed(rtc_tm_to_time64(&alrm->time), info->rtar); 151 149 if (alrm->enabled) 152 150 writel_relaxed(readl_relaxed(info->rtsr) | RTSR_ALE, info->rtsr); 153 151 else 154 152 writel_relaxed(readl_relaxed(info->rtsr) & ~RTSR_ALE, info->rtsr); 155 - out: 156 153 spin_unlock_irq(&info->lock); 157 154 158 - return ret; 155 + return 0; 159 156 } 160 157 161 158 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) ··· 173 182 174 183 int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) 175 184 { 176 - struct rtc_device *rtc; 177 185 int ret; 178 186 179 187 spin_lock_init(&info->lock); ··· 201 211 writel_relaxed(0, info->rcnr); 202 212 } 203 213 204 - rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, 205 - THIS_MODULE); 206 - if (IS_ERR(rtc)) { 207 - clk_disable_unprepare(info->clk); 208 - return PTR_ERR(rtc); 209 - } 210 - info->rtc = rtc; 214 + info->rtc->ops = &sa1100_rtc_ops; 215 + info->rtc->max_user_freq = RTC_FREQ; 216 + info->rtc->range_max = U32_MAX; 211 217 212 - rtc->max_user_freq = RTC_FREQ; 218 + ret = rtc_register_device(info->rtc); 219 + if (ret) { 220 + clk_disable_unprepare(info->clk); 221 + return ret; 222 + } 213 223 214 224 /* Fix for a nasty initialization problem the in SA11xx RTSR register. 215 225 * See also the comments in sa1100_rtc_interrupt(). ··· 256 266 return -ENOMEM; 257 267 info->irq_1hz = irq_1hz; 258 268 info->irq_alarm = irq_alarm; 269 + 270 + info->rtc = devm_rtc_allocate_device(&pdev->dev); 271 + if (IS_ERR(info->rtc)) 272 + return PTR_ERR(info->rtc); 259 273 260 274 ret = devm_request_irq(&pdev->dev, irq_1hz, sa1100_rtc_interrupt, 0, 261 275 "rtc 1Hz", &pdev->dev);
+1 -2
drivers/rtc/rtc-sh.c
··· 504 504 if (unlikely(!rtc->res)) 505 505 return -EBUSY; 506 506 507 - rtc->regbase = devm_ioremap(&pdev->dev, rtc->res->start, 508 - rtc->regsize); 507 + rtc->regbase = devm_ioremap(&pdev->dev, rtc->res->start, rtc->regsize); 509 508 if (unlikely(!rtc->regbase)) 510 509 return -EINVAL; 511 510
+19 -25
drivers/rtc/rtc-sirfsoc.c
··· 90 90 */ 91 91 /* if alarm is in next overflow cycle */ 92 92 if (rtc_count > rtc_alarm) 93 - rtc_time_to_tm((rtcdrv->overflow_rtc + 1) 94 - << (BITS_PER_LONG - RTC_SHIFT) 95 - | rtc_alarm >> RTC_SHIFT, &(alrm->time)); 93 + rtc_time64_to_tm((rtcdrv->overflow_rtc + 1) 94 + << (BITS_PER_LONG - RTC_SHIFT) 95 + | rtc_alarm >> RTC_SHIFT, &alrm->time); 96 96 else 97 - rtc_time_to_tm(rtcdrv->overflow_rtc 98 - << (BITS_PER_LONG - RTC_SHIFT) 99 - | rtc_alarm >> RTC_SHIFT, &(alrm->time)); 97 + rtc_time64_to_tm(rtcdrv->overflow_rtc 98 + << (BITS_PER_LONG - RTC_SHIFT) 99 + | rtc_alarm >> RTC_SHIFT, &alrm->time); 100 100 if (sirfsoc_rtc_readl(rtcdrv, RTC_STATUS) & SIRFSOC_RTC_AL0E) 101 101 alrm->enabled = 1; 102 102 ··· 113 113 rtcdrv = dev_get_drvdata(dev); 114 114 115 115 if (alrm->enabled) { 116 - rtc_tm_to_time(&(alrm->time), &rtc_alarm); 116 + rtc_alarm = rtc_tm_to_time64(&alrm->time); 117 117 118 118 spin_lock_irq(&rtcdrv->lock); 119 119 ··· 181 181 cpu_relax(); 182 182 } while (tmp_rtc != sirfsoc_rtc_readl(rtcdrv, RTC_CN)); 183 183 184 - rtc_time_to_tm(rtcdrv->overflow_rtc << (BITS_PER_LONG - RTC_SHIFT) | 185 - tmp_rtc >> RTC_SHIFT, tm); 184 + rtc_time64_to_tm(rtcdrv->overflow_rtc << (BITS_PER_LONG - RTC_SHIFT) 185 + | tmp_rtc >> RTC_SHIFT, tm); 186 186 return 0; 187 187 } 188 188 ··· 193 193 struct sirfsoc_rtc_drv *rtcdrv; 194 194 rtcdrv = dev_get_drvdata(dev); 195 195 196 - rtc_tm_to_time(tm, &rtc_time); 196 + rtc_time = rtc_tm_to_time64(tm); 197 197 198 198 rtcdrv->overflow_rtc = rtc_time >> (BITS_PER_LONG - RTC_SHIFT); 199 199 ··· 341 341 rtcdrv->overflow_rtc = 342 342 sirfsoc_rtc_readl(rtcdrv, RTC_SW_VALUE); 343 343 344 - rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 345 - &sirfsoc_rtc_ops, THIS_MODULE); 346 - if (IS_ERR(rtcdrv->rtc)) { 347 - err = PTR_ERR(rtcdrv->rtc); 348 - dev_err(&pdev->dev, "can't register RTC device\n"); 349 - return err; 350 - } 344 + rtcdrv->rtc = devm_rtc_allocate_device(&pdev->dev); 345 + if (IS_ERR(rtcdrv->rtc)) 346 + return PTR_ERR(rtcdrv->rtc); 347 + 348 + rtcdrv->rtc->ops = &sirfsoc_rtc_ops; 349 + rtcdrv->rtc->range_max = (1ULL << 60) - 1; 351 350 352 351 rtcdrv->irq = platform_get_irq(pdev, 0); 353 - err = devm_request_irq( 354 - &pdev->dev, 355 - rtcdrv->irq, 356 - sirfsoc_rtc_irq_handler, 357 - IRQF_SHARED, 358 - pdev->name, 359 - rtcdrv); 352 + err = devm_request_irq(&pdev->dev, rtcdrv->irq, sirfsoc_rtc_irq_handler, 353 + IRQF_SHARED, pdev->name, rtcdrv); 360 354 if (err) { 361 355 dev_err(&pdev->dev, "Unable to register for the SiRF SOC RTC IRQ\n"); 362 356 return err; 363 357 } 364 358 365 - return 0; 359 + return rtc_register_device(rtcdrv->rtc); 366 360 } 367 361 368 362 #ifdef CONFIG_PM_SLEEP
+13 -15
drivers/rtc/rtc-snvs.c
··· 7 7 #include <linux/kernel.h> 8 8 #include <linux/module.h> 9 9 #include <linux/of.h> 10 - #include <linux/of_device.h> 11 10 #include <linux/platform_device.h> 12 11 #include <linux/pm_wakeirq.h> 13 12 #include <linux/rtc.h> ··· 263 264 .reg_stride = 4, 264 265 }; 265 266 267 + static void snvs_rtc_action(void *data) 268 + { 269 + if (data) 270 + clk_disable_unprepare(data); 271 + } 272 + 266 273 static int snvs_rtc_probe(struct platform_device *pdev) 267 274 { 268 275 struct snvs_rtc_data *data; ··· 319 314 } 320 315 } 321 316 317 + ret = devm_add_action_or_reset(&pdev->dev, snvs_rtc_action, data->clk); 318 + if (ret) 319 + return ret; 320 + 322 321 platform_set_drvdata(pdev, data); 323 322 324 323 /* Initialize glitch detect */ ··· 335 326 ret = snvs_rtc_enable(data, true); 336 327 if (ret) { 337 328 dev_err(&pdev->dev, "failed to enable rtc %d\n", ret); 338 - goto error_rtc_device_register; 329 + return ret; 339 330 } 340 331 341 332 device_init_wakeup(&pdev->dev, true); ··· 348 339 if (ret) { 349 340 dev_err(&pdev->dev, "failed to request irq %d: %d\n", 350 341 data->irq, ret); 351 - goto error_rtc_device_register; 342 + return ret; 352 343 } 353 344 354 345 data->rtc->ops = &snvs_rtc_ops; 355 346 data->rtc->range_max = U32_MAX; 356 - ret = rtc_register_device(data->rtc); 357 - if (ret) { 358 - dev_err(&pdev->dev, "failed to register rtc: %d\n", ret); 359 - goto error_rtc_device_register; 360 - } 361 347 362 - return 0; 363 - 364 - error_rtc_device_register: 365 - if (data->clk) 366 - clk_disable_unprepare(data->clk); 367 - 368 - return ret; 348 + return rtc_register_device(data->rtc); 369 349 } 370 350 371 351 static int __maybe_unused snvs_rtc_suspend_noirq(struct device *dev)
+6 -4
drivers/rtc/rtc-starfire.c
··· 27 27 28 28 static int starfire_read_time(struct device *dev, struct rtc_time *tm) 29 29 { 30 - rtc_time_to_tm(starfire_get_time(), tm); 30 + rtc_time64_to_tm(starfire_get_time(), tm); 31 31 return 0; 32 32 } 33 33 ··· 39 39 { 40 40 struct rtc_device *rtc; 41 41 42 - rtc = devm_rtc_device_register(&pdev->dev, "starfire", 43 - &starfire_rtc_ops, THIS_MODULE); 42 + rtc = devm_rtc_allocate_device(&pdev->dev); 44 43 if (IS_ERR(rtc)) 45 44 return PTR_ERR(rtc); 46 45 46 + rtc->ops = &starfire_rtc_ops; 47 + rtc->range_max = U32_MAX; 48 + 47 49 platform_set_drvdata(pdev, rtc); 48 50 49 - return 0; 51 + return rtc_register_device(rtc); 50 52 } 51 53 52 54 static struct platform_driver starfire_rtc_driver = {
+21 -26
drivers/rtc/rtc-sun6i.c
··· 108 108 * driver, even though it is somewhat limited. 109 109 */ 110 110 #define SUN6I_YEAR_MIN 1970 111 - #define SUN6I_YEAR_MAX 2033 112 111 #define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900) 113 112 114 113 /* ··· 249 250 writel(reg, rtc->base + SUN6I_LOSC_CTRL); 250 251 } 251 252 252 - /* Switch to the external, more precise, oscillator */ 253 - reg |= SUN6I_LOSC_CTRL_EXT_OSC; 254 - if (rtc->data->has_losc_en) 255 - reg |= SUN6I_LOSC_CTRL_EXT_LOSC_EN; 253 + /* Switch to the external, more precise, oscillator, if present */ 254 + if (of_get_property(node, "clocks", NULL)) { 255 + reg |= SUN6I_LOSC_CTRL_EXT_OSC; 256 + if (rtc->data->has_losc_en) 257 + reg |= SUN6I_LOSC_CTRL_EXT_LOSC_EN; 258 + } 256 259 writel(reg, rtc->base + SUN6I_LOSC_CTRL); 257 260 258 261 /* Yes, I know, this is ugly. */ 259 262 sun6i_rtc = rtc; 260 - 261 - /* Deal with old DTs */ 262 - if (!of_get_property(node, "clocks", NULL)) 263 - goto err; 264 263 265 264 /* Only read IOSC name from device tree if it is exported */ 266 265 if (rtc->data->export_iosc) ··· 276 279 } 277 280 278 281 parents[0] = clk_hw_get_name(rtc->int_osc); 282 + /* If there is no external oscillator, this will be NULL and ... */ 279 283 parents[1] = of_clk_get_parent_name(node, 0); 280 284 281 285 rtc->hw.init = &init; 282 286 283 287 init.parent_names = parents; 288 + /* ... number of clock parents will be 1. */ 284 289 init.num_parents = of_clk_get_parent_count(node) + 1; 285 290 of_property_read_string_index(node, "clock-output-names", 0, 286 291 &init.name); ··· 498 499 499 500 wkalrm->enabled = !!(alrm_en & SUN6I_ALRM_EN_CNT_EN); 500 501 wkalrm->pending = !!(alrm_st & SUN6I_ALRM_EN_CNT_EN); 501 - rtc_time_to_tm(chip->alarm, &wkalrm->time); 502 + rtc_time64_to_tm(chip->alarm, &wkalrm->time); 502 503 503 504 return 0; 504 505 } ··· 519 520 return -EINVAL; 520 521 } 521 522 522 - rtc_tm_to_time(alrm_tm, &time_set); 523 - rtc_tm_to_time(&tm_now, &time_now); 523 + time_set = rtc_tm_to_time64(alrm_tm); 524 + time_now = rtc_tm_to_time64(&tm_now); 524 525 if (time_set <= time_now) { 525 526 dev_err(dev, "Date to set in the past\n"); 526 527 return -EINVAL; ··· 568 569 struct sun6i_rtc_dev *chip = dev_get_drvdata(dev); 569 570 u32 date = 0; 570 571 u32 time = 0; 571 - int year; 572 - 573 - year = rtc_tm->tm_year + 1900; 574 - if (year < SUN6I_YEAR_MIN || year > SUN6I_YEAR_MAX) { 575 - dev_err(dev, "rtc only supports year in range %d - %d\n", 576 - SUN6I_YEAR_MIN, SUN6I_YEAR_MAX); 577 - return -EINVAL; 578 - } 579 572 580 573 rtc_tm->tm_year -= SUN6I_YEAR_OFF; 581 574 rtc_tm->tm_mon += 1; ··· 576 585 SUN6I_DATE_SET_MON_VALUE(rtc_tm->tm_mon) | 577 586 SUN6I_DATE_SET_YEAR_VALUE(rtc_tm->tm_year); 578 587 579 - if (is_leap_year(year)) 588 + if (is_leap_year(rtc_tm->tm_year + SUN6I_YEAR_MIN)) 580 589 date |= SUN6I_LEAP_SET_VALUE(1); 581 590 582 591 time = SUN6I_TIME_SET_SEC_VALUE(rtc_tm->tm_sec) | ··· 717 726 718 727 device_init_wakeup(&pdev->dev, 1); 719 728 720 - chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i", 721 - &sun6i_rtc_ops, THIS_MODULE); 722 - if (IS_ERR(chip->rtc)) { 723 - dev_err(&pdev->dev, "unable to register device\n"); 729 + chip->rtc = devm_rtc_allocate_device(&pdev->dev); 730 + if (IS_ERR(chip->rtc)) 724 731 return PTR_ERR(chip->rtc); 725 - } 732 + 733 + chip->rtc->ops = &sun6i_rtc_ops; 734 + chip->rtc->range_max = 2019686399LL; /* 2033-12-31 23:59:59 */ 735 + 736 + ret = rtc_register_device(chip->rtc); 737 + if (ret) 738 + return ret; 726 739 727 740 dev_info(&pdev->dev, "RTC enabled\n"); 728 741
+23 -4
drivers/rtc/rtc-zynqmp.c
··· 38 38 39 39 #define RTC_CALIB_DEF 0x198233 40 40 #define RTC_CALIB_MASK 0x1FFFFF 41 + #define RTC_ALRM_MASK BIT(1) 42 + #define RTC_MSEC 1000 41 43 42 44 struct xlnx_rtc_dev { 43 45 struct rtc_device *rtc; ··· 125 123 static int xlnx_rtc_alarm_irq_enable(struct device *dev, u32 enabled) 126 124 { 127 125 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 126 + unsigned int status; 127 + ulong timeout; 128 128 129 - if (enabled) 129 + timeout = jiffies + msecs_to_jiffies(RTC_MSEC); 130 + 131 + if (enabled) { 132 + while (1) { 133 + status = readl(xrtcdev->reg_base + RTC_INT_STS); 134 + if (!((status & RTC_ALRM_MASK) == RTC_ALRM_MASK)) 135 + break; 136 + 137 + if (time_after_eq(jiffies, timeout)) { 138 + dev_err(dev, "Time out occur, while clearing alarm status bit\n"); 139 + return -ETIMEDOUT; 140 + } 141 + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS); 142 + } 143 + 130 144 writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_EN); 131 - else 145 + } else { 132 146 writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); 147 + } 133 148 134 149 return 0; 135 150 } ··· 202 183 if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) 203 184 return IRQ_NONE; 204 185 205 - /* Clear RTC_INT_ALRM interrupt only */ 206 - writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS); 186 + /* Disable RTC_INT_ALRM interrupt only */ 187 + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); 207 188 208 189 if (status & RTC_INT_ALRM) 209 190 rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF);
+1 -1
drivers/rtc/sysfs.c
··· 279 279 static umode_t rtc_attr_is_visible(struct kobject *kobj, 280 280 struct attribute *attr, int n) 281 281 { 282 - struct device *dev = container_of(kobj, struct device, kobj); 282 + struct device *dev = kobj_to_dev(kobj); 283 283 struct rtc_device *rtc = to_rtc_device(dev); 284 284 umode_t mode = attr->mode; 285 285
-12
include/linux/rtc.h
··· 34 34 return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs); 35 35 } 36 36 37 - static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) 38 - { 39 - rtc_time64_to_tm(time, tm); 40 - } 41 - 42 - static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) 43 - { 44 - *time = rtc_tm_to_time64(tm); 45 - 46 - return 0; 47 - } 48 - 49 37 #include <linux/device.h> 50 38 #include <linux/seq_file.h> 51 39 #include <linux/cdev.h>
+7 -4
include/uapi/linux/rtc.h
··· 12 12 #ifndef _UAPI_LINUX_RTC_H_ 13 13 #define _UAPI_LINUX_RTC_H_ 14 14 15 + #include <linux/const.h> 16 + #include <linux/ioctl.h> 17 + 15 18 /* 16 19 * The struct used to pass data via the following ioctl. Similar to the 17 20 * struct tm in <time.h>, but it needs to be here so that the kernel ··· 95 92 #define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ 96 93 #define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */ 97 94 98 - #define RTC_VL_DATA_INVALID BIT(0) /* Voltage too low, RTC data is invalid */ 99 - #define RTC_VL_BACKUP_LOW BIT(1) /* Backup voltage is low */ 100 - #define RTC_VL_BACKUP_EMPTY BIT(2) /* Backup empty or not present */ 101 - #define RTC_VL_ACCURACY_LOW BIT(3) /* Voltage is low, RTC accuracy is reduced */ 95 + #define RTC_VL_DATA_INVALID _BITUL(0) /* Voltage too low, RTC data is invalid */ 96 + #define RTC_VL_BACKUP_LOW _BITUL(1) /* Backup voltage is low */ 97 + #define RTC_VL_BACKUP_EMPTY _BITUL(2) /* Backup empty or not present */ 98 + #define RTC_VL_ACCURACY_LOW _BITUL(3) /* Voltage is low, RTC accuracy is reduced */ 102 99 103 100 #define RTC_VL_READ _IOR('p', 0x13, unsigned int) /* Voltage low detection */ 104 101 #define RTC_VL_CLR _IO('p', 0x14) /* Clear voltage low information */