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