]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/input/joystick/iforce/iforce-usb.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[mirror_ubuntu-focal-kernel.git] / drivers / input / joystick / iforce / iforce-usb.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4 2 /*
1da177e4 3 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
598972d4 4 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
1da177e4
LT
5 *
6 * USB/RS232 I-Force joysticks and wheels.
7 */
8
9/*
1da177e4
LT
10 */
11
12#include "iforce.h"
13
14void iforce_usb_xmit(struct iforce *iforce)
15{
16 int n, c;
17 unsigned long flags;
18
19 spin_lock_irqsave(&iforce->xmit_lock, flags);
20
21 if (iforce->xmit.head == iforce->xmit.tail) {
22 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
23 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
24 return;
25 }
26
27 ((char *)iforce->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail];
28 XMIT_INC(iforce->xmit.tail, 1);
29 n = iforce->xmit.buf[iforce->xmit.tail];
30 XMIT_INC(iforce->xmit.tail, 1);
31
32 iforce->out->transfer_buffer_length = n + 1;
33 iforce->out->dev = iforce->usbdev;
34
35 /* Copy rest of data then */
36 c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE);
37 if (n < c) c=n;
38
39 memcpy(iforce->out->transfer_buffer + 1,
40 &iforce->xmit.buf[iforce->xmit.tail],
41 c);
42 if (n != c) {
43 memcpy(iforce->out->transfer_buffer + 1 + c,
44 &iforce->xmit.buf[0],
45 n-c);
46 }
47 XMIT_INC(iforce->xmit.tail, n);
48
49 if ( (n=usb_submit_urb(iforce->out, GFP_ATOMIC)) ) {
b8691fd2 50 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
a852d78e 51 dev_warn(&iforce->intf->dev, "usb_submit_urb failed %d\n", n);
1da177e4
LT
52 }
53
54 /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended.
55 * As long as the urb completion handler is not called, the transmiting
56 * is considered to be running */
57 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
58}
59
7d12e780 60static void iforce_usb_irq(struct urb *urb)
1da177e4
LT
61{
62 struct iforce *iforce = urb->context;
a852d78e 63 struct device *dev = &iforce->intf->dev;
1da177e4
LT
64 int status;
65
66 switch (urb->status) {
67 case 0:
68 /* success */
69 break;
70 case -ECONNRESET:
71 case -ENOENT:
72 case -ESHUTDOWN:
73 /* this urb is terminated, clean up */
f576125d
GKH
74 dev_dbg(dev, "%s - urb shutting down with status: %d\n",
75 __func__, urb->status);
1da177e4
LT
76 return;
77 default:
f576125d
GKH
78 dev_dbg(dev, "%s - urb has status of: %d\n",
79 __func__, urb->status);
1da177e4
LT
80 goto exit;
81 }
82
83 iforce_process_packet(iforce,
7d12e780 84 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1);
1da177e4
LT
85
86exit:
87 status = usb_submit_urb (urb, GFP_ATOMIC);
88 if (status)
f576125d 89 dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
7b22a885 90 __func__, status);
1da177e4
LT
91}
92
7d12e780 93static void iforce_usb_out(struct urb *urb)
1da177e4
LT
94{
95 struct iforce *iforce = urb->context;
96
97 if (urb->status) {
c2b27ef6 98 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
a852d78e 99 dev_dbg(&iforce->intf->dev, "urb->status %d, exiting\n",
f576125d 100 urb->status);
1da177e4
LT
101 return;
102 }
103
104 iforce_usb_xmit(iforce);
105
106 wake_up(&iforce->wait);
107}
108
7d12e780 109static void iforce_usb_ctrl(struct urb *urb)
1da177e4
LT
110{
111 struct iforce *iforce = urb->context;
112 if (urb->status) return;
113 iforce->ecmd = 0xff00 | urb->actual_length;
114 wake_up(&iforce->wait);
115}
116
117static int iforce_usb_probe(struct usb_interface *intf,
118 const struct usb_device_id *id)
119{
120 struct usb_device *dev = interface_to_usbdev(intf);
121 struct usb_host_interface *interface;
122 struct usb_endpoint_descriptor *epirq, *epout;
123 struct iforce *iforce;
17dd3f0f 124 int err = -ENOMEM;
1da177e4
LT
125
126 interface = intf->cur_altsetting;
127
59cf8bed
JH
128 if (interface->desc.bNumEndpoints < 2)
129 return -ENODEV;
130
1da177e4
LT
131 epirq = &interface->endpoint[0].desc;
132 epout = &interface->endpoint[1].desc;
133
17dd3f0f 134 if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL)))
1da177e4
LT
135 goto fail;
136
17dd3f0f 137 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL)))
1da177e4 138 goto fail;
1da177e4 139
17dd3f0f 140 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL)))
1da177e4 141 goto fail;
1da177e4 142
17dd3f0f 143 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
1da177e4 144 goto fail;
1da177e4
LT
145
146 iforce->bus = IFORCE_USB;
147 iforce->usbdev = dev;
a852d78e 148 iforce->intf = intf;
1da177e4
LT
149
150 iforce->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE;
151 iforce->cr.wIndex = 0;
6b8588f7 152 iforce->cr.wLength = cpu_to_le16(16);
1da177e4
LT
153
154 usb_fill_int_urb(iforce->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress),
155 iforce->data, 16, iforce_usb_irq, iforce, epirq->bInterval);
156
b8691fd2
JD
157 usb_fill_int_urb(iforce->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress),
158 iforce + 1, 32, iforce_usb_out, iforce, epout->bInterval);
1da177e4
LT
159
160 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0),
161 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce);
162
17dd3f0f
DT
163 err = iforce_init_device(iforce);
164 if (err)
165 goto fail;
1da177e4
LT
166
167 usb_set_intfdata(intf, iforce);
168 return 0;
169
170fail:
171 if (iforce) {
8f21d119
MK
172 usb_free_urb(iforce->irq);
173 usb_free_urb(iforce->out);
174 usb_free_urb(iforce->ctrl);
1da177e4
LT
175 kfree(iforce);
176 }
177
17dd3f0f 178 return err;
1da177e4
LT
179}
180
1da177e4
LT
181static void iforce_usb_disconnect(struct usb_interface *intf)
182{
183 struct iforce *iforce = usb_get_intfdata(intf);
1da177e4
LT
184
185 usb_set_intfdata(intf, NULL);
1da177e4 186
98b7fb04
DT
187 input_unregister_device(iforce->dev);
188
189 usb_free_urb(iforce->irq);
190 usb_free_urb(iforce->out);
191 usb_free_urb(iforce->ctrl);
192
193 kfree(iforce);
1da177e4
LT
194}
195
c1295851 196static const struct usb_device_id iforce_usb_ids[] = {
1da177e4
LT
197 { USB_DEVICE(0x044f, 0xa01c) }, /* Thrustmaster Motor Sport GT */
198 { USB_DEVICE(0x046d, 0xc281) }, /* Logitech WingMan Force */
199 { USB_DEVICE(0x046d, 0xc291) }, /* Logitech WingMan Formula Force */
200 { USB_DEVICE(0x05ef, 0x020a) }, /* AVB Top Shot Pegasus */
201 { USB_DEVICE(0x05ef, 0x8884) }, /* AVB Mag Turbo Force */
202 { USB_DEVICE(0x05ef, 0x8888) }, /* AVB Top Shot FFB Racing Wheel */
203 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */
68947b8f 204 { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */
1da177e4 205 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */
d861f7bf 206 { USB_DEVICE(0x06f8, 0x0003) }, /* Guillemot Jet Leader Force Feedback */
1da177e4 207 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */
18098a6c 208 { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */
1da177e4
LT
209 { } /* Terminating entry */
210};
211
212MODULE_DEVICE_TABLE (usb, iforce_usb_ids);
213
214struct usb_driver iforce_usb_driver = {
1da177e4
LT
215 .name = "iforce",
216 .probe = iforce_usb_probe,
217 .disconnect = iforce_usb_disconnect,
218 .id_table = iforce_usb_ids,
219};