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

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

Pull RTC updates from Alexandre Belloni:
"There is nothing scary this cycle, mostly driver fixes and updates.

The core fix has been in for a while and has been tested on multiple
kernel revisions by multiple teams.

Core:
- Fix setting the alarm to the next expiring timer

New drivers:
- Mediatek MT7622 RTC
- NXP PCF85363
- Spreadtrum SC27xx PMIC RTC

Drivers updates:
- Use generic nvmem to expose the Non volatile ram for ds1305,
ds1511, m48t86 and omap
- abx80x: solve possible race condition at probe
- armada38x: support trimming the RTC oscillator
- at91rm9200: fix reading the alarm value at boot
- ds1511: allow waking platform
- m41t80: rework square wave output
- pcf8523: support trimming the RTC oscillator
- pcf8563: fix clock output rate
- pl031: make interrupt optional
- xgene: fix suspend/resume"

* tag 'rtc-4.15' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (50 commits)
dt-bindings: rtc: imxdi: Improve the bindings text
rtc: sc27xx: Add Spreadtrum SC27xx PMIC RTC driver
dt-bindings: rtc: Add Spreadtrum SC27xx RTC documentation
rtc: at91rm9200: fix reading alarm value
rtc: at91rm9200: stop calculating yday in at91_rtc_readalarm
rtc: sysfs: Use time64_t variables to set time/alarm
rtc: xgene: mark PM functions as __maybe_unused
rtc: xgene: Fix suspend/resume
rtc: pcf8563: don't alway enable the alarm
rtc: pcf8563: fix output clock rate
rtc: rx8010: Fix for incorrect return value
rtc: rx8010: Specify correct address for RX8010_RESV31
rtc: rx8010: Remove duplicate define
rtc: m41t80: remove unneeded checks from m41t80_sqw_set_rate
rtc: m41t80: avoid i2c read in m41t80_sqw_is_prepared
rtc: m41t80: avoid i2c read in m41t80_sqw_recalc_rate
rtc: m41t80: fix m41t80_sqw_round_rate return value
rtc: m41t80: m41t80_sqw_set_rate should return 0 on success
rtc: add support for NXP PCF85363 real-time clock
rtc: omap: Support scratch registers
...

