blob: b15f5ec81d05fea191ef1efb0dd16db6e92e8ea4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/delay.h>
32#include <linux/proc_fs.h>
33#include <linux/seq_file.h>
Dmitry Torokhov451566f2005-03-19 01:10:05 -050034#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/io.h>
36#include <acpi/acpi_bus.h>
37#include <acpi/acpi_drivers.h>
38#include <acpi/actypes.h>
39
40#define _COMPONENT ACPI_EC_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040041ACPI_MODULE_NAME("acpi_ec")
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define ACPI_EC_COMPONENT 0x00100000
43#define ACPI_EC_CLASS "embedded_controller"
44#define ACPI_EC_HID "PNP0C09"
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
49#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
Dmitry Torokhov451566f2005-03-19 01:10:05 -050050#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */
53#define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */
Dmitry Torokhov451566f2005-03-19 01:10:05 -050054#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
Len Brown4be44fc2005-08-05 00:44:28 -040056#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
57#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define ACPI_EC_COMMAND_READ 0x80
59#define ACPI_EC_COMMAND_WRITE 0x81
Dmitry Torokhov451566f2005-03-19 01:10:05 -050060#define ACPI_EC_BURST_ENABLE 0x82
61#define ACPI_EC_BURST_DISABLE 0x83
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define ACPI_EC_COMMAND_QUERY 0x84
Luming Yu45bea152005-07-23 04:08:00 -040063#define EC_POLLING 0xFF
64#define EC_BURST 0x00
Len Brown4be44fc2005-08-05 00:44:28 -040065static int acpi_ec_remove(struct acpi_device *device, int type);
66static int acpi_ec_start(struct acpi_device *device);
67static int acpi_ec_stop(struct acpi_device *device, int type);
68static int acpi_ec_burst_add(struct acpi_device *device);
69static int acpi_ec_polling_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static struct acpi_driver acpi_ec_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -040072 .name = ACPI_EC_DRIVER_NAME,
73 .class = ACPI_EC_CLASS,
74 .ids = ACPI_EC_HID,
75 .ops = {
76 .add = acpi_ec_polling_add,
77 .remove = acpi_ec_remove,
78 .start = acpi_ec_start,
79 .stop = acpi_ec_stop,
80 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
Luming Yu45bea152005-07-23 04:08:00 -040082union acpi_ec {
83 struct {
Len Brown4be44fc2005-08-05 00:44:28 -040084 u32 mode;
85 acpi_handle handle;
86 unsigned long uid;
87 unsigned long gpe_bit;
88 struct acpi_generic_address status_addr;
89 struct acpi_generic_address command_addr;
90 struct acpi_generic_address data_addr;
91 unsigned long global_lock;
Luming Yu45bea152005-07-23 04:08:00 -040092 } common;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Luming Yu45bea152005-07-23 04:08:00 -040094 struct {
Len Brown4be44fc2005-08-05 00:44:28 -040095 u32 mode;
96 acpi_handle handle;
97 unsigned long uid;
98 unsigned long gpe_bit;
99 struct acpi_generic_address status_addr;
100 struct acpi_generic_address command_addr;
101 struct acpi_generic_address data_addr;
102 unsigned long global_lock;
103 unsigned int expect_event;
104 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
105 atomic_t pending_gpe;
106 struct semaphore sem;
107 wait_queue_head_t wait;
108 } burst;
Luming Yu45bea152005-07-23 04:08:00 -0400109
110 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400111 u32 mode;
112 acpi_handle handle;
113 unsigned long uid;
114 unsigned long gpe_bit;
115 struct acpi_generic_address status_addr;
116 struct acpi_generic_address command_addr;
117 struct acpi_generic_address data_addr;
118 unsigned long global_lock;
119 spinlock_t lock;
120 } polling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
Len Brown4be44fc2005-08-05 00:44:28 -0400123static int acpi_ec_polling_wait(union acpi_ec *ec, u8 event);
Luming Yu45bea152005-07-23 04:08:00 -0400124static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event);
Len Brown4be44fc2005-08-05 00:44:28 -0400125static int acpi_ec_polling_read(union acpi_ec *ec, u8 address, u32 * data);
126static int acpi_ec_burst_read(union acpi_ec *ec, u8 address, u32 * data);
127static int acpi_ec_polling_write(union acpi_ec *ec, u8 address, u8 data);
128static int acpi_ec_burst_write(union acpi_ec *ec, u8 address, u8 data);
129static int acpi_ec_polling_query(union acpi_ec *ec, u32 * data);
130static int acpi_ec_burst_query(union acpi_ec *ec, u32 * data);
131static void acpi_ec_gpe_polling_query(void *ec_cxt);
132static void acpi_ec_gpe_burst_query(void *ec_cxt);
133static u32 acpi_ec_gpe_polling_handler(void *data);
134static u32 acpi_ec_gpe_burst_handler(void *data);
Luming Yu45bea152005-07-23 04:08:00 -0400135static acpi_status __init
Len Brown4be44fc2005-08-05 00:44:28 -0400136acpi_fake_ecdt_polling_callback(acpi_handle handle,
137 u32 Level, void *context, void **retval);
Luming Yu45bea152005-07-23 04:08:00 -0400138
139static acpi_status __init
Len Brown4be44fc2005-08-05 00:44:28 -0400140acpi_fake_ecdt_burst_callback(acpi_handle handle,
141 u32 Level, void *context, void **retval);
Luming Yu45bea152005-07-23 04:08:00 -0400142
Len Brown4be44fc2005-08-05 00:44:28 -0400143static int __init acpi_ec_polling_get_real_ecdt(void);
144static int __init acpi_ec_burst_get_real_ecdt(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* If we find an EC via the ECDT, we need to keep a ptr to its context */
Len Brown4be44fc2005-08-05 00:44:28 -0400146static union acpi_ec *ec_ecdt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/* External interfaces use first EC only, so remember */
149static struct acpi_device *first_ec;
Luming Yu7b15f5e2005-08-03 17:38:04 -0400150static int acpi_ec_polling_mode = EC_POLLING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* --------------------------------------------------------------------------
153 Transaction Management
154 -------------------------------------------------------------------------- */
155
Luming Yu45bea152005-07-23 04:08:00 -0400156static inline u32 acpi_ec_read_status(union acpi_ec *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 u32 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Luming Yu45bea152005-07-23 04:08:00 -0400160 acpi_hw_low_level_read(8, &status, &ec->common.status_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500161 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Len Brown4be44fc2005-08-05 00:44:28 -0400164static int acpi_ec_wait(union acpi_ec *ec, u8 event)
Luming Yu45bea152005-07-23 04:08:00 -0400165{
Len Brown4be44fc2005-08-05 00:44:28 -0400166 if (acpi_ec_polling_mode)
167 return acpi_ec_polling_wait(ec, event);
Luming Yu45bea152005-07-23 04:08:00 -0400168 else
Len Brown4be44fc2005-08-05 00:44:28 -0400169 return acpi_ec_burst_wait(ec, event);
Luming Yu45bea152005-07-23 04:08:00 -0400170}
171
Len Brown4be44fc2005-08-05 00:44:28 -0400172static int acpi_ec_polling_wait(union acpi_ec *ec, u8 event)
Luming Yu45bea152005-07-23 04:08:00 -0400173{
Len Brown4be44fc2005-08-05 00:44:28 -0400174 u32 acpi_ec_status = 0;
175 u32 i = ACPI_EC_UDELAY_COUNT;
Luming Yu45bea152005-07-23 04:08:00 -0400176
177 if (!ec)
178 return -EINVAL;
179
180 /* Poll the EC status register waiting for the event to occur. */
181 switch (event) {
182 case ACPI_EC_EVENT_OBF:
183 do {
Len Brown4be44fc2005-08-05 00:44:28 -0400184 acpi_hw_low_level_read(8, &acpi_ec_status,
185 &ec->common.status_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400186 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
187 return 0;
188 udelay(ACPI_EC_UDELAY);
Len Brown4be44fc2005-08-05 00:44:28 -0400189 } while (--i > 0);
Luming Yu45bea152005-07-23 04:08:00 -0400190 break;
191 case ACPI_EC_EVENT_IBE:
192 do {
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_hw_low_level_read(8, &acpi_ec_status,
194 &ec->common.status_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400195 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
196 return 0;
197 udelay(ACPI_EC_UDELAY);
Len Brown4be44fc2005-08-05 00:44:28 -0400198 } while (--i > 0);
Luming Yu45bea152005-07-23 04:08:00 -0400199 break;
200 default:
201 return -EINVAL;
202 }
203
204 return -ETIME;
205}
206static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500207{
Len Brown4be44fc2005-08-05 00:44:28 -0400208 int result = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500209
210 ACPI_FUNCTION_TRACE("acpi_ec_wait");
211
Luming Yu45bea152005-07-23 04:08:00 -0400212 ec->burst.expect_event = event;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500213 smp_mb();
214
Luming Yu45bea152005-07-23 04:08:00 -0400215 result = wait_event_interruptible_timeout(ec->burst.wait,
Len Brown4be44fc2005-08-05 00:44:28 -0400216 !ec->burst.expect_event,
217 msecs_to_jiffies
218 (ACPI_EC_DELAY));
219
Luming Yu45bea152005-07-23 04:08:00 -0400220 ec->burst.expect_event = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500221 smp_mb();
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 if (result < 0) {
224 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, " result = %d ", result));
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500225 return_VALUE(result);
226 }
227
228 /*
229 * Verify that the event in question has actually happened by
230 * querying EC status. Do the check even if operation timed-out
231 * to make sure that we did not miss interrupt.
232 */
233 switch (event) {
234 case ACPI_EC_EVENT_OBF:
235 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
236 return_VALUE(0);
237 break;
238
239 case ACPI_EC_EVENT_IBE:
240 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
241 return_VALUE(0);
242 break;
243 }
244
245 return_VALUE(-ETIME);
246}
247
Len Brown4be44fc2005-08-05 00:44:28 -0400248static int acpi_ec_enter_burst_mode(union acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500249{
Len Brown4be44fc2005-08-05 00:44:28 -0400250 u32 tmp = 0;
251 int status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500252
253 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
254
255 status = acpi_ec_read_status(ec);
Len Brown4be44fc2005-08-05 00:44:28 -0400256 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
257 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE,
258 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500259 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
Len Brown4be44fc2005-08-05 00:44:28 -0400260 if (status) {
Luming Yu45bea152005-07-23 04:08:00 -0400261 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500262 return_VALUE(-EINVAL);
263 }
Luming Yu45bea152005-07-23 04:08:00 -0400264 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
265 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Len Brown4be44fc2005-08-05 00:44:28 -0400266 if (tmp != 0x90) { /* Burst ACK byte */
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500267 return_VALUE(-EINVAL);
268 }
Luming Yu668d74c2005-07-23 00:26:33 -0400269 }
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 atomic_set(&ec->burst.leaving_burst, 0);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500272 return_VALUE(0);
273}
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275static int acpi_ec_leave_burst_mode(union acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500276{
Len Brown4be44fc2005-08-05 00:44:28 -0400277 int status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500278
279 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 atomic_set(&ec->burst.leaving_burst, 1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500282 status = acpi_ec_read_status(ec);
Len Brown4be44fc2005-08-05 00:44:28 -0400283 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
284 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE,
285 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500286 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
Len Brown4be44fc2005-08-05 00:44:28 -0400287 if (status) {
Luming Yu45bea152005-07-23 04:08:00 -0400288 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Len Brown4be44fc2005-08-05 00:44:28 -0400289 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
290 "------->wait fail\n"));
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500291 return_VALUE(-EINVAL);
292 }
Luming Yu45bea152005-07-23 04:08:00 -0400293 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500294 status = acpi_ec_read_status(ec);
Luming Yu668d74c2005-07-23 00:26:33 -0400295 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500296
297 return_VALUE(0);
298}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Len Brown4be44fc2005-08-05 00:44:28 -0400300static int acpi_ec_read(union acpi_ec *ec, u8 address, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400301{
Len Brown4be44fc2005-08-05 00:44:28 -0400302 if (acpi_ec_polling_mode)
Luming Yu45bea152005-07-23 04:08:00 -0400303 return acpi_ec_polling_read(ec, address, data);
304 else
305 return acpi_ec_burst_read(ec, address, data);
306}
Len Brown4be44fc2005-08-05 00:44:28 -0400307static int acpi_ec_write(union acpi_ec *ec, u8 address, u8 data)
Luming Yu45bea152005-07-23 04:08:00 -0400308{
Len Brown4be44fc2005-08-05 00:44:28 -0400309 if (acpi_ec_polling_mode)
Luming Yu45bea152005-07-23 04:08:00 -0400310 return acpi_ec_polling_write(ec, address, data);
311 else
312 return acpi_ec_burst_write(ec, address, data);
313}
Len Brown4be44fc2005-08-05 00:44:28 -0400314static int acpi_ec_polling_read(union acpi_ec *ec, u8 address, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400315{
Len Brown4be44fc2005-08-05 00:44:28 -0400316 acpi_status status = AE_OK;
317 int result = 0;
318 unsigned long flags = 0;
319 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400320
321 ACPI_FUNCTION_TRACE("acpi_ec_read");
322
323 if (!ec || !data)
324 return_VALUE(-EINVAL);
325
326 *data = 0;
327
328 if (ec->common.global_lock) {
329 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
330 if (ACPI_FAILURE(status))
331 return_VALUE(-ENODEV);
332 }
333
334 spin_lock_irqsave(&ec->polling.lock, flags);
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ,
337 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400338 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
339 if (result)
340 goto end;
341
342 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
343 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
344 if (result)
345 goto end;
346
347 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
348
349 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400350 *data, address));
351
352 end:
Luming Yu45bea152005-07-23 04:08:00 -0400353 spin_unlock_irqrestore(&ec->polling.lock, flags);
354
355 if (ec->common.global_lock)
356 acpi_release_global_lock(glk);
357
358 return_VALUE(result);
359}
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361static int acpi_ec_polling_write(union acpi_ec *ec, u8 address, u8 data)
Luming Yu45bea152005-07-23 04:08:00 -0400362{
Len Brown4be44fc2005-08-05 00:44:28 -0400363 int result = 0;
364 acpi_status status = AE_OK;
365 unsigned long flags = 0;
366 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400367
368 ACPI_FUNCTION_TRACE("acpi_ec_write");
369
370 if (!ec)
371 return_VALUE(-EINVAL);
372
373 if (ec->common.global_lock) {
374 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
375 if (ACPI_FAILURE(status))
376 return_VALUE(-ENODEV);
377 }
378
379 spin_lock_irqsave(&ec->polling.lock, flags);
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE,
382 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400383 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
384 if (result)
385 goto end;
386
387 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
388 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
389 if (result)
390 goto end;
391
392 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
393 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
394 if (result)
395 goto end;
396
397 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400398 data, address));
Luming Yu45bea152005-07-23 04:08:00 -0400399
Len Brown4be44fc2005-08-05 00:44:28 -0400400 end:
Luming Yu45bea152005-07-23 04:08:00 -0400401 spin_unlock_irqrestore(&ec->polling.lock, flags);
402
403 if (ec->common.global_lock)
404 acpi_release_global_lock(glk);
405
406 return_VALUE(result);
407}
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409static int acpi_ec_burst_read(union acpi_ec *ec, u8 address, u32 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Len Brown4be44fc2005-08-05 00:44:28 -0400411 int status = 0;
412 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 ACPI_FUNCTION_TRACE("acpi_ec_read");
415
416 if (!ec || !data)
417 return_VALUE(-EINVAL);
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 retry:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 *data = 0;
421
Luming Yu45bea152005-07-23 04:08:00 -0400422 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
424 if (ACPI_FAILURE(status))
425 return_VALUE(-ENODEV);
426 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500427
428 WARN_ON(in_interrupt());
Luming Yu45bea152005-07-23 04:08:00 -0400429 down(&ec->burst.sem);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500430
Len Brown4be44fc2005-08-05 00:44:28 -0400431 if (acpi_ec_enter_burst_mode(ec))
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500432 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Len Brown4be44fc2005-08-05 00:44:28 -0400434 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ,
435 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500436 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Luming Yu45bea152005-07-23 04:08:00 -0400437 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500438 if (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Luming Yu45bea152005-07-23 04:08:00 -0400442 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
Len Brown4be44fc2005-08-05 00:44:28 -0400443 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
444 if (status) {
Luming Yu45bea152005-07-23 04:08:00 -0400445 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Luming Yu45bea152005-07-23 04:08:00 -0400449 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
450 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400453 *data, address));
454
455 end:
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500456 acpi_ec_leave_burst_mode(ec);
Luming Yu45bea152005-07-23 04:08:00 -0400457 up(&ec->burst.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Luming Yu45bea152005-07-23 04:08:00 -0400459 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 acpi_release_global_lock(glk);
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462 if (atomic_read(&ec->burst.leaving_burst) == 2) {
463 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "aborted, retry ...\n"));
464 while (atomic_read(&ec->burst.pending_gpe)) {
465 msleep(1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500466 }
Luming Yu45bea152005-07-23 04:08:00 -0400467 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500468 goto retry;
469 }
470
471 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Len Brown4be44fc2005-08-05 00:44:28 -0400474static int acpi_ec_burst_write(union acpi_ec *ec, u8 address, u8 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Len Brown4be44fc2005-08-05 00:44:28 -0400476 int status = 0;
477 u32 glk;
478 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 ACPI_FUNCTION_TRACE("acpi_ec_write");
481
482 if (!ec)
483 return_VALUE(-EINVAL);
Len Brown4be44fc2005-08-05 00:44:28 -0400484 retry:
Luming Yu45bea152005-07-23 04:08:00 -0400485 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
487 if (ACPI_FAILURE(status))
488 return_VALUE(-ENODEV);
489 }
490
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500491 WARN_ON(in_interrupt());
Luming Yu45bea152005-07-23 04:08:00 -0400492 down(&ec->burst.sem);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500493
Len Brown4be44fc2005-08-05 00:44:28 -0400494 if (acpi_ec_enter_burst_mode(ec))
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500495 goto end;
496
497 status = acpi_ec_read_status(ec);
Len Brown4be44fc2005-08-05 00:44:28 -0400498 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
499 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE,
500 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500501 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
502 if (status)
503 goto end;
Luming Yu45bea152005-07-23 04:08:00 -0400504 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
Len Brown4be44fc2005-08-05 00:44:28 -0400505 if (tmp != 0x90) /* Burst ACK byte */
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500506 goto end;
507 }
Len Brown4be44fc2005-08-05 00:44:28 -0400508 /*Now we are in burst mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE,
511 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500512 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Luming Yu45bea152005-07-23 04:08:00 -0400513 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Len Brown4be44fc2005-08-05 00:44:28 -0400514 if (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Luming Yu45bea152005-07-23 04:08:00 -0400518 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500519 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Len Brown4be44fc2005-08-05 00:44:28 -0400520 if (status) {
Luming Yu45bea152005-07-23 04:08:00 -0400521 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Luming Yu45bea152005-07-23 04:08:00 -0400525 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500526 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Luming Yu45bea152005-07-23 04:08:00 -0400527 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500528 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 goto end;
530
531 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400532 data, address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Len Brown4be44fc2005-08-05 00:44:28 -0400534 end:
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500535 acpi_ec_leave_burst_mode(ec);
Luming Yu45bea152005-07-23 04:08:00 -0400536 up(&ec->burst.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Luming Yu45bea152005-07-23 04:08:00 -0400538 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 acpi_release_global_lock(glk);
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 if (atomic_read(&ec->burst.leaving_burst) == 2) {
542 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "aborted, retry ...\n"));
543 while (atomic_read(&ec->burst.pending_gpe)) {
544 msleep(1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500545 }
Luming Yu45bea152005-07-23 04:08:00 -0400546 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500547 goto retry;
548 }
549
550 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553/*
554 * Externally callable EC access functions. For now, assume 1 EC only
555 */
Len Brown4be44fc2005-08-05 00:44:28 -0400556int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Luming Yu45bea152005-07-23 04:08:00 -0400558 union acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 int err;
560 u32 temp_data;
561
562 if (!first_ec)
563 return -ENODEV;
564
565 ec = acpi_driver_data(first_ec);
566
567 err = acpi_ec_read(ec, addr, &temp_data);
568
569 if (!err) {
570 *val = temp_data;
571 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400572 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 return err;
574}
Len Brown4be44fc2005-08-05 00:44:28 -0400575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576EXPORT_SYMBOL(ec_read);
577
Len Brown4be44fc2005-08-05 00:44:28 -0400578int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Luming Yu45bea152005-07-23 04:08:00 -0400580 union acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 int err;
582
583 if (!first_ec)
584 return -ENODEV;
585
586 ec = acpi_driver_data(first_ec);
587
588 err = acpi_ec_write(ec, addr, val);
589
590 return err;
591}
Len Brown4be44fc2005-08-05 00:44:28 -0400592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593EXPORT_SYMBOL(ec_write);
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595static int acpi_ec_query(union acpi_ec *ec, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400596{
Len Brown4be44fc2005-08-05 00:44:28 -0400597 if (acpi_ec_polling_mode)
Luming Yu45bea152005-07-23 04:08:00 -0400598 return acpi_ec_polling_query(ec, data);
599 else
600 return acpi_ec_burst_query(ec, data);
601}
Len Brown4be44fc2005-08-05 00:44:28 -0400602static int acpi_ec_polling_query(union acpi_ec *ec, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400603{
Len Brown4be44fc2005-08-05 00:44:28 -0400604 int result = 0;
605 acpi_status status = AE_OK;
606 unsigned long flags = 0;
607 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400608
609 ACPI_FUNCTION_TRACE("acpi_ec_query");
610
611 if (!ec || !data)
612 return_VALUE(-EINVAL);
613
614 *data = 0;
615
616 if (ec->common.global_lock) {
617 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
618 if (ACPI_FAILURE(status))
619 return_VALUE(-ENODEV);
620 }
621
622 /*
623 * Query the EC to find out which _Qxx method we need to evaluate.
624 * Note that successful completion of the query causes the ACPI_EC_SCI
625 * bit to be cleared (and thus clearing the interrupt source).
626 */
627 spin_lock_irqsave(&ec->polling.lock, flags);
628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY,
630 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400631 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
632 if (result)
633 goto end;
634
635 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
636 if (!*data)
637 result = -ENODATA;
638
Len Brown4be44fc2005-08-05 00:44:28 -0400639 end:
Luming Yu45bea152005-07-23 04:08:00 -0400640 spin_unlock_irqrestore(&ec->polling.lock, flags);
641
642 if (ec->common.global_lock)
643 acpi_release_global_lock(glk);
644
645 return_VALUE(result);
646}
Len Brown4be44fc2005-08-05 00:44:28 -0400647static int acpi_ec_burst_query(union acpi_ec *ec, u32 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
Len Brown4be44fc2005-08-05 00:44:28 -0400649 int status = 0;
650 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 ACPI_FUNCTION_TRACE("acpi_ec_query");
653
654 if (!ec || !data)
655 return_VALUE(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 *data = 0;
657
Luming Yu45bea152005-07-23 04:08:00 -0400658 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
660 if (ACPI_FAILURE(status))
661 return_VALUE(-ENODEV);
662 }
663
Luming Yu45bea152005-07-23 04:08:00 -0400664 down(&ec->burst.sem);
Len Brown4be44fc2005-08-05 00:44:28 -0400665 if (acpi_ec_enter_burst_mode(ec))
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500666 goto end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /*
668 * Query the EC to find out which _Qxx method we need to evaluate.
669 * Note that successful completion of the query causes the ACPI_EC_SCI
670 * bit to be cleared (and thus clearing the interrupt source).
671 */
Len Brown4be44fc2005-08-05 00:44:28 -0400672 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY,
673 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500674 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
Len Brown4be44fc2005-08-05 00:44:28 -0400675 if (status) {
Luming Yu45bea152005-07-23 04:08:00 -0400676 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500678 }
679
Luming Yu45bea152005-07-23 04:08:00 -0400680 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
681 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 if (!*data)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500683 status = -ENODATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 end:
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500686 acpi_ec_leave_burst_mode(ec);
Luming Yu45bea152005-07-23 04:08:00 -0400687 up(&ec->burst.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Luming Yu45bea152005-07-23 04:08:00 -0400689 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 acpi_release_global_lock(glk);
691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 if (atomic_read(&ec->burst.leaving_burst) == 2) {
693 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "aborted, retry ...\n"));
Luming Yu45bea152005-07-23 04:08:00 -0400694 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Luming Yu17e9c782005-04-22 23:07:10 -0400695 status = -ENODATA;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500696 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500697 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/* --------------------------------------------------------------------------
701 Event Management
702 -------------------------------------------------------------------------- */
703
Luming Yu45bea152005-07-23 04:08:00 -0400704union acpi_ec_query_data {
Len Brown4be44fc2005-08-05 00:44:28 -0400705 acpi_handle handle;
706 u8 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707};
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Len Brown4be44fc2005-08-05 00:44:28 -0400711 if (acpi_ec_polling_mode)
Luming Yu45bea152005-07-23 04:08:00 -0400712 acpi_ec_gpe_polling_query(ec_cxt);
713 else
714 acpi_ec_gpe_burst_query(ec_cxt);
715}
716
Len Brown4be44fc2005-08-05 00:44:28 -0400717static void acpi_ec_gpe_polling_query(void *ec_cxt)
Luming Yu45bea152005-07-23 04:08:00 -0400718{
Len Brown4be44fc2005-08-05 00:44:28 -0400719 union acpi_ec *ec = (union acpi_ec *)ec_cxt;
720 u32 value = 0;
721 unsigned long flags = 0;
722 static char object_name[5] = { '_', 'Q', '0', '0', '\0' };
723 const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
724 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
725 };
Luming Yu45bea152005-07-23 04:08:00 -0400726
727 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
728
729 if (!ec_cxt)
730 goto end;
731
732 spin_lock_irqsave(&ec->polling.lock, flags);
733 acpi_hw_low_level_read(8, &value, &ec->common.command_addr);
734 spin_unlock_irqrestore(&ec->polling.lock, flags);
735
736 /* TBD: Implement asynch events!
737 * NOTE: All we care about are EC-SCI's. Other EC events are
738 * handled via polling (yuck!). This is because some systems
739 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
740 * a purely interrupt-driven approach (grumble, grumble).
741 */
742 if (!(value & ACPI_EC_FLAG_SCI))
743 goto end;
744
745 if (acpi_ec_query(ec, &value))
746 goto end;
747
748 object_name[2] = hex[((value >> 4) & 0x0F)];
749 object_name[3] = hex[(value & 0x0F)];
750
751 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
752
753 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 end:
Luming Yu45bea152005-07-23 04:08:00 -0400756 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
757}
Len Brown4be44fc2005-08-05 00:44:28 -0400758static void acpi_ec_gpe_burst_query(void *ec_cxt)
Luming Yu45bea152005-07-23 04:08:00 -0400759{
Len Brown4be44fc2005-08-05 00:44:28 -0400760 union acpi_ec *ec = (union acpi_ec *)ec_cxt;
761 u32 value;
762 int result = -ENODATA;
763 static char object_name[5] = { '_', 'Q', '0', '0', '\0' };
764 const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
765 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
766 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
769
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500770 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
771 result = acpi_ec_query(ec, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500773 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 goto end;
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 object_name[2] = hex[((value >> 4) & 0x0F)];
777 object_name[3] = hex[(value & 0x0F)];
778
779 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
780
Luming Yu45bea152005-07-23 04:08:00 -0400781 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400782 end:
Luming Yu45bea152005-07-23 04:08:00 -0400783 atomic_dec(&ec->burst.pending_gpe);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500784 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
786
Len Brown4be44fc2005-08-05 00:44:28 -0400787static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Len Brown4be44fc2005-08-05 00:44:28 -0400789 if (acpi_ec_polling_mode)
Luming Yu45bea152005-07-23 04:08:00 -0400790 return acpi_ec_gpe_polling_handler(data);
791 else
Len Brown4be44fc2005-08-05 00:44:28 -0400792 return acpi_ec_gpe_burst_handler(data);
Luming Yu45bea152005-07-23 04:08:00 -0400793}
Len Brown4be44fc2005-08-05 00:44:28 -0400794static u32 acpi_ec_gpe_polling_handler(void *data)
Luming Yu45bea152005-07-23 04:08:00 -0400795{
Len Brown4be44fc2005-08-05 00:44:28 -0400796 acpi_status status = AE_OK;
797 union acpi_ec *ec = (union acpi_ec *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (!ec)
800 return ACPI_INTERRUPT_NOT_HANDLED;
801
Luming Yu45bea152005-07-23 04:08:00 -0400802 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
803
804 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
Len Brown4be44fc2005-08-05 00:44:28 -0400805 acpi_ec_gpe_query, ec);
Luming Yu45bea152005-07-23 04:08:00 -0400806
807 if (status == AE_OK)
808 return ACPI_INTERRUPT_HANDLED;
809 else
810 return ACPI_INTERRUPT_NOT_HANDLED;
811}
Len Brown4be44fc2005-08-05 00:44:28 -0400812static u32 acpi_ec_gpe_burst_handler(void *data)
Luming Yu45bea152005-07-23 04:08:00 -0400813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 acpi_status status = AE_OK;
815 u32 value;
816 union acpi_ec *ec = (union acpi_ec *)data;
Luming Yu45bea152005-07-23 04:08:00 -0400817
818 if (!ec)
819 return ACPI_INTERRUPT_NOT_HANDLED;
820
821 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500823 value = acpi_ec_read_status(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Len Brown4be44fc2005-08-05 00:44:28 -0400825 if ((value & ACPI_EC_FLAG_IBF) &&
826 !(value & ACPI_EC_FLAG_BURST) &&
827 (atomic_read(&ec->burst.leaving_burst) == 0)) {
828 /*
829 * the embedded controller disables
830 * burst mode for any reason other
831 * than the burst disable command
832 * to process critical event.
833 */
834 atomic_set(&ec->burst.leaving_burst, 2); /* block current pending transaction
835 and retry */
Luming Yu45bea152005-07-23 04:08:00 -0400836 wake_up(&ec->burst.wait);
Len Brown4be44fc2005-08-05 00:44:28 -0400837 } else {
Luming Yu45bea152005-07-23 04:08:00 -0400838 if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF &&
Len Brown4be44fc2005-08-05 00:44:28 -0400839 (value & ACPI_EC_FLAG_OBF)) ||
840 (ec->burst.expect_event == ACPI_EC_EVENT_IBE &&
841 !(value & ACPI_EC_FLAG_IBF))) {
Luming Yu45bea152005-07-23 04:08:00 -0400842 ec->burst.expect_event = 0;
843 wake_up(&ec->burst.wait);
Luming Yu17e9c782005-04-22 23:07:10 -0400844 return ACPI_INTERRUPT_HANDLED;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500845 }
846 }
847
Len Brown4be44fc2005-08-05 00:44:28 -0400848 if (value & ACPI_EC_FLAG_SCI) {
849 atomic_add(1, &ec->burst.pending_gpe);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500850 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
Len Brown4be44fc2005-08-05 00:44:28 -0400851 acpi_ec_gpe_query, ec);
Luming Yu17e9c782005-04-22 23:07:10 -0400852 return status == AE_OK ?
Len Brown4be44fc2005-08-05 00:44:28 -0400853 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
854 }
Luming Yu45bea152005-07-23 04:08:00 -0400855 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500856 return status == AE_OK ?
Len Brown4be44fc2005-08-05 00:44:28 -0400857 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
860/* --------------------------------------------------------------------------
861 Address Space Management
862 -------------------------------------------------------------------------- */
863
864static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400865acpi_ec_space_setup(acpi_handle region_handle,
866 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
868 /*
869 * The EC object is in the handler context and is needed
870 * when calling the acpi_ec_space_handler.
871 */
Len Brown4be44fc2005-08-05 00:44:28 -0400872 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
873 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 return AE_OK;
876}
877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400879acpi_ec_space_handler(u32 function,
880 acpi_physical_address address,
881 u32 bit_width,
882 acpi_integer * value,
883 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Len Brown4be44fc2005-08-05 00:44:28 -0400885 int result = 0;
886 union acpi_ec *ec = NULL;
887 u64 temp = *value;
888 acpi_integer f_v = 0;
889 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
892
893 if ((address > 0xFF) || !value || !handler_context)
894 return_VALUE(AE_BAD_PARAMETER);
895
Luming Yufa9cd542005-03-19 01:54:47 -0500896 if (bit_width != 8 && acpi_strict) {
Len Brown4be44fc2005-08-05 00:44:28 -0400897 printk(KERN_WARNING PREFIX
898 "acpi_ec_space_handler: bit_width should be 8\n");
Luming Yufa9cd542005-03-19 01:54:47 -0500899 return_VALUE(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 }
901
Len Brown4be44fc2005-08-05 00:44:28 -0400902 ec = (union acpi_ec *)handler_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Len Brown4be44fc2005-08-05 00:44:28 -0400904 next_byte:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 switch (function) {
906 case ACPI_READ:
Luming Yufa9cd542005-03-19 01:54:47 -0500907 temp = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400908 result = acpi_ec_read(ec, (u8) address, (u32 *) & temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 break;
910 case ACPI_WRITE:
Luming Yufa9cd542005-03-19 01:54:47 -0500911 result = acpi_ec_write(ec, (u8) address, (u8) temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 break;
913 default:
914 result = -EINVAL;
915 goto out;
916 break;
917 }
918
919 bit_width -= 8;
Luming Yufa9cd542005-03-19 01:54:47 -0500920 if (bit_width) {
921 if (function == ACPI_READ)
922 f_v |= temp << 8 * i;
923 if (function == ACPI_WRITE)
924 temp >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 i++;
Andrew Morton83ea7442005-03-30 22:12:13 -0500926 address++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 goto next_byte;
928 }
929
Luming Yufa9cd542005-03-19 01:54:47 -0500930 if (function == ACPI_READ) {
931 f_v |= temp << 8 * i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 *value = f_v;
933 }
934
Len Brown4be44fc2005-08-05 00:44:28 -0400935 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 switch (result) {
937 case -EINVAL:
938 return_VALUE(AE_BAD_PARAMETER);
939 break;
940 case -ENODEV:
941 return_VALUE(AE_NOT_FOUND);
942 break;
943 case -ETIME:
944 return_VALUE(AE_TIME);
945 break;
946 default:
947 return_VALUE(AE_OK);
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951/* --------------------------------------------------------------------------
952 FS Interface (/proc)
953 -------------------------------------------------------------------------- */
954
Len Brown4be44fc2005-08-05 00:44:28 -0400955static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Len Brown4be44fc2005-08-05 00:44:28 -0400957static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958{
Len Brown4be44fc2005-08-05 00:44:28 -0400959 union acpi_ec *ec = (union acpi_ec *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
962
963 if (!ec)
964 goto end;
965
966 seq_printf(seq, "gpe bit: 0x%02x\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400967 (u32) ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400969 (u32) ec->common.status_addr.address,
970 (u32) ec->common.data_addr.address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 seq_printf(seq, "use global lock: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400972 ec->common.global_lock ? "yes" : "no");
Luming Yu45bea152005-07-23 04:08:00 -0400973 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Len Brown4be44fc2005-08-05 00:44:28 -0400975 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 return_VALUE(0);
977}
978
979static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
980{
981 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
982}
983
984static struct file_operations acpi_ec_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400985 .open = acpi_ec_info_open_fs,
986 .read = seq_read,
987 .llseek = seq_lseek,
988 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 .owner = THIS_MODULE,
990};
991
Len Brown4be44fc2005-08-05 00:44:28 -0400992static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Len Brown4be44fc2005-08-05 00:44:28 -0400994 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
997
998 if (!acpi_device_dir(device)) {
999 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001000 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 if (!acpi_device_dir(device))
1002 return_VALUE(-ENODEV);
1003 }
1004
1005 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown4be44fc2005-08-05 00:44:28 -04001006 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (!entry)
1008 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
Len Brown4be44fc2005-08-05 00:44:28 -04001009 "Unable to create '%s' fs entry\n",
1010 ACPI_EC_FILE_INFO));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 else {
1012 entry->proc_fops = &acpi_ec_info_ops;
1013 entry->data = acpi_driver_data(device);
1014 entry->owner = THIS_MODULE;
1015 }
1016
1017 return_VALUE(0);
1018}
1019
Len Brown4be44fc2005-08-05 00:44:28 -04001020static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
1022 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
1023
1024 if (acpi_device_dir(device)) {
1025 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
1026 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
1027 acpi_device_dir(device) = NULL;
1028 }
1029
1030 return_VALUE(0);
1031}
1032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033/* --------------------------------------------------------------------------
1034 Driver Interface
1035 -------------------------------------------------------------------------- */
1036
Len Brown4be44fc2005-08-05 00:44:28 -04001037static int acpi_ec_polling_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Len Brown4be44fc2005-08-05 00:44:28 -04001039 int result = 0;
1040 acpi_status status = AE_OK;
1041 union acpi_ec *ec = NULL;
1042 unsigned long uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 ACPI_FUNCTION_TRACE("acpi_ec_add");
1045
1046 if (!device)
1047 return_VALUE(-EINVAL);
1048
Luming Yu45bea152005-07-23 04:08:00 -04001049 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 if (!ec)
1051 return_VALUE(-ENOMEM);
Luming Yu45bea152005-07-23 04:08:00 -04001052 memset(ec, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Luming Yu45bea152005-07-23 04:08:00 -04001054 ec->common.handle = device->handle;
1055 ec->common.uid = -1;
1056 spin_lock_init(&ec->polling.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1058 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1059 acpi_driver_data(device) = ec;
1060
1061 /* Use the global lock for all EC transactions? */
Len Brown4be44fc2005-08-05 00:44:28 -04001062 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL,
1063 &ec->common.global_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 /* If our UID matches the UID for the ECDT-enumerated EC,
Len Brown4be44fc2005-08-05 00:44:28 -04001066 we now have the *real* EC info, so kill the makeshift one. */
Luming Yu45bea152005-07-23 04:08:00 -04001067 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1068 if (ec_ecdt && ec_ecdt->common.uid == uid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -04001070 ACPI_ADR_SPACE_EC,
1071 &acpi_ec_space_handler);
1072
1073 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1074 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 kfree(ec_ecdt);
1077 }
1078
1079 /* Get GPE bit assignment (EC events). */
1080 /* TODO: Add support for _GPE returning a package */
Len Brown4be44fc2005-08-05 00:44:28 -04001081 status =
1082 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1083 &ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (ACPI_FAILURE(status)) {
1085 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001086 "Error obtaining GPE bit assignment\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 result = -ENODEV;
1088 goto end;
1089 }
1090
1091 result = acpi_ec_add_fs(device);
1092 if (result)
1093 goto end;
1094
1095 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001096 acpi_device_name(device), acpi_device_bid(device),
1097 (u32) ec->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001098
1099 if (!first_ec)
1100 first_ec = device;
1101
Len Brown4be44fc2005-08-05 00:44:28 -04001102 end:
Luming Yu45bea152005-07-23 04:08:00 -04001103 if (result)
1104 kfree(ec);
1105
1106 return_VALUE(result);
1107}
Len Brown4be44fc2005-08-05 00:44:28 -04001108static int acpi_ec_burst_add(struct acpi_device *device)
Luming Yu45bea152005-07-23 04:08:00 -04001109{
Len Brown4be44fc2005-08-05 00:44:28 -04001110 int result = 0;
1111 acpi_status status = AE_OK;
1112 union acpi_ec *ec = NULL;
1113 unsigned long uid;
Luming Yu45bea152005-07-23 04:08:00 -04001114
1115 ACPI_FUNCTION_TRACE("acpi_ec_add");
1116
1117 if (!device)
1118 return_VALUE(-EINVAL);
1119
1120 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1121 if (!ec)
1122 return_VALUE(-ENOMEM);
1123 memset(ec, 0, sizeof(union acpi_ec));
1124
1125 ec->common.handle = device->handle;
1126 ec->common.uid = -1;
Len Brown4be44fc2005-08-05 00:44:28 -04001127 atomic_set(&ec->burst.pending_gpe, 0);
1128 atomic_set(&ec->burst.leaving_burst, 1);
1129 init_MUTEX(&ec->burst.sem);
1130 init_waitqueue_head(&ec->burst.wait);
Luming Yu45bea152005-07-23 04:08:00 -04001131 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1132 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1133 acpi_driver_data(device) = ec;
1134
1135 /* Use the global lock for all EC transactions? */
Len Brown4be44fc2005-08-05 00:44:28 -04001136 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL,
1137 &ec->common.global_lock);
Luming Yu45bea152005-07-23 04:08:00 -04001138
1139 /* If our UID matches the UID for the ECDT-enumerated EC,
Len Brown4be44fc2005-08-05 00:44:28 -04001140 we now have the *real* EC info, so kill the makeshift one. */
Luming Yu45bea152005-07-23 04:08:00 -04001141 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1142 if (ec_ecdt && ec_ecdt->common.uid == uid) {
1143 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -04001144 ACPI_ADR_SPACE_EC,
1145 &acpi_ec_space_handler);
Luming Yu45bea152005-07-23 04:08:00 -04001146
Len Brown4be44fc2005-08-05 00:44:28 -04001147 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1148 &acpi_ec_gpe_handler);
Luming Yu45bea152005-07-23 04:08:00 -04001149
1150 kfree(ec_ecdt);
1151 }
1152
1153 /* Get GPE bit assignment (EC events). */
1154 /* TODO: Add support for _GPE returning a package */
Len Brown4be44fc2005-08-05 00:44:28 -04001155 status =
1156 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1157 &ec->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001158 if (ACPI_FAILURE(status)) {
1159 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001160 "Error obtaining GPE bit assignment\n"));
Luming Yu45bea152005-07-23 04:08:00 -04001161 result = -ENODEV;
1162 goto end;
1163 }
1164
1165 result = acpi_ec_add_fs(device);
1166 if (result)
1167 goto end;
1168
1169 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001170 acpi_device_name(device), acpi_device_bid(device),
1171 (u32) ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 if (!first_ec)
1174 first_ec = device;
1175
Len Brown4be44fc2005-08-05 00:44:28 -04001176 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 if (result)
1178 kfree(ec);
1179
1180 return_VALUE(result);
1181}
1182
Len Brown4be44fc2005-08-05 00:44:28 -04001183static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
Len Brown4be44fc2005-08-05 00:44:28 -04001185 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 ACPI_FUNCTION_TRACE("acpi_ec_remove");
1188
1189 if (!device)
1190 return_VALUE(-EINVAL);
1191
1192 ec = acpi_driver_data(device);
1193
1194 acpi_ec_remove_fs(device);
1195
1196 kfree(ec);
1197
1198 return_VALUE(0);
1199}
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001202acpi_ec_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Len Brown4be44fc2005-08-05 00:44:28 -04001204 union acpi_ec *ec = (union acpi_ec *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 struct acpi_generic_address *addr;
1206
1207 if (resource->id != ACPI_RSTYPE_IO) {
1208 return AE_OK;
1209 }
1210
1211 /*
1212 * The first address region returned is the data port, and
1213 * the second address region returned is the status/command
1214 * port.
1215 */
Luming Yu45bea152005-07-23 04:08:00 -04001216 if (ec->common.data_addr.register_bit_width == 0) {
1217 addr = &ec->common.data_addr;
1218 } else if (ec->common.command_addr.register_bit_width == 0) {
1219 addr = &ec->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 } else {
1221 return AE_CTRL_TERMINATE;
1222 }
1223
1224 addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
1225 addr->register_bit_width = 8;
1226 addr->register_bit_offset = 0;
1227 addr->address = resource->data.io.min_base_address;
1228
1229 return AE_OK;
1230}
1231
Len Brown4be44fc2005-08-05 00:44:28 -04001232static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Len Brown4be44fc2005-08-05 00:44:28 -04001234 acpi_status status = AE_OK;
1235 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 ACPI_FUNCTION_TRACE("acpi_ec_start");
1238
1239 if (!device)
1240 return_VALUE(-EINVAL);
1241
1242 ec = acpi_driver_data(device);
1243
1244 if (!ec)
1245 return_VALUE(-EINVAL);
1246
1247 /*
1248 * Get I/O port addresses. Convert to GAS format.
1249 */
Luming Yu45bea152005-07-23 04:08:00 -04001250 status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -04001251 acpi_ec_io_ports, ec);
1252 if (ACPI_FAILURE(status)
1253 || ec->common.command_addr.register_bit_width == 0) {
1254 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1255 "Error getting I/O port addresses"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 return_VALUE(-ENODEV);
1257 }
1258
Luming Yu45bea152005-07-23 04:08:00 -04001259 ec->common.status_addr = ec->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001262 (u32) ec->common.gpe_bit,
1263 (u32) ec->common.command_addr.address,
1264 (u32) ec->common.data_addr.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /*
1267 * Install GPE handler
1268 */
Luming Yu45bea152005-07-23 04:08:00 -04001269 status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit,
Len Brown4be44fc2005-08-05 00:44:28 -04001270 ACPI_GPE_EDGE_TRIGGERED,
1271 &acpi_ec_gpe_handler, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if (ACPI_FAILURE(status)) {
1273 return_VALUE(-ENODEV);
1274 }
Len Brown4be44fc2005-08-05 00:44:28 -04001275 acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1276 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Len Brown4be44fc2005-08-05 00:44:28 -04001278 status = acpi_install_address_space_handler(ec->common.handle,
1279 ACPI_ADR_SPACE_EC,
1280 &acpi_ec_space_handler,
1281 &acpi_ec_space_setup, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001283 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1284 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 return_VALUE(-ENODEV);
1286 }
1287
1288 return_VALUE(AE_OK);
1289}
1290
Len Brown4be44fc2005-08-05 00:44:28 -04001291static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Len Brown4be44fc2005-08-05 00:44:28 -04001293 acpi_status status = AE_OK;
1294 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 ACPI_FUNCTION_TRACE("acpi_ec_stop");
1297
1298 if (!device)
1299 return_VALUE(-EINVAL);
1300
1301 ec = acpi_driver_data(device);
1302
Luming Yu45bea152005-07-23 04:08:00 -04001303 status = acpi_remove_address_space_handler(ec->common.handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001304 ACPI_ADR_SPACE_EC,
1305 &acpi_ec_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if (ACPI_FAILURE(status))
1307 return_VALUE(-ENODEV);
1308
Len Brown4be44fc2005-08-05 00:44:28 -04001309 status =
1310 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1311 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (ACPI_FAILURE(status))
1313 return_VALUE(-ENODEV);
1314
1315 return_VALUE(0);
1316}
1317
1318static acpi_status __init
Len Brown4be44fc2005-08-05 00:44:28 -04001319acpi_fake_ecdt_callback(acpi_handle handle,
1320 u32 Level, void *context, void **retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Luming Yu45bea152005-07-23 04:08:00 -04001322
1323 if (acpi_ec_polling_mode)
1324 return acpi_fake_ecdt_polling_callback(handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001325 Level, context, retval);
Luming Yu45bea152005-07-23 04:08:00 -04001326 else
1327 return acpi_fake_ecdt_burst_callback(handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001328 Level, context, retval);
Luming Yu45bea152005-07-23 04:08:00 -04001329}
1330
1331static acpi_status __init
Len Brown4be44fc2005-08-05 00:44:28 -04001332acpi_fake_ecdt_polling_callback(acpi_handle handle,
1333 u32 Level, void *context, void **retval)
Luming Yu45bea152005-07-23 04:08:00 -04001334{
Len Brown4be44fc2005-08-05 00:44:28 -04001335 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -04001338 acpi_ec_io_ports, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 if (ACPI_FAILURE(status))
1340 return status;
Luming Yu45bea152005-07-23 04:08:00 -04001341 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Luming Yu45bea152005-07-23 04:08:00 -04001343 ec_ecdt->common.uid = -1;
1344 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Len Brown4be44fc2005-08-05 00:44:28 -04001346 status =
1347 acpi_evaluate_integer(handle, "_GPE", NULL,
1348 &ec_ecdt->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (ACPI_FAILURE(status))
1350 return status;
Luming Yu45bea152005-07-23 04:08:00 -04001351 spin_lock_init(&ec_ecdt->polling.lock);
1352 ec_ecdt->common.global_lock = TRUE;
1353 ec_ecdt->common.handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Len Brown4be44fc2005-08-05 00:44:28 -04001355 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1356 (u32) ec_ecdt->common.gpe_bit,
1357 (u32) ec_ecdt->common.command_addr.address,
1358 (u32) ec_ecdt->common.data_addr.address);
Luming Yu45bea152005-07-23 04:08:00 -04001359
1360 return AE_CTRL_TERMINATE;
1361}
1362
1363static acpi_status __init
Len Brown4be44fc2005-08-05 00:44:28 -04001364acpi_fake_ecdt_burst_callback(acpi_handle handle,
1365 u32 Level, void *context, void **retval)
Luming Yu45bea152005-07-23 04:08:00 -04001366{
Len Brown4be44fc2005-08-05 00:44:28 -04001367 acpi_status status;
Luming Yu45bea152005-07-23 04:08:00 -04001368
1369 init_MUTEX(&ec_ecdt->burst.sem);
1370 init_waitqueue_head(&ec_ecdt->burst.wait);
1371 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -04001372 acpi_ec_io_ports, ec_ecdt);
Luming Yu45bea152005-07-23 04:08:00 -04001373 if (ACPI_FAILURE(status))
1374 return status;
1375 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
1376
1377 ec_ecdt->common.uid = -1;
1378 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
1379
Len Brown4be44fc2005-08-05 00:44:28 -04001380 status =
1381 acpi_evaluate_integer(handle, "_GPE", NULL,
1382 &ec_ecdt->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001383 if (ACPI_FAILURE(status))
1384 return status;
1385 ec_ecdt->common.global_lock = TRUE;
1386 ec_ecdt->common.handle = handle;
1387
Len Brown4be44fc2005-08-05 00:44:28 -04001388 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1389 (u32) ec_ecdt->common.gpe_bit,
1390 (u32) ec_ecdt->common.command_addr.address,
1391 (u32) ec_ecdt->common.data_addr.address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393 return AE_CTRL_TERMINATE;
1394}
1395
1396/*
1397 * Some BIOS (such as some from Gateway laptops) access EC region very early
1398 * such as in BAT0._INI or EC._INI before an EC device is found and
1399 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
1400 * required, but if EC regison is accessed early, it is required.
1401 * The routine tries to workaround the BIOS bug by pre-scan EC device
1402 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
1403 * op region (since _REG isn't invoked yet). The assumption is true for
1404 * all systems found.
1405 */
Len Brown4be44fc2005-08-05 00:44:28 -04001406static int __init acpi_ec_fake_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Len Brown4be44fc2005-08-05 00:44:28 -04001408 acpi_status status;
1409 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n");
1412
Luming Yu45bea152005-07-23 04:08:00 -04001413 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (!ec_ecdt) {
1415 ret = -ENOMEM;
1416 goto error;
1417 }
Luming Yu45bea152005-07-23 04:08:00 -04001418 memset(ec_ecdt, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Len Brown4be44fc2005-08-05 00:44:28 -04001420 status = acpi_get_devices(ACPI_EC_HID,
1421 acpi_fake_ecdt_callback, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (ACPI_FAILURE(status)) {
1423 kfree(ec_ecdt);
1424 ec_ecdt = NULL;
1425 ret = -ENODEV;
1426 goto error;
1427 }
1428 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001429 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 printk(KERN_ERR PREFIX "Can't make an fake ECDT\n");
1431 return ret;
1432}
1433
Len Brown4be44fc2005-08-05 00:44:28 -04001434static int __init acpi_ec_get_real_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
Luming Yu45bea152005-07-23 04:08:00 -04001436 if (acpi_ec_polling_mode)
1437 return acpi_ec_polling_get_real_ecdt();
1438 else
1439 return acpi_ec_burst_get_real_ecdt();
1440}
1441
Len Brown4be44fc2005-08-05 00:44:28 -04001442static int __init acpi_ec_polling_get_real_ecdt(void)
Luming Yu45bea152005-07-23 04:08:00 -04001443{
Len Brown4be44fc2005-08-05 00:44:28 -04001444 acpi_status status;
1445 struct acpi_table_ecdt *ecdt_ptr;
Luming Yu45bea152005-07-23 04:08:00 -04001446
Len Brown4be44fc2005-08-05 00:44:28 -04001447 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
1448 (struct acpi_table_header **)
1449 &ecdt_ptr);
Luming Yu45bea152005-07-23 04:08:00 -04001450 if (ACPI_FAILURE(status))
1451 return -ENODEV;
1452
1453 printk(KERN_INFO PREFIX "Found ECDT\n");
1454
1455 /*
1456 * Generate a temporary ec context to use until the namespace is scanned
1457 */
1458 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1459 if (!ec_ecdt)
1460 return -ENOMEM;
1461 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1462
1463 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1464 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1465 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1466 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
1467 spin_lock_init(&ec_ecdt->polling.lock);
1468 /* use the GL just to be safe */
1469 ec_ecdt->common.global_lock = TRUE;
1470 ec_ecdt->common.uid = ecdt_ptr->uid;
1471
Len Brown4be44fc2005-08-05 00:44:28 -04001472 status =
1473 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
Luming Yu45bea152005-07-23 04:08:00 -04001474 if (ACPI_FAILURE(status)) {
1475 goto error;
1476 }
1477
1478 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001479 error:
Luming Yu45bea152005-07-23 04:08:00 -04001480 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1481 kfree(ec_ecdt);
1482 ec_ecdt = NULL;
1483
1484 return -ENODEV;
1485}
1486
Len Brown4be44fc2005-08-05 00:44:28 -04001487static int __init acpi_ec_burst_get_real_ecdt(void)
Luming Yu45bea152005-07-23 04:08:00 -04001488{
Len Brown4be44fc2005-08-05 00:44:28 -04001489 acpi_status status;
1490 struct acpi_table_ecdt *ecdt_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Dmitry Torokhov451566f2005-03-19 01:10:05 -05001492 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
Len Brown4be44fc2005-08-05 00:44:28 -04001493 (struct acpi_table_header **)
1494 &ecdt_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (ACPI_FAILURE(status))
1496 return -ENODEV;
1497
1498 printk(KERN_INFO PREFIX "Found ECDT\n");
1499
1500 /*
1501 * Generate a temporary ec context to use until the namespace is scanned
1502 */
Luming Yu45bea152005-07-23 04:08:00 -04001503 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 if (!ec_ecdt)
1505 return -ENOMEM;
Luming Yu45bea152005-07-23 04:08:00 -04001506 memset(ec_ecdt, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Len Brown4be44fc2005-08-05 00:44:28 -04001508 init_MUTEX(&ec_ecdt->burst.sem);
1509 init_waitqueue_head(&ec_ecdt->burst.wait);
Luming Yu45bea152005-07-23 04:08:00 -04001510 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1511 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1512 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1513 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 /* use the GL just to be safe */
Luming Yu45bea152005-07-23 04:08:00 -04001515 ec_ecdt->common.global_lock = TRUE;
1516 ec_ecdt->common.uid = ecdt_ptr->uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Len Brown4be44fc2005-08-05 00:44:28 -04001518 status =
1519 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 if (ACPI_FAILURE(status)) {
1521 goto error;
1522 }
1523
1524 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001525 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1527 kfree(ec_ecdt);
1528 ec_ecdt = NULL;
1529
1530 return -ENODEV;
1531}
1532
1533static int __initdata acpi_fake_ecdt_enabled;
Len Brown4be44fc2005-08-05 00:44:28 -04001534int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Len Brown4be44fc2005-08-05 00:44:28 -04001536 acpi_status status;
1537 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 ret = acpi_ec_get_real_ecdt();
1540 /* Try to make a fake ECDT */
1541 if (ret && acpi_fake_ecdt_enabled) {
1542 ret = acpi_ec_fake_ecdt();
1543 }
1544
1545 if (ret)
1546 return 0;
1547
1548 /*
1549 * Install GPE handler
1550 */
Luming Yu45bea152005-07-23 04:08:00 -04001551 status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
Len Brown4be44fc2005-08-05 00:44:28 -04001552 ACPI_GPE_EDGE_TRIGGERED,
1553 &acpi_ec_gpe_handler, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 if (ACPI_FAILURE(status)) {
1555 goto error;
1556 }
Len Brown4be44fc2005-08-05 00:44:28 -04001557 acpi_set_gpe_type(NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1558 acpi_enable_gpe(NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Len Brown4be44fc2005-08-05 00:44:28 -04001560 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
1561 ACPI_ADR_SPACE_EC,
1562 &acpi_ec_space_handler,
1563 &acpi_ec_space_setup,
1564 ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 if (ACPI_FAILURE(status)) {
Luming Yu45bea152005-07-23 04:08:00 -04001566 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
Len Brown4be44fc2005-08-05 00:44:28 -04001567 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 goto error;
1569 }
1570
1571 return 0;
1572
Len Brown4be44fc2005-08-05 00:44:28 -04001573 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1575 kfree(ec_ecdt);
1576 ec_ecdt = NULL;
1577
1578 return -ENODEV;
1579}
1580
Len Brown4be44fc2005-08-05 00:44:28 -04001581static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582{
Len Brown4be44fc2005-08-05 00:44:28 -04001583 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 ACPI_FUNCTION_TRACE("acpi_ec_init");
1586
1587 if (acpi_disabled)
1588 return_VALUE(0);
1589
1590 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1591 if (!acpi_ec_dir)
1592 return_VALUE(-ENODEV);
1593
1594 /* Now register the driver for the EC */
1595 result = acpi_bus_register_driver(&acpi_ec_driver);
1596 if (result < 0) {
1597 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1598 return_VALUE(-ENODEV);
1599 }
1600
1601 return_VALUE(result);
1602}
1603
1604subsys_initcall(acpi_ec_init);
1605
1606/* EC driver currently not unloadable */
1607#if 0
Len Brown4be44fc2005-08-05 00:44:28 -04001608static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
1610 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1611
1612 acpi_bus_unregister_driver(&acpi_ec_driver);
1613
1614 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1615
1616 return_VOID;
1617}
Len Brown4be44fc2005-08-05 00:44:28 -04001618#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620static int __init acpi_fake_ecdt_setup(char *str)
1621{
1622 acpi_fake_ecdt_enabled = 1;
1623 return 0;
1624}
Luming Yu7b15f5e2005-08-03 17:38:04 -04001625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
Luming Yu45bea152005-07-23 04:08:00 -04001627static int __init acpi_ec_set_polling_mode(char *str)
1628{
Luming Yu7b15f5e2005-08-03 17:38:04 -04001629 int burst;
1630
1631 if (!get_option(&str, &burst))
1632 return 0;
1633
1634 if (burst) {
1635 acpi_ec_polling_mode = EC_BURST;
1636 acpi_ec_driver.ops.add = acpi_ec_burst_add;
1637 } else {
1638 acpi_ec_polling_mode = EC_POLLING;
1639 acpi_ec_driver.ops.add = acpi_ec_polling_add;
1640 }
Len Brown4be44fc2005-08-05 00:44:28 -04001641 printk(KERN_INFO PREFIX "EC %s mode.\n", burst ? "burst" : "polling");
Luming Yu45bea152005-07-23 04:08:00 -04001642 return 0;
1643}
Len Brown4be44fc2005-08-05 00:44:28 -04001644
Luming Yu7b15f5e2005-08-03 17:38:04 -04001645__setup("ec_burst=", acpi_ec_set_polling_mode);