Skip to contentSkip to conversation

x86/init: Add option to skip using RTC

PATCH New Rahul Tanwar 1 participant 2 messages Oct 10, 2019 x86

lore
Share & tools
lore
#0 lore raw

v3 cover x86/init: Add option to skip using RTC

Hi,

We have a new Atom Airmont core based product which does not support RTC as persistent clock source.

Presently, platform ops get/set wallclock always use MC146818 RTC/CMOS device to read & set time. This causes boot failure on our SOC with no RTC. More specifically, it hangs in RTC driver's mach_get_cmos_time() when it polls RTC_FRQ_SELECT register and loops until Update-In-Progress (UIP) flag gets cleared i.e. below code snippet.

while ((CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP))

		cpu_relax();

After few rounds of review cycles/feedback, we concluded that we should control it from Motorola MC146818 compatible RTC devicetree node. Please see [1].

Make RTC read/write optional by detecting platforms which does not support RTC/CMOS device through the corresponding DT node status property. If status says disabled, then noop the get/set wallclock ops.

For non DT enabled platforms or for DT enabled platforms which does not define optional status property, proceed same as before.

Patch is baselined upon Linux 5.4-rc2 at below Git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/core

[1] Documentation/devicetree/bindings/rtc/rtc-cmos.txt

v3:
* Rebase to latest 5.4-rc2 kernel.
* Fix a build warning reported by kbuild test robot.

v2:
* As per review feedback, do not hack RTC read/write functions directly. Instead, override get/set wallclock ops during setup_arch init sequence.

v1:
* Detect platforms with no RTC in RTC read/write functions and skip RTC read/write if not applicable.

Rahul Tanwar (1):
x86/init: Noop get/set wallclock when platform doesn't support RTC

 arch/x86/kernel/x86_init.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/1 x86/init: Noop get/set wallclock when platform doesn't support RTC

Use wallclock_init() op to detect platforms which does not support RTC and noop get/set wallclock ops for such platforms.

---
 arch/x86/kernel/x86_init.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
arch/x86/kernel/x86_init.c +25 -1
index 18a799c8fa28..4f572fd942eb 100644
@@ -31,6 +31,30 @@ 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 int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
+static void get_rtc_noop(struct timespec64 *now) { }
+
+static const struct of_device_id of_cmos_match[] = {
+	{ .compatible = "motorola,mc146818" },
+	{}
+};
+
+static void x86_wallclock_init(void)
+{
+	struct device_node *node;
+
+	node = of_find_matching_node(NULL, of_cmos_match);
+	if (node && !of_device_is_available(node)) {
+		/*
+		 * Some products do not support RTC as persistent clock source. This can be
+		 * optionally indicated by having status property as disabled in the
+		 * corresponding DT node. Override get/set wallclock routines to noops for
+		 * such products.
+		 */
+		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 +97,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 = {
Signature · 1 line
2.11.0