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