Linux RTC
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ACPI: TAD: introduce acpi_has_rtc()
@ 2026-10-23 21:22 Hamza Mahfooz
  2026-10-23 21:22 ` [PATCH v2 2/2] rtc: efi: defer to the ACPI TAD if it can drive the RTC Hamza Mahfooz
  2026-10-23 21:32 ` [PATCH v2 1/2] ACPI: TAD: introduce acpi_has_rtc() sashiko-bot
  0 siblings, 2 replies; 4+ messages in thread
From: Hamza Mahfooz @ 2026-10-23 21:22 UTC (permalink / raw)
  To: linux-acpi, linux-rtc
  Cc: Rafael J. Wysocki, Len Brown, Alexandre Belloni, Hamza Mahfooz,
	Ard Biesheuvel

The same RTC may also be accessible by other means, like the EFI
GetTime() and SetTime() runtime services used by rtc-efi, which are best
avoided if there is a native ACPI interface to the RTC.

To allow other RTC drivers to stand down in that case, add an exported
helper, acpi_has_rtc(), that returns true if there is a TAD the driver
will register an RTC class device for.

The helper looks for a platform device matching the driver's ID table
whose _GCP indicates real time support, like acpi_tad_probe() checks,
instead of checking whether the driver has bound to such a device, so
that callers need not depend on the order in which drivers are probed.

Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
---
v1: https://lore.kernel.org/r/20261022211304.2285792-1-hamzamahfooz@linux.microsoft.com/
v2:
- Rename acpi_tad_rtc_available() to acpi_has_rtc(), move it to within
  acpi-tad (which allows us to simplify it quite a bit) and declare it
  in linux/acpi.h. (Ard)
- Add acpi_disabled check. (Ard)
---
 drivers/acpi/acpi_tad.c | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h    |  6 ++++++
 2 files changed, 44 insertions(+)

diff --git a/drivers/acpi/acpi_tad.c b/drivers/acpi/acpi_tad.c
index 45459a4ca..eea4d2123 100644
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -899,6 +899,44 @@ static const struct acpi_device_id acpi_tad_ids[] = {
 	{}
 };
 
+static int acpi_tad_rtc_match(struct device *dev, const void *data)
+{
+	unsigned long long caps;
+	acpi_status status;
+
+	if (!acpi_match_device(acpi_tad_ids, dev))
+		return 0;
+
+	status = acpi_evaluate_integer(ACPI_HANDLE(dev), "_GCP", NULL, &caps);
+
+	return ACPI_SUCCESS(status) && (caps & ACPI_TAD_RT);
+}
+
+/**
+ * acpi_has_rtc - Check if the RTC should be driven via the ACPI TAD
+ *
+ * Check if there is a TAD implementing the real time methods that this driver
+ * will register an RTC class device for.
+ *
+ * Return: %true if the RTC should be driven via the ACPI TAD, %false otherwise.
+ */
+bool acpi_has_rtc(void)
+{
+	struct device *dev;
+
+	if (acpi_disabled || !IS_ENABLED(CONFIG_RTC_CLASS))
+		return false;
+
+	dev = bus_find_device(&platform_bus_type, NULL, NULL,
+			      acpi_tad_rtc_match);
+	if (!dev)
+		return false;
+
+	put_device(dev);
+	return true;
+}
+EXPORT_SYMBOL_GPL(acpi_has_rtc);
+
 static struct platform_driver acpi_tad_driver = {
 	.driver = {
 		.name = "acpi-tad",
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9d3f039eb..636e5218c 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1548,6 +1548,12 @@ extern bool acpi_has_watchdog(void);
 static inline bool acpi_has_watchdog(void) { return false; }
 #endif
 
+#if IS_REACHABLE(CONFIG_ACPI_TAD)
+bool acpi_has_rtc(void);
+#else
+static inline bool acpi_has_rtc(void) { return false; }
+#endif
+
 #ifdef CONFIG_ACPI_SPCR_TABLE
 extern bool qdf2400_e44_present;
 int acpi_parse_spcr(bool enable_earlycon, bool enable_console);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-23 21:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 21:22 [PATCH v2 1/2] ACPI: TAD: introduce acpi_has_rtc() Hamza Mahfooz
2026-10-23 21:22 ` [PATCH v2 2/2] rtc: efi: defer to the ACPI TAD if it can drive the RTC Hamza Mahfooz
2026-10-23 21:30   ` sashiko-bot
2026-10-23 21:32 ` [PATCH v2 1/2] ACPI: TAD: introduce acpi_has_rtc() sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox