]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
x86/init: Allow DT configured systems to disable RTC at boot time
authorRahul Tanwar <rahul.tanwar@linux.intel.com>
Thu, 10 Oct 2019 09:28:56 +0000 (17:28 +0800)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 12 Nov 2019 14:46:53 +0000 (15:46 +0100)
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 <andriy.shevchenko@intel.com>
Signed-off-by: Rahul Tanwar <rahul.tanwar@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/b84d9152ce0c1c09896ff4987e691a0715cb02df.1570693058.git.rahul.tanwar@linux.intel.com
arch/x86/kernel/x86_init.c

index 18a799c8fa28b0eac90b3505fae50559d70250df..ce89430a7f8011aa5d49e1ee99dcae19a9862cf1 100644 (file)
@@ -31,6 +31,28 @@ static int __init iommu_init_noop(void) { return 0; }
 static void iommu_shutdown_noop(void) { }
 bool __init bool_x86_init_noop(void) { return false; }
 void x86_op_int_noop(int cpu) { }
+static __init int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
+static __init void get_rtc_noop(struct timespec64 *now) { }
+
+static __initconst const struct of_device_id of_cmos_match[] = {
+       { .compatible = "motorola,mc146818" },
+       {}
+};
+
+/*
+ * Allow devicetree configured systems to disable the RTC by setting the
+ * corresponding DT node's status property to disabled. Code is optimized
+ * out for CONFIG_OF=n builds.
+ */
+static __init void x86_wallclock_init(void)
+{
+       struct device_node *node = of_find_matching_node(NULL, of_cmos_match);
+
+       if (node && !of_device_is_available(node)) {
+               x86_platform.get_wallclock = get_rtc_noop;
+               x86_platform.set_wallclock = set_rtc_noop;
+       }
+}
 
 /*
  * The platform setup functions are preset with the default functions
@@ -73,7 +95,7 @@ struct x86_init_ops x86_init __initdata = {
        .timers = {
                .setup_percpu_clockev   = setup_boot_APIC_clock,
                .timer_init             = hpet_time_init,
-               .wallclock_init         = x86_init_noop,
+               .wallclock_init         = x86_wallclock_init,
        },
 
        .iommu = {