blob: 4595d3e645a7358676b5409b8ced918f306e07c2 [file] [log] [blame]
Richard Purdiee842f1c2006-03-27 01:16:46 -08001/*
2 * Real Time Clock interface for StrongARM SA1x00 and XScale PXA2xx
3 *
4 * Copyright (c) 2000 Nils Faerber
5 *
6 * Based on rtc.c by Paul Gortmaker
7 *
8 * Original Driver by Nils Faerber <nils@kernelconcepts.de>
9 *
10 * Modifications from:
11 * CIH <cih@coventive.com>
Nicolas Pitre2f82af02009-09-14 03:25:28 -040012 * Nicolas Pitre <nico@fluxnic.net>
Richard Purdiee842f1c2006-03-27 01:16:46 -080013 * Andrew Christian <andrew.christian@hp.com>
14 *
15 * Converted to the RTC subsystem and Driver Model
16 * by Richard Purdie <rpurdie@rpsys.net>
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
23
24#include <linux/platform_device.h>
25#include <linux/module.h>
26#include <linux/rtc.h>
27#include <linux/init.h>
28#include <linux/fs.h>
29#include <linux/interrupt.h>
Richard Purdiee842f1c2006-03-27 01:16:46 -080030#include <linux/pm.h>
Jett.Zhou7cea0062011-11-30 12:26:23 +080031#include <linux/slab.h>
32#include <linux/clk.h>
33#include <linux/io.h>
Richard Purdiee842f1c2006-03-27 01:16:46 -080034
Russell Kinga09e64f2008-08-05 16:14:15 +010035#include <mach/hardware.h>
Richard Purdiee842f1c2006-03-27 01:16:46 -080036#include <asm/irq.h>
Richard Purdiee842f1c2006-03-27 01:16:46 -080037
Marcelo Roberto Jimeneza404ad12010-10-18 22:33:53 +010038#define RTC_DEF_DIVIDER (32768 - 1)
Richard Purdiee842f1c2006-03-27 01:16:46 -080039#define RTC_DEF_TRIM 0
Jett.Zhou7cea0062011-11-30 12:26:23 +080040#define RTC_FREQ 1024
Richard Purdiee842f1c2006-03-27 01:16:46 -080041
Jett.Zhou7cea0062011-11-30 12:26:23 +080042#define RCNR 0x00 /* RTC Count Register */
43#define RTAR 0x04 /* RTC Alarm Register */
44#define RTSR 0x08 /* RTC Status Register */
45#define RTTR 0x0c /* RTC Timer Trim Register */
Richard Purdiee842f1c2006-03-27 01:16:46 -080046
Jett.Zhou7cea0062011-11-30 12:26:23 +080047#define RTSR_HZE (1 << 3) /* HZ interrupt enable */
48#define RTSR_ALE (1 << 2) /* RTC alarm interrupt enable */
49#define RTSR_HZ (1 << 1) /* HZ rising-edge detected */
50#define RTSR_AL (1 << 0) /* RTC alarm detected */
51
52#define rtc_readl(sa1100_rtc, reg) \
53 readl_relaxed((sa1100_rtc)->base + (reg))
54#define rtc_writel(sa1100_rtc, reg, value) \
55 writel_relaxed((value), (sa1100_rtc)->base + (reg))
56
57struct sa1100_rtc {
58 struct resource *ress;
59 void __iomem *base;
60 struct clk *clk;
61 int irq_1Hz;
62 int irq_Alrm;
63 struct rtc_device *rtc;
64 spinlock_t lock; /* Protects this structure */
65};
Russell King797276e2008-04-20 12:30:41 +010066/*
67 * Calculate the next alarm time given the requested alarm time mask
68 * and the current time.
69 */
Marcelo Roberto Jimeneza404ad12010-10-18 22:33:53 +010070static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
71 struct rtc_time *alrm)
Russell King797276e2008-04-20 12:30:41 +010072{
73 unsigned long next_time;
74 unsigned long now_time;
75
76 next->tm_year = now->tm_year;
77 next->tm_mon = now->tm_mon;
78 next->tm_mday = now->tm_mday;
79 next->tm_hour = alrm->tm_hour;
80 next->tm_min = alrm->tm_min;
81 next->tm_sec = alrm->tm_sec;
82
83 rtc_tm_to_time(now, &now_time);
84 rtc_tm_to_time(next, &next_time);
85
86 if (next_time < now_time) {
87 /* Advance one day */
88 next_time += 60 * 60 * 24;
89 rtc_time_to_tm(next_time, next);
90 }
91}
92
David Howells7d12e782006-10-05 14:55:46 +010093static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
Richard Purdiee842f1c2006-03-27 01:16:46 -080094{
95 struct platform_device *pdev = to_platform_device(dev_id);
Jett.Zhou7cea0062011-11-30 12:26:23 +080096 struct sa1100_rtc *sa1100_rtc = platform_get_drvdata(pdev);
Richard Purdiee842f1c2006-03-27 01:16:46 -080097 unsigned int rtsr;
98 unsigned long events = 0;
99
Jett.Zhou7cea0062011-11-30 12:26:23 +0800100 spin_lock(&sa1100_rtc->lock);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800101
Richard Purdiee842f1c2006-03-27 01:16:46 -0800102 /* clear interrupt sources */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800103 rtsr = rtc_readl(sa1100_rtc, RTSR);
104 rtc_writel(sa1100_rtc, RTSR, 0);
105
Marcelo Roberto Jimenez7decaa52010-10-18 22:35:54 +0100106 /* Fix for a nasty initialization problem the in SA11xx RTSR register.
107 * See also the comments in sa1100_rtc_probe(). */
108 if (rtsr & (RTSR_ALE | RTSR_HZE)) {
109 /* This is the original code, before there was the if test
110 * above. This code does not clear interrupts that were not
111 * enabled. */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800112 rtc_writel(sa1100_rtc, RTSR, (RTSR_AL | RTSR_HZ) & (rtsr >> 2));
Marcelo Roberto Jimenez7decaa52010-10-18 22:35:54 +0100113 } else {
114 /* For some reason, it is possible to enter this routine
115 * without interruptions enabled, it has been tested with
116 * several units (Bug in SA11xx chip?).
117 *
118 * This situation leads to an infinite "loop" of interrupt
119 * routine calling and as a result the processor seems to
120 * lock on its first call to open(). */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800121 rtc_writel(sa1100_rtc, RTSR, (RTSR_AL | RTSR_HZ));
Marcelo Roberto Jimenez7decaa52010-10-18 22:35:54 +0100122 }
Richard Purdiee842f1c2006-03-27 01:16:46 -0800123
124 /* clear alarm interrupt if it has occurred */
125 if (rtsr & RTSR_AL)
126 rtsr &= ~RTSR_ALE;
Jett.Zhou7cea0062011-11-30 12:26:23 +0800127 rtc_writel(sa1100_rtc, RTSR, rtsr & (RTSR_ALE | RTSR_HZE));
Richard Purdiee842f1c2006-03-27 01:16:46 -0800128
129 /* update irq data & counter */
130 if (rtsr & RTSR_AL)
131 events |= RTC_AF | RTC_IRQF;
132 if (rtsr & RTSR_HZ)
133 events |= RTC_UF | RTC_IRQF;
134
Jett.Zhou7cea0062011-11-30 12:26:23 +0800135 rtc_update_irq(sa1100_rtc->rtc, 1, events);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800136
Jett.Zhou7cea0062011-11-30 12:26:23 +0800137 spin_unlock(&sa1100_rtc->lock);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800138
139 return IRQ_HANDLED;
140}
141
Richard Purdiee842f1c2006-03-27 01:16:46 -0800142static int sa1100_rtc_open(struct device *dev)
143{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800144 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800145 int ret;
146
Jett.Zhou7cea0062011-11-30 12:26:23 +0800147 ret = request_irq(sa1100_rtc->irq_1Hz, sa1100_rtc_interrupt,
148 IRQF_DISABLED, "rtc 1Hz", dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800149 if (ret) {
Jett.Zhou7cea0062011-11-30 12:26:23 +0800150 dev_err(dev, "IRQ %d already in use.\n", sa1100_rtc->irq_1Hz);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800151 goto fail_ui;
152 }
Jett.Zhou7cea0062011-11-30 12:26:23 +0800153 ret = request_irq(sa1100_rtc->irq_Alrm, sa1100_rtc_interrupt,
154 IRQF_DISABLED, "rtc Alrm", dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800155 if (ret) {
Jett.Zhou7cea0062011-11-30 12:26:23 +0800156 dev_err(dev, "IRQ %d already in use.\n", sa1100_rtc->irq_Alrm);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800157 goto fail_ai;
158 }
Jett.Zhou7cea0062011-11-30 12:26:23 +0800159 sa1100_rtc->rtc->max_user_freq = RTC_FREQ;
160 rtc_irq_set_freq(sa1100_rtc->rtc, NULL, RTC_FREQ);
Marcelo Roberto Jimenezd2ccb522010-12-16 21:31:32 +0100161
Richard Purdiee842f1c2006-03-27 01:16:46 -0800162 return 0;
163
Richard Purdiee842f1c2006-03-27 01:16:46 -0800164 fail_ai:
Jett.Zhou7cea0062011-11-30 12:26:23 +0800165 free_irq(sa1100_rtc->irq_1Hz, dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800166 fail_ui:
167 return ret;
168}
169
170static void sa1100_rtc_release(struct device *dev)
171{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800172 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800173
Jett.Zhou7cea0062011-11-30 12:26:23 +0800174 spin_lock_irq(&sa1100_rtc->lock);
175 rtc_writel(sa1100_rtc, RTSR, 0);
176 spin_unlock_irq(&sa1100_rtc->lock);
177
178 free_irq(sa1100_rtc->irq_Alrm, dev);
179 free_irq(sa1100_rtc->irq_1Hz, dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800180}
181
John Stultz16380c12011-02-02 17:02:41 -0800182static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
183{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800184 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
185 unsigned int rtsr;
186
187 spin_lock_irq(&sa1100_rtc->lock);
188
189 rtsr = rtc_readl(sa1100_rtc, RTSR);
John Stultz16380c12011-02-02 17:02:41 -0800190 if (enabled)
Jett.Zhou7cea0062011-11-30 12:26:23 +0800191 rtsr |= RTSR_ALE;
John Stultz16380c12011-02-02 17:02:41 -0800192 else
Jett.Zhou7cea0062011-11-30 12:26:23 +0800193 rtsr &= ~RTSR_ALE;
194 rtc_writel(sa1100_rtc, RTSR, rtsr);
195
196 spin_unlock_irq(&sa1100_rtc->lock);
John Stultz16380c12011-02-02 17:02:41 -0800197 return 0;
198}
199
Richard Purdiee842f1c2006-03-27 01:16:46 -0800200static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
201{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800202 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
203
204 rtc_time_to_tm(rtc_readl(sa1100_rtc, RCNR), tm);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800205 return 0;
206}
207
208static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
209{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800210 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800211 unsigned long time;
212 int ret;
213
214 ret = rtc_tm_to_time(tm, &time);
215 if (ret == 0)
Jett.Zhou7cea0062011-11-30 12:26:23 +0800216 rtc_writel(sa1100_rtc, RCNR, time);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800217 return ret;
218}
219
220static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
221{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800222 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
223 unsigned long time;
224 unsigned int rtsr;
David Brownell32b49da2007-02-20 13:58:13 -0800225
Jett.Zhou7cea0062011-11-30 12:26:23 +0800226 time = rtc_readl(sa1100_rtc, RCNR);
227 rtc_time_to_tm(time, &alrm->time);
228 rtsr = rtc_readl(sa1100_rtc, RTSR);
David Brownell32b49da2007-02-20 13:58:13 -0800229 alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
230 alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
Richard Purdiee842f1c2006-03-27 01:16:46 -0800231 return 0;
232}
233
234static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
235{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800236 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
Jett.Zhou42874752011-11-30 12:26:22 +0800237 struct rtc_time now_tm, alarm_tm;
Jett.Zhou7cea0062011-11-30 12:26:23 +0800238 unsigned long time, alarm;
239 unsigned int rtsr;
Richard Purdiee842f1c2006-03-27 01:16:46 -0800240
Jett.Zhou7cea0062011-11-30 12:26:23 +0800241 spin_lock_irq(&sa1100_rtc->lock);
Jett.Zhou42874752011-11-30 12:26:22 +0800242
Jett.Zhou7cea0062011-11-30 12:26:23 +0800243 time = rtc_readl(sa1100_rtc, RCNR);
244 rtc_time_to_tm(time, &now_tm);
245 rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time);
246 rtc_tm_to_time(&alarm_tm, &alarm);
247 rtc_writel(sa1100_rtc, RTAR, alarm);
248
249 rtsr = rtc_readl(sa1100_rtc, RTSR);
Jett.Zhou42874752011-11-30 12:26:22 +0800250 if (alrm->enabled)
Jett.Zhou7cea0062011-11-30 12:26:23 +0800251 rtsr |= RTSR_ALE;
Jett.Zhou42874752011-11-30 12:26:22 +0800252 else
Jett.Zhou7cea0062011-11-30 12:26:23 +0800253 rtsr &= ~RTSR_ALE;
254 rtc_writel(sa1100_rtc, RTSR, rtsr);
Jett.Zhou42874752011-11-30 12:26:22 +0800255
Jett.Zhou7cea0062011-11-30 12:26:23 +0800256 spin_unlock_irq(&sa1100_rtc->lock);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800257
Jett.Zhou7cea0062011-11-30 12:26:23 +0800258 return 0;
Richard Purdiee842f1c2006-03-27 01:16:46 -0800259}
260
261static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
262{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800263 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800264
Jett.Zhou7cea0062011-11-30 12:26:23 +0800265 seq_printf(seq, "trim/divider\t\t: 0x%08x\n",
266 rtc_readl(sa1100_rtc, RTTR));
267 seq_printf(seq, "RTSR\t\t\t: 0x%08x\n",
268 rtc_readl(sa1100_rtc, RTSR));
Richard Purdiee842f1c2006-03-27 01:16:46 -0800269 return 0;
270}
271
David Brownellff8371a2006-09-30 23:28:17 -0700272static const struct rtc_class_ops sa1100_rtc_ops = {
Richard Purdiee842f1c2006-03-27 01:16:46 -0800273 .open = sa1100_rtc_open,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800274 .release = sa1100_rtc_release,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800275 .read_time = sa1100_rtc_read_time,
276 .set_time = sa1100_rtc_set_time,
277 .read_alarm = sa1100_rtc_read_alarm,
278 .set_alarm = sa1100_rtc_set_alarm,
279 .proc = sa1100_rtc_proc,
John Stultz16380c12011-02-02 17:02:41 -0800280 .alarm_irq_enable = sa1100_rtc_alarm_irq_enable,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800281};
282
283static int sa1100_rtc_probe(struct platform_device *pdev)
284{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800285 struct sa1100_rtc *sa1100_rtc;
286 unsigned int rttr;
287 int ret;
288
289 sa1100_rtc = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
290 if (!sa1100_rtc)
291 return -ENOMEM;
292
293 spin_lock_init(&sa1100_rtc->lock);
294 platform_set_drvdata(pdev, sa1100_rtc);
295
296 ret = -ENXIO;
297 sa1100_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
298 if (!sa1100_rtc->ress) {
299 dev_err(&pdev->dev, "No I/O memory resource defined\n");
300 goto err_ress;
301 }
302
303 sa1100_rtc->irq_1Hz = platform_get_irq(pdev, 0);
304 if (sa1100_rtc->irq_1Hz < 0) {
305 dev_err(&pdev->dev, "No 1Hz IRQ resource defined\n");
306 goto err_ress;
307 }
308 sa1100_rtc->irq_Alrm = platform_get_irq(pdev, 1);
309 if (sa1100_rtc->irq_Alrm < 0) {
310 dev_err(&pdev->dev, "No alarm IRQ resource defined\n");
311 goto err_ress;
312 }
313
314 ret = -ENOMEM;
315 sa1100_rtc->base = ioremap(sa1100_rtc->ress->start,
316 resource_size(sa1100_rtc->ress));
317 if (!sa1100_rtc->base) {
318 dev_err(&pdev->dev, "Unable to map pxa RTC I/O memory\n");
319 goto err_map;
320 }
321
322 sa1100_rtc->clk = clk_get(&pdev->dev, NULL);
323 if (IS_ERR(sa1100_rtc->clk)) {
324 dev_err(&pdev->dev, "failed to find rtc clock source\n");
325 ret = PTR_ERR(sa1100_rtc->clk);
326 goto err_clk;
327 }
328 clk_prepare(sa1100_rtc->clk);
329 clk_enable(sa1100_rtc->clk);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800330
331 /*
332 * According to the manual we should be able to let RTTR be zero
333 * and then a default diviser for a 32.768KHz clock is used.
334 * Apparently this doesn't work, at least for my SA1110 rev 5.
335 * If the clock divider is uninitialized then reset it to the
336 * default value to get the 1Hz clock.
337 */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800338 if (rtc_readl(sa1100_rtc, RTTR) == 0) {
339 rttr = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
340 rtc_writel(sa1100_rtc, RTTR, rttr);
341 dev_warn(&pdev->dev, "warning: initializing default clock"
342 " divider/trim value\n");
Richard Purdiee842f1c2006-03-27 01:16:46 -0800343 /* The current RTC value probably doesn't make sense either */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800344 rtc_writel(sa1100_rtc, RCNR, 0);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800345 }
346
Uli Luckase5a2c9c2008-06-18 09:54:03 +0100347 device_init_wakeup(&pdev->dev, 1);
348
Jett.Zhou7cea0062011-11-30 12:26:23 +0800349 sa1100_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
350 &sa1100_rtc_ops, THIS_MODULE);
351 if (IS_ERR(sa1100_rtc->rtc)) {
352 dev_err(&pdev->dev, "Failed to register RTC device -> %d\n",
353 ret);
354 goto err_rtc_reg;
355 }
Marcelo Roberto Jimenez7decaa52010-10-18 22:35:54 +0100356 /* Fix for a nasty initialization problem the in SA11xx RTSR register.
357 * See also the comments in sa1100_rtc_interrupt().
358 *
359 * Sometimes bit 1 of the RTSR (RTSR_HZ) will wake up 1, which means an
360 * interrupt pending, even though interrupts were never enabled.
361 * In this case, this bit it must be reset before enabling
362 * interruptions to avoid a nonexistent interrupt to occur.
363 *
364 * In principle, the same problem would apply to bit 0, although it has
365 * never been observed to happen.
366 *
367 * This issue is addressed both here and in sa1100_rtc_interrupt().
368 * If the issue is not addressed here, in the times when the processor
369 * wakes up with the bit set there will be one spurious interrupt.
370 *
371 * The issue is also dealt with in sa1100_rtc_interrupt() to be on the
372 * safe side, once the condition that lead to this strange
373 * initialization is unknown and could in principle happen during
374 * normal processing.
375 *
376 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to
377 * the corresponding bits in RTSR. */
Jett.Zhou7cea0062011-11-30 12:26:23 +0800378 rtc_writel(sa1100_rtc, RTSR, (RTSR_AL | RTSR_HZ));
Marcelo Roberto Jimenez7decaa52010-10-18 22:35:54 +0100379
Richard Purdiee842f1c2006-03-27 01:16:46 -0800380 return 0;
Jett.Zhou7cea0062011-11-30 12:26:23 +0800381
382err_rtc_reg:
383err_clk:
384 iounmap(sa1100_rtc->base);
385err_ress:
386err_map:
387 kfree(sa1100_rtc);
388 return ret;
Richard Purdiee842f1c2006-03-27 01:16:46 -0800389}
390
391static int sa1100_rtc_remove(struct platform_device *pdev)
392{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800393 struct sa1100_rtc *sa1100_rtc = platform_get_drvdata(pdev);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800394
Jett.Zhou7cea0062011-11-30 12:26:23 +0800395 rtc_device_unregister(sa1100_rtc->rtc);
396 clk_disable(sa1100_rtc->clk);
397 clk_unprepare(sa1100_rtc->clk);
398 iounmap(sa1100_rtc->base);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800399 return 0;
400}
401
Russell King6bc54e62007-11-12 22:49:58 +0000402#ifdef CONFIG_PM
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800403static int sa1100_rtc_suspend(struct device *dev)
Russell King6bc54e62007-11-12 22:49:58 +0000404{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800405 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
406
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800407 if (device_may_wakeup(dev))
Jett.Zhou7cea0062011-11-30 12:26:23 +0800408 enable_irq_wake(sa1100_rtc->irq_Alrm);
Russell King6bc54e62007-11-12 22:49:58 +0000409 return 0;
410}
411
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800412static int sa1100_rtc_resume(struct device *dev)
Russell King6bc54e62007-11-12 22:49:58 +0000413{
Jett.Zhou7cea0062011-11-30 12:26:23 +0800414 struct sa1100_rtc *sa1100_rtc = dev_get_drvdata(dev);
415
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800416 if (device_may_wakeup(dev))
Jett.Zhou7cea0062011-11-30 12:26:23 +0800417 disable_irq_wake(sa1100_rtc->irq_Alrm);
Russell King6bc54e62007-11-12 22:49:58 +0000418 return 0;
419}
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800420
Alexey Dobriyan47145212009-12-14 18:00:08 -0800421static const struct dev_pm_ops sa1100_rtc_pm_ops = {
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800422 .suspend = sa1100_rtc_suspend,
423 .resume = sa1100_rtc_resume,
424};
Russell King6bc54e62007-11-12 22:49:58 +0000425#endif
426
Richard Purdiee842f1c2006-03-27 01:16:46 -0800427static struct platform_driver sa1100_rtc_driver = {
428 .probe = sa1100_rtc_probe,
429 .remove = sa1100_rtc_remove,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800430 .driver = {
Haojian Zhuang5d027cd2009-07-21 14:31:09 +0800431 .name = "sa1100-rtc",
432#ifdef CONFIG_PM
433 .pm = &sa1100_rtc_pm_ops,
434#endif
Richard Purdiee842f1c2006-03-27 01:16:46 -0800435 },
436};
437
Axel Lin0c4eae62012-01-10 15:10:48 -0800438module_platform_driver(sa1100_rtc_driver);
Richard Purdiee842f1c2006-03-27 01:16:46 -0800439
440MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
441MODULE_DESCRIPTION("SA11x0/PXA2xx Realtime Clock Driver (RTC)");
442MODULE_LICENSE("GPL");
Kay Sieversad28a072008-04-10 21:29:25 -0700443MODULE_ALIAS("platform:sa1100-rtc");