diff options
Diffstat (limited to 'drivers/usb/input/xpad.c')
-rw-r--r-- | drivers/usb/input/xpad.c | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c index d65edb22e545..a7fa1b17dcfe 100644 --- a/drivers/usb/input/xpad.c +++ b/drivers/usb/input/xpad.c | |||
@@ -104,13 +104,12 @@ MODULE_DEVICE_TABLE (usb, xpad_table); | |||
104 | struct usb_xpad { | 104 | struct usb_xpad { |
105 | struct input_dev dev; /* input device interface */ | 105 | struct input_dev dev; /* input device interface */ |
106 | struct usb_device *udev; /* usb device */ | 106 | struct usb_device *udev; /* usb device */ |
107 | 107 | ||
108 | struct urb *irq_in; /* urb for interrupt in report */ | 108 | struct urb *irq_in; /* urb for interrupt in report */ |
109 | unsigned char *idata; /* input data */ | 109 | unsigned char *idata; /* input data */ |
110 | dma_addr_t idata_dma; | 110 | dma_addr_t idata_dma; |
111 | 111 | ||
112 | char phys[65]; /* physical device path */ | 112 | char phys[65]; /* physical device path */ |
113 | int open_count; /* reference count */ | ||
114 | }; | 113 | }; |
115 | 114 | ||
116 | /* | 115 | /* |
@@ -128,35 +127,35 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
128 | struct input_dev *dev = &xpad->dev; | 127 | struct input_dev *dev = &xpad->dev; |
129 | 128 | ||
130 | input_regs(dev, regs); | 129 | input_regs(dev, regs); |
131 | 130 | ||
132 | /* left stick */ | 131 | /* left stick */ |
133 | input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12])); | 132 | input_report_abs(dev, ABS_X, (__s16) (((__s16)data[13] << 8) | data[12])); |
134 | input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14])); | 133 | input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[15] << 8) | data[14])); |
135 | 134 | ||
136 | /* right stick */ | 135 | /* right stick */ |
137 | input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16])); | 136 | input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[17] << 8) | data[16])); |
138 | input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18])); | 137 | input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[19] << 8) | data[18])); |
139 | 138 | ||
140 | /* triggers left/right */ | 139 | /* triggers left/right */ |
141 | input_report_abs(dev, ABS_Z, data[10]); | 140 | input_report_abs(dev, ABS_Z, data[10]); |
142 | input_report_abs(dev, ABS_RZ, data[11]); | 141 | input_report_abs(dev, ABS_RZ, data[11]); |
143 | 142 | ||
144 | /* digital pad */ | 143 | /* digital pad */ |
145 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); | 144 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); |
146 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); | 145 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); |
147 | 146 | ||
148 | /* start/back buttons and stick press left/right */ | 147 | /* start/back buttons and stick press left/right */ |
149 | input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); | 148 | input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); |
150 | input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5); | 149 | input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5); |
151 | input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6); | 150 | input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6); |
152 | input_report_key(dev, BTN_THUMBR, data[2] >> 7); | 151 | input_report_key(dev, BTN_THUMBR, data[2] >> 7); |
153 | 152 | ||
154 | /* "analog" buttons A, B, X, Y */ | 153 | /* "analog" buttons A, B, X, Y */ |
155 | input_report_key(dev, BTN_A, data[4]); | 154 | input_report_key(dev, BTN_A, data[4]); |
156 | input_report_key(dev, BTN_B, data[5]); | 155 | input_report_key(dev, BTN_B, data[5]); |
157 | input_report_key(dev, BTN_X, data[6]); | 156 | input_report_key(dev, BTN_X, data[6]); |
158 | input_report_key(dev, BTN_Y, data[7]); | 157 | input_report_key(dev, BTN_Y, data[7]); |
159 | 158 | ||
160 | /* "analog" buttons black, white */ | 159 | /* "analog" buttons black, white */ |
161 | input_report_key(dev, BTN_C, data[8]); | 160 | input_report_key(dev, BTN_C, data[8]); |
162 | input_report_key(dev, BTN_Z, data[9]); | 161 | input_report_key(dev, BTN_Z, data[9]); |
@@ -168,7 +167,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs) | |||
168 | { | 167 | { |
169 | struct usb_xpad *xpad = urb->context; | 168 | struct usb_xpad *xpad = urb->context; |
170 | int retval; | 169 | int retval; |
171 | 170 | ||
172 | switch (urb->status) { | 171 | switch (urb->status) { |
173 | case 0: | 172 | case 0: |
174 | /* success */ | 173 | /* success */ |
@@ -183,7 +182,7 @@ static void xpad_irq_in(struct urb *urb, struct pt_regs *regs) | |||
183 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 182 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); |
184 | goto exit; | 183 | goto exit; |
185 | } | 184 | } |
186 | 185 | ||
187 | xpad_process_packet(xpad, 0, xpad->idata, regs); | 186 | xpad_process_packet(xpad, 0, xpad->idata, regs); |
188 | 187 | ||
189 | exit: | 188 | exit: |
@@ -196,25 +195,19 @@ exit: | |||
196 | static int xpad_open (struct input_dev *dev) | 195 | static int xpad_open (struct input_dev *dev) |
197 | { | 196 | { |
198 | struct usb_xpad *xpad = dev->private; | 197 | struct usb_xpad *xpad = dev->private; |
199 | 198 | ||
200 | if (xpad->open_count++) | ||
201 | return 0; | ||
202 | |||
203 | xpad->irq_in->dev = xpad->udev; | 199 | xpad->irq_in->dev = xpad->udev; |
204 | if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) { | 200 | if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) |
205 | xpad->open_count--; | ||
206 | return -EIO; | 201 | return -EIO; |
207 | } | 202 | |
208 | |||
209 | return 0; | 203 | return 0; |
210 | } | 204 | } |
211 | 205 | ||
212 | static void xpad_close (struct input_dev *dev) | 206 | static void xpad_close (struct input_dev *dev) |
213 | { | 207 | { |
214 | struct usb_xpad *xpad = dev->private; | 208 | struct usb_xpad *xpad = dev->private; |
215 | 209 | ||
216 | if (!--xpad->open_count) | 210 | usb_kill_urb(xpad->irq_in); |
217 | usb_kill_urb(xpad->irq_in); | ||
218 | } | 211 | } |
219 | 212 | ||
220 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) | 213 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) |
@@ -224,19 +217,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
224 | struct usb_endpoint_descriptor *ep_irq_in; | 217 | struct usb_endpoint_descriptor *ep_irq_in; |
225 | char path[64]; | 218 | char path[64]; |
226 | int i; | 219 | int i; |
227 | 220 | ||
228 | for (i = 0; xpad_device[i].idVendor; i++) { | 221 | for (i = 0; xpad_device[i].idVendor; i++) { |
229 | if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && | 222 | if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && |
230 | (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) | 223 | (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) |
231 | break; | 224 | break; |
232 | } | 225 | } |
233 | 226 | ||
234 | if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { | 227 | if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { |
235 | err("cannot allocate memory for new pad"); | 228 | err("cannot allocate memory for new pad"); |
236 | return -ENOMEM; | 229 | return -ENOMEM; |
237 | } | 230 | } |
238 | memset(xpad, 0, sizeof(struct usb_xpad)); | 231 | memset(xpad, 0, sizeof(struct usb_xpad)); |
239 | 232 | ||
240 | xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, | 233 | xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, |
241 | SLAB_ATOMIC, &xpad->idata_dma); | 234 | SLAB_ATOMIC, &xpad->idata_dma); |
242 | if (!xpad->idata) { | 235 | if (!xpad->idata) { |
@@ -251,18 +244,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
251 | kfree(xpad); | 244 | kfree(xpad); |
252 | return -ENOMEM; | 245 | return -ENOMEM; |
253 | } | 246 | } |
254 | 247 | ||
255 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; | 248 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; |
256 | 249 | ||
257 | usb_fill_int_urb(xpad->irq_in, udev, | 250 | usb_fill_int_urb(xpad->irq_in, udev, |
258 | usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), | 251 | usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), |
259 | xpad->idata, XPAD_PKT_LEN, xpad_irq_in, | 252 | xpad->idata, XPAD_PKT_LEN, xpad_irq_in, |
260 | xpad, ep_irq_in->bInterval); | 253 | xpad, ep_irq_in->bInterval); |
261 | xpad->irq_in->transfer_dma = xpad->idata_dma; | 254 | xpad->irq_in->transfer_dma = xpad->idata_dma; |
262 | xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 255 | xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
263 | 256 | ||
264 | xpad->udev = udev; | 257 | xpad->udev = udev; |
265 | 258 | ||
266 | xpad->dev.id.bustype = BUS_USB; | 259 | xpad->dev.id.bustype = BUS_USB; |
267 | xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); | 260 | xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); |
268 | xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct); | 261 | xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct); |
@@ -273,21 +266,21 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
273 | xpad->dev.phys = xpad->phys; | 266 | xpad->dev.phys = xpad->phys; |
274 | xpad->dev.open = xpad_open; | 267 | xpad->dev.open = xpad_open; |
275 | xpad->dev.close = xpad_close; | 268 | xpad->dev.close = xpad_close; |
276 | 269 | ||
277 | usb_make_path(udev, path, 64); | 270 | usb_make_path(udev, path, 64); |
278 | snprintf(xpad->phys, 64, "%s/input0", path); | 271 | snprintf(xpad->phys, 64, "%s/input0", path); |
279 | 272 | ||
280 | xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 273 | xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
281 | 274 | ||
282 | for (i = 0; xpad_btn[i] >= 0; i++) | 275 | for (i = 0; xpad_btn[i] >= 0; i++) |
283 | set_bit(xpad_btn[i], xpad->dev.keybit); | 276 | set_bit(xpad_btn[i], xpad->dev.keybit); |
284 | 277 | ||
285 | for (i = 0; xpad_abs[i] >= 0; i++) { | 278 | for (i = 0; xpad_abs[i] >= 0; i++) { |
286 | 279 | ||
287 | signed short t = xpad_abs[i]; | 280 | signed short t = xpad_abs[i]; |
288 | 281 | ||
289 | set_bit(t, xpad->dev.absbit); | 282 | set_bit(t, xpad->dev.absbit); |
290 | 283 | ||
291 | switch (t) { | 284 | switch (t) { |
292 | case ABS_X: | 285 | case ABS_X: |
293 | case ABS_Y: | 286 | case ABS_Y: |
@@ -310,11 +303,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
310 | break; | 303 | break; |
311 | } | 304 | } |
312 | } | 305 | } |
313 | 306 | ||
314 | input_register_device(&xpad->dev); | 307 | input_register_device(&xpad->dev); |
315 | 308 | ||
316 | printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); | 309 | printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); |
317 | 310 | ||
318 | usb_set_intfdata(intf, xpad); | 311 | usb_set_intfdata(intf, xpad); |
319 | return 0; | 312 | return 0; |
320 | } | 313 | } |
@@ -322,7 +315,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
322 | static void xpad_disconnect(struct usb_interface *intf) | 315 | static void xpad_disconnect(struct usb_interface *intf) |
323 | { | 316 | { |
324 | struct usb_xpad *xpad = usb_get_intfdata (intf); | 317 | struct usb_xpad *xpad = usb_get_intfdata (intf); |
325 | 318 | ||
326 | usb_set_intfdata(intf, NULL); | 319 | usb_set_intfdata(intf, NULL); |
327 | if (xpad) { | 320 | if (xpad) { |
328 | usb_kill_urb(xpad->irq_in); | 321 | usb_kill_urb(xpad->irq_in); |