diff options
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r-- | drivers/acpi/ec.c | 164 |
1 files changed, 85 insertions, 79 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index ad11ba4a412d..a66ab658abbc 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c | |||
@@ -1,11 +1,14 @@ | |||
1 | /* | 1 | /* |
2 | * ec.c - ACPI Embedded Controller Driver (v2.1) | 2 | * ec.c - ACPI Embedded Controller Driver (v2.2) |
3 | * | 3 | * |
4 | * Copyright (C) 2006-2008 Alexey Starikovskiy <astarikovskiy@suse.de> | 4 | * Copyright (C) 2001-2014 Intel Corporation |
5 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> | 5 | * Author: 2014 Lv Zheng <lv.zheng@intel.com> |
6 | * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> | 6 | * 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> |
7 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 7 | * 2006 Denis Sadykov <denis.m.sadykov@intel.com> |
8 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 8 | * 2004 Luming Yu <luming.yu@intel.com> |
9 | * 2001, 2002 Andy Grover <andrew.grover@intel.com> | ||
10 | * 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | ||
11 | * Copyright (C) 2008 Alexey Starikovskiy <astarikovskiy@suse.de> | ||
9 | * | 12 | * |
10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 13 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
11 | * | 14 | * |
@@ -52,6 +55,7 @@ | |||
52 | /* EC status register */ | 55 | /* EC status register */ |
53 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ | 56 | #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ |
54 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ | 57 | #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ |
58 | #define ACPI_EC_FLAG_CMD 0x08 /* Input buffer contains a command */ | ||
55 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ | 59 | #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ |
56 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ | 60 | #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ |
57 | 61 | ||
@@ -78,6 +82,9 @@ enum { | |||
78 | EC_FLAGS_BLOCKED, /* Transactions are blocked */ | 82 | EC_FLAGS_BLOCKED, /* Transactions are blocked */ |
79 | }; | 83 | }; |
80 | 84 | ||
85 | #define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */ | ||
86 | #define ACPI_EC_COMMAND_COMPLETE 0x02 /* Completed last byte */ | ||
87 | |||
81 | /* ec.c is compiled in acpi namespace so this shows up as acpi.ec_delay param */ | 88 | /* ec.c is compiled in acpi namespace so this shows up as acpi.ec_delay param */ |
82 | static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY; | 89 | static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY; |
83 | module_param(ec_delay, uint, 0644); | 90 | module_param(ec_delay, uint, 0644); |
@@ -109,7 +116,7 @@ struct transaction { | |||
109 | u8 ri; | 116 | u8 ri; |
110 | u8 wlen; | 117 | u8 wlen; |
111 | u8 rlen; | 118 | u8 rlen; |
112 | bool done; | 119 | u8 flags; |
113 | }; | 120 | }; |
114 | 121 | ||
115 | struct acpi_ec *boot_ec, *first_ec; | 122 | struct acpi_ec *boot_ec, *first_ec; |
@@ -127,83 +134,104 @@ static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */ | |||
127 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) | 134 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) |
128 | { | 135 | { |
129 | u8 x = inb(ec->command_addr); | 136 | u8 x = inb(ec->command_addr); |
130 | pr_debug("---> status = 0x%2.2x\n", x); | 137 | pr_debug("EC_SC(R) = 0x%2.2x " |
138 | "SCI_EVT=%d BURST=%d CMD=%d IBF=%d OBF=%d\n", | ||
139 | x, | ||
140 | !!(x & ACPI_EC_FLAG_SCI), | ||
141 | !!(x & ACPI_EC_FLAG_BURST), | ||
142 | !!(x & ACPI_EC_FLAG_CMD), | ||
143 | !!(x & ACPI_EC_FLAG_IBF), | ||
144 | !!(x & ACPI_EC_FLAG_OBF)); | ||
131 | return x; | 145 | return x; |
132 | } | 146 | } |
133 | 147 | ||
134 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) | 148 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) |
135 | { | 149 | { |
136 | u8 x = inb(ec->data_addr); | 150 | u8 x = inb(ec->data_addr); |
137 | pr_debug("---> data = 0x%2.2x\n", x); | 151 | pr_debug("EC_DATA(R) = 0x%2.2x\n", x); |
138 | return x; | 152 | return x; |
139 | } | 153 | } |
140 | 154 | ||
141 | static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) | 155 | static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) |
142 | { | 156 | { |
143 | pr_debug("<--- command = 0x%2.2x\n", command); | 157 | pr_debug("EC_SC(W) = 0x%2.2x\n", command); |
144 | outb(command, ec->command_addr); | 158 | outb(command, ec->command_addr); |
145 | } | 159 | } |
146 | 160 | ||
147 | static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) | 161 | static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) |
148 | { | 162 | { |
149 | pr_debug("<--- data = 0x%2.2x\n", data); | 163 | pr_debug("EC_DATA(W) = 0x%2.2x\n", data); |
150 | outb(data, ec->data_addr); | 164 | outb(data, ec->data_addr); |
151 | } | 165 | } |
152 | 166 | ||
153 | static int ec_transaction_done(struct acpi_ec *ec) | 167 | static int ec_transaction_completed(struct acpi_ec *ec) |
154 | { | 168 | { |
155 | unsigned long flags; | 169 | unsigned long flags; |
156 | int ret = 0; | 170 | int ret = 0; |
157 | spin_lock_irqsave(&ec->lock, flags); | 171 | spin_lock_irqsave(&ec->lock, flags); |
158 | if (!ec->curr || ec->curr->done) | 172 | if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE)) |
159 | ret = 1; | 173 | ret = 1; |
160 | spin_unlock_irqrestore(&ec->lock, flags); | 174 | spin_unlock_irqrestore(&ec->lock, flags); |
161 | return ret; | 175 | return ret; |
162 | } | 176 | } |
163 | 177 | ||
164 | static void start_transaction(struct acpi_ec *ec) | 178 | static bool advance_transaction(struct acpi_ec *ec) |
165 | { | 179 | { |
166 | ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0; | ||
167 | ec->curr->done = false; | ||
168 | acpi_ec_write_cmd(ec, ec->curr->command); | ||
169 | } | ||
170 | |||
171 | static void advance_transaction(struct acpi_ec *ec, u8 status) | ||
172 | { | ||
173 | unsigned long flags; | ||
174 | struct transaction *t; | 180 | struct transaction *t; |
181 | u8 status; | ||
182 | bool wakeup = false; | ||
175 | 183 | ||
176 | spin_lock_irqsave(&ec->lock, flags); | 184 | pr_debug("===== %s =====\n", in_interrupt() ? "IRQ" : "TASK"); |
185 | status = acpi_ec_read_status(ec); | ||
177 | t = ec->curr; | 186 | t = ec->curr; |
178 | if (!t) | 187 | if (!t) |
179 | goto unlock; | 188 | goto err; |
180 | if (t->wlen > t->wi) { | 189 | if (t->flags & ACPI_EC_COMMAND_POLL) { |
181 | if ((status & ACPI_EC_FLAG_IBF) == 0) | 190 | if (t->wlen > t->wi) { |
182 | acpi_ec_write_data(ec, | 191 | if ((status & ACPI_EC_FLAG_IBF) == 0) |
183 | t->wdata[t->wi++]); | 192 | acpi_ec_write_data(ec, t->wdata[t->wi++]); |
184 | else | 193 | else |
185 | goto err; | 194 | goto err; |
186 | } else if (t->rlen > t->ri) { | 195 | } else if (t->rlen > t->ri) { |
187 | if ((status & ACPI_EC_FLAG_OBF) == 1) { | 196 | if ((status & ACPI_EC_FLAG_OBF) == 1) { |
188 | t->rdata[t->ri++] = acpi_ec_read_data(ec); | 197 | t->rdata[t->ri++] = acpi_ec_read_data(ec); |
189 | if (t->rlen == t->ri) | 198 | if (t->rlen == t->ri) { |
190 | t->done = true; | 199 | t->flags |= ACPI_EC_COMMAND_COMPLETE; |
200 | wakeup = true; | ||
201 | } | ||
202 | } else | ||
203 | goto err; | ||
204 | } else if (t->wlen == t->wi && | ||
205 | (status & ACPI_EC_FLAG_IBF) == 0) { | ||
206 | t->flags |= ACPI_EC_COMMAND_COMPLETE; | ||
207 | wakeup = true; | ||
208 | } | ||
209 | return wakeup; | ||
210 | } else { | ||
211 | if ((status & ACPI_EC_FLAG_IBF) == 0) { | ||
212 | acpi_ec_write_cmd(ec, t->command); | ||
213 | t->flags |= ACPI_EC_COMMAND_POLL; | ||
191 | } else | 214 | } else |
192 | goto err; | 215 | goto err; |
193 | } else if (t->wlen == t->wi && | 216 | return wakeup; |
194 | (status & ACPI_EC_FLAG_IBF) == 0) | 217 | } |
195 | t->done = true; | ||
196 | goto unlock; | ||
197 | err: | 218 | err: |
198 | /* | 219 | /* |
199 | * If SCI bit is set, then don't think it's a false IRQ | 220 | * If SCI bit is set, then don't think it's a false IRQ |
200 | * otherwise will take a not handled IRQ as a false one. | 221 | * otherwise will take a not handled IRQ as a false one. |
201 | */ | 222 | */ |
202 | if (in_interrupt() && !(status & ACPI_EC_FLAG_SCI)) | 223 | if (!(status & ACPI_EC_FLAG_SCI)) { |
203 | ++t->irq_count; | 224 | if (in_interrupt() && t) |
225 | ++t->irq_count; | ||
226 | } | ||
227 | return wakeup; | ||
228 | } | ||
204 | 229 | ||
205 | unlock: | 230 | static void start_transaction(struct acpi_ec *ec) |
206 | spin_unlock_irqrestore(&ec->lock, flags); | 231 | { |
232 | ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0; | ||
233 | ec->curr->flags = 0; | ||
234 | (void)advance_transaction(ec); | ||
207 | } | 235 | } |
208 | 236 | ||
209 | static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data); | 237 | static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data); |
@@ -228,15 +256,17 @@ static int ec_poll(struct acpi_ec *ec) | |||
228 | /* don't sleep with disabled interrupts */ | 256 | /* don't sleep with disabled interrupts */ |
229 | if (EC_FLAGS_MSI || irqs_disabled()) { | 257 | if (EC_FLAGS_MSI || irqs_disabled()) { |
230 | udelay(ACPI_EC_MSI_UDELAY); | 258 | udelay(ACPI_EC_MSI_UDELAY); |
231 | if (ec_transaction_done(ec)) | 259 | if (ec_transaction_completed(ec)) |
232 | return 0; | 260 | return 0; |
233 | } else { | 261 | } else { |
234 | if (wait_event_timeout(ec->wait, | 262 | if (wait_event_timeout(ec->wait, |
235 | ec_transaction_done(ec), | 263 | ec_transaction_completed(ec), |
236 | msecs_to_jiffies(1))) | 264 | msecs_to_jiffies(1))) |
237 | return 0; | 265 | return 0; |
238 | } | 266 | } |
239 | advance_transaction(ec, acpi_ec_read_status(ec)); | 267 | spin_lock_irqsave(&ec->lock, flags); |
268 | (void)advance_transaction(ec); | ||
269 | spin_unlock_irqrestore(&ec->lock, flags); | ||
240 | } while (time_before(jiffies, delay)); | 270 | } while (time_before(jiffies, delay)); |
241 | pr_debug("controller reset, restart transaction\n"); | 271 | pr_debug("controller reset, restart transaction\n"); |
242 | spin_lock_irqsave(&ec->lock, flags); | 272 | spin_lock_irqsave(&ec->lock, flags); |
@@ -268,23 +298,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, | |||
268 | return ret; | 298 | return ret; |
269 | } | 299 | } |
270 | 300 | ||
271 | static int ec_check_ibf0(struct acpi_ec *ec) | ||
272 | { | ||
273 | u8 status = acpi_ec_read_status(ec); | ||
274 | return (status & ACPI_EC_FLAG_IBF) == 0; | ||
275 | } | ||
276 | |||
277 | static int ec_wait_ibf0(struct acpi_ec *ec) | ||
278 | { | ||
279 | unsigned long delay = jiffies + msecs_to_jiffies(ec_delay); | ||
280 | /* interrupt wait manually if GPE mode is not active */ | ||
281 | while (time_before(jiffies, delay)) | ||
282 | if (wait_event_timeout(ec->wait, ec_check_ibf0(ec), | ||
283 | msecs_to_jiffies(1))) | ||
284 | return 0; | ||
285 | return -ETIME; | ||
286 | } | ||
287 | |||
288 | static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) | 301 | static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) |
289 | { | 302 | { |
290 | int status; | 303 | int status; |
@@ -305,12 +318,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) | |||
305 | goto unlock; | 318 | goto unlock; |
306 | } | 319 | } |
307 | } | 320 | } |
308 | if (ec_wait_ibf0(ec)) { | ||
309 | pr_err("input buffer is not empty, " | ||
310 | "aborting transaction\n"); | ||
311 | status = -ETIME; | ||
312 | goto end; | ||
313 | } | ||
314 | pr_debug("transaction start (cmd=0x%02x, addr=0x%02x)\n", | 321 | pr_debug("transaction start (cmd=0x%02x, addr=0x%02x)\n", |
315 | t->command, t->wdata ? t->wdata[0] : 0); | 322 | t->command, t->wdata ? t->wdata[0] : 0); |
316 | /* disable GPE during transaction if storm is detected */ | 323 | /* disable GPE during transaction if storm is detected */ |
@@ -334,7 +341,6 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) | |||
334 | set_bit(EC_FLAGS_GPE_STORM, &ec->flags); | 341 | set_bit(EC_FLAGS_GPE_STORM, &ec->flags); |
335 | } | 342 | } |
336 | pr_debug("transaction end\n"); | 343 | pr_debug("transaction end\n"); |
337 | end: | ||
338 | if (ec->global_lock) | 344 | if (ec->global_lock) |
339 | acpi_release_global_lock(glk); | 345 | acpi_release_global_lock(glk); |
340 | unlock: | 346 | unlock: |
@@ -634,17 +640,14 @@ static int ec_check_sci(struct acpi_ec *ec, u8 state) | |||
634 | static u32 acpi_ec_gpe_handler(acpi_handle gpe_device, | 640 | static u32 acpi_ec_gpe_handler(acpi_handle gpe_device, |
635 | u32 gpe_number, void *data) | 641 | u32 gpe_number, void *data) |
636 | { | 642 | { |
643 | unsigned long flags; | ||
637 | struct acpi_ec *ec = data; | 644 | struct acpi_ec *ec = data; |
638 | u8 status = acpi_ec_read_status(ec); | ||
639 | 645 | ||
640 | pr_debug("~~~> interrupt, status:0x%02x\n", status); | 646 | spin_lock_irqsave(&ec->lock, flags); |
641 | 647 | if (advance_transaction(ec)) | |
642 | advance_transaction(ec, status); | ||
643 | if (ec_transaction_done(ec) && | ||
644 | (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) == 0) { | ||
645 | wake_up(&ec->wait); | 648 | wake_up(&ec->wait); |
646 | ec_check_sci(ec, acpi_ec_read_status(ec)); | 649 | spin_unlock_irqrestore(&ec->lock, flags); |
647 | } | 650 | ec_check_sci(ec, acpi_ec_read_status(ec)); |
648 | return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE; | 651 | return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE; |
649 | } | 652 | } |
650 | 653 | ||
@@ -1066,8 +1069,10 @@ int __init acpi_ec_ecdt_probe(void) | |||
1066 | /* fall through */ | 1069 | /* fall through */ |
1067 | } | 1070 | } |
1068 | 1071 | ||
1069 | if (EC_FLAGS_SKIP_DSDT_SCAN) | 1072 | if (EC_FLAGS_SKIP_DSDT_SCAN) { |
1073 | kfree(saved_ec); | ||
1070 | return -ENODEV; | 1074 | return -ENODEV; |
1075 | } | ||
1071 | 1076 | ||
1072 | /* This workaround is needed only on some broken machines, | 1077 | /* This workaround is needed only on some broken machines, |
1073 | * which require early EC, but fail to provide ECDT */ | 1078 | * which require early EC, but fail to provide ECDT */ |
@@ -1105,6 +1110,7 @@ install: | |||
1105 | } | 1110 | } |
1106 | error: | 1111 | error: |
1107 | kfree(boot_ec); | 1112 | kfree(boot_ec); |
1113 | kfree(saved_ec); | ||
1108 | boot_ec = NULL; | 1114 | boot_ec = NULL; |
1109 | return -ENODEV; | 1115 | return -ENODEV; |
1110 | } | 1116 | } |