From nobody Mon Jun 29 17:36:49 2026 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 1478FC433FE for ; Fri, 4 Feb 2022 20:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237701AbiBDUUe (ORCPT ); Fri, 4 Feb 2022 15:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237223AbiBDUU3 (ORCPT ); Fri, 4 Feb 2022 15:20:29 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC2B5C061401 for ; Fri, 4 Feb 2022 12:20:24 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id t12-20020a17090a3e4c00b001b87b6fd18aso203980pjm.0 for ; Fri, 04 Feb 2022 12:20:24 -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=hIUv1MO1iy6sJ6WYNc3M1xUaiyEzoDA2Zqsi2W+B1jw=; b=B8DEv/UQfza4NiLvx5+FMWS6eWfCad/NG2Iuh8em+mborNFxW36oGKfNmHA+k4EKbv 34upCx6i1VyR6H4elqTcDjAe8qi1FNjWGIiP8Vy04zHa2/mbZA7gHiEaFMqZMA+Xl/+9 79Vo0YX5u7mvKXUbwRZGUMoxx0AoPsQNr3aTE= 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=hIUv1MO1iy6sJ6WYNc3M1xUaiyEzoDA2Zqsi2W+B1jw=; b=FRNGkXwlVV5ckze5ArtNr3Xt/rUBI/83+nrnDSdsTWXVRmg8vv75JCZfKwIbfDubmU qQC0Q+AP9Eg8KXNQ1Ap1GpaLJx1S48pa0rG6ZiEyzUtjIWdYgn28ZGN469/4dIBYGzrT N3ibvK/meMPV5Aj2lh8UdOzStHZFtDasHBncHI99250dkcx2Naoh637/G5mp5rqXA8ki +M7g9hEASvodq1Tm6l2g+b0vRizMBEzJ9PkL+sQHJfjSEsKrmhohxnnwOTnikfzHKzcP qtzcsGUB+GMahS3n7fyDm8z+9N/dkiyBj8/CPYC1eur5AAUDTSxQhIlnHTqInLn8oN+l fBIQ== X-Gm-Message-State: AOAM532P8sMbU1YWYUNLd8wlhwCexq/1SLmw1Y9yMOoeU6iqvalErKrY v9+Rm7v+1d6E79O46c3unvgDWg== X-Google-Smtp-Source: ABdhPJycvyGMuUD4ZFKKoIUOW4gSawF+pLMxgQJKQNHGGkgRQruC7lpRN2AOdG33xdVZhvw1ElNrNA== X-Received: by 2002:a17:903:41c6:: with SMTP id u6mr4932478ple.6.1644006024339; Fri, 04 Feb 2022 12:20:24 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1ba2:dd59:3b59:18bc]) by smtp.gmail.com with ESMTPSA id q17sm3385561pfk.108.2022.02.04.12.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 12:20:24 -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 1/5] Input: atkbd: Convert function_row_physmap to u16 array Date: Fri, 4 Feb 2022 12:20:17 -0800 Message-Id: <20220204202021.895426-2-swboyd@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204202021.895426-1-swboyd@chromium.org> References: <20220204202021.895426-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- Note this makes a large array on the stack (32 * 24 =3D 768 bytes). It could be moved to the heap with a kmalloc or we could accept the extra 16 * 24 =3D 384 bytes for the vivaldi_data struct if it has a u32, or we can be more precise and make that a u16 pointer in vivaldi_data and move=20 the array to the heap. 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; =20 - u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; + u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; int num_function_row_keys; }; =20 @@ -1202,14 +1202,17 @@ static void atkbd_parse_fwnode_data(struct serio *s= erio) { struct atkbd *atkbd =3D serio_get_drvdata(serio); struct device *dev =3D &serio->dev; - int n; + int i, n; + u32 physmap[MAX_FUNCTION_ROW_KEYS]; =20 /* Parse "function-row-physmap" property */ n =3D device_property_count_u32(dev, "function-row-physmap"); if (n > 0 && n <=3D 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 =3D n; + for (i =3D 0; i < n; i++) + atkbd->function_row_physmap[i] =3D physmap[i]; dev_dbg(dev, "FW reported %d function-row key locations\n", n); } } --=20 https://chromeos.dev From nobody Mon Jun 29 17:36:49 2026 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 4C04DC433F5 for ; Fri, 4 Feb 2022 20:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237825AbiBDUUh (ORCPT ); Fri, 4 Feb 2022 15:20:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237254AbiBDUU3 (ORCPT ); Fri, 4 Feb 2022 15:20:29 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1450AC061744 for ; Fri, 4 Feb 2022 12:20:26 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id d186so5910753pgc.9 for ; Fri, 04 Feb 2022 12:20:26 -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=AzqVXDA8325xWyck4kK1mH4J1g/oDL9rbfCTX+KpW10=; b=e64XQoh0Goucy4J/us8IhE3k+JLUoqijhahBzbyR8NnZX6XpioTmMrPfZxta1Bo6rN 636zwvPUQW9xWUxStyRPLv5JFOWrSi5h2Ne3Fk85lS56QnaT0bSHoZp25sNfi7nuURxE A3xNsJeVteWeVyQ4S12pZBrbc+aDL8jApW4Ho= 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=AzqVXDA8325xWyck4kK1mH4J1g/oDL9rbfCTX+KpW10=; b=ASaG3dixM070c/tWemNL/sKgE0NZbKSzhQ/k6JtKUKQS4PlII0hNWx/Ij2LNSMu74Z nTRGyDIO1AmZjLtKBUJLFlxM9k+DYQI73M5HHNrs7J45XpnjnZNhnZ5FwOTkmUEvatoE jc/gSRelIyreFkCBeu1AoLGviPzVuCmlBOT84JwALUVBD23FOdL4DwWLjWn0tksvFHEi hJwup+x2J0FVEPxKSm3gdiVKHMLosjH5/coZBPEQYC1Cs1ZgdnmmQTIW5wn1vVI2+9R1 6fIQQOEulmcd2+utgp6sjqQ8XbWH07luKlN/jNlOCd0qV3ZHwssGZcPBOXv4YzLJo1VZ ndBA== X-Gm-Message-State: AOAM532Gt0YzLBtMVT8HK57aqBR0RdxPmf92Uj1pEX6zTLGJS8cdLWEn VyZ+5pxvOpd3Y8K4gn7Fi69U4A== X-Google-Smtp-Source: ABdhPJzfiIUenC9xKziWxME4vehKjx0a/ixMnNdDrkjPKmcWoPXmyloDdp99b7mQrdmLPrMXV6MlYw== X-Received: by 2002:a63:8941:: with SMTP id v62mr587060pgd.228.1644006025429; Fri, 04 Feb 2022 12:20:25 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1ba2:dd59:3b59:18bc]) by smtp.gmail.com with ESMTPSA id q17sm3385561pfk.108.2022.02.04.12.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 12:20:25 -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 2/5] Input: Extract ChromeOS vivaldi physmap show function Date: Fri, 4 Feb 2022 12:20:18 -0800 Message-Id: <20220204202021.895426-3-swboyd@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204202021.895426-1-swboyd@chromium.org> References: <20220204202021.895426-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 allmodconfig 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=3D285581925, After=3D285581617, 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 =20 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 @@ =20 #include #include +#include #include #include #include =20 -#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_PHYS= MAP) =20 -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 =3D to_hid_device(dev); struct vivaldi_data *drvdata =3D hid_get_drvdata(hdev); - ssize_t size =3D 0; - int i; - - if (!drvdata->max_function_row_key) - return 0; =20 - for (i =3D 0; i < drvdata->max_function_row_key; i++) - size +=3D sprintf(buf + size, "%02X ", - drvdata->function_row_physmap[i]); - size +=3D sprintf(buf + size, "\n"); - return size; + return vivaldi_function_row_physmap_show(drvdata, buf); } =20 static DEVICE_ATTR_RO(function_row_physmap); @@ -86,10 +71,10 @@ static void vivaldi_feature_mapping(struct hid_device *= hdev, return; =20 fn_key =3D (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 =3D fn_key; + if (fn_key > drvdata->num_function_row_keys) + drvdata->num_function_row_keys =3D fn_key; =20 report_data =3D buf =3D 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; } =20 - drvdata->function_row_physmap[fn_key - MIN_FN_ROW_KEY] =3D + drvdata->function_row_physmap[fn_key - VIVALDI_MIN_FN_ROW_KEY] =3D field->value[usage->usage_index]; =20 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. =20 +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" =20 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 +=3D touchscreen.o obj-$(CONFIG_INPUT_FF_MEMLESS) +=3D ff-memless.o obj-$(CONFIG_INPUT_SPARSEKMAP) +=3D sparse-keymap.o obj-$(CONFIG_INPUT_MATRIXKMAP) +=3D matrix-keymap.o +obj-$(CONFIG_INPUT_VIVALDIFMAP) +=3D vivaldi-keymap.o =20 obj-$(CONFIG_INPUT_LEDS) +=3D input-leds.o obj-$(CONFIG_INPUT_MOUSEDEV) +=3D 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; =20 - u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; - int num_function_row_keys; + struct vivaldi_data vdata; }; =20 /* @@ -308,17 +308,9 @@ static struct attribute *atkbd_attributes[] =3D { =20 static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *= buf) { - ssize_t size =3D 0; - int i; - - if (!atkbd->num_function_row_keys) - return 0; + const struct vivaldi_data *data =3D &atkbd->vdata; =20 - for (i =3D 0; i < atkbd->num_function_row_keys; i++) - size +=3D scnprintf(buf + size, PAGE_SIZE - size, "%02X ", - atkbd->function_row_physmap[i]); - size +=3D scnprintf(buf + size, PAGE_SIZE - size, "\n"); - return size; + return vivaldi_function_row_physmap_show(data, buf); } =20 static umode_t atkbd_attr_is_visible(struct kobject *kobj, @@ -329,7 +321,7 @@ static umode_t atkbd_attr_is_visible(struct kobject *ko= bj, struct atkbd *atkbd =3D serio_get_drvdata(serio); =20 if (attr =3D=3D &atkbd_attr_function_row_physmap.attr && - !atkbd->num_function_row_keys) + !atkbd->vdata.num_function_row_keys) return 0; =20 return attr->mode; @@ -1210,9 +1202,9 @@ static void atkbd_parse_fwnode_data(struct serio *ser= io) if (n > 0 && n <=3D MAX_FUNCTION_ROW_KEYS && !device_property_read_u32_array(dev, "function-row-physmap", physmap, n)) { - atkbd->num_function_row_keys =3D n; + atkbd->vdata.num_function_row_keys =3D n; for (i =3D 0; i < n; i++) - atkbd->function_row_physmap[i] =3D physmap[i]; + atkbd->vdata.function_row_physmap[i] =3D 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; =20 - u16 function_row_physmap[MAX_NUM_TOP_ROW_KEYS]; - size_t num_function_row_keys; + struct vivaldi_data vdata; }; =20 /** @@ -591,10 +589,10 @@ static int cros_ec_keyb_register_matrix(struct cros_e= c_keyb *ckdev) ckdev->idev =3D idev; cros_ec_keyb_compute_valid_keys(ckdev); =20 - physmap =3D ckdev->function_row_physmap; + physmap =3D 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 =3D=3D MAX_NUM_TOP_ROW_KEYS) { + if (ckdev->vdata.num_function_row_keys =3D=3D 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 =3D KEY_COL(key_pos); *physmap =3D MATRIX_SCAN_CODE(row, col, ckdev->row_shift); physmap++; - ckdev->num_function_row_keys++; + ckdev->vdata.num_function_row_keys++; } =20 err =3D input_register_device(ckdev->idev); @@ -619,18 +617,10 @@ static ssize_t function_row_physmap_show(struct devic= e *dev, struct device_attribute *attr, char *buf) { - ssize_t size =3D 0; - int i; - struct cros_ec_keyb *ckdev =3D dev_get_drvdata(dev); - u16 *physmap =3D ckdev->function_row_physmap; - - for (i =3D 0; i < ckdev->num_function_row_keys; i++) - size +=3D scnprintf(buf + size, PAGE_SIZE - size, - "%s%02X", size ? " " : "", physmap[i]); - if (size) - size +=3D scnprintf(buf + size, PAGE_SIZE - size, "\n"); + const struct cros_ec_keyb *ckdev =3D dev_get_drvdata(dev); + const struct vivaldi_data *data =3D &ckdev->vdata; =20 - return size; + return vivaldi_function_row_physmap_show(data, buf); } =20 static DEVICE_ATTR_RO(function_row_physmap); @@ -648,7 +638,7 @@ static umode_t cros_ec_keyb_attr_is_visible(struct kobj= ect *kobj, struct cros_ec_keyb *ckdev =3D dev_get_drvdata(dev); =20 if (attr =3D=3D &dev_attr_function_row_physmap.attr && - !ckdev->num_function_row_keys) + !ckdev->vdata.num_function_row_keys) return 0; =20 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 =3D 0; + int i; + const u16 *physmap =3D data->function_row_physmap; + + if (!data->num_function_row_keys) + return 0; + + for (i =3D 0; i < data->num_function_row_keys; i++) + size +=3D scnprintf(buf + size, PAGE_SIZE - size, + "%s%02X", size ? " " : "", physmap[i]); + if (size) + size +=3D 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/viv= aldi-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 key= boards + * @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 */ --=20 https://chromeos.dev From nobody Mon Jun 29 17:36:49 2026 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 C3BBFC433F5 for ; Fri, 4 Feb 2022 20:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238419AbiBDUUn (ORCPT ); Fri, 4 Feb 2022 15:20:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237509AbiBDUUb (ORCPT ); Fri, 4 Feb 2022 15:20:31 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E37C06174E for ; Fri, 4 Feb 2022 12:20:27 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id d5so6602927pjk.5 for ; Fri, 04 Feb 2022 12:20:27 -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=tMoGWwtYjtAOUkhvjOCJhK5Z921yyMCRTQ3P/6tLMeQ=; b=EZQw7V0nciNULmOoKV0u6+j3J4Th8yfFdf2cixYWjKZzUxhmEE9UrcN8ziHQi+Wr/Y +wf98/Jjury9vKO+q8e4YmOheXUMX77em3S3OTeuMbty8gImxuUsR274hlQFr2/m/WPU UBf3vWPDR3jhjm5EpQmVpfa2R6C5q0Xh8a494= 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=tMoGWwtYjtAOUkhvjOCJhK5Z921yyMCRTQ3P/6tLMeQ=; b=v8BRj8rETAjnGvr5+Yz7qnqhixeNNb1qrnfZ05ygnoQeSKP1nd8jMwwQUpY3m0eKLp IG7hwALY7g9RcWcLT5QDevIEDRQEqAfzdX4fBvRwTMDkso/ZtQsT2abqVXQqIRAIr8HG fGmMp/Bd6kUBKbNffei0Snb9rykmmYdwNnmBGuUmQ8GLjx5n930gAegq6aHOuucBLViK indqyEatO15m0UOX06vyfSp+uCneKOBYB+nZiOrGhoJPI54JktjXxh5OJZQsuXazKwfS Rru1ho0tg7xQGnzyMJfVu0q3aPAB0RAODzg7gIQst+d8qMuHlDnZ4dUdCCGUOGcMzyeQ YSkw== X-Gm-Message-State: AOAM533jhloA2U5i+rlq+jAJNMmZjMH0EQIGs6lsrB2w4MKjPYPjyrSG YnwUdV2w1AERPcBpioQvAop1bQ== X-Google-Smtp-Source: ABdhPJzwzksZG09mPu3PVdnBmhWKM/mGYwFEmZf3l2C9kovSBF42eZ1ixFuDBFfZMLITTgq3Zy/D7Q== X-Received: by 2002:a17:902:e5c3:: with SMTP id u3mr1779787plf.21.1644006026504; Fri, 04 Feb 2022 12:20:26 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1ba2:dd59:3b59:18bc]) by smtp.gmail.com with ESMTPSA id q17sm3385561pfk.108.2022.02.04.12.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 12:20:26 -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 3/5] HID: Extract vivaldi hid feature mapping for use in hid-hammer Date: Fri, 4 Feb 2022 12:20:19 -0800 Message-Id: <20220204202021.895426-4-swboyd@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204202021.895426-1-swboyd@chromium.org> References: <20220204202021.895426-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 the vivaldi-keymap 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 Reported-by: kernel test robot --- drivers/hid/hid-vivaldi.c | 69 +--------------------- drivers/input/vivaldi-keymap.c | 86 ++++++++++++++++++++++++++++ include/linux/input/vivaldi-keymap.h | 9 +++ 3 files changed, 97 insertions(+), 67 deletions(-) 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 =20 -#define HID_VD_FN_ROW_PHYSMAP 0x00000001 -#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYS= MAP) - 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 *h= dev, struct hid_usage *usage) { struct vivaldi_data *drvdata =3D hid_get_drvdata(hdev); - struct hid_report *report =3D field->report; - int fn_key; - int ret; - u32 report_len; - u8 *report_data, *buf; - - if (field->logical !=3D HID_USAGE_FN_ROW_PHYSMAP || - (usage->hid & HID_USAGE_PAGE) !=3D HID_UP_ORDINAL) - return; - - fn_key =3D (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 =3D fn_key; - - report_data =3D buf =3D hid_alloc_report_buf(report, GFP_KERNEL); - if (!report_data) - return; - - report_len =3D 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 =3D 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 =3D 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] =3D - field->value[usage->usage_index]; - -out: - kfree(buf); + + vivaldi_hid_feature_mapping(drvdata, hdev, field, usage); } =20 static int vivaldi_input_configured(struct hid_device *hdev, diff --git a/drivers/input/vivaldi-keymap.c b/drivers/input/vivaldi-keymap.c index da6dc4070216..7d472b8126b2 100644 --- a/drivers/input/vivaldi-keymap.c +++ b/drivers/input/vivaldi-keymap.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -36,4 +37,89 @@ ssize_t vivaldi_function_row_physmap_show(const struct v= ivaldi_data *data, } EXPORT_SYMBOL_GPL(vivaldi_function_row_physmap_show); =20 +#if IS_ENABLED(CONFIG_HID) + +#define HID_VD_FN_ROW_PHYSMAP 0x00000001 +#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYS= MAP) + +/** + * 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 =3D field->report; + int fn_key; + int ret; + u32 report_len; + u8 *report_data, *buf; + + if (field->logical !=3D HID_USAGE_FN_ROW_PHYSMAP || + (usage->hid & HID_USAGE_PAGE) !=3D HID_UP_ORDINAL) + return; + + fn_key =3D (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 =3D fn_key; + + report_data =3D buf =3D hid_alloc_report_buf(report, GFP_KERNEL); + if (!report_data) + return; + + report_len =3D 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 =3D 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 =3D 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] =3D + field->value[usage->usage_index]; + +out: + kfree(buf); +} +EXPORT_SYMBOL_GPL(vivaldi_hid_feature_mapping); +#endif /* CONFIG_HID */ + MODULE_LICENSE("GPL"); diff --git a/include/linux/input/vivaldi-keymap.h b/include/linux/input/viv= aldi-keymap.h index 4023b65e1649..7cf5bc650fed 100644 --- a/include/linux/input/vivaldi-keymap.h +++ b/include/linux/input/vivaldi-keymap.h @@ -4,6 +4,10 @@ =20 #include =20 +struct hid_device; +struct hid_field; +struct hid_usage; + #define VIVALDI_MIN_FN_ROW_KEY 1 #define VIVALDI_MAX_FN_ROW_KEY 24 =20 @@ -25,4 +29,9 @@ struct vivaldi_data { ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data, char *buf); =20 +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 */ --=20 https://chromeos.dev From nobody Mon Jun 29 17:36:49 2026 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 20694C433EF for ; Fri, 4 Feb 2022 20:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238813AbiBDUUq (ORCPT ); Fri, 4 Feb 2022 15:20:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237616AbiBDUUe (ORCPT ); Fri, 4 Feb 2022 15:20:34 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15CB3C06173D for ; Fri, 4 Feb 2022 12:20:28 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso14113965pjv.1 for ; Fri, 04 Feb 2022 12:20:28 -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=j6C39UFn+jrEqEIOvITw0T2gh1RnTm0sOBo49+WVuDA=; b=jGvPAGwayYyRxJU/DyY/MMJwXAGIuoD2BSFjJHICXNMolE12b7ijp2RV+FCiUd7G0X orlr6ZpVrI2eM7+TuN9DaaSbqfcqk+X9nqSp87sAZUeZpXmLVJPxeuV1LqEqNAt4nx5e bs8HiyKzLPBgTC0QjvKrXdIKgKCSCjVKQvm4g= 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=j6C39UFn+jrEqEIOvITw0T2gh1RnTm0sOBo49+WVuDA=; b=3xr3ZoMcuHpTfPyCt7xfsEBZSZbzFBON8nQ+czqHfovEmsltvUxvjAShDPKTI8U6jw QLw3RWcq2Mx2qC8k6E/kDQmeuhdsk67kDsM46X05jY333YY/TuWjZIaXjROgRg/RD2AL aDg2MixaqtQwDDOkOGjfzQTvOyjk8Qv5sNDVNWb6BxaREcJFpkYXXq3Cs1NGMK8YYDiz pqDIiJ4mKDJy5EHdUeVXNnyVObz+elVSGEYtjyAYmNn7qtaBTTWdokySE1YZfr+CmbL0 b4yLc+jjkkebx7uVrVfLnx6y22WWdtwmAySpYtTn9/XnS/+CM7ieOxGNMlUICYCkd2pI GQhA== X-Gm-Message-State: AOAM533GW1FQdosTIBHtSBIaopq8KkFgse/ky5qgwGfIxUkJo8NR2eJT ezOKCNKdyBtHryaTSCyf5sy1sA== X-Google-Smtp-Source: ABdhPJy4fIjcXd5iKfn71Ecib6moONOKAzLwXXPrXvh0pjqlt8nRvQHCfG2u/CfjfwBY300zubxQ1Q== X-Received: by 2002:a17:902:d48a:: with SMTP id c10mr4746224plg.139.1644006027577; Fri, 04 Feb 2022 12:20:27 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1ba2:dd59:3b59:18bc]) by smtp.gmail.com with ESMTPSA id q17sm3385561pfk.108.2022.02.04.12.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 12:20:27 -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 4/5] HID: google: Add support for vivaldi to hid-hammer Date: Fri, 4 Feb 2022 12:20:20 -0800 Message-Id: <20220204202021.895426-5-swboyd@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204202021.895426-1-swboyd@chromium.org> References: <20220204202021.895426-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 5569a2029dab..070c4c8128e8 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -405,6 +405,7 @@ config HOLTEK_FF =20 config HID_GOOGLE_HAMMER tristate "Google Hammer Keyboard" + 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-hamme= r.c index 0403beb3104b..e3dd26ddbd43 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -15,6 +15,7 @@ =20 #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include #include +#include #include =20 #include "hid-ids.h" @@ -300,6 +302,11 @@ struct hammer_kbd_leds { u8 buf[2] ____cacheline_aligned; }; =20 +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; } =20 -static int hammer_register_leds(struct hid_device *hdev) +static int hammer_register_leds(struct hammer_drvdata *hdata, struct hid_d= evice *hdev) { struct hammer_kbd_leds *kbd_backlight; - int error; - - kbd_backlight =3D kzalloc(sizeof(*kbd_backlight), GFP_KERNEL); - if (!kbd_backlight) - return -ENOMEM; =20 + kbd_backlight =3D &hdata->leds; kbd_backlight->hdev =3D hdev; kbd_backlight->cdev.name =3D "hammer::kbd_backlight"; kbd_backlight->cdev.max_brightness =3D MAX_BRIGHTNESS; @@ -356,26 +359,16 @@ static int hammer_register_leds(struct hid_device *hd= ev) /* Set backlight to 0% initially. */ hammer_kbd_brightness_set_blocking(&kbd_backlight->cdev, 0); =20 - error =3D 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); } =20 static void hammer_unregister_leds(struct hid_device *hdev) { - struct hammer_kbd_leds *kbd_backlight =3D hid_get_drvdata(hdev); + struct hammer_drvdata *hdata =3D hid_get_drvdata(hdev); + struct hammer_kbd_leds *kbd_backlight =3D &hdata->leds; =20 - if (kbd_backlight) { + if (kbd_backlight) led_classdev_unregister(&kbd_backlight->cdev); - kfree(kbd_backlight); - } } =20 #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 =20 +static void hammer_feature_mapping(struct hid_device *hdev, + struct hid_field *field, + struct hid_usage *usage) +{ + struct hammer_drvdata *hdata =3D 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 =3D to_hid_device(dev); + struct hammer_drvdata *hdata =3D hid_get_drvdata(hdev); + struct vivaldi_data *vdata =3D &hdata->vdata; + + return vivaldi_function_row_physmap_show(vdata, buf); +} + +static DEVICE_ATTR_RO(function_row_physmap); +static struct attribute *hammer_sysfs_attrs[] =3D { + &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 =3D kobj_to_dev(kobj); + struct hid_device *hdev =3D to_hid_device(dev); + struct hammer_drvdata *hdata =3D hid_get_drvdata(hdev); + struct vivaldi_data *vdata =3D &hdata->vdata; + + if (attr =3D=3D &dev_attr_function_row_physmap.attr && + !vdata->num_function_row_keys) + return 0; + + return attr->mode; +} + +static const struct attribute_group input_attribute_group =3D { + .is_visible =3D hammer_attr_is_visible, + .attrs =3D 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 =3D devm_kzalloc(&hdev->dev, sizeof(*hdata), GFP_KERNEL); + if (!hdata) + return -ENOMEM; + hid_set_drvdata(hdev, hdata); =20 error =3D hid_parse(hdev); if (error) @@ -541,7 +592,7 @@ static int hammer_probe(struct hid_device *hdev, } =20 if (hammer_has_backlight_control(hdev)) { - error =3D hammer_register_leds(hdev); + error =3D 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 =3D { .id_table =3D hammer_devices, .probe =3D hammer_probe, .remove =3D hammer_remove, + .feature_mapping =3D hammer_feature_mapping, + .input_configured =3D hammer_input_configured, .input_mapping =3D hammer_input_mapping, .event =3D hammer_event, }; --=20 https://chromeos.dev From nobody Mon Jun 29 17:36:49 2026 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 3ECD1C433F5 for ; Fri, 4 Feb 2022 20:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238197AbiBDUUk (ORCPT ); Fri, 4 Feb 2022 15:20:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237412AbiBDUUa (ORCPT ); Fri, 4 Feb 2022 15:20:30 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AD4CC061741 for ; Fri, 4 Feb 2022 12:20:29 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id v13-20020a17090ac90d00b001b87bc106bdso141319pjt.4 for ; Fri, 04 Feb 2022 12:20:29 -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=m44UmiZNIzXcaNlxVsUNeCt11Rnd6XDmmWnZlPfuePWHe9i4X2OKyxylOLPFaVeQTQ GVKU2pFVrIGIvBnBq/JmRwCNG3tLeiH0wvEJeRKjX4IWkVuGwOxw55Lewyp4+Wp/85SP RyoB4r9/7gS1YxT0S3SlmLN9Iqve51rnPI91o= 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=BXfwaSBYNALoYKta2yMJftBfQNgFVcTxzlDVFSgtfpEpT08QH9N0r2UTqmUYG3STDT j5VvUeBaacBz5TSrDX9Tz8eLnhgFhRR3w4LW7rWDKkqb4nmcAZIBB+zyS7Ed7NvthQSZ uc4xpTpsyZrwSFFuobxHAaN+FR4a7u3K9Rng507wAs6S8w/bs9saFGJNGAg3dTMOkupF aXS/oA3kS+DmiI+0iarH5dTZuLe5CPfDgV+U7tDVJEuDmLVU6cbVWAIKGnSLsoaiZT3n otsIJ9IRRKamG1mXSRKKqXNjD8/b7AqJYt1cP9fxB7uIuNYHOCjROcgxAxpi3n0LhlBs JhIw== X-Gm-Message-State: AOAM530LW11sCF0GTClCmq5nRkhlbSZeZX3IiVHRObCKXab/VsM5SNQ4 k0LAY15V/w2uhw642mEZuh6Ouw== X-Google-Smtp-Source: ABdhPJxQ8ZCRvr4IQgSkocLn59rOK1y0Ck/eM+WqyNBRC6bb6AVM4Yk+ZuuKu16eRAdso434rpNETg== X-Received: by 2002:a17:902:c155:: with SMTP id 21mr1708641plj.31.1644006028610; Fri, 04 Feb 2022 12:20:28 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:1ba2:dd59:3b59:18bc]) by smtp.gmail.com with ESMTPSA id q17sm3385561pfk.108.2022.02.04.12.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 12:20:28 -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 5/5] HID: google: modify HID device groups of eel Date: Fri, 4 Feb 2022 12:20:21 -0800 Message-Id: <20220204202021.895426-6-swboyd@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220204202021.895426-1-swboyd@chromium.org> References: <20220204202021.895426-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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-hamme= r.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[] =3D { { 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) }, --=20 https://chromeos.dev