diff options
author | Daniel Ribeiro <drwyrm@gmail.com> | 2009-09-22 19:46:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-23 10:39:45 -0400 |
commit | d3c7a3f71a103abb7af5bdaf1adf6f693913a4a9 (patch) | |
tree | 02cce65ada27b93ede5cf580b99a40ba3ce2735f | |
parent | 88413e1eeb2cccc721cd5568544f32f4234700fb (diff) |
rtc: driver for PCAP2 PMIC
[ospite@studenti.unina.it: get pcap data from the parent device]
Signed-off-by: guiming zhuo <gmzhuo@gmail.com>
Signed-off-by: Daniel Ribeiro <drwyrm@gmail.com>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/rtc/Kconfig | 7 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-pcap.c | 224 |
3 files changed, 232 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 8455de86e2bf..3c20dae43ce2 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -820,4 +820,11 @@ config RTC_DRV_STMP | |||
820 | This driver can also be built as a module. If so, the module | 820 | This driver can also be built as a module. If so, the module |
821 | will be called rtc-stmp3xxx. | 821 | will be called rtc-stmp3xxx. |
822 | 822 | ||
823 | config RTC_DRV_PCAP | ||
824 | tristate "PCAP RTC" | ||
825 | depends on EZX_PCAP | ||
826 | help | ||
827 | If you say Y here you will get support for the RTC found on | ||
828 | the PCAP2 ASIC used on some Motorola phones. | ||
829 | |||
823 | endif # RTC_CLASS | 830 | endif # RTC_CLASS |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 82c718bdaf10..aa3fbd5517a1 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -54,6 +54,7 @@ obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o | |||
54 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | 54 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o |
55 | obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o | 55 | obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o |
56 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o | 56 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o |
57 | obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o | ||
57 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o | 58 | obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o |
58 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o | 59 | obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o |
59 | obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o | 60 | obj-$(CONFIG_RTC_DRV_PCF2123) += rtc-pcf2123.o |
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c new file mode 100644 index 000000000000..a99c28992d21 --- /dev/null +++ b/drivers/rtc/rtc-pcap.c | |||
@@ -0,0 +1,224 @@ | |||
1 | /* | ||
2 | * pcap rtc code for Motorola EZX phones | ||
3 | * | ||
4 | * Copyright (c) 2008 guiming zhuo <gmzhuo@gmail.com> | ||
5 | * Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com> | ||
6 | * | ||
7 | * Based on Motorola's rtc.c Copyright (c) 2003-2005 Motorola | ||
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 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/mfd/ezx-pcap.h> | ||
19 | #include <linux/rtc.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | |||
22 | struct pcap_rtc { | ||
23 | struct pcap_chip *pcap; | ||
24 | struct rtc_device *rtc; | ||
25 | }; | ||
26 | |||
27 | static irqreturn_t pcap_rtc_irq(int irq, void *_pcap_rtc) | ||
28 | { | ||
29 | struct pcap_rtc *pcap_rtc = _pcap_rtc; | ||
30 | unsigned long rtc_events; | ||
31 | |||
32 | if (irq == pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ)) | ||
33 | rtc_events = RTC_IRQF | RTC_UF; | ||
34 | else if (irq == pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA)) | ||
35 | rtc_events = RTC_IRQF | RTC_AF; | ||
36 | else | ||
37 | rtc_events = 0; | ||
38 | |||
39 | rtc_update_irq(pcap_rtc->rtc, 1, rtc_events); | ||
40 | return IRQ_HANDLED; | ||
41 | } | ||
42 | |||
43 | static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
44 | { | ||
45 | struct platform_device *pdev = to_platform_device(dev); | ||
46 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
47 | struct rtc_time *tm = &alrm->time; | ||
48 | unsigned long secs; | ||
49 | u32 tod; /* time of day, seconds since midnight */ | ||
50 | u32 days; /* days since 1/1/1970 */ | ||
51 | |||
52 | ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_TODA, &tod); | ||
53 | secs = tod & PCAP_RTC_TOD_MASK; | ||
54 | |||
55 | ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days); | ||
56 | secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; | ||
57 | |||
58 | rtc_time_to_tm(secs, tm); | ||
59 | |||
60 | return 0; | ||
61 | } | ||
62 | |||
63 | static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) | ||
64 | { | ||
65 | struct platform_device *pdev = to_platform_device(dev); | ||
66 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
67 | struct rtc_time *tm = &alrm->time; | ||
68 | unsigned long secs; | ||
69 | u32 tod, days; | ||
70 | |||
71 | rtc_tm_to_time(tm, &secs); | ||
72 | |||
73 | tod = secs % SEC_PER_DAY; | ||
74 | ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod); | ||
75 | |||
76 | days = secs / SEC_PER_DAY; | ||
77 | ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, days); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) | ||
83 | { | ||
84 | struct platform_device *pdev = to_platform_device(dev); | ||
85 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
86 | unsigned long secs; | ||
87 | u32 tod, days; | ||
88 | |||
89 | ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_TOD, &tod); | ||
90 | secs = tod & PCAP_RTC_TOD_MASK; | ||
91 | |||
92 | ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days); | ||
93 | secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; | ||
94 | |||
95 | rtc_time_to_tm(secs, tm); | ||
96 | |||
97 | return rtc_valid_tm(tm); | ||
98 | } | ||
99 | |||
100 | static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) | ||
101 | { | ||
102 | struct platform_device *pdev = to_platform_device(dev); | ||
103 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
104 | u32 tod, days; | ||
105 | |||
106 | tod = secs % SEC_PER_DAY; | ||
107 | ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TOD, tod); | ||
108 | |||
109 | days = secs / SEC_PER_DAY; | ||
110 | ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_DAY, days); | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int pcap_rtc_irq_enable(struct device *dev, int pirq, unsigned int en) | ||
116 | { | ||
117 | struct platform_device *pdev = to_platform_device(dev); | ||
118 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
119 | |||
120 | if (en) | ||
121 | enable_irq(pcap_to_irq(pcap_rtc->pcap, pirq)); | ||
122 | else | ||
123 | disable_irq(pcap_to_irq(pcap_rtc->pcap, pirq)); | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | static int pcap_rtc_alarm_irq_enable(struct device *dev, unsigned int en) | ||
129 | { | ||
130 | return pcap_rtc_irq_enable(dev, PCAP_IRQ_TODA, en); | ||
131 | } | ||
132 | |||
133 | static int pcap_rtc_update_irq_enable(struct device *dev, unsigned int en) | ||
134 | { | ||
135 | return pcap_rtc_irq_enable(dev, PCAP_IRQ_1HZ, en); | ||
136 | } | ||
137 | |||
138 | static const struct rtc_class_ops pcap_rtc_ops = { | ||
139 | .read_time = pcap_rtc_read_time, | ||
140 | .read_alarm = pcap_rtc_read_alarm, | ||
141 | .set_alarm = pcap_rtc_set_alarm, | ||
142 | .set_mmss = pcap_rtc_set_mmss, | ||
143 | .alarm_irq_enable = pcap_rtc_alarm_irq_enable, | ||
144 | .update_irq_enable = pcap_rtc_update_irq_enable, | ||
145 | }; | ||
146 | |||
147 | static int __devinit pcap_rtc_probe(struct platform_device *pdev) | ||
148 | { | ||
149 | struct pcap_rtc *pcap_rtc; | ||
150 | int timer_irq, alarm_irq; | ||
151 | int err = -ENOMEM; | ||
152 | |||
153 | pcap_rtc = kmalloc(sizeof(struct pcap_rtc), GFP_KERNEL); | ||
154 | if (!pcap_rtc) | ||
155 | return err; | ||
156 | |||
157 | pcap_rtc->pcap = dev_get_drvdata(pdev->dev.parent); | ||
158 | |||
159 | pcap_rtc->rtc = rtc_device_register("pcap", &pdev->dev, | ||
160 | &pcap_rtc_ops, THIS_MODULE); | ||
161 | if (IS_ERR(pcap_rtc->rtc)) { | ||
162 | err = PTR_ERR(pcap_rtc->rtc); | ||
163 | goto fail_rtc; | ||
164 | } | ||
165 | |||
166 | platform_set_drvdata(pdev, pcap_rtc); | ||
167 | |||
168 | timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); | ||
169 | alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); | ||
170 | |||
171 | err = request_irq(timer_irq, pcap_rtc_irq, 0, "RTC Timer", pcap_rtc); | ||
172 | if (err) | ||
173 | goto fail_timer; | ||
174 | |||
175 | err = request_irq(alarm_irq, pcap_rtc_irq, 0, "RTC Alarm", pcap_rtc); | ||
176 | if (err) | ||
177 | goto fail_alarm; | ||
178 | |||
179 | return 0; | ||
180 | fail_alarm: | ||
181 | free_irq(timer_irq, pcap_rtc); | ||
182 | fail_timer: | ||
183 | rtc_device_unregister(pcap_rtc->rtc); | ||
184 | fail_rtc: | ||
185 | kfree(pcap_rtc); | ||
186 | return err; | ||
187 | } | ||
188 | |||
189 | static int __devexit pcap_rtc_remove(struct platform_device *pdev) | ||
190 | { | ||
191 | struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev); | ||
192 | |||
193 | free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ), pcap_rtc); | ||
194 | free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA), pcap_rtc); | ||
195 | rtc_device_unregister(pcap_rtc->rtc); | ||
196 | kfree(pcap_rtc); | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | static struct platform_driver pcap_rtc_driver = { | ||
202 | .remove = __devexit_p(pcap_rtc_remove), | ||
203 | .driver = { | ||
204 | .name = "pcap-rtc", | ||
205 | .owner = THIS_MODULE, | ||
206 | }, | ||
207 | }; | ||
208 | |||
209 | static int __init rtc_pcap_init(void) | ||
210 | { | ||
211 | return platform_driver_probe(&pcap_rtc_driver, pcap_rtc_probe); | ||
212 | } | ||
213 | |||
214 | static void __exit rtc_pcap_exit(void) | ||
215 | { | ||
216 | platform_driver_unregister(&pcap_rtc_driver); | ||
217 | } | ||
218 | |||
219 | module_init(rtc_pcap_init); | ||
220 | module_exit(rtc_pcap_exit); | ||
221 | |||
222 | MODULE_DESCRIPTION("Motorola pcap rtc driver"); | ||
223 | MODULE_AUTHOR("guiming zhuo <gmzhuo@gmail.com>"); | ||
224 | MODULE_LICENSE("GPL"); | ||