Unified · Split
| @@ -109,23 +109,23 @@ static __u8 dfp_rdesc_fixed[] = { · 108 unmodified lines | ||
| 109 | 109 | static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 110 | 110 | unsigned int *rsize) |
| 111 | 111 | { |
| 112 | − unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | |
| 112 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); | |
| 113 | 113 | |
| 114 | − if ((quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && | |
| 114 | + if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && | |
| 115 | 115 | rdesc[84] == 0x8c && rdesc[85] == 0x02) { |
| 116 | 116 | hid_info(hdev, |
| 117 | 117 | "fixing up Logitech keyboard report descriptor\n"); |
| 118 | 118 | rdesc[84] = rdesc[89] = 0x4d; |
| 119 | 119 | rdesc[85] = rdesc[90] = 0x10; |
| 120 | 120 | } |
| 121 | − if ((quirks & LG_RDESC_REL_ABS) && *rsize >= 50 && | |
| 121 | + if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 && | |
| 122 | 122 | rdesc[32] == 0x81 && rdesc[33] == 0x06 && |
| 123 | 123 | rdesc[49] == 0x81 && rdesc[50] == 0x06) { |
| 124 | 124 | hid_info(hdev, |
| 125 | 125 | "fixing up rel/abs in Logitech report descriptor\n"); |
| 126 | 126 | rdesc[33] = rdesc[50] = 0x02; |
| 127 | 127 | } |
| 128 | − if ((quirks & LG_FF4) && *rsize >= 101 && | |
| 128 | + if ((drv_data->quirks & LG_FF4) && *rsize >= 101 && | |
| 129 | 129 | rdesc[41] == 0x95 && rdesc[42] == 0x0B && |
| 130 | 130 | rdesc[47] == 0x05 && rdesc[48] == 0x09) { |
| 131 | 131 | hid_info(hdev, "fixing up Logitech Speed Force Wireless button descriptor\n"); |
| @@ -278,7 +278,7 @@ static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 146 unmodified lines | ||
| 278 | 278 | 0, 0, 0, 0, 0,183,184,185,186,187, |
| 279 | 279 | 188,189,190,191,192,193,194, 0, 0, 0 |
| 280 | 280 | }; |
| 281 | − unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | |
| 281 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); | |
| 282 | 282 | unsigned int hid = usage->hid; |
| 283 | 283 | |
| 284 | 284 | if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER && |
| @@ -289,7 +289,7 @@ static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 4 unmodified lines | ||
| 289 | 289 | lg_dinovo_mapping(hi, usage, bit, max)) |
| 290 | 290 | return 1; |
| 291 | 291 | |
| 292 | − if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max)) | |
| 292 | + if ((drv_data->quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max)) | |
| 293 | 293 | return 1; |
| 294 | 294 | |
| 295 | 295 | if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| @@ -299,11 +299,11 @@ static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 3 unmodified lines | ||
| 299 | 299 | |
| 300 | 300 | /* Special handling for Logitech Cordless Desktop */ |
| 301 | 301 | if (field->application == HID_GD_MOUSE) { |
| 302 | − if ((quirks & LG_IGNORE_DOUBLED_WHEEL) && | |
| 302 | + if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) && | |
| 303 | 303 | (hid == 7 || hid == 8)) |
| 304 | 304 | return -1; |
| 305 | 305 | } else { |
| 306 | − if ((quirks & LG_EXPANDED_KEYMAP) && | |
| 306 | + if ((drv_data->quirks & LG_EXPANDED_KEYMAP) && | |
| 307 | 307 | hid < ARRAY_SIZE(e_keymap) && |
| 308 | 308 | e_keymap[hid] != 0) { |
| 309 | 309 | hid_map_usage(hi, usage, bit, max, EV_KEY, |
| @@ -319,13 +319,13 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi, · 9 unmodified lines | ||
| 319 | 319 | struct hid_field *field, struct hid_usage *usage, |
| 320 | 320 | unsigned long **bit, int *max) |
| 321 | 321 | { |
| 322 | − unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | |
| 322 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); | |
| 323 | 323 | |
| 324 | − if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && | |
| 324 | + if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && | |
| 325 | 325 | (field->flags & HID_MAIN_ITEM_RELATIVE)) |
| 326 | 326 | field->flags &= ~HID_MAIN_ITEM_RELATIVE; |
| 327 | 327 | |
| 328 | − if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY || | |
| 328 | + if ((drv_data->quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY || | |
| 329 | 329 | usage->type == EV_REL || usage->type == EV_ABS)) |
| 330 | 330 | clear_bit(usage->code, *bit); |
| 331 | 331 | |
| @@ -335,9 +335,9 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi, · 3 unmodified lines | ||
| 335 | 335 | static int lg_event(struct hid_device *hdev, struct hid_field *field, |
| 336 | 336 | struct hid_usage *usage, __s32 value) |
| 337 | 337 | { |
| 338 | − unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | |
| 338 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); | |
| 339 | 339 | |
| 340 | − if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { | |
| 340 | + if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { | |
| 341 | 341 | input_event(field->hidinput->input, usage->type, usage->code, |
| 342 | 342 | -value); |
| 343 | 343 | return 1; |
| @@ -348,13 +348,20 @@ static int lg_event(struct hid_device *hdev, struct hid_field *field, · 4 unmodified lines | ||
| 348 | 348 | |
| 349 | 349 | static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 350 | 350 | { |
| 351 | − unsigned long quirks = id->driver_data; | |
| 352 | 351 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
| 352 | + struct lg_drv_data *drv_data; | |
| 353 | 353 | int ret; |
| 354 | 354 | |
| 355 | − hid_set_drvdata(hdev, (void *)quirks); | |
| 355 | + drv_data = kzalloc(sizeof(struct lg_drv_data), GFP_KERNEL); | |
| 356 | + if (!drv_data) { | |
| 357 | + hid_err(hdev, "Insufficient memory, cannot allocate driver data\n"); | |
| 358 | + return -ENOMEM; | |
| 359 | + } | |
| 360 | + drv_data->quirks = id->driver_data; | |
| 361 | + | |
| 362 | + hid_set_drvdata(hdev, (void *)drv_data); | |
| 356 | 363 | |
| 357 | − if (quirks & LG_NOGET) | |
| 364 | + if (drv_data->quirks & LG_NOGET) | |
| 358 | 365 | hdev->quirks |= HID_QUIRK_NOGET; |
| 359 | 366 | |
| 360 | 367 | ret = hid_parse(hdev); |
| @@ -363,7 +370,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) · 2 unmodified lines | ||
| 363 | 370 | goto err_free; |
| 364 | 371 | } |
| 365 | 372 | |
| 366 | − if (quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4)) | |
| 373 | + if (drv_data->quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4)) | |
| 367 | 374 | connect_mask &= ~HID_CONNECT_FF; |
| 368 | 375 | |
| 369 | 376 | ret = hid_hw_start(hdev, connect_mask); |
| @@ -392,27 +399,29 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) · 22 unmodified lines | ||
| 392 | 399 | } |
| 393 | 400 | } |
| 394 | 401 | |
| 395 | − if (quirks & LG_FF) | |
| 402 | + if (drv_data->quirks & LG_FF) | |
| 396 | 403 | lgff_init(hdev); |
| 397 | − if (quirks & LG_FF2) | |
| 404 | + if (drv_data->quirks & LG_FF2) | |
| 398 | 405 | lg2ff_init(hdev); |
| 399 | − if (quirks & LG_FF3) | |
| 406 | + if (drv_data->quirks & LG_FF3) | |
| 400 | 407 | lg3ff_init(hdev); |
| 401 | − if (quirks & LG_FF4) | |
| 408 | + if (drv_data->quirks & LG_FF4) | |
| 402 | 409 | lg4ff_init(hdev); |
| 403 | 410 | |
| 404 | 411 | return 0; |
| 405 | 412 | err_free: |
| 413 | + kfree(drv_data); | |
| 406 | 414 | return ret; |
| 407 | 415 | } |
| 408 | 416 | |
| 409 | 417 | static void lg_remove(struct hid_device *hdev) |
| 410 | 418 | { |
| 411 | − unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | |
| 412 | − if(quirks & LG_FF4) | |
| 419 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); | |
| 420 | + if (drv_data->quirks & LG_FF4) | |
| 413 | 421 | lg4ff_deinit(hdev); |
| 414 | 422 | |
| 415 | 423 | hid_hw_stop(hdev); |
| 424 | + kfree(drv_data); | |
| 416 | 425 | } |
| 417 | 426 | |
| 418 | 427 | static const struct hid_device_id lg_devices[] = { |
| @@ -1,6 +1,11 @@ | ||
| 1 | 1 | #ifndef __HID_LG_H |
| 2 | 2 | #define __HID_LG_H |
| 3 | 3 | |
| 4 | +struct lg_drv_data { | |
| 5 | + unsigned long quirks; | |
| 6 | + void *device_props; /* Device specific properties */ | |
| 7 | +}; | |
| 8 | + | |
| 4 | 9 | #ifdef CONFIG_LOGITECH_FF |
| 5 | 10 | int lgff_init(struct hid_device *hdev); |
| 6 | 11 | #else |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | /* |
| 2 | − * Force feedback support for Logitech Speed Force Wireless | |
| 2 | + * Force feedback support for Logitech Gaming Wheels | |
| 3 | 3 | * |
| 4 | − * http://wiibrew.org/wiki/Logitech_USB_steering_wheel | |
| 4 | + * Including G27, G25, DFP, DFGT, FFEX, Momo, Momo2 & | |
| 5 | + * Speed Force Wireless (WiiWheel) | |
| 5 | 6 | * |
| 6 | 7 | * Copyright (c) 2010 Simon Wood <simon@mungewell.org> |
| 7 | 8 | */ |
| @@ -51,20 +52,18 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at · 43 unmodified lines | ||
| 51 | 52 | |
| 52 | 53 | static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store); |
| 53 | 54 | |
| 54 | −static bool list_inited; | |
| 55 | − | |
| 56 | 55 | struct lg4ff_device_entry { |
| 57 | − char *device_id; /* Use name in respective kobject structure's address as the ID */ | |
| 58 | 56 | __u16 range; |
| 59 | 57 | __u16 min_range; |
| 60 | 58 | __u16 max_range; |
| 61 | − __u8 leds; | |
| 59 | +#ifdef CONFIG_LEDS_CLASS | |
| 60 | + __u8 led_state; | |
| 61 | + struct led_classdev *led[5]; | |
| 62 | +#endif | |
| 62 | 63 | struct list_head list; |
| 63 | 64 | void (*set_range)(struct hid_device *hid, u16 range); |
| 64 | 65 | }; |
| 65 | 66 | |
| 66 | −static struct lg4ff_device_entry device_list; | |
| 67 | − | |
| 68 | 67 | static const signed short lg4ff_wheel_effects[] = { |
| 69 | 68 | FF_CONSTANT, |
| 70 | 69 | FF_AUTOCENTER, |
| @@ -285,18 +284,20 @@ static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_n · 214 unmodified lines | ||
| 285 | 284 | /* Read current range and display it in terminal */ |
| 286 | 285 | static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 287 | 286 | { |
| 288 | − struct lg4ff_device_entry *uninitialized_var(entry); | |
| 289 | − struct list_head *h; | |
| 290 | 287 | struct hid_device *hid = to_hid_device(dev); |
| 288 | + struct lg4ff_device_entry *entry; | |
| 289 | + struct lg_drv_data *drv_data; | |
| 291 | 290 | size_t count; |
| 292 | 291 | |
| 293 | − list_for_each(h, &device_list.list) { | |
| 294 | − entry = list_entry(h, struct lg4ff_device_entry, list); | |
| 295 | − if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | |
| 296 | − break; | |
| 292 | + drv_data = hid_get_drvdata(hid); | |
| 293 | + if (!drv_data) { | |
| 294 | + hid_err(hid, "Private driver data not found!\n"); | |
| 295 | + return 0; | |
| 297 | 296 | } |
| 298 | − if (h == &device_list.list) { | |
| 299 | − dbg_hid("Device not found!"); | |
| 297 | + | |
| 298 | + entry = drv_data->device_props; | |
| 299 | + if (!entry) { | |
| 300 | + hid_err(hid, "Device properties not found!\n"); | |
| 300 | 301 | return 0; |
| 301 | 302 | } |
| 302 | 303 | |
| @@ -308,19 +309,21 @@ static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *att · 5 unmodified lines | ||
| 308 | 309 | * according to the type of the wheel */ |
| 309 | 310 | static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
| 310 | 311 | { |
| 311 | − struct lg4ff_device_entry *uninitialized_var(entry); | |
| 312 | − struct list_head *h; | |
| 313 | 312 | struct hid_device *hid = to_hid_device(dev); |
| 313 | + struct lg4ff_device_entry *entry; | |
| 314 | + struct lg_drv_data *drv_data; | |
| 314 | 315 | __u16 range = simple_strtoul(buf, NULL, 10); |
| 315 | 316 | |
| 316 | − list_for_each(h, &device_list.list) { | |
| 317 | − entry = list_entry(h, struct lg4ff_device_entry, list); | |
| 318 | − if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | |
| 319 | − break; | |
| 317 | + drv_data = hid_get_drvdata(hid); | |
| 318 | + if (!drv_data) { | |
| 319 | + hid_err(hid, "Private driver data not found!\n"); | |
| 320 | + return 0; | |
| 320 | 321 | } |
| 321 | − if (h == &device_list.list) { | |
| 322 | − dbg_hid("Device not found!"); | |
| 323 | − return count; | |
| 322 | + | |
| 323 | + entry = drv_data->device_props; | |
| 324 | + if (!entry) { | |
| 325 | + hid_err(hid, "Device properties not found!\n"); | |
| 326 | + return 0; | |
| 324 | 327 | } |
| 325 | 328 | |
| 326 | 329 | if (range == 0) |
| @@ -336,6 +339,88 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at · 9 unmodified lines | ||
| 336 | 339 | return count; |
| 337 | 340 | } |
| 338 | 341 | |
| 342 | +#ifdef CONFIG_LEDS_CLASS | |
| 343 | +static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) | |
| 344 | +{ | |
| 345 | + struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | |
| 346 | + struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | |
| 347 | + | |
| 348 | + report->field[0]->value[0] = 0xf8; | |
| 349 | + report->field[0]->value[1] = 0x12; | |
| 350 | + report->field[0]->value[2] = leds; | |
| 351 | + report->field[0]->value[3] = 0x00; | |
| 352 | + report->field[0]->value[4] = 0x00; | |
| 353 | + report->field[0]->value[5] = 0x00; | |
| 354 | + report->field[0]->value[6] = 0x00; | |
| 355 | + usbhid_submit_report(hid, report, USB_DIR_OUT); | |
| 356 | +} | |
| 357 | + | |
| 358 | +static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, | |
| 359 | + enum led_brightness value) | |
| 360 | +{ | |
| 361 | + struct device *dev = led_cdev->dev->parent; | |
| 362 | + struct hid_device *hid = container_of(dev, struct hid_device, dev); | |
| 363 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); | |
| 364 | + struct lg4ff_device_entry *entry; | |
| 365 | + int i, state = 0; | |
| 366 | + | |
| 367 | + if (!drv_data) { | |
| 368 | + hid_err(hid, "Device data not found."); | |
| 369 | + return; | |
| 370 | + } | |
| 371 | + | |
| 372 | + entry = (struct lg4ff_device_entry *)drv_data->device_props; | |
| 373 | + | |
| 374 | + if (!entry) { | |
| 375 | + hid_err(hid, "Device properties not found."); | |
| 376 | + return; | |
| 377 | + } | |
| 378 | + | |
| 379 | + for (i = 0; i < 5; i++) { | |
| 380 | + if (led_cdev != entry->led[i]) | |
| 381 | + continue; | |
| 382 | + state = (entry->led_state >> i) & 1; | |
| 383 | + if (value == LED_OFF && state) { | |
| 384 | + entry->led_state &= ~(1 << i); | |
| 385 | + lg4ff_set_leds(hid, entry->led_state); | |
| 386 | + } else if (value != LED_OFF && !state) { | |
| 387 | + entry->led_state |= 1 << i; | |
| 388 | + lg4ff_set_leds(hid, entry->led_state); | |
| 389 | + } | |
| 390 | + break; | |
| 391 | + } | |
| 392 | +} | |
| 393 | + | |
| 394 | +static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev) | |
| 395 | +{ | |
| 396 | + struct device *dev = led_cdev->dev->parent; | |
| 397 | + struct hid_device *hid = container_of(dev, struct hid_device, dev); | |
| 398 | + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); | |
| 399 | + struct lg4ff_device_entry *entry; | |
| 400 | + int i, value = 0; | |
| 401 | + | |
| 402 | + if (!drv_data) { | |
| 403 | + hid_err(hid, "Device data not found."); | |
| 404 | + return LED_OFF; | |
| 405 | + } | |
| 406 | + | |
| 407 | + entry = (struct lg4ff_device_entry *)drv_data->device_props; | |
| 408 | + | |
| 409 | + if (!entry) { | |
| 410 | + hid_err(hid, "Device properties not found."); | |
| 411 | + return LED_OFF; | |
| 412 | + } | |
| 413 | + | |
| 414 | + for (i = 0; i < 5; i++) | |
| 415 | + if (led_cdev == entry->led[i]) { | |
| 416 | + value = (entry->led_state >> i) & 1; | |
| 417 | + break; | |
| 418 | + } | |
| 419 | + | |
| 420 | + return value ? LED_FULL : LED_OFF; | |
| 421 | +} | |
| 422 | +#endif | |
| 423 | + | |
| 339 | 424 | int lg4ff_init(struct hid_device *hid) |
| 340 | 425 | { |
| 341 | 426 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); |
| @@ -344,6 +429,7 @@ int lg4ff_init(struct hid_device *hid) · 2 unmodified lines | ||
| 344 | 429 | struct hid_report *report; |
| 345 | 430 | struct hid_field *field; |
| 346 | 431 | struct lg4ff_device_entry *entry; |
| 432 | + struct lg_drv_data *drv_data; | |
| 347 | 433 | struct usb_device_descriptor *udesc; |
| 348 | 434 | int error, i, j; |
| 349 | 435 | __u16 bcdDevice, rev_maj, rev_min; |
| @@ -423,28 +509,24 @@ int lg4ff_init(struct hid_device *hid) · 73 unmodified lines | ||
| 423 | 509 | dev->ff->set_autocenter(dev, 0); |
| 424 | 510 | } |
| 425 | 511 | |
| 426 | − /* Initialize device_list if this is the first device to handle by lg4ff */ | |
| 427 | − if (!list_inited) { | |
| 428 | − INIT_LIST_HEAD(&device_list.list); | |
| 429 | − list_inited = 1; | |
| 512 | + /* Get private driver data */ | |
| 513 | + drv_data = hid_get_drvdata(hid); | |
| 514 | + if (!drv_data) { | |
| 515 | + hid_err(hid, "Cannot add device, private driver data not allocated\n"); | |
| 516 | + return -1; | |
| 430 | 517 | } |
| 431 | 518 | |
| 432 | − /* Add the device to device_list */ | |
| 519 | + /* Initialize device properties */ | |
| 433 | 520 | entry = kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); |
| 434 | 521 | if (!entry) { |
| 435 | − hid_err(hid, "Cannot add device, insufficient memory.\n"); | |
| 436 | − return -ENOMEM; | |
| 437 | − } | |
| 438 | − entry->device_id = kstrdup((&hid->dev)->kobj.name, GFP_KERNEL); | |
| 439 | − if (!entry->device_id) { | |
| 440 | − hid_err(hid, "Cannot set device_id, insufficient memory.\n"); | |
| 441 | − kfree(entry); | |
| 522 | + hid_err(hid, "Cannot add device, insufficient memory to allocate device properties.\n"); | |
| 442 | 523 | return -ENOMEM; |
| 443 | 524 | } |
| 525 | + drv_data->device_props = entry; | |
| 526 | + | |
| 444 | 527 | entry->min_range = lg4ff_devices[i].min_range; |
| 445 | 528 | entry->max_range = lg4ff_devices[i].max_range; |
| 446 | 529 | entry->set_range = lg4ff_devices[i].set_range; |
| 447 | − list_add(&entry->list, &device_list.list); | |
| 448 | 530 | |
| 449 | 531 | /* Create sysfs interface */ |
| 450 | 532 | error = device_create_file(&hid->dev, &dev_attr_range); |
| @@ -457,32 +539,100 @@ int lg4ff_init(struct hid_device *hid) · 6 unmodified lines | ||
| 457 | 539 | if (entry->set_range != NULL) |
| 458 | 540 | entry->set_range(hid, entry->range); |
| 459 | 541 | |
| 460 | − hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood <simon@mungewell.org>\n"); | |
| 542 | +#ifdef CONFIG_LEDS_CLASS | |
| 543 | + /* register led subsystem - G27 only */ | |
| 544 | + entry->led_state = 0; | |
| 545 | + for (j = 0; j < 5; j++) | |
| 546 | + entry->led[j] = NULL; | |
| 547 | + | |
| 548 | + if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) { | |
| 549 | + struct led_classdev *led; | |
| 550 | + size_t name_sz; | |
| 551 | + char *name; | |
| 552 | + | |
| 553 | + lg4ff_set_leds(hid, 0); | |
| 554 | + | |
| 555 | + name_sz = strlen(dev_name(&hid->dev)) + 8; | |
| 556 | + | |
| 557 | + for (j = 0; j < 5; j++) { | |
| 558 | + led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL); | |
| 559 | + if (!led) { | |
| 560 | + hid_err(hid, "can't allocate memory for LED %d\n", j); | |
| 561 | + goto err; | |
| 562 | + } | |
| 563 | + | |
| 564 | + name = (void *)(&led[1]); | |
| 565 | + snprintf(name, name_sz, "%s::RPM%d", dev_name(&hid->dev), j+1); | |
| 566 | + led->name = name; | |
| 567 | + led->brightness = 0; | |
| 568 | + led->max_brightness = 1; | |
| 569 | + led->brightness_get = lg4ff_led_get_brightness; | |
| 570 | + led->brightness_set = lg4ff_led_set_brightness; | |
| 571 | + | |
| 572 | + entry->led[j] = led; | |
| 573 | + error = led_classdev_register(&hid->dev, led); | |
| 574 | + | |
| 575 | + if (error) { | |
| 576 | + hid_err(hid, "failed to register LED %d. Aborting.\n", j); | |
| 577 | +err: | |
| 578 | + /* Deregister LEDs (if any) */ | |
| 579 | + for (j = 0; j < 5; j++) { | |
| 580 | + led = entry->led[j]; | |
| 581 | + entry->led[j] = NULL; | |
| 582 | + if (!led) | |
| 583 | + continue; | |
| 584 | + led_classdev_unregister(led); | |
| 585 | + kfree(led); | |
| 586 | + } | |
| 587 | + goto out; /* Let the driver continue without LEDs */ | |
| 588 | + } | |
| 589 | + } | |
| 590 | + } | |
| 591 | +out: | |
| 592 | +#endif | |
| 593 | + hid_info(hid, "Force feedback support for Logitech Gaming Wheels\n"); | |
| 461 | 594 | return 0; |
| 462 | 595 | } |
| 463 | 596 | |
| 464 | 597 | int lg4ff_deinit(struct hid_device *hid) |
| 465 | 598 | { |
| 466 | − bool found = 0; | |
| 467 | 599 | struct lg4ff_device_entry *entry; |
| 468 | − struct list_head *h, *g; | |
| 469 | − list_for_each_safe(h, g, &device_list.list) { | |
| 470 | − entry = list_entry(h, struct lg4ff_device_entry, list); | |
| 471 | − if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) { | |
| 472 | − list_del(h); | |
| 473 | − kfree(entry->device_id); | |
| 474 | − kfree(entry); | |
| 475 | − found = 1; | |
| 476 | − break; | |
| 477 | − } | |
| 478 | − } | |
| 600 | + struct lg_drv_data *drv_data; | |
| 601 | + | |
| 602 | + device_remove_file(&hid->dev, &dev_attr_range); | |
| 479 | 603 | |
| 480 | − if (!found) { | |
| 481 | − dbg_hid("Device entry not found!\n"); | |
| 604 | + drv_data = hid_get_drvdata(hid); | |
| 605 | + if (!drv_data) { | |
| 606 | + hid_err(hid, "Error while deinitializing device, no private driver data.\n"); | |
| 607 | + return -1; | |
| 608 | + } | |
| 609 | + entry = drv_data->device_props; | |
| 610 | + if (!entry) { | |
| 611 | + hid_err(hid, "Error while deinitializing device, no device properties data.\n"); | |
| 482 | 612 | return -1; |
| 483 | 613 | } |
| 484 | 614 | |
| 485 | − device_remove_file(&hid->dev, &dev_attr_range); | |
| 615 | +#ifdef CONFIG_LEDS_CLASS | |
| 616 | + { | |
| 617 | + int j; | |
| 618 | + struct led_classdev *led; | |
| 619 | + | |
| 620 | + /* Deregister LEDs (if any) */ | |
| 621 | + for (j = 0; j < 5; j++) { | |
| 622 | + | |
| 623 | + led = entry->led[j]; | |
| 624 | + entry->led[j] = NULL; | |
| 625 | + if (!led) | |
| 626 | + continue; | |
| 627 | + led_classdev_unregister(led); | |
| 628 | + kfree(led); | |
| 629 | + } | |
| 630 | + } | |
| 631 | +#endif | |
| 632 | + | |
| 633 | + /* Deallocate memory */ | |
| 634 | + kfree(entry); | |
| 635 | + | |
| 486 | 636 | dbg_hid("Device successfully unregistered\n"); |
| 487 | 637 | return 0; |
| 488 | 638 | } |
| @@ -70,9 +70,16 @@ struct mt_class { · 69 unmodified lines | ||
| 70 | 70 | bool is_indirect; /* true for touchpads */ |
| 71 | 71 | }; |
| 72 | 72 | |
| 73 | +struct mt_fields { | |
| 74 | + unsigned usages[HID_MAX_FIELDS]; | |
| 75 | + unsigned int length; | |
| 76 | +}; | |
| 77 | + | |
| 73 | 78 | struct mt_device { |
| 74 | 79 | struct mt_slot curdata; /* placeholder of incoming data */ |
| 75 | 80 | struct mt_class mtclass; /* our mt device class */ |
| 81 | + struct mt_fields *fields; /* temporary placeholder for storing the | |
| 82 | + multitouch fields */ | |
| 76 | 83 | unsigned last_field_index; /* last field index of the report */ |
| 77 | 84 | unsigned last_slot_field; /* the last field of a slot */ |
| 78 | 85 | __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ |
| @@ -278,11 +285,15 @@ static void set_abs(struct input_dev *input, unsigned int code, · 199 unmodified lines | ||
| 278 | 285 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); |
| 279 | 286 | } |
| 280 | 287 | |
| 281 | −static void set_last_slot_field(struct hid_usage *usage, struct mt_device *td, | |
| 288 | +static void mt_store_field(struct hid_usage *usage, struct mt_device *td, | |
| 282 | 289 | struct hid_input *hi) |
| 283 | 290 | { |
| 284 | − if (!test_bit(usage->hid, hi->input->absbit)) | |
| 285 | − td->last_slot_field = usage->hid; | |
| 291 | + struct mt_fields *f = td->fields; | |
| 292 | + | |
| 293 | + if (f->length >= HID_MAX_FIELDS) | |
| 294 | + return; | |
| 295 | + | |
| 296 | + f->usages[f->length++] = usage->hid; | |
| 286 | 297 | } |
| 287 | 298 | |
| 288 | 299 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, |
| @@ -333,7 +344,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 44 unmodified lines | ||
| 333 | 344 | cls->sn_move); |
| 334 | 345 | /* touchscreen emulation */ |
| 335 | 346 | set_abs(hi->input, ABS_X, field, cls->sn_move); |
| 336 | − set_last_slot_field(usage, td, hi); | |
| 347 | + mt_store_field(usage, td, hi); | |
| 337 | 348 | td->last_field_index = field->index; |
| 338 | 349 | return 1; |
| 339 | 350 | case HID_GD_Y: |
| @@ -343,7 +354,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 3 unmodified lines | ||
| 343 | 354 | cls->sn_move); |
| 344 | 355 | /* touchscreen emulation */ |
| 345 | 356 | set_abs(hi->input, ABS_Y, field, cls->sn_move); |
| 346 | − set_last_slot_field(usage, td, hi); | |
| 357 | + mt_store_field(usage, td, hi); | |
| 347 | 358 | td->last_field_index = field->index; |
| 348 | 359 | return 1; |
| 349 | 360 | } |
| @@ -352,24 +363,24 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 2 unmodified lines | ||
| 352 | 363 | case HID_UP_DIGITIZER: |
| 353 | 364 | switch (usage->hid) { |
| 354 | 365 | case HID_DG_INRANGE: |
| 355 | − set_last_slot_field(usage, td, hi); | |
| 366 | + mt_store_field(usage, td, hi); | |
| 356 | 367 | td->last_field_index = field->index; |
| 357 | 368 | return 1; |
| 358 | 369 | case HID_DG_CONFIDENCE: |
| 359 | − set_last_slot_field(usage, td, hi); | |
| 370 | + mt_store_field(usage, td, hi); | |
| 360 | 371 | td->last_field_index = field->index; |
| 361 | 372 | return 1; |
| 362 | 373 | case HID_DG_TIPSWITCH: |
| 363 | 374 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); |
| 364 | 375 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); |
| 365 | − set_last_slot_field(usage, td, hi); | |
| 376 | + mt_store_field(usage, td, hi); | |
| 366 | 377 | td->last_field_index = field->index; |
| 367 | 378 | return 1; |
| 368 | 379 | case HID_DG_CONTACTID: |
| 369 | 380 | if (!td->maxcontacts) |
| 370 | 381 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; |
| 371 | 382 | input_mt_init_slots(hi->input, td->maxcontacts); |
| 372 | − td->last_slot_field = usage->hid; | |
| 383 | + mt_store_field(usage, td, hi); | |
| 373 | 384 | td->last_field_index = field->index; |
| 374 | 385 | td->touches_by_report++; |
| 375 | 386 | return 1; |
| @@ -378,7 +389,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 2 unmodified lines | ||
| 378 | 389 | EV_ABS, ABS_MT_TOUCH_MAJOR); |
| 379 | 390 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, |
| 380 | 391 | cls->sn_width); |
| 381 | − set_last_slot_field(usage, td, hi); | |
| 392 | + mt_store_field(usage, td, hi); | |
| 382 | 393 | td->last_field_index = field->index; |
| 383 | 394 | return 1; |
| 384 | 395 | case HID_DG_HEIGHT: |
| @@ -388,7 +399,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 3 unmodified lines | ||
| 388 | 399 | cls->sn_height); |
| 389 | 400 | input_set_abs_params(hi->input, |
| 390 | 401 | ABS_MT_ORIENTATION, 0, 1, 0, 0); |
| 391 | − set_last_slot_field(usage, td, hi); | |
| 402 | + mt_store_field(usage, td, hi); | |
| 392 | 403 | td->last_field_index = field->index; |
| 393 | 404 | return 1; |
| 394 | 405 | case HID_DG_TIPPRESSURE: |
| @@ -399,7 +410,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, · 4 unmodified lines | ||
| 399 | 410 | /* touchscreen emulation */ |
| 400 | 411 | set_abs(hi->input, ABS_PRESSURE, field, |
| 401 | 412 | cls->sn_pressure); |
| 402 | − set_last_slot_field(usage, td, hi); | |
| 413 | + mt_store_field(usage, td, hi); | |
| 403 | 414 | td->last_field_index = field->index; |
| 404 | 415 | return 1; |
| 405 | 416 | case HID_DG_CONTACTCOUNT: |
| @@ -653,6 +664,16 @@ static void mt_post_parse_default_settings(struct mt_device *td) · 247 unmodified lines | ||
| 653 | 664 | td->mtclass.quirks = quirks; |
| 654 | 665 | } |
| 655 | 666 | |
| 667 | +static void mt_post_parse(struct mt_device *td) | |
| 668 | +{ | |
| 669 | + struct mt_fields *f = td->fields; | |
| 670 | + | |
| 671 | + if (td->touches_by_report > 0) { | |
| 672 | + int field_count_per_touch = f->length / td->touches_by_report; | |
| 673 | + td->last_slot_field = f->usages[field_count_per_touch - 1]; | |
| 674 | + } | |
| 675 | +} | |
| 676 | + | |
| 656 | 677 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 657 | 678 | { |
| 658 | 679 | int ret, i; |
| @@ -683,6 +704,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) · 24 unmodified lines | ||
| 683 | 704 | td->maxcontact_report_id = -1; |
| 684 | 705 | hid_set_drvdata(hdev, td); |
| 685 | 706 | |
| 707 | + td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL); | |
| 708 | + if (!td->fields) { | |
| 709 | + dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); | |
| 710 | + ret = -ENOMEM; | |
| 711 | + goto fail; | |
| 712 | + } | |
| 713 | + | |
| 686 | 714 | ret = hid_parse(hdev); |
| 687 | 715 | if (ret != 0) |
| 688 | 716 | goto fail; |
| @@ -691,6 +719,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) · 2 unmodified lines | ||
| 691 | 719 | if (ret) |
| 692 | 720 | goto fail; |
| 693 | 721 | |
| 722 | + mt_post_parse(td); | |
| 723 | + | |
| 694 | 724 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) |
| 695 | 725 | mt_post_parse_default_settings(td); |
| 696 | 726 | |
| @@ -708,9 +738,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) · 11 unmodified lines | ||
| 708 | 738 | mt_set_maxcontacts(hdev); |
| 709 | 739 | mt_set_input_mode(hdev); |
| 710 | 740 | |
| 741 | + kfree(td->fields); | |
| 742 | + td->fields = NULL; | |
| 743 | + | |
| 711 | 744 | return 0; |
| 712 | 745 | |
| 713 | 746 | fail: |
| 747 | + kfree(td->fields); | |
| 714 | 748 | kfree(td); |
| 715 | 749 | return ret; |
| 716 | 750 | } |