acpi_ac: update "last_status" on acpi_ac_notify_handler()

* Extracted an "acpi_ac_update_status()" function.
* Use that for both "acpi_ac_init_driver" and "acpi_ac_notify_handler".

This ensures that "acpi_ac_read()" returns the correct (current) status.

Change-Id: I4f8f35037180c10fe507b9abfda3a8a169349c13
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6048
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Oscar Lesta 2023-02-07 13:18:09 +00:00 committed by waddlesplash
parent a34c877fd0
commit a780ec8653

View File

@ -41,15 +41,36 @@ typedef struct acpi_ns_device_info {
} acpi_ac_device_info;
static void
acpi_ac_update_status(acpi_ac_device_info* device)
{
acpi_data buf;
buf.pointer = NULL;
buf.length = ACPI_ALLOCATE_BUFFER;
if (device->acpi->evaluate_method(device->acpi_cookie, "_PSR", NULL, &buf) != B_OK
|| buf.pointer == NULL
|| ((acpi_object_type*)buf.pointer)->object_type != ACPI_TYPE_INTEGER) {
ERROR("couldn't get status\n");
} else {
acpi_object_type* object = (acpi_object_type*)buf.pointer;
device->last_status = object->integer.integer;
TRACE("status %d\n", device->last_status);
}
free(buf.pointer);
}
static void
acpi_ac_notify_handler(acpi_handle device, uint32 value, void *context)
{
if (value == 0x80) {
dprintf("acpi_ac: status changed\n");
} else {
dprintf("acpi_ac: unknown notification\n");
if (value != 0x80) {
dprintf("acpi_ac: unknown notification (%d)\n", value);
return;
}
acpi_ac_device_info* dev = (acpi_ac_device_info*) context;
acpi_ac_update_status(dev);
}
@ -196,20 +217,8 @@ acpi_ac_init_driver(device_node *node, void **_driverCookie)
}
device->last_status = 0;
acpi_data buf;
buf.pointer = NULL;
buf.length = ACPI_ALLOCATE_BUFFER;
if (device->acpi->evaluate_method(device->acpi_cookie, "_PSR", NULL,
&buf) != B_OK
|| buf.pointer == NULL
|| ((acpi_object_type*)buf.pointer)->object_type != ACPI_TYPE_INTEGER) {
ERROR("couldn't get status\n");
} else {
acpi_object_type* object = (acpi_object_type*)buf.pointer;
device->last_status = object->integer.integer;
free(buf.pointer);
TRACE("status %d\n", device->last_status);
}
acpi_ac_update_status(device);
*_driverCookie = device;
return B_OK;