aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-21 13:42:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-21 13:42:11 -0400
commit63d222b9d277c4d7bf08afd1631a7f8e327a825c (patch)
tree5a7167eebe02730c62b3137c9b9e89fa45329db7
parent10cd7158042bf9c949c19dbf0c7ee600d198ed39 (diff)
parentb9ba1eb0336877b9b83556fd30d2becda110fd8c (diff)
Merge tag 'rtc-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "Subsystem wide cleanups: - Use IS_ENABLED() instead of checking for built-in or module - remove useless DRV_VERSION - remove CLK_IS_ROOT - remove UIE signaling Drivers: - ds1302: rewritten to be a proper SPI device driver - m41t80: huge cleanup, alarm, wakelarm ans oscialltor failure detection support - rv3029: switch to regmap to handle rv3049, alarm support, fixes - zynqmp: enable switching to battery power, fixes - small fixes for at91sam9, da9053, ds1307, ds1685, ds3232, r2025, sa1100, snvs, stmp3xxx, tps6586x" * tag 'rtc-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (40 commits) rtc: tps6586x: rename so module can be autoloaded rtc: rv3029: hide unused i2c device table rtc: rs5c372: r2025: fix check for 'oscillator halted' condition rtc: rv3029: add alarm IRQ rtc: rv3029: fix set_time function rtc: rv3029: fix alarm support rtc: rv3029: Remove some checks and warnings rtc: rv3029: Add support of RV3049 rtc: rv3029: convert to use regmap rtc: rv3029: remove 'i2c' in functions names rtc: stmp3xxx: print message on error rtc: Use IS_ENABLED() instead of checking for built-in or module rtc: ds3232: fix call trace when rtc->ops_lock is used as NULL rtc: snvs: return error in case enable_irq_wake fails rtc: zynqmp: Update seconds time programming logic rtc: sa1100: DT spelling s/interrupt-name/interrupt-names/ rtc: mc13xxx: remove UIE signaling rtc: mxc: remove UIE signaling rtc: ds1307: Remove CLK_IS_ROOT rtc: hym8563: Remove CLK_IS_ROOT ...
-rw-r--r--Documentation/devicetree/bindings/rtc/maxim-ds1302.txt46
-rw-r--r--Documentation/devicetree/bindings/rtc/sa1100-rtc.txt2
-rw-r--r--drivers/rtc/Kconfig52
-rw-r--r--drivers/rtc/rtc-at91sam9.c2
-rw-r--r--drivers/rtc/rtc-cmos.c2
-rw-r--r--drivers/rtc/rtc-da9052.c13
-rw-r--r--drivers/rtc/rtc-ds1216.c3
-rw-r--r--drivers/rtc/rtc-ds1286.c3
-rw-r--r--drivers/rtc/rtc-ds1302.c348
-rw-r--r--drivers/rtc/rtc-ds1307.c23
-rw-r--r--drivers/rtc/rtc-ds1343.c2
-rw-r--r--drivers/rtc/rtc-ds1511.c3
-rw-r--r--drivers/rtc/rtc-ds1553.c3
-rw-r--r--drivers/rtc/rtc-ds1672.c5
-rw-r--r--drivers/rtc/rtc-ds1685.c4
-rw-r--r--drivers/rtc/rtc-ds1742.c3
-rw-r--r--drivers/rtc/rtc-ds3232.c9
-rw-r--r--drivers/rtc/rtc-ep93xx.c3
-rw-r--r--drivers/rtc/rtc-gemini.c1
-rw-r--r--drivers/rtc/rtc-hym8563.c2
-rw-r--r--drivers/rtc/rtc-isl12022.c5
-rw-r--r--drivers/rtc/rtc-isl1208.c6
-rw-r--r--drivers/rtc/rtc-m41t80.c447
-rw-r--r--drivers/rtc/rtc-m48t35.c3
-rw-r--r--drivers/rtc/rtc-m48t86.c4
-rw-r--r--drivers/rtc/rtc-max6900.c5
-rw-r--r--drivers/rtc/rtc-mc13xxx.c19
-rw-r--r--drivers/rtc/rtc-mrst.c2
-rw-r--r--drivers/rtc/rtc-mxc.c3
-rw-r--r--drivers/rtc/rtc-pcf2123.c4
-rw-r--r--drivers/rtc/rtc-pcf8563.c7
-rw-r--r--drivers/rtc/rtc-rs5c313.c2
-rw-r--r--drivers/rtc/rtc-rs5c348.c4
-rw-r--r--drivers/rtc/rtc-rs5c372.c18
-rw-r--r--drivers/rtc/rtc-rv3029c2.c596
-rw-r--r--drivers/rtc/rtc-rx8581.c5
-rw-r--r--drivers/rtc/rtc-sh.c2
-rw-r--r--drivers/rtc/rtc-snvs.c2
-rw-r--r--drivers/rtc/rtc-stk17ta8.c3
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c7
-rw-r--r--drivers/rtc/rtc-tps6586x.c2
-rw-r--r--drivers/rtc/rtc-x1205.c5
-rw-r--r--drivers/rtc/rtc-zynqmp.c74
43 files changed, 1019 insertions, 735 deletions
diff --git a/Documentation/devicetree/bindings/rtc/maxim-ds1302.txt b/Documentation/devicetree/bindings/rtc/maxim-ds1302.txt
new file mode 100644
index 000000000000..ba470c56cdec
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/maxim-ds1302.txt
@@ -0,0 +1,46 @@
1* Maxim/Dallas Semiconductor DS-1302 RTC
2
3Simple device which could be used to store date/time between reboots.
4
5The device uses the standard MicroWire half-duplex transfer timing.
6Master output is set on low clock and sensed by the RTC on the rising
7edge. Master input is set by the RTC on the trailing edge and is sensed
8by the master on low clock.
9
10Required properties:
11
12- compatible : Should be "maxim,ds1302"
13
14Required SPI properties:
15
16- reg : Should be address of the device chip select within
17 the controller.
18
19- spi-max-frequency : DS-1302 has 500 kHz if powered at 2.2V,
20 and 2MHz if powered at 5V.
21
22- spi-3wire : The device has a shared signal IN/OUT line.
23
24- spi-lsb-first : DS-1302 requires least significant bit first
25 transfers.
26
27- spi-cs-high: DS-1302 has active high chip select line. This is
28 required unless inverted in hardware.
29
30Example:
31
32spi@901c {
33 #address-cells = <1>;
34 #size-cells = <0>;
35 compatible = "icpdas,lp8841-spi-rtc";
36 reg = <0x901c 0x1>;
37
38 rtc@0 {
39 compatible = "maxim,ds1302";
40 reg = <0>;
41 spi-max-frequency = <500000>;
42 spi-3wire;
43 spi-lsb-first;
44 spi-cs-high;
45 };
46};
diff --git a/Documentation/devicetree/bindings/rtc/sa1100-rtc.txt b/Documentation/devicetree/bindings/rtc/sa1100-rtc.txt
index 0cda19ad4859..968ac820254b 100644
--- a/Documentation/devicetree/bindings/rtc/sa1100-rtc.txt
+++ b/Documentation/devicetree/bindings/rtc/sa1100-rtc.txt
@@ -13,5 +13,5 @@ Example:
13 compatible = "mrvl,mmp-rtc"; 13 compatible = "mrvl,mmp-rtc";
14 reg = <0xd4010000 0x1000>; 14 reg = <0xd4010000 0x1000>;
15 interrupts = <5>, <6>; 15 interrupts = <5>, <6>;
16 interrupt-name = "rtc 1Hz", "rtc alarm"; 16 interrupt-names = "rtc 1Hz", "rtc alarm";
17 }; 17 };
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 3e84315c6f12..18639e0cb6e2 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -573,24 +573,6 @@ config RTC_DRV_EM3027
573 This driver can also be built as a module. If so, the module 573 This driver can also be built as a module. If so, the module
574 will be called rtc-em3027. 574 will be called rtc-em3027.
575 575
576config RTC_DRV_RV3029C2
577 tristate "Micro Crystal RV3029"
578 help
579 If you say yes here you get support for the Micro Crystal
580 RV3029 RTC chips.
581
582 This driver can also be built as a module. If so, the module
583 will be called rtc-rv3029c2.
584
585config RTC_DRV_RV3029_HWMON
586 bool "HWMON support for RV3029"
587 depends on RTC_DRV_RV3029C2 && HWMON
588 depends on !(RTC_DRV_RV3029C2=y && HWMON=m)
589 default y
590 help
591 Say Y here if you want to expose temperature sensor data on
592 rtc-rv3029.
593
594config RTC_DRV_RV8803 576config RTC_DRV_RV8803
595 tristate "Micro Crystal RV8803" 577 tristate "Micro Crystal RV8803"
596 help 578 help
@@ -634,6 +616,15 @@ config RTC_DRV_M41T94
634 This driver can also be built as a module. If so, the module 616 This driver can also be built as a module. If so, the module
635 will be called rtc-m41t94. 617 will be called rtc-m41t94.
636 618
619config RTC_DRV_DS1302
620 tristate "Dallas/Maxim DS1302"
621 depends on SPI
622 help
623 If you say yes here you get support for the Dallas DS1302 RTC chips.
624
625 This driver can also be built as a module. If so, the module
626 will be called rtc-ds1302.
627
637config RTC_DRV_DS1305 628config RTC_DRV_DS1305
638 tristate "Dallas/Maxim DS1305/DS1306" 629 tristate "Dallas/Maxim DS1305/DS1306"
639 help 630 help
@@ -777,6 +768,25 @@ config RTC_DRV_PCF2127
777 This driver can also be built as a module. If so, the module 768 This driver can also be built as a module. If so, the module
778 will be called rtc-pcf2127. 769 will be called rtc-pcf2127.
779 770
771config RTC_DRV_RV3029C2
772 tristate "Micro Crystal RV3029/3049"
773 depends on RTC_I2C_AND_SPI
774 help
775 If you say yes here you get support for the Micro Crystal
776 RV3029 and RV3049 RTC chips.
777
778 This driver can also be built as a module. If so, the module
779 will be called rtc-rv3029c2.
780
781config RTC_DRV_RV3029_HWMON
782 bool "HWMON support for RV3029/3049"
783 depends on RTC_DRV_RV3029C2 && HWMON
784 depends on !(RTC_DRV_RV3029C2=y && HWMON=m)
785 default y
786 help
787 Say Y here if you want to expose temperature sensor data on
788 rtc-rv3029.
789
780comment "Platform RTC drivers" 790comment "Platform RTC drivers"
781 791
782# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h> 792# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h>
@@ -834,12 +844,6 @@ config RTC_DRV_DS1286
834 help 844 help
835 If you say yes here you get support for the Dallas DS1286 RTC chips. 845 If you say yes here you get support for the Dallas DS1286 RTC chips.
836 846
837config RTC_DRV_DS1302
838 tristate "Dallas DS1302"
839 depends on SH_SECUREEDGE5410
840 help
841 If you say yes here you get support for the Dallas DS1302 RTC chips.
842
843config RTC_DRV_DS1511 847config RTC_DRV_DS1511
844 tristate "Dallas DS1511" 848 tristate "Dallas DS1511"
845 depends on HAS_IOMEM 849 depends on HAS_IOMEM
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 7206e2fa4383..99732e6f8c3b 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -268,7 +268,7 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
268static int at91_rtc_proc(struct device *dev, struct seq_file *seq) 268static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
269{ 269{
270 struct sam9_rtc *rtc = dev_get_drvdata(dev); 270 struct sam9_rtc *rtc = dev_get_drvdata(dev);
271 u32 mr = mr = rtt_readl(rtc, MR); 271 u32 mr = rtt_readl(rtc, MR);
272 272
273 seq_printf(seq, "update_IRQ\t: %s\n", 273 seq_printf(seq, "update_IRQ\t: %s\n",
274 (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no"); 274 (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 84fb541038be..fbe9c72438e1 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -401,7 +401,7 @@ static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled)
401 return 0; 401 return 0;
402} 402}
403 403
404#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 404#if IS_ENABLED(CONFIG_RTC_INTF_PROC)
405 405
406static int cmos_procfs(struct device *dev, struct seq_file *seq) 406static int cmos_procfs(struct device *dev, struct seq_file *seq)
407{ 407{
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 1ba4371cbc2d..a20bcf0e33cd 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -302,6 +302,13 @@ static int da9052_rtc_probe(struct platform_device *pdev)
302 if (ret != 0) 302 if (ret != 0)
303 rtc_err(rtc, "Failed to disable TICKS: %d\n", ret); 303 rtc_err(rtc, "Failed to disable TICKS: %d\n", ret);
304 304
305 device_init_wakeup(&pdev->dev, true);
306 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
307 &da9052_rtc_ops, THIS_MODULE);
308
309 if (IS_ERR(rtc->rtc))
310 return PTR_ERR(rtc->rtc);
311
305 ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM", 312 ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM",
306 da9052_rtc_irq, rtc); 313 da9052_rtc_irq, rtc);
307 if (ret != 0) { 314 if (ret != 0) {
@@ -309,11 +316,7 @@ static int da9052_rtc_probe(struct platform_device *pdev)
309 return ret; 316 return ret;
310 } 317 }
311 318
312 device_init_wakeup(&pdev->dev, true); 319 return 0;
313
314 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
315 &da9052_rtc_ops, THIS_MODULE);
316 return PTR_ERR_OR_ZERO(rtc->rtc);
317} 320}
318 321
319static struct platform_driver da9052_rtc_driver = { 322static struct platform_driver da9052_rtc_driver = {
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 12dbd70859ae..9c82b1da2d45 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -11,8 +11,6 @@
11#include <linux/bcd.h> 11#include <linux/bcd.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13 13
14#define DRV_VERSION "0.2"
15
16struct ds1216_regs { 14struct ds1216_regs {
17 u8 tsec; 15 u8 tsec;
18 u8 sec; 16 u8 sec;
@@ -176,5 +174,4 @@ module_platform_driver_probe(ds1216_rtc_platform_driver, ds1216_rtc_probe);
176MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>"); 174MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
177MODULE_DESCRIPTION("DS1216 RTC driver"); 175MODULE_DESCRIPTION("DS1216 RTC driver");
178MODULE_LICENSE("GPL"); 176MODULE_LICENSE("GPL");
179MODULE_VERSION(DRV_VERSION);
180MODULE_ALIAS("platform:rtc-ds1216"); 177MODULE_ALIAS("platform:rtc-ds1216");
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index 8247a29a4eb4..756e509f6ed2 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -20,8 +20,6 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22 22
23#define DRV_VERSION "1.0"
24
25struct ds1286_priv { 23struct ds1286_priv {
26 struct rtc_device *rtc; 24 struct rtc_device *rtc;
27 u32 __iomem *rtcregs; 25 u32 __iomem *rtcregs;
@@ -363,5 +361,4 @@ module_platform_driver(ds1286_platform_driver);
363MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>"); 361MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
364MODULE_DESCRIPTION("DS1286 RTC driver"); 362MODULE_DESCRIPTION("DS1286 RTC driver");
365MODULE_LICENSE("GPL"); 363MODULE_LICENSE("GPL");
366MODULE_VERSION(DRV_VERSION);
367MODULE_ALIAS("platform:rtc-ds1286"); 364MODULE_ALIAS("platform:rtc-ds1286");
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index 6bef7a5233c4..f5dd09fe5add 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -9,16 +9,16 @@
9 * this archive for more details. 9 * this archive for more details.
10 */ 10 */
11 11
12#include <linux/bcd.h>
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/module.h> 14#include <linux/io.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/platform_device.h> 16#include <linux/module.h>
17#include <linux/of.h>
16#include <linux/rtc.h> 18#include <linux/rtc.h>
17#include <linux/io.h> 19#include <linux/spi/spi.h>
18#include <linux/bcd.h>
19 20
20#define DRV_NAME "rtc-ds1302" 21#define DRV_NAME "rtc-ds1302"
21#define DRV_VERSION "0.1.1"
22 22
23#define RTC_CMD_READ 0x81 /* Read command */ 23#define RTC_CMD_READ 0x81 /* Read command */
24#define RTC_CMD_WRITE 0x80 /* Write command */ 24#define RTC_CMD_WRITE 0x80 /* Write command */
@@ -28,6 +28,8 @@
28 28
29#define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */ 29#define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */
30#define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */ 30#define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */
31#define RTC_CLCK_BURST 0x1F /* Address of clock burst */
32#define RTC_CLCK_LEN 0x08 /* Size of clock burst */
31#define RTC_ADDR_CTRL 0x07 /* Address of control register */ 33#define RTC_ADDR_CTRL 0x07 /* Address of control register */
32#define RTC_ADDR_YEAR 0x06 /* Address of year register */ 34#define RTC_ADDR_YEAR 0x06 /* Address of year register */
33#define RTC_ADDR_DAY 0x05 /* Address of day of week register */ 35#define RTC_ADDR_DAY 0x05 /* Address of day of week register */
@@ -37,219 +39,181 @@
37#define RTC_ADDR_MIN 0x01 /* Address of minute register */ 39#define RTC_ADDR_MIN 0x01 /* Address of minute register */
38#define RTC_ADDR_SEC 0x00 /* Address of second register */ 40#define RTC_ADDR_SEC 0x00 /* Address of second register */
39 41
40#ifdef CONFIG_SH_SECUREEDGE5410 42static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *time)
41#include <asm/rtc.h>
42#include <mach/secureedge5410.h>
43
44#define RTC_RESET 0x1000
45#define RTC_IODATA 0x0800
46#define RTC_SCLK 0x0400
47
48#define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00)
49#define get_dp() SECUREEDGE_READ_IOPORT()
50#define ds1302_set_tx()
51#define ds1302_set_rx()
52
53static inline int ds1302_hw_init(void)
54{ 43{
55 return 0; 44 struct spi_device *spi = dev_get_drvdata(dev);
45 u8 buf[1 + RTC_CLCK_LEN];
46 u8 *bp = buf;
47 int status;
48
49 /* Enable writing */
50 bp = buf;
51 *bp++ = RTC_ADDR_CTRL << 1 | RTC_CMD_WRITE;
52 *bp++ = RTC_CMD_WRITE_ENABLE;
53
54 status = spi_write_then_read(spi, buf, 2,
55 NULL, 0);
56 if (status)
57 return status;
58
59 /* Write registers starting at the first time/date address. */
60 bp = buf;
61 *bp++ = RTC_CLCK_BURST << 1 | RTC_CMD_WRITE;
62
63 *bp++ = bin2bcd(time->tm_sec);
64 *bp++ = bin2bcd(time->tm_min);
65 *bp++ = bin2bcd(time->tm_hour);
66 *bp++ = bin2bcd(time->tm_mday);
67 *bp++ = bin2bcd(time->tm_mon + 1);
68 *bp++ = time->tm_wday + 1;
69 *bp++ = bin2bcd(time->tm_year % 100);
70 *bp++ = RTC_CMD_WRITE_DISABLE;
71
72 /* use write-then-read since dma from stack is nonportable */
73 return spi_write_then_read(spi, buf, sizeof(buf),
74 NULL, 0);
56} 75}
57 76
58static inline void ds1302_reset(void) 77static int ds1302_rtc_get_time(struct device *dev, struct rtc_time *time)
59{ 78{
60 set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK)); 79 struct spi_device *spi = dev_get_drvdata(dev);
80 u8 addr = RTC_CLCK_BURST << 1 | RTC_CMD_READ;
81 u8 buf[RTC_CLCK_LEN - 1];
82 int status;
83
84 /* Use write-then-read to get all the date/time registers
85 * since dma from stack is nonportable
86 */
87 status = spi_write_then_read(spi, &addr, sizeof(addr),
88 buf, sizeof(buf));
89 if (status < 0)
90 return status;
91
92 /* Decode the registers */
93 time->tm_sec = bcd2bin(buf[RTC_ADDR_SEC]);
94 time->tm_min = bcd2bin(buf[RTC_ADDR_MIN]);
95 time->tm_hour = bcd2bin(buf[RTC_ADDR_HOUR]);
96 time->tm_wday = buf[RTC_ADDR_DAY] - 1;
97 time->tm_mday = bcd2bin(buf[RTC_ADDR_DATE]);
98 time->tm_mon = bcd2bin(buf[RTC_ADDR_MON]) - 1;
99 time->tm_year = bcd2bin(buf[RTC_ADDR_YEAR]) + 100;
100
101 /* Time may not be set */
102 return rtc_valid_tm(time);
61} 103}
62 104
63static inline void ds1302_clock(void) 105static struct rtc_class_ops ds1302_rtc_ops = {
64{ 106 .read_time = ds1302_rtc_get_time,
65 set_dp(get_dp() | RTC_SCLK); /* clock high */ 107 .set_time = ds1302_rtc_set_time,
66 set_dp(get_dp() & ~RTC_SCLK); /* clock low */ 108};
67}
68
69static inline void ds1302_start(void)
70{
71 set_dp(get_dp() | RTC_RESET);
72}
73
74static inline void ds1302_stop(void)
75{
76 set_dp(get_dp() & ~RTC_RESET);
77}
78
79static inline void ds1302_txbit(int bit)
80{
81 set_dp((get_dp() & ~RTC_IODATA) | (bit ? RTC_IODATA : 0));
82}
83
84static inline int ds1302_rxbit(void)
85{
86 return !!(get_dp() & RTC_IODATA);
87}
88
89#else
90#error "Add support for your platform"
91#endif
92 109
93static void ds1302_sendbits(unsigned int val) 110static int ds1302_probe(struct spi_device *spi)
94{ 111{
95 int i; 112 struct rtc_device *rtc;
96 113 u8 addr;
97 ds1302_set_tx(); 114 u8 buf[4];
98 115 u8 *bp = buf;
99 for (i = 8; (i); i--, val >>= 1) { 116 int status;
100 ds1302_txbit(val & 0x1); 117
101 ds1302_clock(); 118 /* Sanity check board setup data. This may be hooked up
119 * in 3wire mode, but we don't care. Note that unless
120 * there's an inverter in place, this needs SPI_CS_HIGH!
121 */
122 if (spi->bits_per_word && (spi->bits_per_word != 8)) {
123 dev_err(&spi->dev, "bad word length\n");
124 return -EINVAL;
125 } else if (spi->max_speed_hz > 2000000) {
126 dev_err(&spi->dev, "speed is too high\n");
127 return -EINVAL;
128 } else if (spi->mode & SPI_CPHA) {
129 dev_err(&spi->dev, "bad mode\n");
130 return -EINVAL;
102 } 131 }
103}
104
105static unsigned int ds1302_recvbits(void)
106{
107 unsigned int val;
108 int i;
109
110 ds1302_set_rx();
111 132
112 for (i = 0, val = 0; (i < 8); i++) { 133 addr = RTC_ADDR_CTRL << 1 | RTC_CMD_READ;
113 val |= (ds1302_rxbit() << i); 134 status = spi_write_then_read(spi, &addr, sizeof(addr), buf, 1);
114 ds1302_clock(); 135 if (status < 0) {
136 dev_err(&spi->dev, "control register read error %d\n",
137 status);
138 return status;
115 } 139 }
116 140
117 return val; 141 if ((buf[0] & ~RTC_CMD_WRITE_DISABLE) != 0) {
118} 142 status = spi_write_then_read(spi, &addr, sizeof(addr), buf, 1);
119 143 if (status < 0) {
120static unsigned int ds1302_readbyte(unsigned int addr) 144 dev_err(&spi->dev, "control register read error %d\n",
121{ 145 status);
122 unsigned int val; 146 return status;
123 147 }
124 ds1302_reset(); 148
125 149 if ((buf[0] & ~RTC_CMD_WRITE_DISABLE) != 0) {
126 ds1302_start(); 150 dev_err(&spi->dev, "junk in control register\n");
127 ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_READ); 151 return -ENODEV;
128 val = ds1302_recvbits(); 152 }
129 ds1302_stop(); 153 }
130 154 if (buf[0] == 0) {
131 return val; 155 bp = buf;
132} 156 *bp++ = RTC_ADDR_CTRL << 1 | RTC_CMD_WRITE;
133 157 *bp++ = RTC_CMD_WRITE_DISABLE;
134static void ds1302_writebyte(unsigned int addr, unsigned int val) 158
135{ 159 status = spi_write_then_read(spi, buf, 2, NULL, 0);
136 ds1302_reset(); 160 if (status < 0) {
137 161 dev_err(&spi->dev, "control register write error %d\n",
138 ds1302_start(); 162 status);
139 ds1302_sendbits(((addr & 0x3f) << 1) | RTC_CMD_WRITE); 163 return status;
140 ds1302_sendbits(val); 164 }
141 ds1302_stop(); 165
142} 166 addr = RTC_ADDR_CTRL << 1 | RTC_CMD_READ;
143 167 status = spi_write_then_read(spi, &addr, sizeof(addr), buf, 1);
144static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm) 168 if (status < 0) {
145{ 169 dev_err(&spi->dev,
146 tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC)); 170 "error %d reading control register\n",
147 tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN)); 171 status);
148 tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR)); 172 return status;
149 tm->tm_wday = bcd2bin(ds1302_readbyte(RTC_ADDR_DAY)); 173 }
150 tm->tm_mday = bcd2bin(ds1302_readbyte(RTC_ADDR_DATE)); 174
151 tm->tm_mon = bcd2bin(ds1302_readbyte(RTC_ADDR_MON)) - 1; 175 if (buf[0] != RTC_CMD_WRITE_DISABLE) {
152 tm->tm_year = bcd2bin(ds1302_readbyte(RTC_ADDR_YEAR)); 176 dev_err(&spi->dev, "failed to detect chip\n");
153 177 return -ENODEV;
154 if (tm->tm_year < 70) 178 }
155 tm->tm_year += 100; 179 }
156
157 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
158 "mday=%d, mon=%d, year=%d, wday=%d\n",
159 __func__,
160 tm->tm_sec, tm->tm_min, tm->tm_hour,
161 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
162
163 return rtc_valid_tm(tm);
164}
165
166static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
167{
168 ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_ENABLE);
169 /* Stop RTC */
170 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
171
172 ds1302_writebyte(RTC_ADDR_SEC, bin2bcd(tm->tm_sec));
173 ds1302_writebyte(RTC_ADDR_MIN, bin2bcd(tm->tm_min));
174 ds1302_writebyte(RTC_ADDR_HOUR, bin2bcd(tm->tm_hour));
175 ds1302_writebyte(RTC_ADDR_DAY, bin2bcd(tm->tm_wday));
176 ds1302_writebyte(RTC_ADDR_DATE, bin2bcd(tm->tm_mday));
177 ds1302_writebyte(RTC_ADDR_MON, bin2bcd(tm->tm_mon + 1));
178 ds1302_writebyte(RTC_ADDR_YEAR, bin2bcd(tm->tm_year % 100));
179 180
180 /* Start RTC */ 181 spi_set_drvdata(spi, spi);
181 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
182 182
183 ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_DISABLE); 183 rtc = devm_rtc_device_register(&spi->dev, "ds1302",
184 &ds1302_rtc_ops, THIS_MODULE);
185 if (IS_ERR(rtc)) {
186 status = PTR_ERR(rtc);
187 dev_err(&spi->dev, "error %d registering rtc\n", status);
188 return status;
189 }
184 190
185 return 0; 191 return 0;
186} 192}
187 193
188static int ds1302_rtc_ioctl(struct device *dev, unsigned int cmd, 194static int ds1302_remove(struct spi_device *spi)
189 unsigned long arg)
190{ 195{
191 switch (cmd) { 196 spi_set_drvdata(spi, NULL);
192#ifdef RTC_SET_CHARGE 197 return 0;
193 case RTC_SET_CHARGE:
194 {
195 int tcs_val;
196
197 if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
198 return -EFAULT;
199
200 ds1302_writebyte(RTC_ADDR_TCR, (0xa0 | tcs_val * 0xf));
201 return 0;
202 }
203#endif
204 }
205
206 return -ENOIOCTLCMD;
207} 198}
208 199
209static struct rtc_class_ops ds1302_rtc_ops = { 200#ifdef CONFIG_OF
210 .read_time = ds1302_rtc_read_time, 201static const struct of_device_id ds1302_dt_ids[] = {
211 .set_time = ds1302_rtc_set_time, 202 { .compatible = "maxim,ds1302", },
212 .ioctl = ds1302_rtc_ioctl, 203 { /* sentinel */ }
213}; 204};
205MODULE_DEVICE_TABLE(of, ds1302_dt_ids);
206#endif
214 207
215static int __init ds1302_rtc_probe(struct platform_device *pdev) 208static struct spi_driver ds1302_driver = {
216{ 209 .driver.name = "rtc-ds1302",
217 struct rtc_device *rtc; 210 .driver.of_match_table = of_match_ptr(ds1302_dt_ids),
218 211 .probe = ds1302_probe,
219 if (ds1302_hw_init()) { 212 .remove = ds1302_remove,
220 dev_err(&pdev->dev, "Failed to init communication channel");
221 return -EINVAL;
222 }
223
224 /* Reset */
225 ds1302_reset();
226
227 /* Write a magic value to the DS1302 RAM, and see if it sticks. */
228 ds1302_writebyte(RTC_ADDR_RAM0, 0x42);
229 if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42) {
230 dev_err(&pdev->dev, "Failed to probe");
231 return -ENODEV;
232 }
233
234 rtc = devm_rtc_device_register(&pdev->dev, "ds1302",
235 &ds1302_rtc_ops, THIS_MODULE);
236 if (IS_ERR(rtc))
237 return PTR_ERR(rtc);
238
239 platform_set_drvdata(pdev, rtc);
240
241 return 0;
242}
243
244static struct platform_driver ds1302_platform_driver = {
245 .driver = {
246 .name = DRV_NAME,
247 },
248}; 213};
249 214
250module_platform_driver_probe(ds1302_platform_driver, ds1302_rtc_probe); 215module_spi_driver(ds1302_driver);
251 216
252MODULE_DESCRIPTION("Dallas DS1302 RTC driver"); 217MODULE_DESCRIPTION("Dallas DS1302 RTC driver");
253MODULE_VERSION(DRV_VERSION);
254MODULE_AUTHOR("Paul Mundt, David McCullough"); 218MODULE_AUTHOR("Paul Mundt, David McCullough");
255MODULE_LICENSE("GPL v2"); 219MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index ecb7dbae9be9..821d9c089cdb 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -275,9 +275,13 @@ static s32 ds1307_native_smbus_write_block_data(const struct i2c_client *client,
275{ 275{
276 u8 suboffset = 0; 276 u8 suboffset = 0;
277 277
278 if (length <= I2C_SMBUS_BLOCK_MAX) 278 if (length <= I2C_SMBUS_BLOCK_MAX) {
279 return i2c_smbus_write_i2c_block_data(client, 279 s32 retval = i2c_smbus_write_i2c_block_data(client,
280 command, length, values); 280 command, length, values);
281 if (retval < 0)
282 return retval;
283 return length;
284 }
281 285
282 while (suboffset < length) { 286 while (suboffset < length) {
283 s32 retval = i2c_smbus_write_i2c_block_data(client, 287 s32 retval = i2c_smbus_write_i2c_block_data(client,
@@ -538,12 +542,8 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t)
538 buf[5] = 0; 542 buf[5] = 0;
539 buf[6] = 0; 543 buf[6] = 0;
540 544
541 /* optionally enable ALARM1 */ 545 /* disable alarms */
542 buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE); 546 buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE);
543 if (t->enabled) {
544 dev_dbg(dev, "alarm IRQ armed\n");
545 buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
546 }
547 buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I); 547 buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I);
548 548
549 ret = ds1307->write_block_data(client, 549 ret = ds1307->write_block_data(client,
@@ -553,6 +553,13 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t)
553 return ret; 553 return ret;
554 } 554 }
555 555
556 /* optionally enable ALARM1 */
557 if (t->enabled) {
558 dev_dbg(dev, "alarm IRQ armed\n");
559 buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
560 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, buf[7]);
561 }
562
556 return 0; 563 return 0;
557} 564}
558 565
@@ -1144,12 +1151,10 @@ static struct clk_init_data ds3231_clks_init[] = {
1144 [DS3231_CLK_SQW] = { 1151 [DS3231_CLK_SQW] = {
1145 .name = "ds3231_clk_sqw", 1152 .name = "ds3231_clk_sqw",
1146 .ops = &ds3231_clk_sqw_ops, 1153 .ops = &ds3231_clk_sqw_ops,
1147 .flags = CLK_IS_ROOT,
1148 }, 1154 },
1149 [DS3231_CLK_32KHZ] = { 1155 [DS3231_CLK_32KHZ] = {
1150 .name = "ds3231_clk_32khz", 1156 .name = "ds3231_clk_32khz",
1151 .ops = &ds3231_clk_32khz_ops, 1157 .ops = &ds3231_clk_32khz_ops,
1152 .flags = CLK_IS_ROOT,
1153 }, 1158 },
1154}; 1159};
1155 1160
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c
index 3d389bd8a289..23fa9f0cb5e3 100644
--- a/drivers/rtc/rtc-ds1343.c
+++ b/drivers/rtc/rtc-ds1343.c
@@ -24,7 +24,6 @@
24#include <linux/pm_wakeirq.h> 24#include <linux/pm_wakeirq.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26 26
27#define DS1343_DRV_VERSION "01.00"
28#define DALLAS_MAXIM_DS1343 0 27#define DALLAS_MAXIM_DS1343 0
29#define DALLAS_MAXIM_DS1344 1 28#define DALLAS_MAXIM_DS1344 1
30 29
@@ -747,4 +746,3 @@ MODULE_DESCRIPTION("DS1343 RTC SPI Driver");
747MODULE_AUTHOR("Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>," 746MODULE_AUTHOR("Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>,"
748 "Ankur Srivastava <sankurece@gmail.com>"); 747 "Ankur Srivastava <sankurece@gmail.com>");
749MODULE_LICENSE("GPL v2"); 748MODULE_LICENSE("GPL v2");
750MODULE_VERSION(DS1343_DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index da3d04ce83bd..1b2dcb58c0ab 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -25,8 +25,6 @@
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/module.h> 26#include <linux/module.h>
27 27
28#define DRV_VERSION "0.6"
29
30enum ds1511reg { 28enum ds1511reg {
31 DS1511_SEC = 0x0, 29 DS1511_SEC = 0x0,
32 DS1511_MIN = 0x1, 30 DS1511_MIN = 0x1,
@@ -537,4 +535,3 @@ module_platform_driver(ds1511_rtc_driver);
537MODULE_AUTHOR("Andrew Sharp <andy.sharp@lsi.com>"); 535MODULE_AUTHOR("Andrew Sharp <andy.sharp@lsi.com>");
538MODULE_DESCRIPTION("Dallas DS1511 RTC driver"); 536MODULE_DESCRIPTION("Dallas DS1511 RTC driver");
539MODULE_LICENSE("GPL"); 537MODULE_LICENSE("GPL");
540MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 38422ab4ec5a..9961ec646fd2 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -20,8 +20,6 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/module.h> 21#include <linux/module.h>
22 22
23#define DRV_VERSION "0.3"
24
25#define RTC_REG_SIZE 0x2000 23#define RTC_REG_SIZE 0x2000
26#define RTC_OFFSET 0x1ff0 24#define RTC_OFFSET 0x1ff0
27 25
@@ -359,4 +357,3 @@ module_platform_driver(ds1553_rtc_driver);
359MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 357MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
360MODULE_DESCRIPTION("Dallas DS1553 RTC driver"); 358MODULE_DESCRIPTION("Dallas DS1553 RTC driver");
361MODULE_LICENSE("GPL"); 359MODULE_LICENSE("GPL");
362MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 92b1cbf2c4a7..5c18ac7394c4 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -13,8 +13,6 @@
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14#include <linux/module.h> 14#include <linux/module.h>
15 15
16#define DRV_VERSION "0.4"
17
18/* Registers */ 16/* Registers */
19 17
20#define DS1672_REG_CNT_BASE 0 18#define DS1672_REG_CNT_BASE 0
@@ -165,8 +163,6 @@ static int ds1672_probe(struct i2c_client *client,
165 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 163 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
166 return -ENODEV; 164 return -ENODEV;
167 165
168 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
169
170 rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name, 166 rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name,
171 &ds1672_rtc_ops, THIS_MODULE); 167 &ds1672_rtc_ops, THIS_MODULE);
172 168
@@ -213,4 +209,3 @@ module_i2c_driver(ds1672_driver);
213MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 209MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
214MODULE_DESCRIPTION("Dallas/Maxim DS1672 timekeeper driver"); 210MODULE_DESCRIPTION("Dallas/Maxim DS1672 timekeeper driver");
215MODULE_LICENSE("GPL"); 211MODULE_LICENSE("GPL");
216MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 1e6cfc84b1f6..b3ce3c652fcd 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -32,8 +32,6 @@
32#include <linux/proc_fs.h> 32#include <linux/proc_fs.h>
33#endif 33#endif
34 34
35#define DRV_VERSION "0.42.0"
36
37 35
38/* ----------------------------------------------------------------------- */ 36/* ----------------------------------------------------------------------- */
39/* Standard read/write functions if platform does not provide overrides */ 37/* Standard read/write functions if platform does not provide overrides */
@@ -2213,6 +2211,7 @@ ds1685_rtc_poweroff(struct platform_device *pdev)
2213 (ctrl4a | RTC_CTRL_4A_PAB)); 2211 (ctrl4a | RTC_CTRL_4A_PAB));
2214 2212
2215 /* Spin ... we do not switch back to bank0. */ 2213 /* Spin ... we do not switch back to bank0. */
2214 while(1);
2216 unreachable(); 2215 unreachable();
2217 } 2216 }
2218} 2217}
@@ -2224,5 +2223,4 @@ MODULE_AUTHOR("Joshua Kinard <kumba@gentoo.org>");
2224MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd-electronics.com>"); 2223MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd-electronics.com>");
2225MODULE_DESCRIPTION("Dallas/Maxim DS1685/DS1687-series RTC driver"); 2224MODULE_DESCRIPTION("Dallas/Maxim DS1685/DS1687-series RTC driver");
2226MODULE_LICENSE("GPL"); 2225MODULE_LICENSE("GPL");
2227MODULE_VERSION(DRV_VERSION);
2228MODULE_ALIAS("platform:rtc-ds1685"); 2226MODULE_ALIAS("platform:rtc-ds1685");
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index c5168b3bcf1a..3abf1cbfb8ce 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -24,8 +24,6 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/module.h> 25#include <linux/module.h>
26 26
27#define DRV_VERSION "0.4"
28
29#define RTC_SIZE 8 27#define RTC_SIZE 8
30 28
31#define RTC_CONTROL 0 29#define RTC_CONTROL 0
@@ -239,5 +237,4 @@ module_platform_driver(ds1742_rtc_driver);
239MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 237MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
240MODULE_DESCRIPTION("Dallas DS1742 RTC driver"); 238MODULE_DESCRIPTION("Dallas DS1742 RTC driver");
241MODULE_LICENSE("GPL"); 239MODULE_LICENSE("GPL");
242MODULE_VERSION(DRV_VERSION);
243MODULE_ALIAS("platform:rtc-ds1742"); 240MODULE_ALIAS("platform:rtc-ds1742");
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 7edc889729c5..04fbd7fffd0d 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -369,6 +369,11 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
369 if (ret) 369 if (ret)
370 return ret; 370 return ret;
371 371
372 ds3232->rtc = devm_rtc_device_register(dev, name, &ds3232_rtc_ops,
373 THIS_MODULE);
374 if (IS_ERR(ds3232->rtc))
375 return PTR_ERR(ds3232->rtc);
376
372 if (ds3232->irq > 0) { 377 if (ds3232->irq > 0) {
373 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, 378 ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
374 ds3232_irq, 379 ds3232_irq,
@@ -380,10 +385,8 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
380 } else 385 } else
381 device_init_wakeup(dev, 1); 386 device_init_wakeup(dev, 1);
382 } 387 }
383 ds3232->rtc = devm_rtc_device_register(dev, name, &ds3232_rtc_ops,
384 THIS_MODULE);
385 388
386 return PTR_ERR_OR_ZERO(ds3232->rtc); 389 return 0;
387} 390}
388 391
389#ifdef CONFIG_PM_SLEEP 392#ifdef CONFIG_PM_SLEEP
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index a1628adf9f52..694038208745 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -28,8 +28,6 @@
28#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff 28#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
29#define EP93XX_RTC_SWCOMP_INT_SHIFT 0 29#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
30 30
31#define DRV_VERSION "0.3"
32
33/* 31/*
34 * struct device dev.platform_data is used to store our private data 32 * struct device dev.platform_data is used to store our private data
35 * because struct rtc_device does not have a variable to hold it. 33 * because struct rtc_device does not have a variable to hold it.
@@ -184,5 +182,4 @@ module_platform_driver(ep93xx_rtc_driver);
184MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 182MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
185MODULE_DESCRIPTION("EP93XX RTC driver"); 183MODULE_DESCRIPTION("EP93XX RTC driver");
186MODULE_LICENSE("GPL"); 184MODULE_LICENSE("GPL");
187MODULE_VERSION(DRV_VERSION);
188MODULE_ALIAS("platform:ep93xx-rtc"); 185MODULE_ALIAS("platform:ep93xx-rtc");
diff --git a/drivers/rtc/rtc-gemini.c b/drivers/rtc/rtc-gemini.c
index f46b6d46a51b..b57505efadbc 100644
--- a/drivers/rtc/rtc-gemini.c
+++ b/drivers/rtc/rtc-gemini.c
@@ -28,7 +28,6 @@
28#include <linux/module.h> 28#include <linux/module.h>
29 29
30#define DRV_NAME "rtc-gemini" 30#define DRV_NAME "rtc-gemini"
31#define DRV_VERSION "0.2"
32 31
33MODULE_AUTHOR("Hans Ulli Kroll <ulli.kroll@googlemail.com>"); 32MODULE_AUTHOR("Hans Ulli Kroll <ulli.kroll@googlemail.com>");
34MODULE_DESCRIPTION("RTC driver for Gemini SoC"); 33MODULE_DESCRIPTION("RTC driver for Gemini SoC");
diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
index b1b4746a0eab..207270376b55 100644
--- a/drivers/rtc/rtc-hym8563.c
+++ b/drivers/rtc/rtc-hym8563.c
@@ -413,7 +413,7 @@ static struct clk *hym8563_clkout_register_clk(struct hym8563 *hym8563)
413 413
414 init.name = "hym8563-clkout"; 414 init.name = "hym8563-clkout";
415 init.ops = &hym8563_clkout_ops; 415 init.ops = &hym8563_clkout_ops;
416 init.flags = CLK_IS_ROOT; 416 init.flags = 0;
417 init.parent_names = NULL; 417 init.parent_names = NULL;
418 init.num_parents = 0; 418 init.num_parents = 0;
419 hym8563->clkout_hw.init = &init; 419 hym8563->clkout_hw.init = &init;
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 839d1fd63cd7..38586a024ee8 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -20,8 +20,6 @@
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_device.h> 21#include <linux/of_device.h>
22 22
23#define DRV_VERSION "0.1"
24
25/* ISL register offsets */ 23/* ISL register offsets */
26#define ISL12022_REG_SC 0x00 24#define ISL12022_REG_SC 0x00
27#define ISL12022_REG_MN 0x01 25#define ISL12022_REG_MN 0x01
@@ -258,8 +256,6 @@ static int isl12022_probe(struct i2c_client *client,
258 if (!isl12022) 256 if (!isl12022)
259 return -ENOMEM; 257 return -ENOMEM;
260 258
261 dev_dbg(&client->dev, "chip found, driver version " DRV_VERSION "\n");
262
263 i2c_set_clientdata(client, isl12022); 259 i2c_set_clientdata(client, isl12022);
264 260
265 isl12022->rtc = devm_rtc_device_register(&client->dev, 261 isl12022->rtc = devm_rtc_device_register(&client->dev,
@@ -299,4 +295,3 @@ module_i2c_driver(isl12022_driver);
299MODULE_AUTHOR("roman.fietze@telemotive.de"); 295MODULE_AUTHOR("roman.fietze@telemotive.de");
300MODULE_DESCRIPTION("ISL 12022 RTC driver"); 296MODULE_DESCRIPTION("ISL 12022 RTC driver");
301MODULE_LICENSE("GPL"); 297MODULE_LICENSE("GPL");
302MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index b57a304ff62c..2893785f0eba 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -15,8 +15,6 @@
15#include <linux/bcd.h> 15#include <linux/bcd.h>
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17 17
18#define DRV_VERSION "0.3"
19
20/* Register map */ 18/* Register map */
21/* rtc section */ 19/* rtc section */
22#define ISL1208_REG_SC 0x00 20#define ISL1208_REG_SC 0x00
@@ -632,9 +630,6 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
632 if (isl1208_i2c_validate_client(client) < 0) 630 if (isl1208_i2c_validate_client(client) < 0)
633 return -ENODEV; 631 return -ENODEV;
634 632
635 dev_info(&client->dev,
636 "chip found, driver version " DRV_VERSION "\n");
637
638 if (client->irq > 0) { 633 if (client->irq > 0) {
639 rc = devm_request_threaded_irq(&client->dev, client->irq, NULL, 634 rc = devm_request_threaded_irq(&client->dev, client->irq, NULL,
640 isl1208_rtc_interrupt, 635 isl1208_rtc_interrupt,
@@ -706,4 +701,3 @@ module_i2c_driver(isl1208_driver);
706MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>"); 701MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>");
707MODULE_DESCRIPTION("Intersil ISL1208 RTC driver"); 702MODULE_DESCRIPTION("Intersil ISL1208 RTC driver");
708MODULE_LICENSE("GPL"); 703MODULE_LICENSE("GPL");
709MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index d107a8e72a7d..d1bf93a87200 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -32,41 +32,42 @@
32#include <linux/watchdog.h> 32#include <linux/watchdog.h>
33#endif 33#endif
34 34
35#define M41T80_REG_SSEC 0 35#define M41T80_REG_SSEC 0x00
36#define M41T80_REG_SEC 1 36#define M41T80_REG_SEC 0x01
37#define M41T80_REG_MIN 2 37#define M41T80_REG_MIN 0x02
38#define M41T80_REG_HOUR 3 38#define M41T80_REG_HOUR 0x03
39#define M41T80_REG_WDAY 4 39#define M41T80_REG_WDAY 0x04
40#define M41T80_REG_DAY 5 40#define M41T80_REG_DAY 0x05
41#define M41T80_REG_MON 6 41#define M41T80_REG_MON 0x06
42#define M41T80_REG_YEAR 7 42#define M41T80_REG_YEAR 0x07
43#define M41T80_REG_ALARM_MON 0xa 43#define M41T80_REG_ALARM_MON 0x0a
44#define M41T80_REG_ALARM_DAY 0xb 44#define M41T80_REG_ALARM_DAY 0x0b
45#define M41T80_REG_ALARM_HOUR 0xc 45#define M41T80_REG_ALARM_HOUR 0x0c
46#define M41T80_REG_ALARM_MIN 0xd 46#define M41T80_REG_ALARM_MIN 0x0d
47#define M41T80_REG_ALARM_SEC 0xe 47#define M41T80_REG_ALARM_SEC 0x0e
48#define M41T80_REG_FLAGS 0xf 48#define M41T80_REG_FLAGS 0x0f
49#define M41T80_REG_SQW 0x13 49#define M41T80_REG_SQW 0x13
50 50
51#define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1) 51#define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1)
52#define M41T80_ALARM_REG_SIZE \ 52#define M41T80_ALARM_REG_SIZE \
53 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON) 53 (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON)
54 54
55#define M41T80_SEC_ST (1 << 7) /* ST: Stop Bit */ 55#define M41T80_SEC_ST BIT(7) /* ST: Stop Bit */
56#define M41T80_ALMON_AFE (1 << 7) /* AFE: AF Enable Bit */ 56#define M41T80_ALMON_AFE BIT(7) /* AFE: AF Enable Bit */
57#define M41T80_ALMON_SQWE (1 << 6) /* SQWE: SQW Enable Bit */ 57#define M41T80_ALMON_SQWE BIT(6) /* SQWE: SQW Enable Bit */
58#define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ 58#define M41T80_ALHOUR_HT BIT(6) /* HT: Halt Update Bit */
59#define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ 59#define M41T80_FLAGS_OF BIT(2) /* OF: Oscillator Failure Bit */
60#define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ 60#define M41T80_FLAGS_AF BIT(6) /* AF: Alarm Flag Bit */
61#define M41T80_WATCHDOG_RB2 (1 << 7) /* RB: Watchdog resolution */ 61#define M41T80_FLAGS_BATT_LOW BIT(4) /* BL: Battery Low Bit */
62#define M41T80_WATCHDOG_RB1 (1 << 1) /* RB: Watchdog resolution */ 62#define M41T80_WATCHDOG_RB2 BIT(7) /* RB: Watchdog resolution */
63#define M41T80_WATCHDOG_RB0 (1 << 0) /* RB: Watchdog resolution */ 63#define M41T80_WATCHDOG_RB1 BIT(1) /* RB: Watchdog resolution */
64 64#define M41T80_WATCHDOG_RB0 BIT(0) /* RB: Watchdog resolution */
65#define M41T80_FEATURE_HT (1 << 0) /* Halt feature */ 65
66#define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */ 66#define M41T80_FEATURE_HT BIT(0) /* Halt feature */
67#define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */ 67#define M41T80_FEATURE_BL BIT(1) /* Battery low indicator */
68#define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */ 68#define M41T80_FEATURE_SQ BIT(2) /* Squarewave feature */
69#define M41T80_FEATURE_SQ_ALT (1 << 4) /* RSx bits are in reg 4 */ 69#define M41T80_FEATURE_WD BIT(3) /* Extra watchdog resolution */
70#define M41T80_FEATURE_SQ_ALT BIT(4) /* RSx bits are in reg 4 */
70 71
71static DEFINE_MUTEX(m41t80_rtc_mutex); 72static DEFINE_MUTEX(m41t80_rtc_mutex);
72static const struct i2c_device_id m41t80_id[] = { 73static const struct i2c_device_id m41t80_id[] = {
@@ -90,27 +91,65 @@ struct m41t80_data {
90 struct rtc_device *rtc; 91 struct rtc_device *rtc;
91}; 92};
92 93
94static irqreturn_t m41t80_handle_irq(int irq, void *dev_id)
95{
96 struct i2c_client *client = dev_id;
97 struct m41t80_data *m41t80 = i2c_get_clientdata(client);
98 struct mutex *lock = &m41t80->rtc->ops_lock;
99 unsigned long events = 0;
100 int flags, flags_afe;
101
102 mutex_lock(lock);
103
104 flags_afe = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
105 if (flags_afe < 0) {
106 mutex_unlock(lock);
107 return IRQ_NONE;
108 }
109
110 flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
111 if (flags <= 0) {
112 mutex_unlock(lock);
113 return IRQ_NONE;
114 }
115
116 if (flags & M41T80_FLAGS_AF) {
117 flags &= ~M41T80_FLAGS_AF;
118 flags_afe &= ~M41T80_ALMON_AFE;
119 events |= RTC_AF;
120 }
121
122 if (events) {
123 rtc_update_irq(m41t80->rtc, 1, events);
124 i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS, flags);
125 i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
126 flags_afe);
127 }
128
129 mutex_unlock(lock);
130
131 return IRQ_HANDLED;
132}
133
93static int m41t80_get_datetime(struct i2c_client *client, 134static int m41t80_get_datetime(struct i2c_client *client,
94 struct rtc_time *tm) 135 struct rtc_time *tm)
95{ 136{
96 u8 buf[M41T80_DATETIME_REG_SIZE], dt_addr[1] = { M41T80_REG_SEC }; 137 unsigned char buf[8];
97 struct i2c_msg msgs[] = { 138 int err, flags;
98 { 139
99 .addr = client->addr, 140 flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
100 .flags = 0, 141 if (flags < 0)
101 .len = 1, 142 return flags;
102 .buf = dt_addr,
103 },
104 {
105 .addr = client->addr,
106 .flags = I2C_M_RD,
107 .len = M41T80_DATETIME_REG_SIZE - M41T80_REG_SEC,
108 .buf = buf + M41T80_REG_SEC,
109 },
110 };
111 143
112 if (i2c_transfer(client->adapter, msgs, 2) < 0) { 144 if (flags & M41T80_FLAGS_OF) {
113 dev_err(&client->dev, "read error\n"); 145 dev_err(&client->dev, "Oscillator failure, data is invalid.\n");
146 return -EINVAL;
147 }
148
149 err = i2c_smbus_read_i2c_block_data(client, M41T80_REG_SSEC,
150 sizeof(buf), buf);
151 if (err < 0) {
152 dev_err(&client->dev, "Unable to read date\n");
114 return -EIO; 153 return -EIO;
115 } 154 }
116 155
@@ -129,70 +168,42 @@ static int m41t80_get_datetime(struct i2c_client *client,
129/* Sets the given date and time to the real time clock. */ 168/* Sets the given date and time to the real time clock. */
130static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) 169static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
131{ 170{
132 u8 wbuf[1 + M41T80_DATETIME_REG_SIZE]; 171 unsigned char buf[8];
133 u8 *buf = &wbuf[1]; 172 int err, flags;
134 u8 dt_addr[1] = { M41T80_REG_SEC };
135 struct i2c_msg msgs_in[] = {
136 {
137 .addr = client->addr,
138 .flags = 0,
139 .len = 1,
140 .buf = dt_addr,
141 },
142 {
143 .addr = client->addr,
144 .flags = I2C_M_RD,
145 .len = M41T80_DATETIME_REG_SIZE - M41T80_REG_SEC,
146 .buf = buf + M41T80_REG_SEC,
147 },
148 };
149 struct i2c_msg msgs[] = {
150 {
151 .addr = client->addr,
152 .flags = 0,
153 .len = 1 + M41T80_DATETIME_REG_SIZE,
154 .buf = wbuf,
155 },
156 };
157 173
158 /* Read current reg values into buf[1..7] */ 174 if (tm->tm_year < 100 || tm->tm_year > 199)
159 if (i2c_transfer(client->adapter, msgs_in, 2) < 0) { 175 return -EINVAL;
160 dev_err(&client->dev, "read error\n");
161 return -EIO;
162 }
163 176
164 wbuf[0] = 0; /* offset into rtc's regs */
165 /* Merge time-data and register flags into buf[0..7] */
166 buf[M41T80_REG_SSEC] = 0; 177 buf[M41T80_REG_SSEC] = 0;
167 buf[M41T80_REG_SEC] = 178 buf[M41T80_REG_SEC] = bin2bcd(tm->tm_sec);
168 bin2bcd(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f); 179 buf[M41T80_REG_MIN] = bin2bcd(tm->tm_min);
169 buf[M41T80_REG_MIN] = 180 buf[M41T80_REG_HOUR] = bin2bcd(tm->tm_hour);
170 bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); 181 buf[M41T80_REG_DAY] = bin2bcd(tm->tm_mday);
171 buf[M41T80_REG_HOUR] = 182 buf[M41T80_REG_MON] = bin2bcd(tm->tm_mon + 1);
172 bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f); 183 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year - 100);
173 buf[M41T80_REG_WDAY] = 184 buf[M41T80_REG_WDAY] = tm->tm_wday;
174 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); 185
175 buf[M41T80_REG_DAY] = 186 err = i2c_smbus_write_i2c_block_data(client, M41T80_REG_SSEC,
176 bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); 187 sizeof(buf), buf);
177 buf[M41T80_REG_MON] = 188 if (err < 0) {
178 bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); 189 dev_err(&client->dev, "Unable to write to date registers\n");
179 190 return err;
180 /* assume 20YY not 19YY */
181 if (tm->tm_year < 100 || tm->tm_year > 199) {
182 dev_err(&client->dev, "Year must be between 2000 and 2099. It's %d.\n",
183 tm->tm_year + 1900);
184 return -EINVAL;
185 } 191 }
186 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100);
187 192
188 if (i2c_transfer(client->adapter, msgs, 1) != 1) { 193 /* Clear the OF bit of Flags Register */
189 dev_err(&client->dev, "write error\n"); 194 flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
195 if (flags < 0)
196 return flags;
197
198 if (i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
199 flags & ~M41T80_FLAGS_OF)) {
200 dev_err(&client->dev, "Unable to write flags register\n");
190 return -EIO; 201 return -EIO;
191 } 202 }
192 return 0; 203
204 return err;
193} 205}
194 206
195#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
196static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq) 207static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq)
197{ 208{
198 struct i2c_client *client = to_i2c_client(dev); 209 struct i2c_client *client = to_i2c_client(dev);
@@ -206,9 +217,6 @@ static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq)
206 } 217 }
207 return 0; 218 return 0;
208} 219}
209#else
210#define m41t80_rtc_proc NULL
211#endif
212 220
213static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm) 221static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm)
214{ 222{
@@ -220,19 +228,117 @@ static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm)
220 return m41t80_set_datetime(to_i2c_client(dev), tm); 228 return m41t80_set_datetime(to_i2c_client(dev), tm);
221} 229}
222 230
223/* 231static int m41t80_alarm_irq_enable(struct device *dev, unsigned int enabled)
224 * XXX - m41t80 alarm functionality is reported broken. 232{
225 * until it is fixed, don't register alarm functions. 233 struct i2c_client *client = to_i2c_client(dev);
226 */ 234 int flags, retval;
235
236 flags = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
237 if (flags < 0)
238 return flags;
239
240 if (enabled)
241 flags |= M41T80_ALMON_AFE;
242 else
243 flags &= ~M41T80_ALMON_AFE;
244
245 retval = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, flags);
246 if (retval < 0) {
247 dev_info(dev, "Unable to enable alarm IRQ %d\n", retval);
248 return retval;
249 }
250 return 0;
251}
252
253static int m41t80_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
254{
255 struct i2c_client *client = to_i2c_client(dev);
256 u8 alarmvals[5];
257 int ret, err;
258
259 alarmvals[0] = bin2bcd(alrm->time.tm_mon + 1);
260 alarmvals[1] = bin2bcd(alrm->time.tm_mday);
261 alarmvals[2] = bin2bcd(alrm->time.tm_hour);
262 alarmvals[3] = bin2bcd(alrm->time.tm_min);
263 alarmvals[4] = bin2bcd(alrm->time.tm_sec);
264
265 /* Clear AF and AFE flags */
266 ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
267 if (ret < 0)
268 return ret;
269 err = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
270 ret & ~(M41T80_ALMON_AFE));
271 if (err < 0) {
272 dev_err(dev, "Unable to clear AFE bit\n");
273 return err;
274 }
275
276 ret = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
277 if (ret < 0)
278 return ret;
279
280 err = i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
281 ret & ~(M41T80_FLAGS_AF));
282 if (err < 0) {
283 dev_err(dev, "Unable to clear AF bit\n");
284 return err;
285 }
286
287 /* Write the alarm */
288 err = i2c_smbus_write_i2c_block_data(client, M41T80_REG_ALARM_MON,
289 5, alarmvals);
290 if (err)
291 return err;
292
293 /* Enable the alarm interrupt */
294 if (alrm->enabled) {
295 alarmvals[0] |= M41T80_ALMON_AFE;
296 err = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
297 alarmvals[0]);
298 if (err)
299 return err;
300 }
301
302 return 0;
303}
304
305static int m41t80_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
306{
307 struct i2c_client *client = to_i2c_client(dev);
308 u8 alarmvals[5];
309 int flags, ret;
310
311 ret = i2c_smbus_read_i2c_block_data(client, M41T80_REG_ALARM_MON,
312 5, alarmvals);
313 if (ret != 5)
314 return ret < 0 ? ret : -EIO;
315
316 flags = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
317 if (flags < 0)
318 return flags;
319
320 alrm->time.tm_sec = bcd2bin(alarmvals[4] & 0x7f);
321 alrm->time.tm_min = bcd2bin(alarmvals[3] & 0x7f);
322 alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f);
323 alrm->time.tm_wday = -1;
324 alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f);
325 alrm->time.tm_mon = bcd2bin(alarmvals[0] & 0x3f);
326 alrm->time.tm_year = -1;
327
328 alrm->enabled = !!(alarmvals[0] & M41T80_ALMON_AFE);
329 alrm->pending = (flags & M41T80_FLAGS_AF) && alrm->enabled;
330
331 return 0;
332}
333
227static struct rtc_class_ops m41t80_rtc_ops = { 334static struct rtc_class_ops m41t80_rtc_ops = {
228 .read_time = m41t80_rtc_read_time, 335 .read_time = m41t80_rtc_read_time,
229 .set_time = m41t80_rtc_set_time, 336 .set_time = m41t80_rtc_set_time,
230 .proc = m41t80_rtc_proc, 337 .proc = m41t80_rtc_proc,
231}; 338};
232 339
233#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE) 340static ssize_t flags_show(struct device *dev,
234static ssize_t m41t80_sysfs_show_flags(struct device *dev, 341 struct device_attribute *attr, char *buf)
235 struct device_attribute *attr, char *buf)
236{ 342{
237 struct i2c_client *client = to_i2c_client(dev); 343 struct i2c_client *client = to_i2c_client(dev);
238 int val; 344 int val;
@@ -242,10 +348,10 @@ static ssize_t m41t80_sysfs_show_flags(struct device *dev,
242 return val; 348 return val;
243 return sprintf(buf, "%#x\n", val); 349 return sprintf(buf, "%#x\n", val);
244} 350}
245static DEVICE_ATTR(flags, S_IRUGO, m41t80_sysfs_show_flags, NULL); 351static DEVICE_ATTR_RO(flags);
246 352
247static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev, 353static ssize_t sqwfreq_show(struct device *dev,
248 struct device_attribute *attr, char *buf) 354 struct device_attribute *attr, char *buf)
249{ 355{
250 struct i2c_client *client = to_i2c_client(dev); 356 struct i2c_client *client = to_i2c_client(dev);
251 struct m41t80_data *clientdata = i2c_get_clientdata(client); 357 struct m41t80_data *clientdata = i2c_get_clientdata(client);
@@ -272,14 +378,19 @@ static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev,
272 } 378 }
273 return sprintf(buf, "%d\n", val); 379 return sprintf(buf, "%d\n", val);
274} 380}
275static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev, 381
276 struct device_attribute *attr, 382static ssize_t sqwfreq_store(struct device *dev,
277 const char *buf, size_t count) 383 struct device_attribute *attr,
384 const char *buf, size_t count)
278{ 385{
279 struct i2c_client *client = to_i2c_client(dev); 386 struct i2c_client *client = to_i2c_client(dev);
280 struct m41t80_data *clientdata = i2c_get_clientdata(client); 387 struct m41t80_data *clientdata = i2c_get_clientdata(client);
281 int almon, sqw, reg_sqw, rc; 388 int almon, sqw, reg_sqw, rc;
282 int val = simple_strtoul(buf, NULL, 0); 389 unsigned long val;
390
391 rc = kstrtoul(buf, 0, &val);
392 if (rc < 0)
393 return rc;
283 394
284 if (!(clientdata->features & M41T80_FEATURE_SQ)) 395 if (!(clientdata->features & M41T80_FEATURE_SQ))
285 return -EINVAL; 396 return -EINVAL;
@@ -308,7 +419,7 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev,
308 sqw = (sqw & 0x0f) | (val << 4); 419 sqw = (sqw & 0x0f) | (val << 4);
309 420
310 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, 421 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
311 almon & ~M41T80_ALMON_SQWE); 422 almon & ~M41T80_ALMON_SQWE);
312 if (rc < 0) 423 if (rc < 0)
313 return rc; 424 return rc;
314 425
@@ -318,35 +429,24 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev,
318 return rc; 429 return rc;
319 430
320 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, 431 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
321 almon | M41T80_ALMON_SQWE); 432 almon | M41T80_ALMON_SQWE);
322 if (rc <0) 433 if (rc < 0)
323 return rc; 434 return rc;
324 } 435 }
325 return count; 436 return count;
326} 437}
327static DEVICE_ATTR(sqwfreq, S_IRUGO | S_IWUSR, 438static DEVICE_ATTR_RW(sqwfreq);
328 m41t80_sysfs_show_sqwfreq, m41t80_sysfs_set_sqwfreq);
329 439
330static struct attribute *attrs[] = { 440static struct attribute *attrs[] = {
331 &dev_attr_flags.attr, 441 &dev_attr_flags.attr,
332 &dev_attr_sqwfreq.attr, 442 &dev_attr_sqwfreq.attr,
333 NULL, 443 NULL,
334}; 444};
445
335static struct attribute_group attr_group = { 446static struct attribute_group attr_group = {
336 .attrs = attrs, 447 .attrs = attrs,
337}; 448};
338 449
339static int m41t80_sysfs_register(struct device *dev)
340{
341 return sysfs_create_group(&dev->kobj, &attr_group);
342}
343#else
344static int m41t80_sysfs_register(struct device *dev)
345{
346 return 0;
347}
348#endif
349
350#ifdef CONFIG_RTC_DRV_M41T80_WDT 450#ifdef CONFIG_RTC_DRV_M41T80_WDT
351/* 451/*
352 ***************************************************************************** 452 *****************************************************************************
@@ -394,7 +494,7 @@ static void wdt_ping(void)
394 /* 494 /*
395 * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02) 495 * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02)
396 */ 496 */
397 i2c_data[1] = wdt_margin<<2 | 0x82; 497 i2c_data[1] = wdt_margin << 2 | 0x82;
398 498
399 /* 499 /*
400 * M41T65 has three bits for watchdog resolution. Don't set bit 7, as 500 * M41T65 has three bits for watchdog resolution. Don't set bit 7, as
@@ -636,49 +736,76 @@ static struct notifier_block wdt_notifier = {
636 * 736 *
637 ***************************************************************************** 737 *****************************************************************************
638 */ 738 */
739
740static void m41t80_remove_sysfs_group(void *_dev)
741{
742 struct device *dev = _dev;
743
744 sysfs_remove_group(&dev->kobj, &attr_group);
745}
746
639static int m41t80_probe(struct i2c_client *client, 747static int m41t80_probe(struct i2c_client *client,
640 const struct i2c_device_id *id) 748 const struct i2c_device_id *id)
641{ 749{
750 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
642 int rc = 0; 751 int rc = 0;
643 struct rtc_device *rtc = NULL; 752 struct rtc_device *rtc = NULL;
644 struct rtc_time tm; 753 struct rtc_time tm;
645 struct m41t80_data *clientdata = NULL; 754 struct m41t80_data *m41t80_data = NULL;
646 755
647 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C 756 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
648 | I2C_FUNC_SMBUS_BYTE_DATA)) 757 I2C_FUNC_SMBUS_BYTE_DATA)) {
758 dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n");
649 return -ENODEV; 759 return -ENODEV;
760 }
650 761
651 clientdata = devm_kzalloc(&client->dev, sizeof(*clientdata), 762 m41t80_data = devm_kzalloc(&client->dev, sizeof(*m41t80_data),
652 GFP_KERNEL); 763 GFP_KERNEL);
653 if (!clientdata) 764 if (!m41t80_data)
654 return -ENOMEM; 765 return -ENOMEM;
655 766
656 clientdata->features = id->driver_data; 767 m41t80_data->features = id->driver_data;
657 i2c_set_clientdata(client, clientdata); 768 i2c_set_clientdata(client, m41t80_data);
769
770 if (client->irq > 0) {
771 rc = devm_request_threaded_irq(&client->dev, client->irq,
772 NULL, m41t80_handle_irq,
773 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
774 "m41t80", client);
775 if (rc) {
776 dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
777 client->irq = 0;
778 } else {
779 m41t80_rtc_ops.read_alarm = m41t80_read_alarm;
780 m41t80_rtc_ops.set_alarm = m41t80_set_alarm;
781 m41t80_rtc_ops.alarm_irq_enable = m41t80_alarm_irq_enable;
782 /* Enable the wakealarm */
783 device_init_wakeup(&client->dev, true);
784 }
785 }
658 786
659 rtc = devm_rtc_device_register(&client->dev, client->name, 787 rtc = devm_rtc_device_register(&client->dev, client->name,
660 &m41t80_rtc_ops, THIS_MODULE); 788 &m41t80_rtc_ops, THIS_MODULE);
661 if (IS_ERR(rtc)) 789 if (IS_ERR(rtc))
662 return PTR_ERR(rtc); 790 return PTR_ERR(rtc);
663 791
664 clientdata->rtc = rtc; 792 m41t80_data->rtc = rtc;
665 793
666 /* Make sure HT (Halt Update) bit is cleared */ 794 /* Make sure HT (Halt Update) bit is cleared */
667 rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR); 795 rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR);
668 796
669 if (rc >= 0 && rc & M41T80_ALHOUR_HT) { 797 if (rc >= 0 && rc & M41T80_ALHOUR_HT) {
670 if (clientdata->features & M41T80_FEATURE_HT) { 798 if (m41t80_data->features & M41T80_FEATURE_HT) {
671 m41t80_get_datetime(client, &tm); 799 m41t80_get_datetime(client, &tm);
672 dev_info(&client->dev, "HT bit was set!\n"); 800 dev_info(&client->dev, "HT bit was set!\n");
673 dev_info(&client->dev, 801 dev_info(&client->dev,
674 "Power Down at " 802 "Power Down at %04i-%02i-%02i %02i:%02i:%02i\n",
675 "%04i-%02i-%02i %02i:%02i:%02i\n",
676 tm.tm_year + 1900, 803 tm.tm_year + 1900,
677 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, 804 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
678 tm.tm_min, tm.tm_sec); 805 tm.tm_min, tm.tm_sec);
679 } 806 }
680 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR, 807 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR,
681 rc & ~M41T80_ALHOUR_HT); 808 rc & ~M41T80_ALHOUR_HT);
682 } 809 }
683 810
684 if (rc < 0) { 811 if (rc < 0) {
@@ -691,18 +818,30 @@ static int m41t80_probe(struct i2c_client *client,
691 818
692 if (rc >= 0 && rc & M41T80_SEC_ST) 819 if (rc >= 0 && rc & M41T80_SEC_ST)
693 rc = i2c_smbus_write_byte_data(client, M41T80_REG_SEC, 820 rc = i2c_smbus_write_byte_data(client, M41T80_REG_SEC,
694 rc & ~M41T80_SEC_ST); 821 rc & ~M41T80_SEC_ST);
695 if (rc < 0) { 822 if (rc < 0) {
696 dev_err(&client->dev, "Can't clear ST bit\n"); 823 dev_err(&client->dev, "Can't clear ST bit\n");
697 return rc; 824 return rc;
698 } 825 }
699 826
700 rc = m41t80_sysfs_register(&client->dev); 827 /* Export sysfs entries */
701 if (rc) 828 rc = sysfs_create_group(&(&client->dev)->kobj, &attr_group);
829 if (rc) {
830 dev_err(&client->dev, "Failed to create sysfs group: %d\n", rc);
831 return rc;
832 }
833
834 rc = devm_add_action(&client->dev, m41t80_remove_sysfs_group,
835 &client->dev);
836 if (rc) {
837 m41t80_remove_sysfs_group(&client->dev);
838 dev_err(&client->dev,
839 "Failed to add sysfs cleanup action: %d\n", rc);
702 return rc; 840 return rc;
841 }
703 842
704#ifdef CONFIG_RTC_DRV_M41T80_WDT 843#ifdef CONFIG_RTC_DRV_M41T80_WDT
705 if (clientdata->features & M41T80_FEATURE_HT) { 844 if (m41t80_data->features & M41T80_FEATURE_HT) {
706 save_client = client; 845 save_client = client;
707 rc = misc_register(&wdt_dev); 846 rc = misc_register(&wdt_dev);
708 if (rc) 847 if (rc)
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index c62b51217ecf..810f4ea481e4 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -22,8 +22,6 @@
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/err.h> 23#include <linux/err.h>
24 24
25#define DRV_VERSION "1.0"
26
27struct m48t35_rtc { 25struct m48t35_rtc {
28 u8 pad[0x7ff8]; /* starts at 0x7ff8 */ 26 u8 pad[0x7ff8]; /* starts at 0x7ff8 */
29 u8 control; 27 u8 control;
@@ -190,5 +188,4 @@ module_platform_driver(m48t35_platform_driver);
190MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>"); 188MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
191MODULE_DESCRIPTION("M48T35 RTC driver"); 189MODULE_DESCRIPTION("M48T35 RTC driver");
192MODULE_LICENSE("GPL"); 190MODULE_LICENSE("GPL");
193MODULE_VERSION(DRV_VERSION);
194MODULE_ALIAS("platform:rtc-m48t35"); 191MODULE_ALIAS("platform:rtc-m48t35");
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index a17b7a3ceece..f72b91f2501f 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -39,9 +39,6 @@
39#define M48T86_REG_B_SET (1 << 7) 39#define M48T86_REG_B_SET (1 << 7)
40#define M48T86_REG_D_VRT (1 << 7) 40#define M48T86_REG_D_VRT (1 << 7)
41 41
42#define DRV_VERSION "0.1"
43
44
45static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm) 42static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
46{ 43{
47 unsigned char reg; 44 unsigned char reg;
@@ -178,5 +175,4 @@ module_platform_driver(m48t86_rtc_platform_driver);
178MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 175MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
179MODULE_DESCRIPTION("M48T86 RTC driver"); 176MODULE_DESCRIPTION("M48T86 RTC driver");
180MODULE_LICENSE("GPL"); 177MODULE_LICENSE("GPL");
181MODULE_VERSION(DRV_VERSION);
182MODULE_ALIAS("platform:rtc-m48t86"); 178MODULE_ALIAS("platform:rtc-m48t86");
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index b2a76077bbfa..48b6b411f8b2 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -17,8 +17,6 @@
17#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19 19
20#define DRV_VERSION "0.2"
21
22/* 20/*
23 * register indices 21 * register indices
24 */ 22 */
@@ -218,8 +216,6 @@ max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
218 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 216 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
219 return -ENODEV; 217 return -ENODEV;
220 218
221 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
222
223 rtc = devm_rtc_device_register(&client->dev, max6900_driver.driver.name, 219 rtc = devm_rtc_device_register(&client->dev, max6900_driver.driver.name,
224 &max6900_rtc_ops, THIS_MODULE); 220 &max6900_rtc_ops, THIS_MODULE);
225 if (IS_ERR(rtc)) 221 if (IS_ERR(rtc))
@@ -249,4 +245,3 @@ module_i2c_driver(max6900_driver);
249MODULE_DESCRIPTION("Maxim MAX6900 RTC driver"); 245MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
250MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>"); 246MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>");
251MODULE_LICENSE("GPL"); 247MODULE_LICENSE("GPL");
252MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index a65868065743..30b8ef6a3676 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -250,18 +250,6 @@ static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev)
250 return IRQ_HANDLED; 250 return IRQ_HANDLED;
251} 251}
252 252
253static irqreturn_t mc13xxx_rtc_update_handler(int irq, void *dev)
254{
255 struct mc13xxx_rtc *priv = dev;
256 struct mc13xxx *mc13xxx = priv->mc13xxx;
257
258 rtc_update_irq(priv->rtc, 1, RTC_IRQF | RTC_UF);
259
260 mc13xxx_irq_ack(mc13xxx, irq);
261
262 return IRQ_HANDLED;
263}
264
265static const struct rtc_class_ops mc13xxx_rtc_ops = { 253static const struct rtc_class_ops mc13xxx_rtc_ops = {
266 .read_time = mc13xxx_rtc_read_time, 254 .read_time = mc13xxx_rtc_read_time,
267 .set_mmss64 = mc13xxx_rtc_set_mmss, 255 .set_mmss64 = mc13xxx_rtc_set_mmss,
@@ -307,11 +295,6 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
307 if (ret) 295 if (ret)
308 goto err_irq_request; 296 goto err_irq_request;
309 297
310 ret = mc13xxx_irq_request(mc13xxx, MC13XXX_IRQ_1HZ,
311 mc13xxx_rtc_update_handler, DRIVER_NAME, priv);
312 if (ret)
313 goto err_irq_request;
314
315 ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_TODA, 298 ret = mc13xxx_irq_request_nounmask(mc13xxx, MC13XXX_IRQ_TODA,
316 mc13xxx_rtc_alarm_handler, DRIVER_NAME, priv); 299 mc13xxx_rtc_alarm_handler, DRIVER_NAME, priv);
317 if (ret) 300 if (ret)
@@ -326,7 +309,6 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
326 309
327err_irq_request: 310err_irq_request:
328 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_TODA, priv); 311 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_TODA, priv);
329 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_1HZ, priv);
330 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_RTCRST, priv); 312 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_RTCRST, priv);
331 313
332 mc13xxx_unlock(mc13xxx); 314 mc13xxx_unlock(mc13xxx);
@@ -341,7 +323,6 @@ static int mc13xxx_rtc_remove(struct platform_device *pdev)
341 mc13xxx_lock(priv->mc13xxx); 323 mc13xxx_lock(priv->mc13xxx);
342 324
343 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv); 325 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv);
344 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv);
345 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv); 326 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv);
346 327
347 mc13xxx_unlock(priv->mc13xxx); 328 mc13xxx_unlock(priv->mc13xxx);
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c
index 548ea6f6f384..0094d9bdd1e6 100644
--- a/drivers/rtc/rtc-mrst.c
+++ b/drivers/rtc/rtc-mrst.c
@@ -266,7 +266,7 @@ static int mrst_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
266} 266}
267 267
268 268
269#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 269#if IS_ENABLED(CONFIG_RTC_INTF_PROC)
270 270
271static int mrst_procfs(struct device *dev, struct seq_file *seq) 271static int mrst_procfs(struct device *dev, struct seq_file *seq)
272{ 272{
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 7bd89d90048f..359876a88ac8 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -240,9 +240,6 @@ static irqreturn_t mxc_rtc_interrupt(int irq, void *dev_id)
240 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0); 240 mxc_rtc_irq_enable(&pdev->dev, RTC_ALM_BIT, 0);
241 } 241 }
242 242
243 if (status & RTC_1HZ_BIT)
244 events |= (RTC_UF | RTC_IRQF);
245
246 if (status & PIT_ALL_ON) 243 if (status & PIT_ALL_ON)
247 events |= (RTC_PF | RTC_IRQF); 244 events |= (RTC_PF | RTC_IRQF);
248 245
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index da27738b1242..f22e060709e5 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -46,8 +46,6 @@
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/sysfs.h> 47#include <linux/sysfs.h>
48 48
49#define DRV_VERSION "0.6"
50
51/* REGISTERS */ 49/* REGISTERS */
52#define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */ 50#define PCF2123_REG_CTRL1 (0x00) /* Control Register 1 */
53#define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */ 51#define PCF2123_REG_CTRL2 (0x01) /* Control Register 2 */
@@ -395,7 +393,6 @@ static int pcf2123_probe(struct spi_device *spi)
395 } 393 }
396 } 394 }
397 395
398 dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n");
399 dev_info(&spi->dev, "spiclk %u KHz.\n", 396 dev_info(&spi->dev, "spiclk %u KHz.\n",
400 (spi->max_speed_hz + 500) / 1000); 397 (spi->max_speed_hz + 500) / 1000);
401 398
@@ -474,4 +471,3 @@ module_spi_driver(pcf2123_driver);
474MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>"); 471MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>");
475MODULE_DESCRIPTION("NXP PCF2123 RTC driver"); 472MODULE_DESCRIPTION("NXP PCF2123 RTC driver");
476MODULE_LICENSE("GPL"); 473MODULE_LICENSE("GPL");
477MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index c8f95b8e463a..b9ddbb001283 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -23,8 +23,6 @@
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/err.h> 24#include <linux/err.h>
25 25
26#define DRV_VERSION "0.4.4"
27
28#define PCF8563_REG_ST1 0x00 /* status */ 26#define PCF8563_REG_ST1 0x00 /* status */
29#define PCF8563_REG_ST2 0x01 27#define PCF8563_REG_ST2 0x01
30#define PCF8563_BIT_AIE (1 << 1) 28#define PCF8563_BIT_AIE (1 << 1)
@@ -535,7 +533,7 @@ static struct clk *pcf8563_clkout_register_clk(struct pcf8563 *pcf8563)
535 533
536 init.name = "pcf8563-clkout"; 534 init.name = "pcf8563-clkout";
537 init.ops = &pcf8563_clkout_ops; 535 init.ops = &pcf8563_clkout_ops;
538 init.flags = CLK_IS_ROOT; 536 init.flags = 0;
539 init.parent_names = NULL; 537 init.parent_names = NULL;
540 init.num_parents = 0; 538 init.num_parents = 0;
541 pcf8563->clkout_hw.init = &init; 539 pcf8563->clkout_hw.init = &init;
@@ -580,8 +578,6 @@ static int pcf8563_probe(struct i2c_client *client,
580 if (!pcf8563) 578 if (!pcf8563)
581 return -ENOMEM; 579 return -ENOMEM;
582 580
583 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
584
585 i2c_set_clientdata(client, pcf8563); 581 i2c_set_clientdata(client, pcf8563);
586 pcf8563->client = client; 582 pcf8563->client = client;
587 device_set_wakeup_capable(&client->dev, 1); 583 device_set_wakeup_capable(&client->dev, 1);
@@ -662,4 +658,3 @@ module_i2c_driver(pcf8563_driver);
662MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); 658MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
663MODULE_DESCRIPTION("Philips PCF8563/Epson RTC8564 RTC driver"); 659MODULE_DESCRIPTION("Philips PCF8563/Epson RTC8564 RTC driver");
664MODULE_LICENSE("GPL"); 660MODULE_LICENSE("GPL");
665MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 5f48167c802a..89f38e3e917d 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -50,7 +50,6 @@
50#include <linux/io.h> 50#include <linux/io.h>
51 51
52#define DRV_NAME "rs5c313" 52#define DRV_NAME "rs5c313"
53#define DRV_VERSION "1.13"
54 53
55#ifdef CONFIG_SH_LANDISK 54#ifdef CONFIG_SH_LANDISK
56/*****************************************************/ 55/*****************************************************/
@@ -407,7 +406,6 @@ static void __exit rs5c313_rtc_exit(void)
407module_init(rs5c313_rtc_init); 406module_init(rs5c313_rtc_init);
408module_exit(rs5c313_rtc_exit); 407module_exit(rs5c313_rtc_exit);
409 408
410MODULE_VERSION(DRV_VERSION);
411MODULE_AUTHOR("kogiidena , Nobuhiro Iwamatsu <iwamatsu@nigauri.org>"); 409MODULE_AUTHOR("kogiidena , Nobuhiro Iwamatsu <iwamatsu@nigauri.org>");
412MODULE_DESCRIPTION("Ricoh RS5C313 RTC device driver"); 410MODULE_DESCRIPTION("Ricoh RS5C313 RTC device driver");
413MODULE_LICENSE("GPL"); 411MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 1162fecab8cf..9a306983aaba 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -25,8 +25,6 @@
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/module.h> 26#include <linux/module.h>
27 27
28#define DRV_VERSION "0.2"
29
30#define RS5C348_REG_SECS 0 28#define RS5C348_REG_SECS 0
31#define RS5C348_REG_MINS 1 29#define RS5C348_REG_MINS 1
32#define RS5C348_REG_HOURS 2 30#define RS5C348_REG_HOURS 2
@@ -171,7 +169,6 @@ static int rs5c348_probe(struct spi_device *spi)
171 goto kfree_exit; 169 goto kfree_exit;
172 } 170 }
173 171
174 dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n");
175 dev_info(&spi->dev, "spiclk %u KHz.\n", 172 dev_info(&spi->dev, "spiclk %u KHz.\n",
176 (spi->max_speed_hz + 500) / 1000); 173 (spi->max_speed_hz + 500) / 1000);
177 174
@@ -230,5 +227,4 @@ module_spi_driver(rs5c348_driver);
230MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 227MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
231MODULE_DESCRIPTION("Ricoh RS5C348 RTC driver"); 228MODULE_DESCRIPTION("Ricoh RS5C348 RTC driver");
232MODULE_LICENSE("GPL"); 229MODULE_LICENSE("GPL");
233MODULE_VERSION(DRV_VERSION);
234MODULE_ALIAS("spi:rtc-rs5c348"); 230MODULE_ALIAS("spi:rtc-rs5c348");
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 28871cd7e3b5..ef86229428fc 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -16,9 +16,6 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#define DRV_VERSION "0.6"
20
21
22/* 19/*
23 * Ricoh has a family of I2C based RTCs, which differ only slightly from 20 * Ricoh has a family of I2C based RTCs, which differ only slightly from
24 * each other. Differences center on pinout (e.g. how many interrupts, 21 * each other. Differences center on pinout (e.g. how many interrupts,
@@ -240,11 +237,11 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
240 return 0; 237 return 0;
241} 238}
242 239
243#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 240#if IS_ENABLED(CONFIG_RTC_INTF_PROC)
244#define NEED_TRIM 241#define NEED_TRIM
245#endif 242#endif
246 243
247#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE) 244#if IS_ENABLED(CONFIG_RTC_INTF_SYSFS)
248#define NEED_TRIM 245#define NEED_TRIM
249#endif 246#endif
250 247
@@ -412,7 +409,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
412 return 0; 409 return 0;
413} 410}
414 411
415#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE) 412#if IS_ENABLED(CONFIG_RTC_INTF_PROC)
416 413
417static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq) 414static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
418{ 415{
@@ -441,7 +438,7 @@ static const struct rtc_class_ops rs5c372_rtc_ops = {
441 .alarm_irq_enable = rs5c_rtc_alarm_irq_enable, 438 .alarm_irq_enable = rs5c_rtc_alarm_irq_enable,
442}; 439};
443 440
444#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE) 441#if IS_ENABLED(CONFIG_RTC_INTF_SYSFS)
445 442
446static ssize_t rs5c372_sysfs_show_trim(struct device *dev, 443static ssize_t rs5c372_sysfs_show_trim(struct device *dev,
447 struct device_attribute *attr, char *buf) 444 struct device_attribute *attr, char *buf)
@@ -509,9 +506,9 @@ static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
509 int addr, i, ret = 0; 506 int addr, i, ret = 0;
510 507
511 if (rs5c372->type == rtc_r2025sd) { 508 if (rs5c372->type == rtc_r2025sd) {
512 if (!(rs5c372->regs[RS5C_REG_CTRL2] & R2025_CTRL2_XST)) 509 if (rs5c372->regs[RS5C_REG_CTRL2] & R2025_CTRL2_XST)
513 return ret; 510 return ret;
514 rs5c372->regs[RS5C_REG_CTRL2] &= ~R2025_CTRL2_XST; 511 rs5c372->regs[RS5C_REG_CTRL2] |= R2025_CTRL2_XST;
515 } else { 512 } else {
516 if (!(rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP)) 513 if (!(rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP))
517 return ret; 514 return ret;
@@ -640,7 +637,7 @@ static int rs5c372_probe(struct i2c_client *client,
640 if (rs5c372_get_datetime(client, &tm) < 0) 637 if (rs5c372_get_datetime(client, &tm) < 0)
641 dev_warn(&client->dev, "clock needs to be set\n"); 638 dev_warn(&client->dev, "clock needs to be set\n");
642 639
643 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n", 640 dev_info(&client->dev, "%s found, %s\n",
644 ({ char *s; switch (rs5c372->type) { 641 ({ char *s; switch (rs5c372->type) {
645 case rtc_r2025sd: s = "r2025sd"; break; 642 case rtc_r2025sd: s = "r2025sd"; break;
646 case rtc_r2221tl: s = "r2221tl"; break; 643 case rtc_r2221tl: s = "r2221tl"; break;
@@ -696,4 +693,3 @@ MODULE_AUTHOR(
696 "Paul Mundt <lethal@linux-sh.org>"); 693 "Paul Mundt <lethal@linux-sh.org>");
697MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver"); 694MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver");
698MODULE_LICENSE("GPL"); 695MODULE_LICENSE("GPL");
699MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index d0cbf08040cd..1f9f7b4bf3fb 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Micro Crystal RV-3029 rtc class driver 2 * Micro Crystal RV-3029 / RV-3049 rtc class driver
3 * 3 *
4 * Author: Gregory Hermant <gregory.hermant@calao-systems.com> 4 * Author: Gregory Hermant <gregory.hermant@calao-systems.com>
5 * Michael Buesch <m@bues.ch> 5 * Michael Buesch <m@bues.ch>
@@ -14,13 +14,14 @@
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/spi/spi.h>
17#include <linux/bcd.h> 18#include <linux/bcd.h>
18#include <linux/rtc.h> 19#include <linux/rtc.h>
19#include <linux/delay.h> 20#include <linux/delay.h>
20#include <linux/of.h> 21#include <linux/of.h>
21#include <linux/hwmon.h> 22#include <linux/hwmon.h>
22#include <linux/hwmon-sysfs.h> 23#include <linux/hwmon-sysfs.h>
23 24#include <linux/regmap.h>
24 25
25/* Register map */ 26/* Register map */
26/* control section */ 27/* control section */
@@ -75,6 +76,7 @@
75#define RV3029_A_DW 0x14 76#define RV3029_A_DW 0x14
76#define RV3029_A_MO 0x15 77#define RV3029_A_MO 0x15
77#define RV3029_A_YR 0x16 78#define RV3029_A_YR 0x16
79#define RV3029_A_AE_X BIT(7)
78#define RV3029_ALARM_SECTION_LEN 0x07 80#define RV3029_ALARM_SECTION_LEN 0x07
79 81
80/* timer section */ 82/* timer section */
@@ -116,85 +118,84 @@
116#define RV3029_USR2_RAM_PAGE 0x3C 118#define RV3029_USR2_RAM_PAGE 0x3C
117#define RV3029_USR2_SECTION_LEN 0x04 119#define RV3029_USR2_SECTION_LEN 0x04
118 120
119static int 121struct rv3029_data {
120rv3029_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, 122 struct device *dev;
121 unsigned len) 123 struct rtc_device *rtc;
124 struct regmap *regmap;
125 int irq;
126};
127
128static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf,
129 unsigned int len)
122{ 130{
123 int ret; 131 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
124 132
125 if ((reg > RV3029_USR1_RAM_PAGE + 7) || 133 if ((reg > RV3029_USR1_RAM_PAGE + 7) ||
126 (reg + len > RV3029_USR1_RAM_PAGE + 8)) 134 (reg + len > RV3029_USR1_RAM_PAGE + 8))
127 return -EINVAL; 135 return -EINVAL;
128 136
129 ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf); 137 return regmap_bulk_read(rv3029->regmap, reg, buf, len);
130 if (ret < 0)
131 return ret;
132 if (ret < len)
133 return -EIO;
134 return 0;
135} 138}
136 139
137static int 140static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[],
138rv3029_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], 141 unsigned int len)
139 unsigned len)
140{ 142{
143 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
144
141 if ((reg > RV3029_USR1_RAM_PAGE + 7) || 145 if ((reg > RV3029_USR1_RAM_PAGE + 7) ||
142 (reg + len > RV3029_USR1_RAM_PAGE + 8)) 146 (reg + len > RV3029_USR1_RAM_PAGE + 8))
143 return -EINVAL; 147 return -EINVAL;
144 148
145 return i2c_smbus_write_i2c_block_data(client, reg, len, buf); 149 return regmap_bulk_write(rv3029->regmap, reg, buf, len);
146} 150}
147 151
148static int 152static int rv3029_update_bits(struct device *dev, u8 reg, u8 mask, u8 set)
149rv3029_i2c_update_bits(struct i2c_client *client, u8 reg, u8 mask, u8 set)
150{ 153{
151 u8 buf; 154 u8 buf;
152 int ret; 155 int ret;
153 156
154 ret = rv3029_i2c_read_regs(client, reg, &buf, 1); 157 ret = rv3029_read_regs(dev, reg, &buf, 1);
155 if (ret < 0) 158 if (ret < 0)
156 return ret; 159 return ret;
157 buf &= ~mask; 160 buf &= ~mask;
158 buf |= set & mask; 161 buf |= set & mask;
159 ret = rv3029_i2c_write_regs(client, reg, &buf, 1); 162 ret = rv3029_write_regs(dev, reg, &buf, 1);
160 if (ret < 0) 163 if (ret < 0)
161 return ret; 164 return ret;
162 165
163 return 0; 166 return 0;
164} 167}
165 168
166static int 169static int rv3029_get_sr(struct device *dev, u8 *buf)
167rv3029_i2c_get_sr(struct i2c_client *client, u8 *buf)
168{ 170{
169 int ret = rv3029_i2c_read_regs(client, RV3029_STATUS, buf, 1); 171 int ret = rv3029_read_regs(dev, RV3029_STATUS, buf, 1);
170 172
171 if (ret < 0) 173 if (ret < 0)
172 return -EIO; 174 return -EIO;
173 dev_dbg(&client->dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 175 dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
174 return 0; 176 return 0;
175} 177}
176 178
177static int 179static int rv3029_set_sr(struct device *dev, u8 val)
178rv3029_i2c_set_sr(struct i2c_client *client, u8 val)
179{ 180{
180 u8 buf[1]; 181 u8 buf[1];
181 int sr; 182 int sr;
182 183
183 buf[0] = val; 184 buf[0] = val;
184 sr = rv3029_i2c_write_regs(client, RV3029_STATUS, buf, 1); 185 sr = rv3029_write_regs(dev, RV3029_STATUS, buf, 1);
185 dev_dbg(&client->dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 186 dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
186 if (sr < 0) 187 if (sr < 0)
187 return -EIO; 188 return -EIO;
188 return 0; 189 return 0;
189} 190}
190 191
191static int rv3029_eeprom_busywait(struct i2c_client *client) 192static int rv3029_eeprom_busywait(struct device *dev)
192{ 193{
193 int i, ret; 194 int i, ret;
194 u8 sr; 195 u8 sr;
195 196
196 for (i = 100; i > 0; i--) { 197 for (i = 100; i > 0; i--) {
197 ret = rv3029_i2c_get_sr(client, &sr); 198 ret = rv3029_get_sr(dev, &sr);
198 if (ret < 0) 199 if (ret < 0)
199 break; 200 break;
200 if (!(sr & RV3029_STATUS_EEBUSY)) 201 if (!(sr & RV3029_STATUS_EEBUSY))
@@ -202,28 +203,28 @@ static int rv3029_eeprom_busywait(struct i2c_client *client)
202 usleep_range(1000, 10000); 203 usleep_range(1000, 10000);
203 } 204 }
204 if (i <= 0) { 205 if (i <= 0) {
205 dev_err(&client->dev, "EEPROM busy wait timeout.\n"); 206 dev_err(dev, "EEPROM busy wait timeout.\n");
206 return -ETIMEDOUT; 207 return -ETIMEDOUT;
207 } 208 }
208 209
209 return ret; 210 return ret;
210} 211}
211 212
212static int rv3029_eeprom_exit(struct i2c_client *client) 213static int rv3029_eeprom_exit(struct device *dev)
213{ 214{
214 /* Re-enable eeprom refresh */ 215 /* Re-enable eeprom refresh */
215 return rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 216 return rv3029_update_bits(dev, RV3029_ONOFF_CTRL,
216 RV3029_ONOFF_CTRL_EERE, 217 RV3029_ONOFF_CTRL_EERE,
217 RV3029_ONOFF_CTRL_EERE); 218 RV3029_ONOFF_CTRL_EERE);
218} 219}
219 220
220static int rv3029_eeprom_enter(struct i2c_client *client) 221static int rv3029_eeprom_enter(struct device *dev)
221{ 222{
222 int ret; 223 int ret;
223 u8 sr; 224 u8 sr;
224 225
225 /* Check whether we are in the allowed voltage range. */ 226 /* Check whether we are in the allowed voltage range. */
226 ret = rv3029_i2c_get_sr(client, &sr); 227 ret = rv3029_get_sr(dev, &sr);
227 if (ret < 0) 228 if (ret < 0)
228 return ret; 229 return ret;
229 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 230 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
@@ -232,129 +233,168 @@ static int rv3029_eeprom_enter(struct i2c_client *client)
232 */ 233 */
233 sr &= ~RV3029_STATUS_VLOW1; 234 sr &= ~RV3029_STATUS_VLOW1;
234 sr &= ~RV3029_STATUS_VLOW2; 235 sr &= ~RV3029_STATUS_VLOW2;
235 ret = rv3029_i2c_set_sr(client, sr); 236 ret = rv3029_set_sr(dev, sr);
236 if (ret < 0) 237 if (ret < 0)
237 return ret; 238 return ret;
238 usleep_range(1000, 10000); 239 usleep_range(1000, 10000);
239 ret = rv3029_i2c_get_sr(client, &sr); 240 ret = rv3029_get_sr(dev, &sr);
240 if (ret < 0) 241 if (ret < 0)
241 return ret; 242 return ret;
242 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 243 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
243 dev_err(&client->dev, 244 dev_err(dev,
244 "Supply voltage is too low to safely access the EEPROM.\n"); 245 "Supply voltage is too low to safely access the EEPROM.\n");
245 return -ENODEV; 246 return -ENODEV;
246 } 247 }
247 } 248 }
248 249
249 /* Disable eeprom refresh. */ 250 /* Disable eeprom refresh. */
250 ret = rv3029_i2c_update_bits(client, RV3029_ONOFF_CTRL, 251 ret = rv3029_update_bits(dev, RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE,
251 RV3029_ONOFF_CTRL_EERE, 0); 252 0);
252 if (ret < 0) 253 if (ret < 0)
253 return ret; 254 return ret;
254 255
255 /* Wait for any previous eeprom accesses to finish. */ 256 /* Wait for any previous eeprom accesses to finish. */
256 ret = rv3029_eeprom_busywait(client); 257 ret = rv3029_eeprom_busywait(dev);
257 if (ret < 0) 258 if (ret < 0)
258 rv3029_eeprom_exit(client); 259 rv3029_eeprom_exit(dev);
259 260
260 return ret; 261 return ret;
261} 262}
262 263
263static int rv3029_eeprom_read(struct i2c_client *client, u8 reg, 264static int rv3029_eeprom_read(struct device *dev, u8 reg,
264 u8 buf[], size_t len) 265 u8 buf[], size_t len)
265{ 266{
266 int ret, err; 267 int ret, err;
267 268
268 err = rv3029_eeprom_enter(client); 269 err = rv3029_eeprom_enter(dev);
269 if (err < 0) 270 if (err < 0)
270 return err; 271 return err;
271 272
272 ret = rv3029_i2c_read_regs(client, reg, buf, len); 273 ret = rv3029_read_regs(dev, reg, buf, len);
273 274
274 err = rv3029_eeprom_exit(client); 275 err = rv3029_eeprom_exit(dev);
275 if (err < 0) 276 if (err < 0)
276 return err; 277 return err;
277 278
278 return ret; 279 return ret;
279} 280}
280 281
281static int rv3029_eeprom_write(struct i2c_client *client, u8 reg, 282static int rv3029_eeprom_write(struct device *dev, u8 reg,
282 u8 const buf[], size_t len) 283 u8 const buf[], size_t len)
283{ 284{
284 int ret, err; 285 int ret, err;
285 size_t i; 286 size_t i;
286 u8 tmp; 287 u8 tmp;
287 288
288 err = rv3029_eeprom_enter(client); 289 err = rv3029_eeprom_enter(dev);
289 if (err < 0) 290 if (err < 0)
290 return err; 291 return err;
291 292
292 for (i = 0; i < len; i++, reg++) { 293 for (i = 0; i < len; i++, reg++) {
293 ret = rv3029_i2c_read_regs(client, reg, &tmp, 1); 294 ret = rv3029_read_regs(dev, reg, &tmp, 1);
294 if (ret < 0) 295 if (ret < 0)
295 break; 296 break;
296 if (tmp != buf[i]) { 297 if (tmp != buf[i]) {
297 ret = rv3029_i2c_write_regs(client, reg, &buf[i], 1); 298 ret = rv3029_write_regs(dev, reg, &buf[i], 1);
298 if (ret < 0) 299 if (ret < 0)
299 break; 300 break;
300 } 301 }
301 ret = rv3029_eeprom_busywait(client); 302 ret = rv3029_eeprom_busywait(dev);
302 if (ret < 0) 303 if (ret < 0)
303 break; 304 break;
304 } 305 }
305 306
306 err = rv3029_eeprom_exit(client); 307 err = rv3029_eeprom_exit(dev);
307 if (err < 0) 308 if (err < 0)
308 return err; 309 return err;
309 310
310 return ret; 311 return ret;
311} 312}
312 313
313static int rv3029_eeprom_update_bits(struct i2c_client *client, 314static int rv3029_eeprom_update_bits(struct device *dev,
314 u8 reg, u8 mask, u8 set) 315 u8 reg, u8 mask, u8 set)
315{ 316{
316 u8 buf; 317 u8 buf;
317 int ret; 318 int ret;
318 319
319 ret = rv3029_eeprom_read(client, reg, &buf, 1); 320 ret = rv3029_eeprom_read(dev, reg, &buf, 1);
320 if (ret < 0) 321 if (ret < 0)
321 return ret; 322 return ret;
322 buf &= ~mask; 323 buf &= ~mask;
323 buf |= set & mask; 324 buf |= set & mask;
324 ret = rv3029_eeprom_write(client, reg, &buf, 1); 325 ret = rv3029_eeprom_write(dev, reg, &buf, 1);
325 if (ret < 0) 326 if (ret < 0)
326 return ret; 327 return ret;
327 328
328 return 0; 329 return 0;
329} 330}
330 331
331static int 332static irqreturn_t rv3029_handle_irq(int irq, void *dev_id)
332rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 333{
334 struct device *dev = dev_id;
335 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
336 struct mutex *lock = &rv3029->rtc->ops_lock;
337 unsigned long events = 0;
338 u8 flags, controls;
339 int ret;
340
341 mutex_lock(lock);
342
343 ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
344 if (ret) {
345 dev_warn(dev, "Read IRQ Control Register error %d\n", ret);
346 mutex_unlock(lock);
347 return IRQ_NONE;
348 }
349
350 ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
351 if (ret) {
352 dev_warn(dev, "Read IRQ Flags Register error %d\n", ret);
353 mutex_unlock(lock);
354 return IRQ_NONE;
355 }
356
357 if (flags & RV3029_IRQ_FLAGS_AF) {
358 flags &= ~RV3029_IRQ_FLAGS_AF;
359 controls &= ~RV3029_IRQ_CTRL_AIE;
360 events |= RTC_AF;
361 }
362
363 if (events) {
364 rtc_update_irq(rv3029->rtc, 1, events);
365 rv3029_write_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
366 rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
367 }
368 mutex_unlock(lock);
369
370 return IRQ_HANDLED;
371}
372
373static int rv3029_read_time(struct device *dev, struct rtc_time *tm)
333{ 374{
334 u8 buf[1]; 375 u8 buf[1];
335 int ret; 376 int ret;
336 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; 377 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };
337 378
338 ret = rv3029_i2c_get_sr(client, buf); 379 ret = rv3029_get_sr(dev, buf);
339 if (ret < 0) { 380 if (ret < 0) {
340 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 381 dev_err(dev, "%s: reading SR failed\n", __func__);
341 return -EIO; 382 return -EIO;
342 } 383 }
343 384
344 ret = rv3029_i2c_read_regs(client, RV3029_W_SEC, regs, 385 ret = rv3029_read_regs(dev, RV3029_W_SEC, regs,
345 RV3029_WATCH_SECTION_LEN); 386 RV3029_WATCH_SECTION_LEN);
346 if (ret < 0) { 387 if (ret < 0) {
347 dev_err(&client->dev, "%s: reading RTC section failed\n", 388 dev_err(dev, "%s: reading RTC section failed\n", __func__);
348 __func__);
349 return ret; 389 return ret;
350 } 390 }
351 391
352 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC-RV3029_W_SEC]); 392 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]);
353 tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES-RV3029_W_SEC]); 393 tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]);
354 394
355 /* HR field has a more complex interpretation */ 395 /* HR field has a more complex interpretation */
356 { 396 {
357 const u8 _hr = regs[RV3029_W_HOURS-RV3029_W_SEC]; 397 const u8 _hr = regs[RV3029_W_HOURS - RV3029_W_SEC];
358 398
359 if (_hr & RV3029_REG_HR_12_24) { 399 if (_hr & RV3029_REG_HR_12_24) {
360 /* 12h format */ 400 /* 12h format */
@@ -365,77 +405,86 @@ rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
365 tm->tm_hour = bcd2bin(_hr & 0x3f); 405 tm->tm_hour = bcd2bin(_hr & 0x3f);
366 } 406 }
367 407
368 tm->tm_mday = bcd2bin(regs[RV3029_W_DATE-RV3029_W_SEC]); 408 tm->tm_mday = bcd2bin(regs[RV3029_W_DATE - RV3029_W_SEC]);
369 tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS-RV3029_W_SEC]) - 1; 409 tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
370 tm->tm_year = bcd2bin(regs[RV3029_W_YEARS-RV3029_W_SEC]) + 100; 410 tm->tm_year = bcd2bin(regs[RV3029_W_YEARS - RV3029_W_SEC]) + 100;
371 tm->tm_wday = bcd2bin(regs[RV3029_W_DAYS-RV3029_W_SEC]) - 1; 411 tm->tm_wday = bcd2bin(regs[RV3029_W_DAYS - RV3029_W_SEC]) - 1;
372 412
373 return 0; 413 return 0;
374} 414}
375 415
376static int rv3029_rtc_read_time(struct device *dev, struct rtc_time *tm) 416static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
377{
378 return rv3029_i2c_read_time(to_i2c_client(dev), tm);
379}
380
381static int
382rv3029_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
383{ 417{
384 struct rtc_time *const tm = &alarm->time; 418 struct rtc_time *const tm = &alarm->time;
385 int ret; 419 int ret;
386 u8 regs[8]; 420 u8 regs[8], controls, flags;
387 421
388 ret = rv3029_i2c_get_sr(client, regs); 422 ret = rv3029_get_sr(dev, regs);
389 if (ret < 0) { 423 if (ret < 0) {
390 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 424 dev_err(dev, "%s: reading SR failed\n", __func__);
391 return -EIO; 425 return -EIO;
392 } 426 }
393 427
394 ret = rv3029_i2c_read_regs(client, RV3029_A_SC, regs, 428 ret = rv3029_read_regs(dev, RV3029_A_SC, regs,
395 RV3029_ALARM_SECTION_LEN); 429 RV3029_ALARM_SECTION_LEN);
396 430
397 if (ret < 0) { 431 if (ret < 0) {
398 dev_err(&client->dev, "%s: reading alarm section failed\n", 432 dev_err(dev, "%s: reading alarm section failed\n", __func__);
399 __func__);
400 return ret; 433 return ret;
401 } 434 }
402 435
403 tm->tm_sec = bcd2bin(regs[RV3029_A_SC-RV3029_A_SC] & 0x7f); 436 ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
404 tm->tm_min = bcd2bin(regs[RV3029_A_MN-RV3029_A_SC] & 0x7f); 437 if (ret) {
405 tm->tm_hour = bcd2bin(regs[RV3029_A_HR-RV3029_A_SC] & 0x3f); 438 dev_err(dev, "Read IRQ Control Register error %d\n", ret);
406 tm->tm_mday = bcd2bin(regs[RV3029_A_DT-RV3029_A_SC] & 0x3f); 439 return ret;
407 tm->tm_mon = bcd2bin(regs[RV3029_A_MO-RV3029_A_SC] & 0x1f) - 1; 440 }
408 tm->tm_year = bcd2bin(regs[RV3029_A_YR-RV3029_A_SC] & 0x7f) + 100; 441 ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
409 tm->tm_wday = bcd2bin(regs[RV3029_A_DW-RV3029_A_SC] & 0x07) - 1; 442 if (ret < 0) {
443 dev_err(dev, "Read IRQ Flags Register error %d\n", ret);
444 return ret;
445 }
410 446
411 return 0; 447 tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f);
412} 448 tm->tm_min = bcd2bin(regs[RV3029_A_MN - RV3029_A_SC] & 0x7f);
449 tm->tm_hour = bcd2bin(regs[RV3029_A_HR - RV3029_A_SC] & 0x3f);
450 tm->tm_mday = bcd2bin(regs[RV3029_A_DT - RV3029_A_SC] & 0x3f);
451 tm->tm_mon = bcd2bin(regs[RV3029_A_MO - RV3029_A_SC] & 0x1f) - 1;
452 tm->tm_year = bcd2bin(regs[RV3029_A_YR - RV3029_A_SC] & 0x7f) + 100;
453 tm->tm_wday = bcd2bin(regs[RV3029_A_DW - RV3029_A_SC] & 0x07) - 1;
413 454
414static int 455 alarm->enabled = !!(controls & RV3029_IRQ_CTRL_AIE);
415rv3029_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 456 alarm->pending = (flags & RV3029_IRQ_FLAGS_AF) && alarm->enabled;
416{ 457
417 return rv3029_i2c_read_alarm(to_i2c_client(dev), alarm); 458 return 0;
418} 459}
419 460
420static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client *client, 461static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable)
421 int enable)
422{ 462{
423 int ret; 463 int ret;
464 u8 controls;
465
466 ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
467 if (ret < 0) {
468 dev_warn(dev, "Read IRQ Control Register error %d\n", ret);
469 return ret;
470 }
424 471
425 /* enable/disable AIE irq */ 472 /* enable/disable AIE irq */
426 ret = rv3029_i2c_update_bits(client, RV3029_IRQ_CTRL, 473 if (enable)
427 RV3029_IRQ_CTRL_AIE, 474 controls |= RV3029_IRQ_CTRL_AIE;
428 (enable ? RV3029_IRQ_CTRL_AIE : 0)); 475 else
476 controls &= ~RV3029_IRQ_CTRL_AIE;
477
478 ret = rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
429 if (ret < 0) { 479 if (ret < 0) {
430 dev_err(&client->dev, "can't update INT reg\n"); 480 dev_err(dev, "can't update INT reg\n");
431 return ret; 481 return ret;
432 } 482 }
433 483
434 return 0; 484 return 0;
435} 485}
436 486
437static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client, 487static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
438 struct rtc_wkalrm *alarm)
439{ 488{
440 struct rtc_time *const tm = &alarm->time; 489 struct rtc_time *const tm = &alarm->time;
441 int ret; 490 int ret;
@@ -449,57 +498,48 @@ static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client,
449 if (tm->tm_year < 100) 498 if (tm->tm_year < 100)
450 return -EINVAL; 499 return -EINVAL;
451 500
452 ret = rv3029_i2c_get_sr(client, regs); 501 ret = rv3029_get_sr(dev, regs);
453 if (ret < 0) { 502 if (ret < 0) {
454 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 503 dev_err(dev, "%s: reading SR failed\n", __func__);
455 return -EIO; 504 return -EIO;
456 } 505 }
457 regs[RV3029_A_SC-RV3029_A_SC] = bin2bcd(tm->tm_sec & 0x7f);
458 regs[RV3029_A_MN-RV3029_A_SC] = bin2bcd(tm->tm_min & 0x7f);
459 regs[RV3029_A_HR-RV3029_A_SC] = bin2bcd(tm->tm_hour & 0x3f);
460 regs[RV3029_A_DT-RV3029_A_SC] = bin2bcd(tm->tm_mday & 0x3f);
461 regs[RV3029_A_MO-RV3029_A_SC] = bin2bcd((tm->tm_mon & 0x1f) - 1);
462 regs[RV3029_A_DW-RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1);
463 regs[RV3029_A_YR-RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100);
464 506
465 ret = rv3029_i2c_write_regs(client, RV3029_A_SC, regs, 507 /* Activate all the alarms with AE_x bit */
466 RV3029_ALARM_SECTION_LEN); 508 regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X;
509 regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min) | RV3029_A_AE_X;
510 regs[RV3029_A_HR - RV3029_A_SC] = (bin2bcd(tm->tm_hour) & 0x3f)
511 | RV3029_A_AE_X;
512 regs[RV3029_A_DT - RV3029_A_SC] = (bin2bcd(tm->tm_mday) & 0x3f)
513 | RV3029_A_AE_X;
514 regs[RV3029_A_MO - RV3029_A_SC] = (bin2bcd(tm->tm_mon + 1) & 0x1f)
515 | RV3029_A_AE_X;
516 regs[RV3029_A_DW - RV3029_A_SC] = (bin2bcd(tm->tm_wday + 1) & 0x7)
517 | RV3029_A_AE_X;
518 regs[RV3029_A_YR - RV3029_A_SC] = (bin2bcd(tm->tm_year - 100))
519 | RV3029_A_AE_X;
520
521 /* Write the alarm */
522 ret = rv3029_write_regs(dev, RV3029_A_SC, regs,
523 RV3029_ALARM_SECTION_LEN);
467 if (ret < 0) 524 if (ret < 0)
468 return ret; 525 return ret;
469 526
470 if (alarm->enabled) { 527 if (alarm->enabled) {
471 /* clear AF flag */
472 ret = rv3029_i2c_update_bits(client, RV3029_IRQ_FLAGS,
473 RV3029_IRQ_FLAGS_AF, 0);
474 if (ret < 0) {
475 dev_err(&client->dev, "can't clear alarm flag\n");
476 return ret;
477 }
478 /* enable AIE irq */ 528 /* enable AIE irq */
479 ret = rv3029_rtc_i2c_alarm_set_irq(client, 1); 529 ret = rv3029_alarm_irq_enable(dev, 1);
480 if (ret) 530 if (ret)
481 return ret; 531 return ret;
482
483 dev_dbg(&client->dev, "alarm IRQ armed\n");
484 } else { 532 } else {
485 /* disable AIE irq */ 533 /* disable AIE irq */
486 ret = rv3029_rtc_i2c_alarm_set_irq(client, 0); 534 ret = rv3029_alarm_irq_enable(dev, 0);
487 if (ret) 535 if (ret)
488 return ret; 536 return ret;
489
490 dev_dbg(&client->dev, "alarm IRQ disabled\n");
491 } 537 }
492 538
493 return 0; 539 return 0;
494} 540}
495 541
496static int rv3029_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 542static int rv3029_set_time(struct device *dev, struct rtc_time *tm)
497{
498 return rv3029_rtc_i2c_set_alarm(to_i2c_client(dev), alarm);
499}
500
501static int
502rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
503{ 543{
504 u8 regs[8]; 544 u8 regs[8];
505 int ret; 545 int ret;
@@ -512,39 +552,34 @@ rv3029_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
512 if (tm->tm_year < 100) 552 if (tm->tm_year < 100)
513 return -EINVAL; 553 return -EINVAL;
514 554
515 regs[RV3029_W_SEC-RV3029_W_SEC] = bin2bcd(tm->tm_sec); 555 regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec);
516 regs[RV3029_W_MINUTES-RV3029_W_SEC] = bin2bcd(tm->tm_min); 556 regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min);
517 regs[RV3029_W_HOURS-RV3029_W_SEC] = bin2bcd(tm->tm_hour); 557 regs[RV3029_W_HOURS - RV3029_W_SEC] = bin2bcd(tm->tm_hour);
518 regs[RV3029_W_DATE-RV3029_W_SEC] = bin2bcd(tm->tm_mday); 558 regs[RV3029_W_DATE - RV3029_W_SEC] = bin2bcd(tm->tm_mday);
519 regs[RV3029_W_MONTHS-RV3029_W_SEC] = bin2bcd(tm->tm_mon+1); 559 regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
520 regs[RV3029_W_DAYS-RV3029_W_SEC] = bin2bcd((tm->tm_wday & 7)+1); 560 regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7;
521 regs[RV3029_W_YEARS-RV3029_W_SEC] = bin2bcd(tm->tm_year - 100); 561 regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100);
522 562
523 ret = rv3029_i2c_write_regs(client, RV3029_W_SEC, regs, 563 ret = rv3029_write_regs(dev, RV3029_W_SEC, regs,
524 RV3029_WATCH_SECTION_LEN); 564 RV3029_WATCH_SECTION_LEN);
525 if (ret < 0) 565 if (ret < 0)
526 return ret; 566 return ret;
527 567
528 ret = rv3029_i2c_get_sr(client, regs); 568 ret = rv3029_get_sr(dev, regs);
529 if (ret < 0) { 569 if (ret < 0) {
530 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 570 dev_err(dev, "%s: reading SR failed\n", __func__);
531 return ret; 571 return ret;
532 } 572 }
533 /* clear PON bit */ 573 /* clear PON bit */
534 ret = rv3029_i2c_set_sr(client, (regs[0] & ~RV3029_STATUS_PON)); 574 ret = rv3029_set_sr(dev, (regs[0] & ~RV3029_STATUS_PON));
535 if (ret < 0) { 575 if (ret < 0) {
536 dev_err(&client->dev, "%s: reading SR failed\n", __func__); 576 dev_err(dev, "%s: reading SR failed\n", __func__);
537 return ret; 577 return ret;
538 } 578 }
539 579
540 return 0; 580 return 0;
541} 581}
542 582
543static int rv3029_rtc_set_time(struct device *dev, struct rtc_time *tm)
544{
545 return rv3029_i2c_set_time(to_i2c_client(dev), tm);
546}
547
548static const struct rv3029_trickle_tab_elem { 583static const struct rv3029_trickle_tab_elem {
549 u32 r; /* resistance in ohms */ 584 u32 r; /* resistance in ohms */
550 u8 conf; /* trickle config bits */ 585 u8 conf; /* trickle config bits */
@@ -602,9 +637,9 @@ static const struct rv3029_trickle_tab_elem {
602 }, 637 },
603}; 638};
604 639
605static void rv3029_trickle_config(struct i2c_client *client) 640static void rv3029_trickle_config(struct device *dev)
606{ 641{
607 struct device_node *of_node = client->dev.of_node; 642 struct device_node *of_node = dev->of_node;
608 const struct rv3029_trickle_tab_elem *elem; 643 const struct rv3029_trickle_tab_elem *elem;
609 int i, err; 644 int i, err;
610 u32 ohms; 645 u32 ohms;
@@ -626,27 +661,25 @@ static void rv3029_trickle_config(struct i2c_client *client)
626 break; 661 break;
627 } 662 }
628 trickle_set_bits = elem->conf; 663 trickle_set_bits = elem->conf;
629 dev_info(&client->dev, 664 dev_info(dev,
630 "Trickle charger enabled at %d ohms resistance.\n", 665 "Trickle charger enabled at %d ohms resistance.\n",
631 elem->r); 666 elem->r);
632 } 667 }
633 err = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL, 668 err = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,
634 RV3029_TRICKLE_MASK, 669 RV3029_TRICKLE_MASK,
635 trickle_set_bits); 670 trickle_set_bits);
636 if (err < 0) { 671 if (err < 0)
637 dev_err(&client->dev, 672 dev_err(dev, "Failed to update trickle charger config\n");
638 "Failed to update trickle charger config\n");
639 }
640} 673}
641 674
642#ifdef CONFIG_RTC_DRV_RV3029_HWMON 675#ifdef CONFIG_RTC_DRV_RV3029_HWMON
643 676
644static int rv3029_read_temp(struct i2c_client *client, int *temp_mC) 677static int rv3029_read_temp(struct device *dev, int *temp_mC)
645{ 678{
646 int ret; 679 int ret;
647 u8 temp; 680 u8 temp;
648 681
649 ret = rv3029_i2c_read_regs(client, RV3029_TEMP_PAGE, &temp, 1); 682 ret = rv3029_read_regs(dev, RV3029_TEMP_PAGE, &temp, 1);
650 if (ret < 0) 683 if (ret < 0)
651 return ret; 684 return ret;
652 685
@@ -659,10 +692,9 @@ static ssize_t rv3029_hwmon_show_temp(struct device *dev,
659 struct device_attribute *attr, 692 struct device_attribute *attr,
660 char *buf) 693 char *buf)
661{ 694{
662 struct i2c_client *client = dev_get_drvdata(dev);
663 int ret, temp_mC; 695 int ret, temp_mC;
664 696
665 ret = rv3029_read_temp(client, &temp_mC); 697 ret = rv3029_read_temp(dev, &temp_mC);
666 if (ret < 0) 698 if (ret < 0)
667 return ret; 699 return ret;
668 700
@@ -674,7 +706,6 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev,
674 const char *buf, 706 const char *buf,
675 size_t count) 707 size_t count)
676{ 708{
677 struct i2c_client *client = dev_get_drvdata(dev);
678 unsigned long interval_ms; 709 unsigned long interval_ms;
679 int ret; 710 int ret;
680 u8 th_set_bits = 0; 711 u8 th_set_bits = 0;
@@ -688,7 +719,7 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev,
688 if (interval_ms >= 16000) 719 if (interval_ms >= 16000)
689 th_set_bits |= RV3029_EECTRL_THP; 720 th_set_bits |= RV3029_EECTRL_THP;
690 } 721 }
691 ret = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL, 722 ret = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,
692 RV3029_EECTRL_THE | RV3029_EECTRL_THP, 723 RV3029_EECTRL_THE | RV3029_EECTRL_THP,
693 th_set_bits); 724 th_set_bits);
694 if (ret < 0) 725 if (ret < 0)
@@ -701,11 +732,10 @@ static ssize_t rv3029_hwmon_show_update_interval(struct device *dev,
701 struct device_attribute *attr, 732 struct device_attribute *attr,
702 char *buf) 733 char *buf)
703{ 734{
704 struct i2c_client *client = dev_get_drvdata(dev);
705 int ret, interval_ms; 735 int ret, interval_ms;
706 u8 eectrl; 736 u8 eectrl;
707 737
708 ret = rv3029_eeprom_read(client, RV3029_CONTROL_E2P_EECTRL, 738 ret = rv3029_eeprom_read(dev, RV3029_CONTROL_E2P_EECTRL,
709 &eectrl, 1); 739 &eectrl, 1);
710 if (ret < 0) 740 if (ret < 0)
711 return ret; 741 return ret;
@@ -735,82 +765,226 @@ static struct attribute *rv3029_hwmon_attrs[] = {
735}; 765};
736ATTRIBUTE_GROUPS(rv3029_hwmon); 766ATTRIBUTE_GROUPS(rv3029_hwmon);
737 767
738static void rv3029_hwmon_register(struct i2c_client *client) 768static void rv3029_hwmon_register(struct device *dev, const char *name)
739{ 769{
770 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
740 struct device *hwmon_dev; 771 struct device *hwmon_dev;
741 772
742 hwmon_dev = devm_hwmon_device_register_with_groups( 773 hwmon_dev = devm_hwmon_device_register_with_groups(dev, name, rv3029,
743 &client->dev, client->name, client, rv3029_hwmon_groups); 774 rv3029_hwmon_groups);
744 if (IS_ERR(hwmon_dev)) { 775 if (IS_ERR(hwmon_dev)) {
745 dev_warn(&client->dev, 776 dev_warn(dev, "unable to register hwmon device %ld\n",
746 "unable to register hwmon device %ld\n", 777 PTR_ERR(hwmon_dev));
747 PTR_ERR(hwmon_dev));
748 } 778 }
749} 779}
750 780
751#else /* CONFIG_RTC_DRV_RV3029_HWMON */ 781#else /* CONFIG_RTC_DRV_RV3029_HWMON */
752 782
753static void rv3029_hwmon_register(struct i2c_client *client) 783static void rv3029_hwmon_register(struct device *dev, const char *name)
754{ 784{
755} 785}
756 786
757#endif /* CONFIG_RTC_DRV_RV3029_HWMON */ 787#endif /* CONFIG_RTC_DRV_RV3029_HWMON */
758 788
759static const struct rtc_class_ops rv3029_rtc_ops = { 789static struct rtc_class_ops rv3029_rtc_ops = {
760 .read_time = rv3029_rtc_read_time, 790 .read_time = rv3029_read_time,
761 .set_time = rv3029_rtc_set_time, 791 .set_time = rv3029_set_time,
762 .read_alarm = rv3029_rtc_read_alarm,
763 .set_alarm = rv3029_rtc_set_alarm,
764}; 792};
765 793
766static struct i2c_device_id rv3029_id[] = { 794static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
767 { "rv3029", 0 }, 795 const char *name)
768 { "rv3029c2", 0 },
769 { }
770};
771MODULE_DEVICE_TABLE(i2c, rv3029_id);
772
773static int rv3029_probe(struct i2c_client *client,
774 const struct i2c_device_id *id)
775{ 796{
776 struct rtc_device *rtc; 797 struct rv3029_data *rv3029;
777 int rc = 0; 798 int rc = 0;
778 u8 buf[1]; 799 u8 buf[1];
779 800
780 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL)) 801 rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL);
781 return -ENODEV; 802 if (!rv3029)
803 return -ENOMEM;
782 804
783 rc = rv3029_i2c_get_sr(client, buf); 805 rv3029->regmap = regmap;
806 rv3029->irq = irq;
807 rv3029->dev = dev;
808 dev_set_drvdata(dev, rv3029);
809
810 rc = rv3029_get_sr(dev, buf);
784 if (rc < 0) { 811 if (rc < 0) {
785 dev_err(&client->dev, "reading status failed\n"); 812 dev_err(dev, "reading status failed\n");
786 return rc; 813 return rc;
787 } 814 }
788 815
789 rv3029_trickle_config(client); 816 rv3029_trickle_config(dev);
790 rv3029_hwmon_register(client); 817 rv3029_hwmon_register(dev, name);
791
792 rtc = devm_rtc_device_register(&client->dev, client->name,
793 &rv3029_rtc_ops, THIS_MODULE);
794 818
795 if (IS_ERR(rtc)) 819 rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops,
796 return PTR_ERR(rtc); 820 THIS_MODULE);
821 if (IS_ERR(rv3029->rtc)) {
822 dev_err(dev, "unable to register the class device\n");
823 return PTR_ERR(rv3029->rtc);
824 }
797 825
798 i2c_set_clientdata(client, rtc); 826 if (rv3029->irq > 0) {
827 rc = devm_request_threaded_irq(dev, rv3029->irq,
828 NULL, rv3029_handle_irq,
829 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
830 "rv3029", dev);
831 if (rc) {
832 dev_warn(dev, "unable to request IRQ, alarms disabled\n");
833 rv3029->irq = 0;
834 } else {
835 rv3029_rtc_ops.read_alarm = rv3029_read_alarm;
836 rv3029_rtc_ops.set_alarm = rv3029_set_alarm;
837 rv3029_rtc_ops.alarm_irq_enable = rv3029_alarm_irq_enable;
838 }
839 }
799 840
800 return 0; 841 return 0;
801} 842}
802 843
844#if IS_ENABLED(CONFIG_I2C)
845
846static int rv3029_i2c_probe(struct i2c_client *client,
847 const struct i2c_device_id *id)
848{
849 struct regmap *regmap;
850 static const struct regmap_config config = {
851 .reg_bits = 8,
852 .val_bits = 8,
853 };
854
855 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
856 I2C_FUNC_SMBUS_BYTE)) {
857 dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n");
858 return -ENODEV;
859 }
860
861 regmap = devm_regmap_init_i2c(client, &config);
862 if (IS_ERR(regmap)) {
863 dev_err(&client->dev, "%s: regmap allocation failed: %ld\n",
864 __func__, PTR_ERR(regmap));
865 return PTR_ERR(regmap);
866 }
867
868 return rv3029_probe(&client->dev, regmap, client->irq, client->name);
869}
870
871static struct i2c_device_id rv3029_id[] = {
872 { "rv3029", 0 },
873 { "rv3029c2", 0 },
874 { }
875};
876MODULE_DEVICE_TABLE(i2c, rv3029_id);
877
803static struct i2c_driver rv3029_driver = { 878static struct i2c_driver rv3029_driver = {
804 .driver = { 879 .driver = {
805 .name = "rtc-rv3029c2", 880 .name = "rtc-rv3029c2",
806 }, 881 },
807 .probe = rv3029_probe, 882 .probe = rv3029_i2c_probe,
808 .id_table = rv3029_id, 883 .id_table = rv3029_id,
809}; 884};
810 885
811module_i2c_driver(rv3029_driver); 886static int rv3029_register_driver(void)
887{
888 return i2c_add_driver(&rv3029_driver);
889}
890
891static void rv3029_unregister_driver(void)
892{
893 i2c_del_driver(&rv3029_driver);
894}
895
896#else
897
898static int rv3029_register_driver(void)
899{
900 return 0;
901}
902
903static void rv3029_unregister_driver(void)
904{
905}
906
907#endif
908
909#if IS_ENABLED(CONFIG_SPI_MASTER)
910
911static int rv3049_probe(struct spi_device *spi)
912{
913 static const struct regmap_config config = {
914 .reg_bits = 8,
915 .val_bits = 8,
916 };
917 struct regmap *regmap;
918
919 regmap = devm_regmap_init_spi(spi, &config);
920 if (IS_ERR(regmap)) {
921 dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
922 __func__, PTR_ERR(regmap));
923 return PTR_ERR(regmap);
924 }
925
926 return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049");
927}
928
929static struct spi_driver rv3049_driver = {
930 .driver = {
931 .name = "rv3049",
932 },
933 .probe = rv3049_probe,
934};
935
936static int rv3049_register_driver(void)
937{
938 return spi_register_driver(&rv3049_driver);
939}
940
941static void rv3049_unregister_driver(void)
942{
943 spi_unregister_driver(&rv3049_driver);
944}
945
946#else
947
948static int rv3049_register_driver(void)
949{
950 return 0;
951}
952
953static void rv3049_unregister_driver(void)
954{
955}
956
957#endif
958
959static int __init rv30x9_init(void)
960{
961 int ret;
962
963 ret = rv3029_register_driver();
964 if (ret) {
965 pr_err("Failed to register rv3029 driver: %d\n", ret);
966 return ret;
967 }
968
969 ret = rv3049_register_driver();
970 if (ret) {
971 pr_err("Failed to register rv3049 driver: %d\n", ret);
972 rv3029_unregister_driver();
973 }
974
975 return ret;
976}
977module_init(rv30x9_init)
978
979static void __exit rv30x9_exit(void)
980{
981 rv3049_unregister_driver();
982 rv3029_unregister_driver();
983}
984module_exit(rv30x9_exit)
812 985
813MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>"); 986MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>");
814MODULE_AUTHOR("Michael Buesch <m@bues.ch>"); 987MODULE_AUTHOR("Michael Buesch <m@bues.ch>");
815MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver"); 988MODULE_DESCRIPTION("Micro Crystal RV3029/RV3049 RTC driver");
816MODULE_LICENSE("GPL"); 989MODULE_LICENSE("GPL");
990MODULE_ALIAS("spi:rv3049");
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index 161e25d016c3..0c362a3d1f17 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -18,8 +18,6 @@
18#include <linux/rtc.h> 18#include <linux/rtc.h>
19#include <linux/log2.h> 19#include <linux/log2.h>
20 20
21#define DRV_VERSION "0.1"
22
23#define RX8581_REG_SC 0x00 /* Second in BCD */ 21#define RX8581_REG_SC 0x00 /* Second in BCD */
24#define RX8581_REG_MN 0x01 /* Minute in BCD */ 22#define RX8581_REG_MN 0x01 /* Minute in BCD */
25#define RX8581_REG_HR 0x02 /* Hour in BCD */ 23#define RX8581_REG_HR 0x02 /* Hour in BCD */
@@ -292,8 +290,6 @@ static int rx8581_probe(struct i2c_client *client,
292 rx8581->write_block_data = rx8581_write_block_data; 290 rx8581->write_block_data = rx8581_write_block_data;
293 } 291 }
294 292
295 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
296
297 rx8581->rtc = devm_rtc_device_register(&client->dev, 293 rx8581->rtc = devm_rtc_device_register(&client->dev,
298 rx8581_driver.driver.name, &rx8581_rtc_ops, THIS_MODULE); 294 rx8581_driver.driver.name, &rx8581_rtc_ops, THIS_MODULE);
299 295
@@ -325,4 +321,3 @@ module_i2c_driver(rx8581_driver);
325MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>"); 321MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>");
326MODULE_DESCRIPTION("Epson RX-8581 RTC driver"); 322MODULE_DESCRIPTION("Epson RX-8581 RTC driver");
327MODULE_LICENSE("GPL"); 323MODULE_LICENSE("GPL");
328MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 2b81dd4baf17..a45845a571e5 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -30,7 +30,6 @@
30#include <asm/rtc.h> 30#include <asm/rtc.h>
31 31
32#define DRV_NAME "sh-rtc" 32#define DRV_NAME "sh-rtc"
33#define DRV_VERSION "0.2.3"
34 33
35#define RTC_REG(r) ((r) * rtc_reg_size) 34#define RTC_REG(r) ((r) * rtc_reg_size)
36 35
@@ -790,7 +789,6 @@ static struct platform_driver sh_rtc_platform_driver = {
790module_platform_driver_probe(sh_rtc_platform_driver, sh_rtc_probe); 789module_platform_driver_probe(sh_rtc_platform_driver, sh_rtc_probe);
791 790
792MODULE_DESCRIPTION("SuperH on-chip RTC driver"); 791MODULE_DESCRIPTION("SuperH on-chip RTC driver");
793MODULE_VERSION(DRV_VERSION);
794MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, " 792MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, "
795 "Jamie Lenehan <lenehan@twibble.org>, " 793 "Jamie Lenehan <lenehan@twibble.org>, "
796 "Angelo Castello <angelo.castello@st.com>"); 794 "Angelo Castello <angelo.castello@st.com>");
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 950c5d0b6dca..0f11c2a228e3 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -322,7 +322,7 @@ static int snvs_rtc_suspend(struct device *dev)
322 struct snvs_rtc_data *data = dev_get_drvdata(dev); 322 struct snvs_rtc_data *data = dev_get_drvdata(dev);
323 323
324 if (device_may_wakeup(dev)) 324 if (device_may_wakeup(dev))
325 enable_irq_wake(data->irq); 325 return enable_irq_wake(data->irq);
326 326
327 return 0; 327 return 0;
328} 328}
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index ba6a83b5b5c9..a456cb6177ea 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -23,8 +23,6 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/module.h> 24#include <linux/module.h>
25 25
26#define DRV_VERSION "0.1"
27
28#define RTC_REG_SIZE 0x20000 26#define RTC_REG_SIZE 0x20000
29#define RTC_OFFSET 0x1fff0 27#define RTC_OFFSET 0x1fff0
30 28
@@ -366,4 +364,3 @@ module_platform_driver(stk17ta8_rtc_driver);
366MODULE_AUTHOR("Thomas Hommel <thomas.hommel@ge.com>"); 364MODULE_AUTHOR("Thomas Hommel <thomas.hommel@ge.com>");
367MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver"); 365MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver");
368MODULE_LICENSE("GPL"); 366MODULE_LICENSE("GPL");
369MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index ca54d039da31..e6aaaa52e7fe 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -107,14 +107,19 @@ static struct stmp3xxx_wdt_pdata wdt_pdata = {
107 107
108static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev) 108static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
109{ 109{
110 int rc = -1;
110 struct platform_device *wdt_pdev = 111 struct platform_device *wdt_pdev =
111 platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id); 112 platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id);
112 113
113 if (wdt_pdev) { 114 if (wdt_pdev) {
114 wdt_pdev->dev.parent = &rtc_pdev->dev; 115 wdt_pdev->dev.parent = &rtc_pdev->dev;
115 wdt_pdev->dev.platform_data = &wdt_pdata; 116 wdt_pdev->dev.platform_data = &wdt_pdata;
116 platform_device_add(wdt_pdev); 117 rc = platform_device_add(wdt_pdev);
117 } 118 }
119
120 if (rc)
121 dev_err(&rtc_pdev->dev,
122 "failed to register stmp3xxx_rtc_wdt\n");
118} 123}
119#else 124#else
120static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev) 125static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c
index e404faac6851..a3418a8a3796 100644
--- a/drivers/rtc/rtc-tps6586x.c
+++ b/drivers/rtc/rtc-tps6586x.c
@@ -344,7 +344,7 @@ static struct platform_driver tps6586x_rtc_driver = {
344}; 344};
345module_platform_driver(tps6586x_rtc_driver); 345module_platform_driver(tps6586x_rtc_driver);
346 346
347MODULE_ALIAS("platform:rtc-tps6586x"); 347MODULE_ALIAS("platform:tps6586x-rtc");
348MODULE_DESCRIPTION("TI TPS6586x RTC driver"); 348MODULE_DESCRIPTION("TI TPS6586x RTC driver");
349MODULE_AUTHOR("Laxman dewangan <ldewangan@nvidia.com>"); 349MODULE_AUTHOR("Laxman dewangan <ldewangan@nvidia.com>");
350MODULE_LICENSE("GPL v2"); 350MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 5638b7ba8b06..f08f18e4fcdf 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -24,8 +24,6 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26 26
27#define DRV_VERSION "1.0.8"
28
29/* offsets into CCR area */ 27/* offsets into CCR area */
30 28
31#define CCR_SEC 0 29#define CCR_SEC 0
@@ -634,8 +632,6 @@ static int x1205_probe(struct i2c_client *client,
634 if (x1205_validate_client(client) < 0) 632 if (x1205_validate_client(client) < 0)
635 return -ENODEV; 633 return -ENODEV;
636 634
637 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
638
639 rtc = devm_rtc_device_register(&client->dev, x1205_driver.driver.name, 635 rtc = devm_rtc_device_register(&client->dev, x1205_driver.driver.name,
640 &x1205_rtc_ops, THIS_MODULE); 636 &x1205_rtc_ops, THIS_MODULE);
641 637
@@ -693,4 +689,3 @@ MODULE_AUTHOR(
693 "Alessandro Zummo <a.zummo@towertech.it>"); 689 "Alessandro Zummo <a.zummo@towertech.it>");
694MODULE_DESCRIPTION("Xicor/Intersil X1205 RTC driver"); 690MODULE_DESCRIPTION("Xicor/Intersil X1205 RTC driver");
695MODULE_LICENSE("GPL"); 691MODULE_LICENSE("GPL");
696MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c
index 8b28762f06df..da18a8ae3c1d 100644
--- a/drivers/rtc/rtc-zynqmp.c
+++ b/drivers/rtc/rtc-zynqmp.c
@@ -45,6 +45,7 @@
45#define RTC_INT_SEC BIT(0) 45#define RTC_INT_SEC BIT(0)
46#define RTC_INT_ALRM BIT(1) 46#define RTC_INT_ALRM BIT(1)
47#define RTC_OSC_EN BIT(24) 47#define RTC_OSC_EN BIT(24)
48#define RTC_BATT_EN BIT(31)
48 49
49#define RTC_CALIB_DEF 0x198233 50#define RTC_CALIB_DEF 0x198233
50#define RTC_CALIB_MASK 0x1FFFFF 51#define RTC_CALIB_MASK 0x1FFFFF
@@ -55,6 +56,7 @@ struct xlnx_rtc_dev {
55 void __iomem *reg_base; 56 void __iomem *reg_base;
56 int alarm_irq; 57 int alarm_irq;
57 int sec_irq; 58 int sec_irq;
59 int calibval;
58}; 60};
59 61
60static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) 62static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -62,21 +64,63 @@ static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm)
62 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 64 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
63 unsigned long new_time; 65 unsigned long new_time;
64 66
65 new_time = rtc_tm_to_time64(tm); 67 /*
68 * The value written will be updated after 1 sec into the
69 * seconds read register, so we need to program time +1 sec
70 * to get the correct time on read.
71 */
72 new_time = rtc_tm_to_time64(tm) + 1;
66 73
67 if (new_time > RTC_SEC_MAX_VAL) 74 if (new_time > RTC_SEC_MAX_VAL)
68 return -EINVAL; 75 return -EINVAL;
69 76
77 /*
78 * Writing into calibration register will clear the Tick Counter and
79 * force the next second to be signaled exactly in 1 second period
80 */
81 xrtcdev->calibval &= RTC_CALIB_MASK;
82 writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
83
70 writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); 84 writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR);
71 85
86 /*
87 * Clear the rtc interrupt status register after setting the
88 * time. During a read_time function, the code should read the
89 * RTC_INT_STATUS register and if bit 0 is still 0, it means
90 * that one second has not elapsed yet since RTC was set and
91 * the current time should be read from SET_TIME_READ register;
92 * otherwise, CURRENT_TIME register is read to report the time
93 */
94 writel(RTC_INT_SEC, xrtcdev->reg_base + RTC_INT_STS);
95
72 return 0; 96 return 0;
73} 97}
74 98
75static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) 99static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm)
76{ 100{
101 u32 status;
102 unsigned long read_time;
77 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 103 struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
78 104
79 rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm); 105 status = readl(xrtcdev->reg_base + RTC_INT_STS);
106
107 if (status & RTC_INT_SEC) {
108 /*
109 * RTC has updated the CURRENT_TIME with the time written into
110 * SET_TIME_WRITE register.
111 */
112 rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm);
113 } else {
114 /*
115 * Time written in SET_TIME_WRITE has not yet updated into
116 * the seconds read register, so read the time from the
117 * SET_TIME_WRITE instead of CURRENT_TIME register.
118 * Since we add +1 sec while writing, we need to -1 sec while
119 * reading.
120 */
121 read_time = readl(xrtcdev->reg_base + RTC_SET_TM_RD) - 1;
122 rtc_time64_to_tm(read_time, tm);
123 }
80 124
81 return rtc_valid_tm(tm); 125 return rtc_valid_tm(tm);
82} 126}
@@ -120,16 +164,23 @@ static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
120 return 0; 164 return 0;
121} 165}
122 166
123static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval) 167static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev)
124{ 168{
169 u32 rtc_ctrl;
170
171 /* Enable RTC switch to battery when VCC_PSAUX is not available */
172 rtc_ctrl = readl(xrtcdev->reg_base + RTC_CTRL);
173 rtc_ctrl |= RTC_BATT_EN;
174 writel(rtc_ctrl, xrtcdev->reg_base + RTC_CTRL);
175
125 /* 176 /*
126 * Based on crystal freq of 33.330 KHz 177 * Based on crystal freq of 33.330 KHz
127 * set the seconds counter and enable, set fractions counter 178 * set the seconds counter and enable, set fractions counter
128 * to default value suggested as per design spec 179 * to default value suggested as per design spec
129 * to correct RTC delay in frequency over period of time. 180 * to correct RTC delay in frequency over period of time.
130 */ 181 */
131 calibval &= RTC_CALIB_MASK; 182 xrtcdev->calibval &= RTC_CALIB_MASK;
132 writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); 183 writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
133} 184}
134 185
135static const struct rtc_class_ops xlnx_rtc_ops = { 186static const struct rtc_class_ops xlnx_rtc_ops = {
@@ -150,11 +201,9 @@ static irqreturn_t xlnx_rtc_interrupt(int irq, void *id)
150 if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) 201 if (!(status & (RTC_INT_SEC | RTC_INT_ALRM)))
151 return IRQ_NONE; 202 return IRQ_NONE;
152 203
153 /* Clear interrupt */ 204 /* Clear RTC_INT_ALRM interrupt only */
154 writel(status, xrtcdev->reg_base + RTC_INT_STS); 205 writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_STS);
155 206
156 if (status & RTC_INT_SEC)
157 rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF);
158 if (status & RTC_INT_ALRM) 207 if (status & RTC_INT_ALRM)
159 rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF); 208 rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF);
160 209
@@ -166,7 +215,6 @@ static int xlnx_rtc_probe(struct platform_device *pdev)
166 struct xlnx_rtc_dev *xrtcdev; 215 struct xlnx_rtc_dev *xrtcdev;
167 struct resource *res; 216 struct resource *res;
168 int ret; 217 int ret;
169 unsigned int calibvalue;
170 218
171 xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); 219 xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL);
172 if (!xrtcdev) 220 if (!xrtcdev)
@@ -207,11 +255,11 @@ static int xlnx_rtc_probe(struct platform_device *pdev)
207 } 255 }
208 256
209 ret = of_property_read_u32(pdev->dev.of_node, "calibration", 257 ret = of_property_read_u32(pdev->dev.of_node, "calibration",
210 &calibvalue); 258 &xrtcdev->calibval);
211 if (ret) 259 if (ret)
212 calibvalue = RTC_CALIB_DEF; 260 xrtcdev->calibval = RTC_CALIB_DEF;
213 261
214 xlnx_init_rtc(xrtcdev, calibvalue); 262 xlnx_init_rtc(xrtcdev);
215 263
216 device_init_wakeup(&pdev->dev, 1); 264 device_init_wakeup(&pdev->dev, 1);
217 265