1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
4 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
6 * USB/RS232 I-Force joysticks and wheels.
15 struct usb_device
*usbdev
;
16 struct usb_interface
*intf
;
17 struct urb
*irq
, *out
;
19 u8 data_in
[IFORCE_MAX_LENGTH
] ____cacheline_aligned
;
20 u8 data_out
[IFORCE_MAX_LENGTH
] ____cacheline_aligned
;
23 static void __iforce_usb_xmit(struct iforce
*iforce
)
25 struct iforce_usb
*iforce_usb
= container_of(iforce
, struct iforce_usb
,
30 spin_lock_irqsave(&iforce
->xmit_lock
, flags
);
32 if (iforce
->xmit
.head
== iforce
->xmit
.tail
) {
33 clear_bit(IFORCE_XMIT_RUNNING
, iforce
->xmit_flags
);
34 spin_unlock_irqrestore(&iforce
->xmit_lock
, flags
);
38 ((char *)iforce_usb
->out
->transfer_buffer
)[0] = iforce
->xmit
.buf
[iforce
->xmit
.tail
];
39 XMIT_INC(iforce
->xmit
.tail
, 1);
40 n
= iforce
->xmit
.buf
[iforce
->xmit
.tail
];
41 XMIT_INC(iforce
->xmit
.tail
, 1);
43 iforce_usb
->out
->transfer_buffer_length
= n
+ 1;
44 iforce_usb
->out
->dev
= iforce_usb
->usbdev
;
46 /* Copy rest of data then */
47 c
= CIRC_CNT_TO_END(iforce
->xmit
.head
, iforce
->xmit
.tail
, XMIT_SIZE
);
50 memcpy(iforce_usb
->out
->transfer_buffer
+ 1,
51 &iforce
->xmit
.buf
[iforce
->xmit
.tail
],
54 memcpy(iforce_usb
->out
->transfer_buffer
+ 1 + c
,
58 XMIT_INC(iforce
->xmit
.tail
, n
);
60 if ( (n
=usb_submit_urb(iforce_usb
->out
, GFP_ATOMIC
)) ) {
61 clear_bit(IFORCE_XMIT_RUNNING
, iforce
->xmit_flags
);
62 dev_warn(&iforce_usb
->intf
->dev
,
63 "usb_submit_urb failed %d\n", n
);
66 /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended.
67 * As long as the urb completion handler is not called, the transmiting
68 * is considered to be running */
69 spin_unlock_irqrestore(&iforce
->xmit_lock
, flags
);
72 static void iforce_usb_xmit(struct iforce
*iforce
)
74 if (!test_and_set_bit(IFORCE_XMIT_RUNNING
, iforce
->xmit_flags
))
75 __iforce_usb_xmit(iforce
);
78 static int iforce_usb_get_id(struct iforce
*iforce
, u8 id
,
79 u8
*response_data
, size_t *response_len
)
81 struct iforce_usb
*iforce_usb
= container_of(iforce
, struct iforce_usb
,
86 buf
= kmalloc(IFORCE_MAX_LENGTH
, GFP_KERNEL
);
90 status
= usb_control_msg(iforce_usb
->usbdev
,
91 usb_rcvctrlpipe(iforce_usb
->usbdev
, 0),
93 USB_TYPE_VENDOR
| USB_DIR_IN
|
95 0, 0, buf
, IFORCE_MAX_LENGTH
, HZ
);
97 dev_err(&iforce_usb
->intf
->dev
,
98 "usb_submit_urb failed: %d\n", status
);
99 } else if (buf
[0] != id
) {
102 memcpy(response_data
, buf
, status
);
103 *response_len
= status
;
111 static int iforce_usb_start_io(struct iforce
*iforce
)
113 struct iforce_usb
*iforce_usb
= container_of(iforce
, struct iforce_usb
,
116 if (usb_submit_urb(iforce_usb
->irq
, GFP_KERNEL
))
122 static void iforce_usb_stop_io(struct iforce
*iforce
)
124 struct iforce_usb
*iforce_usb
= container_of(iforce
, struct iforce_usb
,
127 usb_kill_urb(iforce_usb
->irq
);
128 usb_kill_urb(iforce_usb
->out
);
131 static const struct iforce_xport_ops iforce_usb_xport_ops
= {
132 .xmit
= iforce_usb_xmit
,
133 .get_id
= iforce_usb_get_id
,
134 .start_io
= iforce_usb_start_io
,
135 .stop_io
= iforce_usb_stop_io
,
138 static void iforce_usb_irq(struct urb
*urb
)
140 struct iforce_usb
*iforce_usb
= urb
->context
;
141 struct iforce
*iforce
= &iforce_usb
->iforce
;
142 struct device
*dev
= &iforce_usb
->intf
->dev
;
145 switch (urb
->status
) {
152 /* this urb is terminated, clean up */
153 dev_dbg(dev
, "%s - urb shutting down with status: %d\n",
154 __func__
, urb
->status
);
157 dev_dbg(dev
, "%s - urb has status of: %d\n",
158 __func__
, urb
->status
);
162 iforce_process_packet(iforce
, iforce_usb
->data_in
[0],
163 iforce_usb
->data_in
+ 1, urb
->actual_length
- 1);
166 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
168 dev_err(dev
, "%s - usb_submit_urb failed with result %d\n",
172 static void iforce_usb_out(struct urb
*urb
)
174 struct iforce_usb
*iforce_usb
= urb
->context
;
175 struct iforce
*iforce
= &iforce_usb
->iforce
;
178 clear_bit(IFORCE_XMIT_RUNNING
, iforce
->xmit_flags
);
179 dev_dbg(&iforce_usb
->intf
->dev
, "urb->status %d, exiting\n",
184 __iforce_usb_xmit(iforce
);
186 wake_up(&iforce
->wait
);
189 static int iforce_usb_probe(struct usb_interface
*intf
,
190 const struct usb_device_id
*id
)
192 struct usb_device
*dev
= interface_to_usbdev(intf
);
193 struct usb_host_interface
*interface
;
194 struct usb_endpoint_descriptor
*epirq
, *epout
;
195 struct iforce_usb
*iforce_usb
;
198 interface
= intf
->cur_altsetting
;
200 if (interface
->desc
.bNumEndpoints
< 2)
203 epirq
= &interface
->endpoint
[0].desc
;
204 if (!usb_endpoint_is_int_in(epirq
))
207 epout
= &interface
->endpoint
[1].desc
;
208 if (!usb_endpoint_is_int_out(epout
))
211 iforce_usb
= kzalloc(sizeof(*iforce_usb
), GFP_KERNEL
);
215 iforce_usb
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
216 if (!iforce_usb
->irq
)
219 iforce_usb
->out
= usb_alloc_urb(0, GFP_KERNEL
);
220 if (!iforce_usb
->out
)
223 iforce_usb
->iforce
.xport_ops
= &iforce_usb_xport_ops
;
225 iforce_usb
->usbdev
= dev
;
226 iforce_usb
->intf
= intf
;
228 usb_fill_int_urb(iforce_usb
->irq
, dev
,
229 usb_rcvintpipe(dev
, epirq
->bEndpointAddress
),
230 iforce_usb
->data_in
, sizeof(iforce_usb
->data_in
),
231 iforce_usb_irq
, iforce_usb
, epirq
->bInterval
);
233 usb_fill_int_urb(iforce_usb
->out
, dev
,
234 usb_sndintpipe(dev
, epout
->bEndpointAddress
),
235 iforce_usb
->data_out
, sizeof(iforce_usb
->data_out
),
236 iforce_usb_out
, iforce_usb
, epout
->bInterval
);
238 err
= iforce_init_device(&intf
->dev
, BUS_USB
, &iforce_usb
->iforce
);
242 usb_set_intfdata(intf
, iforce_usb
);
247 usb_free_urb(iforce_usb
->irq
);
248 usb_free_urb(iforce_usb
->out
);
255 static void iforce_usb_disconnect(struct usb_interface
*intf
)
257 struct iforce_usb
*iforce_usb
= usb_get_intfdata(intf
);
259 usb_set_intfdata(intf
, NULL
);
261 input_unregister_device(iforce_usb
->iforce
.dev
);
263 usb_free_urb(iforce_usb
->irq
);
264 usb_free_urb(iforce_usb
->out
);
269 static const struct usb_device_id iforce_usb_ids
[] = {
270 { USB_DEVICE(0x044f, 0xa01c) }, /* Thrustmaster Motor Sport GT */
271 { USB_DEVICE(0x046d, 0xc281) }, /* Logitech WingMan Force */
272 { USB_DEVICE(0x046d, 0xc291) }, /* Logitech WingMan Formula Force */
273 { USB_DEVICE(0x05ef, 0x020a) }, /* AVB Top Shot Pegasus */
274 { USB_DEVICE(0x05ef, 0x8884) }, /* AVB Mag Turbo Force */
275 { USB_DEVICE(0x05ef, 0x8888) }, /* AVB Top Shot FFB Racing Wheel */
276 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */
277 { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */
278 { USB_DEVICE(0x06a3, 0xff04) }, /* Saitek R440 Force Wheel */
279 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */
280 { USB_DEVICE(0x06f8, 0x0003) }, /* Guillemot Jet Leader Force Feedback */
281 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */
282 { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */
283 { } /* Terminating entry */
286 MODULE_DEVICE_TABLE (usb
, iforce_usb_ids
);
288 struct usb_driver iforce_usb_driver
= {
290 .probe
= iforce_usb_probe
,
291 .disconnect
= iforce_usb_disconnect
,
292 .id_table
= iforce_usb_ids
,
295 module_usb_driver(iforce_usb_driver
);
297 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>, Johann Deneux <johann.deneux@gmail.com>");
298 MODULE_DESCRIPTION("USB I-Force joysticks and wheels driver");
299 MODULE_LICENSE("GPL");