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