ReactOS  0.4.15-dev-1377-ga59cecd
button.c
Go to the documentation of this file.
1 /*
2  * acpi_button.c - ACPI Button Driver ($Revision: 29 $)
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 <precomp.h>
27 
28 #define NDEBUG
29 #include <debug.h>
30 
31 #define _COMPONENT ACPI_BUTTON_COMPONENT
32 ACPI_MODULE_NAME ("acpi_button")
33 
34 
37 
39  {0,0},
42  0,
43  0,
44  "ACPI_FPB,ACPI_FSB,PNP0C0D,PNP0C0C,PNP0C0E",
46 };
47 
48 struct acpi_button {
50  struct acpi_device *device; /* Fixed button kludge */
52  unsigned long pushed;
53 };
54 
58 
59 /* --------------------------------------------------------------------------
60  Driver Interface
61  -------------------------------------------------------------------------- */
62 
63 void
66  UINT32 event,
67  void *data)
68 {
69  struct acpi_button *button = (struct acpi_button *) data;
70 
71  ACPI_FUNCTION_TRACE("acpi_button_notify");
72 
73  if (!button || !button->device)
75 
76  switch (event) {
78  acpi_bus_generate_event(button->device, event, ++button->pushed);
79  break;
80  default:
82  "Unsupported event [0x%x]\n", event));
83  break;
84  }
85 
87 }
88 
89 
92  void *data)
93 {
94  struct acpi_button *button = (struct acpi_button *) data;
95 
96  ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
97 
98  if (!button)
100 
102 
104 }
105 
106 
107 static int
109  struct acpi_device *device)
110 {
111  int result = 0;
113  struct acpi_button *button = NULL;
114 
115  ACPI_FUNCTION_TRACE("acpi_button_add");
116 
117  if (!device)
118  return_VALUE(-1);
119 
120  button = ExAllocatePoolWithTag(NonPagedPool,sizeof(struct acpi_button), 'IPCA');
121  if (!button)
122  return_VALUE(-4);
123  memset(button, 0, sizeof(struct acpi_button));
124 
125  button->device = device;
126  button->handle = device->handle;
128 
129  /*
130  * Determine the button type (via hid), as fixed-feature buttons
131  * need to be handled a bit differently than generic-space.
132  */
137  sprintf(acpi_device_class(device), "%s/%s",
139  }
144  sprintf(acpi_device_class(device), "%s/%s",
146  }
151  sprintf(acpi_device_class(device), "%s/%s",
153  }
158  sprintf(acpi_device_class(device), "%s/%s",
160  }
165  sprintf(acpi_device_class(device), "%s/%s",
167  }
168  else {
169  ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unsupported hid [%s]\n",
171  result = -15;
172  goto end;
173  }
174 
175  /*
176  * Ensure only one button of each type is used.
177  */
178  switch (button->type) {
181  if (!power_button)
183  else {
184  ExFreePoolWithTag(button, 'IPCA');
185  return_VALUE(-15);
186  }
187  break;
190  if (!sleep_button)
192  else {
193  ExFreePoolWithTag(button, 'IPCA');
194  return_VALUE(-15);
195  }
196  break;
198  if (!lid_button)
199  lid_button = device;
200  else {
201  ExFreePoolWithTag(button, 'IPCA');
202  return_VALUE(-15);
203  }
204  break;
205  }
206 
207  switch (button->type) {
212  button);
213  break;
218  button);
219  break;
224  button);
225  break;
226  default:
228  button->handle,
231  button);
232  break;
233  }
234 
235  if (ACPI_FAILURE(status)) {
236  ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
237  "Error installing notify handler\n"));
238  result = -15;
239  goto end;
240  }
241 
242  DPRINT("%s [%s]\n",
244 
245 end:
246  if (result) {
247  ExFreePoolWithTag(button, 'IPCA');
248  }
249 
251 }
252 
253 
254 static int
256 {
257  ACPI_STATUS status = 0;
258  struct acpi_button *button = NULL;
259 
260  ACPI_FUNCTION_TRACE("acpi_button_remove");
261 
262  if (!device || !acpi_driver_data(device))
263  return_VALUE(-1);
264 
266 
267  /* Unregister for device notifications. */
268  switch (button->type) {
272  break;
276  break;
280  break;
281  default:
284  break;
285  }
286 
287  if (ACPI_FAILURE(status))
288  ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
289  "Error removing notify handler\n"));
290 
291  ExFreePoolWithTag(button, 'IPCA');
292 
293  return_VALUE(0);
294 }
295 
296 
297 int
299 {
300  int result = 0;
301 
302  ACPI_FUNCTION_TRACE("acpi_button_init");
303 
305  if (result < 0) {
306  return_VALUE(-15);
307  }
308 
309  return_VALUE(0);
310 }
311 
312 
313 void
315 {
316  ACPI_FUNCTION_TRACE("acpi_button_exit");
317 
319 
320  return_VOID;
321 }
322 
323 
#define ACPI_BUTTON_TYPE_LID
Definition: acpi_drivers.h:108
#define ACPI_BUTTON_HID_POWERF
Definition: acpi_drivers.h:91
#define acpi_device_bid(d)
Definition: acpi_bus.h:186
void acpi_bus_unregister_driver(struct acpi_driver *driver)
Definition: bus.c:1056
ACPI_STATUS AcpiRemoveNotifyHandler(ACPI_HANDLE Device, UINT32 HandlerType, ACPI_NOTIFY_HANDLER Handler)
Definition: evxface.c:273
GLuint64EXT * result
Definition: glext.h:11304
#define return_VALUE(s)
Definition: acoutput.h:499
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
static int acpi_button_add(struct acpi_device *device)
Definition: button.c:108
void acpi_button_notify(ACPI_HANDLE handle, UINT32 event, void *data)
Definition: button.c:64
ACPI_STATUS AcpiInstallFixedEventHandler(UINT32 Event, ACPI_EVENT_HANDLER Handler, void *Context)
Definition: evxface.c:707
#define ACPI_BUTTON_DEVICE_NAME_SLEEP
Definition: acpi_drivers.h:100
struct acpi_device * sleep_button
Definition: button.c:56
DWORD button
Definition: button.c:166
void acpi_button_exit(void)
Definition: button.c:314
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_HANDLE handle
Definition: button.c:49
#define ACPI_BUTTON_TYPE_SLEEPF
Definition: acpi_drivers.h:103
FxDevice * device
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define ACPI_BUTTON_TYPE_POWER
Definition: acpi_drivers.h:94
UINT8 type
Definition: button.c:51
ACPI_STATUS acpi_button_notify_fixed(void *data)
Definition: button.c:91
struct acpi_device * power_button
Definition: button.c:55
unsigned int UINT32
#define ACPI_BUTTON_HID_SLEEPF
Definition: acpi_drivers.h:99
Definition: devices.h:37
char acpi_device_class[20]
Definition: acpi_bus.h:174
#define ACPI_BUTTON_DEVICE_NAME_SLEEPF
Definition: acpi_drivers.h:101
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
ACPI_STATUS AcpiRemoveFixedEventHandler(UINT32 Event, ACPI_EVENT_HANDLER Handler)
Definition: evxface.c:786
int acpi_bus_generate_event(struct acpi_device *device, UINT8 type, int data)
Definition: bus.c:485
void DPRINT(...)
Definition: polytest.cpp:61
#define ACPI_BUTTON_NOTIFY_STATUS
Definition: acpi_drivers.h:87
#define ACPI_DEVICE_NOTIFY
Definition: actypes.h:836
char acpi_device_name[40]
Definition: acpi_bus.h:173
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_BUTTON_HID_LID
Definition: acpi_drivers.h:106
#define ACPI_BUTTON_SUBCLASS_POWER
Definition: acpi_drivers.h:89
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define return_VOID
Definition: acoutput.h:495
GLuint GLuint end
Definition: gl.h:1545
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ACPI_BUTTON_SUBCLASS_SLEEP
Definition: acpi_drivers.h:97
#define ACPI_BUTTON_CLASS
Definition: acpi_drivers.h:83
struct _cl_event * event
Definition: glext.h:7739
#define ACPI_BUTTON_TYPE_POWERF
Definition: acpi_drivers.h:95
#define ACPI_BUTTON_SUBCLASS_LID
Definition: acpi_drivers.h:105
#define ACPI_DB_INFO
Definition: acoutput.h:153
#define ACPI_EVENT_POWER_BUTTON
Definition: actypes.h:757
static int acpi_button_remove(struct acpi_device *device, int type)
Definition: button.c:255
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_BUTTON_DEVICE_NAME_POWERF
Definition: acpi_drivers.h:93
#define ACPI_BUTTON_DEVICE_NAME_POWER
Definition: acpi_drivers.h:92
#define NULL
Definition: types.h:112
int acpi_bus_register_driver(struct acpi_driver *driver)
Definition: bus.c:1029
#define ACPI_BUTTON_TYPE_SLEEP
Definition: acpi_drivers.h:102
ACPI_STATUS AcpiInstallNotifyHandler(ACPI_HANDLE Device, UINT32 HandlerType, ACPI_NOTIFY_HANDLER Handler, void *Context)
Definition: evxface.c:96
#define ACPI_BUTTON_HID_SLEEP
Definition: acpi_drivers.h:98
#define acpi_device_hid(d)
Definition: acpi_bus.h:188
#define ACPI_EVENT_SLEEP_BUTTON
Definition: actypes.h:758
unsigned long pushed
Definition: button.c:52
#define ACPI_BUTTON_HID_POWER
Definition: acpi_drivers.h:90
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define acpi_driver_data(d)
Definition: acpi_bus.h:289
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct acpi_device * device
Definition: button.c:50
#define ACPI_BUTTON_DRIVER_NAME
Definition: acpi_drivers.h:82
unsigned char UINT8
#define memset(x, y, z)
Definition: compat.h:39
#define AE_OK
Definition: acexcep.h:97
struct acpi_device * lid_button
Definition: button.c:57
static struct acpi_driver acpi_button_driver
Definition: button.c:38
#define ACPI_BUTTON_DEVICE_NAME_LID
Definition: acpi_drivers.h:107
int acpi_button_init(void)
Definition: button.c:298
Definition: ps.c:97