Commit ba0b2367 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

ACPI: x86: cmos_rtc: Clean up address space handler driver



Make multiple changes that do not alter functionality to the CMOS RTC
ACPI address space handler driver, including the following:

 - Drop the unused .detach() callback from cmos_rtc_handler.

 - Rename acpi_cmos_rtc_attach_handler() to acpi_cmos_rtc_attach().

 - Rearrange acpi_cmos_rtc_space_handler() to reduce the number of
   redundant checks and make white space follow the coding style.

 - Adjust an error message in acpi_install_cmos_rtc_space_handler()
   and make the white space follow the coding style.

 - Rearrange acpi_remove_cmos_rtc_space_handler() and adjust an error
   message in it.

No intentional functional impact.

Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/5094429.31r3eYUQgx@rafael.j.wysocki
parent 6de23f81
Loading
Loading
Loading
Loading
+32 −29
Original line number Diff line number Diff line
@@ -24,43 +24,47 @@ static const struct acpi_device_id acpi_cmos_rtc_ids[] = {
	{}
};

static acpi_status
acpi_cmos_rtc_space_handler(u32 function, acpi_physical_address address,
static acpi_status acpi_cmos_rtc_space_handler(u32 function,
					       acpi_physical_address address,
					       u32 bits, u64 *value64,
		      void *handler_context, void *region_context)
					       void *handler_context,
					       void *region_context)
{
	int i;
	unsigned int i, bytes = DIV_ROUND_UP(bits, 8);
	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);
	guard(spinlock_irq)(&rtc_lock);

	for (i = 0; i < DIV_ROUND_UP(bits, 8); ++i, ++address, ++value)
		if (function == ACPI_READ)
			*value = CMOS_READ(address);
		else
	if (function == ACPI_WRITE) {
		for (i = 0; i < bytes; i++, address++, value++)
			CMOS_WRITE(*value, address);

	spin_unlock_irq(&rtc_lock);
		return AE_OK;
	}

	if (function == ACPI_READ) {
		for (i = 0; i < bytes; i++, address++, value++)
			*value = CMOS_READ(address);

		return AE_OK;
	}

	return AE_BAD_PARAMETER;
}

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,
						    acpi_cmos_rtc_space_handler,
						    NULL, NULL);
	if (ACPI_FAILURE(status)) {
		pr_err("Error installing CMOS-RTC region handler\n");
		pr_err("Failed to install CMOS-RTC address space handler\n");
		return -ENODEV;
	}

@@ -70,26 +74,25 @@ 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");
	acpi_status status;

	status = acpi_remove_address_space_handler(handle,
						   ACPI_ADR_SPACE_CMOS,
						   acpi_cmos_rtc_space_handler);
	if (ACPI_FAILURE(status))
		pr_err("Failed to remove CMOS-RTC address space 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)
static int acpi_cmos_rtc_attach(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,
	.attach = acpi_cmos_rtc_attach,
};

void __init acpi_cmos_rtc_init(void)