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

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

Pull RTC updates from Alexandre Belloni:
"This cycle, there were mostly non urgent fixes in drivers. I also
finally unexported the non managed registration.

Subsystem:

- non devm managed registration is now removed from the driver API

- all the unnecessary rtc_valid_tm() calls have been removed

Drivers:

- abx80X: watchdog support

- cmos: fix non ACPI support

- sc27xx: fix alarm support

- Remove a possible sysfs race condition for ab8500, ds1307, ds1685,
isl1208

- Fix a possible race condition where an irq handler may be called
before the rtc_device struct is allocated for mt6397, pl030,
menelaus, armada38x"

* tag 'rtc-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (54 commits)
rtc: sc27xx: Always read normal alarm when registering RTC device
rtc: sc27xx: Add check to see if need to enable the alarm interrupt
rtc: sc27xx: Remove interrupts disable and clear in probe()
rtc: sc27xx: Clear SPG value update interrupt status
rtc: sc27xx: Set wakeup capability before registering rtc device
rtc: s35390a: Change buf's type to u8 in s35390a_init
rtc: ds1307: fix ds1339 wakealarm support
rtc: ds1685: simplify getting .driver_data
rtc: m41t80: mark expected switch fall-through
rtc: tegra: Propagate errors from platform_get_irq()
rtc: cmos: Remove the `use_acpi_alarm' module parameter for !ACPI
rtc: cmos: Fix non-ACPI undefined reference to `hpet_rtc_interrupt'
rtc: mv: let the core handle invalid alarms
rtc: vr41xx: switch to rtc_time64_to_tm/rtc_tm_to_time64
rtc: ab8500: remove useless check
rtc: ab8500: let the core handle range
rtc: ab8500: use rtc_add_group
rtc: rs5c348: report error when time is invalid
rtc: rs5c348: remove forward declaration
rtc: rs5c348: remove useless label
...

