aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/dummy_hcd.c432
1 files changed, 211 insertions, 221 deletions
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index fd4d86a57142..67573e5f2a18 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -42,25 +42,24 @@
42#include <linux/scatterlist.h> 42#include <linux/scatterlist.h>
43 43
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#include <asm/io.h> 45#include <linux/io.h>
46#include <asm/irq.h> 46#include <asm/irq.h>
47#include <asm/system.h> 47#include <asm/system.h>
48#include <asm/unaligned.h> 48#include <asm/unaligned.h>
49 49
50
51#define DRIVER_DESC "USB Host+Gadget Emulator" 50#define DRIVER_DESC "USB Host+Gadget Emulator"
52#define DRIVER_VERSION "02 May 2005" 51#define DRIVER_VERSION "02 May 2005"
53 52
54#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */ 53#define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
55 54
56static const char driver_name [] = "dummy_hcd"; 55static const char driver_name[] = "dummy_hcd";
57static const char driver_desc [] = "USB Host+Gadget Emulator"; 56static const char driver_desc[] = "USB Host+Gadget Emulator";
58 57
59static const char gadget_name [] = "dummy_udc"; 58static const char gadget_name[] = "dummy_udc";
60 59
61MODULE_DESCRIPTION (DRIVER_DESC); 60MODULE_DESCRIPTION(DRIVER_DESC);
62MODULE_AUTHOR ("David Brownell"); 61MODULE_AUTHOR("David Brownell");
63MODULE_LICENSE ("GPL"); 62MODULE_LICENSE("GPL");
64 63
65struct dummy_hcd_module_parameters { 64struct dummy_hcd_module_parameters {
66 bool is_super_speed; 65 bool is_super_speed;
@@ -84,10 +83,10 @@ struct dummy_ep {
84 struct usb_gadget *gadget; 83 struct usb_gadget *gadget;
85 const struct usb_endpoint_descriptor *desc; 84 const struct usb_endpoint_descriptor *desc;
86 struct usb_ep ep; 85 struct usb_ep ep;
87 unsigned halted : 1; 86 unsigned halted:1;
88 unsigned wedged : 1; 87 unsigned wedged:1;
89 unsigned already_seen : 1; 88 unsigned already_seen:1;
90 unsigned setup_stage : 1; 89 unsigned setup_stage:1;
91 unsigned stream_en:1; 90 unsigned stream_en:1;
92}; 91};
93 92
@@ -96,15 +95,15 @@ struct dummy_request {
96 struct usb_request req; 95 struct usb_request req;
97}; 96};
98 97
99static inline struct dummy_ep *usb_ep_to_dummy_ep (struct usb_ep *_ep) 98static inline struct dummy_ep *usb_ep_to_dummy_ep(struct usb_ep *_ep)
100{ 99{
101 return container_of (_ep, struct dummy_ep, ep); 100 return container_of(_ep, struct dummy_ep, ep);
102} 101}
103 102
104static inline struct dummy_request *usb_request_to_dummy_request 103static inline struct dummy_request *usb_request_to_dummy_request
105 (struct usb_request *_req) 104 (struct usb_request *_req)
106{ 105{
107 return container_of (_req, struct dummy_request, req); 106 return container_of(_req, struct dummy_request, req);
108} 107}
109 108
110/*-------------------------------------------------------------------------*/ 109/*-------------------------------------------------------------------------*/
@@ -123,9 +122,9 @@ static inline struct dummy_request *usb_request_to_dummy_request
123 * configurations, illegal or unsupported packet lengths, and so on. 122 * configurations, illegal or unsupported packet lengths, and so on.
124 */ 123 */
125 124
126static const char ep0name [] = "ep0"; 125static const char ep0name[] = "ep0";
127 126
128static const char *const ep_name [] = { 127static const char *const ep_name[] = {
129 ep0name, /* everyone has ep0 */ 128 ep0name, /* everyone has ep0 */
130 129
131 /* act like a net2280: high speed, six configurable endpoints */ 130 /* act like a net2280: high speed, six configurable endpoints */
@@ -184,12 +183,12 @@ struct dummy {
184 /* 183 /*
185 * SLAVE/GADGET side support 184 * SLAVE/GADGET side support
186 */ 185 */
187 struct dummy_ep ep [DUMMY_ENDPOINTS]; 186 struct dummy_ep ep[DUMMY_ENDPOINTS];
188 int address; 187 int address;
189 struct usb_gadget gadget; 188 struct usb_gadget gadget;
190 struct usb_gadget_driver *driver; 189 struct usb_gadget_driver *driver;
191 struct dummy_request fifo_req; 190 struct dummy_request fifo_req;
192 u8 fifo_buf [FIFO_SIZE]; 191 u8 fifo_buf[FIFO_SIZE];
193 u16 devstatus; 192 u16 devstatus;
194 unsigned udc_suspended:1; 193 unsigned udc_suspended:1;
195 unsigned pullup:1; 194 unsigned pullup:1;
@@ -216,14 +215,14 @@ static inline struct device *dummy_dev(struct dummy_hcd *dum)
216 return dummy_hcd_to_hcd(dum)->self.controller; 215 return dummy_hcd_to_hcd(dum)->self.controller;
217} 216}
218 217
219static inline struct device *udc_dev (struct dummy *dum) 218static inline struct device *udc_dev(struct dummy *dum)
220{ 219{
221 return dum->gadget.dev.parent; 220 return dum->gadget.dev.parent;
222} 221}
223 222
224static inline struct dummy *ep_to_dummy (struct dummy_ep *ep) 223static inline struct dummy *ep_to_dummy(struct dummy_ep *ep)
225{ 224{
226 return container_of (ep->gadget, struct dummy, gadget); 225 return container_of(ep->gadget, struct dummy, gadget);
227} 226}
228 227
229static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget) 228static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
@@ -235,9 +234,9 @@ static inline struct dummy_hcd *gadget_to_dummy_hcd(struct usb_gadget *gadget)
235 return dum->hs_hcd; 234 return dum->hs_hcd;
236} 235}
237 236
238static inline struct dummy *gadget_dev_to_dummy (struct device *dev) 237static inline struct dummy *gadget_dev_to_dummy(struct device *dev)
239{ 238{
240 return container_of (dev, struct dummy, gadget.dev); 239 return container_of(dev, struct dummy, gadget.dev);
241} 240}
242 241
243static struct dummy the_controller; 242static struct dummy the_controller;
@@ -247,24 +246,23 @@ static struct dummy the_controller;
247/* SLAVE/GADGET SIDE UTILITY ROUTINES */ 246/* SLAVE/GADGET SIDE UTILITY ROUTINES */
248 247
249/* called with spinlock held */ 248/* called with spinlock held */
250static void nuke (struct dummy *dum, struct dummy_ep *ep) 249static void nuke(struct dummy *dum, struct dummy_ep *ep)
251{ 250{
252 while (!list_empty (&ep->queue)) { 251 while (!list_empty(&ep->queue)) {
253 struct dummy_request *req; 252 struct dummy_request *req;
254 253
255 req = list_entry (ep->queue.next, struct dummy_request, queue); 254 req = list_entry(ep->queue.next, struct dummy_request, queue);
256 list_del_init (&req->queue); 255 list_del_init(&req->queue);
257 req->req.status = -ESHUTDOWN; 256 req->req.status = -ESHUTDOWN;
258 257
259 spin_unlock (&dum->lock); 258 spin_unlock(&dum->lock);
260 req->req.complete (&ep->ep, &req->req); 259 req->req.complete(&ep->ep, &req->req);
261 spin_lock (&dum->lock); 260 spin_lock(&dum->lock);
262 } 261 }
263} 262}
264 263
265/* caller must hold lock */ 264/* caller must hold lock */
266static void 265static void stop_activity(struct dummy *dum)
267stop_activity (struct dummy *dum)
268{ 266{
269 struct dummy_ep *ep; 267 struct dummy_ep *ep;
270 268
@@ -274,8 +272,8 @@ stop_activity (struct dummy *dum)
274 /* The timer is left running so that outstanding URBs can fail */ 272 /* The timer is left running so that outstanding URBs can fail */
275 273
276 /* nuke any pending requests first, so driver i/o is quiesced */ 274 /* nuke any pending requests first, so driver i/o is quiesced */
277 list_for_each_entry (ep, &dum->gadget.ep_list, ep.ep_list) 275 list_for_each_entry(ep, &dum->gadget.ep_list, ep.ep_list)
278 nuke (dum, ep); 276 nuke(dum, ep);
279 277
280 /* driver now does any non-usb quiescing necessary */ 278 /* driver now does any non-usb quiescing necessary */
281} 279}
@@ -410,8 +408,8 @@ static void set_link_state(struct dummy_hcd *dum_hcd)
410#define is_enabled(dum) \ 408#define is_enabled(dum) \
411 (dum->port_status & USB_PORT_STAT_ENABLE) 409 (dum->port_status & USB_PORT_STAT_ENABLE)
412 410
413static int 411static int dummy_enable(struct usb_ep *_ep,
414dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) 412 const struct usb_endpoint_descriptor *desc)
415{ 413{
416 struct dummy *dum; 414 struct dummy *dum;
417 struct dummy_hcd *dum_hcd; 415 struct dummy_hcd *dum_hcd;
@@ -419,11 +417,11 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
419 unsigned max; 417 unsigned max;
420 int retval; 418 int retval;
421 419
422 ep = usb_ep_to_dummy_ep (_ep); 420 ep = usb_ep_to_dummy_ep(_ep);
423 if (!_ep || !desc || ep->desc || _ep->name == ep0name 421 if (!_ep || !desc || ep->desc || _ep->name == ep0name
424 || desc->bDescriptorType != USB_DT_ENDPOINT) 422 || desc->bDescriptorType != USB_DT_ENDPOINT)
425 return -EINVAL; 423 return -EINVAL;
426 dum = ep_to_dummy (ep); 424 dum = ep_to_dummy(ep);
427 if (!dum->driver) 425 if (!dum->driver)
428 return -ESHUTDOWN; 426 return -ESHUTDOWN;
429 427
@@ -449,8 +447,8 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
449 retval = -EINVAL; 447 retval = -EINVAL;
450 switch (usb_endpoint_type(desc)) { 448 switch (usb_endpoint_type(desc)) {
451 case USB_ENDPOINT_XFER_BULK: 449 case USB_ENDPOINT_XFER_BULK:
452 if (strstr (ep->ep.name, "-iso") 450 if (strstr(ep->ep.name, "-iso")
453 || strstr (ep->ep.name, "-int")) { 451 || strstr(ep->ep.name, "-int")) {
454 goto done; 452 goto done;
455 } 453 }
456 switch (dum->gadget.speed) { 454 switch (dum->gadget.speed) {
@@ -472,7 +470,7 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
472 } 470 }
473 break; 471 break;
474 case USB_ENDPOINT_XFER_INT: 472 case USB_ENDPOINT_XFER_INT:
475 if (strstr (ep->ep.name, "-iso")) /* bulk is ok */ 473 if (strstr(ep->ep.name, "-iso")) /* bulk is ok */
476 goto done; 474 goto done;
477 /* real hardware might not handle all packet sizes */ 475 /* real hardware might not handle all packet sizes */
478 switch (dum->gadget.speed) { 476 switch (dum->gadget.speed) {
@@ -492,8 +490,8 @@ dummy_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
492 } 490 }
493 break; 491 break;
494 case USB_ENDPOINT_XFER_ISOC: 492 case USB_ENDPOINT_XFER_ISOC:
495 if (strstr (ep->ep.name, "-bulk") 493 if (strstr(ep->ep.name, "-bulk")
496 || strstr (ep->ep.name, "-int")) 494 || strstr(ep->ep.name, "-int"))
497 goto done; 495 goto done;
498 /* real hardware might not handle all packet sizes */ 496 /* real hardware might not handle all packet sizes */
499 switch (dum->gadget.speed) { 497 switch (dum->gadget.speed) {
@@ -556,68 +554,65 @@ done:
556 return retval; 554 return retval;
557} 555}
558 556
559static int dummy_disable (struct usb_ep *_ep) 557static int dummy_disable(struct usb_ep *_ep)
560{ 558{
561 struct dummy_ep *ep; 559 struct dummy_ep *ep;
562 struct dummy *dum; 560 struct dummy *dum;
563 unsigned long flags; 561 unsigned long flags;
564 int retval; 562 int retval;
565 563
566 ep = usb_ep_to_dummy_ep (_ep); 564 ep = usb_ep_to_dummy_ep(_ep);
567 if (!_ep || !ep->desc || _ep->name == ep0name) 565 if (!_ep || !ep->desc || _ep->name == ep0name)
568 return -EINVAL; 566 return -EINVAL;
569 dum = ep_to_dummy (ep); 567 dum = ep_to_dummy(ep);
570 568
571 spin_lock_irqsave (&dum->lock, flags); 569 spin_lock_irqsave(&dum->lock, flags);
572 ep->desc = NULL; 570 ep->desc = NULL;
573 ep->stream_en = 0; 571 ep->stream_en = 0;
574 retval = 0; 572 retval = 0;
575 nuke (dum, ep); 573 nuke(dum, ep);
576 spin_unlock_irqrestore (&dum->lock, flags); 574 spin_unlock_irqrestore(&dum->lock, flags);
577 575
578 dev_dbg (udc_dev(dum), "disabled %s\n", _ep->name); 576 dev_dbg(udc_dev(dum), "disabled %s\n", _ep->name);
579 return retval; 577 return retval;
580} 578}
581 579
582static struct usb_request * 580static struct usb_request *dummy_alloc_request(struct usb_ep *_ep,
583dummy_alloc_request (struct usb_ep *_ep, gfp_t mem_flags) 581 gfp_t mem_flags)
584{ 582{
585 struct dummy_ep *ep; 583 struct dummy_ep *ep;
586 struct dummy_request *req; 584 struct dummy_request *req;
587 585
588 if (!_ep) 586 if (!_ep)
589 return NULL; 587 return NULL;
590 ep = usb_ep_to_dummy_ep (_ep); 588 ep = usb_ep_to_dummy_ep(_ep);
591 589
592 req = kzalloc(sizeof(*req), mem_flags); 590 req = kzalloc(sizeof(*req), mem_flags);
593 if (!req) 591 if (!req)
594 return NULL; 592 return NULL;
595 INIT_LIST_HEAD (&req->queue); 593 INIT_LIST_HEAD(&req->queue);
596 return &req->req; 594 return &req->req;
597} 595}
598 596
599static void 597static void dummy_free_request(struct usb_ep *_ep, struct usb_request *_req)
600dummy_free_request (struct usb_ep *_ep, struct usb_request *_req)
601{ 598{
602 struct dummy_ep *ep; 599 struct dummy_ep *ep;
603 struct dummy_request *req; 600 struct dummy_request *req;
604 601
605 ep = usb_ep_to_dummy_ep (_ep); 602 ep = usb_ep_to_dummy_ep(_ep);
606 if (!ep || !_req || (!ep->desc && _ep->name != ep0name)) 603 if (!ep || !_req || (!ep->desc && _ep->name != ep0name))
607 return; 604 return;
608 605
609 req = usb_request_to_dummy_request (_req); 606 req = usb_request_to_dummy_request(_req);
610 WARN_ON (!list_empty (&req->queue)); 607 WARN_ON(!list_empty(&req->queue));
611 kfree (req); 608 kfree(req);
612} 609}
613 610
614static void 611static void fifo_complete(struct usb_ep *ep, struct usb_request *req)
615fifo_complete (struct usb_ep *ep, struct usb_request *req)
616{ 612{
617} 613}
618 614
619static int 615static int dummy_queue(struct usb_ep *_ep, struct usb_request *_req,
620dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
621 gfp_t mem_flags) 616 gfp_t mem_flags)
622{ 617{
623 struct dummy_ep *ep; 618 struct dummy_ep *ep;
@@ -626,49 +621,48 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
626 struct dummy_hcd *dum_hcd; 621 struct dummy_hcd *dum_hcd;
627 unsigned long flags; 622 unsigned long flags;
628 623
629 req = usb_request_to_dummy_request (_req); 624 req = usb_request_to_dummy_request(_req);
630 if (!_req || !list_empty (&req->queue) || !_req->complete) 625 if (!_req || !list_empty(&req->queue) || !_req->complete)
631 return -EINVAL; 626 return -EINVAL;
632 627
633 ep = usb_ep_to_dummy_ep (_ep); 628 ep = usb_ep_to_dummy_ep(_ep);
634 if (!_ep || (!ep->desc && _ep->name != ep0name)) 629 if (!_ep || (!ep->desc && _ep->name != ep0name))
635 return -EINVAL; 630 return -EINVAL;
636 631
637 dum = ep_to_dummy (ep); 632 dum = ep_to_dummy(ep);
638 dum_hcd = gadget_to_dummy_hcd(&dum->gadget); 633 dum_hcd = gadget_to_dummy_hcd(&dum->gadget);
639 if (!dum->driver || !is_enabled(dum_hcd)) 634 if (!dum->driver || !is_enabled(dum_hcd))
640 return -ESHUTDOWN; 635 return -ESHUTDOWN;
641 636
642#if 0 637#if 0
643 dev_dbg (udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n", 638 dev_dbg(udc_dev(dum), "ep %p queue req %p to %s, len %d buf %p\n",
644 ep, _req, _ep->name, _req->length, _req->buf); 639 ep, _req, _ep->name, _req->length, _req->buf);
645#endif 640#endif
646
647 _req->status = -EINPROGRESS; 641 _req->status = -EINPROGRESS;
648 _req->actual = 0; 642 _req->actual = 0;
649 spin_lock_irqsave (&dum->lock, flags); 643 spin_lock_irqsave(&dum->lock, flags);
650 644
651 /* implement an emulated single-request FIFO */ 645 /* implement an emulated single-request FIFO */
652 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && 646 if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
653 list_empty (&dum->fifo_req.queue) && 647 list_empty(&dum->fifo_req.queue) &&
654 list_empty (&ep->queue) && 648 list_empty(&ep->queue) &&
655 _req->length <= FIFO_SIZE) { 649 _req->length <= FIFO_SIZE) {
656 req = &dum->fifo_req; 650 req = &dum->fifo_req;
657 req->req = *_req; 651 req->req = *_req;
658 req->req.buf = dum->fifo_buf; 652 req->req.buf = dum->fifo_buf;
659 memcpy (dum->fifo_buf, _req->buf, _req->length); 653 memcpy(dum->fifo_buf, _req->buf, _req->length);
660 req->req.context = dum; 654 req->req.context = dum;
661 req->req.complete = fifo_complete; 655 req->req.complete = fifo_complete;
662 656
663 list_add_tail(&req->queue, &ep->queue); 657 list_add_tail(&req->queue, &ep->queue);
664 spin_unlock (&dum->lock); 658 spin_unlock(&dum->lock);
665 _req->actual = _req->length; 659 _req->actual = _req->length;
666 _req->status = 0; 660 _req->status = 0;
667 _req->complete (_ep, _req); 661 _req->complete(_ep, _req);
668 spin_lock (&dum->lock); 662 spin_lock(&dum->lock);
669 } else 663 } else
670 list_add_tail(&req->queue, &ep->queue); 664 list_add_tail(&req->queue, &ep->queue);
671 spin_unlock_irqrestore (&dum->lock, flags); 665 spin_unlock_irqrestore(&dum->lock, flags);
672 666
673 /* real hardware would likely enable transfers here, in case 667 /* real hardware would likely enable transfers here, in case
674 * it'd been left NAKing. 668 * it'd been left NAKing.
@@ -676,7 +670,7 @@ dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
676 return 0; 670 return 0;
677} 671}
678 672
679static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req) 673static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req)
680{ 674{
681 struct dummy_ep *ep; 675 struct dummy_ep *ep;
682 struct dummy *dum; 676 struct dummy *dum;
@@ -686,31 +680,31 @@ static int dummy_dequeue (struct usb_ep *_ep, struct usb_request *_req)
686 680
687 if (!_ep || !_req) 681 if (!_ep || !_req)
688 return retval; 682 return retval;
689 ep = usb_ep_to_dummy_ep (_ep); 683 ep = usb_ep_to_dummy_ep(_ep);
690 dum = ep_to_dummy (ep); 684 dum = ep_to_dummy(ep);
691 685
692 if (!dum->driver) 686 if (!dum->driver)
693 return -ESHUTDOWN; 687 return -ESHUTDOWN;
694 688
695 local_irq_save (flags); 689 local_irq_save(flags);
696 spin_lock (&dum->lock); 690 spin_lock(&dum->lock);
697 list_for_each_entry (req, &ep->queue, queue) { 691 list_for_each_entry(req, &ep->queue, queue) {
698 if (&req->req == _req) { 692 if (&req->req == _req) {
699 list_del_init (&req->queue); 693 list_del_init(&req->queue);
700 _req->status = -ECONNRESET; 694 _req->status = -ECONNRESET;
701 retval = 0; 695 retval = 0;
702 break; 696 break;
703 } 697 }
704 } 698 }
705 spin_unlock (&dum->lock); 699 spin_unlock(&dum->lock);
706 700
707 if (retval == 0) { 701 if (retval == 0) {
708 dev_dbg (udc_dev(dum), 702 dev_dbg(udc_dev(dum),
709 "dequeued req %p from %s, len %d buf %p\n", 703 "dequeued req %p from %s, len %d buf %p\n",
710 req, _ep->name, _req->length, _req->buf); 704 req, _ep->name, _req->length, _req->buf);
711 _req->complete (_ep, _req); 705 _req->complete(_ep, _req);
712 } 706 }
713 local_irq_restore (flags); 707 local_irq_restore(flags);
714 return retval; 708 return retval;
715} 709}
716 710
@@ -722,14 +716,14 @@ dummy_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
722 716
723 if (!_ep) 717 if (!_ep)
724 return -EINVAL; 718 return -EINVAL;
725 ep = usb_ep_to_dummy_ep (_ep); 719 ep = usb_ep_to_dummy_ep(_ep);
726 dum = ep_to_dummy (ep); 720 dum = ep_to_dummy(ep);
727 if (!dum->driver) 721 if (!dum->driver)
728 return -ESHUTDOWN; 722 return -ESHUTDOWN;
729 if (!value) 723 if (!value)
730 ep->halted = ep->wedged = 0; 724 ep->halted = ep->wedged = 0;
731 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) && 725 else if (ep->desc && (ep->desc->bEndpointAddress & USB_DIR_IN) &&
732 !list_empty (&ep->queue)) 726 !list_empty(&ep->queue))
733 return -EAGAIN; 727 return -EAGAIN;
734 else { 728 else {
735 ep->halted = 1; 729 ep->halted = 1;
@@ -770,15 +764,15 @@ static const struct usb_ep_ops dummy_ep_ops = {
770/*-------------------------------------------------------------------------*/ 764/*-------------------------------------------------------------------------*/
771 765
772/* there are both host and device side versions of this call ... */ 766/* there are both host and device side versions of this call ... */
773static int dummy_g_get_frame (struct usb_gadget *_gadget) 767static int dummy_g_get_frame(struct usb_gadget *_gadget)
774{ 768{
775 struct timeval tv; 769 struct timeval tv;
776 770
777 do_gettimeofday (&tv); 771 do_gettimeofday(&tv);
778 return tv.tv_usec / 1000; 772 return tv.tv_usec / 1000;
779} 773}
780 774
781static int dummy_wakeup (struct usb_gadget *_gadget) 775static int dummy_wakeup(struct usb_gadget *_gadget)
782{ 776{
783 struct dummy_hcd *dum_hcd; 777 struct dummy_hcd *dum_hcd;
784 778
@@ -801,11 +795,11 @@ static int dummy_wakeup (struct usb_gadget *_gadget)
801 return 0; 795 return 0;
802} 796}
803 797
804static int dummy_set_selfpowered (struct usb_gadget *_gadget, int value) 798static int dummy_set_selfpowered(struct usb_gadget *_gadget, int value)
805{ 799{
806 struct dummy *dum; 800 struct dummy *dum;
807 801
808 dum = (gadget_to_dummy_hcd(_gadget))->dum; 802 dum = gadget_to_dummy_hcd(_gadget)->dum;
809 if (value) 803 if (value)
810 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED); 804 dum->devstatus |= (1 << USB_DEVICE_SELF_POWERED);
811 else 805 else
@@ -821,7 +815,7 @@ static void dummy_udc_update_ep0(struct dummy *dum)
821 dum->ep[0].ep.maxpacket = 64; 815 dum->ep[0].ep.maxpacket = 64;
822} 816}
823 817
824static int dummy_pullup (struct usb_gadget *_gadget, int value) 818static int dummy_pullup(struct usb_gadget *_gadget, int value)
825{ 819{
826 struct dummy_hcd *dum_hcd; 820 struct dummy_hcd *dum_hcd;
827 struct dummy *dum; 821 struct dummy *dum;
@@ -846,10 +840,10 @@ static int dummy_pullup (struct usb_gadget *_gadget, int value)
846 } 840 }
847 dum_hcd = gadget_to_dummy_hcd(_gadget); 841 dum_hcd = gadget_to_dummy_hcd(_gadget);
848 842
849 spin_lock_irqsave (&dum->lock, flags); 843 spin_lock_irqsave(&dum->lock, flags);
850 dum->pullup = (value != 0); 844 dum->pullup = (value != 0);
851 set_link_state(dum_hcd); 845 set_link_state(dum_hcd);
852 spin_unlock_irqrestore (&dum->lock, flags); 846 spin_unlock_irqrestore(&dum->lock, flags);
853 847
854 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd)); 848 usb_hcd_poll_rh_status(dummy_hcd_to_hcd(dum_hcd));
855 return 0; 849 return 0;
@@ -872,16 +866,16 @@ static const struct usb_gadget_ops dummy_ops = {
872/*-------------------------------------------------------------------------*/ 866/*-------------------------------------------------------------------------*/
873 867
874/* "function" sysfs attribute */ 868/* "function" sysfs attribute */
875static ssize_t 869static ssize_t show_function(struct device *dev, struct device_attribute *attr,
876show_function (struct device *dev, struct device_attribute *attr, char *buf) 870 char *buf)
877{ 871{
878 struct dummy *dum = gadget_dev_to_dummy (dev); 872 struct dummy *dum = gadget_dev_to_dummy(dev);
879 873
880 if (!dum->driver || !dum->driver->function) 874 if (!dum->driver || !dum->driver->function)
881 return 0; 875 return 0;
882 return scnprintf (buf, PAGE_SIZE, "%s\n", dum->driver->function); 876 return scnprintf(buf, PAGE_SIZE, "%s\n", dum->driver->function);
883} 877}
884static DEVICE_ATTR (function, S_IRUGO, show_function, NULL); 878static DEVICE_ATTR(function, S_IRUGO, show_function, NULL);
885 879
886/*-------------------------------------------------------------------------*/ 880/*-------------------------------------------------------------------------*/
887 881
@@ -916,7 +910,7 @@ static int dummy_udc_start(struct usb_gadget *g,
916 dum->devstatus = 0; 910 dum->devstatus = 0;
917 911
918 dum->driver = driver; 912 dum->driver = driver;
919 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 913 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n",
920 driver->driver.name); 914 driver->driver.name);
921 return 0; 915 return 0;
922} 916}
@@ -927,7 +921,7 @@ static int dummy_udc_stop(struct usb_gadget *g,
927 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g); 921 struct dummy_hcd *dum_hcd = gadget_to_dummy_hcd(g);
928 struct dummy *dum = dum_hcd->dum; 922 struct dummy *dum = dum_hcd->dum;
929 923
930 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 924 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
931 driver->driver.name); 925 driver->driver.name);
932 926
933 dum->driver = NULL; 927 dum->driver = NULL;
@@ -940,8 +934,7 @@ static int dummy_udc_stop(struct usb_gadget *g,
940 934
941/* The gadget structure is stored inside the hcd structure and will be 935/* The gadget structure is stored inside the hcd structure and will be
942 * released along with it. */ 936 * released along with it. */
943static void 937static void dummy_gadget_release(struct device *dev)
944dummy_gadget_release (struct device *dev)
945{ 938{
946 return; 939 return;
947} 940}
@@ -978,7 +971,7 @@ static void init_dummy_udc_hw(struct dummy *dum)
978#endif 971#endif
979} 972}
980 973
981static int dummy_udc_probe (struct platform_device *pdev) 974static int dummy_udc_probe(struct platform_device *pdev)
982{ 975{
983 struct dummy *dum = &the_controller; 976 struct dummy *dum = &the_controller;
984 int rc; 977 int rc;
@@ -990,7 +983,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
990 dev_set_name(&dum->gadget.dev, "gadget"); 983 dev_set_name(&dum->gadget.dev, "gadget");
991 dum->gadget.dev.parent = &pdev->dev; 984 dum->gadget.dev.parent = &pdev->dev;
992 dum->gadget.dev.release = dummy_gadget_release; 985 dum->gadget.dev.release = dummy_gadget_release;
993 rc = device_register (&dum->gadget.dev); 986 rc = device_register(&dum->gadget.dev);
994 if (rc < 0) { 987 if (rc < 0) {
995 put_device(&dum->gadget.dev); 988 put_device(&dum->gadget.dev);
996 return rc; 989 return rc;
@@ -1002,7 +995,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
1002 if (rc < 0) 995 if (rc < 0)
1003 goto err_udc; 996 goto err_udc;
1004 997
1005 rc = device_create_file (&dum->gadget.dev, &dev_attr_function); 998 rc = device_create_file(&dum->gadget.dev, &dev_attr_function);
1006 if (rc < 0) 999 if (rc < 0)
1007 goto err_dev; 1000 goto err_dev;
1008 platform_set_drvdata(pdev, dum); 1001 platform_set_drvdata(pdev, dum);
@@ -1015,14 +1008,14 @@ err_udc:
1015 return rc; 1008 return rc;
1016} 1009}
1017 1010
1018static int dummy_udc_remove (struct platform_device *pdev) 1011static int dummy_udc_remove(struct platform_device *pdev)
1019{ 1012{
1020 struct dummy *dum = platform_get_drvdata (pdev); 1013 struct dummy *dum = platform_get_drvdata(pdev);
1021 1014
1022 usb_del_gadget_udc(&dum->gadget); 1015 usb_del_gadget_udc(&dum->gadget);
1023 platform_set_drvdata (pdev, NULL); 1016 platform_set_drvdata(pdev, NULL);
1024 device_remove_file (&dum->gadget.dev, &dev_attr_function); 1017 device_remove_file(&dum->gadget.dev, &dev_attr_function);
1025 device_unregister (&dum->gadget.dev); 1018 device_unregister(&dum->gadget.dev);
1026 return 0; 1019 return 0;
1027} 1020}
1028 1021
@@ -1167,7 +1160,7 @@ static int dummy_validate_stream(struct dummy_hcd *dum_hcd, struct urb *urb)
1167 return 0; 1160 return 0;
1168} 1161}
1169 1162
1170static int dummy_urb_enqueue ( 1163static int dummy_urb_enqueue(
1171 struct usb_hcd *hcd, 1164 struct usb_hcd *hcd,
1172 struct urb *urb, 1165 struct urb *urb,
1173 gfp_t mem_flags 1166 gfp_t mem_flags
@@ -1177,7 +1170,7 @@ static int dummy_urb_enqueue (
1177 unsigned long flags; 1170 unsigned long flags;
1178 int rc; 1171 int rc;
1179 1172
1180 urbp = kmalloc (sizeof *urbp, mem_flags); 1173 urbp = kmalloc(sizeof *urbp, mem_flags);
1181 if (!urbp) 1174 if (!urbp)
1182 return -ENOMEM; 1175 return -ENOMEM;
1183 urbp->urb = urb; 1176 urbp->urb = urb;
@@ -1206,7 +1199,7 @@ static int dummy_urb_enqueue (
1206 1199
1207 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list); 1200 list_add_tail(&urbp->urbp_list, &dum_hcd->urbp_list);
1208 urb->hcpriv = urbp; 1201 urb->hcpriv = urbp;
1209 if (usb_pipetype (urb->pipe) == PIPE_CONTROL) 1202 if (usb_pipetype(urb->pipe) == PIPE_CONTROL)
1210 urb->error_count = 1; /* mark as a new urb */ 1203 urb->error_count = 1; /* mark as a new urb */
1211 1204
1212 /* kick the scheduler, it'll do the rest */ 1205 /* kick the scheduler, it'll do the rest */
@@ -1313,7 +1306,7 @@ static int transfer(struct dummy_hcd *dum_hcd, struct urb *urb,
1313 1306
1314top: 1307top:
1315 /* if there's no request queued, the device is NAKing; return */ 1308 /* if there's no request queued, the device is NAKing; return */
1316 list_for_each_entry (req, &ep->queue, queue) { 1309 list_for_each_entry(req, &ep->queue, queue) {
1317 unsigned host_len, dev_len, len; 1310 unsigned host_len, dev_len, len;
1318 int is_short, to_host; 1311 int is_short, to_host;
1319 int rescan = 0; 1312 int rescan = 0;
@@ -1332,18 +1325,18 @@ top:
1332 */ 1325 */
1333 host_len = urb->transfer_buffer_length - urb->actual_length; 1326 host_len = urb->transfer_buffer_length - urb->actual_length;
1334 dev_len = req->req.length - req->req.actual; 1327 dev_len = req->req.length - req->req.actual;
1335 len = min (host_len, dev_len); 1328 len = min(host_len, dev_len);
1336 1329
1337 /* FIXME update emulated data toggle too */ 1330 /* FIXME update emulated data toggle too */
1338 1331
1339 to_host = usb_pipein (urb->pipe); 1332 to_host = usb_pipein(urb->pipe);
1340 if (unlikely (len == 0)) 1333 if (unlikely(len == 0))
1341 is_short = 1; 1334 is_short = 1;
1342 else { 1335 else {
1343 /* not enough bandwidth left? */ 1336 /* not enough bandwidth left? */
1344 if (limit < ep->ep.maxpacket && limit < len) 1337 if (limit < ep->ep.maxpacket && limit < len)
1345 break; 1338 break;
1346 len = min (len, (unsigned) limit); 1339 len = min_t(unsigned, len, limit);
1347 if (len == 0) 1340 if (len == 0)
1348 break; 1341 break;
1349 1342
@@ -1404,11 +1397,11 @@ top:
1404 1397
1405 /* device side completion --> continuable */ 1398 /* device side completion --> continuable */
1406 if (req->req.status != -EINPROGRESS) { 1399 if (req->req.status != -EINPROGRESS) {
1407 list_del_init (&req->queue); 1400 list_del_init(&req->queue);
1408 1401
1409 spin_unlock (&dum->lock); 1402 spin_unlock(&dum->lock);
1410 req->req.complete (&ep->ep, &req->req); 1403 req->req.complete(&ep->ep, &req->req);
1411 spin_lock (&dum->lock); 1404 spin_lock(&dum->lock);
1412 1405
1413 /* requests might have been unlinked... */ 1406 /* requests might have been unlinked... */
1414 rescan = 1; 1407 rescan = 1;
@@ -1425,7 +1418,7 @@ top:
1425 return limit; 1418 return limit;
1426} 1419}
1427 1420
1428static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep) 1421static int periodic_bytes(struct dummy *dum, struct dummy_ep *ep)
1429{ 1422{
1430 int limit = ep->ep.maxpacket; 1423 int limit = ep->ep.maxpacket;
1431 1424
@@ -1461,7 +1454,7 @@ static int periodic_bytes (struct dummy *dum, struct dummy_ep *ep)
1461 USB_PORT_STAT_SUSPEND)) \ 1454 USB_PORT_STAT_SUSPEND)) \
1462 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) 1455 == (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE))
1463 1456
1464static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address) 1457static struct dummy_ep *find_endpoint(struct dummy *dum, u8 address)
1465{ 1458{
1466 int i; 1459 int i;
1467 1460
@@ -1469,9 +1462,9 @@ static struct dummy_ep *find_endpoint (struct dummy *dum, u8 address)
1469 dum->ss_hcd : dum->hs_hcd))) 1462 dum->ss_hcd : dum->hs_hcd)))
1470 return NULL; 1463 return NULL;
1471 if ((address & ~USB_DIR_IN) == 0) 1464 if ((address & ~USB_DIR_IN) == 0)
1472 return &dum->ep [0]; 1465 return &dum->ep[0];
1473 for (i = 1; i < DUMMY_ENDPOINTS; i++) { 1466 for (i = 1; i < DUMMY_ENDPOINTS; i++) {
1474 struct dummy_ep *ep = &dum->ep [i]; 1467 struct dummy_ep *ep = &dum->ep[i];
1475 1468
1476 if (!ep->desc) 1469 if (!ep->desc)
1477 continue; 1470 continue;
@@ -1701,19 +1694,19 @@ static void dummy_timer(unsigned long _dum_hcd)
1701 /* FIXME if HZ != 1000 this will probably misbehave ... */ 1694 /* FIXME if HZ != 1000 this will probably misbehave ... */
1702 1695
1703 /* look at each urb queued by the host side driver */ 1696 /* look at each urb queued by the host side driver */
1704 spin_lock_irqsave (&dum->lock, flags); 1697 spin_lock_irqsave(&dum->lock, flags);
1705 1698
1706 if (!dum_hcd->udev) { 1699 if (!dum_hcd->udev) {
1707 dev_err(dummy_dev(dum_hcd), 1700 dev_err(dummy_dev(dum_hcd),
1708 "timer fired with no URBs pending?\n"); 1701 "timer fired with no URBs pending?\n");
1709 spin_unlock_irqrestore (&dum->lock, flags); 1702 spin_unlock_irqrestore(&dum->lock, flags);
1710 return; 1703 return;
1711 } 1704 }
1712 1705
1713 for (i = 0; i < DUMMY_ENDPOINTS; i++) { 1706 for (i = 0; i < DUMMY_ENDPOINTS; i++) {
1714 if (!ep_name [i]) 1707 if (!ep_name[i])
1715 break; 1708 break;
1716 dum->ep [i].already_seen = 0; 1709 dum->ep[i].already_seen = 0;
1717 } 1710 }
1718 1711
1719restart: 1712restart:
@@ -1730,7 +1723,7 @@ restart:
1730 goto return_urb; 1723 goto return_urb;
1731 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING) 1724 else if (dum_hcd->rh_state != DUMMY_RH_RUNNING)
1732 continue; 1725 continue;
1733 type = usb_pipetype (urb->pipe); 1726 type = usb_pipetype(urb->pipe);
1734 1727
1735 /* used up this frame's non-periodic bandwidth? 1728 /* used up this frame's non-periodic bandwidth?
1736 * FIXME there's infinite bandwidth for control and 1729 * FIXME there's infinite bandwidth for control and
@@ -1741,7 +1734,7 @@ restart:
1741 1734
1742 /* find the gadget's ep for this request (if configured) */ 1735 /* find the gadget's ep for this request (if configured) */
1743 address = usb_pipeendpoint (urb->pipe); 1736 address = usb_pipeendpoint (urb->pipe);
1744 if (usb_pipein (urb->pipe)) 1737 if (usb_pipein(urb->pipe))
1745 address |= USB_DIR_IN; 1738 address |= USB_DIR_IN;
1746 ep = find_endpoint(dum, address); 1739 ep = find_endpoint(dum, address);
1747 if (!ep) { 1740 if (!ep) {
@@ -1756,7 +1749,7 @@ restart:
1756 if (ep->already_seen) 1749 if (ep->already_seen)
1757 continue; 1750 continue;
1758 ep->already_seen = 1; 1751 ep->already_seen = 1;
1759 if (ep == &dum->ep [0] && urb->error_count) { 1752 if (ep == &dum->ep[0] && urb->error_count) {
1760 ep->setup_stage = 1; /* a new urb */ 1753 ep->setup_stage = 1; /* a new urb */
1761 urb->error_count = 0; 1754 urb->error_count = 0;
1762 } 1755 }
@@ -1770,21 +1763,21 @@ restart:
1770 /* FIXME make sure both ends agree on maxpacket */ 1763 /* FIXME make sure both ends agree on maxpacket */
1771 1764
1772 /* handle control requests */ 1765 /* handle control requests */
1773 if (ep == &dum->ep [0] && ep->setup_stage) { 1766 if (ep == &dum->ep[0] && ep->setup_stage) {
1774 struct usb_ctrlrequest setup; 1767 struct usb_ctrlrequest setup;
1775 int value = 1; 1768 int value = 1;
1776 1769
1777 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1770 setup = *(struct usb_ctrlrequest *) urb->setup_packet;
1778 /* paranoia, in case of stale queued data */ 1771 /* paranoia, in case of stale queued data */
1779 list_for_each_entry (req, &ep->queue, queue) { 1772 list_for_each_entry(req, &ep->queue, queue) {
1780 list_del_init (&req->queue); 1773 list_del_init(&req->queue);
1781 req->req.status = -EOVERFLOW; 1774 req->req.status = -EOVERFLOW;
1782 dev_dbg (udc_dev(dum), "stale req = %p\n", 1775 dev_dbg(udc_dev(dum), "stale req = %p\n",
1783 req); 1776 req);
1784 1777
1785 spin_unlock (&dum->lock); 1778 spin_unlock(&dum->lock);
1786 req->req.complete (&ep->ep, &req->req); 1779 req->req.complete(&ep->ep, &req->req);
1787 spin_lock (&dum->lock); 1780 spin_lock(&dum->lock);
1788 ep->already_seen = 0; 1781 ep->already_seen = 0;
1789 goto restart; 1782 goto restart;
1790 } 1783 }
@@ -1804,10 +1797,10 @@ restart:
1804 * until setup() returns; no reentrancy issues etc. 1797 * until setup() returns; no reentrancy issues etc.
1805 */ 1798 */
1806 if (value > 0) { 1799 if (value > 0) {
1807 spin_unlock (&dum->lock); 1800 spin_unlock(&dum->lock);
1808 value = dum->driver->setup (&dum->gadget, 1801 value = dum->driver->setup(&dum->gadget,
1809 &setup); 1802 &setup);
1810 spin_lock (&dum->lock); 1803 spin_lock(&dum->lock);
1811 1804
1812 if (value >= 0) { 1805 if (value >= 0) {
1813 /* no delays (max 64KB data stage) */ 1806 /* no delays (max 64KB data stage) */
@@ -1819,7 +1812,7 @@ restart:
1819 1812
1820 if (value < 0) { 1813 if (value < 0) {
1821 if (value != -EOPNOTSUPP) 1814 if (value != -EOPNOTSUPP)
1822 dev_dbg (udc_dev(dum), 1815 dev_dbg(udc_dev(dum),
1823 "setup --> %d\n", 1816 "setup --> %d\n",
1824 value); 1817 value);
1825 status = -EPIPE; 1818 status = -EPIPE;
@@ -1831,14 +1824,14 @@ restart:
1831 1824
1832 /* non-control requests */ 1825 /* non-control requests */
1833 limit = total; 1826 limit = total;
1834 switch (usb_pipetype (urb->pipe)) { 1827 switch (usb_pipetype(urb->pipe)) {
1835 case PIPE_ISOCHRONOUS: 1828 case PIPE_ISOCHRONOUS:
1836 /* FIXME is it urb->interval since the last xfer? 1829 /* FIXME is it urb->interval since the last xfer?
1837 * use urb->iso_frame_desc[i]. 1830 * use urb->iso_frame_desc[i].
1838 * complete whether or not ep has requests queued. 1831 * complete whether or not ep has requests queued.
1839 * report random errors, to debug drivers. 1832 * report random errors, to debug drivers.
1840 */ 1833 */
1841 limit = max (limit, periodic_bytes (dum, ep)); 1834 limit = max(limit, periodic_bytes(dum, ep));
1842 status = -ENOSYS; 1835 status = -ENOSYS;
1843 break; 1836 break;
1844 1837
@@ -1846,12 +1839,11 @@ restart:
1846 /* FIXME is it urb->interval since the last xfer? 1839 /* FIXME is it urb->interval since the last xfer?
1847 * this almost certainly polls too fast. 1840 * this almost certainly polls too fast.
1848 */ 1841 */
1849 limit = max (limit, periodic_bytes (dum, ep)); 1842 limit = max(limit, periodic_bytes(dum, ep));
1850 /* FALLTHROUGH */ 1843 /* FALLTHROUGH */
1851 1844
1852 // case PIPE_BULK: case PIPE_CONTROL:
1853 default: 1845 default:
1854 treat_control_like_bulk: 1846treat_control_like_bulk:
1855 ep->last_io = jiffies; 1847 ep->last_io = jiffies;
1856 total = transfer(dum_hcd, urb, ep, limit, &status); 1848 total = transfer(dum_hcd, urb, ep, limit, &status);
1857 break; 1849 break;
@@ -1862,15 +1854,15 @@ restart:
1862 continue; 1854 continue;
1863 1855
1864return_urb: 1856return_urb:
1865 list_del (&urbp->urbp_list); 1857 list_del(&urbp->urbp_list);
1866 kfree (urbp); 1858 kfree(urbp);
1867 if (ep) 1859 if (ep)
1868 ep->already_seen = ep->setup_stage = 0; 1860 ep->already_seen = ep->setup_stage = 0;
1869 1861
1870 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb); 1862 usb_hcd_unlink_urb_from_ep(dummy_hcd_to_hcd(dum_hcd), urb);
1871 spin_unlock (&dum->lock); 1863 spin_unlock(&dum->lock);
1872 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status); 1864 usb_hcd_giveback_urb(dummy_hcd_to_hcd(dum_hcd), urb, status);
1873 spin_lock (&dum->lock); 1865 spin_lock(&dum->lock);
1874 1866
1875 goto restart; 1867 goto restart;
1876 } 1868 }
@@ -1883,7 +1875,7 @@ return_urb:
1883 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1)); 1875 mod_timer(&dum_hcd->timer, jiffies + msecs_to_jiffies(1));
1884 } 1876 }
1885 1877
1886 spin_unlock_irqrestore (&dum->lock, flags); 1878 spin_unlock_irqrestore(&dum->lock, flags);
1887} 1879}
1888 1880
1889/*-------------------------------------------------------------------------*/ 1881/*-------------------------------------------------------------------------*/
@@ -1895,7 +1887,7 @@ return_urb:
1895 | USB_PORT_STAT_C_OVERCURRENT \ 1887 | USB_PORT_STAT_C_OVERCURRENT \
1896 | USB_PORT_STAT_C_RESET) << 16) 1888 | USB_PORT_STAT_C_RESET) << 16)
1897 1889
1898static int dummy_hub_status (struct usb_hcd *hcd, char *buf) 1890static int dummy_hub_status(struct usb_hcd *hcd, char *buf)
1899{ 1891{
1900 struct dummy_hcd *dum_hcd; 1892 struct dummy_hcd *dum_hcd;
1901 unsigned long flags; 1893 unsigned long flags;
@@ -1919,7 +1911,7 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1919 dum_hcd->port_status); 1911 dum_hcd->port_status);
1920 retval = 1; 1912 retval = 1;
1921 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED) 1913 if (dum_hcd->rh_state == DUMMY_RH_SUSPENDED)
1922 usb_hcd_resume_root_hub (hcd); 1914 usb_hcd_resume_root_hub(hcd);
1923 } 1915 }
1924done: 1916done:
1925 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); 1917 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
@@ -1938,10 +1930,9 @@ ss_hub_descriptor(struct usb_hub_descriptor *desc)
1938 desc->u.ss.DeviceRemovable = 0xffff; 1930 desc->u.ss.DeviceRemovable = 0xffff;
1939} 1931}
1940 1932
1941static inline void 1933static inline void hub_descriptor(struct usb_hub_descriptor *desc)
1942hub_descriptor (struct usb_hub_descriptor *desc)
1943{ 1934{
1944 memset (desc, 0, sizeof *desc); 1935 memset(desc, 0, sizeof *desc);
1945 desc->bDescriptorType = 0x29; 1936 desc->bDescriptorType = 0x29;
1946 desc->bDescLength = 9; 1937 desc->bDescLength = 9;
1947 desc->wHubCharacteristics = cpu_to_le16(0x0001); 1938 desc->wHubCharacteristics = cpu_to_le16(0x0001);
@@ -1950,7 +1941,7 @@ hub_descriptor (struct usb_hub_descriptor *desc)
1950 desc->u.hs.DeviceRemovable[1] = 0xff; 1941 desc->u.hs.DeviceRemovable[1] = 0xff;
1951} 1942}
1952 1943
1953static int dummy_hub_control ( 1944static int dummy_hub_control(
1954 struct usb_hcd *hcd, 1945 struct usb_hcd *hcd,
1955 u16 typeReq, 1946 u16 typeReq,
1956 u16 wValue, 1947 u16 wValue,
@@ -2018,7 +2009,7 @@ static int dummy_hub_control (
2018 hub_descriptor((struct usb_hub_descriptor *) buf); 2009 hub_descriptor((struct usb_hub_descriptor *) buf);
2019 break; 2010 break;
2020 case GetHubStatus: 2011 case GetHubStatus:
2021 *(__le32 *) buf = cpu_to_le32 (0); 2012 *(__le32 *) buf = cpu_to_le32(0);
2022 break; 2013 break;
2023 case GetPortStatus: 2014 case GetPortStatus:
2024 if (wIndex != 1) 2015 if (wIndex != 1)
@@ -2060,8 +2051,8 @@ static int dummy_hub_control (
2060 } 2051 }
2061 } 2052 }
2062 set_link_state(dum_hcd); 2053 set_link_state(dum_hcd);
2063 ((__le16 *) buf)[0] = cpu_to_le16 (dum_hcd->port_status); 2054 ((__le16 *) buf)[0] = cpu_to_le16(dum_hcd->port_status);
2064 ((__le16 *) buf)[1] = cpu_to_le16 (dum_hcd->port_status >> 16); 2055 ((__le16 *) buf)[1] = cpu_to_le16(dum_hcd->port_status >> 16);
2065 break; 2056 break;
2066 case SetHubFeature: 2057 case SetHubFeature:
2067 retval = -EPIPE; 2058 retval = -EPIPE;
@@ -2195,15 +2186,15 @@ error:
2195 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); 2186 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
2196 2187
2197 if ((dum_hcd->port_status & PORT_C_MASK) != 0) 2188 if ((dum_hcd->port_status & PORT_C_MASK) != 0)
2198 usb_hcd_poll_rh_status (hcd); 2189 usb_hcd_poll_rh_status(hcd);
2199 return retval; 2190 return retval;
2200} 2191}
2201 2192
2202static int dummy_bus_suspend (struct usb_hcd *hcd) 2193static int dummy_bus_suspend(struct usb_hcd *hcd)
2203{ 2194{
2204 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2195 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2205 2196
2206 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2197 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
2207 2198
2208 spin_lock_irq(&dum_hcd->dum->lock); 2199 spin_lock_irq(&dum_hcd->dum->lock);
2209 dum_hcd->rh_state = DUMMY_RH_SUSPENDED; 2200 dum_hcd->rh_state = DUMMY_RH_SUSPENDED;
@@ -2213,12 +2204,12 @@ static int dummy_bus_suspend (struct usb_hcd *hcd)
2213 return 0; 2204 return 0;
2214} 2205}
2215 2206
2216static int dummy_bus_resume (struct usb_hcd *hcd) 2207static int dummy_bus_resume(struct usb_hcd *hcd)
2217{ 2208{
2218 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2209 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2219 int rc = 0; 2210 int rc = 0;
2220 2211
2221 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 2212 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
2222 2213
2223 spin_lock_irq(&dum_hcd->dum->lock); 2214 spin_lock_irq(&dum_hcd->dum->lock);
2224 if (!HCD_HW_ACCESSIBLE(hcd)) { 2215 if (!HCD_HW_ACCESSIBLE(hcd)) {
@@ -2236,55 +2227,54 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
2236 2227
2237/*-------------------------------------------------------------------------*/ 2228/*-------------------------------------------------------------------------*/
2238 2229
2239static inline ssize_t 2230static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2240show_urb (char *buf, size_t size, struct urb *urb)
2241{ 2231{
2242 int ep = usb_pipeendpoint (urb->pipe); 2232 int ep = usb_pipeendpoint(urb->pipe);
2243 2233
2244 return snprintf (buf, size, 2234 return snprintf(buf, size,
2245 "urb/%p %s ep%d%s%s len %d/%d\n", 2235 "urb/%p %s ep%d%s%s len %d/%d\n",
2246 urb, 2236 urb,
2247 ({ char *s; 2237 ({ char *s;
2248 switch (urb->dev->speed) { 2238 switch (urb->dev->speed) {
2249 case USB_SPEED_LOW: 2239 case USB_SPEED_LOW:
2250 s = "ls"; 2240 s = "ls";
2251 break; 2241 break;
2252 case USB_SPEED_FULL: 2242 case USB_SPEED_FULL:
2253 s = "fs"; 2243 s = "fs";
2254 break; 2244 break;
2255 case USB_SPEED_HIGH: 2245 case USB_SPEED_HIGH:
2256 s = "hs"; 2246 s = "hs";
2257 break; 2247 break;
2258 case USB_SPEED_SUPER: 2248 case USB_SPEED_SUPER:
2259 s = "ss"; 2249 s = "ss";
2260 break; 2250 break;
2261 default: 2251 default:
2262 s = "?"; 2252 s = "?";
2263 break; 2253 break;
2264 }; s; }), 2254 }; s; }),
2265 ep, ep ? (usb_pipein (urb->pipe) ? "in" : "out") : "", 2255 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "",
2266 ({ char *s; \ 2256 ({ char *s; \
2267 switch (usb_pipetype (urb->pipe)) { \ 2257 switch (usb_pipetype(urb->pipe)) { \
2268 case PIPE_CONTROL: \ 2258 case PIPE_CONTROL: \
2269 s = ""; \ 2259 s = ""; \
2270 break; \ 2260 break; \
2271 case PIPE_BULK: \ 2261 case PIPE_BULK: \
2272 s = "-bulk"; \ 2262 s = "-bulk"; \
2273 break; \ 2263 break; \
2274 case PIPE_INTERRUPT: \ 2264 case PIPE_INTERRUPT: \
2275 s = "-int"; \ 2265 s = "-int"; \
2276 break; \ 2266 break; \
2277 default: \ 2267 default: \
2278 s = "-iso"; \ 2268 s = "-iso"; \
2279 break; \ 2269 break; \
2280 }; s;}), 2270 }; s; }),
2281 urb->actual_length, urb->transfer_buffer_length); 2271 urb->actual_length, urb->transfer_buffer_length);
2282} 2272}
2283 2273
2284static ssize_t 2274static ssize_t show_urbs(struct device *dev, struct device_attribute *attr,
2285show_urbs (struct device *dev, struct device_attribute *attr, char *buf) 2275 char *buf)
2286{ 2276{
2287 struct usb_hcd *hcd = dev_get_drvdata (dev); 2277 struct usb_hcd *hcd = dev_get_drvdata(dev);
2288 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd); 2278 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
2289 struct urbp *urbp; 2279 struct urbp *urbp;
2290 size_t size = 0; 2280 size_t size = 0;
@@ -2294,7 +2284,7 @@ show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
2294 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) { 2284 list_for_each_entry(urbp, &dum_hcd->urbp_list, urbp_list) {
2295 size_t temp; 2285 size_t temp;
2296 2286
2297 temp = show_urb (buf, PAGE_SIZE - size, urbp->urb); 2287 temp = show_urb(buf, PAGE_SIZE - size, urbp->urb);
2298 buf += temp; 2288 buf += temp;
2299 size += temp; 2289 size += temp;
2300 } 2290 }
@@ -2302,7 +2292,7 @@ show_urbs (struct device *dev, struct device_attribute *attr, char *buf)
2302 2292
2303 return size; 2293 return size;
2304} 2294}
2305static DEVICE_ATTR (urbs, S_IRUGO, show_urbs, NULL); 2295static DEVICE_ATTR(urbs, S_IRUGO, show_urbs, NULL);
2306 2296
2307static int dummy_start_ss(struct dummy_hcd *dum_hcd) 2297static int dummy_start_ss(struct dummy_hcd *dum_hcd)
2308{ 2298{
@@ -2356,11 +2346,11 @@ static int dummy_start(struct usb_hcd *hcd)
2356 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs); 2346 return device_create_file(dummy_dev(dum_hcd), &dev_attr_urbs);
2357} 2347}
2358 2348
2359static void dummy_stop (struct usb_hcd *hcd) 2349static void dummy_stop(struct usb_hcd *hcd)
2360{ 2350{
2361 struct dummy *dum; 2351 struct dummy *dum;
2362 2352
2363 dum = (hcd_to_dummy_hcd(hcd))->dum; 2353 dum = hcd_to_dummy_hcd(hcd)->dum;
2364 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs); 2354 device_remove_file(dummy_dev(hcd_to_dummy_hcd(hcd)), &dev_attr_urbs);
2365 usb_gadget_unregister_driver(dum->driver); 2355 usb_gadget_unregister_driver(dum->driver);
2366 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n"); 2356 dev_info(dummy_dev(hcd_to_dummy_hcd(hcd)), "stopped\n");
@@ -2368,9 +2358,9 @@ static void dummy_stop (struct usb_hcd *hcd)
2368 2358
2369/*-------------------------------------------------------------------------*/ 2359/*-------------------------------------------------------------------------*/
2370 2360
2371static int dummy_h_get_frame (struct usb_hcd *hcd) 2361static int dummy_h_get_frame(struct usb_hcd *hcd)
2372{ 2362{
2373 return dummy_g_get_frame (NULL); 2363 return dummy_g_get_frame(NULL);
2374} 2364}
2375 2365
2376static int dummy_setup(struct usb_hcd *hcd) 2366static int dummy_setup(struct usb_hcd *hcd)
@@ -2485,13 +2475,13 @@ static struct hc_driver dummy_hcd = {
2485 .start = dummy_start, 2475 .start = dummy_start,
2486 .stop = dummy_stop, 2476 .stop = dummy_stop,
2487 2477
2488 .urb_enqueue = dummy_urb_enqueue, 2478 .urb_enqueue = dummy_urb_enqueue,
2489 .urb_dequeue = dummy_urb_dequeue, 2479 .urb_dequeue = dummy_urb_dequeue,
2490 2480
2491 .get_frame_number = dummy_h_get_frame, 2481 .get_frame_number = dummy_h_get_frame,
2492 2482
2493 .hub_status_data = dummy_hub_status, 2483 .hub_status_data = dummy_hub_status,
2494 .hub_control = dummy_hub_control, 2484 .hub_control = dummy_hub_control,
2495 .bus_suspend = dummy_bus_suspend, 2485 .bus_suspend = dummy_bus_suspend,
2496 .bus_resume = dummy_bus_resume, 2486 .bus_resume = dummy_bus_resume,
2497 2487
@@ -2546,7 +2536,7 @@ static int dummy_hcd_remove(struct platform_device *pdev)
2546{ 2536{
2547 struct dummy *dum; 2537 struct dummy *dum;
2548 2538
2549 dum = (hcd_to_dummy_hcd(platform_get_drvdata(pdev)))->dum; 2539 dum = hcd_to_dummy_hcd(platform_get_drvdata(pdev))->dum;
2550 2540
2551 if (dum->ss_hcd) { 2541 if (dum->ss_hcd) {
2552 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd)); 2542 usb_remove_hcd(dummy_hcd_to_hcd(dum->ss_hcd));
@@ -2562,15 +2552,15 @@ static int dummy_hcd_remove(struct platform_device *pdev)
2562 return 0; 2552 return 0;
2563} 2553}
2564 2554
2565static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state) 2555static int dummy_hcd_suspend(struct platform_device *pdev, pm_message_t state)
2566{ 2556{
2567 struct usb_hcd *hcd; 2557 struct usb_hcd *hcd;
2568 struct dummy_hcd *dum_hcd; 2558 struct dummy_hcd *dum_hcd;
2569 int rc = 0; 2559 int rc = 0;
2570 2560
2571 dev_dbg (&pdev->dev, "%s\n", __func__); 2561 dev_dbg(&pdev->dev, "%s\n", __func__);
2572 2562
2573 hcd = platform_get_drvdata (pdev); 2563 hcd = platform_get_drvdata(pdev);
2574 dum_hcd = hcd_to_dummy_hcd(hcd); 2564 dum_hcd = hcd_to_dummy_hcd(hcd);
2575 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) { 2565 if (dum_hcd->rh_state == DUMMY_RH_RUNNING) {
2576 dev_warn(&pdev->dev, "Root hub isn't suspended!\n"); 2566 dev_warn(&pdev->dev, "Root hub isn't suspended!\n");
@@ -2580,15 +2570,15 @@ static int dummy_hcd_suspend (struct platform_device *pdev, pm_message_t state)
2580 return rc; 2570 return rc;
2581} 2571}
2582 2572
2583static int dummy_hcd_resume (struct platform_device *pdev) 2573static int dummy_hcd_resume(struct platform_device *pdev)
2584{ 2574{
2585 struct usb_hcd *hcd; 2575 struct usb_hcd *hcd;
2586 2576
2587 dev_dbg (&pdev->dev, "%s\n", __func__); 2577 dev_dbg(&pdev->dev, "%s\n", __func__);
2588 2578
2589 hcd = platform_get_drvdata (pdev); 2579 hcd = platform_get_drvdata(pdev);
2590 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 2580 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2591 usb_hcd_poll_rh_status (hcd); 2581 usb_hcd_poll_rh_status(hcd);
2592 return 0; 2582 return 0;
2593} 2583}
2594 2584
@@ -2608,11 +2598,11 @@ static struct platform_driver dummy_hcd_driver = {
2608static struct platform_device *the_udc_pdev; 2598static struct platform_device *the_udc_pdev;
2609static struct platform_device *the_hcd_pdev; 2599static struct platform_device *the_hcd_pdev;
2610 2600
2611static int __init init (void) 2601static int __init init(void)
2612{ 2602{
2613 int retval = -ENOMEM; 2603 int retval = -ENOMEM;
2614 2604
2615 if (usb_disabled ()) 2605 if (usb_disabled())
2616 return -ENODEV; 2606 return -ENODEV;
2617 2607
2618 if (!mod_data.is_high_speed && mod_data.is_super_speed) 2608 if (!mod_data.is_high_speed && mod_data.is_super_speed)
@@ -2671,13 +2661,13 @@ err_alloc_udc:
2671 platform_device_put(the_hcd_pdev); 2661 platform_device_put(the_hcd_pdev);
2672 return retval; 2662 return retval;
2673} 2663}
2674module_init (init); 2664module_init(init);
2675 2665
2676static void __exit cleanup (void) 2666static void __exit cleanup(void)
2677{ 2667{
2678 platform_device_unregister(the_udc_pdev); 2668 platform_device_unregister(the_udc_pdev);
2679 platform_device_unregister(the_hcd_pdev); 2669 platform_device_unregister(the_hcd_pdev);
2680 platform_driver_unregister(&dummy_udc_driver); 2670 platform_driver_unregister(&dummy_udc_driver);
2681 platform_driver_unregister(&dummy_hcd_driver); 2671 platform_driver_unregister(&dummy_hcd_driver);
2682} 2672}
2683module_exit (cleanup); 2673module_exit(cleanup);