rtc-armada38x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * RTC driver for the Armada 38x Marvell SoCs
  3. *
  4. * Copyright (C) 2015 Marvell
  5. *
  6. * Gregory Clement <gregory.clement@free-electrons.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/rtc.h>
  21. #define RTC_STATUS 0x0
  22. #define RTC_STATUS_ALARM1 BIT(0)
  23. #define RTC_STATUS_ALARM2 BIT(1)
  24. #define RTC_IRQ1_CONF 0x4
  25. #define RTC_IRQ2_CONF 0x8
  26. #define RTC_IRQ_AL_EN BIT(0)
  27. #define RTC_IRQ_FREQ_EN BIT(1)
  28. #define RTC_IRQ_FREQ_1HZ BIT(2)
  29. #define RTC_CCR 0x18
  30. #define RTC_CCR_MODE BIT(15)
  31. #define RTC_TIME 0xC
  32. #define RTC_ALARM1 0x10
  33. #define RTC_ALARM2 0x14
  34. /* Armada38x SoC registers */
  35. #define RTC_38X_BRIDGE_TIMING_CTL 0x0
  36. #define RTC_38X_PERIOD_OFFS 0
  37. #define RTC_38X_PERIOD_MASK (0x3FF << RTC_38X_PERIOD_OFFS)
  38. #define RTC_38X_READ_DELAY_OFFS 26
  39. #define RTC_38X_READ_DELAY_MASK (0x1F << RTC_38X_READ_DELAY_OFFS)
  40. /* Armada 7K/8K registers */
  41. #define RTC_8K_BRIDGE_TIMING_CTL0 0x0
  42. #define RTC_8K_WRCLK_PERIOD_OFFS 0
  43. #define RTC_8K_WRCLK_PERIOD_MASK (0xFFFF << RTC_8K_WRCLK_PERIOD_OFFS)
  44. #define RTC_8K_WRCLK_SETUP_OFFS 16
  45. #define RTC_8K_WRCLK_SETUP_MASK (0xFFFF << RTC_8K_WRCLK_SETUP_OFFS)
  46. #define RTC_8K_BRIDGE_TIMING_CTL1 0x4
  47. #define RTC_8K_READ_DELAY_OFFS 0
  48. #define RTC_8K_READ_DELAY_MASK (0xFFFF << RTC_8K_READ_DELAY_OFFS)
  49. #define RTC_8K_ISR 0x10
  50. #define RTC_8K_IMR 0x14
  51. #define RTC_8K_ALARM2 BIT(0)
  52. #define SOC_RTC_INTERRUPT 0x8
  53. #define SOC_RTC_ALARM1 BIT(0)
  54. #define SOC_RTC_ALARM2 BIT(1)
  55. #define SOC_RTC_ALARM1_MASK BIT(2)
  56. #define SOC_RTC_ALARM2_MASK BIT(3)
  57. #define SAMPLE_NR 100
  58. struct value_to_freq {
  59. u32 value;
  60. u8 freq;
  61. };
  62. struct armada38x_rtc {
  63. struct rtc_device *rtc_dev;
  64. void __iomem *regs;
  65. void __iomem *regs_soc;
  66. spinlock_t lock;
  67. int irq;
  68. struct value_to_freq *val_to_freq;
  69. struct armada38x_rtc_data *data;
  70. };
  71. #define ALARM1 0
  72. #define ALARM2 1
  73. #define ALARM_REG(base, alarm) ((base) + (alarm) * sizeof(u32))
  74. struct armada38x_rtc_data {
  75. /* Initialize the RTC-MBUS bridge timing */
  76. void (*update_mbus_timing)(struct armada38x_rtc *rtc);
  77. u32 (*read_rtc_reg)(struct armada38x_rtc *rtc, u8 rtc_reg);
  78. void (*clear_isr)(struct armada38x_rtc *rtc);
  79. void (*unmask_interrupt)(struct armada38x_rtc *rtc);
  80. u32 alarm;
  81. };
  82. /*
  83. * According to the datasheet, the OS should wait 5us after every
  84. * register write to the RTC hard macro so that the required update
  85. * can occur without holding off the system bus
  86. * According to errata RES-3124064, Write to any RTC register
  87. * may fail. As a workaround, before writing to RTC
  88. * register, issue a dummy write of 0x0 twice to RTC Status
  89. * register.
  90. */
  91. static void rtc_delayed_write(u32 val, struct armada38x_rtc *rtc, int offset)
  92. {
  93. writel(0, rtc->regs + RTC_STATUS);
  94. writel(0, rtc->regs + RTC_STATUS);
  95. writel(val, rtc->regs + offset);
  96. udelay(5);
  97. }
  98. /* Update RTC-MBUS bridge timing parameters */
  99. static void rtc_update_38x_mbus_timing_params(struct armada38x_rtc *rtc)
  100. {
  101. u32 reg;
  102. reg = readl(rtc->regs_soc + RTC_38X_BRIDGE_TIMING_CTL);
  103. reg &= ~RTC_38X_PERIOD_MASK;
  104. reg |= 0x3FF << RTC_38X_PERIOD_OFFS; /* Maximum value */
  105. reg &= ~RTC_38X_READ_DELAY_MASK;
  106. reg |= 0x1F << RTC_38X_READ_DELAY_OFFS; /* Maximum value */
  107. writel(reg, rtc->regs_soc + RTC_38X_BRIDGE_TIMING_CTL);
  108. }
  109. static void rtc_update_8k_mbus_timing_params(struct armada38x_rtc *rtc)
  110. {
  111. u32 reg;
  112. reg = readl(rtc->regs_soc + RTC_8K_BRIDGE_TIMING_CTL0);
  113. reg &= ~RTC_8K_WRCLK_PERIOD_MASK;
  114. reg |= 0x3FF << RTC_8K_WRCLK_PERIOD_OFFS;
  115. reg &= ~RTC_8K_WRCLK_SETUP_MASK;
  116. reg |= 0x29 << RTC_8K_WRCLK_SETUP_OFFS;
  117. writel(reg, rtc->regs_soc + RTC_8K_BRIDGE_TIMING_CTL0);
  118. reg = readl(rtc->regs_soc + RTC_8K_BRIDGE_TIMING_CTL1);
  119. reg &= ~RTC_8K_READ_DELAY_MASK;
  120. reg |= 0x3F << RTC_8K_READ_DELAY_OFFS;
  121. writel(reg, rtc->regs_soc + RTC_8K_BRIDGE_TIMING_CTL1);
  122. }
  123. static u32 read_rtc_register(struct armada38x_rtc *rtc, u8 rtc_reg)
  124. {
  125. return readl(rtc->regs + rtc_reg);
  126. }
  127. static u32 read_rtc_register_38x_wa(struct armada38x_rtc *rtc, u8 rtc_reg)
  128. {
  129. int i, index_max = 0, max = 0;
  130. for (i = 0; i < SAMPLE_NR; i++) {
  131. rtc->val_to_freq[i].value = readl(rtc->regs + rtc_reg);
  132. rtc->val_to_freq[i].freq = 0;
  133. }
  134. for (i = 0; i < SAMPLE_NR; i++) {
  135. int j = 0;
  136. u32 value = rtc->val_to_freq[i].value;
  137. while (rtc->val_to_freq[j].freq) {
  138. if (rtc->val_to_freq[j].value == value) {
  139. rtc->val_to_freq[j].freq++;
  140. break;
  141. }
  142. j++;
  143. }
  144. if (!rtc->val_to_freq[j].freq) {
  145. rtc->val_to_freq[j].value = value;
  146. rtc->val_to_freq[j].freq = 1;
  147. }
  148. if (rtc->val_to_freq[j].freq > max) {
  149. index_max = j;
  150. max = rtc->val_to_freq[j].freq;
  151. }
  152. /*
  153. * If a value already has half of the sample this is the most
  154. * frequent one and we can stop the research right now
  155. */
  156. if (max > SAMPLE_NR / 2)
  157. break;
  158. }
  159. return rtc->val_to_freq[index_max].value;
  160. }
  161. static void armada38x_clear_isr(struct armada38x_rtc *rtc)
  162. {
  163. u32 val = readl(rtc->regs_soc + SOC_RTC_INTERRUPT);
  164. writel(val & ~SOC_RTC_ALARM1, rtc->regs_soc + SOC_RTC_INTERRUPT);
  165. }
  166. static void armada38x_unmask_interrupt(struct armada38x_rtc *rtc)
  167. {
  168. u32 val = readl(rtc->regs_soc + SOC_RTC_INTERRUPT);
  169. writel(val | SOC_RTC_ALARM1_MASK, rtc->regs_soc + SOC_RTC_INTERRUPT);
  170. }
  171. static void armada8k_clear_isr(struct armada38x_rtc *rtc)
  172. {
  173. writel(RTC_8K_ALARM2, rtc->regs_soc + RTC_8K_ISR);
  174. }
  175. static void armada8k_unmask_interrupt(struct armada38x_rtc *rtc)
  176. {
  177. writel(RTC_8K_ALARM2, rtc->regs_soc + RTC_8K_IMR);
  178. }
  179. static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
  180. {
  181. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  182. unsigned long time, flags;
  183. spin_lock_irqsave(&rtc->lock, flags);
  184. time = rtc->data->read_rtc_reg(rtc, RTC_TIME);
  185. spin_unlock_irqrestore(&rtc->lock, flags);
  186. rtc_time_to_tm(time, tm);
  187. return 0;
  188. }
  189. static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm)
  190. {
  191. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  192. int ret = 0;
  193. unsigned long time, flags;
  194. ret = rtc_tm_to_time(tm, &time);
  195. if (ret)
  196. goto out;
  197. spin_lock_irqsave(&rtc->lock, flags);
  198. rtc_delayed_write(time, rtc, RTC_TIME);
  199. spin_unlock_irqrestore(&rtc->lock, flags);
  200. out:
  201. return ret;
  202. }
  203. static int armada38x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
  204. {
  205. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  206. unsigned long time, flags;
  207. u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm);
  208. u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
  209. u32 val;
  210. spin_lock_irqsave(&rtc->lock, flags);
  211. time = rtc->data->read_rtc_reg(rtc, reg);
  212. val = rtc->data->read_rtc_reg(rtc, reg_irq) & RTC_IRQ_AL_EN;
  213. spin_unlock_irqrestore(&rtc->lock, flags);
  214. alrm->enabled = val ? 1 : 0;
  215. rtc_time_to_tm(time, &alrm->time);
  216. return 0;
  217. }
  218. static int armada38x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
  219. {
  220. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  221. u32 reg = ALARM_REG(RTC_ALARM1, rtc->data->alarm);
  222. u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
  223. unsigned long time, flags;
  224. int ret = 0;
  225. ret = rtc_tm_to_time(&alrm->time, &time);
  226. if (ret)
  227. goto out;
  228. spin_lock_irqsave(&rtc->lock, flags);
  229. rtc_delayed_write(time, rtc, reg);
  230. if (alrm->enabled) {
  231. rtc_delayed_write(RTC_IRQ_AL_EN, rtc, reg_irq);
  232. rtc->data->unmask_interrupt(rtc);
  233. }
  234. spin_unlock_irqrestore(&rtc->lock, flags);
  235. out:
  236. return ret;
  237. }
  238. static int armada38x_rtc_alarm_irq_enable(struct device *dev,
  239. unsigned int enabled)
  240. {
  241. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  242. u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
  243. unsigned long flags;
  244. spin_lock_irqsave(&rtc->lock, flags);
  245. if (enabled)
  246. rtc_delayed_write(RTC_IRQ_AL_EN, rtc, reg_irq);
  247. else
  248. rtc_delayed_write(0, rtc, reg_irq);
  249. spin_unlock_irqrestore(&rtc->lock, flags);
  250. return 0;
  251. }
  252. static irqreturn_t armada38x_rtc_alarm_irq(int irq, void *data)
  253. {
  254. struct armada38x_rtc *rtc = data;
  255. u32 val;
  256. int event = RTC_IRQF | RTC_AF;
  257. u32 reg_irq = ALARM_REG(RTC_IRQ1_CONF, rtc->data->alarm);
  258. dev_dbg(&rtc->rtc_dev->dev, "%s:irq(%d)\n", __func__, irq);
  259. spin_lock(&rtc->lock);
  260. rtc->data->clear_isr(rtc);
  261. val = rtc->data->read_rtc_reg(rtc, reg_irq);
  262. /* disable all the interrupts for alarm*/
  263. rtc_delayed_write(0, rtc, reg_irq);
  264. /* Ack the event */
  265. rtc_delayed_write(1 << rtc->data->alarm, rtc, RTC_STATUS);
  266. spin_unlock(&rtc->lock);
  267. if (val & RTC_IRQ_FREQ_EN) {
  268. if (val & RTC_IRQ_FREQ_1HZ)
  269. event |= RTC_UF;
  270. else
  271. event |= RTC_PF;
  272. }
  273. rtc_update_irq(rtc->rtc_dev, 1, event);
  274. return IRQ_HANDLED;
  275. }
  276. /*
  277. * The information given in the Armada 388 functional spec is complex.
  278. * They give two different formulas for calculating the offset value,
  279. * but when considering "Offset" as an 8-bit signed integer, they both
  280. * reduce down to (we shall rename "Offset" as "val" here):
  281. *
  282. * val = (f_ideal / f_measured - 1) / resolution where f_ideal = 32768
  283. *
  284. * Converting to time, f = 1/t:
  285. * val = (t_measured / t_ideal - 1) / resolution where t_ideal = 1/32768
  286. *
  287. * => t_measured / t_ideal = val * resolution + 1
  288. *
  289. * "offset" in the RTC interface is defined as:
  290. * t = t0 * (1 + offset * 1e-9)
  291. * where t is the desired period, t0 is the measured period with a zero
  292. * offset, which is t_measured above. With t0 = t_measured and t = t_ideal,
  293. * offset = (t_ideal / t_measured - 1) / 1e-9
  294. *
  295. * => t_ideal / t_measured = offset * 1e-9 + 1
  296. *
  297. * so:
  298. *
  299. * offset * 1e-9 + 1 = 1 / (val * resolution + 1)
  300. *
  301. * We want "resolution" to be an integer, so resolution = R * 1e-9, giving
  302. * offset = 1e18 / (val * R + 1e9) - 1e9
  303. * val = (1e18 / (offset + 1e9) - 1e9) / R
  304. * with a common transformation:
  305. * f(x) = 1e18 / (x + 1e9) - 1e9
  306. * offset = f(val * R)
  307. * val = f(offset) / R
  308. *
  309. * Armada 38x supports two modes, fine mode (954ppb) and coarse mode (3815ppb).
  310. */
  311. static long armada38x_ppb_convert(long ppb)
  312. {
  313. long div = ppb + 1000000000L;
  314. return div_s64(1000000000000000000LL + div / 2, div) - 1000000000L;
  315. }
  316. static int armada38x_rtc_read_offset(struct device *dev, long *offset)
  317. {
  318. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  319. unsigned long ccr, flags;
  320. long ppb_cor;
  321. spin_lock_irqsave(&rtc->lock, flags);
  322. ccr = rtc->data->read_rtc_reg(rtc, RTC_CCR);
  323. spin_unlock_irqrestore(&rtc->lock, flags);
  324. ppb_cor = (ccr & RTC_CCR_MODE ? 3815 : 954) * (s8)ccr;
  325. /* ppb_cor + 1000000000L can never be zero */
  326. *offset = armada38x_ppb_convert(ppb_cor);
  327. return 0;
  328. }
  329. static int armada38x_rtc_set_offset(struct device *dev, long offset)
  330. {
  331. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  332. unsigned long ccr = 0;
  333. long ppb_cor, off;
  334. /*
  335. * The maximum ppb_cor is -128 * 3815 .. 127 * 3815, but we
  336. * need to clamp the input. This equates to -484270 .. 488558.
  337. * Not only is this to stop out of range "off" but also to
  338. * avoid the division by zero in armada38x_ppb_convert().
  339. */
  340. offset = clamp(offset, -484270L, 488558L);
  341. ppb_cor = armada38x_ppb_convert(offset);
  342. /*
  343. * Use low update mode where possible, which gives a better
  344. * resolution of correction.
  345. */
  346. off = DIV_ROUND_CLOSEST(ppb_cor, 954);
  347. if (off > 127 || off < -128) {
  348. ccr = RTC_CCR_MODE;
  349. off = DIV_ROUND_CLOSEST(ppb_cor, 3815);
  350. }
  351. /*
  352. * Armada 388 requires a bit pattern in bits 14..8 depending on
  353. * the sign bit: { 0, ~S, S, S, S, S, S }
  354. */
  355. ccr |= (off & 0x3fff) ^ 0x2000;
  356. rtc_delayed_write(ccr, rtc, RTC_CCR);
  357. return 0;
  358. }
  359. static const struct rtc_class_ops armada38x_rtc_ops = {
  360. .read_time = armada38x_rtc_read_time,
  361. .set_time = armada38x_rtc_set_time,
  362. .read_alarm = armada38x_rtc_read_alarm,
  363. .set_alarm = armada38x_rtc_set_alarm,
  364. .alarm_irq_enable = armada38x_rtc_alarm_irq_enable,
  365. .read_offset = armada38x_rtc_read_offset,
  366. .set_offset = armada38x_rtc_set_offset,
  367. };
  368. static const struct rtc_class_ops armada38x_rtc_ops_noirq = {
  369. .read_time = armada38x_rtc_read_time,
  370. .set_time = armada38x_rtc_set_time,
  371. .read_alarm = armada38x_rtc_read_alarm,
  372. .read_offset = armada38x_rtc_read_offset,
  373. .set_offset = armada38x_rtc_set_offset,
  374. };
  375. static const struct armada38x_rtc_data armada38x_data = {
  376. .update_mbus_timing = rtc_update_38x_mbus_timing_params,
  377. .read_rtc_reg = read_rtc_register_38x_wa,
  378. .clear_isr = armada38x_clear_isr,
  379. .unmask_interrupt = armada38x_unmask_interrupt,
  380. .alarm = ALARM1,
  381. };
  382. static const struct armada38x_rtc_data armada8k_data = {
  383. .update_mbus_timing = rtc_update_8k_mbus_timing_params,
  384. .read_rtc_reg = read_rtc_register,
  385. .clear_isr = armada8k_clear_isr,
  386. .unmask_interrupt = armada8k_unmask_interrupt,
  387. .alarm = ALARM2,
  388. };
  389. #ifdef CONFIG_OF
  390. static const struct of_device_id armada38x_rtc_of_match_table[] = {
  391. {
  392. .compatible = "marvell,armada-380-rtc",
  393. .data = &armada38x_data,
  394. },
  395. {
  396. .compatible = "marvell,armada-8k-rtc",
  397. .data = &armada8k_data,
  398. },
  399. {}
  400. };
  401. MODULE_DEVICE_TABLE(of, armada38x_rtc_of_match_table);
  402. #endif
  403. static __init int armada38x_rtc_probe(struct platform_device *pdev)
  404. {
  405. const struct rtc_class_ops *ops;
  406. struct resource *res;
  407. struct armada38x_rtc *rtc;
  408. const struct of_device_id *match;
  409. int ret;
  410. match = of_match_device(armada38x_rtc_of_match_table, &pdev->dev);
  411. if (!match)
  412. return -ENODEV;
  413. rtc = devm_kzalloc(&pdev->dev, sizeof(struct armada38x_rtc),
  414. GFP_KERNEL);
  415. if (!rtc)
  416. return -ENOMEM;
  417. rtc->val_to_freq = devm_kcalloc(&pdev->dev, SAMPLE_NR,
  418. sizeof(struct value_to_freq), GFP_KERNEL);
  419. if (!rtc->val_to_freq)
  420. return -ENOMEM;
  421. spin_lock_init(&rtc->lock);
  422. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc");
  423. rtc->regs = devm_ioremap_resource(&pdev->dev, res);
  424. if (IS_ERR(rtc->regs))
  425. return PTR_ERR(rtc->regs);
  426. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc-soc");
  427. rtc->regs_soc = devm_ioremap_resource(&pdev->dev, res);
  428. if (IS_ERR(rtc->regs_soc))
  429. return PTR_ERR(rtc->regs_soc);
  430. rtc->irq = platform_get_irq(pdev, 0);
  431. if (rtc->irq < 0) {
  432. dev_err(&pdev->dev, "no irq\n");
  433. return rtc->irq;
  434. }
  435. if (devm_request_irq(&pdev->dev, rtc->irq, armada38x_rtc_alarm_irq,
  436. 0, pdev->name, rtc) < 0) {
  437. dev_warn(&pdev->dev, "Interrupt not available.\n");
  438. rtc->irq = -1;
  439. }
  440. platform_set_drvdata(pdev, rtc);
  441. if (rtc->irq != -1) {
  442. device_init_wakeup(&pdev->dev, 1);
  443. ops = &armada38x_rtc_ops;
  444. } else {
  445. /*
  446. * If there is no interrupt available then we can't
  447. * use the alarm
  448. */
  449. ops = &armada38x_rtc_ops_noirq;
  450. }
  451. rtc->data = (struct armada38x_rtc_data *)match->data;
  452. /* Update RTC-MBUS bridge timing parameters */
  453. rtc->data->update_mbus_timing(rtc);
  454. rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
  455. ops, THIS_MODULE);
  456. if (IS_ERR(rtc->rtc_dev)) {
  457. ret = PTR_ERR(rtc->rtc_dev);
  458. dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
  459. return ret;
  460. }
  461. return 0;
  462. }
  463. #ifdef CONFIG_PM_SLEEP
  464. static int armada38x_rtc_suspend(struct device *dev)
  465. {
  466. if (device_may_wakeup(dev)) {
  467. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  468. return enable_irq_wake(rtc->irq);
  469. }
  470. return 0;
  471. }
  472. static int armada38x_rtc_resume(struct device *dev)
  473. {
  474. if (device_may_wakeup(dev)) {
  475. struct armada38x_rtc *rtc = dev_get_drvdata(dev);
  476. /* Update RTC-MBUS bridge timing parameters */
  477. rtc->data->update_mbus_timing(rtc);
  478. return disable_irq_wake(rtc->irq);
  479. }
  480. return 0;
  481. }
  482. #endif
  483. static SIMPLE_DEV_PM_OPS(armada38x_rtc_pm_ops,
  484. armada38x_rtc_suspend, armada38x_rtc_resume);
  485. static struct platform_driver armada38x_rtc_driver = {
  486. .driver = {
  487. .name = "armada38x-rtc",
  488. .pm = &armada38x_rtc_pm_ops,
  489. .of_match_table = of_match_ptr(armada38x_rtc_of_match_table),
  490. },
  491. };
  492. module_platform_driver_probe(armada38x_rtc_driver, armada38x_rtc_probe);
  493. MODULE_DESCRIPTION("Marvell Armada 38x RTC driver");
  494. MODULE_AUTHOR("Gregory CLEMENT <gregory.clement@free-electrons.com>");
  495. MODULE_LICENSE("GPL");