blob: d578e40d5a506308a76307a5050fd61552fc9420 [file] [log] [blame]
dmitry pervushindf17f632009-09-22 16:46:26 -07001/*
2 * Freescale STMP37XX/STMP378X Real Time Clock driver
3 *
4 * Copyright (c) 2007 Sigmatel, Inc.
5 * Peter Hartley, <peter.hartley@sigmatel.com>
6 *
7 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
8 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
Wolfram Sang7e794cb2011-05-25 12:56:53 +02009 * Copyright 2011 Wolfram Sang, Pengutronix e.K.
dmitry pervushindf17f632009-09-22 16:46:26 -070010 */
11
12/*
13 * The code contained herein is licensed under the GNU General Public
14 * License. You may obtain a copy of the GNU General Public License
15 * Version 2 or later at the following locations:
16 *
17 * http://www.opensource.org/licenses/gpl-license.html
18 * http://www.gnu.org/copyleft/gpl.html
19 */
20#include <linux/kernel.h>
21#include <linux/module.h>
Wolfram Sangb5167152011-05-25 12:56:52 +020022#include <linux/io.h>
dmitry pervushindf17f632009-09-22 16:46:26 -070023#include <linux/init.h>
24#include <linux/platform_device.h>
25#include <linux/interrupt.h>
Lothar Waßmann28a0c882013-08-13 16:00:56 -070026#include <linux/delay.h>
dmitry pervushindf17f632009-09-22 16:46:26 -070027#include <linux/rtc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Marek Vasutdd8d20a2012-06-26 16:29:27 +080029#include <linux/of_device.h>
Sachin Kamatc8a60462013-02-21 16:44:28 -080030#include <linux/of.h>
Wolfram Sang1a71fb82011-09-27 22:21:37 +020031#include <linux/stmp_device.h>
32#include <linux/stmp3xxx_rtc_wdt.h>
dmitry pervushindf17f632009-09-22 16:46:26 -070033
Wolfram Sang47eac332011-05-25 12:56:49 +020034#define STMP3XXX_RTC_CTRL 0x0
35#define STMP3XXX_RTC_CTRL_ALARM_IRQ_EN 0x00000001
36#define STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN 0x00000002
37#define STMP3XXX_RTC_CTRL_ALARM_IRQ 0x00000004
Wolfram Sang1a71fb82011-09-27 22:21:37 +020038#define STMP3XXX_RTC_CTRL_WATCHDOGEN 0x00000010
Wolfram Sang47eac332011-05-25 12:56:49 +020039
40#define STMP3XXX_RTC_STAT 0x10
41#define STMP3XXX_RTC_STAT_STALE_SHIFT 16
42#define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000
Uwe Kleine-König7f48b212015-04-16 12:45:04 -070043#define STMP3XXX_RTC_STAT_XTAL32000_PRESENT 0x10000000
44#define STMP3XXX_RTC_STAT_XTAL32768_PRESENT 0x08000000
Wolfram Sang47eac332011-05-25 12:56:49 +020045
46#define STMP3XXX_RTC_SECONDS 0x30
47
48#define STMP3XXX_RTC_ALARM 0x40
49
Wolfram Sang1a71fb82011-09-27 22:21:37 +020050#define STMP3XXX_RTC_WATCHDOG 0x50
51
Wolfram Sang47eac332011-05-25 12:56:49 +020052#define STMP3XXX_RTC_PERSISTENT0 0x60
Uwe Kleine-König7f48b212015-04-16 12:45:04 -070053#define STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE (1 << 0)
54#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN (1 << 1)
55#define STMP3XXX_RTC_PERSISTENT0_ALARM_EN (1 << 2)
56#define STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP (1 << 4)
57#define STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP (1 << 5)
58#define STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ (1 << 6)
59#define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE (1 << 7)
dmitry pervushindf17f632009-09-22 16:46:26 -070060
Wolfram Sang1a71fb82011-09-27 22:21:37 +020061#define STMP3XXX_RTC_PERSISTENT1 0x70
62/* missing bitmask in headers */
63#define STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER 0x80000000
64
dmitry pervushindf17f632009-09-22 16:46:26 -070065struct stmp3xxx_rtc_data {
66 struct rtc_device *rtc;
dmitry pervushindf17f632009-09-22 16:46:26 -070067 void __iomem *io;
Wolfram Sang7e794cb2011-05-25 12:56:53 +020068 int irq_alarm;
dmitry pervushindf17f632009-09-22 16:46:26 -070069};
70
Wolfram Sang1a71fb82011-09-27 22:21:37 +020071#if IS_ENABLED(CONFIG_STMP3XXX_RTC_WATCHDOG)
72/**
73 * stmp3xxx_wdt_set_timeout - configure the watchdog inside the STMP3xxx RTC
74 * @dev: the parent device of the watchdog (= the RTC)
75 * @timeout: the desired value for the timeout register of the watchdog.
76 * 0 disables the watchdog
77 *
78 * The watchdog needs one register and two bits which are in the RTC domain.
79 * To handle the resource conflict, the RTC driver will create another
80 * platform_device for the watchdog driver as a child of the RTC device.
81 * The watchdog driver is passed the below accessor function via platform_data
82 * to configure the watchdog. Locking is not needed because accessing SET/CLR
83 * registers is atomic.
84 */
85
86static void stmp3xxx_wdt_set_timeout(struct device *dev, u32 timeout)
87{
88 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
89
90 if (timeout) {
91 writel(timeout, rtc_data->io + STMP3XXX_RTC_WATCHDOG);
92 writel(STMP3XXX_RTC_CTRL_WATCHDOGEN,
93 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_SET);
94 writel(STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER,
95 rtc_data->io + STMP3XXX_RTC_PERSISTENT1 + STMP_OFFSET_REG_SET);
96 } else {
97 writel(STMP3XXX_RTC_CTRL_WATCHDOGEN,
98 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
99 writel(STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER,
100 rtc_data->io + STMP3XXX_RTC_PERSISTENT1 + STMP_OFFSET_REG_CLR);
101 }
102}
103
104static struct stmp3xxx_wdt_pdata wdt_pdata = {
105 .wdt_set_timeout = stmp3xxx_wdt_set_timeout,
106};
107
108static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
109{
Sudip Mukherjee34976102016-04-30 20:11:30 +0100110 int rc = -1;
Wolfram Sang1a71fb82011-09-27 22:21:37 +0200111 struct platform_device *wdt_pdev =
112 platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id);
113
114 if (wdt_pdev) {
115 wdt_pdev->dev.parent = &rtc_pdev->dev;
116 wdt_pdev->dev.platform_data = &wdt_pdata;
Sudip Mukherjee34976102016-04-30 20:11:30 +0100117 rc = platform_device_add(wdt_pdev);
Wolfram Sang1a71fb82011-09-27 22:21:37 +0200118 }
Sudip Mukherjee34976102016-04-30 20:11:30 +0100119
120 if (rc)
121 dev_err(&rtc_pdev->dev,
122 "failed to register stmp3xxx_rtc_wdt\n");
Wolfram Sang1a71fb82011-09-27 22:21:37 +0200123}
124#else
125static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
126{
127}
128#endif /* CONFIG_STMP3XXX_RTC_WATCHDOG */
129
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700130static int stmp3xxx_wait_time(struct stmp3xxx_rtc_data *rtc_data)
dmitry pervushindf17f632009-09-22 16:46:26 -0700131{
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700132 int timeout = 5000; /* 3ms according to i.MX28 Ref Manual */
dmitry pervushindf17f632009-09-22 16:46:26 -0700133 /*
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700134 * The i.MX28 Applications Processor Reference Manual, Rev. 1, 2010
135 * states:
136 * | The order in which registers are updated is
137 * | Persistent 0, 1, 2, 3, 4, 5, Alarm, Seconds.
138 * | (This list is in bitfield order, from LSB to MSB, as they would
139 * | appear in the STALE_REGS and NEW_REGS bitfields of the HW_RTC_STAT
140 * | register. For example, the Seconds register corresponds to
141 * | STALE_REGS or NEW_REGS containing 0x80.)
dmitry pervushindf17f632009-09-22 16:46:26 -0700142 */
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700143 do {
144 if (!(readl(rtc_data->io + STMP3XXX_RTC_STAT) &
145 (0x80 << STMP3XXX_RTC_STAT_STALE_SHIFT)))
146 return 0;
147 udelay(1);
148 } while (--timeout > 0);
149 return (readl(rtc_data->io + STMP3XXX_RTC_STAT) &
150 (0x80 << STMP3XXX_RTC_STAT_STALE_SHIFT)) ? -ETIME : 0;
dmitry pervushindf17f632009-09-22 16:46:26 -0700151}
152
153/* Time read/write */
154static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
155{
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700156 int ret;
dmitry pervushindf17f632009-09-22 16:46:26 -0700157 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
158
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700159 ret = stmp3xxx_wait_time(rtc_data);
160 if (ret)
161 return ret;
162
Wolfram Sangb5167152011-05-25 12:56:52 +0200163 rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm);
dmitry pervushindf17f632009-09-22 16:46:26 -0700164 return 0;
165}
166
167static int stmp3xxx_rtc_set_mmss(struct device *dev, unsigned long t)
168{
169 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
170
Wolfram Sangb5167152011-05-25 12:56:52 +0200171 writel(t, rtc_data->io + STMP3XXX_RTC_SECONDS);
Lothar Waßmann28a0c882013-08-13 16:00:56 -0700172 return stmp3xxx_wait_time(rtc_data);
dmitry pervushindf17f632009-09-22 16:46:26 -0700173}
174
175/* interrupt(s) handler */
176static irqreturn_t stmp3xxx_rtc_interrupt(int irq, void *dev_id)
177{
178 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev_id);
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200179 u32 status = readl(rtc_data->io + STMP3XXX_RTC_CTRL);
dmitry pervushindf17f632009-09-22 16:46:26 -0700180
Wolfram Sang47eac332011-05-25 12:56:49 +0200181 if (status & STMP3XXX_RTC_CTRL_ALARM_IRQ) {
Wolfram Sangb5167152011-05-25 12:56:52 +0200182 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ,
Harald Geyer24417822015-10-02 20:18:01 +0000183 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200184 rtc_update_irq(rtc_data->rtc, 1, RTC_AF | RTC_IRQF);
185 return IRQ_HANDLED;
dmitry pervushindf17f632009-09-22 16:46:26 -0700186 }
187
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200188 return IRQ_NONE;
dmitry pervushindf17f632009-09-22 16:46:26 -0700189}
190
191static int stmp3xxx_alarm_irq_enable(struct device *dev, unsigned int enabled)
192{
193 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
dmitry pervushindf17f632009-09-22 16:46:26 -0700194
195 if (enabled) {
Wolfram Sangb5167152011-05-25 12:56:52 +0200196 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
197 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000198 rtc_data->io + STMP3XXX_RTC_PERSISTENT0 +
199 STMP_OFFSET_REG_SET);
Wolfram Sangb5167152011-05-25 12:56:52 +0200200 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000201 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_SET);
dmitry pervushindf17f632009-09-22 16:46:26 -0700202 } else {
Wolfram Sangb5167152011-05-25 12:56:52 +0200203 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
204 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000205 rtc_data->io + STMP3XXX_RTC_PERSISTENT0 +
206 STMP_OFFSET_REG_CLR);
Wolfram Sangb5167152011-05-25 12:56:52 +0200207 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000208 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
dmitry pervushindf17f632009-09-22 16:46:26 -0700209 }
210 return 0;
211}
212
dmitry pervushindf17f632009-09-22 16:46:26 -0700213static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
214{
215 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
216
Wolfram Sangb5167152011-05-25 12:56:52 +0200217 rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time);
dmitry pervushindf17f632009-09-22 16:46:26 -0700218 return 0;
219}
220
221static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
222{
223 unsigned long t;
224 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
225
226 rtc_tm_to_time(&alm->time, &t);
Wolfram Sangb5167152011-05-25 12:56:52 +0200227 writel(t, rtc_data->io + STMP3XXX_RTC_ALARM);
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200228
229 stmp3xxx_alarm_irq_enable(dev, alm->enabled);
230
dmitry pervushindf17f632009-09-22 16:46:26 -0700231 return 0;
232}
233
Julia Lawall34c7b3a2016-08-31 10:05:25 +0200234static const struct rtc_class_ops stmp3xxx_rtc_ops = {
dmitry pervushindf17f632009-09-22 16:46:26 -0700235 .alarm_irq_enable =
236 stmp3xxx_alarm_irq_enable,
dmitry pervushindf17f632009-09-22 16:46:26 -0700237 .read_time = stmp3xxx_rtc_gettime,
238 .set_mmss = stmp3xxx_rtc_set_mmss,
239 .read_alarm = stmp3xxx_rtc_read_alarm,
240 .set_alarm = stmp3xxx_rtc_set_alarm,
241};
242
243static int stmp3xxx_rtc_remove(struct platform_device *pdev)
244{
245 struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(pdev);
246
247 if (!rtc_data)
248 return 0;
249
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200250 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000251 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
dmitry pervushindf17f632009-09-22 16:46:26 -0700252
253 return 0;
254}
255
256static int stmp3xxx_rtc_probe(struct platform_device *pdev)
257{
258 struct stmp3xxx_rtc_data *rtc_data;
259 struct resource *r;
Uwe Kleine-König7f48b212015-04-16 12:45:04 -0700260 u32 rtc_stat;
261 u32 pers0_set, pers0_clr;
262 u32 crystalfreq = 0;
dmitry pervushindf17f632009-09-22 16:46:26 -0700263 int err;
264
Jingoo Han87a81422013-04-29 16:20:55 -0700265 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL);
dmitry pervushindf17f632009-09-22 16:46:26 -0700266 if (!rtc_data)
267 return -ENOMEM;
268
269 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
270 if (!r) {
271 dev_err(&pdev->dev, "failed to get resource\n");
Jingoo Han87a81422013-04-29 16:20:55 -0700272 return -ENXIO;
dmitry pervushindf17f632009-09-22 16:46:26 -0700273 }
274
Jingoo Han87a81422013-04-29 16:20:55 -0700275 rtc_data->io = devm_ioremap(&pdev->dev, r->start, resource_size(r));
dmitry pervushindf17f632009-09-22 16:46:26 -0700276 if (!rtc_data->io) {
277 dev_err(&pdev->dev, "ioremap failed\n");
Jingoo Han87a81422013-04-29 16:20:55 -0700278 return -EIO;
dmitry pervushindf17f632009-09-22 16:46:26 -0700279 }
280
281 rtc_data->irq_alarm = platform_get_irq(pdev, 0);
dmitry pervushindf17f632009-09-22 16:46:26 -0700282
Uwe Kleine-König7f48b212015-04-16 12:45:04 -0700283 rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT);
284 if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) {
dmitry pervushindf17f632009-09-22 16:46:26 -0700285 dev_err(&pdev->dev, "no device onboard\n");
Jingoo Han87a81422013-04-29 16:20:55 -0700286 return -ENODEV;
dmitry pervushindf17f632009-09-22 16:46:26 -0700287 }
288
Wolfram Sanga91d2ba2011-05-25 12:56:51 +0200289 platform_set_drvdata(pdev, rtc_data);
290
Fabio Estevam4e80b182013-07-08 16:00:45 -0700291 err = stmp_reset_block(rtc_data->io);
292 if (err) {
293 dev_err(&pdev->dev, "stmp_reset_block failed: %d\n", err);
294 return err;
295 }
296
Uwe Kleine-König7f48b212015-04-16 12:45:04 -0700297 /*
298 * Obviously the rtc needs a clock input to be able to run.
299 * This clock can be provided by an external 32k crystal. If that one is
300 * missing XTAL must not be disabled in suspend which consumes a
301 * lot of power. Normally the presence and exact frequency (supported
302 * are 32000 Hz and 32768 Hz) is detectable from fuses, but as reality
303 * proves these fuses are not blown correctly on all machines, so the
304 * frequency can be overridden in the device tree.
305 */
306 if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32000_PRESENT)
307 crystalfreq = 32000;
308 else if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32768_PRESENT)
309 crystalfreq = 32768;
310
311 of_property_read_u32(pdev->dev.of_node, "stmp,crystal-freq",
312 &crystalfreq);
313
314 switch (crystalfreq) {
315 case 32000:
316 /* keep 32kHz crystal running in low-power mode */
317 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ |
318 STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
319 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
320 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP;
321 break;
322 case 32768:
323 /* keep 32.768kHz crystal running in low-power mode */
324 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
325 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
326 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP |
327 STMP3XXX_RTC_PERSISTENT0_XTAL32_FREQ;
328 break;
329 default:
330 dev_warn(&pdev->dev,
331 "invalid crystal-freq specified in device-tree. Assuming no crystal\n");
332 /* fall-through */
333 case 0:
334 /* keep XTAL on in low-power mode */
335 pers0_set = STMP3XXX_RTC_PERSISTENT0_XTAL24MHZ_PWRUP;
336 pers0_clr = STMP3XXX_RTC_PERSISTENT0_XTAL32KHZ_PWRUP |
337 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE;
338 }
339
Harald Geyer24417822015-10-02 20:18:01 +0000340 writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0 +
341 STMP_OFFSET_REG_SET);
Uwe Kleine-König7f48b212015-04-16 12:45:04 -0700342
Wolfram Sangb5167152011-05-25 12:56:52 +0200343 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
Wolfram Sang47eac332011-05-25 12:56:49 +0200344 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
Uwe Kleine-König7f48b212015-04-16 12:45:04 -0700345 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr,
Harald Geyer24417822015-10-02 20:18:01 +0000346 rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + STMP_OFFSET_REG_CLR);
Wolfram Sanga91d2ba2011-05-25 12:56:51 +0200347
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200348 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN |
349 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
Harald Geyer24417822015-10-02 20:18:01 +0000350 rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200351
Jingoo Han87a81422013-04-29 16:20:55 -0700352 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
dmitry pervushindf17f632009-09-22 16:46:26 -0700353 &stmp3xxx_rtc_ops, THIS_MODULE);
Jingoo Handfd2a172013-07-03 15:06:37 -0700354 if (IS_ERR(rtc_data->rtc))
355 return PTR_ERR(rtc_data->rtc);
dmitry pervushindf17f632009-09-22 16:46:26 -0700356
Jingoo Han87a81422013-04-29 16:20:55 -0700357 err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
358 stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
dmitry pervushindf17f632009-09-22 16:46:26 -0700359 if (err) {
360 dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
361 rtc_data->irq_alarm);
Jingoo Handfd2a172013-07-03 15:06:37 -0700362 return err;
dmitry pervushindf17f632009-09-22 16:46:26 -0700363 }
dmitry pervushindf17f632009-09-22 16:46:26 -0700364
Wolfram Sang1a71fb82011-09-27 22:21:37 +0200365 stmp3xxx_wdt_register(pdev);
dmitry pervushindf17f632009-09-22 16:46:26 -0700366 return 0;
dmitry pervushindf17f632009-09-22 16:46:26 -0700367}
368
Jingoo Hanef69a7f2013-04-29 16:21:03 -0700369#ifdef CONFIG_PM_SLEEP
370static int stmp3xxx_rtc_suspend(struct device *dev)
dmitry pervushindf17f632009-09-22 16:46:26 -0700371{
372 return 0;
373}
374
Jingoo Hanef69a7f2013-04-29 16:21:03 -0700375static int stmp3xxx_rtc_resume(struct device *dev)
dmitry pervushindf17f632009-09-22 16:46:26 -0700376{
Jingoo Hanef69a7f2013-04-29 16:21:03 -0700377 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
dmitry pervushindf17f632009-09-22 16:46:26 -0700378
Shawn Guo36d1da12013-03-28 23:13:14 +0800379 stmp_reset_block(rtc_data->io);
Wolfram Sangb5167152011-05-25 12:56:52 +0200380 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
Wolfram Sang47eac332011-05-25 12:56:49 +0200381 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN |
382 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE,
Harald Geyer24417822015-10-02 20:18:01 +0000383 rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + STMP_OFFSET_REG_CLR);
dmitry pervushindf17f632009-09-22 16:46:26 -0700384 return 0;
385}
dmitry pervushindf17f632009-09-22 16:46:26 -0700386#endif
387
Jingoo Hanef69a7f2013-04-29 16:21:03 -0700388static SIMPLE_DEV_PM_OPS(stmp3xxx_rtc_pm_ops, stmp3xxx_rtc_suspend,
389 stmp3xxx_rtc_resume);
390
Marek Vasutdd8d20a2012-06-26 16:29:27 +0800391static const struct of_device_id rtc_dt_ids[] = {
392 { .compatible = "fsl,stmp3xxx-rtc", },
393 { /* sentinel */ }
394};
395MODULE_DEVICE_TABLE(of, rtc_dt_ids);
396
dmitry pervushindf17f632009-09-22 16:46:26 -0700397static struct platform_driver stmp3xxx_rtcdrv = {
398 .probe = stmp3xxx_rtc_probe,
399 .remove = stmp3xxx_rtc_remove,
dmitry pervushindf17f632009-09-22 16:46:26 -0700400 .driver = {
401 .name = "stmp3xxx-rtc",
Jingoo Hanef69a7f2013-04-29 16:21:03 -0700402 .pm = &stmp3xxx_rtc_pm_ops,
Sachin Kamat462a4652013-11-12 15:10:58 -0800403 .of_match_table = rtc_dt_ids,
dmitry pervushindf17f632009-09-22 16:46:26 -0700404 },
405};
406
Axel Lin0c4eae62012-01-10 15:10:48 -0800407module_platform_driver(stmp3xxx_rtcdrv);
dmitry pervushindf17f632009-09-22 16:46:26 -0700408
409MODULE_DESCRIPTION("STMP3xxx RTC Driver");
Wolfram Sang7e794cb2011-05-25 12:56:53 +0200410MODULE_AUTHOR("dmitry pervushin <dpervushin@embeddedalley.com> and "
411 "Wolfram Sang <w.sang@pengutronix.de>");
dmitry pervushindf17f632009-09-22 16:46:26 -0700412MODULE_LICENSE("GPL");