blob: a802962ff2b499fc2cc3489a5e28a02e58d2465d [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 Brownf52fd662007-02-12 22:42:12 -050041ACPI_MODULE_NAME("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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_EC_DEVICE_NAME "Embedded Controller"
46#define ACPI_EC_FILE_INFO "info"
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +030047#undef PREFIX
48#define PREFIX "ACPI: EC: "
Denis M. Sadykov703959d2006-09-26 19:50:33 +040049/* EC status register */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
Dmitry Torokhov451566f2005-03-19 01:10:05 -050052#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040054/* EC commands */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030055enum ec_command {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030056 ACPI_EC_COMMAND_READ = 0x80,
57 ACPI_EC_COMMAND_WRITE = 0x81,
58 ACPI_EC_BURST_ENABLE = 0x82,
59 ACPI_EC_BURST_DISABLE = 0x83,
60 ACPI_EC_COMMAND_QUERY = 0x84,
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030061};
Denis M. Sadykov703959d2006-09-26 19:50:33 +040062/* EC events */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030063enum ec_event {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040064 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030065 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040066};
67
Alexey Starikovskiy5c406412006-12-07 18:42:16 +030068#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040069#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040070
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030071static enum ec_mode {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030072 EC_INTR = 1, /* Output buffer full */
73 EC_POLL, /* Input buffer empty */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030074} acpi_ec_mode = EC_INTR;
Denis M. Sadykov703959d2006-09-26 19:50:33 +040075
Len Brown50526df2005-08-11 17:32:05 -040076static int acpi_ec_remove(struct acpi_device *device, int type);
77static int acpi_ec_start(struct acpi_device *device);
78static int acpi_ec_stop(struct acpi_device *device, int type);
Denis M. Sadykov703959d2006-09-26 19:50:33 +040079static int acpi_ec_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81static struct acpi_driver acpi_ec_driver = {
Len Brownc2b6705b2007-02-12 23:33:40 -050082 .name = "ec",
Len Brown50526df2005-08-11 17:32:05 -040083 .class = ACPI_EC_CLASS,
84 .ids = ACPI_EC_HID,
85 .ops = {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040086 .add = acpi_ec_add,
Len Brown50526df2005-08-11 17:32:05 -040087 .remove = acpi_ec_remove,
88 .start = acpi_ec_start,
89 .stop = acpi_ec_stop,
90 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +040092
93/* If we find an EC via the ECDT, we need to keep a ptr to its context */
Adrian Bunka854e082006-12-19 12:56:12 -080094static struct acpi_ec {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040095 acpi_handle handle;
96 unsigned long uid;
Alexey Starikovskiya86e2772006-12-07 18:42:16 +030097 unsigned long gpe;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +040098 unsigned long command_addr;
99 unsigned long data_addr;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400100 unsigned long global_lock;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300101 struct mutex lock;
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300102 atomic_t query_pending;
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500103 atomic_t event_count;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400104 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
105 wait_queue_head_t wait;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400106} *ec_ecdt;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400107
108/* External interfaces use first EC only, so remember */
109static struct acpi_device *first_ec;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/* --------------------------------------------------------------------------
112 Transaction Management
113 -------------------------------------------------------------------------- */
114
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400115static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400117 return inb(ec->command_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400120static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400121{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400122 return inb(ec->data_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400123}
124
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400125static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400126{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400127 outb(command, ec->command_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400128}
129
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400130static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400131{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400132 outb(data, ec->data_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400133}
134
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500135static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event,
136 unsigned old_count)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400137{
Alexey Starikovskiybec5a1e2006-12-07 18:42:16 +0300138 u8 status = acpi_ec_read_status(ec);
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500139 if (old_count == atomic_read(&ec->event_count))
140 return 0;
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300141 if (event == ACPI_EC_EVENT_OBF_1) {
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400142 if (status & ACPI_EC_FLAG_OBF)
143 return 1;
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300144 } else if (event == ACPI_EC_EVENT_IBF_0) {
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400145 if (!(status & ACPI_EC_FLAG_IBF))
146 return 1;
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400147 }
148
149 return 0;
150}
151
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500152static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, unsigned count)
Luming Yu45bea152005-07-23 04:08:00 -0400153{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300154 if (acpi_ec_mode == EC_POLL) {
Alexey Starikovskiy50c1e112006-12-07 18:42:17 +0300155 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
156 while (time_before(jiffies, delay)) {
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500157 if (acpi_ec_check_status(ec, event, 0))
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400158 return 0;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400159 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300160 } else {
161 if (wait_event_timeout(ec->wait,
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500162 acpi_ec_check_status(ec, event, count),
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300163 msecs_to_jiffies(ACPI_EC_DELAY)) ||
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500164 acpi_ec_check_status(ec, event, 0)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400165 return 0;
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300166 } else {
167 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
168 " status = %d, expect_event = %d\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300169 acpi_ec_read_status(ec), event);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400170 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300171 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400172
Patrick Mocheld550d982006-06-27 00:41:40 -0400173 return -ETIME;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500174}
175
Len Brown02b28a32005-12-05 16:33:04 -0500176#ifdef ACPI_FUTURE_USAGE
Luming Yu06a2a382005-09-27 00:43:00 -0400177/*
178 * Note: samsung nv5000 doesn't work with ec burst mode.
179 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
180 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400181int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500182{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400183 u8 tmp = 0;
184 u8 status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500185
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500186 status = acpi_ec_read_status(ec);
Len Brown50526df2005-08-11 17:32:05 -0400187 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400188 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Len Brown50526df2005-08-11 17:32:05 -0400189 if (status)
Luming Yu716e0842005-08-10 01:40:00 -0400190 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400191 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
192 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
193 tmp = acpi_ec_read_data(ec);
Len Brown50526df2005-08-11 17:32:05 -0400194 if (tmp != 0x90) { /* Burst ACK byte */
Patrick Mocheld550d982006-06-27 00:41:40 -0400195 return -EINVAL;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500196 }
Luming Yu668d74c2005-07-23 00:26:33 -0400197 }
198
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400199 atomic_set(&ec->leaving_burst, 0);
Patrick Mocheld550d982006-06-27 00:41:40 -0400200 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300201 end:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400202 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400203 return -1;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500204}
205
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400206int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500207{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400208 u8 status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500209
Luming Yu06a2a382005-09-27 00:43:00 -0400210 status = acpi_ec_read_status(ec);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300211 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400212 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300213 if (status)
Luming Yu06a2a382005-09-27 00:43:00 -0400214 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400215 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
216 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400217 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400218 atomic_set(&ec->leaving_burst, 1);
Patrick Mocheld550d982006-06-27 00:41:40 -0400219 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300220 end:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400221 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400222 return -1;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500223}
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300224#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400226static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300227 const u8 * wdata, unsigned wdata_len,
228 u8 * rdata, unsigned rdata_len)
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400229{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300230 int result = 0;
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500231 unsigned count = atomic_read(&ec->event_count);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400232 acpi_ec_write_cmd(ec, command);
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400233
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300234 for (; wdata_len > 0; --wdata_len) {
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500235 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300236 if (result) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300237 printk(KERN_ERR PREFIX
238 "write_cmd timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300239 goto end;
240 }
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500241 count = atomic_read(&ec->event_count);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400242 acpi_ec_write_data(ec, *(wdata++));
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400243 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400244
Alexey Starikovskiyd91df1a2006-12-07 18:42:16 +0300245 if (!rdata_len) {
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500246 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300247 if (result) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300248 printk(KERN_ERR PREFIX
249 "finish-write timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300250 goto end;
251 }
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300252 } else if (command == ACPI_EC_COMMAND_QUERY) {
253 atomic_set(&ec->query_pending, 0);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400254 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400255
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300256 for (; rdata_len > 0; --rdata_len) {
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500257 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300258 if (result) {
259 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300260 command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300261 goto end;
262 }
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500263 count = atomic_read(&ec->event_count);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400264 *(rdata++) = acpi_ec_read_data(ec);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400265 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300266 end:
267 return result;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400268}
269
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400270static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300271 const u8 * wdata, unsigned wdata_len,
272 u8 * rdata, unsigned rdata_len)
Luming Yu45bea152005-07-23 04:08:00 -0400273{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400274 int status;
Len Brown50526df2005-08-11 17:32:05 -0400275 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400277 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
Patrick Mocheld550d982006-06-27 00:41:40 -0400278 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300280 if (rdata)
281 memset(rdata, 0, rdata_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300283 mutex_lock(&ec->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400284 if (ec->global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300286 if (ACPI_FAILURE(status)) {
287 mutex_unlock(&ec->lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400288 return -ENODEV;
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500291
Alexey Starikovskiy5d57a6a2006-12-07 18:42:16 +0300292 /* Make sure GPE is enabled before doing transaction */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300293 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Alexey Starikovskiy5d57a6a2006-12-07 18:42:16 +0300294
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500295 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
Luming Yu716e0842005-08-10 01:40:00 -0400296 if (status) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300297 printk(KERN_DEBUG PREFIX
298 "input buffer is not empty, aborting transaction\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500299 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300302 status = acpi_ec_transaction_unlocked(ec, command,
303 wdata, wdata_len,
304 rdata, rdata_len);
Len Brown50526df2005-08-11 17:32:05 -0400305
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300306 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400308 if (ec->global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 acpi_release_global_lock(glk);
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300310 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Patrick Mocheld550d982006-06-27 00:41:40 -0400312 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300315static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400316{
317 int result;
318 u8 d;
319
320 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
321 &address, 1, &d, 1);
322 *data = d;
323 return result;
324}
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400325
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400326static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
327{
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300328 u8 wdata[2] = { address, data };
329 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400330 wdata, 2, NULL, 0);
331}
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/*
334 * Externally callable EC access functions. For now, assume 1 EC only
335 */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300336int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400338 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 int err;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400340 u8 temp_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (!first_ec)
343 return -ENODEV;
344
345 ec = acpi_driver_data(first_ec);
346
347 err = acpi_ec_read(ec, addr, &temp_data);
348
349 if (!err) {
350 *val = temp_data;
351 return 0;
Len Brown50526df2005-08-11 17:32:05 -0400352 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return err;
354}
Len Brown50526df2005-08-11 17:32:05 -0400355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356EXPORT_SYMBOL(ec_read);
357
Len Brown50526df2005-08-11 17:32:05 -0400358int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400360 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 int err;
362
363 if (!first_ec)
364 return -ENODEV;
365
366 ec = acpi_driver_data(first_ec);
367
368 err = acpi_ec_write(ec, addr, val);
369
370 return err;
371}
Len Brown50526df2005-08-11 17:32:05 -0400372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373EXPORT_SYMBOL(ec_write);
374
Randy Dunlap616362d2006-10-27 01:47:34 -0400375int ec_transaction(u8 command,
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500376 const u8 * wdata, unsigned wdata_len,
377 u8 * rdata, unsigned rdata_len)
Luming Yu45bea152005-07-23 04:08:00 -0400378{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400379 struct acpi_ec *ec;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400380
381 if (!first_ec)
382 return -ENODEV;
383
384 ec = acpi_driver_data(first_ec);
385
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400386 return acpi_ec_transaction(ec, command, wdata,
387 wdata_len, rdata, rdata_len);
Luming Yu45bea152005-07-23 04:08:00 -0400388}
Luming Yu45bea152005-07-23 04:08:00 -0400389
Lennart Poetteringab9e43c2006-10-03 22:49:00 -0400390EXPORT_SYMBOL(ec_transaction);
391
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300392static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400393{
394 int result;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300395 u8 d;
Luming Yu45bea152005-07-23 04:08:00 -0400396
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300397 if (!ec || !data)
398 return -EINVAL;
Luming Yu45bea152005-07-23 04:08:00 -0400399
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300400 /*
401 * Query the EC to find out which _Qxx method we need to evaluate.
402 * Note that successful completion of the query causes the ACPI_EC_SCI
403 * bit to be cleared (and thus clearing the interrupt source).
404 */
Luming Yu45bea152005-07-23 04:08:00 -0400405
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300406 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
407 if (result)
408 return result;
Luming Yu45bea152005-07-23 04:08:00 -0400409
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300410 if (!d)
411 return -ENODATA;
Luming Yu45bea152005-07-23 04:08:00 -0400412
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300413 *data = d;
414 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417/* --------------------------------------------------------------------------
418 Event Management
419 -------------------------------------------------------------------------- */
420
Len Brown50526df2005-08-11 17:32:05 -0400421static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400423 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400424 u8 value = 0;
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300425 char object_name[8];
Luming Yu45bea152005-07-23 04:08:00 -0400426
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300427 if (!ec || acpi_ec_query(ec, &value))
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300428 return;
Luming Yu45bea152005-07-23 04:08:00 -0400429
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400430 snprintf(object_name, 8, "_Q%2.2X", value);
Luming Yu45bea152005-07-23 04:08:00 -0400431
Guillaume Chazarainc6e19192006-12-24 22:19:02 +0100432 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name));
Luming Yu45bea152005-07-23 04:08:00 -0400433
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400434 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
Luming Yu45bea152005-07-23 04:08:00 -0400435}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Len Brown50526df2005-08-11 17:32:05 -0400437static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Len Brown50526df2005-08-11 17:32:05 -0400439 acpi_status status = AE_OK;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400440 u8 value;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400441 struct acpi_ec *ec = (struct acpi_ec *)data;
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500442 atomic_inc(&ec->event_count);
Denis M. Sadykov8e0341b2006-09-26 19:50:33 +0400443 if (acpi_ec_mode == EC_INTR) {
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300444 wake_up(&ec->wait);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500445 }
446
Alexey Starikovskiybec5a1e2006-12-07 18:42:16 +0300447 value = acpi_ec_read_status(ec);
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300448 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
449 atomic_set(&ec->query_pending, 1);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300450 status =
451 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
452 ec);
Len Brown50526df2005-08-11 17:32:05 -0400453 }
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300454
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500455 return status == AE_OK ?
Len Brown50526df2005-08-11 17:32:05 -0400456 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459/* --------------------------------------------------------------------------
460 Address Space Management
461 -------------------------------------------------------------------------- */
462
463static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400464acpi_ec_space_setup(acpi_handle region_handle,
465 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
467 /*
468 * The EC object is in the handler context and is needed
469 * when calling the acpi_ec_space_handler.
470 */
Len Brown50526df2005-08-11 17:32:05 -0400471 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
472 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 return AE_OK;
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400478acpi_ec_space_handler(u32 function,
479 acpi_physical_address address,
480 u32 bit_width,
481 acpi_integer * value,
482 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Len Brown50526df2005-08-11 17:32:05 -0400484 int result = 0;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400485 struct acpi_ec *ec = NULL;
Len Brown50526df2005-08-11 17:32:05 -0400486 u64 temp = *value;
487 acpi_integer f_v = 0;
488 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if ((address > 0xFF) || !value || !handler_context)
Patrick Mocheld550d982006-06-27 00:41:40 -0400491 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Luming Yufa9cd542005-03-19 01:54:47 -0500493 if (bit_width != 8 && acpi_strict) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400497 ec = (struct acpi_ec *)handler_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Len Brown50526df2005-08-11 17:32:05 -0400499 next_byte:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 switch (function) {
501 case ACPI_READ:
Luming Yufa9cd542005-03-19 01:54:47 -0500502 temp = 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300503 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 break;
505 case ACPI_WRITE:
Luming Yufa9cd542005-03-19 01:54:47 -0500506 result = acpi_ec_write(ec, (u8) address, (u8) temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508 default:
509 result = -EINVAL;
510 goto out;
511 break;
512 }
513
514 bit_width -= 8;
Luming Yufa9cd542005-03-19 01:54:47 -0500515 if (bit_width) {
516 if (function == ACPI_READ)
517 f_v |= temp << 8 * i;
518 if (function == ACPI_WRITE)
519 temp >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 i++;
Andrew Morton83ea7442005-03-30 22:12:13 -0500521 address++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 goto next_byte;
523 }
524
Luming Yufa9cd542005-03-19 01:54:47 -0500525 if (function == ACPI_READ) {
526 f_v |= temp << 8 * i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 *value = f_v;
528 }
529
Len Brown50526df2005-08-11 17:32:05 -0400530 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 switch (result) {
532 case -EINVAL:
Patrick Mocheld550d982006-06-27 00:41:40 -0400533 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 break;
535 case -ENODEV:
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return AE_NOT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 break;
538 case -ETIME:
Patrick Mocheld550d982006-06-27 00:41:40 -0400539 return AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 break;
541 default:
Patrick Mocheld550d982006-06-27 00:41:40 -0400542 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546/* --------------------------------------------------------------------------
547 FS Interface (/proc)
548 -------------------------------------------------------------------------- */
549
Len Brown50526df2005-08-11 17:32:05 -0400550static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown50526df2005-08-11 17:32:05 -0400552static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400554 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (!ec)
557 goto end;
558
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300559 seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300561 (u32) ec->command_addr, (u32) ec->data_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 seq_printf(seq, "use global lock: %s\n",
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400563 ec->global_lock ? "yes" : "no");
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300564 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Len Brown50526df2005-08-11 17:32:05 -0400566 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400567 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
569
570static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
571{
572 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
573}
574
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400575static struct file_operations acpi_ec_info_ops = {
Len Brown50526df2005-08-11 17:32:05 -0400576 .open = acpi_ec_info_open_fs,
577 .read = seq_read,
578 .llseek = seq_lseek,
579 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .owner = THIS_MODULE,
581};
582
Len Brown50526df2005-08-11 17:32:05 -0400583static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Len Brown50526df2005-08-11 17:32:05 -0400585 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (!acpi_device_dir(device)) {
588 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown50526df2005-08-11 17:32:05 -0400589 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400591 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593
594 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown50526df2005-08-11 17:32:05 -0400595 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400597 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 else {
599 entry->proc_fops = &acpi_ec_info_ops;
600 entry->data = acpi_driver_data(device);
601 entry->owner = THIS_MODULE;
602 }
603
Patrick Mocheld550d982006-06-27 00:41:40 -0400604 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Len Brown50526df2005-08-11 17:32:05 -0400607static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 if (acpi_device_dir(device)) {
611 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
612 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
613 acpi_device_dir(device) = NULL;
614 }
615
Patrick Mocheld550d982006-06-27 00:41:40 -0400616 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619/* --------------------------------------------------------------------------
620 Driver Interface
621 -------------------------------------------------------------------------- */
622
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400623static int acpi_ec_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
Len Brown50526df2005-08-11 17:32:05 -0400625 int result = 0;
626 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400627 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400630 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Burman Yan36bcbec2006-12-19 12:56:11 -0800632 ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400634 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400636 ec->handle = device->handle;
637 ec->uid = -1;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300638 mutex_init(&ec->lock);
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300639 atomic_set(&ec->query_pending, 0);
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500640 atomic_set(&ec->event_count, 1);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400641 if (acpi_ec_mode == EC_INTR) {
642 atomic_set(&ec->leaving_burst, 1);
643 init_waitqueue_head(&ec->wait);
644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
646 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
647 acpi_driver_data(device) = ec;
648
649 /* Use the global lock for all EC transactions? */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300650 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Jiri Slabyff2fc3e2006-03-28 17:04:00 -0500652 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
653 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
654 if (ec_ecdt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown50526df2005-08-11 17:32:05 -0400656 ACPI_ADR_SPACE_EC,
657 &acpi_ec_space_handler);
658
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300659 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400660 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 kfree(ec_ecdt);
663 }
664
665 /* Get GPE bit assignment (EC events). */
666 /* TODO: Add support for _GPE returning a package */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300667 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300669 ACPI_EXCEPTION((AE_INFO, status,
670 "Obtaining GPE bit assignment"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 result = -ENODEV;
672 goto end;
673 }
674
675 result = acpi_ec_add_fs(device);
676 if (result)
677 goto end;
678
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400679 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300680 acpi_device_name(device), acpi_device_bid(device),
681 (u32) ec->gpe));
Luming Yu45bea152005-07-23 04:08:00 -0400682
683 if (!first_ec)
684 first_ec = device;
685
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300686 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 if (result)
688 kfree(ec);
689
Patrick Mocheld550d982006-06-27 00:41:40 -0400690 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Len Brown50526df2005-08-11 17:32:05 -0400693static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400695 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400698 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 ec = acpi_driver_data(device);
701
702 acpi_ec_remove_fs(device);
703
704 kfree(ec);
705
Patrick Mocheld550d982006-06-27 00:41:40 -0400706 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400710acpi_ec_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400712 struct acpi_ec *ec = (struct acpi_ec *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Bob Moore50eca3e2005-09-30 19:03:00 -0400714 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return AE_OK;
716 }
717
718 /*
719 * The first address region returned is the data port, and
720 * the second address region returned is the status/command
721 * port.
722 */
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400723 if (ec->data_addr == 0) {
724 ec->data_addr = resource->data.io.minimum;
725 } else if (ec->command_addr == 0) {
726 ec->command_addr = resource->data.io.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 } else {
728 return AE_CTRL_TERMINATE;
729 }
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return AE_OK;
732}
733
Len Brown50526df2005-08-11 17:32:05 -0400734static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Len Brown50526df2005-08-11 17:32:05 -0400736 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400737 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 ec = acpi_driver_data(device);
743
744 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400745 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 /*
748 * Get I/O port addresses. Convert to GAS format.
749 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400750 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -0400751 acpi_ec_io_ports, ec);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400752 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400753 ACPI_EXCEPTION((AE_INFO, status,
754 "Error getting I/O port addresses"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400755 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400758 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300759 ec->gpe, ec->command_addr, ec->data_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /*
762 * Install GPE handler
763 */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300764 status = acpi_install_gpe_handler(NULL, ec->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400765 ACPI_GPE_EDGE_TRIGGERED,
766 &acpi_ec_gpe_handler, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (ACPI_FAILURE(status)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400768 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 }
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300770 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
771 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400773 status = acpi_install_address_space_handler(ec->handle,
Len Brown50526df2005-08-11 17:32:05 -0400774 ACPI_ADR_SPACE_EC,
775 &acpi_ec_space_handler,
776 &acpi_ec_space_setup, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300778 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
Patrick Mocheld550d982006-06-27 00:41:40 -0400779 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 }
781
Patrick Mocheld550d982006-06-27 00:41:40 -0400782 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
Len Brown50526df2005-08-11 17:32:05 -0400785static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Len Brown50526df2005-08-11 17:32:05 -0400787 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400788 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400791 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 ec = acpi_driver_data(device);
794
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400795 status = acpi_remove_address_space_handler(ec->handle,
Len Brown50526df2005-08-11 17:32:05 -0400796 ACPI_ADR_SPACE_EC,
797 &acpi_ec_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400799 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300801 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400803 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Patrick Mocheld550d982006-06-27 00:41:40 -0400805 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806}
807
808static acpi_status __init
Len Brown50526df2005-08-11 17:32:05 -0400809acpi_fake_ecdt_callback(acpi_handle handle,
810 u32 Level, void *context, void **retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
Len Brown50526df2005-08-11 17:32:05 -0400812 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300814 mutex_init(&ec_ecdt->lock);
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500815 atomic_set(&ec_ecdt->event_count, 1);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400816 if (acpi_ec_mode == EC_INTR) {
817 init_waitqueue_head(&ec_ecdt->wait);
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -0400820 acpi_ec_io_ports, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (ACPI_FAILURE(status))
822 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400824 ec_ecdt->uid = -1;
825 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300827 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 if (ACPI_FAILURE(status))
829 return status;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400830 ec_ecdt->global_lock = TRUE;
831 ec_ecdt->handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400833 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300834 ec_ecdt->gpe, ec_ecdt->command_addr,
835 ec_ecdt->data_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 return AE_CTRL_TERMINATE;
838}
839
840/*
841 * Some BIOS (such as some from Gateway laptops) access EC region very early
842 * such as in BAT0._INI or EC._INI before an EC device is found and
843 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
844 * required, but if EC regison is accessed early, it is required.
845 * The routine tries to workaround the BIOS bug by pre-scan EC device
846 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
847 * op region (since _REG isn't invoked yet). The assumption is true for
848 * all systems found.
849 */
Len Brown50526df2005-08-11 17:32:05 -0400850static int __init acpi_ec_fake_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Len Brown50526df2005-08-11 17:32:05 -0400852 acpi_status status;
853 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400855 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Burman Yan36bcbec2006-12-19 12:56:11 -0800857 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (!ec_ecdt) {
859 ret = -ENOMEM;
860 goto error;
861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Len Brown50526df2005-08-11 17:32:05 -0400863 status = acpi_get_devices(ACPI_EC_HID,
864 acpi_fake_ecdt_callback, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (ACPI_FAILURE(status)) {
866 kfree(ec_ecdt);
867 ec_ecdt = NULL;
868 ret = -ENODEV;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400869 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 goto error;
871 }
872 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300873 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return ret;
875}
876
Len Brown50526df2005-08-11 17:32:05 -0400877static int __init acpi_ec_get_real_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Len Brown50526df2005-08-11 17:32:05 -0400879 acpi_status status;
880 struct acpi_table_ecdt *ecdt_ptr;
Luming Yu45bea152005-07-23 04:08:00 -0400881
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +0300882 status = acpi_get_table(ACPI_SIG_ECDT, 1,
883 (struct acpi_table_header **)&ecdt_ptr);
Luming Yu45bea152005-07-23 04:08:00 -0400884 if (ACPI_FAILURE(status))
885 return -ENODEV;
886
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400887 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
Luming Yu45bea152005-07-23 04:08:00 -0400888
889 /*
890 * Generate a temporary ec context to use until the namespace is scanned
891 */
Burman Yan36bcbec2006-12-19 12:56:11 -0800892 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Luming Yu45bea152005-07-23 04:08:00 -0400893 if (!ec_ecdt)
894 return -ENOMEM;
Luming Yu45bea152005-07-23 04:08:00 -0400895
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300896 mutex_init(&ec_ecdt->lock);
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500897 atomic_set(&ec_ecdt->event_count, 1);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400898 if (acpi_ec_mode == EC_INTR) {
899 init_waitqueue_head(&ec_ecdt->wait);
900 }
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300901 ec_ecdt->command_addr = ecdt_ptr->control.address;
902 ec_ecdt->data_addr = ecdt_ptr->data.address;
903 ec_ecdt->gpe = ecdt_ptr->gpe;
Luming Yu45bea152005-07-23 04:08:00 -0400904 /* use the GL just to be safe */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400905 ec_ecdt->global_lock = TRUE;
906 ec_ecdt->uid = ecdt_ptr->uid;
Luming Yu45bea152005-07-23 04:08:00 -0400907
Alexey Starikovskiyad363f82007-02-02 19:48:22 +0300908 status = acpi_get_handle(NULL, ecdt_ptr->id, &ec_ecdt->handle);
Luming Yu45bea152005-07-23 04:08:00 -0400909 if (ACPI_FAILURE(status)) {
910 goto error;
911 }
912
913 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300914 error:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400915 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 kfree(ec_ecdt);
917 ec_ecdt = NULL;
918
919 return -ENODEV;
920}
921
922static int __initdata acpi_fake_ecdt_enabled;
Len Brown50526df2005-08-11 17:32:05 -0400923int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
Len Brown50526df2005-08-11 17:32:05 -0400925 acpi_status status;
926 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 ret = acpi_ec_get_real_ecdt();
929 /* Try to make a fake ECDT */
930 if (ret && acpi_fake_ecdt_enabled) {
931 ret = acpi_ec_fake_ecdt();
932 }
933
934 if (ret)
935 return 0;
936
937 /*
938 * Install GPE handler
939 */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300940 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400941 ACPI_GPE_EDGE_TRIGGERED,
942 &acpi_ec_gpe_handler, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (ACPI_FAILURE(status)) {
944 goto error;
945 }
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300946 acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME);
947 acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Len Brown50526df2005-08-11 17:32:05 -0400949 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
950 ACPI_ADR_SPACE_EC,
951 &acpi_ec_space_handler,
952 &acpi_ec_space_setup,
953 ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (ACPI_FAILURE(status)) {
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300955 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400956 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 goto error;
958 }
959
960 return 0;
961
Len Brown50526df2005-08-11 17:32:05 -0400962 error:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400963 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 kfree(ec_ecdt);
965 ec_ecdt = NULL;
966
967 return -ENODEV;
968}
969
Len Brown50526df2005-08-11 17:32:05 -0400970static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Len Brown50526df2005-08-11 17:32:05 -0400972 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400975 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
978 if (!acpi_ec_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400979 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 /* Now register the driver for the EC */
982 result = acpi_bus_register_driver(&acpi_ec_driver);
983 if (result < 0) {
984 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -0400985 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987
Patrick Mocheld550d982006-06-27 00:41:40 -0400988 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991subsys_initcall(acpi_ec_init);
992
993/* EC driver currently not unloadable */
994#if 0
Len Brown50526df2005-08-11 17:32:05 -0400995static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 acpi_bus_unregister_driver(&acpi_ec_driver);
999
1000 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1001
Patrick Mocheld550d982006-06-27 00:41:40 -04001002 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
Len Brown50526df2005-08-11 17:32:05 -04001004#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006static int __init acpi_fake_ecdt_setup(char *str)
1007{
1008 acpi_fake_ecdt_enabled = 1;
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001009 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
Luming Yu7b15f5e2005-08-03 17:38:04 -04001011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
Len Brown02b28a32005-12-05 16:33:04 -05001013static int __init acpi_ec_set_intr_mode(char *str)
Luming Yu45bea152005-07-23 04:08:00 -04001014{
Len Brown02b28a32005-12-05 16:33:04 -05001015 int intr;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001016
Len Brown02b28a32005-12-05 16:33:04 -05001017 if (!get_option(&str, &intr))
Luming Yu7b15f5e2005-08-03 17:38:04 -04001018 return 0;
1019
Len Brown02b28a32005-12-05 16:33:04 -05001020 if (intr) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001021 acpi_ec_mode = EC_INTR;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001022 } else {
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001023 acpi_ec_mode = EC_POLL;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001024 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001025 acpi_ec_driver.ops.add = acpi_ec_add;
Alexey Starikovskiy9e197212007-03-07 18:29:35 -05001026 printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling");
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001027
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001028 return 1;
Luming Yu45bea152005-07-23 04:08:00 -04001029}
Len Brown50526df2005-08-11 17:32:05 -04001030
Len Brown53f11d42005-12-05 16:46:36 -05001031__setup("ec_intr=", acpi_ec_set_intr_mode);