From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
Danilo Krummrich <dakr@kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v0 5/6] ACPI: TAD: Add RTC class device interface
Date: Sun, 22 Feb 2026 15:18:29 +0100 [thread overview]
Message-ID: <10819001.nUPlyArG6x@rafael.j.wysocki> (raw)
In-Reply-To: <4727679.LvFx2qVVIh@rafael.j.wysocki>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Add an RTC class device interface allowing to read and set the real time
value and providing a procfs callback to the ACPI TAD driver.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_tad.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 83 insertions(+), 2 deletions(-)
--- a/drivers/acpi/acpi_tad.c
+++ b/drivers/acpi/acpi_tad.c
@@ -25,6 +25,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/rtc.h>
#include <linux/suspend.h>
MODULE_DESCRIPTION("ACPI Time and Alarm (TAD) Device Driver");
@@ -51,6 +52,7 @@ MODULE_AUTHOR("Rafael J. Wysocki");
/* ACPI TAD RTC */
#define ACPI_TAD_TZ_UNSPEC 2047
+#define ACPI_TAD_TIME_ISDST 3
struct acpi_tad_driver_data {
u32 capabilities;
@@ -164,6 +166,8 @@ static int acpi_tad_get_real_time(struct
return 0;
}
+/* sysfs interface */
+
static char *acpi_tad_rt_next_field(char *s, int *val)
{
char *p;
@@ -579,6 +583,77 @@ static const struct attribute_group acpi
.is_visible = acpi_tad_attr_is_visible,
};
+/* RTC class device interface */
+
+static int acpi_tad_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct acpi_tad_rt rt;
+
+ rt.year = tm->tm_year + 1900;
+ rt.month = tm->tm_mon + 1;
+ rt.day = tm->tm_mday;
+ rt.hour = tm->tm_hour;
+ rt.minute = tm->tm_min;
+ rt.second = tm->tm_sec;
+ rt.tz = ACPI_TAD_TZ_UNSPEC;
+ rt.daylight = ACPI_TAD_TIME_ISDST * !!tm->tm_isdst;
+
+ return acpi_tad_set_real_time(dev, &rt);
+}
+
+static int acpi_tad_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ struct acpi_tad_rt rt;
+ int ret;
+
+ ret = acpi_tad_get_real_time(dev, &rt);
+ if (ret)
+ return ret;
+
+ tm->tm_year = rt.year - 1900;
+ tm->tm_mon = rt.month - 1;
+ tm->tm_mday = rt.day;
+ tm->tm_hour = rt.hour;
+ tm->tm_min = rt.minute;
+ tm->tm_sec = rt.second;
+ tm->tm_isdst = rt.daylight == ACPI_TAD_TIME_ISDST;
+
+ return 0;
+}
+
+static int acpi_tad_rtc_procfs(struct device *dev, struct seq_file *seq)
+{
+ struct acpi_tad_rt rt;
+ int ret;
+
+ ret = acpi_tad_get_real_time(dev, &rt);
+ if (ret)
+ return ret;
+
+ seq_printf(seq,
+ "Time\t\t: %u:%u:%u\n"
+ "Date\t\t: %u-%u-%u\n"
+ "Daylight\t: %s\n",
+ rt.hour, rt.minute, rt.second,
+ rt.year, rt.month, rt.day,
+ str_yes_no(rt.daylight == ACPI_TAD_TIME_ISDST));
+
+ if (rt.tz == ACPI_TAD_TZ_UNSPEC)
+ seq_puts(seq, "Timezone\t: unspecified\n");
+ else
+ seq_printf(seq, "Timezone\t: %d\n", rt.tz);
+
+ return 0;
+}
+
+static const struct rtc_class_ops acpi_tad_rtc_ops = {
+ .read_time = acpi_tad_rtc_read_time,
+ .set_time = acpi_tad_rtc_set_time,
+ .proc = acpi_tad_rtc_procfs,
+};
+
+/* Platform driver interface */
+
static int acpi_tad_disable_timer(struct device *dev, u32 timer_id)
{
return acpi_tad_wake_set(dev, "_STV", timer_id, ACPI_TAD_WAKE_DISABLED);
@@ -655,10 +730,16 @@ static int acpi_tad_probe(struct platfor
pm_runtime_suspend(dev);
ret = sysfs_create_group(&dev->kobj, &acpi_tad_attr_group);
- if (ret)
+ if (ret) {
acpi_tad_remove(pdev);
+ return ret;
+ }
- return ret;
+ if (caps & ACPI_TAD_RT)
+ devm_rtc_device_register(dev, "acpi-tad-rtc", &acpi_tad_rtc_ops,
+ THIS_MODULE);
+
+ return 0;
}
static const struct acpi_device_id acpi_tad_ids[] = {
next prev parent reply other threads:[~2026-02-22 14:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 14:14 [PATCH v0 0/6] ACPI: TAD: Assorted improvements and RTC class device interface Rafael J. Wysocki
2026-02-22 14:15 ` [PATCH v0 1/6] ACPI: TAD: Create one attribute group Rafael J. Wysocki
2026-02-22 14:16 ` [PATCH v0 2/6] ACPI: TAD: Use __free() for cleanup in time_store() Rafael J. Wysocki
2026-02-22 14:17 ` [PATCH v0 3/6] ACPI: TAD: Update RT data validation checking Rafael J. Wysocki
2026-02-22 14:17 ` [PATCH v0 4/6] ACPI: TAD: Clear unused RT data in acpi_tad_set_real_time() Rafael J. Wysocki
2026-02-22 14:18 ` Rafael J. Wysocki [this message]
2026-02-27 10:37 ` [PATCH v0 5/6] ACPI: TAD: Add RTC class device interface Alexandre Belloni
2026-02-27 11:26 ` Rafael J. Wysocki
2026-02-22 14:19 ` [PATCH v0 6/6] ACPI: TAD: Update the driver description comment Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10819001.nUPlyArG6x@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=dakr@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox