Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * RTC subsystem, interface functions |
| 3 | * |
| 4 | * Copyright (C) 2005 Tower Technologies |
| 5 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
| 6 | * |
| 7 | * based on arch/arm/common/rtctime.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/rtc.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 15 | #include <linux/sched.h> |
David Brownell | 97144c6 | 2007-10-16 01:28:16 -0700 | [diff] [blame] | 16 | #include <linux/log2.h> |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 17 | #include <linux/workqueue.h> |
| 18 | |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 19 | static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); |
| 20 | static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); |
| 21 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 22 | static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) |
| 23 | { |
| 24 | int err; |
| 25 | if (!rtc->ops) |
| 26 | err = -ENODEV; |
| 27 | else if (!rtc->ops->read_time) |
| 28 | err = -EINVAL; |
| 29 | else { |
| 30 | memset(tm, 0, sizeof(struct rtc_time)); |
| 31 | err = rtc->ops->read_time(rtc->dev.parent, tm); |
| 32 | } |
| 33 | return err; |
| 34 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 35 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 36 | int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 37 | { |
| 38 | int err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 39 | |
| 40 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 41 | if (err) |
David Brownell | b68bb26 | 2008-07-29 22:33:30 -0700 | [diff] [blame] | 42 | return err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 43 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 44 | err = __rtc_read_time(rtc, tm); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 45 | mutex_unlock(&rtc->ops_lock); |
| 46 | return err; |
| 47 | } |
| 48 | EXPORT_SYMBOL_GPL(rtc_read_time); |
| 49 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 50 | int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 51 | { |
| 52 | int err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 53 | |
| 54 | err = rtc_valid_tm(tm); |
| 55 | if (err != 0) |
| 56 | return err; |
| 57 | |
| 58 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 59 | if (err) |
David Brownell | b68bb26 | 2008-07-29 22:33:30 -0700 | [diff] [blame] | 60 | return err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 61 | |
| 62 | if (!rtc->ops) |
| 63 | err = -ENODEV; |
Alessandro Zummo | bbccf83 | 2009-01-06 14:42:21 -0800 | [diff] [blame] | 64 | else if (rtc->ops->set_time) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 65 | err = rtc->ops->set_time(rtc->dev.parent, tm); |
Alessandro Zummo | bbccf83 | 2009-01-06 14:42:21 -0800 | [diff] [blame] | 66 | else if (rtc->ops->set_mmss) { |
| 67 | unsigned long secs; |
| 68 | err = rtc_tm_to_time(tm, &secs); |
| 69 | if (err == 0) |
| 70 | err = rtc->ops->set_mmss(rtc->dev.parent, secs); |
| 71 | } else |
| 72 | err = -EINVAL; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 73 | |
| 74 | mutex_unlock(&rtc->ops_lock); |
| 75 | return err; |
| 76 | } |
| 77 | EXPORT_SYMBOL_GPL(rtc_set_time); |
| 78 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 79 | int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 80 | { |
| 81 | int err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 82 | |
| 83 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 84 | if (err) |
David Brownell | b68bb26 | 2008-07-29 22:33:30 -0700 | [diff] [blame] | 85 | return err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 86 | |
| 87 | if (!rtc->ops) |
| 88 | err = -ENODEV; |
| 89 | else if (rtc->ops->set_mmss) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 90 | err = rtc->ops->set_mmss(rtc->dev.parent, secs); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 91 | else if (rtc->ops->read_time && rtc->ops->set_time) { |
| 92 | struct rtc_time new, old; |
| 93 | |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 94 | err = rtc->ops->read_time(rtc->dev.parent, &old); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 95 | if (err == 0) { |
| 96 | rtc_time_to_tm(secs, &new); |
| 97 | |
| 98 | /* |
| 99 | * avoid writing when we're going to change the day of |
| 100 | * the month. We will retry in the next minute. This |
| 101 | * basically means that if the RTC must not drift |
| 102 | * by more than 1 minute in 11 minutes. |
| 103 | */ |
| 104 | if (!((old.tm_hour == 23 && old.tm_min == 59) || |
| 105 | (new.tm_hour == 23 && new.tm_min == 59))) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 106 | err = rtc->ops->set_time(rtc->dev.parent, |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 107 | &new); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | else |
| 111 | err = -EINVAL; |
| 112 | |
| 113 | mutex_unlock(&rtc->ops_lock); |
| 114 | |
| 115 | return err; |
| 116 | } |
| 117 | EXPORT_SYMBOL_GPL(rtc_set_mmss); |
| 118 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 119 | int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 120 | { |
| 121 | int err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 122 | |
| 123 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 124 | if (err) |
David Brownell | b68bb26 | 2008-07-29 22:33:30 -0700 | [diff] [blame] | 125 | return err; |
John Stultz | d5553a5 | 2011-01-20 15:26:13 -0800 | [diff] [blame] | 126 | if (rtc->ops == NULL) |
| 127 | err = -ENODEV; |
| 128 | else if (!rtc->ops->read_alarm) |
| 129 | err = -EINVAL; |
| 130 | else { |
| 131 | memset(alarm, 0, sizeof(struct rtc_wkalrm)); |
| 132 | alarm->enabled = rtc->aie_timer.enabled; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 133 | alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires); |
John Stultz | d5553a5 | 2011-01-20 15:26:13 -0800 | [diff] [blame] | 134 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 135 | mutex_unlock(&rtc->ops_lock); |
Mark Lord | 0e36a9a | 2007-10-16 01:28:21 -0700 | [diff] [blame] | 136 | |
John Stultz | d5553a5 | 2011-01-20 15:26:13 -0800 | [diff] [blame] | 137 | return err; |
Mark Lord | 0e36a9a | 2007-10-16 01:28:21 -0700 | [diff] [blame] | 138 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 139 | EXPORT_SYMBOL_GPL(rtc_read_alarm); |
| 140 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 141 | int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
| 142 | { |
| 143 | struct rtc_time tm; |
| 144 | long now, scheduled; |
| 145 | int err; |
| 146 | |
| 147 | err = rtc_valid_tm(&alarm->time); |
| 148 | if (err) |
| 149 | return err; |
| 150 | rtc_tm_to_time(&alarm->time, &scheduled); |
| 151 | |
| 152 | /* Make sure we're not setting alarms in the past */ |
| 153 | err = __rtc_read_time(rtc, &tm); |
| 154 | rtc_tm_to_time(&tm, &now); |
| 155 | if (scheduled <= now) |
| 156 | return -ETIME; |
| 157 | /* |
| 158 | * XXX - We just checked to make sure the alarm time is not |
| 159 | * in the past, but there is still a race window where if |
| 160 | * the is alarm set for the next second and the second ticks |
| 161 | * over right here, before we set the alarm. |
| 162 | */ |
| 163 | |
| 164 | if (!rtc->ops) |
| 165 | err = -ENODEV; |
| 166 | else if (!rtc->ops->set_alarm) |
| 167 | err = -EINVAL; |
| 168 | else |
| 169 | err = rtc->ops->set_alarm(rtc->dev.parent, alarm); |
| 170 | |
| 171 | return err; |
| 172 | } |
| 173 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 174 | int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 175 | { |
| 176 | int err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 177 | |
David Brownell | f8245c2 | 2007-05-08 00:34:07 -0700 | [diff] [blame] | 178 | err = rtc_valid_tm(&alarm->time); |
| 179 | if (err != 0) |
| 180 | return err; |
| 181 | |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 182 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 183 | if (err) |
David Brownell | b68bb26 | 2008-07-29 22:33:30 -0700 | [diff] [blame] | 184 | return err; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 185 | if (rtc->aie_timer.enabled) { |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 186 | rtc_timer_remove(rtc, &rtc->aie_timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 187 | } |
| 188 | rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); |
| 189 | rtc->aie_timer.period = ktime_set(0, 0); |
| 190 | if (alarm->enabled) { |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 191 | err = rtc_timer_enqueue(rtc, &rtc->aie_timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 192 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 193 | mutex_unlock(&rtc->ops_lock); |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 194 | return err; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 195 | } |
| 196 | EXPORT_SYMBOL_GPL(rtc_set_alarm); |
| 197 | |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 198 | int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) |
| 199 | { |
| 200 | int err = mutex_lock_interruptible(&rtc->ops_lock); |
| 201 | if (err) |
| 202 | return err; |
| 203 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 204 | if (rtc->aie_timer.enabled != enabled) { |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 205 | if (enabled) |
| 206 | err = rtc_timer_enqueue(rtc, &rtc->aie_timer); |
| 207 | else |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 208 | rtc_timer_remove(rtc, &rtc->aie_timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 209 | } |
| 210 | |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 211 | if (err) |
Uwe Kleine-König | 516373b | 2011-02-14 11:33:17 +0100 | [diff] [blame] | 212 | /* nothing */; |
| 213 | else if (!rtc->ops) |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 214 | err = -ENODEV; |
| 215 | else if (!rtc->ops->alarm_irq_enable) |
| 216 | err = -EINVAL; |
| 217 | else |
| 218 | err = rtc->ops->alarm_irq_enable(rtc->dev.parent, enabled); |
| 219 | |
| 220 | mutex_unlock(&rtc->ops_lock); |
| 221 | return err; |
| 222 | } |
| 223 | EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); |
| 224 | |
| 225 | int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) |
| 226 | { |
| 227 | int err = mutex_lock_interruptible(&rtc->ops_lock); |
| 228 | if (err) |
| 229 | return err; |
| 230 | |
John Stultz | 456d66e | 2011-02-11 18:15:23 -0800 | [diff] [blame^] | 231 | #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL |
| 232 | if (enabled == 0 && rtc->uie_irq_active) { |
| 233 | mutex_unlock(&rtc->ops_lock); |
| 234 | return rtc_dev_update_irq_enable_emul(rtc, 0); |
| 235 | } |
| 236 | #endif |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 237 | /* make sure we're changing state */ |
| 238 | if (rtc->uie_rtctimer.enabled == enabled) |
| 239 | goto out; |
| 240 | |
| 241 | if (enabled) { |
| 242 | struct rtc_time tm; |
| 243 | ktime_t now, onesec; |
| 244 | |
| 245 | __rtc_read_time(rtc, &tm); |
| 246 | onesec = ktime_set(1, 0); |
| 247 | now = rtc_tm_to_ktime(tm); |
| 248 | rtc->uie_rtctimer.node.expires = ktime_add(now, onesec); |
| 249 | rtc->uie_rtctimer.period = ktime_set(1, 0); |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 250 | err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer); |
| 251 | } else |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 252 | rtc_timer_remove(rtc, &rtc->uie_rtctimer); |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 253 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 254 | out: |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 255 | mutex_unlock(&rtc->ops_lock); |
John Stultz | 456d66e | 2011-02-11 18:15:23 -0800 | [diff] [blame^] | 256 | #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL |
| 257 | /* |
| 258 | * Enable emulation if the driver did not provide |
| 259 | * the update_irq_enable function pointer or if returned |
| 260 | * -EINVAL to signal that it has been configured without |
| 261 | * interrupts or that are not available at the moment. |
| 262 | */ |
| 263 | if (err == -EINVAL) |
| 264 | err = rtc_dev_update_irq_enable_emul(rtc, enabled); |
| 265 | #endif |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 266 | return err; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 267 | |
Alessandro Zummo | 099e657 | 2009-01-04 12:00:54 -0800 | [diff] [blame] | 268 | } |
| 269 | EXPORT_SYMBOL_GPL(rtc_update_irq_enable); |
| 270 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 271 | |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 272 | /** |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 273 | * rtc_handle_legacy_irq - AIE, UIE and PIE event hook |
| 274 | * @rtc: pointer to the rtc device |
| 275 | * |
| 276 | * This function is called when an AIE, UIE or PIE mode interrupt |
| 277 | * has occured (or been emulated). |
| 278 | * |
| 279 | * Triggers the registered irq_task function callback. |
| 280 | */ |
John Stultz | 456d66e | 2011-02-11 18:15:23 -0800 | [diff] [blame^] | 281 | void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 282 | { |
| 283 | unsigned long flags; |
| 284 | |
| 285 | /* mark one irq of the appropriate mode */ |
| 286 | spin_lock_irqsave(&rtc->irq_lock, flags); |
| 287 | rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF|mode); |
| 288 | spin_unlock_irqrestore(&rtc->irq_lock, flags); |
| 289 | |
| 290 | /* call the task func */ |
| 291 | spin_lock_irqsave(&rtc->irq_task_lock, flags); |
| 292 | if (rtc->irq_task) |
| 293 | rtc->irq_task->func(rtc->irq_task->private_data); |
| 294 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); |
| 295 | |
| 296 | wake_up_interruptible(&rtc->irq_queue); |
| 297 | kill_fasync(&rtc->async_queue, SIGIO, POLL_IN); |
| 298 | } |
| 299 | |
| 300 | |
| 301 | /** |
| 302 | * rtc_aie_update_irq - AIE mode rtctimer hook |
| 303 | * @private: pointer to the rtc_device |
| 304 | * |
| 305 | * This functions is called when the aie_timer expires. |
| 306 | */ |
| 307 | void rtc_aie_update_irq(void *private) |
| 308 | { |
| 309 | struct rtc_device *rtc = (struct rtc_device *)private; |
| 310 | rtc_handle_legacy_irq(rtc, 1, RTC_AF); |
| 311 | } |
| 312 | |
| 313 | |
| 314 | /** |
| 315 | * rtc_uie_update_irq - UIE mode rtctimer hook |
| 316 | * @private: pointer to the rtc_device |
| 317 | * |
| 318 | * This functions is called when the uie_timer expires. |
| 319 | */ |
| 320 | void rtc_uie_update_irq(void *private) |
| 321 | { |
| 322 | struct rtc_device *rtc = (struct rtc_device *)private; |
| 323 | rtc_handle_legacy_irq(rtc, 1, RTC_UF); |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /** |
| 328 | * rtc_pie_update_irq - PIE mode hrtimer hook |
| 329 | * @timer: pointer to the pie mode hrtimer |
| 330 | * |
| 331 | * This function is used to emulate PIE mode interrupts |
| 332 | * using an hrtimer. This function is called when the periodic |
| 333 | * hrtimer expires. |
| 334 | */ |
| 335 | enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) |
| 336 | { |
| 337 | struct rtc_device *rtc; |
| 338 | ktime_t period; |
| 339 | int count; |
| 340 | rtc = container_of(timer, struct rtc_device, pie_timer); |
| 341 | |
| 342 | period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq); |
| 343 | count = hrtimer_forward_now(timer, period); |
| 344 | |
| 345 | rtc_handle_legacy_irq(rtc, count, RTC_PF); |
| 346 | |
| 347 | return HRTIMER_RESTART; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * rtc_update_irq - Triggered when a RTC interrupt occurs. |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 352 | * @rtc: the rtc device |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 353 | * @num: how many irqs are being reported (usually one) |
| 354 | * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF |
Atsushi Nemoto | e6229bec | 2009-06-18 16:49:09 -0700 | [diff] [blame] | 355 | * Context: any |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 356 | */ |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 357 | void rtc_update_irq(struct rtc_device *rtc, |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 358 | unsigned long num, unsigned long events) |
| 359 | { |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 360 | schedule_work(&rtc->irqwork); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 361 | } |
| 362 | EXPORT_SYMBOL_GPL(rtc_update_irq); |
| 363 | |
Dave Young | 71da890 | 2008-01-22 14:00:34 +0800 | [diff] [blame] | 364 | static int __rtc_match(struct device *dev, void *data) |
| 365 | { |
| 366 | char *name = (char *)data; |
| 367 | |
Kay Sievers | d4afc76 | 2009-01-06 14:42:11 -0800 | [diff] [blame] | 368 | if (strcmp(dev_name(dev), name) == 0) |
Dave Young | 71da890 | 2008-01-22 14:00:34 +0800 | [diff] [blame] | 369 | return 1; |
| 370 | return 0; |
| 371 | } |
| 372 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 373 | struct rtc_device *rtc_class_open(char *name) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 374 | { |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 375 | struct device *dev; |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 376 | struct rtc_device *rtc = NULL; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 377 | |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 378 | dev = class_find_device(rtc_class, NULL, name, __rtc_match); |
Dave Young | 71da890 | 2008-01-22 14:00:34 +0800 | [diff] [blame] | 379 | if (dev) |
| 380 | rtc = to_rtc_device(dev); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 381 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 382 | if (rtc) { |
| 383 | if (!try_module_get(rtc->owner)) { |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 384 | put_device(dev); |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 385 | rtc = NULL; |
| 386 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 387 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 388 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 389 | return rtc; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 390 | } |
| 391 | EXPORT_SYMBOL_GPL(rtc_class_open); |
| 392 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 393 | void rtc_class_close(struct rtc_device *rtc) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 394 | { |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 395 | module_put(rtc->owner); |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 396 | put_device(&rtc->dev); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 397 | } |
| 398 | EXPORT_SYMBOL_GPL(rtc_class_close); |
| 399 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 400 | int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 401 | { |
| 402 | int retval = -EBUSY; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 403 | |
| 404 | if (task == NULL || task->func == NULL) |
| 405 | return -EINVAL; |
| 406 | |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 407 | /* Cannot register while the char dev is in use */ |
Jiri Kosina | 372a302 | 2007-12-04 23:45:05 -0800 | [diff] [blame] | 408 | if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 409 | return -EBUSY; |
| 410 | |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 411 | spin_lock_irq(&rtc->irq_task_lock); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 412 | if (rtc->irq_task == NULL) { |
| 413 | rtc->irq_task = task; |
| 414 | retval = 0; |
| 415 | } |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 416 | spin_unlock_irq(&rtc->irq_task_lock); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 417 | |
Jiri Kosina | 372a302 | 2007-12-04 23:45:05 -0800 | [diff] [blame] | 418 | clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 419 | |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 420 | return retval; |
| 421 | } |
| 422 | EXPORT_SYMBOL_GPL(rtc_irq_register); |
| 423 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 424 | void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 425 | { |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 426 | spin_lock_irq(&rtc->irq_task_lock); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 427 | if (rtc->irq_task == task) |
| 428 | rtc->irq_task = NULL; |
David Brownell | d728b1e | 2006-11-25 11:09:28 -0800 | [diff] [blame] | 429 | spin_unlock_irq(&rtc->irq_task_lock); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 430 | } |
| 431 | EXPORT_SYMBOL_GPL(rtc_irq_unregister); |
| 432 | |
David Brownell | 97144c6 | 2007-10-16 01:28:16 -0700 | [diff] [blame] | 433 | /** |
| 434 | * rtc_irq_set_state - enable/disable 2^N Hz periodic IRQs |
| 435 | * @rtc: the rtc device |
| 436 | * @task: currently registered with rtc_irq_register() |
| 437 | * @enabled: true to enable periodic IRQs |
| 438 | * Context: any |
| 439 | * |
| 440 | * Note that rtc_irq_set_freq() should previously have been used to |
| 441 | * specify the desired frequency of periodic IRQ task->func() callbacks. |
| 442 | */ |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 443 | int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 444 | { |
| 445 | int err = 0; |
| 446 | unsigned long flags; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 447 | |
| 448 | spin_lock_irqsave(&rtc->irq_task_lock, flags); |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 449 | if (rtc->irq_task != NULL && task == NULL) |
| 450 | err = -EBUSY; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 451 | if (rtc->irq_task != task) |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 452 | err = -EACCES; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 453 | |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 454 | if (enabled) { |
| 455 | ktime_t period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq); |
| 456 | hrtimer_start(&rtc->pie_timer, period, HRTIMER_MODE_REL); |
| 457 | } else { |
| 458 | hrtimer_cancel(&rtc->pie_timer); |
| 459 | } |
| 460 | rtc->pie_enabled = enabled; |
| 461 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 462 | |
| 463 | return err; |
| 464 | } |
| 465 | EXPORT_SYMBOL_GPL(rtc_irq_set_state); |
| 466 | |
David Brownell | 97144c6 | 2007-10-16 01:28:16 -0700 | [diff] [blame] | 467 | /** |
| 468 | * rtc_irq_set_freq - set 2^N Hz periodic IRQ frequency for IRQ |
| 469 | * @rtc: the rtc device |
| 470 | * @task: currently registered with rtc_irq_register() |
| 471 | * @freq: positive frequency with which task->func() will be called |
| 472 | * Context: any |
| 473 | * |
| 474 | * Note that rtc_irq_set_state() is used to enable or disable the |
| 475 | * periodic IRQs. |
| 476 | */ |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 477 | int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq) |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 478 | { |
Alessandro Zummo | 56f10c6 | 2006-06-25 05:48:20 -0700 | [diff] [blame] | 479 | int err = 0; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 480 | unsigned long flags; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 481 | |
Marcelo Roberto Jimenez | 83a06bf | 2011-02-02 16:04:02 -0200 | [diff] [blame] | 482 | if (freq <= 0) |
| 483 | return -EINVAL; |
| 484 | |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 485 | spin_lock_irqsave(&rtc->irq_task_lock, flags); |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 486 | if (rtc->irq_task != NULL && task == NULL) |
| 487 | err = -EBUSY; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 488 | if (rtc->irq_task != task) |
Alessandro Zummo | d691eb9 | 2007-10-16 01:28:15 -0700 | [diff] [blame] | 489 | err = -EACCES; |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 490 | if (err == 0) { |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 491 | rtc->irq_freq = freq; |
| 492 | if (rtc->pie_enabled) { |
| 493 | ktime_t period; |
| 494 | hrtimer_cancel(&rtc->pie_timer); |
| 495 | period = ktime_set(0, NSEC_PER_SEC/rtc->irq_freq); |
| 496 | hrtimer_start(&rtc->pie_timer, period, |
| 497 | HRTIMER_MODE_REL); |
| 498 | } |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 499 | } |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 500 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); |
Alessandro Zummo | 0c86edc | 2006-03-27 01:16:37 -0800 | [diff] [blame] | 501 | return err; |
| 502 | } |
David Brownell | 2601a46 | 2006-11-25 11:09:27 -0800 | [diff] [blame] | 503 | EXPORT_SYMBOL_GPL(rtc_irq_set_freq); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 504 | |
| 505 | /** |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 506 | * rtc_timer_enqueue - Adds a rtc_timer to the rtc_device timerqueue |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 507 | * @rtc rtc device |
| 508 | * @timer timer being added. |
| 509 | * |
| 510 | * Enqueues a timer onto the rtc devices timerqueue and sets |
| 511 | * the next alarm event appropriately. |
| 512 | * |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 513 | * Sets the enabled bit on the added timer. |
| 514 | * |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 515 | * Must hold ops_lock for proper serialization of timerqueue |
| 516 | */ |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 517 | static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 518 | { |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 519 | timer->enabled = 1; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 520 | timerqueue_add(&rtc->timerqueue, &timer->node); |
| 521 | if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) { |
| 522 | struct rtc_wkalrm alarm; |
| 523 | int err; |
| 524 | alarm.time = rtc_ktime_to_tm(timer->node.expires); |
| 525 | alarm.enabled = 1; |
| 526 | err = __rtc_set_alarm(rtc, &alarm); |
| 527 | if (err == -ETIME) |
| 528 | schedule_work(&rtc->irqwork); |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 529 | else if (err) { |
| 530 | timerqueue_del(&rtc->timerqueue, &timer->node); |
| 531 | timer->enabled = 0; |
| 532 | return err; |
| 533 | } |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 534 | } |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 535 | return 0; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 539 | * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 540 | * @rtc rtc device |
| 541 | * @timer timer being removed. |
| 542 | * |
| 543 | * Removes a timer onto the rtc devices timerqueue and sets |
| 544 | * the next alarm event appropriately. |
| 545 | * |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 546 | * Clears the enabled bit on the removed timer. |
| 547 | * |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 548 | * Must hold ops_lock for proper serialization of timerqueue |
| 549 | */ |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 550 | static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 551 | { |
| 552 | struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); |
| 553 | timerqueue_del(&rtc->timerqueue, &timer->node); |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 554 | timer->enabled = 0; |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 555 | if (next == &timer->node) { |
| 556 | struct rtc_wkalrm alarm; |
| 557 | int err; |
| 558 | next = timerqueue_getnext(&rtc->timerqueue); |
| 559 | if (!next) |
| 560 | return; |
| 561 | alarm.time = rtc_ktime_to_tm(next->expires); |
| 562 | alarm.enabled = 1; |
| 563 | err = __rtc_set_alarm(rtc, &alarm); |
| 564 | if (err == -ETIME) |
| 565 | schedule_work(&rtc->irqwork); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | /** |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 570 | * rtc_timer_do_work - Expires rtc timers |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 571 | * @rtc rtc device |
| 572 | * @timer timer being removed. |
| 573 | * |
| 574 | * Expires rtc timers. Reprograms next alarm event if needed. |
| 575 | * Called via worktask. |
| 576 | * |
| 577 | * Serializes access to timerqueue via ops_lock mutex |
| 578 | */ |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 579 | void rtc_timer_do_work(struct work_struct *work) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 580 | { |
| 581 | struct rtc_timer *timer; |
| 582 | struct timerqueue_node *next; |
| 583 | ktime_t now; |
| 584 | struct rtc_time tm; |
| 585 | |
| 586 | struct rtc_device *rtc = |
| 587 | container_of(work, struct rtc_device, irqwork); |
| 588 | |
| 589 | mutex_lock(&rtc->ops_lock); |
| 590 | again: |
| 591 | __rtc_read_time(rtc, &tm); |
| 592 | now = rtc_tm_to_ktime(tm); |
| 593 | while ((next = timerqueue_getnext(&rtc->timerqueue))) { |
| 594 | if (next->expires.tv64 > now.tv64) |
| 595 | break; |
| 596 | |
| 597 | /* expire timer */ |
| 598 | timer = container_of(next, struct rtc_timer, node); |
| 599 | timerqueue_del(&rtc->timerqueue, &timer->node); |
| 600 | timer->enabled = 0; |
| 601 | if (timer->task.func) |
| 602 | timer->task.func(timer->task.private_data); |
| 603 | |
| 604 | /* Re-add/fwd periodic timers */ |
| 605 | if (ktime_to_ns(timer->period)) { |
| 606 | timer->node.expires = ktime_add(timer->node.expires, |
| 607 | timer->period); |
| 608 | timer->enabled = 1; |
| 609 | timerqueue_add(&rtc->timerqueue, &timer->node); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | /* Set next alarm */ |
| 614 | if (next) { |
| 615 | struct rtc_wkalrm alarm; |
| 616 | int err; |
| 617 | alarm.time = rtc_ktime_to_tm(next->expires); |
| 618 | alarm.enabled = 1; |
| 619 | err = __rtc_set_alarm(rtc, &alarm); |
| 620 | if (err == -ETIME) |
| 621 | goto again; |
| 622 | } |
| 623 | |
| 624 | mutex_unlock(&rtc->ops_lock); |
| 625 | } |
| 626 | |
| 627 | |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 628 | /* rtc_timer_init - Initializes an rtc_timer |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 629 | * @timer: timer to be intiialized |
| 630 | * @f: function pointer to be called when timer fires |
| 631 | * @data: private data passed to function pointer |
| 632 | * |
| 633 | * Kernel interface to initializing an rtc_timer. |
| 634 | */ |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 635 | void rtc_timer_init(struct rtc_timer *timer, void (*f)(void* p), void* data) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 636 | { |
| 637 | timerqueue_init(&timer->node); |
| 638 | timer->enabled = 0; |
| 639 | timer->task.func = f; |
| 640 | timer->task.private_data = data; |
| 641 | } |
| 642 | |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 643 | /* rtc_timer_start - Sets an rtc_timer to fire in the future |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 644 | * @ rtc: rtc device to be used |
| 645 | * @ timer: timer being set |
| 646 | * @ expires: time at which to expire the timer |
| 647 | * @ period: period that the timer will recur |
| 648 | * |
| 649 | * Kernel interface to set an rtc_timer |
| 650 | */ |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 651 | int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer* timer, |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 652 | ktime_t expires, ktime_t period) |
| 653 | { |
| 654 | int ret = 0; |
| 655 | mutex_lock(&rtc->ops_lock); |
| 656 | if (timer->enabled) |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 657 | rtc_timer_remove(rtc, timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 658 | |
| 659 | timer->node.expires = expires; |
| 660 | timer->period = period; |
| 661 | |
John Stultz | aa0be0f | 2011-01-20 15:26:12 -0800 | [diff] [blame] | 662 | ret = rtc_timer_enqueue(rtc, timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 663 | |
| 664 | mutex_unlock(&rtc->ops_lock); |
| 665 | return ret; |
| 666 | } |
| 667 | |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 668 | /* rtc_timer_cancel - Stops an rtc_timer |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 669 | * @ rtc: rtc device to be used |
| 670 | * @ timer: timer being set |
| 671 | * |
| 672 | * Kernel interface to cancel an rtc_timer |
| 673 | */ |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 674 | int rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer* timer) |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 675 | { |
| 676 | int ret = 0; |
| 677 | mutex_lock(&rtc->ops_lock); |
| 678 | if (timer->enabled) |
Thomas Gleixner | 96c8f06 | 2010-12-13 22:45:48 +0100 | [diff] [blame] | 679 | rtc_timer_remove(rtc, timer); |
John Stultz | 6610e08 | 2010-09-23 15:07:34 -0700 | [diff] [blame] | 680 | mutex_unlock(&rtc->ops_lock); |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | |