diff options
author | Michal Malý <madcatxster@gmail.com> | 2012-09-23 19:09:30 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2012-09-25 09:40:00 -0400 |
commit | 74479ba861b5cd77d445c2ec8f59521ae509f7db (patch) | |
tree | 4ad916f83fce648457409b799300db152ba084b3 /drivers/hid/hid-lg4ff.c | |
parent | cead24c1181ad199354bd08013d0f9d08b66691b (diff) |
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: Michal Malý <madcatxster@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-lg4ff.c')
-rw-r--r-- | drivers/hid/hid-lg4ff.c | 121 |
1 files changed, 64 insertions, 57 deletions
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index f3390ee6105c..c40e957aab91 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c | |||
@@ -134,6 +134,7 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e | |||
134 | struct hid_device *hid = input_get_drvdata(dev); | 134 | struct hid_device *hid = input_get_drvdata(dev); |
135 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 135 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
136 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 136 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
137 | __s32 *value = report->field[0]->value; | ||
137 | int x; | 138 | int x; |
138 | 139 | ||
139 | #define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff | 140 | #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 | case FF_CONSTANT: | 143 | case FF_CONSTANT: |
143 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ | 144 | x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */ |
144 | CLAMP(x); | 145 | CLAMP(x); |
145 | report->field[0]->value[0] = 0x11; /* Slot 1 */ | 146 | value[0] = 0x11; /* Slot 1 */ |
146 | report->field[0]->value[1] = 0x08; | 147 | value[1] = 0x08; |
147 | report->field[0]->value[2] = x; | 148 | value[2] = x; |
148 | report->field[0]->value[3] = 0x80; | 149 | value[3] = 0x80; |
149 | report->field[0]->value[4] = 0x00; | 150 | value[4] = 0x00; |
150 | report->field[0]->value[5] = 0x00; | 151 | value[5] = 0x00; |
151 | report->field[0]->value[6] = 0x00; | 152 | value[6] = 0x00; |
152 | 153 | ||
153 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 154 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
154 | break; | 155 | break; |
@@ -163,14 +164,15 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud | |||
163 | struct hid_device *hid = input_get_drvdata(dev); | 164 | struct hid_device *hid = input_get_drvdata(dev); |
164 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 165 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
165 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 166 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
167 | __s32 *value = report->field[0]->value; | ||
166 | 168 | ||
167 | report->field[0]->value[0] = 0xfe; | 169 | value[0] = 0xfe; |
168 | report->field[0]->value[1] = 0x0d; | 170 | value[1] = 0x0d; |
169 | report->field[0]->value[2] = magnitude >> 13; | 171 | value[2] = magnitude >> 13; |
170 | report->field[0]->value[3] = magnitude >> 13; | 172 | value[3] = magnitude >> 13; |
171 | report->field[0]->value[4] = magnitude >> 8; | 173 | value[4] = magnitude >> 8; |
172 | report->field[0]->value[5] = 0x00; | 174 | value[5] = 0x00; |
173 | report->field[0]->value[6] = 0x00; | 175 | value[6] = 0x00; |
174 | 176 | ||
175 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 177 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
176 | } | 178 | } |
@@ -181,16 +183,16 @@ static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude) | |||
181 | struct hid_device *hid = input_get_drvdata(dev); | 183 | struct hid_device *hid = input_get_drvdata(dev); |
182 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 184 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
183 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 185 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
186 | __s32 *value = report->field[0]->value; | ||
184 | magnitude = magnitude * 90 / 65535; | 187 | magnitude = magnitude * 90 / 65535; |
185 | |||
186 | 188 | ||
187 | report->field[0]->value[0] = 0xfe; | 189 | value[0] = 0xfe; |
188 | report->field[0]->value[1] = 0x03; | 190 | value[1] = 0x03; |
189 | report->field[0]->value[2] = magnitude >> 14; | 191 | value[2] = magnitude >> 14; |
190 | report->field[0]->value[3] = magnitude >> 14; | 192 | value[3] = magnitude >> 14; |
191 | report->field[0]->value[4] = magnitude; | 193 | value[4] = magnitude; |
192 | report->field[0]->value[5] = 0x00; | 194 | value[5] = 0x00; |
193 | report->field[0]->value[6] = 0x00; | 195 | value[6] = 0x00; |
194 | 196 | ||
195 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 197 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
196 | } | 198 | } |
@@ -200,15 +202,17 @@ static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range) | |||
200 | { | 202 | { |
201 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 203 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
202 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 204 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
205 | __s32 *value = report->field[0]->value; | ||
206 | |||
203 | dbg_hid("G25/G27/DFGT: setting range to %u\n", range); | 207 | dbg_hid("G25/G27/DFGT: setting range to %u\n", range); |
204 | 208 | ||
205 | report->field[0]->value[0] = 0xf8; | 209 | value[0] = 0xf8; |
206 | report->field[0]->value[1] = 0x81; | 210 | value[1] = 0x81; |
207 | report->field[0]->value[2] = range & 0x00ff; | 211 | value[2] = range & 0x00ff; |
208 | report->field[0]->value[3] = (range & 0xff00) >> 8; | 212 | value[3] = (range & 0xff00) >> 8; |
209 | report->field[0]->value[4] = 0x00; | 213 | value[4] = 0x00; |
210 | report->field[0]->value[5] = 0x00; | 214 | value[5] = 0x00; |
211 | report->field[0]->value[6] = 0x00; | 215 | value[6] = 0x00; |
212 | 216 | ||
213 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 217 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
214 | } | 218 | } |
@@ -219,16 +223,18 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) | |||
219 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 223 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
220 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); | 224 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
221 | int start_left, start_right, full_range; | 225 | int start_left, start_right, full_range; |
226 | __s32 *value = report->field[0]->value; | ||
227 | |||
222 | dbg_hid("Driving Force Pro: setting range to %u\n", range); | 228 | dbg_hid("Driving Force Pro: setting range to %u\n", range); |
223 | 229 | ||
224 | /* Prepare "coarse" limit command */ | 230 | /* Prepare "coarse" limit command */ |
225 | report->field[0]->value[0] = 0xf8; | 231 | value[0] = 0xf8; |
226 | report->field[0]->value[1] = 0x00; /* Set later */ | 232 | value[1] = 0x00; /* Set later */ |
227 | report->field[0]->value[2] = 0x00; | 233 | value[2] = 0x00; |
228 | report->field[0]->value[3] = 0x00; | 234 | value[3] = 0x00; |
229 | report->field[0]->value[4] = 0x00; | 235 | value[4] = 0x00; |
230 | report->field[0]->value[5] = 0x00; | 236 | value[5] = 0x00; |
231 | report->field[0]->value[6] = 0x00; | 237 | value[6] = 0x00; |
232 | 238 | ||
233 | if (range > 200) { | 239 | if (range > 200) { |
234 | report->field[0]->value[1] = 0x03; | 240 | report->field[0]->value[1] = 0x03; |
@@ -240,13 +246,13 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range) | |||
240 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 246 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
241 | 247 | ||
242 | /* Prepare "fine" limit command */ | 248 | /* Prepare "fine" limit command */ |
243 | report->field[0]->value[0] = 0x81; | 249 | value[0] = 0x81; |
244 | report->field[0]->value[1] = 0x0b; | 250 | value[1] = 0x0b; |
245 | report->field[0]->value[2] = 0x00; | 251 | value[2] = 0x00; |
246 | report->field[0]->value[3] = 0x00; | 252 | value[3] = 0x00; |
247 | report->field[0]->value[4] = 0x00; | 253 | value[4] = 0x00; |
248 | report->field[0]->value[5] = 0x00; | 254 | value[5] = 0x00; |
249 | report->field[0]->value[6] = 0x00; | 255 | value[6] = 0x00; |
250 | 256 | ||
251 | if (range == 200 || range == 900) { /* Do not apply any fine limit */ | 257 | if (range == 200 || range == 900) { /* Do not apply any fine limit */ |
252 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 258 | 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 | start_left = (((full_range - range + 1) * 2047) / full_range); | 263 | start_left = (((full_range - range + 1) * 2047) / full_range); |
258 | start_right = 0xfff - start_left; | 264 | start_right = 0xfff - start_left; |
259 | 265 | ||
260 | report->field[0]->value[2] = start_left >> 4; | 266 | value[2] = start_left >> 4; |
261 | report->field[0]->value[3] = start_right >> 4; | 267 | value[3] = start_right >> 4; |
262 | report->field[0]->value[4] = 0xff; | 268 | value[4] = 0xff; |
263 | report->field[0]->value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); | 269 | value[5] = (start_right & 0xe) << 4 | (start_left & 0xe); |
264 | report->field[0]->value[6] = 0xff; | 270 | value[6] = 0xff; |
265 | 271 | ||
266 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 272 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
267 | } | 273 | } |
@@ -344,14 +350,15 @@ static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) | |||
344 | { | 350 | { |
345 | struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; | 351 | 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); | 352 | struct hid_report *report = list_entry(report_list->next, struct hid_report, list); |
347 | 353 | __s32 *value = report->field[0]->value; | |
348 | report->field[0]->value[0] = 0xf8; | 354 | |
349 | report->field[0]->value[1] = 0x12; | 355 | value[0] = 0xf8; |
350 | report->field[0]->value[2] = leds; | 356 | value[1] = 0x12; |
351 | report->field[0]->value[3] = 0x00; | 357 | value[2] = leds; |
352 | report->field[0]->value[4] = 0x00; | 358 | value[3] = 0x00; |
353 | report->field[0]->value[5] = 0x00; | 359 | value[4] = 0x00; |
354 | report->field[0]->value[6] = 0x00; | 360 | value[5] = 0x00; |
361 | value[6] = 0x00; | ||
355 | usbhid_submit_report(hid, report, USB_DIR_OUT); | 362 | usbhid_submit_report(hid, report, USB_DIR_OUT); |
356 | } | 363 | } |
357 | 364 | ||
@@ -501,7 +508,7 @@ int lg4ff_init(struct hid_device *hid) | |||
501 | /* Check if autocentering is available and | 508 | /* Check if autocentering is available and |
502 | * set the centering force to zero by default */ | 509 | * set the centering force to zero by default */ |
503 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) { | 510 | if (test_bit(FF_AUTOCENTER, dev->ffbit)) { |
504 | if(rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ | 511 | if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ |
505 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; | 512 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; |
506 | else | 513 | else |
507 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; | 514 | dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; |