Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 2 | * ec.c - ACPI Embedded Controller Driver (v2.0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 4 | * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> |
| 5 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> |
| 7 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 8 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 9 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or (at |
| 15 | * your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, but |
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 25 | * |
| 26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | */ |
| 28 | |
Márton Németh | d772b3b | 2008-01-23 22:34:09 -0500 | [diff] [blame^] | 29 | /* Uncomment next line to get verbose print outs*/ |
| 30 | /* #define DEBUG */ |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/kernel.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/proc_fs.h> |
| 38 | #include <linux/seq_file.h> |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 40 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/io.h> |
| 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <acpi/acpi_drivers.h> |
| 44 | #include <acpi/actypes.h> |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define ACPI_EC_CLASS "embedded_controller" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" |
| 48 | #define ACPI_EC_FILE_INFO "info" |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 49 | |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 50 | #undef PREFIX |
| 51 | #define PREFIX "ACPI: EC: " |
Alexey Starikovskiy | 4350933 | 2007-05-29 16:42:57 +0400 | [diff] [blame] | 52 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 53 | /* EC status register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
| 55 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 56 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
Alexey Starikovskiy | 4350933 | 2007-05-29 16:42:57 +0400 | [diff] [blame] | 58 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 59 | /* EC commands */ |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 60 | enum ec_command { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 61 | ACPI_EC_COMMAND_READ = 0x80, |
| 62 | ACPI_EC_COMMAND_WRITE = 0x81, |
| 63 | ACPI_EC_BURST_ENABLE = 0x82, |
| 64 | ACPI_EC_BURST_DISABLE = 0x83, |
| 65 | ACPI_EC_COMMAND_QUERY = 0x84, |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 66 | }; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 67 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 68 | /* EC events */ |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 69 | enum ec_event { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 70 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 71 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 72 | }; |
| 73 | |
Alexey Starikovskiy | 5c40641 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 74 | #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 75 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 76 | |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 77 | enum { |
| 78 | EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */ |
| 79 | EC_FLAGS_QUERY_PENDING, /* Query is pending */ |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 80 | EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */ |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 81 | EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */ |
| 82 | EC_FLAGS_ADDRESS, /* Address is being written */ |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 83 | EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */ |
| 84 | EC_FLAGS_WDATA, /* Data is being written */ |
Alexey Starikovskiy | 03d1d99 | 2008-01-23 22:28:34 -0500 | [diff] [blame] | 85 | EC_FLAGS_NO_OBF1_GPE, /* Don't expect GPE before read */ |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 86 | }; |
| 87 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 88 | static int acpi_ec_remove(struct acpi_device *device, int type); |
| 89 | static int acpi_ec_start(struct acpi_device *device); |
| 90 | static int acpi_ec_stop(struct acpi_device *device, int type); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 91 | static int acpi_ec_add(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 93 | static const struct acpi_device_id ec_device_ids[] = { |
| 94 | {"PNP0C09", 0}, |
| 95 | {"", 0}, |
| 96 | }; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static struct acpi_driver acpi_ec_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 99 | .name = "ec", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 100 | .class = ACPI_EC_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 101 | .ids = ec_device_ids, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 102 | .ops = { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 103 | .add = acpi_ec_add, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 104 | .remove = acpi_ec_remove, |
| 105 | .start = acpi_ec_start, |
| 106 | .stop = acpi_ec_stop, |
| 107 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | }; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 109 | |
| 110 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 111 | /* External interfaces use first EC only, so remember */ |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 112 | typedef int (*acpi_ec_query_func) (void *data); |
| 113 | |
| 114 | struct 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 Bunk | a854e08 | 2006-12-19 12:56:12 -0800 | [diff] [blame] | 122 | static struct acpi_ec { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 123 | acpi_handle handle; |
Alexey Starikovskiy | a86e277 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 124 | unsigned long gpe; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 125 | unsigned long command_addr; |
| 126 | unsigned long data_addr; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 127 | unsigned long global_lock; |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 128 | unsigned long flags; |
Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 129 | struct mutex lock; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 130 | wait_queue_head_t wait; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 131 | struct list_head list; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 132 | u8 handlers_installed; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 133 | } *boot_ec, *first_ec; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* -------------------------------------------------------------------------- |
| 136 | Transaction Management |
| 137 | -------------------------------------------------------------------------- */ |
| 138 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 139 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 141 | u8 x = inb(ec->command_addr); |
Márton Németh | 86dae01 | 2008-01-23 22:33:06 -0500 | [diff] [blame] | 142 | pr_debug(PREFIX "---> status = 0x%2.2x\n", x); |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 143 | return x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 146 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 147 | { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 148 | u8 x = inb(ec->data_addr); |
Márton Németh | 86dae01 | 2008-01-23 22:33:06 -0500 | [diff] [blame] | 149 | pr_debug(PREFIX "---> data = 0x%2.2x\n", x); |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 150 | return inb(ec->data_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 151 | } |
| 152 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 153 | static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 154 | { |
Márton Németh | 86dae01 | 2008-01-23 22:33:06 -0500 | [diff] [blame] | 155 | pr_debug(PREFIX "<--- command = 0x%2.2x\n", command); |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 156 | outb(command, ec->command_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 157 | } |
| 158 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 159 | static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 160 | { |
Márton Németh | 86dae01 | 2008-01-23 22:33:06 -0500 | [diff] [blame] | 161 | pr_debug(PREFIX "<--- data = 0x%2.2x\n", data); |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 162 | outb(data, ec->data_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 163 | } |
| 164 | |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 165 | static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 166 | { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 167 | if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags)) |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 168 | return 0; |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 169 | if (event == ACPI_EC_EVENT_OBF_1) { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 170 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF) |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 171 | return 1; |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 172 | } else if (event == ACPI_EC_EVENT_IBF_0) { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 173 | if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF)) |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 174 | return 1; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 180 | static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 181 | { |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 182 | int ret = 0; |
Alexey Starikovskiy | 03d1d99 | 2008-01-23 22:28:34 -0500 | [diff] [blame] | 183 | |
| 184 | if (unlikely(event == ACPI_EC_EVENT_OBF_1 && |
| 185 | test_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags))) |
| 186 | force_poll = 1; |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 187 | if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) && |
| 188 | test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags))) |
| 189 | force_poll = 1; |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 190 | if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) && |
| 191 | test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags))) |
| 192 | force_poll = 1; |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 193 | if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && |
| 194 | likely(!force_poll)) { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 195 | if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), |
| 196 | msecs_to_jiffies(ACPI_EC_DELAY))) |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 197 | goto end; |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 198 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
| 199 | if (acpi_ec_check_status(ec, event)) { |
Alexey Starikovskiy | 03d1d99 | 2008-01-23 22:28:34 -0500 | [diff] [blame] | 200 | if (event == ACPI_EC_EVENT_OBF_1) { |
| 201 | /* miss OBF_1 GPE, don't expect it */ |
| 202 | pr_info(PREFIX "missing OBF confirmation, " |
| 203 | "don't expect it any longer.\n"); |
| 204 | set_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags); |
| 205 | } else if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) { |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 206 | /* miss address GPE, don't expect it anymore */ |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 207 | pr_info(PREFIX "missing address confirmation, " |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 208 | "don't expect it any longer.\n"); |
| 209 | set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags); |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 210 | } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) { |
| 211 | /* miss write data GPE, don't expect it */ |
| 212 | pr_info(PREFIX "missing write data confirmation, " |
| 213 | "don't expect it any longer.\n"); |
| 214 | set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags); |
Alexey Starikovskiy | 95b937e | 2007-10-22 14:19:03 +0400 | [diff] [blame] | 215 | } else { |
Alexey Starikovskiy | 66c5f4e | 2007-10-22 14:18:56 +0400 | [diff] [blame] | 216 | /* missing GPEs, switch back to poll mode */ |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 217 | if (printk_ratelimit()) |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 218 | pr_info(PREFIX "missing confirmations, " |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 219 | "switch off interrupt mode.\n"); |
Alexey Starikovskiy | 66c5f4e | 2007-10-22 14:18:56 +0400 | [diff] [blame] | 220 | clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); |
Alexey Starikovskiy | 95b937e | 2007-10-22 14:19:03 +0400 | [diff] [blame] | 221 | } |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 222 | goto end; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 223 | } |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 224 | } else { |
| 225 | unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); |
| 226 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
| 227 | while (time_before(jiffies, delay)) { |
| 228 | if (acpi_ec_check_status(ec, event)) |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 229 | goto end; |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 230 | } |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 231 | } |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 232 | pr_err(PREFIX "acpi_ec_wait timeout," |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 233 | " status = %d, expect_event = %d\n", |
| 234 | acpi_ec_read_status(ec), event); |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 235 | ret = -ETIME; |
| 236 | end: |
| 237 | clear_bit(EC_FLAGS_ADDRESS, &ec->flags); |
| 238 | return ret; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 241 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 242 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 243 | u8 * rdata, unsigned rdata_len, |
| 244 | int force_poll) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 245 | { |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 246 | int result = 0; |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 247 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 248 | acpi_ec_write_cmd(ec, command); |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 249 | pr_debug(PREFIX "transaction start\n"); |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 250 | for (; wdata_len > 0; --wdata_len) { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 251 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 252 | if (result) { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 253 | pr_err(PREFIX |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 254 | "write_cmd timeout, command = %d\n", command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 255 | goto end; |
| 256 | } |
Alexey Starikovskiy | f2d6893 | 2007-11-19 01:37:03 +0300 | [diff] [blame] | 257 | /* mark the address byte written to EC */ |
| 258 | if (rdata_len + wdata_len > 1) |
| 259 | set_bit(EC_FLAGS_ADDRESS, &ec->flags); |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 260 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 261 | acpi_ec_write_data(ec, *(wdata++)); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 262 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 263 | |
Alexey Starikovskiy | d91df1a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 264 | if (!rdata_len) { |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 265 | set_bit(EC_FLAGS_WDATA, &ec->flags); |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 266 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 267 | if (result) { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 268 | pr_err(PREFIX |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 269 | "finish-write timeout, command = %d\n", command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 270 | goto end; |
| 271 | } |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 272 | } else if (command == ACPI_EC_COMMAND_QUERY) |
| 273 | clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 274 | |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 275 | for (; rdata_len > 0; --rdata_len) { |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 276 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 277 | if (result) { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 278 | pr_err(PREFIX "read timeout, command = %d\n", command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 279 | goto end; |
| 280 | } |
Alexey Starikovskiy | 0c5d31f | 2007-10-22 14:18:36 +0400 | [diff] [blame] | 281 | /* Don't expect GPE after last read */ |
| 282 | if (rdata_len > 1) |
| 283 | set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 284 | *(rdata++) = acpi_ec_read_data(ec); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 285 | } |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 286 | end: |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 287 | pr_debug(PREFIX "transaction end\n"); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 288 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 291 | static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 292 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 293 | u8 * rdata, unsigned rdata_len, |
| 294 | int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 295 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 296 | int status; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 297 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 299 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 300 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 302 | if (rdata) |
| 303 | memset(rdata, 0, rdata_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Alexey Starikovskiy | 523953b | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 305 | mutex_lock(&ec->lock); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 306 | if (ec->global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
Alexey Starikovskiy | c24e912 | 2007-02-15 23:16:18 +0300 | [diff] [blame] | 308 | if (ACPI_FAILURE(status)) { |
| 309 | mutex_unlock(&ec->lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 310 | return -ENODEV; |
Alexey Starikovskiy | c24e912 | 2007-02-15 23:16:18 +0300 | [diff] [blame] | 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 313 | |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 314 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 315 | if (status) { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 316 | pr_err(PREFIX "input buffer is not empty, " |
| 317 | "aborting transaction\n"); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 318 | goto end; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 321 | status = acpi_ec_transaction_unlocked(ec, command, |
| 322 | wdata, wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 323 | rdata, rdata_len, |
| 324 | force_poll); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 325 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 326 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 328 | if (ec->global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | acpi_release_global_lock(glk); |
Alexey Starikovskiy | 523953b | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 330 | mutex_unlock(&ec->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 332 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 335 | /* |
| 336 | * Note: samsung nv5000 doesn't work with ec burst mode. |
| 337 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 |
| 338 | */ |
| 339 | int acpi_ec_burst_enable(struct acpi_ec *ec) |
| 340 | { |
| 341 | u8 d; |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 342 | return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | int acpi_ec_burst_disable(struct acpi_ec *ec) |
| 346 | { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 347 | return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 348 | } |
| 349 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 350 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 351 | { |
| 352 | int result; |
| 353 | u8 d; |
| 354 | |
| 355 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 356 | &address, 1, &d, 1, 0); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 357 | *data = d; |
| 358 | return result; |
| 359 | } |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 360 | |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 361 | static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) |
| 362 | { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 363 | u8 wdata[2] = { address, data }; |
| 364 | return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 365 | wdata, 2, NULL, 0, 0); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* |
| 369 | * Externally callable EC access functions. For now, assume 1 EC only |
| 370 | */ |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 371 | int ec_burst_enable(void) |
| 372 | { |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 373 | if (!first_ec) |
| 374 | return -ENODEV; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 375 | return acpi_ec_burst_enable(first_ec); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | EXPORT_SYMBOL(ec_burst_enable); |
| 379 | |
| 380 | int ec_burst_disable(void) |
| 381 | { |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 382 | if (!first_ec) |
| 383 | return -ENODEV; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 384 | return acpi_ec_burst_disable(first_ec); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | EXPORT_SYMBOL(ec_burst_disable); |
| 388 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 389 | int ec_read(u8 addr, u8 * val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int err; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 392 | u8 temp_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | if (!first_ec) |
| 395 | return -ENODEV; |
| 396 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 397 | err = acpi_ec_read(first_ec, addr, &temp_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | if (!err) { |
| 400 | *val = temp_data; |
| 401 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 402 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return err; |
| 404 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | EXPORT_SYMBOL(ec_read); |
| 407 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 408 | int ec_write(u8 addr, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | int err; |
| 411 | |
| 412 | if (!first_ec) |
| 413 | return -ENODEV; |
| 414 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 415 | err = acpi_ec_write(first_ec, addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | return err; |
| 418 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | EXPORT_SYMBOL(ec_write); |
| 421 | |
Randy Dunlap | 616362d | 2006-10-27 01:47:34 -0400 | [diff] [blame] | 422 | int ec_transaction(u8 command, |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 423 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 424 | u8 * rdata, unsigned rdata_len, |
| 425 | int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 426 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 427 | if (!first_ec) |
| 428 | return -ENODEV; |
| 429 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 430 | return acpi_ec_transaction(first_ec, command, wdata, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 431 | wdata_len, rdata, rdata_len, |
| 432 | force_poll); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 433 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 434 | |
Lennart Poettering | ab9e43c | 2006-10-03 22:49:00 -0400 | [diff] [blame] | 435 | EXPORT_SYMBOL(ec_transaction); |
| 436 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 437 | static int acpi_ec_query(struct acpi_ec *ec, u8 * data) |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 438 | { |
| 439 | int result; |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 440 | u8 d; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 441 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 442 | if (!ec || !data) |
| 443 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 444 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 445 | /* |
| 446 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 447 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 448 | * bit to be cleared (and thus clearing the interrupt source). |
| 449 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 450 | |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 451 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0); |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 452 | if (result) |
| 453 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 454 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 455 | if (!d) |
| 456 | return -ENODATA; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 457 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 458 | *data = d; |
| 459 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | /* -------------------------------------------------------------------------- |
| 463 | Event Management |
| 464 | -------------------------------------------------------------------------- */ |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 465 | int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, |
| 466 | acpi_handle handle, acpi_ec_query_func func, |
| 467 | void *data) |
| 468 | { |
| 469 | struct acpi_ec_query_handler *handler = |
| 470 | kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL); |
| 471 | if (!handler) |
| 472 | return -ENOMEM; |
| 473 | |
| 474 | handler->query_bit = query_bit; |
| 475 | handler->handle = handle; |
| 476 | handler->func = func; |
| 477 | handler->data = data; |
| 478 | mutex_lock(&ec->lock); |
Alexey Starikovskiy | 30c0857 | 2007-09-26 19:43:22 +0400 | [diff] [blame] | 479 | list_add(&handler->node, &ec->list); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 480 | mutex_unlock(&ec->lock); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); |
| 485 | |
| 486 | void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) |
| 487 | { |
Adrian Bunk | 1544fdb | 2007-10-24 18:26:00 +0200 | [diff] [blame] | 488 | struct acpi_ec_query_handler *handler, *tmp; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 489 | mutex_lock(&ec->lock); |
Adrian Bunk | 1544fdb | 2007-10-24 18:26:00 +0200 | [diff] [blame] | 490 | list_for_each_entry_safe(handler, tmp, &ec->list, node) { |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 491 | if (query_bit == handler->query_bit) { |
| 492 | list_del(&handler->node); |
| 493 | kfree(handler); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | mutex_unlock(&ec->lock); |
| 497 | } |
| 498 | |
| 499 | EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 501 | static void acpi_ec_gpe_query(void *ec_cxt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 503 | struct acpi_ec *ec = ec_cxt; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 504 | u8 value = 0; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 505 | struct acpi_ec_query_handler *handler, copy; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 506 | |
Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 507 | if (!ec || acpi_ec_query(ec, &value)) |
Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 508 | return; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 509 | mutex_lock(&ec->lock); |
| 510 | list_for_each_entry(handler, &ec->list, node) { |
| 511 | if (value == handler->query_bit) { |
| 512 | /* have custom handler for this bit */ |
| 513 | memcpy(©, handler, sizeof(copy)); |
| 514 | mutex_unlock(&ec->lock); |
| 515 | if (copy.func) { |
| 516 | copy.func(copy.data); |
| 517 | } else if (copy.handle) { |
| 518 | acpi_evaluate_object(copy.handle, NULL, NULL, NULL); |
| 519 | } |
| 520 | return; |
| 521 | } |
| 522 | } |
| 523 | mutex_unlock(&ec->lock); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 526 | static u32 acpi_ec_gpe_handler(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 528 | acpi_status status = AE_OK; |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 529 | struct acpi_ec *ec = data; |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 530 | |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 531 | pr_debug(PREFIX "~~~> interrupt\n"); |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 532 | clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 533 | if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 534 | wake_up(&ec->wait); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 535 | |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 536 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) { |
| 537 | if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) |
| 538 | status = acpi_os_execute(OSL_EC_BURST_HANDLER, |
| 539 | acpi_ec_gpe_query, ec); |
Alexey Starikovskiy | 95b937e | 2007-10-22 14:19:03 +0400 | [diff] [blame] | 540 | } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { |
| 541 | /* this is non-query, must be confirmation */ |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 542 | if (printk_ratelimit()) |
| 543 | pr_info(PREFIX "non-query interrupt received," |
| 544 | " switching to interrupt mode\n"); |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 545 | set_bit(EC_FLAGS_GPE_MODE, &ec->flags); |
Alexey Starikovskiy | 95b937e | 2007-10-22 14:19:03 +0400 | [diff] [blame] | 546 | } |
Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 547 | |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 548 | return ACPI_SUCCESS(status) ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 549 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /* -------------------------------------------------------------------------- |
| 553 | Address Space Management |
| 554 | -------------------------------------------------------------------------- */ |
| 555 | |
| 556 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 557 | acpi_ec_space_setup(acpi_handle region_handle, |
| 558 | u32 function, void *handler_context, void **return_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { |
| 560 | /* |
| 561 | * The EC object is in the handler context and is needed |
| 562 | * when calling the acpi_ec_space_handler. |
| 563 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 564 | *return_context = (function != ACPI_REGION_DEACTIVATE) ? |
| 565 | handler_context : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | return AE_OK; |
| 568 | } |
| 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | static acpi_status |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 571 | acpi_ec_space_handler(u32 function, acpi_physical_address address, |
| 572 | u32 bits, acpi_integer *value, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 573 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 575 | struct acpi_ec *ec = handler_context; |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 576 | int result = 0, i = 0; |
| 577 | u8 temp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if ((address > 0xFF) || !value || !handler_context) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 580 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 582 | if (function != ACPI_READ && function != ACPI_WRITE) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 583 | return AE_BAD_PARAMETER; |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 584 | |
| 585 | if (bits != 8 && acpi_strict) |
| 586 | return AE_BAD_PARAMETER; |
| 587 | |
| 588 | while (bits - i > 0) { |
| 589 | if (function == ACPI_READ) { |
| 590 | result = acpi_ec_read(ec, address, &temp); |
| 591 | (*value) |= ((acpi_integer)temp) << i; |
| 592 | } else { |
| 593 | temp = 0xff & ((*value) >> i); |
| 594 | result = acpi_ec_write(ec, address, temp); |
| 595 | } |
| 596 | i += 8; |
| 597 | ++address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | switch (result) { |
| 601 | case -EINVAL: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 602 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | break; |
| 604 | case -ENODEV: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 605 | return AE_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | break; |
| 607 | case -ETIME: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 608 | return AE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | break; |
| 610 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 611 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* -------------------------------------------------------------------------- |
| 616 | FS Interface (/proc) |
| 617 | -------------------------------------------------------------------------- */ |
| 618 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 619 | static struct proc_dir_entry *acpi_ec_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 621 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 623 | struct acpi_ec *ec = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if (!ec) |
| 626 | goto end; |
| 627 | |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 628 | seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); |
| 629 | seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", |
| 630 | (unsigned)ec->command_addr, (unsigned)ec->data_addr); |
| 631 | seq_printf(seq, "use global lock:\t%s\n", |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 632 | ec->global_lock ? "yes" : "no"); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 633 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 634 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) |
| 638 | { |
| 639 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
| 640 | } |
| 641 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 642 | static struct file_operations acpi_ec_info_ops = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 643 | .open = acpi_ec_info_open_fs, |
| 644 | .read = seq_read, |
| 645 | .llseek = seq_lseek, |
| 646 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | .owner = THIS_MODULE, |
| 648 | }; |
| 649 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 650 | static int acpi_ec_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 652 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | if (!acpi_device_dir(device)) { |
| 655 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 656 | acpi_ec_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 658 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 662 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 664 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | else { |
| 666 | entry->proc_fops = &acpi_ec_info_ops; |
| 667 | entry->data = acpi_driver_data(device); |
| 668 | entry->owner = THIS_MODULE; |
| 669 | } |
| 670 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 671 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 674 | static int acpi_ec_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | if (acpi_device_dir(device)) { |
| 678 | remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); |
| 679 | remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); |
| 680 | acpi_device_dir(device) = NULL; |
| 681 | } |
| 682 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 683 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* -------------------------------------------------------------------------- |
| 687 | Driver Interface |
| 688 | -------------------------------------------------------------------------- */ |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 689 | static acpi_status |
| 690 | ec_parse_io_ports(struct acpi_resource *resource, void *context); |
| 691 | |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 692 | static struct acpi_ec *make_acpi_ec(void) |
| 693 | { |
| 694 | struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
| 695 | if (!ec) |
| 696 | return NULL; |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 697 | ec->flags = 1 << EC_FLAGS_QUERY_PENDING; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 698 | mutex_init(&ec->lock); |
| 699 | init_waitqueue_head(&ec->wait); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 700 | INIT_LIST_HEAD(&ec->list); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 701 | return ec; |
| 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 704 | static acpi_status |
Alexey Starikovskiy | c019b19 | 2007-08-14 01:03:42 -0400 | [diff] [blame] | 705 | acpi_ec_register_query_methods(acpi_handle handle, u32 level, |
| 706 | void *context, void **return_value) |
| 707 | { |
| 708 | struct acpi_namespace_node *node = handle; |
| 709 | struct acpi_ec *ec = context; |
| 710 | int value = 0; |
| 711 | if (sscanf(node->name.ascii, "_Q%x", &value) == 1) { |
| 712 | acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); |
| 713 | } |
| 714 | return AE_OK; |
| 715 | } |
| 716 | |
| 717 | static acpi_status |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 718 | ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 719 | { |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 720 | acpi_status status; |
| 721 | |
| 722 | struct acpi_ec *ec = context; |
| 723 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 724 | ec_parse_io_ports, ec); |
| 725 | if (ACPI_FAILURE(status)) |
| 726 | return status; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 727 | |
| 728 | /* Get GPE bit assignment (EC events). */ |
| 729 | /* TODO: Add support for _GPE returning a package */ |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 730 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); |
| 731 | if (ACPI_FAILURE(status)) |
| 732 | return status; |
Alexey Starikovskiy | c019b19 | 2007-08-14 01:03:42 -0400 | [diff] [blame] | 733 | /* Find and register all query methods */ |
| 734 | acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, |
| 735 | acpi_ec_register_query_methods, ec, NULL); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 736 | /* Use the global lock for all EC transactions? */ |
| 737 | acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 738 | ec->handle = handle; |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 739 | return AE_CTRL_TERMINATE; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 740 | } |
| 741 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 742 | static void ec_remove_handlers(struct acpi_ec *ec) |
| 743 | { |
| 744 | if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, |
| 745 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 746 | pr_err(PREFIX "failed to remove space handler\n"); |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 747 | if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, |
| 748 | &acpi_ec_gpe_handler))) |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 749 | pr_err(PREFIX "failed to remove gpe handler\n"); |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 750 | ec->handlers_installed = 0; |
| 751 | } |
| 752 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 753 | static int acpi_ec_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 755 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 758 | return -EINVAL; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 759 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 760 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 761 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 762 | /* Check for boot EC */ |
| 763 | if (boot_ec) { |
| 764 | if (boot_ec->handle == device->handle) { |
| 765 | /* Pre-loaded EC from DSDT, just move pointer */ |
| 766 | ec = boot_ec; |
| 767 | boot_ec = NULL; |
| 768 | goto end; |
| 769 | } else if (boot_ec->handle == ACPI_ROOT_OBJECT) { |
| 770 | /* ECDT-based EC, time to shut it down */ |
| 771 | ec_remove_handlers(boot_ec); |
| 772 | kfree(boot_ec); |
| 773 | first_ec = boot_ec = NULL; |
| 774 | } |
| 775 | } |
| 776 | |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 777 | ec = make_acpi_ec(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 779 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 781 | if (ec_parse_device(device->handle, 0, ec, NULL) != |
| 782 | AE_CTRL_TERMINATE) { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 783 | kfree(ec); |
| 784 | return -EINVAL; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 785 | } |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 786 | ec->handle = device->handle; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 787 | end: |
| 788 | if (!first_ec) |
| 789 | first_ec = ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | acpi_driver_data(device) = ec; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 791 | acpi_ec_add_fs(device); |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 792 | pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 793 | ec->gpe, ec->command_addr, ec->data_addr); |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 794 | pr_info(PREFIX "driver started in %s mode\n", |
Alexey Starikovskiy | 95b937e | 2007-10-22 14:19:03 +0400 | [diff] [blame] | 795 | (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 796 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 799 | static int acpi_ec_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 801 | struct acpi_ec *ec; |
Adrian Bunk | 07ddf76 | 2007-07-29 17:00:37 +0200 | [diff] [blame] | 802 | struct acpi_ec_query_handler *handler, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 805 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | ec = acpi_driver_data(device); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 808 | mutex_lock(&ec->lock); |
Adrian Bunk | 07ddf76 | 2007-07-29 17:00:37 +0200 | [diff] [blame] | 809 | list_for_each_entry_safe(handler, tmp, &ec->list, node) { |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 810 | list_del(&handler->node); |
| 811 | kfree(handler); |
| 812 | } |
| 813 | mutex_unlock(&ec->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | acpi_ec_remove_fs(device); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 815 | acpi_driver_data(device) = NULL; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 816 | if (ec == first_ec) |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 817 | first_ec = NULL; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 818 | kfree(ec); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 819 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | static acpi_status |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 823 | ec_parse_io_ports(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 825 | struct acpi_ec *ec = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 827 | if (resource->type != ACPI_RESOURCE_TYPE_IO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | /* |
| 831 | * The first address region returned is the data port, and |
| 832 | * the second address region returned is the status/command |
| 833 | * port. |
| 834 | */ |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 835 | if (ec->data_addr == 0) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 836 | ec->data_addr = resource->data.io.minimum; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 837 | else if (ec->command_addr == 0) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 838 | ec->command_addr = resource->data.io.minimum; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 839 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | return AE_OK; |
| 843 | } |
| 844 | |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 845 | static int ec_install_handlers(struct acpi_ec *ec) |
| 846 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 847 | acpi_status status; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 848 | if (ec->handlers_installed) |
| 849 | return 0; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 850 | status = acpi_install_gpe_handler(NULL, ec->gpe, |
| 851 | ACPI_GPE_EDGE_TRIGGERED, |
| 852 | &acpi_ec_gpe_handler, ec); |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 853 | if (ACPI_FAILURE(status)) |
| 854 | return -ENODEV; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 855 | |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 856 | acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); |
| 857 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
| 858 | |
| 859 | status = acpi_install_address_space_handler(ec->handle, |
| 860 | ACPI_ADR_SPACE_EC, |
| 861 | &acpi_ec_space_handler, |
| 862 | &acpi_ec_space_setup, ec); |
| 863 | if (ACPI_FAILURE(status)) { |
| 864 | acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); |
| 865 | return -ENODEV; |
| 866 | } |
| 867 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 868 | ec->handlers_installed = 1; |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 872 | static int acpi_ec_start(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 874 | struct acpi_ec *ec; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 875 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 878 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
| 880 | ec = acpi_driver_data(device); |
| 881 | |
| 882 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 883 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 885 | ret = ec_install_handlers(ec); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 886 | |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 887 | /* EC is fully operational, allow queries */ |
Alexey Starikovskiy | 080e412 | 2007-10-22 14:18:30 +0400 | [diff] [blame] | 888 | clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 889 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 892 | static int acpi_ec_stop(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 894 | struct acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 896 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | ec = acpi_driver_data(device); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 898 | if (!ec) |
| 899 | return -EINVAL; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame] | 900 | ec_remove_handlers(ec); |
Alexey Starikovskiy | f9319f9 | 2007-08-24 08:10:11 +0400 | [diff] [blame] | 901 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Alexey Starikovskiy | c04209a | 2008-01-01 14:12:55 -0500 | [diff] [blame] | 905 | int __init acpi_boot_ec_enable(void) |
| 906 | { |
| 907 | if (!boot_ec || boot_ec->handlers_installed) |
| 908 | return 0; |
| 909 | if (!ec_install_handlers(boot_ec)) { |
| 910 | first_ec = boot_ec; |
| 911 | return 0; |
| 912 | } |
| 913 | return -EFAULT; |
| 914 | } |
| 915 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 916 | int __init acpi_ec_ecdt_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 918 | int ret; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 919 | acpi_status status; |
| 920 | struct acpi_table_ecdt *ecdt_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 922 | boot_ec = make_acpi_ec(); |
| 923 | if (!boot_ec) |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 924 | return -ENOMEM; |
| 925 | /* |
| 926 | * Generate a boot ec context |
| 927 | */ |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 928 | status = acpi_get_table(ACPI_SIG_ECDT, 1, |
| 929 | (struct acpi_table_header **)&ecdt_ptr); |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 930 | if (ACPI_SUCCESS(status)) { |
Márton Németh | 3ebe08a | 2007-11-21 03:23:26 +0300 | [diff] [blame] | 931 | pr_info(PREFIX "EC description table is found, configuring boot EC\n"); |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 932 | boot_ec->command_addr = ecdt_ptr->control.address; |
| 933 | boot_ec->data_addr = ecdt_ptr->data.address; |
| 934 | boot_ec->gpe = ecdt_ptr->gpe; |
| 935 | boot_ec->handle = ACPI_ROOT_OBJECT; |
| 936 | } else { |
Alexey Starikovskiy | 5870a8c | 2007-11-15 21:52:47 +0300 | [diff] [blame] | 937 | /* This workaround is needed only on some broken machines, |
| 938 | * which require early EC, but fail to provide ECDT */ |
| 939 | acpi_handle x; |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 940 | printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); |
| 941 | status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, |
| 942 | boot_ec, NULL); |
Alexey Starikovskiy | 2d8348b | 2007-08-31 09:05:26 +0400 | [diff] [blame] | 943 | /* Check that acpi_get_devices actually find something */ |
| 944 | if (ACPI_FAILURE(status) || !boot_ec->handle) |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 945 | goto error; |
Alexey Starikovskiy | 5870a8c | 2007-11-15 21:52:47 +0300 | [diff] [blame] | 946 | /* We really need to limit this workaround, the only ASUS, |
| 947 | * which needs it, has fake EC._INI method, so use it as flag. |
Alexey Starikovskiy | c04209a | 2008-01-01 14:12:55 -0500 | [diff] [blame] | 948 | * Keep boot_ec struct as it will be needed soon. |
Alexey Starikovskiy | 5870a8c | 2007-11-15 21:52:47 +0300 | [diff] [blame] | 949 | */ |
| 950 | if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x))) |
Alexey Starikovskiy | c04209a | 2008-01-01 14:12:55 -0500 | [diff] [blame] | 951 | return -ENODEV; |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 954 | ret = ec_install_handlers(boot_ec); |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 955 | if (!ret) { |
| 956 | first_ec = boot_ec; |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 957 | return 0; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 958 | } |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 959 | error: |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 960 | kfree(boot_ec); |
| 961 | boot_ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | return -ENODEV; |
| 963 | } |
| 964 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 965 | static int __init acpi_ec_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 967 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 970 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
| 972 | acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); |
| 973 | if (!acpi_ec_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 974 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | /* Now register the driver for the EC */ |
| 977 | result = acpi_bus_register_driver(&acpi_ec_driver); |
| 978 | if (result < 0) { |
| 979 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 980 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 983 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | subsys_initcall(acpi_ec_init); |
| 987 | |
| 988 | /* EC driver currently not unloadable */ |
| 989 | #if 0 |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 990 | static void __exit acpi_ec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
| 993 | acpi_bus_unregister_driver(&acpi_ec_driver); |
| 994 | |
| 995 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 996 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 997 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | } |
Alexey Starikovskiy | 7843932 | 2007-10-22 14:18:43 +0400 | [diff] [blame] | 999 | #endif /* 0 */ |