ACPI: add battery hotplug support
Subsystems (2)
PATCH 3/4 ACPI: add battery hotplug support
From:Zhang Rui <[email protected]>
Subject: add battery hotplug support
Battery device hotplug support in generic code. Check the notify value and hot-insert/hot-remove the device in acpi global system notify handler.
We only support battery device for now.
http://bugzilla.kernel.org/show_bug.cgi?id=2884
Signed-off-by Zhang Rui <[email protected]>
--- drivers/acpi/bus.c | 58 +++++++++++++++++++++- drivers/acpi/scan.c | 123 +++++++++++++++++++++++++++++++++++++++++++----- include/acpi/acpi_bus.h | 2 3 files changed, 168 insertions(+), 15 deletions(-)
drivers/acpi/scan.c +112 -11
@@ -86,22 +86,53 @@ acpi_device_modalias_show(struct device } static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); -static int acpi_eject_operation (acpi_handle handle,int lockable) +static acpi_status +acpi_bus_insert_device (acpi_handle handle) +{ +struct acpi_object_list arg_list; +union acpi_object arg; +acpi_status status; + + arg_list.count =1 ; + arg_list.pointer = &arg; + arg.type =ACPI_TYPE_INTEGER ; + arg.integer.value =1 ; + status =acpi_evaluate_object (handle,"_LCK" , &arg_list,NULL ); +if (ACPI_FAILURE (status) && status !=AE_NOT_FOUND ) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN , +"Locking device failed\n" )); + +/* power on device */ + status =acpi_evaluate_object (handle,"_PS0" ,NULL ,NULL ); +if (ACPI_FAILURE (status) && status !=AE_NOT_FOUND ) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN , +"Power-on device failed\n" )); + +return AE_OK ; +} + +static acpi_status +acpi_bus_eject_device (acpi_handle handle,int lockable) {struct acpi_object_list arg_list;union acpi_object arg;acpi_status status =AE_OK ; -/* -* TBD: evaluate _PS3? -*/ +/* power off device */ + status =acpi_evaluate_object (handle,"_PS3" ,NULL ,NULL ); +if (ACPI_FAILURE (status) && status !=AE_NOT_FOUND ) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN , +"Power-off device failed\n" ));if (lockable) { arg_list.count =1 ; arg_list.pointer = &arg; arg.type =ACPI_TYPE_INTEGER ; arg.integer.value =0 ; -acpi_evaluate_object (handle,"_LCK" , &arg_list,NULL ); + status =acpi_evaluate_object (handle,"_LCK" , &arg_list,NULL ); +if (ACPI_FAILURE (status)) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN , +"Unlocking device failed\n" )); } arg_list.count =1 ;
@@ -112,13 +143,12 @@ static int acpi_eject_operation(acpi_han/* * TBD: _EJD support. */ - status =acpi_evaluate_object (handle,"_EJ0" , &arg_list,NULL ); -if (ACPI_FAILURE (status)) { -return (-ENODEV ); - } +if (ACPI_FAILURE (status) && status !=AE_NOT_FOUND ) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN , +"Ejecting device failed\n" )); -return (0 ); +return 0 ; } static ssize_t
@@ -154,7 +184,7 @@ acpi_eject_store(struct device *d, struc result =acpi_bus_trim (acpi_device,1 );if (!result) - result =acpi_eject_operation (handle, islockable); + result =acpi_bus_eject_device (handle, islockable);if (result) { ret = -EBUSY ;
@@ -493,6 +523,72 @@ static void acpi_device_unregister(strucdevice_unregister (&device->dev); } +void acpi_bus_hot_insert_device (void *context) +{ +acpi_handle handle = context; +acpi_handle phandle; +struct acpi_device *pdev =NULL ; +struct acpi_device *device =NULL ; +struct acpi_device_status sta; + +ACPI_DEBUG_PRINT ((ACPI_DB_INFO , +"Hot-inserting device...\n" )); + +if (acpi_evaluate_integer (handle,"_STA" ,NULL , + (unsigned long *)&sta) || + !sta.present) +return ; + +if (acpi_get_parent (handle, &phandle)) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Can't get device's parent\n" )); +return ; + } + +if (acpi_bus_get_device (phandle, &pdev)) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Device's parrent isn't present\n" )); +return ; + } + +acpi_bus_insert_device (handle); + +if (acpi_bus_add (&device, pdev, handle,ACPI_BUS_TYPE_DEVICE )) +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Hot-inserting device failed\n" )); + +return ; +} +EXPORT_SYMBOL (acpi_bus_hot_insert_device); + +void acpi_bus_hot_remove_device (void *context) +{ +struct acpi_device *device; +acpi_handle handle = context; +int lockable; + +if (acpi_bus_get_device (handle, &device)) +return ; + +if (!device) +return ; + +ACPI_DEBUG_PRINT ((ACPI_DB_INFO , +"Hot-removing device %s...\n" , device->dev.bus_id)); + + lockable = device->flags.lockable; + +if (acpi_bus_trim (device,1 )) { +ACPI_DEBUG_PRINT ((ACPI_DB_ERROR , +"Removing device failed\n" )); +return ; + } + +acpi_bus_eject_device (handle, lockable); + +return ; +} +EXPORT_SYMBOL (acpi_bus_hot_remove_device);/* -------------------------------------------------------------------------- Driver Management -------------------------------------------------------------------------- */
@@ -1399,6 +1495,11 @@ int acpi_bus_trim(struct acpi_device *stif (ACPI_FAILURE (status)) {continue ; } + +if (type !=ACPI_TYPE_DEVICE && type !=ACPI_TYPE_PROCESSOR + && type !=ACPI_TYPE_THERMAL && type !=ACPI_TYPE_POWER ) +continue ; +/* * If there is a device corresponding to chandle then * parse it (depth-first).
include/acpi/acpi_bus.h +2 -0
@@ -337,6 +337,8 @@ int acpi_bus_receive_event(struct acpi_bstatic inline int acpi_bus_generate_proc_event (struct acpi_device *device,u8 type,int data) {return 0 ; }#endif +void acpi_bus_hot_insert_device (void *); +void acpi_bus_hot_remove_device (void *);int acpi_bus_register_driver (struct acpi_driver *driver);void acpi_bus_unregister_driver (struct acpi_driver *driver); int acpi_bus_add(struct acpi_device **child, struct acpi_device *parent,
drivers/acpi/bus.c +54 -4
94 lines not on this page · raw message