From patchwork Wed Feb 18 20:53:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 5847861 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B7A049F36A for ; Wed, 18 Feb 2015 20:56:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F05D120131 for ; Wed, 18 Feb 2015 20:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F5022012E for ; Wed, 18 Feb 2015 20:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753343AbbBRUzK (ORCPT ); Wed, 18 Feb 2015 15:55:10 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:53471 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbbBRUzH (ORCPT ); Wed, 18 Feb 2015 15:55:07 -0500 Received: from mfilter41-d.gandi.net (mfilter41-d.gandi.net [217.70.178.173]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 439F8A80B6; Wed, 18 Feb 2015 21:55:06 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter41-d.gandi.net Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter41-d.gandi.net (mfilter41-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id vfn5s223mVHH; Wed, 18 Feb 2015 21:55:04 +0100 (CET) X-Originating-IP: 83.155.44.161 Received: from nuvo (mon69-7-83-155-44-161.fbx.proxad.net [83.155.44.161]) (Authenticated sender: hadess@hadess.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 507B5A80CD; Wed, 18 Feb 2015 21:55:04 +0100 (CET) Message-ID: <1424292824.32581.47.camel@hadess.net> Subject: [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr From: Bastien Nocera To: Henrique de Moraes Holschuh , Darren Hart , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Date: Wed, 18 Feb 2015 21:53:44 +0100 X-Mailer: Evolution 3.12.10 (3.12.10-1.fc21) Mime-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Bastien Nocera --- drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index a6dd017..562d958 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -2917,6 +2917,59 @@ static void hotkey_wakeup_hotunplug_complete_notify_change(void) "wakeup_hotunplug_complete"); } +/* sysfs adaptive kbd mode --------------------------------------------- */ + +static int adaptive_keyboard_get_mode(void); +static int adaptive_keyboard_set_mode(int new_mode); + +enum ADAPTIVE_KEY_MODE { + HOME_MODE, + WEB_BROWSER_MODE, + WEB_CONFERENCE_MODE, + FUNCTION_MODE, + LAYFLAT_MODE +}; + +static ssize_t adaptive_kbd_mode_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + u32 current_mode; + + current_mode = adaptive_keyboard_get_mode(); + if (current_mode < 0) + return current_mode; + + return snprintf(buf, PAGE_SIZE, "%d\n", current_mode); +} + +static ssize_t adaptive_kbd_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long t; + int res; + + if (parse_strtoul(buf, LAYFLAT_MODE, &t)) + return -EINVAL; + + res = adaptive_keyboard_set_mode(t); + return (res < 0) ? res : count; +} + +static struct device_attribute dev_attr_adaptive_kbd_mode = + __ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO, + adaptive_kbd_mode_show, adaptive_kbd_mode_store); + +static struct attribute *adaptive_kbd_attributes[] = { + &dev_attr_adaptive_kbd_mode.attr, + NULL +}; + +static const struct attribute_group adaptive_kbd_attr_group = { + .attrs = adaptive_kbd_attributes, +}; + /* --------------------------------------------------------------------- */ static struct attribute *hotkey_attributes[] __initdata = { @@ -3230,8 +3283,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) /* does it have an adaptive keyboard, like * the Lenovo Carbon X1 2014 (2nd gen) */ if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { - if ((hkeyv >> 8) == 2) + if ((hkeyv >> 8) == 2) { tp_features.has_adaptive_kbd = true; + res = sysfs_create_group(&tpacpi_pdev->dev.kobj, + &adaptive_kbd_attr_group); + if (res) + goto err_exit; + } } quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable, @@ -3444,6 +3502,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) err_exit: delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); + sysfs_remove_group(&tpacpi_pdev->dev.kobj, + &adaptive_kbd_attr_group); + hotkey_dev_attributes = NULL; return (res < 0) ? res : 1; @@ -3456,14 +3517,6 @@ err_exit: * Will consider support rest of modes in future. * */ -enum ADAPTIVE_KEY_MODE { - HOME_MODE, - WEB_BROWSER_MODE, - WEB_CONFERENCE_MODE, - FUNCTION_MODE, - LAYFLAT_MODE -}; - const int adaptive_keyboard_modes[] = { HOME_MODE, /* WEB_BROWSER_MODE = 2,