aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-05 14:09:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-05 14:09:16 -0400
commit11126c611e10abb18b6f1ed0300c0548c3906b54 (patch)
tree246227ad730c1e68f5a9c03db57cd4592abe7687 /drivers/rtc
parent67966e088b0c7dc926f4ce19565ebf208e18d058 (diff)
parent33e2a4227ddff7c18921ac175fae3ab0e3ff8a76 (diff)
Merge branch 'akpm' (Andrew's patch-bomb)
Merge misc patches from Andrew Morton: "The MM tree is rather stuck while I wait to find out what the heck is happening with sched/numa. Probably I'll need to route around all the code which was added to -next, sigh. So this is "everything else", or at least most of it - other small bits are still awaiting resolutions of various kinds." * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (180 commits) lib/decompress.c add __init to decompress_method and data kernel/resource.c: fix stack overflow in __reserve_region_with_split() omfs: convert to use beXX_add_cpu() taskstats: cgroupstats_user_cmd() may leak on error aoe: update aoe-internal version number to 50 aoe: update documentation to better reflect aoe-plus-udev usage aoe: remove unused code aoe: make dynamic block minor numbers the default aoe: update and specify AoE address guards and error messages aoe: retain static block device numbers for backwards compatibility aoe: support more AoE addresses with dynamic block device minor numbers aoe: update documentation with new URL and VM settings reference aoe: update copyright year in touched files aoe: update internal version number to 49 aoe: remove unused code and add cosmetic improvements aoe: increase net_device reference count while using it aoe: associate frames with the AoE storage target aoe: disallow unsupported AoE minor addresses aoe: do revalidation steps in order aoe: failover remote interface based on aoe_deadsecs parameter ...
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig87
-rw-r--r--drivers/rtc/Makefile5
-rw-r--r--drivers/rtc/class.c9
-rw-r--r--drivers/rtc/hctosys.c4
-rw-r--r--drivers/rtc/rtc-at91sam9.c13
-rw-r--r--drivers/rtc/rtc-coh901331.c3
-rw-r--r--drivers/rtc/rtc-ds1672.c26
-rw-r--r--drivers/rtc/rtc-ds2404.c303
-rw-r--r--drivers/rtc/rtc-em3027.c17
-rw-r--r--drivers/rtc/rtc-isl1208.c21
-rw-r--r--drivers/rtc/rtc-jz4740.c2
-rw-r--r--drivers/rtc/rtc-m41t80.c157
-rw-r--r--drivers/rtc/rtc-max8907.c244
-rw-r--r--drivers/rtc/rtc-mxc.c30
-rw-r--r--drivers/rtc/rtc-pcf8563.c13
-rw-r--r--drivers/rtc/rtc-proc.c24
-rw-r--r--drivers/rtc/rtc-rc5t583.c331
-rw-r--r--drivers/rtc/rtc-rs5c372.c7
-rw-r--r--drivers/rtc/rtc-s35390a.c129
-rw-r--r--drivers/rtc/rtc-s3c.c4
-rw-r--r--drivers/rtc/rtc-snvs.c350
-rw-r--r--drivers/rtc/rtc-spear.c12
-rw-r--r--drivers/rtc/rtc-sysfs.c6
-rw-r--r--drivers/rtc/rtc-tps65910.c349
-rw-r--r--drivers/rtc/rtc-x1205.c92
25 files changed, 1982 insertions, 256 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index fabc99a75c65..e069f176a82d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -19,7 +19,6 @@ if RTC_CLASS
19 19
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 depends on RTC_CLASS = y
23 default y 22 default y
24 help 23 help
25 If you say yes here, the system time (wall clock) will be set using 24 If you say yes here, the system time (wall clock) will be set using
@@ -51,7 +50,6 @@ config RTC_HCTOSYS_DEVICE
51 50
52config RTC_DEBUG 51config RTC_DEBUG
53 bool "RTC debug support" 52 bool "RTC debug support"
54 depends on RTC_CLASS = y
55 help 53 help
56 Say yes here to enable debugging support in the RTC framework 54 Say yes here to enable debugging support in the RTC framework
57 and individual RTC drivers. 55 and individual RTC drivers.
@@ -61,7 +59,6 @@ comment "RTC interfaces"
61config RTC_INTF_SYSFS 59config RTC_INTF_SYSFS
62 boolean "/sys/class/rtc/rtcN (sysfs)" 60 boolean "/sys/class/rtc/rtcN (sysfs)"
63 depends on SYSFS 61 depends on SYSFS
64 default RTC_CLASS
65 help 62 help
66 Say yes here if you want to use your RTCs using sysfs interfaces, 63 Say yes here if you want to use your RTCs using sysfs interfaces,
67 /sys/class/rtc/rtc0 through /sys/.../rtcN. 64 /sys/class/rtc/rtc0 through /sys/.../rtcN.
@@ -69,19 +66,19 @@ config RTC_INTF_SYSFS
69 If unsure, say Y. 66 If unsure, say Y.
70 67
71config RTC_INTF_PROC 68config RTC_INTF_PROC
72 boolean "/proc/driver/rtc (procfs for rtc0)" 69 boolean "/proc/driver/rtc (procfs for rtcN)"
73 depends on PROC_FS 70 depends on PROC_FS
74 default RTC_CLASS
75 help 71 help
76 Say yes here if you want to use your first RTC through the proc 72 Say yes here if you want to use your system clock RTC through
77 interface, /proc/driver/rtc. Other RTCs will not be available 73 the proc interface, /proc/driver/rtc.
78 through that API. 74 Other RTCs will not be available through that API.
75 If there is no RTC for the system clock, then the first RTC(rtc0)
76 is used by default.
79 77
80 If unsure, say Y. 78 If unsure, say Y.
81 79
82config RTC_INTF_DEV 80config RTC_INTF_DEV
83 boolean "/dev/rtcN (character devices)" 81 boolean "/dev/rtcN (character devices)"
84 default RTC_CLASS
85 help 82 help
86 Say yes here if you want to use your RTCs using the /dev 83 Say yes here if you want to use your RTCs using the /dev
87 interfaces, which "udev" sets up as /dev/rtc0 through 84 interfaces, which "udev" sets up as /dev/rtc0 through
@@ -127,7 +124,7 @@ if I2C
127 124
128config RTC_DRV_88PM860X 125config RTC_DRV_88PM860X
129 tristate "Marvell 88PM860x" 126 tristate "Marvell 88PM860x"
130 depends on RTC_CLASS && I2C && MFD_88PM860X 127 depends on I2C && MFD_88PM860X
131 help 128 help
132 If you say yes here you get support for RTC function in Marvell 129 If you say yes here you get support for RTC function in Marvell
133 88PM860x chips. 130 88PM860x chips.
@@ -137,7 +134,7 @@ config RTC_DRV_88PM860X
137 134
138config RTC_DRV_88PM80X 135config RTC_DRV_88PM80X
139 tristate "Marvell 88PM80x" 136 tristate "Marvell 88PM80x"
140 depends on RTC_CLASS && I2C && MFD_88PM800 137 depends on I2C && MFD_88PM800
141 help 138 help
142 If you say yes here you get support for RTC function in Marvell 139 If you say yes here you get support for RTC function in Marvell
143 88PM80x chips. 140 88PM80x chips.
@@ -165,7 +162,7 @@ config RTC_DRV_DS1307
165 162
166config RTC_DRV_DS1374 163config RTC_DRV_DS1374
167 tristate "Dallas/Maxim DS1374" 164 tristate "Dallas/Maxim DS1374"
168 depends on RTC_CLASS && I2C 165 depends on I2C
169 help 166 help
170 If you say yes here you get support for Dallas Semiconductor 167 If you say yes here you get support for Dallas Semiconductor
171 DS1374 real-time clock chips. If an interrupt is associated 168 DS1374 real-time clock chips. If an interrupt is associated
@@ -185,7 +182,7 @@ config RTC_DRV_DS1672
185 182
186config RTC_DRV_DS3232 183config RTC_DRV_DS3232
187 tristate "Dallas/Maxim DS3232" 184 tristate "Dallas/Maxim DS3232"
188 depends on RTC_CLASS && I2C 185 depends on I2C
189 help 186 help
190 If you say yes here you get support for Dallas Semiconductor 187 If you say yes here you get support for Dallas Semiconductor
191 DS3232 real-time clock chips. If an interrupt is associated 188 DS3232 real-time clock chips. If an interrupt is associated
@@ -203,6 +200,16 @@ config RTC_DRV_MAX6900
203 This driver can also be built as a module. If so, the module 200 This driver can also be built as a module. If so, the module
204 will be called rtc-max6900. 201 will be called rtc-max6900.
205 202
203config RTC_DRV_MAX8907
204 tristate "Maxim MAX8907"
205 depends on MFD_MAX8907
206 help
207 If you say yes here you will get support for the
208 RTC of Maxim MAX8907 PMIC.
209
210 This driver can also be built as a module. If so, the module
211 will be called rtc-max8907.
212
206config RTC_DRV_MAX8925 213config RTC_DRV_MAX8925
207 tristate "Maxim MAX8925" 214 tristate "Maxim MAX8925"
208 depends on MFD_MAX8925 215 depends on MFD_MAX8925
@@ -325,7 +332,7 @@ config RTC_DRV_TWL92330
325 332
326config RTC_DRV_TWL4030 333config RTC_DRV_TWL4030
327 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0" 334 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0"
328 depends on RTC_CLASS && TWL4030_CORE 335 depends on TWL4030_CORE
329 help 336 help
330 If you say yes here you get support for the RTC on the 337 If you say yes here you get support for the RTC on the
331 TWL4030/TWL5030/TWL6030 family chips, used mostly with OMAP3 platforms. 338 TWL4030/TWL5030/TWL6030 family chips, used mostly with OMAP3 platforms.
@@ -333,6 +340,26 @@ config RTC_DRV_TWL4030
333 This driver can also be built as a module. If so, the module 340 This driver can also be built as a module. If so, the module
334 will be called rtc-twl. 341 will be called rtc-twl.
335 342
343config RTC_DRV_TPS65910
344 tristate "TI TPS65910 RTC driver"
345 depends on RTC_CLASS && MFD_TPS65910
346 help
347 If you say yes here you get support for the RTC on the
348 TPS65910 chips.
349
350 This driver can also be built as a module. If so, the module
351 will be called rtc-tps65910.
352
353config RTC_DRV_RC5T583
354 tristate "RICOH 5T583 RTC driver"
355 depends on MFD_RC5T583
356 help
357 If you say yes here you get support for the RTC on the
358 RICOH 5T583 chips.
359
360 This driver can also be built as a module. If so, the module
361 will be called rtc-rc5t583.
362
336config RTC_DRV_S35390A 363config RTC_DRV_S35390A
337 tristate "Seiko Instruments S-35390A" 364 tristate "Seiko Instruments S-35390A"
338 select BITREVERSE 365 select BITREVERSE
@@ -538,7 +565,6 @@ config RTC_DRV_DS1302
538 565
539config RTC_DRV_DS1511 566config RTC_DRV_DS1511
540 tristate "Dallas DS1511" 567 tristate "Dallas DS1511"
541 depends on RTC_CLASS
542 help 568 help
543 If you say yes here you get support for the 569 If you say yes here you get support for the
544 Dallas DS1511 timekeeping/watchdog chip. 570 Dallas DS1511 timekeeping/watchdog chip.
@@ -583,7 +609,6 @@ config RTC_DRV_EFI
583 609
584config RTC_DRV_STK17TA8 610config RTC_DRV_STK17TA8
585 tristate "Simtek STK17TA8" 611 tristate "Simtek STK17TA8"
586 depends on RTC_CLASS
587 help 612 help
588 If you say yes here you get support for the 613 If you say yes here you get support for the
589 Simtek STK17TA8 timekeeping chip. 614 Simtek STK17TA8 timekeeping chip.
@@ -658,6 +683,15 @@ config RTC_DRV_V3020
658 This driver can also be built as a module. If so, the module 683 This driver can also be built as a module. If so, the module
659 will be called rtc-v3020. 684 will be called rtc-v3020.
660 685
686config RTC_DRV_DS2404
687 tristate "Dallas DS2404"
688 help
689 If you say yes here you get support for the
690 Dallas DS2404 RTC chip.
691
692 This driver can also be built as a module. If so, the module
693 will be called rtc-ds2404.
694
661config RTC_DRV_WM831X 695config RTC_DRV_WM831X
662 tristate "Wolfson Microelectronics WM831x RTC" 696 tristate "Wolfson Microelectronics WM831x RTC"
663 depends on MFD_WM831X 697 depends on MFD_WM831X
@@ -704,6 +738,7 @@ config RTC_DRV_AB3100
704config RTC_DRV_AB8500 738config RTC_DRV_AB8500
705 tristate "ST-Ericsson AB8500 RTC" 739 tristate "ST-Ericsson AB8500 RTC"
706 depends on AB8500_CORE 740 depends on AB8500_CORE
741 select RTC_INTF_DEV
707 select RTC_INTF_DEV_UIE_EMUL 742 select RTC_INTF_DEV_UIE_EMUL
708 help 743 help
709 Select this to enable the ST-Ericsson AB8500 power management IC RTC 744 Select this to enable the ST-Ericsson AB8500 power management IC RTC
@@ -711,7 +746,7 @@ config RTC_DRV_AB8500
711 746
712config RTC_DRV_NUC900 747config RTC_DRV_NUC900
713 tristate "NUC910/NUC920 RTC driver" 748 tristate "NUC910/NUC920 RTC driver"
714 depends on RTC_CLASS && ARCH_W90X900 749 depends on ARCH_W90X900
715 help 750 help
716 If you say yes here you get support for the RTC subsystem of the 751 If you say yes here you get support for the RTC subsystem of the
717 NUC910/NUC920 used in embedded systems. 752 NUC910/NUC920 used in embedded systems.
@@ -731,7 +766,6 @@ config RTC_DRV_DAVINCI
731config RTC_DRV_IMXDI 766config RTC_DRV_IMXDI
732 tristate "Freescale IMX DryIce Real Time Clock" 767 tristate "Freescale IMX DryIce Real Time Clock"
733 depends on SOC_IMX25 768 depends on SOC_IMX25
734 depends on RTC_CLASS
735 help 769 help
736 Support for Freescale IMX DryIce RTC 770 Support for Freescale IMX DryIce RTC
737 771
@@ -791,7 +825,7 @@ config RTC_DRV_SA1100
791 825
792config RTC_DRV_SH 826config RTC_DRV_SH
793 tristate "SuperH On-Chip RTC" 827 tristate "SuperH On-Chip RTC"
794 depends on RTC_CLASS && SUPERH && HAVE_CLK 828 depends on SUPERH && HAVE_CLK
795 help 829 help
796 Say Y here to enable support for the on-chip RTC found in 830 Say Y here to enable support for the on-chip RTC found in
797 most SuperH processors. 831 most SuperH processors.
@@ -1023,7 +1057,6 @@ config RTC_DRV_MPC5121
1023 1057
1024config RTC_DRV_JZ4740 1058config RTC_DRV_JZ4740
1025 tristate "Ingenic JZ4740 SoC" 1059 tristate "Ingenic JZ4740 SoC"
1026 depends on RTC_CLASS
1027 depends on MACH_JZ4740 1060 depends on MACH_JZ4740
1028 help 1061 help
1029 If you say yes here you get support for the Ingenic JZ4740 SoC RTC 1062 If you say yes here you get support for the Ingenic JZ4740 SoC RTC
@@ -1053,7 +1086,7 @@ config RTC_DRV_PM8XXX
1053 1086
1054config RTC_DRV_TEGRA 1087config RTC_DRV_TEGRA
1055 tristate "NVIDIA Tegra Internal RTC driver" 1088 tristate "NVIDIA Tegra Internal RTC driver"
1056 depends on RTC_CLASS && ARCH_TEGRA 1089 depends on ARCH_TEGRA
1057 help 1090 help
1058 If you say yes here you get support for the 1091 If you say yes here you get support for the
1059 Tegra 200 series internal RTC module. 1092 Tegra 200 series internal RTC module.
@@ -1090,7 +1123,6 @@ config RTC_DRV_LOONGSON1
1090config RTC_DRV_MXC 1123config RTC_DRV_MXC
1091 tristate "Freescale MXC Real Time Clock" 1124 tristate "Freescale MXC Real Time Clock"
1092 depends on ARCH_MXC 1125 depends on ARCH_MXC
1093 depends on RTC_CLASS
1094 help 1126 help
1095 If you say yes here you get support for the Freescale MXC 1127 If you say yes here you get support for the Freescale MXC
1096 RTC module. 1128 RTC module.
@@ -1098,4 +1130,15 @@ config RTC_DRV_MXC
1098 This driver can also be built as a module, if so, the module 1130 This driver can also be built as a module, if so, the module
1099 will be called "rtc-mxc". 1131 will be called "rtc-mxc".
1100 1132
1133config RTC_DRV_SNVS
1134 tristate "Freescale SNVS RTC support"
1135 depends on HAS_IOMEM
1136 depends on OF
1137 help
1138 If you say yes here you get support for the Freescale SNVS
1139 Low Power (LP) RTC module.
1140
1141 This driver can also be built as a module, if so, the module
1142 will be called "rtc-snvs".
1143
1101endif # RTC_CLASS 1144endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 0d5b2b66f90d..56297f0fd388 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
43obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 43obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
44obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 44obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
45obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 45obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
46obj-$(CONFIG_RTC_DRV_DS2404) += rtc-ds2404.o
46obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o 47obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o
47obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o 48obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o
48obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o 49obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o
@@ -64,6 +65,7 @@ obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o
64obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 65obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
65obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o 66obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o
66obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o 67obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
68obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o
67obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o 69obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o
68obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o 70obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o
69obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 71obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
@@ -85,6 +87,7 @@ obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o
85obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o 87obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o
86obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o 88obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o
87obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o 89obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
90obj-$(CONFIG_RTC_DRV_RC5T583) += rtc-rc5t583.o
88obj-$(CONFIG_RTC_DRV_RP5C01) += rtc-rp5c01.o 91obj-$(CONFIG_RTC_DRV_RP5C01) += rtc-rp5c01.o
89obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o 92obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
90obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o 93obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
@@ -96,6 +99,7 @@ obj-$(CONFIG_RTC_DRV_S35390A) += rtc-s35390a.o
96obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o 99obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
97obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 100obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
98obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 101obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
102obj-$(CONFIG_RTC_DRV_SNVS) += rtc-snvs.o
99obj-$(CONFIG_RTC_DRV_SPEAR) += rtc-spear.o 103obj-$(CONFIG_RTC_DRV_SPEAR) += rtc-spear.o
100obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o 104obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o
101obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o 105obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
@@ -105,6 +109,7 @@ obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o
105obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 109obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
106obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o 110obj-$(CONFIG_RTC_DRV_TILE) += rtc-tile.o
107obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o 111obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o
112obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o
108obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o 113obj-$(CONFIG_RTC_DRV_TX4939) += rtc-tx4939.o
109obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 114obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
110obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 115obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index dc4c2748bbc3..f8a0aab218cb 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -31,8 +31,12 @@ static void rtc_device_release(struct device *dev)
31 kfree(rtc); 31 kfree(rtc);
32} 32}
33 33
34#if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE) 34#ifdef CONFIG_RTC_HCTOSYS_DEVICE
35/* Result of the last RTC to system clock attempt. */
36int rtc_hctosys_ret = -ENODEV;
37#endif
35 38
39#if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
36/* 40/*
37 * On suspend(), measure the delta between one RTC and the 41 * On suspend(), measure the delta between one RTC and the
38 * system's wall clock; restore it on resume(). 42 * system's wall clock; restore it on resume().
@@ -84,6 +88,7 @@ static int rtc_resume(struct device *dev)
84 struct timespec new_system, new_rtc; 88 struct timespec new_system, new_rtc;
85 struct timespec sleep_time; 89 struct timespec sleep_time;
86 90
91 rtc_hctosys_ret = -ENODEV;
87 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 92 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
88 return 0; 93 return 0;
89 94
@@ -117,6 +122,7 @@ static int rtc_resume(struct device *dev)
117 122
118 if (sleep_time.tv_sec >= 0) 123 if (sleep_time.tv_sec >= 0)
119 timekeeping_inject_sleeptime(&sleep_time); 124 timekeeping_inject_sleeptime(&sleep_time);
125 rtc_hctosys_ret = 0;
120 return 0; 126 return 0;
121} 127}
122 128
@@ -238,6 +244,7 @@ void rtc_device_unregister(struct rtc_device *rtc)
238 rtc_proc_del_device(rtc); 244 rtc_proc_del_device(rtc);
239 device_unregister(&rtc->dev); 245 device_unregister(&rtc->dev);
240 rtc->ops = NULL; 246 rtc->ops = NULL;
247 ida_simple_remove(&rtc_ida, rtc->id);
241 mutex_unlock(&rtc->ops_lock); 248 mutex_unlock(&rtc->ops_lock);
242 put_device(&rtc->dev); 249 put_device(&rtc->dev);
243 } 250 }
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index bc90b091f195..4aa60d74004e 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -22,8 +22,6 @@
22 * the best guess is to add 0.5s. 22 * the best guess is to add 0.5s.
23 */ 23 */
24 24
25int rtc_hctosys_ret = -ENODEV;
26
27static int __init rtc_hctosys(void) 25static int __init rtc_hctosys(void)
28{ 26{
29 int err = -ENODEV; 27 int err = -ENODEV;
@@ -56,7 +54,7 @@ static int __init rtc_hctosys(void)
56 54
57 rtc_tm_to_time(&tm, &tv.tv_sec); 55 rtc_tm_to_time(&tm, &tv.tv_sec);
58 56
59 do_settimeofday(&tv); 57 err = do_settimeofday(&tv);
60 58
61 dev_info(rtc->dev.parent, 59 dev_info(rtc->dev.parent,
62 "setting system clock to " 60 "setting system clock to "
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 1dd61f402b04..2dfe7a2fb998 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -473,18 +473,7 @@ static struct platform_driver at91_rtc_driver = {
473 }, 473 },
474}; 474};
475 475
476static int __init at91_rtc_init(void) 476module_platform_driver(at91_rtc_driver);
477{
478 return platform_driver_register(&at91_rtc_driver);
479}
480module_init(at91_rtc_init);
481
482static void __exit at91_rtc_exit(void)
483{
484 platform_driver_unregister(&at91_rtc_driver);
485}
486module_exit(at91_rtc_exit);
487
488 477
489MODULE_AUTHOR("Michel Benoit"); 478MODULE_AUTHOR("Michel Benoit");
490MODULE_DESCRIPTION("RTC driver for Atmel AT91SAM9x"); 479MODULE_DESCRIPTION("RTC driver for Atmel AT91SAM9x");
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index 76b2156d3c62..c8115b83e5ab 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -276,8 +276,7 @@ static void coh901331_shutdown(struct platform_device *pdev)
276 276
277 clk_enable(rtap->clk); 277 clk_enable(rtap->clk);
278 writel(0, rtap->virtbase + COH901331_IRQ_MASK); 278 writel(0, rtap->virtbase + COH901331_IRQ_MASK);
279 clk_disable(rtap->clk); 279 clk_disable_unprepare(rtap->clk);
280 clk_unprepare(rtap->clk);
281} 280}
282 281
283static struct platform_driver coh901331_driver = { 282static struct platform_driver coh901331_driver = {
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 7fa67d0df172..45d65c0b3a85 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -37,8 +37,17 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
37 unsigned char buf[4]; 37 unsigned char buf[4];
38 38
39 struct i2c_msg msgs[] = { 39 struct i2c_msg msgs[] = {
40 {client->addr, 0, 1, &addr}, /* setup read ptr */ 40 {/* setup read ptr */
41 {client->addr, I2C_M_RD, 4, buf}, /* read date */ 41 .addr = client->addr,
42 .len = 1,
43 .buf = &addr
44 },
45 {/* read date */
46 .addr = client->addr,
47 .flags = I2C_M_RD,
48 .len = 4,
49 .buf = buf
50 },
42 }; 51 };
43 52
44 /* read date registers */ 53 /* read date registers */
@@ -99,8 +108,17 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
99 unsigned char addr = DS1672_REG_CONTROL; 108 unsigned char addr = DS1672_REG_CONTROL;
100 109
101 struct i2c_msg msgs[] = { 110 struct i2c_msg msgs[] = {
102 {client->addr, 0, 1, &addr}, /* setup read ptr */ 111 {/* setup read ptr */
103 {client->addr, I2C_M_RD, 1, status}, /* read control */ 112 .addr = client->addr,
113 .len = 1,
114 .buf = &addr
115 },
116 {/* read control */
117 .addr = client->addr,
118 .flags = I2C_M_RD,
119 .len = 1,
120 .buf = status
121 },
104 }; 122 };
105 123
106 /* read control register */ 124 /* read control register */
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
new file mode 100644
index 000000000000..5ea9df7c8c31
--- /dev/null
+++ b/drivers/rtc/rtc-ds2404.c
@@ -0,0 +1,303 @@
1/*
2 * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
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
10#include <linux/platform_device.h>
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/rtc.h>
14#include <linux/types.h>
15#include <linux/bcd.h>
16#include <linux/rtc-ds2404.h>
17#include <linux/delay.h>
18#include <linux/gpio.h>
19#include <linux/slab.h>
20
21#include <linux/io.h>
22
23#define DS2404_STATUS_REG 0x200
24#define DS2404_CONTROL_REG 0x201
25#define DS2404_RTC_REG 0x202
26
27#define DS2404_WRITE_SCRATCHPAD_CMD 0x0f
28#define DS2404_READ_SCRATCHPAD_CMD 0xaa
29#define DS2404_COPY_SCRATCHPAD_CMD 0x55
30#define DS2404_READ_MEMORY_CMD 0xf0
31
32struct ds2404;
33
34struct ds2404_chip_ops {
35 int (*map_io)(struct ds2404 *chip, struct platform_device *pdev,
36 struct ds2404_platform_data *pdata);
37 void (*unmap_io)(struct ds2404 *chip);
38};
39
40#define DS2404_RST 0
41#define DS2404_CLK 1
42#define DS2404_DQ 2
43
44struct ds2404_gpio {
45 const char *name;
46 unsigned int gpio;
47};
48
49struct ds2404 {
50 struct ds2404_gpio *gpio;
51 struct ds2404_chip_ops *ops;
52 struct rtc_device *rtc;
53};
54
55static struct ds2404_gpio ds2404_gpio[] = {
56 { "RTC RST", 0 },
57 { "RTC CLK", 0 },
58 { "RTC DQ", 0 },
59};
60
61static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev,
62 struct ds2404_platform_data *pdata)
63{
64 int i, err;
65
66 ds2404_gpio[DS2404_RST].gpio = pdata->gpio_rst;
67 ds2404_gpio[DS2404_CLK].gpio = pdata->gpio_clk;
68 ds2404_gpio[DS2404_DQ].gpio = pdata->gpio_dq;
69
70 for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++) {
71 err = gpio_request(ds2404_gpio[i].gpio, ds2404_gpio[i].name);
72 if (err) {
73 printk(KERN_ERR "error mapping gpio %s: %d\n",
74 ds2404_gpio[i].name, err);
75 goto err_request;
76 }
77 if (i != DS2404_DQ)
78 gpio_direction_output(ds2404_gpio[i].gpio, 1);
79 }
80
81 chip->gpio = ds2404_gpio;
82 return 0;
83
84err_request:
85 while (--i >= 0)
86 gpio_free(ds2404_gpio[i].gpio);
87 return err;
88}
89
90static void ds2404_gpio_unmap(struct ds2404 *chip)
91{
92 int i;
93
94 for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++)
95 gpio_free(ds2404_gpio[i].gpio);
96}
97
98static struct ds2404_chip_ops ds2404_gpio_ops = {
99 .map_io = ds2404_gpio_map,
100 .unmap_io = ds2404_gpio_unmap,
101};
102
103static void ds2404_reset(struct device *dev)
104{
105 gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0);
106 udelay(1000);
107 gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 1);
108 gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0);
109 gpio_direction_output(ds2404_gpio[DS2404_DQ].gpio, 0);
110 udelay(10);
111}
112
113static void ds2404_write_byte(struct device *dev, u8 byte)
114{
115 int i;
116
117 gpio_direction_output(ds2404_gpio[DS2404_DQ].gpio, 1);
118 for (i = 0; i < 8; i++) {
119 gpio_set_value(ds2404_gpio[DS2404_DQ].gpio, byte & (1 << i));
120 udelay(10);
121 gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 1);
122 udelay(10);
123 gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0);
124 udelay(10);
125 }
126}
127
128static u8 ds2404_read_byte(struct device *dev)
129{
130 int i;
131 u8 ret = 0;
132
133 gpio_direction_input(ds2404_gpio[DS2404_DQ].gpio);
134
135 for (i = 0; i < 8; i++) {
136 gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0);
137 udelay(10);
138 if (gpio_get_value(ds2404_gpio[DS2404_DQ].gpio))
139 ret |= 1 << i;
140 gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 1);
141 udelay(10);
142 }
143 return ret;
144}
145
146static void ds2404_read_memory(struct device *dev, u16 offset,
147 int length, u8 *out)
148{
149 ds2404_reset(dev);
150 ds2404_write_byte(dev, DS2404_READ_MEMORY_CMD);
151 ds2404_write_byte(dev, offset & 0xff);
152 ds2404_write_byte(dev, (offset >> 8) & 0xff);
153 while (length--)
154 *out++ = ds2404_read_byte(dev);
155}
156
157static void ds2404_write_memory(struct device *dev, u16 offset,
158 int length, u8 *out)
159{
160 int i;
161 u8 ta01, ta02, es;
162
163 ds2404_reset(dev);
164 ds2404_write_byte(dev, DS2404_WRITE_SCRATCHPAD_CMD);
165 ds2404_write_byte(dev, offset & 0xff);
166 ds2404_write_byte(dev, (offset >> 8) & 0xff);
167
168 for (i = 0; i < length; i++)
169 ds2404_write_byte(dev, out[i]);
170
171 ds2404_reset(dev);
172 ds2404_write_byte(dev, DS2404_READ_SCRATCHPAD_CMD);
173
174 ta01 = ds2404_read_byte(dev);
175 ta02 = ds2404_read_byte(dev);
176 es = ds2404_read_byte(dev);
177
178 for (i = 0; i < length; i++) {
179 if (out[i] != ds2404_read_byte(dev)) {
180 printk(KERN_ERR "read invalid data\n");
181 return;
182 }
183 }
184
185 ds2404_reset(dev);
186 ds2404_write_byte(dev, DS2404_COPY_SCRATCHPAD_CMD);
187 ds2404_write_byte(dev, ta01);
188 ds2404_write_byte(dev, ta02);
189 ds2404_write_byte(dev, es);
190
191 gpio_direction_input(ds2404_gpio[DS2404_DQ].gpio);
192 while (gpio_get_value(ds2404_gpio[DS2404_DQ].gpio))
193 ;
194}
195
196static void ds2404_enable_osc(struct device *dev)
197{
198 u8 in[1] = { 0x10 }; /* enable oscillator */
199 ds2404_write_memory(dev, 0x201, 1, in);
200}
201
202static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
203{
204 unsigned long time = 0;
205
206 ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
207 time = le32_to_cpu(time);
208
209 rtc_time_to_tm(time, dt);
210 return rtc_valid_tm(dt);
211}
212
213static int ds2404_set_mmss(struct device *dev, unsigned long secs)
214{
215 u32 time = cpu_to_le32(secs);
216 ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
217 return 0;
218}
219
220static const struct rtc_class_ops ds2404_rtc_ops = {
221 .read_time = ds2404_read_time,
222 .set_mmss = ds2404_set_mmss,
223};
224
225static int rtc_probe(struct platform_device *pdev)
226{
227 struct ds2404_platform_data *pdata = pdev->dev.platform_data;
228 struct ds2404 *chip;
229 int retval = -EBUSY;
230
231 chip = kzalloc(sizeof(struct ds2404), GFP_KERNEL);
232 if (!chip)
233 return -ENOMEM;
234
235 chip->ops = &ds2404_gpio_ops;
236
237 retval = chip->ops->map_io(chip, pdev, pdata);
238 if (retval)
239 goto err_chip;
240
241 dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
242 chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
243 chip->gpio[DS2404_DQ].gpio);
244
245 platform_set_drvdata(pdev, chip);
246
247 chip->rtc = rtc_device_register("ds2404",
248 &pdev->dev, &ds2404_rtc_ops, THIS_MODULE);
249 if (IS_ERR(chip->rtc)) {
250 retval = PTR_ERR(chip->rtc);
251 goto err_io;
252 }
253
254 ds2404_enable_osc(&pdev->dev);
255 return 0;
256
257err_io:
258 chip->ops->unmap_io(chip);
259err_chip:
260 kfree(chip);
261 return retval;
262}
263
264static int rtc_remove(struct platform_device *dev)
265{
266 struct ds2404 *chip = platform_get_drvdata(dev);
267 struct rtc_device *rtc = chip->rtc;
268
269 if (rtc)
270 rtc_device_unregister(rtc);
271
272 chip->ops->unmap_io(chip);
273 kfree(chip);
274
275 return 0;
276}
277
278static struct platform_driver rtc_device_driver = {
279 .probe = rtc_probe,
280 .remove = rtc_remove,
281 .driver = {
282 .name = "ds2404",
283 .owner = THIS_MODULE,
284 },
285};
286
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
300MODULE_DESCRIPTION("DS2404 RTC");
301MODULE_AUTHOR("Sven Schnelle");
302MODULE_LICENSE("GPL");
303MODULE_ALIAS("platform:ds2404");
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index 0104ea7ebe50..f6c24ce35d36 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -49,8 +49,17 @@ static int em3027_get_time(struct device *dev, struct rtc_time *tm)
49 unsigned char buf[7]; 49 unsigned char buf[7];
50 50
51 struct i2c_msg msgs[] = { 51 struct i2c_msg msgs[] = {
52 {client->addr, 0, 1, &addr}, /* setup read addr */ 52 {/* setup read addr */
53 {client->addr, I2C_M_RD, 7, buf}, /* read time/date */ 53 .addr = client->addr,
54 .len = 1,
55 .buf = &addr
56 },
57 {/* read time/date */
58 .addr = client->addr,
59 .flags = I2C_M_RD,
60 .len = 7,
61 .buf = buf
62 },
54 }; 63 };
55 64
56 /* read time/date registers */ 65 /* read time/date registers */
@@ -76,7 +85,9 @@ static int em3027_set_time(struct device *dev, struct rtc_time *tm)
76 unsigned char buf[8]; 85 unsigned char buf[8];
77 86
78 struct i2c_msg msg = { 87 struct i2c_msg msg = {
79 client->addr, 0, 8, buf, /* write time/date */ 88 .addr = client->addr,
89 .len = 8,
90 .buf = buf, /* write time/date */
80 }; 91 };
81 92
82 buf[0] = EM3027_REG_WATCH_SEC; 93 buf[0] = EM3027_REG_WATCH_SEC;
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index dd2aeee6c66a..26c81f233606 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -68,9 +68,17 @@ isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
68{ 68{
69 u8 reg_addr[1] = { reg }; 69 u8 reg_addr[1] = { reg };
70 struct i2c_msg msgs[2] = { 70 struct i2c_msg msgs[2] = {
71 {client->addr, 0, sizeof(reg_addr), reg_addr} 71 {
72 , 72 .addr = client->addr,
73 {client->addr, I2C_M_RD, len, buf} 73 .len = sizeof(reg_addr),
74 .buf = reg_addr
75 },
76 {
77 .addr = client->addr,
78 .flags = I2C_M_RD,
79 .len = len,
80 .buf = buf
81 }
74 }; 82 };
75 int ret; 83 int ret;
76 84
@@ -90,7 +98,11 @@ isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
90{ 98{
91 u8 i2c_buf[ISL1208_REG_USR2 + 2]; 99 u8 i2c_buf[ISL1208_REG_USR2 + 2];
92 struct i2c_msg msgs[1] = { 100 struct i2c_msg msgs[1] = {
93 {client->addr, 0, len + 1, i2c_buf} 101 {
102 .addr = client->addr,
103 .len = len + 1,
104 .buf = i2c_buf
105 }
94 }; 106 };
95 int ret; 107 int ret;
96 108
@@ -697,6 +709,7 @@ isl1208_remove(struct i2c_client *client)
697 709
698static const struct i2c_device_id isl1208_id[] = { 710static const struct i2c_device_id isl1208_id[] = {
699 { "isl1208", 0 }, 711 { "isl1208", 0 },
712 { "isl1218", 0 },
700 { } 713 { }
701}; 714};
702MODULE_DEVICE_TABLE(i2c, isl1208_id); 715MODULE_DEVICE_TABLE(i2c, isl1208_id);
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 05ab227eeff7..1224182d3eab 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -42,7 +42,7 @@ struct jz4740_rtc {
42 42
43 struct rtc_device *rtc; 43 struct rtc_device *rtc;
44 44
45 unsigned int irq; 45 int irq;
46 46
47 spinlock_t lock; 47 spinlock_t lock;
48}; 48};
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 4e0f84af99a7..b885bcd08908 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -213,163 +213,14 @@ static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm)
213 return m41t80_set_datetime(to_i2c_client(dev), tm); 213 return m41t80_set_datetime(to_i2c_client(dev), tm);
214} 214}
215 215
216static int m41t80_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 216/*
217{ 217 * XXX - m41t80 alarm functionality is reported broken.
218 struct i2c_client *client = to_i2c_client(dev); 218 * until it is fixed, don't register alarm functions.
219 int rc; 219 */
220
221 rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
222 if (rc < 0)
223 goto err;
224
225 if (enabled)
226 rc |= M41T80_ALMON_AFE;
227 else
228 rc &= ~M41T80_ALMON_AFE;
229
230 if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, rc) < 0)
231 goto err;
232
233 return 0;
234err:
235 return -EIO;
236}
237
238static int m41t80_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
239{
240 struct i2c_client *client = to_i2c_client(dev);
241 u8 wbuf[1 + M41T80_ALARM_REG_SIZE];
242 u8 *buf = &wbuf[1];
243 u8 *reg = buf - M41T80_REG_ALARM_MON;
244 u8 dt_addr[1] = { M41T80_REG_ALARM_MON };
245 struct i2c_msg msgs_in[] = {
246 {
247 .addr = client->addr,
248 .flags = 0,
249 .len = 1,
250 .buf = dt_addr,
251 },
252 {
253 .addr = client->addr,
254 .flags = I2C_M_RD,
255 .len = M41T80_ALARM_REG_SIZE,
256 .buf = buf,
257 },
258 };
259 struct i2c_msg msgs[] = {
260 {
261 .addr = client->addr,
262 .flags = 0,
263 .len = 1 + M41T80_ALARM_REG_SIZE,
264 .buf = wbuf,
265 },
266 };
267
268 if (i2c_transfer(client->adapter, msgs_in, 2) < 0) {
269 dev_err(&client->dev, "read error\n");
270 return -EIO;
271 }
272 reg[M41T80_REG_ALARM_MON] &= ~(0x1f | M41T80_ALMON_AFE);
273 reg[M41T80_REG_ALARM_DAY] = 0;
274 reg[M41T80_REG_ALARM_HOUR] &= ~(0x3f | 0x80);
275 reg[M41T80_REG_ALARM_MIN] = 0;
276 reg[M41T80_REG_ALARM_SEC] = 0;
277
278 wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */
279 reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ?
280 bin2bcd(t->time.tm_sec) : 0x80;
281 reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ?
282 bin2bcd(t->time.tm_min) : 0x80;
283 reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ?
284 bin2bcd(t->time.tm_hour) : 0x80;
285 reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ?
286 bin2bcd(t->time.tm_mday) : 0x80;
287 if (t->time.tm_mon >= 0)
288 reg[M41T80_REG_ALARM_MON] |= bin2bcd(t->time.tm_mon + 1);
289 else
290 reg[M41T80_REG_ALARM_DAY] |= 0x40;
291
292 if (i2c_transfer(client->adapter, msgs, 1) != 1) {
293 dev_err(&client->dev, "write error\n");
294 return -EIO;
295 }
296
297 if (t->enabled) {
298 reg[M41T80_REG_ALARM_MON] |= M41T80_ALMON_AFE;
299 if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
300 reg[M41T80_REG_ALARM_MON]) < 0) {
301 dev_err(&client->dev, "write error\n");
302 return -EIO;
303 }
304 }
305 return 0;
306}
307
308static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t)
309{
310 struct i2c_client *client = to_i2c_client(dev);
311 u8 buf[M41T80_ALARM_REG_SIZE + 1]; /* all alarm regs and flags */
312 u8 dt_addr[1] = { M41T80_REG_ALARM_MON };
313 u8 *reg = buf - M41T80_REG_ALARM_MON;
314 struct i2c_msg msgs[] = {
315 {
316 .addr = client->addr,
317 .flags = 0,
318 .len = 1,
319 .buf = dt_addr,
320 },
321 {
322 .addr = client->addr,
323 .flags = I2C_M_RD,
324 .len = M41T80_ALARM_REG_SIZE + 1,
325 .buf = buf,
326 },
327 };
328
329 if (i2c_transfer(client->adapter, msgs, 2) < 0) {
330 dev_err(&client->dev, "read error\n");
331 return -EIO;
332 }
333 t->time.tm_sec = -1;
334 t->time.tm_min = -1;
335 t->time.tm_hour = -1;
336 t->time.tm_mday = -1;
337 t->time.tm_mon = -1;
338 if (!(reg[M41T80_REG_ALARM_SEC] & 0x80))
339 t->time.tm_sec = bcd2bin(reg[M41T80_REG_ALARM_SEC] & 0x7f);
340 if (!(reg[M41T80_REG_ALARM_MIN] & 0x80))
341 t->time.tm_min = bcd2bin(reg[M41T80_REG_ALARM_MIN] & 0x7f);
342 if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80))
343 t->time.tm_hour = bcd2bin(reg[M41T80_REG_ALARM_HOUR] & 0x3f);
344 if (!(reg[M41T80_REG_ALARM_DAY] & 0x80))
345 t->time.tm_mday = bcd2bin(reg[M41T80_REG_ALARM_DAY] & 0x3f);
346 if (!(reg[M41T80_REG_ALARM_DAY] & 0x40))
347 t->time.tm_mon = bcd2bin(reg[M41T80_REG_ALARM_MON] & 0x1f) - 1;
348 t->time.tm_year = -1;
349 t->time.tm_wday = -1;
350 t->time.tm_yday = -1;
351 t->time.tm_isdst = -1;
352 t->enabled = !!(reg[M41T80_REG_ALARM_MON] & M41T80_ALMON_AFE);
353 t->pending = !!(reg[M41T80_REG_FLAGS] & M41T80_FLAGS_AF);
354 return 0;
355}
356
357static struct rtc_class_ops m41t80_rtc_ops = { 220static struct rtc_class_ops m41t80_rtc_ops = {
358 .read_time = m41t80_rtc_read_time, 221 .read_time = m41t80_rtc_read_time,
359 .set_time = m41t80_rtc_set_time, 222 .set_time = m41t80_rtc_set_time,
360 /*
361 * XXX - m41t80 alarm functionality is reported broken.
362 * until it is fixed, don't register alarm functions.
363 *
364 .read_alarm = m41t80_rtc_read_alarm,
365 .set_alarm = m41t80_rtc_set_alarm,
366 */
367 .proc = m41t80_rtc_proc, 223 .proc = m41t80_rtc_proc,
368 /*
369 * See above comment on broken alarm
370 *
371 .alarm_irq_enable = m41t80_rtc_alarm_irq_enable,
372 */
373}; 224};
374 225
375#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE) 226#if defined(CONFIG_RTC_INTF_SYSFS) || defined(CONFIG_RTC_INTF_SYSFS_MODULE)
diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
new file mode 100644
index 000000000000..e094ffa434f8
--- /dev/null
+++ b/drivers/rtc/rtc-max8907.c
@@ -0,0 +1,244 @@
1/*
2 * RTC driver for Maxim MAX8907
3 *
4 * Copyright (c) 2011-2012, NVIDIA Corporation.
5 *
6 * Based on drivers/rtc/rtc-max8925.c,
7 * Copyright (C) 2009-2010 Marvell International Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/bcd.h>
15#include <linux/i2c.h>
16#include <linux/mfd/max8907.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/regmap.h>
20#include <linux/rtc.h>
21#include <linux/slab.h>
22
23enum {
24 RTC_SEC = 0,
25 RTC_MIN,
26 RTC_HOUR,
27 RTC_WEEKDAY,
28 RTC_DATE,
29 RTC_MONTH,
30 RTC_YEAR1,
31 RTC_YEAR2,
32};
33
34#define TIME_NUM 8
35#define ALARM_1SEC (1 << 7)
36#define HOUR_12 (1 << 7)
37#define HOUR_AM_PM (1 << 5)
38#define ALARM0_IRQ (1 << 3)
39#define ALARM1_IRQ (1 << 2)
40#define ALARM0_STATUS (1 << 2)
41#define ALARM1_STATUS (1 << 1)
42
43struct max8907_rtc {
44 struct max8907 *max8907;
45 struct regmap *regmap;
46 struct rtc_device *rtc_dev;
47 int irq;
48};
49
50static irqreturn_t max8907_irq_handler(int irq, void *data)
51{
52 struct max8907_rtc *rtc = data;
53
54 regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0x7f, 0);
55
56 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
57
58 return IRQ_HANDLED;
59}
60
61static void regs_to_tm(u8 *regs, struct rtc_time *tm)
62{
63 tm->tm_year = bcd2bin(regs[RTC_YEAR2]) * 100 +
64 bcd2bin(regs[RTC_YEAR1]) - 1900;
65 tm->tm_mon = bcd2bin(regs[RTC_MONTH] & 0x1f) - 1;
66 tm->tm_mday = bcd2bin(regs[RTC_DATE] & 0x3f);
67 tm->tm_wday = (regs[RTC_WEEKDAY] & 0x07) - 1;
68 if (regs[RTC_HOUR] & HOUR_12) {
69 tm->tm_hour = bcd2bin(regs[RTC_HOUR] & 0x01f);
70 if (tm->tm_hour == 12)
71 tm->tm_hour = 0;
72 if (regs[RTC_HOUR] & HOUR_AM_PM)
73 tm->tm_hour += 12;
74 } else {
75 tm->tm_hour = bcd2bin(regs[RTC_HOUR] & 0x03f);
76 }
77 tm->tm_min = bcd2bin(regs[RTC_MIN] & 0x7f);
78 tm->tm_sec = bcd2bin(regs[RTC_SEC] & 0x7f);
79}
80
81static void tm_to_regs(struct rtc_time *tm, u8 *regs)
82{
83 u8 high, low;
84
85 high = (tm->tm_year + 1900) / 100;
86 low = tm->tm_year % 100;
87 regs[RTC_YEAR2] = bin2bcd(high);
88 regs[RTC_YEAR1] = bin2bcd(low);
89 regs[RTC_MONTH] = bin2bcd(tm->tm_mon + 1);
90 regs[RTC_DATE] = bin2bcd(tm->tm_mday);
91 regs[RTC_WEEKDAY] = tm->tm_wday + 1;
92 regs[RTC_HOUR] = bin2bcd(tm->tm_hour);
93 regs[RTC_MIN] = bin2bcd(tm->tm_min);
94 regs[RTC_SEC] = bin2bcd(tm->tm_sec);
95}
96
97static int max8907_rtc_read_time(struct device *dev, struct rtc_time *tm)
98{
99 struct max8907_rtc *rtc = dev_get_drvdata(dev);
100 u8 regs[TIME_NUM];
101 int ret;
102
103 ret = regmap_bulk_read(rtc->regmap, MAX8907_REG_RTC_SEC, regs,
104 TIME_NUM);
105 if (ret < 0)
106 return ret;
107
108 regs_to_tm(regs, tm);
109
110 return 0;
111}
112
113static int max8907_rtc_set_time(struct device *dev, struct rtc_time *tm)
114{
115 struct max8907_rtc *rtc = dev_get_drvdata(dev);
116 u8 regs[TIME_NUM];
117
118 tm_to_regs(tm, regs);
119
120 return regmap_bulk_write(rtc->regmap, MAX8907_REG_RTC_SEC, regs,
121 TIME_NUM);
122}
123
124static int max8907_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
125{
126 struct max8907_rtc *rtc = dev_get_drvdata(dev);
127 u8 regs[TIME_NUM];
128 unsigned int val;
129 int ret;
130
131 ret = regmap_bulk_read(rtc->regmap, MAX8907_REG_ALARM0_SEC, regs,
132 TIME_NUM);
133 if (ret < 0)
134 return ret;
135
136 regs_to_tm(regs, &alrm->time);
137
138 ret = regmap_read(rtc->regmap, MAX8907_REG_ALARM0_CNTL, &val);
139 if (ret < 0)
140 return ret;
141
142 alrm->enabled = !!(val & 0x7f);
143
144 return 0;
145}
146
147static int max8907_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
148{
149 struct max8907_rtc *rtc = dev_get_drvdata(dev);
150 u8 regs[TIME_NUM];
151 int ret;
152
153 tm_to_regs(&alrm->time, regs);
154
155 /* Disable alarm while we update the target time */
156 ret = regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL, 0x7f, 0);
157 if (ret < 0)
158 return ret;
159
160 ret = regmap_bulk_write(rtc->regmap, MAX8907_REG_ALARM0_SEC, regs,
161 TIME_NUM);
162 if (ret < 0)
163 return ret;
164
165 if (alrm->enabled)
166 ret = regmap_update_bits(rtc->regmap, MAX8907_REG_ALARM0_CNTL,
167 0x7f, 0x7f);
168
169 return ret;
170}
171
172static const struct rtc_class_ops max8907_rtc_ops = {
173 .read_time = max8907_rtc_read_time,
174 .set_time = max8907_rtc_set_time,
175 .read_alarm = max8907_rtc_read_alarm,
176 .set_alarm = max8907_rtc_set_alarm,
177};
178
179static int __devinit max8907_rtc_probe(struct platform_device *pdev)
180{
181 struct max8907 *max8907 = dev_get_drvdata(pdev->dev.parent);
182 struct max8907_rtc *rtc;
183 int ret;
184
185 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
186 if (!rtc)
187 return -ENOMEM;
188 platform_set_drvdata(pdev, rtc);
189
190 rtc->max8907 = max8907;
191 rtc->regmap = max8907->regmap_rtc;
192
193 rtc->rtc_dev = rtc_device_register("max8907-rtc", &pdev->dev,
194 &max8907_rtc_ops, THIS_MODULE);
195 if (IS_ERR(rtc->rtc_dev)) {
196 ret = PTR_ERR(rtc->rtc_dev);
197 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
198 return ret;
199 }
200
201 rtc->irq = regmap_irq_get_virq(max8907->irqc_rtc,
202 MAX8907_IRQ_RTC_ALARM0);
203 if (rtc->irq < 0) {
204 ret = rtc->irq;
205 goto err_unregister;
206 }
207
208 ret = request_threaded_irq(rtc->irq, NULL, max8907_irq_handler,
209 IRQF_ONESHOT, "max8907-alarm0", rtc);
210 if (ret < 0) {
211 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n",
212 rtc->irq, ret);
213 goto err_unregister;
214 }
215
216 return 0;
217
218err_unregister:
219 rtc_device_unregister(rtc->rtc_dev);
220 return ret;
221}
222
223static int __devexit max8907_rtc_remove(struct platform_device *pdev)
224{
225 struct max8907_rtc *rtc = platform_get_drvdata(pdev);
226
227 free_irq(rtc->irq, rtc);
228 rtc_device_unregister(rtc->rtc_dev);
229
230 return 0;
231}
232
233static struct platform_driver max8907_rtc_driver = {
234 .driver = {
235 .name = "max8907-rtc",
236 .owner = THIS_MODULE,
237 },
238 .probe = max8907_rtc_probe,
239 .remove = __devexit_p(max8907_rtc_remove),
240};
241module_platform_driver(max8907_rtc_driver);
242
243MODULE_DESCRIPTION("Maxim MAX8907 RTC driver");
244MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index e3e50d69baf8..cd0106293a49 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -343,7 +343,7 @@ static struct rtc_class_ops mxc_rtc_ops = {
343 .alarm_irq_enable = mxc_rtc_alarm_irq_enable, 343 .alarm_irq_enable = mxc_rtc_alarm_irq_enable,
344}; 344};
345 345
346static int __init mxc_rtc_probe(struct platform_device *pdev) 346static int __devinit mxc_rtc_probe(struct platform_device *pdev)
347{ 347{
348 struct resource *res; 348 struct resource *res;
349 struct rtc_device *rtc; 349 struct rtc_device *rtc;
@@ -367,14 +367,14 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
367 pdata->ioaddr = devm_ioremap(&pdev->dev, res->start, 367 pdata->ioaddr = devm_ioremap(&pdev->dev, res->start,
368 resource_size(res)); 368 resource_size(res));
369 369
370 pdata->clk = clk_get(&pdev->dev, "rtc"); 370 pdata->clk = devm_clk_get(&pdev->dev, NULL);
371 if (IS_ERR(pdata->clk)) { 371 if (IS_ERR(pdata->clk)) {
372 dev_err(&pdev->dev, "unable to get clock!\n"); 372 dev_err(&pdev->dev, "unable to get clock!\n");
373 ret = PTR_ERR(pdata->clk); 373 ret = PTR_ERR(pdata->clk);
374 goto exit_free_pdata; 374 goto exit_free_pdata;
375 } 375 }
376 376
377 clk_enable(pdata->clk); 377 clk_prepare_enable(pdata->clk);
378 rate = clk_get_rate(pdata->clk); 378 rate = clk_get_rate(pdata->clk);
379 379
380 if (rate == 32768) 380 if (rate == 32768)
@@ -426,22 +426,20 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
426exit_clr_drvdata: 426exit_clr_drvdata:
427 platform_set_drvdata(pdev, NULL); 427 platform_set_drvdata(pdev, NULL);
428exit_put_clk: 428exit_put_clk:
429 clk_disable(pdata->clk); 429 clk_disable_unprepare(pdata->clk);
430 clk_put(pdata->clk);
431 430
432exit_free_pdata: 431exit_free_pdata:
433 432
434 return ret; 433 return ret;
435} 434}
436 435
437static int __exit mxc_rtc_remove(struct platform_device *pdev) 436static int __devexit mxc_rtc_remove(struct platform_device *pdev)
438{ 437{
439 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 438 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
440 439
441 rtc_device_unregister(pdata->rtc); 440 rtc_device_unregister(pdata->rtc);
442 441
443 clk_disable(pdata->clk); 442 clk_disable_unprepare(pdata->clk);
444 clk_put(pdata->clk);
445 platform_set_drvdata(pdev, NULL); 443 platform_set_drvdata(pdev, NULL);
446 444
447 return 0; 445 return 0;
@@ -482,21 +480,11 @@ static struct platform_driver mxc_rtc_driver = {
482#endif 480#endif
483 .owner = THIS_MODULE, 481 .owner = THIS_MODULE,
484 }, 482 },
485 .remove = __exit_p(mxc_rtc_remove), 483 .probe = mxc_rtc_probe,
484 .remove = __devexit_p(mxc_rtc_remove),
486}; 485};
487 486
488static int __init mxc_rtc_init(void) 487module_platform_driver(mxc_rtc_driver)
489{
490 return platform_driver_probe(&mxc_rtc_driver, mxc_rtc_probe);
491}
492
493static void __exit mxc_rtc_exit(void)
494{
495 platform_driver_unregister(&mxc_rtc_driver);
496}
497
498module_init(mxc_rtc_init);
499module_exit(mxc_rtc_exit);
500 488
501MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 489MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
502MODULE_DESCRIPTION("RTC driver for Freescale MXC"); 490MODULE_DESCRIPTION("RTC driver for Freescale MXC");
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index c2fe426a6ef2..98e3a2b681e6 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -78,8 +78,17 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
78 unsigned char buf[13] = { PCF8563_REG_ST1 }; 78 unsigned char buf[13] = { PCF8563_REG_ST1 };
79 79
80 struct i2c_msg msgs[] = { 80 struct i2c_msg msgs[] = {
81 { client->addr, 0, 1, buf }, /* setup read ptr */ 81 {/* setup read ptr */
82 { client->addr, I2C_M_RD, 13, buf }, /* read status + date */ 82 .addr = client->addr,
83 .len = 1,
84 .buf = buf
85 },
86 {/* read status + date */
87 .addr = client->addr,
88 .flags = I2C_M_RD,
89 .len = 13,
90 .buf = buf
91 },
83 }; 92 };
84 93
85 /* read registers */ 94 /* read registers */
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index 0a59fda5c09d..e96236ac2e78 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -18,6 +18,26 @@
18 18
19#include "rtc-core.h" 19#include "rtc-core.h"
20 20
21#define NAME_SIZE 10
22
23#if defined(CONFIG_RTC_HCTOSYS_DEVICE)
24static bool is_rtc_hctosys(struct rtc_device *rtc)
25{
26 int size;
27 char name[NAME_SIZE];
28
29 size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id);
30 if (size > NAME_SIZE)
31 return false;
32
33 return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
34}
35#else
36static bool is_rtc_hctosys(struct rtc_device *rtc)
37{
38 return (rtc->id == 0);
39}
40#endif
21 41
22static int rtc_proc_show(struct seq_file *seq, void *offset) 42static int rtc_proc_show(struct seq_file *seq, void *offset)
23{ 43{
@@ -117,12 +137,12 @@ static const struct file_operations rtc_proc_fops = {
117 137
118void rtc_proc_add_device(struct rtc_device *rtc) 138void rtc_proc_add_device(struct rtc_device *rtc)
119{ 139{
120 if (rtc->id == 0) 140 if (is_rtc_hctosys(rtc))
121 proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc); 141 proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
122} 142}
123 143
124void rtc_proc_del_device(struct rtc_device *rtc) 144void rtc_proc_del_device(struct rtc_device *rtc)
125{ 145{
126 if (rtc->id == 0) 146 if (is_rtc_hctosys(rtc))
127 remove_proc_entry("driver/rtc", NULL); 147 remove_proc_entry("driver/rtc", NULL);
128} 148}
diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c
new file mode 100644
index 000000000000..cdb140c29c56
--- /dev/null
+++ b/drivers/rtc/rtc-rc5t583.c
@@ -0,0 +1,331 @@
1/*
2 * rtc-rc5t583.c -- RICOH RC5T583 Real Time Clock
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5 * Author: Venu Byravarasu <vbyravarasu@nvidia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/rtc.h>
25#include <linux/bcd.h>
26#include <linux/platform_device.h>
27#include <linux/interrupt.h>
28#include <linux/mfd/rc5t583.h>
29
30struct rc5t583_rtc {
31 struct rtc_device *rtc;
32 /* To store the list of enabled interrupts, during system suspend */
33 u32 irqen;
34};
35
36/* Total number of RTC registers needed to set time*/
37#define NUM_TIME_REGS (RC5T583_RTC_YEAR - RC5T583_RTC_SEC + 1)
38
39/* Total number of RTC registers needed to set Y-Alarm*/
40#define NUM_YAL_REGS (RC5T583_RTC_AY_YEAR - RC5T583_RTC_AY_MIN + 1)
41
42/* Set Y-Alarm interrupt */
43#define SET_YAL BIT(5)
44
45/* Get Y-Alarm interrupt status*/
46#define GET_YAL_STATUS BIT(3)
47
48static int rc5t583_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
49{
50 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
51 u8 val;
52
53 /* Set Y-Alarm, based on 'enabled' */
54 val = enabled ? SET_YAL : 0;
55
56 return regmap_update_bits(rc5t583->regmap, RC5T583_RTC_CTL1, SET_YAL,
57 val);
58}
59
60/*
61 * Gets current rc5t583 RTC time and date parameters.
62 *
63 * The RTC's time/alarm representation is not what gmtime(3) requires
64 * Linux to use:
65 *
66 * - Months are 1..12 vs Linux 0-11
67 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
68 */
69static int rc5t583_rtc_read_time(struct device *dev, struct rtc_time *tm)
70{
71 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
72 u8 rtc_data[NUM_TIME_REGS];
73 int ret;
74
75 ret = regmap_bulk_read(rc5t583->regmap, RC5T583_RTC_SEC, rtc_data,
76 NUM_TIME_REGS);
77 if (ret < 0) {
78 dev_err(dev, "RTC read time failed with err:%d\n", ret);
79 return ret;
80 }
81
82 tm->tm_sec = bcd2bin(rtc_data[0]);
83 tm->tm_min = bcd2bin(rtc_data[1]);
84 tm->tm_hour = bcd2bin(rtc_data[2]);
85 tm->tm_wday = bcd2bin(rtc_data[3]);
86 tm->tm_mday = bcd2bin(rtc_data[4]);
87 tm->tm_mon = bcd2bin(rtc_data[5]) - 1;
88 tm->tm_year = bcd2bin(rtc_data[6]) + 100;
89
90 return ret;
91}
92
93static int rc5t583_rtc_set_time(struct device *dev, struct rtc_time *tm)
94{
95 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
96 unsigned char rtc_data[NUM_TIME_REGS];
97 int ret;
98
99 rtc_data[0] = bin2bcd(tm->tm_sec);
100 rtc_data[1] = bin2bcd(tm->tm_min);
101 rtc_data[2] = bin2bcd(tm->tm_hour);
102 rtc_data[3] = bin2bcd(tm->tm_wday);
103 rtc_data[4] = bin2bcd(tm->tm_mday);
104 rtc_data[5] = bin2bcd(tm->tm_mon + 1);
105 rtc_data[6] = bin2bcd(tm->tm_year - 100);
106
107 ret = regmap_bulk_write(rc5t583->regmap, RC5T583_RTC_SEC, rtc_data,
108 NUM_TIME_REGS);
109 if (ret < 0) {
110 dev_err(dev, "RTC set time failed with error %d\n", ret);
111 return ret;
112 }
113
114 return ret;
115}
116
117static int rc5t583_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
118{
119 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
120 unsigned char alarm_data[NUM_YAL_REGS];
121 u32 interrupt_enable;
122 int ret;
123
124 ret = regmap_bulk_read(rc5t583->regmap, RC5T583_RTC_AY_MIN, alarm_data,
125 NUM_YAL_REGS);
126 if (ret < 0) {
127 dev_err(dev, "rtc_read_alarm error %d\n", ret);
128 return ret;
129 }
130
131 alm->time.tm_min = bcd2bin(alarm_data[0]);
132 alm->time.tm_hour = bcd2bin(alarm_data[1]);
133 alm->time.tm_mday = bcd2bin(alarm_data[2]);
134 alm->time.tm_mon = bcd2bin(alarm_data[3]) - 1;
135 alm->time.tm_year = bcd2bin(alarm_data[4]) + 100;
136
137 ret = regmap_read(rc5t583->regmap, RC5T583_RTC_CTL1, &interrupt_enable);
138 if (ret < 0)
139 return ret;
140
141 /* check if YALE is set */
142 if (interrupt_enable & SET_YAL)
143 alm->enabled = 1;
144
145 return ret;
146}
147
148static int rc5t583_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
149{
150 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
151 unsigned char alarm_data[NUM_YAL_REGS];
152 int ret;
153
154 ret = rc5t583_rtc_alarm_irq_enable(dev, 0);
155 if (ret)
156 return ret;
157
158 alarm_data[0] = bin2bcd(alm->time.tm_min);
159 alarm_data[1] = bin2bcd(alm->time.tm_hour);
160 alarm_data[2] = bin2bcd(alm->time.tm_mday);
161 alarm_data[3] = bin2bcd(alm->time.tm_mon + 1);
162 alarm_data[4] = bin2bcd(alm->time.tm_year - 100);
163
164 ret = regmap_bulk_write(rc5t583->regmap, RC5T583_RTC_AY_MIN, alarm_data,
165 NUM_YAL_REGS);
166 if (ret) {
167 dev_err(dev, "rtc_set_alarm error %d\n", ret);
168 return ret;
169 }
170
171 if (alm->enabled)
172 ret = rc5t583_rtc_alarm_irq_enable(dev, 1);
173
174 return ret;
175}
176
177static irqreturn_t rc5t583_rtc_interrupt(int irq, void *rtc)
178{
179 struct device *dev = rtc;
180 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
181 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(dev);
182 unsigned long events = 0;
183 int ret;
184 u32 rtc_reg;
185
186 ret = regmap_read(rc5t583->regmap, RC5T583_RTC_CTL2, &rtc_reg);
187 if (ret < 0)
188 return IRQ_NONE;
189
190 if (rtc_reg & GET_YAL_STATUS) {
191 events = RTC_IRQF | RTC_AF;
192 /* clear pending Y-alarm interrupt bit */
193 rtc_reg &= ~GET_YAL_STATUS;
194 }
195
196 ret = regmap_write(rc5t583->regmap, RC5T583_RTC_CTL2, rtc_reg);
197 if (ret)
198 return IRQ_NONE;
199
200 /* Notify RTC core on event */
201 rtc_update_irq(rc5t583_rtc->rtc, 1, events);
202
203 return IRQ_HANDLED;
204}
205
206static const struct rtc_class_ops rc5t583_rtc_ops = {
207 .read_time = rc5t583_rtc_read_time,
208 .set_time = rc5t583_rtc_set_time,
209 .read_alarm = rc5t583_rtc_read_alarm,
210 .set_alarm = rc5t583_rtc_set_alarm,
211 .alarm_irq_enable = rc5t583_rtc_alarm_irq_enable,
212};
213
214static int __devinit rc5t583_rtc_probe(struct platform_device *pdev)
215{
216 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
217 struct rc5t583_rtc *ricoh_rtc;
218 struct rc5t583_platform_data *pmic_plat_data;
219 int ret;
220 int irq;
221
222 ricoh_rtc = devm_kzalloc(&pdev->dev, sizeof(struct rc5t583_rtc),
223 GFP_KERNEL);
224 if (!ricoh_rtc)
225 return -ENOMEM;
226
227 platform_set_drvdata(pdev, ricoh_rtc);
228
229 /* Clear pending interrupts */
230 ret = regmap_write(rc5t583->regmap, RC5T583_RTC_CTL2, 0);
231 if (ret < 0)
232 return ret;
233
234 /* clear RTC Adjust register */
235 ret = regmap_write(rc5t583->regmap, RC5T583_RTC_ADJ, 0);
236 if (ret < 0) {
237 dev_err(&pdev->dev, "unable to program rtc_adjust reg\n");
238 return -EBUSY;
239 }
240
241 pmic_plat_data = dev_get_platdata(rc5t583->dev);
242 irq = pmic_plat_data->irq_base;
243 if (irq <= 0) {
244 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n",
245 irq);
246 return ret;
247 }
248
249 irq += RC5T583_IRQ_YALE;
250 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
251 rc5t583_rtc_interrupt, IRQF_TRIGGER_LOW,
252 "rtc-rc5t583", &pdev->dev);
253 if (ret < 0) {
254 dev_err(&pdev->dev, "IRQ is not free.\n");
255 return ret;
256 }
257 device_init_wakeup(&pdev->dev, 1);
258
259 ricoh_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
260 &rc5t583_rtc_ops, THIS_MODULE);
261 if (IS_ERR(ricoh_rtc->rtc)) {
262 ret = PTR_ERR(ricoh_rtc->rtc);
263 dev_err(&pdev->dev, "RTC device register: err %d\n", ret);
264 return ret;
265 }
266
267 return 0;
268}
269
270/*
271 * Disable rc5t583 RTC interrupts.
272 * Sets status flag to free.
273 */
274static int __devexit rc5t583_rtc_remove(struct platform_device *pdev)
275{
276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev);
277
278 rc5t583_rtc_alarm_irq_enable(&rc5t583_rtc->rtc->dev, 0);
279
280 rtc_device_unregister(rc5t583_rtc->rtc);
281 return 0;
282}
283
284#ifdef CONFIG_PM_SLEEP
285
286static int rc5t583_rtc_suspend(struct device *dev)
287{
288 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
289 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(dev);
290 int ret;
291
292 /* Store current list of enabled interrupts*/
293 ret = regmap_read(rc5t583->regmap, RC5T583_RTC_CTL1,
294 &rc5t583_rtc->irqen);
295 return ret;
296}
297
298static int rc5t583_rtc_resume(struct device *dev)
299{
300 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
301 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(dev);
302
303 /* Restore list of enabled interrupts before suspend */
304 return regmap_write(rc5t583->regmap, RC5T583_RTC_CTL1,
305 rc5t583_rtc->irqen);
306}
307
308static const struct dev_pm_ops rc5t583_rtc_pm_ops = {
309 .suspend = rc5t583_rtc_suspend,
310 .resume = rc5t583_rtc_resume,
311};
312
313#define DEV_PM_OPS (&rc5t583_rtc_pm_ops)
314#else
315#define DEV_PM_OPS NULL
316#endif
317
318static struct platform_driver rc5t583_rtc_driver = {
319 .probe = rc5t583_rtc_probe,
320 .remove = __devexit_p(rc5t583_rtc_remove),
321 .driver = {
322 .owner = THIS_MODULE,
323 .name = "rtc-rc5t583",
324 .pm = DEV_PM_OPS,
325 },
326};
327
328module_platform_driver(rc5t583_rtc_driver);
329MODULE_ALIAS("platform:rtc-rc5t583");
330MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
331MODULE_LICENSE("GPL v2");
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index fb4842c3544e..76f565ae384d 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -104,7 +104,12 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
104{ 104{
105 struct i2c_client *client = rs5c->client; 105 struct i2c_client *client = rs5c->client;
106 struct i2c_msg msgs[] = { 106 struct i2c_msg msgs[] = {
107 { client->addr, I2C_M_RD, sizeof rs5c->buf, rs5c->buf }, 107 {
108 .addr = client->addr,
109 .flags = I2C_M_RD,
110 .len = sizeof(rs5c->buf),
111 .buf = rs5c->buf
112 },
108 }; 113 };
109 114
110 /* This implements the third reading method from the datasheet, using 115 /* This implements the third reading method from the datasheet, using
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index c9562ceedef3..8a092325188d 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -19,6 +19,8 @@
19#define S35390A_CMD_STATUS1 0 19#define S35390A_CMD_STATUS1 0
20#define S35390A_CMD_STATUS2 1 20#define S35390A_CMD_STATUS2 1
21#define S35390A_CMD_TIME1 2 21#define S35390A_CMD_TIME1 2
22#define S35390A_CMD_TIME2 3
23#define S35390A_CMD_INT2_REG1 5
22 24
23#define S35390A_BYTE_YEAR 0 25#define S35390A_BYTE_YEAR 0
24#define S35390A_BYTE_MONTH 1 26#define S35390A_BYTE_MONTH 1
@@ -28,12 +30,23 @@
28#define S35390A_BYTE_MINS 5 30#define S35390A_BYTE_MINS 5
29#define S35390A_BYTE_SECS 6 31#define S35390A_BYTE_SECS 6
30 32
33#define S35390A_ALRM_BYTE_WDAY 0
34#define S35390A_ALRM_BYTE_HOURS 1
35#define S35390A_ALRM_BYTE_MINS 2
36
31#define S35390A_FLAG_POC 0x01 37#define S35390A_FLAG_POC 0x01
32#define S35390A_FLAG_BLD 0x02 38#define S35390A_FLAG_BLD 0x02
33#define S35390A_FLAG_24H 0x40 39#define S35390A_FLAG_24H 0x40
34#define S35390A_FLAG_RESET 0x80 40#define S35390A_FLAG_RESET 0x80
35#define S35390A_FLAG_TEST 0x01 41#define S35390A_FLAG_TEST 0x01
36 42
43#define S35390A_INT2_MODE_MASK 0xF0
44
45#define S35390A_INT2_MODE_NOINTR 0x00
46#define S35390A_INT2_MODE_FREQ 0x10
47#define S35390A_INT2_MODE_ALARM 0x40
48#define S35390A_INT2_MODE_PMIN_EDG 0x20
49
37static const struct i2c_device_id s35390a_id[] = { 50static const struct i2c_device_id s35390a_id[] = {
38 { "s35390a", 0 }, 51 { "s35390a", 0 },
39 { } 52 { }
@@ -50,7 +63,11 @@ static int s35390a_set_reg(struct s35390a *s35390a, int reg, char *buf, int len)
50{ 63{
51 struct i2c_client *client = s35390a->client[reg]; 64 struct i2c_client *client = s35390a->client[reg];
52 struct i2c_msg msg[] = { 65 struct i2c_msg msg[] = {
53 { client->addr, 0, len, buf }, 66 {
67 .addr = client->addr,
68 .len = len,
69 .buf = buf
70 },
54 }; 71 };
55 72
56 if ((i2c_transfer(client->adapter, msg, 1)) != 1) 73 if ((i2c_transfer(client->adapter, msg, 1)) != 1)
@@ -63,7 +80,12 @@ static int s35390a_get_reg(struct s35390a *s35390a, int reg, char *buf, int len)
63{ 80{
64 struct i2c_client *client = s35390a->client[reg]; 81 struct i2c_client *client = s35390a->client[reg];
65 struct i2c_msg msg[] = { 82 struct i2c_msg msg[] = {
66 { client->addr, I2C_M_RD, len, buf }, 83 {
84 .addr = client->addr,
85 .flags = I2C_M_RD,
86 .len = len,
87 .buf = buf
88 },
67 }; 89 };
68 90
69 if ((i2c_transfer(client->adapter, msg, 1)) != 1) 91 if ((i2c_transfer(client->adapter, msg, 1)) != 1)
@@ -184,6 +206,104 @@ static int s35390a_get_datetime(struct i2c_client *client, struct rtc_time *tm)
184 return rtc_valid_tm(tm); 206 return rtc_valid_tm(tm);
185} 207}
186 208
209static int s35390a_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alm)
210{
211 struct s35390a *s35390a = i2c_get_clientdata(client);
212 char buf[3], sts = 0;
213 int err, i;
214
215 dev_dbg(&client->dev, "%s: alm is secs=%d, mins=%d, hours=%d mday=%d, "\
216 "mon=%d, year=%d, wday=%d\n", __func__, alm->time.tm_sec,
217 alm->time.tm_min, alm->time.tm_hour, alm->time.tm_mday,
218 alm->time.tm_mon, alm->time.tm_year, alm->time.tm_wday);
219
220 /* disable interrupt */
221 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts));
222 if (err < 0)
223 return err;
224
225 /* clear pending interrupt, if any */
226 err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, &sts, sizeof(sts));
227 if (err < 0)
228 return err;
229
230 if (alm->enabled)
231 sts = S35390A_INT2_MODE_ALARM;
232 else
233 sts = S35390A_INT2_MODE_NOINTR;
234
235 /* This chip expects the bits of each byte to be in reverse order */
236 sts = bitrev8(sts);
237
238 /* set interupt mode*/
239 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts));
240 if (err < 0)
241 return err;
242
243 if (alm->time.tm_wday != -1)
244 buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm->time.tm_wday) | 0x80;
245
246 buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a,
247 alm->time.tm_hour) | 0x80;
248 buf[S35390A_ALRM_BYTE_MINS] = bin2bcd(alm->time.tm_min) | 0x80;
249
250 if (alm->time.tm_hour >= 12)
251 buf[S35390A_ALRM_BYTE_HOURS] |= 0x40;
252
253 for (i = 0; i < 3; ++i)
254 buf[i] = bitrev8(buf[i]);
255
256 err = s35390a_set_reg(s35390a, S35390A_CMD_INT2_REG1, buf,
257 sizeof(buf));
258
259 return err;
260}
261
262static int s35390a_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alm)
263{
264 struct s35390a *s35390a = i2c_get_clientdata(client);
265 char buf[3], sts;
266 int i, err;
267
268 err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts));
269 if (err < 0)
270 return err;
271
272 if (bitrev8(sts) != S35390A_INT2_MODE_ALARM)
273 return -EINVAL;
274
275 err = s35390a_get_reg(s35390a, S35390A_CMD_INT2_REG1, buf, sizeof(buf));
276 if (err < 0)
277 return err;
278
279 /* This chip returns the bits of each byte in reverse order */
280 for (i = 0; i < 3; ++i) {
281 buf[i] = bitrev8(buf[i]);
282 buf[i] &= ~0x80;
283 }
284
285 alm->time.tm_wday = bcd2bin(buf[S35390A_ALRM_BYTE_WDAY]);
286 alm->time.tm_hour = s35390a_reg2hr(s35390a,
287 buf[S35390A_ALRM_BYTE_HOURS]);
288 alm->time.tm_min = bcd2bin(buf[S35390A_ALRM_BYTE_MINS]);
289
290 dev_dbg(&client->dev, "%s: alm is mins=%d, hours=%d, wday=%d\n",
291 __func__, alm->time.tm_min, alm->time.tm_hour,
292 alm->time.tm_wday);
293
294 return 0;
295}
296
297static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
298{
299 return s35390a_read_alarm(to_i2c_client(dev), alm);
300}
301
302static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
303{
304 return s35390a_set_alarm(to_i2c_client(dev), alm);
305}
306
187static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm) 307static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm)
188{ 308{
189 return s35390a_get_datetime(to_i2c_client(dev), tm); 309 return s35390a_get_datetime(to_i2c_client(dev), tm);
@@ -197,6 +317,9 @@ static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm)
197static const struct rtc_class_ops s35390a_rtc_ops = { 317static const struct rtc_class_ops s35390a_rtc_ops = {
198 .read_time = s35390a_rtc_read_time, 318 .read_time = s35390a_rtc_read_time,
199 .set_time = s35390a_rtc_set_time, 319 .set_time = s35390a_rtc_set_time,
320 .set_alarm = s35390a_rtc_set_alarm,
321 .read_alarm = s35390a_rtc_read_alarm,
322
200}; 323};
201 324
202static struct i2c_driver s35390a_driver; 325static struct i2c_driver s35390a_driver;
@@ -261,6 +384,8 @@ static int s35390a_probe(struct i2c_client *client,
261 if (s35390a_get_datetime(client, &tm) < 0) 384 if (s35390a_get_datetime(client, &tm) < 0)
262 dev_warn(&client->dev, "clock needs to be set\n"); 385 dev_warn(&client->dev, "clock needs to be set\n");
263 386
387 device_set_wakeup_capable(&client->dev, 1);
388
264 s35390a->rtc = rtc_device_register(s35390a_driver.driver.name, 389 s35390a->rtc = rtc_device_register(s35390a_driver.driver.name,
265 &client->dev, &s35390a_rtc_ops, THIS_MODULE); 390 &client->dev, &s35390a_rtc_ops, THIS_MODULE);
266 391
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index bfbd92c8d1c9..77823d21d314 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -476,13 +476,13 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
476 s3c_rtc_tickno = platform_get_irq(pdev, 1); 476 s3c_rtc_tickno = platform_get_irq(pdev, 1);
477 if (s3c_rtc_tickno < 0) { 477 if (s3c_rtc_tickno < 0) {
478 dev_err(&pdev->dev, "no irq for rtc tick\n"); 478 dev_err(&pdev->dev, "no irq for rtc tick\n");
479 return -ENOENT; 479 return s3c_rtc_tickno;
480 } 480 }
481 481
482 s3c_rtc_alarmno = platform_get_irq(pdev, 0); 482 s3c_rtc_alarmno = platform_get_irq(pdev, 0);
483 if (s3c_rtc_alarmno < 0) { 483 if (s3c_rtc_alarmno < 0) {
484 dev_err(&pdev->dev, "no irq for alarm\n"); 484 dev_err(&pdev->dev, "no irq for alarm\n");
485 return -ENOENT; 485 return s3c_rtc_alarmno;
486 } 486 }
487 487
488 pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n", 488 pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
new file mode 100644
index 000000000000..3c0da333f465
--- /dev/null
+++ b/drivers/rtc/rtc-snvs.c
@@ -0,0 +1,350 @@
1/*
2 * Copyright (C) 2011-2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/init.h>
13#include <linux/io.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/of.h>
17#include <linux/of_device.h>
18#include <linux/platform_device.h>
19#include <linux/rtc.h>
20
21/* These register offsets are relative to LP (Low Power) range */
22#define SNVS_LPCR 0x04
23#define SNVS_LPSR 0x18
24#define SNVS_LPSRTCMR 0x1c
25#define SNVS_LPSRTCLR 0x20
26#define SNVS_LPTAR 0x24
27#define SNVS_LPPGDR 0x30
28
29#define SNVS_LPCR_SRTC_ENV (1 << 0)
30#define SNVS_LPCR_LPTA_EN (1 << 1)
31#define SNVS_LPCR_LPWUI_EN (1 << 3)
32#define SNVS_LPSR_LPTA (1 << 0)
33
34#define SNVS_LPPGDR_INIT 0x41736166
35#define CNTR_TO_SECS_SH 15
36
37struct snvs_rtc_data {
38 struct rtc_device *rtc;
39 void __iomem *ioaddr;
40 int irq;
41 spinlock_t lock;
42};
43
44static u32 rtc_read_lp_counter(void __iomem *ioaddr)
45{
46 u64 read1, read2;
47
48 do {
49 read1 = readl(ioaddr + SNVS_LPSRTCMR);
50 read1 <<= 32;
51 read1 |= readl(ioaddr + SNVS_LPSRTCLR);
52
53 read2 = readl(ioaddr + SNVS_LPSRTCMR);
54 read2 <<= 32;
55 read2 |= readl(ioaddr + SNVS_LPSRTCLR);
56 } while (read1 != read2);
57
58 /* Convert 47-bit counter to 32-bit raw second count */
59 return (u32) (read1 >> CNTR_TO_SECS_SH);
60}
61
62static void rtc_write_sync_lp(void __iomem *ioaddr)
63{
64 u32 count1, count2, count3;
65 int i;
66
67 /* Wait for 3 CKIL cycles */
68 for (i = 0; i < 3; i++) {
69 do {
70 count1 = readl(ioaddr + SNVS_LPSRTCLR);
71 count2 = readl(ioaddr + SNVS_LPSRTCLR);
72 } while (count1 != count2);
73
74 /* Now wait until counter value changes */
75 do {
76 do {
77 count2 = readl(ioaddr + SNVS_LPSRTCLR);
78 count3 = readl(ioaddr + SNVS_LPSRTCLR);
79 } while (count2 != count3);
80 } while (count3 == count1);
81 }
82}
83
84static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
85{
86 unsigned long flags;
87 int timeout = 1000;
88 u32 lpcr;
89
90 spin_lock_irqsave(&data->lock, flags);
91
92 lpcr = readl(data->ioaddr + SNVS_LPCR);
93 if (enable)
94 lpcr |= SNVS_LPCR_SRTC_ENV;
95 else
96 lpcr &= ~SNVS_LPCR_SRTC_ENV;
97 writel(lpcr, data->ioaddr + SNVS_LPCR);
98
99 spin_unlock_irqrestore(&data->lock, flags);
100
101 while (--timeout) {
102 lpcr = readl(data->ioaddr + SNVS_LPCR);
103
104 if (enable) {
105 if (lpcr & SNVS_LPCR_SRTC_ENV)
106 break;
107 } else {
108 if (!(lpcr & SNVS_LPCR_SRTC_ENV))
109 break;
110 }
111 }
112
113 if (!timeout)
114 return -ETIMEDOUT;
115
116 return 0;
117}
118
119static int snvs_rtc_read_time(struct device *dev, struct rtc_time *tm)
120{
121 struct snvs_rtc_data *data = dev_get_drvdata(dev);
122 unsigned long time = rtc_read_lp_counter(data->ioaddr);
123
124 rtc_time_to_tm(time, tm);
125
126 return 0;
127}
128
129static int snvs_rtc_set_time(struct device *dev, struct rtc_time *tm)
130{
131 struct snvs_rtc_data *data = dev_get_drvdata(dev);
132 unsigned long time;
133
134 rtc_tm_to_time(tm, &time);
135
136 /* Disable RTC first */
137 snvs_rtc_enable(data, false);
138
139 /* Write 32-bit time to 47-bit timer, leaving 15 LSBs blank */
140 writel(time << CNTR_TO_SECS_SH, data->ioaddr + SNVS_LPSRTCLR);
141 writel(time >> (32 - CNTR_TO_SECS_SH), data->ioaddr + SNVS_LPSRTCMR);
142
143 /* Enable RTC again */
144 snvs_rtc_enable(data, true);
145
146 return 0;
147}
148
149static int snvs_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
150{
151 struct snvs_rtc_data *data = dev_get_drvdata(dev);
152 u32 lptar, lpsr;
153
154 lptar = readl(data->ioaddr + SNVS_LPTAR);
155 rtc_time_to_tm(lptar, &alrm->time);
156
157 lpsr = readl(data->ioaddr + SNVS_LPSR);
158 alrm->pending = (lpsr & SNVS_LPSR_LPTA) ? 1 : 0;
159
160 return 0;
161}
162
163static int snvs_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
164{
165 struct snvs_rtc_data *data = dev_get_drvdata(dev);
166 u32 lpcr;
167 unsigned long flags;
168
169 spin_lock_irqsave(&data->lock, flags);
170
171 lpcr = readl(data->ioaddr + SNVS_LPCR);
172 if (enable)
173 lpcr |= (SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN);
174 else
175 lpcr &= ~(SNVS_LPCR_LPTA_EN | SNVS_LPCR_LPWUI_EN);
176 writel(lpcr, data->ioaddr + SNVS_LPCR);
177
178 spin_unlock_irqrestore(&data->lock, flags);
179
180 rtc_write_sync_lp(data->ioaddr);
181
182 return 0;
183}
184
185static int snvs_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
186{
187 struct snvs_rtc_data *data = dev_get_drvdata(dev);
188 struct rtc_time *alrm_tm = &alrm->time;
189 unsigned long time;
190 unsigned long flags;
191 u32 lpcr;
192
193 rtc_tm_to_time(alrm_tm, &time);
194
195 spin_lock_irqsave(&data->lock, flags);
196
197 /* Have to clear LPTA_EN before programming new alarm time in LPTAR */
198 lpcr = readl(data->ioaddr + SNVS_LPCR);
199 lpcr &= ~SNVS_LPCR_LPTA_EN;
200 writel(lpcr, data->ioaddr + SNVS_LPCR);
201
202 spin_unlock_irqrestore(&data->lock, flags);
203
204 writel(time, data->ioaddr + SNVS_LPTAR);
205
206 /* Clear alarm interrupt status bit */
207 writel(SNVS_LPSR_LPTA, data->ioaddr + SNVS_LPSR);
208
209 return snvs_rtc_alarm_irq_enable(dev, alrm->enabled);
210}
211
212static const struct rtc_class_ops snvs_rtc_ops = {
213 .read_time = snvs_rtc_read_time,
214 .set_time = snvs_rtc_set_time,
215 .read_alarm = snvs_rtc_read_alarm,
216 .set_alarm = snvs_rtc_set_alarm,
217 .alarm_irq_enable = snvs_rtc_alarm_irq_enable,
218};
219
220static irqreturn_t snvs_rtc_irq_handler(int irq, void *dev_id)
221{
222 struct device *dev = dev_id;
223 struct snvs_rtc_data *data = dev_get_drvdata(dev);
224 u32 lpsr;
225 u32 events = 0;
226
227 lpsr = readl(data->ioaddr + SNVS_LPSR);
228
229 if (lpsr & SNVS_LPSR_LPTA) {
230 events |= (RTC_AF | RTC_IRQF);
231
232 /* RTC alarm should be one-shot */
233 snvs_rtc_alarm_irq_enable(dev, 0);
234
235 rtc_update_irq(data->rtc, 1, events);
236 }
237
238 /* clear interrupt status */
239 writel(lpsr, data->ioaddr + SNVS_LPSR);
240
241 return events ? IRQ_HANDLED : IRQ_NONE;
242}
243
244static int __devinit snvs_rtc_probe(struct platform_device *pdev)
245{
246 struct snvs_rtc_data *data;
247 struct resource *res;
248 int ret;
249
250 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
251 if (!data)
252 return -ENOMEM;
253
254 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
255 data->ioaddr = devm_request_and_ioremap(&pdev->dev, res);
256 if (!data->ioaddr)
257 return -EADDRNOTAVAIL;
258
259 data->irq = platform_get_irq(pdev, 0);
260 if (data->irq < 0)
261 return data->irq;
262
263 platform_set_drvdata(pdev, data);
264
265 spin_lock_init(&data->lock);
266
267 /* Initialize glitch detect */
268 writel(SNVS_LPPGDR_INIT, data->ioaddr + SNVS_LPPGDR);
269
270 /* Clear interrupt status */
271 writel(0xffffffff, data->ioaddr + SNVS_LPSR);
272
273 /* Enable RTC */
274 snvs_rtc_enable(data, true);
275
276 device_init_wakeup(&pdev->dev, true);
277
278 ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler,
279 IRQF_SHARED, "rtc alarm", &pdev->dev);
280 if (ret) {
281 dev_err(&pdev->dev, "failed to request irq %d: %d\n",
282 data->irq, ret);
283 return ret;
284 }
285
286 data->rtc = rtc_device_register(pdev->name, &pdev->dev,
287 &snvs_rtc_ops, THIS_MODULE);
288 if (IS_ERR(data->rtc)) {
289 ret = PTR_ERR(data->rtc);
290 dev_err(&pdev->dev, "failed to register rtc: %d\n", ret);
291 return ret;
292 }
293
294 return 0;
295}
296
297static int __devexit snvs_rtc_remove(struct platform_device *pdev)
298{
299 struct snvs_rtc_data *data = platform_get_drvdata(pdev);
300
301 rtc_device_unregister(data->rtc);
302
303 return 0;
304}
305
306#ifdef CONFIG_PM_SLEEP
307static int snvs_rtc_suspend(struct device *dev)
308{
309 struct snvs_rtc_data *data = dev_get_drvdata(dev);
310
311 if (device_may_wakeup(dev))
312 enable_irq_wake(data->irq);
313
314 return 0;
315}
316
317static int snvs_rtc_resume(struct device *dev)
318{
319 struct snvs_rtc_data *data = dev_get_drvdata(dev);
320
321 if (device_may_wakeup(dev))
322 disable_irq_wake(data->irq);
323
324 return 0;
325}
326#endif
327
328static SIMPLE_DEV_PM_OPS(snvs_rtc_pm_ops, snvs_rtc_suspend, snvs_rtc_resume);
329
330static const struct of_device_id __devinitconst snvs_dt_ids[] = {
331 { .compatible = "fsl,sec-v4.0-mon-rtc-lp", },
332 { /* sentinel */ }
333};
334MODULE_DEVICE_TABLE(of, snvs_dt_ids);
335
336static struct platform_driver snvs_rtc_driver = {
337 .driver = {
338 .name = "snvs_rtc",
339 .owner = THIS_MODULE,
340 .pm = &snvs_rtc_pm_ops,
341 .of_match_table = snvs_dt_ids,
342 },
343 .probe = snvs_rtc_probe,
344 .remove = __devexit_p(snvs_rtc_remove),
345};
346module_platform_driver(snvs_rtc_driver);
347
348MODULE_AUTHOR("Freescale Semiconductor, Inc.");
349MODULE_DESCRIPTION("Freescale SNVS RTC Driver");
350MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index e2785479113c..bb507d23f6ce 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -235,7 +235,7 @@ static int spear_rtc_read_time(struct device *dev, struct rtc_time *tm)
235static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm) 235static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm)
236{ 236{
237 struct spear_rtc_config *config = dev_get_drvdata(dev); 237 struct spear_rtc_config *config = dev_get_drvdata(dev);
238 unsigned int time, date, err = 0; 238 unsigned int time, date;
239 239
240 if (tm2bcd(tm) < 0) 240 if (tm2bcd(tm) < 0)
241 return -EINVAL; 241 return -EINVAL;
@@ -247,11 +247,8 @@ static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm)
247 (tm->tm_year << YEAR_SHIFT); 247 (tm->tm_year << YEAR_SHIFT);
248 writel(time, config->ioaddr + TIME_REG); 248 writel(time, config->ioaddr + TIME_REG);
249 writel(date, config->ioaddr + DATE_REG); 249 writel(date, config->ioaddr + DATE_REG);
250 err = is_write_complete(config);
251 if (err < 0)
252 return err;
253 250
254 return 0; 251 return is_write_complete(config);
255} 252}
256 253
257/* 254/*
@@ -295,7 +292,8 @@ static int spear_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
295static int spear_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) 292static int spear_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
296{ 293{
297 struct spear_rtc_config *config = dev_get_drvdata(dev); 294 struct spear_rtc_config *config = dev_get_drvdata(dev);
298 unsigned int time, date, err = 0; 295 unsigned int time, date;
296 int err;
299 297
300 if (tm2bcd(&alm->time) < 0) 298 if (tm2bcd(&alm->time) < 0)
301 return -EINVAL; 299 return -EINVAL;
@@ -357,7 +355,7 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
357{ 355{
358 struct resource *res; 356 struct resource *res;
359 struct spear_rtc_config *config; 357 struct spear_rtc_config *config;
360 unsigned int status = 0; 358 int status = 0;
361 int irq; 359 int irq;
362 360
363 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 361 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 380083ca572f..b70e2bb63645 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -102,6 +102,12 @@ rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr,
102 return n; 102 return n;
103} 103}
104 104
105/**
106 * rtc_sysfs_show_hctosys - indicate if the given RTC set the system time
107 *
108 * Returns 1 if the system clock was set by this RTC at the last
109 * boot or resume event.
110 */
105static ssize_t 111static ssize_t
106rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, 112rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr,
107 char *buf) 113 char *buf)
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
new file mode 100644
index 000000000000..7a82337e4dee
--- /dev/null
+++ b/drivers/rtc/rtc-tps65910.c
@@ -0,0 +1,349 @@
1/*
2 * rtc-tps65910.c -- TPS65910 Real Time Clock interface
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5 * Author: Venu Byravarasu <vbyravarasu@nvidia.com>
6 *
7 * Based on original TI driver rtc-twl.c
8 * Copyright (C) 2007 MontaVista Software, Inc
9 * Author: Alexandre Rusev <source@mvista.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
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/rtc.h>
23#include <linux/bcd.h>
24#include <linux/platform_device.h>
25#include <linux/interrupt.h>
26#include <linux/mfd/tps65910.h>
27
28struct tps65910_rtc {
29 struct rtc_device *rtc;
30 /* To store the list of enabled interrupts */
31 u32 irqstat;
32};
33
34/* Total number of RTC registers needed to set time*/
35#define NUM_TIME_REGS (TPS65910_YEARS - TPS65910_SECONDS + 1)
36
37static int tps65910_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
38{
39 struct tps65910 *tps = dev_get_drvdata(dev->parent);
40 u8 val = 0;
41
42 if (enabled)
43 val = TPS65910_RTC_INTERRUPTS_IT_ALARM;
44
45 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, val);
46}
47
48/*
49 * Gets current tps65910 RTC time and date parameters.
50 *
51 * The RTC's time/alarm representation is not what gmtime(3) requires
52 * Linux to use:
53 *
54 * - Months are 1..12 vs Linux 0-11
55 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
56 */
57static int tps65910_rtc_read_time(struct device *dev, struct rtc_time *tm)
58{
59 unsigned char rtc_data[NUM_TIME_REGS];
60 struct tps65910 *tps = dev_get_drvdata(dev->parent);
61 int ret;
62
63 /* Copy RTC counting registers to static registers or latches */
64 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
65 TPS65910_RTC_CTRL_GET_TIME, TPS65910_RTC_CTRL_GET_TIME);
66 if (ret < 0) {
67 dev_err(dev, "RTC CTRL reg update failed with err:%d\n", ret);
68 return ret;
69 }
70
71 ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, rtc_data,
72 NUM_TIME_REGS);
73 if (ret < 0) {
74 dev_err(dev, "reading from RTC failed with err:%d\n", ret);
75 return ret;
76 }
77
78 tm->tm_sec = bcd2bin(rtc_data[0]);
79 tm->tm_min = bcd2bin(rtc_data[1]);
80 tm->tm_hour = bcd2bin(rtc_data[2]);
81 tm->tm_mday = bcd2bin(rtc_data[3]);
82 tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
83 tm->tm_year = bcd2bin(rtc_data[5]) + 100;
84
85 return ret;
86}
87
88static int tps65910_rtc_set_time(struct device *dev, struct rtc_time *tm)
89{
90 unsigned char rtc_data[NUM_TIME_REGS];
91 struct tps65910 *tps = dev_get_drvdata(dev->parent);
92 int ret;
93
94 rtc_data[0] = bin2bcd(tm->tm_sec);
95 rtc_data[1] = bin2bcd(tm->tm_min);
96 rtc_data[2] = bin2bcd(tm->tm_hour);
97 rtc_data[3] = bin2bcd(tm->tm_mday);
98 rtc_data[4] = bin2bcd(tm->tm_mon + 1);
99 rtc_data[5] = bin2bcd(tm->tm_year - 100);
100
101 /* Stop RTC while updating the RTC time registers */
102 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
103 TPS65910_RTC_CTRL_STOP_RTC, 0);
104 if (ret < 0) {
105 dev_err(dev, "RTC stop failed with err:%d\n", ret);
106 return ret;
107 }
108
109 /* update all the time registers in one shot */
110 ret = regmap_bulk_write(tps->regmap, TPS65910_SECONDS, rtc_data,
111 NUM_TIME_REGS);
112 if (ret < 0) {
113 dev_err(dev, "rtc_set_time error %d\n", ret);
114 return ret;
115 }
116
117 /* Start back RTC */
118 ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
119 TPS65910_RTC_CTRL_STOP_RTC, 1);
120 if (ret < 0)
121 dev_err(dev, "RTC start failed with err:%d\n", ret);
122
123 return ret;
124}
125
126/*
127 * Gets current tps65910 RTC alarm time.
128 */
129static int tps65910_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
130{
131 unsigned char alarm_data[NUM_TIME_REGS];
132 u32 int_val;
133 struct tps65910 *tps = dev_get_drvdata(dev->parent);
134 int ret;
135
136 ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, alarm_data,
137 NUM_TIME_REGS);
138 if (ret < 0) {
139 dev_err(dev, "rtc_read_alarm error %d\n", ret);
140 return ret;
141 }
142
143 alm->time.tm_sec = bcd2bin(alarm_data[0]);
144 alm->time.tm_min = bcd2bin(alarm_data[1]);
145 alm->time.tm_hour = bcd2bin(alarm_data[2]);
146 alm->time.tm_mday = bcd2bin(alarm_data[3]);
147 alm->time.tm_mon = bcd2bin(alarm_data[4]) - 1;
148 alm->time.tm_year = bcd2bin(alarm_data[5]) + 100;
149
150 ret = regmap_read(tps->regmap, TPS65910_RTC_INTERRUPTS, &int_val);
151 if (ret < 0)
152 return ret;
153
154 if (int_val & TPS65910_RTC_INTERRUPTS_IT_ALARM)
155 alm->enabled = 1;
156
157 return ret;
158}
159
160static int tps65910_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
161{
162 unsigned char alarm_data[NUM_TIME_REGS];
163 struct tps65910 *tps = dev_get_drvdata(dev->parent);
164 int ret;
165
166 ret = tps65910_rtc_alarm_irq_enable(dev, 0);
167 if (ret)
168 return ret;
169
170 alarm_data[0] = bin2bcd(alm->time.tm_sec);
171 alarm_data[1] = bin2bcd(alm->time.tm_min);
172 alarm_data[2] = bin2bcd(alm->time.tm_hour);
173 alarm_data[3] = bin2bcd(alm->time.tm_mday);
174 alarm_data[4] = bin2bcd(alm->time.tm_mon + 1);
175 alarm_data[5] = bin2bcd(alm->time.tm_year - 100);
176
177 /* update all the alarm registers in one shot */
178 ret = regmap_bulk_write(tps->regmap, TPS65910_ALARM_SECONDS,
179 alarm_data, NUM_TIME_REGS);
180 if (ret) {
181 dev_err(dev, "rtc_set_alarm error %d\n", ret);
182 return ret;
183 }
184
185 if (alm->enabled)
186 ret = tps65910_rtc_alarm_irq_enable(dev, 1);
187
188 return ret;
189}
190
191static irqreturn_t tps65910_rtc_interrupt(int irq, void *rtc)
192{
193 struct device *dev = rtc;
194 unsigned long events = 0;
195 struct tps65910 *tps = dev_get_drvdata(dev->parent);
196 struct tps65910_rtc *tps_rtc = dev_get_drvdata(dev);
197 int ret;
198 u32 rtc_reg;
199
200 ret = regmap_read(tps->regmap, TPS65910_RTC_STATUS, &rtc_reg);
201 if (ret)
202 return IRQ_NONE;
203
204 if (rtc_reg & TPS65910_RTC_STATUS_ALARM)
205 events = RTC_IRQF | RTC_AF;
206
207 ret = regmap_write(tps->regmap, TPS65910_RTC_STATUS, rtc_reg);
208 if (ret)
209 return IRQ_NONE;
210
211 /* Notify RTC core on event */
212 rtc_update_irq(tps_rtc->rtc, 1, events);
213
214 return IRQ_HANDLED;
215}
216
217static const struct rtc_class_ops tps65910_rtc_ops = {
218 .read_time = tps65910_rtc_read_time,
219 .set_time = tps65910_rtc_set_time,
220 .read_alarm = tps65910_rtc_read_alarm,
221 .set_alarm = tps65910_rtc_set_alarm,
222 .alarm_irq_enable = tps65910_rtc_alarm_irq_enable,
223};
224
225static int __devinit tps65910_rtc_probe(struct platform_device *pdev)
226{
227 struct tps65910 *tps65910 = NULL;
228 struct tps65910_rtc *tps_rtc = NULL;
229 int ret;
230 int irq;
231 u32 rtc_reg;
232
233 tps65910 = dev_get_drvdata(pdev->dev.parent);
234
235 tps_rtc = devm_kzalloc(&pdev->dev, sizeof(struct tps65910_rtc),
236 GFP_KERNEL);
237 if (!tps_rtc)
238 return -ENOMEM;
239
240 /* Clear pending interrupts */
241 ret = regmap_read(tps65910->regmap, TPS65910_RTC_STATUS, &rtc_reg);
242 if (ret < 0)
243 return ret;
244
245 ret = regmap_write(tps65910->regmap, TPS65910_RTC_STATUS, rtc_reg);
246 if (ret < 0)
247 return ret;
248
249 dev_dbg(&pdev->dev, "Enabling rtc-tps65910.\n");
250 rtc_reg = TPS65910_RTC_CTRL_STOP_RTC;
251 ret = regmap_write(tps65910->regmap, TPS65910_RTC_CTRL, rtc_reg);
252 if (ret < 0)
253 return ret;
254
255 irq = platform_get_irq(pdev, 0);
256 if (irq <= 0) {
257 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n",
258 irq);
259 return ret;
260 }
261
262 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
263 tps65910_rtc_interrupt, IRQF_TRIGGER_LOW,
264 "rtc-tps65910", &pdev->dev);
265 if (ret < 0) {
266 dev_err(&pdev->dev, "IRQ is not free.\n");
267 return ret;
268 }
269 device_init_wakeup(&pdev->dev, 1);
270
271 tps_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
272 &tps65910_rtc_ops, THIS_MODULE);
273 if (IS_ERR(tps_rtc->rtc)) {
274 ret = PTR_ERR(tps_rtc->rtc);
275 dev_err(&pdev->dev, "RTC device register: err %d\n", ret);
276 return ret;
277 }
278
279 platform_set_drvdata(pdev, tps_rtc);
280
281 return 0;
282}
283
284/*
285 * Disable tps65910 RTC interrupts.
286 * Sets status flag to free.
287 */
288static int __devexit tps65910_rtc_remove(struct platform_device *pdev)
289{
290 /* leave rtc running, but disable irqs */
291 struct rtc_device *rtc = platform_get_drvdata(pdev);
292
293 tps65910_rtc_alarm_irq_enable(&rtc->dev, 0);
294
295 rtc_device_unregister(rtc);
296 return 0;
297}
298
299#ifdef CONFIG_PM_SLEEP
300
301static int tps65910_rtc_suspend(struct device *dev)
302{
303 struct tps65910 *tps = dev_get_drvdata(dev->parent);
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
313 /* Enable RTC ALARM interrupt only */
314 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, alarm);
315}
316
317static int tps65910_rtc_resume(struct device *dev)
318{
319 struct tps65910 *tps = dev_get_drvdata(dev->parent);
320
321 /* Restore list of enabled interrupts before suspend */
322 return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS,
323 tps->rtc->irqstat);
324}
325
326static const struct dev_pm_ops tps65910_rtc_pm_ops = {
327 .suspend = tps65910_rtc_suspend,
328 .resume = tps65910_rtc_resume,
329};
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 = {
337 .probe = tps65910_rtc_probe,
338 .remove = __devexit_p(tps65910_rtc_remove),
339 .driver = {
340 .owner = THIS_MODULE,
341 .name = "tps65910-rtc",
342 .pm = DEV_PM_OPS,
343 },
344};
345
346module_platform_driver(tps65910_rtc_driver);
347MODULE_ALIAS("platform:rtc-tps65910");
348MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
349MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 403b3d41d101..f36e59c6bc01 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -97,8 +97,17 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
97 int i; 97 int i;
98 98
99 struct i2c_msg msgs[] = { 99 struct i2c_msg msgs[] = {
100 { client->addr, 0, 2, dt_addr }, /* setup read ptr */ 100 {/* setup read ptr */
101 { client->addr, I2C_M_RD, 8, buf }, /* read date */ 101 .addr = client->addr,
102 .len = 2,
103 .buf = dt_addr
104 },
105 {/* read date */
106 .addr = client->addr,
107 .flags = I2C_M_RD,
108 .len = 8,
109 .buf = buf
110 },
102 }; 111 };
103 112
104 /* read date registers */ 113 /* read date registers */
@@ -142,8 +151,17 @@ static int x1205_get_status(struct i2c_client *client, unsigned char *sr)
142 static unsigned char sr_addr[2] = { 0, X1205_REG_SR }; 151 static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
143 152
144 struct i2c_msg msgs[] = { 153 struct i2c_msg msgs[] = {
145 { client->addr, 0, 2, sr_addr }, /* setup read ptr */ 154 { /* setup read ptr */
146 { client->addr, I2C_M_RD, 1, sr }, /* read status */ 155 .addr = client->addr,
156 .len = 2,
157 .buf = sr_addr
158 },
159 { /* read status */
160 .addr = client->addr,
161 .flags = I2C_M_RD,
162 .len = 1,
163 .buf = sr
164 },
147 }; 165 };
148 166
149 /* read status register */ 167 /* read status register */
@@ -279,8 +297,17 @@ static int x1205_get_dtrim(struct i2c_client *client, int *trim)
279 static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR }; 297 static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR };
280 298
281 struct i2c_msg msgs[] = { 299 struct i2c_msg msgs[] = {
282 { client->addr, 0, 2, dtr_addr }, /* setup read ptr */ 300 { /* setup read ptr */
283 { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */ 301 .addr = client->addr,
302 .len = 2,
303 .buf = dtr_addr
304 },
305 { /* read dtr */
306 .addr = client->addr,
307 .flags = I2C_M_RD,
308 .len = 1,
309 .buf = &dtr
310 },
284 }; 311 };
285 312
286 /* read dtr register */ 313 /* read dtr register */
@@ -311,8 +338,17 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
311 static unsigned char atr_addr[2] = { 0, X1205_REG_ATR }; 338 static unsigned char atr_addr[2] = { 0, X1205_REG_ATR };
312 339
313 struct i2c_msg msgs[] = { 340 struct i2c_msg msgs[] = {
314 { client->addr, 0, 2, atr_addr }, /* setup read ptr */ 341 {/* setup read ptr */
315 { client->addr, I2C_M_RD, 1, &atr }, /* read atr */ 342 .addr = client->addr,
343 .len = 2,
344 .buf = atr_addr
345 },
346 {/* read atr */
347 .addr = client->addr,
348 .flags = I2C_M_RD,
349 .len = 1,
350 .buf = &atr
351 },
316 }; 352 };
317 353
318 /* read atr register */ 354 /* read atr register */
@@ -381,8 +417,17 @@ static int x1205_validate_client(struct i2c_client *client)
381 unsigned char addr[2] = { 0, probe_zero_pattern[i] }; 417 unsigned char addr[2] = { 0, probe_zero_pattern[i] };
382 418
383 struct i2c_msg msgs[2] = { 419 struct i2c_msg msgs[2] = {
384 { client->addr, 0, 2, addr }, 420 {
385 { client->addr, I2C_M_RD, 1, &buf }, 421 .addr = client->addr,
422 .len = 2,
423 .buf = addr
424 },
425 {
426 .addr = client->addr,
427 .flags = I2C_M_RD,
428 .len = 1,
429 .buf = &buf
430 },
386 }; 431 };
387 432
388 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 433 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
@@ -409,8 +454,17 @@ static int x1205_validate_client(struct i2c_client *client)
409 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg }; 454 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg };
410 455
411 struct i2c_msg msgs[2] = { 456 struct i2c_msg msgs[2] = {
412 { client->addr, 0, 2, addr }, 457 {
413 { client->addr, I2C_M_RD, 1, &reg }, 458 .addr = client->addr,
459 .len = 2,
460 .buf = addr
461 },
462 {
463 .addr = client->addr,
464 .flags = I2C_M_RD,
465 .len = 1,
466 .buf = &reg
467 },
414 }; 468 };
415 469
416 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 470 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
@@ -444,8 +498,18 @@ static int x1205_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
444 static unsigned char int_addr[2] = { 0, X1205_REG_INT }; 498 static unsigned char int_addr[2] = { 0, X1205_REG_INT };
445 struct i2c_client *client = to_i2c_client(dev); 499 struct i2c_client *client = to_i2c_client(dev);
446 struct i2c_msg msgs[] = { 500 struct i2c_msg msgs[] = {
447 { client->addr, 0, 2, int_addr }, /* setup read ptr */ 501 { /* setup read ptr */
448 { client->addr, I2C_M_RD, 1, &intreg }, /* read INT register */ 502 .addr = client->addr,
503 .len = 2,
504 .buf = int_addr
505 },
506 {/* read INT register */
507
508 .addr = client->addr,
509 .flags = I2C_M_RD,
510 .len = 1,
511 .buf = &intreg
512 },
449 }; 513 };
450 514
451 /* read interrupt register and status register */ 515 /* read interrupt register and status register */