Skip to content

Commit 0ef1594

Browse files
Nicolas Ferretorvalds
authored andcommitted
drivers/rtc/rtc-at91rm9200.c: use a variable for storing IMR
On some revisions of AT91 SoCs, the RTC IMR register is not working. Instead of elaborating a workaround for that specific SoC or IP version, we simply use a software variable to store the Interrupt Mask Register and modify it for each enabling/disabling of an interrupt. The overhead of this is negligible anyway. The interrupt mask register (IMR) for the RTC is broken on the AT91SAM9x5 sub-family of SoCs (good overview of the members here: http://www.eewiki.net/display/linuxonarm/AT91SAM9x5 ). The "user visible effect" is the RTC doesn't work. That sub-family is less than two years old and only has devicetree (DT) support and came online circa lk 3.7 . The dust is yet to settle on the DT stuff at least for AT91 SoCs (translation: lots of stuff is still broken, so much that it is hard to know where to start). The fix in the patch is pretty simple: just shadow the silicon IMR register with a variable in the driver. Some older SoCs (pre-DT) use the the rtc-at91rm9200 driver (e.g. obviously the AT91RM9200) and they should not be impacted by the change. There shouldn't be a large volume of interrupts associated with a RTC. Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Reported-by: Douglas Gilbert <dgilbert@interlog.com> Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Cc: Ludovic Desroches <ludovic.desroches@atmel.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e66b058 commit 0ef1594

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

‎drivers/rtc/rtc-at91rm9200.c‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static DECLARE_COMPLETION(at91_rtc_updated);
4444
static unsigned int at91_alarm_year = AT91_RTC_EPOCH;
4545
static void __iomem *at91_rtc_regs;
4646
static int irq;
47+
static u32 at91_rtc_imr;
4748

4849
/*
4950
* Decode time/date into rtc_time structure
@@ -108,9 +109,11 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
108109
cr = at91_rtc_read(AT91_RTC_CR);
109110
at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM);
110111

112+
at91_rtc_imr |= AT91_RTC_ACKUPD;
111113
at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD);
112114
wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */
113115
at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD);
116+
at91_rtc_imr &= ~AT91_RTC_ACKUPD;
114117

115118
at91_rtc_write(AT91_RTC_TIMR,
116119
bin2bcd(tm->tm_sec) << 0
@@ -142,7 +145,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
142145
tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
143146
tm->tm_year = at91_alarm_year - 1900;
144147

145-
alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM)
148+
alrm->enabled = (at91_rtc_imr & AT91_RTC_ALARM)
146149
? 1 : 0;
147150

148151
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)
168171
tm.tm_sec = alrm->time.tm_sec;
169172

170173
at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
174+
at91_rtc_imr &= ~AT91_RTC_ALARM;
171175
at91_rtc_write(AT91_RTC_TIMALR,
172176
bin2bcd(tm.tm_sec) << 0
173177
| bin2bcd(tm.tm_min) << 8
@@ -180,6 +184,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
180184

181185
if (alrm->enabled) {
182186
at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
187+
at91_rtc_imr |= AT91_RTC_ALARM;
183188
at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
184189
}
185190

@@ -196,9 +201,12 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
196201

197202
if (enabled) {
198203
at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
204+
at91_rtc_imr |= AT91_RTC_ALARM;
199205
at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
200-
} else
206+
} else {
201207
at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
208+
at91_rtc_imr &= ~AT91_RTC_ALARM;
209+
}
202210

203211
return 0;
204212
}
@@ -207,12 +215,10 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
207215
*/
208216
static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
209217
{
210-
unsigned long imr = at91_rtc_read(AT91_RTC_IMR);
211-
212218
seq_printf(seq, "update_IRQ\t: %s\n",
213-
(imr & AT91_RTC_ACKUPD) ? "yes" : "no");
219+
(at91_rtc_imr & AT91_RTC_ACKUPD) ? "yes" : "no");
214220
seq_printf(seq, "periodic_IRQ\t: %s\n",
215-
(imr & AT91_RTC_SECEV) ? "yes" : "no");
221+
(at91_rtc_imr & AT91_RTC_SECEV) ? "yes" : "no");
216222

217223
return 0;
218224
}
@@ -227,7 +233,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
227233
unsigned int rtsr;
228234
unsigned long events = 0;
229235

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;
231237
if (rtsr) { /* this interrupt is shared! Is it ours? */
232238
if (rtsr & AT91_RTC_ALARM)
233239
events |= (RTC_AF | RTC_IRQF);
@@ -291,6 +297,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
291297
at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
292298
AT91_RTC_SECEV | AT91_RTC_TIMEV |
293299
AT91_RTC_CALEV);
300+
at91_rtc_imr = 0;
294301

295302
ret = request_irq(irq, at91_rtc_interrupt,
296303
IRQF_SHARED,
@@ -329,6 +336,7 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
329336
at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
330337
AT91_RTC_SECEV | AT91_RTC_TIMEV |
331338
AT91_RTC_CALEV);
339+
at91_rtc_imr = 0;
332340
free_irq(irq, pdev);
333341

334342
rtc_device_unregister(rtc);
@@ -341,31 +349,35 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
341349

342350
/* AT91RM9200 RTC Power management control */
343351

344-
static u32 at91_rtc_imr;
352+
static u32 at91_rtc_bkpimr;
353+
345354

346355
static int at91_rtc_suspend(struct device *dev)
347356
{
348357
/* this IRQ is shared with DBGU and other hardware which isn't
349358
* necessarily doing PM like we are...
350359
*/
351-
at91_rtc_imr = at91_rtc_read(AT91_RTC_IMR)
352-
& (AT91_RTC_ALARM|AT91_RTC_SECEV);
353-
if (at91_rtc_imr) {
354-
if (device_may_wakeup(dev))
360+
at91_rtc_bkpimr = at91_rtc_imr & (AT91_RTC_ALARM|AT91_RTC_SECEV);
361+
if (at91_rtc_bkpimr) {
362+
if (device_may_wakeup(dev)) {
355363
enable_irq_wake(irq);
356-
else
357-
at91_rtc_write(AT91_RTC_IDR, at91_rtc_imr);
358-
}
364+
} else {
365+
at91_rtc_write(AT91_RTC_IDR, at91_rtc_bkpimr);
366+
at91_rtc_imr &= ~at91_rtc_bkpimr;
367+
}
368+
}
359369
return 0;
360370
}
361371

362372
static int at91_rtc_resume(struct device *dev)
363373
{
364-
if (at91_rtc_imr) {
365-
if (device_may_wakeup(dev))
374+
if (at91_rtc_bkpimr) {
375+
if (device_may_wakeup(dev)) {
366376
disable_irq_wake(irq);
367-
else
368-
at91_rtc_write(AT91_RTC_IER, at91_rtc_imr);
377+
} else {
378+
at91_rtc_imr |= at91_rtc_bkpimr;
379+
at91_rtc_write(AT91_RTC_IER, at91_rtc_bkpimr);
380+
}
369381
}
370382
return 0;
371383
}

‎drivers/rtc/rtc-at91rm9200.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */
6565
#define AT91_RTC_IER 0x20 /* Interrupt Enable Register */
6666
#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */
67-
#define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */
6867

6968
#define AT91_RTC_VER 0x2c /* Valid Entry Register */
7069
#define AT91_RTC_NVTIM (1 << 0) /* Non valid Time */

0 commit comments

Comments
 (0)