Skip to content

Commit e8d1eb6

Browse files
committed
ACPI: TAD/x86: cmos_rtc: Consolidate address space handler setup
On x86, as a rule the CMOS RTC address space handler is set up by the CMOS RTC ACPI scan handler attach callback, acpi_cmos_rtc_attach(), but if the ACPI namespace does not contain a CMOS RTC device object, the CMOS RTC address space handler installation is taken care of the ACPI TAD (Timer and Alarm Device) driver. This is not particularly straightforward and can be avoided by adding the ACPI TAD device ID to the CMOS RTC ACPI scan handler which will cause it to create a platform device for ACPI TAD after installing the CMOS RTC address space handler. One related detail that needs to be taken care of, though, is that the creation of an ACPI TAD platform device should not cause cmos_rtc_platform_device_present to be set, since this may cause add_rtc_cmos() to suppress the creation of a fallback CMOS RTC platform device which may not be the right thing to do (for instance, due to the fact that the ACPI TAD driver is missing an RTC class device interface). After doing the above, the CMOS RTC address space handler installation and removal can be dropped from the ACPI TAD driver (which allows it to be simplified quite a bit), acpi_remove_cmos_rtc_space_handler() can be dropped and acpi_install_cmos_rtc_space_handler() can be made static. Update the code as per the above. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/23028644.EfDdHjke4D@rafael.j.wysocki
1 parent 62bf102 commit e8d1eb6

3 files changed

Lines changed: 10 additions & 52 deletions

File tree

drivers/acpi/acpi_tad.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ static int acpi_tad_disable_timer(struct device *dev, u32 timer_id)
563563
static void acpi_tad_remove(struct platform_device *pdev)
564564
{
565565
struct device *dev = &pdev->dev;
566-
acpi_handle handle = ACPI_HANDLE(dev);
567566
struct acpi_tad_driver_data *dd = dev_get_drvdata(dev);
568567

569568
device_init_wakeup(dev, false);
@@ -587,7 +586,6 @@ static void acpi_tad_remove(struct platform_device *pdev)
587586

588587
pm_runtime_suspend(dev);
589588
pm_runtime_disable(dev);
590-
acpi_remove_cmos_rtc_space_handler(handle);
591589
}
592590

593591
static int acpi_tad_probe(struct platform_device *pdev)
@@ -599,39 +597,29 @@ static int acpi_tad_probe(struct platform_device *pdev)
599597
unsigned long long caps;
600598
int ret;
601599

602-
ret = acpi_install_cmos_rtc_space_handler(handle);
603-
if (ret < 0) {
604-
dev_info(dev, "Unable to install space handler\n");
605-
return -ENODEV;
606-
}
607600
/*
608601
* Initialization failure messages are mostly about firmware issues, so
609602
* print them at the "info" level.
610603
*/
611604
status = acpi_evaluate_integer(handle, "_GCP", NULL, &caps);
612605
if (ACPI_FAILURE(status)) {
613606
dev_info(dev, "Unable to get capabilities\n");
614-
ret = -ENODEV;
615-
goto remove_handler;
607+
return -ENODEV;
616608
}
617609

618610
if (!(caps & ACPI_TAD_AC_WAKE)) {
619611
dev_info(dev, "Unsupported capabilities\n");
620-
ret = -ENODEV;
621-
goto remove_handler;
612+
return -ENODEV;
622613
}
623614

624615
if (!acpi_has_method(handle, "_PRW")) {
625616
dev_info(dev, "Missing _PRW\n");
626-
ret = -ENODEV;
627-
goto remove_handler;
617+
return -ENODEV;
628618
}
629619

630620
dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL);
631-
if (!dd) {
632-
ret = -ENOMEM;
633-
goto remove_handler;
634-
}
621+
if (!dd)
622+
return -ENOMEM;
635623

636624
dd->capabilities = caps;
637625
dev_set_drvdata(dev, dd);
@@ -673,11 +661,6 @@ static int acpi_tad_probe(struct platform_device *pdev)
673661

674662
fail:
675663
acpi_tad_remove(pdev);
676-
/* Don't fallthrough because cmos rtc space handler is removed in acpi_tad_remove() */
677-
return ret;
678-
679-
remove_handler:
680-
acpi_remove_cmos_rtc_space_handler(handle);
681664
return ret;
682665
}
683666

drivers/acpi/x86/cmos_rtc.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
#include "../internal.h"
1919

2020
static const struct acpi_device_id acpi_cmos_rtc_ids[] = {
21+
{ "ACPI000E", 1 }, /* ACPI Time and Alarm Device (TAD) */
2122
ACPI_CMOS_RTC_IDS
2223
};
2324

2425
bool cmos_rtc_platform_device_present;
2526

26-
static bool cmos_rtc_space_handler_present __read_mostly;
27-
2827
static acpi_status acpi_cmos_rtc_space_handler(u32 function,
2928
acpi_physical_address address,
3029
u32 bits, u64 *value64,
@@ -56,8 +55,9 @@ static acpi_status acpi_cmos_rtc_space_handler(u32 function,
5655
return AE_BAD_PARAMETER;
5756
}
5857

59-
int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
58+
static int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
6059
{
60+
static bool cmos_rtc_space_handler_present __read_mostly;
6161
acpi_status status;
6262

6363
if (cmos_rtc_space_handler_present)
@@ -76,22 +76,6 @@ int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
7676

7777
return 1;
7878
}
79-
EXPORT_SYMBOL_GPL(acpi_install_cmos_rtc_space_handler);
80-
81-
void acpi_remove_cmos_rtc_space_handler(acpi_handle handle)
82-
{
83-
acpi_status status;
84-
85-
if (cmos_rtc_space_handler_present)
86-
return;
87-
88-
status = acpi_remove_address_space_handler(handle,
89-
ACPI_ADR_SPACE_CMOS,
90-
acpi_cmos_rtc_space_handler);
91-
if (ACPI_FAILURE(status))
92-
pr_err("Failed to remove CMOS-RTC address space handler\n");
93-
}
94-
EXPORT_SYMBOL_GPL(acpi_remove_cmos_rtc_space_handler);
9579

9680
static int acpi_cmos_rtc_attach(struct acpi_device *adev,
9781
const struct acpi_device_id *id)
@@ -103,9 +87,9 @@ static int acpi_cmos_rtc_attach(struct acpi_device *adev,
10387
return ret;
10488

10589
if (IS_ERR_OR_NULL(acpi_create_platform_device(adev, NULL))) {
106-
pr_err("Failed to create CMOS-RTC platform device\n");
90+
pr_err("Failed to create a platform device for %s\n", (char *)id->id);
10791
return 0;
108-
} else {
92+
} else if (!id->driver_data) {
10993
cmos_rtc_platform_device_present = true;
11094
}
11195
return 1;

include/acpi/acpi_bus.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,6 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev);
760760
#ifdef CONFIG_X86
761761
bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
762762
bool acpi_quirk_skip_acpi_ac_and_battery(void);
763-
int acpi_install_cmos_rtc_space_handler(acpi_handle handle);
764-
void acpi_remove_cmos_rtc_space_handler(acpi_handle handle);
765763
int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip);
766764
#else
767765
static inline bool acpi_device_override_status(struct acpi_device *adev,
@@ -773,13 +771,6 @@ static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
773771
{
774772
return false;
775773
}
776-
static inline int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
777-
{
778-
return 1;
779-
}
780-
static inline void acpi_remove_cmos_rtc_space_handler(acpi_handle handle)
781-
{
782-
}
783774
static inline int
784775
acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
785776
{

0 commit comments

Comments
 (0)