Lines Matching full:rtc

7  * Based on rtc-at91rm9200.c by Rick Bronson
20 #include <linux/rtc.h>
38 * The RTC's value is the RTT counter plus that offset. The RTC's alarm
42 * choose from, or a "real" RTC module. All systems have multiple GPBR
43 * registers available, likewise usable for more than "RTC" support.
81 #define rtt_readl(rtc, field) \ argument
82 readl((rtc)->rtt + AT91_RTT_ ## field)
83 #define rtt_writel(rtc, field, val) \ argument
84 writel((val), (rtc)->rtt + AT91_RTT_ ## field)
86 static inline unsigned int gpbr_readl(struct sam9_rtc *rtc) in gpbr_readl() argument
90 regmap_read(rtc->gpbr, rtc->gpbr_offset, &val); in gpbr_readl()
95 static inline void gpbr_writel(struct sam9_rtc *rtc, unsigned int val) in gpbr_writel() argument
97 regmap_write(rtc->gpbr, rtc->gpbr_offset, val); in gpbr_writel()
101 * Read current time and date in RTC
105 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_readtime() local
110 offset = gpbr_readl(rtc); in at91_rtc_readtime()
115 secs = rtt_readl(rtc, VR); in at91_rtc_readtime()
116 secs2 = rtt_readl(rtc, VR); in at91_rtc_readtime()
118 secs = rtt_readl(rtc, VR); in at91_rtc_readtime()
128 * Set current time and date in RTC
132 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_settime() local
140 mr = rtt_readl(rtc, MR); in at91_rtc_settime()
143 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); in at91_rtc_settime()
146 offset = gpbr_readl(rtc); in at91_rtc_settime()
150 gpbr_writel(rtc, secs); in at91_rtc_settime()
153 alarm = rtt_readl(rtc, AR); in at91_rtc_settime()
166 rtt_writel(rtc, AR, alarm); in at91_rtc_settime()
170 rtt_writel(rtc, MR, mr | AT91_RTT_RTTRST); in at91_rtc_settime()
177 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_readalarm() local
179 u32 alarm = rtt_readl(rtc, AR); in at91_rtc_readalarm()
182 offset = gpbr_readl(rtc); in at91_rtc_readalarm()
192 if (rtt_readl(rtc, MR) & AT91_RTT_ALMIEN) in at91_rtc_readalarm()
201 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_setalarm() local
209 offset = gpbr_readl(rtc); in at91_rtc_setalarm()
214 mr = rtt_readl(rtc, MR); in at91_rtc_setalarm()
215 rtt_writel(rtc, MR, mr & ~AT91_RTT_ALMIEN); in at91_rtc_setalarm()
219 rtt_writel(rtc, AR, ALARM_DISABLED); in at91_rtc_setalarm()
224 rtt_writel(rtc, AR, secs - offset); in at91_rtc_setalarm()
226 rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN); in at91_rtc_setalarm()
235 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_alarm_irq_enable() local
236 u32 mr = rtt_readl(rtc, MR); in at91_rtc_alarm_irq_enable()
240 rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN); in at91_rtc_alarm_irq_enable()
242 rtt_writel(rtc, MR, mr & ~AT91_RTT_ALMIEN); in at91_rtc_alarm_irq_enable()
247 * Provide additional RTC information in /proc/driver/rtc
251 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_proc() local
252 u32 mr = rtt_readl(rtc, MR); in at91_rtc_proc()
259 static irqreturn_t at91_rtc_cache_events(struct sam9_rtc *rtc) in at91_rtc_cache_events() argument
266 mr = rtt_readl(rtc, MR) & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); in at91_rtc_cache_events()
267 sr = rtt_readl(rtc, SR) & (mr >> 16); in at91_rtc_cache_events()
273 rtc->events |= (RTC_AF | RTC_IRQF); in at91_rtc_cache_events()
277 rtc->events |= (RTC_UF | RTC_IRQF); in at91_rtc_cache_events()
282 static void at91_rtc_flush_events(struct sam9_rtc *rtc) in at91_rtc_flush_events() argument
284 if (!rtc->events) in at91_rtc_flush_events()
287 rtc_update_irq(rtc->rtcdev, 1, rtc->events); in at91_rtc_flush_events()
288 rtc->events = 0; in at91_rtc_flush_events()
291 rtc->events >> 8, rtc->events & 0x000000FF); in at91_rtc_flush_events()
295 * IRQ handler for the RTC
299 struct sam9_rtc *rtc = _rtc; in at91_rtc_interrupt() local
302 spin_lock(&rtc->lock); in at91_rtc_interrupt()
304 ret = at91_rtc_cache_events(rtc); in at91_rtc_interrupt()
307 if (rtc->suspended) { in at91_rtc_interrupt()
309 rtt_writel(rtc, MR, in at91_rtc_interrupt()
310 rtt_readl(rtc, MR) & in at91_rtc_interrupt()
315 at91_rtc_flush_events(rtc); in at91_rtc_interrupt()
318 spin_unlock(&rtc->lock); in at91_rtc_interrupt()
333 * Initialize and install RTC driver
337 struct sam9_rtc *rtc; in at91_rtc_probe() local
347 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); in at91_rtc_probe()
348 if (!rtc) in at91_rtc_probe()
351 spin_lock_init(&rtc->lock); in at91_rtc_probe()
352 rtc->irq = irq; in at91_rtc_probe()
358 platform_set_drvdata(pdev, rtc); in at91_rtc_probe()
360 rtc->rtt = devm_platform_ioremap_resource(pdev, 0); in at91_rtc_probe()
361 if (IS_ERR(rtc->rtt)) in at91_rtc_probe()
362 return PTR_ERR(rtc->rtt); in at91_rtc_probe()
365 "atmel,rtt-rtc-time-reg", 1, 0, in at91_rtc_probe()
370 rtc->gpbr = syscon_node_to_regmap(args.np); in at91_rtc_probe()
372 rtc->gpbr_offset = args.args[0]; in at91_rtc_probe()
373 if (IS_ERR(rtc->gpbr)) { in at91_rtc_probe()
378 rtc->sclk = devm_clk_get(&pdev->dev, NULL); in at91_rtc_probe()
379 if (IS_ERR(rtc->sclk)) in at91_rtc_probe()
380 return PTR_ERR(rtc->sclk); in at91_rtc_probe()
382 ret = clk_prepare_enable(rtc->sclk); in at91_rtc_probe()
388 sclk_rate = clk_get_rate(rtc->sclk); in at91_rtc_probe()
395 mr = rtt_readl(rtc, MR); in at91_rtc_probe()
400 gpbr_writel(rtc, 0); in at91_rtc_probe()
405 rtt_writel(rtc, MR, mr); in at91_rtc_probe()
407 rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev); in at91_rtc_probe()
408 if (IS_ERR(rtc->rtcdev)) { in at91_rtc_probe()
409 ret = PTR_ERR(rtc->rtcdev); in at91_rtc_probe()
413 rtc->rtcdev->ops = &at91_rtc_ops; in at91_rtc_probe()
414 rtc->rtcdev->range_max = U32_MAX; in at91_rtc_probe()
417 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, in at91_rtc_probe()
419 dev_name(&rtc->rtcdev->dev), rtc); in at91_rtc_probe()
421 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); in at91_rtc_probe()
428 * clock, discrete RTC, etc in at91_rtc_probe()
431 if (gpbr_readl(rtc) == 0) in at91_rtc_probe()
433 dev_name(&rtc->rtcdev->dev)); in at91_rtc_probe()
435 return devm_rtc_register_device(rtc->rtcdev); in at91_rtc_probe()
438 clk_disable_unprepare(rtc->sclk); in at91_rtc_probe()
444 * Disable and remove the RTC driver
448 struct sam9_rtc *rtc = platform_get_drvdata(pdev); in at91_rtc_remove() local
449 u32 mr = rtt_readl(rtc, MR); in at91_rtc_remove()
452 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); in at91_rtc_remove()
454 clk_disable_unprepare(rtc->sclk); in at91_rtc_remove()
459 struct sam9_rtc *rtc = platform_get_drvdata(pdev); in at91_rtc_shutdown() local
460 u32 mr = rtt_readl(rtc, MR); in at91_rtc_shutdown()
462 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); in at91_rtc_shutdown()
463 rtt_writel(rtc, MR, mr & ~rtc->imr); in at91_rtc_shutdown()
468 /* AT91SAM9 RTC Power management control */
472 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_suspend() local
473 u32 mr = rtt_readl(rtc, MR); in at91_rtc_suspend()
479 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); in at91_rtc_suspend()
480 if (rtc->imr) { in at91_rtc_suspend()
484 enable_irq_wake(rtc->irq); in at91_rtc_suspend()
485 spin_lock_irqsave(&rtc->lock, flags); in at91_rtc_suspend()
486 rtc->suspended = true; in at91_rtc_suspend()
487 spin_unlock_irqrestore(&rtc->lock, flags); in at91_rtc_suspend()
490 rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); in at91_rtc_suspend()
492 rtt_writel(rtc, MR, mr & ~rtc->imr); in at91_rtc_suspend()
501 struct sam9_rtc *rtc = dev_get_drvdata(dev); in at91_rtc_resume() local
504 if (rtc->imr) { in at91_rtc_resume()
508 disable_irq_wake(rtc->irq); in at91_rtc_resume()
509 mr = rtt_readl(rtc, MR); in at91_rtc_resume()
510 rtt_writel(rtc, MR, mr | rtc->imr); in at91_rtc_resume()
512 spin_lock_irqsave(&rtc->lock, flags); in at91_rtc_resume()
513 rtc->suspended = false; in at91_rtc_resume()
514 at91_rtc_cache_events(rtc); in at91_rtc_resume()
515 at91_rtc_flush_events(rtc); in at91_rtc_resume()
516 spin_unlock_irqrestore(&rtc->lock, flags); in at91_rtc_resume()
536 .name = "rtc-at91sam9",
545 MODULE_DESCRIPTION("RTC driver for Atmel AT91SAM9x");