Skip to content

Commit bbec1bd

Browse files
mungewellJiri Kosina
authored andcommitted
HID: logitech: Simplify wheel detection scheme
Simplfy how hid-logitech driver detects the native mode of the wheel, done by looking at the USB-ID revision and comparing bit mask. Signed-off-by: Simon Wood <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 90cdd98 commit bbec1bd

File tree

1 file changed

+28
-42
lines changed

1 file changed

+28
-42
lines changed

drivers/hid/hid-lg4ff.c

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,12 @@ struct lg4ff_compat_mode_switch {
114114
};
115115

116116
struct lg4ff_wheel_ident_info {
117+
const u32 modes;
117118
const u16 mask;
118119
const u16 result;
119120
const u16 real_product_id;
120121
};
121122

122-
struct lg4ff_wheel_ident_checklist {
123-
const u32 count;
124-
const struct lg4ff_wheel_ident_info *models[];
125-
};
126-
127123
struct lg4ff_multimode_wheel {
128124
const u16 product_id;
129125
const u32 alternate_modes;
@@ -174,36 +170,39 @@ static const struct lg4ff_alternate_mode lg4ff_alternate_modes[] = {
174170

175171
/* Multimode wheel identificators */
176172
static const struct lg4ff_wheel_ident_info lg4ff_dfp_ident_info = {
173+
LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
177174
0xf000,
178175
0x1000,
179176
USB_DEVICE_ID_LOGITECH_DFP_WHEEL
180177
};
181178

182179
static const struct lg4ff_wheel_ident_info lg4ff_g25_ident_info = {
180+
LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
183181
0xff00,
184182
0x1200,
185183
USB_DEVICE_ID_LOGITECH_G25_WHEEL
186184
};
187185

188186
static const struct lg4ff_wheel_ident_info lg4ff_g27_ident_info = {
187+
LG4FF_MODE_G27 | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
189188
0xfff0,
190189
0x1230,
191190
USB_DEVICE_ID_LOGITECH_G27_WHEEL
192191
};
193192

194193
static const struct lg4ff_wheel_ident_info lg4ff_dfgt_ident_info = {
194+
LG4FF_MODE_DFGT | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
195195
0xff00,
196196
0x1300,
197197
USB_DEVICE_ID_LOGITECH_DFGT_WHEEL
198198
};
199199

200200
/* Multimode wheel identification checklists */
201-
static const struct lg4ff_wheel_ident_checklist lg4ff_main_checklist = {
202-
4,
203-
{&lg4ff_dfgt_ident_info,
204-
&lg4ff_g27_ident_info,
205-
&lg4ff_g25_ident_info,
206-
&lg4ff_dfp_ident_info}
201+
static const struct lg4ff_wheel_ident_info *lg4ff_main_checklist[] = {
202+
&lg4ff_dfgt_ident_info,
203+
&lg4ff_g27_ident_info,
204+
&lg4ff_g25_ident_info,
205+
&lg4ff_dfp_ident_info
207206
};
208207

209208
/* Compatibility mode switching commands */
@@ -1037,41 +1036,28 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
10371036

10381037
static u16 lg4ff_identify_multimode_wheel(struct hid_device *hid, const u16 reported_product_id, const u16 bcdDevice)
10391038
{
1040-
const struct lg4ff_wheel_ident_checklist *checklist;
1041-
int i, from_idx, to_idx;
1039+
u32 current_mode;
1040+
int i;
10421041

1043-
switch (reported_product_id) {
1044-
case USB_DEVICE_ID_LOGITECH_WHEEL:
1045-
case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
1046-
checklist = &lg4ff_main_checklist;
1047-
from_idx = 0;
1048-
to_idx = checklist->count - 1;
1049-
break;
1050-
case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
1051-
checklist = &lg4ff_main_checklist;
1052-
from_idx = 0;
1053-
to_idx = checklist->count - 2; /* End identity check at G25 */
1054-
break;
1055-
case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
1056-
checklist = &lg4ff_main_checklist;
1057-
from_idx = 1; /* Start identity check at G27 */
1058-
to_idx = checklist->count - 3; /* End identity check at G27 */
1059-
break;
1060-
case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
1061-
checklist = &lg4ff_main_checklist;
1062-
from_idx = 0;
1063-
to_idx = checklist->count - 4; /* End identity check at DFGT */
1064-
break;
1065-
default:
1066-
return 0;
1042+
/* identify current mode from USB PID */
1043+
for (i = 1; i < ARRAY_SIZE(lg4ff_alternate_modes); i++) {
1044+
dbg_hid("Testing whether PID is %X\n", lg4ff_alternate_modes[i].product_id);
1045+
if (reported_product_id == lg4ff_alternate_modes[i].product_id)
1046+
break;
10671047
}
10681048

1069-
for (i = from_idx; i <= to_idx; i++) {
1070-
const u16 mask = checklist->models[i]->mask;
1071-
const u16 result = checklist->models[i]->result;
1072-
const u16 real_product_id = checklist->models[i]->real_product_id;
1049+
if (i == ARRAY_SIZE(lg4ff_alternate_modes))
1050+
return 0;
1051+
1052+
current_mode = BIT(i);
1053+
1054+
for (i = 0; i < ARRAY_SIZE(lg4ff_main_checklist); i++) {
1055+
const u16 mask = lg4ff_main_checklist[i]->mask;
1056+
const u16 result = lg4ff_main_checklist[i]->result;
1057+
const u16 real_product_id = lg4ff_main_checklist[i]->real_product_id;
10731058

1074-
if ((bcdDevice & mask) == result) {
1059+
if ((current_mode & lg4ff_main_checklist[i]->modes) && \
1060+
(bcdDevice & mask) == result) {
10751061
dbg_hid("Found wheel with real PID %X whose reported PID is %X\n", real_product_id, reported_product_id);
10761062
return real_product_id;
10771063
}

0 commit comments

Comments
 (0)