mirror of
https://github.com/torvalds/linux.git
synced 2024-12-17 16:43:08 +00:00
596ca52a56
Currently, the SystemCMOS address space handler is installed for the ACPI RTC devices (PNP0B00/PNP0B01/PNP0B02) only. But there are platforms with SystemCMOS Operetion Region defined under the ACPI Time and Alarm Device (ACPI000E), which is used by the ACPI pre-defined control methods like _GRT (Get the Real time) and _SRT (Set the Real time). When accessing these control methods via the acpi_tad sysfs interface, missing SystemCMOS address space handler causes errors like below [ 478.255453] ACPI Error: No handler for Region [RTCM] (00000000a8d2dd39) [SystemCMOS] (20230331/evregion-130) [ 478.255458] ACPI Error: Region SystemCMOS (ID=5) has no handler (20230331/exfldio-261) [ 478.255461] Initialized Local Variables for Method [_GRT]: [ 478.255461] Local1: 00000000f182542c <Obj> Integer 0000000000000000 [ 478.255464] No Arguments are initialized for method [_GRT] [ 478.255465] ACPI Error: Aborting method \_SB.AWAC._GRT due to previous error (AE_NOT_EXIST) (20230331/psparse-529) Export two APIs for SystemCMOS address space handler from acpi_cmos_rtc scan handler and install the handler for the ACPI Time and Alarm Device from the ACPI TAD driver. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217714 Signed-off-by: Zhang Rui <rui.zhang@intel.com> [ rjw: Subject and changelog edits, whitespace adjustment ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
99 lines
2.3 KiB
C
99 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* ACPI support for CMOS RTC Address Space access
|
|
*
|
|
* Copyright (C) 2013, Intel Corporation
|
|
* Authors: Lan Tianyu <tianyu.lan@intel.com>
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "ACPI: " fmt
|
|
|
|
#include <linux/acpi.h>
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mc146818rtc.h>
|
|
|
|
#include "internal.h"
|
|
|
|
static const struct acpi_device_id acpi_cmos_rtc_ids[] = {
|
|
{ "PNP0B00" },
|
|
{ "PNP0B01" },
|
|
{ "PNP0B02" },
|
|
{}
|
|
};
|
|
|
|
static acpi_status
|
|
acpi_cmos_rtc_space_handler(u32 function, acpi_physical_address address,
|
|
u32 bits, u64 *value64,
|
|
void *handler_context, void *region_context)
|
|
{
|
|
int i;
|
|
u8 *value = (u8 *)value64;
|
|
|
|
if (address > 0xff || !value64)
|
|
return AE_BAD_PARAMETER;
|
|
|
|
if (function != ACPI_WRITE && function != ACPI_READ)
|
|
return AE_BAD_PARAMETER;
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
for (i = 0; i < DIV_ROUND_UP(bits, 8); ++i, ++address, ++value)
|
|
if (function == ACPI_READ)
|
|
*value = CMOS_READ(address);
|
|
else
|
|
CMOS_WRITE(*value, address);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
return AE_OK;
|
|
}
|
|
|
|
int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
|
|
{
|
|
acpi_status status;
|
|
|
|
status = acpi_install_address_space_handler(handle,
|
|
ACPI_ADR_SPACE_CMOS,
|
|
&acpi_cmos_rtc_space_handler,
|
|
NULL, NULL);
|
|
if (ACPI_FAILURE(status)) {
|
|
pr_err("Error installing CMOS-RTC region handler\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
EXPORT_SYMBOL_GPL(acpi_install_cmos_rtc_space_handler);
|
|
|
|
void acpi_remove_cmos_rtc_space_handler(acpi_handle handle)
|
|
{
|
|
if (ACPI_FAILURE(acpi_remove_address_space_handler(handle,
|
|
ACPI_ADR_SPACE_CMOS, &acpi_cmos_rtc_space_handler)))
|
|
pr_err("Error removing CMOS-RTC region handler\n");
|
|
}
|
|
EXPORT_SYMBOL_GPL(acpi_remove_cmos_rtc_space_handler);
|
|
|
|
static int acpi_cmos_rtc_attach_handler(struct acpi_device *adev, const struct acpi_device_id *id)
|
|
{
|
|
return acpi_install_cmos_rtc_space_handler(adev->handle);
|
|
}
|
|
|
|
static void acpi_cmos_rtc_detach_handler(struct acpi_device *adev)
|
|
{
|
|
acpi_remove_cmos_rtc_space_handler(adev->handle);
|
|
}
|
|
|
|
static struct acpi_scan_handler cmos_rtc_handler = {
|
|
.ids = acpi_cmos_rtc_ids,
|
|
.attach = acpi_cmos_rtc_attach_handler,
|
|
.detach = acpi_cmos_rtc_detach_handler,
|
|
};
|
|
|
|
void __init acpi_cmos_rtc_init(void)
|
|
{
|
|
acpi_scan_add_handler(&cmos_rtc_handler);
|
|
}
|