From patchwork Fri Feb 20 14:44:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 5856751 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B550CBF440 for ; Fri, 20 Feb 2015 14:47:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E70E620364 for ; Fri, 20 Feb 2015 14:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E57E2022A for ; Fri, 20 Feb 2015 14:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754412AbbBTOps (ORCPT ); Fri, 20 Feb 2015 09:45:48 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:48128 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754442AbbBTOpq (ORCPT ); Fri, 20 Feb 2015 09:45:46 -0500 Received: from mfilter36-d.gandi.net (mfilter36-d.gandi.net [217.70.178.167]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id EC1211720AE; Fri, 20 Feb 2015 15:45:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter36-d.gandi.net Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter36-d.gandi.net (mfilter36-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id n5SBBv64rYVm; Fri, 20 Feb 2015 15:45:42 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 5E32D172074; Fri, 20 Feb 2015 15:45:40 +0100 (CET) Message-ID: <1424443456.22910.14.camel@hadess.net> Subject: [PATCH 2/7] thinkpad_acpi: Factor out get/set adaptive kbd mode 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, Jiri Kosina Date: Fri, 20 Feb 2015 15:44:16 +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=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 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 --- drivers/platform/x86/thinkpad_acpi.c | 61 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index c1f4daf..d395d3f 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -3482,6 +3482,32 @@ const int adaptive_keyboard_modes[] = { static bool adaptive_keyboard_mode_is_saved; static int adaptive_keyboard_prev_mode; +static int adaptive_keyboard_get_mode(void) +{ + int mode = 0; + + if (!acpi_evalf(hkey_handle, &mode, "GTRW", "dd", 0)) { + pr_err("Cannot read adaptive keyboard mode\n"); + return -EIO; + } + + return mode; +} + +static int adaptive_keyboard_set_mode(int new_mode) +{ + if (new_mode < 0 || + new_mode > LAYFLAT_MODE) + return -EINVAL; + + if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) { + pr_err("Cannot set adaptive keyboard mode\n"); + return -EIO; + } + + return 0; +} + static int adaptive_keyboard_get_next_mode(int mode) { size_t i; @@ -3511,39 +3537,28 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode) new_mode = adaptive_keyboard_prev_mode; adaptive_keyboard_mode_is_saved = false; } else { - if (!acpi_evalf( - hkey_handle, ¤t_mode, - "GTRW", "dd", 0)) { - pr_err("Cannot read adaptive keyboard mode\n"); + current_mode = adaptive_keyboard_get_mode(); + if (current_mode < 0) return false; - } else { - new_mode = adaptive_keyboard_get_next_mode( - current_mode); - } + new_mode = adaptive_keyboard_get_next_mode( + current_mode); } - if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd", new_mode)) { - pr_err("Cannot set adaptive keyboard mode\n"); + if (adaptive_keyboard_set_mode(new_mode) < 0) return false; - } return true; case DFR_SHOW_QUICKVIEW_ROW: - if (!acpi_evalf(hkey_handle, - &adaptive_keyboard_prev_mode, - "GTRW", "dd", 0)) { - pr_err("Cannot read adaptive keyboard mode\n"); + current_mode = adaptive_keyboard_get_mode(); + if (current_mode < 0) return false; - } else { - adaptive_keyboard_mode_is_saved = true; - if (!acpi_evalf(hkey_handle, - NULL, "STRW", "vd", FUNCTION_MODE)) { - pr_err("Cannot set adaptive keyboard mode\n"); - return false; - } - } + adaptive_keyboard_prev_mode = current_mode; + adaptive_keyboard_mode_is_saved = true; + + if (adaptive_keyboard_set_mode (FUNCTION_MODE) < 0) + return false; return true; default: