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