hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/input/joystick/iforce/iforce-main.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
34 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
....@@ -5,26 +6,11 @@
56 * USB/RS232 I-Force joysticks and wheels.
67 */
78
8
-/*
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
- */
23
-
9
+#include <asm/unaligned.h>
2410 #include "iforce.h"
2511
2612 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>, Johann Deneux <johann.deneux@gmail.com>");
27
-MODULE_DESCRIPTION("USB/RS232 I-Force joysticks and wheels driver");
13
+MODULE_DESCRIPTION("Core I-Force joysticks and wheels driver");
2814 MODULE_LICENSE("GPL");
2915
3016 static signed short btn_joystick[] =
....@@ -64,9 +50,11 @@
6450 { 0x046d, 0xc291, "Logitech WingMan Formula Force", btn_wheel, abs_wheel, ff_iforce },
6551 { 0x05ef, 0x020a, "AVB Top Shot Pegasus", btn_joystick_avb, abs_avb_pegasus, ff_iforce },
6652 { 0x05ef, 0x8884, "AVB Mag Turbo Force", btn_wheel, abs_wheel, ff_iforce },
53
+ { 0x05ef, 0x8886, "Boeder Force Feedback Wheel", btn_wheel, abs_wheel, ff_iforce },
6754 { 0x05ef, 0x8888, "AVB Top Shot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //?
6855 { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //?
6956 { 0x061c, 0xc084, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce },
57
+ { 0x06a3, 0xff04, "Saitek R440 Force Wheel", btn_wheel, abs_wheel, ff_iforce }, //?
7058 { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //?
7159 { 0x06f8, 0x0001, "Guillemot Jet Leader Force Feedback", btn_joystick, abs_joystick_rudder, ff_iforce },
7260 { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //?
....@@ -132,22 +120,21 @@
132120 * Upload the effect
133121 */
134122 switch (effect->type) {
123
+ case FF_PERIODIC:
124
+ ret = iforce_upload_periodic(iforce, effect, old);
125
+ break;
135126
136
- case FF_PERIODIC:
137
- ret = iforce_upload_periodic(iforce, effect, old);
138
- break;
127
+ case FF_CONSTANT:
128
+ ret = iforce_upload_constant(iforce, effect, old);
129
+ break;
139130
140
- case FF_CONSTANT:
141
- ret = iforce_upload_constant(iforce, effect, old);
142
- break;
131
+ case FF_SPRING:
132
+ case FF_DAMPER:
133
+ ret = iforce_upload_condition(iforce, effect, old);
134
+ break;
143135
144
- case FF_SPRING:
145
- case FF_DAMPER:
146
- ret = iforce_upload_condition(iforce, effect, old);
147
- break;
148
-
149
- default:
150
- return -EINVAL;
136
+ default:
137
+ return -EINVAL;
151138 }
152139
153140 if (ret == 0) {
....@@ -185,15 +172,7 @@
185172 {
186173 struct iforce *iforce = input_get_drvdata(dev);
187174
188
- switch (iforce->bus) {
189
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
190
- case IFORCE_USB:
191
- iforce->irq->dev = iforce->usbdev;
192
- if (usb_submit_urb(iforce->irq, GFP_KERNEL))
193
- return -EIO;
194
- break;
195
-#endif
196
- }
175
+ iforce->xport_ops->start_io(iforce);
197176
198177 if (test_bit(EV_FF, dev->evbit)) {
199178 /* Enable force feedback */
....@@ -226,27 +205,17 @@
226205 !test_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags));
227206 }
228207
229
- switch (iforce->bus) {
230
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
231
- case IFORCE_USB:
232
- usb_kill_urb(iforce->irq);
233
- usb_kill_urb(iforce->out);
234
- usb_kill_urb(iforce->ctrl);
235
- break;
236
-#endif
237
-#ifdef CONFIG_JOYSTICK_IFORCE_232
238
- case IFORCE_232:
239
- //TODO: Wait for the last packets to be sent
240
- break;
241
-#endif
242
- }
208
+ iforce->xport_ops->stop_io(iforce);
243209 }
244210
245
-int iforce_init_device(struct iforce *iforce)
211
+int iforce_init_device(struct device *parent, u16 bustype,
212
+ struct iforce *iforce)
246213 {
247214 struct input_dev *input_dev;
248215 struct ff_device *ff;
249
- unsigned char c[] = "CEOV";
216
+ u8 c[] = "CEOV";
217
+ u8 buf[IFORCE_MAX_LENGTH];
218
+ size_t len;
250219 int i, error;
251220 int ff_effects = 0;
252221
....@@ -264,20 +233,8 @@
264233 * Input device fields.
265234 */
266235
267
- switch (iforce->bus) {
268
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
269
- case IFORCE_USB:
270
- input_dev->id.bustype = BUS_USB;
271
- input_dev->dev.parent = &iforce->usbdev->dev;
272
- break;
273
-#endif
274
-#ifdef CONFIG_JOYSTICK_IFORCE_232
275
- case IFORCE_232:
276
- input_dev->id.bustype = BUS_RS232;
277
- input_dev->dev.parent = &iforce->serio->dev;
278
- break;
279
-#endif
280
- }
236
+ input_dev->id.bustype = bustype;
237
+ input_dev->dev.parent = parent;
281238
282239 input_set_drvdata(input_dev, iforce);
283240
....@@ -302,7 +259,7 @@
302259 */
303260
304261 for (i = 0; i < 20; i++)
305
- if (!iforce_get_id_packet(iforce, "O"))
262
+ if (!iforce_get_id_packet(iforce, 'O', buf, &len))
306263 break;
307264
308265 if (i == 20) { /* 5 seconds */
....@@ -316,23 +273,23 @@
316273 * Get device info.
317274 */
318275
319
- if (!iforce_get_id_packet(iforce, "M"))
320
- input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1];
276
+ if (!iforce_get_id_packet(iforce, 'M', buf, &len) && len >= 3)
277
+ input_dev->id.vendor = get_unaligned_le16(buf + 1);
321278 else
322279 dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");
323280
324
- if (!iforce_get_id_packet(iforce, "P"))
325
- input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1];
281
+ if (!iforce_get_id_packet(iforce, 'P', buf, &len) && len >= 3)
282
+ input_dev->id.product = get_unaligned_le16(buf + 1);
326283 else
327284 dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n");
328285
329
- if (!iforce_get_id_packet(iforce, "B"))
330
- iforce->device_memory.end = (iforce->edata[2] << 8) | iforce->edata[1];
286
+ if (!iforce_get_id_packet(iforce, 'B', buf, &len) && len >= 3)
287
+ iforce->device_memory.end = get_unaligned_le16(buf + 1);
331288 else
332289 dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n");
333290
334
- if (!iforce_get_id_packet(iforce, "N"))
335
- ff_effects = iforce->edata[1];
291
+ if (!iforce_get_id_packet(iforce, 'N', buf, &len) && len >= 2)
292
+ ff_effects = buf[1];
336293 else
337294 dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n");
338295
....@@ -348,8 +305,9 @@
348305 */
349306
350307 for (i = 0; c[i]; i++)
351
- if (!iforce_get_id_packet(iforce, c + i))
352
- iforce_dump_packet(iforce, "info", iforce->ecmd, iforce->edata);
308
+ if (!iforce_get_id_packet(iforce, c[i], buf, &len))
309
+ iforce_dump_packet(iforce, "info",
310
+ (FF_CMD_QUERY & 0xff00) | len, buf);
353311
354312 /*
355313 * Disable spring, enable force feedback.
....@@ -383,34 +341,29 @@
383341 signed short t = iforce->type->abs[i];
384342
385343 switch (t) {
344
+ case ABS_X:
345
+ case ABS_Y:
346
+ case ABS_WHEEL:
347
+ input_set_abs_params(input_dev, t, -1920, 1920, 16, 128);
348
+ set_bit(t, input_dev->ffbit);
349
+ break;
386350
387
- case ABS_X:
388
- case ABS_Y:
389
- case ABS_WHEEL:
351
+ case ABS_THROTTLE:
352
+ case ABS_GAS:
353
+ case ABS_BRAKE:
354
+ input_set_abs_params(input_dev, t, 0, 255, 0, 0);
355
+ break;
390356
391
- input_set_abs_params(input_dev, t, -1920, 1920, 16, 128);
392
- set_bit(t, input_dev->ffbit);
393
- break;
357
+ case ABS_RUDDER:
358
+ input_set_abs_params(input_dev, t, -128, 127, 0, 0);
359
+ break;
394360
395
- case ABS_THROTTLE:
396
- case ABS_GAS:
397
- case ABS_BRAKE:
398
-
399
- input_set_abs_params(input_dev, t, 0, 255, 0, 0);
400
- break;
401
-
402
- case ABS_RUDDER:
403
-
404
- input_set_abs_params(input_dev, t, -128, 127, 0, 0);
405
- break;
406
-
407
- case ABS_HAT0X:
408
- case ABS_HAT0Y:
409
- case ABS_HAT1X:
410
- case ABS_HAT1Y:
411
-
412
- input_set_abs_params(input_dev, t, -1, 1, 0, 0);
413
- break;
361
+ case ABS_HAT0X:
362
+ case ABS_HAT0Y:
363
+ case ABS_HAT1X:
364
+ case ABS_HAT1Y:
365
+ input_set_abs_params(input_dev, t, -1, 1, 0, 0);
366
+ break;
414367 }
415368 }
416369
....@@ -443,35 +396,4 @@
443396 fail: input_free_device(input_dev);
444397 return error;
445398 }
446
-
447
-static int __init iforce_init(void)
448
-{
449
- int err = 0;
450
-
451
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
452
- err = usb_register(&iforce_usb_driver);
453
- if (err)
454
- return err;
455
-#endif
456
-#ifdef CONFIG_JOYSTICK_IFORCE_232
457
- err = serio_register_driver(&iforce_serio_drv);
458
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
459
- if (err)
460
- usb_deregister(&iforce_usb_driver);
461
-#endif
462
-#endif
463
- return err;
464
-}
465
-
466
-static void __exit iforce_exit(void)
467
-{
468
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
469
- usb_deregister(&iforce_usb_driver);
470
-#endif
471
-#ifdef CONFIG_JOYSTICK_IFORCE_232
472
- serio_unregister_driver(&iforce_serio_drv);
473
-#endif
474
-}
475
-
476
-module_init(iforce_init);
477
-module_exit(iforce_exit);
399
+EXPORT_SYMBOL(iforce_init_device);