Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $) |
| 3 | * |
| 4 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 23 | * |
| 24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/proc_fs.h> |
| 33 | #include <linux/seq_file.h> |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/io.h> |
| 36 | #include <acpi/acpi_bus.h> |
| 37 | #include <acpi/acpi_drivers.h> |
| 38 | #include <acpi/actypes.h> |
| 39 | |
| 40 | #define _COMPONENT ACPI_EC_COMPONENT |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 41 | ACPI_MODULE_NAME("acpi_ec") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define ACPI_EC_COMPONENT 0x00100000 |
| 43 | #define ACPI_EC_CLASS "embedded_controller" |
| 44 | #define ACPI_EC_HID "PNP0C09" |
| 45 | #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" |
| 46 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" |
| 47 | #define ACPI_EC_FILE_INFO "info" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
| 49 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 50 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */ |
| 53 | #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 54 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 56 | #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ |
| 57 | #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #define ACPI_EC_COMMAND_READ 0x80 |
| 59 | #define ACPI_EC_COMMAND_WRITE 0x81 |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 60 | #define ACPI_EC_BURST_ENABLE 0x82 |
| 61 | #define ACPI_EC_BURST_DISABLE 0x83 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define ACPI_EC_COMMAND_QUERY 0x84 |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 63 | #define EC_POLL 0xFF |
| 64 | #define EC_INTR 0x00 |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 65 | static int acpi_ec_remove(struct acpi_device *device, int type); |
| 66 | static int acpi_ec_start(struct acpi_device *device); |
| 67 | static int acpi_ec_stop(struct acpi_device *device, int type); |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 68 | static int acpi_ec_intr_add(struct acpi_device *device); |
| 69 | static int acpi_ec_poll_add(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | static struct acpi_driver acpi_ec_driver = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 72 | .name = ACPI_EC_DRIVER_NAME, |
| 73 | .class = ACPI_EC_CLASS, |
| 74 | .ids = ACPI_EC_HID, |
| 75 | .ops = { |
Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 76 | .add = acpi_ec_intr_add, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 77 | .remove = acpi_ec_remove, |
| 78 | .start = acpi_ec_start, |
| 79 | .stop = acpi_ec_stop, |
| 80 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | }; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 82 | union acpi_ec { |
| 83 | struct { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 84 | u32 mode; |
| 85 | acpi_handle handle; |
| 86 | unsigned long uid; |
| 87 | unsigned long gpe_bit; |
| 88 | struct acpi_generic_address status_addr; |
| 89 | struct acpi_generic_address command_addr; |
| 90 | struct acpi_generic_address data_addr; |
| 91 | unsigned long global_lock; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 92 | } common; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 94 | struct { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 95 | u32 mode; |
| 96 | acpi_handle handle; |
| 97 | unsigned long uid; |
| 98 | unsigned long gpe_bit; |
| 99 | struct acpi_generic_address status_addr; |
| 100 | struct acpi_generic_address command_addr; |
| 101 | struct acpi_generic_address data_addr; |
| 102 | unsigned long global_lock; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 103 | u8 expect_event; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 104 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ |
| 105 | atomic_t pending_gpe; |
| 106 | struct semaphore sem; |
| 107 | wait_queue_head_t wait; |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 108 | } intr; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 109 | |
| 110 | struct { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 111 | u32 mode; |
| 112 | acpi_handle handle; |
| 113 | unsigned long uid; |
| 114 | unsigned long gpe_bit; |
| 115 | struct acpi_generic_address status_addr; |
| 116 | struct acpi_generic_address command_addr; |
| 117 | struct acpi_generic_address data_addr; |
| 118 | unsigned long global_lock; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 119 | struct semaphore sem; |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 120 | } poll; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 123 | static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 124 | static int acpi_ec_intr_wait(union acpi_ec *ec, u8 event); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 125 | static int acpi_ec_poll_transaction(union acpi_ec *ec, u8 command, |
| 126 | const u8 *wdata, unsigned wdata_len, |
| 127 | u8 *rdata, unsigned rdata_len); |
| 128 | static int acpi_ec_intr_transaction(union acpi_ec *ec, u8 command, |
| 129 | const u8 *wdata, unsigned wdata_len, |
| 130 | u8 *rdata, unsigned rdata_len); |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 131 | static void acpi_ec_gpe_poll_query(void *ec_cxt); |
| 132 | static void acpi_ec_gpe_intr_query(void *ec_cxt); |
| 133 | static u32 acpi_ec_gpe_poll_handler(void *data); |
| 134 | static u32 acpi_ec_gpe_intr_handler(void *data); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 135 | static acpi_status __init |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 136 | acpi_fake_ecdt_poll_callback(acpi_handle handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 137 | u32 Level, void *context, void **retval); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 138 | |
| 139 | static acpi_status __init |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 140 | acpi_fake_ecdt_intr_callback(acpi_handle handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 141 | u32 Level, void *context, void **retval); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 142 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 143 | static int __init acpi_ec_poll_get_real_ecdt(void); |
| 144 | static int __init acpi_ec_intr_get_real_ecdt(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 146 | static union acpi_ec *ec_ecdt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* External interfaces use first EC only, so remember */ |
| 149 | static struct acpi_device *first_ec; |
Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 150 | static int acpi_ec_poll_mode = EC_INTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* -------------------------------------------------------------------------- |
| 153 | Transaction Management |
| 154 | -------------------------------------------------------------------------- */ |
| 155 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 156 | static u32 acpi_ec_read_status(union acpi_ec *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 158 | u32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 160 | acpi_hw_low_level_read(8, &status, &ec->common.status_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 161 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 164 | static int acpi_ec_check_status(u32 status, u8 event) { |
| 165 | |
| 166 | switch (event) { |
| 167 | case ACPI_EC_EVENT_OBF: |
| 168 | if (status & ACPI_EC_FLAG_OBF) |
| 169 | return 1; |
| 170 | case ACPI_EC_EVENT_IBE: |
| 171 | if (!(status & ACPI_EC_FLAG_IBF)) |
| 172 | return 1; |
| 173 | default: |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 180 | static int acpi_ec_wait(union acpi_ec *ec, u8 event) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 181 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 182 | if (acpi_ec_poll_mode) |
| 183 | return acpi_ec_poll_wait(ec, event); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 184 | else |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 185 | return acpi_ec_intr_wait(ec, event); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 186 | } |
| 187 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 188 | static int acpi_ec_poll_wait(union acpi_ec *ec, u8 event) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 189 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 190 | u32 acpi_ec_status = 0; |
| 191 | u32 i = ACPI_EC_UDELAY_COUNT; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 192 | |
| 193 | if (!ec) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | /* Poll the EC status register waiting for the event to occur. */ |
| 197 | switch (event) { |
| 198 | case ACPI_EC_EVENT_OBF: |
| 199 | do { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 200 | acpi_hw_low_level_read(8, &acpi_ec_status, |
| 201 | &ec->common.status_addr); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 202 | if (acpi_ec_status & ACPI_EC_FLAG_OBF) |
| 203 | return 0; |
| 204 | udelay(ACPI_EC_UDELAY); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 205 | } while (--i > 0); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 206 | break; |
| 207 | case ACPI_EC_EVENT_IBE: |
| 208 | do { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 209 | acpi_hw_low_level_read(8, &acpi_ec_status, |
| 210 | &ec->common.status_addr); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 211 | if (!(acpi_ec_status & ACPI_EC_FLAG_IBF)) |
| 212 | return 0; |
| 213 | udelay(ACPI_EC_UDELAY); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 214 | } while (--i > 0); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 215 | break; |
| 216 | default: |
| 217 | return -EINVAL; |
| 218 | } |
| 219 | |
| 220 | return -ETIME; |
| 221 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 222 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 223 | static int acpi_ec_intr_wait(union acpi_ec *ec, u8 event) |
| 224 | { |
| 225 | long time_left; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 226 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 227 | ec->intr.expect_event = event; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 228 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 229 | if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 230 | ec->intr.expect_event = 0; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 231 | return 0; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 232 | } |
| 233 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 234 | time_left = wait_event_timeout(ec->intr.wait, !ec->intr.expect_event, |
| 235 | msecs_to_jiffies(ACPI_EC_DELAY)); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 236 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 237 | ec->intr.expect_event = 0; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 238 | if (time_left <= 0) { |
| 239 | if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { |
| 240 | return 0; |
| 241 | } |
| 242 | } else { |
| 243 | return 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 244 | } |
| 245 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 246 | return -ETIME; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 247 | } |
| 248 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 249 | #ifdef ACPI_FUTURE_USAGE |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 250 | /* |
| 251 | * Note: samsung nv5000 doesn't work with ec burst mode. |
| 252 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 |
| 253 | */ |
| 254 | int acpi_ec_enter_burst_mode(union acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 255 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 256 | u32 tmp = 0; |
| 257 | int status = 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 258 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 259 | |
| 260 | status = acpi_ec_read_status(ec); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 261 | if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 262 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 263 | if (status) |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 264 | goto end; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 265 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, |
| 266 | &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 267 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 268 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 269 | if (tmp != 0x90) { /* Burst ACK byte */ |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 270 | return -EINVAL; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 271 | } |
Luming Yu | 668d74c | 2005-07-23 00:26:33 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 274 | atomic_set(&ec->intr.leaving_burst, 0); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 275 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 276 | end: |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 277 | ACPI_EXCEPTION ((AE_INFO, status, "EC wait, burst mode"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 278 | return -1; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 279 | } |
| 280 | |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 281 | int acpi_ec_leave_burst_mode(union acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 282 | { |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 283 | int status = 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 284 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 285 | |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 286 | status = acpi_ec_read_status(ec); |
| 287 | if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ |
| 288 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); |
| 289 | if(status) |
| 290 | goto end; |
| 291 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr); |
| 292 | acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 293 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 294 | atomic_set(&ec->intr.leaving_burst, 1); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 295 | return 0; |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 296 | end: |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 297 | ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 298 | return -1; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 299 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 300 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 302 | static int acpi_ec_transaction(union acpi_ec *ec, u8 command, |
| 303 | const u8 *wdata, unsigned wdata_len, |
| 304 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 305 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 306 | if (acpi_ec_poll_mode) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 307 | return acpi_ec_poll_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 308 | else |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 309 | return acpi_ec_intr_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
| 310 | } |
| 311 | static int acpi_ec_read(union acpi_ec *ec, u8 address, u32 * data) |
| 312 | { |
| 313 | int result; |
| 314 | u8 d; |
| 315 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, &address, 1, &d, 1); |
| 316 | *data = d; |
| 317 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 318 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 319 | static int acpi_ec_write(union acpi_ec *ec, u8 address, u8 data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 320 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 321 | u8 wdata[2] = { address, data }; |
| 322 | return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, wdata, 2, NULL, 0); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 323 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 324 | |
| 325 | static int acpi_ec_transaction_unlocked(union acpi_ec *ec, u8 command, |
| 326 | const u8 *wdata, unsigned wdata_len, |
| 327 | u8 *rdata, unsigned rdata_len) |
| 328 | { |
| 329 | int result; |
| 330 | |
| 331 | acpi_hw_low_level_write(8, command, &ec->common.command_addr); |
| 332 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 333 | for (; wdata_len > 0; wdata_len --) { |
| 334 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 335 | if (result) |
| 336 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 337 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 338 | acpi_hw_low_level_write(8, *(wdata++), &ec->common.data_addr); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 341 | if (command == ACPI_EC_COMMAND_WRITE) { |
| 342 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 343 | if (result) |
| 344 | return result; |
| 345 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 346 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 347 | for (; rdata_len > 0; rdata_len --) { |
| 348 | u32 d; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 349 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 350 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 351 | if (result) |
| 352 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 353 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 354 | acpi_hw_low_level_read(8, &d, &ec->common.data_addr); |
| 355 | *(rdata++) = (u8) d; |
| 356 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 357 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 358 | return 0; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static int acpi_ec_poll_transaction(union acpi_ec *ec, u8 command, |
| 362 | const u8 *wdata, unsigned wdata_len, |
| 363 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 364 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 365 | acpi_status status = AE_OK; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 366 | int result; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 367 | u32 glk = 0; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 368 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 369 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 370 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 371 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 372 | if (rdata) |
| 373 | memset(rdata, 0, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 374 | |
| 375 | if (ec->common.global_lock) { |
| 376 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 377 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 378 | return -ENODEV; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 379 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 380 | |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 381 | if (down_interruptible(&ec->poll.sem)) { |
| 382 | result = -ERESTARTSYS; |
| 383 | goto end_nosem; |
| 384 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 385 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 386 | result = acpi_ec_transaction_unlocked(ec, command, |
| 387 | wdata, wdata_len, |
| 388 | rdata, rdata_len); |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 389 | up(&ec->poll.sem); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 390 | |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 391 | end_nosem: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 392 | if (ec->common.global_lock) |
| 393 | acpi_release_global_lock(glk); |
| 394 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 395 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 398 | static int acpi_ec_intr_transaction(union acpi_ec *ec, u8 command, |
| 399 | const u8 *wdata, unsigned wdata_len, |
| 400 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 401 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 402 | int status; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 403 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 405 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 406 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 408 | if (rdata) |
| 409 | memset(rdata, 0, rdata_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 411 | if (ec->common.global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 413 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 414 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 416 | |
| 417 | WARN_ON(in_interrupt()); |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 418 | down(&ec->intr.sem); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 419 | |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 420 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 421 | if (status) { |
Len Brown | 1e8df53 | 2005-12-05 16:47:46 -0500 | [diff] [blame] | 422 | printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 423 | goto end; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 426 | status = acpi_ec_transaction_unlocked(ec, command, |
| 427 | wdata, wdata_len, |
| 428 | rdata, rdata_len); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 429 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 430 | end: |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 431 | up(&ec->intr.sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 433 | if (ec->common.global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | acpi_release_global_lock(glk); |
| 435 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 436 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Externally callable EC access functions. For now, assume 1 EC only |
| 441 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 442 | int ec_read(u8 addr, u8 * val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 444 | union acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | int err; |
| 446 | u32 temp_data; |
| 447 | |
| 448 | if (!first_ec) |
| 449 | return -ENODEV; |
| 450 | |
| 451 | ec = acpi_driver_data(first_ec); |
| 452 | |
| 453 | err = acpi_ec_read(ec, addr, &temp_data); |
| 454 | |
| 455 | if (!err) { |
| 456 | *val = temp_data; |
| 457 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 458 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return err; |
| 460 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | EXPORT_SYMBOL(ec_read); |
| 463 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 464 | int ec_write(u8 addr, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 466 | union acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | int err; |
| 468 | |
| 469 | if (!first_ec) |
| 470 | return -ENODEV; |
| 471 | |
| 472 | ec = acpi_driver_data(first_ec); |
| 473 | |
| 474 | err = acpi_ec_write(ec, addr, val); |
| 475 | |
| 476 | return err; |
| 477 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | EXPORT_SYMBOL(ec_write); |
| 480 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 481 | extern int ec_transaction(u8 command, |
| 482 | const u8 *wdata, unsigned wdata_len, |
| 483 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 484 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 485 | union acpi_ec *ec; |
| 486 | |
| 487 | if (!first_ec) |
| 488 | return -ENODEV; |
| 489 | |
| 490 | ec = acpi_driver_data(first_ec); |
| 491 | |
| 492 | return acpi_ec_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 493 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 494 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 495 | EXPORT_SYMBOL(ec_transaction); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 496 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 497 | static int acpi_ec_query(union acpi_ec *ec, u32 * data) { |
| 498 | int result; |
| 499 | u8 d; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 500 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 501 | if (!ec || !data) |
| 502 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 503 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 504 | /* |
| 505 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 506 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 507 | * bit to be cleared (and thus clearing the interrupt source). |
| 508 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 509 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 510 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); |
| 511 | if (result) |
| 512 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 513 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 514 | if (!d) |
| 515 | return -ENODATA; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 516 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 517 | *data = d; |
| 518 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* -------------------------------------------------------------------------- |
| 522 | Event Management |
| 523 | -------------------------------------------------------------------------- */ |
| 524 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 525 | union acpi_ec_query_data { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 526 | acpi_handle handle; |
| 527 | u8 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | }; |
| 529 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 530 | static void acpi_ec_gpe_query(void *ec_cxt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 532 | if (acpi_ec_poll_mode) |
| 533 | acpi_ec_gpe_poll_query(ec_cxt); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 534 | else |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 535 | acpi_ec_gpe_intr_query(ec_cxt); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 538 | static void acpi_ec_gpe_poll_query(void *ec_cxt) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 539 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 540 | union acpi_ec *ec = (union acpi_ec *)ec_cxt; |
| 541 | u32 value = 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 542 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; |
| 543 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', |
| 544 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
| 545 | }; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 546 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 547 | |
| 548 | if (!ec_cxt) |
| 549 | goto end; |
| 550 | |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 551 | if (down_interruptible (&ec->poll.sem)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 552 | return; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 553 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 554 | acpi_hw_low_level_read(8, &value, &ec->common.command_addr); |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 555 | up(&ec->poll.sem); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 556 | |
| 557 | /* TBD: Implement asynch events! |
| 558 | * NOTE: All we care about are EC-SCI's. Other EC events are |
| 559 | * handled via polling (yuck!). This is because some systems |
| 560 | * treat EC-SCIs as level (versus EDGE!) triggered, preventing |
| 561 | * a purely interrupt-driven approach (grumble, grumble). |
| 562 | */ |
| 563 | if (!(value & ACPI_EC_FLAG_SCI)) |
| 564 | goto end; |
| 565 | |
| 566 | if (acpi_ec_query(ec, &value)) |
| 567 | goto end; |
| 568 | |
| 569 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 570 | object_name[3] = hex[(value & 0x0F)]; |
| 571 | |
| 572 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 573 | |
| 574 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
| 575 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 576 | end: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 577 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
| 578 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 579 | static void acpi_ec_gpe_intr_query(void *ec_cxt) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 580 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 581 | union acpi_ec *ec = (union acpi_ec *)ec_cxt; |
| 582 | u32 value; |
| 583 | int result = -ENODATA; |
| 584 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; |
| 585 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', |
| 586 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
| 587 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 590 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) |
| 591 | result = acpi_ec_query(ec, &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 593 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | goto end; |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 597 | object_name[3] = hex[(value & 0x0F)]; |
| 598 | |
| 599 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 600 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 601 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 602 | end: |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 603 | atomic_dec(&ec->intr.pending_gpe); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 604 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 607 | static u32 acpi_ec_gpe_handler(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 609 | if (acpi_ec_poll_mode) |
| 610 | return acpi_ec_gpe_poll_handler(data); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 611 | else |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 612 | return acpi_ec_gpe_intr_handler(data); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 613 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 614 | static u32 acpi_ec_gpe_poll_handler(void *data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 615 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 616 | acpi_status status = AE_OK; |
| 617 | union acpi_ec *ec = (union acpi_ec *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | if (!ec) |
| 620 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 621 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 622 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
| 623 | |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 624 | status = acpi_os_execute(OSL_EC_POLL_HANDLER, acpi_ec_gpe_query, ec); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 625 | |
| 626 | if (status == AE_OK) |
| 627 | return ACPI_INTERRUPT_HANDLED; |
| 628 | else |
| 629 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 630 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 631 | static u32 acpi_ec_gpe_intr_handler(void *data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 632 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 633 | acpi_status status = AE_OK; |
| 634 | u32 value; |
| 635 | union acpi_ec *ec = (union acpi_ec *)data; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 636 | |
| 637 | if (!ec) |
| 638 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 639 | |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 640 | acpi_clear_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 641 | value = acpi_ec_read_status(ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 643 | switch (ec->intr.expect_event) { |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 644 | case ACPI_EC_EVENT_OBF: |
| 645 | if (!(value & ACPI_EC_FLAG_OBF)) |
| 646 | break; |
Vladimir Lebedev | 49fee981 | 2006-06-20 16:46:00 -0400 | [diff] [blame] | 647 | ec->intr.expect_event = 0; |
| 648 | wake_up(&ec->intr.wait); |
| 649 | break; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 650 | case ACPI_EC_EVENT_IBE: |
| 651 | if ((value & ACPI_EC_FLAG_IBF)) |
| 652 | break; |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 653 | ec->intr.expect_event = 0; |
| 654 | wake_up(&ec->intr.wait); |
Vladimir Lebedev | 49fee981 | 2006-06-20 16:46:00 -0400 | [diff] [blame] | 655 | break; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 656 | default: |
| 657 | break; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 660 | if (value & ACPI_EC_FLAG_SCI) { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 661 | atomic_add(1, &ec->intr.pending_gpe); |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 662 | status = acpi_os_execute(OSL_EC_BURST_HANDLER, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 663 | acpi_ec_gpe_query, ec); |
Luming Yu | 17e9c78 | 2005-04-22 23:07:10 -0400 | [diff] [blame] | 664 | return status == AE_OK ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 665 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
| 666 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 667 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 668 | return status == AE_OK ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 669 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /* -------------------------------------------------------------------------- |
| 673 | Address Space Management |
| 674 | -------------------------------------------------------------------------- */ |
| 675 | |
| 676 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 677 | acpi_ec_space_setup(acpi_handle region_handle, |
| 678 | u32 function, void *handler_context, void **return_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
| 680 | /* |
| 681 | * The EC object is in the handler context and is needed |
| 682 | * when calling the acpi_ec_space_handler. |
| 683 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 684 | *return_context = (function != ACPI_REGION_DEACTIVATE) ? |
| 685 | handler_context : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | return AE_OK; |
| 688 | } |
| 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 691 | acpi_ec_space_handler(u32 function, |
| 692 | acpi_physical_address address, |
| 693 | u32 bit_width, |
| 694 | acpi_integer * value, |
| 695 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 697 | int result = 0; |
| 698 | union acpi_ec *ec = NULL; |
| 699 | u64 temp = *value; |
| 700 | acpi_integer f_v = 0; |
| 701 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | if ((address > 0xFF) || !value || !handler_context) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 705 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 707 | if (bit_width != 8 && acpi_strict) { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 708 | printk(KERN_WARNING PREFIX |
| 709 | "acpi_ec_space_handler: bit_width should be 8\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 710 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 713 | ec = (union acpi_ec *)handler_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 715 | next_byte: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | switch (function) { |
| 717 | case ACPI_READ: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 718 | temp = 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 719 | result = acpi_ec_read(ec, (u8) address, (u32 *) & temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | break; |
| 721 | case ACPI_WRITE: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 722 | result = acpi_ec_write(ec, (u8) address, (u8) temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | break; |
| 724 | default: |
| 725 | result = -EINVAL; |
| 726 | goto out; |
| 727 | break; |
| 728 | } |
| 729 | |
| 730 | bit_width -= 8; |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 731 | if (bit_width) { |
| 732 | if (function == ACPI_READ) |
| 733 | f_v |= temp << 8 * i; |
| 734 | if (function == ACPI_WRITE) |
| 735 | temp >>= 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | i++; |
Andrew Morton | 83ea744 | 2005-03-30 22:12:13 -0500 | [diff] [blame] | 737 | address++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | goto next_byte; |
| 739 | } |
| 740 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 741 | if (function == ACPI_READ) { |
| 742 | f_v |= temp << 8 * i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | *value = f_v; |
| 744 | } |
| 745 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 746 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | switch (result) { |
| 748 | case -EINVAL: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 749 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | break; |
| 751 | case -ENODEV: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 752 | return AE_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | break; |
| 754 | case -ETIME: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 755 | return AE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | break; |
| 757 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 758 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | /* -------------------------------------------------------------------------- |
| 763 | FS Interface (/proc) |
| 764 | -------------------------------------------------------------------------- */ |
| 765 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 766 | static struct proc_dir_entry *acpi_ec_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 768 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 770 | union acpi_ec *ec = (union acpi_ec *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
| 773 | if (!ec) |
| 774 | goto end; |
| 775 | |
| 776 | seq_printf(seq, "gpe bit: 0x%02x\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 777 | (u32) ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 779 | (u32) ec->common.status_addr.address, |
| 780 | (u32) ec->common.data_addr.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | seq_printf(seq, "use global lock: %s\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 782 | ec->common.global_lock ? "yes" : "no"); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 783 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 785 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 786 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) |
| 790 | { |
| 791 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
| 792 | } |
| 793 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 794 | static const struct file_operations acpi_ec_info_ops = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 795 | .open = acpi_ec_info_open_fs, |
| 796 | .read = seq_read, |
| 797 | .llseek = seq_lseek, |
| 798 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | .owner = THIS_MODULE, |
| 800 | }; |
| 801 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 802 | static int acpi_ec_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 804 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | if (!acpi_device_dir(device)) { |
| 808 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 809 | acpi_ec_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 811 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 815 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 817 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | else { |
| 819 | entry->proc_fops = &acpi_ec_info_ops; |
| 820 | entry->data = acpi_driver_data(device); |
| 821 | entry->owner = THIS_MODULE; |
| 822 | } |
| 823 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 824 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 827 | static int acpi_ec_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | if (acpi_device_dir(device)) { |
| 831 | remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); |
| 832 | remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); |
| 833 | acpi_device_dir(device) = NULL; |
| 834 | } |
| 835 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 836 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | /* -------------------------------------------------------------------------- |
| 840 | Driver Interface |
| 841 | -------------------------------------------------------------------------- */ |
| 842 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 843 | static int acpi_ec_poll_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 845 | int result = 0; |
| 846 | acpi_status status = AE_OK; |
| 847 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 851 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 853 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 855 | return -ENOMEM; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 856 | memset(ec, 0, sizeof(union acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 858 | ec->common.handle = device->handle; |
| 859 | ec->common.uid = -1; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 860 | init_MUTEX(&ec->poll.sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 862 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 863 | acpi_driver_data(device) = ec; |
| 864 | |
| 865 | /* Use the global lock for all EC transactions? */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 866 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, |
| 867 | &ec->common.global_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Jiri Slaby | ff2fc3e | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 869 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: |
| 870 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ |
| 871 | if (ec_ecdt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 873 | ACPI_ADR_SPACE_EC, |
| 874 | &acpi_ec_space_handler); |
| 875 | |
| 876 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
| 877 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | kfree(ec_ecdt); |
| 880 | } |
| 881 | |
| 882 | /* Get GPE bit assignment (EC events). */ |
| 883 | /* TODO: Add support for _GPE returning a package */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 884 | status = |
| 885 | acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, |
| 886 | &ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 888 | ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | result = -ENODEV; |
| 890 | goto end; |
| 891 | } |
| 892 | |
| 893 | result = acpi_ec_add_fs(device); |
| 894 | if (result) |
| 895 | goto end; |
| 896 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 897 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d) polling mode.\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 898 | acpi_device_name(device), acpi_device_bid(device), |
| 899 | (u32) ec->common.gpe_bit); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 900 | |
| 901 | if (!first_ec) |
| 902 | first_ec = device; |
| 903 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 904 | end: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 905 | if (result) |
| 906 | kfree(ec); |
| 907 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 908 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 909 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 910 | static int acpi_ec_intr_add(struct acpi_device *device) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 911 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 912 | int result = 0; |
| 913 | acpi_status status = AE_OK; |
| 914 | union acpi_ec *ec = NULL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 915 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 916 | |
| 917 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 918 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 919 | |
| 920 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
| 921 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 922 | return -ENOMEM; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 923 | memset(ec, 0, sizeof(union acpi_ec)); |
| 924 | |
| 925 | ec->common.handle = device->handle; |
| 926 | ec->common.uid = -1; |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 927 | atomic_set(&ec->intr.pending_gpe, 0); |
| 928 | atomic_set(&ec->intr.leaving_burst, 1); |
| 929 | init_MUTEX(&ec->intr.sem); |
| 930 | init_waitqueue_head(&ec->intr.wait); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 931 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 932 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 933 | acpi_driver_data(device) = ec; |
| 934 | |
| 935 | /* Use the global lock for all EC transactions? */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 936 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, |
| 937 | &ec->common.global_lock); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 938 | |
Jiri Slaby | ff2fc3e | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 939 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: |
| 940 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ |
| 941 | if (ec_ecdt) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 942 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 943 | ACPI_ADR_SPACE_EC, |
| 944 | &acpi_ec_space_handler); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 945 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 946 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
| 947 | &acpi_ec_gpe_handler); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 948 | |
| 949 | kfree(ec_ecdt); |
| 950 | } |
| 951 | |
| 952 | /* Get GPE bit assignment (EC events). */ |
| 953 | /* TODO: Add support for _GPE returning a package */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 954 | status = |
| 955 | acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, |
| 956 | &ec->common.gpe_bit); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 957 | if (ACPI_FAILURE(status)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 958 | printk(KERN_ERR PREFIX "Obtaining GPE bit assignment\n"); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 959 | result = -ENODEV; |
| 960 | goto end; |
| 961 | } |
| 962 | |
| 963 | result = acpi_ec_add_fs(device); |
| 964 | if (result) |
| 965 | goto end; |
| 966 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 967 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d) interrupt mode.\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 968 | acpi_device_name(device), acpi_device_bid(device), |
| 969 | (u32) ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | if (!first_ec) |
| 972 | first_ec = device; |
| 973 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 974 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | if (result) |
| 976 | kfree(ec); |
| 977 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 978 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 981 | static int acpi_ec_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 983 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
| 986 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 987 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
| 989 | ec = acpi_driver_data(device); |
| 990 | |
| 991 | acpi_ec_remove_fs(device); |
| 992 | |
| 993 | kfree(ec); |
| 994 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 995 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 999 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1001 | union acpi_ec *ec = (union acpi_ec *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | struct acpi_generic_address *addr; |
| 1003 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 1004 | if (resource->type != ACPI_RESOURCE_TYPE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | return AE_OK; |
| 1006 | } |
| 1007 | |
| 1008 | /* |
| 1009 | * The first address region returned is the data port, and |
| 1010 | * the second address region returned is the status/command |
| 1011 | * port. |
| 1012 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1013 | if (ec->common.data_addr.register_bit_width == 0) { |
| 1014 | addr = &ec->common.data_addr; |
| 1015 | } else if (ec->common.command_addr.register_bit_width == 0) { |
| 1016 | addr = &ec->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } else { |
| 1018 | return AE_CTRL_TERMINATE; |
| 1019 | } |
| 1020 | |
| 1021 | addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
| 1022 | addr->register_bit_width = 8; |
| 1023 | addr->register_bit_offset = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 1024 | addr->address = resource->data.io.minimum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | return AE_OK; |
| 1027 | } |
| 1028 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1029 | static int acpi_ec_start(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1031 | acpi_status status = AE_OK; |
| 1032 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
| 1035 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1036 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | ec = acpi_driver_data(device); |
| 1039 | |
| 1040 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1041 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
| 1043 | /* |
| 1044 | * Get I/O port addresses. Convert to GAS format. |
| 1045 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1046 | status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1047 | acpi_ec_io_ports, ec); |
| 1048 | if (ACPI_FAILURE(status) |
| 1049 | || ec->common.command_addr.register_bit_width == 0) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 1050 | printk(KERN_ERR PREFIX "Error getting I/O port addresses\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1051 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1054 | ec->common.status_addr = ec->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
| 1056 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1057 | (u32) ec->common.gpe_bit, |
| 1058 | (u32) ec->common.command_addr.address, |
| 1059 | (u32) ec->common.data_addr.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
| 1061 | /* |
| 1062 | * Install GPE handler |
| 1063 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1064 | status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1065 | ACPI_GPE_EDGE_TRIGGERED, |
| 1066 | &acpi_ec_gpe_handler, ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | if (ACPI_FAILURE(status)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1068 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1070 | acpi_set_gpe_type(NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 1071 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1073 | status = acpi_install_address_space_handler(ec->common.handle, |
| 1074 | ACPI_ADR_SPACE_EC, |
| 1075 | &acpi_ec_space_handler, |
| 1076 | &acpi_ec_space_setup, ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | if (ACPI_FAILURE(status)) { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1078 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, |
| 1079 | &acpi_ec_gpe_handler); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1080 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1083 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1086 | static int acpi_ec_stop(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1088 | acpi_status status = AE_OK; |
| 1089 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
| 1092 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1093 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | ec = acpi_driver_data(device); |
| 1096 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1097 | status = acpi_remove_address_space_handler(ec->common.handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1098 | ACPI_ADR_SPACE_EC, |
| 1099 | &acpi_ec_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1101 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1103 | status = |
| 1104 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, |
| 1105 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1107 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1109 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | static acpi_status __init |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1113 | acpi_fake_ecdt_callback(acpi_handle handle, |
| 1114 | u32 Level, void *context, void **retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1116 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1117 | if (acpi_ec_poll_mode) |
| 1118 | return acpi_fake_ecdt_poll_callback(handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1119 | Level, context, retval); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1120 | else |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1121 | return acpi_fake_ecdt_intr_callback(handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1122 | Level, context, retval); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | static acpi_status __init |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1126 | acpi_fake_ecdt_poll_callback(acpi_handle handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1127 | u32 Level, void *context, void **retval) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1128 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1129 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
| 1131 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1132 | acpi_ec_io_ports, ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | if (ACPI_FAILURE(status)) |
| 1134 | return status; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1135 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1137 | ec_ecdt->common.uid = -1; |
| 1138 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1140 | status = |
| 1141 | acpi_evaluate_integer(handle, "_GPE", NULL, |
| 1142 | &ec_ecdt->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | if (ACPI_FAILURE(status)) |
| 1144 | return status; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 1145 | init_MUTEX(&ec_ecdt->poll.sem); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1146 | ec_ecdt->common.global_lock = TRUE; |
| 1147 | ec_ecdt->common.handle = handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1149 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
| 1150 | (u32) ec_ecdt->common.gpe_bit, |
| 1151 | (u32) ec_ecdt->common.command_addr.address, |
| 1152 | (u32) ec_ecdt->common.data_addr.address); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1153 | |
| 1154 | return AE_CTRL_TERMINATE; |
| 1155 | } |
| 1156 | |
| 1157 | static acpi_status __init |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1158 | acpi_fake_ecdt_intr_callback(acpi_handle handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1159 | u32 Level, void *context, void **retval) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1160 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1161 | acpi_status status; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1162 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1163 | init_MUTEX(&ec_ecdt->intr.sem); |
| 1164 | init_waitqueue_head(&ec_ecdt->intr.wait); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1165 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1166 | acpi_ec_io_ports, ec_ecdt); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1167 | if (ACPI_FAILURE(status)) |
| 1168 | return status; |
| 1169 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
| 1170 | |
| 1171 | ec_ecdt->common.uid = -1; |
| 1172 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
| 1173 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1174 | status = |
| 1175 | acpi_evaluate_integer(handle, "_GPE", NULL, |
| 1176 | &ec_ecdt->common.gpe_bit); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1177 | if (ACPI_FAILURE(status)) |
| 1178 | return status; |
| 1179 | ec_ecdt->common.global_lock = TRUE; |
| 1180 | ec_ecdt->common.handle = handle; |
| 1181 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1182 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
| 1183 | (u32) ec_ecdt->common.gpe_bit, |
| 1184 | (u32) ec_ecdt->common.command_addr.address, |
| 1185 | (u32) ec_ecdt->common.data_addr.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | return AE_CTRL_TERMINATE; |
| 1188 | } |
| 1189 | |
| 1190 | /* |
| 1191 | * Some BIOS (such as some from Gateway laptops) access EC region very early |
| 1192 | * such as in BAT0._INI or EC._INI before an EC device is found and |
| 1193 | * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily |
| 1194 | * required, but if EC regison is accessed early, it is required. |
| 1195 | * The routine tries to workaround the BIOS bug by pre-scan EC device |
| 1196 | * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any |
| 1197 | * op region (since _REG isn't invoked yet). The assumption is true for |
| 1198 | * all systems found. |
| 1199 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1200 | static int __init acpi_ec_fake_ecdt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1202 | acpi_status status; |
| 1203 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
| 1205 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); |
| 1206 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1207 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | if (!ec_ecdt) { |
| 1209 | ret = -ENOMEM; |
| 1210 | goto error; |
| 1211 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1212 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1214 | status = acpi_get_devices(ACPI_EC_HID, |
| 1215 | acpi_fake_ecdt_callback, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | if (ACPI_FAILURE(status)) { |
| 1217 | kfree(ec_ecdt); |
| 1218 | ec_ecdt = NULL; |
| 1219 | ret = -ENODEV; |
| 1220 | goto error; |
| 1221 | } |
| 1222 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1223 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | printk(KERN_ERR PREFIX "Can't make an fake ECDT\n"); |
| 1225 | return ret; |
| 1226 | } |
| 1227 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1228 | static int __init acpi_ec_get_real_ecdt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1230 | if (acpi_ec_poll_mode) |
| 1231 | return acpi_ec_poll_get_real_ecdt(); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1232 | else |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1233 | return acpi_ec_intr_get_real_ecdt(); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1234 | } |
| 1235 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1236 | static int __init acpi_ec_poll_get_real_ecdt(void) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1237 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1238 | acpi_status status; |
| 1239 | struct acpi_table_ecdt *ecdt_ptr; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1240 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1241 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, |
| 1242 | (struct acpi_table_header **) |
| 1243 | &ecdt_ptr); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1244 | if (ACPI_FAILURE(status)) |
| 1245 | return -ENODEV; |
| 1246 | |
| 1247 | printk(KERN_INFO PREFIX "Found ECDT\n"); |
| 1248 | |
| 1249 | /* |
| 1250 | * Generate a temporary ec context to use until the namespace is scanned |
| 1251 | */ |
| 1252 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
| 1253 | if (!ec_ecdt) |
| 1254 | return -ENOMEM; |
| 1255 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
| 1256 | |
| 1257 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
| 1258 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
| 1259 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
| 1260 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 1261 | init_MUTEX(&ec_ecdt->poll.sem); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1262 | /* use the GL just to be safe */ |
| 1263 | ec_ecdt->common.global_lock = TRUE; |
| 1264 | ec_ecdt->common.uid = ecdt_ptr->uid; |
| 1265 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1266 | status = |
| 1267 | acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1268 | if (ACPI_FAILURE(status)) { |
| 1269 | goto error; |
| 1270 | } |
| 1271 | |
| 1272 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1273 | error: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1274 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1275 | kfree(ec_ecdt); |
| 1276 | ec_ecdt = NULL; |
| 1277 | |
| 1278 | return -ENODEV; |
| 1279 | } |
| 1280 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1281 | static int __init acpi_ec_intr_get_real_ecdt(void) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1282 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1283 | acpi_status status; |
| 1284 | struct acpi_table_ecdt *ecdt_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 1286 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1287 | (struct acpi_table_header **) |
| 1288 | &ecdt_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | if (ACPI_FAILURE(status)) |
| 1290 | return -ENODEV; |
| 1291 | |
| 1292 | printk(KERN_INFO PREFIX "Found ECDT\n"); |
| 1293 | |
| 1294 | /* |
| 1295 | * Generate a temporary ec context to use until the namespace is scanned |
| 1296 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1297 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | if (!ec_ecdt) |
| 1299 | return -ENOMEM; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1300 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1302 | init_MUTEX(&ec_ecdt->intr.sem); |
| 1303 | init_waitqueue_head(&ec_ecdt->intr.wait); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1304 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
| 1305 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
| 1306 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
| 1307 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | /* use the GL just to be safe */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1309 | ec_ecdt->common.global_lock = TRUE; |
| 1310 | ec_ecdt->common.uid = ecdt_ptr->uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1312 | status = |
| 1313 | acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | if (ACPI_FAILURE(status)) { |
| 1315 | goto error; |
| 1316 | } |
| 1317 | |
| 1318 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1319 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1321 | kfree(ec_ecdt); |
| 1322 | ec_ecdt = NULL; |
| 1323 | |
| 1324 | return -ENODEV; |
| 1325 | } |
| 1326 | |
| 1327 | static int __initdata acpi_fake_ecdt_enabled; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1328 | int __init acpi_ec_ecdt_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1330 | acpi_status status; |
| 1331 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
| 1333 | ret = acpi_ec_get_real_ecdt(); |
| 1334 | /* Try to make a fake ECDT */ |
| 1335 | if (ret && acpi_fake_ecdt_enabled) { |
| 1336 | ret = acpi_ec_fake_ecdt(); |
| 1337 | } |
| 1338 | |
| 1339 | if (ret) |
| 1340 | return 0; |
| 1341 | |
| 1342 | /* |
| 1343 | * Install GPE handler |
| 1344 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1345 | status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1346 | ACPI_GPE_EDGE_TRIGGERED, |
| 1347 | &acpi_ec_gpe_handler, ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | if (ACPI_FAILURE(status)) { |
| 1349 | goto error; |
| 1350 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1351 | acpi_set_gpe_type(NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 1352 | acpi_enable_gpe(NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1354 | status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, |
| 1355 | ACPI_ADR_SPACE_EC, |
| 1356 | &acpi_ec_space_handler, |
| 1357 | &acpi_ec_space_setup, |
| 1358 | ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | if (ACPI_FAILURE(status)) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1360 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1361 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | goto error; |
| 1363 | } |
| 1364 | |
| 1365 | return 0; |
| 1366 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1367 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1369 | kfree(ec_ecdt); |
| 1370 | ec_ecdt = NULL; |
| 1371 | |
| 1372 | return -ENODEV; |
| 1373 | } |
| 1374 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1375 | static int __init acpi_ec_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1377 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
| 1380 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1381 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
| 1383 | acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); |
| 1384 | if (!acpi_ec_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1385 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
| 1387 | /* Now register the driver for the EC */ |
| 1388 | result = acpi_bus_register_driver(&acpi_ec_driver); |
| 1389 | if (result < 0) { |
| 1390 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1391 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1394 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | subsys_initcall(acpi_ec_init); |
| 1398 | |
| 1399 | /* EC driver currently not unloadable */ |
| 1400 | #if 0 |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1401 | static void __exit acpi_ec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
| 1404 | acpi_bus_unregister_driver(&acpi_ec_driver); |
| 1405 | |
| 1406 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 1407 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1408 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1410 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
| 1412 | static int __init acpi_fake_ecdt_setup(char *str) |
| 1413 | { |
| 1414 | acpi_fake_ecdt_enabled = 1; |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1415 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1419 | static int __init acpi_ec_set_intr_mode(char *str) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1420 | { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1421 | int intr; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1422 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1423 | if (!get_option(&str, &intr)) |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1424 | return 0; |
| 1425 | |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1426 | if (intr) { |
| 1427 | acpi_ec_poll_mode = EC_INTR; |
| 1428 | acpi_ec_driver.ops.add = acpi_ec_intr_add; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1429 | } else { |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1430 | acpi_ec_poll_mode = EC_POLL; |
| 1431 | acpi_ec_driver.ops.add = acpi_ec_poll_add; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1432 | } |
Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1433 | printk(KERN_INFO PREFIX "EC %s mode.\n", intr ? "interrupt" : "polling"); |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1434 | return 1; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1435 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1436 | |
Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 1437 | __setup("ec_intr=", acpi_ec_set_intr_mode); |