From patchwork Mon Feb 28 07:54:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 547415 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 51752C433EF for ; Mon, 28 Feb 2022 07:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233745AbiB1Hzb (ORCPT ); Mon, 28 Feb 2022 02:55:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbiB1Hza (ORCPT ); Mon, 28 Feb 2022 02:55:30 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886F145521 for ; Sun, 27 Feb 2022 23:54:52 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id bc27so1822295pgb.4 for ; Sun, 27 Feb 2022 23:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hOlepmP4ZU+cG5hVHf3h4lPQRDIfJJkyTKWIgz4x6tY=; b=mapqY4JoY0+YygJGCtF8yqSScZsm8gLsAPMWQ30nFr4KhsFp1Wl/FOhzU1J5d/ZyBZ M4B8XDRCFR1eUrwHkf4Ro5uYy+Hv3FqvtYc9QFzF5Vop3d1gyWVCCHNA7m1GN+KzFH11 e0IvICSHxgLj0HHjT2Z0kr0HcPVCdkfL1iO8Bqr3Mf6Y+nx01Ly3HmdNLtBDljuoH0Jc 4Pcjpdb7c1VgpEj87wITHBYzYwVtWGpVzeS8B+KZP+ksdjIFlojfwo/MWBBwoWZ5kO26 tIvY8O2syboAzFGvfV1dwYQXLYhHLgX3OEPi3bbCi+o3LBMw8x31pkw4aZ4QtU7Z+yT8 44Rw== 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=hOlepmP4ZU+cG5hVHf3h4lPQRDIfJJkyTKWIgz4x6tY=; b=4pCYkn2jlmS3KwlMjgmFWBVYgLK32Zg6Q2omglJAiSYPrDsdtlIAfohAw0IwMYyvc+ lyo0OLsp7go/JB8rQhxXWACXIQWSTc6gqqdcJS5oihVzGVIv5CJ6SKIx2L17+sSj8dtm oQ+x5M+eMSEy2Do3aWmNRzEMhToj9hidVePUMvOYZIf1h/lqE5b0B5L3d7404dUobdjC PixgwHYoMt3ZYiECe1uBeBPSIPpqIInHS5w7WGZ/YBqW+y2MGWRFzg7+af+JZjghFOaK 5RbIESbCPZePI8jhpcysjQ9H88Lh1h7HWHRpv3HUSKzyvNWYtEJYOfBG+6Q81SoZMz/2 ELtQ== X-Gm-Message-State: AOAM532c6bI7b+QiTAYS5rrJlhdxJbCsFsuWhI5Z39mNGyg3JnWZeRjA PYxhJ0NWICgaEzh2ZH1KWaTXHEjiRQk= X-Google-Smtp-Source: ABdhPJwiVTlQ1YWjghTBeqQdPt8bAcjReadejX1Ye5JpmywIUCRYc5X9q7c9uaZ5q6tYRdv7qpaQlQ== X-Received: by 2002:aa7:928c:0:b0:4f3:dca7:8b37 with SMTP id j12-20020aa7928c000000b004f3dca78b37mr13573920pfa.41.1646034891448; Sun, 27 Feb 2022 23:54:51 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:43a2:93b6:ebd7:94fd]) by smtp.gmail.com with ESMTPSA id d13-20020a17090ac24d00b001bcd7c2b2c3sm10718517pjx.16.2022.02.27.23.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 23:54:50 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stephen Boyd , benjamin.tissoires@redhat.com, Jiri Kosina , Sean O'Brien , "Douglas Anderson linux-kernel @ vger . kernel . org" Subject: [PATCH v5 1/5] HID: google: switch to devm when registering keyboard backlight LED Date: Sun, 27 Feb 2022 23:54:42 -0800 Message-Id: <20220228075446.466016-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com> References: <20220228075446.466016-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org We can use devm to register keyboard backlight LED on hammer devices, this will allow us to use HID's driver data for something else later. Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-hammer.c | 38 +++++++++++---------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 0403beb3104b..e7da4e74b4bf 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -340,9 +340,9 @@ static int hammer_kbd_brightness_set_blocking(struct led_classdev *cdev, static int hammer_register_leds(struct hid_device *hdev) { struct hammer_kbd_leds *kbd_backlight; - int error; - kbd_backlight = kzalloc(sizeof(*kbd_backlight), GFP_KERNEL); + kbd_backlight = devm_kzalloc(&hdev->dev, sizeof(*kbd_backlight), + GFP_KERNEL); if (!kbd_backlight) return -ENOMEM; @@ -356,26 +356,7 @@ 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; -} - -static void hammer_unregister_leds(struct hid_device *hdev) -{ - struct hammer_kbd_leds *kbd_backlight = hid_get_drvdata(hdev); - - if (kbd_backlight) { - led_classdev_unregister(&kbd_backlight->cdev); - kfree(kbd_backlight); - } + return devm_led_classdev_register(&hdev->dev, &kbd_backlight->cdev); } #define HID_UP_GOOGLEVENDOR 0xffd10000 @@ -512,6 +493,11 @@ static void hammer_get_folded_state(struct hid_device *hdev) kfree(buf); } +static void hammer_stop(void *hdev) +{ + hid_hw_stop(hdev); +} + static int hammer_probe(struct hid_device *hdev, const struct hid_device_id *id) { @@ -525,6 +511,10 @@ static int hammer_probe(struct hid_device *hdev, if (error) return error; + error = devm_add_action(&hdev->dev, hammer_stop, hdev); + if (error) + return error; + /* * We always want to poll for, and handle tablet mode events from * devices that have folded usage, even when nobody has opened the input @@ -577,9 +567,7 @@ static void hammer_remove(struct hid_device *hdev) spin_unlock_irqrestore(&cbas_ec_lock, flags); } - hammer_unregister_leds(hdev); - - hid_hw_stop(hdev); + /* Unregistering LEDs and stopping the hardware is done via devm */ } static const struct hid_device_id hammer_devices[] = { From patchwork Mon Feb 28 07:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 546868 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 3C25FC433F5 for ; Mon, 28 Feb 2022 07:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbiB1Hze (ORCPT ); Mon, 28 Feb 2022 02:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233751AbiB1Hzd (ORCPT ); Mon, 28 Feb 2022 02:55:33 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B7B945AF3 for ; Sun, 27 Feb 2022 23:54:54 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id u16so10350175pfg.12 for ; Sun, 27 Feb 2022 23:54:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OabbcmxJxJWwRor4LztospRi+3hYablgoflT4i1DMEw=; b=MegYvnRwvH8MvcMU7DRGWY27ubvL+q10OJ1zpNQIyFmkT3DfhndCOfhQYJpeQdvTGW k2GhMPr2JyhL9Yb2RkUdJaTzc1CD1nAfW8av23UzD+KkWdwVWa+8Hpw7m2yjpaP1+Wnn v0v//Syzz9zNaIOBnr8vlV7AQUqQaBfJdD7CwvCXfxIv2cI1GutrvlwfkDXojvUgajGF 2q4765OAnYF0lFL2RtGGcOAlweJjYY8ub+ruVfZhQwtihUnGvyURD9Z6JMgu9ORz3w5l 1Pt7ExpKOyPj4u1X170YcXbsLA06yDBUglDe7t79oefP6Z2Ioj/ebCtncNkv/gqJJkqS fXCQ== 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=OabbcmxJxJWwRor4LztospRi+3hYablgoflT4i1DMEw=; b=7aiJmtxSX5XO1lodfInHGU9Nobw6iLAuOHBNZjObdQrtvxMGnd7t8hRItSO5cE1u3U ZNRiV4H+X38CPnnM4BrOXwqcIQlpqyCKlNQ5HZfAJBJ4NiHEaQcjZzPLoMV9+jcwgEHO m63+GpkuS6hDhU+A7uWMaG1EYbpSy6tAt4Yq5bsBGy3fU4k9ZEDCWty9+8PScjbduORn WKD5m231Nuj0JRC7OXZyPyVP6XTik/bsIisqiR2OBNQdYBrRevYi1TLRuSK7UygHc/+9 u499uGb37PSGPExxxXK9YfwhQ83buxzThbdUgNuY4vzukThUuXQdJaKpxLUTT13SweT7 O6lQ== X-Gm-Message-State: AOAM530B1ItZmSMOvmM09evHhWD8wPQSdCSJWQIJCmFcUuOctdc7LcEf L2E7nFsrH+ZOIxUG6RkZyOgc7FQ0HIw= X-Google-Smtp-Source: ABdhPJzfoy0YfFt9aVua6H4hGRDVhcZ6exIk3bnf7H2UsO0p6XDoCrZ0BO3k7sIXiQlKugvMmQttdQ== X-Received: by 2002:a63:701:0:b0:374:3afb:e5d4 with SMTP id 1-20020a630701000000b003743afbe5d4mr16478425pgh.600.1646034893139; Sun, 27 Feb 2022 23:54:53 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:43a2:93b6:ebd7:94fd]) by smtp.gmail.com with ESMTPSA id d13-20020a17090ac24d00b001bcd7c2b2c3sm10718517pjx.16.2022.02.27.23.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 23:54:52 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stephen Boyd , benjamin.tissoires@redhat.com, Jiri Kosina , Sean O'Brien , "Douglas Anderson linux-kernel @ vger . kernel . org" Subject: [PATCH v5 2/5] Input: extract ChromeOS vivaldi physmap show function Date: Sun, 27 Feb 2022 23:54:43 -0800 Message-Id: <20220228075446.466016-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com> References: <20220228075446.466016-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Stephen Boyd 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% Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20220216195901.1326924-2-swboyd@chromium.org Signed-off-by: Dmitry Torokhov --- 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 | 27 +++++------------ drivers/input/keyboard/cros_ec_keyb.c | 43 ++++++++++----------------- drivers/input/vivaldi-fmap.c | 39 ++++++++++++++++++++++++ include/linux/input/vivaldi-fmap.h | 27 +++++++++++++++++ 9 files changed, 108 insertions(+), 66 deletions(-) create mode 100644 drivers/input/vivaldi-fmap.c create mode 100644 include/linux/input/vivaldi-fmap.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 42ceb2058a09..ca8cb40928e6 100644 --- a/drivers/hid/hid-vivaldi.c +++ b/drivers/hid/hid-vivaldi.c @@ -8,37 +8,24 @@ #include #include +#include #include #include #include -#define MIN_FN_ROW_KEY 1 -#define MAX_FN_ROW_KEY 24 +#define MIN_FN_ROW_KEY 1 +#define MAX_FN_ROW_KEY VIVALDI_MAX_FUNCTION_ROW_KEYS #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); @@ -85,11 +72,11 @@ static void vivaldi_feature_mapping(struct hid_device *hdev, (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL) return; - fn_key = (usage->hid & HID_USAGE); + fn_key = usage->hid & HID_USAGE; if (fn_key < MIN_FN_ROW_KEY || fn_key > 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) 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..2266c7d010ef 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-fmap.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 9417ee0b1eff..04954ecb1437 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 fbdef95291e9..d4131236d18c 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -64,8 +65,6 @@ static bool atkbd_terminal; module_param_named(terminal, atkbd_terminal, bool, 0); MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2"); -#define MAX_FUNCTION_ROW_KEYS 24 - #define SCANCODE(keymap) ((keymap >> 16) & 0xFFFF) #define KEYCODE(keymap) (keymap & 0xFFFF) @@ -237,8 +236,7 @@ struct atkbd { /* Serializes reconnect(), attr->set() and event work */ struct mutex mutex; - u32 function_row_physmap[MAX_FUNCTION_ROW_KEYS]; - int num_function_row_keys; + struct vivaldi_data vdata; }; /* @@ -308,17 +306,7 @@ 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; - - 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(&atkbd->vdata, buf); } static umode_t atkbd_attr_is_visible(struct kobject *kobj, @@ -329,7 +317,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; @@ -1206,10 +1194,11 @@ static void atkbd_parse_fwnode_data(struct serio *serio) /* Parse "function-row-physmap" property */ n = device_property_count_u32(dev, "function-row-physmap"); - if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS && + if (n > 0 && n <= VIVALDI_MAX_FUNCTION_ROW_KEYS && !device_property_read_u32_array(dev, "function-row-physmap", - atkbd->function_row_physmap, n)) { - atkbd->num_function_row_keys = n; + atkbd->vdata.function_row_physmap, + n)) { + atkbd->vdata.num_function_row_keys = n; 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..6534dfca60b4 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 @@ -27,8 +28,6 @@ #include -#define MAX_NUM_TOP_ROW_KEYS 15 - /** * struct cros_ec_keyb - Structure representing EC keyboard device * @@ -44,9 +43,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 +61,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; }; /** @@ -537,9 +533,9 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) int err; struct property *prop; const __be32 *p; - u16 *physmap; + u32 *physmap; u32 key_pos; - int row, col; + unsigned int row, col, scancode, n_physmap; err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols); if (err) @@ -591,20 +587,21 @@ 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; + n_physmap = 0; 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 (n_physmap == VIVALDI_MAX_FUNCTION_ROW_KEYS) { dev_warn(dev, "Only support up to %d top row keys\n", - MAX_NUM_TOP_ROW_KEYS); + VIVALDI_MAX_FUNCTION_ROW_KEYS); break; } row = KEY_ROW(key_pos); col = KEY_COL(key_pos); - *physmap = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); - physmap++; - ckdev->num_function_row_keys++; + scancode = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); + physmap[n_physmap++] = scancode; } + ckdev->vdata.num_function_row_keys = n_physmap; err = input_register_device(ckdev->idev); if (err) { @@ -619,18 +616,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 +637,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-fmap.c b/drivers/input/vivaldi-fmap.c new file mode 100644 index 000000000000..6dae83d96806 --- /dev/null +++ b/drivers/input/vivaldi-fmap.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 row map + * @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 u32 *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-fmap.h b/include/linux/input/vivaldi-fmap.h new file mode 100644 index 000000000000..7e4b7023bf04 --- /dev/null +++ b/include/linux/input/vivaldi-fmap.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _VIVALDI_FMAP_H +#define _VIVALDI_FMAP_H + +#include + +#define VIVALDI_MAX_FUNCTION_ROW_KEYS 24 + +/** + * struct vivaldi_data - Function row map data for ChromeOS Vivaldi keyboards + * @function_row_physmap: An array of scancodes or their equivalent (HID usage + * codes, encoded rows/columns, etc) 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 { + u32 function_row_physmap[VIVALDI_MAX_FUNCTION_ROW_KEYS]; + unsigned int num_function_row_keys; +}; + +ssize_t vivaldi_function_row_physmap_show(const struct vivaldi_data *data, + char *buf); + +#endif /* _VIVALDI_FMAP_H */ From patchwork Mon Feb 28 07:54:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 547414 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 227CEC433FE for ; Mon, 28 Feb 2022 07:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233753AbiB1Hzf (ORCPT ); Mon, 28 Feb 2022 02:55:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbiB1Hzf (ORCPT ); Mon, 28 Feb 2022 02:55:35 -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 43B5F4614D for ; Sun, 27 Feb 2022 23:54:56 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 12so10750664pgd.0 for ; Sun, 27 Feb 2022 23:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JbfF5igIjOuMscLIDjexzjqyjFNX5yyYO53wKrTiDpw=; b=foF1n0i22SyPBrM+WEJPyI3O9gsma64F//7Rflu3u0KR4OfDUw2C8Jxp94AkO0roIG PSQkqNcthx4EOwziolg+HLNTc9fb95VB/5Mi4f5Vt3LvIN5DOs8j3OUK9+PMiRFVDKAO mFffhQC5zOeUrRY5ekh4fd1pwP0/ESGrT3El776YvK2nsNjX84dSf7tUFy9AUMUuHOqf 4470pv93bXNQZoBZ3WJb1Bb+Z4qRIQr8OK7Nl+Alr4dm/P9VWzTmgSFcnr5rKGt8QHSL yH7PXkqjMzZSRx5CKyD/vHNgqNp2BWINm2/ckUQh84TPjkf9FtAwqKKJ4Z2RI5urRac0 BTvQ== 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=JbfF5igIjOuMscLIDjexzjqyjFNX5yyYO53wKrTiDpw=; b=XD2pVvJU09JPsOnYhU/CGojqJ25JwXTcHSqtYoeGs+MRiAMixgU63Vgv5BTfAD06ko uuLkVEM9MjdFnL+GHvgDhfw+ZJjPdRz9hINr7canv8BBim4oBqcoM1ggPZAipnPPRFSE Jtk8pwqGgo93lBM/np/nRtKt1T6Tnvt5FBp0rxTQCYe6qYmnJrawLopfcwAoGudtyZVP auWplQMXfqcy7ODCep5vVGFXbHupkx8slDPOtppxdanRuzCLNNUNNPsIwFlhLLndkrYy QxI8G2b2/TKnMXeFsjcHnk5gh4Ng/0HCtOlplTSAs6B7NFYlIdu1+bE4J+Sn6oAiFXJf DPBQ== X-Gm-Message-State: AOAM532DcFFgbGiXP1AgPU/gf9q1TlnkjsADRlLfJIdddRz3RMV8FY/S cL6T1qTBJaAQUo7t88/UalUpxo7URSs= X-Google-Smtp-Source: ABdhPJxzUmi9BnxbQultZy2PIwMqduV1yk67gxUvCbqdby/QsNlEOneSxxhpaQQ2ZECoCVNavFQjzg== X-Received: by 2002:a05:6a00:21ca:b0:4c9:ff9:47e3 with SMTP id t10-20020a056a0021ca00b004c90ff947e3mr20384981pfj.10.1646034895001; Sun, 27 Feb 2022 23:54:55 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:43a2:93b6:ebd7:94fd]) by smtp.gmail.com with ESMTPSA id d13-20020a17090ac24d00b001bcd7c2b2c3sm10718517pjx.16.2022.02.27.23.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 23:54:53 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stephen Boyd , benjamin.tissoires@redhat.com, Jiri Kosina , Sean O'Brien , "Douglas Anderson linux-kernel @ vger . kernel . org" Subject: [PATCH v5 3/5] HID: google: extract Vivaldi hid feature mapping for use in hid-hammer Date: Sun, 27 Feb 2022 23:54:44 -0800 Message-Id: <20220228075446.466016-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com> References: <20220228075446.466016-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Stephen Boyd 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. To allow more code sharing we mandate that vivaldi data must be placed at the very beginning of the driver data attached to the HID device instance. Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20220216195901.1326924-3-swboyd@chromium.org Signed-off-by: Dmitry Torokhov --- drivers/hid/Kconfig | 8 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-vivaldi-common.c | 140 +++++++++++++++++++++++++++++++ drivers/hid/hid-vivaldi-common.h | 16 ++++ drivers/hid/hid-vivaldi.c | 106 +---------------------- 5 files changed, 167 insertions(+), 104 deletions(-) create mode 100644 drivers/hid/hid-vivaldi-common.c create mode 100644 drivers/hid/hid-vivaldi-common.h diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 5569a2029dab..f5245c5fe1af 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -403,6 +403,13 @@ 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" depends on USB_HID && LEDS_CLASS && CROS_EC @@ -411,6 +418,7 @@ config HID_GOOGLE_HAMMER 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..c88b26f4c78b --- /dev/null +++ b/drivers/hid/hid-vivaldi-common.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helpers for ChromeOS HID Vivaldi keyboards + * + * Copyright (C) 2022 Google, Inc + */ + +#include +#include +#include +#include +#include +#include + +#include "hid-vivaldi-common.h" + +#define MIN_FN_ROW_KEY 1 +#define MAX_FN_ROW_KEY VIVALDI_MAX_FUNCTION_ROW_KEYS +#define HID_VD_FN_ROW_PHYSMAP 0x00000001 +#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP) + +/** + * vivaldi_feature_mapping - Fill out vivaldi keymap data exposed via HID + * @hdev: HID device to parse + * @field: HID field to parse + * @usage: HID usage to parse + * + * This function assumes that driver data attached to @hdev contains an + * instance of &struct vivaldi_data in the very beginning. + */ +void vivaldi_feature_mapping(struct hid_device *hdev, + struct hid_field *field, struct hid_usage *usage) +{ + struct vivaldi_data *data = hid_get_drvdata(hdev); + struct hid_report *report = field->report; + u8 *report_data, *buf; + u32 report_len; + unsigned int fn_key; + int ret; + + 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 < MIN_FN_ROW_KEY || fn_key > 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 - MIN_FN_ROW_KEY] = + field->value[usage->usage_index]; + +out: + kfree(buf); +} +EXPORT_SYMBOL_GPL(vivaldi_feature_mapping); + +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 *data = hid_get_drvdata(hdev); + + return vivaldi_function_row_physmap_show(data, buf); +} + +static DEVICE_ATTR_RO(function_row_physmap); +static struct attribute *vivaldi_sysfs_attrs[] = { + &dev_attr_function_row_physmap.attr, + NULL +}; + +static const struct attribute_group vivaldi_attribute_group = { + .attrs = vivaldi_sysfs_attrs, +}; + +/** + * vivaldi_feature_mapping - Complete initialization of device using vivaldi map + * @hdev: HID device to witch vivaldi attributes should be attached + * @hidinput: HID input device (unused). + */ +int vivaldi_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + struct vivaldi_data *data = hid_get_drvdata(hdev); + + if (!data->num_function_row_keys) + return 0; + + return devm_device_add_group(&hdev->dev, &vivaldi_attribute_group); +} +EXPORT_SYMBOL_GPL(vivaldi_input_configured); + +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-vivaldi-common.h b/drivers/hid/hid-vivaldi-common.h new file mode 100644 index 000000000000..37bc9b3e4f27 --- /dev/null +++ b/drivers/hid/hid-vivaldi-common.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef _HID_VIVALDI_COMMON_H +#define _HID_VIVALDI_COMMON_H + +struct hid_device; +struct hid_field; +struct hid_input; +struct hid_usage; + +void vivaldi_feature_mapping(struct hid_device *hdev, + struct hid_field *field, struct hid_usage *usage); + +int vivaldi_input_configured(struct hid_device *hdev, + struct hid_input *hidinput); + +#endif /* _HID_VIVALDI_COMMON_H */ diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c index ca8cb40928e6..3a979123e7d3 100644 --- a/drivers/hid/hid-vivaldi.c +++ b/drivers/hid/hid-vivaldi.c @@ -11,32 +11,8 @@ #include #include #include -#include -#define MIN_FN_ROW_KEY 1 -#define MAX_FN_ROW_KEY VIVALDI_MAX_FUNCTION_ROW_KEYS -#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) -{ - struct hid_device *hdev = to_hid_device(dev); - struct vivaldi_data *drvdata = hid_get_drvdata(hdev); - - return vivaldi_function_row_physmap_show(drvdata, buf); -} - -static DEVICE_ATTR_RO(function_row_physmap); -static struct attribute *sysfs_attrs[] = { - &dev_attr_function_row_physmap.attr, - NULL -}; - -static const struct attribute_group input_attribute_group = { - .attrs = sysfs_attrs -}; +#include "hid-vivaldi-common.h" static int vivaldi_probe(struct hid_device *hdev, const struct hid_device_id *id) @@ -57,86 +33,8 @@ static int vivaldi_probe(struct hid_device *hdev, return hid_hw_start(hdev, HID_CONNECT_DEFAULT); } -static void vivaldi_feature_mapping(struct hid_device *hdev, - struct hid_field *field, - 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 < MIN_FN_ROW_KEY || fn_key > 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 - MIN_FN_ROW_KEY] = - field->value[usage->usage_index]; - -out: - kfree(buf); -} - -static int vivaldi_input_configured(struct hid_device *hdev, - struct hid_input *hidinput) -{ - return devm_device_add_group(&hdev->dev, &input_attribute_group); -} - static const struct hid_device_id vivaldi_table[] = { - { HID_DEVICE(HID_BUS_ANY, HID_GROUP_VIVALDI, HID_ANY_ID, - HID_ANY_ID) }, + { HID_DEVICE(HID_BUS_ANY, HID_GROUP_VIVALDI, HID_ANY_ID, HID_ANY_ID) }, { } }; From patchwork Mon Feb 28 07:54:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 546867 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 8C5CFC433EF for ; Mon, 28 Feb 2022 07:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233752AbiB1Hzg (ORCPT ); Mon, 28 Feb 2022 02:55:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233751AbiB1Hzf (ORCPT ); Mon, 28 Feb 2022 02:55:35 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8500768FB2 for ; Sun, 27 Feb 2022 23:54:57 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id g1so10389875pfv.1 for ; Sun, 27 Feb 2022 23:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=afmbhtxJXuu2P8Qqschaw9Jggn6kd8iv6fg4aLXPxdU=; b=m1YIGzof/6U/6x9Z4Bajw8GzlU4QFrtqCCC7wey5c0y83GyHwL8wCFXYIyJBpEgDkh SwyVaTMnXEpiwHGfi/mqB6R30C1Vu8FZVrUNpF7z586vDA0Ey0RI5KJDBrBIQte15i78 8GNYaphpemIjateTFynV72ahtDrnUaJKqZ2Sha629jm/LX7VCirGeqcr23Bqq1wMoeFk 3IoMgZclSpJDrV9F5/Z6MwSdijcZL3NQ4f41ksW1IJikMV4fpWYvww7rR3kPszNL0CK0 nP8CabiK5GIae26PnwPmFkyLteyEb59grpEvgFhBAu7xYEE/QEoy51fe0u1o0r9emu5F UYcg== 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=afmbhtxJXuu2P8Qqschaw9Jggn6kd8iv6fg4aLXPxdU=; b=nfzIIsmE/T/RrsS0RoKdpoBRhg5BnTbYkG+Fr/bjHMqXA+Eh3aQ/qPKC2Xu65/LTqI Jn0hRErPenMhg8vwjKbsL9uzD874MNRq7FSOr5Y5t9rNAisey186cDSVql8ka1Sg4AOl Yl8sH+RhuCBbys1QAIjzbDGoxk8G3kG0Iw8EoD1/nzYhnNSBrMkBiMp4rX9Pxq1Gakj4 1JKw1o6MoXEIFm3HHwxkdBKIQjBMmr35A7UQDn0z5Fzr733XDR/qNixrdxJlOnMlx/KT ILBa3+Ecu5wSsEQRjxExrGE8m/SHZm8cSkdjLlS3CW+zdIaTWqnqs903Z1jTfKLVjRp6 O/rg== X-Gm-Message-State: AOAM531rcCwW7piT5PyRpfuzbl2MEXzTEncMCy1AZNe3QCHwrLD+j+yL J4zWXByosm2YLEJkkQdM1sH+is0+8bo= X-Google-Smtp-Source: ABdhPJyZZKyr1JkI/yjvJrg1f/D1kk193Y+GAZ/cSlzy6BuAZkmIUxUrPlQscQ/VEf5yktmXdjgDiQ== X-Received: by 2002:a05:6a00:8cc:b0:4cb:b981:2676 with SMTP id s12-20020a056a0008cc00b004cbb9812676mr20270192pfu.5.1646034896529; Sun, 27 Feb 2022 23:54:56 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:43a2:93b6:ebd7:94fd]) by smtp.gmail.com with ESMTPSA id d13-20020a17090ac24d00b001bcd7c2b2c3sm10718517pjx.16.2022.02.27.23.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 23:54:55 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Stephen Boyd , benjamin.tissoires@redhat.com, Jiri Kosina , Sean O'Brien , "Douglas Anderson linux-kernel @ vger . kernel . org" Subject: [PATCH v5 4/5] HID: google: Add support for vivaldi to hid-hammer Date: Sun, 27 Feb 2022 23:54:45 -0800 Message-Id: <20220228075446.466016-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com> References: <20220228075446.466016-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Stephen Boyd 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. Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20220216195901.1326924-4-swboyd@chromium.org Signed-off-by: Dmitry Torokhov --- drivers/hid/Kconfig | 2 ++ drivers/hid/hid-google-hammer.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index f5245c5fe1af..4bea966e617b 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -412,6 +412,8 @@ 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 e7da4e74b4bf..5d774c9c596c 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 @@ -25,6 +26,7 @@ #include #include "hid-ids.h" +#include "hid-vivaldi-common.h" /* * C(hrome)B(ase)A(ttached)S(witch) - switch exported by Chrome EC and reporting @@ -501,8 +503,15 @@ static void hammer_stop(void *hdev) static int hammer_probe(struct hid_device *hdev, const struct hid_device_id *id) { + struct vivaldi_data *vdata; int error; + vdata = devm_kzalloc(&hdev->dev, sizeof(*vdata), GFP_KERNEL); + if (!vdata) + return -ENOMEM; + + hid_set_drvdata(hdev, vdata); + error = hid_parse(hdev); if (error) return error; @@ -598,6 +607,8 @@ static struct hid_driver hammer_driver = { .id_table = hammer_devices, .probe = hammer_probe, .remove = hammer_remove, + .feature_mapping = vivaldi_feature_mapping, + .input_configured = vivaldi_input_configured, .input_mapping = hammer_input_mapping, .event = hammer_event, }; From patchwork Mon Feb 28 07:54:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 547413 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 530C0C433EF for ; Mon, 28 Feb 2022 07:55:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233751AbiB1Hzj (ORCPT ); Mon, 28 Feb 2022 02:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233756AbiB1Hzj (ORCPT ); Mon, 28 Feb 2022 02:55:39 -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 726D4606E5 for ; Sun, 27 Feb 2022 23:54:59 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id v4so10398614pjh.2 for ; Sun, 27 Feb 2022 23:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H1m4Zi6Ns02mUbm+534InG8jnE+hMLBdIMegNJHG0gs=; b=n66Nb6ih4kVIXFgoUoaIsoH9PyiNVF+SqCUNHizLTZgGOvlvgnsd3yniEzh/ylGOx5 4YhqLtQImKkRbTSlIppbjCH0T38UUm7DHVezKFV9GH7ZrTO9UHa/ZuNqsf5ynCY5NOWV mNPKN5bkUk94Z4ueaxuKs6NFSQQZV6ozZ4fD2facfUbLhD0l3D7Y3nbSSlw7VZ19KVTr v2vNupTY6YOmOVM67w6HLrpJ/Xr5Ue3eI07/ywnmg9jSnu4kaEz33q3wvOExjVeRgJfB RnEBcCBXHwTSHJyxPhLYM7E5e14nBwmdBf2XEAkCKQVll4/zO57Kn7fekaw7JZE4GySx ioGA== 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=H1m4Zi6Ns02mUbm+534InG8jnE+hMLBdIMegNJHG0gs=; b=3KjsaoLEqh4KPjn7mOF+tm0fy8kQC83l3pLt9GhCqGg1w0sJJjoWPbSU9izz6+rFfe cbqAnzT4PnTNa+MDMqJVdllYXuSY1U/pesOH/KIk1MV3nMBXWUzsuHK90e76hYEqwkpZ C3CqOUUZeR02p6tQaETFiVxxGKzQpM2Swyjk1cye7s20goByXyCV4XWKrrLp31r6Ipvm MasE1UYLH8vw9+oc4JtzpPwNNmX798YgEsCiJMf252xT+xZ+u/GbDtDBSQjWIyenYbT7 TyZ/kB0YzypC+Y5FTWJfHCHaheOZIJBVWjl2FeH8IkCrQwk4S0R9+7YRhvNE7FhRZlzn nX8A== X-Gm-Message-State: AOAM530YlE9Bmushbk9GGS2wzVkQNHtqD1S03kwXvnQRNFZ+Rwzkz+Rb LaRTOMlp0Um/ZooHaZCxpEVmh1JVsj8= X-Google-Smtp-Source: ABdhPJxHOqbWdqbdXGss84caU4vpc5Sd3PD7MlaRsV4G2kiyyKKli9a/aH1DIiXY3N7RzbRgsQU2kw== X-Received: by 2002:a17:90a:8d85:b0:1b8:a215:e3e4 with SMTP id d5-20020a17090a8d8500b001b8a215e3e4mr15111091pjo.175.1646034898648; Sun, 27 Feb 2022 23:54:58 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:43a2:93b6:ebd7:94fd]) by smtp.gmail.com with ESMTPSA id d13-20020a17090ac24d00b001bcd7c2b2c3sm10718517pjx.16.2022.02.27.23.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 23:54:57 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Zhengqiao Xia , Stephen Boyd , benjamin.tissoires@redhat.com, Jiri Kosina , Sean O'Brien , "Douglas Anderson linux-kernel @ vger . kernel . org" , Jiri Kosina Subject: [PATCH v5 5/5] HID: google: modify HID device groups of eel Date: Sun, 27 Feb 2022 23:54:46 -0800 Message-Id: <20220228075446.466016-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220228075446.466016-1-dmitry.torokhov@gmail.com> References: <20220228075446.466016-1-dmitry.torokhov@gmail.com> 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. Tested-by: "Sean O'Brien" Acked-by: Jiri Kosina Signed-off-by: Zhengqiao Xia [swboyd@chromium.org: Expand on commit text] Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20220216195901.1326924-5-swboyd@chromium.org Patchwork-Id: 12748989 Signed-off-by: Dmitry Torokhov --- 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 5d774c9c596c..7fd342081183 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -582,7 +582,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) },