spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / drivers / input / joystick / iforce / iforce-usb.c
blob6c96631ae5d9faff42fbe8e21969e78fca1133f4
1 /*
2 * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
3 * Copyright (c) 2001-2002, 2007 Johann Deneux <johann.deneux@gmail.com>
5 * USB/RS232 I-Force joysticks and wheels.
6 */
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.
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.
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
23 * Should you need to contact me, the author, you can do so either by
24 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
25 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
28 #include "iforce.h"
30 void iforce_usb_xmit(struct iforce *iforce)
32 int n, c;
33 unsigned long flags;
35 spin_lock_irqsave(&iforce->xmit_lock, flags);
37 if (iforce->xmit.head == iforce->xmit.tail) {
38 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
39 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
40 return;
43 ((char *)iforce->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail];
44 XMIT_INC(iforce->xmit.tail, 1);
45 n = iforce->xmit.buf[iforce->xmit.tail];
46 XMIT_INC(iforce->xmit.tail, 1);
48 iforce->out->transfer_buffer_length = n + 1;
49 iforce->out->dev = iforce->usbdev;
51 /* Copy rest of data then */
52 c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE);
53 if (n < c) c=n;
55 memcpy(iforce->out->transfer_buffer + 1,
56 &iforce->xmit.buf[iforce->xmit.tail],
57 c);
58 if (n != c) {
59 memcpy(iforce->out->transfer_buffer + 1 + c,
60 &iforce->xmit.buf[0],
61 n-c);
63 XMIT_INC(iforce->xmit.tail, n);
65 if ( (n=usb_submit_urb(iforce->out, GFP_ATOMIC)) ) {
66 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
67 dev_warn(&iforce->dev->dev, "usb_submit_urb failed %d\n", n);
70 /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended.
71 * As long as the urb completion handler is not called, the transmiting
72 * is considered to be running */
73 spin_unlock_irqrestore(&iforce->xmit_lock, flags);
76 static void iforce_usb_irq(struct urb *urb)
78 struct iforce *iforce = urb->context;
79 int status;
81 switch (urb->status) {
82 case 0:
83 /* success */
84 break;
85 case -ECONNRESET:
86 case -ENOENT:
87 case -ESHUTDOWN:
88 /* this urb is terminated, clean up */
89 dbg("%s - urb shutting down with status: %d",
90 __func__, urb->status);
91 return;
92 default:
93 dbg("%s - urb has status of: %d", __func__, urb->status);
94 goto exit;
97 iforce_process_packet(iforce,
98 (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1);
100 exit:
101 status = usb_submit_urb (urb, GFP_ATOMIC);
102 if (status)
103 err ("%s - usb_submit_urb failed with result %d",
104 __func__, status);
107 static void iforce_usb_out(struct urb *urb)
109 struct iforce *iforce = urb->context;
111 if (urb->status) {
112 clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags);
113 dbg("urb->status %d, exiting", urb->status);
114 return;
117 iforce_usb_xmit(iforce);
119 wake_up(&iforce->wait);
122 static void iforce_usb_ctrl(struct urb *urb)
124 struct iforce *iforce = urb->context;
125 if (urb->status) return;
126 iforce->ecmd = 0xff00 | urb->actual_length;
127 wake_up(&iforce->wait);
130 static int iforce_usb_probe(struct usb_interface *intf,
131 const struct usb_device_id *id)
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 int err = -ENOMEM;
139 interface = intf->cur_altsetting;
141 epirq = &interface->endpoint[0].desc;
142 epout = &interface->endpoint[1].desc;
144 if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL)))
145 goto fail;
147 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL)))
148 goto fail;
150 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL)))
151 goto fail;
153 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
154 goto fail;
156 iforce->bus = IFORCE_USB;
157 iforce->usbdev = dev;
159 iforce->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE;
160 iforce->cr.wIndex = 0;
161 iforce->cr.wLength = cpu_to_le16(16);
163 usb_fill_int_urb(iforce->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress),
164 iforce->data, 16, iforce_usb_irq, iforce, epirq->bInterval);
166 usb_fill_int_urb(iforce->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress),
167 iforce + 1, 32, iforce_usb_out, iforce, epout->bInterval);
169 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0),
170 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce);
172 err = iforce_init_device(iforce);
173 if (err)
174 goto fail;
176 usb_set_intfdata(intf, iforce);
177 return 0;
179 fail:
180 if (iforce) {
181 usb_free_urb(iforce->irq);
182 usb_free_urb(iforce->out);
183 usb_free_urb(iforce->ctrl);
184 kfree(iforce);
187 return err;
190 static void iforce_usb_disconnect(struct usb_interface *intf)
192 struct iforce *iforce = usb_get_intfdata(intf);
194 usb_set_intfdata(intf, NULL);
196 input_unregister_device(iforce->dev);
198 usb_free_urb(iforce->irq);
199 usb_free_urb(iforce->out);
200 usb_free_urb(iforce->ctrl);
202 kfree(iforce);
205 static struct usb_device_id iforce_usb_ids [] = {
206 { USB_DEVICE(0x044f, 0xa01c) }, /* Thrustmaster Motor Sport GT */
207 { USB_DEVICE(0x046d, 0xc281) }, /* Logitech WingMan Force */
208 { USB_DEVICE(0x046d, 0xc291) }, /* Logitech WingMan Formula Force */
209 { USB_DEVICE(0x05ef, 0x020a) }, /* AVB Top Shot Pegasus */
210 { USB_DEVICE(0x05ef, 0x8884) }, /* AVB Mag Turbo Force */
211 { USB_DEVICE(0x05ef, 0x8888) }, /* AVB Top Shot FFB Racing Wheel */
212 { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */
213 { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */
214 { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */
215 { USB_DEVICE(0x06f8, 0x0003) }, /* Guillemot Jet Leader Force Feedback */
216 { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */
217 { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */
218 { } /* Terminating entry */
221 MODULE_DEVICE_TABLE (usb, iforce_usb_ids);
223 struct usb_driver iforce_usb_driver = {
224 .name = "iforce",
225 .probe = iforce_usb_probe,
226 .disconnect = iforce_usb_disconnect,
227 .id_table = iforce_usb_ids,