blob: 2d9bcb3ce1e3b93b7c67f0c32d0628aba91f8fd9 [file] [log] [blame]
Thomas Gleixner2025cf92019-05-29 07:18:02 -07001// SPDX-License-Identifier: GPL-2.0-only
Chris Zhong3ca1e322014-10-13 15:52:42 -07002/*
3 * RTC driver for Rockchip RK808
4 *
5 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 *
7 * Author: Chris Zhong <zyw@rock-chips.com>
8 * Author: Zhang Qing <zhangqing@rock-chips.com>
Chris Zhong3ca1e322014-10-13 15:52:42 -07009 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/rtc.h>
14#include <linux/bcd.h>
15#include <linux/mfd/rk808.h>
16#include <linux/platform_device.h>
Chris Zhong3ca1e322014-10-13 15:52:42 -070017
18/* RTC_CTRL_REG bitfields */
19#define BIT_RTC_CTRL_REG_STOP_RTC_M BIT(0)
20
21/* RK808 has a shadowed register for saving a "frozen" RTC time.
22 * When user setting "GET_TIME" to 1, the time will save in this shadowed
23 * register. If set "READSEL" to 1, user read rtc time register, actually
24 * get the time of that moment. If we need the real time, clr this bit.
25 */
26#define BIT_RTC_CTRL_REG_RTC_GET_TIME BIT(6)
27#define BIT_RTC_CTRL_REG_RTC_READSEL_M BIT(7)
28#define BIT_RTC_INTERRUPTS_REG_IT_ALARM_M BIT(3)
29#define RTC_STATUS_MASK 0xFE
30
31#define SECONDS_REG_MSK 0x7F
32#define MINUTES_REG_MAK 0x7F
33#define HOURS_REG_MSK 0x3F
34#define DAYS_REG_MSK 0x3F
35#define MONTHS_REG_MSK 0x1F
36#define YEARS_REG_MSK 0xFF
37#define WEEKS_REG_MSK 0x7
38
39/* REG_SECONDS_REG through REG_YEARS_REG is how many registers? */
40
41#define NUM_TIME_REGS (RK808_WEEKS_REG - RK808_SECONDS_REG + 1)
42#define NUM_ALARM_REGS (RK808_ALARM_YEARS_REG - RK808_ALARM_SECONDS_REG + 1)
43
Tony Xiedc790542019-06-21 06:34:38 -040044struct rk_rtc_compat_reg {
45 unsigned int ctrl_reg;
46 unsigned int status_reg;
47 unsigned int alarm_seconds_reg;
48 unsigned int int_reg;
49 unsigned int seconds_reg;
50};
51
Chris Zhong3ca1e322014-10-13 15:52:42 -070052struct rk808_rtc {
Sebastian Reichel2e830cc2022-10-20 22:42:41 +020053 struct regmap *regmap;
Chris Zhong3ca1e322014-10-13 15:52:42 -070054 struct rtc_device *rtc;
Tony Xiedc790542019-06-21 06:34:38 -040055 struct rk_rtc_compat_reg *creg;
Chris Zhong3ca1e322014-10-13 15:52:42 -070056 int irq;
57};
58
Julius Wernerf076ef42015-12-15 15:02:49 -080059/*
60 * The Rockchip calendar used by the RK808 counts November with 31 days. We use
61 * these translation functions to convert its dates to/from the Gregorian
62 * calendar used by the rest of the world. We arbitrarily define Jan 1st, 2016
63 * as the day when both calendars were in sync, and treat all other dates
64 * relative to that.
65 * NOTE: Other system software (e.g. firmware) that reads the same hardware must
66 * implement this exact same conversion algorithm, with the same anchor date.
67 */
68static time64_t nov2dec_transitions(struct rtc_time *tm)
69{
70 return (tm->tm_year + 1900) - 2016 + (tm->tm_mon + 1 > 11 ? 1 : 0);
71}
72
73static void rockchip_to_gregorian(struct rtc_time *tm)
74{
75 /* If it's Nov 31st, rtc_tm_to_time64() will count that like Dec 1st */
76 time64_t time = rtc_tm_to_time64(tm);
77 rtc_time64_to_tm(time + nov2dec_transitions(tm) * 86400, tm);
78}
79
80static void gregorian_to_rockchip(struct rtc_time *tm)
81{
82 time64_t extra_days = nov2dec_transitions(tm);
83 time64_t time = rtc_tm_to_time64(tm);
84 rtc_time64_to_tm(time - extra_days * 86400, tm);
85
86 /* Compensate if we went back over Nov 31st (will work up to 2381) */
87 if (nov2dec_transitions(tm) < extra_days) {
88 if (tm->tm_mon + 1 == 11)
89 tm->tm_mday++; /* This may result in 31! */
90 else
91 rtc_time64_to_tm(time - (extra_days - 1) * 86400, tm);
92 }
93}
94
Chris Zhong3ca1e322014-10-13 15:52:42 -070095/* Read current time and date in RTC */
96static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
97{
98 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -070099 u8 rtc_data[NUM_TIME_REGS];
100 int ret;
101
102 /* Force an update of the shadowed registers right now */
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200103 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->ctrl_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700104 BIT_RTC_CTRL_REG_RTC_GET_TIME,
Chris Zhongc412c602015-02-13 14:40:54 -0800105 BIT_RTC_CTRL_REG_RTC_GET_TIME);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700106 if (ret) {
107 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
108 return ret;
109 }
110
Chris Zhongc412c602015-02-13 14:40:54 -0800111 /*
112 * After we set the GET_TIME bit, the rtc time can't be read
113 * immediately. So we should wait up to 31.25 us, about one cycle of
114 * 32khz. If we clear the GET_TIME bit here, the time of i2c transfer
115 * certainly more than 31.25us: 16 * 2.5us at 400kHz bus frequency.
116 */
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200117 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->ctrl_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700118 BIT_RTC_CTRL_REG_RTC_GET_TIME,
Chris Zhongc412c602015-02-13 14:40:54 -0800119 0);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700120 if (ret) {
121 dev_err(dev, "Failed to update bits rtc_ctrl: %d\n", ret);
122 return ret;
123 }
124
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200125 ret = regmap_bulk_read(rk808_rtc->regmap, rk808_rtc->creg->seconds_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700126 rtc_data, NUM_TIME_REGS);
127 if (ret) {
128 dev_err(dev, "Failed to bulk read rtc_data: %d\n", ret);
129 return ret;
130 }
131
132 tm->tm_sec = bcd2bin(rtc_data[0] & SECONDS_REG_MSK);
133 tm->tm_min = bcd2bin(rtc_data[1] & MINUTES_REG_MAK);
134 tm->tm_hour = bcd2bin(rtc_data[2] & HOURS_REG_MSK);
135 tm->tm_mday = bcd2bin(rtc_data[3] & DAYS_REG_MSK);
136 tm->tm_mon = (bcd2bin(rtc_data[4] & MONTHS_REG_MSK)) - 1;
137 tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 100;
138 tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK);
Julius Wernerf076ef42015-12-15 15:02:49 -0800139 rockchip_to_gregorian(tm);
Andy Shevchenko0991e752018-12-04 23:23:22 +0200140 dev_dbg(dev, "RTC date/time %ptRd(%d) %ptRt\n", tm, tm->tm_wday, tm);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700141
142 return ret;
143}
144
145/* Set current time and date in RTC */
146static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
147{
148 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700149 u8 rtc_data[NUM_TIME_REGS];
150 int ret;
151
Andy Shevchenko0991e752018-12-04 23:23:22 +0200152 dev_dbg(dev, "set RTC date/time %ptRd(%d) %ptRt\n", tm, tm->tm_wday, tm);
Julius Wernerf076ef42015-12-15 15:02:49 -0800153 gregorian_to_rockchip(tm);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700154 rtc_data[0] = bin2bcd(tm->tm_sec);
155 rtc_data[1] = bin2bcd(tm->tm_min);
156 rtc_data[2] = bin2bcd(tm->tm_hour);
157 rtc_data[3] = bin2bcd(tm->tm_mday);
158 rtc_data[4] = bin2bcd(tm->tm_mon + 1);
159 rtc_data[5] = bin2bcd(tm->tm_year - 100);
160 rtc_data[6] = bin2bcd(tm->tm_wday);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700161
162 /* Stop RTC while updating the RTC registers */
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200163 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->ctrl_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700164 BIT_RTC_CTRL_REG_STOP_RTC_M,
165 BIT_RTC_CTRL_REG_STOP_RTC_M);
166 if (ret) {
167 dev_err(dev, "Failed to update RTC control: %d\n", ret);
168 return ret;
169 }
170
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200171 ret = regmap_bulk_write(rk808_rtc->regmap, rk808_rtc->creg->seconds_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700172 rtc_data, NUM_TIME_REGS);
173 if (ret) {
174 dev_err(dev, "Failed to bull write rtc_data: %d\n", ret);
175 return ret;
176 }
177 /* Start RTC again */
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200178 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->ctrl_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700179 BIT_RTC_CTRL_REG_STOP_RTC_M, 0);
180 if (ret) {
181 dev_err(dev, "Failed to update RTC control: %d\n", ret);
182 return ret;
183 }
184 return 0;
185}
186
187/* Read alarm time and date in RTC */
188static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
189{
190 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700191 u8 alrm_data[NUM_ALARM_REGS];
192 uint32_t int_reg;
193 int ret;
194
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200195 ret = regmap_bulk_read(rk808_rtc->regmap,
Tony Xiedc790542019-06-21 06:34:38 -0400196 rk808_rtc->creg->alarm_seconds_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700197 alrm_data, NUM_ALARM_REGS);
Tony Xiedc790542019-06-21 06:34:38 -0400198 if (ret) {
199 dev_err(dev, "Failed to read RTC alarm date REG: %d\n", ret);
200 return ret;
201 }
Chris Zhong3ca1e322014-10-13 15:52:42 -0700202
203 alrm->time.tm_sec = bcd2bin(alrm_data[0] & SECONDS_REG_MSK);
204 alrm->time.tm_min = bcd2bin(alrm_data[1] & MINUTES_REG_MAK);
205 alrm->time.tm_hour = bcd2bin(alrm_data[2] & HOURS_REG_MSK);
206 alrm->time.tm_mday = bcd2bin(alrm_data[3] & DAYS_REG_MSK);
207 alrm->time.tm_mon = (bcd2bin(alrm_data[4] & MONTHS_REG_MSK)) - 1;
208 alrm->time.tm_year = (bcd2bin(alrm_data[5] & YEARS_REG_MSK)) + 100;
Julius Wernerf076ef42015-12-15 15:02:49 -0800209 rockchip_to_gregorian(&alrm->time);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700210
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200211 ret = regmap_read(rk808_rtc->regmap, rk808_rtc->creg->int_reg, &int_reg);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700212 if (ret) {
213 dev_err(dev, "Failed to read RTC INT REG: %d\n", ret);
214 return ret;
215 }
216
Andy Shevchenko0991e752018-12-04 23:23:22 +0200217 dev_dbg(dev, "alrm read RTC date/time %ptRd(%d) %ptRt\n",
218 &alrm->time, alrm->time.tm_wday, &alrm->time);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700219
220 alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0;
221
222 return 0;
223}
224
225static int rk808_rtc_stop_alarm(struct rk808_rtc *rk808_rtc)
226{
Chris Zhong3ca1e322014-10-13 15:52:42 -0700227 int ret;
228
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200229 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->int_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700230 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0);
231
232 return ret;
233}
234
235static int rk808_rtc_start_alarm(struct rk808_rtc *rk808_rtc)
236{
Chris Zhong3ca1e322014-10-13 15:52:42 -0700237 int ret;
238
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200239 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->int_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700240 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M,
241 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
242
243 return ret;
244}
245
246static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
247{
248 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700249 u8 alrm_data[NUM_ALARM_REGS];
250 int ret;
251
252 ret = rk808_rtc_stop_alarm(rk808_rtc);
253 if (ret) {
254 dev_err(dev, "Failed to stop alarm: %d\n", ret);
255 return ret;
256 }
Andy Shevchenko0991e752018-12-04 23:23:22 +0200257 dev_dbg(dev, "alrm set RTC date/time %ptRd(%d) %ptRt\n",
258 &alrm->time, alrm->time.tm_wday, &alrm->time);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700259
Julius Wernerf076ef42015-12-15 15:02:49 -0800260 gregorian_to_rockchip(&alrm->time);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700261 alrm_data[0] = bin2bcd(alrm->time.tm_sec);
262 alrm_data[1] = bin2bcd(alrm->time.tm_min);
263 alrm_data[2] = bin2bcd(alrm->time.tm_hour);
264 alrm_data[3] = bin2bcd(alrm->time.tm_mday);
265 alrm_data[4] = bin2bcd(alrm->time.tm_mon + 1);
266 alrm_data[5] = bin2bcd(alrm->time.tm_year - 100);
267
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200268 ret = regmap_bulk_write(rk808_rtc->regmap,
Tony Xiedc790542019-06-21 06:34:38 -0400269 rk808_rtc->creg->alarm_seconds_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700270 alrm_data, NUM_ALARM_REGS);
271 if (ret) {
272 dev_err(dev, "Failed to bulk write: %d\n", ret);
273 return ret;
274 }
275 if (alrm->enabled) {
276 ret = rk808_rtc_start_alarm(rk808_rtc);
277 if (ret) {
278 dev_err(dev, "Failed to start alarm: %d\n", ret);
279 return ret;
280 }
281 }
282 return 0;
283}
284
285static int rk808_rtc_alarm_irq_enable(struct device *dev,
286 unsigned int enabled)
287{
288 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
289
290 if (enabled)
291 return rk808_rtc_start_alarm(rk808_rtc);
292
293 return rk808_rtc_stop_alarm(rk808_rtc);
294}
295
296/*
297 * We will just handle setting the frequency and make use the framework for
298 * reading the periodic interupts.
299 *
300 * @freq: Current periodic IRQ freq:
301 * bit 0: every second
302 * bit 1: every minute
303 * bit 2: every hour
304 * bit 3: every day
305 */
306static irqreturn_t rk808_alarm_irq(int irq, void *data)
307{
308 struct rk808_rtc *rk808_rtc = data;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700309 int ret;
310
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200311 ret = regmap_write(rk808_rtc->regmap, rk808_rtc->creg->status_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700312 RTC_STATUS_MASK);
313 if (ret) {
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200314 dev_err(&rk808_rtc->rtc->dev,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700315 "%s:Failed to update RTC status: %d\n", __func__, ret);
316 return ret;
317 }
318
319 rtc_update_irq(rk808_rtc->rtc, 1, RTC_IRQF | RTC_AF);
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200320 dev_dbg(&rk808_rtc->rtc->dev,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700321 "%s:irq=%d\n", __func__, irq);
322 return IRQ_HANDLED;
323}
324
325static const struct rtc_class_ops rk808_rtc_ops = {
326 .read_time = rk808_rtc_readtime,
327 .set_time = rk808_rtc_set_time,
328 .read_alarm = rk808_rtc_readalarm,
329 .set_alarm = rk808_rtc_setalarm,
330 .alarm_irq_enable = rk808_rtc_alarm_irq_enable,
331};
332
333#ifdef CONFIG_PM_SLEEP
334/* Turn off the alarm if it should not be a wake source. */
335static int rk808_rtc_suspend(struct device *dev)
336{
Kefeng Wang527bd752019-04-23 15:50:16 +0800337 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700338
339 if (device_may_wakeup(dev))
340 enable_irq_wake(rk808_rtc->irq);
341
342 return 0;
343}
344
345/* Enable the alarm if it should be enabled (in case it was disabled to
346 * prevent use as a wake source).
347 */
348static int rk808_rtc_resume(struct device *dev)
349{
Kefeng Wang527bd752019-04-23 15:50:16 +0800350 struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700351
352 if (device_may_wakeup(dev))
353 disable_irq_wake(rk808_rtc->irq);
354
355 return 0;
356}
357#endif
358
359static SIMPLE_DEV_PM_OPS(rk808_rtc_pm_ops,
360 rk808_rtc_suspend, rk808_rtc_resume);
361
Tony Xiedc790542019-06-21 06:34:38 -0400362static struct rk_rtc_compat_reg rk808_creg = {
363 .ctrl_reg = RK808_RTC_CTRL_REG,
364 .status_reg = RK808_RTC_STATUS_REG,
365 .alarm_seconds_reg = RK808_ALARM_SECONDS_REG,
366 .int_reg = RK808_RTC_INT_REG,
367 .seconds_reg = RK808_SECONDS_REG,
368};
369
370static struct rk_rtc_compat_reg rk817_creg = {
371 .ctrl_reg = RK817_RTC_CTRL_REG,
372 .status_reg = RK817_RTC_STATUS_REG,
373 .alarm_seconds_reg = RK817_ALARM_SECONDS_REG,
374 .int_reg = RK817_RTC_INT_REG,
375 .seconds_reg = RK817_SECONDS_REG,
376};
377
Chris Zhong3ca1e322014-10-13 15:52:42 -0700378static int rk808_rtc_probe(struct platform_device *pdev)
379{
380 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
381 struct rk808_rtc *rk808_rtc;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700382 int ret;
383
384 rk808_rtc = devm_kzalloc(&pdev->dev, sizeof(*rk808_rtc), GFP_KERNEL);
385 if (rk808_rtc == NULL)
386 return -ENOMEM;
387
Tony Xiedc790542019-06-21 06:34:38 -0400388 switch (rk808->variant) {
389 case RK809_ID:
390 case RK817_ID:
391 rk808_rtc->creg = &rk817_creg;
392 break;
393 default:
394 rk808_rtc->creg = &rk808_creg;
395 break;
396 }
Chris Zhong3ca1e322014-10-13 15:52:42 -0700397 platform_set_drvdata(pdev, rk808_rtc);
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200398 rk808_rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
399 if (!rk808_rtc->regmap)
400 return -ENODEV;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700401
402 /* start rtc running by default, and use shadowed timer. */
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200403 ret = regmap_update_bits(rk808_rtc->regmap, rk808_rtc->creg->ctrl_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700404 BIT_RTC_CTRL_REG_STOP_RTC_M |
405 BIT_RTC_CTRL_REG_RTC_READSEL_M,
406 BIT_RTC_CTRL_REG_RTC_READSEL_M);
407 if (ret) {
408 dev_err(&pdev->dev,
409 "Failed to update RTC control: %d\n", ret);
410 return ret;
411 }
412
Sebastian Reichel2e830cc2022-10-20 22:42:41 +0200413 ret = regmap_write(rk808_rtc->regmap, rk808_rtc->creg->status_reg,
Chris Zhong3ca1e322014-10-13 15:52:42 -0700414 RTC_STATUS_MASK);
415 if (ret) {
416 dev_err(&pdev->dev,
417 "Failed to write RTC status: %d\n", ret);
Colin Ian King725412d92018-11-01 14:53:52 +0000418 return ret;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700419 }
420
Chris Zhong3ca1e322014-10-13 15:52:42 -0700421 device_init_wakeup(&pdev->dev, 1);
422
Alexandre Belloni201fac92018-02-21 11:57:05 +0100423 rk808_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
424 if (IS_ERR(rk808_rtc->rtc))
425 return PTR_ERR(rk808_rtc->rtc);
426
427 rk808_rtc->rtc->ops = &rk808_rtc_ops;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700428
429 rk808_rtc->irq = platform_get_irq(pdev, 0);
Stephen Boydfaac9102019-07-30 11:15:39 -0700430 if (rk808_rtc->irq < 0)
Chris Zhong3ca1e322014-10-13 15:52:42 -0700431 return rk808_rtc->irq;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700432
433 /* request alarm irq of rk808 */
434 ret = devm_request_threaded_irq(&pdev->dev, rk808_rtc->irq, NULL,
435 rk808_alarm_irq, 0,
436 "RTC alarm", rk808_rtc);
437 if (ret) {
438 dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
439 rk808_rtc->irq, ret);
Alexandre Belloni201fac92018-02-21 11:57:05 +0100440 return ret;
Chris Zhong3ca1e322014-10-13 15:52:42 -0700441 }
442
Bartosz Golaszewskifdcfd852020-11-09 17:34:08 +0100443 return devm_rtc_register_device(rk808_rtc->rtc);
Chris Zhong3ca1e322014-10-13 15:52:42 -0700444}
445
446static struct platform_driver rk808_rtc_driver = {
447 .probe = rk808_rtc_probe,
448 .driver = {
449 .name = "rk808-rtc",
450 .pm = &rk808_rtc_pm_ops,
451 },
452};
453
454module_platform_driver(rk808_rtc_driver);
455
456MODULE_DESCRIPTION("RTC driver for the rk808 series PMICs");
457MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
458MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
459MODULE_LICENSE("GPL");
460MODULE_ALIAS("platform:rk808-rtc");