aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-at91rm9200.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-at91rm9200.c')
-rw-r--r--drivers/rtc/rtc-at91rm9200.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 434ebc3a99dc..0a9f27e094ea 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -44,6 +44,7 @@ static DECLARE_COMPLETION(at91_rtc_updated);
44static unsigned int at91_alarm_year = AT91_RTC_EPOCH; 44static unsigned int at91_alarm_year = AT91_RTC_EPOCH;
45static void __iomem *at91_rtc_regs; 45static void __iomem *at91_rtc_regs;
46static int irq; 46static int irq;
47static u32 at91_rtc_imr;
47 48
48/* 49/*
49 * Decode time/date into rtc_time structure 50 * Decode time/date into rtc_time structure
@@ -108,9 +109,11 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
108 cr = at91_rtc_read(AT91_RTC_CR); 109 cr = at91_rtc_read(AT91_RTC_CR);
109 at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM); 110 at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM);
110 111
112 at91_rtc_imr |= AT91_RTC_ACKUPD;
111 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD); 113 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD);
112 wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */ 114 wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */
113 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); 115 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD);
116 at91_rtc_imr &= ~AT91_RTC_ACKUPD;
114 117
115 at91_rtc_write(AT91_RTC_TIMR, 118 at91_rtc_write(AT91_RTC_TIMR,
116 bin2bcd(tm->tm_sec) << 0 119 bin2bcd(tm->tm_sec) << 0
@@ -142,7 +145,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
142 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 145 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
143 tm->tm_year = at91_alarm_year - 1900; 146 tm->tm_year = at91_alarm_year - 1900;
144 147
145 alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 148 alrm->enabled = (at91_rtc_imr & AT91_RTC_ALARM)
146 ? 1 : 0; 149 ? 1 : 0;
147 150
148 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 151 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
@@ -168,6 +171,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
168 tm.tm_sec = alrm->time.tm_sec; 171 tm.tm_sec = alrm->time.tm_sec;
169 172
170 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 173 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
174 at91_rtc_imr &= ~AT91_RTC_ALARM;
171 at91_rtc_write(AT91_RTC_TIMALR, 175 at91_rtc_write(AT91_RTC_TIMALR,
172 bin2bcd(tm.tm_sec) << 0 176 bin2bcd(tm.tm_sec) << 0
173 | bin2bcd(tm.tm_min) << 8 177 | bin2bcd(tm.tm_min) << 8
@@ -180,6 +184,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
180 184
181 if (alrm->enabled) { 185 if (alrm->enabled) {
182 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 186 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
187 at91_rtc_imr |= AT91_RTC_ALARM;
183 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 188 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
184 } 189 }
185 190
@@ -196,9 +201,12 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
196 201
197 if (enabled) { 202 if (enabled) {
198 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 203 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
204 at91_rtc_imr |= AT91_RTC_ALARM;
199 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 205 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
200 } else 206 } else {
201 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 207 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
208 at91_rtc_imr &= ~AT91_RTC_ALARM;
209 }
202 210
203 return 0; 211 return 0;
204} 212}
@@ -207,12 +215,10 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
207 */ 215 */
208static int at91_rtc_proc(struct device *dev, struct seq_file *seq) 216static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
209{ 217{
210 unsigned long imr = at91_rtc_read(AT91_RTC_IMR);
211
212 seq_printf(seq, "update_IRQ\t: %s\n", 218 seq_printf(seq, "update_IRQ\t: %s\n",
213 (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); 219 (at91_rtc_imr & AT91_RTC_ACKUPD) ? "yes" : "no");
214 seq_printf(seq, "periodic_IRQ\t: %s\n", 220 seq_printf(seq, "periodic_IRQ\t: %s\n",
215 (imr & AT91_RTC_SECEV) ? "yes" : "no"); 221 (at91_rtc_imr & AT91_RTC_SECEV) ? "yes" : "no");
216 222
217 return 0; 223 return 0;
218} 224}
@@ -227,7 +233,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
227 unsigned int rtsr; 233 unsigned int rtsr;
228 unsigned long events = 0; 234 unsigned long events = 0;
229 235
230 rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read(AT91_RTC_IMR); 236 rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_imr;
231 if (rtsr) { /* this interrupt is shared! Is it ours? */ 237 if (rtsr) { /* this interrupt is shared! Is it ours? */
232 if (rtsr & AT91_RTC_ALARM) 238 if (rtsr & AT91_RTC_ALARM)
233 events |= (RTC_AF | RTC_IRQF); 239 events |= (RTC_AF | RTC_IRQF);
@@ -291,6 +297,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
291 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 297 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
292 AT91_RTC_SECEV | AT91_RTC_TIMEV | 298 AT91_RTC_SECEV | AT91_RTC_TIMEV |
293 AT91_RTC_CALEV); 299 AT91_RTC_CALEV);
300 at91_rtc_imr = 0;
294 301
295 ret = request_irq(irq, at91_rtc_interrupt, 302 ret = request_irq(irq, at91_rtc_interrupt,
296 IRQF_SHARED, 303 IRQF_SHARED,
@@ -329,6 +336,7 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
329 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 336 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
330 AT91_RTC_SECEV | AT91_RTC_TIMEV | 337 AT91_RTC_SECEV | AT91_RTC_TIMEV |
331 AT91_RTC_CALEV); 338 AT91_RTC_CALEV);
339 at91_rtc_imr = 0;
332 free_irq(irq, pdev); 340 free_irq(irq, pdev);
333 341
334 rtc_device_unregister(rtc); 342 rtc_device_unregister(rtc);
@@ -341,31 +349,35 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
341 349
342/* AT91RM9200 RTC Power management control */ 350/* AT91RM9200 RTC Power management control */
343 351
344static u32 at91_rtc_imr; 352static u32 at91_rtc_bkpimr;
353
345 354
346static int at91_rtc_suspend(struct device *dev) 355static int at91_rtc_suspend(struct device *dev)
347{ 356{
348 /* this IRQ is shared with DBGU and other hardware which isn't 357 /* this IRQ is shared with DBGU and other hardware which isn't
349 * necessarily doing PM like we are... 358 * necessarily doing PM like we are...
350 */ 359 */
351 at91_rtc_imr = at91_rtc_read(AT91_RTC_IMR) 360 at91_rtc_bkpimr = at91_rtc_imr & (AT91_RTC_ALARM|AT91_RTC_SECEV);
352 & (AT91_RTC_ALARM|AT91_RTC_SECEV); 361 if (at91_rtc_bkpimr) {
353 if (at91_rtc_imr) { 362 if (device_may_wakeup(dev)) {
354 if (device_may_wakeup(dev))
355 enable_irq_wake(irq); 363 enable_irq_wake(irq);
356 else 364 } else {
357 at91_rtc_write(AT91_RTC_IDR, at91_rtc_imr); 365 at91_rtc_write(AT91_RTC_IDR, at91_rtc_bkpimr);
358 } 366 at91_rtc_imr &= ~at91_rtc_bkpimr;
367 }
368}
359 return 0; 369 return 0;
360} 370}
361 371
362static int at91_rtc_resume(struct device *dev) 372static int at91_rtc_resume(struct device *dev)
363{ 373{
364 if (at91_rtc_imr) { 374 if (at91_rtc_bkpimr) {
365 if (device_may_wakeup(dev)) 375 if (device_may_wakeup(dev)) {
366 disable_irq_wake(irq); 376 disable_irq_wake(irq);
367 else 377 } else {
368 at91_rtc_write(AT91_RTC_IER, at91_rtc_imr); 378 at91_rtc_imr |= at91_rtc_bkpimr;
379 at91_rtc_write(AT91_RTC_IER, at91_rtc_bkpimr);
380 }
369 } 381 }
370 return 0; 382 return 0;
371} 383}