alarmtimer.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Alarmtimer interface
  3. *
  4. * This interface provides a timer which is similarto hrtimers,
  5. * but triggers a RTC alarm if the box is suspend.
  6. *
  7. * This interface is influenced by the Android RTC Alarm timer
  8. * interface.
  9. *
  10. * Copyright (C) 2010 IBM Corperation
  11. *
  12. * Author: John Stultz <john.stultz@linaro.org>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/time.h>
  19. #include <linux/hrtimer.h>
  20. #include <linux/timerqueue.h>
  21. #include <linux/rtc.h>
  22. #include <linux/alarmtimer.h>
  23. #include <linux/mutex.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/posix-timers.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/freezer.h>
  28. /**
  29. * struct alarm_base - Alarm timer bases
  30. * @lock: Lock for syncrhonized access to the base
  31. * @timerqueue: Timerqueue head managing the list of events
  32. * @timer: hrtimer used to schedule events while running
  33. * @gettime: Function to read the time correlating to the base
  34. * @base_clockid: clockid for the base
  35. */
  36. static struct alarm_base {
  37. spinlock_t lock;
  38. struct timerqueue_head timerqueue;
  39. struct hrtimer timer;
  40. ktime_t (*gettime)(void);
  41. clockid_t base_clockid;
  42. } alarm_bases[ALARM_NUMTYPE];
  43. /* rtc timer and device for setting alarm wakeups at suspend */
  44. static struct rtc_timer rtctimer;
  45. static struct rtc_device *rtcdev;
  46. /* freezer delta & lock used to handle clock_nanosleep triggered wakeups */
  47. static ktime_t freezer_delta;
  48. static DEFINE_SPINLOCK(freezer_delta_lock);
  49. /**
  50. * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue
  51. * @base: pointer to the base where the timer is being run
  52. * @alarm: pointer to alarm being enqueued.
  53. *
  54. * Adds alarm to a alarm_base timerqueue and if necessary sets
  55. * an hrtimer to run.
  56. *
  57. * Must hold base->lock when calling.
  58. */
  59. static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm)
  60. {
  61. timerqueue_add(&base->timerqueue, &alarm->node);
  62. if (&alarm->node == timerqueue_getnext(&base->timerqueue)) {
  63. hrtimer_try_to_cancel(&base->timer);
  64. hrtimer_start(&base->timer, alarm->node.expires,
  65. HRTIMER_MODE_ABS);
  66. }
  67. }
  68. /**
  69. * alarmtimer_remove - Removes an alarm timer from an alarm_base timerqueue
  70. * @base: pointer to the base where the timer is running
  71. * @alarm: pointer to alarm being removed
  72. *
  73. * Removes alarm to a alarm_base timerqueue and if necessary sets
  74. * a new timer to run.
  75. *
  76. * Must hold base->lock when calling.
  77. */
  78. static void alarmtimer_remove(struct alarm_base *base, struct alarm *alarm)
  79. {
  80. struct timerqueue_node *next = timerqueue_getnext(&base->timerqueue);
  81. timerqueue_del(&base->timerqueue, &alarm->node);
  82. if (next == &alarm->node) {
  83. hrtimer_try_to_cancel(&base->timer);
  84. next = timerqueue_getnext(&base->timerqueue);
  85. if (!next)
  86. return;
  87. hrtimer_start(&base->timer, next->expires, HRTIMER_MODE_ABS);
  88. }
  89. }
  90. /**
  91. * alarmtimer_fired - Handles alarm hrtimer being fired.
  92. * @timer: pointer to hrtimer being run
  93. *
  94. * When a alarm timer fires, this runs through the timerqueue to
  95. * see which alarms expired, and runs those. If there are more alarm
  96. * timers queued for the future, we set the hrtimer to fire when
  97. * when the next future alarm timer expires.
  98. */
  99. static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer)
  100. {
  101. struct alarm_base *base = container_of(timer, struct alarm_base, timer);
  102. struct timerqueue_node *next;
  103. unsigned long flags;
  104. ktime_t now;
  105. int ret = HRTIMER_NORESTART;
  106. spin_lock_irqsave(&base->lock, flags);
  107. now = base->gettime();
  108. while ((next = timerqueue_getnext(&base->timerqueue))) {
  109. struct alarm *alarm;
  110. ktime_t expired = next->expires;
  111. if (expired.tv64 >= now.tv64)
  112. break;
  113. alarm = container_of(next, struct alarm, node);
  114. timerqueue_del(&base->timerqueue, &alarm->node);
  115. alarm->enabled = 0;
  116. /* Re-add periodic timers */
  117. if (alarm->period.tv64) {
  118. alarm->node.expires = ktime_add(expired, alarm->period);
  119. timerqueue_add(&base->timerqueue, &alarm->node);
  120. alarm->enabled = 1;
  121. }
  122. spin_unlock_irqrestore(&base->lock, flags);
  123. if (alarm->function)
  124. alarm->function(alarm);
  125. spin_lock_irqsave(&base->lock, flags);
  126. }
  127. if (next) {
  128. hrtimer_set_expires(&base->timer, next->expires);
  129. ret = HRTIMER_RESTART;
  130. }
  131. spin_unlock_irqrestore(&base->lock, flags);
  132. return ret;
  133. }
  134. /**
  135. * alarmtimer_suspend - Suspend time callback
  136. * @dev: unused
  137. * @state: unused
  138. *
  139. * When we are going into suspend, we look through the bases
  140. * to see which is the soonest timer to expire. We then
  141. * set an rtc timer to fire that far into the future, which
  142. * will wake us from suspend.
  143. */
  144. static int alarmtimer_suspend(struct device *dev)
  145. {
  146. struct rtc_time tm;
  147. ktime_t min, now;
  148. unsigned long flags;
  149. int i;
  150. spin_lock_irqsave(&freezer_delta_lock, flags);
  151. min = freezer_delta;
  152. freezer_delta = ktime_set(0, 0);
  153. spin_unlock_irqrestore(&freezer_delta_lock, flags);
  154. /* If we have no rtcdev, just return */
  155. if (!rtcdev)
  156. return 0;
  157. /* Find the soonest timer to expire*/
  158. for (i = 0; i < ALARM_NUMTYPE; i++) {
  159. struct alarm_base *base = &alarm_bases[i];
  160. struct timerqueue_node *next;
  161. ktime_t delta;
  162. spin_lock_irqsave(&base->lock, flags);
  163. next = timerqueue_getnext(&base->timerqueue);
  164. spin_unlock_irqrestore(&base->lock, flags);
  165. if (!next)
  166. continue;
  167. delta = ktime_sub(next->expires, base->gettime());
  168. if (!min.tv64 || (delta.tv64 < min.tv64))
  169. min = delta;
  170. }
  171. if (min.tv64 == 0)
  172. return 0;
  173. /* XXX - Should we enforce a minimum sleep time? */
  174. WARN_ON(min.tv64 < NSEC_PER_SEC);
  175. /* Setup an rtc timer to fire that far in the future */
  176. rtc_timer_cancel(rtcdev, &rtctimer);
  177. rtc_read_time(rtcdev, &tm);
  178. now = rtc_tm_to_ktime(tm);
  179. now = ktime_add(now, min);
  180. rtc_timer_start(rtcdev, &rtctimer, now, ktime_set(0, 0));
  181. return 0;
  182. }
  183. static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
  184. {
  185. ktime_t delta;
  186. unsigned long flags;
  187. struct alarm_base *base = &alarm_bases[type];
  188. delta = ktime_sub(absexp, base->gettime());
  189. spin_lock_irqsave(&freezer_delta_lock, flags);
  190. if (!freezer_delta.tv64 || (delta.tv64 < freezer_delta.tv64))
  191. freezer_delta = delta;
  192. spin_unlock_irqrestore(&freezer_delta_lock, flags);
  193. }
  194. /**
  195. * alarm_init - Initialize an alarm structure
  196. * @alarm: ptr to alarm to be initialized
  197. * @type: the type of the alarm
  198. * @function: callback that is run when the alarm fires
  199. */
  200. void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
  201. void (*function)(struct alarm *))
  202. {
  203. timerqueue_init(&alarm->node);
  204. alarm->period = ktime_set(0, 0);
  205. alarm->function = function;
  206. alarm->type = type;
  207. alarm->enabled = 0;
  208. }
  209. /**
  210. * alarm_start - Sets an alarm to fire
  211. * @alarm: ptr to alarm to set
  212. * @start: time to run the alarm
  213. * @period: period at which the alarm will recur
  214. */
  215. void alarm_start(struct alarm *alarm, ktime_t start, ktime_t period)
  216. {
  217. struct alarm_base *base = &alarm_bases[alarm->type];
  218. unsigned long flags;
  219. spin_lock_irqsave(&base->lock, flags);
  220. if (alarm->enabled)
  221. alarmtimer_remove(base, alarm);
  222. alarm->node.expires = start;
  223. alarm->period = period;
  224. alarmtimer_enqueue(base, alarm);
  225. alarm->enabled = 1;
  226. spin_unlock_irqrestore(&base->lock, flags);
  227. }
  228. /**
  229. * alarm_cancel - Tries to cancel an alarm timer
  230. * @alarm: ptr to alarm to be canceled
  231. */
  232. void alarm_cancel(struct alarm *alarm)
  233. {
  234. struct alarm_base *base = &alarm_bases[alarm->type];
  235. unsigned long flags;
  236. spin_lock_irqsave(&base->lock, flags);
  237. if (alarm->enabled)
  238. alarmtimer_remove(base, alarm);
  239. alarm->enabled = 0;
  240. spin_unlock_irqrestore(&base->lock, flags);
  241. }
  242. /**
  243. * clock2alarm - helper that converts from clockid to alarmtypes
  244. * @clockid: clockid.
  245. */
  246. static enum alarmtimer_type clock2alarm(clockid_t clockid)
  247. {
  248. if (clockid == CLOCK_REALTIME_ALARM)
  249. return ALARM_REALTIME;
  250. if (clockid == CLOCK_BOOTTIME_ALARM)
  251. return ALARM_BOOTTIME;
  252. return -1;
  253. }
  254. /**
  255. * alarm_handle_timer - Callback for posix timers
  256. * @alarm: alarm that fired
  257. *
  258. * Posix timer callback for expired alarm timers.
  259. */
  260. static void alarm_handle_timer(struct alarm *alarm)
  261. {
  262. struct k_itimer *ptr = container_of(alarm, struct k_itimer,
  263. it.alarmtimer);
  264. if (posix_timer_event(ptr, 0) != 0)
  265. ptr->it_overrun++;
  266. }
  267. /**
  268. * alarm_clock_getres - posix getres interface
  269. * @which_clock: clockid
  270. * @tp: timespec to fill
  271. *
  272. * Returns the granularity of underlying alarm base clock
  273. */
  274. static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
  275. {
  276. clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid;
  277. return hrtimer_get_res(baseid, tp);
  278. }
  279. /**
  280. * alarm_clock_get - posix clock_get interface
  281. * @which_clock: clockid
  282. * @tp: timespec to fill.
  283. *
  284. * Provides the underlying alarm base time.
  285. */
  286. static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
  287. {
  288. struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
  289. *tp = ktime_to_timespec(base->gettime());
  290. return 0;
  291. }
  292. /**
  293. * alarm_timer_create - posix timer_create interface
  294. * @new_timer: k_itimer pointer to manage
  295. *
  296. * Initializes the k_itimer structure.
  297. */
  298. static int alarm_timer_create(struct k_itimer *new_timer)
  299. {
  300. enum alarmtimer_type type;
  301. struct alarm_base *base;
  302. if (!capable(CAP_WAKE_ALARM))
  303. return -EPERM;
  304. type = clock2alarm(new_timer->it_clock);
  305. base = &alarm_bases[type];
  306. alarm_init(&new_timer->it.alarmtimer, type, alarm_handle_timer);
  307. return 0;
  308. }
  309. /**
  310. * alarm_timer_get - posix timer_get interface
  311. * @new_timer: k_itimer pointer
  312. * @cur_setting: itimerspec data to fill
  313. *
  314. * Copies the itimerspec data out from the k_itimer
  315. */
  316. static void alarm_timer_get(struct k_itimer *timr,
  317. struct itimerspec *cur_setting)
  318. {
  319. cur_setting->it_interval =
  320. ktime_to_timespec(timr->it.alarmtimer.period);
  321. cur_setting->it_value =
  322. ktime_to_timespec(timr->it.alarmtimer.node.expires);
  323. return;
  324. }
  325. /**
  326. * alarm_timer_del - posix timer_del interface
  327. * @timr: k_itimer pointer to be deleted
  328. *
  329. * Cancels any programmed alarms for the given timer.
  330. */
  331. static int alarm_timer_del(struct k_itimer *timr)
  332. {
  333. alarm_cancel(&timr->it.alarmtimer);
  334. return 0;
  335. }
  336. /**
  337. * alarm_timer_set - posix timer_set interface
  338. * @timr: k_itimer pointer to be deleted
  339. * @flags: timer flags
  340. * @new_setting: itimerspec to be used
  341. * @old_setting: itimerspec being replaced
  342. *
  343. * Sets the timer to new_setting, and starts the timer.
  344. */
  345. static int alarm_timer_set(struct k_itimer *timr, int flags,
  346. struct itimerspec *new_setting,
  347. struct itimerspec *old_setting)
  348. {
  349. /* Save old values */
  350. old_setting->it_interval =
  351. ktime_to_timespec(timr->it.alarmtimer.period);
  352. old_setting->it_value =
  353. ktime_to_timespec(timr->it.alarmtimer.node.expires);
  354. /* If the timer was already set, cancel it */
  355. alarm_cancel(&timr->it.alarmtimer);
  356. /* start the timer */
  357. alarm_start(&timr->it.alarmtimer,
  358. timespec_to_ktime(new_setting->it_value),
  359. timespec_to_ktime(new_setting->it_interval));
  360. return 0;
  361. }
  362. /**
  363. * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep
  364. * @alarm: ptr to alarm that fired
  365. *
  366. * Wakes up the task that set the alarmtimer
  367. */
  368. static void alarmtimer_nsleep_wakeup(struct alarm *alarm)
  369. {
  370. struct task_struct *task = (struct task_struct *)alarm->data;
  371. alarm->data = NULL;
  372. if (task)
  373. wake_up_process(task);
  374. }
  375. /**
  376. * alarmtimer_do_nsleep - Internal alarmtimer nsleep implementation
  377. * @alarm: ptr to alarmtimer
  378. * @absexp: absolute expiration time
  379. *
  380. * Sets the alarm timer and sleeps until it is fired or interrupted.
  381. */
  382. static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp)
  383. {
  384. alarm->data = (void *)current;
  385. do {
  386. set_current_state(TASK_INTERRUPTIBLE);
  387. alarm_start(alarm, absexp, ktime_set(0, 0));
  388. if (likely(alarm->data))
  389. schedule();
  390. alarm_cancel(alarm);
  391. } while (alarm->data && !signal_pending(current));
  392. __set_current_state(TASK_RUNNING);
  393. return (alarm->data == NULL);
  394. }
  395. /**
  396. * update_rmtp - Update remaining timespec value
  397. * @exp: expiration time
  398. * @type: timer type
  399. * @rmtp: user pointer to remaining timepsec value
  400. *
  401. * Helper function that fills in rmtp value with time between
  402. * now and the exp value
  403. */
  404. static int update_rmtp(ktime_t exp, enum alarmtimer_type type,
  405. struct timespec __user *rmtp)
  406. {
  407. struct timespec rmt;
  408. ktime_t rem;
  409. rem = ktime_sub(exp, alarm_bases[type].gettime());
  410. if (rem.tv64 <= 0)
  411. return 0;
  412. rmt = ktime_to_timespec(rem);
  413. if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
  414. return -EFAULT;
  415. return 1;
  416. }
  417. /**
  418. * alarm_timer_nsleep_restart - restartblock alarmtimer nsleep
  419. * @restart: ptr to restart block
  420. *
  421. * Handles restarted clock_nanosleep calls
  422. */
  423. static long __sched alarm_timer_nsleep_restart(struct restart_block *restart)
  424. {
  425. enum alarmtimer_type type = restart->nanosleep.index;
  426. ktime_t exp;
  427. struct timespec __user *rmtp;
  428. struct alarm alarm;
  429. int ret = 0;
  430. exp.tv64 = restart->nanosleep.expires;
  431. alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
  432. if (alarmtimer_do_nsleep(&alarm, exp))
  433. goto out;
  434. if (freezing(current))
  435. alarmtimer_freezerset(exp, type);
  436. rmtp = restart->nanosleep.rmtp;
  437. if (rmtp) {
  438. ret = update_rmtp(exp, type, rmtp);
  439. if (ret <= 0)
  440. goto out;
  441. }
  442. /* The other values in restart are already filled in */
  443. ret = -ERESTART_RESTARTBLOCK;
  444. out:
  445. return ret;
  446. }
  447. /**
  448. * alarm_timer_nsleep - alarmtimer nanosleep
  449. * @which_clock: clockid
  450. * @flags: determins abstime or relative
  451. * @tsreq: requested sleep time (abs or rel)
  452. * @rmtp: remaining sleep time saved
  453. *
  454. * Handles clock_nanosleep calls against _ALARM clockids
  455. */
  456. static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
  457. struct timespec *tsreq, struct timespec __user *rmtp)
  458. {
  459. enum alarmtimer_type type = clock2alarm(which_clock);
  460. struct alarm alarm;
  461. ktime_t exp;
  462. int ret = 0;
  463. struct restart_block *restart;
  464. if (!capable(CAP_WAKE_ALARM))
  465. return -EPERM;
  466. alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
  467. exp = timespec_to_ktime(*tsreq);
  468. /* Convert (if necessary) to absolute time */
  469. if (flags != TIMER_ABSTIME) {
  470. ktime_t now = alarm_bases[type].gettime();
  471. exp = ktime_add(now, exp);
  472. }
  473. if (alarmtimer_do_nsleep(&alarm, exp))
  474. goto out;
  475. if (freezing(current))
  476. alarmtimer_freezerset(exp, type);
  477. /* abs timers don't set remaining time or restart */
  478. if (flags == TIMER_ABSTIME) {
  479. ret = -ERESTARTNOHAND;
  480. goto out;
  481. }
  482. if (rmtp) {
  483. ret = update_rmtp(exp, type, rmtp);
  484. if (ret <= 0)
  485. goto out;
  486. }
  487. restart = &current_thread_info()->restart_block;
  488. restart->fn = alarm_timer_nsleep_restart;
  489. restart->nanosleep.index = type;
  490. restart->nanosleep.expires = exp.tv64;
  491. restart->nanosleep.rmtp = rmtp;
  492. ret = -ERESTART_RESTARTBLOCK;
  493. out:
  494. return ret;
  495. }
  496. /* Suspend hook structures */
  497. static const struct dev_pm_ops alarmtimer_pm_ops = {
  498. .suspend = alarmtimer_suspend,
  499. };
  500. static struct platform_driver alarmtimer_driver = {
  501. .driver = {
  502. .name = "alarmtimer",
  503. .pm = &alarmtimer_pm_ops,
  504. }
  505. };
  506. /**
  507. * alarmtimer_init - Initialize alarm timer code
  508. *
  509. * This function initializes the alarm bases and registers
  510. * the posix clock ids.
  511. */
  512. static int __init alarmtimer_init(void)
  513. {
  514. int error = 0;
  515. int i;
  516. struct k_clock alarm_clock = {
  517. .clock_getres = alarm_clock_getres,
  518. .clock_get = alarm_clock_get,
  519. .timer_create = alarm_timer_create,
  520. .timer_set = alarm_timer_set,
  521. .timer_del = alarm_timer_del,
  522. .timer_get = alarm_timer_get,
  523. .nsleep = alarm_timer_nsleep,
  524. };
  525. posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock);
  526. posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock);
  527. /* Initialize alarm bases */
  528. alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
  529. alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
  530. alarm_bases[ALARM_BOOTTIME].base_clockid = CLOCK_BOOTTIME;
  531. alarm_bases[ALARM_BOOTTIME].gettime = &ktime_get_boottime;
  532. for (i = 0; i < ALARM_NUMTYPE; i++) {
  533. timerqueue_init_head(&alarm_bases[i].timerqueue);
  534. spin_lock_init(&alarm_bases[i].lock);
  535. hrtimer_init(&alarm_bases[i].timer,
  536. alarm_bases[i].base_clockid,
  537. HRTIMER_MODE_ABS);
  538. alarm_bases[i].timer.function = alarmtimer_fired;
  539. }
  540. error = platform_driver_register(&alarmtimer_driver);
  541. platform_device_register_simple("alarmtimer", -1, NULL, 0);
  542. return error;
  543. }
  544. device_initcall(alarmtimer_init);
  545. /**
  546. * has_wakealarm - check rtc device has wakealarm ability
  547. * @dev: current device
  548. * @name_ptr: name to be returned
  549. *
  550. * This helper function checks to see if the rtc device can wake
  551. * from suspend.
  552. */
  553. static int __init has_wakealarm(struct device *dev, void *name_ptr)
  554. {
  555. struct rtc_device *candidate = to_rtc_device(dev);
  556. if (!candidate->ops->set_alarm)
  557. return 0;
  558. if (!device_may_wakeup(candidate->dev.parent))
  559. return 0;
  560. *(const char **)name_ptr = dev_name(dev);
  561. return 1;
  562. }
  563. /**
  564. * alarmtimer_init_late - Late initializing of alarmtimer code
  565. *
  566. * This function locates a rtc device to use for wakealarms.
  567. * Run as late_initcall to make sure rtc devices have been
  568. * registered.
  569. */
  570. static int __init alarmtimer_init_late(void)
  571. {
  572. char *str;
  573. /* Find an rtc device and init the rtc_timer */
  574. class_find_device(rtc_class, NULL, &str, has_wakealarm);
  575. if (str)
  576. rtcdev = rtc_class_open(str);
  577. if (!rtcdev) {
  578. printk(KERN_WARNING "No RTC device found, ALARM timers will"
  579. " not wake from suspend");
  580. }
  581. rtc_timer_init(&rtctimer, NULL, NULL);
  582. return 0;
  583. }
  584. late_initcall(alarmtimer_init_late);