12 #include <linux/module.h>
14 #include <linux/string.h>
18 #include <linux/rtc.h>
22 #include <linux/slab.h>
27 #include <mach/hardware.h>
29 static struct resource *puv3_rtc_mem;
32 static int puv3_rtc_tickno =
IRQ_RTC;
37 static irqreturn_t puv3_rtc_alarmirq(
int irq,
void *
id)
46 static irqreturn_t puv3_rtc_tickirq(
int irq,
void *
id)
56 static void puv3_rtc_setaie(
int to)
60 pr_debug(
"%s: aie=%d\n", __func__, to);
74 pr_debug(
"%s: pie=%d\n", __func__, enabled);
76 spin_lock_irq(&puv3_rtc_pie_lock);
83 spin_unlock_irq(&puv3_rtc_pie_lock);
89 static int puv3_rtc_gettime(
struct device *dev,
struct rtc_time *rtc_tm)
93 pr_debug(
"read time %02x.%02x.%02x %02x/%02x/%02x\n",
102 unsigned long rtc_count = 0;
104 pr_debug(
"set time %02d.%02d.%02d %02d/%02d/%02d\n",
122 pr_debug(
"read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n",
133 unsigned long rtcalarm_count = 0;
135 pr_debug(
"puv3_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n",
143 puv3_rtc_setaie(alrm->
enabled);
146 enable_irq_wake(puv3_rtc_alarmno);
148 disable_irq_wake(puv3_rtc_alarmno);
153 static int puv3_rtc_proc(
struct device *dev,
struct seq_file *seq)
160 static int puv3_rtc_open(
struct device *dev)
163 struct rtc_device *rtc_dev = platform_get_drvdata(pdev);
166 ret =
request_irq(puv3_rtc_alarmno, puv3_rtc_alarmirq,
167 0,
"pkunity-rtc alarm", rtc_dev);
170 dev_err(dev,
"IRQ%d error %d\n", puv3_rtc_alarmno, ret);
174 ret =
request_irq(puv3_rtc_tickno, puv3_rtc_tickirq,
175 0,
"pkunity-rtc tick", rtc_dev);
178 dev_err(dev,
"IRQ%d error %d\n", puv3_rtc_tickno, ret);
185 free_irq(puv3_rtc_alarmno, rtc_dev);
189 static void puv3_rtc_release(
struct device *dev)
192 struct rtc_device *rtc_dev = platform_get_drvdata(pdev);
195 puv3_rtc_setpie(dev, 0);
196 free_irq(puv3_rtc_alarmno, rtc_dev);
201 .open = puv3_rtc_open,
202 .release = puv3_rtc_release,
203 .read_time = puv3_rtc_gettime,
204 .set_time = puv3_rtc_settime,
205 .read_alarm = puv3_rtc_getalarm,
206 .set_alarm = puv3_rtc_setalarm,
207 .proc = puv3_rtc_proc,
217 dev_info(&pdev->
dev,
"rtc disabled, re-enabling\n");
227 platform_set_drvdata(dev,
NULL);
230 puv3_rtc_setpie(&dev->
dev, 0);
245 pr_debug(
"%s: probe=%p\n", __func__, pdev);
249 if (puv3_rtc_tickno < 0) {
255 if (puv3_rtc_alarmno < 0) {
260 pr_debug(
"PKUnity_rtc: tick irq %d, alarm irq %d\n",
261 puv3_rtc_tickno, puv3_rtc_alarmno);
266 dev_err(&pdev->
dev,
"failed to get memory region resource\n");
273 if (puv3_rtc_mem ==
NULL) {
274 dev_err(&pdev->
dev,
"failed to reserve memory region\n");
279 puv3_rtc_enable(pdev, 1);
292 if (!device_can_wakeup(&pdev->
dev))
295 platform_set_drvdata(pdev, rtc);
299 puv3_rtc_enable(pdev, 0);
308 static int ticnt_save;
314 puv3_rtc_enable(pdev, 0);
320 puv3_rtc_enable(pdev, 1);
325 #define puv3_rtc_suspend NULL
326 #define puv3_rtc_resume NULL
330 .probe = puv3_rtc_probe,
335 .name =
"PKUnity-v3-RTC",