+1891 -283
+7 -7
Documentation/devicetree/bindings/rtc/imxdi-rtc.txt
··· 1 1 * i.MX25 Real Time Clock controller 2 2 3 - This binding supports the following chips: i.MX25, i.MX53 4 - 5 3 Required properties: 6 4 - compatible: should be: "fsl,imx25-rtc" 7 5 - reg: physical base address of the controller and length of memory mapped 8 6 region. 7 + - clocks: should contain the phandle for the rtc clock 9 8 - interrupts: rtc alarm interrupt 10 9 11 10 Optional properties: 12 - - interrupts: dryice security violation interrupt 11 + - interrupts: dryice security violation interrupt (second entry) 13 12 14 13 Example: 15 14 16 - rtc@80056000 { 17 - compatible = "fsl,imx53-rtc", "fsl,imx25-rtc"; 18 - reg = <0x80056000 2000>; 19 - interrupts = <29 56>; 15 + rtc@53ffc000 { 16 + compatible = "fsl,imx25-rtc"; 17 + reg = <0x53ffc000 0x4000>; 18 + clocks = <&clks 81>; 19 + interrupts = <25 56>; 20 20 };
+17
Documentation/devicetree/bindings/rtc/pcf85363.txt
··· 1 + NXP PCF85363 Real Time Clock 2 + ============================ 3 + 4 + Required properties: 5 + - compatible: Should contain "nxp,pcf85363". 6 + - reg: I2C address for chip. 7 + 8 + Optional properties: 9 + - interrupts: IRQ line for the RTC (not implemented). 10 + 11 + Example: 12 + 13 + pcf85363: pcf85363@51 { 14 + compatible = "nxp,pcf85363"; 15 + reg = <0x51>; 16 + }; 17 +
+21
Documentation/devicetree/bindings/rtc/rtc-mt7622.txt
··· 1 + Device-Tree bindings for MediaTek SoC based RTC 2 + 3 + Required properties: 4 + - compatible : Should be 5 + "mediatek,mt7622-rtc", "mediatek,soc-rtc" : for MT7622 SoC 6 + - reg : Specifies base physical address and size of the registers; 7 + - interrupts : Should contain the interrupt for RTC alarm; 8 + - clocks : Specifies list of clock specifiers, corresponding to 9 + entries in clock-names property; 10 + - clock-names : Should contain "rtc" entries 11 + 12 + Example: 13 + 14 + rtc: rtc@10212800 { 15 + compatible = "mediatek,mt7622-rtc", 16 + "mediatek,soc-rtc"; 17 + reg = <0 0x10212800 0 0x200>; 18 + interrupts = <GIC_SPI 129 IRQ_TYPE_LEVEL_LOW>; 19 + clocks = <&topckgen CLK_TOP_RTC>; 20 + clock-names = "rtc"; 21 + };
+27
Documentation/devicetree/bindings/rtc/sprd,sc27xx-rtc.txt
··· 1 + Spreadtrum SC27xx Real Time Clock 2 + 3 + Required properties: 4 + - compatible: should be "sprd,sc2731-rtc". 5 + - reg: address offset of rtc register. 6 + - interrupt-parent: phandle for the interrupt controller. 7 + - interrupts: rtc alarm interrupt. 8 + 9 + Example: 10 + 11 + sc2731_pmic: pmic@0 { 12 + compatible = "sprd,sc2731"; 13 + reg = <0>; 14 + spi-max-frequency = <26000000>; 15 + interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; 16 + interrupt-controller; 17 + #interrupt-cells = <2>; 18 + #address-cells = <1>; 19 + #size-cells = <0>; 20 + 21 + rtc@280 { 22 + compatible = "sprd,sc2731-rtc"; 23 + reg = <0x280>; 24 + interrupt-parent = <&sc2731_pmic>; 25 + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>; 26 + }; 27 + };
+1 -1
Documentation/devicetree/bindings/trivial-devices.txt
··· 72 72 maxim,max1237 Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs 73 73 maxim,max6621 PECI-to-I2C translator for PECI-to-SMBus/I2C protocol conversion 74 74 maxim,max6625 9-Bit/12-Bit Temperature Sensors with I²C-Compatible Serial Interface 75 - mc,rv3029c2 Real Time Clock Module with I2C-Bus 76 75 mcube,mc3230 mCube 3-axis 8-bit digital accelerometer 77 76 memsic,mxc6225 MEMSIC 2-axis 8-bit digital accelerometer 78 77 microchip,mcp4531-502 Microchip 7-bit Single I2C Digital Potentiometer (5k) ··· 140 141 microchip,mcp4662-104 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (100k) 141 142 microchip,tc654 PWM Fan Speed Controller With Fan Fault Detection 142 143 microchip,tc655 PWM Fan Speed Controller With Fan Fault Detection 144 + microcrystal,rv3029 Real Time Clock Module with I2C-Bus 143 145 miramems,da226 MiraMEMS DA226 2-axis 14-bit digital accelerometer 144 146 miramems,da280 MiraMEMS DA280 3-axis 14-bit digital accelerometer 145 147 miramems,da311 MiraMEMS DA311 3-axis 12-bit digital accelerometer
+3
MAINTAINERS
··· 1590 1590 1591 1591 ARM/Mediatek RTC DRIVER 1592 1592 M: Eddie Huang <eddie.huang@mediatek.com> 1593 + M: Sean Wang <sean.wang@mediatek.com> 1593 1594 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1594 1595 L: linux-mediatek@lists.infradead.org (moderated for non-subscribers) 1595 1596 S: Maintained 1597 + F: Documentation/devicetree/bindings/rtc/rtc-mt7622.txt 1596 1598 F: drivers/rtc/rtc-mt6397.c 1599 + F: drivers/rtc/rtc-mt7622.c 1597 1600 1598 1601 ARM/Mediatek SoC support 1599 1602 M: Matthias Brugger <matthias.bgg@gmail.com>
+38 -4
drivers/rtc/Kconfig
··· 433 433 This driver can also be built as a module. If so, the module 434 434 will be called rtc-pcf85063. 435 435 436 + config RTC_DRV_PCF85363 437 + tristate "NXP PCF85363" 438 + depends on I2C 439 + select REGMAP_I2C 440 + help 441 + If you say yes here you get support for the PCF85363 RTC chip. 442 + 443 + This driver can also be built as a module. If so, the module 444 + will be called rtc-pcf85363. 445 + 446 + The nvmem interface will be named pcf85363-#, where # is the 447 + zero-based instance number. 448 + 436 449 config RTC_DRV_PCF8563 437 450 tristate "Philips PCF8563/Epson RTC8564" 438 451 help ··· 1187 1174 This driver can also be built as a module. If so, the module 1188 1175 will be called "rtc-wm8350". 1189 1176 1177 + config RTC_DRV_SC27XX 1178 + tristate "Spreadtrum SC27xx RTC" 1179 + depends on MFD_SC27XX_PMIC || COMPILE_TEST 1180 + help 1181 + If you say Y here you will get support for the RTC subsystem 1182 + of the Spreadtrum SC27xx series PMICs. The SC27xx series PMICs 1183 + includes the SC2720, SC2721, SC2723, SC2730 and SC2731 chips. 1184 + 1185 + This driver can also be built as a module. If so, the module 1186 + will be called rtc-sc27xx. 1187 + 1190 1188 config RTC_DRV_SPEAR 1191 1189 tristate "SPEAR ST RTC" 1192 1190 depends on PLAT_SPEAR || COMPILE_TEST ··· 1730 1706 will be called rtc-moxart 1731 1707 1732 1708 config RTC_DRV_MT6397 1733 - tristate "Mediatek Real Time Clock driver" 1709 + tristate "MediaTek PMIC based RTC" 1734 1710 depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN) 1735 1711 help 1736 - This selects the Mediatek(R) RTC driver. RTC is part of Mediatek 1712 + This selects the MediaTek(R) RTC driver. RTC is part of MediaTek 1737 1713 MT6397 PMIC. You should enable MT6397 PMIC MFD before select 1738 - Mediatek(R) RTC driver. 1714 + MediaTek(R) RTC driver. 1739 1715 1740 - If you want to use Mediatek(R) RTC interface, select Y or M here. 1716 + If you want to use MediaTek(R) RTC interface, select Y or M here. 1717 + 1718 + config RTC_DRV_MT7622 1719 + tristate "MediaTek SoC based RTC" 1720 + depends on ARCH_MEDIATEK || COMPILE_TEST 1721 + help 1722 + This enables support for the real time clock built in the MediaTek 1723 + SoCs. 1724 + 1725 + This drive can also be built as a module. If so, the module 1726 + will be called rtc-mt7622. 1741 1727 1742 1728 config RTC_DRV_XGENE 1743 1729 tristate "APM X-Gene RTC"
+3
drivers/rtc/Makefile
··· 103 103 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 104 104 obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 105 105 obj-$(CONFIG_RTC_DRV_MT6397) += rtc-mt6397.o 106 + obj-$(CONFIG_RTC_DRV_MT7622) += rtc-mt7622.o 106 107 obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o 107 108 obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o 108 109 obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o ··· 115 114 obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o 116 115 obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o 117 116 obj-$(CONFIG_RTC_DRV_PCF85063) += rtc-pcf85063.o 117 + obj-$(CONFIG_RTC_DRV_PCF85363) += rtc-pcf85363.o 118 118 obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o 119 119 obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 120 120 obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o ··· 146 144 obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o 147 145 obj-$(CONFIG_RTC_DRV_S5M) += rtc-s5m.o 148 146 obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 147 + obj-$(CONFIG_RTC_DRV_SC27XX) += rtc-sc27xx.o 149 148 obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 150 149 obj-$(CONFIG_RTC_DRV_SIRFSOC) += rtc-sirfsoc.o 151 150 obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o
+5 -1
drivers/rtc/interface.c
··· 779 779 } 780 780 781 781 timerqueue_add(&rtc->timerqueue, &timer->node); 782 - if (!next) { 782 + if (!next || ktime_before(timer->node.expires, next->expires)) { 783 783 struct rtc_wkalrm alarm; 784 784 int err; 785 785 alarm.time = rtc_ktime_to_tm(timer->node.expires); ··· 1003 1003 * Some rtc's allow an adjustment to the average duration of a second 1004 1004 * to compensate for differences in the actual clock rate due to temperature, 1005 1005 * the crystal, capacitor, etc. 1006 + * 1007 + * The adjustment applied is as follows: 1008 + * t = t0 * (1 + offset * 1e-9) 1009 + * where t0 is the measured length of 1 RTC second with offset = 0 1006 1010 * 1007 1011 * Kernel interface to adjust an rtc clock offset. 1008 1012 * Return 0 on success, or a negative number on error.
+8 -4
drivers/rtc/rtc-abx80x.c
··· 614 614 if (err) 615 615 return err; 616 616 617 - rtc = devm_rtc_device_register(&client->dev, "abx8xx", 618 - &abx80x_rtc_ops, THIS_MODULE); 619 - 617 + rtc = devm_rtc_allocate_device(&client->dev); 620 618 if (IS_ERR(rtc)) 621 619 return PTR_ERR(rtc); 620 + 621 + rtc->ops = &abx80x_rtc_ops; 622 622 623 623 i2c_set_clientdata(client, rtc); 624 624 ··· 646 646 err = devm_add_action_or_reset(&client->dev, 647 647 rtc_calib_remove_sysfs_group, 648 648 &client->dev); 649 - if (err) 649 + if (err) { 650 650 dev_err(&client->dev, 651 651 "Failed to add sysfs cleanup action: %d\n", 652 652 err); 653 + return err; 654 + } 655 + 656 + err = rtc_register_device(rtc); 653 657 654 658 return err; 655 659 }
+101
drivers/rtc/rtc-armada38x.c
··· 28 28 #define RTC_IRQ_AL_EN BIT(0) 29 29 #define RTC_IRQ_FREQ_EN BIT(1) 30 30 #define RTC_IRQ_FREQ_1HZ BIT(2) 31 + #define RTC_CCR 0x18 32 + #define RTC_CCR_MODE BIT(15) 31 33 32 34 #define RTC_TIME 0xC 33 35 #define RTC_ALARM1 0x10 ··· 345 343 return IRQ_HANDLED; 346 344 } 347 345 346 + /* 347 + * The information given in the Armada 388 functional spec is complex. 348 + * They give two different formulas for calculating the offset value, 349 + * but when considering "Offset" as an 8-bit signed integer, they both 350 + * reduce down to (we shall rename "Offset" as "val" here): 351 + * 352 + * val = (f_ideal / f_measured - 1) / resolution where f_ideal = 32768 353 + * 354 + * Converting to time, f = 1/t: 355 + * val = (t_measured / t_ideal - 1) / resolution where t_ideal = 1/32768 356 + * 357 + * => t_measured / t_ideal = val * resolution + 1 358 + * 359 + * "offset" in the RTC interface is defined as: 360 + * t = t0 * (1 + offset * 1e-9) 361 + * where t is the desired period, t0 is the measured period with a zero 362 + * offset, which is t_measured above. With t0 = t_measured and t = t_ideal, 363 + * offset = (t_ideal / t_measured - 1) / 1e-9 364 + * 365 + * => t_ideal / t_measured = offset * 1e-9 + 1 366 + * 367 + * so: 368 + * 369 + * offset * 1e-9 + 1 = 1 / (val * resolution + 1) 370 + * 371 + * We want "resolution" to be an integer, so resolution = R * 1e-9, giving 372 + * offset = 1e18 / (val * R + 1e9) - 1e9 373 + * val = (1e18 / (offset + 1e9) - 1e9) / R 374 + * with a common transformation: 375 + * f(x) = 1e18 / (x + 1e9) - 1e9 376 + * offset = f(val * R) 377 + * val = f(offset) / R 378 + * 379 + * Armada 38x supports two modes, fine mode (954ppb) and coarse mode (3815ppb). 380 + */ 381 + static long armada38x_ppb_convert(long ppb) 382 + { 383 + long div = ppb + 1000000000L; 384 + 385 + return div_s64(1000000000000000000LL + div / 2, div) - 1000000000L; 386 + } 387 + 388 + static int armada38x_rtc_read_offset(struct device *dev, long *offset) 389 + { 390 + struct armada38x_rtc *rtc = dev_get_drvdata(dev); 391 + unsigned long ccr, flags; 392 + long ppb_cor; 393 + 394 + spin_lock_irqsave(&rtc->lock, flags); 395 + ccr = rtc->data->read_rtc_reg(rtc, RTC_CCR); 396 + spin_unlock_irqrestore(&rtc->lock, flags); 397 + 398 + ppb_cor = (ccr & RTC_CCR_MODE ? 3815 : 954) * (s8)ccr; 399 + /* ppb_cor + 1000000000L can never be zero */ 400 + *offset = armada38x_ppb_convert(ppb_cor); 401 + 402 + return 0; 403 + } 404 + 405 + static int armada38x_rtc_set_offset(struct device *dev, long offset) 406 + { 407 + struct armada38x_rtc *rtc = dev_get_drvdata(dev); 408 + unsigned long ccr = 0; 409 + long ppb_cor, off; 410 + 411 + /* 412 + * The maximum ppb_cor is -128 * 3815 .. 127 * 3815, but we 413 + * need to clamp the input. This equates to -484270 .. 488558. 414 + * Not only is this to stop out of range "off" but also to 415 + * avoid the division by zero in armada38x_ppb_convert(). 416 + */ 417 + offset = clamp(offset, -484270L, 488558L); 418 + 419 + ppb_cor = armada38x_ppb_convert(offset); 420 + 421 + /* 422 + * Use low update mode where possible, which gives a better 423 + * resolution of correction. 424 + */ 425 + off = DIV_ROUND_CLOSEST(ppb_cor, 954); 426 + if (off > 127 || off < -128) { 427 + ccr = RTC_CCR_MODE; 428 + off = DIV_ROUND_CLOSEST(ppb_cor, 3815); 429 + } 430 + 431 + /* 432 + * Armada 388 requires a bit pattern in bits 14..8 depending on 433 + * the sign bit: { 0, ~S, S, S, S, S, S } 434 + */ 435 + ccr |= (off & 0x3fff) ^ 0x2000; 436 + rtc_delayed_write(ccr, rtc, RTC_CCR); 437 + 438 + return 0; 439 + } 440 + 348 441 static const struct rtc_class_ops armada38x_rtc_ops = { 349 442 .read_time = armada38x_rtc_read_time, 350 443 .set_time = armada38x_rtc_set_time, 351 444 .read_alarm = armada38x_rtc_read_alarm, 352 445 .set_alarm = armada38x_rtc_set_alarm, 353 446 .alarm_irq_enable = armada38x_rtc_alarm_irq_enable, 447 + .read_offset = armada38x_rtc_read_offset, 448 + .set_offset = armada38x_rtc_set_offset, 354 449 }; 355 450 356 451 static const struct rtc_class_ops armada38x_rtc_ops_noirq = { 357 452 .read_time = armada38x_rtc_read_time, 358 453 .set_time = armada38x_rtc_set_time, 359 454 .read_alarm = armada38x_rtc_read_alarm, 455 + .read_offset = armada38x_rtc_read_offset, 456 + .set_offset = armada38x_rtc_set_offset, 360 457 }; 361 458 362 459 static const struct armada38x_rtc_data armada38x_data = {
+6 -13
drivers/rtc/rtc-at91rm9200.c
··· 42 42 #define at91_rtc_write(field, val) \ 43 43 writel_relaxed((val), at91_rtc_regs + field) 44 44 45 - #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 46 - 47 45 struct at91_rtc_config { 48 46 bool use_shadow_imr; 49 47 }; ··· 49 51 static const struct at91_rtc_config *at91_rtc_config; 50 52 static DECLARE_COMPLETION(at91_rtc_updated); 51 53 static DECLARE_COMPLETION(at91_rtc_upd_rdy); 52 - static unsigned int at91_alarm_year = AT91_RTC_EPOCH; 53 54 static void __iomem *at91_rtc_regs; 54 55 static int irq; 55 56 static DEFINE_SPINLOCK(at91_rtc_lock); ··· 128 131 129 132 /* 130 133 * The Calendar Alarm register does not have a field for 131 - * the year - so these will return an invalid value. When an 132 - * alarm is set, at91_alarm_year will store the current year. 134 + * the year - so these will return an invalid value. 133 135 */ 134 136 tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */ 135 137 tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */ ··· 204 208 struct rtc_time *tm = &alrm->time; 205 209 206 210 at91_rtc_decodetime(AT91_RTC_TIMALR, AT91_RTC_CALALR, tm); 207 - tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 208 - tm->tm_year = at91_alarm_year - 1900; 211 + tm->tm_year = -1; 209 212 210 213 alrm->enabled = (at91_rtc_read_imr() & AT91_RTC_ALARM) 211 214 ? 1 : 0; 212 215 213 - dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 214 - 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 215 - tm->tm_hour, tm->tm_min, tm->tm_sec); 216 + dev_dbg(dev, "%s(): %02d-%02d %02d:%02d:%02d %sabled\n", __func__, 217 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, 218 + alrm->enabled ? "en" : "dis"); 216 219 217 220 return 0; 218 221 } ··· 224 229 struct rtc_time tm; 225 230 226 231 at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, &tm); 227 - 228 - at91_alarm_year = tm.tm_year; 229 232 230 233 tm.tm_mon = alrm->time.tm_mon; 231 234 tm.tm_mday = alrm->time.tm_mday; ··· 248 255 } 249 256 250 257 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 251 - at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 258 + tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 252 259 tm.tm_min, tm.tm_sec); 253 260 254 261 return 0;
+29 -41
drivers/rtc/rtc-ds1305.c
··· 514 514 spi_message_add_tail(x, m); 515 515 } 516 516 517 - static ssize_t 518 - ds1305_nvram_read(struct file *filp, struct kobject *kobj, 519 - struct bin_attribute *attr, 520 - char *buf, loff_t off, size_t count) 517 + static int ds1305_nvram_read(void *priv, unsigned int off, void *buf, 518 + size_t count) 521 519 { 522 - struct spi_device *spi; 520 + struct ds1305 *ds1305 = priv; 521 + struct spi_device *spi = ds1305->spi; 523 522 u8 addr; 524 523 struct spi_message m; 525 524 struct spi_transfer x[2]; 526 - int status; 527 - 528 - spi = to_spi_device(kobj_to_dev(kobj)); 529 525 530 526 addr = DS1305_NVRAM + off; 531 527 msg_init(&m, x, &addr, count, NULL, buf); 532 528 533 - status = spi_sync(spi, &m); 534 - if (status < 0) 535 - dev_err(&spi->dev, "nvram %s error %d\n", "read", status); 536 - return (status < 0) ? status : count; 529 + return spi_sync(spi, &m); 537 530 } 538 531 539 - static ssize_t 540 - ds1305_nvram_write(struct file *filp, struct kobject *kobj, 541 - struct bin_attribute *attr, 542 - char *buf, loff_t off, size_t count) 532 + static int ds1305_nvram_write(void *priv, unsigned int off, void *buf, 533 + size_t count) 543 534 { 544 - struct spi_device *spi; 535 + struct ds1305 *ds1305 = priv; 536 + struct spi_device *spi = ds1305->spi; 545 537 u8 addr; 546 538 struct spi_message m; 547 539 struct spi_transfer x[2]; 548 - int status; 549 - 550 - spi = to_spi_device(kobj_to_dev(kobj)); 551 540 552 541 addr = (DS1305_WRITE | DS1305_NVRAM) + off; 553 542 msg_init(&m, x, &addr, count, buf, NULL); 554 543 555 - status = spi_sync(spi, &m); 556 - if (status < 0) 557 - dev_err(&spi->dev, "nvram %s error %d\n", "write", status); 558 - return (status < 0) ? status : count; 544 + return spi_sync(spi, &m); 559 545 } 560 546 561 - static struct bin_attribute nvram = { 562 - .attr.name = "nvram", 563 - .attr.mode = S_IRUGO | S_IWUSR, 564 - .read = ds1305_nvram_read, 565 - .write = ds1305_nvram_write, 566 - .size = DS1305_NVRAM_LEN, 547 + static struct nvmem_config ds1305_nvmem_cfg = { 548 + .name = "ds1305_nvram", 549 + .word_size = 1, 550 + .stride = 1, 551 + .size = DS1305_NVRAM_LEN, 552 + .reg_read = ds1305_nvram_read, 553 + .reg_write = ds1305_nvram_write, 567 554 }; 568 555 569 556 /*----------------------------------------------------------------------*/ ··· 695 708 dev_dbg(&spi->dev, "AM/PM\n"); 696 709 697 710 /* register RTC ... from here on, ds1305->ctrl needs locking */ 698 - ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305", 699 - &ds1305_ops, THIS_MODULE); 711 + ds1305->rtc = devm_rtc_allocate_device(&spi->dev); 700 712 if (IS_ERR(ds1305->rtc)) { 701 - status = PTR_ERR(ds1305->rtc); 713 + return PTR_ERR(ds1305->rtc); 714 + } 715 + 716 + ds1305->rtc->ops = &ds1305_ops; 717 + 718 + ds1305_nvmem_cfg.priv = ds1305; 719 + ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg; 720 + ds1305->rtc->nvram_old_abi = true; 721 + 722 + status = rtc_register_device(ds1305->rtc); 723 + if (status) { 702 724 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 703 725 return status; 704 726 } ··· 730 734 } 731 735 } 732 736 733 - /* export NVRAM */ 734 - status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); 735 - if (status < 0) { 736 - dev_err(&spi->dev, "register nvram --> %d\n", status); 737 - } 738 - 739 737 return 0; 740 738 } 741 739 742 740 static int ds1305_remove(struct spi_device *spi) 743 741 { 744 742 struct ds1305 *ds1305 = spi_get_drvdata(spi); 745 - 746 - sysfs_remove_bin_file(&spi->dev.kobj, &nvram); 747 743 748 744 /* carefully shut down irq and workqueue, if present */ 749 745 if (spi->irq) {
+31 -26
drivers/rtc/rtc-ds1307.c
··· 325 325 .compatible = "isil,isl12057", 326 326 .data = (void *)ds_1337 327 327 }, 328 + { 329 + .compatible = "epson,rx8130", 330 + .data = (void *)rx_8130 331 + }, 328 332 { } 329 333 }; 330 334 MODULE_DEVICE_TABLE(of, ds1307_of_match); ··· 352 348 { .id = "PT7C4338", .driver_data = ds_1307 }, 353 349 { .id = "RX8025", .driver_data = rx_8025 }, 354 350 { .id = "ISL12057", .driver_data = ds_1337 }, 351 + { .id = "RX8130", .driver_data = rx_8130 }, 355 352 { } 356 353 }; 357 354 MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids); ··· 792 787 * Alarm support for mcp794xx devices. 793 788 */ 794 789 795 - #define MCP794XX_REG_WEEKDAY 0x3 796 - #define MCP794XX_REG_WEEKDAY_WDAY_MASK 0x7 797 790 #define MCP794XX_REG_CONTROL 0x07 798 791 # define MCP794XX_BIT_ALM0_EN 0x10 799 792 # define MCP794XX_BIT_ALM1_EN 0x20 ··· 880 877 return 0; 881 878 } 882 879 880 + /* 881 + * We may have a random RTC weekday, therefore calculate alarm weekday based 882 + * on current weekday we read from the RTC timekeeping regs 883 + */ 884 + static int mcp794xx_alm_weekday(struct device *dev, struct rtc_time *tm_alarm) 885 + { 886 + struct rtc_time tm_now; 887 + int days_now, days_alarm, ret; 888 + 889 + ret = ds1307_get_time(dev, &tm_now); 890 + if (ret) 891 + return ret; 892 + 893 + days_now = div_s64(rtc_tm_to_time64(&tm_now), 24 * 60 * 60); 894 + days_alarm = div_s64(rtc_tm_to_time64(tm_alarm), 24 * 60 * 60); 895 + 896 + return (tm_now.tm_wday + days_alarm - days_now) % 7 + 1; 897 + } 898 + 883 899 static int mcp794xx_set_alarm(struct device *dev, struct rtc_wkalrm *t) 884 900 { 885 901 struct ds1307 *ds1307 = dev_get_drvdata(dev); 886 902 unsigned char regs[10]; 887 - int ret; 903 + int wday, ret; 888 904 889 905 if (!test_bit(HAS_ALARM, &ds1307->flags)) 890 906 return -EINVAL; 907 + 908 + wday = mcp794xx_alm_weekday(dev, &t->time); 909 + if (wday < 0) 910 + return wday; 891 911 892 912 dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d " 893 913 "enabled=%d pending=%d\n", __func__, ··· 928 902 regs[3] = bin2bcd(t->time.tm_sec); 929 903 regs[4] = bin2bcd(t->time.tm_min); 930 904 regs[5] = bin2bcd(t->time.tm_hour); 931 - regs[6] = bin2bcd(t->time.tm_wday + 1); 905 + regs[6] = wday; 932 906 regs[7] = bin2bcd(t->time.tm_mday); 933 907 regs[8] = bin2bcd(t->time.tm_mon + 1); 934 908 ··· 1380 1354 { 1381 1355 struct ds1307 *ds1307; 1382 1356 int err = -ENODEV; 1383 - int tmp, wday; 1357 + int tmp; 1384 1358 const struct chip_desc *chip; 1385 1359 bool want_irq; 1386 1360 bool ds1307_can_wakeup_device = false; 1387 1361 unsigned char regs[8]; 1388 1362 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); 1389 - struct rtc_time tm; 1390 - unsigned long timestamp; 1391 1363 u8 trickle_charger_setup = 0; 1392 1364 1393 1365 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); ··· 1664 1640 regmap_write(ds1307->regmap, chip->offset + DS1307_REG_HOUR, 1665 1641 bin2bcd(tmp)); 1666 1642 } 1667 - 1668 - /* 1669 - * Some IPs have weekday reset value = 0x1 which might not correct 1670 - * hence compute the wday using the current date/month/year values 1671 - */ 1672 - ds1307_get_time(ds1307->dev, &tm); 1673 - wday = tm.tm_wday; 1674 - timestamp = rtc_tm_to_time64(&tm); 1675 - rtc_time64_to_tm(timestamp, &tm); 1676 - 1677 - /* 1678 - * Check if reset wday is different from the computed wday 1679 - * If different then set the wday which we computed using 1680 - * timestamp 1681 - */ 1682 - if (wday != tm.tm_wday) 1683 - regmap_update_bits(ds1307->regmap, MCP794XX_REG_WEEKDAY, 1684 - MCP794XX_REG_WEEKDAY_WDAY_MASK, 1685 - tm.tm_wday + 1); 1686 1643 1687 1644 if (want_irq || ds1307_can_wakeup_device) { 1688 1645 device_set_wakeup_capable(ds1307->dev, true);
+7
drivers/rtc/rtc-ds1390.c
··· 216 216 return res; 217 217 } 218 218 219 + static const struct of_device_id ds1390_of_match[] = { 220 + { .compatible = "dallas,ds1390" }, 221 + {} 222 + }; 223 + MODULE_DEVICE_TABLE(of, ds1390_of_match); 224 + 219 225 static struct spi_driver ds1390_driver = { 220 226 .driver = { 221 227 .name = "rtc-ds1390", 228 + .of_match_table = of_match_ptr(ds1390_of_match), 222 229 }, 223 230 .probe = ds1390_probe, 224 231 };
+29 -46
drivers/rtc/rtc-ds1511.c
··· 398 398 .alarm_irq_enable = ds1511_rtc_alarm_irq_enable, 399 399 }; 400 400 401 - static ssize_t 402 - ds1511_nvram_read(struct file *filp, struct kobject *kobj, 403 - struct bin_attribute *ba, 404 - char *buf, loff_t pos, size_t size) 401 + static int ds1511_nvram_read(void *priv, unsigned int pos, void *buf, 402 + size_t size) 405 403 { 406 - ssize_t count; 404 + int i; 407 405 408 406 rtc_write(pos, DS1511_RAMADDR_LSB); 409 - for (count = 0; count < size; count++) 410 - *buf++ = rtc_read(DS1511_RAMDATA); 407 + for (i = 0; i < size; i++) 408 + *(char *)buf++ = rtc_read(DS1511_RAMDATA); 411 409 412 - return count; 410 + return 0; 413 411 } 414 412 415 - static ssize_t 416 - ds1511_nvram_write(struct file *filp, struct kobject *kobj, 417 - struct bin_attribute *bin_attr, 418 - char *buf, loff_t pos, size_t size) 413 + static int ds1511_nvram_write(void *priv, unsigned int pos, void *buf, 414 + size_t size) 419 415 { 420 - ssize_t count; 416 + int i; 421 417 422 418 rtc_write(pos, DS1511_RAMADDR_LSB); 423 - for (count = 0; count < size; count++) 424 - rtc_write(*buf++, DS1511_RAMDATA); 419 + for (i = 0; i < size; i++) 420 + rtc_write(*(char *)buf++, DS1511_RAMDATA); 425 421 426 - return count; 422 + return 0; 427 423 } 428 424 429 - static struct bin_attribute ds1511_nvram_attr = { 430 - .attr = { 431 - .name = "nvram", 432 - .mode = S_IRUGO | S_IWUSR, 433 - }, 425 + static struct nvmem_config ds1511_nvmem_cfg = { 426 + .name = "ds1511_nvram", 427 + .word_size = 1, 428 + .stride = 1, 434 429 .size = DS1511_RAM_MAX, 435 - .read = ds1511_nvram_read, 436 - .write = ds1511_nvram_write, 430 + .reg_read = ds1511_nvram_read, 431 + .reg_write = ds1511_nvram_write, 437 432 }; 438 433 439 434 static int ds1511_rtc_probe(struct platform_device *pdev) ··· 472 477 spin_lock_init(&pdata->lock); 473 478 platform_set_drvdata(pdev, pdata); 474 479 475 - pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 476 - &ds1511_rtc_ops, THIS_MODULE); 480 + pdata->rtc = devm_rtc_allocate_device(&pdev->dev); 477 481 if (IS_ERR(pdata->rtc)) 478 482 return PTR_ERR(pdata->rtc); 483 + 484 + pdata->rtc->ops = &ds1511_rtc_ops; 485 + 486 + ds1511_nvmem_cfg.priv = &pdev->dev; 487 + pdata->rtc->nvmem_config = &ds1511_nvmem_cfg; 488 + pdata->rtc->nvram_old_abi = true; 489 + 490 + ret = rtc_register_device(pdata->rtc); 491 + if (ret) 492 + return ret; 479 493 480 494 /* 481 495 * if the platform has an interrupt in mind for this device, ··· 500 496 } 501 497 } 502 498 503 - ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 504 - if (ret) 505 - dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n", 506 - ds1511_nvram_attr.attr.name); 507 - 508 - return 0; 509 - } 510 - 511 - static int ds1511_rtc_remove(struct platform_device *pdev) 512 - { 513 - struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 514 - 515 - sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 516 - if (pdata->irq > 0) { 517 - /* 518 - * disable the alarm interrupt 519 - */ 520 - rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD); 521 - rtc_read(RTC_CMD1); 522 - } 523 499 return 0; 524 500 } 525 501 ··· 508 524 509 525 static struct platform_driver ds1511_rtc_driver = { 510 526 .probe = ds1511_rtc_probe, 511 - .remove = ds1511_rtc_remove, 512 527 .driver = { 513 528 .name = "ds1511", 514 529 },
+3 -3
drivers/rtc/rtc-jz4740.c
··· 82 82 static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc) 83 83 { 84 84 uint32_t ctrl; 85 - int timeout = 1000; 85 + int timeout = 10000; 86 86 87 87 do { 88 88 ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL); ··· 94 94 static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc) 95 95 { 96 96 uint32_t ctrl; 97 - int ret, timeout = 1000; 97 + int ret, timeout = 10000; 98 98 99 99 ret = jz4740_rtc_wait_write_ready(rtc); 100 100 if (ret != 0) ··· 368 368 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678); 369 369 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); 370 370 if (ret) { 371 - dev_err(&pdev->dev, "Could not write write to RTC registers\n"); 371 + dev_err(&pdev->dev, "Could not write to RTC registers\n"); 372 372 return ret; 373 373 } 374 374 }
+37 -47
drivers/rtc/rtc-m41t80.c
··· 154 154 struct rtc_device *rtc; 155 155 #ifdef CONFIG_COMMON_CLK 156 156 struct clk_hw sqw; 157 + unsigned long freq; 158 + unsigned int sqwe; 157 159 #endif 158 160 }; 159 161 ··· 445 443 #ifdef CONFIG_COMMON_CLK 446 444 #define sqw_to_m41t80_data(_hw) container_of(_hw, struct m41t80_data, sqw) 447 445 448 - static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw, 449 - unsigned long parent_rate) 446 + static unsigned long m41t80_decode_freq(int setting) 450 447 { 451 - struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 448 + return (setting == 0) ? 0 : (setting == 1) ? M41T80_SQW_MAX_FREQ : 449 + M41T80_SQW_MAX_FREQ >> setting; 450 + } 451 + 452 + static unsigned long m41t80_get_freq(struct m41t80_data *m41t80) 453 + { 452 454 struct i2c_client *client = m41t80->client; 453 455 int reg_sqw = (m41t80->features & M41T80_FEATURE_SQ_ALT) ? 454 456 M41T80_REG_WDAY : M41T80_REG_SQW; 455 457 int ret = i2c_smbus_read_byte_data(client, reg_sqw); 456 - unsigned long val = M41T80_SQW_MAX_FREQ; 457 458 458 459 if (ret < 0) 459 460 return 0; 461 + return m41t80_decode_freq(ret >> 4); 462 + } 460 463 461 - ret >>= 4; 462 - if (ret == 0) 463 - val = 0; 464 - else if (ret > 1) 465 - val = val / (1 << ret); 466 - 467 - return val; 464 + static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw, 465 + unsigned long parent_rate) 466 + { 467 + return sqw_to_m41t80_data(hw)->freq; 468 468 } 469 469 470 470 static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate, 471 471 unsigned long *prate) 472 472 { 473 - int i, freq = M41T80_SQW_MAX_FREQ; 474 - 475 - if (freq <= rate) 476 - return freq; 477 - 478 - for (i = 2; i <= ilog2(M41T80_SQW_MAX_FREQ); i++) { 479 - freq /= 1 << i; 480 - if (freq <= rate) 481 - return freq; 482 - } 483 - 484 - return 0; 473 + if (rate >= M41T80_SQW_MAX_FREQ) 474 + return M41T80_SQW_MAX_FREQ; 475 + if (rate >= M41T80_SQW_MAX_FREQ / 4) 476 + return M41T80_SQW_MAX_FREQ / 4; 477 + if (!rate) 478 + return 0; 479 + return 1 << ilog2(rate); 485 480 } 486 481 487 482 static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate, ··· 490 491 M41T80_REG_WDAY : M41T80_REG_SQW; 491 492 int reg, ret, val = 0; 492 493 493 - if (rate) { 494 - if (!is_power_of_2(rate)) 495 - return -EINVAL; 496 - val = ilog2(rate); 497 - if (val == ilog2(M41T80_SQW_MAX_FREQ)) 498 - val = 1; 499 - else if (val < (ilog2(M41T80_SQW_MAX_FREQ) - 1)) 500 - val = ilog2(M41T80_SQW_MAX_FREQ) - val; 501 - else 502 - return -EINVAL; 503 - } 494 + if (rate >= M41T80_SQW_MAX_FREQ) 495 + val = 1; 496 + else if (rate >= M41T80_SQW_MAX_FREQ / 4) 497 + val = 2; 498 + else if (rate) 499 + val = 15 - ilog2(rate); 504 500 505 501 reg = i2c_smbus_read_byte_data(client, reg_sqw); 506 502 if (reg < 0) ··· 504 510 reg = (reg & 0x0f) | (val << 4); 505 511 506 512 ret = i2c_smbus_write_byte_data(client, reg_sqw, reg); 507 - if (ret < 0) 508 - return ret; 509 - 510 - return -EINVAL; 513 + if (!ret) 514 + m41t80->freq = m41t80_decode_freq(val); 515 + return ret; 511 516 } 512 517 513 518 static int m41t80_sqw_control(struct clk_hw *hw, bool enable) ··· 523 530 else 524 531 ret &= ~M41T80_ALMON_SQWE; 525 532 526 - return i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, ret); 533 + ret = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, ret); 534 + if (!ret) 535 + m41t80->sqwe = enable; 536 + return ret; 527 537 } 528 538 529 539 static int m41t80_sqw_prepare(struct clk_hw *hw) ··· 541 545 542 546 static int m41t80_sqw_is_prepared(struct clk_hw *hw) 543 547 { 544 - struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw); 545 - struct i2c_client *client = m41t80->client; 546 - int ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); 547 - 548 - if (ret < 0) 549 - return ret; 550 - 551 - return !!(ret & M41T80_ALMON_SQWE); 548 + return sqw_to_m41t80_data(hw)->sqwe; 552 549 } 553 550 554 551 static const struct clk_ops m41t80_sqw_ops = { ··· 576 587 init.parent_names = NULL; 577 588 init.num_parents = 0; 578 589 m41t80->sqw.init = &init; 590 + m41t80->freq = m41t80_get_freq(m41t80); 579 591 580 592 /* optional override of the clockname */ 581 593 of_property_read_string(node, "clock-output-names", &init.name);
+31 -27
drivers/rtc/rtc-m48t86.c
··· 163 163 .proc = m48t86_rtc_proc, 164 164 }; 165 165 166 - static ssize_t m48t86_nvram_read(struct file *filp, struct kobject *kobj, 167 - struct bin_attribute *attr, 168 - char *buf, loff_t off, size_t count) 166 + static int m48t86_nvram_read(void *priv, unsigned int off, void *buf, 167 + size_t count) 169 168 { 170 - struct device *dev = kobj_to_dev(kobj); 169 + struct device *dev = priv; 171 170 unsigned int i; 172 171 173 172 for (i = 0; i < count; i++) 174 - buf[i] = m48t86_readb(dev, M48T86_NVRAM(off + i)); 173 + ((u8 *)buf)[i] = m48t86_readb(dev, M48T86_NVRAM(off + i)); 175 174 176 - return count; 175 + return 0; 177 176 } 178 177 179 - static ssize_t m48t86_nvram_write(struct file *filp, struct kobject *kobj, 180 - struct bin_attribute *attr, 181 - char *buf, loff_t off, size_t count) 178 + static int m48t86_nvram_write(void *priv, unsigned int off, void *buf, 179 + size_t count) 182 180 { 183 - struct device *dev = kobj_to_dev(kobj); 181 + struct device *dev = priv; 184 182 unsigned int i; 185 183 186 184 for (i = 0; i < count; i++) 187 - m48t86_writeb(dev, buf[i], M48T86_NVRAM(off + i)); 185 + m48t86_writeb(dev, ((u8 *)buf)[i], M48T86_NVRAM(off + i)); 188 186 189 - return count; 187 + return 0; 190 188 } 191 - 192 - static BIN_ATTR(nvram, 0644, m48t86_nvram_read, m48t86_nvram_write, 193 - M48T86_NVRAM_LEN); 194 189 195 190 /* 196 191 * The RTC is an optional feature at purchase time on some Technologic Systems ··· 218 223 return false; 219 224 } 220 225 226 + static struct nvmem_config m48t86_nvmem_cfg = { 227 + .name = "m48t86_nvram", 228 + .word_size = 1, 229 + .stride = 1, 230 + .size = M48T86_NVRAM_LEN, 231 + .reg_read = m48t86_nvram_read, 232 + .reg_write = m48t86_nvram_write, 233 + }; 234 + 221 235 static int m48t86_rtc_probe(struct platform_device *pdev) 222 236 { 223 237 struct m48t86_rtc_info *info; 224 238 struct resource *res; 225 239 unsigned char reg; 240 + int err; 226 241 227 242 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 228 243 if (!info) ··· 259 254 return -ENODEV; 260 255 } 261 256 262 - info->rtc = devm_rtc_device_register(&pdev->dev, "m48t86", 263 - &m48t86_rtc_ops, THIS_MODULE); 257 + info->rtc = devm_rtc_allocate_device(&pdev->dev); 264 258 if (IS_ERR(info->rtc)) 265 259 return PTR_ERR(info->rtc); 260 + 261 + info->rtc->ops = &m48t86_rtc_ops; 262 + 263 + m48t86_nvmem_cfg.priv = &pdev->dev; 264 + info->rtc->nvmem_config = &m48t86_nvmem_cfg; 265 + info->rtc->nvram_old_abi = true; 266 + 267 + err = rtc_register_device(info->rtc); 268 + if (err) 269 + return err; 266 270 267 271 /* read battery status */ 268 272 reg = m48t86_readb(&pdev->dev, M48T86_D); 269 273 dev_info(&pdev->dev, "battery %s\n", 270 274 (reg & M48T86_D_VRT) ? "ok" : "exhausted"); 271 275 272 - if (device_create_bin_file(&pdev->dev, &bin_attr_nvram)) 273 - dev_err(&pdev->dev, "failed to create nvram sysfs entry\n"); 274 - 275 - return 0; 276 - } 277 - 278 - static int m48t86_rtc_remove(struct platform_device *pdev) 279 - { 280 - device_remove_bin_file(&pdev->dev, &bin_attr_nvram); 281 276 return 0; 282 277 } 283 278 ··· 286 281 .name = "rtc-m48t86", 287 282 }, 288 283 .probe = m48t86_rtc_probe, 289 - .remove = m48t86_rtc_remove, 290 284 }; 291 285 292 286 module_platform_driver(m48t86_rtc_platform_driver);
+422
drivers/rtc/rtc-mt7622.c
··· 1 + /* 2 + * Driver for MediaTek SoC based RTC 3 + * 4 + * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com> 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License as 8 + * published by the Free Software Foundation; either version 2 of 9 + * the License, or (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/clk.h> 18 + #include <linux/interrupt.h> 19 + #include <linux/module.h> 20 + #include <linux/of_address.h> 21 + #include <linux/of_device.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/rtc.h> 24 + 25 + #define MTK_RTC_DEV KBUILD_MODNAME 26 + 27 + #define MTK_RTC_PWRCHK1 0x4 28 + #define RTC_PWRCHK1_MAGIC 0xc6 29 + 30 + #define MTK_RTC_PWRCHK2 0x8 31 + #define RTC_PWRCHK2_MAGIC 0x9a 32 + 33 + #define MTK_RTC_KEY 0xc 34 + #define RTC_KEY_MAGIC 0x59 35 + 36 + #define MTK_RTC_PROT1 0x10 37 + #define RTC_PROT1_MAGIC 0xa3 38 + 39 + #define MTK_RTC_PROT2 0x14 40 + #define RTC_PROT2_MAGIC 0x57 41 + 42 + #define MTK_RTC_PROT3 0x18 43 + #define RTC_PROT3_MAGIC 0x67 44 + 45 + #define MTK_RTC_PROT4 0x1c 46 + #define RTC_PROT4_MAGIC 0xd2 47 + 48 + #define MTK_RTC_CTL 0x20 49 + #define RTC_RC_STOP BIT(0) 50 + 51 + #define MTK_RTC_DEBNCE 0x2c 52 + #define RTC_DEBNCE_MASK GENMASK(2, 0) 53 + 54 + #define MTK_RTC_INT 0x30 55 + #define RTC_INT_AL_STA BIT(4) 56 + 57 + /* 58 + * Ranges from 0x40 to 0x78 provide RTC time setup for year, month, 59 + * day of month, day of week, hour, minute and second. 60 + */ 61 + #define MTK_RTC_TREG(_t, _f) (0x40 + (0x4 * (_f)) + ((_t) * 0x20)) 62 + 63 + #define MTK_RTC_AL_CTL 0x7c 64 + #define RTC_AL_EN BIT(0) 65 + #define RTC_AL_ALL GENMASK(7, 0) 66 + 67 + /* 68 + * The offset is used in the translation for the year between in struct 69 + * rtc_time and in hardware register MTK_RTC_TREG(x,MTK_YEA) 70 + */ 71 + #define MTK_RTC_TM_YR_OFFSET 100 72 + 73 + /* 74 + * The lowest value for the valid tm_year. RTC hardware would take incorrectly 75 + * tm_year 100 as not a leap year and thus it is also required being excluded 76 + * from the valid options. 77 + */ 78 + #define MTK_RTC_TM_YR_L (MTK_RTC_TM_YR_OFFSET + 1) 79 + 80 + /* 81 + * The most year the RTC can hold is 99 and the next to 99 in year register 82 + * would be wraparound to 0, for MT7622. 83 + */ 84 + #define MTK_RTC_HW_YR_LIMIT 99 85 + 86 + /* The highest value for the valid tm_year */ 87 + #define MTK_RTC_TM_YR_H (MTK_RTC_TM_YR_OFFSET + MTK_RTC_HW_YR_LIMIT) 88 + 89 + /* Simple macro helps to check whether the hardware supports the tm_year */ 90 + #define MTK_RTC_TM_YR_VALID(_y) ((_y) >= MTK_RTC_TM_YR_L && \ 91 + (_y) <= MTK_RTC_TM_YR_H) 92 + 93 + /* Types of the function the RTC provides are time counter and alarm. */ 94 + enum { 95 + MTK_TC, 96 + MTK_AL, 97 + }; 98 + 99 + /* Indexes are used for the pointer to relevant registers in MTK_RTC_TREG */ 100 + enum { 101 + MTK_YEA, 102 + MTK_MON, 103 + MTK_DOM, 104 + MTK_DOW, 105 + MTK_HOU, 106 + MTK_MIN, 107 + MTK_SEC 108 + }; 109 + 110 + struct mtk_rtc { 111 + struct rtc_device *rtc; 112 + void __iomem *base; 113 + int irq; 114 + struct clk *clk; 115 + }; 116 + 117 + static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val) 118 + { 119 + writel_relaxed(val, rtc->base + reg); 120 + } 121 + 122 + static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg) 123 + { 124 + return readl_relaxed(rtc->base + reg); 125 + } 126 + 127 + static void mtk_rmw(struct mtk_rtc *rtc, u32 reg, u32 mask, u32 set) 128 + { 129 + u32 val; 130 + 131 + val = mtk_r32(rtc, reg); 132 + val &= ~mask; 133 + val |= set; 134 + mtk_w32(rtc, reg, val); 135 + } 136 + 137 + static void mtk_set(struct mtk_rtc *rtc, u32 reg, u32 val) 138 + { 139 + mtk_rmw(rtc, reg, 0, val); 140 + } 141 + 142 + static void mtk_clr(struct mtk_rtc *rtc, u32 reg, u32 val) 143 + { 144 + mtk_rmw(rtc, reg, val, 0); 145 + } 146 + 147 + static void mtk_rtc_hw_init(struct mtk_rtc *hw) 148 + { 149 + /* The setup of the init sequence is for allowing RTC got to work */ 150 + mtk_w32(hw, MTK_RTC_PWRCHK1, RTC_PWRCHK1_MAGIC); 151 + mtk_w32(hw, MTK_RTC_PWRCHK2, RTC_PWRCHK2_MAGIC); 152 + mtk_w32(hw, MTK_RTC_KEY, RTC_KEY_MAGIC); 153 + mtk_w32(hw, MTK_RTC_PROT1, RTC_PROT1_MAGIC); 154 + mtk_w32(hw, MTK_RTC_PROT2, RTC_PROT2_MAGIC); 155 + mtk_w32(hw, MTK_RTC_PROT3, RTC_PROT3_MAGIC); 156 + mtk_w32(hw, MTK_RTC_PROT4, RTC_PROT4_MAGIC); 157 + mtk_rmw(hw, MTK_RTC_DEBNCE, RTC_DEBNCE_MASK, 0); 158 + mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP); 159 + } 160 + 161 + static void mtk_rtc_get_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm, 162 + int time_alarm) 163 + { 164 + u32 year, mon, mday, wday, hour, min, sec; 165 + 166 + /* 167 + * Read again until the field of the second is not changed which 168 + * ensures all fields in the consistent state. Note that MTK_SEC must 169 + * be read first. In this way, it guarantees the others remain not 170 + * changed when the results for two MTK_SEC consecutive reads are same. 171 + */ 172 + do { 173 + sec = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC)); 174 + min = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN)); 175 + hour = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU)); 176 + wday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW)); 177 + mday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM)); 178 + mon = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON)); 179 + year = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA)); 180 + } while (sec != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC))); 181 + 182 + tm->tm_sec = sec; 183 + tm->tm_min = min; 184 + tm->tm_hour = hour; 185 + tm->tm_wday = wday; 186 + tm->tm_mday = mday; 187 + tm->tm_mon = mon - 1; 188 + 189 + /* Rebase to the absolute year which userspace queries */ 190 + tm->tm_year = year + MTK_RTC_TM_YR_OFFSET; 191 + } 192 + 193 + static void mtk_rtc_set_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm, 194 + int time_alarm) 195 + { 196 + u32 year; 197 + 198 + /* Rebase to the relative year which RTC hardware requires */ 199 + year = tm->tm_year - MTK_RTC_TM_YR_OFFSET; 200 + 201 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA), year); 202 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_MON), tm->tm_mon + 1); 203 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW), tm->tm_wday); 204 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM), tm->tm_mday); 205 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU), tm->tm_hour); 206 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN), tm->tm_min); 207 + mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC), tm->tm_sec); 208 + } 209 + 210 + static irqreturn_t mtk_rtc_alarmirq(int irq, void *id) 211 + { 212 + struct mtk_rtc *hw = (struct mtk_rtc *)id; 213 + u32 irq_sta; 214 + 215 + irq_sta = mtk_r32(hw, MTK_RTC_INT); 216 + if (irq_sta & RTC_INT_AL_STA) { 217 + /* Stop alarm also implicitly disables the alarm interrupt */ 218 + mtk_w32(hw, MTK_RTC_AL_CTL, 0); 219 + rtc_update_irq(hw->rtc, 1, RTC_IRQF | RTC_AF); 220 + 221 + /* Ack alarm interrupt status */ 222 + mtk_w32(hw, MTK_RTC_INT, RTC_INT_AL_STA); 223 + return IRQ_HANDLED; 224 + } 225 + 226 + return IRQ_NONE; 227 + } 228 + 229 + static int mtk_rtc_gettime(struct device *dev, struct rtc_time *tm) 230 + { 231 + struct mtk_rtc *hw = dev_get_drvdata(dev); 232 + 233 + mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC); 234 + 235 + return rtc_valid_tm(tm); 236 + } 237 + 238 + static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm) 239 + { 240 + struct mtk_rtc *hw = dev_get_drvdata(dev); 241 + 242 + if (!MTK_RTC_TM_YR_VALID(tm->tm_year)) 243 + return -EINVAL; 244 + 245 + /* Stop time counter before setting a new one*/ 246 + mtk_set(hw, MTK_RTC_CTL, RTC_RC_STOP); 247 + 248 + mtk_rtc_set_alarm_or_time(hw, tm, MTK_TC); 249 + 250 + /* Restart the time counter */ 251 + mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP); 252 + 253 + return 0; 254 + } 255 + 256 + static int mtk_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm) 257 + { 258 + struct mtk_rtc *hw = dev_get_drvdata(dev); 259 + struct rtc_time *alrm_tm = &wkalrm->time; 260 + 261 + mtk_rtc_get_alarm_or_time(hw, alrm_tm, MTK_AL); 262 + 263 + wkalrm->enabled = !!(mtk_r32(hw, MTK_RTC_AL_CTL) & RTC_AL_EN); 264 + wkalrm->pending = !!(mtk_r32(hw, MTK_RTC_INT) & RTC_INT_AL_STA); 265 + 266 + return 0; 267 + } 268 + 269 + static int mtk_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm) 270 + { 271 + struct mtk_rtc *hw = dev_get_drvdata(dev); 272 + struct rtc_time *alrm_tm = &wkalrm->time; 273 + 274 + if (!MTK_RTC_TM_YR_VALID(alrm_tm->tm_year)) 275 + return -EINVAL; 276 + 277 + /* 278 + * Stop the alarm also implicitly including disables interrupt before 279 + * setting a new one. 280 + */ 281 + mtk_clr(hw, MTK_RTC_AL_CTL, RTC_AL_EN); 282 + 283 + /* 284 + * Avoid contention between mtk_rtc_setalarm and IRQ handler so that 285 + * disabling the interrupt and awaiting for pending IRQ handler to 286 + * complete. 287 + */ 288 + synchronize_irq(hw->irq); 289 + 290 + mtk_rtc_set_alarm_or_time(hw, alrm_tm, MTK_AL); 291 + 292 + /* Restart the alarm with the new setup */ 293 + mtk_w32(hw, MTK_RTC_AL_CTL, RTC_AL_ALL); 294 + 295 + return 0; 296 + } 297 + 298 + static const struct rtc_class_ops mtk_rtc_ops = { 299 + .read_time = mtk_rtc_gettime, 300 + .set_time = mtk_rtc_settime, 301 + .read_alarm = mtk_rtc_getalarm, 302 + .set_alarm = mtk_rtc_setalarm, 303 + }; 304 + 305 + static const struct of_device_id mtk_rtc_match[] = { 306 + { .compatible = "mediatek,mt7622-rtc" }, 307 + { .compatible = "mediatek,soc-rtc" }, 308 + {}, 309 + }; 310 + 311 + static int mtk_rtc_probe(struct platform_device *pdev) 312 + { 313 + struct mtk_rtc *hw; 314 + struct resource *res; 315 + int ret; 316 + 317 + hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL); 318 + if (!hw) 319 + return -ENOMEM; 320 + 321 + platform_set_drvdata(pdev, hw); 322 + 323 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 324 + hw->base = devm_ioremap_resource(&pdev->dev, res); 325 + if (IS_ERR(hw->base)) 326 + return PTR_ERR(hw->base); 327 + 328 + hw->clk = devm_clk_get(&pdev->dev, "rtc"); 329 + if (IS_ERR(hw->clk)) { 330 + dev_err(&pdev->dev, "No clock\n"); 331 + return PTR_ERR(hw->clk); 332 + } 333 + 334 + ret = clk_prepare_enable(hw->clk); 335 + if (ret) 336 + return ret; 337 + 338 + hw->irq = platform_get_irq(pdev, 0); 339 + if (hw->irq < 0) { 340 + dev_err(&pdev->dev, "No IRQ resource\n"); 341 + ret = hw->irq; 342 + goto err; 343 + } 344 + 345 + ret = devm_request_irq(&pdev->dev, hw->irq, mtk_rtc_alarmirq, 346 + 0, dev_name(&pdev->dev), hw); 347 + if (ret) { 348 + dev_err(&pdev->dev, "Can't request IRQ\n"); 349 + goto err; 350 + } 351 + 352 + mtk_rtc_hw_init(hw); 353 + 354 + device_init_wakeup(&pdev->dev, true); 355 + 356 + hw->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 357 + &mtk_rtc_ops, THIS_MODULE); 358 + if (IS_ERR(hw->rtc)) { 359 + ret = PTR_ERR(hw->rtc); 360 + dev_err(&pdev->dev, "Unable to register device\n"); 361 + goto err; 362 + } 363 + 364 + return 0; 365 + err: 366 + clk_disable_unprepare(hw->clk); 367 + 368 + return ret; 369 + } 370 + 371 + static int mtk_rtc_remove(struct platform_device *pdev) 372 + { 373 + struct mtk_rtc *hw = platform_get_drvdata(pdev); 374 + 375 + clk_disable_unprepare(hw->clk); 376 + 377 + return 0; 378 + } 379 + 380 + #ifdef CONFIG_PM_SLEEP 381 + static int mtk_rtc_suspend(struct device *dev) 382 + { 383 + struct mtk_rtc *hw = dev_get_drvdata(dev); 384 + 385 + if (device_may_wakeup(dev)) 386 + enable_irq_wake(hw->irq); 387 + 388 + return 0; 389 + } 390 + 391 + static int mtk_rtc_resume(struct device *dev) 392 + { 393 + struct mtk_rtc *hw = dev_get_drvdata(dev); 394 + 395 + if (device_may_wakeup(dev)) 396 + disable_irq_wake(hw->irq); 397 + 398 + return 0; 399 + } 400 + 401 + static SIMPLE_DEV_PM_OPS(mtk_rtc_pm_ops, mtk_rtc_suspend, mtk_rtc_resume); 402 + 403 + #define MTK_RTC_PM_OPS (&mtk_rtc_pm_ops) 404 + #else /* CONFIG_PM */ 405 + #define MTK_RTC_PM_OPS NULL 406 + #endif /* CONFIG_PM */ 407 + 408 + static struct platform_driver mtk_rtc_driver = { 409 + .probe = mtk_rtc_probe, 410 + .remove = mtk_rtc_remove, 411 + .driver = { 412 + .name = MTK_RTC_DEV, 413 + .of_match_table = mtk_rtc_match, 414 + .pm = MTK_RTC_PM_OPS, 415 + }, 416 + }; 417 + 418 + module_platform_driver(mtk_rtc_driver); 419 + 420 + MODULE_DESCRIPTION("MediaTek SoC based RTC Driver"); 421 + MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>"); 422 + MODULE_LICENSE("GPL");
+54 -3
drivers/rtc/rtc-omap.c
··· 70 70 #define OMAP_RTC_COMP_MSB_REG 0x50 71 71 #define OMAP_RTC_OSC_REG 0x54 72 72 73 + #define OMAP_RTC_SCRATCH0_REG 0x60 74 + #define OMAP_RTC_SCRATCH1_REG 0x64 75 + #define OMAP_RTC_SCRATCH2_REG 0x68 76 + 73 77 #define OMAP_RTC_KICK0_REG 0x6c 74 78 #define OMAP_RTC_KICK1_REG 0x70 75 79 ··· 671 667 .owner = THIS_MODULE, 672 668 }; 673 669 670 + static int omap_rtc_scratch_read(void *priv, unsigned int offset, void *_val, 671 + size_t bytes) 672 + { 673 + struct omap_rtc *rtc = priv; 674 + u32 *val = _val; 675 + int i; 676 + 677 + for (i = 0; i < bytes / 4; i++) 678 + val[i] = rtc_readl(rtc, 679 + OMAP_RTC_SCRATCH0_REG + offset + (i * 4)); 680 + 681 + return 0; 682 + } 683 + 684 + static int omap_rtc_scratch_write(void *priv, unsigned int offset, void *_val, 685 + size_t bytes) 686 + { 687 + struct omap_rtc *rtc = priv; 688 + u32 *val = _val; 689 + int i; 690 + 691 + rtc->type->unlock(rtc); 692 + for (i = 0; i < bytes / 4; i++) 693 + rtc_writel(rtc, 694 + OMAP_RTC_SCRATCH0_REG + offset + (i * 4), val[i]); 695 + rtc->type->lock(rtc); 696 + 697 + return 0; 698 + } 699 + 700 + static struct nvmem_config omap_rtc_nvmem_config = { 701 + .name = "omap_rtc_scratch", 702 + .word_size = 4, 703 + .stride = 4, 704 + .size = OMAP_RTC_KICK0_REG - OMAP_RTC_SCRATCH0_REG, 705 + .reg_read = omap_rtc_scratch_read, 706 + .reg_write = omap_rtc_scratch_write, 707 + }; 708 + 674 709 static int omap_rtc_probe(struct platform_device *pdev) 675 710 { 676 711 struct omap_rtc *rtc; ··· 840 797 841 798 device_init_wakeup(&pdev->dev, true); 842 799 843 - rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 844 - &omap_rtc_ops, THIS_MODULE); 800 + rtc->rtc = devm_rtc_allocate_device(&pdev->dev); 845 801 if (IS_ERR(rtc->rtc)) { 846 802 ret = PTR_ERR(rtc->rtc); 847 803 goto err; 848 804 } 805 + 806 + rtc->rtc->ops = &omap_rtc_ops; 807 + omap_rtc_nvmem_config.priv = rtc; 808 + rtc->rtc->nvmem_config = &omap_rtc_nvmem_config; 849 809 850 810 /* handle periodic and alarm irqs */ 851 811 ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0, ··· 876 830 rtc->pctldev = pinctrl_register(&rtc_pinctrl_desc, &pdev->dev, rtc); 877 831 if (IS_ERR(rtc->pctldev)) { 878 832 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); 879 - return PTR_ERR(rtc->pctldev); 833 + ret = PTR_ERR(rtc->pctldev); 834 + goto err; 880 835 } 836 + 837 + ret = rtc_register_device(rtc->rtc); 838 + if (ret) 839 + goto err; 881 840 882 841 return 0; 883 842
+40
drivers/rtc/rtc-pcf8523.c
··· 35 35 #define REG_MONTHS 0x08 36 36 #define REG_YEARS 0x09 37 37 38 + #define REG_OFFSET 0x0e 39 + #define REG_OFFSET_MODE BIT(7) 40 + 38 41 struct pcf8523 { 39 42 struct rtc_device *rtc; 40 43 }; ··· 275 272 #define pcf8523_rtc_ioctl NULL 276 273 #endif 277 274 275 + static int pcf8523_rtc_read_offset(struct device *dev, long *offset) 276 + { 277 + struct i2c_client *client = to_i2c_client(dev); 278 + int err; 279 + u8 value; 280 + s8 val; 281 + 282 + err = pcf8523_read(client, REG_OFFSET, &value); 283 + if (err < 0) 284 + return err; 285 + 286 + /* sign extend the 7-bit offset value */ 287 + val = value << 1; 288 + *offset = (value & REG_OFFSET_MODE ? 4069 : 4340) * (val >> 1); 289 + 290 + return 0; 291 + } 292 + 293 + static int pcf8523_rtc_set_offset(struct device *dev, long offset) 294 + { 295 + struct i2c_client *client = to_i2c_client(dev); 296 + long reg_m0, reg_m1; 297 + u8 value; 298 + 299 + reg_m0 = clamp(DIV_ROUND_CLOSEST(offset, 4340), -64L, 63L); 300 + reg_m1 = clamp(DIV_ROUND_CLOSEST(offset, 4069), -64L, 63L); 301 + 302 + if (abs(reg_m0 * 4340 - offset) < abs(reg_m1 * 4069 - offset)) 303 + value = reg_m0 & 0x7f; 304 + else 305 + value = (reg_m1 & 0x7f) | REG_OFFSET_MODE; 306 + 307 + return pcf8523_write(client, REG_OFFSET, value); 308 + } 309 + 278 310 static const struct rtc_class_ops pcf8523_rtc_ops = { 279 311 .read_time = pcf8523_rtc_read_time, 280 312 .set_time = pcf8523_rtc_set_time, 281 313 .ioctl = pcf8523_rtc_ioctl, 314 + .read_offset = pcf8523_rtc_read_offset, 315 + .set_offset = pcf8523_rtc_set_offset, 282 316 }; 283 317 284 318 static int pcf8523_probe(struct i2c_client *client,
+220
drivers/rtc/rtc-pcf85363.c
··· 1 + /* 2 + * drivers/rtc/rtc-pcf85363.c 3 + * 4 + * Driver for NXP PCF85363 real-time clock. 5 + * 6 + * Copyright (C) 2017 Eric Nelson 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 + * Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert 13 + */ 14 + #include <linux/module.h> 15 + #include <linux/i2c.h> 16 + #include <linux/slab.h> 17 + #include <linux/rtc.h> 18 + #include <linux/init.h> 19 + #include <linux/err.h> 20 + #include <linux/errno.h> 21 + #include <linux/bcd.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 24 + #include <linux/regmap.h> 25 + 26 + /* 27 + * Date/Time registers 28 + */ 29 + #define DT_100THS 0x00 30 + #define DT_SECS 0x01 31 + #define DT_MINUTES 0x02 32 + #define DT_HOURS 0x03 33 + #define DT_DAYS 0x04 34 + #define DT_WEEKDAYS 0x05 35 + #define DT_MONTHS 0x06 36 + #define DT_YEARS 0x07 37 + 38 + /* 39 + * Alarm registers 40 + */ 41 + #define DT_SECOND_ALM1 0x08 42 + #define DT_MINUTE_ALM1 0x09 43 + #define DT_HOUR_ALM1 0x0a 44 + #define DT_DAY_ALM1 0x0b 45 + #define DT_MONTH_ALM1 0x0c 46 + #define DT_MINUTE_ALM2 0x0d 47 + #define DT_HOUR_ALM2 0x0e 48 + #define DT_WEEKDAY_ALM2 0x0f 49 + #define DT_ALARM_EN 0x10 50 + 51 + /* 52 + * Time stamp registers 53 + */ 54 + #define DT_TIMESTAMP1 0x11 55 + #define DT_TIMESTAMP2 0x17 56 + #define DT_TIMESTAMP3 0x1d 57 + #define DT_TS_MODE 0x23 58 + 59 + /* 60 + * control registers 61 + */ 62 + #define CTRL_OFFSET 0x24 63 + #define CTRL_OSCILLATOR 0x25 64 + #define CTRL_BATTERY 0x26 65 + #define CTRL_PIN_IO 0x27 66 + #define CTRL_FUNCTION 0x28 67 + #define CTRL_INTA_EN 0x29 68 + #define CTRL_INTB_EN 0x2a 69 + #define CTRL_FLAGS 0x2b 70 + #define CTRL_RAMBYTE 0x2c 71 + #define CTRL_WDOG 0x2d 72 + #define CTRL_STOP_EN 0x2e 73 + #define CTRL_RESETS 0x2f 74 + #define CTRL_RAM 0x40 75 + 76 + #define NVRAM_SIZE 0x40 77 + 78 + static struct i2c_driver pcf85363_driver; 79 + 80 + struct pcf85363 { 81 + struct device *dev; 82 + struct rtc_device *rtc; 83 + struct nvmem_config nvmem_cfg; 84 + struct regmap *regmap; 85 + }; 86 + 87 + static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm) 88 + { 89 + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 90 + unsigned char buf[DT_YEARS + 1]; 91 + int ret, len = sizeof(buf); 92 + 93 + /* read the RTC date and time registers all at once */ 94 + ret = regmap_bulk_read(pcf85363->regmap, DT_100THS, buf, len); 95 + if (ret) { 96 + dev_err(dev, "%s: error %d\n", __func__, ret); 97 + return ret; 98 + } 99 + 100 + tm->tm_year = bcd2bin(buf[DT_YEARS]); 101 + /* adjust for 1900 base of rtc_time */ 102 + tm->tm_year += 100; 103 + 104 + tm->tm_wday = buf[DT_WEEKDAYS] & 7; 105 + buf[DT_SECS] &= 0x7F; 106 + tm->tm_sec = bcd2bin(buf[DT_SECS]); 107 + buf[DT_MINUTES] &= 0x7F; 108 + tm->tm_min = bcd2bin(buf[DT_MINUTES]); 109 + tm->tm_hour = bcd2bin(buf[DT_HOURS]); 110 + tm->tm_mday = bcd2bin(buf[DT_DAYS]); 111 + tm->tm_mon = bcd2bin(buf[DT_MONTHS]) - 1; 112 + 113 + return 0; 114 + } 115 + 116 + static int pcf85363_rtc_set_time(struct device *dev, struct rtc_time *tm) 117 + { 118 + struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 119 + unsigned char buf[DT_YEARS + 1]; 120 + int len = sizeof(buf); 121 + 122 + buf[DT_100THS] = 0; 123 + buf[DT_SECS] = bin2bcd(tm->tm_sec); 124 + buf[DT_MINUTES] = bin2bcd(tm->tm_min); 125 + buf[DT_HOURS] = bin2bcd(tm->tm_hour); 126 + buf[DT_DAYS] = bin2bcd(tm->tm_mday); 127 + buf[DT_WEEKDAYS] = tm->tm_wday; 128 + buf[DT_MONTHS] = bin2bcd(tm->tm_mon + 1); 129 + buf[DT_YEARS] = bin2bcd(tm->tm_year % 100); 130 + 131 + return regmap_bulk_write(pcf85363->regmap, DT_100THS, 132 + buf, len); 133 + } 134 + 135 + static const struct rtc_class_ops rtc_ops = { 136 + .read_time = pcf85363_rtc_read_time, 137 + .set_time = pcf85363_rtc_set_time, 138 + }; 139 + 140 + static int pcf85363_nvram_read(void *priv, unsigned int offset, void *val, 141 + size_t bytes) 142 + { 143 + struct pcf85363 *pcf85363 = priv; 144 + 145 + return regmap_bulk_read(pcf85363->regmap, CTRL_RAM + offset, 146 + val, bytes); 147 + } 148 + 149 + static int pcf85363_nvram_write(void *priv, unsigned int offset, void *val, 150 + size_t bytes) 151 + { 152 + struct pcf85363 *pcf85363 = priv; 153 + 154 + return regmap_bulk_write(pcf85363->regmap, CTRL_RAM + offset, 155 + val, bytes); 156 + } 157 + 158 + static const struct regmap_config regmap_config = { 159 + .reg_bits = 8, 160 + .val_bits = 8, 161 + }; 162 + 163 + static int pcf85363_probe(struct i2c_client *client, 164 + const struct i2c_device_id *id) 165 + { 166 + struct pcf85363 *pcf85363; 167 + 168 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 169 + return -ENODEV; 170 + 171 + pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), 172 + GFP_KERNEL); 173 + if (!pcf85363) 174 + return -ENOMEM; 175 + 176 + pcf85363->regmap = devm_regmap_init_i2c(client, &regmap_config); 177 + if (IS_ERR(pcf85363->regmap)) { 178 + dev_err(&client->dev, "regmap allocation failed\n"); 179 + return PTR_ERR(pcf85363->regmap); 180 + } 181 + 182 + pcf85363->dev = &client->dev; 183 + i2c_set_clientdata(client, pcf85363); 184 + 185 + pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); 186 + if (IS_ERR(pcf85363->rtc)) 187 + return PTR_ERR(pcf85363->rtc); 188 + 189 + pcf85363->nvmem_cfg.name = "pcf85363-"; 190 + pcf85363->nvmem_cfg.word_size = 1; 191 + pcf85363->nvmem_cfg.stride = 1; 192 + pcf85363->nvmem_cfg.size = NVRAM_SIZE; 193 + pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; 194 + pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; 195 + pcf85363->nvmem_cfg.priv = pcf85363; 196 + pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; 197 + pcf85363->rtc->ops = &rtc_ops; 198 + 199 + return rtc_register_device(pcf85363->rtc); 200 + } 201 + 202 + static const struct of_device_id dev_ids[] = { 203 + { .compatible = "nxp,pcf85363" }, 204 + {} 205 + }; 206 + MODULE_DEVICE_TABLE(of, dev_ids); 207 + 208 + static struct i2c_driver pcf85363_driver = { 209 + .driver = { 210 + .name = "pcf85363", 211 + .of_match_table = of_match_ptr(dev_ids), 212 + }, 213 + .probe = pcf85363_probe, 214 + }; 215 + 216 + module_i2c_driver(pcf85363_driver); 217 + 218 + MODULE_AUTHOR("Eric Nelson"); 219 + MODULE_DESCRIPTION("pcf85363 I2C RTC driver"); 220 + MODULE_LICENSE("GPL");
+2 -2
drivers/rtc/rtc-pcf8563.c
··· 387 387 if (err) 388 388 return err; 389 389 390 - return pcf8563_set_alarm_mode(client, 1); 390 + return pcf8563_set_alarm_mode(client, !!tm->enabled); 391 391 } 392 392 393 393 static int pcf8563_irq_enable(struct device *dev, unsigned int enabled) ··· 422 422 return 0; 423 423 424 424 buf &= PCF8563_REG_CLKO_F_MASK; 425 - return clkout_rates[ret]; 425 + return clkout_rates[buf]; 426 426 } 427 427 428 428 static long pcf8563_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
+27 -21
drivers/rtc/rtc-pl031.c
··· 308 308 309 309 dev_pm_clear_wake_irq(&adev->dev); 310 310 device_init_wakeup(&adev->dev, false); 311 - free_irq(adev->irq[0], ldata); 311 + if (adev->irq[0]) 312 + free_irq(adev->irq[0], ldata); 312 313 rtc_device_unregister(ldata->rtc); 313 - iounmap(ldata->base); 314 - kfree(ldata); 315 314 amba_release_regions(adev); 316 315 317 316 return 0; ··· 321 322 int ret; 322 323 struct pl031_local *ldata; 323 324 struct pl031_vendor_data *vendor = id->data; 324 - struct rtc_class_ops *ops = &vendor->ops; 325 + struct rtc_class_ops *ops; 325 326 unsigned long time, data; 326 327 327 328 ret = amba_request_regions(adev, NULL); 328 329 if (ret) 329 330 goto err_req; 330 331 331 - ldata = kzalloc(sizeof(struct pl031_local), GFP_KERNEL); 332 - if (!ldata) { 332 + ldata = devm_kzalloc(&adev->dev, sizeof(struct pl031_local), 333 + GFP_KERNEL); 334 + ops = devm_kmemdup(&adev->dev, &vendor->ops, sizeof(vendor->ops), 335 + GFP_KERNEL); 336 + if (!ldata || !ops) { 333 337 ret = -ENOMEM; 334 338 goto out; 335 339 } 340 + 336 341 ldata->vendor = vendor; 337 - 338 - ldata->base = ioremap(adev->res.start, resource_size(&adev->res)); 339 - 342 + ldata->base = devm_ioremap(&adev->dev, adev->res.start, 343 + resource_size(&adev->res)); 340 344 if (!ldata->base) { 341 345 ret = -ENOMEM; 342 - goto out_no_remap; 346 + goto out; 343 347 } 344 348 345 349 amba_set_drvdata(adev, ldata); ··· 375 373 } 376 374 } 377 375 376 + if (!adev->irq[0]) { 377 + /* When there's no interrupt, no point in exposing the alarm */ 378 + ops->read_alarm = NULL; 379 + ops->set_alarm = NULL; 380 + ops->alarm_irq_enable = NULL; 381 + } 382 + 378 383 device_init_wakeup(&adev->dev, true); 379 384 ldata->rtc = rtc_device_register("pl031", &adev->dev, ops, 380 385 THIS_MODULE); 381 386 if (IS_ERR(ldata->rtc)) { 382 387 ret = PTR_ERR(ldata->rtc); 383 - goto out_no_rtc; 388 + goto out; 384 389 } 385 390 386 - if (request_irq(adev->irq[0], pl031_interrupt, 387 - vendor->irqflags, "rtc-pl031", ldata)) { 388 - ret = -EIO; 389 - goto out_no_irq; 391 + if (adev->irq[0]) { 392 + ret = request_irq(adev->irq[0], pl031_interrupt, 393 + vendor->irqflags, "rtc-pl031", ldata); 394 + if (ret) 395 + goto out_no_irq; 396 + dev_pm_set_wake_irq(&adev->dev, adev->irq[0]); 390 397 } 391 - dev_pm_set_wake_irq(&adev->dev, adev->irq[0]); 392 398 return 0; 393 399 394 400 out_no_irq: 395 401 rtc_device_unregister(ldata->rtc); 396 - out_no_rtc: 397 - iounmap(ldata->base); 398 - out_no_remap: 399 - kfree(ldata); 400 402 out: 401 403 amba_release_regions(adev); 402 404 err_req: ··· 452 446 .irqflags = IRQF_SHARED | IRQF_COND_SUSPEND, 453 447 }; 454 448 455 - static struct amba_id pl031_ids[] = { 449 + static const struct amba_id pl031_ids[] = { 456 450 { 457 451 .id = 0x00041031, 458 452 .mask = 0x000fffff,
+10 -8
drivers/rtc/rtc-rv3029c2.c
··· 282 282 static int rv3029_eeprom_write(struct device *dev, u8 reg, 283 283 u8 const buf[], size_t len) 284 284 { 285 - int ret, err; 285 + int ret; 286 286 size_t i; 287 287 u8 tmp; 288 288 289 - err = rv3029_eeprom_enter(dev); 290 - if (err < 0) 291 - return err; 289 + ret = rv3029_eeprom_enter(dev); 290 + if (ret < 0) 291 + return ret; 292 292 293 293 for (i = 0; i < len; i++, reg++) { 294 294 ret = rv3029_read_regs(dev, reg, &tmp, 1); ··· 304 304 break; 305 305 } 306 306 307 - err = rv3029_eeprom_exit(dev); 308 - if (err < 0) 309 - return err; 307 + ret = rv3029_eeprom_exit(dev); 308 + if (ret < 0) 309 + return ret; 310 310 311 - return ret; 311 + return 0; 312 312 } 313 313 314 314 static int rv3029_eeprom_update_bits(struct device *dev, ··· 876 876 MODULE_DEVICE_TABLE(i2c, rv3029_id); 877 877 878 878 static const struct of_device_id rv3029_of_match[] = { 879 + { .compatible = "microcrystal,rv3029" }, 880 + /* Backward compatibility only, do not use compatibles below: */ 879 881 { .compatible = "rv3029" }, 880 882 { .compatible = "rv3029c2" }, 881 883 { .compatible = "mc,rv3029c2" },
+3 -4
drivers/rtc/rtc-rx8010.c
··· 24 24 #define RX8010_MDAY 0x14 25 25 #define RX8010_MONTH 0x15 26 26 #define RX8010_YEAR 0x16 27 - #define RX8010_YEAR 0x16 28 27 #define RX8010_RESV17 0x17 29 28 #define RX8010_ALMIN 0x18 30 29 #define RX8010_ALHOUR 0x19 ··· 35 36 #define RX8010_CTRL 0x1F 36 37 /* 0x20 to 0x2F are user registers */ 37 38 #define RX8010_RESV30 0x30 38 - #define RX8010_RESV31 0x32 39 + #define RX8010_RESV31 0x31 39 40 #define RX8010_IRQ 0x32 40 41 41 42 #define RX8010_EXT_WADA BIT(3) ··· 247 248 248 249 rx8010->ctrlreg = (ctrl[1] & ~RX8010_CTRL_TEST); 249 250 250 - return err; 251 + return 0; 251 252 } 252 253 253 254 static int rx8010_read_alarm(struct device *dev, struct rtc_wkalrm *t) ··· 276 277 t->enabled = !!(rx8010->ctrlreg & RX8010_CTRL_AIE); 277 278 t->pending = (flagreg & RX8010_FLAG_AF) && t->enabled; 278 279 279 - return err; 280 + return 0; 280 281 } 281 282 282 283 static int rx8010_set_alarm(struct device *dev, struct rtc_wkalrm *t)
+662
drivers/rtc/rtc-sc27xx.c
··· 1 + /* 2 + * Copyright (C) 2017 Spreadtrum Communications Inc. 3 + * 4 + * SPDX-License-Identifier: GPL-2.0 5 + */ 6 + 7 + #include <linux/bitops.h> 8 + #include <linux/delay.h> 9 + #include <linux/err.h> 10 + #include <linux/module.h> 11 + #include <linux/of.h> 12 + #include <linux/platform_device.h> 13 + #include <linux/regmap.h> 14 + #include <linux/rtc.h> 15 + 16 + #define SPRD_RTC_SEC_CNT_VALUE 0x0 17 + #define SPRD_RTC_MIN_CNT_VALUE 0x4 18 + #define SPRD_RTC_HOUR_CNT_VALUE 0x8 19 + #define SPRD_RTC_DAY_CNT_VALUE 0xc 20 + #define SPRD_RTC_SEC_CNT_UPD 0x10 21 + #define SPRD_RTC_MIN_CNT_UPD 0x14 22 + #define SPRD_RTC_HOUR_CNT_UPD 0x18 23 + #define SPRD_RTC_DAY_CNT_UPD 0x1c 24 + #define SPRD_RTC_SEC_ALM_UPD 0x20 25 + #define SPRD_RTC_MIN_ALM_UPD 0x24 26 + #define SPRD_RTC_HOUR_ALM_UPD 0x28 27 + #define SPRD_RTC_DAY_ALM_UPD 0x2c 28 + #define SPRD_RTC_INT_EN 0x30 29 + #define SPRD_RTC_INT_RAW_STS 0x34 30 + #define SPRD_RTC_INT_CLR 0x38 31 + #define SPRD_RTC_INT_MASK_STS 0x3C 32 + #define SPRD_RTC_SEC_ALM_VALUE 0x40 33 + #define SPRD_RTC_MIN_ALM_VALUE 0x44 34 + #define SPRD_RTC_HOUR_ALM_VALUE 0x48 35 + #define SPRD_RTC_DAY_ALM_VALUE 0x4c 36 + #define SPRD_RTC_SPG_VALUE 0x50 37 + #define SPRD_RTC_SPG_UPD 0x54 38 + #define SPRD_RTC_SEC_AUXALM_UPD 0x60 39 + #define SPRD_RTC_MIN_AUXALM_UPD 0x64 40 + #define SPRD_RTC_HOUR_AUXALM_UPD 0x68 41 + #define SPRD_RTC_DAY_AUXALM_UPD 0x6c 42 + 43 + /* BIT & MASK definition for SPRD_RTC_INT_* registers */ 44 + #define SPRD_RTC_SEC_EN BIT(0) 45 + #define SPRD_RTC_MIN_EN BIT(1) 46 + #define SPRD_RTC_HOUR_EN BIT(2) 47 + #define SPRD_RTC_DAY_EN BIT(3) 48 + #define SPRD_RTC_ALARM_EN BIT(4) 49 + #define SPRD_RTC_HRS_FORMAT_EN BIT(5) 50 + #define SPRD_RTC_AUXALM_EN BIT(6) 51 + #define SPRD_RTC_SPG_UPD_EN BIT(7) 52 + #define SPRD_RTC_SEC_UPD_EN BIT(8) 53 + #define SPRD_RTC_MIN_UPD_EN BIT(9) 54 + #define SPRD_RTC_HOUR_UPD_EN BIT(10) 55 + #define SPRD_RTC_DAY_UPD_EN BIT(11) 56 + #define SPRD_RTC_ALMSEC_UPD_EN BIT(12) 57 + #define SPRD_RTC_ALMMIN_UPD_EN BIT(13) 58 + #define SPRD_RTC_ALMHOUR_UPD_EN BIT(14) 59 + #define SPRD_RTC_ALMDAY_UPD_EN BIT(15) 60 + #define SPRD_RTC_INT_MASK GENMASK(15, 0) 61 + 62 + #define SPRD_RTC_TIME_INT_MASK \ 63 + (SPRD_RTC_SEC_UPD_EN | SPRD_RTC_MIN_UPD_EN | \ 64 + SPRD_RTC_HOUR_UPD_EN | SPRD_RTC_DAY_UPD_EN) 65 + 66 + #define SPRD_RTC_ALMTIME_INT_MASK \ 67 + (SPRD_RTC_ALMSEC_UPD_EN | SPRD_RTC_ALMMIN_UPD_EN | \ 68 + SPRD_RTC_ALMHOUR_UPD_EN | SPRD_RTC_ALMDAY_UPD_EN) 69 + 70 + #define SPRD_RTC_ALM_INT_MASK \ 71 + (SPRD_RTC_SEC_EN | SPRD_RTC_MIN_EN | \ 72 + SPRD_RTC_HOUR_EN | SPRD_RTC_DAY_EN | \ 73 + SPRD_RTC_ALARM_EN | SPRD_RTC_AUXALM_EN) 74 + 75 + /* second/minute/hour/day values mask definition */ 76 + #define SPRD_RTC_SEC_MASK GENMASK(5, 0) 77 + #define SPRD_RTC_MIN_MASK GENMASK(5, 0) 78 + #define SPRD_RTC_HOUR_MASK GENMASK(4, 0) 79 + #define SPRD_RTC_DAY_MASK GENMASK(15, 0) 80 + 81 + /* alarm lock definition for SPRD_RTC_SPG_UPD register */ 82 + #define SPRD_RTC_ALMLOCK_MASK GENMASK(7, 0) 83 + #define SPRD_RTC_ALM_UNLOCK 0xa5 84 + #define SPRD_RTC_ALM_LOCK (~SPRD_RTC_ALM_UNLOCK & \ 85 + SPRD_RTC_ALMLOCK_MASK) 86 + 87 + /* SPG values definition for SPRD_RTC_SPG_UPD register */ 88 + #define SPRD_RTC_POWEROFF_ALM_FLAG BIT(8) 89 + #define SPRD_RTC_POWER_RESET_FLAG BIT(9) 90 + 91 + /* timeout of synchronizing time and alarm registers (us) */ 92 + #define SPRD_RTC_POLL_TIMEOUT 200000 93 + #define SPRD_RTC_POLL_DELAY_US 20000 94 + 95 + struct sprd_rtc { 96 + struct rtc_device *rtc; 97 + struct regmap *regmap; 98 + struct device *dev; 99 + u32 base; 100 + int irq; 101 + bool valid; 102 + }; 103 + 104 + /* 105 + * The Spreadtrum RTC controller has 3 groups registers, including time, normal 106 + * alarm and auxiliary alarm. The time group registers are used to set RTC time, 107 + * the normal alarm registers are used to set normal alarm, and the auxiliary 108 + * alarm registers are used to set auxiliary alarm. Both alarm event and 109 + * auxiliary alarm event can wake up system from deep sleep, but only alarm 110 + * event can power up system from power down status. 111 + */ 112 + enum sprd_rtc_reg_types { 113 + SPRD_RTC_TIME, 114 + SPRD_RTC_ALARM, 115 + SPRD_RTC_AUX_ALARM, 116 + }; 117 + 118 + static int sprd_rtc_clear_alarm_ints(struct sprd_rtc *rtc) 119 + { 120 + return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 121 + SPRD_RTC_ALM_INT_MASK); 122 + } 123 + 124 + static int sprd_rtc_disable_ints(struct sprd_rtc *rtc) 125 + { 126 + int ret; 127 + 128 + ret = regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, 129 + SPRD_RTC_INT_MASK, 0); 130 + if (ret) 131 + return ret; 132 + 133 + return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 134 + SPRD_RTC_INT_MASK); 135 + } 136 + 137 + static int sprd_rtc_lock_alarm(struct sprd_rtc *rtc, bool lock) 138 + { 139 + int ret; 140 + u32 val; 141 + 142 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); 143 + if (ret) 144 + return ret; 145 + 146 + val &= ~(SPRD_RTC_ALMLOCK_MASK | SPRD_RTC_POWEROFF_ALM_FLAG); 147 + if (lock) 148 + val |= SPRD_RTC_ALM_LOCK; 149 + else 150 + val |= SPRD_RTC_ALM_UNLOCK | SPRD_RTC_POWEROFF_ALM_FLAG; 151 + 152 + ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_SPG_UPD, val); 153 + if (ret) 154 + return ret; 155 + 156 + /* wait until the SPG value is updated successfully */ 157 + ret = regmap_read_poll_timeout(rtc->regmap, 158 + rtc->base + SPRD_RTC_INT_RAW_STS, val, 159 + (val & SPRD_RTC_SPG_UPD_EN), 160 + SPRD_RTC_POLL_DELAY_US, 161 + SPRD_RTC_POLL_TIMEOUT); 162 + if (ret) { 163 + dev_err(rtc->dev, "failed to update SPG value:%d\n", ret); 164 + return ret; 165 + } 166 + 167 + return 0; 168 + } 169 + 170 + static int sprd_rtc_get_secs(struct sprd_rtc *rtc, enum sprd_rtc_reg_types type, 171 + time64_t *secs) 172 + { 173 + u32 sec_reg, min_reg, hour_reg, day_reg; 174 + u32 val, sec, min, hour, day; 175 + int ret; 176 + 177 + switch (type) { 178 + case SPRD_RTC_TIME: 179 + sec_reg = SPRD_RTC_SEC_CNT_VALUE; 180 + min_reg = SPRD_RTC_MIN_CNT_VALUE; 181 + hour_reg = SPRD_RTC_HOUR_CNT_VALUE; 182 + day_reg = SPRD_RTC_DAY_CNT_VALUE; 183 + break; 184 + case SPRD_RTC_ALARM: 185 + sec_reg = SPRD_RTC_SEC_ALM_VALUE; 186 + min_reg = SPRD_RTC_MIN_ALM_VALUE; 187 + hour_reg = SPRD_RTC_HOUR_ALM_VALUE; 188 + day_reg = SPRD_RTC_DAY_ALM_VALUE; 189 + break; 190 + case SPRD_RTC_AUX_ALARM: 191 + sec_reg = SPRD_RTC_SEC_AUXALM_UPD; 192 + min_reg = SPRD_RTC_MIN_AUXALM_UPD; 193 + hour_reg = SPRD_RTC_HOUR_AUXALM_UPD; 194 + day_reg = SPRD_RTC_DAY_AUXALM_UPD; 195 + break; 196 + default: 197 + return -EINVAL; 198 + } 199 + 200 + ret = regmap_read(rtc->regmap, rtc->base + sec_reg, &val); 201 + if (ret) 202 + return ret; 203 + 204 + sec = val & SPRD_RTC_SEC_MASK; 205 + 206 + ret = regmap_read(rtc->regmap, rtc->base + min_reg, &val); 207 + if (ret) 208 + return ret; 209 + 210 + min = val & SPRD_RTC_MIN_MASK; 211 + 212 + ret = regmap_read(rtc->regmap, rtc->base + hour_reg, &val); 213 + if (ret) 214 + return ret; 215 + 216 + hour = val & SPRD_RTC_HOUR_MASK; 217 + 218 + ret = regmap_read(rtc->regmap, rtc->base + day_reg, &val); 219 + if (ret) 220 + return ret; 221 + 222 + day = val & SPRD_RTC_DAY_MASK; 223 + *secs = (((time64_t)(day * 24) + hour) * 60 + min) * 60 + sec; 224 + return 0; 225 + } 226 + 227 + static int sprd_rtc_set_secs(struct sprd_rtc *rtc, enum sprd_rtc_reg_types type, 228 + time64_t secs) 229 + { 230 + u32 sec_reg, min_reg, hour_reg, day_reg, sts_mask; 231 + u32 sec, min, hour, day, val; 232 + int ret, rem; 233 + 234 + /* convert seconds to RTC time format */ 235 + day = div_s64_rem(secs, 86400, &rem); 236 + hour = rem / 3600; 237 + rem -= hour * 3600; 238 + min = rem / 60; 239 + sec = rem - min * 60; 240 + 241 + switch (type) { 242 + case SPRD_RTC_TIME: 243 + sec_reg = SPRD_RTC_SEC_CNT_UPD; 244 + min_reg = SPRD_RTC_MIN_CNT_UPD; 245 + hour_reg = SPRD_RTC_HOUR_CNT_UPD; 246 + day_reg = SPRD_RTC_DAY_CNT_UPD; 247 + sts_mask = SPRD_RTC_TIME_INT_MASK; 248 + break; 249 + case SPRD_RTC_ALARM: 250 + sec_reg = SPRD_RTC_SEC_ALM_UPD; 251 + min_reg = SPRD_RTC_MIN_ALM_UPD; 252 + hour_reg = SPRD_RTC_HOUR_ALM_UPD; 253 + day_reg = SPRD_RTC_DAY_ALM_UPD; 254 + sts_mask = SPRD_RTC_ALMTIME_INT_MASK; 255 + break; 256 + case SPRD_RTC_AUX_ALARM: 257 + sec_reg = SPRD_RTC_SEC_AUXALM_UPD; 258 + min_reg = SPRD_RTC_MIN_AUXALM_UPD; 259 + hour_reg = SPRD_RTC_HOUR_AUXALM_UPD; 260 + day_reg = SPRD_RTC_DAY_AUXALM_UPD; 261 + sts_mask = 0; 262 + break; 263 + default: 264 + return -EINVAL; 265 + } 266 + 267 + ret = regmap_write(rtc->regmap, rtc->base + sec_reg, sec); 268 + if (ret) 269 + return ret; 270 + 271 + ret = regmap_write(rtc->regmap, rtc->base + min_reg, min); 272 + if (ret) 273 + return ret; 274 + 275 + ret = regmap_write(rtc->regmap, rtc->base + hour_reg, hour); 276 + if (ret) 277 + return ret; 278 + 279 + ret = regmap_write(rtc->regmap, rtc->base + day_reg, day); 280 + if (ret) 281 + return ret; 282 + 283 + if (type == SPRD_RTC_AUX_ALARM) 284 + return 0; 285 + 286 + /* 287 + * Since the time and normal alarm registers are put in always-power-on 288 + * region supplied by VDDRTC, then these registers changing time will 289 + * be very long, about 125ms. Thus here we should wait until all 290 + * values are updated successfully. 291 + */ 292 + ret = regmap_read_poll_timeout(rtc->regmap, 293 + rtc->base + SPRD_RTC_INT_RAW_STS, val, 294 + ((val & sts_mask) == sts_mask), 295 + SPRD_RTC_POLL_DELAY_US, 296 + SPRD_RTC_POLL_TIMEOUT); 297 + if (ret < 0) { 298 + dev_err(rtc->dev, "set time/alarm values timeout\n"); 299 + return ret; 300 + } 301 + 302 + return regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 303 + sts_mask); 304 + } 305 + 306 + static int sprd_rtc_read_aux_alarm(struct device *dev, struct rtc_wkalrm *alrm) 307 + { 308 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 309 + time64_t secs; 310 + u32 val; 311 + int ret; 312 + 313 + ret = sprd_rtc_get_secs(rtc, SPRD_RTC_AUX_ALARM, &secs); 314 + if (ret) 315 + return ret; 316 + 317 + rtc_time64_to_tm(secs, &alrm->time); 318 + 319 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, &val); 320 + if (ret) 321 + return ret; 322 + 323 + alrm->enabled = !!(val & SPRD_RTC_AUXALM_EN); 324 + 325 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_RAW_STS, &val); 326 + if (ret) 327 + return ret; 328 + 329 + alrm->pending = !!(val & SPRD_RTC_AUXALM_EN); 330 + return 0; 331 + } 332 + 333 + static int sprd_rtc_set_aux_alarm(struct device *dev, struct rtc_wkalrm *alrm) 334 + { 335 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 336 + time64_t secs = rtc_tm_to_time64(&alrm->time); 337 + int ret; 338 + 339 + /* clear the auxiliary alarm interrupt status */ 340 + ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 341 + SPRD_RTC_AUXALM_EN); 342 + if (ret) 343 + return ret; 344 + 345 + ret = sprd_rtc_set_secs(rtc, SPRD_RTC_AUX_ALARM, secs); 346 + if (ret) 347 + return ret; 348 + 349 + if (alrm->enabled) { 350 + ret = regmap_update_bits(rtc->regmap, 351 + rtc->base + SPRD_RTC_INT_EN, 352 + SPRD_RTC_AUXALM_EN, 353 + SPRD_RTC_AUXALM_EN); 354 + } else { 355 + ret = regmap_update_bits(rtc->regmap, 356 + rtc->base + SPRD_RTC_INT_EN, 357 + SPRD_RTC_AUXALM_EN, 0); 358 + } 359 + 360 + return ret; 361 + } 362 + 363 + static int sprd_rtc_read_time(struct device *dev, struct rtc_time *tm) 364 + { 365 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 366 + time64_t secs; 367 + int ret; 368 + 369 + if (!rtc->valid) { 370 + dev_warn(dev, "RTC values are invalid\n"); 371 + return -EINVAL; 372 + } 373 + 374 + ret = sprd_rtc_get_secs(rtc, SPRD_RTC_TIME, &secs); 375 + if (ret) 376 + return ret; 377 + 378 + rtc_time64_to_tm(secs, tm); 379 + return rtc_valid_tm(tm); 380 + } 381 + 382 + static int sprd_rtc_set_time(struct device *dev, struct rtc_time *tm) 383 + { 384 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 385 + time64_t secs = rtc_tm_to_time64(tm); 386 + u32 val; 387 + int ret; 388 + 389 + ret = sprd_rtc_set_secs(rtc, SPRD_RTC_TIME, secs); 390 + if (ret) 391 + return ret; 392 + 393 + if (!rtc->valid) { 394 + /* 395 + * Set SPRD_RTC_POWER_RESET_FLAG to indicate now RTC has valid 396 + * time values. 397 + */ 398 + ret = regmap_update_bits(rtc->regmap, 399 + rtc->base + SPRD_RTC_SPG_UPD, 400 + SPRD_RTC_POWER_RESET_FLAG, 401 + SPRD_RTC_POWER_RESET_FLAG); 402 + if (ret) 403 + return ret; 404 + 405 + ret = regmap_read_poll_timeout(rtc->regmap, 406 + rtc->base + SPRD_RTC_INT_RAW_STS, 407 + val, (val & SPRD_RTC_SPG_UPD_EN), 408 + SPRD_RTC_POLL_DELAY_US, 409 + SPRD_RTC_POLL_TIMEOUT); 410 + if (ret) { 411 + dev_err(rtc->dev, "failed to update SPG value:%d\n", 412 + ret); 413 + return ret; 414 + } 415 + 416 + rtc->valid = true; 417 + } 418 + 419 + return 0; 420 + } 421 + 422 + static int sprd_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 423 + { 424 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 425 + time64_t secs; 426 + int ret; 427 + u32 val; 428 + 429 + /* 430 + * If aie_timer is enabled, we should get the normal alarm time. 431 + * Otherwise we should get auxiliary alarm time. 432 + */ 433 + if (rtc->rtc && rtc->rtc->aie_timer.enabled == 0) 434 + return sprd_rtc_read_aux_alarm(dev, alrm); 435 + 436 + ret = sprd_rtc_get_secs(rtc, SPRD_RTC_ALARM, &secs); 437 + if (ret) 438 + return ret; 439 + 440 + rtc_time64_to_tm(secs, &alrm->time); 441 + 442 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, &val); 443 + if (ret) 444 + return ret; 445 + 446 + alrm->enabled = !!(val & SPRD_RTC_ALARM_EN); 447 + 448 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_INT_RAW_STS, &val); 449 + if (ret) 450 + return ret; 451 + 452 + alrm->pending = !!(val & SPRD_RTC_ALARM_EN); 453 + return 0; 454 + } 455 + 456 + static int sprd_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 457 + { 458 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 459 + time64_t secs = rtc_tm_to_time64(&alrm->time); 460 + struct rtc_time aie_time = 461 + rtc_ktime_to_tm(rtc->rtc->aie_timer.node.expires); 462 + int ret; 463 + 464 + /* 465 + * We have 2 groups alarms: normal alarm and auxiliary alarm. Since 466 + * both normal alarm event and auxiliary alarm event can wake up system 467 + * from deep sleep, but only alarm event can power up system from power 468 + * down status. Moreover we do not need to poll about 125ms when 469 + * updating auxiliary alarm registers. Thus we usually set auxiliary 470 + * alarm when wake up system from deep sleep, and for other scenarios, 471 + * we should set normal alarm with polling status. 472 + * 473 + * So here we check if the alarm time is set by aie_timer, if yes, we 474 + * should set normal alarm, if not, we should set auxiliary alarm which 475 + * means it is just a wake event. 476 + */ 477 + if (!rtc->rtc->aie_timer.enabled || rtc_tm_sub(&aie_time, &alrm->time)) 478 + return sprd_rtc_set_aux_alarm(dev, alrm); 479 + 480 + /* clear the alarm interrupt status firstly */ 481 + ret = regmap_write(rtc->regmap, rtc->base + SPRD_RTC_INT_CLR, 482 + SPRD_RTC_ALARM_EN); 483 + if (ret) 484 + return ret; 485 + 486 + ret = sprd_rtc_set_secs(rtc, SPRD_RTC_ALARM, secs); 487 + if (ret) 488 + return ret; 489 + 490 + if (alrm->enabled) { 491 + ret = regmap_update_bits(rtc->regmap, 492 + rtc->base + SPRD_RTC_INT_EN, 493 + SPRD_RTC_ALARM_EN, 494 + SPRD_RTC_ALARM_EN); 495 + if (ret) 496 + return ret; 497 + 498 + /* unlock the alarm to enable the alarm function. */ 499 + ret = sprd_rtc_lock_alarm(rtc, false); 500 + } else { 501 + regmap_update_bits(rtc->regmap, 502 + rtc->base + SPRD_RTC_INT_EN, 503 + SPRD_RTC_ALARM_EN, 0); 504 + 505 + /* 506 + * Lock the alarm function in case fake alarm event will power 507 + * up systems. 508 + */ 509 + ret = sprd_rtc_lock_alarm(rtc, true); 510 + } 511 + 512 + return ret; 513 + } 514 + 515 + static int sprd_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 516 + { 517 + struct sprd_rtc *rtc = dev_get_drvdata(dev); 518 + int ret; 519 + 520 + if (enabled) { 521 + ret = regmap_update_bits(rtc->regmap, 522 + rtc->base + SPRD_RTC_INT_EN, 523 + SPRD_RTC_ALARM_EN | SPRD_RTC_AUXALM_EN, 524 + SPRD_RTC_ALARM_EN | SPRD_RTC_AUXALM_EN); 525 + if (ret) 526 + return ret; 527 + 528 + ret = sprd_rtc_lock_alarm(rtc, false); 529 + } else { 530 + regmap_update_bits(rtc->regmap, rtc->base + SPRD_RTC_INT_EN, 531 + SPRD_RTC_ALARM_EN | SPRD_RTC_AUXALM_EN, 0); 532 + 533 + ret = sprd_rtc_lock_alarm(rtc, true); 534 + } 535 + 536 + return ret; 537 + } 538 + 539 + static const struct rtc_class_ops sprd_rtc_ops = { 540 + .read_time = sprd_rtc_read_time, 541 + .set_time = sprd_rtc_set_time, 542 + .read_alarm = sprd_rtc_read_alarm, 543 + .set_alarm = sprd_rtc_set_alarm, 544 + .alarm_irq_enable = sprd_rtc_alarm_irq_enable, 545 + }; 546 + 547 + static irqreturn_t sprd_rtc_handler(int irq, void *dev_id) 548 + { 549 + struct sprd_rtc *rtc = dev_id; 550 + int ret; 551 + 552 + ret = sprd_rtc_clear_alarm_ints(rtc); 553 + if (ret) 554 + return IRQ_RETVAL(ret); 555 + 556 + rtc_update_irq(rtc->rtc, 1, RTC_AF | RTC_IRQF); 557 + return IRQ_HANDLED; 558 + } 559 + 560 + static int sprd_rtc_check_power_down(struct sprd_rtc *rtc) 561 + { 562 + u32 val; 563 + int ret; 564 + 565 + ret = regmap_read(rtc->regmap, rtc->base + SPRD_RTC_SPG_VALUE, &val); 566 + if (ret) 567 + return ret; 568 + 569 + /* 570 + * If the SPRD_RTC_POWER_RESET_FLAG was not set, which means the RTC has 571 + * been powered down, so the RTC time values are invalid. 572 + */ 573 + rtc->valid = (val & SPRD_RTC_POWER_RESET_FLAG) ? true : false; 574 + return 0; 575 + } 576 + 577 + static int sprd_rtc_probe(struct platform_device *pdev) 578 + { 579 + struct device_node *node = pdev->dev.of_node; 580 + struct sprd_rtc *rtc; 581 + int ret; 582 + 583 + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); 584 + if (!rtc) 585 + return -ENOMEM; 586 + 587 + rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL); 588 + if (!rtc->regmap) 589 + return -ENODEV; 590 + 591 + ret = of_property_read_u32(node, "reg", &rtc->base); 592 + if (ret) { 593 + dev_err(&pdev->dev, "failed to get RTC base address\n"); 594 + return ret; 595 + } 596 + 597 + rtc->irq = platform_get_irq(pdev, 0); 598 + if (rtc->irq < 0) { 599 + dev_err(&pdev->dev, "failed to get RTC irq number\n"); 600 + return rtc->irq; 601 + } 602 + 603 + rtc->dev = &pdev->dev; 604 + platform_set_drvdata(pdev, rtc); 605 + 606 + /* clear all RTC interrupts and disable all RTC interrupts */ 607 + ret = sprd_rtc_disable_ints(rtc); 608 + if (ret) { 609 + dev_err(&pdev->dev, "failed to disable RTC interrupts\n"); 610 + return ret; 611 + } 612 + 613 + /* check if RTC time values are valid */ 614 + ret = sprd_rtc_check_power_down(rtc); 615 + if (ret) { 616 + dev_err(&pdev->dev, "failed to check RTC time values\n"); 617 + return ret; 618 + } 619 + 620 + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 621 + sprd_rtc_handler, 622 + IRQF_ONESHOT | IRQF_EARLY_RESUME, 623 + pdev->name, rtc); 624 + if (ret < 0) { 625 + dev_err(&pdev->dev, "failed to request RTC irq\n"); 626 + return ret; 627 + } 628 + 629 + rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 630 + &sprd_rtc_ops, THIS_MODULE); 631 + if (IS_ERR(rtc->rtc)) 632 + return PTR_ERR(rtc->rtc); 633 + 634 + device_init_wakeup(&pdev->dev, 1); 635 + return 0; 636 + } 637 + 638 + static int sprd_rtc_remove(struct platform_device *pdev) 639 + { 640 + device_init_wakeup(&pdev->dev, 0); 641 + return 0; 642 + } 643 + 644 + static const struct of_device_id sprd_rtc_of_match[] = { 645 + { .compatible = "sprd,sc2731-rtc", }, 646 + { }, 647 + }; 648 + MODULE_DEVICE_TABLE(of, sprd_rtc_of_match); 649 + 650 + static struct platform_driver sprd_rtc_driver = { 651 + .driver = { 652 + .name = "sprd-rtc", 653 + .of_match_table = sprd_rtc_of_match, 654 + }, 655 + .probe = sprd_rtc_probe, 656 + .remove = sprd_rtc_remove, 657 + }; 658 + module_platform_driver(sprd_rtc_driver); 659 + 660 + MODULE_LICENSE("GPL v2"); 661 + MODULE_DESCRIPTION("Spreadtrum RTC Device Driver"); 662 + MODULE_AUTHOR("Baolin Wang <baolin.wang@spreadtrum.com>");
+13 -12
drivers/rtc/rtc-sysfs.c
··· 72 72 73 73 retval = rtc_read_time(to_rtc_device(dev), &tm); 74 74 if (retval == 0) { 75 - unsigned long time; 76 - rtc_tm_to_time(&tm, &time); 77 - retval = sprintf(buf, "%lu\n", time); 75 + time64_t time; 76 + 77 + time = rtc_tm_to_time64(&tm); 78 + retval = sprintf(buf, "%lld\n", time); 78 79 } 79 80 80 81 return retval; ··· 133 132 wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) 134 133 { 135 134 ssize_t retval; 136 - unsigned long alarm; 135 + time64_t alarm; 137 136 struct rtc_wkalrm alm; 138 137 139 138 /* Don't show disabled alarms. For uniformity, RTC alarms are ··· 146 145 */ 147 146 retval = rtc_read_alarm(to_rtc_device(dev), &alm); 148 147 if (retval == 0 && alm.enabled) { 149 - rtc_tm_to_time(&alm.time, &alarm); 150 - retval = sprintf(buf, "%lu\n", alarm); 148 + alarm = rtc_tm_to_time64(&alm.time); 149 + retval = sprintf(buf, "%lld\n", alarm); 151 150 } 152 151 153 152 return retval; ··· 158 157 const char *buf, size_t n) 159 158 { 160 159 ssize_t retval; 161 - unsigned long now, alarm; 162 - unsigned long push = 0; 160 + time64_t now, alarm; 161 + time64_t push = 0; 163 162 struct rtc_wkalrm alm; 164 163 struct rtc_device *rtc = to_rtc_device(dev); 165 164 const char *buf_ptr; ··· 171 170 retval = rtc_read_time(rtc, &alm.time); 172 171 if (retval < 0) 173 172 return retval; 174 - rtc_tm_to_time(&alm.time, &now); 173 + now = rtc_tm_to_time64(&alm.time); 175 174 176 175 buf_ptr = buf; 177 176 if (*buf_ptr == '+') { ··· 182 181 } else 183 182 adjust = 1; 184 183 } 185 - retval = kstrtoul(buf_ptr, 0, &alarm); 184 + retval = kstrtos64(buf_ptr, 0, &alarm); 186 185 if (retval) 187 186 return retval; 188 187 if (adjust) { ··· 198 197 return retval; 199 198 if (alm.enabled) { 200 199 if (push) { 201 - rtc_tm_to_time(&alm.time, &push); 200 + push = rtc_tm_to_time64(&alm.time); 202 201 alarm += push; 203 202 } else 204 203 return -EBUSY; ··· 213 212 */ 214 213 alarm = now + 300; 215 214 } 216 - rtc_time_to_tm(alarm, &alm.time); 215 + rtc_time64_to_tm(alarm, &alm.time); 217 216 218 217 retval = rtc_set_alarm(rtc, &alm); 219 218 return (retval < 0) ? retval : n;
+34 -13
drivers/rtc/rtc-xgene.c
··· 52 52 void __iomem *csr_base; 53 53 struct clk *clk; 54 54 unsigned int irq_wake; 55 + unsigned int irq_enabled; 55 56 }; 56 57 57 58 static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm) ··· 105 104 return 0; 106 105 } 107 106 107 + static int xgene_rtc_alarm_irq_enabled(struct device *dev) 108 + { 109 + struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 110 + 111 + return readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE ? 1 : 0; 112 + } 113 + 108 114 static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 109 115 { 110 116 struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); 111 - unsigned long rtc_time; 112 117 unsigned long alarm_time; 113 118 114 - rtc_time = readl(pdata->csr_base + RTC_CCVR); 115 119 rtc_tm_to_time(&alrm->time, &alarm_time); 116 - 117 120 pdata->alarm_time = alarm_time; 118 121 writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR); 119 122 ··· 185 180 dev_err(&pdev->dev, "Couldn't get the clock for RTC\n"); 186 181 return -ENODEV; 187 182 } 188 - clk_prepare_enable(pdata->clk); 183 + ret = clk_prepare_enable(pdata->clk); 184 + if (ret) 185 + return ret; 189 186 190 187 /* Turn on the clock and the crystal */ 191 188 writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR); 192 189 193 - device_init_wakeup(&pdev->dev, 1); 190 + ret = device_init_wakeup(&pdev->dev, 1); 191 + if (ret) { 192 + clk_disable_unprepare(pdata->clk); 193 + return ret; 194 + } 194 195 195 196 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 196 197 &xgene_rtc_ops, THIS_MODULE); ··· 221 210 return 0; 222 211 } 223 212 224 - #ifdef CONFIG_PM_SLEEP 225 - static int xgene_rtc_suspend(struct device *dev) 213 + static int __maybe_unused xgene_rtc_suspend(struct device *dev) 226 214 { 227 215 struct platform_device *pdev = to_platform_device(dev); 228 216 struct xgene_rtc_dev *pdata = platform_get_drvdata(pdev); 229 217 int irq; 230 218 231 219 irq = platform_get_irq(pdev, 0); 220 + 221 + /* 222 + * If this RTC alarm will be used for waking the system up, 223 + * don't disable it of course. Else we just disable the alarm 224 + * and await suspension. 225 + */ 232 226 if (device_may_wakeup(&pdev->dev)) { 233 227 if (!enable_irq_wake(irq)) 234 228 pdata->irq_wake = 1; 235 229 } else { 230 + pdata->irq_enabled = xgene_rtc_alarm_irq_enabled(dev); 236 231 xgene_rtc_alarm_irq_enable(dev, 0); 237 - clk_disable(pdata->clk); 232 + clk_disable_unprepare(pdata->clk); 238 233 } 239 - 240 234 return 0; 241 235 } 242 236 243 - static int xgene_rtc_resume(struct device *dev) 237 + static int __maybe_unused xgene_rtc_resume(struct device *dev) 244 238 { 245 239 struct platform_device *pdev = to_platform_device(dev); 246 240 struct xgene_rtc_dev *pdata = platform_get_drvdata(pdev); 247 241 int irq; 242 + int rc; 248 243 249 244 irq = platform_get_irq(pdev, 0); 245 + 250 246 if (device_may_wakeup(&pdev->dev)) { 251 247 if (pdata->irq_wake) { 252 248 disable_irq_wake(irq); 253 249 pdata->irq_wake = 0; 254 250 } 255 251 } else { 256 - clk_enable(pdata->clk); 257 - xgene_rtc_alarm_irq_enable(dev, 1); 252 + rc = clk_prepare_enable(pdata->clk); 253 + if (rc) { 254 + dev_err(dev, "Unable to enable clock error %d\n", rc); 255 + return rc; 256 + } 257 + xgene_rtc_alarm_irq_enable(dev, pdata->irq_enabled); 258 258 } 259 259 260 260 return 0; 261 261 } 262 - #endif 263 262 264 263 static SIMPLE_DEV_PM_OPS(xgene_rtc_pm_ops, xgene_rtc_suspend, xgene_rtc_resume); 265 264