Skip to content

Commit c311ed6

Browse files
Rahul TanwarKAGA-KOKO
authored andcommitted
x86/init: Allow DT configured systems to disable RTC at boot time
Systems which do not support RTC run into boot problems as the kernel assumes the availability of the RTC by default. On device tree configured systems the availability of the RTC can be detected by querying the corresponding device tree node. Implement a wallclock init function to query the device tree and disable RTC if the RTC is marked as not available in the corresponding node. [ tglx: Rewrote changelog and comments. Added proper __init(const) annotations. ] Suggested-by: Andy Shevchenko <[email protected]> Signed-off-by: Rahul Tanwar <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/b84d9152ce0c1c09896ff4987e691a0715cb02df.1570693058.git.rahul.tanwar@linux.intel.com
1 parent 6a181e3 commit c311ed6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

arch/x86/kernel/x86_init.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ static int __init iommu_init_noop(void) { return 0; }
3131
static void iommu_shutdown_noop(void) { }
3232
bool __init bool_x86_init_noop(void) { return false; }
3333
void x86_op_int_noop(int cpu) { }
34+
static __init int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
35+
static __init void get_rtc_noop(struct timespec64 *now) { }
36+
37+
static __initconst const struct of_device_id of_cmos_match[] = {
38+
{ .compatible = "motorola,mc146818" },
39+
{}
40+
};
41+
42+
/*
43+
* Allow devicetree configured systems to disable the RTC by setting the
44+
* corresponding DT node's status property to disabled. Code is optimized
45+
* out for CONFIG_OF=n builds.
46+
*/
47+
static __init void x86_wallclock_init(void)
48+
{
49+
struct device_node *node = of_find_matching_node(NULL, of_cmos_match);
50+
51+
if (node && !of_device_is_available(node)) {
52+
x86_platform.get_wallclock = get_rtc_noop;
53+
x86_platform.set_wallclock = set_rtc_noop;
54+
}
55+
}
3456

3557
/*
3658
* The platform setup functions are preset with the default functions
@@ -73,7 +95,7 @@ struct x86_init_ops x86_init __initdata = {
7395
.timers = {
7496
.setup_percpu_clockev = setup_boot_APIC_clock,
7597
.timer_init = hpet_time_init,
76-
.wallclock_init = x86_init_noop,
98+
.wallclock_init = x86_wallclock_init,
7799
},
78100

79101
.iommu = {

0 commit comments

Comments
 (0)