]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/ec.c
ACPI: EC: move acpi_ec_start() after acpi_ec_add()
[mirror_ubuntu-zesty-kernel.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 */
34ff4dbc 70#define ACPI_EC_CDELAY 10 /* Wait 10us before polling EC */
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
34ff4dbc
AS
239static void ec_delay(void)
240{
241 /* EC in MSI notebooks don't tolerate delays other than 550 usec */
242 if (EC_FLAGS_MSI)
243 udelay(ACPI_EC_DELAY);
244 else
245 /* Use shortest sleep available */
246 msleep(1);
247}
248
7c6db4e0
AS
249static int ec_poll(struct acpi_ec *ec)
250{
251 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
34ff4dbc 252 udelay(ACPI_EC_CDELAY);
7c6db4e0
AS
253 while (time_before(jiffies, delay)) {
254 gpe_transaction(ec, acpi_ec_read_status(ec));
34ff4dbc 255 ec_delay();
7c6db4e0 256 if (ec_transaction_done(ec))
9d699ed9 257 return 0;
af3fd140 258 }
b77d81b2 259 return -ETIME;
1da177e4
LT
260}
261
8463200a
AS
262static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
263 struct transaction *t,
00eb43a1 264 int force_poll)
45bea155 265{
7c6db4e0 266 unsigned long tmp;
7c6db4e0 267 int ret = 0;
3ebe08a7 268 pr_debug(PREFIX "transaction start\n");
7c6db4e0
AS
269 /* disable GPE during transaction if storm is detected */
270 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
271 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
0b7084ac 272 acpi_disable_gpe(NULL, ec->gpe);
3576cf61 273 }
5423a0cb
AS
274 if (EC_FLAGS_MSI)
275 udelay(ACPI_EC_DELAY);
7c6db4e0 276 /* start transaction */
8463200a 277 spin_lock_irqsave(&ec->curr_lock, tmp);
7c6db4e0 278 /* following two actions should be kept atomic */
8463200a 279 ec->curr = t;
a2f93aea 280 start_transaction(ec);
8463200a 281 if (ec->curr->command == ACPI_EC_COMMAND_QUERY)
080e412c 282 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
8463200a 283 spin_unlock_irqrestore(&ec->curr_lock, tmp);
7c6db4e0
AS
284 /* if we selected poll mode or failed in GPE-mode do a poll loop */
285 if (force_poll ||
286 !test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ||
287 acpi_ec_wait(ec))
288 ret = ec_poll(ec);
3ebe08a7 289 pr_debug(PREFIX "transaction end\n");
8463200a
AS
290 spin_lock_irqsave(&ec->curr_lock, tmp);
291 ec->curr = NULL;
292 spin_unlock_irqrestore(&ec->curr_lock, tmp);
7c6db4e0
AS
293 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
294 /* check if we received SCI during transaction */
295 ec_check_sci(ec, acpi_ec_read_status(ec));
296 /* it is safe to enable GPE outside of transaction */
0b7084ac 297 acpi_enable_gpe(NULL, ec->gpe);
7c6db4e0 298 } else if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
8463200a 299 t->irq_count > ACPI_EC_STORM_THRESHOLD) {
f8248434
AJ
300 pr_info(PREFIX "GPE storm detected, "
301 "transactions will use polling mode\n");
7c6db4e0
AS
302 set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
303 }
304 return ret;
305}
306
307static int ec_check_ibf0(struct acpi_ec *ec)
308{
309 u8 status = acpi_ec_read_status(ec);
310 return (status & ACPI_EC_FLAG_IBF) == 0;
45bea155
LY
311}
312
c0ff1772
AS
313static int ec_wait_ibf0(struct acpi_ec *ec)
314{
315 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
316 /* interrupt wait manually if GPE mode is not active */
317 unsigned long timeout = test_bit(EC_FLAGS_GPE_MODE, &ec->flags) ?
318 msecs_to_jiffies(ACPI_EC_DELAY) : msecs_to_jiffies(1);
319 while (time_before(jiffies, delay))
320 if (wait_event_timeout(ec->wait, ec_check_ibf0(ec), timeout))
321 return 0;
322 return -ETIME;
45bea155
LY
323}
324
8463200a 325static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t,
00eb43a1 326 int force_poll)
1da177e4 327{
d7a76e4c 328 int status;
50526df6 329 u32 glk;
8463200a 330 if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
d550d98d 331 return -EINVAL;
8463200a
AS
332 if (t->rdata)
333 memset(t->rdata, 0, t->rlen);
523953b4 334 mutex_lock(&ec->lock);
703959d4 335 if (ec->global_lock) {
1da177e4 336 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
c24e912b 337 if (ACPI_FAILURE(status)) {
7c6db4e0
AS
338 status = -ENODEV;
339 goto unlock;
c24e912b 340 }
1da177e4 341 }
c0ff1772 342 if (ec_wait_ibf0(ec)) {
3ebe08a7
MN
343 pr_err(PREFIX "input buffer is not empty, "
344 "aborting transaction\n");
7c6db4e0 345 status = -ETIME;
451566f4 346 goto end;
716e084e 347 }
8463200a 348 status = acpi_ec_transaction_unlocked(ec, t, force_poll);
7c6db4e0 349end:
703959d4 350 if (ec->global_lock)
1da177e4 351 acpi_release_global_lock(glk);
7c6db4e0 352unlock:
523953b4 353 mutex_unlock(&ec->lock);
d550d98d 354 return status;
1da177e4
LT
355}
356
c45aac43
AS
357/*
358 * Note: samsung nv5000 doesn't work with ec burst mode.
359 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
360 */
8a383ef0 361static int acpi_ec_burst_enable(struct acpi_ec *ec)
c45aac43
AS
362{
363 u8 d;
8463200a
AS
364 struct transaction t = {.command = ACPI_EC_BURST_ENABLE,
365 .wdata = NULL, .rdata = &d,
366 .wlen = 0, .rlen = 1};
367
368 return acpi_ec_transaction(ec, &t, 0);
c45aac43
AS
369}
370
8a383ef0 371static int acpi_ec_burst_disable(struct acpi_ec *ec)
c45aac43 372{
8463200a
AS
373 struct transaction t = {.command = ACPI_EC_BURST_DISABLE,
374 .wdata = NULL, .rdata = NULL,
375 .wlen = 0, .rlen = 0};
376
7c6db4e0 377 return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
8463200a 378 acpi_ec_transaction(ec, &t, 0) : 0;
c45aac43
AS
379}
380
6ccedb10 381static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
3576cf61
DS
382{
383 int result;
384 u8 d;
8463200a
AS
385 struct transaction t = {.command = ACPI_EC_COMMAND_READ,
386 .wdata = &address, .rdata = &d,
387 .wlen = 1, .rlen = 1};
3576cf61 388
8463200a 389 result = acpi_ec_transaction(ec, &t, 0);
3576cf61
DS
390 *data = d;
391 return result;
392}
6ffb221a 393
3576cf61
DS
394static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
395{
6ccedb10 396 u8 wdata[2] = { address, data };
8463200a
AS
397 struct transaction t = {.command = ACPI_EC_COMMAND_WRITE,
398 .wdata = wdata, .rdata = NULL,
399 .wlen = 2, .rlen = 0};
400
401 return acpi_ec_transaction(ec, &t, 0);
3576cf61
DS
402}
403
1da177e4
LT
404/*
405 * Externally callable EC access functions. For now, assume 1 EC only
406 */
c45aac43
AS
407int ec_burst_enable(void)
408{
c45aac43
AS
409 if (!first_ec)
410 return -ENODEV;
d033879c 411 return acpi_ec_burst_enable(first_ec);
c45aac43
AS
412}
413
414EXPORT_SYMBOL(ec_burst_enable);
415
416int ec_burst_disable(void)
417{
c45aac43
AS
418 if (!first_ec)
419 return -ENODEV;
d033879c 420 return acpi_ec_burst_disable(first_ec);
c45aac43
AS
421}
422
423EXPORT_SYMBOL(ec_burst_disable);
424
6ccedb10 425int ec_read(u8 addr, u8 * val)
1da177e4 426{
1da177e4 427 int err;
6ffb221a 428 u8 temp_data;
1da177e4
LT
429
430 if (!first_ec)
431 return -ENODEV;
432
d033879c 433 err = acpi_ec_read(first_ec, addr, &temp_data);
1da177e4
LT
434
435 if (!err) {
436 *val = temp_data;
437 return 0;
50526df6 438 } else
1da177e4
LT
439 return err;
440}
50526df6 441
1da177e4
LT
442EXPORT_SYMBOL(ec_read);
443
50526df6 444int ec_write(u8 addr, u8 val)
1da177e4 445{
1da177e4
LT
446 int err;
447
448 if (!first_ec)
449 return -ENODEV;
450
d033879c 451 err = acpi_ec_write(first_ec, addr, val);
1da177e4
LT
452
453 return err;
454}
50526df6 455
1da177e4
LT
456EXPORT_SYMBOL(ec_write);
457
616362de 458int ec_transaction(u8 command,
9e197219 459 const u8 * wdata, unsigned wdata_len,
00eb43a1
LP
460 u8 * rdata, unsigned rdata_len,
461 int force_poll)
45bea155 462{
8463200a
AS
463 struct transaction t = {.command = command,
464 .wdata = wdata, .rdata = rdata,
465 .wlen = wdata_len, .rlen = rdata_len};
d7a76e4c
LP
466 if (!first_ec)
467 return -ENODEV;
45bea155 468
8463200a 469 return acpi_ec_transaction(first_ec, &t, force_poll);
45bea155 470}
1da177e4 471
ab9e43c6
LP
472EXPORT_SYMBOL(ec_transaction);
473
6ccedb10 474static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
3576cf61
DS
475{
476 int result;
6ccedb10 477 u8 d;
8463200a
AS
478 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
479 .wdata = NULL, .rdata = &d,
480 .wlen = 0, .rlen = 1};
6ccedb10
AS
481 if (!ec || !data)
482 return -EINVAL;
1da177e4 483
6ccedb10
AS
484 /*
485 * Query the EC to find out which _Qxx method we need to evaluate.
486 * Note that successful completion of the query causes the ACPI_EC_SCI
487 * bit to be cleared (and thus clearing the interrupt source).
488 */
716e084e 489
8463200a 490 result = acpi_ec_transaction(ec, &t, 0);
6ccedb10
AS
491 if (result)
492 return result;
1da177e4 493
6ccedb10
AS
494 if (!d)
495 return -ENODATA;
1da177e4 496
6ccedb10
AS
497 *data = d;
498 return 0;
1da177e4
LT
499}
500
1da177e4
LT
501/* --------------------------------------------------------------------------
502 Event Management
503 -------------------------------------------------------------------------- */
837012ed
AS
504int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
505 acpi_handle handle, acpi_ec_query_func func,
506 void *data)
507{
508 struct acpi_ec_query_handler *handler =
509 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
510 if (!handler)
511 return -ENOMEM;
512
513 handler->query_bit = query_bit;
514 handler->handle = handle;
515 handler->func = func;
516 handler->data = data;
517 mutex_lock(&ec->lock);
30c08574 518 list_add(&handler->node, &ec->list);
837012ed
AS
519 mutex_unlock(&ec->lock);
520 return 0;
521}
522
523EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
524
525void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
526{
1544fdbc 527 struct acpi_ec_query_handler *handler, *tmp;
837012ed 528 mutex_lock(&ec->lock);
1544fdbc 529 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
837012ed
AS
530 if (query_bit == handler->query_bit) {
531 list_del(&handler->node);
532 kfree(handler);
837012ed
AS
533 }
534 }
535 mutex_unlock(&ec->lock);
536}
537
538EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
1da177e4 539
50526df6 540static void acpi_ec_gpe_query(void *ec_cxt)
45bea155 541{
3d02b90b 542 struct acpi_ec *ec = ec_cxt;
6ffb221a 543 u8 value = 0;
837012ed 544 struct acpi_ec_query_handler *handler, copy;
45bea155 545
5d0c288b 546 if (!ec || acpi_ec_query(ec, &value))
e41334c0 547 return;
837012ed
AS
548 mutex_lock(&ec->lock);
549 list_for_each_entry(handler, &ec->list, node) {
550 if (value == handler->query_bit) {
551 /* have custom handler for this bit */
552 memcpy(&copy, handler, sizeof(copy));
553 mutex_unlock(&ec->lock);
554 if (copy.func) {
555 copy.func(copy.data);
556 } else if (copy.handle) {
557 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
558 }
559 return;
560 }
561 }
562 mutex_unlock(&ec->lock);
45bea155 563}
1da177e4 564
50526df6 565static u32 acpi_ec_gpe_handler(void *data)
1da177e4 566{
3d02b90b 567 struct acpi_ec *ec = data;
7c6db4e0 568 u8 status;
00eb43a1 569
3ebe08a7 570 pr_debug(PREFIX "~~~> interrupt\n");
7c6db4e0
AS
571 status = acpi_ec_read_status(ec);
572
8517934e
AS
573 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) {
574 gpe_transaction(ec, status);
575 if (ec_transaction_done(ec) &&
576 (status & ACPI_EC_FLAG_IBF) == 0)
577 wake_up(&ec->wait);
578 }
451566f4 579
7c6db4e0
AS
580 ec_check_sci(ec, status);
581 if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
582 !test_bit(EC_FLAGS_NO_GPE, &ec->flags)) {
95b937e3 583 /* this is non-query, must be confirmation */
f8248434
AJ
584 if (!test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
585 if (printk_ratelimit())
586 pr_info(PREFIX "non-query interrupt received,"
587 " switching to interrupt mode\n");
588 } else {
589 /* hush, STORM switches the mode every transaction */
590 pr_debug(PREFIX "non-query interrupt received,"
3ebe08a7 591 " switching to interrupt mode\n");
f8248434 592 }
7843932a 593 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
95b937e3 594 }
7c6db4e0 595 return ACPI_INTERRUPT_HANDLED;
845625cd
AS
596}
597
1da177e4
LT
598/* --------------------------------------------------------------------------
599 Address Space Management
600 -------------------------------------------------------------------------- */
601
1da177e4 602static acpi_status
5b7734b4
AS
603acpi_ec_space_handler(u32 function, acpi_physical_address address,
604 u32 bits, acpi_integer *value,
50526df6 605 void *handler_context, void *region_context)
1da177e4 606{
3d02b90b 607 struct acpi_ec *ec = handler_context;
3e71a87d 608 int result = 0, i;
5b7734b4 609 u8 temp = 0;
1da177e4 610
1da177e4 611 if ((address > 0xFF) || !value || !handler_context)
d550d98d 612 return AE_BAD_PARAMETER;
1da177e4 613
5b7734b4 614 if (function != ACPI_READ && function != ACPI_WRITE)
d550d98d 615 return AE_BAD_PARAMETER;
1da177e4 616
5b7734b4
AS
617 if (bits != 8 && acpi_strict)
618 return AE_BAD_PARAMETER;
1da177e4 619
b3b233c7
AS
620 acpi_ec_burst_enable(ec);
621
3e71a87d
AS
622 if (function == ACPI_READ) {
623 result = acpi_ec_read(ec, address, &temp);
624 *value = temp;
625 } else {
626 temp = 0xff & (*value);
627 result = acpi_ec_write(ec, address, temp);
628 }
629
630 for (i = 8; unlikely(bits - i > 0); i += 8) {
631 ++address;
5b7734b4
AS
632 if (function == ACPI_READ) {
633 result = acpi_ec_read(ec, address, &temp);
634 (*value) |= ((acpi_integer)temp) << i;
635 } else {
636 temp = 0xff & ((*value) >> i);
637 result = acpi_ec_write(ec, address, temp);
638 }
1da177e4
LT
639 }
640
b3b233c7
AS
641 acpi_ec_burst_disable(ec);
642
1da177e4
LT
643 switch (result) {
644 case -EINVAL:
d550d98d 645 return AE_BAD_PARAMETER;
1da177e4
LT
646 break;
647 case -ENODEV:
d550d98d 648 return AE_NOT_FOUND;
1da177e4
LT
649 break;
650 case -ETIME:
d550d98d 651 return AE_TIME;
1da177e4
LT
652 break;
653 default:
d550d98d 654 return AE_OK;
1da177e4 655 }
1da177e4
LT
656}
657
1da177e4
LT
658/* --------------------------------------------------------------------------
659 FS Interface (/proc)
660 -------------------------------------------------------------------------- */
661
50526df6 662static struct proc_dir_entry *acpi_ec_dir;
1da177e4 663
50526df6 664static int acpi_ec_read_info(struct seq_file *seq, void *offset)
1da177e4 665{
3d02b90b 666 struct acpi_ec *ec = seq->private;
1da177e4 667
1da177e4
LT
668 if (!ec)
669 goto end;
670
01f22462
AS
671 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
672 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
673 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
674 seq_printf(seq, "use global lock:\t%s\n",
703959d4 675 ec->global_lock ? "yes" : "no");
50526df6 676 end:
d550d98d 677 return 0;
1da177e4
LT
678}
679
680static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
681{
682 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
683}
684
070d8eb1 685static const struct file_operations acpi_ec_info_ops = {
50526df6
LB
686 .open = acpi_ec_info_open_fs,
687 .read = seq_read,
688 .llseek = seq_lseek,
689 .release = single_release,
1da177e4
LT
690 .owner = THIS_MODULE,
691};
692
50526df6 693static int acpi_ec_add_fs(struct acpi_device *device)
1da177e4 694{
50526df6 695 struct proc_dir_entry *entry = NULL;
1da177e4 696
1da177e4
LT
697 if (!acpi_device_dir(device)) {
698 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
50526df6 699 acpi_ec_dir);
1da177e4 700 if (!acpi_device_dir(device))
d550d98d 701 return -ENODEV;
1da177e4
LT
702 }
703
cf7acfab
DL
704 entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO,
705 acpi_device_dir(device),
706 &acpi_ec_info_ops, acpi_driver_data(device));
1da177e4 707 if (!entry)
d550d98d 708 return -ENODEV;
d550d98d 709 return 0;
1da177e4
LT
710}
711
50526df6 712static int acpi_ec_remove_fs(struct acpi_device *device)
1da177e4 713{
1da177e4
LT
714
715 if (acpi_device_dir(device)) {
716 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
717 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
718 acpi_device_dir(device) = NULL;
719 }
720
d550d98d 721 return 0;
1da177e4
LT
722}
723
1da177e4
LT
724/* --------------------------------------------------------------------------
725 Driver Interface
726 -------------------------------------------------------------------------- */
c0900c35
AS
727static acpi_status
728ec_parse_io_ports(struct acpi_resource *resource, void *context);
729
c0900c35
AS
730static struct acpi_ec *make_acpi_ec(void)
731{
732 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
733 if (!ec)
734 return NULL;
080e412c 735 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
c0900c35
AS
736 mutex_init(&ec->lock);
737 init_waitqueue_head(&ec->wait);
837012ed 738 INIT_LIST_HEAD(&ec->list);
8463200a 739 spin_lock_init(&ec->curr_lock);
c0900c35
AS
740 return ec;
741}
837012ed 742
c019b193
AS
743static acpi_status
744acpi_ec_register_query_methods(acpi_handle handle, u32 level,
745 void *context, void **return_value)
746{
0175d562
LM
747 char node_name[5];
748 struct acpi_buffer buffer = { sizeof(node_name), node_name };
c019b193
AS
749 struct acpi_ec *ec = context;
750 int value = 0;
0175d562
LM
751 acpi_status status;
752
753 status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
754
755 if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1) {
c019b193
AS
756 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
757 }
758 return AE_OK;
759}
760
cd8c93a4
AS
761static acpi_status
762ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
837012ed 763{
cd8c93a4 764 acpi_status status;
d21cf3c1 765 unsigned long long tmp = 0;
cd8c93a4
AS
766
767 struct acpi_ec *ec = context;
a5032bfd
AS
768
769 /* clear addr values, ec_parse_io_ports depend on it */
770 ec->command_addr = ec->data_addr = 0;
771
cd8c93a4
AS
772 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
773 ec_parse_io_ports, ec);
774 if (ACPI_FAILURE(status))
775 return status;
837012ed
AS
776
777 /* Get GPE bit assignment (EC events). */
778 /* TODO: Add support for _GPE returning a package */
27663c58 779 status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
cd8c93a4
AS
780 if (ACPI_FAILURE(status))
781 return status;
27663c58 782 ec->gpe = tmp;
837012ed 783 /* Use the global lock for all EC transactions? */
d21cf3c1 784 tmp = 0;
27663c58
MW
785 acpi_evaluate_integer(handle, "_GLK", NULL, &tmp);
786 ec->global_lock = tmp;
837012ed 787 ec->handle = handle;
cd8c93a4 788 return AE_CTRL_TERMINATE;
837012ed
AS
789}
790
5efc5476
BH
791static int ec_install_handlers(struct acpi_ec *ec)
792{
793 acpi_status status;
794 if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
795 return 0;
796 status = acpi_install_gpe_handler(NULL, ec->gpe,
797 ACPI_GPE_EDGE_TRIGGERED,
798 &acpi_ec_gpe_handler, ec);
799 if (ACPI_FAILURE(status))
800 return -ENODEV;
801 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
802 acpi_enable_gpe(NULL, ec->gpe);
803 status = acpi_install_address_space_handler(ec->handle,
804 ACPI_ADR_SPACE_EC,
805 &acpi_ec_space_handler,
806 NULL, ec);
807 if (ACPI_FAILURE(status)) {
808 if (status == AE_NOT_FOUND) {
809 /*
810 * Maybe OS fails in evaluating the _REG object.
811 * The AE_NOT_FOUND error will be ignored and OS
812 * continue to initialize EC.
813 */
814 printk(KERN_ERR "Fail in evaluating the _REG object"
815 " of EC device. Broken bios is suspected.\n");
816 } else {
817 acpi_remove_gpe_handler(NULL, ec->gpe,
818 &acpi_ec_gpe_handler);
819 return -ENODEV;
820 }
821 }
822
823 set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
824 return 0;
825}
826
4c611060
AS
827static void ec_remove_handlers(struct acpi_ec *ec)
828{
829 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
830 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
3ebe08a7 831 pr_err(PREFIX "failed to remove space handler\n");
4c611060
AS
832 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
833 &acpi_ec_gpe_handler)))
3ebe08a7 834 pr_err(PREFIX "failed to remove gpe handler\n");
7c6db4e0 835 clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
4c611060
AS
836}
837
703959d4 838static int acpi_ec_add(struct acpi_device *device)
1da177e4 839{
703959d4 840 struct acpi_ec *ec = NULL;
45bea155 841
45bea155 842 if (!device)
d550d98d 843 return -EINVAL;
c0900c35
AS
844 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
845 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
846
4c611060 847 /* Check for boot EC */
ce52ddf5
AS
848 if (boot_ec &&
849 (boot_ec->handle == device->handle ||
850 boot_ec->handle == ACPI_ROOT_OBJECT)) {
851 ec = boot_ec;
852 boot_ec = NULL;
853 } else {
854 ec = make_acpi_ec();
855 if (!ec)
856 return -ENOMEM;
a5032bfd
AS
857 }
858 if (ec_parse_device(device->handle, 0, ec, NULL) !=
859 AE_CTRL_TERMINATE) {
ce52ddf5
AS
860 kfree(ec);
861 return -EINVAL;
4c611060
AS
862 }
863
c0900c35 864 ec->handle = device->handle;
ce52ddf5
AS
865
866 /* Find and register all query methods */
867 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
868 acpi_ec_register_query_methods, ec, NULL);
869
4c611060
AS
870 if (!first_ec)
871 first_ec = ec;
db89b4f0 872 device->driver_data = ec;
c0900c35 873 acpi_ec_add_fs(device);
3ebe08a7 874 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
4c611060 875 ec->gpe, ec->command_addr, ec->data_addr);
3ebe08a7 876 pr_info(PREFIX "driver started in %s mode\n",
95b937e3 877 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
c0900c35 878 return 0;
1da177e4
LT
879}
880
5efc5476
BH
881static int acpi_ec_start(struct acpi_device *device)
882{
883 struct acpi_ec *ec;
884 int ret = 0;
885
886 if (!device)
887 return -EINVAL;
888
889 ec = acpi_driver_data(device);
890
891 if (!ec)
892 return -EINVAL;
893
894 ret = ec_install_handlers(ec);
895
896 /* EC is fully operational, allow queries */
897 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
898 return ret;
899}
900
50526df6 901static int acpi_ec_remove(struct acpi_device *device, int type)
1da177e4 902{
01f22462 903 struct acpi_ec *ec;
07ddf768 904 struct acpi_ec_query_handler *handler, *tmp;
1da177e4 905
1da177e4 906 if (!device)
d550d98d 907 return -EINVAL;
1da177e4
LT
908
909 ec = acpi_driver_data(device);
837012ed 910 mutex_lock(&ec->lock);
07ddf768 911 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
837012ed
AS
912 list_del(&handler->node);
913 kfree(handler);
914 }
915 mutex_unlock(&ec->lock);
1da177e4 916 acpi_ec_remove_fs(device);
db89b4f0 917 device->driver_data = NULL;
d033879c 918 if (ec == first_ec)
c0900c35 919 first_ec = NULL;
4c611060 920 kfree(ec);
d550d98d 921 return 0;
1da177e4
LT
922}
923
1da177e4 924static acpi_status
c0900c35 925ec_parse_io_ports(struct acpi_resource *resource, void *context)
1da177e4 926{
3d02b90b 927 struct acpi_ec *ec = context;
1da177e4 928
01f22462 929 if (resource->type != ACPI_RESOURCE_TYPE_IO)
1da177e4 930 return AE_OK;
1da177e4
LT
931
932 /*
933 * The first address region returned is the data port, and
934 * the second address region returned is the status/command
935 * port.
936 */
01f22462 937 if (ec->data_addr == 0)
6ffb221a 938 ec->data_addr = resource->data.io.minimum;
01f22462 939 else if (ec->command_addr == 0)
6ffb221a 940 ec->command_addr = resource->data.io.minimum;
01f22462 941 else
1da177e4 942 return AE_CTRL_TERMINATE;
1da177e4 943
1da177e4
LT
944 return AE_OK;
945}
946
50526df6 947static int acpi_ec_stop(struct acpi_device *device, int type)
1da177e4 948{
c0900c35 949 struct acpi_ec *ec;
1da177e4 950 if (!device)
d550d98d 951 return -EINVAL;
1da177e4 952 ec = acpi_driver_data(device);
c0900c35
AS
953 if (!ec)
954 return -EINVAL;
4c611060 955 ec_remove_handlers(ec);
f9319f90 956
d550d98d 957 return 0;
1da177e4
LT
958}
959
c04209a7
AS
960int __init acpi_boot_ec_enable(void)
961{
7c6db4e0 962 if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
c04209a7
AS
963 return 0;
964 if (!ec_install_handlers(boot_ec)) {
965 first_ec = boot_ec;
966 return 0;
967 }
968 return -EFAULT;
969}
970
223883b7
AS
971static const struct acpi_device_id ec_device_ids[] = {
972 {"PNP0C09", 0},
973 {"", 0},
974};
975
c0900c35
AS
976int __init acpi_ec_ecdt_probe(void)
977{
c0900c35 978 acpi_status status;
c6cb0e87 979 struct acpi_ec *saved_ec = NULL;
50526df6 980 struct acpi_table_ecdt *ecdt_ptr;
45bea155 981
d66d969d
AS
982 boot_ec = make_acpi_ec();
983 if (!boot_ec)
c0900c35
AS
984 return -ENOMEM;
985 /*
986 * Generate a boot ec context
987 */
5423a0cb
AS
988 if (dmi_name_in_vendors("Micro-Star") ||
989 dmi_name_in_vendors("Notebook")) {
990 pr_info(PREFIX "Enabling special treatment for EC from MSI.\n");
991 EC_FLAGS_MSI = 1;
992 }
15a58ed1
AS
993 status = acpi_get_table(ACPI_SIG_ECDT, 1,
994 (struct acpi_table_header **)&ecdt_ptr);
cd8c93a4 995 if (ACPI_SUCCESS(status)) {
3ebe08a7 996 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
cd8c93a4
AS
997 boot_ec->command_addr = ecdt_ptr->control.address;
998 boot_ec->data_addr = ecdt_ptr->data.address;
999 boot_ec->gpe = ecdt_ptr->gpe;
4af8e10a 1000 boot_ec->handle = ACPI_ROOT_OBJECT;
ce52ddf5 1001 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
c6cb0e87 1002 /* Don't trust ECDT, which comes from ASUSTek */
a5032bfd 1003 if (!dmi_name_in_vendors("ASUS") && EC_FLAGS_MSI == 0)
c5279dee 1004 goto install;
c6cb0e87
AS
1005 saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
1006 if (!saved_ec)
1007 return -ENOMEM;
a5032bfd 1008 memcpy(saved_ec, boot_ec, sizeof(struct acpi_ec));
c5279dee 1009 /* fall through */
cd8c93a4 1010 }
c5279dee
AS
1011 /* This workaround is needed only on some broken machines,
1012 * which require early EC, but fail to provide ECDT */
c5279dee
AS
1013 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
1014 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
1015 boot_ec, NULL);
1016 /* Check that acpi_get_devices actually find something */
1017 if (ACPI_FAILURE(status) || !boot_ec->handle)
1018 goto error;
c6cb0e87
AS
1019 if (saved_ec) {
1020 /* try to find good ECDT from ASUSTek */
1021 if (saved_ec->command_addr != boot_ec->command_addr ||
1022 saved_ec->data_addr != boot_ec->data_addr ||
1023 saved_ec->gpe != boot_ec->gpe ||
1024 saved_ec->handle != boot_ec->handle)
1025 pr_info(PREFIX "ASUSTek keeps feeding us with broken "
1026 "ECDT tables, which are very hard to workaround. "
1027 "Trying to use DSDT EC info instead. Please send "
1028 "output of acpidump to linux-acpi@vger.kernel.org\n");
1029 kfree(saved_ec);
1030 saved_ec = NULL;
1031 } else {
1032 /* We really need to limit this workaround, the only ASUS,
1033 * which needs it, has fake EC._INI method, so use it as flag.
1034 * Keep boot_ec struct as it will be needed soon.
1035 */
1036 acpi_handle dummy;
1037 if (!dmi_name_in_vendors("ASUS") ||
1038 ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI",
1039 &dummy)))
1040 return -ENODEV;
1041 }
c5279dee
AS
1042install:
1043 if (!ec_install_handlers(boot_ec)) {
d033879c 1044 first_ec = boot_ec;
e8284321 1045 return 0;
d033879c 1046 }
c5279dee 1047error:
d66d969d
AS
1048 kfree(boot_ec);
1049 boot_ec = NULL;
1da177e4
LT
1050 return -ENODEV;
1051}
1052
223883b7
AS
1053static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
1054{
1055 struct acpi_ec *ec = acpi_driver_data(device);
1056 /* Stop using GPE */
1057 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
1058 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
0b7084ac 1059 acpi_disable_gpe(NULL, ec->gpe);
223883b7
AS
1060 return 0;
1061}
1062
1063static int acpi_ec_resume(struct acpi_device *device)
1064{
1065 struct acpi_ec *ec = acpi_driver_data(device);
1066 /* Enable use of GPE back */
1067 clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
5aa63f03 1068 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
0b7084ac 1069 acpi_enable_gpe(NULL, ec->gpe);
223883b7
AS
1070 return 0;
1071}
1072
1073static struct acpi_driver acpi_ec_driver = {
1074 .name = "ec",
1075 .class = ACPI_EC_CLASS,
1076 .ids = ec_device_ids,
1077 .ops = {
1078 .add = acpi_ec_add,
1079 .remove = acpi_ec_remove,
1080 .start = acpi_ec_start,
1081 .stop = acpi_ec_stop,
1082 .suspend = acpi_ec_suspend,
1083 .resume = acpi_ec_resume,
1084 },
1085};
1086
a5f820fe 1087int __init acpi_ec_init(void)
1da177e4 1088{
50526df6 1089 int result = 0;
1da177e4 1090
1da177e4
LT
1091 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
1092 if (!acpi_ec_dir)
d550d98d 1093 return -ENODEV;
1da177e4
LT
1094
1095 /* Now register the driver for the EC */
1096 result = acpi_bus_register_driver(&acpi_ec_driver);
1097 if (result < 0) {
1098 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
d550d98d 1099 return -ENODEV;
1da177e4
LT
1100 }
1101
d550d98d 1102 return result;
1da177e4
LT
1103}
1104
1da177e4
LT
1105/* EC driver currently not unloadable */
1106#if 0
50526df6 1107static void __exit acpi_ec_exit(void)
1da177e4 1108{
1da177e4
LT
1109
1110 acpi_bus_unregister_driver(&acpi_ec_driver);
1111
1112 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1113
d550d98d 1114 return;
1da177e4 1115}
7843932a 1116#endif /* 0 */