Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_power.c - ACPI Bus Power Management ($Revision: 39 $) |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 6 | * |
| 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or (at |
| 12 | * your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 | * |
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * ACPI power-managed devices may be controlled in two ways: |
| 28 | * 1. via "Device Specific (D-State) Control" |
| 29 | * 2. via "Power Resource Control". |
| 30 | * This module is used to manage devices relying on Power Resource Control. |
| 31 | * |
| 32 | * An ACPI "power resource object" describes a software controllable power |
| 33 | * plane, clock plane, or other resource used by a power managed device. |
| 34 | * A device may rely on multiple power resources, and a power resource |
| 35 | * may be shared by multiple devices. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/kernel.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/types.h> |
| 42 | #include <linux/proc_fs.h> |
| 43 | #include <linux/seq_file.h> |
| 44 | #include <acpi/acpi_bus.h> |
| 45 | #include <acpi/acpi_drivers.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define _COMPONENT ACPI_POWER_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | ACPI_MODULE_NAME("acpi_power") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define ACPI_POWER_COMPONENT 0x00800000 |
| 50 | #define ACPI_POWER_CLASS "power_resource" |
| 51 | #define ACPI_POWER_DRIVER_NAME "ACPI Power Resource Driver" |
| 52 | #define ACPI_POWER_DEVICE_NAME "Power Resource" |
| 53 | #define ACPI_POWER_FILE_INFO "info" |
| 54 | #define ACPI_POWER_FILE_STATUS "state" |
| 55 | #define ACPI_POWER_RESOURCE_STATE_OFF 0x00 |
| 56 | #define ACPI_POWER_RESOURCE_STATE_ON 0x01 |
| 57 | #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | static int acpi_power_add(struct acpi_device *device); |
| 59 | static int acpi_power_remove(struct acpi_device *device, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int acpi_power_open_fs(struct inode *inode, struct file *file); |
| 61 | |
| 62 | static struct acpi_driver acpi_power_driver = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | .name = ACPI_POWER_DRIVER_NAME, |
| 64 | .class = ACPI_POWER_CLASS, |
| 65 | .ids = ACPI_POWER_HID, |
| 66 | .ops = { |
| 67 | .add = acpi_power_add, |
| 68 | .remove = acpi_power_remove, |
| 69 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | struct acpi_power_resource { |
| 73 | acpi_handle handle; |
Patrick Mochel | 4159857 | 2006-05-19 16:54:40 -0400 | [diff] [blame^] | 74 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | acpi_bus_id name; |
| 76 | u32 system_level; |
| 77 | u32 order; |
| 78 | int state; |
| 79 | int references; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | static struct list_head acpi_power_resource_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | static struct file_operations acpi_power_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | .open = acpi_power_open_fs, |
| 86 | .read = seq_read, |
| 87 | .llseek = seq_lseek, |
| 88 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /* -------------------------------------------------------------------------- |
| 92 | Power Resource Management |
| 93 | -------------------------------------------------------------------------- */ |
| 94 | |
| 95 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | acpi_power_get_context(acpi_handle handle, |
| 97 | struct acpi_power_resource **resource) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | int result = 0; |
| 100 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 104 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | result = acpi_bus_get_device(handle, &device); |
| 107 | if (result) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 108 | printk(KERN_WARNING PREFIX "Getting context [%p]\n", handle); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 109 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | *resource = (struct acpi_power_resource *)acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 114 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 116 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | static int acpi_power_get_state(struct acpi_power_resource *resource) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | acpi_status status = AE_OK; |
| 122 | unsigned long sta = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 126 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | status = acpi_evaluate_integer(resource->handle, "_STA", NULL, &sta); |
| 129 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 130 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | if (sta & 0x01) |
| 133 | resource->state = ACPI_POWER_RESOURCE_STATE_ON; |
| 134 | else |
| 135 | resource->state = ACPI_POWER_RESOURCE_STATE_OFF; |
| 136 | |
| 137 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | resource->name, resource->state ? "on" : "off")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 140 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | struct acpi_power_resource *resource = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | if (!list || !state) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 151 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | /* The state of the list is 'on' IFF all resources are 'on'. */ |
| 154 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | for (i = 0; i < list->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | result = acpi_power_get_context(list->handles[i], &resource); |
| 157 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 158 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | result = acpi_power_get_state(resource); |
| 160 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 161 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | *state = resource->state; |
| 164 | |
| 165 | if (*state != ACPI_POWER_RESOURCE_STATE_ON) |
| 166 | break; |
| 167 | } |
| 168 | |
| 169 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource list is %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | *state ? "on" : "off")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 172 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | static int acpi_power_on(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | int result = 0; |
| 178 | acpi_status status = AE_OK; |
| 179 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | struct acpi_power_resource *resource = NULL; |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | result = acpi_power_get_context(handle, &resource); |
| 184 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 185 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | resource->references++; |
| 188 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | if ((resource->references > 1) |
| 190 | || (resource->state == ACPI_POWER_RESOURCE_STATE_ON)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | resource->name)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | status = acpi_evaluate_object(resource->handle, "_ON", NULL, NULL); |
| 197 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 198 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | result = acpi_power_get_state(resource); |
| 201 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 202 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (resource->state != ACPI_POWER_RESOURCE_STATE_ON) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 204 | return -ENOEXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | /* Update the power resource's _device_ power state */ |
Patrick Mochel | 4159857 | 2006-05-19 16:54:40 -0400 | [diff] [blame^] | 207 | device = resource->device; |
| 208 | resource->device->power.state = ACPI_STATE_D0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | resource->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | static int acpi_power_off_device(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | int result = 0; |
| 219 | acpi_status status = AE_OK; |
| 220 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | struct acpi_power_resource *resource = NULL; |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | result = acpi_power_get_context(handle, &resource); |
| 225 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 226 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (resource->references) |
| 229 | resource->references--; |
| 230 | |
| 231 | if (resource->references) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 233 | "Resource [%s] is still in use, dereferencing\n", |
| 234 | device->pnp.bus_id)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 235 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { |
| 239 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | device->pnp.bus_id)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 241 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | status = acpi_evaluate_object(resource->handle, "_OFF", NULL, NULL); |
| 245 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 246 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | result = acpi_power_get_state(resource); |
| 249 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 250 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 252 | return -ENOEXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | /* Update the power resource's _device_ power state */ |
Patrick Mochel | 4159857 | 2006-05-19 16:54:40 -0400 | [diff] [blame^] | 255 | device = resource->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | device->power.state = ACPI_STATE_D3; |
| 257 | |
| 258 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned off\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | resource->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 261 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* |
| 265 | * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): |
| 266 | * 1. Power on the power resources required for the wakeup device |
| 267 | * 2. Enable _PSW (power state wake) for the device if present |
| 268 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | int acpi_enable_wakeup_device_power(struct acpi_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | union acpi_object arg = { ACPI_TYPE_INTEGER }; |
| 272 | struct acpi_object_list arg_list = { 1, &arg }; |
| 273 | acpi_status status = AE_OK; |
| 274 | int i; |
| 275 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | if (!dev || !dev->wakeup.flags.valid) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 278 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | arg.integer.value = 1; |
| 281 | /* Open power resource */ |
| 282 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
| 283 | ret = acpi_power_on(dev->wakeup.resources.handles[i]); |
| 284 | if (ret) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 285 | printk(KERN_ERR PREFIX "Transition power state\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | dev->wakeup.flags.valid = 0; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 287 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | /* Execute PSW */ |
| 292 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); |
| 293 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 294 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | dev->wakeup.flags.valid = 0; |
| 296 | ret = -1; |
| 297 | } |
| 298 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 299 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Shutdown a wakeup device, counterpart of above method |
| 304 | * 1. Disable _PSW (power state wake) |
| 305 | * 2. Shutdown down the power resources |
| 306 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | union acpi_object arg = { ACPI_TYPE_INTEGER }; |
| 310 | struct acpi_object_list arg_list = { 1, &arg }; |
| 311 | acpi_status status = AE_OK; |
| 312 | int i; |
| 313 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | if (!dev || !dev->wakeup.flags.valid) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 317 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | arg.integer.value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* Execute PSW */ |
| 321 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); |
| 322 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 323 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | dev->wakeup.flags.valid = 0; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 325 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* Close power resource */ |
| 329 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
| 330 | ret = acpi_power_off_device(dev->wakeup.resources.handles[i]); |
| 331 | if (ret) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 332 | printk(KERN_ERR PREFIX "Transition power state\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | dev->wakeup.flags.valid = 0; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 334 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 338 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | /* -------------------------------------------------------------------------- |
| 342 | Device Power Management |
| 343 | -------------------------------------------------------------------------- */ |
| 344 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | int acpi_power_get_inferred_state(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | int result = 0; |
| 348 | struct acpi_handle_list *list = NULL; |
| 349 | int list_state = 0; |
| 350 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 354 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | device->power.state = ACPI_STATE_UNKNOWN; |
| 357 | |
| 358 | /* |
| 359 | * We know a device's inferred power state when all the resources |
| 360 | * required for a given D-state are 'on'. |
| 361 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | for (i = ACPI_STATE_D0; i < ACPI_STATE_D3; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | list = &device->power.states[i].resources; |
| 364 | if (list->count < 1) |
| 365 | continue; |
| 366 | |
| 367 | result = acpi_power_get_list_state(list, &list_state); |
| 368 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 369 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | if (list_state == ACPI_POWER_RESOURCE_STATE_ON) { |
| 372 | device->power.state = i; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 373 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
| 377 | device->power.state = ACPI_STATE_D3; |
| 378 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 379 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | int acpi_power_transition(struct acpi_device *device, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 384 | int result = 0; |
| 385 | struct acpi_handle_list *cl = NULL; /* Current Resources */ |
| 386 | struct acpi_handle_list *tl = NULL; /* Target Resources */ |
| 387 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 391 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 393 | if ((device->power.state < ACPI_STATE_D0) |
| 394 | || (device->power.state > ACPI_STATE_D3)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 395 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | cl = &device->power.states[device->power.state].resources; |
| 398 | tl = &device->power.states[state].resources; |
| 399 | |
| 400 | device->power.state = ACPI_STATE_UNKNOWN; |
| 401 | |
| 402 | if (!cl->count && !tl->count) { |
| 403 | result = -ENODEV; |
| 404 | goto end; |
| 405 | } |
| 406 | |
| 407 | /* TBD: Resources must be ordered. */ |
| 408 | |
| 409 | /* |
| 410 | * First we reference all power resources required in the target list |
| 411 | * (e.g. so the device doesn't lose power while transitioning). |
| 412 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | for (i = 0; i < tl->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | result = acpi_power_on(tl->handles[i]); |
| 415 | if (result) |
| 416 | goto end; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Then we dereference all power resources used in the current list. |
| 421 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | for (i = 0; i < cl->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | result = acpi_power_off_device(cl->handles[i]); |
| 424 | if (result) |
| 425 | goto end; |
| 426 | } |
| 427 | |
| 428 | /* We shouldn't change the state till all above operations succeed */ |
| 429 | device->power.state = state; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | if (result) |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 432 | printk(KERN_WARNING PREFIX "Transitioning device [%s] to D%d\n", |
| 433 | device->pnp.bus_id, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 435 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* -------------------------------------------------------------------------- |
| 439 | FS Interface (/proc) |
| 440 | -------------------------------------------------------------------------- */ |
| 441 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | static struct proc_dir_entry *acpi_power_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | static int acpi_power_seq_show(struct seq_file *seq, void *offset) |
| 445 | { |
| 446 | struct acpi_power_resource *resource = NULL; |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | resource = (struct acpi_power_resource *)seq->private; |
| 450 | |
| 451 | if (!resource) |
| 452 | goto end; |
| 453 | |
| 454 | seq_puts(seq, "state: "); |
| 455 | switch (resource->state) { |
| 456 | case ACPI_POWER_RESOURCE_STATE_ON: |
| 457 | seq_puts(seq, "on\n"); |
| 458 | break; |
| 459 | case ACPI_POWER_RESOURCE_STATE_OFF: |
| 460 | seq_puts(seq, "off\n"); |
| 461 | break; |
| 462 | default: |
| 463 | seq_puts(seq, "unknown\n"); |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | seq_printf(seq, "system level: S%d\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | "order: %d\n" |
| 469 | "reference count: %d\n", |
| 470 | resource->system_level, |
| 471 | resource->order, resource->references); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 474 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static int acpi_power_open_fs(struct inode *inode, struct file *file) |
| 478 | { |
| 479 | return single_open(file, acpi_power_seq_show, PDE(inode)->data); |
| 480 | } |
| 481 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | static int acpi_power_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 488 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | if (!acpi_device_dir(device)) { |
| 491 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | acpi_power_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 494 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* 'status' [R] */ |
| 498 | entry = create_proc_entry(ACPI_POWER_FILE_STATUS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 499 | S_IRUGO, acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 501 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | else { |
| 503 | entry->proc_fops = &acpi_power_fops; |
| 504 | entry->data = acpi_driver_data(device); |
| 505 | } |
| 506 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 507 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | static int acpi_power_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | if (acpi_device_dir(device)) { |
| 514 | remove_proc_entry(ACPI_POWER_FILE_STATUS, |
| 515 | acpi_device_dir(device)); |
| 516 | remove_proc_entry(acpi_device_bid(device), acpi_power_dir); |
| 517 | acpi_device_dir(device) = NULL; |
| 518 | } |
| 519 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 520 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* -------------------------------------------------------------------------- |
| 524 | Driver Interface |
| 525 | -------------------------------------------------------------------------- */ |
| 526 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | static int acpi_power_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | int result = 0; |
| 530 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | struct acpi_power_resource *resource = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | union acpi_object acpi_object; |
| 533 | struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 537 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | resource = kmalloc(sizeof(struct acpi_power_resource), GFP_KERNEL); |
| 540 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 541 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | memset(resource, 0, sizeof(struct acpi_power_resource)); |
| 543 | |
| 544 | resource->handle = device->handle; |
Patrick Mochel | 4159857 | 2006-05-19 16:54:40 -0400 | [diff] [blame^] | 545 | resource->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | strcpy(resource->name, device->pnp.bus_id); |
| 547 | strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); |
| 548 | strcpy(acpi_device_class(device), ACPI_POWER_CLASS); |
| 549 | acpi_driver_data(device) = resource; |
| 550 | |
| 551 | /* Evalute the object to get the system level and resource order. */ |
| 552 | status = acpi_evaluate_object(resource->handle, NULL, NULL, &buffer); |
| 553 | if (ACPI_FAILURE(status)) { |
| 554 | result = -ENODEV; |
| 555 | goto end; |
| 556 | } |
| 557 | resource->system_level = acpi_object.power_resource.system_level; |
| 558 | resource->order = acpi_object.power_resource.resource_order; |
| 559 | |
| 560 | result = acpi_power_get_state(resource); |
| 561 | if (result) |
| 562 | goto end; |
| 563 | |
| 564 | switch (resource->state) { |
| 565 | case ACPI_POWER_RESOURCE_STATE_ON: |
| 566 | device->power.state = ACPI_STATE_D0; |
| 567 | break; |
| 568 | case ACPI_POWER_RESOURCE_STATE_OFF: |
| 569 | device->power.state = ACPI_STATE_D3; |
| 570 | break; |
| 571 | default: |
| 572 | device->power.state = ACPI_STATE_UNKNOWN; |
| 573 | break; |
| 574 | } |
| 575 | |
| 576 | result = acpi_power_add_fs(device); |
| 577 | if (result) |
| 578 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 580 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), |
| 581 | acpi_device_bid(device), resource->state ? "on" : "off"); |
| 582 | |
| 583 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | if (result) |
| 585 | kfree(resource); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 587 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 590 | static int acpi_power_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
| 592 | struct acpi_power_resource *resource = NULL; |
| 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 596 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 598 | resource = (struct acpi_power_resource *)acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | acpi_power_remove_fs(device); |
| 601 | |
| 602 | kfree(resource); |
| 603 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 604 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | static int __init acpi_power_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 609 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 613 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | INIT_LIST_HEAD(&acpi_power_resource_list); |
| 616 | |
| 617 | acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir); |
| 618 | if (!acpi_power_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 619 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | result = acpi_bus_register_driver(&acpi_power_driver); |
| 622 | if (result < 0) { |
| 623 | remove_proc_entry(ACPI_POWER_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 624 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 627 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | subsys_initcall(acpi_power_init); |