diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/input/joystick/iforce/iforce-usb.c |
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/input/joystick/iforce/iforce-usb.c')
-rw-r--r-- | drivers/input/joystick/iforce/iforce-usb.c | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c new file mode 100644 index 00000000000..617c0b0e5a3 --- /dev/null +++ b/drivers/input/joystick/iforce/iforce-usb.c | |||
@@ -0,0 +1,243 @@ | |||
1 | /* | ||
2 | * $Id: iforce-usb.c,v 1.16 2002/06/09 11:08:04 jdeneux Exp $ | ||
3 | * | ||
4 | * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz> | ||
5 | * Copyright (c) 2001-2002 Johann Deneux <deneux@ifrance.com> | ||
6 | * | ||
7 | * USB/RS232 I-Force joysticks and wheels. | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | * | ||
25 | * Should you need to contact me, the author, you can do so either by | ||
26 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | ||
27 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | ||
28 | */ | ||
29 | |||
30 | #include "iforce.h" | ||
31 | |||
32 | void iforce_usb_xmit(struct iforce *iforce) | ||
33 | { | ||
34 | int n, c; | ||
35 | unsigned long flags; | ||
36 | |||
37 | spin_lock_irqsave(&iforce->xmit_lock, flags); | ||
38 | |||
39 | if (iforce->xmit.head == iforce->xmit.tail) { | ||
40 | clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags); | ||
41 | spin_unlock_irqrestore(&iforce->xmit_lock, flags); | ||
42 | return; | ||
43 | } | ||
44 | |||
45 | ((char *)iforce->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail]; | ||
46 | XMIT_INC(iforce->xmit.tail, 1); | ||
47 | n = iforce->xmit.buf[iforce->xmit.tail]; | ||
48 | XMIT_INC(iforce->xmit.tail, 1); | ||
49 | |||
50 | iforce->out->transfer_buffer_length = n + 1; | ||
51 | iforce->out->dev = iforce->usbdev; | ||
52 | |||
53 | /* Copy rest of data then */ | ||
54 | c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE); | ||
55 | if (n < c) c=n; | ||
56 | |||
57 | memcpy(iforce->out->transfer_buffer + 1, | ||
58 | &iforce->xmit.buf[iforce->xmit.tail], | ||
59 | c); | ||
60 | if (n != c) { | ||
61 | memcpy(iforce->out->transfer_buffer + 1 + c, | ||
62 | &iforce->xmit.buf[0], | ||
63 | n-c); | ||
64 | } | ||
65 | XMIT_INC(iforce->xmit.tail, n); | ||
66 | |||
67 | if ( (n=usb_submit_urb(iforce->out, GFP_ATOMIC)) ) { | ||
68 | printk(KERN_WARNING "iforce-usb.c: iforce_usb_xmit: usb_submit_urb failed %d\n", n); | ||
69 | } | ||
70 | |||
71 | /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended. | ||
72 | * As long as the urb completion handler is not called, the transmiting | ||
73 | * is considered to be running */ | ||
74 | spin_unlock_irqrestore(&iforce->xmit_lock, flags); | ||
75 | } | ||
76 | |||
77 | static void iforce_usb_irq(struct urb *urb, struct pt_regs *regs) | ||
78 | { | ||
79 | struct iforce *iforce = urb->context; | ||
80 | int status; | ||
81 | |||
82 | switch (urb->status) { | ||
83 | case 0: | ||
84 | /* success */ | ||
85 | break; | ||
86 | case -ECONNRESET: | ||
87 | case -ENOENT: | ||
88 | case -ESHUTDOWN: | ||
89 | /* this urb is terminated, clean up */ | ||
90 | dbg("%s - urb shutting down with status: %d", | ||
91 | __FUNCTION__, urb->status); | ||
92 | return; | ||
93 | default: | ||
94 | dbg("%s - urb has status of: %d", __FUNCTION__, urb->status); | ||
95 | goto exit; | ||
96 | } | ||
97 | |||
98 | iforce_process_packet(iforce, | ||
99 | (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1, regs); | ||
100 | |||
101 | exit: | ||
102 | status = usb_submit_urb (urb, GFP_ATOMIC); | ||
103 | if (status) | ||
104 | err ("%s - usb_submit_urb failed with result %d", | ||
105 | __FUNCTION__, status); | ||
106 | } | ||
107 | |||
108 | static void iforce_usb_out(struct urb *urb, struct pt_regs *regs) | ||
109 | { | ||
110 | struct iforce *iforce = urb->context; | ||
111 | |||
112 | if (urb->status) { | ||
113 | printk(KERN_DEBUG "iforce_usb_out: urb->status %d, exiting", urb->status); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | iforce_usb_xmit(iforce); | ||
118 | |||
119 | wake_up(&iforce->wait); | ||
120 | } | ||
121 | |||
122 | static void iforce_usb_ctrl(struct urb *urb, struct pt_regs *regs) | ||
123 | { | ||
124 | struct iforce *iforce = urb->context; | ||
125 | if (urb->status) return; | ||
126 | iforce->ecmd = 0xff00 | urb->actual_length; | ||
127 | wake_up(&iforce->wait); | ||
128 | } | ||
129 | |||
130 | static int iforce_usb_probe(struct usb_interface *intf, | ||
131 | const struct usb_device_id *id) | ||
132 | { | ||
133 | struct usb_device *dev = interface_to_usbdev(intf); | ||
134 | struct usb_host_interface *interface; | ||
135 | struct usb_endpoint_descriptor *epirq, *epout; | ||
136 | struct iforce *iforce; | ||
137 | |||
138 | interface = intf->cur_altsetting; | ||
139 | |||
140 | epirq = &interface->endpoint[0].desc; | ||
141 | epout = &interface->endpoint[1].desc; | ||
142 | |||
143 | if (!(iforce = kmalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) | ||
144 | goto fail; | ||
145 | |||
146 | memset(iforce, 0, sizeof(struct iforce)); | ||
147 | |||
148 | if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL))) { | ||
149 | goto fail; | ||
150 | } | ||
151 | |||
152 | if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL))) { | ||
153 | goto fail; | ||
154 | } | ||
155 | |||
156 | if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) { | ||
157 | goto fail; | ||
158 | } | ||
159 | |||
160 | iforce->bus = IFORCE_USB; | ||
161 | iforce->usbdev = dev; | ||
162 | |||
163 | iforce->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE; | ||
164 | iforce->cr.wIndex = 0; | ||
165 | iforce->cr.wLength = 16; | ||
166 | |||
167 | usb_fill_int_urb(iforce->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), | ||
168 | iforce->data, 16, iforce_usb_irq, iforce, epirq->bInterval); | ||
169 | |||
170 | usb_fill_bulk_urb(iforce->out, dev, usb_sndbulkpipe(dev, epout->bEndpointAddress), | ||
171 | iforce + 1, 32, iforce_usb_out, iforce); | ||
172 | |||
173 | usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), | ||
174 | (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); | ||
175 | |||
176 | if (iforce_init_device(iforce)) goto fail; | ||
177 | |||
178 | usb_set_intfdata(intf, iforce); | ||
179 | return 0; | ||
180 | |||
181 | fail: | ||
182 | if (iforce) { | ||
183 | if (iforce->irq) usb_free_urb(iforce->irq); | ||
184 | if (iforce->out) usb_free_urb(iforce->out); | ||
185 | if (iforce->ctrl) usb_free_urb(iforce->ctrl); | ||
186 | kfree(iforce); | ||
187 | } | ||
188 | |||
189 | return -ENODEV; | ||
190 | } | ||
191 | |||
192 | /* Called by iforce_delete() */ | ||
193 | void iforce_usb_delete(struct iforce* iforce) | ||
194 | { | ||
195 | usb_unlink_urb(iforce->irq); | ||
196 | /* Is it ok to unlink those ? */ | ||
197 | usb_unlink_urb(iforce->out); | ||
198 | usb_unlink_urb(iforce->ctrl); | ||
199 | |||
200 | usb_free_urb(iforce->irq); | ||
201 | usb_free_urb(iforce->out); | ||
202 | usb_free_urb(iforce->ctrl); | ||
203 | } | ||
204 | |||
205 | static void iforce_usb_disconnect(struct usb_interface *intf) | ||
206 | { | ||
207 | struct iforce *iforce = usb_get_intfdata(intf); | ||
208 | int open = 0; /* FIXME! iforce->dev.handle->open; */ | ||
209 | |||
210 | usb_set_intfdata(intf, NULL); | ||
211 | if (iforce) { | ||
212 | iforce->usbdev = NULL; | ||
213 | input_unregister_device(&iforce->dev); | ||
214 | |||
215 | if (!open) { | ||
216 | iforce_delete_device(iforce); | ||
217 | kfree(iforce); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | static struct usb_device_id iforce_usb_ids [] = { | ||
223 | { USB_DEVICE(0x044f, 0xa01c) }, /* Thrustmaster Motor Sport GT */ | ||
224 | { USB_DEVICE(0x046d, 0xc281) }, /* Logitech WingMan Force */ | ||
225 | { USB_DEVICE(0x046d, 0xc291) }, /* Logitech WingMan Formula Force */ | ||
226 | { USB_DEVICE(0x05ef, 0x020a) }, /* AVB Top Shot Pegasus */ | ||
227 | { USB_DEVICE(0x05ef, 0x8884) }, /* AVB Mag Turbo Force */ | ||
228 | { USB_DEVICE(0x05ef, 0x8888) }, /* AVB Top Shot FFB Racing Wheel */ | ||
229 | { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ | ||
230 | { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ | ||
231 | { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ | ||
232 | { } /* Terminating entry */ | ||
233 | }; | ||
234 | |||
235 | MODULE_DEVICE_TABLE (usb, iforce_usb_ids); | ||
236 | |||
237 | struct usb_driver iforce_usb_driver = { | ||
238 | .owner = THIS_MODULE, | ||
239 | .name = "iforce", | ||
240 | .probe = iforce_usb_probe, | ||
241 | .disconnect = iforce_usb_disconnect, | ||
242 | .id_table = iforce_usb_ids, | ||
243 | }; | ||