24 #include <linux/module.h>
25 #include <linux/rtc.h>
29 #include <linux/slab.h>
33 #include <mach/hardware.h>
35 #define TIMER_FREQ CLOCK_TICK_RATE
36 #define RTC_DEF_DIVIDER (32768 - 1)
37 #define RTC_DEF_TRIM 0
38 #define MAXFREQ_PERIODIC 1000
43 #define RTSR_PICE (1 << 15)
44 #define RTSR_PIALE (1 << 14)
45 #define RTSR_PIAL (1 << 13)
46 #define RTSR_SWALE2 (1 << 11)
47 #define RTSR_SWAL2 (1 << 10)
48 #define RTSR_SWALE1 (1 << 9)
49 #define RTSR_SWAL1 (1 << 8)
50 #define RTSR_RDALE2 (1 << 7)
51 #define RTSR_RDAL2 (1 << 6)
52 #define RTSR_RDALE1 (1 << 5)
53 #define RTSR_RDAL1 (1 << 4)
54 #define RTSR_HZE (1 << 3)
55 #define RTSR_ALE (1 << 2)
56 #define RTSR_HZ (1 << 1)
57 #define RTSR_AL (1 << 0)
58 #define RTSR_TRIG_MASK (RTSR_AL | RTSR_HZ | RTSR_RDAL1 | RTSR_RDAL2\
59 | RTSR_SWAL1 | RTSR_SWAL2)
61 #define RYxR_YEAR_MASK (0xfff << RYxR_YEAR_S)
62 #define RYxR_MONTH_S 5
63 #define RYxR_MONTH_MASK (0xf << RYxR_MONTH_S)
64 #define RYxR_DAY_MASK 0x1f
65 #define RDxR_HOUR_S 12
66 #define RDxR_HOUR_MASK (0x1f << RDxR_HOUR_S)
68 #define RDxR_MIN_MASK (0x3f << RDxR_MIN_S)
69 #define RDxR_SEC_MASK 0x3f
80 #define rtc_readl(pxa_rtc, reg) \
81 __raw_readl((pxa_rtc)->base + (reg))
82 #define rtc_writel(pxa_rtc, reg, value) \
83 __raw_writel((value), (pxa_rtc)->base + (reg))
144 spin_lock(&pxa_rtc->
lock);
158 if (rtsr & RTSR_RDAL1)
170 spin_unlock(&pxa_rtc->
lock);
174 static int pxa_rtc_open(
struct device *
dev)
202 static void pxa_rtc_release(
struct device *dev)
206 spin_lock_irq(&pxa_rtc->
lock);
208 spin_unlock_irq(&pxa_rtc->
lock);
214 static int pxa_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
218 spin_lock_irq(&pxa_rtc->
lock);
225 spin_unlock_irq(&pxa_rtc->
lock);
229 static int pxa_rtc_read_time(
struct device *dev,
struct rtc_time *tm)
237 tm_calc(rycr, rdcr, tm);
241 static int pxa_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
254 u32 rtsr, ryar, rdar;
258 tm_calc(ryar, rdar, &alrm->
time);
271 spin_lock_irq(&pxa_rtc->
lock);
283 spin_unlock_irq(&pxa_rtc->
lock);
303 .open = pxa_rtc_open,
304 .release = pxa_rtc_release,
305 .read_time = pxa_rtc_read_time,
306 .set_time = pxa_rtc_set_time,
307 .read_alarm = pxa_rtc_read_alarm,
308 .set_alarm = pxa_rtc_set_alarm,
309 .alarm_irq_enable = pxa_alarm_irq_enable,
310 .proc = pxa_rtc_proc,
316 struct pxa_rtc *pxa_rtc;
320 pxa_rtc = kzalloc(
sizeof(
struct pxa_rtc),
GFP_KERNEL);
325 platform_set_drvdata(pdev, pxa_rtc);
329 if (!pxa_rtc->
ress) {
330 dev_err(dev,
"No I/O memory resource defined\n");
336 dev_err(dev,
"No 1Hz IRQ resource defined\n");
341 dev_err(dev,
"No alarm IRQ resource defined\n");
347 resource_size(pxa_rtc->
ress));
348 if (!pxa_rtc->
base) {
349 dev_err(&pdev->
dev,
"Unable to map pxa RTC I/O memory\n");
360 dev_warn(dev,
"warning: initializing default clock"
361 " divider/trim value\n");
368 ret = PTR_ERR(pxa_rtc->
rtc);
369 if (IS_ERR(pxa_rtc->
rtc)) {
370 dev_err(dev,
"Failed to register RTC device -> %d\n", ret);
388 struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
392 spin_lock_irq(&pxa_rtc->
lock);
394 spin_unlock_irq(&pxa_rtc->
lock);
410 static int pxa_rtc_suspend(
struct device *dev)
414 if (device_may_wakeup(dev))
419 static int pxa_rtc_resume(
struct device *dev)
423 if (device_may_wakeup(dev))
424 disable_irq_wake(pxa_rtc->
irq_Alrm);
428 static const struct dev_pm_ops pxa_rtc_pm_ops = {
430 .resume = pxa_rtc_resume,
440 .pm = &pxa_rtc_pm_ops,
445 static int __init pxa_rtc_init(
void)
453 static void __exit pxa_rtc_exit(
void)