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

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

Pull RTC updates from Alexandre Belloni:
"Here is the pull-request for the RTC subsystem for 4.13.

Subsystem:

- expose non volatile RAM using nvmem instead of open coding in many
drivers. Unfortunately, this option has to be enabled by default to
not break existing users.

- rtctest can now test for cutoff dates, showing when an RTC will
start failing to properly save time and date.

- new RTC registration functions to remove race conditions in drivers

Newly supported RTCs:

- Broadcom STB wake-timer

- Epson RX8130CE

- Maxim IC DS1308

- STMicroelectronics STM32H7

Drivers:

- ds1307: use regmap, use nvmem, more cleanups

- ds3232: temperature reading support

- gemini: renamed to ftrtc010

- m41t80: use CCF to expose the clock

- rv8803: use nvmem

- s3c: many cleanups

- st-lpc: fix y2106 bug"

* tag 'rtc-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (51 commits)
rtc: Remove wrong deprecation comment
nvmem: include linux/err.h from header
rtc: st-lpc: make it robust against y2038/2106 bug
rtc: rtctest: add check for problematic dates
tools: timer: add rtctest_setdate
rtc: ds1307: remove ds1307_remove
rtc: ds1307: use generic nvmem
rtc: ds1307: switch to rtc_register_device
rtc: rv8803: remove rv8803_remove
rtc: rv8803: use generic nvmem support
rtc: rv8803: switch to rtc_register_device
rtc: add generic nvmem support
rtc: at91rm9200: remove race condition
rtc: introduce new registration method
rtc: class separate id allocation from registration
rtc: class separate device allocation from registration
rtc: stm32: add STM32H7 RTC support
dt-bindings: rtc: stm32: add support for STM32H7
rtc: ds1307: add ds1308 variant
rtc: ds3232: add temperature support
...

