aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ec.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r--drivers/acpi/ec.c139
1 files changed, 106 insertions, 33 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 06b78e5e33a1..7222a18a0319 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -26,6 +26,9 @@
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 */ 27 */
28 28
29/* Uncomment next line to get verbose print outs*/
30/* #define DEBUG */
31
29#include <linux/kernel.h> 32#include <linux/kernel.h>
30#include <linux/module.h> 33#include <linux/module.h>
31#include <linux/init.h> 34#include <linux/init.h>
@@ -75,7 +78,11 @@ enum {
75 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */ 78 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
76 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 79 EC_FLAGS_QUERY_PENDING, /* Query is pending */
77 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */ 80 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
78 EC_FLAGS_ONLY_IBF_GPE, /* Expect GPE only for IBF = 0 event */ 81 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
82 EC_FLAGS_ADDRESS, /* Address is being written */
83 EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */
84 EC_FLAGS_WDATA, /* Data is being written */
85 EC_FLAGS_NO_OBF1_GPE, /* Don't expect GPE before read */
79}; 86};
80 87
81static int acpi_ec_remove(struct acpi_device *device, int type); 88static int acpi_ec_remove(struct acpi_device *device, int type);
@@ -131,21 +138,27 @@ static struct acpi_ec {
131 138
132static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 139static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
133{ 140{
134 return inb(ec->command_addr); 141 u8 x = inb(ec->command_addr);
142 pr_debug(PREFIX "---> status = 0x%2.2x\n", x);
143 return x;
135} 144}
136 145
137static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 146static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
138{ 147{
148 u8 x = inb(ec->data_addr);
149 pr_debug(PREFIX "---> data = 0x%2.2x\n", x);
139 return inb(ec->data_addr); 150 return inb(ec->data_addr);
140} 151}
141 152
142static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) 153static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
143{ 154{
155 pr_debug(PREFIX "<--- command = 0x%2.2x\n", command);
144 outb(command, ec->command_addr); 156 outb(command, ec->command_addr);
145} 157}
146 158
147static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) 159static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
148{ 160{
161 pr_debug(PREFIX "<--- data = 0x%2.2x\n", data);
149 outb(data, ec->data_addr); 162 outb(data, ec->data_addr);
150} 163}
151 164
@@ -166,38 +179,63 @@ static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
166 179
167static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) 180static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
168{ 181{
182 int ret = 0;
183
184 if (unlikely(event == ACPI_EC_EVENT_OBF_1 &&
185 test_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags)))
186 force_poll = 1;
187 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
188 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
189 force_poll = 1;
190 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) &&
191 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags)))
192 force_poll = 1;
169 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && 193 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
170 likely(!force_poll)) { 194 likely(!force_poll)) {
171 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), 195 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
172 msecs_to_jiffies(ACPI_EC_DELAY))) 196 msecs_to_jiffies(ACPI_EC_DELAY)))
173 return 0; 197 goto end;
174 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 198 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
175 if (acpi_ec_check_status(ec, event)) { 199 if (acpi_ec_check_status(ec, event)) {
176 if (event == ACPI_EC_EVENT_OBF_1) { 200 if (event == ACPI_EC_EVENT_OBF_1) {
177 /* miss OBF = 1 GPE, don't expect it anymore */ 201 /* miss OBF_1 GPE, don't expect it */
178 printk(KERN_INFO PREFIX "missing OBF_1 confirmation," 202 pr_info(PREFIX "missing OBF confirmation, "
179 "switching to degraded mode.\n"); 203 "don't expect it any longer.\n");
180 set_bit(EC_FLAGS_ONLY_IBF_GPE, &ec->flags); 204 set_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags);
205 } else if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
206 /* miss address GPE, don't expect it anymore */
207 pr_info(PREFIX "missing address confirmation, "
208 "don't expect it any longer.\n");
209 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
210 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
211 /* miss write data GPE, don't expect it */
212 pr_info(PREFIX "missing write data confirmation, "
213 "don't expect it any longer.\n");
214 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
181 } else { 215 } else {
182 /* missing GPEs, switch back to poll mode */ 216 /* missing GPEs, switch back to poll mode */
183 printk(KERN_INFO PREFIX "missing IBF_1 confirmations," 217 if (printk_ratelimit())
184 "switch off interrupt mode.\n"); 218 pr_info(PREFIX "missing confirmations, "
219 "switch off interrupt mode.\n");
185 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 220 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
186 } 221 }
187 return 0; 222 goto end;
188 } 223 }
189 } else { 224 } else {
190 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 225 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
191 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 226 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
192 while (time_before(jiffies, delay)) { 227 while (time_before(jiffies, delay)) {
193 if (acpi_ec_check_status(ec, event)) 228 if (acpi_ec_check_status(ec, event))
194 return 0; 229 goto end;
195 } 230 }
196 } 231 }
197 printk(KERN_ERR PREFIX "acpi_ec_wait timeout," 232 pr_err(PREFIX "acpi_ec_wait timeout,"
198 " status = %d, expect_event = %d\n", 233 " status = %d, expect_event = %d\n",
199 acpi_ec_read_status(ec), event); 234 acpi_ec_read_status(ec), event);
200 return -ETIME; 235 ret = -ETIME;
236 end:
237 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
238 return ret;
201} 239}
202 240
203static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 241static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
@@ -208,22 +246,26 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
208 int result = 0; 246 int result = 0;
209 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 247 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
210 acpi_ec_write_cmd(ec, command); 248 acpi_ec_write_cmd(ec, command);
211 249 pr_debug(PREFIX "transaction start\n");
212 for (; wdata_len > 0; --wdata_len) { 250 for (; wdata_len > 0; --wdata_len) {
213 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 251 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
214 if (result) { 252 if (result) {
215 printk(KERN_ERR PREFIX 253 pr_err(PREFIX
216 "write_cmd timeout, command = %d\n", command); 254 "write_cmd timeout, command = %d\n", command);
217 goto end; 255 goto end;
218 } 256 }
257 /* mark the address byte written to EC */
258 if (rdata_len + wdata_len > 1)
259 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
219 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 260 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
220 acpi_ec_write_data(ec, *(wdata++)); 261 acpi_ec_write_data(ec, *(wdata++));
221 } 262 }
222 263
223 if (!rdata_len) { 264 if (!rdata_len) {
265 set_bit(EC_FLAGS_WDATA, &ec->flags);
224 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 266 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
225 if (result) { 267 if (result) {
226 printk(KERN_ERR PREFIX 268 pr_err(PREFIX
227 "finish-write timeout, command = %d\n", command); 269 "finish-write timeout, command = %d\n", command);
228 goto end; 270 goto end;
229 } 271 }
@@ -231,12 +273,9 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
231 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 273 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
232 274
233 for (; rdata_len > 0; --rdata_len) { 275 for (; rdata_len > 0; --rdata_len) {
234 if (test_bit(EC_FLAGS_ONLY_IBF_GPE, &ec->flags))
235 force_poll = 1;
236 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll); 276 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
237 if (result) { 277 if (result) {
238 printk(KERN_ERR PREFIX "read timeout, command = %d\n", 278 pr_err(PREFIX "read timeout, command = %d\n", command);
239 command);
240 goto end; 279 goto end;
241 } 280 }
242 /* Don't expect GPE after last read */ 281 /* Don't expect GPE after last read */
@@ -245,6 +284,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
245 *(rdata++) = acpi_ec_read_data(ec); 284 *(rdata++) = acpi_ec_read_data(ec);
246 } 285 }
247 end: 286 end:
287 pr_debug(PREFIX "transaction end\n");
248 return result; 288 return result;
249} 289}
250 290
@@ -273,8 +313,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
273 313
274 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); 314 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
275 if (status) { 315 if (status) {
276 printk(KERN_ERR PREFIX 316 pr_err(PREFIX "input buffer is not empty, "
277 "input buffer is not empty, aborting transaction\n"); 317 "aborting transaction\n");
278 goto end; 318 goto end;
279 } 319 }
280 320
@@ -488,6 +528,7 @@ static u32 acpi_ec_gpe_handler(void *data)
488 acpi_status status = AE_OK; 528 acpi_status status = AE_OK;
489 struct acpi_ec *ec = data; 529 struct acpi_ec *ec = data;
490 530
531 pr_debug(PREFIX "~~~> interrupt\n");
491 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 532 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
492 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) 533 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
493 wake_up(&ec->wait); 534 wake_up(&ec->wait);
@@ -498,8 +539,9 @@ static u32 acpi_ec_gpe_handler(void *data)
498 acpi_ec_gpe_query, ec); 539 acpi_ec_gpe_query, ec);
499 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { 540 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
500 /* this is non-query, must be confirmation */ 541 /* this is non-query, must be confirmation */
501 printk(KERN_INFO PREFIX "non-query interrupt received," 542 if (printk_ratelimit())
502 " switching to interrupt mode\n"); 543 pr_info(PREFIX "non-query interrupt received,"
544 " switching to interrupt mode\n");
503 set_bit(EC_FLAGS_GPE_MODE, &ec->flags); 545 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
504 } 546 }
505 547
@@ -531,7 +573,7 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address,
531 void *handler_context, void *region_context) 573 void *handler_context, void *region_context)
532{ 574{
533 struct acpi_ec *ec = handler_context; 575 struct acpi_ec *ec = handler_context;
534 int result = 0, i = 0; 576 int result = 0, i;
535 u8 temp = 0; 577 u8 temp = 0;
536 578
537 if ((address > 0xFF) || !value || !handler_context) 579 if ((address > 0xFF) || !value || !handler_context)
@@ -543,7 +585,18 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address,
543 if (bits != 8 && acpi_strict) 585 if (bits != 8 && acpi_strict)
544 return AE_BAD_PARAMETER; 586 return AE_BAD_PARAMETER;
545 587
546 while (bits - i > 0) { 588 acpi_ec_burst_enable(ec);
589
590 if (function == ACPI_READ) {
591 result = acpi_ec_read(ec, address, &temp);
592 *value = temp;
593 } else {
594 temp = 0xff & (*value);
595 result = acpi_ec_write(ec, address, temp);
596 }
597
598 for (i = 8; unlikely(bits - i > 0); i += 8) {
599 ++address;
547 if (function == ACPI_READ) { 600 if (function == ACPI_READ) {
548 result = acpi_ec_read(ec, address, &temp); 601 result = acpi_ec_read(ec, address, &temp);
549 (*value) |= ((acpi_integer)temp) << i; 602 (*value) |= ((acpi_integer)temp) << i;
@@ -551,10 +604,10 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address,
551 temp = 0xff & ((*value) >> i); 604 temp = 0xff & ((*value) >> i);
552 result = acpi_ec_write(ec, address, temp); 605 result = acpi_ec_write(ec, address, temp);
553 } 606 }
554 i += 8;
555 ++address;
556 } 607 }
557 608
609 acpi_ec_burst_disable(ec);
610
558 switch (result) { 611 switch (result) {
559 case -EINVAL: 612 case -EINVAL:
560 return AE_BAD_PARAMETER; 613 return AE_BAD_PARAMETER;
@@ -701,10 +754,10 @@ static void ec_remove_handlers(struct acpi_ec *ec)
701{ 754{
702 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 755 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
703 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 756 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
704 printk(KERN_ERR PREFIX "failed to remove space handler\n"); 757 pr_err(PREFIX "failed to remove space handler\n");
705 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, 758 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
706 &acpi_ec_gpe_handler))) 759 &acpi_ec_gpe_handler)))
707 printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); 760 pr_err(PREFIX "failed to remove gpe handler\n");
708 ec->handlers_installed = 0; 761 ec->handlers_installed = 0;
709} 762}
710 763
@@ -747,9 +800,9 @@ static int acpi_ec_add(struct acpi_device *device)
747 first_ec = ec; 800 first_ec = ec;
748 acpi_driver_data(device) = ec; 801 acpi_driver_data(device) = ec;
749 acpi_ec_add_fs(device); 802 acpi_ec_add_fs(device);
750 printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", 803 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
751 ec->gpe, ec->command_addr, ec->data_addr); 804 ec->gpe, ec->command_addr, ec->data_addr);
752 printk(KERN_INFO PREFIX "driver started in %s mode\n", 805 pr_info(PREFIX "driver started in %s mode\n",
753 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); 806 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
754 return 0; 807 return 0;
755} 808}
@@ -860,6 +913,17 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
860 return 0; 913 return 0;
861} 914}
862 915
916int __init acpi_boot_ec_enable(void)
917{
918 if (!boot_ec || boot_ec->handlers_installed)
919 return 0;
920 if (!ec_install_handlers(boot_ec)) {
921 first_ec = boot_ec;
922 return 0;
923 }
924 return -EFAULT;
925}
926
863int __init acpi_ec_ecdt_probe(void) 927int __init acpi_ec_ecdt_probe(void)
864{ 928{
865 int ret; 929 int ret;
@@ -875,18 +939,27 @@ int __init acpi_ec_ecdt_probe(void)
875 status = acpi_get_table(ACPI_SIG_ECDT, 1, 939 status = acpi_get_table(ACPI_SIG_ECDT, 1,
876 (struct acpi_table_header **)&ecdt_ptr); 940 (struct acpi_table_header **)&ecdt_ptr);
877 if (ACPI_SUCCESS(status)) { 941 if (ACPI_SUCCESS(status)) {
878 printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); 942 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
879 boot_ec->command_addr = ecdt_ptr->control.address; 943 boot_ec->command_addr = ecdt_ptr->control.address;
880 boot_ec->data_addr = ecdt_ptr->data.address; 944 boot_ec->data_addr = ecdt_ptr->data.address;
881 boot_ec->gpe = ecdt_ptr->gpe; 945 boot_ec->gpe = ecdt_ptr->gpe;
882 boot_ec->handle = ACPI_ROOT_OBJECT; 946 boot_ec->handle = ACPI_ROOT_OBJECT;
883 } else { 947 } else {
948 /* This workaround is needed only on some broken machines,
949 * which require early EC, but fail to provide ECDT */
950 acpi_handle x;
884 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); 951 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
885 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, 952 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
886 boot_ec, NULL); 953 boot_ec, NULL);
887 /* Check that acpi_get_devices actually find something */ 954 /* Check that acpi_get_devices actually find something */
888 if (ACPI_FAILURE(status) || !boot_ec->handle) 955 if (ACPI_FAILURE(status) || !boot_ec->handle)
889 goto error; 956 goto error;
957 /* We really need to limit this workaround, the only ASUS,
958 * which needs it, has fake EC._INI method, so use it as flag.
959 * Keep boot_ec struct as it will be needed soon.
960 */
961 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
962 return -ENODEV;
890 } 963 }
891 964
892 ret = ec_install_handlers(boot_ec); 965 ret = ec_install_handlers(boot_ec);