34 #include <linux/kernel.h>
35 #include <linux/module.h>
56 #define RTC_IRQMASK (RTC_PF | RTC_AF)
58 static inline int is_intr(
u8 rtc_intr)
65 static inline unsigned char vrtc_is_updating(
void)
72 spin_unlock_irqrestore(&rtc_lock, flags);
93 if (vrtc_is_updating())
103 spin_unlock_irqrestore(&rtc_lock, flags);
111 static int mrst_set_time(
struct device *dev,
struct rtc_time *time)
125 if (yrs < 72 || yrs > 138)
138 spin_unlock_irqrestore(&rtc_lock, flags);
156 t->
time.tm_mday = -1;
158 t->
time.tm_year = -1;
161 spin_lock_irq(&rtc_lock);
167 spin_unlock_irq(&rtc_lock);
175 static void mrst_checkintr(
struct mrst_rtc *mrst,
unsigned char rtc_control)
177 unsigned char rtc_intr;
185 if (is_intr(rtc_intr))
189 static void mrst_irq_enable(
struct mrst_rtc *mrst,
unsigned char mask)
198 mrst_checkintr(mrst, rtc_control);
203 mrst_checkintr(mrst, rtc_control);
206 static void mrst_irq_disable(
struct mrst_rtc *mrst,
unsigned char mask)
211 rtc_control &= ~mask;
213 mrst_checkintr(mrst, rtc_control);
219 unsigned char hrs,
min,
sec;
225 hrs = t->
time.tm_hour;
226 min = t->
time.tm_min;
227 sec = t->
time.tm_sec;
229 spin_lock_irq(&rtc_lock);
231 mrst_irq_disable(mrst,
RTC_AIE);
238 spin_unlock_irq(&rtc_lock);
244 spin_lock_irq(&rtc_lock);
246 mrst_irq_enable(mrst,
RTC_AIE);
248 spin_unlock_irq(&rtc_lock);
254 static int mrst_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
261 mrst_irq_enable(mrst,
RTC_AIE);
263 mrst_irq_disable(mrst,
RTC_AIE);
264 spin_unlock_irqrestore(&rtc_lock, flags);
269 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
275 spin_lock_irq(&rtc_lock);
278 spin_unlock_irq(&rtc_lock);
281 "periodic_IRQ\t: %s\n"
284 "periodic_freq\t: daily (not adjustable)\n",
285 (rtc_control &
RTC_PIE) ?
"on" :
"off",
286 (rtc_control &
RTC_AIE) ?
"on" :
"off");
290 #define mrst_procfs NULL
294 .read_time = mrst_read_time,
295 .set_time = mrst_set_time,
296 .read_alarm = mrst_read_alarm,
297 .set_alarm = mrst_set_alarm,
299 .alarm_irq_enable = mrst_rtc_alarm_irq_enable,
312 spin_lock(&rtc_lock);
315 spin_unlock(&rtc_lock);
318 if (is_intr(irqstat)) {
341 dev_dbg(dev,
"i/o mem already in use.\n");
359 spin_lock_irq(&rtc_lock);
362 spin_unlock_irq(&rtc_lock);
365 dev_dbg(dev,
"TODO: support more than 24-hr BCD mode\n");
372 dev_dbg(dev,
"IRQ %d is already in use, err %d\n",
386 dev_err(dev,
"rtc-mrst: unable to initialise\n");
390 static void rtc_mrst_do_shutdown(
void)
392 spin_lock_irq(&rtc_lock);
394 spin_unlock_irq(&rtc_lock);
402 rtc_mrst_do_shutdown();
425 spin_lock_irq(&rtc_lock);
430 if (device_may_wakeup(dev))
437 mrst_checkintr(mrst, tmp);
439 spin_unlock_irq(&rtc_lock);
443 enable_irq_wake(mrst->
irq);
447 (tmp & RTC_AIE) ?
", alarm may wake" :
"",
456 static inline int mrst_poweroff(
struct device *dev)
471 disable_irq_wake(mrst->
irq);
475 spin_lock_irq(&rtc_lock);
487 spin_unlock_irq(&rtc_lock);
496 #define mrst_suspend NULL
497 #define mrst_resume NULL
499 static inline int mrst_poweroff(
struct device *dev)
508 return vrtc_mrst_do_probe(&pdev->
dev,
515 rtc_mrst_do_remove(&pdev->
dev);
524 rtc_mrst_do_shutdown();
530 .probe = vrtc_mrst_platform_probe,
532 .shutdown = vrtc_mrst_platform_shutdown,