+2040 -905
+22
Documentation/devicetree/bindings/rtc/brcm,brcmstb-waketimer.txt
··· 1 + Broadcom STB wake-up Timer 2 + 3 + The Broadcom STB wake-up timer provides a 27Mhz resolution timer, with the 4 + ability to wake up the system from low-power suspend/standby modes. 5 + 6 + Required properties: 7 + - compatible : should contain "brcm,brcmstb-waketimer" 8 + - reg : the register start and length for the WKTMR block 9 + - interrupts : The TIMER interrupt 10 + - interrupt-parent: The phandle to the Always-On (AON) Power Management (PM) L2 11 + interrupt controller node 12 + - clocks : The phandle to the UPG fixed clock (27Mhz domain) 13 + 14 + Example: 15 + 16 + waketimer@f0411580 { 17 + compatible = "brcm,brcmstb-waketimer"; 18 + reg = <0xf0411580 0x14>; 19 + interrupts = <0x3>; 20 + interrupt-parent = <&aon_pm_l2_intc>; 21 + clocks = <&upg_fixed>; 22 + };
-14
Documentation/devicetree/bindings/rtc/cortina,gemini.txt
··· 1 - * Cortina Systems Gemini RTC 2 - 3 - Gemini SoC real-time clock. 4 - 5 - Required properties: 6 - - compatible : Should be "cortina,gemini-rtc" 7 - 8 - Examples: 9 - 10 - rtc@45000000 { 11 - compatible = "cortina,gemini-rtc"; 12 - reg = <0x45000000 0x100>; 13 - interrupts = <17 IRQ_TYPE_LEVEL_HIGH>; 14 - };
+28
Documentation/devicetree/bindings/rtc/faraday,ftrtc010.txt
··· 1 + * Faraday Technology FTRTC010 Real Time Clock 2 + 3 + This RTC appears in for example the Storlink Gemini family of 4 + SoCs. 5 + 6 + Required properties: 7 + - compatible : Should be one of: 8 + "faraday,ftrtc010" 9 + "cortina,gemini-rtc", "faraday,ftrtc010" 10 + 11 + Optional properties: 12 + - clocks: when present should contain clock references to the 13 + PCLK and EXTCLK clocks. Faraday calls the later CLK1HZ and 14 + says the clock should be 1 Hz, but implementers actually seem 15 + to choose different clocks here, like Cortina who chose 16 + 32768 Hz (a typical low-power clock). 17 + - clock-names: should name the clocks "PCLK" and "EXTCLK" 18 + respectively. 19 + 20 + Examples: 21 + 22 + rtc@45000000 { 23 + compatible = "cortina,gemini-rtc"; 24 + reg = <0x45000000 0x100>; 25 + interrupts = <17 IRQ_TYPE_LEVEL_HIGH>; 26 + clocks = <&foo 0>, <&foo 1>; 27 + clock-names = "PCLK", "EXTCLK"; 28 + };
+27 -5
Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt
··· 1 1 STM32 Real Time Clock 2 2 3 3 Required properties: 4 - - compatible: "st,stm32-rtc". 4 + - compatible: can be either "st,stm32-rtc" or "st,stm32h7-rtc", depending on 5 + the device is compatible with stm32(f4/f7) or stm32h7. 5 6 - reg: address range of rtc register set. 6 - - clocks: reference to the clock entry ck_rtc. 7 + - clocks: can use up to two clocks, depending on part used: 8 + - "rtc_ck": RTC clock source. 9 + It is required on stm32(f4/f7) and stm32h7. 10 + - "pclk": RTC APB interface clock. 11 + It is not present on stm32(f4/f7). 12 + It is required on stm32h7. 13 + - clock-names: must be "rtc_ck" and "pclk". 14 + It is required only on stm32h7. 7 15 - interrupt-parent: phandle for the interrupt controller. 8 16 - interrupts: rtc alarm interrupt. 9 17 - st,syscfg: phandle for pwrcfg, mandatory to disable/enable backup domain 10 18 (RTC registers) write protection. 11 19 12 - Optional properties (to override default ck_rtc parent clock): 13 - - assigned-clocks: reference to the ck_rtc clock entry. 14 - - assigned-clock-parents: phandle of the new parent clock of ck_rtc. 20 + Optional properties (to override default rtc_ck parent clock): 21 + - assigned-clocks: reference to the rtc_ck clock entry. 22 + - assigned-clock-parents: phandle of the new parent clock of rtc_ck. 15 23 16 24 Example: 17 25 ··· 32 24 interrupt-parent = <&exti>; 33 25 interrupts = <17 1>; 34 26 st,syscfg = <&pwrcfg>; 27 + }; 28 + 29 + rtc: rtc@58004000 { 30 + compatible = "st,stm32h7-rtc"; 31 + reg = <0x58004000 0x400>; 32 + clocks = <&rcc RTCAPB_CK>, <&rcc RTC_CK>; 33 + clock-names = "pclk", "rtc_ck"; 34 + assigned-clocks = <&rcc RTC_CK>; 35 + assigned-clock-parents = <&rcc LSE_CK>; 36 + interrupt-parent = <&exti>; 37 + interrupts = <17 1>; 38 + interrupt-names = "alarm"; 39 + st,syscfg = <&pwrcfg>; 40 + status = "disabled"; 35 41 };
+25 -21
Documentation/rtc.txt
··· 1 - 2 - Real Time Clock (RTC) Drivers for Linux 3 - ======================================= 1 + ======================================= 2 + Real Time Clock (RTC) Drivers for Linux 3 + ======================================= 4 4 5 5 When Linux developers talk about a "Real Time Clock", they usually mean 6 6 something that tracks wall clock time and is battery backed so that it ··· 32 32 be able to schedule one any time in the upcoming century. 33 33 34 34 35 - Old PC/AT-Compatible driver: /dev/rtc 36 - -------------------------------------- 35 + Old PC/AT-Compatible driver: /dev/rtc 36 + -------------------------------------- 37 37 38 38 All PCs (even Alpha machines) have a Real Time Clock built into them. 39 39 Usually they are built into the chipset of the computer, but some may ··· 105 105 (The original /dev/rtc driver was written by Paul Gortmaker.) 106 106 107 107 108 - New portable "RTC Class" drivers: /dev/rtcN 109 - -------------------------------------------- 108 + New portable "RTC Class" drivers: /dev/rtcN 109 + -------------------------------------------- 110 110 111 111 Because Linux supports many non-ACPI and non-PC platforms, some of which 112 112 have more than one RTC style clock, it needed a more portable solution ··· 136 136 the system clock from the discrete RTC, but use the integrated one for all 137 137 other tasks, because of its greater functionality. 138 138 139 - SYSFS INTERFACE 139 + SYSFS interface 140 140 --------------- 141 141 142 142 The sysfs interface under /sys/class/rtc/rtcN provides access to various 143 143 rtc attributes without requiring the use of ioctls. All dates and times 144 144 are in the RTC's timezone, rather than in system time. 145 145 146 - date: RTC-provided date 147 - hctosys: 1 if the RTC provided the system time at boot via the 146 + ================ ============================================================== 147 + date RTC-provided date 148 + hctosys 1 if the RTC provided the system time at boot via the 148 149 CONFIG_RTC_HCTOSYS kernel option, 0 otherwise 149 - max_user_freq: The maximum interrupt rate an unprivileged user may request 150 + max_user_freq The maximum interrupt rate an unprivileged user may request 150 151 from this RTC. 151 - name: The name of the RTC corresponding to this sysfs directory 152 - since_epoch: The number of seconds since the epoch according to the RTC 153 - time: RTC-provided time 154 - wakealarm: The time at which the clock will generate a system wakeup 152 + name The name of the RTC corresponding to this sysfs directory 153 + since_epoch The number of seconds since the epoch according to the RTC 154 + time RTC-provided time 155 + wakealarm The time at which the clock will generate a system wakeup 155 156 event. This is a one shot wakeup event, so must be reset 156 - after wake if a daily wakeup is required. Format is seconds since 157 - the epoch by default, or if there's a leading +, seconds in the 158 - future, or if there is a leading +=, seconds ahead of the current 159 - alarm. 160 - offset: The amount which the rtc clock has been adjusted in firmware. 157 + after wake if a daily wakeup is required. Format is seconds 158 + since the epoch by default, or if there's a leading +, seconds 159 + in the future, or if there is a leading +=, seconds ahead of 160 + the current alarm. 161 + offset The amount which the rtc clock has been adjusted in firmware. 161 162 Visible only if the driver supports clock offset adjustment. 162 163 The unit is parts per billion, i.e. The number of clock ticks 163 164 which are added to or removed from the rtc's base clock per 164 165 billion ticks. A positive value makes a day pass more slowly, 165 166 longer, and a negative value makes a day pass more quickly. 167 + */nvmem The non volatile storage exported as a raw file, as described 168 + in Documentation/nvmem/nvmem.txt 169 + ================ ============================================================== 166 170 167 - IOCTL INTERFACE 171 + IOCTL interface 168 172 --------------- 169 173 170 174 The ioctl() calls supported by /dev/rtc are also supported by the RTC class
+1 -1
MAINTAINERS
··· 1255 1255 T: git git://github.com/ulli-kroll/linux.git 1256 1256 S: Maintained 1257 1257 F: arch/arm/mach-gemini/ 1258 - F: drivers/rtc/rtc-gemini.c 1258 + F: drivers/rtc/rtc-ftrtc010.c 1259 1259 1260 1260 ARM/CSR SIRFPRIMA2 MACHINE SUPPORT 1261 1261 M: Barry Song <baohua@kernel.org>
+32 -5
drivers/rtc/Kconfig
··· 77 77 Say yes here to enable debugging support in the RTC framework 78 78 and individual RTC drivers. 79 79 80 + config RTC_NVMEM 81 + bool "RTC non volatile storage support" 82 + select NVMEM 83 + default RTC_CLASS 84 + help 85 + Say yes here to add support for the non volatile (often battery 86 + backed) storage present on RTCs. 87 + 80 88 comment "RTC interfaces" 81 89 82 90 config RTC_INTF_SYSFS ··· 204 196 205 197 This driver can also be built as a module. If so, the module 206 198 will be called rtc-ac100. 199 + 200 + config RTC_DRV_BRCMSTB 201 + tristate "Broadcom STB wake-timer" 202 + depends on ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST 203 + default ARCH_BRCMSTB || BMIPS_GENERIC 204 + help 205 + If you say yes here you get support for the wake-timer found on 206 + Broadcom STB SoCs (BCM7xxx). 207 + 208 + This driver can also be built as a module. If so, the module will 209 + be called rtc-brcmstb-waketimer. 207 210 208 211 config RTC_DRV_AS3722 209 212 tristate "ams AS3722 RTC driver" ··· 809 790 810 791 This driver can also be built as a module. If so, the module 811 792 will be called rtc-ds3232. 793 + 794 + config RTC_DRV_DS3232_HWMON 795 + bool "HWMON support for Dallas/Maxim DS3232/DS3234" 796 + depends on RTC_DRV_DS3232 && HWMON && !(RTC_DRV_DS3232=y && HWMON=m) 797 + default y 798 + help 799 + Say Y here if you want to expose temperature sensor data on 800 + rtc-ds3232 812 801 813 802 config RTC_DRV_PCF2127 814 803 tristate "NXP PCF2127" ··· 1511 1484 This driver can also be built as a module. If so, the module 1512 1485 will be called armada38x-rtc. 1513 1486 1514 - config RTC_DRV_GEMINI 1515 - tristate "Gemini SoC RTC" 1516 - depends on ARCH_GEMINI || COMPILE_TEST 1487 + config RTC_DRV_FTRTC010 1488 + tristate "Faraday Technology FTRTC010 RTC" 1517 1489 depends on HAS_IOMEM 1490 + default ARCH_GEMINI 1518 1491 help 1519 1492 If you say Y here you will get support for the 1520 - RTC found on Gemini SoC's. 1493 + Faraday Technolog FTRTC010 found on e.g. Gemini SoC's. 1521 1494 1522 1495 This driver can also be built as a module. If so, the module 1523 - will be called rtc-gemini. 1496 + will be called rtc-ftrtc010. 1524 1497 1525 1498 config RTC_DRV_PS3 1526 1499 tristate "PS3 RTC"
+3 -1
drivers/rtc/Makefile
··· 15 15 rtc-core-y += rtc-efi-platform.o 16 16 endif 17 17 18 + rtc-core-$(CONFIG_RTC_NVMEM) += nvmem.o 18 19 rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 19 20 rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 20 21 rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o ··· 37 36 obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o 38 37 obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o 39 38 obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o 39 + obj-$(CONFIG_RTC_DRV_BRCMSTB) += rtc-brcmstb-waketimer.o 40 40 obj-$(CONFIG_RTC_DRV_BQ32K) += rtc-bq32k.o 41 41 obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o 42 42 obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o ··· 69 67 obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o 70 68 obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 71 69 obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 72 - obj-$(CONFIG_RTC_DRV_GEMINI) += rtc-gemini.o 70 + obj-$(CONFIG_RTC_DRV_FTRTC010) += rtc-ftrtc010.o 73 71 obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 74 72 obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o 75 73 obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o
+153 -49
drivers/rtc/class.c
··· 150 150 #define RTC_CLASS_DEV_PM_OPS NULL 151 151 #endif 152 152 153 - 154 - /** 155 - * rtc_device_register - register w/ RTC class 156 - * @dev: the device to register 157 - * 158 - * rtc_device_unregister() must be called when the class device is no 159 - * longer needed. 160 - * 161 - * Returns the pointer to the new struct class device. 162 - */ 163 - struct rtc_device *rtc_device_register(const char *name, struct device *dev, 164 - const struct rtc_class_ops *ops, 165 - struct module *owner) 153 + /* Ensure the caller will set the id before releasing the device */ 154 + static struct rtc_device *rtc_allocate_device(void) 166 155 { 167 156 struct rtc_device *rtc; 168 - struct rtc_wkalrm alrm; 169 - int of_id = -1, id = -1, err; 170 157 171 - if (dev->of_node) 172 - of_id = of_alias_get_id(dev->of_node, "rtc"); 173 - else if (dev->parent && dev->parent->of_node) 174 - of_id = of_alias_get_id(dev->parent->of_node, "rtc"); 175 - 176 - if (of_id >= 0) { 177 - id = ida_simple_get(&rtc_ida, of_id, of_id + 1, 178 - GFP_KERNEL); 179 - if (id < 0) 180 - dev_warn(dev, "/aliases ID %d not available\n", 181 - of_id); 182 - } 183 - 184 - if (id < 0) { 185 - id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); 186 - if (id < 0) { 187 - err = id; 188 - goto exit; 189 - } 190 - } 191 - 192 - rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL); 193 - if (rtc == NULL) { 194 - err = -ENOMEM; 195 - goto exit_ida; 196 - } 158 + rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 159 + if (!rtc) 160 + return NULL; 197 161 198 162 device_initialize(&rtc->dev); 199 163 200 - rtc->id = id; 201 - rtc->ops = ops; 202 - rtc->owner = owner; 203 164 rtc->irq_freq = 1; 204 165 rtc->max_user_freq = 64; 205 - rtc->dev.parent = dev; 206 166 rtc->dev.class = rtc_class; 207 167 rtc->dev.groups = rtc_get_dev_attribute_groups(); 208 168 rtc->dev.release = rtc_device_release; ··· 184 224 rtc->pie_timer.function = rtc_pie_update_irq; 185 225 rtc->pie_enabled = 0; 186 226 187 - strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); 227 + return rtc; 228 + } 229 + 230 + static int rtc_device_get_id(struct device *dev) 231 + { 232 + int of_id = -1, id = -1; 233 + 234 + if (dev->of_node) 235 + of_id = of_alias_get_id(dev->of_node, "rtc"); 236 + else if (dev->parent && dev->parent->of_node) 237 + of_id = of_alias_get_id(dev->parent->of_node, "rtc"); 238 + 239 + if (of_id >= 0) { 240 + id = ida_simple_get(&rtc_ida, of_id, of_id + 1, GFP_KERNEL); 241 + if (id < 0) 242 + dev_warn(dev, "/aliases ID %d not available\n", of_id); 243 + } 244 + 245 + if (id < 0) 246 + id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); 247 + 248 + return id; 249 + } 250 + 251 + /** 252 + * rtc_device_register - register w/ RTC class 253 + * @dev: the device to register 254 + * 255 + * rtc_device_unregister() must be called when the class device is no 256 + * longer needed. 257 + * 258 + * Returns the pointer to the new struct class device. 259 + */ 260 + struct rtc_device *rtc_device_register(const char *name, struct device *dev, 261 + const struct rtc_class_ops *ops, 262 + struct module *owner) 263 + { 264 + struct rtc_device *rtc; 265 + struct rtc_wkalrm alrm; 266 + int id, err; 267 + 268 + id = rtc_device_get_id(dev); 269 + if (id < 0) { 270 + err = id; 271 + goto exit; 272 + } 273 + 274 + rtc = rtc_allocate_device(); 275 + if (!rtc) { 276 + err = -ENOMEM; 277 + goto exit_ida; 278 + } 279 + 280 + rtc->id = id; 281 + rtc->ops = ops; 282 + rtc->owner = owner; 283 + rtc->dev.parent = dev; 284 + 188 285 dev_set_name(&rtc->dev, "rtc%d", id); 189 286 190 287 /* Check to see if there is an ALARM already set in hw */ ··· 255 238 err = cdev_device_add(&rtc->char_dev, &rtc->dev); 256 239 if (err) { 257 240 dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", 258 - rtc->name, MAJOR(rtc->dev.devt), rtc->id); 241 + name, MAJOR(rtc->dev.devt), rtc->id); 259 242 260 243 /* This will free both memory and the ID */ 261 244 put_device(&rtc->dev); 262 245 goto exit; 263 246 } else { 264 - dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, 247 + dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", name, 265 248 MAJOR(rtc->dev.devt), rtc->id); 266 249 } 267 250 268 251 rtc_proc_add_device(rtc); 269 252 270 253 dev_info(dev, "rtc core: registered %s as %s\n", 271 - rtc->name, dev_name(&rtc->dev)); 254 + name, dev_name(&rtc->dev)); 272 255 273 256 return rtc; 274 257 ··· 290 273 */ 291 274 void rtc_device_unregister(struct rtc_device *rtc) 292 275 { 276 + rtc_nvmem_unregister(rtc); 277 + 293 278 mutex_lock(&rtc->ops_lock); 294 279 /* 295 280 * Remove innards of this RTC, then disable it, before ··· 374 355 WARN_ON(rc); 375 356 } 376 357 EXPORT_SYMBOL_GPL(devm_rtc_device_unregister); 358 + 359 + static void devm_rtc_release_device(struct device *dev, void *res) 360 + { 361 + struct rtc_device *rtc = *(struct rtc_device **)res; 362 + 363 + if (rtc->registered) 364 + rtc_device_unregister(rtc); 365 + else 366 + put_device(&rtc->dev); 367 + } 368 + 369 + struct rtc_device *devm_rtc_allocate_device(struct device *dev) 370 + { 371 + struct rtc_device **ptr, *rtc; 372 + int id, err; 373 + 374 + id = rtc_device_get_id(dev); 375 + if (id < 0) 376 + return ERR_PTR(id); 377 + 378 + ptr = devres_alloc(devm_rtc_release_device, sizeof(*ptr), GFP_KERNEL); 379 + if (!ptr) { 380 + err = -ENOMEM; 381 + goto exit_ida; 382 + } 383 + 384 + rtc = rtc_allocate_device(); 385 + if (!rtc) { 386 + err = -ENOMEM; 387 + goto exit_devres; 388 + } 389 + 390 + *ptr = rtc; 391 + devres_add(dev, ptr); 392 + 393 + rtc->id = id; 394 + rtc->dev.parent = dev; 395 + dev_set_name(&rtc->dev, "rtc%d", id); 396 + 397 + return rtc; 398 + 399 + exit_devres: 400 + devres_free(ptr); 401 + exit_ida: 402 + ida_simple_remove(&rtc_ida, id); 403 + return ERR_PTR(err); 404 + } 405 + EXPORT_SYMBOL_GPL(devm_rtc_allocate_device); 406 + 407 + int __rtc_register_device(struct module *owner, struct rtc_device *rtc) 408 + { 409 + struct rtc_wkalrm alrm; 410 + int err; 411 + 412 + if (!rtc->ops) 413 + return -EINVAL; 414 + 415 + rtc->owner = owner; 416 + 417 + /* Check to see if there is an ALARM already set in hw */ 418 + err = __rtc_read_alarm(rtc, &alrm); 419 + if (!err && !rtc_valid_tm(&alrm.time)) 420 + rtc_initialize_alarm(rtc, &alrm); 421 + 422 + rtc_dev_prepare(rtc); 423 + 424 + err = cdev_device_add(&rtc->char_dev, &rtc->dev); 425 + if (err) 426 + dev_warn(rtc->dev.parent, "failed to add char device %d:%d\n", 427 + MAJOR(rtc->dev.devt), rtc->id); 428 + else 429 + dev_dbg(rtc->dev.parent, "char device (%d:%d)\n", 430 + MAJOR(rtc->dev.devt), rtc->id); 431 + 432 + rtc_proc_add_device(rtc); 433 + 434 + rtc_nvmem_register(rtc); 435 + 436 + rtc->registered = true; 437 + dev_info(rtc->dev.parent, "registered as %s\n", 438 + dev_name(&rtc->dev)); 439 + 440 + return 0; 441 + } 442 + EXPORT_SYMBOL_GPL(__rtc_register_device); 377 443 378 444 static int __init rtc_init(void) 379 445 {
+8 -1
drivers/rtc/interface.c
··· 227 227 missing = year; 228 228 } 229 229 230 + /* Can't proceed if alarm is still invalid after replacing 231 + * missing fields. 232 + */ 233 + err = rtc_valid_tm(&alarm->time); 234 + if (err) 235 + goto done; 236 + 230 237 /* with luck, no rollover is needed */ 231 238 t_now = rtc_tm_to_time64(&now); 232 239 t_alm = rtc_tm_to_time64(&alarm->time); ··· 285 278 dev_warn(&rtc->dev, "alarm rollover not handled\n"); 286 279 } 287 280 288 - done: 289 281 err = rtc_valid_tm(&alarm->time); 290 282 283 + done: 291 284 if (err) { 292 285 dev_warn(&rtc->dev, "invalid alarm value: %d-%d-%d %d:%d:%d\n", 293 286 alarm->time.tm_year + 1900, alarm->time.tm_mon + 1,
+113
drivers/rtc/nvmem.c
··· 1 + /* 2 + * RTC subsystem, nvmem interface 3 + * 4 + * Copyright (C) 2017 Alexandre Belloni 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/err.h> 12 + #include <linux/types.h> 13 + #include <linux/nvmem-consumer.h> 14 + #include <linux/rtc.h> 15 + #include <linux/sysfs.h> 16 + 17 + #include "rtc-core.h" 18 + 19 + /* 20 + * Deprecated ABI compatibility, this should be removed at some point 21 + */ 22 + 23 + static const char nvram_warning[] = "Deprecated ABI, please use nvmem"; 24 + 25 + static ssize_t 26 + rtc_nvram_read(struct file *filp, struct kobject *kobj, 27 + struct bin_attribute *attr, 28 + char *buf, loff_t off, size_t count) 29 + { 30 + struct rtc_device *rtc = attr->private; 31 + 32 + dev_warn_once(kobj_to_dev(kobj), nvram_warning); 33 + 34 + return nvmem_device_read(rtc->nvmem, off, count, buf); 35 + } 36 + 37 + static ssize_t 38 + rtc_nvram_write(struct file *filp, struct kobject *kobj, 39 + struct bin_attribute *attr, 40 + char *buf, loff_t off, size_t count) 41 + { 42 + struct rtc_device *rtc = attr->private; 43 + 44 + dev_warn_once(kobj_to_dev(kobj), nvram_warning); 45 + 46 + return nvmem_device_write(rtc->nvmem, off, count, buf); 47 + } 48 + 49 + static int rtc_nvram_register(struct rtc_device *rtc) 50 + { 51 + int err; 52 + 53 + rtc->nvram = devm_kzalloc(rtc->dev.parent, 54 + sizeof(struct bin_attribute), 55 + GFP_KERNEL); 56 + if (!rtc->nvram) 57 + return -ENOMEM; 58 + 59 + rtc->nvram->attr.name = "nvram"; 60 + rtc->nvram->attr.mode = 0644; 61 + rtc->nvram->private = rtc; 62 + 63 + sysfs_bin_attr_init(rtc->nvram); 64 + 65 + rtc->nvram->read = rtc_nvram_read; 66 + rtc->nvram->write = rtc_nvram_write; 67 + rtc->nvram->size = rtc->nvmem_config->size; 68 + 69 + err = sysfs_create_bin_file(&rtc->dev.parent->kobj, 70 + rtc->nvram); 71 + if (err) { 72 + devm_kfree(rtc->dev.parent, rtc->nvram); 73 + rtc->nvram = NULL; 74 + } 75 + 76 + return err; 77 + } 78 + 79 + static void rtc_nvram_unregister(struct rtc_device *rtc) 80 + { 81 + sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram); 82 + } 83 + 84 + /* 85 + * New ABI, uses nvmem 86 + */ 87 + void rtc_nvmem_register(struct rtc_device *rtc) 88 + { 89 + if (!rtc->nvmem_config) 90 + return; 91 + 92 + rtc->nvmem_config->dev = &rtc->dev; 93 + rtc->nvmem_config->owner = rtc->owner; 94 + rtc->nvmem = nvmem_register(rtc->nvmem_config); 95 + if (IS_ERR_OR_NULL(rtc->nvmem)) 96 + return; 97 + 98 + /* Register the old ABI */ 99 + if (rtc->nvram_old_abi) 100 + rtc_nvram_register(rtc); 101 + } 102 + 103 + void rtc_nvmem_unregister(struct rtc_device *rtc) 104 + { 105 + if (IS_ERR_OR_NULL(rtc->nvmem)) 106 + return; 107 + 108 + /* unregister the old ABI */ 109 + if (rtc->nvram) 110 + rtc_nvram_unregister(rtc); 111 + 112 + nvmem_unregister(rtc->nvmem); 113 + }
+8 -6
drivers/rtc/rtc-at91rm9200.c
··· 409 409 return -ENOMEM; 410 410 } 411 411 412 + rtc = devm_rtc_allocate_device(&pdev->dev); 413 + if (IS_ERR(rtc)) 414 + return PTR_ERR(rtc); 415 + platform_set_drvdata(pdev, rtc); 416 + 412 417 sclk = devm_clk_get(&pdev->dev, NULL); 413 418 if (IS_ERR(sclk)) 414 419 return PTR_ERR(sclk); ··· 446 441 if (!device_can_wakeup(&pdev->dev)) 447 442 device_init_wakeup(&pdev->dev, 1); 448 443 449 - rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 450 - &at91_rtc_ops, THIS_MODULE); 451 - if (IS_ERR(rtc)) { 452 - ret = PTR_ERR(rtc); 444 + rtc->ops = &at91_rtc_ops; 445 + ret = rtc_register_device(rtc); 446 + if (ret) 453 447 goto err_clk; 454 - } 455 - platform_set_drvdata(pdev, rtc); 456 448 457 449 /* enable SECEV interrupt in order to initialize at91_rtc_upd_rdy 458 450 * completion.
+330
drivers/rtc/rtc-brcmstb-waketimer.c
··· 1 + /* 2 + * Copyright © 2014-2017 Broadcom 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 + 16 + #include <linux/clk.h> 17 + #include <linux/device.h> 18 + #include <linux/err.h> 19 + #include <linux/init.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/io.h> 22 + #include <linux/irqreturn.h> 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/of.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/pm.h> 28 + #include <linux/pm_wakeup.h> 29 + #include <linux/reboot.h> 30 + #include <linux/rtc.h> 31 + #include <linux/stat.h> 32 + #include <linux/suspend.h> 33 + 34 + struct brcmstb_waketmr { 35 + struct rtc_device *rtc; 36 + struct device *dev; 37 + void __iomem *base; 38 + int irq; 39 + struct notifier_block reboot_notifier; 40 + struct clk *clk; 41 + u32 rate; 42 + }; 43 + 44 + #define BRCMSTB_WKTMR_EVENT 0x00 45 + #define BRCMSTB_WKTMR_COUNTER 0x04 46 + #define BRCMSTB_WKTMR_ALARM 0x08 47 + #define BRCMSTB_WKTMR_PRESCALER 0x0C 48 + #define BRCMSTB_WKTMR_PRESCALER_VAL 0x10 49 + 50 + #define BRCMSTB_WKTMR_DEFAULT_FREQ 27000000 51 + 52 + static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer) 53 + { 54 + writel_relaxed(1, timer->base + BRCMSTB_WKTMR_EVENT); 55 + (void)readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT); 56 + } 57 + 58 + static void brcmstb_waketmr_set_alarm(struct brcmstb_waketmr *timer, 59 + unsigned int secs) 60 + { 61 + brcmstb_waketmr_clear_alarm(timer); 62 + 63 + writel_relaxed(secs + 1, timer->base + BRCMSTB_WKTMR_ALARM); 64 + } 65 + 66 + static irqreturn_t brcmstb_waketmr_irq(int irq, void *data) 67 + { 68 + struct brcmstb_waketmr *timer = data; 69 + 70 + pm_wakeup_event(timer->dev, 0); 71 + 72 + return IRQ_HANDLED; 73 + } 74 + 75 + struct wktmr_time { 76 + u32 sec; 77 + u32 pre; 78 + }; 79 + 80 + static void wktmr_read(struct brcmstb_waketmr *timer, 81 + struct wktmr_time *t) 82 + { 83 + u32 tmp; 84 + 85 + do { 86 + t->sec = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER); 87 + tmp = readl_relaxed(timer->base + BRCMSTB_WKTMR_PRESCALER_VAL); 88 + } while (tmp >= timer->rate); 89 + 90 + t->pre = timer->rate - tmp; 91 + } 92 + 93 + static int brcmstb_waketmr_prepare_suspend(struct brcmstb_waketmr *timer) 94 + { 95 + struct device *dev = timer->dev; 96 + int ret = 0; 97 + 98 + if (device_may_wakeup(dev)) { 99 + ret = enable_irq_wake(timer->irq); 100 + if (ret) { 101 + dev_err(dev, "failed to enable wake-up interrupt\n"); 102 + return ret; 103 + } 104 + } 105 + 106 + return ret; 107 + } 108 + 109 + /* If enabled as a wakeup-source, arm the timer when powering off */ 110 + static int brcmstb_waketmr_reboot(struct notifier_block *nb, 111 + unsigned long action, void *data) 112 + { 113 + struct brcmstb_waketmr *timer; 114 + 115 + timer = container_of(nb, struct brcmstb_waketmr, reboot_notifier); 116 + 117 + /* Set timer for cold boot */ 118 + if (action == SYS_POWER_OFF) 119 + brcmstb_waketmr_prepare_suspend(timer); 120 + 121 + return NOTIFY_DONE; 122 + } 123 + 124 + static int brcmstb_waketmr_gettime(struct device *dev, 125 + struct rtc_time *tm) 126 + { 127 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 128 + struct wktmr_time now; 129 + 130 + wktmr_read(timer, &now); 131 + 132 + rtc_time_to_tm(now.sec, tm); 133 + 134 + return 0; 135 + } 136 + 137 + static int brcmstb_waketmr_settime(struct device *dev, 138 + struct rtc_time *tm) 139 + { 140 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 141 + time64_t sec; 142 + 143 + sec = rtc_tm_to_time64(tm); 144 + 145 + if (sec > U32_MAX || sec < 0) 146 + return -EINVAL; 147 + 148 + writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER); 149 + 150 + return 0; 151 + } 152 + 153 + static int brcmstb_waketmr_getalarm(struct device *dev, 154 + struct rtc_wkalrm *alarm) 155 + { 156 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 157 + time64_t sec; 158 + u32 reg; 159 + 160 + sec = readl_relaxed(timer->base + BRCMSTB_WKTMR_ALARM); 161 + if (sec != 0) { 162 + /* Alarm is enabled */ 163 + alarm->enabled = 1; 164 + rtc_time64_to_tm(sec, &alarm->time); 165 + } 166 + 167 + reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT); 168 + alarm->pending = !!(reg & 1); 169 + 170 + return 0; 171 + } 172 + 173 + static int brcmstb_waketmr_setalarm(struct device *dev, 174 + struct rtc_wkalrm *alarm) 175 + { 176 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 177 + time64_t sec; 178 + 179 + if (alarm->enabled) 180 + sec = rtc_tm_to_time64(&alarm->time); 181 + else 182 + sec = 0; 183 + 184 + if (sec > U32_MAX || sec < 0) 185 + return -EINVAL; 186 + 187 + brcmstb_waketmr_set_alarm(timer, sec); 188 + 189 + return 0; 190 + } 191 + 192 + /* 193 + * Does not do much but keep the RTC class happy. We always support 194 + * alarms. 195 + */ 196 + static int brcmstb_waketmr_alarm_enable(struct device *dev, 197 + unsigned int enabled) 198 + { 199 + return 0; 200 + } 201 + 202 + static const struct rtc_class_ops brcmstb_waketmr_ops = { 203 + .read_time = brcmstb_waketmr_gettime, 204 + .set_time = brcmstb_waketmr_settime, 205 + .read_alarm = brcmstb_waketmr_getalarm, 206 + .set_alarm = brcmstb_waketmr_setalarm, 207 + .alarm_irq_enable = brcmstb_waketmr_alarm_enable, 208 + }; 209 + 210 + static int brcmstb_waketmr_probe(struct platform_device *pdev) 211 + { 212 + struct device *dev = &pdev->dev; 213 + struct brcmstb_waketmr *timer; 214 + struct resource *res; 215 + int ret; 216 + 217 + timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL); 218 + if (!timer) 219 + return -ENOMEM; 220 + 221 + platform_set_drvdata(pdev, timer); 222 + timer->dev = dev; 223 + 224 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 225 + timer->base = devm_ioremap_resource(dev, res); 226 + if (IS_ERR(timer->base)) 227 + return PTR_ERR(timer->base); 228 + 229 + /* 230 + * Set wakeup capability before requesting wakeup interrupt, so we can 231 + * process boot-time "wakeups" (e.g., from S5 soft-off) 232 + */ 233 + device_set_wakeup_capable(dev, true); 234 + device_wakeup_enable(dev); 235 + 236 + timer->irq = platform_get_irq(pdev, 0); 237 + if (timer->irq < 0) 238 + return -ENODEV; 239 + 240 + timer->clk = devm_clk_get(dev, NULL); 241 + if (!IS_ERR(timer->clk)) { 242 + ret = clk_prepare_enable(timer->clk); 243 + if (ret) 244 + return ret; 245 + timer->rate = clk_get_rate(timer->clk); 246 + if (!timer->rate) 247 + timer->rate = BRCMSTB_WKTMR_DEFAULT_FREQ; 248 + } else { 249 + timer->rate = BRCMSTB_WKTMR_DEFAULT_FREQ; 250 + timer->clk = NULL; 251 + } 252 + 253 + ret = devm_request_irq(dev, timer->irq, brcmstb_waketmr_irq, 0, 254 + "brcmstb-waketimer", timer); 255 + if (ret < 0) 256 + return ret; 257 + 258 + timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot; 259 + register_reboot_notifier(&timer->reboot_notifier); 260 + 261 + timer->rtc = rtc_device_register("brcmstb-waketmr", dev, 262 + &brcmstb_waketmr_ops, THIS_MODULE); 263 + if (IS_ERR(timer->rtc)) { 264 + dev_err(dev, "unable to register device\n"); 265 + unregister_reboot_notifier(&timer->reboot_notifier); 266 + return PTR_ERR(timer->rtc); 267 + } 268 + 269 + dev_info(dev, "registered, with irq %d\n", timer->irq); 270 + 271 + return ret; 272 + } 273 + 274 + static int brcmstb_waketmr_remove(struct platform_device *pdev) 275 + { 276 + struct brcmstb_waketmr *timer = dev_get_drvdata(&pdev->dev); 277 + 278 + unregister_reboot_notifier(&timer->reboot_notifier); 279 + rtc_device_unregister(timer->rtc); 280 + 281 + return 0; 282 + } 283 + 284 + #ifdef CONFIG_PM_SLEEP 285 + static int brcmstb_waketmr_suspend(struct device *dev) 286 + { 287 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 288 + 289 + return brcmstb_waketmr_prepare_suspend(timer); 290 + } 291 + 292 + static int brcmstb_waketmr_resume(struct device *dev) 293 + { 294 + struct brcmstb_waketmr *timer = dev_get_drvdata(dev); 295 + int ret; 296 + 297 + if (!device_may_wakeup(dev)) 298 + return 0; 299 + 300 + ret = disable_irq_wake(timer->irq); 301 + 302 + brcmstb_waketmr_clear_alarm(timer); 303 + 304 + return ret; 305 + } 306 + #endif /* CONFIG_PM_SLEEP */ 307 + 308 + static SIMPLE_DEV_PM_OPS(brcmstb_waketmr_pm_ops, 309 + brcmstb_waketmr_suspend, brcmstb_waketmr_resume); 310 + 311 + static const struct of_device_id brcmstb_waketmr_of_match[] = { 312 + { .compatible = "brcm,brcmstb-waketimer" }, 313 + { /* sentinel */ }, 314 + }; 315 + 316 + static struct platform_driver brcmstb_waketmr_driver = { 317 + .probe = brcmstb_waketmr_probe, 318 + .remove = brcmstb_waketmr_remove, 319 + .driver = { 320 + .name = "brcmstb-waketimer", 321 + .pm = &brcmstb_waketmr_pm_ops, 322 + .of_match_table = of_match_ptr(brcmstb_waketmr_of_match), 323 + } 324 + }; 325 + module_platform_driver(brcmstb_waketmr_driver); 326 + 327 + MODULE_LICENSE("GPL v2"); 328 + MODULE_AUTHOR("Brian Norris"); 329 + MODULE_AUTHOR("Markus Mayer"); 330 + MODULE_DESCRIPTION("Wake-up timer driver for STB chips");
+8
drivers/rtc/rtc-core.h
··· 45 45 return NULL; 46 46 } 47 47 #endif 48 + 49 + #ifdef CONFIG_RTC_NVMEM 50 + void rtc_nvmem_register(struct rtc_device *rtc); 51 + void rtc_nvmem_unregister(struct rtc_device *rtc); 52 + #else 53 + static inline void rtc_nvmem_register(struct rtc_device *rtc) {} 54 + static inline void rtc_nvmem_unregister(struct rtc_device *rtc) {} 55 + #endif
+1 -1
drivers/rtc/rtc-dev.c
··· 464 464 return; 465 465 466 466 if (rtc->id >= RTC_DEV_MAX) { 467 - dev_dbg(&rtc->dev, "%s: too many RTC devices\n", rtc->name); 467 + dev_dbg(&rtc->dev, "too many RTC devices\n"); 468 468 return; 469 469 } 470 470
+440 -519
drivers/rtc/rtc-ds1307.c
··· 24 24 #include <linux/hwmon.h> 25 25 #include <linux/hwmon-sysfs.h> 26 26 #include <linux/clk-provider.h> 27 + #include <linux/regmap.h> 27 28 28 29 /* 29 30 * We can't determine type by probing, but if we expect pre-Linux code ··· 34 33 */ 35 34 enum ds_type { 36 35 ds_1307, 36 + ds_1308, 37 37 ds_1337, 38 38 ds_1338, 39 39 ds_1339, ··· 45 43 m41t00, 46 44 mcp794xx, 47 45 rx_8025, 46 + rx_8130, 48 47 last_ds_type /* always last */ 49 48 /* rs5c372 too? different address... */ 50 49 }; ··· 118 115 u8 offset; /* register's offset */ 119 116 u8 regs[11]; 120 117 u16 nvram_offset; 121 - struct bin_attribute *nvram; 118 + struct nvmem_config nvmem_cfg; 122 119 enum ds_type type; 123 120 unsigned long flags; 124 121 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */ 125 122 #define HAS_ALARM 1 /* bit 1 == irq claimed */ 126 - struct i2c_client *client; 123 + struct device *dev; 124 + struct regmap *regmap; 125 + const char *name; 126 + int irq; 127 127 struct rtc_device *rtc; 128 - s32 (*read_block_data)(const struct i2c_client *client, u8 command, 129 - u8 length, u8 *values); 130 - s32 (*write_block_data)(const struct i2c_client *client, u8 command, 131 - u8 length, const u8 *values); 132 128 #ifdef CONFIG_COMMON_CLK 133 129 struct clk_hw clks[2]; 134 130 #endif ··· 137 135 unsigned alarm:1; 138 136 u16 nvram_offset; 139 137 u16 nvram_size; 138 + u8 century_reg; 139 + u8 century_enable_bit; 140 + u8 century_bit; 140 141 u16 trickle_charger_reg; 141 142 u8 trickle_charger_setup; 142 - u8 (*do_trickle_setup)(struct i2c_client *, uint32_t, bool); 143 + u8 (*do_trickle_setup)(struct ds1307 *, uint32_t, 144 + bool); 143 145 }; 144 146 145 - static u8 do_trickle_setup_ds1339(struct i2c_client *, 146 - uint32_t ohms, bool diode); 147 + static u8 do_trickle_setup_ds1339(struct ds1307 *, uint32_t ohms, bool diode); 147 148 148 149 static struct chip_desc chips[last_ds_type] = { 149 150 [ds_1307] = { 150 151 .nvram_offset = 8, 151 152 .nvram_size = 56, 152 153 }, 154 + [ds_1308] = { 155 + .nvram_offset = 8, 156 + .nvram_size = 56, 157 + }, 153 158 [ds_1337] = { 154 159 .alarm = 1, 160 + .century_reg = DS1307_REG_MONTH, 161 + .century_bit = DS1337_BIT_CENTURY, 155 162 }, 156 163 [ds_1338] = { 157 164 .nvram_offset = 8, ··· 168 157 }, 169 158 [ds_1339] = { 170 159 .alarm = 1, 160 + .century_reg = DS1307_REG_MONTH, 161 + .century_bit = DS1337_BIT_CENTURY, 171 162 .trickle_charger_reg = 0x10, 172 163 .do_trickle_setup = &do_trickle_setup_ds1339, 173 164 }, 174 165 [ds_1340] = { 166 + .century_reg = DS1307_REG_HOUR, 167 + .century_enable_bit = DS1340_BIT_CENTURY_EN, 168 + .century_bit = DS1340_BIT_CENTURY, 175 169 .trickle_charger_reg = 0x08, 176 170 }, 177 171 [ds_1388] = { ··· 184 168 }, 185 169 [ds_3231] = { 186 170 .alarm = 1, 171 + .century_reg = DS1307_REG_MONTH, 172 + .century_bit = DS1337_BIT_CENTURY, 173 + }, 174 + [rx_8130] = { 175 + .alarm = 1, 176 + /* this is battery backed SRAM */ 177 + .nvram_offset = 0x20, 178 + .nvram_size = 4, /* 32bit (4 word x 8 bit) */ 187 179 }, 188 180 [mcp794xx] = { 189 181 .alarm = 1, ··· 203 179 204 180 static const struct i2c_device_id ds1307_id[] = { 205 181 { "ds1307", ds_1307 }, 182 + { "ds1308", ds_1308 }, 206 183 { "ds1337", ds_1337 }, 207 184 { "ds1338", ds_1338 }, 208 185 { "ds1339", ds_1339 }, ··· 217 192 { "pt7c4338", ds_1307 }, 218 193 { "rx8025", rx_8025 }, 219 194 { "isl12057", ds_1337 }, 195 + { "rx8130", rx_8130 }, 220 196 { } 221 197 }; 222 198 MODULE_DEVICE_TABLE(i2c, ds1307_id); ··· 227 201 { 228 202 .compatible = "dallas,ds1307", 229 203 .data = (void *)ds_1307 204 + }, 205 + { 206 + .compatible = "dallas,ds1308", 207 + .data = (void *)ds_1308 230 208 }, 231 209 { 232 210 .compatible = "dallas,ds1337", ··· 292 262 #ifdef CONFIG_ACPI 293 263 static const struct acpi_device_id ds1307_acpi_ids[] = { 294 264 { .id = "DS1307", .driver_data = ds_1307 }, 265 + { .id = "DS1308", .driver_data = ds_1308 }, 295 266 { .id = "DS1337", .driver_data = ds_1337 }, 296 267 { .id = "DS1338", .driver_data = ds_1338 }, 297 268 { .id = "DS1339", .driver_data = ds_1339 }, ··· 311 280 MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids); 312 281 #endif 313 282 314 - /*----------------------------------------------------------------------*/ 315 - 316 - #define BLOCK_DATA_MAX_TRIES 10 317 - 318 - static s32 ds1307_read_block_data_once(const struct i2c_client *client, 319 - u8 command, u8 length, u8 *values) 320 - { 321 - s32 i, data; 322 - 323 - for (i = 0; i < length; i++) { 324 - data = i2c_smbus_read_byte_data(client, command + i); 325 - if (data < 0) 326 - return data; 327 - values[i] = data; 328 - } 329 - return i; 330 - } 331 - 332 - static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command, 333 - u8 length, u8 *values) 334 - { 335 - u8 oldvalues[255]; 336 - s32 ret; 337 - int tries = 0; 338 - 339 - dev_dbg(&client->dev, "ds1307_read_block_data (length=%d)\n", length); 340 - ret = ds1307_read_block_data_once(client, command, length, values); 341 - if (ret < 0) 342 - return ret; 343 - do { 344 - if (++tries > BLOCK_DATA_MAX_TRIES) { 345 - dev_err(&client->dev, 346 - "ds1307_read_block_data failed\n"); 347 - return -EIO; 348 - } 349 - memcpy(oldvalues, values, length); 350 - ret = ds1307_read_block_data_once(client, command, length, 351 - values); 352 - if (ret < 0) 353 - return ret; 354 - } while (memcmp(oldvalues, values, length)); 355 - return length; 356 - } 357 - 358 - static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command, 359 - u8 length, const u8 *values) 360 - { 361 - u8 currvalues[255]; 362 - int tries = 0; 363 - 364 - dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length); 365 - do { 366 - s32 i, ret; 367 - 368 - if (++tries > BLOCK_DATA_MAX_TRIES) { 369 - dev_err(&client->dev, 370 - "ds1307_write_block_data failed\n"); 371 - return -EIO; 372 - } 373 - for (i = 0; i < length; i++) { 374 - ret = i2c_smbus_write_byte_data(client, command + i, 375 - values[i]); 376 - if (ret < 0) 377 - return ret; 378 - } 379 - ret = ds1307_read_block_data_once(client, command, length, 380 - currvalues); 381 - if (ret < 0) 382 - return ret; 383 - } while (memcmp(currvalues, values, length)); 384 - return length; 385 - } 386 - 387 - /*----------------------------------------------------------------------*/ 388 - 389 - /* These RTC devices are not designed to be connected to a SMbus adapter. 390 - SMbus limits block operations length to 32 bytes, whereas it's not 391 - limited on I2C buses. As a result, accesses may exceed 32 bytes; 392 - in that case, split them into smaller blocks */ 393 - 394 - static s32 ds1307_native_smbus_write_block_data(const struct i2c_client *client, 395 - u8 command, u8 length, const u8 *values) 396 - { 397 - u8 suboffset = 0; 398 - 399 - if (length <= I2C_SMBUS_BLOCK_MAX) { 400 - s32 retval = i2c_smbus_write_i2c_block_data(client, 401 - command, length, values); 402 - if (retval < 0) 403 - return retval; 404 - return length; 405 - } 406 - 407 - while (suboffset < length) { 408 - s32 retval = i2c_smbus_write_i2c_block_data(client, 409 - command + suboffset, 410 - min(I2C_SMBUS_BLOCK_MAX, length - suboffset), 411 - values + suboffset); 412 - if (retval < 0) 413 - return retval; 414 - 415 - suboffset += I2C_SMBUS_BLOCK_MAX; 416 - } 417 - return length; 418 - } 419 - 420 - static s32 ds1307_native_smbus_read_block_data(const struct i2c_client *client, 421 - u8 command, u8 length, u8 *values) 422 - { 423 - u8 suboffset = 0; 424 - 425 - if (length <= I2C_SMBUS_BLOCK_MAX) 426 - return i2c_smbus_read_i2c_block_data(client, 427 - command, length, values); 428 - 429 - while (suboffset < length) { 430 - s32 retval = i2c_smbus_read_i2c_block_data(client, 431 - command + suboffset, 432 - min(I2C_SMBUS_BLOCK_MAX, length - suboffset), 433 - values + suboffset); 434 - if (retval < 0) 435 - return retval; 436 - 437 - suboffset += I2C_SMBUS_BLOCK_MAX; 438 - } 439 - return length; 440 - } 441 - 442 - /*----------------------------------------------------------------------*/ 443 - 444 283 /* 445 284 * The ds1337 and ds1339 both have two alarms, but we only use the first 446 285 * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm ··· 318 417 */ 319 418 static irqreturn_t ds1307_irq(int irq, void *dev_id) 320 419 { 321 - struct i2c_client *client = dev_id; 322 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 420 + struct ds1307 *ds1307 = dev_id; 323 421 struct mutex *lock = &ds1307->rtc->ops_lock; 324 - int stat, control; 422 + int stat, ret; 325 423 326 424 mutex_lock(lock); 327 - stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS); 328 - if (stat < 0) 425 + ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &stat); 426 + if (ret) 329 427 goto out; 330 428 331 429 if (stat & DS1337_BIT_A1I) { 332 430 stat &= ~DS1337_BIT_A1I; 333 - i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, stat); 431 + regmap_write(ds1307->regmap, DS1337_REG_STATUS, stat); 334 432 335 - control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL); 336 - if (control < 0) 433 + ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, 434 + DS1337_BIT_A1IE, 0); 435 + if (ret) 337 436 goto out; 338 - 339 - control &= ~DS1337_BIT_A1IE; 340 - i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control); 341 437 342 438 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); 343 439 } ··· 350 452 static int ds1307_get_time(struct device *dev, struct rtc_time *t) 351 453 { 352 454 struct ds1307 *ds1307 = dev_get_drvdata(dev); 353 - int tmp; 455 + int tmp, ret; 456 + const struct chip_desc *chip = &chips[ds1307->type]; 354 457 355 458 /* read the RTC date and time registers all at once */ 356 - tmp = ds1307->read_block_data(ds1307->client, 357 - ds1307->offset, 7, ds1307->regs); 358 - if (tmp != 7) { 359 - dev_err(dev, "%s error %d\n", "read", tmp); 360 - return -EIO; 459 + ret = regmap_bulk_read(ds1307->regmap, ds1307->offset, ds1307->regs, 7); 460 + if (ret) { 461 + dev_err(dev, "%s error %d\n", "read", ret); 462 + return ret; 361 463 } 362 464 363 465 dev_dbg(dev, "%s: %7ph\n", "read", ds1307->regs); ··· 379 481 t->tm_mon = bcd2bin(tmp) - 1; 380 482 t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100; 381 483 382 - #ifdef CONFIG_RTC_DRV_DS1307_CENTURY 383 - switch (ds1307->type) { 384 - case ds_1337: 385 - case ds_1339: 386 - case ds_3231: 387 - if (ds1307->regs[DS1307_REG_MONTH] & DS1337_BIT_CENTURY) 388 - t->tm_year += 100; 389 - break; 390 - case ds_1340: 391 - if (ds1307->regs[DS1307_REG_HOUR] & DS1340_BIT_CENTURY) 392 - t->tm_year += 100; 393 - break; 394 - default: 395 - break; 396 - } 397 - #endif 484 + if (ds1307->regs[chip->century_reg] & chip->century_bit && 485 + IS_ENABLED(CONFIG_RTC_DRV_DS1307_CENTURY)) 486 + t->tm_year += 100; 398 487 399 488 dev_dbg(dev, "%s secs=%d, mins=%d, " 400 489 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", ··· 396 511 static int ds1307_set_time(struct device *dev, struct rtc_time *t) 397 512 { 398 513 struct ds1307 *ds1307 = dev_get_drvdata(dev); 514 + const struct chip_desc *chip = &chips[ds1307->type]; 399 515 int result; 400 516 int tmp; 401 517 u8 *buf = ds1307->regs; ··· 407 521 t->tm_hour, t->tm_mday, 408 522 t->tm_mon, t->tm_year, t->tm_wday); 409 523 410 - #ifdef CONFIG_RTC_DRV_DS1307_CENTURY 411 524 if (t->tm_year < 100) 412 525 return -EINVAL; 413 526 414 - switch (ds1307->type) { 415 - case ds_1337: 416 - case ds_1339: 417 - case ds_3231: 418 - case ds_1340: 419 - if (t->tm_year > 299) 420 - return -EINVAL; 421 - default: 422 - if (t->tm_year > 199) 423 - return -EINVAL; 424 - break; 425 - } 527 + #ifdef CONFIG_RTC_DRV_DS1307_CENTURY 528 + if (t->tm_year > (chip->century_bit ? 299 : 199)) 529 + return -EINVAL; 426 530 #else 427 - if (t->tm_year < 100 || t->tm_year > 199) 531 + if (t->tm_year > 199) 428 532 return -EINVAL; 429 533 #endif 430 534 ··· 429 553 tmp = t->tm_year - 100; 430 554 buf[DS1307_REG_YEAR] = bin2bcd(tmp); 431 555 432 - switch (ds1307->type) { 433 - case ds_1337: 434 - case ds_1339: 435 - case ds_3231: 436 - if (t->tm_year > 199) 437 - buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY; 438 - break; 439 - case ds_1340: 440 - buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN; 441 - if (t->tm_year > 199) 442 - buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY; 443 - break; 444 - case mcp794xx: 556 + if (chip->century_enable_bit) 557 + buf[chip->century_reg] |= chip->century_enable_bit; 558 + if (t->tm_year > 199 && chip->century_bit) 559 + buf[chip->century_reg] |= chip->century_bit; 560 + 561 + if (ds1307->type == mcp794xx) { 445 562 /* 446 563 * these bits were cleared when preparing the date/time 447 564 * values and need to be set again before writing the ··· 442 573 */ 443 574 buf[DS1307_REG_SECS] |= MCP794XX_BIT_ST; 444 575 buf[DS1307_REG_WDAY] |= MCP794XX_BIT_VBATEN; 445 - break; 446 - default: 447 - break; 448 576 } 449 577 450 578 dev_dbg(dev, "%s: %7ph\n", "write", buf); 451 579 452 - result = ds1307->write_block_data(ds1307->client, 453 - ds1307->offset, 7, buf); 454 - if (result < 0) { 580 + result = regmap_bulk_write(ds1307->regmap, ds1307->offset, buf, 7); 581 + if (result) { 455 582 dev_err(dev, "%s error %d\n", "write", result); 456 583 return result; 457 584 } ··· 456 591 457 592 static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t) 458 593 { 459 - struct i2c_client *client = to_i2c_client(dev); 460 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 594 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 461 595 int ret; 462 596 463 597 if (!test_bit(HAS_ALARM, &ds1307->flags)) 464 598 return -EINVAL; 465 599 466 600 /* read all ALARM1, ALARM2, and status registers at once */ 467 - ret = ds1307->read_block_data(client, 468 - DS1339_REG_ALARM1_SECS, 9, ds1307->regs); 469 - if (ret != 9) { 601 + ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, 602 + ds1307->regs, 9); 603 + if (ret) { 470 604 dev_err(dev, "%s error %d\n", "alarm read", ret); 471 - return -EIO; 605 + return ret; 472 606 } 473 607 474 608 dev_dbg(dev, "%s: %4ph, %3ph, %2ph\n", "alarm read", ··· 497 633 498 634 static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t) 499 635 { 500 - struct i2c_client *client = to_i2c_client(dev); 501 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 636 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 502 637 unsigned char *buf = ds1307->regs; 503 638 u8 control, status; 504 639 int ret; ··· 512 649 t->enabled, t->pending); 513 650 514 651 /* read current status of both alarms and the chip */ 515 - ret = ds1307->read_block_data(client, 516 - DS1339_REG_ALARM1_SECS, 9, buf); 517 - if (ret != 9) { 652 + ret = regmap_bulk_read(ds1307->regmap, DS1339_REG_ALARM1_SECS, buf, 9); 653 + if (ret) { 518 654 dev_err(dev, "%s error %d\n", "alarm write", ret); 519 - return -EIO; 655 + return ret; 520 656 } 521 657 control = ds1307->regs[7]; 522 658 status = ds1307->regs[8]; ··· 538 676 buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE); 539 677 buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I); 540 678 541 - ret = ds1307->write_block_data(client, 542 - DS1339_REG_ALARM1_SECS, 9, buf); 543 - if (ret < 0) { 679 + ret = regmap_bulk_write(ds1307->regmap, DS1339_REG_ALARM1_SECS, buf, 9); 680 + if (ret) { 544 681 dev_err(dev, "can't set alarm time\n"); 545 682 return ret; 546 683 } ··· 548 687 if (t->enabled) { 549 688 dev_dbg(dev, "alarm IRQ armed\n"); 550 689 buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */ 551 - i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, buf[7]); 690 + regmap_write(ds1307->regmap, DS1337_REG_CONTROL, buf[7]); 552 691 } 553 692 554 693 return 0; ··· 556 695 557 696 static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled) 558 697 { 559 - struct i2c_client *client = to_i2c_client(dev); 560 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 561 - int ret; 698 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 562 699 563 700 if (!test_bit(HAS_ALARM, &ds1307->flags)) 564 701 return -ENOTTY; 565 702 566 - ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL); 567 - if (ret < 0) 568 - return ret; 569 - 570 - if (enabled) 571 - ret |= DS1337_BIT_A1IE; 572 - else 573 - ret &= ~DS1337_BIT_A1IE; 574 - 575 - ret = i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, ret); 576 - if (ret < 0) 577 - return ret; 578 - 579 - return 0; 703 + return regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, 704 + DS1337_BIT_A1IE, 705 + enabled ? DS1337_BIT_A1IE : 0); 580 706 } 581 707 582 708 static const struct rtc_class_ops ds13xx_rtc_ops = { ··· 572 724 .read_alarm = ds1337_read_alarm, 573 725 .set_alarm = ds1337_set_alarm, 574 726 .alarm_irq_enable = ds1307_alarm_irq_enable, 727 + }; 728 + 729 + /*----------------------------------------------------------------------*/ 730 + 731 + /* 732 + * Alarm support for rx8130 devices. 733 + */ 734 + 735 + #define RX8130_REG_ALARM_MIN 0x07 736 + #define RX8130_REG_ALARM_HOUR 0x08 737 + #define RX8130_REG_ALARM_WEEK_OR_DAY 0x09 738 + #define RX8130_REG_EXTENSION 0x0c 739 + #define RX8130_REG_EXTENSION_WADA (1 << 3) 740 + #define RX8130_REG_FLAG 0x0d 741 + #define RX8130_REG_FLAG_AF (1 << 3) 742 + #define RX8130_REG_CONTROL0 0x0e 743 + #define RX8130_REG_CONTROL0_AIE (1 << 3) 744 + 745 + static irqreturn_t rx8130_irq(int irq, void *dev_id) 746 + { 747 + struct ds1307 *ds1307 = dev_id; 748 + struct mutex *lock = &ds1307->rtc->ops_lock; 749 + u8 ctl[3]; 750 + int ret; 751 + 752 + mutex_lock(lock); 753 + 754 + /* Read control registers. */ 755 + ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 756 + if (ret < 0) 757 + goto out; 758 + if (!(ctl[1] & RX8130_REG_FLAG_AF)) 759 + goto out; 760 + ctl[1] &= ~RX8130_REG_FLAG_AF; 761 + ctl[2] &= ~RX8130_REG_CONTROL0_AIE; 762 + 763 + ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 764 + if (ret < 0) 765 + goto out; 766 + 767 + rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); 768 + 769 + out: 770 + mutex_unlock(lock); 771 + 772 + return IRQ_HANDLED; 773 + } 774 + 775 + static int rx8130_read_alarm(struct device *dev, struct rtc_wkalrm *t) 776 + { 777 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 778 + u8 ald[3], ctl[3]; 779 + int ret; 780 + 781 + if (!test_bit(HAS_ALARM, &ds1307->flags)) 782 + return -EINVAL; 783 + 784 + /* Read alarm registers. */ 785 + ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, 3); 786 + if (ret < 0) 787 + return ret; 788 + 789 + /* Read control registers. */ 790 + ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 791 + if (ret < 0) 792 + return ret; 793 + 794 + t->enabled = !!(ctl[2] & RX8130_REG_CONTROL0_AIE); 795 + t->pending = !!(ctl[1] & RX8130_REG_FLAG_AF); 796 + 797 + /* Report alarm 0 time assuming 24-hour and day-of-month modes. */ 798 + t->time.tm_sec = -1; 799 + t->time.tm_min = bcd2bin(ald[0] & 0x7f); 800 + t->time.tm_hour = bcd2bin(ald[1] & 0x7f); 801 + t->time.tm_wday = -1; 802 + t->time.tm_mday = bcd2bin(ald[2] & 0x7f); 803 + t->time.tm_mon = -1; 804 + t->time.tm_year = -1; 805 + t->time.tm_yday = -1; 806 + t->time.tm_isdst = -1; 807 + 808 + dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d enabled=%d\n", 809 + __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour, 810 + t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled); 811 + 812 + return 0; 813 + } 814 + 815 + static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t) 816 + { 817 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 818 + u8 ald[3], ctl[3]; 819 + int ret; 820 + 821 + if (!test_bit(HAS_ALARM, &ds1307->flags)) 822 + return -EINVAL; 823 + 824 + dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " 825 + "enabled=%d pending=%d\n", __func__, 826 + t->time.tm_sec, t->time.tm_min, t->time.tm_hour, 827 + t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, 828 + t->enabled, t->pending); 829 + 830 + /* Read control registers. */ 831 + ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 832 + if (ret < 0) 833 + return ret; 834 + 835 + ctl[0] &= ~RX8130_REG_EXTENSION_WADA; 836 + ctl[1] |= RX8130_REG_FLAG_AF; 837 + ctl[2] &= ~RX8130_REG_CONTROL0_AIE; 838 + 839 + ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 840 + if (ret < 0) 841 + return ret; 842 + 843 + /* Hardware alarm precision is 1 minute! */ 844 + ald[0] = bin2bcd(t->time.tm_min); 845 + ald[1] = bin2bcd(t->time.tm_hour); 846 + ald[2] = bin2bcd(t->time.tm_mday); 847 + 848 + ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, 3); 849 + if (ret < 0) 850 + return ret; 851 + 852 + if (!t->enabled) 853 + return 0; 854 + 855 + ctl[2] |= RX8130_REG_CONTROL0_AIE; 856 + 857 + return regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3); 858 + } 859 + 860 + static int rx8130_alarm_irq_enable(struct device *dev, unsigned int enabled) 861 + { 862 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 863 + int ret, reg; 864 + 865 + if (!test_bit(HAS_ALARM, &ds1307->flags)) 866 + return -EINVAL; 867 + 868 + ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, &reg); 869 + if (ret < 0) 870 + return ret; 871 + 872 + if (enabled) 873 + reg |= RX8130_REG_CONTROL0_AIE; 874 + else 875 + reg &= ~RX8130_REG_CONTROL0_AIE; 876 + 877 + return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg); 878 + } 879 + 880 + static const struct rtc_class_ops rx8130_rtc_ops = { 881 + .read_time = ds1307_get_time, 882 + .set_time = ds1307_set_time, 883 + .read_alarm = rx8130_read_alarm, 884 + .set_alarm = rx8130_set_alarm, 885 + .alarm_irq_enable = rx8130_alarm_irq_enable, 575 886 }; 576 887 577 888 /*----------------------------------------------------------------------*/ ··· 759 752 760 753 static irqreturn_t mcp794xx_irq(int irq, void *dev_id) 761 754 { 762 - struct i2c_client *client = dev_id; 763 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 755 + struct ds1307 *ds1307 = dev_id; 764 756 struct mutex *lock = &ds1307->rtc->ops_lock; 765 757 int reg, ret; 766 758 767 759 mutex_lock(lock); 768 760 769 761 /* Check and clear alarm 0 interrupt flag. */ 770 - reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_ALARM0_CTRL); 771 - if (reg < 0) 762 + ret = regmap_read(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, &reg); 763 + if (ret) 772 764 goto out; 773 765 if (!(reg & MCP794XX_BIT_ALMX_IF)) 774 766 goto out; 775 767 reg &= ~MCP794XX_BIT_ALMX_IF; 776 - ret = i2c_smbus_write_byte_data(client, MCP794XX_REG_ALARM0_CTRL, reg); 777 - if (ret < 0) 768 + ret = regmap_write(ds1307->regmap, MCP794XX_REG_ALARM0_CTRL, reg); 769 + if (ret) 778 770 goto out; 779 771 780 772 /* Disable alarm 0. */ 781 - reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_CONTROL); 782 - if (reg < 0) 783 - goto out; 784 - reg &= ~MCP794XX_BIT_ALM0_EN; 785 - ret = i2c_smbus_write_byte_data(client, MCP794XX_REG_CONTROL, reg); 786 - if (ret < 0) 773 + ret = regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, 774 + MCP794XX_BIT_ALM0_EN, 0); 775 + if (ret) 787 776 goto out; 788 777 789 778 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); ··· 792 789 793 790 static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t) 794 791 { 795 - struct i2c_client *client = to_i2c_client(dev); 796 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 792 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 797 793 u8 *regs = ds1307->regs; 798 794 int ret; 799 795 ··· 800 798 return -EINVAL; 801 799 802 800 /* Read control and alarm 0 registers. */ 803 - ret = ds1307->read_block_data(client, MCP794XX_REG_CONTROL, 10, regs); 804 - if (ret < 0) 801 + ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, 10); 802 + if (ret) 805 803 return ret; 806 804 807 805 t->enabled = !!(regs[0] & MCP794XX_BIT_ALM0_EN); ··· 830 828 831 829 static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t) 832 830 { 833 - struct i2c_client *client = to_i2c_client(dev); 834 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 831 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 835 832 unsigned char *regs = ds1307->regs; 836 833 int ret; 837 834 ··· 844 843 t->enabled, t->pending); 845 844 846 845 /* Read control and alarm 0 registers. */ 847 - ret = ds1307->read_block_data(client, MCP794XX_REG_CONTROL, 10, regs); 848 - if (ret < 0) 846 + ret = regmap_bulk_read(ds1307->regmap, MCP794XX_REG_CONTROL, regs, 10); 847 + if (ret) 849 848 return ret; 850 849 851 850 /* Set alarm 0, using 24-hour and day-of-month modes. */ ··· 863 862 /* Disable interrupt. We will not enable until completely programmed */ 864 863 regs[0] &= ~MCP794XX_BIT_ALM0_EN; 865 864 866 - ret = ds1307->write_block_data(client, MCP794XX_REG_CONTROL, 10, regs); 867 - if (ret < 0) 865 + ret = regmap_bulk_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs, 10); 866 + if (ret) 868 867 return ret; 869 868 870 869 if (!t->enabled) 871 870 return 0; 872 871 regs[0] |= MCP794XX_BIT_ALM0_EN; 873 - return i2c_smbus_write_byte_data(client, MCP794XX_REG_CONTROL, regs[0]); 872 + return regmap_write(ds1307->regmap, MCP794XX_REG_CONTROL, regs[0]); 874 873 } 875 874 876 875 static int mcp794xx_alarm_irq_enable(struct device *dev, unsigned int enabled) 877 876 { 878 - struct i2c_client *client = to_i2c_client(dev); 879 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 880 - int reg; 877 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 881 878 882 879 if (!test_bit(HAS_ALARM, &ds1307->flags)) 883 880 return -EINVAL; 884 881 885 - reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_CONTROL); 886 - if (reg < 0) 887 - return reg; 888 - 889 - if (enabled) 890 - reg |= MCP794XX_BIT_ALM0_EN; 891 - else 892 - reg &= ~MCP794XX_BIT_ALM0_EN; 893 - 894 - return i2c_smbus_write_byte_data(client, MCP794XX_REG_CONTROL, reg); 882 + return regmap_update_bits(ds1307->regmap, MCP794XX_REG_CONTROL, 883 + MCP794XX_BIT_ALM0_EN, 884 + enabled ? MCP794XX_BIT_ALM0_EN : 0); 895 885 } 896 886 897 887 static const struct rtc_class_ops mcp794xx_rtc_ops = { ··· 895 903 896 904 /*----------------------------------------------------------------------*/ 897 905 898 - static ssize_t 899 - ds1307_nvram_read(struct file *filp, struct kobject *kobj, 900 - struct bin_attribute *attr, 901 - char *buf, loff_t off, size_t count) 906 + static int ds1307_nvram_read(void *priv, unsigned int offset, void *val, 907 + size_t bytes) 902 908 { 903 - struct i2c_client *client; 904 - struct ds1307 *ds1307; 905 - int result; 909 + struct ds1307 *ds1307 = priv; 906 910 907 - client = kobj_to_i2c_client(kobj); 908 - ds1307 = i2c_get_clientdata(client); 909 - 910 - result = ds1307->read_block_data(client, ds1307->nvram_offset + off, 911 - count, buf); 912 - if (result < 0) 913 - dev_err(&client->dev, "%s error %d\n", "nvram read", result); 914 - return result; 911 + return regmap_bulk_read(ds1307->regmap, ds1307->nvram_offset + offset, 912 + val, bytes); 915 913 } 916 914 917 - static ssize_t 918 - ds1307_nvram_write(struct file *filp, struct kobject *kobj, 919 - struct bin_attribute *attr, 920 - char *buf, loff_t off, size_t count) 915 + static int ds1307_nvram_write(void *priv, unsigned int offset, void *val, 916 + size_t bytes) 921 917 { 922 - struct i2c_client *client; 923 - struct ds1307 *ds1307; 924 - int result; 918 + struct ds1307 *ds1307 = priv; 925 919 926 - client = kobj_to_i2c_client(kobj); 927 - ds1307 = i2c_get_clientdata(client); 928 - 929 - result = ds1307->write_block_data(client, ds1307->nvram_offset + off, 930 - count, buf); 931 - if (result < 0) { 932 - dev_err(&client->dev, "%s error %d\n", "nvram write", result); 933 - return result; 934 - } 935 - return count; 920 + return regmap_bulk_write(ds1307->regmap, ds1307->nvram_offset + offset, 921 + val, bytes); 936 922 } 937 - 938 923 939 924 /*----------------------------------------------------------------------*/ 940 925 941 - static u8 do_trickle_setup_ds1339(struct i2c_client *client, 926 + static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, 942 927 uint32_t ohms, bool diode) 943 928 { 944 929 u8 setup = (diode) ? DS1307_TRICKLE_CHARGER_DIODE : ··· 932 963 setup |= DS1307_TRICKLE_CHARGER_4K_OHM; 933 964 break; 934 965 default: 935 - dev_warn(&client->dev, 966 + dev_warn(ds1307->dev, 936 967 "Unsupported ohm value %u in dt\n", ohms); 937 968 return 0; 938 969 } 939 970 return setup; 940 971 } 941 972 942 - static void ds1307_trickle_init(struct i2c_client *client, 973 + static void ds1307_trickle_init(struct ds1307 *ds1307, 943 974 struct chip_desc *chip) 944 975 { 945 976 uint32_t ohms = 0; ··· 947 978 948 979 if (!chip->do_trickle_setup) 949 980 goto out; 950 - if (device_property_read_u32(&client->dev, "trickle-resistor-ohms", &ohms)) 981 + if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms", 982 + &ohms)) 951 983 goto out; 952 - if (device_property_read_bool(&client->dev, "trickle-diode-disable")) 984 + if (device_property_read_bool(ds1307->dev, "trickle-diode-disable")) 953 985 diode = false; 954 - chip->trickle_charger_setup = chip->do_trickle_setup(client, 986 + chip->trickle_charger_setup = chip->do_trickle_setup(ds1307, 955 987 ohms, diode); 956 988 out: 957 989 return; ··· 979 1009 s16 temp; 980 1010 int ret; 981 1011 982 - ret = ds1307->read_block_data(ds1307->client, DS3231_REG_TEMPERATURE, 983 - sizeof(temp_buf), temp_buf); 984 - if (ret < 0) 1012 + ret = regmap_bulk_read(ds1307->regmap, DS3231_REG_TEMPERATURE, 1013 + temp_buf, sizeof(temp_buf)); 1014 + if (ret) 985 1015 return ret; 986 - if (ret != sizeof(temp_buf)) 987 - return -EIO; 988 - 989 1016 /* 990 1017 * Temperature is represented as a 10-bit code with a resolution of 991 1018 * 0.25 degree celsius and encoded in two's complement format. ··· 1022 1055 if (ds1307->type != ds_3231) 1023 1056 return; 1024 1057 1025 - dev = devm_hwmon_device_register_with_groups(&ds1307->client->dev, 1026 - ds1307->client->name, 1058 + dev = devm_hwmon_device_register_with_groups(ds1307->dev, ds1307->name, 1027 1059 ds1307, ds3231_hwmon_groups); 1028 1060 if (IS_ERR(dev)) { 1029 - dev_warn(&ds1307->client->dev, 1030 - "unable to register hwmon device %ld\n", PTR_ERR(dev)); 1061 + dev_warn(ds1307->dev, "unable to register hwmon device %ld\n", 1062 + PTR_ERR(dev)); 1031 1063 } 1032 1064 } 1033 1065 ··· 1065 1099 1066 1100 static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value) 1067 1101 { 1068 - struct i2c_client *client = ds1307->client; 1069 1102 struct mutex *lock = &ds1307->rtc->ops_lock; 1070 - int control; 1071 1103 int ret; 1072 1104 1073 1105 mutex_lock(lock); 1074 - 1075 - control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL); 1076 - if (control < 0) { 1077 - ret = control; 1078 - goto out; 1079 - } 1080 - 1081 - control &= ~mask; 1082 - control |= value; 1083 - 1084 - ret = i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control); 1085 - out: 1106 + ret = regmap_update_bits(ds1307->regmap, DS1337_REG_CONTROL, 1107 + mask, value); 1086 1108 mutex_unlock(lock); 1087 1109 1088 1110 return ret; ··· 1080 1126 unsigned long parent_rate) 1081 1127 { 1082 1128 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1083 - int control; 1129 + int control, ret; 1084 1130 int rate_sel = 0; 1085 1131 1086 - control = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_CONTROL); 1087 - if (control < 0) 1088 - return control; 1132 + ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); 1133 + if (ret) 1134 + return ret; 1089 1135 if (control & DS1337_BIT_RS1) 1090 1136 rate_sel += 1; 1091 1137 if (control & DS1337_BIT_RS2) ··· 1149 1195 static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw) 1150 1196 { 1151 1197 struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1152 - int control; 1198 + int control, ret; 1153 1199 1154 - control = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_CONTROL); 1155 - if (control < 0) 1156 - return control; 1200 + ret = regmap_read(ds1307->regmap, DS1337_REG_CONTROL, &control); 1201 + if (ret) 1202 + return ret; 1157 1203 1158 1204 return !(control & DS1337_BIT_INTCN); 1159 1205 } ··· 1175 1221 1176 1222 static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable) 1177 1223 { 1178 - struct i2c_client *client = ds1307->client; 1179 1224 struct mutex *lock = &ds1307->rtc->ops_lock; 1180 - int status; 1181 1225 int ret; 1182 1226 1183 1227 mutex_lock(lock); 1184 - 1185 - status = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS); 1186 - if (status < 0) { 1187 - ret = status; 1188 - goto out; 1189 - } 1190 - 1191 - if (enable) 1192 - status |= DS3231_BIT_EN32KHZ; 1193 - else 1194 - status &= ~DS3231_BIT_EN32KHZ; 1195 - 1196 - ret = i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, status); 1197 - out: 1228 + ret = regmap_update_bits(ds1307->regmap, DS1337_REG_STATUS, 1229 + DS3231_BIT_EN32KHZ, 1230 + enable ? DS3231_BIT_EN32KHZ : 0); 1198 1231 mutex_unlock(lock); 1199 1232 1200 1233 return ret; ··· 1204 1263 static int ds3231_clk_32khz_is_prepared(struct clk_hw *hw) 1205 1264 { 1206 1265 struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); 1207 - int status; 1266 + int status, ret; 1208 1267 1209 - status = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_STATUS); 1210 - if (status < 0) 1211 - return status; 1268 + ret = regmap_read(ds1307->regmap, DS1337_REG_STATUS, &status); 1269 + if (ret) 1270 + return ret; 1212 1271 1213 1272 return !!(status & DS3231_BIT_EN32KHZ); 1214 1273 } ··· 1233 1292 1234 1293 static int ds3231_clks_register(struct ds1307 *ds1307) 1235 1294 { 1236 - struct i2c_client *client = ds1307->client; 1237 - struct device_node *node = client->dev.of_node; 1295 + struct device_node *node = ds1307->dev->of_node; 1238 1296 struct clk_onecell_data *onecell; 1239 1297 int i; 1240 1298 1241 - onecell = devm_kzalloc(&client->dev, sizeof(*onecell), GFP_KERNEL); 1299 + onecell = devm_kzalloc(ds1307->dev, sizeof(*onecell), GFP_KERNEL); 1242 1300 if (!onecell) 1243 1301 return -ENOMEM; 1244 1302 1245 1303 onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); 1246 - onecell->clks = devm_kcalloc(&client->dev, onecell->clk_num, 1247 - sizeof(onecell->clks[0]), GFP_KERNEL); 1304 + onecell->clks = devm_kcalloc(ds1307->dev, onecell->clk_num, 1305 + sizeof(onecell->clks[0]), GFP_KERNEL); 1248 1306 if (!onecell->clks) 1249 1307 return -ENOMEM; 1250 1308 ··· 1262 1322 &init.name); 1263 1323 ds1307->clks[i].init = &init; 1264 1324 1265 - onecell->clks[i] = devm_clk_register(&client->dev, 1266 - &ds1307->clks[i]); 1325 + onecell->clks[i] = devm_clk_register(ds1307->dev, 1326 + &ds1307->clks[i]); 1267 1327 if (IS_ERR(onecell->clks[i])) 1268 1328 return PTR_ERR(onecell->clks[i]); 1269 1329 } ··· 1285 1345 1286 1346 ret = ds3231_clks_register(ds1307); 1287 1347 if (ret) { 1288 - dev_warn(&ds1307->client->dev, 1289 - "unable to register clock device %d\n", ret); 1348 + dev_warn(ds1307->dev, "unable to register clock device %d\n", 1349 + ret); 1290 1350 } 1291 1351 } 1292 1352 ··· 1298 1358 1299 1359 #endif /* CONFIG_COMMON_CLK */ 1300 1360 1361 + static const struct regmap_config regmap_config = { 1362 + .reg_bits = 8, 1363 + .val_bits = 8, 1364 + .max_register = 0x12, 1365 + }; 1366 + 1301 1367 static int ds1307_probe(struct i2c_client *client, 1302 1368 const struct i2c_device_id *id) 1303 1369 { ··· 1311 1365 int err = -ENODEV; 1312 1366 int tmp, wday; 1313 1367 struct chip_desc *chip; 1314 - struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1315 1368 bool want_irq = false; 1316 1369 bool ds1307_can_wakeup_device = false; 1317 1370 unsigned char *buf; ··· 1327 1382 }; 1328 1383 const struct rtc_class_ops *rtc_ops = &ds13xx_rtc_ops; 1329 1384 1330 - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA) 1331 - && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 1332 - return -EIO; 1333 - 1334 1385 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); 1335 1386 if (!ds1307) 1336 1387 return -ENOMEM; 1337 1388 1338 - i2c_set_clientdata(client, ds1307); 1389 + dev_set_drvdata(&client->dev, ds1307); 1390 + ds1307->dev = &client->dev; 1391 + ds1307->name = client->name; 1392 + ds1307->irq = client->irq; 1339 1393 1340 - ds1307->client = client; 1394 + ds1307->regmap = devm_regmap_init_i2c(client, &regmap_config); 1395 + if (IS_ERR(ds1307->regmap)) { 1396 + dev_err(ds1307->dev, "regmap allocation failed\n"); 1397 + return PTR_ERR(ds1307->regmap); 1398 + } 1399 + 1400 + i2c_set_clientdata(client, ds1307); 1341 1401 1342 1402 if (client->dev.of_node) { 1343 1403 ds1307->type = (enum ds_type) ··· 1355 1405 const struct acpi_device_id *acpi_id; 1356 1406 1357 1407 acpi_id = acpi_match_device(ACPI_PTR(ds1307_acpi_ids), 1358 - &client->dev); 1408 + ds1307->dev); 1359 1409 if (!acpi_id) 1360 1410 return -ENODEV; 1361 1411 chip = &chips[acpi_id->driver_data]; ··· 1363 1413 } 1364 1414 1365 1415 if (!pdata) 1366 - ds1307_trickle_init(client, chip); 1416 + ds1307_trickle_init(ds1307, chip); 1367 1417 else if (pdata->trickle_charger_setup) 1368 1418 chip->trickle_charger_setup = pdata->trickle_charger_setup; 1369 1419 1370 1420 if (chip->trickle_charger_setup && chip->trickle_charger_reg) { 1371 - dev_dbg(&client->dev, "writing trickle charger info 0x%x to 0x%x\n", 1421 + dev_dbg(ds1307->dev, 1422 + "writing trickle charger info 0x%x to 0x%x\n", 1372 1423 DS13XX_TRICKLE_CHARGER_MAGIC | chip->trickle_charger_setup, 1373 1424 chip->trickle_charger_reg); 1374 - i2c_smbus_write_byte_data(client, chip->trickle_charger_reg, 1425 + regmap_write(ds1307->regmap, chip->trickle_charger_reg, 1375 1426 DS13XX_TRICKLE_CHARGER_MAGIC | 1376 1427 chip->trickle_charger_setup); 1377 1428 } 1378 1429 1379 1430 buf = ds1307->regs; 1380 - if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { 1381 - ds1307->read_block_data = ds1307_native_smbus_read_block_data; 1382 - ds1307->write_block_data = ds1307_native_smbus_write_block_data; 1383 - } else { 1384 - ds1307->read_block_data = ds1307_read_block_data; 1385 - ds1307->write_block_data = ds1307_write_block_data; 1386 - } 1387 1431 1388 1432 #ifdef CONFIG_OF 1389 1433 /* ··· 1403 1459 case ds_1339: 1404 1460 case ds_3231: 1405 1461 /* get registers that the "rtc" read below won't read... */ 1406 - tmp = ds1307->read_block_data(ds1307->client, 1407 - DS1337_REG_CONTROL, 2, buf); 1408 - if (tmp != 2) { 1409 - dev_dbg(&client->dev, "read error %d\n", tmp); 1410 - err = -EIO; 1462 + err = regmap_bulk_read(ds1307->regmap, DS1337_REG_CONTROL, 1463 + buf, 2); 1464 + if (err) { 1465 + dev_dbg(ds1307->dev, "read error %d\n", err); 1411 1466 goto exit; 1412 1467 } 1413 1468 ··· 1420 1477 * For some variants, be sure alarms can trigger when we're 1421 1478 * running on Vbackup (BBSQI/BBSQW) 1422 1479 */ 1423 - if (chip->alarm && (ds1307->client->irq > 0 || 1424 - ds1307_can_wakeup_device)) { 1480 + if (chip->alarm && (ds1307->irq > 0 || 1481 + ds1307_can_wakeup_device)) { 1425 1482 ds1307->regs[0] |= DS1337_BIT_INTCN 1426 1483 | bbsqi_bitpos[ds1307->type]; 1427 1484 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); ··· 1429 1486 want_irq = true; 1430 1487 } 1431 1488 1432 - i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, 1433 - ds1307->regs[0]); 1489 + regmap_write(ds1307->regmap, DS1337_REG_CONTROL, 1490 + ds1307->regs[0]); 1434 1491 1435 1492 /* oscillator fault? clear flag, and warn */ 1436 1493 if (ds1307->regs[1] & DS1337_BIT_OSF) { 1437 - i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, 1438 - ds1307->regs[1] & ~DS1337_BIT_OSF); 1439 - dev_warn(&client->dev, "SET TIME!\n"); 1494 + regmap_write(ds1307->regmap, DS1337_REG_STATUS, 1495 + ds1307->regs[1] & ~DS1337_BIT_OSF); 1496 + dev_warn(ds1307->dev, "SET TIME!\n"); 1440 1497 } 1441 1498 break; 1442 1499 1443 1500 case rx_8025: 1444 - tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 1445 - RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 1446 - if (tmp != 2) { 1447 - dev_dbg(&client->dev, "read error %d\n", tmp); 1448 - err = -EIO; 1501 + err = regmap_bulk_read(ds1307->regmap, 1502 + RX8025_REG_CTRL1 << 4 | 0x08, buf, 2); 1503 + if (err) { 1504 + dev_dbg(ds1307->dev, "read error %d\n", err); 1449 1505 goto exit; 1450 1506 } 1451 1507 1452 1508 /* oscillator off? turn it on, so clock can tick. */ 1453 1509 if (!(ds1307->regs[1] & RX8025_BIT_XST)) { 1454 1510 ds1307->regs[1] |= RX8025_BIT_XST; 1455 - i2c_smbus_write_byte_data(client, 1456 - RX8025_REG_CTRL2 << 4 | 0x08, 1457 - ds1307->regs[1]); 1458 - dev_warn(&client->dev, 1511 + regmap_write(ds1307->regmap, 1512 + RX8025_REG_CTRL2 << 4 | 0x08, 1513 + ds1307->regs[1]); 1514 + dev_warn(ds1307->dev, 1459 1515 "oscillator stop detected - SET TIME!\n"); 1460 1516 } 1461 1517 1462 1518 if (ds1307->regs[1] & RX8025_BIT_PON) { 1463 1519 ds1307->regs[1] &= ~RX8025_BIT_PON; 1464 - i2c_smbus_write_byte_data(client, 1465 - RX8025_REG_CTRL2 << 4 | 0x08, 1466 - ds1307->regs[1]); 1467 - dev_warn(&client->dev, "power-on detected\n"); 1520 + regmap_write(ds1307->regmap, 1521 + RX8025_REG_CTRL2 << 4 | 0x08, 1522 + ds1307->regs[1]); 1523 + dev_warn(ds1307->dev, "power-on detected\n"); 1468 1524 } 1469 1525 1470 1526 if (ds1307->regs[1] & RX8025_BIT_VDET) { 1471 1527 ds1307->regs[1] &= ~RX8025_BIT_VDET; 1472 - i2c_smbus_write_byte_data(client, 1473 - RX8025_REG_CTRL2 << 4 | 0x08, 1474 - ds1307->regs[1]); 1475 - dev_warn(&client->dev, "voltage drop detected\n"); 1528 + regmap_write(ds1307->regmap, 1529 + RX8025_REG_CTRL2 << 4 | 0x08, 1530 + ds1307->regs[1]); 1531 + dev_warn(ds1307->dev, "voltage drop detected\n"); 1476 1532 } 1477 1533 1478 1534 /* make sure we are running in 24hour mode */ ··· 1479 1537 u8 hour; 1480 1538 1481 1539 /* switch to 24 hour mode */ 1482 - i2c_smbus_write_byte_data(client, 1483 - RX8025_REG_CTRL1 << 4 | 0x08, 1484 - ds1307->regs[0] | 1485 - RX8025_BIT_2412); 1540 + regmap_write(ds1307->regmap, 1541 + RX8025_REG_CTRL1 << 4 | 0x08, 1542 + ds1307->regs[0] | RX8025_BIT_2412); 1486 1543 1487 - tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 1488 - RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 1489 - if (tmp != 2) { 1490 - dev_dbg(&client->dev, "read error %d\n", tmp); 1491 - err = -EIO; 1544 + err = regmap_bulk_read(ds1307->regmap, 1545 + RX8025_REG_CTRL1 << 4 | 0x08, 1546 + buf, 2); 1547 + if (err) { 1548 + dev_dbg(ds1307->dev, "read error %d\n", err); 1492 1549 goto exit; 1493 1550 } 1494 1551 ··· 1498 1557 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) 1499 1558 hour += 12; 1500 1559 1501 - i2c_smbus_write_byte_data(client, 1502 - DS1307_REG_HOUR << 4 | 0x08, 1503 - hour); 1560 + regmap_write(ds1307->regmap, 1561 + DS1307_REG_HOUR << 4 | 0x08, hour); 1562 + } 1563 + break; 1564 + case rx_8130: 1565 + ds1307->offset = 0x10; /* Seconds starts at 0x10 */ 1566 + rtc_ops = &rx8130_rtc_ops; 1567 + if (chip->alarm && ds1307->irq > 0) { 1568 + irq_handler = rx8130_irq; 1569 + want_irq = true; 1504 1570 } 1505 1571 break; 1506 1572 case ds_1388: ··· 1515 1567 break; 1516 1568 case mcp794xx: 1517 1569 rtc_ops = &mcp794xx_rtc_ops; 1518 - if (ds1307->client->irq > 0 && chip->alarm) { 1570 + if (chip->alarm && (ds1307->irq > 0 || 1571 + ds1307_can_wakeup_device)) { 1519 1572 irq_handler = mcp794xx_irq; 1520 1573 want_irq = true; 1521 1574 } ··· 1527 1578 1528 1579 read_rtc: 1529 1580 /* read RTC registers */ 1530 - tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf); 1531 - if (tmp != 8) { 1532 - dev_dbg(&client->dev, "read error %d\n", tmp); 1533 - err = -EIO; 1581 + err = regmap_bulk_read(ds1307->regmap, ds1307->offset, buf, 8); 1582 + if (err) { 1583 + dev_dbg(ds1307->dev, "read error %d\n", err); 1534 1584 goto exit; 1535 1585 } 1536 1586 ··· 1545 1597 case m41t00: 1546 1598 /* clock halted? turn it on, so clock can tick. */ 1547 1599 if (tmp & DS1307_BIT_CH) { 1548 - i2c_smbus_write_byte_data(client, DS1307_REG_SECS, 0); 1549 - dev_warn(&client->dev, "SET TIME!\n"); 1600 + regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); 1601 + dev_warn(ds1307->dev, "SET TIME!\n"); 1550 1602 goto read_rtc; 1551 1603 } 1552 1604 break; 1605 + case ds_1308: 1553 1606 case ds_1338: 1554 1607 /* clock halted? turn it on, so clock can tick. */ 1555 1608 if (tmp & DS1307_BIT_CH) 1556 - i2c_smbus_write_byte_data(client, DS1307_REG_SECS, 0); 1609 + regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); 1557 1610 1558 1611 /* oscillator fault? clear flag, and warn */ 1559 1612 if (ds1307->regs[DS1307_REG_CONTROL] & DS1338_BIT_OSF) { 1560 - i2c_smbus_write_byte_data(client, DS1307_REG_CONTROL, 1561 - ds1307->regs[DS1307_REG_CONTROL] 1562 - & ~DS1338_BIT_OSF); 1563 - dev_warn(&client->dev, "SET TIME!\n"); 1613 + regmap_write(ds1307->regmap, DS1307_REG_CONTROL, 1614 + ds1307->regs[DS1307_REG_CONTROL] & 1615 + ~DS1338_BIT_OSF); 1616 + dev_warn(ds1307->dev, "SET TIME!\n"); 1564 1617 goto read_rtc; 1565 1618 } 1566 1619 break; 1567 1620 case ds_1340: 1568 1621 /* clock halted? turn it on, so clock can tick. */ 1569 1622 if (tmp & DS1340_BIT_nEOSC) 1570 - i2c_smbus_write_byte_data(client, DS1307_REG_SECS, 0); 1623 + regmap_write(ds1307->regmap, DS1307_REG_SECS, 0); 1571 1624 1572 - tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG); 1573 - if (tmp < 0) { 1574 - dev_dbg(&client->dev, "read error %d\n", tmp); 1575 - err = -EIO; 1625 + err = regmap_read(ds1307->regmap, DS1340_REG_FLAG, &tmp); 1626 + if (err) { 1627 + dev_dbg(ds1307->dev, "read error %d\n", err); 1576 1628 goto exit; 1577 1629 } 1578 1630 1579 1631 /* oscillator fault? clear flag, and warn */ 1580 1632 if (tmp & DS1340_BIT_OSF) { 1581 - i2c_smbus_write_byte_data(client, DS1340_REG_FLAG, 0); 1582 - dev_warn(&client->dev, "SET TIME!\n"); 1633 + regmap_write(ds1307->regmap, DS1340_REG_FLAG, 0); 1634 + dev_warn(ds1307->dev, "SET TIME!\n"); 1583 1635 } 1584 1636 break; 1585 1637 case mcp794xx: 1586 1638 /* make sure that the backup battery is enabled */ 1587 1639 if (!(ds1307->regs[DS1307_REG_WDAY] & MCP794XX_BIT_VBATEN)) { 1588 - i2c_smbus_write_byte_data(client, DS1307_REG_WDAY, 1589 - ds1307->regs[DS1307_REG_WDAY] 1590 - | MCP794XX_BIT_VBATEN); 1640 + regmap_write(ds1307->regmap, DS1307_REG_WDAY, 1641 + ds1307->regs[DS1307_REG_WDAY] | 1642 + MCP794XX_BIT_VBATEN); 1591 1643 } 1592 1644 1593 1645 /* clock halted? turn it on, so clock can tick. */ 1594 1646 if (!(tmp & MCP794XX_BIT_ST)) { 1595 - i2c_smbus_write_byte_data(client, DS1307_REG_SECS, 1596 - MCP794XX_BIT_ST); 1597 - dev_warn(&client->dev, "SET TIME!\n"); 1647 + regmap_write(ds1307->regmap, DS1307_REG_SECS, 1648 + MCP794XX_BIT_ST); 1649 + dev_warn(ds1307->dev, "SET TIME!\n"); 1598 1650 goto read_rtc; 1599 1651 } 1600 1652 ··· 1628 1680 tmp = 0; 1629 1681 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) 1630 1682 tmp += 12; 1631 - i2c_smbus_write_byte_data(client, 1632 - ds1307->offset + DS1307_REG_HOUR, 1633 - bin2bcd(tmp)); 1683 + regmap_write(ds1307->regmap, ds1307->offset + DS1307_REG_HOUR, 1684 + bin2bcd(tmp)); 1634 1685 } 1635 1686 1636 1687 /* 1637 1688 * Some IPs have weekday reset value = 0x1 which might not correct 1638 1689 * hence compute the wday using the current date/month/year values 1639 1690 */ 1640 - ds1307_get_time(&client->dev, &tm); 1691 + ds1307_get_time(ds1307->dev, &tm); 1641 1692 wday = tm.tm_wday; 1642 1693 timestamp = rtc_tm_to_time64(&tm); 1643 1694 rtc_time64_to_tm(timestamp, &tm); ··· 1646 1699 * If different then set the wday which we computed using 1647 1700 * timestamp 1648 1701 */ 1649 - if (wday != tm.tm_wday) { 1650 - wday = i2c_smbus_read_byte_data(client, MCP794XX_REG_WEEKDAY); 1651 - wday = wday & ~MCP794XX_REG_WEEKDAY_WDAY_MASK; 1652 - wday = wday | (tm.tm_wday + 1); 1653 - i2c_smbus_write_byte_data(client, MCP794XX_REG_WEEKDAY, wday); 1654 - } 1702 + if (wday != tm.tm_wday) 1703 + regmap_update_bits(ds1307->regmap, MCP794XX_REG_WEEKDAY, 1704 + MCP794XX_REG_WEEKDAY_WDAY_MASK, 1705 + tm.tm_wday + 1); 1655 1706 1656 1707 if (want_irq) { 1657 - device_set_wakeup_capable(&client->dev, true); 1708 + device_set_wakeup_capable(ds1307->dev, true); 1658 1709 set_bit(HAS_ALARM, &ds1307->flags); 1659 1710 } 1660 - ds1307->rtc = devm_rtc_device_register(&client->dev, client->name, 1661 - rtc_ops, THIS_MODULE); 1711 + 1712 + ds1307->rtc = devm_rtc_allocate_device(ds1307->dev); 1662 1713 if (IS_ERR(ds1307->rtc)) { 1663 1714 return PTR_ERR(ds1307->rtc); 1664 1715 } 1665 1716 1666 - if (ds1307_can_wakeup_device && ds1307->client->irq <= 0) { 1717 + if (ds1307_can_wakeup_device && ds1307->irq <= 0) { 1667 1718 /* Disable request for an IRQ */ 1668 1719 want_irq = false; 1669 - dev_info(&client->dev, "'wakeup-source' is set, request for an IRQ is disabled!\n"); 1720 + dev_info(ds1307->dev, 1721 + "'wakeup-source' is set, request for an IRQ is disabled!\n"); 1670 1722 /* We cannot support UIE mode if we do not have an IRQ line */ 1671 1723 ds1307->rtc->uie_unsupported = 1; 1672 1724 } 1673 1725 1674 1726 if (want_irq) { 1675 - err = devm_request_threaded_irq(&client->dev, 1676 - client->irq, NULL, irq_handler, 1727 + err = devm_request_threaded_irq(ds1307->dev, 1728 + ds1307->irq, NULL, irq_handler, 1677 1729 IRQF_SHARED | IRQF_ONESHOT, 1678 - ds1307->rtc->name, client); 1730 + ds1307->name, ds1307); 1679 1731 if (err) { 1680 1732 client->irq = 0; 1681 - device_set_wakeup_capable(&client->dev, false); 1733 + device_set_wakeup_capable(ds1307->dev, false); 1682 1734 clear_bit(HAS_ALARM, &ds1307->flags); 1683 - dev_err(&client->dev, "unable to request IRQ!\n"); 1735 + dev_err(ds1307->dev, "unable to request IRQ!\n"); 1684 1736 } else 1685 - dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 1737 + dev_dbg(ds1307->dev, "got IRQ %d\n", client->irq); 1686 1738 } 1687 1739 1688 1740 if (chip->nvram_size) { 1741 + ds1307->nvmem_cfg.name = "ds1307_nvram"; 1742 + ds1307->nvmem_cfg.word_size = 1; 1743 + ds1307->nvmem_cfg.stride = 1; 1744 + ds1307->nvmem_cfg.size = chip->nvram_size; 1745 + ds1307->nvmem_cfg.reg_read = ds1307_nvram_read; 1746 + ds1307->nvmem_cfg.reg_write = ds1307_nvram_write; 1747 + ds1307->nvmem_cfg.priv = ds1307; 1748 + ds1307->nvram_offset = chip->nvram_offset; 1689 1749 1690 - ds1307->nvram = devm_kzalloc(&client->dev, 1691 - sizeof(struct bin_attribute), 1692 - GFP_KERNEL); 1693 - if (!ds1307->nvram) { 1694 - dev_err(&client->dev, "cannot allocate memory for nvram sysfs\n"); 1695 - } else { 1696 - 1697 - ds1307->nvram->attr.name = "nvram"; 1698 - ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 1699 - 1700 - sysfs_bin_attr_init(ds1307->nvram); 1701 - 1702 - ds1307->nvram->read = ds1307_nvram_read; 1703 - ds1307->nvram->write = ds1307_nvram_write; 1704 - ds1307->nvram->size = chip->nvram_size; 1705 - ds1307->nvram_offset = chip->nvram_offset; 1706 - 1707 - err = sysfs_create_bin_file(&client->dev.kobj, 1708 - ds1307->nvram); 1709 - if (err) { 1710 - dev_err(&client->dev, 1711 - "unable to create sysfs file: %s\n", 1712 - ds1307->nvram->attr.name); 1713 - } else { 1714 - set_bit(HAS_NVRAM, &ds1307->flags); 1715 - dev_info(&client->dev, "%zu bytes nvram\n", 1716 - ds1307->nvram->size); 1717 - } 1718 - } 1750 + ds1307->rtc->nvmem_config = &ds1307->nvmem_cfg; 1751 + ds1307->rtc->nvram_old_abi = true; 1719 1752 } 1753 + 1754 + ds1307->rtc->ops = rtc_ops; 1755 + err = rtc_register_device(ds1307->rtc); 1756 + if (err) 1757 + return err; 1720 1758 1721 1759 ds1307_hwmon_register(ds1307); 1722 1760 ds1307_clks_register(ds1307); ··· 1712 1780 return err; 1713 1781 } 1714 1782 1715 - static int ds1307_remove(struct i2c_client *client) 1716 - { 1717 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 1718 - 1719 - if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) 1720 - sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); 1721 - 1722 - return 0; 1723 - } 1724 - 1725 1783 static struct i2c_driver ds1307_driver = { 1726 1784 .driver = { 1727 1785 .name = "rtc-ds1307", ··· 1719 1797 .acpi_match_table = ACPI_PTR(ds1307_acpi_ids), 1720 1798 }, 1721 1799 .probe = ds1307_probe, 1722 - .remove = ds1307_remove, 1723 1800 .id_table = ds1307_id, 1724 1801 }; 1725 1802
+119
drivers/rtc/rtc-ds3232.c
··· 22 22 #include <linux/bcd.h> 23 23 #include <linux/slab.h> 24 24 #include <linux/regmap.h> 25 + #include <linux/hwmon.h> 25 26 26 27 #define DS3232_REG_SECONDS 0x00 27 28 #define DS3232_REG_MINUTES 0x01 ··· 46 45 # define DS3232_REG_SR_BSY 0x04 47 46 # define DS3232_REG_SR_A2F 0x02 48 47 # define DS3232_REG_SR_A1F 0x01 48 + 49 + #define DS3232_REG_TEMPERATURE 0x11 49 50 50 51 struct ds3232 { 51 52 struct device *dev; ··· 278 275 return ret; 279 276 } 280 277 278 + /* 279 + * Temperature sensor support for ds3232/ds3234 devices. 280 + * A user-initiated temperature conversion is not started by this function, 281 + * so the temperature is updated once every 64 seconds. 282 + */ 283 + static int ds3232_hwmon_read_temp(struct device *dev, long int *mC) 284 + { 285 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 286 + u8 temp_buf[2]; 287 + s16 temp; 288 + int ret; 289 + 290 + ret = regmap_bulk_read(ds3232->regmap, DS3232_REG_TEMPERATURE, temp_buf, 291 + sizeof(temp_buf)); 292 + if (ret < 0) 293 + return ret; 294 + 295 + /* 296 + * Temperature is represented as a 10-bit code with a resolution of 297 + * 0.25 degree celsius and encoded in two's complement format. 298 + */ 299 + temp = (temp_buf[0] << 8) | temp_buf[1]; 300 + temp >>= 6; 301 + *mC = temp * 250; 302 + 303 + return 0; 304 + } 305 + 306 + static umode_t ds3232_hwmon_is_visible(const void *data, 307 + enum hwmon_sensor_types type, 308 + u32 attr, int channel) 309 + { 310 + if (type != hwmon_temp) 311 + return 0; 312 + 313 + switch (attr) { 314 + case hwmon_temp_input: 315 + return 0444; 316 + default: 317 + return 0; 318 + } 319 + } 320 + 321 + static int ds3232_hwmon_read(struct device *dev, 322 + enum hwmon_sensor_types type, 323 + u32 attr, int channel, long *temp) 324 + { 325 + int err; 326 + 327 + switch (attr) { 328 + case hwmon_temp_input: 329 + err = ds3232_hwmon_read_temp(dev, temp); 330 + break; 331 + default: 332 + err = -EOPNOTSUPP; 333 + break; 334 + } 335 + 336 + return err; 337 + } 338 + 339 + static u32 ds3232_hwmon_chip_config[] = { 340 + HWMON_C_REGISTER_TZ, 341 + 0 342 + }; 343 + 344 + static const struct hwmon_channel_info ds3232_hwmon_chip = { 345 + .type = hwmon_chip, 346 + .config = ds3232_hwmon_chip_config, 347 + }; 348 + 349 + static u32 ds3232_hwmon_temp_config[] = { 350 + HWMON_T_INPUT, 351 + 0 352 + }; 353 + 354 + static const struct hwmon_channel_info ds3232_hwmon_temp = { 355 + .type = hwmon_temp, 356 + .config = ds3232_hwmon_temp_config, 357 + }; 358 + 359 + static const struct hwmon_channel_info *ds3232_hwmon_info[] = { 360 + &ds3232_hwmon_chip, 361 + &ds3232_hwmon_temp, 362 + NULL 363 + }; 364 + 365 + static const struct hwmon_ops ds3232_hwmon_hwmon_ops = { 366 + .is_visible = ds3232_hwmon_is_visible, 367 + .read = ds3232_hwmon_read, 368 + }; 369 + 370 + static const struct hwmon_chip_info ds3232_hwmon_chip_info = { 371 + .ops = &ds3232_hwmon_hwmon_ops, 372 + .info = ds3232_hwmon_info, 373 + }; 374 + 375 + static void ds3232_hwmon_register(struct device *dev, const char *name) 376 + { 377 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 378 + struct device *hwmon_dev; 379 + 380 + if (!IS_ENABLED(CONFIG_RTC_DRV_DS3232_HWMON)) 381 + return; 382 + 383 + hwmon_dev = devm_hwmon_device_register_with_info(dev, name, ds3232, 384 + &ds3232_hwmon_chip_info, 385 + NULL); 386 + if (IS_ERR(hwmon_dev)) { 387 + dev_err(dev, "unable to register hwmon device %ld\n", 388 + PTR_ERR(hwmon_dev)); 389 + } 390 + } 391 + 281 392 static int ds3232_alarm_irq_enable(struct device *dev, unsigned int enabled) 282 393 { 283 394 struct ds3232 *ds3232 = dev_get_drvdata(dev); ··· 482 365 483 366 if (ds3232->irq > 0) 484 367 device_init_wakeup(dev, 1); 368 + 369 + ds3232_hwmon_register(dev, name); 485 370 486 371 ds3232->rtc = devm_rtc_device_register(dev, name, &ds3232_rtc_ops, 487 372 THIS_MODULE);
+74 -45
drivers/rtc/rtc-gemini.c drivers/rtc/rtc-ftrtc010.c
··· 1 1 /* 2 - * Gemini OnChip RTC 2 + * Faraday Technology FTRTC010 driver 3 3 * 4 4 * Copyright (C) 2009 Janos Laube <janos.dev@gmail.com> 5 5 * ··· 26 26 #include <linux/platform_device.h> 27 27 #include <linux/kernel.h> 28 28 #include <linux/module.h> 29 + #include <linux/clk.h> 29 30 30 - #define DRV_NAME "rtc-gemini" 31 + #define DRV_NAME "rtc-ftrtc010" 31 32 32 33 MODULE_AUTHOR("Hans Ulli Kroll <ulli.kroll@googlemail.com>"); 33 34 MODULE_DESCRIPTION("RTC driver for Gemini SoC"); 34 35 MODULE_LICENSE("GPL"); 35 36 MODULE_ALIAS("platform:" DRV_NAME); 36 37 37 - struct gemini_rtc { 38 + struct ftrtc010_rtc { 38 39 struct rtc_device *rtc_dev; 39 40 void __iomem *rtc_base; 40 41 int rtc_irq; 42 + struct clk *pclk; 43 + struct clk *extclk; 41 44 }; 42 45 43 - enum gemini_rtc_offsets { 44 - GEMINI_RTC_SECOND = 0x00, 45 - GEMINI_RTC_MINUTE = 0x04, 46 - GEMINI_RTC_HOUR = 0x08, 47 - GEMINI_RTC_DAYS = 0x0C, 48 - GEMINI_RTC_ALARM_SECOND = 0x10, 49 - GEMINI_RTC_ALARM_MINUTE = 0x14, 50 - GEMINI_RTC_ALARM_HOUR = 0x18, 51 - GEMINI_RTC_RECORD = 0x1C, 52 - GEMINI_RTC_CR = 0x20 46 + enum ftrtc010_rtc_offsets { 47 + FTRTC010_RTC_SECOND = 0x00, 48 + FTRTC010_RTC_MINUTE = 0x04, 49 + FTRTC010_RTC_HOUR = 0x08, 50 + FTRTC010_RTC_DAYS = 0x0C, 51 + FTRTC010_RTC_ALARM_SECOND = 0x10, 52 + FTRTC010_RTC_ALARM_MINUTE = 0x14, 53 + FTRTC010_RTC_ALARM_HOUR = 0x18, 54 + FTRTC010_RTC_RECORD = 0x1C, 55 + FTRTC010_RTC_CR = 0x20, 53 56 }; 54 57 55 - static irqreturn_t gemini_rtc_interrupt(int irq, void *dev) 58 + static irqreturn_t ftrtc010_rtc_interrupt(int irq, void *dev) 56 59 { 57 60 return IRQ_HANDLED; 58 61 } ··· 69 66 * the same thing, without the rtc-lib.c calls. 70 67 */ 71 68 72 - static int gemini_rtc_read_time(struct device *dev, struct rtc_time *tm) 69 + static int ftrtc010_rtc_read_time(struct device *dev, struct rtc_time *tm) 73 70 { 74 - struct gemini_rtc *rtc = dev_get_drvdata(dev); 71 + struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); 75 72 76 73 unsigned int days, hour, min, sec; 77 74 unsigned long offset, time; 78 75 79 - sec = readl(rtc->rtc_base + GEMINI_RTC_SECOND); 80 - min = readl(rtc->rtc_base + GEMINI_RTC_MINUTE); 81 - hour = readl(rtc->rtc_base + GEMINI_RTC_HOUR); 82 - days = readl(rtc->rtc_base + GEMINI_RTC_DAYS); 83 - offset = readl(rtc->rtc_base + GEMINI_RTC_RECORD); 76 + sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); 77 + min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); 78 + hour = readl(rtc->rtc_base + FTRTC010_RTC_HOUR); 79 + days = readl(rtc->rtc_base + FTRTC010_RTC_DAYS); 80 + offset = readl(rtc->rtc_base + FTRTC010_RTC_RECORD); 84 81 85 82 time = offset + days * 86400 + hour * 3600 + min * 60 + sec; 86 83 ··· 89 86 return 0; 90 87 } 91 88 92 - static int gemini_rtc_set_time(struct device *dev, struct rtc_time *tm) 89 + static int ftrtc010_rtc_set_time(struct device *dev, struct rtc_time *tm) 93 90 { 94 - struct gemini_rtc *rtc = dev_get_drvdata(dev); 91 + struct ftrtc010_rtc *rtc = dev_get_drvdata(dev); 95 92 unsigned int sec, min, hour, day; 96 93 unsigned long offset, time; 97 94 ··· 100 97 101 98 rtc_tm_to_time(tm, &time); 102 99 103 - sec = readl(rtc->rtc_base + GEMINI_RTC_SECOND); 104 - min = readl(rtc->rtc_base + GEMINI_RTC_MINUTE); 105 - hour = readl(rtc->rtc_base + GEMINI_RTC_HOUR); 106 - day = readl(rtc->rtc_base + GEMINI_RTC_DAYS); 100 + sec = readl(rtc->rtc_base + FTRTC010_RTC_SECOND); 101 + min = readl(rtc->rtc_base + FTRTC010_RTC_MINUTE); 102 + hour = readl(rtc->rtc_base + FTRTC010_RTC_HOUR); 103 + day = readl(rtc->rtc_base + FTRTC010_RTC_DAYS); 107 104 108 105 offset = time - (day * 86400 + hour * 3600 + min * 60 + sec); 109 106 110 - writel(offset, rtc->rtc_base + GEMINI_RTC_RECORD); 111 - writel(0x01, rtc->rtc_base + GEMINI_RTC_CR); 107 + writel(offset, rtc->rtc_base + FTRTC010_RTC_RECORD); 108 + writel(0x01, rtc->rtc_base + FTRTC010_RTC_CR); 112 109 113 110 return 0; 114 111 } 115 112 116 - static const struct rtc_class_ops gemini_rtc_ops = { 117 - .read_time = gemini_rtc_read_time, 118 - .set_time = gemini_rtc_set_time, 113 + static const struct rtc_class_ops ftrtc010_rtc_ops = { 114 + .read_time = ftrtc010_rtc_read_time, 115 + .set_time = ftrtc010_rtc_set_time, 119 116 }; 120 117 121 - static int gemini_rtc_probe(struct platform_device *pdev) 118 + static int ftrtc010_rtc_probe(struct platform_device *pdev) 122 119 { 123 - struct gemini_rtc *rtc; 120 + struct ftrtc010_rtc *rtc; 124 121 struct device *dev = &pdev->dev; 125 122 struct resource *res; 126 123 int ret; ··· 129 126 if (unlikely(!rtc)) 130 127 return -ENOMEM; 131 128 platform_set_drvdata(pdev, rtc); 129 + 130 + rtc->pclk = devm_clk_get(dev, "PCLK"); 131 + if (IS_ERR(rtc->pclk)) { 132 + dev_err(dev, "could not get PCLK\n"); 133 + } else { 134 + ret = clk_prepare_enable(rtc->pclk); 135 + if (ret) { 136 + dev_err(dev, "failed to enable PCLK\n"); 137 + return ret; 138 + } 139 + } 140 + rtc->extclk = devm_clk_get(dev, "EXTCLK"); 141 + if (IS_ERR(rtc->extclk)) { 142 + dev_err(dev, "could not get EXTCLK\n"); 143 + } else { 144 + ret = clk_prepare_enable(rtc->extclk); 145 + if (ret) { 146 + dev_err(dev, "failed to enable EXTCLK\n"); 147 + return ret; 148 + } 149 + } 132 150 133 151 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 134 152 if (!res) ··· 166 142 if (!rtc->rtc_base) 167 143 return -ENOMEM; 168 144 169 - ret = devm_request_irq(dev, rtc->rtc_irq, gemini_rtc_interrupt, 145 + ret = devm_request_irq(dev, rtc->rtc_irq, ftrtc010_rtc_interrupt, 170 146 IRQF_SHARED, pdev->name, dev); 171 147 if (unlikely(ret)) 172 148 return ret; 173 149 174 150 rtc->rtc_dev = rtc_device_register(pdev->name, dev, 175 - &gemini_rtc_ops, THIS_MODULE); 151 + &ftrtc010_rtc_ops, THIS_MODULE); 176 152 return PTR_ERR_OR_ZERO(rtc->rtc_dev); 177 153 } 178 154 179 - static int gemini_rtc_remove(struct platform_device *pdev) 155 + static int ftrtc010_rtc_remove(struct platform_device *pdev) 180 156 { 181 - struct gemini_rtc *rtc = platform_get_drvdata(pdev); 157 + struct ftrtc010_rtc *rtc = platform_get_drvdata(pdev); 182 158 159 + if (!IS_ERR(rtc->extclk)) 160 + clk_disable_unprepare(rtc->extclk); 161 + if (!IS_ERR(rtc->pclk)) 162 + clk_disable_unprepare(rtc->pclk); 183 163 rtc_device_unregister(rtc->rtc_dev); 184 164 185 165 return 0; 186 166 } 187 167 188 - static const struct of_device_id gemini_rtc_dt_match[] = { 168 + static const struct of_device_id ftrtc010_rtc_dt_match[] = { 189 169 { .compatible = "cortina,gemini-rtc" }, 170 + { .compatible = "faraday,ftrtc010" }, 190 171 { } 191 172 }; 192 - MODULE_DEVICE_TABLE(of, gemini_rtc_dt_match); 173 + MODULE_DEVICE_TABLE(of, ftrtc010_rtc_dt_match); 193 174 194 - static struct platform_driver gemini_rtc_driver = { 175 + static struct platform_driver ftrtc010_rtc_driver = { 195 176 .driver = { 196 177 .name = DRV_NAME, 197 - .of_match_table = gemini_rtc_dt_match, 178 + .of_match_table = ftrtc010_rtc_dt_match, 198 179 }, 199 - .probe = gemini_rtc_probe, 200 - .remove = gemini_rtc_remove, 180 + .probe = ftrtc010_rtc_probe, 181 + .remove = ftrtc010_rtc_remove, 201 182 }; 202 183 203 - module_platform_driver_probe(gemini_rtc_driver, gemini_rtc_probe); 184 + module_platform_driver_probe(ftrtc010_rtc_driver, ftrtc010_rtc_probe);
+187 -88
drivers/rtc/rtc-m41t80.c
··· 16 16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 17 18 18 #include <linux/bcd.h> 19 + #include <linux/clk-provider.h> 19 20 #include <linux/i2c.h> 20 21 #include <linux/init.h> 21 22 #include <linux/kernel.h> ··· 53 52 #define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1) 54 53 #define M41T80_ALARM_REG_SIZE \ 55 54 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON) 55 + 56 + #define M41T80_SQW_MAX_FREQ 32768 56 57 57 58 #define M41T80_SEC_ST BIT(7) /* ST: Stop Bit */ 58 59 #define M41T80_ALMON_AFE BIT(7) /* AFE: AF Enable Bit */ ··· 150 147 151 148 struct m41t80_data { 152 149 unsigned long features; 150 + struct i2c_client *client; 153 151 struct rtc_device *rtc; 152 + #ifdef CONFIG_COMMON_CLK 153 + struct clk_hw sqw; 154 + #endif 154 155 }; 155 156 156 157 static irqreturn_t m41t80_handle_irq(int irq, void *dev_id) ··· 234 227 /* Sets the given date and time to the real time clock. */ 235 228 static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) 236 229 { 230 + struct m41t80_data *clientdata = i2c_get_clientdata(client); 237 231 unsigned char buf[8]; 238 232 int err, flags; 239 233 ··· 249 241 buf[M41T80_REG_MON] = bin2bcd(tm->tm_mon + 1); 250 242 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year - 100); 251 243 buf[M41T80_REG_WDAY] = tm->tm_wday; 244 + 245 + /* If the square wave output is controlled in the weekday register */ 246 + if (clientdata->features & M41T80_FEATURE_SQ_ALT) { 247 + int val; 248 + 249 + val = i2c_smbus_read_byte_data(client, M41T80_REG_WDAY); 250 + if (val < 0) 251 + return val; 252 + 253 + buf[M41T80_REG_WDAY] |= (val & 0xf0); 254 + } 252 255 253 256 err = i2c_smbus_write_i2c_block_data(client, M41T80_REG_SSEC, 254 257 sizeof(buf), buf); ··· 350 331 dev_err(dev, "Unable to clear AFE bit\n"); 351 332 return err; 352 333 } 334 + 335 + /* Keep SQWE bit value */ 336 + alarmvals[0] |= (ret & M41T80_ALMON_SQWE); 353 337 354 338 ret = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); 355 339 if (ret < 0) ··· 453 431 } 454 432 static DEVICE_ATTR_RO(flags); 455 433 456 - static ssize_t sqwfreq_show(struct device *dev, 457 - struct device_attribute *attr, char *buf) 458 - { 459 - struct i2c_client *client = to_i2c_client(dev); 460 - struct m41t80_data *clientdata = i2c_get_clientdata(client); 461 - int val, reg_sqw; 462 - 463 - if (!(clientdata->features & M41T80_FEATURE_SQ)) 464 - return -EINVAL; 465 - 466 - reg_sqw = M41T80_REG_SQW; 467 - if (clientdata->features & M41T80_FEATURE_SQ_ALT) 468 - reg_sqw = M41T80_REG_WDAY; 469 - val = i2c_smbus_read_byte_data(client, reg_sqw); 470 - if (val < 0) 471 - return val; 472 - val = (val >> 4) & 0xf; 473 - switch (val) { 474 - case 0: 475 - break; 476 - case 1: 477 - val = 32768; 478 - break; 479 - default: 480 - val = 32768 >> val; 481 - } 482 - return sprintf(buf, "%d\n", val); 483 - } 484 - 485 - static ssize_t sqwfreq_store(struct device *dev, 486 - struct device_attribute *attr, 487 - const char *buf, size_t count) 488 - { 489 - struct i2c_client *client = to_i2c_client(dev); 490 - struct m41t80_data *clientdata = i2c_get_clientdata(client); 491 - int almon, sqw, reg_sqw, rc; 492 - unsigned long val; 493 - 494 - rc = kstrtoul(buf, 0, &val); 495 - if (rc < 0) 496 - return rc; 497 - 498 - if (!(clientdata->features & M41T80_FEATURE_SQ)) 499 - return -EINVAL; 500 - 501 - if (val) { 502 - if (!is_power_of_2(val)) 503 - return -EINVAL; 504 - val = ilog2(val); 505 - if (val == 15) 506 - val = 1; 507 - else if (val < 14) 508 - val = 15 - val; 509 - else 510 - return -EINVAL; 511 - } 512 - /* disable SQW, set SQW frequency & re-enable */ 513 - almon = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); 514 - if (almon < 0) 515 - return almon; 516 - reg_sqw = M41T80_REG_SQW; 517 - if (clientdata->features & M41T80_FEATURE_SQ_ALT) 518 - reg_sqw = M41T80_REG_WDAY; 519 - sqw = i2c_smbus_read_byte_data(client, reg_sqw); 520 - if (sqw < 0) 521 - return sqw; 522 - sqw = (sqw & 0x0f) | (val << 4); 523 - 524 - rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, 525 - almon & ~M41T80_ALMON_SQWE); 526 - if (rc < 0) 527 - return rc; 528 - 529 - if (val) { 530 - rc = i2c_smbus_write_byte_data(client, reg_sqw, sqw); 531 - if (rc < 0) 532 - return rc; 533 - 534 - rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, 535 - almon | M41T80_ALMON_SQWE); 536 - if (rc < 0) 537 - return rc; 538 - } 539 - return count; 540 - } 541 - static DEVICE_ATTR_RW(sqwfreq); 542 - 543 434 static struct attribute *attrs[] = { 544 435 &dev_attr_flags.attr, 545 - &dev_attr_sqwfreq.attr, 546 436 NULL, 547 437 }; 548 438 549 439 static struct attribute_group attr_group = { 550 440 .attrs = attrs, 551 441 }; 442 + 443 + #ifdef CONFIG_COMMON_CLK 444 + #define sqw_to_m41t80_data(_hw) container_of(_hw, struct m41t80_data, sqw) 445 + 446 + static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw, 447 + unsigned long parent_rate) 448 + { 449 + struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 450 + struct i2c_client *client = m41t80->client; 451 + int reg_sqw = (m41t80->features & M41T80_FEATURE_SQ_ALT) ? 452 + M41T80_REG_WDAY : M41T80_REG_SQW; 453 + int ret = i2c_smbus_read_byte_data(client, reg_sqw); 454 + unsigned long val = M41T80_SQW_MAX_FREQ; 455 + 456 + if (ret < 0) 457 + return 0; 458 + 459 + ret >>= 4; 460 + if (ret == 0) 461 + val = 0; 462 + else if (ret > 1) 463 + val = val / (1 << ret); 464 + 465 + return val; 466 + } 467 + 468 + static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate, 469 + unsigned long *prate) 470 + { 471 + int i, freq = M41T80_SQW_MAX_FREQ; 472 + 473 + if (freq <= rate) 474 + return freq; 475 + 476 + for (i = 2; i <= ilog2(M41T80_SQW_MAX_FREQ); i++) { 477 + freq /= 1 << i; 478 + if (freq <= rate) 479 + return freq; 480 + } 481 + 482 + return 0; 483 + } 484 + 485 + static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate, 486 + unsigned long parent_rate) 487 + { 488 + struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 489 + struct i2c_client *client = m41t80->client; 490 + int reg_sqw = (m41t80->features & M41T80_FEATURE_SQ_ALT) ? 491 + M41T80_REG_WDAY : M41T80_REG_SQW; 492 + int reg, ret, val = 0; 493 + 494 + if (rate) { 495 + if (!is_power_of_2(rate)) 496 + return -EINVAL; 497 + val = ilog2(rate); 498 + if (val == ilog2(M41T80_SQW_MAX_FREQ)) 499 + val = 1; 500 + else if (val < (ilog2(M41T80_SQW_MAX_FREQ) - 1)) 501 + val = ilog2(M41T80_SQW_MAX_FREQ) - val; 502 + else 503 + return -EINVAL; 504 + } 505 + 506 + reg = i2c_smbus_read_byte_data(client, reg_sqw); 507 + if (reg < 0) 508 + return reg; 509 + 510 + reg = (reg & 0x0f) | (val << 4); 511 + 512 + ret = i2c_smbus_write_byte_data(client, reg_sqw, reg); 513 + if (ret < 0) 514 + return ret; 515 + 516 + return -EINVAL; 517 + } 518 + 519 + static int m41t80_sqw_control(struct clk_hw *hw, bool enable) 520 + { 521 + struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 522 + struct i2c_client *client = m41t80->client; 523 + int ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); 524 + 525 + if (ret < 0) 526 + return ret; 527 + 528 + if (enable) 529 + ret |= M41T80_ALMON_SQWE; 530 + else 531 + ret &= ~M41T80_ALMON_SQWE; 532 + 533 + return i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, ret); 534 + } 535 + 536 + static int m41t80_sqw_prepare(struct clk_hw *hw) 537 + { 538 + return m41t80_sqw_control(hw, 1); 539 + } 540 + 541 + static void m41t80_sqw_unprepare(struct clk_hw *hw) 542 + { 543 + m41t80_sqw_control(hw, 0); 544 + } 545 + 546 + static int m41t80_sqw_is_prepared(struct clk_hw *hw) 547 + { 548 + struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 549 + struct i2c_client *client = m41t80->client; 550 + int ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); 551 + 552 + if (ret < 0) 553 + return ret; 554 + 555 + return !!(ret & M41T80_ALMON_SQWE); 556 + } 557 + 558 + static const struct clk_ops m41t80_sqw_ops = { 559 + .prepare = m41t80_sqw_prepare, 560 + .unprepare = m41t80_sqw_unprepare, 561 + .is_prepared = m41t80_sqw_is_prepared, 562 + .recalc_rate = m41t80_sqw_recalc_rate, 563 + .round_rate = m41t80_sqw_round_rate, 564 + .set_rate = m41t80_sqw_set_rate, 565 + }; 566 + 567 + static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80) 568 + { 569 + struct i2c_client *client = m41t80->client; 570 + struct device_node *node = client->dev.of_node; 571 + struct clk *clk; 572 + struct clk_init_data init; 573 + int ret; 574 + 575 + /* First disable the clock */ 576 + ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); 577 + if (ret < 0) 578 + return ERR_PTR(ret); 579 + ret = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, 580 + ret & ~(M41T80_ALMON_SQWE)); 581 + if (ret < 0) 582 + return ERR_PTR(ret); 583 + 584 + init.name = "m41t80-sqw"; 585 + init.ops = &m41t80_sqw_ops; 586 + init.flags = 0; 587 + init.parent_names = NULL; 588 + init.num_parents = 0; 589 + m41t80->sqw.init = &init; 590 + 591 + /* optional override of the clockname */ 592 + of_property_read_string(node, "clock-output-names", &init.name); 593 + 594 + /* register the clock */ 595 + clk = clk_register(&client->dev, &m41t80->sqw); 596 + if (!IS_ERR(clk)) 597 + of_clk_add_provider(node, of_clk_src_simple_get, clk); 598 + 599 + return clk; 600 + } 601 + #endif 552 602 553 603 #ifdef CONFIG_RTC_DRV_M41T80_WDT 554 604 /* ··· 939 845 if (!m41t80_data) 940 846 return -ENOMEM; 941 847 848 + m41t80_data->client = client; 942 849 if (client->dev.of_node) 943 850 m41t80_data->features = (unsigned long) 944 851 of_device_get_match_data(&client->dev); ··· 1031 936 return rc; 1032 937 } 1033 938 } 939 + #endif 940 + #ifdef CONFIG_COMMON_CLK 941 + if (m41t80_data->features & M41T80_FEATURE_SQ) 942 + m41t80_sqw_register_clk(m41t80_data); 1034 943 #endif 1035 944 return 0; 1036 945 }
-11
drivers/rtc/rtc-mxc.c
··· 43 43 44 44 #define MAX_PIE_NUM 9 45 45 #define MAX_PIE_FREQ 512 46 - static const u32 PIE_BIT_DEF[MAX_PIE_NUM][2] = { 47 - { 2, RTC_2HZ_BIT }, 48 - { 4, RTC_SAM0_BIT }, 49 - { 8, RTC_SAM1_BIT }, 50 - { 16, RTC_SAM2_BIT }, 51 - { 32, RTC_SAM3_BIT }, 52 - { 64, RTC_SAM4_BIT }, 53 - { 128, RTC_SAM5_BIT }, 54 - { 256, RTC_SAM6_BIT }, 55 - { MAX_PIE_FREQ, RTC_SAM7_BIT }, 56 - }; 57 46 58 47 #define MXC_RTC_TIME 0 59 48 #define MXC_RTC_ALARM 1
+1 -1
drivers/rtc/rtc-nuc900.c
··· 93 93 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER); 94 94 95 95 while (!(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) 96 - && timeout--) 96 + && --timeout) 97 97 mdelay(1); 98 98 99 99 if (!timeout)
+31 -1
drivers/rtc/rtc-opal.c
··· 142 142 143 143 y_m_d = be32_to_cpu(__y_m_d); 144 144 h_m_s_ms = ((u64)be32_to_cpu(__h_m) << 32); 145 + 146 + /* check if no alarm is set */ 147 + if (y_m_d == 0 && h_m_s_ms == 0) { 148 + pr_debug("No alarm is set\n"); 149 + rc = -ENOENT; 150 + goto exit; 151 + } else { 152 + pr_debug("Alarm set to %x %llx\n", y_m_d, h_m_s_ms); 153 + } 154 + 145 155 opal_to_tm(y_m_d, h_m_s_ms, &alarm->time); 146 156 147 157 exit: ··· 167 157 u32 y_m_d = 0; 168 158 int token, rc; 169 159 170 - tm_to_opal(&alarm->time, &y_m_d, &h_m_s_ms); 160 + /* if alarm is enabled */ 161 + if (alarm->enabled) { 162 + tm_to_opal(&alarm->time, &y_m_d, &h_m_s_ms); 163 + pr_debug("Alarm set to %x %llx\n", y_m_d, h_m_s_ms); 164 + 165 + } else { 166 + pr_debug("Alarm getting disabled\n"); 167 + } 171 168 172 169 token = opal_async_get_token_interruptible(); 173 170 if (token < 0) { ··· 207 190 return rc; 208 191 } 209 192 193 + int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled) 194 + { 195 + struct rtc_wkalrm alarm = { .enabled = 0 }; 196 + 197 + /* 198 + * TPO is automatically enabled when opal_set_tpo_time() is called with 199 + * non-zero rtc-time. We only handle disable case which needs to be 200 + * explicitly told to opal. 201 + */ 202 + return enabled ? 0 : opal_set_tpo_time(dev, &alarm); 203 + } 204 + 210 205 static struct rtc_class_ops opal_rtc_ops = { 211 206 .read_time = opal_get_rtc_time, 212 207 .set_time = opal_set_rtc_time, ··· 234 205 device_set_wakeup_capable(&pdev->dev, true); 235 206 opal_rtc_ops.read_alarm = opal_get_tpo_time; 236 207 opal_rtc_ops.set_alarm = opal_set_tpo_time; 208 + opal_rtc_ops.alarm_irq_enable = opal_tpo_alarm_irq_enable; 237 209 } 238 210 239 211 rtc = devm_rtc_device_register(&pdev->dev, DRVNAME, &opal_rtc_ops,
+1 -1
drivers/rtc/rtc-pcf8563.c
··· 606 606 err = devm_request_threaded_irq(&client->dev, client->irq, 607 607 NULL, pcf8563_irq, 608 608 IRQF_SHARED|IRQF_ONESHOT|IRQF_TRIGGER_FALLING, 609 - pcf8563->rtc->name, client); 609 + pcf8563_driver.driver.name, client); 610 610 if (err) { 611 611 dev_err(&client->dev, "unable to request IRQ %d\n", 612 612 client->irq);
+29 -43
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; 71 72 }; 72 73 73 74 static int rv8803_read_reg(const struct i2c_client *client, u8 reg) ··· 461 460 } 462 461 } 463 462 464 - static ssize_t rv8803_nvram_write(struct file *filp, struct kobject *kobj, 465 - struct bin_attribute *attr, 466 - char *buf, loff_t off, size_t count) 463 + static int rv8803_nvram_write(void *priv, unsigned int offset, void *val, 464 + size_t bytes) 467 465 { 468 - struct device *dev = kobj_to_dev(kobj); 469 - struct i2c_client *client = to_i2c_client(dev); 470 466 int ret; 471 467 472 - ret = rv8803_write_reg(client, RV8803_RAM, buf[0]); 468 + ret = rv8803_write_reg(priv, RV8803_RAM, *(u8 *)val); 473 469 if (ret) 474 470 return ret; 475 471 476 - return 1; 472 + return 0; 477 473 } 478 474 479 - static ssize_t rv8803_nvram_read(struct file *filp, struct kobject *kobj, 480 - struct bin_attribute *attr, 481 - char *buf, loff_t off, size_t count) 475 + static int rv8803_nvram_read(void *priv, unsigned int offset, 476 + void *val, size_t bytes) 482 477 { 483 - struct device *dev = kobj_to_dev(kobj); 484 - struct i2c_client *client = to_i2c_client(dev); 485 478 int ret; 486 479 487 - ret = rv8803_read_reg(client, RV8803_RAM); 480 + ret = rv8803_read_reg(priv, RV8803_RAM); 488 481 if (ret < 0) 489 482 return ret; 490 483 491 - buf[0] = ret; 484 + *(u8 *)val = ret; 492 485 493 - return 1; 486 + return 0; 494 487 } 495 - 496 - static struct bin_attribute rv8803_nvram_attr = { 497 - .attr = { 498 - .name = "nvram", 499 - .mode = S_IRUGO | S_IWUSR, 500 - }, 501 - .size = 1, 502 - .read = rv8803_nvram_read, 503 - .write = rv8803_nvram_write, 504 - }; 505 488 506 489 static struct rtc_class_ops rv8803_rtc_ops = { 507 490 .read_time = rv8803_get_time, ··· 562 577 if (flags & RV8803_FLAG_AF) 563 578 dev_warn(&client->dev, "An alarm maybe have been missed.\n"); 564 579 580 + rv8803->rtc = devm_rtc_allocate_device(&client->dev); 581 + if (IS_ERR(rv8803->rtc)) { 582 + return PTR_ERR(rv8803->rtc); 583 + } 584 + 565 585 if (client->irq > 0) { 566 586 err = devm_request_threaded_irq(&client->dev, client->irq, 567 587 NULL, rv8803_handle_irq, ··· 582 592 } 583 593 } 584 594 585 - rv8803->rtc = devm_rtc_device_register(&client->dev, client->name, 586 - &rv8803_rtc_ops, THIS_MODULE); 587 - if (IS_ERR(rv8803->rtc)) { 588 - dev_err(&client->dev, "unable to register the class device\n"); 589 - return PTR_ERR(rv8803->rtc); 590 - } 595 + rv8803->nvmem_cfg.name = "rv8803_nvram", 596 + rv8803->nvmem_cfg.word_size = 1, 597 + rv8803->nvmem_cfg.stride = 1, 598 + rv8803->nvmem_cfg.size = 1, 599 + rv8803->nvmem_cfg.reg_read = rv8803_nvram_read, 600 + rv8803->nvmem_cfg.reg_write = rv8803_nvram_write, 601 + rv8803->nvmem_cfg.priv = client; 602 + 603 + rv8803->rtc->ops = &rv8803_rtc_ops; 604 + rv8803->rtc->nvmem_config = &rv8803->nvmem_cfg; 605 + rv8803->rtc->nvram_old_abi = true; 606 + err = rtc_register_device(rv8803->rtc); 607 + if (err) 608 + return err; 591 609 592 610 err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); 593 611 if (err) ··· 607 609 return err; 608 610 } 609 611 610 - err = device_create_bin_file(&client->dev, &rv8803_nvram_attr); 611 - if (err) 612 - return err; 613 - 614 612 rv8803->rtc->max_user_freq = 1; 615 - 616 - return 0; 617 - } 618 - 619 - static int rv8803_remove(struct i2c_client *client) 620 - { 621 - device_remove_bin_file(&client->dev, &rv8803_nvram_attr); 622 613 623 614 return 0; 624 615 } ··· 638 651 .of_match_table = of_match_ptr(rv8803_of_match), 639 652 }, 640 653 .probe = rv8803_probe, 641 - .remove = rv8803_remove, 642 654 .id_table = rv8803_id, 643 655 }; 644 656 module_i2c_driver(rv8803_driver);
+96 -51
drivers/rtc/rtc-s3c.c
··· 41 41 struct clk *rtc_src_clk; 42 42 bool clk_disabled; 43 43 44 - struct s3c_rtc_data *data; 44 + const struct s3c_rtc_data *data; 45 45 46 46 int irq_alarm; 47 47 int irq_tick; ··· 49 49 spinlock_t pie_lock; 50 50 spinlock_t alarm_clk_lock; 51 51 52 - int ticnt_save, ticnt_en_save; 52 + int ticnt_save; 53 + int ticnt_en_save; 53 54 bool wake_en; 54 55 }; 55 56 ··· 68 67 void (*disable) (struct s3c_rtc *info); 69 68 }; 70 69 71 - static void s3c_rtc_enable_clk(struct s3c_rtc *info) 70 + static int s3c_rtc_enable_clk(struct s3c_rtc *info) 72 71 { 73 72 unsigned long irq_flags; 73 + int ret = 0; 74 74 75 75 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 76 + 76 77 if (info->clk_disabled) { 77 - clk_enable(info->rtc_clk); 78 - if (info->data->needs_src_clk) 79 - clk_enable(info->rtc_src_clk); 78 + ret = clk_enable(info->rtc_clk); 79 + if (ret) 80 + goto out; 81 + 82 + if (info->data->needs_src_clk) { 83 + ret = clk_enable(info->rtc_src_clk); 84 + if (ret) { 85 + clk_disable(info->rtc_clk); 86 + goto out; 87 + } 88 + } 80 89 info->clk_disabled = false; 81 90 } 91 + 92 + out: 82 93 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 94 + 95 + return ret; 83 96 } 84 97 85 98 static void s3c_rtc_disable_clk(struct s3c_rtc *info) ··· 136 121 { 137 122 struct s3c_rtc *info = dev_get_drvdata(dev); 138 123 unsigned int tmp; 124 + int ret; 139 125 140 126 dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled); 141 127 142 - s3c_rtc_enable_clk(info); 128 + ret = s3c_rtc_enable_clk(info); 129 + if (ret) 130 + return ret; 143 131 144 132 tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 145 133 ··· 153 135 154 136 s3c_rtc_disable_clk(info); 155 137 156 - if (enabled) 157 - s3c_rtc_enable_clk(info); 158 - else 138 + if (enabled) { 139 + ret = s3c_rtc_enable_clk(info); 140 + if (ret) 141 + return ret; 142 + } else { 159 143 s3c_rtc_disable_clk(info); 144 + } 160 145 161 146 return 0; 162 147 } ··· 167 146 /* Set RTC frequency */ 168 147 static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq) 169 148 { 149 + int ret; 150 + 170 151 if (!is_power_of_2(freq)) 171 152 return -EINVAL; 172 153 173 - s3c_rtc_enable_clk(info); 154 + ret = s3c_rtc_enable_clk(info); 155 + if (ret) 156 + return ret; 174 157 spin_lock_irq(&info->pie_lock); 175 158 176 159 if (info->data->set_freq) ··· 191 166 { 192 167 struct s3c_rtc *info = dev_get_drvdata(dev); 193 168 unsigned int have_retried = 0; 169 + int ret; 194 170 195 - s3c_rtc_enable_clk(info); 171 + ret = s3c_rtc_enable_clk(info); 172 + if (ret) 173 + return ret; 196 174 197 - retry_get_time: 175 + retry_get_time: 198 176 rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN); 199 177 rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR); 200 178 rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE); ··· 227 199 rtc_tm->tm_year += 100; 228 200 229 201 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", 230 - 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 231 - rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 202 + 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 203 + rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 232 204 233 205 rtc_tm->tm_mon -= 1; 234 206 ··· 239 211 { 240 212 struct s3c_rtc *info = dev_get_drvdata(dev); 241 213 int year = tm->tm_year - 100; 214 + int ret; 242 215 243 216 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n", 244 - 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 245 - tm->tm_hour, tm->tm_min, tm->tm_sec); 217 + 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 218 + tm->tm_hour, tm->tm_min, tm->tm_sec); 246 219 247 220 /* we get around y2k by simply not supporting it */ 248 221 ··· 252 223 return -EINVAL; 253 224 } 254 225 255 - s3c_rtc_enable_clk(info); 226 + ret = s3c_rtc_enable_clk(info); 227 + if (ret) 228 + return ret; 256 229 257 230 writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC); 258 231 writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN); ··· 273 242 struct s3c_rtc *info = dev_get_drvdata(dev); 274 243 struct rtc_time *alm_tm = &alrm->time; 275 244 unsigned int alm_en; 245 + int ret; 276 246 277 - s3c_rtc_enable_clk(info); 247 + ret = s3c_rtc_enable_clk(info); 248 + if (ret) 249 + return ret; 278 250 279 251 alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC); 280 252 alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN); ··· 293 259 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 294 260 295 261 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", 296 - alm_en, 297 - 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 298 - alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 262 + alm_en, 263 + 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 264 + alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 299 265 300 266 /* decode the alarm enable field */ 301 267 if (alm_en & S3C2410_RTCALM_SECEN) ··· 326 292 struct s3c_rtc *info = dev_get_drvdata(dev); 327 293 struct rtc_time *tm = &alrm->time; 328 294 unsigned int alrm_en; 295 + int ret; 329 296 int year = tm->tm_year - 100; 330 297 331 298 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 332 - alrm->enabled, 333 - 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 334 - tm->tm_hour, tm->tm_min, tm->tm_sec); 299 + alrm->enabled, 300 + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 301 + tm->tm_hour, tm->tm_min, tm->tm_sec); 335 302 336 - s3c_rtc_enable_clk(info); 303 + ret = s3c_rtc_enable_clk(info); 304 + if (ret) 305 + return ret; 337 306 338 307 alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN; 339 308 writeb(0x00, info->base + S3C2410_RTCALM); ··· 385 348 static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) 386 349 { 387 350 struct s3c_rtc *info = dev_get_drvdata(dev); 351 + int ret; 388 352 389 - s3c_rtc_enable_clk(info); 353 + ret = s3c_rtc_enable_clk(info); 354 + if (ret) 355 + return ret; 390 356 391 357 if (info->data->enable_tick) 392 358 info->data->enable_tick(info, seq); ··· 418 378 dev_info(info->dev, "rtc disabled, re-enabling\n"); 419 379 420 380 tmp = readw(info->base + S3C2410_RTCCON); 421 - writew(tmp | S3C2410_RTCCON_RTCEN, 422 - info->base + S3C2410_RTCCON); 381 + writew(tmp | S3C2410_RTCCON_RTCEN, info->base + S3C2410_RTCCON); 423 382 } 424 383 425 384 if (con & S3C2410_RTCCON_CNTSEL) { ··· 426 387 427 388 tmp = readw(info->base + S3C2410_RTCCON); 428 389 writew(tmp & ~S3C2410_RTCCON_CNTSEL, 429 - info->base + S3C2410_RTCCON); 390 + info->base + S3C2410_RTCCON); 430 391 } 431 392 432 393 if (con & S3C2410_RTCCON_CLKRST) { ··· 434 395 435 396 tmp = readw(info->base + S3C2410_RTCCON); 436 397 writew(tmp & ~S3C2410_RTCCON_CLKRST, 437 - info->base + S3C2410_RTCCON); 398 + info->base + S3C2410_RTCCON); 438 399 } 439 400 } 440 401 ··· 476 437 477 438 static const struct of_device_id s3c_rtc_dt_match[]; 478 439 479 - static struct s3c_rtc_data *s3c_rtc_get_data(struct platform_device *pdev) 440 + static const struct s3c_rtc_data *s3c_rtc_get_data(struct platform_device *pdev) 480 441 { 481 442 const struct of_device_id *match; 482 443 483 444 match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node); 484 - return (struct s3c_rtc_data *)match->data; 445 + return match->data; 485 446 } 486 447 487 448 static int s3c_rtc_probe(struct platform_device *pdev) ··· 520 481 } 521 482 522 483 dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n", 523 - info->irq_tick, info->irq_alarm); 484 + info->irq_tick, info->irq_alarm); 524 485 525 486 /* get the memory region */ 526 487 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 537 498 dev_dbg(&pdev->dev, "probe deferred due to missing rtc clk\n"); 538 499 return ret; 539 500 } 540 - clk_prepare_enable(info->rtc_clk); 501 + ret = clk_prepare_enable(info->rtc_clk); 502 + if (ret) 503 + return ret; 541 504 542 505 if (info->data->needs_src_clk) { 543 506 info->rtc_src_clk = devm_clk_get(&pdev->dev, "rtc_src"); ··· 551 510 else 552 511 dev_dbg(&pdev->dev, 553 512 "probe deferred due to missing rtc src clk\n"); 554 - clk_disable_unprepare(info->rtc_clk); 555 - return ret; 513 + goto err_src_clk; 556 514 } 557 - clk_prepare_enable(info->rtc_src_clk); 515 + ret = clk_prepare_enable(info->rtc_src_clk); 516 + if (ret) 517 + goto err_src_clk; 558 518 } 559 519 560 520 /* check to see if everything is setup correctly */ ··· 563 521 info->data->enable(info); 564 522 565 523 dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n", 566 - readw(info->base + S3C2410_RTCCON)); 524 + readw(info->base + S3C2410_RTCCON)); 567 525 568 526 device_init_wakeup(&pdev->dev, 1); 569 527 ··· 583 541 584 542 /* register RTC and exit */ 585 543 info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops, 586 - THIS_MODULE); 544 + THIS_MODULE); 587 545 if (IS_ERR(info->rtc)) { 588 546 dev_err(&pdev->dev, "cannot attach rtc\n"); 589 547 ret = PTR_ERR(info->rtc); ··· 591 549 } 592 550 593 551 ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq, 594 - 0, "s3c2410-rtc alarm", info); 552 + 0, "s3c2410-rtc alarm", info); 595 553 if (ret) { 596 554 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret); 597 555 goto err_nortc; 598 556 } 599 557 600 558 ret = devm_request_irq(&pdev->dev, info->irq_tick, s3c_rtc_tickirq, 601 - 0, "s3c2410-rtc tick", info); 559 + 0, "s3c2410-rtc tick", info); 602 560 if (ret) { 603 561 dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_tick, ret); 604 562 goto err_nortc; ··· 611 569 612 570 return 0; 613 571 614 - err_nortc: 572 + err_nortc: 615 573 if (info->data->disable) 616 574 info->data->disable(info); 617 575 618 576 if (info->data->needs_src_clk) 619 577 clk_disable_unprepare(info->rtc_src_clk); 578 + err_src_clk: 620 579 clk_disable_unprepare(info->rtc_clk); 621 580 622 581 return ret; ··· 628 585 static int s3c_rtc_suspend(struct device *dev) 629 586 { 630 587 struct s3c_rtc *info = dev_get_drvdata(dev); 588 + int ret; 631 589 632 - s3c_rtc_enable_clk(info); 590 + ret = s3c_rtc_enable_clk(info); 591 + if (ret) 592 + return ret; 633 593 634 594 /* save TICNT for anyone using periodic interrupts */ 635 595 if (info->data->save_tick_cnt) ··· 793 747 writel(info->ticnt_save, info->base + S3C2410_TICNT); 794 748 if (info->ticnt_en_save) { 795 749 con = readw(info->base + S3C2410_RTCCON); 796 - writew(con | info->ticnt_en_save, 797 - info->base + S3C2410_RTCCON); 750 + writew(con | info->ticnt_en_save, info->base + S3C2410_RTCCON); 798 751 } 799 752 } 800 753 ··· 847 802 static const struct of_device_id s3c_rtc_dt_match[] = { 848 803 { 849 804 .compatible = "samsung,s3c2410-rtc", 850 - .data = (void *)&s3c2410_rtc_data, 805 + .data = &s3c2410_rtc_data, 851 806 }, { 852 807 .compatible = "samsung,s3c2416-rtc", 853 - .data = (void *)&s3c2416_rtc_data, 808 + .data = &s3c2416_rtc_data, 854 809 }, { 855 810 .compatible = "samsung,s3c2443-rtc", 856 - .data = (void *)&s3c2443_rtc_data, 811 + .data = &s3c2443_rtc_data, 857 812 }, { 858 813 .compatible = "samsung,s3c6410-rtc", 859 - .data = (void *)&s3c6410_rtc_data, 814 + .data = &s3c6410_rtc_data, 860 815 }, { 861 816 .compatible = "samsung,exynos3250-rtc", 862 - .data = (void *)&s3c6410_rtc_data, 817 + .data = &s3c6410_rtc_data, 863 818 }, 864 819 { /* sentinel */ }, 865 820 };
+8 -11
drivers/rtc/rtc-st-lpc.c
··· 99 99 100 100 lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb; 101 101 do_div(lpt, rtc->clkrate); 102 - rtc_time_to_tm(lpt, tm); 102 + rtc_time64_to_tm(lpt, tm); 103 103 104 104 return 0; 105 105 } ··· 107 107 static int st_rtc_set_time(struct device *dev, struct rtc_time *tm) 108 108 { 109 109 struct st_rtc *rtc = dev_get_drvdata(dev); 110 - unsigned long long lpt; 111 - unsigned long secs, flags; 112 - int ret; 110 + unsigned long long lpt, secs; 111 + unsigned long flags; 113 112 114 - ret = rtc_tm_to_time(tm, &secs); 115 - if (ret) 116 - return ret; 113 + secs = rtc_tm_to_time64(tm); 117 114 118 115 lpt = (unsigned long long)secs * rtc->clkrate; 119 116 ··· 158 161 { 159 162 struct st_rtc *rtc = dev_get_drvdata(dev); 160 163 struct rtc_time now; 161 - unsigned long now_secs; 162 - unsigned long alarm_secs; 164 + unsigned long long now_secs; 165 + unsigned long long alarm_secs; 163 166 unsigned long long lpa; 164 167 165 168 st_rtc_read_time(dev, &now); 166 - rtc_tm_to_time(&now, &now_secs); 167 - rtc_tm_to_time(&t->time, &alarm_secs); 169 + now_secs = rtc_tm_to_time64(&now); 170 + alarm_secs = rtc_tm_to_time64(&t->time); 168 171 169 172 /* Invalid alarm time */ 170 173 if (now_secs > alarm_secs)
+65 -17
drivers/rtc/rtc-stm32.c
··· 94 94 /* STM32_PWR_CR bit field */ 95 95 #define PWR_CR_DBP BIT(8) 96 96 97 + struct stm32_rtc_data { 98 + bool has_pclk; 99 + }; 100 + 97 101 struct stm32_rtc { 98 102 struct rtc_device *rtc_dev; 99 103 void __iomem *base; 100 104 struct regmap *dbp; 101 - struct clk *ck_rtc; 105 + struct stm32_rtc_data *data; 106 + struct clk *pclk; 107 + struct clk *rtc_ck; 102 108 int irq_alarm; 103 109 }; 104 110 ··· 128 122 writel_relaxed(isr, rtc->base + STM32_RTC_ISR); 129 123 130 124 /* 131 - * It takes around 2 ck_rtc clock cycles to enter in 125 + * It takes around 2 rtc_ck clock cycles to enter in 132 126 * initialization phase mode (and have INITF flag set). As 133 - * slowest ck_rtc frequency may be 32kHz and highest should be 127 + * slowest rtc_ck frequency may be 32kHz and highest should be 134 128 * 1MHz, we poll every 10 us with a timeout of 100ms. 135 129 */ 136 130 return readl_relaxed_poll_timeout_atomic( ··· 159 153 160 154 /* 161 155 * Wait for RSF to be set to ensure the calendar registers are 162 - * synchronised, it takes around 2 ck_rtc clock cycles 156 + * synchronised, it takes around 2 rtc_ck clock cycles 163 157 */ 164 158 return readl_relaxed_poll_timeout_atomic(rtc->base + STM32_RTC_ISR, 165 159 isr, ··· 462 456 463 457 /* 464 458 * Poll Alarm write flag to be sure that Alarm update is allowed: it 465 - * takes around 2 ck_rtc clock cycles 459 + * takes around 2 rtc_ck clock cycles 466 460 */ 467 461 ret = readl_relaxed_poll_timeout_atomic(rtc->base + STM32_RTC_ISR, 468 462 isr, ··· 496 490 .alarm_irq_enable = stm32_rtc_alarm_irq_enable, 497 491 }; 498 492 493 + static const struct stm32_rtc_data stm32_rtc_data = { 494 + .has_pclk = false, 495 + }; 496 + 497 + static const struct stm32_rtc_data stm32h7_rtc_data = { 498 + .has_pclk = true, 499 + }; 500 + 499 501 static const struct of_device_id stm32_rtc_of_match[] = { 500 - { .compatible = "st,stm32-rtc" }, 502 + { .compatible = "st,stm32-rtc", .data = &stm32_rtc_data }, 503 + { .compatible = "st,stm32h7-rtc", .data = &stm32h7_rtc_data }, 501 504 {} 502 505 }; 503 506 MODULE_DEVICE_TABLE(of, stm32_rtc_of_match); ··· 518 503 unsigned int rate; 519 504 int ret = 0; 520 505 521 - rate = clk_get_rate(rtc->ck_rtc); 506 + rate = clk_get_rate(rtc->rtc_ck); 522 507 523 508 /* Find prediv_a and prediv_s to obtain the 1Hz calendar clock */ 524 509 pred_a_max = STM32_RTC_PRER_PRED_A >> STM32_RTC_PRER_PRED_A_SHIFT; ··· 539 524 pred_a = pred_a_max; 540 525 pred_s = (rate / (pred_a + 1)) - 1; 541 526 542 - dev_warn(&pdev->dev, "ck_rtc is %s\n", 527 + dev_warn(&pdev->dev, "rtc_ck is %s\n", 543 528 (rate < ((pred_a + 1) * (pred_s + 1))) ? 544 529 "fast" : "slow"); 545 530 } ··· 576 561 { 577 562 struct stm32_rtc *rtc; 578 563 struct resource *res; 564 + const struct of_device_id *match; 579 565 int ret; 580 566 581 567 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); ··· 595 579 return PTR_ERR(rtc->dbp); 596 580 } 597 581 598 - rtc->ck_rtc = devm_clk_get(&pdev->dev, NULL); 599 - if (IS_ERR(rtc->ck_rtc)) { 600 - dev_err(&pdev->dev, "no ck_rtc clock"); 601 - return PTR_ERR(rtc->ck_rtc); 582 + match = of_match_device(stm32_rtc_of_match, &pdev->dev); 583 + rtc->data = (struct stm32_rtc_data *)match->data; 584 + 585 + if (!rtc->data->has_pclk) { 586 + rtc->pclk = NULL; 587 + rtc->rtc_ck = devm_clk_get(&pdev->dev, NULL); 588 + } else { 589 + rtc->pclk = devm_clk_get(&pdev->dev, "pclk"); 590 + if (IS_ERR(rtc->pclk)) { 591 + dev_err(&pdev->dev, "no pclk clock"); 592 + return PTR_ERR(rtc->pclk); 593 + } 594 + rtc->rtc_ck = devm_clk_get(&pdev->dev, "rtc_ck"); 595 + } 596 + if (IS_ERR(rtc->rtc_ck)) { 597 + dev_err(&pdev->dev, "no rtc_ck clock"); 598 + return PTR_ERR(rtc->rtc_ck); 602 599 } 603 600 604 - ret = clk_prepare_enable(rtc->ck_rtc); 601 + if (rtc->data->has_pclk) { 602 + ret = clk_prepare_enable(rtc->pclk); 603 + if (ret) 604 + return ret; 605 + } 606 + 607 + ret = clk_prepare_enable(rtc->rtc_ck); 605 608 if (ret) 606 - return ret; 609 + goto err; 607 610 608 611 regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, PWR_CR_DBP); 609 612 ··· 630 595 * After a system reset, RTC_ISR.INITS flag can be read to check if 631 596 * the calendar has been initalized or not. INITS flag is reset by a 632 597 * power-on reset (no vbat, no power-supply). It is not reset if 633 - * ck_rtc parent clock has changed (so RTC prescalers need to be 598 + * rtc_ck parent clock has changed (so RTC prescalers need to be 634 599 * changed). That's why we cannot rely on this flag to know if RTC 635 600 * init has to be done. 636 601 */ ··· 681 646 682 647 return 0; 683 648 err: 684 - clk_disable_unprepare(rtc->ck_rtc); 649 + if (rtc->data->has_pclk) 650 + clk_disable_unprepare(rtc->pclk); 651 + clk_disable_unprepare(rtc->rtc_ck); 685 652 686 653 regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, 0); 687 654 ··· 704 667 writel_relaxed(cr, rtc->base + STM32_RTC_CR); 705 668 stm32_rtc_wpr_lock(rtc); 706 669 707 - clk_disable_unprepare(rtc->ck_rtc); 670 + clk_disable_unprepare(rtc->rtc_ck); 671 + if (rtc->data->has_pclk) 672 + clk_disable_unprepare(rtc->pclk); 708 673 709 674 /* Enable backup domain write protection */ 710 675 regmap_update_bits(rtc->dbp, PWR_CR, PWR_CR_DBP, 0); ··· 721 682 { 722 683 struct stm32_rtc *rtc = dev_get_drvdata(dev); 723 684 685 + if (rtc->data->has_pclk) 686 + clk_disable_unprepare(rtc->pclk); 687 + 724 688 if (device_may_wakeup(dev)) 725 689 return enable_irq_wake(rtc->irq_alarm); 726 690 ··· 734 692 { 735 693 struct stm32_rtc *rtc = dev_get_drvdata(dev); 736 694 int ret = 0; 695 + 696 + if (rtc->data->has_pclk) { 697 + ret = clk_prepare_enable(rtc->pclk); 698 + if (ret) 699 + return ret; 700 + } 737 701 738 702 ret = stm32_rtc_wait_sync(rtc); 739 703 if (ret < 0)
+2 -1
drivers/rtc/rtc-sysfs.c
··· 27 27 static ssize_t 28 28 name_show(struct device *dev, struct device_attribute *attr, char *buf) 29 29 { 30 - return sprintf(buf, "%s\n", to_rtc_device(dev)->name); 30 + return sprintf(buf, "%s %s\n", dev_driver_string(dev->parent), 31 + dev_name(dev->parent)); 31 32 } 32 33 static DEVICE_ATTR_RO(name); 33 34
+3
include/linux/nvmem-provider.h
··· 12 12 #ifndef _LINUX_NVMEM_PROVIDER_H 13 13 #define _LINUX_NVMEM_PROVIDER_H 14 14 15 + #include <linux/err.h> 16 + #include <linux/errno.h> 17 + 15 18 struct nvmem_device; 16 19 struct nvmem_cell_info; 17 20 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
+14 -7
include/linux/rtc.h
··· 14 14 15 15 #include <linux/types.h> 16 16 #include <linux/interrupt.h> 17 + #include <linux/nvmem-provider.h> 17 18 #include <uapi/linux/rtc.h> 18 19 19 20 extern int rtc_month_days(unsigned int month, unsigned int year); ··· 33 32 return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs); 34 33 } 35 34 36 - /** 37 - * Deprecated. Use rtc_time64_to_tm(). 38 - */ 39 35 static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) 40 36 { 41 37 rtc_time64_to_tm(time, tm); 42 38 } 43 39 44 - /** 45 - * Deprecated. Use rtc_tm_to_time64(). 46 - */ 47 40 static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time) 48 41 { 49 42 *time = rtc_tm_to_time64(tm); ··· 111 116 struct module *owner; 112 117 113 118 int id; 114 - char name[RTC_DEVICE_NAME_SIZE]; 115 119 116 120 const struct rtc_class_ops *ops; 117 121 struct mutex ops_lock; ··· 137 143 /* Some hardware can't support UIE mode */ 138 144 int uie_unsupported; 139 145 146 + bool registered; 147 + 148 + struct nvmem_config *nvmem_config; 149 + struct nvmem_device *nvmem; 150 + /* Old ABI support */ 151 + bool nvram_old_abi; 152 + struct bin_attribute *nvram; 153 + 140 154 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 141 155 struct work_struct uie_task; 142 156 struct timer_list uie_timer; ··· 166 164 const char *name, 167 165 const struct rtc_class_ops *ops, 168 166 struct module *owner); 167 + struct rtc_device *devm_rtc_allocate_device(struct device *dev); 168 + int __rtc_register_device(struct module *owner, struct rtc_device *rtc); 169 169 extern void rtc_device_unregister(struct rtc_device *rtc); 170 170 extern void devm_rtc_device_unregister(struct device *dev, 171 171 struct rtc_device *rtc); ··· 222 218 { 223 219 return (!(year % 4) && (year % 100)) || !(year % 400); 224 220 } 221 + 222 + #define rtc_register_device(device) \ 223 + __rtc_register_device(THIS_MODULE, device) 225 224 226 225 #ifdef CONFIG_RTC_HCTOSYS_DEVICE 227 226 extern int rtc_hctosys_ret;
+1 -1
tools/testing/selftests/timers/Makefile
··· 9 9 10 10 TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ 11 11 skew_consistency clocksource-switch freq-step leap-a-day \ 12 - leapcrash set-tai set-2038 set-tz 12 + leapcrash set-tai set-2038 set-tz rtctest_setdate 13 13 14 14 15 15 include ../lib.mk
+124 -4
tools/testing/selftests/timers/rtctest.c
··· 21 21 #include <stdlib.h> 22 22 #include <errno.h> 23 23 24 + #ifndef ARRAY_SIZE 25 + # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 26 + #endif 24 27 25 28 /* 26 29 * This expects the new RTC class driver framework, working with ··· 32 29 */ 33 30 static const char default_rtc[] = "/dev/rtc0"; 34 31 32 + static struct rtc_time cutoff_dates[] = { 33 + { 34 + .tm_year = 70, /* 1970 -1900 */ 35 + .tm_mday = 1, 36 + }, 37 + /* signed time_t 19/01/2038 3:14:08 */ 38 + { 39 + .tm_year = 138, 40 + .tm_mday = 19, 41 + }, 42 + { 43 + .tm_year = 138, 44 + .tm_mday = 20, 45 + }, 46 + { 47 + .tm_year = 199, /* 2099 -1900 */ 48 + .tm_mday = 1, 49 + }, 50 + { 51 + .tm_year = 200, /* 2100 -1900 */ 52 + .tm_mday = 1, 53 + }, 54 + /* unsigned time_t 07/02/2106 7:28:15*/ 55 + { 56 + .tm_year = 205, 57 + .tm_mon = 1, 58 + .tm_mday = 7, 59 + }, 60 + { 61 + .tm_year = 206, 62 + .tm_mon = 1, 63 + .tm_mday = 8, 64 + }, 65 + /* signed time on 64bit in nanoseconds 12/04/2262 01:47:16*/ 66 + { 67 + .tm_year = 362, 68 + .tm_mon = 3, 69 + .tm_mday = 12, 70 + }, 71 + { 72 + .tm_year = 362, /* 2262 -1900 */ 73 + .tm_mon = 3, 74 + .tm_mday = 13, 75 + }, 76 + }; 77 + 78 + static int compare_dates(struct rtc_time *a, struct rtc_time *b) 79 + { 80 + if (a->tm_year != b->tm_year || 81 + a->tm_mon != b->tm_mon || 82 + a->tm_mday != b->tm_mday || 83 + a->tm_hour != b->tm_hour || 84 + a->tm_min != b->tm_min || 85 + ((b->tm_sec - a->tm_sec) > 1)) 86 + return 1; 87 + 88 + return 0; 89 + } 35 90 36 91 int main(int argc, char **argv) 37 92 { 38 - int i, fd, retval, irqcount = 0; 93 + int i, fd, retval, irqcount = 0, dangerous = 0; 39 94 unsigned long tmp, data; 40 95 struct rtc_time rtc_tm; 41 96 const char *rtc = default_rtc; 42 97 struct timeval start, end, diff; 43 98 44 99 switch (argc) { 100 + case 3: 101 + if (*argv[2] == 'd') 102 + dangerous = 1; 45 103 case 2: 46 104 rtc = argv[1]; 47 105 /* FALLTHROUGH */ 48 106 case 1: 49 107 break; 50 108 default: 51 - fprintf(stderr, "usage: rtctest [rtcdev]\n"); 109 + fprintf(stderr, "usage: rtctest [rtcdev] [d]\n"); 52 110 return 1; 53 111 } 54 112 ··· 266 202 /* not all RTCs support periodic IRQs */ 267 203 if (errno == EINVAL) { 268 204 fprintf(stderr, "\nNo periodic IRQ support\n"); 269 - goto done; 205 + goto test_DATE; 270 206 } 271 207 perror("RTC_IRQP_READ ioctl"); 272 208 exit(errno); ··· 285 221 if (errno == EINVAL) { 286 222 fprintf(stderr, 287 223 "\n...Periodic IRQ rate is fixed\n"); 288 - goto done; 224 + goto test_DATE; 289 225 } 290 226 perror("RTC_IRQP_SET ioctl"); 291 227 exit(errno); ··· 333 269 } 334 270 } 335 271 272 + test_DATE: 273 + if (!dangerous) 274 + goto done; 275 + 276 + fprintf(stderr, "\nTesting problematic dates\n"); 277 + 278 + for (i = 0; i < ARRAY_SIZE(cutoff_dates); i++) { 279 + struct rtc_time current; 280 + 281 + /* Write the new date in RTC */ 282 + retval = ioctl(fd, RTC_SET_TIME, &cutoff_dates[i]); 283 + if (retval == -1) { 284 + perror("RTC_SET_TIME ioctl"); 285 + close(fd); 286 + exit(errno); 287 + } 288 + 289 + /* Read back */ 290 + retval = ioctl(fd, RTC_RD_TIME, &current); 291 + if (retval == -1) { 292 + perror("RTC_RD_TIME ioctl"); 293 + exit(errno); 294 + } 295 + 296 + if(compare_dates(&cutoff_dates[i], &current)) { 297 + fprintf(stderr,"Setting date %d failed\n", 298 + cutoff_dates[i].tm_year + 1900); 299 + goto done; 300 + } 301 + 302 + cutoff_dates[i].tm_sec += 5; 303 + 304 + /* Write the new alarm in RTC */ 305 + retval = ioctl(fd, RTC_ALM_SET, &cutoff_dates[i]); 306 + if (retval == -1) { 307 + perror("RTC_ALM_SET ioctl"); 308 + close(fd); 309 + exit(errno); 310 + } 311 + 312 + /* Read back */ 313 + retval = ioctl(fd, RTC_ALM_READ, &current); 314 + if (retval == -1) { 315 + perror("RTC_ALM_READ ioctl"); 316 + exit(errno); 317 + } 318 + 319 + if(compare_dates(&cutoff_dates[i], &current)) { 320 + fprintf(stderr,"Setting alarm %d failed\n", 321 + cutoff_dates[i].tm_year + 1900); 322 + goto done; 323 + } 324 + 325 + fprintf(stderr, "Setting year %d is OK \n", 326 + cutoff_dates[i].tm_year + 1900); 327 + } 336 328 done: 337 329 fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n"); 338 330
+86
tools/testing/selftests/timers/rtctest_setdate.c
··· 1 + /* Real Time Clock Driver Test 2 + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org) 3 + * 4 + * To build 5 + * gcc rtctest_setdate.c -o rtctest_setdate 6 + * 7 + * This program is free software: you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation, either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #include <stdio.h> 19 + #include <linux/rtc.h> 20 + #include <sys/ioctl.h> 21 + #include <sys/time.h> 22 + #include <sys/types.h> 23 + #include <fcntl.h> 24 + #include <unistd.h> 25 + #include <stdlib.h> 26 + #include <errno.h> 27 + 28 + static const char default_time[] = "00:00:00"; 29 + 30 + int main(int argc, char **argv) 31 + { 32 + int fd, retval; 33 + struct rtc_time new, current; 34 + const char *rtc, *date; 35 + const char *time = default_time; 36 + 37 + switch (argc) { 38 + case 4: 39 + time = argv[3]; 40 + /* FALLTHROUGH */ 41 + case 3: 42 + date = argv[2]; 43 + rtc = argv[1]; 44 + break; 45 + default: 46 + fprintf(stderr, "usage: rtctest_setdate <rtcdev> <DD-MM-YYYY> [HH:MM:SS]\n"); 47 + return 1; 48 + } 49 + 50 + fd = open(rtc, O_RDONLY); 51 + if (fd == -1) { 52 + perror(rtc); 53 + exit(errno); 54 + } 55 + 56 + sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year); 57 + new.tm_mon -= 1; 58 + new.tm_year -= 1900; 59 + sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec); 60 + 61 + fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n", 62 + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900, 63 + new.tm_hour, new.tm_min, new.tm_sec); 64 + 65 + /* Write the new date in RTC */ 66 + retval = ioctl(fd, RTC_SET_TIME, &new); 67 + if (retval == -1) { 68 + perror("RTC_SET_TIME ioctl"); 69 + close(fd); 70 + exit(errno); 71 + } 72 + 73 + /* Read back */ 74 + retval = ioctl(fd, RTC_RD_TIME, &current); 75 + if (retval == -1) { 76 + perror("RTC_RD_TIME ioctl"); 77 + exit(errno); 78 + } 79 + 80 + fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n", 81 + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900, 82 + current.tm_hour, current.tm_min, current.tm_sec); 83 + 84 + close(fd); 85 + return 0; 86 + }