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" |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 48 | |
| 49 | /* EC status register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
| 51 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 52 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 54 | |
| 55 | /* EC commands */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define ACPI_EC_COMMAND_READ 0x80 |
| 57 | #define ACPI_EC_COMMAND_WRITE 0x81 |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 58 | #define ACPI_EC_BURST_ENABLE 0x82 |
| 59 | #define ACPI_EC_BURST_DISABLE 0x83 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define ACPI_EC_COMMAND_QUERY 0x84 |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 61 | |
| 62 | /* EC events */ |
| 63 | enum { |
| 64 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ |
| 65 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ |
| 66 | }; |
| 67 | |
| 68 | #define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ |
| 69 | #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ |
| 70 | #define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */ |
| 71 | #define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */ |
| 72 | |
| 73 | enum { |
| 74 | EC_INTR = 1, /* Output buffer full */ |
| 75 | EC_POLL, /* Input buffer empty */ |
| 76 | }; |
| 77 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 78 | static int acpi_ec_remove(struct acpi_device *device, int type); |
| 79 | static int acpi_ec_start(struct acpi_device *device); |
| 80 | static int acpi_ec_stop(struct acpi_device *device, int type); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 81 | static int acpi_ec_add(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | static struct acpi_driver acpi_ec_driver = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 84 | .name = ACPI_EC_DRIVER_NAME, |
| 85 | .class = ACPI_EC_CLASS, |
| 86 | .ids = ACPI_EC_HID, |
| 87 | .ops = { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 88 | .add = acpi_ec_add, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 89 | .remove = acpi_ec_remove, |
| 90 | .start = acpi_ec_start, |
| 91 | .stop = acpi_ec_stop, |
| 92 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 94 | struct acpi_ec { |
| 95 | acpi_handle handle; |
| 96 | unsigned long uid; |
| 97 | unsigned long gpe_bit; |
| 98 | struct acpi_generic_address status_addr; |
| 99 | struct acpi_generic_address command_addr; |
| 100 | struct acpi_generic_address data_addr; |
| 101 | unsigned long global_lock; |
| 102 | struct semaphore sem; |
| 103 | unsigned int expect_event; |
| 104 | atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ |
| 105 | wait_queue_head_t wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 108 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
| 109 | static struct acpi_ec *ec_ecdt; |
| 110 | |
| 111 | /* External interfaces use first EC only, so remember */ |
| 112 | static struct acpi_device *first_ec; |
| 113 | static int acpi_ec_mode = EC_INTR; |
| 114 | |
| 115 | static int acpi_ec_poll_transaction(struct acpi_ec *ec, u8 command, |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 116 | const u8 *wdata, unsigned wdata_len, |
| 117 | u8 *rdata, unsigned rdata_len); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 118 | static int acpi_ec_intr_transaction(struct acpi_ec *ec, u8 command, |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 119 | const u8 *wdata, unsigned wdata_len, |
| 120 | u8 *rdata, unsigned rdata_len); |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 121 | static void acpi_ec_gpe_poll_query(void *ec_cxt); |
| 122 | static void acpi_ec_gpe_intr_query(void *ec_cxt); |
| 123 | static u32 acpi_ec_gpe_poll_handler(void *data); |
| 124 | static u32 acpi_ec_gpe_intr_handler(void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | /* -------------------------------------------------------------------------- |
| 127 | Transaction Management |
| 128 | -------------------------------------------------------------------------- */ |
| 129 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 130 | static u32 acpi_ec_read_status(struct acpi_ec *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 132 | u32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 134 | acpi_hw_low_level_read(8, &status, &ec->status_addr); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 135 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 138 | static u32 acpi_ec_read_data(struct acpi_ec *ec) |
| 139 | { |
| 140 | u32 data = 0; |
| 141 | |
| 142 | acpi_hw_low_level_read(8, &data, &ec->data_addr); |
| 143 | return data; |
| 144 | } |
| 145 | |
| 146 | static void acpi_ec_write_cmd(struct acpi_ec *ec, u32 command) |
| 147 | { |
| 148 | acpi_hw_low_level_write(8, command, &ec->command_addr); |
| 149 | } |
| 150 | |
| 151 | static void acpi_ec_write_data(struct acpi_ec *ec, u32 data) |
| 152 | { |
| 153 | acpi_hw_low_level_write(8, data, &ec->data_addr); |
| 154 | } |
| 155 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 156 | static int acpi_ec_check_status(u32 status, u8 event) { |
| 157 | |
| 158 | switch (event) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 159 | case ACPI_EC_EVENT_OBF_1: |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 160 | if (status & ACPI_EC_FLAG_OBF) |
| 161 | return 1; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 162 | break; |
| 163 | case ACPI_EC_EVENT_IBF_0: |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 164 | if (!(status & ACPI_EC_FLAG_IBF)) |
| 165 | return 1; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 166 | break; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 167 | default: |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 174 | static int acpi_ec_wait(struct acpi_ec *ec, u8 event) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 175 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 176 | int i = (acpi_ec_mode == EC_POLL) ? ACPI_EC_UDELAY_COUNT : 0; |
| 177 | long time_left; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 178 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 179 | ec->expect_event = event; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 180 | if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 181 | ec->expect_event = 0; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 182 | return 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 185 | do { |
| 186 | if (acpi_ec_mode == EC_POLL) { |
| 187 | udelay(ACPI_EC_UDELAY); |
| 188 | } else { |
| 189 | time_left = wait_event_timeout(ec->wait, |
| 190 | !ec->expect_event, |
| 191 | msecs_to_jiffies(ACPI_EC_DELAY)); |
| 192 | if (time_left > 0) { |
| 193 | ec->expect_event = 0; |
| 194 | return 0; |
| 195 | } |
| 196 | } |
| 197 | if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { |
| 198 | ec->expect_event = 0; |
| 199 | return 0; |
| 200 | } |
| 201 | } while (--i > 0); |
| 202 | |
| 203 | ec->expect_event = 0; |
| 204 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 205 | return -ETIME; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 206 | } |
| 207 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 208 | #ifdef ACPI_FUTURE_USAGE |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 209 | /* |
| 210 | * Note: samsung nv5000 doesn't work with ec burst mode. |
| 211 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 |
| 212 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 213 | int acpi_ec_enter_burst_mode(struct acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 214 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 215 | u32 tmp = 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 216 | u32 status = 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 217 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 218 | |
| 219 | status = acpi_ec_read_status(ec); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 220 | if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 221 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 222 | if (status) |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 223 | goto end; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 224 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE); |
| 225 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); |
| 226 | tmp = acpi_ec_read_data(ec); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 227 | if (tmp != 0x90) { /* Burst ACK byte */ |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 228 | return -EINVAL; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 229 | } |
Luming Yu | 668d74c | 2005-07-23 00:26:33 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 232 | atomic_set(&ec->leaving_burst, 0); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 233 | return 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 234 | end: |
| 235 | ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 236 | return -1; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 239 | int acpi_ec_leave_burst_mode(struct acpi_ec *ec) |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 240 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 241 | u32 status = 0; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 242 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 243 | |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 244 | status = acpi_ec_read_status(ec); |
| 245 | if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 246 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 247 | if(status) |
| 248 | goto end; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 249 | acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); |
| 250 | acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 251 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 252 | atomic_set(&ec->leaving_burst, 1); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 253 | return 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 254 | end: |
| 255 | ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 256 | return -1; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 257 | } |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 258 | #endif /* ACPI_FUTURE_USAGE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 260 | static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 261 | const u8 *wdata, unsigned wdata_len, |
| 262 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 263 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 264 | if (acpi_ec_mode == EC_POLL) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 265 | return acpi_ec_poll_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 266 | else |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 267 | return acpi_ec_intr_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
| 268 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 269 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u32 * data) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 270 | { |
| 271 | int result; |
| 272 | u8 d; |
| 273 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, &address, 1, &d, 1); |
| 274 | *data = d; |
| 275 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 276 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 277 | static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 278 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 279 | u8 wdata[2] = { address, data }; |
| 280 | return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, wdata, 2, NULL, 0); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 281 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 282 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 283 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
| 284 | const u8 *wdata, unsigned wdata_len, |
| 285 | u8 *rdata, unsigned rdata_len) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 286 | { |
| 287 | int result; |
| 288 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 289 | acpi_ec_write_cmd(ec, command); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 290 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 291 | for (; wdata_len > 0; wdata_len --) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 292 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 293 | if (result) |
| 294 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 295 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 296 | acpi_ec_write_data(ec, *(wdata++)); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 297 | } |
| 298 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 299 | if (command == ACPI_EC_COMMAND_WRITE) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 300 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 301 | if (result) |
| 302 | return result; |
| 303 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 304 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 305 | for (; rdata_len > 0; rdata_len --) { |
| 306 | u32 d; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 307 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 308 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 309 | if (result) |
| 310 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 311 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 312 | d = acpi_ec_read_data(ec); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 313 | *(rdata++) = (u8) d; |
| 314 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 315 | |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 316 | return 0; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 319 | static int acpi_ec_poll_transaction(struct acpi_ec *ec, u8 command, |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 320 | const u8 *wdata, unsigned wdata_len, |
| 321 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 322 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 323 | acpi_status status = AE_OK; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 324 | int result; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 325 | u32 glk = 0; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 326 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 327 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 328 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 329 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 330 | if (rdata) |
| 331 | memset(rdata, 0, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 332 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 333 | if (ec->global_lock) { |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 334 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 335 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 336 | return -ENODEV; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 337 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 338 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 339 | if (down_interruptible(&ec->sem)) { |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 340 | result = -ERESTARTSYS; |
| 341 | goto end_nosem; |
| 342 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 343 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 344 | result = acpi_ec_transaction_unlocked(ec, command, |
| 345 | wdata, wdata_len, |
| 346 | rdata, rdata_len); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 347 | up(&ec->sem); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 348 | |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 349 | end_nosem: |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 350 | if (ec->global_lock) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 351 | acpi_release_global_lock(glk); |
| 352 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 353 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 354 | } |
| 355 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 356 | static int acpi_ec_intr_transaction(struct acpi_ec *ec, u8 command, |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 357 | const u8 *wdata, unsigned wdata_len, |
| 358 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 359 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 360 | int status; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 361 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 363 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 364 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 366 | if (rdata) |
| 367 | memset(rdata, 0, rdata_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 369 | if (ec->global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
| 371 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 372 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 374 | |
| 375 | WARN_ON(in_interrupt()); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 376 | down(&ec->sem); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 377 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 378 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 379 | if (status) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 380 | ACPI_EXCEPTION((AE_INFO, status, "read EC, IB not empty")); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 381 | goto end; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 384 | status = acpi_ec_transaction_unlocked(ec, command, |
| 385 | wdata, wdata_len, |
| 386 | rdata, rdata_len); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 387 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 388 | end: |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 389 | up(&ec->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 391 | if (ec->global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | acpi_release_global_lock(glk); |
| 393 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 394 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /* |
| 398 | * Externally callable EC access functions. For now, assume 1 EC only |
| 399 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 400 | int ec_read(u8 addr, u8 * val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 402 | struct acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | int err; |
| 404 | u32 temp_data; |
| 405 | |
| 406 | if (!first_ec) |
| 407 | return -ENODEV; |
| 408 | |
| 409 | ec = acpi_driver_data(first_ec); |
| 410 | |
| 411 | err = acpi_ec_read(ec, addr, &temp_data); |
| 412 | |
| 413 | if (!err) { |
| 414 | *val = temp_data; |
| 415 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 416 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return err; |
| 418 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | EXPORT_SYMBOL(ec_read); |
| 421 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 422 | int ec_write(u8 addr, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 424 | struct acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | int err; |
| 426 | |
| 427 | if (!first_ec) |
| 428 | return -ENODEV; |
| 429 | |
| 430 | ec = acpi_driver_data(first_ec); |
| 431 | |
| 432 | err = acpi_ec_write(ec, addr, val); |
| 433 | |
| 434 | return err; |
| 435 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | EXPORT_SYMBOL(ec_write); |
| 438 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 439 | extern int ec_transaction(u8 command, |
| 440 | const u8 *wdata, unsigned wdata_len, |
| 441 | u8 *rdata, unsigned rdata_len) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 442 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 443 | struct acpi_ec *ec; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 444 | |
| 445 | if (!first_ec) |
| 446 | return -ENODEV; |
| 447 | |
| 448 | ec = acpi_driver_data(first_ec); |
| 449 | |
| 450 | return acpi_ec_transaction(ec, command, wdata, wdata_len, rdata, rdata_len); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 451 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 452 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 453 | EXPORT_SYMBOL(ec_transaction); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 454 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 455 | static int acpi_ec_query(struct acpi_ec *ec, u32 * data) { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 456 | int result; |
| 457 | u8 d; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 458 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 459 | if (!ec || !data) |
| 460 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 461 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 462 | /* |
| 463 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 464 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 465 | * bit to be cleared (and thus clearing the interrupt source). |
| 466 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 467 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 468 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); |
| 469 | if (result) |
| 470 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 471 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 472 | if (!d) |
| 473 | return -ENODATA; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 474 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 475 | *data = d; |
| 476 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* -------------------------------------------------------------------------- |
| 480 | Event Management |
| 481 | -------------------------------------------------------------------------- */ |
| 482 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 483 | union acpi_ec_query_data { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 484 | acpi_handle handle; |
| 485 | u8 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 488 | static void acpi_ec_gpe_query(void *ec_cxt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 490 | if (acpi_ec_mode == EC_POLL) |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 491 | acpi_ec_gpe_poll_query(ec_cxt); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 492 | else |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 493 | acpi_ec_gpe_intr_query(ec_cxt); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 496 | static void acpi_ec_gpe_poll_query(void *ec_cxt) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 497 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 498 | struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 499 | u32 value = 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 500 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; |
| 501 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', |
| 502 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
| 503 | }; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 504 | |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 505 | |
| 506 | if (!ec_cxt) |
| 507 | goto end; |
| 508 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 509 | if (down_interruptible (&ec->sem)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 510 | return; |
Rich Townsend | f9a6ee1a | 2005-12-19 23:07:00 -0500 | [diff] [blame] | 511 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 512 | value = acpi_ec_read_status(ec); |
| 513 | up(&ec->sem); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 514 | |
| 515 | /* TBD: Implement asynch events! |
| 516 | * NOTE: All we care about are EC-SCI's. Other EC events are |
| 517 | * handled via polling (yuck!). This is because some systems |
| 518 | * treat EC-SCIs as level (versus EDGE!) triggered, preventing |
| 519 | * a purely interrupt-driven approach (grumble, grumble). |
| 520 | */ |
| 521 | if (!(value & ACPI_EC_FLAG_SCI)) |
| 522 | goto end; |
| 523 | |
| 524 | if (acpi_ec_query(ec, &value)) |
| 525 | goto end; |
| 526 | |
| 527 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 528 | object_name[3] = hex[(value & 0x0F)]; |
| 529 | |
| 530 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 531 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 532 | acpi_evaluate_object(ec->handle, object_name, NULL, NULL); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 533 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 534 | end: |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 535 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 536 | } |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 537 | static void acpi_ec_gpe_intr_query(void *ec_cxt) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 538 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 539 | struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 540 | u32 value; |
| 541 | int result = -ENODATA; |
| 542 | static char object_name[5] = { '_', 'Q', '0', '0', '\0' }; |
| 543 | const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', |
| 544 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
| 545 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 548 | if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) |
| 549 | result = acpi_ec_query(ec, &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 551 | if (result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | goto end; |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | object_name[2] = hex[((value >> 4) & 0x0F)]; |
| 555 | object_name[3] = hex[(value & 0x0F)]; |
| 556 | |
| 557 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); |
| 558 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 559 | acpi_evaluate_object(ec->handle, object_name, NULL, NULL); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 560 | end: |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 561 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 564 | static u32 acpi_ec_gpe_handler(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 566 | if (acpi_ec_mode == EC_POLL) |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 567 | return acpi_ec_gpe_poll_handler(data); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 568 | else |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 569 | return acpi_ec_gpe_intr_handler(data); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 570 | } |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 571 | static u32 acpi_ec_gpe_poll_handler(void *data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 572 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 573 | acpi_status status = AE_OK; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 574 | struct acpi_ec *ec = (struct acpi_ec *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | if (!ec) |
| 577 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 578 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 579 | acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 580 | |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 581 | 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] | 582 | |
| 583 | if (status == AE_OK) |
| 584 | return ACPI_INTERRUPT_HANDLED; |
| 585 | else |
| 586 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 587 | } |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 588 | static u32 acpi_ec_gpe_intr_handler(void *data) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 589 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 590 | acpi_status status = AE_OK; |
| 591 | u32 value; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 592 | struct acpi_ec *ec = (struct acpi_ec *)data; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 593 | |
| 594 | if (!ec) |
| 595 | return ACPI_INTERRUPT_NOT_HANDLED; |
| 596 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 597 | acpi_clear_gpe(NULL, ec->gpe_bit, ACPI_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 598 | value = acpi_ec_read_status(ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 600 | switch (ec->expect_event) { |
| 601 | case ACPI_EC_EVENT_OBF_1: |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 602 | if (!(value & ACPI_EC_FLAG_OBF)) |
| 603 | break; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 604 | ec->expect_event = 0; |
| 605 | wake_up(&ec->wait); |
Vladimir Lebedev | 49fee981 | 2006-06-20 16:46:00 -0400 | [diff] [blame] | 606 | break; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 607 | case ACPI_EC_EVENT_IBF_0: |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 608 | if ((value & ACPI_EC_FLAG_IBF)) |
| 609 | break; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 610 | ec->expect_event = 0; |
| 611 | wake_up(&ec->wait); |
Vladimir Lebedev | 49fee981 | 2006-06-20 16:46:00 -0400 | [diff] [blame] | 612 | break; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 613 | default: |
| 614 | break; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 615 | } |
| 616 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 617 | if (value & ACPI_EC_FLAG_SCI) { |
Alexey Starikovskiy | b8d3519 | 2006-05-05 03:23:00 -0400 | [diff] [blame] | 618 | status = acpi_os_execute(OSL_EC_BURST_HANDLER, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 619 | acpi_ec_gpe_query, ec); |
Luming Yu | 17e9c78 | 2005-04-22 23:07:10 -0400 | [diff] [blame] | 620 | return status == AE_OK ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 621 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
| 622 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 623 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 624 | return status == AE_OK ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 625 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* -------------------------------------------------------------------------- |
| 629 | Address Space Management |
| 630 | -------------------------------------------------------------------------- */ |
| 631 | |
| 632 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 633 | acpi_ec_space_setup(acpi_handle region_handle, |
| 634 | u32 function, void *handler_context, void **return_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
| 636 | /* |
| 637 | * The EC object is in the handler context and is needed |
| 638 | * when calling the acpi_ec_space_handler. |
| 639 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 640 | *return_context = (function != ACPI_REGION_DEACTIVATE) ? |
| 641 | handler_context : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | return AE_OK; |
| 644 | } |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 647 | acpi_ec_space_handler(u32 function, |
| 648 | acpi_physical_address address, |
| 649 | u32 bit_width, |
| 650 | acpi_integer * value, |
| 651 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 653 | int result = 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 654 | struct acpi_ec *ec = NULL; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 655 | u64 temp = *value; |
| 656 | acpi_integer f_v = 0; |
| 657 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | if ((address > 0xFF) || !value || !handler_context) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 661 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 663 | if (bit_width != 8 && acpi_strict) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 664 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 667 | ec = (struct acpi_ec *)handler_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 669 | next_byte: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | switch (function) { |
| 671 | case ACPI_READ: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 672 | temp = 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 673 | result = acpi_ec_read(ec, (u8) address, (u32 *) & temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | break; |
| 675 | case ACPI_WRITE: |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 676 | result = acpi_ec_write(ec, (u8) address, (u8) temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | break; |
| 678 | default: |
| 679 | result = -EINVAL; |
| 680 | goto out; |
| 681 | break; |
| 682 | } |
| 683 | |
| 684 | bit_width -= 8; |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 685 | if (bit_width) { |
| 686 | if (function == ACPI_READ) |
| 687 | f_v |= temp << 8 * i; |
| 688 | if (function == ACPI_WRITE) |
| 689 | temp >>= 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | i++; |
Andrew Morton | 83ea744 | 2005-03-30 22:12:13 -0500 | [diff] [blame] | 691 | address++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | goto next_byte; |
| 693 | } |
| 694 | |
Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 695 | if (function == ACPI_READ) { |
| 696 | f_v |= temp << 8 * i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | *value = f_v; |
| 698 | } |
| 699 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 700 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | switch (result) { |
| 702 | case -EINVAL: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 703 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | break; |
| 705 | case -ENODEV: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 706 | return AE_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | break; |
| 708 | case -ETIME: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 709 | return AE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | break; |
| 711 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 712 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | /* -------------------------------------------------------------------------- |
| 717 | FS Interface (/proc) |
| 718 | -------------------------------------------------------------------------- */ |
| 719 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 720 | static struct proc_dir_entry *acpi_ec_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 722 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 724 | struct acpi_ec *ec = (struct acpi_ec *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
| 727 | if (!ec) |
| 728 | goto end; |
| 729 | |
| 730 | seq_printf(seq, "gpe bit: 0x%02x\n", |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 731 | (u32) ec->gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | seq_printf(seq, "ports: 0x%02x, 0x%02x\n", |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 733 | (u32) ec->status_addr.address, |
| 734 | (u32) ec->data_addr.address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | seq_printf(seq, "use global lock: %s\n", |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 736 | ec->global_lock ? "yes" : "no"); |
| 737 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 739 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 740 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) |
| 744 | { |
| 745 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
| 746 | } |
| 747 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 748 | static struct file_operations acpi_ec_info_ops = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 749 | .open = acpi_ec_info_open_fs, |
| 750 | .read = seq_read, |
| 751 | .llseek = seq_lseek, |
| 752 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | .owner = THIS_MODULE, |
| 754 | }; |
| 755 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 756 | static int acpi_ec_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 758 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | if (!acpi_device_dir(device)) { |
| 762 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 763 | acpi_ec_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 765 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 769 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 771 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | else { |
| 773 | entry->proc_fops = &acpi_ec_info_ops; |
| 774 | entry->data = acpi_driver_data(device); |
| 775 | entry->owner = THIS_MODULE; |
| 776 | } |
| 777 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 778 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 781 | static int acpi_ec_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
| 784 | if (acpi_device_dir(device)) { |
| 785 | remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); |
| 786 | remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); |
| 787 | acpi_device_dir(device) = NULL; |
| 788 | } |
| 789 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 790 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* -------------------------------------------------------------------------- |
| 794 | Driver Interface |
| 795 | -------------------------------------------------------------------------- */ |
| 796 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 797 | static int acpi_ec_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 799 | int result = 0; |
| 800 | acpi_status status = AE_OK; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 801 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 805 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 807 | ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 809 | return -ENOMEM; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 810 | memset(ec, 0, sizeof(struct acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 812 | ec->handle = device->handle; |
| 813 | ec->uid = -1; |
| 814 | init_MUTEX(&ec->sem); |
| 815 | if (acpi_ec_mode == EC_INTR) { |
| 816 | atomic_set(&ec->leaving_burst, 1); |
| 817 | init_waitqueue_head(&ec->wait); |
| 818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 820 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 821 | acpi_driver_data(device) = ec; |
| 822 | |
| 823 | /* Use the global lock for all EC transactions? */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 824 | acpi_evaluate_integer(ec->handle, "_GLK", NULL, |
| 825 | &ec->global_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Jiri Slaby | ff2fc3e | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 827 | /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: |
| 828 | http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ |
| 829 | if (ec_ecdt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 831 | ACPI_ADR_SPACE_EC, |
| 832 | &acpi_ec_space_handler); |
| 833 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 834 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 835 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
| 837 | kfree(ec_ecdt); |
| 838 | } |
| 839 | |
| 840 | /* Get GPE bit assignment (EC events). */ |
| 841 | /* TODO: Add support for _GPE returning a package */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 842 | status = |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 843 | acpi_evaluate_integer(ec->handle, "_GPE", NULL, |
| 844 | &ec->gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | if (ACPI_FAILURE(status)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 846 | ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | result = -ENODEV; |
| 848 | goto end; |
| 849 | } |
| 850 | |
| 851 | result = acpi_ec_add_fs(device); |
| 852 | if (result) |
| 853 | goto end; |
| 854 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 855 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 856 | acpi_device_name(device), acpi_device_bid(device), |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 857 | (u32) ec->gpe_bit)); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 858 | |
| 859 | if (!first_ec) |
| 860 | first_ec = device; |
| 861 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 862 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (result) |
| 864 | kfree(ec); |
| 865 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 866 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 869 | static int acpi_ec_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 871 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 875 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | ec = acpi_driver_data(device); |
| 878 | |
| 879 | acpi_ec_remove_fs(device); |
| 880 | |
| 881 | kfree(ec); |
| 882 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 883 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 887 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 889 | struct acpi_ec *ec = (struct acpi_ec *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | struct acpi_generic_address *addr; |
| 891 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 892 | if (resource->type != ACPI_RESOURCE_TYPE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return AE_OK; |
| 894 | } |
| 895 | |
| 896 | /* |
| 897 | * The first address region returned is the data port, and |
| 898 | * the second address region returned is the status/command |
| 899 | * port. |
| 900 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 901 | if (ec->data_addr.register_bit_width == 0) { |
| 902 | addr = &ec->data_addr; |
| 903 | } else if (ec->command_addr.register_bit_width == 0) { |
| 904 | addr = &ec->command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } else { |
| 906 | return AE_CTRL_TERMINATE; |
| 907 | } |
| 908 | |
| 909 | addr->address_space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
| 910 | addr->register_bit_width = 8; |
| 911 | addr->register_bit_offset = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 912 | addr->address = resource->data.io.minimum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | return AE_OK; |
| 915 | } |
| 916 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 917 | static int acpi_ec_start(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 919 | acpi_status status = AE_OK; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 920 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
| 923 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 924 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | ec = acpi_driver_data(device); |
| 927 | |
| 928 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 929 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * Get I/O port addresses. Convert to GAS format. |
| 933 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 934 | status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 935 | acpi_ec_io_ports, ec); |
| 936 | if (ACPI_FAILURE(status) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 937 | || ec->command_addr.register_bit_width == 0) { |
| 938 | ACPI_EXCEPTION((AE_INFO, status, |
| 939 | "Error getting I/O port addresses")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 940 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 943 | ec->status_addr = ec->command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 945 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x", |
| 946 | (u32) ec->gpe_bit, |
| 947 | (u32) ec->command_addr.address, |
| 948 | (u32) ec->data_addr.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
| 950 | /* |
| 951 | * Install GPE handler |
| 952 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 953 | status = acpi_install_gpe_handler(NULL, ec->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 954 | ACPI_GPE_EDGE_TRIGGERED, |
| 955 | &acpi_ec_gpe_handler, ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | if (ACPI_FAILURE(status)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 957 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 959 | acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 960 | acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 962 | status = acpi_install_address_space_handler(ec->handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 963 | ACPI_ADR_SPACE_EC, |
| 964 | &acpi_ec_space_handler, |
| 965 | &acpi_ec_space_setup, ec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | if (ACPI_FAILURE(status)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 967 | acpi_remove_gpe_handler(NULL, ec->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 968 | &acpi_ec_gpe_handler); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 969 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 972 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 975 | static int acpi_ec_stop(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 977 | acpi_status status = AE_OK; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 978 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
| 981 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 982 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | ec = acpi_driver_data(device); |
| 985 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 986 | status = acpi_remove_address_space_handler(ec->handle, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 987 | ACPI_ADR_SPACE_EC, |
| 988 | &acpi_ec_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 990 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 992 | status = |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 993 | acpi_remove_gpe_handler(NULL, ec->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 994 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 996 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 998 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static acpi_status __init |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1002 | acpi_fake_ecdt_callback(acpi_handle handle, |
| 1003 | u32 Level, void *context, void **retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1005 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1007 | init_MUTEX(&ec_ecdt->sem); |
| 1008 | if (acpi_ec_mode == EC_INTR) { |
| 1009 | init_waitqueue_head(&ec_ecdt->wait); |
| 1010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1012 | acpi_ec_io_ports, ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | if (ACPI_FAILURE(status)) |
| 1014 | return status; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1015 | ec_ecdt->status_addr = ec_ecdt->command_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1017 | ec_ecdt->uid = -1; |
| 1018 | acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1020 | status = |
| 1021 | acpi_evaluate_integer(handle, "_GPE", NULL, |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1022 | &ec_ecdt->gpe_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (ACPI_FAILURE(status)) |
| 1024 | return status; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1025 | ec_ecdt->global_lock = TRUE; |
| 1026 | ec_ecdt->handle = handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1028 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02x, ports=0x%2x, 0x%2x", |
| 1029 | (u32) ec_ecdt->gpe_bit, |
| 1030 | (u32) ec_ecdt->command_addr.address, |
| 1031 | (u32) ec_ecdt->data_addr.address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | return AE_CTRL_TERMINATE; |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | * Some BIOS (such as some from Gateway laptops) access EC region very early |
| 1038 | * such as in BAT0._INI or EC._INI before an EC device is found and |
| 1039 | * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily |
| 1040 | * required, but if EC regison is accessed early, it is required. |
| 1041 | * The routine tries to workaround the BIOS bug by pre-scan EC device |
| 1042 | * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any |
| 1043 | * op region (since _REG isn't invoked yet). The assumption is true for |
| 1044 | * all systems found. |
| 1045 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1046 | static int __init acpi_ec_fake_ecdt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1048 | acpi_status status; |
| 1049 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1051 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1053 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | if (!ec_ecdt) { |
| 1055 | ret = -ENOMEM; |
| 1056 | goto error; |
| 1057 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1058 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1060 | status = acpi_get_devices(ACPI_EC_HID, |
| 1061 | acpi_fake_ecdt_callback, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | if (ACPI_FAILURE(status)) { |
| 1063 | kfree(ec_ecdt); |
| 1064 | ec_ecdt = NULL; |
| 1065 | ret = -ENODEV; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1066 | ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | goto error; |
| 1068 | } |
| 1069 | return 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1070 | error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | return ret; |
| 1072 | } |
| 1073 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1074 | static int __init acpi_ec_get_real_ecdt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1076 | acpi_status status; |
| 1077 | struct acpi_table_ecdt *ecdt_ptr; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1078 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1079 | status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, |
| 1080 | (struct acpi_table_header **) |
| 1081 | &ecdt_ptr); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1082 | if (ACPI_FAILURE(status)) |
| 1083 | return -ENODEV; |
| 1084 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1085 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1086 | |
| 1087 | /* |
| 1088 | * Generate a temporary ec context to use until the namespace is scanned |
| 1089 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1090 | ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1091 | if (!ec_ecdt) |
| 1092 | return -ENOMEM; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1093 | memset(ec_ecdt, 0, sizeof(struct acpi_ec)); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1094 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1095 | init_MUTEX(&ec_ecdt->sem); |
| 1096 | if (acpi_ec_mode == EC_INTR) { |
| 1097 | init_waitqueue_head(&ec_ecdt->wait); |
| 1098 | } |
| 1099 | ec_ecdt->command_addr = ecdt_ptr->ec_control; |
| 1100 | ec_ecdt->status_addr = ecdt_ptr->ec_control; |
| 1101 | ec_ecdt->data_addr = ecdt_ptr->ec_data; |
| 1102 | ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1103 | /* use the GL just to be safe */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1104 | ec_ecdt->global_lock = TRUE; |
| 1105 | ec_ecdt->uid = ecdt_ptr->uid; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1106 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1107 | status = |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1108 | acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1109 | if (ACPI_FAILURE(status)) { |
| 1110 | goto error; |
| 1111 | } |
| 1112 | |
| 1113 | return 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1114 | error: |
| 1115 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | kfree(ec_ecdt); |
| 1117 | ec_ecdt = NULL; |
| 1118 | |
| 1119 | return -ENODEV; |
| 1120 | } |
| 1121 | |
| 1122 | static int __initdata acpi_fake_ecdt_enabled; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1123 | int __init acpi_ec_ecdt_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1125 | acpi_status status; |
| 1126 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
| 1128 | ret = acpi_ec_get_real_ecdt(); |
| 1129 | /* Try to make a fake ECDT */ |
| 1130 | if (ret && acpi_fake_ecdt_enabled) { |
| 1131 | ret = acpi_ec_fake_ecdt(); |
| 1132 | } |
| 1133 | |
| 1134 | if (ret) |
| 1135 | return 0; |
| 1136 | |
| 1137 | /* |
| 1138 | * Install GPE handler |
| 1139 | */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1140 | status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1141 | ACPI_GPE_EDGE_TRIGGERED, |
| 1142 | &acpi_ec_gpe_handler, ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | if (ACPI_FAILURE(status)) { |
| 1144 | goto error; |
| 1145 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1146 | acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); |
| 1147 | acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1149 | status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, |
| 1150 | ACPI_ADR_SPACE_EC, |
| 1151 | &acpi_ec_space_handler, |
| 1152 | &acpi_ec_space_setup, |
| 1153 | ec_ecdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | if (ACPI_FAILURE(status)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1155 | acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1156 | &acpi_ec_gpe_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | goto error; |
| 1158 | } |
| 1159 | |
| 1160 | return 0; |
| 1161 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1162 | error: |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1163 | ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | kfree(ec_ecdt); |
| 1165 | ec_ecdt = NULL; |
| 1166 | |
| 1167 | return -ENODEV; |
| 1168 | } |
| 1169 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1170 | static int __init acpi_ec_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1172 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
| 1175 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1176 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
| 1178 | acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); |
| 1179 | if (!acpi_ec_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1180 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
| 1182 | /* Now register the driver for the EC */ |
| 1183 | result = acpi_bus_register_driver(&acpi_ec_driver); |
| 1184 | if (result < 0) { |
| 1185 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1186 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1189 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | subsys_initcall(acpi_ec_init); |
| 1193 | |
| 1194 | /* EC driver currently not unloadable */ |
| 1195 | #if 0 |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1196 | static void __exit acpi_ec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
| 1199 | acpi_bus_unregister_driver(&acpi_ec_driver); |
| 1200 | |
| 1201 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 1202 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1203 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1205 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
| 1207 | static int __init acpi_fake_ecdt_setup(char *str) |
| 1208 | { |
| 1209 | acpi_fake_ecdt_enabled = 1; |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1210 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | } |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1214 | static int __init acpi_ec_set_intr_mode(char *str) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1215 | { |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1216 | int intr; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1217 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1218 | if (!get_option(&str, &intr)) |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1219 | return 0; |
| 1220 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1221 | if (intr) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1222 | acpi_ec_mode = EC_INTR; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1223 | } else { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1224 | acpi_ec_mode = EC_POLL; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1225 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame^] | 1226 | acpi_ec_driver.ops.add = acpi_ec_add; |
| 1227 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling")); |
| 1228 | |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1229 | return 1; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1230 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1231 | |
Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 1232 | __setup("ec_intr=", acpi_ec_set_intr_mode); |