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