rtc-davinci.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * DaVinci Power Management and Real Time Clock Driver for TI platforms
  3. *
  4. * Copyright (C) 2009 Texas Instruments, Inc
  5. *
  6. * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/ioport.h>
  26. #include <linux/delay.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/rtc.h>
  29. #include <linux/bcd.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/io.h>
  32. #include <linux/slab.h>
  33. /*
  34. * The DaVinci RTC is a simple RTC with the following
  35. * Sec: 0 - 59 : BCD count
  36. * Min: 0 - 59 : BCD count
  37. * Hour: 0 - 23 : BCD count
  38. * Day: 0 - 0x7FFF(32767) : Binary count ( Over 89 years )
  39. */
  40. /* PRTC interface registers */
  41. #define DAVINCI_PRTCIF_PID 0x00
  42. #define PRTCIF_CTLR 0x04
  43. #define PRTCIF_LDATA 0x08
  44. #define PRTCIF_UDATA 0x0C
  45. #define PRTCIF_INTEN 0x10
  46. #define PRTCIF_INTFLG 0x14
  47. /* PRTCIF_CTLR bit fields */
  48. #define PRTCIF_CTLR_BUSY BIT(31)
  49. #define PRTCIF_CTLR_SIZE BIT(25)
  50. #define PRTCIF_CTLR_DIR BIT(24)
  51. #define PRTCIF_CTLR_BENU_MSB BIT(23)
  52. #define PRTCIF_CTLR_BENU_3RD_BYTE BIT(22)
  53. #define PRTCIF_CTLR_BENU_2ND_BYTE BIT(21)
  54. #define PRTCIF_CTLR_BENU_LSB BIT(20)
  55. #define PRTCIF_CTLR_BENU_MASK (0x00F00000)
  56. #define PRTCIF_CTLR_BENL_MSB BIT(19)
  57. #define PRTCIF_CTLR_BENL_3RD_BYTE BIT(18)
  58. #define PRTCIF_CTLR_BENL_2ND_BYTE BIT(17)
  59. #define PRTCIF_CTLR_BENL_LSB BIT(16)
  60. #define PRTCIF_CTLR_BENL_MASK (0x000F0000)
  61. /* PRTCIF_INTEN bit fields */
  62. #define PRTCIF_INTEN_RTCSS BIT(1)
  63. #define PRTCIF_INTEN_RTCIF BIT(0)
  64. #define PRTCIF_INTEN_MASK (PRTCIF_INTEN_RTCSS \
  65. | PRTCIF_INTEN_RTCIF)
  66. /* PRTCIF_INTFLG bit fields */
  67. #define PRTCIF_INTFLG_RTCSS BIT(1)
  68. #define PRTCIF_INTFLG_RTCIF BIT(0)
  69. #define PRTCIF_INTFLG_MASK (PRTCIF_INTFLG_RTCSS \
  70. | PRTCIF_INTFLG_RTCIF)
  71. /* PRTC subsystem registers */
  72. #define PRTCSS_RTC_INTC_EXTENA1 (0x0C)
  73. #define PRTCSS_RTC_CTRL (0x10)
  74. #define PRTCSS_RTC_WDT (0x11)
  75. #define PRTCSS_RTC_TMR0 (0x12)
  76. #define PRTCSS_RTC_TMR1 (0x13)
  77. #define PRTCSS_RTC_CCTRL (0x14)
  78. #define PRTCSS_RTC_SEC (0x15)
  79. #define PRTCSS_RTC_MIN (0x16)
  80. #define PRTCSS_RTC_HOUR (0x17)
  81. #define PRTCSS_RTC_DAY0 (0x18)
  82. #define PRTCSS_RTC_DAY1 (0x19)
  83. #define PRTCSS_RTC_AMIN (0x1A)
  84. #define PRTCSS_RTC_AHOUR (0x1B)
  85. #define PRTCSS_RTC_ADAY0 (0x1C)
  86. #define PRTCSS_RTC_ADAY1 (0x1D)
  87. #define PRTCSS_RTC_CLKC_CNT (0x20)
  88. /* PRTCSS_RTC_INTC_EXTENA1 */
  89. #define PRTCSS_RTC_INTC_EXTENA1_MASK (0x07)
  90. /* PRTCSS_RTC_CTRL bit fields */
  91. #define PRTCSS_RTC_CTRL_WDTBUS BIT(7)
  92. #define PRTCSS_RTC_CTRL_WEN BIT(6)
  93. #define PRTCSS_RTC_CTRL_WDRT BIT(5)
  94. #define PRTCSS_RTC_CTRL_WDTFLG BIT(4)
  95. #define PRTCSS_RTC_CTRL_TE BIT(3)
  96. #define PRTCSS_RTC_CTRL_TIEN BIT(2)
  97. #define PRTCSS_RTC_CTRL_TMRFLG BIT(1)
  98. #define PRTCSS_RTC_CTRL_TMMD BIT(0)
  99. /* PRTCSS_RTC_CCTRL bit fields */
  100. #define PRTCSS_RTC_CCTRL_CALBUSY BIT(7)
  101. #define PRTCSS_RTC_CCTRL_DAEN BIT(5)
  102. #define PRTCSS_RTC_CCTRL_HAEN BIT(4)
  103. #define PRTCSS_RTC_CCTRL_MAEN BIT(3)
  104. #define PRTCSS_RTC_CCTRL_ALMFLG BIT(2)
  105. #define PRTCSS_RTC_CCTRL_AIEN BIT(1)
  106. #define PRTCSS_RTC_CCTRL_CAEN BIT(0)
  107. static DEFINE_SPINLOCK(davinci_rtc_lock);
  108. struct davinci_rtc {
  109. struct rtc_device *rtc;
  110. void __iomem *base;
  111. int irq;
  112. };
  113. static inline void rtcif_write(struct davinci_rtc *davinci_rtc,
  114. u32 val, u32 addr)
  115. {
  116. writel(val, davinci_rtc->base + addr);
  117. }
  118. static inline u32 rtcif_read(struct davinci_rtc *davinci_rtc, u32 addr)
  119. {
  120. return readl(davinci_rtc->base + addr);
  121. }
  122. static inline void rtcif_wait(struct davinci_rtc *davinci_rtc)
  123. {
  124. while (rtcif_read(davinci_rtc, PRTCIF_CTLR) & PRTCIF_CTLR_BUSY)
  125. cpu_relax();
  126. }
  127. static inline void rtcss_write(struct davinci_rtc *davinci_rtc,
  128. unsigned long val, u8 addr)
  129. {
  130. rtcif_wait(davinci_rtc);
  131. rtcif_write(davinci_rtc, PRTCIF_CTLR_BENL_LSB | addr, PRTCIF_CTLR);
  132. rtcif_write(davinci_rtc, val, PRTCIF_LDATA);
  133. rtcif_wait(davinci_rtc);
  134. }
  135. static inline u8 rtcss_read(struct davinci_rtc *davinci_rtc, u8 addr)
  136. {
  137. rtcif_wait(davinci_rtc);
  138. rtcif_write(davinci_rtc, PRTCIF_CTLR_DIR | PRTCIF_CTLR_BENL_LSB | addr,
  139. PRTCIF_CTLR);
  140. rtcif_wait(davinci_rtc);
  141. return rtcif_read(davinci_rtc, PRTCIF_LDATA);
  142. }
  143. static inline void davinci_rtcss_calendar_wait(struct davinci_rtc *davinci_rtc)
  144. {
  145. while (rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL) &
  146. PRTCSS_RTC_CCTRL_CALBUSY)
  147. cpu_relax();
  148. }
  149. static irqreturn_t davinci_rtc_interrupt(int irq, void *class_dev)
  150. {
  151. struct davinci_rtc *davinci_rtc = class_dev;
  152. unsigned long events = 0;
  153. u32 irq_flg;
  154. u8 alm_irq, tmr_irq;
  155. u8 rtc_ctrl, rtc_cctrl;
  156. int ret = IRQ_NONE;
  157. irq_flg = rtcif_read(davinci_rtc, PRTCIF_INTFLG) &
  158. PRTCIF_INTFLG_RTCSS;
  159. alm_irq = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL) &
  160. PRTCSS_RTC_CCTRL_ALMFLG;
  161. tmr_irq = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL) &
  162. PRTCSS_RTC_CTRL_TMRFLG;
  163. if (irq_flg) {
  164. if (alm_irq) {
  165. events |= RTC_IRQF | RTC_AF;
  166. rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
  167. rtc_cctrl |= PRTCSS_RTC_CCTRL_ALMFLG;
  168. rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
  169. } else if (tmr_irq) {
  170. events |= RTC_IRQF | RTC_PF;
  171. rtc_ctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL);
  172. rtc_ctrl |= PRTCSS_RTC_CTRL_TMRFLG;
  173. rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
  174. }
  175. rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS,
  176. PRTCIF_INTFLG);
  177. rtc_update_irq(davinci_rtc->rtc, 1, events);
  178. ret = IRQ_HANDLED;
  179. }
  180. return ret;
  181. }
  182. static int
  183. davinci_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
  184. {
  185. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  186. u8 rtc_ctrl;
  187. unsigned long flags;
  188. int ret = 0;
  189. spin_lock_irqsave(&davinci_rtc_lock, flags);
  190. rtc_ctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL);
  191. switch (cmd) {
  192. case RTC_WIE_ON:
  193. rtc_ctrl |= PRTCSS_RTC_CTRL_WEN | PRTCSS_RTC_CTRL_WDTFLG;
  194. break;
  195. case RTC_WIE_OFF:
  196. rtc_ctrl &= ~PRTCSS_RTC_CTRL_WEN;
  197. break;
  198. default:
  199. ret = -ENOIOCTLCMD;
  200. }
  201. rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
  202. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  203. return ret;
  204. }
  205. static int convertfromdays(u16 days, struct rtc_time *tm)
  206. {
  207. int tmp_days, year, mon;
  208. for (year = 2000;; year++) {
  209. tmp_days = rtc_year_days(1, 12, year);
  210. if (days >= tmp_days)
  211. days -= tmp_days;
  212. else {
  213. for (mon = 0;; mon++) {
  214. tmp_days = rtc_month_days(mon, year);
  215. if (days >= tmp_days) {
  216. days -= tmp_days;
  217. } else {
  218. tm->tm_year = year - 1900;
  219. tm->tm_mon = mon;
  220. tm->tm_mday = days + 1;
  221. break;
  222. }
  223. }
  224. break;
  225. }
  226. }
  227. return 0;
  228. }
  229. static int convert2days(u16 *days, struct rtc_time *tm)
  230. {
  231. int i;
  232. *days = 0;
  233. /* epoch == 1900 */
  234. if (tm->tm_year < 100 || tm->tm_year > 199)
  235. return -EINVAL;
  236. for (i = 2000; i < 1900 + tm->tm_year; i++)
  237. *days += rtc_year_days(1, 12, i);
  238. *days += rtc_year_days(tm->tm_mday, tm->tm_mon, 1900 + tm->tm_year);
  239. return 0;
  240. }
  241. static int davinci_rtc_read_time(struct device *dev, struct rtc_time *tm)
  242. {
  243. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  244. u16 days = 0;
  245. u8 day0, day1;
  246. unsigned long flags;
  247. spin_lock_irqsave(&davinci_rtc_lock, flags);
  248. davinci_rtcss_calendar_wait(davinci_rtc);
  249. tm->tm_sec = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_SEC));
  250. davinci_rtcss_calendar_wait(davinci_rtc);
  251. tm->tm_min = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_MIN));
  252. davinci_rtcss_calendar_wait(davinci_rtc);
  253. tm->tm_hour = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_HOUR));
  254. davinci_rtcss_calendar_wait(davinci_rtc);
  255. day0 = rtcss_read(davinci_rtc, PRTCSS_RTC_DAY0);
  256. davinci_rtcss_calendar_wait(davinci_rtc);
  257. day1 = rtcss_read(davinci_rtc, PRTCSS_RTC_DAY1);
  258. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  259. days |= day1;
  260. days <<= 8;
  261. days |= day0;
  262. if (convertfromdays(days, tm) < 0)
  263. return -EINVAL;
  264. return 0;
  265. }
  266. static int davinci_rtc_set_time(struct device *dev, struct rtc_time *tm)
  267. {
  268. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  269. u16 days;
  270. u8 rtc_cctrl;
  271. unsigned long flags;
  272. if (convert2days(&days, tm) < 0)
  273. return -EINVAL;
  274. spin_lock_irqsave(&davinci_rtc_lock, flags);
  275. davinci_rtcss_calendar_wait(davinci_rtc);
  276. rtcss_write(davinci_rtc, bin2bcd(tm->tm_sec), PRTCSS_RTC_SEC);
  277. davinci_rtcss_calendar_wait(davinci_rtc);
  278. rtcss_write(davinci_rtc, bin2bcd(tm->tm_min), PRTCSS_RTC_MIN);
  279. davinci_rtcss_calendar_wait(davinci_rtc);
  280. rtcss_write(davinci_rtc, bin2bcd(tm->tm_hour), PRTCSS_RTC_HOUR);
  281. davinci_rtcss_calendar_wait(davinci_rtc);
  282. rtcss_write(davinci_rtc, days & 0xFF, PRTCSS_RTC_DAY0);
  283. davinci_rtcss_calendar_wait(davinci_rtc);
  284. rtcss_write(davinci_rtc, (days & 0xFF00) >> 8, PRTCSS_RTC_DAY1);
  285. rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
  286. rtc_cctrl |= PRTCSS_RTC_CCTRL_CAEN;
  287. rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
  288. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  289. return 0;
  290. }
  291. static int davinci_rtc_alarm_irq_enable(struct device *dev,
  292. unsigned int enabled)
  293. {
  294. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  295. unsigned long flags;
  296. u8 rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
  297. spin_lock_irqsave(&davinci_rtc_lock, flags);
  298. if (enabled)
  299. rtc_cctrl |= PRTCSS_RTC_CCTRL_DAEN |
  300. PRTCSS_RTC_CCTRL_HAEN |
  301. PRTCSS_RTC_CCTRL_MAEN |
  302. PRTCSS_RTC_CCTRL_ALMFLG |
  303. PRTCSS_RTC_CCTRL_AIEN;
  304. else
  305. rtc_cctrl &= ~PRTCSS_RTC_CCTRL_AIEN;
  306. davinci_rtcss_calendar_wait(davinci_rtc);
  307. rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
  308. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  309. return 0;
  310. }
  311. static int davinci_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
  312. {
  313. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  314. u16 days = 0;
  315. u8 day0, day1;
  316. unsigned long flags;
  317. spin_lock_irqsave(&davinci_rtc_lock, flags);
  318. davinci_rtcss_calendar_wait(davinci_rtc);
  319. alm->time.tm_min = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_AMIN));
  320. davinci_rtcss_calendar_wait(davinci_rtc);
  321. alm->time.tm_hour = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_AHOUR));
  322. davinci_rtcss_calendar_wait(davinci_rtc);
  323. day0 = rtcss_read(davinci_rtc, PRTCSS_RTC_ADAY0);
  324. davinci_rtcss_calendar_wait(davinci_rtc);
  325. day1 = rtcss_read(davinci_rtc, PRTCSS_RTC_ADAY1);
  326. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  327. days |= day1;
  328. days <<= 8;
  329. days |= day0;
  330. if (convertfromdays(days, &alm->time) < 0)
  331. return -EINVAL;
  332. alm->pending = !!(rtcss_read(davinci_rtc,
  333. PRTCSS_RTC_CCTRL) &
  334. PRTCSS_RTC_CCTRL_AIEN);
  335. alm->enabled = alm->pending && device_may_wakeup(dev);
  336. return 0;
  337. }
  338. static int davinci_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
  339. {
  340. struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
  341. unsigned long flags;
  342. u16 days;
  343. if (alm->time.tm_mday <= 0 && alm->time.tm_mon < 0
  344. && alm->time.tm_year < 0) {
  345. struct rtc_time tm;
  346. unsigned long now, then;
  347. davinci_rtc_read_time(dev, &tm);
  348. rtc_tm_to_time(&tm, &now);
  349. alm->time.tm_mday = tm.tm_mday;
  350. alm->time.tm_mon = tm.tm_mon;
  351. alm->time.tm_year = tm.tm_year;
  352. rtc_tm_to_time(&alm->time, &then);
  353. if (then < now) {
  354. rtc_time_to_tm(now + 24 * 60 * 60, &tm);
  355. alm->time.tm_mday = tm.tm_mday;
  356. alm->time.tm_mon = tm.tm_mon;
  357. alm->time.tm_year = tm.tm_year;
  358. }
  359. }
  360. if (convert2days(&days, &alm->time) < 0)
  361. return -EINVAL;
  362. spin_lock_irqsave(&davinci_rtc_lock, flags);
  363. davinci_rtcss_calendar_wait(davinci_rtc);
  364. rtcss_write(davinci_rtc, bin2bcd(alm->time.tm_min), PRTCSS_RTC_AMIN);
  365. davinci_rtcss_calendar_wait(davinci_rtc);
  366. rtcss_write(davinci_rtc, bin2bcd(alm->time.tm_hour), PRTCSS_RTC_AHOUR);
  367. davinci_rtcss_calendar_wait(davinci_rtc);
  368. rtcss_write(davinci_rtc, days & 0xFF, PRTCSS_RTC_ADAY0);
  369. davinci_rtcss_calendar_wait(davinci_rtc);
  370. rtcss_write(davinci_rtc, (days & 0xFF00) >> 8, PRTCSS_RTC_ADAY1);
  371. spin_unlock_irqrestore(&davinci_rtc_lock, flags);
  372. return 0;
  373. }
  374. static struct rtc_class_ops davinci_rtc_ops = {
  375. .ioctl = davinci_rtc_ioctl,
  376. .read_time = davinci_rtc_read_time,
  377. .set_time = davinci_rtc_set_time,
  378. .alarm_irq_enable = davinci_rtc_alarm_irq_enable,
  379. .read_alarm = davinci_rtc_read_alarm,
  380. .set_alarm = davinci_rtc_set_alarm,
  381. };
  382. static int __init davinci_rtc_probe(struct platform_device *pdev)
  383. {
  384. struct device *dev = &pdev->dev;
  385. struct davinci_rtc *davinci_rtc;
  386. struct resource *res;
  387. int ret = 0;
  388. davinci_rtc = devm_kzalloc(&pdev->dev, sizeof(struct davinci_rtc), GFP_KERNEL);
  389. if (!davinci_rtc)
  390. return -ENOMEM;
  391. davinci_rtc->irq = platform_get_irq(pdev, 0);
  392. if (davinci_rtc->irq < 0) {
  393. dev_err(dev, "no RTC irq\n");
  394. return davinci_rtc->irq;
  395. }
  396. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  397. davinci_rtc->base = devm_ioremap_resource(dev, res);
  398. if (IS_ERR(davinci_rtc->base))
  399. return PTR_ERR(davinci_rtc->base);
  400. platform_set_drvdata(pdev, davinci_rtc);
  401. davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
  402. &davinci_rtc_ops, THIS_MODULE);
  403. if (IS_ERR(davinci_rtc->rtc)) {
  404. dev_err(dev, "unable to register RTC device, err %d\n",
  405. ret);
  406. return PTR_ERR(davinci_rtc->rtc);
  407. }
  408. rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
  409. rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
  410. rtcss_write(davinci_rtc, 0, PRTCSS_RTC_INTC_EXTENA1);
  411. rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CTRL);
  412. rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CCTRL);
  413. ret = devm_request_irq(dev, davinci_rtc->irq, davinci_rtc_interrupt,
  414. 0, "davinci_rtc", davinci_rtc);
  415. if (ret < 0) {
  416. dev_err(dev, "unable to register davinci RTC interrupt\n");
  417. return ret;
  418. }
  419. /* Enable interrupts */
  420. rtcif_write(davinci_rtc, PRTCIF_INTEN_RTCSS, PRTCIF_INTEN);
  421. rtcss_write(davinci_rtc, PRTCSS_RTC_INTC_EXTENA1_MASK,
  422. PRTCSS_RTC_INTC_EXTENA1);
  423. rtcss_write(davinci_rtc, PRTCSS_RTC_CCTRL_CAEN, PRTCSS_RTC_CCTRL);
  424. device_init_wakeup(&pdev->dev, 0);
  425. return 0;
  426. }
  427. static int __exit davinci_rtc_remove(struct platform_device *pdev)
  428. {
  429. struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
  430. device_init_wakeup(&pdev->dev, 0);
  431. rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
  432. return 0;
  433. }
  434. static struct platform_driver davinci_rtc_driver = {
  435. .remove = __exit_p(davinci_rtc_remove),
  436. .driver = {
  437. .name = "rtc_davinci",
  438. },
  439. };
  440. module_platform_driver_probe(davinci_rtc_driver, davinci_rtc_probe);
  441. MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>");
  442. MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver");
  443. MODULE_LICENSE("GPL");