aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig111
-rw-r--r--drivers/rtc/Makefile10
-rw-r--r--drivers/rtc/class.c12
-rw-r--r--drivers/rtc/interface.c6
-rw-r--r--drivers/rtc/rtc-88pm80x.c6
-rw-r--r--drivers/rtc/rtc-88pm860x.c10
-rw-r--r--drivers/rtc/rtc-ab8500.c6
-rw-r--r--drivers/rtc/rtc-at91rm9200.c17
-rw-r--r--drivers/rtc/rtc-at91sam9.c6
-rw-r--r--drivers/rtc/rtc-au1xxx.c6
-rw-r--r--drivers/rtc/rtc-bfin.c6
-rw-r--r--drivers/rtc/rtc-bq32k.c4
-rw-r--r--drivers/rtc/rtc-bq4802.c6
-rw-r--r--drivers/rtc/rtc-cmos.c24
-rw-r--r--drivers/rtc/rtc-coh901331.c7
-rw-r--r--drivers/rtc/rtc-da9052.c24
-rw-r--r--drivers/rtc/rtc-da9055.c413
-rw-r--r--drivers/rtc/rtc-davinci.c53
-rw-r--r--drivers/rtc/rtc-dev.c30
-rw-r--r--drivers/rtc/rtc-dm355evm.c6
-rw-r--r--drivers/rtc/rtc-ds1286.c6
-rw-r--r--drivers/rtc/rtc-ds1302.c4
-rw-r--r--drivers/rtc/rtc-ds1305.c14
-rw-r--r--drivers/rtc/rtc-ds1307.c19
-rw-r--r--drivers/rtc/rtc-ds1374.c4
-rw-r--r--drivers/rtc/rtc-ds1390.c6
-rw-r--r--drivers/rtc/rtc-ds1511.c8
-rw-r--r--drivers/rtc/rtc-ds1553.c6
-rw-r--r--drivers/rtc/rtc-ds1742.c6
-rw-r--r--drivers/rtc/rtc-ds2404.c18
-rw-r--r--drivers/rtc/rtc-ds3232.c8
-rw-r--r--drivers/rtc/rtc-ds3234.c6
-rw-r--r--drivers/rtc/rtc-efi.c10
-rw-r--r--drivers/rtc/rtc-ep93xx.c6
-rw-r--r--drivers/rtc/rtc-fm3130.c41
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c292
-rw-r--r--drivers/rtc/rtc-imxdi.c20
-rw-r--r--drivers/rtc/rtc-isl12022.c2
-rw-r--r--drivers/rtc/rtc-isl1208.c3
-rw-r--r--drivers/rtc/rtc-jz4740.c6
-rw-r--r--drivers/rtc/rtc-lp8788.c338
-rw-r--r--drivers/rtc/rtc-lpc32xx.c6
-rw-r--r--drivers/rtc/rtc-ls1x.c6
-rw-r--r--drivers/rtc/rtc-m41t93.c6
-rw-r--r--drivers/rtc/rtc-m41t94.c6
-rw-r--r--drivers/rtc/rtc-m48t35.c6
-rw-r--r--drivers/rtc/rtc-m48t59.c6
-rw-r--r--drivers/rtc/rtc-m48t86.c6
-rw-r--r--drivers/rtc/rtc-max6902.c6
-rw-r--r--drivers/rtc/rtc-max77686.c641
-rw-r--r--drivers/rtc/rtc-max8907.c12
-rw-r--r--drivers/rtc/rtc-max8925.c6
-rw-r--r--drivers/rtc/rtc-max8997.c552
-rw-r--r--drivers/rtc/rtc-max8998.c6
-rw-r--r--drivers/rtc/rtc-mpc5121.c13
-rw-r--r--drivers/rtc/rtc-mrst.c12
-rw-r--r--drivers/rtc/rtc-mv.c2
-rw-r--r--drivers/rtc/rtc-mxc.c6
-rw-r--r--drivers/rtc/rtc-nuc900.c6
-rw-r--r--drivers/rtc/rtc-omap.c80
-rw-r--r--drivers/rtc/rtc-pcap.c6
-rw-r--r--drivers/rtc/rtc-pcf2123.c6
-rw-r--r--drivers/rtc/rtc-pcf50633.c6
-rw-r--r--drivers/rtc/rtc-pcf8523.c357
-rw-r--r--drivers/rtc/rtc-pcf8563.c4
-rw-r--r--drivers/rtc/rtc-pcf8583.c8
-rw-r--r--drivers/rtc/rtc-pl031.c12
-rw-r--r--drivers/rtc/rtc-pm8xxx.c6
-rw-r--r--drivers/rtc/rtc-puv3.c6
-rw-r--r--drivers/rtc/rtc-pxa.c23
-rw-r--r--drivers/rtc/rtc-r9701.c6
-rw-r--r--drivers/rtc/rtc-rc5t583.c6
-rw-r--r--drivers/rtc/rtc-rs5c313.c9
-rw-r--r--drivers/rtc/rtc-rs5c348.c6
-rw-r--r--drivers/rtc/rtc-rs5c372.c10
-rw-r--r--drivers/rtc/rtc-rv3029c2.c8
-rw-r--r--drivers/rtc/rtc-rx4581.c314
-rw-r--r--drivers/rtc/rtc-rx8025.c8
-rw-r--r--drivers/rtc/rtc-rx8581.c8
-rw-r--r--drivers/rtc/rtc-s3c.c78
-rw-r--r--drivers/rtc/rtc-sa1100.c15
-rw-r--r--drivers/rtc/rtc-snvs.c16
-rw-r--r--drivers/rtc/rtc-spear.c99
-rw-r--r--drivers/rtc/rtc-stk17ta8.c6
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c3
-rw-r--r--drivers/rtc/rtc-sun4v.c10
-rw-r--r--drivers/rtc/rtc-tegra.c21
-rw-r--r--drivers/rtc/rtc-test.c18
-rw-r--r--drivers/rtc/rtc-tile.c6
-rw-r--r--drivers/rtc/rtc-tps6586x.c356
-rw-r--r--drivers/rtc/rtc-tps65910.c59
-rw-r--r--drivers/rtc/rtc-tps80031.c349
-rw-r--r--drivers/rtc/rtc-twl.c44
-rw-r--r--drivers/rtc/rtc-vr41xx.c8
-rw-r--r--drivers/rtc/rtc-vt8500.c62
-rw-r--r--drivers/rtc/rtc-wm831x.c13
-rw-r--r--drivers/rtc/rtc-wm8350.c4
-rw-r--r--drivers/rtc/systohc.c44
98 files changed, 4347 insertions, 643 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 19c03ab2bdcb..e6ab071fb6fd 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -20,14 +20,24 @@ if RTC_CLASS
20config RTC_HCTOSYS 20config RTC_HCTOSYS
21 bool "Set system time from RTC on startup and resume" 21 bool "Set system time from RTC on startup and resume"
22 default y 22 default y
23 depends on !ALWAYS_USE_PERSISTENT_CLOCK
23 help 24 help
24 If you say yes here, the system time (wall clock) will be set using 25 If you say yes here, the system time (wall clock) will be set using
25 the value read from a specified RTC device. This is useful to avoid 26 the value read from a specified RTC device. This is useful to avoid
26 unnecessary fsck runs at boot time, and to network better. 27 unnecessary fsck runs at boot time, and to network better.
27 28
29config RTC_SYSTOHC
30 bool "Set the RTC time based on NTP synchronization"
31 default y
32 depends on !ALWAYS_USE_PERSISTENT_CLOCK
33 help
34 If you say yes here, the system time (wall clock) will be stored
35 in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11
36 minutes if userspace reports synchronized NTP status.
37
28config RTC_HCTOSYS_DEVICE 38config RTC_HCTOSYS_DEVICE
29 string "RTC used to set the system time" 39 string "RTC used to set the system time"
30 depends on RTC_HCTOSYS = y 40 depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y
31 default "rtc0" 41 default "rtc0"
32 help 42 help
33 The RTC device that will be used to (re)initialize the system 43 The RTC device that will be used to (re)initialize the system
@@ -194,6 +204,12 @@ config RTC_DRV_DS3232
194 This driver can also be built as a module. If so, the module 204 This driver can also be built as a module. If so, the module
195 will be called rtc-ds3232. 205 will be called rtc-ds3232.
196 206
207config RTC_DRV_LP8788
208 tristate "TI LP8788 RTC driver"
209 depends on MFD_LP8788
210 help
211 Say Y to enable support for the LP8788 RTC/ALARM driver.
212
197config RTC_DRV_MAX6900 213config RTC_DRV_MAX6900
198 tristate "Maxim MAX6900" 214 tristate "Maxim MAX6900"
199 help 215 help
@@ -233,6 +249,26 @@ config RTC_DRV_MAX8998
233 This driver can also be built as a module. If so, the module 249 This driver can also be built as a module. If so, the module
234 will be called rtc-max8998. 250 will be called rtc-max8998.
235 251
252config RTC_DRV_MAX8997
253 tristate "Maxim MAX8997"
254 depends on MFD_MAX8997
255 help
256 If you say yes here you will get support for the
257 RTC of Maxim MAX8997 PMIC.
258
259 This driver can also be built as a module. If so, the module
260 will be called rtc-max8997.
261
262config RTC_DRV_MAX77686
263 tristate "Maxim MAX77686"
264 depends on MFD_MAX77686
265 help
266 If you say yes here you will get support for the
267 RTC of Maxim MAX77686 PMIC.
268
269 This driver can also be built as a module. If so, the module
270 will be called rtc-max77686.
271
236config RTC_DRV_RS5C372 272config RTC_DRV_RS5C372
237 tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A" 273 tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
238 help 274 help
@@ -269,6 +305,15 @@ config RTC_DRV_X1205
269 This driver can also be built as a module. If so, the module 305 This driver can also be built as a module. If so, the module
270 will be called rtc-x1205. 306 will be called rtc-x1205.
271 307
308config RTC_DRV_PCF8523
309 tristate "NXP PCF8523"
310 help
311 If you say yes here you get support for the NXP PCF8523 RTC
312 chips.
313
314 This driver can also be built as a module. If so, the module
315 will be called rtc-pcf8523.
316
272config RTC_DRV_PCF8563 317config RTC_DRV_PCF8563
273 tristate "Philips PCF8563/Epson RTC8564" 318 tristate "Philips PCF8563/Epson RTC8564"
274 help 319 help
@@ -343,6 +388,14 @@ config RTC_DRV_TWL4030
343 This driver can also be built as a module. If so, the module 388 This driver can also be built as a module. If so, the module
344 will be called rtc-twl. 389 will be called rtc-twl.
345 390
391config RTC_DRV_TPS6586X
392 tristate "TI TPS6586X RTC driver"
393 depends on MFD_TPS6586X
394 help
395 TI Power Managment IC TPS6586X supports RTC functionality
396 along with alarm. This driver supports the RTC driver for
397 the TPS6586X RTC module.
398
346config RTC_DRV_TPS65910 399config RTC_DRV_TPS65910
347 tristate "TI TPS65910 RTC driver" 400 tristate "TI TPS65910 RTC driver"
348 depends on RTC_CLASS && MFD_TPS65910 401 depends on RTC_CLASS && MFD_TPS65910
@@ -353,6 +406,14 @@ config RTC_DRV_TPS65910
353 This driver can also be built as a module. If so, the module 406 This driver can also be built as a module. If so, the module
354 will be called rtc-tps65910. 407 will be called rtc-tps65910.
355 408
409config RTC_DRV_TPS80031
410 tristate "TI TPS80031/TPS80032 RTC driver"
411 depends on MFD_TPS80031
412 help
413 TI Power Managment IC TPS80031 supports RTC functionality
414 along with alarm. This driver supports the RTC driver for
415 the TPS80031 RTC module.
416
356config RTC_DRV_RC5T583 417config RTC_DRV_RC5T583
357 tristate "RICOH 5T583 RTC driver" 418 tristate "RICOH 5T583 RTC driver"
358 depends on MFD_RC5T583 419 depends on MFD_RC5T583
@@ -510,6 +571,14 @@ config RTC_DRV_PCF2123
510 This driver can also be built as a module. If so, the module 571 This driver can also be built as a module. If so, the module
511 will be called rtc-pcf2123. 572 will be called rtc-pcf2123.
512 573
574config RTC_DRV_RX4581
575 tristate "Epson RX-4581"
576 help
577 If you say yes here you will get support for the Epson RX-4581.
578
579 This driver can also be built as a module. If so the module
580 will be called rtc-rx4581.
581
513endif # SPI_MASTER 582endif # SPI_MASTER
514 583
515comment "Platform RTC drivers" 584comment "Platform RTC drivers"
@@ -600,6 +669,16 @@ config RTC_DRV_DA9052
600 Say y here to support the RTC driver for Dialog Semiconductor 669 Say y here to support the RTC driver for Dialog Semiconductor
601 DA9052-BC and DA9053-AA/Bx PMICs. 670 DA9052-BC and DA9053-AA/Bx PMICs.
602 671
672config RTC_DRV_DA9055
673 tristate "Dialog Semiconductor DA9055 RTC"
674 depends on MFD_DA9055
675 help
676 If you say yes here you will get support for the
677 RTC of the Dialog DA9055 PMIC.
678
679 This driver can also be built as a module. If so, the module
680 will be called rtc-da9055
681
603config RTC_DRV_EFI 682config RTC_DRV_EFI
604 tristate "EFI RTC" 683 tristate "EFI RTC"
605 depends on IA64 684 depends on IA64
@@ -768,7 +847,7 @@ config RTC_DRV_DAVINCI
768 847
769config RTC_DRV_IMXDI 848config RTC_DRV_IMXDI
770 tristate "Freescale IMX DryIce Real Time Clock" 849 tristate "Freescale IMX DryIce Real Time Clock"
771 depends on SOC_IMX25 850 depends on ARCH_MXC
772 help 851 help
773 Support for Freescale IMX DryIce RTC 852 Support for Freescale IMX DryIce RTC
774 853
@@ -777,11 +856,13 @@ config RTC_DRV_IMXDI
777 856
778config RTC_DRV_OMAP 857config RTC_DRV_OMAP
779 tristate "TI OMAP1" 858 tristate "TI OMAP1"
780 depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX 859 depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX || SOC_AM33XX
781 help 860 help
782 Say "yes" here to support the real time clock on TI OMAP1 and 861 Say "yes" here to support the on chip real time clock
783 DA8xx/OMAP-L13x chips. This driver can also be built as a 862 present on TI OMAP1, AM33xx and DA8xx/OMAP-L13x.
784 module called rtc-omap. 863
864 This driver can also be built as a module, if so, module
865 will be called rtc-omap.
785 866
786config HAVE_S3C_RTC 867config HAVE_S3C_RTC
787 bool 868 bool
@@ -994,7 +1075,7 @@ config RTC_DRV_TX4939
994 1075
995config RTC_DRV_MV 1076config RTC_DRV_MV
996 tristate "Marvell SoC RTC" 1077 tristate "Marvell SoC RTC"
997 depends on ARCH_KIRKWOOD || ARCH_DOVE 1078 depends on ARCH_KIRKWOOD || ARCH_DOVE || ARCH_MVEBU
998 help 1079 help
999 If you say yes here you will get support for the in-chip RTC 1080 If you say yes here you will get support for the in-chip RTC
1000 that can be found in some of Marvell's SoC devices, such as 1081 that can be found in some of Marvell's SoC devices, such as
@@ -1144,4 +1225,20 @@ config RTC_DRV_SNVS
1144 This driver can also be built as a module, if so, the module 1225 This driver can also be built as a module, if so, the module
1145 will be called "rtc-snvs". 1226 will be called "rtc-snvs".
1146 1227
1228comment "HID Sensor RTC drivers"
1229
1230config RTC_DRV_HID_SENSOR_TIME
1231 tristate "HID Sensor Time"
1232 depends on USB_HID
1233 select IIO
1234 select HID_SENSOR_HUB
1235 select HID_SENSOR_IIO_COMMON
1236 help
1237 Say yes here to build support for the HID Sensors of type Time.
1238 This drivers makes such sensors available as RTCs.
1239
1240 If this driver is compiled as a module, it will be named
1241 rtc-hid-sensor-time.
1242
1243
1147endif # RTC_CLASS 1244endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 56297f0fd388..e8f2e2fee06f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -6,6 +6,7 @@ ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_RTC_LIB) += rtc-lib.o 7obj-$(CONFIG_RTC_LIB) += rtc-lib.o
8obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 8obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
9obj-$(CONFIG_RTC_SYSTOHC) += systohc.o
9obj-$(CONFIG_RTC_CLASS) += rtc-core.o 10obj-$(CONFIG_RTC_CLASS) += rtc-core.o
10rtc-core-y := class.o interface.o 11rtc-core-y := class.o interface.o
11 12
@@ -29,6 +30,7 @@ obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o
29obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 30obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
30obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o 31obj-$(CONFIG_RTC_DRV_COH901331) += rtc-coh901331.o
31obj-$(CONFIG_RTC_DRV_DA9052) += rtc-da9052.o 32obj-$(CONFIG_RTC_DRV_DA9052) += rtc-da9052.o
33obj-$(CONFIG_RTC_DRV_DA9055) += rtc-da9055.o
32obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o 34obj-$(CONFIG_RTC_DRV_DAVINCI) += rtc-davinci.o
33obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o 35obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o
34obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o 36obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o
@@ -51,10 +53,12 @@ obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o
51obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 53obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
52obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 54obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
53obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 55obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
56obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
54obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o 57obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
55obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 58obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
56obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o 59obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
57obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 60obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
61obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o
58obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o 62obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o
59obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o 63obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o
60obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 64obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
@@ -68,7 +72,9 @@ obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
68obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o 72obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o
69obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o 73obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o
70obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o 74obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o
75obj-$(CONFIG_RTC_DRV_MAX8997) += rtc-max8997.o
71obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 76obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
77obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o
72obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o 78obj-$(CONFIG_RTC_DRV_MC13XXX) += rtc-mc13xxx.o
73obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 79obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o
74obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o 80obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o
@@ -76,6 +82,7 @@ obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o
76obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o 82obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o
77obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 83obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
78obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o 84obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o
85obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o
79obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 86obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
80obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 87obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
81obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o 88obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o
@@ -93,6 +100,7 @@ obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
93obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o 100obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
94obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o 101obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
95obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o 102obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o
103obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o
96obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o 104obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o
97obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o 105obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
98obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o 106obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
@@ -109,7 +117,9 @@ obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o
109obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 117obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
110obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o 118obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o
111obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o 119obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o
120obj-$(CONFIG_RTC_DRV_TPS6586X) += rtc-tps6586x.o
112obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o 121obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o
122obj-$(CONFIG_RTC_DRV_TPS80031) += rtc-tps80031.o
113obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 123obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o
114obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 124obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
115obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 125obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index f8a0aab218cb..9b742d3ffb94 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -11,6 +11,8 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12*/ 12*/
13 13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/rtc.h> 17#include <linux/rtc.h>
16#include <linux/kdev_t.h> 18#include <linux/kdev_t.h>
@@ -50,6 +52,10 @@ static int rtc_suspend(struct device *dev, pm_message_t mesg)
50 struct rtc_device *rtc = to_rtc_device(dev); 52 struct rtc_device *rtc = to_rtc_device(dev);
51 struct rtc_time tm; 53 struct rtc_time tm;
52 struct timespec delta, delta_delta; 54 struct timespec delta, delta_delta;
55
56 if (has_persistent_clock())
57 return 0;
58
53 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 59 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
54 return 0; 60 return 0;
55 61
@@ -88,6 +94,9 @@ static int rtc_resume(struct device *dev)
88 struct timespec new_system, new_rtc; 94 struct timespec new_system, new_rtc;
89 struct timespec sleep_time; 95 struct timespec sleep_time;
90 96
97 if (has_persistent_clock())
98 return 0;
99
91 rtc_hctosys_ret = -ENODEV; 100 rtc_hctosys_ret = -ENODEV;
92 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 101 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
93 return 0; 102 return 0;
@@ -244,7 +253,6 @@ void rtc_device_unregister(struct rtc_device *rtc)
244 rtc_proc_del_device(rtc); 253 rtc_proc_del_device(rtc);
245 device_unregister(&rtc->dev); 254 device_unregister(&rtc->dev);
246 rtc->ops = NULL; 255 rtc->ops = NULL;
247 ida_simple_remove(&rtc_ida, rtc->id);
248 mutex_unlock(&rtc->ops_lock); 256 mutex_unlock(&rtc->ops_lock);
249 put_device(&rtc->dev); 257 put_device(&rtc->dev);
250 } 258 }
@@ -255,7 +263,7 @@ static int __init rtc_init(void)
255{ 263{
256 rtc_class = class_create(THIS_MODULE, "rtc"); 264 rtc_class = class_create(THIS_MODULE, "rtc");
257 if (IS_ERR(rtc_class)) { 265 if (IS_ERR(rtc_class)) {
258 printk(KERN_ERR "%s: couldn't create class\n", __FILE__); 266 pr_err("couldn't create class\n");
259 return PTR_ERR(rtc_class); 267 return PTR_ERR(rtc_class);
260 } 268 }
261 rtc_class->suspend = rtc_suspend; 269 rtc_class->suspend = rtc_suspend;
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 9592b936b71b..42bd57da239d 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -587,16 +587,16 @@ void rtc_update_irq(struct rtc_device *rtc,
587} 587}
588EXPORT_SYMBOL_GPL(rtc_update_irq); 588EXPORT_SYMBOL_GPL(rtc_update_irq);
589 589
590static int __rtc_match(struct device *dev, void *data) 590static int __rtc_match(struct device *dev, const void *data)
591{ 591{
592 char *name = (char *)data; 592 const char *name = data;
593 593
594 if (strcmp(dev_name(dev), name) == 0) 594 if (strcmp(dev_name(dev), name) == 0)
595 return 1; 595 return 1;
596 return 0; 596 return 0;
597} 597}
598 598
599struct rtc_device *rtc_class_open(char *name) 599struct rtc_device *rtc_class_open(const char *name)
600{ 600{
601 struct device *dev; 601 struct device *dev;
602 struct rtc_device *rtc = NULL; 602 struct rtc_device *rtc = NULL;
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 6367984e0565..63b17ebe90e8 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -248,7 +248,7 @@ static int pm80x_rtc_resume(struct device *dev)
248 248
249static SIMPLE_DEV_PM_OPS(pm80x_rtc_pm_ops, pm80x_rtc_suspend, pm80x_rtc_resume); 249static SIMPLE_DEV_PM_OPS(pm80x_rtc_pm_ops, pm80x_rtc_suspend, pm80x_rtc_resume);
250 250
251static int __devinit pm80x_rtc_probe(struct platform_device *pdev) 251static int pm80x_rtc_probe(struct platform_device *pdev)
252{ 252{
253 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); 253 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
254 struct pm80x_platform_data *pm80x_pdata; 254 struct pm80x_platform_data *pm80x_pdata;
@@ -342,7 +342,7 @@ out:
342 return ret; 342 return ret;
343} 343}
344 344
345static int __devexit pm80x_rtc_remove(struct platform_device *pdev) 345static int pm80x_rtc_remove(struct platform_device *pdev)
346{ 346{
347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev); 347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev);
348 platform_set_drvdata(pdev, NULL); 348 platform_set_drvdata(pdev, NULL);
@@ -358,7 +358,7 @@ static struct platform_driver pm80x_rtc_driver = {
358 .pm = &pm80x_rtc_pm_ops, 358 .pm = &pm80x_rtc_pm_ops,
359 }, 359 },
360 .probe = pm80x_rtc_probe, 360 .probe = pm80x_rtc_probe,
361 .remove = __devexit_p(pm80x_rtc_remove), 361 .remove = pm80x_rtc_remove,
362}; 362};
363 363
364module_platform_driver(pm80x_rtc_driver); 364module_platform_driver(pm80x_rtc_driver);
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index de9e854b326a..f663746f4603 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -286,8 +286,8 @@ out:
286#endif 286#endif
287 287
288#ifdef CONFIG_OF 288#ifdef CONFIG_OF
289static int __devinit pm860x_rtc_dt_init(struct platform_device *pdev, 289static int pm860x_rtc_dt_init(struct platform_device *pdev,
290 struct pm860x_rtc_info *info) 290 struct pm860x_rtc_info *info)
291{ 291{
292 struct device_node *np = pdev->dev.parent->of_node; 292 struct device_node *np = pdev->dev.parent->of_node;
293 int ret; 293 int ret;
@@ -307,7 +307,7 @@ static int __devinit pm860x_rtc_dt_init(struct platform_device *pdev,
307#define pm860x_rtc_dt_init(x, y) (-1) 307#define pm860x_rtc_dt_init(x, y) (-1)
308#endif 308#endif
309 309
310static int __devinit pm860x_rtc_probe(struct platform_device *pdev) 310static int pm860x_rtc_probe(struct platform_device *pdev)
311{ 311{
312 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 312 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
313 struct pm860x_rtc_pdata *pdata = NULL; 313 struct pm860x_rtc_pdata *pdata = NULL;
@@ -412,7 +412,7 @@ out:
412 return ret; 412 return ret;
413} 413}
414 414
415static int __devexit pm860x_rtc_remove(struct platform_device *pdev) 415static int pm860x_rtc_remove(struct platform_device *pdev)
416{ 416{
417 struct pm860x_rtc_info *info = platform_get_drvdata(pdev); 417 struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
418 418
@@ -459,7 +459,7 @@ static struct platform_driver pm860x_rtc_driver = {
459 .pm = &pm860x_rtc_pm_ops, 459 .pm = &pm860x_rtc_pm_ops,
460 }, 460 },
461 .probe = pm860x_rtc_probe, 461 .probe = pm860x_rtc_probe,
462 .remove = __devexit_p(pm860x_rtc_remove), 462 .remove = pm860x_rtc_remove,
463}; 463};
464 464
465module_platform_driver(pm860x_rtc_driver); 465module_platform_driver(pm860x_rtc_driver);
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 2e5970fe9eeb..57cde2b061e6 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -389,7 +389,7 @@ static const struct rtc_class_ops ab8500_rtc_ops = {
389 .alarm_irq_enable = ab8500_rtc_irq_enable, 389 .alarm_irq_enable = ab8500_rtc_irq_enable,
390}; 390};
391 391
392static int __devinit ab8500_rtc_probe(struct platform_device *pdev) 392static int ab8500_rtc_probe(struct platform_device *pdev)
393{ 393{
394 int err; 394 int err;
395 struct rtc_device *rtc; 395 struct rtc_device *rtc;
@@ -448,7 +448,7 @@ static int __devinit ab8500_rtc_probe(struct platform_device *pdev)
448 return 0; 448 return 0;
449} 449}
450 450
451static int __devexit ab8500_rtc_remove(struct platform_device *pdev) 451static int ab8500_rtc_remove(struct platform_device *pdev)
452{ 452{
453 struct rtc_device *rtc = platform_get_drvdata(pdev); 453 struct rtc_device *rtc = platform_get_drvdata(pdev);
454 int irq = platform_get_irq_byname(pdev, "ALARM"); 454 int irq = platform_get_irq_byname(pdev, "ALARM");
@@ -468,7 +468,7 @@ static struct platform_driver ab8500_rtc_driver = {
468 .owner = THIS_MODULE, 468 .owner = THIS_MODULE,
469 }, 469 },
470 .probe = ab8500_rtc_probe, 470 .probe = ab8500_rtc_probe,
471 .remove = __devexit_p(ab8500_rtc_remove), 471 .remove = ab8500_rtc_remove,
472}; 472};
473 473
474module_platform_driver(ab8500_rtc_driver); 474module_platform_driver(ab8500_rtc_driver);
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index b6469e2cae89..434ebc3a99dc 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -86,7 +86,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
86 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 86 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
87 tm->tm_year = tm->tm_year - 1900; 87 tm->tm_year = tm->tm_year - 1900;
88 88
89 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 89 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
90 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 90 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
91 tm->tm_hour, tm->tm_min, tm->tm_sec); 91 tm->tm_hour, tm->tm_min, tm->tm_sec);
92 92
@@ -100,7 +100,7 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
100{ 100{
101 unsigned long cr; 101 unsigned long cr;
102 102
103 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 103 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
104 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 104 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
105 tm->tm_hour, tm->tm_min, tm->tm_sec); 105 tm->tm_hour, tm->tm_min, tm->tm_sec);
106 106
@@ -145,7 +145,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
145 alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 145 alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
146 ? 1 : 0; 146 ? 1 : 0;
147 147
148 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 148 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
149 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 149 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
150 tm->tm_hour, tm->tm_min, tm->tm_sec); 150 tm->tm_hour, tm->tm_min, tm->tm_sec);
151 151
@@ -183,7 +183,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
183 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 183 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
184 } 184 }
185 185
186 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 186 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
187 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, 187 at91_alarm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
188 tm.tm_min, tm.tm_sec); 188 tm.tm_min, tm.tm_sec);
189 189
@@ -192,7 +192,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
192 192
193static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 193static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
194{ 194{
195 pr_debug("%s(): cmd=%08x\n", __func__, enabled); 195 dev_dbg(dev, "%s(): cmd=%08x\n", __func__, enabled);
196 196
197 if (enabled) { 197 if (enabled) {
198 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 198 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
@@ -240,7 +240,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
240 240
241 rtc_update_irq(rtc, 1, events); 241 rtc_update_irq(rtc, 1, events);
242 242
243 pr_debug("%s(): num=%ld, events=0x%02lx\n", __func__, 243 dev_dbg(&pdev->dev, "%s(): num=%ld, events=0x%02lx\n", __func__,
244 events >> 8, events & 0x000000FF); 244 events >> 8, events & 0x000000FF);
245 245
246 return IRQ_HANDLED; 246 return IRQ_HANDLED;
@@ -296,8 +296,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
296 IRQF_SHARED, 296 IRQF_SHARED,
297 "at91_rtc", pdev); 297 "at91_rtc", pdev);
298 if (ret) { 298 if (ret) {
299 printk(KERN_ERR "at91_rtc: IRQ %d already in use.\n", 299 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq);
300 irq);
301 return ret; 300 return ret;
302 } 301 }
303 302
@@ -315,7 +314,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
315 } 314 }
316 platform_set_drvdata(pdev, rtc); 315 platform_set_drvdata(pdev, rtc);
317 316
318 printk(KERN_INFO "AT91 Real Time Clock driver.\n"); 317 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n");
319 return 0; 318 return 0;
320} 319}
321 320
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index e981798e9a9b..39cfd2ee0042 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -289,7 +289,7 @@ static const struct rtc_class_ops at91_rtc_ops = {
289/* 289/*
290 * Initialize and install RTC driver 290 * Initialize and install RTC driver
291 */ 291 */
292static int __devinit at91_rtc_probe(struct platform_device *pdev) 292static int at91_rtc_probe(struct platform_device *pdev)
293{ 293{
294 struct resource *r, *r_gpbr; 294 struct resource *r, *r_gpbr;
295 struct sam9_rtc *rtc; 295 struct sam9_rtc *rtc;
@@ -387,7 +387,7 @@ fail:
387/* 387/*
388 * Disable and remove the RTC driver 388 * Disable and remove the RTC driver
389 */ 389 */
390static int __devexit at91_rtc_remove(struct platform_device *pdev) 390static int at91_rtc_remove(struct platform_device *pdev)
391{ 391{
392 struct sam9_rtc *rtc = platform_get_drvdata(pdev); 392 struct sam9_rtc *rtc = platform_get_drvdata(pdev);
393 u32 mr = rtt_readl(rtc, MR); 393 u32 mr = rtt_readl(rtc, MR);
@@ -463,7 +463,7 @@ static int at91_rtc_resume(struct platform_device *pdev)
463 463
464static struct platform_driver at91_rtc_driver = { 464static struct platform_driver at91_rtc_driver = {
465 .probe = at91_rtc_probe, 465 .probe = at91_rtc_probe,
466 .remove = __devexit_p(at91_rtc_remove), 466 .remove = at91_rtc_remove,
467 .shutdown = at91_rtc_shutdown, 467 .shutdown = at91_rtc_shutdown,
468 .suspend = at91_rtc_suspend, 468 .suspend = at91_rtc_suspend,
469 .resume = at91_rtc_resume, 469 .resume = at91_rtc_resume,
diff --git a/drivers/rtc/rtc-au1xxx.c b/drivers/rtc/rtc-au1xxx.c
index 979ed0406ce9..b309da4ec745 100644
--- a/drivers/rtc/rtc-au1xxx.c
+++ b/drivers/rtc/rtc-au1xxx.c
@@ -62,7 +62,7 @@ static struct rtc_class_ops au1xtoy_rtc_ops = {
62 .set_time = au1xtoy_rtc_set_time, 62 .set_time = au1xtoy_rtc_set_time,
63}; 63};
64 64
65static int __devinit au1xtoy_rtc_probe(struct platform_device *pdev) 65static int au1xtoy_rtc_probe(struct platform_device *pdev)
66{ 66{
67 struct rtc_device *rtcdev; 67 struct rtc_device *rtcdev;
68 unsigned long t; 68 unsigned long t;
@@ -116,7 +116,7 @@ out_err:
116 return ret; 116 return ret;
117} 117}
118 118
119static int __devexit au1xtoy_rtc_remove(struct platform_device *pdev) 119static int au1xtoy_rtc_remove(struct platform_device *pdev)
120{ 120{
121 struct rtc_device *rtcdev = platform_get_drvdata(pdev); 121 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
122 122
@@ -131,7 +131,7 @@ static struct platform_driver au1xrtc_driver = {
131 .name = "rtc-au1xxx", 131 .name = "rtc-au1xxx",
132 .owner = THIS_MODULE, 132 .owner = THIS_MODULE,
133 }, 133 },
134 .remove = __devexit_p(au1xtoy_rtc_remove), 134 .remove = au1xtoy_rtc_remove,
135}; 135};
136 136
137static int __init au1xtoy_rtc_init(void) 137static int __init au1xtoy_rtc_init(void)
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index abfc1a0c07d9..4ec614b0954d 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -342,7 +342,7 @@ static struct rtc_class_ops bfin_rtc_ops = {
342 .alarm_irq_enable = bfin_rtc_alarm_irq_enable, 342 .alarm_irq_enable = bfin_rtc_alarm_irq_enable,
343}; 343};
344 344
345static int __devinit bfin_rtc_probe(struct platform_device *pdev) 345static int bfin_rtc_probe(struct platform_device *pdev)
346{ 346{
347 struct bfin_rtc *rtc; 347 struct bfin_rtc *rtc;
348 struct device *dev = &pdev->dev; 348 struct device *dev = &pdev->dev;
@@ -388,7 +388,7 @@ err:
388 return ret; 388 return ret;
389} 389}
390 390
391static int __devexit bfin_rtc_remove(struct platform_device *pdev) 391static int bfin_rtc_remove(struct platform_device *pdev)
392{ 392{
393 struct bfin_rtc *rtc = platform_get_drvdata(pdev); 393 struct bfin_rtc *rtc = platform_get_drvdata(pdev);
394 struct device *dev = &pdev->dev; 394 struct device *dev = &pdev->dev;
@@ -451,7 +451,7 @@ static struct platform_driver bfin_rtc_driver = {
451 .owner = THIS_MODULE, 451 .owner = THIS_MODULE,
452 }, 452 },
453 .probe = bfin_rtc_probe, 453 .probe = bfin_rtc_probe,
454 .remove = __devexit_p(bfin_rtc_remove), 454 .remove = bfin_rtc_remove,
455 .suspend = bfin_rtc_suspend, 455 .suspend = bfin_rtc_suspend,
456 .resume = bfin_rtc_resume, 456 .resume = bfin_rtc_resume,
457}; 457};
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index f090159dce4a..036cb89f8188 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -163,7 +163,7 @@ static int bq32k_probe(struct i2c_client *client,
163 return 0; 163 return 0;
164} 164}
165 165
166static int __devexit bq32k_remove(struct i2c_client *client) 166static int bq32k_remove(struct i2c_client *client)
167{ 167{
168 struct rtc_device *rtc = i2c_get_clientdata(client); 168 struct rtc_device *rtc = i2c_get_clientdata(client);
169 169
@@ -183,7 +183,7 @@ static struct i2c_driver bq32k_driver = {
183 .owner = THIS_MODULE, 183 .owner = THIS_MODULE,
184 }, 184 },
185 .probe = bq32k_probe, 185 .probe = bq32k_probe,
186 .remove = __devexit_p(bq32k_remove), 186 .remove = bq32k_remove,
187 .id_table = bq32k_id, 187 .id_table = bq32k_id,
188}; 188};
189 189
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index bf612ef22941..693be71b5b18 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -140,7 +140,7 @@ static const struct rtc_class_ops bq4802_ops = {
140 .set_time = bq4802_set_time, 140 .set_time = bq4802_set_time,
141}; 141};
142 142
143static int __devinit bq4802_probe(struct platform_device *pdev) 143static int bq4802_probe(struct platform_device *pdev)
144{ 144{
145 struct bq4802 *p = kzalloc(sizeof(*p), GFP_KERNEL); 145 struct bq4802 *p = kzalloc(sizeof(*p), GFP_KERNEL);
146 int err = -ENOMEM; 146 int err = -ENOMEM;
@@ -191,7 +191,7 @@ out_free:
191 goto out; 191 goto out;
192} 192}
193 193
194static int __devexit bq4802_remove(struct platform_device *pdev) 194static int bq4802_remove(struct platform_device *pdev)
195{ 195{
196 struct bq4802 *p = platform_get_drvdata(pdev); 196 struct bq4802 *p = platform_get_drvdata(pdev);
197 197
@@ -215,7 +215,7 @@ static struct platform_driver bq4802_driver = {
215 .owner = THIS_MODULE, 215 .owner = THIS_MODULE,
216 }, 216 },
217 .probe = bq4802_probe, 217 .probe = bq4802_probe,
218 .remove = __devexit_p(bq4802_remove), 218 .remove = bq4802_remove,
219}; 219};
220 220
221module_platform_driver(bq4802_driver); 221module_platform_driver(bq4802_driver);
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 4267789ca995..af97c94e8a3a 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -706,7 +706,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
706 rtc_cmos_int_handler = hpet_rtc_interrupt; 706 rtc_cmos_int_handler = hpet_rtc_interrupt;
707 err = hpet_register_irq_handler(cmos_interrupt); 707 err = hpet_register_irq_handler(cmos_interrupt);
708 if (err != 0) { 708 if (err != 0) {
709 printk(KERN_WARNING "hpet_register_irq_handler " 709 dev_warn(dev, "hpet_register_irq_handler "
710 " failed in rtc_init()."); 710 " failed in rtc_init().");
711 goto cleanup1; 711 goto cleanup1;
712 } 712 }
@@ -731,8 +731,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
731 goto cleanup2; 731 goto cleanup2;
732 } 732 }
733 733
734 pr_info("%s: %s%s, %zd bytes nvram%s\n", 734 dev_info(dev, "%s%s, %zd bytes nvram%s\n",
735 dev_name(&cmos_rtc.rtc->dev),
736 !is_valid_irq(rtc_irq) ? "no alarms" : 735 !is_valid_irq(rtc_irq) ? "no alarms" :
737 cmos_rtc.mon_alrm ? "alarms up to one year" : 736 cmos_rtc.mon_alrm ? "alarms up to one year" :
738 cmos_rtc.day_alrm ? "alarms up to one month" : 737 cmos_rtc.day_alrm ? "alarms up to one month" :
@@ -820,8 +819,7 @@ static int cmos_suspend(struct device *dev)
820 enable_irq_wake(cmos->irq); 819 enable_irq_wake(cmos->irq);
821 } 820 }
822 821
823 pr_debug("%s: suspend%s, ctrl %02x\n", 822 dev_dbg(dev, "suspend%s, ctrl %02x\n",
824 dev_name(&cmos_rtc.rtc->dev),
825 (tmp & RTC_AIE) ? ", alarm may wake" : "", 823 (tmp & RTC_AIE) ? ", alarm may wake" : "",
826 tmp); 824 tmp);
827 825
@@ -876,9 +874,7 @@ static int cmos_resume(struct device *dev)
876 spin_unlock_irq(&rtc_lock); 874 spin_unlock_irq(&rtc_lock);
877 } 875 }
878 876
879 pr_debug("%s: resume, ctrl %02x\n", 877 dev_dbg(dev, "resume, ctrl %02x\n", tmp);
880 dev_name(&cmos_rtc.rtc->dev),
881 tmp);
882 878
883 return 0; 879 return 0;
884} 880}
@@ -947,8 +943,7 @@ static void rtc_wake_off(struct device *dev)
947 */ 943 */
948static struct cmos_rtc_board_info acpi_rtc_info; 944static struct cmos_rtc_board_info acpi_rtc_info;
949 945
950static void __devinit 946static void cmos_wake_setup(struct device *dev)
951cmos_wake_setup(struct device *dev)
952{ 947{
953 if (acpi_disabled) 948 if (acpi_disabled)
954 return; 949 return;
@@ -980,8 +975,7 @@ cmos_wake_setup(struct device *dev)
980 975
981#else 976#else
982 977
983static void __devinit 978static void cmos_wake_setup(struct device *dev)
984cmos_wake_setup(struct device *dev)
985{ 979{
986} 980}
987 981
@@ -991,8 +985,7 @@ cmos_wake_setup(struct device *dev)
991 985
992#include <linux/pnp.h> 986#include <linux/pnp.h>
993 987
994static int __devinit 988static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
995cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
996{ 989{
997 cmos_wake_setup(&pnp->dev); 990 cmos_wake_setup(&pnp->dev);
998 991
@@ -1101,7 +1094,6 @@ static __init void cmos_of_init(struct platform_device *pdev)
1101} 1094}
1102#else 1095#else
1103static inline void cmos_of_init(struct platform_device *pdev) {} 1096static inline void cmos_of_init(struct platform_device *pdev) {}
1104#define of_cmos_match NULL
1105#endif 1097#endif
1106/*----------------------------------------------------------------*/ 1098/*----------------------------------------------------------------*/
1107 1099
@@ -1143,7 +1135,7 @@ static struct platform_driver cmos_platform_driver = {
1143#ifdef CONFIG_PM 1135#ifdef CONFIG_PM
1144 .pm = &cmos_pm_ops, 1136 .pm = &cmos_pm_ops,
1145#endif 1137#endif
1146 .of_match_table = of_cmos_match, 1138 .of_match_table = of_match_ptr(of_cmos_match),
1147 } 1139 }
1148}; 1140};
1149 1141
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index c8115b83e5ab..2d28ec1aa1cd 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -157,7 +157,6 @@ static int __exit coh901331_remove(struct platform_device *pdev)
157 if (rtap) { 157 if (rtap) {
158 rtc_device_unregister(rtap->rtc); 158 rtc_device_unregister(rtap->rtc);
159 clk_unprepare(rtap->clk); 159 clk_unprepare(rtap->clk);
160 clk_put(rtap->clk);
161 platform_set_drvdata(pdev, NULL); 160 platform_set_drvdata(pdev, NULL);
162 } 161 }
163 162
@@ -196,7 +195,7 @@ static int __init coh901331_probe(struct platform_device *pdev)
196 "RTC COH 901 331 Alarm", rtap)) 195 "RTC COH 901 331 Alarm", rtap))
197 return -EIO; 196 return -EIO;
198 197
199 rtap->clk = clk_get(&pdev->dev, NULL); 198 rtap->clk = devm_clk_get(&pdev->dev, NULL);
200 if (IS_ERR(rtap->clk)) { 199 if (IS_ERR(rtap->clk)) {
201 ret = PTR_ERR(rtap->clk); 200 ret = PTR_ERR(rtap->clk);
202 dev_err(&pdev->dev, "could not get clock\n"); 201 dev_err(&pdev->dev, "could not get clock\n");
@@ -207,7 +206,7 @@ static int __init coh901331_probe(struct platform_device *pdev)
207 ret = clk_prepare_enable(rtap->clk); 206 ret = clk_prepare_enable(rtap->clk);
208 if (ret) { 207 if (ret) {
209 dev_err(&pdev->dev, "could not enable clock\n"); 208 dev_err(&pdev->dev, "could not enable clock\n");
210 goto out_no_clk_prepenable; 209 return ret;
211 } 210 }
212 clk_disable(rtap->clk); 211 clk_disable(rtap->clk);
213 212
@@ -224,8 +223,6 @@ static int __init coh901331_probe(struct platform_device *pdev)
224 out_no_rtc: 223 out_no_rtc:
225 platform_set_drvdata(pdev, NULL); 224 platform_set_drvdata(pdev, NULL);
226 clk_unprepare(rtap->clk); 225 clk_unprepare(rtap->clk);
227 out_no_clk_prepenable:
228 clk_put(rtap->clk);
229 return ret; 226 return ret;
230} 227}
231 228
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 78070255bd3f..0dde688ca09b 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -228,7 +228,7 @@ static const struct rtc_class_ops da9052_rtc_ops = {
228 .alarm_irq_enable = da9052_rtc_alarm_irq_enable, 228 .alarm_irq_enable = da9052_rtc_alarm_irq_enable,
229}; 229};
230 230
231static int __devinit da9052_rtc_probe(struct platform_device *pdev) 231static int da9052_rtc_probe(struct platform_device *pdev)
232{ 232{
233 struct da9052_rtc *rtc; 233 struct da9052_rtc *rtc;
234 int ret; 234 int ret;
@@ -240,9 +240,10 @@ static int __devinit da9052_rtc_probe(struct platform_device *pdev)
240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent); 240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent);
241 platform_set_drvdata(pdev, rtc); 241 platform_set_drvdata(pdev, rtc);
242 rtc->irq = platform_get_irq_byname(pdev, "ALM"); 242 rtc->irq = platform_get_irq_byname(pdev, "ALM");
243 ret = request_threaded_irq(rtc->irq, NULL, da9052_rtc_irq, 243 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
244 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 244 da9052_rtc_irq,
245 "ALM", rtc); 245 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
246 "ALM", rtc);
246 if (ret != 0) { 247 if (ret != 0) {
247 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret); 248 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret);
248 return ret; 249 return ret;
@@ -250,24 +251,17 @@ static int __devinit da9052_rtc_probe(struct platform_device *pdev)
250 251
251 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 252 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
252 &da9052_rtc_ops, THIS_MODULE); 253 &da9052_rtc_ops, THIS_MODULE);
253 if (IS_ERR(rtc->rtc)) { 254 if (IS_ERR(rtc->rtc))
254 ret = PTR_ERR(rtc->rtc); 255 return PTR_ERR(rtc->rtc);
255 goto err_free_irq;
256 }
257 256
258 return 0; 257 return 0;
259
260err_free_irq:
261 free_irq(rtc->irq, rtc);
262 return ret;
263} 258}
264 259
265static int __devexit da9052_rtc_remove(struct platform_device *pdev) 260static int da9052_rtc_remove(struct platform_device *pdev)
266{ 261{
267 struct da9052_rtc *rtc = pdev->dev.platform_data; 262 struct da9052_rtc *rtc = pdev->dev.platform_data;
268 263
269 rtc_device_unregister(rtc->rtc); 264 rtc_device_unregister(rtc->rtc);
270 free_irq(rtc->irq, rtc);
271 platform_set_drvdata(pdev, NULL); 265 platform_set_drvdata(pdev, NULL);
272 266
273 return 0; 267 return 0;
@@ -275,7 +269,7 @@ static int __devexit da9052_rtc_remove(struct platform_device *pdev)
275 269
276static struct platform_driver da9052_rtc_driver = { 270static struct platform_driver da9052_rtc_driver = {
277 .probe = da9052_rtc_probe, 271 .probe = da9052_rtc_probe,
278 .remove = __devexit_p(da9052_rtc_remove), 272 .remove = da9052_rtc_remove,
279 .driver = { 273 .driver = {
280 .name = "da9052-rtc", 274 .name = "da9052-rtc",
281 .owner = THIS_MODULE, 275 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c
new file mode 100644
index 000000000000..8f0dcfedb83c
--- /dev/null
+++ b/drivers/rtc/rtc-da9055.c
@@ -0,0 +1,413 @@
1/*
2 * Real time clock driver for DA9055
3 *
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
5 *
6 * Author: Dajun Dajun Chen <dajun.chen@diasemi.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/rtc.h>
18
19#include <linux/mfd/da9055/core.h>
20#include <linux/mfd/da9055/reg.h>
21#include <linux/mfd/da9055/pdata.h>
22
23struct da9055_rtc {
24 struct rtc_device *rtc;
25 struct da9055 *da9055;
26 int alarm_enable;
27};
28
29static int da9055_rtc_enable_alarm(struct da9055_rtc *rtc, bool enable)
30{
31 int ret;
32 if (enable) {
33 ret = da9055_reg_update(rtc->da9055, DA9055_REG_ALARM_Y,
34 DA9055_RTC_ALM_EN,
35 DA9055_RTC_ALM_EN);
36 if (ret != 0)
37 dev_err(rtc->da9055->dev, "Failed to enable ALM: %d\n",
38 ret);
39 rtc->alarm_enable = 1;
40 } else {
41 ret = da9055_reg_update(rtc->da9055, DA9055_REG_ALARM_Y,
42 DA9055_RTC_ALM_EN, 0);
43 if (ret != 0)
44 dev_err(rtc->da9055->dev,
45 "Failed to disable ALM: %d\n", ret);
46 rtc->alarm_enable = 0;
47 }
48 return ret;
49}
50
51static irqreturn_t da9055_rtc_alm_irq(int irq, void *data)
52{
53 struct da9055_rtc *rtc = data;
54
55 da9055_rtc_enable_alarm(rtc, 0);
56 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
57
58 return IRQ_HANDLED;
59}
60
61static int da9055_read_alarm(struct da9055 *da9055, struct rtc_time *rtc_tm)
62{
63 int ret;
64 uint8_t v[5];
65
66 ret = da9055_group_read(da9055, DA9055_REG_ALARM_MI, 5, v);
67 if (ret != 0) {
68 dev_err(da9055->dev, "Failed to group read ALM: %d\n", ret);
69 return ret;
70 }
71
72 rtc_tm->tm_year = (v[4] & DA9055_RTC_ALM_YEAR) + 100;
73 rtc_tm->tm_mon = (v[3] & DA9055_RTC_ALM_MONTH) - 1;
74 rtc_tm->tm_mday = v[2] & DA9055_RTC_ALM_DAY;
75 rtc_tm->tm_hour = v[1] & DA9055_RTC_ALM_HOUR;
76 rtc_tm->tm_min = v[0] & DA9055_RTC_ALM_MIN;
77
78 return rtc_valid_tm(rtc_tm);
79}
80
81static int da9055_set_alarm(struct da9055 *da9055, struct rtc_time *rtc_tm)
82{
83 int ret;
84 uint8_t v[2];
85
86 rtc_tm->tm_year -= 100;
87 rtc_tm->tm_mon += 1;
88
89 ret = da9055_reg_update(da9055, DA9055_REG_ALARM_MI,
90 DA9055_RTC_ALM_MIN, rtc_tm->tm_min);
91 if (ret != 0) {
92 dev_err(da9055->dev, "Failed to write ALRM MIN: %d\n", ret);
93 return ret;
94 }
95
96 v[0] = rtc_tm->tm_hour;
97 v[1] = rtc_tm->tm_mday;
98
99 ret = da9055_group_write(da9055, DA9055_REG_ALARM_H, 2, v);
100 if (ret < 0)
101 return ret;
102
103 ret = da9055_reg_update(da9055, DA9055_REG_ALARM_MO,
104 DA9055_RTC_ALM_MONTH, rtc_tm->tm_mon);
105 if (ret < 0)
106 dev_err(da9055->dev, "Failed to write ALM Month:%d\n", ret);
107
108 ret = da9055_reg_update(da9055, DA9055_REG_ALARM_Y,
109 DA9055_RTC_ALM_YEAR, rtc_tm->tm_year);
110 if (ret < 0)
111 dev_err(da9055->dev, "Failed to write ALM Year:%d\n", ret);
112
113 return ret;
114}
115
116static int da9055_rtc_get_alarm_status(struct da9055 *da9055)
117{
118 int ret;
119
120 ret = da9055_reg_read(da9055, DA9055_REG_ALARM_Y);
121 if (ret < 0) {
122 dev_err(da9055->dev, "Failed to read ALM: %d\n", ret);
123 return ret;
124 }
125 ret &= DA9055_RTC_ALM_EN;
126 return (ret > 0) ? 1 : 0;
127}
128
129static int da9055_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
130{
131 struct da9055_rtc *rtc = dev_get_drvdata(dev);
132 uint8_t v[6];
133 int ret;
134
135 ret = da9055_reg_read(rtc->da9055, DA9055_REG_COUNT_S);
136 if (ret < 0)
137 return ret;
138
139 /*
140 * Registers are only valid when RTC_READ
141 * status bit is asserted
142 */
143 if (!(ret & DA9055_RTC_READ))
144 return -EBUSY;
145
146 ret = da9055_group_read(rtc->da9055, DA9055_REG_COUNT_S, 6, v);
147 if (ret < 0) {
148 dev_err(rtc->da9055->dev, "Failed to read RTC time : %d\n",
149 ret);
150 return ret;
151 }
152
153 rtc_tm->tm_year = (v[5] & DA9055_RTC_YEAR) + 100;
154 rtc_tm->tm_mon = (v[4] & DA9055_RTC_MONTH) - 1;
155 rtc_tm->tm_mday = v[3] & DA9055_RTC_DAY;
156 rtc_tm->tm_hour = v[2] & DA9055_RTC_HOUR;
157 rtc_tm->tm_min = v[1] & DA9055_RTC_MIN;
158 rtc_tm->tm_sec = v[0] & DA9055_RTC_SEC;
159
160 return rtc_valid_tm(rtc_tm);
161}
162
163static int da9055_rtc_set_time(struct device *dev, struct rtc_time *tm)
164{
165 struct da9055_rtc *rtc;
166 uint8_t v[6];
167
168 rtc = dev_get_drvdata(dev);
169
170 v[0] = tm->tm_sec;
171 v[1] = tm->tm_min;
172 v[2] = tm->tm_hour;
173 v[3] = tm->tm_mday;
174 v[4] = tm->tm_mon + 1;
175 v[5] = tm->tm_year - 100;
176
177 return da9055_group_write(rtc->da9055, DA9055_REG_COUNT_S, 6, v);
178}
179
180static int da9055_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
181{
182 int ret;
183 struct rtc_time *tm = &alrm->time;
184 struct da9055_rtc *rtc = dev_get_drvdata(dev);
185
186 ret = da9055_read_alarm(rtc->da9055, tm);
187
188 if (ret)
189 return ret;
190
191 alrm->enabled = da9055_rtc_get_alarm_status(rtc->da9055);
192
193 return 0;
194}
195
196static int da9055_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
197{
198 int ret;
199 struct rtc_time *tm = &alrm->time;
200 struct da9055_rtc *rtc = dev_get_drvdata(dev);
201
202 ret = da9055_rtc_enable_alarm(rtc, 0);
203 if (ret < 0)
204 return ret;
205
206 ret = da9055_set_alarm(rtc->da9055, tm);
207 if (ret)
208 return ret;
209
210 ret = da9055_rtc_enable_alarm(rtc, 1);
211
212 return ret;
213}
214
215static int da9055_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
216{
217 struct da9055_rtc *rtc = dev_get_drvdata(dev);
218
219 return da9055_rtc_enable_alarm(rtc, enabled);
220}
221
222static const struct rtc_class_ops da9055_rtc_ops = {
223 .read_time = da9055_rtc_read_time,
224 .set_time = da9055_rtc_set_time,
225 .read_alarm = da9055_rtc_read_alarm,
226 .set_alarm = da9055_rtc_set_alarm,
227 .alarm_irq_enable = da9055_rtc_alarm_irq_enable,
228};
229
230static int da9055_rtc_device_init(struct da9055 *da9055,
231 struct da9055_pdata *pdata)
232{
233 int ret;
234
235 /* Enable RTC and the internal Crystal */
236 ret = da9055_reg_update(da9055, DA9055_REG_CONTROL_B,
237 DA9055_RTC_EN, DA9055_RTC_EN);
238 if (ret < 0)
239 return ret;
240 ret = da9055_reg_update(da9055, DA9055_REG_EN_32K,
241 DA9055_CRYSTAL_EN, DA9055_CRYSTAL_EN);
242 if (ret < 0)
243 return ret;
244
245 /* Enable RTC in Power Down mode */
246 ret = da9055_reg_update(da9055, DA9055_REG_CONTROL_B,
247 DA9055_RTC_MODE_PD, DA9055_RTC_MODE_PD);
248 if (ret < 0)
249 return ret;
250
251 /* Enable RTC in Reset mode */
252 if (pdata && pdata->reset_enable) {
253 ret = da9055_reg_update(da9055, DA9055_REG_CONTROL_B,
254 DA9055_RTC_MODE_SD,
255 DA9055_RTC_MODE_SD <<
256 DA9055_RTC_MODE_SD_SHIFT);
257 if (ret < 0)
258 return ret;
259 }
260
261 /* Disable the RTC TICK ALM */
262 ret = da9055_reg_update(da9055, DA9055_REG_ALARM_MO,
263 DA9055_RTC_TICK_WAKE_MASK, 0);
264 if (ret < 0)
265 return ret;
266
267 return 0;
268}
269
270static int da9055_rtc_probe(struct platform_device *pdev)
271{
272 struct da9055_rtc *rtc;
273 struct da9055_pdata *pdata = NULL;
274 int ret, alm_irq;
275
276 rtc = devm_kzalloc(&pdev->dev, sizeof(struct da9055_rtc), GFP_KERNEL);
277 if (!rtc)
278 return -ENOMEM;
279
280 rtc->da9055 = dev_get_drvdata(pdev->dev.parent);
281 pdata = rtc->da9055->dev->platform_data;
282 platform_set_drvdata(pdev, rtc);
283
284 ret = da9055_rtc_device_init(rtc->da9055, pdata);
285 if (ret < 0)
286 goto err_rtc;
287
288 ret = da9055_reg_read(rtc->da9055, DA9055_REG_ALARM_Y);
289 if (ret < 0)
290 goto err_rtc;
291
292 if (ret & DA9055_RTC_ALM_EN)
293 rtc->alarm_enable = 1;
294
295 device_init_wakeup(&pdev->dev, 1);
296
297 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
298 &da9055_rtc_ops, THIS_MODULE);
299 if (IS_ERR(rtc->rtc)) {
300 ret = PTR_ERR(rtc->rtc);
301 goto err_rtc;
302 }
303
304 alm_irq = platform_get_irq_byname(pdev, "ALM");
305 alm_irq = regmap_irq_get_virq(rtc->da9055->irq_data, alm_irq);
306 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
307 da9055_rtc_alm_irq,
308 IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
309 "ALM", rtc);
310 if (ret != 0)
311 dev_err(rtc->da9055->dev, "irq registration failed: %d\n", ret);
312
313err_rtc:
314 return ret;
315
316}
317
318static int da9055_rtc_remove(struct platform_device *pdev)
319{
320 struct da9055_rtc *rtc = pdev->dev.platform_data;
321
322 rtc_device_unregister(rtc->rtc);
323 platform_set_drvdata(pdev, NULL);
324
325 return 0;
326}
327
328#ifdef CONFIG_PM
329/* Turn off the alarm if it should not be a wake source. */
330static int da9055_rtc_suspend(struct device *dev)
331{
332 struct platform_device *pdev = to_platform_device(dev);
333 struct da9055_rtc *rtc = dev_get_drvdata(&pdev->dev);
334 int ret;
335
336 if (!device_may_wakeup(&pdev->dev)) {
337 /* Disable the ALM IRQ */
338 ret = da9055_rtc_enable_alarm(rtc, 0);
339 if (ret < 0)
340 dev_err(&pdev->dev, "Failed to disable RTC ALM\n");
341 }
342
343 return 0;
344}
345
346/* Enable the alarm if it should be enabled (in case it was disabled to
347 * prevent use as a wake source).
348 */
349static int da9055_rtc_resume(struct device *dev)
350{
351 struct platform_device *pdev = to_platform_device(dev);
352 struct da9055_rtc *rtc = dev_get_drvdata(&pdev->dev);
353 int ret;
354
355 if (!device_may_wakeup(&pdev->dev)) {
356 if (rtc->alarm_enable) {
357 ret = da9055_rtc_enable_alarm(rtc, 1);
358 if (ret < 0)
359 dev_err(&pdev->dev,
360 "Failed to restart RTC ALM\n");
361 }
362 }
363
364 return 0;
365}
366
367/* Unconditionally disable the alarm */
368static int da9055_rtc_freeze(struct device *dev)
369{
370 struct platform_device *pdev = to_platform_device(dev);
371 struct da9055_rtc *rtc = dev_get_drvdata(&pdev->dev);
372 int ret;
373
374 ret = da9055_rtc_enable_alarm(rtc, 0);
375 if (ret < 0)
376 dev_err(&pdev->dev, "Failed to freeze RTC ALMs\n");
377
378 return 0;
379
380}
381#else
382#define da9055_rtc_suspend NULL
383#define da9055_rtc_resume NULL
384#define da9055_rtc_freeze NULL
385#endif
386
387static const struct dev_pm_ops da9055_rtc_pm_ops = {
388 .suspend = da9055_rtc_suspend,
389 .resume = da9055_rtc_resume,
390
391 .freeze = da9055_rtc_freeze,
392 .thaw = da9055_rtc_resume,
393 .restore = da9055_rtc_resume,
394
395 .poweroff = da9055_rtc_suspend,
396};
397
398static struct platform_driver da9055_rtc_driver = {
399 .probe = da9055_rtc_probe,
400 .remove = da9055_rtc_remove,
401 .driver = {
402 .name = "da9055-rtc",
403 .owner = THIS_MODULE,
404 .pm = &da9055_rtc_pm_ops,
405 },
406};
407
408module_platform_driver(da9055_rtc_driver);
409
410MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
411MODULE_DESCRIPTION("RTC driver for Dialog DA9055 PMIC");
412MODULE_LICENSE("GPL");
413MODULE_ALIAS("platform:da9055-rtc");
diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
index 14c2109dbaa3..56b73089bb29 100644
--- a/drivers/rtc/rtc-davinci.c
+++ b/drivers/rtc/rtc-davinci.c
@@ -485,7 +485,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
485 struct resource *res, *mem; 485 struct resource *res, *mem;
486 int ret = 0; 486 int ret = 0;
487 487
488 davinci_rtc = kzalloc(sizeof(struct davinci_rtc), GFP_KERNEL); 488 davinci_rtc = devm_kzalloc(&pdev->dev, sizeof(struct davinci_rtc), GFP_KERNEL);
489 if (!davinci_rtc) { 489 if (!davinci_rtc) {
490 dev_dbg(dev, "could not allocate memory for private data\n"); 490 dev_dbg(dev, "could not allocate memory for private data\n");
491 return -ENOMEM; 491 return -ENOMEM;
@@ -494,34 +494,31 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
494 davinci_rtc->irq = platform_get_irq(pdev, 0); 494 davinci_rtc->irq = platform_get_irq(pdev, 0);
495 if (davinci_rtc->irq < 0) { 495 if (davinci_rtc->irq < 0) {
496 dev_err(dev, "no RTC irq\n"); 496 dev_err(dev, "no RTC irq\n");
497 ret = davinci_rtc->irq; 497 return davinci_rtc->irq;
498 goto fail1;
499 } 498 }
500 499
501 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 500 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
502 if (!res) { 501 if (!res) {
503 dev_err(dev, "no mem resource\n"); 502 dev_err(dev, "no mem resource\n");
504 ret = -EINVAL; 503 return -EINVAL;
505 goto fail1;
506 } 504 }
507 505
508 davinci_rtc->pbase = res->start; 506 davinci_rtc->pbase = res->start;
509 davinci_rtc->base_size = resource_size(res); 507 davinci_rtc->base_size = resource_size(res);
510 508
511 mem = request_mem_region(davinci_rtc->pbase, davinci_rtc->base_size, 509 mem = devm_request_mem_region(dev, davinci_rtc->pbase,
512 pdev->name); 510 davinci_rtc->base_size, pdev->name);
513 if (!mem) { 511 if (!mem) {
514 dev_err(dev, "RTC registers at %08x are not free\n", 512 dev_err(dev, "RTC registers at %08x are not free\n",
515 davinci_rtc->pbase); 513 davinci_rtc->pbase);
516 ret = -EBUSY; 514 return -EBUSY;
517 goto fail1;
518 } 515 }
519 516
520 davinci_rtc->base = ioremap(davinci_rtc->pbase, davinci_rtc->base_size); 517 davinci_rtc->base = devm_ioremap(dev, davinci_rtc->pbase,
518 davinci_rtc->base_size);
521 if (!davinci_rtc->base) { 519 if (!davinci_rtc->base) {
522 dev_err(dev, "unable to ioremap MEM resource\n"); 520 dev_err(dev, "unable to ioremap MEM resource\n");
523 ret = -ENOMEM; 521 return -ENOMEM;
524 goto fail2;
525 } 522 }
526 523
527 platform_set_drvdata(pdev, davinci_rtc); 524 platform_set_drvdata(pdev, davinci_rtc);
@@ -529,9 +526,10 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
529 davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 526 davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
530 &davinci_rtc_ops, THIS_MODULE); 527 &davinci_rtc_ops, THIS_MODULE);
531 if (IS_ERR(davinci_rtc->rtc)) { 528 if (IS_ERR(davinci_rtc->rtc)) {
532 dev_err(dev, "unable to register RTC device, err %ld\n", 529 ret = PTR_ERR(davinci_rtc->rtc);
533 PTR_ERR(davinci_rtc->rtc)); 530 dev_err(dev, "unable to register RTC device, err %d\n",
534 goto fail3; 531 ret);
532 goto fail1;
535 } 533 }
536 534
537 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG); 535 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
@@ -541,11 +539,11 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
541 rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CTRL); 539 rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CTRL);
542 rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CCTRL); 540 rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CCTRL);
543 541
544 ret = request_irq(davinci_rtc->irq, davinci_rtc_interrupt, 542 ret = devm_request_irq(dev, davinci_rtc->irq, davinci_rtc_interrupt,
545 0, "davinci_rtc", davinci_rtc); 543 0, "davinci_rtc", davinci_rtc);
546 if (ret < 0) { 544 if (ret < 0) {
547 dev_err(dev, "unable to register davinci RTC interrupt\n"); 545 dev_err(dev, "unable to register davinci RTC interrupt\n");
548 goto fail4; 546 goto fail2;
549 } 547 }
550 548
551 /* Enable interrupts */ 549 /* Enable interrupts */
@@ -559,20 +557,14 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
559 557
560 return 0; 558 return 0;
561 559
562fail4:
563 rtc_device_unregister(davinci_rtc->rtc);
564fail3:
565 platform_set_drvdata(pdev, NULL);
566 iounmap(davinci_rtc->base);
567fail2: 560fail2:
568 release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size); 561 rtc_device_unregister(davinci_rtc->rtc);
569fail1: 562fail1:
570 kfree(davinci_rtc); 563 platform_set_drvdata(pdev, NULL);
571
572 return ret; 564 return ret;
573} 565}
574 566
575static int __devexit davinci_rtc_remove(struct platform_device *pdev) 567static int davinci_rtc_remove(struct platform_device *pdev)
576{ 568{
577 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev); 569 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
578 570
@@ -580,23 +572,16 @@ static int __devexit davinci_rtc_remove(struct platform_device *pdev)
580 572
581 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN); 573 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
582 574
583 free_irq(davinci_rtc->irq, davinci_rtc);
584
585 rtc_device_unregister(davinci_rtc->rtc); 575 rtc_device_unregister(davinci_rtc->rtc);
586 576
587 iounmap(davinci_rtc->base);
588 release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);
589
590 platform_set_drvdata(pdev, NULL); 577 platform_set_drvdata(pdev, NULL);
591 578
592 kfree(davinci_rtc);
593
594 return 0; 579 return 0;
595} 580}
596 581
597static struct platform_driver davinci_rtc_driver = { 582static struct platform_driver davinci_rtc_driver = {
598 .probe = davinci_rtc_probe, 583 .probe = davinci_rtc_probe,
599 .remove = __devexit_p(davinci_rtc_remove), 584 .remove = davinci_rtc_remove,
600 .driver = { 585 .driver = {
601 .name = "rtc_davinci", 586 .name = "rtc_davinci",
602 .owner = THIS_MODULE, 587 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index cace6d3aed9a..d04939369251 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -11,6 +11,8 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12*/ 12*/
13 13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/rtc.h> 17#include <linux/rtc.h>
16#include <linux/sched.h> 18#include <linux/sched.h>
@@ -379,25 +381,6 @@ static long rtc_dev_ioctl(struct file *file,
379 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg); 381 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
380 break; 382 break;
381 383
382#if 0
383 case RTC_EPOCH_SET:
384#ifndef rtc_epoch
385 /*
386 * There were no RTC clocks before 1900.
387 */
388 if (arg < 1900) {
389 err = -EINVAL;
390 break;
391 }
392 rtc_epoch = arg;
393 err = 0;
394#endif
395 break;
396
397 case RTC_EPOCH_READ:
398 err = put_user(rtc_epoch, (unsigned long __user *)uarg);
399 break;
400#endif
401 case RTC_WKALM_SET: 384 case RTC_WKALM_SET:
402 mutex_unlock(&rtc->ops_lock); 385 mutex_unlock(&rtc->ops_lock);
403 if (copy_from_user(&alarm, uarg, sizeof(alarm))) 386 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
@@ -481,7 +464,7 @@ void rtc_dev_prepare(struct rtc_device *rtc)
481 return; 464 return;
482 465
483 if (rtc->id >= RTC_DEV_MAX) { 466 if (rtc->id >= RTC_DEV_MAX) {
484 pr_debug("%s: too many RTC devices\n", rtc->name); 467 dev_dbg(&rtc->dev, "%s: too many RTC devices\n", rtc->name);
485 return; 468 return;
486 } 469 }
487 470
@@ -499,10 +482,10 @@ void rtc_dev_prepare(struct rtc_device *rtc)
499void rtc_dev_add_device(struct rtc_device *rtc) 482void rtc_dev_add_device(struct rtc_device *rtc)
500{ 483{
501 if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1)) 484 if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1))
502 printk(KERN_WARNING "%s: failed to add char device %d:%d\n", 485 dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n",
503 rtc->name, MAJOR(rtc_devt), rtc->id); 486 rtc->name, MAJOR(rtc_devt), rtc->id);
504 else 487 else
505 pr_debug("%s: dev (%d:%d)\n", rtc->name, 488 dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name,
506 MAJOR(rtc_devt), rtc->id); 489 MAJOR(rtc_devt), rtc->id);
507} 490}
508 491
@@ -518,8 +501,7 @@ void __init rtc_dev_init(void)
518 501
519 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc"); 502 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
520 if (err < 0) 503 if (err < 0)
521 printk(KERN_ERR "%s: failed to allocate char dev region\n", 504 pr_err("failed to allocate char dev region\n");
522 __FILE__);
523} 505}
524 506
525void __exit rtc_dev_exit(void) 507void __exit rtc_dev_exit(void)
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index d4457afcba89..b2ed2c94b081 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -123,7 +123,7 @@ static struct rtc_class_ops dm355evm_rtc_ops = {
123 123
124/*----------------------------------------------------------------------*/ 124/*----------------------------------------------------------------------*/
125 125
126static int __devinit dm355evm_rtc_probe(struct platform_device *pdev) 126static int dm355evm_rtc_probe(struct platform_device *pdev)
127{ 127{
128 struct rtc_device *rtc; 128 struct rtc_device *rtc;
129 129
@@ -139,7 +139,7 @@ static int __devinit dm355evm_rtc_probe(struct platform_device *pdev)
139 return 0; 139 return 0;
140} 140}
141 141
142static int __devexit dm355evm_rtc_remove(struct platform_device *pdev) 142static int dm355evm_rtc_remove(struct platform_device *pdev)
143{ 143{
144 struct rtc_device *rtc = platform_get_drvdata(pdev); 144 struct rtc_device *rtc = platform_get_drvdata(pdev);
145 145
@@ -154,7 +154,7 @@ static int __devexit dm355evm_rtc_remove(struct platform_device *pdev)
154 */ 154 */
155static struct platform_driver rtc_dm355evm_driver = { 155static struct platform_driver rtc_dm355evm_driver = {
156 .probe = dm355evm_rtc_probe, 156 .probe = dm355evm_rtc_probe,
157 .remove = __devexit_p(dm355evm_rtc_remove), 157 .remove = dm355evm_rtc_remove,
158 .driver = { 158 .driver = {
159 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
160 .name = "rtc-dm355evm", 160 .name = "rtc-dm355evm",
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index 990c3ff489bf..d989412a348a 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -329,7 +329,7 @@ static const struct rtc_class_ops ds1286_ops = {
329 .alarm_irq_enable = ds1286_alarm_irq_enable, 329 .alarm_irq_enable = ds1286_alarm_irq_enable,
330}; 330};
331 331
332static int __devinit ds1286_probe(struct platform_device *pdev) 332static int ds1286_probe(struct platform_device *pdev)
333{ 333{
334 struct rtc_device *rtc; 334 struct rtc_device *rtc;
335 struct resource *res; 335 struct resource *res;
@@ -376,7 +376,7 @@ out:
376 return ret; 376 return ret;
377} 377}
378 378
379static int __devexit ds1286_remove(struct platform_device *pdev) 379static int ds1286_remove(struct platform_device *pdev)
380{ 380{
381 struct ds1286_priv *priv = platform_get_drvdata(pdev); 381 struct ds1286_priv *priv = platform_get_drvdata(pdev);
382 382
@@ -393,7 +393,7 @@ static struct platform_driver ds1286_platform_driver = {
393 .owner = THIS_MODULE, 393 .owner = THIS_MODULE,
394 }, 394 },
395 .probe = ds1286_probe, 395 .probe = ds1286_probe,
396 .remove = __devexit_p(ds1286_remove), 396 .remove = ds1286_remove,
397}; 397};
398 398
399module_platform_driver(ds1286_platform_driver); 399module_platform_driver(ds1286_platform_driver);
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index f0d638922644..fdbcdb289d60 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -234,7 +234,7 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
234 return 0; 234 return 0;
235} 235}
236 236
237static int __devexit ds1302_rtc_remove(struct platform_device *pdev) 237static int ds1302_rtc_remove(struct platform_device *pdev)
238{ 238{
239 struct rtc_device *rtc = platform_get_drvdata(pdev); 239 struct rtc_device *rtc = platform_get_drvdata(pdev);
240 240
@@ -249,7 +249,7 @@ static struct platform_driver ds1302_platform_driver = {
249 .name = DRV_NAME, 249 .name = DRV_NAME,
250 .owner = THIS_MODULE, 250 .owner = THIS_MODULE,
251 }, 251 },
252 .remove = __devexit_p(ds1302_rtc_remove), 252 .remove = ds1302_rtc_remove,
253}; 253};
254 254
255static int __init ds1302_rtc_init(void) 255static int __init ds1302_rtc_init(void)
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index 686a865913e1..b05a6dc96405 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -601,7 +601,7 @@ static struct bin_attribute nvram = {
601 * Interface to SPI stack 601 * Interface to SPI stack
602 */ 602 */
603 603
604static int __devinit ds1305_probe(struct spi_device *spi) 604static int ds1305_probe(struct spi_device *spi)
605{ 605{
606 struct ds1305 *ds1305; 606 struct ds1305 *ds1305;
607 int status; 607 int status;
@@ -635,9 +635,7 @@ static int __devinit ds1305_probe(struct spi_device *spi)
635 goto fail0; 635 goto fail0;
636 } 636 }
637 637
638 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n", 638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl);
639 "read", ds1305->ctrl[0],
640 ds1305->ctrl[1], ds1305->ctrl[2]);
641 639
642 /* Sanity check register values ... partially compensating for the 640 /* Sanity check register values ... partially compensating for the
643 * fact that SPI has no device handshake. A pullup on MISO would 641 * fact that SPI has no device handshake. A pullup on MISO would
@@ -723,9 +721,7 @@ static int __devinit ds1305_probe(struct spi_device *spi)
723 goto fail0; 721 goto fail0;
724 } 722 }
725 723
726 dev_dbg(&spi->dev, "ctrl %s: %02x %02x %02x\n", 724 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl);
727 "write", ds1305->ctrl[0],
728 ds1305->ctrl[1], ds1305->ctrl[2]);
729 } 725 }
730 726
731 /* see if non-Linux software set up AM/PM mode */ 727 /* see if non-Linux software set up AM/PM mode */
@@ -787,7 +783,7 @@ fail0:
787 return status; 783 return status;
788} 784}
789 785
790static int __devexit ds1305_remove(struct spi_device *spi) 786static int ds1305_remove(struct spi_device *spi)
791{ 787{
792 struct ds1305 *ds1305 = spi_get_drvdata(spi); 788 struct ds1305 *ds1305 = spi_get_drvdata(spi);
793 789
@@ -810,7 +806,7 @@ static struct spi_driver ds1305_driver = {
810 .driver.name = "rtc-ds1305", 806 .driver.name = "rtc-ds1305",
811 .driver.owner = THIS_MODULE, 807 .driver.owner = THIS_MODULE,
812 .probe = ds1305_probe, 808 .probe = ds1305_probe,
813 .remove = __devexit_p(ds1305_remove), 809 .remove = ds1305_remove,
814 /* REVISIT add suspend/resume */ 810 /* REVISIT add suspend/resume */
815}; 811};
816 812
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 836710ce750e..970a236b147a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -322,12 +322,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
322 return -EIO; 322 return -EIO;
323 } 323 }
324 324
325 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x\n", 325 dev_dbg(dev, "%s: %7ph\n", "read", ds1307->regs);
326 "read",
327 ds1307->regs[0], ds1307->regs[1],
328 ds1307->regs[2], ds1307->regs[3],
329 ds1307->regs[4], ds1307->regs[5],
330 ds1307->regs[6]);
331 326
332 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f); 327 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f);
333 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f); 328 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f);
@@ -398,9 +393,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
398 break; 393 break;
399 } 394 }
400 395
401 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x\n", 396 dev_dbg(dev, "%s: %7ph\n", "write", buf);
402 "write", buf[0], buf[1], buf[2], buf[3],
403 buf[4], buf[5], buf[6]);
404 397
405 result = ds1307->write_block_data(ds1307->client, 398 result = ds1307->write_block_data(ds1307->client,
406 ds1307->offset, 7, buf); 399 ds1307->offset, 7, buf);
@@ -617,8 +610,8 @@ ds1307_nvram_write(struct file *filp, struct kobject *kobj,
617 610
618/*----------------------------------------------------------------------*/ 611/*----------------------------------------------------------------------*/
619 612
620static int __devinit ds1307_probe(struct i2c_client *client, 613static int ds1307_probe(struct i2c_client *client,
621 const struct i2c_device_id *id) 614 const struct i2c_device_id *id)
622{ 615{
623 struct ds1307 *ds1307; 616 struct ds1307 *ds1307;
624 int err = -ENODEV; 617 int err = -ENODEV;
@@ -938,7 +931,7 @@ exit_free:
938 return err; 931 return err;
939} 932}
940 933
941static int __devexit ds1307_remove(struct i2c_client *client) 934static int ds1307_remove(struct i2c_client *client)
942{ 935{
943 struct ds1307 *ds1307 = i2c_get_clientdata(client); 936 struct ds1307 *ds1307 = i2c_get_clientdata(client);
944 937
@@ -963,7 +956,7 @@ static struct i2c_driver ds1307_driver = {
963 .owner = THIS_MODULE, 956 .owner = THIS_MODULE,
964 }, 957 },
965 .probe = ds1307_probe, 958 .probe = ds1307_probe,
966 .remove = __devexit_p(ds1307_remove), 959 .remove = ds1307_remove,
967 .id_table = ds1307_id, 960 .id_table = ds1307_id,
968}; 961};
969 962
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 966316088b7f..fef76868aae0 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -391,7 +391,7 @@ out_free:
391 return ret; 391 return ret;
392} 392}
393 393
394static int __devexit ds1374_remove(struct i2c_client *client) 394static int ds1374_remove(struct i2c_client *client)
395{ 395{
396 struct ds1374 *ds1374 = i2c_get_clientdata(client); 396 struct ds1374 *ds1374 = i2c_get_clientdata(client);
397 397
@@ -442,7 +442,7 @@ static struct i2c_driver ds1374_driver = {
442 .pm = DS1374_PM, 442 .pm = DS1374_PM,
443 }, 443 },
444 .probe = ds1374_probe, 444 .probe = ds1374_probe,
445 .remove = __devexit_p(ds1374_remove), 445 .remove = ds1374_remove,
446 .id_table = ds1374_id, 446 .id_table = ds1374_id,
447}; 447};
448 448
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index b0a99e1b25be..f994257981a0 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -121,7 +121,7 @@ static const struct rtc_class_ops ds1390_rtc_ops = {
121 .set_time = ds1390_set_time, 121 .set_time = ds1390_set_time,
122}; 122};
123 123
124static int __devinit ds1390_probe(struct spi_device *spi) 124static int ds1390_probe(struct spi_device *spi)
125{ 125{
126 unsigned char tmp; 126 unsigned char tmp;
127 struct ds1390 *chip; 127 struct ds1390 *chip;
@@ -156,7 +156,7 @@ static int __devinit ds1390_probe(struct spi_device *spi)
156 return res; 156 return res;
157} 157}
158 158
159static int __devexit ds1390_remove(struct spi_device *spi) 159static int ds1390_remove(struct spi_device *spi)
160{ 160{
161 struct ds1390 *chip = spi_get_drvdata(spi); 161 struct ds1390 *chip = spi_get_drvdata(spi);
162 162
@@ -172,7 +172,7 @@ static struct spi_driver ds1390_driver = {
172 .owner = THIS_MODULE, 172 .owner = THIS_MODULE,
173 }, 173 },
174 .probe = ds1390_probe, 174 .probe = ds1390_probe,
175 .remove = __devexit_p(ds1390_remove), 175 .remove = ds1390_remove,
176}; 176};
177 177
178module_spi_driver(ds1390_driver); 178module_spi_driver(ds1390_driver);
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 1f675f5294f5..6a3fcfe3b0e7 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -476,8 +476,7 @@ static struct bin_attribute ds1511_nvram_attr = {
476 .write = ds1511_nvram_write, 476 .write = ds1511_nvram_write,
477}; 477};
478 478
479 static int __devinit 479static int ds1511_rtc_probe(struct platform_device *pdev)
480ds1511_rtc_probe(struct platform_device *pdev)
481{ 480{
482 struct rtc_device *rtc; 481 struct rtc_device *rtc;
483 struct resource *res; 482 struct resource *res;
@@ -551,8 +550,7 @@ ds1511_rtc_probe(struct platform_device *pdev)
551 return ret; 550 return ret;
552} 551}
553 552
554 static int __devexit 553static int ds1511_rtc_remove(struct platform_device *pdev)
555ds1511_rtc_remove(struct platform_device *pdev)
556{ 554{
557 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 555 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
558 556
@@ -573,7 +571,7 @@ MODULE_ALIAS("platform:ds1511");
573 571
574static struct platform_driver ds1511_rtc_driver = { 572static struct platform_driver ds1511_rtc_driver = {
575 .probe = ds1511_rtc_probe, 573 .probe = ds1511_rtc_probe,
576 .remove = __devexit_p(ds1511_rtc_remove), 574 .remove = ds1511_rtc_remove,
577 .driver = { 575 .driver = {
578 .name = "ds1511", 576 .name = "ds1511",
579 .owner = THIS_MODULE, 577 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 6ccedbbf923c..25ce0621ade9 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -276,7 +276,7 @@ static struct bin_attribute ds1553_nvram_attr = {
276 .write = ds1553_nvram_write, 276 .write = ds1553_nvram_write,
277}; 277};
278 278
279static int __devinit ds1553_rtc_probe(struct platform_device *pdev) 279static int ds1553_rtc_probe(struct platform_device *pdev)
280{ 280{
281 struct rtc_device *rtc; 281 struct rtc_device *rtc;
282 struct resource *res; 282 struct resource *res;
@@ -338,7 +338,7 @@ static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
338 return ret; 338 return ret;
339} 339}
340 340
341static int __devexit ds1553_rtc_remove(struct platform_device *pdev) 341static int ds1553_rtc_remove(struct platform_device *pdev)
342{ 342{
343 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 343 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
344 344
@@ -354,7 +354,7 @@ MODULE_ALIAS("platform:rtc-ds1553");
354 354
355static struct platform_driver ds1553_rtc_driver = { 355static struct platform_driver ds1553_rtc_driver = {
356 .probe = ds1553_rtc_probe, 356 .probe = ds1553_rtc_probe,
357 .remove = __devexit_p(ds1553_rtc_remove), 357 .remove = ds1553_rtc_remove,
358 .driver = { 358 .driver = {
359 .name = "rtc-ds1553", 359 .name = "rtc-ds1553",
360 .owner = THIS_MODULE, 360 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 76112667c507..609c870e2cc5 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -159,7 +159,7 @@ static ssize_t ds1742_nvram_write(struct file *filp, struct kobject *kobj,
159 return count; 159 return count;
160} 160}
161 161
162static int __devinit ds1742_rtc_probe(struct platform_device *pdev) 162static int ds1742_rtc_probe(struct platform_device *pdev)
163{ 163{
164 struct rtc_device *rtc; 164 struct rtc_device *rtc;
165 struct resource *res; 165 struct resource *res;
@@ -222,7 +222,7 @@ static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
222 return ret; 222 return ret;
223} 223}
224 224
225static int __devexit ds1742_rtc_remove(struct platform_device *pdev) 225static int ds1742_rtc_remove(struct platform_device *pdev)
226{ 226{
227 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 227 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
228 228
@@ -233,7 +233,7 @@ static int __devexit ds1742_rtc_remove(struct platform_device *pdev)
233 233
234static struct platform_driver ds1742_rtc_driver = { 234static struct platform_driver ds1742_rtc_driver = {
235 .probe = ds1742_rtc_probe, 235 .probe = ds1742_rtc_probe,
236 .remove = __devexit_p(ds1742_rtc_remove), 236 .remove = ds1742_rtc_remove,
237 .driver = { 237 .driver = {
238 .name = "rtc-ds1742", 238 .name = "rtc-ds1742",
239 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index 5ea9df7c8c31..b04fc4272fb3 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -70,7 +70,7 @@ static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev,
70 for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++) { 70 for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++) {
71 err = gpio_request(ds2404_gpio[i].gpio, ds2404_gpio[i].name); 71 err = gpio_request(ds2404_gpio[i].gpio, ds2404_gpio[i].name);
72 if (err) { 72 if (err) {
73 printk(KERN_ERR "error mapping gpio %s: %d\n", 73 dev_err(&pdev->dev, "error mapping gpio %s: %d\n",
74 ds2404_gpio[i].name, err); 74 ds2404_gpio[i].name, err);
75 goto err_request; 75 goto err_request;
76 } 76 }
@@ -177,7 +177,7 @@ static void ds2404_write_memory(struct device *dev, u16 offset,
177 177
178 for (i = 0; i < length; i++) { 178 for (i = 0; i < length; i++) {
179 if (out[i] != ds2404_read_byte(dev)) { 179 if (out[i] != ds2404_read_byte(dev)) {
180 printk(KERN_ERR "read invalid data\n"); 180 dev_err(dev, "read invalid data\n");
181 return; 181 return;
182 } 182 }
183 } 183 }
@@ -283,19 +283,7 @@ static struct platform_driver rtc_device_driver = {
283 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
284 }, 284 },
285}; 285};
286 286module_platform_driver(rtc_device_driver);
287static __init int ds2404_init(void)
288{
289 return platform_driver_register(&rtc_device_driver);
290}
291
292static __exit void ds2404_exit(void)
293{
294 platform_driver_unregister(&rtc_device_driver);
295}
296
297module_init(ds2404_init);
298module_exit(ds2404_exit);
299 287
300MODULE_DESCRIPTION("DS2404 RTC"); 288MODULE_DESCRIPTION("DS2404 RTC");
301MODULE_AUTHOR("Sven Schnelle"); 289MODULE_AUTHOR("Sven Schnelle");
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index e1945095814e..db0ca08db315 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -391,8 +391,8 @@ static const struct rtc_class_ops ds3232_rtc_ops = {
391 .alarm_irq_enable = ds3232_alarm_irq_enable, 391 .alarm_irq_enable = ds3232_alarm_irq_enable,
392}; 392};
393 393
394static int __devinit ds3232_probe(struct i2c_client *client, 394static int ds3232_probe(struct i2c_client *client,
395 const struct i2c_device_id *id) 395 const struct i2c_device_id *id)
396{ 396{
397 struct ds3232 *ds3232; 397 struct ds3232 *ds3232;
398 int ret; 398 int ret;
@@ -439,7 +439,7 @@ out_free:
439 return ret; 439 return ret;
440} 440}
441 441
442static int __devexit ds3232_remove(struct i2c_client *client) 442static int ds3232_remove(struct i2c_client *client)
443{ 443{
444 struct ds3232 *ds3232 = i2c_get_clientdata(client); 444 struct ds3232 *ds3232 = i2c_get_clientdata(client);
445 445
@@ -469,7 +469,7 @@ static struct i2c_driver ds3232_driver = {
469 .owner = THIS_MODULE, 469 .owner = THIS_MODULE,
470 }, 470 },
471 .probe = ds3232_probe, 471 .probe = ds3232_probe,
472 .remove = __devexit_p(ds3232_remove), 472 .remove = ds3232_remove,
473 .id_table = ds3232_id, 473 .id_table = ds3232_id,
474}; 474};
475 475
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
index fda707926f02..7a4495ef1c39 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -105,7 +105,7 @@ static const struct rtc_class_ops ds3234_rtc_ops = {
105 .set_time = ds3234_set_time, 105 .set_time = ds3234_set_time,
106}; 106};
107 107
108static int __devinit ds3234_probe(struct spi_device *spi) 108static int ds3234_probe(struct spi_device *spi)
109{ 109{
110 struct rtc_device *rtc; 110 struct rtc_device *rtc;
111 unsigned char tmp; 111 unsigned char tmp;
@@ -156,7 +156,7 @@ static int __devinit ds3234_probe(struct spi_device *spi)
156 return 0; 156 return 0;
157} 157}
158 158
159static int __devexit ds3234_remove(struct spi_device *spi) 159static int ds3234_remove(struct spi_device *spi)
160{ 160{
161 struct rtc_device *rtc = spi_get_drvdata(spi); 161 struct rtc_device *rtc = spi_get_drvdata(spi);
162 162
@@ -170,7 +170,7 @@ static struct spi_driver ds3234_driver = {
170 .owner = THIS_MODULE, 170 .owner = THIS_MODULE,
171 }, 171 },
172 .probe = ds3234_probe, 172 .probe = ds3234_probe,
173 .remove = __devexit_p(ds3234_remove), 173 .remove = ds3234_remove,
174}; 174};
175 175
176module_spi_driver(ds3234_driver); 176module_spi_driver(ds3234_driver);
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
index c9f890b088da..1a0c37c9152b 100644
--- a/drivers/rtc/rtc-efi.c
+++ b/drivers/rtc/rtc-efi.c
@@ -13,6 +13,8 @@
13 * 13 *
14 */ 14 */
15 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
16#include <linux/kernel.h> 18#include <linux/kernel.h>
17#include <linux/module.h> 19#include <linux/module.h>
18#include <linux/time.h> 20#include <linux/time.h>
@@ -47,7 +49,7 @@ compute_wday(efi_time_t *eft)
47 int ndays = 0; 49 int ndays = 0;
48 50
49 if (eft->year < 1998) { 51 if (eft->year < 1998) {
50 printk(KERN_ERR "efirtc: EFI year < 1998, invalid date\n"); 52 pr_err("EFI year < 1998, invalid date\n");
51 return -1; 53 return -1;
52 } 54 }
53 55
@@ -70,7 +72,7 @@ convert_to_efi_time(struct rtc_time *wtime, efi_time_t *eft)
70 eft->day = wtime->tm_mday; 72 eft->day = wtime->tm_mday;
71 eft->hour = wtime->tm_hour; 73 eft->hour = wtime->tm_hour;
72 eft->minute = wtime->tm_min; 74 eft->minute = wtime->tm_min;
73 eft->second = wtime->tm_sec; 75 eft->second = wtime->tm_sec;
74 eft->nanosecond = 0; 76 eft->nanosecond = 0;
75 eft->daylight = wtime->tm_isdst ? EFI_ISDST : 0; 77 eft->daylight = wtime->tm_isdst ? EFI_ISDST : 0;
76 eft->timezone = EFI_UNSPECIFIED_TIMEZONE; 78 eft->timezone = EFI_UNSPECIFIED_TIMEZONE;
@@ -142,7 +144,7 @@ static int efi_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
142 */ 144 */
143 status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft); 145 status = efi.set_wakeup_time((efi_bool_t)wkalrm->enabled, &eft);
144 146
145 printk(KERN_WARNING "write status is %d\n", (int)status); 147 dev_warn(dev, "write status is %d\n", (int)status);
146 148
147 return status == EFI_SUCCESS ? 0 : -EINVAL; 149 return status == EFI_SUCCESS ? 0 : -EINVAL;
148} 150}
@@ -157,7 +159,7 @@ static int efi_read_time(struct device *dev, struct rtc_time *tm)
157 159
158 if (status != EFI_SUCCESS) { 160 if (status != EFI_SUCCESS) {
159 /* should never happen */ 161 /* should never happen */
160 printk(KERN_ERR "efitime: can't read time\n"); 162 dev_err(dev, "can't read time\n");
161 return -EINVAL; 163 return -EINVAL;
162 } 164 }
163 165
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 9602278ff988..1a4e5e4a70cd 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -127,7 +127,7 @@ static const struct attribute_group ep93xx_rtc_sysfs_files = {
127 .attrs = ep93xx_rtc_attrs, 127 .attrs = ep93xx_rtc_attrs,
128}; 128};
129 129
130static int __devinit ep93xx_rtc_probe(struct platform_device *pdev) 130static int ep93xx_rtc_probe(struct platform_device *pdev)
131{ 131{
132 struct ep93xx_rtc *ep93xx_rtc; 132 struct ep93xx_rtc *ep93xx_rtc;
133 struct resource *res; 133 struct resource *res;
@@ -174,7 +174,7 @@ exit:
174 return err; 174 return err;
175} 175}
176 176
177static int __devexit ep93xx_rtc_remove(struct platform_device *pdev) 177static int ep93xx_rtc_remove(struct platform_device *pdev)
178{ 178{
179 struct ep93xx_rtc *ep93xx_rtc = platform_get_drvdata(pdev); 179 struct ep93xx_rtc *ep93xx_rtc = platform_get_drvdata(pdev);
180 180
@@ -192,7 +192,7 @@ static struct platform_driver ep93xx_rtc_driver = {
192 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
193 }, 193 },
194 .probe = ep93xx_rtc_probe, 194 .probe = ep93xx_rtc_probe,
195 .remove = __devexit_p(ep93xx_rtc_remove), 195 .remove = ep93xx_rtc_remove,
196}; 196};
197 197
198module_platform_driver(ep93xx_rtc_driver); 198module_platform_driver(ep93xx_rtc_driver);
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index 86b6ecce99f0..bff3cdc5140e 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -116,17 +116,7 @@ static int fm3130_get_time(struct device *dev, struct rtc_time *t)
116 116
117 fm3130_rtc_mode(dev, FM3130_MODE_NORMAL); 117 fm3130_rtc_mode(dev, FM3130_MODE_NORMAL);
118 118
119 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x %02x" 119 dev_dbg(dev, "%s: %15ph\n", "read", fm3130->regs);
120 "%02x %02x %02x %02x %02x %02x %02x\n",
121 "read",
122 fm3130->regs[0], fm3130->regs[1],
123 fm3130->regs[2], fm3130->regs[3],
124 fm3130->regs[4], fm3130->regs[5],
125 fm3130->regs[6], fm3130->regs[7],
126 fm3130->regs[8], fm3130->regs[9],
127 fm3130->regs[0xa], fm3130->regs[0xb],
128 fm3130->regs[0xc], fm3130->regs[0xd],
129 fm3130->regs[0xe]);
130 120
131 t->tm_sec = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f); 121 t->tm_sec = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
132 t->tm_min = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); 122 t->tm_min = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
@@ -175,12 +165,7 @@ static int fm3130_set_time(struct device *dev, struct rtc_time *t)
175 tmp = t->tm_year - 100; 165 tmp = t->tm_year - 100;
176 buf[FM3130_RTC_YEARS] = bin2bcd(tmp); 166 buf[FM3130_RTC_YEARS] = bin2bcd(tmp);
177 167
178 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x" 168 dev_dbg(dev, "%s: %15ph\n", "write", buf);
179 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
180 "write", buf[0], buf[1], buf[2], buf[3],
181 buf[4], buf[5], buf[6], buf[7],
182 buf[8], buf[9], buf[0xa], buf[0xb],
183 buf[0xc], buf[0xd], buf[0xe]);
184 169
185 fm3130_rtc_mode(dev, FM3130_MODE_WRITE); 170 fm3130_rtc_mode(dev, FM3130_MODE_WRITE);
186 171
@@ -361,8 +346,8 @@ static const struct rtc_class_ops fm3130_rtc_ops = {
361 346
362static struct i2c_driver fm3130_driver; 347static struct i2c_driver fm3130_driver;
363 348
364static int __devinit fm3130_probe(struct i2c_client *client, 349static int fm3130_probe(struct i2c_client *client,
365 const struct i2c_device_id *id) 350 const struct i2c_device_id *id)
366{ 351{
367 struct fm3130 *fm3130; 352 struct fm3130 *fm3130;
368 int err = -ENODEV; 353 int err = -ENODEV;
@@ -517,18 +502,8 @@ bad_alarm:
517bad_clock: 502bad_clock:
518 503
519 if (!fm3130->data_valid || !fm3130->alarm_valid) 504 if (!fm3130->data_valid || !fm3130->alarm_valid)
520 dev_dbg(&client->dev, 505 dev_dbg(&client->dev, "%s: %15ph\n", "bogus registers",
521 "%s: %02x %02x %02x %02x %02x %02x %02x %02x" 506 fm3130->regs);
522 "%02x %02x %02x %02x %02x %02x %02x\n",
523 "bogus registers",
524 fm3130->regs[0], fm3130->regs[1],
525 fm3130->regs[2], fm3130->regs[3],
526 fm3130->regs[4], fm3130->regs[5],
527 fm3130->regs[6], fm3130->regs[7],
528 fm3130->regs[8], fm3130->regs[9],
529 fm3130->regs[0xa], fm3130->regs[0xb],
530 fm3130->regs[0xc], fm3130->regs[0xd],
531 fm3130->regs[0xe]);
532 507
533 /* We won't bail out here because we just got invalid data. 508 /* We won't bail out here because we just got invalid data.
534 Time setting from u-boot doesn't work anyway */ 509 Time setting from u-boot doesn't work anyway */
@@ -546,7 +521,7 @@ exit_free:
546 return err; 521 return err;
547} 522}
548 523
549static int __devexit fm3130_remove(struct i2c_client *client) 524static int fm3130_remove(struct i2c_client *client)
550{ 525{
551 struct fm3130 *fm3130 = i2c_get_clientdata(client); 526 struct fm3130 *fm3130 = i2c_get_clientdata(client);
552 527
@@ -561,7 +536,7 @@ static struct i2c_driver fm3130_driver = {
561 .owner = THIS_MODULE, 536 .owner = THIS_MODULE,
562 }, 537 },
563 .probe = fm3130_probe, 538 .probe = fm3130_probe,
564 .remove = __devexit_p(fm3130_remove), 539 .remove = fm3130_remove,
565 .id_table = fm3130_id, 540 .id_table = fm3130_id,
566}; 541};
567 542
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 000000000000..31c5728ef629
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,292 @@
1/*
2 * HID Sensor Time Driver
3 * Copyright (c) 2012, Alexander Holler.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/module.h>
22#include <linux/hid-sensor-hub.h>
23#include <linux/iio/iio.h>
24#include <linux/rtc.h>
25
26/* Format: HID-SENSOR-usage_id_in_hex */
27/* Usage ID from spec for Time: 0x2000A0 */
28#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
29
30enum hid_time_channel {
31 CHANNEL_SCAN_INDEX_YEAR,
32 CHANNEL_SCAN_INDEX_MONTH,
33 CHANNEL_SCAN_INDEX_DAY,
34 CHANNEL_SCAN_INDEX_HOUR,
35 CHANNEL_SCAN_INDEX_MINUTE,
36 CHANNEL_SCAN_INDEX_SECOND,
37 TIME_RTC_CHANNEL_MAX,
38};
39
40struct hid_time_state {
41 struct hid_sensor_hub_callbacks callbacks;
42 struct hid_sensor_common common_attributes;
43 struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
44 struct rtc_time last_time;
45 spinlock_t lock_last_time;
46 struct completion comp_last_time;
47 struct rtc_time time_buf;
48 struct rtc_device *rtc;
49};
50
51static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
52 HID_USAGE_SENSOR_TIME_YEAR,
53 HID_USAGE_SENSOR_TIME_MONTH,
54 HID_USAGE_SENSOR_TIME_DAY,
55 HID_USAGE_SENSOR_TIME_HOUR,
56 HID_USAGE_SENSOR_TIME_MINUTE,
57 HID_USAGE_SENSOR_TIME_SECOND,
58};
59
60/* Channel names for verbose error messages */
61static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
62 "year", "month", "day", "hour", "minute", "second",
63};
64
65/* Callback handler to send event after all samples are received and captured */
66static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
67 unsigned usage_id, void *priv)
68{
69 unsigned long flags;
70 struct hid_time_state *time_state = platform_get_drvdata(priv);
71
72 spin_lock_irqsave(&time_state->lock_last_time, flags);
73 time_state->last_time = time_state->time_buf;
74 spin_unlock_irqrestore(&time_state->lock_last_time, flags);
75 complete(&time_state->comp_last_time);
76 return 0;
77}
78
79static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
80 unsigned usage_id, size_t raw_len,
81 char *raw_data, void *priv)
82{
83 struct hid_time_state *time_state = platform_get_drvdata(priv);
84 struct rtc_time *time_buf = &time_state->time_buf;
85
86 switch (usage_id) {
87 case HID_USAGE_SENSOR_TIME_YEAR:
88 time_buf->tm_year = *(u8 *)raw_data;
89 if (time_buf->tm_year < 70)
90 /* assume we are in 1970...2069 */
91 time_buf->tm_year += 100;
92 break;
93 case HID_USAGE_SENSOR_TIME_MONTH:
94 /* sensor sending the month as 1-12, we need 0-11 */
95 time_buf->tm_mon = *(u8 *)raw_data-1;
96 break;
97 case HID_USAGE_SENSOR_TIME_DAY:
98 time_buf->tm_mday = *(u8 *)raw_data;
99 break;
100 case HID_USAGE_SENSOR_TIME_HOUR:
101 time_buf->tm_hour = *(u8 *)raw_data;
102 break;
103 case HID_USAGE_SENSOR_TIME_MINUTE:
104 time_buf->tm_min = *(u8 *)raw_data;
105 break;
106 case HID_USAGE_SENSOR_TIME_SECOND:
107 time_buf->tm_sec = *(u8 *)raw_data;
108 break;
109 default:
110 return -EINVAL;
111 }
112 return 0;
113}
114
115/* small helper, haven't found any other way */
116static const char *hid_time_attrib_name(u32 attrib_id)
117{
118 static const char unknown[] = "unknown";
119 unsigned i;
120
121 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
122 if (hid_time_addresses[i] == attrib_id)
123 return hid_time_channel_names[i];
124 }
125 return unknown; /* should never happen */
126}
127
128static int hid_time_parse_report(struct platform_device *pdev,
129 struct hid_sensor_hub_device *hsdev,
130 unsigned usage_id,
131 struct hid_time_state *time_state)
132{
133 int report_id, i;
134
135 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
136 if (sensor_hub_input_get_attribute_info(hsdev,
137 HID_INPUT_REPORT, usage_id,
138 hid_time_addresses[i],
139 &time_state->info[i]) < 0)
140 return -EINVAL;
141 /* Check the (needed) attributes for sanity */
142 report_id = time_state->info[0].report_id;
143 if (report_id < 0) {
144 dev_err(&pdev->dev, "bad report ID!\n");
145 return -EINVAL;
146 }
147 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
148 if (time_state->info[i].report_id != report_id) {
149 dev_err(&pdev->dev,
150 "not all needed attributes inside the same report!\n");
151 return -EINVAL;
152 }
153 if (time_state->info[i].size != 1) {
154 dev_err(&pdev->dev,
155 "attribute '%s' not 8 bits wide!\n",
156 hid_time_attrib_name(
157 time_state->info[i].attrib_id));
158 return -EINVAL;
159 }
160 if (time_state->info[i].units !=
161 HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
162 /* allow attribute seconds with unit seconds */
163 !(time_state->info[i].attrib_id ==
164 HID_USAGE_SENSOR_TIME_SECOND &&
165 time_state->info[i].units ==
166 HID_USAGE_SENSOR_UNITS_SECOND)) {
167 dev_err(&pdev->dev,
168 "attribute '%s' hasn't a unit of type 'none'!\n",
169 hid_time_attrib_name(
170 time_state->info[i].attrib_id));
171 return -EINVAL;
172 }
173 if (time_state->info[i].unit_expo) {
174 dev_err(&pdev->dev,
175 "attribute '%s' hasn't a unit exponent of 1!\n",
176 hid_time_attrib_name(
177 time_state->info[i].attrib_id));
178 return -EINVAL;
179 }
180 }
181
182 return 0;
183}
184
185static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
186{
187 unsigned long flags;
188 struct hid_time_state *time_state =
189 platform_get_drvdata(to_platform_device(dev));
190 int ret;
191
192 INIT_COMPLETION(time_state->comp_last_time);
193 /* get a report with all values through requesting one value */
194 sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
195 HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
196 time_state->info[0].report_id);
197 /* wait for all values (event) */
198 ret = wait_for_completion_killable_timeout(
199 &time_state->comp_last_time, HZ*6);
200 if (ret > 0) {
201 /* no error */
202 spin_lock_irqsave(&time_state->lock_last_time, flags);
203 *tm = time_state->last_time;
204 spin_unlock_irqrestore(&time_state->lock_last_time, flags);
205 return 0;
206 }
207 if (!ret)
208 return -EIO; /* timeouted */
209 return ret; /* killed (-ERESTARTSYS) */
210}
211
212static const struct rtc_class_ops hid_time_rtc_ops = {
213 .read_time = hid_rtc_read_time,
214};
215
216static int hid_time_probe(struct platform_device *pdev)
217{
218 int ret = 0;
219 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
220 struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
221 sizeof(struct hid_time_state), GFP_KERNEL);
222
223 if (time_state == NULL)
224 return -ENOMEM;
225
226 platform_set_drvdata(pdev, time_state);
227
228 spin_lock_init(&time_state->lock_last_time);
229 init_completion(&time_state->comp_last_time);
230 time_state->common_attributes.hsdev = hsdev;
231 time_state->common_attributes.pdev = pdev;
232
233 ret = hid_sensor_parse_common_attributes(hsdev,
234 HID_USAGE_SENSOR_TIME,
235 &time_state->common_attributes);
236 if (ret) {
237 dev_err(&pdev->dev, "failed to setup common attributes!\n");
238 return ret;
239 }
240
241 ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
242 time_state);
243 if (ret) {
244 dev_err(&pdev->dev, "failed to setup attributes!\n");
245 return ret;
246 }
247
248 time_state->callbacks.send_event = hid_time_proc_event;
249 time_state->callbacks.capture_sample = hid_time_capture_sample;
250 time_state->callbacks.pdev = pdev;
251 ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
252 &time_state->callbacks);
253 if (ret < 0) {
254 dev_err(&pdev->dev, "register callback failed!\n");
255 return ret;
256 }
257
258 time_state->rtc = rtc_device_register("hid-sensor-time",
259 &pdev->dev, &hid_time_rtc_ops, THIS_MODULE);
260
261 if (IS_ERR(time_state->rtc)) {
262 dev_err(&pdev->dev, "rtc device register failed!\n");
263 return PTR_ERR(time_state->rtc);
264 }
265
266 return ret;
267}
268
269static int hid_time_remove(struct platform_device *pdev)
270{
271 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
272 struct hid_time_state *time_state = platform_get_drvdata(pdev);
273
274 rtc_device_unregister(time_state->rtc);
275 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
276
277 return 0;
278}
279
280static struct platform_driver hid_time_platform_driver = {
281 .driver = {
282 .name = DRIVER_NAME,
283 .owner = THIS_MODULE,
284 },
285 .probe = hid_time_probe,
286 .remove = hid_time_remove,
287};
288module_platform_driver(hid_time_platform_driver);
289
290MODULE_DESCRIPTION("HID Sensor Time");
291MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
292MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
index 4eed51044c5d..82aad695979e 100644
--- a/drivers/rtc/rtc-imxdi.c
+++ b/drivers/rtc/rtc-imxdi.c
@@ -36,7 +36,9 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/rtc.h> 37#include <linux/rtc.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/spinlock.h>
39#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/of.h>
40 42
41/* DryIce Register Definitions */ 43/* DryIce Register Definitions */
42 44
@@ -404,7 +406,7 @@ static int dryice_rtc_probe(struct platform_device *pdev)
404 406
405 mutex_init(&imxdi->write_mutex); 407 mutex_init(&imxdi->write_mutex);
406 408
407 imxdi->clk = clk_get(&pdev->dev, NULL); 409 imxdi->clk = devm_clk_get(&pdev->dev, NULL);
408 if (IS_ERR(imxdi->clk)) 410 if (IS_ERR(imxdi->clk))
409 return PTR_ERR(imxdi->clk); 411 return PTR_ERR(imxdi->clk);
410 clk_prepare_enable(imxdi->clk); 412 clk_prepare_enable(imxdi->clk);
@@ -473,12 +475,11 @@ static int dryice_rtc_probe(struct platform_device *pdev)
473 475
474err: 476err:
475 clk_disable_unprepare(imxdi->clk); 477 clk_disable_unprepare(imxdi->clk);
476 clk_put(imxdi->clk);
477 478
478 return rc; 479 return rc;
479} 480}
480 481
481static int __devexit dryice_rtc_remove(struct platform_device *pdev) 482static int dryice_rtc_remove(struct platform_device *pdev)
482{ 483{
483 struct imxdi_dev *imxdi = platform_get_drvdata(pdev); 484 struct imxdi_dev *imxdi = platform_get_drvdata(pdev);
484 485
@@ -490,17 +491,26 @@ static int __devexit dryice_rtc_remove(struct platform_device *pdev)
490 rtc_device_unregister(imxdi->rtc); 491 rtc_device_unregister(imxdi->rtc);
491 492
492 clk_disable_unprepare(imxdi->clk); 493 clk_disable_unprepare(imxdi->clk);
493 clk_put(imxdi->clk);
494 494
495 return 0; 495 return 0;
496} 496}
497 497
498#ifdef CONFIG_OF
499static const struct of_device_id dryice_dt_ids[] = {
500 { .compatible = "fsl,imx25-rtc" },
501 { /* sentinel */ }
502};
503
504MODULE_DEVICE_TABLE(of, dryice_dt_ids);
505#endif
506
498static struct platform_driver dryice_rtc_driver = { 507static struct platform_driver dryice_rtc_driver = {
499 .driver = { 508 .driver = {
500 .name = "imxdi_rtc", 509 .name = "imxdi_rtc",
501 .owner = THIS_MODULE, 510 .owner = THIS_MODULE,
511 .of_match_table = of_match_ptr(dryice_dt_ids),
502 }, 512 },
503 .remove = __devexit_p(dryice_rtc_remove), 513 .remove = dryice_rtc_remove,
504}; 514};
505 515
506static int __init dryice_rtc_init(void) 516static int __init dryice_rtc_init(void)
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 1850104705c0..6b4298ea683d 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -227,7 +227,7 @@ static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm)
227 buf[ISL12022_REG_SC + i]); 227 buf[ISL12022_REG_SC + i]);
228 if (ret) 228 if (ret)
229 return -EIO; 229 return -EIO;
230 }; 230 }
231 231
232 return 0; 232 return 0;
233} 233}
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index afb7cfa85ccc..c016ad81767a 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -506,6 +506,7 @@ isl1208_rtc_interrupt(int irq, void *data)
506{ 506{
507 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 507 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
508 struct i2c_client *client = data; 508 struct i2c_client *client = data;
509 struct rtc_device *rtc = i2c_get_clientdata(client);
509 int handled = 0, sr, err; 510 int handled = 0, sr, err;
510 511
511 /* 512 /*
@@ -528,6 +529,8 @@ isl1208_rtc_interrupt(int irq, void *data)
528 if (sr & ISL1208_REG_SR_ALM) { 529 if (sr & ISL1208_REG_SR_ALM) {
529 dev_dbg(&client->dev, "alarm!\n"); 530 dev_dbg(&client->dev, "alarm!\n");
530 531
532 rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF);
533
531 /* Clear the alarm */ 534 /* Clear the alarm */
532 sr &= ~ISL1208_REG_SR_ALM; 535 sr &= ~ISL1208_REG_SR_ALM;
533 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, sr); 536 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, sr);
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 1224182d3eab..1e48686ca6d2 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -210,7 +210,7 @@ void jz4740_rtc_poweroff(struct device *dev)
210} 210}
211EXPORT_SYMBOL_GPL(jz4740_rtc_poweroff); 211EXPORT_SYMBOL_GPL(jz4740_rtc_poweroff);
212 212
213static int __devinit jz4740_rtc_probe(struct platform_device *pdev) 213static int jz4740_rtc_probe(struct platform_device *pdev)
214{ 214{
215 int ret; 215 int ret;
216 struct jz4740_rtc *rtc; 216 struct jz4740_rtc *rtc;
@@ -297,7 +297,7 @@ err_free:
297 return ret; 297 return ret;
298} 298}
299 299
300static int __devexit jz4740_rtc_remove(struct platform_device *pdev) 300static int jz4740_rtc_remove(struct platform_device *pdev)
301{ 301{
302 struct jz4740_rtc *rtc = platform_get_drvdata(pdev); 302 struct jz4740_rtc *rtc = platform_get_drvdata(pdev);
303 303
@@ -347,7 +347,7 @@ static const struct dev_pm_ops jz4740_pm_ops = {
347 347
348static struct platform_driver jz4740_rtc_driver = { 348static struct platform_driver jz4740_rtc_driver = {
349 .probe = jz4740_rtc_probe, 349 .probe = jz4740_rtc_probe,
350 .remove = __devexit_p(jz4740_rtc_remove), 350 .remove = jz4740_rtc_remove,
351 .driver = { 351 .driver = {
352 .name = "jz4740-rtc", 352 .name = "jz4740-rtc",
353 .owner = THIS_MODULE, 353 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-lp8788.c b/drivers/rtc/rtc-lp8788.c
new file mode 100644
index 000000000000..9a4631218f41
--- /dev/null
+++ b/drivers/rtc/rtc-lp8788.c
@@ -0,0 +1,338 @@
1/*
2 * TI LP8788 MFD - rtc driver
3 *
4 * Copyright 2012 Texas Instruments
5 *
6 * Author: Milo(Woogyom) Kim <milo.kim@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/err.h>
15#include <linux/irqdomain.h>
16#include <linux/mfd/lp8788.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/rtc.h>
20#include <linux/slab.h>
21
22/* register address */
23#define LP8788_INTEN_3 0x05
24#define LP8788_RTC_UNLOCK 0x64
25#define LP8788_RTC_SEC 0x70
26#define LP8788_ALM1_SEC 0x77
27#define LP8788_ALM1_EN 0x7D
28#define LP8788_ALM2_SEC 0x7E
29#define LP8788_ALM2_EN 0x84
30
31/* mask/shift bits */
32#define LP8788_INT_RTC_ALM1_M BIT(1) /* Addr 05h */
33#define LP8788_INT_RTC_ALM1_S 1
34#define LP8788_INT_RTC_ALM2_M BIT(2) /* Addr 05h */
35#define LP8788_INT_RTC_ALM2_S 2
36#define LP8788_ALM_EN_M BIT(7) /* Addr 7Dh or 84h */
37#define LP8788_ALM_EN_S 7
38
39#define DEFAULT_ALARM_SEL LP8788_ALARM_1
40#define LP8788_MONTH_OFFSET 1
41#define LP8788_BASE_YEAR 2000
42#define MAX_WDAY_BITS 7
43#define LP8788_WDAY_SET 1
44#define RTC_UNLOCK 0x1
45#define RTC_LATCH 0x2
46#define ALARM_IRQ_FLAG (RTC_IRQF | RTC_AF)
47
48enum lp8788_time {
49 LPTIME_SEC,
50 LPTIME_MIN,
51 LPTIME_HOUR,
52 LPTIME_MDAY,
53 LPTIME_MON,
54 LPTIME_YEAR,
55 LPTIME_WDAY,
56 LPTIME_MAX,
57};
58
59struct lp8788_rtc {
60 struct lp8788 *lp;
61 struct rtc_device *rdev;
62 enum lp8788_alarm_sel alarm;
63 int irq;
64};
65
66static const u8 addr_alarm_sec[LP8788_ALARM_MAX] = {
67 LP8788_ALM1_SEC,
68 LP8788_ALM2_SEC,
69};
70
71static const u8 addr_alarm_en[LP8788_ALARM_MAX] = {
72 LP8788_ALM1_EN,
73 LP8788_ALM2_EN,
74};
75
76static const u8 mask_alarm_en[LP8788_ALARM_MAX] = {
77 LP8788_INT_RTC_ALM1_M,
78 LP8788_INT_RTC_ALM2_M,
79};
80
81static const u8 shift_alarm_en[LP8788_ALARM_MAX] = {
82 LP8788_INT_RTC_ALM1_S,
83 LP8788_INT_RTC_ALM2_S,
84};
85
86static int _to_tm_wday(u8 lp8788_wday)
87{
88 int i;
89
90 if (lp8788_wday == 0)
91 return 0;
92
93 /* lookup defined weekday from read register value */
94 for (i = 0; i < MAX_WDAY_BITS; i++) {
95 if ((lp8788_wday >> i) == LP8788_WDAY_SET)
96 break;
97 }
98
99 return i + 1;
100}
101
102static inline int _to_lp8788_wday(int tm_wday)
103{
104 return LP8788_WDAY_SET << (tm_wday - 1);
105}
106
107static void lp8788_rtc_unlock(struct lp8788 *lp)
108{
109 lp8788_write_byte(lp, LP8788_RTC_UNLOCK, RTC_UNLOCK);
110 lp8788_write_byte(lp, LP8788_RTC_UNLOCK, RTC_LATCH);
111}
112
113static int lp8788_rtc_read_time(struct device *dev, struct rtc_time *tm)
114{
115 struct lp8788_rtc *rtc = dev_get_drvdata(dev);
116 struct lp8788 *lp = rtc->lp;
117 u8 data[LPTIME_MAX];
118 int ret;
119
120 lp8788_rtc_unlock(lp);
121
122 ret = lp8788_read_multi_bytes(lp, LP8788_RTC_SEC, data, LPTIME_MAX);
123 if (ret)
124 return ret;
125
126 tm->tm_sec = data[LPTIME_SEC];
127 tm->tm_min = data[LPTIME_MIN];
128 tm->tm_hour = data[LPTIME_HOUR];
129 tm->tm_mday = data[LPTIME_MDAY];
130 tm->tm_mon = data[LPTIME_MON] - LP8788_MONTH_OFFSET;
131 tm->tm_year = data[LPTIME_YEAR] + LP8788_BASE_YEAR - 1900;
132 tm->tm_wday = _to_tm_wday(data[LPTIME_WDAY]);
133
134 return 0;
135}
136
137static int lp8788_rtc_set_time(struct device *dev, struct rtc_time *tm)
138{
139 struct lp8788_rtc *rtc = dev_get_drvdata(dev);
140 struct lp8788 *lp = rtc->lp;
141 u8 data[LPTIME_MAX - 1];
142 int ret, i, year;
143
144 year = tm->tm_year + 1900 - LP8788_BASE_YEAR;
145 if (year < 0) {
146 dev_err(lp->dev, "invalid year: %d\n", year);
147 return -EINVAL;
148 }
149
150 /* because rtc weekday is a readonly register, do not update */
151 data[LPTIME_SEC] = tm->tm_sec;
152 data[LPTIME_MIN] = tm->tm_min;
153 data[LPTIME_HOUR] = tm->tm_hour;
154 data[LPTIME_MDAY] = tm->tm_mday;
155 data[LPTIME_MON] = tm->tm_mon + LP8788_MONTH_OFFSET;
156 data[LPTIME_YEAR] = year;
157
158 for (i = 0; i < ARRAY_SIZE(data); i++) {
159 ret = lp8788_write_byte(lp, LP8788_RTC_SEC + i, data[i]);
160 if (ret)
161 return ret;
162 }
163
164 return 0;
165}
166
167static int lp8788_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
168{
169 struct lp8788_rtc *rtc = dev_get_drvdata(dev);
170 struct lp8788 *lp = rtc->lp;
171 struct rtc_time *tm = &alarm->time;
172 u8 addr, data[LPTIME_MAX];
173 int ret;
174
175 addr = addr_alarm_sec[rtc->alarm];
176 ret = lp8788_read_multi_bytes(lp, addr, data, LPTIME_MAX);
177 if (ret)
178 return ret;
179
180 tm->tm_sec = data[LPTIME_SEC];
181 tm->tm_min = data[LPTIME_MIN];
182 tm->tm_hour = data[LPTIME_HOUR];
183 tm->tm_mday = data[LPTIME_MDAY];
184 tm->tm_mon = data[LPTIME_MON] - LP8788_MONTH_OFFSET;
185 tm->tm_year = data[LPTIME_YEAR] + LP8788_BASE_YEAR - 1900;
186 tm->tm_wday = _to_tm_wday(data[LPTIME_WDAY]);
187 alarm->enabled = data[LPTIME_WDAY] & LP8788_ALM_EN_M;
188
189 return 0;
190}
191
192static int lp8788_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
193{
194 struct lp8788_rtc *rtc = dev_get_drvdata(dev);
195 struct lp8788 *lp = rtc->lp;
196 struct rtc_time *tm = &alarm->time;
197 u8 addr, data[LPTIME_MAX];
198 int ret, i, year;
199
200 year = tm->tm_year + 1900 - LP8788_BASE_YEAR;
201 if (year < 0) {
202 dev_err(lp->dev, "invalid year: %d\n", year);
203 return -EINVAL;
204 }
205
206 data[LPTIME_SEC] = tm->tm_sec;
207 data[LPTIME_MIN] = tm->tm_min;
208 data[LPTIME_HOUR] = tm->tm_hour;
209 data[LPTIME_MDAY] = tm->tm_mday;
210 data[LPTIME_MON] = tm->tm_mon + LP8788_MONTH_OFFSET;
211 data[LPTIME_YEAR] = year;
212 data[LPTIME_WDAY] = _to_lp8788_wday(tm->tm_wday);
213
214 for (i = 0; i < ARRAY_SIZE(data); i++) {
215 addr = addr_alarm_sec[rtc->alarm] + i;
216 ret = lp8788_write_byte(lp, addr, data[i]);
217 if (ret)
218 return ret;
219 }
220
221 alarm->enabled = 1;
222 addr = addr_alarm_en[rtc->alarm];
223
224 return lp8788_update_bits(lp, addr, LP8788_ALM_EN_M,
225 alarm->enabled << LP8788_ALM_EN_S);
226}
227
228static int lp8788_alarm_irq_enable(struct device *dev, unsigned int enable)
229{
230 struct lp8788_rtc *rtc = dev_get_drvdata(dev);
231 struct lp8788 *lp = rtc->lp;
232 u8 mask, shift;
233
234 if (!rtc->irq)
235 return -EIO;
236
237 mask = mask_alarm_en[rtc->alarm];
238 shift = shift_alarm_en[rtc->alarm];
239
240 return lp8788_update_bits(lp, LP8788_INTEN_3, mask, enable << shift);
241}
242
243static const struct rtc_class_ops lp8788_rtc_ops = {
244 .read_time = lp8788_rtc_read_time,
245 .set_time = lp8788_rtc_set_time,
246 .read_alarm = lp8788_read_alarm,
247 .set_alarm = lp8788_set_alarm,
248 .alarm_irq_enable = lp8788_alarm_irq_enable,
249};
250
251static irqreturn_t lp8788_alarm_irq_handler(int irq, void *ptr)
252{
253 struct lp8788_rtc *rtc = ptr;
254
255 rtc_update_irq(rtc->rdev, 1, ALARM_IRQ_FLAG);
256 return IRQ_HANDLED;
257}
258
259static int lp8788_alarm_irq_register(struct platform_device *pdev,
260 struct lp8788_rtc *rtc)
261{
262 struct resource *r;
263 struct lp8788 *lp = rtc->lp;
264 struct irq_domain *irqdm = lp->irqdm;
265 int irq;
266
267 rtc->irq = 0;
268
269 /* even the alarm IRQ number is not specified, rtc time should work */
270 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, LP8788_ALM_IRQ);
271 if (!r)
272 return 0;
273
274 if (rtc->alarm == LP8788_ALARM_1)
275 irq = r->start;
276 else
277 irq = r->end;
278
279 rtc->irq = irq_create_mapping(irqdm, irq);
280
281 return devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
282 lp8788_alarm_irq_handler,
283 0, LP8788_ALM_IRQ, rtc);
284}
285
286static int lp8788_rtc_probe(struct platform_device *pdev)
287{
288 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
289 struct lp8788_rtc *rtc;
290 struct device *dev = &pdev->dev;
291
292 rtc = devm_kzalloc(dev, sizeof(struct lp8788_rtc), GFP_KERNEL);
293 if (!rtc)
294 return -ENOMEM;
295
296 rtc->lp = lp;
297 rtc->alarm = lp->pdata ? lp->pdata->alarm_sel : DEFAULT_ALARM_SEL;
298 platform_set_drvdata(pdev, rtc);
299
300 device_init_wakeup(dev, 1);
301
302 rtc->rdev = rtc_device_register("lp8788_rtc", dev,
303 &lp8788_rtc_ops, THIS_MODULE);
304 if (IS_ERR(rtc->rdev)) {
305 dev_err(dev, "can not register rtc device\n");
306 return PTR_ERR(rtc->rdev);
307 }
308
309 if (lp8788_alarm_irq_register(pdev, rtc))
310 dev_warn(lp->dev, "no rtc irq handler\n");
311
312 return 0;
313}
314
315static int lp8788_rtc_remove(struct platform_device *pdev)
316{
317 struct lp8788_rtc *rtc = platform_get_drvdata(pdev);
318
319 rtc_device_unregister(rtc->rdev);
320 platform_set_drvdata(pdev, NULL);
321
322 return 0;
323}
324
325static struct platform_driver lp8788_rtc_driver = {
326 .probe = lp8788_rtc_probe,
327 .remove = lp8788_rtc_remove,
328 .driver = {
329 .name = LP8788_DEV_RTC,
330 .owner = THIS_MODULE,
331 },
332};
333module_platform_driver(lp8788_rtc_driver);
334
335MODULE_DESCRIPTION("Texas Instruments LP8788 RTC Driver");
336MODULE_AUTHOR("Milo Kim");
337MODULE_LICENSE("GPL");
338MODULE_ALIAS("platform:lp8788-rtc");
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
index d5218553741f..40a598332bac 100644
--- a/drivers/rtc/rtc-lpc32xx.c
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -197,7 +197,7 @@ static const struct rtc_class_ops lpc32xx_rtc_ops = {
197 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable, 197 .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable,
198}; 198};
199 199
200static int __devinit lpc32xx_rtc_probe(struct platform_device *pdev) 200static int lpc32xx_rtc_probe(struct platform_device *pdev)
201{ 201{
202 struct resource *res; 202 struct resource *res;
203 struct lpc32xx_rtc *rtc; 203 struct lpc32xx_rtc *rtc;
@@ -299,7 +299,7 @@ static int __devinit lpc32xx_rtc_probe(struct platform_device *pdev)
299 return 0; 299 return 0;
300} 300}
301 301
302static int __devexit lpc32xx_rtc_remove(struct platform_device *pdev) 302static int lpc32xx_rtc_remove(struct platform_device *pdev)
303{ 303{
304 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev); 304 struct lpc32xx_rtc *rtc = platform_get_drvdata(pdev);
305 305
@@ -397,7 +397,7 @@ MODULE_DEVICE_TABLE(of, lpc32xx_rtc_match);
397 397
398static struct platform_driver lpc32xx_rtc_driver = { 398static struct platform_driver lpc32xx_rtc_driver = {
399 .probe = lpc32xx_rtc_probe, 399 .probe = lpc32xx_rtc_probe,
400 .remove = __devexit_p(lpc32xx_rtc_remove), 400 .remove = lpc32xx_rtc_remove,
401 .driver = { 401 .driver = {
402 .name = RTC_NAME, 402 .name = RTC_NAME,
403 .owner = THIS_MODULE, 403 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c
index 07e81c5f8247..f59b6349551a 100644
--- a/drivers/rtc/rtc-ls1x.c
+++ b/drivers/rtc/rtc-ls1x.c
@@ -143,7 +143,7 @@ static struct rtc_class_ops ls1x_rtc_ops = {
143 .set_time = ls1x_rtc_set_time, 143 .set_time = ls1x_rtc_set_time,
144}; 144};
145 145
146static int __devinit ls1x_rtc_probe(struct platform_device *pdev) 146static int ls1x_rtc_probe(struct platform_device *pdev)
147{ 147{
148 struct rtc_device *rtcdev; 148 struct rtc_device *rtcdev;
149 unsigned long v; 149 unsigned long v;
@@ -185,7 +185,7 @@ err:
185 return ret; 185 return ret;
186} 186}
187 187
188static int __devexit ls1x_rtc_remove(struct platform_device *pdev) 188static int ls1x_rtc_remove(struct platform_device *pdev)
189{ 189{
190 struct rtc_device *rtcdev = platform_get_drvdata(pdev); 190 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
191 191
@@ -200,7 +200,7 @@ static struct platform_driver ls1x_rtc_driver = {
200 .name = "ls1x-rtc", 200 .name = "ls1x-rtc",
201 .owner = THIS_MODULE, 201 .owner = THIS_MODULE,
202 }, 202 },
203 .remove = __devexit_p(ls1x_rtc_remove), 203 .remove = ls1x_rtc_remove,
204 .probe = ls1x_rtc_probe, 204 .probe = ls1x_rtc_probe,
205}; 205};
206 206
diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c
index efab3d48cb15..49169680786e 100644
--- a/drivers/rtc/rtc-m41t93.c
+++ b/drivers/rtc/rtc-m41t93.c
@@ -170,7 +170,7 @@ static const struct rtc_class_ops m41t93_rtc_ops = {
170 170
171static struct spi_driver m41t93_driver; 171static struct spi_driver m41t93_driver;
172 172
173static int __devinit m41t93_probe(struct spi_device *spi) 173static int m41t93_probe(struct spi_device *spi)
174{ 174{
175 struct rtc_device *rtc; 175 struct rtc_device *rtc;
176 int res; 176 int res;
@@ -195,7 +195,7 @@ static int __devinit m41t93_probe(struct spi_device *spi)
195} 195}
196 196
197 197
198static int __devexit m41t93_remove(struct spi_device *spi) 198static int m41t93_remove(struct spi_device *spi)
199{ 199{
200 struct rtc_device *rtc = spi_get_drvdata(spi); 200 struct rtc_device *rtc = spi_get_drvdata(spi);
201 201
@@ -211,7 +211,7 @@ static struct spi_driver m41t93_driver = {
211 .owner = THIS_MODULE, 211 .owner = THIS_MODULE,
212 }, 212 },
213 .probe = m41t93_probe, 213 .probe = m41t93_probe,
214 .remove = __devexit_p(m41t93_remove), 214 .remove = m41t93_remove,
215}; 215};
216 216
217module_spi_driver(m41t93_driver); 217module_spi_driver(m41t93_driver);
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 6e78193e026b..89266c6764bc 100644
--- a/drivers/rtc/rtc-m41t94.c
+++ b/drivers/rtc/rtc-m41t94.c
@@ -110,7 +110,7 @@ static const struct rtc_class_ops m41t94_rtc_ops = {
110 110
111static struct spi_driver m41t94_driver; 111static struct spi_driver m41t94_driver;
112 112
113static int __devinit m41t94_probe(struct spi_device *spi) 113static int m41t94_probe(struct spi_device *spi)
114{ 114{
115 struct rtc_device *rtc; 115 struct rtc_device *rtc;
116 int res; 116 int res;
@@ -134,7 +134,7 @@ static int __devinit m41t94_probe(struct spi_device *spi)
134 return 0; 134 return 0;
135} 135}
136 136
137static int __devexit m41t94_remove(struct spi_device *spi) 137static int m41t94_remove(struct spi_device *spi)
138{ 138{
139 struct rtc_device *rtc = spi_get_drvdata(spi); 139 struct rtc_device *rtc = spi_get_drvdata(spi);
140 140
@@ -150,7 +150,7 @@ static struct spi_driver m41t94_driver = {
150 .owner = THIS_MODULE, 150 .owner = THIS_MODULE,
151 }, 151 },
152 .probe = m41t94_probe, 152 .probe = m41t94_probe,
153 .remove = __devexit_p(m41t94_remove), 153 .remove = m41t94_remove,
154}; 154};
155 155
156module_spi_driver(m41t94_driver); 156module_spi_driver(m41t94_driver);
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index f9e3b3583733..31c9190a1fcb 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -141,7 +141,7 @@ static const struct rtc_class_ops m48t35_ops = {
141 .set_time = m48t35_set_time, 141 .set_time = m48t35_set_time,
142}; 142};
143 143
144static int __devinit m48t35_probe(struct platform_device *pdev) 144static int m48t35_probe(struct platform_device *pdev)
145{ 145{
146 struct resource *res; 146 struct resource *res;
147 struct m48t35_priv *priv; 147 struct m48t35_priv *priv;
@@ -194,7 +194,7 @@ out:
194 return ret; 194 return ret;
195} 195}
196 196
197static int __devexit m48t35_remove(struct platform_device *pdev) 197static int m48t35_remove(struct platform_device *pdev)
198{ 198{
199 struct m48t35_priv *priv = platform_get_drvdata(pdev); 199 struct m48t35_priv *priv = platform_get_drvdata(pdev);
200 200
@@ -213,7 +213,7 @@ static struct platform_driver m48t35_platform_driver = {
213 .owner = THIS_MODULE, 213 .owner = THIS_MODULE,
214 }, 214 },
215 .probe = m48t35_probe, 215 .probe = m48t35_probe,
216 .remove = __devexit_p(m48t35_remove), 216 .remove = m48t35_remove,
217}; 217};
218 218
219module_platform_driver(m48t35_platform_driver); 219module_platform_driver(m48t35_platform_driver);
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index 30ebfec9fd2b..130f29af3869 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -383,7 +383,7 @@ static struct bin_attribute m48t59_nvram_attr = {
383 .write = m48t59_nvram_write, 383 .write = m48t59_nvram_write,
384}; 384};
385 385
386static int __devinit m48t59_rtc_probe(struct platform_device *pdev) 386static int m48t59_rtc_probe(struct platform_device *pdev)
387{ 387{
388 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 388 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
389 struct m48t59_private *m48t59 = NULL; 389 struct m48t59_private *m48t59 = NULL;
@@ -501,7 +501,7 @@ out:
501 return ret; 501 return ret;
502} 502}
503 503
504static int __devexit m48t59_rtc_remove(struct platform_device *pdev) 504static int m48t59_rtc_remove(struct platform_device *pdev)
505{ 505{
506 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 506 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
507 struct m48t59_plat_data *pdata = pdev->dev.platform_data; 507 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
@@ -527,7 +527,7 @@ static struct platform_driver m48t59_rtc_driver = {
527 .owner = THIS_MODULE, 527 .owner = THIS_MODULE,
528 }, 528 },
529 .probe = m48t59_rtc_probe, 529 .probe = m48t59_rtc_probe,
530 .remove = __devexit_p(m48t59_rtc_remove), 530 .remove = m48t59_rtc_remove,
531}; 531};
532 532
533module_platform_driver(m48t59_rtc_driver); 533module_platform_driver(m48t59_rtc_driver);
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 863fb3363aa6..2ffbcacd2439 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -144,7 +144,7 @@ static const struct rtc_class_ops m48t86_rtc_ops = {
144 .proc = m48t86_rtc_proc, 144 .proc = m48t86_rtc_proc,
145}; 145};
146 146
147static int __devinit m48t86_rtc_probe(struct platform_device *dev) 147static int m48t86_rtc_probe(struct platform_device *dev)
148{ 148{
149 unsigned char reg; 149 unsigned char reg;
150 struct m48t86_ops *ops = dev->dev.platform_data; 150 struct m48t86_ops *ops = dev->dev.platform_data;
@@ -164,7 +164,7 @@ static int __devinit m48t86_rtc_probe(struct platform_device *dev)
164 return 0; 164 return 0;
165} 165}
166 166
167static int __devexit m48t86_rtc_remove(struct platform_device *dev) 167static int m48t86_rtc_remove(struct platform_device *dev)
168{ 168{
169 struct rtc_device *rtc = platform_get_drvdata(dev); 169 struct rtc_device *rtc = platform_get_drvdata(dev);
170 170
@@ -182,7 +182,7 @@ static struct platform_driver m48t86_rtc_platform_driver = {
182 .owner = THIS_MODULE, 182 .owner = THIS_MODULE,
183 }, 183 },
184 .probe = m48t86_rtc_probe, 184 .probe = m48t86_rtc_probe,
185 .remove = __devexit_p(m48t86_rtc_remove), 185 .remove = m48t86_rtc_remove,
186}; 186};
187 187
188module_platform_driver(m48t86_rtc_platform_driver); 188module_platform_driver(m48t86_rtc_platform_driver);
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 36c74d22e8b5..7d0bf698b79e 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -120,7 +120,7 @@ static const struct rtc_class_ops max6902_rtc_ops = {
120 .set_time = max6902_set_time, 120 .set_time = max6902_set_time,
121}; 121};
122 122
123static int __devinit max6902_probe(struct spi_device *spi) 123static int max6902_probe(struct spi_device *spi)
124{ 124{
125 struct rtc_device *rtc; 125 struct rtc_device *rtc;
126 unsigned char tmp; 126 unsigned char tmp;
@@ -143,7 +143,7 @@ static int __devinit max6902_probe(struct spi_device *spi)
143 return 0; 143 return 0;
144} 144}
145 145
146static int __devexit max6902_remove(struct spi_device *spi) 146static int max6902_remove(struct spi_device *spi)
147{ 147{
148 struct rtc_device *rtc = dev_get_drvdata(&spi->dev); 148 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
149 149
@@ -157,7 +157,7 @@ static struct spi_driver max6902_driver = {
157 .owner = THIS_MODULE, 157 .owner = THIS_MODULE,
158 }, 158 },
159 .probe = max6902_probe, 159 .probe = max6902_probe,
160 .remove = __devexit_p(max6902_remove), 160 .remove = max6902_remove,
161}; 161};
162 162
163module_spi_driver(max6902_driver); 163module_spi_driver(max6902_driver);
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
new file mode 100644
index 000000000000..6b1337f9baf4
--- /dev/null
+++ b/drivers/rtc/rtc-max77686.c
@@ -0,0 +1,641 @@
1/*
2 * RTC driver for Maxim MAX77686
3 *
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 *
6 * based on rtc-max8997.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/slab.h>
16#include <linux/rtc.h>
17#include <linux/delay.h>
18#include <linux/mutex.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/max77686-private.h>
22#include <linux/irqdomain.h>
23#include <linux/regmap.h>
24
25/* RTC Control Register */
26#define BCD_EN_SHIFT 0
27#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
28#define MODEL24_SHIFT 1
29#define MODEL24_MASK (1 << MODEL24_SHIFT)
30/* RTC Update Register1 */
31#define RTC_UDR_SHIFT 0
32#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)
33#define RTC_RBUDR_SHIFT 4
34#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
35/* WTSR and SMPL Register */
36#define WTSRT_SHIFT 0
37#define SMPLT_SHIFT 2
38#define WTSR_EN_SHIFT 6
39#define SMPL_EN_SHIFT 7
40#define WTSRT_MASK (3 << WTSRT_SHIFT)
41#define SMPLT_MASK (3 << SMPLT_SHIFT)
42#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT)
43#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT)
44/* RTC Hour register */
45#define HOUR_PM_SHIFT 6
46#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT)
47/* RTC Alarm Enable */
48#define ALARM_ENABLE_SHIFT 7
49#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT)
50
51#define MAX77686_RTC_UPDATE_DELAY 16
52#undef MAX77686_RTC_WTSR_SMPL
53
54enum {
55 RTC_SEC = 0,
56 RTC_MIN,
57 RTC_HOUR,
58 RTC_WEEKDAY,
59 RTC_MONTH,
60 RTC_YEAR,
61 RTC_DATE,
62 RTC_NR_TIME
63};
64
65struct max77686_rtc_info {
66 struct device *dev;
67 struct max77686_dev *max77686;
68 struct i2c_client *rtc;
69 struct rtc_device *rtc_dev;
70 struct mutex lock;
71
72 struct regmap *regmap;
73
74 int virq;
75 int rtc_24hr_mode;
76};
77
78enum MAX77686_RTC_OP {
79 MAX77686_RTC_WRITE,
80 MAX77686_RTC_READ,
81};
82
83static inline int max77686_rtc_calculate_wday(u8 shifted)
84{
85 int counter = -1;
86 while (shifted) {
87 shifted >>= 1;
88 counter++;
89 }
90 return counter;
91}
92
93static void max77686_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
94 int rtc_24hr_mode)
95{
96 tm->tm_sec = data[RTC_SEC] & 0x7f;
97 tm->tm_min = data[RTC_MIN] & 0x7f;
98 if (rtc_24hr_mode)
99 tm->tm_hour = data[RTC_HOUR] & 0x1f;
100 else {
101 tm->tm_hour = data[RTC_HOUR] & 0x0f;
102 if (data[RTC_HOUR] & HOUR_PM_MASK)
103 tm->tm_hour += 12;
104 }
105
106 tm->tm_wday = max77686_rtc_calculate_wday(data[RTC_WEEKDAY] & 0x7f);
107 tm->tm_mday = data[RTC_DATE] & 0x1f;
108 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
109 tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
110 tm->tm_yday = 0;
111 tm->tm_isdst = 0;
112}
113
114static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
115{
116 data[RTC_SEC] = tm->tm_sec;
117 data[RTC_MIN] = tm->tm_min;
118 data[RTC_HOUR] = tm->tm_hour;
119 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
120 data[RTC_DATE] = tm->tm_mday;
121 data[RTC_MONTH] = tm->tm_mon + 1;
122 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0 ;
123
124 if (tm->tm_year < 100) {
125 pr_warn("%s: MAX77686 RTC cannot handle the year %d."
126 "Assume it's 2000.\n", __func__, 1900 + tm->tm_year);
127 return -EINVAL;
128 }
129 return 0;
130}
131
132static int max77686_rtc_update(struct max77686_rtc_info *info,
133 enum MAX77686_RTC_OP op)
134{
135 int ret;
136 unsigned int data;
137
138 if (op == MAX77686_RTC_WRITE)
139 data = 1 << RTC_UDR_SHIFT;
140 else
141 data = 1 << RTC_RBUDR_SHIFT;
142
143 ret = regmap_update_bits(info->max77686->rtc_regmap,
144 MAX77686_RTC_UPDATE0, data, data);
145 if (ret < 0)
146 dev_err(info->dev, "%s: fail to write update reg(ret=%d, data=0x%x)\n",
147 __func__, ret, data);
148 else {
149 /* Minimum 16ms delay required before RTC update. */
150 msleep(MAX77686_RTC_UPDATE_DELAY);
151 }
152
153 return ret;
154}
155
156static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
157{
158 struct max77686_rtc_info *info = dev_get_drvdata(dev);
159 u8 data[RTC_NR_TIME];
160 int ret;
161
162 mutex_lock(&info->lock);
163
164 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
165 if (ret < 0)
166 goto out;
167
168 ret = regmap_bulk_read(info->max77686->rtc_regmap,
169 MAX77686_RTC_SEC, data, RTC_NR_TIME);
170 if (ret < 0) {
171 dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__, ret);
172 goto out;
173 }
174
175 max77686_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
176
177 ret = rtc_valid_tm(tm);
178
179out:
180 mutex_unlock(&info->lock);
181 return ret;
182}
183
184static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
185{
186 struct max77686_rtc_info *info = dev_get_drvdata(dev);
187 u8 data[RTC_NR_TIME];
188 int ret;
189
190 ret = max77686_rtc_tm_to_data(tm, data);
191 if (ret < 0)
192 return ret;
193
194 mutex_lock(&info->lock);
195
196 ret = regmap_bulk_write(info->max77686->rtc_regmap,
197 MAX77686_RTC_SEC, data, RTC_NR_TIME);
198 if (ret < 0) {
199 dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
200 ret);
201 goto out;
202 }
203
204 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
205
206out:
207 mutex_unlock(&info->lock);
208 return ret;
209}
210
211static int max77686_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
212{
213 struct max77686_rtc_info *info = dev_get_drvdata(dev);
214 u8 data[RTC_NR_TIME];
215 unsigned int val;
216 int i, ret;
217
218 mutex_lock(&info->lock);
219
220 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
221 if (ret < 0)
222 goto out;
223
224 ret = regmap_bulk_read(info->max77686->rtc_regmap,
225 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
226 if (ret < 0) {
227 dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
228 __func__, __LINE__, ret);
229 goto out;
230 }
231
232 max77686_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
233
234 alrm->enabled = 0;
235 for (i = 0; i < RTC_NR_TIME; i++) {
236 if (data[i] & ALARM_ENABLE_MASK) {
237 alrm->enabled = 1;
238 break;
239 }
240 }
241
242 alrm->pending = 0;
243 ret = regmap_read(info->max77686->regmap, MAX77686_REG_STATUS1, &val);
244 if (ret < 0) {
245 dev_err(info->dev, "%s:%d fail to read status1 reg(%d)\n",
246 __func__, __LINE__, ret);
247 goto out;
248 }
249
250 if (val & (1 << 4)) /* RTCA1 */
251 alrm->pending = 1;
252
253out:
254 mutex_unlock(&info->lock);
255 return 0;
256}
257
258static int max77686_rtc_stop_alarm(struct max77686_rtc_info *info)
259{
260 u8 data[RTC_NR_TIME];
261 int ret, i;
262 struct rtc_time tm;
263
264 if (!mutex_is_locked(&info->lock))
265 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
266
267 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
268 if (ret < 0)
269 goto out;
270
271 ret = regmap_bulk_read(info->max77686->rtc_regmap,
272 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
273 if (ret < 0) {
274 dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
275 __func__, ret);
276 goto out;
277 }
278
279 max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
280
281 for (i = 0; i < RTC_NR_TIME; i++)
282 data[i] &= ~ALARM_ENABLE_MASK;
283
284 ret = regmap_bulk_write(info->max77686->rtc_regmap,
285 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
286 if (ret < 0) {
287 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
288 __func__, ret);
289 goto out;
290 }
291
292 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
293out:
294 return ret;
295}
296
297static int max77686_rtc_start_alarm(struct max77686_rtc_info *info)
298{
299 u8 data[RTC_NR_TIME];
300 int ret;
301 struct rtc_time tm;
302
303 if (!mutex_is_locked(&info->lock))
304 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
305
306 ret = max77686_rtc_update(info, MAX77686_RTC_READ);
307 if (ret < 0)
308 goto out;
309
310 ret = regmap_bulk_read(info->max77686->rtc_regmap,
311 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
312 if (ret < 0) {
313 dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
314 __func__, ret);
315 goto out;
316 }
317
318 max77686_rtc_data_to_tm(data, &tm, info->rtc_24hr_mode);
319
320 data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
321 data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
322 data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
323 data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
324 if (data[RTC_MONTH] & 0xf)
325 data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
326 if (data[RTC_YEAR] & 0x7f)
327 data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
328 if (data[RTC_DATE] & 0x1f)
329 data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
330
331 ret = regmap_bulk_write(info->max77686->rtc_regmap,
332 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
333 if (ret < 0) {
334 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
335 __func__, ret);
336 goto out;
337 }
338
339 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
340out:
341 return ret;
342}
343
344static int max77686_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
345{
346 struct max77686_rtc_info *info = dev_get_drvdata(dev);
347 u8 data[RTC_NR_TIME];
348 int ret;
349
350 ret = max77686_rtc_tm_to_data(&alrm->time, data);
351 if (ret < 0)
352 return ret;
353
354 mutex_lock(&info->lock);
355
356 ret = max77686_rtc_stop_alarm(info);
357 if (ret < 0)
358 goto out;
359
360 ret = regmap_bulk_write(info->max77686->rtc_regmap,
361 MAX77686_ALARM1_SEC, data, RTC_NR_TIME);
362
363 if (ret < 0) {
364 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
365 __func__, ret);
366 goto out;
367 }
368
369 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
370 if (ret < 0)
371 goto out;
372
373 if (alrm->enabled)
374 ret = max77686_rtc_start_alarm(info);
375out:
376 mutex_unlock(&info->lock);
377 return ret;
378}
379
380static int max77686_rtc_alarm_irq_enable(struct device *dev,
381 unsigned int enabled)
382{
383 struct max77686_rtc_info *info = dev_get_drvdata(dev);
384 int ret;
385
386 mutex_lock(&info->lock);
387 if (enabled)
388 ret = max77686_rtc_start_alarm(info);
389 else
390 ret = max77686_rtc_stop_alarm(info);
391 mutex_unlock(&info->lock);
392
393 return ret;
394}
395
396static irqreturn_t max77686_rtc_alarm_irq(int irq, void *data)
397{
398 struct max77686_rtc_info *info = data;
399
400 dev_info(info->dev, "%s:irq(%d)\n", __func__, irq);
401
402 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
403
404 return IRQ_HANDLED;
405}
406
407static const struct rtc_class_ops max77686_rtc_ops = {
408 .read_time = max77686_rtc_read_time,
409 .set_time = max77686_rtc_set_time,
410 .read_alarm = max77686_rtc_read_alarm,
411 .set_alarm = max77686_rtc_set_alarm,
412 .alarm_irq_enable = max77686_rtc_alarm_irq_enable,
413};
414
415#ifdef MAX77686_RTC_WTSR_SMPL
416static void max77686_rtc_enable_wtsr(struct max77686_rtc_info *info, bool enable)
417{
418 int ret;
419 unsigned int val, mask;
420
421 if (enable)
422 val = (1 << WTSR_EN_SHIFT) | (3 << WTSRT_SHIFT);
423 else
424 val = 0;
425
426 mask = WTSR_EN_MASK | WTSRT_MASK;
427
428 dev_info(info->dev, "%s: %s WTSR\n", __func__,
429 enable ? "enable" : "disable");
430
431 ret = regmap_update_bits(info->max77686->rtc_regmap,
432 MAX77686_WTSR_SMPL_CNTL, mask, val);
433 if (ret < 0) {
434 dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
435 __func__, ret);
436 return;
437 }
438
439 max77686_rtc_update(info, MAX77686_RTC_WRITE);
440}
441
442static void max77686_rtc_enable_smpl(struct max77686_rtc_info *info, bool enable)
443{
444 int ret;
445 unsigned int val, mask;
446
447 if (enable)
448 val = (1 << SMPL_EN_SHIFT) | (0 << SMPLT_SHIFT);
449 else
450 val = 0;
451
452 mask = SMPL_EN_MASK | SMPLT_MASK;
453
454 dev_info(info->dev, "%s: %s SMPL\n", __func__,
455 enable ? "enable" : "disable");
456
457 ret = regmap_update_bits(info->max77686->rtc_regmap,
458 MAX77686_WTSR_SMPL_CNTL, mask, val);
459 if (ret < 0) {
460 dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
461 __func__, ret);
462 return;
463 }
464
465 max77686_rtc_update(info, MAX77686_RTC_WRITE);
466
467 val = 0;
468 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
469 pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val);
470}
471#endif /* MAX77686_RTC_WTSR_SMPL */
472
473static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
474{
475 u8 data[2];
476 int ret;
477
478 /* Set RTC control register : Binary mode, 24hour mdoe */
479 data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
480 data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
481
482 info->rtc_24hr_mode = 1;
483
484 ret = regmap_bulk_write(info->max77686->rtc_regmap, MAX77686_RTC_CONTROLM, data, 2);
485 if (ret < 0) {
486 dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
487 __func__, ret);
488 return ret;
489 }
490
491 ret = max77686_rtc_update(info, MAX77686_RTC_WRITE);
492 return ret;
493}
494
495static struct regmap_config max77686_rtc_regmap_config = {
496 .reg_bits = 8,
497 .val_bits = 8,
498};
499
500static int max77686_rtc_probe(struct platform_device *pdev)
501{
502 struct max77686_dev *max77686 = dev_get_drvdata(pdev->dev.parent);
503 struct max77686_rtc_info *info;
504 int ret, virq;
505
506 dev_info(&pdev->dev, "%s\n", __func__);
507
508 info = kzalloc(sizeof(struct max77686_rtc_info), GFP_KERNEL);
509 if (!info)
510 return -ENOMEM;
511
512 mutex_init(&info->lock);
513 info->dev = &pdev->dev;
514 info->max77686 = max77686;
515 info->rtc = max77686->rtc;
516 info->max77686->rtc_regmap = regmap_init_i2c(info->max77686->rtc,
517 &max77686_rtc_regmap_config);
518 if (IS_ERR(info->max77686->rtc_regmap)) {
519 ret = PTR_ERR(info->max77686->rtc_regmap);
520 dev_err(info->max77686->dev, "Failed to allocate register map: %d\n",
521 ret);
522 kfree(info);
523 return ret;
524 }
525 platform_set_drvdata(pdev, info);
526
527 ret = max77686_rtc_init_reg(info);
528
529 if (ret < 0) {
530 dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
531 goto err_rtc;
532 }
533
534#ifdef MAX77686_RTC_WTSR_SMPL
535 max77686_rtc_enable_wtsr(info, true);
536 max77686_rtc_enable_smpl(info, true);
537#endif
538
539 device_init_wakeup(&pdev->dev, 1);
540
541 info->rtc_dev = rtc_device_register("max77686-rtc", &pdev->dev,
542 &max77686_rtc_ops, THIS_MODULE);
543
544 if (IS_ERR(info->rtc_dev)) {
545 dev_info(&pdev->dev, "%s: fail\n", __func__);
546
547 ret = PTR_ERR(info->rtc_dev);
548 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
549 if (ret == 0)
550 ret = -EINVAL;
551 goto err_rtc;
552 }
553 virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1);
554 if (!virq)
555 goto err_rtc;
556 info->virq = virq;
557
558 ret = request_threaded_irq(virq, NULL, max77686_rtc_alarm_irq, 0,
559 "rtc-alarm0", info);
560 if (ret < 0) {
561 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
562 info->virq, ret);
563 goto err_rtc;
564 }
565
566 goto out;
567err_rtc:
568 kfree(info);
569 return ret;
570out:
571 return ret;
572}
573
574static int max77686_rtc_remove(struct platform_device *pdev)
575{
576 struct max77686_rtc_info *info = platform_get_drvdata(pdev);
577
578 if (info) {
579 free_irq(info->virq, info);
580 rtc_device_unregister(info->rtc_dev);
581 kfree(info);
582 }
583
584 return 0;
585}
586
587static void max77686_rtc_shutdown(struct platform_device *pdev)
588{
589#ifdef MAX77686_RTC_WTSR_SMPL
590 struct max77686_rtc_info *info = platform_get_drvdata(pdev);
591 int i;
592 u8 val = 0;
593
594 for (i = 0; i < 3; i++) {
595 max77686_rtc_enable_wtsr(info, false);
596 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
597 pr_info("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val);
598 if (val & WTSR_EN_MASK)
599 pr_emerg("%s: fail to disable WTSR\n", __func__);
600 else {
601 pr_info("%s: success to disable WTSR\n", __func__);
602 break;
603 }
604 }
605
606 /* Disable SMPL when power off */
607 max77686_rtc_enable_smpl(info, false);
608#endif /* MAX77686_RTC_WTSR_SMPL */
609}
610
611static const struct platform_device_id rtc_id[] = {
612 { "max77686-rtc", 0 },
613 {},
614};
615
616static struct platform_driver max77686_rtc_driver = {
617 .driver = {
618 .name = "max77686-rtc",
619 .owner = THIS_MODULE,
620 },
621 .probe = max77686_rtc_probe,
622 .remove = max77686_rtc_remove,
623 .shutdown = max77686_rtc_shutdown,
624 .id_table = rtc_id,
625};
626
627static int __init max77686_rtc_init(void)
628{
629 return platform_driver_register(&max77686_rtc_driver);
630}
631module_init(max77686_rtc_init);
632
633static void __exit max77686_rtc_exit(void)
634{
635 platform_driver_unregister(&max77686_rtc_driver);
636}
637module_exit(max77686_rtc_exit);
638
639MODULE_DESCRIPTION("Maxim MAX77686 RTC driver");
640MODULE_AUTHOR("<woong.byun@samsung.com>");
641MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
index e094ffa434f8..31ca8faf9f05 100644
--- a/drivers/rtc/rtc-max8907.c
+++ b/drivers/rtc/rtc-max8907.c
@@ -176,7 +176,7 @@ static const struct rtc_class_ops max8907_rtc_ops = {
176 .set_alarm = max8907_rtc_set_alarm, 176 .set_alarm = max8907_rtc_set_alarm,
177}; 177};
178 178
179static int __devinit max8907_rtc_probe(struct platform_device *pdev) 179static int max8907_rtc_probe(struct platform_device *pdev)
180{ 180{
181 struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent); 181 struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent);
182 struct max8907_rtc *rtc; 182 struct max8907_rtc *rtc;
@@ -205,8 +205,9 @@ static int __devinit max8907_rtc_probe(struct platform_device *pdev)
205 goto err_unregister; 205 goto err_unregister;
206 } 206 }
207 207
208 ret = request_threaded_irq(rtc->irq, NULL, max8907_irq_handler, 208 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
209 IRQF_ONESHOT, "max8907-alarm0", rtc); 209 max8907_irq_handler,
210 IRQF_ONESHOT, "max8907-alarm0", rtc);
210 if (ret < 0) { 211 if (ret < 0) {
211 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n", 212 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n",
212 rtc->irq, ret); 213 rtc->irq, ret);
@@ -220,11 +221,10 @@ err_unregister:
220 return ret; 221 return ret;
221} 222}
222 223
223static int __devexit max8907_rtc_remove(struct platform_device *pdev) 224static int max8907_rtc_remove(struct platform_device *pdev)
224{ 225{
225 struct max8907_rtc *rtc = platform_get_drvdata(pdev); 226 struct max8907_rtc *rtc = platform_get_drvdata(pdev);
226 227
227 free_irq(rtc->irq, rtc);
228 rtc_device_unregister(rtc->rtc_dev); 228 rtc_device_unregister(rtc->rtc_dev);
229 229
230 return 0; 230 return 0;
@@ -236,7 +236,7 @@ static struct platform_driver max8907_rtc_driver = {
236 .owner = THIS_MODULE, 236 .owner = THIS_MODULE,
237 }, 237 },
238 .probe = max8907_rtc_probe, 238 .probe = max8907_rtc_probe,
239 .remove = __devexit_p(max8907_rtc_remove), 239 .remove = max8907_rtc_remove,
240}; 240};
241module_platform_driver(max8907_rtc_driver); 241module_platform_driver(max8907_rtc_driver);
242 242
diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index 34e4349611db..a0c8265646d2 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -247,7 +247,7 @@ static const struct rtc_class_ops max8925_rtc_ops = {
247 .set_alarm = max8925_rtc_set_alarm, 247 .set_alarm = max8925_rtc_set_alarm,
248}; 248};
249 249
250static int __devinit max8925_rtc_probe(struct platform_device *pdev) 250static int max8925_rtc_probe(struct platform_device *pdev)
251{ 251{
252 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); 252 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
253 struct max8925_rtc_info *info; 253 struct max8925_rtc_info *info;
@@ -292,7 +292,7 @@ out_irq:
292 return ret; 292 return ret;
293} 293}
294 294
295static int __devexit max8925_rtc_remove(struct platform_device *pdev) 295static int max8925_rtc_remove(struct platform_device *pdev)
296{ 296{
297 struct max8925_rtc_info *info = platform_get_drvdata(pdev); 297 struct max8925_rtc_info *info = platform_get_drvdata(pdev);
298 298
@@ -334,7 +334,7 @@ static struct platform_driver max8925_rtc_driver = {
334 .pm = &max8925_rtc_pm_ops, 334 .pm = &max8925_rtc_pm_ops,
335 }, 335 },
336 .probe = max8925_rtc_probe, 336 .probe = max8925_rtc_probe,
337 .remove = __devexit_p(max8925_rtc_remove), 337 .remove = max8925_rtc_remove,
338}; 338};
339 339
340module_platform_driver(max8925_rtc_driver); 340module_platform_driver(max8925_rtc_driver);
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
new file mode 100644
index 000000000000..00e505b6bee3
--- /dev/null
+++ b/drivers/rtc/rtc-max8997.c
@@ -0,0 +1,552 @@
1/*
2 * RTC driver for Maxim MAX8997
3 *
4 * Copyright (C) 2013 Samsung Electronics Co.Ltd
5 *
6 * based on rtc-max8998.c
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/slab.h>
16#include <linux/rtc.h>
17#include <linux/delay.h>
18#include <linux/mutex.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/max8997-private.h>
22#include <linux/irqdomain.h>
23
24/* Module parameter for WTSR function control */
25static int wtsr_en = 1;
26module_param(wtsr_en, int, 0444);
27MODULE_PARM_DESC(wtsr_en, "Wachdog Timeout & Sofware Reset (default=on)");
28/* Module parameter for SMPL function control */
29static int smpl_en = 1;
30module_param(smpl_en, int, 0444);
31MODULE_PARM_DESC(smpl_en, "Sudden Momentary Power Loss (default=on)");
32
33/* RTC Control Register */
34#define BCD_EN_SHIFT 0
35#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
36#define MODEL24_SHIFT 1
37#define MODEL24_MASK (1 << MODEL24_SHIFT)
38/* RTC Update Register1 */
39#define RTC_UDR_SHIFT 0
40#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)
41/* WTSR and SMPL Register */
42#define WTSRT_SHIFT 0
43#define SMPLT_SHIFT 2
44#define WTSR_EN_SHIFT 6
45#define SMPL_EN_SHIFT 7
46#define WTSRT_MASK (3 << WTSRT_SHIFT)
47#define SMPLT_MASK (3 << SMPLT_SHIFT)
48#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT)
49#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT)
50/* RTC Hour register */
51#define HOUR_PM_SHIFT 6
52#define HOUR_PM_MASK (1 << HOUR_PM_SHIFT)
53/* RTC Alarm Enable */
54#define ALARM_ENABLE_SHIFT 7
55#define ALARM_ENABLE_MASK (1 << ALARM_ENABLE_SHIFT)
56
57enum {
58 RTC_SEC = 0,
59 RTC_MIN,
60 RTC_HOUR,
61 RTC_WEEKDAY,
62 RTC_MONTH,
63 RTC_YEAR,
64 RTC_DATE,
65 RTC_NR_TIME
66};
67
68struct max8997_rtc_info {
69 struct device *dev;
70 struct max8997_dev *max8997;
71 struct i2c_client *rtc;
72 struct rtc_device *rtc_dev;
73 struct mutex lock;
74 int virq;
75 int rtc_24hr_mode;
76};
77
78static void max8997_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
79 int rtc_24hr_mode)
80{
81 tm->tm_sec = data[RTC_SEC] & 0x7f;
82 tm->tm_min = data[RTC_MIN] & 0x7f;
83 if (rtc_24hr_mode)
84 tm->tm_hour = data[RTC_HOUR] & 0x1f;
85 else {
86 tm->tm_hour = data[RTC_HOUR] & 0x0f;
87 if (data[RTC_HOUR] & HOUR_PM_MASK)
88 tm->tm_hour += 12;
89 }
90
91 tm->tm_wday = fls(data[RTC_WEEKDAY] & 0x7f) - 1;
92 tm->tm_mday = data[RTC_DATE] & 0x1f;
93 tm->tm_mon = (data[RTC_MONTH] & 0x0f) - 1;
94 tm->tm_year = (data[RTC_YEAR] & 0x7f) + 100;
95 tm->tm_yday = 0;
96 tm->tm_isdst = 0;
97}
98
99static int max8997_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
100{
101 data[RTC_SEC] = tm->tm_sec;
102 data[RTC_MIN] = tm->tm_min;
103 data[RTC_HOUR] = tm->tm_hour;
104 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
105 data[RTC_DATE] = tm->tm_mday;
106 data[RTC_MONTH] = tm->tm_mon + 1;
107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0 ;
108
109 if (tm->tm_year < 100) {
110 pr_warn("%s: MAX8997 RTC cannot handle the year %d."
111 "Assume it's 2000.\n", __func__, 1900 + tm->tm_year);
112 return -EINVAL;
113 }
114 return 0;
115}
116
117static inline int max8997_rtc_set_update_reg(struct max8997_rtc_info *info)
118{
119 int ret;
120
121 ret = max8997_write_reg(info->rtc, MAX8997_RTC_UPDATE1,
122 RTC_UDR_MASK);
123 if (ret < 0)
124 dev_err(info->dev, "%s: fail to write update reg(%d)\n",
125 __func__, ret);
126 else {
127 /* Minimum 16ms delay required before RTC update.
128 * Otherwise, we may read and update based on out-of-date
129 * value */
130 msleep(20);
131 }
132
133 return ret;
134}
135
136static int max8997_rtc_read_time(struct device *dev, struct rtc_time *tm)
137{
138 struct max8997_rtc_info *info = dev_get_drvdata(dev);
139 u8 data[RTC_NR_TIME];
140 int ret;
141
142 mutex_lock(&info->lock);
143 ret = max8997_bulk_read(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
144 mutex_unlock(&info->lock);
145
146 if (ret < 0) {
147 dev_err(info->dev, "%s: fail to read time reg(%d)\n", __func__,
148 ret);
149 return ret;
150 }
151
152 max8997_rtc_data_to_tm(data, tm, info->rtc_24hr_mode);
153
154 return rtc_valid_tm(tm);
155}
156
157static int max8997_rtc_set_time(struct device *dev, struct rtc_time *tm)
158{
159 struct max8997_rtc_info *info = dev_get_drvdata(dev);
160 u8 data[RTC_NR_TIME];
161 int ret;
162
163 ret = max8997_rtc_tm_to_data(tm, data);
164 if (ret < 0)
165 return ret;
166
167 mutex_lock(&info->lock);
168
169 ret = max8997_bulk_write(info->rtc, MAX8997_RTC_SEC, RTC_NR_TIME, data);
170 if (ret < 0) {
171 dev_err(info->dev, "%s: fail to write time reg(%d)\n", __func__,
172 ret);
173 goto out;
174 }
175
176 ret = max8997_rtc_set_update_reg(info);
177out:
178 mutex_unlock(&info->lock);
179 return ret;
180}
181
182static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
183{
184 struct max8997_rtc_info *info = dev_get_drvdata(dev);
185 u8 data[RTC_NR_TIME];
186 u8 val;
187 int i, ret;
188
189 mutex_lock(&info->lock);
190
191 ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
192 data);
193 if (ret < 0) {
194 dev_err(info->dev, "%s:%d fail to read alarm reg(%d)\n",
195 __func__, __LINE__, ret);
196 goto out;
197 }
198
199 max8997_rtc_data_to_tm(data, &alrm->time, info->rtc_24hr_mode);
200
201 alrm->enabled = 0;
202 for (i = 0; i < RTC_NR_TIME; i++) {
203 if (data[i] & ALARM_ENABLE_MASK) {
204 alrm->enabled = 1;
205 break;
206 }
207 }
208
209 alrm->pending = 0;
210 ret = max8997_read_reg(info->max8997->i2c, MAX8997_REG_STATUS1, &val);
211 if (ret < 0) {
212 dev_err(info->dev, "%s:%d fail to read status1 reg(%d)\n",
213 __func__, __LINE__, ret);
214 goto out;
215 }
216
217 if (val & (1 << 4)) /* RTCA1 */
218 alrm->pending = 1;
219
220out:
221 mutex_unlock(&info->lock);
222 return 0;
223}
224
225static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
226{
227 u8 data[RTC_NR_TIME];
228 int ret, i;
229
230 if (!mutex_is_locked(&info->lock))
231 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
232
233 ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
234 data);
235 if (ret < 0) {
236 dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
237 __func__, ret);
238 goto out;
239 }
240
241 for (i = 0; i < RTC_NR_TIME; i++)
242 data[i] &= ~ALARM_ENABLE_MASK;
243
244 ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
245 data);
246 if (ret < 0) {
247 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
248 __func__, ret);
249 goto out;
250 }
251
252 ret = max8997_rtc_set_update_reg(info);
253out:
254 return ret;
255}
256
257static int max8997_rtc_start_alarm(struct max8997_rtc_info *info)
258{
259 u8 data[RTC_NR_TIME];
260 int ret;
261
262 if (!mutex_is_locked(&info->lock))
263 dev_warn(info->dev, "%s: should have mutex locked\n", __func__);
264
265 ret = max8997_bulk_read(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
266 data);
267 if (ret < 0) {
268 dev_err(info->dev, "%s: fail to read alarm reg(%d)\n",
269 __func__, ret);
270 goto out;
271 }
272
273 data[RTC_SEC] |= (1 << ALARM_ENABLE_SHIFT);
274 data[RTC_MIN] |= (1 << ALARM_ENABLE_SHIFT);
275 data[RTC_HOUR] |= (1 << ALARM_ENABLE_SHIFT);
276 data[RTC_WEEKDAY] &= ~ALARM_ENABLE_MASK;
277 if (data[RTC_MONTH] & 0xf)
278 data[RTC_MONTH] |= (1 << ALARM_ENABLE_SHIFT);
279 if (data[RTC_YEAR] & 0x7f)
280 data[RTC_YEAR] |= (1 << ALARM_ENABLE_SHIFT);
281 if (data[RTC_DATE] & 0x1f)
282 data[RTC_DATE] |= (1 << ALARM_ENABLE_SHIFT);
283
284 ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
285 data);
286 if (ret < 0) {
287 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
288 __func__, ret);
289 goto out;
290 }
291
292 ret = max8997_rtc_set_update_reg(info);
293out:
294 return ret;
295}
296static int max8997_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
297{
298 struct max8997_rtc_info *info = dev_get_drvdata(dev);
299 u8 data[RTC_NR_TIME];
300 int ret;
301
302 ret = max8997_rtc_tm_to_data(&alrm->time, data);
303 if (ret < 0)
304 return ret;
305
306 dev_info(info->dev, "%s: %d-%02d-%02d %02d:%02d:%02d\n", __func__,
307 data[RTC_YEAR] + 2000, data[RTC_MONTH], data[RTC_DATE],
308 data[RTC_HOUR], data[RTC_MIN], data[RTC_SEC]);
309
310 mutex_lock(&info->lock);
311
312 ret = max8997_rtc_stop_alarm(info);
313 if (ret < 0)
314 goto out;
315
316 ret = max8997_bulk_write(info->rtc, MAX8997_RTC_ALARM1_SEC, RTC_NR_TIME,
317 data);
318 if (ret < 0) {
319 dev_err(info->dev, "%s: fail to write alarm reg(%d)\n",
320 __func__, ret);
321 goto out;
322 }
323
324 ret = max8997_rtc_set_update_reg(info);
325 if (ret < 0)
326 goto out;
327
328 if (alrm->enabled)
329 ret = max8997_rtc_start_alarm(info);
330out:
331 mutex_unlock(&info->lock);
332 return ret;
333}
334
335static int max8997_rtc_alarm_irq_enable(struct device *dev,
336 unsigned int enabled)
337{
338 struct max8997_rtc_info *info = dev_get_drvdata(dev);
339 int ret;
340
341 mutex_lock(&info->lock);
342 if (enabled)
343 ret = max8997_rtc_start_alarm(info);
344 else
345 ret = max8997_rtc_stop_alarm(info);
346 mutex_unlock(&info->lock);
347
348 return ret;
349}
350
351static irqreturn_t max8997_rtc_alarm_irq(int irq, void *data)
352{
353 struct max8997_rtc_info *info = data;
354
355 dev_info(info->dev, "%s:irq(%d)\n", __func__, irq);
356
357 rtc_update_irq(info->rtc_dev, 1, RTC_IRQF | RTC_AF);
358
359 return IRQ_HANDLED;
360}
361
362static const struct rtc_class_ops max8997_rtc_ops = {
363 .read_time = max8997_rtc_read_time,
364 .set_time = max8997_rtc_set_time,
365 .read_alarm = max8997_rtc_read_alarm,
366 .set_alarm = max8997_rtc_set_alarm,
367 .alarm_irq_enable = max8997_rtc_alarm_irq_enable,
368};
369
370static void max8997_rtc_enable_wtsr(struct max8997_rtc_info *info, bool enable)
371{
372 int ret;
373 u8 val, mask;
374
375 if (!wtsr_en)
376 return;
377
378 if (enable)
379 val = (1 << WTSR_EN_SHIFT) | (3 << WTSRT_SHIFT);
380 else
381 val = 0;
382
383 mask = WTSR_EN_MASK | WTSRT_MASK;
384
385 dev_info(info->dev, "%s: %s WTSR\n", __func__,
386 enable ? "enable" : "disable");
387
388 ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
389 if (ret < 0) {
390 dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
391 __func__, ret);
392 return;
393 }
394
395 max8997_rtc_set_update_reg(info);
396}
397
398static void max8997_rtc_enable_smpl(struct max8997_rtc_info *info, bool enable)
399{
400 int ret;
401 u8 val, mask;
402
403 if (!smpl_en)
404 return;
405
406 if (enable)
407 val = (1 << SMPL_EN_SHIFT) | (0 << SMPLT_SHIFT);
408 else
409 val = 0;
410
411 mask = SMPL_EN_MASK | SMPLT_MASK;
412
413 dev_info(info->dev, "%s: %s SMPL\n", __func__,
414 enable ? "enable" : "disable");
415
416 ret = max8997_update_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, val, mask);
417 if (ret < 0) {
418 dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
419 __func__, ret);
420 return;
421 }
422
423 max8997_rtc_set_update_reg(info);
424
425 val = 0;
426 max8997_read_reg(info->rtc, MAX8997_RTC_WTSR_SMPL, &val);
427 pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val);
428}
429
430static int max8997_rtc_init_reg(struct max8997_rtc_info *info)
431{
432 u8 data[2];
433 int ret;
434
435 /* Set RTC control register : Binary mode, 24hour mdoe */
436 data[0] = (1 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
437 data[1] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
438
439 info->rtc_24hr_mode = 1;
440
441 ret = max8997_bulk_write(info->rtc, MAX8997_RTC_CTRLMASK, 2, data);
442 if (ret < 0) {
443 dev_err(info->dev, "%s: fail to write controlm reg(%d)\n",
444 __func__, ret);
445 return ret;
446 }
447
448 ret = max8997_rtc_set_update_reg(info);
449 return ret;
450}
451
452static int max8997_rtc_probe(struct platform_device *pdev)
453{
454 struct max8997_dev *max8997 = dev_get_drvdata(pdev->dev.parent);
455 struct max8997_rtc_info *info;
456 int ret, virq;
457
458 info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_rtc_info),
459 GFP_KERNEL);
460 if (!info)
461 return -ENOMEM;
462
463 mutex_init(&info->lock);
464 info->dev = &pdev->dev;
465 info->max8997 = max8997;
466 info->rtc = max8997->rtc;
467
468 platform_set_drvdata(pdev, info);
469
470 ret = max8997_rtc_init_reg(info);
471
472 if (ret < 0) {
473 dev_err(&pdev->dev, "Failed to initialize RTC reg:%d\n", ret);
474 return ret;
475 }
476
477 max8997_rtc_enable_wtsr(info, true);
478 max8997_rtc_enable_smpl(info, true);
479
480 device_init_wakeup(&pdev->dev, 1);
481
482 info->rtc_dev = rtc_device_register("max8997-rtc", &pdev->dev,
483 &max8997_rtc_ops, THIS_MODULE);
484
485 if (IS_ERR(info->rtc_dev)) {
486 ret = PTR_ERR(info->rtc_dev);
487 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
488 return ret;
489 }
490
491 virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1);
492 if (!virq) {
493 dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n");
494 goto err_out;
495 }
496 info->virq = virq;
497
498 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
499 max8997_rtc_alarm_irq, 0,
500 "rtc-alarm0", info);
501 if (ret < 0) {
502 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
503 info->virq, ret);
504 goto err_out;
505 }
506
507 return ret;
508
509err_out:
510 rtc_device_unregister(info->rtc_dev);
511 return ret;
512}
513
514static int max8997_rtc_remove(struct platform_device *pdev)
515{
516 struct max8997_rtc_info *info = platform_get_drvdata(pdev);
517
518 if (info)
519 rtc_device_unregister(info->rtc_dev);
520
521 return 0;
522}
523
524static void max8997_rtc_shutdown(struct platform_device *pdev)
525{
526 struct max8997_rtc_info *info = platform_get_drvdata(pdev);
527
528 max8997_rtc_enable_wtsr(info, false);
529 max8997_rtc_enable_smpl(info, false);
530}
531
532static const struct platform_device_id rtc_id[] = {
533 { "max8997-rtc", 0 },
534 {},
535};
536
537static struct platform_driver max8997_rtc_driver = {
538 .driver = {
539 .name = "max8997-rtc",
540 .owner = THIS_MODULE,
541 },
542 .probe = max8997_rtc_probe,
543 .remove = max8997_rtc_remove,
544 .shutdown = max8997_rtc_shutdown,
545 .id_table = rtc_id,
546};
547
548module_platform_driver(max8997_rtc_driver);
549
550MODULE_DESCRIPTION("Maxim MAX8997 RTC driver");
551MODULE_AUTHOR("<ms925.kim@samsung.com>");
552MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c
index 7196f438c089..8f234a075e8f 100644
--- a/drivers/rtc/rtc-max8998.c
+++ b/drivers/rtc/rtc-max8998.c
@@ -249,7 +249,7 @@ static const struct rtc_class_ops max8998_rtc_ops = {
249 .alarm_irq_enable = max8998_rtc_alarm_irq_enable, 249 .alarm_irq_enable = max8998_rtc_alarm_irq_enable,
250}; 250};
251 251
252static int __devinit max8998_rtc_probe(struct platform_device *pdev) 252static int max8998_rtc_probe(struct platform_device *pdev)
253{ 253{
254 struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent); 254 struct max8998_dev *max8998 = dev_get_drvdata(pdev->dev.parent);
255 struct max8998_platform_data *pdata = dev_get_platdata(max8998->dev); 255 struct max8998_platform_data *pdata = dev_get_platdata(max8998->dev);
@@ -298,7 +298,7 @@ out_rtc:
298 return ret; 298 return ret;
299} 299}
300 300
301static int __devexit max8998_rtc_remove(struct platform_device *pdev) 301static int max8998_rtc_remove(struct platform_device *pdev)
302{ 302{
303 struct max8998_rtc_info *info = platform_get_drvdata(pdev); 303 struct max8998_rtc_info *info = platform_get_drvdata(pdev);
304 304
@@ -323,7 +323,7 @@ static struct platform_driver max8998_rtc_driver = {
323 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
324 }, 324 },
325 .probe = max8998_rtc_probe, 325 .probe = max8998_rtc_probe,
326 .remove = __devexit_p(max8998_rtc_remove), 326 .remove = max8998_rtc_remove,
327 .id_table = max8998_rtc_id, 327 .id_table = max8998_rtc_id,
328}; 328};
329 329
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index 029e421baaed..bdcc60830aec 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/rtc.h> 15#include <linux/rtc.h>
16#include <linux/of.h>
16#include <linux/of_device.h> 17#include <linux/of_device.h>
17#include <linux/of_platform.h> 18#include <linux/of_platform.h>
18#include <linux/io.h> 19#include <linux/io.h>
@@ -306,7 +307,7 @@ static const struct rtc_class_ops mpc5200_rtc_ops = {
306 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable, 307 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable,
307}; 308};
308 309
309static int __devinit mpc5121_rtc_probe(struct platform_device *op) 310static int mpc5121_rtc_probe(struct platform_device *op)
310{ 311{
311 struct mpc5121_rtc_data *rtc; 312 struct mpc5121_rtc_data *rtc;
312 int err = 0; 313 int err = 0;
@@ -382,7 +383,7 @@ out_free:
382 return err; 383 return err;
383} 384}
384 385
385static int __devexit mpc5121_rtc_remove(struct platform_device *op) 386static int mpc5121_rtc_remove(struct platform_device *op)
386{ 387{
387 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev); 388 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev);
388 struct mpc5121_rtc_regs __iomem *regs = rtc->regs; 389 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
@@ -403,20 +404,22 @@ static int __devexit mpc5121_rtc_remove(struct platform_device *op)
403 return 0; 404 return 0;
404} 405}
405 406
406static struct of_device_id mpc5121_rtc_match[] __devinitdata = { 407#ifdef CONFIG_OF
408static struct of_device_id mpc5121_rtc_match[] = {
407 { .compatible = "fsl,mpc5121-rtc", }, 409 { .compatible = "fsl,mpc5121-rtc", },
408 { .compatible = "fsl,mpc5200-rtc", }, 410 { .compatible = "fsl,mpc5200-rtc", },
409 {}, 411 {},
410}; 412};
413#endif
411 414
412static struct platform_driver mpc5121_rtc_driver = { 415static struct platform_driver mpc5121_rtc_driver = {
413 .driver = { 416 .driver = {
414 .name = "mpc5121-rtc", 417 .name = "mpc5121-rtc",
415 .owner = THIS_MODULE, 418 .owner = THIS_MODULE,
416 .of_match_table = mpc5121_rtc_match, 419 .of_match_table = of_match_ptr(mpc5121_rtc_match),
417 }, 420 },
418 .probe = mpc5121_rtc_probe, 421 .probe = mpc5121_rtc_probe,
419 .remove = __devexit_p(mpc5121_rtc_remove), 422 .remove = mpc5121_rtc_remove,
420}; 423};
421 424
422module_platform_driver(mpc5121_rtc_driver); 425module_platform_driver(mpc5121_rtc_driver);
diff --git a/drivers/rtc/rtc-mrst.c b/drivers/rtc/rtc-mrst.c
index f51719bf4a75..578baf9d9725 100644
--- a/drivers/rtc/rtc-mrst.c
+++ b/drivers/rtc/rtc-mrst.c
@@ -322,8 +322,8 @@ static irqreturn_t mrst_rtc_irq(int irq, void *p)
322 return IRQ_NONE; 322 return IRQ_NONE;
323} 323}
324 324
325static int __devinit 325static int vrtc_mrst_do_probe(struct device *dev, struct resource *iomem,
326vrtc_mrst_do_probe(struct device *dev, struct resource *iomem, int rtc_irq) 326 int rtc_irq)
327{ 327{
328 int retval = 0; 328 int retval = 0;
329 unsigned char rtc_control; 329 unsigned char rtc_control;
@@ -394,7 +394,7 @@ static void rtc_mrst_do_shutdown(void)
394 spin_unlock_irq(&rtc_lock); 394 spin_unlock_irq(&rtc_lock);
395} 395}
396 396
397static void __devexit rtc_mrst_do_remove(struct device *dev) 397static void rtc_mrst_do_remove(struct device *dev)
398{ 398{
399 struct mrst_rtc *mrst = dev_get_drvdata(dev); 399 struct mrst_rtc *mrst = dev_get_drvdata(dev);
400 struct resource *iomem; 400 struct resource *iomem;
@@ -503,14 +503,14 @@ static inline int mrst_poweroff(struct device *dev)
503 503
504#endif 504#endif
505 505
506static int __devinit vrtc_mrst_platform_probe(struct platform_device *pdev) 506static int vrtc_mrst_platform_probe(struct platform_device *pdev)
507{ 507{
508 return vrtc_mrst_do_probe(&pdev->dev, 508 return vrtc_mrst_do_probe(&pdev->dev,
509 platform_get_resource(pdev, IORESOURCE_MEM, 0), 509 platform_get_resource(pdev, IORESOURCE_MEM, 0),
510 platform_get_irq(pdev, 0)); 510 platform_get_irq(pdev, 0));
511} 511}
512 512
513static int __devexit vrtc_mrst_platform_remove(struct platform_device *pdev) 513static int vrtc_mrst_platform_remove(struct platform_device *pdev)
514{ 514{
515 rtc_mrst_do_remove(&pdev->dev); 515 rtc_mrst_do_remove(&pdev->dev);
516 return 0; 516 return 0;
@@ -528,7 +528,7 @@ MODULE_ALIAS("platform:vrtc_mrst");
528 528
529static struct platform_driver vrtc_mrst_platform_driver = { 529static struct platform_driver vrtc_mrst_platform_driver = {
530 .probe = vrtc_mrst_platform_probe, 530 .probe = vrtc_mrst_platform_probe,
531 .remove = __devexit_p(vrtc_mrst_platform_remove), 531 .remove = vrtc_mrst_platform_remove,
532 .shutdown = vrtc_mrst_platform_shutdown, 532 .shutdown = vrtc_mrst_platform_shutdown,
533 .driver = { 533 .driver = {
534 .name = (char *) driver_name, 534 .name = (char *) driver_name,
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index ebc1649d45d6..57233c885998 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -215,7 +215,7 @@ static const struct rtc_class_ops mv_rtc_alarm_ops = {
215 .alarm_irq_enable = mv_rtc_alarm_irq_enable, 215 .alarm_irq_enable = mv_rtc_alarm_irq_enable,
216}; 216};
217 217
218static int __devinit mv_rtc_probe(struct platform_device *pdev) 218static int mv_rtc_probe(struct platform_device *pdev)
219{ 219{
220 struct resource *res; 220 struct resource *res;
221 struct rtc_plat_data *pdata; 221 struct rtc_plat_data *pdata;
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 7304139934aa..1c3ef7289565 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -368,7 +368,7 @@ static struct rtc_class_ops mxc_rtc_ops = {
368 .alarm_irq_enable = mxc_rtc_alarm_irq_enable, 368 .alarm_irq_enable = mxc_rtc_alarm_irq_enable,
369}; 369};
370 370
371static int __devinit mxc_rtc_probe(struct platform_device *pdev) 371static int mxc_rtc_probe(struct platform_device *pdev)
372{ 372{
373 struct resource *res; 373 struct resource *res;
374 struct rtc_device *rtc; 374 struct rtc_device *rtc;
@@ -460,7 +460,7 @@ exit_free_pdata:
460 return ret; 460 return ret;
461} 461}
462 462
463static int __devexit mxc_rtc_remove(struct platform_device *pdev) 463static int mxc_rtc_remove(struct platform_device *pdev)
464{ 464{
465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
466 466
@@ -509,7 +509,7 @@ static struct platform_driver mxc_rtc_driver = {
509 }, 509 },
510 .id_table = imx_rtc_devtype, 510 .id_table = imx_rtc_devtype,
511 .probe = mxc_rtc_probe, 511 .probe = mxc_rtc_probe,
512 .remove = __devexit_p(mxc_rtc_remove), 512 .remove = mxc_rtc_remove,
513}; 513};
514 514
515module_platform_driver(mxc_rtc_driver) 515module_platform_driver(mxc_rtc_driver)
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index b79010987d1e..a63680850fef 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -222,7 +222,7 @@ static struct rtc_class_ops nuc900_rtc_ops = {
222 .alarm_irq_enable = nuc900_alarm_irq_enable, 222 .alarm_irq_enable = nuc900_alarm_irq_enable,
223}; 223};
224 224
225static int __devinit nuc900_rtc_probe(struct platform_device *pdev) 225static int nuc900_rtc_probe(struct platform_device *pdev)
226{ 226{
227 struct resource *res; 227 struct resource *res;
228 struct nuc900_rtc *nuc900_rtc; 228 struct nuc900_rtc *nuc900_rtc;
@@ -284,7 +284,7 @@ fail1: kfree(nuc900_rtc);
284 return err; 284 return err;
285} 285}
286 286
287static int __devexit nuc900_rtc_remove(struct platform_device *pdev) 287static int nuc900_rtc_remove(struct platform_device *pdev)
288{ 288{
289 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev); 289 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
290 struct resource *res; 290 struct resource *res;
@@ -304,7 +304,7 @@ static int __devexit nuc900_rtc_remove(struct platform_device *pdev)
304} 304}
305 305
306static struct platform_driver nuc900_rtc_driver = { 306static struct platform_driver nuc900_rtc_driver = {
307 .remove = __devexit_p(nuc900_rtc_remove), 307 .remove = nuc900_rtc_remove,
308 .driver = { 308 .driver = {
309 .name = "nuc900-rtc", 309 .name = "nuc900-rtc",
310 .owner = THIS_MODULE, 310 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 0b614e32653d..600971407aac 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -20,6 +20,9 @@
20#include <linux/rtc.h> 20#include <linux/rtc.h>
21#include <linux/bcd.h> 21#include <linux/bcd.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/of.h>
24#include <linux/of_device.h>
25#include <linux/pm_runtime.h>
23 26
24#include <asm/io.h> 27#include <asm/io.h>
25 28
@@ -38,6 +41,8 @@
38 * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment. 41 * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment.
39 */ 42 */
40 43
44#define DRIVER_NAME "omap_rtc"
45
41#define OMAP_RTC_BASE 0xfffb4800 46#define OMAP_RTC_BASE 0xfffb4800
42 47
43/* RTC registers */ 48/* RTC registers */
@@ -64,6 +69,9 @@
64#define OMAP_RTC_COMP_MSB_REG 0x50 69#define OMAP_RTC_COMP_MSB_REG 0x50
65#define OMAP_RTC_OSC_REG 0x54 70#define OMAP_RTC_OSC_REG 0x54
66 71
72#define OMAP_RTC_KICK0_REG 0x6c
73#define OMAP_RTC_KICK1_REG 0x70
74
67/* OMAP_RTC_CTRL_REG bit fields: */ 75/* OMAP_RTC_CTRL_REG bit fields: */
68#define OMAP_RTC_CTRL_SPLIT (1<<7) 76#define OMAP_RTC_CTRL_SPLIT (1<<7)
69#define OMAP_RTC_CTRL_DISABLE (1<<6) 77#define OMAP_RTC_CTRL_DISABLE (1<<6)
@@ -88,10 +96,18 @@
88#define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3) 96#define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3)
89#define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2) 97#define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2)
90 98
99/* OMAP_RTC_KICKER values */
100#define KICK0_VALUE 0x83e70b13
101#define KICK1_VALUE 0x95a4f1e0
102
103#define OMAP_RTC_HAS_KICKER 0x1
104
91static void __iomem *rtc_base; 105static void __iomem *rtc_base;
92 106
93#define rtc_read(addr) __raw_readb(rtc_base + (addr)) 107#define rtc_read(addr) readb(rtc_base + (addr))
94#define rtc_write(val, addr) __raw_writeb(val, rtc_base + (addr)) 108#define rtc_write(val, addr) writeb(val, rtc_base + (addr))
109
110#define rtc_writel(val, addr) writel(val, rtc_base + (addr))
95 111
96 112
97/* we rely on the rtc framework to handle locking (rtc->ops_lock), 113/* we rely on the rtc framework to handle locking (rtc->ops_lock),
@@ -285,11 +301,38 @@ static struct rtc_class_ops omap_rtc_ops = {
285static int omap_rtc_alarm; 301static int omap_rtc_alarm;
286static int omap_rtc_timer; 302static int omap_rtc_timer;
287 303
304#define OMAP_RTC_DATA_DA830_IDX 1
305
306static struct platform_device_id omap_rtc_devtype[] = {
307 {
308 .name = DRIVER_NAME,
309 }, {
310 .name = "da830-rtc",
311 .driver_data = OMAP_RTC_HAS_KICKER,
312 },
313 {},
314};
315MODULE_DEVICE_TABLE(platform, omap_rtc_devtype);
316
317static const struct of_device_id omap_rtc_of_match[] = {
318 { .compatible = "ti,da830-rtc",
319 .data = &omap_rtc_devtype[OMAP_RTC_DATA_DA830_IDX],
320 },
321 {},
322};
323MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
324
288static int __init omap_rtc_probe(struct platform_device *pdev) 325static int __init omap_rtc_probe(struct platform_device *pdev)
289{ 326{
290 struct resource *res, *mem; 327 struct resource *res, *mem;
291 struct rtc_device *rtc; 328 struct rtc_device *rtc;
292 u8 reg, new_ctrl; 329 u8 reg, new_ctrl;
330 const struct platform_device_id *id_entry;
331 const struct of_device_id *of_id;
332
333 of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
334 if (of_id)
335 pdev->id_entry = of_id->data;
293 336
294 omap_rtc_timer = platform_get_irq(pdev, 0); 337 omap_rtc_timer = platform_get_irq(pdev, 0);
295 if (omap_rtc_timer <= 0) { 338 if (omap_rtc_timer <= 0) {
@@ -322,6 +365,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
322 goto fail; 365 goto fail;
323 } 366 }
324 367
368 /* Enable the clock/module so that we can access the registers */
369 pm_runtime_enable(&pdev->dev);
370 pm_runtime_get_sync(&pdev->dev);
371
372 id_entry = platform_get_device_id(pdev);
373 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) {
374 rtc_writel(KICK0_VALUE, OMAP_RTC_KICK0_REG);
375 rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG);
376 }
377
325 rtc = rtc_device_register(pdev->name, &pdev->dev, 378 rtc = rtc_device_register(pdev->name, &pdev->dev,
326 &omap_rtc_ops, THIS_MODULE); 379 &omap_rtc_ops, THIS_MODULE);
327 if (IS_ERR(rtc)) { 380 if (IS_ERR(rtc)) {
@@ -398,6 +451,10 @@ fail2:
398fail1: 451fail1:
399 rtc_device_unregister(rtc); 452 rtc_device_unregister(rtc);
400fail0: 453fail0:
454 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
455 rtc_writel(0, OMAP_RTC_KICK0_REG);
456 pm_runtime_put_sync(&pdev->dev);
457 pm_runtime_disable(&pdev->dev);
401 iounmap(rtc_base); 458 iounmap(rtc_base);
402fail: 459fail:
403 release_mem_region(mem->start, resource_size(mem)); 460 release_mem_region(mem->start, resource_size(mem));
@@ -408,6 +465,8 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
408{ 465{
409 struct rtc_device *rtc = platform_get_drvdata(pdev); 466 struct rtc_device *rtc = platform_get_drvdata(pdev);
410 struct resource *mem = dev_get_drvdata(&rtc->dev); 467 struct resource *mem = dev_get_drvdata(&rtc->dev);
468 const struct platform_device_id *id_entry =
469 platform_get_device_id(pdev);
411 470
412 device_init_wakeup(&pdev->dev, 0); 471 device_init_wakeup(&pdev->dev, 0);
413 472
@@ -420,6 +479,13 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
420 free_irq(omap_rtc_alarm, rtc); 479 free_irq(omap_rtc_alarm, rtc);
421 480
422 rtc_device_unregister(rtc); 481 rtc_device_unregister(rtc);
482 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
483 rtc_writel(0, OMAP_RTC_KICK0_REG);
484
485 /* Disable the clock/module */
486 pm_runtime_put_sync(&pdev->dev);
487 pm_runtime_disable(&pdev->dev);
488
423 iounmap(rtc_base); 489 iounmap(rtc_base);
424 release_mem_region(mem->start, resource_size(mem)); 490 release_mem_region(mem->start, resource_size(mem));
425 return 0; 491 return 0;
@@ -442,11 +508,17 @@ static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
442 else 508 else
443 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 509 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
444 510
511 /* Disable the clock/module */
512 pm_runtime_put_sync(&pdev->dev);
513
445 return 0; 514 return 0;
446} 515}
447 516
448static int omap_rtc_resume(struct platform_device *pdev) 517static int omap_rtc_resume(struct platform_device *pdev)
449{ 518{
519 /* Enable the clock/module so that we can access the registers */
520 pm_runtime_get_sync(&pdev->dev);
521
450 if (device_may_wakeup(&pdev->dev)) 522 if (device_may_wakeup(&pdev->dev))
451 disable_irq_wake(omap_rtc_alarm); 523 disable_irq_wake(omap_rtc_alarm);
452 else 524 else
@@ -471,9 +543,11 @@ static struct platform_driver omap_rtc_driver = {
471 .resume = omap_rtc_resume, 543 .resume = omap_rtc_resume,
472 .shutdown = omap_rtc_shutdown, 544 .shutdown = omap_rtc_shutdown,
473 .driver = { 545 .driver = {
474 .name = "omap_rtc", 546 .name = DRIVER_NAME,
475 .owner = THIS_MODULE, 547 .owner = THIS_MODULE,
548 .of_match_table = of_match_ptr(omap_rtc_of_match),
476 }, 549 },
550 .id_table = omap_rtc_devtype,
477}; 551};
478 552
479static int __init rtc_init(void) 553static int __init rtc_init(void)
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c
index cd4f198cc2ef..e0019cd0bf71 100644
--- a/drivers/rtc/rtc-pcap.c
+++ b/drivers/rtc/rtc-pcap.c
@@ -139,7 +139,7 @@ static const struct rtc_class_ops pcap_rtc_ops = {
139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable, 139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
140}; 140};
141 141
142static int __devinit pcap_rtc_probe(struct platform_device *pdev) 142static int pcap_rtc_probe(struct platform_device *pdev)
143{ 143{
144 struct pcap_rtc *pcap_rtc; 144 struct pcap_rtc *pcap_rtc;
145 int timer_irq, alarm_irq; 145 int timer_irq, alarm_irq;
@@ -183,7 +183,7 @@ fail_rtc:
183 return err; 183 return err;
184} 184}
185 185
186static int __devexit pcap_rtc_remove(struct platform_device *pdev) 186static int pcap_rtc_remove(struct platform_device *pdev)
187{ 187{
188 struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); 188 struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev);
189 189
@@ -196,7 +196,7 @@ static int __devexit pcap_rtc_remove(struct platform_device *pdev)
196} 196}
197 197
198static struct platform_driver pcap_rtc_driver = { 198static struct platform_driver pcap_rtc_driver = {
199 .remove = __devexit_p(pcap_rtc_remove), 199 .remove = pcap_rtc_remove,
200 .driver = { 200 .driver = {
201 .name = "pcap-rtc", 201 .name = "pcap-rtc",
202 .owner = THIS_MODULE, 202 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 13e4df63974f..02b742afa761 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -219,7 +219,7 @@ static const struct rtc_class_ops pcf2123_rtc_ops = {
219 .set_time = pcf2123_rtc_set_time, 219 .set_time = pcf2123_rtc_set_time,
220}; 220};
221 221
222static int __devinit pcf2123_probe(struct spi_device *spi) 222static int pcf2123_probe(struct spi_device *spi)
223{ 223{
224 struct rtc_device *rtc; 224 struct rtc_device *rtc;
225 struct pcf2123_plat_data *pdata; 225 struct pcf2123_plat_data *pdata;
@@ -319,7 +319,7 @@ kfree_exit:
319 return ret; 319 return ret;
320} 320}
321 321
322static int __devexit pcf2123_remove(struct spi_device *spi) 322static int pcf2123_remove(struct spi_device *spi)
323{ 323{
324 struct pcf2123_plat_data *pdata = spi->dev.platform_data; 324 struct pcf2123_plat_data *pdata = spi->dev.platform_data;
325 int i; 325 int i;
@@ -345,7 +345,7 @@ static struct spi_driver pcf2123_driver = {
345 .owner = THIS_MODULE, 345 .owner = THIS_MODULE,
346 }, 346 },
347 .probe = pcf2123_probe, 347 .probe = pcf2123_probe,
348 .remove = __devexit_p(pcf2123_remove), 348 .remove = pcf2123_remove,
349}; 349};
350 350
351module_spi_driver(pcf2123_driver); 351module_spi_driver(pcf2123_driver);
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index a20202f9ee57..e9f3135d305f 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -248,7 +248,7 @@ static void pcf50633_rtc_irq(int irq, void *data)
248 rtc->alarm_pending = 1; 248 rtc->alarm_pending = 1;
249} 249}
250 250
251static int __devinit pcf50633_rtc_probe(struct platform_device *pdev) 251static int pcf50633_rtc_probe(struct platform_device *pdev)
252{ 252{
253 struct pcf50633_rtc *rtc; 253 struct pcf50633_rtc *rtc;
254 254
@@ -272,7 +272,7 @@ static int __devinit pcf50633_rtc_probe(struct platform_device *pdev)
272 return 0; 272 return 0;
273} 273}
274 274
275static int __devexit pcf50633_rtc_remove(struct platform_device *pdev) 275static int pcf50633_rtc_remove(struct platform_device *pdev)
276{ 276{
277 struct pcf50633_rtc *rtc; 277 struct pcf50633_rtc *rtc;
278 278
@@ -291,7 +291,7 @@ static struct platform_driver pcf50633_rtc_driver = {
291 .name = "pcf50633-rtc", 291 .name = "pcf50633-rtc",
292 }, 292 },
293 .probe = pcf50633_rtc_probe, 293 .probe = pcf50633_rtc_probe,
294 .remove = __devexit_p(pcf50633_rtc_remove), 294 .remove = pcf50633_rtc_remove,
295}; 295};
296 296
297module_platform_driver(pcf50633_rtc_driver); 297module_platform_driver(pcf50633_rtc_driver);
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
new file mode 100644
index 000000000000..889e3160e701
--- /dev/null
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -0,0 +1,357 @@
1/*
2 * Copyright (C) 2012 Avionic Design GmbH
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/bcd.h>
10#include <linux/i2c.h>
11#include <linux/module.h>
12#include <linux/rtc.h>
13#include <linux/of.h>
14
15#define DRIVER_NAME "rtc-pcf8523"
16
17#define REG_CONTROL1 0x00
18#define REG_CONTROL1_CAP_SEL (1 << 7)
19#define REG_CONTROL1_STOP (1 << 5)
20
21#define REG_CONTROL3 0x02
22#define REG_CONTROL3_PM_BLD (1 << 7) /* battery low detection disabled */
23#define REG_CONTROL3_PM_VDD (1 << 6) /* switch-over disabled */
24#define REG_CONTROL3_PM_DSM (1 << 5) /* direct switching mode */
25#define REG_CONTROL3_PM_MASK 0xe0
26#define REG_CONTROL3_BLF (1 << 2) /* battery low bit, read-only */
27
28#define REG_SECONDS 0x03
29#define REG_SECONDS_OS (1 << 7)
30
31#define REG_MINUTES 0x04
32#define REG_HOURS 0x05
33#define REG_DAYS 0x06
34#define REG_WEEKDAYS 0x07
35#define REG_MONTHS 0x08
36#define REG_YEARS 0x09
37
38struct pcf8523 {
39 struct rtc_device *rtc;
40};
41
42static int pcf8523_read(struct i2c_client *client, u8 reg, u8 *valuep)
43{
44 struct i2c_msg msgs[2];
45 u8 value = 0;
46 int err;
47
48 msgs[0].addr = client->addr;
49 msgs[0].flags = 0;
50 msgs[0].len = sizeof(reg);
51 msgs[0].buf = &reg;
52
53 msgs[1].addr = client->addr;
54 msgs[1].flags = I2C_M_RD;
55 msgs[1].len = sizeof(value);
56 msgs[1].buf = &value;
57
58 err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
59 if (err < 0)
60 return err;
61
62 *valuep = value;
63
64 return 0;
65}
66
67static int pcf8523_write(struct i2c_client *client, u8 reg, u8 value)
68{
69 u8 buffer[2] = { reg, value };
70 struct i2c_msg msg;
71 int err;
72
73 msg.addr = client->addr;
74 msg.flags = 0;
75 msg.len = sizeof(buffer);
76 msg.buf = buffer;
77
78 err = i2c_transfer(client->adapter, &msg, 1);
79 if (err < 0)
80 return err;
81
82 return 0;
83}
84
85static int pcf8523_select_capacitance(struct i2c_client *client, bool high)
86{
87 u8 value;
88 int err;
89
90 err = pcf8523_read(client, REG_CONTROL1, &value);
91 if (err < 0)
92 return err;
93
94 if (!high)
95 value &= ~REG_CONTROL1_CAP_SEL;
96 else
97 value |= REG_CONTROL1_CAP_SEL;
98
99 err = pcf8523_write(client, REG_CONTROL1, value);
100 if (err < 0)
101 return err;
102
103 return err;
104}
105
106static int pcf8523_set_pm(struct i2c_client *client, u8 pm)
107{
108 u8 value;
109 int err;
110
111 err = pcf8523_read(client, REG_CONTROL3, &value);
112 if (err < 0)
113 return err;
114
115 value = (value & ~REG_CONTROL3_PM_MASK) | pm;
116
117 err = pcf8523_write(client, REG_CONTROL3, value);
118 if (err < 0)
119 return err;
120
121 return 0;
122}
123
124static int pcf8523_stop_rtc(struct i2c_client *client)
125{
126 u8 value;
127 int err;
128
129 err = pcf8523_read(client, REG_CONTROL1, &value);
130 if (err < 0)
131 return err;
132
133 value |= REG_CONTROL1_STOP;
134
135 err = pcf8523_write(client, REG_CONTROL1, value);
136 if (err < 0)
137 return err;
138
139 return 0;
140}
141
142static int pcf8523_start_rtc(struct i2c_client *client)
143{
144 u8 value;
145 int err;
146
147 err = pcf8523_read(client, REG_CONTROL1, &value);
148 if (err < 0)
149 return err;
150
151 value &= ~REG_CONTROL1_STOP;
152
153 err = pcf8523_write(client, REG_CONTROL1, value);
154 if (err < 0)
155 return err;
156
157 return 0;
158}
159
160static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
161{
162 struct i2c_client *client = to_i2c_client(dev);
163 u8 start = REG_SECONDS, regs[7];
164 struct i2c_msg msgs[2];
165 int err;
166
167 msgs[0].addr = client->addr;
168 msgs[0].flags = 0;
169 msgs[0].len = 1;
170 msgs[0].buf = &start;
171
172 msgs[1].addr = client->addr;
173 msgs[1].flags = I2C_M_RD;
174 msgs[1].len = sizeof(regs);
175 msgs[1].buf = regs;
176
177 err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
178 if (err < 0)
179 return err;
180
181 if (regs[0] & REG_SECONDS_OS) {
182 /*
183 * If the oscillator was stopped, try to clear the flag. Upon
184 * power-up the flag is always set, but if we cannot clear it
185 * the oscillator isn't running properly for some reason. The
186 * sensible thing therefore is to return an error, signalling
187 * that the clock cannot be assumed to be correct.
188 */
189
190 regs[0] &= ~REG_SECONDS_OS;
191
192 err = pcf8523_write(client, REG_SECONDS, regs[0]);
193 if (err < 0)
194 return err;
195
196 err = pcf8523_read(client, REG_SECONDS, &regs[0]);
197 if (err < 0)
198 return err;
199
200 if (regs[0] & REG_SECONDS_OS)
201 return -EAGAIN;
202 }
203
204 tm->tm_sec = bcd2bin(regs[0] & 0x7f);
205 tm->tm_min = bcd2bin(regs[1] & 0x7f);
206 tm->tm_hour = bcd2bin(regs[2] & 0x3f);
207 tm->tm_mday = bcd2bin(regs[3] & 0x3f);
208 tm->tm_wday = regs[4] & 0x7;
209 tm->tm_mon = bcd2bin(regs[5] & 0x1f);
210 tm->tm_year = bcd2bin(regs[6]) + 100;
211
212 return rtc_valid_tm(tm);
213}
214
215static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
216{
217 struct i2c_client *client = to_i2c_client(dev);
218 struct i2c_msg msg;
219 u8 regs[8];
220 int err;
221
222 err = pcf8523_stop_rtc(client);
223 if (err < 0)
224 return err;
225
226 regs[0] = REG_SECONDS;
227 regs[1] = bin2bcd(tm->tm_sec);
228 regs[2] = bin2bcd(tm->tm_min);
229 regs[3] = bin2bcd(tm->tm_hour);
230 regs[4] = bin2bcd(tm->tm_mday);
231 regs[5] = tm->tm_wday;
232 regs[6] = bin2bcd(tm->tm_mon);
233 regs[7] = bin2bcd(tm->tm_year - 100);
234
235 msg.addr = client->addr;
236 msg.flags = 0;
237 msg.len = sizeof(regs);
238 msg.buf = regs;
239
240 err = i2c_transfer(client->adapter, &msg, 1);
241 if (err < 0) {
242 /*
243 * If the time cannot be set, restart the RTC anyway. Note
244 * that errors are ignored if the RTC cannot be started so
245 * that we have a chance to propagate the original error.
246 */
247 pcf8523_start_rtc(client);
248 return err;
249 }
250
251 return pcf8523_start_rtc(client);
252}
253
254#ifdef CONFIG_RTC_INTF_DEV
255static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd,
256 unsigned long arg)
257{
258 struct i2c_client *client = to_i2c_client(dev);
259 u8 value;
260 int ret = 0, err;
261
262 switch (cmd) {
263 case RTC_VL_READ:
264 err = pcf8523_read(client, REG_CONTROL3, &value);
265 if (err < 0)
266 return err;
267
268 if (value & REG_CONTROL3_BLF)
269 ret = 1;
270
271 if (copy_to_user((void __user *)arg, &ret, sizeof(int)))
272 return -EFAULT;
273
274 return 0;
275 default:
276 return -ENOIOCTLCMD;
277 }
278}
279#else
280#define pcf8523_rtc_ioctl NULL
281#endif
282
283static const struct rtc_class_ops pcf8523_rtc_ops = {
284 .read_time = pcf8523_rtc_read_time,
285 .set_time = pcf8523_rtc_set_time,
286 .ioctl = pcf8523_rtc_ioctl,
287};
288
289static int pcf8523_probe(struct i2c_client *client,
290 const struct i2c_device_id *id)
291{
292 struct pcf8523 *pcf;
293 int err;
294
295 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
296 return -ENODEV;
297
298 pcf = devm_kzalloc(&client->dev, sizeof(*pcf), GFP_KERNEL);
299 if (!pcf)
300 return -ENOMEM;
301
302 err = pcf8523_select_capacitance(client, true);
303 if (err < 0)
304 return err;
305
306 err = pcf8523_set_pm(client, 0);
307 if (err < 0)
308 return err;
309
310 pcf->rtc = rtc_device_register(DRIVER_NAME, &client->dev,
311 &pcf8523_rtc_ops, THIS_MODULE);
312 if (IS_ERR(pcf->rtc))
313 return PTR_ERR(pcf->rtc);
314
315 i2c_set_clientdata(client, pcf);
316
317 return 0;
318}
319
320static int pcf8523_remove(struct i2c_client *client)
321{
322 struct pcf8523 *pcf = i2c_get_clientdata(client);
323
324 rtc_device_unregister(pcf->rtc);
325
326 return 0;
327}
328
329static const struct i2c_device_id pcf8523_id[] = {
330 { "pcf8523", 0 },
331 { }
332};
333MODULE_DEVICE_TABLE(i2c, pcf8523_id);
334
335#ifdef CONFIG_OF
336static const struct of_device_id pcf8523_of_match[] = {
337 { .compatible = "nxp,pcf8523" },
338 { }
339};
340MODULE_DEVICE_TABLE(of, pcf8523_of_match);
341#endif
342
343static struct i2c_driver pcf8523_driver = {
344 .driver = {
345 .name = DRIVER_NAME,
346 .owner = THIS_MODULE,
347 .of_match_table = of_match_ptr(pcf8523_of_match),
348 },
349 .probe = pcf8523_probe,
350 .remove = pcf8523_remove,
351 .id_table = pcf8523_id,
352};
353module_i2c_driver(pcf8523_driver);
354
355MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
356MODULE_DESCRIPTION("NXP PCF8523 RTC driver");
357MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 98e3a2b681e6..f7daf18a112e 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -181,7 +181,7 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
181 __func__, err, data[0], data[1]); 181 __func__, err, data[0], data[1]);
182 return -EIO; 182 return -EIO;
183 } 183 }
184 }; 184 }
185 185
186 return 0; 186 return 0;
187} 187}
@@ -296,7 +296,7 @@ static const struct i2c_device_id pcf8563_id[] = {
296MODULE_DEVICE_TABLE(i2c, pcf8563_id); 296MODULE_DEVICE_TABLE(i2c, pcf8563_id);
297 297
298#ifdef CONFIG_OF 298#ifdef CONFIG_OF
299static const struct of_device_id pcf8563_of_match[] __devinitconst = { 299static const struct of_device_id pcf8563_of_match[] = {
300 { .compatible = "nxp,pcf8563" }, 300 { .compatible = "nxp,pcf8563" },
301 {} 301 {}
302}; 302};
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 019ff3571168..5f97c61247d5 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -185,8 +185,8 @@ static int pcf8583_rtc_read_time(struct device *dev, struct rtc_time *tm)
185 if (ctrl & (CTRL_STOP | CTRL_HOLD)) { 185 if (ctrl & (CTRL_STOP | CTRL_HOLD)) {
186 unsigned char new_ctrl = ctrl & ~(CTRL_STOP | CTRL_HOLD); 186 unsigned char new_ctrl = ctrl & ~(CTRL_STOP | CTRL_HOLD);
187 187
188 printk(KERN_WARNING "RTC: resetting control %02x -> %02x\n", 188 dev_warn(dev, "resetting control %02x -> %02x\n",
189 ctrl, new_ctrl); 189 ctrl, new_ctrl);
190 190
191 if ((err = pcf8583_set_ctrl(client, &new_ctrl)) < 0) 191 if ((err = pcf8583_set_ctrl(client, &new_ctrl)) < 0)
192 return err; 192 return err;
@@ -294,7 +294,7 @@ exit_kfree:
294 return err; 294 return err;
295} 295}
296 296
297static int __devexit pcf8583_remove(struct i2c_client *client) 297static int pcf8583_remove(struct i2c_client *client)
298{ 298{
299 struct pcf8583 *pcf8583 = i2c_get_clientdata(client); 299 struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
300 300
@@ -316,7 +316,7 @@ static struct i2c_driver pcf8583_driver = {
316 .owner = THIS_MODULE, 316 .owner = THIS_MODULE,
317 }, 317 },
318 .probe = pcf8583_probe, 318 .probe = pcf8583_probe,
319 .remove = __devexit_p(pcf8583_remove), 319 .remove = pcf8583_remove,
320 .id_table = pcf8583_id, 320 .id_table = pcf8583_id,
321}; 321};
322 322
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 08378e3cc21c..8900ea784817 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -44,6 +44,7 @@
44#define RTC_YMR 0x34 /* Year match register */ 44#define RTC_YMR 0x34 /* Year match register */
45#define RTC_YLR 0x38 /* Year data load register */ 45#define RTC_YLR 0x38 /* Year data load register */
46 46
47#define RTC_CR_EN (1 << 0) /* counter enable bit */
47#define RTC_CR_CWEN (1 << 26) /* Clockwatch enable bit */ 48#define RTC_CR_CWEN (1 << 26) /* Clockwatch enable bit */
48 49
49#define RTC_TCR_EN (1 << 1) /* Periodic timer enable bit */ 50#define RTC_TCR_EN (1 << 1) /* Periodic timer enable bit */
@@ -320,7 +321,7 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
320 struct pl031_local *ldata; 321 struct pl031_local *ldata;
321 struct pl031_vendor_data *vendor = id->data; 322 struct pl031_vendor_data *vendor = id->data;
322 struct rtc_class_ops *ops = &vendor->ops; 323 struct rtc_class_ops *ops = &vendor->ops;
323 unsigned long time; 324 unsigned long time, data;
324 325
325 ret = amba_request_regions(adev, NULL); 326 ret = amba_request_regions(adev, NULL);
326 if (ret) 327 if (ret)
@@ -345,10 +346,13 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
345 dev_dbg(&adev->dev, "designer ID = 0x%02x\n", amba_manf(adev)); 346 dev_dbg(&adev->dev, "designer ID = 0x%02x\n", amba_manf(adev));
346 dev_dbg(&adev->dev, "revision = 0x%01x\n", amba_rev(adev)); 347 dev_dbg(&adev->dev, "revision = 0x%01x\n", amba_rev(adev));
347 348
349 data = readl(ldata->base + RTC_CR);
348 /* Enable the clockwatch on ST Variants */ 350 /* Enable the clockwatch on ST Variants */
349 if (vendor->clockwatch) 351 if (vendor->clockwatch)
350 writel(readl(ldata->base + RTC_CR) | RTC_CR_CWEN, 352 data |= RTC_CR_CWEN;
351 ldata->base + RTC_CR); 353 else
354 data |= RTC_CR_EN;
355 writel(data, ldata->base + RTC_CR);
352 356
353 /* 357 /*
354 * On ST PL031 variants, the RTC reset value does not provide correct 358 * On ST PL031 variants, the RTC reset value does not provide correct
@@ -380,6 +384,8 @@ static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
380 goto out_no_irq; 384 goto out_no_irq;
381 } 385 }
382 386
387 device_init_wakeup(&adev->dev, 1);
388
383 return 0; 389 return 0;
384 390
385out_no_irq: 391out_no_irq:
diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
index d00bd24342a3..f1a6557261f3 100644
--- a/drivers/rtc/rtc-pm8xxx.c
+++ b/drivers/rtc/rtc-pm8xxx.c
@@ -382,7 +382,7 @@ rtc_alarm_handled:
382 return IRQ_HANDLED; 382 return IRQ_HANDLED;
383} 383}
384 384
385static int __devinit pm8xxx_rtc_probe(struct platform_device *pdev) 385static int pm8xxx_rtc_probe(struct platform_device *pdev)
386{ 386{
387 int rc; 387 int rc;
388 u8 ctrl_reg; 388 u8 ctrl_reg;
@@ -485,7 +485,7 @@ fail_rtc_enable:
485 return rc; 485 return rc;
486} 486}
487 487
488static int __devexit pm8xxx_rtc_remove(struct platform_device *pdev) 488static int pm8xxx_rtc_remove(struct platform_device *pdev)
489{ 489{
490 struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev); 490 struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
491 491
@@ -524,7 +524,7 @@ static SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, pm8xxx_rtc_suspend, pm8xxx_rtc_resum
524 524
525static struct platform_driver pm8xxx_rtc_driver = { 525static struct platform_driver pm8xxx_rtc_driver = {
526 .probe = pm8xxx_rtc_probe, 526 .probe = pm8xxx_rtc_probe,
527 .remove = __devexit_p(pm8xxx_rtc_remove), 527 .remove = pm8xxx_rtc_remove,
528 .driver = { 528 .driver = {
529 .name = PM8XXX_RTC_DEV_NAME, 529 .name = PM8XXX_RTC_DEV_NAME,
530 .owner = THIS_MODULE, 530 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index ab0acaeb2371..0407e13d4de4 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -220,7 +220,7 @@ static void puv3_rtc_enable(struct platform_device *pdev, int en)
220 } 220 }
221} 221}
222 222
223static int __devexit puv3_rtc_remove(struct platform_device *dev) 223static int puv3_rtc_remove(struct platform_device *dev)
224{ 224{
225 struct rtc_device *rtc = platform_get_drvdata(dev); 225 struct rtc_device *rtc = platform_get_drvdata(dev);
226 226
@@ -236,7 +236,7 @@ static int __devexit puv3_rtc_remove(struct platform_device *dev)
236 return 0; 236 return 0;
237} 237}
238 238
239static int __devinit puv3_rtc_probe(struct platform_device *pdev) 239static int puv3_rtc_probe(struct platform_device *pdev)
240{ 240{
241 struct rtc_device *rtc; 241 struct rtc_device *rtc;
242 struct resource *res; 242 struct resource *res;
@@ -328,7 +328,7 @@ static int puv3_rtc_resume(struct platform_device *pdev)
328 328
329static struct platform_driver puv3_rtc_driver = { 329static struct platform_driver puv3_rtc_driver = {
330 .probe = puv3_rtc_probe, 330 .probe = puv3_rtc_probe,
331 .remove = __devexit_p(puv3_rtc_remove), 331 .remove = puv3_rtc_remove,
332 .suspend = puv3_rtc_suspend, 332 .suspend = puv3_rtc_suspend,
333 .resume = puv3_rtc_resume, 333 .resume = puv3_rtc_resume,
334 .driver = { 334 .driver = {
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index f771b2ee4b18..03c85ee719a7 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -62,6 +62,10 @@
62#define RYxR_MONTH_S 5 62#define RYxR_MONTH_S 5
63#define RYxR_MONTH_MASK (0xf << RYxR_MONTH_S) 63#define RYxR_MONTH_MASK (0xf << RYxR_MONTH_S)
64#define RYxR_DAY_MASK 0x1f 64#define RYxR_DAY_MASK 0x1f
65#define RDxR_WOM_S 20
66#define RDxR_WOM_MASK (0x7 << RDxR_WOM_S)
67#define RDxR_DOW_S 17
68#define RDxR_DOW_MASK (0x7 << RDxR_DOW_S)
65#define RDxR_HOUR_S 12 69#define RDxR_HOUR_S 12
66#define RDxR_HOUR_MASK (0x1f << RDxR_HOUR_S) 70#define RDxR_HOUR_MASK (0x1f << RDxR_HOUR_S)
67#define RDxR_MIN_S 6 71#define RDxR_MIN_S 6
@@ -91,6 +95,7 @@ struct pxa_rtc {
91 spinlock_t lock; /* Protects this structure */ 95 spinlock_t lock; /* Protects this structure */
92}; 96};
93 97
98
94static u32 ryxr_calc(struct rtc_time *tm) 99static u32 ryxr_calc(struct rtc_time *tm)
95{ 100{
96 return ((tm->tm_year + 1900) << RYxR_YEAR_S) 101 return ((tm->tm_year + 1900) << RYxR_YEAR_S)
@@ -100,7 +105,10 @@ static u32 ryxr_calc(struct rtc_time *tm)
100 105
101static u32 rdxr_calc(struct rtc_time *tm) 106static u32 rdxr_calc(struct rtc_time *tm)
102{ 107{
103 return (tm->tm_hour << RDxR_HOUR_S) | (tm->tm_min << RDxR_MIN_S) 108 return ((((tm->tm_mday + 6) / 7) << RDxR_WOM_S) & RDxR_WOM_MASK)
109 | (((tm->tm_wday + 1) << RDxR_DOW_S) & RDxR_DOW_MASK)
110 | (tm->tm_hour << RDxR_HOUR_S)
111 | (tm->tm_min << RDxR_MIN_S)
104 | tm->tm_sec; 112 | tm->tm_sec;
105} 113}
106 114
@@ -109,6 +117,7 @@ static void tm_calc(u32 rycr, u32 rdcr, struct rtc_time *tm)
109 tm->tm_year = ((rycr & RYxR_YEAR_MASK) >> RYxR_YEAR_S) - 1900; 117 tm->tm_year = ((rycr & RYxR_YEAR_MASK) >> RYxR_YEAR_S) - 1900;
110 tm->tm_mon = (((rycr & RYxR_MONTH_MASK) >> RYxR_MONTH_S)) - 1; 118 tm->tm_mon = (((rycr & RYxR_MONTH_MASK) >> RYxR_MONTH_S)) - 1;
111 tm->tm_mday = (rycr & RYxR_DAY_MASK); 119 tm->tm_mday = (rycr & RYxR_DAY_MASK);
120 tm->tm_wday = ((rycr & RDxR_DOW_MASK) >> RDxR_DOW_S) - 1;
112 tm->tm_hour = (rdcr & RDxR_HOUR_MASK) >> RDxR_HOUR_S; 121 tm->tm_hour = (rdcr & RDxR_HOUR_MASK) >> RDxR_HOUR_S;
113 tm->tm_min = (rdcr & RDxR_MIN_MASK) >> RDxR_MIN_S; 122 tm->tm_min = (rdcr & RDxR_MIN_MASK) >> RDxR_MIN_S;
114 tm->tm_sec = rdcr & RDxR_SEC_MASK; 123 tm->tm_sec = rdcr & RDxR_SEC_MASK;
@@ -300,8 +309,6 @@ static int pxa_rtc_proc(struct device *dev, struct seq_file *seq)
300} 309}
301 310
302static const struct rtc_class_ops pxa_rtc_ops = { 311static const struct rtc_class_ops pxa_rtc_ops = {
303 .open = pxa_rtc_open,
304 .release = pxa_rtc_release,
305 .read_time = pxa_rtc_read_time, 312 .read_time = pxa_rtc_read_time,
306 .set_time = pxa_rtc_set_time, 313 .set_time = pxa_rtc_set_time,
307 .read_alarm = pxa_rtc_read_alarm, 314 .read_alarm = pxa_rtc_read_alarm,
@@ -341,7 +348,7 @@ static int __init pxa_rtc_probe(struct platform_device *pdev)
341 dev_err(dev, "No alarm IRQ resource defined\n"); 348 dev_err(dev, "No alarm IRQ resource defined\n");
342 goto err_ress; 349 goto err_ress;
343 } 350 }
344 351 pxa_rtc_open(dev);
345 ret = -ENOMEM; 352 ret = -ENOMEM;
346 pxa_rtc->base = ioremap(pxa_rtc->ress->start, 353 pxa_rtc->base = ioremap(pxa_rtc->ress->start,
347 resource_size(pxa_rtc->ress)); 354 resource_size(pxa_rtc->ress));
@@ -387,6 +394,9 @@ static int __exit pxa_rtc_remove(struct platform_device *pdev)
387{ 394{
388 struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev); 395 struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
389 396
397 struct device *dev = &pdev->dev;
398 pxa_rtc_release(dev);
399
390 rtc_device_unregister(pxa_rtc->rtc); 400 rtc_device_unregister(pxa_rtc->rtc);
391 401
392 spin_lock_irq(&pxa_rtc->lock); 402 spin_lock_irq(&pxa_rtc->lock);
@@ -444,10 +454,7 @@ static struct platform_driver pxa_rtc_driver = {
444 454
445static int __init pxa_rtc_init(void) 455static int __init pxa_rtc_init(void)
446{ 456{
447 if (cpu_is_pxa27x() || cpu_is_pxa3xx()) 457 return platform_driver_probe(&pxa_rtc_driver, pxa_rtc_probe);
448 return platform_driver_probe(&pxa_rtc_driver, pxa_rtc_probe);
449
450 return -ENODEV;
451} 458}
452 459
453static void __exit pxa_rtc_exit(void) 460static void __exit pxa_rtc_exit(void)
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 2c183ebff715..7726f4a4f2d0 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -119,7 +119,7 @@ static const struct rtc_class_ops r9701_rtc_ops = {
119 .set_time = r9701_set_datetime, 119 .set_time = r9701_set_datetime,
120}; 120};
121 121
122static int __devinit r9701_probe(struct spi_device *spi) 122static int r9701_probe(struct spi_device *spi)
123{ 123{
124 struct rtc_device *rtc; 124 struct rtc_device *rtc;
125 struct rtc_time dt; 125 struct rtc_time dt;
@@ -164,7 +164,7 @@ static int __devinit r9701_probe(struct spi_device *spi)
164 return 0; 164 return 0;
165} 165}
166 166
167static int __devexit r9701_remove(struct spi_device *spi) 167static int r9701_remove(struct spi_device *spi)
168{ 168{
169 struct rtc_device *rtc = dev_get_drvdata(&spi->dev); 169 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
170 170
@@ -178,7 +178,7 @@ static struct spi_driver r9701_driver = {
178 .owner = THIS_MODULE, 178 .owner = THIS_MODULE,
179 }, 179 },
180 .probe = r9701_probe, 180 .probe = r9701_probe,
181 .remove = __devexit_p(r9701_remove), 181 .remove = r9701_remove,
182}; 182};
183 183
184module_spi_driver(r9701_driver); 184module_spi_driver(r9701_driver);
diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c
index cdb140c29c56..eb3194d664a8 100644
--- a/drivers/rtc/rtc-rc5t583.c
+++ b/drivers/rtc/rtc-rc5t583.c
@@ -211,7 +211,7 @@ static const struct rtc_class_ops rc5t583_rtc_ops = {
211 .alarm_irq_enable = rc5t583_rtc_alarm_irq_enable, 211 .alarm_irq_enable = rc5t583_rtc_alarm_irq_enable,
212}; 212};
213 213
214static int __devinit rc5t583_rtc_probe(struct platform_device *pdev) 214static int rc5t583_rtc_probe(struct platform_device *pdev)
215{ 215{
216 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent); 216 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
217 struct rc5t583_rtc *ricoh_rtc; 217 struct rc5t583_rtc *ricoh_rtc;
@@ -271,7 +271,7 @@ static int __devinit rc5t583_rtc_probe(struct platform_device *pdev)
271 * Disable rc5t583 RTC interrupts. 271 * Disable rc5t583 RTC interrupts.
272 * Sets status flag to free. 272 * Sets status flag to free.
273 */ 273 */
274static int __devexit rc5t583_rtc_remove(struct platform_device *pdev) 274static int rc5t583_rtc_remove(struct platform_device *pdev)
275{ 275{
276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev); 276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev);
277 277
@@ -317,7 +317,7 @@ static const struct dev_pm_ops rc5t583_rtc_pm_ops = {
317 317
318static struct platform_driver rc5t583_rtc_driver = { 318static struct platform_driver rc5t583_rtc_driver = {
319 .probe = rc5t583_rtc_probe, 319 .probe = rc5t583_rtc_probe,
320 .remove = __devexit_p(rc5t583_rtc_remove), 320 .remove = rc5t583_rtc_remove,
321 .driver = { 321 .driver = {
322 .owner = THIS_MODULE, 322 .owner = THIS_MODULE,
323 .name = "rtc-rc5t583", 323 .name = "rtc-rc5t583",
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index e3ff179b99ca..d98ea5b759c8 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -39,6 +39,8 @@
39 * 1.13 Nobuhiro Iwamatsu: Updata driver. 39 * 1.13 Nobuhiro Iwamatsu: Updata driver.
40 */ 40 */
41 41
42#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
42#include <linux/module.h> 44#include <linux/module.h>
43#include <linux/err.h> 45#include <linux/err.h>
44#include <linux/rtc.h> 46#include <linux/rtc.h>
@@ -352,8 +354,7 @@ static void rs5c313_check_xstp_bit(void)
352 tm.tm_year = 2000 - 1900; 354 tm.tm_year = 2000 - 1900;
353 355
354 rs5c313_rtc_set_time(NULL, &tm); 356 rs5c313_rtc_set_time(NULL, &tm);
355 printk(KERN_ERR "RICHO RS5C313: invalid value, resetting to " 357 pr_err("invalid value, resetting to 1 Jan 2000\n");
356 "1 Jan 2000\n");
357 } 358 }
358 RS5C313_CEDISABLE; 359 RS5C313_CEDISABLE;
359 ndelay(700); /* CE:L */ 360 ndelay(700); /* CE:L */
@@ -377,7 +378,7 @@ static int rs5c313_rtc_probe(struct platform_device *pdev)
377 return 0; 378 return 0;
378} 379}
379 380
380static int __devexit rs5c313_rtc_remove(struct platform_device *pdev) 381static int rs5c313_rtc_remove(struct platform_device *pdev)
381{ 382{
382 struct rtc_device *rtc = platform_get_drvdata( pdev ); 383 struct rtc_device *rtc = platform_get_drvdata( pdev );
383 384
@@ -392,7 +393,7 @@ static struct platform_driver rs5c313_rtc_platform_driver = {
392 .owner = THIS_MODULE, 393 .owner = THIS_MODULE,
393 }, 394 },
394 .probe = rs5c313_rtc_probe, 395 .probe = rs5c313_rtc_probe,
395 .remove = __devexit_p( rs5c313_rtc_remove ), 396 .remove = rs5c313_rtc_remove,
396}; 397};
397 398
398static int __init rs5c313_rtc_init(void) 399static int __init rs5c313_rtc_init(void)
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index fd5c7af04ae5..72ef10be8662 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -152,7 +152,7 @@ static const struct rtc_class_ops rs5c348_rtc_ops = {
152 152
153static struct spi_driver rs5c348_driver; 153static struct spi_driver rs5c348_driver;
154 154
155static int __devinit rs5c348_probe(struct spi_device *spi) 155static int rs5c348_probe(struct spi_device *spi)
156{ 156{
157 int ret; 157 int ret;
158 struct rtc_device *rtc; 158 struct rtc_device *rtc;
@@ -218,7 +218,7 @@ static int __devinit rs5c348_probe(struct spi_device *spi)
218 return ret; 218 return ret;
219} 219}
220 220
221static int __devexit rs5c348_remove(struct spi_device *spi) 221static int rs5c348_remove(struct spi_device *spi)
222{ 222{
223 struct rs5c348_plat_data *pdata = spi->dev.platform_data; 223 struct rs5c348_plat_data *pdata = spi->dev.platform_data;
224 struct rtc_device *rtc = pdata->rtc; 224 struct rtc_device *rtc = pdata->rtc;
@@ -235,7 +235,7 @@ static struct spi_driver rs5c348_driver = {
235 .owner = THIS_MODULE, 235 .owner = THIS_MODULE,
236 }, 236 },
237 .probe = rs5c348_probe, 237 .probe = rs5c348_probe,
238 .remove = __devexit_p(rs5c348_remove), 238 .remove = rs5c348_remove,
239}; 239};
240 240
241module_spi_driver(rs5c348_driver); 241module_spi_driver(rs5c348_driver);
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 76f565ae384d..581739f40097 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -311,8 +311,7 @@ static int rs5c_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
311 buf &= ~RS5C_CTRL1_AALE; 311 buf &= ~RS5C_CTRL1_AALE;
312 312
313 if (i2c_smbus_write_byte_data(client, addr, buf) < 0) { 313 if (i2c_smbus_write_byte_data(client, addr, buf) < 0) {
314 printk(KERN_WARNING "%s: can't update alarm\n", 314 dev_warn(dev, "can't update alarm\n");
315 rs5c->rtc->name);
316 status = -EIO; 315 status = -EIO;
317 } else 316 } else
318 rs5c->regs[RS5C_REG_CTRL1] = buf; 317 rs5c->regs[RS5C_REG_CTRL1] = buf;
@@ -381,7 +380,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
381 addr = RS5C_ADDR(RS5C_REG_CTRL1); 380 addr = RS5C_ADDR(RS5C_REG_CTRL1);
382 buf[0] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE; 381 buf[0] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE;
383 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0) { 382 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0) {
384 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name); 383 dev_dbg(dev, "can't disable alarm\n");
385 return -EIO; 384 return -EIO;
386 } 385 }
387 rs5c->regs[RS5C_REG_CTRL1] = buf[0]; 386 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
@@ -395,7 +394,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
395 for (i = 0; i < sizeof(buf); i++) { 394 for (i = 0; i < sizeof(buf); i++) {
396 addr = RS5C_ADDR(RS5C_REG_ALARM_A_MIN + i); 395 addr = RS5C_ADDR(RS5C_REG_ALARM_A_MIN + i);
397 if (i2c_smbus_write_byte_data(client, addr, buf[i]) < 0) { 396 if (i2c_smbus_write_byte_data(client, addr, buf[i]) < 0) {
398 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name); 397 dev_dbg(dev, "can't set alarm time\n");
399 return -EIO; 398 return -EIO;
400 } 399 }
401 } 400 }
@@ -405,8 +404,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
405 addr = RS5C_ADDR(RS5C_REG_CTRL1); 404 addr = RS5C_ADDR(RS5C_REG_CTRL1);
406 buf[0] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE; 405 buf[0] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE;
407 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0) 406 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0)
408 printk(KERN_WARNING "%s: can't enable alarm\n", 407 dev_warn(dev, "can't enable alarm\n");
409 rs5c->rtc->name);
410 rs5c->regs[RS5C_REG_CTRL1] = buf[0]; 408 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
411 } 409 }
412 410
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 0fbe57b2f6d2..f8ee8ad7825e 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -385,8 +385,8 @@ static struct i2c_device_id rv3029c2_id[] = {
385}; 385};
386MODULE_DEVICE_TABLE(i2c, rv3029c2_id); 386MODULE_DEVICE_TABLE(i2c, rv3029c2_id);
387 387
388static int __devinit 388static int rv3029c2_probe(struct i2c_client *client,
389rv3029c2_probe(struct i2c_client *client, const struct i2c_device_id *id) 389 const struct i2c_device_id *id)
390{ 390{
391 struct rtc_device *rtc; 391 struct rtc_device *rtc;
392 int rc = 0; 392 int rc = 0;
@@ -418,7 +418,7 @@ exit_unregister:
418 return rc; 418 return rc;
419} 419}
420 420
421static int __devexit rv3029c2_remove(struct i2c_client *client) 421static int rv3029c2_remove(struct i2c_client *client)
422{ 422{
423 struct rtc_device *rtc = i2c_get_clientdata(client); 423 struct rtc_device *rtc = i2c_get_clientdata(client);
424 424
@@ -432,7 +432,7 @@ static struct i2c_driver rv3029c2_driver = {
432 .name = "rtc-rv3029c2", 432 .name = "rtc-rv3029c2",
433 }, 433 },
434 .probe = rv3029c2_probe, 434 .probe = rv3029c2_probe,
435 .remove = __devexit_p(rv3029c2_remove), 435 .remove = rv3029c2_remove,
436 .id_table = rv3029c2_id, 436 .id_table = rv3029c2_id,
437}; 437};
438 438
diff --git a/drivers/rtc/rtc-rx4581.c b/drivers/rtc/rtc-rx4581.c
new file mode 100644
index 000000000000..599ec73ec886
--- /dev/null
+++ b/drivers/rtc/rtc-rx4581.c
@@ -0,0 +1,314 @@
1/* drivers/rtc/rtc-rx4581.c
2 *
3 * written by Torben Hohn <torbenh@linutronix.de>
4 *
5 * Based on:
6 * drivers/rtc/rtc-max6902.c
7 *
8 * Copyright (C) 2006 8D Technologies inc.
9 * Copyright (C) 2004 Compulab Ltd.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * Driver for MAX6902 spi RTC
16 *
17 * and based on:
18 * drivers/rtc/rtc-rx8581.c
19 *
20 * An I2C driver for the Epson RX8581 RTC
21 *
22 * Author: Martyn Welch <martyn.welch@ge.com>
23 * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License version 2 as
27 * published by the Free Software Foundation.
28 *
29 * Based on: rtc-pcf8563.c (An I2C driver for the Philips PCF8563 RTC)
30 * Copyright 2005-06 Tower Technologies
31 *
32 */
33
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/platform_device.h>
37#include <linux/init.h>
38#include <linux/rtc.h>
39#include <linux/spi/spi.h>
40#include <linux/bcd.h>
41
42#define RX4581_REG_SC 0x00 /* Second in BCD */
43#define RX4581_REG_MN 0x01 /* Minute in BCD */
44#define RX4581_REG_HR 0x02 /* Hour in BCD */
45#define RX4581_REG_DW 0x03 /* Day of Week */
46#define RX4581_REG_DM 0x04 /* Day of Month in BCD */
47#define RX4581_REG_MO 0x05 /* Month in BCD */
48#define RX4581_REG_YR 0x06 /* Year in BCD */
49#define RX4581_REG_RAM 0x07 /* RAM */
50#define RX4581_REG_AMN 0x08 /* Alarm Min in BCD*/
51#define RX4581_REG_AHR 0x09 /* Alarm Hour in BCD */
52#define RX4581_REG_ADM 0x0A
53#define RX4581_REG_ADW 0x0A
54#define RX4581_REG_TMR0 0x0B
55#define RX4581_REG_TMR1 0x0C
56#define RX4581_REG_EXT 0x0D /* Extension Register */
57#define RX4581_REG_FLAG 0x0E /* Flag Register */
58#define RX4581_REG_CTRL 0x0F /* Control Register */
59
60
61/* Flag Register bit definitions */
62#define RX4581_FLAG_UF 0x20 /* Update */
63#define RX4581_FLAG_TF 0x10 /* Timer */
64#define RX4581_FLAG_AF 0x08 /* Alarm */
65#define RX4581_FLAG_VLF 0x02 /* Voltage Low */
66
67/* Control Register bit definitions */
68#define RX4581_CTRL_UIE 0x20 /* Update Interrupt Enable */
69#define RX4581_CTRL_TIE 0x10 /* Timer Interrupt Enable */
70#define RX4581_CTRL_AIE 0x08 /* Alarm Interrupt Enable */
71#define RX4581_CTRL_STOP 0x02 /* STOP bit */
72#define RX4581_CTRL_RESET 0x01 /* RESET bit */
73
74static int rx4581_set_reg(struct device *dev, unsigned char address,
75 unsigned char data)
76{
77 struct spi_device *spi = to_spi_device(dev);
78 unsigned char buf[2];
79
80 /* high nibble must be '0' to write */
81 buf[0] = address & 0x0f;
82 buf[1] = data;
83
84 return spi_write_then_read(spi, buf, 2, NULL, 0);
85}
86
87static int rx4581_get_reg(struct device *dev, unsigned char address,
88 unsigned char *data)
89{
90 struct spi_device *spi = to_spi_device(dev);
91
92 /* Set MSB to indicate read */
93 *data = address | 0x80;
94
95 return spi_write_then_read(spi, data, 1, data, 1);
96}
97
98/*
99 * In the routines that deal directly with the rx8581 hardware, we use
100 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
101 */
102static int rx4581_get_datetime(struct device *dev, struct rtc_time *tm)
103{
104 struct spi_device *spi = to_spi_device(dev);
105 unsigned char date[7];
106 unsigned char data;
107 int err;
108
109 /* First we ensure that the "update flag" is not set, we read the
110 * time and date then re-read the "update flag". If the update flag
111 * has been set, we know that the time has changed during the read so
112 * we repeat the whole process again.
113 */
114 err = rx4581_get_reg(dev, RX4581_REG_FLAG, &data);
115 if (err != 0) {
116 dev_err(dev, "Unable to read device flags\n");
117 return -EIO;
118 }
119
120 do {
121 /* If update flag set, clear it */
122 if (data & RX4581_FLAG_UF) {
123 err = rx4581_set_reg(dev,
124 RX4581_REG_FLAG, (data & ~RX4581_FLAG_UF));
125 if (err != 0) {
126 dev_err(dev, "Unable to write device "
127 "flags\n");
128 return -EIO;
129 }
130 }
131
132 /* Now read time and date */
133 date[0] = 0x80;
134 err = spi_write_then_read(spi, date, 1, date, 7);
135 if (err < 0) {
136 dev_err(dev, "Unable to read date\n");
137 return -EIO;
138 }
139
140 /* Check flag register */
141 err = rx4581_get_reg(dev, RX4581_REG_FLAG, &data);
142 if (err != 0) {
143 dev_err(dev, "Unable to read device flags\n");
144 return -EIO;
145 }
146 } while (data & RX4581_FLAG_UF);
147
148 if (data & RX4581_FLAG_VLF)
149 dev_info(dev,
150 "low voltage detected, date/time is not reliable.\n");
151
152 dev_dbg(dev,
153 "%s: raw data is sec=%02x, min=%02x, hr=%02x, "
154 "wday=%02x, mday=%02x, mon=%02x, year=%02x\n",
155 __func__,
156 date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
157
158 tm->tm_sec = bcd2bin(date[RX4581_REG_SC] & 0x7F);
159 tm->tm_min = bcd2bin(date[RX4581_REG_MN] & 0x7F);
160 tm->tm_hour = bcd2bin(date[RX4581_REG_HR] & 0x3F); /* rtc hr 0-23 */
161 tm->tm_wday = ilog2(date[RX4581_REG_DW] & 0x7F);
162 tm->tm_mday = bcd2bin(date[RX4581_REG_DM] & 0x3F);
163 tm->tm_mon = bcd2bin(date[RX4581_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
164 tm->tm_year = bcd2bin(date[RX4581_REG_YR]);
165 if (tm->tm_year < 70)
166 tm->tm_year += 100; /* assume we are in 1970...2069 */
167
168
169 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
170 "mday=%d, mon=%d, year=%d, wday=%d\n",
171 __func__,
172 tm->tm_sec, tm->tm_min, tm->tm_hour,
173 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
174
175 err = rtc_valid_tm(tm);
176 if (err < 0)
177 dev_err(dev, "retrieved date/time is not valid.\n");
178
179 return err;
180}
181
182static int rx4581_set_datetime(struct device *dev, struct rtc_time *tm)
183{
184 struct spi_device *spi = to_spi_device(dev);
185 int err;
186 unsigned char buf[8], data;
187
188 dev_dbg(dev, "%s: secs=%d, mins=%d, hours=%d, "
189 "mday=%d, mon=%d, year=%d, wday=%d\n",
190 __func__,
191 tm->tm_sec, tm->tm_min, tm->tm_hour,
192 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
193
194 buf[0] = 0x00;
195 /* hours, minutes and seconds */
196 buf[RX4581_REG_SC+1] = bin2bcd(tm->tm_sec);
197 buf[RX4581_REG_MN+1] = bin2bcd(tm->tm_min);
198 buf[RX4581_REG_HR+1] = bin2bcd(tm->tm_hour);
199
200 buf[RX4581_REG_DM+1] = bin2bcd(tm->tm_mday);
201
202 /* month, 1 - 12 */
203 buf[RX4581_REG_MO+1] = bin2bcd(tm->tm_mon + 1);
204
205 /* year and century */
206 buf[RX4581_REG_YR+1] = bin2bcd(tm->tm_year % 100);
207 buf[RX4581_REG_DW+1] = (0x1 << tm->tm_wday);
208
209 /* Stop the clock */
210 err = rx4581_get_reg(dev, RX4581_REG_CTRL, &data);
211 if (err != 0) {
212 dev_err(dev, "Unable to read control register\n");
213 return -EIO;
214 }
215
216 err = rx4581_set_reg(dev, RX4581_REG_CTRL,
217 (data | RX4581_CTRL_STOP));
218 if (err != 0) {
219 dev_err(dev, "Unable to write control register\n");
220 return -EIO;
221 }
222
223 /* write register's data */
224 err = spi_write_then_read(spi, buf, 8, NULL, 0);
225 if (err != 0) {
226 dev_err(dev, "Unable to write to date registers\n");
227 return -EIO;
228 }
229
230 /* get VLF and clear it */
231 err = rx4581_get_reg(dev, RX4581_REG_FLAG, &data);
232 if (err != 0) {
233 dev_err(dev, "Unable to read flag register\n");
234 return -EIO;
235 }
236
237 err = rx4581_set_reg(dev, RX4581_REG_FLAG,
238 (data & ~(RX4581_FLAG_VLF)));
239 if (err != 0) {
240 dev_err(dev, "Unable to write flag register\n");
241 return -EIO;
242 }
243
244 /* Restart the clock */
245 err = rx4581_get_reg(dev, RX4581_REG_CTRL, &data);
246 if (err != 0) {
247 dev_err(dev, "Unable to read control register\n");
248 return -EIO;
249 }
250
251 err = rx4581_set_reg(dev, RX4581_REG_CTRL,
252 (data & ~(RX4581_CTRL_STOP)));
253 if (err != 0) {
254 dev_err(dev, "Unable to write control register\n");
255 return -EIO;
256 }
257
258 return 0;
259}
260
261static const struct rtc_class_ops rx4581_rtc_ops = {
262 .read_time = rx4581_get_datetime,
263 .set_time = rx4581_set_datetime,
264};
265
266static int rx4581_probe(struct spi_device *spi)
267{
268 struct rtc_device *rtc;
269 unsigned char tmp;
270 int res;
271
272 res = rx4581_get_reg(&spi->dev, RX4581_REG_SC, &tmp);
273 if (res != 0)
274 return res;
275
276 rtc = rtc_device_register("rx4581",
277 &spi->dev, &rx4581_rtc_ops, THIS_MODULE);
278 if (IS_ERR(rtc))
279 return PTR_ERR(rtc);
280
281 dev_set_drvdata(&spi->dev, rtc);
282 return 0;
283}
284
285static int rx4581_remove(struct spi_device *spi)
286{
287 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
288
289 rtc_device_unregister(rtc);
290 return 0;
291}
292
293static const struct spi_device_id rx4581_id[] = {
294 { "rx4581", 0 },
295 { }
296};
297MODULE_DEVICE_TABLE(spi, rx4581_id);
298
299static struct spi_driver rx4581_driver = {
300 .driver = {
301 .name = "rtc-rx4581",
302 .owner = THIS_MODULE,
303 },
304 .probe = rx4581_probe,
305 .remove = rx4581_remove,
306 .id_table = rx4581_id,
307};
308
309module_spi_driver(rx4581_driver);
310
311MODULE_DESCRIPTION("rx4581 spi RTC driver");
312MODULE_AUTHOR("Torben Hohn");
313MODULE_LICENSE("GPL");
314MODULE_ALIAS("spi:rtc-rx4581");
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index 0de902dc1cd5..0722d36b9c9a 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -534,8 +534,8 @@ static void rx8025_sysfs_unregister(struct device *dev)
534 device_remove_file(dev, &dev_attr_clock_adjust_ppb); 534 device_remove_file(dev, &dev_attr_clock_adjust_ppb);
535} 535}
536 536
537static int __devinit rx8025_probe(struct i2c_client *client, 537static int rx8025_probe(struct i2c_client *client,
538 const struct i2c_device_id *id) 538 const struct i2c_device_id *id)
539{ 539{
540 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 540 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
541 struct rx8025_data *rx8025; 541 struct rx8025_data *rx8025;
@@ -614,7 +614,7 @@ errout:
614 return err; 614 return err;
615} 615}
616 616
617static int __devexit rx8025_remove(struct i2c_client *client) 617static int rx8025_remove(struct i2c_client *client)
618{ 618{
619 struct rx8025_data *rx8025 = i2c_get_clientdata(client); 619 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
620 struct mutex *lock = &rx8025->rtc->ops_lock; 620 struct mutex *lock = &rx8025->rtc->ops_lock;
@@ -640,7 +640,7 @@ static struct i2c_driver rx8025_driver = {
640 .owner = THIS_MODULE, 640 .owner = THIS_MODULE,
641 }, 641 },
642 .probe = rx8025_probe, 642 .probe = rx8025_probe,
643 .remove = __devexit_p(rx8025_remove), 643 .remove = rx8025_remove,
644 .id_table = rx8025_id, 644 .id_table = rx8025_id,
645}; 645};
646 646
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index d84825124a7a..b0c272658fa2 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -228,8 +228,8 @@ static const struct rtc_class_ops rx8581_rtc_ops = {
228 .set_time = rx8581_rtc_set_time, 228 .set_time = rx8581_rtc_set_time,
229}; 229};
230 230
231static int __devinit rx8581_probe(struct i2c_client *client, 231static int rx8581_probe(struct i2c_client *client,
232 const struct i2c_device_id *id) 232 const struct i2c_device_id *id)
233{ 233{
234 struct rtc_device *rtc; 234 struct rtc_device *rtc;
235 235
@@ -251,7 +251,7 @@ static int __devinit rx8581_probe(struct i2c_client *client,
251 return 0; 251 return 0;
252} 252}
253 253
254static int __devexit rx8581_remove(struct i2c_client *client) 254static int rx8581_remove(struct i2c_client *client)
255{ 255{
256 struct rtc_device *rtc = i2c_get_clientdata(client); 256 struct rtc_device *rtc = i2c_get_clientdata(client);
257 257
@@ -272,7 +272,7 @@ static struct i2c_driver rx8581_driver = {
272 .owner = THIS_MODULE, 272 .owner = THIS_MODULE,
273 }, 273 },
274 .probe = rx8581_probe, 274 .probe = rx8581_probe,
275 .remove = __devexit_p(rx8581_remove), 275 .remove = rx8581_remove,
276 .id_table = rx8581_id, 276 .id_table = rx8581_id,
277}; 277};
278 278
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index a7a2a998fa91..fb994e9ddc15 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -47,8 +47,6 @@ struct s3c_rtc_drv_data {
47/* I have yet to find an S3C implementation with more than one 47/* I have yet to find an S3C implementation with more than one
48 * of these rtc blocks in */ 48 * of these rtc blocks in */
49 49
50static struct resource *s3c_rtc_mem;
51
52static struct clk *rtc_clk; 50static struct clk *rtc_clk;
53static void __iomem *s3c_rtc_base; 51static void __iomem *s3c_rtc_base;
54static int s3c_rtc_alarmno = NO_IRQ; 52static int s3c_rtc_alarmno = NO_IRQ;
@@ -117,7 +115,7 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
117{ 115{
118 unsigned int tmp; 116 unsigned int tmp;
119 117
120 pr_debug("%s: aie=%d\n", __func__, enabled); 118 dev_dbg(dev, "%s: aie=%d\n", __func__, enabled);
121 119
122 clk_enable(rtc_clk); 120 clk_enable(rtc_clk);
123 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN; 121 tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
@@ -205,7 +203,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
205 203
206 rtc_tm->tm_year += 100; 204 rtc_tm->tm_year += 100;
207 205
208 pr_debug("read time %04d.%02d.%02d %02d:%02d:%02d\n", 206 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
209 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 207 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
210 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 208 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
211 209
@@ -220,7 +218,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
220 void __iomem *base = s3c_rtc_base; 218 void __iomem *base = s3c_rtc_base;
221 int year = tm->tm_year - 100; 219 int year = tm->tm_year - 100;
222 220
223 pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n", 221 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
224 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday, 222 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
225 tm->tm_hour, tm->tm_min, tm->tm_sec); 223 tm->tm_hour, tm->tm_min, tm->tm_sec);
226 224
@@ -261,7 +259,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
261 259
262 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 260 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
263 261
264 pr_debug("read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", 262 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
265 alm_en, 263 alm_en,
266 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, 264 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
267 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec); 265 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
@@ -312,7 +310,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
312 unsigned int alrm_en; 310 unsigned int alrm_en;
313 311
314 clk_enable(rtc_clk); 312 clk_enable(rtc_clk);
315 pr_debug("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 313 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
316 alrm->enabled, 314 alrm->enabled,
317 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, 315 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
318 tm->tm_hour, tm->tm_min, tm->tm_sec); 316 tm->tm_hour, tm->tm_min, tm->tm_sec);
@@ -335,7 +333,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
335 writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR); 333 writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
336 } 334 }
337 335
338 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en); 336 dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);
339 337
340 writeb(alrm_en, base + S3C2410_RTCALM); 338 writeb(alrm_en, base + S3C2410_RTCALM);
341 339
@@ -423,25 +421,17 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
423 clk_disable(rtc_clk); 421 clk_disable(rtc_clk);
424} 422}
425 423
426static int __devexit s3c_rtc_remove(struct platform_device *dev) 424static int s3c_rtc_remove(struct platform_device *dev)
427{ 425{
428 struct rtc_device *rtc = platform_get_drvdata(dev); 426 struct rtc_device *rtc = platform_get_drvdata(dev);
429 427
430 free_irq(s3c_rtc_alarmno, rtc);
431 free_irq(s3c_rtc_tickno, rtc);
432
433 platform_set_drvdata(dev, NULL); 428 platform_set_drvdata(dev, NULL);
434 rtc_device_unregister(rtc); 429 rtc_device_unregister(rtc);
435 430
436 s3c_rtc_setaie(&dev->dev, 0); 431 s3c_rtc_setaie(&dev->dev, 0);
437 432
438 clk_put(rtc_clk);
439 rtc_clk = NULL; 433 rtc_clk = NULL;
440 434
441 iounmap(s3c_rtc_base);
442 release_resource(s3c_rtc_mem);
443 kfree(s3c_rtc_mem);
444
445 return 0; 435 return 0;
446} 436}
447 437
@@ -461,7 +451,7 @@ static inline int s3c_rtc_get_driver_data(struct platform_device *pdev)
461 return platform_get_device_id(pdev)->driver_data; 451 return platform_get_device_id(pdev)->driver_data;
462} 452}
463 453
464static int __devinit s3c_rtc_probe(struct platform_device *pdev) 454static int s3c_rtc_probe(struct platform_device *pdev)
465{ 455{
466 struct rtc_device *rtc; 456 struct rtc_device *rtc;
467 struct rtc_time rtc_tm; 457 struct rtc_time rtc_tm;
@@ -469,7 +459,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
469 int ret; 459 int ret;
470 int tmp; 460 int tmp;
471 461
472 pr_debug("%s: probe=%p\n", __func__, pdev); 462 dev_dbg(&pdev->dev, "%s: probe=%p\n", __func__, pdev);
473 463
474 /* find the IRQs */ 464 /* find the IRQs */
475 465
@@ -485,7 +475,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
485 return s3c_rtc_alarmno; 475 return s3c_rtc_alarmno;
486 } 476 }
487 477
488 pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n", 478 dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
489 s3c_rtc_tickno, s3c_rtc_alarmno); 479 s3c_rtc_tickno, s3c_rtc_alarmno);
490 480
491 /* get the memory region */ 481 /* get the memory region */
@@ -496,28 +486,16 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
496 return -ENOENT; 486 return -ENOENT;
497 } 487 }
498 488
499 s3c_rtc_mem = request_mem_region(res->start, resource_size(res), 489 s3c_rtc_base = devm_ioremap_resource(&pdev->dev, res);
500 pdev->name); 490 if (IS_ERR(s3c_rtc_base))
501 491 return PTR_ERR(s3c_rtc_base);
502 if (s3c_rtc_mem == NULL) {
503 dev_err(&pdev->dev, "failed to reserve memory region\n");
504 ret = -ENOENT;
505 goto err_nores;
506 }
507
508 s3c_rtc_base = ioremap(res->start, resource_size(res));
509 if (s3c_rtc_base == NULL) {
510 dev_err(&pdev->dev, "failed ioremap()\n");
511 ret = -EINVAL;
512 goto err_nomap;
513 }
514 492
515 rtc_clk = clk_get(&pdev->dev, "rtc"); 493 rtc_clk = devm_clk_get(&pdev->dev, "rtc");
516 if (IS_ERR(rtc_clk)) { 494 if (IS_ERR(rtc_clk)) {
517 dev_err(&pdev->dev, "failed to find rtc clock source\n"); 495 dev_err(&pdev->dev, "failed to find rtc clock source\n");
518 ret = PTR_ERR(rtc_clk); 496 ret = PTR_ERR(rtc_clk);
519 rtc_clk = NULL; 497 rtc_clk = NULL;
520 goto err_clk; 498 return ret;
521 } 499 }
522 500
523 clk_enable(rtc_clk); 501 clk_enable(rtc_clk);
@@ -526,7 +504,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
526 504
527 s3c_rtc_enable(pdev, 1); 505 s3c_rtc_enable(pdev, 1);
528 506
529 pr_debug("s3c2410_rtc: RTCCON=%02x\n", 507 dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n",
530 readw(s3c_rtc_base + S3C2410_RTCCON)); 508 readw(s3c_rtc_base + S3C2410_RTCCON));
531 509
532 device_init_wakeup(&pdev->dev, 1); 510 device_init_wakeup(&pdev->dev, 1);
@@ -576,28 +554,24 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
576 554
577 s3c_rtc_setfreq(&pdev->dev, 1); 555 s3c_rtc_setfreq(&pdev->dev, 1);
578 556
579 ret = request_irq(s3c_rtc_alarmno, s3c_rtc_alarmirq, 557 ret = devm_request_irq(&pdev->dev, s3c_rtc_alarmno, s3c_rtc_alarmirq,
580 0, "s3c2410-rtc alarm", rtc); 558 0, "s3c2410-rtc alarm", rtc);
581 if (ret) { 559 if (ret) {
582 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_alarmno, ret); 560 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_alarmno, ret);
583 goto err_alarm_irq; 561 goto err_alarm_irq;
584 } 562 }
585 563
586 ret = request_irq(s3c_rtc_tickno, s3c_rtc_tickirq, 564 ret = devm_request_irq(&pdev->dev, s3c_rtc_tickno, s3c_rtc_tickirq,
587 0, "s3c2410-rtc tick", rtc); 565 0, "s3c2410-rtc tick", rtc);
588 if (ret) { 566 if (ret) {
589 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_tickno, ret); 567 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_tickno, ret);
590 free_irq(s3c_rtc_alarmno, rtc); 568 goto err_alarm_irq;
591 goto err_tick_irq;
592 } 569 }
593 570
594 clk_disable(rtc_clk); 571 clk_disable(rtc_clk);
595 572
596 return 0; 573 return 0;
597 574
598 err_tick_irq:
599 free_irq(s3c_rtc_alarmno, rtc);
600
601 err_alarm_irq: 575 err_alarm_irq:
602 platform_set_drvdata(pdev, NULL); 576 platform_set_drvdata(pdev, NULL);
603 rtc_device_unregister(rtc); 577 rtc_device_unregister(rtc);
@@ -605,15 +579,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
605 err_nortc: 579 err_nortc:
606 s3c_rtc_enable(pdev, 0); 580 s3c_rtc_enable(pdev, 0);
607 clk_disable(rtc_clk); 581 clk_disable(rtc_clk);
608 clk_put(rtc_clk);
609 582
610 err_clk:
611 iounmap(s3c_rtc_base);
612
613 err_nomap:
614 release_resource(s3c_rtc_mem);
615
616 err_nores:
617 return ret; 583 return ret;
618} 584}
619 585
@@ -695,8 +661,6 @@ static const struct of_device_id s3c_rtc_dt_match[] = {
695 {}, 661 {},
696}; 662};
697MODULE_DEVICE_TABLE(of, s3c_rtc_dt_match); 663MODULE_DEVICE_TABLE(of, s3c_rtc_dt_match);
698#else
699#define s3c_rtc_dt_match NULL
700#endif 664#endif
701 665
702static struct platform_device_id s3c_rtc_driver_ids[] = { 666static struct platform_device_id s3c_rtc_driver_ids[] = {
@@ -720,14 +684,14 @@ MODULE_DEVICE_TABLE(platform, s3c_rtc_driver_ids);
720 684
721static struct platform_driver s3c_rtc_driver = { 685static struct platform_driver s3c_rtc_driver = {
722 .probe = s3c_rtc_probe, 686 .probe = s3c_rtc_probe,
723 .remove = __devexit_p(s3c_rtc_remove), 687 .remove = s3c_rtc_remove,
724 .suspend = s3c_rtc_suspend, 688 .suspend = s3c_rtc_suspend,
725 .resume = s3c_rtc_resume, 689 .resume = s3c_rtc_resume,
726 .id_table = s3c_rtc_driver_ids, 690 .id_table = s3c_rtc_driver_ids,
727 .driver = { 691 .driver = {
728 .name = "s3c-rtc", 692 .name = "s3c-rtc",
729 .owner = THIS_MODULE, 693 .owner = THIS_MODULE,
730 .of_match_table = s3c_rtc_dt_match, 694 .of_match_table = of_match_ptr(s3c_rtc_dt_match),
731 }, 695 },
732}; 696};
733 697
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 50a5c4adee48..5ec5036df0bc 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -108,9 +108,6 @@ static int sa1100_rtc_open(struct device *dev)
108 struct rtc_device *rtc = info->rtc; 108 struct rtc_device *rtc = info->rtc;
109 int ret; 109 int ret;
110 110
111 ret = clk_prepare_enable(info->clk);
112 if (ret)
113 goto fail_clk;
114 ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, 0, "rtc 1Hz", dev); 111 ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, 0, "rtc 1Hz", dev);
115 if (ret) { 112 if (ret) {
116 dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz); 113 dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz);
@@ -130,7 +127,6 @@ static int sa1100_rtc_open(struct device *dev)
130 free_irq(info->irq_1hz, dev); 127 free_irq(info->irq_1hz, dev);
131 fail_ui: 128 fail_ui:
132 clk_disable_unprepare(info->clk); 129 clk_disable_unprepare(info->clk);
133 fail_clk:
134 return ret; 130 return ret;
135} 131}
136 132
@@ -144,7 +140,6 @@ static void sa1100_rtc_release(struct device *dev)
144 140
145 free_irq(info->irq_alarm, dev); 141 free_irq(info->irq_alarm, dev);
146 free_irq(info->irq_1hz, dev); 142 free_irq(info->irq_1hz, dev);
147 clk_disable_unprepare(info->clk);
148} 143}
149 144
150static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 145static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
@@ -253,6 +248,9 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
253 spin_lock_init(&info->lock); 248 spin_lock_init(&info->lock);
254 platform_set_drvdata(pdev, info); 249 platform_set_drvdata(pdev, info);
255 250
251 ret = clk_prepare_enable(info->clk);
252 if (ret)
253 goto err_enable_clk;
256 /* 254 /*
257 * According to the manual we should be able to let RTTR be zero 255 * According to the manual we should be able to let RTTR be zero
258 * and then a default diviser for a 32.768KHz clock is used. 256 * and then a default diviser for a 32.768KHz clock is used.
@@ -305,6 +303,8 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
305 303
306 return 0; 304 return 0;
307err_dev: 305err_dev:
306 clk_disable_unprepare(info->clk);
307err_enable_clk:
308 platform_set_drvdata(pdev, NULL); 308 platform_set_drvdata(pdev, NULL);
309 clk_put(info->clk); 309 clk_put(info->clk);
310err_clk: 310err_clk:
@@ -318,6 +318,7 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
318 318
319 if (info) { 319 if (info) {
320 rtc_device_unregister(info->rtc); 320 rtc_device_unregister(info->rtc);
321 clk_disable_unprepare(info->clk);
321 clk_put(info->clk); 322 clk_put(info->clk);
322 platform_set_drvdata(pdev, NULL); 323 platform_set_drvdata(pdev, NULL);
323 kfree(info); 324 kfree(info);
@@ -349,12 +350,14 @@ static const struct dev_pm_ops sa1100_rtc_pm_ops = {
349}; 350};
350#endif 351#endif
351 352
353#ifdef CONFIG_OF
352static struct of_device_id sa1100_rtc_dt_ids[] = { 354static struct of_device_id sa1100_rtc_dt_ids[] = {
353 { .compatible = "mrvl,sa1100-rtc", }, 355 { .compatible = "mrvl,sa1100-rtc", },
354 { .compatible = "mrvl,mmp-rtc", }, 356 { .compatible = "mrvl,mmp-rtc", },
355 {} 357 {}
356}; 358};
357MODULE_DEVICE_TABLE(of, sa1100_rtc_dt_ids); 359MODULE_DEVICE_TABLE(of, sa1100_rtc_dt_ids);
360#endif
358 361
359static struct platform_driver sa1100_rtc_driver = { 362static struct platform_driver sa1100_rtc_driver = {
360 .probe = sa1100_rtc_probe, 363 .probe = sa1100_rtc_probe,
@@ -364,7 +367,7 @@ static struct platform_driver sa1100_rtc_driver = {
364#ifdef CONFIG_PM 367#ifdef CONFIG_PM
365 .pm = &sa1100_rtc_pm_ops, 368 .pm = &sa1100_rtc_pm_ops,
366#endif 369#endif
367 .of_match_table = sa1100_rtc_dt_ids, 370 .of_match_table = of_match_ptr(sa1100_rtc_dt_ids),
368 }, 371 },
369}; 372};
370 373
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 3c0da333f465..f7d90703db5e 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -241,7 +241,7 @@ static irqreturn_t snvs_rtc_irq_handler(int irq, void *dev_id)
241 return events ? IRQ_HANDLED : IRQ_NONE; 241 return events ? IRQ_HANDLED : IRQ_NONE;
242} 242}
243 243
244static int __devinit snvs_rtc_probe(struct platform_device *pdev) 244static int snvs_rtc_probe(struct platform_device *pdev)
245{ 245{
246 struct snvs_rtc_data *data; 246 struct snvs_rtc_data *data;
247 struct resource *res; 247 struct resource *res;
@@ -252,9 +252,9 @@ static int __devinit snvs_rtc_probe(struct platform_device *pdev)
252 return -ENOMEM; 252 return -ENOMEM;
253 253
254 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 254 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
255 data->ioaddr = devm_request_and_ioremap(&pdev->dev, res); 255 data->ioaddr = devm_ioremap_resource(&pdev->dev, res);
256 if (!data->ioaddr) 256 if (IS_ERR(data->ioaddr))
257 return -EADDRNOTAVAIL; 257 return PTR_ERR(data->ioaddr);
258 258
259 data->irq = platform_get_irq(pdev, 0); 259 data->irq = platform_get_irq(pdev, 0);
260 if (data->irq < 0) 260 if (data->irq < 0)
@@ -294,7 +294,7 @@ static int __devinit snvs_rtc_probe(struct platform_device *pdev)
294 return 0; 294 return 0;
295} 295}
296 296
297static int __devexit snvs_rtc_remove(struct platform_device *pdev) 297static int snvs_rtc_remove(struct platform_device *pdev)
298{ 298{
299 struct snvs_rtc_data *data = platform_get_drvdata(pdev); 299 struct snvs_rtc_data *data = platform_get_drvdata(pdev);
300 300
@@ -327,7 +327,7 @@ static int snvs_rtc_resume(struct device *dev)
327 327
328static SIMPLE_DEV_PM_OPS(snvs_rtc_pm_ops, snvs_rtc_suspend, snvs_rtc_resume); 328static SIMPLE_DEV_PM_OPS(snvs_rtc_pm_ops, snvs_rtc_suspend, snvs_rtc_resume);
329 329
330static const struct of_device_id __devinitconst snvs_dt_ids[] = { 330static const struct of_device_id snvs_dt_ids[] = {
331 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", }, 331 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", },
332 { /* sentinel */ } 332 { /* sentinel */ }
333}; 333};
@@ -338,10 +338,10 @@ static struct platform_driver snvs_rtc_driver = {
338 .name = "snvs_rtc", 338 .name = "snvs_rtc",
339 .owner = THIS_MODULE, 339 .owner = THIS_MODULE,
340 .pm = &snvs_rtc_pm_ops, 340 .pm = &snvs_rtc_pm_ops,
341 .of_match_table = snvs_dt_ids, 341 .of_match_table = of_match_ptr(snvs_dt_ids),
342 }, 342 },
343 .probe = snvs_rtc_probe, 343 .probe = snvs_rtc_probe,
344 .remove = __devexit_p(snvs_rtc_remove), 344 .remove = snvs_rtc_remove,
345}; 345};
346module_platform_driver(snvs_rtc_driver); 346module_platform_driver(snvs_rtc_driver);
347 347
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index bb507d23f6ce..a18c3192ed40 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -351,7 +351,7 @@ static struct rtc_class_ops spear_rtc_ops = {
351 .alarm_irq_enable = spear_alarm_irq_enable, 351 .alarm_irq_enable = spear_alarm_irq_enable,
352}; 352};
353 353
354static int __devinit spear_rtc_probe(struct platform_device *pdev) 354static int spear_rtc_probe(struct platform_device *pdev)
355{ 355{
356 struct resource *res; 356 struct resource *res;
357 struct spear_rtc_config *config; 357 struct spear_rtc_config *config;
@@ -363,35 +363,40 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
363 dev_err(&pdev->dev, "no resource defined\n"); 363 dev_err(&pdev->dev, "no resource defined\n");
364 return -EBUSY; 364 return -EBUSY;
365 } 365 }
366 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
367 dev_err(&pdev->dev, "rtc region already claimed\n");
368 return -EBUSY;
369 }
370 366
371 config = kzalloc(sizeof(*config), GFP_KERNEL); 367 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
372 if (!config) { 368 if (!config) {
373 dev_err(&pdev->dev, "out of memory\n"); 369 dev_err(&pdev->dev, "out of memory\n");
374 status = -ENOMEM; 370 return -ENOMEM;
375 goto err_release_region;
376 } 371 }
377 372
378 config->clk = clk_get(&pdev->dev, NULL); 373 /* alarm irqs */
379 if (IS_ERR(config->clk)) { 374 irq = platform_get_irq(pdev, 0);
380 status = PTR_ERR(config->clk); 375 if (irq < 0) {
381 goto err_kfree; 376 dev_err(&pdev->dev, "no update irq?\n");
377 return irq;
382 } 378 }
383 379
384 status = clk_enable(config->clk); 380 status = devm_request_irq(&pdev->dev, irq, spear_rtc_irq, 0, pdev->name,
385 if (status < 0) 381 config);
386 goto err_clk_put; 382 if (status) {
387 383 dev_err(&pdev->dev, "Alarm interrupt IRQ%d already claimed\n",
388 config->ioaddr = ioremap(res->start, resource_size(res)); 384 irq);
389 if (!config->ioaddr) { 385 return status;
390 dev_err(&pdev->dev, "ioremap fail\n");
391 status = -ENOMEM;
392 goto err_disable_clock;
393 } 386 }
394 387
388 config->ioaddr = devm_ioremap_resource(&pdev->dev, res);
389 if (IS_ERR(config->ioaddr))
390 return PTR_ERR(config->ioaddr);
391
392 config->clk = devm_clk_get(&pdev->dev, NULL);
393 if (IS_ERR(config->clk))
394 return PTR_ERR(config->clk);
395
396 status = clk_prepare_enable(config->clk);
397 if (status < 0)
398 return status;
399
395 spin_lock_init(&config->lock); 400 spin_lock_init(&config->lock);
396 platform_set_drvdata(pdev, config); 401 platform_set_drvdata(pdev, config);
397 402
@@ -401,67 +406,31 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
401 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 406 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
402 PTR_ERR(config->rtc)); 407 PTR_ERR(config->rtc));
403 status = PTR_ERR(config->rtc); 408 status = PTR_ERR(config->rtc);
404 goto err_iounmap; 409 goto err_disable_clock;
405 }
406
407 /* alarm irqs */
408 irq = platform_get_irq(pdev, 0);
409 if (irq < 0) {
410 dev_err(&pdev->dev, "no update irq?\n");
411 status = irq;
412 goto err_clear_platdata;
413 } 410 }
414 411
415 status = request_irq(irq, spear_rtc_irq, 0, pdev->name, config); 412 config->rtc->uie_unsupported = 1;
416 if (status) {
417 dev_err(&pdev->dev, "Alarm interrupt IRQ%d already \
418 claimed\n", irq);
419 goto err_clear_platdata;
420 }
421 413
422 if (!device_can_wakeup(&pdev->dev)) 414 if (!device_can_wakeup(&pdev->dev))
423 device_init_wakeup(&pdev->dev, 1); 415 device_init_wakeup(&pdev->dev, 1);
424 416
425 return 0; 417 return 0;
426 418
427err_clear_platdata:
428 platform_set_drvdata(pdev, NULL);
429 rtc_device_unregister(config->rtc);
430err_iounmap:
431 iounmap(config->ioaddr);
432err_disable_clock: 419err_disable_clock:
433 clk_disable(config->clk); 420 platform_set_drvdata(pdev, NULL);
434err_clk_put: 421 clk_disable_unprepare(config->clk);
435 clk_put(config->clk);
436err_kfree:
437 kfree(config);
438err_release_region:
439 release_mem_region(res->start, resource_size(res));
440 422
441 return status; 423 return status;
442} 424}
443 425
444static int __devexit spear_rtc_remove(struct platform_device *pdev) 426static int spear_rtc_remove(struct platform_device *pdev)
445{ 427{
446 struct spear_rtc_config *config = platform_get_drvdata(pdev); 428 struct spear_rtc_config *config = platform_get_drvdata(pdev);
447 int irq;
448 struct resource *res;
449 429
450 /* leave rtc running, but disable irqs */ 430 rtc_device_unregister(config->rtc);
451 spear_rtc_disable_interrupt(config); 431 spear_rtc_disable_interrupt(config);
432 clk_disable_unprepare(config->clk);
452 device_init_wakeup(&pdev->dev, 0); 433 device_init_wakeup(&pdev->dev, 0);
453 irq = platform_get_irq(pdev, 0);
454 if (irq)
455 free_irq(irq, pdev);
456 clk_disable(config->clk);
457 clk_put(config->clk);
458 iounmap(config->ioaddr);
459 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
460 if (res)
461 release_mem_region(res->start, resource_size(res));
462 platform_set_drvdata(pdev, NULL);
463 rtc_device_unregister(config->rtc);
464 kfree(config);
465 434
466 return 0; 435 return 0;
467} 436}
@@ -528,7 +497,7 @@ MODULE_DEVICE_TABLE(of, spear_rtc_id_table);
528 497
529static struct platform_driver spear_rtc_driver = { 498static struct platform_driver spear_rtc_driver = {
530 .probe = spear_rtc_probe, 499 .probe = spear_rtc_probe,
531 .remove = __devexit_p(spear_rtc_remove), 500 .remove = spear_rtc_remove,
532 .suspend = spear_rtc_suspend, 501 .suspend = spear_rtc_suspend,
533 .resume = spear_rtc_resume, 502 .resume = spear_rtc_resume,
534 .shutdown = spear_rtc_shutdown, 503 .shutdown = spear_rtc_shutdown,
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 279f5cfa691a..7e4a6f65cb91 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -285,7 +285,7 @@ static struct bin_attribute stk17ta8_nvram_attr = {
285 .write = stk17ta8_nvram_write, 285 .write = stk17ta8_nvram_write,
286}; 286};
287 287
288static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev) 288static int stk17ta8_rtc_probe(struct platform_device *pdev)
289{ 289{
290 struct resource *res; 290 struct resource *res;
291 unsigned int cal; 291 unsigned int cal;
@@ -347,7 +347,7 @@ static int __devinit stk17ta8_rtc_probe(struct platform_device *pdev)
347 return ret; 347 return ret;
348} 348}
349 349
350static int __devexit stk17ta8_rtc_remove(struct platform_device *pdev) 350static int stk17ta8_rtc_remove(struct platform_device *pdev)
351{ 351{
352 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 352 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
353 353
@@ -363,7 +363,7 @@ MODULE_ALIAS("platform:stk17ta8");
363 363
364static struct platform_driver stk17ta8_rtc_driver = { 364static struct platform_driver stk17ta8_rtc_driver = {
365 .probe = stk17ta8_rtc_probe, 365 .probe = stk17ta8_rtc_probe,
366 .remove = __devexit_p(stk17ta8_rtc_remove), 366 .remove = stk17ta8_rtc_remove,
367 .driver = { 367 .driver = {
368 .name = "stk17ta8", 368 .name = "stk17ta8",
369 .owner = THIS_MODULE, 369 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 739ef55694f4..b2a8ed99b2bf 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -26,6 +26,7 @@
26#include <linux/rtc.h> 26#include <linux/rtc.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/of_device.h> 28#include <linux/of_device.h>
29#include <linux/of.h>
29 30
30#include <mach/common.h> 31#include <mach/common.h>
31 32
@@ -280,7 +281,7 @@ static struct platform_driver stmp3xxx_rtcdrv = {
280 .driver = { 281 .driver = {
281 .name = "stmp3xxx-rtc", 282 .name = "stmp3xxx-rtc",
282 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
283 .of_match_table = rtc_dt_ids, 284 .of_match_table = of_match_ptr(rtc_dt_ids),
284 }, 285 },
285}; 286};
286 287
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c
index 5b2261052a65..59b5c2dcb58c 100644
--- a/drivers/rtc/rtc-sun4v.c
+++ b/drivers/rtc/rtc-sun4v.c
@@ -3,6 +3,8 @@
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net> 3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */ 4 */
5 5
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7
6#include <linux/kernel.h> 8#include <linux/kernel.h>
7#include <linux/module.h> 9#include <linux/module.h>
8#include <linux/delay.h> 10#include <linux/delay.h>
@@ -26,10 +28,10 @@ retry:
26 udelay(100); 28 udelay(100);
27 goto retry; 29 goto retry;
28 } 30 }
29 printk(KERN_WARNING "SUN4V: tod_get() timed out.\n"); 31 pr_warn("tod_get() timed out.\n");
30 return 0; 32 return 0;
31 } 33 }
32 printk(KERN_WARNING "SUN4V: tod_get() not supported.\n"); 34 pr_warn("tod_get() not supported.\n");
33 return 0; 35 return 0;
34} 36}
35 37
@@ -53,10 +55,10 @@ retry:
53 udelay(100); 55 udelay(100);
54 goto retry; 56 goto retry;
55 } 57 }
56 printk(KERN_WARNING "SUN4V: tod_set() timed out.\n"); 58 pr_warn("tod_set() timed out.\n");
57 return -EAGAIN; 59 return -EAGAIN;
58 } 60 }
59 printk(KERN_WARNING "SUN4V: tod_set() not supported.\n"); 61 pr_warn("tod_set() not supported.\n");
60 return -EOPNOTSUPP; 62 return -EOPNOTSUPP;
61} 63}
62 64
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index c006025cecc8..7c033756d6b5 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -303,7 +303,13 @@ static struct rtc_class_ops tegra_rtc_ops = {
303 .alarm_irq_enable = tegra_rtc_alarm_irq_enable, 303 .alarm_irq_enable = tegra_rtc_alarm_irq_enable,
304}; 304};
305 305
306static int __devinit tegra_rtc_probe(struct platform_device *pdev) 306static const struct of_device_id tegra_rtc_dt_match[] = {
307 { .compatible = "nvidia,tegra20-rtc", },
308 {}
309};
310MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match);
311
312static int tegra_rtc_probe(struct platform_device *pdev)
307{ 313{
308 struct tegra_rtc_info *info; 314 struct tegra_rtc_info *info;
309 struct resource *res; 315 struct resource *res;
@@ -321,11 +327,9 @@ static int __devinit tegra_rtc_probe(struct platform_device *pdev)
321 return -EBUSY; 327 return -EBUSY;
322 } 328 }
323 329
324 info->rtc_base = devm_request_and_ioremap(&pdev->dev, res); 330 info->rtc_base = devm_ioremap_resource(&pdev->dev, res);
325 if (!info->rtc_base) { 331 if (IS_ERR(info->rtc_base))
326 dev_err(&pdev->dev, "Unable to request mem region and grab IOs for device.\n"); 332 return PTR_ERR(info->rtc_base);
327 return -EBUSY;
328 }
329 333
330 info->tegra_rtc_irq = platform_get_irq(pdev, 0); 334 info->tegra_rtc_irq = platform_get_irq(pdev, 0);
331 if (info->tegra_rtc_irq <= 0) 335 if (info->tegra_rtc_irq <= 0)
@@ -375,7 +379,7 @@ err_dev_unreg:
375 return ret; 379 return ret;
376} 380}
377 381
378static int __devexit tegra_rtc_remove(struct platform_device *pdev) 382static int tegra_rtc_remove(struct platform_device *pdev)
379{ 383{
380 struct tegra_rtc_info *info = platform_get_drvdata(pdev); 384 struct tegra_rtc_info *info = platform_get_drvdata(pdev);
381 385
@@ -435,11 +439,12 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
435 439
436MODULE_ALIAS("platform:tegra_rtc"); 440MODULE_ALIAS("platform:tegra_rtc");
437static struct platform_driver tegra_rtc_driver = { 441static struct platform_driver tegra_rtc_driver = {
438 .remove = __devexit_p(tegra_rtc_remove), 442 .remove = tegra_rtc_remove,
439 .shutdown = tegra_rtc_shutdown, 443 .shutdown = tegra_rtc_shutdown,
440 .driver = { 444 .driver = {
441 .name = "tegra_rtc", 445 .name = "tegra_rtc",
442 .owner = THIS_MODULE, 446 .owner = THIS_MODULE,
447 .of_match_table = tegra_rtc_dt_match,
443 }, 448 },
444#ifdef CONFIG_PM 449#ifdef CONFIG_PM
445 .suspend = tegra_rtc_suspend, 450 .suspend = tegra_rtc_suspend,
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 7e96254bd365..b92e0f6383e6 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -119,7 +119,7 @@ err:
119 return err; 119 return err;
120} 120}
121 121
122static int __devexit test_remove(struct platform_device *plat_dev) 122static int test_remove(struct platform_device *plat_dev)
123{ 123{
124 struct rtc_device *rtc = platform_get_drvdata(plat_dev); 124 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
125 125
@@ -131,7 +131,7 @@ static int __devexit test_remove(struct platform_device *plat_dev)
131 131
132static struct platform_driver test_driver = { 132static struct platform_driver test_driver = {
133 .probe = test_probe, 133 .probe = test_probe,
134 .remove = __devexit_p(test_remove), 134 .remove = test_remove,
135 .driver = { 135 .driver = {
136 .name = "rtc-test", 136 .name = "rtc-test",
137 .owner = THIS_MODULE, 137 .owner = THIS_MODULE,
@@ -152,24 +152,24 @@ static int __init test_init(void)
152 152
153 if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) { 153 if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
154 err = -ENOMEM; 154 err = -ENOMEM;
155 goto exit_free_test0; 155 goto exit_put_test0;
156 } 156 }
157 157
158 if ((err = platform_device_add(test0))) 158 if ((err = platform_device_add(test0)))
159 goto exit_free_test1; 159 goto exit_put_test1;
160 160
161 if ((err = platform_device_add(test1))) 161 if ((err = platform_device_add(test1)))
162 goto exit_device_unregister; 162 goto exit_del_test0;
163 163
164 return 0; 164 return 0;
165 165
166exit_device_unregister: 166exit_del_test0:
167 platform_device_unregister(test0); 167 platform_device_del(test0);
168 168
169exit_free_test1: 169exit_put_test1:
170 platform_device_put(test1); 170 platform_device_put(test1);
171 171
172exit_free_test0: 172exit_put_test0:
173 platform_device_put(test0); 173 platform_device_put(test0);
174 174
175exit_driver_unregister: 175exit_driver_unregister:
diff --git a/drivers/rtc/rtc-tile.c b/drivers/rtc/rtc-tile.c
index eb65dafee66e..62db4841078b 100644
--- a/drivers/rtc/rtc-tile.c
+++ b/drivers/rtc/rtc-tile.c
@@ -76,7 +76,7 @@ static const struct rtc_class_ops tile_rtc_ops = {
76/* 76/*
77 * Device probe routine. 77 * Device probe routine.
78 */ 78 */
79static int __devinit tile_rtc_probe(struct platform_device *dev) 79static int tile_rtc_probe(struct platform_device *dev)
80{ 80{
81 struct rtc_device *rtc; 81 struct rtc_device *rtc;
82 82
@@ -94,7 +94,7 @@ static int __devinit tile_rtc_probe(struct platform_device *dev)
94/* 94/*
95 * Device cleanup routine. 95 * Device cleanup routine.
96 */ 96 */
97static int __devexit tile_rtc_remove(struct platform_device *dev) 97static int tile_rtc_remove(struct platform_device *dev)
98{ 98{
99 struct rtc_device *rtc = platform_get_drvdata(dev); 99 struct rtc_device *rtc = platform_get_drvdata(dev);
100 100
@@ -112,7 +112,7 @@ static struct platform_driver tile_rtc_platform_driver = {
112 .owner = THIS_MODULE, 112 .owner = THIS_MODULE,
113 }, 113 },
114 .probe = tile_rtc_probe, 114 .probe = tile_rtc_probe,
115 .remove = __devexit_p(tile_rtc_remove), 115 .remove = tile_rtc_remove,
116}; 116};
117 117
118/* 118/*
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c
new file mode 100644
index 000000000000..aab4e8c93622
--- /dev/null
+++ b/drivers/rtc/rtc-tps6586x.c
@@ -0,0 +1,356 @@
1/*
2 * rtc-tps6586x.c: RTC driver for TI PMIC TPS6586X
3 *
4 * Copyright (c) 2012, NVIDIA Corporation.
5 *
6 * Author: Laxman Dewangan <ldewangan@nvidia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
13 * whether express or implied; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307, USA
21 */
22
23#include <linux/device.h>
24#include <linux/err.h>
25#include <linux/init.h>
26#include <linux/kernel.h>
27#include <linux/mfd/tps6586x.h>
28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/pm_runtime.h>
31#include <linux/rtc.h>
32#include <linux/slab.h>
33
34#define RTC_CTRL 0xc0
35#define POR_RESET_N BIT(7)
36#define OSC_SRC_SEL BIT(6)
37#define RTC_ENABLE BIT(5) /* enables alarm */
38#define RTC_BUF_ENABLE BIT(4) /* 32 KHz buffer enable */
39#define PRE_BYPASS BIT(3) /* 0=1KHz or 1=32KHz updates */
40#define CL_SEL_MASK (BIT(2)|BIT(1))
41#define CL_SEL_POS 1
42#define RTC_ALARM1_HI 0xc1
43#define RTC_COUNT4 0xc6
44
45/* start a PMU RTC access by reading the register prior to the RTC_COUNT4 */
46#define RTC_COUNT4_DUMMYREAD 0xc5
47
48/*only 14-bits width in second*/
49#define ALM1_VALID_RANGE_IN_SEC 0x3FFF
50
51#define TPS6586X_RTC_CL_SEL_1_5PF 0x0
52#define TPS6586X_RTC_CL_SEL_6_5PF 0x1
53#define TPS6586X_RTC_CL_SEL_7_5PF 0x2
54#define TPS6586X_RTC_CL_SEL_12_5PF 0x3
55
56struct tps6586x_rtc {
57 struct device *dev;
58 struct rtc_device *rtc;
59 int irq;
60 bool irq_en;
61 unsigned long long epoch_start;
62};
63
64static inline struct device *to_tps6586x_dev(struct device *dev)
65{
66 return dev->parent;
67}
68
69static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm)
70{
71 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
72 struct device *tps_dev = to_tps6586x_dev(dev);
73 unsigned long long ticks = 0;
74 unsigned long seconds;
75 u8 buff[6];
76 int ret;
77 int i;
78
79 ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(buff), buff);
80 if (ret < 0) {
81 dev_err(dev, "read counter failed with err %d\n", ret);
82 return ret;
83 }
84
85 for (i = 1; i < sizeof(buff); i++) {
86 ticks <<= 8;
87 ticks |= buff[i];
88 }
89
90 seconds = ticks >> 10;
91 seconds += rtc->epoch_start;
92 rtc_time_to_tm(seconds, tm);
93 return rtc_valid_tm(tm);
94}
95
96static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm)
97{
98 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
99 struct device *tps_dev = to_tps6586x_dev(dev);
100 unsigned long long ticks;
101 unsigned long seconds;
102 u8 buff[5];
103 int ret;
104
105 rtc_tm_to_time(tm, &seconds);
106 if (seconds < rtc->epoch_start) {
107 dev_err(dev, "requested time unsupported\n");
108 return -EINVAL;
109 }
110 seconds -= rtc->epoch_start;
111
112 ticks = (unsigned long long)seconds << 10;
113 buff[0] = (ticks >> 32) & 0xff;
114 buff[1] = (ticks >> 24) & 0xff;
115 buff[2] = (ticks >> 16) & 0xff;
116 buff[3] = (ticks >> 8) & 0xff;
117 buff[4] = ticks & 0xff;
118
119 /* Disable RTC before changing time */
120 ret = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE);
121 if (ret < 0) {
122 dev_err(dev, "failed to clear RTC_ENABLE\n");
123 return ret;
124 }
125
126 ret = tps6586x_writes(tps_dev, RTC_COUNT4, sizeof(buff), buff);
127 if (ret < 0) {
128 dev_err(dev, "failed to program new time\n");
129 return ret;
130 }
131
132 /* Enable RTC */
133 ret = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE);
134 if (ret < 0) {
135 dev_err(dev, "failed to set RTC_ENABLE\n");
136 return ret;
137 }
138 return 0;
139}
140
141static int tps6586x_rtc_alarm_irq_enable(struct device *dev,
142 unsigned int enabled)
143{
144 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
145
146 if (enabled && !rtc->irq_en) {
147 enable_irq(rtc->irq);
148 rtc->irq_en = true;
149 } else if (!enabled && rtc->irq_en) {
150 disable_irq(rtc->irq);
151 rtc->irq_en = false;
152 }
153 return 0;
154}
155
156static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
157{
158 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
159 struct device *tps_dev = to_tps6586x_dev(dev);
160 unsigned long seconds;
161 unsigned long ticks;
162 unsigned long rtc_current_time;
163 unsigned long long rticks = 0;
164 u8 buff[3];
165 u8 rbuff[6];
166 int ret;
167 int i;
168
169 rtc_tm_to_time(&alrm->time, &seconds);
170
171 if (alrm->enabled && (seconds < rtc->epoch_start)) {
172 dev_err(dev, "can't set alarm to requested time\n");
173 return -EINVAL;
174 }
175
176 ret = tps6586x_rtc_alarm_irq_enable(dev, alrm->enabled);
177 if (ret < 0) {
178 dev_err(dev, "can't set alarm irq, err %d\n", ret);
179 return ret;
180 }
181
182 seconds -= rtc->epoch_start;
183 ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD,
184 sizeof(rbuff), rbuff);
185 if (ret < 0) {
186 dev_err(dev, "read counter failed with err %d\n", ret);
187 return ret;
188 }
189
190 for (i = 1; i < sizeof(rbuff); i++) {
191 rticks <<= 8;
192 rticks |= rbuff[i];
193 }
194
195 rtc_current_time = rticks >> 10;
196 if ((seconds - rtc_current_time) > ALM1_VALID_RANGE_IN_SEC)
197 seconds = rtc_current_time - 1;
198
199 ticks = (unsigned long long)seconds << 10;
200 buff[0] = (ticks >> 16) & 0xff;
201 buff[1] = (ticks >> 8) & 0xff;
202 buff[2] = ticks & 0xff;
203
204 ret = tps6586x_writes(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff);
205 if (ret)
206 dev_err(dev, "programming alarm failed with err %d\n", ret);
207
208 return ret;
209}
210
211static int tps6586x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
212{
213 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
214 struct device *tps_dev = to_tps6586x_dev(dev);
215 unsigned long ticks;
216 unsigned long seconds;
217 u8 buff[3];
218 int ret;
219
220 ret = tps6586x_reads(tps_dev, RTC_ALARM1_HI, sizeof(buff), buff);
221 if (ret) {
222 dev_err(dev, "read RTC_ALARM1_HI failed with err %d\n", ret);
223 return ret;
224 }
225
226 ticks = (buff[0] << 16) | (buff[1] << 8) | buff[2];
227 seconds = ticks >> 10;
228 seconds += rtc->epoch_start;
229
230 rtc_time_to_tm(seconds, &alrm->time);
231 return 0;
232}
233
234static const struct rtc_class_ops tps6586x_rtc_ops = {
235 .read_time = tps6586x_rtc_read_time,
236 .set_time = tps6586x_rtc_set_time,
237 .set_alarm = tps6586x_rtc_set_alarm,
238 .read_alarm = tps6586x_rtc_read_alarm,
239 .alarm_irq_enable = tps6586x_rtc_alarm_irq_enable,
240};
241
242static irqreturn_t tps6586x_rtc_irq(int irq, void *data)
243{
244 struct tps6586x_rtc *rtc = data;
245
246 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
247 return IRQ_HANDLED;
248}
249
250static int tps6586x_rtc_probe(struct platform_device *pdev)
251{
252 struct device *tps_dev = to_tps6586x_dev(&pdev->dev);
253 struct tps6586x_rtc *rtc;
254 int ret;
255
256 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
257 if (!rtc)
258 return -ENOMEM;
259
260 rtc->dev = &pdev->dev;
261 rtc->irq = platform_get_irq(pdev, 0);
262
263 /* Set epoch start as 00:00:00:01:01:2009 */
264 rtc->epoch_start = mktime(2009, 1, 1, 0, 0, 0);
265
266 /* 1 kHz tick mode, enable tick counting */
267 ret = tps6586x_update(tps_dev, RTC_CTRL,
268 RTC_ENABLE | OSC_SRC_SEL |
269 ((TPS6586X_RTC_CL_SEL_1_5PF << CL_SEL_POS) & CL_SEL_MASK),
270 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
271 if (ret < 0) {
272 dev_err(&pdev->dev, "unable to start counter\n");
273 return ret;
274 }
275
276 platform_set_drvdata(pdev, rtc);
277 rtc->rtc = rtc_device_register(dev_name(&pdev->dev), &pdev->dev,
278 &tps6586x_rtc_ops, THIS_MODULE);
279 if (IS_ERR(rtc->rtc)) {
280 ret = PTR_ERR(rtc->rtc);
281 dev_err(&pdev->dev, "RTC device register: ret %d\n", ret);
282 goto fail_rtc_register;
283 }
284
285 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
286 tps6586x_rtc_irq,
287 IRQF_ONESHOT | IRQF_EARLY_RESUME,
288 dev_name(&pdev->dev), rtc);
289 if (ret < 0) {
290 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n",
291 rtc->irq, ret);
292 goto fail_req_irq;
293 }
294 disable_irq(rtc->irq);
295 device_set_wakeup_capable(&pdev->dev, 1);
296 return 0;
297
298fail_req_irq:
299 rtc_device_unregister(rtc->rtc);
300
301fail_rtc_register:
302 tps6586x_update(tps_dev, RTC_CTRL, 0,
303 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
304 return ret;
305};
306
307static int tps6586x_rtc_remove(struct platform_device *pdev)
308{
309 struct tps6586x_rtc *rtc = platform_get_drvdata(pdev);
310 struct device *tps_dev = to_tps6586x_dev(&pdev->dev);
311
312 tps6586x_update(tps_dev, RTC_CTRL, 0,
313 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
314 rtc_device_unregister(rtc->rtc);
315 return 0;
316}
317
318#ifdef CONFIG_PM_SLEEP
319static int tps6586x_rtc_suspend(struct device *dev)
320{
321 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
322
323 if (device_may_wakeup(dev))
324 enable_irq_wake(rtc->irq);
325 return 0;
326}
327
328static int tps6586x_rtc_resume(struct device *dev)
329{
330 struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
331
332 if (device_may_wakeup(dev))
333 disable_irq_wake(rtc->irq);
334 return 0;
335}
336#endif
337
338static const struct dev_pm_ops tps6586x_pm_ops = {
339 SET_SYSTEM_SLEEP_PM_OPS(tps6586x_rtc_suspend, tps6586x_rtc_resume)
340};
341
342static struct platform_driver tps6586x_rtc_driver = {
343 .driver = {
344 .name = "tps6586x-rtc",
345 .owner = THIS_MODULE,
346 .pm = &tps6586x_pm_ops,
347 },
348 .probe = tps6586x_rtc_probe,
349 .remove = tps6586x_rtc_remove,
350};
351module_platform_driver(tps6586x_rtc_driver);
352
353MODULE_ALIAS("platform:rtc-tps6586x");
354MODULE_DESCRIPTION("TI TPS6586x RTC driver");
355MODULE_AUTHOR("Laxman dewangan <ldewangan@nvidia.com>");
356MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
index 073108dcf9e7..8bd8115329b5 100644
--- a/drivers/rtc/rtc-tps65910.c
+++ b/drivers/rtc/rtc-tps65910.c
@@ -22,13 +22,13 @@
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/bcd.h> 23#include <linux/bcd.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/mfd/tps65910.h> 27#include <linux/mfd/tps65910.h>
27 28
28struct tps65910_rtc { 29struct tps65910_rtc {
29 struct rtc_device *rtc; 30 struct rtc_device *rtc;
30 /* To store the list of enabled interrupts */ 31 int irq;
31 u32 irqstat;
32}; 32};
33 33
34/* Total number of RTC registers needed to set time*/ 34/* Total number of RTC registers needed to set time*/
@@ -222,7 +222,7 @@ static const struct rtc_class_ops tps65910_rtc_ops = {
222 .alarm_irq_enable = tps65910_rtc_alarm_irq_enable, 222 .alarm_irq_enable = tps65910_rtc_alarm_irq_enable,
223}; 223};
224 224
225static int __devinit tps65910_rtc_probe(struct platform_device *pdev) 225static int tps65910_rtc_probe(struct platform_device *pdev)
226{ 226{
227 struct tps65910 *tps65910 = NULL; 227 struct tps65910 *tps65910 = NULL;
228 struct tps65910_rtc *tps_rtc = NULL; 228 struct tps65910_rtc *tps_rtc = NULL;
@@ -247,6 +247,13 @@ static int __devinit tps65910_rtc_probe(struct platform_device *pdev)
247 return ret; 247 return ret;
248 248
249 dev_dbg(&pdev->dev, "Enabling rtc-tps65910.\n"); 249 dev_dbg(&pdev->dev, "Enabling rtc-tps65910.\n");
250
251 /* Enable RTC digital power domain */
252 ret = regmap_update_bits(tps65910->regmap, TPS65910_DEVCTRL,
253 DEVCTRL_RTC_PWDN_MASK, 0 << DEVCTRL_RTC_PWDN_SHIFT);
254 if (ret < 0)
255 return ret;
256
250 rtc_reg = TPS65910_RTC_CTRL_STOP_RTC; 257 rtc_reg = TPS65910_RTC_CTRL_STOP_RTC;
251 ret = regmap_write(tps65910->regmap, TPS65910_RTC_CTRL, rtc_reg); 258 ret = regmap_write(tps65910->regmap, TPS65910_RTC_CTRL, rtc_reg);
252 if (ret < 0) 259 if (ret < 0)
@@ -260,13 +267,14 @@ static int __devinit tps65910_rtc_probe(struct platform_device *pdev)
260 } 267 }
261 268
262 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 269 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
263 tps65910_rtc_interrupt, IRQF_TRIGGER_LOW, 270 tps65910_rtc_interrupt, IRQF_TRIGGER_LOW | IRQF_EARLY_RESUME,
264 "rtc-tps65910", &pdev->dev); 271 dev_name(&pdev->dev), &pdev->dev);
265 if (ret < 0) { 272 if (ret < 0) {
266 dev_err(&pdev->dev, "IRQ is not free.\n"); 273 dev_err(&pdev->dev, "IRQ is not free.\n");
267 return ret; 274 return ret;
268 } 275 }
269 device_init_wakeup(&pdev->dev, 1); 276 tps_rtc->irq = irq;
277 device_set_wakeup_capable(&pdev->dev, 1);
270 278
271 tps_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 279 tps_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
272 &tps65910_rtc_ops, THIS_MODULE); 280 &tps65910_rtc_ops, THIS_MODULE);
@@ -285,7 +293,7 @@ static int __devinit tps65910_rtc_probe(struct platform_device *pdev)
285 * Disable tps65910 RTC interrupts. 293 * Disable tps65910 RTC interrupts.
286 * Sets status flag to free. 294 * Sets status flag to free.
287 */ 295 */
288static int __devexit tps65910_rtc_remove(struct platform_device *pdev) 296static int tps65910_rtc_remove(struct platform_device *pdev)
289{ 297{
290 /* leave rtc running, but disable irqs */ 298 /* leave rtc running, but disable irqs */
291 struct tps65910_rtc *tps_rtc = platform_get_drvdata(pdev); 299 struct tps65910_rtc *tps_rtc = platform_get_drvdata(pdev);
@@ -297,49 +305,36 @@ static int __devexit tps65910_rtc_remove(struct platform_device *pdev)
297} 305}
298 306
299#ifdef CONFIG_PM_SLEEP 307#ifdef CONFIG_PM_SLEEP
300
301static int tps65910_rtc_suspend(struct device *dev) 308static int tps65910_rtc_suspend(struct device *dev)
302{ 309{
303 struct tps65910 *tps = dev_get_drvdata(dev->parent); 310 struct tps65910_rtc *tps_rtc = dev_get_drvdata(dev);
304 u8 alarm = TPS65910_RTC_INTERRUPTS_IT_ALARM;
305 int ret;
306
307 /* Store current list of enabled interrupts*/
308 ret = regmap_read(tps->regmap, TPS65910_RTC_INTERRUPTS,
309 &tps->rtc->irqstat);
310 if (ret < 0)
311 return ret;
312 311
313 /* Enable RTC ALARM interrupt only */ 312 if (device_may_wakeup(dev))
314 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, alarm); 313 enable_irq_wake(tps_rtc->irq);
314 return 0;
315} 315}
316 316
317static int tps65910_rtc_resume(struct device *dev) 317static int tps65910_rtc_resume(struct device *dev)
318{ 318{
319 struct tps65910 *tps = dev_get_drvdata(dev->parent); 319 struct tps65910_rtc *tps_rtc = dev_get_drvdata(dev);
320 320
321 /* Restore list of enabled interrupts before suspend */ 321 if (device_may_wakeup(dev))
322 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, 322 disable_irq_wake(tps_rtc->irq);
323 tps->rtc->irqstat); 323 return 0;
324} 324}
325#endif
325 326
326static const struct dev_pm_ops tps65910_rtc_pm_ops = { 327static const struct dev_pm_ops tps65910_rtc_pm_ops = {
327 .suspend = tps65910_rtc_suspend, 328 SET_SYSTEM_SLEEP_PM_OPS(tps65910_rtc_suspend, tps65910_rtc_resume)
328 .resume = tps65910_rtc_resume,
329}; 329};
330 330
331#define DEV_PM_OPS (&tps65910_rtc_pm_ops)
332#else
333#define DEV_PM_OPS NULL
334#endif
335
336static struct platform_driver tps65910_rtc_driver = { 331static struct platform_driver tps65910_rtc_driver = {
337 .probe = tps65910_rtc_probe, 332 .probe = tps65910_rtc_probe,
338 .remove = __devexit_p(tps65910_rtc_remove), 333 .remove = tps65910_rtc_remove,
339 .driver = { 334 .driver = {
340 .owner = THIS_MODULE, 335 .owner = THIS_MODULE,
341 .name = "tps65910-rtc", 336 .name = "tps65910-rtc",
342 .pm = DEV_PM_OPS, 337 .pm = &tps65910_rtc_pm_ops,
343 }, 338 },
344}; 339};
345 340
diff --git a/drivers/rtc/rtc-tps80031.c b/drivers/rtc/rtc-tps80031.c
new file mode 100644
index 000000000000..9aaf8aaebae9
--- /dev/null
+++ b/drivers/rtc/rtc-tps80031.c
@@ -0,0 +1,349 @@
1/*
2 * rtc-tps80031.c -- TI TPS80031/TPS80032 RTC driver
3 *
4 * RTC driver for TI TPS80031/TPS80032 Fully Integrated
5 * Power Management with Power Path and Battery Charger
6 *
7 * Copyright (c) 2012, NVIDIA Corporation.
8 *
9 * Author: Laxman Dewangan <ldewangan@nvidia.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
14 *
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
16 * whether express or implied; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307, USA
24 */
25
26#include <linux/bcd.h>
27#include <linux/device.h>
28#include <linux/err.h>
29#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/mfd/tps80031.h>
33#include <linux/platform_device.h>
34#include <linux/pm.h>
35#include <linux/rtc.h>
36#include <linux/slab.h>
37
38#define ENABLE_ALARM_INT 0x08
39#define ALARM_INT_STATUS 0x40
40
41/**
42 * Setting bit to 1 in STOP_RTC will run the RTC and
43 * setting this bit to 0 will freeze RTC.
44 */
45#define STOP_RTC 0x1
46
47/* Power on reset Values of RTC registers */
48#define TPS80031_RTC_POR_YEAR 0
49#define TPS80031_RTC_POR_MONTH 1
50#define TPS80031_RTC_POR_DAY 1
51
52/* Numbers of registers for time and alarms */
53#define TPS80031_RTC_TIME_NUM_REGS 7
54#define TPS80031_RTC_ALARM_NUM_REGS 6
55
56/**
57 * PMU RTC have only 2 nibbles to store year information, so using an
58 * offset of 100 to set the base year as 2000 for our driver.
59 */
60#define RTC_YEAR_OFFSET 100
61
62struct tps80031_rtc {
63 struct rtc_device *rtc;
64 int irq;
65};
66
67static int tps80031_rtc_read_time(struct device *dev, struct rtc_time *tm)
68{
69 u8 buff[TPS80031_RTC_TIME_NUM_REGS];
70 int ret;
71
72 ret = tps80031_reads(dev->parent, TPS80031_SLAVE_ID1,
73 TPS80031_SECONDS_REG, TPS80031_RTC_TIME_NUM_REGS, buff);
74 if (ret < 0) {
75 dev_err(dev, "reading RTC_SECONDS_REG failed, err = %d\n", ret);
76 return ret;
77 }
78
79 tm->tm_sec = bcd2bin(buff[0]);
80 tm->tm_min = bcd2bin(buff[1]);
81 tm->tm_hour = bcd2bin(buff[2]);
82 tm->tm_mday = bcd2bin(buff[3]);
83 tm->tm_mon = bcd2bin(buff[4]) - 1;
84 tm->tm_year = bcd2bin(buff[5]) + RTC_YEAR_OFFSET;
85 tm->tm_wday = bcd2bin(buff[6]);
86 return 0;
87}
88
89static int tps80031_rtc_set_time(struct device *dev, struct rtc_time *tm)
90{
91 u8 buff[7];
92 int ret;
93
94 buff[0] = bin2bcd(tm->tm_sec);
95 buff[1] = bin2bcd(tm->tm_min);
96 buff[2] = bin2bcd(tm->tm_hour);
97 buff[3] = bin2bcd(tm->tm_mday);
98 buff[4] = bin2bcd(tm->tm_mon + 1);
99 buff[5] = bin2bcd(tm->tm_year % RTC_YEAR_OFFSET);
100 buff[6] = bin2bcd(tm->tm_wday);
101
102 /* Stop RTC while updating the RTC time registers */
103 ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1,
104 TPS80031_RTC_CTRL_REG, STOP_RTC);
105 if (ret < 0) {
106 dev_err(dev->parent, "Stop RTC failed, err = %d\n", ret);
107 return ret;
108 }
109
110 ret = tps80031_writes(dev->parent, TPS80031_SLAVE_ID1,
111 TPS80031_SECONDS_REG,
112 TPS80031_RTC_TIME_NUM_REGS, buff);
113 if (ret < 0) {
114 dev_err(dev, "writing RTC_SECONDS_REG failed, err %d\n", ret);
115 return ret;
116 }
117
118 ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
119 TPS80031_RTC_CTRL_REG, STOP_RTC);
120 if (ret < 0)
121 dev_err(dev->parent, "Start RTC failed, err = %d\n", ret);
122 return ret;
123}
124
125static int tps80031_rtc_alarm_irq_enable(struct device *dev,
126 unsigned int enable)
127{
128 int ret;
129
130 if (enable)
131 ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
132 TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT);
133 else
134 ret = tps80031_clr_bits(dev->parent, TPS80031_SLAVE_ID1,
135 TPS80031_RTC_INTERRUPTS_REG, ENABLE_ALARM_INT);
136 if (ret < 0) {
137 dev_err(dev, "Update on RTC_INT failed, err = %d\n", ret);
138 return ret;
139 }
140 return 0;
141}
142
143static int tps80031_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
144{
145 u8 buff[TPS80031_RTC_ALARM_NUM_REGS];
146 int ret;
147
148 buff[0] = bin2bcd(alrm->time.tm_sec);
149 buff[1] = bin2bcd(alrm->time.tm_min);
150 buff[2] = bin2bcd(alrm->time.tm_hour);
151 buff[3] = bin2bcd(alrm->time.tm_mday);
152 buff[4] = bin2bcd(alrm->time.tm_mon + 1);
153 buff[5] = bin2bcd(alrm->time.tm_year % RTC_YEAR_OFFSET);
154 ret = tps80031_writes(dev->parent, TPS80031_SLAVE_ID1,
155 TPS80031_ALARM_SECONDS_REG,
156 TPS80031_RTC_ALARM_NUM_REGS, buff);
157 if (ret < 0) {
158 dev_err(dev, "Writing RTC_ALARM failed, err %d\n", ret);
159 return ret;
160 }
161 return tps80031_rtc_alarm_irq_enable(dev, alrm->enabled);
162}
163
164static int tps80031_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
165{
166 u8 buff[6];
167 int ret;
168
169 ret = tps80031_reads(dev->parent, TPS80031_SLAVE_ID1,
170 TPS80031_ALARM_SECONDS_REG,
171 TPS80031_RTC_ALARM_NUM_REGS, buff);
172 if (ret < 0) {
173 dev_err(dev->parent,
174 "reading RTC_ALARM failed, err = %d\n", ret);
175 return ret;
176 }
177
178 alrm->time.tm_sec = bcd2bin(buff[0]);
179 alrm->time.tm_min = bcd2bin(buff[1]);
180 alrm->time.tm_hour = bcd2bin(buff[2]);
181 alrm->time.tm_mday = bcd2bin(buff[3]);
182 alrm->time.tm_mon = bcd2bin(buff[4]) - 1;
183 alrm->time.tm_year = bcd2bin(buff[5]) + RTC_YEAR_OFFSET;
184 return 0;
185}
186
187static int clear_alarm_int_status(struct device *dev, struct tps80031_rtc *rtc)
188{
189 int ret;
190 u8 buf;
191
192 /**
193 * As per datasheet, A dummy read of this RTC_STATUS_REG register
194 * is necessary before each I2C read in order to update the status
195 * register value.
196 */
197 ret = tps80031_read(dev->parent, TPS80031_SLAVE_ID1,
198 TPS80031_RTC_STATUS_REG, &buf);
199 if (ret < 0) {
200 dev_err(dev, "reading RTC_STATUS failed. err = %d\n", ret);
201 return ret;
202 }
203
204 /* clear Alarm status bits.*/
205 ret = tps80031_set_bits(dev->parent, TPS80031_SLAVE_ID1,
206 TPS80031_RTC_STATUS_REG, ALARM_INT_STATUS);
207 if (ret < 0) {
208 dev_err(dev, "clear Alarm INT failed, err = %d\n", ret);
209 return ret;
210 }
211 return 0;
212}
213
214static irqreturn_t tps80031_rtc_irq(int irq, void *data)
215{
216 struct device *dev = data;
217 struct tps80031_rtc *rtc = dev_get_drvdata(dev);
218 int ret;
219
220 ret = clear_alarm_int_status(dev, rtc);
221 if (ret < 0)
222 return ret;
223
224 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
225 return IRQ_HANDLED;
226}
227
228static const struct rtc_class_ops tps80031_rtc_ops = {
229 .read_time = tps80031_rtc_read_time,
230 .set_time = tps80031_rtc_set_time,
231 .set_alarm = tps80031_rtc_set_alarm,
232 .read_alarm = tps80031_rtc_read_alarm,
233 .alarm_irq_enable = tps80031_rtc_alarm_irq_enable,
234};
235
236static int tps80031_rtc_probe(struct platform_device *pdev)
237{
238 struct tps80031_rtc *rtc;
239 struct rtc_time tm;
240 int ret;
241
242 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
243 if (!rtc)
244 return -ENOMEM;
245
246 rtc->irq = platform_get_irq(pdev, 0);
247 platform_set_drvdata(pdev, rtc);
248
249 /* Start RTC */
250 ret = tps80031_set_bits(pdev->dev.parent, TPS80031_SLAVE_ID1,
251 TPS80031_RTC_CTRL_REG, STOP_RTC);
252 if (ret < 0) {
253 dev_err(&pdev->dev, "failed to start RTC. err = %d\n", ret);
254 return ret;
255 }
256
257 /* If RTC have POR values, set time 01:01:2000 */
258 tps80031_rtc_read_time(&pdev->dev, &tm);
259 if ((tm.tm_year == RTC_YEAR_OFFSET + TPS80031_RTC_POR_YEAR) &&
260 (tm.tm_mon == (TPS80031_RTC_POR_MONTH - 1)) &&
261 (tm.tm_mday == TPS80031_RTC_POR_DAY)) {
262 tm.tm_year = 2000;
263 tm.tm_mday = 1;
264 tm.tm_mon = 1;
265 ret = tps80031_rtc_set_time(&pdev->dev, &tm);
266 if (ret < 0) {
267 dev_err(&pdev->dev,
268 "RTC set time failed, err = %d\n", ret);
269 return ret;
270 }
271 }
272
273 /* Clear alarm intretupt status if it is there */
274 ret = clear_alarm_int_status(&pdev->dev, rtc);
275 if (ret < 0) {
276 dev_err(&pdev->dev, "Clear alarm int failed, err = %d\n", ret);
277 return ret;
278 }
279
280 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
281 &tps80031_rtc_ops, THIS_MODULE);
282 if (IS_ERR(rtc->rtc)) {
283 ret = PTR_ERR(rtc->rtc);
284 dev_err(&pdev->dev, "RTC registration failed, err %d\n", ret);
285 return ret;
286 }
287
288 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
289 tps80031_rtc_irq,
290 IRQF_ONESHOT | IRQF_EARLY_RESUME,
291 dev_name(&pdev->dev), rtc);
292 if (ret < 0) {
293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n",
294 rtc->irq, ret);
295 rtc_device_unregister(rtc->rtc);
296 return ret;
297 }
298 device_set_wakeup_capable(&pdev->dev, 1);
299 return 0;
300}
301
302static int tps80031_rtc_remove(struct platform_device *pdev)
303{
304 struct tps80031_rtc *rtc = platform_get_drvdata(pdev);
305
306 rtc_device_unregister(rtc->rtc);
307 return 0;
308}
309
310#ifdef CONFIG_PM_SLEEP
311static int tps80031_rtc_suspend(struct device *dev)
312{
313 struct tps80031_rtc *rtc = dev_get_drvdata(dev);
314
315 if (device_may_wakeup(dev))
316 enable_irq_wake(rtc->irq);
317 return 0;
318}
319
320static int tps80031_rtc_resume(struct device *dev)
321{
322 struct tps80031_rtc *rtc = dev_get_drvdata(dev);
323
324 if (device_may_wakeup(dev))
325 disable_irq_wake(rtc->irq);
326 return 0;
327};
328#endif
329
330static const struct dev_pm_ops tps80031_pm_ops = {
331 SET_SYSTEM_SLEEP_PM_OPS(tps80031_rtc_suspend, tps80031_rtc_resume)
332};
333
334static struct platform_driver tps80031_rtc_driver = {
335 .driver = {
336 .name = "tps80031-rtc",
337 .owner = THIS_MODULE,
338 .pm = &tps80031_pm_ops,
339 },
340 .probe = tps80031_rtc_probe,
341 .remove = tps80031_rtc_remove,
342};
343
344module_platform_driver(tps80031_rtc_driver);
345
346MODULE_ALIAS("platform:tps80031-rtc");
347MODULE_DESCRIPTION("TI TPS80031/TPS80032 RTC driver");
348MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
349MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 9277d945bf48..8bc6c80b184c 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -27,6 +27,7 @@
27#include <linux/bcd.h> 27#include <linux/bcd.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/of.h>
30 31
31#include <linux/i2c/twl.h> 32#include <linux/i2c/twl.h>
32 33
@@ -233,7 +234,7 @@ static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
233 */ 234 */
234static int twl_rtc_read_time(struct device *dev, struct rtc_time *tm) 235static int twl_rtc_read_time(struct device *dev, struct rtc_time *tm)
235{ 236{
236 unsigned char rtc_data[ALL_TIME_REGS + 1]; 237 unsigned char rtc_data[ALL_TIME_REGS];
237 int ret; 238 int ret;
238 u8 save_control; 239 u8 save_control;
239 u8 rtc_control; 240 u8 rtc_control;
@@ -300,15 +301,15 @@ static int twl_rtc_read_time(struct device *dev, struct rtc_time *tm)
300static int twl_rtc_set_time(struct device *dev, struct rtc_time *tm) 301static int twl_rtc_set_time(struct device *dev, struct rtc_time *tm)
301{ 302{
302 unsigned char save_control; 303 unsigned char save_control;
303 unsigned char rtc_data[ALL_TIME_REGS + 1]; 304 unsigned char rtc_data[ALL_TIME_REGS];
304 int ret; 305 int ret;
305 306
306 rtc_data[1] = bin2bcd(tm->tm_sec); 307 rtc_data[0] = bin2bcd(tm->tm_sec);
307 rtc_data[2] = bin2bcd(tm->tm_min); 308 rtc_data[1] = bin2bcd(tm->tm_min);
308 rtc_data[3] = bin2bcd(tm->tm_hour); 309 rtc_data[2] = bin2bcd(tm->tm_hour);
309 rtc_data[4] = bin2bcd(tm->tm_mday); 310 rtc_data[3] = bin2bcd(tm->tm_mday);
310 rtc_data[5] = bin2bcd(tm->tm_mon + 1); 311 rtc_data[4] = bin2bcd(tm->tm_mon + 1);
311 rtc_data[6] = bin2bcd(tm->tm_year - 100); 312 rtc_data[5] = bin2bcd(tm->tm_year - 100);
312 313
313 /* Stop RTC while updating the TC registers */ 314 /* Stop RTC while updating the TC registers */
314 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG); 315 ret = twl_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
@@ -341,7 +342,7 @@ out:
341 */ 342 */
342static int twl_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 343static int twl_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
343{ 344{
344 unsigned char rtc_data[ALL_TIME_REGS + 1]; 345 unsigned char rtc_data[ALL_TIME_REGS];
345 int ret; 346 int ret;
346 347
347 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data, 348 ret = twl_i2c_read(TWL_MODULE_RTC, rtc_data,
@@ -368,19 +369,19 @@ static int twl_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
368 369
369static int twl_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 370static int twl_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
370{ 371{
371 unsigned char alarm_data[ALL_TIME_REGS + 1]; 372 unsigned char alarm_data[ALL_TIME_REGS];
372 int ret; 373 int ret;
373 374
374 ret = twl_rtc_alarm_irq_enable(dev, 0); 375 ret = twl_rtc_alarm_irq_enable(dev, 0);
375 if (ret) 376 if (ret)
376 goto out; 377 goto out;
377 378
378 alarm_data[1] = bin2bcd(alm->time.tm_sec); 379 alarm_data[0] = bin2bcd(alm->time.tm_sec);
379 alarm_data[2] = bin2bcd(alm->time.tm_min); 380 alarm_data[1] = bin2bcd(alm->time.tm_min);
380 alarm_data[3] = bin2bcd(alm->time.tm_hour); 381 alarm_data[2] = bin2bcd(alm->time.tm_hour);
381 alarm_data[4] = bin2bcd(alm->time.tm_mday); 382 alarm_data[3] = bin2bcd(alm->time.tm_mday);
382 alarm_data[5] = bin2bcd(alm->time.tm_mon + 1); 383 alarm_data[4] = bin2bcd(alm->time.tm_mon + 1);
383 alarm_data[6] = bin2bcd(alm->time.tm_year - 100); 384 alarm_data[5] = bin2bcd(alm->time.tm_year - 100);
384 385
385 /* update all the alarm registers in one shot */ 386 /* update all the alarm registers in one shot */
386 ret = twl_i2c_write(TWL_MODULE_RTC, alarm_data, 387 ret = twl_i2c_write(TWL_MODULE_RTC, alarm_data,
@@ -458,7 +459,7 @@ static struct rtc_class_ops twl_rtc_ops = {
458 459
459/*----------------------------------------------------------------------*/ 460/*----------------------------------------------------------------------*/
460 461
461static int __devinit twl_rtc_probe(struct platform_device *pdev) 462static int twl_rtc_probe(struct platform_device *pdev)
462{ 463{
463 struct rtc_device *rtc; 464 struct rtc_device *rtc;
464 int ret = -EINVAL; 465 int ret = -EINVAL;
@@ -535,7 +536,7 @@ out1:
535 * Disable all TWL RTC module interrupts. 536 * Disable all TWL RTC module interrupts.
536 * Sets status flag to free. 537 * Sets status flag to free.
537 */ 538 */
538static int __devexit twl_rtc_remove(struct platform_device *pdev) 539static int twl_rtc_remove(struct platform_device *pdev)
539{ 540{
540 /* leave rtc running, but disable irqs */ 541 /* leave rtc running, but disable irqs */
541 struct rtc_device *rtc = platform_get_drvdata(pdev); 542 struct rtc_device *rtc = platform_get_drvdata(pdev);
@@ -588,23 +589,26 @@ static int twl_rtc_resume(struct platform_device *pdev)
588#define twl_rtc_resume NULL 589#define twl_rtc_resume NULL
589#endif 590#endif
590 591
592#ifdef CONFIG_OF
591static const struct of_device_id twl_rtc_of_match[] = { 593static const struct of_device_id twl_rtc_of_match[] = {
592 {.compatible = "ti,twl4030-rtc", }, 594 {.compatible = "ti,twl4030-rtc", },
593 { }, 595 { },
594}; 596};
595MODULE_DEVICE_TABLE(of, twl_rtc_of_match); 597MODULE_DEVICE_TABLE(of, twl_rtc_of_match);
598#endif
599
596MODULE_ALIAS("platform:twl_rtc"); 600MODULE_ALIAS("platform:twl_rtc");
597 601
598static struct platform_driver twl4030rtc_driver = { 602static struct platform_driver twl4030rtc_driver = {
599 .probe = twl_rtc_probe, 603 .probe = twl_rtc_probe,
600 .remove = __devexit_p(twl_rtc_remove), 604 .remove = twl_rtc_remove,
601 .shutdown = twl_rtc_shutdown, 605 .shutdown = twl_rtc_shutdown,
602 .suspend = twl_rtc_suspend, 606 .suspend = twl_rtc_suspend,
603 .resume = twl_rtc_resume, 607 .resume = twl_rtc_resume,
604 .driver = { 608 .driver = {
605 .owner = THIS_MODULE, 609 .owner = THIS_MODULE,
606 .name = "twl_rtc", 610 .name = "twl_rtc",
607 .of_match_table = twl_rtc_of_match, 611 .of_match_table = of_match_ptr(twl_rtc_of_match),
608 }, 612 },
609}; 613};
610 614
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index 5f60a7c6a155..f91be04b9050 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -280,7 +280,7 @@ static const struct rtc_class_ops vr41xx_rtc_ops = {
280 .set_alarm = vr41xx_rtc_set_alarm, 280 .set_alarm = vr41xx_rtc_set_alarm,
281}; 281};
282 282
283static int __devinit rtc_probe(struct platform_device *pdev) 283static int rtc_probe(struct platform_device *pdev)
284{ 284{
285 struct resource *res; 285 struct resource *res;
286 struct rtc_device *rtc; 286 struct rtc_device *rtc;
@@ -352,7 +352,7 @@ static int __devinit rtc_probe(struct platform_device *pdev)
352 disable_irq(aie_irq); 352 disable_irq(aie_irq);
353 disable_irq(pie_irq); 353 disable_irq(pie_irq);
354 354
355 printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n"); 355 dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n");
356 356
357 return 0; 357 return 0;
358 358
@@ -373,7 +373,7 @@ err_rtc1_iounmap:
373 return retval; 373 return retval;
374} 374}
375 375
376static int __devexit rtc_remove(struct platform_device *pdev) 376static int rtc_remove(struct platform_device *pdev)
377{ 377{
378 struct rtc_device *rtc; 378 struct rtc_device *rtc;
379 379
@@ -398,7 +398,7 @@ MODULE_ALIAS("platform:RTC");
398 398
399static struct platform_driver rtc_platform_driver = { 399static struct platform_driver rtc_platform_driver = {
400 .probe = rtc_probe, 400 .probe = rtc_probe,
401 .remove = __devexit_p(rtc_remove), 401 .remove = rtc_remove,
402 .driver = { 402 .driver = {
403 .name = rtc_name, 403 .name = rtc_name,
404 .owner = THIS_MODULE, 404 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
index 07bf19364a74..a000bc0a8bff 100644
--- a/drivers/rtc/rtc-vt8500.c
+++ b/drivers/rtc/rtc-vt8500.c
@@ -70,7 +70,7 @@
70 | ALARM_SEC_BIT) 70 | ALARM_SEC_BIT)
71 71
72#define VT8500_RTC_CR_ENABLE (1 << 0) /* Enable RTC */ 72#define VT8500_RTC_CR_ENABLE (1 << 0) /* Enable RTC */
73#define VT8500_RTC_CR_24H (1 << 1) /* 24h time format */ 73#define VT8500_RTC_CR_12H (1 << 1) /* 12h time format */
74#define VT8500_RTC_CR_SM_ENABLE (1 << 2) /* Enable periodic irqs */ 74#define VT8500_RTC_CR_SM_ENABLE (1 << 2) /* Enable periodic irqs */
75#define VT8500_RTC_CR_SM_SEC (1 << 3) /* 0: 1Hz/60, 1: 1Hz */ 75#define VT8500_RTC_CR_SM_SEC (1 << 3) /* 0: 1Hz/60, 1: 1Hz */
76#define VT8500_RTC_CR_CALIB (1 << 4) /* Enable calibration */ 76#define VT8500_RTC_CR_CALIB (1 << 4) /* Enable calibration */
@@ -119,7 +119,7 @@ static int vt8500_rtc_read_time(struct device *dev, struct rtc_time *tm)
119 tm->tm_min = bcd2bin((time & TIME_MIN_MASK) >> TIME_MIN_S); 119 tm->tm_min = bcd2bin((time & TIME_MIN_MASK) >> TIME_MIN_S);
120 tm->tm_hour = bcd2bin((time & TIME_HOUR_MASK) >> TIME_HOUR_S); 120 tm->tm_hour = bcd2bin((time & TIME_HOUR_MASK) >> TIME_HOUR_S);
121 tm->tm_mday = bcd2bin(date & DATE_DAY_MASK); 121 tm->tm_mday = bcd2bin(date & DATE_DAY_MASK);
122 tm->tm_mon = bcd2bin((date & DATE_MONTH_MASK) >> DATE_MONTH_S); 122 tm->tm_mon = bcd2bin((date & DATE_MONTH_MASK) >> DATE_MONTH_S) - 1;
123 tm->tm_year = bcd2bin((date & DATE_YEAR_MASK) >> DATE_YEAR_S) 123 tm->tm_year = bcd2bin((date & DATE_YEAR_MASK) >> DATE_YEAR_S)
124 + ((date >> DATE_CENTURY_S) & 1 ? 200 : 100); 124 + ((date >> DATE_CENTURY_S) & 1 ? 200 : 100);
125 tm->tm_wday = (time & TIME_DOW_MASK) >> TIME_DOW_S; 125 tm->tm_wday = (time & TIME_DOW_MASK) >> TIME_DOW_S;
@@ -137,9 +137,10 @@ static int vt8500_rtc_set_time(struct device *dev, struct rtc_time *tm)
137 return -EINVAL; 137 return -EINVAL;
138 } 138 }
139 139
140 writel((bin2bcd(tm->tm_year - 100) << DATE_YEAR_S) 140 writel((bin2bcd(tm->tm_year % 100) << DATE_YEAR_S)
141 | (bin2bcd(tm->tm_mon) << DATE_MONTH_S) 141 | (bin2bcd(tm->tm_mon + 1) << DATE_MONTH_S)
142 | (bin2bcd(tm->tm_mday)), 142 | (bin2bcd(tm->tm_mday))
143 | ((tm->tm_year >= 200) << DATE_CENTURY_S),
143 vt8500_rtc->regbase + VT8500_RTC_DS); 144 vt8500_rtc->regbase + VT8500_RTC_DS);
144 writel((bin2bcd(tm->tm_wday) << TIME_DOW_S) 145 writel((bin2bcd(tm->tm_wday) << TIME_DOW_S)
145 | (bin2bcd(tm->tm_hour) << TIME_HOUR_S) 146 | (bin2bcd(tm->tm_hour) << TIME_HOUR_S)
@@ -205,12 +206,13 @@ static const struct rtc_class_ops vt8500_rtc_ops = {
205 .alarm_irq_enable = vt8500_alarm_irq_enable, 206 .alarm_irq_enable = vt8500_alarm_irq_enable,
206}; 207};
207 208
208static int __devinit vt8500_rtc_probe(struct platform_device *pdev) 209static int vt8500_rtc_probe(struct platform_device *pdev)
209{ 210{
210 struct vt8500_rtc *vt8500_rtc; 211 struct vt8500_rtc *vt8500_rtc;
211 int ret; 212 int ret;
212 213
213 vt8500_rtc = kzalloc(sizeof(struct vt8500_rtc), GFP_KERNEL); 214 vt8500_rtc = devm_kzalloc(&pdev->dev,
215 sizeof(struct vt8500_rtc), GFP_KERNEL);
214 if (!vt8500_rtc) 216 if (!vt8500_rtc)
215 return -ENOMEM; 217 return -ENOMEM;
216 218
@@ -220,36 +222,34 @@ static int __devinit vt8500_rtc_probe(struct platform_device *pdev)
220 vt8500_rtc->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 222 vt8500_rtc->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
221 if (!vt8500_rtc->res) { 223 if (!vt8500_rtc->res) {
222 dev_err(&pdev->dev, "No I/O memory resource defined\n"); 224 dev_err(&pdev->dev, "No I/O memory resource defined\n");
223 ret = -ENXIO; 225 return -ENXIO;
224 goto err_free;
225 } 226 }
226 227
227 vt8500_rtc->irq_alarm = platform_get_irq(pdev, 0); 228 vt8500_rtc->irq_alarm = platform_get_irq(pdev, 0);
228 if (vt8500_rtc->irq_alarm < 0) { 229 if (vt8500_rtc->irq_alarm < 0) {
229 dev_err(&pdev->dev, "No alarm IRQ resource defined\n"); 230 dev_err(&pdev->dev, "No alarm IRQ resource defined\n");
230 ret = -ENXIO; 231 return -ENXIO;
231 goto err_free;
232 } 232 }
233 233
234 vt8500_rtc->res = request_mem_region(vt8500_rtc->res->start, 234 vt8500_rtc->res = devm_request_mem_region(&pdev->dev,
235 resource_size(vt8500_rtc->res), 235 vt8500_rtc->res->start,
236 "vt8500-rtc"); 236 resource_size(vt8500_rtc->res),
237 "vt8500-rtc");
237 if (vt8500_rtc->res == NULL) { 238 if (vt8500_rtc->res == NULL) {
238 dev_err(&pdev->dev, "failed to request I/O memory\n"); 239 dev_err(&pdev->dev, "failed to request I/O memory\n");
239 ret = -EBUSY; 240 return -EBUSY;
240 goto err_free;
241 } 241 }
242 242
243 vt8500_rtc->regbase = ioremap(vt8500_rtc->res->start, 243 vt8500_rtc->regbase = devm_ioremap(&pdev->dev, vt8500_rtc->res->start,
244 resource_size(vt8500_rtc->res)); 244 resource_size(vt8500_rtc->res));
245 if (!vt8500_rtc->regbase) { 245 if (!vt8500_rtc->regbase) {
246 dev_err(&pdev->dev, "Unable to map RTC I/O memory\n"); 246 dev_err(&pdev->dev, "Unable to map RTC I/O memory\n");
247 ret = -EBUSY; 247 ret = -EBUSY;
248 goto err_release; 248 goto err_return;
249 } 249 }
250 250
251 /* Enable RTC and set it to 24-hour mode */ 251 /* Enable RTC and set it to 24-hour mode */
252 writel(VT8500_RTC_CR_ENABLE | VT8500_RTC_CR_24H, 252 writel(VT8500_RTC_CR_ENABLE,
253 vt8500_rtc->regbase + VT8500_RTC_CR); 253 vt8500_rtc->regbase + VT8500_RTC_CR);
254 254
255 vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev, 255 vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev,
@@ -258,11 +258,11 @@ static int __devinit vt8500_rtc_probe(struct platform_device *pdev)
258 ret = PTR_ERR(vt8500_rtc->rtc); 258 ret = PTR_ERR(vt8500_rtc->rtc);
259 dev_err(&pdev->dev, 259 dev_err(&pdev->dev,
260 "Failed to register RTC device -> %d\n", ret); 260 "Failed to register RTC device -> %d\n", ret);
261 goto err_unmap; 261 goto err_return;
262 } 262 }
263 263
264 ret = request_irq(vt8500_rtc->irq_alarm, vt8500_rtc_irq, 0, 264 ret = devm_request_irq(&pdev->dev, vt8500_rtc->irq_alarm,
265 "rtc alarm", vt8500_rtc); 265 vt8500_rtc_irq, 0, "rtc alarm", vt8500_rtc);
266 if (ret < 0) { 266 if (ret < 0) {
267 dev_err(&pdev->dev, "can't get irq %i, err %d\n", 267 dev_err(&pdev->dev, "can't get irq %i, err %d\n",
268 vt8500_rtc->irq_alarm, ret); 268 vt8500_rtc->irq_alarm, ret);
@@ -273,31 +273,19 @@ static int __devinit vt8500_rtc_probe(struct platform_device *pdev)
273 273
274err_unreg: 274err_unreg:
275 rtc_device_unregister(vt8500_rtc->rtc); 275 rtc_device_unregister(vt8500_rtc->rtc);
276err_unmap: 276err_return:
277 iounmap(vt8500_rtc->regbase);
278err_release:
279 release_mem_region(vt8500_rtc->res->start,
280 resource_size(vt8500_rtc->res));
281err_free:
282 kfree(vt8500_rtc);
283 return ret; 277 return ret;
284} 278}
285 279
286static int __devexit vt8500_rtc_remove(struct platform_device *pdev) 280static int vt8500_rtc_remove(struct platform_device *pdev)
287{ 281{
288 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev); 282 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);
289 283
290 free_irq(vt8500_rtc->irq_alarm, vt8500_rtc);
291
292 rtc_device_unregister(vt8500_rtc->rtc); 284 rtc_device_unregister(vt8500_rtc->rtc);
293 285
294 /* Disable alarm matching */ 286 /* Disable alarm matching */
295 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS); 287 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
296 iounmap(vt8500_rtc->regbase);
297 release_mem_region(vt8500_rtc->res->start,
298 resource_size(vt8500_rtc->res));
299 288
300 kfree(vt8500_rtc);
301 platform_set_drvdata(pdev, NULL); 289 platform_set_drvdata(pdev, NULL);
302 290
303 return 0; 291 return 0;
@@ -310,7 +298,7 @@ static const struct of_device_id wmt_dt_ids[] = {
310 298
311static struct platform_driver vt8500_rtc_driver = { 299static struct platform_driver vt8500_rtc_driver = {
312 .probe = vt8500_rtc_probe, 300 .probe = vt8500_rtc_probe,
313 .remove = __devexit_p(vt8500_rtc_remove), 301 .remove = vt8500_rtc_remove,
314 .driver = { 302 .driver = {
315 .name = "vt8500-rtc", 303 .name = "vt8500-rtc",
316 .owner = THIS_MODULE, 304 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index ea5c6f857ca5..2f0ac7b30a0c 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -443,9 +443,10 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
443 goto err; 443 goto err;
444 } 444 }
445 445
446 ret = request_threaded_irq(alm_irq, NULL, wm831x_alm_irq, 446 ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
447 IRQF_TRIGGER_RISING, "RTC alarm", 447 wm831x_alm_irq,
448 wm831x_rtc); 448 IRQF_TRIGGER_RISING, "RTC alarm",
449 wm831x_rtc);
449 if (ret != 0) { 450 if (ret != 0) {
450 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", 451 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
451 alm_irq, ret); 452 alm_irq, ret);
@@ -459,12 +460,10 @@ err:
459 return ret; 460 return ret;
460} 461}
461 462
462static int __devexit wm831x_rtc_remove(struct platform_device *pdev) 463static int wm831x_rtc_remove(struct platform_device *pdev)
463{ 464{
464 struct wm831x_rtc *wm831x_rtc = platform_get_drvdata(pdev); 465 struct wm831x_rtc *wm831x_rtc = platform_get_drvdata(pdev);
465 int alm_irq = platform_get_irq_byname(pdev, "ALM");
466 466
467 free_irq(alm_irq, wm831x_rtc);
468 rtc_device_unregister(wm831x_rtc->rtc); 467 rtc_device_unregister(wm831x_rtc->rtc);
469 468
470 return 0; 469 return 0;
@@ -483,7 +482,7 @@ static const struct dev_pm_ops wm831x_rtc_pm_ops = {
483 482
484static struct platform_driver wm831x_rtc_driver = { 483static struct platform_driver wm831x_rtc_driver = {
485 .probe = wm831x_rtc_probe, 484 .probe = wm831x_rtc_probe,
486 .remove = __devexit_p(wm831x_rtc_remove), 485 .remove = wm831x_rtc_remove,
487 .driver = { 486 .driver = {
488 .name = "wm831x-rtc", 487 .name = "wm831x-rtc",
489 .pm = &wm831x_rtc_pm_ops, 488 .pm = &wm831x_rtc_pm_ops,
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
index c2e52d15abb2..8ad86ae0d30f 100644
--- a/drivers/rtc/rtc-wm8350.c
+++ b/drivers/rtc/rtc-wm8350.c
@@ -459,7 +459,7 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
459 return 0; 459 return 0;
460} 460}
461 461
462static int __devexit wm8350_rtc_remove(struct platform_device *pdev) 462static int wm8350_rtc_remove(struct platform_device *pdev)
463{ 463{
464 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 464 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
465 struct wm8350_rtc *wm_rtc = &wm8350->rtc; 465 struct wm8350_rtc *wm_rtc = &wm8350->rtc;
@@ -479,7 +479,7 @@ static struct dev_pm_ops wm8350_rtc_pm_ops = {
479 479
480static struct platform_driver wm8350_rtc_driver = { 480static struct platform_driver wm8350_rtc_driver = {
481 .probe = wm8350_rtc_probe, 481 .probe = wm8350_rtc_probe,
482 .remove = __devexit_p(wm8350_rtc_remove), 482 .remove = wm8350_rtc_remove,
483 .driver = { 483 .driver = {
484 .name = "wm8350-rtc", 484 .name = "wm8350-rtc",
485 .pm = &wm8350_rtc_pm_ops, 485 .pm = &wm8350_rtc_pm_ops,
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c
new file mode 100644
index 000000000000..bf3e242ccc5c
--- /dev/null
+++ b/drivers/rtc/systohc.c
@@ -0,0 +1,44 @@
1/*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published by
4 * the Free Software Foundation.
5 *
6 */
7#include <linux/rtc.h>
8#include <linux/time.h>
9
10/**
11 * rtc_set_ntp_time - Save NTP synchronized time to the RTC
12 * @now: Current time of day
13 *
14 * Replacement for the NTP platform function update_persistent_clock
15 * that stores time for later retrieval by rtc_hctosys.
16 *
17 * Returns 0 on successful RTC update, -ENODEV if a RTC update is not
18 * possible at all, and various other -errno for specific temporary failure
19 * cases.
20 *
21 * If temporary failure is indicated the caller should try again 'soon'
22 */
23int rtc_set_ntp_time(struct timespec now)
24{
25 struct rtc_device *rtc;
26 struct rtc_time tm;
27 int err = -ENODEV;
28
29 if (now.tv_nsec < (NSEC_PER_SEC >> 1))
30 rtc_time_to_tm(now.tv_sec, &tm);
31 else
32 rtc_time_to_tm(now.tv_sec + 1, &tm);
33
34 rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
35 if (rtc) {
36 /* rtc_hctosys exclusively uses UTC, so we call set_time here,
37 * not set_mmss. */
38 if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss))
39 err = rtc_set_time(rtc, &tm);
40 rtc_class_close(rtc);
41 }
42
43 return err;
44}