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

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

Pull RTC updates from Alexandre Belloni:
"This contains a few series that have been in preparation for a while
and that will help systems with RTCs that will fail in 2038, 2069 or
2100.

Subsystem:
- Add tracepoints
- Rework of the RTC/nvmem API to allow drivers to discard struct
nvmem_config after registration
- New range API, drivers can now expose the useful range of the RTC
- New offset API the core is now able to add an offset to the RTC
time, modifying the supported range.
- Multiple rtc_time64_to_tm fixes
- Handle time_t overflow on 32 bit platforms in the core instead of
letting drivers do crazy things.
- remove rtc_control API

New driver:
- Intersil ISL12026

Drivers:
- Drivers exposing the RTC non volatile memory have been converted to
use nvmem
- Removed useless time and date validation
- Removed an indirection pattern that was a cargo cult from ancient
drivers
- Removed VLA usage
- Fixed a possible race condition in probe functions
- AB8540 support is dropped from ab8500
- pcf85363 now has alarm support"

* tag 'rtc-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (128 commits)
rtc: snvs: Fix usage of snvs_rtc_enable
rtc: mt7622: fix module autoloading for OF platform drivers
rtc: isl12022: use true and false for boolean values
rtc: ab8500: Drop AB8540 support
rtc: remove a warning during scripts/kernel-doc step
rtc: 88pm860x: remove artificial limitation
rtc: 88pm80x: remove artificial limitation
rtc: st-lpc: remove artificial limitation
rtc: mrst: remove artificial limitation
rtc: mv: remove artificial limitation
rtc: hctosys: Ensure system time doesn't overflow time_t
parisc: time: stop validating rtc_time in .read_time
rtc: pcf85063: fix clearing bits in pcf85063_start_clock
rtc: at91sam9: Set name of regmap_config
rtc: s5m: Remove VLA usage
rtc: s5m: Move enum from rtc.h to rtc-s5m.c
rtc: remove VLA usage
rtc: Add useful timestamp definitions
rtc: Add one offset seconds to expand RTC range
rtc: Factor out the RTC range validation into rtc_valid_range()
...

