From patchwork Fri Jul 27 20:19:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel M. Lambea" X-Patchwork-Id: 10547695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB0A7112E for ; Fri, 27 Jul 2018 20:19:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1CA62C548 for ; Fri, 27 Jul 2018 20:19:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93C5B2C54D; Fri, 27 Jul 2018 20:19:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F5822C544 for ; Fri, 27 Jul 2018 20:19:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389434AbeG0Vmu (ORCPT ); Fri, 27 Jul 2018 17:42:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:50850 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389386AbeG0Vmu (ORCPT ); Fri, 27 Jul 2018 17:42:50 -0400 Received: by mail-wm0-f65.google.com with SMTP id s12-v6so6487850wmc.0 for ; Fri, 27 Jul 2018 13:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3sHdz/LF8VwrdmTRbkwGIAqVlzFWZ/qc9sWGWOQnusk=; b=F/H48MY0RvCwDCneRD4auNTkQWZZYX5lHWJ+k+kFMHVwVGKaLAeQCBAYD0uR/TPAyr yI1ZkW47x3rYDvaQTOBlCXNBOslR2rq1gudysI4HC8vYJ9vHIuYNfv2BKUq5K06fMk0x bhdxvHvUoVBbeuLKpidXbK+EP7ZBJLGQ5sDyq2vwdfUvWqZVlxDejj6EfjEIgdxx+IXb scLF2X8q6bCV2kK0/PtlgzsTfBa2Y32WmianQ7JcbxF/4maPUADDWh0IUc+BrSSO4fz1 bQerRmmlSo/+UMnoh0rRCEO2NSgVvi2168NrF14ymXgZe09yB75Tonp7AeU0LEKg14hb kfaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3sHdz/LF8VwrdmTRbkwGIAqVlzFWZ/qc9sWGWOQnusk=; b=BQy/Pybnv+kgfob0E73ircNJ8vUczeFVFhCCdzvemjaAh2zw9lA7d7iW/WIrUEwnbj I33Uf1hS7tn/7hr6uLroS+konJB3WZt5U6z3JLrh3LvTwgMqHUm2kuFhd0uhqX4Dd4dL IAQ8LaARAkEHRpCt7t2MXNG/Vy/dohFuZiSDgYLLZOdztNjHjHseAP1qnIe5b05BqW6z 0j7psx3AtGjXwbTWgmPu5G1fOfYPzZc/5ErVVKzCwiL5t53fqsGzEhfojSlR3cdD+BYG SuEWQsiA80OmZKnrsGzQshrwIWrYCD3ZdunIcdkLHlrpOqRZ2Ceg1vjcDfAxxdxXLW06 PGYQ== X-Gm-Message-State: AOUpUlEelo0Qh4bUkb5rFh8nzDkYYcoy6tQw5yb3rzGjNHZ9GXmfBo4C US2BU0cAhsf2Fy8oKAg4IhY= X-Google-Smtp-Source: AAOMgpeAjU24Rlk+yvlhzZ1FrRxfK7hX3/slGVuPIqCGwf+Vgf2FcbBwWMsrPftJpOvVrvns5AaBTQ== X-Received: by 2002:a1c:5c8f:: with SMTP id q137-v6mr5875774wmb.24.1532722759942; Fri, 27 Jul 2018 13:19:19 -0700 (PDT) Received: from localhost.localdomain (86.red-83-42-60.dynamicip.rima-tde.net. [83.42.60.86]) by smtp.gmail.com with ESMTPSA id z5-v6sm6991296wrv.2.2018.07.27.13.19.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Jul 2018 13:19:19 -0700 (PDT) From: "Daniel M. Lambea" To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org Subject: [PATCH 1/2] HID: cougar: Make parameter 'g6_is_space' dinamically settable Date: Fri, 27 Jul 2018 21:19:11 +0100 Message-Id: <20180727201912.6752-1-dmlambea@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Parameter g6_is_space instructs the driver to map G6 keypresses to KEY_SPACE (true) or to KEY_F18 (false). Make the parameter configurable via module_param_cb to allow users to change its value without reloading the module. Signed-off-by: Daniel M. Lambea --- This patch series is to be applied on top of branch for-4.19/cougar. drivers/hid/hid-cougar.c | 46 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-cougar.c b/drivers/hid/hid-cougar.c index ad2e87de7dc5..910ef4312157 100644 --- a/drivers/hid/hid-cougar.c +++ b/drivers/hid/hid-cougar.c @@ -7,6 +7,7 @@ #include #include +#include #include "hid-ids.h" @@ -15,11 +16,9 @@ MODULE_DESCRIPTION("Cougar 500k Gaming Keyboard"); MODULE_LICENSE("GPL"); MODULE_INFO(key_mappings, "G1-G6 are mapped to F13-F18"); -static int cougar_g6_is_space = 1; -module_param_named(g6_is_space, cougar_g6_is_space, int, 0600); +static bool g6_is_space = true; MODULE_PARM_DESC(g6_is_space, - "If set, G6 programmable key sends SPACE instead of F18 (0=off, 1=on) (default=1)"); - + "If true, G6 programmable key sends SPACE instead of F18 (default=true)"); #define COUGAR_VENDOR_USAGE 0xff00ff00 @@ -82,20 +81,23 @@ struct cougar { static LIST_HEAD(cougar_udev_list); static DEFINE_MUTEX(cougar_udev_list_lock); -static void cougar_fix_g6_mapping(struct hid_device *hdev) +/** + * cougar_fix_g6_mapping - configure the mapping for key G6/Spacebar + */ +static void cougar_fix_g6_mapping(void) { int i; for (i = 0; cougar_mapping[i][0]; i++) { if (cougar_mapping[i][0] == COUGAR_KEY_G6) { cougar_mapping[i][1] = - cougar_g6_is_space ? KEY_SPACE : KEY_F18; - hid_info(hdev, "G6 mapped to %s\n", - cougar_g6_is_space ? "space" : "F18"); + g6_is_space ? KEY_SPACE : KEY_F18; + pr_info("cougar: G6 mapped to %s\n", + g6_is_space ? "space" : "F18"); return; } } - hid_warn(hdev, "no mapping defined for G6/spacebar"); + pr_warn("cougar: no mappings defined for G6/spacebar"); } /* @@ -154,7 +156,8 @@ static void cougar_remove_shared_data(void *resource) * Bind the device group's shared data to this cougar struct. * If no shared data exists for this group, create and initialize it. */ -static int cougar_bind_shared_data(struct hid_device *hdev, struct cougar *cougar) +static int cougar_bind_shared_data(struct hid_device *hdev, + struct cougar *cougar) { struct cougar_shared *shared; int error = 0; @@ -228,7 +231,6 @@ static int cougar_probe(struct hid_device *hdev, * to it. */ if (hdev->collection->usage == HID_GD_KEYBOARD) { - cougar_fix_g6_mapping(hdev); list_for_each_entry_safe(hidinput, next, &hdev->inputs, list) { if (hidinput->registered && hidinput->input != NULL) { cougar->shared->input = hidinput->input; @@ -237,6 +239,8 @@ static int cougar_probe(struct hid_device *hdev, } } } else if (hdev->collection->usage == COUGAR_VENDOR_USAGE) { + /* Preinit the mapping table */ + cougar_fix_g6_mapping(); error = hid_hw_open(hdev); if (error) goto fail_stop_and_cleanup; @@ -293,6 +297,26 @@ static void cougar_remove(struct hid_device *hdev) hid_hw_stop(hdev); } +static int cougar_param_set_g6_is_space(const char *val, + const struct kernel_param *kp) +{ + int ret; + + ret = param_set_bool(val, kp); + if (ret) + return ret; + + cougar_fix_g6_mapping(); + + return 0; +} + +static const struct kernel_param_ops cougar_g6_is_space_ops = { + .set = cougar_param_set_g6_is_space, + .get = param_get_bool, +}; +module_param_cb(g6_is_space, &cougar_g6_is_space_ops, &g6_is_space, 0644); + static struct hid_device_id cougar_id_table[] = { { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR, USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD) },