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