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.c100
1 files changed, 70 insertions, 30 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 06b78e5e33a1..d411017f8c06 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -47,6 +47,9 @@
47#undef PREFIX 47#undef PREFIX
48#define PREFIX "ACPI: EC: " 48#define PREFIX "ACPI: EC: "
49 49
50/* Uncomment next line to get verbose print outs*/
51/* #define DEBUG */
52
50/* EC status register */ 53/* EC status register */
51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 54#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 55#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
@@ -75,7 +78,10 @@ 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 */
79}; 85};
80 86
81static int acpi_ec_remove(struct acpi_device *device, int type); 87static int acpi_ec_remove(struct acpi_device *device, int type);
@@ -131,21 +137,27 @@ static struct acpi_ec {
131 137
132static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 138static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
133{ 139{
134 return inb(ec->command_addr); 140 u8 x = inb(ec->command_addr);
141 pr_debug(PREFIX "---> status = 0x%2x\n", x);
142 return x;
135} 143}
136 144
137static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 145static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
138{ 146{
147 u8 x = inb(ec->data_addr);
148 pr_debug(PREFIX "---> data = 0x%2x\n", x);
139 return inb(ec->data_addr); 149 return inb(ec->data_addr);
140} 150}
141 151
142static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) 152static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
143{ 153{
154 pr_debug(PREFIX "<--- command = 0x%2x\n", command);
144 outb(command, ec->command_addr); 155 outb(command, ec->command_addr);
145} 156}
146 157
147static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) 158static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
148{ 159{
160 pr_debug(PREFIX "<--- data = 0x%2x\n", data);
149 outb(data, ec->data_addr); 161 outb(data, ec->data_addr);
150} 162}
151 163
@@ -166,38 +178,54 @@ static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
166 178
167static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) 179static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
168{ 180{
181 int ret = 0;
182 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
183 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
184 force_poll = 1;
185 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) &&
186 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags)))
187 force_poll = 1;
169 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && 188 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
170 likely(!force_poll)) { 189 likely(!force_poll)) {
171 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), 190 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
172 msecs_to_jiffies(ACPI_EC_DELAY))) 191 msecs_to_jiffies(ACPI_EC_DELAY)))
173 return 0; 192 goto end;
174 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 193 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
175 if (acpi_ec_check_status(ec, event)) { 194 if (acpi_ec_check_status(ec, event)) {
176 if (event == ACPI_EC_EVENT_OBF_1) { 195 if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
177 /* miss OBF = 1 GPE, don't expect it anymore */ 196 /* miss address GPE, don't expect it anymore */
178 printk(KERN_INFO PREFIX "missing OBF_1 confirmation," 197 pr_info(PREFIX "missing address confirmation, "
179 "switching to degraded mode.\n"); 198 "don't expect it any longer.\n");
180 set_bit(EC_FLAGS_ONLY_IBF_GPE, &ec->flags); 199 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
200 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
201 /* miss write data GPE, don't expect it */
202 pr_info(PREFIX "missing write data confirmation, "
203 "don't expect it any longer.\n");
204 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
181 } else { 205 } else {
182 /* missing GPEs, switch back to poll mode */ 206 /* missing GPEs, switch back to poll mode */
183 printk(KERN_INFO PREFIX "missing IBF_1 confirmations," 207 if (printk_ratelimit())
184 "switch off interrupt mode.\n"); 208 pr_info(PREFIX "missing confirmations, "
209 "switch off interrupt mode.\n");
185 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 210 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
186 } 211 }
187 return 0; 212 goto end;
188 } 213 }
189 } else { 214 } else {
190 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 215 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
191 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 216 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
192 while (time_before(jiffies, delay)) { 217 while (time_before(jiffies, delay)) {
193 if (acpi_ec_check_status(ec, event)) 218 if (acpi_ec_check_status(ec, event))
194 return 0; 219 goto end;
195 } 220 }
196 } 221 }
197 printk(KERN_ERR PREFIX "acpi_ec_wait timeout," 222 pr_err(PREFIX "acpi_ec_wait timeout,"
198 " status = %d, expect_event = %d\n", 223 " status = %d, expect_event = %d\n",
199 acpi_ec_read_status(ec), event); 224 acpi_ec_read_status(ec), event);
200 return -ETIME; 225 ret = -ETIME;
226 end:
227 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
228 return ret;
201} 229}
202 230
203static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 231static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
@@ -208,22 +236,26 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
208 int result = 0; 236 int result = 0;
209 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 237 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
210 acpi_ec_write_cmd(ec, command); 238 acpi_ec_write_cmd(ec, command);
211 239 pr_debug(PREFIX "transaction start\n");
212 for (; wdata_len > 0; --wdata_len) { 240 for (; wdata_len > 0; --wdata_len) {
213 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 241 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
214 if (result) { 242 if (result) {
215 printk(KERN_ERR PREFIX 243 pr_err(PREFIX
216 "write_cmd timeout, command = %d\n", command); 244 "write_cmd timeout, command = %d\n", command);
217 goto end; 245 goto end;
218 } 246 }
247 /* mark the address byte written to EC */
248 if (rdata_len + wdata_len > 1)
249 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
219 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 250 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
220 acpi_ec_write_data(ec, *(wdata++)); 251 acpi_ec_write_data(ec, *(wdata++));
221 } 252 }
222 253
223 if (!rdata_len) { 254 if (!rdata_len) {
255 set_bit(EC_FLAGS_WDATA, &ec->flags);
224 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 256 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
225 if (result) { 257 if (result) {
226 printk(KERN_ERR PREFIX 258 pr_err(PREFIX
227 "finish-write timeout, command = %d\n", command); 259 "finish-write timeout, command = %d\n", command);
228 goto end; 260 goto end;
229 } 261 }
@@ -231,12 +263,9 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
231 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 263 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
232 264
233 for (; rdata_len > 0; --rdata_len) { 265 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); 266 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
237 if (result) { 267 if (result) {
238 printk(KERN_ERR PREFIX "read timeout, command = %d\n", 268 pr_err(PREFIX "read timeout, command = %d\n", command);
239 command);
240 goto end; 269 goto end;
241 } 270 }
242 /* Don't expect GPE after last read */ 271 /* Don't expect GPE after last read */
@@ -245,6 +274,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
245 *(rdata++) = acpi_ec_read_data(ec); 274 *(rdata++) = acpi_ec_read_data(ec);
246 } 275 }
247 end: 276 end:
277 pr_debug(PREFIX "transaction end\n");
248 return result; 278 return result;
249} 279}
250 280
@@ -273,8 +303,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
273 303
274 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); 304 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
275 if (status) { 305 if (status) {
276 printk(KERN_ERR PREFIX 306 pr_err(PREFIX "input buffer is not empty, "
277 "input buffer is not empty, aborting transaction\n"); 307 "aborting transaction\n");
278 goto end; 308 goto end;
279 } 309 }
280 310
@@ -488,6 +518,7 @@ static u32 acpi_ec_gpe_handler(void *data)
488 acpi_status status = AE_OK; 518 acpi_status status = AE_OK;
489 struct acpi_ec *ec = data; 519 struct acpi_ec *ec = data;
490 520
521 pr_debug(PREFIX "~~~> interrupt\n");
491 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 522 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
492 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) 523 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
493 wake_up(&ec->wait); 524 wake_up(&ec->wait);
@@ -498,8 +529,9 @@ static u32 acpi_ec_gpe_handler(void *data)
498 acpi_ec_gpe_query, ec); 529 acpi_ec_gpe_query, ec);
499 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { 530 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
500 /* this is non-query, must be confirmation */ 531 /* this is non-query, must be confirmation */
501 printk(KERN_INFO PREFIX "non-query interrupt received," 532 if (printk_ratelimit())
502 " switching to interrupt mode\n"); 533 pr_info(PREFIX "non-query interrupt received,"
534 " switching to interrupt mode\n");
503 set_bit(EC_FLAGS_GPE_MODE, &ec->flags); 535 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
504 } 536 }
505 537
@@ -701,10 +733,10 @@ static void ec_remove_handlers(struct acpi_ec *ec)
701{ 733{
702 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 734 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
703 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 735 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
704 printk(KERN_ERR PREFIX "failed to remove space handler\n"); 736 pr_err(PREFIX "failed to remove space handler\n");
705 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, 737 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
706 &acpi_ec_gpe_handler))) 738 &acpi_ec_gpe_handler)))
707 printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); 739 pr_err(PREFIX "failed to remove gpe handler\n");
708 ec->handlers_installed = 0; 740 ec->handlers_installed = 0;
709} 741}
710 742
@@ -747,9 +779,9 @@ static int acpi_ec_add(struct acpi_device *device)
747 first_ec = ec; 779 first_ec = ec;
748 acpi_driver_data(device) = ec; 780 acpi_driver_data(device) = ec;
749 acpi_ec_add_fs(device); 781 acpi_ec_add_fs(device);
750 printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", 782 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); 783 ec->gpe, ec->command_addr, ec->data_addr);
752 printk(KERN_INFO PREFIX "driver started in %s mode\n", 784 pr_info(PREFIX "driver started in %s mode\n",
753 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); 785 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
754 return 0; 786 return 0;
755} 787}
@@ -875,18 +907,26 @@ int __init acpi_ec_ecdt_probe(void)
875 status = acpi_get_table(ACPI_SIG_ECDT, 1, 907 status = acpi_get_table(ACPI_SIG_ECDT, 1,
876 (struct acpi_table_header **)&ecdt_ptr); 908 (struct acpi_table_header **)&ecdt_ptr);
877 if (ACPI_SUCCESS(status)) { 909 if (ACPI_SUCCESS(status)) {
878 printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); 910 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
879 boot_ec->command_addr = ecdt_ptr->control.address; 911 boot_ec->command_addr = ecdt_ptr->control.address;
880 boot_ec->data_addr = ecdt_ptr->data.address; 912 boot_ec->data_addr = ecdt_ptr->data.address;
881 boot_ec->gpe = ecdt_ptr->gpe; 913 boot_ec->gpe = ecdt_ptr->gpe;
882 boot_ec->handle = ACPI_ROOT_OBJECT; 914 boot_ec->handle = ACPI_ROOT_OBJECT;
883 } else { 915 } else {
916 /* This workaround is needed only on some broken machines,
917 * which require early EC, but fail to provide ECDT */
918 acpi_handle x;
884 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); 919 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
885 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, 920 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
886 boot_ec, NULL); 921 boot_ec, NULL);
887 /* Check that acpi_get_devices actually find something */ 922 /* Check that acpi_get_devices actually find something */
888 if (ACPI_FAILURE(status) || !boot_ec->handle) 923 if (ACPI_FAILURE(status) || !boot_ec->handle)
889 goto error; 924 goto error;
925 /* We really need to limit this workaround, the only ASUS,
926 * which needs it, has fake EC._INI method, so use it as flag.
927 */
928 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
929 goto error;
890 } 930 }
891 931
892 ret = ec_install_handlers(boot_ec); 932 ret = ec_install_handlers(boot_ec);