+547 -482
+1 -1
arch/mips/Kconfig
··· 75 75 select MODULES_USE_ELF_RELA if MODULES && 64BIT 76 76 select MODULES_USE_ELF_REL if MODULES 77 77 select PERF_USE_VMALLOC 78 - select RTC_LIB if !MACH_LOONGSON64 78 + select RTC_LIB 79 79 select SYSCTL_EXCEPTION_TRACE 80 80 select VIRT_TO_BUS 81 81 select NO_BOOTMEM
+1 -1
drivers/char/Kconfig
··· 268 268 269 269 config RTC 270 270 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)" 271 - depends on ALPHA || (MIPS && MACH_LOONGSON64) 271 + depends on ALPHA 272 272 ---help--- 273 273 If you say Y here and create a character special file /dev/rtc with 274 274 major number 10 and minor number 135 using mknod ("man mknod"), you
+2 -12
drivers/rtc/Kconfig
··· 187 187 188 188 config RTC_DRV_ABX80X 189 189 tristate "Abracon ABx80x" 190 + select WATCHDOG_CORE if WATCHDOG 190 191 help 191 192 If you say yes here you get support for Abracon AB080X and AB180X 192 193 families of ultra-low-power battery- and capacitor-backed real-time ··· 1008 1007 1009 1008 endchoice 1010 1009 1011 - config RTC_DS1685_PROC_REGS 1012 - bool "Display register values in /proc" 1013 - depends on RTC_DRV_DS1685_FAMILY && PROC_FS 1014 - help 1015 - Enable this to display a readout of all of the RTC registers in 1016 - /proc/drivers/rtc. Keep in mind that this can potentially lead 1017 - to lost interrupts, as reading Control Register C will clear 1018 - all pending IRQ flags. 1019 - 1020 - Unless you are debugging this driver, choose N. 1021 - 1022 1010 config RTC_DRV_DS1742 1023 1011 tristate "Maxim/Dallas DS1742/1743" 1024 1012 depends on HAS_IOMEM ··· 1577 1587 1578 1588 config RTC_DRV_JZ4740 1579 1589 tristate "Ingenic JZ4740 SoC" 1580 - depends on MACH_INGENIC || COMPILE_TEST 1590 + depends on MIPS || COMPILE_TEST 1581 1591 help 1582 1592 If you say yes here you get support for the Ingenic JZ47xx SoCs RTC 1583 1593 controllers.
+6 -6
drivers/rtc/Makefile
··· 36 36 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o 37 37 obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o 38 38 obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o 39 - obj-$(CONFIG_RTC_DRV_BRCMSTB) += rtc-brcmstb-waketimer.o 40 39 obj-$(CONFIG_RTC_DRV_BQ32K) += rtc-bq32k.o 41 40 obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o 41 + obj-$(CONFIG_RTC_DRV_BRCMSTB) += rtc-brcmstb-waketimer.o 42 42 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 43 43 obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o 44 44 obj-$(CONFIG_RTC_DRV_CPCAP) += rtc-cpcap.o ··· 71 71 obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 72 72 obj-$(CONFIG_RTC_DRV_FTRTC010) += rtc-ftrtc010.o 73 73 obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 74 + obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o 74 75 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o 75 76 obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o 76 77 obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o ··· 79 78 obj-$(CONFIG_RTC_DRV_ISL12026) += rtc-isl12026.o 80 79 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 81 80 obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 81 + obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o 82 82 obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o 83 83 obj-$(CONFIG_RTC_DRV_LPC24XX) += rtc-lpc24xx.o 84 84 obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o 85 - obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o 86 85 obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 87 86 obj-$(CONFIG_RTC_DRV_M41T93) += rtc-m41t93.o 88 87 obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o ··· 101 100 obj-$(CONFIG_RTC_DRV_MCP795) += rtc-mcp795.o 102 101 obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o 103 102 obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o 104 - obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 105 103 obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 106 104 obj-$(CONFIG_RTC_DRV_MT6397) += rtc-mt6397.o 107 105 obj-$(CONFIG_RTC_DRV_MT7622) += rtc-mt7622.o ··· 116 116 obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o 117 117 obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o 118 118 obj-$(CONFIG_RTC_DRV_PCF85063) += rtc-pcf85063.o 119 - obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o 120 119 obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o 120 + obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o 121 121 obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 122 122 obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 123 123 obj-$(CONFIG_RTC_DRV_PIC32) += rtc-pic32.o ··· 154 154 obj-$(CONFIG_RTC_DRV_SPEAR) += rtc-spear.o 155 155 obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o 156 156 obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o 157 + obj-$(CONFIG_RTC_DRV_ST_LPC) += rtc-st-lpc.o 157 158 obj-$(CONFIG_RTC_DRV_STM32) += rtc-stm32.o 158 159 obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o 159 - obj-$(CONFIG_RTC_DRV_ST_LPC) += rtc-st-lpc.o 160 160 obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o 161 161 obj-$(CONFIG_RTC_DRV_SUN6I) += rtc-sun6i.o 162 162 obj-$(CONFIG_RTC_DRV_SUNXI) += rtc-sunxi.o ··· 169 169 obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 170 170 obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 171 171 obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 172 + obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 172 173 obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o 173 174 obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o 174 175 obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o 175 176 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 176 177 obj-$(CONFIG_RTC_DRV_XGENE) += rtc-xgene.o 177 178 obj-$(CONFIG_RTC_DRV_ZYNQMP) += rtc-zynqmp.o 178 - obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o
+5 -7
drivers/rtc/class.c
··· 286 286 * 287 287 * Returns the pointer to the new struct class device. 288 288 */ 289 - struct rtc_device *rtc_device_register(const char *name, struct device *dev, 290 - const struct rtc_class_ops *ops, 291 - struct module *owner) 289 + static struct rtc_device *rtc_device_register(const char *name, 290 + struct device *dev, 291 + const struct rtc_class_ops *ops, 292 + struct module *owner) 292 293 { 293 294 struct rtc_device *rtc; 294 295 struct rtc_wkalrm alrm; ··· 352 351 name, err); 353 352 return ERR_PTR(err); 354 353 } 355 - EXPORT_SYMBOL_GPL(rtc_device_register); 356 - 357 354 358 355 /** 359 356 * rtc_device_unregister - removes the previously registered RTC class device 360 357 * 361 358 * @rtc: the RTC class device to destroy 362 359 */ 363 - void rtc_device_unregister(struct rtc_device *rtc) 360 + static void rtc_device_unregister(struct rtc_device *rtc) 364 361 { 365 362 mutex_lock(&rtc->ops_lock); 366 363 /* ··· 371 372 mutex_unlock(&rtc->ops_lock); 372 373 put_device(&rtc->dev); 373 374 } 374 - EXPORT_SYMBOL_GPL(rtc_device_unregister); 375 375 376 376 static void devm_rtc_device_release(struct device *dev, void *res) 377 377 {
-3
drivers/rtc/interface.c
··· 596 596 * This function is called when an AIE, UIE or PIE mode interrupt 597 597 * has occurred (or been emulated). 598 598 * 599 - * Triggers the registered irq_task function callback. 600 599 */ 601 600 void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode) 602 601 { ··· 740 741 /** 741 742 * rtc_irq_set_state - enable/disable 2^N Hz periodic IRQs 742 743 * @rtc: the rtc device 743 - * @task: currently registered with rtc_irq_register() 744 744 * @enabled: true to enable periodic IRQs 745 745 * Context: any 746 746 * ··· 762 764 /** 763 765 * rtc_irq_set_freq - set 2^N Hz periodic IRQ frequency for IRQ 764 766 * @rtc: the rtc device 765 - * @task: currently registered with rtc_irq_register() 766 767 * @freq: positive frequency 767 768 * Context: any 768 769 *
+22 -74
drivers/rtc/rtc-ab8500.c
··· 46 46 #define RTC_STATUS_DATA 0x01 47 47 48 48 #define COUNTS_PER_SEC (0xF000 / 60) 49 - #define AB8500_RTC_EPOCH 2000 50 49 51 50 static const u8 ab8500_rtc_time_regs[] = { 52 51 AB8500_RTC_WATCH_TMIN_HI_REG, AB8500_RTC_WATCH_TMIN_MID_REG, ··· 57 58 AB8500_RTC_ALRM_MIN_HI_REG, AB8500_RTC_ALRM_MIN_MID_REG, 58 59 AB8500_RTC_ALRM_MIN_LOW_REG 59 60 }; 60 - 61 - /* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */ 62 - static unsigned long get_elapsed_seconds(int year) 63 - { 64 - unsigned long secs; 65 - struct rtc_time tm = { 66 - .tm_year = year - 1900, 67 - .tm_mday = 1, 68 - }; 69 - 70 - /* 71 - * This function calculates secs from 1970 and not from 72 - * 1900, even if we supply the offset from year 1900. 73 - */ 74 - rtc_tm_to_time(&tm, &secs); 75 - return secs; 76 - } 77 61 78 62 static int ab8500_rtc_read_time(struct device *dev, struct rtc_time *tm) 79 63 { ··· 100 118 secs = secs / COUNTS_PER_SEC; 101 119 secs = secs + (mins * 60); 102 120 103 - /* Add back the initially subtracted number of seconds */ 104 - secs += get_elapsed_seconds(AB8500_RTC_EPOCH); 105 - 106 121 rtc_time_to_tm(secs, tm); 107 122 return 0; 108 123 } ··· 110 131 unsigned char buf[ARRAY_SIZE(ab8500_rtc_time_regs)]; 111 132 unsigned long no_secs, no_mins, secs = 0; 112 133 113 - if (tm->tm_year < (AB8500_RTC_EPOCH - 1900)) { 114 - dev_dbg(dev, "year should be equal to or greater than %d\n", 115 - AB8500_RTC_EPOCH); 116 - return -EINVAL; 117 - } 118 - 119 - /* Get the number of seconds since 1970 */ 120 134 rtc_tm_to_time(tm, &secs); 121 - 122 - /* 123 - * Convert it to the number of seconds since 01-01-2000 00:00:00, since 124 - * we only have a small counter in the RTC. 125 - */ 126 - secs -= get_elapsed_seconds(AB8500_RTC_EPOCH); 127 135 128 136 no_mins = secs / 60; 129 137 ··· 168 202 mins = (buf[0] << 16) | (buf[1] << 8) | (buf[2]); 169 203 secs = mins * 60; 170 204 171 - /* Add back the initially subtracted number of seconds */ 172 - secs += get_elapsed_seconds(AB8500_RTC_EPOCH); 173 - 174 205 rtc_time_to_tm(secs, &alarm->time); 175 206 176 - return rtc_valid_tm(&alarm->time); 207 + return 0; 177 208 } 178 209 179 210 static int ab8500_rtc_irq_enable(struct device *dev, unsigned int enabled) ··· 187 224 unsigned long mins, secs = 0, cursec = 0; 188 225 struct rtc_time curtm; 189 226 190 - if (alarm->time.tm_year < (AB8500_RTC_EPOCH - 1900)) { 191 - dev_dbg(dev, "year should be equal to or greater than %d\n", 192 - AB8500_RTC_EPOCH); 193 - return -EINVAL; 194 - } 195 - 196 227 /* Get the number of seconds since 1970 */ 197 228 rtc_tm_to_time(&alarm->time, &secs); 198 229 ··· 201 244 dev_dbg(dev, "Alarm less than 1 minute not supported\r\n"); 202 245 return -EINVAL; 203 246 } 204 - 205 - /* 206 - * Convert it to the number of seconds since 01-01-2000 00:00:00, since 207 - * we only have a small counter in the RTC. 208 - */ 209 - secs -= get_elapsed_seconds(AB8500_RTC_EPOCH); 210 247 211 248 mins = secs / 60; 212 249 ··· 311 360 ab8500_sysfs_show_rtc_calibration, 312 361 ab8500_sysfs_store_rtc_calibration); 313 362 314 - static int ab8500_sysfs_rtc_register(struct device *dev) 315 - { 316 - return device_create_file(dev, &dev_attr_rtc_calibration); 317 - } 363 + static struct attribute *ab8500_rtc_attrs[] = { 364 + &dev_attr_rtc_calibration.attr, 365 + NULL 366 + }; 318 367 319 - static void ab8500_sysfs_rtc_unregister(struct device *dev) 320 - { 321 - device_remove_file(dev, &dev_attr_rtc_calibration); 322 - } 368 + static const struct attribute_group ab8500_rtc_sysfs_files = { 369 + .attrs = ab8500_rtc_attrs, 370 + }; 323 371 324 372 static irqreturn_t rtc_alarm_handler(int irq, void *data) 325 373 { ··· 379 429 380 430 device_init_wakeup(&pdev->dev, true); 381 431 382 - rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc", 383 - (struct rtc_class_ops *)platid->driver_data, 384 - THIS_MODULE); 385 - if (IS_ERR(rtc)) { 386 - dev_err(&pdev->dev, "Registration failed\n"); 387 - err = PTR_ERR(rtc); 388 - return err; 389 - } 432 + rtc = devm_rtc_allocate_device(&pdev->dev); 433 + if (IS_ERR(rtc)) 434 + return PTR_ERR(rtc); 435 + 436 + rtc->ops = (struct rtc_class_ops *)platid->driver_data; 390 437 391 438 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 392 439 rtc_alarm_handler, IRQF_ONESHOT, ··· 394 447 dev_pm_set_wake_irq(&pdev->dev, irq); 395 448 platform_set_drvdata(pdev, rtc); 396 449 397 - err = ab8500_sysfs_rtc_register(&pdev->dev); 398 - if (err) { 399 - dev_err(&pdev->dev, "sysfs RTC failed to register\n"); 400 - return err; 401 - } 402 - 403 450 rtc->uie_unsupported = 1; 404 451 405 - return 0; 452 + rtc->range_max = (1ULL << 24) * 60 - 1; // 24-bit minutes + 59 secs 453 + rtc->start_secs = RTC_TIMESTAMP_BEGIN_2000; 454 + rtc->set_start_time = true; 455 + 456 + err = rtc_add_group(rtc, &ab8500_rtc_sysfs_files); 457 + if (err) 458 + return err; 459 + 460 + return rtc_register_device(rtc); 406 461 } 407 462 408 463 static int ab8500_rtc_remove(struct platform_device *pdev) 409 464 { 410 465 dev_pm_clear_wake_irq(&pdev->dev); 411 466 device_init_wakeup(&pdev->dev, false); 412 - ab8500_sysfs_rtc_unregister(&pdev->dev); 413 467 414 468 return 0; 415 469 }
+131 -12
drivers/rtc/rtc-abx80x.c
··· 17 17 #include <linux/i2c.h> 18 18 #include <linux/module.h> 19 19 #include <linux/rtc.h> 20 + #include <linux/watchdog.h> 20 21 21 22 #define ABX8XX_REG_HTH 0x00 22 23 #define ABX8XX_REG_SC 0x01 ··· 38 37 39 38 #define ABX8XX_REG_STATUS 0x0f 40 39 #define ABX8XX_STATUS_AF BIT(2) 40 + #define ABX8XX_STATUS_WDT BIT(6) 41 41 42 42 #define ABX8XX_REG_CTRL1 0x10 43 43 #define ABX8XX_CTRL_WRITE BIT(0) ··· 63 61 #define ABX8XX_OSS_OF BIT(1) 64 62 #define ABX8XX_OSS_OMODE BIT(4) 65 63 64 + #define ABX8XX_REG_WDT 0x1b 65 + #define ABX8XX_WDT_WDS BIT(7) 66 + #define ABX8XX_WDT_BMB_MASK 0x7c 67 + #define ABX8XX_WDT_BMB_SHIFT 2 68 + #define ABX8XX_WDT_MAX_TIME (ABX8XX_WDT_BMB_MASK >> ABX8XX_WDT_BMB_SHIFT) 69 + #define ABX8XX_WDT_WRB_MASK 0x03 70 + #define ABX8XX_WDT_WRB_1HZ 0x02 71 + 66 72 #define ABX8XX_REG_CFG_KEY 0x1f 67 73 #define ABX8XX_CFG_KEY_OSC 0xa1 68 74 #define ABX8XX_CFG_KEY_MISC 0x9d ··· 90 80 struct abx80x_cap { 91 81 u16 pn; 92 82 bool has_tc; 83 + bool has_wdog; 93 84 }; 94 85 95 86 static struct abx80x_cap abx80x_caps[] = { 96 87 [AB0801] = {.pn = 0x0801}, 97 88 [AB0803] = {.pn = 0x0803}, 98 - [AB0804] = {.pn = 0x0804, .has_tc = true}, 99 - [AB0805] = {.pn = 0x0805, .has_tc = true}, 89 + [AB0804] = {.pn = 0x0804, .has_tc = true, .has_wdog = true}, 90 + [AB0805] = {.pn = 0x0805, .has_tc = true, .has_wdog = true}, 100 91 [AB1801] = {.pn = 0x1801}, 101 92 [AB1803] = {.pn = 0x1803}, 102 - [AB1804] = {.pn = 0x1804, .has_tc = true}, 103 - [AB1805] = {.pn = 0x1805, .has_tc = true}, 93 + [AB1804] = {.pn = 0x1804, .has_tc = true, .has_wdog = true}, 94 + [AB1805] = {.pn = 0x1805, .has_tc = true, .has_wdog = true}, 104 95 [ABX80X] = {.pn = 0} 96 + }; 97 + 98 + struct abx80x_priv { 99 + struct rtc_device *rtc; 100 + struct i2c_client *client; 101 + struct watchdog_device wdog; 105 102 }; 106 103 107 104 static int abx80x_is_rc_mode(struct i2c_client *client) ··· 235 218 static irqreturn_t abx80x_handle_irq(int irq, void *dev_id) 236 219 { 237 220 struct i2c_client *client = dev_id; 238 - struct rtc_device *rtc = i2c_get_clientdata(client); 221 + struct abx80x_priv *priv = i2c_get_clientdata(client); 222 + struct rtc_device *rtc = priv->rtc; 239 223 int status; 240 224 241 225 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS); ··· 245 227 246 228 if (status & ABX8XX_STATUS_AF) 247 229 rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF); 230 + 231 + /* 232 + * It is unclear if we'll get an interrupt before the external 233 + * reset kicks in. 234 + */ 235 + if (status & ABX8XX_STATUS_WDT) 236 + dev_alert(&client->dev, "watchdog timeout interrupt.\n"); 248 237 249 238 i2c_smbus_write_byte_data(client, ABX8XX_REG_STATUS, 0); 250 239 ··· 554 529 sysfs_remove_group(&dev->kobj, &rtc_calib_attr_group); 555 530 } 556 531 532 + #ifdef CONFIG_WATCHDOG 533 + 534 + static inline u8 timeout_bits(unsigned int timeout) 535 + { 536 + return ((timeout << ABX8XX_WDT_BMB_SHIFT) & ABX8XX_WDT_BMB_MASK) | 537 + ABX8XX_WDT_WRB_1HZ; 538 + } 539 + 540 + static int __abx80x_wdog_set_timeout(struct watchdog_device *wdog, 541 + unsigned int timeout) 542 + { 543 + struct abx80x_priv *priv = watchdog_get_drvdata(wdog); 544 + u8 val = ABX8XX_WDT_WDS | timeout_bits(timeout); 545 + 546 + /* 547 + * Writing any timeout to the WDT register resets the watchdog timer. 548 + * Writing 0 disables it. 549 + */ 550 + return i2c_smbus_write_byte_data(priv->client, ABX8XX_REG_WDT, val); 551 + } 552 + 553 + static int abx80x_wdog_set_timeout(struct watchdog_device *wdog, 554 + unsigned int new_timeout) 555 + { 556 + int err = 0; 557 + 558 + if (watchdog_hw_running(wdog)) 559 + err = __abx80x_wdog_set_timeout(wdog, new_timeout); 560 + 561 + if (err == 0) 562 + wdog->timeout = new_timeout; 563 + 564 + return err; 565 + } 566 + 567 + static int abx80x_wdog_ping(struct watchdog_device *wdog) 568 + { 569 + return __abx80x_wdog_set_timeout(wdog, wdog->timeout); 570 + } 571 + 572 + static int abx80x_wdog_start(struct watchdog_device *wdog) 573 + { 574 + return __abx80x_wdog_set_timeout(wdog, wdog->timeout); 575 + } 576 + 577 + static int abx80x_wdog_stop(struct watchdog_device *wdog) 578 + { 579 + return __abx80x_wdog_set_timeout(wdog, 0); 580 + } 581 + 582 + static const struct watchdog_info abx80x_wdog_info = { 583 + .identity = "abx80x watchdog", 584 + .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, 585 + }; 586 + 587 + static const struct watchdog_ops abx80x_wdog_ops = { 588 + .owner = THIS_MODULE, 589 + .start = abx80x_wdog_start, 590 + .stop = abx80x_wdog_stop, 591 + .ping = abx80x_wdog_ping, 592 + .set_timeout = abx80x_wdog_set_timeout, 593 + }; 594 + 595 + static int abx80x_setup_watchdog(struct abx80x_priv *priv) 596 + { 597 + priv->wdog.parent = &priv->client->dev; 598 + priv->wdog.ops = &abx80x_wdog_ops; 599 + priv->wdog.info = &abx80x_wdog_info; 600 + priv->wdog.min_timeout = 1; 601 + priv->wdog.max_timeout = ABX8XX_WDT_MAX_TIME; 602 + priv->wdog.timeout = ABX8XX_WDT_MAX_TIME; 603 + 604 + watchdog_set_drvdata(&priv->wdog, priv); 605 + 606 + return devm_watchdog_register_device(&priv->client->dev, &priv->wdog); 607 + } 608 + #else 609 + static int abx80x_setup_watchdog(struct abx80x_priv *priv) 610 + { 611 + return 0; 612 + } 613 + #endif 614 + 557 615 static int abx80x_probe(struct i2c_client *client, 558 616 const struct i2c_device_id *id) 559 617 { 560 618 struct device_node *np = client->dev.of_node; 561 - struct rtc_device *rtc; 619 + struct abx80x_priv *priv; 562 620 int i, data, err, trickle_cfg = -EINVAL; 563 621 char buf[7]; 564 622 unsigned int part = id->driver_data; ··· 718 610 if (err) 719 611 return err; 720 612 721 - rtc = devm_rtc_allocate_device(&client->dev); 722 - if (IS_ERR(rtc)) 723 - return PTR_ERR(rtc); 613 + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); 614 + if (priv == NULL) 615 + return -ENOMEM; 724 616 725 - rtc->ops = &abx80x_rtc_ops; 617 + priv->rtc = devm_rtc_allocate_device(&client->dev); 618 + if (IS_ERR(priv->rtc)) 619 + return PTR_ERR(priv->rtc); 726 620 727 - i2c_set_clientdata(client, rtc); 621 + priv->rtc->ops = &abx80x_rtc_ops; 622 + priv->client = client; 623 + 624 + i2c_set_clientdata(client, priv); 625 + 626 + if (abx80x_caps[part].has_wdog) { 627 + err = abx80x_setup_watchdog(priv); 628 + if (err) 629 + return err; 630 + } 728 631 729 632 if (client->irq > 0) { 730 633 dev_info(&client->dev, "IRQ %d supplied\n", client->irq); ··· 768 649 return err; 769 650 } 770 651 771 - err = rtc_register_device(rtc); 652 + err = rtc_register_device(priv->rtc); 772 653 773 654 return err; 774 655 }
+19 -27
drivers/rtc/rtc-armada38x.c
··· 224 224 time = rtc->data->read_rtc_reg(rtc, RTC_TIME); 225 225 spin_unlock_irqrestore(&rtc->lock, flags); 226 226 227 - rtc_time_to_tm(time, tm); 227 + rtc_time64_to_tm(time, tm); 228 228 229 229 return 0; 230 230 } ··· 249 249 static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm) 250 250 { 251 251 struct armada38x_rtc *rtc = dev_get_drvdata(dev); 252 - int ret = 0; 253 252 unsigned long time, flags; 254 253 255 - ret = rtc_tm_to_time(tm, &time); 256 - 257 - if (ret) 258 - goto out; 254 + time = rtc_tm_to_time64(tm); 259 255 260 256 if (!rtc->initialized) 261 257 armada38x_rtc_reset(rtc); ··· 260 264 rtc_delayed_write(time, rtc, RTC_TIME); 261 265 spin_unlock_irqrestore(&rtc->lock, flags); 262 266 263 - out: 264 - return ret; 267 + return 0; 265 268 } 266 269 267 270 static int armada38x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ··· 279 284 spin_unlock_irqrestore(&rtc->lock, flags); 280 285 281 286 alrm->enabled = val ? 1 : 0; 282 - rtc_time_to_tm(time, &alrm->time); 287 + rtc_time64_to_tm(time, &alrm->time); 283 288 284 289 return 0; 285 290 } ··· 290 295 u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm); 291 296 u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm); 292 297 unsigned long time, flags; 293 - int ret = 0; 294 298 295 - ret = rtc_tm_to_time(&alrm->time, &time); 296 - 297 - if (ret) 298 - goto out; 299 + time = rtc_tm_to_time64(&alrm->time); 299 300 300 301 spin_lock_irqsave(&rtc->lock, flags); 301 302 ··· 304 313 305 314 spin_unlock_irqrestore(&rtc->lock, flags); 306 315 307 - out: 308 - return ret; 316 + return 0; 309 317 } 310 318 311 319 static int armada38x_rtc_alarm_irq_enable(struct device *dev, ··· 504 514 505 515 static __init int armada38x_rtc_probe(struct platform_device *pdev) 506 516 { 507 - const struct rtc_class_ops *ops; 508 517 struct resource *res; 509 518 struct armada38x_rtc *rtc; 510 519 const struct of_device_id *match; ··· 540 551 dev_err(&pdev->dev, "no irq\n"); 541 552 return rtc->irq; 542 553 } 554 + 555 + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); 556 + if (IS_ERR(rtc->rtc_dev)) 557 + return PTR_ERR(rtc->rtc_dev); 558 + 543 559 if (devm_request_irq(&pdev->dev, rtc->irq, armada38x_rtc_alarm_irq, 544 560 0, pdev->name, rtc) < 0) { 545 561 dev_warn(&pdev->dev, "Interrupt not available.\n"); ··· 554 560 555 561 if (rtc->irq != -1) { 556 562 device_init_wakeup(&pdev->dev, 1); 557 - ops = &armada38x_rtc_ops; 563 + rtc->rtc_dev->ops = &armada38x_rtc_ops; 558 564 } else { 559 565 /* 560 566 * If there is no interrupt available then we can't 561 567 * use the alarm 562 568 */ 563 - ops = &armada38x_rtc_ops_noirq; 569 + rtc->rtc_dev->ops = &armada38x_rtc_ops_noirq; 564 570 } 565 571 rtc->data = (struct armada38x_rtc_data *)match->data; 566 - 567 572 568 573 /* Update RTC-MBUS bridge timing parameters */ 569 574 rtc->data->update_mbus_timing(rtc); 570 575 571 - rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, 572 - ops, THIS_MODULE); 573 - if (IS_ERR(rtc->rtc_dev)) { 574 - ret = PTR_ERR(rtc->rtc_dev); 576 + rtc->rtc_dev->range_max = U32_MAX; 577 + 578 + ret = rtc_register_device(rtc->rtc_dev); 579 + if (ret) 575 580 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 576 - return ret; 577 - } 578 - return 0; 581 + 582 + return ret; 579 583 } 580 584 581 585 #ifdef CONFIG_PM_SLEEP
+21 -8
drivers/rtc/rtc-cmos.c
··· 50 50 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ 51 51 #include <linux/mc146818rtc.h> 52 52 53 + #ifdef CONFIG_ACPI 53 54 /* 54 55 * Use ACPI SCI to replace HPET interrupt for RTC Alarm event 55 56 * ··· 61 60 62 61 static bool use_acpi_alarm; 63 62 module_param(use_acpi_alarm, bool, 0444); 63 + 64 + static inline int cmos_use_acpi_alarm(void) 65 + { 66 + return use_acpi_alarm; 67 + } 68 + #else /* !CONFIG_ACPI */ 69 + 70 + static inline int cmos_use_acpi_alarm(void) 71 + { 72 + return 0; 73 + } 74 + #endif 64 75 65 76 struct cmos_rtc { 66 77 struct rtc_device *rtc; ··· 180 167 #endif 181 168 182 169 /* Don't use HPET for RTC Alarm event if ACPI Fixed event is used */ 183 - static int use_hpet_alarm(void) 170 + static inline int use_hpet_alarm(void) 184 171 { 185 - return is_hpet_enabled() && !use_acpi_alarm; 172 + return is_hpet_enabled() && !cmos_use_acpi_alarm(); 186 173 } 187 174 188 175 /*----------------------------------------------------------------*/ ··· 353 340 if (use_hpet_alarm()) 354 341 hpet_set_rtc_irq_bit(mask); 355 342 356 - if ((mask & RTC_AIE) && use_acpi_alarm) { 343 + if ((mask & RTC_AIE) && cmos_use_acpi_alarm()) { 357 344 if (cmos->wake_on) 358 345 cmos->wake_on(cmos->dev); 359 346 } ··· 371 358 if (use_hpet_alarm()) 372 359 hpet_mask_rtc_irq_bit(mask); 373 360 374 - if ((mask & RTC_AIE) && use_acpi_alarm) { 361 + if ((mask & RTC_AIE) && cmos_use_acpi_alarm()) { 375 362 if (cmos->wake_off) 376 363 cmos->wake_off(cmos->dev); 377 364 } ··· 993 980 } 994 981 spin_unlock_irq(&rtc_lock); 995 982 996 - if ((tmp & RTC_AIE) && !use_acpi_alarm) { 983 + if ((tmp & RTC_AIE) && !cmos_use_acpi_alarm()) { 997 984 cmos->enabled_wake = 1; 998 985 if (cmos->wake_on) 999 986 cmos->wake_on(dev); ··· 1044 1031 * ACPI RTC wake event is cleared after resume from STR, 1045 1032 * ACK the rtc irq here 1046 1033 */ 1047 - if (t_now >= cmos->alarm_expires && use_acpi_alarm) { 1034 + if (t_now >= cmos->alarm_expires && cmos_use_acpi_alarm()) { 1048 1035 cmos_interrupt(0, (void *)cmos->rtc); 1049 1036 return; 1050 1037 } ··· 1066 1053 struct cmos_rtc *cmos = dev_get_drvdata(dev); 1067 1054 unsigned char tmp; 1068 1055 1069 - if (cmos->enabled_wake && !use_acpi_alarm) { 1056 + if (cmos->enabled_wake && !cmos_use_acpi_alarm()) { 1070 1057 if (cmos->wake_off) 1071 1058 cmos->wake_off(dev); 1072 1059 else ··· 1145 1132 * Or else, ACPI SCI is enabled during suspend/resume only, 1146 1133 * update rtc irq in that case. 1147 1134 */ 1148 - if (use_acpi_alarm) 1135 + if (cmos_use_acpi_alarm()) 1149 1136 cmos_interrupt(0, (void *)cmos->rtc); 1150 1137 else { 1151 1138 /* Fix me: can we use cmos_interrupt() here as well? */
-14
drivers/rtc/rtc-core.h
··· 40 40 41 41 #ifdef CONFIG_RTC_INTF_SYSFS 42 42 const struct attribute_group **rtc_get_dev_attribute_groups(void); 43 - int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp); 44 - int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps); 45 43 #else 46 44 static inline const struct attribute_group **rtc_get_dev_attribute_groups(void) 47 45 { 48 46 return NULL; 49 - } 50 - 51 - static inline 52 - int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp) 53 - { 54 - return 0; 55 - } 56 - 57 - static inline 58 - int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) 59 - { 60 - return 0; 61 47 } 62 48 #endif
+144 -1
drivers/rtc/rtc-ds1307.c
··· 114 114 # define RX8025_BIT_VDET 0x40 115 115 # define RX8025_BIT_XST 0x20 116 116 117 + #define M41TXX_REG_CONTROL 0x07 118 + # define M41TXX_BIT_OUT BIT(7) 119 + # define M41TXX_BIT_FT BIT(6) 120 + # define M41TXX_BIT_CALIB_SIGN BIT(5) 121 + # define M41TXX_M_CALIBRATION GENMASK(4, 0) 122 + 123 + /* negative offset step is -2.034ppm */ 124 + #define M41TXX_NEG_OFFSET_STEP_PPB 2034 125 + /* positive offset step is +4.068ppm */ 126 + #define M41TXX_POS_OFFSET_STEP_PPB 4068 127 + /* Min and max values supported with 'offset' interface by M41TXX */ 128 + #define M41TXX_MIN_OFFSET ((-31) * M41TXX_NEG_OFFSET_STEP_PPB) 129 + #define M41TXX_MAX_OFFSET ((31) * M41TXX_POS_OFFSET_STEP_PPB) 130 + 117 131 struct ds1307 { 118 132 enum ds_type type; 119 133 unsigned long flags; ··· 160 146 161 147 static int ds1307_get_time(struct device *dev, struct rtc_time *t); 162 148 static int ds1307_set_time(struct device *dev, struct rtc_time *t); 149 + static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t); 150 + static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t); 151 + static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled); 163 152 static u8 do_trickle_setup_ds1339(struct ds1307 *, u32 ohms, bool diode); 164 153 static irqreturn_t rx8130_irq(int irq, void *dev_id); 165 154 static int rx8130_read_alarm(struct device *dev, struct rtc_wkalrm *t); ··· 172 155 static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t); 173 156 static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t); 174 157 static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled); 158 + static int m41txx_rtc_read_offset(struct device *dev, long *offset); 159 + static int m41txx_rtc_set_offset(struct device *dev, long offset); 175 160 176 161 static const struct rtc_class_ops rx8130_rtc_ops = { 177 162 .read_time = ds1307_get_time, ··· 189 170 .read_alarm = mcp794xx_read_alarm, 190 171 .set_alarm = mcp794xx_set_alarm, 191 172 .alarm_irq_enable = mcp794xx_alarm_irq_enable, 173 + }; 174 + 175 + static const struct rtc_class_ops m41txx_rtc_ops = { 176 + .read_time = ds1307_get_time, 177 + .set_time = ds1307_set_time, 178 + .read_alarm = ds1337_read_alarm, 179 + .set_alarm = ds1337_set_alarm, 180 + .alarm_irq_enable = ds1307_alarm_irq_enable, 181 + .read_offset = m41txx_rtc_read_offset, 182 + .set_offset = m41txx_rtc_set_offset, 192 183 }; 193 184 194 185 static const struct chip_desc chips[last_ds_type] = { ··· 257 228 .irq_handler = rx8130_irq, 258 229 .rtc_ops = &rx8130_rtc_ops, 259 230 }, 231 + [m41t0] = { 232 + .rtc_ops = &m41txx_rtc_ops, 233 + }, 234 + [m41t00] = { 235 + .rtc_ops = &m41txx_rtc_ops, 236 + }, 260 237 [m41t11] = { 261 238 /* this is battery backed SRAM */ 262 239 .nvram_offset = 8, 263 240 .nvram_size = 56, 241 + .rtc_ops = &m41txx_rtc_ops, 264 242 }, 265 243 [mcp794xx] = { 266 244 .alarm = 1, ··· 1009 973 enabled ? MCP794XX_BIT_ALM0_EN : 0); 1010 974 } 1011 975 976 + static int m41txx_rtc_read_offset(struct device *dev, long *offset) 977 + { 978 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 979 + unsigned int ctrl_reg; 980 + u8 val; 981 + 982 + regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); 983 + 984 + val = ctrl_reg & M41TXX_M_CALIBRATION; 985 + 986 + /* check if positive */ 987 + if (ctrl_reg & M41TXX_BIT_CALIB_SIGN) 988 + *offset = (val * M41TXX_POS_OFFSET_STEP_PPB); 989 + else 990 + *offset = -(val * M41TXX_NEG_OFFSET_STEP_PPB); 991 + 992 + return 0; 993 + } 994 + 995 + static int m41txx_rtc_set_offset(struct device *dev, long offset) 996 + { 997 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 998 + unsigned int ctrl_reg; 999 + 1000 + if ((offset < M41TXX_MIN_OFFSET) || (offset > M41TXX_MAX_OFFSET)) 1001 + return -ERANGE; 1002 + 1003 + if (offset >= 0) { 1004 + ctrl_reg = DIV_ROUND_CLOSEST(offset, 1005 + M41TXX_POS_OFFSET_STEP_PPB); 1006 + ctrl_reg |= M41TXX_BIT_CALIB_SIGN; 1007 + } else { 1008 + ctrl_reg = DIV_ROUND_CLOSEST(abs(offset), 1009 + M41TXX_NEG_OFFSET_STEP_PPB); 1010 + } 1011 + 1012 + return regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, 1013 + M41TXX_M_CALIBRATION | M41TXX_BIT_CALIB_SIGN, 1014 + ctrl_reg); 1015 + } 1016 + 1017 + static ssize_t frequency_test_store(struct device *dev, 1018 + struct device_attribute *attr, 1019 + const char *buf, size_t count) 1020 + { 1021 + struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); 1022 + bool freq_test_en; 1023 + int ret; 1024 + 1025 + ret = kstrtobool(buf, &freq_test_en); 1026 + if (ret) { 1027 + dev_err(dev, "Failed to store RTC Frequency Test attribute\n"); 1028 + return ret; 1029 + } 1030 + 1031 + regmap_update_bits(ds1307->regmap, M41TXX_REG_CONTROL, M41TXX_BIT_FT, 1032 + freq_test_en ? M41TXX_BIT_FT : 0); 1033 + 1034 + return count; 1035 + } 1036 + 1037 + static ssize_t frequency_test_show(struct device *dev, 1038 + struct device_attribute *attr, 1039 + char *buf) 1040 + { 1041 + struct ds1307 *ds1307 = dev_get_drvdata(dev->parent); 1042 + unsigned int ctrl_reg; 1043 + 1044 + regmap_read(ds1307->regmap, M41TXX_REG_CONTROL, &ctrl_reg); 1045 + 1046 + return scnprintf(buf, PAGE_SIZE, (ctrl_reg & M41TXX_BIT_FT) ? "on\n" : 1047 + "off\n"); 1048 + } 1049 + 1050 + static DEVICE_ATTR_RW(frequency_test); 1051 + 1052 + static struct attribute *rtc_freq_test_attrs[] = { 1053 + &dev_attr_frequency_test.attr, 1054 + NULL, 1055 + }; 1056 + 1057 + static const struct attribute_group rtc_freq_test_attr_group = { 1058 + .attrs = rtc_freq_test_attrs, 1059 + }; 1060 + 1061 + static int ds1307_add_frequency_test(struct ds1307 *ds1307) 1062 + { 1063 + int err; 1064 + 1065 + switch (ds1307->type) { 1066 + case m41t0: 1067 + case m41t00: 1068 + case m41t11: 1069 + err = rtc_add_group(ds1307->rtc, &rtc_freq_test_attr_group); 1070 + if (err) 1071 + return err; 1072 + break; 1073 + default: 1074 + break; 1075 + } 1076 + 1077 + return 0; 1078 + } 1079 + 1012 1080 /*----------------------------------------------------------------------*/ 1013 1081 1014 1082 static int ds1307_nvram_read(void *priv, unsigned int offset, void *val, ··· 1524 1384 static const struct regmap_config regmap_config = { 1525 1385 .reg_bits = 8, 1526 1386 .val_bits = 8, 1527 - .max_register = 0x9, 1528 1387 }; 1529 1388 1530 1389 static int ds1307_probe(struct i2c_client *client, ··· 1850 1711 } 1851 1712 1852 1713 ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; 1714 + err = ds1307_add_frequency_test(ds1307); 1715 + if (err) 1716 + return err; 1717 + 1853 1718 err = rtc_register_device(ds1307->rtc); 1854 1719 if (err) 1855 1720 return err;
+26 -168
drivers/rtc/rtc-ds1685.c
··· 770 770 "512Hz", "256Hz", "128Hz", "64Hz", "32Hz", "16Hz", "8Hz", "4Hz", "2Hz" 771 771 }; 772 772 773 - #ifdef CONFIG_RTC_DS1685_PROC_REGS 774 - /** 775 - * ds1685_rtc_print_regs - helper function to print register values. 776 - * @hex: hex byte to convert into binary bits. 777 - * @dest: destination char array. 778 - * 779 - * This is basically a hex->binary function, just with extra spacing between 780 - * the digits. It only works on 1-byte values (8 bits). 781 - */ 782 - static char* 783 - ds1685_rtc_print_regs(u8 hex, char *dest) 784 - { 785 - u32 i, j; 786 - char *tmp = dest; 787 - 788 - for (i = 0; i < NUM_BITS; i++) { 789 - *tmp++ = ((hex & 0x80) != 0 ? '1' : '0'); 790 - for (j = 0; j < NUM_SPACES; j++) 791 - *tmp++ = ' '; 792 - hex <<= 1; 793 - } 794 - *tmp++ = '\0'; 795 - 796 - return dest; 797 - } 798 - #endif 799 - 800 773 /** 801 774 * ds1685_rtc_proc - procfs access function. 802 775 * @dev: pointer to device structure. ··· 778 805 static int 779 806 ds1685_rtc_proc(struct device *dev, struct seq_file *seq) 780 807 { 781 - struct platform_device *pdev = to_platform_device(dev); 782 - struct ds1685_priv *rtc = platform_get_drvdata(pdev); 808 + struct ds1685_priv *rtc = dev_get_drvdata(dev); 783 809 u8 ctrla, ctrlb, ctrlc, ctrld, ctrl4a, ctrl4b, ssn[8]; 784 810 char *model; 785 - #ifdef CONFIG_RTC_DS1685_PROC_REGS 786 - char bits[NUM_REGS][(NUM_BITS * NUM_SPACES) + NUM_BITS + 1]; 787 - #endif 788 811 789 812 /* Read all the relevant data from the control registers. */ 790 813 ds1685_rtc_switch_to_bank1(rtc); ··· 828 859 "Periodic IRQ\t: %s\n" 829 860 "Periodic Rate\t: %s\n" 830 861 "SQW Freq\t: %s\n" 831 - #ifdef CONFIG_RTC_DS1685_PROC_REGS 832 - "Serial #\t: %8phC\n" 833 - "Register Status\t:\n" 834 - " Ctrl A\t: UIP DV2 DV1 DV0 RS3 RS2 RS1 RS0\n" 835 - "\t\t: %s\n" 836 - " Ctrl B\t: SET PIE AIE UIE SQWE DM 2412 DSE\n" 837 - "\t\t: %s\n" 838 - " Ctrl C\t: IRQF PF AF UF --- --- --- ---\n" 839 - "\t\t: %s\n" 840 - " Ctrl D\t: VRT --- --- --- --- --- --- ---\n" 841 - "\t\t: %s\n" 842 - #if !defined(CONFIG_RTC_DRV_DS1685) && !defined(CONFIG_RTC_DRV_DS1689) 843 - " Ctrl 4A\t: VRT2 INCR BME --- PAB RF WF KF\n" 844 - #else 845 - " Ctrl 4A\t: VRT2 INCR --- --- PAB RF WF KF\n" 846 - #endif 847 - "\t\t: %s\n" 848 - " Ctrl 4B\t: ABE E32k CS RCE PRS RIE WIE KSE\n" 849 - "\t\t: %s\n", 850 - #else 851 862 "Serial #\t: %8phC\n", 852 - #endif 853 863 model, 854 864 ((ctrla & RTC_CTRL_A_DV1) ? "enabled" : "disabled"), 855 865 ((ctrlb & RTC_CTRL_B_2412) ? "24-hour" : "12-hour"), ··· 842 894 ds1685_rtc_pirq_rate[(ctrla & RTC_CTRL_A_RS_MASK)] : "none"), 843 895 (!((ctrl4b & RTC_CTRL_4B_E32K)) ? 844 896 ds1685_rtc_sqw_freq[(ctrla & RTC_CTRL_A_RS_MASK)] : "32768Hz"), 845 - #ifdef CONFIG_RTC_DS1685_PROC_REGS 846 - ssn, 847 - ds1685_rtc_print_regs(ctrla, bits[0]), 848 - ds1685_rtc_print_regs(ctrlb, bits[1]), 849 - ds1685_rtc_print_regs(ctrlc, bits[2]), 850 - ds1685_rtc_print_regs(ctrld, bits[3]), 851 - ds1685_rtc_print_regs(ctrl4a, bits[4]), 852 - ds1685_rtc_print_regs(ctrl4b, bits[5])); 853 - #else 854 897 ssn); 855 - #endif 856 898 return 0; 857 899 } 858 900 #else ··· 865 927 }; 866 928 /* ----------------------------------------------------------------------- */ 867 929 868 - 869 - /* ----------------------------------------------------------------------- */ 870 - /* SysFS interface */ 871 - 872 - #ifdef CONFIG_SYSFS 873 - /** 874 - * ds1685_rtc_sysfs_nvram_read - reads rtc nvram via sysfs. 875 - * @file: pointer to file structure. 876 - * @kobj: pointer to kobject structure. 877 - * @bin_attr: pointer to bin_attribute structure. 878 - * @buf: pointer to char array to hold the output. 879 - * @pos: current file position pointer. 880 - * @size: size of the data to read. 881 - */ 882 - static ssize_t 883 - ds1685_rtc_sysfs_nvram_read(struct file *filp, struct kobject *kobj, 884 - struct bin_attribute *bin_attr, char *buf, 885 - loff_t pos, size_t size) 930 + static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, 931 + size_t size) 886 932 { 887 - struct platform_device *pdev = 888 - to_platform_device(container_of(kobj, struct device, kobj)); 889 - struct ds1685_priv *rtc = platform_get_drvdata(pdev); 933 + struct ds1685_priv *rtc = priv; 890 934 ssize_t count; 891 935 unsigned long flags = 0; 936 + u8 *buf = val; 892 937 893 938 spin_lock_irqsave(&rtc->lock, flags); 894 939 ds1685_rtc_switch_to_bank0(rtc); ··· 925 1004 #endif /* !CONFIG_RTC_DRV_DS1689 */ 926 1005 spin_unlock_irqrestore(&rtc->lock, flags); 927 1006 928 - /* 929 - * XXX: Bug? this appears to cause the function to get executed 930 - * several times in succession. But it's the only way to actually get 931 - * data written out to a file. 932 - */ 933 - return count; 1007 + return 0; 934 1008 } 935 1009 936 - /** 937 - * ds1685_rtc_sysfs_nvram_write - writes rtc nvram via sysfs. 938 - * @file: pointer to file structure. 939 - * @kobj: pointer to kobject structure. 940 - * @bin_attr: pointer to bin_attribute structure. 941 - * @buf: pointer to char array to hold the input. 942 - * @pos: current file position pointer. 943 - * @size: size of the data to write. 944 - */ 945 - static ssize_t 946 - ds1685_rtc_sysfs_nvram_write(struct file *filp, struct kobject *kobj, 947 - struct bin_attribute *bin_attr, char *buf, 948 - loff_t pos, size_t size) 1010 + static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, 1011 + size_t size) 949 1012 { 950 - struct platform_device *pdev = 951 - to_platform_device(container_of(kobj, struct device, kobj)); 952 - struct ds1685_priv *rtc = platform_get_drvdata(pdev); 1013 + struct ds1685_priv *rtc = priv; 953 1014 ssize_t count; 954 1015 unsigned long flags = 0; 1016 + u8 *buf = val; 955 1017 956 1018 spin_lock_irqsave(&rtc->lock, flags); 957 1019 ds1685_rtc_switch_to_bank0(rtc); ··· 988 1084 #endif /* !CONFIG_RTC_DRV_DS1689 */ 989 1085 spin_unlock_irqrestore(&rtc->lock, flags); 990 1086 991 - return count; 1087 + return 0; 992 1088 } 993 1089 994 - /** 995 - * struct ds1685_rtc_sysfs_nvram_attr - sysfs attributes for rtc nvram. 996 - * @attr: nvram attributes. 997 - * @read: nvram read function. 998 - * @write: nvram write function. 999 - * @size: nvram total size (bank0 + extended). 1000 - */ 1001 - static struct bin_attribute 1002 - ds1685_rtc_sysfs_nvram_attr = { 1003 - .attr = { 1004 - .name = "nvram", 1005 - .mode = S_IRUGO | S_IWUSR, 1006 - }, 1007 - .read = ds1685_rtc_sysfs_nvram_read, 1008 - .write = ds1685_rtc_sysfs_nvram_write, 1009 - .size = NVRAM_TOTAL_SZ 1010 - }; 1090 + /* ----------------------------------------------------------------------- */ 1091 + /* SysFS interface */ 1011 1092 1012 1093 /** 1013 1094 * ds1685_rtc_sysfs_battery_show - sysfs file for main battery status. ··· 1077 1188 .attrs = ds1685_rtc_sysfs_misc_attrs, 1078 1189 }; 1079 1190 1080 - /** 1081 - * ds1685_rtc_sysfs_register - register sysfs files. 1082 - * @dev: pointer to device structure. 1083 - */ 1084 - static int 1085 - ds1685_rtc_sysfs_register(struct device *dev) 1086 - { 1087 - int ret = 0; 1088 - 1089 - sysfs_bin_attr_init(&ds1685_rtc_sysfs_nvram_attr); 1090 - ret = sysfs_create_bin_file(&dev->kobj, &ds1685_rtc_sysfs_nvram_attr); 1091 - if (ret) 1092 - return ret; 1093 - 1094 - ret = sysfs_create_group(&dev->kobj, &ds1685_rtc_sysfs_misc_grp); 1095 - if (ret) 1096 - return ret; 1097 - 1098 - return 0; 1099 - } 1100 - 1101 - /** 1102 - * ds1685_rtc_sysfs_unregister - unregister sysfs files. 1103 - * @dev: pointer to device structure. 1104 - */ 1105 - static int 1106 - ds1685_rtc_sysfs_unregister(struct device *dev) 1107 - { 1108 - sysfs_remove_bin_file(&dev->kobj, &ds1685_rtc_sysfs_nvram_attr); 1109 - sysfs_remove_group(&dev->kobj, &ds1685_rtc_sysfs_misc_grp); 1110 - 1111 - return 0; 1112 - } 1113 - #endif /* CONFIG_SYSFS */ 1114 - 1115 - 1116 - 1117 1191 /* ----------------------------------------------------------------------- */ 1118 1192 /* Driver Probe/Removal */ 1119 1193 ··· 1094 1242 u8 ctrla, ctrlb, hours; 1095 1243 unsigned char am_pm; 1096 1244 int ret = 0; 1245 + struct nvmem_config nvmem_cfg = { 1246 + .name = "ds1685_nvram", 1247 + .size = NVRAM_TOTAL_SZ, 1248 + .reg_read = ds1685_nvram_read, 1249 + .reg_write = ds1685_nvram_write, 1250 + }; 1097 1251 1098 1252 /* Get the platform data. */ 1099 1253 pdata = (struct ds1685_rtc_platform_data *) pdev->dev.platform_data; ··· 1357 1499 /* Setup complete. */ 1358 1500 ds1685_rtc_switch_to_bank0(rtc); 1359 1501 1360 - #ifdef CONFIG_SYSFS 1361 - ret = ds1685_rtc_sysfs_register(&pdev->dev); 1502 + ret = rtc_add_group(rtc_dev, &ds1685_rtc_sysfs_misc_grp); 1362 1503 if (ret) 1363 1504 return ret; 1364 - #endif 1505 + 1506 + rtc_dev->nvram_old_abi = true; 1507 + nvmem_cfg.priv = rtc; 1508 + ret = rtc_nvmem_register(rtc_dev, &nvmem_cfg); 1509 + if (ret) 1510 + return ret; 1365 1511 1366 1512 return rtc_register_device(rtc_dev); 1367 1513 } ··· 1378 1516 ds1685_rtc_remove(struct platform_device *pdev) 1379 1517 { 1380 1518 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 1381 - 1382 - #ifdef CONFIG_SYSFS 1383 - ds1685_rtc_sysfs_unregister(&pdev->dev); 1384 - #endif 1385 1519 1386 1520 /* Read Ctrl B and clear PIE/AIE/UIE. */ 1387 1521 rtc->write(rtc, RTC_CTRL_B,
+13 -21
drivers/rtc/rtc-isl1208.c
··· 10 10 * 11 11 */ 12 12 13 - #include <linux/module.h> 14 - #include <linux/i2c.h> 15 13 #include <linux/bcd.h> 16 - #include <linux/rtc.h> 17 - #include "rtc-core.h" 14 + #include <linux/i2c.h> 15 + #include <linux/module.h> 18 16 #include <linux/of_irq.h> 17 + #include <linux/rtc.h> 19 18 20 19 /* Register map */ 21 20 /* rtc section */ ··· 517 518 struct device_attribute *attr, 518 519 const char *buf, size_t count) 519 520 { 520 - struct i2c_client *client = dev_get_drvdata(dev); 521 + struct i2c_client *client = to_i2c_client(dev->parent); 521 522 int sr; 522 523 523 524 sr = isl1208_i2c_get_sr(client); ··· 539 540 static ssize_t timestamp0_show(struct device *dev, 540 541 struct device_attribute *attr, char *buf) 541 542 { 542 - struct i2c_client *client = dev_get_drvdata(dev); 543 + struct i2c_client *client = to_i2c_client(dev->parent); 543 544 u8 regs[ISL1219_EVT_SECTION_LEN] = { 0, }; 544 545 struct rtc_time tm; 545 546 int sr; ··· 649 650 isl1208_sysfs_show_atrim(struct device *dev, 650 651 struct device_attribute *attr, char *buf) 651 652 { 652 - int atr = isl1208_i2c_get_atr(to_i2c_client(dev)); 653 + int atr = isl1208_i2c_get_atr(to_i2c_client(dev->parent)); 653 654 if (atr < 0) 654 655 return atr; 655 656 ··· 662 663 isl1208_sysfs_show_dtrim(struct device *dev, 663 664 struct device_attribute *attr, char *buf) 664 665 { 665 - int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev)); 666 + int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev->parent)); 666 667 if (dtr < 0) 667 668 return dtr; 668 669 ··· 675 676 isl1208_sysfs_show_usr(struct device *dev, 676 677 struct device_attribute *attr, char *buf) 677 678 { 678 - int usr = isl1208_i2c_get_usr(to_i2c_client(dev)); 679 + int usr = isl1208_i2c_get_usr(to_i2c_client(dev->parent)); 679 680 if (usr < 0) 680 681 return usr; 681 682 ··· 700 701 if (usr < 0 || usr > 0xffff) 701 702 return -EINVAL; 702 703 703 - return isl1208_i2c_set_usr(to_i2c_client(dev), usr) ? -EIO : count; 704 + if (isl1208_i2c_set_usr(to_i2c_client(dev->parent), usr)) 705 + return -EIO; 706 + 707 + return count; 704 708 } 705 709 706 710 static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr, ··· 767 765 rtc->ops = &isl1208_rtc_ops; 768 766 769 767 i2c_set_clientdata(client, rtc); 770 - dev_set_drvdata(&rtc->dev, client); 771 768 772 769 rc = isl1208_i2c_get_sr(client); 773 770 if (rc < 0) { ··· 805 804 evdet_irq = of_irq_get_byname(np, "evdet"); 806 805 } 807 806 808 - rc = sysfs_create_group(&client->dev.kobj, &isl1208_rtc_sysfs_files); 807 + rc = rtc_add_group(rtc, &isl1208_rtc_sysfs_files); 809 808 if (rc) 810 809 return rc; 811 810 ··· 820 819 return rc; 821 820 822 821 return rtc_register_device(rtc); 823 - } 824 - 825 - static int 826 - isl1208_remove(struct i2c_client *client) 827 - { 828 - sysfs_remove_group(&client->dev.kobj, &isl1208_rtc_sysfs_files); 829 - 830 - return 0; 831 822 } 832 823 833 824 static const struct i2c_device_id isl1208_id[] = { ··· 844 851 .of_match_table = of_match_ptr(isl1208_of_match), 845 852 }, 846 853 .probe = isl1208_probe, 847 - .remove = isl1208_remove, 848 854 .id_table = isl1208_id, 849 855 }; 850 856
+1 -1
drivers/rtc/rtc-lib.c
··· 47 47 48 48 49 49 /* 50 - * rtc_time_to_tm64 - Converts time64_t to rtc_time. 50 + * rtc_time64_to_tm - Converts time64_t to rtc_time. 51 51 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. 52 52 */ 53 53 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-m41t80.c
··· 745 745 return -EINVAL; 746 746 wdt_margin = new_margin; 747 747 wdt_ping(); 748 - /* Fall */ 748 + /* Fall through */ 749 749 case WDIOC_GETTIMEOUT: 750 750 return put_user(wdt_margin, (int __user *)arg); 751 751
+2 -3
drivers/rtc/rtc-mrst.c
··· 90 90 unsigned long flags; 91 91 92 92 if (vrtc_is_updating()) 93 - mdelay(20); 93 + msleep(20); 94 94 95 95 spin_lock_irqsave(&rtc_lock, flags); 96 96 time->tm_sec = vrtc_cmos_read(RTC_SECONDS); ··· 261 261 262 262 static int mrst_procfs(struct device *dev, struct seq_file *seq) 263 263 { 264 - unsigned char rtc_control, valid; 264 + unsigned char rtc_control; 265 265 266 266 spin_lock_irq(&rtc_lock); 267 267 rtc_control = vrtc_cmos_read(RTC_CONTROL); 268 - valid = vrtc_cmos_read(RTC_VALID); 269 268 spin_unlock_irq(&rtc_lock); 270 269 271 270 seq_printf(seq,
+8 -5
drivers/rtc/rtc-mt6397.c
··· 332 332 333 333 platform_set_drvdata(pdev, rtc); 334 334 335 + rtc->rtc_dev = devm_rtc_allocate_device(rtc->dev); 336 + if (IS_ERR(rtc->rtc_dev)) 337 + return PTR_ERR(rtc->rtc_dev); 338 + 335 339 ret = request_threaded_irq(rtc->irq, NULL, 336 340 mtk_rtc_irq_handler_thread, 337 341 IRQF_ONESHOT | IRQF_TRIGGER_HIGH, ··· 348 344 349 345 device_init_wakeup(&pdev->dev, 1); 350 346 351 - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, 352 - &mtk_rtc_ops, THIS_MODULE); 353 - if (IS_ERR(rtc->rtc_dev)) { 347 + rtc->rtc_dev->ops = &mtk_rtc_ops; 348 + 349 + ret = rtc_register_device(rtc->rtc_dev); 350 + if (ret) { 354 351 dev_err(&pdev->dev, "register rtc device failed\n"); 355 - ret = PTR_ERR(rtc->rtc_dev); 356 352 goto out_free_irq; 357 353 } 358 354 ··· 369 365 { 370 366 struct mt6397_rtc *rtc = platform_get_drvdata(pdev); 371 367 372 - rtc_device_unregister(rtc->rtc_dev); 373 368 free_irq(rtc->irq, rtc->rtc_dev); 374 369 irq_dispose_mapping(rtc->irq); 375 370
+2 -6
drivers/rtc/rtc-mv.c
··· 125 125 /* hw counts from year 2000, but tm_year is relative to 1900 */ 126 126 alm->time.tm_year = bcd2bin(year) + 100; 127 127 128 - if (rtc_valid_tm(&alm->time) < 0) { 129 - dev_err(dev, "retrieved alarm date/time is not valid.\n"); 130 - rtc_time_to_tm(0, &alm->time); 131 - } 132 - 133 128 alm->enabled = !!readl(ioaddr + RTC_ALARM_INTERRUPT_MASK_REG_OFFS); 134 - return 0; 129 + 130 + return rtc_valid_tm(&alm->time); 135 131 } 136 132 137 133 static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
+16 -12
drivers/rtc/rtc-omap.c
··· 421 421 * The RTC can be used to control an external PMIC via the pmic_power_en pin, 422 422 * which can be configured to transition to OFF on ALARM2 events. 423 423 * 424 - * Notes: 425 - * The two-second alarm offset is the shortest offset possible as the alarm 426 - * registers must be set before the next timer update and the offset 427 - * calculation is too heavy for everything to be done within a single access 428 - * period (~15 us). 429 - * 430 424 * Called with local interrupts disabled. 431 425 */ 432 426 static void omap_rtc_power_off(void) ··· 428 434 struct omap_rtc *rtc = omap_rtc_power_off_rtc; 429 435 struct rtc_time tm; 430 436 unsigned long now; 437 + int seconds; 431 438 u32 val; 432 439 433 440 rtc->type->unlock(rtc); ··· 436 441 val = rtc_readl(rtc, OMAP_RTC_PMIC_REG); 437 442 rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN); 438 443 439 - /* set alarm two seconds from now */ 444 + again: 445 + /* set alarm one second from now */ 440 446 omap_rtc_read_time_raw(rtc, &tm); 447 + seconds = tm.tm_sec; 441 448 bcd2tm(&tm); 442 449 rtc_tm_to_time(&tm, &now); 443 - rtc_time_to_tm(now + 2, &tm); 450 + rtc_time_to_tm(now + 1, &tm); 444 451 445 452 if (tm2bcd(&tm) < 0) { 446 453 dev_err(&rtc->rtc->dev, "power off failed\n"); ··· 467 470 val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); 468 471 rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 469 472 val | OMAP_RTC_INTERRUPTS_IT_ALARM2); 473 + 474 + /* Retry in case roll over happened before alarm was armed. */ 475 + if (rtc_read(rtc, OMAP_RTC_SECONDS_REG) != seconds) { 476 + val = rtc_read(rtc, OMAP_RTC_STATUS_REG); 477 + if (!(val & OMAP_RTC_STATUS_ALARM2)) 478 + goto again; 479 + } 480 + 470 481 rtc->type->lock(rtc); 471 482 472 483 /* 473 - * Wait for alarm to trigger (within two seconds) and external PMIC to 484 + * Wait for alarm to trigger (within one second) and external PMIC to 474 485 * power off the system. Add a 500 ms margin for external latencies 475 486 * (e.g. debounce circuits). 476 487 */ 477 - mdelay(2500); 488 + mdelay(1500); 478 489 } 479 490 480 491 static const struct rtc_class_ops omap_rtc_ops = { ··· 726 721 if (of_id) { 727 722 rtc->type = of_id->data; 728 723 rtc->is_pmic_controller = rtc->type->has_pmic_mode && 729 - of_property_read_bool(pdev->dev.of_node, 730 - "system-power-controller"); 724 + of_device_is_system_power_controller(pdev->dev.of_node); 731 725 } else { 732 726 id_entry = platform_get_device_id(pdev); 733 727 rtc->type = (void *)id_entry->driver_data;
+9 -6
drivers/rtc/rtc-pl030.c
··· 112 112 goto err_rtc; 113 113 } 114 114 115 + rtc->rtc = devm_rtc_allocate_device(&dev->dev); 116 + if (IS_ERR(rtc->rtc)) { 117 + ret = PTR_ERR(rtc->rtc); 118 + goto err_rtc; 119 + } 120 + 121 + rtc->rtc->ops = &pl030_ops; 115 122 rtc->base = ioremap(dev->res.start, resource_size(&dev->res)); 116 123 if (!rtc->base) { 117 124 ret = -ENOMEM; ··· 135 128 if (ret) 136 129 goto err_irq; 137 130 138 - rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops, 139 - THIS_MODULE); 140 - if (IS_ERR(rtc->rtc)) { 141 - ret = PTR_ERR(rtc->rtc); 131 + ret = rtc_register_device(rtc->rtc); 132 + if (ret) 142 133 goto err_reg; 143 - } 144 134 145 135 return 0; 146 136 ··· 158 154 writel(0, rtc->base + RTC_CR); 159 155 160 156 free_irq(dev->irq[0], rtc); 161 - rtc_device_unregister(rtc->rtc); 162 157 iounmap(rtc->base); 163 158 amba_release_regions(dev); 164 159
+9 -9
drivers/rtc/rtc-pl031.c
··· 310 310 device_init_wakeup(&adev->dev, false); 311 311 if (adev->irq[0]) 312 312 free_irq(adev->irq[0], ldata); 313 - rtc_device_unregister(ldata->rtc); 314 313 amba_release_regions(adev); 315 314 316 315 return 0; ··· 382 383 } 383 384 384 385 device_init_wakeup(&adev->dev, true); 385 - ldata->rtc = rtc_device_register("pl031", &adev->dev, ops, 386 - THIS_MODULE); 387 - if (IS_ERR(ldata->rtc)) { 388 - ret = PTR_ERR(ldata->rtc); 386 + ldata->rtc = devm_rtc_allocate_device(&adev->dev); 387 + if (IS_ERR(ldata->rtc)) 388 + return PTR_ERR(ldata->rtc); 389 + 390 + ldata->rtc->ops = ops; 391 + 392 + ret = rtc_register_device(ldata->rtc); 393 + if (ret) 389 394 goto out; 390 - } 391 395 392 396 if (adev->irq[0]) { 393 397 ret = request_irq(adev->irq[0], pl031_interrupt, 394 398 vendor->irqflags, "rtc-pl031", ldata); 395 399 if (ret) 396 - goto out_no_irq; 400 + goto out; 397 401 dev_pm_set_wake_irq(&adev->dev, adev->irq[0]); 398 402 } 399 403 return 0; 400 404 401 - out_no_irq: 402 - rtc_device_unregister(ldata->rtc); 403 405 out: 404 406 amba_release_regions(adev); 405 407 err_req:
+29 -36
drivers/rtc/rtc-rs5c348.c
··· 66 66 u8 txbuf[5+7], *txp; 67 67 int ret; 68 68 69 + ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2)); 70 + if (ret < 0) 71 + return ret; 72 + if (ret & RS5C348_BIT_XSTP) { 73 + txbuf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2); 74 + txbuf[1] = 0; 75 + ret = spi_write_then_read(spi, txbuf, 2, NULL, 0); 76 + if (ret < 0) 77 + return ret; 78 + } 79 + 69 80 /* Transfer 5 bytes before writing SEC. This gives 31us for carry. */ 70 81 txp = txbuf; 71 82 txbuf[0] = RS5C348_CMD_R(RS5C348_REG_CTL2); /* cmd, ctl2 */ ··· 112 101 struct rs5c348_plat_data *pdata = dev_get_platdata(&spi->dev); 113 102 u8 txbuf[5], rxbuf[7]; 114 103 int ret; 104 + 105 + ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2)); 106 + if (ret < 0) 107 + return ret; 108 + if (ret & RS5C348_BIT_VDET) 109 + dev_warn(&spi->dev, "voltage-low detected.\n"); 110 + if (ret & RS5C348_BIT_XSTP) { 111 + dev_warn(&spi->dev, "oscillator-stop detected.\n"); 112 + return -EINVAL; 113 + } 115 114 116 115 /* Transfer 5 byte befores reading SEC. This gives 31us for carry. */ 117 116 txbuf[0] = RS5C348_CMD_R(RS5C348_REG_CTL2); /* cmd, ctl2 */ ··· 164 143 .set_time = rs5c348_rtc_set_time, 165 144 }; 166 145 167 - static struct spi_driver rs5c348_driver; 168 - 169 146 static int rs5c348_probe(struct spi_device *spi) 170 147 { 171 148 int ret; ··· 180 161 ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_SECS)); 181 162 if (ret < 0 || (ret & 0x80)) { 182 163 dev_err(&spi->dev, "not found.\n"); 183 - goto kfree_exit; 164 + return ret; 184 165 } 185 166 186 167 dev_info(&spi->dev, "spiclk %u KHz.\n", 187 168 (spi->max_speed_hz + 500) / 1000); 188 169 189 - /* turn RTC on if it was not on */ 190 - ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2)); 191 - if (ret < 0) 192 - goto kfree_exit; 193 - if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) { 194 - u8 buf[2]; 195 - struct rtc_time tm; 196 - if (ret & RS5C348_BIT_VDET) 197 - dev_warn(&spi->dev, "voltage-low detected.\n"); 198 - if (ret & RS5C348_BIT_XSTP) 199 - dev_warn(&spi->dev, "oscillator-stop detected.\n"); 200 - rtc_time_to_tm(0, &tm); /* 1970/1/1 */ 201 - ret = rs5c348_rtc_set_time(&spi->dev, &tm); 202 - if (ret < 0) 203 - goto kfree_exit; 204 - buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2); 205 - buf[1] = 0; 206 - ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0); 207 - if (ret < 0) 208 - goto kfree_exit; 209 - } 210 - 211 170 ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL1)); 212 171 if (ret < 0) 213 - goto kfree_exit; 172 + return ret; 214 173 if (ret & RS5C348_BIT_24H) 215 174 pdata->rtc_24h = 1; 216 175 217 - rtc = devm_rtc_device_register(&spi->dev, rs5c348_driver.driver.name, 218 - &rs5c348_rtc_ops, THIS_MODULE); 219 - 220 - if (IS_ERR(rtc)) { 221 - ret = PTR_ERR(rtc); 222 - goto kfree_exit; 223 - } 176 + rtc = devm_rtc_allocate_device(&spi->dev); 177 + if (IS_ERR(rtc)) 178 + return PTR_ERR(rtc); 224 179 225 180 pdata->rtc = rtc; 226 181 227 - return 0; 228 - kfree_exit: 229 - return ret; 182 + rtc->ops = &rs5c348_rtc_ops; 183 + 184 + return rtc_register_device(rtc); 230 185 } 231 186 232 187 static struct spi_driver rs5c348_driver = {
+6 -1
drivers/rtc/rtc-rv8803.c
··· 615 615 616 616 static const struct i2c_device_id rv8803_id[] = { 617 617 { "rv8803", rv_8803 }, 618 + { "rx8803", rv_8803 }, 618 619 { "rx8900", rx_8900 }, 619 620 { } 620 621 }; ··· 624 623 static const struct of_device_id rv8803_of_match[] = { 625 624 { 626 625 .compatible = "microcrystal,rv8803", 627 - .data = (void *)rx_8900 626 + .data = (void *)rv_8803 627 + }, 628 + { 629 + .compatible = "epson,rx8803", 630 + .data = (void *)rv_8803 628 631 }, 629 632 { 630 633 .compatible = "epson,rx8900",
+1 -1
drivers/rtc/rtc-s35390a.c
··· 108 108 109 109 static int s35390a_init(struct s35390a *s35390a) 110 110 { 111 - char buf; 111 + u8 buf; 112 112 int ret; 113 113 unsigned initcount = 0; 114 114
+40 -20
drivers/rtc/rtc-sc27xx.c
··· 129 129 SPRD_RTC_ALM_INT_MASK); 130 130 } 131 131 132 - static int sprd_rtc_disable_ints(struct sprd_rtc *rtc) 133 - { 134 - int ret; 135 - 136 - ret = regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, 137 - SPRD_RTC_INT_MASK, 0); 138 - if (ret) 139 - return ret; 140 - 141 - return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 142 - SPRD_RTC_INT_MASK); 143 - } 144 - 145 132 static int sprd_rtc_lock_alarm(struct sprd_rtc *rtc, bool lock) 146 133 { 147 134 int ret; ··· 159 172 return ret; 160 173 } 161 174 162 - return 0; 175 + return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 176 + SPRD_RTC_SPG_UPD_EN); 163 177 } 164 178 165 179 static int sprd_rtc_get_secs(struct sprd_rtc *rtc, enum sprd_rtc_reg_types type, ··· 415 427 u32 val; 416 428 417 429 /* 418 - * If aie_timer is enabled, we should get the normal alarm time. 430 + * Before RTC device is registered, it will check to see if there is an 431 + * alarm already set in RTC hardware, and we always read the normal 432 + * alarm at this time. 433 + * 434 + * Or if aie_timer is enabled, we should get the normal alarm time. 419 435 * Otherwise we should get auxiliary alarm time. 420 436 */ 421 - if (rtc->rtc && rtc->rtc->aie_timer.enabled == 0) 437 + if (rtc->rtc && rtc->rtc->registered && rtc->rtc->aie_timer.enabled == 0) 422 438 return sprd_rtc_read_aux_alarm(dev, alrm); 423 439 424 440 ret = sprd_rtc_get_secs(rtc, SPRD_RTC_ALARM, &secs); ··· 567 575 return 0; 568 576 } 569 577 578 + static int sprd_rtc_check_alarm_int(struct sprd_rtc *rtc) 579 + { 580 + u32 val; 581 + int ret; 582 + 583 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); 584 + if (ret) 585 + return ret; 586 + 587 + /* 588 + * The SPRD_RTC_INT_EN register is not put in always-power-on region 589 + * supplied by VDDRTC, so we should check if we need enable the alarm 590 + * interrupt when system booting. 591 + * 592 + * If we have set SPRD_RTC_POWEROFF_ALM_FLAG which is saved in 593 + * always-power-on region, that means we have set one alarm last time, 594 + * so we should enable the alarm interrupt to help RTC core to see if 595 + * there is an alarm already set in RTC hardware. 596 + */ 597 + if (!(val & SPRD_RTC_POWEROFF_ALM_FLAG)) 598 + return 0; 599 + 600 + return regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, 601 + SPRD_RTC_ALARM_EN, SPRD_RTC_ALARM_EN); 602 + } 603 + 570 604 static int sprd_rtc_probe(struct platform_device *pdev) 571 605 { 572 606 struct device_node *node = pdev->dev.of_node; ··· 626 608 rtc->dev = &pdev->dev; 627 609 platform_set_drvdata(pdev, rtc); 628 610 629 - /* clear all RTC interrupts and disable all RTC interrupts */ 630 - ret = sprd_rtc_disable_ints(rtc); 611 + /* check if we need set the alarm interrupt */ 612 + ret = sprd_rtc_check_alarm_int(rtc); 631 613 if (ret) { 632 - dev_err(&pdev->dev, "failed to disable RTC interrupts\n"); 614 + dev_err(&pdev->dev, "failed to check RTC alarm interrupt\n"); 633 615 return ret; 634 616 } 635 617 ··· 649 631 return ret; 650 632 } 651 633 634 + device_init_wakeup(&pdev->dev, 1); 635 + 652 636 rtc->rtc->ops = &sprd_rtc_ops; 653 637 rtc->rtc->range_min = 0; 654 638 rtc->rtc->range_max = 5662310399LL; 655 639 ret = rtc_register_device(rtc->rtc); 656 640 if (ret) { 657 641 dev_err(&pdev->dev, "failed to register rtc device\n"); 642 + device_init_wakeup(&pdev->dev, 0); 658 643 return ret; 659 644 } 660 645 661 - device_init_wakeup(&pdev->dev, 1); 662 646 return 0; 663 647 } 664 648
+1 -2
drivers/rtc/rtc-sun6i.c
··· 199 199 if (!rtc) 200 200 return; 201 201 202 - clk_data = kzalloc(sizeof(*clk_data) + (sizeof(*clk_data->hws) * 2), 203 - GFP_KERNEL); 202 + clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL); 204 203 if (!clk_data) { 205 204 kfree(rtc); 206 205 return;
+2 -2
drivers/rtc/rtc-sysfs.c
··· 338 338 339 339 new_cnt = old_cnt + add_cnt + 1; 340 340 groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL); 341 - if (IS_ERR_OR_NULL(groups)) 342 - return PTR_ERR(groups); 341 + if (!groups) 342 + return -ENOMEM; 343 343 memcpy(groups, rtc->dev.groups, old_cnt * sizeof(*groups)); 344 344 memcpy(groups + old_cnt, grps, add_cnt * sizeof(*groups)); 345 345 groups[old_cnt + add_cnt] = NULL;
+7 -3
drivers/rtc/rtc-tegra.c
··· 322 322 if (IS_ERR(info->rtc_base)) 323 323 return PTR_ERR(info->rtc_base); 324 324 325 - info->tegra_rtc_irq = platform_get_irq(pdev, 0); 326 - if (info->tegra_rtc_irq <= 0) 327 - return -EBUSY; 325 + ret = platform_get_irq(pdev, 0); 326 + if (ret <= 0) { 327 + dev_err(&pdev->dev, "failed to get platform IRQ: %d\n", ret); 328 + return ret; 329 + } 330 + 331 + info->tegra_rtc_irq = ret; 328 332 329 333 info->clk = devm_clk_get(&pdev->dev, NULL); 330 334 if (IS_ERR(info->clk))
+2 -5
drivers/rtc/rtc-test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * An RTC test device/driver 3 4 * Copyright (C) 2005 Tower Technologies 4 5 * Author: Alessandro Zummo <a.zummo@towertech.it> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 6 */ 10 7 11 8 #include <linux/module.h> ··· 194 197 195 198 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 196 199 MODULE_DESCRIPTION("RTC test driver/device"); 197 - MODULE_LICENSE("GPL"); 200 + MODULE_LICENSE("GPL v2"); 198 201 199 202 module_init(test_init); 200 203 module_exit(test_exit);
+1 -3
drivers/rtc/rtc-tx4939.c
··· 253 253 struct resource *res; 254 254 int irq, ret; 255 255 struct nvmem_config nvmem_cfg = { 256 - .name = "rv8803_nvram", 257 - .word_size = 4, 258 - .stride = 4, 256 + .name = "tx4939_nvram", 259 257 .size = TX4939_RTC_REG_RAMSIZE, 260 258 .reg_read = tx4939_nvram_read, 261 259 .reg_write = tx4939_nvram_write,
+3 -6
drivers/rtc/rtc-vr41xx.c
··· 136 136 time64_t epoch_sec, current_sec; 137 137 138 138 epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); 139 - current_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, 140 - time->tm_hour, time->tm_min, time->tm_sec); 139 + current_sec = rtc_tm_to_time64(time); 141 140 142 141 write_elapsed_second(current_sec - epoch_sec); 143 142 ··· 157 158 158 159 spin_unlock_irq(&rtc_lock); 159 160 160 - rtc_time_to_tm((high << 17) | (mid << 1) | (low >> 15), time); 161 + rtc_time64_to_tm((high << 17) | (mid << 1) | (low >> 15), time); 161 162 162 163 return 0; 163 164 } ··· 165 166 static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 166 167 { 167 168 time64_t alarm_sec; 168 - struct rtc_time *time = &wkalrm->time; 169 169 170 - alarm_sec = mktime64(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, 171 - time->tm_hour, time->tm_min, time->tm_sec); 170 + alarm_sec = rtc_tm_to_time64(&wkalrm->time); 172 171 173 172 spin_lock_irq(&rtc_lock); 174 173
+16 -5
include/linux/rtc.h
··· 167 167 #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */ 168 168 #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */ 169 169 170 - extern struct rtc_device *rtc_device_register(const char *name, 171 - struct device *dev, 172 - const struct rtc_class_ops *ops, 173 - struct module *owner); 174 170 extern struct rtc_device *devm_rtc_device_register(struct device *dev, 175 171 const char *name, 176 172 const struct rtc_class_ops *ops, 177 173 struct module *owner); 178 174 struct rtc_device *devm_rtc_allocate_device(struct device *dev); 179 175 int __rtc_register_device(struct module *owner, struct rtc_device *rtc); 180 - extern void rtc_device_unregister(struct rtc_device *rtc); 181 176 extern void devm_rtc_device_unregister(struct device *dev, 182 177 struct rtc_device *rtc); 183 178 ··· 272 277 static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} 273 278 #endif 274 279 280 + #ifdef CONFIG_RTC_INTF_SYSFS 281 + int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp); 282 + int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps); 283 + #else 284 + static inline 285 + int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp) 286 + { 287 + return 0; 288 + } 289 + 290 + static inline 291 + int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) 292 + { 293 + return 0; 294 + } 295 + #endif 275 296 #endif /* _LINUX_RTC_H_ */