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