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

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

Pull RTC updates from Alexandre Belloni:
"Core:
- New sysfs interface to set and read clock offset
- Drivers can now be both I2C and SPI (see pcf2127 and ds3232)

New drivers:
- Alphascale ASM9260
- Epson RX6110SA
- Maxim max20024 and max77620 (in max77686)
- Microchip PIC32
- NXP pcf2129 (in pcf2127)

Subsystem wide cleanups:
- remove IRQF_EARLY_RESUME when unecessary

Drivers:
- ds1307: clock output, temperature sensor and wakeup-source support
- ds1685: actually spin forever in poweroff error path
- ds3232: many cleanups
- ds3234: merged in ds3232
- hym8563: fix invalid year calculation
- max77686: many cleanups
- max77802 merged in max77686
- pcf2123: cleanups and offset support
- pcf85063: cleanups
- pcf8523: propely handle oscillator stop bit
- rv3029: many cleanups, trickle charger and temperature sensor support
- rv8803: convert spin_lock to mutex_lock
- rx8025: many fixes
- vr41xx: restore alarm_irq_enable"

* tag 'rtc-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (86 commits)
rtc: pcf2127: add pcf2129 device id
rtc: pcf2127: add support for spi interface
rtc: pcf2127: convert to use regmap
rtc: rv3029: Add thermometer hwmon support
rtc: rv3029: Add update_bits helper for eeprom access
rtc: ds1685: actually spin forever in poweroff error path
rtc: hym8563: fix invalid year calculation
rtc: ds3232: use rtc->ops_lock to protect alarm operations
rtc: ds3232: fix issue when irq is shared several devices
rtc: ds3232: remove unused UIE code
rtc: ds3232: add register access error checks
rtc: ds3232: fix read on /dev/rtc after RTC_AIE_ON
rtc: merge ds3232 and ds3234
rtc: ds3232: convert to use regmap
rtc: pxa: fix Kconfig indentation
rtc: rv3029: Add device tree property for trickle charger
rtc: rv3029: Add functions for EEPROM access
rtc: rv3029: Add i2c register update-bits helper
rtc: rv3029: Add missing register definitions
rtc: rv3029: Add "rv3029" I2C device id
...

