dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 9 | * Copyright 2011 Wolfram Sang, Pengutronix e.K. |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 10 | */ |
| 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 Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 22 | #include <linux/io.h> |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/rtc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Marek Vasut | dd8d20a | 2012-06-26 16:29:27 +0800 | [diff] [blame] | 28 | #include <linux/of_device.h> |
Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 29 | #include <linux/of.h> |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 30 | #include <linux/stmp_device.h> |
| 31 | #include <linux/stmp3xxx_rtc_wdt.h> |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 32 | |
Wolfram Sang | 46b2121 | 2011-05-25 12:56:50 +0200 | [diff] [blame] | 33 | #include <mach/common.h> |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 34 | |
| 35 | #define STMP3XXX_RTC_CTRL 0x0 |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 36 | #define STMP3XXX_RTC_CTRL_SET 0x4 |
| 37 | #define STMP3XXX_RTC_CTRL_CLR 0x8 |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 38 | #define STMP3XXX_RTC_CTRL_ALARM_IRQ_EN 0x00000001 |
| 39 | #define STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN 0x00000002 |
| 40 | #define STMP3XXX_RTC_CTRL_ALARM_IRQ 0x00000004 |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 41 | #define STMP3XXX_RTC_CTRL_WATCHDOGEN 0x00000010 |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 42 | |
| 43 | #define STMP3XXX_RTC_STAT 0x10 |
| 44 | #define STMP3XXX_RTC_STAT_STALE_SHIFT 16 |
| 45 | #define STMP3XXX_RTC_STAT_RTC_PRESENT 0x80000000 |
| 46 | |
| 47 | #define STMP3XXX_RTC_SECONDS 0x30 |
| 48 | |
| 49 | #define STMP3XXX_RTC_ALARM 0x40 |
| 50 | |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 51 | #define STMP3XXX_RTC_WATCHDOG 0x50 |
| 52 | |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 53 | #define STMP3XXX_RTC_PERSISTENT0 0x60 |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 54 | #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 |
| 55 | #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 56 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN 0x00000002 |
| 57 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN 0x00000004 |
| 58 | #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE 0x00000080 |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 59 | |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 60 | #define STMP3XXX_RTC_PERSISTENT1 0x70 |
| 61 | /* missing bitmask in headers */ |
| 62 | #define STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER 0x80000000 |
| 63 | |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 64 | struct stmp3xxx_rtc_data { |
| 65 | struct rtc_device *rtc; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 66 | void __iomem *io; |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 67 | int irq_alarm; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 70 | #if IS_ENABLED(CONFIG_STMP3XXX_RTC_WATCHDOG) |
| 71 | /** |
| 72 | * stmp3xxx_wdt_set_timeout - configure the watchdog inside the STMP3xxx RTC |
| 73 | * @dev: the parent device of the watchdog (= the RTC) |
| 74 | * @timeout: the desired value for the timeout register of the watchdog. |
| 75 | * 0 disables the watchdog |
| 76 | * |
| 77 | * The watchdog needs one register and two bits which are in the RTC domain. |
| 78 | * To handle the resource conflict, the RTC driver will create another |
| 79 | * platform_device for the watchdog driver as a child of the RTC device. |
| 80 | * The watchdog driver is passed the below accessor function via platform_data |
| 81 | * to configure the watchdog. Locking is not needed because accessing SET/CLR |
| 82 | * registers is atomic. |
| 83 | */ |
| 84 | |
| 85 | static void stmp3xxx_wdt_set_timeout(struct device *dev, u32 timeout) |
| 86 | { |
| 87 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
| 88 | |
| 89 | if (timeout) { |
| 90 | writel(timeout, rtc_data->io + STMP3XXX_RTC_WATCHDOG); |
| 91 | writel(STMP3XXX_RTC_CTRL_WATCHDOGEN, |
| 92 | rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_SET); |
| 93 | writel(STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER, |
| 94 | rtc_data->io + STMP3XXX_RTC_PERSISTENT1 + STMP_OFFSET_REG_SET); |
| 95 | } else { |
| 96 | writel(STMP3XXX_RTC_CTRL_WATCHDOGEN, |
| 97 | rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); |
| 98 | writel(STMP3XXX_RTC_PERSISTENT1_FORCE_UPDATER, |
| 99 | rtc_data->io + STMP3XXX_RTC_PERSISTENT1 + STMP_OFFSET_REG_CLR); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static struct stmp3xxx_wdt_pdata wdt_pdata = { |
| 104 | .wdt_set_timeout = stmp3xxx_wdt_set_timeout, |
| 105 | }; |
| 106 | |
| 107 | static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev) |
| 108 | { |
| 109 | struct platform_device *wdt_pdev = |
| 110 | platform_device_alloc("stmp3xxx_rtc_wdt", rtc_pdev->id); |
| 111 | |
| 112 | if (wdt_pdev) { |
| 113 | wdt_pdev->dev.parent = &rtc_pdev->dev; |
| 114 | wdt_pdev->dev.platform_data = &wdt_pdata; |
| 115 | platform_device_add(wdt_pdev); |
| 116 | } |
| 117 | } |
| 118 | #else |
| 119 | static void stmp3xxx_wdt_register(struct platform_device *rtc_pdev) |
| 120 | { |
| 121 | } |
| 122 | #endif /* CONFIG_STMP3XXX_RTC_WATCHDOG */ |
| 123 | |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 124 | static void stmp3xxx_wait_time(struct stmp3xxx_rtc_data *rtc_data) |
| 125 | { |
| 126 | /* |
| 127 | * The datasheet doesn't say which way round the |
| 128 | * NEW_REGS/STALE_REGS bitfields go. In fact it's 0x1=P0, |
| 129 | * 0x2=P1, .., 0x20=P5, 0x40=ALARM, 0x80=SECONDS |
| 130 | */ |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 131 | while (readl(rtc_data->io + STMP3XXX_RTC_STAT) & |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 132 | (0x80 << STMP3XXX_RTC_STAT_STALE_SHIFT)) |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 133 | cpu_relax(); |
| 134 | } |
| 135 | |
| 136 | /* Time read/write */ |
| 137 | static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) |
| 138 | { |
| 139 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
| 140 | |
| 141 | stmp3xxx_wait_time(rtc_data); |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 142 | rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | static int stmp3xxx_rtc_set_mmss(struct device *dev, unsigned long t) |
| 147 | { |
| 148 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
| 149 | |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 150 | writel(t, rtc_data->io + STMP3XXX_RTC_SECONDS); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 151 | stmp3xxx_wait_time(rtc_data); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /* interrupt(s) handler */ |
| 156 | static irqreturn_t stmp3xxx_rtc_interrupt(int irq, void *dev_id) |
| 157 | { |
| 158 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev_id); |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 159 | u32 status = readl(rtc_data->io + STMP3XXX_RTC_CTRL); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 160 | |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 161 | if (status & STMP3XXX_RTC_CTRL_ALARM_IRQ) { |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 162 | writel(STMP3XXX_RTC_CTRL_ALARM_IRQ, |
| 163 | rtc_data->io + STMP3XXX_RTC_CTRL_CLR); |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 164 | rtc_update_irq(rtc_data->rtc, 1, RTC_AF | RTC_IRQF); |
| 165 | return IRQ_HANDLED; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 168 | return IRQ_NONE; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static int stmp3xxx_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 172 | { |
| 173 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 174 | |
| 175 | if (enabled) { |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 176 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | |
| 177 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN, |
| 178 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); |
| 179 | writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, |
| 180 | rtc_data->io + STMP3XXX_RTC_CTRL_SET); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 181 | } else { |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 182 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | |
| 183 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN, |
| 184 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); |
| 185 | writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, |
| 186 | rtc_data->io + STMP3XXX_RTC_CTRL_CLR); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 191 | static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) |
| 192 | { |
| 193 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
| 194 | |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 195 | rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) |
| 200 | { |
| 201 | unsigned long t; |
| 202 | struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); |
| 203 | |
| 204 | rtc_tm_to_time(&alm->time, &t); |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 205 | writel(t, rtc_data->io + STMP3XXX_RTC_ALARM); |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 206 | |
| 207 | stmp3xxx_alarm_irq_enable(dev, alm->enabled); |
| 208 | |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static struct rtc_class_ops stmp3xxx_rtc_ops = { |
| 213 | .alarm_irq_enable = |
| 214 | stmp3xxx_alarm_irq_enable, |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 215 | .read_time = stmp3xxx_rtc_gettime, |
| 216 | .set_mmss = stmp3xxx_rtc_set_mmss, |
| 217 | .read_alarm = stmp3xxx_rtc_read_alarm, |
| 218 | .set_alarm = stmp3xxx_rtc_set_alarm, |
| 219 | }; |
| 220 | |
| 221 | static int stmp3xxx_rtc_remove(struct platform_device *pdev) |
| 222 | { |
| 223 | struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(pdev); |
| 224 | |
| 225 | if (!rtc_data) |
| 226 | return 0; |
| 227 | |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 228 | writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 229 | rtc_data->io + STMP3XXX_RTC_CTRL_CLR); |
Wolfram Sang | a91d2ba | 2011-05-25 12:56:51 +0200 | [diff] [blame] | 230 | platform_set_drvdata(pdev, NULL); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int stmp3xxx_rtc_probe(struct platform_device *pdev) |
| 236 | { |
| 237 | struct stmp3xxx_rtc_data *rtc_data; |
| 238 | struct resource *r; |
| 239 | int err; |
| 240 | |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 241 | rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 242 | if (!rtc_data) |
| 243 | return -ENOMEM; |
| 244 | |
| 245 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 246 | if (!r) { |
| 247 | dev_err(&pdev->dev, "failed to get resource\n"); |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 248 | return -ENXIO; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 251 | rtc_data->io = devm_ioremap(&pdev->dev, r->start, resource_size(r)); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 252 | if (!rtc_data->io) { |
| 253 | dev_err(&pdev->dev, "ioremap failed\n"); |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 254 | return -EIO; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | rtc_data->irq_alarm = platform_get_irq(pdev, 0); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 258 | |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 259 | if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 260 | STMP3XXX_RTC_STAT_RTC_PRESENT)) { |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 261 | dev_err(&pdev->dev, "no device onboard\n"); |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 262 | return -ENODEV; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Wolfram Sang | a91d2ba | 2011-05-25 12:56:51 +0200 | [diff] [blame] | 265 | platform_set_drvdata(pdev, rtc_data); |
| 266 | |
Wolfram Sang | 46b2121 | 2011-05-25 12:56:50 +0200 | [diff] [blame] | 267 | mxs_reset_block(rtc_data->io); |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 268 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 269 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | |
| 270 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 271 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); |
Wolfram Sang | a91d2ba | 2011-05-25 12:56:51 +0200 | [diff] [blame] | 272 | |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 273 | writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN | |
| 274 | STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, |
| 275 | rtc_data->io + STMP3XXX_RTC_CTRL_CLR); |
| 276 | |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 277 | rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 278 | &stmp3xxx_rtc_ops, THIS_MODULE); |
| 279 | if (IS_ERR(rtc_data->rtc)) { |
| 280 | err = PTR_ERR(rtc_data->rtc); |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 281 | goto out; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 284 | err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm, |
| 285 | stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 286 | if (err) { |
| 287 | dev_err(&pdev->dev, "Cannot claim IRQ%d\n", |
| 288 | rtc_data->irq_alarm); |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 289 | goto out; |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 290 | } |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 291 | |
Wolfram Sang | 1a71fb8 | 2011-09-27 22:21:37 +0200 | [diff] [blame] | 292 | stmp3xxx_wdt_register(pdev); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 293 | return 0; |
| 294 | |
Jingoo Han | 87a8142 | 2013-04-29 16:20:55 -0700 | [diff] [blame] | 295 | out: |
Wolfram Sang | a91d2ba | 2011-05-25 12:56:51 +0200 | [diff] [blame] | 296 | platform_set_drvdata(pdev, NULL); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 297 | return err; |
| 298 | } |
| 299 | |
| 300 | #ifdef CONFIG_PM |
| 301 | static int stmp3xxx_rtc_suspend(struct platform_device *dev, pm_message_t state) |
| 302 | { |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int stmp3xxx_rtc_resume(struct platform_device *dev) |
| 307 | { |
| 308 | struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(dev); |
| 309 | |
Wolfram Sang | 46b2121 | 2011-05-25 12:56:50 +0200 | [diff] [blame] | 310 | mxs_reset_block(rtc_data->io); |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 311 | writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | |
Wolfram Sang | 47eac33 | 2011-05-25 12:56:49 +0200 | [diff] [blame] | 312 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | |
| 313 | STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, |
Wolfram Sang | b516715 | 2011-05-25 12:56:52 +0200 | [diff] [blame] | 314 | rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | #else |
| 318 | #define stmp3xxx_rtc_suspend NULL |
| 319 | #define stmp3xxx_rtc_resume NULL |
| 320 | #endif |
| 321 | |
Marek Vasut | dd8d20a | 2012-06-26 16:29:27 +0800 | [diff] [blame] | 322 | static const struct of_device_id rtc_dt_ids[] = { |
| 323 | { .compatible = "fsl,stmp3xxx-rtc", }, |
| 324 | { /* sentinel */ } |
| 325 | }; |
| 326 | MODULE_DEVICE_TABLE(of, rtc_dt_ids); |
| 327 | |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 328 | static struct platform_driver stmp3xxx_rtcdrv = { |
| 329 | .probe = stmp3xxx_rtc_probe, |
| 330 | .remove = stmp3xxx_rtc_remove, |
| 331 | .suspend = stmp3xxx_rtc_suspend, |
| 332 | .resume = stmp3xxx_rtc_resume, |
| 333 | .driver = { |
| 334 | .name = "stmp3xxx-rtc", |
| 335 | .owner = THIS_MODULE, |
Sachin Kamat | c8a6046 | 2013-02-21 16:44:28 -0800 | [diff] [blame] | 336 | .of_match_table = of_match_ptr(rtc_dt_ids), |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 337 | }, |
| 338 | }; |
| 339 | |
Axel Lin | 0c4eae6 | 2012-01-10 15:10:48 -0800 | [diff] [blame] | 340 | module_platform_driver(stmp3xxx_rtcdrv); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 341 | |
| 342 | MODULE_DESCRIPTION("STMP3xxx RTC Driver"); |
Wolfram Sang | 7e794cb | 2011-05-25 12:56:53 +0200 | [diff] [blame] | 343 | MODULE_AUTHOR("dmitry pervushin <dpervushin@embeddedalley.com> and " |
| 344 | "Wolfram Sang <w.sang@pengutronix.de>"); |
dmitry pervushin | df17f63 | 2009-09-22 16:46:26 -0700 | [diff] [blame] | 345 | MODULE_LICENSE("GPL"); |