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 |
| 41 | ACPI_MODULE_NAME ("acpi_ec") |
| 42 | |
| 43 | #define ACPI_EC_COMPONENT 0x00100000 |
| 44 | #define ACPI_EC_CLASS "embedded_controller" |
| 45 | #define ACPI_EC_HID "PNP0C09" |
| 46 | #define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" |
| 47 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" |
| 48 | #define ACPI_EC_FILE_INFO "info" |
| 49 | |
| 50 | |
| 51 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
| 52 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 53 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
| 55 | |
| 56 | #define ACPI_EC_EVENT_OBF 0x01 /* Output buffer full */ |
| 57 | #define ACPI_EC_EVENT_IBE 0x02 /* Input buffer empty */ |
| 58 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 59 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
| 61 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 62 | #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ |
| 63 | #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */ |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define ACPI_EC_COMMAND_READ 0x80 |
| 66 | #define ACPI_EC_COMMAND_WRITE 0x81 |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 67 | #define ACPI_EC_BURST_ENABLE 0x82 |
| 68 | #define ACPI_EC_BURST_DISABLE 0x83 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define ACPI_EC_COMMAND_QUERY 0x84 |
| 70 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 71 | #define EC_POLLING 0xFF |
| 72 | #define EC_BURST 0x00 |
| 73 | |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static int acpi_ec_remove (struct acpi_device *device, int type); |
| 76 | static int acpi_ec_start (struct acpi_device *device); |
| 77 | static int acpi_ec_stop (struct acpi_device *device, int type); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 78 | static int acpi_ec_burst_add ( struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | static struct acpi_driver acpi_ec_driver = { |
| 81 | .name = ACPI_EC_DRIVER_NAME, |
| 82 | .class = ACPI_EC_CLASS, |
| 83 | .ids = ACPI_EC_HID, |
| 84 | .ops = { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 85 | .add = acpi_ec_burst_add, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .remove = acpi_ec_remove, |
| 87 | .start = acpi_ec_start, |
| 88 | .stop = acpi_ec_stop, |
| 89 | }, |
| 90 | }; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 91 | union acpi_ec { |
| 92 | struct { |
| 93 | u32 mode; |
| 94 | acpi_handle handle; |
| 95 | unsigned long uid; |
| 96 | unsigned long gpe_bit; |
| 97 | struct acpi_generic_address status_addr; |
| 98 | struct acpi_generic_address command_addr; |
| 99 | struct acpi_generic_address data_addr; |
| 100 | unsigned long global_lock; |
| 101 | } common; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 103 | struct { |
| 104 | u32 mode; |
| 105 | acpi_handle handle; |
| 106 | unsigned long uid; |
| 107 | unsigned long gpe_bit; |
| 108 | struct acpi_generic_address status_addr; |
| 109 | struct acpi_generic_address command_addr; |
| 110 | struct acpi_generic_address data_addr; |
| 111 | unsigned long global_lock; |
| 112 | unsigned int expect_event; |
| 113 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/ |
| 114 | atomic_t pending_gpe; |
| 115 | struct semaphore sem; |
| 116 | wait_queue_head_t wait; |
| 117 | }burst; |
| 118 | |
| 119 | struct { |
| 120 | u32 mode; |
| 121 | acpi_handle handle; |
| 122 | unsigned long uid; |
| 123 | unsigned long gpe_bit; |
| 124 | struct acpi_generic_address status_addr; |
| 125 | struct acpi_generic_address command_addr; |
| 126 | struct acpi_generic_address data_addr; |
| 127 | unsigned long global_lock; |
| 128 | spinlock_t lock; |
| 129 | }polling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 132 | static int acpi_ec_polling_wait ( union acpi_ec *ec, u8 event); |
| 133 | static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event); |
| 134 | static int acpi_ec_polling_read ( union acpi_ec *ec, u8 address, u32 *data); |
| 135 | static int acpi_ec_burst_read( union acpi_ec *ec, u8 address, u32 *data); |
| 136 | static int acpi_ec_polling_write ( union acpi_ec *ec, u8 address, u8 data); |
| 137 | static int acpi_ec_burst_write ( union acpi_ec *ec, u8 address, u8 data); |
| 138 | static int acpi_ec_polling_query ( union acpi_ec *ec, u32 *data); |
| 139 | static int acpi_ec_burst_query ( union acpi_ec *ec, u32 *data); |
| 140 | static void acpi_ec_gpe_polling_query ( void *ec_cxt); |
| 141 | static void acpi_ec_gpe_burst_query ( void *ec_cxt); |
| 142 | static u32 acpi_ec_gpe_polling_handler ( void *data); |
| 143 | static u32 acpi_ec_gpe_burst_handler ( void *data); |
| 144 | static acpi_status __init |
| 145 | acpi_fake_ecdt_polling_callback ( |
| 146 | acpi_handle handle, |
| 147 | u32 Level, |
| 148 | void *context, |
| 149 | void **retval); |
| 150 | |
| 151 | static acpi_status __init |
| 152 | acpi_fake_ecdt_burst_callback ( |
| 153 | acpi_handle handle, |
| 154 | u32 Level, |
| 155 | void *context, |
| 156 | void **retval); |
| 157 | |
| 158 | static int __init |
| 159 | acpi_ec_polling_get_real_ecdt(void); |
| 160 | static int __init |
| 161 | acpi_ec_burst_get_real_ecdt(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 163 | static union acpi_ec *ec_ecdt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | /* External interfaces use first EC only, so remember */ |
| 166 | static struct acpi_device *first_ec; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 167 | static int acpi_ec_polling_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /* -------------------------------------------------------------------------- |
| 170 | Transaction Management |
| 171 | -------------------------------------------------------------------------- */ |
| 172 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 173 | static inline u32 acpi_ec_read_status(union acpi_ec *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 175 | u32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 177 | acpi_hw_low_level_read(8, &status, &ec->common.status_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 178 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 181 | static int |
| 182 | acpi_ec_wait ( |
| 183 | union acpi_ec *ec, |
| 184 | u8 event) |
| 185 | { |
| 186 | if (acpi_ec_polling_mode) |
| 187 | return acpi_ec_polling_wait (ec, event); |
| 188 | else |
| 189 | return acpi_ec_burst_wait (ec, event); |
| 190 | } |
| 191 | |
| 192 | static int |
| 193 | acpi_ec_polling_wait ( |
| 194 | union acpi_ec *ec, |
| 195 | u8 event) |
| 196 | { |
| 197 | u32 acpi_ec_status = 0; |
| 198 | u32 i = ACPI_EC_UDELAY_COUNT; |
| 199 | |
| 200 | if (!ec) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | /* Poll the EC status register waiting for the event to occur. */ |
| 204 | switch (event) { |
| 205 | case ACPI_EC_EVENT_OBF: |
| 206 | do { |
| 207 | acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr); |
| 208 | if (acpi_ec_status & ACPI_EC_FLAG_OBF) |
| 209 | return 0; |
| 210 | udelay(ACPI_EC_UDELAY); |
| 211 | } while (--i>0); |
| 212 | break; |
| 213 | case ACPI_EC_EVENT_IBE: |
| 214 | do { |
| 215 | acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr); |
| 216 | if (!(acpi_ec_status & ACPI_EC_FLAG_IBF)) |
| 217 | return 0; |
| 218 | udelay(ACPI_EC_UDELAY); |
| 219 | } while (--i>0); |
| 220 | break; |
| 221 | default: |
| 222 | return -EINVAL; |
| 223 | } |
| 224 | |
| 225 | return -ETIME; |
| 226 | } |
| 227 | static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 228 | { |
| 229 | int result = 0; |
| 230 | |
| 231 | ACPI_FUNCTION_TRACE("acpi_ec_wait"); |
| 232 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 233 | ec->burst.expect_event = event; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 234 | smp_mb(); |
| 235 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 236 | result = wait_event_interruptible_timeout(ec->burst.wait, |
| 237 | !ec->burst.expect_event, |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 238 | msecs_to_jiffies(ACPI_EC_DELAY)); |
| 239 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 240 | ec->burst.expect_event = 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 241 | smp_mb(); |
| 242 | |
| 243 | if (result < 0){ |
| 244 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR," result = %d ", result)); |
| 245 | return_VALUE(result); |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Verify that the event in question has actually happened by |
| 250 | * querying EC status. Do the check even if operation timed-out |
| 251 | * to make sure that we did not miss interrupt. |
| 252 | */ |
| 253 | switch (event) { |
| 254 | case ACPI_EC_EVENT_OBF: |
| 255 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF) |
| 256 | return_VALUE(0); |
| 257 | break; |
| 258 | |
| 259 | case ACPI_EC_EVENT_IBE: |
| 260 | if (~acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) |
| 261 | return_VALUE(0); |
| 262 | break; |
| 263 | } |
| 264 | |
| 265 | return_VALUE(-ETIME); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | |
| 270 | static int |
| 271 | acpi_ec_enter_burst_mode ( |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 272 | union acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 273 | { |
| 274 | u32 tmp = 0; |
| 275 | int status = 0; |
| 276 | |
| 277 | ACPI_FUNCTION_TRACE("acpi_ec_enter_burst_mode"); |
| 278 | |
| 279 | status = acpi_ec_read_status(ec); |
| 280 | if (status != -EINVAL && |
| 281 | !(status & ACPI_EC_FLAG_BURST)){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 282 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 283 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 284 | if (status){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 285 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 286 | return_VALUE(-EINVAL); |
| 287 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 288 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
| 289 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 290 | if(tmp != 0x90 ) {/* Burst ACK byte*/ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 291 | return_VALUE(-EINVAL); |
| 292 | } |
Luming Yu | 668d74c | 2005-07-23 00:26:33 -0400 | [diff] [blame] | 293 | } |
| 294 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 295 | atomic_set(&ec->burst.leaving_burst , 0); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 296 | return_VALUE(0); |
| 297 | } |
| 298 | |
| 299 | static int |
| 300 | acpi_ec_leave_burst_mode ( |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 301 | union acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 302 | { |
| 303 | int status =0; |
| 304 | |
| 305 | ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); |
| 306 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 307 | atomic_set(&ec->burst.leaving_burst , 1); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 308 | status = acpi_ec_read_status(ec); |
| 309 | if (status != -EINVAL && |
| 310 | (status & ACPI_EC_FLAG_BURST)){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 311 | acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 312 | status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); |
| 313 | if (status){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 314 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 315 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); |
| 316 | return_VALUE(-EINVAL); |
| 317 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 318 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 319 | status = acpi_ec_read_status(ec); |
Luming Yu | 668d74c | 2005-07-23 00:26:33 -0400 | [diff] [blame] | 320 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 321 | |
| 322 | return_VALUE(0); |
| 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | static int |
| 326 | acpi_ec_read ( |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 327 | union acpi_ec *ec, |
| 328 | u8 address, |
| 329 | u32 *data) |
| 330 | { |
| 331 | if (acpi_ec_polling_mode) |
| 332 | return acpi_ec_polling_read(ec, address, data); |
| 333 | else |
| 334 | return acpi_ec_burst_read(ec, address, data); |
| 335 | } |
| 336 | static int |
| 337 | acpi_ec_write ( |
| 338 | union acpi_ec *ec, |
| 339 | u8 address, |
| 340 | u8 data) |
| 341 | { |
| 342 | if (acpi_ec_polling_mode) |
| 343 | return acpi_ec_polling_write(ec, address, data); |
| 344 | else |
| 345 | return acpi_ec_burst_write(ec, address, data); |
| 346 | } |
| 347 | static int |
| 348 | acpi_ec_polling_read ( |
| 349 | union acpi_ec *ec, |
| 350 | u8 address, |
| 351 | u32 *data) |
| 352 | { |
| 353 | acpi_status status = AE_OK; |
| 354 | int result = 0; |
| 355 | unsigned long flags = 0; |
| 356 | u32 glk = 0; |
| 357 | |
| 358 | ACPI_FUNCTION_TRACE("acpi_ec_read"); |
| 359 | |
| 360 | if (!ec || !data) |
| 361 | return_VALUE(-EINVAL); |
| 362 | |
| 363 | *data = 0; |
| 364 | |
| 365 | if (ec->common.global_lock) { |
| 366 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 367 | if (ACPI_FAILURE(status)) |
| 368 | return_VALUE(-ENODEV); |
| 369 | } |
| 370 | |
| 371 | spin_lock_irqsave(&ec->polling.lock, flags); |
| 372 | |
| 373 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr); |
| 374 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 375 | if (result) |
| 376 | goto end; |
| 377 | |
| 378 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
| 379 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 380 | if (result) |
| 381 | goto end; |
| 382 | |
| 383 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
| 384 | |
| 385 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", |
| 386 | *data, address)); |
| 387 | |
| 388 | end: |
| 389 | spin_unlock_irqrestore(&ec->polling.lock, flags); |
| 390 | |
| 391 | if (ec->common.global_lock) |
| 392 | acpi_release_global_lock(glk); |
| 393 | |
| 394 | return_VALUE(result); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | static int |
| 399 | acpi_ec_polling_write ( |
| 400 | union acpi_ec *ec, |
| 401 | u8 address, |
| 402 | u8 data) |
| 403 | { |
| 404 | int result = 0; |
| 405 | acpi_status status = AE_OK; |
| 406 | unsigned long flags = 0; |
| 407 | u32 glk = 0; |
| 408 | |
| 409 | ACPI_FUNCTION_TRACE("acpi_ec_write"); |
| 410 | |
| 411 | if (!ec) |
| 412 | return_VALUE(-EINVAL); |
| 413 | |
| 414 | if (ec->common.global_lock) { |
| 415 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 416 | if (ACPI_FAILURE(status)) |
| 417 | return_VALUE(-ENODEV); |
| 418 | } |
| 419 | |
| 420 | spin_lock_irqsave(&ec->polling.lock, flags); |
| 421 | |
| 422 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr); |
| 423 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 424 | if (result) |
| 425 | goto end; |
| 426 | |
| 427 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
| 428 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 429 | if (result) |
| 430 | goto end; |
| 431 | |
| 432 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); |
| 433 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 434 | if (result) |
| 435 | goto end; |
| 436 | |
| 437 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", |
| 438 | data, address)); |
| 439 | |
| 440 | end: |
| 441 | spin_unlock_irqrestore(&ec->polling.lock, flags); |
| 442 | |
| 443 | if (ec->common.global_lock) |
| 444 | acpi_release_global_lock(glk); |
| 445 | |
| 446 | return_VALUE(result); |
| 447 | } |
| 448 | |
| 449 | static int |
| 450 | acpi_ec_burst_read ( |
| 451 | union acpi_ec *ec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | u8 address, |
| 453 | u32 *data) |
| 454 | { |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 455 | int status = 0; |
| 456 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | ACPI_FUNCTION_TRACE("acpi_ec_read"); |
| 459 | |
| 460 | if (!ec || !data) |
| 461 | return_VALUE(-EINVAL); |
| 462 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 463 | retry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | *data = 0; |
| 465 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 466 | if (ec->common.global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 468 | if (ACPI_FAILURE(status)) |
| 469 | return_VALUE(-ENODEV); |
| 470 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 471 | |
| 472 | WARN_ON(in_interrupt()); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 473 | down(&ec->burst.sem); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 474 | |
| 475 | if(acpi_ec_enter_burst_mode(ec)) |
| 476 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 478 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 479 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 480 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 481 | if (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | goto end; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 485 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 486 | status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 487 | if (status){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 488 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | goto end; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 492 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
| 493 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", |
| 496 | *data, address)); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | end: |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 499 | acpi_ec_leave_burst_mode(ec); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 500 | up(&ec->burst.sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 502 | if (ec->common.global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | acpi_release_global_lock(glk); |
| 504 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 505 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 506 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 507 | while(atomic_read(&ec->burst.pending_gpe)){ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 508 | msleep(1); |
| 509 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 510 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 511 | goto retry; |
| 512 | } |
| 513 | |
| 514 | return_VALUE(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | |
| 518 | static int |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 519 | acpi_ec_burst_write ( |
| 520 | union acpi_ec *ec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | u8 address, |
| 522 | u8 data) |
| 523 | { |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 524 | int status = 0; |
| 525 | u32 glk; |
| 526 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | ACPI_FUNCTION_TRACE("acpi_ec_write"); |
| 529 | |
| 530 | if (!ec) |
| 531 | return_VALUE(-EINVAL); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 532 | retry: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 533 | if (ec->common.global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 535 | if (ACPI_FAILURE(status)) |
| 536 | return_VALUE(-ENODEV); |
| 537 | } |
| 538 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 539 | WARN_ON(in_interrupt()); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 540 | down(&ec->burst.sem); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 541 | |
| 542 | if(acpi_ec_enter_burst_mode(ec)) |
| 543 | goto end; |
| 544 | |
| 545 | status = acpi_ec_read_status(ec); |
| 546 | if (status != -EINVAL && |
| 547 | !(status & ACPI_EC_FLAG_BURST)){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 548 | acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 549 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 550 | if (status) |
| 551 | goto end; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 552 | acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 553 | if(tmp != 0x90 ) /* Burst ACK byte*/ |
| 554 | goto end; |
| 555 | } |
| 556 | /*Now we are in burst mode*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 558 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 559 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 560 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 561 | if (status){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | goto end; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 565 | acpi_hw_low_level_write(8, address, &ec->common.data_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 566 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
| 567 | if (status){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 568 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | goto end; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 572 | acpi_hw_low_level_write(8, data, &ec->common.data_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 573 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 574 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 575 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | goto end; |
| 577 | |
| 578 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n", |
| 579 | data, address)); |
| 580 | |
| 581 | end: |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 582 | acpi_ec_leave_burst_mode(ec); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 583 | up(&ec->burst.sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 585 | if (ec->common.global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | acpi_release_global_lock(glk); |
| 587 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 588 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 589 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 590 | while(atomic_read(&ec->burst.pending_gpe)){ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 591 | msleep(1); |
| 592 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 593 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 594 | goto retry; |
| 595 | } |
| 596 | |
| 597 | return_VALUE(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* |
| 601 | * Externally callable EC access functions. For now, assume 1 EC only |
| 602 | */ |
| 603 | int |
| 604 | ec_read(u8 addr, u8 *val) |
| 605 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 606 | union acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | int err; |
| 608 | u32 temp_data; |
| 609 | |
| 610 | if (!first_ec) |
| 611 | return -ENODEV; |
| 612 | |
| 613 | ec = acpi_driver_data(first_ec); |
| 614 | |
| 615 | err = acpi_ec_read(ec, addr, &temp_data); |
| 616 | |
| 617 | if (!err) { |
| 618 | *val = temp_data; |
| 619 | return 0; |
| 620 | } |
| 621 | else |
| 622 | return err; |
| 623 | } |
| 624 | EXPORT_SYMBOL(ec_read); |
| 625 | |
| 626 | int |
| 627 | ec_write(u8 addr, u8 val) |
| 628 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 629 | union acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | int err; |
| 631 | |
| 632 | if (!first_ec) |
| 633 | return -ENODEV; |
| 634 | |
| 635 | ec = acpi_driver_data(first_ec); |
| 636 | |
| 637 | err = acpi_ec_write(ec, addr, val); |
| 638 | |
| 639 | return err; |
| 640 | } |
| 641 | EXPORT_SYMBOL(ec_write); |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | static int |
| 644 | acpi_ec_query ( |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 645 | union acpi_ec *ec, |
| 646 | u32 *data) |
| 647 | { |
| 648 | if (acpi_ec_polling_mode) |
| 649 | return acpi_ec_polling_query(ec, data); |
| 650 | else |
| 651 | return acpi_ec_burst_query(ec, data); |
| 652 | } |
| 653 | static int |
| 654 | acpi_ec_polling_query ( |
| 655 | union acpi_ec *ec, |
| 656 | u32 *data) |
| 657 | { |
| 658 | int result = 0; |
| 659 | acpi_status status = AE_OK; |
| 660 | unsigned long flags = 0; |
| 661 | u32 glk = 0; |
| 662 | |
| 663 | ACPI_FUNCTION_TRACE("acpi_ec_query"); |
| 664 | |
| 665 | if (!ec || !data) |
| 666 | return_VALUE(-EINVAL); |
| 667 | |
| 668 | *data = 0; |
| 669 | |
| 670 | if (ec->common.global_lock) { |
| 671 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 672 | if (ACPI_FAILURE(status)) |
| 673 | return_VALUE(-ENODEV); |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 678 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 679 | * bit to be cleared (and thus clearing the interrupt source). |
| 680 | */ |
| 681 | spin_lock_irqsave(&ec->polling.lock, flags); |
| 682 | |
| 683 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr); |
| 684 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 685 | if (result) |
| 686 | goto end; |
| 687 | |
| 688 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
| 689 | if (!*data) |
| 690 | result = -ENODATA; |
| 691 | |
| 692 | end: |
| 693 | spin_unlock_irqrestore(&ec->polling.lock, flags); |
| 694 | |
| 695 | if (ec->common.global_lock) |
| 696 | acpi_release_global_lock(glk); |
| 697 | |
| 698 | return_VALUE(result); |
| 699 | } |
| 700 | static int |
| 701 | acpi_ec_burst_query ( |
| 702 | union acpi_ec *ec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | u32 *data) |
| 704 | { |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 705 | int status = 0; |
| 706 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | ACPI_FUNCTION_TRACE("acpi_ec_query"); |
| 709 | |
| 710 | if (!ec || !data) |
| 711 | return_VALUE(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | *data = 0; |
| 713 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 714 | if (ec->common.global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 716 | if (ACPI_FAILURE(status)) |
| 717 | return_VALUE(-ENODEV); |
| 718 | } |
| 719 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 720 | down(&ec->burst.sem); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 721 | if(acpi_ec_enter_burst_mode(ec)) |
| 722 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* |
| 724 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 725 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 726 | * bit to be cleared (and thus clearing the interrupt source). |
| 727 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 728 | acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 729 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); |
| 730 | if (status){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 731 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | goto end; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 733 | } |
| 734 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 735 | acpi_hw_low_level_read(8, data, &ec->common.data_addr); |
| 736 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | if (!*data) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 738 | status = -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
| 740 | end: |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 741 | acpi_ec_leave_burst_mode(ec); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 742 | up(&ec->burst.sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 744 | if (ec->common.global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | acpi_release_global_lock(glk); |
| 746 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 747 | if(atomic_read(&ec->burst.leaving_burst) == 2){ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 748 | ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 749 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Luming Yu | 17e9c78 | 2005-04-22 23:07:10 -0400 | [diff] [blame] | 750 | status = -ENODATA; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 751 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 752 | return_VALUE(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | |
| 756 | /* -------------------------------------------------------------------------- |
| 757 | Event Management |
| 758 | -------------------------------------------------------------------------- */ |
| 759 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 760 | union acpi_ec_query_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | acpi_handle handle; |
| 762 | u8 data; |
| 763 | }; |
| 764 | |
| 765 | static void |
| 766 | acpi_ec_gpe_query ( |
| 767 | void *ec_cxt) |
| 768 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 769 | if (acpi_ec_polling_mode) |
| 770 | acpi_ec_gpe_polling_query(ec_cxt); |
| 771 | else |
| 772 | acpi_ec_gpe_burst_query(ec_cxt); |
| 773 | } |
| 774 | |
| 775 | static void |
| 776 | acpi_ec_gpe_polling_query ( |
| 777 | void *ec_cxt) |
| 778 | { |
| 779 | union acpi_ec *ec = (union acpi_ec *) ec_cxt; |
| 780 | u32 value = 0; |
| 781 | unsigned long flags = 0; |
| 782 | static char object_name[5] = {'_','Q','0','0','\0'}; |
| 783 | const char hex[] = {'0','1','2','3','4','5','6','7', |
| 784 | '8','9','A','B','C','D','E','F'}; |
| 785 | |
| 786 | ACPI_FUNCTION_TRACE("acpi_ec_gpe_query"); |
| 787 | |
| 788 | if (!ec_cxt) |
| 789 | goto end; |
| 790 | |
| 791 | spin_lock_irqsave(&ec->polling.lock, flags); |
| 792 | acpi_hw_low_level_read(8, &value, &ec->common.command_addr); |
| 793 | spin_unlock_irqrestore(&ec->polling.lock, flags); |
| 794 | |
| 795 | /* TBD: Implement asynch events! |
| 796 | * NOTE: All we care about are EC-SCI's. Other EC events are |
| 797 | * handled via polling (yuck!). This is because some systems |
| 798 | * treat EC-SCIs as level (versus EDGE!) triggered, preventing |
| 799 | * a purely interrupt-driven approach (grumble, grumble). |
| 800 | */ |
| 801 | if (!(value & ACPI_EC_FLAG_SCI)) |
| 802 | goto end; |
| 803 | |
| 804 | if (acpi_ec_query(ec, &value)) |
| 805 | goto end; |
| 806 | |
| 807 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 808 | object_name[3] = hex[(value & 0x0F)]; |
| 809 | |
| 810 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 811 | |
| 812 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
| 813 | |
| 814 | end: |
| 815 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
| 816 | } |
| 817 | static void |
| 818 | acpi_ec_gpe_burst_query ( |
| 819 | void *ec_cxt) |
| 820 | { |
| 821 | union acpi_ec *ec = (union acpi_ec *) ec_cxt; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 822 | u32 value; |
| 823 | int result = -ENODATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | static char object_name[5] = {'_','Q','0','0','\0'}; |
| 825 | const char hex[] = {'0','1','2','3','4','5','6','7', |
| 826 | '8','9','A','B','C','D','E','F'}; |
| 827 | |
| 828 | ACPI_FUNCTION_TRACE("acpi_ec_gpe_query"); |
| 829 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 830 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) |
| 831 | result = acpi_ec_query(ec, &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 833 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | goto end; |
| 835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 837 | object_name[3] = hex[(value & 0x0F)]; |
| 838 | |
| 839 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 840 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 841 | acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 842 | end: |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 843 | atomic_dec(&ec->burst.pending_gpe); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 844 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static u32 |
| 848 | acpi_ec_gpe_handler ( |
| 849 | void *data) |
| 850 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 851 | if (acpi_ec_polling_mode) |
| 852 | return acpi_ec_gpe_polling_handler(data); |
| 853 | else |
| 854 | return acpi_ec_gpe_burst_handler(data); |
| 855 | } |
| 856 | static u32 |
| 857 | acpi_ec_gpe_polling_handler ( |
| 858 | void *data) |
| 859 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | acpi_status status = AE_OK; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 861 | union acpi_ec *ec = (union acpi_ec *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | if (!ec) |
| 864 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 865 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 866 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
| 867 | |
| 868 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, |
| 869 | acpi_ec_gpe_query, ec); |
| 870 | |
| 871 | if (status == AE_OK) |
| 872 | return ACPI_INTERRUPT_HANDLED; |
| 873 | else |
| 874 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 875 | } |
| 876 | static u32 |
| 877 | acpi_ec_gpe_burst_handler ( |
| 878 | void *data) |
| 879 | { |
| 880 | acpi_status status = AE_OK; |
| 881 | u32 value; |
| 882 | union acpi_ec *ec = (union acpi_ec *) data; |
| 883 | |
| 884 | if (!ec) |
| 885 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 886 | |
| 887 | acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 889 | value = acpi_ec_read_status(ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 891 | if((value & ACPI_EC_FLAG_IBF) && |
| 892 | !(value & ACPI_EC_FLAG_BURST) && |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 893 | (atomic_read(&ec->burst.leaving_burst) == 0)) { |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 894 | /* |
| 895 | * the embedded controller disables |
| 896 | * burst mode for any reason other |
| 897 | * than the burst disable command |
| 898 | * to process critical event. |
| 899 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 900 | atomic_set(&ec->burst.leaving_burst , 2); /* block current pending transaction |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 901 | and retry */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 902 | wake_up(&ec->burst.wait); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 903 | }else { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 904 | if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF && |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 905 | (value & ACPI_EC_FLAG_OBF)) || |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 906 | (ec->burst.expect_event == ACPI_EC_EVENT_IBE && |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 907 | !(value & ACPI_EC_FLAG_IBF))) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 908 | ec->burst.expect_event = 0; |
| 909 | wake_up(&ec->burst.wait); |
Luming Yu | 17e9c78 | 2005-04-22 23:07:10 -0400 | [diff] [blame] | 910 | return ACPI_INTERRUPT_HANDLED; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
| 914 | if (value & ACPI_EC_FLAG_SCI){ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 915 | atomic_add(1, &ec->burst.pending_gpe) ; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 916 | status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, |
| 917 | acpi_ec_gpe_query, ec); |
Luming Yu | 17e9c78 | 2005-04-22 23:07:10 -0400 | [diff] [blame] | 918 | return status == AE_OK ? |
| 919 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 920 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 921 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 922 | return status == AE_OK ? |
| 923 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* -------------------------------------------------------------------------- |
| 927 | Address Space Management |
| 928 | -------------------------------------------------------------------------- */ |
| 929 | |
| 930 | static acpi_status |
| 931 | acpi_ec_space_setup ( |
| 932 | acpi_handle region_handle, |
| 933 | u32 function, |
| 934 | void *handler_context, |
| 935 | void **return_context) |
| 936 | { |
| 937 | /* |
| 938 | * The EC object is in the handler context and is needed |
| 939 | * when calling the acpi_ec_space_handler. |
| 940 | */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 941 | *return_context = (function != ACPI_REGION_DEACTIVATE) ? |
| 942 | handler_context : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
| 944 | return AE_OK; |
| 945 | } |
| 946 | |
| 947 | |
| 948 | static acpi_status |
| 949 | acpi_ec_space_handler ( |
| 950 | u32 function, |
| 951 | acpi_physical_address address, |
| 952 | u32 bit_width, |
| 953 | acpi_integer *value, |
| 954 | void *handler_context, |
| 955 | void *region_context) |
| 956 | { |
| 957 | int result = 0; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 958 | union acpi_ec *ec = NULL; |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 959 | u64 temp = *value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | acpi_integer f_v = 0; |
| 961 | int i = 0; |
| 962 | |
| 963 | ACPI_FUNCTION_TRACE("acpi_ec_space_handler"); |
| 964 | |
| 965 | if ((address > 0xFF) || !value || !handler_context) |
| 966 | return_VALUE(AE_BAD_PARAMETER); |
| 967 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 968 | if (bit_width != 8 && acpi_strict) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | printk(KERN_WARNING PREFIX "acpi_ec_space_handler: bit_width should be 8\n"); |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 970 | return_VALUE(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 973 | ec = (union acpi_ec *) handler_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | next_byte: |
| 976 | switch (function) { |
| 977 | case ACPI_READ: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 978 | temp = 0; |
| 979 | result = acpi_ec_read(ec, (u8) address, (u32 *)&temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | break; |
| 981 | case ACPI_WRITE: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 982 | result = acpi_ec_write(ec, (u8) address, (u8) temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | break; |
| 984 | default: |
| 985 | result = -EINVAL; |
| 986 | goto out; |
| 987 | break; |
| 988 | } |
| 989 | |
| 990 | bit_width -= 8; |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 991 | if (bit_width) { |
| 992 | if (function == ACPI_READ) |
| 993 | f_v |= temp << 8 * i; |
| 994 | if (function == ACPI_WRITE) |
| 995 | temp >>= 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | i++; |
Andrew Morton | 83ea744 | 2005-03-30 22:12:13 -0500 | [diff] [blame] | 997 | address++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | goto next_byte; |
| 999 | } |
| 1000 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 1001 | if (function == ACPI_READ) { |
| 1002 | f_v |= temp << 8 * i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | *value = f_v; |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | out: |
| 1008 | switch (result) { |
| 1009 | case -EINVAL: |
| 1010 | return_VALUE(AE_BAD_PARAMETER); |
| 1011 | break; |
| 1012 | case -ENODEV: |
| 1013 | return_VALUE(AE_NOT_FOUND); |
| 1014 | break; |
| 1015 | case -ETIME: |
| 1016 | return_VALUE(AE_TIME); |
| 1017 | break; |
| 1018 | default: |
| 1019 | return_VALUE(AE_OK); |
| 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | /* -------------------------------------------------------------------------- |
| 1025 | FS Interface (/proc) |
| 1026 | -------------------------------------------------------------------------- */ |
| 1027 | |
| 1028 | static struct proc_dir_entry *acpi_ec_dir; |
| 1029 | |
| 1030 | |
| 1031 | static int |
| 1032 | acpi_ec_read_info (struct seq_file *seq, void *offset) |
| 1033 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1034 | union acpi_ec *ec = (union acpi_ec *) seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
| 1036 | ACPI_FUNCTION_TRACE("acpi_ec_read_info"); |
| 1037 | |
| 1038 | if (!ec) |
| 1039 | goto end; |
| 1040 | |
| 1041 | seq_printf(seq, "gpe bit: 0x%02x\n", |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1042 | (u32) ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1044 | (u32) ec->common.status_addr.address, (u32) ec->common.data_addr.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | seq_printf(seq, "use global lock: %s\n", |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1046 | ec->common.global_lock?"yes":"no"); |
| 1047 | acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | end: |
| 1050 | return_VALUE(0); |
| 1051 | } |
| 1052 | |
| 1053 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) |
| 1054 | { |
| 1055 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
| 1056 | } |
| 1057 | |
| 1058 | static struct file_operations acpi_ec_info_ops = { |
| 1059 | .open = acpi_ec_info_open_fs, |
| 1060 | .read = seq_read, |
| 1061 | .llseek = seq_lseek, |
| 1062 | .release = single_release, |
| 1063 | .owner = THIS_MODULE, |
| 1064 | }; |
| 1065 | |
| 1066 | static int |
| 1067 | acpi_ec_add_fs ( |
| 1068 | struct acpi_device *device) |
| 1069 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1070 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); |
| 1073 | |
| 1074 | if (!acpi_device_dir(device)) { |
| 1075 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
| 1076 | acpi_ec_dir); |
| 1077 | if (!acpi_device_dir(device)) |
| 1078 | return_VALUE(-ENODEV); |
| 1079 | } |
| 1080 | |
| 1081 | entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, |
| 1082 | acpi_device_dir(device)); |
| 1083 | if (!entry) |
| 1084 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 1085 | "Unable to create '%s' fs entry\n", |
| 1086 | ACPI_EC_FILE_INFO)); |
| 1087 | else { |
| 1088 | entry->proc_fops = &acpi_ec_info_ops; |
| 1089 | entry->data = acpi_driver_data(device); |
| 1090 | entry->owner = THIS_MODULE; |
| 1091 | } |
| 1092 | |
| 1093 | return_VALUE(0); |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | static int |
| 1098 | acpi_ec_remove_fs ( |
| 1099 | struct acpi_device *device) |
| 1100 | { |
| 1101 | ACPI_FUNCTION_TRACE("acpi_ec_remove_fs"); |
| 1102 | |
| 1103 | if (acpi_device_dir(device)) { |
| 1104 | remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); |
| 1105 | remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); |
| 1106 | acpi_device_dir(device) = NULL; |
| 1107 | } |
| 1108 | |
| 1109 | return_VALUE(0); |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | /* -------------------------------------------------------------------------- |
| 1114 | Driver Interface |
| 1115 | -------------------------------------------------------------------------- */ |
| 1116 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | static int |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1119 | acpi_ec_polling_add ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | struct acpi_device *device) |
| 1121 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1122 | int result = 0; |
| 1123 | acpi_status status = AE_OK; |
| 1124 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | unsigned long uid; |
| 1126 | |
| 1127 | ACPI_FUNCTION_TRACE("acpi_ec_add"); |
| 1128 | |
| 1129 | if (!device) |
| 1130 | return_VALUE(-EINVAL); |
| 1131 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1132 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | if (!ec) |
| 1134 | return_VALUE(-ENOMEM); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1135 | memset(ec, 0, sizeof(union acpi_ec)); |
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->common.handle = device->handle; |
| 1138 | ec->common.uid = -1; |
| 1139 | spin_lock_init(&ec->polling.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 1141 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 1142 | acpi_driver_data(device) = ec; |
| 1143 | |
| 1144 | /* Use the global lock for all EC transactions? */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1145 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
| 1147 | /* If our UID matches the UID for the ECDT-enumerated EC, |
| 1148 | we now have the *real* EC info, so kill the makeshift one.*/ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1149 | acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid); |
| 1150 | if (ec_ecdt && ec_ecdt->common.uid == uid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
| 1152 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1153 | |
| 1154 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
| 1156 | kfree(ec_ecdt); |
| 1157 | } |
| 1158 | |
| 1159 | /* Get GPE bit assignment (EC events). */ |
| 1160 | /* TODO: Add support for _GPE returning a package */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1161 | status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | if (ACPI_FAILURE(status)) { |
| 1163 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 1164 | "Error obtaining GPE bit assignment\n")); |
| 1165 | result = -ENODEV; |
| 1166 | goto end; |
| 1167 | } |
| 1168 | |
| 1169 | result = acpi_ec_add_fs(device); |
| 1170 | if (result) |
| 1171 | goto end; |
| 1172 | |
| 1173 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", |
| 1174 | acpi_device_name(device), acpi_device_bid(device), |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1175 | (u32) ec->common.gpe_bit); |
| 1176 | |
| 1177 | if (!first_ec) |
| 1178 | first_ec = device; |
| 1179 | |
| 1180 | end: |
| 1181 | if (result) |
| 1182 | kfree(ec); |
| 1183 | |
| 1184 | return_VALUE(result); |
| 1185 | } |
| 1186 | static int |
| 1187 | acpi_ec_burst_add ( |
| 1188 | struct acpi_device *device) |
| 1189 | { |
| 1190 | int result = 0; |
| 1191 | acpi_status status = AE_OK; |
| 1192 | union acpi_ec *ec = NULL; |
| 1193 | unsigned long uid; |
| 1194 | |
| 1195 | ACPI_FUNCTION_TRACE("acpi_ec_add"); |
| 1196 | |
| 1197 | if (!device) |
| 1198 | return_VALUE(-EINVAL); |
| 1199 | |
| 1200 | ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
| 1201 | if (!ec) |
| 1202 | return_VALUE(-ENOMEM); |
| 1203 | memset(ec, 0, sizeof(union acpi_ec)); |
| 1204 | |
| 1205 | ec->common.handle = device->handle; |
| 1206 | ec->common.uid = -1; |
| 1207 | atomic_set(&ec->burst.pending_gpe, 0); |
| 1208 | atomic_set(&ec->burst.leaving_burst , 1); |
| 1209 | init_MUTEX(&ec->burst.sem); |
| 1210 | init_waitqueue_head(&ec->burst.wait); |
| 1211 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 1212 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 1213 | acpi_driver_data(device) = ec; |
| 1214 | |
| 1215 | /* Use the global lock for all EC transactions? */ |
| 1216 | acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock); |
| 1217 | |
| 1218 | /* If our UID matches the UID for the ECDT-enumerated EC, |
| 1219 | we now have the *real* EC info, so kill the makeshift one.*/ |
| 1220 | acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid); |
| 1221 | if (ec_ecdt && ec_ecdt->common.uid == uid) { |
| 1222 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
| 1223 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
| 1224 | |
| 1225 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler); |
| 1226 | |
| 1227 | kfree(ec_ecdt); |
| 1228 | } |
| 1229 | |
| 1230 | /* Get GPE bit assignment (EC events). */ |
| 1231 | /* TODO: Add support for _GPE returning a package */ |
| 1232 | status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit); |
| 1233 | if (ACPI_FAILURE(status)) { |
| 1234 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 1235 | "Error obtaining GPE bit assignment\n")); |
| 1236 | result = -ENODEV; |
| 1237 | goto end; |
| 1238 | } |
| 1239 | |
| 1240 | result = acpi_ec_add_fs(device); |
| 1241 | if (result) |
| 1242 | goto end; |
| 1243 | |
| 1244 | printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", |
| 1245 | acpi_device_name(device), acpi_device_bid(device), |
| 1246 | (u32) ec->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | if (!first_ec) |
| 1249 | first_ec = device; |
| 1250 | |
| 1251 | end: |
| 1252 | if (result) |
| 1253 | kfree(ec); |
| 1254 | |
| 1255 | return_VALUE(result); |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | static int |
| 1260 | acpi_ec_remove ( |
| 1261 | struct acpi_device *device, |
| 1262 | int type) |
| 1263 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1264 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | ACPI_FUNCTION_TRACE("acpi_ec_remove"); |
| 1267 | |
| 1268 | if (!device) |
| 1269 | return_VALUE(-EINVAL); |
| 1270 | |
| 1271 | ec = acpi_driver_data(device); |
| 1272 | |
| 1273 | acpi_ec_remove_fs(device); |
| 1274 | |
| 1275 | kfree(ec); |
| 1276 | |
| 1277 | return_VALUE(0); |
| 1278 | } |
| 1279 | |
| 1280 | |
| 1281 | static acpi_status |
| 1282 | acpi_ec_io_ports ( |
| 1283 | struct acpi_resource *resource, |
| 1284 | void *context) |
| 1285 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1286 | union acpi_ec *ec = (union acpi_ec *) context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | struct acpi_generic_address *addr; |
| 1288 | |
| 1289 | if (resource->id != ACPI_RSTYPE_IO) { |
| 1290 | return AE_OK; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * The first address region returned is the data port, and |
| 1295 | * the second address region returned is the status/command |
| 1296 | * port. |
| 1297 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1298 | if (ec->common.data_addr.register_bit_width == 0) { |
| 1299 | addr = &ec->common.data_addr; |
| 1300 | } else if (ec->common.command_addr.register_bit_width == 0) { |
| 1301 | addr = &ec->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } else { |
| 1303 | return AE_CTRL_TERMINATE; |
| 1304 | } |
| 1305 | |
| 1306 | addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
| 1307 | addr->register_bit_width = 8; |
| 1308 | addr->register_bit_offset = 0; |
| 1309 | addr->address = resource->data.io.min_base_address; |
| 1310 | |
| 1311 | return AE_OK; |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | static int |
| 1316 | acpi_ec_start ( |
| 1317 | struct acpi_device *device) |
| 1318 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1319 | acpi_status status = AE_OK; |
| 1320 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
| 1322 | ACPI_FUNCTION_TRACE("acpi_ec_start"); |
| 1323 | |
| 1324 | if (!device) |
| 1325 | return_VALUE(-EINVAL); |
| 1326 | |
| 1327 | ec = acpi_driver_data(device); |
| 1328 | |
| 1329 | if (!ec) |
| 1330 | return_VALUE(-EINVAL); |
| 1331 | |
| 1332 | /* |
| 1333 | * Get I/O port addresses. Convert to GAS format. |
| 1334 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1335 | status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | acpi_ec_io_ports, ec); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1337 | if (ACPI_FAILURE(status) || ec->common.command_addr.register_bit_width == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses")); |
| 1339 | return_VALUE(-ENODEV); |
| 1340 | } |
| 1341 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1342 | ec->common.status_addr = ec->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
| 1344 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1345 | (u32) ec->common.gpe_bit, (u32) ec->common.command_addr.address, |
| 1346 | (u32) ec->common.data_addr.address)); |
| 1347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* |
| 1350 | * Install GPE handler |
| 1351 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1352 | status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); |
| 1354 | if (ACPI_FAILURE(status)) { |
| 1355 | return_VALUE(-ENODEV); |
| 1356 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1357 | acpi_set_gpe_type (NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 1358 | acpi_enable_gpe (NULL, ec->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1360 | status = acpi_install_address_space_handler (ec->common.handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
| 1362 | &acpi_ec_space_setup, ec); |
| 1363 | if (ACPI_FAILURE(status)) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1364 | acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | return_VALUE(-ENODEV); |
| 1366 | } |
| 1367 | |
| 1368 | return_VALUE(AE_OK); |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | static int |
| 1373 | acpi_ec_stop ( |
| 1374 | struct acpi_device *device, |
| 1375 | int type) |
| 1376 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1377 | acpi_status status = AE_OK; |
| 1378 | union acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
| 1380 | ACPI_FUNCTION_TRACE("acpi_ec_stop"); |
| 1381 | |
| 1382 | if (!device) |
| 1383 | return_VALUE(-EINVAL); |
| 1384 | |
| 1385 | ec = acpi_driver_data(device); |
| 1386 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1387 | status = acpi_remove_address_space_handler(ec->common.handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); |
| 1389 | if (ACPI_FAILURE(status)) |
| 1390 | return_VALUE(-ENODEV); |
| 1391 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1392 | status = acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | if (ACPI_FAILURE(status)) |
| 1394 | return_VALUE(-ENODEV); |
| 1395 | |
| 1396 | return_VALUE(0); |
| 1397 | } |
| 1398 | |
| 1399 | static acpi_status __init |
| 1400 | acpi_fake_ecdt_callback ( |
| 1401 | acpi_handle handle, |
| 1402 | u32 Level, |
| 1403 | void *context, |
| 1404 | void **retval) |
| 1405 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1406 | |
| 1407 | if (acpi_ec_polling_mode) |
| 1408 | return acpi_fake_ecdt_polling_callback(handle, |
| 1409 | Level, context, retval); |
| 1410 | else |
| 1411 | return acpi_fake_ecdt_burst_callback(handle, |
| 1412 | Level, context, retval); |
| 1413 | } |
| 1414 | |
| 1415 | static acpi_status __init |
| 1416 | acpi_fake_ecdt_polling_callback ( |
| 1417 | acpi_handle handle, |
| 1418 | u32 Level, |
| 1419 | void *context, |
| 1420 | void **retval) |
| 1421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | acpi_status status; |
| 1423 | |
| 1424 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 1425 | acpi_ec_io_ports, ec_ecdt); |
| 1426 | if (ACPI_FAILURE(status)) |
| 1427 | return status; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1428 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1430 | ec_ecdt->common.uid = -1; |
| 1431 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1433 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | if (ACPI_FAILURE(status)) |
| 1435 | return status; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1436 | spin_lock_init(&ec_ecdt->polling.lock); |
| 1437 | ec_ecdt->common.global_lock = TRUE; |
| 1438 | ec_ecdt->common.handle = handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
| 1440 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1441 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, |
| 1442 | (u32) ec_ecdt->common.data_addr.address); |
| 1443 | |
| 1444 | return AE_CTRL_TERMINATE; |
| 1445 | } |
| 1446 | |
| 1447 | static acpi_status __init |
| 1448 | acpi_fake_ecdt_burst_callback ( |
| 1449 | acpi_handle handle, |
| 1450 | u32 Level, |
| 1451 | void *context, |
| 1452 | void **retval) |
| 1453 | { |
| 1454 | acpi_status status; |
| 1455 | |
| 1456 | init_MUTEX(&ec_ecdt->burst.sem); |
| 1457 | init_waitqueue_head(&ec_ecdt->burst.wait); |
| 1458 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 1459 | acpi_ec_io_ports, ec_ecdt); |
| 1460 | if (ACPI_FAILURE(status)) |
| 1461 | return status; |
| 1462 | ec_ecdt->common.status_addr = ec_ecdt->common.command_addr; |
| 1463 | |
| 1464 | ec_ecdt->common.uid = -1; |
| 1465 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid); |
| 1466 | |
| 1467 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit); |
| 1468 | if (ACPI_FAILURE(status)) |
| 1469 | return status; |
| 1470 | ec_ecdt->common.global_lock = TRUE; |
| 1471 | ec_ecdt->common.handle = handle; |
| 1472 | |
| 1473 | printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", |
| 1474 | (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address, |
| 1475 | (u32) ec_ecdt->common.data_addr.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
| 1477 | return AE_CTRL_TERMINATE; |
| 1478 | } |
| 1479 | |
| 1480 | /* |
| 1481 | * Some BIOS (such as some from Gateway laptops) access EC region very early |
| 1482 | * such as in BAT0._INI or EC._INI before an EC device is found and |
| 1483 | * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily |
| 1484 | * required, but if EC regison is accessed early, it is required. |
| 1485 | * The routine tries to workaround the BIOS bug by pre-scan EC device |
| 1486 | * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any |
| 1487 | * op region (since _REG isn't invoked yet). The assumption is true for |
| 1488 | * all systems found. |
| 1489 | */ |
| 1490 | static int __init |
| 1491 | acpi_ec_fake_ecdt(void) |
| 1492 | { |
| 1493 | acpi_status status; |
| 1494 | int ret = 0; |
| 1495 | |
| 1496 | printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); |
| 1497 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1498 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | if (!ec_ecdt) { |
| 1500 | ret = -ENOMEM; |
| 1501 | goto error; |
| 1502 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1503 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
| 1505 | status = acpi_get_devices (ACPI_EC_HID, |
| 1506 | acpi_fake_ecdt_callback, |
| 1507 | NULL, |
| 1508 | NULL); |
| 1509 | if (ACPI_FAILURE(status)) { |
| 1510 | kfree(ec_ecdt); |
| 1511 | ec_ecdt = NULL; |
| 1512 | ret = -ENODEV; |
| 1513 | goto error; |
| 1514 | } |
| 1515 | return 0; |
| 1516 | error: |
| 1517 | printk(KERN_ERR PREFIX "Can't make an fake ECDT\n"); |
| 1518 | return ret; |
| 1519 | } |
| 1520 | |
| 1521 | static int __init |
| 1522 | acpi_ec_get_real_ecdt(void) |
| 1523 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1524 | if (acpi_ec_polling_mode) |
| 1525 | return acpi_ec_polling_get_real_ecdt(); |
| 1526 | else |
| 1527 | return acpi_ec_burst_get_real_ecdt(); |
| 1528 | } |
| 1529 | |
| 1530 | static int __init |
| 1531 | acpi_ec_polling_get_real_ecdt(void) |
| 1532 | { |
| 1533 | acpi_status status; |
| 1534 | struct acpi_table_ecdt *ecdt_ptr; |
| 1535 | |
| 1536 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, |
| 1537 | (struct acpi_table_header **) &ecdt_ptr); |
| 1538 | if (ACPI_FAILURE(status)) |
| 1539 | return -ENODEV; |
| 1540 | |
| 1541 | printk(KERN_INFO PREFIX "Found ECDT\n"); |
| 1542 | |
| 1543 | /* |
| 1544 | * Generate a temporary ec context to use until the namespace is scanned |
| 1545 | */ |
| 1546 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
| 1547 | if (!ec_ecdt) |
| 1548 | return -ENOMEM; |
| 1549 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
| 1550 | |
| 1551 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
| 1552 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
| 1553 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
| 1554 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
| 1555 | spin_lock_init(&ec_ecdt->polling.lock); |
| 1556 | /* use the GL just to be safe */ |
| 1557 | ec_ecdt->common.global_lock = TRUE; |
| 1558 | ec_ecdt->common.uid = ecdt_ptr->uid; |
| 1559 | |
| 1560 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); |
| 1561 | if (ACPI_FAILURE(status)) { |
| 1562 | goto error; |
| 1563 | } |
| 1564 | |
| 1565 | return 0; |
| 1566 | error: |
| 1567 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1568 | kfree(ec_ecdt); |
| 1569 | ec_ecdt = NULL; |
| 1570 | |
| 1571 | return -ENODEV; |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | static int __init |
| 1576 | acpi_ec_burst_get_real_ecdt(void) |
| 1577 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | acpi_status status; |
| 1579 | struct acpi_table_ecdt *ecdt_ptr; |
| 1580 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 1581 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | (struct acpi_table_header **) &ecdt_ptr); |
| 1583 | if (ACPI_FAILURE(status)) |
| 1584 | return -ENODEV; |
| 1585 | |
| 1586 | printk(KERN_INFO PREFIX "Found ECDT\n"); |
| 1587 | |
| 1588 | /* |
| 1589 | * Generate a temporary ec context to use until the namespace is scanned |
| 1590 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1591 | ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | if (!ec_ecdt) |
| 1593 | return -ENOMEM; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1594 | memset(ec_ecdt, 0, sizeof(union acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1596 | init_MUTEX(&ec_ecdt->burst.sem); |
| 1597 | init_waitqueue_head(&ec_ecdt->burst.wait); |
| 1598 | ec_ecdt->common.command_addr = ecdt_ptr->ec_control; |
| 1599 | ec_ecdt->common.status_addr = ecdt_ptr->ec_control; |
| 1600 | ec_ecdt->common.data_addr = ecdt_ptr->ec_data; |
| 1601 | ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | /* use the GL just to be safe */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1603 | ec_ecdt->common.global_lock = TRUE; |
| 1604 | ec_ecdt->common.uid = ecdt_ptr->uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1606 | status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | if (ACPI_FAILURE(status)) { |
| 1608 | goto error; |
| 1609 | } |
| 1610 | |
| 1611 | return 0; |
| 1612 | error: |
| 1613 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1614 | kfree(ec_ecdt); |
| 1615 | ec_ecdt = NULL; |
| 1616 | |
| 1617 | return -ENODEV; |
| 1618 | } |
| 1619 | |
| 1620 | static int __initdata acpi_fake_ecdt_enabled; |
| 1621 | int __init |
| 1622 | acpi_ec_ecdt_probe (void) |
| 1623 | { |
| 1624 | acpi_status status; |
| 1625 | int ret; |
| 1626 | |
| 1627 | ret = acpi_ec_get_real_ecdt(); |
| 1628 | /* Try to make a fake ECDT */ |
| 1629 | if (ret && acpi_fake_ecdt_enabled) { |
| 1630 | ret = acpi_ec_fake_ecdt(); |
| 1631 | } |
| 1632 | |
| 1633 | if (ret) |
| 1634 | return 0; |
| 1635 | |
| 1636 | /* |
| 1637 | * Install GPE handler |
| 1638 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1639 | status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, |
| 1641 | ec_ecdt); |
| 1642 | if (ACPI_FAILURE(status)) { |
| 1643 | goto error; |
| 1644 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1645 | acpi_set_gpe_type (NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 1646 | acpi_enable_gpe (NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | |
| 1648 | status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, |
| 1649 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, |
| 1650 | &acpi_ec_space_setup, ec_ecdt); |
| 1651 | if (ACPI_FAILURE(status)) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1652 | acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | &acpi_ec_gpe_handler); |
| 1654 | goto error; |
| 1655 | } |
| 1656 | |
| 1657 | return 0; |
| 1658 | |
| 1659 | error: |
| 1660 | printk(KERN_ERR PREFIX "Could not use ECDT\n"); |
| 1661 | kfree(ec_ecdt); |
| 1662 | ec_ecdt = NULL; |
| 1663 | |
| 1664 | return -ENODEV; |
| 1665 | } |
| 1666 | |
| 1667 | |
| 1668 | static int __init acpi_ec_init (void) |
| 1669 | { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1670 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
| 1672 | ACPI_FUNCTION_TRACE("acpi_ec_init"); |
| 1673 | |
| 1674 | if (acpi_disabled) |
| 1675 | return_VALUE(0); |
| 1676 | |
| 1677 | acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); |
| 1678 | if (!acpi_ec_dir) |
| 1679 | return_VALUE(-ENODEV); |
| 1680 | |
| 1681 | /* Now register the driver for the EC */ |
| 1682 | result = acpi_bus_register_driver(&acpi_ec_driver); |
| 1683 | if (result < 0) { |
| 1684 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 1685 | return_VALUE(-ENODEV); |
| 1686 | } |
| 1687 | |
| 1688 | return_VALUE(result); |
| 1689 | } |
| 1690 | |
| 1691 | subsys_initcall(acpi_ec_init); |
| 1692 | |
| 1693 | /* EC driver currently not unloadable */ |
| 1694 | #if 0 |
| 1695 | static void __exit |
| 1696 | acpi_ec_exit (void) |
| 1697 | { |
| 1698 | ACPI_FUNCTION_TRACE("acpi_ec_exit"); |
| 1699 | |
| 1700 | acpi_bus_unregister_driver(&acpi_ec_driver); |
| 1701 | |
| 1702 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 1703 | |
| 1704 | return_VOID; |
| 1705 | } |
| 1706 | #endif /* 0 */ |
| 1707 | |
| 1708 | static int __init acpi_fake_ecdt_setup(char *str) |
| 1709 | { |
| 1710 | acpi_fake_ecdt_enabled = 1; |
| 1711 | return 0; |
| 1712 | } |
| 1713 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame^] | 1714 | static int __init acpi_ec_set_polling_mode(char *str) |
| 1715 | { |
| 1716 | acpi_ec_polling_mode = EC_POLLING; |
| 1717 | acpi_ec_driver.ops.add = acpi_ec_polling_add; |
| 1718 | return 0; |
| 1719 | } |
| 1720 | __setup("ec_polling", acpi_ec_set_polling_mode); |