rtc-omap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * TI OMAP1 Real Time Clock interface for Linux
  3. *
  4. * Copyright (C) 2003 MontaVista Software, Inc.
  5. * Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com>
  6. *
  7. * Copyright (C) 2006 David Brownell (new RTC framework)
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/ioport.h>
  18. #include <linux/delay.h>
  19. #include <linux/rtc.h>
  20. #include <linux/bcd.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/of.h>
  23. #include <linux/of_device.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/io.h>
  26. /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock
  27. * with century-range alarm matching, driven by the 32kHz clock.
  28. *
  29. * The main user-visible ways it differs from PC RTCs are by omitting
  30. * "don't care" alarm fields and sub-second periodic IRQs, and having
  31. * an autoadjust mechanism to calibrate to the true oscillator rate.
  32. *
  33. * Board-specific wiring options include using split power mode with
  34. * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset),
  35. * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from
  36. * low power modes) for OMAP1 boards (OMAP-L138 has this built into
  37. * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment.
  38. */
  39. #define DRIVER_NAME "omap_rtc"
  40. #define OMAP_RTC_BASE 0xfffb4800
  41. /* RTC registers */
  42. #define OMAP_RTC_SECONDS_REG 0x00
  43. #define OMAP_RTC_MINUTES_REG 0x04
  44. #define OMAP_RTC_HOURS_REG 0x08
  45. #define OMAP_RTC_DAYS_REG 0x0C
  46. #define OMAP_RTC_MONTHS_REG 0x10
  47. #define OMAP_RTC_YEARS_REG 0x14
  48. #define OMAP_RTC_WEEKS_REG 0x18
  49. #define OMAP_RTC_ALARM_SECONDS_REG 0x20
  50. #define OMAP_RTC_ALARM_MINUTES_REG 0x24
  51. #define OMAP_RTC_ALARM_HOURS_REG 0x28
  52. #define OMAP_RTC_ALARM_DAYS_REG 0x2c
  53. #define OMAP_RTC_ALARM_MONTHS_REG 0x30
  54. #define OMAP_RTC_ALARM_YEARS_REG 0x34
  55. #define OMAP_RTC_CTRL_REG 0x40
  56. #define OMAP_RTC_STATUS_REG 0x44
  57. #define OMAP_RTC_INTERRUPTS_REG 0x48
  58. #define OMAP_RTC_COMP_LSB_REG 0x4c
  59. #define OMAP_RTC_COMP_MSB_REG 0x50
  60. #define OMAP_RTC_OSC_REG 0x54
  61. #define OMAP_RTC_KICK0_REG 0x6c
  62. #define OMAP_RTC_KICK1_REG 0x70
  63. #define OMAP_RTC_IRQWAKEEN 0x7c
  64. /* OMAP_RTC_CTRL_REG bit fields: */
  65. #define OMAP_RTC_CTRL_SPLIT BIT(7)
  66. #define OMAP_RTC_CTRL_DISABLE BIT(6)
  67. #define OMAP_RTC_CTRL_SET_32_COUNTER BIT(5)
  68. #define OMAP_RTC_CTRL_TEST BIT(4)
  69. #define OMAP_RTC_CTRL_MODE_12_24 BIT(3)
  70. #define OMAP_RTC_CTRL_AUTO_COMP BIT(2)
  71. #define OMAP_RTC_CTRL_ROUND_30S BIT(1)
  72. #define OMAP_RTC_CTRL_STOP BIT(0)
  73. /* OMAP_RTC_STATUS_REG bit fields: */
  74. #define OMAP_RTC_STATUS_POWER_UP BIT(7)
  75. #define OMAP_RTC_STATUS_ALARM BIT(6)
  76. #define OMAP_RTC_STATUS_1D_EVENT BIT(5)
  77. #define OMAP_RTC_STATUS_1H_EVENT BIT(4)
  78. #define OMAP_RTC_STATUS_1M_EVENT BIT(3)
  79. #define OMAP_RTC_STATUS_1S_EVENT BIT(2)
  80. #define OMAP_RTC_STATUS_RUN BIT(1)
  81. #define OMAP_RTC_STATUS_BUSY BIT(0)
  82. /* OMAP_RTC_INTERRUPTS_REG bit fields: */
  83. #define OMAP_RTC_INTERRUPTS_IT_ALARM BIT(3)
  84. #define OMAP_RTC_INTERRUPTS_IT_TIMER BIT(2)
  85. /* OMAP_RTC_OSC_REG bit fields: */
  86. #define OMAP_RTC_OSC_32KCLK_EN BIT(6)
  87. /* OMAP_RTC_IRQWAKEEN bit fields: */
  88. #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1)
  89. /* OMAP_RTC_KICKER values */
  90. #define KICK0_VALUE 0x83e70b13
  91. #define KICK1_VALUE 0x95a4f1e0
  92. #define OMAP_RTC_HAS_KICKER BIT(0)
  93. /*
  94. * Few RTC IP revisions has special WAKE-EN Register to enable Wakeup
  95. * generation for event Alarm.
  96. */
  97. #define OMAP_RTC_HAS_IRQWAKEEN BIT(1)
  98. /*
  99. * Some RTC IP revisions (like those in AM335x and DRA7x) need
  100. * the 32KHz clock to be explicitly enabled.
  101. */
  102. #define OMAP_RTC_HAS_32KCLK_EN BIT(2)
  103. static void __iomem *rtc_base;
  104. #define rtc_read(addr) readb(rtc_base + (addr))
  105. #define rtc_write(val, addr) writeb(val, rtc_base + (addr))
  106. #define rtc_writel(val, addr) writel(val, rtc_base + (addr))
  107. /* we rely on the rtc framework to handle locking (rtc->ops_lock),
  108. * so the only other requirement is that register accesses which
  109. * require BUSY to be clear are made with IRQs locally disabled
  110. */
  111. static void rtc_wait_not_busy(void)
  112. {
  113. int count = 0;
  114. u8 status;
  115. /* BUSY may stay active for 1/32768 second (~30 usec) */
  116. for (count = 0; count < 50; count++) {
  117. status = rtc_read(OMAP_RTC_STATUS_REG);
  118. if ((status & (u8)OMAP_RTC_STATUS_BUSY) == 0)
  119. break;
  120. udelay(1);
  121. }
  122. /* now we have ~15 usec to read/write various registers */
  123. }
  124. static irqreturn_t rtc_irq(int irq, void *rtc)
  125. {
  126. unsigned long events = 0;
  127. u8 irq_data;
  128. irq_data = rtc_read(OMAP_RTC_STATUS_REG);
  129. /* alarm irq? */
  130. if (irq_data & OMAP_RTC_STATUS_ALARM) {
  131. rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
  132. events |= RTC_IRQF | RTC_AF;
  133. }
  134. /* 1/sec periodic/update irq? */
  135. if (irq_data & OMAP_RTC_STATUS_1S_EVENT)
  136. events |= RTC_IRQF | RTC_UF;
  137. rtc_update_irq(rtc, 1, events);
  138. return IRQ_HANDLED;
  139. }
  140. static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
  141. {
  142. u8 reg, irqwake_reg = 0;
  143. struct platform_device *pdev = to_platform_device(dev);
  144. const struct platform_device_id *id_entry =
  145. platform_get_device_id(pdev);
  146. local_irq_disable();
  147. rtc_wait_not_busy();
  148. reg = rtc_read(OMAP_RTC_INTERRUPTS_REG);
  149. if (id_entry->driver_data & OMAP_RTC_HAS_IRQWAKEEN)
  150. irqwake_reg = rtc_read(OMAP_RTC_IRQWAKEEN);
  151. if (enabled) {
  152. reg |= OMAP_RTC_INTERRUPTS_IT_ALARM;
  153. irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
  154. } else {
  155. reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM;
  156. irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
  157. }
  158. rtc_wait_not_busy();
  159. rtc_write(reg, OMAP_RTC_INTERRUPTS_REG);
  160. if (id_entry->driver_data & OMAP_RTC_HAS_IRQWAKEEN)
  161. rtc_write(irqwake_reg, OMAP_RTC_IRQWAKEEN);
  162. local_irq_enable();
  163. return 0;
  164. }
  165. /* this hardware doesn't support "don't care" alarm fields */
  166. static int tm2bcd(struct rtc_time *tm)
  167. {
  168. if (rtc_valid_tm(tm) != 0)
  169. return -EINVAL;
  170. tm->tm_sec = bin2bcd(tm->tm_sec);
  171. tm->tm_min = bin2bcd(tm->tm_min);
  172. tm->tm_hour = bin2bcd(tm->tm_hour);
  173. tm->tm_mday = bin2bcd(tm->tm_mday);
  174. tm->tm_mon = bin2bcd(tm->tm_mon + 1);
  175. /* epoch == 1900 */
  176. if (tm->tm_year < 100 || tm->tm_year > 199)
  177. return -EINVAL;
  178. tm->tm_year = bin2bcd(tm->tm_year - 100);
  179. return 0;
  180. }
  181. static void bcd2tm(struct rtc_time *tm)
  182. {
  183. tm->tm_sec = bcd2bin(tm->tm_sec);
  184. tm->tm_min = bcd2bin(tm->tm_min);
  185. tm->tm_hour = bcd2bin(tm->tm_hour);
  186. tm->tm_mday = bcd2bin(tm->tm_mday);
  187. tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
  188. /* epoch == 1900 */
  189. tm->tm_year = bcd2bin(tm->tm_year) + 100;
  190. }
  191. static int omap_rtc_read_time(struct device *dev, struct rtc_time *tm)
  192. {
  193. /* we don't report wday/yday/isdst ... */
  194. local_irq_disable();
  195. rtc_wait_not_busy();
  196. tm->tm_sec = rtc_read(OMAP_RTC_SECONDS_REG);
  197. tm->tm_min = rtc_read(OMAP_RTC_MINUTES_REG);
  198. tm->tm_hour = rtc_read(OMAP_RTC_HOURS_REG);
  199. tm->tm_mday = rtc_read(OMAP_RTC_DAYS_REG);
  200. tm->tm_mon = rtc_read(OMAP_RTC_MONTHS_REG);
  201. tm->tm_year = rtc_read(OMAP_RTC_YEARS_REG);
  202. local_irq_enable();
  203. bcd2tm(tm);
  204. return 0;
  205. }
  206. static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm)
  207. {
  208. if (tm2bcd(tm) < 0)
  209. return -EINVAL;
  210. local_irq_disable();
  211. rtc_wait_not_busy();
  212. rtc_write(tm->tm_year, OMAP_RTC_YEARS_REG);
  213. rtc_write(tm->tm_mon, OMAP_RTC_MONTHS_REG);
  214. rtc_write(tm->tm_mday, OMAP_RTC_DAYS_REG);
  215. rtc_write(tm->tm_hour, OMAP_RTC_HOURS_REG);
  216. rtc_write(tm->tm_min, OMAP_RTC_MINUTES_REG);
  217. rtc_write(tm->tm_sec, OMAP_RTC_SECONDS_REG);
  218. local_irq_enable();
  219. return 0;
  220. }
  221. static int omap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
  222. {
  223. local_irq_disable();
  224. rtc_wait_not_busy();
  225. alm->time.tm_sec = rtc_read(OMAP_RTC_ALARM_SECONDS_REG);
  226. alm->time.tm_min = rtc_read(OMAP_RTC_ALARM_MINUTES_REG);
  227. alm->time.tm_hour = rtc_read(OMAP_RTC_ALARM_HOURS_REG);
  228. alm->time.tm_mday = rtc_read(OMAP_RTC_ALARM_DAYS_REG);
  229. alm->time.tm_mon = rtc_read(OMAP_RTC_ALARM_MONTHS_REG);
  230. alm->time.tm_year = rtc_read(OMAP_RTC_ALARM_YEARS_REG);
  231. local_irq_enable();
  232. bcd2tm(&alm->time);
  233. alm->enabled = !!(rtc_read(OMAP_RTC_INTERRUPTS_REG)
  234. & OMAP_RTC_INTERRUPTS_IT_ALARM);
  235. return 0;
  236. }
  237. static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
  238. {
  239. u8 reg, irqwake_reg = 0;
  240. struct platform_device *pdev = to_platform_device(dev);
  241. const struct platform_device_id *id_entry =
  242. platform_get_device_id(pdev);
  243. if (tm2bcd(&alm->time) < 0)
  244. return -EINVAL;
  245. local_irq_disable();
  246. rtc_wait_not_busy();
  247. rtc_write(alm->time.tm_year, OMAP_RTC_ALARM_YEARS_REG);
  248. rtc_write(alm->time.tm_mon, OMAP_RTC_ALARM_MONTHS_REG);
  249. rtc_write(alm->time.tm_mday, OMAP_RTC_ALARM_DAYS_REG);
  250. rtc_write(alm->time.tm_hour, OMAP_RTC_ALARM_HOURS_REG);
  251. rtc_write(alm->time.tm_min, OMAP_RTC_ALARM_MINUTES_REG);
  252. rtc_write(alm->time.tm_sec, OMAP_RTC_ALARM_SECONDS_REG);
  253. reg = rtc_read(OMAP_RTC_INTERRUPTS_REG);
  254. if (id_entry->driver_data & OMAP_RTC_HAS_IRQWAKEEN)
  255. irqwake_reg = rtc_read(OMAP_RTC_IRQWAKEEN);
  256. if (alm->enabled) {
  257. reg |= OMAP_RTC_INTERRUPTS_IT_ALARM;
  258. irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
  259. } else {
  260. reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM;
  261. irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
  262. }
  263. rtc_write(reg, OMAP_RTC_INTERRUPTS_REG);
  264. if (id_entry->driver_data & OMAP_RTC_HAS_IRQWAKEEN)
  265. rtc_write(irqwake_reg, OMAP_RTC_IRQWAKEEN);
  266. local_irq_enable();
  267. return 0;
  268. }
  269. static struct rtc_class_ops omap_rtc_ops = {
  270. .read_time = omap_rtc_read_time,
  271. .set_time = omap_rtc_set_time,
  272. .read_alarm = omap_rtc_read_alarm,
  273. .set_alarm = omap_rtc_set_alarm,
  274. .alarm_irq_enable = omap_rtc_alarm_irq_enable,
  275. };
  276. static int omap_rtc_alarm;
  277. static int omap_rtc_timer;
  278. #define OMAP_RTC_DATA_AM3352_IDX 1
  279. #define OMAP_RTC_DATA_DA830_IDX 2
  280. static struct platform_device_id omap_rtc_devtype[] = {
  281. {
  282. .name = DRIVER_NAME,
  283. },
  284. [OMAP_RTC_DATA_AM3352_IDX] = {
  285. .name = "am3352-rtc",
  286. .driver_data = OMAP_RTC_HAS_KICKER | OMAP_RTC_HAS_IRQWAKEEN |
  287. OMAP_RTC_HAS_32KCLK_EN,
  288. },
  289. [OMAP_RTC_DATA_DA830_IDX] = {
  290. .name = "da830-rtc",
  291. .driver_data = OMAP_RTC_HAS_KICKER,
  292. },
  293. {},
  294. };
  295. MODULE_DEVICE_TABLE(platform, omap_rtc_devtype);
  296. static const struct of_device_id omap_rtc_of_match[] = {
  297. { .compatible = "ti,da830-rtc",
  298. .data = &omap_rtc_devtype[OMAP_RTC_DATA_DA830_IDX],
  299. },
  300. { .compatible = "ti,am3352-rtc",
  301. .data = &omap_rtc_devtype[OMAP_RTC_DATA_AM3352_IDX],
  302. },
  303. {},
  304. };
  305. MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
  306. static int __init omap_rtc_probe(struct platform_device *pdev)
  307. {
  308. struct resource *res;
  309. struct rtc_device *rtc;
  310. u8 reg, new_ctrl;
  311. const struct platform_device_id *id_entry;
  312. const struct of_device_id *of_id;
  313. of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
  314. if (of_id)
  315. pdev->id_entry = of_id->data;
  316. id_entry = platform_get_device_id(pdev);
  317. if (!id_entry) {
  318. dev_err(&pdev->dev, "no matching device entry\n");
  319. return -ENODEV;
  320. }
  321. omap_rtc_timer = platform_get_irq(pdev, 0);
  322. if (omap_rtc_timer <= 0) {
  323. pr_debug("%s: no update irq?\n", pdev->name);
  324. return -ENOENT;
  325. }
  326. omap_rtc_alarm = platform_get_irq(pdev, 1);
  327. if (omap_rtc_alarm <= 0) {
  328. pr_debug("%s: no alarm irq?\n", pdev->name);
  329. return -ENOENT;
  330. }
  331. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  332. rtc_base = devm_ioremap_resource(&pdev->dev, res);
  333. if (IS_ERR(rtc_base))
  334. return PTR_ERR(rtc_base);
  335. /* Enable the clock/module so that we can access the registers */
  336. pm_runtime_enable(&pdev->dev);
  337. pm_runtime_get_sync(&pdev->dev);
  338. if (id_entry->driver_data & OMAP_RTC_HAS_KICKER) {
  339. rtc_writel(KICK0_VALUE, OMAP_RTC_KICK0_REG);
  340. rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG);
  341. }
  342. rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
  343. &omap_rtc_ops, THIS_MODULE);
  344. if (IS_ERR(rtc)) {
  345. pr_debug("%s: can't register RTC device, err %ld\n",
  346. pdev->name, PTR_ERR(rtc));
  347. goto fail0;
  348. }
  349. platform_set_drvdata(pdev, rtc);
  350. /* clear pending irqs, and set 1/second periodic,
  351. * which we'll use instead of update irqs
  352. */
  353. rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
  354. /* enable RTC functional clock */
  355. if (id_entry->driver_data & OMAP_RTC_HAS_32KCLK_EN)
  356. rtc_writel(OMAP_RTC_OSC_32KCLK_EN, OMAP_RTC_OSC_REG);
  357. /* clear old status */
  358. reg = rtc_read(OMAP_RTC_STATUS_REG);
  359. if (reg & (u8) OMAP_RTC_STATUS_POWER_UP) {
  360. pr_info("%s: RTC power up reset detected\n",
  361. pdev->name);
  362. rtc_write(OMAP_RTC_STATUS_POWER_UP, OMAP_RTC_STATUS_REG);
  363. }
  364. if (reg & (u8) OMAP_RTC_STATUS_ALARM)
  365. rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
  366. /* handle periodic and alarm irqs */
  367. if (devm_request_irq(&pdev->dev, omap_rtc_timer, rtc_irq, 0,
  368. dev_name(&rtc->dev), rtc)) {
  369. pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
  370. pdev->name, omap_rtc_timer);
  371. goto fail0;
  372. }
  373. if ((omap_rtc_timer != omap_rtc_alarm) &&
  374. (devm_request_irq(&pdev->dev, omap_rtc_alarm, rtc_irq, 0,
  375. dev_name(&rtc->dev), rtc))) {
  376. pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
  377. pdev->name, omap_rtc_alarm);
  378. goto fail0;
  379. }
  380. /* On boards with split power, RTC_ON_NOFF won't reset the RTC */
  381. reg = rtc_read(OMAP_RTC_CTRL_REG);
  382. if (reg & (u8) OMAP_RTC_CTRL_STOP)
  383. pr_info("%s: already running\n", pdev->name);
  384. /* force to 24 hour mode */
  385. new_ctrl = reg & (OMAP_RTC_CTRL_SPLIT|OMAP_RTC_CTRL_AUTO_COMP);
  386. new_ctrl |= OMAP_RTC_CTRL_STOP;
  387. /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE:
  388. *
  389. * - Device wake-up capability setting should come through chip
  390. * init logic. OMAP1 boards should initialize the "wakeup capable"
  391. * flag in the platform device if the board is wired right for
  392. * being woken up by RTC alarm. For OMAP-L138, this capability
  393. * is built into the SoC by the "Deep Sleep" capability.
  394. *
  395. * - Boards wired so RTC_ON_nOFF is used as the reset signal,
  396. * rather than nPWRON_RESET, should forcibly enable split
  397. * power mode. (Some chip errata report that RTC_CTRL_SPLIT
  398. * is write-only, and always reads as zero...)
  399. */
  400. device_init_wakeup(&pdev->dev, true);
  401. if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT)
  402. pr_info("%s: split power mode\n", pdev->name);
  403. if (reg != new_ctrl)
  404. rtc_write(new_ctrl, OMAP_RTC_CTRL_REG);
  405. return 0;
  406. fail0:
  407. if (id_entry->driver_data & OMAP_RTC_HAS_KICKER)
  408. rtc_writel(0, OMAP_RTC_KICK0_REG);
  409. pm_runtime_put_sync(&pdev->dev);
  410. pm_runtime_disable(&pdev->dev);
  411. return -EIO;
  412. }
  413. static int __exit omap_rtc_remove(struct platform_device *pdev)
  414. {
  415. const struct platform_device_id *id_entry =
  416. platform_get_device_id(pdev);
  417. device_init_wakeup(&pdev->dev, 0);
  418. /* leave rtc running, but disable irqs */
  419. rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
  420. if (id_entry->driver_data & OMAP_RTC_HAS_KICKER)
  421. rtc_writel(0, OMAP_RTC_KICK0_REG);
  422. /* Disable the clock/module */
  423. pm_runtime_put_sync(&pdev->dev);
  424. pm_runtime_disable(&pdev->dev);
  425. return 0;
  426. }
  427. #ifdef CONFIG_PM_SLEEP
  428. static u8 irqstat;
  429. static int omap_rtc_suspend(struct device *dev)
  430. {
  431. irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG);
  432. /* FIXME the RTC alarm is not currently acting as a wakeup event
  433. * source on some platforms, and in fact this enable() call is just
  434. * saving a flag that's never used...
  435. */
  436. if (device_may_wakeup(dev))
  437. enable_irq_wake(omap_rtc_alarm);
  438. else
  439. rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
  440. /* Disable the clock/module */
  441. pm_runtime_put_sync(dev);
  442. return 0;
  443. }
  444. static int omap_rtc_resume(struct device *dev)
  445. {
  446. /* Enable the clock/module so that we can access the registers */
  447. pm_runtime_get_sync(dev);
  448. if (device_may_wakeup(dev))
  449. disable_irq_wake(omap_rtc_alarm);
  450. else
  451. rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG);
  452. return 0;
  453. }
  454. #endif
  455. static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume);
  456. static void omap_rtc_shutdown(struct platform_device *pdev)
  457. {
  458. rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
  459. }
  460. MODULE_ALIAS("platform:omap_rtc");
  461. static struct platform_driver omap_rtc_driver = {
  462. .remove = __exit_p(omap_rtc_remove),
  463. .shutdown = omap_rtc_shutdown,
  464. .driver = {
  465. .name = DRIVER_NAME,
  466. .pm = &omap_rtc_pm_ops,
  467. .of_match_table = omap_rtc_of_match,
  468. },
  469. .id_table = omap_rtc_devtype,
  470. };
  471. module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe);
  472. MODULE_AUTHOR("George G. Davis (and others)");
  473. MODULE_LICENSE("GPL");