This source file includes following definitions.
- alarmtimer_get_rtcdev
- alarmtimer_rtc_add_device
- alarmtimer_rtc_timer_init
- alarmtimer_rtc_interface_setup
- alarmtimer_rtc_interface_remove
- alarmtimer_get_rtcdev
- alarmtimer_rtc_interface_setup
- alarmtimer_rtc_interface_remove
- alarmtimer_rtc_timer_init
- alarmtimer_enqueue
- alarmtimer_dequeue
- alarmtimer_fired
- alarm_expires_remaining
- alarmtimer_suspend
- alarmtimer_resume
- alarmtimer_suspend
- alarmtimer_resume
- __alarm_init
- alarm_init
- alarm_start
- alarm_start_relative
- alarm_restart
- alarm_try_to_cancel
- alarm_cancel
- alarm_forward
- alarm_forward_now
- alarmtimer_freezerset
- clock2alarm
- alarm_handle_timer
- alarm_timer_rearm
- alarm_timer_forward
- alarm_timer_remaining
- alarm_timer_try_to_cancel
- alarm_timer_wait_running
- alarm_timer_arm
- alarm_clock_getres
- alarm_clock_get
- alarm_timer_create
- alarmtimer_nsleep_wakeup
- alarmtimer_do_nsleep
- alarm_init_on_stack
- alarm_timer_nsleep_restart
- alarm_timer_nsleep
- alarmtimer_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include <linux/time.h>
16 #include <linux/hrtimer.h>
17 #include <linux/timerqueue.h>
18 #include <linux/rtc.h>
19 #include <linux/sched/signal.h>
20 #include <linux/sched/debug.h>
21 #include <linux/alarmtimer.h>
22 #include <linux/mutex.h>
23 #include <linux/platform_device.h>
24 #include <linux/posix-timers.h>
25 #include <linux/workqueue.h>
26 #include <linux/freezer.h>
27 #include <linux/compat.h>
28 #include <linux/module.h>
29
30 #include "posix-timers.h"
31
32 #define CREATE_TRACE_POINTS
33 #include <trace/events/alarmtimer.h>
34
35
36
37
38
39
40
41
42 static struct alarm_base {
43 spinlock_t lock;
44 struct timerqueue_head timerqueue;
45 ktime_t (*gettime)(void);
46 clockid_t base_clockid;
47 } alarm_bases[ALARM_NUMTYPE];
48
49 #if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS)
50
51 static enum alarmtimer_type freezer_alarmtype;
52 static ktime_t freezer_expires;
53 static ktime_t freezer_delta;
54 static DEFINE_SPINLOCK(freezer_delta_lock);
55 #endif
56
57 #ifdef CONFIG_RTC_CLASS
58 static struct wakeup_source *ws;
59
60
61 static struct rtc_timer rtctimer;
62 static struct rtc_device *rtcdev;
63 static DEFINE_SPINLOCK(rtcdev_lock);
64
65
66
67
68
69
70
71
72 struct rtc_device *alarmtimer_get_rtcdev(void)
73 {
74 unsigned long flags;
75 struct rtc_device *ret;
76
77 spin_lock_irqsave(&rtcdev_lock, flags);
78 ret = rtcdev;
79 spin_unlock_irqrestore(&rtcdev_lock, flags);
80
81 return ret;
82 }
83 EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
84
85 static int alarmtimer_rtc_add_device(struct device *dev,
86 struct class_interface *class_intf)
87 {
88 unsigned long flags;
89 struct rtc_device *rtc = to_rtc_device(dev);
90 struct wakeup_source *__ws;
91 struct platform_device *pdev;
92 int ret = 0;
93
94 if (rtcdev)
95 return -EBUSY;
96
97 if (!rtc->ops->set_alarm)
98 return -1;
99 if (!device_may_wakeup(rtc->dev.parent))
100 return -1;
101
102 __ws = wakeup_source_register(dev, "alarmtimer");
103 pdev = platform_device_register_data(dev, "alarmtimer",
104 PLATFORM_DEVID_AUTO, NULL, 0);
105
106 spin_lock_irqsave(&rtcdev_lock, flags);
107 if (__ws && !IS_ERR(pdev) && !rtcdev) {
108 if (!try_module_get(rtc->owner)) {
109 ret = -1;
110 goto unlock;
111 }
112
113 rtcdev = rtc;
114
115 get_device(dev);
116 ws = __ws;
117 __ws = NULL;
118 pdev = NULL;
119 } else {
120 ret = -1;
121 }
122 unlock:
123 spin_unlock_irqrestore(&rtcdev_lock, flags);
124
125 platform_device_unregister(pdev);
126 wakeup_source_unregister(__ws);
127
128 return ret;
129 }
130
131 static inline void alarmtimer_rtc_timer_init(void)
132 {
133 rtc_timer_init(&rtctimer, NULL, NULL);
134 }
135
136 static struct class_interface alarmtimer_rtc_interface = {
137 .add_dev = &alarmtimer_rtc_add_device,
138 };
139
140 static int alarmtimer_rtc_interface_setup(void)
141 {
142 alarmtimer_rtc_interface.class = rtc_class;
143 return class_interface_register(&alarmtimer_rtc_interface);
144 }
145 static void alarmtimer_rtc_interface_remove(void)
146 {
147 class_interface_unregister(&alarmtimer_rtc_interface);
148 }
149 #else
150 struct rtc_device *alarmtimer_get_rtcdev(void)
151 {
152 return NULL;
153 }
154 #define rtcdev (NULL)
155 static inline int alarmtimer_rtc_interface_setup(void) { return 0; }
156 static inline void alarmtimer_rtc_interface_remove(void) { }
157 static inline void alarmtimer_rtc_timer_init(void) { }
158 #endif
159
160
161
162
163
164
165
166
167
168
169 static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm)
170 {
171 if (alarm->state & ALARMTIMER_STATE_ENQUEUED)
172 timerqueue_del(&base->timerqueue, &alarm->node);
173
174 timerqueue_add(&base->timerqueue, &alarm->node);
175 alarm->state |= ALARMTIMER_STATE_ENQUEUED;
176 }
177
178
179
180
181
182
183
184
185
186
187 static void alarmtimer_dequeue(struct alarm_base *base, struct alarm *alarm)
188 {
189 if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED))
190 return;
191
192 timerqueue_del(&base->timerqueue, &alarm->node);
193 alarm->state &= ~ALARMTIMER_STATE_ENQUEUED;
194 }
195
196
197
198
199
200
201
202
203
204
205
206 static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer)
207 {
208 struct alarm *alarm = container_of(timer, struct alarm, timer);
209 struct alarm_base *base = &alarm_bases[alarm->type];
210 unsigned long flags;
211 int ret = HRTIMER_NORESTART;
212 int restart = ALARMTIMER_NORESTART;
213
214 spin_lock_irqsave(&base->lock, flags);
215 alarmtimer_dequeue(base, alarm);
216 spin_unlock_irqrestore(&base->lock, flags);
217
218 if (alarm->function)
219 restart = alarm->function(alarm, base->gettime());
220
221 spin_lock_irqsave(&base->lock, flags);
222 if (restart != ALARMTIMER_NORESTART) {
223 hrtimer_set_expires(&alarm->timer, alarm->node.expires);
224 alarmtimer_enqueue(base, alarm);
225 ret = HRTIMER_RESTART;
226 }
227 spin_unlock_irqrestore(&base->lock, flags);
228
229 trace_alarmtimer_fired(alarm, base->gettime());
230 return ret;
231
232 }
233
234 ktime_t alarm_expires_remaining(const struct alarm *alarm)
235 {
236 struct alarm_base *base = &alarm_bases[alarm->type];
237 return ktime_sub(alarm->node.expires, base->gettime());
238 }
239 EXPORT_SYMBOL_GPL(alarm_expires_remaining);
240
241 #ifdef CONFIG_RTC_CLASS
242
243
244
245
246
247
248
249
250
251 static int alarmtimer_suspend(struct device *dev)
252 {
253 ktime_t min, now, expires;
254 int i, ret, type;
255 struct rtc_device *rtc;
256 unsigned long flags;
257 struct rtc_time tm;
258
259 spin_lock_irqsave(&freezer_delta_lock, flags);
260 min = freezer_delta;
261 expires = freezer_expires;
262 type = freezer_alarmtype;
263 freezer_delta = 0;
264 spin_unlock_irqrestore(&freezer_delta_lock, flags);
265
266 rtc = alarmtimer_get_rtcdev();
267
268 if (!rtc)
269 return 0;
270
271
272 for (i = 0; i < ALARM_NUMTYPE; i++) {
273 struct alarm_base *base = &alarm_bases[i];
274 struct timerqueue_node *next;
275 ktime_t delta;
276
277 spin_lock_irqsave(&base->lock, flags);
278 next = timerqueue_getnext(&base->timerqueue);
279 spin_unlock_irqrestore(&base->lock, flags);
280 if (!next)
281 continue;
282 delta = ktime_sub(next->expires, base->gettime());
283 if (!min || (delta < min)) {
284 expires = next->expires;
285 min = delta;
286 type = i;
287 }
288 }
289 if (min == 0)
290 return 0;
291
292 if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
293 __pm_wakeup_event(ws, 2 * MSEC_PER_SEC);
294 return -EBUSY;
295 }
296
297 trace_alarmtimer_suspend(expires, type);
298
299
300 rtc_timer_cancel(rtc, &rtctimer);
301 rtc_read_time(rtc, &tm);
302 now = rtc_tm_to_ktime(tm);
303 now = ktime_add(now, min);
304
305
306 ret = rtc_timer_start(rtc, &rtctimer, now, 0);
307 if (ret < 0)
308 __pm_wakeup_event(ws, MSEC_PER_SEC);
309 return ret;
310 }
311
312 static int alarmtimer_resume(struct device *dev)
313 {
314 struct rtc_device *rtc;
315
316 rtc = alarmtimer_get_rtcdev();
317 if (rtc)
318 rtc_timer_cancel(rtc, &rtctimer);
319 return 0;
320 }
321
322 #else
323 static int alarmtimer_suspend(struct device *dev)
324 {
325 return 0;
326 }
327
328 static int alarmtimer_resume(struct device *dev)
329 {
330 return 0;
331 }
332 #endif
333
334 static void
335 __alarm_init(struct alarm *alarm, enum alarmtimer_type type,
336 enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
337 {
338 timerqueue_init(&alarm->node);
339 alarm->timer.function = alarmtimer_fired;
340 alarm->function = function;
341 alarm->type = type;
342 alarm->state = ALARMTIMER_STATE_INACTIVE;
343 }
344
345
346
347
348
349
350
351 void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
352 enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
353 {
354 hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid,
355 HRTIMER_MODE_ABS);
356 __alarm_init(alarm, type, function);
357 }
358 EXPORT_SYMBOL_GPL(alarm_init);
359
360
361
362
363
364
365 void alarm_start(struct alarm *alarm, ktime_t start)
366 {
367 struct alarm_base *base = &alarm_bases[alarm->type];
368 unsigned long flags;
369
370 spin_lock_irqsave(&base->lock, flags);
371 alarm->node.expires = start;
372 alarmtimer_enqueue(base, alarm);
373 hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS);
374 spin_unlock_irqrestore(&base->lock, flags);
375
376 trace_alarmtimer_start(alarm, base->gettime());
377 }
378 EXPORT_SYMBOL_GPL(alarm_start);
379
380
381
382
383
384
385 void alarm_start_relative(struct alarm *alarm, ktime_t start)
386 {
387 struct alarm_base *base = &alarm_bases[alarm->type];
388
389 start = ktime_add_safe(start, base->gettime());
390 alarm_start(alarm, start);
391 }
392 EXPORT_SYMBOL_GPL(alarm_start_relative);
393
394 void alarm_restart(struct alarm *alarm)
395 {
396 struct alarm_base *base = &alarm_bases[alarm->type];
397 unsigned long flags;
398
399 spin_lock_irqsave(&base->lock, flags);
400 hrtimer_set_expires(&alarm->timer, alarm->node.expires);
401 hrtimer_restart(&alarm->timer);
402 alarmtimer_enqueue(base, alarm);
403 spin_unlock_irqrestore(&base->lock, flags);
404 }
405 EXPORT_SYMBOL_GPL(alarm_restart);
406
407
408
409
410
411
412
413
414 int alarm_try_to_cancel(struct alarm *alarm)
415 {
416 struct alarm_base *base = &alarm_bases[alarm->type];
417 unsigned long flags;
418 int ret;
419
420 spin_lock_irqsave(&base->lock, flags);
421 ret = hrtimer_try_to_cancel(&alarm->timer);
422 if (ret >= 0)
423 alarmtimer_dequeue(base, alarm);
424 spin_unlock_irqrestore(&base->lock, flags);
425
426 trace_alarmtimer_cancel(alarm, base->gettime());
427 return ret;
428 }
429 EXPORT_SYMBOL_GPL(alarm_try_to_cancel);
430
431
432
433
434
435
436
437
438 int alarm_cancel(struct alarm *alarm)
439 {
440 for (;;) {
441 int ret = alarm_try_to_cancel(alarm);
442 if (ret >= 0)
443 return ret;
444 hrtimer_cancel_wait_running(&alarm->timer);
445 }
446 }
447 EXPORT_SYMBOL_GPL(alarm_cancel);
448
449
450 u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
451 {
452 u64 overrun = 1;
453 ktime_t delta;
454
455 delta = ktime_sub(now, alarm->node.expires);
456
457 if (delta < 0)
458 return 0;
459
460 if (unlikely(delta >= interval)) {
461 s64 incr = ktime_to_ns(interval);
462
463 overrun = ktime_divns(delta, incr);
464
465 alarm->node.expires = ktime_add_ns(alarm->node.expires,
466 incr*overrun);
467
468 if (alarm->node.expires > now)
469 return overrun;
470
471
472
473
474 overrun++;
475 }
476
477 alarm->node.expires = ktime_add_safe(alarm->node.expires, interval);
478 return overrun;
479 }
480 EXPORT_SYMBOL_GPL(alarm_forward);
481
482 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
483 {
484 struct alarm_base *base = &alarm_bases[alarm->type];
485
486 return alarm_forward(alarm, base->gettime(), interval);
487 }
488 EXPORT_SYMBOL_GPL(alarm_forward_now);
489
490 #ifdef CONFIG_POSIX_TIMERS
491
492 static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
493 {
494 struct alarm_base *base;
495 unsigned long flags;
496 ktime_t delta;
497
498 switch(type) {
499 case ALARM_REALTIME:
500 base = &alarm_bases[ALARM_REALTIME];
501 type = ALARM_REALTIME_FREEZER;
502 break;
503 case ALARM_BOOTTIME:
504 base = &alarm_bases[ALARM_BOOTTIME];
505 type = ALARM_BOOTTIME_FREEZER;
506 break;
507 default:
508 WARN_ONCE(1, "Invalid alarm type: %d\n", type);
509 return;
510 }
511
512 delta = ktime_sub(absexp, base->gettime());
513
514 spin_lock_irqsave(&freezer_delta_lock, flags);
515 if (!freezer_delta || (delta < freezer_delta)) {
516 freezer_delta = delta;
517 freezer_expires = absexp;
518 freezer_alarmtype = type;
519 }
520 spin_unlock_irqrestore(&freezer_delta_lock, flags);
521 }
522
523
524
525
526
527 static enum alarmtimer_type clock2alarm(clockid_t clockid)
528 {
529 if (clockid == CLOCK_REALTIME_ALARM)
530 return ALARM_REALTIME;
531 if (clockid == CLOCK_BOOTTIME_ALARM)
532 return ALARM_BOOTTIME;
533 return -1;
534 }
535
536
537
538
539
540
541
542 static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
543 ktime_t now)
544 {
545 struct k_itimer *ptr = container_of(alarm, struct k_itimer,
546 it.alarm.alarmtimer);
547 enum alarmtimer_restart result = ALARMTIMER_NORESTART;
548 unsigned long flags;
549 int si_private = 0;
550
551 spin_lock_irqsave(&ptr->it_lock, flags);
552
553 ptr->it_active = 0;
554 if (ptr->it_interval)
555 si_private = ++ptr->it_requeue_pending;
556
557 if (posix_timer_event(ptr, si_private) && ptr->it_interval) {
558
559
560
561
562 ptr->it_overrun += alarm_forward_now(alarm, ptr->it_interval);
563 ++ptr->it_requeue_pending;
564 ptr->it_active = 1;
565 result = ALARMTIMER_RESTART;
566 }
567 spin_unlock_irqrestore(&ptr->it_lock, flags);
568
569 return result;
570 }
571
572
573
574
575
576 static void alarm_timer_rearm(struct k_itimer *timr)
577 {
578 struct alarm *alarm = &timr->it.alarm.alarmtimer;
579
580 timr->it_overrun += alarm_forward_now(alarm, timr->it_interval);
581 alarm_start(alarm, alarm->node.expires);
582 }
583
584
585
586
587
588
589 static s64 alarm_timer_forward(struct k_itimer *timr, ktime_t now)
590 {
591 struct alarm *alarm = &timr->it.alarm.alarmtimer;
592
593 return alarm_forward(alarm, timr->it_interval, now);
594 }
595
596
597
598
599
600
601 static ktime_t alarm_timer_remaining(struct k_itimer *timr, ktime_t now)
602 {
603 struct alarm *alarm = &timr->it.alarm.alarmtimer;
604
605 return ktime_sub(alarm->node.expires, now);
606 }
607
608
609
610
611
612 static int alarm_timer_try_to_cancel(struct k_itimer *timr)
613 {
614 return alarm_try_to_cancel(&timr->it.alarm.alarmtimer);
615 }
616
617
618
619
620
621
622
623
624
625 static void alarm_timer_wait_running(struct k_itimer *timr)
626 {
627 hrtimer_cancel_wait_running(&timr->it.alarm.alarmtimer.timer);
628 }
629
630
631
632
633
634
635
636
637 static void alarm_timer_arm(struct k_itimer *timr, ktime_t expires,
638 bool absolute, bool sigev_none)
639 {
640 struct alarm *alarm = &timr->it.alarm.alarmtimer;
641 struct alarm_base *base = &alarm_bases[alarm->type];
642
643 if (!absolute)
644 expires = ktime_add_safe(expires, base->gettime());
645 if (sigev_none)
646 alarm->node.expires = expires;
647 else
648 alarm_start(&timr->it.alarm.alarmtimer, expires);
649 }
650
651
652
653
654
655
656
657
658 static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
659 {
660 if (!alarmtimer_get_rtcdev())
661 return -EINVAL;
662
663 tp->tv_sec = 0;
664 tp->tv_nsec = hrtimer_resolution;
665 return 0;
666 }
667
668
669
670
671
672
673
674
675 static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
676 {
677 struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
678
679 if (!alarmtimer_get_rtcdev())
680 return -EINVAL;
681
682 *tp = ktime_to_timespec64(base->gettime());
683 return 0;
684 }
685
686
687
688
689
690
691
692 static int alarm_timer_create(struct k_itimer *new_timer)
693 {
694 enum alarmtimer_type type;
695
696 if (!alarmtimer_get_rtcdev())
697 return -EOPNOTSUPP;
698
699 if (!capable(CAP_WAKE_ALARM))
700 return -EPERM;
701
702 type = clock2alarm(new_timer->it_clock);
703 alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer);
704 return 0;
705 }
706
707
708
709
710
711
712
713 static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm,
714 ktime_t now)
715 {
716 struct task_struct *task = (struct task_struct *)alarm->data;
717
718 alarm->data = NULL;
719 if (task)
720 wake_up_process(task);
721 return ALARMTIMER_NORESTART;
722 }
723
724
725
726
727
728
729
730
731 static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
732 enum alarmtimer_type type)
733 {
734 struct restart_block *restart;
735 alarm->data = (void *)current;
736 do {
737 set_current_state(TASK_INTERRUPTIBLE);
738 alarm_start(alarm, absexp);
739 if (likely(alarm->data))
740 schedule();
741
742 alarm_cancel(alarm);
743 } while (alarm->data && !signal_pending(current));
744
745 __set_current_state(TASK_RUNNING);
746
747 destroy_hrtimer_on_stack(&alarm->timer);
748
749 if (!alarm->data)
750 return 0;
751
752 if (freezing(current))
753 alarmtimer_freezerset(absexp, type);
754 restart = ¤t->restart_block;
755 if (restart->nanosleep.type != TT_NONE) {
756 struct timespec64 rmt;
757 ktime_t rem;
758
759 rem = ktime_sub(absexp, alarm_bases[type].gettime());
760
761 if (rem <= 0)
762 return 0;
763 rmt = ktime_to_timespec64(rem);
764
765 return nanosleep_copyout(restart, &rmt);
766 }
767 return -ERESTART_RESTARTBLOCK;
768 }
769
770 static void
771 alarm_init_on_stack(struct alarm *alarm, enum alarmtimer_type type,
772 enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
773 {
774 hrtimer_init_on_stack(&alarm->timer, alarm_bases[type].base_clockid,
775 HRTIMER_MODE_ABS);
776 __alarm_init(alarm, type, function);
777 }
778
779
780
781
782
783
784
785 static long __sched alarm_timer_nsleep_restart(struct restart_block *restart)
786 {
787 enum alarmtimer_type type = restart->nanosleep.clockid;
788 ktime_t exp = restart->nanosleep.expires;
789 struct alarm alarm;
790
791 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup);
792
793 return alarmtimer_do_nsleep(&alarm, exp, type);
794 }
795
796
797
798
799
800
801
802
803
804
805 static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
806 const struct timespec64 *tsreq)
807 {
808 enum alarmtimer_type type = clock2alarm(which_clock);
809 struct restart_block *restart = ¤t->restart_block;
810 struct alarm alarm;
811 ktime_t exp;
812 int ret = 0;
813
814 if (!alarmtimer_get_rtcdev())
815 return -EOPNOTSUPP;
816
817 if (flags & ~TIMER_ABSTIME)
818 return -EINVAL;
819
820 if (!capable(CAP_WAKE_ALARM))
821 return -EPERM;
822
823 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup);
824
825 exp = timespec64_to_ktime(*tsreq);
826
827 if (flags != TIMER_ABSTIME) {
828 ktime_t now = alarm_bases[type].gettime();
829
830 exp = ktime_add_safe(now, exp);
831 }
832
833 ret = alarmtimer_do_nsleep(&alarm, exp, type);
834 if (ret != -ERESTART_RESTARTBLOCK)
835 return ret;
836
837
838 if (flags == TIMER_ABSTIME)
839 return -ERESTARTNOHAND;
840
841 restart->fn = alarm_timer_nsleep_restart;
842 restart->nanosleep.clockid = type;
843 restart->nanosleep.expires = exp;
844 return ret;
845 }
846
847 const struct k_clock alarm_clock = {
848 .clock_getres = alarm_clock_getres,
849 .clock_get = alarm_clock_get,
850 .timer_create = alarm_timer_create,
851 .timer_set = common_timer_set,
852 .timer_del = common_timer_del,
853 .timer_get = common_timer_get,
854 .timer_arm = alarm_timer_arm,
855 .timer_rearm = alarm_timer_rearm,
856 .timer_forward = alarm_timer_forward,
857 .timer_remaining = alarm_timer_remaining,
858 .timer_try_to_cancel = alarm_timer_try_to_cancel,
859 .timer_wait_running = alarm_timer_wait_running,
860 .nsleep = alarm_timer_nsleep,
861 };
862 #endif
863
864
865
866 static const struct dev_pm_ops alarmtimer_pm_ops = {
867 .suspend = alarmtimer_suspend,
868 .resume = alarmtimer_resume,
869 };
870
871 static struct platform_driver alarmtimer_driver = {
872 .driver = {
873 .name = "alarmtimer",
874 .pm = &alarmtimer_pm_ops,
875 }
876 };
877
878
879
880
881
882
883
884 static int __init alarmtimer_init(void)
885 {
886 int error;
887 int i;
888
889 alarmtimer_rtc_timer_init();
890
891
892 alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
893 alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
894 alarm_bases[ALARM_BOOTTIME].base_clockid = CLOCK_BOOTTIME;
895 alarm_bases[ALARM_BOOTTIME].gettime = &ktime_get_boottime;
896 for (i = 0; i < ALARM_NUMTYPE; i++) {
897 timerqueue_init_head(&alarm_bases[i].timerqueue);
898 spin_lock_init(&alarm_bases[i].lock);
899 }
900
901 error = alarmtimer_rtc_interface_setup();
902 if (error)
903 return error;
904
905 error = platform_driver_register(&alarmtimer_driver);
906 if (error)
907 goto out_if;
908
909 return 0;
910 out_if:
911 alarmtimer_rtc_interface_remove();
912 return error;
913 }
914 device_initcall(alarmtimer_init);