rtc-s3c.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* drivers/rtc/rtc-s3c.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com/
  5. *
  6. * Copyright (c) 2004,2006 Simtec Electronics
  7. * Ben Dooks, <ben@simtec.co.uk>
  8. * http://armlinux.simtec.co.uk/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * S3C2410/S3C2440/S3C24XX Internal RTC Driver
  15. */
  16. #include <linux/module.h>
  17. #include <linux/fs.h>
  18. #include <linux/string.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/rtc.h>
  23. #include <linux/bcd.h>
  24. #include <linux/clk.h>
  25. #include <linux/log2.h>
  26. #include <linux/slab.h>
  27. #include <mach/hardware.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <plat/regs-rtc.h>
  32. enum s3c_cpu_type {
  33. TYPE_S3C2410,
  34. TYPE_S3C64XX,
  35. };
  36. /* I have yet to find an S3C implementation with more than one
  37. * of these rtc blocks in */
  38. static struct resource *s3c_rtc_mem;
  39. static struct clk *rtc_clk;
  40. static void __iomem *s3c_rtc_base;
  41. static int s3c_rtc_alarmno = NO_IRQ;
  42. static int s3c_rtc_tickno = NO_IRQ;
  43. static bool wake_en;
  44. static enum s3c_cpu_type s3c_rtc_cpu_type;
  45. static DEFINE_SPINLOCK(s3c_rtc_pie_lock);
  46. /* IRQ Handlers */
  47. static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
  48. {
  49. struct rtc_device *rdev = id;
  50. clk_enable(rtc_clk);
  51. rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF);
  52. if (s3c_rtc_cpu_type == TYPE_S3C64XX)
  53. writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP);
  54. clk_disable(rtc_clk);
  55. return IRQ_HANDLED;
  56. }
  57. static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
  58. {
  59. struct rtc_device *rdev = id;
  60. clk_enable(rtc_clk);
  61. rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF);
  62. if (s3c_rtc_cpu_type == TYPE_S3C64XX)
  63. writeb(S3C2410_INTP_TIC, s3c_rtc_base + S3C2410_INTP);
  64. clk_disable(rtc_clk);
  65. return IRQ_HANDLED;
  66. }
  67. /* Update control registers */
  68. static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
  69. {
  70. unsigned int tmp;
  71. pr_debug("%s: aie=%d\n", __func__, enabled);
  72. clk_enable(rtc_clk);
  73. tmp = readb(s3c_rtc_base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
  74. if (enabled)
  75. tmp |= S3C2410_RTCALM_ALMEN;
  76. writeb(tmp, s3c_rtc_base + S3C2410_RTCALM);
  77. clk_disable(rtc_clk);
  78. return 0;
  79. }
  80. static int s3c_rtc_setfreq(struct device *dev, int freq)
  81. {
  82. struct platform_device *pdev = to_platform_device(dev);
  83. struct rtc_device *rtc_dev = platform_get_drvdata(pdev);
  84. unsigned int tmp = 0;
  85. if (!is_power_of_2(freq))
  86. return -EINVAL;
  87. clk_enable(rtc_clk);
  88. spin_lock_irq(&s3c_rtc_pie_lock);
  89. if (s3c_rtc_cpu_type == TYPE_S3C2410) {
  90. tmp = readb(s3c_rtc_base + S3C2410_TICNT);
  91. tmp &= S3C2410_TICNT_ENABLE;
  92. }
  93. tmp |= (rtc_dev->max_user_freq / freq)-1;
  94. writel(tmp, s3c_rtc_base + S3C2410_TICNT);
  95. spin_unlock_irq(&s3c_rtc_pie_lock);
  96. clk_disable(rtc_clk);
  97. return 0;
  98. }
  99. /* Time read/write */
  100. static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
  101. {
  102. unsigned int have_retried = 0;
  103. void __iomem *base = s3c_rtc_base;
  104. clk_enable(rtc_clk);
  105. retry_get_time:
  106. rtc_tm->tm_min = readb(base + S3C2410_RTCMIN);
  107. rtc_tm->tm_hour = readb(base + S3C2410_RTCHOUR);
  108. rtc_tm->tm_mday = readb(base + S3C2410_RTCDATE);
  109. rtc_tm->tm_mon = readb(base + S3C2410_RTCMON);
  110. rtc_tm->tm_year = readb(base + S3C2410_RTCYEAR);
  111. rtc_tm->tm_sec = readb(base + S3C2410_RTCSEC);
  112. /* the only way to work out wether the system was mid-update
  113. * when we read it is to check the second counter, and if it
  114. * is zero, then we re-try the entire read
  115. */
  116. if (rtc_tm->tm_sec == 0 && !have_retried) {
  117. have_retried = 1;
  118. goto retry_get_time;
  119. }
  120. pr_debug("read time %04d.%02d.%02d %02d:%02d:%02d\n",
  121. 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
  122. rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
  123. rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
  124. rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
  125. rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
  126. rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
  127. rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
  128. rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
  129. rtc_tm->tm_year += 100;
  130. rtc_tm->tm_mon -= 1;
  131. clk_disable(rtc_clk);
  132. return rtc_valid_tm(rtc_tm);
  133. }
  134. static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
  135. {
  136. void __iomem *base = s3c_rtc_base;
  137. int year = tm->tm_year - 100;
  138. clk_enable(rtc_clk);
  139. pr_debug("set time %04d.%02d.%02d %02d:%02d:%02d\n",
  140. 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
  141. tm->tm_hour, tm->tm_min, tm->tm_sec);
  142. /* we get around y2k by simply not supporting it */
  143. if (year < 0 || year >= 100) {
  144. dev_err(dev, "rtc only supports 100 years\n");
  145. return -EINVAL;
  146. }
  147. writeb(bin2bcd(tm->tm_sec), base + S3C2410_RTCSEC);
  148. writeb(bin2bcd(tm->tm_min), base + S3C2410_RTCMIN);
  149. writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR);
  150. writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE);
  151. writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON);
  152. writeb(bin2bcd(year), base + S3C2410_RTCYEAR);
  153. clk_disable(rtc_clk);
  154. return 0;
  155. }
  156. static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
  157. {
  158. struct rtc_time *alm_tm = &alrm->time;
  159. void __iomem *base = s3c_rtc_base;
  160. unsigned int alm_en;
  161. clk_enable(rtc_clk);
  162. alm_tm->tm_sec = readb(base + S3C2410_ALMSEC);
  163. alm_tm->tm_min = readb(base + S3C2410_ALMMIN);
  164. alm_tm->tm_hour = readb(base + S3C2410_ALMHOUR);
  165. alm_tm->tm_mon = readb(base + S3C2410_ALMMON);
  166. alm_tm->tm_mday = readb(base + S3C2410_ALMDATE);
  167. alm_tm->tm_year = readb(base + S3C2410_ALMYEAR);
  168. alm_en = readb(base + S3C2410_RTCALM);
  169. alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
  170. pr_debug("read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
  171. alm_en,
  172. 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
  173. alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
  174. /* decode the alarm enable field */
  175. if (alm_en & S3C2410_RTCALM_SECEN)
  176. alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
  177. else
  178. alm_tm->tm_sec = -1;
  179. if (alm_en & S3C2410_RTCALM_MINEN)
  180. alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
  181. else
  182. alm_tm->tm_min = -1;
  183. if (alm_en & S3C2410_RTCALM_HOUREN)
  184. alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
  185. else
  186. alm_tm->tm_hour = -1;
  187. if (alm_en & S3C2410_RTCALM_DAYEN)
  188. alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday);
  189. else
  190. alm_tm->tm_mday = -1;
  191. if (alm_en & S3C2410_RTCALM_MONEN) {
  192. alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon);
  193. alm_tm->tm_mon -= 1;
  194. } else {
  195. alm_tm->tm_mon = -1;
  196. }
  197. if (alm_en & S3C2410_RTCALM_YEAREN)
  198. alm_tm->tm_year = bcd2bin(alm_tm->tm_year);
  199. else
  200. alm_tm->tm_year = -1;
  201. clk_disable(rtc_clk);
  202. return 0;
  203. }
  204. static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
  205. {
  206. struct rtc_time *tm = &alrm->time;
  207. void __iomem *base = s3c_rtc_base;
  208. unsigned int alrm_en;
  209. clk_enable(rtc_clk);
  210. pr_debug("s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
  211. alrm->enabled,
  212. 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
  213. tm->tm_hour, tm->tm_min, tm->tm_sec);
  214. alrm_en = readb(base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
  215. writeb(0x00, base + S3C2410_RTCALM);
  216. if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
  217. alrm_en |= S3C2410_RTCALM_SECEN;
  218. writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC);
  219. }
  220. if (tm->tm_min < 60 && tm->tm_min >= 0) {
  221. alrm_en |= S3C2410_RTCALM_MINEN;
  222. writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN);
  223. }
  224. if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
  225. alrm_en |= S3C2410_RTCALM_HOUREN;
  226. writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
  227. }
  228. pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);
  229. writeb(alrm_en, base + S3C2410_RTCALM);
  230. s3c_rtc_setaie(dev, alrm->enabled);
  231. clk_disable(rtc_clk);
  232. return 0;
  233. }
  234. static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
  235. {
  236. unsigned int ticnt;
  237. clk_enable(rtc_clk);
  238. if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
  239. ticnt = readw(s3c_rtc_base + S3C2410_RTCCON);
  240. ticnt &= S3C64XX_RTCCON_TICEN;
  241. } else {
  242. ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
  243. ticnt &= S3C2410_TICNT_ENABLE;
  244. }
  245. seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no");
  246. clk_disable(rtc_clk);
  247. return 0;
  248. }
  249. static int s3c_rtc_open(struct device *dev)
  250. {
  251. struct platform_device *pdev = to_platform_device(dev);
  252. struct rtc_device *rtc_dev = platform_get_drvdata(pdev);
  253. int ret;
  254. ret = request_irq(s3c_rtc_alarmno, s3c_rtc_alarmirq,
  255. IRQF_DISABLED, "s3c2410-rtc alarm", rtc_dev);
  256. if (ret) {
  257. dev_err(dev, "IRQ%d error %d\n", s3c_rtc_alarmno, ret);
  258. return ret;
  259. }
  260. ret = request_irq(s3c_rtc_tickno, s3c_rtc_tickirq,
  261. IRQF_DISABLED, "s3c2410-rtc tick", rtc_dev);
  262. if (ret) {
  263. dev_err(dev, "IRQ%d error %d\n", s3c_rtc_tickno, ret);
  264. goto tick_err;
  265. }
  266. return ret;
  267. tick_err:
  268. free_irq(s3c_rtc_alarmno, rtc_dev);
  269. return ret;
  270. }
  271. static void s3c_rtc_release(struct device *dev)
  272. {
  273. struct platform_device *pdev = to_platform_device(dev);
  274. struct rtc_device *rtc_dev = platform_get_drvdata(pdev);
  275. /* do not clear AIE here, it may be needed for wake */
  276. free_irq(s3c_rtc_alarmno, rtc_dev);
  277. free_irq(s3c_rtc_tickno, rtc_dev);
  278. }
  279. static const struct rtc_class_ops s3c_rtcops = {
  280. .open = s3c_rtc_open,
  281. .release = s3c_rtc_release,
  282. .read_time = s3c_rtc_gettime,
  283. .set_time = s3c_rtc_settime,
  284. .read_alarm = s3c_rtc_getalarm,
  285. .set_alarm = s3c_rtc_setalarm,
  286. .proc = s3c_rtc_proc,
  287. .alarm_irq_enable = s3c_rtc_setaie,
  288. };
  289. static void s3c_rtc_enable(struct platform_device *pdev, int en)
  290. {
  291. void __iomem *base = s3c_rtc_base;
  292. unsigned int tmp;
  293. if (s3c_rtc_base == NULL)
  294. return;
  295. clk_enable(rtc_clk);
  296. if (!en) {
  297. tmp = readw(base + S3C2410_RTCCON);
  298. if (s3c_rtc_cpu_type == TYPE_S3C64XX)
  299. tmp &= ~S3C64XX_RTCCON_TICEN;
  300. tmp &= ~S3C2410_RTCCON_RTCEN;
  301. writew(tmp, base + S3C2410_RTCCON);
  302. if (s3c_rtc_cpu_type == TYPE_S3C2410) {
  303. tmp = readb(base + S3C2410_TICNT);
  304. tmp &= ~S3C2410_TICNT_ENABLE;
  305. writeb(tmp, base + S3C2410_TICNT);
  306. }
  307. } else {
  308. /* re-enable the device, and check it is ok */
  309. if ((readw(base+S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0) {
  310. dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
  311. tmp = readw(base + S3C2410_RTCCON);
  312. writew(tmp | S3C2410_RTCCON_RTCEN,
  313. base + S3C2410_RTCCON);
  314. }
  315. if ((readw(base + S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)) {
  316. dev_info(&pdev->dev, "removing RTCCON_CNTSEL\n");
  317. tmp = readw(base + S3C2410_RTCCON);
  318. writew(tmp & ~S3C2410_RTCCON_CNTSEL,
  319. base + S3C2410_RTCCON);
  320. }
  321. if ((readw(base + S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)) {
  322. dev_info(&pdev->dev, "removing RTCCON_CLKRST\n");
  323. tmp = readw(base + S3C2410_RTCCON);
  324. writew(tmp & ~S3C2410_RTCCON_CLKRST,
  325. base + S3C2410_RTCCON);
  326. }
  327. }
  328. clk_disable(rtc_clk);
  329. }
  330. static int __devexit s3c_rtc_remove(struct platform_device *dev)
  331. {
  332. struct rtc_device *rtc = platform_get_drvdata(dev);
  333. platform_set_drvdata(dev, NULL);
  334. rtc_device_unregister(rtc);
  335. s3c_rtc_setaie(&dev->dev, 0);
  336. clk_put(rtc_clk);
  337. rtc_clk = NULL;
  338. iounmap(s3c_rtc_base);
  339. release_resource(s3c_rtc_mem);
  340. kfree(s3c_rtc_mem);
  341. return 0;
  342. }
  343. static int __devinit s3c_rtc_probe(struct platform_device *pdev)
  344. {
  345. struct rtc_device *rtc;
  346. struct rtc_time rtc_tm;
  347. struct resource *res;
  348. int ret;
  349. pr_debug("%s: probe=%p\n", __func__, pdev);
  350. /* find the IRQs */
  351. s3c_rtc_tickno = platform_get_irq(pdev, 1);
  352. if (s3c_rtc_tickno < 0) {
  353. dev_err(&pdev->dev, "no irq for rtc tick\n");
  354. return -ENOENT;
  355. }
  356. s3c_rtc_alarmno = platform_get_irq(pdev, 0);
  357. if (s3c_rtc_alarmno < 0) {
  358. dev_err(&pdev->dev, "no irq for alarm\n");
  359. return -ENOENT;
  360. }
  361. pr_debug("s3c2410_rtc: tick irq %d, alarm irq %d\n",
  362. s3c_rtc_tickno, s3c_rtc_alarmno);
  363. /* get the memory region */
  364. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  365. if (res == NULL) {
  366. dev_err(&pdev->dev, "failed to get memory region resource\n");
  367. return -ENOENT;
  368. }
  369. s3c_rtc_mem = request_mem_region(res->start, resource_size(res),
  370. pdev->name);
  371. if (s3c_rtc_mem == NULL) {
  372. dev_err(&pdev->dev, "failed to reserve memory region\n");
  373. ret = -ENOENT;
  374. goto err_nores;
  375. }
  376. s3c_rtc_base = ioremap(res->start, resource_size(res));
  377. if (s3c_rtc_base == NULL) {
  378. dev_err(&pdev->dev, "failed ioremap()\n");
  379. ret = -EINVAL;
  380. goto err_nomap;
  381. }
  382. rtc_clk = clk_get(&pdev->dev, "rtc");
  383. if (IS_ERR(rtc_clk)) {
  384. dev_err(&pdev->dev, "failed to find rtc clock source\n");
  385. ret = PTR_ERR(rtc_clk);
  386. rtc_clk = NULL;
  387. goto err_clk;
  388. }
  389. clk_enable(rtc_clk);
  390. /* check to see if everything is setup correctly */
  391. s3c_rtc_enable(pdev, 1);
  392. pr_debug("s3c2410_rtc: RTCCON=%02x\n",
  393. readw(s3c_rtc_base + S3C2410_RTCCON));
  394. device_init_wakeup(&pdev->dev, 1);
  395. /* register RTC and exit */
  396. rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops,
  397. THIS_MODULE);
  398. if (IS_ERR(rtc)) {
  399. dev_err(&pdev->dev, "cannot attach rtc\n");
  400. ret = PTR_ERR(rtc);
  401. goto err_nortc;
  402. }
  403. s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
  404. /* Check RTC Time */
  405. s3c_rtc_gettime(NULL, &rtc_tm);
  406. if (rtc_valid_tm(&rtc_tm)) {
  407. rtc_tm.tm_year = 100;
  408. rtc_tm.tm_mon = 0;
  409. rtc_tm.tm_mday = 1;
  410. rtc_tm.tm_hour = 0;
  411. rtc_tm.tm_min = 0;
  412. rtc_tm.tm_sec = 0;
  413. s3c_rtc_settime(NULL, &rtc_tm);
  414. dev_warn(&pdev->dev, "warning: invalid RTC value so initializing it\n");
  415. }
  416. if (s3c_rtc_cpu_type == TYPE_S3C64XX)
  417. rtc->max_user_freq = 32768;
  418. else
  419. rtc->max_user_freq = 128;
  420. platform_set_drvdata(pdev, rtc);
  421. s3c_rtc_setfreq(&pdev->dev, 1);
  422. clk_disable(rtc_clk);
  423. return 0;
  424. err_nortc:
  425. s3c_rtc_enable(pdev, 0);
  426. clk_disable(rtc_clk);
  427. clk_put(rtc_clk);
  428. err_clk:
  429. iounmap(s3c_rtc_base);
  430. err_nomap:
  431. release_resource(s3c_rtc_mem);
  432. err_nores:
  433. return ret;
  434. }
  435. #ifdef CONFIG_PM
  436. /* RTC Power management control */
  437. static int ticnt_save, ticnt_en_save;
  438. static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
  439. {
  440. clk_enable(rtc_clk);
  441. /* save TICNT for anyone using periodic interrupts */
  442. ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
  443. if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
  444. ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON);
  445. ticnt_en_save &= S3C64XX_RTCCON_TICEN;
  446. }
  447. s3c_rtc_enable(pdev, 0);
  448. if (device_may_wakeup(&pdev->dev) && !wake_en) {
  449. if (enable_irq_wake(s3c_rtc_alarmno) == 0)
  450. wake_en = true;
  451. else
  452. dev_err(&pdev->dev, "enable_irq_wake failed\n");
  453. }
  454. clk_disable(rtc_clk);
  455. return 0;
  456. }
  457. static int s3c_rtc_resume(struct platform_device *pdev)
  458. {
  459. unsigned int tmp;
  460. clk_enable(rtc_clk);
  461. s3c_rtc_enable(pdev, 1);
  462. writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
  463. if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) {
  464. tmp = readw(s3c_rtc_base + S3C2410_RTCCON);
  465. writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
  466. }
  467. if (device_may_wakeup(&pdev->dev) && wake_en) {
  468. disable_irq_wake(s3c_rtc_alarmno);
  469. wake_en = false;
  470. }
  471. clk_disable(rtc_clk);
  472. return 0;
  473. }
  474. #else
  475. #define s3c_rtc_suspend NULL
  476. #define s3c_rtc_resume NULL
  477. #endif
  478. static struct platform_device_id s3c_rtc_driver_ids[] = {
  479. {
  480. .name = "s3c2410-rtc",
  481. .driver_data = TYPE_S3C2410,
  482. }, {
  483. .name = "s3c64xx-rtc",
  484. .driver_data = TYPE_S3C64XX,
  485. },
  486. { }
  487. };
  488. MODULE_DEVICE_TABLE(platform, s3c_rtc_driver_ids);
  489. static struct platform_driver s3c_rtc_driver = {
  490. .probe = s3c_rtc_probe,
  491. .remove = __devexit_p(s3c_rtc_remove),
  492. .suspend = s3c_rtc_suspend,
  493. .resume = s3c_rtc_resume,
  494. .id_table = s3c_rtc_driver_ids,
  495. .driver = {
  496. .name = "s3c-rtc",
  497. .owner = THIS_MODULE,
  498. },
  499. };
  500. static char __initdata banner[] = "S3C24XX RTC, (c) 2004,2006 Simtec Electronics\n";
  501. static int __init s3c_rtc_init(void)
  502. {
  503. printk(banner);
  504. return platform_driver_register(&s3c_rtc_driver);
  505. }
  506. static void __exit s3c_rtc_exit(void)
  507. {
  508. platform_driver_unregister(&s3c_rtc_driver);
  509. }
  510. module_init(s3c_rtc_init);
  511. module_exit(s3c_rtc_exit);
  512. MODULE_DESCRIPTION("Samsung S3C RTC Driver");
  513. MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
  514. MODULE_LICENSE("GPL");
  515. MODULE_ALIAS("platform:s3c2410-rtc");