blob: d2638209c6049a5eb15e4914686e3e90b4dc62dd [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 Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -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
Len Brown02b28a32005-12-05 16:33:04 -050063#define EC_POLL 0xFF
64#define EC_INTR 0x00
Len Brown50526df2005-08-11 17:32:05 -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);
Len Brown02b28a32005-12-05 16:33:04 -050068static int acpi_ec_intr_add(struct acpi_device *device);
69static int acpi_ec_poll_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static struct acpi_driver acpi_ec_driver = {
Len Brown50526df2005-08-11 17:32:05 -040072 .name = ACPI_EC_DRIVER_NAME,
73 .class = ACPI_EC_CLASS,
74 .ids = ACPI_EC_HID,
75 .ops = {
Len Brown53f11d42005-12-05 16:46:36 -050076 .add = acpi_ec_intr_add,
Len Brown50526df2005-08-11 17:32:05 -040077 .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 Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -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;
Len Brown02b28a32005-12-05 16:33:04 -0500108 } intr;
Luming Yu45bea152005-07-23 04:08:00 -0400109
110 struct {
Len Brown50526df2005-08-11 17:32:05 -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;
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500119 struct semaphore sem;
Len Brown02b28a32005-12-05 16:33:04 -0500120 } poll;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121};
122
Len Brown02b28a32005-12-05 16:33:04 -0500123static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event);
124static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event);
125static int acpi_ec_poll_read(union acpi_ec *ec, u8 address, u32 * data);
126static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data);
127static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data);
128static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data);
129static int acpi_ec_poll_query(union acpi_ec *ec, u32 * data);
130static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data);
131static void acpi_ec_gpe_poll_query(void *ec_cxt);
132static void acpi_ec_gpe_intr_query(void *ec_cxt);
133static u32 acpi_ec_gpe_poll_handler(void *data);
134static u32 acpi_ec_gpe_intr_handler(void *data);
Luming Yu45bea152005-07-23 04:08:00 -0400135static acpi_status __init
Len Brown02b28a32005-12-05 16:33:04 -0500136acpi_fake_ecdt_poll_callback(acpi_handle handle,
Len Brown50526df2005-08-11 17:32:05 -0400137 u32 Level, void *context, void **retval);
Luming Yu45bea152005-07-23 04:08:00 -0400138
139static acpi_status __init
Len Brown02b28a32005-12-05 16:33:04 -0500140acpi_fake_ecdt_intr_callback(acpi_handle handle,
Len Brown50526df2005-08-11 17:32:05 -0400141 u32 Level, void *context, void **retval);
Luming Yu45bea152005-07-23 04:08:00 -0400142
Len Brown02b28a32005-12-05 16:33:04 -0500143static int __init acpi_ec_poll_get_real_ecdt(void);
144static int __init acpi_ec_intr_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 Brown50526df2005-08-11 17:32:05 -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;
Len Brown53f11d42005-12-05 16:46:36 -0500150static int acpi_ec_poll_mode = EC_INTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* --------------------------------------------------------------------------
153 Transaction Management
154 -------------------------------------------------------------------------- */
155
Arjan van de Ven858119e2006-01-14 13:20:43 -0800156static u32 acpi_ec_read_status(union acpi_ec *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -0400164static int acpi_ec_wait(union acpi_ec *ec, u8 event)
Luming Yu45bea152005-07-23 04:08:00 -0400165{
Len Brown02b28a32005-12-05 16:33:04 -0500166 if (acpi_ec_poll_mode)
167 return acpi_ec_poll_wait(ec, event);
Luming Yu45bea152005-07-23 04:08:00 -0400168 else
Len Brown02b28a32005-12-05 16:33:04 -0500169 return acpi_ec_intr_wait(ec, event);
Luming Yu45bea152005-07-23 04:08:00 -0400170}
171
Len Brown02b28a32005-12-05 16:33:04 -0500172static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event)
Luming Yu45bea152005-07-23 04:08:00 -0400173{
Len Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -0400189 } while (--i > 0);
Luming Yu45bea152005-07-23 04:08:00 -0400190 break;
191 case ACPI_EC_EVENT_IBE:
192 do {
Len Brown50526df2005-08-11 17:32:05 -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 Brown50526df2005-08-11 17:32:05 -0400198 } while (--i > 0);
Luming Yu45bea152005-07-23 04:08:00 -0400199 break;
200 default:
201 return -EINVAL;
202 }
203
204 return -ETIME;
205}
Len Brown02b28a32005-12-05 16:33:04 -0500206static int acpi_ec_intr_wait(union acpi_ec *ec, unsigned int event)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500207{
Len Brown50526df2005-08-11 17:32:05 -0400208 int result = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500209
210 ACPI_FUNCTION_TRACE("acpi_ec_wait");
211
Len Brown02b28a32005-12-05 16:33:04 -0500212 ec->intr.expect_event = event;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500213 smp_mb();
214
Luming Yu716e0842005-08-10 01:40:00 -0400215 switch (event) {
Luming Yu716e0842005-08-10 01:40:00 -0400216 case ACPI_EC_EVENT_IBE:
217 if (~acpi_ec_read_status(ec) & event) {
Len Brown02b28a32005-12-05 16:33:04 -0500218 ec->intr.expect_event = 0;
Luming Yu716e0842005-08-10 01:40:00 -0400219 return_VALUE(0);
220 }
221 break;
Luming Yu06a2a382005-09-27 00:43:00 -0400222 default:
Luming Yu716e0842005-08-10 01:40:00 -0400223 break;
224 }
225
Len Brown02b28a32005-12-05 16:33:04 -0500226 result = wait_event_timeout(ec->intr.wait,
227 !ec->intr.expect_event,
Len Brown50526df2005-08-11 17:32:05 -0400228 msecs_to_jiffies(ACPI_EC_DELAY));
229
Len Brown02b28a32005-12-05 16:33:04 -0500230 ec->intr.expect_event = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500231 smp_mb();
232
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500233 /*
234 * Verify that the event in question has actually happened by
235 * querying EC status. Do the check even if operation timed-out
236 * to make sure that we did not miss interrupt.
237 */
238 switch (event) {
239 case ACPI_EC_EVENT_OBF:
240 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
241 return_VALUE(0);
242 break;
243
244 case ACPI_EC_EVENT_IBE:
245 if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)
246 return_VALUE(0);
247 break;
248 }
249
250 return_VALUE(-ETIME);
251}
252
Len Brown02b28a32005-12-05 16:33:04 -0500253#ifdef ACPI_FUTURE_USAGE
Luming Yu06a2a382005-09-27 00:43:00 -0400254/*
255 * Note: samsung nv5000 doesn't work with ec burst mode.
256 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
257 */
258int acpi_ec_enter_burst_mode(union acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500259{
Len Brown50526df2005-08-11 17:32:05 -0400260 u32 tmp = 0;
261 int status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500262
263 ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode");
264
265 status = acpi_ec_read_status(ec);
Len Brown50526df2005-08-11 17:32:05 -0400266 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
Luming Yu716e0842005-08-10 01:40:00 -0400267 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Len Brown50526df2005-08-11 17:32:05 -0400268 if (status)
Luming Yu716e0842005-08-10 01:40:00 -0400269 goto end;
Len Brown50526df2005-08-11 17:32:05 -0400270 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE,
271 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500272 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
Luming Yu45bea152005-07-23 04:08:00 -0400273 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
Len Brown50526df2005-08-11 17:32:05 -0400274 if (tmp != 0x90) { /* Burst ACK byte */
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500275 return_VALUE(-EINVAL);
276 }
Luming Yu668d74c2005-07-23 00:26:33 -0400277 }
278
Len Brown02b28a32005-12-05 16:33:04 -0500279 atomic_set(&ec->intr.leaving_burst, 0);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500280 return_VALUE(0);
Len Brown50526df2005-08-11 17:32:05 -0400281 end:
Len Brown1e8df532005-12-05 16:47:46 -0500282 printk(KERN_WARNING PREFIX "Error in acpi_ec_wait\n");
Luming Yu716e0842005-08-10 01:40:00 -0400283 return_VALUE(-1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500284}
285
Luming Yu06a2a382005-09-27 00:43:00 -0400286int acpi_ec_leave_burst_mode(union acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500287{
Luming Yu06a2a382005-09-27 00:43:00 -0400288 int status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500289
290 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
291
Luming Yu06a2a382005-09-27 00:43:00 -0400292 status = acpi_ec_read_status(ec);
293 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){
294 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
295 if(status)
296 goto end;
297 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr);
298 acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
299 }
Len Brown02b28a32005-12-05 16:33:04 -0500300 atomic_set(&ec->intr.leaving_burst, 1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500301 return_VALUE(0);
Luming Yu06a2a382005-09-27 00:43:00 -0400302end:
Len Brown1e8df532005-12-05 16:47:46 -0500303 printk(KERN_WARNING PREFIX "leave burst_mode:error\n");
Luming Yu06a2a382005-09-27 00:43:00 -0400304 return_VALUE(-1);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500305}
Len Brown02b28a32005-12-05 16:33:04 -0500306#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Len Brown50526df2005-08-11 17:32:05 -0400308static int acpi_ec_read(union acpi_ec *ec, u8 address, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400309{
Len Brown02b28a32005-12-05 16:33:04 -0500310 if (acpi_ec_poll_mode)
311 return acpi_ec_poll_read(ec, address, data);
Luming Yu45bea152005-07-23 04:08:00 -0400312 else
Len Brown02b28a32005-12-05 16:33:04 -0500313 return acpi_ec_intr_read(ec, address, data);
Luming Yu45bea152005-07-23 04:08:00 -0400314}
Len Brown50526df2005-08-11 17:32:05 -0400315static int acpi_ec_write(union acpi_ec *ec, u8 address, u8 data)
Luming Yu45bea152005-07-23 04:08:00 -0400316{
Len Brown02b28a32005-12-05 16:33:04 -0500317 if (acpi_ec_poll_mode)
318 return acpi_ec_poll_write(ec, address, data);
Luming Yu45bea152005-07-23 04:08:00 -0400319 else
Len Brown02b28a32005-12-05 16:33:04 -0500320 return acpi_ec_intr_write(ec, address, data);
Luming Yu45bea152005-07-23 04:08:00 -0400321}
Len Brown02b28a32005-12-05 16:33:04 -0500322static int acpi_ec_poll_read(union acpi_ec *ec, u8 address, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400323{
Len Brown50526df2005-08-11 17:32:05 -0400324 acpi_status status = AE_OK;
325 int result = 0;
Len Brown50526df2005-08-11 17:32:05 -0400326 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400327
328 ACPI_FUNCTION_TRACE("acpi_ec_read");
329
330 if (!ec || !data)
331 return_VALUE(-EINVAL);
332
333 *data = 0;
334
335 if (ec->common.global_lock) {
336 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
337 if (ACPI_FAILURE(status))
338 return_VALUE(-ENODEV);
339 }
340
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500341 if (down_interruptible(&ec->poll.sem)) {
342 result = -ERESTARTSYS;
343 goto end_nosem;
344 }
345
Len Brown50526df2005-08-11 17:32:05 -0400346 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ,
347 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400348 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
349 if (result)
350 goto end;
351
352 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
353 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
354 if (result)
355 goto end;
356
357 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
358
359 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
Len Brown50526df2005-08-11 17:32:05 -0400360 *data, address));
361
362 end:
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500363 up(&ec->poll.sem);
364end_nosem:
Luming Yu45bea152005-07-23 04:08:00 -0400365 if (ec->common.global_lock)
366 acpi_release_global_lock(glk);
367
368 return_VALUE(result);
369}
370
Len Brown02b28a32005-12-05 16:33:04 -0500371static int acpi_ec_poll_write(union acpi_ec *ec, u8 address, u8 data)
Luming Yu45bea152005-07-23 04:08:00 -0400372{
Len Brown50526df2005-08-11 17:32:05 -0400373 int result = 0;
374 acpi_status status = AE_OK;
Len Brown50526df2005-08-11 17:32:05 -0400375 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400376
377 ACPI_FUNCTION_TRACE("acpi_ec_write");
378
379 if (!ec)
380 return_VALUE(-EINVAL);
381
382 if (ec->common.global_lock) {
383 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
384 if (ACPI_FAILURE(status))
385 return_VALUE(-ENODEV);
386 }
387
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500388 if (down_interruptible(&ec->poll.sem)) {
389 result = -ERESTARTSYS;
390 goto end_nosem;
391 }
392
Len Brown50526df2005-08-11 17:32:05 -0400393 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE,
394 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400395 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
396 if (result)
397 goto end;
398
399 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
400 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
401 if (result)
402 goto end;
403
404 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
405 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
406 if (result)
407 goto end;
408
409 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
Len Brown50526df2005-08-11 17:32:05 -0400410 data, address));
Luming Yu45bea152005-07-23 04:08:00 -0400411
Len Brown50526df2005-08-11 17:32:05 -0400412 end:
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500413 up(&ec->poll.sem);
414end_nosem:
Luming Yu45bea152005-07-23 04:08:00 -0400415 if (ec->common.global_lock)
416 acpi_release_global_lock(glk);
417
418 return_VALUE(result);
419}
420
Len Brown02b28a32005-12-05 16:33:04 -0500421static int acpi_ec_intr_read(union acpi_ec *ec, u8 address, u32 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Len Brown50526df2005-08-11 17:32:05 -0400423 int status = 0;
424 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 ACPI_FUNCTION_TRACE("acpi_ec_read");
427
428 if (!ec || !data)
429 return_VALUE(-EINVAL);
430
431 *data = 0;
432
Luming Yu45bea152005-07-23 04:08:00 -0400433 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
435 if (ACPI_FAILURE(status))
436 return_VALUE(-ENODEV);
437 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500438
439 WARN_ON(in_interrupt());
Len Brown02b28a32005-12-05 16:33:04 -0500440 down(&ec->intr.sem);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500441
Luming Yu716e0842005-08-10 01:40:00 -0400442 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
443 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500444 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500445 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400446 }
Len Brown50526df2005-08-11 17:32:05 -0400447 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ,
448 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500449 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500450 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500451 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Luming Yu45bea152005-07-23 04:08:00 -0400454 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
Len Brown50526df2005-08-11 17:32:05 -0400455 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
456 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500457 printk(KERN_DEBUG PREFIX "read EC, OB not full\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500459 }
Luming Yu45bea152005-07-23 04:08:00 -0400460 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
Len Brown50526df2005-08-11 17:32:05 -0400462 *data, address));
463
464 end:
Len Brown02b28a32005-12-05 16:33:04 -0500465 up(&ec->intr.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Luming Yu45bea152005-07-23 04:08:00 -0400467 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 acpi_release_global_lock(glk);
469
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500470 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Len Brown02b28a32005-12-05 16:33:04 -0500473static int acpi_ec_intr_write(union acpi_ec *ec, u8 address, u8 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Len Brown50526df2005-08-11 17:32:05 -0400475 int status = 0;
476 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 ACPI_FUNCTION_TRACE("acpi_ec_write");
479
480 if (!ec)
481 return_VALUE(-EINVAL);
Luming Yu716e0842005-08-10 01:40:00 -0400482
Luming Yu45bea152005-07-23 04:08:00 -0400483 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
485 if (ACPI_FAILURE(status))
486 return_VALUE(-ENODEV);
487 }
488
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500489 WARN_ON(in_interrupt());
Len Brown02b28a32005-12-05 16:33:04 -0500490 down(&ec->intr.sem);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500491
Luming Yu716e0842005-08-10 01:40:00 -0400492 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Len Brown50526df2005-08-11 17:32:05 -0400493 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500494 printk(KERN_DEBUG PREFIX "write EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500495 }
Len Brown50526df2005-08-11 17:32:05 -0400496 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE,
497 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500498 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Luming Yu716e0842005-08-10 01:40:00 -0400499 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500500 printk(KERN_DEBUG PREFIX "write EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Luming Yu45bea152005-07-23 04:08:00 -0400503 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500504 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
Len Brown50526df2005-08-11 17:32:05 -0400505 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500506 printk(KERN_DEBUG PREFIX "write EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Luming Yu45bea152005-07-23 04:08:00 -0400509 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
Len Brown50526df2005-08-11 17:32:05 -0400512 data, address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Len Brown02b28a32005-12-05 16:33:04 -0500514 up(&ec->intr.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Luming Yu45bea152005-07-23 04:08:00 -0400516 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 acpi_release_global_lock(glk);
518
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500519 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522/*
523 * Externally callable EC access functions. For now, assume 1 EC only
524 */
Len Brown50526df2005-08-11 17:32:05 -0400525int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Luming Yu45bea152005-07-23 04:08:00 -0400527 union acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 int err;
529 u32 temp_data;
530
531 if (!first_ec)
532 return -ENODEV;
533
534 ec = acpi_driver_data(first_ec);
535
536 err = acpi_ec_read(ec, addr, &temp_data);
537
538 if (!err) {
539 *val = temp_data;
540 return 0;
Len Brown50526df2005-08-11 17:32:05 -0400541 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 return err;
543}
Len Brown50526df2005-08-11 17:32:05 -0400544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545EXPORT_SYMBOL(ec_read);
546
Len Brown50526df2005-08-11 17:32:05 -0400547int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Luming Yu45bea152005-07-23 04:08:00 -0400549 union acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 int err;
551
552 if (!first_ec)
553 return -ENODEV;
554
555 ec = acpi_driver_data(first_ec);
556
557 err = acpi_ec_write(ec, addr, val);
558
559 return err;
560}
Len Brown50526df2005-08-11 17:32:05 -0400561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562EXPORT_SYMBOL(ec_write);
563
Len Brown50526df2005-08-11 17:32:05 -0400564static int acpi_ec_query(union acpi_ec *ec, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400565{
Len Brown02b28a32005-12-05 16:33:04 -0500566 if (acpi_ec_poll_mode)
567 return acpi_ec_poll_query(ec, data);
Luming Yu45bea152005-07-23 04:08:00 -0400568 else
Len Brown02b28a32005-12-05 16:33:04 -0500569 return acpi_ec_intr_query(ec, data);
Luming Yu45bea152005-07-23 04:08:00 -0400570}
Len Brown02b28a32005-12-05 16:33:04 -0500571static int acpi_ec_poll_query(union acpi_ec *ec, u32 * data)
Luming Yu45bea152005-07-23 04:08:00 -0400572{
Len Brown50526df2005-08-11 17:32:05 -0400573 int result = 0;
574 acpi_status status = AE_OK;
Len Brown50526df2005-08-11 17:32:05 -0400575 u32 glk = 0;
Luming Yu45bea152005-07-23 04:08:00 -0400576
577 ACPI_FUNCTION_TRACE("acpi_ec_query");
578
579 if (!ec || !data)
580 return_VALUE(-EINVAL);
581
582 *data = 0;
583
584 if (ec->common.global_lock) {
585 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
586 if (ACPI_FAILURE(status))
587 return_VALUE(-ENODEV);
588 }
589
590 /*
591 * Query the EC to find out which _Qxx method we need to evaluate.
592 * Note that successful completion of the query causes the ACPI_EC_SCI
593 * bit to be cleared (and thus clearing the interrupt source).
594 */
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500595 if (down_interruptible(&ec->poll.sem)) {
596 result = -ERESTARTSYS;
597 goto end_nosem;
598 }
599
Len Brown50526df2005-08-11 17:32:05 -0400600 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY,
601 &ec->common.command_addr);
Luming Yu45bea152005-07-23 04:08:00 -0400602 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
603 if (result)
604 goto end;
605
606 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
607 if (!*data)
608 result = -ENODATA;
609
Len Brown50526df2005-08-11 17:32:05 -0400610 end:
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500611 up(&ec->poll.sem);
612end_nosem:
Luming Yu45bea152005-07-23 04:08:00 -0400613 if (ec->common.global_lock)
614 acpi_release_global_lock(glk);
615
616 return_VALUE(result);
617}
Len Brown02b28a32005-12-05 16:33:04 -0500618static int acpi_ec_intr_query(union acpi_ec *ec, u32 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Len Brown50526df2005-08-11 17:32:05 -0400620 int status = 0;
621 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 ACPI_FUNCTION_TRACE("acpi_ec_query");
624
625 if (!ec || !data)
626 return_VALUE(-EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 *data = 0;
628
Luming Yu45bea152005-07-23 04:08:00 -0400629 if (ec->common.global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
631 if (ACPI_FAILURE(status))
632 return_VALUE(-ENODEV);
633 }
634
Len Brown02b28a32005-12-05 16:33:04 -0500635 down(&ec->intr.sem);
Luming Yu716e0842005-08-10 01:40:00 -0400636
637 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
638 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500639 printk(KERN_DEBUG PREFIX "query EC, IB not empty\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500640 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 /*
643 * Query the EC to find out which _Qxx method we need to evaluate.
644 * Note that successful completion of the query causes the ACPI_EC_SCI
645 * bit to be cleared (and thus clearing the interrupt source).
646 */
Len Brown50526df2005-08-11 17:32:05 -0400647 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY,
648 &ec->common.command_addr);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500649 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
Len Brown50526df2005-08-11 17:32:05 -0400650 if (status) {
Len Brown1e8df532005-12-05 16:47:46 -0500651 printk(KERN_DEBUG PREFIX "query EC, OB not full\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 goto end;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500653 }
654
Luming Yu45bea152005-07-23 04:08:00 -0400655 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (!*data)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500657 status = -ENODATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Len Brown50526df2005-08-11 17:32:05 -0400659 end:
Len Brown02b28a32005-12-05 16:33:04 -0500660 up(&ec->intr.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Luming Yu45bea152005-07-23 04:08:00 -0400662 if (ec->common.global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 acpi_release_global_lock(glk);
664
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500665 return_VALUE(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668/* --------------------------------------------------------------------------
669 Event Management
670 -------------------------------------------------------------------------- */
671
Luming Yu45bea152005-07-23 04:08:00 -0400672union acpi_ec_query_data {
Len Brown50526df2005-08-11 17:32:05 -0400673 acpi_handle handle;
674 u8 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675};
676
Len Brown50526df2005-08-11 17:32:05 -0400677static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown02b28a32005-12-05 16:33:04 -0500679 if (acpi_ec_poll_mode)
680 acpi_ec_gpe_poll_query(ec_cxt);
Luming Yu45bea152005-07-23 04:08:00 -0400681 else
Len Brown02b28a32005-12-05 16:33:04 -0500682 acpi_ec_gpe_intr_query(ec_cxt);
Luming Yu45bea152005-07-23 04:08:00 -0400683}
684
Len Brown02b28a32005-12-05 16:33:04 -0500685static void acpi_ec_gpe_poll_query(void *ec_cxt)
Luming Yu45bea152005-07-23 04:08:00 -0400686{
Len Brown50526df2005-08-11 17:32:05 -0400687 union acpi_ec *ec = (union acpi_ec *)ec_cxt;
688 u32 value = 0;
Len Brown50526df2005-08-11 17:32:05 -0400689 static char object_name[5] = { '_', 'Q', '0', '0', '\0' };
690 const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
691 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
692 };
Luming Yu45bea152005-07-23 04:08:00 -0400693
694 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
695
696 if (!ec_cxt)
697 goto end;
698
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500699 if (down_interruptible (&ec->poll.sem)) {
700 return_VOID;
701 }
Luming Yu45bea152005-07-23 04:08:00 -0400702 acpi_hw_low_level_read(8, &value, &ec->common.command_addr);
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -0500703 up(&ec->poll.sem);
Luming Yu45bea152005-07-23 04:08:00 -0400704
705 /* TBD: Implement asynch events!
706 * NOTE: All we care about are EC-SCI's. Other EC events are
707 * handled via polling (yuck!). This is because some systems
708 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
709 * a purely interrupt-driven approach (grumble, grumble).
710 */
711 if (!(value & ACPI_EC_FLAG_SCI))
712 goto end;
713
714 if (acpi_ec_query(ec, &value))
715 goto end;
716
717 object_name[2] = hex[((value >> 4) & 0x0F)];
718 object_name[3] = hex[(value & 0x0F)];
719
720 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
721
722 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
723
Len Brown50526df2005-08-11 17:32:05 -0400724 end:
Luming Yu45bea152005-07-23 04:08:00 -0400725 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
726}
Len Brown02b28a32005-12-05 16:33:04 -0500727static void acpi_ec_gpe_intr_query(void *ec_cxt)
Luming Yu45bea152005-07-23 04:08:00 -0400728{
Len Brown50526df2005-08-11 17:32:05 -0400729 union acpi_ec *ec = (union acpi_ec *)ec_cxt;
730 u32 value;
731 int result = -ENODATA;
732 static char object_name[5] = { '_', 'Q', '0', '0', '\0' };
733 const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
734 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
735 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
738
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500739 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI)
740 result = acpi_ec_query(ec, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500742 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 goto end;
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 object_name[2] = hex[((value >> 4) & 0x0F)];
746 object_name[3] = hex[(value & 0x0F)];
747
748 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
749
Luming Yu45bea152005-07-23 04:08:00 -0400750 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
Len Brown50526df2005-08-11 17:32:05 -0400751 end:
Len Brown02b28a32005-12-05 16:33:04 -0500752 atomic_dec(&ec->intr.pending_gpe);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500753 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
Len Brown50526df2005-08-11 17:32:05 -0400756static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Len Brown02b28a32005-12-05 16:33:04 -0500758 if (acpi_ec_poll_mode)
759 return acpi_ec_gpe_poll_handler(data);
Luming Yu45bea152005-07-23 04:08:00 -0400760 else
Len Brown02b28a32005-12-05 16:33:04 -0500761 return acpi_ec_gpe_intr_handler(data);
Luming Yu45bea152005-07-23 04:08:00 -0400762}
Len Brown02b28a32005-12-05 16:33:04 -0500763static u32 acpi_ec_gpe_poll_handler(void *data)
Luming Yu45bea152005-07-23 04:08:00 -0400764{
Len Brown50526df2005-08-11 17:32:05 -0400765 acpi_status status = AE_OK;
766 union acpi_ec *ec = (union acpi_ec *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 if (!ec)
769 return ACPI_INTERRUPT_NOT_HANDLED;
770
Luming Yu45bea152005-07-23 04:08:00 -0400771 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
772
773 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
Len Brown50526df2005-08-11 17:32:05 -0400774 acpi_ec_gpe_query, ec);
Luming Yu45bea152005-07-23 04:08:00 -0400775
776 if (status == AE_OK)
777 return ACPI_INTERRUPT_HANDLED;
778 else
779 return ACPI_INTERRUPT_NOT_HANDLED;
780}
Len Brown02b28a32005-12-05 16:33:04 -0500781static u32 acpi_ec_gpe_intr_handler(void *data)
Luming Yu45bea152005-07-23 04:08:00 -0400782{
Len Brown50526df2005-08-11 17:32:05 -0400783 acpi_status status = AE_OK;
784 u32 value;
785 union acpi_ec *ec = (union acpi_ec *)data;
Luming Yu45bea152005-07-23 04:08:00 -0400786
787 if (!ec)
788 return ACPI_INTERRUPT_NOT_HANDLED;
789
Luming Yu716e0842005-08-10 01:40:00 -0400790 acpi_clear_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500791 value = acpi_ec_read_status(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Len Brown02b28a32005-12-05 16:33:04 -0500793 switch (ec->intr.expect_event) {
Luming Yu716e0842005-08-10 01:40:00 -0400794 case ACPI_EC_EVENT_OBF:
795 if (!(value & ACPI_EC_FLAG_OBF))
796 break;
797 case ACPI_EC_EVENT_IBE:
798 if ((value & ACPI_EC_FLAG_IBF))
799 break;
Len Brown02b28a32005-12-05 16:33:04 -0500800 ec->intr.expect_event = 0;
801 wake_up(&ec->intr.wait);
Luming Yu716e0842005-08-10 01:40:00 -0400802 return ACPI_INTERRUPT_HANDLED;
803 default:
804 break;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500805 }
806
Len Brown50526df2005-08-11 17:32:05 -0400807 if (value & ACPI_EC_FLAG_SCI) {
Len Brown02b28a32005-12-05 16:33:04 -0500808 atomic_add(1, &ec->intr.pending_gpe);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500809 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
Len Brown50526df2005-08-11 17:32:05 -0400810 acpi_ec_gpe_query, ec);
Luming Yu17e9c782005-04-22 23:07:10 -0400811 return status == AE_OK ?
Len Brown50526df2005-08-11 17:32:05 -0400812 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
813 }
Luming Yu45bea152005-07-23 04:08:00 -0400814 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500815 return status == AE_OK ?
Len Brown50526df2005-08-11 17:32:05 -0400816 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
819/* --------------------------------------------------------------------------
820 Address Space Management
821 -------------------------------------------------------------------------- */
822
823static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400824acpi_ec_space_setup(acpi_handle region_handle,
825 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 /*
828 * The EC object is in the handler context and is needed
829 * when calling the acpi_ec_space_handler.
830 */
Len Brown50526df2005-08-11 17:32:05 -0400831 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
832 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 return AE_OK;
835}
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400838acpi_ec_space_handler(u32 function,
839 acpi_physical_address address,
840 u32 bit_width,
841 acpi_integer * value,
842 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Len Brown50526df2005-08-11 17:32:05 -0400844 int result = 0;
845 union acpi_ec *ec = NULL;
846 u64 temp = *value;
847 acpi_integer f_v = 0;
848 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 ACPI_FUNCTION_TRACE("acpi_ec_space_handler");
851
852 if ((address > 0xFF) || !value || !handler_context)
853 return_VALUE(AE_BAD_PARAMETER);
854
Luming Yufa9cd542005-03-19 01:54:47 -0500855 if (bit_width != 8 && acpi_strict) {
Len Brown50526df2005-08-11 17:32:05 -0400856 printk(KERN_WARNING PREFIX
857 "acpi_ec_space_handler: bit_width should be 8\n");
Luming Yufa9cd542005-03-19 01:54:47 -0500858 return_VALUE(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860
Len Brown50526df2005-08-11 17:32:05 -0400861 ec = (union acpi_ec *)handler_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Len Brown50526df2005-08-11 17:32:05 -0400863 next_byte:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 switch (function) {
865 case ACPI_READ:
Luming Yufa9cd542005-03-19 01:54:47 -0500866 temp = 0;
Len Brown50526df2005-08-11 17:32:05 -0400867 result = acpi_ec_read(ec, (u8) address, (u32 *) & temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 break;
869 case ACPI_WRITE:
Luming Yufa9cd542005-03-19 01:54:47 -0500870 result = acpi_ec_write(ec, (u8) address, (u8) temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 break;
872 default:
873 result = -EINVAL;
874 goto out;
875 break;
876 }
877
878 bit_width -= 8;
Luming Yufa9cd542005-03-19 01:54:47 -0500879 if (bit_width) {
880 if (function == ACPI_READ)
881 f_v |= temp << 8 * i;
882 if (function == ACPI_WRITE)
883 temp >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 i++;
Andrew Morton83ea7442005-03-30 22:12:13 -0500885 address++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 goto next_byte;
887 }
888
Luming Yufa9cd542005-03-19 01:54:47 -0500889 if (function == ACPI_READ) {
890 f_v |= temp << 8 * i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 *value = f_v;
892 }
893
Len Brown50526df2005-08-11 17:32:05 -0400894 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 switch (result) {
896 case -EINVAL:
897 return_VALUE(AE_BAD_PARAMETER);
898 break;
899 case -ENODEV:
900 return_VALUE(AE_NOT_FOUND);
901 break;
902 case -ETIME:
903 return_VALUE(AE_TIME);
904 break;
905 default:
906 return_VALUE(AE_OK);
907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910/* --------------------------------------------------------------------------
911 FS Interface (/proc)
912 -------------------------------------------------------------------------- */
913
Len Brown50526df2005-08-11 17:32:05 -0400914static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Len Brown50526df2005-08-11 17:32:05 -0400916static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Len Brown50526df2005-08-11 17:32:05 -0400918 union acpi_ec *ec = (union acpi_ec *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
921
922 if (!ec)
923 goto end;
924
925 seq_printf(seq, "gpe bit: 0x%02x\n",
Len Brown50526df2005-08-11 17:32:05 -0400926 (u32) ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
Len Brown50526df2005-08-11 17:32:05 -0400928 (u32) ec->common.status_addr.address,
929 (u32) ec->common.data_addr.address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 seq_printf(seq, "use global lock: %s\n",
Len Brown50526df2005-08-11 17:32:05 -0400931 ec->common.global_lock ? "yes" : "no");
Luming Yu45bea152005-07-23 04:08:00 -0400932 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Len Brown50526df2005-08-11 17:32:05 -0400934 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return_VALUE(0);
936}
937
938static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
939{
940 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
941}
942
943static struct file_operations acpi_ec_info_ops = {
Len Brown50526df2005-08-11 17:32:05 -0400944 .open = acpi_ec_info_open_fs,
945 .read = seq_read,
946 .llseek = seq_lseek,
947 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 .owner = THIS_MODULE,
949};
950
Len Brown50526df2005-08-11 17:32:05 -0400951static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Len Brown50526df2005-08-11 17:32:05 -0400953 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
956
957 if (!acpi_device_dir(device)) {
958 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown50526df2005-08-11 17:32:05 -0400959 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (!acpi_device_dir(device))
961 return_VALUE(-ENODEV);
962 }
963
964 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown50526df2005-08-11 17:32:05 -0400965 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 if (!entry)
967 ACPI_DEBUG_PRINT((ACPI_DB_WARN,
Len Brown50526df2005-08-11 17:32:05 -0400968 "Unable to create '%s' fs entry\n",
969 ACPI_EC_FILE_INFO));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 else {
971 entry->proc_fops = &acpi_ec_info_ops;
972 entry->data = acpi_driver_data(device);
973 entry->owner = THIS_MODULE;
974 }
975
976 return_VALUE(0);
977}
978
Len Brown50526df2005-08-11 17:32:05 -0400979static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980{
981 ACPI_FUNCTION_TRACE("acpi_ec_remove_fs");
982
983 if (acpi_device_dir(device)) {
984 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
985 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
986 acpi_device_dir(device) = NULL;
987 }
988
989 return_VALUE(0);
990}
991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992/* --------------------------------------------------------------------------
993 Driver Interface
994 -------------------------------------------------------------------------- */
995
Len Brown02b28a32005-12-05 16:33:04 -0500996static int acpi_ec_poll_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Len Brown50526df2005-08-11 17:32:05 -0400998 int result = 0;
999 acpi_status status = AE_OK;
1000 union acpi_ec *ec = NULL;
1001 unsigned long uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 ACPI_FUNCTION_TRACE("acpi_ec_add");
1004
1005 if (!device)
1006 return_VALUE(-EINVAL);
1007
Luming Yu45bea152005-07-23 04:08:00 -04001008 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (!ec)
1010 return_VALUE(-ENOMEM);
Luming Yu45bea152005-07-23 04:08:00 -04001011 memset(ec, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Luming Yu45bea152005-07-23 04:08:00 -04001013 ec->common.handle = device->handle;
1014 ec->common.uid = -1;
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -05001015 init_MUTEX(&ec->poll.sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1017 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1018 acpi_driver_data(device) = ec;
1019
1020 /* Use the global lock for all EC transactions? */
Len Brown50526df2005-08-11 17:32:05 -04001021 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL,
1022 &ec->common.global_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 /* If our UID matches the UID for the ECDT-enumerated EC,
Len Brown50526df2005-08-11 17:32:05 -04001025 we now have the *real* EC info, so kill the makeshift one. */
Luming Yu45bea152005-07-23 04:08:00 -04001026 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1027 if (ec_ecdt && ec_ecdt->common.uid == uid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown50526df2005-08-11 17:32:05 -04001029 ACPI_ADR_SPACE_EC,
1030 &acpi_ec_space_handler);
1031
1032 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1033 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035 kfree(ec_ecdt);
1036 }
1037
1038 /* Get GPE bit assignment (EC events). */
1039 /* TODO: Add support for _GPE returning a package */
Len Brown50526df2005-08-11 17:32:05 -04001040 status =
1041 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1042 &ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (ACPI_FAILURE(status)) {
1044 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown50526df2005-08-11 17:32:05 -04001045 "Error obtaining GPE bit assignment\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 result = -ENODEV;
1047 goto end;
1048 }
1049
1050 result = acpi_ec_add_fs(device);
1051 if (result)
1052 goto end;
1053
Len Brown02b28a32005-12-05 16:33:04 -05001054 printk(KERN_INFO PREFIX "%s [%s] (gpe %d) polling mode.\n",
Len Brown50526df2005-08-11 17:32:05 -04001055 acpi_device_name(device), acpi_device_bid(device),
1056 (u32) ec->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001057
1058 if (!first_ec)
1059 first_ec = device;
1060
Len Brown50526df2005-08-11 17:32:05 -04001061 end:
Luming Yu45bea152005-07-23 04:08:00 -04001062 if (result)
1063 kfree(ec);
1064
1065 return_VALUE(result);
1066}
Len Brown02b28a32005-12-05 16:33:04 -05001067static int acpi_ec_intr_add(struct acpi_device *device)
Luming Yu45bea152005-07-23 04:08:00 -04001068{
Len Brown50526df2005-08-11 17:32:05 -04001069 int result = 0;
1070 acpi_status status = AE_OK;
1071 union acpi_ec *ec = NULL;
1072 unsigned long uid;
Luming Yu45bea152005-07-23 04:08:00 -04001073
1074 ACPI_FUNCTION_TRACE("acpi_ec_add");
1075
1076 if (!device)
1077 return_VALUE(-EINVAL);
1078
1079 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1080 if (!ec)
1081 return_VALUE(-ENOMEM);
1082 memset(ec, 0, sizeof(union acpi_ec));
1083
1084 ec->common.handle = device->handle;
1085 ec->common.uid = -1;
Len Brown02b28a32005-12-05 16:33:04 -05001086 atomic_set(&ec->intr.pending_gpe, 0);
1087 atomic_set(&ec->intr.leaving_burst, 1);
1088 init_MUTEX(&ec->intr.sem);
1089 init_waitqueue_head(&ec->intr.wait);
Luming Yu45bea152005-07-23 04:08:00 -04001090 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1091 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1092 acpi_driver_data(device) = ec;
1093
1094 /* Use the global lock for all EC transactions? */
Len Brown50526df2005-08-11 17:32:05 -04001095 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL,
1096 &ec->common.global_lock);
Luming Yu45bea152005-07-23 04:08:00 -04001097
1098 /* If our UID matches the UID for the ECDT-enumerated EC,
Len Brown50526df2005-08-11 17:32:05 -04001099 we now have the *real* EC info, so kill the makeshift one. */
Luming Yu45bea152005-07-23 04:08:00 -04001100 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1101 if (ec_ecdt && ec_ecdt->common.uid == uid) {
1102 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown50526df2005-08-11 17:32:05 -04001103 ACPI_ADR_SPACE_EC,
1104 &acpi_ec_space_handler);
Luming Yu45bea152005-07-23 04:08:00 -04001105
Len Brown50526df2005-08-11 17:32:05 -04001106 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1107 &acpi_ec_gpe_handler);
Luming Yu45bea152005-07-23 04:08:00 -04001108
1109 kfree(ec_ecdt);
1110 }
1111
1112 /* Get GPE bit assignment (EC events). */
1113 /* TODO: Add support for _GPE returning a package */
Len Brown50526df2005-08-11 17:32:05 -04001114 status =
1115 acpi_evaluate_integer(ec->common.handle, "_GPE", NULL,
1116 &ec->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001117 if (ACPI_FAILURE(status)) {
1118 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown50526df2005-08-11 17:32:05 -04001119 "Error obtaining GPE bit assignment\n"));
Luming Yu45bea152005-07-23 04:08:00 -04001120 result = -ENODEV;
1121 goto end;
1122 }
1123
1124 result = acpi_ec_add_fs(device);
1125 if (result)
1126 goto end;
1127
Len Brown02b28a32005-12-05 16:33:04 -05001128 printk(KERN_INFO PREFIX "%s [%s] (gpe %d) interrupt mode.\n",
Len Brown50526df2005-08-11 17:32:05 -04001129 acpi_device_name(device), acpi_device_bid(device),
1130 (u32) ec->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 if (!first_ec)
1133 first_ec = device;
1134
Len Brown50526df2005-08-11 17:32:05 -04001135 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (result)
1137 kfree(ec);
1138
1139 return_VALUE(result);
1140}
1141
Len Brown50526df2005-08-11 17:32:05 -04001142static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143{
Len Brown50526df2005-08-11 17:32:05 -04001144 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 ACPI_FUNCTION_TRACE("acpi_ec_remove");
1147
1148 if (!device)
1149 return_VALUE(-EINVAL);
1150
1151 ec = acpi_driver_data(device);
1152
1153 acpi_ec_remove_fs(device);
1154
1155 kfree(ec);
1156
1157 return_VALUE(0);
1158}
1159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160static acpi_status
Len Brown50526df2005-08-11 17:32:05 -04001161acpi_ec_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162{
Len Brown50526df2005-08-11 17:32:05 -04001163 union acpi_ec *ec = (union acpi_ec *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 struct acpi_generic_address *addr;
1165
Bob Moore50eca3e2005-09-30 19:03:00 -04001166 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 return AE_OK;
1168 }
1169
1170 /*
1171 * The first address region returned is the data port, and
1172 * the second address region returned is the status/command
1173 * port.
1174 */
Luming Yu45bea152005-07-23 04:08:00 -04001175 if (ec->common.data_addr.register_bit_width == 0) {
1176 addr = &ec->common.data_addr;
1177 } else if (ec->common.command_addr.register_bit_width == 0) {
1178 addr = &ec->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 } else {
1180 return AE_CTRL_TERMINATE;
1181 }
1182
1183 addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO;
1184 addr->register_bit_width = 8;
1185 addr->register_bit_offset = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -04001186 addr->address = resource->data.io.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 return AE_OK;
1189}
1190
Len Brown50526df2005-08-11 17:32:05 -04001191static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Len Brown50526df2005-08-11 17:32:05 -04001193 acpi_status status = AE_OK;
1194 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 ACPI_FUNCTION_TRACE("acpi_ec_start");
1197
1198 if (!device)
1199 return_VALUE(-EINVAL);
1200
1201 ec = acpi_driver_data(device);
1202
1203 if (!ec)
1204 return_VALUE(-EINVAL);
1205
1206 /*
1207 * Get I/O port addresses. Convert to GAS format.
1208 */
Luming Yu45bea152005-07-23 04:08:00 -04001209 status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -04001210 acpi_ec_io_ports, ec);
1211 if (ACPI_FAILURE(status)
1212 || ec->common.command_addr.register_bit_width == 0) {
1213 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1214 "Error getting I/O port addresses"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 return_VALUE(-ENODEV);
1216 }
1217
Luming Yu45bea152005-07-23 04:08:00 -04001218 ec->common.status_addr = ec->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
Len Brown50526df2005-08-11 17:32:05 -04001221 (u32) ec->common.gpe_bit,
1222 (u32) ec->common.command_addr.address,
1223 (u32) ec->common.data_addr.address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 /*
1226 * Install GPE handler
1227 */
Luming Yu45bea152005-07-23 04:08:00 -04001228 status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit,
Len Brown50526df2005-08-11 17:32:05 -04001229 ACPI_GPE_EDGE_TRIGGERED,
1230 &acpi_ec_gpe_handler, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 if (ACPI_FAILURE(status)) {
1232 return_VALUE(-ENODEV);
1233 }
Len Brown50526df2005-08-11 17:32:05 -04001234 acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1235 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Len Brown50526df2005-08-11 17:32:05 -04001237 status = acpi_install_address_space_handler(ec->common.handle,
1238 ACPI_ADR_SPACE_EC,
1239 &acpi_ec_space_handler,
1240 &acpi_ec_space_setup, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 if (ACPI_FAILURE(status)) {
Len Brown50526df2005-08-11 17:32:05 -04001242 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1243 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 return_VALUE(-ENODEV);
1245 }
1246
1247 return_VALUE(AE_OK);
1248}
1249
Len Brown50526df2005-08-11 17:32:05 -04001250static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Len Brown50526df2005-08-11 17:32:05 -04001252 acpi_status status = AE_OK;
1253 union acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 ACPI_FUNCTION_TRACE("acpi_ec_stop");
1256
1257 if (!device)
1258 return_VALUE(-EINVAL);
1259
1260 ec = acpi_driver_data(device);
1261
Luming Yu45bea152005-07-23 04:08:00 -04001262 status = acpi_remove_address_space_handler(ec->common.handle,
Len Brown50526df2005-08-11 17:32:05 -04001263 ACPI_ADR_SPACE_EC,
1264 &acpi_ec_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (ACPI_FAILURE(status))
1266 return_VALUE(-ENODEV);
1267
Len Brown50526df2005-08-11 17:32:05 -04001268 status =
1269 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit,
1270 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if (ACPI_FAILURE(status))
1272 return_VALUE(-ENODEV);
1273
1274 return_VALUE(0);
1275}
1276
1277static acpi_status __init
Len Brown50526df2005-08-11 17:32:05 -04001278acpi_fake_ecdt_callback(acpi_handle handle,
1279 u32 Level, void *context, void **retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Luming Yu45bea152005-07-23 04:08:00 -04001281
Len Brown02b28a32005-12-05 16:33:04 -05001282 if (acpi_ec_poll_mode)
1283 return acpi_fake_ecdt_poll_callback(handle,
Len Brown50526df2005-08-11 17:32:05 -04001284 Level, context, retval);
Luming Yu45bea152005-07-23 04:08:00 -04001285 else
Len Brown02b28a32005-12-05 16:33:04 -05001286 return acpi_fake_ecdt_intr_callback(handle,
Len Brown50526df2005-08-11 17:32:05 -04001287 Level, context, retval);
Luming Yu45bea152005-07-23 04:08:00 -04001288}
1289
1290static acpi_status __init
Len Brown02b28a32005-12-05 16:33:04 -05001291acpi_fake_ecdt_poll_callback(acpi_handle handle,
Len Brown50526df2005-08-11 17:32:05 -04001292 u32 Level, void *context, void **retval)
Luming Yu45bea152005-07-23 04:08:00 -04001293{
Len Brown50526df2005-08-11 17:32:05 -04001294 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -04001297 acpi_ec_io_ports, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (ACPI_FAILURE(status))
1299 return status;
Luming Yu45bea152005-07-23 04:08:00 -04001300 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Luming Yu45bea152005-07-23 04:08:00 -04001302 ec_ecdt->common.uid = -1;
1303 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Len Brown50526df2005-08-11 17:32:05 -04001305 status =
1306 acpi_evaluate_integer(handle, "_GPE", NULL,
1307 &ec_ecdt->common.gpe_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (ACPI_FAILURE(status))
1309 return status;
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -05001310 init_MUTEX(&ec_ecdt->poll.sem);
Luming Yu45bea152005-07-23 04:08:00 -04001311 ec_ecdt->common.global_lock = TRUE;
1312 ec_ecdt->common.handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Len Brown50526df2005-08-11 17:32:05 -04001314 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1315 (u32) ec_ecdt->common.gpe_bit,
1316 (u32) ec_ecdt->common.command_addr.address,
1317 (u32) ec_ecdt->common.data_addr.address);
Luming Yu45bea152005-07-23 04:08:00 -04001318
1319 return AE_CTRL_TERMINATE;
1320}
1321
1322static acpi_status __init
Len Brown02b28a32005-12-05 16:33:04 -05001323acpi_fake_ecdt_intr_callback(acpi_handle handle,
Len Brown50526df2005-08-11 17:32:05 -04001324 u32 Level, void *context, void **retval)
Luming Yu45bea152005-07-23 04:08:00 -04001325{
Len Brown50526df2005-08-11 17:32:05 -04001326 acpi_status status;
Luming Yu45bea152005-07-23 04:08:00 -04001327
Len Brown02b28a32005-12-05 16:33:04 -05001328 init_MUTEX(&ec_ecdt->intr.sem);
1329 init_waitqueue_head(&ec_ecdt->intr.wait);
Luming Yu45bea152005-07-23 04:08:00 -04001330 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -04001331 acpi_ec_io_ports, ec_ecdt);
Luming Yu45bea152005-07-23 04:08:00 -04001332 if (ACPI_FAILURE(status))
1333 return status;
1334 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
1335
1336 ec_ecdt->common.uid = -1;
1337 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
1338
Len Brown50526df2005-08-11 17:32:05 -04001339 status =
1340 acpi_evaluate_integer(handle, "_GPE", NULL,
1341 &ec_ecdt->common.gpe_bit);
Luming Yu45bea152005-07-23 04:08:00 -04001342 if (ACPI_FAILURE(status))
1343 return status;
1344 ec_ecdt->common.global_lock = TRUE;
1345 ec_ecdt->common.handle = handle;
1346
Len Brown50526df2005-08-11 17:32:05 -04001347 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1348 (u32) ec_ecdt->common.gpe_bit,
1349 (u32) ec_ecdt->common.command_addr.address,
1350 (u32) ec_ecdt->common.data_addr.address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 return AE_CTRL_TERMINATE;
1353}
1354
1355/*
1356 * Some BIOS (such as some from Gateway laptops) access EC region very early
1357 * such as in BAT0._INI or EC._INI before an EC device is found and
1358 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
1359 * required, but if EC regison is accessed early, it is required.
1360 * The routine tries to workaround the BIOS bug by pre-scan EC device
1361 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
1362 * op region (since _REG isn't invoked yet). The assumption is true for
1363 * all systems found.
1364 */
Len Brown50526df2005-08-11 17:32:05 -04001365static int __init acpi_ec_fake_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
Len Brown50526df2005-08-11 17:32:05 -04001367 acpi_status status;
1368 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n");
1371
Luming Yu45bea152005-07-23 04:08:00 -04001372 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (!ec_ecdt) {
1374 ret = -ENOMEM;
1375 goto error;
1376 }
Luming Yu45bea152005-07-23 04:08:00 -04001377 memset(ec_ecdt, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Len Brown50526df2005-08-11 17:32:05 -04001379 status = acpi_get_devices(ACPI_EC_HID,
1380 acpi_fake_ecdt_callback, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (ACPI_FAILURE(status)) {
1382 kfree(ec_ecdt);
1383 ec_ecdt = NULL;
1384 ret = -ENODEV;
1385 goto error;
1386 }
1387 return 0;
Len Brown50526df2005-08-11 17:32:05 -04001388 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 printk(KERN_ERR PREFIX "Can't make an fake ECDT\n");
1390 return ret;
1391}
1392
Len Brown50526df2005-08-11 17:32:05 -04001393static int __init acpi_ec_get_real_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
Len Brown02b28a32005-12-05 16:33:04 -05001395 if (acpi_ec_poll_mode)
1396 return acpi_ec_poll_get_real_ecdt();
Luming Yu45bea152005-07-23 04:08:00 -04001397 else
Len Brown02b28a32005-12-05 16:33:04 -05001398 return acpi_ec_intr_get_real_ecdt();
Luming Yu45bea152005-07-23 04:08:00 -04001399}
1400
Len Brown02b28a32005-12-05 16:33:04 -05001401static int __init acpi_ec_poll_get_real_ecdt(void)
Luming Yu45bea152005-07-23 04:08:00 -04001402{
Len Brown50526df2005-08-11 17:32:05 -04001403 acpi_status status;
1404 struct acpi_table_ecdt *ecdt_ptr;
Luming Yu45bea152005-07-23 04:08:00 -04001405
Len Brown50526df2005-08-11 17:32:05 -04001406 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
1407 (struct acpi_table_header **)
1408 &ecdt_ptr);
Luming Yu45bea152005-07-23 04:08:00 -04001409 if (ACPI_FAILURE(status))
1410 return -ENODEV;
1411
1412 printk(KERN_INFO PREFIX "Found ECDT\n");
1413
1414 /*
1415 * Generate a temporary ec context to use until the namespace is scanned
1416 */
1417 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1418 if (!ec_ecdt)
1419 return -ENOMEM;
1420 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1421
1422 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1423 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1424 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1425 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
Rich Townsendf9a6ee1a2005-12-19 23:07:00 -05001426 init_MUTEX(&ec_ecdt->poll.sem);
Luming Yu45bea152005-07-23 04:08:00 -04001427 /* use the GL just to be safe */
1428 ec_ecdt->common.global_lock = TRUE;
1429 ec_ecdt->common.uid = ecdt_ptr->uid;
1430
Len Brown50526df2005-08-11 17:32:05 -04001431 status =
1432 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
Luming Yu45bea152005-07-23 04:08:00 -04001433 if (ACPI_FAILURE(status)) {
1434 goto error;
1435 }
1436
1437 return 0;
Len Brown50526df2005-08-11 17:32:05 -04001438 error:
Luming Yu45bea152005-07-23 04:08:00 -04001439 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1440 kfree(ec_ecdt);
1441 ec_ecdt = NULL;
1442
1443 return -ENODEV;
1444}
1445
Len Brown02b28a32005-12-05 16:33:04 -05001446static int __init acpi_ec_intr_get_real_ecdt(void)
Luming Yu45bea152005-07-23 04:08:00 -04001447{
Len Brown50526df2005-08-11 17:32:05 -04001448 acpi_status status;
1449 struct acpi_table_ecdt *ecdt_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Dmitry Torokhov451566f2005-03-19 01:10:05 -05001451 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
Len Brown50526df2005-08-11 17:32:05 -04001452 (struct acpi_table_header **)
1453 &ecdt_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if (ACPI_FAILURE(status))
1455 return -ENODEV;
1456
1457 printk(KERN_INFO PREFIX "Found ECDT\n");
1458
1459 /*
1460 * Generate a temporary ec context to use until the namespace is scanned
1461 */
Luming Yu45bea152005-07-23 04:08:00 -04001462 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 if (!ec_ecdt)
1464 return -ENOMEM;
Luming Yu45bea152005-07-23 04:08:00 -04001465 memset(ec_ecdt, 0, sizeof(union acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Len Brown02b28a32005-12-05 16:33:04 -05001467 init_MUTEX(&ec_ecdt->intr.sem);
1468 init_waitqueue_head(&ec_ecdt->intr.wait);
Luming Yu45bea152005-07-23 04:08:00 -04001469 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1470 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1471 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1472 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 /* use the GL just to be safe */
Luming Yu45bea152005-07-23 04:08:00 -04001474 ec_ecdt->common.global_lock = TRUE;
1475 ec_ecdt->common.uid = ecdt_ptr->uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Len Brown50526df2005-08-11 17:32:05 -04001477 status =
1478 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 if (ACPI_FAILURE(status)) {
1480 goto error;
1481 }
1482
1483 return 0;
Len Brown50526df2005-08-11 17:32:05 -04001484 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1486 kfree(ec_ecdt);
1487 ec_ecdt = NULL;
1488
1489 return -ENODEV;
1490}
1491
1492static int __initdata acpi_fake_ecdt_enabled;
Len Brown50526df2005-08-11 17:32:05 -04001493int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Len Brown50526df2005-08-11 17:32:05 -04001495 acpi_status status;
1496 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 ret = acpi_ec_get_real_ecdt();
1499 /* Try to make a fake ECDT */
1500 if (ret && acpi_fake_ecdt_enabled) {
1501 ret = acpi_ec_fake_ecdt();
1502 }
1503
1504 if (ret)
1505 return 0;
1506
1507 /*
1508 * Install GPE handler
1509 */
Luming Yu45bea152005-07-23 04:08:00 -04001510 status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
Len Brown50526df2005-08-11 17:32:05 -04001511 ACPI_GPE_EDGE_TRIGGERED,
1512 &acpi_ec_gpe_handler, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (ACPI_FAILURE(status)) {
1514 goto error;
1515 }
Len Brown50526df2005-08-11 17:32:05 -04001516 acpi_set_gpe_type(NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1517 acpi_enable_gpe(NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Len Brown50526df2005-08-11 17:32:05 -04001519 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
1520 ACPI_ADR_SPACE_EC,
1521 &acpi_ec_space_handler,
1522 &acpi_ec_space_setup,
1523 ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 if (ACPI_FAILURE(status)) {
Luming Yu45bea152005-07-23 04:08:00 -04001525 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
Len Brown50526df2005-08-11 17:32:05 -04001526 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 goto error;
1528 }
1529
1530 return 0;
1531
Len Brown50526df2005-08-11 17:32:05 -04001532 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1534 kfree(ec_ecdt);
1535 ec_ecdt = NULL;
1536
1537 return -ENODEV;
1538}
1539
Len Brown50526df2005-08-11 17:32:05 -04001540static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Len Brown50526df2005-08-11 17:32:05 -04001542 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 ACPI_FUNCTION_TRACE("acpi_ec_init");
1545
1546 if (acpi_disabled)
1547 return_VALUE(0);
1548
1549 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1550 if (!acpi_ec_dir)
1551 return_VALUE(-ENODEV);
1552
1553 /* Now register the driver for the EC */
1554 result = acpi_bus_register_driver(&acpi_ec_driver);
1555 if (result < 0) {
1556 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1557 return_VALUE(-ENODEV);
1558 }
1559
1560 return_VALUE(result);
1561}
1562
1563subsys_initcall(acpi_ec_init);
1564
1565/* EC driver currently not unloadable */
1566#if 0
Len Brown50526df2005-08-11 17:32:05 -04001567static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
1569 ACPI_FUNCTION_TRACE("acpi_ec_exit");
1570
1571 acpi_bus_unregister_driver(&acpi_ec_driver);
1572
1573 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1574
1575 return_VOID;
1576}
Len Brown50526df2005-08-11 17:32:05 -04001577#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579static int __init acpi_fake_ecdt_setup(char *str)
1580{
1581 acpi_fake_ecdt_enabled = 1;
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001582 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
Luming Yu7b15f5e2005-08-03 17:38:04 -04001584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
Len Brown02b28a32005-12-05 16:33:04 -05001586static int __init acpi_ec_set_intr_mode(char *str)
Luming Yu45bea152005-07-23 04:08:00 -04001587{
Len Brown02b28a32005-12-05 16:33:04 -05001588 int intr;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001589
Len Brown02b28a32005-12-05 16:33:04 -05001590 if (!get_option(&str, &intr))
Luming Yu7b15f5e2005-08-03 17:38:04 -04001591 return 0;
1592
Len Brown02b28a32005-12-05 16:33:04 -05001593 if (intr) {
1594 acpi_ec_poll_mode = EC_INTR;
1595 acpi_ec_driver.ops.add = acpi_ec_intr_add;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001596 } else {
Len Brown02b28a32005-12-05 16:33:04 -05001597 acpi_ec_poll_mode = EC_POLL;
1598 acpi_ec_driver.ops.add = acpi_ec_poll_add;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001599 }
Len Brown02b28a32005-12-05 16:33:04 -05001600 printk(KERN_INFO PREFIX "EC %s mode.\n", intr ? "interrupt" : "polling");
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001601 return 1;
Luming Yu45bea152005-07-23 04:08:00 -04001602}
Len Brown50526df2005-08-11 17:32:05 -04001603
Len Brown53f11d42005-12-05 16:46:36 -05001604__setup("ec_intr=", acpi_ec_set_intr_mode);