+3855 -1654
+19
Documentation/devicetree/bindings/rtc/alphascale,asm9260-rtc.txt
··· 1 + * Alphascale asm9260 SoC Real Time Clock 2 + 3 + Required properties: 4 + - compatible: Should be "alphascale,asm9260-rtc" 5 + - reg: Physical base address of the controller and length 6 + of memory mapped region. 7 + - interrupts: IRQ line for the RTC. 8 + - clocks: Reference to the clock entry. 9 + - clock-names: should contain: 10 + * "ahb" for the SoC RTC clock 11 + 12 + Example: 13 + rtc0: rtc@800a0000 { 14 + compatible = "alphascale,asm9260-rtc"; 15 + reg = <0x800a0000 0x100>; 16 + clocks = <&acc CLKID_AHB_RTC>; 17 + clock-names = "ahb"; 18 + interrupts = <2>; 19 + };
+39
Documentation/devicetree/bindings/rtc/epson,rx6110.txt
··· 1 + Epson RX6110 Real Time Clock 2 + ============================ 3 + 4 + The Epson RX6110 can be used with SPI or I2C busses. The kind of 5 + bus depends on the SPISEL pin and can not be configured via software. 6 + 7 + I2C mode 8 + -------- 9 + 10 + Required properties: 11 + - compatible: should be: "epson,rx6110" 12 + - reg : the I2C address of the device for I2C 13 + 14 + Example: 15 + 16 + rtc: rtc@32 { 17 + compatible = "epson,rx6110" 18 + reg = <0x32>; 19 + }; 20 + 21 + SPI mode 22 + -------- 23 + 24 + Required properties: 25 + - compatible: should be: "epson,rx6110" 26 + - reg: chip select number 27 + - spi-cs-high: RX6110 needs chipselect high 28 + - spi-cpha: RX6110 works with SPI shifted clock phase 29 + - spi-cpol: RX6110 works with SPI inverse clock polarity 30 + 31 + Example: 32 + 33 + rtc: rtc@3 { 34 + compatible = "epson,rx6110" 35 + reg = <3> 36 + spi-cs-high; 37 + spi-cpha; 38 + spi-cpol; 39 + };
+37
Documentation/devicetree/bindings/rtc/maxim,ds3231.txt
··· 1 + * Maxim DS3231 Real Time Clock 2 + 3 + Required properties: 4 + see: Documentation/devicetree/bindings/i2c/trivial-devices.txt 5 + 6 + Optional property: 7 + - #clock-cells: Should be 1. 8 + - clock-output-names: 9 + overwrite the default clock names "ds3231_clk_sqw" and "ds3231_clk_32khz". 10 + 11 + Each clock is assigned an identifier and client nodes can use this identifier 12 + to specify the clock which they consume. Following indices are allowed: 13 + - 0: square-wave output on the SQW pin 14 + - 1: square-wave output on the 32kHz pin 15 + 16 + - interrupts: rtc alarm/event interrupt. When this property is selected, 17 + clock on the SQW pin cannot be used. 18 + 19 + Example: 20 + 21 + ds3231: ds3231@51 { 22 + compatible = "maxim,ds3231"; 23 + reg = <0x68>; 24 + #clock-cells = <1>; 25 + }; 26 + 27 + device1 { 28 + ... 29 + clocks = <&ds3231 0>; 30 + ... 31 + }; 32 + 33 + device2 { 34 + ... 35 + clocks = <&ds3231 1>; 36 + ... 37 + };
+21
Documentation/devicetree/bindings/rtc/microchip,pic32-rtc.txt
··· 1 + * Microchip PIC32 Real Time Clock and Calendar 2 + 3 + The RTCC keeps time in hours, minutes, and seconds, and one half second. It 4 + provides a calendar in weekday, date, month, and year. It also provides a 5 + configurable alarm. 6 + 7 + Required properties: 8 + - compatible: should be: "microchip,pic32mzda-rtc" 9 + - reg: physical base address of the controller and length of memory mapped 10 + region. 11 + - interrupts: RTC alarm/event interrupt 12 + - clocks: clock phandle 13 + 14 + Example: 15 + 16 + rtc: rtc@1f8c0000 { 17 + compatible = "microchip,pic32mzda-rtc"; 18 + reg = <0x1f8c0000 0x60>; 19 + interrupts = <166 IRQ_TYPE_EDGE_RISING>; 20 + clocks = <&PBCLK6>; 21 + };
+6
Documentation/rtc.txt
··· 157 157 the epoch by default, or if there's a leading +, seconds in the 158 158 future, or if there is a leading +=, seconds ahead of the current 159 159 alarm. 160 + offset: The amount which the rtc clock has been adjusted in firmware. 161 + Visible only if the driver supports clock offset adjustment. 162 + The unit is parts per billion, i.e. The number of clock ticks 163 + which are added to or removed from the rtc's base clock per 164 + billion ticks. A positive value makes a day pass more slowly, 165 + longer, and a negative value makes a day pass more quickly. 160 166 161 167 IOCTL INTERFACE 162 168 ---------------
+3 -83
drivers/mfd/max77686.c
··· 35 35 #include <linux/err.h> 36 36 #include <linux/of.h> 37 37 38 - #define I2C_ADDR_RTC (0x0C >> 1) 39 - 40 38 static const struct mfd_cell max77686_devs[] = { 41 39 { .name = "max77686-pmic", }, 42 40 { .name = "max77686-rtc", }, ··· 114 116 .val_bits = 8, 115 117 }; 116 118 117 - static const struct regmap_config max77686_rtc_regmap_config = { 118 - .reg_bits = 8, 119 - .val_bits = 8, 120 - }; 121 - 122 119 static const struct regmap_config max77802_regmap_config = { 123 120 .reg_bits = 8, 124 121 .val_bits = 8, ··· 149 156 .num_irqs = ARRAY_SIZE(max77686_irqs), 150 157 }; 151 158 152 - static const struct regmap_irq max77686_rtc_irqs[] = { 153 - /* RTC interrupts */ 154 - { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC60S_MSK, }, 155 - { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA1_MSK, }, 156 - { .reg_offset = 0, .mask = MAX77686_RTCINT_RTCA2_MSK, }, 157 - { .reg_offset = 0, .mask = MAX77686_RTCINT_SMPL_MSK, }, 158 - { .reg_offset = 0, .mask = MAX77686_RTCINT_RTC1S_MSK, }, 159 - { .reg_offset = 0, .mask = MAX77686_RTCINT_WTSR_MSK, }, 160 - }; 161 - 162 - static const struct regmap_irq_chip max77686_rtc_irq_chip = { 163 - .name = "max77686-rtc", 164 - .status_base = MAX77686_RTC_INT, 165 - .mask_base = MAX77686_RTC_INTM, 166 - .num_regs = 1, 167 - .irqs = max77686_rtc_irqs, 168 - .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), 169 - }; 170 - 171 159 static const struct regmap_irq_chip max77802_irq_chip = { 172 160 .name = "max77802-pmic", 173 161 .status_base = MAX77802_REG_INT1, ··· 156 182 .num_regs = 2, 157 183 .irqs = max77686_irqs, /* same masks as 77686 */ 158 184 .num_irqs = ARRAY_SIZE(max77686_irqs), 159 - }; 160 - 161 - static const struct regmap_irq_chip max77802_rtc_irq_chip = { 162 - .name = "max77802-rtc", 163 - .status_base = MAX77802_RTC_INT, 164 - .mask_base = MAX77802_RTC_INTM, 165 - .num_regs = 1, 166 - .irqs = max77686_rtc_irqs, /* same masks as 77686 */ 167 - .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), 168 185 }; 169 186 170 187 static const struct of_device_id max77686_pmic_dt_match[] = { ··· 179 214 int ret = 0; 180 215 const struct regmap_config *config; 181 216 const struct regmap_irq_chip *irq_chip; 182 - const struct regmap_irq_chip *rtc_irq_chip; 183 - struct regmap **rtc_regmap; 184 217 const struct mfd_cell *cells; 185 218 int n_devs; 186 219 ··· 205 242 if (max77686->type == TYPE_MAX77686) { 206 243 config = &max77686_regmap_config; 207 244 irq_chip = &max77686_irq_chip; 208 - rtc_irq_chip = &max77686_rtc_irq_chip; 209 - rtc_regmap = &max77686->rtc_regmap; 210 245 cells = max77686_devs; 211 246 n_devs = ARRAY_SIZE(max77686_devs); 212 247 } else { 213 248 config = &max77802_regmap_config; 214 249 irq_chip = &max77802_irq_chip; 215 - rtc_irq_chip = &max77802_rtc_irq_chip; 216 - rtc_regmap = &max77686->regmap; 217 250 cells = max77802_devs; 218 251 n_devs = ARRAY_SIZE(max77802_devs); 219 252 } ··· 229 270 return -ENODEV; 230 271 } 231 272 232 - if (max77686->type == TYPE_MAX77686) { 233 - max77686->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); 234 - if (!max77686->rtc) { 235 - dev_err(max77686->dev, 236 - "Failed to allocate I2C device for RTC\n"); 237 - return -ENODEV; 238 - } 239 - i2c_set_clientdata(max77686->rtc, max77686); 240 - 241 - max77686->rtc_regmap = 242 - devm_regmap_init_i2c(max77686->rtc, 243 - &max77686_rtc_regmap_config); 244 - if (IS_ERR(max77686->rtc_regmap)) { 245 - ret = PTR_ERR(max77686->rtc_regmap); 246 - dev_err(max77686->dev, 247 - "failed to allocate RTC regmap: %d\n", 248 - ret); 249 - goto err_unregister_i2c; 250 - } 251 - } 252 - 253 273 ret = regmap_add_irq_chip(max77686->regmap, max77686->irq, 254 274 IRQF_TRIGGER_FALLING | IRQF_ONESHOT | 255 275 IRQF_SHARED, 0, irq_chip, 256 276 &max77686->irq_data); 257 - if (ret) { 277 + if (ret < 0) { 258 278 dev_err(&i2c->dev, "failed to add PMIC irq chip: %d\n", ret); 259 - goto err_unregister_i2c; 260 - } 261 - 262 - ret = regmap_add_irq_chip(*rtc_regmap, max77686->irq, 263 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT | 264 - IRQF_SHARED, 0, rtc_irq_chip, 265 - &max77686->rtc_irq_data); 266 - if (ret) { 267 - dev_err(&i2c->dev, "failed to add RTC irq chip: %d\n", ret); 268 - goto err_del_irqc; 279 + return ret; 269 280 } 270 281 271 282 ret = mfd_add_devices(max77686->dev, -1, cells, n_devs, NULL, 0, NULL); 272 283 if (ret < 0) { 273 284 dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret); 274 - goto err_del_rtc_irqc; 285 + goto err_del_irqc; 275 286 } 276 287 277 288 return 0; 278 289 279 - err_del_rtc_irqc: 280 - regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); 281 290 err_del_irqc: 282 291 regmap_del_irq_chip(max77686->irq, max77686->irq_data); 283 - err_unregister_i2c: 284 - if (max77686->type == TYPE_MAX77686) 285 - i2c_unregister_device(max77686->rtc); 286 292 287 293 return ret; 288 294 } ··· 258 334 259 335 mfd_remove_devices(max77686->dev); 260 336 261 - regmap_del_irq_chip(max77686->irq, max77686->rtc_irq_data); 262 337 regmap_del_irq_chip(max77686->irq, max77686->irq_data); 263 - 264 - if (max77686->type == TYPE_MAX77686) 265 - i2c_unregister_device(max77686->rtc); 266 338 267 339 return 0; 268 340 }
+148 -104
drivers/rtc/Kconfig
··· 140 140 will be called rtc-test. 141 141 142 142 comment "I2C RTC drivers" 143 - depends on I2C 144 143 145 144 if I2C 146 145 ··· 211 212 This driver can also be built as a module. If so, the module 212 213 will be called rtc-ds1307. 213 214 215 + config RTC_DRV_DS1307_HWMON 216 + bool "HWMON support for rtc-ds1307" 217 + depends on RTC_DRV_DS1307 && HWMON 218 + depends on !(RTC_DRV_DS1307=y && HWMON=m) 219 + default y 220 + help 221 + Say Y here if you want to expose temperature sensor data on 222 + rtc-ds1307 (only DS3231) 223 + 214 224 config RTC_DRV_DS1374 215 225 tristate "Dallas/Maxim DS1374" 216 226 help ··· 246 238 247 239 This driver can also be built as a module. If so, the module 248 240 will be called rtc-ds1672. 249 - 250 - config RTC_DRV_DS3232 251 - tristate "Dallas/Maxim DS3232" 252 - help 253 - If you say yes here you get support for Dallas Semiconductor 254 - DS3232 real-time clock chips. If an interrupt is associated 255 - with the device, the alarm functionality is supported. 256 - 257 - This driver can also be built as a module. If so, the module 258 - will be called rtc-ds3232. 259 241 260 242 config RTC_DRV_HYM8563 261 243 tristate "Haoyu Microelectronics HYM8563" ··· 315 317 316 318 config RTC_DRV_MAX77686 317 319 tristate "Maxim MAX77686" 318 - depends on MFD_MAX77686 320 + depends on MFD_MAX77686 || MFD_MAX77620 319 321 help 320 322 If you say yes here you will get support for the 321 - RTC of Maxim MAX77686 PMIC. 323 + RTC of Maxim MAX77686/MAX77620/MAX77802 PMIC. 322 324 323 325 This driver can also be built as a module. If so, the module 324 326 will be called rtc-max77686. ··· 332 334 333 335 This driver can also be built as a module. If so, the module 334 336 will be called rk808-rtc. 335 - 336 - config RTC_DRV_MAX77802 337 - tristate "Maxim 77802 RTC" 338 - depends on MFD_MAX77686 339 - help 340 - If you say yes here you will get support for the 341 - RTC of Maxim MAX77802 PMIC. 342 - 343 - This driver can also be built as a module. If so, the module 344 - will be called rtc-max77802. 345 337 346 338 config RTC_DRV_RS5C372 347 339 tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A" ··· 379 391 This driver can also be built as a module. If so, the module 380 392 will be called rtc-x1205. 381 393 382 - config RTC_DRV_PALMAS 383 - tristate "TI Palmas RTC driver" 384 - depends on MFD_PALMAS 385 - help 386 - If you say yes here you get support for the RTC of TI PALMA series PMIC 387 - chips. 388 - 389 - This driver can also be built as a module. If so, the module 390 - will be called rtc-palma. 391 - 392 - config RTC_DRV_PCF2127 393 - tristate "NXP PCF2127" 394 - help 395 - If you say yes here you get support for the NXP PCF2127/29 RTC 396 - chips. 397 - 398 - This driver can also be built as a module. If so, the module 399 - will be called rtc-pcf2127. 400 - 401 394 config RTC_DRV_PCF8523 402 395 tristate "NXP PCF8523" 403 396 help ··· 387 418 388 419 This driver can also be built as a module. If so, the module 389 420 will be called rtc-pcf8523. 421 + 422 + config RTC_DRV_PCF85063 423 + tristate "NXP PCF85063" 424 + help 425 + If you say yes here you get support for the PCF85063 RTC chip 426 + 427 + This driver can also be built as a module. If so, the module 428 + will be called rtc-pcf85063. 390 429 391 430 config RTC_DRV_PCF8563 392 431 tristate "Philips PCF8563/Epson RTC8564" ··· 405 428 406 429 This driver can also be built as a module. If so, the module 407 430 will be called rtc-pcf8563. 408 - 409 - config RTC_DRV_PCF85063 410 - tristate "nxp PCF85063" 411 - help 412 - If you say yes here you get support for the PCF85063 RTC chip 413 - 414 - This driver can also be built as a module. If so, the module 415 - will be called rtc-pcf85063. 416 431 417 432 config RTC_DRV_PCF8583 418 433 tristate "Philips PCF8583" ··· 469 500 470 501 This driver can also be built as a module. If so, the module 471 502 will be called rtc-twl. 503 + 504 + config RTC_DRV_PALMAS 505 + tristate "TI Palmas RTC driver" 506 + depends on MFD_PALMAS 507 + help 508 + If you say yes here you get support for the RTC of TI PALMA series PMIC 509 + chips. 510 + 511 + This driver can also be built as a module. If so, the module 512 + will be called rtc-palma. 472 513 473 514 config RTC_DRV_TPS6586X 474 515 tristate "TI TPS6586X RTC driver" ··· 574 595 will be called rtc-em3027. 575 596 576 597 config RTC_DRV_RV3029C2 577 - tristate "Micro Crystal RTC" 598 + tristate "Micro Crystal RV3029" 578 599 help 579 600 If you say yes here you get support for the Micro Crystal 580 - RV3029-C2 RTC chips. 601 + RV3029 RTC chips. 581 602 582 603 This driver can also be built as a module. If so, the module 583 604 will be called rtc-rv3029c2. 605 + 606 + config RTC_DRV_RV3029_HWMON 607 + bool "HWMON support for RV3029" 608 + depends on RTC_DRV_RV3029C2 && HWMON 609 + depends on !(RTC_DRV_RV3029C2=y && HWMON=m) 610 + default y 611 + help 612 + Say Y here if you want to expose temperature sensor data on 613 + rtc-rv3029c2. 584 614 585 615 config RTC_DRV_RV8803 586 616 tristate "Micro Crystal RV8803" ··· 679 691 This driver can also be built as a module. If so, the module 680 692 will be called rtc-ds1390. 681 693 682 - config RTC_DRV_MAX6902 683 - tristate "Maxim MAX6902" 684 - help 685 - If you say yes here you will get support for the 686 - Maxim MAX6902 SPI RTC chip. 687 - 688 - This driver can also be built as a module. If so, the module 689 - will be called rtc-max6902. 690 - 691 694 config RTC_DRV_R9701 692 695 tristate "Epson RTC-9701JE" 693 696 help ··· 687 708 688 709 This driver can also be built as a module. If so, the module 689 710 will be called rtc-r9701. 711 + 712 + config RTC_DRV_RX4581 713 + tristate "Epson RX-4581" 714 + help 715 + If you say yes here you will get support for the Epson RX-4581. 716 + 717 + This driver can also be built as a module. If so the module 718 + will be called rtc-rx4581. 719 + 720 + config RTC_DRV_RX6110 721 + tristate "Epson RX-6110" 722 + select REGMAP_SPI 723 + help 724 + If you say yes here you will get support for the Epson RX-6610. 725 + 726 + This driver can also be built as a module. If so the module 727 + will be called rtc-rx6110. 690 728 691 729 config RTC_DRV_RS5C348 692 730 tristate "Ricoh RS5C348A/B" ··· 714 718 This driver can also be built as a module. If so, the module 715 719 will be called rtc-rs5c348. 716 720 717 - config RTC_DRV_DS3234 718 - tristate "Maxim/Dallas DS3234" 721 + config RTC_DRV_MAX6902 722 + tristate "Maxim MAX6902" 719 723 help 720 - If you say yes here you get support for the 721 - Maxim/Dallas DS3234 SPI RTC chip. 724 + If you say yes here you will get support for the 725 + Maxim MAX6902 SPI RTC chip. 722 726 723 727 This driver can also be built as a module. If so, the module 724 - will be called rtc-ds3234. 728 + will be called rtc-max6902. 725 729 726 730 config RTC_DRV_PCF2123 727 731 tristate "NXP PCF2123" ··· 732 736 This driver can also be built as a module. If so, the module 733 737 will be called rtc-pcf2123. 734 738 735 - config RTC_DRV_RX4581 736 - tristate "Epson RX-4581" 737 - help 738 - If you say yes here you will get support for the Epson RX-4581. 739 - 740 - This driver can also be built as a module. If so the module 741 - will be called rtc-rx4581. 742 - 743 739 config RTC_DRV_MCP795 744 740 tristate "Microchip MCP795" 745 741 help ··· 741 753 will be called rtc-mcp795. 742 754 743 755 endif # SPI_MASTER 756 + 757 + # 758 + # Helper to resolve issues with configs that have SPI enabled but I2C 759 + # modular. See SND_SOC_I2C_AND_SPI for more information 760 + # 761 + config RTC_I2C_AND_SPI 762 + tristate 763 + default m if I2C=m 764 + default y if I2C=y 765 + default y if SPI_MASTER=y 766 + select REGMAP_I2C if I2C 767 + select REGMAP_SPI if SPI_MASTER 768 + 769 + comment "SPI and I2C RTC drivers" 770 + 771 + config RTC_DRV_DS3232 772 + tristate "Dallas/Maxim DS3232/DS3234" 773 + depends on RTC_I2C_AND_SPI 774 + help 775 + If you say yes here you get support for Dallas Semiconductor 776 + DS3232 and DS3234 real-time clock chips. If an interrupt is associated 777 + with the device, the alarm functionality is supported. 778 + 779 + This driver can also be built as a module. If so, the module 780 + will be called rtc-ds3232. 781 + 782 + config RTC_DRV_PCF2127 783 + tristate "NXP PCF2127" 784 + depends on RTC_I2C_AND_SPI 785 + help 786 + If you say yes here you get support for the NXP PCF2127/29 RTC 787 + chips. 788 + 789 + This driver can also be built as a module. If so, the module 790 + will be called rtc-pcf2127. 744 791 745 792 comment "Platform RTC drivers" 746 793 ··· 1110 1087 1111 1088 config RTC_DRV_SPEAR 1112 1089 tristate "SPEAR ST RTC" 1113 - depends on PLAT_SPEAR 1090 + depends on PLAT_SPEAR || COMPILE_TEST 1114 1091 default y 1115 1092 help 1116 1093 If you say Y here you will get support for the RTC found on ··· 1142 1119 1143 1120 config RTC_DRV_NUC900 1144 1121 tristate "NUC910/NUC920 RTC driver" 1145 - depends on ARCH_W90X900 1122 + depends on ARCH_W90X900 || COMPILE_TEST 1146 1123 help 1147 1124 If you say yes here you get support for the RTC subsystem of the 1148 1125 NUC910/NUC920 used in embedded systems. ··· 1167 1144 1168 1145 comment "on-CPU RTC drivers" 1169 1146 1147 + config RTC_DRV_ASM9260 1148 + tristate "Alphascale asm9260 RTC" 1149 + depends on MACH_ASM9260 1150 + help 1151 + If you say yes here you get support for the RTC on the 1152 + Alphascale asm9260 SoC. 1153 + 1154 + This driver can also be built as a module. If so, the module 1155 + will be called rtc-asm9260. 1156 + 1170 1157 config RTC_DRV_DAVINCI 1171 1158 tristate "TI DaVinci RTC" 1172 - depends on ARCH_DAVINCI_DM365 1159 + depends on ARCH_DAVINCI_DM365 || COMPILE_TEST 1173 1160 help 1174 1161 If you say yes here you get support for the RTC on the 1175 1162 DaVinci platforms (DM365). ··· 1189 1156 1190 1157 config RTC_DRV_DIGICOLOR 1191 1158 tristate "Conexant Digicolor RTC" 1192 - depends on ARCH_DIGICOLOR 1159 + depends on ARCH_DIGICOLOR || COMPILE_TEST 1193 1160 help 1194 1161 If you say yes here you get support for the RTC on Conexant 1195 1162 Digicolor platforms. This currently includes the CX92755 SoC. ··· 1208 1175 1209 1176 config RTC_DRV_OMAP 1210 1177 tristate "TI OMAP Real Time Clock" 1211 - depends on ARCH_OMAP || ARCH_DAVINCI 1178 + depends on ARCH_OMAP || ARCH_DAVINCI || COMPILE_TEST 1212 1179 help 1213 1180 Say "yes" here to support the on chip real time clock 1214 1181 present on TI OMAP1, AM33xx, DA8xx/OMAP-L13x, AM43xx and DRA7xx. ··· 1225 1192 1226 1193 config RTC_DRV_S3C 1227 1194 tristate "Samsung S3C series SoC RTC" 1228 - depends on ARCH_S3C64XX || HAVE_S3C_RTC 1195 + depends on ARCH_S3C64XX || HAVE_S3C_RTC || COMPILE_TEST 1229 1196 help 1230 1197 RTC (Realtime Clock) driver for the clock inbuilt into the 1231 1198 Samsung S3C24XX series of SoCs. This can provide periodic ··· 1241 1208 1242 1209 config RTC_DRV_EP93XX 1243 1210 tristate "Cirrus Logic EP93XX" 1244 - depends on ARCH_EP93XX 1211 + depends on ARCH_EP93XX || COMPILE_TEST 1245 1212 help 1246 1213 If you say yes here you get support for the 1247 1214 RTC embedded in the Cirrus Logic EP93XX processors. ··· 1271 1238 1272 1239 config RTC_DRV_VR41XX 1273 1240 tristate "NEC VR41XX" 1274 - depends on CPU_VR41XX 1241 + depends on CPU_VR41XX || COMPILE_TEST 1275 1242 help 1276 1243 If you say Y here you will get access to the real time clock 1277 1244 built into your NEC VR41XX CPU. ··· 1301 1268 1302 1269 config RTC_DRV_AT32AP700X 1303 1270 tristate "AT32AP700X series RTC" 1304 - depends on PLATFORM_AT32AP 1271 + depends on PLATFORM_AT32AP || COMPILE_TEST 1305 1272 help 1306 1273 Driver for the internal RTC (Realtime Clock) on Atmel AVR32 1307 1274 AT32AP700x family processors. 1308 1275 1309 1276 config RTC_DRV_AT91RM9200 1310 1277 tristate "AT91RM9200 or some AT91SAM9 RTC" 1311 - depends on ARCH_AT91 1278 + depends on ARCH_AT91 || COMPILE_TEST 1312 1279 help 1313 1280 Driver for the internal RTC (Realtime Clock) module found on 1314 1281 Atmel AT91RM9200's and some AT91SAM9 chips. On AT91SAM9 chips ··· 1316 1283 1317 1284 config RTC_DRV_AT91SAM9 1318 1285 tristate "AT91SAM9 RTT as RTC" 1319 - depends on ARCH_AT91 1286 + depends on ARCH_AT91 || COMPILE_TEST 1320 1287 select MFD_SYSCON 1321 1288 help 1322 1289 Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which ··· 1358 1325 tristate "Generic RTC support" 1359 1326 # Please consider writing a new RTC driver instead of using the generic 1360 1327 # RTC abstraction 1361 - depends on PARISC || M68K || PPC || SUPERH32 1328 + depends on PARISC || M68K || PPC || SUPERH32 || COMPILE_TEST 1362 1329 help 1363 1330 Say Y or M here to enable RTC support on systems using the generic 1364 1331 RTC abstraction. If you do not know what you are doing, you should 1365 1332 just say Y. 1366 1333 1367 1334 config RTC_DRV_PXA 1368 - tristate "PXA27x/PXA3xx" 1369 - depends on ARCH_PXA 1370 - select RTC_DRV_SA1100 1371 - help 1335 + tristate "PXA27x/PXA3xx" 1336 + depends on ARCH_PXA 1337 + select RTC_DRV_SA1100 1338 + help 1372 1339 If you say Y here you will get access to the real time clock 1373 1340 built into your PXA27x or PXA3xx CPU. This RTC is actually 2 RTCs 1374 1341 consisting of an SA1100 compatible RTC and the extended PXA RTC. ··· 1378 1345 1379 1346 config RTC_DRV_VT8500 1380 1347 tristate "VIA/WonderMedia 85xx SoC RTC" 1381 - depends on ARCH_VT8500 1348 + depends on ARCH_VT8500 || COMPILE_TEST 1382 1349 help 1383 1350 If you say Y here you will get access to the real time clock 1384 1351 built into your VIA VT8500 SoC or its relatives. ··· 1393 1360 1394 1361 config RTC_DRV_SUN6I 1395 1362 tristate "Allwinner A31 RTC" 1396 - depends on MACH_SUN6I || MACH_SUN8I 1363 + default MACH_SUN6I || MACH_SUN8I || COMPILE_TEST 1364 + depends on ARCH_SUNXI 1397 1365 help 1398 - If you say Y here you will get support for the RTC found on 1399 - Allwinner A31. 1366 + If you say Y here you will get support for the RTC found in 1367 + some Allwinner SoCs like the A31 or the A64. 1400 1368 1401 1369 config RTC_DRV_SUNXI 1402 1370 tristate "Allwinner sun4i/sun7i RTC" 1403 - depends on MACH_SUN4I || MACH_SUN7I 1371 + depends on MACH_SUN4I || MACH_SUN7I || COMPILE_TEST 1404 1372 help 1405 1373 If you say Y here you will get support for the RTC found on 1406 1374 Allwinner A10/A20. ··· 1422 1388 1423 1389 config RTC_DRV_MV 1424 1390 tristate "Marvell SoC RTC" 1425 - depends on ARCH_DOVE || ARCH_MVEBU 1391 + depends on ARCH_DOVE || ARCH_MVEBU || COMPILE_TEST 1426 1392 help 1427 1393 If you say yes here you will get support for the in-chip RTC 1428 1394 that can be found in some of Marvell's SoC devices, such as ··· 1433 1399 1434 1400 config RTC_DRV_ARMADA38X 1435 1401 tristate "Armada 38x Marvell SoC RTC" 1436 - depends on ARCH_MVEBU 1402 + depends on ARCH_MVEBU || COMPILE_TEST 1437 1403 help 1438 1404 If you say yes here you will get support for the in-chip RTC 1439 1405 that can be found in the Armada 38x Marvell's SoC device ··· 1463 1429 1464 1430 config RTC_DRV_COH901331 1465 1431 tristate "ST-Ericsson COH 901 331 RTC" 1466 - depends on ARCH_U300 1432 + depends on ARCH_U300 || COMPILE_TEST 1467 1433 help 1468 1434 If you say Y here you will get access to ST-Ericsson 1469 1435 COH 901 331 RTC clock found in some ST-Ericsson Mobile ··· 1475 1441 1476 1442 config RTC_DRV_STMP 1477 1443 tristate "Freescale STMP3xxx/i.MX23/i.MX28 RTC" 1478 - depends on ARCH_MXS 1444 + depends on ARCH_MXS || COMPILE_TEST 1479 1445 select STMP_DEVICE 1480 1446 help 1481 1447 If you say yes here you will get support for the onboard ··· 1510 1476 1511 1477 config RTC_DRV_JZ4740 1512 1478 tristate "Ingenic JZ4740 SoC" 1513 - depends on MACH_JZ4740 1479 + depends on MACH_JZ4740 || COMPILE_TEST 1514 1480 help 1515 1481 If you say yes here you get support for the Ingenic JZ4740 SoC RTC 1516 1482 controller. ··· 1531 1497 so, the module will be called rtc-lpc24xx. 1532 1498 1533 1499 config RTC_DRV_LPC32XX 1534 - depends on ARCH_LPC32XX 1500 + depends on ARCH_LPC32XX || COMPILE_TEST 1535 1501 tristate "NXP LPC32XX RTC" 1536 1502 help 1537 1503 This enables support for the NXP RTC in the LPC32XX ··· 1541 1507 1542 1508 config RTC_DRV_PM8XXX 1543 1509 tristate "Qualcomm PMIC8XXX RTC" 1544 - depends on MFD_PM8XXX || MFD_SPMI_PMIC 1510 + depends on MFD_PM8XXX || MFD_SPMI_PMIC || COMPILE_TEST 1545 1511 help 1546 1512 If you say yes here you get support for the 1547 1513 Qualcomm PMIC8XXX RTC. ··· 1551 1517 1552 1518 config RTC_DRV_TEGRA 1553 1519 tristate "NVIDIA Tegra Internal RTC driver" 1554 - depends on ARCH_TEGRA 1520 + depends on ARCH_TEGRA || COMPILE_TEST 1555 1521 help 1556 1522 If you say yes here you get support for the 1557 1523 Tegra 200 series internal RTC module. ··· 1637 1603 1638 1604 config RTC_DRV_MT6397 1639 1605 tristate "Mediatek Real Time Clock driver" 1640 - depends on MFD_MT6397 || COMPILE_TEST 1606 + depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN) 1641 1607 help 1642 1608 This selects the Mediatek(R) RTC driver. RTC is part of Mediatek 1643 1609 MT6397 PMIC. You should enable MT6397 PMIC MFD before select ··· 1655 1621 1656 1622 This driver can also be built as a module, if so, the module 1657 1623 will be called "rtc-xgene". 1624 + 1625 + config RTC_DRV_PIC32 1626 + tristate "Microchip PIC32 RTC" 1627 + depends on MACH_PIC32 1628 + default y 1629 + help 1630 + If you say yes here you get support for the PIC32 RTC module. 1631 + 1632 + This driver can also be built as a module. If so, the module 1633 + will be called rtc-pic32 1658 1634 1659 1635 comment "HID Sensor RTC drivers" 1660 1636
+3 -2
drivers/rtc/Makefile
··· 28 28 obj-$(CONFIG_RTC_DRV_ABX80X) += rtc-abx80x.o 29 29 obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o 30 30 obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o 31 + obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o 31 32 obj-$(CONFIG_RTC_DRV_AT32AP700X)+= rtc-at32ap700x.o 32 33 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o 33 34 obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o ··· 60 59 obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 61 60 obj-$(CONFIG_RTC_DRV_DS2404) += rtc-ds2404.o 62 61 obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o 63 - obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o 64 62 obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o 65 63 obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o 66 64 obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o ··· 86 86 obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o 87 87 obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 88 88 obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o 89 - obj-$(CONFIG_RTC_DRV_MAX77802) += rtc-max77802.o 90 89 obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o 91 90 obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o 92 91 obj-$(CONFIG_RTC_DRV_MAX8997) += rtc-max8997.o ··· 111 112 obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o 112 113 obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 113 114 obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 115 + obj-$(CONFIG_RTC_DRV_PIC32) += rtc-pic32.o 114 116 obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o 115 117 obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 116 118 obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o ··· 128 128 obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o 129 129 obj-$(CONFIG_RTC_DRV_RV8803) += rtc-rv8803.o 130 130 obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o 131 + obj-$(CONFIG_RTC_DRV_RX6110) += rtc-rx6110.o 131 132 obj-$(CONFIG_RTC_DRV_RX8010) += rtc-rx8010.o 132 133 obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o 133 134 obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
-13
drivers/rtc/class.c
··· 361 361 rtc_dev_init(); 362 362 return 0; 363 363 } 364 - 365 - static void __exit rtc_exit(void) 366 - { 367 - rtc_dev_exit(); 368 - class_destroy(rtc_class); 369 - ida_destroy(&rtc_ida); 370 - } 371 - 372 364 subsys_initcall(rtc_init); 373 - module_exit(rtc_exit); 374 - 375 - MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 376 - MODULE_DESCRIPTION("RTC class support"); 377 - MODULE_LICENSE("GPL");
+54
drivers/rtc/interface.c
··· 939 939 mutex_unlock(&rtc->ops_lock); 940 940 } 941 941 942 + /** 943 + * rtc_read_offset - Read the amount of rtc offset in parts per billion 944 + * @ rtc: rtc device to be used 945 + * @ offset: the offset in parts per billion 946 + * 947 + * see below for details. 948 + * 949 + * Kernel interface to read rtc clock offset 950 + * Returns 0 on success, or a negative number on error. 951 + * If read_offset() is not implemented for the rtc, return -EINVAL 952 + */ 953 + int rtc_read_offset(struct rtc_device *rtc, long *offset) 954 + { 955 + int ret; 942 956 957 + if (!rtc->ops) 958 + return -ENODEV; 959 + 960 + if (!rtc->ops->read_offset) 961 + return -EINVAL; 962 + 963 + mutex_lock(&rtc->ops_lock); 964 + ret = rtc->ops->read_offset(rtc->dev.parent, offset); 965 + mutex_unlock(&rtc->ops_lock); 966 + return ret; 967 + } 968 + 969 + /** 970 + * rtc_set_offset - Adjusts the duration of the average second 971 + * @ rtc: rtc device to be used 972 + * @ offset: the offset in parts per billion 973 + * 974 + * Some rtc's allow an adjustment to the average duration of a second 975 + * to compensate for differences in the actual clock rate due to temperature, 976 + * the crystal, capacitor, etc. 977 + * 978 + * Kernel interface to adjust an rtc clock offset. 979 + * Return 0 on success, or a negative number on error. 980 + * If the rtc offset is not setable (or not implemented), return -EINVAL 981 + */ 982 + int rtc_set_offset(struct rtc_device *rtc, long offset) 983 + { 984 + int ret; 985 + 986 + if (!rtc->ops) 987 + return -ENODEV; 988 + 989 + if (!rtc->ops->set_offset) 990 + return -EINVAL; 991 + 992 + mutex_lock(&rtc->ops_lock); 993 + ret = rtc->ops->set_offset(rtc->dev.parent, offset); 994 + mutex_unlock(&rtc->ops_lock); 995 + return ret; 996 + }
+1 -1
drivers/rtc/rtc-as3722.c
··· 210 210 dev_info(&pdev->dev, "RTC interrupt %d\n", as3722_rtc->alarm_irq); 211 211 212 212 ret = devm_request_threaded_irq(&pdev->dev, as3722_rtc->alarm_irq, NULL, 213 - as3722_alarm_irq, IRQF_ONESHOT | IRQF_EARLY_RESUME, 213 + as3722_alarm_irq, IRQF_ONESHOT, 214 214 "rtc-alarm", as3722_rtc); 215 215 if (ret < 0) { 216 216 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
+355
drivers/rtc/rtc-asm9260.c
··· 1 + /* 2 + * Copyright (C) 2016 Oleksij Rempel <linux@rempel-privat.de> 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms of the GNU General Public License as published by the 6 + * Free Software Foundation; either version 2 of the License, 7 + * or (at your option) any later version. 8 + */ 9 + 10 + #include <linux/clk.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/io.h> 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/rtc.h> 17 + 18 + /* Miscellaneous registers */ 19 + /* Interrupt Location Register */ 20 + #define HW_ILR 0x00 21 + #define BM_RTCALF BIT(1) 22 + #define BM_RTCCIF BIT(0) 23 + 24 + /* Clock Control Register */ 25 + #define HW_CCR 0x08 26 + /* Calibration counter disable */ 27 + #define BM_CCALOFF BIT(4) 28 + /* Reset internal oscillator divider */ 29 + #define BM_CTCRST BIT(1) 30 + /* Clock Enable */ 31 + #define BM_CLKEN BIT(0) 32 + 33 + /* Counter Increment Interrupt Register */ 34 + #define HW_CIIR 0x0C 35 + #define BM_CIIR_IMYEAR BIT(7) 36 + #define BM_CIIR_IMMON BIT(6) 37 + #define BM_CIIR_IMDOY BIT(5) 38 + #define BM_CIIR_IMDOW BIT(4) 39 + #define BM_CIIR_IMDOM BIT(3) 40 + #define BM_CIIR_IMHOUR BIT(2) 41 + #define BM_CIIR_IMMIN BIT(1) 42 + #define BM_CIIR_IMSEC BIT(0) 43 + 44 + /* Alarm Mask Register */ 45 + #define HW_AMR 0x10 46 + #define BM_AMR_IMYEAR BIT(7) 47 + #define BM_AMR_IMMON BIT(6) 48 + #define BM_AMR_IMDOY BIT(5) 49 + #define BM_AMR_IMDOW BIT(4) 50 + #define BM_AMR_IMDOM BIT(3) 51 + #define BM_AMR_IMHOUR BIT(2) 52 + #define BM_AMR_IMMIN BIT(1) 53 + #define BM_AMR_IMSEC BIT(0) 54 + #define BM_AMR_OFF 0xff 55 + 56 + /* Consolidated time registers */ 57 + #define HW_CTIME0 0x14 58 + #define BM_CTIME0_DOW_S 24 59 + #define BM_CTIME0_DOW_M 0x7 60 + #define BM_CTIME0_HOUR_S 16 61 + #define BM_CTIME0_HOUR_M 0x1f 62 + #define BM_CTIME0_MIN_S 8 63 + #define BM_CTIME0_MIN_M 0x3f 64 + #define BM_CTIME0_SEC_S 0 65 + #define BM_CTIME0_SEC_M 0x3f 66 + 67 + #define HW_CTIME1 0x18 68 + #define BM_CTIME1_YEAR_S 16 69 + #define BM_CTIME1_YEAR_M 0xfff 70 + #define BM_CTIME1_MON_S 8 71 + #define BM_CTIME1_MON_M 0xf 72 + #define BM_CTIME1_DOM_S 0 73 + #define BM_CTIME1_DOM_M 0x1f 74 + 75 + #define HW_CTIME2 0x1C 76 + #define BM_CTIME2_DOY_S 0 77 + #define BM_CTIME2_DOY_M 0xfff 78 + 79 + /* Time counter registers */ 80 + #define HW_SEC 0x20 81 + #define HW_MIN 0x24 82 + #define HW_HOUR 0x28 83 + #define HW_DOM 0x2C 84 + #define HW_DOW 0x30 85 + #define HW_DOY 0x34 86 + #define HW_MONTH 0x38 87 + #define HW_YEAR 0x3C 88 + 89 + #define HW_CALIBRATION 0x40 90 + #define BM_CALDIR_BACK BIT(17) 91 + #define BM_CALVAL_M 0x1ffff 92 + 93 + /* General purpose registers */ 94 + #define HW_GPREG0 0x44 95 + #define HW_GPREG1 0x48 96 + #define HW_GPREG2 0x4C 97 + #define HW_GPREG3 0x50 98 + #define HW_GPREG4 0x54 99 + 100 + /* Alarm register group */ 101 + #define HW_ALSEC 0x60 102 + #define HW_ALMIN 0x64 103 + #define HW_ALHOUR 0x68 104 + #define HW_ALDOM 0x6C 105 + #define HW_ALDOW 0x70 106 + #define HW_ALDOY 0x74 107 + #define HW_ALMON 0x78 108 + #define HW_ALYEAR 0x7C 109 + 110 + struct asm9260_rtc_priv { 111 + struct device *dev; 112 + void __iomem *iobase; 113 + struct rtc_device *rtc; 114 + struct clk *clk; 115 + /* io lock */ 116 + spinlock_t lock; 117 + }; 118 + 119 + static irqreturn_t asm9260_rtc_irq(int irq, void *dev_id) 120 + { 121 + struct asm9260_rtc_priv *priv = dev_id; 122 + u32 isr; 123 + unsigned long events = 0; 124 + 125 + isr = ioread32(priv->iobase + HW_CIIR); 126 + if (!isr) 127 + return IRQ_NONE; 128 + 129 + iowrite32(0, priv->iobase + HW_CIIR); 130 + 131 + events |= RTC_AF | RTC_IRQF; 132 + 133 + rtc_update_irq(priv->rtc, 1, events); 134 + 135 + return IRQ_HANDLED; 136 + } 137 + 138 + static int asm9260_rtc_read_time(struct device *dev, struct rtc_time *tm) 139 + { 140 + struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); 141 + u32 ctime0, ctime1, ctime2; 142 + unsigned long irq_flags; 143 + 144 + spin_lock_irqsave(&priv->lock, irq_flags); 145 + ctime0 = ioread32(priv->iobase + HW_CTIME0); 146 + ctime1 = ioread32(priv->iobase + HW_CTIME1); 147 + ctime2 = ioread32(priv->iobase + HW_CTIME2); 148 + 149 + if (ctime1 != ioread32(priv->iobase + HW_CTIME1)) { 150 + /* 151 + * woops, counter flipped right now. Now we are safe 152 + * to reread. 153 + */ 154 + ctime0 = ioread32(priv->iobase + HW_CTIME0); 155 + ctime1 = ioread32(priv->iobase + HW_CTIME1); 156 + ctime2 = ioread32(priv->iobase + HW_CTIME2); 157 + } 158 + spin_unlock_irqrestore(&priv->lock, irq_flags); 159 + 160 + tm->tm_sec = (ctime0 >> BM_CTIME0_SEC_S) & BM_CTIME0_SEC_M; 161 + tm->tm_min = (ctime0 >> BM_CTIME0_MIN_S) & BM_CTIME0_MIN_M; 162 + tm->tm_hour = (ctime0 >> BM_CTIME0_HOUR_S) & BM_CTIME0_HOUR_M; 163 + tm->tm_wday = (ctime0 >> BM_CTIME0_DOW_S) & BM_CTIME0_DOW_M; 164 + 165 + tm->tm_mday = (ctime1 >> BM_CTIME1_DOM_S) & BM_CTIME1_DOM_M; 166 + tm->tm_mon = (ctime1 >> BM_CTIME1_MON_S) & BM_CTIME1_MON_M; 167 + tm->tm_year = (ctime1 >> BM_CTIME1_YEAR_S) & BM_CTIME1_YEAR_M; 168 + 169 + tm->tm_yday = (ctime2 >> BM_CTIME2_DOY_S) & BM_CTIME2_DOY_M; 170 + 171 + return 0; 172 + } 173 + 174 + static int asm9260_rtc_set_time(struct device *dev, struct rtc_time *tm) 175 + { 176 + struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); 177 + unsigned long irq_flags; 178 + 179 + spin_lock_irqsave(&priv->lock, irq_flags); 180 + /* 181 + * make sure SEC counter will not flip other counter on write time, 182 + * real value will be written at the enf of sequence. 183 + */ 184 + iowrite32(0, priv->iobase + HW_SEC); 185 + 186 + iowrite32(tm->tm_year, priv->iobase + HW_YEAR); 187 + iowrite32(tm->tm_mon, priv->iobase + HW_MONTH); 188 + iowrite32(tm->tm_mday, priv->iobase + HW_DOM); 189 + iowrite32(tm->tm_wday, priv->iobase + HW_DOW); 190 + iowrite32(tm->tm_yday, priv->iobase + HW_DOY); 191 + iowrite32(tm->tm_hour, priv->iobase + HW_HOUR); 192 + iowrite32(tm->tm_min, priv->iobase + HW_MIN); 193 + iowrite32(tm->tm_sec, priv->iobase + HW_SEC); 194 + spin_unlock_irqrestore(&priv->lock, irq_flags); 195 + 196 + return 0; 197 + } 198 + 199 + static int asm9260_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 200 + { 201 + struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); 202 + unsigned long irq_flags; 203 + 204 + spin_lock_irqsave(&priv->lock, irq_flags); 205 + alrm->time.tm_year = ioread32(priv->iobase + HW_ALYEAR); 206 + alrm->time.tm_mon = ioread32(priv->iobase + HW_ALMON); 207 + alrm->time.tm_mday = ioread32(priv->iobase + HW_ALDOM); 208 + alrm->time.tm_wday = ioread32(priv->iobase + HW_ALDOW); 209 + alrm->time.tm_yday = ioread32(priv->iobase + HW_ALDOY); 210 + alrm->time.tm_hour = ioread32(priv->iobase + HW_ALHOUR); 211 + alrm->time.tm_min = ioread32(priv->iobase + HW_ALMIN); 212 + alrm->time.tm_sec = ioread32(priv->iobase + HW_ALSEC); 213 + 214 + alrm->enabled = ioread32(priv->iobase + HW_AMR) ? 1 : 0; 215 + alrm->pending = ioread32(priv->iobase + HW_CIIR) ? 1 : 0; 216 + spin_unlock_irqrestore(&priv->lock, irq_flags); 217 + 218 + return rtc_valid_tm(&alrm->time); 219 + } 220 + 221 + static int asm9260_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 222 + { 223 + struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); 224 + unsigned long irq_flags; 225 + 226 + spin_lock_irqsave(&priv->lock, irq_flags); 227 + iowrite32(alrm->time.tm_year, priv->iobase + HW_ALYEAR); 228 + iowrite32(alrm->time.tm_mon, priv->iobase + HW_ALMON); 229 + iowrite32(alrm->time.tm_mday, priv->iobase + HW_ALDOM); 230 + iowrite32(alrm->time.tm_wday, priv->iobase + HW_ALDOW); 231 + iowrite32(alrm->time.tm_yday, priv->iobase + HW_ALDOY); 232 + iowrite32(alrm->time.tm_hour, priv->iobase + HW_ALHOUR); 233 + iowrite32(alrm->time.tm_min, priv->iobase + HW_ALMIN); 234 + iowrite32(alrm->time.tm_sec, priv->iobase + HW_ALSEC); 235 + 236 + iowrite32(alrm->enabled ? 0 : BM_AMR_OFF, priv->iobase + HW_AMR); 237 + spin_unlock_irqrestore(&priv->lock, irq_flags); 238 + 239 + return 0; 240 + } 241 + 242 + static int asm9260_alarm_irq_enable(struct device *dev, unsigned int enabled) 243 + { 244 + struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); 245 + 246 + iowrite32(enabled ? 0 : BM_AMR_OFF, priv->iobase + HW_AMR); 247 + return 0; 248 + } 249 + 250 + static const struct rtc_class_ops asm9260_rtc_ops = { 251 + .read_time = asm9260_rtc_read_time, 252 + .set_time = asm9260_rtc_set_time, 253 + .read_alarm = asm9260_rtc_read_alarm, 254 + .set_alarm = asm9260_rtc_set_alarm, 255 + .alarm_irq_enable = asm9260_alarm_irq_enable, 256 + }; 257 + 258 + static int __init asm9260_rtc_probe(struct platform_device *pdev) 259 + { 260 + struct asm9260_rtc_priv *priv; 261 + struct device *dev = &pdev->dev; 262 + struct resource *res; 263 + int irq_alarm, ret; 264 + u32 ccr; 265 + 266 + priv = devm_kzalloc(dev, sizeof(struct asm9260_rtc_priv), GFP_KERNEL); 267 + if (!priv) 268 + return -ENOMEM; 269 + 270 + priv->dev = &pdev->dev; 271 + platform_set_drvdata(pdev, priv); 272 + 273 + irq_alarm = platform_get_irq(pdev, 0); 274 + if (irq_alarm < 0) { 275 + dev_err(dev, "No alarm IRQ resource defined\n"); 276 + return irq_alarm; 277 + } 278 + 279 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 280 + priv->iobase = devm_ioremap_resource(dev, res); 281 + if (IS_ERR(priv->iobase)) 282 + return PTR_ERR(priv->iobase); 283 + 284 + priv->clk = devm_clk_get(dev, "ahb"); 285 + ret = clk_prepare_enable(priv->clk); 286 + if (ret) { 287 + dev_err(dev, "Failed to enable clk!\n"); 288 + return ret; 289 + } 290 + 291 + ccr = ioread32(priv->iobase + HW_CCR); 292 + /* if dev is not enabled, reset it */ 293 + if ((ccr & (BM_CLKEN | BM_CTCRST)) != BM_CLKEN) { 294 + iowrite32(BM_CTCRST, priv->iobase + HW_CCR); 295 + ccr = 0; 296 + } 297 + 298 + iowrite32(BM_CLKEN | ccr, priv->iobase + HW_CCR); 299 + iowrite32(0, priv->iobase + HW_CIIR); 300 + iowrite32(BM_AMR_OFF, priv->iobase + HW_AMR); 301 + 302 + priv->rtc = devm_rtc_device_register(dev, dev_name(dev), 303 + &asm9260_rtc_ops, THIS_MODULE); 304 + if (IS_ERR(priv->rtc)) { 305 + ret = PTR_ERR(priv->rtc); 306 + dev_err(dev, "Failed to register RTC device: %d\n", ret); 307 + goto err_return; 308 + } 309 + 310 + ret = devm_request_threaded_irq(dev, irq_alarm, NULL, 311 + asm9260_rtc_irq, IRQF_ONESHOT, 312 + dev_name(dev), priv); 313 + if (ret < 0) { 314 + dev_err(dev, "can't get irq %i, err %d\n", 315 + irq_alarm, ret); 316 + goto err_return; 317 + } 318 + 319 + return 0; 320 + 321 + err_return: 322 + clk_disable_unprepare(priv->clk); 323 + return ret; 324 + } 325 + 326 + static int __exit asm9260_rtc_remove(struct platform_device *pdev) 327 + { 328 + struct asm9260_rtc_priv *priv = platform_get_drvdata(pdev); 329 + 330 + /* Disable alarm matching */ 331 + iowrite32(BM_AMR_OFF, priv->iobase + HW_AMR); 332 + clk_disable_unprepare(priv->clk); 333 + return 0; 334 + } 335 + 336 + static const struct of_device_id asm9260_dt_ids[] = { 337 + { .compatible = "alphascale,asm9260-rtc", }, 338 + {} 339 + }; 340 + 341 + static struct platform_driver asm9260_rtc_driver = { 342 + .probe = asm9260_rtc_probe, 343 + .remove = asm9260_rtc_remove, 344 + .driver = { 345 + .name = "asm9260-rtc", 346 + .owner = THIS_MODULE, 347 + .of_match_table = asm9260_dt_ids, 348 + }, 349 + }; 350 + 351 + module_platform_driver(asm9260_rtc_driver); 352 + 353 + MODULE_AUTHOR("Oleksij Rempel <linux@rempel-privat.de>"); 354 + MODULE_DESCRIPTION("Alphascale asm9260 SoC Realtime Clock Driver (RTC)"); 355 + MODULE_LICENSE("GPL");
+2 -2
drivers/rtc/rtc-ds1305.c
··· 532 532 struct spi_transfer x[2]; 533 533 int status; 534 534 535 - spi = container_of(kobj, struct spi_device, dev.kobj); 535 + spi = to_spi_device(kobj_to_dev(kobj)); 536 536 537 537 addr = DS1305_NVRAM + off; 538 538 msg_init(&m, x, &addr, count, NULL, buf); ··· 554 554 struct spi_transfer x[2]; 555 555 int status; 556 556 557 - spi = container_of(kobj, struct spi_device, dev.kobj); 557 + spi = to_spi_device(kobj_to_dev(kobj)); 558 558 559 559 addr = (DS1305_WRITE | DS1305_NVRAM) + off; 560 560 msg_init(&m, x, &addr, count, buf, NULL);
+409 -2
drivers/rtc/rtc-ds1307.c
··· 19 19 #include <linux/rtc.h> 20 20 #include <linux/slab.h> 21 21 #include <linux/string.h> 22 + #include <linux/hwmon.h> 23 + #include <linux/hwmon-sysfs.h> 24 + #include <linux/clk-provider.h> 22 25 23 26 /* 24 27 * We can't determine type by probing, but if we expect pre-Linux code ··· 92 89 # define DS1340_BIT_OSF 0x80 93 90 #define DS1337_REG_STATUS 0x0f 94 91 # define DS1337_BIT_OSF 0x80 92 + # define DS3231_BIT_EN32KHZ 0x08 95 93 # define DS1337_BIT_A2I 0x02 96 94 # define DS1337_BIT_A1I 0x01 97 95 #define DS1339_REG_ALARM1_SECS 0x07 ··· 122 118 u8 length, u8 *values); 123 119 s32 (*write_block_data)(const struct i2c_client *client, u8 command, 124 120 u8 length, const u8 *values); 121 + #ifdef CONFIG_COMMON_CLK 122 + struct clk_hw clks[2]; 123 + #endif 125 124 }; 126 125 127 126 struct chip_desc { ··· 849 842 return; 850 843 } 851 844 845 + /*----------------------------------------------------------------------*/ 846 + 847 + #ifdef CONFIG_RTC_DRV_DS1307_HWMON 848 + 849 + /* 850 + * Temperature sensor support for ds3231 devices. 851 + */ 852 + 853 + #define DS3231_REG_TEMPERATURE 0x11 854 + 855 + /* 856 + * A user-initiated temperature conversion is not started by this function, 857 + * so the temperature is updated once every 64 seconds. 858 + */ 859 + static int ds3231_hwmon_read_temp(struct device *dev, s16 *mC) 860 + { 861 + struct ds1307 *ds1307 = dev_get_drvdata(dev); 862 + u8 temp_buf[2]; 863 + s16 temp; 864 + int ret; 865 + 866 + ret = ds1307->read_block_data(ds1307->client, DS3231_REG_TEMPERATURE, 867 + sizeof(temp_buf), temp_buf); 868 + if (ret < 0) 869 + return ret; 870 + if (ret != sizeof(temp_buf)) 871 + return -EIO; 872 + 873 + /* 874 + * Temperature is represented as a 10-bit code with a resolution of 875 + * 0.25 degree celsius and encoded in two's complement format. 876 + */ 877 + temp = (temp_buf[0] << 8) | temp_buf[1]; 878 + temp >>= 6; 879 + *mC = temp * 250; 880 + 881 + return 0; 882 + } 883 + 884 + static ssize_t ds3231_hwmon_show_temp(struct device *dev, 885 + struct device_attribute *attr, char *buf) 886 + { 887 + int ret; 888 + s16 temp; 889 + 890 + ret = ds3231_hwmon_read_temp(dev, &temp); 891 + if (ret) 892 + return ret; 893 + 894 + return sprintf(buf, "%d\n", temp); 895 + } 896 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, ds3231_hwmon_show_temp, 897 + NULL, 0); 898 + 899 + static struct attribute *ds3231_hwmon_attrs[] = { 900 + &sensor_dev_attr_temp1_input.dev_attr.attr, 901 + NULL, 902 + }; 903 + ATTRIBUTE_GROUPS(ds3231_hwmon); 904 + 905 + static void ds1307_hwmon_register(struct ds1307 *ds1307) 906 + { 907 + struct device *dev; 908 + 909 + if (ds1307->type != ds_3231) 910 + return; 911 + 912 + dev = devm_hwmon_device_register_with_groups(&ds1307->client->dev, 913 + ds1307->client->name, 914 + ds1307, ds3231_hwmon_groups); 915 + if (IS_ERR(dev)) { 916 + dev_warn(&ds1307->client->dev, 917 + "unable to register hwmon device %ld\n", PTR_ERR(dev)); 918 + } 919 + } 920 + 921 + #else 922 + 923 + static void ds1307_hwmon_register(struct ds1307 *ds1307) 924 + { 925 + } 926 + 927 + #endif /* CONFIG_RTC_DRV_DS1307_HWMON */ 928 + 929 + /*----------------------------------------------------------------------*/ 930 + 931 + /* 932 + * Square-wave output support for DS3231 933 + * Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf 934 + */ 935 + #ifdef CONFIG_COMMON_CLK 936 + 937 + enum { 938 + DS3231_CLK_SQW = 0, 939 + DS3231_CLK_32KHZ, 940 + }; 941 + 942 + #define clk_sqw_to_ds1307(clk) \ 943 + container_of(clk, struct ds1307, clks[DS3231_CLK_SQW]) 944 + #define clk_32khz_to_ds1307(clk) \ 945 + container_of(clk, struct ds1307, clks[DS3231_CLK_32KHZ]) 946 + 947 + static int ds3231_clk_sqw_rates[] = { 948 + 1, 949 + 1024, 950 + 4096, 951 + 8192, 952 + }; 953 + 954 + static int ds1337_write_control(struct ds1307 *ds1307, u8 mask, u8 value) 955 + { 956 + struct i2c_client *client = ds1307->client; 957 + struct mutex *lock = &ds1307->rtc->ops_lock; 958 + int control; 959 + int ret; 960 + 961 + mutex_lock(lock); 962 + 963 + control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL); 964 + if (control < 0) { 965 + ret = control; 966 + goto out; 967 + } 968 + 969 + control &= ~mask; 970 + control |= value; 971 + 972 + ret = i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control); 973 + out: 974 + mutex_unlock(lock); 975 + 976 + return ret; 977 + } 978 + 979 + static unsigned long ds3231_clk_sqw_recalc_rate(struct clk_hw *hw, 980 + unsigned long parent_rate) 981 + { 982 + struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 983 + int control; 984 + int rate_sel = 0; 985 + 986 + control = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_CONTROL); 987 + if (control < 0) 988 + return control; 989 + if (control & DS1337_BIT_RS1) 990 + rate_sel += 1; 991 + if (control & DS1337_BIT_RS2) 992 + rate_sel += 2; 993 + 994 + return ds3231_clk_sqw_rates[rate_sel]; 995 + } 996 + 997 + static long ds3231_clk_sqw_round_rate(struct clk_hw *hw, unsigned long rate, 998 + unsigned long *prate) 999 + { 1000 + int i; 1001 + 1002 + for (i = ARRAY_SIZE(ds3231_clk_sqw_rates) - 1; i >= 0; i--) { 1003 + if (ds3231_clk_sqw_rates[i] <= rate) 1004 + return ds3231_clk_sqw_rates[i]; 1005 + } 1006 + 1007 + return 0; 1008 + } 1009 + 1010 + static int ds3231_clk_sqw_set_rate(struct clk_hw *hw, unsigned long rate, 1011 + unsigned long parent_rate) 1012 + { 1013 + struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1014 + int control = 0; 1015 + int rate_sel; 1016 + 1017 + for (rate_sel = 0; rate_sel < ARRAY_SIZE(ds3231_clk_sqw_rates); 1018 + rate_sel++) { 1019 + if (ds3231_clk_sqw_rates[rate_sel] == rate) 1020 + break; 1021 + } 1022 + 1023 + if (rate_sel == ARRAY_SIZE(ds3231_clk_sqw_rates)) 1024 + return -EINVAL; 1025 + 1026 + if (rate_sel & 1) 1027 + control |= DS1337_BIT_RS1; 1028 + if (rate_sel & 2) 1029 + control |= DS1337_BIT_RS2; 1030 + 1031 + return ds1337_write_control(ds1307, DS1337_BIT_RS1 | DS1337_BIT_RS2, 1032 + control); 1033 + } 1034 + 1035 + static int ds3231_clk_sqw_prepare(struct clk_hw *hw) 1036 + { 1037 + struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1038 + 1039 + return ds1337_write_control(ds1307, DS1337_BIT_INTCN, 0); 1040 + } 1041 + 1042 + static void ds3231_clk_sqw_unprepare(struct clk_hw *hw) 1043 + { 1044 + struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1045 + 1046 + ds1337_write_control(ds1307, DS1337_BIT_INTCN, DS1337_BIT_INTCN); 1047 + } 1048 + 1049 + static int ds3231_clk_sqw_is_prepared(struct clk_hw *hw) 1050 + { 1051 + struct ds1307 *ds1307 = clk_sqw_to_ds1307(hw); 1052 + int control; 1053 + 1054 + control = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_CONTROL); 1055 + if (control < 0) 1056 + return control; 1057 + 1058 + return !(control & DS1337_BIT_INTCN); 1059 + } 1060 + 1061 + static const struct clk_ops ds3231_clk_sqw_ops = { 1062 + .prepare = ds3231_clk_sqw_prepare, 1063 + .unprepare = ds3231_clk_sqw_unprepare, 1064 + .is_prepared = ds3231_clk_sqw_is_prepared, 1065 + .recalc_rate = ds3231_clk_sqw_recalc_rate, 1066 + .round_rate = ds3231_clk_sqw_round_rate, 1067 + .set_rate = ds3231_clk_sqw_set_rate, 1068 + }; 1069 + 1070 + static unsigned long ds3231_clk_32khz_recalc_rate(struct clk_hw *hw, 1071 + unsigned long parent_rate) 1072 + { 1073 + return 32768; 1074 + } 1075 + 1076 + static int ds3231_clk_32khz_control(struct ds1307 *ds1307, bool enable) 1077 + { 1078 + struct i2c_client *client = ds1307->client; 1079 + struct mutex *lock = &ds1307->rtc->ops_lock; 1080 + int status; 1081 + int ret; 1082 + 1083 + mutex_lock(lock); 1084 + 1085 + status = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS); 1086 + if (status < 0) { 1087 + ret = status; 1088 + goto out; 1089 + } 1090 + 1091 + if (enable) 1092 + status |= DS3231_BIT_EN32KHZ; 1093 + else 1094 + status &= ~DS3231_BIT_EN32KHZ; 1095 + 1096 + ret = i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, status); 1097 + out: 1098 + mutex_unlock(lock); 1099 + 1100 + return ret; 1101 + } 1102 + 1103 + static int ds3231_clk_32khz_prepare(struct clk_hw *hw) 1104 + { 1105 + struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); 1106 + 1107 + return ds3231_clk_32khz_control(ds1307, true); 1108 + } 1109 + 1110 + static void ds3231_clk_32khz_unprepare(struct clk_hw *hw) 1111 + { 1112 + struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); 1113 + 1114 + ds3231_clk_32khz_control(ds1307, false); 1115 + } 1116 + 1117 + static int ds3231_clk_32khz_is_prepared(struct clk_hw *hw) 1118 + { 1119 + struct ds1307 *ds1307 = clk_32khz_to_ds1307(hw); 1120 + int status; 1121 + 1122 + status = i2c_smbus_read_byte_data(ds1307->client, DS1337_REG_STATUS); 1123 + if (status < 0) 1124 + return status; 1125 + 1126 + return !!(status & DS3231_BIT_EN32KHZ); 1127 + } 1128 + 1129 + static const struct clk_ops ds3231_clk_32khz_ops = { 1130 + .prepare = ds3231_clk_32khz_prepare, 1131 + .unprepare = ds3231_clk_32khz_unprepare, 1132 + .is_prepared = ds3231_clk_32khz_is_prepared, 1133 + .recalc_rate = ds3231_clk_32khz_recalc_rate, 1134 + }; 1135 + 1136 + static struct clk_init_data ds3231_clks_init[] = { 1137 + [DS3231_CLK_SQW] = { 1138 + .name = "ds3231_clk_sqw", 1139 + .ops = &ds3231_clk_sqw_ops, 1140 + .flags = CLK_IS_ROOT, 1141 + }, 1142 + [DS3231_CLK_32KHZ] = { 1143 + .name = "ds3231_clk_32khz", 1144 + .ops = &ds3231_clk_32khz_ops, 1145 + .flags = CLK_IS_ROOT, 1146 + }, 1147 + }; 1148 + 1149 + static int ds3231_clks_register(struct ds1307 *ds1307) 1150 + { 1151 + struct i2c_client *client = ds1307->client; 1152 + struct device_node *node = client->dev.of_node; 1153 + struct clk_onecell_data *onecell; 1154 + int i; 1155 + 1156 + onecell = devm_kzalloc(&client->dev, sizeof(*onecell), GFP_KERNEL); 1157 + if (!onecell) 1158 + return -ENOMEM; 1159 + 1160 + onecell->clk_num = ARRAY_SIZE(ds3231_clks_init); 1161 + onecell->clks = devm_kcalloc(&client->dev, onecell->clk_num, 1162 + sizeof(onecell->clks[0]), GFP_KERNEL); 1163 + if (!onecell->clks) 1164 + return -ENOMEM; 1165 + 1166 + for (i = 0; i < ARRAY_SIZE(ds3231_clks_init); i++) { 1167 + struct clk_init_data init = ds3231_clks_init[i]; 1168 + 1169 + /* 1170 + * Interrupt signal due to alarm conditions and square-wave 1171 + * output share same pin, so don't initialize both. 1172 + */ 1173 + if (i == DS3231_CLK_SQW && test_bit(HAS_ALARM, &ds1307->flags)) 1174 + continue; 1175 + 1176 + /* optional override of the clockname */ 1177 + of_property_read_string_index(node, "clock-output-names", i, 1178 + &init.name); 1179 + ds1307->clks[i].init = &init; 1180 + 1181 + onecell->clks[i] = devm_clk_register(&client->dev, 1182 + &ds1307->clks[i]); 1183 + if (IS_ERR(onecell->clks[i])) 1184 + return PTR_ERR(onecell->clks[i]); 1185 + } 1186 + 1187 + if (!node) 1188 + return 0; 1189 + 1190 + of_clk_add_provider(node, of_clk_src_onecell_get, onecell); 1191 + 1192 + return 0; 1193 + } 1194 + 1195 + static void ds1307_clks_register(struct ds1307 *ds1307) 1196 + { 1197 + int ret; 1198 + 1199 + if (ds1307->type != ds_3231) 1200 + return; 1201 + 1202 + ret = ds3231_clks_register(ds1307); 1203 + if (ret) { 1204 + dev_warn(&ds1307->client->dev, 1205 + "unable to register clock device %d\n", ret); 1206 + } 1207 + } 1208 + 1209 + #else 1210 + 1211 + static void ds1307_clks_register(struct ds1307 *ds1307) 1212 + { 1213 + } 1214 + 1215 + #endif /* CONFIG_COMMON_CLK */ 1216 + 852 1217 static int ds1307_probe(struct i2c_client *client, 853 1218 const struct i2c_device_id *id) 854 1219 { ··· 1230 851 struct chip_desc *chip = &chips[id->driver_data]; 1231 852 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1232 853 bool want_irq = false; 854 + bool ds1307_can_wakeup_device = false; 1233 855 unsigned char *buf; 1234 856 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); 1235 857 irq_handler_t irq_handler = ds1307_irq; ··· 1278 898 ds1307->write_block_data = ds1307_write_block_data; 1279 899 } 1280 900 901 + #ifdef CONFIG_OF 902 + /* 903 + * For devices with no IRQ directly connected to the SoC, the RTC chip 904 + * can be forced as a wakeup source by stating that explicitly in 905 + * the device's .dts file using the "wakeup-source" boolean property. 906 + * If the "wakeup-source" property is set, don't request an IRQ. 907 + * This will guarantee the 'wakealarm' sysfs entry is available on the device, 908 + * if supported by the RTC. 909 + */ 910 + if (of_property_read_bool(client->dev.of_node, "wakeup-source")) { 911 + ds1307_can_wakeup_device = true; 912 + } 913 + #endif 914 + 1281 915 switch (ds1307->type) { 1282 916 case ds_1337: 1283 917 case ds_1339: ··· 1310 916 ds1307->regs[0] &= ~DS1337_BIT_nEOSC; 1311 917 1312 918 /* 1313 - * Using IRQ? Disable the square wave and both alarms. 919 + * Using IRQ or defined as wakeup-source? 920 + * Disable the square wave and both alarms. 1314 921 * For some variants, be sure alarms can trigger when we're 1315 922 * running on Vbackup (BBSQI/BBSQW) 1316 923 */ 1317 - if (ds1307->client->irq > 0 && chip->alarm) { 924 + if (chip->alarm && (ds1307->client->irq > 0 || 925 + ds1307_can_wakeup_device)) { 1318 926 ds1307->regs[0] |= DS1337_BIT_INTCN 1319 927 | bbsqi_bitpos[ds1307->type]; 1320 928 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); ··· 1531 1135 return PTR_ERR(ds1307->rtc); 1532 1136 } 1533 1137 1138 + if (ds1307_can_wakeup_device) { 1139 + /* Disable request for an IRQ */ 1140 + want_irq = false; 1141 + dev_info(&client->dev, "'wakeup-source' is set, request for an IRQ is disabled!\n"); 1142 + /* We cannot support UIE mode if we do not have an IRQ line */ 1143 + ds1307->rtc->uie_unsupported = 1; 1144 + } 1145 + 1534 1146 if (want_irq) { 1535 1147 err = devm_request_threaded_irq(&client->dev, 1536 1148 client->irq, NULL, irq_handler, ··· 1585 1181 } 1586 1182 } 1587 1183 } 1184 + 1185 + ds1307_hwmon_register(ds1307); 1186 + ds1307_clks_register(ds1307); 1588 1187 1589 1188 return 0; 1590 1189
+5 -4
drivers/rtc/rtc-ds1685.c
··· 187 187 * Only use this where you are certain another lock will not be held. 188 188 */ 189 189 static inline void 190 - ds1685_rtc_begin_ctrl_access(struct ds1685_priv *rtc, unsigned long flags) 190 + ds1685_rtc_begin_ctrl_access(struct ds1685_priv *rtc, unsigned long *flags) 191 191 { 192 - spin_lock_irqsave(&rtc->lock, flags); 192 + spin_lock_irqsave(&rtc->lock, *flags); 193 193 ds1685_rtc_switch_to_bank1(rtc); 194 194 } 195 195 ··· 1300 1300 { 1301 1301 struct ds1685_priv *rtc = dev_get_drvdata(dev); 1302 1302 u8 reg = 0, bit = 0, tmp; 1303 - unsigned long flags = 0; 1303 + unsigned long flags; 1304 1304 long int val = 0; 1305 1305 const struct ds1685_rtc_ctrl_regs *reg_info = 1306 1306 ds1685_rtc_sysfs_ctrl_regs_lookup(attr->attr.name); ··· 1321 1321 bit = reg_info->bit; 1322 1322 1323 1323 /* Safe to spinlock during a write. */ 1324 - ds1685_rtc_begin_ctrl_access(rtc, flags); 1324 + ds1685_rtc_begin_ctrl_access(rtc, &flags); 1325 1325 tmp = rtc->read(rtc, reg); 1326 1326 rtc->write(rtc, reg, (val ? (tmp | bit) : (tmp & ~(bit)))); 1327 1327 ds1685_rtc_end_ctrl_access(rtc, flags); ··· 2161 2161 /* Check for valid RTC data, else, spin forever. */ 2162 2162 if (unlikely(!pdev)) { 2163 2163 pr_emerg("platform device data not available, spinning forever ...\n"); 2164 + while(1); 2164 2165 unreachable(); 2165 2166 } else { 2166 2167 /* Get the rtc data. */
+283 -193
drivers/rtc/rtc-ds3232.c
··· 1 1 /* 2 - * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C 2 + * RTC client/driver for the Maxim/Dallas DS3232/DS3234 Real-Time Clock 3 3 * 4 4 * Copyright (C) 2009-2011 Freescale Semiconductor. 5 5 * Author: Jack Lan <jack.lan@freescale.com> 6 + * Copyright (C) 2008 MIMOMax Wireless Ltd. 6 7 * 7 8 * This program is free software; you can redistribute it and/or modify it 8 9 * under the terms of the GNU General Public License as published by the 9 10 * Free Software Foundation; either version 2 of the License, or (at your 10 11 * option) any later version. 11 - */ 12 - /* 13 - * It would be more efficient to use i2c msgs/i2c_transfer directly but, as 14 - * recommened in .../Documentation/i2c/writing-clients section 15 - * "Sending and receiving", using SMBus level communication is preferred. 16 12 */ 17 13 18 14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt ··· 17 21 #include <linux/module.h> 18 22 #include <linux/interrupt.h> 19 23 #include <linux/i2c.h> 24 + #include <linux/spi/spi.h> 20 25 #include <linux/rtc.h> 21 26 #include <linux/bcd.h> 22 - #include <linux/workqueue.h> 23 27 #include <linux/slab.h> 28 + #include <linux/regmap.h> 24 29 25 30 #define DS3232_REG_SECONDS 0x00 26 31 #define DS3232_REG_MINUTES 0x01 ··· 47 50 # define DS3232_REG_SR_A1F 0x01 48 51 49 52 struct ds3232 { 50 - struct i2c_client *client; 53 + struct device *dev; 54 + struct regmap *regmap; 55 + int irq; 51 56 struct rtc_device *rtc; 52 - struct work_struct work; 53 57 54 - /* The mutex protects alarm operations, and prevents a race 55 - * between the enable_irq() in the workqueue and the free_irq() 56 - * in the remove function. 57 - */ 58 - struct mutex mutex; 59 58 bool suspended; 60 - int exiting; 61 59 }; 62 60 63 - static struct i2c_driver ds3232_driver; 64 - 65 - static int ds3232_check_rtc_status(struct i2c_client *client) 61 + static int ds3232_check_rtc_status(struct device *dev) 66 62 { 63 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 67 64 int ret = 0; 68 65 int control, stat; 69 66 70 - stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR); 71 - if (stat < 0) 72 - return stat; 67 + ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); 68 + if (ret) 69 + return ret; 73 70 74 71 if (stat & DS3232_REG_SR_OSF) 75 - dev_warn(&client->dev, 72 + dev_warn(dev, 76 73 "oscillator discontinuity flagged, " 77 74 "time unreliable\n"); 78 75 79 76 stat &= ~(DS3232_REG_SR_OSF | DS3232_REG_SR_A1F | DS3232_REG_SR_A2F); 80 77 81 - ret = i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat); 82 - if (ret < 0) 78 + ret = regmap_write(ds3232->regmap, DS3232_REG_SR, stat); 79 + if (ret) 83 80 return ret; 84 81 85 82 /* If the alarm is pending, clear it before requesting ··· 81 90 * before everything is initialized. 82 91 */ 83 92 84 - control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 85 - if (control < 0) 86 - return control; 93 + ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); 94 + if (ret) 95 + return ret; 87 96 88 97 control &= ~(DS3232_REG_CR_A1IE | DS3232_REG_CR_A2IE); 89 98 control |= DS3232_REG_CR_INTCN; 90 99 91 - return i2c_smbus_write_byte_data(client, DS3232_REG_CR, control); 100 + return regmap_write(ds3232->regmap, DS3232_REG_CR, control); 92 101 } 93 102 94 103 static int ds3232_read_time(struct device *dev, struct rtc_time *time) 95 104 { 96 - struct i2c_client *client = to_i2c_client(dev); 105 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 97 106 int ret; 98 107 u8 buf[7]; 99 108 unsigned int year, month, day, hour, minute, second; 100 109 unsigned int week, twelve_hr, am_pm; 101 110 unsigned int century, add_century = 0; 102 111 103 - ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_SECONDS, 7, buf); 104 - 105 - if (ret < 0) 112 + ret = regmap_bulk_read(ds3232->regmap, DS3232_REG_SECONDS, buf, 7); 113 + if (ret) 106 114 return ret; 107 - if (ret < 7) 108 - return -EIO; 109 115 110 116 second = buf[0]; 111 117 minute = buf[1]; ··· 147 159 148 160 static int ds3232_set_time(struct device *dev, struct rtc_time *time) 149 161 { 150 - struct i2c_client *client = to_i2c_client(dev); 162 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 151 163 u8 buf[7]; 152 164 153 165 /* Extract time from rtc_time and load into ds3232*/ ··· 167 179 buf[6] = bin2bcd(time->tm_year); 168 180 } 169 181 170 - return i2c_smbus_write_i2c_block_data(client, 171 - DS3232_REG_SECONDS, 7, buf); 182 + return regmap_bulk_write(ds3232->regmap, DS3232_REG_SECONDS, buf, 7); 172 183 } 173 184 174 185 /* ··· 177 190 */ 178 191 static int ds3232_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 179 192 { 180 - struct i2c_client *client = to_i2c_client(dev); 181 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 193 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 182 194 int control, stat; 183 195 int ret; 184 196 u8 buf[4]; 185 197 186 - mutex_lock(&ds3232->mutex); 187 - 188 - ret = i2c_smbus_read_byte_data(client, DS3232_REG_SR); 189 - if (ret < 0) 198 + ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); 199 + if (ret) 190 200 goto out; 191 - stat = ret; 192 - ret = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 193 - if (ret < 0) 201 + ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); 202 + if (ret) 194 203 goto out; 195 - control = ret; 196 - ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf); 197 - if (ret < 0) 204 + ret = regmap_bulk_read(ds3232->regmap, DS3232_REG_ALARM1, buf, 4); 205 + if (ret) 198 206 goto out; 199 207 200 208 alarm->time.tm_sec = bcd2bin(buf[0] & 0x7F); ··· 208 226 209 227 ret = 0; 210 228 out: 211 - mutex_unlock(&ds3232->mutex); 212 229 return ret; 213 230 } 214 231 ··· 217 236 */ 218 237 static int ds3232_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 219 238 { 220 - struct i2c_client *client = to_i2c_client(dev); 221 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 239 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 222 240 int control, stat; 223 241 int ret; 224 242 u8 buf[4]; 225 243 226 - if (client->irq <= 0) 244 + if (ds3232->irq <= 0) 227 245 return -EINVAL; 228 - 229 - mutex_lock(&ds3232->mutex); 230 246 231 247 buf[0] = bin2bcd(alarm->time.tm_sec); 232 248 buf[1] = bin2bcd(alarm->time.tm_min); ··· 231 253 buf[3] = bin2bcd(alarm->time.tm_mday); 232 254 233 255 /* clear alarm interrupt enable bit */ 234 - ret = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 235 - if (ret < 0) 256 + ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); 257 + if (ret) 236 258 goto out; 237 - control = ret; 238 259 control &= ~(DS3232_REG_CR_A1IE | DS3232_REG_CR_A2IE); 239 - ret = i2c_smbus_write_byte_data(client, DS3232_REG_CR, control); 240 - if (ret < 0) 260 + ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control); 261 + if (ret) 241 262 goto out; 242 263 243 264 /* clear any pending alarm flag */ 244 - ret = i2c_smbus_read_byte_data(client, DS3232_REG_SR); 245 - if (ret < 0) 265 + ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); 266 + if (ret) 246 267 goto out; 247 - stat = ret; 248 268 stat &= ~(DS3232_REG_SR_A1F | DS3232_REG_SR_A2F); 249 - ret = i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat); 250 - if (ret < 0) 269 + ret = regmap_write(ds3232->regmap, DS3232_REG_SR, stat); 270 + if (ret) 251 271 goto out; 252 272 253 - ret = i2c_smbus_write_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf); 273 + ret = regmap_bulk_write(ds3232->regmap, DS3232_REG_ALARM1, buf, 4); 274 + if (ret) 275 + goto out; 254 276 255 277 if (alarm->enabled) { 256 278 control |= DS3232_REG_CR_A1IE; 257 - ret = i2c_smbus_write_byte_data(client, DS3232_REG_CR, control); 279 + ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control); 258 280 } 259 281 out: 260 - mutex_unlock(&ds3232->mutex); 261 282 return ret; 262 283 } 263 284 264 - static void ds3232_update_alarm(struct i2c_client *client) 285 + static int ds3232_update_alarm(struct device *dev, unsigned int enabled) 265 286 { 266 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 287 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 267 288 int control; 268 289 int ret; 269 - u8 buf[4]; 270 290 271 - mutex_lock(&ds3232->mutex); 291 + ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); 292 + if (ret) 293 + return ret; 272 294 273 - ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf); 274 - if (ret < 0) 275 - goto unlock; 276 - 277 - buf[0] = bcd2bin(buf[0]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ? 278 - 0x80 : buf[0]; 279 - buf[1] = bcd2bin(buf[1]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ? 280 - 0x80 : buf[1]; 281 - buf[2] = bcd2bin(buf[2]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ? 282 - 0x80 : buf[2]; 283 - buf[3] = bcd2bin(buf[3]) < 0 || (ds3232->rtc->irq_data & RTC_UF) ? 284 - 0x80 : buf[3]; 285 - 286 - ret = i2c_smbus_write_i2c_block_data(client, DS3232_REG_ALARM1, 4, buf); 287 - if (ret < 0) 288 - goto unlock; 289 - 290 - control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 291 - if (control < 0) 292 - goto unlock; 293 - 294 - if (ds3232->rtc->irq_data & (RTC_AF | RTC_UF)) 295 + if (enabled) 295 296 /* enable alarm1 interrupt */ 296 297 control |= DS3232_REG_CR_A1IE; 297 298 else 298 299 /* disable alarm1 interrupt */ 299 300 control &= ~(DS3232_REG_CR_A1IE); 300 - i2c_smbus_write_byte_data(client, DS3232_REG_CR, control); 301 + ret = regmap_write(ds3232->regmap, DS3232_REG_CR, control); 301 302 302 - unlock: 303 - mutex_unlock(&ds3232->mutex); 303 + return ret; 304 304 } 305 305 306 306 static int ds3232_alarm_irq_enable(struct device *dev, unsigned int enabled) 307 307 { 308 - struct i2c_client *client = to_i2c_client(dev); 309 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 308 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 310 309 311 - if (client->irq <= 0) 310 + if (ds3232->irq <= 0) 312 311 return -EINVAL; 313 312 314 - if (enabled) 315 - ds3232->rtc->irq_data |= RTC_AF; 316 - else 317 - ds3232->rtc->irq_data &= ~RTC_AF; 318 - 319 - ds3232_update_alarm(client); 320 - return 0; 313 + return ds3232_update_alarm(dev, enabled); 321 314 } 322 315 323 316 static irqreturn_t ds3232_irq(int irq, void *dev_id) 324 317 { 325 - struct i2c_client *client = dev_id; 326 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 327 - 328 - disable_irq_nosync(irq); 329 - 330 - /* 331 - * If rtc as a wakeup source, can't schedule the work 332 - * at system resume flow, because at this time the i2c bus 333 - * has not been resumed. 334 - */ 335 - if (!ds3232->suspended) 336 - schedule_work(&ds3232->work); 337 - 338 - return IRQ_HANDLED; 339 - } 340 - 341 - static void ds3232_work(struct work_struct *work) 342 - { 343 - struct ds3232 *ds3232 = container_of(work, struct ds3232, work); 344 - struct i2c_client *client = ds3232->client; 318 + struct device *dev = dev_id; 319 + struct ds3232 *ds3232 = dev_get_drvdata(dev); 320 + struct mutex *lock = &ds3232->rtc->ops_lock; 321 + int ret; 345 322 int stat, control; 346 323 347 - mutex_lock(&ds3232->mutex); 324 + mutex_lock(lock); 348 325 349 - stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR); 350 - if (stat < 0) 326 + ret = regmap_read(ds3232->regmap, DS3232_REG_SR, &stat); 327 + if (ret) 351 328 goto unlock; 352 329 353 330 if (stat & DS3232_REG_SR_A1F) { 354 - control = i2c_smbus_read_byte_data(client, DS3232_REG_CR); 355 - if (control < 0) { 356 - pr_warn("Read Control Register error - Disable IRQ%d\n", 357 - client->irq); 331 + ret = regmap_read(ds3232->regmap, DS3232_REG_CR, &control); 332 + if (ret) { 333 + dev_warn(ds3232->dev, 334 + "Read Control Register error %d\n", ret); 358 335 } else { 359 336 /* disable alarm1 interrupt */ 360 337 control &= ~(DS3232_REG_CR_A1IE); 361 - i2c_smbus_write_byte_data(client, DS3232_REG_CR, 362 - control); 338 + ret = regmap_write(ds3232->regmap, DS3232_REG_CR, 339 + control); 340 + if (ret) { 341 + dev_warn(ds3232->dev, 342 + "Write Control Register error %d\n", 343 + ret); 344 + goto unlock; 345 + } 363 346 364 347 /* clear the alarm pend flag */ 365 348 stat &= ~DS3232_REG_SR_A1F; 366 - i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat); 349 + ret = regmap_write(ds3232->regmap, DS3232_REG_SR, stat); 350 + if (ret) { 351 + dev_warn(ds3232->dev, 352 + "Write Status Register error %d\n", 353 + ret); 354 + goto unlock; 355 + } 367 356 368 357 rtc_update_irq(ds3232->rtc, 1, RTC_AF | RTC_IRQF); 369 - 370 - if (!ds3232->exiting) 371 - enable_irq(client->irq); 372 358 } 373 359 } 374 360 375 361 unlock: 376 - mutex_unlock(&ds3232->mutex); 362 + mutex_unlock(lock); 363 + 364 + return IRQ_HANDLED; 377 365 } 378 366 379 367 static const struct rtc_class_ops ds3232_rtc_ops = { ··· 350 406 .alarm_irq_enable = ds3232_alarm_irq_enable, 351 407 }; 352 408 353 - static int ds3232_probe(struct i2c_client *client, 354 - const struct i2c_device_id *id) 409 + static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, 410 + const char *name) 355 411 { 356 412 struct ds3232 *ds3232; 357 413 int ret; 358 414 359 - ds3232 = devm_kzalloc(&client->dev, sizeof(struct ds3232), GFP_KERNEL); 415 + ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); 360 416 if (!ds3232) 361 417 return -ENOMEM; 362 418 363 - ds3232->client = client; 364 - i2c_set_clientdata(client, ds3232); 419 + ds3232->regmap = regmap; 420 + ds3232->irq = irq; 421 + ds3232->dev = dev; 422 + dev_set_drvdata(dev, ds3232); 365 423 366 - INIT_WORK(&ds3232->work, ds3232_work); 367 - mutex_init(&ds3232->mutex); 368 - 369 - ret = ds3232_check_rtc_status(client); 424 + ret = ds3232_check_rtc_status(dev); 370 425 if (ret) 371 426 return ret; 372 427 373 - if (client->irq > 0) { 374 - ret = devm_request_irq(&client->dev, client->irq, ds3232_irq, 375 - IRQF_SHARED, "ds3232", client); 428 + if (ds3232->irq > 0) { 429 + ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, 430 + ds3232_irq, 431 + IRQF_SHARED | IRQF_ONESHOT, 432 + name, dev); 376 433 if (ret) { 377 - dev_err(&client->dev, "unable to request IRQ\n"); 378 - } 379 - device_init_wakeup(&client->dev, 1); 434 + ds3232->irq = 0; 435 + dev_err(dev, "unable to request IRQ\n"); 436 + } else 437 + device_init_wakeup(dev, 1); 380 438 } 381 - ds3232->rtc = devm_rtc_device_register(&client->dev, client->name, 382 - &ds3232_rtc_ops, THIS_MODULE); 439 + ds3232->rtc = devm_rtc_device_register(dev, name, &ds3232_rtc_ops, 440 + THIS_MODULE); 441 + 383 442 return PTR_ERR_OR_ZERO(ds3232->rtc); 384 - } 385 - 386 - static int ds3232_remove(struct i2c_client *client) 387 - { 388 - struct ds3232 *ds3232 = i2c_get_clientdata(client); 389 - 390 - if (client->irq > 0) { 391 - mutex_lock(&ds3232->mutex); 392 - ds3232->exiting = 1; 393 - mutex_unlock(&ds3232->mutex); 394 - 395 - devm_free_irq(&client->dev, client->irq, client); 396 - cancel_work_sync(&ds3232->work); 397 - } 398 - 399 - return 0; 400 443 } 401 444 402 445 #ifdef CONFIG_PM_SLEEP 403 446 static int ds3232_suspend(struct device *dev) 404 447 { 405 448 struct ds3232 *ds3232 = dev_get_drvdata(dev); 406 - struct i2c_client *client = to_i2c_client(dev); 407 449 408 - if (device_can_wakeup(dev)) { 409 - ds3232->suspended = true; 410 - if (irq_set_irq_wake(client->irq, 1)) { 450 + if (device_may_wakeup(dev)) { 451 + if (enable_irq_wake(ds3232->irq)) 411 452 dev_warn_once(dev, "Cannot set wakeup source\n"); 412 - ds3232->suspended = false; 413 - } 414 453 } 415 454 416 455 return 0; ··· 402 475 static int ds3232_resume(struct device *dev) 403 476 { 404 477 struct ds3232 *ds3232 = dev_get_drvdata(dev); 405 - struct i2c_client *client = to_i2c_client(dev); 406 478 407 - if (ds3232->suspended) { 408 - ds3232->suspended = false; 409 - 410 - /* Clear the hardware alarm pend flag */ 411 - schedule_work(&ds3232->work); 412 - 413 - irq_set_irq_wake(client->irq, 0); 414 - } 479 + if (device_may_wakeup(dev)) 480 + disable_irq_wake(ds3232->irq); 415 481 416 482 return 0; 417 483 } ··· 413 493 static const struct dev_pm_ops ds3232_pm_ops = { 414 494 SET_SYSTEM_SLEEP_PM_OPS(ds3232_suspend, ds3232_resume) 415 495 }; 496 + 497 + #if IS_ENABLED(CONFIG_I2C) 498 + 499 + static int ds3232_i2c_probe(struct i2c_client *client, 500 + const struct i2c_device_id *id) 501 + { 502 + struct regmap *regmap; 503 + static const struct regmap_config config = { 504 + .reg_bits = 8, 505 + .val_bits = 8, 506 + }; 507 + 508 + regmap = devm_regmap_init_i2c(client, &config); 509 + if (IS_ERR(regmap)) { 510 + dev_err(&client->dev, "%s: regmap allocation failed: %ld\n", 511 + __func__, PTR_ERR(regmap)); 512 + return PTR_ERR(regmap); 513 + } 514 + 515 + return ds3232_probe(&client->dev, regmap, client->irq, client->name); 516 + } 416 517 417 518 static const struct i2c_device_id ds3232_id[] = { 418 519 { "ds3232", 0 }, ··· 446 505 .name = "rtc-ds3232", 447 506 .pm = &ds3232_pm_ops, 448 507 }, 449 - .probe = ds3232_probe, 450 - .remove = ds3232_remove, 508 + .probe = ds3232_i2c_probe, 451 509 .id_table = ds3232_id, 452 510 }; 453 511 454 - module_i2c_driver(ds3232_driver); 512 + static int ds3232_register_driver(void) 513 + { 514 + return i2c_add_driver(&ds3232_driver); 515 + } 516 + 517 + static void ds3232_unregister_driver(void) 518 + { 519 + i2c_del_driver(&ds3232_driver); 520 + } 521 + 522 + #else 523 + 524 + static int ds3232_register_driver(void) 525 + { 526 + return 0; 527 + } 528 + 529 + static void ds3232_unregister_driver(void) 530 + { 531 + } 532 + 533 + #endif 534 + 535 + #if IS_ENABLED(CONFIG_SPI_MASTER) 536 + 537 + static int ds3234_probe(struct spi_device *spi) 538 + { 539 + int res; 540 + unsigned int tmp; 541 + static const struct regmap_config config = { 542 + .reg_bits = 8, 543 + .val_bits = 8, 544 + .write_flag_mask = 0x80, 545 + }; 546 + struct regmap *regmap; 547 + 548 + regmap = devm_regmap_init_spi(spi, &config); 549 + if (IS_ERR(regmap)) { 550 + dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", 551 + __func__, PTR_ERR(regmap)); 552 + return PTR_ERR(regmap); 553 + } 554 + 555 + spi->mode = SPI_MODE_3; 556 + spi->bits_per_word = 8; 557 + spi_setup(spi); 558 + 559 + res = regmap_read(regmap, DS3232_REG_SECONDS, &tmp); 560 + if (res) 561 + return res; 562 + 563 + /* Control settings 564 + * 565 + * CONTROL_REG 566 + * BIT 7 6 5 4 3 2 1 0 567 + * EOSC BBSQW CONV RS2 RS1 INTCN A2IE A1IE 568 + * 569 + * 0 0 0 1 1 1 0 0 570 + * 571 + * CONTROL_STAT_REG 572 + * BIT 7 6 5 4 3 2 1 0 573 + * OSF BB32kHz CRATE1 CRATE0 EN32kHz BSY A2F A1F 574 + * 575 + * 1 0 0 0 1 0 0 0 576 + */ 577 + res = regmap_read(regmap, DS3232_REG_CR, &tmp); 578 + if (res) 579 + return res; 580 + res = regmap_write(regmap, DS3232_REG_CR, tmp & 0x1c); 581 + if (res) 582 + return res; 583 + 584 + res = regmap_read(regmap, DS3232_REG_SR, &tmp); 585 + if (res) 586 + return res; 587 + res = regmap_write(regmap, DS3232_REG_SR, tmp & 0x88); 588 + if (res) 589 + return res; 590 + 591 + /* Print our settings */ 592 + res = regmap_read(regmap, DS3232_REG_CR, &tmp); 593 + if (res) 594 + return res; 595 + dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp); 596 + 597 + res = regmap_read(regmap, DS3232_REG_SR, &tmp); 598 + if (res) 599 + return res; 600 + dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); 601 + 602 + return ds3232_probe(&spi->dev, regmap, spi->irq, "ds3234"); 603 + } 604 + 605 + static struct spi_driver ds3234_driver = { 606 + .driver = { 607 + .name = "ds3234", 608 + }, 609 + .probe = ds3234_probe, 610 + }; 611 + 612 + static int ds3234_register_driver(void) 613 + { 614 + return spi_register_driver(&ds3234_driver); 615 + } 616 + 617 + static void ds3234_unregister_driver(void) 618 + { 619 + spi_unregister_driver(&ds3234_driver); 620 + } 621 + 622 + #else 623 + 624 + static int ds3234_register_driver(void) 625 + { 626 + return 0; 627 + } 628 + 629 + static void ds3234_unregister_driver(void) 630 + { 631 + } 632 + 633 + #endif 634 + 635 + static int __init ds323x_init(void) 636 + { 637 + int ret; 638 + 639 + ret = ds3232_register_driver(); 640 + if (ret) { 641 + pr_err("Failed to register ds3232 driver: %d\n", ret); 642 + return ret; 643 + } 644 + 645 + ret = ds3234_register_driver(); 646 + if (ret) { 647 + pr_err("Failed to register ds3234 driver: %d\n", ret); 648 + ds3232_unregister_driver(); 649 + } 650 + 651 + return ret; 652 + } 653 + module_init(ds323x_init) 654 + 655 + static void __exit ds323x_exit(void) 656 + { 657 + ds3234_unregister_driver(); 658 + ds3232_unregister_driver(); 659 + } 660 + module_exit(ds323x_exit) 455 661 456 662 MODULE_AUTHOR("Srikanth Srinivasan <srikanth.srinivasan@freescale.com>"); 457 - MODULE_DESCRIPTION("Maxim/Dallas DS3232 RTC Driver"); 663 + MODULE_AUTHOR("Dennis Aberilla <denzzzhome@yahoo.com>"); 664 + MODULE_DESCRIPTION("Maxim/Dallas DS3232/DS3234 RTC Driver"); 458 665 MODULE_LICENSE("GPL"); 666 + MODULE_ALIAS("spi:ds3234");
-171
drivers/rtc/rtc-ds3234.c
··· 1 - /* rtc-ds3234.c 2 - * 3 - * Driver for Dallas Semiconductor (DS3234) SPI RTC with Integrated Crystal 4 - * and SRAM. 5 - * 6 - * Copyright (C) 2008 MIMOMax Wireless Ltd. 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - * 12 - */ 13 - 14 - #include <linux/init.h> 15 - #include <linux/module.h> 16 - #include <linux/device.h> 17 - #include <linux/platform_device.h> 18 - #include <linux/rtc.h> 19 - #include <linux/spi/spi.h> 20 - #include <linux/bcd.h> 21 - 22 - #define DS3234_REG_SECONDS 0x00 23 - #define DS3234_REG_MINUTES 0x01 24 - #define DS3234_REG_HOURS 0x02 25 - #define DS3234_REG_DAY 0x03 26 - #define DS3234_REG_DATE 0x04 27 - #define DS3234_REG_MONTH 0x05 28 - #define DS3234_REG_YEAR 0x06 29 - #define DS3234_REG_CENTURY (1 << 7) /* Bit 7 of the Month register */ 30 - 31 - #define DS3234_REG_CONTROL 0x0E 32 - #define DS3234_REG_CONT_STAT 0x0F 33 - 34 - static int ds3234_set_reg(struct device *dev, unsigned char address, 35 - unsigned char data) 36 - { 37 - struct spi_device *spi = to_spi_device(dev); 38 - unsigned char buf[2]; 39 - 40 - /* MSB must be '1' to indicate write */ 41 - buf[0] = address | 0x80; 42 - buf[1] = data; 43 - 44 - return spi_write_then_read(spi, buf, 2, NULL, 0); 45 - } 46 - 47 - static int ds3234_get_reg(struct device *dev, unsigned char address, 48 - unsigned char *data) 49 - { 50 - struct spi_device *spi = to_spi_device(dev); 51 - 52 - *data = address & 0x7f; 53 - 54 - return spi_write_then_read(spi, data, 1, data, 1); 55 - } 56 - 57 - static int ds3234_read_time(struct device *dev, struct rtc_time *dt) 58 - { 59 - int err; 60 - unsigned char buf[8]; 61 - struct spi_device *spi = to_spi_device(dev); 62 - 63 - buf[0] = 0x00; /* Start address */ 64 - 65 - err = spi_write_then_read(spi, buf, 1, buf, 8); 66 - if (err != 0) 67 - return err; 68 - 69 - /* Seconds, Minutes, Hours, Day, Date, Month, Year */ 70 - dt->tm_sec = bcd2bin(buf[0]); 71 - dt->tm_min = bcd2bin(buf[1]); 72 - dt->tm_hour = bcd2bin(buf[2] & 0x3f); 73 - dt->tm_wday = bcd2bin(buf[3]) - 1; /* 0 = Sun */ 74 - dt->tm_mday = bcd2bin(buf[4]); 75 - dt->tm_mon = bcd2bin(buf[5] & 0x1f) - 1; /* 0 = Jan */ 76 - dt->tm_year = bcd2bin(buf[6] & 0xff) + 100; /* Assume 20YY */ 77 - 78 - return rtc_valid_tm(dt); 79 - } 80 - 81 - static int ds3234_set_time(struct device *dev, struct rtc_time *dt) 82 - { 83 - ds3234_set_reg(dev, DS3234_REG_SECONDS, bin2bcd(dt->tm_sec)); 84 - ds3234_set_reg(dev, DS3234_REG_MINUTES, bin2bcd(dt->tm_min)); 85 - ds3234_set_reg(dev, DS3234_REG_HOURS, bin2bcd(dt->tm_hour) & 0x3f); 86 - 87 - /* 0 = Sun */ 88 - ds3234_set_reg(dev, DS3234_REG_DAY, bin2bcd(dt->tm_wday + 1)); 89 - ds3234_set_reg(dev, DS3234_REG_DATE, bin2bcd(dt->tm_mday)); 90 - 91 - /* 0 = Jan */ 92 - ds3234_set_reg(dev, DS3234_REG_MONTH, bin2bcd(dt->tm_mon + 1)); 93 - 94 - /* Assume 20YY although we just want to make sure not to go negative. */ 95 - if (dt->tm_year > 100) 96 - dt->tm_year -= 100; 97 - 98 - ds3234_set_reg(dev, DS3234_REG_YEAR, bin2bcd(dt->tm_year)); 99 - 100 - return 0; 101 - } 102 - 103 - static const struct rtc_class_ops ds3234_rtc_ops = { 104 - .read_time = ds3234_read_time, 105 - .set_time = ds3234_set_time, 106 - }; 107 - 108 - static int ds3234_probe(struct spi_device *spi) 109 - { 110 - struct rtc_device *rtc; 111 - unsigned char tmp; 112 - int res; 113 - 114 - spi->mode = SPI_MODE_3; 115 - spi->bits_per_word = 8; 116 - spi_setup(spi); 117 - 118 - res = ds3234_get_reg(&spi->dev, DS3234_REG_SECONDS, &tmp); 119 - if (res != 0) 120 - return res; 121 - 122 - /* Control settings 123 - * 124 - * CONTROL_REG 125 - * BIT 7 6 5 4 3 2 1 0 126 - * EOSC BBSQW CONV RS2 RS1 INTCN A2IE A1IE 127 - * 128 - * 0 0 0 1 1 1 0 0 129 - * 130 - * CONTROL_STAT_REG 131 - * BIT 7 6 5 4 3 2 1 0 132 - * OSF BB32kHz CRATE1 CRATE0 EN32kHz BSY A2F A1F 133 - * 134 - * 1 0 0 0 1 0 0 0 135 - */ 136 - ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp); 137 - ds3234_set_reg(&spi->dev, DS3234_REG_CONTROL, tmp & 0x1c); 138 - 139 - ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp); 140 - ds3234_set_reg(&spi->dev, DS3234_REG_CONT_STAT, tmp & 0x88); 141 - 142 - /* Print our settings */ 143 - ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp); 144 - dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp); 145 - 146 - ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp); 147 - dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); 148 - 149 - rtc = devm_rtc_device_register(&spi->dev, "ds3234", 150 - &ds3234_rtc_ops, THIS_MODULE); 151 - if (IS_ERR(rtc)) 152 - return PTR_ERR(rtc); 153 - 154 - spi_set_drvdata(spi, rtc); 155 - 156 - return 0; 157 - } 158 - 159 - static struct spi_driver ds3234_driver = { 160 - .driver = { 161 - .name = "ds3234", 162 - }, 163 - .probe = ds3234_probe, 164 - }; 165 - 166 - module_spi_driver(ds3234_driver); 167 - 168 - MODULE_DESCRIPTION("DS3234 SPI RTC driver"); 169 - MODULE_AUTHOR("Dennis Aberilla <denzzzhome@yahoo.com>"); 170 - MODULE_LICENSE("GPL"); 171 - MODULE_ALIAS("spi:ds3234");
+11 -1
drivers/rtc/rtc-generic.c
··· 9 9 #include <linux/platform_device.h> 10 10 #include <linux/rtc.h> 11 11 12 + #if defined(CONFIG_M68K) || defined(CONFIG_PARISC) || \ 13 + defined(CONFIG_PPC) || defined(CONFIG_SUPERH32) 12 14 #include <asm/rtc.h> 13 15 14 16 static int generic_get_time(struct device *dev, struct rtc_time *tm) ··· 35 33 .read_time = generic_get_time, 36 34 .set_time = generic_set_time, 37 35 }; 36 + #else 37 + #define generic_rtc_ops *(struct rtc_class_ops*)NULL 38 + #endif 38 39 39 40 static int __init generic_rtc_probe(struct platform_device *dev) 40 41 { 41 42 struct rtc_device *rtc; 43 + const struct rtc_class_ops *ops; 44 + 45 + ops = dev_get_platdata(&dev->dev); 46 + if (!ops) 47 + ops = &generic_rtc_ops; 42 48 43 49 rtc = devm_rtc_device_register(&dev->dev, "rtc-generic", 44 - &generic_rtc_ops, THIS_MODULE); 50 + ops, THIS_MODULE); 45 51 if (IS_ERR(rtc)) 46 52 return PTR_ERR(rtc); 47 53
+1 -1
drivers/rtc/rtc-hym8563.c
··· 144 144 * it does not seem to carry it over a subsequent write/read. 145 145 * So we'll limit ourself to 100 years, starting at 2000 for now. 146 146 */ 147 - buf[6] = tm->tm_year - 100; 147 + buf[6] = bin2bcd(tm->tm_year - 100); 148 148 149 149 /* 150 150 * CTL1 only contains TEST-mode bits apart from stop,
+452 -117
drivers/rtc/rtc-max77686.c
··· 1 1 /* 2 - * RTC driver for Maxim MAX77686 2 + * RTC driver for Maxim MAX77686 and MAX77802 3 3 * 4 4 * Copyright (C) 2012 Samsung Electronics Co.Ltd 5 5 * ··· 12 12 * 13 13 */ 14 14 15 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16 - 15 + #include <linux/i2c.h> 17 16 #include <linux/slab.h> 18 17 #include <linux/rtc.h> 19 18 #include <linux/delay.h> ··· 23 24 #include <linux/irqdomain.h> 24 25 #include <linux/regmap.h> 25 26 27 + #define MAX77686_I2C_ADDR_RTC (0x0C >> 1) 28 + #define MAX77620_I2C_ADDR_RTC 0x68 29 + #define MAX77686_INVALID_I2C_ADDR (-1) 30 + 31 + /* Define non existing register */ 32 + #define MAX77686_INVALID_REG (-1) 33 + 26 34 /* RTC Control Register */ 27 35 #define BCD_EN_SHIFT 0 28 - #define BCD_EN_MASK (1 << BCD_EN_SHIFT) 36 + #define BCD_EN_MASK BIT(BCD_EN_SHIFT) 29 37 #define MODEL24_SHIFT 1 30 - #define MODEL24_MASK (1 << MODEL24_SHIFT) 38 + #define MODEL24_MASK BIT(MODEL24_SHIFT) 31 39 /* RTC Update Register1 */ 32 40 #define RTC_UDR_SHIFT 0 33 - #define RTC_UDR_MASK (1 << RTC_UDR_SHIFT) 41 + #define RTC_UDR_MASK BIT(RTC_UDR_SHIFT) 34 42 #define RTC_RBUDR_SHIFT 4 35 - #define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT) 43 + #define RTC_RBUDR_MASK BIT(RTC_RBUDR_SHIFT) 36 44 /* RTC Hour register */ 37 45 #define HOUR_PM_SHIFT 6 38 - #define HOUR_PM_MASK (1 << HOUR_PM_SHIFT) 46 + #define HOUR_PM_MASK BIT(HOUR_PM_SHIFT) 39 47 /* RTC Alarm Enable */ 40 48 #define ALARM_ENABLE_SHIFT 7 41 - #define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT) 49 + #define ALARM_ENABLE_MASK BIT(ALARM_ENABLE_SHIFT) 42 50 43 - #define MAX77686_RTC_UPDATE_DELAY 16 51 + #define REG_RTC_NONE 0xdeadbeef 52 + 53 + /* 54 + * MAX77802 has separate register (RTCAE1) for alarm enable instead 55 + * using 1 bit from registers RTC{SEC,MIN,HOUR,DAY,MONTH,YEAR,DATE} 56 + * as in done in MAX77686. 57 + */ 58 + #define MAX77802_ALARM_ENABLE_VALUE 0x77 44 59 45 60 enum { 46 61 RTC_SEC = 0, ··· 67 54 RTC_NR_TIME 68 55 }; 69 56 57 + struct max77686_rtc_driver_data { 58 + /* Minimum usecs needed for a RTC update */ 59 + unsigned long delay; 60 + /* Mask used to read RTC registers value */ 61 + u8 mask; 62 + /* Registers offset to I2C addresses map */ 63 + const unsigned int *map; 64 + /* Has a separate alarm enable register? */ 65 + bool alarm_enable_reg; 66 + /* I2C address for RTC block */ 67 + int rtc_i2c_addr; 68 + /* RTC interrupt via platform resource */ 69 + bool rtc_irq_from_platform; 70 + /* Pending alarm status register */ 71 + int alarm_pending_status_reg; 72 + /* RTC IRQ CHIP for regmap */ 73 + const struct regmap_irq_chip *rtc_irq_chip; 74 + }; 75 + 70 76 struct max77686_rtc_info { 71 77 struct device *dev; 72 - struct max77686_dev *max77686; 73 78 struct i2c_client *rtc; 74 79 struct rtc_device *rtc_dev; 75 80 struct mutex lock; 76 81 77 82 struct regmap *regmap; 83 + struct regmap *rtc_regmap; 78 84 85 + const struct max77686_rtc_driver_data *drv_data; 86 + struct regmap_irq_chip_data *rtc_irq_data; 87 + 88 + int rtc_irq; 79 89 int virq; 80 90 int rtc_24hr_mode; 81 91 }; ··· 108 72 MAX77686_RTC_READ, 109 73 }; 110 74 75 + /* These are not registers but just offsets that are mapped to addresses */ 76 + enum max77686_rtc_reg_offset { 77 + REG_RTC_CONTROLM = 0, 78 + REG_RTC_CONTROL, 79 + REG_RTC_UPDATE0, 80 + REG_WTSR_SMPL_CNTL, 81 + REG_RTC_SEC, 82 + REG_RTC_MIN, 83 + REG_RTC_HOUR, 84 + REG_RTC_WEEKDAY, 85 + REG_RTC_MONTH, 86 + REG_RTC_YEAR, 87 + REG_RTC_DATE, 88 + REG_ALARM1_SEC, 89 + REG_ALARM1_MIN, 90 + REG_ALARM1_HOUR, 91 + REG_ALARM1_WEEKDAY, 92 + REG_ALARM1_MONTH, 93 + REG_ALARM1_YEAR, 94 + REG_ALARM1_DATE, 95 + REG_ALARM2_SEC, 96 + REG_ALARM2_MIN, 97 + REG_ALARM2_HOUR, 98 + REG_ALARM2_WEEKDAY, 99 + REG_ALARM2_MONTH, 100 + REG_ALARM2_YEAR, 101 + REG_ALARM2_DATE, 102 + REG_RTC_AE1, 103 + REG_RTC_END, 104 + }; 105 + 106 + /* Maps RTC registers offset to the MAX77686 register addresses */ 107 + static const unsigned int max77686_map[REG_RTC_END] = { 108 + [REG_RTC_CONTROLM] = MAX77686_RTC_CONTROLM, 109 + [REG_RTC_CONTROL] = MAX77686_RTC_CONTROL, 110 + [REG_RTC_UPDATE0] = MAX77686_RTC_UPDATE0, 111 + [REG_WTSR_SMPL_CNTL] = MAX77686_WTSR_SMPL_CNTL, 112 + [REG_RTC_SEC] = MAX77686_RTC_SEC, 113 + [REG_RTC_MIN] = MAX77686_RTC_MIN, 114 + [REG_RTC_HOUR] = MAX77686_RTC_HOUR, 115 + [REG_RTC_WEEKDAY] = MAX77686_RTC_WEEKDAY, 116 + [REG_RTC_MONTH] = MAX77686_RTC_MONTH, 117 + [REG_RTC_YEAR] = MAX77686_RTC_YEAR, 118 + [REG_RTC_DATE] = MAX77686_RTC_DATE, 119 + [REG_ALARM1_SEC] = MAX77686_ALARM1_SEC, 120 + [REG_ALARM1_MIN] = MAX77686_ALARM1_MIN, 121 + [REG_ALARM1_HOUR] = MAX77686_ALARM1_HOUR, 122 + [REG_ALARM1_WEEKDAY] = MAX77686_ALARM1_WEEKDAY, 123 + [REG_ALARM1_MONTH] = MAX77686_ALARM1_MONTH, 124 + [REG_ALARM1_YEAR] = MAX77686_ALARM1_YEAR, 125 + [REG_ALARM1_DATE] = MAX77686_ALARM1_DATE, 126 + [REG_ALARM2_SEC] = MAX77686_ALARM2_SEC, 127 + [REG_ALARM2_MIN] = MAX77686_ALARM2_MIN, 128 + [REG_ALARM2_HOUR] = MAX77686_ALARM2_HOUR, 129 + [REG_ALARM2_WEEKDAY] = MAX77686_ALARM2_WEEKDAY, 130 + [REG_ALARM2_MONTH] = MAX77686_ALARM2_MONTH, 131 + [REG_ALARM2_YEAR] = MAX77686_ALARM2_YEAR, 132 + [REG_ALARM2_DATE] = MAX77686_ALARM2_DATE, 133 + [REG_RTC_AE1] = REG_RTC_NONE, 134 + }; 135 + 136 + static const struct regmap_irq max77686_rtc_irqs[] = { 137 + /* RTC interrupts */ 138 + REGMAP_IRQ_REG(0, 0, MAX77686_RTCINT_RTC60S_MSK), 139 + REGMAP_IRQ_REG(1, 0, MAX77686_RTCINT_RTCA1_MSK), 140 + REGMAP_IRQ_REG(2, 0, MAX77686_RTCINT_RTCA2_MSK), 141 + REGMAP_IRQ_REG(3, 0, MAX77686_RTCINT_SMPL_MSK), 142 + REGMAP_IRQ_REG(4, 0, MAX77686_RTCINT_RTC1S_MSK), 143 + REGMAP_IRQ_REG(5, 0, MAX77686_RTCINT_WTSR_MSK), 144 + }; 145 + 146 + static const struct regmap_irq_chip max77686_rtc_irq_chip = { 147 + .name = "max77686-rtc", 148 + .status_base = MAX77686_RTC_INT, 149 + .mask_base = MAX77686_RTC_INTM, 150 + .num_regs = 1, 151 + .irqs = max77686_rtc_irqs, 152 + .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), 153 + }; 154 + 155 + static const struct max77686_rtc_driver_data max77686_drv_data = { 156 + .delay = 16000, 157 + .mask = 0x7f, 158 + .map = max77686_map, 159 + .alarm_enable_reg = false, 160 + .rtc_irq_from_platform = false, 161 + .alarm_pending_status_reg = MAX77686_REG_STATUS2, 162 + .rtc_i2c_addr = MAX77686_I2C_ADDR_RTC, 163 + .rtc_irq_chip = &max77686_rtc_irq_chip, 164 + }; 165 + 166 + static const struct max77686_rtc_driver_data max77620_drv_data = { 167 + .delay = 16000, 168 + .mask = 0x7f, 169 + .map = max77686_map, 170 + .alarm_enable_reg = false, 171 + .rtc_irq_from_platform = true, 172 + .alarm_pending_status_reg = MAX77686_INVALID_REG, 173 + .rtc_i2c_addr = MAX77620_I2C_ADDR_RTC, 174 + .rtc_irq_chip = &max77686_rtc_irq_chip, 175 + }; 176 + 177 + static const unsigned int max77802_map[REG_RTC_END] = { 178 + [REG_RTC_CONTROLM] = MAX77802_RTC_CONTROLM, 179 + [REG_RTC_CONTROL] = MAX77802_RTC_CONTROL, 180 + [REG_RTC_UPDATE0] = MAX77802_RTC_UPDATE0, 181 + [REG_WTSR_SMPL_CNTL] = MAX77802_WTSR_SMPL_CNTL, 182 + [REG_RTC_SEC] = MAX77802_RTC_SEC, 183 + [REG_RTC_MIN] = MAX77802_RTC_MIN, 184 + [REG_RTC_HOUR] = MAX77802_RTC_HOUR, 185 + [REG_RTC_WEEKDAY] = MAX77802_RTC_WEEKDAY, 186 + [REG_RTC_MONTH] = MAX77802_RTC_MONTH, 187 + [REG_RTC_YEAR] = MAX77802_RTC_YEAR, 188 + [REG_RTC_DATE] = MAX77802_RTC_DATE, 189 + [REG_ALARM1_SEC] = MAX77802_ALARM1_SEC, 190 + [REG_ALARM1_MIN] = MAX77802_ALARM1_MIN, 191 + [REG_ALARM1_HOUR] = MAX77802_ALARM1_HOUR, 192 + [REG_ALARM1_WEEKDAY] = MAX77802_ALARM1_WEEKDAY, 193 + [REG_ALARM1_MONTH] = MAX77802_ALARM1_MONTH, 194 + [REG_ALARM1_YEAR] = MAX77802_ALARM1_YEAR, 195 + [REG_ALARM1_DATE] = MAX77802_ALARM1_DATE, 196 + [REG_ALARM2_SEC] = MAX77802_ALARM2_SEC, 197 + [REG_ALARM2_MIN] = MAX77802_ALARM2_MIN, 198 + [REG_ALARM2_HOUR] = MAX77802_ALARM2_HOUR, 199 + [REG_ALARM2_WEEKDAY] = MAX77802_ALARM2_WEEKDAY, 200 + [REG_ALARM2_MONTH] = MAX77802_ALARM2_MONTH, 201 + [REG_ALARM2_YEAR] = MAX77802_ALARM2_YEAR, 202 + [REG_ALARM2_DATE] = MAX77802_ALARM2_DATE, 203 + [REG_RTC_AE1] = MAX77802_RTC_AE1, 204 + }; 205 + 206 + static const struct regmap_irq_chip max77802_rtc_irq_chip = { 207 + .name = "max77802-rtc", 208 + .status_base = MAX77802_RTC_INT, 209 + .mask_base = MAX77802_RTC_INTM, 210 + .num_regs = 1, 211 + .irqs = max77686_rtc_irqs, /* same masks as 77686 */ 212 + .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), 213 + }; 214 + 215 + static const struct max77686_rtc_driver_data max77802_drv_data = { 216 + .delay = 200, 217 + .mask = 0xff, 218 + .map = max77802_map, 219 + .alarm_enable_reg = true, 220 + .rtc_irq_from_platform = false, 221 + .alarm_pending_status_reg = MAX77686_REG_STATUS2, 222 + .rtc_i2c_addr = MAX77686_INVALID_I2C_ADDR, 223 + .rtc_irq_chip = &max77802_rtc_irq_chip, 224 + }; 225 + 111 226 static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm, 112 - int rtc_24hr_mode) 227 + struct max77686_rtc_info *info) 113 228 { 114 - tm->tm_sec = data[RTC_SEC] & 0x7f; 115 - tm->tm_min = data[RTC_MIN] & 0x7f; 116 - if (rtc_24hr_mode) 229 + u8 mask = info->drv_data->mask; 230 + 231 + tm->tm_sec = data[RTC_SEC] & mask; 232 + tm->tm_min = data[RTC_MIN] & mask; 233 + if (info->rtc_24hr_mode) { 117 234 tm->tm_hour = data[RTC_HOUR] & 0x1f; 118 - else { 235 + } else { 119 236 tm->tm_hour = data[RTC_HOUR] & 0x0f; 120 237 if (data[RTC_HOUR] & HOUR_PM_MASK) 121 238 tm->tm_hour += 12; 122 239 } 123 240 124 241 /* Only a single bit is set in data[], so fls() would be equivalent */ 125 - tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0x7f) - 1; 242 + tm->tm_wday = ffs(data[RTC_WEEKDAY] & mask) - 1; 126 243 tm->tm_mday = data[RTC_DATE] & 0x1f; 127 244 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1; 128 - tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100; 245 + tm->tm_year = data[RTC_YEAR] & mask; 129 246 tm->tm_yday = 0; 130 247 tm->tm_isdst = 0; 248 + 249 + /* 250 + * MAX77686 uses 1 bit from sec/min/hour/etc RTC registers and the 251 + * year values are just 0..99 so add 100 to support up to 2099. 252 + */ 253 + if (!info->drv_data->alarm_enable_reg) 254 + tm->tm_year += 100; 131 255 } 132 256 133 - static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data) 257 + static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data, 258 + struct max77686_rtc_info *info) 134 259 { 135 260 data[RTC_SEC] = tm->tm_sec; 136 261 data[RTC_MIN] = tm->tm_min; ··· 299 102 data[RTC_WEEKDAY] = 1 << tm->tm_wday; 300 103 data[RTC_DATE] = tm->tm_mday; 301 104 data[RTC_MONTH] = tm->tm_mon + 1; 105 + 106 + if (info->drv_data->alarm_enable_reg) { 107 + data[RTC_YEAR] = tm->tm_year; 108 + return 0; 109 + } 110 + 302 111 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0; 303 112 304 113 if (tm->tm_year < 100) { 305 - pr_warn("RTC cannot handle the year %d. Assume it's 2000.\n", 114 + dev_err(info->dev, "RTC cannot handle the year %d.\n", 306 115 1900 + tm->tm_year); 307 116 return -EINVAL; 308 117 } 118 + 309 119 return 0; 310 120 } 311 121 312 122 static int max77686_rtc_update(struct max77686_rtc_info *info, 313 - enum MAX77686_RTC_OP op) 123 + enum MAX77686_RTC_OP op) 314 124 { 315 125 int ret; 316 126 unsigned int data; 127 + unsigned long delay = info->drv_data->delay; 317 128 318 129 if (op == MAX77686_RTC_WRITE) 319 130 data = 1 << RTC_UDR_SHIFT; 320 131 else 321 132 data = 1 << RTC_RBUDR_SHIFT; 322 133 323 - ret = regmap_update_bits(info->max77686->rtc_regmap, 324 - MAX77686_RTC_UPDATE0, data, data); 134 + ret = regmap_update_bits(info->rtc_regmap, 135 + info->drv_data->map[REG_RTC_UPDATE0], 136 + data, data); 325 137 if (ret < 0) 326 - dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n", 327 - __func__, ret, data); 138 + dev_err(info->dev, "Fail to write update reg(ret=%d, data=0x%x)\n", 139 + ret, data); 328 140 else { 329 - /* Minimum 16ms delay required before RTC update. */ 330 - msleep(MAX77686_RTC_UPDATE_DELAY); 141 + /* Minimum delay required before RTC update. */ 142 + usleep_range(delay, delay * 2); 331 143 } 332 144 333 145 return ret; ··· 354 148 if (ret < 0) 355 149 goto out; 356 150 357 - ret = regmap_bulk_read(info->max77686->rtc_regmap, 358 - MAX77686_RTC_SEC, data, RTC_NR_TIME); 151 + ret = regmap_bulk_read(info->rtc_regmap, 152 + info->drv_data->map[REG_RTC_SEC], 153 + data, ARRAY_SIZE(data)); 359 154 if (ret < 0) { 360 - dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, ret); 155 + dev_err(info->dev, "Fail to read time reg(%d)\n", ret); 361 156 goto out; 362 157 } 363 158 364 - max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode); 159 + max77686_rtc_data_to_tm(data, tm, info); 365 160 366 161 ret = rtc_valid_tm(tm); 367 162 ··· 377 170 u8 data[RTC_NR_TIME]; 378 171 int ret; 379 172 380 - ret = max77686_rtc_tm_to_data(tm, data); 173 + ret = max77686_rtc_tm_to_data(tm, data, info); 381 174 if (ret < 0) 382 175 return ret; 383 176 384 177 mutex_lock(&info->lock); 385 178 386 - ret = regmap_bulk_write(info->max77686->rtc_regmap, 387 - MAX77686_RTC_SEC, data, RTC_NR_TIME); 179 + ret = regmap_bulk_write(info->rtc_regmap, 180 + info->drv_data->map[REG_RTC_SEC], 181 + data, ARRAY_SIZE(data)); 388 182 if (ret < 0) { 389 - dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__, 390 - ret); 183 + dev_err(info->dev, "Fail to write time reg(%d)\n", ret); 391 184 goto out; 392 185 } 393 186 ··· 403 196 struct max77686_rtc_info *info = dev_get_drvdata(dev); 404 197 u8 data[RTC_NR_TIME]; 405 198 unsigned int val; 199 + const unsigned int *map = info->drv_data->map; 406 200 int i, ret; 407 201 408 202 mutex_lock(&info->lock); ··· 412 204 if (ret < 0) 413 205 goto out; 414 206 415 - ret = regmap_bulk_read(info->max77686->rtc_regmap, 416 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 207 + ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC], 208 + data, ARRAY_SIZE(data)); 417 209 if (ret < 0) { 418 - dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n", 419 - __func__, __LINE__, ret); 210 + dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret); 420 211 goto out; 421 212 } 422 213 423 - max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 214 + max77686_rtc_data_to_tm(data, &alrm->time, info); 424 215 425 216 alrm->enabled = 0; 426 - for (i = 0; i < RTC_NR_TIME; i++) { 427 - if (data[i] & ALARM_ENABLE_MASK) { 217 + 218 + if (info->drv_data->alarm_enable_reg) { 219 + if (map[REG_RTC_AE1] == REG_RTC_NONE) { 220 + ret = -EINVAL; 221 + dev_err(info->dev, 222 + "alarm enable register not set(%d)\n", ret); 223 + goto out; 224 + } 225 + 226 + ret = regmap_read(info->rtc_regmap, map[REG_RTC_AE1], &val); 227 + if (ret < 0) { 228 + dev_err(info->dev, 229 + "fail to read alarm enable(%d)\n", ret); 230 + goto out; 231 + } 232 + 233 + if (val) 428 234 alrm->enabled = 1; 429 - break; 235 + } else { 236 + for (i = 0; i < ARRAY_SIZE(data); i++) { 237 + if (data[i] & ALARM_ENABLE_MASK) { 238 + alrm->enabled = 1; 239 + break; 240 + } 430 241 } 431 242 } 432 243 433 244 alrm->pending = 0; 434 - ret = regmap_read(info->max77686->regmap, MAX77686_REG_STATUS2, &val); 245 + 246 + if (info->drv_data->alarm_pending_status_reg == MAX77686_INVALID_REG) 247 + goto out; 248 + 249 + ret = regmap_read(info->regmap, 250 + info->drv_data->alarm_pending_status_reg, &val); 435 251 if (ret < 0) { 436 - dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n", 437 - __func__, __LINE__, ret); 252 + dev_err(info->dev, 253 + "Fail to read alarm pending status reg(%d)\n", ret); 438 254 goto out; 439 255 } 440 256 ··· 467 235 468 236 out: 469 237 mutex_unlock(&info->lock); 470 - return 0; 238 + return ret; 471 239 } 472 240 473 241 static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info) ··· 475 243 u8 data[RTC_NR_TIME]; 476 244 int ret, i; 477 245 struct rtc_time tm; 246 + const unsigned int *map = info->drv_data->map; 478 247 479 248 if (!mutex_is_locked(&info->lock)) 480 249 dev_warn(info->dev, "%s: should have mutex locked\n", __func__); ··· 484 251 if (ret < 0) 485 252 goto out; 486 253 487 - ret = regmap_bulk_read(info->max77686->rtc_regmap, 488 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 489 - if (ret < 0) { 490 - dev_err(info->dev, "%s: fail to read alarm reg(%d)\n", 491 - __func__, ret); 492 - goto out; 254 + if (info->drv_data->alarm_enable_reg) { 255 + if (map[REG_RTC_AE1] == REG_RTC_NONE) { 256 + ret = -EINVAL; 257 + dev_err(info->dev, 258 + "alarm enable register not set(%d)\n", ret); 259 + goto out; 260 + } 261 + 262 + ret = regmap_write(info->rtc_regmap, map[REG_RTC_AE1], 0); 263 + } else { 264 + ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC], 265 + data, ARRAY_SIZE(data)); 266 + if (ret < 0) { 267 + dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret); 268 + goto out; 269 + } 270 + 271 + max77686_rtc_data_to_tm(data, &tm, info); 272 + 273 + for (i = 0; i < ARRAY_SIZE(data); i++) 274 + data[i] &= ~ALARM_ENABLE_MASK; 275 + 276 + ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC], 277 + data, ARRAY_SIZE(data)); 493 278 } 494 279 495 - max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode); 496 - 497 - for (i = 0; i < RTC_NR_TIME; i++) 498 - data[i] &= ~ALARM_ENABLE_MASK; 499 - 500 - ret = regmap_bulk_write(info->max77686->rtc_regmap, 501 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 502 280 if (ret < 0) { 503 - dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", 504 - __func__, ret); 281 + dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret); 505 282 goto out; 506 283 } 507 284 ··· 525 282 u8 data[RTC_NR_TIME]; 526 283 int ret; 527 284 struct rtc_time tm; 285 + const unsigned int *map = info->drv_data->map; 528 286 529 287 if (!mutex_is_locked(&info->lock)) 530 288 dev_warn(info->dev, "%s: should have mutex locked\n", __func__); ··· 534 290 if (ret < 0) 535 291 goto out; 536 292 537 - ret = regmap_bulk_read(info->max77686->rtc_regmap, 538 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 539 - if (ret < 0) { 540 - dev_err(info->dev, "%s: fail to read alarm reg(%d)\n", 541 - __func__, ret); 542 - goto out; 293 + if (info->drv_data->alarm_enable_reg) { 294 + ret = regmap_write(info->rtc_regmap, map[REG_RTC_AE1], 295 + MAX77802_ALARM_ENABLE_VALUE); 296 + } else { 297 + ret = regmap_bulk_read(info->rtc_regmap, map[REG_ALARM1_SEC], 298 + data, ARRAY_SIZE(data)); 299 + if (ret < 0) { 300 + dev_err(info->dev, "Fail to read alarm reg(%d)\n", ret); 301 + goto out; 302 + } 303 + 304 + max77686_rtc_data_to_tm(data, &tm, info); 305 + 306 + data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT); 307 + data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT); 308 + data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT); 309 + data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK; 310 + if (data[RTC_MONTH] & 0xf) 311 + data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT); 312 + if (data[RTC_YEAR] & info->drv_data->mask) 313 + data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT); 314 + if (data[RTC_DATE] & 0x1f) 315 + data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT); 316 + 317 + ret = regmap_bulk_write(info->rtc_regmap, map[REG_ALARM1_SEC], 318 + data, ARRAY_SIZE(data)); 543 319 } 544 320 545 - max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode); 546 - 547 - data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT); 548 - data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT); 549 - data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT); 550 - data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK; 551 - if (data[RTC_MONTH] & 0xf) 552 - data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT); 553 - if (data[RTC_YEAR] & 0x7f) 554 - data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT); 555 - if (data[RTC_DATE] & 0x1f) 556 - data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT); 557 - 558 - ret = regmap_bulk_write(info->max77686->rtc_regmap, 559 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 560 321 if (ret < 0) { 561 - dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", 562 - __func__, ret); 322 + dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret); 563 323 goto out; 564 324 } 565 325 ··· 578 330 u8 data[RTC_NR_TIME]; 579 331 int ret; 580 332 581 - ret = max77686_rtc_tm_to_data(&alrm->time, data); 333 + ret = max77686_rtc_tm_to_data(&alrm->time, data, info); 582 334 if (ret < 0) 583 335 return ret; 584 336 ··· 588 340 if (ret < 0) 589 341 goto out; 590 342 591 - ret = regmap_bulk_write(info->max77686->rtc_regmap, 592 - MAX77686_ALARM1_SEC, data, RTC_NR_TIME); 343 + ret = regmap_bulk_write(info->rtc_regmap, 344 + info->drv_data->map[REG_ALARM1_SEC], 345 + data, ARRAY_SIZE(data)); 593 346 594 347 if (ret < 0) { 595 - dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", 596 - __func__, ret); 348 + dev_err(info->dev, "Fail to write alarm reg(%d)\n", ret); 597 349 goto out; 598 350 } 599 351 ··· 609 361 } 610 362 611 363 static int max77686_rtc_alarm_irq_enable(struct device *dev, 612 - unsigned int enabled) 364 + unsigned int enabled) 613 365 { 614 366 struct max77686_rtc_info *info = dev_get_drvdata(dev); 615 367 int ret; ··· 628 380 { 629 381 struct max77686_rtc_info *info = data; 630 382 631 - dev_info(info->dev, "%s:irq(%d)\n", __func__, irq); 383 + dev_dbg(info->dev, "RTC alarm IRQ: %d\n", irq); 632 384 633 385 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF); 634 386 ··· 654 406 655 407 info->rtc_24hr_mode = 1; 656 408 657 - ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2); 409 + ret = regmap_bulk_write(info->rtc_regmap, 410 + info->drv_data->map[REG_RTC_CONTROLM], 411 + data, ARRAY_SIZE(data)); 658 412 if (ret < 0) { 659 - dev_err(info->dev, "%s: fail to write controlm reg(%d)\n", 660 - __func__, ret); 413 + dev_err(info->dev, "Fail to write controlm reg(%d)\n", ret); 661 414 return ret; 662 415 } 663 416 ··· 666 417 return ret; 667 418 } 668 419 669 - static int max77686_rtc_probe(struct platform_device *pdev) 420 + static const struct regmap_config max77686_rtc_regmap_config = { 421 + .reg_bits = 8, 422 + .val_bits = 8, 423 + }; 424 + 425 + static int max77686_init_rtc_regmap(struct max77686_rtc_info *info) 670 426 { 671 - struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent); 672 - struct max77686_rtc_info *info; 427 + struct device *parent = info->dev->parent; 428 + struct i2c_client *parent_i2c = to_i2c_client(parent); 673 429 int ret; 674 430 675 - dev_info(&pdev->dev, "%s\n", __func__); 431 + if (info->drv_data->rtc_irq_from_platform) { 432 + struct platform_device *pdev = to_platform_device(info->dev); 433 + 434 + info->rtc_irq = platform_get_irq(pdev, 0); 435 + if (info->rtc_irq < 0) { 436 + dev_err(info->dev, "Failed to get rtc interrupts: %d\n", 437 + info->rtc_irq); 438 + return info->rtc_irq; 439 + } 440 + } else { 441 + info->rtc_irq = parent_i2c->irq; 442 + } 443 + 444 + info->regmap = dev_get_regmap(parent, NULL); 445 + if (!info->regmap) { 446 + dev_err(info->dev, "Failed to get rtc regmap\n"); 447 + return -ENODEV; 448 + } 449 + 450 + if (info->drv_data->rtc_i2c_addr == MAX77686_INVALID_I2C_ADDR) { 451 + info->rtc_regmap = info->regmap; 452 + goto add_rtc_irq; 453 + } 454 + 455 + info->rtc = i2c_new_dummy(parent_i2c->adapter, 456 + info->drv_data->rtc_i2c_addr); 457 + if (!info->rtc) { 458 + dev_err(info->dev, "Failed to allocate I2C device for RTC\n"); 459 + return -ENODEV; 460 + } 461 + 462 + info->rtc_regmap = devm_regmap_init_i2c(info->rtc, 463 + &max77686_rtc_regmap_config); 464 + if (IS_ERR(info->rtc_regmap)) { 465 + ret = PTR_ERR(info->rtc_regmap); 466 + dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret); 467 + goto err_unregister_i2c; 468 + } 469 + 470 + add_rtc_irq: 471 + ret = regmap_add_irq_chip(info->rtc_regmap, info->rtc_irq, 472 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT | 473 + IRQF_SHARED, 0, info->drv_data->rtc_irq_chip, 474 + &info->rtc_irq_data); 475 + if (ret < 0) { 476 + dev_err(info->dev, "Failed to add RTC irq chip: %d\n", ret); 477 + goto err_unregister_i2c; 478 + } 479 + 480 + return 0; 481 + 482 + err_unregister_i2c: 483 + if (info->rtc) 484 + i2c_unregister_device(info->rtc); 485 + return ret; 486 + } 487 + 488 + static int max77686_rtc_probe(struct platform_device *pdev) 489 + { 490 + struct max77686_rtc_info *info; 491 + const struct platform_device_id *id = platform_get_device_id(pdev); 492 + int ret; 676 493 677 494 info = devm_kzalloc(&pdev->dev, sizeof(struct max77686_rtc_info), 678 - GFP_KERNEL); 495 + GFP_KERNEL); 679 496 if (!info) 680 497 return -ENOMEM; 681 498 682 499 mutex_init(&info->lock); 683 500 info->dev = &pdev->dev; 684 - info->max77686 = max77686; 685 - info->rtc = max77686->rtc; 501 + info->drv_data = (const struct max77686_rtc_driver_data *) 502 + id->driver_data; 503 + 504 + ret = max77686_init_rtc_regmap(info); 505 + if (ret < 0) 506 + return ret; 686 507 687 508 platform_set_drvdata(pdev, info); 688 509 689 510 ret = max77686_rtc_init_reg(info); 690 - 691 511 if (ret < 0) { 692 512 dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret); 693 513 goto err_rtc; ··· 764 446 765 447 device_init_wakeup(&pdev->dev, 1); 766 448 767 - info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc", 449 + info->rtc_dev = devm_rtc_device_register(&pdev->dev, id->name, 768 450 &max77686_rtc_ops, THIS_MODULE); 769 451 770 452 if (IS_ERR(info->rtc_dev)) { ··· 775 457 goto err_rtc; 776 458 } 777 459 778 - if (!max77686->rtc_irq_data) { 779 - ret = -EINVAL; 780 - dev_err(&pdev->dev, "%s: no RTC regmap IRQ chip\n", __func__); 781 - goto err_rtc; 782 - } 783 - 784 - info->virq = regmap_irq_get_virq(max77686->rtc_irq_data, 460 + info->virq = regmap_irq_get_virq(info->rtc_irq_data, 785 461 MAX77686_RTCIRQ_RTCA1); 786 - if (!info->virq) { 462 + if (info->virq <= 0) { 787 463 ret = -ENXIO; 788 464 goto err_rtc; 789 465 } 790 466 791 - ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL, 792 - max77686_rtc_alarm_irq, 0, "rtc-alarm1", info); 793 - if (ret < 0) 467 + ret = request_threaded_irq(info->virq, NULL, max77686_rtc_alarm_irq, 0, 468 + "rtc-alarm1", info); 469 + if (ret < 0) { 794 470 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 795 471 info->virq, ret); 472 + goto err_rtc; 473 + } 474 + 475 + return 0; 796 476 797 477 err_rtc: 478 + regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data); 479 + if (info->rtc) 480 + i2c_unregister_device(info->rtc); 481 + 798 482 return ret; 483 + } 484 + 485 + static int max77686_rtc_remove(struct platform_device *pdev) 486 + { 487 + struct max77686_rtc_info *info = platform_get_drvdata(pdev); 488 + 489 + free_irq(info->virq, info); 490 + regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data); 491 + if (info->rtc) 492 + i2c_unregister_device(info->rtc); 493 + 494 + return 0; 799 495 } 800 496 801 497 #ifdef CONFIG_PM_SLEEP ··· 840 508 max77686_rtc_suspend, max77686_rtc_resume); 841 509 842 510 static const struct platform_device_id rtc_id[] = { 843 - { "max77686-rtc", 0 }, 511 + { "max77686-rtc", .driver_data = (kernel_ulong_t)&max77686_drv_data, }, 512 + { "max77802-rtc", .driver_data = (kernel_ulong_t)&max77802_drv_data, }, 513 + { "max77620-rtc", .driver_data = (kernel_ulong_t)&max77620_drv_data, }, 844 514 {}, 845 515 }; 846 516 MODULE_DEVICE_TABLE(platform, rtc_id); ··· 853 519 .pm = &max77686_rtc_pm_ops, 854 520 }, 855 521 .probe = max77686_rtc_probe, 522 + .remove = max77686_rtc_remove, 856 523 .id_table = rtc_id, 857 524 }; 858 525
-502
drivers/rtc/rtc-max77802.c
··· 1 - /* 2 - * RTC driver for Maxim MAX77802 3 - * 4 - * Copyright (C) 2013 Google, Inc 5 - * 6 - * Copyright (C) 2012 Samsung Electronics Co.Ltd 7 - * 8 - * based on rtc-max8997.c 9 - * 10 - * This program is free software; you can redistribute it and/or modify it 11 - * under the terms of the GNU General Public License as published by the 12 - * Free Software Foundation; either version 2 of the License, or (at your 13 - * option) any later version. 14 - * 15 - */ 16 - 17 - #include <linux/slab.h> 18 - #include <linux/rtc.h> 19 - #include <linux/delay.h> 20 - #include <linux/mutex.h> 21 - #include <linux/module.h> 22 - #include <linux/platform_device.h> 23 - #include <linux/mfd/max77686-private.h> 24 - #include <linux/irqdomain.h> 25 - #include <linux/regmap.h> 26 - 27 - /* RTC Control Register */ 28 - #define BCD_EN_SHIFT 0 29 - #define BCD_EN_MASK (1 << BCD_EN_SHIFT) 30 - #define MODEL24_SHIFT 1 31 - #define MODEL24_MASK (1 << MODEL24_SHIFT) 32 - /* RTC Update Register1 */ 33 - #define RTC_UDR_SHIFT 0 34 - #define RTC_UDR_MASK (1 << RTC_UDR_SHIFT) 35 - #define RTC_RBUDR_SHIFT 4 36 - #define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT) 37 - /* RTC Hour register */ 38 - #define HOUR_PM_SHIFT 6 39 - #define HOUR_PM_MASK (1 << HOUR_PM_SHIFT) 40 - /* RTC Alarm Enable */ 41 - #define ALARM_ENABLE_SHIFT 7 42 - #define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT) 43 - 44 - /* For the RTCAE1 register, we write this value to enable the alarm */ 45 - #define ALARM_ENABLE_VALUE 0x77 46 - 47 - #define MAX77802_RTC_UPDATE_DELAY_US 200 48 - 49 - enum { 50 - RTC_SEC = 0, 51 - RTC_MIN, 52 - RTC_HOUR, 53 - RTC_WEEKDAY, 54 - RTC_MONTH, 55 - RTC_YEAR, 56 - RTC_DATE, 57 - RTC_NR_TIME 58 - }; 59 - 60 - struct max77802_rtc_info { 61 - struct device *dev; 62 - struct max77686_dev *max77802; 63 - struct i2c_client *rtc; 64 - struct rtc_device *rtc_dev; 65 - struct mutex lock; 66 - 67 - struct regmap *regmap; 68 - 69 - int virq; 70 - int rtc_24hr_mode; 71 - }; 72 - 73 - enum MAX77802_RTC_OP { 74 - MAX77802_RTC_WRITE, 75 - MAX77802_RTC_READ, 76 - }; 77 - 78 - static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm, 79 - int rtc_24hr_mode) 80 - { 81 - tm->tm_sec = data[RTC_SEC] & 0xff; 82 - tm->tm_min = data[RTC_MIN] & 0xff; 83 - if (rtc_24hr_mode) 84 - tm->tm_hour = data[RTC_HOUR] & 0x1f; 85 - else { 86 - tm->tm_hour = data[RTC_HOUR] & 0x0f; 87 - if (data[RTC_HOUR] & HOUR_PM_MASK) 88 - tm->tm_hour += 12; 89 - } 90 - 91 - /* Only a single bit is set in data[], so fls() would be equivalent */ 92 - tm->tm_wday = ffs(data[RTC_WEEKDAY] & 0xff) - 1; 93 - tm->tm_mday = data[RTC_DATE] & 0x1f; 94 - tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1; 95 - 96 - tm->tm_year = data[RTC_YEAR] & 0xff; 97 - tm->tm_yday = 0; 98 - tm->tm_isdst = 0; 99 - } 100 - 101 - static int max77802_rtc_tm_to_data(struct rtc_time *tm, u8 *data) 102 - { 103 - data[RTC_SEC] = tm->tm_sec; 104 - data[RTC_MIN] = tm->tm_min; 105 - data[RTC_HOUR] = tm->tm_hour; 106 - data[RTC_WEEKDAY] = 1 << tm->tm_wday; 107 - data[RTC_DATE] = tm->tm_mday; 108 - data[RTC_MONTH] = tm->tm_mon + 1; 109 - data[RTC_YEAR] = tm->tm_year; 110 - 111 - return 0; 112 - } 113 - 114 - static int max77802_rtc_update(struct max77802_rtc_info *info, 115 - enum MAX77802_RTC_OP op) 116 - { 117 - int ret; 118 - unsigned int data; 119 - 120 - if (op == MAX77802_RTC_WRITE) 121 - data = 1 << RTC_UDR_SHIFT; 122 - else 123 - data = 1 << RTC_RBUDR_SHIFT; 124 - 125 - ret = regmap_update_bits(info->max77802->regmap, 126 - MAX77802_RTC_UPDATE0, data, data); 127 - if (ret < 0) 128 - dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n", 129 - __func__, ret, data); 130 - else { 131 - /* Minimum delay required before RTC update. */ 132 - usleep_range(MAX77802_RTC_UPDATE_DELAY_US, 133 - MAX77802_RTC_UPDATE_DELAY_US * 2); 134 - } 135 - 136 - return ret; 137 - } 138 - 139 - static int max77802_rtc_read_time(struct device *dev, struct rtc_time *tm) 140 - { 141 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 142 - u8 data[RTC_NR_TIME]; 143 - int ret; 144 - 145 - mutex_lock(&info->lock); 146 - 147 - ret = max77802_rtc_update(info, MAX77802_RTC_READ); 148 - if (ret < 0) 149 - goto out; 150 - 151 - ret = regmap_bulk_read(info->max77802->regmap, 152 - MAX77802_RTC_SEC, data, RTC_NR_TIME); 153 - if (ret < 0) { 154 - dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, 155 - ret); 156 - goto out; 157 - } 158 - 159 - max77802_rtc_data_to_tm(data, tm, info->rtc_24hr_mode); 160 - 161 - ret = rtc_valid_tm(tm); 162 - 163 - out: 164 - mutex_unlock(&info->lock); 165 - return ret; 166 - } 167 - 168 - static int max77802_rtc_set_time(struct device *dev, struct rtc_time *tm) 169 - { 170 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 171 - u8 data[RTC_NR_TIME]; 172 - int ret; 173 - 174 - ret = max77802_rtc_tm_to_data(tm, data); 175 - if (ret < 0) 176 - return ret; 177 - 178 - mutex_lock(&info->lock); 179 - 180 - ret = regmap_bulk_write(info->max77802->regmap, 181 - MAX77802_RTC_SEC, data, RTC_NR_TIME); 182 - if (ret < 0) { 183 - dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__, 184 - ret); 185 - goto out; 186 - } 187 - 188 - ret = max77802_rtc_update(info, MAX77802_RTC_WRITE); 189 - 190 - out: 191 - mutex_unlock(&info->lock); 192 - return ret; 193 - } 194 - 195 - static int max77802_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 196 - { 197 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 198 - u8 data[RTC_NR_TIME]; 199 - unsigned int val; 200 - int ret; 201 - 202 - mutex_lock(&info->lock); 203 - 204 - ret = max77802_rtc_update(info, MAX77802_RTC_READ); 205 - if (ret < 0) 206 - goto out; 207 - 208 - ret = regmap_bulk_read(info->max77802->regmap, 209 - MAX77802_ALARM1_SEC, data, RTC_NR_TIME); 210 - if (ret < 0) { 211 - dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n", 212 - __func__, __LINE__, ret); 213 - goto out; 214 - } 215 - 216 - max77802_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode); 217 - 218 - alrm->enabled = 0; 219 - ret = regmap_read(info->max77802->regmap, 220 - MAX77802_RTC_AE1, &val); 221 - if (ret < 0) { 222 - dev_err(info->dev, "%s:%d fail to read alarm enable(%d)\n", 223 - __func__, __LINE__, ret); 224 - goto out; 225 - } 226 - if (val) 227 - alrm->enabled = 1; 228 - 229 - alrm->pending = 0; 230 - ret = regmap_read(info->max77802->regmap, MAX77802_REG_STATUS2, &val); 231 - if (ret < 0) { 232 - dev_err(info->dev, "%s:%d fail to read status2 reg(%d)\n", 233 - __func__, __LINE__, ret); 234 - goto out; 235 - } 236 - 237 - if (val & (1 << 2)) /* RTCA1 */ 238 - alrm->pending = 1; 239 - 240 - out: 241 - mutex_unlock(&info->lock); 242 - return 0; 243 - } 244 - 245 - static int max77802_rtc_stop_alarm(struct max77802_rtc_info *info) 246 - { 247 - int ret; 248 - 249 - if (!mutex_is_locked(&info->lock)) 250 - dev_warn(info->dev, "%s: should have mutex locked\n", __func__); 251 - 252 - ret = max77802_rtc_update(info, MAX77802_RTC_READ); 253 - if (ret < 0) 254 - goto out; 255 - 256 - ret = regmap_write(info->max77802->regmap, 257 - MAX77802_RTC_AE1, 0); 258 - if (ret < 0) { 259 - dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", 260 - __func__, ret); 261 - goto out; 262 - } 263 - 264 - ret = max77802_rtc_update(info, MAX77802_RTC_WRITE); 265 - out: 266 - return ret; 267 - } 268 - 269 - static int max77802_rtc_start_alarm(struct max77802_rtc_info *info) 270 - { 271 - int ret; 272 - 273 - if (!mutex_is_locked(&info->lock)) 274 - dev_warn(info->dev, "%s: should have mutex locked\n", 275 - __func__); 276 - 277 - ret = max77802_rtc_update(info, MAX77802_RTC_READ); 278 - if (ret < 0) 279 - goto out; 280 - 281 - ret = regmap_write(info->max77802->regmap, 282 - MAX77802_RTC_AE1, 283 - ALARM_ENABLE_VALUE); 284 - 285 - if (ret < 0) { 286 - dev_err(info->dev, "%s: fail to read alarm reg(%d)\n", 287 - __func__, ret); 288 - goto out; 289 - } 290 - 291 - ret = max77802_rtc_update(info, MAX77802_RTC_WRITE); 292 - out: 293 - return ret; 294 - } 295 - 296 - static int max77802_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 297 - { 298 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 299 - u8 data[RTC_NR_TIME]; 300 - int ret; 301 - 302 - ret = max77802_rtc_tm_to_data(&alrm->time, data); 303 - if (ret < 0) 304 - return ret; 305 - 306 - mutex_lock(&info->lock); 307 - 308 - ret = max77802_rtc_stop_alarm(info); 309 - if (ret < 0) 310 - goto out; 311 - 312 - ret = regmap_bulk_write(info->max77802->regmap, 313 - MAX77802_ALARM1_SEC, data, RTC_NR_TIME); 314 - 315 - if (ret < 0) { 316 - dev_err(info->dev, "%s: fail to write alarm reg(%d)\n", 317 - __func__, ret); 318 - goto out; 319 - } 320 - 321 - ret = max77802_rtc_update(info, MAX77802_RTC_WRITE); 322 - if (ret < 0) 323 - goto out; 324 - 325 - if (alrm->enabled) 326 - ret = max77802_rtc_start_alarm(info); 327 - out: 328 - mutex_unlock(&info->lock); 329 - return ret; 330 - } 331 - 332 - static int max77802_rtc_alarm_irq_enable(struct device *dev, 333 - unsigned int enabled) 334 - { 335 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 336 - int ret; 337 - 338 - mutex_lock(&info->lock); 339 - if (enabled) 340 - ret = max77802_rtc_start_alarm(info); 341 - else 342 - ret = max77802_rtc_stop_alarm(info); 343 - mutex_unlock(&info->lock); 344 - 345 - return ret; 346 - } 347 - 348 - static irqreturn_t max77802_rtc_alarm_irq(int irq, void *data) 349 - { 350 - struct max77802_rtc_info *info = data; 351 - 352 - dev_dbg(info->dev, "%s:irq(%d)\n", __func__, irq); 353 - 354 - rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF); 355 - 356 - return IRQ_HANDLED; 357 - } 358 - 359 - static const struct rtc_class_ops max77802_rtc_ops = { 360 - .read_time = max77802_rtc_read_time, 361 - .set_time = max77802_rtc_set_time, 362 - .read_alarm = max77802_rtc_read_alarm, 363 - .set_alarm = max77802_rtc_set_alarm, 364 - .alarm_irq_enable = max77802_rtc_alarm_irq_enable, 365 - }; 366 - 367 - static int max77802_rtc_init_reg(struct max77802_rtc_info *info) 368 - { 369 - u8 data[2]; 370 - int ret; 371 - 372 - max77802_rtc_update(info, MAX77802_RTC_READ); 373 - 374 - /* Set RTC control register : Binary mode, 24hour mdoe */ 375 - data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 376 - data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 377 - 378 - info->rtc_24hr_mode = 1; 379 - 380 - ret = regmap_bulk_write(info->max77802->regmap, 381 - MAX77802_RTC_CONTROLM, data, ARRAY_SIZE(data)); 382 - if (ret < 0) { 383 - dev_err(info->dev, "%s: fail to write controlm reg(%d)\n", 384 - __func__, ret); 385 - return ret; 386 - } 387 - 388 - ret = max77802_rtc_update(info, MAX77802_RTC_WRITE); 389 - return ret; 390 - } 391 - 392 - static int max77802_rtc_probe(struct platform_device *pdev) 393 - { 394 - struct max77686_dev *max77802 = dev_get_drvdata(pdev->dev.parent); 395 - struct max77802_rtc_info *info; 396 - int ret; 397 - 398 - dev_dbg(&pdev->dev, "%s\n", __func__); 399 - 400 - info = devm_kzalloc(&pdev->dev, sizeof(struct max77802_rtc_info), 401 - GFP_KERNEL); 402 - if (!info) 403 - return -ENOMEM; 404 - 405 - mutex_init(&info->lock); 406 - info->dev = &pdev->dev; 407 - info->max77802 = max77802; 408 - info->rtc = max77802->i2c; 409 - 410 - platform_set_drvdata(pdev, info); 411 - 412 - ret = max77802_rtc_init_reg(info); 413 - 414 - if (ret < 0) { 415 - dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret); 416 - return ret; 417 - } 418 - 419 - device_init_wakeup(&pdev->dev, 1); 420 - 421 - info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77802-rtc", 422 - &max77802_rtc_ops, THIS_MODULE); 423 - 424 - if (IS_ERR(info->rtc_dev)) { 425 - ret = PTR_ERR(info->rtc_dev); 426 - dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 427 - if (ret == 0) 428 - ret = -EINVAL; 429 - return ret; 430 - } 431 - 432 - if (!max77802->rtc_irq_data) { 433 - dev_err(&pdev->dev, "No RTC regmap IRQ chip\n"); 434 - return -EINVAL; 435 - } 436 - 437 - info->virq = regmap_irq_get_virq(max77802->rtc_irq_data, 438 - MAX77686_RTCIRQ_RTCA1); 439 - 440 - if (info->virq <= 0) { 441 - dev_err(&pdev->dev, "Failed to get virtual IRQ %d\n", 442 - MAX77686_RTCIRQ_RTCA1); 443 - return -EINVAL; 444 - } 445 - 446 - ret = devm_request_threaded_irq(&pdev->dev, info->virq, NULL, 447 - max77802_rtc_alarm_irq, 0, "rtc-alarm1", 448 - info); 449 - if (ret < 0) 450 - dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 451 - info->virq, ret); 452 - 453 - return ret; 454 - } 455 - 456 - #ifdef CONFIG_PM_SLEEP 457 - static int max77802_rtc_suspend(struct device *dev) 458 - { 459 - if (device_may_wakeup(dev)) { 460 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 461 - 462 - return enable_irq_wake(info->virq); 463 - } 464 - 465 - return 0; 466 - } 467 - 468 - static int max77802_rtc_resume(struct device *dev) 469 - { 470 - if (device_may_wakeup(dev)) { 471 - struct max77802_rtc_info *info = dev_get_drvdata(dev); 472 - 473 - return disable_irq_wake(info->virq); 474 - } 475 - 476 - return 0; 477 - } 478 - #endif 479 - 480 - static SIMPLE_DEV_PM_OPS(max77802_rtc_pm_ops, 481 - max77802_rtc_suspend, max77802_rtc_resume); 482 - 483 - static const struct platform_device_id rtc_id[] = { 484 - { "max77802-rtc", 0 }, 485 - {}, 486 - }; 487 - MODULE_DEVICE_TABLE(platform, rtc_id); 488 - 489 - static struct platform_driver max77802_rtc_driver = { 490 - .driver = { 491 - .name = "max77802-rtc", 492 - .pm = &max77802_rtc_pm_ops, 493 - }, 494 - .probe = max77802_rtc_probe, 495 - .id_table = rtc_id, 496 - }; 497 - 498 - module_platform_driver(max77802_rtc_driver); 499 - 500 - MODULE_DESCRIPTION("Maxim MAX77802 RTC driver"); 501 - MODULE_AUTHOR("Simon Glass <sjg@chromium.org>"); 502 - MODULE_LICENSE("GPL");
-1
drivers/rtc/rtc-mt6397.c
··· 419 419 MODULE_LICENSE("GPL v2"); 420 420 MODULE_AUTHOR("Tianping Fang <tianping.fang@mediatek.com>"); 421 421 MODULE_DESCRIPTION("RTC Driver for MediaTek MT6397 PMIC"); 422 - MODULE_ALIAS("platform:mt6397-rtc");
+1 -2
drivers/rtc/rtc-palmas.c
··· 311 311 312 312 ret = devm_request_threaded_irq(&pdev->dev, palmas_rtc->irq, NULL, 313 313 palmas_rtc_interrupt, 314 - IRQF_TRIGGER_LOW | IRQF_ONESHOT | 315 - IRQF_EARLY_RESUME, 314 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 316 315 dev_name(&pdev->dev), palmas_rtc); 317 316 if (ret < 0) { 318 317 dev_err(&pdev->dev, "IRQ request failed, err = %d\n", ret);
+194 -77
drivers/rtc/rtc-pcf2123.c
··· 48 48 49 49 #define DRV_VERSION "0.6" 50 50 51 + /* REGISTERS */ 51 52 #define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */ 52 53 #define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */ 53 54 #define PCF2123_REG_SC (0x02) /* datetime */ ··· 58 57 #define PCF2123_REG_DW (0x06) 59 58 #define PCF2123_REG_MO (0x07) 60 59 #define PCF2123_REG_YR (0x08) 60 + #define PCF2123_REG_ALRM_MN (0x09) /* Alarm Registers */ 61 + #define PCF2123_REG_ALRM_HR (0x0a) 62 + #define PCF2123_REG_ALRM_DM (0x0b) 63 + #define PCF2123_REG_ALRM_DW (0x0c) 64 + #define PCF2123_REG_OFFSET (0x0d) /* Clock Rate Offset Register */ 65 + #define PCF2123_REG_TMR_CLKOUT (0x0e) /* Timer Registers */ 66 + #define PCF2123_REG_CTDWN_TMR (0x0f) 61 67 62 - #define PCF2123_SUBADDR (1 << 4) 63 - #define PCF2123_WRITE ((0 << 7) | PCF2123_SUBADDR) 64 - #define PCF2123_READ ((1 << 7) | PCF2123_SUBADDR) 68 + /* PCF2123_REG_CTRL1 BITS */ 69 + #define CTRL1_CLEAR (0) /* Clear */ 70 + #define CTRL1_CORR_INT BIT(1) /* Correction irq enable */ 71 + #define CTRL1_12_HOUR BIT(2) /* 12 hour time */ 72 + #define CTRL1_SW_RESET (BIT(3) | BIT(4) | BIT(6)) /* Software reset */ 73 + #define CTRL1_STOP BIT(5) /* Stop the clock */ 74 + #define CTRL1_EXT_TEST BIT(7) /* External clock test mode */ 75 + 76 + /* PCF2123_REG_CTRL2 BITS */ 77 + #define CTRL2_TIE BIT(0) /* Countdown timer irq enable */ 78 + #define CTRL2_AIE BIT(1) /* Alarm irq enable */ 79 + #define CTRL2_TF BIT(2) /* Countdown timer flag */ 80 + #define CTRL2_AF BIT(3) /* Alarm flag */ 81 + #define CTRL2_TI_TP BIT(4) /* Irq pin generates pulse */ 82 + #define CTRL2_MSF BIT(5) /* Minute or second irq flag */ 83 + #define CTRL2_SI BIT(6) /* Second irq enable */ 84 + #define CTRL2_MI BIT(7) /* Minute irq enable */ 85 + 86 + /* PCF2123_REG_SC BITS */ 87 + #define OSC_HAS_STOPPED BIT(7) /* Clock has been stopped */ 88 + 89 + /* PCF2123_REG_ALRM_XX BITS */ 90 + #define ALRM_ENABLE BIT(7) /* MN, HR, DM, or DW alarm enable */ 91 + 92 + /* PCF2123_REG_TMR_CLKOUT BITS */ 93 + #define CD_TMR_4096KHZ (0) /* 4096 KHz countdown timer */ 94 + #define CD_TMR_64HZ (1) /* 64 Hz countdown timer */ 95 + #define CD_TMR_1HZ (2) /* 1 Hz countdown timer */ 96 + #define CD_TMR_60th_HZ (3) /* 60th Hz countdown timer */ 97 + #define CD_TMR_TE BIT(3) /* Countdown timer enable */ 98 + 99 + /* PCF2123_REG_OFFSET BITS */ 100 + #define OFFSET_SIGN_BIT BIT(6) /* 2's complement sign bit */ 101 + #define OFFSET_COARSE BIT(7) /* Coarse mode offset */ 102 + #define OFFSET_STEP (2170) /* Offset step in parts per billion */ 103 + 104 + /* READ/WRITE ADDRESS BITS */ 105 + #define PCF2123_WRITE BIT(4) 106 + #define PCF2123_READ (BIT(4) | BIT(7)) 107 + 65 108 66 109 static struct spi_driver pcf2123_driver; 67 110 ··· 129 84 ndelay(30); 130 85 } 131 86 87 + static int pcf2123_read(struct device *dev, u8 reg, u8 *rxbuf, size_t size) 88 + { 89 + struct spi_device *spi = to_spi_device(dev); 90 + int ret; 91 + 92 + reg |= PCF2123_READ; 93 + ret = spi_write_then_read(spi, &reg, 1, rxbuf, size); 94 + pcf2123_delay_trec(); 95 + 96 + return ret; 97 + } 98 + 99 + static int pcf2123_write(struct device *dev, u8 *txbuf, size_t size) 100 + { 101 + struct spi_device *spi = to_spi_device(dev); 102 + int ret; 103 + 104 + txbuf[0] |= PCF2123_WRITE; 105 + ret = spi_write(spi, txbuf, size); 106 + pcf2123_delay_trec(); 107 + 108 + return ret; 109 + } 110 + 111 + static int pcf2123_write_reg(struct device *dev, u8 reg, u8 val) 112 + { 113 + u8 txbuf[2]; 114 + 115 + txbuf[0] = reg; 116 + txbuf[1] = val; 117 + return pcf2123_write(dev, txbuf, sizeof(txbuf)); 118 + } 119 + 132 120 static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr, 133 121 char *buffer) 134 122 { 135 - struct spi_device *spi = to_spi_device(dev); 136 123 struct pcf2123_sysfs_reg *r; 137 - u8 txbuf[1], rxbuf[1]; 124 + u8 rxbuf[1]; 138 125 unsigned long reg; 139 126 int ret; 140 127 ··· 176 99 if (ret) 177 100 return ret; 178 101 179 - txbuf[0] = PCF2123_READ | reg; 180 - ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1); 102 + ret = pcf2123_read(dev, reg, rxbuf, 1); 181 103 if (ret < 0) 182 104 return -EIO; 183 - pcf2123_delay_trec(); 105 + 184 106 return sprintf(buffer, "0x%x\n", rxbuf[0]); 185 107 } 186 108 187 109 static ssize_t pcf2123_store(struct device *dev, struct device_attribute *attr, 188 110 const char *buffer, size_t count) { 189 - struct spi_device *spi = to_spi_device(dev); 190 111 struct pcf2123_sysfs_reg *r; 191 - u8 txbuf[2]; 192 112 unsigned long reg; 193 113 unsigned long val; 194 114 ··· 201 127 if (ret) 202 128 return ret; 203 129 204 - txbuf[0] = PCF2123_WRITE | reg; 205 - txbuf[1] = val; 206 - ret = spi_write(spi, txbuf, sizeof(txbuf)); 130 + pcf2123_write_reg(dev, reg, val); 207 131 if (ret < 0) 208 132 return -EIO; 209 - pcf2123_delay_trec(); 210 133 return count; 134 + } 135 + 136 + static int pcf2123_read_offset(struct device *dev, long *offset) 137 + { 138 + int ret; 139 + s8 reg; 140 + 141 + ret = pcf2123_read(dev, PCF2123_REG_OFFSET, &reg, 1); 142 + if (ret < 0) 143 + return ret; 144 + 145 + if (reg & OFFSET_COARSE) 146 + reg <<= 1; /* multiply by 2 and sign extend */ 147 + else 148 + reg |= (reg & OFFSET_SIGN_BIT) << 1; /* sign extend only */ 149 + 150 + *offset = ((long)reg) * OFFSET_STEP; 151 + 152 + return 0; 153 + } 154 + 155 + /* 156 + * The offset register is a 7 bit signed value with a coarse bit in bit 7. 157 + * The main difference between the two is normal offset adjusts the first 158 + * second of n minutes every other hour, with 61, 62 and 63 being shoved 159 + * into the 60th minute. 160 + * The coarse adjustment does the same, but every hour. 161 + * the two overlap, with every even normal offset value corresponding 162 + * to a coarse offset. Based on this algorithm, it seems that despite the 163 + * name, coarse offset is a better fit for overlapping values. 164 + */ 165 + static int pcf2123_set_offset(struct device *dev, long offset) 166 + { 167 + s8 reg; 168 + 169 + if (offset > OFFSET_STEP * 127) 170 + reg = 127; 171 + else if (offset < OFFSET_STEP * -128) 172 + reg = -128; 173 + else 174 + reg = (s8)((offset + (OFFSET_STEP >> 1)) / OFFSET_STEP); 175 + 176 + /* choose fine offset only for odd values in the normal range */ 177 + if (reg & 1 && reg <= 63 && reg >= -64) { 178 + /* Normal offset. Clear the coarse bit */ 179 + reg &= ~OFFSET_COARSE; 180 + } else { 181 + /* Coarse offset. Divide by 2 and set the coarse bit */ 182 + reg >>= 1; 183 + reg |= OFFSET_COARSE; 184 + } 185 + 186 + return pcf2123_write_reg(dev, PCF2123_REG_OFFSET, reg); 211 187 } 212 188 213 189 static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm) 214 190 { 215 - struct spi_device *spi = to_spi_device(dev); 216 - u8 txbuf[1], rxbuf[7]; 191 + u8 rxbuf[7]; 217 192 int ret; 218 193 219 - txbuf[0] = PCF2123_READ | PCF2123_REG_SC; 220 - ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), 221 - rxbuf, sizeof(rxbuf)); 194 + ret = pcf2123_read(dev, PCF2123_REG_SC, rxbuf, sizeof(rxbuf)); 222 195 if (ret < 0) 223 196 return ret; 224 - pcf2123_delay_trec(); 197 + 198 + if (rxbuf[0] & OSC_HAS_STOPPED) { 199 + dev_info(dev, "clock was stopped. Time is not valid\n"); 200 + return -EINVAL; 201 + } 225 202 226 203 tm->tm_sec = bcd2bin(rxbuf[0] & 0x7F); 227 204 tm->tm_min = bcd2bin(rxbuf[1] & 0x7F); ··· 295 170 296 171 static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm) 297 172 { 298 - struct spi_device *spi = to_spi_device(dev); 299 173 u8 txbuf[8]; 300 174 int ret; 301 175 ··· 305 181 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 306 182 307 183 /* Stop the counter first */ 308 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_CTRL1; 309 - txbuf[1] = 0x20; 310 - ret = spi_write(spi, txbuf, 2); 184 + ret = pcf2123_write_reg(dev, PCF2123_REG_CTRL1, CTRL1_STOP); 311 185 if (ret < 0) 312 186 return ret; 313 - pcf2123_delay_trec(); 314 187 315 188 /* Set the new time */ 316 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_SC; 189 + txbuf[0] = PCF2123_REG_SC; 317 190 txbuf[1] = bin2bcd(tm->tm_sec & 0x7F); 318 191 txbuf[2] = bin2bcd(tm->tm_min & 0x7F); 319 192 txbuf[3] = bin2bcd(tm->tm_hour & 0x3F); ··· 319 198 txbuf[6] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */ 320 199 txbuf[7] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100); 321 200 322 - ret = spi_write(spi, txbuf, sizeof(txbuf)); 201 + ret = pcf2123_write(dev, txbuf, sizeof(txbuf)); 323 202 if (ret < 0) 324 203 return ret; 325 - pcf2123_delay_trec(); 326 204 327 205 /* Start the counter */ 328 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_CTRL1; 329 - txbuf[1] = 0x00; 330 - ret = spi_write(spi, txbuf, 2); 206 + ret = pcf2123_write_reg(dev, PCF2123_REG_CTRL1, CTRL1_CLEAR); 331 207 if (ret < 0) 332 208 return ret; 333 - pcf2123_delay_trec(); 209 + 210 + return 0; 211 + } 212 + 213 + static int pcf2123_reset(struct device *dev) 214 + { 215 + int ret; 216 + u8 rxbuf[2]; 217 + 218 + ret = pcf2123_write_reg(dev, PCF2123_REG_CTRL1, CTRL1_SW_RESET); 219 + if (ret < 0) 220 + return ret; 221 + 222 + /* Stop the counter */ 223 + dev_dbg(dev, "stopping RTC\n"); 224 + ret = pcf2123_write_reg(dev, PCF2123_REG_CTRL1, CTRL1_STOP); 225 + if (ret < 0) 226 + return ret; 227 + 228 + /* See if the counter was actually stopped */ 229 + dev_dbg(dev, "checking for presence of RTC\n"); 230 + ret = pcf2123_read(dev, PCF2123_REG_CTRL1, rxbuf, sizeof(rxbuf)); 231 + if (ret < 0) 232 + return ret; 233 + 234 + dev_dbg(dev, "received data from RTC (0x%02X 0x%02X)\n", 235 + rxbuf[0], rxbuf[1]); 236 + if (!(rxbuf[0] & CTRL1_STOP)) 237 + return -ENODEV; 238 + 239 + /* Start the counter */ 240 + ret = pcf2123_write_reg(dev, PCF2123_REG_CTRL1, CTRL1_CLEAR); 241 + if (ret < 0) 242 + return ret; 334 243 335 244 return 0; 336 245 } ··· 368 217 static const struct rtc_class_ops pcf2123_rtc_ops = { 369 218 .read_time = pcf2123_rtc_read_time, 370 219 .set_time = pcf2123_rtc_set_time, 220 + .read_offset = pcf2123_read_offset, 221 + .set_offset = pcf2123_set_offset, 222 + 371 223 }; 372 224 373 225 static int pcf2123_probe(struct spi_device *spi) 374 226 { 375 227 struct rtc_device *rtc; 228 + struct rtc_time tm; 376 229 struct pcf2123_plat_data *pdata; 377 - u8 txbuf[2], rxbuf[2]; 378 230 int ret, i; 379 231 380 232 pdata = devm_kzalloc(&spi->dev, sizeof(struct pcf2123_plat_data), ··· 386 232 return -ENOMEM; 387 233 spi->dev.platform_data = pdata; 388 234 389 - /* Send a software reset command */ 390 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_CTRL1; 391 - txbuf[1] = 0x58; 392 - dev_dbg(&spi->dev, "resetting RTC (0x%02X 0x%02X)\n", 393 - txbuf[0], txbuf[1]); 394 - ret = spi_write(spi, txbuf, 2 * sizeof(u8)); 395 - if (ret < 0) 396 - goto kfree_exit; 397 - pcf2123_delay_trec(); 398 - 399 - /* Stop the counter */ 400 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_CTRL1; 401 - txbuf[1] = 0x20; 402 - dev_dbg(&spi->dev, "stopping RTC (0x%02X 0x%02X)\n", 403 - txbuf[0], txbuf[1]); 404 - ret = spi_write(spi, txbuf, 2 * sizeof(u8)); 405 - if (ret < 0) 406 - goto kfree_exit; 407 - pcf2123_delay_trec(); 408 - 409 - /* See if the counter was actually stopped */ 410 - txbuf[0] = PCF2123_READ | PCF2123_REG_CTRL1; 411 - dev_dbg(&spi->dev, "checking for presence of RTC (0x%02X)\n", 412 - txbuf[0]); 413 - ret = spi_write_then_read(spi, txbuf, 1 * sizeof(u8), 414 - rxbuf, 2 * sizeof(u8)); 415 - dev_dbg(&spi->dev, "received data from RTC (0x%02X 0x%02X)\n", 416 - rxbuf[0], rxbuf[1]); 417 - if (ret < 0) 418 - goto kfree_exit; 419 - pcf2123_delay_trec(); 420 - 421 - if (!(rxbuf[0] & 0x20)) { 422 - dev_err(&spi->dev, "chip not found\n"); 423 - ret = -ENODEV; 424 - goto kfree_exit; 235 + ret = pcf2123_rtc_read_time(&spi->dev, &tm); 236 + if (ret < 0) { 237 + ret = pcf2123_reset(&spi->dev); 238 + if (ret < 0) { 239 + dev_err(&spi->dev, "chip not found\n"); 240 + goto kfree_exit; 241 + } 425 242 } 426 243 427 244 dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n"); 428 245 dev_info(&spi->dev, "spiclk %u KHz.\n", 429 246 (spi->max_speed_hz + 500) / 1000); 430 - 431 - /* Start the counter */ 432 - txbuf[0] = PCF2123_WRITE | PCF2123_REG_CTRL1; 433 - txbuf[1] = 0x00; 434 - ret = spi_write(spi, txbuf, sizeof(txbuf)); 435 - if (ret < 0) 436 - goto kfree_exit; 437 - pcf2123_delay_trec(); 438 247 439 248 /* Finalize the initialization */ 440 249 rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
+266 -75
drivers/rtc/rtc-pcf2127.c
··· 1 1 /* 2 - * An I2C driver for the NXP PCF2127 RTC 2 + * An I2C and SPI driver for the NXP PCF2127/29 RTC 3 3 * Copyright 2013 Til-Technologies 4 4 * 5 5 * Author: Renaud Cerrato <r.cerrato@til-technologies.fr> 6 6 * 7 7 * based on the other drivers in this same directory. 8 8 * 9 - * http://www.nxp.com/documents/data_sheet/PCF2127AT.pdf 9 + * Datasheet: http://cache.nxp.com/documents/data_sheet/PCF2127.pdf 10 10 * 11 11 * This program is free software; you can redistribute it and/or modify 12 12 * it under the terms of the GNU General Public License version 2 as ··· 14 14 */ 15 15 16 16 #include <linux/i2c.h> 17 + #include <linux/spi/spi.h> 17 18 #include <linux/bcd.h> 18 19 #include <linux/rtc.h> 19 20 #include <linux/slab.h> 20 21 #include <linux/module.h> 21 22 #include <linux/of.h> 23 + #include <linux/regmap.h> 22 24 23 25 #define PCF2127_REG_CTRL1 (0x00) /* Control Register 1 */ 24 26 #define PCF2127_REG_CTRL2 (0x01) /* Control Register 2 */ ··· 38 36 39 37 #define PCF2127_OSF BIT(7) /* Oscillator Fail flag */ 40 38 41 - static struct i2c_driver pcf2127_driver; 42 - 43 39 struct pcf2127 { 44 40 struct rtc_device *rtc; 41 + struct regmap *regmap; 45 42 }; 46 43 47 44 /* 48 45 * In the routines that deal directly with the pcf2127 hardware, we use 49 46 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 50 47 */ 51 - static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm) 48 + static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) 52 49 { 53 - unsigned char buf[10] = { PCF2127_REG_CTRL1 }; 50 + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 51 + unsigned char buf[10]; 52 + int ret; 54 53 55 - /* read registers */ 56 - if (i2c_master_send(client, buf, 1) != 1 || 57 - i2c_master_recv(client, buf, sizeof(buf)) != sizeof(buf)) { 58 - dev_err(&client->dev, "%s: read error\n", __func__); 59 - return -EIO; 54 + ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL1, buf, 55 + sizeof(buf)); 56 + if (ret) { 57 + dev_err(dev, "%s: read error\n", __func__); 58 + return ret; 60 59 } 61 60 62 61 if (buf[PCF2127_REG_CTRL3] & PCF2127_REG_CTRL3_BLF) 63 - dev_info(&client->dev, 62 + dev_info(dev, 64 63 "low voltage detected, check/replace RTC battery.\n"); 65 64 66 65 if (buf[PCF2127_REG_SC] & PCF2127_OSF) { ··· 69 66 * no need clear the flag here, 70 67 * it will be cleared once the new date is saved 71 68 */ 72 - dev_warn(&client->dev, 69 + dev_warn(dev, 73 70 "oscillator stop detected, date/time is not reliable\n"); 74 71 return -EINVAL; 75 72 } 76 73 77 - dev_dbg(&client->dev, 74 + dev_dbg(dev, 78 75 "%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, " 79 76 "sec=%02x, min=%02x, hr=%02x, " 80 77 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n", ··· 94 91 if (tm->tm_year < 70) 95 92 tm->tm_year += 100; /* assume we are in 1970...2069 */ 96 93 97 - dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 94 + dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 98 95 "mday=%d, mon=%d, year=%d, wday=%d\n", 99 96 __func__, 100 97 tm->tm_sec, tm->tm_min, tm->tm_hour, ··· 103 100 return rtc_valid_tm(tm); 104 101 } 105 102 106 - static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) 103 + static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) 107 104 { 108 - unsigned char buf[8]; 105 + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 106 + unsigned char buf[7]; 109 107 int i = 0, err; 110 108 111 - dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, " 109 + dev_dbg(dev, "%s: secs=%d, mins=%d, hours=%d, " 112 110 "mday=%d, mon=%d, year=%d, wday=%d\n", 113 111 __func__, 114 112 tm->tm_sec, tm->tm_min, tm->tm_hour, 115 113 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 116 - 117 - /* start register address */ 118 - buf[i++] = PCF2127_REG_SC; 119 114 120 115 /* hours, minutes and seconds */ 121 116 buf[i++] = bin2bcd(tm->tm_sec); /* this will also clear OSF flag */ ··· 129 128 buf[i++] = bin2bcd(tm->tm_year % 100); 130 129 131 130 /* write register's data */ 132 - err = i2c_master_send(client, buf, i); 133 - if (err != i) { 134 - dev_err(&client->dev, 131 + err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i); 132 + if (err) { 133 + dev_err(dev, 135 134 "%s: err=%d", __func__, err); 136 - return -EIO; 135 + return err; 137 136 } 138 137 139 138 return 0; ··· 143 142 static int pcf2127_rtc_ioctl(struct device *dev, 144 143 unsigned int cmd, unsigned long arg) 145 144 { 146 - struct i2c_client *client = to_i2c_client(dev); 147 - unsigned char buf = PCF2127_REG_CTRL3; 145 + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 148 146 int touser; 149 147 int ret; 150 148 151 149 switch (cmd) { 152 150 case RTC_VL_READ: 153 - ret = i2c_master_send(client, &buf, 1); 154 - if (!ret) 155 - ret = -EIO; 156 - if (ret < 0) 151 + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &touser); 152 + if (ret) 157 153 return ret; 158 154 159 - ret = i2c_master_recv(client, &buf, 1); 160 - if (!ret) 161 - ret = -EIO; 162 - if (ret < 0) 163 - return ret; 164 - 165 - touser = buf & PCF2127_REG_CTRL3_BLF ? 1 : 0; 155 + touser = touser & PCF2127_REG_CTRL3_BLF ? 1 : 0; 166 156 167 157 if (copy_to_user((void __user *)arg, &touser, sizeof(int))) 168 158 return -EFAULT; ··· 166 174 #define pcf2127_rtc_ioctl NULL 167 175 #endif 168 176 169 - static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) 170 - { 171 - return pcf2127_get_datetime(to_i2c_client(dev), tm); 172 - } 173 - 174 - static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm) 175 - { 176 - return pcf2127_set_datetime(to_i2c_client(dev), tm); 177 - } 178 - 179 177 static const struct rtc_class_ops pcf2127_rtc_ops = { 180 178 .ioctl = pcf2127_rtc_ioctl, 181 179 .read_time = pcf2127_rtc_read_time, 182 180 .set_time = pcf2127_rtc_set_time, 183 181 }; 184 182 185 - static int pcf2127_probe(struct i2c_client *client, 186 - const struct i2c_device_id *id) 183 + static int pcf2127_probe(struct device *dev, struct regmap *regmap, 184 + const char *name) 187 185 { 188 186 struct pcf2127 *pcf2127; 189 187 190 - dev_dbg(&client->dev, "%s\n", __func__); 188 + dev_dbg(dev, "%s\n", __func__); 191 189 192 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 193 - return -ENODEV; 194 - 195 - pcf2127 = devm_kzalloc(&client->dev, sizeof(struct pcf2127), 196 - GFP_KERNEL); 190 + pcf2127 = devm_kzalloc(dev, sizeof(*pcf2127), GFP_KERNEL); 197 191 if (!pcf2127) 198 192 return -ENOMEM; 199 193 200 - i2c_set_clientdata(client, pcf2127); 194 + pcf2127->regmap = regmap; 201 195 202 - pcf2127->rtc = devm_rtc_device_register(&client->dev, 203 - pcf2127_driver.driver.name, 204 - &pcf2127_rtc_ops, THIS_MODULE); 196 + dev_set_drvdata(dev, pcf2127); 197 + 198 + pcf2127->rtc = devm_rtc_device_register(dev, name, &pcf2127_rtc_ops, 199 + THIS_MODULE); 205 200 206 201 return PTR_ERR_OR_ZERO(pcf2127->rtc); 207 202 } 208 203 209 - static const struct i2c_device_id pcf2127_id[] = { 210 - { "pcf2127", 0 }, 211 - { } 212 - }; 213 - MODULE_DEVICE_TABLE(i2c, pcf2127_id); 214 - 215 204 #ifdef CONFIG_OF 216 205 static const struct of_device_id pcf2127_of_match[] = { 217 206 { .compatible = "nxp,pcf2127" }, 207 + { .compatible = "nxp,pcf2129" }, 218 208 {} 219 209 }; 220 210 MODULE_DEVICE_TABLE(of, pcf2127_of_match); 221 211 #endif 222 212 223 - static struct i2c_driver pcf2127_driver = { 224 - .driver = { 225 - .name = "rtc-pcf2127", 226 - .of_match_table = of_match_ptr(pcf2127_of_match), 227 - }, 228 - .probe = pcf2127_probe, 229 - .id_table = pcf2127_id, 213 + #if IS_ENABLED(CONFIG_I2C) 214 + 215 + static int pcf2127_i2c_write(void *context, const void *data, size_t count) 216 + { 217 + struct device *dev = context; 218 + struct i2c_client *client = to_i2c_client(dev); 219 + int ret; 220 + 221 + ret = i2c_master_send(client, data, count); 222 + if (ret != count) 223 + return ret < 0 ? ret : -EIO; 224 + 225 + return 0; 226 + } 227 + 228 + static int pcf2127_i2c_gather_write(void *context, 229 + const void *reg, size_t reg_size, 230 + const void *val, size_t val_size) 231 + { 232 + struct device *dev = context; 233 + struct i2c_client *client = to_i2c_client(dev); 234 + int ret; 235 + void *buf; 236 + 237 + if (WARN_ON(reg_size != 1)) 238 + return -EINVAL; 239 + 240 + buf = kmalloc(val_size + 1, GFP_KERNEL); 241 + if (!buf) 242 + return -ENOMEM; 243 + 244 + memcpy(buf, reg, 1); 245 + memcpy(buf + 1, val, val_size); 246 + 247 + ret = i2c_master_send(client, buf, val_size + 1); 248 + if (ret != val_size + 1) 249 + return ret < 0 ? ret : -EIO; 250 + 251 + return 0; 252 + } 253 + 254 + static int pcf2127_i2c_read(void *context, const void *reg, size_t reg_size, 255 + void *val, size_t val_size) 256 + { 257 + struct device *dev = context; 258 + struct i2c_client *client = to_i2c_client(dev); 259 + int ret; 260 + 261 + if (WARN_ON(reg_size != 1)) 262 + return -EINVAL; 263 + 264 + ret = i2c_master_send(client, reg, 1); 265 + if (ret != 1) 266 + return ret < 0 ? ret : -EIO; 267 + 268 + ret = i2c_master_recv(client, val, val_size); 269 + if (ret != val_size) 270 + return ret < 0 ? ret : -EIO; 271 + 272 + return 0; 273 + } 274 + 275 + /* 276 + * The reason we need this custom regmap_bus instead of using regmap_init_i2c() 277 + * is that the STOP condition is required between set register address and 278 + * read register data when reading from registers. 279 + */ 280 + static const struct regmap_bus pcf2127_i2c_regmap = { 281 + .write = pcf2127_i2c_write, 282 + .gather_write = pcf2127_i2c_gather_write, 283 + .read = pcf2127_i2c_read, 230 284 }; 231 285 232 - module_i2c_driver(pcf2127_driver); 286 + static struct i2c_driver pcf2127_i2c_driver; 287 + 288 + static int pcf2127_i2c_probe(struct i2c_client *client, 289 + const struct i2c_device_id *id) 290 + { 291 + struct regmap *regmap; 292 + static const struct regmap_config config = { 293 + .reg_bits = 8, 294 + .val_bits = 8, 295 + }; 296 + 297 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 298 + return -ENODEV; 299 + 300 + regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap, 301 + &client->dev, &config); 302 + if (IS_ERR(regmap)) { 303 + dev_err(&client->dev, "%s: regmap allocation failed: %ld\n", 304 + __func__, PTR_ERR(regmap)); 305 + return PTR_ERR(regmap); 306 + } 307 + 308 + return pcf2127_probe(&client->dev, regmap, 309 + pcf2127_i2c_driver.driver.name); 310 + } 311 + 312 + static const struct i2c_device_id pcf2127_i2c_id[] = { 313 + { "pcf2127", 0 }, 314 + { "pcf2129", 0 }, 315 + { } 316 + }; 317 + MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id); 318 + 319 + static struct i2c_driver pcf2127_i2c_driver = { 320 + .driver = { 321 + .name = "rtc-pcf2127-i2c", 322 + .of_match_table = of_match_ptr(pcf2127_of_match), 323 + }, 324 + .probe = pcf2127_i2c_probe, 325 + .id_table = pcf2127_i2c_id, 326 + }; 327 + 328 + static int pcf2127_i2c_register_driver(void) 329 + { 330 + return i2c_add_driver(&pcf2127_i2c_driver); 331 + } 332 + 333 + static void pcf2127_i2c_unregister_driver(void) 334 + { 335 + i2c_del_driver(&pcf2127_i2c_driver); 336 + } 337 + 338 + #else 339 + 340 + static int pcf2127_i2c_register_driver(void) 341 + { 342 + return 0; 343 + } 344 + 345 + static void pcf2127_i2c_unregister_driver(void) 346 + { 347 + } 348 + 349 + #endif 350 + 351 + #if IS_ENABLED(CONFIG_SPI_MASTER) 352 + 353 + static struct spi_driver pcf2127_spi_driver; 354 + 355 + static int pcf2127_spi_probe(struct spi_device *spi) 356 + { 357 + static const struct regmap_config config = { 358 + .reg_bits = 8, 359 + .val_bits = 8, 360 + .read_flag_mask = 0xa0, 361 + .write_flag_mask = 0x20, 362 + }; 363 + struct regmap *regmap; 364 + 365 + regmap = devm_regmap_init_spi(spi, &config); 366 + if (IS_ERR(regmap)) { 367 + dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", 368 + __func__, PTR_ERR(regmap)); 369 + return PTR_ERR(regmap); 370 + } 371 + 372 + return pcf2127_probe(&spi->dev, regmap, pcf2127_spi_driver.driver.name); 373 + } 374 + 375 + static const struct spi_device_id pcf2127_spi_id[] = { 376 + { "pcf2127", 0 }, 377 + { "pcf2129", 0 }, 378 + { } 379 + }; 380 + MODULE_DEVICE_TABLE(spi, pcf2127_spi_id); 381 + 382 + static struct spi_driver pcf2127_spi_driver = { 383 + .driver = { 384 + .name = "rtc-pcf2127-spi", 385 + .of_match_table = of_match_ptr(pcf2127_of_match), 386 + }, 387 + .probe = pcf2127_spi_probe, 388 + .id_table = pcf2127_spi_id, 389 + }; 390 + 391 + static int pcf2127_spi_register_driver(void) 392 + { 393 + return spi_register_driver(&pcf2127_spi_driver); 394 + } 395 + 396 + static void pcf2127_spi_unregister_driver(void) 397 + { 398 + spi_unregister_driver(&pcf2127_spi_driver); 399 + } 400 + 401 + #else 402 + 403 + static int pcf2127_spi_register_driver(void) 404 + { 405 + return 0; 406 + } 407 + 408 + static void pcf2127_spi_unregister_driver(void) 409 + { 410 + } 411 + 412 + #endif 413 + 414 + static int __init pcf2127_init(void) 415 + { 416 + int ret; 417 + 418 + ret = pcf2127_i2c_register_driver(); 419 + if (ret) { 420 + pr_err("Failed to register pcf2127 i2c driver: %d\n", ret); 421 + return ret; 422 + } 423 + 424 + ret = pcf2127_spi_register_driver(); 425 + if (ret) { 426 + pr_err("Failed to register pcf2127 spi driver: %d\n", ret); 427 + pcf2127_i2c_unregister_driver(); 428 + } 429 + 430 + return ret; 431 + } 432 + module_init(pcf2127_init) 433 + 434 + static void __exit pcf2127_exit(void) 435 + { 436 + pcf2127_spi_unregister_driver(); 437 + pcf2127_i2c_unregister_driver(); 438 + } 439 + module_exit(pcf2127_exit) 233 440 234 441 MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>"); 235 - MODULE_DESCRIPTION("NXP PCF2127 RTC driver"); 442 + MODULE_DESCRIPTION("NXP PCF2127/29 RTC driver"); 236 443 MODULE_LICENSE("GPL v2");
+83 -73
drivers/rtc/rtc-pcf85063.c
··· 16 16 #include <linux/rtc.h> 17 17 #include <linux/module.h> 18 18 19 - #define DRV_VERSION "0.0.1" 20 - 21 19 #define PCF85063_REG_CTRL1 0x00 /* status */ 20 + #define PCF85063_REG_CTRL1_STOP BIT(5) 22 21 #define PCF85063_REG_CTRL2 0x01 23 22 24 23 #define PCF85063_REG_SC 0x04 /* datetime */ 24 + #define PCF85063_REG_SC_OS 0x80 25 25 #define PCF85063_REG_MN 0x05 26 26 #define PCF85063_REG_HR 0x06 27 27 #define PCF85063_REG_DM 0x07 ··· 29 29 #define PCF85063_REG_MO 0x09 30 30 #define PCF85063_REG_YR 0x0A 31 31 32 - #define PCF85063_MO_C 0x80 /* century */ 33 - 34 32 static struct i2c_driver pcf85063_driver; 35 33 36 - struct pcf85063 { 37 - struct rtc_device *rtc; 38 - int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */ 39 - int voltage_low; /* indicates if a low_voltage was detected */ 40 - }; 34 + static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1) 35 + { 36 + s32 ret; 37 + 38 + ret = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); 39 + if (ret < 0) { 40 + dev_err(&client->dev, "Failing to stop the clock\n"); 41 + return -EIO; 42 + } 43 + 44 + /* stop the clock */ 45 + ret |= PCF85063_REG_CTRL1_STOP; 46 + 47 + ret = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ret); 48 + if (ret < 0) { 49 + dev_err(&client->dev, "Failing to stop the clock\n"); 50 + return -EIO; 51 + } 52 + 53 + *ctrl1 = ret; 54 + 55 + return 0; 56 + } 41 57 42 58 /* 43 59 * In the routines that deal directly with the pcf85063 hardware, we use ··· 61 45 */ 62 46 static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) 63 47 { 64 - struct pcf85063 *pcf85063 = i2c_get_clientdata(client); 65 - unsigned char buf[13] = { PCF85063_REG_CTRL1 }; 66 - struct i2c_msg msgs[] = { 67 - {/* setup read ptr */ 68 - .addr = client->addr, 69 - .len = 1, 70 - .buf = buf 71 - }, 72 - {/* read status + date */ 73 - .addr = client->addr, 74 - .flags = I2C_M_RD, 75 - .len = 13, 76 - .buf = buf 77 - }, 78 - }; 48 + int rc; 49 + u8 regs[7]; 79 50 80 - /* read registers */ 81 - if ((i2c_transfer(client->adapter, msgs, 2)) != 2) { 82 - dev_err(&client->dev, "%s: read error\n", __func__); 51 + /* 52 + * while reading, the time/date registers are blocked and not updated 53 + * anymore until the access is finished. To not lose a second 54 + * event, the access must be finished within one second. So, read all 55 + * time/date registers in one turn. 56 + */ 57 + rc = i2c_smbus_read_i2c_block_data(client, PCF85063_REG_SC, 58 + sizeof(regs), regs); 59 + if (rc != sizeof(regs)) { 60 + dev_err(&client->dev, "date/time register read error\n"); 83 61 return -EIO; 84 62 } 85 63 86 - tm->tm_sec = bcd2bin(buf[PCF85063_REG_SC] & 0x7F); 87 - tm->tm_min = bcd2bin(buf[PCF85063_REG_MN] & 0x7F); 88 - tm->tm_hour = bcd2bin(buf[PCF85063_REG_HR] & 0x3F); /* rtc hr 0-23 */ 89 - tm->tm_mday = bcd2bin(buf[PCF85063_REG_DM] & 0x3F); 90 - tm->tm_wday = buf[PCF85063_REG_DW] & 0x07; 91 - tm->tm_mon = bcd2bin(buf[PCF85063_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ 92 - tm->tm_year = bcd2bin(buf[PCF85063_REG_YR]); 64 + /* if the clock has lost its power it makes no sense to use its time */ 65 + if (regs[0] & PCF85063_REG_SC_OS) { 66 + dev_warn(&client->dev, "Power loss detected, invalid time\n"); 67 + return -EINVAL; 68 + } 69 + 70 + tm->tm_sec = bcd2bin(regs[0] & 0x7F); 71 + tm->tm_min = bcd2bin(regs[1] & 0x7F); 72 + tm->tm_hour = bcd2bin(regs[2] & 0x3F); /* rtc hr 0-23 */ 73 + tm->tm_mday = bcd2bin(regs[3] & 0x3F); 74 + tm->tm_wday = regs[4] & 0x07; 75 + tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ 76 + tm->tm_year = bcd2bin(regs[6]); 93 77 if (tm->tm_year < 70) 94 78 tm->tm_year += 100; /* assume we are in 1970...2069 */ 95 - /* detect the polarity heuristically. see note above. */ 96 - pcf85063->c_polarity = (buf[PCF85063_REG_MO] & PCF85063_MO_C) ? 97 - (tm->tm_year >= 100) : (tm->tm_year < 100); 98 79 99 80 return rtc_valid_tm(tm); 100 81 } 101 82 102 83 static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm) 103 84 { 104 - int i = 0, err = 0; 105 - unsigned char buf[11]; 85 + int rc; 86 + u8 regs[8]; 106 87 107 - /* Control & status */ 108 - buf[PCF85063_REG_CTRL1] = 0; 109 - buf[PCF85063_REG_CTRL2] = 5; 88 + /* 89 + * to accurately set the time, reset the divider chain and keep it in 90 + * reset state until all time/date registers are written 91 + */ 92 + rc = pcf85063_stop_clock(client, &regs[7]); 93 + if (rc != 0) 94 + return rc; 110 95 111 96 /* hours, minutes and seconds */ 112 - buf[PCF85063_REG_SC] = bin2bcd(tm->tm_sec) & 0x7F; 97 + regs[0] = bin2bcd(tm->tm_sec) & 0x7F; /* clear OS flag */ 113 98 114 - buf[PCF85063_REG_MN] = bin2bcd(tm->tm_min); 115 - buf[PCF85063_REG_HR] = bin2bcd(tm->tm_hour); 99 + regs[1] = bin2bcd(tm->tm_min); 100 + regs[2] = bin2bcd(tm->tm_hour); 116 101 117 102 /* Day of month, 1 - 31 */ 118 - buf[PCF85063_REG_DM] = bin2bcd(tm->tm_mday); 103 + regs[3] = bin2bcd(tm->tm_mday); 119 104 120 105 /* Day, 0 - 6 */ 121 - buf[PCF85063_REG_DW] = tm->tm_wday & 0x07; 106 + regs[4] = tm->tm_wday & 0x07; 122 107 123 108 /* month, 1 - 12 */ 124 - buf[PCF85063_REG_MO] = bin2bcd(tm->tm_mon + 1); 109 + regs[5] = bin2bcd(tm->tm_mon + 1); 125 110 126 111 /* year and century */ 127 - buf[PCF85063_REG_YR] = bin2bcd(tm->tm_year % 100); 112 + regs[6] = bin2bcd(tm->tm_year % 100); 128 113 129 - /* write register's data */ 130 - for (i = 0; i < sizeof(buf); i++) { 131 - unsigned char data[2] = { i, buf[i] }; 114 + /* 115 + * after all time/date registers are written, let the 'address auto 116 + * increment' feature wrap around and write register CTRL1 to re-enable 117 + * the clock divider chain again 118 + */ 119 + regs[7] &= ~PCF85063_REG_CTRL1_STOP; 132 120 133 - err = i2c_master_send(client, data, sizeof(data)); 134 - if (err != sizeof(data)) { 135 - dev_err(&client->dev, "%s: err=%d addr=%02x, data=%02x\n", 136 - __func__, err, data[0], data[1]); 137 - return -EIO; 138 - } 121 + /* write all registers at once */ 122 + rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC, 123 + sizeof(regs), regs); 124 + if (rc < 0) { 125 + dev_err(&client->dev, "date/time register write error\n"); 126 + return rc; 139 127 } 140 128 141 129 return 0; ··· 163 143 static int pcf85063_probe(struct i2c_client *client, 164 144 const struct i2c_device_id *id) 165 145 { 166 - struct pcf85063 *pcf85063; 146 + struct rtc_device *rtc; 167 147 168 148 dev_dbg(&client->dev, "%s\n", __func__); 169 149 170 150 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 171 151 return -ENODEV; 172 152 173 - pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063), 174 - GFP_KERNEL); 175 - if (!pcf85063) 176 - return -ENOMEM; 153 + rtc = devm_rtc_device_register(&client->dev, 154 + pcf85063_driver.driver.name, 155 + &pcf85063_rtc_ops, THIS_MODULE); 177 156 178 - dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 179 - 180 - i2c_set_clientdata(client, pcf85063); 181 - 182 - pcf85063->rtc = devm_rtc_device_register(&client->dev, 183 - pcf85063_driver.driver.name, 184 - &pcf85063_rtc_ops, THIS_MODULE); 185 - 186 - return PTR_ERR_OR_ZERO(pcf85063->rtc); 157 + return PTR_ERR_OR_ZERO(rtc); 187 158 } 188 159 189 160 static const struct i2c_device_id pcf85063_id[] = { ··· 205 194 MODULE_AUTHOR("Søren Andersen <san@rosetechnology.dk>"); 206 195 MODULE_DESCRIPTION("PCF85063 RTC driver"); 207 196 MODULE_LICENSE("GPL"); 208 - MODULE_VERSION(DRV_VERSION);
+3 -22
drivers/rtc/rtc-pcf8523.c
··· 178 178 if (err < 0) 179 179 return err; 180 180 181 - if (regs[0] & REG_SECONDS_OS) { 182 - /* 183 - * If the oscillator was stopped, try to clear the flag. Upon 184 - * power-up the flag is always set, but if we cannot clear it 185 - * the oscillator isn't running properly for some reason. The 186 - * sensible thing therefore is to return an error, signalling 187 - * that the clock cannot be assumed to be correct. 188 - */ 189 - 190 - regs[0] &= ~REG_SECONDS_OS; 191 - 192 - err = pcf8523_write(client, REG_SECONDS, regs[0]); 193 - if (err < 0) 194 - return err; 195 - 196 - err = pcf8523_read(client, REG_SECONDS, &regs[0]); 197 - if (err < 0) 198 - return err; 199 - 200 - if (regs[0] & REG_SECONDS_OS) 201 - return -EAGAIN; 202 - } 181 + if (regs[0] & REG_SECONDS_OS) 182 + return -EINVAL; 203 183 204 184 tm->tm_sec = bcd2bin(regs[0] & 0x7f); 205 185 tm->tm_min = bcd2bin(regs[1] & 0x7f); ··· 215 235 return err; 216 236 217 237 regs[0] = REG_SECONDS; 238 + /* This will purposely overwrite REG_SECONDS_OS */ 218 239 regs[1] = bin2bcd(tm->tm_sec); 219 240 regs[2] = bin2bcd(tm->tm_min); 220 241 regs[3] = bin2bcd(tm->tm_hour);
+411
drivers/rtc/rtc-pic32.c
··· 1 + /* 2 + * PIC32 RTC driver 3 + * 4 + * Joshua Henderson <joshua.henderson@microchip.com> 5 + * Copyright (C) 2016 Microchip Technology Inc. All rights reserved. 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, but WITHOUT 13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 + * more details. 16 + */ 17 + #include <linux/init.h> 18 + #include <linux/module.h> 19 + #include <linux/of.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/io.h> 22 + #include <linux/slab.h> 23 + #include <linux/clk.h> 24 + #include <linux/rtc.h> 25 + #include <linux/bcd.h> 26 + 27 + #include <asm/mach-pic32/pic32.h> 28 + 29 + #define PIC32_RTCCON 0x00 30 + #define PIC32_RTCCON_ON BIT(15) 31 + #define PIC32_RTCCON_SIDL BIT(13) 32 + #define PIC32_RTCCON_RTCCLKSEL (3 << 9) 33 + #define PIC32_RTCCON_RTCCLKON BIT(6) 34 + #define PIC32_RTCCON_RTCWREN BIT(3) 35 + #define PIC32_RTCCON_RTCSYNC BIT(2) 36 + #define PIC32_RTCCON_HALFSEC BIT(1) 37 + #define PIC32_RTCCON_RTCOE BIT(0) 38 + 39 + #define PIC32_RTCALRM 0x10 40 + #define PIC32_RTCALRM_ALRMEN BIT(15) 41 + #define PIC32_RTCALRM_CHIME BIT(14) 42 + #define PIC32_RTCALRM_PIV BIT(13) 43 + #define PIC32_RTCALRM_ALARMSYNC BIT(12) 44 + #define PIC32_RTCALRM_AMASK 0x0F00 45 + #define PIC32_RTCALRM_ARPT 0xFF 46 + 47 + #define PIC32_RTCHOUR 0x23 48 + #define PIC32_RTCMIN 0x22 49 + #define PIC32_RTCSEC 0x21 50 + #define PIC32_RTCYEAR 0x33 51 + #define PIC32_RTCMON 0x32 52 + #define PIC32_RTCDAY 0x31 53 + 54 + #define PIC32_ALRMTIME 0x40 55 + #define PIC32_ALRMDATE 0x50 56 + 57 + #define PIC32_ALRMHOUR 0x43 58 + #define PIC32_ALRMMIN 0x42 59 + #define PIC32_ALRMSEC 0x41 60 + #define PIC32_ALRMYEAR 0x53 61 + #define PIC32_ALRMMON 0x52 62 + #define PIC32_ALRMDAY 0x51 63 + 64 + struct pic32_rtc_dev { 65 + struct rtc_device *rtc; 66 + void __iomem *reg_base; 67 + struct clk *clk; 68 + spinlock_t alarm_lock; 69 + int alarm_irq; 70 + bool alarm_clk_enabled; 71 + }; 72 + 73 + static void pic32_rtc_alarm_clk_enable(struct pic32_rtc_dev *pdata, 74 + bool enable) 75 + { 76 + unsigned long flags; 77 + 78 + spin_lock_irqsave(&pdata->alarm_lock, flags); 79 + if (enable) { 80 + if (!pdata->alarm_clk_enabled) { 81 + clk_enable(pdata->clk); 82 + pdata->alarm_clk_enabled = true; 83 + } 84 + } else { 85 + if (pdata->alarm_clk_enabled) { 86 + clk_disable(pdata->clk); 87 + pdata->alarm_clk_enabled = false; 88 + } 89 + } 90 + spin_unlock_irqrestore(&pdata->alarm_lock, flags); 91 + } 92 + 93 + static irqreturn_t pic32_rtc_alarmirq(int irq, void *id) 94 + { 95 + struct pic32_rtc_dev *pdata = (struct pic32_rtc_dev *)id; 96 + 97 + clk_enable(pdata->clk); 98 + rtc_update_irq(pdata->rtc, 1, RTC_AF | RTC_IRQF); 99 + clk_disable(pdata->clk); 100 + 101 + pic32_rtc_alarm_clk_enable(pdata, false); 102 + 103 + return IRQ_HANDLED; 104 + } 105 + 106 + static int pic32_rtc_setaie(struct device *dev, unsigned int enabled) 107 + { 108 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 109 + void __iomem *base = pdata->reg_base; 110 + 111 + clk_enable(pdata->clk); 112 + 113 + writel(PIC32_RTCALRM_ALRMEN, 114 + base + (enabled ? PIC32_SET(PIC32_RTCALRM) : 115 + PIC32_CLR(PIC32_RTCALRM))); 116 + 117 + clk_disable(pdata->clk); 118 + 119 + pic32_rtc_alarm_clk_enable(pdata, enabled); 120 + 121 + return 0; 122 + } 123 + 124 + static int pic32_rtc_setfreq(struct device *dev, int freq) 125 + { 126 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 127 + void __iomem *base = pdata->reg_base; 128 + 129 + clk_enable(pdata->clk); 130 + 131 + writel(PIC32_RTCALRM_AMASK, base + PIC32_CLR(PIC32_RTCALRM)); 132 + writel(freq << 8, base + PIC32_SET(PIC32_RTCALRM)); 133 + writel(PIC32_RTCALRM_CHIME, base + PIC32_SET(PIC32_RTCALRM)); 134 + 135 + clk_disable(pdata->clk); 136 + 137 + return 0; 138 + } 139 + 140 + static int pic32_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) 141 + { 142 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 143 + void __iomem *base = pdata->reg_base; 144 + unsigned int tries = 0; 145 + 146 + clk_enable(pdata->clk); 147 + 148 + do { 149 + rtc_tm->tm_hour = readb(base + PIC32_RTCHOUR); 150 + rtc_tm->tm_min = readb(base + PIC32_RTCMIN); 151 + rtc_tm->tm_mon = readb(base + PIC32_RTCMON); 152 + rtc_tm->tm_mday = readb(base + PIC32_RTCDAY); 153 + rtc_tm->tm_year = readb(base + PIC32_RTCYEAR); 154 + rtc_tm->tm_sec = readb(base + PIC32_RTCSEC); 155 + 156 + /* 157 + * The only way to work out whether the system was mid-update 158 + * when we read it is to check the second counter, and if it 159 + * is zero, then we re-try the entire read. 160 + */ 161 + tries += 1; 162 + } while (rtc_tm->tm_sec == 0 && tries < 2); 163 + 164 + rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec); 165 + rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min); 166 + rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour); 167 + rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday); 168 + rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon) - 1; 169 + rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year); 170 + 171 + rtc_tm->tm_year += 100; 172 + 173 + dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", 174 + 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 175 + rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 176 + 177 + clk_disable(pdata->clk); 178 + return rtc_valid_tm(rtc_tm); 179 + } 180 + 181 + static int pic32_rtc_settime(struct device *dev, struct rtc_time *tm) 182 + { 183 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 184 + void __iomem *base = pdata->reg_base; 185 + int year = tm->tm_year - 100; 186 + 187 + dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n", 188 + 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 189 + tm->tm_hour, tm->tm_min, tm->tm_sec); 190 + 191 + if (year < 0 || year >= 100) { 192 + dev_err(dev, "rtc only supports 100 years\n"); 193 + return -EINVAL; 194 + } 195 + 196 + clk_enable(pdata->clk); 197 + writeb(bin2bcd(tm->tm_sec), base + PIC32_RTCSEC); 198 + writeb(bin2bcd(tm->tm_min), base + PIC32_RTCMIN); 199 + writeb(bin2bcd(tm->tm_hour), base + PIC32_RTCHOUR); 200 + writeb(bin2bcd(tm->tm_mday), base + PIC32_RTCDAY); 201 + writeb(bin2bcd(tm->tm_mon + 1), base + PIC32_RTCMON); 202 + writeb(bin2bcd(year), base + PIC32_RTCYEAR); 203 + clk_disable(pdata->clk); 204 + 205 + return 0; 206 + } 207 + 208 + static int pic32_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm) 209 + { 210 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 211 + struct rtc_time *alm_tm = &alrm->time; 212 + void __iomem *base = pdata->reg_base; 213 + unsigned int alm_en; 214 + 215 + clk_enable(pdata->clk); 216 + alm_tm->tm_sec = readb(base + PIC32_ALRMSEC); 217 + alm_tm->tm_min = readb(base + PIC32_ALRMMIN); 218 + alm_tm->tm_hour = readb(base + PIC32_ALRMHOUR); 219 + alm_tm->tm_mon = readb(base + PIC32_ALRMMON); 220 + alm_tm->tm_mday = readb(base + PIC32_ALRMDAY); 221 + alm_tm->tm_year = readb(base + PIC32_ALRMYEAR); 222 + 223 + alm_en = readb(base + PIC32_RTCALRM); 224 + 225 + alrm->enabled = (alm_en & PIC32_RTCALRM_ALRMEN) ? 1 : 0; 226 + 227 + dev_dbg(dev, "getalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 228 + alm_en, 229 + 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 230 + alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 231 + 232 + alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 233 + alm_tm->tm_min = bcd2bin(alm_tm->tm_min); 234 + alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); 235 + alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); 236 + alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon) - 1; 237 + alm_tm->tm_year = bcd2bin(alm_tm->tm_year); 238 + 239 + clk_disable(pdata->clk); 240 + return 0; 241 + } 242 + 243 + static int pic32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 244 + { 245 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 246 + struct rtc_time *tm = &alrm->time; 247 + void __iomem *base = pdata->reg_base; 248 + 249 + clk_enable(pdata->clk); 250 + dev_dbg(dev, "setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 251 + alrm->enabled, 252 + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 253 + tm->tm_hour, tm->tm_min, tm->tm_sec); 254 + 255 + writel(0x00, base + PIC32_ALRMTIME); 256 + writel(0x00, base + PIC32_ALRMDATE); 257 + 258 + pic32_rtc_setaie(dev, alrm->enabled); 259 + 260 + clk_disable(pdata->clk); 261 + return 0; 262 + } 263 + 264 + static int pic32_rtc_proc(struct device *dev, struct seq_file *seq) 265 + { 266 + struct pic32_rtc_dev *pdata = dev_get_drvdata(dev); 267 + void __iomem *base = pdata->reg_base; 268 + unsigned int repeat; 269 + 270 + clk_enable(pdata->clk); 271 + 272 + repeat = readw(base + PIC32_RTCALRM); 273 + repeat &= PIC32_RTCALRM_ARPT; 274 + seq_printf(seq, "periodic_IRQ\t: %s\n", repeat ? "yes" : "no"); 275 + 276 + clk_disable(pdata->clk); 277 + return 0; 278 + } 279 + 280 + static const struct rtc_class_ops pic32_rtcops = { 281 + .read_time = pic32_rtc_gettime, 282 + .set_time = pic32_rtc_settime, 283 + .read_alarm = pic32_rtc_getalarm, 284 + .set_alarm = pic32_rtc_setalarm, 285 + .proc = pic32_rtc_proc, 286 + .alarm_irq_enable = pic32_rtc_setaie, 287 + }; 288 + 289 + static void pic32_rtc_enable(struct pic32_rtc_dev *pdata, int en) 290 + { 291 + void __iomem *base = pdata->reg_base; 292 + 293 + if (!base) 294 + return; 295 + 296 + clk_enable(pdata->clk); 297 + if (!en) { 298 + writel(PIC32_RTCCON_ON, base + PIC32_CLR(PIC32_RTCCON)); 299 + } else { 300 + pic32_syskey_unlock(); 301 + 302 + writel(PIC32_RTCCON_RTCWREN, base + PIC32_SET(PIC32_RTCCON)); 303 + writel(3 << 9, base + PIC32_CLR(PIC32_RTCCON)); 304 + 305 + if (!(readl(base + PIC32_RTCCON) & PIC32_RTCCON_ON)) 306 + writel(PIC32_RTCCON_ON, base + PIC32_SET(PIC32_RTCCON)); 307 + } 308 + clk_disable(pdata->clk); 309 + } 310 + 311 + static int pic32_rtc_remove(struct platform_device *pdev) 312 + { 313 + struct pic32_rtc_dev *pdata = platform_get_drvdata(pdev); 314 + 315 + pic32_rtc_setaie(&pdev->dev, 0); 316 + clk_unprepare(pdata->clk); 317 + pdata->clk = NULL; 318 + 319 + return 0; 320 + } 321 + 322 + static int pic32_rtc_probe(struct platform_device *pdev) 323 + { 324 + struct pic32_rtc_dev *pdata; 325 + struct resource *res; 326 + int ret; 327 + 328 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 329 + if (!pdata) 330 + return -ENOMEM; 331 + 332 + platform_set_drvdata(pdev, pdata); 333 + 334 + pdata->alarm_irq = platform_get_irq(pdev, 0); 335 + if (pdata->alarm_irq < 0) { 336 + dev_err(&pdev->dev, "no irq for alarm\n"); 337 + return pdata->alarm_irq; 338 + } 339 + 340 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 341 + pdata->reg_base = devm_ioremap_resource(&pdev->dev, res); 342 + if (IS_ERR(pdata->reg_base)) 343 + return PTR_ERR(pdata->reg_base); 344 + 345 + pdata->clk = devm_clk_get(&pdev->dev, NULL); 346 + if (IS_ERR(pdata->clk)) { 347 + dev_err(&pdev->dev, "failed to find rtc clock source\n"); 348 + ret = PTR_ERR(pdata->clk); 349 + pdata->clk = NULL; 350 + return ret; 351 + } 352 + 353 + spin_lock_init(&pdata->alarm_lock); 354 + 355 + clk_prepare_enable(pdata->clk); 356 + 357 + pic32_rtc_enable(pdata, 1); 358 + 359 + device_init_wakeup(&pdev->dev, 1); 360 + 361 + pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 362 + &pic32_rtcops, 363 + THIS_MODULE); 364 + if (IS_ERR(pdata->rtc)) { 365 + ret = PTR_ERR(pdata->rtc); 366 + goto err_nortc; 367 + } 368 + 369 + pdata->rtc->max_user_freq = 128; 370 + 371 + pic32_rtc_setfreq(&pdev->dev, 1); 372 + ret = devm_request_irq(&pdev->dev, pdata->alarm_irq, 373 + pic32_rtc_alarmirq, 0, 374 + dev_name(&pdev->dev), pdata); 375 + if (ret) { 376 + dev_err(&pdev->dev, 377 + "IRQ %d error %d\n", pdata->alarm_irq, ret); 378 + goto err_nortc; 379 + } 380 + 381 + clk_disable(pdata->clk); 382 + 383 + return 0; 384 + 385 + err_nortc: 386 + pic32_rtc_enable(pdata, 0); 387 + clk_disable_unprepare(pdata->clk); 388 + 389 + return ret; 390 + } 391 + 392 + static const struct of_device_id pic32_rtc_dt_ids[] = { 393 + { .compatible = "microchip,pic32mzda-rtc" }, 394 + { /* sentinel */ } 395 + }; 396 + MODULE_DEVICE_TABLE(of, pic32_rtc_dt_ids); 397 + 398 + static struct platform_driver pic32_rtc_driver = { 399 + .probe = pic32_rtc_probe, 400 + .remove = pic32_rtc_remove, 401 + .driver = { 402 + .name = "pic32-rtc", 403 + .owner = THIS_MODULE, 404 + .of_match_table = of_match_ptr(pic32_rtc_dt_ids), 405 + }, 406 + }; 407 + module_platform_driver(pic32_rtc_driver); 408 + 409 + MODULE_DESCRIPTION("Microchip PIC32 RTC Driver"); 410 + MODULE_AUTHOR("Joshua Henderson <joshua.henderson@microchip.com>"); 411 + MODULE_LICENSE("GPL");
+555 -166
drivers/rtc/rtc-rv3029c2.c
··· 1 1 /* 2 - * Micro Crystal RV-3029C2 rtc class driver 2 + * Micro Crystal RV-3029 rtc class driver 3 3 * 4 4 * Author: Gregory Hermant <gregory.hermant@calao-systems.com> 5 + * Michael Buesch <m@bues.ch> 5 6 * 6 7 * based on previously existing rtc class drivers 7 8 * ··· 10 9 * it under the terms of the GNU General Public License version 2 as 11 10 * published by the Free Software Foundation. 12 11 * 13 - * NOTE: Currently this driver only supports the bare minimum for read 14 - * and write the RTC and alarms. The extra features provided by this chip 15 - * (trickle charger, eeprom, T° compensation) are unavailable. 16 12 */ 17 13 18 14 #include <linux/module.h> 19 15 #include <linux/i2c.h> 20 16 #include <linux/bcd.h> 21 17 #include <linux/rtc.h> 18 + #include <linux/delay.h> 19 + #include <linux/of.h> 20 + #include <linux/hwmon.h> 21 + #include <linux/hwmon-sysfs.h> 22 + 22 23 23 24 /* Register map */ 24 25 /* control section */ 25 - #define RV3029C2_ONOFF_CTRL 0x00 26 - #define RV3029C2_IRQ_CTRL 0x01 27 - #define RV3029C2_IRQ_CTRL_AIE (1 << 0) 28 - #define RV3029C2_IRQ_FLAGS 0x02 29 - #define RV3029C2_IRQ_FLAGS_AF (1 << 0) 30 - #define RV3029C2_STATUS 0x03 31 - #define RV3029C2_STATUS_VLOW1 (1 << 2) 32 - #define RV3029C2_STATUS_VLOW2 (1 << 3) 33 - #define RV3029C2_STATUS_SR (1 << 4) 34 - #define RV3029C2_STATUS_PON (1 << 5) 35 - #define RV3029C2_STATUS_EEBUSY (1 << 7) 36 - #define RV3029C2_RST_CTRL 0x04 37 - #define RV3029C2_CONTROL_SECTION_LEN 0x05 26 + #define RV3029_ONOFF_CTRL 0x00 27 + #define RV3029_ONOFF_CTRL_WE BIT(0) 28 + #define RV3029_ONOFF_CTRL_TE BIT(1) 29 + #define RV3029_ONOFF_CTRL_TAR BIT(2) 30 + #define RV3029_ONOFF_CTRL_EERE BIT(3) 31 + #define RV3029_ONOFF_CTRL_SRON BIT(4) 32 + #define RV3029_ONOFF_CTRL_TD0 BIT(5) 33 + #define RV3029_ONOFF_CTRL_TD1 BIT(6) 34 + #define RV3029_ONOFF_CTRL_CLKINT BIT(7) 35 + #define RV3029_IRQ_CTRL 0x01 36 + #define RV3029_IRQ_CTRL_AIE BIT(0) 37 + #define RV3029_IRQ_CTRL_TIE BIT(1) 38 + #define RV3029_IRQ_CTRL_V1IE BIT(2) 39 + #define RV3029_IRQ_CTRL_V2IE BIT(3) 40 + #define RV3029_IRQ_CTRL_SRIE BIT(4) 41 + #define RV3029_IRQ_FLAGS 0x02 42 + #define RV3029_IRQ_FLAGS_AF BIT(0) 43 + #define RV3029_IRQ_FLAGS_TF BIT(1) 44 + #define RV3029_IRQ_FLAGS_V1IF BIT(2) 45 + #define RV3029_IRQ_FLAGS_V2IF BIT(3) 46 + #define RV3029_IRQ_FLAGS_SRF BIT(4) 47 + #define RV3029_STATUS 0x03 48 + #define RV3029_STATUS_VLOW1 BIT(2) 49 + #define RV3029_STATUS_VLOW2 BIT(3) 50 + #define RV3029_STATUS_SR BIT(4) 51 + #define RV3029_STATUS_PON BIT(5) 52 + #define RV3029_STATUS_EEBUSY BIT(7) 53 + #define RV3029_RST_CTRL 0x04 54 + #define RV3029_RST_CTRL_SYSR BIT(4) 55 + #define RV3029_CONTROL_SECTION_LEN 0x05 38 56 39 57 /* watch section */ 40 - #define RV3029C2_W_SEC 0x08 41 - #define RV3029C2_W_MINUTES 0x09 42 - #define RV3029C2_W_HOURS 0x0A 43 - #define RV3029C2_REG_HR_12_24 (1<<6) /* 24h/12h mode */ 44 - #define RV3029C2_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */ 45 - #define RV3029C2_W_DATE 0x0B 46 - #define RV3029C2_W_DAYS 0x0C 47 - #define RV3029C2_W_MONTHS 0x0D 48 - #define RV3029C2_W_YEARS 0x0E 49 - #define RV3029C2_WATCH_SECTION_LEN 0x07 58 + #define RV3029_W_SEC 0x08 59 + #define RV3029_W_MINUTES 0x09 60 + #define RV3029_W_HOURS 0x0A 61 + #define RV3029_REG_HR_12_24 BIT(6) /* 24h/12h mode */ 62 + #define RV3029_REG_HR_PM BIT(5) /* PM/AM bit in 12h mode */ 63 + #define RV3029_W_DATE 0x0B 64 + #define RV3029_W_DAYS 0x0C 65 + #define RV3029_W_MONTHS 0x0D 66 + #define RV3029_W_YEARS 0x0E 67 + #define RV3029_WATCH_SECTION_LEN 0x07 50 68 51 69 /* alarm section */ 52 - #define RV3029C2_A_SC 0x10 53 - #define RV3029C2_A_MN 0x11 54 - #define RV3029C2_A_HR 0x12 55 - #define RV3029C2_A_DT 0x13 56 - #define RV3029C2_A_DW 0x14 57 - #define RV3029C2_A_MO 0x15 58 - #define RV3029C2_A_YR 0x16 59 - #define RV3029C2_ALARM_SECTION_LEN 0x07 70 + #define RV3029_A_SC 0x10 71 + #define RV3029_A_MN 0x11 72 + #define RV3029_A_HR 0x12 73 + #define RV3029_A_DT 0x13 74 + #define RV3029_A_DW 0x14 75 + #define RV3029_A_MO 0x15 76 + #define RV3029_A_YR 0x16 77 + #define RV3029_ALARM_SECTION_LEN 0x07 60 78 61 79 /* timer section */ 62 - #define RV3029C2_TIMER_LOW 0x18 63 - #define RV3029C2_TIMER_HIGH 0x19 80 + #define RV3029_TIMER_LOW 0x18 81 + #define RV3029_TIMER_HIGH 0x19 64 82 65 83 /* temperature section */ 66 - #define RV3029C2_TEMP_PAGE 0x20 84 + #define RV3029_TEMP_PAGE 0x20 67 85 68 86 /* eeprom data section */ 69 - #define RV3029C2_E2P_EEDATA1 0x28 70 - #define RV3029C2_E2P_EEDATA2 0x29 87 + #define RV3029_E2P_EEDATA1 0x28 88 + #define RV3029_E2P_EEDATA2 0x29 89 + #define RV3029_E2PDATA_SECTION_LEN 0x02 71 90 72 91 /* eeprom control section */ 73 - #define RV3029C2_CONTROL_E2P_EECTRL 0x30 74 - #define RV3029C2_TRICKLE_1K (1<<0) /* 1K resistance */ 75 - #define RV3029C2_TRICKLE_5K (1<<1) /* 5K resistance */ 76 - #define RV3029C2_TRICKLE_20K (1<<2) /* 20K resistance */ 77 - #define RV3029C2_TRICKLE_80K (1<<3) /* 80K resistance */ 78 - #define RV3029C2_CONTROL_E2P_XTALOFFSET 0x31 79 - #define RV3029C2_CONTROL_E2P_QCOEF 0x32 80 - #define RV3029C2_CONTROL_E2P_TURNOVER 0x33 92 + #define RV3029_CONTROL_E2P_EECTRL 0x30 93 + #define RV3029_EECTRL_THP BIT(0) /* temp scan interval */ 94 + #define RV3029_EECTRL_THE BIT(1) /* thermometer enable */ 95 + #define RV3029_EECTRL_FD0 BIT(2) /* CLKOUT */ 96 + #define RV3029_EECTRL_FD1 BIT(3) /* CLKOUT */ 97 + #define RV3029_TRICKLE_1K BIT(4) /* 1.5K resistance */ 98 + #define RV3029_TRICKLE_5K BIT(5) /* 5K resistance */ 99 + #define RV3029_TRICKLE_20K BIT(6) /* 20K resistance */ 100 + #define RV3029_TRICKLE_80K BIT(7) /* 80K resistance */ 101 + #define RV3029_TRICKLE_MASK (RV3029_TRICKLE_1K |\ 102 + RV3029_TRICKLE_5K |\ 103 + RV3029_TRICKLE_20K |\ 104 + RV3029_TRICKLE_80K) 105 + #define RV3029_TRICKLE_SHIFT 4 106 + #define RV3029_CONTROL_E2P_XOFFS 0x31 /* XTAL offset */ 107 + #define RV3029_CONTROL_E2P_XOFFS_SIGN BIT(7) /* Sign: 1->pos, 0->neg */ 108 + #define RV3029_CONTROL_E2P_QCOEF 0x32 /* XTAL temp drift coef */ 109 + #define RV3029_CONTROL_E2P_TURNOVER 0x33 /* XTAL turnover temp (in *C) */ 110 + #define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */ 81 111 82 112 /* user ram section */ 83 - #define RV3029C2_USR1_RAM_PAGE 0x38 84 - #define RV3029C2_USR1_SECTION_LEN 0x04 85 - #define RV3029C2_USR2_RAM_PAGE 0x3C 86 - #define RV3029C2_USR2_SECTION_LEN 0x04 113 + #define RV3029_USR1_RAM_PAGE 0x38 114 + #define RV3029_USR1_SECTION_LEN 0x04 115 + #define RV3029_USR2_RAM_PAGE 0x3C 116 + #define RV3029_USR2_SECTION_LEN 0x04 87 117 88 118 static int 89 - rv3029c2_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, 90 - unsigned len) 119 + rv3029_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, 120 + unsigned len) 91 121 { 92 122 int ret; 93 123 94 - if ((reg > RV3029C2_USR1_RAM_PAGE + 7) || 95 - (reg + len > RV3029C2_USR1_RAM_PAGE + 8)) 124 + if ((reg > RV3029_USR1_RAM_PAGE + 7) || 125 + (reg + len > RV3029_USR1_RAM_PAGE + 8)) 96 126 return -EINVAL; 97 127 98 128 ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf); ··· 135 103 } 136 104 137 105 static int 138 - rv3029c2_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], 139 - unsigned len) 106 + rv3029_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], 107 + unsigned len) 140 108 { 141 - if ((reg > RV3029C2_USR1_RAM_PAGE + 7) || 142 - (reg + len > RV3029C2_USR1_RAM_PAGE + 8)) 109 + if ((reg > RV3029_USR1_RAM_PAGE + 7) || 110 + (reg + len > RV3029_USR1_RAM_PAGE + 8)) 143 111 return -EINVAL; 144 112 145 113 return i2c_smbus_write_i2c_block_data(client, reg, len, buf); 146 114 } 147 115 148 116 static int 149 - rv3029c2_i2c_get_sr(struct i2c_client *client, u8 *buf) 117 + rv3029_i2c_update_bits(struct i2c_client *client, u8 reg, u8 mask, u8 set) 150 118 { 151 - int ret = rv3029c2_i2c_read_regs(client, RV3029C2_STATUS, buf, 1); 119 + u8 buf; 120 + int ret; 121 + 122 + ret = rv3029_i2c_read_regs(client, reg, &buf, 1); 123 + if (ret < 0) 124 + return ret; 125 + buf &= ~mask; 126 + buf |= set & mask; 127 + ret = rv3029_i2c_write_regs(client, reg, &buf, 1); 128 + if (ret < 0) 129 + return ret; 130 + 131 + return 0; 132 + } 133 + 134 + static int 135 + rv3029_i2c_get_sr(struct i2c_client *client, u8 *buf) 136 + { 137 + int ret = rv3029_i2c_read_regs(client, RV3029_STATUS, buf, 1); 152 138 153 139 if (ret < 0) 154 140 return -EIO; ··· 175 125 } 176 126 177 127 static int 178 - rv3029c2_i2c_set_sr(struct i2c_client *client, u8 val) 128 + rv3029_i2c_set_sr(struct i2c_client *client, u8 val) 179 129 { 180 130 u8 buf[1]; 181 131 int sr; 182 132 183 133 buf[0] = val; 184 - sr = rv3029c2_i2c_write_regs(client, RV3029C2_STATUS, buf, 1); 134 + sr = rv3029_i2c_write_regs(client, RV3029_STATUS, buf, 1); 185 135 dev_dbg(&client->dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 186 136 if (sr < 0) 187 137 return -EIO; 188 138 return 0; 189 139 } 190 140 141 + static int rv3029_eeprom_busywait(struct i2c_client *client) 142 + { 143 + int i, ret; 144 + u8 sr; 145 + 146 + for (i = 100; i > 0; i--) { 147 + ret = rv3029_i2c_get_sr(client, &sr); 148 + if (ret < 0) 149 + break; 150 + if (!(sr & RV3029_STATUS_EEBUSY)) 151 + break; 152 + usleep_range(1000, 10000); 153 + } 154 + if (i <= 0) { 155 + dev_err(&client->dev, "EEPROM busy wait timeout.\n"); 156 + return -ETIMEDOUT; 157 + } 158 + 159 + return ret; 160 + } 161 + 162 + static int rv3029_eeprom_exit(struct i2c_client *client) 163 + { 164 + /* Re-enable eeprom refresh */ 165 + return rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 166 + RV3029_ONOFF_CTRL_EERE, 167 + RV3029_ONOFF_CTRL_EERE); 168 + } 169 + 170 + static int rv3029_eeprom_enter(struct i2c_client *client) 171 + { 172 + int ret; 173 + u8 sr; 174 + 175 + /* Check whether we are in the allowed voltage range. */ 176 + ret = rv3029_i2c_get_sr(client, &sr); 177 + if (ret < 0) 178 + return ret; 179 + if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 180 + /* We clear the bits and retry once just in case 181 + * we had a brown out in early startup. 182 + */ 183 + sr &= ~RV3029_STATUS_VLOW1; 184 + sr &= ~RV3029_STATUS_VLOW2; 185 + ret = rv3029_i2c_set_sr(client, sr); 186 + if (ret < 0) 187 + return ret; 188 + usleep_range(1000, 10000); 189 + ret = rv3029_i2c_get_sr(client, &sr); 190 + if (ret < 0) 191 + return ret; 192 + if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 193 + dev_err(&client->dev, 194 + "Supply voltage is too low to safely access the EEPROM.\n"); 195 + return -ENODEV; 196 + } 197 + } 198 + 199 + /* Disable eeprom refresh. */ 200 + ret = rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 201 + RV3029_ONOFF_CTRL_EERE, 0); 202 + if (ret < 0) 203 + return ret; 204 + 205 + /* Wait for any previous eeprom accesses to finish. */ 206 + ret = rv3029_eeprom_busywait(client); 207 + if (ret < 0) 208 + rv3029_eeprom_exit(client); 209 + 210 + return ret; 211 + } 212 + 213 + static int rv3029_eeprom_read(struct i2c_client *client, u8 reg, 214 + u8 buf[], size_t len) 215 + { 216 + int ret, err; 217 + 218 + err = rv3029_eeprom_enter(client); 219 + if (err < 0) 220 + return err; 221 + 222 + ret = rv3029_i2c_read_regs(client, reg, buf, len); 223 + 224 + err = rv3029_eeprom_exit(client); 225 + if (err < 0) 226 + return err; 227 + 228 + return ret; 229 + } 230 + 231 + static int rv3029_eeprom_write(struct i2c_client *client, u8 reg, 232 + u8 const buf[], size_t len) 233 + { 234 + int ret, err; 235 + size_t i; 236 + u8 tmp; 237 + 238 + err = rv3029_eeprom_enter(client); 239 + if (err < 0) 240 + return err; 241 + 242 + for (i = 0; i < len; i++, reg++) { 243 + ret = rv3029_i2c_read_regs(client, reg, &tmp, 1); 244 + if (ret < 0) 245 + break; 246 + if (tmp != buf[i]) { 247 + ret = rv3029_i2c_write_regs(client, reg, &buf[i], 1); 248 + if (ret < 0) 249 + break; 250 + } 251 + ret = rv3029_eeprom_busywait(client); 252 + if (ret < 0) 253 + break; 254 + } 255 + 256 + err = rv3029_eeprom_exit(client); 257 + if (err < 0) 258 + return err; 259 + 260 + return ret; 261 + } 262 + 263 + static int rv3029_eeprom_update_bits(struct i2c_client *client, 264 + u8 reg, u8 mask, u8 set) 265 + { 266 + u8 buf; 267 + int ret; 268 + 269 + ret = rv3029_eeprom_read(client, reg, &buf, 1); 270 + if (ret < 0) 271 + return ret; 272 + buf &= ~mask; 273 + buf |= set & mask; 274 + ret = rv3029_eeprom_write(client, reg, &buf, 1); 275 + if (ret < 0) 276 + return ret; 277 + 278 + return 0; 279 + } 280 + 191 281 static int 192 - rv3029c2_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 282 + rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 193 283 { 194 284 u8 buf[1]; 195 285 int ret; 196 - u8 regs[RV3029C2_WATCH_SECTION_LEN] = { 0, }; 286 + u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; 197 287 198 - ret = rv3029c2_i2c_get_sr(client, buf); 288 + ret = rv3029_i2c_get_sr(client, buf); 199 289 if (ret < 0) { 200 290 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 201 291 return -EIO; 202 292 } 203 293 204 - ret = rv3029c2_i2c_read_regs(client, RV3029C2_W_SEC , regs, 205 - RV3029C2_WATCH_SECTION_LEN); 294 + ret = rv3029_i2c_read_regs(client, RV3029_W_SEC, regs, 295 + RV3029_WATCH_SECTION_LEN); 206 296 if (ret < 0) { 207 297 dev_err(&client->dev, "%s: reading RTC section failed\n", 208 298 __func__); 209 299 return ret; 210 300 } 211 301 212 - tm->tm_sec = bcd2bin(regs[RV3029C2_W_SEC-RV3029C2_W_SEC]); 213 - tm->tm_min = bcd2bin(regs[RV3029C2_W_MINUTES-RV3029C2_W_SEC]); 302 + tm->tm_sec = bcd2bin(regs[RV3029_W_SEC-RV3029_W_SEC]); 303 + tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES-RV3029_W_SEC]); 214 304 215 305 /* HR field has a more complex interpretation */ 216 306 { 217 - const u8 _hr = regs[RV3029C2_W_HOURS-RV3029C2_W_SEC]; 218 - if (_hr & RV3029C2_REG_HR_12_24) { 307 + const u8 _hr = regs[RV3029_W_HOURS-RV3029_W_SEC]; 308 + 309 + if (_hr & RV3029_REG_HR_12_24) { 219 310 /* 12h format */ 220 311 tm->tm_hour = bcd2bin(_hr & 0x1f); 221 - if (_hr & RV3029C2_REG_HR_PM) /* PM flag set */ 312 + if (_hr & RV3029_REG_HR_PM) /* PM flag set */ 222 313 tm->tm_hour += 12; 223 314 } else /* 24h format */ 224 315 tm->tm_hour = bcd2bin(_hr & 0x3f); 225 316 } 226 317 227 - tm->tm_mday = bcd2bin(regs[RV3029C2_W_DATE-RV3029C2_W_SEC]); 228 - tm->tm_mon = bcd2bin(regs[RV3029C2_W_MONTHS-RV3029C2_W_SEC]) - 1; 229 - tm->tm_year = bcd2bin(regs[RV3029C2_W_YEARS-RV3029C2_W_SEC]) + 100; 230 - tm->tm_wday = bcd2bin(regs[RV3029C2_W_DAYS-RV3029C2_W_SEC]) - 1; 318 + tm->tm_mday = bcd2bin(regs[RV3029_W_DATE-RV3029_W_SEC]); 319 + tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS-RV3029_W_SEC]) - 1; 320 + tm->tm_year = bcd2bin(regs[RV3029_W_YEARS-RV3029_W_SEC]) + 100; 321 + tm->tm_wday = bcd2bin(regs[RV3029_W_DAYS-RV3029_W_SEC]) - 1; 231 322 232 323 return 0; 233 324 } 234 325 235 - static int rv3029c2_rtc_read_time(struct device *dev, struct rtc_time *tm) 326 + static int rv3029_rtc_read_time(struct device *dev, struct rtc_time *tm) 236 327 { 237 - return rv3029c2_i2c_read_time(to_i2c_client(dev), tm); 328 + return rv3029_i2c_read_time(to_i2c_client(dev), tm); 238 329 } 239 330 240 331 static int 241 - rv3029c2_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm) 332 + rv3029_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm) 242 333 { 243 334 struct rtc_time *const tm = &alarm->time; 244 335 int ret; 245 336 u8 regs[8]; 246 337 247 - ret = rv3029c2_i2c_get_sr(client, regs); 338 + ret = rv3029_i2c_get_sr(client, regs); 248 339 if (ret < 0) { 249 340 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 250 341 return -EIO; 251 342 } 252 343 253 - ret = rv3029c2_i2c_read_regs(client, RV3029C2_A_SC, regs, 254 - RV3029C2_ALARM_SECTION_LEN); 344 + ret = rv3029_i2c_read_regs(client, RV3029_A_SC, regs, 345 + RV3029_ALARM_SECTION_LEN); 255 346 256 347 if (ret < 0) { 257 348 dev_err(&client->dev, "%s: reading alarm section failed\n", ··· 400 209 return ret; 401 210 } 402 211 403 - tm->tm_sec = bcd2bin(regs[RV3029C2_A_SC-RV3029C2_A_SC] & 0x7f); 404 - tm->tm_min = bcd2bin(regs[RV3029C2_A_MN-RV3029C2_A_SC] & 0x7f); 405 - tm->tm_hour = bcd2bin(regs[RV3029C2_A_HR-RV3029C2_A_SC] & 0x3f); 406 - tm->tm_mday = bcd2bin(regs[RV3029C2_A_DT-RV3029C2_A_SC] & 0x3f); 407 - tm->tm_mon = bcd2bin(regs[RV3029C2_A_MO-RV3029C2_A_SC] & 0x1f) - 1; 408 - tm->tm_year = bcd2bin(regs[RV3029C2_A_YR-RV3029C2_A_SC] & 0x7f) + 100; 409 - tm->tm_wday = bcd2bin(regs[RV3029C2_A_DW-RV3029C2_A_SC] & 0x07) - 1; 212 + tm->tm_sec = bcd2bin(regs[RV3029_A_SC-RV3029_A_SC] & 0x7f); 213 + tm->tm_min = bcd2bin(regs[RV3029_A_MN-RV3029_A_SC] & 0x7f); 214 + tm->tm_hour = bcd2bin(regs[RV3029_A_HR-RV3029_A_SC] & 0x3f); 215 + tm->tm_mday = bcd2bin(regs[RV3029_A_DT-RV3029_A_SC] & 0x3f); 216 + tm->tm_mon = bcd2bin(regs[RV3029_A_MO-RV3029_A_SC] & 0x1f) - 1; 217 + tm->tm_year = bcd2bin(regs[RV3029_A_YR-RV3029_A_SC] & 0x7f) + 100; 218 + tm->tm_wday = bcd2bin(regs[RV3029_A_DW-RV3029_A_SC] & 0x07) - 1; 410 219 411 220 return 0; 412 221 } 413 222 414 223 static int 415 - rv3029c2_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 224 + rv3029_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 416 225 { 417 - return rv3029c2_i2c_read_alarm(to_i2c_client(dev), alarm); 226 + return rv3029_i2c_read_alarm(to_i2c_client(dev), alarm); 418 227 } 419 228 420 - static int rv3029c2_rtc_i2c_alarm_set_irq(struct i2c_client *client, 229 + static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client *client, 421 230 int enable) 422 231 { 423 232 int ret; 424 - u8 buf[1]; 425 233 426 - /* enable AIE irq */ 427 - ret = rv3029c2_i2c_read_regs(client, RV3029C2_IRQ_CTRL, buf, 1); 234 + /* enable/disable AIE irq */ 235 + ret = rv3029_i2c_update_bits(client, RV3029_IRQ_CTRL, 236 + RV3029_IRQ_CTRL_AIE, 237 + (enable ? RV3029_IRQ_CTRL_AIE : 0)); 428 238 if (ret < 0) { 429 - dev_err(&client->dev, "can't read INT reg\n"); 430 - return ret; 431 - } 432 - if (enable) 433 - buf[0] |= RV3029C2_IRQ_CTRL_AIE; 434 - else 435 - buf[0] &= ~RV3029C2_IRQ_CTRL_AIE; 436 - 437 - ret = rv3029c2_i2c_write_regs(client, RV3029C2_IRQ_CTRL, buf, 1); 438 - if (ret < 0) { 439 - dev_err(&client->dev, "can't set INT reg\n"); 239 + dev_err(&client->dev, "can't update INT reg\n"); 440 240 return ret; 441 241 } 442 242 443 243 return 0; 444 244 } 445 245 446 - static int rv3029c2_rtc_i2c_set_alarm(struct i2c_client *client, 447 - struct rtc_wkalrm *alarm) 246 + static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client, 247 + struct rtc_wkalrm *alarm) 448 248 { 449 249 struct rtc_time *const tm = &alarm->time; 450 250 int ret; ··· 449 267 if (tm->tm_year < 100) 450 268 return -EINVAL; 451 269 452 - ret = rv3029c2_i2c_get_sr(client, regs); 270 + ret = rv3029_i2c_get_sr(client, regs); 453 271 if (ret < 0) { 454 272 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 455 273 return -EIO; 456 274 } 457 - regs[RV3029C2_A_SC-RV3029C2_A_SC] = bin2bcd(tm->tm_sec & 0x7f); 458 - regs[RV3029C2_A_MN-RV3029C2_A_SC] = bin2bcd(tm->tm_min & 0x7f); 459 - regs[RV3029C2_A_HR-RV3029C2_A_SC] = bin2bcd(tm->tm_hour & 0x3f); 460 - regs[RV3029C2_A_DT-RV3029C2_A_SC] = bin2bcd(tm->tm_mday & 0x3f); 461 - regs[RV3029C2_A_MO-RV3029C2_A_SC] = bin2bcd((tm->tm_mon & 0x1f) - 1); 462 - regs[RV3029C2_A_DW-RV3029C2_A_SC] = bin2bcd((tm->tm_wday & 7) - 1); 463 - regs[RV3029C2_A_YR-RV3029C2_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100); 275 + regs[RV3029_A_SC-RV3029_A_SC] = bin2bcd(tm->tm_sec & 0x7f); 276 + regs[RV3029_A_MN-RV3029_A_SC] = bin2bcd(tm->tm_min & 0x7f); 277 + regs[RV3029_A_HR-RV3029_A_SC] = bin2bcd(tm->tm_hour & 0x3f); 278 + regs[RV3029_A_DT-RV3029_A_SC] = bin2bcd(tm->tm_mday & 0x3f); 279 + regs[RV3029_A_MO-RV3029_A_SC] = bin2bcd((tm->tm_mon & 0x1f) - 1); 280 + regs[RV3029_A_DW-RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1); 281 + regs[RV3029_A_YR-RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100); 464 282 465 - ret = rv3029c2_i2c_write_regs(client, RV3029C2_A_SC, regs, 466 - RV3029C2_ALARM_SECTION_LEN); 283 + ret = rv3029_i2c_write_regs(client, RV3029_A_SC, regs, 284 + RV3029_ALARM_SECTION_LEN); 467 285 if (ret < 0) 468 286 return ret; 469 287 470 288 if (alarm->enabled) { 471 - u8 buf[1]; 472 - 473 289 /* clear AF flag */ 474 - ret = rv3029c2_i2c_read_regs(client, RV3029C2_IRQ_FLAGS, 475 - buf, 1); 290 + ret = rv3029_i2c_update_bits(client, RV3029_IRQ_FLAGS, 291 + RV3029_IRQ_FLAGS_AF, 0); 476 292 if (ret < 0) { 477 - dev_err(&client->dev, "can't read alarm flag\n"); 478 - return ret; 479 - } 480 - buf[0] &= ~RV3029C2_IRQ_FLAGS_AF; 481 - ret = rv3029c2_i2c_write_regs(client, RV3029C2_IRQ_FLAGS, 482 - buf, 1); 483 - if (ret < 0) { 484 - dev_err(&client->dev, "can't set alarm flag\n"); 293 + dev_err(&client->dev, "can't clear alarm flag\n"); 485 294 return ret; 486 295 } 487 296 /* enable AIE irq */ 488 - ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 1); 297 + ret = rv3029_rtc_i2c_alarm_set_irq(client, 1); 489 298 if (ret) 490 299 return ret; 491 300 492 301 dev_dbg(&client->dev, "alarm IRQ armed\n"); 493 302 } else { 494 303 /* disable AIE irq */ 495 - ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 0); 304 + ret = rv3029_rtc_i2c_alarm_set_irq(client, 0); 496 305 if (ret) 497 306 return ret; 498 307 ··· 493 320 return 0; 494 321 } 495 322 496 - static int rv3029c2_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 323 + static int rv3029_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 497 324 { 498 - return rv3029c2_rtc_i2c_set_alarm(to_i2c_client(dev), alarm); 325 + return rv3029_rtc_i2c_set_alarm(to_i2c_client(dev), alarm); 499 326 } 500 327 501 328 static int 502 - rv3029c2_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) 329 + rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) 503 330 { 504 331 u8 regs[8]; 505 332 int ret; ··· 512 339 if (tm->tm_year < 100) 513 340 return -EINVAL; 514 341 515 - regs[RV3029C2_W_SEC-RV3029C2_W_SEC] = bin2bcd(tm->tm_sec); 516 - regs[RV3029C2_W_MINUTES-RV3029C2_W_SEC] = bin2bcd(tm->tm_min); 517 - regs[RV3029C2_W_HOURS-RV3029C2_W_SEC] = bin2bcd(tm->tm_hour); 518 - regs[RV3029C2_W_DATE-RV3029C2_W_SEC] = bin2bcd(tm->tm_mday); 519 - regs[RV3029C2_W_MONTHS-RV3029C2_W_SEC] = bin2bcd(tm->tm_mon+1); 520 - regs[RV3029C2_W_DAYS-RV3029C2_W_SEC] = bin2bcd((tm->tm_wday & 7)+1); 521 - regs[RV3029C2_W_YEARS-RV3029C2_W_SEC] = bin2bcd(tm->tm_year - 100); 342 + regs[RV3029_W_SEC-RV3029_W_SEC] = bin2bcd(tm->tm_sec); 343 + regs[RV3029_W_MINUTES-RV3029_W_SEC] = bin2bcd(tm->tm_min); 344 + regs[RV3029_W_HOURS-RV3029_W_SEC] = bin2bcd(tm->tm_hour); 345 + regs[RV3029_W_DATE-RV3029_W_SEC] = bin2bcd(tm->tm_mday); 346 + regs[RV3029_W_MONTHS-RV3029_W_SEC] = bin2bcd(tm->tm_mon+1); 347 + regs[RV3029_W_DAYS-RV3029_W_SEC] = bin2bcd((tm->tm_wday & 7)+1); 348 + regs[RV3029_W_YEARS-RV3029_W_SEC] = bin2bcd(tm->tm_year - 100); 522 349 523 - ret = rv3029c2_i2c_write_regs(client, RV3029C2_W_SEC, regs, 524 - RV3029C2_WATCH_SECTION_LEN); 350 + ret = rv3029_i2c_write_regs(client, RV3029_W_SEC, regs, 351 + RV3029_WATCH_SECTION_LEN); 525 352 if (ret < 0) 526 353 return ret; 527 354 528 - ret = rv3029c2_i2c_get_sr(client, regs); 355 + ret = rv3029_i2c_get_sr(client, regs); 529 356 if (ret < 0) { 530 357 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 531 358 return ret; 532 359 } 533 360 /* clear PON bit */ 534 - ret = rv3029c2_i2c_set_sr(client, (regs[0] & ~RV3029C2_STATUS_PON)); 361 + ret = rv3029_i2c_set_sr(client, (regs[0] & ~RV3029_STATUS_PON)); 535 362 if (ret < 0) { 536 363 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 537 364 return ret; ··· 540 367 return 0; 541 368 } 542 369 543 - static int rv3029c2_rtc_set_time(struct device *dev, struct rtc_time *tm) 370 + static int rv3029_rtc_set_time(struct device *dev, struct rtc_time *tm) 544 371 { 545 - return rv3029c2_i2c_set_time(to_i2c_client(dev), tm); 372 + return rv3029_i2c_set_time(to_i2c_client(dev), tm); 546 373 } 547 374 548 - static const struct rtc_class_ops rv3029c2_rtc_ops = { 549 - .read_time = rv3029c2_rtc_read_time, 550 - .set_time = rv3029c2_rtc_set_time, 551 - .read_alarm = rv3029c2_rtc_read_alarm, 552 - .set_alarm = rv3029c2_rtc_set_alarm, 375 + static const struct rv3029_trickle_tab_elem { 376 + u32 r; /* resistance in ohms */ 377 + u8 conf; /* trickle config bits */ 378 + } rv3029_trickle_tab[] = { 379 + { 380 + .r = 1076, 381 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | 382 + RV3029_TRICKLE_20K | RV3029_TRICKLE_80K, 383 + }, { 384 + .r = 1091, 385 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | 386 + RV3029_TRICKLE_20K, 387 + }, { 388 + .r = 1137, 389 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K | 390 + RV3029_TRICKLE_80K, 391 + }, { 392 + .r = 1154, 393 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_5K, 394 + }, { 395 + .r = 1371, 396 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_20K | 397 + RV3029_TRICKLE_80K, 398 + }, { 399 + .r = 1395, 400 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_20K, 401 + }, { 402 + .r = 1472, 403 + .conf = RV3029_TRICKLE_1K | RV3029_TRICKLE_80K, 404 + }, { 405 + .r = 1500, 406 + .conf = RV3029_TRICKLE_1K, 407 + }, { 408 + .r = 3810, 409 + .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_20K | 410 + RV3029_TRICKLE_80K, 411 + }, { 412 + .r = 4000, 413 + .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_20K, 414 + }, { 415 + .r = 4706, 416 + .conf = RV3029_TRICKLE_5K | RV3029_TRICKLE_80K, 417 + }, { 418 + .r = 5000, 419 + .conf = RV3029_TRICKLE_5K, 420 + }, { 421 + .r = 16000, 422 + .conf = RV3029_TRICKLE_20K | RV3029_TRICKLE_80K, 423 + }, { 424 + .r = 20000, 425 + .conf = RV3029_TRICKLE_20K, 426 + }, { 427 + .r = 80000, 428 + .conf = RV3029_TRICKLE_80K, 429 + }, 553 430 }; 554 431 555 - static struct i2c_device_id rv3029c2_id[] = { 432 + static void rv3029_trickle_config(struct i2c_client *client) 433 + { 434 + struct device_node *of_node = client->dev.of_node; 435 + const struct rv3029_trickle_tab_elem *elem; 436 + int i, err; 437 + u32 ohms; 438 + u8 trickle_set_bits; 439 + 440 + if (!of_node) 441 + return; 442 + 443 + /* Configure the trickle charger. */ 444 + err = of_property_read_u32(of_node, "trickle-resistor-ohms", &ohms); 445 + if (err) { 446 + /* Disable trickle charger. */ 447 + trickle_set_bits = 0; 448 + } else { 449 + /* Enable trickle charger. */ 450 + for (i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++) { 451 + elem = &rv3029_trickle_tab[i]; 452 + if (elem->r >= ohms) 453 + break; 454 + } 455 + trickle_set_bits = elem->conf; 456 + dev_info(&client->dev, 457 + "Trickle charger enabled at %d ohms resistance.\n", 458 + elem->r); 459 + } 460 + err = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL, 461 + RV3029_TRICKLE_MASK, 462 + trickle_set_bits); 463 + if (err < 0) { 464 + dev_err(&client->dev, 465 + "Failed to update trickle charger config\n"); 466 + } 467 + } 468 + 469 + #ifdef CONFIG_RTC_DRV_RV3029_HWMON 470 + 471 + static int rv3029_read_temp(struct i2c_client *client, int *temp_mC) 472 + { 473 + int ret; 474 + u8 temp; 475 + 476 + ret = rv3029_i2c_read_regs(client, RV3029_TEMP_PAGE, &temp, 1); 477 + if (ret < 0) 478 + return ret; 479 + 480 + *temp_mC = ((int)temp - 60) * 1000; 481 + 482 + return 0; 483 + } 484 + 485 + static ssize_t rv3029_hwmon_show_temp(struct device *dev, 486 + struct device_attribute *attr, 487 + char *buf) 488 + { 489 + struct i2c_client *client = dev_get_drvdata(dev); 490 + int ret, temp_mC; 491 + 492 + ret = rv3029_read_temp(client, &temp_mC); 493 + if (ret < 0) 494 + return ret; 495 + 496 + return sprintf(buf, "%d\n", temp_mC); 497 + } 498 + 499 + static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, 500 + struct device_attribute *attr, 501 + const char *buf, 502 + size_t count) 503 + { 504 + struct i2c_client *client = dev_get_drvdata(dev); 505 + unsigned long interval_ms; 506 + int ret; 507 + u8 th_set_bits = 0; 508 + 509 + ret = kstrtoul(buf, 10, &interval_ms); 510 + if (ret < 0) 511 + return ret; 512 + 513 + if (interval_ms != 0) { 514 + th_set_bits |= RV3029_EECTRL_THE; 515 + if (interval_ms >= 16000) 516 + th_set_bits |= RV3029_EECTRL_THP; 517 + } 518 + ret = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL, 519 + RV3029_EECTRL_THE | RV3029_EECTRL_THP, 520 + th_set_bits); 521 + if (ret < 0) 522 + return ret; 523 + 524 + return count; 525 + } 526 + 527 + static ssize_t rv3029_hwmon_show_update_interval(struct device *dev, 528 + struct device_attribute *attr, 529 + char *buf) 530 + { 531 + struct i2c_client *client = dev_get_drvdata(dev); 532 + int ret, interval_ms; 533 + u8 eectrl; 534 + 535 + ret = rv3029_eeprom_read(client, RV3029_CONTROL_E2P_EECTRL, 536 + &eectrl, 1); 537 + if (ret < 0) 538 + return ret; 539 + 540 + if (eectrl & RV3029_EECTRL_THE) { 541 + if (eectrl & RV3029_EECTRL_THP) 542 + interval_ms = 16000; 543 + else 544 + interval_ms = 1000; 545 + } else { 546 + interval_ms = 0; 547 + } 548 + 549 + return sprintf(buf, "%d\n", interval_ms); 550 + } 551 + 552 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, rv3029_hwmon_show_temp, 553 + NULL, 0); 554 + static SENSOR_DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, 555 + rv3029_hwmon_show_update_interval, 556 + rv3029_hwmon_set_update_interval, 0); 557 + 558 + static struct attribute *rv3029_hwmon_attrs[] = { 559 + &sensor_dev_attr_temp1_input.dev_attr.attr, 560 + &sensor_dev_attr_update_interval.dev_attr.attr, 561 + NULL, 562 + }; 563 + ATTRIBUTE_GROUPS(rv3029_hwmon); 564 + 565 + static void rv3029_hwmon_register(struct i2c_client *client) 566 + { 567 + struct device *hwmon_dev; 568 + 569 + hwmon_dev = devm_hwmon_device_register_with_groups( 570 + &client->dev, client->name, client, rv3029_hwmon_groups); 571 + if (IS_ERR(hwmon_dev)) { 572 + dev_warn(&client->dev, 573 + "unable to register hwmon device %ld\n", 574 + PTR_ERR(hwmon_dev)); 575 + } 576 + } 577 + 578 + #else /* CONFIG_RTC_DRV_RV3029_HWMON */ 579 + 580 + static void rv3029_hwmon_register(struct i2c_client *client) 581 + { 582 + } 583 + 584 + #endif /* CONFIG_RTC_DRV_RV3029_HWMON */ 585 + 586 + static const struct rtc_class_ops rv3029_rtc_ops = { 587 + .read_time = rv3029_rtc_read_time, 588 + .set_time = rv3029_rtc_set_time, 589 + .read_alarm = rv3029_rtc_read_alarm, 590 + .set_alarm = rv3029_rtc_set_alarm, 591 + }; 592 + 593 + static struct i2c_device_id rv3029_id[] = { 594 + { "rv3029", 0 }, 556 595 { "rv3029c2", 0 }, 557 596 { } 558 597 }; 559 - MODULE_DEVICE_TABLE(i2c, rv3029c2_id); 598 + MODULE_DEVICE_TABLE(i2c, rv3029_id); 560 599 561 - static int rv3029c2_probe(struct i2c_client *client, 562 - const struct i2c_device_id *id) 600 + static int rv3029_probe(struct i2c_client *client, 601 + const struct i2c_device_id *id) 563 602 { 564 603 struct rtc_device *rtc; 565 604 int rc = 0; ··· 780 395 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL)) 781 396 return -ENODEV; 782 397 783 - rc = rv3029c2_i2c_get_sr(client, buf); 398 + rc = rv3029_i2c_get_sr(client, buf); 784 399 if (rc < 0) { 785 400 dev_err(&client->dev, "reading status failed\n"); 786 401 return rc; 787 402 } 788 403 404 + rv3029_trickle_config(client); 405 + rv3029_hwmon_register(client); 406 + 789 407 rtc = devm_rtc_device_register(&client->dev, client->name, 790 - &rv3029c2_rtc_ops, THIS_MODULE); 408 + &rv3029_rtc_ops, THIS_MODULE); 791 409 792 410 if (IS_ERR(rtc)) 793 411 return PTR_ERR(rtc); ··· 800 412 return 0; 801 413 } 802 414 803 - static struct i2c_driver rv3029c2_driver = { 415 + static struct i2c_driver rv3029_driver = { 804 416 .driver = { 805 417 .name = "rtc-rv3029c2", 806 418 }, 807 - .probe = rv3029c2_probe, 808 - .id_table = rv3029c2_id, 419 + .probe = rv3029_probe, 420 + .id_table = rv3029_id, 809 421 }; 810 422 811 - module_i2c_driver(rv3029c2_driver); 423 + module_i2c_driver(rv3029_driver); 812 424 813 425 MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>"); 814 - MODULE_DESCRIPTION("Micro Crystal RV3029C2 RTC driver"); 426 + MODULE_AUTHOR("Michael Buesch <m@bues.ch>"); 427 + MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver"); 815 428 MODULE_LICENSE("GPL");
+18 -21
drivers/rtc/rtc-rv8803.c
··· 52 52 struct rv8803_data { 53 53 struct i2c_client *client; 54 54 struct rtc_device *rtc; 55 - spinlock_t flags_lock; 55 + struct mutex flags_lock; 56 56 u8 ctrl; 57 57 }; 58 58 ··· 63 63 unsigned long events = 0; 64 64 int flags; 65 65 66 - spin_lock(&rv8803->flags_lock); 66 + mutex_lock(&rv8803->flags_lock); 67 67 68 68 flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 69 69 if (flags <= 0) { 70 - spin_unlock(&rv8803->flags_lock); 70 + mutex_unlock(&rv8803->flags_lock); 71 71 return IRQ_NONE; 72 72 } 73 73 ··· 102 102 rv8803->ctrl); 103 103 } 104 104 105 - spin_unlock(&rv8803->flags_lock); 105 + mutex_unlock(&rv8803->flags_lock); 106 106 107 107 return IRQ_HANDLED; 108 108 } ··· 155 155 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 156 156 u8 date[7]; 157 157 int flags, ret; 158 - unsigned long irqflags; 159 158 160 159 if ((tm->tm_year < 100) || (tm->tm_year > 199)) 161 160 return -EINVAL; ··· 172 173 if (ret < 0) 173 174 return ret; 174 175 175 - spin_lock_irqsave(&rv8803->flags_lock, irqflags); 176 + mutex_lock(&rv8803->flags_lock); 176 177 177 178 flags = i2c_smbus_read_byte_data(rv8803->client, RV8803_FLAG); 178 179 if (flags < 0) { 179 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 180 + mutex_unlock(&rv8803->flags_lock); 180 181 return flags; 181 182 } 182 183 183 184 ret = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, 184 185 flags & ~RV8803_FLAG_V2F); 185 186 186 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 187 + mutex_unlock(&rv8803->flags_lock); 187 188 188 189 return ret; 189 190 } ··· 225 226 u8 alarmvals[3]; 226 227 u8 ctrl[2]; 227 228 int ret, err; 228 - unsigned long irqflags; 229 229 230 230 /* The alarm has no seconds, round up to nearest minute */ 231 231 if (alrm->time.tm_sec) { ··· 234 236 rtc_time64_to_tm(alarm_time, &alrm->time); 235 237 } 236 238 237 - spin_lock_irqsave(&rv8803->flags_lock, irqflags); 239 + mutex_lock(&rv8803->flags_lock); 238 240 239 241 ret = i2c_smbus_read_i2c_block_data(client, RV8803_FLAG, 2, ctrl); 240 242 if (ret != 2) { 241 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 243 + mutex_unlock(&rv8803->flags_lock); 242 244 return ret < 0 ? ret : -EIO; 243 245 } 244 246 ··· 251 253 err = i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 252 254 rv8803->ctrl); 253 255 if (err) { 254 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 256 + mutex_unlock(&rv8803->flags_lock); 255 257 return err; 256 258 } 257 259 } 258 260 259 261 ctrl[1] &= ~RV8803_FLAG_AF; 260 262 err = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, ctrl[1]); 261 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 263 + mutex_unlock(&rv8803->flags_lock); 262 264 if (err) 263 265 return err; 264 266 ··· 287 289 struct i2c_client *client = to_i2c_client(dev); 288 290 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 289 291 int ctrl, flags, err; 290 - unsigned long irqflags; 291 292 292 293 ctrl = rv8803->ctrl; 293 294 ··· 302 305 ctrl &= ~RV8803_CTRL_AIE; 303 306 } 304 307 305 - spin_lock_irqsave(&rv8803->flags_lock, irqflags); 308 + mutex_lock(&rv8803->flags_lock); 306 309 flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 307 310 if (flags < 0) { 308 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 311 + mutex_unlock(&rv8803->flags_lock); 309 312 return flags; 310 313 } 311 314 flags &= ~(RV8803_FLAG_AF | RV8803_FLAG_UF); 312 315 err = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 313 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 316 + mutex_unlock(&rv8803->flags_lock); 314 317 if (err) 315 318 return err; 316 319 ··· 330 333 struct i2c_client *client = to_i2c_client(dev); 331 334 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 332 335 int flags, ret = 0; 333 - unsigned long irqflags; 334 336 335 337 switch (cmd) { 336 338 case RTC_VL_READ: ··· 351 355 return 0; 352 356 353 357 case RTC_VL_CLR: 354 - spin_lock_irqsave(&rv8803->flags_lock, irqflags); 358 + mutex_lock(&rv8803->flags_lock); 355 359 flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 356 360 if (flags < 0) { 357 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 361 + mutex_unlock(&rv8803->flags_lock); 358 362 return flags; 359 363 } 360 364 361 365 flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F); 362 366 ret = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 363 - spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 367 + mutex_unlock(&rv8803->flags_lock); 364 368 if (ret < 0) 365 369 return ret; 366 370 ··· 437 441 if (!rv8803) 438 442 return -ENOMEM; 439 443 444 + mutex_init(&rv8803->flags_lock); 440 445 rv8803->client = client; 441 446 i2c_set_clientdata(client, rv8803); 442 447
+402
drivers/rtc/rtc-rx6110.c
··· 1 + /* 2 + * Driver for the Epson RTC module RX-6110 SA 3 + * 4 + * Copyright(C) 2015 Pengutronix, Steffen Trumtrar <kernel@pengutronix.de> 5 + * Copyright(C) SEIKO EPSON CORPORATION 2013. All rights reserved. 6 + * 7 + * This driver software is distributed as is, without any warranty of any kind, 8 + * either express or implied as further specified in the GNU Public License. 9 + * This software may be used and distributed according to the terms of the GNU 10 + * Public License, version 2 as published by the Free Software Foundation. 11 + * See the file COPYING in the main directory of this archive for more details. 12 + * 13 + * You should have received a copy of the GNU General Public License along with 14 + * this program. If not, see <http://www.gnu.org/licenses/>. 15 + */ 16 + 17 + #include <linux/bcd.h> 18 + #include <linux/init.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 21 + #include <linux/of_gpio.h> 22 + #include <linux/regmap.h> 23 + #include <linux/rtc.h> 24 + #include <linux/spi/spi.h> 25 + 26 + /* RX-6110 Register definitions */ 27 + #define RX6110_REG_SEC 0x10 28 + #define RX6110_REG_MIN 0x11 29 + #define RX6110_REG_HOUR 0x12 30 + #define RX6110_REG_WDAY 0x13 31 + #define RX6110_REG_MDAY 0x14 32 + #define RX6110_REG_MONTH 0x15 33 + #define RX6110_REG_YEAR 0x16 34 + #define RX6110_REG_RES1 0x17 35 + #define RX6110_REG_ALMIN 0x18 36 + #define RX6110_REG_ALHOUR 0x19 37 + #define RX6110_REG_ALWDAY 0x1A 38 + #define RX6110_REG_TCOUNT0 0x1B 39 + #define RX6110_REG_TCOUNT1 0x1C 40 + #define RX6110_REG_EXT 0x1D 41 + #define RX6110_REG_FLAG 0x1E 42 + #define RX6110_REG_CTRL 0x1F 43 + #define RX6110_REG_USER0 0x20 44 + #define RX6110_REG_USER1 0x21 45 + #define RX6110_REG_USER2 0x22 46 + #define RX6110_REG_USER3 0x23 47 + #define RX6110_REG_USER4 0x24 48 + #define RX6110_REG_USER5 0x25 49 + #define RX6110_REG_USER6 0x26 50 + #define RX6110_REG_USER7 0x27 51 + #define RX6110_REG_USER8 0x28 52 + #define RX6110_REG_USER9 0x29 53 + #define RX6110_REG_USERA 0x2A 54 + #define RX6110_REG_USERB 0x2B 55 + #define RX6110_REG_USERC 0x2C 56 + #define RX6110_REG_USERD 0x2D 57 + #define RX6110_REG_USERE 0x2E 58 + #define RX6110_REG_USERF 0x2F 59 + #define RX6110_REG_RES2 0x30 60 + #define RX6110_REG_RES3 0x31 61 + #define RX6110_REG_IRQ 0x32 62 + 63 + #define RX6110_BIT_ALARM_EN BIT(7) 64 + 65 + /* Extension Register (1Dh) bit positions */ 66 + #define RX6110_BIT_EXT_TSEL0 BIT(0) 67 + #define RX6110_BIT_EXT_TSEL1 BIT(1) 68 + #define RX6110_BIT_EXT_TSEL2 BIT(2) 69 + #define RX6110_BIT_EXT_WADA BIT(3) 70 + #define RX6110_BIT_EXT_TE BIT(4) 71 + #define RX6110_BIT_EXT_USEL BIT(5) 72 + #define RX6110_BIT_EXT_FSEL0 BIT(6) 73 + #define RX6110_BIT_EXT_FSEL1 BIT(7) 74 + 75 + /* Flag Register (1Eh) bit positions */ 76 + #define RX6110_BIT_FLAG_VLF BIT(1) 77 + #define RX6110_BIT_FLAG_AF BIT(3) 78 + #define RX6110_BIT_FLAG_TF BIT(4) 79 + #define RX6110_BIT_FLAG_UF BIT(5) 80 + 81 + /* Control Register (1Fh) bit positions */ 82 + #define RX6110_BIT_CTRL_TBKE BIT(0) 83 + #define RX6110_BIT_CTRL_TBKON BIT(1) 84 + #define RX6110_BIT_CTRL_TSTP BIT(2) 85 + #define RX6110_BIT_CTRL_AIE BIT(3) 86 + #define RX6110_BIT_CTRL_TIE BIT(4) 87 + #define RX6110_BIT_CTRL_UIE BIT(5) 88 + #define RX6110_BIT_CTRL_STOP BIT(6) 89 + #define RX6110_BIT_CTRL_TEST BIT(7) 90 + 91 + enum { 92 + RTC_SEC = 0, 93 + RTC_MIN, 94 + RTC_HOUR, 95 + RTC_WDAY, 96 + RTC_MDAY, 97 + RTC_MONTH, 98 + RTC_YEAR, 99 + RTC_NR_TIME 100 + }; 101 + 102 + #define RX6110_DRIVER_NAME "rx6110" 103 + 104 + struct rx6110_data { 105 + struct rtc_device *rtc; 106 + struct regmap *regmap; 107 + }; 108 + 109 + /** 110 + * rx6110_rtc_tm_to_data - convert rtc_time to native time encoding 111 + * 112 + * @tm: holds date and time 113 + * @data: holds the encoding in rx6110 native form 114 + */ 115 + static int rx6110_rtc_tm_to_data(struct rtc_time *tm, u8 *data) 116 + { 117 + pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 118 + tm->tm_sec, tm->tm_min, tm->tm_hour, 119 + tm->tm_mday, tm->tm_mon, tm->tm_year); 120 + 121 + /* 122 + * The year in the RTC is a value between 0 and 99. 123 + * Assume that this represents the current century 124 + * and disregard all other values. 125 + */ 126 + if (tm->tm_year < 100 || tm->tm_year >= 200) 127 + return -EINVAL; 128 + 129 + data[RTC_SEC] = bin2bcd(tm->tm_sec); 130 + data[RTC_MIN] = bin2bcd(tm->tm_min); 131 + data[RTC_HOUR] = bin2bcd(tm->tm_hour); 132 + data[RTC_WDAY] = BIT(bin2bcd(tm->tm_wday)); 133 + data[RTC_MDAY] = bin2bcd(tm->tm_mday); 134 + data[RTC_MONTH] = bin2bcd(tm->tm_mon + 1); 135 + data[RTC_YEAR] = bin2bcd(tm->tm_year % 100); 136 + 137 + return 0; 138 + } 139 + 140 + /** 141 + * rx6110_data_to_rtc_tm - convert native time encoding to rtc_time 142 + * 143 + * @data: holds the encoding in rx6110 native form 144 + * @tm: holds date and time 145 + */ 146 + static int rx6110_data_to_rtc_tm(u8 *data, struct rtc_time *tm) 147 + { 148 + tm->tm_sec = bcd2bin(data[RTC_SEC] & 0x7f); 149 + tm->tm_min = bcd2bin(data[RTC_MIN] & 0x7f); 150 + /* only 24-hour clock */ 151 + tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f); 152 + tm->tm_wday = ffs(data[RTC_WDAY] & 0x7f); 153 + tm->tm_mday = bcd2bin(data[RTC_MDAY] & 0x3f); 154 + tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1; 155 + tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100; 156 + 157 + pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 158 + tm->tm_sec, tm->tm_min, tm->tm_hour, 159 + tm->tm_mday, tm->tm_mon, tm->tm_year); 160 + 161 + /* 162 + * The year in the RTC is a value between 0 and 99. 163 + * Assume that this represents the current century 164 + * and disregard all other values. 165 + */ 166 + if (tm->tm_year < 100 || tm->tm_year >= 200) 167 + return -EINVAL; 168 + 169 + return 0; 170 + } 171 + 172 + /** 173 + * rx6110_set_time - set the current time in the rx6110 registers 174 + * 175 + * @dev: the rtc device in use 176 + * @tm: holds date and time 177 + * 178 + * BUG: The HW assumes every year that is a multiple of 4 to be a leap 179 + * year. Next time this is wrong is 2100, which will not be a leap year 180 + * 181 + * Note: If STOP is not set/cleared, the clock will start when the seconds 182 + * register is written 183 + * 184 + */ 185 + static int rx6110_set_time(struct device *dev, struct rtc_time *tm) 186 + { 187 + struct rx6110_data *rx6110 = dev_get_drvdata(dev); 188 + u8 data[RTC_NR_TIME]; 189 + int ret; 190 + 191 + ret = rx6110_rtc_tm_to_data(tm, data); 192 + if (ret < 0) 193 + return ret; 194 + 195 + /* set STOP bit before changing clock/calendar */ 196 + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL, 197 + RX6110_BIT_CTRL_STOP, RX6110_BIT_CTRL_STOP); 198 + if (ret) 199 + return ret; 200 + 201 + ret = regmap_bulk_write(rx6110->regmap, RX6110_REG_SEC, data, 202 + RTC_NR_TIME); 203 + if (ret) 204 + return ret; 205 + 206 + /* The time in the RTC is valid. Be sure to have VLF cleared. */ 207 + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG, 208 + RX6110_BIT_FLAG_VLF, 0); 209 + if (ret) 210 + return ret; 211 + 212 + /* clear STOP bit after changing clock/calendar */ 213 + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_CTRL, 214 + RX6110_BIT_CTRL_STOP, 0); 215 + 216 + return ret; 217 + } 218 + 219 + /** 220 + * rx6110_get_time - get the current time from the rx6110 registers 221 + * @dev: the rtc device in use 222 + * @tm: holds date and time 223 + */ 224 + static int rx6110_get_time(struct device *dev, struct rtc_time *tm) 225 + { 226 + struct rx6110_data *rx6110 = dev_get_drvdata(dev); 227 + u8 data[RTC_NR_TIME]; 228 + int flags; 229 + int ret; 230 + 231 + ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags); 232 + if (ret) 233 + return -EINVAL; 234 + 235 + /* check for VLF Flag (set at power-on) */ 236 + if ((flags & RX6110_BIT_FLAG_VLF)) { 237 + dev_warn(dev, "Voltage low, data is invalid.\n"); 238 + return -EINVAL; 239 + } 240 + 241 + /* read registers to date */ 242 + ret = regmap_bulk_read(rx6110->regmap, RX6110_REG_SEC, data, 243 + RTC_NR_TIME); 244 + if (ret) 245 + return ret; 246 + 247 + ret = rx6110_data_to_rtc_tm(data, tm); 248 + if (ret) 249 + return ret; 250 + 251 + dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 252 + tm->tm_sec, tm->tm_min, tm->tm_hour, 253 + tm->tm_mday, tm->tm_mon, tm->tm_year); 254 + 255 + return rtc_valid_tm(tm); 256 + } 257 + 258 + static const struct reg_sequence rx6110_default_regs[] = { 259 + { RX6110_REG_RES1, 0xB8 }, 260 + { RX6110_REG_RES2, 0x00 }, 261 + { RX6110_REG_RES3, 0x10 }, 262 + { RX6110_REG_IRQ, 0x00 }, 263 + { RX6110_REG_ALMIN, 0x00 }, 264 + { RX6110_REG_ALHOUR, 0x00 }, 265 + { RX6110_REG_ALWDAY, 0x00 }, 266 + }; 267 + 268 + /** 269 + * rx6110_init - initialize the rx6110 registers 270 + * 271 + * @rx6110: pointer to the rx6110 struct in use 272 + * 273 + */ 274 + static int rx6110_init(struct rx6110_data *rx6110) 275 + { 276 + struct rtc_device *rtc = rx6110->rtc; 277 + int flags; 278 + int ret; 279 + 280 + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_EXT, 281 + RX6110_BIT_EXT_TE, 0); 282 + if (ret) 283 + return ret; 284 + 285 + ret = regmap_register_patch(rx6110->regmap, rx6110_default_regs, 286 + ARRAY_SIZE(rx6110_default_regs)); 287 + if (ret) 288 + return ret; 289 + 290 + ret = regmap_read(rx6110->regmap, RX6110_REG_FLAG, &flags); 291 + if (ret) 292 + return ret; 293 + 294 + /* check for VLF Flag (set at power-on) */ 295 + if ((flags & RX6110_BIT_FLAG_VLF)) 296 + dev_warn(&rtc->dev, "Voltage low, data loss detected.\n"); 297 + 298 + /* check for Alarm Flag */ 299 + if (flags & RX6110_BIT_FLAG_AF) 300 + dev_warn(&rtc->dev, "An alarm may have been missed.\n"); 301 + 302 + /* check for Periodic Timer Flag */ 303 + if (flags & RX6110_BIT_FLAG_TF) 304 + dev_warn(&rtc->dev, "Periodic timer was detected\n"); 305 + 306 + /* check for Update Timer Flag */ 307 + if (flags & RX6110_BIT_FLAG_UF) 308 + dev_warn(&rtc->dev, "Update timer was detected\n"); 309 + 310 + /* clear all flags BUT VLF */ 311 + ret = regmap_update_bits(rx6110->regmap, RX6110_REG_FLAG, 312 + RX6110_BIT_FLAG_AF | 313 + RX6110_BIT_FLAG_UF | 314 + RX6110_BIT_FLAG_TF, 315 + 0); 316 + 317 + return ret; 318 + } 319 + 320 + static struct rtc_class_ops rx6110_rtc_ops = { 321 + .read_time = rx6110_get_time, 322 + .set_time = rx6110_set_time, 323 + }; 324 + 325 + static struct regmap_config regmap_spi_config = { 326 + .reg_bits = 8, 327 + .val_bits = 8, 328 + .max_register = RX6110_REG_IRQ, 329 + .read_flag_mask = 0x80, 330 + }; 331 + 332 + /** 333 + * rx6110_probe - initialize rtc driver 334 + * @spi: pointer to spi device 335 + */ 336 + static int rx6110_probe(struct spi_device *spi) 337 + { 338 + struct rx6110_data *rx6110; 339 + int err; 340 + 341 + if ((spi->bits_per_word && spi->bits_per_word != 8) || 342 + (spi->max_speed_hz > 2000000) || 343 + (spi->mode != (SPI_CS_HIGH | SPI_CPOL | SPI_CPHA))) { 344 + dev_warn(&spi->dev, "SPI settings: bits_per_word: %d, max_speed_hz: %d, mode: %xh\n", 345 + spi->bits_per_word, spi->max_speed_hz, spi->mode); 346 + dev_warn(&spi->dev, "driving device in an unsupported mode"); 347 + } 348 + 349 + rx6110 = devm_kzalloc(&spi->dev, sizeof(*rx6110), GFP_KERNEL); 350 + if (!rx6110) 351 + return -ENOMEM; 352 + 353 + rx6110->regmap = devm_regmap_init_spi(spi, &regmap_spi_config); 354 + if (IS_ERR(rx6110->regmap)) { 355 + dev_err(&spi->dev, "regmap init failed for rtc rx6110\n"); 356 + return PTR_ERR(rx6110->regmap); 357 + } 358 + 359 + spi_set_drvdata(spi, rx6110); 360 + 361 + rx6110->rtc = devm_rtc_device_register(&spi->dev, 362 + RX6110_DRIVER_NAME, 363 + &rx6110_rtc_ops, THIS_MODULE); 364 + 365 + if (IS_ERR(rx6110->rtc)) 366 + return PTR_ERR(rx6110->rtc); 367 + 368 + err = rx6110_init(rx6110); 369 + if (err) 370 + return err; 371 + 372 + rx6110->rtc->max_user_freq = 1; 373 + 374 + return 0; 375 + } 376 + 377 + static int rx6110_remove(struct spi_device *spi) 378 + { 379 + return 0; 380 + } 381 + 382 + static const struct spi_device_id rx6110_id[] = { 383 + { "rx6110", 0 }, 384 + { } 385 + }; 386 + MODULE_DEVICE_TABLE(spi, rx6110_id); 387 + 388 + static struct spi_driver rx6110_driver = { 389 + .driver = { 390 + .name = RX6110_DRIVER_NAME, 391 + .owner = THIS_MODULE, 392 + }, 393 + .probe = rx6110_probe, 394 + .remove = rx6110_remove, 395 + .id_table = rx6110_id, 396 + }; 397 + 398 + module_spi_driver(rx6110_driver); 399 + 400 + MODULE_AUTHOR("Val Krutov <val.krutov@erd.epson.com>"); 401 + MODULE_DESCRIPTION("RX-6110 SA RTC driver"); 402 + MODULE_LICENSE("GPL");
+21 -4
drivers/rtc/rtc-rx8025.c
··· 65 65 66 66 static const struct i2c_device_id rx8025_id[] = { 67 67 { "rx8025", 0 }, 68 - { "rv8803", 1 }, 69 68 { } 70 69 }; 71 70 MODULE_DEVICE_TABLE(i2c, rx8025_id); ··· 146 147 { 147 148 struct i2c_client *client = dev_id; 148 149 struct rx8025_data *rx8025 = i2c_get_clientdata(client); 150 + struct mutex *lock = &rx8025->rtc->ops_lock; 149 151 int status; 150 152 153 + mutex_lock(lock); 151 154 status = rx8025_read_reg(client, RX8025_REG_CTRL2); 152 155 if (status < 0) 153 156 goto out; ··· 174 173 } 175 174 176 175 out: 176 + mutex_unlock(lock); 177 + 177 178 return IRQ_HANDLED; 178 179 } 179 180 ··· 344 341 if (client->irq <= 0) 345 342 return -EINVAL; 346 343 347 - /* Hardware alarm precision is 1 minute! */ 344 + /* 345 + * Hardware alarm precision is 1 minute! 346 + * round up to nearest minute 347 + */ 348 + if (t->time.tm_sec) { 349 + time64_t alarm_time = rtc_tm_to_time64(&t->time); 350 + 351 + alarm_time += 60 - t->time.tm_sec; 352 + rtc_time64_to_tm(alarm_time, &t->time); 353 + } 354 + 348 355 ald[0] = bin2bcd(t->time.tm_min); 349 356 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224) 350 357 ald[1] = bin2bcd(t->time.tm_hour); ··· 552 539 if (client->irq > 0) { 553 540 dev_info(&client->dev, "IRQ %d supplied\n", client->irq); 554 541 err = devm_request_threaded_irq(&client->dev, client->irq, NULL, 555 - rx8025_handle_irq, 0, "rx8025", 556 - client); 542 + rx8025_handle_irq, 543 + IRQF_ONESHOT, 544 + "rx8025", client); 557 545 if (err) { 558 546 dev_err(&client->dev, "unable to request IRQ, alarms disabled\n"); 559 547 client->irq = 0; ··· 562 548 } 563 549 564 550 rx8025->rtc->max_user_freq = 1; 551 + 552 + /* the rx8025 alarm only supports a minute accuracy */ 553 + rx8025->rtc->uie_unsupported = 1; 565 554 566 555 err = rx8025_sysfs_register(&client->dev); 567 556 return err;
+4 -4
drivers/rtc/rtc-s5m.c
··· 216 216 * Read RTC_UDR_CON register and wait till UDR field is cleared. 217 217 * This indicates that time/alarm update ended. 218 218 */ 219 - static inline int s5m8767_wait_for_udr_update(struct s5m_rtc_info *info) 219 + static int s5m8767_wait_for_udr_update(struct s5m_rtc_info *info) 220 220 { 221 221 int ret, retry = UDR_READ_RETRY_CNT; 222 222 unsigned int data; ··· 231 231 return ret; 232 232 } 233 233 234 - static inline int s5m_check_peding_alarm_interrupt(struct s5m_rtc_info *info, 234 + static int s5m_check_peding_alarm_interrupt(struct s5m_rtc_info *info, 235 235 struct rtc_wkalrm *alarm) 236 236 { 237 237 int ret; ··· 264 264 return 0; 265 265 } 266 266 267 - static inline int s5m8767_rtc_set_time_reg(struct s5m_rtc_info *info) 267 + static int s5m8767_rtc_set_time_reg(struct s5m_rtc_info *info) 268 268 { 269 269 int ret; 270 270 unsigned int data; ··· 288 288 return ret; 289 289 } 290 290 291 - static inline int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info) 291 + static int s5m8767_rtc_set_alarm_reg(struct s5m_rtc_info *info) 292 292 { 293 293 int ret; 294 294 unsigned int data;
+34 -1
drivers/rtc/rtc-sysfs.c
··· 218 218 } 219 219 static DEVICE_ATTR_RW(wakealarm); 220 220 221 + static ssize_t 222 + offset_show(struct device *dev, struct device_attribute *attr, char *buf) 223 + { 224 + ssize_t retval; 225 + long offset; 226 + 227 + retval = rtc_read_offset(to_rtc_device(dev), &offset); 228 + if (retval == 0) 229 + retval = sprintf(buf, "%ld\n", offset); 230 + 231 + return retval; 232 + } 233 + 234 + static ssize_t 235 + offset_store(struct device *dev, struct device_attribute *attr, 236 + const char *buf, size_t n) 237 + { 238 + ssize_t retval; 239 + long offset; 240 + 241 + retval = kstrtol(buf, 10, &offset); 242 + if (retval == 0) 243 + retval = rtc_set_offset(to_rtc_device(dev), offset); 244 + 245 + return (retval < 0) ? retval : n; 246 + } 247 + static DEVICE_ATTR_RW(offset); 248 + 221 249 static struct attribute *rtc_attrs[] = { 222 250 &dev_attr_name.attr, 223 251 &dev_attr_date.attr, ··· 254 226 &dev_attr_max_user_freq.attr, 255 227 &dev_attr_hctosys.attr, 256 228 &dev_attr_wakealarm.attr, 229 + &dev_attr_offset.attr, 257 230 NULL, 258 231 }; 259 232 ··· 278 249 struct rtc_device *rtc = to_rtc_device(dev); 279 250 umode_t mode = attr->mode; 280 251 281 - if (attr == &dev_attr_wakealarm.attr) 252 + if (attr == &dev_attr_wakealarm.attr) { 282 253 if (!rtc_does_wakealarm(rtc)) 283 254 mode = 0; 255 + } else if (attr == &dev_attr_offset.attr) { 256 + if (!rtc->ops->set_offset) 257 + mode = 0; 258 + } 284 259 285 260 return mode; 286 261 }
+1 -1
drivers/rtc/rtc-tps6586x.c
··· 286 286 287 287 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 288 288 tps6586x_rtc_irq, 289 - IRQF_ONESHOT | IRQF_EARLY_RESUME, 289 + IRQF_ONESHOT, 290 290 dev_name(&pdev->dev), rtc); 291 291 if (ret < 0) { 292 292 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n",
+1 -1
drivers/rtc/rtc-tps65910.c
··· 268 268 } 269 269 270 270 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 271 - tps65910_rtc_interrupt, IRQF_TRIGGER_LOW | IRQF_EARLY_RESUME, 271 + tps65910_rtc_interrupt, IRQF_TRIGGER_LOW, 272 272 dev_name(&pdev->dev), &pdev->dev); 273 273 if (ret < 0) { 274 274 dev_err(&pdev->dev, "IRQ is not free.\n");
+1 -1
drivers/rtc/rtc-tps80031.c
··· 287 287 288 288 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 289 289 tps80031_rtc_irq, 290 - IRQF_ONESHOT | IRQF_EARLY_RESUME, 290 + IRQF_ONESHOT, 291 291 dev_name(&pdev->dev), rtc); 292 292 if (ret < 0) { 293 293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n",
+7 -6
drivers/rtc/rtc-vr41xx.c
··· 272 272 } 273 273 274 274 static const struct rtc_class_ops vr41xx_rtc_ops = { 275 - .release = vr41xx_rtc_release, 276 - .ioctl = vr41xx_rtc_ioctl, 277 - .read_time = vr41xx_rtc_read_time, 278 - .set_time = vr41xx_rtc_set_time, 279 - .read_alarm = vr41xx_rtc_read_alarm, 280 - .set_alarm = vr41xx_rtc_set_alarm, 275 + .release = vr41xx_rtc_release, 276 + .ioctl = vr41xx_rtc_ioctl, 277 + .read_time = vr41xx_rtc_read_time, 278 + .set_time = vr41xx_rtc_set_time, 279 + .read_alarm = vr41xx_rtc_read_alarm, 280 + .set_alarm = vr41xx_rtc_set_alarm, 281 + .alarm_irq_enable = vr41xx_rtc_alarm_irq_enable, 281 282 }; 282 283 283 284 static int rtc_probe(struct platform_device *pdev)
-3
include/linux/mfd/max77686-private.h
··· 437 437 struct max77686_dev { 438 438 struct device *dev; 439 439 struct i2c_client *i2c; /* 0xcc / PMIC, Battery Control, and FLASH */ 440 - struct i2c_client *rtc; /* slave addr 0x0c */ 441 440 442 441 unsigned long type; 443 442 444 443 struct regmap *regmap; /* regmap for mfd */ 445 - struct regmap *rtc_regmap; /* regmap for rtc */ 446 444 struct regmap_irq_chip_data *irq_data; 447 - struct regmap_irq_chip_data *rtc_irq_data; 448 445 449 446 int irq; 450 447 struct mutex irqlock;
+4
include/linux/rtc.h
··· 89 89 int (*set_mmss)(struct device *, unsigned long secs); 90 90 int (*read_callback)(struct device *, int data); 91 91 int (*alarm_irq_enable)(struct device *, unsigned int enabled); 92 + int (*read_offset)(struct device *, long *offset); 93 + int (*set_offset)(struct device *, long offset); 92 94 }; 93 95 94 96 #define RTC_DEVICE_NAME_SIZE 20 ··· 210 208 int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, 211 209 ktime_t expires, ktime_t period); 212 210 void rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer *timer); 211 + int rtc_read_offset(struct rtc_device *rtc, long *offset); 212 + int rtc_set_offset(struct rtc_device *rtc, long offset); 213 213 void rtc_timer_do_work(struct work_struct *work); 214 214 215 215 static inline bool is_leap_year(unsigned int year)