Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Real time clock driver for DA9052 |
| 4 | * |
| 5 | * Copyright(c) 2012 Dialog Semiconductor Ltd. |
| 6 | * |
| 7 | * Author: Dajun Dajun Chen <dajun.chen@diasemi.com> |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/rtc.h> |
Sachin Kamat | 11f54d0 | 2013-07-03 15:07:48 -0700 | [diff] [blame] | 13 | #include <linux/err.h> |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <linux/mfd/da9052/da9052.h> |
| 17 | #include <linux/mfd/da9052/reg.h> |
| 18 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 19 | #define rtc_err(rtc, fmt, ...) \ |
| 20 | dev_err(rtc->da9052->dev, "%s: " fmt, __func__, ##__VA_ARGS__) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 21 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 22 | #define DA9052_GET_TIME_RETRIES 5 |
| 23 | |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 24 | struct da9052_rtc { |
| 25 | struct rtc_device *rtc; |
| 26 | struct da9052 *da9052; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 27 | }; |
| 28 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 29 | static int da9052_rtc_enable_alarm(struct da9052_rtc *rtc, bool enable) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 30 | { |
| 31 | int ret; |
| 32 | if (enable) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 33 | ret = da9052_reg_update(rtc->da9052, DA9052_ALARM_Y_REG, |
| 34 | DA9052_ALARM_Y_ALARM_ON|DA9052_ALARM_Y_TICK_ON, |
| 35 | DA9052_ALARM_Y_ALARM_ON); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 36 | if (ret != 0) |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 37 | rtc_err(rtc, "Failed to enable ALM: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 38 | } else { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 39 | ret = da9052_reg_update(rtc->da9052, DA9052_ALARM_Y_REG, |
| 40 | DA9052_ALARM_Y_ALARM_ON|DA9052_ALARM_Y_TICK_ON, 0); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 41 | if (ret != 0) |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 42 | rtc_err(rtc, "Write error: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 43 | } |
| 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | static irqreturn_t da9052_rtc_irq(int irq, void *data) |
| 48 | { |
| 49 | struct da9052_rtc *rtc = data; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 50 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 51 | rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 52 | |
| 53 | return IRQ_HANDLED; |
| 54 | } |
| 55 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 56 | static int da9052_read_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 57 | { |
| 58 | int ret; |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 59 | uint8_t v[2][5]; |
| 60 | int idx = 1; |
| 61 | int timeout = DA9052_GET_TIME_RETRIES; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 62 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 63 | ret = da9052_group_read(rtc->da9052, DA9052_ALARM_MI_REG, 5, &v[0][0]); |
| 64 | if (ret) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 65 | rtc_err(rtc, "Failed to group read ALM: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 66 | return ret; |
| 67 | } |
| 68 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 69 | do { |
| 70 | ret = da9052_group_read(rtc->da9052, |
| 71 | DA9052_ALARM_MI_REG, 5, &v[idx][0]); |
| 72 | if (ret) { |
| 73 | rtc_err(rtc, "Failed to group read ALM: %d\n", ret); |
| 74 | return ret; |
| 75 | } |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 76 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 77 | if (memcmp(&v[0][0], &v[1][0], 5) == 0) { |
| 78 | rtc_tm->tm_year = (v[0][4] & DA9052_RTC_YEAR) + 100; |
| 79 | rtc_tm->tm_mon = (v[0][3] & DA9052_RTC_MONTH) - 1; |
| 80 | rtc_tm->tm_mday = v[0][2] & DA9052_RTC_DAY; |
| 81 | rtc_tm->tm_hour = v[0][1] & DA9052_RTC_HOUR; |
| 82 | rtc_tm->tm_min = v[0][0] & DA9052_RTC_MIN; |
Uwe Kleine-König | d2c9270 | 2016-07-11 10:05:27 +0200 | [diff] [blame] | 83 | rtc_tm->tm_sec = 0; |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 84 | |
| 85 | ret = rtc_valid_tm(rtc_tm); |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | idx = (1-idx); |
| 90 | msleep(20); |
| 91 | |
| 92 | } while (timeout--); |
| 93 | |
| 94 | rtc_err(rtc, "Timed out reading alarm time\n"); |
| 95 | |
| 96 | return -EIO; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 99 | static int da9052_set_alarm(struct da9052_rtc *rtc, struct rtc_time *rtc_tm) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 100 | { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 101 | struct da9052 *da9052 = rtc->da9052; |
| 102 | unsigned long alm_time; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 103 | int ret; |
| 104 | uint8_t v[3]; |
| 105 | |
Alexandre Belloni | 06c4e10 | 2020-03-06 08:35:47 +0100 | [diff] [blame] | 106 | alm_time = rtc_tm_to_time64(rtc_tm); |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 107 | |
| 108 | if (rtc_tm->tm_sec > 0) { |
| 109 | alm_time += 60 - rtc_tm->tm_sec; |
Alexandre Belloni | 06c4e10 | 2020-03-06 08:35:47 +0100 | [diff] [blame] | 110 | rtc_time64_to_tm(alm_time, rtc_tm); |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 111 | } |
| 112 | BUG_ON(rtc_tm->tm_sec); /* it will cause repeated irqs if not zero */ |
| 113 | |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 114 | rtc_tm->tm_year -= 100; |
| 115 | rtc_tm->tm_mon += 1; |
| 116 | |
| 117 | ret = da9052_reg_update(da9052, DA9052_ALARM_MI_REG, |
| 118 | DA9052_RTC_MIN, rtc_tm->tm_min); |
| 119 | if (ret != 0) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 120 | rtc_err(rtc, "Failed to write ALRM MIN: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | v[0] = rtc_tm->tm_hour; |
| 125 | v[1] = rtc_tm->tm_mday; |
| 126 | v[2] = rtc_tm->tm_mon; |
| 127 | |
| 128 | ret = da9052_group_write(da9052, DA9052_ALARM_H_REG, 3, v); |
| 129 | if (ret < 0) |
| 130 | return ret; |
| 131 | |
| 132 | ret = da9052_reg_update(da9052, DA9052_ALARM_Y_REG, |
| 133 | DA9052_RTC_YEAR, rtc_tm->tm_year); |
| 134 | if (ret != 0) |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 135 | rtc_err(rtc, "Failed to write ALRM YEAR: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 140 | static int da9052_rtc_get_alarm_status(struct da9052_rtc *rtc) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 141 | { |
| 142 | int ret; |
| 143 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 144 | ret = da9052_reg_read(rtc->da9052, DA9052_ALARM_Y_REG); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 145 | if (ret < 0) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 146 | rtc_err(rtc, "Failed to read ALM: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 147 | return ret; |
| 148 | } |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 149 | |
| 150 | return !!(ret&DA9052_ALARM_Y_ALARM_ON); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static int da9052_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm) |
| 154 | { |
| 155 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 156 | int ret; |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 157 | uint8_t v[2][6]; |
| 158 | int idx = 1; |
| 159 | int timeout = DA9052_GET_TIME_RETRIES; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 160 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 161 | ret = da9052_group_read(rtc->da9052, DA9052_COUNT_S_REG, 6, &v[0][0]); |
| 162 | if (ret) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 163 | rtc_err(rtc, "Failed to read RTC time : %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 164 | return ret; |
| 165 | } |
| 166 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 167 | do { |
| 168 | ret = da9052_group_read(rtc->da9052, |
| 169 | DA9052_COUNT_S_REG, 6, &v[idx][0]); |
| 170 | if (ret) { |
| 171 | rtc_err(rtc, "Failed to read RTC time : %d\n", ret); |
| 172 | return ret; |
| 173 | } |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 174 | |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 175 | if (memcmp(&v[0][0], &v[1][0], 6) == 0) { |
| 176 | rtc_tm->tm_year = (v[0][5] & DA9052_RTC_YEAR) + 100; |
| 177 | rtc_tm->tm_mon = (v[0][4] & DA9052_RTC_MONTH) - 1; |
| 178 | rtc_tm->tm_mday = v[0][3] & DA9052_RTC_DAY; |
| 179 | rtc_tm->tm_hour = v[0][2] & DA9052_RTC_HOUR; |
| 180 | rtc_tm->tm_min = v[0][1] & DA9052_RTC_MIN; |
| 181 | rtc_tm->tm_sec = v[0][0] & DA9052_RTC_SEC; |
| 182 | |
Alexandre Belloni | bb54be1 | 2018-03-02 10:08:47 +0100 | [diff] [blame] | 183 | return 0; |
Adam Ward | 03cc162 | 2015-04-16 12:45:26 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | idx = (1-idx); |
| 187 | msleep(20); |
| 188 | |
| 189 | } while (timeout--); |
| 190 | |
| 191 | rtc_err(rtc, "Timed out reading time\n"); |
| 192 | |
| 193 | return -EIO; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int da9052_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 197 | { |
| 198 | struct da9052_rtc *rtc; |
| 199 | uint8_t v[6]; |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 200 | int ret; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 201 | |
Adam Ward | ae824c4 | 2015-04-16 12:45:29 -0700 | [diff] [blame] | 202 | /* DA9052 only has 6 bits for year - to represent 2000-2063 */ |
| 203 | if ((tm->tm_year < 100) || (tm->tm_year > 163)) |
| 204 | return -EINVAL; |
| 205 | |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 206 | rtc = dev_get_drvdata(dev); |
| 207 | |
| 208 | v[0] = tm->tm_sec; |
| 209 | v[1] = tm->tm_min; |
| 210 | v[2] = tm->tm_hour; |
| 211 | v[3] = tm->tm_mday; |
| 212 | v[4] = tm->tm_mon + 1; |
| 213 | v[5] = tm->tm_year - 100; |
| 214 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 215 | ret = da9052_group_write(rtc->da9052, DA9052_COUNT_S_REG, 6, v); |
| 216 | if (ret < 0) |
| 217 | rtc_err(rtc, "failed to set RTC time: %d\n", ret); |
| 218 | return ret; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static int da9052_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 222 | { |
| 223 | int ret; |
| 224 | struct rtc_time *tm = &alrm->time; |
| 225 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
| 226 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 227 | ret = da9052_read_alarm(rtc, tm); |
| 228 | if (ret < 0) { |
| 229 | rtc_err(rtc, "failed to read RTC alarm: %d\n", ret); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 230 | return ret; |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 231 | } |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 232 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 233 | alrm->enabled = da9052_rtc_get_alarm_status(rtc); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int da9052_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 238 | { |
| 239 | int ret; |
| 240 | struct rtc_time *tm = &alrm->time; |
| 241 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
| 242 | |
Adam Ward | ae824c4 | 2015-04-16 12:45:29 -0700 | [diff] [blame] | 243 | /* DA9052 only has 6 bits for year - to represent 2000-2063 */ |
| 244 | if ((tm->tm_year < 100) || (tm->tm_year > 163)) |
| 245 | return -EINVAL; |
| 246 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 247 | ret = da9052_rtc_enable_alarm(rtc, 0); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 248 | if (ret < 0) |
| 249 | return ret; |
| 250 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 251 | ret = da9052_set_alarm(rtc, tm); |
| 252 | if (ret < 0) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 253 | return ret; |
| 254 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 255 | ret = da9052_rtc_enable_alarm(rtc, 1); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static int da9052_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 260 | { |
| 261 | struct da9052_rtc *rtc = dev_get_drvdata(dev); |
| 262 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 263 | return da9052_rtc_enable_alarm(rtc, enabled); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static const struct rtc_class_ops da9052_rtc_ops = { |
| 267 | .read_time = da9052_rtc_read_time, |
| 268 | .set_time = da9052_rtc_set_time, |
| 269 | .read_alarm = da9052_rtc_read_alarm, |
| 270 | .set_alarm = da9052_rtc_set_alarm, |
| 271 | .alarm_irq_enable = da9052_rtc_alarm_irq_enable, |
| 272 | }; |
| 273 | |
Greg Kroah-Hartman | 5a167f4 | 2012-12-21 13:09:38 -0800 | [diff] [blame] | 274 | static int da9052_rtc_probe(struct platform_device *pdev) |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 275 | { |
| 276 | struct da9052_rtc *rtc; |
| 277 | int ret; |
| 278 | |
| 279 | rtc = devm_kzalloc(&pdev->dev, sizeof(struct da9052_rtc), GFP_KERNEL); |
| 280 | if (!rtc) |
| 281 | return -ENOMEM; |
| 282 | |
| 283 | rtc->da9052 = dev_get_drvdata(pdev->dev.parent); |
| 284 | platform_set_drvdata(pdev, rtc); |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 285 | |
| 286 | ret = da9052_reg_write(rtc->da9052, DA9052_BBAT_CONT_REG, 0xFE); |
| 287 | if (ret < 0) { |
| 288 | rtc_err(rtc, |
| 289 | "Failed to setup RTC battery charging: %d\n", ret); |
| 290 | return ret; |
| 291 | } |
| 292 | |
| 293 | ret = da9052_reg_update(rtc->da9052, DA9052_ALARM_Y_REG, |
| 294 | DA9052_ALARM_Y_TICK_ON, 0); |
| 295 | if (ret != 0) |
| 296 | rtc_err(rtc, "Failed to disable TICKS: %d\n", ret); |
| 297 | |
Steve Twiss | 6406d96e | 2016-04-14 12:04:54 +0100 | [diff] [blame] | 298 | device_init_wakeup(&pdev->dev, true); |
Alexandre Belloni | d17077e | 2020-03-30 00:42:40 +0200 | [diff] [blame] | 299 | rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
Steve Twiss | 6406d96e | 2016-04-14 12:04:54 +0100 | [diff] [blame] | 300 | if (IS_ERR(rtc->rtc)) |
| 301 | return PTR_ERR(rtc->rtc); |
| 302 | |
Alexandre Belloni | d17077e | 2020-03-30 00:42:40 +0200 | [diff] [blame] | 303 | rtc->rtc->ops = &da9052_rtc_ops; |
Alexandre Belloni | 23af616 | 2020-03-06 08:35:46 +0100 | [diff] [blame] | 304 | rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
| 305 | rtc->rtc->range_max = RTC_TIMESTAMP_END_2063; |
Alexandre Belloni | d17077e | 2020-03-30 00:42:40 +0200 | [diff] [blame] | 306 | |
Bartosz Golaszewski | fdcfd85 | 2020-11-09 17:34:08 +0100 | [diff] [blame] | 307 | ret = devm_rtc_register_device(rtc->rtc); |
Alexandre Belloni | d17077e | 2020-03-30 00:42:40 +0200 | [diff] [blame] | 308 | if (ret) |
| 309 | return ret; |
| 310 | |
Anthony Olech | c2c0eed | 2014-04-03 14:49:52 -0700 | [diff] [blame] | 311 | ret = da9052_request_irq(rtc->da9052, DA9052_IRQ_ALARM, "ALM", |
Ashish Jangam | 925e8ea | 2013-03-22 15:04:44 -0700 | [diff] [blame] | 312 | da9052_rtc_irq, rtc); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 313 | if (ret != 0) { |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 314 | rtc_err(rtc, "irq registration failed: %d\n", ret); |
Devendra Naga | 007def0 | 2012-07-30 14:41:54 -0700 | [diff] [blame] | 315 | return ret; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Steve Twiss | 6406d96e | 2016-04-14 12:04:54 +0100 | [diff] [blame] | 318 | return 0; |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 321 | static struct platform_driver da9052_rtc_driver = { |
| 322 | .probe = da9052_rtc_probe, |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 323 | .driver = { |
| 324 | .name = "da9052-rtc", |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 325 | }, |
| 326 | }; |
| 327 | |
| 328 | module_platform_driver(da9052_rtc_driver); |
| 329 | |
Anthony Olech | 7c994c08 | 2014-06-06 14:35:54 -0700 | [diff] [blame] | 330 | MODULE_AUTHOR("Anthony Olech <Anthony.Olech@diasemi.com>"); |
Ashish Jangam | fef931f | 2012-03-23 15:02:36 -0700 | [diff] [blame] | 331 | MODULE_DESCRIPTION("RTC driver for Dialog DA9052 PMIC"); |
| 332 | MODULE_LICENSE("GPL"); |
| 333 | MODULE_ALIAS("platform:da9052-rtc"); |