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