Skip to contentSkip to conversation

Input/HID: Consolidate ChromeOS Vivaldi keyboard logic

PATCH In review Dmitry Torokhov 2 participants 10 messages Feb 28, 2022 – Mar 2, 2022

Subsystems (3)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

v5 cover Input/HID: Consolidate ChromeOS Vivaldi keyboard logic

This is a follow-on to this thread[1] where we discussed the need to support the vivaldi keyboard function row keys in the google hammer driver. I've extracted the common code into a new vivaldi-fmap.c file that can be used by the various keyboard drivers used on ChromeOS devices to expose the function_row_physmap sysfs attribute. Then we make another file to keep the HID parsing logic common for the vivaldi and hammer keyboards. Finally, we add support for the function row physmap attribute to the hammer driver.

NOTE: I dropped Tested-by and Acked-by as patches have been reworked, please give them another spin.

Changed from v4 (dtor):
(https://lore.kernel.org/r/[email protected]):
* The series is on top of [PATCH] HID: vivaldi: fix sysfs attributes leak (https://lore.kernel.org/r/[email protected])
* Added patch to used devm for keyboard backlight LED in hammer driver
* Avoid putting HID-specific stuff in input header, instead introduce new private hid-vivaldi-common.h
* More code sharing between hid-google-hammer.c and hid-vivaldi.c by mandating that vivaldi data instance should be the very first or the only driver-private data.

Changes from v3
(https://lore.kernel.org/r/[email protected]):
* Changed vivaldi-keymap to vivaldi-fmap

Changes from v2
(https://lore.kernel.org/r/[email protected]):
* Drop first patch to change to u16
* Change array type to u32 in vivaldi_data

Changes from v1
(https://lore.kernel.org/r/[email protected]):
* Yet another new file for HID part to fix compilation problems

Dmitry Torokhov (1):
HID: google: switch to devm when registering keyboard backlight LED

Stephen Boyd (3):
Input: extract ChromeOS vivaldi physmap show function
HID: google: extract Vivaldi hid feature mapping for use in hid-hammer
HID: google: Add support for vivaldi to hid-hammer

Zhengqiao Xia (1):
HID: google: modify HID device groups of eel

 drivers/hid/Kconfig                   |  11 ++
 drivers/hid/Makefile                  |   1 +
 drivers/hid/hid-google-hammer.c       |  51 +++++-----
 drivers/hid/hid-vivaldi-common.c      | 140 ++++++++++++++++++++++++++
 drivers/hid/hid-vivaldi-common.h      |  16 +++
 drivers/hid/hid-vivaldi.c             | 121 +---------------------
 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 +++++
 13 files changed, 296 insertions(+), 190 deletions(-)
 create mode 100644 drivers/hid/hid-vivaldi-common.c
 create mode 100644 drivers/hid/hid-vivaldi-common.h
 create mode 100644 drivers/input/vivaldi-fmap.c
 create mode 100644 include/linux/input/vivaldi-fmap.h
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
author maintainer
#1 lore raw

PATCH v5 1/5 HID: google: switch to devm when registering keyboard backlight LED

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.

---
 drivers/hid/hid-google-hammer.c | 38 +++++++++++----------------------
 1 file changed, 13 insertions(+), 25 deletions(-)
drivers/hid/hid-google-hammer.c +13 -25
index 0403beb3104b..e7da4e74b4bf 100644
@@ -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[] = {
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
author maintainer
#2 lore raw

PATCH v5 2/5 Input: extract ChromeOS vivaldi physmap show function

In reply to Dmitry Torokhov

From: Stephen Boyd <[email protected]>

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%

---
 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
drivers/hid/Kconfig +1 -0
index f5544157576c..5569a2029dab 100644
@@ -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.
drivers/hid/hid-vivaldi.c +7 -20
index 42ceb2058a09..ca8cb40928e6 100644
@@ -8,37 +8,24 @@
 
 #include <linux/device.h>
 #include <linux/hid.h>
+#include <linux/input/vivaldi-fmap.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/sysfs.h>
 
-#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)
drivers/input/Kconfig +7 -0
index 5baebf62df33..e2752f7364bc 100644
@@ -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
drivers/input/Makefile +1 -0
index 037cc595106c..2266c7d010ef 100644
@@ -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
drivers/input/keyboard/Kconfig +2 -0
index 9417ee0b1eff..04954ecb1437 100644
@@ -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
drivers/input/keyboard/atkbd.c +8 -19
index fbdef95291e9..d4131236d18c 100644
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/input.h>
+#include <linux/input/vivaldi-fmap.h>
 #include <linux/serio.h>
 #include <linux/workqueue.h>
 #include <linux/libps2.h>
@@ -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);
 	}
 }
drivers/input/keyboard/cros_ec_keyb.c +16 -27

101 lines not on this page · raw message

drivers/input/vivaldi-fmap.c new file +39 -0
new file mode 100644
index 000000000000..6dae83d96806
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Helpers for ChromeOS Vivaldi keyboard function row mapping
+ *
+ * Copyright (C) 2022 Google, Inc
+ */
+
+#include <linux/export.h>
+#include <linux/input/vivaldi-fmap.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+
+/**
+ * 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");
include/linux/input/vivaldi-fmap.h new file +27 -0
new file mode 100644
index 000000000000..7e4b7023bf04
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _VIVALDI_FMAP_H
+#define _VIVALDI_FMAP_H
+
+#include <linux/types.h>
+
+#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 */
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
author maintainer
#3 lore raw

PATCH v5 3/5 HID: google: extract Vivaldi hid feature mapping for use in hid-hammer

In reply to Dmitry Torokhov

From: Stephen Boyd <[email protected]>

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.

---
 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
drivers/hid/Kconfig +8 -0
index 5569a2029dab..f5245c5fe1af 100644
@@ -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
drivers/hid/Makefile +1 -0
index 6d3e630e81af..469a6159ebae 100644
@@ -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
drivers/hid/hid-vivaldi-common.c new file +140 -0

140 lines not on this page · raw message

drivers/hid/hid-vivaldi-common.h new file +16 -0
new file mode 100644
index 000000000000..37bc9b3e4f27
@@ -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 */
drivers/hid/hid-vivaldi.c +2 -104

120 lines not on this page · raw message

Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
#4 lore raw

Re: [PATCH v5 3/5] HID: google: extract Vivaldi hid feature mapping for use in hid-hammer

Quoting Dmitry Torokhov (2022-02-27 23:54:44)

Quoted 7 lines
drivers/hid/hid-vivaldi-common.c new file +1 -0
new file mode 100644
index 000000000000..c88b26f4c78b
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: GPL-2.0

[...]

Quoted 7 lines

+/**
+ * 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

Maybe add

Note: This function assumes ...

Quoted 1 line

+ * instance of &struct vivaldi_data in the very beginning.

It makes me nervous that this can't be checked statically but OK.

Quoted 10 lines

+ */

drivers/hid/hid-vivaldi-common.c new file +9 -0
+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;

[...]

drivers/hid/hid-vivaldi-common.c line 124

Quoted 13 lines
drivers/hid/hid-vivaldi-common.c new file +13 -0
+
+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

vivaldi_input_configured

Quoted 1 line

+ * @hdev: HID device to witch vivaldi attributes should be attached

s/witch/which/

Quoted 1 line

+ * @hidinput: HID input device (unused).

Drop the period? It's not on the hdev argument description above.

Quoted 3 lines

+ */

drivers/hid/hid-vivaldi-common.c new file +2 -0
+int vivaldi_input_configured(struct hid_device *hdev,
+                            struct hid_input *hidinput)
author maintainer
#5 lore raw

PATCH v5 4/5 HID: google: Add support for vivaldi to hid-hammer

In reply to Dmitry Torokhov

From: Stephen Boyd <[email protected]>

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.

---
 drivers/hid/Kconfig             |  2 ++
 drivers/hid/hid-google-hammer.c | 11 +++++++++++
 2 files changed, 13 insertions(+)
drivers/hid/Kconfig +2 -0
index f5245c5fe1af..4bea966e617b 100644
@@ -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.
drivers/hid/hid-google-hammer.c +11 -0
index e7da4e74b4bf..5d774c9c596c 100644
@@ -15,6 +15,7 @@
 
 #include <linux/acpi.h>
 #include <linux/hid.h>
+#include <linux/input/vivaldi-fmap.h>
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -25,6 +26,7 @@
 #include <asm/unaligned.h>
 
 #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,
 };
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
author maintainer
#6 lore raw

PATCH v5 5/5 HID: google: modify HID device groups of eel

In reply to Dmitry Torokhov

From: Zhengqiao Xia <[email protected]>

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.

Patchwork-Id: 12748989

---
 drivers/hid/hid-google-hammer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-google-hammer.c +1 -1
index 5d774c9c596c..7fd342081183 100644
@@ -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) },
Signature · 1 line
2.35.1.574.g5d30c73bfb-goog
#7 lore raw

