Commit 74479ba8 authored by Michal Malý's avatar Michal Malý Committed by Jiri Kosina

HID: hid-lg4ff: Minor code cleanup to improve readability

This patch replaces all occurrences of "report->field[0]->value[n]" with just
"value[n]" to get rid of the lengthy trains we have now.
Signed-off-by: default avatarMichal Malý <madcatxster@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent cead24c1
...@@ -134,6 +134,7 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e ...@@ -134,6 +134,7 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e
struct hid_device *hid = input_get_drvdata(dev); struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
int x; int x;
#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff #define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
...@@ -142,13 +143,13 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e ...@@ -142,13 +143,13 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e
case FF_CONSTANT: case FF_CONSTANT:
x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */
CLAMP(x); CLAMP(x);
report->field[0]->value[0] = 0x11; /* Slot 1 */ value[0] = 0x11; /* Slot 1 */
report->field[0]->value[1] = 0x08; value[1] = 0x08;
report->field[0]->value[2] = x; value[2] = x;
report->field[0]->value[3] = 0x80; value[3] = 0x80;
report->field[0]->value[4] = 0x00; value[4] = 0x00;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
break; break;
...@@ -163,14 +164,15 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud ...@@ -163,14 +164,15 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud
struct hid_device *hid = input_get_drvdata(dev); struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
report->field[0]->value[0] = 0xfe; value[0] = 0xfe;
report->field[0]->value[1] = 0x0d; value[1] = 0x0d;
report->field[0]->value[2] = magnitude >> 13; value[2] = magnitude >> 13;
report->field[0]->value[3] = magnitude >> 13; value[3] = magnitude >> 13;
report->field[0]->value[4] = magnitude >> 8; value[4] = magnitude >> 8;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
} }
...@@ -181,16 +183,16 @@ static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude) ...@@ -181,16 +183,16 @@ static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude)
struct hid_device *hid = input_get_drvdata(dev); struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
magnitude = magnitude * 90 / 65535; magnitude = magnitude * 90 / 65535;
report->field[0]->value[0] = 0xfe; value[0] = 0xfe;
report->field[0]->value[1] = 0x03; value[1] = 0x03;
report->field[0]->value[2] = magnitude >> 14; value[2] = magnitude >> 14;
report->field[0]->value[3] = magnitude >> 14; value[3] = magnitude >> 14;
report->field[0]->value[4] = magnitude; value[4] = magnitude;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
} }
...@@ -200,15 +202,17 @@ static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range) ...@@ -200,15 +202,17 @@ static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range)
{ {
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
dbg_hid("G25/G27/DFGT: setting range to %u\n", range); dbg_hid("G25/G27/DFGT: setting range to %u\n", range);
report->field[0]->value[0] = 0xf8; value[0] = 0xf8;
report->field[0]->value[1] = 0x81; value[1] = 0x81;
report->field[0]->value[2] = range & 0x00ff; value[2] = range & 0x00ff;
report->field[0]->value[3] = (range & 0xff00) >> 8; value[3] = (range & 0xff00) >> 8;
report->field[0]->value[4] = 0x00; value[4] = 0x00;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
} }
...@@ -219,16 +223,18 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) ...@@ -219,16 +223,18 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
int start_left, start_right, full_range; int start_left, start_right, full_range;
__s32 *value = report->field[0]->value;
dbg_hid("Driving Force Pro: setting range to %u\n", range); dbg_hid("Driving Force Pro: setting range to %u\n", range);
/* Prepare "coarse" limit command */ /* Prepare "coarse" limit command */
report->field[0]->value[0] = 0xf8; value[0] = 0xf8;
report->field[0]->value[1] = 0x00; /* Set later */ value[1] = 0x00; /* Set later */
report->field[0]->value[2] = 0x00; value[2] = 0x00;
report->field[0]->value[3] = 0x00; value[3] = 0x00;
report->field[0]->value[4] = 0x00; value[4] = 0x00;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
if (range > 200) { if (range > 200) {
report->field[0]->value[1] = 0x03; report->field[0]->value[1] = 0x03;
...@@ -240,13 +246,13 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) ...@@ -240,13 +246,13 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
/* Prepare "fine" limit command */ /* Prepare "fine" limit command */
report->field[0]->value[0] = 0x81; value[0] = 0x81;
report->field[0]->value[1] = 0x0b; value[1] = 0x0b;
report->field[0]->value[2] = 0x00; value[2] = 0x00;
report->field[0]->value[3] = 0x00; value[3] = 0x00;
report->field[0]->value[4] = 0x00; value[4] = 0x00;
report->field[0]->value[5] = 0x00; value[5] = 0x00;
report->field[0]->value[6] = 0x00; value[6] = 0x00;
if (range == 200 || range == 900) { /* Do not apply any fine limit */ if (range == 200 || range == 900) { /* Do not apply any fine limit */
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
...@@ -257,11 +263,11 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) ...@@ -257,11 +263,11 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
start_left = (((full_range - range + 1) * 2047) / full_range); start_left = (((full_range - range + 1) * 2047) / full_range);
start_right = 0xfff - start_left; start_right = 0xfff - start_left;
report->field[0]->value[2] = start_left >> 4; value[2] = start_left >> 4;
report->field[0]->value[3] = start_right >> 4; value[3] = start_right >> 4;
report->field[0]->value[4] = 0xff; value[4] = 0xff;
report->field[0]->value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); value[5] = (start_right & 0xe) << 4 | (start_left & 0xe);
report->field[0]->value[6] = 0xff; value[6] = 0xff;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
} }
...@@ -344,14 +350,15 @@ static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) ...@@ -344,14 +350,15 @@ 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 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); struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
report->field[0]->value[0] = 0xf8;
report->field[0]->value[1] = 0x12; value[0] = 0xf8;
report->field[0]->value[2] = leds; value[1] = 0x12;
report->field[0]->value[3] = 0x00; value[2] = leds;
report->field[0]->value[4] = 0x00; value[3] = 0x00;
report->field[0]->value[5] = 0x00; value[4] = 0x00;
report->field[0]->value[6] = 0x00; value[5] = 0x00;
value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT); usbhid_submit_report(hid, report, USB_DIR_OUT);
} }
...@@ -501,7 +508,7 @@ int lg4ff_init(struct hid_device *hid) ...@@ -501,7 +508,7 @@ int lg4ff_init(struct hid_device *hid)
/* Check if autocentering is available and /* Check if autocentering is available and
* set the centering force to zero by default */ * set the centering force to zero by default */
if (test_bit(FF_AUTOCENTER, dev->ffbit)) { if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
if(rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
else else
dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment