Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / ec.c
CommitLineData
1da177e4 1/*
7c6db4e0 2 * ec.c - ACPI Embedded Controller Driver (v2.1)
1da177e4 3 *
7c6db4e0 4 * Copyright (C) 2006-2008 Alexey Starikovskiy <astarikovskiy@suse.de>
01f22462 5 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
1da177e4
LT
6 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
7 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
8 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 */
28
7c6db4e0 29/* Uncomment next line to get verbose printout */
d772b3b3
MN
30/* #define DEBUG */
31
1da177e4
LT
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/types.h>
36#include <linux/delay.h>
37#include <linux/proc_fs.h>
38#include <linux/seq_file.h>
451566f4 39#include <linux/interrupt.h>
837012ed 40#include <linux/list.h>
7c6db4e0 41#include <linux/spinlock.h>
1da177e4
LT
42#include <asm/io.h>
43#include <acpi/acpi_bus.h>
44#include <acpi/acpi_drivers.h>
1da177e4 45
1da177e4 46#define ACPI_EC_CLASS "embedded_controller"
1da177e4
LT
47#define ACPI_EC_DEVICE_NAME "Embedded Controller"
48#define ACPI_EC_FILE_INFO "info"
837012ed 49
af3fd140
AS
50#undef PREFIX
51#define PREFIX "ACPI: EC: "
4350933a 52
703959d4 53/* EC status register */
1da177e4
LT
54#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
55#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
451566f4 56#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
1da177e4 57#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
4350933a 58
703959d4 59/* EC commands */
3261ff4d 60enum ec_command {
6ccedb10
AS
61 ACPI_EC_COMMAND_READ = 0x80,
62 ACPI_EC_COMMAND_WRITE = 0x81,
63 ACPI_EC_BURST_ENABLE = 0x82,
64 ACPI_EC_BURST_DISABLE = 0x83,
65 ACPI_EC_COMMAND_QUERY = 0x84,
3261ff4d 66};
837012ed 67
5c406412 68#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
703959d4 69#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
e6e82a30 70#define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */
703959d4 71
06cf7d3c 72#define ACPI_EC_STORM_THRESHOLD 8 /* number of false interrupts
7c6db4e0
AS
73 per one transaction */
74
080e412c 75enum {
080e412c 76 EC_FLAGS_QUERY_PENDING, /* Query is pending */
7c6db4e0
AS
77 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent
78 * for status change */
b77d81b2 79 EC_FLAGS_NO_GPE, /* Don't use GPE mode */
7c6db4e0
AS
80 EC_FLAGS_GPE_STORM, /* GPE storm detected */
81 EC_FLAGS_HANDLERS_INSTALLED /* Handlers for GPE and
82 * OpReg are installed */
1da177e4 83};
6ffb221a
DS
84
85/* If we find an EC via the ECDT, we need to keep a ptr to its context */
d033879c 86/* External interfaces use first EC only, so remember */
837012ed
AS
87typedef int (*acpi_ec_query_func) (void *data);
88
89struct acpi_ec_query_handler {
90 struct list_head node;
91 acpi_ec_query_func func;
92 acpi_handle handle;
93 void *data;
94 u8 query_bit;
95};
96
8463200a 97struct transaction {
7c6db4e0
AS
98 const u8 *wdata;
99 u8 *rdata;
100 unsigned short irq_count;
8463200a 101 u8 command;
a2f93aea
AS
102 u8 wi;
103 u8 ri;
7c6db4e0
AS
104 u8 wlen;
105 u8 rlen;
dd15f8c4 106 bool done;
7c6db4e0
AS
107};
108
a854e08a 109static struct acpi_ec {
703959d4 110 acpi_handle handle;
a86e2772 111 unsigned long gpe;
6ffb221a
DS
112 unsigned long command_addr;
113 unsigned long data_addr;
703959d4 114 unsigned long global_lock;
080e412c 115 unsigned long flags;
c787a855 116 struct mutex lock;
703959d4 117 wait_queue_head_t wait;
837012ed 118 struct list_head list;
8463200a
AS
119 struct transaction *curr;
120 spinlock_t curr_lock;
d033879c 121} *boot_ec, *first_ec;
703959d4 122
5423a0cb
AS
123static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
124
1da177e4
LT
125/* --------------------------------------------------------------------------
126 Transaction Management
127 -------------------------------------------------------------------------- */
128
6ffb221a 129static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
1da177e4 130{
3ebe08a7 131 u8 x = inb(ec->command_addr);
86dae015 132 pr_debug(PREFIX "---> status = 0x%2.2x\n", x);
3ebe08a7 133 return x;
451566f4
DT
134}
135
6ffb221a 136static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
703959d4 137{
3ebe08a7 138 u8 x = inb(ec->data_addr);
86dae015 139 pr_debug(PREFIX "---> data = 0x%2.2x\n", x);
7c6db4e0 140 return x;
7c6db5e5
DS
141}
142
6ffb221a 143static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
45bea155 144{
86dae015 145 pr_debug(PREFIX "<--- command = 0x%2.2x\n", command);
6ffb221a 146 outb(command, ec->command_addr);
45bea155
LY
147}
148
6ffb221a 149static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
45bea155 150{
86dae015 151 pr_debug(PREFIX "<--- data = 0x%2.2x\n", data);
6ffb221a 152 outb(data, ec->data_addr);
703959d4 153}
45bea155 154
7c6db4e0 155static int ec_transaction_done(struct acpi_ec *ec)
6ffb221a 156{
7c6db4e0
AS
157 unsigned long flags;
158 int ret = 0;
8463200a 159 spin_lock_irqsave(&ec->curr_lock, flags);
dd15f8c4 160 if (!ec->curr || ec->curr->done)
7c6db4e0 161 ret = 1;
8463200a 162 spin_unlock_irqrestore(&ec->curr_lock, flags);
7c6db4e0 163 return ret;
45bea155 164}
451566f4 165
a2f93aea
AS
166static void start_transaction(struct acpi_ec *ec)
167{
168 ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0;
169 ec->curr->done = false;
170 acpi_ec_write_cmd(ec, ec->curr->command);
171}
172
7c6db4e0 173static void gpe_transaction(struct acpi_ec *ec, u8 status)
7c6db5e5 174{
7c6db4e0 175 unsigned long flags;
8463200a
AS
176 spin_lock_irqsave(&ec->curr_lock, flags);
177 if (!ec->curr)
7c6db4e0 178 goto unlock;
a2f93aea
AS
179 if (ec->curr->wlen > ec->curr->wi) {
180 if ((status & ACPI_EC_FLAG_IBF) == 0)
181 acpi_ec_write_data(ec,
182 ec->curr->wdata[ec->curr->wi++]);
183 else
dd15f8c4 184 goto err;
a2f93aea 185 } else if (ec->curr->rlen > ec->curr->ri) {
7c6db4e0 186 if ((status & ACPI_EC_FLAG_OBF) == 1) {
a2f93aea
AS
187 ec->curr->rdata[ec->curr->ri++] = acpi_ec_read_data(ec);
188 if (ec->curr->rlen == ec->curr->ri)
dd15f8c4 189 ec->curr->done = true;
7c6db4e0 190 } else
dd15f8c4 191 goto err;
a2f93aea
AS
192 } else if (ec->curr->wlen == ec->curr->wi &&
193 (status & ACPI_EC_FLAG_IBF) == 0)
dd15f8c4
AS
194 ec->curr->done = true;
195 goto unlock;
196err:
197 /* false interrupt, state didn't change */
7b4d4692
AS
198 if (in_interrupt())
199 ++ec->curr->irq_count;
7c6db4e0 200unlock:
8463200a 201 spin_unlock_irqrestore(&ec->curr_lock, flags);
845625cd 202}
03d1d99c 203
7c6db4e0 204static int acpi_ec_wait(struct acpi_ec *ec)
845625cd 205{
7c6db4e0
AS
206 if (wait_event_timeout(ec->wait, ec_transaction_done(ec),
207 msecs_to_jiffies(ACPI_EC_DELAY)))
208 return 0;
a2f93aea
AS
209 /* try restart command if we get any false interrupts */
210 if (ec->curr->irq_count &&
211 (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) == 0) {
212 pr_debug(PREFIX "controller reset, restart transaction\n");
213 start_transaction(ec);
214 if (wait_event_timeout(ec->wait, ec_transaction_done(ec),
215 msecs_to_jiffies(ACPI_EC_DELAY)))
216 return 0;
217 }
7c6db4e0
AS
218 /* missing GPEs, switch back to poll mode */
219 if (printk_ratelimit())
220 pr_info(PREFIX "missing confirmations, "
221 "switch off interrupt mode.\n");
b77d81b2 222 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
845625cd 223 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
7c6db4e0 224 return 1;
845625cd
AS
225}
226
7c6db4e0
AS
227static void acpi_ec_gpe_query(void *ec_cxt);
228
229static int ec_check_sci(struct acpi_ec *ec, u8 state)
7c6db5e5 230{
7c6db4e0
AS
231 if (state & ACPI_EC_FLAG_SCI) {
232 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
233 return acpi_os_execute(OSL_EC_BURST_HANDLER,
234 acpi_ec_gpe_query, ec);
235 }
236 return 0;
237}
238
239static int ec_poll(struct acpi_ec *ec)
240{
241 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
1cfe62c8 242 udelay(ACPI_EC_UDELAY);
7c6db4e0
AS
243 while (time_before(jiffies, delay)) {
244 gpe_transaction(ec, acpi_ec_read_status(ec));
1cfe62c8 245 udelay(ACPI_EC_UDELAY);
7c6db4e0 246 if (ec_transaction_done(ec))
9d699ed9 247 return 0;
af3fd140 248 }
b77d81b2 249 return -ETIME;
1da177e4
LT
250}
251
8463200a
AS
252static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
253 struct transaction *t,
00eb43a1 254 int force_poll)
45bea155 255{
7c6db4e0 256 unsigned long tmp;
7c6db4e0 257 int ret = 0;
3ebe08a7 258 pr_debug(PREFIX "transaction start\n");
7c6db4e0
AS
259 /* disable GPE during transaction if storm is detected */
260 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
261 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
0b7084ac 262 acpi_disable_gpe(NULL, ec->gpe);
3576cf61 263 }
5423a0cb
AS
264 if (EC_FLAGS_MSI)
265 udelay(ACPI_EC_DELAY);
7c6db4e0 266 /* start transaction */
8463200a 267 spin_lock_irqsave(&ec->curr_lock, tmp);
7c6db4e0 268 /* following two actions should be kept atomic */
8463200a 269 ec->curr = t;
a2f93aea 270 start_transaction(ec);
8463200a 271 if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
080e412c 272 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
8463200a 273 spin_unlock_irqrestore(&ec->curr_lock, tmp);
7c6db4e0
AS
274 /* if we selected poll mode or failed in GPE-mode do a poll loop */
275 if (force_poll ||
276 !test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ||
277 acpi_ec_wait(ec))
278 ret = ec_poll(ec);
3ebe08a7 279 pr_debug(PREFIX "transaction end\n");
8463200a
AS
280 spin_lock_irqsave(&ec->curr_lock, tmp);
281 ec->curr = NULL;
282 spin_unlock_irqrestore(&ec->curr_lock, tmp);
7c6db4e0
AS
283 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
284 /* check if we received SCI during transaction */
285 ec_check_sci(ec, acpi_ec_read_status(ec));
286 /* it is safe to enable GPE outside of transaction */
0b7084ac 287 acpi_enable_gpe(NULL, ec->gpe);
7c6db4e0 288 } else if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
8463200a 289 t->irq_count > ACPI_EC_STORM_THRESHOLD) {
f8248434
AJ
290 pr_info(PREFIX "GPE storm detected, "
291 "transactions will use polling mode\n");
7c6db4e0
AS
292 set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
293 }
294 return ret;
295}
296
297static int ec_check_ibf0(struct acpi_ec *ec)
298{
299 u8 status = acpi_ec_read_status(ec);
300 return (status & ACPI_EC_FLAG_IBF) == 0;
45bea155
LY
301}
302
c0ff1772
AS
303static int ec_wait_ibf0(struct acpi_ec *ec)
304{
305 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
306 /* interrupt wait manually if GPE mode is not active */
307 unsigned long timeout = test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ?
308 msecs_to_jiffies(ACPI_EC_DELAY) : msecs_to_jiffies(1);
309 while (time_before(jiffies, delay))
310 if (wait_event_timeout(ec->wait, ec_check_ibf0(ec), timeout))
311 return 0;
312 return -ETIME;
45bea155
LY
313}
314
8463200a 315static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t,
00eb43a1 316 int force_poll)
1da177e4 317{
d7a76e4c 318 int status;
50526df6 319 u32 glk;
8463200a 320 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
d550d98d 321 return -EINVAL;
8463200a
AS
322 if (t->rdata)
323 memset(t->rdata, 0, t->rlen);
523953b4 324 mutex_lock(&ec->lock);
703959d4 325 if (ec->global_lock) {
1da177e4 326 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
c24e912b 327 if (ACPI_FAILURE(status)) {
7c6db4e0
AS
328 status = -ENODEV;
329 goto unlock;
c24e912b 330 }
1da177e4 331 }
c0ff1772 332 if (ec_wait_ibf0(ec)) {
3ebe08a7
MN
333 pr_err(PREFIX "input buffer is not empty, "
334 "aborting transaction\n");
7c6db4e0 335 status = -ETIME;
451566f4 336 goto end;
716e084e 337 }
8463200a 338 status = acpi_ec_transaction_unlocked(ec, t, force_poll);
7c6db4e0 339end:
703959d4 340 if (ec->global_lock)
1da177e4 341 acpi_release_global_lock(glk);
7c6db4e0 342unlock:
523953b4 343 mutex_unlock(&ec->lock);
d550d98d 344 return status;
1da177e4
LT
345}
346
c45aac43
AS
347/*
348 * Note: samsung nv5000 doesn't work with ec burst mode.
349 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
350 */
8a383ef0 351static int acpi_ec_burst_enable(struct acpi_ec *ec)
c45aac43
AS
352{
353 u8 d;
8463200a
AS
354 struct transaction t = {.command = ACPI_EC_BURST_ENABLE,
355 .wdata = NULL, .rdata = &d,
356 .wlen = 0, .rlen = 1};
357
358 return acpi_ec_transaction(ec, &t, 0);
c45aac43
AS
359}
360
8a383ef0 361static int acpi_ec_burst_disable(struct acpi_ec *ec)
c45aac43 362{
8463200a
AS
363 struct transaction t = {.command = ACPI_EC_BURST_DISABLE,
364 .wdata = NULL, .rdata = NULL,
365 .wlen = 0, .rlen = 0};
366
7c6db4e0 367 return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
8463200a 368 acpi_ec_transaction(ec, &t, 0) : 0;
c45aac43
AS
369}
370
6ccedb10 371static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
3576cf61
DS
372{
373 int result;
374 u8 d;
8463200a
AS
375 struct transaction t = {.command = ACPI_EC_COMMAND_READ,
376 .wdata = &address, .rdata = &d,
377 .wlen = 1, .rlen = 1};
3576cf61 378
8463200a 379 result = acpi_ec_transaction(ec, &t, 0);
3576cf61
DS
380 *data = d;
381 return result;
382}
6ffb221a 383
3576cf61
DS
384static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
385{
6ccedb10 386 u8 wdata[2] = { address, data };
8463200a
AS
387 struct transaction t = {.command = ACPI_EC_COMMAND_WRITE,
388 .wdata = wdata, .rdata = NULL,
389 .wlen = 2, .rlen = 0};
390
391 return acpi_ec_transaction(ec, &t, 0);
3576cf61
DS
392}
393
1da177e4
LT
394/*
395 * Externally callable EC access functions. For now, assume 1 EC only
396 */
c45aac43
AS
397int ec_burst_enable(void)
398{
c45aac43
AS
399 if (!first_ec)
400 return -ENODEV;
d033879c 401 return acpi_ec_burst_enable(first_ec);
c45aac43
AS
402}
403
404EXPORT_SYMBOL(ec_burst_enable);
405
406int ec_burst_disable(void)
407{
c45aac43
AS
408 if (!first_ec)
409 return -ENODEV;
d033879c 410 return acpi_ec_burst_disable(first_ec);
c45aac43
AS
411}
412
413EXPORT_SYMBOL(ec_burst_disable);
414
6ccedb10 415int ec_read(u8 addr, u8 * val)
1da177e4 416{
1da177e4 417 int err;
6ffb221a 418 u8 temp_data;
1da177e4
LT
419
420 if (!first_ec)
421 return -ENODEV;
422
d033879c 423 err = acpi_ec_read(first_ec, addr, &temp_data);
1da177e4
LT
424
425 if (!err) {
426 *val = temp_data;
427 return 0;
50526df6 428 } else
1da177e4
LT
429 return err;
430}
50526df6 431
1da177e4
LT
432EXPORT_SYMBOL(ec_read);
433
50526df6 434int ec_write(u8 addr, u8 val)
1da177e4 435{
1da177e4
LT
436 int err;
437
438 if (!first_ec)
439 return -ENODEV;
440
d033879c 441 err = acpi_ec_write(first_ec, addr, val);
1da177e4
LT
442
443 return err;
444}
50526df6 445
1da177e4
LT
446EXPORT_SYMBOL(ec_write);
447
616362de 448int ec_transaction(u8 command,
9e197219 449 const u8 * wdata, unsigned wdata_len,
00eb43a1
LP
450 u8 * rdata, unsigned rdata_len,
451 int force_poll)
45bea155 452{
8463200a
AS
453 struct transaction t = {.command = command,
454 .wdata = wdata, .rdata = rdata,
455 .wlen = wdata_len, .rlen = rdata_len};
d7a76e4c
LP
456 if (!first_ec)
457 return -ENODEV;
45bea155 458
8463200a 459 return acpi_ec_transaction(first_ec, &t, force_poll);
45bea155 460}
1da177e4 461
ab9e43c6
LP
462EXPORT_SYMBOL(ec_transaction);
463
6ccedb10 464static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
3576cf61
DS
465{
466 int result;
6ccedb10 467 u8 d;
8463200a
AS
468 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
469 .wdata = NULL, .rdata = &d,
470 .wlen = 0, .rlen = 1};
6ccedb10
AS
471 if (!ec || !data)
472 return -EINVAL;
1da177e4 473
6ccedb10
AS
474 /*
475 * Query the EC to find out which _Qxx method we need to evaluate.
476 * Note that successful completion of the query causes the ACPI_EC_SCI
477 * bit to be cleared (and thus clearing the interrupt source).
478 */
716e084e 479
8463200a 480 result = acpi_ec_transaction(ec, &t, 0);
6ccedb10
AS
481 if (result)
482 return result;
1da177e4 483
6ccedb10
AS
484 if (!d)
485 return -ENODATA;
1da177e4 486
6ccedb10
AS
487 *data = d;
488 return 0;
1da177e4
LT
489}
490
1da177e4
LT
491/* --------------------------------------------------------------------------
492 Event Management
493 -------------------------------------------------------------------------- */
837012ed
AS
494int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
495 acpi_handle handle, acpi_ec_query_func func,
496 void *data)
497{
498 struct acpi_ec_query_handler *handler =
499 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
500 if (!handler)
501 return -ENOMEM;
502
503 handler->query_bit = query_bit;
504 handler->handle = handle;
505 handler->func = func;
506 handler->data = data;
507 mutex_lock(&ec->lock);
30c08574 508 list_add(&handler->node, &ec->list);
837012ed
AS
509 mutex_unlock(&ec->lock);
510 return 0;
511}
512
513EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
514
515void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
516{
1544fdbc 517 struct acpi_ec_query_handler *handler, *tmp;
837012ed 518 mutex_lock(&ec->lock);
1544fdbc 519 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
837012ed
AS
520 if (query_bit == handler->query_bit) {
521 list_del(&handler->node);
522 kfree(handler);
837012ed
AS
523 }
524 }
525 mutex_unlock(&ec->lock);
526}
527
528EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
1da177e4 529
50526df6 530static void acpi_ec_gpe_query(void *ec_cxt)
45bea155 531{
3d02b90b 532 struct acpi_ec *ec = ec_cxt;
6ffb221a 533 u8 value = 0;
837012ed 534 struct acpi_ec_query_handler *handler, copy;
45bea155 535
5d0c288b 536 if (!ec || acpi_ec_query(ec, &value))
e41334c0 537 return;
837012ed
AS
538 mutex_lock(&ec->lock);
539 list_for_each_entry(handler, &ec->list, node) {
540 if (value == handler->query_bit) {
541 /* have custom handler for this bit */
542 memcpy(&copy, handler, sizeof(copy));
543 mutex_unlock(&ec->lock);
544 if (copy.func) {
545 copy.func(copy.data);
546 } else if (copy.handle) {
547 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
548 }
549 return;
550 }
551 }
552 mutex_unlock(&ec->lock);
45bea155 553}
1da177e4 554
50526df6 555static u32 acpi_ec_gpe_handler(void *data)
1da177e4 556{
3d02b90b 557 struct acpi_ec *ec = data;
7c6db4e0 558 u8 status;
00eb43a1 559
3ebe08a7 560 pr_debug(PREFIX "~~~> interrupt\n");
7c6db4e0
AS
561 status = acpi_ec_read_status(ec);
562
8517934e
AS
563 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) {
564 gpe_transaction(ec, status);
565 if (ec_transaction_done(ec) &&
566 (status & ACPI_EC_FLAG_IBF) == 0)
567 wake_up(&ec->wait);
568 }
451566f4 569
7c6db4e0
AS
570 ec_check_sci(ec, status);
571 if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
572 !test_bit(EC_FLAGS_NO_GPE, &ec->flags)) {
95b937e3 573 /* this is non-query, must be confirmation */
f8248434
AJ
574 if (!test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
575 if (printk_ratelimit())
576 pr_info(PREFIX "non-query interrupt received,"
577 " switching to interrupt mode\n");
578 } else {
579 /* hush, STORM switches the mode every transaction */
580 pr_debug(PREFIX "non-query interrupt received,"
3ebe08a7 581 " switching to interrupt mode\n");
f8248434 582 }
7843932a 583 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
95b937e3 584 }
7c6db4e0 585 return ACPI_INTERRUPT_HANDLED;
845625cd
AS
586}
587
1da177e4
LT
588/* --------------------------------------------------------------------------
589 Address Space Management
590 -------------------------------------------------------------------------- */
591
1da177e4 592static acpi_status
5b7734b4
AS
593acpi_ec_space_handler(u32 function, acpi_physical_address address,
594 u32 bits, acpi_integer *value,
50526df6 595 void *handler_context, void *region_context)
1da177e4 596{
3d02b90b 597 struct acpi_ec *ec = handler_context;
3e71a87d 598 int result = 0, i;
5b7734b4 599 u8 temp = 0;
1da177e4 600
1da177e4 601 if ((address > 0xFF) || !value || !handler_context)
d550d98d 602 return AE_BAD_PARAMETER;
1da177e4 603
5b7734b4 604 if (function != ACPI_READ && function != ACPI_WRITE)
d550d98d 605 return AE_BAD_PARAMETER;
1da177e4 606
5b7734b4
AS
607 if (bits != 8 && acpi_strict)
608 return AE_BAD_PARAMETER;
1da177e4 609
b3b233c7
AS
610 acpi_ec_burst_enable(ec);
611
3e71a87d
AS
612 if (function == ACPI_READ) {
613 result = acpi_ec_read(ec, address, &temp);
614 *value = temp;
615 } else {
616 temp = 0xff & (*value);
617 result = acpi_ec_write(ec, address, temp);
618 }
619
620 for (i = 8; unlikely(bits - i > 0); i += 8) {
621 ++address;
5b7734b4
AS
622 if (function == ACPI_READ) {
623 result = acpi_ec_read(ec, address, &temp);
624 (*value) |= ((acpi_integer)temp) << i;
625 } else {
626 temp = 0xff & ((*value) >> i);
627 result = acpi_ec_write(ec, address, temp);
628 }
1da177e4
LT
629 }
630
b3b233c7
AS
631 acpi_ec_burst_disable(ec);
632
1da177e4
LT
633 switch (result) {
634 case -EINVAL:
d550d98d 635 return AE_BAD_PARAMETER;
1da177e4
LT
636 break;
637 case -ENODEV:
d550d98d 638 return AE_NOT_FOUND;
1da177e4
LT
639 break;
640 case -ETIME:
d550d98d 641 return AE_TIME;
1da177e4
LT
642 break;
643 default:
d550d98d 644 return AE_OK;
1da177e4 645 }
1da177e4
LT
646}
647
1da177e4
LT
648/* --------------------------------------------------------------------------
649 FS Interface (/proc)
650 -------------------------------------------------------------------------- */
651
50526df6 652static struct proc_dir_entry *acpi_ec_dir;
1da177e4 653
50526df6 654static int acpi_ec_read_info(struct seq_file *seq, void *offset)
1da177e4 655{
3d02b90b 656 struct acpi_ec *ec = seq->private;
1da177e4 657
1da177e4
LT
658 if (!ec)
659 goto end;
660
01f22462
AS
661 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
662 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
663 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
664 seq_printf(seq, "use global lock:\t%s\n",
703959d4 665 ec->global_lock ? "yes" : "no");
50526df6 666 end:
d550d98d 667 return 0;
1da177e4
LT
668}
669
670static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
671{
672 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
673}
674
703959d4 675static struct file_operations acpi_ec_info_ops = {
50526df6
LB
676 .open = acpi_ec_info_open_fs,
677 .read = seq_read,
678 .llseek = seq_lseek,
679 .release = single_release,
1da177e4
LT
680 .owner = THIS_MODULE,
681};
682
50526df6 683static int acpi_ec_add_fs(struct acpi_device *device)
1da177e4 684{
50526df6 685 struct proc_dir_entry *entry = NULL;
1da177e4 686
1da177e4
LT
687 if (!acpi_device_dir(device)) {
688 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
50526df6 689 acpi_ec_dir);
1da177e4 690 if (!acpi_device_dir(device))
d550d98d 691 return -ENODEV;
1da177e4
LT
692 }
693
cf7acfab
DL
694 entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO,
695 acpi_device_dir(device),
696 &acpi_ec_info_ops, acpi_driver_data(device));
1da177e4 697 if (!entry)
d550d98d 698 return -ENODEV;
d550d98d 699 return 0;
1da177e4
LT
700}
701
50526df6 702static int acpi_ec_remove_fs(struct acpi_device *device)
1da177e4 703{
1da177e4
LT
704
705 if (acpi_device_dir(device)) {
706 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
707 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
708 acpi_device_dir(device) = NULL;
709 }
710
d550d98d 711 return 0;
1da177e4
LT
712}
713
1da177e4
LT
714/* --------------------------------------------------------------------------
715 Driver Interface
716 -------------------------------------------------------------------------- */
c0900c35
AS
717static acpi_status
718ec_parse_io_ports(struct acpi_resource *resource, void *context);
719
c0900c35
AS
720static struct acpi_ec *make_acpi_ec(void)
721{
722 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
723 if (!ec)
724 return NULL;
080e412c 725 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
c0900c35
AS
726 mutex_init(&ec->lock);
727 init_waitqueue_head(&ec->wait);
837012ed 728 INIT_LIST_HEAD(&ec->list);
8463200a 729 spin_lock_init(&ec->curr_lock);
c0900c35
AS
730 return ec;
731}
837012ed 732
c019b193
AS
733static acpi_status
734acpi_ec_register_query_methods(acpi_handle handle, u32 level,
735 void *context, void **return_value)
736{
0175d562
LM
737 char node_name[5];
738 struct acpi_buffer buffer = { sizeof(node_name), node_name };
c019b193
AS
739 struct acpi_ec *ec = context;
740 int value = 0;
0175d562
LM
741 acpi_status status;
742
743 status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
744
745 if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1) {
c019b193
AS
746 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
747 }
748 return AE_OK;
749}
750
cd8c93a4
AS
751static acpi_status
752ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
837012ed 753{
cd8c93a4 754 acpi_status status;
d21cf3c1 755 unsigned long long tmp = 0;
cd8c93a4
AS
756
757 struct acpi_ec *ec = context;
758 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
759 ec_parse_io_ports, ec);
760 if (ACPI_FAILURE(status))
761 return status;
837012ed
AS
762
763 /* Get GPE bit assignment (EC events). */
764 /* TODO: Add support for _GPE returning a package */
27663c58 765 status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
cd8c93a4
AS
766 if (ACPI_FAILURE(status))
767 return status;
27663c58 768 ec->gpe = tmp;
837012ed 769 /* Use the global lock for all EC transactions? */
d21cf3c1 770 tmp = 0;
27663c58
MW
771 acpi_evaluate_integer(handle, "_GLK", NULL, &tmp);
772 ec->global_lock = tmp;
837012ed 773 ec->handle = handle;
cd8c93a4 774 return AE_CTRL_TERMINATE;
837012ed
AS
775}
776
4c611060
AS
777static void ec_remove_handlers(struct acpi_ec *ec)
778{
779 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
780 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
3ebe08a7 781 pr_err(PREFIX "failed to remove space handler\n");
4c611060
AS
782 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
783 &acpi_ec_gpe_handler)))
3ebe08a7 784 pr_err(PREFIX "failed to remove gpe handler\n");
7c6db4e0 785 clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
4c611060
AS
786}
787
703959d4 788static int acpi_ec_add(struct acpi_device *device)
1da177e4 789{
703959d4 790 struct acpi_ec *ec = NULL;
45bea155 791
45bea155 792 if (!device)
d550d98d 793 return -EINVAL;
c0900c35
AS
794 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
795 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
796
4c611060 797 /* Check for boot EC */
ce52ddf5
AS
798 if (boot_ec &&
799 (boot_ec->handle == device->handle ||
800 boot_ec->handle == ACPI_ROOT_OBJECT)) {
801 ec = boot_ec;
802 boot_ec = NULL;
803 } else {
804 ec = make_acpi_ec();
805 if (!ec)
806 return -ENOMEM;
807 if (ec_parse_device(device->handle, 0, ec, NULL) !=
808 AE_CTRL_TERMINATE) {
809 kfree(ec);
810 return -EINVAL;
4c611060
AS
811 }
812 }
813
c0900c35 814 ec->handle = device->handle;
ce52ddf5
AS
815
816 /* Find and register all query methods */
817 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
818 acpi_ec_register_query_methods, ec, NULL);
819
4c611060
AS
820 if (!first_ec)
821 first_ec = ec;
db89b4f0 822 device->driver_data = ec;
c0900c35 823 acpi_ec_add_fs(device);
3ebe08a7 824 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
4c611060 825 ec->gpe, ec->command_addr, ec->data_addr);
3ebe08a7 826 pr_info(PREFIX "driver started in %s mode\n",
95b937e3 827 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
c0900c35 828 return 0;
1da177e4
LT
829}
830
50526df6 831static int acpi_ec_remove(struct acpi_device *device, int type)
1da177e4 832{
01f22462 833 struct acpi_ec *ec;
07ddf768 834 struct acpi_ec_query_handler *handler, *tmp;
1da177e4 835
1da177e4 836 if (!device)
d550d98d 837 return -EINVAL;
1da177e4
LT
838
839 ec = acpi_driver_data(device);
837012ed 840 mutex_lock(&ec->lock);
07ddf768 841 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
837012ed
AS
842 list_del(&handler->node);
843 kfree(handler);
844 }
845 mutex_unlock(&ec->lock);
1da177e4 846 acpi_ec_remove_fs(device);
db89b4f0 847 device->driver_data = NULL;
d033879c 848 if (ec == first_ec)
c0900c35 849 first_ec = NULL;
4c611060 850 kfree(ec);
d550d98d 851 return 0;
1da177e4
LT
852}
853
1da177e4 854static acpi_status
c0900c35 855ec_parse_io_ports(struct acpi_resource *resource, void *context)
1da177e4 856{
3d02b90b 857 struct acpi_ec *ec = context;
1da177e4 858
01f22462 859 if (resource->type != ACPI_RESOURCE_TYPE_IO)
1da177e4 860 return AE_OK;
1da177e4
LT
861
862 /*
863 * The first address region returned is the data port, and
864 * the second address region returned is the status/command
865 * port.
866 */
01f22462 867 if (ec->data_addr == 0)
6ffb221a 868 ec->data_addr = resource->data.io.minimum;
01f22462 869 else if (ec->command_addr == 0)
6ffb221a 870 ec->command_addr = resource->data.io.minimum;
01f22462 871 else
1da177e4 872 return AE_CTRL_TERMINATE;
1da177e4 873
1da177e4
LT
874 return AE_OK;
875}
876
e8284321
AS
877static int ec_install_handlers(struct acpi_ec *ec)
878{
c0900c35 879 acpi_status status;
7c6db4e0 880 if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
4c611060 881 return 0;
c0900c35 882 status = acpi_install_gpe_handler(NULL, ec->gpe,
7c6db4e0
AS
883 ACPI_GPE_EDGE_TRIGGERED,
884 &acpi_ec_gpe_handler, ec);
e8284321
AS
885 if (ACPI_FAILURE(status))
886 return -ENODEV;
887 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
0b7084ac 888 acpi_enable_gpe(NULL, ec->gpe);
e8284321
AS
889 status = acpi_install_address_space_handler(ec->handle,
890 ACPI_ADR_SPACE_EC,
891 &acpi_ec_space_handler,
6d9e1120 892 NULL, ec);
e8284321 893 if (ACPI_FAILURE(status)) {
20edd74f
ZY
894 if (status == AE_NOT_FOUND) {
895 /*
896 * Maybe OS fails in evaluating the _REG object.
897 * The AE_NOT_FOUND error will be ignored and OS
898 * continue to initialize EC.
899 */
900 printk(KERN_ERR "Fail in evaluating the _REG object"
901 " of EC device. Broken bios is suspected.\n");
902 } else {
903 acpi_remove_gpe_handler(NULL, ec->gpe,
904 &acpi_ec_gpe_handler);
905 return -ENODEV;
906 }
e8284321
AS
907 }
908
7c6db4e0 909 set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
e8284321
AS
910 return 0;
911}
912
50526df6 913static int acpi_ec_start(struct acpi_device *device)
1da177e4 914{
c0900c35 915 struct acpi_ec *ec;
837012ed 916 int ret = 0;
1da177e4 917
1da177e4 918 if (!device)
d550d98d 919 return -EINVAL;
1da177e4
LT
920
921 ec = acpi_driver_data(device);
922
923 if (!ec)
d550d98d 924 return -EINVAL;
1da177e4 925
4c611060 926 ret = ec_install_handlers(ec);
837012ed
AS
927
928 /* EC is fully operational, allow queries */
080e412c 929 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
837012ed 930 return ret;
1da177e4
LT
931}
932
50526df6 933static int acpi_ec_stop(struct acpi_device *device, int type)
1da177e4 934{
c0900c35 935 struct acpi_ec *ec;
1da177e4 936 if (!device)
d550d98d 937 return -EINVAL;
1da177e4 938 ec = acpi_driver_data(device);
c0900c35
AS
939 if (!ec)
940 return -EINVAL;
4c611060 941 ec_remove_handlers(ec);
f9319f90 942
d550d98d 943 return 0;
1da177e4
LT
944}
945
c04209a7
AS
946int __init acpi_boot_ec_enable(void)
947{
7c6db4e0 948 if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
c04209a7
AS
949 return 0;
950 if (!ec_install_handlers(boot_ec)) {
951 first_ec = boot_ec;
952 return 0;
953 }
954 return -EFAULT;
955}
956
223883b7
AS
957static const struct acpi_device_id ec_device_ids[] = {
958 {"PNP0C09", 0},
959 {"", 0},
960};
961
c0900c35
AS
962int __init acpi_ec_ecdt_probe(void)
963{
c0900c35 964 acpi_status status;
c6cb0e87 965 struct acpi_ec *saved_ec = NULL;
50526df6 966 struct acpi_table_ecdt *ecdt_ptr;
45bea155 967
d66d969d
AS
968 boot_ec = make_acpi_ec();
969 if (!boot_ec)
c0900c35
AS
970 return -ENOMEM;
971 /*
972 * Generate a boot ec context
973 */
5423a0cb
AS
974 if (dmi_name_in_vendors("Micro-Star") ||
975 dmi_name_in_vendors("Notebook")) {
976 pr_info(PREFIX "Enabling special treatment for EC from MSI.\n");
977 EC_FLAGS_MSI = 1;
978 }
15a58ed1
AS
979 status = acpi_get_table(ACPI_SIG_ECDT, 1,
980 (struct acpi_table_header **)&ecdt_ptr);
cd8c93a4 981 if (ACPI_SUCCESS(status)) {
3ebe08a7 982 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
cd8c93a4
AS
983 boot_ec->command_addr = ecdt_ptr->control.address;
984 boot_ec->data_addr = ecdt_ptr->data.address;
985 boot_ec->gpe = ecdt_ptr->gpe;
4af8e10a 986 boot_ec->handle = ACPI_ROOT_OBJECT;
ce52ddf5 987 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
c6cb0e87
AS
988 /* Don't trust ECDT, which comes from ASUSTek */
989 if (!dmi_name_in_vendors("ASUS"))
c5279dee 990 goto install;
c6cb0e87
AS
991 saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
992 if (!saved_ec)
993 return -ENOMEM;
4312495f 994 memcpy(saved_ec, boot_ec, sizeof(*saved_ec));
c5279dee 995 /* fall through */
cd8c93a4 996 }
c5279dee
AS
997 /* This workaround is needed only on some broken machines,
998 * which require early EC, but fail to provide ECDT */
c5279dee
AS
999 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
1000 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
1001 boot_ec, NULL);
1002 /* Check that acpi_get_devices actually find something */
1003 if (ACPI_FAILURE(status) || !boot_ec->handle)
1004 goto error;
c6cb0e87
AS
1005 if (saved_ec) {
1006 /* try to find good ECDT from ASUSTek */
1007 if (saved_ec->command_addr != boot_ec->command_addr ||
1008 saved_ec->data_addr != boot_ec->data_addr ||
1009 saved_ec->gpe != boot_ec->gpe ||
1010 saved_ec->handle != boot_ec->handle)
1011 pr_info(PREFIX "ASUSTek keeps feeding us with broken "
1012 "ECDT tables, which are very hard to workaround. "
1013 "Trying to use DSDT EC info instead. Please send "
1014 "output of acpidump to linux-acpi@vger.kernel.org\n");
1015 kfree(saved_ec);
1016 saved_ec = NULL;
1017 } else {
1018 /* We really need to limit this workaround, the only ASUS,
1019 * which needs it, has fake EC._INI method, so use it as flag.
1020 * Keep boot_ec struct as it will be needed soon.
1021 */
1022 acpi_handle dummy;
1023 if (!dmi_name_in_vendors("ASUS") ||
1024 ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI",
1025 &dummy)))
1026 return -ENODEV;
1027 }
c5279dee
AS
1028install:
1029 if (!ec_install_handlers(boot_ec)) {
d033879c 1030 first_ec = boot_ec;
e8284321 1031 return 0;
d033879c 1032 }
c5279dee 1033error:
d66d969d
AS
1034 kfree(boot_ec);
1035 boot_ec = NULL;
1da177e4
LT
1036 return -ENODEV;
1037}
1038
223883b7
AS
1039static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
1040{
1041 struct acpi_ec *ec = acpi_driver_data(device);
1042 /* Stop using GPE */
1043 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
1044 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
0b7084ac 1045 acpi_disable_gpe(NULL, ec->gpe);
223883b7
AS
1046 return 0;
1047}
1048
1049static int acpi_ec_resume(struct acpi_device *device)
1050{
1051 struct acpi_ec *ec = acpi_driver_data(device);
1052 /* Enable use of GPE back */
1053 clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
0b7084ac 1054 acpi_enable_gpe(NULL, ec->gpe);
223883b7
AS
1055 return 0;
1056}
1057
1058static struct acpi_driver acpi_ec_driver = {
1059 .name = "ec",
1060 .class = ACPI_EC_CLASS,
1061 .ids = ec_device_ids,
1062 .ops = {
1063 .add = acpi_ec_add,
1064 .remove = acpi_ec_remove,
1065 .start = acpi_ec_start,
1066 .stop = acpi_ec_stop,
1067 .suspend = acpi_ec_suspend,
1068 .resume = acpi_ec_resume,
1069 },
1070};
1071
50526df6 1072static int __init acpi_ec_init(void)
1da177e4 1073{
50526df6 1074 int result = 0;
1da177e4 1075
1da177e4 1076 if (acpi_disabled)
d550d98d 1077 return 0;
1da177e4
LT
1078
1079 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1080 if (!acpi_ec_dir)
d550d98d 1081 return -ENODEV;
1da177e4
LT
1082
1083 /* Now register the driver for the EC */
1084 result = acpi_bus_register_driver(&acpi_ec_driver);
1085 if (result < 0) {
1086 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
d550d98d 1087 return -ENODEV;
1da177e4
LT
1088 }
1089
d550d98d 1090 return result;
1da177e4
LT
1091}
1092
1093subsys_initcall(acpi_ec_init);
1094
1095/* EC driver currently not unloadable */
1096#if 0
50526df6 1097static void __exit acpi_ec_exit(void)
1da177e4 1098{
1da177e4
LT
1099
1100 acpi_bus_unregister_driver(&acpi_ec_driver);
1101
1102 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1103
d550d98d 1104 return;
1da177e4 1105}
7843932a 1106#endif /* 0 */