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