Commit 45ceaf14 authored by Stephen Boyd's avatar Stephen Boyd Committed by Dmitry Torokhov
Browse files

Input: extract ChromeOS vivaldi physmap show function



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: default avatarStephen Boyd <swboyd@chromium.org>
Tested-by: Stephen Boyd <swboyd@chromium.org> # coachz, wormdingler
Link: https://lore.kernel.org/r/20220228075446.466016-3-dmitry.torokhov@gmail.com


Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent d950db3f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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.
+7 −20
Original line number Diff line number Diff line
@@ -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 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)
+7 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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
Loading