+1812 -1086
+8 -8
Documentation/ABI/testing/sysfs-class-rtc
··· 43 43 Description: 44 44 (RO) The name of the RTC corresponding to this sysfs directory 45 45 46 + What: /sys/class/rtc/rtcX/range 47 + Date: January 2018 48 + KernelVersion: 4.16 49 + Contact: linux-rtc@vger.kernel.org 50 + Description: 51 + Valid time range for the RTC, as seconds from epoch, formatted 52 + as [min, max] 53 + 46 54 What: /sys/class/rtc/rtcX/since_epoch 47 55 Date: March 2006 48 56 KernelVersion: 2.6.17 ··· 64 56 Contact: linux-rtc@vger.kernel.org 65 57 Description: 66 58 (RO) RTC-provided time in 24-hour notation (hh:mm:ss) 67 - 68 - What: /sys/class/rtc/rtcX/*/nvmem 69 - Date: February 2016 70 - KernelVersion: 4.6 71 - Contact: linux-rtc@vger.kernel.org 72 - Description: 73 - (RW) The non volatile storage exported as a raw file, as 74 - described in Documentation/nvmem/nvmem.txt 75 59 76 60 What: /sys/class/rtc/rtcX/offset 77 61 Date: February 2016
+28
Documentation/devicetree/bindings/rtc/isil,isl12026.txt
··· 1 + ISL12026 I2C RTC/EEPROM 2 + 3 + ISL12026 is an I2C RTC/EEPROM combination device. The RTC and control 4 + registers respond at bus address 0x6f, and the EEPROM array responds 5 + at bus address 0x57. The canonical "reg" value will be for the RTC portion. 6 + 7 + Required properties supported by the device: 8 + 9 + - "compatible": must be "isil,isl12026" 10 + - "reg": I2C bus address of the device (always 0x6f) 11 + 12 + Optional properties: 13 + 14 + - "isil,pwr-bsw": If present PWR.BSW bit must be set to the specified 15 + value for proper operation. 16 + 17 + - "isil,pwr-sbib": If present PWR.SBIB bit must be set to the specified 18 + value for proper operation. 19 + 20 + 21 + Example: 22 + 23 + rtc@6f { 24 + compatible = "isil,isl12026"; 25 + reg = <0x6f>; 26 + isil,pwr-bsw = <0>; 27 + isil,pwr-sbib = <1>; 28 + }
+1 -1
MAINTAINERS
··· 11810 11810 11811 11811 REAL TIME CLOCK (RTC) SUBSYSTEM 11812 11812 M: Alessandro Zummo <a.zummo@towertech.it> 11813 - M: Alexandre Belloni <alexandre.belloni@free-electrons.com> 11813 + M: Alexandre Belloni <alexandre.belloni@bootlin.com> 11814 11814 L: linux-rtc@vger.kernel.org 11815 11815 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 11816 11816 T: git git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git
+1 -1
arch/parisc/kernel/time.c
··· 174 174 175 175 /* we treat tod_sec as unsigned, so this can work until year 2106 */ 176 176 rtc_time64_to_tm(tod_data.tod_sec, tm); 177 - return rtc_valid_tm(tm); 177 + return 0; 178 178 } 179 179 180 180 static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm)
-83
drivers/char/rtc.c
··· 809 809 } 810 810 #endif 811 811 812 - int rtc_register(rtc_task_t *task) 813 - { 814 - #ifndef RTC_IRQ 815 - return -EIO; 816 - #else 817 - if (task == NULL || task->func == NULL) 818 - return -EINVAL; 819 - spin_lock_irq(&rtc_lock); 820 - if (rtc_status & RTC_IS_OPEN) { 821 - spin_unlock_irq(&rtc_lock); 822 - return -EBUSY; 823 - } 824 - spin_lock(&rtc_task_lock); 825 - if (rtc_callback) { 826 - spin_unlock(&rtc_task_lock); 827 - spin_unlock_irq(&rtc_lock); 828 - return -EBUSY; 829 - } 830 - rtc_status |= RTC_IS_OPEN; 831 - rtc_callback = task; 832 - spin_unlock(&rtc_task_lock); 833 - spin_unlock_irq(&rtc_lock); 834 - return 0; 835 - #endif 836 - } 837 - EXPORT_SYMBOL(rtc_register); 838 - 839 - int rtc_unregister(rtc_task_t *task) 840 - { 841 - #ifndef RTC_IRQ 842 - return -EIO; 843 - #else 844 - unsigned char tmp; 845 - 846 - spin_lock_irq(&rtc_lock); 847 - spin_lock(&rtc_task_lock); 848 - if (rtc_callback != task) { 849 - spin_unlock(&rtc_task_lock); 850 - spin_unlock_irq(&rtc_lock); 851 - return -ENXIO; 852 - } 853 - rtc_callback = NULL; 854 - 855 - /* disable controls */ 856 - if (!hpet_mask_rtc_irq_bit(RTC_PIE | RTC_AIE | RTC_UIE)) { 857 - tmp = CMOS_READ(RTC_CONTROL); 858 - tmp &= ~RTC_PIE; 859 - tmp &= ~RTC_AIE; 860 - tmp &= ~RTC_UIE; 861 - CMOS_WRITE(tmp, RTC_CONTROL); 862 - CMOS_READ(RTC_INTR_FLAGS); 863 - } 864 - if (rtc_status & RTC_TIMER_ON) { 865 - rtc_status &= ~RTC_TIMER_ON; 866 - del_timer(&rtc_irq_timer); 867 - } 868 - rtc_status &= ~RTC_IS_OPEN; 869 - spin_unlock(&rtc_task_lock); 870 - spin_unlock_irq(&rtc_lock); 871 - return 0; 872 - #endif 873 - } 874 - EXPORT_SYMBOL(rtc_unregister); 875 - 876 - int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg) 877 - { 878 - #ifndef RTC_IRQ 879 - return -EIO; 880 - #else 881 - unsigned long flags; 882 - if (cmd != RTC_PIE_ON && cmd != RTC_PIE_OFF && cmd != RTC_IRQP_SET) 883 - return -EINVAL; 884 - spin_lock_irqsave(&rtc_task_lock, flags); 885 - if (rtc_callback != task) { 886 - spin_unlock_irqrestore(&rtc_task_lock, flags); 887 - return -ENXIO; 888 - } 889 - spin_unlock_irqrestore(&rtc_task_lock, flags); 890 - return rtc_do_ioctl(cmd, arg, 1); 891 - #endif 892 - } 893 - EXPORT_SYMBOL(rtc_control); 894 - 895 812 /* 896 813 * The various file operations we support. 897 814 */
+12 -1
drivers/rtc/Kconfig
··· 407 407 This driver can also be built as a module. If so, the module 408 408 will be called rtc-isl12022. 409 409 410 + config RTC_DRV_ISL12026 411 + tristate "Intersil ISL12026" 412 + depends on OF || COMPILE_TEST 413 + help 414 + If you say yes here you get support for the 415 + Intersil ISL12026 RTC chip. 416 + 417 + This driver can also be built as a module. If so, the module 418 + will be called rtc-isl12026. 419 + 410 420 config RTC_DRV_X1205 411 421 tristate "Xicor/Intersil X1205" 412 422 help ··· 1423 1413 config RTC_DRV_AT91SAM9 1424 1414 tristate "AT91SAM9 RTT as RTC" 1425 1415 depends on ARCH_AT91 || COMPILE_TEST 1416 + depends on HAS_IOMEM 1426 1417 select MFD_SYSCON 1427 1418 help 1428 1419 Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which ··· 1513 1502 1514 1503 config RTC_DRV_TX4939 1515 1504 tristate "TX4939 SoC" 1516 - depends on SOC_TX4939 1505 + depends on SOC_TX4939 || COMPILE_TEST 1517 1506 help 1518 1507 Driver for the internal RTC (Realtime Clock) module found on 1519 1508 Toshiba TX4939 SoC.
+1
drivers/rtc/Makefile
··· 75 75 obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o 76 76 obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o 77 77 obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o 78 + obj-$(CONFIG_RTC_DRV_ISL12026) += rtc-isl12026.o 78 79 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 79 80 obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 80 81 obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o
+73 -4
drivers/rtc/class.c
··· 211 211 return id; 212 212 } 213 213 214 + static void rtc_device_get_offset(struct rtc_device *rtc) 215 + { 216 + time64_t range_secs; 217 + u32 start_year; 218 + int ret; 219 + 220 + /* 221 + * If RTC driver did not implement the range of RTC hardware device, 222 + * then we can not expand the RTC range by adding or subtracting one 223 + * offset. 224 + */ 225 + if (rtc->range_min == rtc->range_max) 226 + return; 227 + 228 + ret = device_property_read_u32(rtc->dev.parent, "start-year", 229 + &start_year); 230 + if (!ret) { 231 + rtc->start_secs = mktime64(start_year, 1, 1, 0, 0, 0); 232 + rtc->set_start_time = true; 233 + } 234 + 235 + /* 236 + * If user did not implement the start time for RTC driver, then no 237 + * need to expand the RTC range. 238 + */ 239 + if (!rtc->set_start_time) 240 + return; 241 + 242 + range_secs = rtc->range_max - rtc->range_min + 1; 243 + 244 + /* 245 + * If the start_secs is larger than the maximum seconds (rtc->range_max) 246 + * supported by RTC hardware or the maximum seconds of new expanded 247 + * range (start_secs + rtc->range_max - rtc->range_min) is less than 248 + * rtc->range_min, which means the minimum seconds (rtc->range_min) of 249 + * RTC hardware will be mapped to start_secs by adding one offset, so 250 + * the offset seconds calculation formula should be: 251 + * rtc->offset_secs = rtc->start_secs - rtc->range_min; 252 + * 253 + * If the start_secs is larger than the minimum seconds (rtc->range_min) 254 + * supported by RTC hardware, then there is one region is overlapped 255 + * between the original RTC hardware range and the new expanded range, 256 + * and this overlapped region do not need to be mapped into the new 257 + * expanded range due to it is valid for RTC device. So the minimum 258 + * seconds of RTC hardware (rtc->range_min) should be mapped to 259 + * rtc->range_max + 1, then the offset seconds formula should be: 260 + * rtc->offset_secs = rtc->range_max - rtc->range_min + 1; 261 + * 262 + * If the start_secs is less than the minimum seconds (rtc->range_min), 263 + * which is similar to case 2. So the start_secs should be mapped to 264 + * start_secs + rtc->range_max - rtc->range_min + 1, then the 265 + * offset seconds formula should be: 266 + * rtc->offset_secs = -(rtc->range_max - rtc->range_min + 1); 267 + * 268 + * Otherwise the offset seconds should be 0. 269 + */ 270 + if (rtc->start_secs > rtc->range_max || 271 + rtc->start_secs + range_secs - 1 < rtc->range_min) 272 + rtc->offset_secs = rtc->start_secs - rtc->range_min; 273 + else if (rtc->start_secs > rtc->range_min) 274 + rtc->offset_secs = range_secs; 275 + else if (rtc->start_secs < rtc->range_min) 276 + rtc->offset_secs = -range_secs; 277 + else 278 + rtc->offset_secs = 0; 279 + } 280 + 214 281 /** 215 282 * rtc_device_register - register w/ RTC class 216 283 * @dev: the device to register ··· 313 246 rtc->dev.parent = dev; 314 247 315 248 dev_set_name(&rtc->dev, "rtc%d", id); 249 + 250 + rtc_device_get_offset(rtc); 316 251 317 252 /* Check to see if there is an ALARM already set in hw */ 318 253 err = __rtc_read_alarm(rtc, &alrm); ··· 362 293 */ 363 294 void rtc_device_unregister(struct rtc_device *rtc) 364 295 { 365 - rtc_nvmem_unregister(rtc); 366 - 367 296 mutex_lock(&rtc->ops_lock); 368 297 /* 369 298 * Remove innards of this RTC, then disable it, before ··· 379 312 { 380 313 struct rtc_device *rtc = *(struct rtc_device **)res; 381 314 315 + rtc_nvmem_unregister(rtc); 382 316 rtc_device_unregister(rtc); 383 317 } 384 318 ··· 450 382 { 451 383 struct rtc_device *rtc = *(struct rtc_device **)res; 452 384 385 + rtc_nvmem_unregister(rtc); 386 + 453 387 if (rtc->registered) 454 388 rtc_device_unregister(rtc); 455 389 else ··· 505 435 return -EINVAL; 506 436 507 437 rtc->owner = owner; 438 + rtc_device_get_offset(rtc); 508 439 509 440 /* Check to see if there is an ALARM already set in hw */ 510 441 err = __rtc_read_alarm(rtc, &alrm); ··· 523 452 MAJOR(rtc->dev.devt), rtc->id); 524 453 525 454 rtc_proc_add_device(rtc); 526 - 527 - rtc_nvmem_register(rtc); 528 455 529 456 rtc->registered = true; 530 457 dev_info(rtc->dev.parent, "registered as %s\n",
+5
drivers/rtc/hctosys.c
··· 49 49 50 50 tv64.tv_sec = rtc_tm_to_time64(&tm); 51 51 52 + #if BITS_PER_LONG == 32 53 + if (tv64.tv_sec > INT_MAX) 54 + goto err_read; 55 + #endif 56 + 52 57 err = do_settimeofday64(&tv64); 53 58 54 59 dev_info(rtc->dev.parent,
+107
drivers/rtc/interface.c
··· 17 17 #include <linux/log2.h> 18 18 #include <linux/workqueue.h> 19 19 20 + #define CREATE_TRACE_POINTS 21 + #include <trace/events/rtc.h> 22 + 20 23 static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); 21 24 static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); 25 + 26 + static void rtc_add_offset(struct rtc_device *rtc, struct rtc_time *tm) 27 + { 28 + time64_t secs; 29 + 30 + if (!rtc->offset_secs) 31 + return; 32 + 33 + secs = rtc_tm_to_time64(tm); 34 + 35 + /* 36 + * Since the reading time values from RTC device are always in the RTC 37 + * original valid range, but we need to skip the overlapped region 38 + * between expanded range and original range, which is no need to add 39 + * the offset. 40 + */ 41 + if ((rtc->start_secs > rtc->range_min && secs >= rtc->start_secs) || 42 + (rtc->start_secs < rtc->range_min && 43 + secs <= (rtc->start_secs + rtc->range_max - rtc->range_min))) 44 + return; 45 + 46 + rtc_time64_to_tm(secs + rtc->offset_secs, tm); 47 + } 48 + 49 + static void rtc_subtract_offset(struct rtc_device *rtc, struct rtc_time *tm) 50 + { 51 + time64_t secs; 52 + 53 + if (!rtc->offset_secs) 54 + return; 55 + 56 + secs = rtc_tm_to_time64(tm); 57 + 58 + /* 59 + * If the setting time values are in the valid range of RTC hardware 60 + * device, then no need to subtract the offset when setting time to RTC 61 + * device. Otherwise we need to subtract the offset to make the time 62 + * values are valid for RTC hardware device. 63 + */ 64 + if (secs >= rtc->range_min && secs <= rtc->range_max) 65 + return; 66 + 67 + rtc_time64_to_tm(secs - rtc->offset_secs, tm); 68 + } 69 + 70 + static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) 71 + { 72 + if (rtc->range_min != rtc->range_max) { 73 + time64_t time = rtc_tm_to_time64(tm); 74 + time64_t range_min = rtc->set_start_time ? rtc->start_secs : 75 + rtc->range_min; 76 + time64_t range_max = rtc->set_start_time ? 77 + (rtc->start_secs + rtc->range_max - rtc->range_min) : 78 + rtc->range_max; 79 + 80 + if (time < range_min || time > range_max) 81 + return -ERANGE; 82 + } 83 + 84 + return 0; 85 + } 22 86 23 87 static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) 24 88 { ··· 99 35 err); 100 36 return err; 101 37 } 38 + 39 + rtc_add_offset(rtc, tm); 102 40 103 41 err = rtc_valid_tm(tm); 104 42 if (err < 0) ··· 119 53 120 54 err = __rtc_read_time(rtc, tm); 121 55 mutex_unlock(&rtc->ops_lock); 56 + 57 + trace_rtc_read_time(rtc_tm_to_time64(tm), err); 122 58 return err; 123 59 } 124 60 EXPORT_SYMBOL_GPL(rtc_read_time); ··· 132 64 err = rtc_valid_tm(tm); 133 65 if (err != 0) 134 66 return err; 67 + 68 + err = rtc_valid_range(rtc, tm); 69 + if (err) 70 + return err; 71 + 72 + rtc_subtract_offset(rtc, tm); 135 73 136 74 err = mutex_lock_interruptible(&rtc->ops_lock); 137 75 if (err) ··· 161 87 mutex_unlock(&rtc->ops_lock); 162 88 /* A timer might have just expired */ 163 89 schedule_work(&rtc->irqwork); 90 + 91 + trace_rtc_set_time(rtc_tm_to_time64(tm), err); 164 92 return err; 165 93 } 166 94 EXPORT_SYMBOL_GPL(rtc_set_time); ··· 195 119 } 196 120 197 121 mutex_unlock(&rtc->ops_lock); 122 + 123 + trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err); 198 124 return err; 199 125 } 200 126 ··· 394 316 } 395 317 mutex_unlock(&rtc->ops_lock); 396 318 319 + trace_rtc_read_alarm(rtc_tm_to_time64(&alarm->time), err); 397 320 return err; 398 321 } 399 322 EXPORT_SYMBOL_GPL(rtc_read_alarm); ··· 408 329 err = rtc_valid_tm(&alarm->time); 409 330 if (err) 410 331 return err; 332 + 333 + rtc_subtract_offset(rtc, &alarm->time); 411 334 scheduled = rtc_tm_to_time64(&alarm->time); 412 335 413 336 /* Make sure we're not setting alarms in the past */ ··· 433 352 else 434 353 err = rtc->ops->set_alarm(rtc->dev.parent, alarm); 435 354 355 + trace_rtc_set_alarm(rtc_tm_to_time64(&alarm->time), err); 436 356 return err; 437 357 } 438 358 ··· 443 361 444 362 err = rtc_valid_tm(&alarm->time); 445 363 if (err != 0) 364 + return err; 365 + 366 + err = rtc_valid_range(rtc, &alarm->time); 367 + if (err) 446 368 return err; 447 369 448 370 err = mutex_lock_interruptible(&rtc->ops_lock); ··· 461 375 err = rtc_timer_enqueue(rtc, &rtc->aie_timer); 462 376 463 377 mutex_unlock(&rtc->ops_lock); 378 + 379 + rtc_add_offset(rtc, &alarm->time); 464 380 return err; 465 381 } 466 382 EXPORT_SYMBOL_GPL(rtc_set_alarm); ··· 494 406 495 407 rtc->aie_timer.enabled = 1; 496 408 timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); 409 + trace_rtc_timer_enqueue(&rtc->aie_timer); 497 410 } 498 411 mutex_unlock(&rtc->ops_lock); 499 412 return err; ··· 524 435 err = rtc->ops->alarm_irq_enable(rtc->dev.parent, enabled); 525 436 526 437 mutex_unlock(&rtc->ops_lock); 438 + 439 + trace_rtc_alarm_irq_enable(enabled, err); 527 440 return err; 528 441 } 529 442 EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); ··· 800 709 rtc->pie_enabled = enabled; 801 710 } 802 711 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 712 + 713 + trace_rtc_irq_set_state(enabled, err); 803 714 return err; 804 715 } 805 716 EXPORT_SYMBOL_GPL(rtc_irq_set_state); ··· 838 745 } 839 746 } 840 747 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 748 + 749 + trace_rtc_irq_set_freq(freq, err); 841 750 return err; 842 751 } 843 752 EXPORT_SYMBOL_GPL(rtc_irq_set_freq); ··· 874 779 } 875 780 876 781 timerqueue_add(&rtc->timerqueue, &timer->node); 782 + trace_rtc_timer_enqueue(timer); 877 783 if (!next || ktime_before(timer->node.expires, next->expires)) { 878 784 struct rtc_wkalrm alarm; 879 785 int err; ··· 886 790 schedule_work(&rtc->irqwork); 887 791 } else if (err) { 888 792 timerqueue_del(&rtc->timerqueue, &timer->node); 793 + trace_rtc_timer_dequeue(timer); 889 794 timer->enabled = 0; 890 795 return err; 891 796 } ··· 900 803 return; 901 804 902 805 rtc->ops->alarm_irq_enable(rtc->dev.parent, false); 806 + trace_rtc_alarm_irq_enable(0, 0); 903 807 } 904 808 905 809 /** ··· 919 821 { 920 822 struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); 921 823 timerqueue_del(&rtc->timerqueue, &timer->node); 824 + trace_rtc_timer_dequeue(timer); 922 825 timer->enabled = 0; 923 826 if (next == &timer->node) { 924 827 struct rtc_wkalrm alarm; ··· 970 871 /* expire timer */ 971 872 timer = container_of(next, struct rtc_timer, node); 972 873 timerqueue_del(&rtc->timerqueue, &timer->node); 874 + trace_rtc_timer_dequeue(timer); 973 875 timer->enabled = 0; 974 876 if (timer->task.func) 975 877 timer->task.func(timer->task.private_data); 976 878 879 + trace_rtc_timer_fired(timer); 977 880 /* Re-add/fwd periodic timers */ 978 881 if (ktime_to_ns(timer->period)) { 979 882 timer->node.expires = ktime_add(timer->node.expires, 980 883 timer->period); 981 884 timer->enabled = 1; 982 885 timerqueue_add(&rtc->timerqueue, &timer->node); 886 + trace_rtc_timer_enqueue(timer); 983 887 } 984 888 } 985 889 ··· 1004 902 1005 903 timer = container_of(next, struct rtc_timer, node); 1006 904 timerqueue_del(&rtc->timerqueue, &timer->node); 905 + trace_rtc_timer_dequeue(timer); 1007 906 timer->enabled = 0; 1008 907 dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err); 1009 908 goto again; ··· 1095 992 mutex_lock(&rtc->ops_lock); 1096 993 ret = rtc->ops->read_offset(rtc->dev.parent, offset); 1097 994 mutex_unlock(&rtc->ops_lock); 995 + 996 + trace_rtc_read_offset(*offset, ret); 1098 997 return ret; 1099 998 } 1100 999 ··· 1130 1025 mutex_lock(&rtc->ops_lock); 1131 1026 ret = rtc->ops->set_offset(rtc->dev.parent, offset); 1132 1027 mutex_unlock(&rtc->ops_lock); 1028 + 1029 + trace_rtc_set_offset(offset, ret); 1133 1030 return ret; 1134 1031 }
+17 -12
drivers/rtc/nvmem.c
··· 14 14 #include <linux/rtc.h> 15 15 #include <linux/sysfs.h> 16 16 17 - #include "rtc-core.h" 18 - 19 17 /* 20 18 * Deprecated ABI compatibility, this should be removed at some point 21 19 */ ··· 44 46 return nvmem_device_write(rtc->nvmem, off, count, buf); 45 47 } 46 48 47 - static int rtc_nvram_register(struct rtc_device *rtc) 49 + static int rtc_nvram_register(struct rtc_device *rtc, size_t size) 48 50 { 49 51 int err; 50 52 ··· 62 64 63 65 rtc->nvram->read = rtc_nvram_read; 64 66 rtc->nvram->write = rtc_nvram_write; 65 - rtc->nvram->size = rtc->nvmem_config->size; 67 + rtc->nvram->size = size; 66 68 67 69 err = sysfs_create_bin_file(&rtc->dev.parent->kobj, 68 70 rtc->nvram); ··· 82 84 /* 83 85 * New ABI, uses nvmem 84 86 */ 85 - void rtc_nvmem_register(struct rtc_device *rtc) 87 + int rtc_nvmem_register(struct rtc_device *rtc, 88 + struct nvmem_config *nvmem_config) 86 89 { 87 - if (!rtc->nvmem_config) 88 - return; 90 + if (!IS_ERR_OR_NULL(rtc->nvmem)) 91 + return -EBUSY; 89 92 90 - rtc->nvmem_config->dev = &rtc->dev; 91 - rtc->nvmem_config->owner = rtc->owner; 92 - rtc->nvmem = nvmem_register(rtc->nvmem_config); 93 + if (!nvmem_config) 94 + return -ENODEV; 95 + 96 + nvmem_config->dev = rtc->dev.parent; 97 + nvmem_config->owner = rtc->owner; 98 + rtc->nvmem = nvmem_register(nvmem_config); 93 99 if (IS_ERR_OR_NULL(rtc->nvmem)) 94 - return; 100 + return PTR_ERR(rtc->nvmem); 95 101 96 102 /* Register the old ABI */ 97 103 if (rtc->nvram_old_abi) 98 - rtc_nvram_register(rtc); 104 + rtc_nvram_register(rtc, nvmem_config->size); 105 + 106 + return 0; 99 107 } 108 + EXPORT_SYMBOL_GPL(rtc_nvmem_register); 100 109 101 110 void rtc_nvmem_unregister(struct rtc_device *rtc) 102 111 {
+2 -2
drivers/rtc/rtc-88pm80x.c
··· 134 134 struct pm80x_rtc_info *info = dev_get_drvdata(dev); 135 135 unsigned char buf[4]; 136 136 unsigned long ticks, base, data; 137 - if ((tm->tm_year < 70) || (tm->tm_year > 138)) { 137 + if (tm->tm_year > 206) { 138 138 dev_dbg(info->dev, 139 - "Set time %d out of range. Please set time between 1970 to 2038.\n", 139 + "Set time %d out of range. Please set time between 1970 to 2106.\n", 140 140 1900 + tm->tm_year); 141 141 return -EINVAL; 142 142 }
+2 -2
drivers/rtc/rtc-88pm860x.c
··· 135 135 unsigned char buf[4]; 136 136 unsigned long ticks, base, data; 137 137 138 - if ((tm->tm_year < 70) || (tm->tm_year > 138)) { 138 + if (tm->tm_year > 206) { 139 139 dev_dbg(info->dev, "Set time %d out of range. " 140 - "Please set time between 1970 to 2038.\n", 140 + "Please set time between 1970 to 2106.\n", 141 141 1900 + tm->tm_year); 142 142 return -EINVAL; 143 143 }
+1 -3
drivers/rtc/rtc-ab-b5ze-s3.c
··· 217 217 { 218 218 struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); 219 219 u8 regs[ABB5ZES3_REG_RTC_SC + ABB5ZES3_RTC_SEC_LEN]; 220 - int ret; 220 + int ret = 0; 221 221 222 222 /* 223 223 * As we need to read CTRL1 register anyway to access 24/12h ··· 254 254 tm->tm_wday = bcd2bin(regs[ABB5ZES3_REG_RTC_DW]); 255 255 tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ 256 256 tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; 257 - 258 - ret = rtc_valid_tm(tm); 259 257 260 258 err: 261 259 return ret;
+1 -1
drivers/rtc/rtc-ab3100.c
··· 106 106 107 107 rtc_time64_to_tm(time, tm); 108 108 109 - return rtc_valid_tm(tm); 109 + return 0; 110 110 } 111 111 112 112 static int ab3100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+1 -56
drivers/rtc/rtc-ab8500.c
··· 36 36 #define AB8500_RTC_FORCE_BKUP_REG 0x0D 37 37 #define AB8500_RTC_CALIB_REG 0x0E 38 38 #define AB8500_RTC_SWITCH_STAT_REG 0x0F 39 - #define AB8540_RTC_ALRM_SEC 0x22 40 - #define AB8540_RTC_ALRM_MIN_LOW_REG 0x23 41 - #define AB8540_RTC_ALRM_MIN_MID_REG 0x24 42 - #define AB8540_RTC_ALRM_MIN_HI_REG 0x25 43 39 44 40 /* RtcReadRequest bits */ 45 41 #define RTC_READ_REQUEST 0x01 ··· 57 61 static const u8 ab8500_rtc_alarm_regs[] = { 58 62 AB8500_RTC_ALRM_MIN_HI_REG, AB8500_RTC_ALRM_MIN_MID_REG, 59 63 AB8500_RTC_ALRM_MIN_LOW_REG 60 - }; 61 - 62 - static const u8 ab8540_rtc_alarm_regs[] = { 63 - AB8540_RTC_ALRM_MIN_HI_REG, AB8540_RTC_ALRM_MIN_MID_REG, 64 - AB8540_RTC_ALRM_MIN_LOW_REG, AB8540_RTC_ALRM_SEC 65 64 }; 66 65 67 66 /* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */ ··· 122 131 secs += get_elapsed_seconds(AB8500_RTC_EPOCH); 123 132 124 133 rtc_time_to_tm(secs, tm); 125 - return rtc_valid_tm(tm); 134 + return 0; 126 135 } 127 136 128 137 static int ab8500_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 268 277 return ab8500_rtc_irq_enable(dev, alarm->enabled); 269 278 } 270 279 271 - static int ab8540_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 272 - { 273 - int retval, i; 274 - unsigned char buf[ARRAY_SIZE(ab8540_rtc_alarm_regs)]; 275 - unsigned long mins, secs = 0; 276 - 277 - if (alarm->time.tm_year < (AB8500_RTC_EPOCH - 1900)) { 278 - dev_dbg(dev, "year should be equal to or greater than %d\n", 279 - AB8500_RTC_EPOCH); 280 - return -EINVAL; 281 - } 282 - 283 - /* Get the number of seconds since 1970 */ 284 - rtc_tm_to_time(&alarm->time, &secs); 285 - 286 - /* 287 - * Convert it to the number of seconds since 01-01-2000 00:00:00 288 - */ 289 - secs -= get_elapsed_seconds(AB8500_RTC_EPOCH); 290 - mins = secs / 60; 291 - 292 - buf[3] = secs % 60; 293 - buf[2] = mins & 0xFF; 294 - buf[1] = (mins >> 8) & 0xFF; 295 - buf[0] = (mins >> 16) & 0xFF; 296 - 297 - /* Set the alarm time */ 298 - for (i = 0; i < ARRAY_SIZE(ab8540_rtc_alarm_regs); i++) { 299 - retval = abx500_set_register_interruptible(dev, AB8500_RTC, 300 - ab8540_rtc_alarm_regs[i], buf[i]); 301 - if (retval < 0) 302 - return retval; 303 - } 304 - 305 - return ab8500_rtc_irq_enable(dev, alarm->enabled); 306 - } 307 - 308 280 static int ab8500_rtc_set_calibration(struct device *dev, int calibration) 309 281 { 310 282 int retval; ··· 389 435 .alarm_irq_enable = ab8500_rtc_irq_enable, 390 436 }; 391 437 392 - static const struct rtc_class_ops ab8540_rtc_ops = { 393 - .read_time = ab8500_rtc_read_time, 394 - .set_time = ab8500_rtc_set_time, 395 - .read_alarm = ab8500_rtc_read_alarm, 396 - .set_alarm = ab8540_rtc_set_alarm, 397 - .alarm_irq_enable = ab8500_rtc_irq_enable, 398 - }; 399 - 400 438 static const struct platform_device_id ab85xx_rtc_ids[] = { 401 439 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, }, 402 - { "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, }, 403 440 { /* sentinel */ } 404 441 }; 405 442 MODULE_DEVICE_TABLE(platform, ab85xx_rtc_ids);
+1 -5
drivers/rtc/rtc-abx80x.c
··· 172 172 tm->tm_mon = bcd2bin(buf[ABX8XX_REG_MO] & 0x1F) - 1; 173 173 tm->tm_year = bcd2bin(buf[ABX8XX_REG_YR]) + 100; 174 174 175 - err = rtc_valid_tm(tm); 176 - if (err < 0) 177 - dev_err(&client->dev, "retrieved date/time is not valid.\n"); 178 - 179 - return err; 175 + return 0; 180 176 } 181 177 182 178 static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+24 -2
drivers/rtc/rtc-ac100.c
··· 183 183 184 184 for (i = 0; i < num_parents; i++) { 185 185 struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i); 186 - unsigned long tmp, prate = clk_hw_get_rate(parent); 186 + unsigned long tmp, prate; 187 + 188 + /* 189 + * The clock has two parents, one is a fixed clock which is 190 + * internally registered by the ac100 driver. The other parent 191 + * is a clock from the codec side of the chip, which we 192 + * properly declare and reference in the devicetree and is 193 + * not implemented in any driver right now. 194 + * If the clock core looks for the parent of that second 195 + * missing clock, it can't find one that is registered and 196 + * returns NULL. 197 + * So we end up in a situation where clk_hw_get_num_parents 198 + * returns the amount of clocks we can be parented to, but 199 + * clk_hw_get_parent_by_index will not return the orphan 200 + * clocks. 201 + * Thus we need to check if the parent exists before 202 + * we get the parent rate, so we could use the RTC 203 + * without waiting for the codec to be supported. 204 + */ 205 + if (!parent) 206 + continue; 207 + 208 + prate = clk_hw_get_rate(parent); 187 209 188 210 tmp = ac100_clkout_round_rate(hw, req->rate, prate); 189 211 ··· 409 387 rtc_tm->tm_year = bcd2bin(reg[6] & AC100_RTC_YEA_MASK) + 410 388 AC100_YEAR_OFF; 411 389 412 - return rtc_valid_tm(rtc_tm); 390 + return 0; 413 391 } 414 392 415 393 static int ac100_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
+1
drivers/rtc/rtc-at91sam9.c
··· 349 349 }; 350 350 351 351 static const struct regmap_config gpbr_regmap_config = { 352 + .name = "gpbr", 352 353 .reg_bits = 32, 353 354 .val_bits = 32, 354 355 .reg_stride = 4,
+1 -1
drivers/rtc/rtc-au1xxx.c
··· 36 36 37 37 rtc_time_to_tm(t, tm); 38 38 39 - return rtc_valid_tm(tm); 39 + return 0; 40 40 } 41 41 42 42 static int au1xtoy_rtc_set_time(struct device *dev, struct rtc_time *tm)
+6 -2
drivers/rtc/rtc-bq32k.c
··· 36 36 #define BQ32K_CFG2 0x09 /* Trickle charger control */ 37 37 #define BQ32K_TCFE BIT(6) /* Trickle charge FET bypass */ 38 38 39 + #define MAX_LEN 10 /* Maximum number of consecutive 40 + * register for this particular RTC. 41 + */ 42 + 39 43 struct bq32k_regs { 40 44 uint8_t seconds; 41 45 uint8_t minutes; ··· 78 74 static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len) 79 75 { 80 76 struct i2c_client *client = to_i2c_client(dev); 81 - uint8_t buffer[len + 1]; 77 + uint8_t buffer[MAX_LEN + 1]; 82 78 83 79 buffer[0] = off; 84 80 memcpy(&buffer[1], data, len); ··· 114 110 tm->tm_year = bcd2bin(regs.years) + 115 111 ((regs.cent_hours & BQ32K_CENT) ? 100 : 0); 116 112 117 - return rtc_valid_tm(tm); 113 + return 0; 118 114 } 119 115 120 116 static int bq32k_rtc_set_time(struct device *dev, struct rtc_time *tm)
+3
drivers/rtc/rtc-brcmstb-waketimer.c
··· 60 60 { 61 61 brcmstb_waketmr_clear_alarm(timer); 62 62 63 + /* Make sure we are actually counting in seconds */ 64 + writel_relaxed(timer->rate, timer->base + BRCMSTB_WKTMR_PRESCALER); 65 + 63 66 writel_relaxed(secs + 1, timer->base + BRCMSTB_WKTMR_ALARM); 64 67 } 65 68
+33 -54
drivers/rtc/rtc-cmos.c
··· 541 541 542 542 #define NVRAM_OFFSET (RTC_REG_D + 1) 543 543 544 - static ssize_t 545 - cmos_nvram_read(struct file *filp, struct kobject *kobj, 546 - struct bin_attribute *attr, 547 - char *buf, loff_t off, size_t count) 544 + static int cmos_nvram_read(void *priv, unsigned int off, void *val, 545 + size_t count) 548 546 { 547 + unsigned char *buf = val; 549 548 int retval; 550 549 551 550 off += NVRAM_OFFSET; ··· 562 563 return retval; 563 564 } 564 565 565 - static ssize_t 566 - cmos_nvram_write(struct file *filp, struct kobject *kobj, 567 - struct bin_attribute *attr, 568 - char *buf, loff_t off, size_t count) 566 + static int cmos_nvram_write(void *priv, unsigned int off, void *val, 567 + size_t count) 569 568 { 570 - struct cmos_rtc *cmos; 569 + struct cmos_rtc *cmos = priv; 570 + unsigned char *buf = val; 571 571 int retval; 572 - 573 - cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); 574 572 575 573 /* NOTE: on at least PCs and Ataris, the boot firmware uses a 576 574 * checksum on part of the NVRAM data. That's currently ignored ··· 593 597 594 598 return retval; 595 599 } 596 - 597 - static struct bin_attribute nvram = { 598 - .attr = { 599 - .name = "nvram", 600 - .mode = S_IRUGO | S_IWUSR, 601 - }, 602 - 603 - .read = cmos_nvram_read, 604 - .write = cmos_nvram_write, 605 - /* size gets set up later */ 606 - }; 607 600 608 601 /*----------------------------------------------------------------*/ 609 602 ··· 660 675 unsigned char rtc_control; 661 676 unsigned address_space; 662 677 u32 flags = 0; 678 + struct nvmem_config nvmem_cfg = { 679 + .name = "cmos_nvram", 680 + .word_size = 1, 681 + .stride = 1, 682 + .reg_read = cmos_nvram_read, 683 + .reg_write = cmos_nvram_write, 684 + .priv = &cmos_rtc, 685 + }; 663 686 664 687 /* there can be only one ... */ 665 688 if (cmos_rtc.dev) ··· 744 751 cmos_rtc.dev = dev; 745 752 dev_set_drvdata(dev, &cmos_rtc); 746 753 747 - cmos_rtc.rtc = rtc_device_register(driver_name, dev, 748 - &cmos_rtc_ops, THIS_MODULE); 754 + cmos_rtc.rtc = devm_rtc_allocate_device(dev); 749 755 if (IS_ERR(cmos_rtc.rtc)) { 750 756 retval = PTR_ERR(cmos_rtc.rtc); 751 757 goto cleanup0; ··· 806 814 } 807 815 } 808 816 809 - /* export at least the first block of NVRAM */ 810 - nvram.size = address_space - NVRAM_OFFSET; 811 - retval = sysfs_create_bin_file(&dev->kobj, &nvram); 812 - if (retval < 0) { 813 - dev_dbg(dev, "can't create nvram file? %d\n", retval); 817 + cmos_rtc.rtc->ops = &cmos_rtc_ops; 818 + cmos_rtc.rtc->nvram_old_abi = true; 819 + retval = rtc_register_device(cmos_rtc.rtc); 820 + if (retval) 814 821 goto cleanup2; 815 - } 816 822 817 - dev_info(dev, "%s%s, %zd bytes nvram%s\n", 818 - !is_valid_irq(rtc_irq) ? "no alarms" : 819 - cmos_rtc.mon_alrm ? "alarms up to one year" : 820 - cmos_rtc.day_alrm ? "alarms up to one month" : 821 - "alarms up to one day", 822 - cmos_rtc.century ? ", y3k" : "", 823 - nvram.size, 824 - is_hpet_enabled() ? ", hpet irqs" : ""); 823 + /* export at least the first block of NVRAM */ 824 + nvmem_cfg.size = address_space - NVRAM_OFFSET; 825 + if (rtc_nvmem_register(cmos_rtc.rtc, &nvmem_cfg)) 826 + dev_err(dev, "nvmem registration failed\n"); 827 + 828 + dev_info(dev, "%s%s, %d bytes nvram%s\n", 829 + !is_valid_irq(rtc_irq) ? "no alarms" : 830 + cmos_rtc.mon_alrm ? "alarms up to one year" : 831 + cmos_rtc.day_alrm ? "alarms up to one month" : 832 + "alarms up to one day", 833 + cmos_rtc.century ? ", y3k" : "", 834 + nvmem_cfg.size, 835 + is_hpet_enabled() ? ", hpet irqs" : ""); 825 836 826 837 return 0; 827 838 ··· 833 838 free_irq(rtc_irq, cmos_rtc.rtc); 834 839 cleanup1: 835 840 cmos_rtc.dev = NULL; 836 - rtc_device_unregister(cmos_rtc.rtc); 837 841 cleanup0: 838 842 if (RTC_IOMAPPED) 839 843 release_region(ports->start, resource_size(ports)); ··· 856 862 857 863 cmos_do_shutdown(cmos->irq); 858 864 859 - sysfs_remove_bin_file(&dev->kobj, &nvram); 860 - 861 865 if (is_valid_irq(cmos->irq)) { 862 866 free_irq(cmos->irq, cmos->rtc); 863 867 hpet_unregister_irq_handler(cmos_interrupt); 864 868 } 865 869 866 - rtc_device_unregister(cmos->rtc); 867 870 cmos->rtc = NULL; 868 871 869 872 ports = cmos->iomem; ··· 1262 1271 static __init void cmos_of_init(struct platform_device *pdev) 1263 1272 { 1264 1273 struct device_node *node = pdev->dev.of_node; 1265 - struct rtc_time time; 1266 - int ret; 1267 1274 const __be32 *val; 1268 1275 1269 1276 if (!node) ··· 1274 1285 val = of_get_property(node, "freq-reg", NULL); 1275 1286 if (val) 1276 1287 CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT); 1277 - 1278 - cmos_read_time(&pdev->dev, &time); 1279 - ret = rtc_valid_tm(&time); 1280 - if (ret) { 1281 - struct rtc_time def_time = { 1282 - .tm_year = 1, 1283 - .tm_mday = 1, 1284 - }; 1285 - cmos_set_time(&pdev->dev, &def_time); 1286 - } 1287 1288 } 1288 1289 #else 1289 1290 static inline void cmos_of_init(struct platform_device *pdev) {}
+1 -1
drivers/rtc/rtc-coh901331.c
··· 82 82 if (readl(rtap->virtbase + COH901331_VALID)) { 83 83 rtc_time_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm); 84 84 clk_disable(rtap->clk); 85 - return rtc_valid_tm(tm); 85 + return 0; 86 86 } 87 87 clk_disable(rtap->clk); 88 88 return -EINVAL;
-8
drivers/rtc/rtc-core.h
··· 46 46 return NULL; 47 47 } 48 48 #endif 49 - 50 - #ifdef CONFIG_RTC_NVMEM 51 - void rtc_nvmem_register(struct rtc_device *rtc); 52 - void rtc_nvmem_unregister(struct rtc_device *rtc); 53 - #else 54 - static inline void rtc_nvmem_register(struct rtc_device *rtc) {} 55 - static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} 56 - #endif
+1 -1
drivers/rtc/rtc-cpcap.c
··· 119 119 120 120 cpcap2rtc_time(tm, &cpcap_tm); 121 121 122 - return rtc_valid_tm(tm); 122 + return 0; 123 123 } 124 124 125 125 static int cpcap_rtc_set_time(struct device *dev, struct rtc_time *tm)
+4 -4
drivers/rtc/rtc-cros-ec.c
··· 197 197 cros_ec_rtc->saved_alarm = (u32)alarm_time; 198 198 } else { 199 199 /* Don't set an alarm in the past. */ 200 - if ((u32)alarm_time < current_time) 201 - alarm_offset = EC_RTC_ALARM_CLEAR; 202 - else 203 - alarm_offset = (u32)alarm_time - current_time; 200 + if ((u32)alarm_time <= current_time) 201 + return -ETIME; 202 + 203 + alarm_offset = (u32)alarm_time - current_time; 204 204 } 205 205 206 206 ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset);
+1 -2
drivers/rtc/rtc-da9052.c
··· 187 187 rtc_tm->tm_min = v[0][1] & DA9052_RTC_MIN; 188 188 rtc_tm->tm_sec = v[0][0] & DA9052_RTC_SEC; 189 189 190 - ret = rtc_valid_tm(rtc_tm); 191 - return ret; 190 + return 0; 192 191 } 193 192 194 193 idx = (1-idx);
+1 -1
drivers/rtc/rtc-da9055.c
··· 158 158 rtc_tm->tm_min = v[1] & DA9055_RTC_MIN; 159 159 rtc_tm->tm_sec = v[0] & DA9055_RTC_SEC; 160 160 161 - return rtc_valid_tm(rtc_tm); 161 + return 0; 162 162 } 163 163 164 164 static int da9055_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-da9063.c
··· 256 256 else 257 257 rtc->rtc_sync = false; 258 258 259 - return rtc_valid_tm(tm); 259 + return 0; 260 260 } 261 261 262 262 static int da9063_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-ds1216.c
··· 99 99 if (tm->tm_year < 70) 100 100 tm->tm_year += 100; 101 101 102 - return rtc_valid_tm(tm); 102 + return 0; 103 103 } 104 104 105 105 static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-ds1286.c
··· 211 211 212 212 tm->tm_mon--; 213 213 214 - return rtc_valid_tm(tm); 214 + return 0; 215 215 } 216 216 217 217 static int ds1286_set_time(struct device *dev, struct rtc_time *tm)
+3 -4
drivers/rtc/rtc-ds1302.c
··· 43 43 { 44 44 struct spi_device *spi = dev_get_drvdata(dev); 45 45 u8 buf[1 + RTC_CLCK_LEN]; 46 - u8 *bp = buf; 46 + u8 *bp; 47 47 int status; 48 48 49 49 /* Enable writing */ ··· 98 98 time->tm_mon = bcd2bin(buf[RTC_ADDR_MON]) - 1; 99 99 time->tm_year = bcd2bin(buf[RTC_ADDR_YEAR]) + 100; 100 100 101 - /* Time may not be set */ 102 - return rtc_valid_tm(time); 101 + return 0; 103 102 } 104 103 105 104 static const struct rtc_class_ops ds1302_rtc_ops = { ··· 111 112 struct rtc_device *rtc; 112 113 u8 addr; 113 114 u8 buf[4]; 114 - u8 *bp = buf; 115 + u8 *bp; 115 116 int status; 116 117 117 118 /* Sanity check board setup data. This may be hooked up
+11 -13
drivers/rtc/rtc-ds1305.c
··· 203 203 time->tm_hour, time->tm_mday, 204 204 time->tm_mon, time->tm_year, time->tm_wday); 205 205 206 - /* Time may not be set */ 207 - return rtc_valid_tm(time); 206 + return 0; 208 207 } 209 208 210 209 static int ds1305_set_time(struct device *dev, struct rtc_time *time) ··· 543 544 return spi_sync(spi, &m); 544 545 } 545 546 546 - static struct nvmem_config ds1305_nvmem_cfg = { 547 - .name = "ds1305_nvram", 548 - .word_size = 1, 549 - .stride = 1, 550 - .size = DS1305_NVRAM_LEN, 551 - .reg_read = ds1305_nvram_read, 552 - .reg_write = ds1305_nvram_write, 553 - }; 554 - 555 547 /*----------------------------------------------------------------------*/ 556 548 557 549 /* ··· 556 566 u8 addr, value; 557 567 struct ds1305_platform_data *pdata = dev_get_platdata(&spi->dev); 558 568 bool write_ctrl = false; 569 + struct nvmem_config ds1305_nvmem_cfg = { 570 + .name = "ds1305_nvram", 571 + .word_size = 1, 572 + .stride = 1, 573 + .size = DS1305_NVRAM_LEN, 574 + .reg_read = ds1305_nvram_read, 575 + .reg_write = ds1305_nvram_write, 576 + }; 559 577 560 578 /* Sanity check board setup data. This may be hooked up 561 579 * in 3wire mode, but we don't care. Note that unless ··· 701 703 ds1305->rtc->ops = &ds1305_ops; 702 704 703 705 ds1305_nvmem_cfg.priv = ds1305; 704 - ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg; 705 706 ds1305->rtc->nvram_old_abi = true; 706 - 707 707 status = rtc_register_device(ds1305->rtc); 708 708 if (status) { 709 709 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 710 710 return status; 711 711 } 712 + 713 + rtc_nvmem_register(ds1305->rtc, &ds1305_nvmem_cfg); 712 714 713 715 /* Maybe set up alarm IRQ; be ready to handle it triggering right 714 716 * away. NOTE that we don't share this. The signal is active low,
+16 -16
drivers/rtc/rtc-ds1307.c
··· 114 114 # define RX8025_BIT_XST 0x20 115 115 116 116 struct ds1307 { 117 - struct nvmem_config nvmem_cfg; 118 117 enum ds_type type; 119 118 unsigned long flags; 120 119 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */ ··· 437 438 t->tm_hour, t->tm_mday, 438 439 t->tm_mon, t->tm_year, t->tm_wday); 439 440 440 - /* initial clock setting can be undefined */ 441 - return rtc_valid_tm(t); 441 + return 0; 442 442 } 443 443 444 444 static int ds1307_set_time(struct device *dev, struct rtc_time *t) ··· 1694 1696 } 1695 1697 } 1696 1698 1697 - if (chip->nvram_size) { 1698 - ds1307->nvmem_cfg.name = "ds1307_nvram"; 1699 - ds1307->nvmem_cfg.word_size = 1; 1700 - ds1307->nvmem_cfg.stride = 1; 1701 - ds1307->nvmem_cfg.size = chip->nvram_size; 1702 - ds1307->nvmem_cfg.reg_read = ds1307_nvram_read; 1703 - ds1307->nvmem_cfg.reg_write = ds1307_nvram_write; 1704 - ds1307->nvmem_cfg.priv = ds1307; 1705 - 1706 - ds1307->rtc->nvmem_config = &ds1307->nvmem_cfg; 1707 - ds1307->rtc->nvram_old_abi = true; 1708 - } 1709 - 1710 1699 ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; 1711 1700 err = rtc_register_device(ds1307->rtc); 1712 1701 if (err) 1713 1702 return err; 1703 + 1704 + if (chip->nvram_size) { 1705 + struct nvmem_config nvmem_cfg = { 1706 + .name = "ds1307_nvram", 1707 + .word_size = 1, 1708 + .stride = 1, 1709 + .size = chip->nvram_size, 1710 + .reg_read = ds1307_nvram_read, 1711 + .reg_write = ds1307_nvram_write, 1712 + .priv = ds1307, 1713 + }; 1714 + 1715 + ds1307->rtc->nvram_old_abi = true; 1716 + rtc_nvmem_register(ds1307->rtc, &nvmem_cfg); 1717 + } 1714 1718 1715 1719 ds1307_hwmon_register(ds1307); 1716 1720 ds1307_clks_register(ds1307);
+32 -153
drivers/rtc/rtc-ds1343.c
··· 153 153 static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter, 154 154 ds1343_store_glitchfilter); 155 155 156 - static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj, 157 - struct bin_attribute *attr, 158 - char *buf, loff_t off, size_t count) 156 + static int ds1343_nvram_write(void *priv, unsigned int off, void *val, 157 + size_t bytes) 159 158 { 160 - int ret; 161 - unsigned char address; 162 - struct device *dev = kobj_to_dev(kobj); 163 - struct ds1343_priv *priv = dev_get_drvdata(dev); 159 + struct ds1343_priv *ds1343 = priv; 164 160 165 - address = DS1343_NVRAM + off; 166 - 167 - ret = regmap_bulk_write(priv->map, address, buf, count); 168 - if (ret < 0) 169 - dev_err(&priv->spi->dev, "Error in nvram write %d", ret); 170 - 171 - return (ret < 0) ? ret : count; 161 + return regmap_bulk_write(ds1343->map, DS1343_NVRAM + off, val, bytes); 172 162 } 173 163 174 - 175 - static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj, 176 - struct bin_attribute *attr, 177 - char *buf, loff_t off, size_t count) 164 + static int ds1343_nvram_read(void *priv, unsigned int off, void *val, 165 + size_t bytes) 178 166 { 179 - int ret; 180 - unsigned char address; 181 - struct device *dev = kobj_to_dev(kobj); 182 - struct ds1343_priv *priv = dev_get_drvdata(dev); 167 + struct ds1343_priv *ds1343 = priv; 183 168 184 - address = DS1343_NVRAM + off; 185 - 186 - ret = regmap_bulk_read(priv->map, address, buf, count); 187 - if (ret < 0) 188 - dev_err(&priv->spi->dev, "Error in nvram read %d\n", ret); 189 - 190 - return (ret < 0) ? ret : count; 169 + return regmap_bulk_read(ds1343->map, DS1343_NVRAM + off, val, bytes); 191 170 } 192 - 193 - 194 - static struct bin_attribute nvram_attr = { 195 - .attr.name = "nvram", 196 - .attr.mode = S_IRUGO | S_IWUSR, 197 - .read = ds1343_nvram_read, 198 - .write = ds1343_nvram_write, 199 - .size = DS1343_NVRAM_LEN, 200 - }; 201 - 202 - static ssize_t ds1343_show_alarmstatus(struct device *dev, 203 - struct device_attribute *attr, char *buf) 204 - { 205 - struct ds1343_priv *priv = dev_get_drvdata(dev); 206 - int alarmstatus, data; 207 - 208 - regmap_read(priv->map, DS1343_CONTROL_REG, &data); 209 - 210 - alarmstatus = !!(data & DS1343_A0IE); 211 - 212 - if (alarmstatus) 213 - return sprintf(buf, "enabled\n"); 214 - else 215 - return sprintf(buf, "disabled\n"); 216 - } 217 - 218 - static DEVICE_ATTR(alarm_status, S_IRUGO, ds1343_show_alarmstatus, NULL); 219 - 220 - static ssize_t ds1343_show_alarmmode(struct device *dev, 221 - struct device_attribute *attr, char *buf) 222 - { 223 - struct ds1343_priv *priv = dev_get_drvdata(dev); 224 - int alarm_mode, data; 225 - char *alarm_str; 226 - 227 - regmap_read(priv->map, DS1343_ALM0_SEC_REG, &data); 228 - alarm_mode = (data & 0x80) >> 4; 229 - 230 - regmap_read(priv->map, DS1343_ALM0_MIN_REG, &data); 231 - alarm_mode |= (data & 0x80) >> 5; 232 - 233 - regmap_read(priv->map, DS1343_ALM0_HOUR_REG, &data); 234 - alarm_mode |= (data & 0x80) >> 6; 235 - 236 - regmap_read(priv->map, DS1343_ALM0_DAY_REG, &data); 237 - alarm_mode |= (data & 0x80) >> 7; 238 - 239 - switch (alarm_mode) { 240 - case 15: 241 - alarm_str = "each second"; 242 - break; 243 - 244 - case 7: 245 - alarm_str = "seconds match"; 246 - break; 247 - 248 - case 3: 249 - alarm_str = "minutes and seconds match"; 250 - break; 251 - 252 - case 1: 253 - alarm_str = "hours, minutes and seconds match"; 254 - break; 255 - 256 - case 0: 257 - alarm_str = "day, hours, minutes and seconds match"; 258 - break; 259 - 260 - default: 261 - alarm_str = "invalid"; 262 - break; 263 - } 264 - 265 - return sprintf(buf, "%s\n", alarm_str); 266 - } 267 - 268 - static DEVICE_ATTR(alarm_mode, S_IRUGO, ds1343_show_alarmmode, NULL); 269 171 270 172 static ssize_t ds1343_show_tricklecharger(struct device *dev, 271 173 struct device_attribute *attr, char *buf) ··· 215 313 216 314 static int ds1343_sysfs_register(struct device *dev) 217 315 { 218 - struct ds1343_priv *priv = dev_get_drvdata(dev); 219 316 int err; 220 317 221 318 err = device_create_file(dev, &dev_attr_glitch_filter); ··· 222 321 return err; 223 322 224 323 err = device_create_file(dev, &dev_attr_trickle_charger); 225 - if (err) 226 - goto error1; 227 - 228 - err = device_create_bin_file(dev, &nvram_attr); 229 - if (err) 230 - goto error2; 231 - 232 - if (priv->irq <= 0) 233 - return err; 234 - 235 - err = device_create_file(dev, &dev_attr_alarm_mode); 236 - if (err) 237 - goto error3; 238 - 239 - err = device_create_file(dev, &dev_attr_alarm_status); 240 324 if (!err) 241 - return err; 325 + return 0; 242 326 243 - device_remove_file(dev, &dev_attr_alarm_mode); 244 - 245 - error3: 246 - device_remove_bin_file(dev, &nvram_attr); 247 - 248 - error2: 249 - device_remove_file(dev, &dev_attr_trickle_charger); 250 - 251 - error1: 252 327 device_remove_file(dev, &dev_attr_glitch_filter); 253 328 254 329 return err; ··· 232 355 233 356 static void ds1343_sysfs_unregister(struct device *dev) 234 357 { 235 - struct ds1343_priv *priv = dev_get_drvdata(dev); 236 - 237 358 device_remove_file(dev, &dev_attr_glitch_filter); 238 359 device_remove_file(dev, &dev_attr_trickle_charger); 239 - device_remove_bin_file(dev, &nvram_attr); 240 - 241 - if (priv->irq <= 0) 242 - return; 243 - 244 - device_remove_file(dev, &dev_attr_alarm_status); 245 - device_remove_file(dev, &dev_attr_alarm_mode); 246 360 } 247 361 248 362 static int ds1343_read_time(struct device *dev, struct rtc_time *dt) ··· 254 386 dt->tm_mon = bcd2bin(buf[5] & 0x1F) - 1; 255 387 dt->tm_year = bcd2bin(buf[6]) + 100; /* year offset from 1900 */ 256 388 257 - return rtc_valid_tm(dt); 389 + return 0; 258 390 } 259 391 260 392 static int ds1343_set_time(struct device *dev, struct rtc_time *dt) ··· 467 599 static int ds1343_probe(struct spi_device *spi) 468 600 { 469 601 struct ds1343_priv *priv; 470 - struct regmap_config config; 602 + struct regmap_config config = { .reg_bits = 8, .val_bits = 8, 603 + .write_flag_mask = 0x80, }; 471 604 unsigned int data; 472 605 int res; 473 - 474 - memset(&config, 0, sizeof(config)); 475 - config.reg_bits = 8; 476 - config.val_bits = 8; 477 - config.write_flag_mask = 0x80; 606 + struct nvmem_config nvmem_cfg = { 607 + .name = "ds1343-", 608 + .word_size = 1, 609 + .stride = 1, 610 + .size = DS1343_NVRAM_LEN, 611 + .reg_read = ds1343_nvram_read, 612 + .reg_write = ds1343_nvram_write, 613 + }; 478 614 479 615 priv = devm_kzalloc(&spi->dev, sizeof(struct ds1343_priv), GFP_KERNEL); 480 616 if (!priv) ··· 518 646 data &= ~(DS1343_OSF | DS1343_IRQF1 | DS1343_IRQF0); 519 647 regmap_write(priv->map, DS1343_STATUS_REG, data); 520 648 521 - priv->rtc = devm_rtc_device_register(&spi->dev, "ds1343", 522 - &ds1343_rtc_ops, THIS_MODULE); 523 - if (IS_ERR(priv->rtc)) { 524 - dev_err(&spi->dev, "unable to register rtc ds1343\n"); 649 + priv->rtc = devm_rtc_allocate_device(&spi->dev); 650 + if (IS_ERR(priv->rtc)) 525 651 return PTR_ERR(priv->rtc); 526 - } 652 + 653 + priv->rtc->nvram_old_abi = true; 654 + priv->rtc->ops = &ds1343_rtc_ops; 655 + 656 + res = rtc_register_device(priv->rtc); 657 + if (res) 658 + return res; 659 + 660 + nvmem_cfg.priv = priv; 661 + rtc_nvmem_register(priv->rtc, &nvmem_cfg); 527 662 528 663 priv->irq = spi->irq; 529 664
+1 -1
drivers/rtc/rtc-ds1347.c
··· 66 66 dt->tm_wday = bcd2bin(buf[5]) - 1; 67 67 dt->tm_year = bcd2bin(buf[6]) + 100; 68 68 69 - return rtc_valid_tm(dt); 69 + return 0; 70 70 } 71 71 72 72 static int ds1347_set_time(struct device *dev, struct rtc_time *dt)
+1 -1
drivers/rtc/rtc-ds1390.c
··· 153 153 /* adjust for century bit */ 154 154 dt->tm_year = bcd2bin(chip->txrx_buf[6]) + ((chip->txrx_buf[5] & 0x80) ? 100 : 0); 155 155 156 - return rtc_valid_tm(dt); 156 + return 0; 157 157 } 158 158 159 159 static int ds1390_set_time(struct device *dev, struct rtc_time *dt)
+11 -15
drivers/rtc/rtc-ds1511.c
··· 277 277 278 278 rtc_tm->tm_mon--; 279 279 280 - if (rtc_valid_tm(rtc_tm) < 0) { 281 - dev_err(dev, "retrieved date/time is not valid.\n"); 282 - rtc_time_to_tm(0, rtc_tm); 283 - } 284 280 return 0; 285 281 } 286 282 ··· 418 422 return 0; 419 423 } 420 424 421 - static struct nvmem_config ds1511_nvmem_cfg = { 422 - .name = "ds1511_nvram", 423 - .word_size = 1, 424 - .stride = 1, 425 - .size = DS1511_RAM_MAX, 426 - .reg_read = ds1511_nvram_read, 427 - .reg_write = ds1511_nvram_write, 428 - }; 429 - 430 425 static int ds1511_rtc_probe(struct platform_device *pdev) 431 426 { 432 427 struct resource *res; 433 428 struct rtc_plat_data *pdata; 434 429 int ret = 0; 430 + struct nvmem_config ds1511_nvmem_cfg = { 431 + .name = "ds1511_nvram", 432 + .word_size = 1, 433 + .stride = 1, 434 + .size = DS1511_RAM_MAX, 435 + .reg_read = ds1511_nvram_read, 436 + .reg_write = ds1511_nvram_write, 437 + .priv = &pdev->dev, 438 + }; 435 439 436 440 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 437 441 if (!pdata) ··· 474 478 475 479 pdata->rtc->ops = &ds1511_rtc_ops; 476 480 477 - ds1511_nvmem_cfg.priv = &pdev->dev; 478 - pdata->rtc->nvmem_config = &ds1511_nvmem_cfg; 479 481 pdata->rtc->nvram_old_abi = true; 480 482 481 483 ret = rtc_register_device(pdata->rtc); 482 484 if (ret) 483 485 return ret; 486 + 487 + rtc_nvmem_register(pdata->rtc, &ds1511_nvmem_cfg); 484 488 485 489 /* 486 490 * if the platform has an interrupt in mind for this device,
+31 -47
drivers/rtc/rtc-ds1553.c
··· 127 127 /* year is 1900 + tm->tm_year */ 128 128 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; 129 129 130 - if (rtc_valid_tm(tm) < 0) { 131 - dev_err(dev, "retrieved date/time is not valid.\n"); 132 - rtc_time_to_tm(0, tm); 133 - } 134 130 return 0; 135 131 } 136 132 ··· 229 233 .alarm_irq_enable = ds1553_rtc_alarm_irq_enable, 230 234 }; 231 235 232 - static ssize_t ds1553_nvram_read(struct file *filp, struct kobject *kobj, 233 - struct bin_attribute *bin_attr, 234 - char *buf, loff_t pos, size_t size) 236 + static int ds1553_nvram_read(void *priv, unsigned int pos, void *val, 237 + size_t bytes) 235 238 { 236 - struct device *dev = container_of(kobj, struct device, kobj); 237 - struct platform_device *pdev = to_platform_device(dev); 239 + struct platform_device *pdev = priv; 238 240 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 239 241 void __iomem *ioaddr = pdata->ioaddr; 240 - ssize_t count; 242 + u8 *buf = val; 241 243 242 - for (count = 0; count < size; count++) 244 + for (; bytes; bytes--) 243 245 *buf++ = readb(ioaddr + pos++); 244 - return count; 246 + return 0; 245 247 } 246 248 247 - static ssize_t ds1553_nvram_write(struct file *filp, struct kobject *kobj, 248 - struct bin_attribute *bin_attr, 249 - char *buf, loff_t pos, size_t size) 249 + static int ds1553_nvram_write(void *priv, unsigned int pos, void *val, 250 + size_t bytes) 250 251 { 251 - struct device *dev = container_of(kobj, struct device, kobj); 252 - struct platform_device *pdev = to_platform_device(dev); 252 + struct platform_device *pdev = priv; 253 253 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 254 254 void __iomem *ioaddr = pdata->ioaddr; 255 - ssize_t count; 255 + u8 *buf = val; 256 256 257 - for (count = 0; count < size; count++) 257 + for (; bytes; bytes--) 258 258 writeb(*buf++, ioaddr + pos++); 259 - return count; 259 + return 0; 260 260 } 261 - 262 - static struct bin_attribute ds1553_nvram_attr = { 263 - .attr = { 264 - .name = "nvram", 265 - .mode = S_IRUGO | S_IWUSR, 266 - }, 267 - .size = RTC_OFFSET, 268 - .read = ds1553_nvram_read, 269 - .write = ds1553_nvram_write, 270 - }; 271 261 272 262 static int ds1553_rtc_probe(struct platform_device *pdev) 273 263 { ··· 262 280 struct rtc_plat_data *pdata; 263 281 void __iomem *ioaddr; 264 282 int ret = 0; 283 + struct nvmem_config nvmem_cfg = { 284 + .name = "ds1553_nvram", 285 + .word_size = 1, 286 + .stride = 1, 287 + .size = RTC_OFFSET, 288 + .reg_read = ds1553_nvram_read, 289 + .reg_write = ds1553_nvram_write, 290 + .priv = pdev, 291 + }; 265 292 266 293 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 267 294 if (!pdata) ··· 299 308 pdata->last_jiffies = jiffies; 300 309 platform_set_drvdata(pdev, pdata); 301 310 302 - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 303 - &ds1553_rtc_ops, THIS_MODULE); 311 + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); 304 312 if (IS_ERR(pdata->rtc)) 305 313 return PTR_ERR(pdata->rtc); 314 + 315 + pdata->rtc->ops = &ds1553_rtc_ops; 316 + pdata->rtc->nvram_old_abi = true; 317 + 318 + ret = rtc_register_device(pdata->rtc); 319 + if (ret) 320 + return ret; 306 321 307 322 if (pdata->irq > 0) { 308 323 writeb(0, ioaddr + RTC_INTERRUPTS); ··· 320 323 } 321 324 } 322 325 323 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 324 - if (ret) 325 - dev_err(&pdev->dev, "unable to create sysfs file: %s\n", 326 - ds1553_nvram_attr.attr.name); 326 + if (rtc_nvmem_register(pdata->rtc, &nvmem_cfg)) 327 + dev_err(&pdev->dev, "unable to register nvmem\n"); 327 328 328 - return 0; 329 - } 330 - 331 - static int ds1553_rtc_remove(struct platform_device *pdev) 332 - { 333 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 334 - 335 - sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 336 - if (pdata->irq > 0) 337 - writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 338 329 return 0; 339 330 } 340 331 ··· 331 346 332 347 static struct platform_driver ds1553_rtc_driver = { 333 348 .probe = ds1553_rtc_probe, 334 - .remove = ds1553_rtc_remove, 335 349 .driver = { 336 350 .name = "rtc-ds1553", 337 351 },
+1 -1
drivers/rtc/rtc-ds1685.c
··· 306 306 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 307 307 tm->tm_isdst = 0; /* RTC has hardcoded timezone, so don't use. */ 308 308 309 - return rtc_valid_tm(tm); 309 + return 0; 310 310 } 311 311 312 312 /**
+33 -42
drivers/rtc/rtc-ds1742.c
··· 53 53 struct rtc_plat_data { 54 54 void __iomem *ioaddr_nvram; 55 55 void __iomem *ioaddr_rtc; 56 - size_t size_nvram; 57 56 unsigned long last_jiffies; 58 - struct bin_attribute nvram_attr; 59 57 }; 60 58 61 59 static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 112 114 /* year is 1900 + tm->tm_year */ 113 115 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; 114 116 115 - return rtc_valid_tm(tm); 117 + return 0; 116 118 } 117 119 118 120 static const struct rtc_class_ops ds1742_rtc_ops = { ··· 120 122 .set_time = ds1742_rtc_set_time, 121 123 }; 122 124 123 - static ssize_t ds1742_nvram_read(struct file *filp, struct kobject *kobj, 124 - struct bin_attribute *bin_attr, 125 - char *buf, loff_t pos, size_t size) 125 + static int ds1742_nvram_read(void *priv, unsigned int pos, void *val, 126 + size_t bytes) 126 127 { 127 - struct device *dev = container_of(kobj, struct device, kobj); 128 - struct platform_device *pdev = to_platform_device(dev); 129 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 128 + struct rtc_plat_data *pdata = priv; 130 129 void __iomem *ioaddr = pdata->ioaddr_nvram; 131 - ssize_t count; 130 + u8 *buf = val; 132 131 133 - for (count = 0; count < size; count++) 132 + for (; bytes; bytes--) 134 133 *buf++ = readb(ioaddr + pos++); 135 - return count; 134 + return 0; 136 135 } 137 136 138 - static ssize_t ds1742_nvram_write(struct file *filp, struct kobject *kobj, 139 - struct bin_attribute *bin_attr, 140 - char *buf, loff_t pos, size_t size) 137 + static int ds1742_nvram_write(void *priv, unsigned int pos, void *val, 138 + size_t bytes) 141 139 { 142 - struct device *dev = container_of(kobj, struct device, kobj); 143 - struct platform_device *pdev = to_platform_device(dev); 144 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 140 + struct rtc_plat_data *pdata = priv; 145 141 void __iomem *ioaddr = pdata->ioaddr_nvram; 146 - ssize_t count; 142 + u8 *buf = val; 147 143 148 - for (count = 0; count < size; count++) 144 + for (; bytes; bytes--) 149 145 writeb(*buf++, ioaddr + pos++); 150 - return count; 146 + return 0; 151 147 } 152 148 153 149 static int ds1742_rtc_probe(struct platform_device *pdev) ··· 152 160 struct rtc_plat_data *pdata; 153 161 void __iomem *ioaddr; 154 162 int ret = 0; 163 + struct nvmem_config nvmem_cfg = { 164 + .name = "ds1742_nvram", 165 + .word_size = 1, 166 + .stride = 1, 167 + .reg_read = ds1742_nvram_read, 168 + .reg_write = ds1742_nvram_write, 169 + }; 170 + 155 171 156 172 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 157 173 if (!pdata) ··· 171 171 return PTR_ERR(ioaddr); 172 172 173 173 pdata->ioaddr_nvram = ioaddr; 174 - pdata->size_nvram = resource_size(res) - RTC_SIZE; 175 - pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; 174 + pdata->ioaddr_rtc = ioaddr + resource_size(res) - RTC_SIZE; 176 175 177 - sysfs_bin_attr_init(&pdata->nvram_attr); 178 - pdata->nvram_attr.attr.name = "nvram"; 179 - pdata->nvram_attr.attr.mode = S_IRUGO | S_IWUSR; 180 - pdata->nvram_attr.read = ds1742_nvram_read; 181 - pdata->nvram_attr.write = ds1742_nvram_write; 182 - pdata->nvram_attr.size = pdata->size_nvram; 176 + nvmem_cfg.size = resource_size(res) - RTC_SIZE; 177 + nvmem_cfg.priv = pdata; 183 178 184 179 /* turn RTC on if it was not on */ 185 180 ioaddr = pdata->ioaddr_rtc; ··· 191 196 192 197 pdata->last_jiffies = jiffies; 193 198 platform_set_drvdata(pdev, pdata); 194 - rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 195 - &ds1742_rtc_ops, THIS_MODULE); 199 + 200 + rtc = devm_rtc_allocate_device(&pdev->dev); 196 201 if (IS_ERR(rtc)) 197 202 return PTR_ERR(rtc); 198 203 199 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 204 + rtc->ops = &ds1742_rtc_ops; 205 + rtc->nvram_old_abi = true; 206 + 207 + ret = rtc_register_device(rtc); 200 208 if (ret) 201 - dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n", 202 - pdata->nvram_attr.attr.name); 209 + return ret; 203 210 204 - return 0; 205 - } 211 + if (rtc_nvmem_register(rtc, &nvmem_cfg)) 212 + dev_err(&pdev->dev, "Unable to register nvmem\n"); 206 213 207 - static int ds1742_rtc_remove(struct platform_device *pdev) 208 - { 209 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 210 - 211 - sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 212 214 return 0; 213 215 } 214 216 ··· 217 225 218 226 static struct platform_driver ds1742_rtc_driver = { 219 227 .probe = ds1742_rtc_probe, 220 - .remove = ds1742_rtc_remove, 221 228 .driver = { 222 229 .name = "rtc-ds1742", 223 230 .of_match_table = of_match_ptr(ds1742_rtc_of_match),
+1 -1
drivers/rtc/rtc-ds2404.c
··· 207 207 time = le32_to_cpu(time); 208 208 209 209 rtc_time_to_tm(time, dt); 210 - return rtc_valid_tm(dt); 210 + return 0; 211 211 } 212 212 213 213 static int ds2404_set_mmss(struct device *dev, unsigned long secs)
+1 -1
drivers/rtc/rtc-ds3232.c
··· 145 145 146 146 time->tm_year = bcd2bin(year) + add_century; 147 147 148 - return rtc_valid_tm(time); 148 + return 0; 149 149 } 150 150 151 151 static int ds3232_set_time(struct device *dev, struct rtc_time *time)
+1 -1
drivers/rtc/rtc-efi.c
··· 176 176 if (!convert_from_efi_time(&eft, tm)) 177 177 return -EIO; 178 178 179 - return rtc_valid_tm(tm); 179 + return 0; 180 180 } 181 181 182 182 static int efi_set_time(struct device *dev, struct rtc_time *tm)
+1 -2
drivers/rtc/rtc-fm3130.c
··· 136 136 t->tm_hour, t->tm_mday, 137 137 t->tm_mon, t->tm_year, t->tm_wday); 138 138 139 - /* initial clock setting can be undefined */ 140 - return rtc_valid_tm(t); 139 + return 0; 141 140 } 142 141 143 142
+2
drivers/rtc/rtc-goldfish.c
··· 235 235 }; 236 236 237 237 module_platform_driver(goldfish_rtc); 238 + 239 + MODULE_LICENSE("GPL v2");
+6 -14
drivers/rtc/rtc-isl12022.c
··· 104 104 * In the routines that deal directly with the isl12022 hardware, we use 105 105 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 106 106 */ 107 - static int isl12022_get_datetime(struct i2c_client *client, struct rtc_time *tm) 107 + static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm) 108 108 { 109 + struct i2c_client *client = to_i2c_client(dev); 109 110 uint8_t buf[ISL12022_REG_INT + 1]; 110 111 int ret; 111 112 ··· 150 149 tm->tm_sec, tm->tm_min, tm->tm_hour, 151 150 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 152 151 153 - return rtc_valid_tm(tm); 152 + return 0; 154 153 } 155 154 156 - static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm) 155 + static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm) 157 156 { 157 + struct i2c_client *client = to_i2c_client(dev); 158 158 struct isl12022 *isl12022 = i2c_get_clientdata(client); 159 159 size_t i; 160 160 int ret; ··· 201 199 return ret; 202 200 } 203 201 204 - isl12022->write_enabled = 1; 202 + isl12022->write_enabled = true; 205 203 } 206 204 207 205 /* hours, minutes and seconds */ ··· 228 226 } 229 227 230 228 return 0; 231 - } 232 - 233 - static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm) 234 - { 235 - return isl12022_get_datetime(to_i2c_client(dev), tm); 236 - } 237 - 238 - static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm) 239 - { 240 - return isl12022_set_datetime(to_i2c_client(dev), tm); 241 229 } 242 230 243 231 static const struct rtc_class_ops isl12022_rtc_ops = {
+501
drivers/rtc/rtc-isl12026.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * An I2C driver for the Intersil ISL 12026 4 + * 5 + * Copyright (c) 2018 Cavium, Inc. 6 + */ 7 + #include <linux/bcd.h> 8 + #include <linux/delay.h> 9 + #include <linux/i2c.h> 10 + #include <linux/module.h> 11 + #include <linux/mutex.h> 12 + #include <linux/nvmem-provider.h> 13 + #include <linux/of.h> 14 + #include <linux/of_device.h> 15 + #include <linux/rtc.h> 16 + #include <linux/slab.h> 17 + 18 + /* register offsets */ 19 + #define ISL12026_REG_PWR 0x14 20 + # define ISL12026_REG_PWR_BSW BIT(6) 21 + # define ISL12026_REG_PWR_SBIB BIT(7) 22 + #define ISL12026_REG_SC 0x30 23 + #define ISL12026_REG_HR 0x32 24 + # define ISL12026_REG_HR_MIL BIT(7) /* military or 24 hour time */ 25 + #define ISL12026_REG_SR 0x3f 26 + # define ISL12026_REG_SR_RTCF BIT(0) 27 + # define ISL12026_REG_SR_WEL BIT(1) 28 + # define ISL12026_REG_SR_RWEL BIT(2) 29 + # define ISL12026_REG_SR_MBZ BIT(3) 30 + # define ISL12026_REG_SR_OSCF BIT(4) 31 + 32 + /* The EEPROM array responds at i2c address 0x57 */ 33 + #define ISL12026_EEPROM_ADDR 0x57 34 + 35 + #define ISL12026_PAGESIZE 16 36 + #define ISL12026_NVMEM_WRITE_TIME 20 37 + 38 + struct isl12026 { 39 + struct rtc_device *rtc; 40 + struct i2c_client *nvm_client; 41 + }; 42 + 43 + static int isl12026_read_reg(struct i2c_client *client, int reg) 44 + { 45 + u8 addr[] = {0, reg}; 46 + u8 val; 47 + int ret; 48 + 49 + struct i2c_msg msgs[] = { 50 + { 51 + .addr = client->addr, 52 + .flags = 0, 53 + .len = sizeof(addr), 54 + .buf = addr 55 + }, { 56 + .addr = client->addr, 57 + .flags = I2C_M_RD, 58 + .len = 1, 59 + .buf = &val 60 + } 61 + }; 62 + 63 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 64 + if (ret != ARRAY_SIZE(msgs)) { 65 + dev_err(&client->dev, "read reg error, ret=%d\n", ret); 66 + ret = ret < 0 ? ret : -EIO; 67 + } else { 68 + ret = val; 69 + } 70 + 71 + return ret; 72 + } 73 + 74 + static int isl12026_arm_write(struct i2c_client *client) 75 + { 76 + int ret; 77 + u8 op[3]; 78 + struct i2c_msg msg = { 79 + .addr = client->addr, 80 + .flags = 0, 81 + .len = 1, 82 + .buf = op 83 + }; 84 + 85 + /* Set SR.WEL */ 86 + op[0] = 0; 87 + op[1] = ISL12026_REG_SR; 88 + op[2] = ISL12026_REG_SR_WEL; 89 + msg.len = 3; 90 + ret = i2c_transfer(client->adapter, &msg, 1); 91 + if (ret != 1) { 92 + dev_err(&client->dev, "write error SR.WEL, ret=%d\n", ret); 93 + ret = ret < 0 ? ret : -EIO; 94 + goto out; 95 + } 96 + 97 + /* Set SR.WEL and SR.RWEL */ 98 + op[2] = ISL12026_REG_SR_WEL | ISL12026_REG_SR_RWEL; 99 + msg.len = 3; 100 + ret = i2c_transfer(client->adapter, &msg, 1); 101 + if (ret != 1) { 102 + dev_err(&client->dev, 103 + "write error SR.WEL|SR.RWEL, ret=%d\n", ret); 104 + ret = ret < 0 ? ret : -EIO; 105 + goto out; 106 + } else { 107 + ret = 0; 108 + } 109 + out: 110 + return ret; 111 + } 112 + 113 + static int isl12026_disarm_write(struct i2c_client *client) 114 + { 115 + int ret; 116 + u8 op[3] = {0, ISL12026_REG_SR, 0}; 117 + struct i2c_msg msg = { 118 + .addr = client->addr, 119 + .flags = 0, 120 + .len = sizeof(op), 121 + .buf = op 122 + }; 123 + 124 + ret = i2c_transfer(client->adapter, &msg, 1); 125 + if (ret != 1) { 126 + dev_err(&client->dev, 127 + "write error SR, ret=%d\n", ret); 128 + ret = ret < 0 ? ret : -EIO; 129 + } else { 130 + ret = 0; 131 + } 132 + 133 + return ret; 134 + } 135 + 136 + static int isl12026_write_reg(struct i2c_client *client, int reg, u8 val) 137 + { 138 + int ret; 139 + u8 op[3] = {0, reg, val}; 140 + struct i2c_msg msg = { 141 + .addr = client->addr, 142 + .flags = 0, 143 + .len = sizeof(op), 144 + .buf = op 145 + }; 146 + 147 + ret = isl12026_arm_write(client); 148 + if (ret) 149 + return ret; 150 + 151 + ret = i2c_transfer(client->adapter, &msg, 1); 152 + if (ret != 1) { 153 + dev_err(&client->dev, "write error CCR, ret=%d\n", ret); 154 + ret = ret < 0 ? ret : -EIO; 155 + goto out; 156 + } 157 + 158 + msleep(ISL12026_NVMEM_WRITE_TIME); 159 + 160 + ret = isl12026_disarm_write(client); 161 + out: 162 + return ret; 163 + } 164 + 165 + static int isl12026_rtc_set_time(struct device *dev, struct rtc_time *tm) 166 + { 167 + struct i2c_client *client = to_i2c_client(dev); 168 + int ret; 169 + u8 op[10]; 170 + struct i2c_msg msg = { 171 + .addr = client->addr, 172 + .flags = 0, 173 + .len = sizeof(op), 174 + .buf = op 175 + }; 176 + 177 + ret = isl12026_arm_write(client); 178 + if (ret) 179 + return ret; 180 + 181 + /* Set the CCR registers */ 182 + op[0] = 0; 183 + op[1] = ISL12026_REG_SC; 184 + op[2] = bin2bcd(tm->tm_sec); /* SC */ 185 + op[3] = bin2bcd(tm->tm_min); /* MN */ 186 + op[4] = bin2bcd(tm->tm_hour) | ISL12026_REG_HR_MIL; /* HR */ 187 + op[5] = bin2bcd(tm->tm_mday); /* DT */ 188 + op[6] = bin2bcd(tm->tm_mon + 1); /* MO */ 189 + op[7] = bin2bcd(tm->tm_year % 100); /* YR */ 190 + op[8] = bin2bcd(tm->tm_wday & 7); /* DW */ 191 + op[9] = bin2bcd(tm->tm_year >= 100 ? 20 : 19); /* Y2K */ 192 + ret = i2c_transfer(client->adapter, &msg, 1); 193 + if (ret != 1) { 194 + dev_err(&client->dev, "write error CCR, ret=%d\n", ret); 195 + ret = ret < 0 ? ret : -EIO; 196 + goto out; 197 + } 198 + 199 + ret = isl12026_disarm_write(client); 200 + out: 201 + return ret; 202 + } 203 + 204 + static int isl12026_rtc_read_time(struct device *dev, struct rtc_time *tm) 205 + { 206 + struct i2c_client *client = to_i2c_client(dev); 207 + u8 ccr[8]; 208 + u8 addr[2]; 209 + u8 sr; 210 + int ret; 211 + struct i2c_msg msgs[] = { 212 + { 213 + .addr = client->addr, 214 + .flags = 0, 215 + .len = sizeof(addr), 216 + .buf = addr 217 + }, { 218 + .addr = client->addr, 219 + .flags = I2C_M_RD, 220 + } 221 + }; 222 + 223 + /* First, read SR */ 224 + addr[0] = 0; 225 + addr[1] = ISL12026_REG_SR; 226 + msgs[1].len = 1; 227 + msgs[1].buf = &sr; 228 + 229 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 230 + if (ret != ARRAY_SIZE(msgs)) { 231 + dev_err(&client->dev, "read error, ret=%d\n", ret); 232 + ret = ret < 0 ? ret : -EIO; 233 + goto out; 234 + } 235 + 236 + if (sr & ISL12026_REG_SR_RTCF) 237 + dev_warn(&client->dev, "Real-Time Clock Failure on read\n"); 238 + if (sr & ISL12026_REG_SR_OSCF) 239 + dev_warn(&client->dev, "Oscillator Failure on read\n"); 240 + 241 + /* Second, CCR regs */ 242 + addr[0] = 0; 243 + addr[1] = ISL12026_REG_SC; 244 + msgs[1].len = sizeof(ccr); 245 + msgs[1].buf = ccr; 246 + 247 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 248 + if (ret != ARRAY_SIZE(msgs)) { 249 + dev_err(&client->dev, "read error, ret=%d\n", ret); 250 + ret = ret < 0 ? ret : -EIO; 251 + goto out; 252 + } 253 + 254 + tm->tm_sec = bcd2bin(ccr[0] & 0x7F); 255 + tm->tm_min = bcd2bin(ccr[1] & 0x7F); 256 + if (ccr[2] & ISL12026_REG_HR_MIL) 257 + tm->tm_hour = bcd2bin(ccr[2] & 0x3F); 258 + else 259 + tm->tm_hour = bcd2bin(ccr[2] & 0x1F) + 260 + ((ccr[2] & 0x20) ? 12 : 0); 261 + tm->tm_mday = bcd2bin(ccr[3] & 0x3F); 262 + tm->tm_mon = bcd2bin(ccr[4] & 0x1F) - 1; 263 + tm->tm_year = bcd2bin(ccr[5]); 264 + if (bcd2bin(ccr[7]) == 20) 265 + tm->tm_year += 100; 266 + tm->tm_wday = ccr[6] & 0x07; 267 + 268 + ret = 0; 269 + out: 270 + return ret; 271 + } 272 + 273 + static const struct rtc_class_ops isl12026_rtc_ops = { 274 + .read_time = isl12026_rtc_read_time, 275 + .set_time = isl12026_rtc_set_time, 276 + }; 277 + 278 + static int isl12026_nvm_read(void *p, unsigned int offset, 279 + void *val, size_t bytes) 280 + { 281 + struct isl12026 *priv = p; 282 + int ret; 283 + u8 addr[2]; 284 + struct i2c_msg msgs[] = { 285 + { 286 + .addr = priv->nvm_client->addr, 287 + .flags = 0, 288 + .len = sizeof(addr), 289 + .buf = addr 290 + }, { 291 + .addr = priv->nvm_client->addr, 292 + .flags = I2C_M_RD, 293 + .buf = val 294 + } 295 + }; 296 + 297 + /* 298 + * offset and bytes checked and limited by nvmem core, so 299 + * proceed without further checks. 300 + */ 301 + ret = mutex_lock_interruptible(&priv->rtc->ops_lock); 302 + if (ret) 303 + return ret; 304 + 305 + /* 2 bytes of address, most significant first */ 306 + addr[0] = offset >> 8; 307 + addr[1] = offset; 308 + msgs[1].len = bytes; 309 + ret = i2c_transfer(priv->nvm_client->adapter, msgs, ARRAY_SIZE(msgs)); 310 + 311 + mutex_unlock(&priv->rtc->ops_lock); 312 + 313 + if (ret != ARRAY_SIZE(msgs)) { 314 + dev_err(&priv->nvm_client->dev, 315 + "nvmem read error, ret=%d\n", ret); 316 + return ret < 0 ? ret : -EIO; 317 + } 318 + 319 + return 0; 320 + } 321 + 322 + static int isl12026_nvm_write(void *p, unsigned int offset, 323 + void *val, size_t bytes) 324 + { 325 + struct isl12026 *priv = p; 326 + int ret; 327 + u8 *v = val; 328 + size_t chunk_size, num_written; 329 + u8 payload[ISL12026_PAGESIZE + 2]; /* page + 2 address bytes */ 330 + struct i2c_msg msgs[] = { 331 + { 332 + .addr = priv->nvm_client->addr, 333 + .flags = 0, 334 + .buf = payload 335 + } 336 + }; 337 + 338 + /* 339 + * offset and bytes checked and limited by nvmem core, so 340 + * proceed without further checks. 341 + */ 342 + ret = mutex_lock_interruptible(&priv->rtc->ops_lock); 343 + if (ret) 344 + return ret; 345 + 346 + num_written = 0; 347 + while (bytes) { 348 + chunk_size = round_down(offset, ISL12026_PAGESIZE) + 349 + ISL12026_PAGESIZE - offset; 350 + chunk_size = min(bytes, chunk_size); 351 + /* 352 + * 2 bytes of address, most significant first, followed 353 + * by page data bytes 354 + */ 355 + memcpy(payload + 2, v + num_written, chunk_size); 356 + payload[0] = offset >> 8; 357 + payload[1] = offset; 358 + msgs[0].len = chunk_size + 2; 359 + ret = i2c_transfer(priv->nvm_client->adapter, 360 + msgs, ARRAY_SIZE(msgs)); 361 + if (ret != ARRAY_SIZE(msgs)) { 362 + dev_err(&priv->nvm_client->dev, 363 + "nvmem write error, ret=%d\n", ret); 364 + ret = ret < 0 ? ret : -EIO; 365 + break; 366 + } 367 + ret = 0; 368 + bytes -= chunk_size; 369 + offset += chunk_size; 370 + num_written += chunk_size; 371 + msleep(ISL12026_NVMEM_WRITE_TIME); 372 + } 373 + 374 + mutex_unlock(&priv->rtc->ops_lock); 375 + 376 + return ret; 377 + } 378 + 379 + static void isl12026_force_power_modes(struct i2c_client *client) 380 + { 381 + int ret; 382 + int pwr, requested_pwr; 383 + u32 bsw_val, sbib_val; 384 + bool set_bsw, set_sbib; 385 + 386 + /* 387 + * If we can read the of_property, set the specified value. 388 + * If there is an error reading the of_property (likely 389 + * because it does not exist), keep the current value. 390 + */ 391 + ret = of_property_read_u32(client->dev.of_node, 392 + "isil,pwr-bsw", &bsw_val); 393 + set_bsw = (ret == 0); 394 + 395 + ret = of_property_read_u32(client->dev.of_node, 396 + "isil,pwr-sbib", &sbib_val); 397 + set_sbib = (ret == 0); 398 + 399 + /* Check if PWR.BSW and/or PWR.SBIB need specified values */ 400 + if (!set_bsw && !set_sbib) 401 + return; 402 + 403 + pwr = isl12026_read_reg(client, ISL12026_REG_PWR); 404 + if (pwr < 0) { 405 + dev_warn(&client->dev, "Error: Failed to read PWR %d\n", pwr); 406 + return; 407 + } 408 + 409 + requested_pwr = pwr; 410 + 411 + if (set_bsw) { 412 + if (bsw_val) 413 + requested_pwr |= ISL12026_REG_PWR_BSW; 414 + else 415 + requested_pwr &= ~ISL12026_REG_PWR_BSW; 416 + } /* else keep current BSW */ 417 + 418 + if (set_sbib) { 419 + if (sbib_val) 420 + requested_pwr |= ISL12026_REG_PWR_SBIB; 421 + else 422 + requested_pwr &= ~ISL12026_REG_PWR_SBIB; 423 + } /* else keep current SBIB */ 424 + 425 + if (pwr >= 0 && pwr != requested_pwr) { 426 + dev_dbg(&client->dev, "PWR: %02x\n", pwr); 427 + dev_dbg(&client->dev, "Updating PWR to: %02x\n", requested_pwr); 428 + isl12026_write_reg(client, ISL12026_REG_PWR, requested_pwr); 429 + } 430 + } 431 + 432 + static int isl12026_probe_new(struct i2c_client *client) 433 + { 434 + struct isl12026 *priv; 435 + int ret; 436 + struct nvmem_config nvm_cfg = { 437 + .name = "isl12026-", 438 + .base_dev = &client->dev, 439 + .stride = 1, 440 + .word_size = 1, 441 + .size = 512, 442 + .reg_read = isl12026_nvm_read, 443 + .reg_write = isl12026_nvm_write, 444 + }; 445 + 446 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 447 + return -ENODEV; 448 + 449 + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); 450 + if (!priv) 451 + return -ENOMEM; 452 + 453 + i2c_set_clientdata(client, priv); 454 + 455 + isl12026_force_power_modes(client); 456 + 457 + priv->nvm_client = i2c_new_dummy(client->adapter, ISL12026_EEPROM_ADDR); 458 + if (!priv->nvm_client) 459 + return -ENOMEM; 460 + 461 + priv->rtc = devm_rtc_allocate_device(&client->dev); 462 + ret = PTR_ERR_OR_ZERO(priv->rtc); 463 + if (ret) 464 + return ret; 465 + 466 + priv->rtc->ops = &isl12026_rtc_ops; 467 + nvm_cfg.priv = priv; 468 + ret = rtc_nvmem_register(priv->rtc, &nvm_cfg); 469 + if (ret) 470 + return ret; 471 + 472 + return rtc_register_device(priv->rtc); 473 + } 474 + 475 + static int isl12026_remove(struct i2c_client *client) 476 + { 477 + struct isl12026 *priv = i2c_get_clientdata(client); 478 + 479 + i2c_unregister_device(priv->nvm_client); 480 + return 0; 481 + } 482 + 483 + static const struct of_device_id isl12026_dt_match[] = { 484 + { .compatible = "isil,isl12026" }, 485 + { } 486 + }; 487 + MODULE_DEVICE_TABLE(of, isl12026_dt_match); 488 + 489 + static struct i2c_driver isl12026_driver = { 490 + .driver = { 491 + .name = "rtc-isl12026", 492 + .of_match_table = isl12026_dt_match, 493 + }, 494 + .probe_new = isl12026_probe_new, 495 + .remove = isl12026_remove, 496 + }; 497 + 498 + module_i2c_driver(isl12026_driver); 499 + 500 + MODULE_DESCRIPTION("ISL 12026 RTC driver"); 501 + MODULE_LICENSE("GPL");
+26 -21
drivers/rtc/rtc-isl1208.c
··· 459 459 } 460 460 461 461 /* clear WRTC again */ 462 + sr = isl1208_i2c_get_sr(client); 463 + if (sr < 0) { 464 + dev_err(&client->dev, "%s: reading SR failed\n", __func__); 465 + return sr; 466 + } 462 467 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, 463 468 sr & ~ISL1208_REG_SR_WRTC); 464 469 if (sr < 0) { ··· 635 630 if (isl1208_i2c_validate_client(client) < 0) 636 631 return -ENODEV; 637 632 638 - if (client->irq > 0) { 639 - rc = devm_request_threaded_irq(&client->dev, client->irq, NULL, 640 - isl1208_rtc_interrupt, 641 - IRQF_SHARED | IRQF_ONESHOT, 642 - isl1208_driver.driver.name, 643 - client); 644 - if (!rc) { 645 - device_init_wakeup(&client->dev, 1); 646 - enable_irq_wake(client->irq); 647 - } else { 648 - dev_err(&client->dev, 649 - "Unable to request irq %d, no alarm support\n", 650 - client->irq); 651 - client->irq = 0; 652 - } 653 - } 654 - 655 - rtc = devm_rtc_device_register(&client->dev, isl1208_driver.driver.name, 656 - &isl1208_rtc_ops, 657 - THIS_MODULE); 633 + rtc = devm_rtc_allocate_device(&client->dev); 658 634 if (IS_ERR(rtc)) 659 635 return PTR_ERR(rtc); 636 + 637 + rtc->ops = &isl1208_rtc_ops; 660 638 661 639 i2c_set_clientdata(client, rtc); 662 640 ··· 657 669 if (rc) 658 670 return rc; 659 671 660 - return 0; 672 + if (client->irq > 0) { 673 + rc = devm_request_threaded_irq(&client->dev, client->irq, NULL, 674 + isl1208_rtc_interrupt, 675 + IRQF_SHARED | IRQF_ONESHOT, 676 + isl1208_driver.driver.name, 677 + client); 678 + if (!rc) { 679 + device_init_wakeup(&client->dev, 1); 680 + enable_irq_wake(client->irq); 681 + } else { 682 + dev_err(&client->dev, 683 + "Unable to request irq %d, no alarm support\n", 684 + client->irq); 685 + client->irq = 0; 686 + } 687 + } 688 + 689 + return rtc_register_device(rtc); 661 690 } 662 691 663 692 static int
+1 -1
drivers/rtc/rtc-jz4740.c
··· 173 173 174 174 rtc_time_to_tm(secs, time); 175 175 176 - return rtc_valid_tm(time); 176 + return 0; 177 177 } 178 178 179 179 static int jz4740_rtc_set_mmss(struct device *dev, unsigned long secs)
+3 -5
drivers/rtc/rtc-lib.c
··· 52 52 */ 53 53 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm) 54 54 { 55 - unsigned int month, year; 56 - unsigned long secs; 55 + unsigned int month, year, secs; 57 56 int days; 58 57 59 58 /* time must be positive */ 60 - days = div_s64(time, 86400); 61 - secs = time - (unsigned int) days * 86400; 59 + days = div_s64_rem(time, 86400, &secs); 62 60 63 61 /* day of the week, 1970-01-01 was a Thursday */ 64 62 tm->tm_wday = (days + 4) % 7; ··· 65 67 days -= (year - 1970) * 365 66 68 + LEAPS_THRU_END_OF(year - 1) 67 69 - LEAPS_THRU_END_OF(1970 - 1); 68 - if (days < 0) { 70 + while (days < 0) { 69 71 year -= 1; 70 72 days += 365 + is_leap_year(year); 71 73 }
+1 -1
drivers/rtc/rtc-lpc24xx.c
··· 110 110 tm->tm_year = CT1_YEAR(ct1); 111 111 tm->tm_yday = CT2_DOY(ct2); 112 112 113 - return rtc_valid_tm(tm); 113 + return 0; 114 114 } 115 115 116 116 static int lpc24xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+1 -1
drivers/rtc/rtc-lpc32xx.c
··· 70 70 elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT); 71 71 rtc_time_to_tm(elapsed_sec, time); 72 72 73 - return rtc_valid_tm(time); 73 + return 0; 74 74 } 75 75 76 76 static int lpc32xx_rtc_set_mmss(struct device *dev, unsigned long secs)
+1 -1
drivers/rtc/rtc-ls1x.c
··· 98 98 ls1x_get_min(v), ls1x_get_sec(v)); 99 99 rtc_time_to_tm(t, rtm); 100 100 101 - return rtc_valid_tm(rtm); 101 + return 0; 102 102 } 103 103 104 104 static int ls1x_rtc_set_time(struct device *dev, struct rtc_time *rtm)
+18 -24
drivers/rtc/rtc-m41t80.c
··· 73 73 #define M41T80_FEATURE_WD BIT(3) /* Extra watchdog resolution */ 74 74 #define M41T80_FEATURE_SQ_ALT BIT(4) /* RSx bits are in reg 4 */ 75 75 76 - static DEFINE_MUTEX(m41t80_rtc_mutex); 77 76 static const struct i2c_device_id m41t80_id[] = { 78 77 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, 79 78 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, ··· 198 199 return IRQ_HANDLED; 199 200 } 200 201 201 - static int m41t80_get_datetime(struct i2c_client *client, 202 - struct rtc_time *tm) 202 + static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm) 203 203 { 204 + struct i2c_client *client = to_i2c_client(dev); 204 205 unsigned char buf[8]; 205 206 int err, flags; 206 207 ··· 229 230 230 231 /* assume 20YY not 19YY, and ignore the Century Bit */ 231 232 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100; 232 - return rtc_valid_tm(tm); 233 + return 0; 233 234 } 234 235 235 - /* Sets the given date and time to the real time clock. */ 236 - static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) 236 + static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm) 237 237 { 238 + struct i2c_client *client = to_i2c_client(dev); 238 239 struct m41t80_data *clientdata = i2c_get_clientdata(client); 239 240 unsigned char buf[8]; 240 241 int err, flags; ··· 295 296 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); 296 297 } 297 298 return 0; 298 - } 299 - 300 - static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm) 301 - { 302 - return m41t80_get_datetime(to_i2c_client(dev), tm); 303 - } 304 - 305 - static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm) 306 - { 307 - return m41t80_set_datetime(to_i2c_client(dev), tm); 308 299 } 309 300 310 301 static int m41t80_alarm_irq_enable(struct device *dev, unsigned int enabled) ··· 587 598 * 588 599 ***************************************************************************** 589 600 */ 601 + static DEFINE_MUTEX(m41t80_rtc_mutex); 590 602 static struct i2c_client *save_client; 591 603 592 604 /* Default margin */ ··· 875 885 { 876 886 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 877 887 int rc = 0; 878 - struct rtc_device *rtc = NULL; 879 888 struct rtc_time tm; 880 889 struct m41t80_data *m41t80_data = NULL; 881 890 bool wakeup_source = false; ··· 897 908 else 898 909 m41t80_data->features = id->driver_data; 899 910 i2c_set_clientdata(client, m41t80_data); 911 + 912 + m41t80_data->rtc = devm_rtc_allocate_device(&client->dev); 913 + if (IS_ERR(m41t80_data->rtc)) 914 + return PTR_ERR(m41t80_data->rtc); 900 915 901 916 #ifdef CONFIG_OF 902 917 wakeup_source = of_property_read_bool(client->dev.of_node, ··· 925 932 device_init_wakeup(&client->dev, true); 926 933 } 927 934 928 - rtc = devm_rtc_device_register(&client->dev, client->name, 929 - &m41t80_rtc_ops, THIS_MODULE); 930 - if (IS_ERR(rtc)) 931 - return PTR_ERR(rtc); 935 + m41t80_data->rtc->ops = &m41t80_rtc_ops; 932 936 933 - m41t80_data->rtc = rtc; 934 937 if (client->irq <= 0) { 935 938 /* We cannot support UIE mode if we do not have an IRQ line */ 936 - rtc->uie_unsupported = 1; 939 + m41t80_data->rtc->uie_unsupported = 1; 937 940 } 938 941 939 942 /* Make sure HT (Halt Update) bit is cleared */ ··· 937 948 938 949 if (rc >= 0 && rc & M41T80_ALHOUR_HT) { 939 950 if (m41t80_data->features & M41T80_FEATURE_HT) { 940 - m41t80_get_datetime(client, &tm); 951 + m41t80_rtc_read_time(&client->dev, &tm); 941 952 dev_info(&client->dev, "HT bit was set!\n"); 942 953 dev_info(&client->dev, 943 954 "Power Down at %04i-%02i-%02i %02i:%02i:%02i\n", ··· 982 993 if (m41t80_data->features & M41T80_FEATURE_SQ) 983 994 m41t80_sqw_register_clk(m41t80_data); 984 995 #endif 996 + 997 + rc = rtc_register_device(m41t80_data->rtc); 998 + if (rc) 999 + return rc; 1000 + 985 1001 return 0; 986 1002 } 987 1003
+1 -1
drivers/rtc/rtc-m41t93.c
··· 159 159 tm->tm_hour, tm->tm_mday, 160 160 tm->tm_mon, tm->tm_year, tm->tm_wday); 161 161 162 - return ret < 0 ? ret : rtc_valid_tm(tm); 162 + return ret; 163 163 } 164 164 165 165
+1 -2
drivers/rtc/rtc-m41t94.c
··· 99 99 tm->tm_hour, tm->tm_mday, 100 100 tm->tm_mon, tm->tm_year, tm->tm_wday); 101 101 102 - /* initial clock setting can be undefined */ 103 - return rtc_valid_tm(tm); 102 + return 0; 104 103 } 105 104 106 105 static const struct rtc_class_ops m41t94_rtc_ops = {
+1 -1
drivers/rtc/rtc-m48t35.c
··· 84 84 tm->tm_year += 100; 85 85 86 86 tm->tm_mon--; 87 - return rtc_valid_tm(tm); 87 + return 0; 88 88 } 89 89 90 90 static int m48t35_set_time(struct device *dev, struct rtc_time *tm)
+29 -32
drivers/rtc/rtc-m48t59.c
··· 105 105 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n", 106 106 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 107 107 tm->tm_hour, tm->tm_min, tm->tm_sec); 108 - return rtc_valid_tm(tm); 108 + return 0; 109 109 } 110 110 111 111 static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 334 334 .set_time = m48t59_rtc_set_time, 335 335 }; 336 336 337 - static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj, 338 - struct bin_attribute *bin_attr, 339 - char *buf, loff_t pos, size_t size) 337 + static int m48t59_nvram_read(void *priv, unsigned int offset, void *val, 338 + size_t size) 340 339 { 341 - struct device *dev = container_of(kobj, struct device, kobj); 342 - struct platform_device *pdev = to_platform_device(dev); 340 + struct platform_device *pdev = priv; 341 + struct device *dev = &pdev->dev; 343 342 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); 344 343 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 345 344 ssize_t cnt = 0; 346 345 unsigned long flags; 346 + u8 *buf = val; 347 347 348 348 spin_lock_irqsave(&m48t59->lock, flags); 349 349 ··· 352 352 353 353 spin_unlock_irqrestore(&m48t59->lock, flags); 354 354 355 - return cnt; 355 + return 0; 356 356 } 357 357 358 - static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj, 359 - struct bin_attribute *bin_attr, 360 - char *buf, loff_t pos, size_t size) 358 + static int m48t59_nvram_write(void *priv, unsigned int offset, void *val, 359 + size_t size) 361 360 { 362 - struct device *dev = container_of(kobj, struct device, kobj); 363 - struct platform_device *pdev = to_platform_device(dev); 361 + struct platform_device *pdev = priv; 362 + struct device *dev = &pdev->dev; 364 363 struct m48t59_plat_data *pdata = dev_get_platdata(&pdev->dev); 365 364 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 366 365 ssize_t cnt = 0; 367 366 unsigned long flags; 367 + u8 *buf = val; 368 368 369 369 spin_lock_irqsave(&m48t59->lock, flags); 370 370 ··· 373 373 374 374 spin_unlock_irqrestore(&m48t59->lock, flags); 375 375 376 - return cnt; 376 + return 0; 377 377 } 378 - 379 - static struct bin_attribute m48t59_nvram_attr = { 380 - .attr = { 381 - .name = "nvram", 382 - .mode = S_IRUGO | S_IWUSR, 383 - }, 384 - .read = m48t59_nvram_read, 385 - .write = m48t59_nvram_write, 386 - }; 387 378 388 379 static int m48t59_rtc_probe(struct platform_device *pdev) 389 380 { ··· 384 393 int ret = -ENOMEM; 385 394 char *name; 386 395 const struct rtc_class_ops *ops; 396 + struct nvmem_config nvmem_cfg = { 397 + .name = "m48t59-", 398 + .word_size = 1, 399 + .stride = 1, 400 + .reg_read = m48t59_nvram_read, 401 + .reg_write = m48t59_nvram_write, 402 + .priv = pdev, 403 + }; 387 404 388 405 /* This chip could be memory-mapped or I/O-mapped */ 389 406 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 479 480 spin_lock_init(&m48t59->lock); 480 481 platform_set_drvdata(pdev, m48t59); 481 482 482 - m48t59->rtc = devm_rtc_device_register(&pdev->dev, name, ops, 483 - THIS_MODULE); 483 + m48t59->rtc = devm_rtc_allocate_device(&pdev->dev); 484 484 if (IS_ERR(m48t59->rtc)) 485 485 return PTR_ERR(m48t59->rtc); 486 486 487 - m48t59_nvram_attr.size = pdata->offset; 487 + m48t59->rtc->nvram_old_abi = true; 488 + m48t59->rtc->ops = ops; 488 489 489 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 490 + nvmem_cfg.size = pdata->offset; 491 + ret = rtc_nvmem_register(m48t59->rtc, &nvmem_cfg); 490 492 if (ret) 491 493 return ret; 492 494 493 - return 0; 494 - } 495 + ret = rtc_register_device(m48t59->rtc); 496 + if (ret) 497 + return ret; 495 498 496 - static int m48t59_rtc_remove(struct platform_device *pdev) 497 - { 498 - sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 499 499 return 0; 500 500 } 501 501 ··· 506 508 .name = "rtc-m48t59", 507 509 }, 508 510 .probe = m48t59_rtc_probe, 509 - .remove = m48t59_rtc_remove, 510 511 }; 511 512 512 513 module_platform_driver(m48t59_rtc_driver);
+12 -13
drivers/rtc/rtc-m48t86.c
··· 100 100 if (m48t86_readb(dev, M48T86_HOUR) & 0x80) 101 101 tm->tm_hour += 12; 102 102 103 - return rtc_valid_tm(tm); 103 + return 0; 104 104 } 105 105 106 106 static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 218 218 return false; 219 219 } 220 220 221 - static struct nvmem_config m48t86_nvmem_cfg = { 222 - .name = "m48t86_nvram", 223 - .word_size = 1, 224 - .stride = 1, 225 - .size = M48T86_NVRAM_LEN, 226 - .reg_read = m48t86_nvram_read, 227 - .reg_write = m48t86_nvram_write, 228 - }; 229 - 230 221 static int m48t86_rtc_probe(struct platform_device *pdev) 231 222 { 232 223 struct m48t86_rtc_info *info; 233 224 struct resource *res; 234 225 unsigned char reg; 235 226 int err; 227 + struct nvmem_config m48t86_nvmem_cfg = { 228 + .name = "m48t86_nvram", 229 + .word_size = 1, 230 + .stride = 1, 231 + .size = M48T86_NVRAM_LEN, 232 + .reg_read = m48t86_nvram_read, 233 + .reg_write = m48t86_nvram_write, 234 + .priv = &pdev->dev, 235 + }; 236 236 237 237 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 238 238 if (!info) ··· 264 264 return PTR_ERR(info->rtc); 265 265 266 266 info->rtc->ops = &m48t86_rtc_ops; 267 - 268 - m48t86_nvmem_cfg.priv = &pdev->dev; 269 - info->rtc->nvmem_config = &m48t86_nvmem_cfg; 270 267 info->rtc->nvram_old_abi = true; 271 268 272 269 err = rtc_register_device(info->rtc); 273 270 if (err) 274 271 return err; 272 + 273 + rtc_nvmem_register(info->rtc, &m48t86_nvmem_cfg); 275 274 276 275 /* read battery status */ 277 276 reg = m48t86_readb(&pdev->dev, M48T86_D);
+5 -14
drivers/rtc/rtc-max6900.c
··· 139 139 return -EIO; 140 140 } 141 141 142 - static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 142 + static int max6900_rtc_read_time(struct device *dev, struct rtc_time *tm) 143 143 { 144 + struct i2c_client *client = to_i2c_client(dev); 144 145 int rc; 145 146 u8 regs[MAX6900_REG_LEN]; 146 147 ··· 158 157 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 158 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]); 160 159 161 - return rtc_valid_tm(tm); 160 + return 0; 162 161 } 163 162 164 163 static int max6900_i2c_clear_write_protect(struct i2c_client *client) ··· 166 165 return i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0); 167 166 } 168 167 169 - static int 170 - max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) 168 + static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm) 171 169 { 170 + struct i2c_client *client = to_i2c_client(dev); 172 171 u8 regs[MAX6900_REG_LEN]; 173 172 int rc; 174 173 ··· 192 191 return rc; 193 192 194 193 return 0; 195 - } 196 - 197 - static int max6900_rtc_read_time(struct device *dev, struct rtc_time *tm) 198 - { 199 - return max6900_i2c_read_time(to_i2c_client(dev), tm); 200 - } 201 - 202 - static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm) 203 - { 204 - return max6900_i2c_set_time(to_i2c_client(dev), tm); 205 194 } 206 195 207 196 static const struct rtc_class_ops max6900_rtc_ops = {
+1 -1
drivers/rtc/rtc-max6902.c
··· 85 85 dt->tm_year += century; 86 86 dt->tm_year -= 1900; 87 87 88 - return rtc_valid_tm(dt); 88 + return 0; 89 89 } 90 90 91 91 static int max6902_set_time(struct device *dev, struct rtc_time *dt)
+1 -1
drivers/rtc/rtc-max6916.c
··· 75 75 dt->tm_wday = bcd2bin(buf[5]) - 1; 76 76 dt->tm_year = bcd2bin(buf[6]) + 100; 77 77 78 - return rtc_valid_tm(dt); 78 + return 0; 79 79 } 80 80 81 81 static int max6916_set_time(struct device *dev, struct rtc_time *dt)
+1 -3
drivers/rtc/rtc-max77686.c
··· 364 364 365 365 max77686_rtc_data_to_tm(data, tm, info); 366 366 367 - ret = rtc_valid_tm(tm); 368 - 369 367 out: 370 368 mutex_unlock(&info->lock); 371 - return ret; 369 + return 0; 372 370 } 373 371 374 372 static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-max8997.c
··· 153 153 154 154 max8997_rtc_data_to_tm(data, tm, info->rtc_24hr_mode); 155 155 156 - return rtc_valid_tm(tm); 156 + return 0; 157 157 } 158 158 159 159 static int max8997_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-max8998.c
··· 120 120 121 121 max8998_data_to_tm(data, tm); 122 122 123 - return rtc_valid_tm(tm); 123 + return 0; 124 124 } 125 125 126 126 static int max8998_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-mc13xxx.c
··· 85 85 86 86 rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm); 87 87 88 - return rtc_valid_tm(tm); 88 + return 0; 89 89 } 90 90 91 91 static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
+2 -2
drivers/rtc/rtc-mcp795.c
··· 82 82 { 83 83 struct spi_device *spi = to_spi_device(dev); 84 84 int ret; 85 - u8 tx[2 + count]; 85 + u8 tx[257]; 86 86 87 87 tx[0] = MCP795_WRITE; 88 88 tx[1] = addr; ··· 262 262 tim->tm_year + 1900, tim->tm_mon, tim->tm_mday, 263 263 tim->tm_wday, tim->tm_hour, tim->tm_min, tim->tm_sec); 264 264 265 - return rtc_valid_tm(tim); 265 + return 0; 266 266 } 267 267 268 268 static int mcp795_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
+1 -1
drivers/rtc/rtc-mpc5121.c
··· 122 122 */ 123 123 mpc5121_rtc_update_smh(regs, tm); 124 124 125 - return rtc_valid_tm(tm); 125 + return 0; 126 126 } 127 127 128 128 static int mpc5121_rtc_set_time(struct device *dev, struct rtc_time *tm)
+2 -2
drivers/rtc/rtc-mrst.c
··· 105 105 /* Adjust for the 1972/1900 */ 106 106 time->tm_year += 72; 107 107 time->tm_mon--; 108 - return rtc_valid_tm(time); 108 + return 0; 109 109 } 110 110 111 111 static int mrst_set_time(struct device *dev, struct rtc_time *time) ··· 122 122 min = time->tm_min; 123 123 sec = time->tm_sec; 124 124 125 - if (yrs < 72 || yrs > 138) 125 + if (yrs < 72 || yrs > 172) 126 126 return -EINVAL; 127 127 yrs -= 72; 128 128
+1 -1
drivers/rtc/rtc-msm6242.c
··· 155 155 156 156 msm6242_unlock(priv); 157 157 158 - return rtc_valid_tm(tm); 158 + return 0; 159 159 } 160 160 161 161 static int msm6242_set_time(struct device *dev, struct rtc_time *tm)
+2 -1
drivers/rtc/rtc-mt7622.c
··· 232 232 233 233 mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC); 234 234 235 - return rtc_valid_tm(tm); 235 + return 0; 236 236 } 237 237 238 238 static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm) ··· 307 307 { .compatible = "mediatek,soc-rtc" }, 308 308 {}, 309 309 }; 310 + MODULE_DEVICE_TABLE(of, mtk_rtc_match); 310 311 311 312 static int mtk_rtc_probe(struct platform_device *pdev) 312 313 {
+1 -13
drivers/rtc/rtc-mv.c
··· 94 94 /* hw counts from year 2000, but tm_year is relative to 1900 */ 95 95 tm->tm_year = bcd2bin(year) + 100; 96 96 97 - return rtc_valid_tm(tm); 97 + return 0; 98 98 } 99 99 100 100 static int mv_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) ··· 223 223 struct resource *res; 224 224 struct rtc_plat_data *pdata; 225 225 u32 rtc_time; 226 - u32 rtc_date; 227 226 int ret = 0; 228 227 229 228 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); ··· 256 257 ret = -ENODEV; 257 258 goto out; 258 259 } 259 - } 260 - 261 - /* 262 - * A date after January 19th, 2038 does not fit on 32 bits and 263 - * will confuse the kernel and userspace. Reset to a sane date 264 - * (January 1st, 2013) if we're after 2038. 265 - */ 266 - rtc_date = readl(pdata->ioaddr + RTC_DATE_REG_OFFS); 267 - if (bcd2bin((rtc_date >> RTC_YEAR_OFFS) & 0xff) >= 38) { 268 - dev_info(&pdev->dev, "invalid RTC date, resetting to January 1st, 2013\n"); 269 - writel(0x130101, pdata->ioaddr + RTC_DATE_REG_OFFS); 270 260 } 271 261 272 262 pdata->irq = platform_get_irq(pdev, 0);
+1 -1
drivers/rtc/rtc-mxc_v2.c
··· 273 273 .alarm_irq_enable = mxc_rtc_alarm_irq_enable, 274 274 }; 275 275 276 - static int mxc_rtc_wait_for_flag(void *__iomem ioaddr, int flag) 276 + static int mxc_rtc_wait_for_flag(void __iomem *ioaddr, int flag) 277 277 { 278 278 unsigned int timeout = REG_READ_TIMEOUT; 279 279
+8 -6
drivers/rtc/rtc-nuc900.c
··· 102 102 return NULL; 103 103 } 104 104 105 - static int nuc900_rtc_bcd2bin(unsigned int timereg, 106 - unsigned int calreg, struct rtc_time *tm) 105 + static void nuc900_rtc_bcd2bin(unsigned int timereg, 106 + unsigned int calreg, struct rtc_time *tm) 107 107 { 108 108 tm->tm_mday = bcd2bin(calreg >> 0); 109 109 tm->tm_mon = bcd2bin(calreg >> 8); ··· 112 112 tm->tm_sec = bcd2bin(timereg >> 0); 113 113 tm->tm_min = bcd2bin(timereg >> 8); 114 114 tm->tm_hour = bcd2bin(timereg >> 16); 115 - 116 - return rtc_valid_tm(tm); 117 115 } 118 116 119 117 static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm, ··· 154 156 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR); 155 157 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR); 156 158 157 - return nuc900_rtc_bcd2bin(timeval, clrval, tm); 159 + nuc900_rtc_bcd2bin(timeval, clrval, tm); 160 + 161 + return 0; 158 162 } 159 163 160 164 static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 189 189 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR); 190 190 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR); 191 191 192 - return nuc900_rtc_bcd2bin(timeval, carval, &alrm->time); 192 + nuc900_rtc_bcd2bin(timeval, carval, &alrm->time); 193 + 194 + return rtc_valid_tm(&alrm->time); 193 195 } 194 196 195 197 static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+2 -4
drivers/rtc/rtc-omap.c
··· 273 273 /* this hardware doesn't support "don't care" alarm fields */ 274 274 static int tm2bcd(struct rtc_time *tm) 275 275 { 276 - if (rtc_valid_tm(tm) != 0) 277 - return -EINVAL; 278 - 279 276 tm->tm_sec = bin2bcd(tm->tm_sec); 280 277 tm->tm_min = bin2bcd(tm->tm_min); 281 278 tm->tm_hour = bin2bcd(tm->tm_hour); ··· 847 850 848 851 rtc->rtc->ops = &omap_rtc_ops; 849 852 omap_rtc_nvmem_config.priv = rtc; 850 - rtc->rtc->nvmem_config = &omap_rtc_nvmem_config; 851 853 852 854 /* handle periodic and alarm irqs */ 853 855 ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0, ··· 881 885 ret = rtc_register_device(rtc->rtc); 882 886 if (ret) 883 887 goto err; 888 + 889 + rtc_nvmem_register(rtc->rtc, &omap_rtc_nvmem_config); 884 890 885 891 return 0; 886 892
+1 -1
drivers/rtc/rtc-pcap.c
··· 95 95 96 96 rtc_time_to_tm(secs, tm); 97 97 98 - return rtc_valid_tm(tm); 98 + return 0; 99 99 } 100 100 101 101 static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs)
+1 -1
drivers/rtc/rtc-pcf2123.c
··· 289 289 tm->tm_sec, tm->tm_min, tm->tm_hour, 290 290 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 291 291 292 - return rtc_valid_tm(tm); 292 + return 0; 293 293 } 294 294 295 295 static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-pcf2127.c
··· 111 111 tm->tm_sec, tm->tm_min, tm->tm_hour, 112 112 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 113 113 114 - return rtc_valid_tm(tm); 114 + return 0; 115 115 } 116 116 117 117 static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-pcf50633.c
··· 135 135 tm->tm_mday, tm->tm_mon, tm->tm_year, 136 136 tm->tm_hour, tm->tm_min, tm->tm_sec); 137 137 138 - return rtc_valid_tm(tm); 138 + return 0; 139 139 } 140 140 141 141 static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
+6 -14
drivers/rtc/rtc-pcf85063.c
··· 70 70 s32 ret; 71 71 72 72 /* start the clock */ 73 - ctrl1 &= PCF85063_REG_CTRL1_STOP; 73 + ctrl1 &= ~PCF85063_REG_CTRL1_STOP; 74 74 75 75 ret = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); 76 76 if (ret < 0) { ··· 81 81 return 0; 82 82 } 83 83 84 - static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) 84 + static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) 85 85 { 86 + struct i2c_client *client = to_i2c_client(dev); 86 87 int rc; 87 88 u8 regs[7]; 88 89 ··· 115 114 tm->tm_year = bcd2bin(regs[6]); 116 115 tm->tm_year += 100; 117 116 118 - return rtc_valid_tm(tm); 117 + return 0; 119 118 } 120 119 121 - static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm) 120 + static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) 122 121 { 122 + struct i2c_client *client = to_i2c_client(dev); 123 123 int rc; 124 124 u8 regs[7]; 125 125 u8 ctrl1; ··· 172 170 return rc; 173 171 174 172 return 0; 175 - } 176 - 177 - static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) 178 - { 179 - return pcf85063_get_datetime(to_i2c_client(dev), tm); 180 - } 181 - 182 - static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) 183 - { 184 - return pcf85063_set_datetime(to_i2c_client(dev), tm); 185 173 } 186 174 187 175 static const struct rtc_class_ops pcf85063_rtc_ops = {
+1 -1
drivers/rtc/rtc-pcf8523.c
··· 192 192 tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1; 193 193 tm->tm_year = bcd2bin(regs[6]) + 100; 194 194 195 - return rtc_valid_tm(tm); 195 + return 0; 196 196 } 197 197 198 198 static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
+191 -14
drivers/rtc/rtc-pcf85363.c
··· 73 73 #define CTRL_RESETS 0x2f 74 74 #define CTRL_RAM 0x40 75 75 76 + #define ALRM_SEC_A1E BIT(0) 77 + #define ALRM_MIN_A1E BIT(1) 78 + #define ALRM_HR_A1E BIT(2) 79 + #define ALRM_DAY_A1E BIT(3) 80 + #define ALRM_MON_A1E BIT(4) 81 + #define ALRM_MIN_A2E BIT(5) 82 + #define ALRM_HR_A2E BIT(6) 83 + #define ALRM_DAY_A2E BIT(7) 84 + 85 + #define INT_WDIE BIT(0) 86 + #define INT_BSIE BIT(1) 87 + #define INT_TSRIE BIT(2) 88 + #define INT_A2IE BIT(3) 89 + #define INT_A1IE BIT(4) 90 + #define INT_OIE BIT(5) 91 + #define INT_PIE BIT(6) 92 + #define INT_ILP BIT(7) 93 + 94 + #define FLAGS_TSR1F BIT(0) 95 + #define FLAGS_TSR2F BIT(1) 96 + #define FLAGS_TSR3F BIT(2) 97 + #define FLAGS_BSF BIT(3) 98 + #define FLAGS_WDF BIT(4) 99 + #define FLAGS_A1F BIT(5) 100 + #define FLAGS_A2F BIT(6) 101 + #define FLAGS_PIF BIT(7) 102 + 103 + #define PIN_IO_INTAPM GENMASK(1, 0) 104 + #define PIN_IO_INTA_CLK 0 105 + #define PIN_IO_INTA_BAT 1 106 + #define PIN_IO_INTA_OUT 2 107 + #define PIN_IO_INTA_HIZ 3 108 + 109 + #define STOP_EN_STOP BIT(0) 110 + 111 + #define RESET_CPR 0xa4 112 + 76 113 #define NVRAM_SIZE 0x40 77 114 78 115 static struct i2c_driver pcf85363_driver; ··· 117 80 struct pcf85363 { 118 81 struct device *dev; 119 82 struct rtc_device *rtc; 120 - struct nvmem_config nvmem_cfg; 121 83 struct regmap *regmap; 122 84 }; 123 85 ··· 152 116 static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) 153 117 { 154 118 struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 155 - unsigned char buf[DT_YEARS + 1]; 156 - int len = sizeof(buf); 119 + unsigned char tmp[11]; 120 + unsigned char *buf = &tmp[2]; 121 + int ret; 122 + 123 + tmp[0] = STOP_EN_STOP; 124 + tmp[1] = RESET_CPR; 157 125 158 126 buf[DT_100THS] = 0; 159 127 buf[DT_SECS] = bin2bcd(tm->tm_sec); ··· 168 128 buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); 169 129 buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); 170 130 171 - return regmap_bulk_write(pcf85363->regmap, DT_100THS, 172 - buf, len); 131 + ret = regmap_bulk_write(pcf85363->regmap, CTRL_STOP_EN, 132 + tmp, sizeof(tmp)); 133 + if (ret) 134 + return ret; 135 + 136 + return regmap_write(pcf85363->regmap, CTRL_STOP_EN, 0); 137 + } 138 + 139 + static int pcf85363_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 140 + { 141 + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 142 + unsigned char buf[DT_MONTH_ALM1 - DT_SECOND_ALM1 + 1]; 143 + unsigned int val; 144 + int ret; 145 + 146 + ret = regmap_bulk_read(pcf85363->regmap, DT_SECOND_ALM1, buf, 147 + sizeof(buf)); 148 + if (ret) 149 + return ret; 150 + 151 + alrm->time.tm_sec = bcd2bin(buf[0]); 152 + alrm->time.tm_min = bcd2bin(buf[1]); 153 + alrm->time.tm_hour = bcd2bin(buf[2]); 154 + alrm->time.tm_mday = bcd2bin(buf[3]); 155 + alrm->time.tm_mon = bcd2bin(buf[4]) - 1; 156 + 157 + ret = regmap_read(pcf85363->regmap, CTRL_INTA_EN, &val); 158 + if (ret) 159 + return ret; 160 + 161 + alrm->enabled = !!(val & INT_A1IE); 162 + 163 + return 0; 164 + } 165 + 166 + static int _pcf85363_rtc_alarm_irq_enable(struct pcf85363 *pcf85363, unsigned 167 + int enabled) 168 + { 169 + unsigned int alarm_flags = ALRM_SEC_A1E | ALRM_MIN_A1E | ALRM_HR_A1E | 170 + ALRM_DAY_A1E | ALRM_MON_A1E; 171 + int ret; 172 + 173 + ret = regmap_update_bits(pcf85363->regmap, DT_ALARM_EN, alarm_flags, 174 + enabled ? alarm_flags : 0); 175 + if (ret) 176 + return ret; 177 + 178 + ret = regmap_update_bits(pcf85363->regmap, CTRL_INTA_EN, 179 + INT_A1IE, enabled ? INT_A1IE : 0); 180 + 181 + if (ret || enabled) 182 + return ret; 183 + 184 + /* clear current flags */ 185 + return regmap_update_bits(pcf85363->regmap, CTRL_FLAGS, FLAGS_A1F, 0); 186 + } 187 + 188 + static int pcf85363_rtc_alarm_irq_enable(struct device *dev, 189 + unsigned int enabled) 190 + { 191 + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 192 + 193 + return _pcf85363_rtc_alarm_irq_enable(pcf85363, enabled); 194 + } 195 + 196 + static int pcf85363_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 197 + { 198 + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 199 + unsigned char buf[DT_MONTH_ALM1 - DT_SECOND_ALM1 + 1]; 200 + int ret; 201 + 202 + buf[0] = bin2bcd(alrm->time.tm_sec); 203 + buf[1] = bin2bcd(alrm->time.tm_min); 204 + buf[2] = bin2bcd(alrm->time.tm_hour); 205 + buf[3] = bin2bcd(alrm->time.tm_mday); 206 + buf[4] = bin2bcd(alrm->time.tm_mon + 1); 207 + 208 + /* 209 + * Disable the alarm interrupt before changing the value to avoid 210 + * spurious interrupts 211 + */ 212 + ret = _pcf85363_rtc_alarm_irq_enable(pcf85363, 0); 213 + if (ret) 214 + return ret; 215 + 216 + ret = regmap_bulk_write(pcf85363->regmap, DT_SECOND_ALM1, buf, 217 + sizeof(buf)); 218 + if (ret) 219 + return ret; 220 + 221 + return _pcf85363_rtc_alarm_irq_enable(pcf85363, alrm->enabled); 222 + } 223 + 224 + static irqreturn_t pcf85363_rtc_handle_irq(int irq, void *dev_id) 225 + { 226 + struct pcf85363 *pcf85363 = i2c_get_clientdata(dev_id); 227 + unsigned int flags; 228 + int err; 229 + 230 + err = regmap_read(pcf85363->regmap, CTRL_FLAGS, &flags); 231 + if (err) 232 + return IRQ_NONE; 233 + 234 + if (flags & FLAGS_A1F) { 235 + rtc_update_irq(pcf85363->rtc, 1, RTC_IRQF | RTC_AF); 236 + regmap_update_bits(pcf85363->regmap, CTRL_FLAGS, FLAGS_A1F, 0); 237 + return IRQ_HANDLED; 238 + } 239 + 240 + return IRQ_NONE; 173 241 } 174 242 175 243 static const struct rtc_class_ops rtc_ops = { 176 244 .read_time = pcf85363_rtc_read_time, 177 245 .set_time = pcf85363_rtc_set_time, 246 + }; 247 + 248 + static const struct rtc_class_ops rtc_ops_alarm = { 249 + .read_time = pcf85363_rtc_read_time, 250 + .set_time = pcf85363_rtc_set_time, 251 + .read_alarm = pcf85363_rtc_read_alarm, 252 + .set_alarm = pcf85363_rtc_set_alarm, 253 + .alarm_irq_enable = pcf85363_rtc_alarm_irq_enable, 178 254 }; 179 255 180 256 static int pcf85363_nvram_read(void *priv, unsigned int offset, void *val, ··· 314 158 static const struct regmap_config regmap_config = { 315 159 .reg_bits = 8, 316 160 .val_bits = 8, 161 + .max_register = 0x7f, 317 162 }; 318 163 319 164 static int pcf85363_probe(struct i2c_client *client, 320 165 const struct i2c_device_id *id) 321 166 { 322 167 struct pcf85363 *pcf85363; 168 + struct nvmem_config nvmem_cfg = { 169 + .name = "pcf85363-", 170 + .word_size = 1, 171 + .stride = 1, 172 + .size = NVRAM_SIZE, 173 + .reg_read = pcf85363_nvram_read, 174 + .reg_write = pcf85363_nvram_write, 175 + }; 176 + int ret; 323 177 324 178 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 325 179 return -ENODEV; ··· 352 186 if (IS_ERR(pcf85363->rtc)) 353 187 return PTR_ERR(pcf85363->rtc); 354 188 355 - pcf85363->nvmem_cfg.name = "pcf85363-"; 356 - pcf85363->nvmem_cfg.word_size = 1; 357 - pcf85363->nvmem_cfg.stride = 1; 358 - pcf85363->nvmem_cfg.size = NVRAM_SIZE; 359 - pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; 360 - pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; 361 - pcf85363->nvmem_cfg.priv = pcf85363; 362 - pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; 363 189 pcf85363->rtc->ops = &rtc_ops; 364 190 365 - return rtc_register_device(pcf85363->rtc); 191 + if (client->irq > 0) { 192 + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); 193 + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, 194 + PIN_IO_INTA_OUT, PIN_IO_INTAPM); 195 + ret = devm_request_threaded_irq(pcf85363->dev, client->irq, 196 + NULL, pcf85363_rtc_handle_irq, 197 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 198 + "pcf85363", client); 199 + if (ret) 200 + dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); 201 + else 202 + pcf85363->rtc->ops = &rtc_ops_alarm; 203 + } 204 + 205 + ret = rtc_register_device(pcf85363->rtc); 206 + 207 + nvmem_cfg.priv = pcf85363; 208 + rtc_nvmem_register(pcf85363->rtc, &nvmem_cfg); 209 + 210 + return ret; 366 211 } 367 212 368 213 static const struct of_device_id dev_ids[] = {
+1 -1
drivers/rtc/rtc-pic32.c
··· 175 175 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 176 176 177 177 clk_disable(pdata->clk); 178 - return rtc_valid_tm(rtc_tm); 178 + return 0; 179 179 } 180 180 181 181 static int pic32_rtc_settime(struct device *dev, struct rtc_time *tm)
+39 -18
drivers/rtc/rtc-pm8xxx.c
··· 74 74 /* 75 75 * Steps to write the RTC registers. 76 76 * 1. Disable alarm if enabled. 77 - * 2. Write 0x00 to LSB. 78 - * 3. Write Byte[1], Byte[2], Byte[3] then Byte[0]. 79 - * 4. Enable alarm if disabled in step 1. 77 + * 2. Disable rtc if enabled. 78 + * 3. Write 0x00 to LSB. 79 + * 4. Write Byte[1], Byte[2], Byte[3] then Byte[0]. 80 + * 5. Enable rtc if disabled in step 2. 81 + * 6. Enable alarm if disabled in step 1. 80 82 */ 81 83 static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) 82 84 { 83 85 int rc, i; 84 86 unsigned long secs, irq_flags; 85 - u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0; 86 - unsigned int ctrl_reg; 87 + u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0, rtc_disabled = 0; 88 + unsigned int ctrl_reg, rtc_ctrl_reg; 87 89 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); 88 90 const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; 89 91 ··· 94 92 95 93 rtc_tm_to_time(tm, &secs); 96 94 95 + dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs); 96 + 97 97 for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) { 98 98 value[i] = secs & 0xFF; 99 99 secs >>= 8; 100 100 } 101 101 102 - dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs); 103 - 104 102 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); 105 103 106 - rc = regmap_read(rtc_dd->regmap, regs->ctrl, &ctrl_reg); 104 + rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); 107 105 if (rc) 108 106 goto rtc_rw_fail; 109 107 110 108 if (ctrl_reg & regs->alarm_en) { 111 109 alarm_enabled = 1; 112 110 ctrl_reg &= ~regs->alarm_en; 113 - rc = regmap_write(rtc_dd->regmap, regs->ctrl, ctrl_reg); 111 + rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); 112 + if (rc) { 113 + dev_err(dev, "Write to RTC Alarm control register failed\n"); 114 + goto rtc_rw_fail; 115 + } 116 + } 117 + 118 + /* Disable RTC H/w before writing on RTC register */ 119 + rc = regmap_read(rtc_dd->regmap, regs->ctrl, &rtc_ctrl_reg); 120 + if (rc) 121 + goto rtc_rw_fail; 122 + 123 + if (rtc_ctrl_reg & PM8xxx_RTC_ENABLE) { 124 + rtc_disabled = 1; 125 + rtc_ctrl_reg &= ~PM8xxx_RTC_ENABLE; 126 + rc = regmap_write(rtc_dd->regmap, regs->ctrl, rtc_ctrl_reg); 114 127 if (rc) { 115 128 dev_err(dev, "Write to RTC control register failed\n"); 116 129 goto rtc_rw_fail; ··· 154 137 goto rtc_rw_fail; 155 138 } 156 139 157 - if (alarm_enabled) { 158 - ctrl_reg |= regs->alarm_en; 159 - rc = regmap_write(rtc_dd->regmap, regs->ctrl, ctrl_reg); 140 + /* Enable RTC H/w after writing on RTC register */ 141 + if (rtc_disabled) { 142 + rtc_ctrl_reg |= PM8xxx_RTC_ENABLE; 143 + rc = regmap_write(rtc_dd->regmap, regs->ctrl, rtc_ctrl_reg); 160 144 if (rc) { 161 145 dev_err(dev, "Write to RTC control register failed\n"); 146 + goto rtc_rw_fail; 147 + } 148 + } 149 + 150 + if (alarm_enabled) { 151 + ctrl_reg |= regs->alarm_en; 152 + rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); 153 + if (rc) { 154 + dev_err(dev, "Write to RTC Alarm control register failed\n"); 162 155 goto rtc_rw_fail; 163 156 } 164 157 } ··· 216 189 secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); 217 190 218 191 rtc_time_to_tm(secs, tm); 219 - 220 - rc = rtc_valid_tm(tm); 221 - if (rc < 0) { 222 - dev_err(dev, "Invalid time read from RTC\n"); 223 - return rc; 224 - } 225 192 226 193 dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n", 227 194 secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
+1 -1
drivers/rtc/rtc-ps3.c
··· 41 41 static int ps3_get_time(struct device *dev, struct rtc_time *tm) 42 42 { 43 43 rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm); 44 - return rtc_valid_tm(tm); 44 + return 0; 45 45 } 46 46 47 47 static int ps3_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-r7301.c
··· 224 224 225 225 spin_unlock_irqrestore(&priv->lock, flags); 226 226 227 - return err ? err : rtc_valid_tm(tm); 227 + return err; 228 228 } 229 229 230 230 static int rtc7301_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-r9701.c
··· 92 92 * according to the data sheet. make sure they are valid. 93 93 */ 94 94 95 - return rtc_valid_tm(dt); 95 + return 0; 96 96 } 97 97 98 98 static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
+7 -18
drivers/rtc/rtc-rk808.c
··· 375 375 { 376 376 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); 377 377 struct rk808_rtc *rk808_rtc; 378 - struct rtc_time tm; 379 378 int ret; 380 379 381 380 rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc), GFP_KERNEL); ··· 403 404 return ret; 404 405 } 405 406 406 - /* set init time */ 407 - ret = rk808_rtc_readtime(&pdev->dev, &tm); 408 - if (ret) { 409 - dev_err(&pdev->dev, "Failed to read RTC time\n"); 410 - return ret; 411 - } 412 - ret = rtc_valid_tm(&tm); 413 - if (ret) 414 - dev_warn(&pdev->dev, "invalid date/time\n"); 415 - 416 407 device_init_wakeup(&pdev->dev, 1); 417 408 418 - rk808_rtc->rtc = devm_rtc_device_register(&pdev->dev, "rk808-rtc", 419 - &rk808_rtc_ops, THIS_MODULE); 420 - if (IS_ERR(rk808_rtc->rtc)) { 421 - ret = PTR_ERR(rk808_rtc->rtc); 422 - return ret; 423 - } 409 + rk808_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); 410 + if (IS_ERR(rk808_rtc->rtc)) 411 + return PTR_ERR(rk808_rtc->rtc); 412 + 413 + rk808_rtc->rtc->ops = &rk808_rtc_ops; 424 414 425 415 rk808_rtc->irq = platform_get_irq(pdev, 0); 426 416 if (rk808_rtc->irq < 0) { ··· 426 438 if (ret) { 427 439 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", 428 440 rk808_rtc->irq, ret); 441 + return ret; 429 442 } 430 443 431 - return ret; 444 + return rtc_register_device(rk808_rtc->rtc); 432 445 } 433 446 434 447 static struct platform_driver rk808_rtc_driver = {
+29 -38
drivers/rtc/rtc-rp5c01.c
··· 64 64 u32 __iomem *regs; 65 65 struct rtc_device *rtc; 66 66 spinlock_t lock; /* against concurrent RTC/NVRAM access */ 67 - struct bin_attribute nvram_attr; 68 67 }; 69 68 70 69 static inline unsigned int rp5c01_read(struct rp5c01_priv *priv, ··· 115 116 rp5c01_unlock(priv); 116 117 spin_unlock_irq(&priv->lock); 117 118 118 - return rtc_valid_tm(tm); 119 + return 0; 119 120 } 120 121 121 122 static int rp5c01_set_time(struct device *dev, struct rtc_time *tm) ··· 159 160 * byte is stored in BLOCK10, the low nibble in BLOCK11. 160 161 */ 161 162 162 - static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj, 163 - struct bin_attribute *bin_attr, 164 - char *buf, loff_t pos, size_t size) 163 + static int rp5c01_nvram_read(void *_priv, unsigned int pos, void *val, 164 + size_t bytes) 165 165 { 166 - struct device *dev = container_of(kobj, struct device, kobj); 167 - struct rp5c01_priv *priv = dev_get_drvdata(dev); 168 - ssize_t count; 166 + struct rp5c01_priv *priv = _priv; 167 + u8 *buf = val; 169 168 170 169 spin_lock_irq(&priv->lock); 171 170 172 - for (count = 0; count < size; count++) { 171 + for (; bytes; bytes--) { 173 172 u8 data; 174 173 175 174 rp5c01_write(priv, ··· 184 187 } 185 188 186 189 spin_unlock_irq(&priv->lock); 187 - return count; 190 + return 0; 188 191 } 189 192 190 - static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj, 191 - struct bin_attribute *bin_attr, 192 - char *buf, loff_t pos, size_t size) 193 + static int rp5c01_nvram_write(void *_priv, unsigned int pos, void *val, 194 + size_t bytes) 193 195 { 194 - struct device *dev = container_of(kobj, struct device, kobj); 195 - struct rp5c01_priv *priv = dev_get_drvdata(dev); 196 - ssize_t count; 196 + struct rp5c01_priv *priv = _priv; 197 + u8 *buf = val; 197 198 198 199 spin_lock_irq(&priv->lock); 199 200 200 - for (count = 0; count < size; count++) { 201 + for (; bytes; bytes--) { 201 202 u8 data = *buf++; 202 203 203 204 rp5c01_write(priv, ··· 211 216 } 212 217 213 218 spin_unlock_irq(&priv->lock); 214 - return count; 219 + return 0; 215 220 } 216 221 217 222 static int __init rp5c01_rtc_probe(struct platform_device *dev) ··· 220 225 struct rp5c01_priv *priv; 221 226 struct rtc_device *rtc; 222 227 int error; 228 + struct nvmem_config nvmem_cfg = { 229 + .name = "rp5c01_nvram", 230 + .word_size = 1, 231 + .stride = 1, 232 + .size = RP5C01_MODE, 233 + .reg_read = rp5c01_nvram_read, 234 + .reg_write = rp5c01_nvram_write, 235 + }; 223 236 224 237 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 225 238 if (!res) ··· 241 238 if (!priv->regs) 242 239 return -ENOMEM; 243 240 244 - sysfs_bin_attr_init(&priv->nvram_attr); 245 - priv->nvram_attr.attr.name = "nvram"; 246 - priv->nvram_attr.attr.mode = S_IRUGO | S_IWUSR; 247 - priv->nvram_attr.read = rp5c01_nvram_read; 248 - priv->nvram_attr.write = rp5c01_nvram_write; 249 - priv->nvram_attr.size = RP5C01_MODE; 250 - 251 241 spin_lock_init(&priv->lock); 252 242 253 243 platform_set_drvdata(dev, priv); 254 244 255 - rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops, 256 - THIS_MODULE); 245 + rtc = devm_rtc_allocate_device(&dev->dev); 257 246 if (IS_ERR(rtc)) 258 247 return PTR_ERR(rtc); 248 + 249 + rtc->ops = &rp5c01_rtc_ops; 250 + rtc->nvram_old_abi = true; 251 + 259 252 priv->rtc = rtc; 260 253 261 - error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); 254 + nvmem_cfg.priv = priv; 255 + error = rtc_nvmem_register(rtc, &nvmem_cfg); 262 256 if (error) 263 257 return error; 264 258 265 - return 0; 266 - } 267 - 268 - static int __exit rp5c01_rtc_remove(struct platform_device *dev) 269 - { 270 - struct rp5c01_priv *priv = platform_get_drvdata(dev); 271 - 272 - sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr); 273 - return 0; 259 + return rtc_register_device(rtc); 274 260 } 275 261 276 262 static struct platform_driver rp5c01_rtc_driver = { 277 263 .driver = { 278 264 .name = "rtc-rp5c01", 279 265 }, 280 - .remove = __exit_p(rp5c01_rtc_remove), 281 266 }; 282 267 283 268 module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe);
-5
drivers/rtc/rtc-rs5c348.c
··· 135 135 tm->tm_year = bcd2bin(rxbuf[RS5C348_REG_YEAR]) + 136 136 ((rxbuf[RS5C348_REG_MONTH] & RS5C348_BIT_Y2K) ? 100 : 0); 137 137 138 - if (rtc_valid_tm(tm) < 0) { 139 - dev_err(&spi->dev, "retrieved date/time is not valid.\n"); 140 - rtc_time_to_tm(0, tm); 141 - } 142 - 143 138 return 0; 144 139 } 145 140
+5 -19
drivers/rtc/rtc-rs5c372.c
··· 207 207 return bin2bcd(hour); 208 208 } 209 209 210 - static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) 210 + static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm) 211 211 { 212 + struct i2c_client *client = to_i2c_client(dev); 212 213 struct rs5c372 *rs5c = i2c_get_clientdata(client); 213 214 int status = rs5c_get_regs(rs5c); 214 215 ··· 235 234 tm->tm_sec, tm->tm_min, tm->tm_hour, 236 235 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 237 236 238 - /* rtc might need initialization */ 239 - return rtc_valid_tm(tm); 237 + return 0; 240 238 } 241 239 242 - static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm) 240 + static int rs5c372_rtc_set_time(struct device *dev, struct rtc_time *tm) 243 241 { 242 + struct i2c_client *client = to_i2c_client(dev); 244 243 struct rs5c372 *rs5c = i2c_get_clientdata(client); 245 244 unsigned char buf[7]; 246 245 int addr; ··· 305 304 return 0; 306 305 } 307 306 #endif 308 - 309 - static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm) 310 - { 311 - return rs5c372_get_datetime(to_i2c_client(dev), tm); 312 - } 313 - 314 - static int rs5c372_rtc_set_time(struct device *dev, struct rtc_time *tm) 315 - { 316 - return rs5c372_set_datetime(to_i2c_client(dev), tm); 317 - } 318 - 319 307 320 308 static int rs5c_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 321 309 { ··· 571 581 int err = 0; 572 582 int smbus_mode = 0; 573 583 struct rs5c372 *rs5c372; 574 - struct rtc_time tm; 575 584 576 585 dev_dbg(&client->dev, "%s\n", __func__); 577 586 ··· 650 661 dev_err(&client->dev, "setup error\n"); 651 662 goto exit; 652 663 } 653 - 654 - if (rs5c372_get_datetime(client, &tm) < 0) 655 - dev_warn(&client->dev, "clock needs to be set\n"); 656 664 657 665 dev_info(&client->dev, "%s found, %s\n", 658 666 ({ char *s; switch (rs5c372->type) {
+17 -16
drivers/rtc/rtc-rv8803.c
··· 68 68 struct mutex flags_lock; 69 69 u8 ctrl; 70 70 enum rv8803_type type; 71 - struct nvmem_config nvmem_cfg; 72 71 }; 73 72 74 73 static int rv8803_read_reg(const struct i2c_client *client, u8 reg) ··· 527 528 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 528 529 struct rv8803_data *rv8803; 529 530 int err, flags; 531 + struct nvmem_config nvmem_cfg = { 532 + .name = "rv8803_nvram", 533 + .word_size = 1, 534 + .stride = 1, 535 + .size = 1, 536 + .reg_read = rv8803_nvram_read, 537 + .reg_write = rv8803_nvram_write, 538 + .priv = client, 539 + }; 530 540 531 541 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 532 542 I2C_FUNC_SMBUS_I2C_BLOCK)) { ··· 590 582 } 591 583 } 592 584 593 - rv8803->nvmem_cfg.name = "rv8803_nvram", 594 - rv8803->nvmem_cfg.word_size = 1, 595 - rv8803->nvmem_cfg.stride = 1, 596 - rv8803->nvmem_cfg.size = 1, 597 - rv8803->nvmem_cfg.reg_read = rv8803_nvram_read, 598 - rv8803->nvmem_cfg.reg_write = rv8803_nvram_write, 599 - rv8803->nvmem_cfg.priv = client; 600 - 601 - rv8803->rtc->ops = &rv8803_rtc_ops; 602 - rv8803->rtc->nvmem_config = &rv8803->nvmem_cfg; 603 - rv8803->rtc->nvram_old_abi = true; 604 - err = rtc_register_device(rv8803->rtc); 605 - if (err) 606 - return err; 607 - 608 585 err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); 609 586 if (err) 610 587 return err; ··· 599 606 dev_err(&client->dev, "failed to init charger\n"); 600 607 return err; 601 608 } 609 + 610 + rv8803->rtc->ops = &rv8803_rtc_ops; 611 + rv8803->rtc->nvram_old_abi = true; 612 + err = rtc_register_device(rv8803->rtc); 613 + if (err) 614 + return err; 615 + 616 + rtc_nvmem_register(rv8803->rtc, &nvmem_cfg); 602 617 603 618 rv8803->rtc->max_user_freq = 1; 604 619
+1 -5
drivers/rtc/rtc-rx4581.c
··· 172 172 tm->tm_sec, tm->tm_min, tm->tm_hour, 173 173 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 174 174 175 - err = rtc_valid_tm(tm); 176 - if (err < 0) 177 - dev_err(dev, "retrieved date/time is not valid.\n"); 178 - 179 - return err; 175 + return 0; 180 176 } 181 177 182 178 static int rx4581_set_datetime(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-rx6110.c
··· 252 252 tm->tm_sec, tm->tm_min, tm->tm_hour, 253 253 tm->tm_mday, tm->tm_mon, tm->tm_year); 254 254 255 - return rtc_valid_tm(tm); 255 + return 0; 256 256 } 257 257 258 258 static const struct reg_sequence rx6110_default_regs[] = {
+1 -1
drivers/rtc/rtc-rx8010.c
··· 138 138 dt->tm_year = bcd2bin(date[RX8010_YEAR - RX8010_SEC]) + 100; 139 139 dt->tm_wday = ffs(date[RX8010_WDAY - RX8010_SEC] & 0x7f); 140 140 141 - return rtc_valid_tm(dt); 141 + return 0; 142 142 } 143 143 144 144 static int rx8010_set_time(struct device *dev, struct rtc_time *dt)
+1 -1
drivers/rtc/rtc-rx8025.c
··· 214 214 dt->tm_sec, dt->tm_min, dt->tm_hour, 215 215 dt->tm_mday, dt->tm_mon, dt->tm_year); 216 216 217 - return rtc_valid_tm(dt); 217 + return 0; 218 218 } 219 219 220 220 static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
+1 -5
drivers/rtc/rtc-rx8581.c
··· 164 164 tm->tm_sec, tm->tm_min, tm->tm_hour, 165 165 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 166 166 167 - err = rtc_valid_tm(tm); 168 - if (err < 0) 169 - dev_err(&client->dev, "retrieved date/time is not valid.\n"); 170 - 171 - return err; 167 + return 0; 172 168 } 173 169 174 170 static int rx8581_set_datetime(struct i2c_client *client, struct rtc_time *tm)
+9 -29
drivers/rtc/rtc-s35390a.c
··· 210 210 return hour; 211 211 } 212 212 213 - static int s35390a_set_datetime(struct i2c_client *client, struct rtc_time *tm) 213 + static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm) 214 214 { 215 + struct i2c_client *client = to_i2c_client(dev); 215 216 struct s35390a *s35390a = i2c_get_clientdata(client); 216 217 int i, err; 217 218 char buf[7], status; ··· 242 241 return err; 243 242 } 244 243 245 - static int s35390a_get_datetime(struct i2c_client *client, struct rtc_time *tm) 244 + static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm) 246 245 { 246 + struct i2c_client *client = to_i2c_client(dev); 247 247 struct s35390a *s35390a = i2c_get_clientdata(client); 248 248 char buf[7], status; 249 249 int i, err; ··· 273 271 tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, 274 272 tm->tm_wday); 275 273 276 - return rtc_valid_tm(tm); 274 + return 0; 277 275 } 278 276 279 - static int s35390a_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alm) 277 + static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 280 278 { 279 + struct i2c_client *client = to_i2c_client(dev); 281 280 struct s35390a *s35390a = i2c_get_clientdata(client); 282 281 char buf[3], sts = 0; 283 282 int err, i; ··· 332 329 return err; 333 330 } 334 331 335 - static int s35390a_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alm) 332 + static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 336 333 { 334 + struct i2c_client *client = to_i2c_client(dev); 337 335 struct s35390a *s35390a = i2c_get_clientdata(client); 338 336 char buf[3], sts; 339 337 int i, err; ··· 388 384 return 0; 389 385 } 390 386 391 - static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 392 - { 393 - return s35390a_read_alarm(to_i2c_client(dev), alm); 394 - } 395 - 396 - static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 397 - { 398 - return s35390a_set_alarm(to_i2c_client(dev), alm); 399 - } 400 - 401 - static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm) 402 - { 403 - return s35390a_get_datetime(to_i2c_client(dev), tm); 404 - } 405 - 406 - static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm) 407 - { 408 - return s35390a_set_datetime(to_i2c_client(dev), tm); 409 - } 410 - 411 387 static int s35390a_rtc_ioctl(struct device *dev, unsigned int cmd, 412 388 unsigned long arg) 413 389 { ··· 434 450 int err, err_read; 435 451 unsigned int i; 436 452 struct s35390a *s35390a; 437 - struct rtc_time tm; 438 453 char buf, status1; 439 454 440 455 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { ··· 490 507 goto exit_dummy; 491 508 } 492 509 } 493 - 494 - if (err_read > 0 || s35390a_get_datetime(client, &tm) < 0) 495 - dev_warn(&client->dev, "clock needs to be set\n"); 496 510 497 511 device_set_wakeup_capable(&client->dev, 1); 498 512
+1 -1
drivers/rtc/rtc-s3c.c
··· 232 232 233 233 rtc_tm->tm_mon -= 1; 234 234 235 - return rtc_valid_tm(rtc_tm); 235 + return 0; 236 236 } 237 237 238 238 static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
+20 -7
drivers/rtc/rtc-s5m.c
··· 38 38 */ 39 39 #define UDR_READ_RETRY_CNT 5 40 40 41 + enum { 42 + RTC_SEC = 0, 43 + RTC_MIN, 44 + RTC_HOUR, 45 + RTC_WEEKDAY, 46 + RTC_DATE, 47 + RTC_MONTH, 48 + RTC_YEAR1, 49 + RTC_YEAR2, 50 + /* Make sure this is always the last enum name. */ 51 + RTC_MAX_NUM_TIME_REGS 52 + }; 53 + 41 54 /* 42 55 * Registers used by the driver which are different between chipsets. 43 56 * ··· 380 367 static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm) 381 368 { 382 369 struct s5m_rtc_info *info = dev_get_drvdata(dev); 383 - u8 data[info->regs->regs_count]; 370 + u8 data[RTC_MAX_NUM_TIME_REGS]; 384 371 int ret; 385 372 386 373 if (info->regs->read_time_udr_mask) { ··· 420 407 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, 421 408 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday); 422 409 423 - return rtc_valid_tm(tm); 410 + return 0; 424 411 } 425 412 426 413 static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm) 427 414 { 428 415 struct s5m_rtc_info *info = dev_get_drvdata(dev); 429 - u8 data[info->regs->regs_count]; 416 + u8 data[RTC_MAX_NUM_TIME_REGS]; 430 417 int ret = 0; 431 418 432 419 switch (info->device_type) { ··· 463 450 static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 464 451 { 465 452 struct s5m_rtc_info *info = dev_get_drvdata(dev); 466 - u8 data[info->regs->regs_count]; 453 + u8 data[RTC_MAX_NUM_TIME_REGS]; 467 454 unsigned int val; 468 455 int ret, i; 469 456 ··· 513 500 514 501 static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info) 515 502 { 516 - u8 data[info->regs->regs_count]; 503 + u8 data[RTC_MAX_NUM_TIME_REGS]; 517 504 int ret, i; 518 505 struct rtc_time tm; 519 506 ··· 558 545 static int s5m_rtc_start_alarm(struct s5m_rtc_info *info) 559 546 { 560 547 int ret; 561 - u8 data[info->regs->regs_count]; 548 + u8 data[RTC_MAX_NUM_TIME_REGS]; 562 549 u8 alarm0_conf; 563 550 struct rtc_time tm; 564 551 ··· 611 598 static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 612 599 { 613 600 struct s5m_rtc_info *info = dev_get_drvdata(dev); 614 - u8 data[info->regs->regs_count]; 601 + u8 data[RTC_MAX_NUM_TIME_REGS]; 615 602 int ret; 616 603 617 604 switch (info->device_type) {
+1 -1
drivers/rtc/rtc-sc27xx.c
··· 376 376 return ret; 377 377 378 378 rtc_time64_to_tm(secs, tm); 379 - return rtc_valid_tm(tm); 379 + return 0; 380 380 } 381 381 382 382 static int sprd_rtc_set_time(struct device *dev, struct rtc_time *tm)
+1 -1
drivers/rtc/rtc-sh.c
··· 414 414 tm->tm_sec, tm->tm_min, tm->tm_hour, 415 415 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 416 416 417 - return rtc_valid_tm(tm); 417 + return 0; 418 418 } 419 419 420 420 static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
-18
drivers/rtc/rtc-sirfsoc.c
··· 204 204 return 0; 205 205 } 206 206 207 - static int sirfsoc_rtc_ioctl(struct device *dev, unsigned int cmd, 208 - unsigned long arg) 209 - { 210 - switch (cmd) { 211 - case RTC_PIE_ON: 212 - case RTC_PIE_OFF: 213 - case RTC_UIE_ON: 214 - case RTC_UIE_OFF: 215 - case RTC_AIE_ON: 216 - case RTC_AIE_OFF: 217 - return 0; 218 - 219 - default: 220 - return -ENOIOCTLCMD; 221 - } 222 - } 223 - 224 207 static int sirfsoc_rtc_alarm_irq_enable(struct device *dev, 225 208 unsigned int enabled) 226 209 { ··· 233 250 .set_time = sirfsoc_rtc_set_time, 234 251 .read_alarm = sirfsoc_rtc_read_alarm, 235 252 .set_alarm = sirfsoc_rtc_set_alarm, 236 - .ioctl = sirfsoc_rtc_ioctl, 237 253 .alarm_irq_enable = sirfsoc_rtc_alarm_irq_enable 238 254 }; 239 255
+11 -4
drivers/rtc/rtc-snvs.c
··· 132 132 { 133 133 struct snvs_rtc_data *data = dev_get_drvdata(dev); 134 134 unsigned long time; 135 + int ret; 135 136 136 137 rtc_tm_to_time(tm, &time); 137 138 138 139 /* Disable RTC first */ 139 - snvs_rtc_enable(data, false); 140 + ret = snvs_rtc_enable(data, false); 141 + if (ret) 142 + return ret; 140 143 141 144 /* Write 32-bit time to 47-bit timer, leaving 15 LSBs blank */ 142 145 regmap_write(data->regmap, data->offset + SNVS_LPSRTCLR, time << CNTR_TO_SECS_SH); 143 146 regmap_write(data->regmap, data->offset + SNVS_LPSRTCMR, time >> (32 - CNTR_TO_SECS_SH)); 144 147 145 148 /* Enable RTC again */ 146 - snvs_rtc_enable(data, true); 149 + ret = snvs_rtc_enable(data, true); 147 150 148 - return 0; 151 + return ret; 149 152 } 150 153 151 154 static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ··· 291 288 regmap_write(data->regmap, data->offset + SNVS_LPSR, 0xffffffff); 292 289 293 290 /* Enable RTC */ 294 - snvs_rtc_enable(data, true); 291 + ret = snvs_rtc_enable(data, true); 292 + if (ret) { 293 + dev_err(&pdev->dev, "failed to enable rtc %d\n", ret); 294 + goto error_rtc_device_register; 295 + } 295 296 296 297 device_init_wakeup(&pdev->dev, true); 297 298
+3 -9
drivers/rtc/rtc-spear.c
··· 170 170 171 171 } 172 172 173 - static int tm2bcd(struct rtc_time *tm) 173 + static void tm2bcd(struct rtc_time *tm) 174 174 { 175 - if (rtc_valid_tm(tm) != 0) 176 - return -EINVAL; 177 175 tm->tm_sec = bin2bcd(tm->tm_sec); 178 176 tm->tm_min = bin2bcd(tm->tm_min); 179 177 tm->tm_hour = bin2bcd(tm->tm_hour); 180 178 tm->tm_mday = bin2bcd(tm->tm_mday); 181 179 tm->tm_mon = bin2bcd(tm->tm_mon + 1); 182 180 tm->tm_year = bin2bcd(tm->tm_year); 183 - 184 - return 0; 185 181 } 186 182 187 183 static void bcd2tm(struct rtc_time *tm) ··· 233 237 struct spear_rtc_config *config = dev_get_drvdata(dev); 234 238 unsigned int time, date; 235 239 236 - if (tm2bcd(tm) < 0) 237 - return -EINVAL; 240 + tm2bcd(tm); 238 241 239 242 rtc_wait_not_busy(config); 240 243 time = (tm->tm_sec << SECOND_SHIFT) | (tm->tm_min << MINUTE_SHIFT) | ··· 290 295 unsigned int time, date; 291 296 int err; 292 297 293 - if (tm2bcd(&alm->time) < 0) 294 - return -EINVAL; 298 + tm2bcd(&alm->time); 295 299 296 300 rtc_wait_not_busy(config); 297 301
-16
drivers/rtc/rtc-st-lpc.c
··· 195 195 struct device_node *np = pdev->dev.of_node; 196 196 struct st_rtc *rtc; 197 197 struct resource *res; 198 - struct rtc_time tm_check; 199 198 uint32_t mode; 200 199 int ret = 0; 201 200 ··· 252 253 device_set_wakeup_capable(&pdev->dev, 1); 253 254 254 255 platform_set_drvdata(pdev, rtc); 255 - 256 - /* 257 - * The RTC-LPC is able to manage date.year > 2038 258 - * but currently the kernel can not manage this date! 259 - * If the RTC-LPC has a date.year > 2038 then 260 - * it's set to the epoch "Jan 1st 2000" 261 - */ 262 - st_rtc_read_time(&pdev->dev, &tm_check); 263 - 264 - if (tm_check.tm_year >= (2038 - 1900)) { 265 - memset(&tm_check, 0, sizeof(tm_check)); 266 - tm_check.tm_year = 100; 267 - tm_check.tm_mday = 1; 268 - st_rtc_set_time(&pdev->dev, &tm_check); 269 - } 270 256 271 257 rtc->rtc_dev = rtc_device_register("st-lpc-rtc", &pdev->dev, 272 258 &st_rtc_ops, THIS_MODULE);
+1 -1
drivers/rtc/rtc-starfire.c
··· 28 28 static int starfire_read_time(struct device *dev, struct rtc_time *tm) 29 29 { 30 30 rtc_time_to_tm(starfire_get_time(), tm); 31 - return rtc_valid_tm(tm); 31 + return 0; 32 32 } 33 33 34 34 static const struct rtc_class_ops starfire_rtc_ops = {
+28 -46
drivers/rtc/rtc-stk17ta8.c
··· 129 129 /* year is 1900 + tm->tm_year */ 130 130 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900; 131 131 132 - if (rtc_valid_tm(tm) < 0) { 133 - dev_err(dev, "retrieved date/time is not valid.\n"); 134 - rtc_time_to_tm(0, tm); 135 - } 136 132 return 0; 137 133 } 138 134 ··· 238 242 .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable, 239 243 }; 240 244 241 - static ssize_t stk17ta8_nvram_read(struct file *filp, struct kobject *kobj, 242 - struct bin_attribute *attr, char *buf, 243 - loff_t pos, size_t size) 245 + static int stk17ta8_nvram_read(void *priv, unsigned int pos, void *val, 246 + size_t bytes) 244 247 { 245 - struct device *dev = container_of(kobj, struct device, kobj); 246 - struct platform_device *pdev = to_platform_device(dev); 247 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 248 + struct rtc_plat_data *pdata = priv; 248 249 void __iomem *ioaddr = pdata->ioaddr; 249 - ssize_t count; 250 + u8 *buf = val; 250 251 251 - for (count = 0; count < size; count++) 252 + for (; bytes; bytes--) 252 253 *buf++ = readb(ioaddr + pos++); 253 - return count; 254 + return 0; 254 255 } 255 256 256 - static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj, 257 - struct bin_attribute *attr, char *buf, 258 - loff_t pos, size_t size) 257 + static int stk17ta8_nvram_write(void *priv, unsigned int pos, void *val, 258 + size_t bytes) 259 259 { 260 - struct device *dev = container_of(kobj, struct device, kobj); 261 - struct platform_device *pdev = to_platform_device(dev); 262 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 260 + struct rtc_plat_data *pdata = priv; 263 261 void __iomem *ioaddr = pdata->ioaddr; 264 - ssize_t count; 262 + u8 *buf = val; 265 263 266 - for (count = 0; count < size; count++) 264 + for (; bytes; bytes--) 267 265 writeb(*buf++, ioaddr + pos++); 268 - return count; 266 + return 0; 269 267 } 270 - 271 - static struct bin_attribute stk17ta8_nvram_attr = { 272 - .attr = { 273 - .name = "nvram", 274 - .mode = S_IRUGO | S_IWUSR, 275 - }, 276 - .size = RTC_OFFSET, 277 - .read = stk17ta8_nvram_read, 278 - .write = stk17ta8_nvram_write, 279 - }; 280 268 281 269 static int stk17ta8_rtc_probe(struct platform_device *pdev) 282 270 { ··· 270 290 struct rtc_plat_data *pdata; 271 291 void __iomem *ioaddr; 272 292 int ret = 0; 293 + struct nvmem_config nvmem_cfg = { 294 + .name = "stk17ta8_nvram", 295 + .word_size = 1, 296 + .stride = 1, 297 + .size = RTC_OFFSET, 298 + .reg_read = stk17ta8_nvram_read, 299 + .reg_write = stk17ta8_nvram_write, 300 + }; 273 301 274 302 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 275 303 if (!pdata) ··· 316 328 } 317 329 } 318 330 319 - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 320 - &stk17ta8_rtc_ops, THIS_MODULE); 331 + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); 321 332 if (IS_ERR(pdata->rtc)) 322 333 return PTR_ERR(pdata->rtc); 323 334 324 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 335 + pdata->rtc->ops = &stk17ta8_rtc_ops; 336 + pdata->rtc->nvram_old_abi = true; 325 337 326 - return ret; 327 - } 338 + nvmem_cfg.priv = pdata; 339 + ret = rtc_nvmem_register(pdata->rtc, &nvmem_cfg); 340 + if (ret) 341 + return ret; 328 342 329 - static int stk17ta8_rtc_remove(struct platform_device *pdev) 330 - { 331 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 332 - 333 - sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 334 - if (pdata->irq > 0) 335 - writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 336 - return 0; 343 + return rtc_register_device(pdata->rtc); 337 344 } 338 345 339 346 /* work with hotplug and coldplug */ ··· 336 353 337 354 static struct platform_driver stk17ta8_rtc_driver = { 338 355 .probe = stk17ta8_rtc_probe, 339 - .remove = stk17ta8_rtc_remove, 340 356 .driver = { 341 357 .name = "stk17ta8", 342 358 },
+1 -1
drivers/rtc/rtc-sun6i.c
··· 349 349 */ 350 350 rtc_tm->tm_year += SUN6I_YEAR_OFF; 351 351 352 - return rtc_valid_tm(rtc_tm); 352 + return 0; 353 353 } 354 354 355 355 static int sun6i_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+1 -1
drivers/rtc/rtc-sunxi.c
··· 261 261 */ 262 262 rtc_tm->tm_year += SUNXI_YEAR_OFF(chip->data_year); 263 263 264 - return rtc_valid_tm(rtc_tm); 264 + return 0; 265 265 } 266 266 267 267 static int sunxi_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+12
drivers/rtc/rtc-sysfs.c
··· 248 248 } 249 249 static DEVICE_ATTR_RW(offset); 250 250 251 + static ssize_t 252 + range_show(struct device *dev, struct device_attribute *attr, char *buf) 253 + { 254 + return sprintf(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min, 255 + to_rtc_device(dev)->range_max); 256 + } 257 + static DEVICE_ATTR_RO(range); 258 + 251 259 static struct attribute *rtc_attrs[] = { 252 260 &dev_attr_name.attr, 253 261 &dev_attr_date.attr, ··· 265 257 &dev_attr_hctosys.attr, 266 258 &dev_attr_wakealarm.attr, 267 259 &dev_attr_offset.attr, 260 + &dev_attr_range.attr, 268 261 NULL, 269 262 }; 270 263 ··· 294 285 mode = 0; 295 286 } else if (attr == &dev_attr_offset.attr) { 296 287 if (!rtc->ops->set_offset) 288 + mode = 0; 289 + } else if (attr == &dev_attr_range.attr) { 290 + if (!(rtc->range_max - rtc->range_min)) 297 291 mode = 0; 298 292 } 299 293
-4
drivers/rtc/rtc-tegra.c
··· 144 144 int ret; 145 145 146 146 /* convert tm to seconds. */ 147 - ret = rtc_valid_tm(tm); 148 - if (ret) 149 - return ret; 150 - 151 147 rtc_tm_to_time(tm, &sec); 152 148 153 149 dev_vdbg(dev, "time set to %lu. %d/%d/%d %d:%02u:%02u\n",
+1 -1
drivers/rtc/rtc-tps6586x.c
··· 90 90 seconds = ticks >> 10; 91 91 seconds += rtc->epoch_start; 92 92 rtc_time_to_tm(seconds, tm); 93 - return rtc_valid_tm(tm); 93 + return 0; 94 94 } 95 95 96 96 static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+61 -36
drivers/rtc/rtc-tx4939.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/io.h> 16 16 #include <linux/gfp.h> 17 - #include <asm/txx9/tx4939.h> 17 + 18 + #define TX4939_RTCCTL_ALME 0x00000080 19 + #define TX4939_RTCCTL_ALMD 0x00000040 20 + #define TX4939_RTCCTL_BUSY 0x00000020 21 + 22 + #define TX4939_RTCCTL_COMMAND 0x00000007 23 + #define TX4939_RTCCTL_COMMAND_NOP 0x00000000 24 + #define TX4939_RTCCTL_COMMAND_GETTIME 0x00000001 25 + #define TX4939_RTCCTL_COMMAND_SETTIME 0x00000002 26 + #define TX4939_RTCCTL_COMMAND_GETALARM 0x00000003 27 + #define TX4939_RTCCTL_COMMAND_SETALARM 0x00000004 28 + 29 + #define TX4939_RTCTBC_PM 0x00000080 30 + #define TX4939_RTCTBC_COMP 0x0000007f 31 + 32 + #define TX4939_RTC_REG_RAMSIZE 0x00000100 33 + #define TX4939_RTC_REG_RWBSIZE 0x00000006 34 + 35 + struct tx4939_rtc_reg { 36 + __u32 ctl; 37 + __u32 adr; 38 + __u32 dat; 39 + __u32 tbc; 40 + }; 18 41 19 42 struct tx4939rtc_plat_data { 20 43 struct rtc_device *rtc; ··· 109 86 for (i = 2; i < 6; i++) 110 87 buf[i] = __raw_readl(&rtcreg->dat); 111 88 spin_unlock_irq(&pdata->lock); 112 - sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; 89 + sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | 90 + (buf[3] << 8) | buf[2]; 113 91 rtc_time_to_tm(sec, tm); 114 - return rtc_valid_tm(tm); 92 + return 0; 115 93 } 116 94 117 95 static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ··· 171 147 alrm->enabled = (ctl & TX4939_RTCCTL_ALME) ? 1 : 0; 172 148 alrm->pending = (ctl & TX4939_RTCCTL_ALMD) ? 1 : 0; 173 149 spin_unlock_irq(&pdata->lock); 174 - sec = (buf[5] << 24) | (buf[4] << 16) | (buf[3] << 8) | buf[2]; 150 + sec = ((unsigned long)buf[5] << 24) | (buf[4] << 16) | 151 + (buf[3] << 8) | buf[2]; 175 152 rtc_time_to_tm(sec, &alrm->time); 176 153 return rtc_valid_tm(&alrm->time); 177 154 } ··· 214 189 .alarm_irq_enable = tx4939_rtc_alarm_irq_enable, 215 190 }; 216 191 217 - static ssize_t tx4939_rtc_nvram_read(struct file *filp, struct kobject *kobj, 218 - struct bin_attribute *bin_attr, 219 - char *buf, loff_t pos, size_t size) 192 + static int tx4939_nvram_read(void *priv, unsigned int pos, void *val, 193 + size_t bytes) 220 194 { 221 - struct device *dev = container_of(kobj, struct device, kobj); 222 - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 195 + struct tx4939rtc_plat_data *pdata = priv; 223 196 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 224 - ssize_t count; 197 + u8 *buf = val; 225 198 226 199 spin_lock_irq(&pdata->lock); 227 - for (count = 0; count < size; count++) { 200 + for (; bytes; bytes--) { 228 201 __raw_writel(pos++, &rtcreg->adr); 229 202 *buf++ = __raw_readl(&rtcreg->dat); 230 203 } 231 204 spin_unlock_irq(&pdata->lock); 232 - return count; 205 + return 0; 233 206 } 234 207 235 - static ssize_t tx4939_rtc_nvram_write(struct file *filp, struct kobject *kobj, 236 - struct bin_attribute *bin_attr, 237 - char *buf, loff_t pos, size_t size) 208 + static int tx4939_nvram_write(void *priv, unsigned int pos, void *val, 209 + size_t bytes) 238 210 { 239 - struct device *dev = container_of(kobj, struct device, kobj); 240 - struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); 211 + struct tx4939rtc_plat_data *pdata = priv; 241 212 struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; 242 - ssize_t count; 213 + u8 *buf = val; 243 214 244 215 spin_lock_irq(&pdata->lock); 245 - for (count = 0; count < size; count++) { 216 + for (; bytes; bytes--) { 246 217 __raw_writel(pos++, &rtcreg->adr); 247 218 __raw_writel(*buf++, &rtcreg->dat); 248 219 } 249 220 spin_unlock_irq(&pdata->lock); 250 - return count; 221 + return 0; 251 222 } 252 - 253 - static struct bin_attribute tx4939_rtc_nvram_attr = { 254 - .attr = { 255 - .name = "nvram", 256 - .mode = S_IRUGO | S_IWUSR, 257 - }, 258 - .size = TX4939_RTC_REG_RAMSIZE, 259 - .read = tx4939_rtc_nvram_read, 260 - .write = tx4939_rtc_nvram_write, 261 - }; 262 223 263 224 static int __init tx4939_rtc_probe(struct platform_device *pdev) 264 225 { ··· 252 241 struct tx4939rtc_plat_data *pdata; 253 242 struct resource *res; 254 243 int irq, ret; 244 + struct nvmem_config nvmem_cfg = { 245 + .name = "rv8803_nvram", 246 + .word_size = 4, 247 + .stride = 4, 248 + .size = TX4939_RTC_REG_RAMSIZE, 249 + .reg_read = tx4939_nvram_read, 250 + .reg_write = tx4939_nvram_write, 251 + }; 255 252 256 253 irq = platform_get_irq(pdev, 0); 257 254 if (irq < 0) ··· 279 260 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, 280 261 0, pdev->name, &pdev->dev) < 0) 281 262 return -EBUSY; 282 - rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 283 - &tx4939_rtc_ops, THIS_MODULE); 263 + rtc = devm_rtc_allocate_device(&pdev->dev); 284 264 if (IS_ERR(rtc)) 285 265 return PTR_ERR(rtc); 286 - pdata->rtc = rtc; 287 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 288 266 289 - return ret; 267 + rtc->ops = &tx4939_rtc_ops; 268 + rtc->nvram_old_abi = true; 269 + 270 + pdata->rtc = rtc; 271 + 272 + nvmem_cfg.priv = pdata; 273 + ret = rtc_nvmem_register(rtc, &nvmem_cfg); 274 + if (ret) 275 + return ret; 276 + 277 + return rtc_register_device(rtc); 290 278 } 291 279 292 280 static int __exit tx4939_rtc_remove(struct platform_device *pdev) 293 281 { 294 282 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); 295 283 296 - sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 297 284 spin_lock_irq(&pdata->lock); 298 285 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); 299 286 spin_unlock_irq(&pdata->lock);
+1 -1
drivers/rtc/rtc-wm831x.c
··· 156 156 u32 time = (time1[0] << 16) | time1[1]; 157 157 158 158 rtc_time_to_tm(time, tm); 159 - return rtc_valid_tm(tm); 159 + return 0; 160 160 } 161 161 162 162 } while (++count < WM831X_GET_TIME_RETRIES);
+1 -1
drivers/rtc/rtc-xgene.c
··· 60 60 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 61 61 62 62 rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm); 63 - return rtc_valid_tm(tm); 63 + return 0; 64 64 } 65 65 66 66 static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs)
+1 -1
drivers/rtc/rtc-zynqmp.c
··· 122 122 rtc_time64_to_tm(read_time, tm); 123 123 } 124 124 125 - return rtc_valid_tm(tm); 125 + return 0; 126 126 } 127 127 128 128 static int xlnx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+1 -1
drivers/rtc/systohc.c
··· 20 20 * cases. 21 21 * 22 22 * -EPROTO is returned if now.tv_nsec is not close enough to *target_nsec. 23 - ( 23 + * 24 24 * If temporary failure is indicated the caller should try again 'soon' 25 25 */ 26 26 int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec)
-11
include/linux/mfd/samsung/rtc.h
··· 141 141 #define WTSR_ENABLE_SHIFT 6 142 142 #define WTSR_ENABLE_MASK (1 << WTSR_ENABLE_SHIFT) 143 143 144 - enum { 145 - RTC_SEC = 0, 146 - RTC_MIN, 147 - RTC_HOUR, 148 - RTC_WEEKDAY, 149 - RTC_DATE, 150 - RTC_MONTH, 151 - RTC_YEAR1, 152 - RTC_YEAR2, 153 - }; 154 - 155 144 #endif /* __LINUX_MFD_SEC_RTC_H */
+24 -5
include/linux/rtc.h
··· 145 145 146 146 bool registered; 147 147 148 - struct nvmem_config *nvmem_config; 149 148 struct nvmem_device *nvmem; 150 149 /* Old ABI support */ 151 150 bool nvram_old_abi; 152 151 struct bin_attribute *nvram; 152 + 153 + time64_t range_min; 154 + timeu64_t range_max; 155 + time64_t start_secs; 156 + time64_t offset_secs; 157 + bool set_start_time; 153 158 154 159 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 155 160 struct work_struct uie_task; ··· 168 163 #endif 169 164 }; 170 165 #define to_rtc_device(d) container_of(d, struct rtc_device, dev) 166 + 167 + /* useful timestamps */ 168 + #define RTC_TIMESTAMP_BEGIN_1900 -2208989361LL /* 1900-01-01 00:00:00 */ 169 + #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */ 170 + #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */ 171 171 172 172 extern struct rtc_device *rtc_device_register(const char *name, 173 173 struct device *dev, ··· 221 211 void rtc_aie_update_irq(void *private); 222 212 void rtc_uie_update_irq(void *private); 223 213 enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer); 224 - 225 - int rtc_register(rtc_task_t *task); 226 - int rtc_unregister(rtc_task_t *task); 227 - int rtc_control(rtc_task_t *t, unsigned int cmd, unsigned long arg); 228 214 229 215 void rtc_timer_init(struct rtc_timer *timer, void (*f)(void *p), void *data); 230 216 int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, ··· 275 269 extern int rtc_hctosys_ret; 276 270 #else 277 271 #define rtc_hctosys_ret -ENODEV 272 + #endif 273 + 274 + #ifdef CONFIG_RTC_NVMEM 275 + int rtc_nvmem_register(struct rtc_device *rtc, 276 + struct nvmem_config *nvmem_config); 277 + void rtc_nvmem_unregister(struct rtc_device *rtc); 278 + #else 279 + static inline int rtc_nvmem_register(struct rtc_device *rtc, 280 + struct nvmem_config *nvmem_config) 281 + { 282 + return -ENODEV; 283 + } 284 + static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} 278 285 #endif 279 286 280 287 #endif /* _LINUX_RTC_H_ */
+206
include/trace/events/rtc.h
··· 1 + #undef TRACE_SYSTEM 2 + #define TRACE_SYSTEM rtc 3 + 4 + #if !defined(_TRACE_RTC_H) || defined(TRACE_HEADER_MULTI_READ) 5 + #define _TRACE_RTC_H 6 + 7 + #include <linux/rtc.h> 8 + #include <linux/tracepoint.h> 9 + 10 + DECLARE_EVENT_CLASS(rtc_time_alarm_class, 11 + 12 + TP_PROTO(time64_t secs, int err), 13 + 14 + TP_ARGS(secs, err), 15 + 16 + TP_STRUCT__entry( 17 + __field(time64_t, secs) 18 + __field(int, err) 19 + ), 20 + 21 + TP_fast_assign( 22 + __entry->secs = secs; 23 + __entry->err = err; 24 + ), 25 + 26 + TP_printk("UTC (%lld) (%d)", 27 + __entry->secs, __entry->err 28 + ) 29 + ); 30 + 31 + DEFINE_EVENT(rtc_time_alarm_class, rtc_set_time, 32 + 33 + TP_PROTO(time64_t secs, int err), 34 + 35 + TP_ARGS(secs, err) 36 + ); 37 + 38 + DEFINE_EVENT(rtc_time_alarm_class, rtc_read_time, 39 + 40 + TP_PROTO(time64_t secs, int err), 41 + 42 + TP_ARGS(secs, err) 43 + ); 44 + 45 + DEFINE_EVENT(rtc_time_alarm_class, rtc_set_alarm, 46 + 47 + TP_PROTO(time64_t secs, int err), 48 + 49 + TP_ARGS(secs, err) 50 + ); 51 + 52 + DEFINE_EVENT(rtc_time_alarm_class, rtc_read_alarm, 53 + 54 + TP_PROTO(time64_t secs, int err), 55 + 56 + TP_ARGS(secs, err) 57 + ); 58 + 59 + TRACE_EVENT(rtc_irq_set_freq, 60 + 61 + TP_PROTO(int freq, int err), 62 + 63 + TP_ARGS(freq, err), 64 + 65 + TP_STRUCT__entry( 66 + __field(int, freq) 67 + __field(int, err) 68 + ), 69 + 70 + TP_fast_assign( 71 + __entry->freq = freq; 72 + __entry->err = err; 73 + ), 74 + 75 + TP_printk("set RTC periodic IRQ frequency:%u (%d)", 76 + __entry->freq, __entry->err 77 + ) 78 + ); 79 + 80 + TRACE_EVENT(rtc_irq_set_state, 81 + 82 + TP_PROTO(int enabled, int err), 83 + 84 + TP_ARGS(enabled, err), 85 + 86 + TP_STRUCT__entry( 87 + __field(int, enabled) 88 + __field(int, err) 89 + ), 90 + 91 + TP_fast_assign( 92 + __entry->enabled = enabled; 93 + __entry->err = err; 94 + ), 95 + 96 + TP_printk("%s RTC 2^N Hz periodic IRQs (%d)", 97 + __entry->enabled ? "enable" : "disable", 98 + __entry->err 99 + ) 100 + ); 101 + 102 + TRACE_EVENT(rtc_alarm_irq_enable, 103 + 104 + TP_PROTO(unsigned int enabled, int err), 105 + 106 + TP_ARGS(enabled, err), 107 + 108 + TP_STRUCT__entry( 109 + __field(unsigned int, enabled) 110 + __field(int, err) 111 + ), 112 + 113 + TP_fast_assign( 114 + __entry->enabled = enabled; 115 + __entry->err = err; 116 + ), 117 + 118 + TP_printk("%s RTC alarm IRQ (%d)", 119 + __entry->enabled ? "enable" : "disable", 120 + __entry->err 121 + ) 122 + ); 123 + 124 + DECLARE_EVENT_CLASS(rtc_offset_class, 125 + 126 + TP_PROTO(long offset, int err), 127 + 128 + TP_ARGS(offset, err), 129 + 130 + TP_STRUCT__entry( 131 + __field(long, offset) 132 + __field(int, err) 133 + ), 134 + 135 + TP_fast_assign( 136 + __entry->offset = offset; 137 + __entry->err = err; 138 + ), 139 + 140 + TP_printk("RTC offset: %ld (%d)", 141 + __entry->offset, __entry->err 142 + ) 143 + ); 144 + 145 + DEFINE_EVENT(rtc_offset_class, rtc_set_offset, 146 + 147 + TP_PROTO(long offset, int err), 148 + 149 + TP_ARGS(offset, err) 150 + ); 151 + 152 + DEFINE_EVENT(rtc_offset_class, rtc_read_offset, 153 + 154 + TP_PROTO(long offset, int err), 155 + 156 + TP_ARGS(offset, err) 157 + ); 158 + 159 + DECLARE_EVENT_CLASS(rtc_timer_class, 160 + 161 + TP_PROTO(struct rtc_timer *timer), 162 + 163 + TP_ARGS(timer), 164 + 165 + TP_STRUCT__entry( 166 + __field(struct rtc_timer *, timer) 167 + __field(ktime_t, expires) 168 + __field(ktime_t, period) 169 + ), 170 + 171 + TP_fast_assign( 172 + __entry->timer = timer; 173 + __entry->expires = timer->node.expires; 174 + __entry->period = timer->period; 175 + ), 176 + 177 + TP_printk("RTC timer:(%p) expires:%lld period:%lld", 178 + __entry->timer, __entry->expires, __entry->period 179 + ) 180 + ); 181 + 182 + DEFINE_EVENT(rtc_timer_class, rtc_timer_enqueue, 183 + 184 + TP_PROTO(struct rtc_timer *timer), 185 + 186 + TP_ARGS(timer) 187 + ); 188 + 189 + DEFINE_EVENT(rtc_timer_class, rtc_timer_dequeue, 190 + 191 + TP_PROTO(struct rtc_timer *timer), 192 + 193 + TP_ARGS(timer) 194 + ); 195 + 196 + DEFINE_EVENT(rtc_timer_class, rtc_timer_fired, 197 + 198 + TP_PROTO(struct rtc_timer *timer), 199 + 200 + TP_ARGS(timer) 201 + ); 202 + 203 + #endif /* _TRACE_RTC_H */ 204 + 205 + /* This part must be outside protection */ 206 + #include <trace/define_trace.h>