acpi_lid: correctly report lid status

* notify handling not working (like acpi_ac).
* deleted header
* code cleanup
This commit is contained in:
Jérôme Duval 2013-11-01 20:31:03 +01:00
parent c9fb65f961
commit 45c56fdb6b
3 changed files with 68 additions and 47 deletions

View File

@ -1,15 +1,5 @@
SubDir HAIKU_TOP src add-ons kernel drivers power acpi_lid ;
SetSubDirSupportedPlatformsBeOSCompatible ;
if $(TARGET_PLATFORM) != haiku {
# Needed for <ACPI.h>. Unfortunately we also get the other headers there,
# that we don't really want.
UsePublicHeaders drivers ;
}
KernelAddon acpi_lid :
acpi_lid.c
acpi_lid.cpp
;
Depends acpi_lid : acpi ;

View File

@ -1,19 +1,16 @@
/*
* Copyright 2008, Haiku, Inc. All Rights Reserved.
* Copyright 2008-2013, Jérôme Duval, korli@users.berlios.de.
*
* Distributed under the terms of the MIT License.
*/
#include <KernelExport.h>
#include <Drivers.h>
#include <Errors.h>
#include <string.h>
#include <ACPI.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ACPI.h>
#include "acpi_lid.h"
#define ACPI_LID_MODULE_NAME "drivers/power/acpi_lid/driver_v1"
@ -25,15 +22,37 @@
// name of pnp generator of path ids
#define ACPI_LID_PATHID_GENERATOR "acpi_lid/path_id"
#define TRACE_LID
#ifdef TRACE_LID
# define TRACE(x...) dprintf("acpi_lid: "x)
#else
# define TRACE(x...)
#endif
#define ERROR(x...) dprintf("acpi_lid: "x)
static device_manager_info *sDeviceManager;
typedef struct acpi_ns_device_info {
device_node *node;
acpi_device_module_info *acpi;
acpi_device acpi_cookie;
uint8 last_status;
} acpi_lid_device_info;
static void
acpi_lid_notify_handler(acpi_handle device, uint32 value, void *context)
{
if (value == 0x80) {
dprintf("acpi_lid: status changed\n");
} else {
dprintf("acpi_lid: unknown notification\n");
}
}
// #pragma mark - device module API
@ -43,6 +62,7 @@ acpi_lid_init_device(void *_cookie, void **cookie)
device_node *node = (device_node *)_cookie;
acpi_lid_device_info *device;
device_node *parent;
status_t status;
device = (acpi_lid_device_info *)calloc(1, sizeof(*device));
if (device == NULL)
@ -55,6 +75,28 @@ acpi_lid_init_device(void *_cookie, void **cookie)
(void **)&device->acpi_cookie);
sDeviceManager->put_node(parent);
status = device->acpi->install_notify_handler(device->acpi_cookie, ACPI_DEVICE_NOTIFY,
acpi_lid_notify_handler, device);
if (status != B_OK) {
ERROR("can't install notify handler\n");
}
device->last_status = 0;
acpi_data buf;
buf.pointer = NULL;
buf.length = ACPI_ALLOCATE_BUFFER;
if (device->acpi->evaluate_method(device->acpi_cookie, "_LID", 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);
}
*cookie = device;
return B_OK;
}
@ -64,6 +106,10 @@ static void
acpi_lid_uninit_device(void *_cookie)
{
acpi_lid_device_info *device = (acpi_lid_device_info *)_cookie;
device->acpi->remove_notify_handler(device->acpi_cookie, ACPI_DEVICE_NOTIFY,
acpi_lid_notify_handler);
free(device);
}
@ -94,8 +140,6 @@ acpi_lid_write(void* cookie, off_t position, const void* buffer, size_t* num_byt
static status_t
acpi_lid_control(void* _cookie, uint32 op, void* arg, size_t len)
{
acpi_lid_device_info* device = (acpi_lid_device_info*)_cookie;
return B_ERROR;
}
@ -124,8 +168,6 @@ acpi_lid_support(device_node *parent)
uint32 device_type;
const char *hid;
dprintf("acpi_lid_support\n");
// make sure parent is really the ACPI bus manager
if (sDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false))
return -1;
@ -134,17 +176,20 @@ acpi_lid_support(device_node *parent)
return 0.0;
// check whether it's really a device
if (sDeviceManager->get_attr_uint32(parent, ACPI_DEVICE_TYPE_ITEM, &device_type, false) != B_OK
if (sDeviceManager->get_attr_uint32(parent, ACPI_DEVICE_TYPE_ITEM,
&device_type, false) != B_OK
|| device_type != ACPI_TYPE_DEVICE) {
return 0.0;
}
// check whether it's a lid device
if (sDeviceManager->get_attr_string(parent, ACPI_DEVICE_HID_ITEM, &hid, false) != B_OK
|| strcmp(hid, "PNP0C0D")) {
if (sDeviceManager->get_attr_string(parent, ACPI_DEVICE_HID_ITEM, &hid,
false) != B_OK || strcmp(hid, "PNP0C0D")) {
return 0.0;
}
dprintf("acpi_lid_support lid device found\n");
return 0.6;
}
@ -157,7 +202,8 @@ acpi_lid_register_device(device_node *node)
{ NULL }
};
return sDeviceManager->register_node(node, ACPI_LID_MODULE_NAME, attrs, NULL, NULL);
return sDeviceManager->register_node(node, ACPI_LID_MODULE_NAME, attrs,
NULL, NULL);
}
@ -178,12 +224,10 @@ acpi_lid_uninit_driver(void *driverCookie)
static status_t
acpi_lid_register_child_devices(void *_cookie)
{
device_node *node = _cookie;
device_node *node = (device_node *)_cookie;
int path_id;
char name[128];
dprintf("acpi_lid_register_child_devices\n");
path_id = sDeviceManager->create_id(ACPI_LID_PATHID_GENERATOR);
if (path_id < 0) {
dprintf("acpi_lid_register_child_devices: couldn't create a path_id\n");

View File

@ -1,13 +0,0 @@
/*
* Copyright 2008, Haiku, Inc. All Rights Reserved.
*
* Distributed under the terms of the MIT License.
*/
#ifndef _ACPI_LID_H
#define _ACPI_LID_H
#include <KernelExport.h>
#include <ACPI.h>
#endif /* _ACPI_LID_H */