Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Real Time Clock interface for StrongARM SA1x00 and XScale PXA2xx |
| 3 | * |
| 4 | * Copyright (c) 2000 Nils Faerber |
| 5 | * |
| 6 | * Based on rtc.c by Paul Gortmaker |
| 7 | * |
| 8 | * Original Driver by Nils Faerber <nils@kernelconcepts.de> |
| 9 | * |
| 10 | * Modifications from: |
| 11 | * CIH <cih@coventive.com> |
Nicolas Pitre | 2f82af0 | 2009-09-14 03:25:28 -0400 | [diff] [blame] | 12 | * Nicolas Pitre <nico@fluxnic.net> |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 13 | * Andrew Christian <andrew.christian@hp.com> |
| 14 | * |
| 15 | * Converted to the RTC subsystem and Driver Model |
| 16 | * by Richard Purdie <rpurdie@rpsys.net> |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or |
| 19 | * modify it under the terms of the GNU General Public License |
| 20 | * as published by the Free Software Foundation; either version |
| 21 | * 2 of the License, or (at your option) any later version. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/rtc.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/pm.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 32 | #include <linux/bitops.h> |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 33 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/hardware.h> |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 35 | #include <asm/irq.h> |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 36 | |
| 37 | #ifdef CONFIG_ARCH_PXA |
Eric Miao | 5bf3df3 | 2009-01-20 11:04:16 +0800 | [diff] [blame] | 38 | #include <mach/regs-rtc.h> |
| 39 | #include <mach/regs-ost.h> |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 40 | #endif |
| 41 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 42 | #define RTC_DEF_DIVIDER 32768 - 1 |
| 43 | #define RTC_DEF_TRIM 0 |
| 44 | |
| 45 | static unsigned long rtc_freq = 1024; |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 46 | static unsigned long timer_freq; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 47 | static struct rtc_time rtc_alarm; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 48 | static DEFINE_SPINLOCK(sa1100_rtc_lock); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 49 | |
Russell King | 797276ec | 2008-04-20 12:30:41 +0100 | [diff] [blame] | 50 | static inline int rtc_periodic_alarm(struct rtc_time *tm) |
| 51 | { |
| 52 | return (tm->tm_year == -1) || |
| 53 | ((unsigned)tm->tm_mon >= 12) || |
| 54 | ((unsigned)(tm->tm_mday - 1) >= 31) || |
| 55 | ((unsigned)tm->tm_hour > 23) || |
| 56 | ((unsigned)tm->tm_min > 59) || |
| 57 | ((unsigned)tm->tm_sec > 59); |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Calculate the next alarm time given the requested alarm time mask |
| 62 | * and the current time. |
| 63 | */ |
| 64 | static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now, struct rtc_time *alrm) |
| 65 | { |
| 66 | unsigned long next_time; |
| 67 | unsigned long now_time; |
| 68 | |
| 69 | next->tm_year = now->tm_year; |
| 70 | next->tm_mon = now->tm_mon; |
| 71 | next->tm_mday = now->tm_mday; |
| 72 | next->tm_hour = alrm->tm_hour; |
| 73 | next->tm_min = alrm->tm_min; |
| 74 | next->tm_sec = alrm->tm_sec; |
| 75 | |
| 76 | rtc_tm_to_time(now, &now_time); |
| 77 | rtc_tm_to_time(next, &next_time); |
| 78 | |
| 79 | if (next_time < now_time) { |
| 80 | /* Advance one day */ |
| 81 | next_time += 60 * 60 * 24; |
| 82 | rtc_time_to_tm(next_time, next); |
| 83 | } |
| 84 | } |
| 85 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 86 | static int rtc_update_alarm(struct rtc_time *alrm) |
| 87 | { |
| 88 | struct rtc_time alarm_tm, now_tm; |
| 89 | unsigned long now, time; |
| 90 | int ret; |
| 91 | |
| 92 | do { |
| 93 | now = RCNR; |
| 94 | rtc_time_to_tm(now, &now_tm); |
| 95 | rtc_next_alarm_time(&alarm_tm, &now_tm, alrm); |
| 96 | ret = rtc_tm_to_time(&alarm_tm, &time); |
| 97 | if (ret != 0) |
| 98 | break; |
| 99 | |
| 100 | RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL); |
| 101 | RTAR = time; |
| 102 | } while (now != RCNR); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 107 | static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 108 | { |
| 109 | struct platform_device *pdev = to_platform_device(dev_id); |
| 110 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
| 111 | unsigned int rtsr; |
| 112 | unsigned long events = 0; |
| 113 | |
| 114 | spin_lock(&sa1100_rtc_lock); |
| 115 | |
| 116 | rtsr = RTSR; |
| 117 | /* clear interrupt sources */ |
| 118 | RTSR = 0; |
| 119 | RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2); |
| 120 | |
| 121 | /* clear alarm interrupt if it has occurred */ |
| 122 | if (rtsr & RTSR_AL) |
| 123 | rtsr &= ~RTSR_ALE; |
| 124 | RTSR = rtsr & (RTSR_ALE | RTSR_HZE); |
| 125 | |
| 126 | /* update irq data & counter */ |
| 127 | if (rtsr & RTSR_AL) |
| 128 | events |= RTC_AF | RTC_IRQF; |
| 129 | if (rtsr & RTSR_HZ) |
| 130 | events |= RTC_UF | RTC_IRQF; |
| 131 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 132 | rtc_update_irq(rtc, 1, events); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 133 | |
| 134 | if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm)) |
| 135 | rtc_update_alarm(&rtc_alarm); |
| 136 | |
| 137 | spin_unlock(&sa1100_rtc_lock); |
| 138 | |
| 139 | return IRQ_HANDLED; |
| 140 | } |
| 141 | |
| 142 | static int rtc_timer1_count; |
| 143 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 144 | static irqreturn_t timer1_interrupt(int irq, void *dev_id) |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 145 | { |
| 146 | struct platform_device *pdev = to_platform_device(dev_id); |
| 147 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
| 148 | |
| 149 | /* |
| 150 | * If we match for the first time, rtc_timer1_count will be 1. |
| 151 | * Otherwise, we wrapped around (very unlikely but |
| 152 | * still possible) so compute the amount of missed periods. |
| 153 | * The match reg is updated only when the data is actually retrieved |
| 154 | * to avoid unnecessary interrupts. |
| 155 | */ |
| 156 | OSSR = OSSR_M1; /* clear match on timer1 */ |
| 157 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 158 | rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 159 | |
| 160 | if (rtc_timer1_count == 1) |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 161 | rtc_timer1_count = (rtc_freq * ((1 << 30) / (timer_freq >> 2))); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 162 | |
| 163 | return IRQ_HANDLED; |
| 164 | } |
| 165 | |
| 166 | static int sa1100_rtc_read_callback(struct device *dev, int data) |
| 167 | { |
| 168 | if (data & RTC_PF) { |
| 169 | /* interpolate missed periods and set match for the next */ |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 170 | unsigned long period = timer_freq / rtc_freq; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 171 | unsigned long oscr = OSCR; |
| 172 | unsigned long osmr1 = OSMR1; |
| 173 | unsigned long missed = (oscr - osmr1)/period; |
| 174 | data += missed << 8; |
| 175 | OSSR = OSSR_M1; /* clear match on timer 1 */ |
| 176 | OSMR1 = osmr1 + (missed + 1)*period; |
| 177 | /* Ensure we didn't miss another match in the mean time. |
| 178 | * Here we compare (match - OSCR) 8 instead of 0 -- |
| 179 | * see comment in pxa_timer_interrupt() for explanation. |
| 180 | */ |
| 181 | while( (signed long)((osmr1 = OSMR1) - OSCR) <= 8 ) { |
| 182 | data += 0x100; |
| 183 | OSSR = OSSR_M1; /* clear match on timer 1 */ |
| 184 | OSMR1 = osmr1 + period; |
| 185 | } |
| 186 | } |
| 187 | return data; |
| 188 | } |
| 189 | |
| 190 | static int sa1100_rtc_open(struct device *dev) |
| 191 | { |
| 192 | int ret; |
| 193 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 194 | ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED, |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 195 | "rtc 1Hz", dev); |
| 196 | if (ret) { |
Alessandro Zummo | 2260a25 | 2006-04-10 22:54:46 -0700 | [diff] [blame] | 197 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 198 | goto fail_ui; |
| 199 | } |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 200 | ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED, |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 201 | "rtc Alrm", dev); |
| 202 | if (ret) { |
Alessandro Zummo | 2260a25 | 2006-04-10 22:54:46 -0700 | [diff] [blame] | 203 | dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 204 | goto fail_ai; |
| 205 | } |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 206 | ret = request_irq(IRQ_OST1, timer1_interrupt, IRQF_DISABLED, |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 207 | "rtc timer", dev); |
| 208 | if (ret) { |
Alessandro Zummo | 2260a25 | 2006-04-10 22:54:46 -0700 | [diff] [blame] | 209 | dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 210 | goto fail_pi; |
| 211 | } |
| 212 | return 0; |
| 213 | |
| 214 | fail_pi: |
Russell King | f122670 | 2006-05-06 11:29:21 +0100 | [diff] [blame] | 215 | free_irq(IRQ_RTCAlrm, dev); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 216 | fail_ai: |
Russell King | f122670 | 2006-05-06 11:29:21 +0100 | [diff] [blame] | 217 | free_irq(IRQ_RTC1Hz, dev); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 218 | fail_ui: |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | static void sa1100_rtc_release(struct device *dev) |
| 223 | { |
| 224 | spin_lock_irq(&sa1100_rtc_lock); |
| 225 | RTSR = 0; |
| 226 | OIER &= ~OIER_E1; |
| 227 | OSSR = OSSR_M1; |
| 228 | spin_unlock_irq(&sa1100_rtc_lock); |
| 229 | |
| 230 | free_irq(IRQ_OST1, dev); |
| 231 | free_irq(IRQ_RTCAlrm, dev); |
| 232 | free_irq(IRQ_RTC1Hz, dev); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd, |
| 237 | unsigned long arg) |
| 238 | { |
| 239 | switch(cmd) { |
| 240 | case RTC_AIE_OFF: |
| 241 | spin_lock_irq(&sa1100_rtc_lock); |
| 242 | RTSR &= ~RTSR_ALE; |
| 243 | spin_unlock_irq(&sa1100_rtc_lock); |
| 244 | return 0; |
| 245 | case RTC_AIE_ON: |
| 246 | spin_lock_irq(&sa1100_rtc_lock); |
| 247 | RTSR |= RTSR_ALE; |
| 248 | spin_unlock_irq(&sa1100_rtc_lock); |
| 249 | return 0; |
| 250 | case RTC_UIE_OFF: |
| 251 | spin_lock_irq(&sa1100_rtc_lock); |
| 252 | RTSR &= ~RTSR_HZE; |
| 253 | spin_unlock_irq(&sa1100_rtc_lock); |
| 254 | return 0; |
| 255 | case RTC_UIE_ON: |
| 256 | spin_lock_irq(&sa1100_rtc_lock); |
| 257 | RTSR |= RTSR_HZE; |
| 258 | spin_unlock_irq(&sa1100_rtc_lock); |
| 259 | return 0; |
| 260 | case RTC_PIE_OFF: |
| 261 | spin_lock_irq(&sa1100_rtc_lock); |
| 262 | OIER &= ~OIER_E1; |
| 263 | spin_unlock_irq(&sa1100_rtc_lock); |
| 264 | return 0; |
| 265 | case RTC_PIE_ON: |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 266 | spin_lock_irq(&sa1100_rtc_lock); |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 267 | OSMR1 = timer_freq / rtc_freq + OSCR; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 268 | OIER |= OIER_E1; |
| 269 | rtc_timer1_count = 1; |
| 270 | spin_unlock_irq(&sa1100_rtc_lock); |
| 271 | return 0; |
| 272 | case RTC_IRQP_READ: |
| 273 | return put_user(rtc_freq, (unsigned long *)arg); |
| 274 | case RTC_IRQP_SET: |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 275 | if (arg < 1 || arg > timer_freq) |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 276 | return -EINVAL; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 277 | rtc_freq = arg; |
| 278 | return 0; |
| 279 | } |
Alessandro Zummo | b3969e5 | 2006-05-20 15:00:29 -0700 | [diff] [blame] | 280 | return -ENOIOCTLCMD; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 284 | { |
| 285 | rtc_time_to_tm(RCNR, tm); |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 290 | { |
| 291 | unsigned long time; |
| 292 | int ret; |
| 293 | |
| 294 | ret = rtc_tm_to_time(tm, &time); |
| 295 | if (ret == 0) |
| 296 | RCNR = time; |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 301 | { |
David Brownell | 32b49da | 2007-02-20 13:58:13 -0800 | [diff] [blame] | 302 | u32 rtsr; |
| 303 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 304 | memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time)); |
David Brownell | 32b49da | 2007-02-20 13:58:13 -0800 | [diff] [blame] | 305 | rtsr = RTSR; |
| 306 | alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0; |
| 307 | alrm->pending = (rtsr & RTSR_AL) ? 1 : 0; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 312 | { |
| 313 | int ret; |
| 314 | |
| 315 | spin_lock_irq(&sa1100_rtc_lock); |
| 316 | ret = rtc_update_alarm(&alrm->time); |
| 317 | if (ret == 0) { |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 318 | if (alrm->enabled) |
David Brownell | 32b49da | 2007-02-20 13:58:13 -0800 | [diff] [blame] | 319 | RTSR |= RTSR_ALE; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 320 | else |
David Brownell | 32b49da | 2007-02-20 13:58:13 -0800 | [diff] [blame] | 321 | RTSR &= ~RTSR_ALE; |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 322 | } |
| 323 | spin_unlock_irq(&sa1100_rtc_lock); |
| 324 | |
| 325 | return ret; |
| 326 | } |
| 327 | |
| 328 | static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) |
| 329 | { |
David Brownell | a2db8df | 2006-12-13 00:35:08 -0800 | [diff] [blame] | 330 | seq_printf(seq, "trim/divider\t: 0x%08x\n", (u32) RTTR); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 331 | seq_printf(seq, "update_IRQ\t: %s\n", |
| 332 | (RTSR & RTSR_HZE) ? "yes" : "no"); |
| 333 | seq_printf(seq, "periodic_IRQ\t: %s\n", |
| 334 | (OIER & OIER_E1) ? "yes" : "no"); |
| 335 | seq_printf(seq, "periodic_freq\t: %ld\n", rtc_freq); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
David Brownell | ff8371a | 2006-09-30 23:28:17 -0700 | [diff] [blame] | 340 | static const struct rtc_class_ops sa1100_rtc_ops = { |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 341 | .open = sa1100_rtc_open, |
| 342 | .read_callback = sa1100_rtc_read_callback, |
| 343 | .release = sa1100_rtc_release, |
| 344 | .ioctl = sa1100_rtc_ioctl, |
| 345 | .read_time = sa1100_rtc_read_time, |
| 346 | .set_time = sa1100_rtc_set_time, |
| 347 | .read_alarm = sa1100_rtc_read_alarm, |
| 348 | .set_alarm = sa1100_rtc_set_alarm, |
| 349 | .proc = sa1100_rtc_proc, |
| 350 | }; |
| 351 | |
| 352 | static int sa1100_rtc_probe(struct platform_device *pdev) |
| 353 | { |
| 354 | struct rtc_device *rtc; |
| 355 | |
Eric Miao | 6769717 | 2008-12-18 11:10:32 +0800 | [diff] [blame] | 356 | timer_freq = get_clock_tick_rate(); |
| 357 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 358 | /* |
| 359 | * According to the manual we should be able to let RTTR be zero |
| 360 | * and then a default diviser for a 32.768KHz clock is used. |
| 361 | * Apparently this doesn't work, at least for my SA1110 rev 5. |
| 362 | * If the clock divider is uninitialized then reset it to the |
| 363 | * default value to get the 1Hz clock. |
| 364 | */ |
| 365 | if (RTTR == 0) { |
| 366 | RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); |
Alessandro Zummo | 2260a25 | 2006-04-10 22:54:46 -0700 | [diff] [blame] | 367 | dev_warn(&pdev->dev, "warning: initializing default clock divider/trim value\n"); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 368 | /* The current RTC value probably doesn't make sense either */ |
| 369 | RCNR = 0; |
| 370 | } |
| 371 | |
Uli Luckas | e5a2c9c | 2008-06-18 09:54:03 +0100 | [diff] [blame] | 372 | device_init_wakeup(&pdev->dev, 1); |
| 373 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 374 | rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, |
| 375 | THIS_MODULE); |
| 376 | |
Alessandro Zummo | 2260a25 | 2006-04-10 22:54:46 -0700 | [diff] [blame] | 377 | if (IS_ERR(rtc)) |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 378 | return PTR_ERR(rtc); |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 379 | |
| 380 | platform_set_drvdata(pdev, rtc); |
| 381 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static int sa1100_rtc_remove(struct platform_device *pdev) |
| 386 | { |
| 387 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
| 388 | |
| 389 | if (rtc) |
| 390 | rtc_device_unregister(rtc); |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 395 | #ifdef CONFIG_PM |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 396 | static int sa1100_rtc_suspend(struct device *dev) |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 397 | { |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 398 | if (device_may_wakeup(dev)) |
David Brownell | f618258 | 2008-02-06 01:38:57 -0800 | [diff] [blame] | 399 | enable_irq_wake(IRQ_RTCAlrm); |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 403 | static int sa1100_rtc_resume(struct device *dev) |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 404 | { |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 405 | if (device_may_wakeup(dev)) |
David Brownell | f618258 | 2008-02-06 01:38:57 -0800 | [diff] [blame] | 406 | disable_irq_wake(IRQ_RTCAlrm); |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 407 | return 0; |
| 408 | } |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 409 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 410 | static const struct dev_pm_ops sa1100_rtc_pm_ops = { |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 411 | .suspend = sa1100_rtc_suspend, |
| 412 | .resume = sa1100_rtc_resume, |
| 413 | }; |
Russell King | 6bc54e6 | 2007-11-12 22:49:58 +0000 | [diff] [blame] | 414 | #endif |
| 415 | |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 416 | static struct platform_driver sa1100_rtc_driver = { |
| 417 | .probe = sa1100_rtc_probe, |
| 418 | .remove = sa1100_rtc_remove, |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 419 | .driver = { |
Haojian Zhuang | 5d027cd | 2009-07-21 14:31:09 +0800 | [diff] [blame] | 420 | .name = "sa1100-rtc", |
| 421 | #ifdef CONFIG_PM |
| 422 | .pm = &sa1100_rtc_pm_ops, |
| 423 | #endif |
Richard Purdie | e842f1c | 2006-03-27 01:16:46 -0800 | [diff] [blame] | 424 | }, |
| 425 | }; |
| 426 | |
| 427 | static int __init sa1100_rtc_init(void) |
| 428 | { |
| 429 | return platform_driver_register(&sa1100_rtc_driver); |
| 430 | } |
| 431 | |
| 432 | static void __exit sa1100_rtc_exit(void) |
| 433 | { |
| 434 | platform_driver_unregister(&sa1100_rtc_driver); |
| 435 | } |
| 436 | |
| 437 | module_init(sa1100_rtc_init); |
| 438 | module_exit(sa1100_rtc_exit); |
| 439 | |
| 440 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
| 441 | MODULE_DESCRIPTION("SA11x0/PXA2xx Realtime Clock Driver (RTC)"); |
| 442 | MODULE_LICENSE("GPL"); |
Kay Sievers | ad28a07 | 2008-04-10 21:29:25 -0700 | [diff] [blame] | 443 | MODULE_ALIAS("platform:sa1100-rtc"); |