Subject: [PATCH] [acpi driver model] Add interface for adding device events - Create drivers/acpi/drivers/core/event.c and implement acpi_device_event_{add,remove}. - Make sure it gets built with the core. Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/Makefile | 2 + drivers/acpi/drivers/core/event.c | 62 ++++++++++++++++++++++++++++++++++++ drivers/acpi/drivers/core/event.h | 9 +++++ 3 files changed, 72 insertions(+), 1 deletions(-) create mode 100644 drivers/acpi/drivers/core/event.c create mode 100644 drivers/acpi/drivers/core/event.h applies-to: 22963cb20674717c67c6f1803ba0cca9ac29869c 97225015529c334c84b6e109caa1b7ff7d460b92 diff --git a/drivers/acpi/drivers/core/Makefile b/drivers/acpi/drivers/core/Makefile index da56506..b9c847a 100644 --- a/drivers/acpi/drivers/core/Makefile +++ b/drivers/acpi/drivers/core/Makefile @@ -1,5 +1,5 @@ -obj-y := bus.o device.o driver.o +obj-y := bus.o device.o driver.o event.o obj-y += lib.o obj-$(CONFIG_ACPI_DM_SYSFS) += sysfs.o diff --git a/drivers/acpi/drivers/core/event.c b/drivers/acpi/drivers/core/event.c new file mode 100644 index 0000000..acc4eb6 --- /dev/null +++ b/drivers/acpi/drivers/core/event.c @@ -0,0 +1,62 @@ +/** + * drivers/acpi/drivers/core/event.c - Core event management + * + * Copyright (C) 2006 Patrick Mochel + * + */ + +#include "core.h" + + +/** + * acpi_device_event_add - Register a driver's event handler + * @ad: The device to register handler for. + * + * This function is called by the ACPI driver core, + * after the device has been successfully added to the + * driver. + * + * This is all simple - we check for a valid ->d_event + * field in the driver, and if it's there, use it to + * register a handler for the device. + */ + +int acpi_device_event_add(struct acpi_dev * ad) +{ + struct acpi_device_driver * drv = to_acpi_driver(ad->dev.driver); + struct acpi_device_event * e = drv->d_event; + int ret = 0; + + if (e && e->e_handler) { + acpi_status status; + + status = acpi_install_notify_handler(ad->acpi_device->handle, + e->e_type, + e->e_handler, + ad); + if (ACPI_FAILURE(status)) { + err("Installing notify handler failed for [%s] [%s]", + drv->d_drv.name, ad->dev.bus_id); + ret = -EIO; + } + } + return ret; +} + + +/** + * acpi_device_event_remove - Unregister a driver's event handler + * @ad: The device to unregister the handler for. + * + */ + +void acpi_device_event_remove(struct acpi_dev * ad) +{ + struct acpi_device_driver * drv = to_acpi_driver(ad->dev.driver); + struct acpi_device_event * e = drv->d_event; + + if (e && e->e_handler) { + acpi_remove_notify_handler(ad->acpi_device->handle, + e->e_type, e->e_handler); + } +} diff --git a/drivers/acpi/drivers/core/event.h b/drivers/acpi/drivers/core/event.h new file mode 100644 index 0000000..9eddbc1 --- /dev/null +++ b/drivers/acpi/drivers/core/event.h @@ -0,0 +1,9 @@ +/** + * drivers/acpi/drivers/core/event.h + * + * Event handler interface for ACPI driver model. + */ + + +extern int acpi_device_event_add(struct acpi_dev * ad); +extern void acpi_device_event_remove(struct acpi_dev * ad); --- 0.99.9.GIT