rtc-pm8xxx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/rtc.h>
  15. #include <linux/pm.h>
  16. #include <linux/slab.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/mfd/pm8xxx/core.h>
  19. #include <linux/mfd/pm8xxx/rtc.h>
  20. /* RTC Register offsets from RTC CTRL REG */
  21. #define PM8XXX_ALARM_CTRL_OFFSET 0x01
  22. #define PM8XXX_RTC_WRITE_OFFSET 0x02
  23. #define PM8XXX_RTC_READ_OFFSET 0x06
  24. #define PM8XXX_ALARM_RW_OFFSET 0x0A
  25. /* RTC_CTRL register bit fields */
  26. #define PM8xxx_RTC_ENABLE BIT(7)
  27. #define PM8xxx_RTC_ALARM_ENABLE BIT(1)
  28. #define PM8xxx_RTC_ALARM_CLEAR BIT(0)
  29. #define PM8xxx_RTC_ABORT_ENABLE BIT(0)
  30. #define NUM_8_BIT_RTC_REGS 0x4
  31. /**
  32. * struct pm8xxx_rtc - rtc driver internal structure
  33. * @rtc: rtc device for this driver.
  34. * @rtc_alarm_irq: rtc alarm irq number.
  35. * @rtc_base: address of rtc control register.
  36. * @rtc_read_base: base address of read registers.
  37. * @rtc_write_base: base address of write registers.
  38. * @alarm_rw_base: base address of alarm registers.
  39. * @ctrl_reg: rtc control register.
  40. * @rtc_dev: device structure.
  41. * @ctrl_reg_lock: spinlock protecting access to ctrl_reg.
  42. */
  43. struct pm8xxx_rtc {
  44. struct rtc_device *rtc;
  45. int rtc_alarm_irq;
  46. int rtc_base;
  47. int rtc_read_base;
  48. int rtc_write_base;
  49. int alarm_rw_base;
  50. u8 ctrl_reg;
  51. struct device *rtc_dev;
  52. spinlock_t ctrl_reg_lock;
  53. };
  54. /*
  55. * The RTC registers need to be read/written one byte at a time. This is a
  56. * hardware limitation.
  57. */
  58. static int pm8xxx_read_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
  59. int base, int count)
  60. {
  61. int i, rc;
  62. struct device *parent = rtc_dd->rtc_dev->parent;
  63. for (i = 0; i < count; i++) {
  64. rc = pm8xxx_readb(parent, base + i, &rtc_val[i]);
  65. if (rc < 0) {
  66. dev_err(rtc_dd->rtc_dev, "PMIC read failed\n");
  67. return rc;
  68. }
  69. }
  70. return 0;
  71. }
  72. static int pm8xxx_write_wrapper(struct pm8xxx_rtc *rtc_dd, u8 *rtc_val,
  73. int base, int count)
  74. {
  75. int i, rc;
  76. struct device *parent = rtc_dd->rtc_dev->parent;
  77. for (i = 0; i < count; i++) {
  78. rc = pm8xxx_writeb(parent, base + i, rtc_val[i]);
  79. if (rc < 0) {
  80. dev_err(rtc_dd->rtc_dev, "PMIC write failed\n");
  81. return rc;
  82. }
  83. }
  84. return 0;
  85. }
  86. /*
  87. * Steps to write the RTC registers.
  88. * 1. Disable alarm if enabled.
  89. * 2. Write 0x00 to LSB.
  90. * 3. Write Byte[1], Byte[2], Byte[3] then Byte[0].
  91. * 4. Enable alarm if disabled in step 1.
  92. */
  93. static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
  94. {
  95. int rc, i;
  96. unsigned long secs, irq_flags;
  97. u8 value[NUM_8_BIT_RTC_REGS], reg = 0, alarm_enabled = 0, ctrl_reg;
  98. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  99. rtc_tm_to_time(tm, &secs);
  100. for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) {
  101. value[i] = secs & 0xFF;
  102. secs >>= 8;
  103. }
  104. dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs);
  105. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  106. ctrl_reg = rtc_dd->ctrl_reg;
  107. if (ctrl_reg & PM8xxx_RTC_ALARM_ENABLE) {
  108. alarm_enabled = 1;
  109. ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
  110. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
  111. 1);
  112. if (rc < 0) {
  113. dev_err(dev, "Write to RTC control register "
  114. "failed\n");
  115. goto rtc_rw_fail;
  116. }
  117. rtc_dd->ctrl_reg = ctrl_reg;
  118. } else
  119. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  120. /* Write 0 to Byte[0] */
  121. reg = 0;
  122. rc = pm8xxx_write_wrapper(rtc_dd, &reg, rtc_dd->rtc_write_base, 1);
  123. if (rc < 0) {
  124. dev_err(dev, "Write to RTC write data register failed\n");
  125. goto rtc_rw_fail;
  126. }
  127. /* Write Byte[1], Byte[2], Byte[3] */
  128. rc = pm8xxx_write_wrapper(rtc_dd, value + 1,
  129. rtc_dd->rtc_write_base + 1, 3);
  130. if (rc < 0) {
  131. dev_err(dev, "Write to RTC write data register failed\n");
  132. goto rtc_rw_fail;
  133. }
  134. /* Write Byte[0] */
  135. rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->rtc_write_base, 1);
  136. if (rc < 0) {
  137. dev_err(dev, "Write to RTC write data register failed\n");
  138. goto rtc_rw_fail;
  139. }
  140. if (alarm_enabled) {
  141. ctrl_reg |= PM8xxx_RTC_ALARM_ENABLE;
  142. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
  143. 1);
  144. if (rc < 0) {
  145. dev_err(dev, "Write to RTC control register "
  146. "failed\n");
  147. goto rtc_rw_fail;
  148. }
  149. rtc_dd->ctrl_reg = ctrl_reg;
  150. }
  151. rtc_rw_fail:
  152. if (alarm_enabled)
  153. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  154. return rc;
  155. }
  156. static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
  157. {
  158. int rc;
  159. u8 value[NUM_8_BIT_RTC_REGS], reg;
  160. unsigned long secs;
  161. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  162. rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->rtc_read_base,
  163. NUM_8_BIT_RTC_REGS);
  164. if (rc < 0) {
  165. dev_err(dev, "RTC read data register failed\n");
  166. return rc;
  167. }
  168. /*
  169. * Read the LSB again and check if there has been a carry over.
  170. * If there is, redo the read operation.
  171. */
  172. rc = pm8xxx_read_wrapper(rtc_dd, &reg, rtc_dd->rtc_read_base, 1);
  173. if (rc < 0) {
  174. dev_err(dev, "RTC read data register failed\n");
  175. return rc;
  176. }
  177. if (unlikely(reg < value[0])) {
  178. rc = pm8xxx_read_wrapper(rtc_dd, value,
  179. rtc_dd->rtc_read_base, NUM_8_BIT_RTC_REGS);
  180. if (rc < 0) {
  181. dev_err(dev, "RTC read data register failed\n");
  182. return rc;
  183. }
  184. }
  185. secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24);
  186. rtc_time_to_tm(secs, tm);
  187. rc = rtc_valid_tm(tm);
  188. if (rc < 0) {
  189. dev_err(dev, "Invalid time read from RTC\n");
  190. return rc;
  191. }
  192. dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n",
  193. secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
  194. tm->tm_mday, tm->tm_mon, tm->tm_year);
  195. return 0;
  196. }
  197. static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
  198. {
  199. int rc, i;
  200. u8 value[NUM_8_BIT_RTC_REGS], ctrl_reg;
  201. unsigned long secs, irq_flags;
  202. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  203. rtc_tm_to_time(&alarm->time, &secs);
  204. for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) {
  205. value[i] = secs & 0xFF;
  206. secs >>= 8;
  207. }
  208. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  209. rc = pm8xxx_write_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
  210. NUM_8_BIT_RTC_REGS);
  211. if (rc < 0) {
  212. dev_err(dev, "Write to RTC ALARM register failed\n");
  213. goto rtc_rw_fail;
  214. }
  215. ctrl_reg = rtc_dd->ctrl_reg;
  216. ctrl_reg = alarm->enabled ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
  217. (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
  218. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  219. if (rc < 0) {
  220. dev_err(dev, "Write to RTC control register failed\n");
  221. goto rtc_rw_fail;
  222. }
  223. rtc_dd->ctrl_reg = ctrl_reg;
  224. dev_dbg(dev, "Alarm Set for h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
  225. alarm->time.tm_hour, alarm->time.tm_min,
  226. alarm->time.tm_sec, alarm->time.tm_mday,
  227. alarm->time.tm_mon, alarm->time.tm_year);
  228. rtc_rw_fail:
  229. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  230. return rc;
  231. }
  232. static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
  233. {
  234. int rc;
  235. u8 value[NUM_8_BIT_RTC_REGS];
  236. unsigned long secs;
  237. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  238. rc = pm8xxx_read_wrapper(rtc_dd, value, rtc_dd->alarm_rw_base,
  239. NUM_8_BIT_RTC_REGS);
  240. if (rc < 0) {
  241. dev_err(dev, "RTC alarm time read failed\n");
  242. return rc;
  243. }
  244. secs = value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24);
  245. rtc_time_to_tm(secs, &alarm->time);
  246. rc = rtc_valid_tm(&alarm->time);
  247. if (rc < 0) {
  248. dev_err(dev, "Invalid alarm time read from RTC\n");
  249. return rc;
  250. }
  251. dev_dbg(dev, "Alarm set for - h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
  252. alarm->time.tm_hour, alarm->time.tm_min,
  253. alarm->time.tm_sec, alarm->time.tm_mday,
  254. alarm->time.tm_mon, alarm->time.tm_year);
  255. return 0;
  256. }
  257. static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
  258. {
  259. int rc;
  260. unsigned long irq_flags;
  261. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  262. u8 ctrl_reg;
  263. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  264. ctrl_reg = rtc_dd->ctrl_reg;
  265. ctrl_reg = (enable) ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
  266. (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
  267. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  268. if (rc < 0) {
  269. dev_err(dev, "Write to RTC control register failed\n");
  270. goto rtc_rw_fail;
  271. }
  272. rtc_dd->ctrl_reg = ctrl_reg;
  273. rtc_rw_fail:
  274. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  275. return rc;
  276. }
  277. static struct rtc_class_ops pm8xxx_rtc_ops = {
  278. .read_time = pm8xxx_rtc_read_time,
  279. .set_alarm = pm8xxx_rtc_set_alarm,
  280. .read_alarm = pm8xxx_rtc_read_alarm,
  281. .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable,
  282. };
  283. static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
  284. {
  285. struct pm8xxx_rtc *rtc_dd = dev_id;
  286. u8 ctrl_reg;
  287. int rc;
  288. unsigned long irq_flags;
  289. rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
  290. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  291. /* Clear the alarm enable bit */
  292. ctrl_reg = rtc_dd->ctrl_reg;
  293. ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
  294. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  295. if (rc < 0) {
  296. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  297. dev_err(rtc_dd->rtc_dev, "Write to RTC control register "
  298. "failed\n");
  299. goto rtc_alarm_handled;
  300. }
  301. rtc_dd->ctrl_reg = ctrl_reg;
  302. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  303. /* Clear RTC alarm register */
  304. rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
  305. PM8XXX_ALARM_CTRL_OFFSET, 1);
  306. if (rc < 0) {
  307. dev_err(rtc_dd->rtc_dev, "RTC Alarm control register read "
  308. "failed\n");
  309. goto rtc_alarm_handled;
  310. }
  311. ctrl_reg &= ~PM8xxx_RTC_ALARM_CLEAR;
  312. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
  313. PM8XXX_ALARM_CTRL_OFFSET, 1);
  314. if (rc < 0)
  315. dev_err(rtc_dd->rtc_dev, "Write to RTC Alarm control register"
  316. " failed\n");
  317. rtc_alarm_handled:
  318. return IRQ_HANDLED;
  319. }
  320. static int __devinit pm8xxx_rtc_probe(struct platform_device *pdev)
  321. {
  322. int rc;
  323. u8 ctrl_reg;
  324. bool rtc_write_enable = false;
  325. struct pm8xxx_rtc *rtc_dd;
  326. struct resource *rtc_resource;
  327. const struct pm8xxx_rtc_platform_data *pdata =
  328. dev_get_platdata(&pdev->dev);
  329. if (pdata != NULL)
  330. rtc_write_enable = pdata->rtc_write_enable;
  331. rtc_dd = kzalloc(sizeof(*rtc_dd), GFP_KERNEL);
  332. if (rtc_dd == NULL) {
  333. dev_err(&pdev->dev, "Unable to allocate memory!\n");
  334. return -ENOMEM;
  335. }
  336. /* Initialise spinlock to protect RTC control register */
  337. spin_lock_init(&rtc_dd->ctrl_reg_lock);
  338. rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
  339. if (rtc_dd->rtc_alarm_irq < 0) {
  340. dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
  341. rc = -ENXIO;
  342. goto fail_rtc_enable;
  343. }
  344. rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
  345. "pmic_rtc_base");
  346. if (!(rtc_resource && rtc_resource->start)) {
  347. dev_err(&pdev->dev, "RTC IO resource absent!\n");
  348. rc = -ENXIO;
  349. goto fail_rtc_enable;
  350. }
  351. rtc_dd->rtc_base = rtc_resource->start;
  352. /* Setup RTC register addresses */
  353. rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET;
  354. rtc_dd->rtc_read_base = rtc_dd->rtc_base + PM8XXX_RTC_READ_OFFSET;
  355. rtc_dd->alarm_rw_base = rtc_dd->rtc_base + PM8XXX_ALARM_RW_OFFSET;
  356. rtc_dd->rtc_dev = &pdev->dev;
  357. /* Check if the RTC is on, else turn it on */
  358. rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  359. if (rc < 0) {
  360. dev_err(&pdev->dev, "RTC control register read failed!\n");
  361. goto fail_rtc_enable;
  362. }
  363. if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) {
  364. ctrl_reg |= PM8xxx_RTC_ENABLE;
  365. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
  366. 1);
  367. if (rc < 0) {
  368. dev_err(&pdev->dev, "Write to RTC control register "
  369. "failed\n");
  370. goto fail_rtc_enable;
  371. }
  372. }
  373. /* Enable abort enable feature */
  374. ctrl_reg |= PM8xxx_RTC_ABORT_ENABLE;
  375. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  376. if (rc < 0) {
  377. dev_err(&pdev->dev, "PM8xxx write failed!\n");
  378. goto fail_rtc_enable;
  379. }
  380. rtc_dd->ctrl_reg = ctrl_reg;
  381. if (rtc_write_enable == true)
  382. pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time;
  383. platform_set_drvdata(pdev, rtc_dd);
  384. device_init_wakeup(&pdev->dev, 1);
  385. /* Register the RTC device */
  386. rtc_dd->rtc = rtc_device_register("pm8xxx_rtc", &pdev->dev,
  387. &pm8xxx_rtc_ops, THIS_MODULE);
  388. if (IS_ERR(rtc_dd->rtc)) {
  389. dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
  390. __func__, PTR_ERR(rtc_dd->rtc));
  391. rc = PTR_ERR(rtc_dd->rtc);
  392. goto fail_rtc_enable;
  393. }
  394. /* Request the alarm IRQ */
  395. rc = request_any_context_irq(rtc_dd->rtc_alarm_irq,
  396. pm8xxx_alarm_trigger, IRQF_TRIGGER_RISING,
  397. "pm8xxx_rtc_alarm", rtc_dd);
  398. if (rc < 0) {
  399. dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc);
  400. goto fail_req_irq;
  401. }
  402. dev_dbg(&pdev->dev, "Probe success !!\n");
  403. return 0;
  404. fail_req_irq:
  405. rtc_device_unregister(rtc_dd->rtc);
  406. fail_rtc_enable:
  407. platform_set_drvdata(pdev, NULL);
  408. kfree(rtc_dd);
  409. return rc;
  410. }
  411. static int __devexit pm8xxx_rtc_remove(struct platform_device *pdev)
  412. {
  413. struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
  414. device_init_wakeup(&pdev->dev, 0);
  415. free_irq(rtc_dd->rtc_alarm_irq, rtc_dd);
  416. rtc_device_unregister(rtc_dd->rtc);
  417. platform_set_drvdata(pdev, NULL);
  418. kfree(rtc_dd);
  419. return 0;
  420. }
  421. #ifdef CONFIG_PM_SLEEP
  422. static int pm8xxx_rtc_resume(struct device *dev)
  423. {
  424. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  425. if (device_may_wakeup(dev))
  426. disable_irq_wake(rtc_dd->rtc_alarm_irq);
  427. return 0;
  428. }
  429. static int pm8xxx_rtc_suspend(struct device *dev)
  430. {
  431. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  432. if (device_may_wakeup(dev))
  433. enable_irq_wake(rtc_dd->rtc_alarm_irq);
  434. return 0;
  435. }
  436. #endif
  437. static SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, pm8xxx_rtc_suspend, pm8xxx_rtc_resume);
  438. static void pm8xxx_rtc_shutdown(struct platform_device *pdev)
  439. {
  440. u8 value[4] = {0, 0, 0, 0};
  441. u8 reg;
  442. int rc;
  443. unsigned long irq_flags;
  444. bool rtc_alarm_powerup = false;
  445. struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
  446. struct pm8xxx_rtc_platform_data *pdata = pdev->dev.platform_data;
  447. if (pdata != NULL)
  448. rtc_alarm_powerup = pdata->rtc_alarm_powerup;
  449. if (!rtc_alarm_powerup) {
  450. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  451. dev_dbg(&pdev->dev, "Disabling alarm interrupts\n");
  452. /* Disable RTC alarms */
  453. reg = rtc_dd->ctrl_reg;
  454. reg &= ~PM8xxx_RTC_ALARM_ENABLE;
  455. rc = pm8xxx_write_wrapper(rtc_dd, &reg, rtc_dd->rtc_base, 1);
  456. if (rc < 0) {
  457. dev_err(rtc_dd->rtc_dev, "Disabling alarm failed\n");
  458. goto fail_alarm_disable;
  459. }
  460. /* Clear Alarm register */
  461. rc = pm8xxx_write_wrapper(rtc_dd, value,
  462. rtc_dd->alarm_rw_base, NUM_8_BIT_RTC_REGS);
  463. if (rc < 0)
  464. dev_err(rtc_dd->rtc_dev, "Clearing alarm failed\n");
  465. fail_alarm_disable:
  466. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  467. }
  468. }
  469. static struct platform_driver pm8xxx_rtc_driver = {
  470. .probe = pm8xxx_rtc_probe,
  471. .remove = __devexit_p(pm8xxx_rtc_remove),
  472. .shutdown = pm8xxx_rtc_shutdown,
  473. .driver = {
  474. .name = PM8XXX_RTC_DEV_NAME,
  475. .owner = THIS_MODULE,
  476. .pm = &pm8xxx_rtc_pm_ops,
  477. },
  478. };
  479. module_platform_driver(pm8xxx_rtc_driver);
  480. MODULE_ALIAS("platform:rtc-pm8xxx");
  481. MODULE_DESCRIPTION("PMIC8xxx RTC driver");
  482. MODULE_LICENSE("GPL v2");
  483. MODULE_AUTHOR("Anirudh Ghayal <aghayal@codeaurora.org>");