Re: [PATCH v5 5/5] HID: google: modify HID device groups of eel

Quoting Dmitry Torokhov (2022-02-27 23:54:46)

Quoted 8 lines

From: Zhengqiao Xia <[email protected]>

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.

Quoted 7 lines

Patchwork-Id: 12748989

Should this patchwork id be removed?

author maintainer
#8 lore raw

Re: [PATCH v5 5/5] HID: google: modify HID device groups of eel

Quoted 17 lines · Stephen Boyd

Quoting Dmitry Torokhov (2022-02-27 23:54:46)

Quoted 8 lines

From: Zhengqiao Xia <[email protected]>

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.

Quoted 7 lines

Patchwork-Id: 12748989

Quoted 1 line

Should this patchwork id be removed?

Yeah, this is leftover from my scripts, they will drop it when applying.

Thanks.

Signature · 1 line
Dmitry
Tested-by on the v5 series
#9 lore raw
In reply to Dmitry Torokhov

Quoting Dmitry Torokhov (2022-02-27 23:54:41)

Quoted 11 lines

This is a follow-on to this thread[1] where we discussed the need to support the vivaldi keyboard function row keys in the google hammer driver. I've extracted the common code into a new vivaldi-fmap.c file that can be used by the various keyboard drivers used on ChromeOS devices to expose the function_row_physmap sysfs attribute. Then we make another file to keep the HID parsing logic common for the vivaldi and hammer keyboards. Finally, we add support for the function row physmap attribute to the hammer driver.

NOTE: I dropped Tested-by and Acked-by as patches have been reworked, please give them another spin.

I tested it on a device with hid-vivaldi (coachz) and a device with hid-google-hammer (wormdingler) and it works on both. Feel free to add

to the patches.

Quoted 12 lines

Changed from v4 (dtor):
(https://lore.kernel.org/r/[email protected]):
* The series is on top of [PATCH] HID: vivaldi: fix sysfs attributes leak (https://lore.kernel.org/r/[email protected])
* Added patch to used devm for keyboard backlight LED in hammer driver
* Avoid putting HID-specific stuff in input header, instead introduce new private hid-vivaldi-common.h
* More code sharing between hid-google-hammer.c and hid-vivaldi.c by mandating that vivaldi data instance should be the very first or the only driver-private data.