diff options
| -rw-r--r-- | drivers/hid/hid-lg.c | 55 | ||||
| -rw-r--r-- | drivers/hid/hid-lg.h | 5 | ||||
| -rw-r--r-- | drivers/hid/hid-lg4ff.c | 258 | ||||
| -rw-r--r-- | drivers/hid/hid-multitouch.c | 58 |
4 files changed, 287 insertions, 89 deletions
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c index e7a7bd1eb34a..fc37ed6b108c 100644 --- a/drivers/hid/hid-lg.c +++ b/drivers/hid/hid-lg.c | |||
| @@ -109,23 +109,23 @@ static __u8 dfp_rdesc_fixed[] = { | |||
| 109 | static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, | 109 | static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 110 | unsigned int *rsize) | 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 | rdesc[84] == 0x8c && rdesc[85] == 0x02) { | 115 | rdesc[84] == 0x8c && rdesc[85] == 0x02) { |
| 116 | hid_info(hdev, | 116 | hid_info(hdev, |
| 117 | "fixing up Logitech keyboard report descriptor\n"); | 117 | "fixing up Logitech keyboard report descriptor\n"); |
| 118 | rdesc[84] = rdesc[89] = 0x4d; | 118 | rdesc[84] = rdesc[89] = 0x4d; |
| 119 | rdesc[85] = rdesc[90] = 0x10; | 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 | rdesc[32] == 0x81 && rdesc[33] == 0x06 && | 122 | rdesc[32] == 0x81 && rdesc[33] == 0x06 && |
| 123 | rdesc[49] == 0x81 && rdesc[50] == 0x06) { | 123 | rdesc[49] == 0x81 && rdesc[50] == 0x06) { |
| 124 | hid_info(hdev, | 124 | hid_info(hdev, |
| 125 | "fixing up rel/abs in Logitech report descriptor\n"); | 125 | "fixing up rel/abs in Logitech report descriptor\n"); |
| 126 | rdesc[33] = rdesc[50] = 0x02; | 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 | rdesc[41] == 0x95 && rdesc[42] == 0x0B && | 129 | rdesc[41] == 0x95 && rdesc[42] == 0x0B && |
| 130 | rdesc[47] == 0x05 && rdesc[48] == 0x09) { | 130 | rdesc[47] == 0x05 && rdesc[48] == 0x09) { |
| 131 | hid_info(hdev, "fixing up Logitech Speed Force Wireless button descriptor\n"); | 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, | |||
| 278 | 0, 0, 0, 0, 0,183,184,185,186,187, | 278 | 0, 0, 0, 0, 0,183,184,185,186,187, |
| 279 | 188,189,190,191,192,193,194, 0, 0, 0 | 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 | unsigned int hid = usage->hid; | 282 | unsigned int hid = usage->hid; |
| 283 | 283 | ||
| 284 | if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER && | 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, | |||
| 289 | lg_dinovo_mapping(hi, usage, bit, max)) | 289 | lg_dinovo_mapping(hi, usage, bit, max)) |
| 290 | return 1; | 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 | return 1; | 293 | return 1; |
| 294 | 294 | ||
| 295 | if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON) | 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, | |||
| 299 | 299 | ||
| 300 | /* Special handling for Logitech Cordless Desktop */ | 300 | /* Special handling for Logitech Cordless Desktop */ |
| 301 | if (field->application == HID_GD_MOUSE) { | 301 | if (field->application == HID_GD_MOUSE) { |
| 302 | if ((quirks & LG_IGNORE_DOUBLED_WHEEL) && | 302 | if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) && |
| 303 | (hid == 7 || hid == 8)) | 303 | (hid == 7 || hid == 8)) |
| 304 | return -1; | 304 | return -1; |
| 305 | } else { | 305 | } else { |
| 306 | if ((quirks & LG_EXPANDED_KEYMAP) && | 306 | if ((drv_data->quirks & LG_EXPANDED_KEYMAP) && |
| 307 | hid < ARRAY_SIZE(e_keymap) && | 307 | hid < ARRAY_SIZE(e_keymap) && |
| 308 | e_keymap[hid] != 0) { | 308 | e_keymap[hid] != 0) { |
| 309 | hid_map_usage(hi, usage, bit, max, EV_KEY, | 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, | |||
| 319 | struct hid_field *field, struct hid_usage *usage, | 319 | struct hid_field *field, struct hid_usage *usage, |
| 320 | unsigned long **bit, int *max) | 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 | (field->flags & HID_MAIN_ITEM_RELATIVE)) | 325 | (field->flags & HID_MAIN_ITEM_RELATIVE)) |
| 326 | field->flags &= ~HID_MAIN_ITEM_RELATIVE; | 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 | usage->type == EV_REL || usage->type == EV_ABS)) | 329 | usage->type == EV_REL || usage->type == EV_ABS)) |
| 330 | clear_bit(usage->code, *bit); | 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, | |||
| 335 | static int lg_event(struct hid_device *hdev, struct hid_field *field, | 335 | static int lg_event(struct hid_device *hdev, struct hid_field *field, |
| 336 | struct hid_usage *usage, __s32 value) | 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 | input_event(field->hidinput->input, usage->type, usage->code, | 341 | input_event(field->hidinput->input, usage->type, usage->code, |
| 342 | -value); | 342 | -value); |
| 343 | return 1; | 343 | return 1; |
| @@ -348,13 +348,20 @@ static int lg_event(struct hid_device *hdev, struct hid_field *field, | |||
| 348 | 348 | ||
| 349 | static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | 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 | unsigned int connect_mask = HID_CONNECT_DEFAULT; | 351 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
| 352 | struct lg_drv_data *drv_data; | ||
| 353 | int ret; | 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 | hdev->quirks |= HID_QUIRK_NOGET; | 365 | hdev->quirks |= HID_QUIRK_NOGET; |
| 359 | 366 | ||
| 360 | ret = hid_parse(hdev); | 367 | ret = hid_parse(hdev); |
| @@ -363,7 +370,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 363 | goto err_free; | 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 | connect_mask &= ~HID_CONNECT_FF; | 374 | connect_mask &= ~HID_CONNECT_FF; |
| 368 | 375 | ||
| 369 | ret = hid_hw_start(hdev, connect_mask); | 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) | |||
| 392 | } | 399 | } |
| 393 | } | 400 | } |
| 394 | 401 | ||
| 395 | if (quirks & LG_FF) | 402 | if (drv_data->quirks & LG_FF) |
| 396 | lgff_init(hdev); | 403 | lgff_init(hdev); |
| 397 | if (quirks & LG_FF2) | 404 | if (drv_data->quirks & LG_FF2) |
| 398 | lg2ff_init(hdev); | 405 | lg2ff_init(hdev); |
| 399 | if (quirks & LG_FF3) | 406 | if (drv_data->quirks & LG_FF3) |
| 400 | lg3ff_init(hdev); | 407 | lg3ff_init(hdev); |
| 401 | if (quirks & LG_FF4) | 408 | if (drv_data->quirks & LG_FF4) |
| 402 | lg4ff_init(hdev); | 409 | lg4ff_init(hdev); |
| 403 | 410 | ||
| 404 | return 0; | 411 | return 0; |
| 405 | err_free: | 412 | err_free: |
| 413 | kfree(drv_data); | ||
| 406 | return ret; | 414 | return ret; |
| 407 | } | 415 | } |
| 408 | 416 | ||
| 409 | static void lg_remove(struct hid_device *hdev) | 417 | static void lg_remove(struct hid_device *hdev) |
| 410 | { | 418 | { |
| 411 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | 419 | struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); |
| 412 | if(quirks & LG_FF4) | 420 | if (drv_data->quirks & LG_FF4) |
| 413 | lg4ff_deinit(hdev); | 421 | lg4ff_deinit(hdev); |
| 414 | 422 | ||
| 415 | hid_hw_stop(hdev); | 423 | hid_hw_stop(hdev); |
| 424 | kfree(drv_data); | ||
| 416 | } | 425 | } |
| 417 | 426 | ||
| 418 | static const struct hid_device_id lg_devices[] = { | 427 | static const struct hid_device_id lg_devices[] = { |
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h index 4b097286dc78..d64cf8d2751e 100644 --- a/drivers/hid/hid-lg.h +++ b/drivers/hid/hid-lg.h | |||
| @@ -1,6 +1,11 @@ | |||
| 1 | #ifndef __HID_LG_H | 1 | #ifndef __HID_LG_H |
| 2 | #define __HID_LG_H | 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 | #ifdef CONFIG_LOGITECH_FF | 9 | #ifdef CONFIG_LOGITECH_FF |
| 5 | int lgff_init(struct hid_device *hdev); | 10 | int lgff_init(struct hid_device *hdev); |
| 6 | #else | 11 | #else |
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 6ecc9e220440..f3390ee6105c 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c | |||
| @@ -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 | * Copyright (c) 2010 Simon Wood <simon@mungewell.org> | 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 | |||
| 51 | 52 | ||
| 52 | static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store); | 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 | struct lg4ff_device_entry { | 55 | struct lg4ff_device_entry { |
| 57 | char *device_id; /* Use name in respective kobject structure's address as the ID */ | ||
| 58 | __u16 range; | 56 | __u16 range; |
| 59 | __u16 min_range; | 57 | __u16 min_range; |
| 60 | __u16 max_range; | 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 | struct list_head list; | 63 | struct list_head list; |
| 63 | void (*set_range)(struct hid_device *hid, u16 range); | 64 | void (*set_range)(struct hid_device *hid, u16 range); |
| 64 | }; | 65 | }; |
| 65 | 66 | ||
| 66 | static struct lg4ff_device_entry device_list; | ||
| 67 | |||
| 68 | static const signed short lg4ff_wheel_effects[] = { | 67 | static const signed short lg4ff_wheel_effects[] = { |
| 69 | FF_CONSTANT, | 68 | FF_CONSTANT, |
| 70 | FF_AUTOCENTER, | 69 | FF_AUTOCENTER, |
| @@ -285,18 +284,20 @@ static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_n | |||
| 285 | /* Read current range and display it in terminal */ | 284 | /* Read current range and display it in terminal */ |
| 286 | static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, char *buf) | 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 | struct hid_device *hid = to_hid_device(dev); | 287 | struct hid_device *hid = to_hid_device(dev); |
| 288 | struct lg4ff_device_entry *entry; | ||
| 289 | struct lg_drv_data *drv_data; | ||
| 291 | size_t count; | 290 | size_t count; |
| 292 | 291 | ||
| 293 | list_for_each(h, &device_list.list) { | 292 | drv_data = hid_get_drvdata(hid); |
| 294 | entry = list_entry(h, struct lg4ff_device_entry, list); | 293 | if (!drv_data) { |
| 295 | if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | 294 | hid_err(hid, "Private driver data not found!\n"); |
| 296 | break; | 295 | return 0; |
| 297 | } | 296 | } |
| 298 | if (h == &device_list.list) { | 297 | |
| 299 | dbg_hid("Device not found!"); | 298 | entry = drv_data->device_props; |
| 299 | if (!entry) { | ||
| 300 | hid_err(hid, "Device properties not found!\n"); | ||
| 300 | return 0; | 301 | return 0; |
| 301 | } | 302 | } |
| 302 | 303 | ||
| @@ -308,19 +309,21 @@ static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *att | |||
| 308 | * according to the type of the wheel */ | 309 | * according to the type of the wheel */ |
| 309 | static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 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 | struct hid_device *hid = to_hid_device(dev); | 312 | struct hid_device *hid = to_hid_device(dev); |
| 313 | struct lg4ff_device_entry *entry; | ||
| 314 | struct lg_drv_data *drv_data; | ||
| 314 | __u16 range = simple_strtoul(buf, NULL, 10); | 315 | __u16 range = simple_strtoul(buf, NULL, 10); |
| 315 | 316 | ||
| 316 | list_for_each(h, &device_list.list) { | 317 | drv_data = hid_get_drvdata(hid); |
| 317 | entry = list_entry(h, struct lg4ff_device_entry, list); | 318 | if (!drv_data) { |
| 318 | if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) | 319 | hid_err(hid, "Private driver data not found!\n"); |
| 319 | break; | 320 | return 0; |
| 320 | } | 321 | } |
| 321 | if (h == &device_list.list) { | 322 | |
| 322 | dbg_hid("Device not found!"); | 323 | entry = drv_data->device_props; |
| 323 | return count; | 324 | if (!entry) { |
| 325 | hid_err(hid, "Device properties not found!\n"); | ||
| 326 | return 0; | ||
| 324 | } | 327 | } |
| 325 | 328 | ||
| 326 | if (range == 0) | 329 | if (range == 0) |
| @@ -336,6 +339,88 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at | |||
| 336 | return count; | 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 | int lg4ff_init(struct hid_device *hid) | 424 | int lg4ff_init(struct hid_device *hid) |
| 340 | { | 425 | { |
| 341 | struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); | 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) | |||
| 344 | struct hid_report *report; | 429 | struct hid_report *report; |
| 345 | struct hid_field *field; | 430 | struct hid_field *field; |
| 346 | struct lg4ff_device_entry *entry; | 431 | struct lg4ff_device_entry *entry; |
| 432 | struct lg_drv_data *drv_data; | ||
| 347 | struct usb_device_descriptor *udesc; | 433 | struct usb_device_descriptor *udesc; |
| 348 | int error, i, j; | 434 | int error, i, j; |
| 349 | __u16 bcdDevice, rev_maj, rev_min; | 435 | __u16 bcdDevice, rev_maj, rev_min; |
| @@ -423,28 +509,24 @@ int lg4ff_init(struct hid_device *hid) | |||
| 423 | dev->ff->set_autocenter(dev, 0); | 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 */ | 512 | /* Get private driver data */ |
| 427 | if (!list_inited) { | 513 | drv_data = hid_get_drvdata(hid); |
| 428 | INIT_LIST_HEAD(&device_list.list); | 514 | if (!drv_data) { |
| 429 | list_inited = 1; | 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 | entry = kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); | 520 | entry = kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); |
| 434 | if (!entry) { | 521 | if (!entry) { |
| 435 | hid_err(hid, "Cannot add device, insufficient memory.\n"); | 522 | hid_err(hid, "Cannot add device, insufficient memory to allocate device properties.\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); | ||
| 442 | return -ENOMEM; | 523 | return -ENOMEM; |
| 443 | } | 524 | } |
| 525 | drv_data->device_props = entry; | ||
| 526 | |||
| 444 | entry->min_range = lg4ff_devices[i].min_range; | 527 | entry->min_range = lg4ff_devices[i].min_range; |
| 445 | entry->max_range = lg4ff_devices[i].max_range; | 528 | entry->max_range = lg4ff_devices[i].max_range; |
| 446 | entry->set_range = lg4ff_devices[i].set_range; | 529 | entry->set_range = lg4ff_devices[i].set_range; |
| 447 | list_add(&entry->list, &device_list.list); | ||
| 448 | 530 | ||
| 449 | /* Create sysfs interface */ | 531 | /* Create sysfs interface */ |
| 450 | error = device_create_file(&hid->dev, &dev_attr_range); | 532 | error = device_create_file(&hid->dev, &dev_attr_range); |
| @@ -457,32 +539,100 @@ int lg4ff_init(struct hid_device *hid) | |||
| 457 | if (entry->set_range != NULL) | 539 | if (entry->set_range != NULL) |
| 458 | entry->set_range(hid, entry->range); | 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 | return 0; | 594 | return 0; |
| 462 | } | 595 | } |
| 463 | 596 | ||
| 464 | int lg4ff_deinit(struct hid_device *hid) | 597 | int lg4ff_deinit(struct hid_device *hid) |
| 465 | { | 598 | { |
| 466 | bool found = 0; | ||
| 467 | struct lg4ff_device_entry *entry; | 599 | struct lg4ff_device_entry *entry; |
| 468 | struct list_head *h, *g; | 600 | struct lg_drv_data *drv_data; |
| 469 | list_for_each_safe(h, g, &device_list.list) { | 601 | |
| 470 | entry = list_entry(h, struct lg4ff_device_entry, list); | 602 | device_remove_file(&hid->dev, &dev_attr_range); |
| 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 | } | ||
| 479 | 603 | ||
| 480 | if (!found) { | 604 | drv_data = hid_get_drvdata(hid); |
| 481 | dbg_hid("Device entry not found!\n"); | 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 | return -1; | 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 | dbg_hid("Device successfully unregistered\n"); | 636 | dbg_hid("Device successfully unregistered\n"); |
| 487 | return 0; | 637 | return 0; |
| 488 | } | 638 | } |
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 25b94253e68f..6e3332a99976 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
| @@ -70,9 +70,16 @@ struct mt_class { | |||
| 70 | bool is_indirect; /* true for touchpads */ | 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 | struct mt_device { | 78 | struct mt_device { |
| 74 | struct mt_slot curdata; /* placeholder of incoming data */ | 79 | struct mt_slot curdata; /* placeholder of incoming data */ |
| 75 | struct mt_class mtclass; /* our mt device class */ | 80 | struct mt_class mtclass; /* our mt device class */ |
| 81 | struct mt_fields *fields; /* temporary placeholder for storing the | ||
| 82 | multitouch fields */ | ||
| 76 | unsigned last_field_index; /* last field index of the report */ | 83 | unsigned last_field_index; /* last field index of the report */ |
| 77 | unsigned last_slot_field; /* the last field of a slot */ | 84 | unsigned last_slot_field; /* the last field of a slot */ |
| 78 | __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ | 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, | |||
| 278 | input_set_abs_params(input, code, fmin, fmax, fuzz, 0); | 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 | struct hid_input *hi) | 289 | struct hid_input *hi) |
| 283 | { | 290 | { |
| 284 | if (!test_bit(usage->hid, hi->input->absbit)) | 291 | struct mt_fields *f = td->fields; |
| 285 | td->last_slot_field = usage->hid; | 292 | |
| 293 | if (f->length >= HID_MAX_FIELDS) | ||
| 294 | return; | ||
| 295 | |||
| 296 | f->usages[f->length++] = usage->hid; | ||
| 286 | } | 297 | } |
| 287 | 298 | ||
| 288 | static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | 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, | |||
| 333 | cls->sn_move); | 344 | cls->sn_move); |
| 334 | /* touchscreen emulation */ | 345 | /* touchscreen emulation */ |
| 335 | set_abs(hi->input, ABS_X, field, cls->sn_move); | 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 | td->last_field_index = field->index; | 348 | td->last_field_index = field->index; |
| 338 | return 1; | 349 | return 1; |
| 339 | case HID_GD_Y: | 350 | case HID_GD_Y: |
| @@ -343,7 +354,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 343 | cls->sn_move); | 354 | cls->sn_move); |
| 344 | /* touchscreen emulation */ | 355 | /* touchscreen emulation */ |
| 345 | set_abs(hi->input, ABS_Y, field, cls->sn_move); | 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 | td->last_field_index = field->index; | 358 | td->last_field_index = field->index; |
| 348 | return 1; | 359 | return 1; |
| 349 | } | 360 | } |
| @@ -352,24 +363,24 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 352 | case HID_UP_DIGITIZER: | 363 | case HID_UP_DIGITIZER: |
| 353 | switch (usage->hid) { | 364 | switch (usage->hid) { |
| 354 | case HID_DG_INRANGE: | 365 | case HID_DG_INRANGE: |
| 355 | set_last_slot_field(usage, td, hi); | 366 | mt_store_field(usage, td, hi); |
| 356 | td->last_field_index = field->index; | 367 | td->last_field_index = field->index; |
| 357 | return 1; | 368 | return 1; |
| 358 | case HID_DG_CONFIDENCE: | 369 | case HID_DG_CONFIDENCE: |
| 359 | set_last_slot_field(usage, td, hi); | 370 | mt_store_field(usage, td, hi); |
| 360 | td->last_field_index = field->index; | 371 | td->last_field_index = field->index; |
| 361 | return 1; | 372 | return 1; |
| 362 | case HID_DG_TIPSWITCH: | 373 | case HID_DG_TIPSWITCH: |
| 363 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); | 374 | hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); |
| 364 | input_set_capability(hi->input, EV_KEY, BTN_TOUCH); | 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 | td->last_field_index = field->index; | 377 | td->last_field_index = field->index; |
| 367 | return 1; | 378 | return 1; |
| 368 | case HID_DG_CONTACTID: | 379 | case HID_DG_CONTACTID: |
| 369 | if (!td->maxcontacts) | 380 | if (!td->maxcontacts) |
| 370 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; | 381 | td->maxcontacts = MT_DEFAULT_MAXCONTACT; |
| 371 | input_mt_init_slots(hi->input, td->maxcontacts); | 382 | input_mt_init_slots(hi->input, td->maxcontacts); |
| 372 | td->last_slot_field = usage->hid; | 383 | mt_store_field(usage, td, hi); |
| 373 | td->last_field_index = field->index; | 384 | td->last_field_index = field->index; |
| 374 | td->touches_by_report++; | 385 | td->touches_by_report++; |
| 375 | return 1; | 386 | return 1; |
| @@ -378,7 +389,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 378 | EV_ABS, ABS_MT_TOUCH_MAJOR); | 389 | EV_ABS, ABS_MT_TOUCH_MAJOR); |
| 379 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, | 390 | set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, |
| 380 | cls->sn_width); | 391 | cls->sn_width); |
| 381 | set_last_slot_field(usage, td, hi); | 392 | mt_store_field(usage, td, hi); |
| 382 | td->last_field_index = field->index; | 393 | td->last_field_index = field->index; |
| 383 | return 1; | 394 | return 1; |
| 384 | case HID_DG_HEIGHT: | 395 | case HID_DG_HEIGHT: |
| @@ -388,7 +399,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 388 | cls->sn_height); | 399 | cls->sn_height); |
| 389 | input_set_abs_params(hi->input, | 400 | input_set_abs_params(hi->input, |
| 390 | ABS_MT_ORIENTATION, 0, 1, 0, 0); | 401 | ABS_MT_ORIENTATION, 0, 1, 0, 0); |
| 391 | set_last_slot_field(usage, td, hi); | 402 | mt_store_field(usage, td, hi); |
| 392 | td->last_field_index = field->index; | 403 | td->last_field_index = field->index; |
| 393 | return 1; | 404 | return 1; |
| 394 | case HID_DG_TIPPRESSURE: | 405 | case HID_DG_TIPPRESSURE: |
| @@ -399,7 +410,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
| 399 | /* touchscreen emulation */ | 410 | /* touchscreen emulation */ |
| 400 | set_abs(hi->input, ABS_PRESSURE, field, | 411 | set_abs(hi->input, ABS_PRESSURE, field, |
| 401 | cls->sn_pressure); | 412 | cls->sn_pressure); |
| 402 | set_last_slot_field(usage, td, hi); | 413 | mt_store_field(usage, td, hi); |
| 403 | td->last_field_index = field->index; | 414 | td->last_field_index = field->index; |
| 404 | return 1; | 415 | return 1; |
| 405 | case HID_DG_CONTACTCOUNT: | 416 | case HID_DG_CONTACTCOUNT: |
| @@ -653,6 +664,16 @@ static void mt_post_parse_default_settings(struct mt_device *td) | |||
| 653 | td->mtclass.quirks = quirks; | 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 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | 677 | static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 657 | { | 678 | { |
| 658 | int ret, i; | 679 | int ret, i; |
| @@ -683,6 +704,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 683 | td->maxcontact_report_id = -1; | 704 | td->maxcontact_report_id = -1; |
| 684 | hid_set_drvdata(hdev, td); | 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 | ret = hid_parse(hdev); | 714 | ret = hid_parse(hdev); |
| 687 | if (ret != 0) | 715 | if (ret != 0) |
| 688 | goto fail; | 716 | goto fail; |
| @@ -691,6 +719,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 691 | if (ret) | 719 | if (ret) |
| 692 | goto fail; | 720 | goto fail; |
| 693 | 721 | ||
| 722 | mt_post_parse(td); | ||
| 723 | |||
| 694 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) | 724 | if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) |
| 695 | mt_post_parse_default_settings(td); | 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) | |||
| 708 | mt_set_maxcontacts(hdev); | 738 | mt_set_maxcontacts(hdev); |
| 709 | mt_set_input_mode(hdev); | 739 | mt_set_input_mode(hdev); |
| 710 | 740 | ||
| 741 | kfree(td->fields); | ||
| 742 | td->fields = NULL; | ||
| 743 | |||
| 711 | return 0; | 744 | return 0; |
| 712 | 745 | ||
| 713 | fail: | 746 | fail: |
| 747 | kfree(td->fields); | ||
| 714 | kfree(td); | 748 | kfree(td); |
| 715 | return ret; | 749 | return ret; |
| 716 | } | 750 | } |
