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