blob: 828c75292cf69f7bbfe12f1f333c2351cdc3c415 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Alexey Starikovskiy01f22462007-03-07 22:28:00 +03002 * ec.c - ACPI Embedded Controller Driver (v2.0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Alexey Starikovskiy01f22462007-03-07 22:28:00 +03004 * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
7 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
8 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 */
28
Márton Némethd772b3b2008-01-23 22:34:09 -050029/* Uncomment next line to get verbose print outs*/
30/* #define DEBUG */
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/types.h>
36#include <linux/delay.h>
37#include <linux/proc_fs.h>
38#include <linux/seq_file.h>
Dmitry Torokhov451566f2005-03-19 01:10:05 -050039#include <linux/interrupt.h>
Alexey Starikovskiy837012e2007-05-29 16:43:02 +040040#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
42#include <acpi/acpi_bus.h>
43#include <acpi/acpi_drivers.h>
44#include <acpi/actypes.h>
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define ACPI_EC_CLASS "embedded_controller"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define ACPI_EC_DEVICE_NAME "Embedded Controller"
48#define ACPI_EC_FILE_INFO "info"
Alexey Starikovskiy837012e2007-05-29 16:43:02 +040049
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +030050#undef PREFIX
51#define PREFIX "ACPI: EC: "
Alexey Starikovskiy43509332007-05-29 16:42:57 +040052
Denis M. Sadykov703959d2006-09-26 19:50:33 +040053/* EC status register */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
55#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
Dmitry Torokhov451566f2005-03-19 01:10:05 -050056#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
Alexey Starikovskiy43509332007-05-29 16:42:57 +040058
Denis M. Sadykov703959d2006-09-26 19:50:33 +040059/* EC commands */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030060enum ec_command {
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +030061 ACPI_EC_COMMAND_READ = 0x80,
62 ACPI_EC_COMMAND_WRITE = 0x81,
63 ACPI_EC_BURST_ENABLE = 0x82,
64 ACPI_EC_BURST_DISABLE = 0x83,
65 ACPI_EC_COMMAND_QUERY = 0x84,
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030066};
Alexey Starikovskiy837012e2007-05-29 16:43:02 +040067
Denis M. Sadykov703959d2006-09-26 19:50:33 +040068/* EC events */
Alexey Starikovskiy3261ff42006-12-07 18:42:17 +030069enum ec_event {
Denis M. Sadykov703959d2006-09-26 19:50:33 +040070 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
Alexey Starikovskiy080e4122007-10-22 14:18:30 +040071 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040072};
73
Alexey Starikovskiy5c406412006-12-07 18:42:16 +030074#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040075#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
Alexey Starikovskiye6e82a32008-03-21 17:06:57 +030076#define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040077
Alexey Starikovskiy080e4122007-10-22 14:18:30 +040078enum {
79 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
80 EC_FLAGS_QUERY_PENDING, /* Query is pending */
Alexey Starikovskiy78439322007-10-22 14:18:43 +040081 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +030082 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
83 EC_FLAGS_ADDRESS, /* Address is being written */
Alexey Starikovskiye790cc82007-11-21 03:23:32 +030084 EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */
85 EC_FLAGS_WDATA, /* Data is being written */
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -050086 EC_FLAGS_NO_OBF1_GPE, /* Don't expect GPE before read */
Alexey Starikovskiy080e4122007-10-22 14:18:30 +040087};
88
Len Brown50526df2005-08-11 17:32:05 -040089static int acpi_ec_remove(struct acpi_device *device, int type);
90static int acpi_ec_start(struct acpi_device *device);
91static int acpi_ec_stop(struct acpi_device *device, int type);
Denis M. Sadykov703959d2006-09-26 19:50:33 +040092static int acpi_ec_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Thomas Renninger1ba90e32007-07-23 14:44:41 +020094static const struct acpi_device_id ec_device_ids[] = {
95 {"PNP0C09", 0},
96 {"", 0},
97};
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static struct acpi_driver acpi_ec_driver = {
Len Brownc2b67052007-02-12 23:33:40 -0500100 .name = "ec",
Len Brown50526df2005-08-11 17:32:05 -0400101 .class = ACPI_EC_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200102 .ids = ec_device_ids,
Len Brown50526df2005-08-11 17:32:05 -0400103 .ops = {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400104 .add = acpi_ec_add,
Len Brown50526df2005-08-11 17:32:05 -0400105 .remove = acpi_ec_remove,
106 .start = acpi_ec_start,
107 .stop = acpi_ec_stop,
108 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400110
111/* If we find an EC via the ECDT, we need to keep a ptr to its context */
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300112/* External interfaces use first EC only, so remember */
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400113typedef int (*acpi_ec_query_func) (void *data);
114
115struct acpi_ec_query_handler {
116 struct list_head node;
117 acpi_ec_query_func func;
118 acpi_handle handle;
119 void *data;
120 u8 query_bit;
121};
122
Adrian Bunka854e082006-12-19 12:56:12 -0800123static struct acpi_ec {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400124 acpi_handle handle;
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300125 unsigned long gpe;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400126 unsigned long command_addr;
127 unsigned long data_addr;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400128 unsigned long global_lock;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400129 unsigned long flags;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300130 struct mutex lock;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400131 wait_queue_head_t wait;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400132 struct list_head list;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400133 u8 handlers_installed;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300134} *boot_ec, *first_ec;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* --------------------------------------------------------------------------
137 Transaction Management
138 -------------------------------------------------------------------------- */
139
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400140static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Márton Németh3ebe08a2007-11-21 03:23:26 +0300142 u8 x = inb(ec->command_addr);
Márton Németh86dae012008-01-23 22:33:06 -0500143 pr_debug(PREFIX "---> status = 0x%2.2x\n", x);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300144 return x;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400147static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400148{
Márton Németh3ebe08a2007-11-21 03:23:26 +0300149 u8 x = inb(ec->data_addr);
Márton Németh86dae012008-01-23 22:33:06 -0500150 pr_debug(PREFIX "---> data = 0x%2.2x\n", x);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400151 return inb(ec->data_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400152}
153
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400154static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400155{
Márton Németh86dae012008-01-23 22:33:06 -0500156 pr_debug(PREFIX "<--- command = 0x%2.2x\n", command);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400157 outb(command, ec->command_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400158}
159
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400160static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400161{
Márton Németh86dae012008-01-23 22:33:06 -0500162 pr_debug(PREFIX "<--- data = 0x%2.2x\n", data);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400163 outb(data, ec->data_addr);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400164}
165
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400166static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400167{
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400168 if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500169 return 0;
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300170 if (event == ACPI_EC_EVENT_OBF_1) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400171 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400172 return 1;
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300173 } else if (event == ACPI_EC_EVENT_IBF_0) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400174 if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400175 return 1;
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400176 }
177
178 return 0;
179}
180
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400181static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
Luming Yu45bea152005-07-23 04:08:00 -0400182{
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300183 int ret = 0;
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -0500184
185 if (unlikely(event == ACPI_EC_EVENT_OBF_1 &&
186 test_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags)))
187 force_poll = 1;
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300188 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
189 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
190 force_poll = 1;
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300191 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) &&
192 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags)))
193 force_poll = 1;
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400194 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
195 likely(!force_poll)) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400196 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
197 msecs_to_jiffies(ACPI_EC_DELAY)))
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300198 goto end;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400199 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
200 if (acpi_ec_check_status(ec, event)) {
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -0500201 if (event == ACPI_EC_EVENT_OBF_1) {
202 /* miss OBF_1 GPE, don't expect it */
203 pr_info(PREFIX "missing OBF confirmation, "
204 "don't expect it any longer.\n");
205 set_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags);
206 } else if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300207 /* miss address GPE, don't expect it anymore */
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300208 pr_info(PREFIX "missing address confirmation, "
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300209 "don't expect it any longer.\n");
210 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300211 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
212 /* miss write data GPE, don't expect it */
213 pr_info(PREFIX "missing write data confirmation, "
214 "don't expect it any longer.\n");
215 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400216 } else {
Alexey Starikovskiy66c5f4e2007-10-22 14:18:56 +0400217 /* missing GPEs, switch back to poll mode */
Márton Németh3ebe08a2007-11-21 03:23:26 +0300218 if (printk_ratelimit())
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300219 pr_info(PREFIX "missing confirmations, "
Márton Németh3ebe08a2007-11-21 03:23:26 +0300220 "switch off interrupt mode.\n");
Alexey Starikovskiy66c5f4e2007-10-22 14:18:56 +0400221 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400222 }
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300223 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400224 }
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400225 } else {
226 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
227 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
228 while (time_before(jiffies, delay)) {
229 if (acpi_ec_check_status(ec, event))
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300230 goto end;
Alexey Starikovskiye6e82a32008-03-21 17:06:57 +0300231 udelay(ACPI_EC_UDELAY);
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400232 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300233 }
Márton Németh3ebe08a2007-11-21 03:23:26 +0300234 pr_err(PREFIX "acpi_ec_wait timeout,"
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400235 " status = %d, expect_event = %d\n",
236 acpi_ec_read_status(ec), event);
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300237 ret = -ETIME;
238 end:
239 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
240 return ret;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500241}
242
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400243static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300244 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200245 u8 * rdata, unsigned rdata_len,
246 int force_poll)
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400247{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300248 int result = 0;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400249 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400250 acpi_ec_write_cmd(ec, command);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300251 pr_debug(PREFIX "transaction start\n");
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300252 for (; wdata_len > 0; --wdata_len) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400253 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300254 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300255 pr_err(PREFIX
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300256 "write_cmd timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300257 goto end;
258 }
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300259 /* mark the address byte written to EC */
260 if (rdata_len + wdata_len > 1)
261 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400262 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400263 acpi_ec_write_data(ec, *(wdata++));
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400264 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400265
Alexey Starikovskiyd91df1a2006-12-07 18:42:16 +0300266 if (!rdata_len) {
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300267 set_bit(EC_FLAGS_WDATA, &ec->flags);
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400268 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300269 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300270 pr_err(PREFIX
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300271 "finish-write timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300272 goto end;
273 }
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400274 } else if (command == ACPI_EC_COMMAND_QUERY)
275 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400276
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300277 for (; rdata_len > 0; --rdata_len) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400278 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300279 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300280 pr_err(PREFIX "read timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300281 goto end;
282 }
Alexey Starikovskiy0c5d31f2007-10-22 14:18:36 +0400283 /* Don't expect GPE after last read */
284 if (rdata_len > 1)
285 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400286 *(rdata++) = acpi_ec_read_data(ec);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400287 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300288 end:
Márton Németh3ebe08a2007-11-21 03:23:26 +0300289 pr_debug(PREFIX "transaction end\n");
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300290 return result;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400291}
292
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400293static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300294 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200295 u8 * rdata, unsigned rdata_len,
296 int force_poll)
Luming Yu45bea152005-07-23 04:08:00 -0400297{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400298 int status;
Len Brown50526df2005-08-11 17:32:05 -0400299 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400301 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
Patrick Mocheld550d982006-06-27 00:41:40 -0400302 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300304 if (rdata)
305 memset(rdata, 0, rdata_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300307 mutex_lock(&ec->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400308 if (ec->global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300310 if (ACPI_FAILURE(status)) {
311 mutex_unlock(&ec->lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400312 return -ENODEV;
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500315
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400316 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
Luming Yu716e0842005-08-10 01:40:00 -0400317 if (status) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300318 pr_err(PREFIX "input buffer is not empty, "
319 "aborting transaction\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500320 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300323 status = acpi_ec_transaction_unlocked(ec, command,
324 wdata, wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200325 rdata, rdata_len,
326 force_poll);
Len Brown50526df2005-08-11 17:32:05 -0400327
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300328 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400330 if (ec->global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 acpi_release_global_lock(glk);
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300332 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Patrick Mocheld550d982006-06-27 00:41:40 -0400334 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300337/*
338 * Note: samsung nv5000 doesn't work with ec burst mode.
339 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
340 */
341int acpi_ec_burst_enable(struct acpi_ec *ec)
342{
343 u8 d;
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200344 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300345}
346
347int acpi_ec_burst_disable(struct acpi_ec *ec)
348{
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200349 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300350}
351
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300352static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400353{
354 int result;
355 u8 d;
356
357 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200358 &address, 1, &d, 1, 0);
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400359 *data = d;
360 return result;
361}
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400362
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400363static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
364{
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300365 u8 wdata[2] = { address, data };
366 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200367 wdata, 2, NULL, 0, 0);
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/*
371 * Externally callable EC access functions. For now, assume 1 EC only
372 */
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300373int ec_burst_enable(void)
374{
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300375 if (!first_ec)
376 return -ENODEV;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300377 return acpi_ec_burst_enable(first_ec);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300378}
379
380EXPORT_SYMBOL(ec_burst_enable);
381
382int ec_burst_disable(void)
383{
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300384 if (!first_ec)
385 return -ENODEV;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300386 return acpi_ec_burst_disable(first_ec);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300387}
388
389EXPORT_SYMBOL(ec_burst_disable);
390
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300391int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 int err;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400394 u8 temp_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 if (!first_ec)
397 return -ENODEV;
398
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300399 err = acpi_ec_read(first_ec, addr, &temp_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 if (!err) {
402 *val = temp_data;
403 return 0;
Len Brown50526df2005-08-11 17:32:05 -0400404 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return err;
406}
Len Brown50526df2005-08-11 17:32:05 -0400407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408EXPORT_SYMBOL(ec_read);
409
Len Brown50526df2005-08-11 17:32:05 -0400410int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 int err;
413
414 if (!first_ec)
415 return -ENODEV;
416
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300417 err = acpi_ec_write(first_ec, addr, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 return err;
420}
Len Brown50526df2005-08-11 17:32:05 -0400421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422EXPORT_SYMBOL(ec_write);
423
Randy Dunlap616362d2006-10-27 01:47:34 -0400424int ec_transaction(u8 command,
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500425 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200426 u8 * rdata, unsigned rdata_len,
427 int force_poll)
Luming Yu45bea152005-07-23 04:08:00 -0400428{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400429 if (!first_ec)
430 return -ENODEV;
431
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300432 return acpi_ec_transaction(first_ec, command, wdata,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200433 wdata_len, rdata, rdata_len,
434 force_poll);
Luming Yu45bea152005-07-23 04:08:00 -0400435}
Luming Yu45bea152005-07-23 04:08:00 -0400436
Lennart Poetteringab9e43c2006-10-03 22:49:00 -0400437EXPORT_SYMBOL(ec_transaction);
438
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300439static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400440{
441 int result;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300442 u8 d;
Luming Yu45bea152005-07-23 04:08:00 -0400443
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300444 if (!ec || !data)
445 return -EINVAL;
Luming Yu45bea152005-07-23 04:08:00 -0400446
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300447 /*
448 * Query the EC to find out which _Qxx method we need to evaluate.
449 * Note that successful completion of the query causes the ACPI_EC_SCI
450 * bit to be cleared (and thus clearing the interrupt source).
451 */
Luming Yu45bea152005-07-23 04:08:00 -0400452
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200453 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300454 if (result)
455 return result;
Luming Yu45bea152005-07-23 04:08:00 -0400456
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300457 if (!d)
458 return -ENODATA;
Luming Yu45bea152005-07-23 04:08:00 -0400459
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300460 *data = d;
461 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/* --------------------------------------------------------------------------
465 Event Management
466 -------------------------------------------------------------------------- */
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400467int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
468 acpi_handle handle, acpi_ec_query_func func,
469 void *data)
470{
471 struct acpi_ec_query_handler *handler =
472 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
473 if (!handler)
474 return -ENOMEM;
475
476 handler->query_bit = query_bit;
477 handler->handle = handle;
478 handler->func = func;
479 handler->data = data;
480 mutex_lock(&ec->lock);
Alexey Starikovskiy30c08572007-09-26 19:43:22 +0400481 list_add(&handler->node, &ec->list);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400482 mutex_unlock(&ec->lock);
483 return 0;
484}
485
486EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
487
488void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
489{
Adrian Bunk1544fdb2007-10-24 18:26:00 +0200490 struct acpi_ec_query_handler *handler, *tmp;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400491 mutex_lock(&ec->lock);
Adrian Bunk1544fdb2007-10-24 18:26:00 +0200492 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400493 if (query_bit == handler->query_bit) {
494 list_del(&handler->node);
495 kfree(handler);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400496 }
497 }
498 mutex_unlock(&ec->lock);
499}
500
501EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Len Brown50526df2005-08-11 17:32:05 -0400503static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300505 struct acpi_ec *ec = ec_cxt;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400506 u8 value = 0;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400507 struct acpi_ec_query_handler *handler, copy;
Luming Yu45bea152005-07-23 04:08:00 -0400508
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300509 if (!ec || acpi_ec_query(ec, &value))
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300510 return;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400511 mutex_lock(&ec->lock);
512 list_for_each_entry(handler, &ec->list, node) {
513 if (value == handler->query_bit) {
514 /* have custom handler for this bit */
515 memcpy(&copy, handler, sizeof(copy));
516 mutex_unlock(&ec->lock);
517 if (copy.func) {
518 copy.func(copy.data);
519 } else if (copy.handle) {
520 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
521 }
522 return;
523 }
524 }
525 mutex_unlock(&ec->lock);
Luming Yu45bea152005-07-23 04:08:00 -0400526}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Len Brown50526df2005-08-11 17:32:05 -0400528static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Len Brown50526df2005-08-11 17:32:05 -0400530 acpi_status status = AE_OK;
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300531 struct acpi_ec *ec = data;
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200532
Márton Németh3ebe08a2007-11-21 03:23:26 +0300533 pr_debug(PREFIX "~~~> interrupt\n");
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400534 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400535 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300536 wake_up(&ec->wait);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500537
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400538 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) {
539 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
540 status = acpi_os_execute(OSL_EC_BURST_HANDLER,
541 acpi_ec_gpe_query, ec);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400542 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
543 /* this is non-query, must be confirmation */
Márton Németh3ebe08a2007-11-21 03:23:26 +0300544 if (printk_ratelimit())
545 pr_info(PREFIX "non-query interrupt received,"
546 " switching to interrupt mode\n");
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400547 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400548 }
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300549
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400550 return ACPI_SUCCESS(status) ?
Len Brown50526df2005-08-11 17:32:05 -0400551 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
554/* --------------------------------------------------------------------------
555 Address Space Management
556 -------------------------------------------------------------------------- */
557
558static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400559acpi_ec_space_setup(acpi_handle region_handle,
560 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 /*
563 * The EC object is in the handler context and is needed
564 * when calling the acpi_ec_space_handler.
565 */
Len Brown50526df2005-08-11 17:32:05 -0400566 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
567 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 return AE_OK;
570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572static acpi_status
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400573acpi_ec_space_handler(u32 function, acpi_physical_address address,
574 u32 bits, acpi_integer *value,
Len Brown50526df2005-08-11 17:32:05 -0400575 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300577 struct acpi_ec *ec = handler_context;
Alexey Starikovskiy3e71a872008-01-11 02:42:51 +0300578 int result = 0, i;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400579 u8 temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if ((address > 0xFF) || !value || !handler_context)
Patrick Mocheld550d982006-06-27 00:41:40 -0400582 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400584 if (function != ACPI_READ && function != ACPI_WRITE)
Patrick Mocheld550d982006-06-27 00:41:40 -0400585 return AE_BAD_PARAMETER;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400586
587 if (bits != 8 && acpi_strict)
588 return AE_BAD_PARAMETER;
589
Alexey Starikovskiyb3b233c2008-01-11 02:42:57 +0300590 acpi_ec_burst_enable(ec);
591
Alexey Starikovskiy3e71a872008-01-11 02:42:51 +0300592 if (function == ACPI_READ) {
593 result = acpi_ec_read(ec, address, &temp);
594 *value = temp;
595 } else {
596 temp = 0xff & (*value);
597 result = acpi_ec_write(ec, address, temp);
598 }
599
600 for (i = 8; unlikely(bits - i > 0); i += 8) {
601 ++address;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400602 if (function == ACPI_READ) {
603 result = acpi_ec_read(ec, address, &temp);
604 (*value) |= ((acpi_integer)temp) << i;
605 } else {
606 temp = 0xff & ((*value) >> i);
607 result = acpi_ec_write(ec, address, temp);
608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610
Alexey Starikovskiyb3b233c2008-01-11 02:42:57 +0300611 acpi_ec_burst_disable(ec);
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 switch (result) {
614 case -EINVAL:
Patrick Mocheld550d982006-06-27 00:41:40 -0400615 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 break;
617 case -ENODEV:
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return AE_NOT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 break;
620 case -ETIME:
Patrick Mocheld550d982006-06-27 00:41:40 -0400621 return AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
623 default:
Patrick Mocheld550d982006-06-27 00:41:40 -0400624 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628/* --------------------------------------------------------------------------
629 FS Interface (/proc)
630 -------------------------------------------------------------------------- */
631
Len Brown50526df2005-08-11 17:32:05 -0400632static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Len Brown50526df2005-08-11 17:32:05 -0400634static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300636 struct acpi_ec *ec = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 if (!ec)
639 goto end;
640
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300641 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
642 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
643 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
644 seq_printf(seq, "use global lock:\t%s\n",
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400645 ec->global_lock ? "yes" : "no");
Len Brown50526df2005-08-11 17:32:05 -0400646 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400647 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
651{
652 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
653}
654
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400655static struct file_operations acpi_ec_info_ops = {
Len Brown50526df2005-08-11 17:32:05 -0400656 .open = acpi_ec_info_open_fs,
657 .read = seq_read,
658 .llseek = seq_lseek,
659 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .owner = THIS_MODULE,
661};
662
Len Brown50526df2005-08-11 17:32:05 -0400663static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Len Brown50526df2005-08-11 17:32:05 -0400665 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (!acpi_device_dir(device)) {
668 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown50526df2005-08-11 17:32:05 -0400669 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400671 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 }
673
674 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown50526df2005-08-11 17:32:05 -0400675 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400677 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 else {
679 entry->proc_fops = &acpi_ec_info_ops;
680 entry->data = acpi_driver_data(device);
681 entry->owner = THIS_MODULE;
682 }
683
Patrick Mocheld550d982006-06-27 00:41:40 -0400684 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
Len Brown50526df2005-08-11 17:32:05 -0400687static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 if (acpi_device_dir(device)) {
691 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
692 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
693 acpi_device_dir(device) = NULL;
694 }
695
Patrick Mocheld550d982006-06-27 00:41:40 -0400696 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699/* --------------------------------------------------------------------------
700 Driver Interface
701 -------------------------------------------------------------------------- */
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300702static acpi_status
703ec_parse_io_ports(struct acpi_resource *resource, void *context);
704
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300705static struct acpi_ec *make_acpi_ec(void)
706{
707 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
708 if (!ec)
709 return NULL;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400710 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300711 mutex_init(&ec->lock);
712 init_waitqueue_head(&ec->wait);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400713 INIT_LIST_HEAD(&ec->list);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300714 return ec;
715}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400717static acpi_status
Alexey Starikovskiyc019b192007-08-14 01:03:42 -0400718acpi_ec_register_query_methods(acpi_handle handle, u32 level,
719 void *context, void **return_value)
720{
721 struct acpi_namespace_node *node = handle;
722 struct acpi_ec *ec = context;
723 int value = 0;
724 if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
725 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
726 }
727 return AE_OK;
728}
729
730static acpi_status
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400731ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400732{
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400733 acpi_status status;
734
735 struct acpi_ec *ec = context;
736 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
737 ec_parse_io_ports, ec);
738 if (ACPI_FAILURE(status))
739 return status;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400740
741 /* Get GPE bit assignment (EC events). */
742 /* TODO: Add support for _GPE returning a package */
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400743 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
744 if (ACPI_FAILURE(status))
745 return status;
Alexey Starikovskiyc019b192007-08-14 01:03:42 -0400746 /* Find and register all query methods */
747 acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
748 acpi_ec_register_query_methods, ec, NULL);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400749 /* Use the global lock for all EC transactions? */
750 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400751 ec->handle = handle;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400752 return AE_CTRL_TERMINATE;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400753}
754
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400755static void ec_remove_handlers(struct acpi_ec *ec)
756{
757 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
758 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
Márton Németh3ebe08a2007-11-21 03:23:26 +0300759 pr_err(PREFIX "failed to remove space handler\n");
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400760 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
761 &acpi_ec_gpe_handler)))
Márton Németh3ebe08a2007-11-21 03:23:26 +0300762 pr_err(PREFIX "failed to remove gpe handler\n");
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400763 ec->handlers_installed = 0;
764}
765
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400766static int acpi_ec_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400768 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400771 return -EINVAL;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300772 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
773 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
774
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400775 /* Check for boot EC */
776 if (boot_ec) {
777 if (boot_ec->handle == device->handle) {
778 /* Pre-loaded EC from DSDT, just move pointer */
779 ec = boot_ec;
780 boot_ec = NULL;
781 goto end;
782 } else if (boot_ec->handle == ACPI_ROOT_OBJECT) {
783 /* ECDT-based EC, time to shut it down */
784 ec_remove_handlers(boot_ec);
785 kfree(boot_ec);
786 first_ec = boot_ec = NULL;
787 }
788 }
789
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300790 ec = make_acpi_ec();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400792 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400794 if (ec_parse_device(device->handle, 0, ec, NULL) !=
795 AE_CTRL_TERMINATE) {
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300796 kfree(ec);
797 return -EINVAL;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400798 }
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300799 ec->handle = device->handle;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400800 end:
801 if (!first_ec)
802 first_ec = ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 acpi_driver_data(device) = ec;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300804 acpi_ec_add_fs(device);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300805 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400806 ec->gpe, ec->command_addr, ec->data_addr);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300807 pr_info(PREFIX "driver started in %s mode\n",
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400808 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300809 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Len Brown50526df2005-08-11 17:32:05 -0400812static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300814 struct acpi_ec *ec;
Adrian Bunk07ddf762007-07-29 17:00:37 +0200815 struct acpi_ec_query_handler *handler, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400818 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 ec = acpi_driver_data(device);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400821 mutex_lock(&ec->lock);
Adrian Bunk07ddf762007-07-29 17:00:37 +0200822 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400823 list_del(&handler->node);
824 kfree(handler);
825 }
826 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 acpi_ec_remove_fs(device);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300828 acpi_driver_data(device) = NULL;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300829 if (ec == first_ec)
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300830 first_ec = NULL;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400831 kfree(ec);
Patrick Mocheld550d982006-06-27 00:41:40 -0400832 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835static acpi_status
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300836ec_parse_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300838 struct acpi_ec *ec = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300840 if (resource->type != ACPI_RESOURCE_TYPE_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 /*
844 * The first address region returned is the data port, and
845 * the second address region returned is the status/command
846 * port.
847 */
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300848 if (ec->data_addr == 0)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400849 ec->data_addr = resource->data.io.minimum;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300850 else if (ec->command_addr == 0)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400851 ec->command_addr = resource->data.io.minimum;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300852 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return AE_OK;
856}
857
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300858static int ec_install_handlers(struct acpi_ec *ec)
859{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300860 acpi_status status;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400861 if (ec->handlers_installed)
862 return 0;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300863 status = acpi_install_gpe_handler(NULL, ec->gpe,
864 ACPI_GPE_EDGE_TRIGGERED,
865 &acpi_ec_gpe_handler, ec);
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300866 if (ACPI_FAILURE(status))
867 return -ENODEV;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300868
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300869 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
870 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
871
872 status = acpi_install_address_space_handler(ec->handle,
873 ACPI_ADR_SPACE_EC,
874 &acpi_ec_space_handler,
875 &acpi_ec_space_setup, ec);
876 if (ACPI_FAILURE(status)) {
877 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
878 return -ENODEV;
879 }
880
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400881 ec->handlers_installed = 1;
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300882 return 0;
883}
884
Len Brown50526df2005-08-11 17:32:05 -0400885static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300887 struct acpi_ec *ec;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400888 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400891 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 ec = acpi_driver_data(device);
894
895 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400896 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400898 ret = ec_install_handlers(ec);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300899
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400900 /* EC is fully operational, allow queries */
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400901 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400902 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903}
904
Len Brown50526df2005-08-11 17:32:05 -0400905static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300907 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400909 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 ec = acpi_driver_data(device);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300911 if (!ec)
912 return -EINVAL;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400913 ec_remove_handlers(ec);
Alexey Starikovskiyf9319f92007-08-24 08:10:11 +0400914
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
917
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500918int __init acpi_boot_ec_enable(void)
919{
920 if (!boot_ec || boot_ec->handlers_installed)
921 return 0;
922 if (!ec_install_handlers(boot_ec)) {
923 first_ec = boot_ec;
924 return 0;
925 }
926 return -EFAULT;
927}
928
Len Brown50526df2005-08-11 17:32:05 -0400929int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
Len Brown50526df2005-08-11 17:32:05 -0400931 int ret;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300932 acpi_status status;
933 struct acpi_table_ecdt *ecdt_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300935 boot_ec = make_acpi_ec();
936 if (!boot_ec)
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300937 return -ENOMEM;
938 /*
939 * Generate a boot ec context
940 */
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300941 status = acpi_get_table(ACPI_SIG_ECDT, 1,
942 (struct acpi_table_header **)&ecdt_ptr);
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400943 if (ACPI_SUCCESS(status)) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300944 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400945 boot_ec->command_addr = ecdt_ptr->control.address;
946 boot_ec->data_addr = ecdt_ptr->data.address;
947 boot_ec->gpe = ecdt_ptr->gpe;
Len Brown4af8e102008-03-11 00:27:16 -0400948 boot_ec->handle = ACPI_ROOT_OBJECT;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400949 } else {
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300950 /* This workaround is needed only on some broken machines,
951 * which require early EC, but fail to provide ECDT */
952 acpi_handle x;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400953 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
954 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
955 boot_ec, NULL);
Alexey Starikovskiy2d8348b2007-08-31 09:05:26 +0400956 /* Check that acpi_get_devices actually find something */
957 if (ACPI_FAILURE(status) || !boot_ec->handle)
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400958 goto error;
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300959 /* We really need to limit this workaround, the only ASUS,
960 * which needs it, has fake EC._INI method, so use it as flag.
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500961 * Keep boot_ec struct as it will be needed soon.
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300962 */
963 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500964 return -ENODEV;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300967 ret = ec_install_handlers(boot_ec);
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300968 if (!ret) {
969 first_ec = boot_ec;
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300970 return 0;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300971 }
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300972 error:
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300973 kfree(boot_ec);
974 boot_ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 return -ENODEV;
976}
977
Len Brown50526df2005-08-11 17:32:05 -0400978static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
Len Brown50526df2005-08-11 17:32:05 -0400980 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400983 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
986 if (!acpi_ec_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -0400987 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 /* Now register the driver for the EC */
990 result = acpi_bus_register_driver(&acpi_ec_driver);
991 if (result < 0) {
992 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995
Patrick Mocheld550d982006-06-27 00:41:40 -0400996 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
999subsys_initcall(acpi_ec_init);
1000
1001/* EC driver currently not unloadable */
1002#if 0
Len Brown50526df2005-08-11 17:32:05 -04001003static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 acpi_bus_unregister_driver(&acpi_ec_driver);
1007
1008 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1009
Patrick Mocheld550d982006-06-27 00:41:40 -04001010 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
Alexey Starikovskiy78439322007-10-22 14:18:43 +04001012#endif /* 0 */