15 #include <linux/kernel.h>
17 #include <linux/module.h>
20 #include <linux/rtc.h>
41 #define OMAP_RTC_BASE 0xfffb4800
44 #define OMAP_RTC_SECONDS_REG 0x00
45 #define OMAP_RTC_MINUTES_REG 0x04
46 #define OMAP_RTC_HOURS_REG 0x08
47 #define OMAP_RTC_DAYS_REG 0x0C
48 #define OMAP_RTC_MONTHS_REG 0x10
49 #define OMAP_RTC_YEARS_REG 0x14
50 #define OMAP_RTC_WEEKS_REG 0x18
52 #define OMAP_RTC_ALARM_SECONDS_REG 0x20
53 #define OMAP_RTC_ALARM_MINUTES_REG 0x24
54 #define OMAP_RTC_ALARM_HOURS_REG 0x28
55 #define OMAP_RTC_ALARM_DAYS_REG 0x2c
56 #define OMAP_RTC_ALARM_MONTHS_REG 0x30
57 #define OMAP_RTC_ALARM_YEARS_REG 0x34
59 #define OMAP_RTC_CTRL_REG 0x40
60 #define OMAP_RTC_STATUS_REG 0x44
61 #define OMAP_RTC_INTERRUPTS_REG 0x48
63 #define OMAP_RTC_COMP_LSB_REG 0x4c
64 #define OMAP_RTC_COMP_MSB_REG 0x50
65 #define OMAP_RTC_OSC_REG 0x54
68 #define OMAP_RTC_CTRL_SPLIT (1<<7)
69 #define OMAP_RTC_CTRL_DISABLE (1<<6)
70 #define OMAP_RTC_CTRL_SET_32_COUNTER (1<<5)
71 #define OMAP_RTC_CTRL_TEST (1<<4)
72 #define OMAP_RTC_CTRL_MODE_12_24 (1<<3)
73 #define OMAP_RTC_CTRL_AUTO_COMP (1<<2)
74 #define OMAP_RTC_CTRL_ROUND_30S (1<<1)
75 #define OMAP_RTC_CTRL_STOP (1<<0)
78 #define OMAP_RTC_STATUS_POWER_UP (1<<7)
79 #define OMAP_RTC_STATUS_ALARM (1<<6)
80 #define OMAP_RTC_STATUS_1D_EVENT (1<<5)
81 #define OMAP_RTC_STATUS_1H_EVENT (1<<4)
82 #define OMAP_RTC_STATUS_1M_EVENT (1<<3)
83 #define OMAP_RTC_STATUS_1S_EVENT (1<<2)
84 #define OMAP_RTC_STATUS_RUN (1<<1)
85 #define OMAP_RTC_STATUS_BUSY (1<<0)
88 #define OMAP_RTC_INTERRUPTS_IT_ALARM (1<<3)
89 #define OMAP_RTC_INTERRUPTS_IT_TIMER (1<<2)
93 #define rtc_read(addr) __raw_readb(rtc_base + (addr))
94 #define rtc_write(val, addr) __raw_writeb(val, rtc_base + (addr))
101 static void rtc_wait_not_busy(
void)
107 for (count = 0; count < 50; count++) {
138 static int omap_rtc_alarm_irq_enable(
struct device *
dev,
unsigned int enabled)
177 static void bcd2tm(
struct rtc_time *tm)
189 static int omap_rtc_read_time(
struct device *dev,
struct rtc_time *tm)
208 static int omap_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
252 if (tm2bcd(&alm->
time) < 0)
278 .read_time = omap_rtc_read_time,
279 .set_time = omap_rtc_set_time,
280 .read_alarm = omap_rtc_read_alarm,
281 .set_alarm = omap_rtc_set_alarm,
282 .alarm_irq_enable = omap_rtc_alarm_irq_enable,
285 static int omap_rtc_alarm;
286 static int omap_rtc_timer;
295 if (omap_rtc_timer <= 0) {
301 if (omap_rtc_alarm <= 0) {
308 pr_debug(
"%s: RTC resource data missing\n", pdev->
name);
314 pr_debug(
"%s: RTC registers at %08x are not free\n",
321 pr_debug(
"%s: RTC registers can't be mapped\n", pdev->
name);
328 pr_debug(
"%s: can't register RTC device, err %ld\n",
329 pdev->
name, PTR_ERR(rtc));
332 platform_set_drvdata(pdev, rtc);
343 pr_info(
"%s: RTC power up reset detected\n",
347 if (reg & (
u8) OMAP_RTC_STATUS_ALARM)
352 dev_name(&rtc->
dev), rtc)) {
353 pr_debug(
"%s: RTC timer interrupt IRQ%d already claimed\n",
354 pdev->
name, omap_rtc_timer);
357 if ((omap_rtc_timer != omap_rtc_alarm) &&
359 dev_name(&rtc->
dev), rtc))) {
360 pr_debug(
"%s: RTC alarm interrupt IRQ%d already claimed\n",
361 pdev->
name, omap_rtc_alarm);
409 struct rtc_device *rtc = platform_get_drvdata(pdev);
419 if (omap_rtc_timer != omap_rtc_alarm)
440 if (device_may_wakeup(&pdev->
dev))
441 enable_irq_wake(omap_rtc_alarm);
450 if (device_may_wakeup(&pdev->
dev))
451 disable_irq_wake(omap_rtc_alarm);
458 #define omap_rtc_suspend NULL
459 #define omap_rtc_resume NULL
469 .remove =
__exit_p(omap_rtc_remove),
472 .shutdown = omap_rtc_shutdown,
479 static int __init rtc_init(
void)
485 static void __exit rtc_exit(
void)