Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_button.c - ACPI Button Driver ($Revision: 30 $) |
| 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 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 29 | #include <linux/types.h> |
| 30 | #include <linux/proc_fs.h> |
| 31 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <acpi/acpi_bus.h> |
| 33 | #include <acpi/acpi_drivers.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define ACPI_BUTTON_COMPONENT 0x00080000 |
| 36 | #define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver" |
| 37 | #define ACPI_BUTTON_CLASS "button" |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 38 | #define ACPI_BUTTON_FILE_INFO "info" |
| 39 | #define ACPI_BUTTON_FILE_STATE "state" |
| 40 | #define ACPI_BUTTON_TYPE_UNKNOWN 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define ACPI_BUTTON_NOTIFY_STATUS 0x80 |
| 42 | |
| 43 | #define ACPI_BUTTON_SUBCLASS_POWER "power" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 44 | #define ACPI_BUTTON_HID_POWER "PNP0C0C" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button (CM)" |
| 46 | #define ACPI_BUTTON_DEVICE_NAME_POWERF "Power Button (FF)" |
| 47 | #define ACPI_BUTTON_TYPE_POWER 0x01 |
| 48 | #define ACPI_BUTTON_TYPE_POWERF 0x02 |
| 49 | |
| 50 | #define ACPI_BUTTON_SUBCLASS_SLEEP "sleep" |
| 51 | #define ACPI_BUTTON_HID_SLEEP "PNP0C0E" |
| 52 | #define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button (CM)" |
| 53 | #define ACPI_BUTTON_DEVICE_NAME_SLEEPF "Sleep Button (FF)" |
| 54 | #define ACPI_BUTTON_TYPE_SLEEP 0x03 |
| 55 | #define ACPI_BUTTON_TYPE_SLEEPF 0x04 |
| 56 | |
| 57 | #define ACPI_BUTTON_SUBCLASS_LID "lid" |
| 58 | #define ACPI_BUTTON_HID_LID "PNP0C0D" |
| 59 | #define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch" |
| 60 | #define ACPI_BUTTON_TYPE_LID 0x05 |
| 61 | |
| 62 | #define _COMPONENT ACPI_BUTTON_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | ACPI_MODULE_NAME("acpi_button") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); |
| 67 | MODULE_LICENSE("GPL"); |
| 68 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | static int acpi_button_add(struct acpi_device *device); |
| 70 | static int acpi_button_remove(struct acpi_device *device, int type); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 71 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); |
| 72 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | static struct acpi_driver acpi_button_driver = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | .name = ACPI_BUTTON_DRIVER_NAME, |
| 76 | .class = ACPI_BUTTON_CLASS, |
| 77 | .ids = "ACPI_FPB,ACPI_FSB,PNP0C0D,PNP0C0C,PNP0C0E", |
| 78 | .ops = { |
| 79 | .add = acpi_button_add, |
| 80 | .remove = acpi_button_remove, |
| 81 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct acpi_button { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | acpi_handle handle; |
| 86 | struct acpi_device *device; /* Fixed button kludge */ |
| 87 | u8 type; |
| 88 | unsigned long pushed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 91 | static struct file_operations acpi_button_info_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | .open = acpi_button_info_open_fs, |
| 93 | .read = seq_read, |
| 94 | .llseek = seq_lseek, |
| 95 | .release = single_release, |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static struct file_operations acpi_button_state_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | .open = acpi_button_state_open_fs, |
| 100 | .read = seq_read, |
| 101 | .llseek = seq_lseek, |
| 102 | .release = single_release, |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 103 | }; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 105 | /* -------------------------------------------------------------------------- |
| 106 | FS Interface (/proc) |
| 107 | -------------------------------------------------------------------------- */ |
| 108 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | static struct proc_dir_entry *acpi_button_dir; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 110 | |
| 111 | static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) |
| 112 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | struct acpi_button *button = (struct acpi_button *)seq->private; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 114 | |
| 115 | ACPI_FUNCTION_TRACE("acpi_button_info_seq_show"); |
| 116 | |
| 117 | if (!button || !button->device) |
| 118 | return_VALUE(0); |
| 119 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | seq_printf(seq, "type: %s\n", |
| 121 | acpi_device_name(button->device)); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 122 | |
| 123 | return_VALUE(0); |
| 124 | } |
| 125 | |
| 126 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file) |
| 127 | { |
| 128 | return single_open(file, acpi_button_info_seq_show, PDE(inode)->data); |
| 129 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 131 | static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) |
| 132 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | struct acpi_button *button = (struct acpi_button *)seq->private; |
| 134 | acpi_status status; |
| 135 | unsigned long state; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 136 | |
| 137 | ACPI_FUNCTION_TRACE("acpi_button_state_seq_show"); |
| 138 | |
| 139 | if (!button || !button->device) |
| 140 | return_VALUE(0); |
| 141 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 143 | if (ACPI_FAILURE(status)) { |
| 144 | seq_printf(seq, "state: unsupported\n"); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | } else { |
| 146 | seq_printf(seq, "state: %s\n", |
| 147 | (state ? "open" : "closed")); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | return_VALUE(0); |
| 151 | } |
| 152 | |
| 153 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file) |
| 154 | { |
| 155 | return single_open(file, acpi_button_state_seq_show, PDE(inode)->data); |
| 156 | } |
| 157 | |
| 158 | static struct proc_dir_entry *acpi_power_dir; |
| 159 | static struct proc_dir_entry *acpi_sleep_dir; |
| 160 | static struct proc_dir_entry *acpi_lid_dir; |
| 161 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | static int acpi_button_add_fs(struct acpi_device *device) |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 163 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | struct proc_dir_entry *entry = NULL; |
| 165 | struct acpi_button *button = NULL; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 166 | |
| 167 | ACPI_FUNCTION_TRACE("acpi_button_add_fs"); |
| 168 | |
| 169 | if (!device || !acpi_driver_data(device)) |
| 170 | return_VALUE(-EINVAL); |
| 171 | |
| 172 | button = acpi_driver_data(device); |
| 173 | |
| 174 | switch (button->type) { |
| 175 | case ACPI_BUTTON_TYPE_POWER: |
| 176 | case ACPI_BUTTON_TYPE_POWERF: |
| 177 | if (!acpi_power_dir) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER, |
| 179 | acpi_button_dir); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 180 | entry = acpi_power_dir; |
| 181 | break; |
| 182 | case ACPI_BUTTON_TYPE_SLEEP: |
| 183 | case ACPI_BUTTON_TYPE_SLEEPF: |
| 184 | if (!acpi_sleep_dir) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP, |
| 186 | acpi_button_dir); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 187 | entry = acpi_sleep_dir; |
| 188 | break; |
| 189 | case ACPI_BUTTON_TYPE_LID: |
| 190 | if (!acpi_lid_dir) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID, |
| 192 | acpi_button_dir); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 193 | entry = acpi_lid_dir; |
| 194 | break; |
| 195 | } |
| 196 | |
| 197 | if (!entry) |
| 198 | return_VALUE(-ENODEV); |
| 199 | entry->owner = THIS_MODULE; |
| 200 | |
| 201 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); |
| 202 | if (!acpi_device_dir(device)) |
| 203 | return_VALUE(-ENODEV); |
| 204 | acpi_device_dir(device)->owner = THIS_MODULE; |
| 205 | |
| 206 | /* 'info' [R] */ |
| 207 | entry = create_proc_entry(ACPI_BUTTON_FILE_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | S_IRUGO, acpi_device_dir(device)); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 209 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame^] | 210 | return_VALUE(-ENODEV); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 211 | else { |
| 212 | entry->proc_fops = &acpi_button_info_fops; |
| 213 | entry->data = acpi_driver_data(device); |
| 214 | entry->owner = THIS_MODULE; |
| 215 | } |
| 216 | |
| 217 | /* show lid state [R] */ |
| 218 | if (button->type == ACPI_BUTTON_TYPE_LID) { |
| 219 | entry = create_proc_entry(ACPI_BUTTON_FILE_STATE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | S_IRUGO, acpi_device_dir(device)); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 221 | if (!entry) |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame^] | 222 | return -ENODEV; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 223 | else { |
| 224 | entry->proc_fops = &acpi_button_state_fops; |
| 225 | entry->data = acpi_driver_data(device); |
| 226 | entry->owner = THIS_MODULE; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return_VALUE(0); |
| 231 | } |
| 232 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | static int acpi_button_remove_fs(struct acpi_device *device) |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 234 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | struct acpi_button *button = NULL; |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 236 | |
| 237 | ACPI_FUNCTION_TRACE("acpi_button_remove_fs"); |
| 238 | |
| 239 | button = acpi_driver_data(device); |
| 240 | if (acpi_device_dir(device)) { |
| 241 | if (button->type == ACPI_BUTTON_TYPE_LID) |
| 242 | remove_proc_entry(ACPI_BUTTON_FILE_STATE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | acpi_device_dir(device)); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 244 | remove_proc_entry(ACPI_BUTTON_FILE_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | acpi_device_dir(device)); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 246 | |
| 247 | remove_proc_entry(acpi_device_bid(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_device_dir(device)->parent); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 249 | acpi_device_dir(device) = NULL; |
| 250 | } |
| 251 | |
| 252 | return_VALUE(0); |
| 253 | } |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* -------------------------------------------------------------------------- |
| 256 | Driver Interface |
| 257 | -------------------------------------------------------------------------- */ |
| 258 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 261 | struct acpi_button *button = (struct acpi_button *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | ACPI_FUNCTION_TRACE("acpi_button_notify"); |
| 264 | |
| 265 | if (!button || !button->device) |
| 266 | return_VOID; |
| 267 | |
| 268 | switch (event) { |
| 269 | case ACPI_BUTTON_NOTIFY_STATUS: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | acpi_bus_generate_event(button->device, event, |
| 271 | ++button->pushed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | break; |
| 273 | default: |
| 274 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | |
| 279 | return_VOID; |
| 280 | } |
| 281 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | static acpi_status acpi_button_notify_fixed(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | struct acpi_button *button = (struct acpi_button *)data; |
| 285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | ACPI_FUNCTION_TRACE("acpi_button_notify_fixed"); |
| 287 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 288 | if (!button) |
| 289 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); |
| 292 | |
| 293 | return_ACPI_STATUS(AE_OK); |
| 294 | } |
| 295 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | static int acpi_button_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | int result = 0; |
| 299 | acpi_status status = AE_OK; |
| 300 | struct acpi_button *button = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | ACPI_FUNCTION_TRACE("acpi_button_add"); |
| 303 | |
| 304 | if (!device) |
| 305 | return_VALUE(-EINVAL); |
| 306 | |
| 307 | button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); |
| 308 | if (!button) |
| 309 | return_VALUE(-ENOMEM); |
| 310 | memset(button, 0, sizeof(struct acpi_button)); |
| 311 | |
| 312 | button->device = device; |
| 313 | button->handle = device->handle; |
| 314 | acpi_driver_data(device) = button; |
| 315 | |
| 316 | /* |
| 317 | * Determine the button type (via hid), as fixed-feature buttons |
| 318 | * need to be handled a bit differently than generic-space. |
| 319 | */ |
| 320 | if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWER)) { |
| 321 | button->type = ACPI_BUTTON_TYPE_POWER; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER); |
| 323 | sprintf(acpi_device_class(device), "%s/%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | button->type = ACPI_BUTTON_TYPE_POWERF; |
| 327 | strcpy(acpi_device_name(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 328 | ACPI_BUTTON_DEVICE_NAME_POWERF); |
| 329 | sprintf(acpi_device_class(device), "%s/%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 331 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | button->type = ACPI_BUTTON_TYPE_SLEEP; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP); |
| 334 | sprintf(acpi_device_class(device), "%s/%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | button->type = ACPI_BUTTON_TYPE_SLEEPF; |
| 338 | strcpy(acpi_device_name(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | ACPI_BUTTON_DEVICE_NAME_SLEEPF); |
| 340 | sprintf(acpi_device_class(device), "%s/%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_LID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | button->type = ACPI_BUTTON_TYPE_LID; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID); |
| 345 | sprintf(acpi_device_class(device), "%s/%s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | } else { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame^] | 348 | ACPI_ERROR((AE_INFO, "Unsupported hid [%s]", |
| 349 | acpi_device_hid(device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | result = -ENODEV; |
| 351 | goto end; |
| 352 | } |
| 353 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 354 | result = acpi_button_add_fs(device); |
| 355 | if (result) |
| 356 | goto end; |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | switch (button->type) { |
| 359 | case ACPI_BUTTON_TYPE_POWERF: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | status = |
| 361 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, |
| 362 | acpi_button_notify_fixed, |
| 363 | button); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | break; |
| 365 | case ACPI_BUTTON_TYPE_SLEEPF: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | status = |
| 367 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, |
| 368 | acpi_button_notify_fixed, |
| 369 | button); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | break; |
| 371 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | status = acpi_install_notify_handler(button->handle, |
| 373 | ACPI_DEVICE_NOTIFY, |
| 374 | acpi_button_notify, |
| 375 | button); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | break; |
| 377 | } |
| 378 | |
| 379 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | result = -ENODEV; |
| 381 | goto end; |
| 382 | } |
| 383 | |
| 384 | if (device->wakeup.flags.valid) { |
| 385 | /* Button's GPE is run-wake GPE */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | acpi_set_gpe_type(device->wakeup.gpe_device, |
| 387 | device->wakeup.gpe_number, |
| 388 | ACPI_GPE_TYPE_WAKE_RUN); |
| 389 | acpi_enable_gpe(device->wakeup.gpe_device, |
| 390 | device->wakeup.gpe_number, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | device->wakeup.state.enabled = 1; |
| 392 | } |
| 393 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | printk(KERN_INFO PREFIX "%s [%s]\n", |
| 395 | acpi_device_name(device), acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (result) { |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 399 | acpi_button_remove_fs(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | kfree(button); |
| 401 | } |
| 402 | |
| 403 | return_VALUE(result); |
| 404 | } |
| 405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | static int acpi_button_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | acpi_status status = 0; |
| 409 | struct acpi_button *button = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | ACPI_FUNCTION_TRACE("acpi_button_remove"); |
| 412 | |
| 413 | if (!device || !acpi_driver_data(device)) |
| 414 | return_VALUE(-EINVAL); |
| 415 | |
| 416 | button = acpi_driver_data(device); |
| 417 | |
| 418 | /* Unregister for device notifications. */ |
| 419 | switch (button->type) { |
| 420 | case ACPI_BUTTON_TYPE_POWERF: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 421 | status = |
| 422 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, |
| 423 | acpi_button_notify_fixed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | break; |
| 425 | case ACPI_BUTTON_TYPE_SLEEPF: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | status = |
| 427 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, |
| 428 | acpi_button_notify_fixed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | break; |
| 430 | default: |
| 431 | status = acpi_remove_notify_handler(button->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | ACPI_DEVICE_NOTIFY, |
| 433 | acpi_button_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | break; |
| 435 | } |
| 436 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | acpi_button_remove_fs(device); |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | kfree(button); |
| 440 | |
| 441 | return_VALUE(0); |
| 442 | } |
| 443 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | static int __init acpi_button_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | ACPI_FUNCTION_TRACE("acpi_button_init"); |
| 449 | |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 450 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); |
| 451 | if (!acpi_button_dir) |
| 452 | return_VALUE(-ENODEV); |
| 453 | acpi_button_dir->owner = THIS_MODULE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | result = acpi_bus_register_driver(&acpi_button_driver); |
| 455 | if (result < 0) { |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 456 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return_VALUE(-ENODEV); |
| 458 | } |
| 459 | |
| 460 | return_VALUE(0); |
| 461 | } |
| 462 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | static void __exit acpi_button_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
| 465 | ACPI_FUNCTION_TRACE("acpi_button_exit"); |
| 466 | |
| 467 | acpi_bus_unregister_driver(&acpi_button_driver); |
| 468 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | if (acpi_power_dir) |
Alexey Starikovskiy | b34a803 | 2005-08-03 17:55:21 -0400 | [diff] [blame] | 470 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER, acpi_button_dir); |
| 471 | if (acpi_sleep_dir) |
| 472 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP, acpi_button_dir); |
| 473 | if (acpi_lid_dir) |
| 474 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); |
| 475 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return_VOID; |
| 478 | } |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | module_init(acpi_button_init); |
| 481 | module_exit(acpi_button_exit); |