blob: 4b6d9f0096a10cb8cdf1409f8558cff7674b1e9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Starikovskiyb34a8032005-08-03 17:55:21 -040029#include <linux/types.h>
30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define ACPI_BUTTON_COMPONENT 0x00080000
36#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
37#define ACPI_BUTTON_CLASS "button"
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -040038#define ACPI_BUTTON_FILE_INFO "info"
39#define ACPI_BUTTON_FILE_STATE "state"
40#define ACPI_BUTTON_TYPE_UNKNOWN 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define ACPI_BUTTON_NOTIFY_STATUS 0x80
42
43#define ACPI_BUTTON_SUBCLASS_POWER "power"
Len Brown4be44fc2005-08-05 00:44:28 -040044#define ACPI_BUTTON_HID_POWER "PNP0C0C"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#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 Brown4be44fc2005-08-05 00:44:28 -040063ACPI_MODULE_NAME("acpi_button")
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Len Brown4be44fc2005-08-05 00:44:28 -040065 MODULE_AUTHOR("Paul Diefenbaugh");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME);
67MODULE_LICENSE("GPL");
68
Len Brown4be44fc2005-08-05 00:44:28 -040069static int acpi_button_add(struct acpi_device *device);
70static int acpi_button_remove(struct acpi_device *device, int type);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -040071static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
72static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74static struct acpi_driver acpi_button_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -040075 .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 Torvalds1da177e2005-04-16 15:20:36 -070082};
83
84struct acpi_button {
Len Brown4be44fc2005-08-05 00:44:28 -040085 acpi_handle handle;
86 struct acpi_device *device; /* Fixed button kludge */
87 u8 type;
88 unsigned long pushed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -040091static struct file_operations acpi_button_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -040092 .open = acpi_button_info_open_fs,
93 .read = seq_read,
94 .llseek = seq_lseek,
95 .release = single_release,
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -040096};
97
98static struct file_operations acpi_button_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -040099 .open = acpi_button_state_open_fs,
100 .read = seq_read,
101 .llseek = seq_lseek,
102 .release = single_release,
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400103};
Len Brown4be44fc2005-08-05 00:44:28 -0400104
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400105/* --------------------------------------------------------------------------
106 FS Interface (/proc)
107 -------------------------------------------------------------------------- */
108
Len Brown4be44fc2005-08-05 00:44:28 -0400109static struct proc_dir_entry *acpi_button_dir;
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400110
111static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
112{
Len Brown4be44fc2005-08-05 00:44:28 -0400113 struct acpi_button *button = (struct acpi_button *)seq->private;
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400114
115 ACPI_FUNCTION_TRACE("acpi_button_info_seq_show");
116
117 if (!button || !button->device)
118 return_VALUE(0);
119
Len Brown4be44fc2005-08-05 00:44:28 -0400120 seq_printf(seq, "type: %s\n",
121 acpi_device_name(button->device));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400122
123 return_VALUE(0);
124}
125
126static 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 Brown4be44fc2005-08-05 00:44:28 -0400130
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400131static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
132{
Len Brown4be44fc2005-08-05 00:44:28 -0400133 struct acpi_button *button = (struct acpi_button *)seq->private;
134 acpi_status status;
135 unsigned long state;
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400136
137 ACPI_FUNCTION_TRACE("acpi_button_state_seq_show");
138
139 if (!button || !button->device)
140 return_VALUE(0);
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400143 if (ACPI_FAILURE(status)) {
144 seq_printf(seq, "state: unsupported\n");
Len Brown4be44fc2005-08-05 00:44:28 -0400145 } else {
146 seq_printf(seq, "state: %s\n",
147 (state ? "open" : "closed"));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400148 }
149
150 return_VALUE(0);
151}
152
153static 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
158static struct proc_dir_entry *acpi_power_dir;
159static struct proc_dir_entry *acpi_sleep_dir;
160static struct proc_dir_entry *acpi_lid_dir;
161
Len Brown4be44fc2005-08-05 00:44:28 -0400162static int acpi_button_add_fs(struct acpi_device *device)
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400163{
Len Brown4be44fc2005-08-05 00:44:28 -0400164 struct proc_dir_entry *entry = NULL;
165 struct acpi_button *button = NULL;
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400166
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 Brown4be44fc2005-08-05 00:44:28 -0400178 acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER,
179 acpi_button_dir);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400180 entry = acpi_power_dir;
181 break;
182 case ACPI_BUTTON_TYPE_SLEEP:
183 case ACPI_BUTTON_TYPE_SLEEPF:
184 if (!acpi_sleep_dir)
Len Brown4be44fc2005-08-05 00:44:28 -0400185 acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP,
186 acpi_button_dir);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400187 entry = acpi_sleep_dir;
188 break;
189 case ACPI_BUTTON_TYPE_LID:
190 if (!acpi_lid_dir)
Len Brown4be44fc2005-08-05 00:44:28 -0400191 acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID,
192 acpi_button_dir);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400193 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 Brown4be44fc2005-08-05 00:44:28 -0400208 S_IRUGO, acpi_device_dir(device));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400209 if (!entry)
210 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400211 "Unable to create '%s' fs entry\n",
212 ACPI_BUTTON_FILE_INFO));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400213 else {
214 entry->proc_fops = &acpi_button_info_fops;
215 entry->data = acpi_driver_data(device);
216 entry->owner = THIS_MODULE;
217 }
218
219 /* show lid state [R] */
220 if (button->type == ACPI_BUTTON_TYPE_LID) {
221 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE,
Len Brown4be44fc2005-08-05 00:44:28 -0400222 S_IRUGO, acpi_device_dir(device));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400223 if (!entry)
224 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400225 "Unable to create '%s' fs entry\n",
226 ACPI_BUTTON_FILE_INFO));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400227 else {
228 entry->proc_fops = &acpi_button_state_fops;
229 entry->data = acpi_driver_data(device);
230 entry->owner = THIS_MODULE;
231 }
232 }
233
234 return_VALUE(0);
235}
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_button_remove_fs(struct acpi_device *device)
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400238{
Len Brown4be44fc2005-08-05 00:44:28 -0400239 struct acpi_button *button = NULL;
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400240
241 ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
242
243 button = acpi_driver_data(device);
244 if (acpi_device_dir(device)) {
245 if (button->type == ACPI_BUTTON_TYPE_LID)
246 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
Len Brown4be44fc2005-08-05 00:44:28 -0400247 acpi_device_dir(device));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400248 remove_proc_entry(ACPI_BUTTON_FILE_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400249 acpi_device_dir(device));
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400250
251 remove_proc_entry(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400252 acpi_device_dir(device)->parent);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400253 acpi_device_dir(device) = NULL;
254 }
255
256 return_VALUE(0);
257}
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* --------------------------------------------------------------------------
260 Driver Interface
261 -------------------------------------------------------------------------- */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Len Brown4be44fc2005-08-05 00:44:28 -0400265 struct acpi_button *button = (struct acpi_button *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 ACPI_FUNCTION_TRACE("acpi_button_notify");
268
269 if (!button || !button->device)
270 return_VOID;
271
272 switch (event) {
273 case ACPI_BUTTON_NOTIFY_STATUS:
Len Brown4be44fc2005-08-05 00:44:28 -0400274 acpi_bus_generate_event(button->device, event,
275 ++button->pushed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 break;
277 default:
278 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400279 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
281 }
282
283 return_VOID;
284}
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286static acpi_status acpi_button_notify_fixed(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Len Brown4be44fc2005-08-05 00:44:28 -0400288 struct acpi_button *button = (struct acpi_button *)data;
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
291
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400292 if (!button)
293 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
296
297 return_ACPI_STATUS(AE_OK);
298}
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300static int acpi_button_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Len Brown4be44fc2005-08-05 00:44:28 -0400302 int result = 0;
303 acpi_status status = AE_OK;
304 struct acpi_button *button = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 ACPI_FUNCTION_TRACE("acpi_button_add");
307
308 if (!device)
309 return_VALUE(-EINVAL);
310
311 button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL);
312 if (!button)
313 return_VALUE(-ENOMEM);
314 memset(button, 0, sizeof(struct acpi_button));
315
316 button->device = device;
317 button->handle = device->handle;
318 acpi_driver_data(device) = button;
319
320 /*
321 * Determine the button type (via hid), as fixed-feature buttons
322 * need to be handled a bit differently than generic-space.
323 */
324 if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWER)) {
325 button->type = ACPI_BUTTON_TYPE_POWER;
Len Brown4be44fc2005-08-05 00:44:28 -0400326 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER);
327 sprintf(acpi_device_class(device), "%s/%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
Len Brown4be44fc2005-08-05 00:44:28 -0400329 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 button->type = ACPI_BUTTON_TYPE_POWERF;
331 strcpy(acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400332 ACPI_BUTTON_DEVICE_NAME_POWERF);
333 sprintf(acpi_device_class(device), "%s/%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
Len Brown4be44fc2005-08-05 00:44:28 -0400335 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 button->type = ACPI_BUTTON_TYPE_SLEEP;
Len Brown4be44fc2005-08-05 00:44:28 -0400337 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP);
338 sprintf(acpi_device_class(device), "%s/%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
Len Brown4be44fc2005-08-05 00:44:28 -0400340 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 button->type = ACPI_BUTTON_TYPE_SLEEPF;
342 strcpy(acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_BUTTON_DEVICE_NAME_SLEEPF);
344 sprintf(acpi_device_class(device), "%s/%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
Len Brown4be44fc2005-08-05 00:44:28 -0400346 } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_LID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 button->type = ACPI_BUTTON_TYPE_LID;
Len Brown4be44fc2005-08-05 00:44:28 -0400348 strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID);
349 sprintf(acpi_device_class(device), "%s/%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
Len Brown4be44fc2005-08-05 00:44:28 -0400351 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unsupported hid [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400353 acpi_device_hid(device)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 result = -ENODEV;
355 goto end;
356 }
357
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400358 result = acpi_button_add_fs(device);
359 if (result)
360 goto end;
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 switch (button->type) {
363 case ACPI_BUTTON_TYPE_POWERF:
Len Brown4be44fc2005-08-05 00:44:28 -0400364 status =
365 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
366 acpi_button_notify_fixed,
367 button);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 break;
369 case ACPI_BUTTON_TYPE_SLEEPF:
Len Brown4be44fc2005-08-05 00:44:28 -0400370 status =
371 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
372 acpi_button_notify_fixed,
373 button);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
375 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400376 status = acpi_install_notify_handler(button->handle,
377 ACPI_DEVICE_NOTIFY,
378 acpi_button_notify,
379 button);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
381 }
382
383 if (ACPI_FAILURE(status)) {
384 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400385 "Error installing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 result = -ENODEV;
387 goto end;
388 }
389
390 if (device->wakeup.flags.valid) {
391 /* Button's GPE is run-wake GPE */
Len Brown4be44fc2005-08-05 00:44:28 -0400392 acpi_set_gpe_type(device->wakeup.gpe_device,
393 device->wakeup.gpe_number,
394 ACPI_GPE_TYPE_WAKE_RUN);
395 acpi_enable_gpe(device->wakeup.gpe_device,
396 device->wakeup.gpe_number, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 device->wakeup.state.enabled = 1;
398 }
399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 printk(KERN_INFO PREFIX "%s [%s]\n",
401 acpi_device_name(device), acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (result) {
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400405 acpi_button_remove_fs(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 kfree(button);
407 }
408
409 return_VALUE(result);
410}
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412static int acpi_button_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Len Brown4be44fc2005-08-05 00:44:28 -0400414 acpi_status status = 0;
415 struct acpi_button *button = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 ACPI_FUNCTION_TRACE("acpi_button_remove");
418
419 if (!device || !acpi_driver_data(device))
420 return_VALUE(-EINVAL);
421
422 button = acpi_driver_data(device);
423
424 /* Unregister for device notifications. */
425 switch (button->type) {
426 case ACPI_BUTTON_TYPE_POWERF:
Len Brown4be44fc2005-08-05 00:44:28 -0400427 status =
428 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
429 acpi_button_notify_fixed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431 case ACPI_BUTTON_TYPE_SLEEPF:
Len Brown4be44fc2005-08-05 00:44:28 -0400432 status =
433 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
434 acpi_button_notify_fixed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 break;
436 default:
437 status = acpi_remove_notify_handler(button->handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400438 ACPI_DEVICE_NOTIFY,
439 acpi_button_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 break;
441 }
442
443 if (ACPI_FAILURE(status))
444 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -0400445 "Error removing notify handler\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Len Brown4be44fc2005-08-05 00:44:28 -0400447 acpi_button_remove_fs(device);
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 kfree(button);
450
451 return_VALUE(0);
452}
453
Len Brown4be44fc2005-08-05 00:44:28 -0400454static int __init acpi_button_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Len Brown4be44fc2005-08-05 00:44:28 -0400456 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 ACPI_FUNCTION_TRACE("acpi_button_init");
459
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400460 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
461 if (!acpi_button_dir)
462 return_VALUE(-ENODEV);
463 acpi_button_dir->owner = THIS_MODULE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 result = acpi_bus_register_driver(&acpi_button_driver);
465 if (result < 0) {
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400466 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return_VALUE(-ENODEV);
468 }
469
470 return_VALUE(0);
471}
472
Len Brown4be44fc2005-08-05 00:44:28 -0400473static void __exit acpi_button_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 ACPI_FUNCTION_TRACE("acpi_button_exit");
476
477 acpi_bus_unregister_driver(&acpi_button_driver);
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 if (acpi_power_dir)
Alexey Starikovskiyb34a8032005-08-03 17:55:21 -0400480 remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER, acpi_button_dir);
481 if (acpi_sleep_dir)
482 remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP, acpi_button_dir);
483 if (acpi_lid_dir)
484 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
485 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return_VOID;
488}
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490module_init(acpi_button_init);
491module_exit(acpi_button_exit);