14 #include <linux/module.h>
15 #include <linux/kernel.h>
17 #include <linux/time.h>
18 #include <linux/rtc.h>
21 #include <linux/slab.h>
23 #include <mach/board.h>
53 #define ALARM_DISABLED ((u32)~0)
64 #define rtt_readl(rtc, field) \
65 __raw_readl((rtc)->rtt + AT91_RTT_ ## field)
66 #define rtt_writel(rtc, field, val) \
67 __raw_writel((val), (rtc)->rtt + AT91_RTT_ ## field)
69 #define gpbr_readl(rtc) \
70 __raw_readl((rtc)->gpbr)
71 #define gpbr_writel(rtc, val) \
72 __raw_writel((val), (rtc)->gpbr)
96 dev_dbg(dev,
"%s: %4d-%02d-%02d %02d:%02d:%02d\n",
"readtime",
113 dev_dbg(dev,
"%s: %4d-%02d-%02d %02d:%02d:%02d\n",
"settime",
138 alarm += (offset - secs);
139 }
else if ((alarm + offset) > secs) {
167 memset(alrm, 0,
sizeof(*alrm));
171 dev_dbg(dev,
"%s: %4d-%02d-%02d %02d:%02d:%02d\n",
"readalarm",
204 if (secs <= offset) {
214 dev_dbg(dev,
"%s: %4d-%02d-%02d %02d:%02d:%02d\n",
"setalarm",
221 static int at91_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
226 dev_dbg(dev,
"alarm_irq_enable: enabled=%08x, mr %08x\n", enabled, mr);
237 static int at91_rtc_proc(
struct device *dev,
struct seq_file *seq)
274 pr_debug(
"%s: num=%ld, events=0x%02lx\n", __func__,
275 events >> 8, events & 0x000000FF);
281 .read_time = at91_rtc_readtime,
282 .set_time = at91_rtc_settime,
283 .read_alarm = at91_rtc_readalarm,
284 .set_alarm = at91_rtc_setalarm,
285 .proc = at91_rtc_proc,
286 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
308 dev_err(&pdev->
dev,
"failed to get interrupt resource\n");
319 if (!device_can_wakeup(&pdev->
dev))
322 platform_set_drvdata(pdev, rtc);
325 dev_err(&pdev->
dev,
"failed to map registers, aborting.\n");
332 dev_err(&pdev->
dev,
"failed to map gpbr registers, aborting.\n");
351 if (IS_ERR(rtc->
rtcdev)) {
352 ret = PTR_ERR(rtc->
rtcdev);
358 dev_name(&rtc->
rtcdev->dev), rtc);
373 dev_name(&rtc->
rtcdev->dev));
382 platform_set_drvdata(pdev,
NULL);
392 struct sam9_rtc *rtc = platform_get_drvdata(pdev);
403 platform_set_drvdata(pdev,
NULL);
410 struct sam9_rtc *rtc = platform_get_drvdata(pdev);
424 struct sam9_rtc *rtc = platform_get_drvdata(pdev);
434 enable_irq_wake(rtc->
irq);
437 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
447 struct sam9_rtc *rtc = platform_get_drvdata(pdev);
451 if (device_may_wakeup(&pdev->
dev))
452 disable_irq_wake(rtc->
irq);
460 #define at91_rtc_suspend NULL
461 #define at91_rtc_resume NULL
465 .probe = at91_rtc_probe,
467 .shutdown = at91_rtc_shutdown,
471 .name =
"rtc-at91sam9",