diff options
author | Henrique de Moraes Holschuh <hmh@hmh.eng.br> | 2007-04-21 10:08:39 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-04-21 23:30:34 -0400 |
commit | b86c4722de62f336b82dff3c47ef59ba2a587ec1 (patch) | |
tree | 9295b5e3f9590021c86bfdadecb72732861ec337 /drivers/misc/thinkpad_acpi.c | |
parent | d01320e606d334a0cd35d781a58f9f3c254829ab (diff) |
ACPI: thinkpad-acpi: clean up hotkey subdriver
Cleanup hotkey subdriver code.
Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/misc/thinkpad_acpi.c')
-rw-r--r-- | drivers/misc/thinkpad_acpi.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 809ec8400ec5..344eb551c443 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c | |||
@@ -511,6 +511,8 @@ static int hotkey_orig_mask; | |||
511 | 511 | ||
512 | static int __init hotkey_init(struct ibm_init_struct *iibm) | 512 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
513 | { | 513 | { |
514 | int res; | ||
515 | |||
514 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); | 516 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
515 | 517 | ||
516 | IBM_ACPIHANDLE_INIT(hkey); | 518 | IBM_ACPIHANDLE_INIT(hkey); |
@@ -530,8 +532,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
530 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", | 532 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
531 | str_supported(tp_features.hotkey_mask)); | 533 | str_supported(tp_features.hotkey_mask)); |
532 | 534 | ||
533 | if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask)) | 535 | res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); |
534 | return -ENODEV; | 536 | if (res) |
537 | return res; | ||
535 | } | 538 | } |
536 | 539 | ||
537 | return (tp_features.hotkey)? 0 : 1; | 540 | return (tp_features.hotkey)? 0 : 1; |
@@ -539,9 +542,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
539 | 542 | ||
540 | static void hotkey_exit(void) | 543 | static void hotkey_exit(void) |
541 | { | 544 | { |
545 | int res; | ||
546 | |||
542 | if (tp_features.hotkey) { | 547 | if (tp_features.hotkey) { |
543 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n"); | 548 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n"); |
544 | hotkey_set(hotkey_orig_status, hotkey_orig_mask); | 549 | res = hotkey_set(hotkey_orig_status, hotkey_orig_mask); |
550 | if (res) | ||
551 | printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n"); | ||
545 | } | 552 | } |
546 | } | 553 | } |
547 | 554 | ||
@@ -560,13 +567,13 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) | |||
560 | static int hotkey_get(int *status, int *mask) | 567 | static int hotkey_get(int *status, int *mask) |
561 | { | 568 | { |
562 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | 569 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
563 | return 0; | 570 | return -EIO; |
564 | 571 | ||
565 | if (tp_features.hotkey_mask) | 572 | if (tp_features.hotkey_mask) |
566 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) | 573 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) |
567 | return 0; | 574 | return -EIO; |
568 | 575 | ||
569 | return 1; | 576 | return 0; |
570 | } | 577 | } |
571 | 578 | ||
572 | static int hotkey_set(int status, int mask) | 579 | static int hotkey_set(int status, int mask) |
@@ -574,22 +581,22 @@ static int hotkey_set(int status, int mask) | |||
574 | int i; | 581 | int i; |
575 | 582 | ||
576 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) | 583 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
577 | return 0; | 584 | return -EIO; |
578 | 585 | ||
579 | if (tp_features.hotkey_mask) | 586 | if (tp_features.hotkey_mask) |
580 | for (i = 0; i < 32; i++) { | 587 | for (i = 0; i < 32; i++) { |
581 | int bit = ((1 << i) & mask) != 0; | 588 | int bit = ((1 << i) & mask) != 0; |
582 | if (!acpi_evalf(hkey_handle, | 589 | if (!acpi_evalf(hkey_handle, |
583 | NULL, "MHKM", "vdd", i + 1, bit)) | 590 | NULL, "MHKM", "vdd", i + 1, bit)) |
584 | return 0; | 591 | return -EIO; |
585 | } | 592 | } |
586 | 593 | ||
587 | return 1; | 594 | return 0; |
588 | } | 595 | } |
589 | 596 | ||
590 | static int hotkey_read(char *p) | 597 | static int hotkey_read(char *p) |
591 | { | 598 | { |
592 | int status, mask; | 599 | int res, status, mask; |
593 | int len = 0; | 600 | int len = 0; |
594 | 601 | ||
595 | if (!tp_features.hotkey) { | 602 | if (!tp_features.hotkey) { |
@@ -597,8 +604,9 @@ static int hotkey_read(char *p) | |||
597 | return len; | 604 | return len; |
598 | } | 605 | } |
599 | 606 | ||
600 | if (!hotkey_get(&status, &mask)) | 607 | res = hotkey_get(&status, &mask); |
601 | return -EIO; | 608 | if (res) |
609 | return res; | ||
602 | 610 | ||
603 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); | 611 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
604 | if (tp_features.hotkey_mask) { | 612 | if (tp_features.hotkey_mask) { |
@@ -615,15 +623,16 @@ static int hotkey_read(char *p) | |||
615 | 623 | ||
616 | static int hotkey_write(char *buf) | 624 | static int hotkey_write(char *buf) |
617 | { | 625 | { |
618 | int status, mask; | 626 | int res, status, mask; |
619 | char *cmd; | 627 | char *cmd; |
620 | int do_cmd = 0; | 628 | int do_cmd = 0; |
621 | 629 | ||
622 | if (!tp_features.hotkey) | 630 | if (!tp_features.hotkey) |
623 | return -ENODEV; | 631 | return -ENODEV; |
624 | 632 | ||
625 | if (!hotkey_get(&status, &mask)) | 633 | res = hotkey_get(&status, &mask); |
626 | return -EIO; | 634 | if (res) |
635 | return res; | ||
627 | 636 | ||
628 | while ((cmd = next_cmd(&buf))) { | 637 | while ((cmd = next_cmd(&buf))) { |
629 | if (strlencmp(cmd, "enable") == 0) { | 638 | if (strlencmp(cmd, "enable") == 0) { |
@@ -642,8 +651,11 @@ static int hotkey_write(char *buf) | |||
642 | do_cmd = 1; | 651 | do_cmd = 1; |
643 | } | 652 | } |
644 | 653 | ||
645 | if (do_cmd && !hotkey_set(status, mask)) | 654 | if (do_cmd) { |
646 | return -EIO; | 655 | res = hotkey_set(status, mask); |
656 | if (res) | ||
657 | return res; | ||
658 | } | ||
647 | 659 | ||
648 | return 0; | 660 | return 0; |
649 | } | 661 | } |