1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/clockchips.h>
7 #include <linux/init.h>
8 #include <linux/timex.h>
9 #include <linux/i8253.h>
17 * HPET replaces the PIT, when enabled. So we need to know, which of
18 * the two timers is used
20 struct clock_event_device
*global_clock_event
;
23 * Modern chipsets can disable the PIT clock which makes it unusable. It
24 * would be possible to enable the clock but the registers are chipset
25 * specific and not discoverable. Avoid the whack a mole game.
27 * These platforms have discoverable TSC/CPU frequencies but this also
28 * requires to know the local APIC timer frequency as it normally is
29 * calibrated against the PIT interrupt.
31 static bool __init
use_pit(void)
33 if (!IS_ENABLED(CONFIG_X86_TSC
) || !boot_cpu_has(X86_FEATURE_TSC
))
36 /* This also returns true when APIC is disabled */
37 return apic_needs_pit();
40 bool __init
pit_timer_init(void)
45 clockevent_i8253_init(true);
46 global_clock_event
= &i8253_clockevent
;
51 static int __init
init_pit_clocksource(void)
54 * Several reasons not to register PIT as a clocksource:
56 * - On SMP PIT does not scale due to i8253_lock
57 * - when HPET is enabled
58 * - when local APIC timer is active (PIT is switched off)
60 if (num_possible_cpus() > 1 || is_hpet_enabled() ||
61 !clockevent_state_periodic(&i8253_clockevent
))
64 return clocksource_i8253_init();
66 arch_initcall(init_pit_clocksource
);
67 #endif /* !CONFIG_X86_64 */