blob: 6e51df72fd658147f5e3b033ea1c331962492809 [file] [log] [blame]
Alexandre Belloni86836d62019-04-30 11:28:21 +02001// SPDX-License-Identifier: GPL-2.0+
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +00002/*
3 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
Paul Cercueild0f744c2010-10-27 15:33:12 -07004 * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net>
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +00005 * JZ4740 SoC RTC driver
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +00006 */
7
Paul Cercueilf9eb69d2016-10-31 21:39:48 +01008#include <linux/clk.h>
Jingoo Hanc08ac4892013-07-03 15:07:06 -07009#include <linux/io.h>
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000010#include <linux/kernel.h>
Alexandre Belloni586655d2017-01-25 00:44:16 +010011#include <linux/module.h>
Paul Cercueilc05229a2016-10-31 21:39:47 +010012#include <linux/of_device.h>
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000013#include <linux/platform_device.h>
Alexandre Belloni3b2dc192019-04-30 11:28:19 +020014#include <linux/pm_wakeirq.h>
Paul Cercueilf9eb69d2016-10-31 21:39:48 +010015#include <linux/reboot.h>
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000016#include <linux/rtc.h>
17#include <linux/slab.h>
18#include <linux/spinlock.h>
19
20#define JZ_REG_RTC_CTRL 0x00
21#define JZ_REG_RTC_SEC 0x04
22#define JZ_REG_RTC_SEC_ALARM 0x08
23#define JZ_REG_RTC_REGULATOR 0x0C
24#define JZ_REG_RTC_HIBERNATE 0x20
Paul Cercueilf9eb69d2016-10-31 21:39:48 +010025#define JZ_REG_RTC_WAKEUP_FILTER 0x24
26#define JZ_REG_RTC_RESET_COUNTER 0x28
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000027#define JZ_REG_RTC_SCRATCHPAD 0x34
28
Paul Cercueilcd563202016-10-31 21:39:45 +010029/* The following are present on the jz4780 */
30#define JZ_REG_RTC_WENR 0x3C
31#define JZ_RTC_WENR_WEN BIT(31)
32
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000033#define JZ_RTC_CTRL_WRDY BIT(7)
34#define JZ_RTC_CTRL_1HZ BIT(6)
35#define JZ_RTC_CTRL_1HZ_IRQ BIT(5)
36#define JZ_RTC_CTRL_AF BIT(4)
37#define JZ_RTC_CTRL_AF_IRQ BIT(3)
38#define JZ_RTC_CTRL_AE BIT(2)
39#define JZ_RTC_CTRL_ENABLE BIT(0)
40
Paul Cercueilcd563202016-10-31 21:39:45 +010041/* Magic value to enable writes on jz4780 */
42#define JZ_RTC_WENR_MAGIC 0xA55A
43
Paul Cercueilf9eb69d2016-10-31 21:39:48 +010044#define JZ_RTC_WAKEUP_FILTER_MASK 0x0000FFE0
45#define JZ_RTC_RESET_COUNTER_MASK 0x00000FE0
46
Paul Cercueilcd563202016-10-31 21:39:45 +010047enum jz4740_rtc_type {
48 ID_JZ4740,
Paul Cercueil58407482020-03-11 19:23:16 +010049 ID_JZ4760,
Paul Cercueilcd563202016-10-31 21:39:45 +010050 ID_JZ4780,
51};
52
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000053struct jz4740_rtc {
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000054 void __iomem *base;
Paul Cercueilcd563202016-10-31 21:39:45 +010055 enum jz4740_rtc_type type;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000056
57 struct rtc_device *rtc;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000058
59 spinlock_t lock;
60};
61
Paul Cercueilf9eb69d2016-10-31 21:39:48 +010062static struct device *dev_for_power_off;
63
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000064static inline uint32_t jz4740_rtc_reg_read(struct jz4740_rtc *rtc, size_t reg)
65{
66 return readl(rtc->base + reg);
67}
68
69static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc)
70{
71 uint32_t ctrl;
Mathieu Malaterre695e38d2017-09-18 21:10:13 +020072 int timeout = 10000;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000073
74 do {
75 ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL);
76 } while (!(ctrl & JZ_RTC_CTRL_WRDY) && --timeout);
77
78 return timeout ? 0 : -EIO;
79}
80
Paul Cercueilcd563202016-10-31 21:39:45 +010081static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc)
82{
83 uint32_t ctrl;
Mathieu Malaterre695e38d2017-09-18 21:10:13 +020084 int ret, timeout = 10000;
Paul Cercueilcd563202016-10-31 21:39:45 +010085
86 ret = jz4740_rtc_wait_write_ready(rtc);
87 if (ret != 0)
88 return ret;
89
90 writel(JZ_RTC_WENR_MAGIC, rtc->base + JZ_REG_RTC_WENR);
91
92 do {
93 ctrl = readl(rtc->base + JZ_REG_RTC_WENR);
94 } while (!(ctrl & JZ_RTC_WENR_WEN) && --timeout);
95
96 return timeout ? 0 : -EIO;
97}
98
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +000099static inline int jz4740_rtc_reg_write(struct jz4740_rtc *rtc, size_t reg,
100 uint32_t val)
101{
Paul Cercueilcd563202016-10-31 21:39:45 +0100102 int ret = 0;
103
Paul Cercueil58407482020-03-11 19:23:16 +0100104 if (rtc->type >= ID_JZ4760)
Paul Cercueilcd563202016-10-31 21:39:45 +0100105 ret = jz4780_rtc_enable_write(rtc);
106 if (ret == 0)
107 ret = jz4740_rtc_wait_write_ready(rtc);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000108 if (ret == 0)
109 writel(val, rtc->base + reg);
110
111 return ret;
112}
113
114static int jz4740_rtc_ctrl_set_bits(struct jz4740_rtc *rtc, uint32_t mask,
115 bool set)
116{
117 int ret;
118 unsigned long flags;
119 uint32_t ctrl;
120
121 spin_lock_irqsave(&rtc->lock, flags);
122
123 ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL);
124
125 /* Don't clear interrupt flags by accident */
126 ctrl |= JZ_RTC_CTRL_1HZ | JZ_RTC_CTRL_AF;
127
128 if (set)
129 ctrl |= mask;
130 else
131 ctrl &= ~mask;
132
133 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_CTRL, ctrl);
134
135 spin_unlock_irqrestore(&rtc->lock, flags);
136
137 return ret;
138}
139
140static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
141{
142 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
143 uint32_t secs, secs2;
144 int timeout = 5;
145
Alexandre Belloni7fe8fce2019-04-30 11:28:20 +0200146 if (jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD) != 0x12345678)
147 return -EINVAL;
148
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000149 /* If the seconds register is read while it is updated, it can contain a
150 * bogus value. This can be avoided by making sure that two consecutive
151 * reads have the same value.
152 */
153 secs = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SEC);
154 secs2 = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SEC);
155
156 while (secs != secs2 && --timeout) {
157 secs = secs2;
158 secs2 = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SEC);
159 }
160
161 if (timeout == 0)
162 return -EIO;
163
Alexandre Bellonibe8dce92019-04-30 11:28:16 +0200164 rtc_time64_to_tm(secs, time);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000165
Alexandre Belloniab626702018-02-19 16:23:55 +0100166 return 0;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000167}
168
Alexandre Bellonie72746e2019-04-30 11:28:18 +0200169static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time)
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000170{
171 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
Alexandre Belloni7fe8fce2019-04-30 11:28:20 +0200172 int ret;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000173
Alexandre Belloni7fe8fce2019-04-30 11:28:20 +0200174 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time));
175 if (ret)
176 return ret;
177
178 return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000179}
180
181static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
182{
183 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
184 uint32_t secs;
185 uint32_t ctrl;
186
187 secs = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SEC_ALARM);
188
189 ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL);
190
191 alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
192 alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
193
Alexandre Bellonibe8dce92019-04-30 11:28:16 +0200194 rtc_time64_to_tm(secs, &alrm->time);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000195
Alexandre Bellonid10dcc952019-04-30 11:28:17 +0200196 return 0;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000197}
198
199static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
200{
201 int ret;
202 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
Alexandre Bellonibe8dce92019-04-30 11:28:16 +0200203 uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000204
205 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
206 if (!ret)
Paul Cercueild0f744c2010-10-27 15:33:12 -0700207 ret = jz4740_rtc_ctrl_set_bits(rtc,
208 JZ_RTC_CTRL_AE | JZ_RTC_CTRL_AF_IRQ, alrm->enabled);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000209
210 return ret;
211}
212
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000213static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
214{
215 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
216 return jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_AF_IRQ, enable);
217}
218
Julia Lawall34c7b3a2016-08-31 10:05:25 +0200219static const struct rtc_class_ops jz4740_rtc_ops = {
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000220 .read_time = jz4740_rtc_read_time,
Alexandre Bellonie72746e2019-04-30 11:28:18 +0200221 .set_time = jz4740_rtc_set_time,
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000222 .read_alarm = jz4740_rtc_read_alarm,
223 .set_alarm = jz4740_rtc_set_alarm,
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000224 .alarm_irq_enable = jz4740_rtc_alarm_irq_enable,
225};
226
227static irqreturn_t jz4740_rtc_irq(int irq, void *data)
228{
229 struct jz4740_rtc *rtc = data;
230 uint32_t ctrl;
231 unsigned long events = 0;
232
233 ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL);
234
235 if (ctrl & JZ_RTC_CTRL_1HZ)
236 events |= (RTC_UF | RTC_IRQF);
237
238 if (ctrl & JZ_RTC_CTRL_AF)
239 events |= (RTC_AF | RTC_IRQF);
240
241 rtc_update_irq(rtc->rtc, 1, events);
242
243 jz4740_rtc_ctrl_set_bits(rtc, JZ_RTC_CTRL_1HZ | JZ_RTC_CTRL_AF, false);
244
245 return IRQ_HANDLED;
246}
247
Alexandre Belloni819c2172016-11-08 22:20:37 +0100248static void jz4740_rtc_poweroff(struct device *dev)
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000249{
250 struct jz4740_rtc *rtc = dev_get_drvdata(dev);
251 jz4740_rtc_reg_write(rtc, JZ_REG_RTC_HIBERNATE, 1);
252}
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000253
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100254static void jz4740_rtc_power_off(void)
255{
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100256 jz4740_rtc_poweroff(dev_for_power_off);
Alexandre Belloni586655d2017-01-25 00:44:16 +0100257 kernel_halt();
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100258}
259
Paul Cercueil796be8b2020-05-06 00:13:32 +0200260static void jz4740_rtc_clk_disable(void *data)
261{
262 clk_disable_unprepare(data);
263}
264
Paul Cercueilc05229a2016-10-31 21:39:47 +0100265static const struct of_device_id jz4740_rtc_of_match[] = {
266 { .compatible = "ingenic,jz4740-rtc", .data = (void *)ID_JZ4740 },
Paul Cercueil58407482020-03-11 19:23:16 +0100267 { .compatible = "ingenic,jz4760-rtc", .data = (void *)ID_JZ4760 },
Paul Cercueilc05229a2016-10-31 21:39:47 +0100268 { .compatible = "ingenic,jz4780-rtc", .data = (void *)ID_JZ4780 },
269 {},
270};
Alexandre Belloni586655d2017-01-25 00:44:16 +0100271MODULE_DEVICE_TABLE(of, jz4740_rtc_of_match);
Paul Cercueilc05229a2016-10-31 21:39:47 +0100272
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200273static void jz4740_rtc_set_wakeup_params(struct jz4740_rtc *rtc,
274 struct device_node *np,
275 unsigned long rate)
276{
277 unsigned long wakeup_ticks, reset_ticks;
278 unsigned int min_wakeup_pin_assert_time = 60; /* Default: 60ms */
279 unsigned int reset_pin_assert_time = 100; /* Default: 100ms */
280
281 of_property_read_u32(np, "ingenic,reset-pin-assert-time-ms",
282 &reset_pin_assert_time);
283 of_property_read_u32(np, "ingenic,min-wakeup-pin-assert-time-ms",
284 &min_wakeup_pin_assert_time);
285
286 /*
287 * Set minimum wakeup pin assertion time: 100 ms.
288 * Range is 0 to 2 sec if RTC is clocked at 32 kHz.
289 */
290 wakeup_ticks = (min_wakeup_pin_assert_time * rate) / 1000;
291 if (wakeup_ticks < JZ_RTC_WAKEUP_FILTER_MASK)
292 wakeup_ticks &= JZ_RTC_WAKEUP_FILTER_MASK;
293 else
294 wakeup_ticks = JZ_RTC_WAKEUP_FILTER_MASK;
295 jz4740_rtc_reg_write(rtc, JZ_REG_RTC_WAKEUP_FILTER, wakeup_ticks);
296
297 /*
298 * Set reset pin low-level assertion time after wakeup: 60 ms.
299 * Range is 0 to 125 ms if RTC is clocked at 32 kHz.
300 */
301 reset_ticks = (reset_pin_assert_time * rate) / 1000;
302 if (reset_ticks < JZ_RTC_RESET_COUNTER_MASK)
303 reset_ticks &= JZ_RTC_RESET_COUNTER_MASK;
304 else
305 reset_ticks = JZ_RTC_RESET_COUNTER_MASK;
306 jz4740_rtc_reg_write(rtc, JZ_REG_RTC_RESET_COUNTER, reset_ticks);
307}
308
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800309static int jz4740_rtc_probe(struct platform_device *pdev)
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000310{
Paul Cercueilc61293f2020-05-06 00:13:31 +0200311 struct device *dev = &pdev->dev;
312 struct device_node *np = dev->of_node;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000313 struct jz4740_rtc *rtc;
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200314 unsigned long rate;
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200315 struct clk *clk;
316 int ret, irq;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000317
Paul Cercueilc61293f2020-05-06 00:13:31 +0200318 rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000319 if (!rtc)
320 return -ENOMEM;
321
Paul Cercueil24e1f2c2020-05-06 00:13:30 +0200322 rtc->type = (enum jz4740_rtc_type)device_get_match_data(dev);
Paul Cercueilcd563202016-10-31 21:39:45 +0100323
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200324 irq = platform_get_irq(pdev, 0);
325 if (irq < 0)
Paul Cercueil15eeadd2020-05-06 00:13:35 +0200326 return irq;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000327
YueHaibing09ef18b2019-10-06 18:29:20 +0800328 rtc->base = devm_platform_ioremap_resource(pdev, 0);
Jingoo Han3b6aa902014-04-03 14:49:50 -0700329 if (IS_ERR(rtc->base))
330 return PTR_ERR(rtc->base);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000331
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200332 clk = devm_clk_get(dev, "rtc");
333 if (IS_ERR(clk)) {
Paul Cercueilc61293f2020-05-06 00:13:31 +0200334 dev_err(dev, "Failed to get RTC clock\n");
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200335 return PTR_ERR(clk);
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100336 }
337
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200338 ret = clk_prepare_enable(clk);
Paul Cercueil796be8b2020-05-06 00:13:32 +0200339 if (ret) {
340 dev_err(dev, "Failed to enable clock\n");
341 return ret;
342 }
343
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200344 ret = devm_add_action_or_reset(dev, jz4740_rtc_clk_disable, clk);
Paul Cercueil796be8b2020-05-06 00:13:32 +0200345 if (ret) {
346 dev_err(dev, "Failed to register devm action\n");
347 return ret;
348 }
349
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000350 spin_lock_init(&rtc->lock);
351
352 platform_set_drvdata(pdev, rtc);
353
Paul Cercueilc61293f2020-05-06 00:13:31 +0200354 device_init_wakeup(dev, 1);
Paul Cercueild0f744c2010-10-27 15:33:12 -0700355
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200356 ret = dev_pm_set_wake_irq(dev, irq);
Alexandre Belloni3b2dc192019-04-30 11:28:19 +0200357 if (ret) {
Paul Cercueilc61293f2020-05-06 00:13:31 +0200358 dev_err(dev, "Failed to set wake irq: %d\n", ret);
Alexandre Belloni3b2dc192019-04-30 11:28:19 +0200359 return ret;
360 }
361
Paul Cercueilc61293f2020-05-06 00:13:31 +0200362 rtc->rtc = devm_rtc_allocate_device(dev);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000363 if (IS_ERR(rtc->rtc)) {
364 ret = PTR_ERR(rtc->rtc);
Paul Cercueilc61293f2020-05-06 00:13:31 +0200365 dev_err(dev, "Failed to allocate rtc device: %d\n", ret);
Alexandre Bellonia7ab6be2019-04-30 11:28:15 +0200366 return ret;
367 }
368
369 rtc->rtc->ops = &jz4740_rtc_ops;
370 rtc->rtc->range_max = U32_MAX;
371
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200372 rate = clk_get_rate(clk);
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200373 jz4740_rtc_set_wakeup_params(rtc, np, rate);
374
Paul Cercueil378252b2020-05-06 00:13:36 +0200375 /* Each 1 Hz pulse should happen after (rate) ticks */
376 jz4740_rtc_reg_write(rtc, JZ_REG_RTC_REGULATOR, rate - 1);
377
Bartosz Golaszewskifdcfd852020-11-09 17:34:08 +0100378 ret = devm_rtc_register_device(rtc->rtc);
Alexandre Belloni44c638c2019-08-19 00:00:41 +0200379 if (ret)
Jingoo Hanc08ac4892013-07-03 15:07:06 -0700380 return ret;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000381
Paul Cercueil77d8f3c2020-05-06 00:13:34 +0200382 ret = devm_request_irq(dev, irq, jz4740_rtc_irq, 0,
Paul Cercueilc61293f2020-05-06 00:13:31 +0200383 pdev->name, rtc);
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000384 if (ret) {
Paul Cercueilc61293f2020-05-06 00:13:31 +0200385 dev_err(dev, "Failed to request rtc irq: %d\n", ret);
Jingoo Hanc08ac4892013-07-03 15:07:06 -0700386 return ret;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000387 }
388
Paul Cercueil24e1f2c2020-05-06 00:13:30 +0200389 if (of_device_is_system_power_controller(np)) {
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200390 dev_for_power_off = dev;
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100391
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200392 if (!pm_power_off)
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100393 pm_power_off = jz4740_rtc_power_off;
Paul Cercueilfe0557f2020-05-06 00:13:33 +0200394 else
Paul Cercueilc61293f2020-05-06 00:13:31 +0200395 dev_warn(dev, "Poweroff handler already present!\n");
Paul Cercueilf9eb69d2016-10-31 21:39:48 +0100396 }
397
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000398 return 0;
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000399}
400
Axel Lin681d0372012-01-10 15:10:55 -0800401static struct platform_driver jz4740_rtc_driver = {
Paul Cercueild0f744c2010-10-27 15:33:12 -0700402 .probe = jz4740_rtc_probe,
Paul Cercueild0f744c2010-10-27 15:33:12 -0700403 .driver = {
404 .name = "jz4740-rtc",
Paul Cercueil24e1f2c2020-05-06 00:13:30 +0200405 .of_match_table = jz4740_rtc_of_match,
Lars-Peter Clausen3bf0eea2010-06-19 18:29:50 +0000406 },
407};
408
Alexandre Belloni586655d2017-01-25 00:44:16 +0100409module_platform_driver(jz4740_rtc_driver);
410
411MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
412MODULE_LICENSE("GPL");
413MODULE_DESCRIPTION("RTC driver for the JZ4740 SoC\n");
414MODULE_ALIAS("platform:jz4740-rtc");