20 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
27 #include <linux/rtc.h>
31 #define TEGRA_RTC_REG_BUSY 0x004
32 #define TEGRA_RTC_REG_SECONDS 0x008
34 #define TEGRA_RTC_REG_SHADOW_SECONDS 0x00c
35 #define TEGRA_RTC_REG_MILLI_SECONDS 0x010
36 #define TEGRA_RTC_REG_SECONDS_ALARM0 0x014
37 #define TEGRA_RTC_REG_SECONDS_ALARM1 0x018
38 #define TEGRA_RTC_REG_MILLI_SECONDS_ALARM0 0x01c
39 #define TEGRA_RTC_REG_INTR_MASK 0x028
41 #define TEGRA_RTC_REG_INTR_STATUS 0x02c
44 #define TEGRA_RTC_INTR_MASK_MSEC_CDN_ALARM (1<<4)
45 #define TEGRA_RTC_INTR_MASK_SEC_CDN_ALARM (1<<3)
46 #define TEGRA_RTC_INTR_MASK_MSEC_ALARM (1<<2)
47 #define TEGRA_RTC_INTR_MASK_SEC_ALARM1 (1<<1)
48 #define TEGRA_RTC_INTR_MASK_SEC_ALARM0 (1<<0)
51 #define TEGRA_RTC_INTR_STATUS_MSEC_CDN_ALARM (1<<4)
52 #define TEGRA_RTC_INTR_STATUS_SEC_CDN_ALARM (1<<3)
53 #define TEGRA_RTC_INTR_STATUS_MSEC_ALARM (1<<2)
54 #define TEGRA_RTC_INTR_STATUS_SEC_ALARM1 (1<<1)
55 #define TEGRA_RTC_INTR_STATUS_SEC_ALARM0 (1<<0)
84 static int tegra_rtc_wait_while_busy(
struct device *
dev)
92 while (tegra_rtc_check_busy(info)) {
102 dev_err(dev,
"write failed:retry count exceeded.\n");
110 unsigned long sl_irq_flags;
123 dev_vdbg(dev,
"time read as %lu. %d/%d/%d %d:%02u:%02u\n",
149 dev_vdbg(dev,
"time set to %lu. %d/%d/%d %d:%02u:%02u\n",
160 ret = tegra_rtc_wait_while_busy(dev);
164 dev_vdbg(dev,
"time read back as %d\n",
181 alarm->
time.tm_mon = -1;
182 alarm->
time.tm_mday = -1;
183 alarm->
time.tm_year = -1;
184 alarm->
time.tm_hour = -1;
185 alarm->
time.tm_min = -1;
186 alarm->
time.tm_sec = -1;
199 static int tegra_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
203 unsigned long sl_irq_flags;
205 tegra_rtc_wait_while_busy(dev);
222 static int tegra_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alarm)
232 tegra_rtc_wait_while_busy(dev);
234 dev_vdbg(dev,
"alarm read back as %d\n",
239 tegra_rtc_alarm_irq_enable(dev, 1);
241 dev_vdbg(dev,
"alarm set as %lu. %d/%d/%d %d:%02u:%02u\n",
243 alarm->
time.tm_mon+1,
245 alarm->
time.tm_year+1900,
252 tegra_rtc_alarm_irq_enable(dev, 0);
258 static int tegra_rtc_proc(
struct device *dev,
struct seq_file *seq)
263 return seq_printf(seq,
"name\t\t: %s\n", dev_name(dev));
272 unsigned long sl_irq_flags;
277 tegra_rtc_wait_while_busy(dev);
298 .read_time = tegra_rtc_read_time,
299 .set_time = tegra_rtc_set_time,
300 .read_alarm = tegra_rtc_read_alarm,
301 .set_alarm = tegra_rtc_set_alarm,
302 .proc = tegra_rtc_proc,
303 .alarm_irq_enable = tegra_rtc_alarm_irq_enable,
320 "Unable to allocate resources for device.\n");
326 dev_err(&pdev->
dev,
"Unable to request mem region and grab IOs for device.\n");
338 platform_set_drvdata(pdev, info);
353 "Unable to register device (err=%d).\n",
360 "rtc alarm", &pdev->
dev);
363 "Unable to request interrupt for device (err=%d).\n",
368 dev_notice(&pdev->
dev,
"Tegra internal Real Time Clock\n");
384 platform_set_drvdata(pdev,
NULL);
395 tegra_rtc_wait_while_busy(dev);
399 writel(TEGRA_RTC_INTR_STATUS_SEC_ALARM0,
405 dev_vdbg(dev,
"Suspend (device_may_wakeup=%d) irq:%d\n",
409 if (device_may_wakeup(dev))
420 dev_vdbg(dev,
"Resume (device_may_wakeup=%d)\n",
421 device_may_wakeup(dev));
423 if (device_may_wakeup(dev))
433 tegra_rtc_alarm_irq_enable(&pdev->
dev, 0);
439 .shutdown = tegra_rtc_shutdown,
445 .suspend = tegra_rtc_suspend,
446 .resume = tegra_rtc_resume,
450 static int __init tegra_rtc_init(
void)
456 static void __exit tegra_rtc_exit(
void)