Skip to content

Commit b72cdfa

Browse files
jwrdegoedeJiri Kosina
authored andcommitted
HID: lenovo: Merge tpkbd and cptkbd data structures
Merge the tpkbd and cptkbd data structures, into a single unified structure instead of having a separate data structure per keyboard type. This is a preparation patch for making the tpkbd LED functions more generic, so that they can be re-used for supporting the LEDs on the Thinkpad 10 ultrabook keyboard. Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent a789d5f commit b72cdfa

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

drivers/hid/hid-lenovo.c

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include "hid-ids.h"
3434

35-
struct lenovo_drvdata_tpkbd {
35+
struct lenovo_drvdata {
3636
int led_state;
3737
struct led_classdev led_mute;
3838
struct led_classdev led_micmute;
@@ -42,12 +42,8 @@ struct lenovo_drvdata_tpkbd {
4242
int select_right;
4343
int sensitivity;
4444
int press_speed;
45-
};
46-
47-
struct lenovo_drvdata_cptkbd {
4845
u8 middlebutton_state; /* 0:Up, 1:Down (undecided), 2:Scrolling */
4946
bool fn_lock;
50-
int sensitivity;
5147
};
5248

5349
#define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
@@ -242,7 +238,7 @@ static int lenovo_send_cmd_cptkbd(struct hid_device *hdev,
242238
static void lenovo_features_set_cptkbd(struct hid_device *hdev)
243239
{
244240
int ret;
245-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
241+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
246242

247243
ret = lenovo_send_cmd_cptkbd(hdev, 0x05, cptkbd_data->fn_lock);
248244
if (ret)
@@ -258,7 +254,7 @@ static ssize_t attr_fn_lock_show_cptkbd(struct device *dev,
258254
char *buf)
259255
{
260256
struct hid_device *hdev = to_hid_device(dev);
261-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
257+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
262258

263259
return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock);
264260
}
@@ -269,7 +265,7 @@ static ssize_t attr_fn_lock_store_cptkbd(struct device *dev,
269265
size_t count)
270266
{
271267
struct hid_device *hdev = to_hid_device(dev);
272-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
268+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
273269
int value;
274270

275271
if (kstrtoint(buf, 10, &value))
@@ -288,7 +284,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
288284
char *buf)
289285
{
290286
struct hid_device *hdev = to_hid_device(dev);
291-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
287+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
292288

293289
return snprintf(buf, PAGE_SIZE, "%u\n",
294290
cptkbd_data->sensitivity);
@@ -300,7 +296,7 @@ static ssize_t attr_sensitivity_store_cptkbd(struct device *dev,
300296
size_t count)
301297
{
302298
struct hid_device *hdev = to_hid_device(dev);
303-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
299+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
304300
int value;
305301

306302
if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
@@ -357,7 +353,7 @@ static int lenovo_raw_event(struct hid_device *hdev,
357353
static int lenovo_event_cptkbd(struct hid_device *hdev,
358354
struct hid_field *field, struct hid_usage *usage, __s32 value)
359355
{
360-
struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
356+
struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
361357

362358
/* "wheel" scroll events */
363359
if (usage->type == EV_REL && (usage->code == REL_WHEEL ||
@@ -404,7 +400,7 @@ static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
404400
static int lenovo_features_set_tpkbd(struct hid_device *hdev)
405401
{
406402
struct hid_report *report;
407-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
403+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
408404

409405
report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4];
410406

@@ -425,7 +421,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
425421
char *buf)
426422
{
427423
struct hid_device *hdev = to_hid_device(dev);
428-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
424+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
429425

430426
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
431427
}
@@ -436,7 +432,7 @@ static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
436432
size_t count)
437433
{
438434
struct hid_device *hdev = to_hid_device(dev);
439-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
435+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
440436
int value;
441437

442438
if (kstrtoint(buf, 10, &value))
@@ -455,7 +451,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev,
455451
char *buf)
456452
{
457453
struct hid_device *hdev = to_hid_device(dev);
458-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
454+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
459455

460456
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
461457
}
@@ -466,7 +462,7 @@ static ssize_t attr_dragging_store_tpkbd(struct device *dev,
466462
size_t count)
467463
{
468464
struct hid_device *hdev = to_hid_device(dev);
469-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
465+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
470466
int value;
471467

472468
if (kstrtoint(buf, 10, &value))
@@ -485,7 +481,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
485481
char *buf)
486482
{
487483
struct hid_device *hdev = to_hid_device(dev);
488-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
484+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
489485

490486
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
491487
}
@@ -496,7 +492,7 @@ static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
496492
size_t count)
497493
{
498494
struct hid_device *hdev = to_hid_device(dev);
499-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
495+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
500496
int value;
501497

502498
if (kstrtoint(buf, 10, &value))
@@ -515,7 +511,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev,
515511
char *buf)
516512
{
517513
struct hid_device *hdev = to_hid_device(dev);
518-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
514+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
519515

520516
return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
521517
}
@@ -526,7 +522,7 @@ static ssize_t attr_select_right_store_tpkbd(struct device *dev,
526522
size_t count)
527523
{
528524
struct hid_device *hdev = to_hid_device(dev);
529-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
525+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
530526
int value;
531527

532528
if (kstrtoint(buf, 10, &value))
@@ -545,7 +541,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
545541
char *buf)
546542
{
547543
struct hid_device *hdev = to_hid_device(dev);
548-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
544+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
549545

550546
return snprintf(buf, PAGE_SIZE, "%u\n",
551547
data_pointer->sensitivity);
@@ -557,7 +553,7 @@ static ssize_t attr_sensitivity_store_tpkbd(struct device *dev,
557553
size_t count)
558554
{
559555
struct hid_device *hdev = to_hid_device(dev);
560-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
556+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
561557
int value;
562558

563559
if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
@@ -574,7 +570,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
574570
char *buf)
575571
{
576572
struct hid_device *hdev = to_hid_device(dev);
577-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
573+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
578574

579575
return snprintf(buf, PAGE_SIZE, "%u\n",
580576
data_pointer->press_speed);
@@ -586,7 +582,7 @@ static ssize_t attr_press_speed_store_tpkbd(struct device *dev,
586582
size_t count)
587583
{
588584
struct hid_device *hdev = to_hid_device(dev);
589-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
585+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
590586
int value;
591587

592588
if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
@@ -647,7 +643,7 @@ static enum led_brightness lenovo_led_brightness_get_tpkbd(
647643
{
648644
struct device *dev = led_cdev->dev->parent;
649645
struct hid_device *hdev = to_hid_device(dev);
650-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
646+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
651647
int led_nr = 0;
652648

653649
if (led_cdev == &data_pointer->led_micmute)
@@ -663,7 +659,7 @@ static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev,
663659
{
664660
struct device *dev = led_cdev->dev->parent;
665661
struct hid_device *hdev = to_hid_device(dev);
666-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
662+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
667663
struct hid_report *report;
668664
int led_nr = 0;
669665

@@ -684,7 +680,7 @@ static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev,
684680
static int lenovo_probe_tpkbd(struct hid_device *hdev)
685681
{
686682
struct device *dev = &hdev->dev;
687-
struct lenovo_drvdata_tpkbd *data_pointer;
683+
struct lenovo_drvdata *data_pointer;
688684
size_t name_sz = strlen(dev_name(dev)) + 16;
689685
char *name_mute, *name_micmute;
690686
int i;
@@ -712,7 +708,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
712708
hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
713709

714710
data_pointer = devm_kzalloc(&hdev->dev,
715-
sizeof(struct lenovo_drvdata_tpkbd),
711+
sizeof(struct lenovo_drvdata),
716712
GFP_KERNEL);
717713
if (data_pointer == NULL) {
718714
hid_err(hdev, "Could not allocate memory for driver data\n");
@@ -767,7 +763,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
767763
static int lenovo_probe_cptkbd(struct hid_device *hdev)
768764
{
769765
int ret;
770-
struct lenovo_drvdata_cptkbd *cptkbd_data;
766+
struct lenovo_drvdata *cptkbd_data;
771767

772768
/* All the custom action happens on the USBMOUSE device for USB */
773769
if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD
@@ -852,7 +848,7 @@ static int lenovo_probe(struct hid_device *hdev,
852848

853849
static void lenovo_remove_tpkbd(struct hid_device *hdev)
854850
{
855-
struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
851+
struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
856852

857853
/*
858854
* Only the trackpoint half of the keyboard has drvdata and stuff that

0 commit comments

Comments
 (0)