aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel M. Lambea <dmlambea@gmail.com>2018-07-27 16:19:11 -0400
committerJiri Kosina <jkosina@suse.cz>2018-09-05 04:25:37 -0400
commit6b003a8ddd6f413a7e17470515accdd4cd80e871 (patch)
treed3a4bdbdd181500e128fe8b29c4d8a3c8fa383b0
parent7a324b3f0535ceb0f6676fa20ca2a7b6213008cb (diff)
HID: cougar: Make parameter 'g6_is_space' dinamically settable
Parameter g6_is_space instructs the driver to map G6 keypresses to KEY_SPACE (true) or to KEY_F18 (false). Make the parameter configurable via module_param_cb to allow users to change its value without reloading the module. Signed-off-by: Daniel M. Lambea <dmlambea@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-cougar.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/drivers/hid/hid-cougar.c b/drivers/hid/hid-cougar.c
index ad2e87de7dc5..910ef4312157 100644
--- a/drivers/hid/hid-cougar.c
+++ b/drivers/hid/hid-cougar.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/hid.h> 8#include <linux/hid.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/printk.h>
10 11
11#include "hid-ids.h" 12#include "hid-ids.h"
12 13
@@ -15,11 +16,9 @@ MODULE_DESCRIPTION("Cougar 500k Gaming Keyboard");
15MODULE_LICENSE("GPL"); 16MODULE_LICENSE("GPL");
16MODULE_INFO(key_mappings, "G1-G6 are mapped to F13-F18"); 17MODULE_INFO(key_mappings, "G1-G6 are mapped to F13-F18");
17 18
18static int cougar_g6_is_space = 1; 19static bool g6_is_space = true;
19module_param_named(g6_is_space, cougar_g6_is_space, int, 0600);
20MODULE_PARM_DESC(g6_is_space, 20MODULE_PARM_DESC(g6_is_space,
21 "If set, G6 programmable key sends SPACE instead of F18 (0=off, 1=on) (default=1)"); 21 "If true, G6 programmable key sends SPACE instead of F18 (default=true)");
22
23 22
24#define COUGAR_VENDOR_USAGE 0xff00ff00 23#define COUGAR_VENDOR_USAGE 0xff00ff00
25 24
@@ -82,20 +81,23 @@ struct cougar {
82static LIST_HEAD(cougar_udev_list); 81static LIST_HEAD(cougar_udev_list);
83static DEFINE_MUTEX(cougar_udev_list_lock); 82static DEFINE_MUTEX(cougar_udev_list_lock);
84 83
85static void cougar_fix_g6_mapping(struct hid_device *hdev) 84/**
85 * cougar_fix_g6_mapping - configure the mapping for key G6/Spacebar
86 */
87static void cougar_fix_g6_mapping(void)
86{ 88{
87 int i; 89 int i;
88 90
89 for (i = 0; cougar_mapping[i][0]; i++) { 91 for (i = 0; cougar_mapping[i][0]; i++) {
90 if (cougar_mapping[i][0] == COUGAR_KEY_G6) { 92 if (cougar_mapping[i][0] == COUGAR_KEY_G6) {
91 cougar_mapping[i][1] = 93 cougar_mapping[i][1] =
92 cougar_g6_is_space ? KEY_SPACE : KEY_F18; 94 g6_is_space ? KEY_SPACE : KEY_F18;
93 hid_info(hdev, "G6 mapped to %s\n", 95 pr_info("cougar: G6 mapped to %s\n",
94 cougar_g6_is_space ? "space" : "F18"); 96 g6_is_space ? "space" : "F18");
95 return; 97 return;
96 } 98 }
97 } 99 }
98 hid_warn(hdev, "no mapping defined for G6/spacebar"); 100 pr_warn("cougar: no mappings defined for G6/spacebar");
99} 101}
100 102
101/* 103/*
@@ -154,7 +156,8 @@ static void cougar_remove_shared_data(void *resource)
154 * Bind the device group's shared data to this cougar struct. 156 * Bind the device group's shared data to this cougar struct.
155 * If no shared data exists for this group, create and initialize it. 157 * If no shared data exists for this group, create and initialize it.
156 */ 158 */
157static int cougar_bind_shared_data(struct hid_device *hdev, struct cougar *cougar) 159static int cougar_bind_shared_data(struct hid_device *hdev,
160 struct cougar *cougar)
158{ 161{
159 struct cougar_shared *shared; 162 struct cougar_shared *shared;
160 int error = 0; 163 int error = 0;
@@ -228,7 +231,6 @@ static int cougar_probe(struct hid_device *hdev,
228 * to it. 231 * to it.
229 */ 232 */
230 if (hdev->collection->usage == HID_GD_KEYBOARD) { 233 if (hdev->collection->usage == HID_GD_KEYBOARD) {
231 cougar_fix_g6_mapping(hdev);
232 list_for_each_entry_safe(hidinput, next, &hdev->inputs, list) { 234 list_for_each_entry_safe(hidinput, next, &hdev->inputs, list) {
233 if (hidinput->registered && hidinput->input != NULL) { 235 if (hidinput->registered && hidinput->input != NULL) {
234 cougar->shared->input = hidinput->input; 236 cougar->shared->input = hidinput->input;
@@ -237,6 +239,8 @@ static int cougar_probe(struct hid_device *hdev,
237 } 239 }
238 } 240 }
239 } else if (hdev->collection->usage == COUGAR_VENDOR_USAGE) { 241 } else if (hdev->collection->usage == COUGAR_VENDOR_USAGE) {
242 /* Preinit the mapping table */
243 cougar_fix_g6_mapping();
240 error = hid_hw_open(hdev); 244 error = hid_hw_open(hdev);
241 if (error) 245 if (error)
242 goto fail_stop_and_cleanup; 246 goto fail_stop_and_cleanup;
@@ -293,6 +297,26 @@ static void cougar_remove(struct hid_device *hdev)
293 hid_hw_stop(hdev); 297 hid_hw_stop(hdev);
294} 298}
295 299
300static int cougar_param_set_g6_is_space(const char *val,
301 const struct kernel_param *kp)
302{
303 int ret;
304
305 ret = param_set_bool(val, kp);
306 if (ret)
307 return ret;
308
309 cougar_fix_g6_mapping();
310
311 return 0;
312}
313
314static const struct kernel_param_ops cougar_g6_is_space_ops = {
315 .set = cougar_param_set_g6_is_space,
316 .get = param_get_bool,
317};
318module_param_cb(g6_is_space, &cougar_g6_is_space_ops, &g6_is_space, 0644);
319
296static struct hid_device_id cougar_id_table[] = { 320static struct hid_device_id cougar_id_table[] = {
297 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR, 321 { HID_USB_DEVICE(USB_VENDOR_ID_SOLID_YEAR,
298 USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD) }, 322 USB_DEVICE_ID_COUGAR_500K_GAMING_KEYBOARD) },