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