/** * alarmtimer_suspend - Suspend time callback * @dev: unused * @state: unused * * When we are going into suspend, we look through the bases * to see which is the soonest timer to expire. We then * set an rtc timer to fire that far into the future, which * will wake us from suspend. */ static int alarmtimer_suspend(struct device *dev) { struct rtc_time tm; ktime_t min, now; unsigned long flags; struct rtc_device *rtc; int i; spin_lock_irqsave(&freezer_delta_lock, flags); min = freezer_delta; freezer_delta = ktime_set(0, 0); spin_unlock_irqrestore(&freezer_delta_lock, flags); rtc = rtcdev; /* If we have no rtcdev, just return */ if (!rtc) return 0; /* Find the soonest timer to expire*/ for (i = 0; i < ALARM_NUMTYPE; i++) { struct alarm_base *base = &alarm_bases[i]; struct timerqueue_node *next; ktime_t delta; spin_lock_irqsave(&base->lock, flags); next = timerqueue_getnext(&base->timerqueue); spin_unlock_irqrestore(&base->lock, flags); if (!next) continue; delta = ktime_sub(next->expires, base->gettime()); if (!min.tv64 || (delta.tv64 < min.tv64)) min = delta; } if (min.tv64 == 0) return 0; /* XXX - Should we enforce a minimum sleep time? */ WARN_ON(min.tv64 < NSEC_PER_SEC); /* Setup an rtc timer to fire that far in the future */ rtc_timer_cancel(rtc, &rtctimer); rtc_read_time(rtc, &tm); now = rtc_tm_to_ktime(tm); now = ktime_add(now, min); rtc_timer_start(rtc, &rtctimer, now, ktime_set(0, 0)); return 0; }
/* * Initialize the real-time clock device. * In addition, various variables used to support the clock are initialized. */ int rtclock_init(void) { uint64_t cycles; assert(!ml_get_interrupts_enabled()); if (cpu_number() == master_cpu) { assert(tscFreq); rtc_set_timescale(tscFreq); /* * Adjust and set the exported cpu speed. */ cycles = rtc_export_speed(tscFreq); /* * Set min/max to actual. * ACPI may update these later if speed-stepping is detected. */ gPEClockFrequencyInfo.cpu_frequency_min_hz = cycles; gPEClockFrequencyInfo.cpu_frequency_max_hz = cycles; rtc_timer_init(); clock_timebase_init(); ml_init_lock_timeout(); ml_init_delay_spin_threshold(10); } /* Set fixed configuration for lapic timers */ rtc_timer->config(); rtc_timer_start(); return (1); }