aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2015-03-02 08:45:22 -0500
committerDarren Hart <dvhart@linux.intel.com>2015-03-03 11:59:35 -0500
commitf74587fb9308dd6d4346180672d79b8a861f02dd (patch)
tree45ed1f2ede3a93fe9adf5a1e7acb55d851ac3b31 /drivers/platform/x86
parentf23a5bcb70586231b5130a08de965592afdcf9cd (diff)
thinkpad_acpi: Factor out get/set adaptive kbd mode
Move the getting/setting of the adaptive keyboard mode to separate functions, so that we can reuse them later through sysfs attributes. Signed-off-by: Bastien Nocera <hadess@hadess.net> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Diffstat (limited to 'drivers/platform/x86')
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c61
1 files changed, 38 insertions, 23 deletions
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 763aef0e7764..5dea4c270482 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3483,6 +3483,32 @@ static const int adaptive_keyboard_modes[] = {
3483static bool adaptive_keyboard_mode_is_saved; 3483static bool adaptive_keyboard_mode_is_saved;
3484static int adaptive_keyboard_prev_mode; 3484static int adaptive_keyboard_prev_mode;
3485 3485
3486static int adaptive_keyboard_get_mode(void)
3487{
3488 int mode = 0;
3489
3490 if (!acpi_evalf(hkey_handle, &mode, "GTRW", "dd", 0)) {
3491 pr_err("Cannot read adaptive keyboard mode\n");
3492 return -EIO;
3493 }
3494
3495 return mode;
3496}
3497
3498static int adaptive_keyboard_set_mode(int new_mode)
3499{
3500 if (new_mode < 0 ||
3501 new_mode > LAYFLAT_MODE)
3502 return -EINVAL;
3503
3504 if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) {
3505 pr_err("Cannot set adaptive keyboard mode\n");
3506 return -EIO;
3507 }
3508
3509 return 0;
3510}
3511
3486static int adaptive_keyboard_get_next_mode(int mode) 3512static int adaptive_keyboard_get_next_mode(int mode)
3487{ 3513{
3488 size_t i; 3514 size_t i;
@@ -3512,39 +3538,28 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
3512 new_mode = adaptive_keyboard_prev_mode; 3538 new_mode = adaptive_keyboard_prev_mode;
3513 adaptive_keyboard_mode_is_saved = false; 3539 adaptive_keyboard_mode_is_saved = false;
3514 } else { 3540 } else {
3515 if (!acpi_evalf( 3541 current_mode = adaptive_keyboard_get_mode();
3516 hkey_handle, &current_mode, 3542 if (current_mode < 0)
3517 "GTRW", "dd", 0)) {
3518 pr_err("Cannot read adaptive keyboard mode\n");
3519 return false; 3543 return false;
3520 } else { 3544 new_mode = adaptive_keyboard_get_next_mode(
3521 new_mode = adaptive_keyboard_get_next_mode( 3545 current_mode);
3522 current_mode);
3523 }
3524 } 3546 }
3525 3547
3526 if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) { 3548 if (adaptive_keyboard_set_mode(new_mode) < 0)
3527 pr_err("Cannot set adaptive keyboard mode\n");
3528 return false; 3549 return false;
3529 }
3530 3550
3531 return true; 3551 return true;
3532 3552
3533 case DFR_SHOW_QUICKVIEW_ROW: 3553 case DFR_SHOW_QUICKVIEW_ROW:
3534 if (!acpi_evalf(hkey_handle, 3554 current_mode = adaptive_keyboard_get_mode();
3535 &adaptive_keyboard_prev_mode, 3555 if (current_mode < 0)
3536 "GTRW", "dd", 0)) {
3537 pr_err("Cannot read adaptive keyboard mode\n");
3538 return false; 3556 return false;
3539 } else {
3540 adaptive_keyboard_mode_is_saved = true;
3541 3557
3542 if (!acpi_evalf(hkey_handle, 3558 adaptive_keyboard_prev_mode = current_mode;
3543 NULL, "STRW", "vd", FUNCTION_MODE)) { 3559 adaptive_keyboard_mode_is_saved = true;
3544 pr_err("Cannot set adaptive keyboard mode\n"); 3560
3545 return false; 3561 if (adaptive_keyboard_set_mode (FUNCTION_MODE) < 0)
3546 } 3562 return false;
3547 }
3548 return true; 3563 return true;
3549 3564
3550 default: 3565 default: