Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/time/clockevents.c |
| 3 | * |
| 4 | * This file contains functions which manage clock event devices. |
| 5 | * |
| 6 | * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de> |
| 7 | * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar |
| 8 | * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner |
| 9 | * |
| 10 | * This code is licenced under the GPL version 2. For details see |
| 11 | * kernel-base/COPYING. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clockchips.h> |
| 15 | #include <linux/hrtimer.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/module.h> |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 18 | #include <linux/smp.h> |
Thomas Gleixner | 501f867 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 19 | #include <linux/device.h> |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 20 | |
H Hartley Sweeten | 8e1a928 | 2009-10-16 18:19:01 -0400 | [diff] [blame] | 21 | #include "tick-internal.h" |
| 22 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 23 | /* The registered clock event devices */ |
| 24 | static LIST_HEAD(clockevent_devices); |
| 25 | static LIST_HEAD(clockevents_released); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 26 | /* Protection for the above */ |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 27 | static DEFINE_RAW_SPINLOCK(clockevents_lock); |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 28 | /* Protection for unbind operations */ |
| 29 | static DEFINE_MUTEX(clockevents_mutex); |
| 30 | |
| 31 | struct ce_unbind { |
| 32 | struct clock_event_device *ce; |
| 33 | int res; |
| 34 | }; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 35 | |
Thomas Gleixner | 97b9410 | 2013-09-24 21:50:23 +0200 | [diff] [blame] | 36 | static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt, |
| 37 | bool ismax) |
| 38 | { |
| 39 | u64 clc = (u64) latch << evt->shift; |
| 40 | u64 rnd; |
| 41 | |
| 42 | if (unlikely(!evt->mult)) { |
| 43 | evt->mult = 1; |
| 44 | WARN_ON(1); |
| 45 | } |
| 46 | rnd = (u64) evt->mult - 1; |
| 47 | |
| 48 | /* |
| 49 | * Upper bound sanity check. If the backwards conversion is |
| 50 | * not equal latch, we know that the above shift overflowed. |
| 51 | */ |
| 52 | if ((clc >> evt->shift) != (u64)latch) |
| 53 | clc = ~0ULL; |
| 54 | |
| 55 | /* |
| 56 | * Scaled math oddities: |
| 57 | * |
| 58 | * For mult <= (1 << shift) we can safely add mult - 1 to |
| 59 | * prevent integer rounding loss. So the backwards conversion |
| 60 | * from nsec to device ticks will be correct. |
| 61 | * |
| 62 | * For mult > (1 << shift), i.e. device frequency is > 1GHz we |
| 63 | * need to be careful. Adding mult - 1 will result in a value |
| 64 | * which when converted back to device ticks can be larger |
| 65 | * than latch by up to (mult - 1) >> shift. For the min_delta |
| 66 | * calculation we still want to apply this in order to stay |
| 67 | * above the minimum device ticks limit. For the upper limit |
| 68 | * we would end up with a latch value larger than the upper |
| 69 | * limit of the device, so we omit the add to stay below the |
| 70 | * device upper boundary. |
| 71 | * |
| 72 | * Also omit the add if it would overflow the u64 boundary. |
| 73 | */ |
| 74 | if ((~0ULL - clc > rnd) && |
Thomas Gleixner | 1063200 | 2014-10-20 15:07:50 +0400 | [diff] [blame] | 75 | (!ismax || evt->mult <= (1ULL << evt->shift))) |
Thomas Gleixner | 97b9410 | 2013-09-24 21:50:23 +0200 | [diff] [blame] | 76 | clc += rnd; |
| 77 | |
| 78 | do_div(clc, evt->mult); |
| 79 | |
| 80 | /* Deltas less than 1usec are pointless noise */ |
| 81 | return clc > 1000 ? clc : 1000; |
| 82 | } |
| 83 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 84 | /** |
| 85 | * clockevents_delta2ns - Convert a latch value (device ticks) to nanoseconds |
| 86 | * @latch: value to convert |
| 87 | * @evt: pointer to clock event device descriptor |
| 88 | * |
| 89 | * Math helper, returns latch value converted to nanoseconds (bound checked) |
| 90 | */ |
Jon Hunter | 97813f2 | 2009-08-18 12:45:11 -0500 | [diff] [blame] | 91 | u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt) |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 92 | { |
Thomas Gleixner | 97b9410 | 2013-09-24 21:50:23 +0200 | [diff] [blame] | 93 | return cev_delta2ns(latch, evt, false); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 94 | } |
Magnus Damm | c81fc2c | 2009-05-01 14:52:47 +0900 | [diff] [blame] | 95 | EXPORT_SYMBOL_GPL(clockevent_delta2ns); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 96 | |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 97 | static int __clockevents_set_mode(struct clock_event_device *dev, |
| 98 | enum clock_event_mode mode) |
| 99 | { |
| 100 | /* Transition with legacy set_mode() callback */ |
| 101 | if (dev->set_mode) { |
| 102 | /* Legacy callback doesn't support new modes */ |
Viresh Kumar | 554ef38 | 2015-02-27 17:21:32 +0530 | [diff] [blame^] | 103 | if (mode > CLOCK_EVT_MODE_ONESHOT) |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 104 | return -ENOSYS; |
| 105 | dev->set_mode(mode, dev); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | if (dev->features & CLOCK_EVT_FEAT_DUMMY) |
| 110 | return 0; |
| 111 | |
| 112 | /* Transition with new mode-specific callbacks */ |
| 113 | switch (mode) { |
| 114 | case CLOCK_EVT_MODE_UNUSED: |
| 115 | /* |
| 116 | * This is an internal state, which is guaranteed to go from |
| 117 | * SHUTDOWN to UNUSED. No driver interaction required. |
| 118 | */ |
| 119 | return 0; |
| 120 | |
| 121 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 122 | return dev->set_mode_shutdown(dev); |
| 123 | |
| 124 | case CLOCK_EVT_MODE_PERIODIC: |
| 125 | /* Core internal bug */ |
| 126 | if (!(dev->features & CLOCK_EVT_FEAT_PERIODIC)) |
| 127 | return -ENOSYS; |
| 128 | return dev->set_mode_periodic(dev); |
| 129 | |
| 130 | case CLOCK_EVT_MODE_ONESHOT: |
| 131 | /* Core internal bug */ |
| 132 | if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT)) |
| 133 | return -ENOSYS; |
| 134 | return dev->set_mode_oneshot(dev); |
| 135 | |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 136 | default: |
| 137 | return -ENOSYS; |
| 138 | } |
| 139 | } |
| 140 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 141 | /** |
| 142 | * clockevents_set_mode - set the operating mode of a clock event device |
| 143 | * @dev: device to modify |
| 144 | * @mode: new mode |
| 145 | * |
| 146 | * Must be called with interrupts disabled ! |
| 147 | */ |
| 148 | void clockevents_set_mode(struct clock_event_device *dev, |
| 149 | enum clock_event_mode mode) |
| 150 | { |
| 151 | if (dev->mode != mode) { |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 152 | if (__clockevents_set_mode(dev, mode)) |
| 153 | return; |
| 154 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 155 | dev->mode = mode; |
Magnus Damm | 2d68259 | 2009-01-16 17:14:38 +0900 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * A nsec2cyc multiplicator of 0 is invalid and we'd crash |
| 159 | * on it, so fix it up and emit a warning: |
| 160 | */ |
| 161 | if (mode == CLOCK_EVT_MODE_ONESHOT) { |
| 162 | if (unlikely(!dev->mult)) { |
| 163 | dev->mult = 1; |
| 164 | WARN_ON(1); |
| 165 | } |
| 166 | } |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 171 | * clockevents_shutdown - shutdown the device and clear next_event |
| 172 | * @dev: device to shutdown |
| 173 | */ |
| 174 | void clockevents_shutdown(struct clock_event_device *dev) |
| 175 | { |
| 176 | clockevents_set_mode(dev, CLOCK_EVT_MODE_SHUTDOWN); |
| 177 | dev->next_event.tv64 = KTIME_MAX; |
| 178 | } |
| 179 | |
Viresh Kumar | 554ef38 | 2015-02-27 17:21:32 +0530 | [diff] [blame^] | 180 | /** |
| 181 | * clockevents_tick_resume - Resume the tick device before using it again |
| 182 | * @dev: device to resume |
| 183 | */ |
| 184 | int clockevents_tick_resume(struct clock_event_device *dev) |
| 185 | { |
| 186 | int ret = 0; |
| 187 | |
| 188 | if (dev->set_mode) |
| 189 | dev->set_mode(CLOCK_EVT_MODE_RESUME, dev); |
| 190 | else if (dev->tick_resume) |
| 191 | ret = dev->tick_resume(dev); |
| 192 | |
| 193 | if (likely(!ret)) |
| 194 | dev->mode = CLOCK_EVT_MODE_RESUME; |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 199 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST |
| 200 | |
| 201 | /* Limit min_delta to a jiffie */ |
| 202 | #define MIN_DELTA_LIMIT (NSEC_PER_SEC / HZ) |
| 203 | |
| 204 | /** |
| 205 | * clockevents_increase_min_delta - raise minimum delta of a clock event device |
| 206 | * @dev: device to increase the minimum delta |
| 207 | * |
| 208 | * Returns 0 on success, -ETIME when the minimum delta reached the limit. |
| 209 | */ |
| 210 | static int clockevents_increase_min_delta(struct clock_event_device *dev) |
| 211 | { |
| 212 | /* Nothing to do if we already reached the limit */ |
| 213 | if (dev->min_delta_ns >= MIN_DELTA_LIMIT) { |
Jan Kara | 504d587 | 2014-08-01 12:20:02 +0200 | [diff] [blame] | 214 | printk_deferred(KERN_WARNING |
| 215 | "CE: Reprogramming failure. Giving up\n"); |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 216 | dev->next_event.tv64 = KTIME_MAX; |
| 217 | return -ETIME; |
| 218 | } |
| 219 | |
| 220 | if (dev->min_delta_ns < 5000) |
| 221 | dev->min_delta_ns = 5000; |
| 222 | else |
| 223 | dev->min_delta_ns += dev->min_delta_ns >> 1; |
| 224 | |
| 225 | if (dev->min_delta_ns > MIN_DELTA_LIMIT) |
| 226 | dev->min_delta_ns = MIN_DELTA_LIMIT; |
| 227 | |
Jan Kara | 504d587 | 2014-08-01 12:20:02 +0200 | [diff] [blame] | 228 | printk_deferred(KERN_WARNING |
| 229 | "CE: %s increased min_delta_ns to %llu nsec\n", |
| 230 | dev->name ? dev->name : "?", |
| 231 | (unsigned long long) dev->min_delta_ns); |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * clockevents_program_min_delta - Set clock event device to the minimum delay. |
| 237 | * @dev: device to program |
| 238 | * |
| 239 | * Returns 0 on success, -ETIME when the retry loop failed. |
| 240 | */ |
| 241 | static int clockevents_program_min_delta(struct clock_event_device *dev) |
| 242 | { |
| 243 | unsigned long long clc; |
| 244 | int64_t delta; |
| 245 | int i; |
| 246 | |
| 247 | for (i = 0;;) { |
| 248 | delta = dev->min_delta_ns; |
| 249 | dev->next_event = ktime_add_ns(ktime_get(), delta); |
| 250 | |
| 251 | if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN) |
| 252 | return 0; |
| 253 | |
| 254 | dev->retries++; |
| 255 | clc = ((unsigned long long) delta * dev->mult) >> dev->shift; |
| 256 | if (dev->set_next_event((unsigned long) clc, dev) == 0) |
| 257 | return 0; |
| 258 | |
| 259 | if (++i > 2) { |
| 260 | /* |
| 261 | * We tried 3 times to program the device with the |
| 262 | * given min_delta_ns. Try to increase the minimum |
| 263 | * delta, if that fails as well get out of here. |
| 264 | */ |
| 265 | if (clockevents_increase_min_delta(dev)) |
| 266 | return -ETIME; |
| 267 | i = 0; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | #else /* CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST */ |
| 273 | |
| 274 | /** |
| 275 | * clockevents_program_min_delta - Set clock event device to the minimum delay. |
| 276 | * @dev: device to program |
| 277 | * |
| 278 | * Returns 0 on success, -ETIME when the retry loop failed. |
| 279 | */ |
| 280 | static int clockevents_program_min_delta(struct clock_event_device *dev) |
| 281 | { |
| 282 | unsigned long long clc; |
| 283 | int64_t delta; |
| 284 | |
| 285 | delta = dev->min_delta_ns; |
| 286 | dev->next_event = ktime_add_ns(ktime_get(), delta); |
| 287 | |
| 288 | if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN) |
| 289 | return 0; |
| 290 | |
| 291 | dev->retries++; |
| 292 | clc = ((unsigned long long) delta * dev->mult) >> dev->shift; |
| 293 | return dev->set_next_event((unsigned long) clc, dev); |
| 294 | } |
| 295 | |
| 296 | #endif /* CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST */ |
| 297 | |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 298 | /** |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 299 | * clockevents_program_event - Reprogram the clock event device. |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 300 | * @dev: device to program |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 301 | * @expires: absolute expiry time (monotonic clock) |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 302 | * @force: program minimum delay if expires can not be set |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 303 | * |
| 304 | * Returns 0 on success, -ETIME when the event is in the past. |
| 305 | */ |
| 306 | int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 307 | bool force) |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 308 | { |
| 309 | unsigned long long clc; |
| 310 | int64_t delta; |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 311 | int rc; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 312 | |
Thomas Gleixner | 167b1de | 2007-12-07 19:16:17 +0100 | [diff] [blame] | 313 | if (unlikely(expires.tv64 < 0)) { |
| 314 | WARN_ON_ONCE(1); |
| 315 | return -ETIME; |
| 316 | } |
| 317 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 318 | dev->next_event = expires; |
| 319 | |
| 320 | if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN) |
| 321 | return 0; |
| 322 | |
Martin Schwidefsky | 65516f8 | 2011-08-23 15:29:43 +0200 | [diff] [blame] | 323 | /* Shortcut for clockevent devices that can deal with ktime. */ |
| 324 | if (dev->features & CLOCK_EVT_FEAT_KTIME) |
| 325 | return dev->set_next_ktime(expires, dev); |
| 326 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 327 | delta = ktime_to_ns(ktime_sub(expires, ktime_get())); |
| 328 | if (delta <= 0) |
| 329 | return force ? clockevents_program_min_delta(dev) : -ETIME; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 330 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 331 | delta = min(delta, (int64_t) dev->max_delta_ns); |
| 332 | delta = max(delta, (int64_t) dev->min_delta_ns); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 333 | |
Martin Schwidefsky | d174830 | 2011-08-23 15:29:42 +0200 | [diff] [blame] | 334 | clc = ((unsigned long long) delta * dev->mult) >> dev->shift; |
| 335 | rc = dev->set_next_event((unsigned long) clc, dev); |
| 336 | |
| 337 | return (rc && force) ? clockevents_program_min_delta(dev) : rc; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 340 | /* |
Li Zefan | 3eb0567 | 2008-02-08 04:19:25 -0800 | [diff] [blame] | 341 | * Called after a notify add to make devices available which were |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 342 | * released from the notifier call. |
| 343 | */ |
| 344 | static void clockevents_notify_released(void) |
| 345 | { |
| 346 | struct clock_event_device *dev; |
| 347 | |
| 348 | while (!list_empty(&clockevents_released)) { |
| 349 | dev = list_entry(clockevents_released.next, |
| 350 | struct clock_event_device, list); |
| 351 | list_del(&dev->list); |
| 352 | list_add(&dev->list, &clockevent_devices); |
Thomas Gleixner | 7172a286 | 2013-04-25 20:31:47 +0000 | [diff] [blame] | 353 | tick_check_new_device(dev); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 357 | /* |
| 358 | * Try to install a replacement clock event device |
| 359 | */ |
| 360 | static int clockevents_replace(struct clock_event_device *ced) |
| 361 | { |
| 362 | struct clock_event_device *dev, *newdev = NULL; |
| 363 | |
| 364 | list_for_each_entry(dev, &clockevent_devices, list) { |
| 365 | if (dev == ced || dev->mode != CLOCK_EVT_MODE_UNUSED) |
| 366 | continue; |
| 367 | |
| 368 | if (!tick_check_replacement(newdev, dev)) |
| 369 | continue; |
| 370 | |
| 371 | if (!try_module_get(dev->owner)) |
| 372 | continue; |
| 373 | |
| 374 | if (newdev) |
| 375 | module_put(newdev->owner); |
| 376 | newdev = dev; |
| 377 | } |
| 378 | if (newdev) { |
| 379 | tick_install_replacement(newdev); |
| 380 | list_del_init(&ced->list); |
| 381 | } |
| 382 | return newdev ? 0 : -EBUSY; |
| 383 | } |
| 384 | |
| 385 | /* |
| 386 | * Called with clockevents_mutex and clockevents_lock held |
| 387 | */ |
| 388 | static int __clockevents_try_unbind(struct clock_event_device *ced, int cpu) |
| 389 | { |
| 390 | /* Fast track. Device is unused */ |
| 391 | if (ced->mode == CLOCK_EVT_MODE_UNUSED) { |
| 392 | list_del_init(&ced->list); |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | return ced == per_cpu(tick_cpu_device, cpu).evtdev ? -EAGAIN : -EBUSY; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * SMP function call to unbind a device |
| 401 | */ |
| 402 | static void __clockevents_unbind(void *arg) |
| 403 | { |
| 404 | struct ce_unbind *cu = arg; |
| 405 | int res; |
| 406 | |
| 407 | raw_spin_lock(&clockevents_lock); |
| 408 | res = __clockevents_try_unbind(cu->ce, smp_processor_id()); |
| 409 | if (res == -EAGAIN) |
| 410 | res = clockevents_replace(cu->ce); |
| 411 | cu->res = res; |
| 412 | raw_spin_unlock(&clockevents_lock); |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * Issues smp function call to unbind a per cpu device. Called with |
| 417 | * clockevents_mutex held. |
| 418 | */ |
| 419 | static int clockevents_unbind(struct clock_event_device *ced, int cpu) |
| 420 | { |
| 421 | struct ce_unbind cu = { .ce = ced, .res = -ENODEV }; |
| 422 | |
| 423 | smp_call_function_single(cpu, __clockevents_unbind, &cu, 1); |
| 424 | return cu.res; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * Unbind a clockevents device. |
| 429 | */ |
| 430 | int clockevents_unbind_device(struct clock_event_device *ced, int cpu) |
| 431 | { |
| 432 | int ret; |
| 433 | |
| 434 | mutex_lock(&clockevents_mutex); |
| 435 | ret = clockevents_unbind(ced, cpu); |
| 436 | mutex_unlock(&clockevents_mutex); |
| 437 | return ret; |
| 438 | } |
| 439 | EXPORT_SYMBOL_GPL(clockevents_unbind); |
| 440 | |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 441 | /* Sanity check of mode transition callbacks */ |
| 442 | static int clockevents_sanity_check(struct clock_event_device *dev) |
| 443 | { |
| 444 | /* Legacy set_mode() callback */ |
| 445 | if (dev->set_mode) { |
| 446 | /* We shouldn't be supporting new modes now */ |
| 447 | WARN_ON(dev->set_mode_periodic || dev->set_mode_oneshot || |
Viresh Kumar | 554ef38 | 2015-02-27 17:21:32 +0530 | [diff] [blame^] | 448 | dev->set_mode_shutdown || dev->tick_resume); |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | if (dev->features & CLOCK_EVT_FEAT_DUMMY) |
| 453 | return 0; |
| 454 | |
| 455 | /* New mode-specific callbacks */ |
| 456 | if (!dev->set_mode_shutdown) |
| 457 | return -EINVAL; |
| 458 | |
| 459 | if ((dev->features & CLOCK_EVT_FEAT_PERIODIC) && |
| 460 | !dev->set_mode_periodic) |
| 461 | return -EINVAL; |
| 462 | |
| 463 | if ((dev->features & CLOCK_EVT_FEAT_ONESHOT) && |
| 464 | !dev->set_mode_oneshot) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 470 | /** |
| 471 | * clockevents_register_device - register a clock event device |
| 472 | * @dev: device to register |
| 473 | */ |
| 474 | void clockevents_register_device(struct clock_event_device *dev) |
| 475 | { |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 476 | unsigned long flags; |
| 477 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 478 | BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED); |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 479 | BUG_ON(clockevents_sanity_check(dev)); |
| 480 | |
Thomas Gleixner | 1b054b6 | 2011-06-03 11:13:33 +0200 | [diff] [blame] | 481 | if (!dev->cpumask) { |
| 482 | WARN_ON(num_possible_cpus() > 1); |
| 483 | dev->cpumask = cpumask_of(smp_processor_id()); |
| 484 | } |
Rusty Russell | 320ab2b | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 485 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 486 | raw_spin_lock_irqsave(&clockevents_lock, flags); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 487 | |
| 488 | list_add(&dev->list, &clockevent_devices); |
Thomas Gleixner | 7172a286 | 2013-04-25 20:31:47 +0000 | [diff] [blame] | 489 | tick_check_new_device(dev); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 490 | clockevents_notify_released(); |
| 491 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 492 | raw_spin_unlock_irqrestore(&clockevents_lock, flags); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 493 | } |
Magnus Damm | c81fc2c | 2009-05-01 14:52:47 +0900 | [diff] [blame] | 494 | EXPORT_SYMBOL_GPL(clockevents_register_device); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 495 | |
Magnus Damm | e540032 | 2012-05-09 23:39:34 +0900 | [diff] [blame] | 496 | void clockevents_config(struct clock_event_device *dev, u32 freq) |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 497 | { |
Thomas Gleixner | c0e299b | 2011-05-20 10:50:52 +0200 | [diff] [blame] | 498 | u64 sec; |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 499 | |
| 500 | if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT)) |
| 501 | return; |
| 502 | |
| 503 | /* |
| 504 | * Calculate the maximum number of seconds we can sleep. Limit |
| 505 | * to 10 minutes for hardware which can program more than |
| 506 | * 32bit ticks so we still get reasonable conversion values. |
| 507 | */ |
| 508 | sec = dev->max_delta_ticks; |
| 509 | do_div(sec, freq); |
| 510 | if (!sec) |
| 511 | sec = 1; |
| 512 | else if (sec > 600 && dev->max_delta_ticks > UINT_MAX) |
| 513 | sec = 600; |
| 514 | |
| 515 | clockevents_calc_mult_shift(dev, freq, sec); |
Thomas Gleixner | 97b9410 | 2013-09-24 21:50:23 +0200 | [diff] [blame] | 516 | dev->min_delta_ns = cev_delta2ns(dev->min_delta_ticks, dev, false); |
| 517 | dev->max_delta_ns = cev_delta2ns(dev->max_delta_ticks, dev, true); |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| 521 | * clockevents_config_and_register - Configure and register a clock event device |
| 522 | * @dev: device to register |
| 523 | * @freq: The clock frequency |
| 524 | * @min_delta: The minimum clock ticks to program in oneshot mode |
| 525 | * @max_delta: The maximum clock ticks to program in oneshot mode |
| 526 | * |
| 527 | * min/max_delta can be 0 for devices which do not support oneshot mode. |
| 528 | */ |
| 529 | void clockevents_config_and_register(struct clock_event_device *dev, |
| 530 | u32 freq, unsigned long min_delta, |
| 531 | unsigned long max_delta) |
| 532 | { |
| 533 | dev->min_delta_ticks = min_delta; |
| 534 | dev->max_delta_ticks = max_delta; |
| 535 | clockevents_config(dev, freq); |
| 536 | clockevents_register_device(dev); |
| 537 | } |
Shawn Guo | c35ef95 | 2013-01-12 11:50:04 +0000 | [diff] [blame] | 538 | EXPORT_SYMBOL_GPL(clockevents_config_and_register); |
Thomas Gleixner | 57f0fcb | 2011-05-18 21:33:41 +0000 | [diff] [blame] | 539 | |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 540 | int __clockevents_update_freq(struct clock_event_device *dev, u32 freq) |
Thomas Gleixner | 80b816b | 2011-05-18 21:33:42 +0000 | [diff] [blame] | 541 | { |
| 542 | clockevents_config(dev, freq); |
| 543 | |
Soren Brinkmann | fe79a9b | 2014-02-03 14:34:32 -0800 | [diff] [blame] | 544 | if (dev->mode == CLOCK_EVT_MODE_ONESHOT) |
| 545 | return clockevents_program_event(dev, dev->next_event, false); |
Thomas Gleixner | 80b816b | 2011-05-18 21:33:42 +0000 | [diff] [blame] | 546 | |
Soren Brinkmann | fe79a9b | 2014-02-03 14:34:32 -0800 | [diff] [blame] | 547 | if (dev->mode == CLOCK_EVT_MODE_PERIODIC) |
Viresh Kumar | bd624d7 | 2015-02-13 08:54:56 +0800 | [diff] [blame] | 548 | return __clockevents_set_mode(dev, CLOCK_EVT_MODE_PERIODIC); |
Soren Brinkmann | fe79a9b | 2014-02-03 14:34:32 -0800 | [diff] [blame] | 549 | |
| 550 | return 0; |
Thomas Gleixner | 80b816b | 2011-05-18 21:33:42 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Thomas Gleixner | 627ee79 | 2014-02-03 14:34:31 -0800 | [diff] [blame] | 553 | /** |
| 554 | * clockevents_update_freq - Update frequency and reprogram a clock event device. |
| 555 | * @dev: device to modify |
| 556 | * @freq: new device frequency |
| 557 | * |
| 558 | * Reconfigure and reprogram a clock event device in oneshot |
| 559 | * mode. Must be called on the cpu for which the device delivers per |
| 560 | * cpu timer events. If called for the broadcast device the core takes |
| 561 | * care of serialization. |
| 562 | * |
| 563 | * Returns 0 on success, -ETIME when the event is in the past. |
| 564 | */ |
| 565 | int clockevents_update_freq(struct clock_event_device *dev, u32 freq) |
| 566 | { |
| 567 | unsigned long flags; |
| 568 | int ret; |
| 569 | |
| 570 | local_irq_save(flags); |
| 571 | ret = tick_broadcast_update_freq(dev, freq); |
| 572 | if (ret == -ENODEV) |
| 573 | ret = __clockevents_update_freq(dev, freq); |
| 574 | local_irq_restore(flags); |
| 575 | return ret; |
| 576 | } |
| 577 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 578 | /* |
| 579 | * Noop handler when we shut down an event device |
| 580 | */ |
Venkatesh Pallipadi | 7c1e768 | 2008-09-03 21:36:50 +0000 | [diff] [blame] | 581 | void clockevents_handle_noop(struct clock_event_device *dev) |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 582 | { |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * clockevents_exchange_device - release and request clock devices |
| 587 | * @old: device to release (can be NULL) |
| 588 | * @new: device to request (can be NULL) |
| 589 | * |
| 590 | * Called from the notifier chain. clockevents_lock is held already |
| 591 | */ |
| 592 | void clockevents_exchange_device(struct clock_event_device *old, |
| 593 | struct clock_event_device *new) |
| 594 | { |
| 595 | unsigned long flags; |
| 596 | |
| 597 | local_irq_save(flags); |
| 598 | /* |
| 599 | * Caller releases a clock event device. We queue it into the |
| 600 | * released list and do a notify add later. |
| 601 | */ |
| 602 | if (old) { |
Thomas Gleixner | ccf33d6 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 603 | module_put(old->owner); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 604 | clockevents_set_mode(old, CLOCK_EVT_MODE_UNUSED); |
| 605 | list_del(&old->list); |
| 606 | list_add(&old->list, &clockevents_released); |
| 607 | } |
| 608 | |
| 609 | if (new) { |
| 610 | BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED); |
Thomas Gleixner | 2344abb | 2008-09-16 11:32:50 -0700 | [diff] [blame] | 611 | clockevents_shutdown(new); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 612 | } |
| 613 | local_irq_restore(flags); |
| 614 | } |
| 615 | |
Rafael J. Wysocki | adc78e6 | 2012-08-06 01:40:41 +0200 | [diff] [blame] | 616 | /** |
| 617 | * clockevents_suspend - suspend clock devices |
| 618 | */ |
| 619 | void clockevents_suspend(void) |
| 620 | { |
| 621 | struct clock_event_device *dev; |
| 622 | |
| 623 | list_for_each_entry_reverse(dev, &clockevent_devices, list) |
| 624 | if (dev->suspend) |
| 625 | dev->suspend(dev); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * clockevents_resume - resume clock devices |
| 630 | */ |
| 631 | void clockevents_resume(void) |
| 632 | { |
| 633 | struct clock_event_device *dev; |
| 634 | |
| 635 | list_for_each_entry(dev, &clockevent_devices, list) |
| 636 | if (dev->resume) |
| 637 | dev->resume(dev); |
| 638 | } |
| 639 | |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 640 | #ifdef CONFIG_GENERIC_CLOCKEVENTS |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 641 | /** |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 642 | * clockevents_notify - notification about relevant events |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 643 | * Returns 0 on success, any other value on error |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 644 | */ |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 645 | int clockevents_notify(unsigned long reason, void *arg) |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 646 | { |
Thomas Gleixner | bb6eddf | 2009-12-10 15:35:10 +0100 | [diff] [blame] | 647 | struct clock_event_device *dev, *tmp; |
Suresh Siddha | f833bab | 2009-08-17 14:34:59 -0700 | [diff] [blame] | 648 | unsigned long flags; |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 649 | int cpu, ret = 0; |
Li Zefan | 0b858e6 | 2008-02-08 04:19:24 -0800 | [diff] [blame] | 650 | |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 651 | raw_spin_lock_irqsave(&clockevents_lock, flags); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 652 | |
| 653 | switch (reason) { |
Thomas Gleixner | 8c53daf | 2013-04-25 20:31:48 +0000 | [diff] [blame] | 654 | case CLOCK_EVT_NOTIFY_BROADCAST_ON: |
| 655 | case CLOCK_EVT_NOTIFY_BROADCAST_OFF: |
| 656 | case CLOCK_EVT_NOTIFY_BROADCAST_FORCE: |
| 657 | tick_broadcast_on_off(reason, arg); |
| 658 | break; |
| 659 | |
| 660 | case CLOCK_EVT_NOTIFY_BROADCAST_ENTER: |
| 661 | case CLOCK_EVT_NOTIFY_BROADCAST_EXIT: |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 662 | ret = tick_broadcast_oneshot_control(reason); |
Thomas Gleixner | 8c53daf | 2013-04-25 20:31:48 +0000 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case CLOCK_EVT_NOTIFY_CPU_DYING: |
| 666 | tick_handover_do_timer(arg); |
| 667 | break; |
| 668 | |
| 669 | case CLOCK_EVT_NOTIFY_SUSPEND: |
| 670 | tick_suspend(); |
| 671 | tick_suspend_broadcast(); |
| 672 | break; |
| 673 | |
| 674 | case CLOCK_EVT_NOTIFY_RESUME: |
| 675 | tick_resume(); |
| 676 | break; |
| 677 | |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 678 | case CLOCK_EVT_NOTIFY_CPU_DEAD: |
Thomas Gleixner | 8c53daf | 2013-04-25 20:31:48 +0000 | [diff] [blame] | 679 | tick_shutdown_broadcast_oneshot(arg); |
| 680 | tick_shutdown_broadcast(arg); |
| 681 | tick_shutdown(arg); |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 682 | /* |
| 683 | * Unregister the clock event devices which were |
| 684 | * released from the users in the notify chain. |
| 685 | */ |
Thomas Gleixner | bb6eddf | 2009-12-10 15:35:10 +0100 | [diff] [blame] | 686 | list_for_each_entry_safe(dev, tmp, &clockevents_released, list) |
| 687 | list_del(&dev->list); |
| 688 | /* |
| 689 | * Now check whether the CPU has left unused per cpu devices |
| 690 | */ |
| 691 | cpu = *((int *)arg); |
| 692 | list_for_each_entry_safe(dev, tmp, &clockevent_devices, list) { |
| 693 | if (cpumask_test_cpu(cpu, dev->cpumask) && |
Xiaotian Feng | ea9d8e3 | 2010-01-07 11:22:44 +0800 | [diff] [blame] | 694 | cpumask_weight(dev->cpumask) == 1 && |
| 695 | !tick_is_broadcast_device(dev)) { |
Thomas Gleixner | bb6eddf | 2009-12-10 15:35:10 +0100 | [diff] [blame] | 696 | BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED); |
| 697 | list_del(&dev->list); |
| 698 | } |
| 699 | } |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 700 | break; |
| 701 | default: |
| 702 | break; |
| 703 | } |
Thomas Gleixner | b5f91da | 2009-12-08 12:40:31 +0100 | [diff] [blame] | 704 | raw_spin_unlock_irqrestore(&clockevents_lock, flags); |
Preeti U Murthy | da7e6f4 | 2014-02-07 13:36:06 +0530 | [diff] [blame] | 705 | return ret; |
Thomas Gleixner | d316c57 | 2007-02-16 01:28:00 -0800 | [diff] [blame] | 706 | } |
| 707 | EXPORT_SYMBOL_GPL(clockevents_notify); |
Thomas Gleixner | 501f867 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 708 | |
| 709 | #ifdef CONFIG_SYSFS |
| 710 | struct bus_type clockevents_subsys = { |
| 711 | .name = "clockevents", |
| 712 | .dev_name = "clockevent", |
| 713 | }; |
| 714 | |
| 715 | static DEFINE_PER_CPU(struct device, tick_percpu_dev); |
| 716 | static struct tick_device *tick_get_tick_dev(struct device *dev); |
| 717 | |
| 718 | static ssize_t sysfs_show_current_tick_dev(struct device *dev, |
| 719 | struct device_attribute *attr, |
| 720 | char *buf) |
| 721 | { |
| 722 | struct tick_device *td; |
| 723 | ssize_t count = 0; |
| 724 | |
| 725 | raw_spin_lock_irq(&clockevents_lock); |
| 726 | td = tick_get_tick_dev(dev); |
| 727 | if (td && td->evtdev) |
| 728 | count = snprintf(buf, PAGE_SIZE, "%s\n", td->evtdev->name); |
| 729 | raw_spin_unlock_irq(&clockevents_lock); |
| 730 | return count; |
| 731 | } |
| 732 | static DEVICE_ATTR(current_device, 0444, sysfs_show_current_tick_dev, NULL); |
| 733 | |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 734 | /* We don't support the abomination of removable broadcast devices */ |
| 735 | static ssize_t sysfs_unbind_tick_dev(struct device *dev, |
| 736 | struct device_attribute *attr, |
| 737 | const char *buf, size_t count) |
| 738 | { |
| 739 | char name[CS_NAME_LEN]; |
Patrick Palka | 891292a | 2013-10-11 13:11:55 -0400 | [diff] [blame] | 740 | ssize_t ret = sysfs_get_uname(buf, name, count); |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 741 | struct clock_event_device *ce; |
| 742 | |
| 743 | if (ret < 0) |
| 744 | return ret; |
| 745 | |
| 746 | ret = -ENODEV; |
| 747 | mutex_lock(&clockevents_mutex); |
| 748 | raw_spin_lock_irq(&clockevents_lock); |
| 749 | list_for_each_entry(ce, &clockevent_devices, list) { |
| 750 | if (!strcmp(ce->name, name)) { |
| 751 | ret = __clockevents_try_unbind(ce, dev->id); |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | raw_spin_unlock_irq(&clockevents_lock); |
| 756 | /* |
| 757 | * We hold clockevents_mutex, so ce can't go away |
| 758 | */ |
| 759 | if (ret == -EAGAIN) |
| 760 | ret = clockevents_unbind(ce, dev->id); |
| 761 | mutex_unlock(&clockevents_mutex); |
| 762 | return ret ? ret : count; |
| 763 | } |
| 764 | static DEVICE_ATTR(unbind_device, 0200, NULL, sysfs_unbind_tick_dev); |
| 765 | |
Thomas Gleixner | 501f867 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 766 | #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST |
| 767 | static struct device tick_bc_dev = { |
| 768 | .init_name = "broadcast", |
| 769 | .id = 0, |
| 770 | .bus = &clockevents_subsys, |
| 771 | }; |
| 772 | |
| 773 | static struct tick_device *tick_get_tick_dev(struct device *dev) |
| 774 | { |
| 775 | return dev == &tick_bc_dev ? tick_get_broadcast_device() : |
| 776 | &per_cpu(tick_cpu_device, dev->id); |
| 777 | } |
| 778 | |
| 779 | static __init int tick_broadcast_init_sysfs(void) |
| 780 | { |
| 781 | int err = device_register(&tick_bc_dev); |
| 782 | |
| 783 | if (!err) |
| 784 | err = device_create_file(&tick_bc_dev, &dev_attr_current_device); |
| 785 | return err; |
| 786 | } |
| 787 | #else |
| 788 | static struct tick_device *tick_get_tick_dev(struct device *dev) |
| 789 | { |
| 790 | return &per_cpu(tick_cpu_device, dev->id); |
| 791 | } |
| 792 | static inline int tick_broadcast_init_sysfs(void) { return 0; } |
Thomas Gleixner | de68d9b | 2007-10-12 23:04:05 +0200 | [diff] [blame] | 793 | #endif |
Thomas Gleixner | 501f867 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 794 | |
| 795 | static int __init tick_init_sysfs(void) |
| 796 | { |
| 797 | int cpu; |
| 798 | |
| 799 | for_each_possible_cpu(cpu) { |
| 800 | struct device *dev = &per_cpu(tick_percpu_dev, cpu); |
| 801 | int err; |
| 802 | |
| 803 | dev->id = cpu; |
| 804 | dev->bus = &clockevents_subsys; |
| 805 | err = device_register(dev); |
| 806 | if (!err) |
| 807 | err = device_create_file(dev, &dev_attr_current_device); |
Thomas Gleixner | 03e13cf | 2013-04-25 20:31:50 +0000 | [diff] [blame] | 808 | if (!err) |
| 809 | err = device_create_file(dev, &dev_attr_unbind_device); |
Thomas Gleixner | 501f867 | 2013-04-25 20:31:49 +0000 | [diff] [blame] | 810 | if (err) |
| 811 | return err; |
| 812 | } |
| 813 | return tick_broadcast_init_sysfs(); |
| 814 | } |
| 815 | |
| 816 | static int __init clockevents_init_sysfs(void) |
| 817 | { |
| 818 | int err = subsys_system_register(&clockevents_subsys, NULL); |
| 819 | |
| 820 | if (!err) |
| 821 | err = tick_init_sysfs(); |
| 822 | return err; |
| 823 | } |
| 824 | device_initcall(clockevents_init_sysfs); |
| 825 | #endif /* SYSFS */ |
| 826 | |
| 827 | #endif /* GENERIC_CLOCK_EVENTS */ |