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