blob: 2c77359dbdc968a242044562ea8e411527bb4ec5 [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 */
Denis M. Sadykov703959d2006-09-26 19:50:33 +040076
Alexey Starikovskiy080e4122007-10-22 14:18:30 +040077enum {
78 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
79 EC_FLAGS_QUERY_PENDING, /* Query is pending */
Alexey Starikovskiy78439322007-10-22 14:18:43 +040080 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +030081 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
82 EC_FLAGS_ADDRESS, /* Address is being written */
Alexey Starikovskiye790cc82007-11-21 03:23:32 +030083 EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */
84 EC_FLAGS_WDATA, /* Data is being written */
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -050085 EC_FLAGS_NO_OBF1_GPE, /* Don't expect GPE before read */
Alexey Starikovskiy080e4122007-10-22 14:18:30 +040086};
87
Len Brown50526df2005-08-11 17:32:05 -040088static int acpi_ec_remove(struct acpi_device *device, int type);
89static int acpi_ec_start(struct acpi_device *device);
90static int acpi_ec_stop(struct acpi_device *device, int type);
Denis M. Sadykov703959d2006-09-26 19:50:33 +040091static int acpi_ec_add(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Thomas Renninger1ba90e32007-07-23 14:44:41 +020093static const struct acpi_device_id ec_device_ids[] = {
94 {"PNP0C09", 0},
95 {"", 0},
96};
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static struct acpi_driver acpi_ec_driver = {
Len Brownc2b6705b2007-02-12 23:33:40 -050099 .name = "ec",
Len Brown50526df2005-08-11 17:32:05 -0400100 .class = ACPI_EC_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200101 .ids = ec_device_ids,
Len Brown50526df2005-08-11 17:32:05 -0400102 .ops = {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400103 .add = acpi_ec_add,
Len Brown50526df2005-08-11 17:32:05 -0400104 .remove = acpi_ec_remove,
105 .start = acpi_ec_start,
106 .stop = acpi_ec_stop,
107 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400109
110/* If we find an EC via the ECDT, we need to keep a ptr to its context */
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300111/* External interfaces use first EC only, so remember */
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400112typedef int (*acpi_ec_query_func) (void *data);
113
114struct acpi_ec_query_handler {
115 struct list_head node;
116 acpi_ec_query_func func;
117 acpi_handle handle;
118 void *data;
119 u8 query_bit;
120};
121
Adrian Bunka854e082006-12-19 12:56:12 -0800122static struct acpi_ec {
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400123 acpi_handle handle;
Alexey Starikovskiya86e2772006-12-07 18:42:16 +0300124 unsigned long gpe;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400125 unsigned long command_addr;
126 unsigned long data_addr;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400127 unsigned long global_lock;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400128 unsigned long flags;
Alexey Starikovskiyc787a852006-12-07 18:42:16 +0300129 struct mutex lock;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400130 wait_queue_head_t wait;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400131 struct list_head list;
Alexey Starikovskiy2c81ce42008-03-11 13:30:00 -0400132 atomic_t irq_count;
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
Alexey Starikovskiy2c81ce42008-03-11 13:30:00 -0400185 atomic_set(&ec->irq_count, 0);
186
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -0500187 if (unlikely(event == ACPI_EC_EVENT_OBF_1 &&
188 test_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags)))
189 force_poll = 1;
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300190 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
191 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
192 force_poll = 1;
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300193 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) &&
194 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags)))
195 force_poll = 1;
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400196 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
197 likely(!force_poll)) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400198 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
199 msecs_to_jiffies(ACPI_EC_DELAY)))
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300200 goto end;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400201 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
202 if (acpi_ec_check_status(ec, event)) {
Alexey Starikovskiy03d1d992008-01-23 22:28:34 -0500203 if (event == ACPI_EC_EVENT_OBF_1) {
204 /* miss OBF_1 GPE, don't expect it */
205 pr_info(PREFIX "missing OBF confirmation, "
206 "don't expect it any longer.\n");
207 set_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags);
208 } else if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300209 /* miss address GPE, don't expect it anymore */
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300210 pr_info(PREFIX "missing address confirmation, "
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300211 "don't expect it any longer.\n");
212 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300213 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
214 /* miss write data GPE, don't expect it */
215 pr_info(PREFIX "missing write data confirmation, "
216 "don't expect it any longer.\n");
217 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400218 } else {
Alexey Starikovskiy66c5f4e2007-10-22 14:18:56 +0400219 /* missing GPEs, switch back to poll mode */
Márton Németh3ebe08a2007-11-21 03:23:26 +0300220 if (printk_ratelimit())
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300221 pr_info(PREFIX "missing confirmations, "
Márton Németh3ebe08a2007-11-21 03:23:26 +0300222 "switch off interrupt mode.\n");
Alexey Starikovskiy66c5f4e2007-10-22 14:18:56 +0400223 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400224 }
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300225 goto end;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400226 }
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400227 } else {
228 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
229 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
230 while (time_before(jiffies, delay)) {
231 if (acpi_ec_check_status(ec, event))
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300232 goto end;
Alexey Starikovskiy2c81ce42008-03-11 13:30:00 -0400233 msleep(5);
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400234 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300235 }
Márton Németh3ebe08a2007-11-21 03:23:26 +0300236 pr_err(PREFIX "acpi_ec_wait timeout,"
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400237 " status = %d, expect_event = %d\n",
238 acpi_ec_read_status(ec), event);
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300239 ret = -ETIME;
240 end:
241 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
242 return ret;
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500243}
244
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400245static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300246 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200247 u8 * rdata, unsigned rdata_len,
248 int force_poll)
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400249{
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300250 int result = 0;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400251 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400252 acpi_ec_write_cmd(ec, command);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300253 pr_debug(PREFIX "transaction start\n");
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300254 for (; wdata_len > 0; --wdata_len) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400255 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300256 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300257 pr_err(PREFIX
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300258 "write_cmd timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300259 goto end;
260 }
Alexey Starikovskiyf2d68932007-11-19 01:37:03 +0300261 /* mark the address byte written to EC */
262 if (rdata_len + wdata_len > 1)
263 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400264 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400265 acpi_ec_write_data(ec, *(wdata++));
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400266 }
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400267
Alexey Starikovskiyd91df1a2006-12-07 18:42:16 +0300268 if (!rdata_len) {
Alexey Starikovskiye790cc82007-11-21 03:23:32 +0300269 set_bit(EC_FLAGS_WDATA, &ec->flags);
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400270 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300271 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300272 pr_err(PREFIX
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300273 "finish-write timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300274 goto end;
275 }
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400276 } else if (command == ACPI_EC_COMMAND_QUERY)
277 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400278
Alexey Starikovskiy78d0af32006-12-07 18:42:17 +0300279 for (; rdata_len > 0; --rdata_len) {
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400280 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300281 if (result) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300282 pr_err(PREFIX "read timeout, command = %d\n", command);
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300283 goto end;
284 }
Alexey Starikovskiy0c5d31f2007-10-22 14:18:36 +0400285 /* Don't expect GPE after last read */
286 if (rdata_len > 1)
287 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400288 *(rdata++) = acpi_ec_read_data(ec);
Denis M. Sadykov7c6db5e2006-09-26 19:50:33 +0400289 }
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300290 end:
Márton Németh3ebe08a2007-11-21 03:23:26 +0300291 pr_debug(PREFIX "transaction end\n");
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300292 return result;
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400293}
294
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400295static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300296 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200297 u8 * rdata, unsigned rdata_len,
298 int force_poll)
Luming Yu45bea152005-07-23 04:08:00 -0400299{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400300 int status;
Len Brown50526df2005-08-11 17:32:05 -0400301 u32 glk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400303 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
Patrick Mocheld550d982006-06-27 00:41:40 -0400304 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300306 if (rdata)
307 memset(rdata, 0, rdata_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300309 mutex_lock(&ec->lock);
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400310 if (ec->global_lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300312 if (ACPI_FAILURE(status)) {
313 mutex_unlock(&ec->lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400314 return -ENODEV;
Alexey Starikovskiyc24e9122007-02-15 23:16:18 +0300315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 }
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500317
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400318 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
Luming Yu716e0842005-08-10 01:40:00 -0400319 if (status) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300320 pr_err(PREFIX "input buffer is not empty, "
321 "aborting transaction\n");
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500322 goto end;
Luming Yu716e0842005-08-10 01:40:00 -0400323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300325 status = acpi_ec_transaction_unlocked(ec, command,
326 wdata, wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200327 rdata, rdata_len,
328 force_poll);
Len Brown50526df2005-08-11 17:32:05 -0400329
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300330 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400332 if (ec->global_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 acpi_release_global_lock(glk);
Alexey Starikovskiy523953b2006-12-07 18:42:17 +0300334 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Patrick Mocheld550d982006-06-27 00:41:40 -0400336 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300339/*
340 * Note: samsung nv5000 doesn't work with ec burst mode.
341 * http://bugzilla.kernel.org/show_bug.cgi?id=4980
342 */
343int acpi_ec_burst_enable(struct acpi_ec *ec)
344{
345 u8 d;
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200346 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300347}
348
349int acpi_ec_burst_disable(struct acpi_ec *ec)
350{
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200351 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300352}
353
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300354static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400355{
356 int result;
357 u8 d;
358
359 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200360 &address, 1, &d, 1, 0);
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400361 *data = d;
362 return result;
363}
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400364
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400365static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
366{
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300367 u8 wdata[2] = { address, data };
368 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200369 wdata, 2, NULL, 0, 0);
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372/*
373 * Externally callable EC access functions. For now, assume 1 EC only
374 */
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300375int ec_burst_enable(void)
376{
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300377 if (!first_ec)
378 return -ENODEV;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300379 return acpi_ec_burst_enable(first_ec);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300380}
381
382EXPORT_SYMBOL(ec_burst_enable);
383
384int ec_burst_disable(void)
385{
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300386 if (!first_ec)
387 return -ENODEV;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300388 return acpi_ec_burst_disable(first_ec);
Alexey Starikovskiyc45aac42007-03-07 22:28:00 +0300389}
390
391EXPORT_SYMBOL(ec_burst_disable);
392
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300393int ec_read(u8 addr, u8 * val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 int err;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400396 u8 temp_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (!first_ec)
399 return -ENODEV;
400
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300401 err = acpi_ec_read(first_ec, addr, &temp_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 if (!err) {
404 *val = temp_data;
405 return 0;
Len Brown50526df2005-08-11 17:32:05 -0400406 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return err;
408}
Len Brown50526df2005-08-11 17:32:05 -0400409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410EXPORT_SYMBOL(ec_read);
411
Len Brown50526df2005-08-11 17:32:05 -0400412int ec_write(u8 addr, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 int err;
415
416 if (!first_ec)
417 return -ENODEV;
418
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300419 err = acpi_ec_write(first_ec, addr, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 return err;
422}
Len Brown50526df2005-08-11 17:32:05 -0400423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424EXPORT_SYMBOL(ec_write);
425
Randy Dunlap616362d2006-10-27 01:47:34 -0400426int ec_transaction(u8 command,
Alexey Starikovskiy9e197212007-03-07 18:29:35 -0500427 const u8 * wdata, unsigned wdata_len,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200428 u8 * rdata, unsigned rdata_len,
429 int force_poll)
Luming Yu45bea152005-07-23 04:08:00 -0400430{
Lennart Poetteringd7a76e42006-09-05 12:12:24 -0400431 if (!first_ec)
432 return -ENODEV;
433
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300434 return acpi_ec_transaction(first_ec, command, wdata,
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200435 wdata_len, rdata, rdata_len,
436 force_poll);
Luming Yu45bea152005-07-23 04:08:00 -0400437}
Luming Yu45bea152005-07-23 04:08:00 -0400438
Lennart Poetteringab9e43c2006-10-03 22:49:00 -0400439EXPORT_SYMBOL(ec_transaction);
440
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300441static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
Denis M. Sadykov3576cf62006-09-26 19:50:33 +0400442{
443 int result;
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300444 u8 d;
Luming Yu45bea152005-07-23 04:08:00 -0400445
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300446 if (!ec || !data)
447 return -EINVAL;
Luming Yu45bea152005-07-23 04:08:00 -0400448
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300449 /*
450 * Query the EC to find out which _Qxx method we need to evaluate.
451 * Note that successful completion of the query causes the ACPI_EC_SCI
452 * bit to be cleared (and thus clearing the interrupt source).
453 */
Luming Yu45bea152005-07-23 04:08:00 -0400454
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200455 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300456 if (result)
457 return result;
Luming Yu45bea152005-07-23 04:08:00 -0400458
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300459 if (!d)
460 return -ENODATA;
Luming Yu45bea152005-07-23 04:08:00 -0400461
Alexey Starikovskiy6ccedb12006-12-07 18:42:17 +0300462 *data = d;
463 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/* --------------------------------------------------------------------------
467 Event Management
468 -------------------------------------------------------------------------- */
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400469int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
470 acpi_handle handle, acpi_ec_query_func func,
471 void *data)
472{
473 struct acpi_ec_query_handler *handler =
474 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
475 if (!handler)
476 return -ENOMEM;
477
478 handler->query_bit = query_bit;
479 handler->handle = handle;
480 handler->func = func;
481 handler->data = data;
482 mutex_lock(&ec->lock);
Alexey Starikovskiy30c08572007-09-26 19:43:22 +0400483 list_add(&handler->node, &ec->list);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400484 mutex_unlock(&ec->lock);
485 return 0;
486}
487
488EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
489
490void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
491{
Adrian Bunk1544fdb2007-10-24 18:26:00 +0200492 struct acpi_ec_query_handler *handler, *tmp;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400493 mutex_lock(&ec->lock);
Adrian Bunk1544fdb2007-10-24 18:26:00 +0200494 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400495 if (query_bit == handler->query_bit) {
496 list_del(&handler->node);
497 kfree(handler);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400498 }
499 }
500 mutex_unlock(&ec->lock);
501}
502
503EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Len Brown50526df2005-08-11 17:32:05 -0400505static void acpi_ec_gpe_query(void *ec_cxt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300507 struct acpi_ec *ec = ec_cxt;
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400508 u8 value = 0;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400509 struct acpi_ec_query_handler *handler, copy;
Luming Yu45bea152005-07-23 04:08:00 -0400510
Alexey Starikovskiy5d0c2882006-12-07 18:42:16 +0300511 if (!ec || acpi_ec_query(ec, &value))
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300512 return;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400513 mutex_lock(&ec->lock);
514 list_for_each_entry(handler, &ec->list, node) {
515 if (value == handler->query_bit) {
516 /* have custom handler for this bit */
517 memcpy(&copy, handler, sizeof(copy));
518 mutex_unlock(&ec->lock);
519 if (copy.func) {
520 copy.func(copy.data);
521 } else if (copy.handle) {
522 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
523 }
524 return;
525 }
526 }
527 mutex_unlock(&ec->lock);
Luming Yu45bea152005-07-23 04:08:00 -0400528}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Len Brown50526df2005-08-11 17:32:05 -0400530static u32 acpi_ec_gpe_handler(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Len Brown50526df2005-08-11 17:32:05 -0400532 acpi_status status = AE_OK;
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300533 struct acpi_ec *ec = data;
Lennart Poettering00eb43a2007-05-04 14:16:19 +0200534
Márton Németh3ebe08a2007-11-21 03:23:26 +0300535 pr_debug(PREFIX "~~~> interrupt\n");
Alexey Starikovskiy2c81ce42008-03-11 13:30:00 -0400536 atomic_inc(&ec->irq_count);
537 if (atomic_read(&ec->irq_count) > 5) {
538 pr_err(PREFIX "GPE storm detected, disabling EC GPE\n");
539 acpi_disable_gpe(NULL, ec->gpe, ACPI_ISR);
540 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
541 return ACPI_INTERRUPT_HANDLED;
542 }
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400543 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400544 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
Alexey Starikovskiyaf3fd142006-12-07 18:42:16 +0300545 wake_up(&ec->wait);
Dmitry Torokhov451566f2005-03-19 01:10:05 -0500546
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400547 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) {
548 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
549 status = acpi_os_execute(OSL_EC_BURST_HANDLER,
550 acpi_ec_gpe_query, ec);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400551 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
552 /* this is non-query, must be confirmation */
Márton Németh3ebe08a2007-11-21 03:23:26 +0300553 if (printk_ratelimit())
554 pr_info(PREFIX "non-query interrupt received,"
555 " switching to interrupt mode\n");
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400556 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400557 }
Alexey Starikovskiye41334c2006-12-07 18:42:16 +0300558
Alexey Starikovskiy78439322007-10-22 14:18:43 +0400559 return ACPI_SUCCESS(status) ?
Len Brown50526df2005-08-11 17:32:05 -0400560 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563/* --------------------------------------------------------------------------
564 Address Space Management
565 -------------------------------------------------------------------------- */
566
567static acpi_status
Len Brown50526df2005-08-11 17:32:05 -0400568acpi_ec_space_setup(acpi_handle region_handle,
569 u32 function, void *handler_context, void **return_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
571 /*
572 * The EC object is in the handler context and is needed
573 * when calling the acpi_ec_space_handler.
574 */
Len Brown50526df2005-08-11 17:32:05 -0400575 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
576 handler_context : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 return AE_OK;
579}
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581static acpi_status
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400582acpi_ec_space_handler(u32 function, acpi_physical_address address,
583 u32 bits, acpi_integer *value,
Len Brown50526df2005-08-11 17:32:05 -0400584 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300586 struct acpi_ec *ec = handler_context;
Alexey Starikovskiy3e71a872008-01-11 02:42:51 +0300587 int result = 0, i;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400588 u8 temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if ((address > 0xFF) || !value || !handler_context)
Patrick Mocheld550d982006-06-27 00:41:40 -0400591 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400593 if (function != ACPI_READ && function != ACPI_WRITE)
Patrick Mocheld550d982006-06-27 00:41:40 -0400594 return AE_BAD_PARAMETER;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400595
596 if (bits != 8 && acpi_strict)
597 return AE_BAD_PARAMETER;
598
Alexey Starikovskiyb3b233c2008-01-11 02:42:57 +0300599 acpi_ec_burst_enable(ec);
600
Alexey Starikovskiy3e71a872008-01-11 02:42:51 +0300601 if (function == ACPI_READ) {
602 result = acpi_ec_read(ec, address, &temp);
603 *value = temp;
604 } else {
605 temp = 0xff & (*value);
606 result = acpi_ec_write(ec, address, temp);
607 }
608
609 for (i = 8; unlikely(bits - i > 0); i += 8) {
610 ++address;
Alexey Starikovskiy5b7734b2007-05-29 16:42:52 +0400611 if (function == ACPI_READ) {
612 result = acpi_ec_read(ec, address, &temp);
613 (*value) |= ((acpi_integer)temp) << i;
614 } else {
615 temp = 0xff & ((*value) >> i);
616 result = acpi_ec_write(ec, address, temp);
617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 }
619
Alexey Starikovskiyb3b233c2008-01-11 02:42:57 +0300620 acpi_ec_burst_disable(ec);
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 switch (result) {
623 case -EINVAL:
Patrick Mocheld550d982006-06-27 00:41:40 -0400624 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
626 case -ENODEV:
Patrick Mocheld550d982006-06-27 00:41:40 -0400627 return AE_NOT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 break;
629 case -ETIME:
Patrick Mocheld550d982006-06-27 00:41:40 -0400630 return AE_TIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 break;
632 default:
Patrick Mocheld550d982006-06-27 00:41:40 -0400633 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635}
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637/* --------------------------------------------------------------------------
638 FS Interface (/proc)
639 -------------------------------------------------------------------------- */
640
Len Brown50526df2005-08-11 17:32:05 -0400641static struct proc_dir_entry *acpi_ec_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Len Brown50526df2005-08-11 17:32:05 -0400643static int acpi_ec_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300645 struct acpi_ec *ec = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!ec)
648 goto end;
649
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300650 seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe);
651 seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n",
652 (unsigned)ec->command_addr, (unsigned)ec->data_addr);
653 seq_printf(seq, "use global lock:\t%s\n",
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400654 ec->global_lock ? "yes" : "no");
Len Brown50526df2005-08-11 17:32:05 -0400655 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400656 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
659static int acpi_ec_info_open_fs(struct inode *inode, struct file *file)
660{
661 return single_open(file, acpi_ec_read_info, PDE(inode)->data);
662}
663
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400664static struct file_operations acpi_ec_info_ops = {
Len Brown50526df2005-08-11 17:32:05 -0400665 .open = acpi_ec_info_open_fs,
666 .read = seq_read,
667 .llseek = seq_lseek,
668 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .owner = THIS_MODULE,
670};
671
Len Brown50526df2005-08-11 17:32:05 -0400672static int acpi_ec_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Len Brown50526df2005-08-11 17:32:05 -0400674 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (!acpi_device_dir(device)) {
677 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown50526df2005-08-11 17:32:05 -0400678 acpi_ec_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
683 entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO,
Len Brown50526df2005-08-11 17:32:05 -0400684 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400686 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 else {
688 entry->proc_fops = &acpi_ec_info_ops;
689 entry->data = acpi_driver_data(device);
690 entry->owner = THIS_MODULE;
691 }
692
Patrick Mocheld550d982006-06-27 00:41:40 -0400693 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
Len Brown50526df2005-08-11 17:32:05 -0400696static int acpi_ec_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 if (acpi_device_dir(device)) {
700 remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device));
701 remove_proc_entry(acpi_device_bid(device), acpi_ec_dir);
702 acpi_device_dir(device) = NULL;
703 }
704
Patrick Mocheld550d982006-06-27 00:41:40 -0400705 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708/* --------------------------------------------------------------------------
709 Driver Interface
710 -------------------------------------------------------------------------- */
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300711static acpi_status
712ec_parse_io_ports(struct acpi_resource *resource, void *context);
713
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300714static struct acpi_ec *make_acpi_ec(void)
715{
716 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
717 if (!ec)
718 return NULL;
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400719 ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300720 mutex_init(&ec->lock);
721 init_waitqueue_head(&ec->wait);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400722 INIT_LIST_HEAD(&ec->list);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300723 return ec;
724}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400726static acpi_status
Alexey Starikovskiyc019b192007-08-14 01:03:42 -0400727acpi_ec_register_query_methods(acpi_handle handle, u32 level,
728 void *context, void **return_value)
729{
730 struct acpi_namespace_node *node = handle;
731 struct acpi_ec *ec = context;
732 int value = 0;
733 if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
734 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
735 }
736 return AE_OK;
737}
738
739static acpi_status
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400740ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400741{
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400742 acpi_status status;
743
744 struct acpi_ec *ec = context;
745 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
746 ec_parse_io_ports, ec);
747 if (ACPI_FAILURE(status))
748 return status;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400749
750 /* Get GPE bit assignment (EC events). */
751 /* TODO: Add support for _GPE returning a package */
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400752 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
753 if (ACPI_FAILURE(status))
754 return status;
Alexey Starikovskiyc019b192007-08-14 01:03:42 -0400755 /* Find and register all query methods */
756 acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
757 acpi_ec_register_query_methods, ec, NULL);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400758 /* Use the global lock for all EC transactions? */
759 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400760 ec->handle = handle;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400761 return AE_CTRL_TERMINATE;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400762}
763
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400764static void ec_remove_handlers(struct acpi_ec *ec)
765{
766 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
767 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
Márton Németh3ebe08a2007-11-21 03:23:26 +0300768 pr_err(PREFIX "failed to remove space handler\n");
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400769 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
770 &acpi_ec_gpe_handler)))
Márton Németh3ebe08a2007-11-21 03:23:26 +0300771 pr_err(PREFIX "failed to remove gpe handler\n");
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400772 ec->handlers_installed = 0;
773}
774
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400775static int acpi_ec_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400777 struct acpi_ec *ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400780 return -EINVAL;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300781 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
782 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
783
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400784 /* Check for boot EC */
785 if (boot_ec) {
786 if (boot_ec->handle == device->handle) {
787 /* Pre-loaded EC from DSDT, just move pointer */
788 ec = boot_ec;
789 boot_ec = NULL;
790 goto end;
791 } else if (boot_ec->handle == ACPI_ROOT_OBJECT) {
792 /* ECDT-based EC, time to shut it down */
793 ec_remove_handlers(boot_ec);
794 kfree(boot_ec);
795 first_ec = boot_ec = NULL;
796 }
797 }
798
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300799 ec = make_acpi_ec();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400801 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400803 if (ec_parse_device(device->handle, 0, ec, NULL) !=
804 AE_CTRL_TERMINATE) {
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300805 kfree(ec);
806 return -EINVAL;
Denis M. Sadykov703959d2006-09-26 19:50:33 +0400807 }
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300808 ec->handle = device->handle;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400809 end:
810 if (!first_ec)
811 first_ec = ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 acpi_driver_data(device) = ec;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300813 acpi_ec_add_fs(device);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300814 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400815 ec->gpe, ec->command_addr, ec->data_addr);
Márton Németh3ebe08a2007-11-21 03:23:26 +0300816 pr_info(PREFIX "driver started in %s mode\n",
Alexey Starikovskiy95b937e2007-10-22 14:19:03 +0400817 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300818 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
Len Brown50526df2005-08-11 17:32:05 -0400821static int acpi_ec_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300823 struct acpi_ec *ec;
Adrian Bunk07ddf762007-07-29 17:00:37 +0200824 struct acpi_ec_query_handler *handler, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400827 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 ec = acpi_driver_data(device);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400830 mutex_lock(&ec->lock);
Adrian Bunk07ddf762007-07-29 17:00:37 +0200831 list_for_each_entry_safe(handler, tmp, &ec->list, node) {
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400832 list_del(&handler->node);
833 kfree(handler);
834 }
835 mutex_unlock(&ec->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 acpi_ec_remove_fs(device);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300837 acpi_driver_data(device) = NULL;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300838 if (ec == first_ec)
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300839 first_ec = NULL;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400840 kfree(ec);
Patrick Mocheld550d982006-06-27 00:41:40 -0400841 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844static acpi_status
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300845ec_parse_io_ports(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Alexey Starikovskiy3d02b902007-03-07 22:28:00 +0300847 struct acpi_ec *ec = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300849 if (resource->type != ACPI_RESOURCE_TYPE_IO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 /*
853 * The first address region returned is the data port, and
854 * the second address region returned is the status/command
855 * port.
856 */
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300857 if (ec->data_addr == 0)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400858 ec->data_addr = resource->data.io.minimum;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300859 else if (ec->command_addr == 0)
Denis M. Sadykov6ffb2212006-09-26 19:50:33 +0400860 ec->command_addr = resource->data.io.minimum;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300861 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return AE_OK;
865}
866
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300867static int ec_install_handlers(struct acpi_ec *ec)
868{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300869 acpi_status status;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400870 if (ec->handlers_installed)
871 return 0;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300872 status = acpi_install_gpe_handler(NULL, ec->gpe,
873 ACPI_GPE_EDGE_TRIGGERED,
874 &acpi_ec_gpe_handler, ec);
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300875 if (ACPI_FAILURE(status))
876 return -ENODEV;
Alexey Starikovskiy01f22462007-03-07 22:28:00 +0300877
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300878 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
879 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
880
881 status = acpi_install_address_space_handler(ec->handle,
882 ACPI_ADR_SPACE_EC,
883 &acpi_ec_space_handler,
884 &acpi_ec_space_setup, ec);
885 if (ACPI_FAILURE(status)) {
886 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
887 return -ENODEV;
888 }
889
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400890 ec->handlers_installed = 1;
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300891 return 0;
892}
893
Len Brown50526df2005-08-11 17:32:05 -0400894static int acpi_ec_start(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300896 struct acpi_ec *ec;
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400897 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400900 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 ec = acpi_driver_data(device);
903
904 if (!ec)
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400907 ret = ec_install_handlers(ec);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300908
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400909 /* EC is fully operational, allow queries */
Alexey Starikovskiy080e4122007-10-22 14:18:30 +0400910 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
Alexey Starikovskiy837012e2007-05-29 16:43:02 +0400911 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
Len Brown50526df2005-08-11 17:32:05 -0400914static int acpi_ec_stop(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300916 struct acpi_ec *ec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400918 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 ec = acpi_driver_data(device);
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300920 if (!ec)
921 return -EINVAL;
Alexey Starikovskiy4c611062007-09-05 19:56:38 -0400922 ec_remove_handlers(ec);
Alexey Starikovskiyf9319f92007-08-24 08:10:11 +0400923
Patrick Mocheld550d982006-06-27 00:41:40 -0400924 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500927int __init acpi_boot_ec_enable(void)
928{
929 if (!boot_ec || boot_ec->handlers_installed)
930 return 0;
931 if (!ec_install_handlers(boot_ec)) {
932 first_ec = boot_ec;
933 return 0;
934 }
935 return -EFAULT;
936}
937
Len Brown50526df2005-08-11 17:32:05 -0400938int __init acpi_ec_ecdt_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
Len Brown50526df2005-08-11 17:32:05 -0400940 int ret;
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300941 acpi_status status;
942 struct acpi_table_ecdt *ecdt_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300944 boot_ec = make_acpi_ec();
945 if (!boot_ec)
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300946 return -ENOMEM;
947 /*
948 * Generate a boot ec context
949 */
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300950 status = acpi_get_table(ACPI_SIG_ECDT, 1,
951 (struct acpi_table_header **)&ecdt_ptr);
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400952 if (ACPI_SUCCESS(status)) {
Márton Németh3ebe08a2007-11-21 03:23:26 +0300953 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400954 boot_ec->command_addr = ecdt_ptr->control.address;
955 boot_ec->data_addr = ecdt_ptr->data.address;
956 boot_ec->gpe = ecdt_ptr->gpe;
Alexey Starikovskiy208c70a2008-02-14 15:58:47 -0500957 if (ACPI_FAILURE(acpi_get_handle(NULL, ecdt_ptr->id,
958 &boot_ec->handle))) {
959 pr_info("Failed to locate handle for boot EC\n");
960 boot_ec->handle = ACPI_ROOT_OBJECT;
961 }
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400962 } else {
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300963 /* This workaround is needed only on some broken machines,
964 * which require early EC, but fail to provide ECDT */
965 acpi_handle x;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400966 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
967 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
968 boot_ec, NULL);
Alexey Starikovskiy2d8348b2007-08-31 09:05:26 +0400969 /* Check that acpi_get_devices actually find something */
970 if (ACPI_FAILURE(status) || !boot_ec->handle)
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400971 goto error;
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300972 /* We really need to limit this workaround, the only ASUS,
973 * which needs it, has fake EC._INI method, so use it as flag.
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500974 * Keep boot_ec struct as it will be needed soon.
Alexey Starikovskiy5870a8c2007-11-15 21:52:47 +0300975 */
976 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
Alexey Starikovskiyc04209a2008-01-01 14:12:55 -0500977 return -ENODEV;
Alexey Starikovskiycd8c93a2007-08-03 17:52:48 -0400978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300980 ret = ec_install_handlers(boot_ec);
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300981 if (!ret) {
982 first_ec = boot_ec;
Alexey Starikovskiye8284322007-03-07 22:28:00 +0300983 return 0;
Alexey Starikovskiyd0338792007-03-07 22:28:00 +0300984 }
Alexey Starikovskiyc0900c32007-03-07 22:28:00 +0300985 error:
Alexey Starikovskiyd66d9692007-03-07 22:28:00 +0300986 kfree(boot_ec);
987 boot_ec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 return -ENODEV;
989}
990
Len Brown50526df2005-08-11 17:32:05 -0400991static int __init acpi_ec_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992{
Len Brown50526df2005-08-11 17:32:05 -0400993 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400996 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
998 acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir);
999 if (!acpi_ec_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001000 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /* Now register the driver for the EC */
1003 result = acpi_bus_register_driver(&acpi_ec_driver);
1004 if (result < 0) {
1005 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04001006 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008
Patrick Mocheld550d982006-06-27 00:41:40 -04001009 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
1012subsys_initcall(acpi_ec_init);
1013
1014/* EC driver currently not unloadable */
1015#if 0
Len Brown50526df2005-08-11 17:32:05 -04001016static void __exit acpi_ec_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
1019 acpi_bus_unregister_driver(&acpi_ec_driver);
1020
1021 remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir);
1022
Patrick Mocheld550d982006-06-27 00:41:40 -04001023 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024}
Alexey Starikovskiy78439322007-10-22 14:18:43 +04001025#endif /* 0 */