Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 2 | * ec.c - ACPI Embedded Controller Driver (v2.0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 4 | * Copyright (C) 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> |
| 5 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> |
| 7 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 8 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 9 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or (at |
| 15 | * your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, but |
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 25 | * |
| 26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | */ |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/proc_fs.h> |
| 35 | #include <linux/seq_file.h> |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 37 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/io.h> |
| 39 | #include <acpi/acpi_bus.h> |
| 40 | #include <acpi/acpi_drivers.h> |
| 41 | #include <acpi/actypes.h> |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define ACPI_EC_CLASS "embedded_controller" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define ACPI_EC_DEVICE_NAME "Embedded Controller" |
| 45 | #define ACPI_EC_FILE_INFO "info" |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 46 | |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 47 | #undef PREFIX |
| 48 | #define PREFIX "ACPI: EC: " |
Alexey Starikovskiy | 4350933 | 2007-05-29 16:42:57 +0400 | [diff] [blame] | 49 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 50 | /* EC status register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
| 52 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 53 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
Alexey Starikovskiy | 4350933 | 2007-05-29 16:42:57 +0400 | [diff] [blame] | 55 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 56 | /* EC commands */ |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 57 | enum ec_command { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 58 | ACPI_EC_COMMAND_READ = 0x80, |
| 59 | ACPI_EC_COMMAND_WRITE = 0x81, |
| 60 | ACPI_EC_BURST_ENABLE = 0x82, |
| 61 | ACPI_EC_BURST_DISABLE = 0x83, |
| 62 | ACPI_EC_COMMAND_QUERY = 0x84, |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 63 | }; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 64 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 65 | /* EC events */ |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 66 | enum ec_event { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 67 | ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 68 | ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 69 | }; |
| 70 | |
Alexey Starikovskiy | 5c40641 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 71 | #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 72 | #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] | 73 | |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 74 | static enum ec_mode { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 75 | EC_INTR = 1, /* Output buffer full */ |
| 76 | EC_POLL, /* Input buffer empty */ |
Alexey Starikovskiy | 3261ff4 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 77 | } acpi_ec_mode = EC_INTR; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 78 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 79 | static int acpi_ec_remove(struct acpi_device *device, int type); |
| 80 | static int acpi_ec_start(struct acpi_device *device); |
| 81 | static int acpi_ec_stop(struct acpi_device *device, int type); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 82 | static int acpi_ec_add(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 84 | static const struct acpi_device_id ec_device_ids[] = { |
| 85 | {"PNP0C09", 0}, |
| 86 | {"", 0}, |
| 87 | }; |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static struct acpi_driver acpi_ec_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 90 | .name = "ec", |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 91 | .class = ACPI_EC_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 92 | .ids = ec_device_ids, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 93 | .ops = { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 94 | .add = acpi_ec_add, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 95 | .remove = acpi_ec_remove, |
| 96 | .start = acpi_ec_start, |
| 97 | .stop = acpi_ec_stop, |
| 98 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | }; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 100 | |
| 101 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 102 | /* External interfaces use first EC only, so remember */ |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 103 | typedef int (*acpi_ec_query_func) (void *data); |
| 104 | |
| 105 | struct acpi_ec_query_handler { |
| 106 | struct list_head node; |
| 107 | acpi_ec_query_func func; |
| 108 | acpi_handle handle; |
| 109 | void *data; |
| 110 | u8 query_bit; |
| 111 | }; |
| 112 | |
Adrian Bunk | a854e08 | 2006-12-19 12:56:12 -0800 | [diff] [blame] | 113 | static struct acpi_ec { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 114 | acpi_handle handle; |
Alexey Starikovskiy | a86e277 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 115 | unsigned long gpe; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 116 | unsigned long command_addr; |
| 117 | unsigned long data_addr; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 118 | unsigned long global_lock; |
Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 119 | struct mutex lock; |
Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 120 | atomic_t query_pending; |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 121 | atomic_t event_count; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 122 | wait_queue_head_t wait; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 123 | struct list_head list; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 124 | u8 handlers_installed; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 125 | } *boot_ec, *first_ec; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* -------------------------------------------------------------------------- |
| 128 | Transaction Management |
| 129 | -------------------------------------------------------------------------- */ |
| 130 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 131 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 133 | return inb(ec->command_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 136 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 137 | { |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 138 | return inb(ec->data_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 139 | } |
| 140 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 141 | 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] | 142 | { |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 143 | outb(command, ec->command_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 144 | } |
| 145 | |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 146 | 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] | 147 | { |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 148 | outb(data, ec->data_addr); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 149 | } |
| 150 | |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 151 | static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event, |
| 152 | unsigned old_count) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 153 | { |
Alexey Starikovskiy | bec5a1e | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 154 | u8 status = acpi_ec_read_status(ec); |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 155 | if (old_count == atomic_read(&ec->event_count)) |
| 156 | return 0; |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 157 | if (event == ACPI_EC_EVENT_OBF_1) { |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 158 | if (status & ACPI_EC_FLAG_OBF) |
| 159 | return 1; |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 160 | } else if (event == ACPI_EC_EVENT_IBF_0) { |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 161 | if (!(status & ACPI_EC_FLAG_IBF)) |
| 162 | return 1; |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 168 | static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, |
| 169 | unsigned count, int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 170 | { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 171 | if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) { |
Alexey Starikovskiy | 50c1e11 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 172 | unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); |
| 173 | while (time_before(jiffies, delay)) { |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 174 | if (acpi_ec_check_status(ec, event, 0)) |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 175 | return 0; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 176 | } |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 177 | } else { |
| 178 | if (wait_event_timeout(ec->wait, |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 179 | acpi_ec_check_status(ec, event, count), |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 180 | msecs_to_jiffies(ACPI_EC_DELAY)) || |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 181 | acpi_ec_check_status(ec, event, 0)) { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 182 | return 0; |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 183 | } else { |
| 184 | printk(KERN_ERR PREFIX "acpi_ec_wait timeout," |
| 185 | " status = %d, expect_event = %d\n", |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 186 | acpi_ec_read_status(ec), event); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 187 | } |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 188 | } |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 189 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 190 | return -ETIME; |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 193 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 194 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 195 | u8 * rdata, unsigned rdata_len, |
| 196 | int force_poll) |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 197 | { |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 198 | int result = 0; |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 199 | unsigned count = atomic_read(&ec->event_count); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 200 | acpi_ec_write_cmd(ec, command); |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 201 | |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 202 | for (; wdata_len > 0; --wdata_len) { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 203 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 204 | if (result) { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 205 | printk(KERN_ERR PREFIX |
| 206 | "write_cmd timeout, command = %d\n", command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 207 | goto end; |
| 208 | } |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 209 | count = atomic_read(&ec->event_count); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 210 | acpi_ec_write_data(ec, *(wdata++)); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 211 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 212 | |
Alexey Starikovskiy | d91df1a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 213 | if (!rdata_len) { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 214 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 215 | if (result) { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 216 | printk(KERN_ERR PREFIX |
| 217 | "finish-write timeout, command = %d\n", command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 218 | goto end; |
| 219 | } |
Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 220 | } else if (command == ACPI_EC_COMMAND_QUERY) { |
| 221 | atomic_set(&ec->query_pending, 0); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 222 | } |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 223 | |
Alexey Starikovskiy | 78d0af3 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 224 | for (; rdata_len > 0; --rdata_len) { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 225 | result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 226 | if (result) { |
| 227 | printk(KERN_ERR PREFIX "read timeout, command = %d\n", |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 228 | command); |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 229 | goto end; |
| 230 | } |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 231 | count = atomic_read(&ec->event_count); |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 232 | *(rdata++) = acpi_ec_read_data(ec); |
Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 233 | } |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 234 | end: |
| 235 | return result; |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 238 | static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 239 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 240 | u8 * rdata, unsigned rdata_len, |
| 241 | int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 242 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 243 | int status; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 244 | u32 glk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 246 | if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 247 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 249 | if (rdata) |
| 250 | memset(rdata, 0, rdata_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Alexey Starikovskiy | 523953b | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 252 | mutex_lock(&ec->lock); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 253 | if (ec->global_lock) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); |
Alexey Starikovskiy | c24e912 | 2007-02-15 23:16:18 +0300 | [diff] [blame] | 255 | if (ACPI_FAILURE(status)) { |
| 256 | mutex_unlock(&ec->lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 257 | return -ENODEV; |
Alexey Starikovskiy | c24e912 | 2007-02-15 23:16:18 +0300 | [diff] [blame] | 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 260 | |
Alexey Starikovskiy | 5d57a6a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 261 | /* Make sure GPE is enabled before doing transaction */ |
Alexey Starikovskiy | a86e277 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 262 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
Alexey Starikovskiy | 5d57a6a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 263 | |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 264 | status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0); |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 265 | if (status) { |
Alexey Starikovskiy | 4350933 | 2007-05-29 16:42:57 +0400 | [diff] [blame] | 266 | printk(KERN_ERR PREFIX |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 267 | "input buffer is not empty, aborting transaction\n"); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 268 | goto end; |
Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 271 | status = acpi_ec_transaction_unlocked(ec, command, |
| 272 | wdata, wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 273 | rdata, rdata_len, |
| 274 | force_poll); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 275 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 276 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 278 | if (ec->global_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | acpi_release_global_lock(glk); |
Alexey Starikovskiy | 523953b | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 280 | mutex_unlock(&ec->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 282 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 285 | /* |
| 286 | * Note: samsung nv5000 doesn't work with ec burst mode. |
| 287 | * http://bugzilla.kernel.org/show_bug.cgi?id=4980 |
| 288 | */ |
| 289 | int acpi_ec_burst_enable(struct acpi_ec *ec) |
| 290 | { |
| 291 | u8 d; |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 292 | return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | int acpi_ec_burst_disable(struct acpi_ec *ec) |
| 296 | { |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 297 | return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 298 | } |
| 299 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 300 | 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] | 301 | { |
| 302 | int result; |
| 303 | u8 d; |
| 304 | |
| 305 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 306 | &address, 1, &d, 1, 0); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 307 | *data = d; |
| 308 | return result; |
| 309 | } |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 310 | |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 311 | static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) |
| 312 | { |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 313 | u8 wdata[2] = { address, data }; |
| 314 | return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 315 | wdata, 2, NULL, 0, 0); |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 316 | } |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* |
| 319 | * Externally callable EC access functions. For now, assume 1 EC only |
| 320 | */ |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 321 | int ec_burst_enable(void) |
| 322 | { |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 323 | if (!first_ec) |
| 324 | return -ENODEV; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 325 | return acpi_ec_burst_enable(first_ec); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | EXPORT_SYMBOL(ec_burst_enable); |
| 329 | |
| 330 | int ec_burst_disable(void) |
| 331 | { |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 332 | if (!first_ec) |
| 333 | return -ENODEV; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 334 | return acpi_ec_burst_disable(first_ec); |
Alexey Starikovskiy | c45aac4 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | EXPORT_SYMBOL(ec_burst_disable); |
| 338 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 339 | int ec_read(u8 addr, u8 * val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int err; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 342 | u8 temp_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (!first_ec) |
| 345 | return -ENODEV; |
| 346 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 347 | err = acpi_ec_read(first_ec, addr, &temp_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | if (!err) { |
| 350 | *val = temp_data; |
| 351 | return 0; |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 352 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return err; |
| 354 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | EXPORT_SYMBOL(ec_read); |
| 357 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 358 | int ec_write(u8 addr, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | int err; |
| 361 | |
| 362 | if (!first_ec) |
| 363 | return -ENODEV; |
| 364 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 365 | err = acpi_ec_write(first_ec, addr, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | return err; |
| 368 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | EXPORT_SYMBOL(ec_write); |
| 371 | |
Randy Dunlap | 616362d | 2006-10-27 01:47:34 -0400 | [diff] [blame] | 372 | int ec_transaction(u8 command, |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 373 | const u8 * wdata, unsigned wdata_len, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 374 | u8 * rdata, unsigned rdata_len, |
| 375 | int force_poll) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 376 | { |
Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 377 | if (!first_ec) |
| 378 | return -ENODEV; |
| 379 | |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 380 | return acpi_ec_transaction(first_ec, command, wdata, |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 381 | wdata_len, rdata, rdata_len, |
| 382 | force_poll); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 383 | } |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 384 | |
Lennart Poettering | ab9e43c | 2006-10-03 22:49:00 -0400 | [diff] [blame] | 385 | EXPORT_SYMBOL(ec_transaction); |
| 386 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 387 | static int acpi_ec_query(struct acpi_ec *ec, u8 * data) |
Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 388 | { |
| 389 | int result; |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 390 | u8 d; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 391 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 392 | if (!ec || !data) |
| 393 | return -EINVAL; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 394 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 395 | /* |
| 396 | * Query the EC to find out which _Qxx method we need to evaluate. |
| 397 | * Note that successful completion of the query causes the ACPI_EC_SCI |
| 398 | * bit to be cleared (and thus clearing the interrupt source). |
| 399 | */ |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 400 | |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 401 | result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0); |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 402 | if (result) |
| 403 | return result; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 404 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 405 | if (!d) |
| 406 | return -ENODATA; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 407 | |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 408 | *data = d; |
| 409 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | /* -------------------------------------------------------------------------- |
| 413 | Event Management |
| 414 | -------------------------------------------------------------------------- */ |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 415 | int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, |
| 416 | acpi_handle handle, acpi_ec_query_func func, |
| 417 | void *data) |
| 418 | { |
| 419 | struct acpi_ec_query_handler *handler = |
| 420 | kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL); |
| 421 | if (!handler) |
| 422 | return -ENOMEM; |
| 423 | |
| 424 | handler->query_bit = query_bit; |
| 425 | handler->handle = handle; |
| 426 | handler->func = func; |
| 427 | handler->data = data; |
| 428 | mutex_lock(&ec->lock); |
| 429 | list_add_tail(&handler->node, &ec->list); |
| 430 | mutex_unlock(&ec->lock); |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); |
| 435 | |
| 436 | void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) |
| 437 | { |
| 438 | struct acpi_ec_query_handler *handler; |
| 439 | mutex_lock(&ec->lock); |
| 440 | list_for_each_entry(handler, &ec->list, node) { |
| 441 | if (query_bit == handler->query_bit) { |
| 442 | list_del(&handler->node); |
| 443 | kfree(handler); |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | mutex_unlock(&ec->lock); |
| 448 | } |
| 449 | |
| 450 | EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 452 | static void acpi_ec_gpe_query(void *ec_cxt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 454 | struct acpi_ec *ec = ec_cxt; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 455 | u8 value = 0; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 456 | struct acpi_ec_query_handler *handler, copy; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 457 | |
Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 458 | if (!ec || acpi_ec_query(ec, &value)) |
Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 459 | return; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 460 | mutex_lock(&ec->lock); |
| 461 | list_for_each_entry(handler, &ec->list, node) { |
| 462 | if (value == handler->query_bit) { |
| 463 | /* have custom handler for this bit */ |
| 464 | memcpy(©, handler, sizeof(copy)); |
| 465 | mutex_unlock(&ec->lock); |
| 466 | if (copy.func) { |
| 467 | copy.func(copy.data); |
| 468 | } else if (copy.handle) { |
| 469 | acpi_evaluate_object(copy.handle, NULL, NULL, NULL); |
| 470 | } |
| 471 | return; |
| 472 | } |
| 473 | } |
| 474 | mutex_unlock(&ec->lock); |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 477 | static u32 acpi_ec_gpe_handler(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 479 | acpi_status status = AE_OK; |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 480 | u8 value; |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 481 | struct acpi_ec *ec = data; |
Lennart Poettering | 00eb43a | 2007-05-04 14:16:19 +0200 | [diff] [blame] | 482 | |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 483 | atomic_inc(&ec->event_count); |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 484 | |
Denis M. Sadykov | 8e0341b | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 485 | if (acpi_ec_mode == EC_INTR) { |
Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 486 | wake_up(&ec->wait); |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 487 | } |
| 488 | |
Alexey Starikovskiy | bec5a1e | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 489 | value = acpi_ec_read_status(ec); |
Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 490 | if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { |
| 491 | atomic_set(&ec->query_pending, 1); |
Alexey Starikovskiy | 6ccedb1 | 2006-12-07 18:42:17 +0300 | [diff] [blame] | 492 | status = |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 493 | acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 494 | } |
Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 495 | |
Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 496 | return status == AE_OK ? |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 497 | ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* -------------------------------------------------------------------------- |
| 501 | Address Space Management |
| 502 | -------------------------------------------------------------------------- */ |
| 503 | |
| 504 | static acpi_status |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 505 | acpi_ec_space_setup(acpi_handle region_handle, |
| 506 | u32 function, void *handler_context, void **return_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
| 508 | /* |
| 509 | * The EC object is in the handler context and is needed |
| 510 | * when calling the acpi_ec_space_handler. |
| 511 | */ |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 512 | *return_context = (function != ACPI_REGION_DEACTIVATE) ? |
| 513 | handler_context : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | return AE_OK; |
| 516 | } |
| 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | static acpi_status |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 519 | acpi_ec_space_handler(u32 function, acpi_physical_address address, |
| 520 | u32 bits, acpi_integer *value, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 521 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 523 | struct acpi_ec *ec = handler_context; |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 524 | int result = 0, i = 0; |
| 525 | u8 temp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | if ((address > 0xFF) || !value || !handler_context) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 528 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 530 | if (function != ACPI_READ && function != ACPI_WRITE) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 531 | return AE_BAD_PARAMETER; |
Alexey Starikovskiy | 5b7734b | 2007-05-29 16:42:52 +0400 | [diff] [blame] | 532 | |
| 533 | if (bits != 8 && acpi_strict) |
| 534 | return AE_BAD_PARAMETER; |
| 535 | |
| 536 | while (bits - i > 0) { |
| 537 | if (function == ACPI_READ) { |
| 538 | result = acpi_ec_read(ec, address, &temp); |
| 539 | (*value) |= ((acpi_integer)temp) << i; |
| 540 | } else { |
| 541 | temp = 0xff & ((*value) >> i); |
| 542 | result = acpi_ec_write(ec, address, temp); |
| 543 | } |
| 544 | i += 8; |
| 545 | ++address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | switch (result) { |
| 549 | case -EINVAL: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 550 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | break; |
| 552 | case -ENODEV: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 553 | return AE_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | break; |
| 555 | case -ETIME: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 556 | return AE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | break; |
| 558 | default: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 559 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* -------------------------------------------------------------------------- |
| 564 | FS Interface (/proc) |
| 565 | -------------------------------------------------------------------------- */ |
| 566 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 567 | static struct proc_dir_entry *acpi_ec_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 569 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 571 | struct acpi_ec *ec = seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (!ec) |
| 574 | goto end; |
| 575 | |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 576 | seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); |
| 577 | seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", |
| 578 | (unsigned)ec->command_addr, (unsigned)ec->data_addr); |
| 579 | seq_printf(seq, "use global lock:\t%s\n", |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 580 | ec->global_lock ? "yes" : "no"); |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 581 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 582 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) |
| 586 | { |
| 587 | return single_open(file, acpi_ec_read_info, PDE(inode)->data); |
| 588 | } |
| 589 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 590 | static struct file_operations acpi_ec_info_ops = { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 591 | .open = acpi_ec_info_open_fs, |
| 592 | .read = seq_read, |
| 593 | .llseek = seq_lseek, |
| 594 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | .owner = THIS_MODULE, |
| 596 | }; |
| 597 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 598 | static int acpi_ec_add_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 600 | struct proc_dir_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | if (!acpi_device_dir(device)) { |
| 603 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 604 | acpi_ec_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | if (!acpi_device_dir(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 606 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 610 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 612 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | else { |
| 614 | entry->proc_fops = &acpi_ec_info_ops; |
| 615 | entry->data = acpi_driver_data(device); |
| 616 | entry->owner = THIS_MODULE; |
| 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 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 622 | static int acpi_ec_remove_fs(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | if (acpi_device_dir(device)) { |
| 626 | remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); |
| 627 | remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); |
| 628 | acpi_device_dir(device) = NULL; |
| 629 | } |
| 630 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 631 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | /* -------------------------------------------------------------------------- |
| 635 | Driver Interface |
| 636 | -------------------------------------------------------------------------- */ |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 637 | static acpi_status |
| 638 | ec_parse_io_ports(struct acpi_resource *resource, void *context); |
| 639 | |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 640 | static struct acpi_ec *make_acpi_ec(void) |
| 641 | { |
| 642 | struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); |
| 643 | if (!ec) |
| 644 | return NULL; |
| 645 | |
Alexey Starikovskiy | 9fd9f8e | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 646 | atomic_set(&ec->query_pending, 1); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 647 | atomic_set(&ec->event_count, 1); |
| 648 | mutex_init(&ec->lock); |
| 649 | init_waitqueue_head(&ec->wait); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 650 | INIT_LIST_HEAD(&ec->list); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 651 | |
| 652 | return ec; |
| 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 655 | static acpi_status |
Alexey Starikovskiy | c019b19 | 2007-08-14 01:03:42 -0400 | [diff] [blame] | 656 | acpi_ec_register_query_methods(acpi_handle handle, u32 level, |
| 657 | void *context, void **return_value) |
| 658 | { |
| 659 | struct acpi_namespace_node *node = handle; |
| 660 | struct acpi_ec *ec = context; |
| 661 | int value = 0; |
| 662 | if (sscanf(node->name.ascii, "_Q%x", &value) == 1) { |
| 663 | acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); |
| 664 | } |
| 665 | return AE_OK; |
| 666 | } |
| 667 | |
| 668 | static acpi_status |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 669 | ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 670 | { |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 671 | acpi_status status; |
| 672 | |
| 673 | struct acpi_ec *ec = context; |
| 674 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 675 | ec_parse_io_ports, ec); |
| 676 | if (ACPI_FAILURE(status)) |
| 677 | return status; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 678 | |
| 679 | /* Get GPE bit assignment (EC events). */ |
| 680 | /* TODO: Add support for _GPE returning a package */ |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 681 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); |
| 682 | if (ACPI_FAILURE(status)) |
| 683 | return status; |
Alexey Starikovskiy | c019b19 | 2007-08-14 01:03:42 -0400 | [diff] [blame] | 684 | /* Find and register all query methods */ |
| 685 | acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, |
| 686 | acpi_ec_register_query_methods, ec, NULL); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 687 | /* Use the global lock for all EC transactions? */ |
| 688 | acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 689 | ec->handle = handle; |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 690 | return AE_CTRL_TERMINATE; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 691 | } |
| 692 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 693 | static void ec_remove_handlers(struct acpi_ec *ec) |
| 694 | { |
| 695 | if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, |
| 696 | ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) |
| 697 | printk(KERN_ERR PREFIX "failed to remove space handler\n"); |
| 698 | if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, |
| 699 | &acpi_ec_gpe_handler))) |
| 700 | printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); |
| 701 | ec->handlers_installed = 0; |
| 702 | } |
| 703 | |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 704 | static int acpi_ec_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 706 | struct acpi_ec *ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 709 | return -EINVAL; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 710 | strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); |
| 711 | strcpy(acpi_device_class(device), ACPI_EC_CLASS); |
| 712 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 713 | /* Check for boot EC */ |
| 714 | if (boot_ec) { |
| 715 | if (boot_ec->handle == device->handle) { |
| 716 | /* Pre-loaded EC from DSDT, just move pointer */ |
| 717 | ec = boot_ec; |
| 718 | boot_ec = NULL; |
| 719 | goto end; |
| 720 | } else if (boot_ec->handle == ACPI_ROOT_OBJECT) { |
| 721 | /* ECDT-based EC, time to shut it down */ |
| 722 | ec_remove_handlers(boot_ec); |
| 723 | kfree(boot_ec); |
| 724 | first_ec = boot_ec = NULL; |
| 725 | } |
| 726 | } |
| 727 | |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 728 | ec = make_acpi_ec(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 730 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 732 | if (ec_parse_device(device->handle, 0, ec, NULL) != |
| 733 | AE_CTRL_TERMINATE) { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 734 | kfree(ec); |
| 735 | return -EINVAL; |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 736 | } |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 737 | ec->handle = device->handle; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 738 | end: |
| 739 | if (!first_ec) |
| 740 | first_ec = ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | acpi_driver_data(device) = ec; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 742 | acpi_ec_add_fs(device); |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 743 | printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", |
| 744 | ec->gpe, ec->command_addr, ec->data_addr); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 745 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 748 | static int acpi_ec_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 750 | struct acpi_ec *ec; |
Adrian Bunk | 07ddf76 | 2007-07-29 17:00:37 +0200 | [diff] [blame] | 751 | struct acpi_ec_query_handler *handler, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 754 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
| 756 | ec = acpi_driver_data(device); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 757 | mutex_lock(&ec->lock); |
Adrian Bunk | 07ddf76 | 2007-07-29 17:00:37 +0200 | [diff] [blame] | 758 | list_for_each_entry_safe(handler, tmp, &ec->list, node) { |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 759 | list_del(&handler->node); |
| 760 | kfree(handler); |
| 761 | } |
| 762 | mutex_unlock(&ec->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | acpi_ec_remove_fs(device); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 764 | acpi_driver_data(device) = NULL; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 765 | if (ec == first_ec) |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 766 | first_ec = NULL; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 767 | kfree(ec); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 768 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | static acpi_status |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 772 | ec_parse_io_ports(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
Alexey Starikovskiy | 3d02b90 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 774 | struct acpi_ec *ec = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 776 | if (resource->type != ACPI_RESOURCE_TYPE_IO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * The first address region returned is the data port, and |
| 781 | * the second address region returned is the status/command |
| 782 | * port. |
| 783 | */ |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 784 | if (ec->data_addr == 0) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 785 | ec->data_addr = resource->data.io.minimum; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 786 | else if (ec->command_addr == 0) |
Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 787 | ec->command_addr = resource->data.io.minimum; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 788 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | return AE_OK; |
| 792 | } |
| 793 | |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 794 | static int ec_install_handlers(struct acpi_ec *ec) |
| 795 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 796 | acpi_status status; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 797 | if (ec->handlers_installed) |
| 798 | return 0; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 799 | status = acpi_install_gpe_handler(NULL, ec->gpe, |
| 800 | ACPI_GPE_EDGE_TRIGGERED, |
| 801 | &acpi_ec_gpe_handler, ec); |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 802 | if (ACPI_FAILURE(status)) |
| 803 | return -ENODEV; |
Alexey Starikovskiy | 01f22462 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 804 | |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 805 | acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); |
| 806 | acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); |
| 807 | |
| 808 | status = acpi_install_address_space_handler(ec->handle, |
| 809 | ACPI_ADR_SPACE_EC, |
| 810 | &acpi_ec_space_handler, |
| 811 | &acpi_ec_space_setup, ec); |
| 812 | if (ACPI_FAILURE(status)) { |
| 813 | acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); |
| 814 | return -ENODEV; |
| 815 | } |
| 816 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 817 | ec->handlers_installed = 1; |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 821 | static int acpi_ec_start(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 823 | struct acpi_ec *ec; |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 824 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 827 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | ec = acpi_driver_data(device); |
| 830 | |
| 831 | if (!ec) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 832 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 834 | ret = ec_install_handlers(ec); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 835 | |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 836 | /* EC is fully operational, allow queries */ |
| 837 | atomic_set(&ec->query_pending, 0); |
Alexey Starikovskiy | 837012e | 2007-05-29 16:43:02 +0400 | [diff] [blame] | 838 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 841 | static int acpi_ec_stop(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 843 | struct acpi_ec *ec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 845 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | ec = acpi_driver_data(device); |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 847 | if (!ec) |
| 848 | return -EINVAL; |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 849 | ec_remove_handlers(ec); |
Alexey Starikovskiy | f9319f9 | 2007-08-24 08:10:11 +0400 | [diff] [blame] | 850 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 851 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 854 | int __init acpi_ec_ecdt_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 856 | int ret; |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 857 | acpi_status status; |
| 858 | struct acpi_table_ecdt *ecdt_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 860 | boot_ec = make_acpi_ec(); |
| 861 | if (!boot_ec) |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 862 | return -ENOMEM; |
| 863 | /* |
| 864 | * Generate a boot ec context |
| 865 | */ |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 866 | status = acpi_get_table(ACPI_SIG_ECDT, 1, |
| 867 | (struct acpi_table_header **)&ecdt_ptr); |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 868 | if (ACPI_SUCCESS(status)) { |
Alexey Starikovskiy | 4c61106 | 2007-09-05 19:56:38 -0400 | [diff] [blame^] | 869 | printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 870 | boot_ec->command_addr = ecdt_ptr->control.address; |
| 871 | boot_ec->data_addr = ecdt_ptr->data.address; |
| 872 | boot_ec->gpe = ecdt_ptr->gpe; |
| 873 | boot_ec->handle = ACPI_ROOT_OBJECT; |
| 874 | } else { |
| 875 | printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); |
| 876 | status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, |
| 877 | boot_ec, NULL); |
Alexey Starikovskiy | 2d8348b | 2007-08-31 09:05:26 +0400 | [diff] [blame] | 878 | /* Check that acpi_get_devices actually find something */ |
| 879 | if (ACPI_FAILURE(status) || !boot_ec->handle) |
Alexey Starikovskiy | cd8c93a | 2007-08-03 17:52:48 -0400 | [diff] [blame] | 880 | goto error; |
| 881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 883 | ret = ec_install_handlers(boot_ec); |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 884 | if (!ret) { |
| 885 | first_ec = boot_ec; |
Alexey Starikovskiy | e828432 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 886 | return 0; |
Alexey Starikovskiy | d033879 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 887 | } |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 888 | error: |
Alexey Starikovskiy | d66d969 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 889 | kfree(boot_ec); |
| 890 | boot_ec = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | return -ENODEV; |
| 892 | } |
| 893 | |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 894 | static int __init acpi_ec_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 896 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 899 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); |
| 902 | if (!acpi_ec_dir) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 903 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | /* Now register the driver for the EC */ |
| 906 | result = acpi_bus_register_driver(&acpi_ec_driver); |
| 907 | if (result < 0) { |
| 908 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 909 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 912 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | subsys_initcall(acpi_ec_init); |
| 916 | |
| 917 | /* EC driver currently not unloadable */ |
| 918 | #if 0 |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 919 | static void __exit acpi_ec_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
| 922 | acpi_bus_unregister_driver(&acpi_ec_driver); |
| 923 | |
| 924 | remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); |
| 925 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 926 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 928 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 930 | static int __init acpi_ec_set_intr_mode(char *str) |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 931 | { |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 932 | int intr; |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 933 | |
Len Brown | 02b28a33 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 934 | if (!get_option(&str, &intr)) |
Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 935 | return 0; |
| 936 | |
Alexey Starikovskiy | c0900c3 | 2007-03-07 22:28:00 +0300 | [diff] [blame] | 937 | acpi_ec_mode = (intr) ? EC_INTR : EC_POLL; |
| 938 | |
Alexey Starikovskiy | 9e19721 | 2007-03-07 18:29:35 -0500 | [diff] [blame] | 939 | printk(KERN_NOTICE PREFIX "%s mode.\n", intr ? "interrupt" : "polling"); |
Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 940 | |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 941 | return 1; |
Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 942 | } |
Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 943 | |
Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 944 | __setup("ec_intr=", acpi_ec_set_intr_mode); |