From: Sergei Kolzun Date: Thu, 4 Aug 2011 07:25:57 +0000 (-0700) Subject: HID: ACRUX - handle gamepads with different report layout X-Git-Tag: v3.2-rc1~187^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b55ebc27b0a54ff4cdbfdcb218a85f96e502db3c;p=platform%2Fkernel%2Flinux-exynos.git HID: ACRUX - handle gamepads with different report layout There are gamepads that share the same VID and PID but have different report structure - instead of having 4 fields with one value they have one field that can hold all 4 values. Make the driver cope with devices using both styles. Signed-off-by: Sergei Kolzun Signed-off-by: Dmitry Torokhov Signed-off-by: Jiri Kosina --- diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c index 1215141..3bdb450 100644 --- a/drivers/hid/hid-axff.c +++ b/drivers/hid/hid-axff.c @@ -6,7 +6,7 @@ * Xbox 360 controller. * * 1a34:0802 "ACRUX USB GAMEPAD 8116" - * - tested with a EXEQ EQ-PCU-02090 game controller. + * - tested with an EXEQ EQ-PCU-02090 game controller. * * Copyright (c) 2010 Sergei Kolzun */ @@ -45,7 +45,10 @@ static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect { struct hid_device *hid = input_get_drvdata(dev); struct axff_device *axff = data; + struct hid_report *report = axff->report; + int field_count = 0; int left, right; + int i, j; left = effect->u.rumble.strong_magnitude; right = effect->u.rumble.weak_magnitude; @@ -55,10 +58,14 @@ static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect left = left * 0xff / 0xffff; right = right * 0xff / 0xffff; - axff->report->field[0]->value[0] = left; - axff->report->field[1]->value[0] = right; - axff->report->field[2]->value[0] = left; - axff->report->field[3]->value[0] = right; + for (i = 0; i < report->maxfield; i++) { + for (j = 0; j < report->field[i]->report_count; j++) { + report->field[i]->value[j] = + field_count % 2 ? right : left; + field_count++; + } + } + dbg_hid("running with 0x%02x 0x%02x", left, right); usbhid_submit_report(hid, axff->report, USB_DIR_OUT); @@ -72,6 +79,8 @@ static int axff_init(struct hid_device *hid) struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list); struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list; struct input_dev *dev = hidinput->input; + int field_count = 0; + int i, j; int error; if (list_empty(report_list)) { @@ -80,9 +89,16 @@ static int axff_init(struct hid_device *hid) } report = list_first_entry(report_list, struct hid_report, list); + for (i = 0; i < report->maxfield; i++) { + for (j = 0; j < report->field[i]->report_count; j++) { + report->field[i]->value[j] = 0x00; + field_count++; + } + } - if (report->maxfield < 4) { - hid_err(hid, "no fields in the report: %d\n", report->maxfield); + if (field_count < 4) { + hid_err(hid, "not enough fields in the report: %d\n", + field_count); return -ENODEV; } @@ -97,13 +113,9 @@ static int axff_init(struct hid_device *hid) goto err_free_mem; axff->report = report; - axff->report->field[0]->value[0] = 0x00; - axff->report->field[1]->value[0] = 0x00; - axff->report->field[2]->value[0] = 0x00; - axff->report->field[3]->value[0] = 0x00; usbhid_submit_report(hid, axff->report, USB_DIR_OUT); - hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun\n"); + hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun \n"); return 0;