From: Hans de Goede <hdegoede@redhat.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>, Peter Hoeg <peter@hoeg.com>,
linux-input@vger.kernel.org
Subject: [PATCH 3/6] HID: lg-g15: Add a lg_g15_init_input_dev() helper function
Date: Fri, 16 Apr 2021 15:13:20 +0200 [thread overview]
Message-ID: <20210416131323.233184-4-hdegoede@redhat.com> (raw)
In-Reply-To: <20210416131323.233184-1-hdegoede@redhat.com>
Factor the input-device setup + KEY_KBD_LCD_MENU capability setting out
of lg_g15_probe() into a new lg_g15_init_input_dev() helper function.
This is a preparation patch for adding support for the LCD menu
keys + LCD brightness control on the Logitech Z-10 speakers (with LCD)
which use the same protocol as the G15 keyboards.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/hid/hid-lg-g15.c | 42 ++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/drivers/hid/hid-lg-g15.c b/drivers/hid/hid-lg-g15.c
index 75a27b48d9c9..eff8c51a8dce 100644
--- a/drivers/hid/hid-lg-g15.c
+++ b/drivers/hid/hid-lg-g15.c
@@ -709,6 +709,28 @@ static int lg_g15_register_led(struct lg_g15_data *g15, int i)
return devm_led_classdev_register(&g15->hdev->dev, &g15->leds[i].cdev);
}
+/* Common input device init code shared between keyboards and Z-10 speaker handling */
+static void lg_g15_init_input_dev(struct hid_device *hdev, struct input_dev *input,
+ const char *name)
+{
+ int i;
+
+ input->name = name;
+ input->phys = hdev->phys;
+ input->uniq = hdev->uniq;
+ input->id.bustype = hdev->bus;
+ input->id.vendor = hdev->vendor;
+ input->id.product = hdev->product;
+ input->id.version = hdev->version;
+ input->dev.parent = &hdev->dev;
+ input->open = lg_g15_input_open;
+ input->close = lg_g15_input_close;
+
+ /* Keys below the LCD, intended for controlling a menu on the LCD */
+ for (i = 0; i < 5; i++)
+ input_set_capability(input, EV_KEY, KEY_KBD_LCD_MENU1 + i);
+}
+
static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
u8 gkeys_settings_output_report = 0;
@@ -751,6 +773,8 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
g15->hdev = hdev;
g15->model = id->driver_data;
+ g15->input = input;
+ input_set_drvdata(input, hdev);
hid_set_drvdata(hdev, (void *)g15);
switch (g15->model) {
@@ -822,16 +846,7 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
goto error_hw_stop;
/* Setup and register input device */
- input->name = "Logitech Gaming Keyboard Gaming Keys";
- input->phys = hdev->phys;
- input->uniq = hdev->uniq;
- input->id.bustype = hdev->bus;
- input->id.vendor = hdev->vendor;
- input->id.product = hdev->product;
- input->id.version = hdev->version;
- input->dev.parent = &hdev->dev;
- input->open = lg_g15_input_open;
- input->close = lg_g15_input_close;
+ lg_g15_init_input_dev(hdev, input, "Logitech Gaming Keyboard Gaming Keys");
/* G-keys */
for (i = 0; i < gkeys; i++)
@@ -842,10 +857,6 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
input_set_capability(input, EV_KEY, KEY_MACRO_PRESET1 + i);
input_set_capability(input, EV_KEY, KEY_MACRO_RECORD_START);
- /* Keys below the LCD, intended for controlling a menu on the LCD */
- for (i = 0; i < 5; i++)
- input_set_capability(input, EV_KEY, KEY_KBD_LCD_MENU1 + i);
-
/*
* On the G510 only report headphone and mic mute keys when *not* using
* the builtin USB audio device. When the builtin audio is used these
@@ -857,9 +868,6 @@ static int lg_g15_probe(struct hid_device *hdev, const struct hid_device_id *id)
input_set_capability(input, EV_KEY, KEY_F20);
}
- g15->input = input;
- input_set_drvdata(input, hdev);
-
ret = input_register_device(input);
if (ret)
goto error_hw_stop;
--
2.31.1
next prev parent reply other threads:[~2021-04-16 13:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 13:13 [PATCH 0/6] HID: lg-g15: Add support for the Logitech Z-10 speakers Hans de Goede
2021-04-16 13:13 ` [PATCH 1/6] HID: lg-g15: Remove unused size argument from lg_*_event() functions Hans de Goede
2021-04-16 13:13 ` [PATCH 2/6] HID: lg-g15: Add a lg_g15_handle_lcd_menu_keys() helper function Hans de Goede
2021-04-16 13:13 ` Hans de Goede [this message]
2021-04-16 13:13 ` [PATCH 4/6] HID: lg-g15: Make the LED-name used by lg_g15_register_led() a parameter Hans de Goede
2021-04-16 13:13 ` [PATCH 5/6] HID: lg-g15: Add support for the Logitech Z-10 speakers Hans de Goede
2021-04-16 13:13 ` [PATCH 6/6] HID: lg-g15 + ite: Add MODULE_AUTHOR Hans de Goede
2021-05-05 12:40 ` [PATCH 0/6] HID: lg-g15: Add support for the Logitech Z-10 speakers Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210416131323.233184-4-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=peter@hoeg.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).