diff options
author | Bastien Nocera <hadess@hadess.net> | 2015-03-02 08:45:27 -0500 |
---|---|---|
committer | Darren Hart <dvhart@linux.intel.com> | 2015-03-03 12:00:08 -0500 |
commit | b790ceeb0fd94725150219abd8c13b08a17a32e3 (patch) | |
tree | 33d9de70fd13dcb99d9ae93b68ad000033f83906 /drivers/platform | |
parent | f74587fb9308dd6d4346180672d79b8a861f02dd (diff) |
thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
Add a sysfs attribute to allow privileged users to change the keyboard
mode. This could be used by desktop environments to change the keyboard
mode depending on the application focused, as the Windows application
does.
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')
-rw-r--r-- | drivers/platform/x86/thinkpad_acpi.c | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 5dea4c270482..ae528cf0b143 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c | |||
@@ -2918,6 +2918,57 @@ static void hotkey_wakeup_hotunplug_complete_notify_change(void) | |||
2918 | "wakeup_hotunplug_complete"); | 2918 | "wakeup_hotunplug_complete"); |
2919 | } | 2919 | } |
2920 | 2920 | ||
2921 | /* sysfs adaptive kbd mode --------------------------------------------- */ | ||
2922 | |||
2923 | static int adaptive_keyboard_get_mode(void); | ||
2924 | static int adaptive_keyboard_set_mode(int new_mode); | ||
2925 | |||
2926 | enum ADAPTIVE_KEY_MODE { | ||
2927 | HOME_MODE, | ||
2928 | WEB_BROWSER_MODE, | ||
2929 | WEB_CONFERENCE_MODE, | ||
2930 | FUNCTION_MODE, | ||
2931 | LAYFLAT_MODE | ||
2932 | }; | ||
2933 | |||
2934 | static ssize_t adaptive_kbd_mode_show(struct device *dev, | ||
2935 | struct device_attribute *attr, | ||
2936 | char *buf) | ||
2937 | { | ||
2938 | u32 current_mode; | ||
2939 | |||
2940 | current_mode = adaptive_keyboard_get_mode(); | ||
2941 | if (current_mode < 0) | ||
2942 | return current_mode; | ||
2943 | |||
2944 | return snprintf(buf, PAGE_SIZE, "%d\n", current_mode); | ||
2945 | } | ||
2946 | |||
2947 | static ssize_t adaptive_kbd_mode_store(struct device *dev, | ||
2948 | struct device_attribute *attr, | ||
2949 | const char *buf, size_t count) | ||
2950 | { | ||
2951 | unsigned long t; | ||
2952 | int res; | ||
2953 | |||
2954 | if (parse_strtoul(buf, LAYFLAT_MODE, &t)) | ||
2955 | return -EINVAL; | ||
2956 | |||
2957 | res = adaptive_keyboard_set_mode(t); | ||
2958 | return (res < 0) ? res : count; | ||
2959 | } | ||
2960 | |||
2961 | static DEVICE_ATTR_RW(adaptive_kbd_mode); | ||
2962 | |||
2963 | static struct attribute *adaptive_kbd_attributes[] = { | ||
2964 | &dev_attr_adaptive_kbd_mode.attr, | ||
2965 | NULL | ||
2966 | }; | ||
2967 | |||
2968 | static const struct attribute_group adaptive_kbd_attr_group = { | ||
2969 | .attrs = adaptive_kbd_attributes, | ||
2970 | }; | ||
2971 | |||
2921 | /* --------------------------------------------------------------------- */ | 2972 | /* --------------------------------------------------------------------- */ |
2922 | 2973 | ||
2923 | static struct attribute *hotkey_attributes[] __initdata = { | 2974 | static struct attribute *hotkey_attributes[] __initdata = { |
@@ -3233,8 +3284,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
3233 | * Lenovo Carbon X1 2014 (2nd Gen). | 3284 | * Lenovo Carbon X1 2014 (2nd Gen). |
3234 | */ | 3285 | */ |
3235 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { | 3286 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { |
3236 | if ((hkeyv >> 8) == 2) | 3287 | if ((hkeyv >> 8) == 2) { |
3237 | tp_features.has_adaptive_kbd = true; | 3288 | tp_features.has_adaptive_kbd = true; |
3289 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | ||
3290 | &adaptive_kbd_attr_group); | ||
3291 | if (res) | ||
3292 | goto err_exit; | ||
3293 | } | ||
3238 | } | 3294 | } |
3239 | 3295 | ||
3240 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, | 3296 | quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, |
@@ -3447,6 +3503,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) | |||
3447 | 3503 | ||
3448 | err_exit: | 3504 | err_exit: |
3449 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | 3505 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); |
3506 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | ||
3507 | &adaptive_kbd_attr_group); | ||
3508 | |||
3450 | hotkey_dev_attributes = NULL; | 3509 | hotkey_dev_attributes = NULL; |
3451 | 3510 | ||
3452 | return (res < 0) ? res : 1; | 3511 | return (res < 0) ? res : 1; |
@@ -3459,14 +3518,6 @@ err_exit: | |||
3459 | * Will consider support rest of modes in future. | 3518 | * Will consider support rest of modes in future. |
3460 | * | 3519 | * |
3461 | */ | 3520 | */ |
3462 | enum ADAPTIVE_KEY_MODE { | ||
3463 | HOME_MODE, | ||
3464 | WEB_BROWSER_MODE, | ||
3465 | WEB_CONFERENCE_MODE, | ||
3466 | FUNCTION_MODE, | ||
3467 | LAYFLAT_MODE | ||
3468 | }; | ||
3469 | |||
3470 | static const int adaptive_keyboard_modes[] = { | 3521 | static const int adaptive_keyboard_modes[] = { |
3471 | HOME_MODE, | 3522 | HOME_MODE, |
3472 | /* WEB_BROWSER_MODE = 2, | 3523 | /* WEB_BROWSER_MODE = 2, |