aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 11:25:49 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 11:25:49 -0400
commit52a23685f37c06d0cd00eeb8f517a90de3f2c338 (patch)
tree1449bf12db013962c98b2b8cd9b4b5d1cf359b01 /drivers/usb/host
parentd046943cbaf332f75284ad99f4b3e60bae7ffff2 (diff)
parentd20da3c39b9d5b04f0258ba74643533268f56e30 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6: (44 commits) USB: drivers/usb/storage/dpcm.c whitespace cleanup USB: r8a66597-hcd: fixes some problem USB: change name of spinlock in hcd.c USB: move routines in hcd.c USB: misc: uss720: clean up urb->status usage USB: misc: usbtest: clean up urb->status usage USB: misc: usblcd: clean up urb->status usage USB: misc: phidgetmotorcontrol: clean up urb->status usage USB: misc: phidgetkit: clean up urb->status usage USB: misc: legousbtower: clean up urb->status usage USB: misc: ldusb: clean up urb->status usage USB: misc: iowarrior: clean up urb->status usage USB: misc: ftdi-elan: clean up urb->status usage USB: misc: auerswald: clean up urb->status usage USB: misc: appledisplay: clean up urb->status usage USB: misc: adtux: clean up urb->status usage USB: core: message: clean up urb->status usage USB: image: microtek: clean up urb->status usage USB: image: mdc800: clean up urb->status usage USB: storage: onetouch: clean up urb->status usage ...
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/isp116x-hcd.c187
-rw-r--r--drivers/usb/host/r8a66597-hcd.c110
-rw-r--r--drivers/usb/host/r8a66597.h87
-rw-r--r--drivers/usb/host/u132-hcd.c17
-rw-r--r--drivers/usb/host/uhci-q.c59
5 files changed, 229 insertions, 231 deletions
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 46873f2534b5..5c851a36de72 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -228,7 +228,6 @@ static void preproc_atl_queue(struct isp116x *isp116x)
228 struct urb, urb_list); 228 struct urb, urb_list);
229 ptd = &ep->ptd; 229 ptd = &ep->ptd;
230 len = ep->length; 230 len = ep->length;
231 spin_lock(&urb->lock);
232 ep->data = (unsigned char *)urb->transfer_buffer 231 ep->data = (unsigned char *)urb->transfer_buffer
233 + urb->actual_length; 232 + urb->actual_length;
234 233
@@ -264,7 +263,6 @@ static void preproc_atl_queue(struct isp116x *isp116x)
264 | PTD_EP(ep->epnum); 263 | PTD_EP(ep->epnum);
265 ptd->len = PTD_LEN(len) | PTD_DIR(dir); 264 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
266 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); 265 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
267 spin_unlock(&urb->lock);
268 if (!ep->active) { 266 if (!ep->active) {
269 ptd->mps |= PTD_LAST_MSK; 267 ptd->mps |= PTD_LAST_MSK;
270 isp116x->atl_last_dir = dir; 268 isp116x->atl_last_dir = dir;
@@ -275,6 +273,61 @@ static void preproc_atl_queue(struct isp116x *isp116x)
275} 273}
276 274
277/* 275/*
276 Take done or failed requests out of schedule. Give back
277 processed urbs.
278*/
279static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
280 struct urb *urb)
281__releases(isp116x->lock) __acquires(isp116x->lock)
282{
283 unsigned i;
284
285 urb->hcpriv = NULL;
286 ep->error_count = 0;
287
288 if (usb_pipecontrol(urb->pipe))
289 ep->nextpid = USB_PID_SETUP;
290
291 urb_dbg(urb, "Finish");
292
293 spin_unlock(&isp116x->lock);
294 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb);
295 spin_lock(&isp116x->lock);
296
297 /* take idle endpoints out of the schedule */
298 if (!list_empty(&ep->hep->urb_list))
299 return;
300
301 /* async deschedule */
302 if (!list_empty(&ep->schedule)) {
303 list_del_init(&ep->schedule);
304 return;
305 }
306
307 /* periodic deschedule */
308 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
309 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
310 struct isp116x_ep *temp;
311 struct isp116x_ep **prev = &isp116x->periodic[i];
312
313 while (*prev && ((temp = *prev) != ep))
314 prev = &temp->next;
315 if (*prev)
316 *prev = ep->next;
317 isp116x->load[i] -= ep->load;
318 }
319 ep->branch = PERIODIC_SIZE;
320 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
321 ep->load / ep->period;
322
323 /* switch irq type? */
324 if (!--isp116x->periodic_count) {
325 isp116x->irqenb &= ~HCuPINT_SOF;
326 isp116x->irqenb |= HCuPINT_ATL;
327 }
328}
329
330/*
278 Analyze transfer results, handle partial transfers and errors 331 Analyze transfer results, handle partial transfers and errors
279*/ 332*/
280static void postproc_atl_queue(struct isp116x *isp116x) 333static void postproc_atl_queue(struct isp116x *isp116x)
@@ -284,6 +337,7 @@ static void postproc_atl_queue(struct isp116x *isp116x)
284 struct usb_device *udev; 337 struct usb_device *udev;
285 struct ptd *ptd; 338 struct ptd *ptd;
286 int short_not_ok; 339 int short_not_ok;
340 int status;
287 u8 cc; 341 u8 cc;
288 342
289 for (ep = isp116x->atl_active; ep; ep = ep->active) { 343 for (ep = isp116x->atl_active; ep; ep = ep->active) {
@@ -294,7 +348,7 @@ static void postproc_atl_queue(struct isp116x *isp116x)
294 ptd = &ep->ptd; 348 ptd = &ep->ptd;
295 cc = PTD_GET_CC(ptd); 349 cc = PTD_GET_CC(ptd);
296 short_not_ok = 1; 350 short_not_ok = 1;
297 spin_lock(&urb->lock); 351 status = -EINPROGRESS;
298 352
299 /* Data underrun is special. For allowed underrun 353 /* Data underrun is special. For allowed underrun
300 we clear the error and continue as normal. For 354 we clear the error and continue as normal. For
@@ -302,47 +356,36 @@ static void postproc_atl_queue(struct isp116x *isp116x)
302 immediately while for control transfer, 356 immediately while for control transfer,
303 we do a STATUS stage. */ 357 we do a STATUS stage. */
304 if (cc == TD_DATAUNDERRUN) { 358 if (cc == TD_DATAUNDERRUN) {
305 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) { 359 if (!(urb->transfer_flags & URB_SHORT_NOT_OK) ||
306 DBG("Allowed data underrun\n"); 360 usb_pipecontrol(urb->pipe)) {
361 DBG("Allowed or control data underrun\n");
307 cc = TD_CC_NOERROR; 362 cc = TD_CC_NOERROR;
308 short_not_ok = 0; 363 short_not_ok = 0;
309 } else { 364 } else {
310 ep->error_count = 1; 365 ep->error_count = 1;
311 if (usb_pipecontrol(urb->pipe)) 366 usb_settoggle(udev, ep->epnum,
312 ep->nextpid = USB_PID_ACK; 367 ep->nextpid == USB_PID_OUT,
313 else 368 PTD_GET_TOGGLE(ptd));
314 usb_settoggle(udev, ep->epnum,
315 ep->nextpid ==
316 USB_PID_OUT,
317 PTD_GET_TOGGLE(ptd));
318 urb->actual_length += PTD_GET_COUNT(ptd); 369 urb->actual_length += PTD_GET_COUNT(ptd);
319 urb->status = cc_to_error[TD_DATAUNDERRUN]; 370 status = cc_to_error[TD_DATAUNDERRUN];
320 spin_unlock(&urb->lock); 371 goto done;
321 continue;
322 } 372 }
323 } 373 }
324 /* Keep underrun error through the STATUS stage */
325 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
326 cc = TD_DATAUNDERRUN;
327 374
328 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED 375 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
329 && (++ep->error_count >= 3 || cc == TD_CC_STALL 376 && (++ep->error_count >= 3 || cc == TD_CC_STALL
330 || cc == TD_DATAOVERRUN)) { 377 || cc == TD_DATAOVERRUN)) {
331 if (urb->status == -EINPROGRESS) 378 status = cc_to_error[cc];
332 urb->status = cc_to_error[cc];
333 if (ep->nextpid == USB_PID_ACK) 379 if (ep->nextpid == USB_PID_ACK)
334 ep->nextpid = 0; 380 ep->nextpid = 0;
335 spin_unlock(&urb->lock); 381 goto done;
336 continue;
337 } 382 }
338 /* According to usb spec, zero-length Int transfer signals 383 /* According to usb spec, zero-length Int transfer signals
339 finishing of the urb. Hey, does this apply only 384 finishing of the urb. Hey, does this apply only
340 for IN endpoints? */ 385 for IN endpoints? */
341 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) { 386 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
342 if (urb->status == -EINPROGRESS) 387 status = 0;
343 urb->status = 0; 388 goto done;
344 spin_unlock(&urb->lock);
345 continue;
346 } 389 }
347 390
348 /* Relax after previously failed, but later succeeded 391 /* Relax after previously failed, but later succeeded
@@ -381,8 +424,8 @@ static void postproc_atl_queue(struct isp116x *isp116x)
381 /* All data for this URB is transferred, let's finish */ 424 /* All data for this URB is transferred, let's finish */
382 if (usb_pipecontrol(urb->pipe)) 425 if (usb_pipecontrol(urb->pipe))
383 ep->nextpid = USB_PID_ACK; 426 ep->nextpid = USB_PID_ACK;
384 else if (urb->status == -EINPROGRESS) 427 else
385 urb->status = 0; 428 status = 0;
386 break; 429 break;
387 case USB_PID_SETUP: 430 case USB_PID_SETUP:
388 if (PTD_GET_ACTIVE(ptd) 431 if (PTD_GET_ACTIVE(ptd)
@@ -402,69 +445,27 @@ static void postproc_atl_queue(struct isp116x *isp116x)
402 if (PTD_GET_ACTIVE(ptd) 445 if (PTD_GET_ACTIVE(ptd)
403 || (cc != TD_CC_NOERROR && cc < 0x0E)) 446 || (cc != TD_CC_NOERROR && cc < 0x0E))
404 break; 447 break;
405 if (urb->status == -EINPROGRESS) 448 if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
406 urb->status = 0; 449 urb->actual_length <
450 urb->transfer_buffer_length)
451 status = -EREMOTEIO;
452 else
453 status = 0;
407 ep->nextpid = 0; 454 ep->nextpid = 0;
408 break; 455 break;
409 default: 456 default:
410 BUG(); 457 BUG();
411 } 458 }
412 spin_unlock(&urb->lock);
413 }
414}
415
416/*
417 Take done or failed requests out of schedule. Give back
418 processed urbs.
419*/
420static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
421 struct urb *urb)
422__releases(isp116x->lock) __acquires(isp116x->lock)
423{
424 unsigned i;
425
426 urb->hcpriv = NULL;
427 ep->error_count = 0;
428
429 if (usb_pipecontrol(urb->pipe))
430 ep->nextpid = USB_PID_SETUP;
431
432 urb_dbg(urb, "Finish");
433
434 spin_unlock(&isp116x->lock);
435 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb);
436 spin_lock(&isp116x->lock);
437
438 /* take idle endpoints out of the schedule */
439 if (!list_empty(&ep->hep->urb_list))
440 return;
441
442 /* async deschedule */
443 if (!list_empty(&ep->schedule)) {
444 list_del_init(&ep->schedule);
445 return;
446 }
447 459
448 /* periodic deschedule */ 460 done:
449 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 461 if (status != -EINPROGRESS) {
450 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 462 spin_lock(&urb->lock);
451 struct isp116x_ep *temp; 463 if (urb->status == -EINPROGRESS)
452 struct isp116x_ep **prev = &isp116x->periodic[i]; 464 urb->status = status;
453 465 spin_unlock(&urb->lock);
454 while (*prev && ((temp = *prev) != ep)) 466 }
455 prev = &temp->next; 467 if (urb->status != -EINPROGRESS)
456 if (*prev) 468 finish_request(isp116x, ep, urb);
457 *prev = ep->next;
458 isp116x->load[i] -= ep->load;
459 }
460 ep->branch = PERIODIC_SIZE;
461 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
462 ep->load / ep->period;
463
464 /* switch irq type? */
465 if (!--isp116x->periodic_count) {
466 isp116x->irqenb &= ~HCuPINT_SOF;
467 isp116x->irqenb |= HCuPINT_ATL;
468 } 469 }
469} 470}
470 471
@@ -570,9 +571,6 @@ static void start_atl_transfers(struct isp116x *isp116x)
570*/ 571*/
571static void finish_atl_transfers(struct isp116x *isp116x) 572static void finish_atl_transfers(struct isp116x *isp116x)
572{ 573{
573 struct isp116x_ep *ep;
574 struct urb *urb;
575
576 if (!isp116x->atl_active) 574 if (!isp116x->atl_active)
577 return; 575 return;
578 /* Fifo not ready? */ 576 /* Fifo not ready? */
@@ -582,16 +580,6 @@ static void finish_atl_transfers(struct isp116x *isp116x)
582 atomic_inc(&isp116x->atl_finishing); 580 atomic_inc(&isp116x->atl_finishing);
583 unpack_fifo(isp116x); 581 unpack_fifo(isp116x);
584 postproc_atl_queue(isp116x); 582 postproc_atl_queue(isp116x);
585 for (ep = isp116x->atl_active; ep; ep = ep->active) {
586 urb =
587 container_of(ep->hep->urb_list.next, struct urb, urb_list);
588 /* USB_PID_ACK check here avoids finishing of
589 control transfers, for which TD_DATAUNDERRUN
590 occured, while URB_SHORT_NOT_OK was set */
591 if (urb && urb->status != -EINPROGRESS
592 && ep->nextpid != USB_PID_ACK)
593 finish_request(isp116x, ep, urb);
594 }
595 atomic_dec(&isp116x->atl_finishing); 583 atomic_dec(&isp116x->atl_finishing);
596} 584}
597 585
@@ -821,15 +809,12 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
821 } 809 }
822 810
823 /* in case of unlink-during-submit */ 811 /* in case of unlink-during-submit */
824 spin_lock(&urb->lock);
825 if (urb->status != -EINPROGRESS) { 812 if (urb->status != -EINPROGRESS) {
826 spin_unlock(&urb->lock);
827 finish_request(isp116x, ep, urb); 813 finish_request(isp116x, ep, urb);
828 ret = 0; 814 ret = 0;
829 goto fail; 815 goto fail;
830 } 816 }
831 urb->hcpriv = hep; 817 urb->hcpriv = hep;
832 spin_unlock(&urb->lock);
833 start_atl_transfers(isp116x); 818 start_atl_transfers(isp116x);
834 819
835 fail: 820 fail:
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index a7a7070c6e2a..d60f1985320c 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -35,10 +35,8 @@
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38 38#include <linux/io.h>
39#include <asm/io.h> 39#include <linux/irq.h>
40#include <asm/irq.h>
41#include <asm/system.h>
42 40
43#include "../core/hcd.h" 41#include "../core/hcd.h"
44#include "r8a66597.h" 42#include "r8a66597.h"
@@ -54,16 +52,21 @@ static const char hcd_name[] = "r8a66597_hcd";
54/* module parameters */ 52/* module parameters */
55static unsigned short clock = XTAL12; 53static unsigned short clock = XTAL12;
56module_param(clock, ushort, 0644); 54module_param(clock, ushort, 0644);
57MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=0)"); 55MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
56 "(default=0)");
57
58static unsigned short vif = LDRV; 58static unsigned short vif = LDRV;
59module_param(vif, ushort, 0644); 59module_param(vif, ushort, 0644);
60MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); 60MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)");
61static unsigned short endian = 0; 61
62static unsigned short endian;
62module_param(endian, ushort, 0644); 63module_param(endian, ushort, 0644);
63MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); 64MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
65
64static unsigned short irq_sense = INTL; 66static unsigned short irq_sense = INTL;
65module_param(irq_sense, ushort, 0644); 67module_param(irq_sense, ushort, 0644);
66MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0(default=32)"); 68MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0 "
69 "(default=32)");
67 70
68static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); 71static void packet_write(struct r8a66597 *r8a66597, u16 pipenum);
69static int r8a66597_get_frame(struct usb_hcd *hcd); 72static int r8a66597_get_frame(struct usb_hcd *hcd);
@@ -308,7 +311,7 @@ static int make_r8a66597_device(struct r8a66597 *r8a66597,
308 struct r8a66597_device *dev; 311 struct r8a66597_device *dev;
309 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ 312 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
310 313
311 dev = kzalloc(sizeof(struct r8a66597_device), GFP_KERNEL); 314 dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
312 if (dev == NULL) 315 if (dev == NULL)
313 return -ENOMEM; 316 return -ENOMEM;
314 317
@@ -611,33 +614,33 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
611 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; 614 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
612 615
613 memset(array, 0, sizeof(array)); 616 memset(array, 0, sizeof(array));
614 switch(ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 617 switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
615 case USB_ENDPOINT_XFER_BULK: 618 case USB_ENDPOINT_XFER_BULK:
616 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 619 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
617 array[i++] = 4; 620 array[i++] = 4;
618 else { 621 else {
619 array[i++] = 3; 622 array[i++] = 3;
620 array[i++] = 5; 623 array[i++] = 5;
621 } 624 }
622 break; 625 break;
623 case USB_ENDPOINT_XFER_INT: 626 case USB_ENDPOINT_XFER_INT:
624 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { 627 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
625 array[i++] = 6; 628 array[i++] = 6;
626 array[i++] = 7; 629 array[i++] = 7;
627 array[i++] = 8; 630 array[i++] = 8;
628 } else 631 } else
629 array[i++] = 9; 632 array[i++] = 9;
630 break; 633 break;
631 case USB_ENDPOINT_XFER_ISOC: 634 case USB_ENDPOINT_XFER_ISOC:
632 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 635 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
633 array[i++] = 2; 636 array[i++] = 2;
634 else 637 else
635 array[i++] = 1; 638 array[i++] = 1;
636 break; 639 break;
637 default: 640 default:
638 err("Illegal type"); 641 err("Illegal type");
639 return 0; 642 return 0;
640 } 643 }
641 644
642 i = 1; 645 i = 1;
643 min = array[0]; 646 min = array[0];
@@ -654,7 +657,7 @@ static u16 get_r8a66597_type(__u8 type)
654{ 657{
655 u16 r8a66597_type; 658 u16 r8a66597_type;
656 659
657 switch(type) { 660 switch (type) {
658 case USB_ENDPOINT_XFER_BULK: 661 case USB_ENDPOINT_XFER_BULK:
659 r8a66597_type = R8A66597_BULK; 662 r8a66597_type = R8A66597_BULK;
660 break; 663 break;
@@ -874,7 +877,7 @@ static void r8a66597_usb_preconnect(struct r8a66597 *r8a66597, int port)
874{ 877{
875 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) 878 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION)
876 | (1 << USB_PORT_FEAT_C_CONNECTION); 879 | (1 << USB_PORT_FEAT_C_CONNECTION);
877 r8a66597_write(r8a66597, (u16)~DTCH, get_intsts_reg(port)); 880 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
878 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); 881 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
879} 882}
880 883
@@ -917,7 +920,7 @@ static void prepare_setup_packet(struct r8a66597 *r8a66597,
917 920
918 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, 921 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
919 DCPMAXP); 922 DCPMAXP);
920 r8a66597_write(r8a66597, (u16)~(SIGN | SACK), INTSTS1); 923 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
921 924
922 for (i = 0; i < 4; i++) { 925 for (i = 0; i < 4; i++) {
923 r8a66597_write(r8a66597, p[i], setup_addr); 926 r8a66597_write(r8a66597, p[i], setup_addr);
@@ -948,19 +951,18 @@ static void prepare_packet_read(struct r8a66597 *r8a66597,
948 pipe_irq_disable(r8a66597, td->pipenum); 951 pipe_irq_disable(r8a66597, td->pipenum);
949 pipe_setting(r8a66597, td); 952 pipe_setting(r8a66597, td);
950 pipe_stop(r8a66597, td->pipe); 953 pipe_stop(r8a66597, td->pipe);
951 r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), 954 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
952 BRDYSTS);
953 955
954 if (td->pipe->pipetre) { 956 if (td->pipe->pipetre) {
955 r8a66597_write(r8a66597, TRCLR, 957 r8a66597_write(r8a66597, TRCLR,
956 td->pipe->pipetre); 958 td->pipe->pipetre);
957 r8a66597_write(r8a66597, 959 r8a66597_write(r8a66597,
958 (urb->transfer_buffer_length 960 (urb->transfer_buffer_length
959 + td->maxpacket - 1) 961 + td->maxpacket - 1)
960 / td->maxpacket, 962 / td->maxpacket,
961 td->pipe->pipetrn); 963 td->pipe->pipetrn);
962 r8a66597_bset(r8a66597, TRENB, 964 r8a66597_bset(r8a66597, TRENB,
963 td->pipe->pipetre); 965 td->pipe->pipetre);
964 } 966 }
965 967
966 pipe_start(r8a66597, td->pipe); 968 pipe_start(r8a66597, td->pipe);
@@ -991,7 +993,7 @@ static void prepare_packet_write(struct r8a66597 *r8a66597,
991 if (td->pipe->pipetre) 993 if (td->pipe->pipetre)
992 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); 994 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
993 } 995 }
994 r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), BRDYSTS); 996 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
995 997
996 fifo_change_from_pipe(r8a66597, td->pipe); 998 fifo_change_from_pipe(r8a66597, td->pipe);
997 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); 999 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
@@ -1009,21 +1011,21 @@ static void prepare_status_packet(struct r8a66597 *r8a66597,
1009 struct urb *urb = td->urb; 1011 struct urb *urb = td->urb;
1010 1012
1011 r8a66597_pipe_toggle(r8a66597, td->pipe, 1); 1013 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1014 pipe_stop(r8a66597, td->pipe);
1012 1015
1013 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { 1016 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
1014 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); 1017 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1015 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); 1018 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1016 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); 1019 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1017 r8a66597_write(r8a66597, BVAL | BCLR, CFIFOCTR); 1020 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
1018 r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); 1021 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1022 r8a66597_write(r8a66597, BVAL, CFIFOCTR);
1019 enable_irq_empty(r8a66597, 0); 1023 enable_irq_empty(r8a66597, 0);
1020 } else { 1024 } else {
1021 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); 1025 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1022 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); 1026 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1023 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); 1027 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1024 r8a66597_write(r8a66597, BCLR, CFIFOCTR); 1028 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1025 r8a66597_write(r8a66597, (u16)~BRDY0, BRDYSTS);
1026 r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS);
1027 enable_irq_ready(r8a66597, 0); 1029 enable_irq_ready(r8a66597, 0);
1028 } 1030 }
1029 enable_irq_nrdy(r8a66597, 0); 1031 enable_irq_nrdy(r8a66597, 0);
@@ -1269,7 +1271,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1269 1271
1270 /* write fifo */ 1272 /* write fifo */
1271 if (pipenum > 0) 1273 if (pipenum > 0)
1272 r8a66597_write(r8a66597, (u16)~(1 << pipenum), BEMPSTS); 1274 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
1273 if (urb->transfer_buffer) { 1275 if (urb->transfer_buffer) {
1274 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); 1276 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size);
1275 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) 1277 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
@@ -1362,7 +1364,7 @@ static void irq_pipe_ready(struct r8a66597 *r8a66597)
1362 1364
1363 mask = r8a66597_read(r8a66597, BRDYSTS) 1365 mask = r8a66597_read(r8a66597, BRDYSTS)
1364 & r8a66597_read(r8a66597, BRDYENB); 1366 & r8a66597_read(r8a66597, BRDYENB);
1365 r8a66597_write(r8a66597, (u16)~mask, BRDYSTS); 1367 r8a66597_write(r8a66597, ~mask, BRDYSTS);
1366 if (mask & BRDY0) { 1368 if (mask & BRDY0) {
1367 td = r8a66597_get_td(r8a66597, 0); 1369 td = r8a66597_get_td(r8a66597, 0);
1368 if (td && td->type == USB_PID_IN) 1370 if (td && td->type == USB_PID_IN)
@@ -1397,7 +1399,7 @@ static void irq_pipe_empty(struct r8a66597 *r8a66597)
1397 1399
1398 mask = r8a66597_read(r8a66597, BEMPSTS) 1400 mask = r8a66597_read(r8a66597, BEMPSTS)
1399 & r8a66597_read(r8a66597, BEMPENB); 1401 & r8a66597_read(r8a66597, BEMPENB);
1400 r8a66597_write(r8a66597, (u16)~mask, BEMPSTS); 1402 r8a66597_write(r8a66597, ~mask, BEMPSTS);
1401 if (mask & BEMP0) { 1403 if (mask & BEMP0) {
1402 cfifo_change(r8a66597, 0); 1404 cfifo_change(r8a66597, 0);
1403 td = r8a66597_get_td(r8a66597, 0); 1405 td = r8a66597_get_td(r8a66597, 0);
@@ -1434,7 +1436,7 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1434 1436
1435 mask = r8a66597_read(r8a66597, NRDYSTS) 1437 mask = r8a66597_read(r8a66597, NRDYSTS)
1436 & r8a66597_read(r8a66597, NRDYENB); 1438 & r8a66597_read(r8a66597, NRDYENB);
1437 r8a66597_write(r8a66597, (u16)~mask, NRDYSTS); 1439 r8a66597_write(r8a66597, ~mask, NRDYSTS);
1438 if (mask & NRDY0) { 1440 if (mask & NRDY0) {
1439 cfifo_change(r8a66597, 0); 1441 cfifo_change(r8a66597, 0);
1440 set_urb_error(r8a66597, 0); 1442 set_urb_error(r8a66597, 0);
@@ -1488,14 +1490,14 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1488 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); 1490 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
1489 if (mask2) { 1491 if (mask2) {
1490 if (mask2 & ATTCH) { 1492 if (mask2 & ATTCH) {
1491 r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS2); 1493 r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
1492 r8a66597_bclr(r8a66597, ATTCHE, INTENB2); 1494 r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
1493 1495
1494 /* start usb bus sampling */ 1496 /* start usb bus sampling */
1495 start_root_hub_sampling(r8a66597, 1); 1497 start_root_hub_sampling(r8a66597, 1);
1496 } 1498 }
1497 if (mask2 & DTCH) { 1499 if (mask2 & DTCH) {
1498 r8a66597_write(r8a66597, (u16)~DTCH, INTSTS2); 1500 r8a66597_write(r8a66597, ~DTCH, INTSTS2);
1499 r8a66597_bclr(r8a66597, DTCHE, INTENB2); 1501 r8a66597_bclr(r8a66597, DTCHE, INTENB2);
1500 r8a66597_usb_disconnect(r8a66597, 1); 1502 r8a66597_usb_disconnect(r8a66597, 1);
1501 } 1503 }
@@ -1503,24 +1505,24 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1503 1505
1504 if (mask1) { 1506 if (mask1) {
1505 if (mask1 & ATTCH) { 1507 if (mask1 & ATTCH) {
1506 r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS1); 1508 r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
1507 r8a66597_bclr(r8a66597, ATTCHE, INTENB1); 1509 r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
1508 1510
1509 /* start usb bus sampling */ 1511 /* start usb bus sampling */
1510 start_root_hub_sampling(r8a66597, 0); 1512 start_root_hub_sampling(r8a66597, 0);
1511 } 1513 }
1512 if (mask1 & DTCH) { 1514 if (mask1 & DTCH) {
1513 r8a66597_write(r8a66597, (u16)~DTCH, INTSTS1); 1515 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
1514 r8a66597_bclr(r8a66597, DTCHE, INTENB1); 1516 r8a66597_bclr(r8a66597, DTCHE, INTENB1);
1515 r8a66597_usb_disconnect(r8a66597, 0); 1517 r8a66597_usb_disconnect(r8a66597, 0);
1516 } 1518 }
1517 if (mask1 & SIGN) { 1519 if (mask1 & SIGN) {
1518 r8a66597_write(r8a66597, (u16)~SIGN, INTSTS1); 1520 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1519 set_urb_error(r8a66597, 0); 1521 set_urb_error(r8a66597, 0);
1520 check_next_phase(r8a66597); 1522 check_next_phase(r8a66597);
1521 } 1523 }
1522 if (mask1 & SACK) { 1524 if (mask1 & SACK) {
1523 r8a66597_write(r8a66597, (u16)~SACK, INTSTS1); 1525 r8a66597_write(r8a66597, ~SACK, INTSTS1);
1524 check_next_phase(r8a66597); 1526 check_next_phase(r8a66597);
1525 } 1527 }
1526 } 1528 }
@@ -1663,13 +1665,9 @@ static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
1663static int r8a66597_start(struct usb_hcd *hcd) 1665static int r8a66597_start(struct usb_hcd *hcd)
1664{ 1666{
1665 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1667 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1666 int ret;
1667 1668
1668 hcd->state = HC_STATE_RUNNING; 1669 hcd->state = HC_STATE_RUNNING;
1669 if ((ret = enable_controller(r8a66597)) < 0) 1670 return enable_controller(r8a66597);
1670 return ret;
1671
1672 return 0;
1673} 1671}
1674 1672
1675static void r8a66597_stop(struct usb_hcd *hcd) 1673static void r8a66597_stop(struct usb_hcd *hcd)
@@ -1696,13 +1694,12 @@ static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
1696 1694
1697static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, 1695static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1698 struct urb *urb, 1696 struct urb *urb,
1699 struct usb_host_endpoint *hep, 1697 struct usb_host_endpoint *hep)
1700 gfp_t mem_flags)
1701{ 1698{
1702 struct r8a66597_td *td; 1699 struct r8a66597_td *td;
1703 u16 pipenum; 1700 u16 pipenum;
1704 1701
1705 td = kzalloc(sizeof(struct r8a66597_td), mem_flags); 1702 td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
1706 if (td == NULL) 1703 if (td == NULL)
1707 return NULL; 1704 return NULL;
1708 1705
@@ -1741,7 +1738,8 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1741 } 1738 }
1742 1739
1743 if (!hep->hcpriv) { 1740 if (!hep->hcpriv) {
1744 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), mem_flags); 1741 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1742 GFP_ATOMIC);
1745 if (!hep->hcpriv) { 1743 if (!hep->hcpriv) {
1746 ret = -ENOMEM; 1744 ret = -ENOMEM;
1747 goto error; 1745 goto error;
@@ -1755,7 +1753,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1755 init_pipe_config(r8a66597, urb); 1753 init_pipe_config(r8a66597, urb);
1756 1754
1757 set_address_zero(r8a66597, urb); 1755 set_address_zero(r8a66597, urb);
1758 td = r8a66597_make_td(r8a66597, urb, hep, mem_flags); 1756 td = r8a66597_make_td(r8a66597, urb, hep);
1759 if (td == NULL) { 1757 if (td == NULL) {
1760 ret = -ENOMEM; 1758 ret = -ENOMEM;
1761 goto error; 1759 goto error;
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index 97c2a71ac7a1..fe9ceb077d9b 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -203,14 +203,14 @@
203#define DTLN 0x0FFF /* b11-0: FIFO received data length */ 203#define DTLN 0x0FFF /* b11-0: FIFO received data length */
204 204
205/* Interrupt Enable Register 0 */ 205/* Interrupt Enable Register 0 */
206#define VBSE 0x8000 /* b15: VBUS interrupt */ 206#define VBSE 0x8000 /* b15: VBUS interrupt */
207#define RSME 0x4000 /* b14: Resume interrupt */ 207#define RSME 0x4000 /* b14: Resume interrupt */
208#define SOFE 0x2000 /* b13: Frame update interrupt */ 208#define SOFE 0x2000 /* b13: Frame update interrupt */
209#define DVSE 0x1000 /* b12: Device state transition interrupt */ 209#define DVSE 0x1000 /* b12: Device state transition interrupt */
210#define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ 210#define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */
211#define BEMPE 0x0400 /* b10: Buffer empty interrupt */ 211#define BEMPE 0x0400 /* b10: Buffer empty interrupt */
212#define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ 212#define NRDYE 0x0200 /* b9: Buffer not ready interrupt */
213#define BRDYE 0x0100 /* b8: Buffer ready interrupt */ 213#define BRDYE 0x0100 /* b8: Buffer ready interrupt */
214 214
215/* Interrupt Enable Register 1 */ 215/* Interrupt Enable Register 1 */
216#define OVRCRE 0x8000 /* b15: Over-current interrupt */ 216#define OVRCRE 0x8000 /* b15: Over-current interrupt */
@@ -268,16 +268,16 @@
268#define SOF_DISABLE 0x0000 /* SOF OUT Disable */ 268#define SOF_DISABLE 0x0000 /* SOF OUT Disable */
269 269
270/* Interrupt Status Register 0 */ 270/* Interrupt Status Register 0 */
271#define VBINT 0x8000 /* b15: VBUS interrupt */ 271#define VBINT 0x8000 /* b15: VBUS interrupt */
272#define RESM 0x4000 /* b14: Resume interrupt */ 272#define RESM 0x4000 /* b14: Resume interrupt */
273#define SOFR 0x2000 /* b13: SOF frame update interrupt */ 273#define SOFR 0x2000 /* b13: SOF frame update interrupt */
274#define DVST 0x1000 /* b12: Device state transition interrupt */ 274#define DVST 0x1000 /* b12: Device state transition interrupt */
275#define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ 275#define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */
276#define BEMP 0x0400 /* b10: Buffer empty interrupt */ 276#define BEMP 0x0400 /* b10: Buffer empty interrupt */
277#define NRDY 0x0200 /* b9: Buffer not ready interrupt */ 277#define NRDY 0x0200 /* b9: Buffer not ready interrupt */
278#define BRDY 0x0100 /* b8: Buffer ready interrupt */ 278#define BRDY 0x0100 /* b8: Buffer ready interrupt */
279#define VBSTS 0x0080 /* b7: VBUS input port */ 279#define VBSTS 0x0080 /* b7: VBUS input port */
280#define DVSQ 0x0070 /* b6-4: Device state */ 280#define DVSQ 0x0070 /* b6-4: Device state */
281#define DS_SPD_CNFG 0x0070 /* Suspend Configured */ 281#define DS_SPD_CNFG 0x0070 /* Suspend Configured */
282#define DS_SPD_ADDR 0x0060 /* Suspend Address */ 282#define DS_SPD_ADDR 0x0060 /* Suspend Address */
283#define DS_SPD_DFLT 0x0050 /* Suspend Default */ 283#define DS_SPD_DFLT 0x0050 /* Suspend Default */
@@ -315,13 +315,10 @@
315/* Micro Frame Number Register */ 315/* Micro Frame Number Register */
316#define UFRNM 0x0007 /* b2-0: Micro frame number */ 316#define UFRNM 0x0007 /* b2-0: Micro frame number */
317 317
318/* USB Address / Low Power Status Recovery Register */
319//#define USBADDR 0x007F /* b6-0: USB address */
320
321/* Default Control Pipe Maxpacket Size Register */ 318/* Default Control Pipe Maxpacket Size Register */
322/* Pipe Maxpacket Size Register */ 319/* Pipe Maxpacket Size Register */
323#define DEVSEL 0xF000 /* b15-14: Device address select */ 320#define DEVSEL 0xF000 /* b15-14: Device address select */
324#define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ 321#define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */
325 322
326/* Default Control Pipe Control Register */ 323/* Default Control Pipe Control Register */
327#define BSTS 0x8000 /* b15: Buffer status */ 324#define BSTS 0x8000 /* b15: Buffer status */
@@ -366,21 +363,21 @@
366#define MXPS 0x07FF /* b10-0: Maxpacket size */ 363#define MXPS 0x07FF /* b10-0: Maxpacket size */
367 364
368/* Pipe Cycle Configuration Register */ 365/* Pipe Cycle Configuration Register */
369#define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ 366#define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */
370#define IITV 0x0007 /* b2-0: Isochronous interval */ 367#define IITV 0x0007 /* b2-0: Isochronous interval */
371 368
372/* Pipex Control Register */ 369/* Pipex Control Register */
373#define BSTS 0x8000 /* b15: Buffer status */ 370#define BSTS 0x8000 /* b15: Buffer status */
374#define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ 371#define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */
375#define CSCLR 0x2000 /* b13: complete-split status clear */ 372#define CSCLR 0x2000 /* b13: complete-split status clear */
376#define CSSTS 0x1000 /* b12: complete-split status */ 373#define CSSTS 0x1000 /* b12: complete-split status */
377#define ATREPM 0x0400 /* b10: Auto repeat mode */ 374#define ATREPM 0x0400 /* b10: Auto repeat mode */
378#define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ 375#define ACLRM 0x0200 /* b9: Out buffer auto clear mode */
379#define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ 376#define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
380#define SQSET 0x0080 /* b7: Sequence toggle bit set */ 377#define SQSET 0x0080 /* b7: Sequence toggle bit set */
381#define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ 378#define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
382#define PBUSY 0x0020 /* b5: pipe busy */ 379#define PBUSY 0x0020 /* b5: pipe busy */
383#define PID 0x0003 /* b1-0: Response PID */ 380#define PID 0x0003 /* b1-0: Response PID */
384 381
385/* PIPExTRE */ 382/* PIPExTRE */
386#define TRENB 0x0200 /* b9: Transaction counter enable */ 383#define TRENB 0x0200 /* b9: Transaction counter enable */
@@ -407,15 +404,15 @@
407#define make_devsel(addr) (addr << 12) 404#define make_devsel(addr) (addr << 12)
408 405
409struct r8a66597_pipe_info { 406struct r8a66597_pipe_info {
410 u16 pipenum; 407 u16 pipenum;
411 u16 address; /* R8A66597 HCD usb addres */ 408 u16 address; /* R8A66597 HCD usb addres */
412 u16 epnum; 409 u16 epnum;
413 u16 maxpacket; 410 u16 maxpacket;
414 u16 type; 411 u16 type;
415 u16 bufnum; 412 u16 bufnum;
416 u16 buf_bsize; 413 u16 buf_bsize;
417 u16 interval; 414 u16 interval;
418 u16 dir_in; 415 u16 dir_in;
419}; 416};
420 417
421struct r8a66597_pipe { 418struct r8a66597_pipe {
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index e98df2ee9901..7f765ec038cd 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -52,6 +52,7 @@
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/platform_device.h> 53#include <linux/platform_device.h>
54#include <linux/pci_ids.h> 54#include <linux/pci_ids.h>
55#include <linux/mutex.h>
55#include <asm/io.h> 56#include <asm/io.h>
56#include <asm/irq.h> 57#include <asm/irq.h>
57#include <asm/system.h> 58#include <asm/system.h>
@@ -83,7 +84,7 @@ static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
83* u132_module_lock exists to protect access to global variables 84* u132_module_lock exists to protect access to global variables
84* 85*
85*/ 86*/
86static struct semaphore u132_module_lock; 87static struct mutex u132_module_lock;
87static int u132_exiting = 0; 88static int u132_exiting = 0;
88static int u132_instances = 0; 89static int u132_instances = 0;
89static struct list_head u132_static_list; 90static struct list_head u132_static_list;
@@ -258,10 +259,10 @@ static void u132_hcd_delete(struct kref *kref)
258 struct platform_device *pdev = u132->platform_dev; 259 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132); 260 struct usb_hcd *hcd = u132_to_hcd(u132);
260 u132->going += 1; 261 u132->going += 1;
261 down(&u132_module_lock); 262 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list); 263 list_del_init(&u132->u132_list);
263 u132_instances -= 1; 264 u132_instances -= 1;
264 up(&u132_module_lock); 265 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" 266 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); 267 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
267 usb_put_hcd(hcd); 268 usb_put_hcd(hcd);
@@ -3111,10 +3112,10 @@ static int __devinit u132_probe(struct platform_device *pdev)
3111 int retval = 0; 3112 int retval = 0;
3112 struct u132 *u132 = hcd_to_u132(hcd); 3113 struct u132 *u132 = hcd_to_u132(hcd);
3113 hcd->rsrc_start = 0; 3114 hcd->rsrc_start = 0;
3114 down(&u132_module_lock); 3115 mutex_lock(&u132_module_lock);
3115 list_add_tail(&u132->u132_list, &u132_static_list); 3116 list_add_tail(&u132->u132_list, &u132_static_list);
3116 u132->sequence_num = ++u132_instances; 3117 u132->sequence_num = ++u132_instances;
3117 up(&u132_module_lock); 3118 mutex_unlock(&u132_module_lock);
3118 u132_u132_init_kref(u132); 3119 u132_u132_init_kref(u132);
3119 u132_initialise(u132, pdev); 3120 u132_initialise(u132, pdev);
3120 hcd->product_desc = "ELAN U132 Host Controller"; 3121 hcd->product_desc = "ELAN U132 Host Controller";
@@ -3216,7 +3217,7 @@ static int __init u132_hcd_init(void)
3216 INIT_LIST_HEAD(&u132_static_list); 3217 INIT_LIST_HEAD(&u132_static_list);
3217 u132_instances = 0; 3218 u132_instances = 0;
3218 u132_exiting = 0; 3219 u132_exiting = 0;
3219 init_MUTEX(&u132_module_lock); 3220 mutex_init(&u132_module_lock);
3220 if (usb_disabled()) 3221 if (usb_disabled())
3221 return -ENODEV; 3222 return -ENODEV;
3222 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, 3223 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
@@ -3232,9 +3233,9 @@ static void __exit u132_hcd_exit(void)
3232{ 3233{
3233 struct u132 *u132; 3234 struct u132 *u132;
3234 struct u132 *temp; 3235 struct u132 *temp;
3235 down(&u132_module_lock); 3236 mutex_lock(&u132_module_lock);
3236 u132_exiting += 1; 3237 u132_exiting += 1;
3237 up(&u132_module_lock); 3238 mutex_unlock(&u132_module_lock);
3238 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { 3239 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3239 platform_device_unregister(u132->platform_dev); 3240 platform_device_unregister(u132->platform_dev);
3240 } platform_driver_unregister(&u132_platform_driver); 3241 } platform_driver_unregister(&u132_platform_driver);
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 4aed305982ec..3bb908ca38e9 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -827,8 +827,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
827 * If direction is "send", change the packet ID from SETUP (0x2D) 827 * If direction is "send", change the packet ID from SETUP (0x2D)
828 * to OUT (0xE1). Else change it from SETUP to IN (0x69) and 828 * to OUT (0xE1). Else change it from SETUP to IN (0x69) and
829 * set Short Packet Detect (SPD) for all data packets. 829 * set Short Packet Detect (SPD) for all data packets.
830 *
831 * 0-length transfers always get treated as "send".
830 */ 832 */
831 if (usb_pipeout(urb->pipe)) 833 if (usb_pipeout(urb->pipe) || len == 0)
832 destination ^= (USB_PID_SETUP ^ USB_PID_OUT); 834 destination ^= (USB_PID_SETUP ^ USB_PID_OUT);
833 else { 835 else {
834 destination ^= (USB_PID_SETUP ^ USB_PID_IN); 836 destination ^= (USB_PID_SETUP ^ USB_PID_IN);
@@ -839,7 +841,12 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
839 * Build the DATA TDs 841 * Build the DATA TDs
840 */ 842 */
841 while (len > 0) { 843 while (len > 0) {
842 int pktsze = min(len, maxsze); 844 int pktsze = maxsze;
845
846 if (len <= pktsze) { /* The last data packet */
847 pktsze = len;
848 status &= ~TD_CTRL_SPD;
849 }
843 850
844 td = uhci_alloc_td(uhci); 851 td = uhci_alloc_td(uhci);
845 if (!td) 852 if (!td)
@@ -866,20 +873,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
866 goto nomem; 873 goto nomem;
867 *plink = LINK_TO_TD(td); 874 *plink = LINK_TO_TD(td);
868 875
869 /* 876 /* Change direction for the status transaction */
870 * It's IN if the pipe is an output pipe or we're not expecting 877 destination ^= (USB_PID_IN ^ USB_PID_OUT);
871 * data back.
872 */
873 destination &= ~TD_TOKEN_PID_MASK;
874 if (usb_pipeout(urb->pipe) || !urb->transfer_buffer_length)
875 destination |= USB_PID_IN;
876 else
877 destination |= USB_PID_OUT;
878
879 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ 878 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */
880 879
881 status &= ~TD_CTRL_SPD;
882
883 uhci_add_td_to_urbp(td, urbp); 880 uhci_add_td_to_urbp(td, urbp);
884 uhci_fill_td(td, status | TD_CTRL_IOC, 881 uhci_fill_td(td, status | TD_CTRL_IOC,
885 destination | uhci_explen(0), 0); 882 destination | uhci_explen(0), 0);
@@ -1185,10 +1182,18 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1185 } 1182 }
1186 } 1183 }
1187 1184
1185 /* Did we receive a short packet? */
1188 } else if (len < uhci_expected_length(td_token(td))) { 1186 } else if (len < uhci_expected_length(td_token(td))) {
1189 1187
1190 /* We received a short packet */ 1188 /* For control transfers, go to the status TD if
1191 if (urb->transfer_flags & URB_SHORT_NOT_OK) 1189 * this isn't already the last data TD */
1190 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1191 if (td->list.next != urbp->td_list.prev)
1192 ret = 1;
1193 }
1194
1195 /* For bulk and interrupt, this may be an error */
1196 else if (urb->transfer_flags & URB_SHORT_NOT_OK)
1192 ret = -EREMOTEIO; 1197 ret = -EREMOTEIO;
1193 1198
1194 /* Fixup needed only if this isn't the URB's last TD */ 1199 /* Fixup needed only if this isn't the URB's last TD */
@@ -1208,10 +1213,6 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1208 1213
1209err: 1214err:
1210 if (ret < 0) { 1215 if (ret < 0) {
1211 /* In case a control transfer gets an error
1212 * during the setup stage */
1213 urb->actual_length = max(urb->actual_length, 0);
1214
1215 /* Note that the queue has stopped and save 1216 /* Note that the queue has stopped and save
1216 * the next toggle value */ 1217 * the next toggle value */
1217 qh->element = UHCI_PTR_TERM; 1218 qh->element = UHCI_PTR_TERM;
@@ -1489,9 +1490,25 @@ __acquires(uhci->lock)
1489{ 1490{
1490 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; 1491 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1491 1492
1493 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1494
1495 /* urb->actual_length < 0 means the setup transaction didn't
1496 * complete successfully. Either it failed or the URB was
1497 * unlinked first. Regardless, don't confuse people with a
1498 * negative length. */
1499 urb->actual_length = max(urb->actual_length, 0);
1500
1501 /* Report erroneous short transfers */
1502 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1503 urb->actual_length <
1504 urb->transfer_buffer_length &&
1505 urb->status == 0))
1506 urb->status = -EREMOTEIO;
1507 }
1508
1492 /* When giving back the first URB in an Isochronous queue, 1509 /* When giving back the first URB in an Isochronous queue,
1493 * reinitialize the QH's iso-related members for the next URB. */ 1510 * reinitialize the QH's iso-related members for the next URB. */
1494 if (qh->type == USB_ENDPOINT_XFER_ISOC && 1511 else if (qh->type == USB_ENDPOINT_XFER_ISOC &&
1495 urbp->node.prev == &qh->queue && 1512 urbp->node.prev == &qh->queue &&
1496 urbp->node.next != &qh->queue) { 1513 urbp->node.next != &qh->queue) {
1497 struct urb *nurb = list_entry(urbp->node.next, 1514 struct urb *nurb = list_entry(urbp->node.next,