Commit 98caa79c authored by David S. Miller's avatar David S. Miller

This converts all of the input USB drivers to manage DMA

buffers via usb_buffer_alloc in 2.5.x  This helps platforms
where doing a pci_{map,unmap}_single() on every input event
is very inefficient.

Also adds a missing kfree(hid), because the HID struct was never
freed.
parent 58c2e6e8
...@@ -113,13 +113,15 @@ struct aiptek_features { ...@@ -113,13 +113,15 @@ struct aiptek_features {
}; };
struct aiptek { struct aiptek {
signed char data[10];
struct input_dev dev; struct input_dev dev;
struct usb_device *usbdev; struct usb_device *usbdev;
struct urb *irq; struct urb *irq;
struct aiptek_features *features; struct aiptek_features *features;
int tool; int tool;
int open; int open;
signed char *data;
dma_addr_t data_dma;
}; };
static void static void
...@@ -235,8 +237,15 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -235,8 +237,15 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum,
memset(aiptek, 0, sizeof (struct aiptek)); memset(aiptek, 0, sizeof (struct aiptek));
aiptek->data = usb_buffer_alloc(dev, 10, SLAB_ATOMIC, &aiptek->data_dma);
if (!aiptek->data) {
kfree(aiptek);
return NULL;
}
aiptek->irq = usb_alloc_urb(0, GFP_KERNEL); aiptek->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!aiptek->irq) { if (!aiptek->irq) {
usb_buffer_free(dev, 10, aiptek->data, aiptek->data_dma);
kfree(aiptek); kfree(aiptek);
return NULL; return NULL;
} }
...@@ -287,14 +296,15 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -287,14 +296,15 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum,
endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0; endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(aiptek->irq, if (aiptek->features->pktlen > 10)
dev, BUG();
usb_fill_int_urb(aiptek->irq, dev,
usb_rcvintpipe(dev, endpoint->bEndpointAddress), usb_rcvintpipe(dev, endpoint->bEndpointAddress),
aiptek->data, aiptek->data, aiptek->features->pktlen,
aiptek->features->pktlen, aiptek->features->irq, aiptek, endpoint->bInterval);
aiptek->features->irq, aiptek->irq->transfer_dma = aiptek->data_dma;
aiptek, aiptek->irq->transfer_flags |= URB_NO_DMA_MAP;
endpoint->bInterval);
input_register_device(&aiptek->dev); input_register_device(&aiptek->dev);
...@@ -311,6 +321,7 @@ aiptek_disconnect(struct usb_device *dev, void *ptr) ...@@ -311,6 +321,7 @@ aiptek_disconnect(struct usb_device *dev, void *ptr)
usb_unlink_urb(aiptek->irq); usb_unlink_urb(aiptek->irq);
input_unregister_device(&aiptek->dev); input_unregister_device(&aiptek->dev);
usb_free_urb(aiptek->irq); usb_free_urb(aiptek->irq);
usb_buffer_free(dev, 10, aiptek->data, aiptek->data_dma);
kfree(aiptek); kfree(aiptek);
} }
......
/* /*
* $Id: hid-core.c,v 1.6 2002/06/09 17:34:55 jdeneux Exp $ * USB HID support for Linux
* *
* Copyright (c) 1999 Andreas Gal * Copyright (c) 1999 Andreas Gal
* Copyright (c) 2000-2001 Vojtech Pavlik * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@suse.cz>
*
* USB HID support for Linux
*/ */
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify it
* it under the terms of the GNU General Public License as published by * under the terms of the GNU General Public License as published by the Free
* the Free Software Foundation; either version 2 of the License, or * Software Foundation; either version 2 of the License, or (at your option)
* (at your option) any later version. * any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Should you need to contact me, the author, you can do so either by
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -52,8 +37,8 @@ ...@@ -52,8 +37,8 @@
* Version Information * Version Information
*/ */
#define DRIVER_VERSION "v1.31" #define DRIVER_VERSION "v2.0"
#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik <vojtech@ucw.cz>" #define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
#define DRIVER_DESC "USB HID core driver" #define DRIVER_DESC "USB HID core driver"
#define DRIVER_LICENSE "GPL" #define DRIVER_LICENSE "GPL"
...@@ -559,6 +544,7 @@ static void hid_free_device(struct hid_device *device) ...@@ -559,6 +544,7 @@ static void hid_free_device(struct hid_device *device)
} }
if (device->rdesc) kfree(device->rdesc); if (device->rdesc) kfree(device->rdesc);
kfree(device);
} }
/* /*
...@@ -651,9 +637,8 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size) ...@@ -651,9 +637,8 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
return NULL; return NULL;
memset(device, 0, sizeof(struct hid_device)); memset(device, 0, sizeof(struct hid_device));
if (!(device->collection = kmalloc(sizeof(struct hid_collection) * if (!(device->collection =kmalloc(sizeof(struct hid_collection) *
HID_DEFAULT_NUM_COLLECTIONS, HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
GFP_KERNEL))) {
kfree(device); kfree(device);
return NULL; return NULL;
} }
...@@ -1071,11 +1056,11 @@ static int hid_submit_ctrl(struct hid_device *hid) ...@@ -1071,11 +1056,11 @@ static int hid_submit_ctrl(struct hid_device *hid)
hid->urbctrl->pipe = (dir == USB_DIR_OUT) ? usb_sndctrlpipe(hid->dev, 0) : usb_rcvctrlpipe(hid->dev, 0); hid->urbctrl->pipe = (dir == USB_DIR_OUT) ? usb_sndctrlpipe(hid->dev, 0) : usb_rcvctrlpipe(hid->dev, 0);
hid->urbctrl->dev = hid->dev; hid->urbctrl->dev = hid->dev;
hid->cr.bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; hid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
hid->cr.bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; hid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
hid->cr.wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); hid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
hid->cr.wIndex = cpu_to_le16(hid->ifnum); hid->cr->wIndex = cpu_to_le16(hid->ifnum);
hid->cr.wLength = cpu_to_le16(hid->urbctrl->transfer_buffer_length); hid->cr->wLength = cpu_to_le16(hid->urbctrl->transfer_buffer_length);
dbg("submitting ctrl urb"); dbg("submitting ctrl urb");
...@@ -1338,6 +1323,32 @@ struct hid_blacklist { ...@@ -1338,6 +1323,32 @@ struct hid_blacklist {
{ 0, 0 } { 0, 0 }
}; };
static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
{
if (!(hid->inbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->inbuf_dma)))
return -1;
if (!(hid->outbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->outbuf_dma)))
return -1;
if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma)))
return -1;
if (!(hid->ctrlbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->ctrlbuf_dma)))
return -1;
return 0;
}
static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
{
if (hid->inbuf)
usb_buffer_free(dev, HID_BUFFER_SIZE, hid->inbuf, hid->inbuf_dma);
if (hid->outbuf)
usb_buffer_free(dev, HID_BUFFER_SIZE, hid->outbuf, hid->outbuf_dma);
if (hid->cr)
usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma);
if (hid->ctrlbuf)
usb_buffer_free(dev, HID_BUFFER_SIZE, hid->ctrlbuf, hid->ctrlbuf_dma);
}
static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum) static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum)
{ {
struct usb_interface_descriptor *interface = dev->actconfig->interface[ifnum].altsetting + 0; struct usb_interface_descriptor *interface = dev->actconfig->interface[ifnum].altsetting + 0;
...@@ -1397,6 +1408,11 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum) ...@@ -1397,6 +1408,11 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum)
kfree(rdesc); kfree(rdesc);
hid->quirks = quirks; hid->quirks = quirks;
if (hid_alloc_buffers(dev, hid)) {
hid_free_buffers(dev, hid);
goto fail;
}
for (n = 0; n < interface->bNumEndpoints; n++) { for (n = 0; n < interface->bNumEndpoints; n++) {
struct usb_endpoint_descriptor *endpoint = &interface->endpoint[n]; struct usb_endpoint_descriptor *endpoint = &interface->endpoint[n];
...@@ -1411,14 +1427,20 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum) ...@@ -1411,14 +1427,20 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum)
if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
FILL_INT_URB(hid->urbin, dev, pipe, hid->inbuf, 0, hid_irq_in, hid, endpoint->bInterval); usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, 0,
hid_irq_in, hid, endpoint->bInterval);
hid->urbin->transfer_dma = hid->inbuf_dma;
hid->urbin->transfer_flags |= URB_NO_DMA_MAP;
} else { } else {
if (hid->urbout) if (hid->urbout)
continue; continue;
if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL))) if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
pipe = usb_sndbulkpipe(dev, endpoint->bEndpointAddress); pipe = usb_sndbulkpipe(dev, endpoint->bEndpointAddress);
FILL_BULK_URB(hid->urbout, dev, pipe, hid->outbuf, 0, hid_irq_out, hid); usb_fill_bulk_urb(hid->urbout, dev, pipe, hid->outbuf, 0,
hid_irq_out, hid);
hid->urbout->transfer_dma = hid->outbuf_dma;
hid->urbout->transfer_flags |= URB_NO_DMA_MAP;
} }
} }
...@@ -1458,16 +1480,21 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum) ...@@ -1458,16 +1480,21 @@ static struct hid_device *usb_hid_configure(struct usb_device *dev, int ifnum)
kfree(buf); kfree(buf);
hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
FILL_CONTROL_URB(hid->urbctrl, dev, 0, (void*) &hid->cr, hid->ctrlbuf, 1, hid_ctrl, hid); usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr,
hid->ctrlbuf, 1, hid_ctrl, hid);
hid->urbctrl->setup_dma = hid->cr_dma;
hid->urbctrl->transfer_dma = hid->ctrlbuf_dma;
hid->urbctrl->transfer_flags |= URB_NO_DMA_MAP;
return hid; return hid;
fail: fail:
hid_free_device(hid);
if (hid->urbin) usb_free_urb(hid->urbin); if (hid->urbin) usb_free_urb(hid->urbin);
if (hid->urbout) usb_free_urb(hid->urbout); if (hid->urbout) usb_free_urb(hid->urbout);
if (hid->urbctrl) usb_free_urb(hid->urbctrl); if (hid->urbctrl) usb_free_urb(hid->urbctrl);
hid_free_buffers(dev, hid);
hid_free_device(hid);
return NULL; return NULL;
} }
...@@ -1490,6 +1517,7 @@ static void hid_disconnect(struct usb_device *dev, void *ptr) ...@@ -1490,6 +1517,7 @@ static void hid_disconnect(struct usb_device *dev, void *ptr)
if (hid->urbout) if (hid->urbout)
usb_free_urb(hid->urbout); usb_free_urb(hid->urbout);
hid_free_buffers(dev, hid);
hid_free_device(hid); hid_free_device(hid);
} }
......
...@@ -337,19 +337,23 @@ struct hid_device { /* device report descriptor */ ...@@ -337,19 +337,23 @@ struct hid_device { /* device report descriptor */
unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
struct urb *urbin; /* Input URB */ struct urb *urbin; /* Input URB */
char inbuf[HID_BUFFER_SIZE]; /* Input buffer */ char *inbuf; /* Input buffer */
dma_addr_t inbuf_dma; /* Input buffer dma */
struct urb *urbctrl; /* Control URB */ struct urb *urbctrl; /* Control URB */
struct usb_ctrlrequest cr; /* Control request struct */ struct usb_ctrlrequest *cr; /* Control request struct */
dma_addr_t cr_dma; /* Control request struct dma */
struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */ struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
char ctrlbuf[HID_BUFFER_SIZE]; /* Control buffer */ char *ctrlbuf; /* Control buffer */
dma_addr_t ctrlbuf_dma; /* Control buffer dma */
spinlock_t ctrllock; /* Control fifo spinlock */ spinlock_t ctrllock; /* Control fifo spinlock */
struct urb *urbout; /* Output URB */ struct urb *urbout; /* Output URB */
struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
unsigned char outhead, outtail; /* Output pipe fifo head & tail */ unsigned char outhead, outtail; /* Output pipe fifo head & tail */
char outbuf[HID_BUFFER_SIZE]; /* Output buffer */ char *outbuf; /* Output buffer */
dma_addr_t outbuf_dma; /* Output buffer dma */
spinlock_t outlock; /* Output fifo spinlock */ spinlock_t outlock; /* Output fifo spinlock */
unsigned claimed; /* Claimed by hidinput, hiddev? */ unsigned claimed; /* Claimed by hidinput, hiddev? */
......
...@@ -52,9 +52,11 @@ ...@@ -52,9 +52,11 @@
#define POWERMATE_PAYLOAD_SIZE 3 #define POWERMATE_PAYLOAD_SIZE 3
struct powermate_device { struct powermate_device {
signed char data[POWERMATE_PAYLOAD_SIZE]; signed char *data;
struct urb irq, config; dma_addr_t data_dma;
struct usb_ctrlrequest configcr; struct urb *irq, *config;
struct usb_ctrlrequest *configcr;
dma_addr_t configcr_dma;
struct usb_device *udev; struct usb_device *udev;
struct input_dev input; struct input_dev input;
struct semaphore lock; struct semaphore lock;
...@@ -77,7 +79,7 @@ static void powermate_irq(struct urb *urb) ...@@ -77,7 +79,7 @@ static void powermate_irq(struct urb *urb)
{ {
struct powermate_device *pm = urb->context; struct powermate_device *pm = urb->context;
if(urb->status) if (urb->status)
return; return;
/* handle updates to device state */ /* handle updates to device state */
...@@ -89,24 +91,24 @@ static void powermate_irq(struct urb *urb) ...@@ -89,24 +91,24 @@ static void powermate_irq(struct urb *urb)
/* Decide if we need to issue a control message and do so. Must be called with pm->lock down */ /* Decide if we need to issue a control message and do so. Must be called with pm->lock down */
static void powermate_sync_state(struct powermate_device *pm) static void powermate_sync_state(struct powermate_device *pm)
{ {
if(pm->requires_update == 0) if (pm->requires_update == 0)
return; /* no updates are required */ return; /* no updates are required */
if(pm->config.status == -EINPROGRESS) if (pm->config->status == -EINPROGRESS)
return; /* an update is already in progress; it'll issue this update when it completes */ return; /* an update is already in progress; it'll issue this update when it completes */
if(pm->requires_update & UPDATE_STATIC_BRIGHTNESS){ if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS){
pm->configcr.wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS ); pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
pm->configcr.wIndex = cpu_to_le16( pm->static_brightness ); pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS; pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
}else if(pm->requires_update & UPDATE_PULSE_ASLEEP){ }else if (pm->requires_update & UPDATE_PULSE_ASLEEP){
pm->configcr.wValue = cpu_to_le16( SET_PULSE_ASLEEP ); pm->configcr->wValue = cpu_to_le16( SET_PULSE_ASLEEP );
pm->configcr.wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 ); pm->configcr->wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
pm->requires_update &= ~UPDATE_PULSE_ASLEEP; pm->requires_update &= ~UPDATE_PULSE_ASLEEP;
}else if(pm->requires_update & UPDATE_PULSE_AWAKE){ }else if (pm->requires_update & UPDATE_PULSE_AWAKE){
pm->configcr.wValue = cpu_to_le16( SET_PULSE_AWAKE ); pm->configcr->wValue = cpu_to_le16( SET_PULSE_AWAKE );
pm->configcr.wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 ); pm->configcr->wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
pm->requires_update &= ~UPDATE_PULSE_AWAKE; pm->requires_update &= ~UPDATE_PULSE_AWAKE;
}else if(pm->requires_update & UPDATE_PULSE_MODE){ }else if (pm->requires_update & UPDATE_PULSE_MODE){
int op, arg; int op, arg;
/* the powermate takes an operation and an argument for its pulse algorithm. /* the powermate takes an operation and an argument for its pulse algorithm.
the operation can be: the operation can be:
...@@ -125,18 +127,18 @@ static void powermate_sync_state(struct powermate_device *pm) ...@@ -125,18 +127,18 @@ static void powermate_sync_state(struct powermate_device *pm)
Only values of 'arg' quite close to 255 are particularly useful/spectacular. Only values of 'arg' quite close to 255 are particularly useful/spectacular.
*/ */
if(pm->pulse_speed < 255){ if (pm->pulse_speed < 255){
op = 0; // divide op = 0; // divide
arg = 255 - pm->pulse_speed; arg = 255 - pm->pulse_speed;
}else if(pm->pulse_speed > 255){ } else if (pm->pulse_speed > 255){
op = 2; // multiply op = 2; // multiply
arg = pm->pulse_speed - 255; arg = pm->pulse_speed - 255;
}else{ } else {
op = 1; // normal speed op = 1; // normal speed
arg = 0; // can be any value arg = 0; // can be any value
} }
pm->configcr.wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE ); pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
pm->configcr.wIndex = cpu_to_le16( (arg << 8) | op ); pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
pm->requires_update &= ~UPDATE_PULSE_MODE; pm->requires_update &= ~UPDATE_PULSE_MODE;
}else{ }else{
printk(KERN_ERR "powermate: unknown update required"); printk(KERN_ERR "powermate: unknown update required");
...@@ -144,17 +146,19 @@ static void powermate_sync_state(struct powermate_device *pm) ...@@ -144,17 +146,19 @@ static void powermate_sync_state(struct powermate_device *pm)
return; return;
} }
/* printk("powermate: %04x %04x\n", pm->configcr.wValue, pm->configcr.wIndex); */ /* printk("powermate: %04x %04x\n", pm->configcr->wValue, pm->configcr->wIndex); */
pm->config.dev = pm->udev; /* is this necessary? */ pm->configcr->bRequestType = 0x41; /* vendor request */
pm->configcr.bRequestType = 0x41; /* vendor request */ pm->configcr->bRequest = 0x01;
pm->configcr.bRequest = 0x01; pm->configcr->wLength = 0;
pm->configcr.wLength = 0;
FILL_CONTROL_URB(&pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0), usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
(void*)&pm->configcr, 0, 0, powermate_config_complete, pm); (void *) pm->configcr, 0, 0,
powermate_config_complete, pm);
pm->config->setup_dma = pm->configcr_dma;
pm->config->transfer_flags |= URB_NO_DMA_MAP;
if(usb_submit_urb(&pm->config, GFP_ATOMIC)) if (usb_submit_urb(pm->config, GFP_ATOMIC))
printk(KERN_ERR "powermate: usb_submit_urb(config) failed"); printk(KERN_ERR "powermate: usb_submit_urb(config) failed");
} }
...@@ -163,7 +167,7 @@ static void powermate_config_complete(struct urb *urb) ...@@ -163,7 +167,7 @@ static void powermate_config_complete(struct urb *urb)
{ {
struct powermate_device *pm = urb->context; struct powermate_device *pm = urb->context;
if(urb->status) if (urb->status)
printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
down(&pm->lock); down(&pm->lock);
...@@ -175,13 +179,13 @@ static void powermate_config_complete(struct urb *urb) ...@@ -175,13 +179,13 @@ static void powermate_config_complete(struct urb *urb)
static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
int pulse_table, int pulse_asleep, int pulse_awake) int pulse_table, int pulse_asleep, int pulse_awake)
{ {
if(pulse_speed < 0) if (pulse_speed < 0)
pulse_speed = 0; pulse_speed = 0;
if(pulse_table < 0) if (pulse_table < 0)
pulse_table = 0; pulse_table = 0;
if(pulse_speed > 510) if (pulse_speed > 510)
pulse_speed = 510; pulse_speed = 510;
if(pulse_table > 2) if (pulse_table > 2)
pulse_table = 2; pulse_table = 2;
pulse_asleep = !!pulse_asleep; pulse_asleep = !!pulse_asleep;
...@@ -190,19 +194,19 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne ...@@ -190,19 +194,19 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
down(&pm->lock); down(&pm->lock);
/* mark state updates which are required */ /* mark state updates which are required */
if(static_brightness != pm->static_brightness){ if (static_brightness != pm->static_brightness){
pm->static_brightness = static_brightness; pm->static_brightness = static_brightness;
pm->requires_update |= UPDATE_STATIC_BRIGHTNESS; pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
} }
if(pulse_asleep != pm->pulse_asleep){ if (pulse_asleep != pm->pulse_asleep){
pm->pulse_asleep = pulse_asleep; pm->pulse_asleep = pulse_asleep;
pm->requires_update |= UPDATE_PULSE_ASLEEP; pm->requires_update |= UPDATE_PULSE_ASLEEP;
} }
if(pulse_awake != pm->pulse_awake){ if (pulse_awake != pm->pulse_awake){
pm->pulse_awake = pulse_awake; pm->pulse_awake = pulse_awake;
pm->requires_update |= UPDATE_PULSE_AWAKE; pm->requires_update |= UPDATE_PULSE_AWAKE;
} }
if(pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table){ if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table){
pm->pulse_speed = pulse_speed; pm->pulse_speed = pulse_speed;
pm->pulse_table = pulse_table; pm->pulse_table = pulse_table;
pm->requires_update |= UPDATE_PULSE_MODE; pm->requires_update |= UPDATE_PULSE_MODE;
...@@ -219,7 +223,7 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig ...@@ -219,7 +223,7 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
unsigned int command = (unsigned int)_value; unsigned int command = (unsigned int)_value;
struct powermate_device *pm = dev->private; struct powermate_device *pm = dev->private;
if(type == EV_MSC && code == MSC_PULSELED){ if (type == EV_MSC && code == MSC_PULSELED){
/* /*
bits 0- 7: 8 bits: LED brightness bits 0- 7: 8 bits: LED brightness
bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster. bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
...@@ -239,6 +243,30 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig ...@@ -239,6 +243,30 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
return 0; return 0;
} }
static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm)
{
pm->data = usb_buffer_alloc(udev, POWERMATE_PAYLOAD_SIZE,
SLAB_ATOMIC, &pm->data_dma);
if (!pm->data)
return -1;
pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)),
SLAB_ATOMIC, &pm->configcr_dma);
if (!pm->configcr)
return -1;
return 0;
}
static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm)
{
if (pm->data)
usb_buffer_free(udev, POWERMATE_PAYLOAD_SIZE,
pm->data, pm->data_dma);
if (pm->configcr)
usb_buffer_free(udev, sizeof(*(pm->configcr)),
pm->configcr, pm->configcr_dma);
}
/* Called whenever a USB device matching one in our supported devices table is connected */ /* Called whenever a USB device matching one in our supported devices table is connected */
static void *powermate_probe(struct usb_device *udev, unsigned int ifnum, const struct usb_device_id *id) static void *powermate_probe(struct usb_device *udev, unsigned int ifnum, const struct usb_device_id *id)
{ {
...@@ -264,19 +292,46 @@ static void *powermate_probe(struct usb_device *udev, unsigned int ifnum, const ...@@ -264,19 +292,46 @@ static void *powermate_probe(struct usb_device *udev, unsigned int ifnum, const
memset(pm, 0, sizeof(struct powermate_device)); memset(pm, 0, sizeof(struct powermate_device));
pm->udev = udev; pm->udev = udev;
if (powermate_alloc_buffers(udev, pm)) {
powermate_free_buffers(udev, pm);
kfree(pm);
return NULL;
}
pm->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!pm->irq) {
powermate_free_buffers(udev, pm);
kfree(pm);
return NULL;
}
pm->config = usb_alloc_urb(0, GFP_KERNEL);
if (!pm->config) {
usb_free_urb(pm->irq);
powermate_free_buffers(udev, pm);
kfree(pm);
return NULL;
}
init_MUTEX(&pm->lock); init_MUTEX(&pm->lock);
/* get a handle to the interrupt data pipe */ /* get a handle to the interrupt data pipe */
pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
if(maxp != POWERMATE_PAYLOAD_SIZE) if (maxp != POWERMATE_PAYLOAD_SIZE)
printk("powermate: Expected payload of %d bytes, found %d bytes!\n", POWERMATE_PAYLOAD_SIZE, maxp); printk("powermate: Expected payload of %d bytes, found %d bytes!\n", POWERMATE_PAYLOAD_SIZE, maxp);
FILL_INT_URB(&pm->irq, udev, pipe, pm->data, POWERMATE_PAYLOAD_SIZE, powermate_irq, pm, endpoint->bInterval);
usb_fill_int_urb(pm->irq, udev, pipe, pm->data,
POWERMATE_PAYLOAD_SIZE, powermate_irq,
pm, endpoint->bInterval);
pm->irq->transfer_dma = pm->data_dma;
pm->irq->transfer_flags |= URB_NO_DMA_MAP;
/* register our interrupt URB with the USB system */ /* register our interrupt URB with the USB system */
if(usb_submit_urb(&pm->irq, GFP_KERNEL)) { if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
powermate_free_buffers(udev, pm);
kfree(pm); kfree(pm);
return NULL; /* failure */ return NULL; /* failure */
} }
...@@ -319,8 +374,11 @@ static void powermate_disconnect(struct usb_device *dev, void *ptr) ...@@ -319,8 +374,11 @@ static void powermate_disconnect(struct usb_device *dev, void *ptr)
struct powermate_device *pm = ptr; struct powermate_device *pm = ptr;
down(&pm->lock); down(&pm->lock);
pm->requires_update = 0; pm->requires_update = 0;
usb_unlink_urb(&pm->irq); usb_unlink_urb(pm->irq);
input_unregister_device(&pm->input); input_unregister_device(&pm->input);
usb_free_urb(pm->irq);
usb_free_urb(pm->config);
powermate_free_buffers(dev, pm);
kfree(pm); kfree(pm);
} }
......
...@@ -67,14 +67,19 @@ static unsigned char usb_kbd_keycode[256] = { ...@@ -67,14 +67,19 @@ static unsigned char usb_kbd_keycode[256] = {
struct usb_kbd { struct usb_kbd {
struct input_dev dev; struct input_dev dev;
struct usb_device *usbdev; struct usb_device *usbdev;
unsigned char new[8];
unsigned char old[8]; unsigned char old[8];
struct urb *irq, *led; struct urb *irq, *led;
struct usb_ctrlrequest cr; unsigned char newleds;
unsigned char leds, newleds;
char name[128]; char name[128];
char phys[64]; char phys[64];
int open; int open;
unsigned char *new;
struct usb_ctrlrequest *cr;
unsigned char *leds;
dma_addr_t cr_dma;
dma_addr_t new_dma;
dma_addr_t leds_dma;
}; };
static void usb_kbd_irq(struct urb *urb) static void usb_kbd_irq(struct urb *urb)
...@@ -123,10 +128,10 @@ int usb_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, i ...@@ -123,10 +128,10 @@ int usb_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, i
if (kbd->led->status == -EINPROGRESS) if (kbd->led->status == -EINPROGRESS)
return 0; return 0;
if (kbd->leds == kbd->newleds) if (*(kbd->leds) == kbd->newleds)
return 0; return 0;
kbd->leds = kbd->newleds; *(kbd->leds) = kbd->newleds;
kbd->led->dev = kbd->usbdev; kbd->led->dev = kbd->usbdev;
if (usb_submit_urb(kbd->led, GFP_ATOMIC)) if (usb_submit_urb(kbd->led, GFP_ATOMIC))
err("usb_submit_urb(leds) failed"); err("usb_submit_urb(leds) failed");
...@@ -141,10 +146,10 @@ static void usb_kbd_led(struct urb *urb) ...@@ -141,10 +146,10 @@ static void usb_kbd_led(struct urb *urb)
if (urb->status) if (urb->status)
warn("led urb status %d received", urb->status); warn("led urb status %d received", urb->status);
if (kbd->leds == kbd->newleds) if (*(kbd->leds) == kbd->newleds)
return; return;
kbd->leds = kbd->newleds; *(kbd->leds) = kbd->newleds;
kbd->led->dev = kbd->usbdev; kbd->led->dev = kbd->usbdev;
if (usb_submit_urb(kbd->led, GFP_ATOMIC)) if (usb_submit_urb(kbd->led, GFP_ATOMIC))
err("usb_submit_urb(leds) failed"); err("usb_submit_urb(leds) failed");
...@@ -172,6 +177,36 @@ static void usb_kbd_close(struct input_dev *dev) ...@@ -172,6 +177,36 @@ static void usb_kbd_close(struct input_dev *dev)
usb_unlink_urb(kbd->irq); usb_unlink_urb(kbd->irq);
} }
static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
{
if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
return -1;
if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
return -1;
if (!(kbd->new = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &kbd->new_dma)))
return -1;
if (!(kbd->cr = usb_buffer_alloc(dev, sizeof(struct usb_ctrlrequest), SLAB_ATOMIC, &kbd->cr_dma)))
return -1;
if (!(kbd->leds = usb_buffer_alloc(dev, 1, SLAB_ATOMIC, &kbd->leds_dma)))
return -1;
return 0;
}
static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
{
if (kbd->irq)
usb_free_urb(kbd->irq);
if (kbd->led)
usb_free_urb(kbd->led);
if (kbd->new)
usb_buffer_free(dev, 8, kbd->new, kbd->new_dma);
if (kbd->cr)
usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma);
if (kbd->leds)
usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
}
static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum, static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
...@@ -198,14 +233,8 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -198,14 +233,8 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
if (!(kbd = kmalloc(sizeof(struct usb_kbd), GFP_KERNEL))) return NULL; if (!(kbd = kmalloc(sizeof(struct usb_kbd), GFP_KERNEL))) return NULL;
memset(kbd, 0, sizeof(struct usb_kbd)); memset(kbd, 0, sizeof(struct usb_kbd));
kbd->irq = usb_alloc_urb(0, GFP_KERNEL); if (usb_kbd_alloc_mem(dev, kbd)) {
if (!kbd->irq) { usb_kbd_free_mem(dev, kbd);
kfree(kbd);
return NULL;
}
kbd->led = usb_alloc_urb(0, GFP_KERNEL);
if (!kbd->led) {
usb_free_urb(kbd->irq);
kfree(kbd); kfree(kbd);
return NULL; return NULL;
} }
...@@ -224,14 +253,17 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -224,14 +253,17 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kbd->dev.open = usb_kbd_open; kbd->dev.open = usb_kbd_open;
kbd->dev.close = usb_kbd_close; kbd->dev.close = usb_kbd_close;
FILL_INT_URB(kbd->irq, dev, pipe, kbd->new, maxp > 8 ? 8 : maxp, usb_fill_int_urb(kbd->irq, dev, pipe,
kbd->new, (maxp > 8 ? 8 : maxp),
usb_kbd_irq, kbd, endpoint->bInterval); usb_kbd_irq, kbd, endpoint->bInterval);
kbd->irq->transfer_dma = kbd->new_dma;
kbd->irq->transfer_flags |= URB_NO_DMA_MAP;
kbd->cr.bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE; kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
kbd->cr.bRequest = 0x09; kbd->cr->bRequest = 0x09;
kbd->cr.wValue = 0x200; kbd->cr->wValue = cpu_to_le16(0x200);
kbd->cr.wIndex = interface->bInterfaceNumber; kbd->cr->wIndex = cpu_to_le16(interface->bInterfaceNumber);
kbd->cr.wLength = 1; kbd->cr->wLength = cpu_to_le16(1);
usb_make_path(dev, path, 64); usb_make_path(dev, path, 64);
sprintf(kbd->phys, "%s/input0", path); sprintf(kbd->phys, "%s/input0", path);
...@@ -244,6 +276,8 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -244,6 +276,8 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kbd->dev.id.version = dev->descriptor.bcdDevice; kbd->dev.id.version = dev->descriptor.bcdDevice;
if (!(buf = kmalloc(63, GFP_KERNEL))) { if (!(buf = kmalloc(63, GFP_KERNEL))) {
usb_free_urb(kbd->irq);
usb_kbd_free_buffers(dev, kbd);
kfree(kbd); kfree(kbd);
return NULL; return NULL;
} }
...@@ -261,8 +295,12 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -261,8 +295,12 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kfree(buf); kfree(buf);
FILL_CONTROL_URB(kbd->led, dev, usb_sndctrlpipe(dev, 0), usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
(void*) &kbd->cr, &kbd->leds, 1, usb_kbd_led, kbd); (void *) kbd->cr, kbd->leds, 1,
usb_kbd_led, kbd);
kbd->led->setup_dma = kbd->cr_dma;
kbd->led->transfer_dma = kbd->leds_dma;
kbd->led->transfer_flags |= URB_NO_DMA_MAP;
input_register_device(&kbd->dev); input_register_device(&kbd->dev);
...@@ -276,8 +314,7 @@ static void usb_kbd_disconnect(struct usb_device *dev, void *ptr) ...@@ -276,8 +314,7 @@ static void usb_kbd_disconnect(struct usb_device *dev, void *ptr)
struct usb_kbd *kbd = ptr; struct usb_kbd *kbd = ptr;
usb_unlink_urb(kbd->irq); usb_unlink_urb(kbd->irq);
input_unregister_device(&kbd->dev); input_unregister_device(&kbd->dev);
usb_free_urb(kbd->irq); usb_kbd_free_buffers(dev, kbd);
usb_free_urb(kbd->led);
kfree(kbd); kfree(kbd);
} }
......
...@@ -46,13 +46,15 @@ MODULE_DESCRIPTION(DRIVER_DESC); ...@@ -46,13 +46,15 @@ MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE(DRIVER_LICENSE); MODULE_LICENSE(DRIVER_LICENSE);
struct usb_mouse { struct usb_mouse {
signed char data[8];
char name[128]; char name[128];
char phys[64]; char phys[64];
struct usb_device *usbdev; struct usb_device *usbdev;
struct input_dev dev; struct input_dev dev;
struct urb *irq; struct urb *irq;
int open; int open;
signed char *data;
dma_addr_t data_dma;
}; };
static void usb_mouse_irq(struct urb *urb) static void usb_mouse_irq(struct urb *urb)
...@@ -124,8 +126,15 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -124,8 +126,15 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum,
if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) return NULL; if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) return NULL;
memset(mouse, 0, sizeof(struct usb_mouse)); memset(mouse, 0, sizeof(struct usb_mouse));
mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma);
if (!mouse->data) {
kfree(mouse);
return NULL;
}
mouse->irq = usb_alloc_urb(0, GFP_KERNEL); mouse->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!mouse->irq) { if (!mouse->irq) {
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse); kfree(mouse);
return NULL; return NULL;
} }
...@@ -153,6 +162,7 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -153,6 +162,7 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum,
mouse->dev.id.version = dev->descriptor.bcdDevice; mouse->dev.id.version = dev->descriptor.bcdDevice;
if (!(buf = kmalloc(63, GFP_KERNEL))) { if (!(buf = kmalloc(63, GFP_KERNEL))) {
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse); kfree(mouse);
return NULL; return NULL;
} }
...@@ -170,8 +180,11 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -170,8 +180,11 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum,
kfree(buf); kfree(buf);
FILL_INT_URB(mouse->irq, dev, pipe, mouse->data, maxp > 8 ? 8 : maxp, usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
(maxp > 8 ? 8 : maxp),
usb_mouse_irq, mouse, endpoint->bInterval); usb_mouse_irq, mouse, endpoint->bInterval);
mouse->irq->transfer_dma = mouse->data_dma;
mouse->irq->transfer_flags |= URB_NO_DMA_MAP;
input_register_device(&mouse->dev); input_register_device(&mouse->dev);
...@@ -186,6 +199,7 @@ static void usb_mouse_disconnect(struct usb_device *dev, void *ptr) ...@@ -186,6 +199,7 @@ static void usb_mouse_disconnect(struct usb_device *dev, void *ptr)
usb_unlink_urb(mouse->irq); usb_unlink_urb(mouse->irq);
input_unregister_device(&mouse->dev); input_unregister_device(&mouse->dev);
usb_free_urb(mouse->irq); usb_free_urb(mouse->irq);
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse); kfree(mouse);
} }
......
...@@ -96,7 +96,8 @@ struct wacom_features { ...@@ -96,7 +96,8 @@ struct wacom_features {
}; };
struct wacom { struct wacom {
signed char data[10]; signed char *data;
dma_addr_t data_dma;
struct input_dev dev; struct input_dev dev;
struct usb_device *usbdev; struct usb_device *usbdev;
struct urb *irq; struct urb *irq;
...@@ -364,8 +365,15 @@ static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struc ...@@ -364,8 +365,15 @@ static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struc
if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) return NULL; if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) return NULL;
memset(wacom, 0, sizeof(struct wacom)); memset(wacom, 0, sizeof(struct wacom));
wacom->data = usb_buffer_alloc(dev, 10, SLAB_ATOMIC, &wacom->data_dma);
if (!wacom->data) {
kfree(wacom);
return NULL;
}
wacom->irq = usb_alloc_urb(0, GFP_KERNEL); wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!wacom->irq) { if (!wacom->irq) {
usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
kfree(wacom); kfree(wacom);
return NULL; return NULL;
} }
...@@ -413,8 +421,15 @@ static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struc ...@@ -413,8 +421,15 @@ static void *wacom_probe(struct usb_device *dev, unsigned int ifnum, const struc
endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0; endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(wacom->irq, dev, usb_rcvintpipe(dev, endpoint->bEndpointAddress), if (wacom->features->pktlen > 10)
wacom->data, wacom->features->pktlen, wacom->features->irq, wacom, endpoint->bInterval); BUG();
usb_fill_int_urb(wacom->irq, dev,
usb_rcvintpipe(dev, endpoint->bEndpointAddress),
wacom->data, wacom->features->pktlen,
wacom->features->irq, wacom, endpoint->bInterval);
wacom->irq->transfer_dma = wacom->data_dma;
wacom->irq->transfer_flags |= URB_NO_DMA_MAP;
input_register_device(&wacom->dev); input_register_device(&wacom->dev);
...@@ -429,6 +444,7 @@ static void wacom_disconnect(struct usb_device *dev, void *ptr) ...@@ -429,6 +444,7 @@ static void wacom_disconnect(struct usb_device *dev, void *ptr)
usb_unlink_urb(wacom->irq); usb_unlink_urb(wacom->irq);
input_unregister_device(&wacom->dev); input_unregister_device(&wacom->dev);
usb_free_urb(wacom->irq); usb_free_urb(wacom->irq);
usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
kfree(wacom); kfree(wacom);
} }
......
...@@ -107,7 +107,8 @@ struct usb_xpad { ...@@ -107,7 +107,8 @@ struct usb_xpad {
struct usb_device *udev; /* usb device */ struct usb_device *udev; /* usb device */
struct urb *irq_in; /* urb for interrupt in report */ struct urb *irq_in; /* urb for interrupt in report */
unsigned char idata[XPAD_PKT_LEN]; /* input data */ unsigned char *idata; /* input data */
dma_addr_t idata_dma;
char phys[65]; /* physical device path */ char phys[65]; /* physical device path */
int open_count; /* reference count */ int open_count; /* reference count */
...@@ -213,19 +214,29 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -213,19 +214,29 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru
} }
memset(xpad, 0, sizeof(struct usb_xpad)); memset(xpad, 0, sizeof(struct usb_xpad));
xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
SLAB_ATOMIC, &xpad->idata_dma);
if (!xpad->idata) {
kfree(xpad);
return NULL;
}
xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
if (!xpad->irq_in) { if (!xpad->irq_in) {
err("cannot allocate memory for new pad irq urb"); err("cannot allocate memory for new pad irq urb");
usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
kfree(xpad); kfree(xpad);
return NULL; return NULL;
} }
ep_irq_in = udev->actconfig->interface[ifnum].altsetting[0].endpoint + 0; ep_irq_in = udev->actconfig->interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(xpad->irq_in, udev, usb_fill_int_urb(xpad->irq_in, udev,
usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
xpad->idata, XPAD_PKT_LEN, xpad_irq_in, xpad, xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
ep_irq_in->bInterval); xpad, ep_irq_in->bInterval);
xpad->irq_in->transfer_dma = xpad->idata_dma;
xpad->irq_in->transfer_flags |= URB_NO_DMA_MAP;
xpad->udev = udev; xpad->udev = udev;
...@@ -290,6 +301,7 @@ static void xpad_disconnect(struct usb_device *udev, void *ptr) ...@@ -290,6 +301,7 @@ static void xpad_disconnect(struct usb_device *udev, void *ptr)
usb_unlink_urb(xpad->irq_in); usb_unlink_urb(xpad->irq_in);
input_unregister_device(&xpad->dev); input_unregister_device(&xpad->dev);
usb_free_urb(xpad->irq_in); usb_free_urb(xpad->irq_in);
usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
kfree(xpad); kfree(xpad);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment