From 8577dbf9d6eb07213caefb49e2017c177c5f023d Mon Sep 17 00:00:00 2001 From: Michal Malý Date: Sat, 31 Mar 2012 11:17:25 +0200 Subject: HID: hid-lg: Allow for custom device-specific properties to be stored in priv drvdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds support for custom device-specific properties which can now be stored as private driver data and read/saved using hid_get/set_drvdata(). Signed-off-by: Michal Malý Tested-by: simon@mungewell.org Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg.c | 55 ++++++++++++++++++++++++++++++---------------------- drivers/hid/hid-lg.h | 7 +++++++ 2 files changed, 39 insertions(+), 23 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[] = { static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); - if ((quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && + if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 && rdesc[84] == 0x8c && rdesc[85] == 0x02) { hid_info(hdev, "fixing up Logitech keyboard report descriptor\n"); rdesc[84] = rdesc[89] = 0x4d; rdesc[85] = rdesc[90] = 0x10; } - if ((quirks & LG_RDESC_REL_ABS) && *rsize >= 50 && + if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 && rdesc[32] == 0x81 && rdesc[33] == 0x06 && rdesc[49] == 0x81 && rdesc[50] == 0x06) { hid_info(hdev, "fixing up rel/abs in Logitech report descriptor\n"); rdesc[33] = rdesc[50] = 0x02; } - if ((quirks & LG_FF4) && *rsize >= 101 && + if ((drv_data->quirks & LG_FF4) && *rsize >= 101 && rdesc[41] == 0x95 && rdesc[42] == 0x0B && rdesc[47] == 0x05 && rdesc[48] == 0x09) { 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, 0, 0, 0, 0, 0,183,184,185,186,187, 188,189,190,191,192,193,194, 0, 0, 0 }; - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); unsigned int hid = usage->hid; 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, lg_dinovo_mapping(hi, usage, bit, max)) return 1; - if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max)) + if ((drv_data->quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max)) return 1; 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, /* Special handling for Logitech Cordless Desktop */ if (field->application == HID_GD_MOUSE) { - if ((quirks & LG_IGNORE_DOUBLED_WHEEL) && + if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) && (hid == 7 || hid == 8)) return -1; } else { - if ((quirks & LG_EXPANDED_KEYMAP) && + if ((drv_data->quirks & LG_EXPANDED_KEYMAP) && hid < ARRAY_SIZE(e_keymap) && e_keymap[hid] != 0) { 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, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); - if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && + if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY && (field->flags & HID_MAIN_ITEM_RELATIVE)) field->flags &= ~HID_MAIN_ITEM_RELATIVE; - if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY || + if ((drv_data->quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY || usage->type == EV_REL || usage->type == EV_ABS)) clear_bit(usage->code, *bit); @@ -335,9 +335,9 @@ static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi, static int lg_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); - if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { + if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) { input_event(field->hidinput->input, usage->type, usage->code, -value); return 1; @@ -348,13 +348,20 @@ static int lg_event(struct hid_device *hdev, struct hid_field *field, static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) { - unsigned long quirks = id->driver_data; unsigned int connect_mask = HID_CONNECT_DEFAULT; + struct lg_drv_data *drv_data; int ret; - hid_set_drvdata(hdev, (void *)quirks); + drv_data = kzalloc(sizeof(struct lg_drv_data), GFP_KERNEL); + if (!drv_data) { + hid_err(hdev, "Insufficient memory, cannot allocate driver data\n"); + return -ENOMEM; + } + drv_data->quirks = id->driver_data; + + hid_set_drvdata(hdev, (void *)drv_data); - if (quirks & LG_NOGET) + if (drv_data->quirks & LG_NOGET) hdev->quirks |= HID_QUIRK_NOGET; ret = hid_parse(hdev); @@ -363,7 +370,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) goto err_free; } - if (quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4)) + if (drv_data->quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4)) connect_mask &= ~HID_CONNECT_FF; 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) } } - if (quirks & LG_FF) + if (drv_data->quirks & LG_FF) lgff_init(hdev); - if (quirks & LG_FF2) + if (drv_data->quirks & LG_FF2) lg2ff_init(hdev); - if (quirks & LG_FF3) + if (drv_data->quirks & LG_FF3) lg3ff_init(hdev); - if (quirks & LG_FF4) + if (drv_data->quirks & LG_FF4) lg4ff_init(hdev); return 0; err_free: + kfree(drv_data); return ret; } static void lg_remove(struct hid_device *hdev) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); - if(quirks & LG_FF4) + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev); + if (drv_data->quirks & LG_FF4) lg4ff_deinit(hdev); hid_hw_stop(hdev); + kfree(drv_data); } static const struct hid_device_id lg_devices[] = { diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h index 4b097286dc78..500457b67b21 100644 --- a/drivers/hid/hid-lg.h +++ b/drivers/hid/hid-lg.h @@ -1,6 +1,13 @@ #ifndef __HID_LG_H #define __HID_LG_H +#include + +struct lg_drv_data { + unsigned long quirks; + void *device_props; /* Device specific properties */ +}; + #ifdef CONFIG_LOGITECH_FF int lgff_init(struct hid_device *hdev); #else -- cgit v1.2.3 From 6a2e176b2d6ae6bb528c0c1a50a6332e176cda12 Mon Sep 17 00:00:00 2001 From: Michal Malý Date: Sat, 31 Mar 2012 11:35:05 +0200 Subject: HID: lg4ff: Remove sysfs iface before deallocating memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes a possible race condition caused by the sysfs interface being removed after the memory used by the interface was already kfree'd. Signed-off-by: Michal Malý Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg.h | 2 -- drivers/hid/hid-lg4ff.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h index 500457b67b21..d64cf8d2751e 100644 --- a/drivers/hid/hid-lg.h +++ b/drivers/hid/hid-lg.h @@ -1,8 +1,6 @@ #ifndef __HID_LG_H #define __HID_LG_H -#include - struct lg_drv_data { unsigned long quirks; void *device_props; /* Device specific properties */ diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 6ecc9e220440..11452920a6c3 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -466,6 +466,9 @@ int lg4ff_deinit(struct hid_device *hid) bool found = 0; struct lg4ff_device_entry *entry; struct list_head *h, *g; + + device_remove_file(&hid->dev, &dev_attr_range); + list_for_each_safe(h, g, &device_list.list) { entry = list_entry(h, struct lg4ff_device_entry, list); if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) { @@ -478,11 +481,10 @@ int lg4ff_deinit(struct hid_device *hid) } if (!found) { - dbg_hid("Device entry not found!\n"); + hid_err(hid, "Device entry not found!\n"); return -1; } - device_remove_file(&hid->dev, &dev_attr_range); dbg_hid("Device successfully unregistered\n"); return 0; } -- cgit v1.2.3 From 3b6b17b7330c0fab7d8442b6d225bee905df3745 Mon Sep 17 00:00:00 2001 From: Michal Malý Date: Mon, 9 Apr 2012 09:08:49 +0200 Subject: HID: lg4ff: Take advantage of private driver data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lg4ff now calls hid_get/set_drvdata() to read or store device configuration. Signed-off-by: Michal Malý Tested-by: Simon Wood Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 92 ++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 11452920a6c3..32c173fcb7f8 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -51,10 +51,7 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at static DEVICE_ATTR(range, S_IRWXU | S_IRWXG | S_IRWXO, lg4ff_range_show, lg4ff_range_store); -static bool list_inited; - struct lg4ff_device_entry { - char *device_id; /* Use name in respective kobject structure's address as the ID */ __u16 range; __u16 min_range; __u16 max_range; @@ -63,8 +60,6 @@ struct lg4ff_device_entry { void (*set_range)(struct hid_device *hid, u16 range); }; -static struct lg4ff_device_entry device_list; - static const signed short lg4ff_wheel_effects[] = { FF_CONSTANT, FF_AUTOCENTER, @@ -285,18 +280,20 @@ static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_n /* Read current range and display it in terminal */ static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct lg4ff_device_entry *uninitialized_var(entry); - struct list_head *h; struct hid_device *hid = to_hid_device(dev); + struct lg4ff_device_entry *entry; + struct lg_drv_data *drv_data; size_t count; - list_for_each(h, &device_list.list) { - entry = list_entry(h, struct lg4ff_device_entry, list); - if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) - break; + drv_data = hid_get_drvdata(hid); + if (!drv_data) { + hid_err(hid, "Private driver data not found!\n"); + return 0; } - if (h == &device_list.list) { - dbg_hid("Device not found!"); + + entry = drv_data->device_props; + if (!entry) { + hid_err(hid, "Device properties not found!\n"); return 0; } @@ -308,19 +305,21 @@ static ssize_t lg4ff_range_show(struct device *dev, struct device_attribute *att * according to the type of the wheel */ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct lg4ff_device_entry *uninitialized_var(entry); - struct list_head *h; struct hid_device *hid = to_hid_device(dev); + struct lg4ff_device_entry *entry; + struct lg_drv_data *drv_data; __u16 range = simple_strtoul(buf, NULL, 10); - list_for_each(h, &device_list.list) { - entry = list_entry(h, struct lg4ff_device_entry, list); - if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) - break; + drv_data = hid_get_drvdata(hid); + if (!drv_data) { + hid_err(hid, "Private driver data not found!\n"); + return 0; } - if (h == &device_list.list) { - dbg_hid("Device not found!"); - return count; + + entry = drv_data->device_props; + if (!entry) { + hid_err(hid, "Device properties not found!\n"); + return 0; } if (range == 0) @@ -344,6 +343,7 @@ int lg4ff_init(struct hid_device *hid) struct hid_report *report; struct hid_field *field; struct lg4ff_device_entry *entry; + struct lg_drv_data *drv_data; struct usb_device_descriptor *udesc; int error, i, j; __u16 bcdDevice, rev_maj, rev_min; @@ -423,28 +423,24 @@ int lg4ff_init(struct hid_device *hid) dev->ff->set_autocenter(dev, 0); } - /* Initialize device_list if this is the first device to handle by lg4ff */ - if (!list_inited) { - INIT_LIST_HEAD(&device_list.list); - list_inited = 1; + /* Get private driver data */ + drv_data = hid_get_drvdata(hid); + if (!drv_data) { + hid_err(hid, "Cannot add device, private driver data not allocated\n"); + return -1; } - /* Add the device to device_list */ + /* Initialize device properties */ entry = kzalloc(sizeof(struct lg4ff_device_entry), GFP_KERNEL); if (!entry) { - hid_err(hid, "Cannot add device, insufficient memory.\n"); - return -ENOMEM; - } - entry->device_id = kstrdup((&hid->dev)->kobj.name, GFP_KERNEL); - if (!entry->device_id) { - hid_err(hid, "Cannot set device_id, insufficient memory.\n"); - kfree(entry); + hid_err(hid, "Cannot add device, insufficient memory to allocate device properties.\n"); return -ENOMEM; } + drv_data->device_props = entry; + entry->min_range = lg4ff_devices[i].min_range; entry->max_range = lg4ff_devices[i].max_range; entry->set_range = lg4ff_devices[i].set_range; - list_add(&entry->list, &device_list.list); /* Create sysfs interface */ error = device_create_file(&hid->dev, &dev_attr_range); @@ -463,27 +459,23 @@ int lg4ff_init(struct hid_device *hid) int lg4ff_deinit(struct hid_device *hid) { - bool found = 0; struct lg4ff_device_entry *entry; - struct list_head *h, *g; - + struct lg_drv_data *drv_data; + device_remove_file(&hid->dev, &dev_attr_range); - list_for_each_safe(h, g, &device_list.list) { - entry = list_entry(h, struct lg4ff_device_entry, list); - if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) { - list_del(h); - kfree(entry->device_id); - kfree(entry); - found = 1; - break; - } + drv_data = hid_get_drvdata(hid); + if (!drv_data) { + hid_err(hid, "Error while deinitializing device, no private driver data.\n"); + return -1; } - - if (!found) { - hid_err(hid, "Device entry not found!\n"); + entry = drv_data->device_props; + if (!entry) { + hid_err(hid, "Error while deinitializing device, no device properties data.\n"); return -1; } + /* Deallocate memory */ + kfree(entry); dbg_hid("Device successfully unregistered\n"); return 0; -- cgit v1.2.3 From 22bcefdc8838186f2253edbfd4a0c22cb85d030e Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Sat, 21 Apr 2012 05:41:15 -0700 Subject: HID: hid-lg4ff: Add support for G27 LEDs This patch adds supports for controlling the LED 'tachometer' on the G27 wheel, via the LED subsystem. The 5 LEDs are arranged from right (1=grn, 2=grn, 3=yel, 4=yel, 5=red) and 'mirrored' to the left (10 LEDs in total). Signed-off-by: Simon Wood Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 32c173fcb7f8..1e942a014038 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -55,7 +55,10 @@ struct lg4ff_device_entry { __u16 range; __u16 min_range; __u16 max_range; - __u8 leds; +#ifdef CONFIG_LEDS_CLASS + __u8 led_state; + struct led_classdev *led[5]; +#endif struct list_head list; void (*set_range)(struct hid_device *hid, u16 range); }; @@ -335,6 +338,88 @@ static ssize_t lg4ff_range_store(struct device *dev, struct device_attribute *at return count; } +#ifdef CONFIG_LEDS_CLASS +static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) +{ + struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; + struct hid_report *report = list_entry(report_list->next, struct hid_report, list); + + report->field[0]->value[0] = 0xf8; + report->field[0]->value[1] = 0x12; + report->field[0]->value[2] = leds; + report->field[0]->value[3] = 0x00; + report->field[0]->value[4] = 0x00; + report->field[0]->value[5] = 0x00; + report->field[0]->value[6] = 0x00; + usbhid_submit_report(hid, report, USB_DIR_OUT); +} + +static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct device *dev = led_cdev->dev->parent; + struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); + struct lg4ff_device_entry *entry; + int i, state = 0; + + if (!drv_data) { + hid_err(hid, "Device data not found."); + return; + } + + entry = (struct lg4ff_device_entry *)drv_data->device_props; + + if (!entry) { + hid_err(hid, "Device properties not found."); + return; + } + + for (i = 0; i < 5; i++) { + if (led_cdev != entry->led[i]) + continue; + state = (entry->led_state >> i) & 1; + if (value == LED_OFF && state) { + entry->led_state &= ~(1 << i); + lg4ff_set_leds(hid, entry->led_state); + } else if (value != LED_OFF && !state) { + entry->led_state |= 1 << i; + lg4ff_set_leds(hid, entry->led_state); + } + break; + } +} + +static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev) +{ + struct device *dev = led_cdev->dev->parent; + struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hid); + struct lg4ff_device_entry *entry; + int i, value = 0; + + if (!drv_data) { + hid_err(hid, "Device data not found."); + return LED_OFF; + } + + entry = (struct lg4ff_device_entry *)drv_data->device_props; + + if (!entry) { + hid_err(hid, "Device properties not found."); + return LED_OFF; + } + + for (i = 0; i < 5; i++) + if (led_cdev == entry->led[i]) { + value = (entry->led_state >> i) & 1; + break; + } + + return value ? LED_FULL : LED_OFF; +} +#endif + int lg4ff_init(struct hid_device *hid) { struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); @@ -453,6 +538,58 @@ int lg4ff_init(struct hid_device *hid) if (entry->set_range != NULL) entry->set_range(hid, entry->range); +#ifdef CONFIG_LEDS_CLASS + /* register led subsystem - G27 only */ + entry->led_state = 0; + for (j = 0; j < 5; j++) + entry->led[j] = NULL; + + if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_G27_WHEEL) { + struct led_classdev *led; + size_t name_sz; + char *name; + + lg4ff_set_leds(hid, 0); + + name_sz = strlen(dev_name(&hid->dev)) + 8; + + for (j = 0; j < 5; j++) { + led = kzalloc(sizeof(struct led_classdev)+name_sz, GFP_KERNEL); + if (!led) { + hid_err(hid, "can't allocate memory for LED %d\n", j); + goto err; + } + + name = (void *)(&led[1]); + snprintf(name, name_sz, "%s::RPM%d", dev_name(&hid->dev), j+1); + led->name = name; + led->brightness = 0; + led->max_brightness = 1; + led->brightness_get = lg4ff_led_get_brightness; + led->brightness_set = lg4ff_led_set_brightness; + + entry->led[j] = led; + error = led_classdev_register(&hid->dev, led); + + if (error) { + hid_err(hid, "failed to register LED %d. Aborting.\n", j); +err: + /* Deregister LEDs (if any) */ + for (j = 0; j < 5; j++) { + led = entry->led[j]; + entry->led[j] = NULL; + if (!led) + continue; + led_classdev_unregister(led); + kfree(led); + } + goto out; /* Let the driver continue without LEDs */ + } + } + } +#endif + +out: hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood \n"); return 0; } @@ -474,6 +611,25 @@ int lg4ff_deinit(struct hid_device *hid) hid_err(hid, "Error while deinitializing device, no device properties data.\n"); return -1; } + +#ifdef CONFIG_LEDS_CLASS + { + int j; + struct led_classdev *led; + + /* Deregister LEDs (if any) */ + for (j = 0; j < 5; j++) { + + led = entry->led[j]; + entry->led[j] = NULL; + if (!led) + continue; + led_classdev_unregister(led); + kfree(led); + } + } +#endif + /* Deallocate memory */ kfree(entry); -- cgit v1.2.3 From 6401380086eda2278a67f0c08ef783008d940f73 Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Sat, 21 Apr 2012 05:41:16 -0700 Subject: HID: hid-lg4ff: Update Comments Updated comments to say that this driver now supports all Logitech gaming wheels, and not just the WiiWheel. Signed-off-by: Simon Wood Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 1e942a014038..24cf0379f800 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -1,7 +1,8 @@ /* - * Force feedback support for Logitech Speed Force Wireless + * Force feedback support for Logitech Gaming Wheels * - * http://wiibrew.org/wiki/Logitech_USB_steering_wheel + * Including G27, G25, DFP, DFGT, FFEX, Momo, Momo2 & + * Speed Force Wireless (WiiWheel) * * Copyright (c) 2010 Simon Wood */ @@ -590,7 +591,7 @@ err: #endif out: - hid_info(hid, "Force feedback for Logitech Speed Force Wireless by Simon Wood \n"); + hid_info(hid, "Force feedback support for Logitech Gaming Wheels\n"); return 0; } -- cgit v1.2.3 From c6e6dc87b306b897abc8a8b1c6ca05aa72317249 Mon Sep 17 00:00:00 2001 From: Jiri Kosina Date: Mon, 23 Apr 2012 21:08:15 +0200 Subject: HID: hid-lg4ff: remove unused label in !LEDS_CLASS case 'out' label will be unused of CONFIG_LEDS_CLASS is unset. Move it into conditional block. Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 24cf0379f800..f3390ee6105c 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -588,9 +588,8 @@ err: } } } -#endif - out: +#endif hid_info(hid, "Force feedback support for Logitech Gaming Wheels\n"); return 0; } -- cgit v1.2.3 From 3ac36d15557d1bedfb1151d9911b9587b2d40759 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 4 May 2012 14:53:46 +0200 Subject: HID: hid-multitouch: fix wrong protocol detection The previous implementation introduced a randomness in the splitting of the different touches reported by the device. This version is more robust as we don't rely on hi->input->absbit, but on our own structure. This also prepares hid-multitouch to better support Win8 devices. [Jiri Kosina : fix build] Signed-off-by: Benjamin Tissoires Acked-by: Henrik Rydberg Signed-off-by: Jiri Kosina --- drivers/hid/hid-multitouch.c | 58 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) 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 { bool is_indirect; /* true for touchpads */ }; +struct mt_fields { + unsigned usages[HID_MAX_FIELDS]; + unsigned int length; +}; + struct mt_device { struct mt_slot curdata; /* placeholder of incoming data */ struct mt_class mtclass; /* our mt device class */ + struct mt_fields *fields; /* temporary placeholder for storing the + multitouch fields */ unsigned last_field_index; /* last field index of the report */ unsigned last_slot_field; /* the last field of a slot */ __s8 inputmode; /* InputMode HID feature, -1 if non-existent */ @@ -278,11 +285,15 @@ static void set_abs(struct input_dev *input, unsigned int code, input_set_abs_params(input, code, fmin, fmax, fuzz, 0); } -static void set_last_slot_field(struct hid_usage *usage, struct mt_device *td, +static void mt_store_field(struct hid_usage *usage, struct mt_device *td, struct hid_input *hi) { - if (!test_bit(usage->hid, hi->input->absbit)) - td->last_slot_field = usage->hid; + struct mt_fields *f = td->fields; + + if (f->length >= HID_MAX_FIELDS) + return; + + f->usages[f->length++] = usage->hid; } 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, cls->sn_move); /* touchscreen emulation */ set_abs(hi->input, ABS_X, field, cls->sn_move); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_GD_Y: @@ -343,7 +354,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, cls->sn_move); /* touchscreen emulation */ set_abs(hi->input, ABS_Y, field, cls->sn_move); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; } @@ -352,24 +363,24 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, case HID_UP_DIGITIZER: switch (usage->hid) { case HID_DG_INRANGE: - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_CONFIDENCE: - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_TIPSWITCH: hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH); input_set_capability(hi->input, EV_KEY, BTN_TOUCH); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_CONTACTID: if (!td->maxcontacts) td->maxcontacts = MT_DEFAULT_MAXCONTACT; input_mt_init_slots(hi->input, td->maxcontacts); - td->last_slot_field = usage->hid; + mt_store_field(usage, td, hi); td->last_field_index = field->index; td->touches_by_report++; return 1; @@ -378,7 +389,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, EV_ABS, ABS_MT_TOUCH_MAJOR); set_abs(hi->input, ABS_MT_TOUCH_MAJOR, field, cls->sn_width); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_HEIGHT: @@ -388,7 +399,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, cls->sn_height); input_set_abs_params(hi->input, ABS_MT_ORIENTATION, 0, 1, 0, 0); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_TIPPRESSURE: @@ -399,7 +410,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, /* touchscreen emulation */ set_abs(hi->input, ABS_PRESSURE, field, cls->sn_pressure); - set_last_slot_field(usage, td, hi); + mt_store_field(usage, td, hi); td->last_field_index = field->index; return 1; case HID_DG_CONTACTCOUNT: @@ -653,6 +664,16 @@ static void mt_post_parse_default_settings(struct mt_device *td) td->mtclass.quirks = quirks; } +static void mt_post_parse(struct mt_device *td) +{ + struct mt_fields *f = td->fields; + + if (td->touches_by_report > 0) { + int field_count_per_touch = f->length / td->touches_by_report; + td->last_slot_field = f->usages[field_count_per_touch - 1]; + } +} + static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret, i; @@ -683,6 +704,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) td->maxcontact_report_id = -1; hid_set_drvdata(hdev, td); + td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL); + if (!td->fields) { + dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); + ret = -ENOMEM; + goto fail; + } + ret = hid_parse(hdev); if (ret != 0) goto fail; @@ -691,6 +719,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) if (ret) goto fail; + mt_post_parse(td); + if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) mt_post_parse_default_settings(td); @@ -708,9 +738,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) mt_set_maxcontacts(hdev); mt_set_input_mode(hdev); + kfree(td->fields); + td->fields = NULL; + return 0; fail: + kfree(td->fields); kfree(td); return ret; } -- cgit v1.2.3