rtc-s3c.c 15 KB

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