blob: e2cfc9e078e9bfb0d42d8703180f88f7686c654a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/delay.h>
32#include <linux/proc_fs.h>
33#include <linux/seq_file.h>
Dmitry Torokhov451566f2005-03-19 01:10:05 -050034#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/io.h>
36#include <acpi/acpi_bus.h>
37#include <acpi/acpi_drivers.h>
38#include <acpi/actypes.h>
39
40#define _COMPONENT ACPI_EC_COMPONENT
Len Brown50526df2005-08-11 17:32:05 -040041ACPI_MODULE_NAME("acpi_ec")
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define ACPI_EC_COMPONENT 0x00100000
43#define ACPI_EC_CLASS "embedded_controller"
44#define ACPI_EC_HID "PNP0C09"
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info"
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +030048#undef PREFIX
49#define PREFIX "ACPI: EC: "
Denis M. Sadykov703959d2006-09-26 19:50:33 +040050/* EC status register */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
Dmitry Torokhov451566f2005-03-19 01:10:05 -050053#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040055/* EC commands */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030056enum ec_command {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030057 ACPI_EC_COMMAND_READ = 0x80,
58 ACPI_EC_COMMAND_WRITE = 0x81,
59 ACPI_EC_BURST_ENABLE = 0x82,
60 ACPI_EC_BURST_DISABLE = 0x83,
61 ACPI_EC_COMMAND_QUERY = 0x84,
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030062};
Denis M. Sadykov703959d2006-09-26 19:50:33 +040063/* EC events */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030064enum ec_event {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040065 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030066 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040067};
68
Alexey Starikovskiy5c406412006-12-07 18:42:16 +030069#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040070#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040071
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030072static enum ec_mode {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030073 EC_INTR = 1, /* Output buffer full */
74 EC_POLL, /* Input buffer empty */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030075} acpi_ec_mode = EC_INTR;
Denis M. Sadykov703959d2006-09-26 19:50:33 +040076
Len Brown50526df2005-08-11 17:32:05 -040077static int acpi_ec_remove(struct acpi_device *device, int type);
78static int acpi_ec_start(struct acpi_device *device);
79static int acpi_ec_stop(struct acpi_device *device, int type);
Denis M. Sadykov703959d2006-09-26 19:50:33 +040080static int acpi_ec_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82static struct acpi_driver acpi_ec_driver = {
Len Brown50526df2005-08-11 17:32:05 -040083 .name = ACPI_EC_DRIVER_NAME,
84 .class = ACPI_EC_CLASS,
85 .ids = ACPI_EC_HID,
86 .ops = {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040087 .add = acpi_ec_add,
Len Brown50526df2005-08-11 17:32:05 -040088 .remove = acpi_ec_remove,
89 .start = acpi_ec_start,
90 .stop = acpi_ec_stop,
91 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +040093
94/* If we find an EC via the ECDT, we need to keep a ptr to its context */
Adrian Bunka854e082006-12-19 12:56:12 -080095static struct acpi_ec {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040096 acpi_handle handle;
97 unsigned long uid;
Alexey Starikovskiya86e2772006-12-07 18:42:16 +030098 unsigned long gpe;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +040099 unsigned long command_addr;
100 unsigned long data_addr;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400101 unsigned long global_lock;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300102 struct mutex lock;
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300103 atomic_t query_pending;
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 Starikovskiy3261ff42006-12-07 18:42:17 +0300135static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400136{
Alexey Starikovskiybec5a1e2006-12-07 18:42:16 +0300137 u8 status = acpi_ec_read_status(ec);
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300138
139 if (event == ACPI_EC_EVENT_OBF_1) {
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400140 if (status & ACPI_EC_FLAG_OBF)
141 return 1;
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300142 } else if (event == ACPI_EC_EVENT_IBF_0) {
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400143 if (!(status & ACPI_EC_FLAG_IBF))
144 return 1;
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400145 }
146
147 return 0;
148}
149
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +0300150static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event)
Luming Yu45bea152005-07-23 04:08:00 -0400151{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300152 if (acpi_ec_mode == EC_POLL) {
Alexey Starikovskiy50c1e112006-12-07 18:42:17 +0300153 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
154 while (time_before(jiffies, delay)) {
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300155 if (acpi_ec_check_status(ec, event))
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400156 return 0;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400157 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300158 } else {
159 if (wait_event_timeout(ec->wait,
160 acpi_ec_check_status(ec, event),
161 msecs_to_jiffies(ACPI_EC_DELAY)) ||
162 acpi_ec_check_status(ec, event)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400163 return 0;
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300164 } else {
165 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
166 " status = %d, expect_event = %d\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300167 acpi_ec_read_status(ec), event);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400168 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300169 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400170
Patrick Mocheld550d982006-06-27 00:41:40 -0400171 return -ETIME;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500172}
173
Len Brown02b28a32005-12-05 16:33:04 -0500174#ifdef ACPI_FUTURE_USAGE
Luming Yu06a2a382005-09-27 00:43:00 -0400175/*
176 * Note: samsung nv5000 doesn't work with ec burst mode.
177 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
178 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400179int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500180{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400181 u8 tmp = 0;
182 u8 status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500183
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500184 status = acpi_ec_read_status(ec);
Len Brown50526df2005-08-11 17:32:05 -0400185 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400186 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Len Brown50526df2005-08-11 17:32:05 -0400187 if (status)
Luming Yu716e0842005-08-10 01:40:00 -0400188 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400189 acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE);
190 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
191 tmp = acpi_ec_read_data(ec);
Len Brown50526df2005-08-11 17:32:05 -0400192 if (tmp != 0x90) { /* Burst ACK byte */
Patrick Mocheld550d982006-06-27 00:41:40 -0400193 return -EINVAL;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500194 }
Luming Yu668d74c2005-07-23 00:26:33 -0400195 }
196
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400197 atomic_set(&ec->leaving_burst, 0);
Patrick Mocheld550d982006-06-27 00:41:40 -0400198 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300199 end:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400200 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400201 return -1;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500202}
203
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400204int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500205{
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400206 u8 status = 0;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500207
Luming Yu06a2a382005-09-27 00:43:00 -0400208 status = acpi_ec_read_status(ec);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300209 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400210 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300211 if (status)
Luming Yu06a2a382005-09-27 00:43:00 -0400212 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400213 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
214 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400215 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400216 atomic_set(&ec->leaving_burst, 1);
Patrick Mocheld550d982006-06-27 00:41:40 -0400217 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300218 end:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400219 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400220 return -1;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500221}
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300222#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400224static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300225 const u8 * wdata, unsigned wdata_len,
226 u8 * rdata, unsigned rdata_len)
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400227{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300228 int result = 0;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400229
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400230 acpi_ec_write_cmd(ec, command);
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400231
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300232 for (; wdata_len > 0; --wdata_len) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400233 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300234 if (result) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300235 printk(KERN_ERR PREFIX
236 "write_cmd timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300237 goto end;
238 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400239 acpi_ec_write_data(ec, *(wdata++));
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400240 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400241
Alexey Starikovskiyd91df1a2006-12-07 18:42:16 +0300242 if (!rdata_len) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400243 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300244 if (result) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300245 printk(KERN_ERR PREFIX
246 "finish-write timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300247 goto end;
248 }
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300249 } else if (command == ACPI_EC_COMMAND_QUERY) {
250 atomic_set(&ec->query_pending, 0);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400251 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400252
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300253 for (; rdata_len > 0; --rdata_len) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400254 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300255 if (result) {
256 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300257 command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300258 goto end;
259 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400260
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400261 *(rdata++) = acpi_ec_read_data(ec);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400262 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300263 end:
264 return result;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400265}
266
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400267static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300268 const u8 * wdata, unsigned wdata_len,
269 u8 * rdata, unsigned rdata_len)
Luming Yu45bea152005-07-23 04:08:00 -0400270{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400271 int status;
Len Brown50526df2005-08-11 17:32:05 -0400272 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400274 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
Patrick Mocheld550d982006-06-27 00:41:40 -0400275 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300277 if (rdata)
278 memset(rdata, 0, rdata_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300280 mutex_lock(&ec->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400281 if (ec->global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
283 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400284 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500286
Alexey Starikovskiy5d57a6a2006-12-07 18:42:16 +0300287 /* Make sure GPE is enabled before doing transaction */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300288 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Alexey Starikovskiy5d57a6a2006-12-07 18:42:16 +0300289
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400290 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
Luming Yu716e0842005-08-10 01:40:00 -0400291 if (status) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300292 printk(KERN_DEBUG PREFIX
293 "input buffer is not empty, aborting transaction\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500294 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300297 status = acpi_ec_transaction_unlocked(ec, command,
298 wdata, wdata_len,
299 rdata, rdata_len);
Len Brown50526df2005-08-11 17:32:05 -0400300
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300301 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400303 if (ec->global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 acpi_release_global_lock(glk);
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300305 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Patrick Mocheld550d982006-06-27 00:41:40 -0400307 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300310static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400311{
312 int result;
313 u8 d;
314
315 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
316 &address, 1, &d, 1);
317 *data = d;
318 return result;
319}
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400320
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400321static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
322{
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300323 u8 wdata[2] = { address, data };
324 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400325 wdata, 2, NULL, 0);
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/*
329 * Externally callable EC access functions. For now, assume 1 EC only
330 */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300331int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400333 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 int err;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400335 u8 temp_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if (!first_ec)
338 return -ENODEV;
339
340 ec = acpi_driver_data(first_ec);
341
342 err = acpi_ec_read(ec, addr, &temp_data);
343
344 if (!err) {
345 *val = temp_data;
346 return 0;
Len Brown50526df2005-08-11 17:32:05 -0400347 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return err;
349}
Len Brown50526df2005-08-11 17:32:05 -0400350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351EXPORT_SYMBOL(ec_read);
352
Len Brown50526df2005-08-11 17:32:05 -0400353int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400355 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 int err;
357
358 if (!first_ec)
359 return -ENODEV;
360
361 ec = acpi_driver_data(first_ec);
362
363 err = acpi_ec_write(ec, addr, val);
364
365 return err;
366}
Len Brown50526df2005-08-11 17:32:05 -0400367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368EXPORT_SYMBOL(ec_write);
369
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400370extern int ec_transaction(u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300371 const u8 * wdata, unsigned wdata_len,
372 u8 * rdata, unsigned rdata_len)
Luming Yu45bea152005-07-23 04:08:00 -0400373{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400374 struct acpi_ec *ec;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400375
376 if (!first_ec)
377 return -ENODEV;
378
379 ec = acpi_driver_data(first_ec);
380
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400381 return acpi_ec_transaction(ec, command, wdata,
382 wdata_len, rdata, rdata_len);
Luming Yu45bea152005-07-23 04:08:00 -0400383}
Luming Yu45bea152005-07-23 04:08:00 -0400384
Lennart Poetteringab9e43c2006-10-03 22:49:00 -0400385EXPORT_SYMBOL(ec_transaction);
386
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300387static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400388{
389 int result;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300390 u8 d;
Luming Yu45bea152005-07-23 04:08:00 -0400391
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300392 if (!ec || !data)
393 return -EINVAL;
Luming Yu45bea152005-07-23 04:08:00 -0400394
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300395 /*
396 * Query the EC to find out which _Qxx method we need to evaluate.
397 * Note that successful completion of the query causes the ACPI_EC_SCI
398 * bit to be cleared (and thus clearing the interrupt source).
399 */
Luming Yu45bea152005-07-23 04:08:00 -0400400
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300401 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
402 if (result)
403 return result;
Luming Yu45bea152005-07-23 04:08:00 -0400404
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300405 if (!d)
406 return -ENODATA;
Luming Yu45bea152005-07-23 04:08:00 -0400407
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300408 *data = d;
409 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412/* --------------------------------------------------------------------------
413 Event Management
414 -------------------------------------------------------------------------- */
415
Len Brown50526df2005-08-11 17:32:05 -0400416static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400418 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400419 u8 value = 0;
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300420 char object_name[8];
Luming Yu45bea152005-07-23 04:08:00 -0400421
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300422 if (!ec || acpi_ec_query(ec, &value))
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300423 return;
Luming Yu45bea152005-07-23 04:08:00 -0400424
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400425 snprintf(object_name, 8, "_Q%2.2X", value);
Luming Yu45bea152005-07-23 04:08:00 -0400426
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300427 printk(KERN_INFO PREFIX "evaluating %s\n", object_name);
Luming Yu45bea152005-07-23 04:08:00 -0400428
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400429 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
Luming Yu45bea152005-07-23 04:08:00 -0400430}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Len Brown50526df2005-08-11 17:32:05 -0400432static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Len Brown50526df2005-08-11 17:32:05 -0400434 acpi_status status = AE_OK;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400435 u8 value;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400436 struct acpi_ec *ec = (struct acpi_ec *)data;
Luming Yu45bea152005-07-23 04:08:00 -0400437
Denis M. Sadykov8e0341b2006-09-26 19:50:33 +0400438 if (acpi_ec_mode == EC_INTR) {
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300439 wake_up(&ec->wait);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500440 }
441
Alexey Starikovskiybec5a1e2006-12-07 18:42:16 +0300442 value = acpi_ec_read_status(ec);
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300443 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
444 atomic_set(&ec->query_pending, 1);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300445 status =
446 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
447 ec);
Len Brown50526df2005-08-11 17:32:05 -0400448 }
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300449
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500450 return status == AE_OK ?
Len Brown50526df2005-08-11 17:32:05 -0400451 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454/* --------------------------------------------------------------------------
455 Address Space Management
456 -------------------------------------------------------------------------- */
457
458static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400459acpi_ec_space_setup(acpi_handle region_handle,
460 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 /*
463 * The EC object is in the handler context and is needed
464 * when calling the acpi_ec_space_handler.
465 */
Len Brown50526df2005-08-11 17:32:05 -0400466 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
467 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 return AE_OK;
470}
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400473acpi_ec_space_handler(u32 function,
474 acpi_physical_address address,
475 u32 bit_width,
476 acpi_integer * value,
477 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Len Brown50526df2005-08-11 17:32:05 -0400479 int result = 0;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400480 struct acpi_ec *ec = NULL;
Len Brown50526df2005-08-11 17:32:05 -0400481 u64 temp = *value;
482 acpi_integer f_v = 0;
483 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 if ((address > 0xFF) || !value || !handler_context)
Patrick Mocheld550d982006-06-27 00:41:40 -0400486 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Luming Yufa9cd542005-03-19 01:54:47 -0500488 if (bit_width != 8 && acpi_strict) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400489 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400492 ec = (struct acpi_ec *)handler_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Len Brown50526df2005-08-11 17:32:05 -0400494 next_byte:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 switch (function) {
496 case ACPI_READ:
Luming Yufa9cd542005-03-19 01:54:47 -0500497 temp = 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300498 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 break;
500 case ACPI_WRITE:
Luming Yufa9cd542005-03-19 01:54:47 -0500501 result = acpi_ec_write(ec, (u8) address, (u8) temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 break;
503 default:
504 result = -EINVAL;
505 goto out;
506 break;
507 }
508
509 bit_width -= 8;
Luming Yufa9cd542005-03-19 01:54:47 -0500510 if (bit_width) {
511 if (function == ACPI_READ)
512 f_v |= temp << 8 * i;
513 if (function == ACPI_WRITE)
514 temp >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 i++;
Andrew Morton83ea7442005-03-30 22:12:13 -0500516 address++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 goto next_byte;
518 }
519
Luming Yufa9cd542005-03-19 01:54:47 -0500520 if (function == ACPI_READ) {
521 f_v |= temp << 8 * i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 *value = f_v;
523 }
524
Len Brown50526df2005-08-11 17:32:05 -0400525 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 switch (result) {
527 case -EINVAL:
Patrick Mocheld550d982006-06-27 00:41:40 -0400528 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 break;
530 case -ENODEV:
Patrick Mocheld550d982006-06-27 00:41:40 -0400531 return AE_NOT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 break;
533 case -ETIME:
Patrick Mocheld550d982006-06-27 00:41:40 -0400534 return AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 break;
536 default:
Patrick Mocheld550d982006-06-27 00:41:40 -0400537 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541/* --------------------------------------------------------------------------
542 FS Interface (/proc)
543 -------------------------------------------------------------------------- */
544
Len Brown50526df2005-08-11 17:32:05 -0400545static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Len Brown50526df2005-08-11 17:32:05 -0400547static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400549 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (!ec)
552 goto end;
553
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300554 seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300556 (u32) ec->command_addr, (u32) ec->data_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 seq_printf(seq, "use global lock: %s\n",
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400558 ec->global_lock ? "yes" : "no");
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300559 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Len Brown50526df2005-08-11 17:32:05 -0400561 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
566{
567 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
568}
569
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400570static struct file_operations acpi_ec_info_ops = {
Len Brown50526df2005-08-11 17:32:05 -0400571 .open = acpi_ec_info_open_fs,
572 .read = seq_read,
573 .llseek = seq_lseek,
574 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .owner = THIS_MODULE,
576};
577
Len Brown50526df2005-08-11 17:32:05 -0400578static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Len Brown50526df2005-08-11 17:32:05 -0400580 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 if (!acpi_device_dir(device)) {
583 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown50526df2005-08-11 17:32:05 -0400584 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400586 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
588
589 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown50526df2005-08-11 17:32:05 -0400590 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400592 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 else {
594 entry->proc_fops = &acpi_ec_info_ops;
595 entry->data = acpi_driver_data(device);
596 entry->owner = THIS_MODULE;
597 }
598
Patrick Mocheld550d982006-06-27 00:41:40 -0400599 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Len Brown50526df2005-08-11 17:32:05 -0400602static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (acpi_device_dir(device)) {
606 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
607 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
608 acpi_device_dir(device) = NULL;
609 }
610
Patrick Mocheld550d982006-06-27 00:41:40 -0400611 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/* --------------------------------------------------------------------------
615 Driver Interface
616 -------------------------------------------------------------------------- */
617
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400618static int acpi_ec_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Len Brown50526df2005-08-11 17:32:05 -0400620 int result = 0;
621 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400622 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400625 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400627 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400629 return -ENOMEM;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400630 memset(ec, 0, sizeof(struct acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400632 ec->handle = device->handle;
633 ec->uid = -1;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300634 mutex_init(&ec->lock);
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300635 atomic_set(&ec->query_pending, 0);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400636 if (acpi_ec_mode == EC_INTR) {
637 atomic_set(&ec->leaving_burst, 1);
638 init_waitqueue_head(&ec->wait);
639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
641 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
642 acpi_driver_data(device) = ec;
643
644 /* Use the global lock for all EC transactions? */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300645 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Jiri Slabyff2fc3e2006-03-28 17:04:00 -0500647 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
648 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
649 if (ec_ecdt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
Len Brown50526df2005-08-11 17:32:05 -0400651 ACPI_ADR_SPACE_EC,
652 &acpi_ec_space_handler);
653
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300654 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400655 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 kfree(ec_ecdt);
658 }
659
660 /* Get GPE bit assignment (EC events). */
661 /* TODO: Add support for _GPE returning a package */
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300662 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300664 ACPI_EXCEPTION((AE_INFO, status,
665 "Obtaining GPE bit assignment"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 result = -ENODEV;
667 goto end;
668 }
669
670 result = acpi_ec_add_fs(device);
671 if (result)
672 goto end;
673
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400674 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300675 acpi_device_name(device), acpi_device_bid(device),
676 (u32) ec->gpe));
Luming Yu45bea152005-07-23 04:08:00 -0400677
678 if (!first_ec)
679 first_ec = device;
680
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300681 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 if (result)
683 kfree(ec);
684
Patrick Mocheld550d982006-06-27 00:41:40 -0400685 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
Len Brown50526df2005-08-11 17:32:05 -0400688static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400690 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400693 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 ec = acpi_driver_data(device);
696
697 acpi_ec_remove_fs(device);
698
699 kfree(ec);
700
Patrick Mocheld550d982006-06-27 00:41:40 -0400701 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400705acpi_ec_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400707 struct acpi_ec *ec = (struct acpi_ec *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Bob Moore50eca3e2005-09-30 19:03:00 -0400709 if (resource->type != ACPI_RESOURCE_TYPE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return AE_OK;
711 }
712
713 /*
714 * The first address region returned is the data port, and
715 * the second address region returned is the status/command
716 * port.
717 */
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400718 if (ec->data_addr == 0) {
719 ec->data_addr = resource->data.io.minimum;
720 } else if (ec->command_addr == 0) {
721 ec->command_addr = resource->data.io.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 } else {
723 return AE_CTRL_TERMINATE;
724 }
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return AE_OK;
727}
728
Len Brown50526df2005-08-11 17:32:05 -0400729static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Len Brown50526df2005-08-11 17:32:05 -0400731 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400732 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 ec = acpi_driver_data(device);
738
739 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /*
743 * Get I/O port addresses. Convert to GAS format.
744 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400745 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -0400746 acpi_ec_io_ports, ec);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400747 if (ACPI_FAILURE(status) || ec->command_addr == 0) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400748 ACPI_EXCEPTION((AE_INFO, status,
749 "Error getting I/O port addresses"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400750 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400753 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300754 ec->gpe, ec->command_addr, ec->data_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 /*
757 * Install GPE handler
758 */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300759 status = acpi_install_gpe_handler(NULL, ec->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400760 ACPI_GPE_EDGE_TRIGGERED,
761 &acpi_ec_gpe_handler, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 if (ACPI_FAILURE(status)) {
Patrick Mocheld550d982006-06-27 00:41:40 -0400763 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300765 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
766 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400768 status = acpi_install_address_space_handler(ec->handle,
Len Brown50526df2005-08-11 17:32:05 -0400769 ACPI_ADR_SPACE_EC,
770 &acpi_ec_space_handler,
771 &acpi_ec_space_setup, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (ACPI_FAILURE(status)) {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300773 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776
Patrick Mocheld550d982006-06-27 00:41:40 -0400777 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
Len Brown50526df2005-08-11 17:32:05 -0400780static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Len Brown50526df2005-08-11 17:32:05 -0400782 acpi_status status = AE_OK;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400783 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400786 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 ec = acpi_driver_data(device);
789
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400790 status = acpi_remove_address_space_handler(ec->handle,
Len Brown50526df2005-08-11 17:32:05 -0400791 ACPI_ADR_SPACE_EC,
792 &acpi_ec_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400794 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300796 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Patrick Mocheld550d982006-06-27 00:41:40 -0400800 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
803static acpi_status __init
Len Brown50526df2005-08-11 17:32:05 -0400804acpi_fake_ecdt_callback(acpi_handle handle,
805 u32 Level, void *context, void **retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
Len Brown50526df2005-08-11 17:32:05 -0400807 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300809 mutex_init(&ec_ecdt->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400810 if (acpi_ec_mode == EC_INTR) {
811 init_waitqueue_head(&ec_ecdt->wait);
812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Len Brown50526df2005-08-11 17:32:05 -0400814 acpi_ec_io_ports, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (ACPI_FAILURE(status))
816 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400818 ec_ecdt->uid = -1;
819 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300821 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (ACPI_FAILURE(status))
823 return status;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400824 ec_ecdt->global_lock = TRUE;
825 ec_ecdt->handle = handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400827 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300828 ec_ecdt->gpe, ec_ecdt->command_addr,
829 ec_ecdt->data_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 return AE_CTRL_TERMINATE;
832}
833
834/*
835 * Some BIOS (such as some from Gateway laptops) access EC region very early
836 * such as in BAT0._INI or EC._INI before an EC device is found and
837 * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily
838 * required, but if EC regison is accessed early, it is required.
839 * The routine tries to workaround the BIOS bug by pre-scan EC device
840 * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any
841 * op region (since _REG isn't invoked yet). The assumption is true for
842 * all systems found.
843 */
Len Brown50526df2005-08-11 17:32:05 -0400844static int __init acpi_ec_fake_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Len Brown50526df2005-08-11 17:32:05 -0400846 acpi_status status;
847 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400849 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400851 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (!ec_ecdt) {
853 ret = -ENOMEM;
854 goto error;
855 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400856 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Len Brown50526df2005-08-11 17:32:05 -0400858 status = acpi_get_devices(ACPI_EC_HID,
859 acpi_fake_ecdt_callback, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (ACPI_FAILURE(status)) {
861 kfree(ec_ecdt);
862 ec_ecdt = NULL;
863 ret = -ENODEV;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400864 ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 goto error;
866 }
867 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300868 error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 return ret;
870}
871
Len Brown50526df2005-08-11 17:32:05 -0400872static int __init acpi_ec_get_real_ecdt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Len Brown50526df2005-08-11 17:32:05 -0400874 acpi_status status;
875 struct acpi_table_ecdt *ecdt_ptr;
Luming Yu45bea152005-07-23 04:08:00 -0400876
Len Brown50526df2005-08-11 17:32:05 -0400877 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
878 (struct acpi_table_header **)
879 &ecdt_ptr);
Luming Yu45bea152005-07-23 04:08:00 -0400880 if (ACPI_FAILURE(status))
881 return -ENODEV;
882
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400883 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT"));
Luming Yu45bea152005-07-23 04:08:00 -0400884
885 /*
886 * Generate a temporary ec context to use until the namespace is scanned
887 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400888 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
Luming Yu45bea152005-07-23 04:08:00 -0400889 if (!ec_ecdt)
890 return -ENOMEM;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400891 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
Luming Yu45bea152005-07-23 04:08:00 -0400892
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300893 mutex_init(&ec_ecdt->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400894 if (acpi_ec_mode == EC_INTR) {
895 init_waitqueue_head(&ec_ecdt->wait);
896 }
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400897 ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
898 ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300899 ec_ecdt->gpe = ecdt_ptr->gpe_bit;
Luming Yu45bea152005-07-23 04:08:00 -0400900 /* use the GL just to be safe */
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400901 ec_ecdt->global_lock = TRUE;
902 ec_ecdt->uid = ecdt_ptr->uid;
Luming Yu45bea152005-07-23 04:08:00 -0400903
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300904 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
Luming Yu45bea152005-07-23 04:08:00 -0400905 if (ACPI_FAILURE(status)) {
906 goto error;
907 }
908
909 return 0;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300910 error:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400911 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 kfree(ec_ecdt);
913 ec_ecdt = NULL;
914
915 return -ENODEV;
916}
917
918static int __initdata acpi_fake_ecdt_enabled;
Len Brown50526df2005-08-11 17:32:05 -0400919int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
Len Brown50526df2005-08-11 17:32:05 -0400921 acpi_status status;
922 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 ret = acpi_ec_get_real_ecdt();
925 /* Try to make a fake ECDT */
926 if (ret && acpi_fake_ecdt_enabled) {
927 ret = acpi_ec_fake_ecdt();
928 }
929
930 if (ret)
931 return 0;
932
933 /*
934 * Install GPE handler
935 */
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300936 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400937 ACPI_GPE_EDGE_TRIGGERED,
938 &acpi_ec_gpe_handler, ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (ACPI_FAILURE(status)) {
940 goto error;
941 }
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300942 acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME);
943 acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Len Brown50526df2005-08-11 17:32:05 -0400945 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
946 ACPI_ADR_SPACE_EC,
947 &acpi_ec_space_handler,
948 &acpi_ec_space_setup,
949 ec_ecdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 if (ACPI_FAILURE(status)) {
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300951 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
Len Brown50526df2005-08-11 17:32:05 -0400952 &acpi_ec_gpe_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 goto error;
954 }
955
956 return 0;
957
Len Brown50526df2005-08-11 17:32:05 -0400958 error:
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400959 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 kfree(ec_ecdt);
961 ec_ecdt = NULL;
962
963 return -ENODEV;
964}
965
Len Brown50526df2005-08-11 17:32:05 -0400966static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Len Brown50526df2005-08-11 17:32:05 -0400968 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400971 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
974 if (!acpi_ec_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400975 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /* Now register the driver for the EC */
978 result = acpi_bus_register_driver(&acpi_ec_driver);
979 if (result < 0) {
980 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -0400981 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983
Patrick Mocheld550d982006-06-27 00:41:40 -0400984 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
987subsys_initcall(acpi_ec_init);
988
989/* EC driver currently not unloadable */
990#if 0
Len Brown50526df2005-08-11 17:32:05 -0400991static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 acpi_bus_unregister_driver(&acpi_ec_driver);
995
996 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
997
Patrick Mocheld550d982006-06-27 00:41:40 -0400998 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
Len Brown50526df2005-08-11 17:32:05 -04001000#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002static int __init acpi_fake_ecdt_setup(char *str)
1003{
1004 acpi_fake_ecdt_enabled = 1;
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001005 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
Luming Yu7b15f5e2005-08-03 17:38:04 -04001007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
Len Brown02b28a32005-12-05 16:33:04 -05001009static int __init acpi_ec_set_intr_mode(char *str)
Luming Yu45bea152005-07-23 04:08:00 -04001010{
Len Brown02b28a32005-12-05 16:33:04 -05001011 int intr;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001012
Len Brown02b28a32005-12-05 16:33:04 -05001013 if (!get_option(&str, &intr))
Luming Yu7b15f5e2005-08-03 17:38:04 -04001014 return 0;
1015
Len Brown02b28a32005-12-05 16:33:04 -05001016 if (intr) {
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001017 acpi_ec_mode = EC_INTR;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001018 } else {
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001019 acpi_ec_mode = EC_POLL;
Luming Yu7b15f5e2005-08-03 17:38:04 -04001020 }
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001021 acpi_ec_driver.ops.add = acpi_ec_add;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +03001022 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n",
1023 intr ? "interrupt" : "polling"));
Denis M. Sadykov703959d2006-09-26 19:50:33 +04001024
OGAWA Hirofumi9b410462006-03-31 02:30:33 -08001025 return 1;
Luming Yu45bea152005-07-23 04:08:00 -04001026}
Len Brown50526df2005-08-11 17:32:05 -04001027
Len Brown53f11d42005-12-05 16:46:36 -05001028__setup("ec_intr=", acpi_ec_set_intr_mode);