From patchwork Wed Feb 9 22:55:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12741038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36D05C433EF for ; Wed, 9 Feb 2022 22:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236577AbiBIWz6 (ORCPT ); Wed, 9 Feb 2022 17:55:58 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236586AbiBIWz5 (ORCPT ); Wed, 9 Feb 2022 17:55:57 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D91EAE019775 for ; Wed, 9 Feb 2022 14:55:59 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id x4so244516plb.4 for ; Wed, 09 Feb 2022 14:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vm/cV6FYDT+Lx9WNAQ4ji/uvsuD1Mn+JgYVp1tPCrfc=; b=FAImFDTtEmYTZo/1em3aetOFOlJ7KiALiEZzAP9S6VJccFf9uWS3oiDouR3RlWNhC/ w2xuCkEjjM9DxhhHUjSmm6/DokOFlq+9QwsmgxlwkUapwRgQOZJW1Bbc1ve4UZyAQ3Jr eQCTwT6MZ31raD4VZSpcDPIFrAtBu4SOxtUtA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vm/cV6FYDT+Lx9WNAQ4ji/uvsuD1Mn+JgYVp1tPCrfc=; b=2ZU/3ctNObyMOVtIbMnUf5tTf/Y3UZns0sMX4IeY+WryzulDaGwpXK5bwjpFPgYje0 cVb1Cp775Tk+ItmollP9iqkPbjavQKfWVvmdbkgE269Zp3So+J+is8RPeasowaYmzie8 MLMeDSAFpY9vqsQCi4FJahx0tiwOIEgl+PMEtgK/t7XY2Uzo2j7vjYd9SuD1stXry1/y hHrb7qgYotCBvhRpxCEQkt+KMuIiqPkC/Jkevng979lBcGvmL4iBC7HQbUv8R1LDTYZG JLqxm41uRUzing1wtYf0gB8FG36E/1D9Bk1WS+HGj736KWIE3zhosVIW8V+jA6ys2azM n/fA== X-Gm-Message-State: AOAM531cgw6BhRqzcpAq5gcY3hwzfjIJSE69bJq8lGNYpYrqa1Bs5HLS EJ75yy2imfnnwctIVmAqCUitvg== X-Google-Smtp-Source: ABdhPJyDpICcFtWrDeN23/PKeYsWz+4mpeFE8ppPzdHh+kxkJJSI8jwsQ7CWpBfLKMoGfRPns61W9g== X-Received: by 2002:a17:902:8f8d:: with SMTP id z13mr4542483plo.118.1644447359407; Wed, 09 Feb 2022 14:55:59 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:5193:6865:e38e:3a5b]) by smtp.gmail.com with ESMTPSA id b1sm5982015pgb.66.2022.02.09.14.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:55:59 -0800 (PST) From: Stephen Boyd To: benjamin.tissoires@redhat.com, Dmitry Torokhov , Jiri Kosina Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, "Sean O'Brien" , Douglas Anderson , Zhengqiao Xia Subject: [PATCH v2 1/5] Input: atkbd: Convert function_row_physmap to u16 array Date: Wed, 9 Feb 2022 14:55:52 -0800 Message-Id: <20220209225556.3992827-2-swboyd@chromium.org> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220209225556.3992827-1-swboyd@chromium.org> References: <20220209225556.3992827-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This is a u32 array because the device property is an array of u32s. Convert this to a u16 array to save a little space and to ease the transition to a common physmap function in the next patch. Cc: Jiri Kosina Cc: Dmitry Torokhov Cc: "Sean O'Brien" Cc: Douglas Anderson Cc: Zhengqiao Xia Signed-off-by: Stephen Boyd --- drivers/input/keyboard/atkbd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index fbdef95291e9..721cde982637 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -237,7 +237,7 @@ struct atkbd { /* Serializes reconnect(), attr->set() and event work */ struct mutex mutex; - u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; + u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; int num_function_row_keys; }; @@ -1202,14 +1202,17 @@ static void atkbd_parse_fwnode_data(struct serio *serio) { struct atkbd *atkbd = serio_get_drvdata(serio); struct device *dev = &serio->dev; - int n; + int i, n; + u32 physmap[MAX_FUNCTION_ROW_KEYS]; /* Parse "function-row-physmap" property */ n = device_property_count_u32(dev, "function-row-physmap"); if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS && !device_property_read_u32_array(dev, "function-row-physmap", - atkbd->function_row_physmap, n)) { + physmap, n)) { atkbd->num_function_row_keys = n; + for (i = 0; i < n; i++) + atkbd->function_row_physmap[i] = physmap[i]; dev_dbg(dev, "FW reported %d function-row key locations\n", n); } } From patchwork Wed Feb 9 22:55:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12741039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 317F5C433F5 for ; Wed, 9 Feb 2022 22:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236619AbiBIW4A (ORCPT ); Wed, 9 Feb 2022 17:56:00 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236599AbiBIWz6 (ORCPT ); Wed, 9 Feb 2022 17:55:58 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF982E019775 for ; Wed, 9 Feb 2022 14:56:00 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id x15so4545746pfr.5 for ; Wed, 09 Feb 2022 14:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TjRtwSXYHT5J47hsI/ryAldat2t/W6F5BVRXjX1zG4I=; b=S8ayzEPzEtYa8moDFXfC5C9hlSd1+d4HElt98EDjUdrQMY0x4pTh4BvrRDMu8WeILJ vZz83GHpbzw6tUXghx4cgWIaPd6aikMYFxi4VCyv7EMDMGRYQ6wn42T5FvPAzovqqrGy t0aogamTN1jwHzFYYZ/jziSyd5gC6MFv1lCPI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TjRtwSXYHT5J47hsI/ryAldat2t/W6F5BVRXjX1zG4I=; b=EeW9foJzg5rMmzpE72Td6nnDxvZCwY8fKsBl22w4tb2j8exCbb+Q/z4N3XMgmaARBS k8Hq+iiMEDQEptYbYZHgdo3zf4uVwQB5d9lgZJ6Cnfk+rzd5CBbkB8BeNVX0v1U11rCh wIEozRjINTuD/B1StBUNjaYr0ZVUJP/jO7cNVV7782bmjnu7WEPbYWDJIGKLDZ5dPmP0 9/vmU8EZUJlcpd8jRCaUg0E+8pDby8AWHdL0v1ZhV+rr4WZZHLEZ81WTGSbFADhDdX6n LXhYiVUEj1o7lViEtUjBind5SrY7A8qNeCB7mU9n3spGCCXRAwqe895gBv/yMZsDTzc9 nAyw== X-Gm-Message-State: AOAM532SVhNYaNmAKT/hGH6QB0e3wKJvb7tg6y1+8IvGa06aajUofAUD XJ81Rm0lE+PDfZyhTMpcd0tLVA== X-Google-Smtp-Source: ABdhPJzlczzJXAoqqeQHVXEAH4hmaGVofYXiSwhhxdBTObEOFkBGFBVJuyiqJZbOB7T6gNYpWdA61Q== X-Received: by 2002:a05:6a00:1789:: with SMTP id s9mr4614478pfg.71.1644447360427; Wed, 09 Feb 2022 14:56:00 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:5193:6865:e38e:3a5b]) by smtp.gmail.com with ESMTPSA id b1sm5982015pgb.66.2022.02.09.14.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:56:00 -0800 (PST) From: Stephen Boyd To: benjamin.tissoires@redhat.com, Dmitry Torokhov , Jiri Kosina Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, "Sean O'Brien" , Douglas Anderson , Zhengqiao Xia Subject: [PATCH v2 2/5] Input: Extract ChromeOS vivaldi physmap show function Date: Wed, 9 Feb 2022 14:55:53 -0800 Message-Id: <20220209225556.3992827-3-swboyd@chromium.org> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220209225556.3992827-1-swboyd@chromium.org> References: <20220209225556.3992827-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Let's introduce a common library file for the physmap show function duplicated between three different keyboard drivers. This largely copies the code from cros_ec_keyb.c which has the most recent version of the show function, while using the vivaldi_data struct from the hid-vivaldi driver. This saves a small amount of space in an allyesconfig build. $ ./scripts/bloat-o-meter vmlinux.before vmlinux.after add/remove: 3/0 grow/shrink: 2/3 up/down: 412/-720 (-308) Function old new delta vivaldi_function_row_physmap_show - 292 +292 _sub_I_65535_1 1057564 1057616 +52 _sub_D_65535_0 1057564 1057616 +52 e843419@49f2_00062737_9b04 - 8 +8 e843419@20f6_0002a34d_35bc - 8 +8 atkbd_parse_fwnode_data 480 472 -8 atkbd_do_show_function_row_physmap 316 76 -240 function_row_physmap_show 620 148 -472 Total: Before=285581925, After=285581617, chg -0.00% Cc: Jiri Kosina Cc: Dmitry Torokhov Cc: "Sean O'Brien" Cc: Douglas Anderson Cc: Zhengqiao Xia Signed-off-by: Stephen Boyd --- drivers/hid/Kconfig | 1 + drivers/hid/hid-vivaldi.c | 27 +++++-------------- drivers/input/Kconfig | 7 +++++ drivers/input/Makefile | 1 + drivers/input/keyboard/Kconfig | 2 ++ drivers/input/keyboard/atkbd.c | 22 +++++---------- drivers/input/keyboard/cros_ec_keyb.c | 30 +++++++-------------- drivers/input/vivaldi-keymap.c | 39 +++++++++++++++++++++++++++ include/linux/input/vivaldi-keymap.h | 28 +++++++++++++++++++ 9 files changed, 101 insertions(+), 56 deletions(-) create mode 100644 drivers/input/vivaldi-keymap.c create mode 100644 include/linux/input/vivaldi-keymap.h diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index f5544157576c..5569a2029dab 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -411,6 +411,7 @@ config HID_GOOGLE_HAMMER config HID_VIVALDI tristate "Vivaldi Keyboard" + select INPUT_VIVALDIFMAP depends on HID help Say Y here if you want to enable support for Vivaldi keyboards. diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c index efa6140915f4..78ae3725bc89 100644 --- a/drivers/hid/hid-vivaldi.c +++ b/drivers/hid/hid-vivaldi.c @@ -8,37 +8,22 @@ #include #include +#include #include #include #include -#define MIN_FN_ROW_KEY 1 -#define MAX_FN_ROW_KEY 24 #define HID_VD_FN_ROW_PHYSMAP 0x00000001 #define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP) -struct vivaldi_data { - u32 function_row_physmap[MAX_FN_ROW_KEY - MIN_FN_ROW_KEY + 1]; - int max_function_row_key; -}; - static ssize_t function_row_physmap_show(struct device *dev, struct device_attribute *attr, char *buf) { struct hid_device *hdev = to_hid_device(dev); struct vivaldi_data *drvdata = hid_get_drvdata(hdev); - ssize_t size = 0; - int i; - - if (!drvdata->max_function_row_key) - return 0; - for (i = 0; i < drvdata->max_function_row_key; i++) - size += sprintf(buf + size, "%02X ", - drvdata->function_row_physmap[i]); - size += sprintf(buf + size, "\n"); - return size; + return vivaldi_function_row_physmap_show(drvdata, buf); } static DEVICE_ATTR_RO(function_row_physmap); @@ -86,10 +71,10 @@ static void vivaldi_feature_mapping(struct hid_device *hdev, return; fn_key = (usage->hid & HID_USAGE); - if (fn_key < MIN_FN_ROW_KEY || fn_key > MAX_FN_ROW_KEY) + if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY) return; - if (fn_key > drvdata->max_function_row_key) - drvdata->max_function_row_key = fn_key; + if (fn_key > drvdata->num_function_row_keys) + drvdata->num_function_row_keys = fn_key; report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL); if (!report_data) @@ -134,7 +119,7 @@ static void vivaldi_feature_mapping(struct hid_device *hdev, goto out; } - drvdata->function_row_physmap[fn_key - MIN_FN_ROW_KEY] = + drvdata->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] = field->value[usage->usage_index]; out: diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index 5baebf62df33..e2752f7364bc 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -77,6 +77,13 @@ config INPUT_MATRIXKMAP To compile this driver as a module, choose M here: the module will be called matrix-keymap. +config INPUT_VIVALDIFMAP + tristate + help + ChromeOS Vivaldi keymap support library. This is a hidden + option so that drivers can use common code to parse and + expose the vivaldi function row keymap. + comment "Userland interfaces" config INPUT_MOUSEDEV diff --git a/drivers/input/Makefile b/drivers/input/Makefile index 037cc595106c..ba320cc99393 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -12,6 +12,7 @@ input-core-y += touchscreen.o obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o obj-$(CONFIG_INPUT_SPARSEKMAP) += sparse-keymap.o obj-$(CONFIG_INPUT_MATRIXKMAP) += matrix-keymap.o +obj-$(CONFIG_INPUT_VIVALDIFMAP) += vivaldi-keymap.o obj-$(CONFIG_INPUT_LEDS) += input-leds.o obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 0c607da9ee10..8b4477e54a01 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -103,6 +103,7 @@ config KEYBOARD_ATKBD select SERIO_LIBPS2 select SERIO_I8042 if ARCH_MIGHT_HAVE_PC_SERIO select SERIO_GSCPS2 if GSC + select INPUT_VIVALDIFMAP help Say Y here if you want to use a standard AT or PS/2 keyboard. Usually you'll need this, unless you have a different type keyboard (USB, ADB @@ -749,6 +750,7 @@ config KEYBOARD_XTKBD config KEYBOARD_CROS_EC tristate "ChromeOS EC keyboard" select INPUT_MATRIXKMAP + select INPUT_VIVALDIFMAP depends on CROS_EC help Say Y here to enable the matrix keyboard used by ChromeOS devices diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index 721cde982637..aa539076c121 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -237,8 +238,7 @@ struct atkbd { /* Serializes reconnect(), attr->set() and event work */ struct mutex mutex; - u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; - int num_function_row_keys; + struct vivaldi_data vdata; }; /* @@ -308,17 +308,9 @@ static struct attribute *atkbd_attributes[] = { static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf) { - ssize_t size = 0; - int i; - - if (!atkbd->num_function_row_keys) - return 0; + const struct vivaldi_data *data = &atkbd->vdata; - for (i = 0; i < atkbd->num_function_row_keys; i++) - size += scnprintf(buf + size, PAGE_SIZE - size, "%02X ", - atkbd->function_row_physmap[i]); - size += scnprintf(buf + size, PAGE_SIZE - size, "\n"); - return size; + return vivaldi_function_row_physmap_show(data, buf); } static umode_t atkbd_attr_is_visible(struct kobject *kobj, @@ -329,7 +321,7 @@ static umode_t atkbd_attr_is_visible(struct kobject *kobj, struct atkbd *atkbd = serio_get_drvdata(serio); if (attr == &atkbd_attr_function_row_physmap.attr && - !atkbd->num_function_row_keys) + !atkbd->vdata.num_function_row_keys) return 0; return attr->mode; @@ -1210,9 +1202,9 @@ static void atkbd_parse_fwnode_data(struct serio *serio) if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS && !device_property_read_u32_array(dev, "function-row-physmap", physmap, n)) { - atkbd->num_function_row_keys = n; + atkbd->vdata.num_function_row_keys = n; for (i = 0; i < n; i++) - atkbd->function_row_physmap[i] = physmap[i]; + atkbd->vdata.function_row_physmap[i] = physmap[i]; dev_dbg(dev, "FW reported %d function-row key locations\n", n); } } diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c index fc02c540636e..ef0f767353fb 100644 --- a/drivers/input/keyboard/cros_ec_keyb.c +++ b/drivers/input/keyboard/cros_ec_keyb.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -44,9 +45,7 @@ * @idev: The input device for the matrix keys. * @bs_idev: The input device for non-matrix buttons and switches (or NULL). * @notifier: interrupt event notifier for transport devices - * @function_row_physmap: An array of the encoded rows/columns for the top - * row function keys, in an order from left to right - * @num_function_row_keys: The number of top row keys in a custom keyboard + * @vdata: vivaldi function row data */ struct cros_ec_keyb { unsigned int rows; @@ -64,8 +63,7 @@ struct cros_ec_keyb { struct input_dev *bs_idev; struct notifier_block notifier; - u16 function_row_physmap[MAX_NUM_TOP_ROW_KEYS]; - size_t num_function_row_keys; + struct vivaldi_data vdata; }; /** @@ -591,10 +589,10 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) ckdev->idev = idev; cros_ec_keyb_compute_valid_keys(ckdev); - physmap = ckdev->function_row_physmap; + physmap = ckdev->vdata.function_row_physmap; of_property_for_each_u32(dev->of_node, "function-row-physmap", prop, p, key_pos) { - if (ckdev->num_function_row_keys == MAX_NUM_TOP_ROW_KEYS) { + if (ckdev->vdata.num_function_row_keys == MAX_NUM_TOP_ROW_KEYS) { dev_warn(dev, "Only support up to %d top row keys\n", MAX_NUM_TOP_ROW_KEYS); break; @@ -603,7 +601,7 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) col = KEY_COL(key_pos); *physmap = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); physmap++; - ckdev->num_function_row_keys++; + ckdev->vdata.num_function_row_keys++; } err = input_register_device(ckdev->idev); @@ -619,18 +617,10 @@ static ssize_t function_row_physmap_show(struct device *dev, struct device_attribute *attr, char *buf) { - ssize_t size = 0; - int i; - struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); - u16 *physmap = ckdev->function_row_physmap; - - for (i = 0; i < ckdev->num_function_row_keys; i++) - size += scnprintf(buf + size, PAGE_SIZE - size, - "%s%02X", size ? " " : "", physmap[i]); - if (size) - size += scnprintf(buf + size, PAGE_SIZE - size, "\n"); + const struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); + const struct vivaldi_data *data = &ckdev->vdata; - return size; + return vivaldi_function_row_physmap_show(data, buf); } static DEVICE_ATTR_RO(function_row_physmap); @@ -648,7 +638,7 @@ static umode_t cros_ec_keyb_attr_is_visible(struct kobject *kobj, struct cros_ec_keyb *ckdev = dev_get_drvdata(dev); if (attr == &dev_attr_function_row_physmap.attr && - !ckdev->num_function_row_keys) + !ckdev->vdata.num_function_row_keys) return 0; return attr->mode; diff --git a/drivers/input/vivaldi-keymap.c b/drivers/input/vivaldi-keymap.c new file mode 100644 index 000000000000..da6dc4070216 --- /dev/null +++ b/drivers/input/vivaldi-keymap.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helpers for ChromeOS Vivaldi keyboard function row mapping + * + * Copyright (C) 2022 Google, Inc + */ + +#include +#include +#include +#include +#include + +/** + * vivaldi_function_row_physmap_show - Print vivaldi function row physmap attribute + * @data: The vivaldi function keymap + * @buf: Buffer to print the function row phsymap to + */ +ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data, + char *buf) +{ + ssize_t size = 0; + int i; + const u16 *physmap = data->function_row_physmap; + + if (!data->num_function_row_keys) + return 0; + + for (i = 0; i < data->num_function_row_keys; i++) + size += scnprintf(buf + size, PAGE_SIZE - size, + "%s%02X", size ? " " : "", physmap[i]); + if (size) + size += scnprintf(buf + size, PAGE_SIZE - size, "\n"); + + return size; +} +EXPORT_SYMBOL_GPL(vivaldi_function_row_physmap_show); + +MODULE_LICENSE("GPL"); diff --git a/include/linux/input/vivaldi-keymap.h b/include/linux/input/vivaldi-keymap.h new file mode 100644 index 000000000000..4023b65e1649 --- /dev/null +++ b/include/linux/input/vivaldi-keymap.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _VIVALDI_KEYMAP_H +#define _VIVALDI_KEYMAP_H + +#include + +#define VIVALDI_MIN_FN_ROW_KEY 1 +#define VIVALDI_MAX_FN_ROW_KEY 24 + +/** + * struct vivaldi_data - Function row keymap data for ChromeOS vivaldi keyboards + * @function_row_physmap: An array of the encoded rows/columns for the top + * row function keys, in an order from left to right + * @num_function_row_keys: The number of top row keys in a custom keyboard + * + * This structure is supposed to be used by ChromeOS keyboards using + * the vivaldi keyboard function row design. + */ +struct vivaldi_data { + u16 function_row_physmap[VIVALDI_MAX_FN_ROW_KEY - VIVALDI_MIN_FN_ROW_KEY + 1]; + int num_function_row_keys; +}; + + +ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data, + char *buf); + +#endif /* _VIVALDI_KEYMAP_H */ From patchwork Wed Feb 9 22:55:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12741040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 190D5C433EF for ; Wed, 9 Feb 2022 22:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236642AbiBIW4C (ORCPT ); Wed, 9 Feb 2022 17:56:02 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236609AbiBIWz7 (ORCPT ); Wed, 9 Feb 2022 17:55:59 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34446E04FF08 for ; Wed, 9 Feb 2022 14:56:02 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id u12so218336plf.13 for ; Wed, 09 Feb 2022 14:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OD3ScagW/UVEvAgXcoCt88MegSsPUonQOP/whnuiG6c=; b=IdqQVxvkIDlWqFoR5ZkdpFlMKtj+Rwf9Ot9GDH2GxmjZ5Lt8AtA5Z5hsfTb/QXFmGm X5Fk4Mi8YKk4mpkvl9DPcDgkofoO7HgW8+JxfmhuA1Z02HU0/DGFIHTYu8s/p+vGuXYq OqObv8659R8SbEDzlNM4BHGOjPxoU3PsDeoAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OD3ScagW/UVEvAgXcoCt88MegSsPUonQOP/whnuiG6c=; b=7QeKxmF+Ux0sJyLAShMsxo+k964LcJfJx00NE2sBN8SO2JrMrfrvirUmawDYxIfP7J FLh9TIHC0e+OXdnCxIP6TZXTjYlytekeu286/66/bxynMtFtnWThq46ARQjMHunH6XPT w3aqGm35TK32cOsl/LUoKbzwqv61ldfDEEMQiDpU4zlAO30CIgvoGhAQS93Jq9CuPulv lBtTavyqjQv5qyOYkFt4UqY+Fk2oDyoQ6O/r2vzO7L3GyNo7fHLu0cw+vrP6nmS6dCFZ 3ZaQmoO6Ogzhwtuu0fG7E4gKWO2Hfa9QcZyfMrA1NWHI2LiYvxdw08scRcXiJIn9ff+z ngCQ== X-Gm-Message-State: AOAM530Mxy5wKytaVmQWxuzRrUJBvItYmPrQpiH8/njrPWiepklxSV1a sJCtStmVTjlq+hwyhD7vSrRQOA== X-Google-Smtp-Source: ABdhPJy/n7z7OnxkklzAPapMuR6v5FKtUfoFTwrSu2jJqxkQSYKA6+VsygyAUOuGgNnuZMn/TUwwoA== X-Received: by 2002:a17:903:41c6:: with SMTP id u6mr4349471ple.74.1644447361711; Wed, 09 Feb 2022 14:56:01 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:5193:6865:e38e:3a5b]) by smtp.gmail.com with ESMTPSA id b1sm5982015pgb.66.2022.02.09.14.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:56:01 -0800 (PST) From: Stephen Boyd To: benjamin.tissoires@redhat.com, Dmitry Torokhov , Jiri Kosina Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, "Sean O'Brien" , Douglas Anderson , Zhengqiao Xia Subject: [PATCH v2 3/5] HID: Extract vivaldi hid feature mapping for use in hid-hammer Date: Wed, 9 Feb 2022 14:55:54 -0800 Message-Id: <20220209225556.3992827-4-swboyd@chromium.org> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220209225556.3992827-1-swboyd@chromium.org> References: <20220209225556.3992827-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org We need to support parsing the HID device in both the vivaldi and the hammer drivers so that we can properly expose the function row physmap to userspace when a hammer device uses a vivaldi keyboard layout for the function row keys. Extract the feature mapping logic from the vivaldi driver into an hid specific vivaldi library so we can use it from both HID drivers. Cc: Jiri Kosina Cc: Dmitry Torokhov Cc: "Sean O'Brien" Cc: Douglas Anderson Cc: Zhengqiao Xia Signed-off-by: Stephen Boyd --- drivers/hid/Kconfig | 9 +++ drivers/hid/Makefile | 1 + drivers/hid/hid-vivaldi-common.c | 97 ++++++++++++++++++++++++++++ drivers/hid/hid-vivaldi.c | 69 +------------------- include/linux/input/vivaldi-keymap.h | 9 +++ 5 files changed, 118 insertions(+), 67 deletions(-) create mode 100644 drivers/hid/hid-vivaldi-common.c diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 5569a2029dab..ea8fa71c9e9c 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -403,14 +403,23 @@ config HOLTEK_FF Say Y here if you have a Holtek On Line Grip based game controller and want to have force feedback support for it. +config HID_VIVALDI_COMMON + tristate + help + ChromeOS Vivaldi HID parsing support library. This is a hidden + option so that drivers can use common code to parse the HID + descriptors for vivaldi function row keymap. + config HID_GOOGLE_HAMMER tristate "Google Hammer Keyboard" + select HID_VIVALDI_COMMON depends on USB_HID && LEDS_CLASS && CROS_EC help Say Y here if you have a Google Hammer device. config HID_VIVALDI tristate "Vivaldi Keyboard" + select HID_VIVALDI_COMMON select INPUT_VIVALDIFMAP depends on HID help diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 6d3e630e81af..469a6159ebae 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_HID_FT260) += hid-ft260.o obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o obj-$(CONFIG_HID_GFRM) += hid-gfrm.o obj-$(CONFIG_HID_GLORIOUS) += hid-glorious.o +obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o obj-$(CONFIG_HID_VIVALDI) += hid-vivaldi.o obj-$(CONFIG_HID_GT683R) += hid-gt683r.o diff --git a/drivers/hid/hid-vivaldi-common.c b/drivers/hid/hid-vivaldi-common.c new file mode 100644 index 000000000000..c00f11e6530f --- /dev/null +++ b/drivers/hid/hid-vivaldi-common.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helpers for ChromeOS HID Vivaldi keyboards + * + * Copyright (C) 2022 Google, Inc + */ + +#include +#include +#include +#include +#include +#include + +#define HID_VD_FN_ROW_PHYSMAP 0x00000001 +#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP) + +/** + * vivaldi_hid_feature_mapping - Fill out vivaldi keymap data exposed via HID + * @data: The vivaldi function keymap + * @hdev: HID device to parse + * @field: HID field to parse + * @usage: HID usage to parse + */ +void vivaldi_hid_feature_mapping(struct vivaldi_data *data, + struct hid_device *hdev, + struct hid_field *field, + struct hid_usage *usage) +{ + struct hid_report *report = field->report; + int fn_key; + int ret; + u32 report_len; + u8 *report_data, *buf; + + if (field->logical != HID_USAGE_FN_ROW_PHYSMAP || + (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL) + return; + + fn_key = (usage->hid & HID_USAGE); + if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY) + return; + if (fn_key > data->num_function_row_keys) + data->num_function_row_keys = fn_key; + + report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL); + if (!report_data) + return; + + report_len = hid_report_len(report); + if (!report->id) { + /* + * hid_hw_raw_request() will stuff report ID (which will be 0) + * into the first byte of the buffer even for unnumbered + * reports, so we need to account for this to avoid getting + * -EOVERFLOW in return. + * Note that hid_alloc_report_buf() adds 7 bytes to the size + * so we can safely say that we have space for an extra byte. + */ + report_len++; + } + + ret = hid_hw_raw_request(hdev, report->id, report_data, + report_len, HID_FEATURE_REPORT, + HID_REQ_GET_REPORT); + if (ret < 0) { + dev_warn(&hdev->dev, "failed to fetch feature %d\n", + field->report->id); + goto out; + } + + if (!report->id) { + /* + * Undo the damage from hid_hw_raw_request() for unnumbered + * reports. + */ + report_data++; + report_len--; + } + + ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data, + report_len, 0); + if (ret) { + dev_warn(&hdev->dev, "failed to report feature %d\n", + field->report->id); + goto out; + } + + data->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] = + field->value[usage->usage_index]; + +out: + kfree(buf); +} +EXPORT_SYMBOL_GPL(vivaldi_hid_feature_mapping); + +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c index 78ae3725bc89..361ba6200387 100644 --- a/drivers/hid/hid-vivaldi.c +++ b/drivers/hid/hid-vivaldi.c @@ -13,9 +13,6 @@ #include #include -#define HID_VD_FN_ROW_PHYSMAP 0x00000001 -#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP) - static ssize_t function_row_physmap_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -60,70 +57,8 @@ static void vivaldi_feature_mapping(struct hid_device *hdev, struct hid_usage *usage) { struct vivaldi_data *drvdata = hid_get_drvdata(hdev); - struct hid_report *report = field->report; - int fn_key; - int ret; - u32 report_len; - u8 *report_data, *buf; - - if (field->logical != HID_USAGE_FN_ROW_PHYSMAP || - (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL) - return; - - fn_key = (usage->hid & HID_USAGE); - if (fn_key < VIVALDI_MIN_FN_ROW_KEY || fn_key > VIVALDI_MAX_FN_ROW_KEY) - return; - if (fn_key > drvdata->num_function_row_keys) - drvdata->num_function_row_keys = fn_key; - - report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL); - if (!report_data) - return; - - report_len = hid_report_len(report); - if (!report->id) { - /* - * hid_hw_raw_request() will stuff report ID (which will be 0) - * into the first byte of the buffer even for unnumbered - * reports, so we need to account for this to avoid getting - * -EOVERFLOW in return. - * Note that hid_alloc_report_buf() adds 7 bytes to the size - * so we can safely say that we have space for an extra byte. - */ - report_len++; - } - - ret = hid_hw_raw_request(hdev, report->id, report_data, - report_len, HID_FEATURE_REPORT, - HID_REQ_GET_REPORT); - if (ret < 0) { - dev_warn(&hdev->dev, "failed to fetch feature %d\n", - field->report->id); - goto out; - } - - if (!report->id) { - /* - * Undo the damage from hid_hw_raw_request() for unnumbered - * reports. - */ - report_data++; - report_len--; - } - - ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data, - report_len, 0); - if (ret) { - dev_warn(&hdev->dev, "failed to report feature %d\n", - field->report->id); - goto out; - } - - drvdata->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] = - field->value[usage->usage_index]; - -out: - kfree(buf); + + vivaldi_hid_feature_mapping(drvdata, hdev, field, usage); } static int vivaldi_input_configured(struct hid_device *hdev, diff --git a/include/linux/input/vivaldi-keymap.h b/include/linux/input/vivaldi-keymap.h index 4023b65e1649..7cf5bc650fed 100644 --- a/include/linux/input/vivaldi-keymap.h +++ b/include/linux/input/vivaldi-keymap.h @@ -4,6 +4,10 @@ #include +struct hid_device; +struct hid_field; +struct hid_usage; + #define VIVALDI_MIN_FN_ROW_KEY 1 #define VIVALDI_MAX_FN_ROW_KEY 24 @@ -25,4 +29,9 @@ struct vivaldi_data { ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data, char *buf); +void vivaldi_hid_feature_mapping(struct vivaldi_data *data, + struct hid_device *hdev, + struct hid_field *field, + struct hid_usage *usage); + #endif /* _VIVALDI_KEYMAP_H */ From patchwork Wed Feb 9 22:55:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12741041 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28C67C433F5 for ; Wed, 9 Feb 2022 22:56:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236628AbiBIW4L (ORCPT ); Wed, 9 Feb 2022 17:56:11 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236620AbiBIW4A (ORCPT ); Wed, 9 Feb 2022 17:56:00 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE64C0219EC for ; Wed, 9 Feb 2022 14:56:03 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id d9-20020a17090a498900b001b8bb1d00e7so3765830pjh.3 for ; Wed, 09 Feb 2022 14:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=58Fa3Wh9DcmUEAhH/K1NiJCQawyeai7Qep950CRfr5k=; b=LZtxDVpWicPa4w8Wq3phXbi/oOPDH4QN6BokfH9WqfnCetqmgBrmta4bdAnVJPyNib AjETUBbfdgN7+2qcEjVe+hY64DvCEWbzz+zp4AlM68NW1ZUawxQtpeRlxvH925fabIL2 SRbFvhN7nriYiR/t2/hWYqrFYQQP5tSSeQwY8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=58Fa3Wh9DcmUEAhH/K1NiJCQawyeai7Qep950CRfr5k=; b=qxtoy2ri5EGn21XB3ZhcEVsmx0Y6fNrUElNPnZqymOC4/+i7E0Lu4Qvia2KZMCNL82 HQO1oQg1owA9mey8Ft5muBaoPpVNJznKLkrmTmslMJf1OfbAP5CsirsDaCaQN7F5nYRF q06sJgGCUDsxWiigxU++VCNZTaSszVyAMuY+7mNEQXaGPyIHNLySk3x+0kvdjFscjakW 8nqE8F1okysGIzH2MNjVVci603WRtpOOYsr0Zs9ndcBCbN1+bfsG3Dr035Z3mhml2oDi g59KGVYjhdbv2+QmnShMZP3G32VyuRAKXPF1Eu4M2MnLfMIBXb6InAbotVFaGZ1NwVyH DTNw== X-Gm-Message-State: AOAM531729L+qKX2vlTYsNyMHxcNyQ/bxlOLSyBp5lTaq64gS9G87SAZ xNdD4cJfmPSQw9oyCAAz8ugIuA== X-Google-Smtp-Source: ABdhPJxwRB+ksK3viTMSliugPrEX+GZbnY799z2QUwDuZmxom2YpBct/5u44LjV9pzBmvb6cRh44mQ== X-Received: by 2002:a17:90b:350c:: with SMTP id ls12mr5100463pjb.182.1644447362806; Wed, 09 Feb 2022 14:56:02 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:5193:6865:e38e:3a5b]) by smtp.gmail.com with ESMTPSA id b1sm5982015pgb.66.2022.02.09.14.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:56:02 -0800 (PST) From: Stephen Boyd To: benjamin.tissoires@redhat.com, Dmitry Torokhov , Jiri Kosina Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, "Sean O'Brien" , Douglas Anderson , Zhengqiao Xia Subject: [PATCH v2 4/5] HID: google: Add support for vivaldi to hid-hammer Date: Wed, 9 Feb 2022 14:55:55 -0800 Message-Id: <20220209225556.3992827-5-swboyd@chromium.org> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220209225556.3992827-1-swboyd@chromium.org> References: <20220209225556.3992827-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add support to the hammer driver to parse vivaldi keyboard layouts and expose them to userspace. This allows hammer devices to use vivaldi function row keys while also supporting the other features this driver supports, like the CBAS (chrome base attached switch) and a keyboard backlight. Cc: Jiri Kosina Cc: Dmitry Torokhov Cc: "Sean O'Brien" Cc: Douglas Anderson Cc: Zhengqiao Xia Signed-off-by: Stephen Boyd --- drivers/hid/Kconfig | 1 + drivers/hid/hid-google-hammer.c | 95 +++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 21 deletions(-) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index ea8fa71c9e9c..4bea966e617b 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -413,6 +413,7 @@ config HID_VIVALDI_COMMON config HID_GOOGLE_HAMMER tristate "Google Hammer Keyboard" select HID_VIVALDI_COMMON + select INPUT_VIVALDIFMAP depends on USB_HID && LEDS_CLASS && CROS_EC help Say Y here if you have a Google Hammer device. diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 0403beb3104b..e3dd26ddbd43 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include #include "hid-ids.h" @@ -300,6 +302,11 @@ struct hammer_kbd_leds { u8 buf[2] ____cacheline_aligned; }; +struct hammer_drvdata { + struct vivaldi_data vdata; + struct hammer_kbd_leds leds; +}; + static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, enum led_brightness br) { @@ -337,15 +344,11 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, return ret; } -static int hammer_register_leds(struct hid_device *hdev) +static int hammer_register_leds(struct hammer_drvdata *hdata, struct hid_device *hdev) { struct hammer_kbd_leds *kbd_backlight; - int error; - - kbd_backlight = kzalloc(sizeof(*kbd_backlight), GFP_KERNEL); - if (!kbd_backlight) - return -ENOMEM; + kbd_backlight = &hdata->leds; kbd_backlight->hdev = hdev; kbd_backlight->cdev.name = "hammer::kbd_backlight"; kbd_backlight->cdev.max_brightness = MAX_BRIGHTNESS; @@ -356,26 +359,16 @@ static int hammer_register_leds(struct hid_device *hdev) /* Set backlight to 0% initially. */ hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0); - error = led_classdev_register(&hdev->dev, &kbd_backlight->cdev); - if (error) - goto err_free_mem; - - hid_set_drvdata(hdev, kbd_backlight); - return 0; - -err_free_mem: - kfree(kbd_backlight); - return error; + return led_classdev_register(&hdev->dev, &kbd_backlight->cdev); } static void hammer_unregister_leds(struct hid_device *hdev) { - struct hammer_kbd_leds *kbd_backlight = hid_get_drvdata(hdev); + struct hammer_drvdata *hdata = hid_get_drvdata(hdev); + struct hammer_kbd_leds *kbd_backlight = &hdata->leds; - if (kbd_backlight) { + if (kbd_backlight) led_classdev_unregister(&kbd_backlight->cdev); - kfree(kbd_backlight); - } } #define HID_UP_GOOGLEVENDOR 0xffd10000 @@ -385,6 +378,58 @@ static void hammer_unregister_leds(struct hid_device *hdev) /* HID usage for keyboard backlight (Alphanumeric display brightness) */ #define HID_AD_BRIGHTNESS 0x00140046 +static void hammer_feature_mapping(struct hid_device *hdev, + struct hid_field *field, + struct hid_usage *usage) +{ + struct hammer_drvdata *hdata = hid_get_drvdata(hdev); + + vivaldi_hid_feature_mapping(&hdata->vdata, hdev, field, usage); +} + +static ssize_t function_row_physmap_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct hid_device *hdev = to_hid_device(dev); + struct hammer_drvdata *hdata = hid_get_drvdata(hdev); + struct vivaldi_data *vdata = &hdata->vdata; + + return vivaldi_function_row_physmap_show(vdata, buf); +} + +static DEVICE_ATTR_RO(function_row_physmap); +static struct attribute *hammer_sysfs_attrs[] = { + &dev_attr_function_row_physmap.attr, + NULL +}; + +static umode_t hammer_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct hid_device *hdev = to_hid_device(dev); + struct hammer_drvdata *hdata = hid_get_drvdata(hdev); + struct vivaldi_data *vdata = &hdata->vdata; + + if (attr == &dev_attr_function_row_physmap.attr && + !vdata->num_function_row_keys) + return 0; + + return attr->mode; +} + +static const struct attribute_group input_attribute_group = { + .is_visible = hammer_attr_is_visible, + .attrs = hammer_sysfs_attrs, +}; + +static int hammer_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + return sysfs_create_group(&hdev->dev.kobj, &input_attribute_group); +} + static int hammer_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, @@ -516,6 +561,12 @@ static int hammer_probe(struct hid_device *hdev, const struct hid_device_id *id) { int error; + struct hammer_drvdata *hdata; + + hdata = devm_kzalloc(&hdev->dev, sizeof(*hdata), GFP_KERNEL); + if (!hdata) + return -ENOMEM; + hid_set_drvdata(hdev, hdata); error = hid_parse(hdev); if (error) @@ -541,7 +592,7 @@ static int hammer_probe(struct hid_device *hdev, } if (hammer_has_backlight_control(hdev)) { - error = hammer_register_leds(hdev); + error = hammer_register_leds(hdata, hdev); if (error) hid_warn(hdev, "Failed to register keyboard backlight: %d\n", @@ -610,6 +661,8 @@ static struct hid_driver hammer_driver = { .id_table = hammer_devices, .probe = hammer_probe, .remove = hammer_remove, + .feature_mapping = hammer_feature_mapping, + .input_configured = hammer_input_configured, .input_mapping = hammer_input_mapping, .event = hammer_event, }; From patchwork Wed Feb 9 22:55:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 12741042 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C879C433FE for ; Wed, 9 Feb 2022 22:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236601AbiBIW4M (ORCPT ); Wed, 9 Feb 2022 17:56:12 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236641AbiBIW4B (ORCPT ); Wed, 9 Feb 2022 17:56:01 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D685E04BEAF for ; Wed, 9 Feb 2022 14:56:04 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id t4-20020a17090a510400b001b8c4a6cd5dso3751005pjh.5 for ; Wed, 09 Feb 2022 14:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HZuOJxErdx75B/XhX4U4+Jmre2nmp1Aql4lPGNRbh74=; b=BZCYaLZJ72Lr18F9LbSoJpXl8uFXbNwwSa++F3WdUBrC4dx6FmGhX503X68xqi/L8L Iih/akndZicOcnZ5Hn2RpZxC9jEHc5snh7MUeHtg4CRTfsHADPjaF0Lo5N8klocTz5Wo FP90MYvC89pOuv3vNHGs+tV2Cj0gu8vnxN4Ns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HZuOJxErdx75B/XhX4U4+Jmre2nmp1Aql4lPGNRbh74=; b=kDhqnxjRd/pC0tqYwO/o+FCn8PUQUczmQu5INCF3hz9iXQPDab4URj/S4XCxKuW4Tz vUIrbu1vwsxCu89zh4rCmbvBDmtgl9ELOOam81Q7CyCMYO5w5i1J+AGezvcS35oVTSFg 6mGDM491DjqxXmwiR8lw8/1H0jyrtuetgwiyE7dlPkS+ZRBdKfscbhu2ws3Nwz6iK4yq zMQwUFXQlI6dSRIfGC20n2lH5DzMlYtarY29mi4ddlwevpQawPcSsX815Z3kI8I0iK7h /XrVaJE616/AmVYMMNDc91/2SPRJX9/3wEjjU/PlJaPsJ64w4ZGMzyxtzZkRGgmeHM0j PDpw== X-Gm-Message-State: AOAM532WttJ4Pn8fAVFEyb+UvVHEnufEFYhQG9KUp7lh9WkPzMFlvlMt j6JQUjdB8TXdcslK7YK1RYH64g== X-Google-Smtp-Source: ABdhPJzft2yBweLZEkRQW0naWztlGqli0RbJWdb6uQMBO2ybSilpILtlONJZp8fjSTCMMa3zkYrsCA== X-Received: by 2002:a17:90b:188a:: with SMTP id mn10mr5884867pjb.186.1644447363867; Wed, 09 Feb 2022 14:56:03 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:5193:6865:e38e:3a5b]) by smtp.gmail.com with ESMTPSA id b1sm5982015pgb.66.2022.02.09.14.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 14:56:03 -0800 (PST) From: Stephen Boyd To: benjamin.tissoires@redhat.com, Dmitry Torokhov , Jiri Kosina Cc: Zhengqiao Xia , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, "Sean O'Brien" , Douglas Anderson Subject: [PATCH v2 5/5] HID: google: modify HID device groups of eel Date: Wed, 9 Feb 2022 14:55:56 -0800 Message-Id: <20220209225556.3992827-6-swboyd@chromium.org> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220209225556.3992827-1-swboyd@chromium.org> References: <20220209225556.3992827-1-swboyd@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Zhengqiao Xia If HID_GROUP of eel is set to HID_GROUP_GENERIC, Whiskers Tablet Mode Switch of eel hammer will not be detected by system because the hid-vivaldi driver probes the device. When it is set to HID_GROUP_VIVALDI, system will detect Whiskers Tablet Mode Switch successfully and also support the vivaldi keyboard layout. Cc: Jiri Kosina Cc: Dmitry Torokhov Cc: "Sean O'Brien" Cc: Douglas Anderson Signed-off-by: Zhengqiao Xia [swboyd@chromium.org: Expand on commit text] Signed-off-by: Stephen Boyd --- drivers/hid/hid-google-hammer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index e3dd26ddbd43..8ed75bb0878f 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -636,7 +636,7 @@ static void hammer_remove(struct hid_device *hdev) static const struct hid_device_id hammer_devices[] = { { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_DON) }, - { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, + { HID_DEVICE(BUS_USB, HID_GROUP_VIVALDI, USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_EEL) }, { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_HAMMER) },