aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/ec.c
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2007-11-20 20:07:49 -0500
committerLen Brown <len.brown@intel.com>2007-11-20 20:07:49 -0500
commita3f095ade0f5fd2a09a7f523632d762314452871 (patch)
tree24e23bc2077ae866be9c43cc1f419db46f043714 /drivers/acpi/ec.c
parente6532b8883760bdf9d251c669a3919fc9457aeca (diff)
parente790cc8bbb990df900eabdda18a5a480d22a60c8 (diff)
Pull bugzilla-9327 into release branch
Conflicts: drivers/acpi/ec.c Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/ec.c')
-rw-r--r--drivers/acpi/ec.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index c5028568058b..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 */
@@ -77,6 +80,8 @@ enum {
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_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */ 81 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
79 EC_FLAGS_ADDRESS, /* Address is being written */ 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 */
80}; 85};
81 86
82static int acpi_ec_remove(struct acpi_device *device, int type); 87static int acpi_ec_remove(struct acpi_device *device, int type);
@@ -132,21 +137,27 @@ static struct acpi_ec {
132 137
133static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 138static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
134{ 139{
135 return inb(ec->command_addr); 140 u8 x = inb(ec->command_addr);
141 pr_debug(PREFIX "---> status = 0x%2x\n", x);
142 return x;
136} 143}
137 144
138static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 145static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
139{ 146{
147 u8 x = inb(ec->data_addr);
148 pr_debug(PREFIX "---> data = 0x%2x\n", x);
140 return inb(ec->data_addr); 149 return inb(ec->data_addr);
141} 150}
142 151
143static 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)
144{ 153{
154 pr_debug(PREFIX "<--- command = 0x%2x\n", command);
145 outb(command, ec->command_addr); 155 outb(command, ec->command_addr);
146} 156}
147 157
148static 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)
149{ 159{
160 pr_debug(PREFIX "<--- data = 0x%2x\n", data);
150 outb(data, ec->data_addr); 161 outb(data, ec->data_addr);
151} 162}
152 163
@@ -171,6 +182,9 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
171 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) && 182 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
172 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags))) 183 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
173 force_poll = 1; 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;
174 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && 188 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
175 likely(!force_poll)) { 189 likely(!force_poll)) {
176 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),
@@ -180,13 +194,19 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
180 if (acpi_ec_check_status(ec, event)) { 194 if (acpi_ec_check_status(ec, event)) {
181 if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) { 195 if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
182 /* miss address GPE, don't expect it anymore */ 196 /* miss address GPE, don't expect it anymore */
183 printk(KERN_INFO PREFIX "missing address confirmation, " 197 pr_info(PREFIX "missing address confirmation, "
184 "don't expect it any longer.\n"); 198 "don't expect it any longer.\n");
185 set_bit(EC_FLAGS_NO_ADDRESS_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);
186 } else { 205 } else {
187 /* missing GPEs, switch back to poll mode */ 206 /* missing GPEs, switch back to poll mode */
188 printk(KERN_INFO PREFIX "missing confirmations, " 207 if (printk_ratelimit())
189 "switch off interrupt mode.\n"); 208 pr_info(PREFIX "missing confirmations, "
209 "switch off interrupt mode.\n");
190 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 210 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
191 } 211 }
192 goto end; 212 goto end;
@@ -199,7 +219,7 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
199 goto end; 219 goto end;
200 } 220 }
201 } 221 }
202 printk(KERN_ERR PREFIX "acpi_ec_wait timeout," 222 pr_err(PREFIX "acpi_ec_wait timeout,"
203 " status = %d, expect_event = %d\n", 223 " status = %d, expect_event = %d\n",
204 acpi_ec_read_status(ec), event); 224 acpi_ec_read_status(ec), event);
205 ret = -ETIME; 225 ret = -ETIME;
@@ -216,11 +236,11 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
216 int result = 0; 236 int result = 0;
217 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 237 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
218 acpi_ec_write_cmd(ec, command); 238 acpi_ec_write_cmd(ec, command);
219 239 pr_debug(PREFIX "transaction start\n");
220 for (; wdata_len > 0; --wdata_len) { 240 for (; wdata_len > 0; --wdata_len) {
221 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);
222 if (result) { 242 if (result) {
223 printk(KERN_ERR PREFIX 243 pr_err(PREFIX
224 "write_cmd timeout, command = %d\n", command); 244 "write_cmd timeout, command = %d\n", command);
225 goto end; 245 goto end;
226 } 246 }
@@ -232,9 +252,10 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
232 } 252 }
233 253
234 if (!rdata_len) { 254 if (!rdata_len) {
255 set_bit(EC_FLAGS_WDATA, &ec->flags);
235 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);
236 if (result) { 257 if (result) {
237 printk(KERN_ERR PREFIX 258 pr_err(PREFIX
238 "finish-write timeout, command = %d\n", command); 259 "finish-write timeout, command = %d\n", command);
239 goto end; 260 goto end;
240 } 261 }
@@ -244,8 +265,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
244 for (; rdata_len > 0; --rdata_len) { 265 for (; rdata_len > 0; --rdata_len) {
245 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);
246 if (result) { 267 if (result) {
247 printk(KERN_ERR PREFIX "read timeout, command = %d\n", 268 pr_err(PREFIX "read timeout, command = %d\n", command);
248 command);
249 goto end; 269 goto end;
250 } 270 }
251 /* Don't expect GPE after last read */ 271 /* Don't expect GPE after last read */
@@ -254,6 +274,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
254 *(rdata++) = acpi_ec_read_data(ec); 274 *(rdata++) = acpi_ec_read_data(ec);
255 } 275 }
256 end: 276 end:
277 pr_debug(PREFIX "transaction end\n");
257 return result; 278 return result;
258} 279}
259 280
@@ -282,8 +303,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
282 303
283 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); 304 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
284 if (status) { 305 if (status) {
285 printk(KERN_ERR PREFIX 306 pr_err(PREFIX "input buffer is not empty, "
286 "input buffer is not empty, aborting transaction\n"); 307 "aborting transaction\n");
287 goto end; 308 goto end;
288 } 309 }
289 310
@@ -497,6 +518,7 @@ static u32 acpi_ec_gpe_handler(void *data)
497 acpi_status status = AE_OK; 518 acpi_status status = AE_OK;
498 struct acpi_ec *ec = data; 519 struct acpi_ec *ec = data;
499 520
521 pr_debug(PREFIX "~~~> interrupt\n");
500 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 522 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
501 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) 523 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
502 wake_up(&ec->wait); 524 wake_up(&ec->wait);
@@ -507,8 +529,9 @@ static u32 acpi_ec_gpe_handler(void *data)
507 acpi_ec_gpe_query, ec); 529 acpi_ec_gpe_query, ec);
508 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { 530 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
509 /* this is non-query, must be confirmation */ 531 /* this is non-query, must be confirmation */
510 printk(KERN_INFO PREFIX "non-query interrupt received," 532 if (printk_ratelimit())
511 " switching to interrupt mode\n"); 533 pr_info(PREFIX "non-query interrupt received,"
534 " switching to interrupt mode\n");
512 set_bit(EC_FLAGS_GPE_MODE, &ec->flags); 535 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
513 } 536 }
514 537
@@ -710,10 +733,10 @@ static void ec_remove_handlers(struct acpi_ec *ec)
710{ 733{
711 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 734 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
712 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 735 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
713 printk(KERN_ERR PREFIX "failed to remove space handler\n"); 736 pr_err(PREFIX "failed to remove space handler\n");
714 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, 737 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
715 &acpi_ec_gpe_handler))) 738 &acpi_ec_gpe_handler)))
716 printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); 739 pr_err(PREFIX "failed to remove gpe handler\n");
717 ec->handlers_installed = 0; 740 ec->handlers_installed = 0;
718} 741}
719 742
@@ -756,9 +779,9 @@ static int acpi_ec_add(struct acpi_device *device)
756 first_ec = ec; 779 first_ec = ec;
757 acpi_driver_data(device) = ec; 780 acpi_driver_data(device) = ec;
758 acpi_ec_add_fs(device); 781 acpi_ec_add_fs(device);
759 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",
760 ec->gpe, ec->command_addr, ec->data_addr); 783 ec->gpe, ec->command_addr, ec->data_addr);
761 printk(KERN_INFO PREFIX "driver started in %s mode\n", 784 pr_info(PREFIX "driver started in %s mode\n",
762 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); 785 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
763 return 0; 786 return 0;
764} 787}
@@ -884,7 +907,7 @@ int __init acpi_ec_ecdt_probe(void)
884 status = acpi_get_table(ACPI_SIG_ECDT, 1, 907 status = acpi_get_table(ACPI_SIG_ECDT, 1,
885 (struct acpi_table_header **)&ecdt_ptr); 908 (struct acpi_table_header **)&ecdt_ptr);
886 if (ACPI_SUCCESS(status)) { 909 if (ACPI_SUCCESS(status)) {
887 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");
888 boot_ec->command_addr = ecdt_ptr->control.address; 911 boot_ec->command_addr = ecdt_ptr->control.address;
889 boot_ec->data_addr = ecdt_ptr->data.address; 912 boot_ec->data_addr = ecdt_ptr->data.address;
890 boot_ec->gpe = ecdt_ptr->gpe; 913 boot_ec->gpe = ecdt_ptr->gpe;