Thomas Gleixner | 97fb5e8 | 2019-05-29 07:17:58 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 2 | /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 3 | */ |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 4 | #include <linux/of.h> |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 5 | #include <linux/module.h> |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/rtc.h> |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 8 | #include <linux/platform_device.h> |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 9 | #include <linux/pm.h> |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 10 | #include <linux/regmap.h> |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 14 | /* RTC Register offsets from RTC CTRL REG */ |
| 15 | #define PM8XXX_ALARM_CTRL_OFFSET 0x01 |
| 16 | #define PM8XXX_RTC_WRITE_OFFSET 0x02 |
| 17 | #define PM8XXX_RTC_READ_OFFSET 0x06 |
| 18 | #define PM8XXX_ALARM_RW_OFFSET 0x0A |
| 19 | |
| 20 | /* RTC_CTRL register bit fields */ |
| 21 | #define PM8xxx_RTC_ENABLE BIT(7) |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 22 | #define PM8xxx_RTC_ALARM_CLEAR BIT(0) |
Guixiong Wei | 121f54e | 2020-12-24 19:28:57 +0800 | [diff] [blame] | 23 | #define PM8xxx_RTC_ALARM_ENABLE BIT(7) |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 24 | |
| 25 | #define NUM_8_BIT_RTC_REGS 0x4 |
| 26 | |
| 27 | /** |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 28 | * struct pm8xxx_rtc_regs - describe RTC registers per PMIC versions |
| 29 | * @ctrl: base address of control register |
| 30 | * @write: base address of write register |
| 31 | * @read: base address of read register |
| 32 | * @alarm_ctrl: base address of alarm control register |
| 33 | * @alarm_ctrl2: base address of alarm control2 register |
| 34 | * @alarm_rw: base address of alarm read-write register |
| 35 | * @alarm_en: alarm enable mask |
| 36 | */ |
| 37 | struct pm8xxx_rtc_regs { |
| 38 | unsigned int ctrl; |
| 39 | unsigned int write; |
| 40 | unsigned int read; |
| 41 | unsigned int alarm_ctrl; |
| 42 | unsigned int alarm_ctrl2; |
| 43 | unsigned int alarm_rw; |
| 44 | unsigned int alarm_en; |
| 45 | }; |
| 46 | |
| 47 | /** |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 48 | * struct pm8xxx_rtc - rtc driver internal structure |
| 49 | * @rtc: rtc device for this driver. |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 50 | * @regmap: regmap used to access RTC registers |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 51 | * @allow_set_time: indicates whether writing to the RTC is allowed |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 52 | * @rtc_alarm_irq: rtc alarm irq number. |
Alexandre Belloni | 863d7b1 | 2019-11-22 11:22:10 +0100 | [diff] [blame] | 53 | * @regs: rtc registers description. |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 54 | * @rtc_dev: device structure. |
| 55 | * @ctrl_reg_lock: spinlock protecting access to ctrl_reg. |
| 56 | */ |
| 57 | struct pm8xxx_rtc { |
| 58 | struct rtc_device *rtc; |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 59 | struct regmap *regmap; |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 60 | bool allow_set_time; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 61 | int rtc_alarm_irq; |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 62 | const struct pm8xxx_rtc_regs *regs; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 63 | struct device *rtc_dev; |
| 64 | spinlock_t ctrl_reg_lock; |
| 65 | }; |
| 66 | |
| 67 | /* |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 68 | * Steps to write the RTC registers. |
| 69 | * 1. Disable alarm if enabled. |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 70 | * 2. Disable rtc if enabled. |
| 71 | * 3. Write 0x00 to LSB. |
| 72 | * 4. Write Byte[1], Byte[2], Byte[3] then Byte[0]. |
| 73 | * 5. Enable rtc if disabled in step 2. |
| 74 | * 6. Enable alarm if disabled in step 1. |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 75 | */ |
| 76 | static int pm8xxx_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 77 | { |
| 78 | int rc, i; |
| 79 | unsigned long secs, irq_flags; |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 80 | u8 value[NUM_8_BIT_RTC_REGS], alarm_enabled = 0, rtc_disabled = 0; |
| 81 | unsigned int ctrl_reg, rtc_ctrl_reg; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 82 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 83 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 84 | |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 85 | if (!rtc_dd->allow_set_time) |
| 86 | return -EACCES; |
| 87 | |
Alexandre Belloni | 4c470b2 | 2020-03-06 08:37:57 +0100 | [diff] [blame] | 88 | secs = rtc_tm_to_time64(tm); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 89 | |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 90 | dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs); |
| 91 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 92 | for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) { |
| 93 | value[i] = secs & 0xFF; |
| 94 | secs >>= 8; |
| 95 | } |
| 96 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 97 | spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 98 | |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 99 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 100 | if (rc) |
| 101 | goto rtc_rw_fail; |
| 102 | |
| 103 | if (ctrl_reg & regs->alarm_en) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 104 | alarm_enabled = 1; |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 105 | ctrl_reg &= ~regs->alarm_en; |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 106 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); |
| 107 | if (rc) { |
| 108 | dev_err(dev, "Write to RTC Alarm control register failed\n"); |
| 109 | goto rtc_rw_fail; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* Disable RTC H/w before writing on RTC register */ |
| 114 | rc = regmap_read(rtc_dd->regmap, regs->ctrl, &rtc_ctrl_reg); |
| 115 | if (rc) |
| 116 | goto rtc_rw_fail; |
| 117 | |
| 118 | if (rtc_ctrl_reg & PM8xxx_RTC_ENABLE) { |
| 119 | rtc_disabled = 1; |
| 120 | rtc_ctrl_reg &= ~PM8xxx_RTC_ENABLE; |
| 121 | rc = regmap_write(rtc_dd->regmap, regs->ctrl, rtc_ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 122 | if (rc) { |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 123 | dev_err(dev, "Write to RTC control register failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 124 | goto rtc_rw_fail; |
| 125 | } |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 126 | } |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 127 | |
| 128 | /* Write 0 to Byte[0] */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 129 | rc = regmap_write(rtc_dd->regmap, regs->write, 0); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 130 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 131 | dev_err(dev, "Write to RTC write data register failed\n"); |
| 132 | goto rtc_rw_fail; |
| 133 | } |
| 134 | |
| 135 | /* Write Byte[1], Byte[2], Byte[3] */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 136 | rc = regmap_bulk_write(rtc_dd->regmap, regs->write + 1, |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 137 | &value[1], sizeof(value) - 1); |
| 138 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 139 | dev_err(dev, "Write to RTC write data register failed\n"); |
| 140 | goto rtc_rw_fail; |
| 141 | } |
| 142 | |
| 143 | /* Write Byte[0] */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 144 | rc = regmap_write(rtc_dd->regmap, regs->write, value[0]); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 145 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 146 | dev_err(dev, "Write to RTC write data register failed\n"); |
| 147 | goto rtc_rw_fail; |
| 148 | } |
| 149 | |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 150 | /* Enable RTC H/w after writing on RTC register */ |
| 151 | if (rtc_disabled) { |
| 152 | rtc_ctrl_reg |= PM8xxx_RTC_ENABLE; |
| 153 | rc = regmap_write(rtc_dd->regmap, regs->ctrl, rtc_ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 154 | if (rc) { |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 155 | dev_err(dev, "Write to RTC control register failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 156 | goto rtc_rw_fail; |
| 157 | } |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Mohit Aggarwal | 83220bf | 2018-03-05 14:35:58 +0530 | [diff] [blame] | 160 | if (alarm_enabled) { |
| 161 | ctrl_reg |= regs->alarm_en; |
| 162 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); |
| 163 | if (rc) { |
| 164 | dev_err(dev, "Write to RTC Alarm control register failed\n"); |
| 165 | goto rtc_rw_fail; |
| 166 | } |
| 167 | } |
| 168 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 169 | rtc_rw_fail: |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 170 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 171 | |
| 172 | return rc; |
| 173 | } |
| 174 | |
| 175 | static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 176 | { |
| 177 | int rc; |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 178 | u8 value[NUM_8_BIT_RTC_REGS]; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 179 | unsigned long secs; |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 180 | unsigned int reg; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 181 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 182 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 183 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 184 | rc = regmap_bulk_read(rtc_dd->regmap, regs->read, value, sizeof(value)); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 185 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 186 | dev_err(dev, "RTC read data register failed\n"); |
| 187 | return rc; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Read the LSB again and check if there has been a carry over. |
| 192 | * If there is, redo the read operation. |
| 193 | */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 194 | rc = regmap_read(rtc_dd->regmap, regs->read, ®); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 195 | if (rc < 0) { |
| 196 | dev_err(dev, "RTC read data register failed\n"); |
| 197 | return rc; |
| 198 | } |
| 199 | |
| 200 | if (unlikely(reg < value[0])) { |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 201 | rc = regmap_bulk_read(rtc_dd->regmap, regs->read, |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 202 | value, sizeof(value)); |
| 203 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 204 | dev_err(dev, "RTC read data register failed\n"); |
| 205 | return rc; |
| 206 | } |
| 207 | } |
| 208 | |
Colin Ian King | e422808 | 2019-02-06 10:31:02 +0000 | [diff] [blame] | 209 | secs = value[0] | (value[1] << 8) | (value[2] << 16) | |
| 210 | ((unsigned long)value[3] << 24); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 211 | |
Alexandre Belloni | 4c470b2 | 2020-03-06 08:37:57 +0100 | [diff] [blame] | 212 | rtc_time64_to_tm(secs, tm); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 213 | |
Andy Shevchenko | 4f5ef6e | 2018-12-04 23:23:20 +0200 | [diff] [blame] | 214 | dev_dbg(dev, "secs = %lu, h:m:s == %ptRt, y-m-d = %ptRdr\n", secs, tm, tm); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 220 | { |
| 221 | int rc, i; |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 222 | u8 value[NUM_8_BIT_RTC_REGS]; |
| 223 | unsigned int ctrl_reg; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 224 | unsigned long secs, irq_flags; |
| 225 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 226 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 227 | |
Alexandre Belloni | 4c470b2 | 2020-03-06 08:37:57 +0100 | [diff] [blame] | 228 | secs = rtc_tm_to_time64(&alarm->time); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 229 | |
| 230 | for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) { |
| 231 | value[i] = secs & 0xFF; |
| 232 | secs >>= 8; |
| 233 | } |
| 234 | |
| 235 | spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); |
| 236 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 237 | rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 238 | sizeof(value)); |
| 239 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 240 | dev_err(dev, "Write to RTC ALARM register failed\n"); |
| 241 | goto rtc_rw_fail; |
| 242 | } |
| 243 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 244 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); |
| 245 | if (rc) |
| 246 | goto rtc_rw_fail; |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 247 | |
| 248 | if (alarm->enabled) |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 249 | ctrl_reg |= regs->alarm_en; |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 250 | else |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 251 | ctrl_reg &= ~regs->alarm_en; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 252 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 253 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 254 | if (rc) { |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 255 | dev_err(dev, "Write to RTC alarm control register failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 256 | goto rtc_rw_fail; |
| 257 | } |
| 258 | |
Andy Shevchenko | 4f5ef6e | 2018-12-04 23:23:20 +0200 | [diff] [blame] | 259 | dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n", |
| 260 | &alarm->time, &alarm->time); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 261 | rtc_rw_fail: |
| 262 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); |
| 263 | return rc; |
| 264 | } |
| 265 | |
| 266 | static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 267 | { |
| 268 | int rc; |
Guixiong Wei | 121f54e | 2020-12-24 19:28:57 +0800 | [diff] [blame] | 269 | unsigned int ctrl_reg; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 270 | u8 value[NUM_8_BIT_RTC_REGS]; |
| 271 | unsigned long secs; |
| 272 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 273 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 274 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 275 | rc = regmap_bulk_read(rtc_dd->regmap, regs->alarm_rw, value, |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 276 | sizeof(value)); |
| 277 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 278 | dev_err(dev, "RTC alarm time read failed\n"); |
| 279 | return rc; |
| 280 | } |
| 281 | |
Colin Ian King | e422808 | 2019-02-06 10:31:02 +0000 | [diff] [blame] | 282 | secs = value[0] | (value[1] << 8) | (value[2] << 16) | |
| 283 | ((unsigned long)value[3] << 24); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 284 | |
Alexandre Belloni | 4c470b2 | 2020-03-06 08:37:57 +0100 | [diff] [blame] | 285 | rtc_time64_to_tm(secs, &alarm->time); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 286 | |
Guixiong Wei | 121f54e | 2020-12-24 19:28:57 +0800 | [diff] [blame] | 287 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); |
| 288 | if (rc) { |
| 289 | dev_err(dev, "Read from RTC alarm control register failed\n"); |
| 290 | return rc; |
| 291 | } |
| 292 | alarm->enabled = !!(ctrl_reg & PM8xxx_RTC_ALARM_ENABLE); |
| 293 | |
Andy Shevchenko | 4f5ef6e | 2018-12-04 23:23:20 +0200 | [diff] [blame] | 294 | dev_dbg(dev, "Alarm set for - h:m:s=%ptRt, y-m-d=%ptRdr\n", |
| 295 | &alarm->time, &alarm->time); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static int pm8xxx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) |
| 301 | { |
| 302 | int rc; |
| 303 | unsigned long irq_flags; |
| 304 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 305 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
| 306 | unsigned int ctrl_reg; |
韩科才 | 34ce297 | 2020-03-21 19:50:17 +0800 | [diff] [blame] | 307 | u8 value[NUM_8_BIT_RTC_REGS] = {0}; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 308 | |
| 309 | spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags); |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 310 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 311 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); |
| 312 | if (rc) |
| 313 | goto rtc_rw_fail; |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 314 | |
| 315 | if (enable) |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 316 | ctrl_reg |= regs->alarm_en; |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 317 | else |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 318 | ctrl_reg &= ~regs->alarm_en; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 319 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 320 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 321 | if (rc) { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 322 | dev_err(dev, "Write to RTC control register failed\n"); |
| 323 | goto rtc_rw_fail; |
| 324 | } |
| 325 | |
韩科才 | 34ce297 | 2020-03-21 19:50:17 +0800 | [diff] [blame] | 326 | /* Clear Alarm register */ |
| 327 | if (!enable) { |
| 328 | rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value, |
| 329 | sizeof(value)); |
| 330 | if (rc) { |
| 331 | dev_err(dev, "Clear RTC ALARM register failed\n"); |
| 332 | goto rtc_rw_fail; |
| 333 | } |
| 334 | } |
| 335 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 336 | rtc_rw_fail: |
| 337 | spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); |
| 338 | return rc; |
| 339 | } |
| 340 | |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 341 | static const struct rtc_class_ops pm8xxx_rtc_ops = { |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 342 | .read_time = pm8xxx_rtc_read_time, |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 343 | .set_time = pm8xxx_rtc_set_time, |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 344 | .set_alarm = pm8xxx_rtc_set_alarm, |
| 345 | .read_alarm = pm8xxx_rtc_read_alarm, |
| 346 | .alarm_irq_enable = pm8xxx_rtc_alarm_irq_enable, |
| 347 | }; |
| 348 | |
| 349 | static irqreturn_t pm8xxx_alarm_trigger(int irq, void *dev_id) |
| 350 | { |
| 351 | struct pm8xxx_rtc *rtc_dd = dev_id; |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 352 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 353 | unsigned int ctrl_reg; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 354 | int rc; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 355 | |
| 356 | rtc_update_irq(rtc_dd->rtc, 1, RTC_IRQF | RTC_AF); |
| 357 | |
Xiaofei Tan | 5131797 | 2021-02-03 20:39:37 +0800 | [diff] [blame] | 358 | spin_lock(&rtc_dd->ctrl_reg_lock); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 359 | |
| 360 | /* Clear the alarm enable bit */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 361 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl, &ctrl_reg); |
| 362 | if (rc) { |
Xiaofei Tan | 5131797 | 2021-02-03 20:39:37 +0800 | [diff] [blame] | 363 | spin_unlock(&rtc_dd->ctrl_reg_lock); |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 364 | goto rtc_alarm_handled; |
| 365 | } |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 366 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 367 | ctrl_reg &= ~regs->alarm_en; |
| 368 | |
| 369 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl, ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 370 | if (rc) { |
Xiaofei Tan | 5131797 | 2021-02-03 20:39:37 +0800 | [diff] [blame] | 371 | spin_unlock(&rtc_dd->ctrl_reg_lock); |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 372 | dev_err(rtc_dd->rtc_dev, |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 373 | "Write to alarm control register failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 374 | goto rtc_alarm_handled; |
| 375 | } |
| 376 | |
Xiaofei Tan | 5131797 | 2021-02-03 20:39:37 +0800 | [diff] [blame] | 377 | spin_unlock(&rtc_dd->ctrl_reg_lock); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 378 | |
| 379 | /* Clear RTC alarm register */ |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 380 | rc = regmap_read(rtc_dd->regmap, regs->alarm_ctrl2, &ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 381 | if (rc) { |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 382 | dev_err(rtc_dd->rtc_dev, |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 383 | "RTC Alarm control2 register read failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 384 | goto rtc_alarm_handled; |
| 385 | } |
| 386 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 387 | ctrl_reg |= PM8xxx_RTC_ALARM_CLEAR; |
| 388 | rc = regmap_write(rtc_dd->regmap, regs->alarm_ctrl2, ctrl_reg); |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 389 | if (rc) |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 390 | dev_err(rtc_dd->rtc_dev, |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 391 | "Write to RTC Alarm control2 register failed\n"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 392 | |
| 393 | rtc_alarm_handled: |
| 394 | return IRQ_HANDLED; |
| 395 | } |
| 396 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 397 | static int pm8xxx_rtc_enable(struct pm8xxx_rtc *rtc_dd) |
| 398 | { |
| 399 | const struct pm8xxx_rtc_regs *regs = rtc_dd->regs; |
| 400 | unsigned int ctrl_reg; |
| 401 | int rc; |
| 402 | |
| 403 | /* Check if the RTC is on, else turn it on */ |
| 404 | rc = regmap_read(rtc_dd->regmap, regs->ctrl, &ctrl_reg); |
| 405 | if (rc) |
| 406 | return rc; |
| 407 | |
| 408 | if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) { |
| 409 | ctrl_reg |= PM8xxx_RTC_ENABLE; |
| 410 | rc = regmap_write(rtc_dd->regmap, regs->ctrl, ctrl_reg); |
| 411 | if (rc) |
| 412 | return rc; |
| 413 | } |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static const struct pm8xxx_rtc_regs pm8921_regs = { |
| 419 | .ctrl = 0x11d, |
| 420 | .write = 0x11f, |
| 421 | .read = 0x123, |
| 422 | .alarm_rw = 0x127, |
| 423 | .alarm_ctrl = 0x11d, |
| 424 | .alarm_ctrl2 = 0x11e, |
| 425 | .alarm_en = BIT(1), |
| 426 | }; |
| 427 | |
| 428 | static const struct pm8xxx_rtc_regs pm8058_regs = { |
| 429 | .ctrl = 0x1e8, |
| 430 | .write = 0x1ea, |
| 431 | .read = 0x1ee, |
| 432 | .alarm_rw = 0x1f2, |
| 433 | .alarm_ctrl = 0x1e8, |
| 434 | .alarm_ctrl2 = 0x1e9, |
| 435 | .alarm_en = BIT(1), |
| 436 | }; |
| 437 | |
| 438 | static const struct pm8xxx_rtc_regs pm8941_regs = { |
| 439 | .ctrl = 0x6046, |
| 440 | .write = 0x6040, |
| 441 | .read = 0x6048, |
| 442 | .alarm_rw = 0x6140, |
| 443 | .alarm_ctrl = 0x6146, |
| 444 | .alarm_ctrl2 = 0x6148, |
| 445 | .alarm_en = BIT(7), |
| 446 | }; |
| 447 | |
satya priya | c8f0ca8 | 2021-04-09 19:29:23 +0530 | [diff] [blame] | 448 | static const struct pm8xxx_rtc_regs pmk8350_regs = { |
| 449 | .ctrl = 0x6146, |
| 450 | .write = 0x6140, |
| 451 | .read = 0x6148, |
| 452 | .alarm_rw = 0x6240, |
| 453 | .alarm_ctrl = 0x6246, |
| 454 | .alarm_ctrl2 = 0x6248, |
| 455 | .alarm_en = BIT(7), |
| 456 | }; |
| 457 | |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 458 | /* |
| 459 | * Hardcoded RTC bases until IORESOURCE_REG mapping is figured out |
| 460 | */ |
| 461 | static const struct of_device_id pm8xxx_id_table[] = { |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 462 | { .compatible = "qcom,pm8921-rtc", .data = &pm8921_regs }, |
Neil Armstrong | 08655bc | 2016-08-11 15:16:44 +0200 | [diff] [blame] | 463 | { .compatible = "qcom,pm8018-rtc", .data = &pm8921_regs }, |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 464 | { .compatible = "qcom,pm8058-rtc", .data = &pm8058_regs }, |
| 465 | { .compatible = "qcom,pm8941-rtc", .data = &pm8941_regs }, |
satya priya | c8f0ca8 | 2021-04-09 19:29:23 +0530 | [diff] [blame] | 466 | { .compatible = "qcom,pmk8350-rtc", .data = &pmk8350_regs }, |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 467 | { }, |
| 468 | }; |
| 469 | MODULE_DEVICE_TABLE(of, pm8xxx_id_table); |
| 470 | |
Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 471 | static int pm8xxx_rtc_probe(struct platform_device *pdev) |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 472 | { |
| 473 | int rc; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 474 | struct pm8xxx_rtc *rtc_dd; |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 475 | const struct of_device_id *match; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 476 | |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 477 | match = of_match_node(pm8xxx_id_table, pdev->dev.of_node); |
| 478 | if (!match) |
| 479 | return -ENXIO; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 480 | |
Jingoo Han | c417299 | 2013-07-03 15:07:09 -0700 | [diff] [blame] | 481 | rtc_dd = devm_kzalloc(&pdev->dev, sizeof(*rtc_dd), GFP_KERNEL); |
Jingoo Han | 49ae425 | 2014-04-03 14:49:43 -0700 | [diff] [blame] | 482 | if (rtc_dd == NULL) |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 483 | return -ENOMEM; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 484 | |
| 485 | /* Initialise spinlock to protect RTC control register */ |
| 486 | spin_lock_init(&rtc_dd->ctrl_reg_lock); |
| 487 | |
Josh Cartwright | 5d7dc4c | 2014-04-03 14:50:11 -0700 | [diff] [blame] | 488 | rtc_dd->regmap = dev_get_regmap(pdev->dev.parent, NULL); |
| 489 | if (!rtc_dd->regmap) { |
| 490 | dev_err(&pdev->dev, "Parent regmap unavailable.\n"); |
| 491 | return -ENXIO; |
| 492 | } |
| 493 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 494 | rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0); |
Stephen Boyd | faac910 | 2019-07-30 11:15:39 -0700 | [diff] [blame] | 495 | if (rtc_dd->rtc_alarm_irq < 0) |
Jingoo Han | c417299 | 2013-07-03 15:07:09 -0700 | [diff] [blame] | 496 | return -ENXIO; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 497 | |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 498 | rtc_dd->allow_set_time = of_property_read_bool(pdev->dev.of_node, |
| 499 | "allow-set-time"); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 500 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 501 | rtc_dd->regs = match->data; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 502 | rtc_dd->rtc_dev = &pdev->dev; |
| 503 | |
Stanimir Varbanov | c8d523a | 2014-10-29 14:50:33 -0700 | [diff] [blame] | 504 | rc = pm8xxx_rtc_enable(rtc_dd); |
| 505 | if (rc) |
Jingoo Han | c417299 | 2013-07-03 15:07:09 -0700 | [diff] [blame] | 506 | return rc; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 507 | |
| 508 | platform_set_drvdata(pdev, rtc_dd); |
| 509 | |
Josh Cartwright | fda9909 | 2014-04-03 14:50:14 -0700 | [diff] [blame] | 510 | device_init_wakeup(&pdev->dev, 1); |
| 511 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 512 | /* Register the RTC device */ |
Alexandre Belloni | d5d55b7 | 2020-03-06 08:37:55 +0100 | [diff] [blame] | 513 | rtc_dd->rtc = devm_rtc_allocate_device(&pdev->dev); |
| 514 | if (IS_ERR(rtc_dd->rtc)) |
Jingoo Han | c417299 | 2013-07-03 15:07:09 -0700 | [diff] [blame] | 515 | return PTR_ERR(rtc_dd->rtc); |
Alexandre Belloni | d5d55b7 | 2020-03-06 08:37:55 +0100 | [diff] [blame] | 516 | |
| 517 | rtc_dd->rtc->ops = &pm8xxx_rtc_ops; |
Alexandre Belloni | 3cfe526 | 2020-03-06 08:37:56 +0100 | [diff] [blame] | 518 | rtc_dd->rtc->range_max = U32_MAX; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 519 | |
| 520 | /* Request the alarm IRQ */ |
Josh Cartwright | bffcbc0 | 2014-04-03 14:50:12 -0700 | [diff] [blame] | 521 | rc = devm_request_any_context_irq(&pdev->dev, rtc_dd->rtc_alarm_irq, |
| 522 | pm8xxx_alarm_trigger, |
| 523 | IRQF_TRIGGER_RISING, |
| 524 | "pm8xxx_rtc_alarm", rtc_dd); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 525 | if (rc < 0) { |
| 526 | dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc); |
Jingoo Han | c417299 | 2013-07-03 15:07:09 -0700 | [diff] [blame] | 527 | return rc; |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Bartosz Golaszewski | fdcfd85 | 2020-11-09 17:34:08 +0100 | [diff] [blame] | 530 | return devm_rtc_register_device(rtc_dd->rtc); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 533 | #ifdef CONFIG_PM_SLEEP |
| 534 | static int pm8xxx_rtc_resume(struct device *dev) |
| 535 | { |
| 536 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
| 537 | |
| 538 | if (device_may_wakeup(dev)) |
| 539 | disable_irq_wake(rtc_dd->rtc_alarm_irq); |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static int pm8xxx_rtc_suspend(struct device *dev) |
| 545 | { |
| 546 | struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev); |
| 547 | |
| 548 | if (device_may_wakeup(dev)) |
| 549 | enable_irq_wake(rtc_dd->rtc_alarm_irq); |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | #endif |
| 554 | |
Josh Cartwright | 5bed811 | 2014-04-03 14:50:10 -0700 | [diff] [blame] | 555 | static SIMPLE_DEV_PM_OPS(pm8xxx_rtc_pm_ops, |
| 556 | pm8xxx_rtc_suspend, |
| 557 | pm8xxx_rtc_resume); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 558 | |
| 559 | static struct platform_driver pm8xxx_rtc_driver = { |
| 560 | .probe = pm8xxx_rtc_probe, |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 561 | .driver = { |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 562 | .name = "rtc-pm8xxx", |
Josh Cartwright | 5a41855 | 2014-04-03 14:50:13 -0700 | [diff] [blame] | 563 | .pm = &pm8xxx_rtc_pm_ops, |
| 564 | .of_match_table = pm8xxx_id_table, |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 565 | }, |
| 566 | }; |
| 567 | |
Axel Lin | 0c4eae6 | 2012-01-10 15:10:48 -0800 | [diff] [blame] | 568 | module_platform_driver(pm8xxx_rtc_driver); |
Anirudh Ghayal | 9a9a54a | 2011-07-25 17:13:33 -0700 | [diff] [blame] | 569 | |
| 570 | MODULE_ALIAS("platform:rtc-pm8xxx"); |
| 571 | MODULE_DESCRIPTION("PMIC8xxx RTC driver"); |
| 572 | MODULE_LICENSE("GPL v2"); |
| 573 | MODULE_AUTHOR("Anirudh Ghayal <aghayal@codeaurora.org>"); |