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 {
};
struct aiptek {
signed char data[10];
struct input_dev dev;
struct usb_device *usbdev;
struct urb *irq;
struct aiptek_features *features;
int tool;
int open;
signed char *data;
dma_addr_t data_dma;
};
static void
......@@ -235,11 +237,18 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum,
memset(aiptek, 0, sizeof (struct aiptek));
aiptek->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!aiptek->irq) {
kfree(aiptek);
return NULL;
}
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);
if (!aiptek->irq) {
usb_buffer_free(dev, 10, aiptek->data, aiptek->data_dma);
kfree(aiptek);
return NULL;
}
// Resolution500LPI
aiptek_command(dev, ifnum, 0x18, 0x04);
......@@ -287,14 +296,15 @@ aiptek_probe(struct usb_device *dev, unsigned int ifnum,
endpoint = dev->config[0].interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(aiptek->irq,
dev,
usb_rcvintpipe(dev, endpoint->bEndpointAddress),
aiptek->data,
aiptek->features->pktlen,
aiptek->features->irq,
aiptek,
endpoint->bInterval);
if (aiptek->features->pktlen > 10)
BUG();
usb_fill_int_urb(aiptek->irq, dev,
usb_rcvintpipe(dev, endpoint->bEndpointAddress),
aiptek->data, aiptek->features->pktlen,
aiptek->features->irq, aiptek, endpoint->bInterval);
aiptek->irq->transfer_dma = aiptek->data_dma;
aiptek->irq->transfer_flags |= URB_NO_DMA_MAP;
input_register_device(&aiptek->dev);
......@@ -310,7 +320,8 @@ aiptek_disconnect(struct usb_device *dev, void *ptr)
struct aiptek *aiptek = ptr;
usb_unlink_urb(aiptek->irq);
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);
}
......
/*
* $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) 2000-2001 Vojtech Pavlik
*
* USB HID support for Linux
* Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@suse.cz>
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) 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
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
#include <linux/module.h>
......@@ -52,8 +37,8 @@
* Version Information
*/
#define DRIVER_VERSION "v1.31"
#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik <vojtech@ucw.cz>"
#define DRIVER_VERSION "v2.0"
#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
#define DRIVER_DESC "USB HID core driver"
#define DRIVER_LICENSE "GPL"
......@@ -559,6 +544,7 @@ static void hid_free_device(struct hid_device *device)
}
if (device->rdesc) kfree(device->rdesc);
kfree(device);
}
/*
......@@ -651,9 +637,8 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
return NULL;
memset(device, 0, sizeof(struct hid_device));
if (!(device->collection = kmalloc(sizeof(struct hid_collection) *
HID_DEFAULT_NUM_COLLECTIONS,
GFP_KERNEL))) {
if (!(device->collection =kmalloc(sizeof(struct hid_collection) *
HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
kfree(device);
return NULL;
}
......@@ -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->dev = hid->dev;
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.wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
hid->cr.wIndex = cpu_to_le16(hid->ifnum);
hid->cr.wLength = cpu_to_le16(hid->urbctrl->transfer_buffer_length);
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->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
hid->cr->wIndex = cpu_to_le16(hid->ifnum);
hid->cr->wLength = cpu_to_le16(hid->urbctrl->transfer_buffer_length);
dbg("submitting ctrl urb");
......@@ -1338,6 +1323,32 @@ struct hid_blacklist {
{ 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)
{
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)
kfree(rdesc);
hid->quirks = quirks;
if (hid_alloc_buffers(dev, hid)) {
hid_free_buffers(dev, hid);
goto fail;
}
for (n = 0; n < interface->bNumEndpoints; 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)
if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
goto fail;
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 {
if (hid->urbout)
continue;
if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
goto fail;
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)
kfree(buf);
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;
fail:
hid_free_device(hid);
if (hid->urbin) usb_free_urb(hid->urbin);
if (hid->urbout) usb_free_urb(hid->urbout);
if (hid->urbctrl) usb_free_urb(hid->urbctrl);
hid_free_buffers(dev, hid);
hid_free_device(hid);
return NULL;
}
......@@ -1490,6 +1517,7 @@ static void hid_disconnect(struct usb_device *dev, void *ptr)
if (hid->urbout)
usb_free_urb(hid->urbout);
hid_free_buffers(dev, hid);
hid_free_device(hid);
}
......
......@@ -337,19 +337,23 @@ struct hid_device { /* device report descriptor */
unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
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 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 */
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 */
struct urb *urbout; /* Output URB */
struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
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 */
unsigned claimed; /* Claimed by hidinput, hiddev? */
......
......@@ -52,9 +52,11 @@
#define POWERMATE_PAYLOAD_SIZE 3
struct powermate_device {
signed char data[POWERMATE_PAYLOAD_SIZE];
struct urb irq, config;
struct usb_ctrlrequest configcr;
signed char *data;
dma_addr_t data_dma;
struct urb *irq, *config;
struct usb_ctrlrequest *configcr;
dma_addr_t configcr_dma;
struct usb_device *udev;
struct input_dev input;
struct semaphore lock;
......@@ -77,7 +79,7 @@ static void powermate_irq(struct urb *urb)
{
struct powermate_device *pm = urb->context;
if(urb->status)
if (urb->status)
return;
/* handle updates to device state */
......@@ -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 */
static void powermate_sync_state(struct powermate_device *pm)
{
if(pm->requires_update == 0)
if (pm->requires_update == 0)
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 */
if(pm->requires_update & UPDATE_STATIC_BRIGHTNESS){
pm->configcr.wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
pm->configcr.wIndex = cpu_to_le16( pm->static_brightness );
if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS){
pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
}else if(pm->requires_update & UPDATE_PULSE_ASLEEP){
pm->configcr.wValue = cpu_to_le16( SET_PULSE_ASLEEP );
pm->configcr.wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
}else if (pm->requires_update & UPDATE_PULSE_ASLEEP){
pm->configcr->wValue = cpu_to_le16( SET_PULSE_ASLEEP );
pm->configcr->wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
pm->requires_update &= ~UPDATE_PULSE_ASLEEP;
}else if(pm->requires_update & UPDATE_PULSE_AWAKE){
pm->configcr.wValue = cpu_to_le16( SET_PULSE_AWAKE );
pm->configcr.wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
}else if (pm->requires_update & UPDATE_PULSE_AWAKE){
pm->configcr->wValue = cpu_to_le16( SET_PULSE_AWAKE );
pm->configcr->wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
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;
/* the powermate takes an operation and an argument for its pulse algorithm.
the operation can be:
......@@ -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.
*/
if(pm->pulse_speed < 255){
if (pm->pulse_speed < 255){
op = 0; // divide
arg = 255 - pm->pulse_speed;
}else if(pm->pulse_speed > 255){
} else if (pm->pulse_speed > 255){
op = 2; // multiply
arg = pm->pulse_speed - 255;
}else{
} else {
op = 1; // normal speed
arg = 0; // can be any value
}
pm->configcr.wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
pm->configcr.wIndex = cpu_to_le16( (arg << 8) | op );
pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
pm->requires_update &= ~UPDATE_PULSE_MODE;
}else{
printk(KERN_ERR "powermate: unknown update required");
......@@ -144,17 +146,19 @@ static void powermate_sync_state(struct powermate_device *pm)
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.bRequest = 0x01;
pm->configcr.wLength = 0;
pm->configcr->bRequestType = 0x41; /* vendor request */
pm->configcr->bRequest = 0x01;
pm->configcr->wLength = 0;
FILL_CONTROL_URB(&pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
(void*)&pm->configcr, 0, 0, powermate_config_complete, pm);
usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
(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");
}
......@@ -163,7 +167,7 @@ static void powermate_config_complete(struct urb *urb)
{
struct powermate_device *pm = urb->context;
if(urb->status)
if (urb->status)
printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
down(&pm->lock);
......@@ -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,
int pulse_table, int pulse_asleep, int pulse_awake)
{
if(pulse_speed < 0)
if (pulse_speed < 0)
pulse_speed = 0;
if(pulse_table < 0)
if (pulse_table < 0)
pulse_table = 0;
if(pulse_speed > 510)
if (pulse_speed > 510)
pulse_speed = 510;
if(pulse_table > 2)
if (pulse_table > 2)
pulse_table = 2;
pulse_asleep = !!pulse_asleep;
......@@ -190,19 +194,19 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
down(&pm->lock);
/* mark state updates which are required */
if(static_brightness != pm->static_brightness){
if (static_brightness != pm->static_brightness){
pm->static_brightness = 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->requires_update |= UPDATE_PULSE_ASLEEP;
}
if(pulse_awake != pm->pulse_awake){
if (pulse_awake != pm->pulse_awake){
pm->pulse_awake = 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_table = pulse_table;
pm->requires_update |= UPDATE_PULSE_MODE;
......@@ -219,7 +223,7 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
unsigned int command = (unsigned int)_value;
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 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
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 */
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
memset(pm, 0, sizeof(struct powermate_device));
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);
/* get a handle to the interrupt data pipe */
pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
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);
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 */
if(usb_submit_urb(&pm->irq, GFP_KERNEL)) {
if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
powermate_free_buffers(udev, pm);
kfree(pm);
return NULL; /* failure */
}
......@@ -319,8 +374,11 @@ static void powermate_disconnect(struct usb_device *dev, void *ptr)
struct powermate_device *pm = ptr;
down(&pm->lock);
pm->requires_update = 0;
usb_unlink_urb(&pm->irq);
usb_unlink_urb(pm->irq);
input_unregister_device(&pm->input);
usb_free_urb(pm->irq);
usb_free_urb(pm->config);
powermate_free_buffers(dev, pm);
kfree(pm);
}
......
......@@ -67,14 +67,19 @@ static unsigned char usb_kbd_keycode[256] = {
struct usb_kbd {
struct input_dev dev;
struct usb_device *usbdev;
unsigned char new[8];
unsigned char old[8];
struct urb *irq, *led;
struct usb_ctrlrequest cr;
unsigned char leds, newleds;
unsigned char newleds;
char name[128];
char phys[64];
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)
......@@ -123,10 +128,10 @@ int usb_kbd_event(struct input_dev *dev, unsigned int type, unsigned int code, i
if (kbd->led->status == -EINPROGRESS)
return 0;
if (kbd->leds == kbd->newleds)
if (*(kbd->leds) == kbd->newleds)
return 0;
kbd->leds = kbd->newleds;
*(kbd->leds) = kbd->newleds;
kbd->led->dev = kbd->usbdev;
if (usb_submit_urb(kbd->led, GFP_ATOMIC))
err("usb_submit_urb(leds) failed");
......@@ -141,10 +146,10 @@ static void usb_kbd_led(struct urb *urb)
if (urb->status)
warn("led urb status %d received", urb->status);
if (kbd->leds == kbd->newleds)
if (*(kbd->leds) == kbd->newleds)
return;
kbd->leds = kbd->newleds;
*(kbd->leds) = kbd->newleds;
kbd->led->dev = kbd->usbdev;
if (usb_submit_urb(kbd->led, GFP_ATOMIC))
err("usb_submit_urb(leds) failed");
......@@ -172,6 +177,36 @@ static void usb_kbd_close(struct input_dev *dev)
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,
const struct usb_device_id *id)
{
......@@ -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;
memset(kbd, 0, sizeof(struct usb_kbd));
kbd->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!kbd->irq) {
kfree(kbd);
return NULL;
}
kbd->led = usb_alloc_urb(0, GFP_KERNEL);
if (!kbd->led) {
usb_free_urb(kbd->irq);
if (usb_kbd_alloc_mem(dev, kbd)) {
usb_kbd_free_mem(dev, kbd);
kfree(kbd);
return NULL;
}
......@@ -224,14 +253,17 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kbd->dev.open = usb_kbd_open;
kbd->dev.close = usb_kbd_close;
FILL_INT_URB(kbd->irq, dev, pipe, kbd->new, maxp > 8 ? 8 : maxp,
usb_kbd_irq, kbd, endpoint->bInterval);
usb_fill_int_urb(kbd->irq, dev, pipe,
kbd->new, (maxp > 8 ? 8 : maxp),
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.bRequest = 0x09;
kbd->cr.wValue = 0x200;
kbd->cr.wIndex = interface->bInterfaceNumber;
kbd->cr.wLength = 1;
kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
kbd->cr->bRequest = 0x09;
kbd->cr->wValue = cpu_to_le16(0x200);
kbd->cr->wIndex = cpu_to_le16(interface->bInterfaceNumber);
kbd->cr->wLength = cpu_to_le16(1);
usb_make_path(dev, path, 64);
sprintf(kbd->phys, "%s/input0", path);
......@@ -244,6 +276,8 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kbd->dev.id.version = dev->descriptor.bcdDevice;
if (!(buf = kmalloc(63, GFP_KERNEL))) {
usb_free_urb(kbd->irq);
usb_kbd_free_buffers(dev, kbd);
kfree(kbd);
return NULL;
}
......@@ -261,9 +295,13 @@ static void *usb_kbd_probe(struct usb_device *dev, unsigned int ifnum,
kfree(buf);
FILL_CONTROL_URB(kbd->led, dev, usb_sndctrlpipe(dev, 0),
(void*) &kbd->cr, &kbd->leds, 1, usb_kbd_led, kbd);
usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
(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);
printk(KERN_INFO "input: %s on %s\n", kbd->name, path);
......@@ -276,8 +314,7 @@ static void usb_kbd_disconnect(struct usb_device *dev, void *ptr)
struct usb_kbd *kbd = ptr;
usb_unlink_urb(kbd->irq);
input_unregister_device(&kbd->dev);
usb_free_urb(kbd->irq);
usb_free_urb(kbd->led);
usb_kbd_free_buffers(dev, kbd);
kfree(kbd);
}
......
......@@ -46,13 +46,15 @@ MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE(DRIVER_LICENSE);
struct usb_mouse {
signed char data[8];
char name[128];
char phys[64];
struct usb_device *usbdev;
struct input_dev dev;
struct urb *irq;
int open;
signed char *data;
dma_addr_t data_dma;
};
static void usb_mouse_irq(struct urb *urb)
......@@ -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;
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);
if (!mouse->irq) {
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse);
return NULL;
}
......@@ -153,6 +162,7 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum,
mouse->dev.id.version = dev->descriptor.bcdDevice;
if (!(buf = kmalloc(63, GFP_KERNEL))) {
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse);
return NULL;
}
......@@ -170,8 +180,11 @@ static void *usb_mouse_probe(struct usb_device *dev, unsigned int ifnum,
kfree(buf);
FILL_INT_URB(mouse->irq, dev, pipe, mouse->data, maxp > 8 ? 8 : maxp,
usb_mouse_irq, mouse, endpoint->bInterval);
usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
(maxp > 8 ? 8 : maxp),
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);
......@@ -186,6 +199,7 @@ static void usb_mouse_disconnect(struct usb_device *dev, void *ptr)
usb_unlink_urb(mouse->irq);
input_unregister_device(&mouse->dev);
usb_free_urb(mouse->irq);
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
kfree(mouse);
}
......
......@@ -96,7 +96,8 @@ struct wacom_features {
};
struct wacom {
signed char data[10];
signed char *data;
dma_addr_t data_dma;
struct input_dev dev;
struct usb_device *usbdev;
struct urb *irq;
......@@ -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;
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);
if (!wacom->irq) {
usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
kfree(wacom);
return NULL;
}
......@@ -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;
FILL_INT_URB(wacom->irq, dev, usb_rcvintpipe(dev, endpoint->bEndpointAddress),
wacom->data, wacom->features->pktlen, wacom->features->irq, wacom, endpoint->bInterval);
if (wacom->features->pktlen > 10)
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);
......@@ -429,6 +444,7 @@ static void wacom_disconnect(struct usb_device *dev, void *ptr)
usb_unlink_urb(wacom->irq);
input_unregister_device(&wacom->dev);
usb_free_urb(wacom->irq);
usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
kfree(wacom);
}
......
......@@ -107,7 +107,8 @@ struct usb_xpad {
struct usb_device *udev; /* usb device */
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 */
int open_count; /* reference count */
......@@ -213,19 +214,29 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru
}
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);
if (!xpad->irq_in) {
err("cannot allocate memory for new pad irq urb");
usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
kfree(xpad);
return NULL;
}
ep_irq_in = udev->actconfig->interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(xpad->irq_in, udev,
usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
xpad->idata, XPAD_PKT_LEN, xpad_irq_in, xpad,
ep_irq_in->bInterval);
usb_fill_int_urb(xpad->irq_in, udev,
usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
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;
......@@ -290,6 +301,7 @@ static void xpad_disconnect(struct usb_device *udev, void *ptr)
usb_unlink_urb(xpad->irq_in);
input_unregister_device(&xpad->dev);
usb_free_urb(xpad->irq_in);
usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
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