rtc-pm8xxx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. u8 value[4] = {0};
  264. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  265. ctrl_reg = rtc_dd->ctrl_reg;
  266. ctrl_reg = (enable) ? (ctrl_reg | PM8xxx_RTC_ALARM_ENABLE) :
  267. (ctrl_reg & ~PM8xxx_RTC_ALARM_ENABLE);
  268. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  269. if (rc < 0) {
  270. dev_err(dev, "Write to RTC control register failed\n");
  271. goto rtc_rw_fail;
  272. }
  273. rtc_dd->ctrl_reg = ctrl_reg;
  274. /* Clear Alarm register */
  275. if (!enable) {
  276. rc = pm8xxx_write_wrapper(rtc_dd, value,
  277. rtc_dd->alarm_rw_base, NUM_8_BIT_RTC_REGS);
  278. if (rc < 0)
  279. dev_err(dev, "Clear ALARM value reg failed\n");
  280. }
  281. rtc_rw_fail:
  282. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  283. return rc;
  284. }
  285. static struct rtc_class_ops pm8xxx_rtc_ops = {
  286. .read_time = pm8xxx_rtc_read_time,
  287. .set_alarm = pm8xxx_rtc_set_alarm,
  288. .read_alarm = pm8xxx_rtc_read_alarm,
  289. .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable,
  290. };
  291. static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id)
  292. {
  293. struct pm8xxx_rtc *rtc_dd = dev_id;
  294. u8 ctrl_reg;
  295. int rc;
  296. unsigned long irq_flags;
  297. rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF);
  298. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  299. /* Clear the alarm enable bit */
  300. ctrl_reg = rtc_dd->ctrl_reg;
  301. ctrl_reg &= ~PM8xxx_RTC_ALARM_ENABLE;
  302. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  303. if (rc < 0) {
  304. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  305. dev_err(rtc_dd->rtc_dev, "Write to RTC control register "
  306. "failed\n");
  307. goto rtc_alarm_handled;
  308. }
  309. rtc_dd->ctrl_reg = ctrl_reg;
  310. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  311. /* Clear RTC alarm register */
  312. rc = pm8xxx_read_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, "RTC Alarm control register read "
  316. "failed\n");
  317. goto rtc_alarm_handled;
  318. }
  319. ctrl_reg &= ~PM8xxx_RTC_ALARM_CLEAR;
  320. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base +
  321. PM8XXX_ALARM_CTRL_OFFSET, 1);
  322. if (rc < 0)
  323. dev_err(rtc_dd->rtc_dev, "Write to RTC Alarm control register"
  324. " failed\n");
  325. rtc_alarm_handled:
  326. return IRQ_HANDLED;
  327. }
  328. static int __devinit pm8xxx_rtc_probe(struct platform_device *pdev)
  329. {
  330. int rc;
  331. u8 ctrl_reg;
  332. bool rtc_write_enable = false;
  333. struct pm8xxx_rtc *rtc_dd;
  334. struct resource *rtc_resource;
  335. const struct pm8xxx_rtc_platform_data *pdata =
  336. dev_get_platdata(&pdev->dev);
  337. if (pdata != NULL)
  338. rtc_write_enable = pdata->rtc_write_enable;
  339. rtc_dd = kzalloc(sizeof(*rtc_dd), GFP_KERNEL);
  340. if (rtc_dd == NULL) {
  341. dev_err(&pdev->dev, "Unable to allocate memory!\n");
  342. return -ENOMEM;
  343. }
  344. /* Initialise spinlock to protect RTC control register */
  345. spin_lock_init(&rtc_dd->ctrl_reg_lock);
  346. rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
  347. if (rtc_dd->rtc_alarm_irq < 0) {
  348. dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
  349. rc = -ENXIO;
  350. goto fail_rtc_enable;
  351. }
  352. rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
  353. "pmic_rtc_base");
  354. if (!(rtc_resource && rtc_resource->start)) {
  355. dev_err(&pdev->dev, "RTC IO resource absent!\n");
  356. rc = -ENXIO;
  357. goto fail_rtc_enable;
  358. }
  359. rtc_dd->rtc_base = rtc_resource->start;
  360. /* Setup RTC register addresses */
  361. rtc_dd->rtc_write_base = rtc_dd->rtc_base + PM8XXX_RTC_WRITE_OFFSET;
  362. rtc_dd->rtc_read_base = rtc_dd->rtc_base + PM8XXX_RTC_READ_OFFSET;
  363. rtc_dd->alarm_rw_base = rtc_dd->rtc_base + PM8XXX_ALARM_RW_OFFSET;
  364. rtc_dd->rtc_dev = &pdev->dev;
  365. /* Check if the RTC is on, else turn it on */
  366. rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  367. if (rc < 0) {
  368. dev_err(&pdev->dev, "RTC control register read failed!\n");
  369. goto fail_rtc_enable;
  370. }
  371. if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) {
  372. ctrl_reg |= PM8xxx_RTC_ENABLE;
  373. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base,
  374. 1);
  375. if (rc < 0) {
  376. dev_err(&pdev->dev, "Write to RTC control register "
  377. "failed\n");
  378. goto fail_rtc_enable;
  379. }
  380. }
  381. /* Enable abort enable feature */
  382. ctrl_reg |= PM8xxx_RTC_ABORT_ENABLE;
  383. rc = pm8xxx_write_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
  384. if (rc < 0) {
  385. dev_err(&pdev->dev, "PM8xxx write failed!\n");
  386. goto fail_rtc_enable;
  387. }
  388. rtc_dd->ctrl_reg = ctrl_reg;
  389. if (rtc_write_enable == true)
  390. pm8xxx_rtc_ops.set_time = pm8xxx_rtc_set_time;
  391. platform_set_drvdata(pdev, rtc_dd);
  392. device_init_wakeup(&pdev->dev, 1);
  393. /* Register the RTC device */
  394. rtc_dd->rtc = rtc_device_register("pm8xxx_rtc", &pdev->dev,
  395. &pm8xxx_rtc_ops, THIS_MODULE);
  396. if (IS_ERR(rtc_dd->rtc)) {
  397. dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
  398. __func__, PTR_ERR(rtc_dd->rtc));
  399. rc = PTR_ERR(rtc_dd->rtc);
  400. goto fail_rtc_enable;
  401. }
  402. /* Request the alarm IRQ */
  403. rc = request_any_context_irq(rtc_dd->rtc_alarm_irq,
  404. pm8xxx_alarm_trigger, IRQF_TRIGGER_RISING,
  405. "pm8xxx_rtc_alarm", rtc_dd);
  406. if (rc < 0) {
  407. dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc);
  408. goto fail_req_irq;
  409. }
  410. dev_dbg(&pdev->dev, "Probe success !!\n");
  411. return 0;
  412. fail_req_irq:
  413. rtc_device_unregister(rtc_dd->rtc);
  414. fail_rtc_enable:
  415. platform_set_drvdata(pdev, NULL);
  416. kfree(rtc_dd);
  417. return rc;
  418. }
  419. static int __devexit pm8xxx_rtc_remove(struct platform_device *pdev)
  420. {
  421. struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
  422. device_init_wakeup(&pdev->dev, 0);
  423. free_irq(rtc_dd->rtc_alarm_irq, rtc_dd);
  424. rtc_device_unregister(rtc_dd->rtc);
  425. platform_set_drvdata(pdev, NULL);
  426. kfree(rtc_dd);
  427. return 0;
  428. }
  429. #ifdef CONFIG_PM_SLEEP
  430. static int pm8xxx_rtc_resume(struct device *dev)
  431. {
  432. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  433. if (device_may_wakeup(dev))
  434. disable_irq_wake(rtc_dd->rtc_alarm_irq);
  435. return 0;
  436. }
  437. static int pm8xxx_rtc_suspend(struct device *dev)
  438. {
  439. struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
  440. if (device_may_wakeup(dev))
  441. enable_irq_wake(rtc_dd->rtc_alarm_irq);
  442. return 0;
  443. }
  444. #endif
  445. static SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, pm8xxx_rtc_suspend, pm8xxx_rtc_resume);
  446. static void pm8xxx_rtc_shutdown(struct platform_device *pdev)
  447. {
  448. u8 value[4] = {0, 0, 0, 0};
  449. u8 reg;
  450. int rc;
  451. unsigned long irq_flags;
  452. bool rtc_alarm_powerup = false;
  453. struct pm8xxx_rtc *rtc_dd = platform_get_drvdata(pdev);
  454. struct pm8xxx_rtc_platform_data *pdata = pdev->dev.platform_data;
  455. if (pdata != NULL)
  456. rtc_alarm_powerup = pdata->rtc_alarm_powerup;
  457. if (!rtc_alarm_powerup) {
  458. spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
  459. dev_dbg(&pdev->dev, "Disabling alarm interrupts\n");
  460. /* Disable RTC alarms */
  461. reg = rtc_dd->ctrl_reg;
  462. reg &= ~PM8xxx_RTC_ALARM_ENABLE;
  463. rc = pm8xxx_write_wrapper(rtc_dd, &reg, rtc_dd->rtc_base, 1);
  464. if (rc < 0) {
  465. dev_err(rtc_dd->rtc_dev, "Disabling alarm failed\n");
  466. goto fail_alarm_disable;
  467. }
  468. /* Clear Alarm register */
  469. rc = pm8xxx_write_wrapper(rtc_dd, value,
  470. rtc_dd->alarm_rw_base, NUM_8_BIT_RTC_REGS);
  471. if (rc < 0)
  472. dev_err(rtc_dd->rtc_dev, "Clearing alarm failed\n");
  473. fail_alarm_disable:
  474. spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
  475. }
  476. }
  477. static struct platform_driver pm8xxx_rtc_driver = {
  478. .probe = pm8xxx_rtc_probe,
  479. .remove = __devexit_p(pm8xxx_rtc_remove),
  480. .shutdown = pm8xxx_rtc_shutdown,
  481. .driver = {
  482. .name = PM8XXX_RTC_DEV_NAME,
  483. .owner = THIS_MODULE,
  484. .pm = &pm8xxx_rtc_pm_ops,
  485. },
  486. };
  487. module_platform_driver(pm8xxx_rtc_driver);
  488. MODULE_ALIAS("platform:rtc-pm8xxx");
  489. MODULE_DESCRIPTION("PMIC8xxx RTC driver");
  490. MODULE_LICENSE("GPL v2");
  491. MODULE_AUTHOR("Anirudh Ghayal <aghayal@codeaurora.org>");