18 #include <linux/module.h>
21 #include <linux/rtc.h>
22 #include <linux/slab.h>
28 #define ALARM_TIME_REG 0x08
29 #define ALARM_DATE_REG 0x0C
31 #define STATUS_REG 0x14
34 #define SECONDS_UNITS (0xf<<0)
35 #define SECONDS_TENS (0x7<<4)
36 #define MINUTES_UNITS (0xf<<8)
37 #define MINUTES_TENS (0x7<<12)
38 #define HOURS_UNITS (0xf<<16)
39 #define HOURS_TENS (0x3<<20)
42 #define DAYS_UNITS (0xf<<0)
43 #define DAYS_TENS (0x3<<4)
44 #define MONTHS_UNITS (0xf<<8)
45 #define MONTHS_TENS (0x1<<12)
46 #define YEARS_UNITS (0xf<<16)
47 #define YEARS_TENS (0xf<<20)
48 #define YEARS_HUNDREDS (0xf<<24)
49 #define YEARS_MILLENIUMS (0xf<<28)
52 #define SECOND_SHIFT 0x00
53 #define MINUTE_SHIFT 0x08
54 #define HOUR_SHIFT 0x10
55 #define MDAY_SHIFT 0x00
56 #define MONTH_SHIFT 0x08
57 #define YEAR_SHIFT 0x10
59 #define SECOND_MASK 0x7F
61 #define HOUR_MASK 0x3F
63 #define MONTH_MASK 0x7F
64 #define YEAR_MASK 0xFFFF
67 #define TIME_BYP (1<<9)
68 #define INT_ENABLE (1<<31)
71 #define CLK_UNCONNECTED (1<<0)
72 #define PEND_WR_TIME (1<<2)
73 #define PEND_WR_DATE (1<<3)
74 #define LOST_WR_TIME (1<<4)
75 #define LOST_WR_DATE (1<<5)
76 #define RTC_INT_MASK (1<<31)
77 #define STATUS_BUSY (PEND_WR_TIME | PEND_WR_DATE)
78 #define STATUS_FAIL (LOST_WR_TIME | LOST_WR_DATE)
97 spin_unlock_irqrestore(&config->
lock, flags);
106 spear_rtc_clear_interrupt(config);
112 static inline void spear_rtc_disable_interrupt(
struct spear_rtc_config *config)
131 spin_unlock_irqrestore(&config->
lock, flags);
142 for (count = 0; count < 80; count++) {
145 spin_unlock_irqrestore(&config->
lock, flags);
161 spin_unlock_irqrestore(&config->
lock, flags);
164 spear_rtc_clear_interrupt(config);
187 static void bcd2tm(
struct rtc_time *tm)
212 rtc_wait_not_busy(config);
243 rtc_wait_not_busy(config);
251 return is_write_complete(config);
267 rtc_wait_not_busy(config);
298 if (tm2bcd(&alm->
time) < 0)
301 rtc_wait_not_busy(config);
310 err = is_write_complete(config);
315 spear_rtc_enable_interrupt(config);
317 spear_rtc_disable_interrupt(config);
322 static int spear_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
327 spear_rtc_clear_interrupt(config);
332 spear_rtc_disable_interrupt(config);
336 spear_rtc_enable_interrupt(config);
347 .read_time = spear_rtc_read_time,
348 .set_time = spear_rtc_set_time,
349 .read_alarm = spear_rtc_read_alarm,
350 .set_alarm = spear_rtc_set_alarm,
351 .alarm_irq_enable = spear_alarm_irq_enable,
367 dev_err(&pdev->
dev,
"rtc region already claimed\n");
371 config = kzalloc(
sizeof(*config),
GFP_KERNEL);
375 goto err_release_region;
379 if (IS_ERR(config->
clk)) {
380 status = PTR_ERR(config->
clk);
392 goto err_disable_clock;
396 platform_set_drvdata(pdev, config);
400 if (IS_ERR(config->
rtc)) {
401 dev_err(&pdev->
dev,
"can't register RTC device, err %ld\n",
402 PTR_ERR(config->
rtc));
403 status = PTR_ERR(config->
rtc);
412 goto err_clear_platdata;
417 dev_err(&pdev->
dev,
"Alarm interrupt IRQ%d already \
419 goto err_clear_platdata;
422 if (!device_can_wakeup(&pdev->
dev))
428 platform_set_drvdata(pdev,
NULL);
451 spear_rtc_disable_interrupt(config);
462 platform_set_drvdata(pdev,
NULL);
477 if (device_may_wakeup(&pdev->
dev)) {
478 if (!enable_irq_wake(irq))
481 spear_rtc_disable_interrupt(config);
495 if (device_may_wakeup(&pdev->
dev)) {
497 disable_irq_wake(irq);
502 spear_rtc_enable_interrupt(config);
509 #define spear_rtc_suspend NULL
510 #define spear_rtc_resume NULL
517 spear_rtc_disable_interrupt(config);
522 static const struct of_device_id spear_rtc_id_table[] = {
530 .probe = spear_rtc_probe,
534 .shutdown = spear_rtc_shutdown,