public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux ACPI <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-rtc@vger.kernel.org, Linux PM <linux-pm@vger.kernel.org>
Subject: Re: [PATCH v1 6/7] ACPI: TAD: Add RTC class device interface
Date: Thu, 5 Mar 2026 08:48:01 +0100	[thread overview]
Message-ID: <20260305074801a04117a7@mail.local> (raw)
In-Reply-To: <2352027.iZASKD2KPV@rafael.j.wysocki>

On 04/03/2026 19:16:01+0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Add an RTC class device interface allowing to read and set the real time
> value to the ACPI TAD driver.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/acpi/acpi_tad.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 76 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,71 @@ static const struct attribute_group acpi
>  	.is_visible = acpi_tad_attr_is_visible,
>  };
>  
> +#ifdef CONFIG_RTC_CLASS
> +/* 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 const struct rtc_class_ops acpi_tad_rtc_ops = {
> +	.read_time = acpi_tad_rtc_read_time,
> +	.set_time = acpi_tad_rtc_set_time,
> +};
> +
> +static void acpi_tad_register_rtc(struct device *dev)
> +{
> +	struct rtc_device *rtc;
> +
> +	rtc = devm_rtc_allocate_device(dev);
> +	if (IS_ERR(rtc))
> +		return;
> +
> +	rtc->range_min = mktime64(1900,  1,  1,  0,  0,  0);
> +	rtc->range_max = mktime64(9999, 12, 31, 23, 59, 59);
> +
> +	rtc->ops = &acpi_tad_rtc_ops;
> +
> +	devm_rtc_register_device(rtc);
> +}
> +#else /* !CONFIG_RTC_CLASS */
> +static inline void acpi_tad_register_rtc(struct device *dev) {}
> +#endif /* !CONFIG_RTC_CLASS */
> +
> +/* 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);
> @@ -660,10 +729,15 @@ 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)
> +		acpi_tad_register_rtc(dev);
> +
> +	return 0;
>  }
>  
>  static const struct acpi_device_id acpi_tad_ids[] = {
> 
> 
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2026-03-05  7:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 18:11 [PATCH v1 0/7] ACPI: TAD: Assorted improvements and RTC class device interface Rafael J. Wysocki
2026-03-04 18:12 ` [PATCH v1 1/7] ACPI: TAD: Create one attribute group Rafael J. Wysocki
2026-03-04 18:13 ` [PATCH v1 2/7] ACPI: TAD: Support RTC without wakeup Rafael J. Wysocki
2026-03-04 18:14 ` [PATCH v1 3/7] ACPI: TAD: Use __free() for cleanup in time_store() Rafael J. Wysocki
2026-03-04 18:14 ` [PATCH v1 4/7] ACPI: TAD: Rearrange RT data validation checking Rafael J. Wysocki
2026-03-04 18:15 ` [PATCH v1 5/7] ACPI: TAD: Clear unused RT data in acpi_tad_set_real_time() Rafael J. Wysocki
2026-03-04 18:16 ` [PATCH v1 6/7] ACPI: TAD: Add RTC class device interface Rafael J. Wysocki
2026-03-05  7:48   ` Alexandre Belloni [this message]
2026-03-04 18:16 ` [PATCH v1 7/7] 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=20260305074801a04117a7@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=rafael@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