diff options
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/at91_udc.c | 205 | ||||
-rw-r--r-- | drivers/usb/gadget/at91_udc.h | 3 | ||||
-rw-r--r-- | drivers/usb/gadget/f_eem.c | 3 | ||||
-rw-r--r-- | drivers/usb/gadget/f_fs.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/f_mass_storage.c | 194 | ||||
-rw-r--r-- | drivers/usb/gadget/f_uvc.c | 4 | ||||
-rw-r--r-- | drivers/usb/gadget/fsl_mxc_udc.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/g_ffs.c | 11 | ||||
-rw-r--r-- | drivers/usb/gadget/printer.c | 32 | ||||
-rw-r--r-- | drivers/usb/gadget/pxa27x_udc.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/s3c2410_udc.c | 10 | ||||
-rw-r--r-- | drivers/usb/gadget/u_serial.c | 16 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc.h | 10 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_queue.c | 153 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_queue.h | 20 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_v4l2.c | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/uvc_video.c | 6 | ||||
-rw-r--r-- | drivers/usb/gadget/webcam.c | 4 |
18 files changed, 354 insertions, 325 deletions
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index eaa79c8a9b8c..93ead19507b6 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -76,11 +76,12 @@ | |||
76 | static const char driver_name [] = "at91_udc"; | 76 | static const char driver_name [] = "at91_udc"; |
77 | static const char ep0name[] = "ep0"; | 77 | static const char ep0name[] = "ep0"; |
78 | 78 | ||
79 | #define VBUS_POLL_TIMEOUT msecs_to_jiffies(1000) | ||
79 | 80 | ||
80 | #define at91_udp_read(dev, reg) \ | 81 | #define at91_udp_read(udc, reg) \ |
81 | __raw_readl((dev)->udp_baseaddr + (reg)) | 82 | __raw_readl((udc)->udp_baseaddr + (reg)) |
82 | #define at91_udp_write(dev, reg, val) \ | 83 | #define at91_udp_write(udc, reg, val) \ |
83 | __raw_writel((val), (dev)->udp_baseaddr + (reg)) | 84 | __raw_writel((val), (udc)->udp_baseaddr + (reg)) |
84 | 85 | ||
85 | /*-------------------------------------------------------------------------*/ | 86 | /*-------------------------------------------------------------------------*/ |
86 | 87 | ||
@@ -102,8 +103,9 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep) | |||
102 | u32 csr; | 103 | u32 csr; |
103 | struct at91_request *req; | 104 | struct at91_request *req; |
104 | unsigned long flags; | 105 | unsigned long flags; |
106 | struct at91_udc *udc = ep->udc; | ||
105 | 107 | ||
106 | local_irq_save(flags); | 108 | spin_lock_irqsave(&udc->lock, flags); |
107 | 109 | ||
108 | csr = __raw_readl(ep->creg); | 110 | csr = __raw_readl(ep->creg); |
109 | 111 | ||
@@ -147,7 +149,7 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep) | |||
147 | &req->req, length, | 149 | &req->req, length, |
148 | req->req.length, req->req.buf); | 150 | req->req.length, req->req.buf); |
149 | } | 151 | } |
150 | local_irq_restore(flags); | 152 | spin_unlock_irqrestore(&udc->lock, flags); |
151 | } | 153 | } |
152 | 154 | ||
153 | static void proc_irq_show(struct seq_file *s, const char *label, u32 mask) | 155 | static void proc_irq_show(struct seq_file *s, const char *label, u32 mask) |
@@ -272,7 +274,9 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status) | |||
272 | VDBG("%s done %p, status %d\n", ep->ep.name, req, status); | 274 | VDBG("%s done %p, status %d\n", ep->ep.name, req, status); |
273 | 275 | ||
274 | ep->stopped = 1; | 276 | ep->stopped = 1; |
277 | spin_unlock(&udc->lock); | ||
275 | req->req.complete(&ep->ep, &req->req); | 278 | req->req.complete(&ep->ep, &req->req); |
279 | spin_lock(&udc->lock); | ||
276 | ep->stopped = stopped; | 280 | ep->stopped = stopped; |
277 | 281 | ||
278 | /* ep0 is always ready; other endpoints need a non-empty queue */ | 282 | /* ep0 is always ready; other endpoints need a non-empty queue */ |
@@ -472,7 +476,7 @@ static int at91_ep_enable(struct usb_ep *_ep, | |||
472 | const struct usb_endpoint_descriptor *desc) | 476 | const struct usb_endpoint_descriptor *desc) |
473 | { | 477 | { |
474 | struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); | 478 | struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); |
475 | struct at91_udc *dev = ep->udc; | 479 | struct at91_udc *udc = ep->udc; |
476 | u16 maxpacket; | 480 | u16 maxpacket; |
477 | u32 tmp; | 481 | u32 tmp; |
478 | unsigned long flags; | 482 | unsigned long flags; |
@@ -487,7 +491,7 @@ static int at91_ep_enable(struct usb_ep *_ep, | |||
487 | return -EINVAL; | 491 | return -EINVAL; |
488 | } | 492 | } |
489 | 493 | ||
490 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { | 494 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { |
491 | DBG("bogus device state\n"); | 495 | DBG("bogus device state\n"); |
492 | return -ESHUTDOWN; | 496 | return -ESHUTDOWN; |
493 | } | 497 | } |
@@ -521,7 +525,7 @@ bogus_max: | |||
521 | } | 525 | } |
522 | 526 | ||
523 | ok: | 527 | ok: |
524 | local_irq_save(flags); | 528 | spin_lock_irqsave(&udc->lock, flags); |
525 | 529 | ||
526 | /* initialize endpoint to match this descriptor */ | 530 | /* initialize endpoint to match this descriptor */ |
527 | ep->is_in = usb_endpoint_dir_in(desc); | 531 | ep->is_in = usb_endpoint_dir_in(desc); |
@@ -540,10 +544,10 @@ ok: | |||
540 | * reset/init endpoint fifo. NOTE: leaves fifo_bank alone, | 544 | * reset/init endpoint fifo. NOTE: leaves fifo_bank alone, |
541 | * since endpoint resets don't reset hw pingpong state. | 545 | * since endpoint resets don't reset hw pingpong state. |
542 | */ | 546 | */ |
543 | at91_udp_write(dev, AT91_UDP_RST_EP, ep->int_mask); | 547 | at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask); |
544 | at91_udp_write(dev, AT91_UDP_RST_EP, 0); | 548 | at91_udp_write(udc, AT91_UDP_RST_EP, 0); |
545 | 549 | ||
546 | local_irq_restore(flags); | 550 | spin_unlock_irqrestore(&udc->lock, flags); |
547 | return 0; | 551 | return 0; |
548 | } | 552 | } |
549 | 553 | ||
@@ -556,7 +560,7 @@ static int at91_ep_disable (struct usb_ep * _ep) | |||
556 | if (ep == &ep->udc->ep[0]) | 560 | if (ep == &ep->udc->ep[0]) |
557 | return -EINVAL; | 561 | return -EINVAL; |
558 | 562 | ||
559 | local_irq_save(flags); | 563 | spin_lock_irqsave(&udc->lock, flags); |
560 | 564 | ||
561 | nuke(ep, -ESHUTDOWN); | 565 | nuke(ep, -ESHUTDOWN); |
562 | 566 | ||
@@ -571,7 +575,7 @@ static int at91_ep_disable (struct usb_ep * _ep) | |||
571 | __raw_writel(0, ep->creg); | 575 | __raw_writel(0, ep->creg); |
572 | } | 576 | } |
573 | 577 | ||
574 | local_irq_restore(flags); | 578 | spin_unlock_irqrestore(&udc->lock, flags); |
575 | return 0; | 579 | return 0; |
576 | } | 580 | } |
577 | 581 | ||
@@ -607,7 +611,7 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
607 | { | 611 | { |
608 | struct at91_request *req; | 612 | struct at91_request *req; |
609 | struct at91_ep *ep; | 613 | struct at91_ep *ep; |
610 | struct at91_udc *dev; | 614 | struct at91_udc *udc; |
611 | int status; | 615 | int status; |
612 | unsigned long flags; | 616 | unsigned long flags; |
613 | 617 | ||
@@ -625,9 +629,9 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
625 | return -EINVAL; | 629 | return -EINVAL; |
626 | } | 630 | } |
627 | 631 | ||
628 | dev = ep->udc; | 632 | udc = ep->udc; |
629 | 633 | ||
630 | if (!dev || !dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { | 634 | if (!udc || !udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { |
631 | DBG("invalid device\n"); | 635 | DBG("invalid device\n"); |
632 | return -EINVAL; | 636 | return -EINVAL; |
633 | } | 637 | } |
@@ -635,7 +639,7 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
635 | _req->status = -EINPROGRESS; | 639 | _req->status = -EINPROGRESS; |
636 | _req->actual = 0; | 640 | _req->actual = 0; |
637 | 641 | ||
638 | local_irq_save(flags); | 642 | spin_lock_irqsave(&udc->lock, flags); |
639 | 643 | ||
640 | /* try to kickstart any empty and idle queue */ | 644 | /* try to kickstart any empty and idle queue */ |
641 | if (list_empty(&ep->queue) && !ep->stopped) { | 645 | if (list_empty(&ep->queue) && !ep->stopped) { |
@@ -653,7 +657,7 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
653 | if (is_ep0) { | 657 | if (is_ep0) { |
654 | u32 tmp; | 658 | u32 tmp; |
655 | 659 | ||
656 | if (!dev->req_pending) { | 660 | if (!udc->req_pending) { |
657 | status = -EINVAL; | 661 | status = -EINVAL; |
658 | goto done; | 662 | goto done; |
659 | } | 663 | } |
@@ -662,11 +666,11 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
662 | * defer changing CONFG until after the gadget driver | 666 | * defer changing CONFG until after the gadget driver |
663 | * reconfigures the endpoints. | 667 | * reconfigures the endpoints. |
664 | */ | 668 | */ |
665 | if (dev->wait_for_config_ack) { | 669 | if (udc->wait_for_config_ack) { |
666 | tmp = at91_udp_read(dev, AT91_UDP_GLB_STAT); | 670 | tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT); |
667 | tmp ^= AT91_UDP_CONFG; | 671 | tmp ^= AT91_UDP_CONFG; |
668 | VDBG("toggle config\n"); | 672 | VDBG("toggle config\n"); |
669 | at91_udp_write(dev, AT91_UDP_GLB_STAT, tmp); | 673 | at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp); |
670 | } | 674 | } |
671 | if (req->req.length == 0) { | 675 | if (req->req.length == 0) { |
672 | ep0_in_status: | 676 | ep0_in_status: |
@@ -676,7 +680,7 @@ ep0_in_status: | |||
676 | tmp &= ~SET_FX; | 680 | tmp &= ~SET_FX; |
677 | tmp |= CLR_FX | AT91_UDP_TXPKTRDY; | 681 | tmp |= CLR_FX | AT91_UDP_TXPKTRDY; |
678 | __raw_writel(tmp, ep->creg); | 682 | __raw_writel(tmp, ep->creg); |
679 | dev->req_pending = 0; | 683 | udc->req_pending = 0; |
680 | goto done; | 684 | goto done; |
681 | } | 685 | } |
682 | } | 686 | } |
@@ -695,31 +699,40 @@ ep0_in_status: | |||
695 | 699 | ||
696 | if (req && !status) { | 700 | if (req && !status) { |
697 | list_add_tail (&req->queue, &ep->queue); | 701 | list_add_tail (&req->queue, &ep->queue); |
698 | at91_udp_write(dev, AT91_UDP_IER, ep->int_mask); | 702 | at91_udp_write(udc, AT91_UDP_IER, ep->int_mask); |
699 | } | 703 | } |
700 | done: | 704 | done: |
701 | local_irq_restore(flags); | 705 | spin_unlock_irqrestore(&udc->lock, flags); |
702 | return (status < 0) ? status : 0; | 706 | return (status < 0) ? status : 0; |
703 | } | 707 | } |
704 | 708 | ||
705 | static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | 709 | static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) |
706 | { | 710 | { |
707 | struct at91_ep *ep; | 711 | struct at91_ep *ep; |
708 | struct at91_request *req; | 712 | struct at91_request *req; |
713 | unsigned long flags; | ||
714 | struct at91_udc *udc; | ||
709 | 715 | ||
710 | ep = container_of(_ep, struct at91_ep, ep); | 716 | ep = container_of(_ep, struct at91_ep, ep); |
711 | if (!_ep || ep->ep.name == ep0name) | 717 | if (!_ep || ep->ep.name == ep0name) |
712 | return -EINVAL; | 718 | return -EINVAL; |
713 | 719 | ||
720 | udc = ep->udc; | ||
721 | |||
722 | spin_lock_irqsave(&udc->lock, flags); | ||
723 | |||
714 | /* make sure it's actually queued on this endpoint */ | 724 | /* make sure it's actually queued on this endpoint */ |
715 | list_for_each_entry (req, &ep->queue, queue) { | 725 | list_for_each_entry (req, &ep->queue, queue) { |
716 | if (&req->req == _req) | 726 | if (&req->req == _req) |
717 | break; | 727 | break; |
718 | } | 728 | } |
719 | if (&req->req != _req) | 729 | if (&req->req != _req) { |
730 | spin_unlock_irqrestore(&udc->lock, flags); | ||
720 | return -EINVAL; | 731 | return -EINVAL; |
732 | } | ||
721 | 733 | ||
722 | done(ep, req, -ECONNRESET); | 734 | done(ep, req, -ECONNRESET); |
735 | spin_unlock_irqrestore(&udc->lock, flags); | ||
723 | return 0; | 736 | return 0; |
724 | } | 737 | } |
725 | 738 | ||
@@ -736,7 +749,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value) | |||
736 | return -EINVAL; | 749 | return -EINVAL; |
737 | 750 | ||
738 | creg = ep->creg; | 751 | creg = ep->creg; |
739 | local_irq_save(flags); | 752 | spin_lock_irqsave(&udc->lock, flags); |
740 | 753 | ||
741 | csr = __raw_readl(creg); | 754 | csr = __raw_readl(creg); |
742 | 755 | ||
@@ -761,7 +774,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value) | |||
761 | __raw_writel(csr, creg); | 774 | __raw_writel(csr, creg); |
762 | } | 775 | } |
763 | 776 | ||
764 | local_irq_restore(flags); | 777 | spin_unlock_irqrestore(&udc->lock, flags); |
765 | return status; | 778 | return status; |
766 | } | 779 | } |
767 | 780 | ||
@@ -795,7 +808,7 @@ static int at91_wakeup(struct usb_gadget *gadget) | |||
795 | unsigned long flags; | 808 | unsigned long flags; |
796 | 809 | ||
797 | DBG("%s\n", __func__ ); | 810 | DBG("%s\n", __func__ ); |
798 | local_irq_save(flags); | 811 | spin_lock_irqsave(&udc->lock, flags); |
799 | 812 | ||
800 | if (!udc->clocked || !udc->suspended) | 813 | if (!udc->clocked || !udc->suspended) |
801 | goto done; | 814 | goto done; |
@@ -809,7 +822,7 @@ static int at91_wakeup(struct usb_gadget *gadget) | |||
809 | at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate); | 822 | at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate); |
810 | 823 | ||
811 | done: | 824 | done: |
812 | local_irq_restore(flags); | 825 | spin_unlock_irqrestore(&udc->lock, flags); |
813 | return status; | 826 | return status; |
814 | } | 827 | } |
815 | 828 | ||
@@ -851,8 +864,11 @@ static void stop_activity(struct at91_udc *udc) | |||
851 | ep->stopped = 1; | 864 | ep->stopped = 1; |
852 | nuke(ep, -ESHUTDOWN); | 865 | nuke(ep, -ESHUTDOWN); |
853 | } | 866 | } |
854 | if (driver) | 867 | if (driver) { |
868 | spin_unlock(&udc->lock); | ||
855 | driver->disconnect(&udc->gadget); | 869 | driver->disconnect(&udc->gadget); |
870 | spin_lock(&udc->lock); | ||
871 | } | ||
856 | 872 | ||
857 | udc_reinit(udc); | 873 | udc_reinit(udc); |
858 | } | 874 | } |
@@ -935,13 +951,13 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active) | |||
935 | unsigned long flags; | 951 | unsigned long flags; |
936 | 952 | ||
937 | // VDBG("vbus %s\n", is_active ? "on" : "off"); | 953 | // VDBG("vbus %s\n", is_active ? "on" : "off"); |
938 | local_irq_save(flags); | 954 | spin_lock_irqsave(&udc->lock, flags); |
939 | udc->vbus = (is_active != 0); | 955 | udc->vbus = (is_active != 0); |
940 | if (udc->driver) | 956 | if (udc->driver) |
941 | pullup(udc, is_active); | 957 | pullup(udc, is_active); |
942 | else | 958 | else |
943 | pullup(udc, 0); | 959 | pullup(udc, 0); |
944 | local_irq_restore(flags); | 960 | spin_unlock_irqrestore(&udc->lock, flags); |
945 | return 0; | 961 | return 0; |
946 | } | 962 | } |
947 | 963 | ||
@@ -950,10 +966,10 @@ static int at91_pullup(struct usb_gadget *gadget, int is_on) | |||
950 | struct at91_udc *udc = to_udc(gadget); | 966 | struct at91_udc *udc = to_udc(gadget); |
951 | unsigned long flags; | 967 | unsigned long flags; |
952 | 968 | ||
953 | local_irq_save(flags); | 969 | spin_lock_irqsave(&udc->lock, flags); |
954 | udc->enabled = is_on = !!is_on; | 970 | udc->enabled = is_on = !!is_on; |
955 | pullup(udc, is_on); | 971 | pullup(udc, is_on); |
956 | local_irq_restore(flags); | 972 | spin_unlock_irqrestore(&udc->lock, flags); |
957 | return 0; | 973 | return 0; |
958 | } | 974 | } |
959 | 975 | ||
@@ -962,9 +978,9 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on) | |||
962 | struct at91_udc *udc = to_udc(gadget); | 978 | struct at91_udc *udc = to_udc(gadget); |
963 | unsigned long flags; | 979 | unsigned long flags; |
964 | 980 | ||
965 | local_irq_save(flags); | 981 | spin_lock_irqsave(&udc->lock, flags); |
966 | udc->selfpowered = (is_on != 0); | 982 | udc->selfpowered = (is_on != 0); |
967 | local_irq_restore(flags); | 983 | spin_unlock_irqrestore(&udc->lock, flags); |
968 | return 0; | 984 | return 0; |
969 | } | 985 | } |
970 | 986 | ||
@@ -1226,8 +1242,11 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | |||
1226 | #undef w_length | 1242 | #undef w_length |
1227 | 1243 | ||
1228 | /* pass request up to the gadget driver */ | 1244 | /* pass request up to the gadget driver */ |
1229 | if (udc->driver) | 1245 | if (udc->driver) { |
1246 | spin_unlock(&udc->lock); | ||
1230 | status = udc->driver->setup(&udc->gadget, &pkt.r); | 1247 | status = udc->driver->setup(&udc->gadget, &pkt.r); |
1248 | spin_lock(&udc->lock); | ||
1249 | } | ||
1231 | else | 1250 | else |
1232 | status = -ENODEV; | 1251 | status = -ENODEV; |
1233 | if (status < 0) { | 1252 | if (status < 0) { |
@@ -1378,6 +1397,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1378 | struct at91_udc *udc = _udc; | 1397 | struct at91_udc *udc = _udc; |
1379 | u32 rescans = 5; | 1398 | u32 rescans = 5; |
1380 | int disable_clock = 0; | 1399 | int disable_clock = 0; |
1400 | unsigned long flags; | ||
1401 | |||
1402 | spin_lock_irqsave(&udc->lock, flags); | ||
1381 | 1403 | ||
1382 | if (!udc->clocked) { | 1404 | if (!udc->clocked) { |
1383 | clk_on(udc); | 1405 | clk_on(udc); |
@@ -1433,8 +1455,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1433 | * and then into standby to avoid drawing more than | 1455 | * and then into standby to avoid drawing more than |
1434 | * 500uA power (2500uA for some high-power configs). | 1456 | * 500uA power (2500uA for some high-power configs). |
1435 | */ | 1457 | */ |
1436 | if (udc->driver && udc->driver->suspend) | 1458 | if (udc->driver && udc->driver->suspend) { |
1459 | spin_unlock(&udc->lock); | ||
1437 | udc->driver->suspend(&udc->gadget); | 1460 | udc->driver->suspend(&udc->gadget); |
1461 | spin_lock(&udc->lock); | ||
1462 | } | ||
1438 | 1463 | ||
1439 | /* host initiated resume */ | 1464 | /* host initiated resume */ |
1440 | } else if (status & AT91_UDP_RXRSM) { | 1465 | } else if (status & AT91_UDP_RXRSM) { |
@@ -1451,8 +1476,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1451 | * would normally want to switch out of slow clock | 1476 | * would normally want to switch out of slow clock |
1452 | * mode into normal mode. | 1477 | * mode into normal mode. |
1453 | */ | 1478 | */ |
1454 | if (udc->driver && udc->driver->resume) | 1479 | if (udc->driver && udc->driver->resume) { |
1480 | spin_unlock(&udc->lock); | ||
1455 | udc->driver->resume(&udc->gadget); | 1481 | udc->driver->resume(&udc->gadget); |
1482 | spin_lock(&udc->lock); | ||
1483 | } | ||
1456 | 1484 | ||
1457 | /* endpoint IRQs are cleared by handling them */ | 1485 | /* endpoint IRQs are cleared by handling them */ |
1458 | } else { | 1486 | } else { |
@@ -1474,6 +1502,8 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) | |||
1474 | if (disable_clock) | 1502 | if (disable_clock) |
1475 | clk_off(udc); | 1503 | clk_off(udc); |
1476 | 1504 | ||
1505 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1506 | |||
1477 | return IRQ_HANDLED; | 1507 | return IRQ_HANDLED; |
1478 | } | 1508 | } |
1479 | 1509 | ||
@@ -1556,24 +1586,53 @@ static struct at91_udc controller = { | |||
1556 | /* ep6 and ep7 are also reserved (custom silicon might use them) */ | 1586 | /* ep6 and ep7 are also reserved (custom silicon might use them) */ |
1557 | }; | 1587 | }; |
1558 | 1588 | ||
1589 | static void at91_vbus_update(struct at91_udc *udc, unsigned value) | ||
1590 | { | ||
1591 | value ^= udc->board.vbus_active_low; | ||
1592 | if (value != udc->vbus) | ||
1593 | at91_vbus_session(&udc->gadget, value); | ||
1594 | } | ||
1595 | |||
1559 | static irqreturn_t at91_vbus_irq(int irq, void *_udc) | 1596 | static irqreturn_t at91_vbus_irq(int irq, void *_udc) |
1560 | { | 1597 | { |
1561 | struct at91_udc *udc = _udc; | 1598 | struct at91_udc *udc = _udc; |
1562 | unsigned value; | ||
1563 | 1599 | ||
1564 | /* vbus needs at least brief debouncing */ | 1600 | /* vbus needs at least brief debouncing */ |
1565 | udelay(10); | 1601 | udelay(10); |
1566 | value = gpio_get_value(udc->board.vbus_pin); | 1602 | at91_vbus_update(udc, gpio_get_value(udc->board.vbus_pin)); |
1567 | if (value != udc->vbus) | ||
1568 | at91_vbus_session(&udc->gadget, value); | ||
1569 | 1603 | ||
1570 | return IRQ_HANDLED; | 1604 | return IRQ_HANDLED; |
1571 | } | 1605 | } |
1572 | 1606 | ||
1607 | static void at91_vbus_timer_work(struct work_struct *work) | ||
1608 | { | ||
1609 | struct at91_udc *udc = container_of(work, struct at91_udc, | ||
1610 | vbus_timer_work); | ||
1611 | |||
1612 | at91_vbus_update(udc, gpio_get_value_cansleep(udc->board.vbus_pin)); | ||
1613 | |||
1614 | if (!timer_pending(&udc->vbus_timer)) | ||
1615 | mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT); | ||
1616 | } | ||
1617 | |||
1618 | static void at91_vbus_timer(unsigned long data) | ||
1619 | { | ||
1620 | struct at91_udc *udc = (struct at91_udc *)data; | ||
1621 | |||
1622 | /* | ||
1623 | * If we are polling vbus it is likely that the gpio is on an | ||
1624 | * bus such as i2c or spi which may sleep, so schedule some work | ||
1625 | * to read the vbus gpio | ||
1626 | */ | ||
1627 | if (!work_pending(&udc->vbus_timer_work)) | ||
1628 | schedule_work(&udc->vbus_timer_work); | ||
1629 | } | ||
1630 | |||
1573 | int usb_gadget_register_driver (struct usb_gadget_driver *driver) | 1631 | int usb_gadget_register_driver (struct usb_gadget_driver *driver) |
1574 | { | 1632 | { |
1575 | struct at91_udc *udc = &controller; | 1633 | struct at91_udc *udc = &controller; |
1576 | int retval; | 1634 | int retval; |
1635 | unsigned long flags; | ||
1577 | 1636 | ||
1578 | if (!driver | 1637 | if (!driver |
1579 | || driver->speed < USB_SPEED_FULL | 1638 | || driver->speed < USB_SPEED_FULL |
@@ -1605,9 +1664,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) | |||
1605 | return retval; | 1664 | return retval; |
1606 | } | 1665 | } |
1607 | 1666 | ||
1608 | local_irq_disable(); | 1667 | spin_lock_irqsave(&udc->lock, flags); |
1609 | pullup(udc, 1); | 1668 | pullup(udc, 1); |
1610 | local_irq_enable(); | 1669 | spin_unlock_irqrestore(&udc->lock, flags); |
1611 | 1670 | ||
1612 | DBG("bound to %s\n", driver->driver.name); | 1671 | DBG("bound to %s\n", driver->driver.name); |
1613 | return 0; | 1672 | return 0; |
@@ -1617,15 +1676,16 @@ EXPORT_SYMBOL (usb_gadget_register_driver); | |||
1617 | int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) | 1676 | int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) |
1618 | { | 1677 | { |
1619 | struct at91_udc *udc = &controller; | 1678 | struct at91_udc *udc = &controller; |
1679 | unsigned long flags; | ||
1620 | 1680 | ||
1621 | if (!driver || driver != udc->driver || !driver->unbind) | 1681 | if (!driver || driver != udc->driver || !driver->unbind) |
1622 | return -EINVAL; | 1682 | return -EINVAL; |
1623 | 1683 | ||
1624 | local_irq_disable(); | 1684 | spin_lock_irqsave(&udc->lock, flags); |
1625 | udc->enabled = 0; | 1685 | udc->enabled = 0; |
1626 | at91_udp_write(udc, AT91_UDP_IDR, ~0); | 1686 | at91_udp_write(udc, AT91_UDP_IDR, ~0); |
1627 | pullup(udc, 0); | 1687 | pullup(udc, 0); |
1628 | local_irq_enable(); | 1688 | spin_unlock_irqrestore(&udc->lock, flags); |
1629 | 1689 | ||
1630 | driver->unbind(&udc->gadget); | 1690 | driver->unbind(&udc->gadget); |
1631 | udc->gadget.dev.driver = NULL; | 1691 | udc->gadget.dev.driver = NULL; |
@@ -1641,8 +1701,13 @@ EXPORT_SYMBOL (usb_gadget_unregister_driver); | |||
1641 | 1701 | ||
1642 | static void at91udc_shutdown(struct platform_device *dev) | 1702 | static void at91udc_shutdown(struct platform_device *dev) |
1643 | { | 1703 | { |
1704 | struct at91_udc *udc = platform_get_drvdata(dev); | ||
1705 | unsigned long flags; | ||
1706 | |||
1644 | /* force disconnect on reboot */ | 1707 | /* force disconnect on reboot */ |
1708 | spin_lock_irqsave(&udc->lock, flags); | ||
1645 | pullup(platform_get_drvdata(dev), 0); | 1709 | pullup(platform_get_drvdata(dev), 0); |
1710 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1646 | } | 1711 | } |
1647 | 1712 | ||
1648 | static int __init at91udc_probe(struct platform_device *pdev) | 1713 | static int __init at91udc_probe(struct platform_device *pdev) |
@@ -1683,6 +1748,7 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1683 | udc->board = *(struct at91_udc_data *) dev->platform_data; | 1748 | udc->board = *(struct at91_udc_data *) dev->platform_data; |
1684 | udc->pdev = pdev; | 1749 | udc->pdev = pdev; |
1685 | udc->enabled = 0; | 1750 | udc->enabled = 0; |
1751 | spin_lock_init(&udc->lock); | ||
1686 | 1752 | ||
1687 | /* rm9200 needs manual D+ pullup; off by default */ | 1753 | /* rm9200 needs manual D+ pullup; off by default */ |
1688 | if (cpu_is_at91rm9200()) { | 1754 | if (cpu_is_at91rm9200()) { |
@@ -1763,13 +1829,23 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1763 | * Get the initial state of VBUS - we cannot expect | 1829 | * Get the initial state of VBUS - we cannot expect |
1764 | * a pending interrupt. | 1830 | * a pending interrupt. |
1765 | */ | 1831 | */ |
1766 | udc->vbus = gpio_get_value(udc->board.vbus_pin); | 1832 | udc->vbus = gpio_get_value_cansleep(udc->board.vbus_pin) ^ |
1767 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, | 1833 | udc->board.vbus_active_low; |
1768 | IRQF_DISABLED, driver_name, udc)) { | 1834 | |
1769 | DBG("request vbus irq %d failed\n", | 1835 | if (udc->board.vbus_polled) { |
1770 | udc->board.vbus_pin); | 1836 | INIT_WORK(&udc->vbus_timer_work, at91_vbus_timer_work); |
1771 | retval = -EBUSY; | 1837 | setup_timer(&udc->vbus_timer, at91_vbus_timer, |
1772 | goto fail3; | 1838 | (unsigned long)udc); |
1839 | mod_timer(&udc->vbus_timer, | ||
1840 | jiffies + VBUS_POLL_TIMEOUT); | ||
1841 | } else { | ||
1842 | if (request_irq(udc->board.vbus_pin, at91_vbus_irq, | ||
1843 | IRQF_DISABLED, driver_name, udc)) { | ||
1844 | DBG("request vbus irq %d failed\n", | ||
1845 | udc->board.vbus_pin); | ||
1846 | retval = -EBUSY; | ||
1847 | goto fail3; | ||
1848 | } | ||
1773 | } | 1849 | } |
1774 | } else { | 1850 | } else { |
1775 | DBG("no VBUS detection, assuming always-on\n"); | 1851 | DBG("no VBUS detection, assuming always-on\n"); |
@@ -1804,13 +1880,16 @@ static int __exit at91udc_remove(struct platform_device *pdev) | |||
1804 | { | 1880 | { |
1805 | struct at91_udc *udc = platform_get_drvdata(pdev); | 1881 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1806 | struct resource *res; | 1882 | struct resource *res; |
1883 | unsigned long flags; | ||
1807 | 1884 | ||
1808 | DBG("remove\n"); | 1885 | DBG("remove\n"); |
1809 | 1886 | ||
1810 | if (udc->driver) | 1887 | if (udc->driver) |
1811 | return -EBUSY; | 1888 | return -EBUSY; |
1812 | 1889 | ||
1890 | spin_lock_irqsave(&udc->lock, flags); | ||
1813 | pullup(udc, 0); | 1891 | pullup(udc, 0); |
1892 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1814 | 1893 | ||
1815 | device_init_wakeup(&pdev->dev, 0); | 1894 | device_init_wakeup(&pdev->dev, 0); |
1816 | remove_debug_file(udc); | 1895 | remove_debug_file(udc); |
@@ -1840,6 +1919,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
1840 | { | 1919 | { |
1841 | struct at91_udc *udc = platform_get_drvdata(pdev); | 1920 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1842 | int wake = udc->driver && device_may_wakeup(&pdev->dev); | 1921 | int wake = udc->driver && device_may_wakeup(&pdev->dev); |
1922 | unsigned long flags; | ||
1843 | 1923 | ||
1844 | /* Unless we can act normally to the host (letting it wake us up | 1924 | /* Unless we can act normally to the host (letting it wake us up |
1845 | * whenever it has work for us) force disconnect. Wakeup requires | 1925 | * whenever it has work for us) force disconnect. Wakeup requires |
@@ -1849,13 +1929,15 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
1849 | if ((!udc->suspended && udc->addr) | 1929 | if ((!udc->suspended && udc->addr) |
1850 | || !wake | 1930 | || !wake |
1851 | || at91_suspend_entering_slow_clock()) { | 1931 | || at91_suspend_entering_slow_clock()) { |
1932 | spin_lock_irqsave(&udc->lock, flags); | ||
1852 | pullup(udc, 0); | 1933 | pullup(udc, 0); |
1853 | wake = 0; | 1934 | wake = 0; |
1935 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1854 | } else | 1936 | } else |
1855 | enable_irq_wake(udc->udp_irq); | 1937 | enable_irq_wake(udc->udp_irq); |
1856 | 1938 | ||
1857 | udc->active_suspend = wake; | 1939 | udc->active_suspend = wake; |
1858 | if (udc->board.vbus_pin > 0 && wake) | 1940 | if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled && wake) |
1859 | enable_irq_wake(udc->board.vbus_pin); | 1941 | enable_irq_wake(udc->board.vbus_pin); |
1860 | return 0; | 1942 | return 0; |
1861 | } | 1943 | } |
@@ -1863,15 +1945,20 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) | |||
1863 | static int at91udc_resume(struct platform_device *pdev) | 1945 | static int at91udc_resume(struct platform_device *pdev) |
1864 | { | 1946 | { |
1865 | struct at91_udc *udc = platform_get_drvdata(pdev); | 1947 | struct at91_udc *udc = platform_get_drvdata(pdev); |
1948 | unsigned long flags; | ||
1866 | 1949 | ||
1867 | if (udc->board.vbus_pin > 0 && udc->active_suspend) | 1950 | if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled && |
1951 | udc->active_suspend) | ||
1868 | disable_irq_wake(udc->board.vbus_pin); | 1952 | disable_irq_wake(udc->board.vbus_pin); |
1869 | 1953 | ||
1870 | /* maybe reconnect to host; if so, clocks on */ | 1954 | /* maybe reconnect to host; if so, clocks on */ |
1871 | if (udc->active_suspend) | 1955 | if (udc->active_suspend) |
1872 | disable_irq_wake(udc->udp_irq); | 1956 | disable_irq_wake(udc->udp_irq); |
1873 | else | 1957 | else { |
1958 | spin_lock_irqsave(&udc->lock, flags); | ||
1874 | pullup(udc, 1); | 1959 | pullup(udc, 1); |
1960 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1961 | } | ||
1875 | return 0; | 1962 | return 0; |
1876 | } | 1963 | } |
1877 | #else | 1964 | #else |
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index c65d62295890..108ca54f9092 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h | |||
@@ -144,6 +144,9 @@ struct at91_udc { | |||
144 | struct proc_dir_entry *pde; | 144 | struct proc_dir_entry *pde; |
145 | void __iomem *udp_baseaddr; | 145 | void __iomem *udp_baseaddr; |
146 | int udp_irq; | 146 | int udp_irq; |
147 | spinlock_t lock; | ||
148 | struct timer_list vbus_timer; | ||
149 | struct work_struct vbus_timer_work; | ||
147 | }; | 150 | }; |
148 | 151 | ||
149 | static inline struct at91_udc *to_udc(struct usb_gadget *g) | 152 | static inline struct at91_udc *to_udc(struct usb_gadget *g) |
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c index 38226e9a371d..95dd4662d6a8 100644 --- a/drivers/usb/gadget/f_eem.c +++ b/drivers/usb/gadget/f_eem.c | |||
@@ -469,8 +469,7 @@ static int eem_unwrap(struct gether *port, | |||
469 | crc = get_unaligned_le32(skb->data + len | 469 | crc = get_unaligned_le32(skb->data + len |
470 | - ETH_FCS_LEN); | 470 | - ETH_FCS_LEN); |
471 | crc2 = ~crc32_le(~0, | 471 | crc2 = ~crc32_le(~0, |
472 | skb->data, | 472 | skb->data, len - ETH_FCS_LEN); |
473 | skb->len - ETH_FCS_LEN); | ||
474 | } else { | 473 | } else { |
475 | crc = get_unaligned_be32(skb->data + len | 474 | crc = get_unaligned_be32(skb->data + len |
476 | - ETH_FCS_LEN); | 475 | - ETH_FCS_LEN); |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index d69eccf5f197..2aaa0f75c6cf 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -136,7 +136,7 @@ struct ffs_data { | |||
136 | * handling setup requests immidiatelly user space may be so | 136 | * handling setup requests immidiatelly user space may be so |
137 | * slow that another setup will be sent to the gadget but this | 137 | * slow that another setup will be sent to the gadget but this |
138 | * time not to us but another function and then there could be | 138 | * time not to us but another function and then there could be |
139 | * a race. Is taht the case? Or maybe we can use cdev->req | 139 | * a race. Is that the case? Or maybe we can use cdev->req |
140 | * after all, maybe we just need some spinlock for that? */ | 140 | * after all, maybe we just need some spinlock for that? */ |
141 | struct usb_request *ep0req; /* P: mutex */ | 141 | struct usb_request *ep0req; /* P: mutex */ |
142 | struct completion ep0req_completion; /* P: mutex */ | 142 | struct completion ep0req_completion; /* P: mutex */ |
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 7d05a0be5c60..4ce899c9b165 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -321,8 +321,8 @@ struct fsg_dev; | |||
321 | /* Data shared by all the FSG instances. */ | 321 | /* Data shared by all the FSG instances. */ |
322 | struct fsg_common { | 322 | struct fsg_common { |
323 | struct usb_gadget *gadget; | 323 | struct usb_gadget *gadget; |
324 | struct fsg_dev *fsg; | 324 | struct fsg_dev *fsg, *new_fsg; |
325 | struct fsg_dev *prev_fsg; | 325 | wait_queue_head_t fsg_wait; |
326 | 326 | ||
327 | /* filesem protects: backing files in use */ | 327 | /* filesem protects: backing files in use */ |
328 | struct rw_semaphore filesem; | 328 | struct rw_semaphore filesem; |
@@ -351,7 +351,6 @@ struct fsg_common { | |||
351 | enum fsg_state state; /* For exception handling */ | 351 | enum fsg_state state; /* For exception handling */ |
352 | unsigned int exception_req_tag; | 352 | unsigned int exception_req_tag; |
353 | 353 | ||
354 | u8 config, new_config; | ||
355 | enum data_direction data_dir; | 354 | enum data_direction data_dir; |
356 | u32 data_size; | 355 | u32 data_size; |
357 | u32 data_size_from_cmnd; | 356 | u32 data_size_from_cmnd; |
@@ -595,7 +594,7 @@ static int fsg_setup(struct usb_function *f, | |||
595 | u16 w_value = le16_to_cpu(ctrl->wValue); | 594 | u16 w_value = le16_to_cpu(ctrl->wValue); |
596 | u16 w_length = le16_to_cpu(ctrl->wLength); | 595 | u16 w_length = le16_to_cpu(ctrl->wLength); |
597 | 596 | ||
598 | if (!fsg->common->config) | 597 | if (!fsg_is_set(fsg->common)) |
599 | return -EOPNOTSUPP; | 598 | return -EOPNOTSUPP; |
600 | 599 | ||
601 | switch (ctrl->bRequest) { | 600 | switch (ctrl->bRequest) { |
@@ -2303,24 +2302,20 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep, | |||
2303 | return -ENOMEM; | 2302 | return -ENOMEM; |
2304 | } | 2303 | } |
2305 | 2304 | ||
2306 | /* | 2305 | /* Reset interface setting and re-init endpoint state (toggle etc). */ |
2307 | * Reset interface setting and re-init endpoint state (toggle etc). | 2306 | static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg) |
2308 | * Call with altsetting < 0 to disable the interface. The only other | ||
2309 | * available altsetting is 0, which enables the interface. | ||
2310 | */ | ||
2311 | static int do_set_interface(struct fsg_common *common, int altsetting) | ||
2312 | { | 2307 | { |
2313 | int rc = 0; | 2308 | const struct usb_endpoint_descriptor *d; |
2314 | int i; | 2309 | struct fsg_dev *fsg; |
2315 | const struct usb_endpoint_descriptor *d; | 2310 | int i, rc = 0; |
2316 | 2311 | ||
2317 | if (common->running) | 2312 | if (common->running) |
2318 | DBG(common, "reset interface\n"); | 2313 | DBG(common, "reset interface\n"); |
2319 | 2314 | ||
2320 | reset: | 2315 | reset: |
2321 | /* Deallocate the requests */ | 2316 | /* Deallocate the requests */ |
2322 | if (common->prev_fsg) { | 2317 | if (common->fsg) { |
2323 | struct fsg_dev *fsg = common->prev_fsg; | 2318 | fsg = common->fsg; |
2324 | 2319 | ||
2325 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2320 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { |
2326 | struct fsg_buffhd *bh = &common->buffhds[i]; | 2321 | struct fsg_buffhd *bh = &common->buffhds[i]; |
@@ -2345,88 +2340,53 @@ reset: | |||
2345 | fsg->bulk_out_enabled = 0; | 2340 | fsg->bulk_out_enabled = 0; |
2346 | } | 2341 | } |
2347 | 2342 | ||
2348 | common->prev_fsg = 0; | 2343 | common->fsg = NULL; |
2344 | wake_up(&common->fsg_wait); | ||
2349 | } | 2345 | } |
2350 | 2346 | ||
2351 | common->running = 0; | 2347 | common->running = 0; |
2352 | if (altsetting < 0 || rc != 0) | 2348 | if (!new_fsg || rc) |
2353 | return rc; | 2349 | return rc; |
2354 | 2350 | ||
2355 | DBG(common, "set interface %d\n", altsetting); | 2351 | common->fsg = new_fsg; |
2352 | fsg = common->fsg; | ||
2356 | 2353 | ||
2357 | if (fsg_is_set(common)) { | 2354 | /* Enable the endpoints */ |
2358 | struct fsg_dev *fsg = common->fsg; | 2355 | d = fsg_ep_desc(common->gadget, |
2359 | common->prev_fsg = common->fsg; | 2356 | &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); |
2357 | rc = enable_endpoint(common, fsg->bulk_in, d); | ||
2358 | if (rc) | ||
2359 | goto reset; | ||
2360 | fsg->bulk_in_enabled = 1; | ||
2361 | |||
2362 | d = fsg_ep_desc(common->gadget, | ||
2363 | &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); | ||
2364 | rc = enable_endpoint(common, fsg->bulk_out, d); | ||
2365 | if (rc) | ||
2366 | goto reset; | ||
2367 | fsg->bulk_out_enabled = 1; | ||
2368 | common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); | ||
2369 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | ||
2360 | 2370 | ||
2361 | /* Enable the endpoints */ | 2371 | /* Allocate the requests */ |
2362 | d = fsg_ep_desc(common->gadget, | 2372 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { |
2363 | &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); | 2373 | struct fsg_buffhd *bh = &common->buffhds[i]; |
2364 | rc = enable_endpoint(common, fsg->bulk_in, d); | 2374 | |
2375 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); | ||
2365 | if (rc) | 2376 | if (rc) |
2366 | goto reset; | 2377 | goto reset; |
2367 | fsg->bulk_in_enabled = 1; | 2378 | rc = alloc_request(common, fsg->bulk_out, &bh->outreq); |
2368 | |||
2369 | d = fsg_ep_desc(common->gadget, | ||
2370 | &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); | ||
2371 | rc = enable_endpoint(common, fsg->bulk_out, d); | ||
2372 | if (rc) | 2379 | if (rc) |
2373 | goto reset; | 2380 | goto reset; |
2374 | fsg->bulk_out_enabled = 1; | 2381 | bh->inreq->buf = bh->outreq->buf = bh->buf; |
2375 | common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); | 2382 | bh->inreq->context = bh->outreq->context = bh; |
2376 | clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); | 2383 | bh->inreq->complete = bulk_in_complete; |
2377 | 2384 | bh->outreq->complete = bulk_out_complete; | |
2378 | /* Allocate the requests */ | ||
2379 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | ||
2380 | struct fsg_buffhd *bh = &common->buffhds[i]; | ||
2381 | |||
2382 | rc = alloc_request(common, fsg->bulk_in, &bh->inreq); | ||
2383 | if (rc) | ||
2384 | goto reset; | ||
2385 | rc = alloc_request(common, fsg->bulk_out, &bh->outreq); | ||
2386 | if (rc) | ||
2387 | goto reset; | ||
2388 | bh->inreq->buf = bh->outreq->buf = bh->buf; | ||
2389 | bh->inreq->context = bh->outreq->context = bh; | ||
2390 | bh->inreq->complete = bulk_in_complete; | ||
2391 | bh->outreq->complete = bulk_out_complete; | ||
2392 | } | ||
2393 | |||
2394 | common->running = 1; | ||
2395 | for (i = 0; i < common->nluns; ++i) | ||
2396 | common->luns[i].unit_attention_data = SS_RESET_OCCURRED; | ||
2397 | return rc; | ||
2398 | } else { | ||
2399 | return -EIO; | ||
2400 | } | ||
2401 | } | ||
2402 | |||
2403 | |||
2404 | /* | ||
2405 | * Change our operational configuration. This code must agree with the code | ||
2406 | * that returns config descriptors, and with interface altsetting code. | ||
2407 | * | ||
2408 | * It's also responsible for power management interactions. Some | ||
2409 | * configurations might not work with our current power sources. | ||
2410 | * For now we just assume the gadget is always self-powered. | ||
2411 | */ | ||
2412 | static int do_set_config(struct fsg_common *common, u8 new_config) | ||
2413 | { | ||
2414 | int rc = 0; | ||
2415 | |||
2416 | /* Disable the single interface */ | ||
2417 | if (common->config != 0) { | ||
2418 | DBG(common, "reset config\n"); | ||
2419 | common->config = 0; | ||
2420 | rc = do_set_interface(common, -1); | ||
2421 | } | 2385 | } |
2422 | 2386 | ||
2423 | /* Enable the interface */ | 2387 | common->running = 1; |
2424 | if (new_config != 0) { | 2388 | for (i = 0; i < common->nluns; ++i) |
2425 | common->config = new_config; | 2389 | common->luns[i].unit_attention_data = SS_RESET_OCCURRED; |
2426 | rc = do_set_interface(common, 0); | ||
2427 | if (rc != 0) | ||
2428 | common->config = 0; /* Reset on errors */ | ||
2429 | } | ||
2430 | return rc; | 2390 | return rc; |
2431 | } | 2391 | } |
2432 | 2392 | ||
@@ -2437,9 +2397,7 @@ static int do_set_config(struct fsg_common *common, u8 new_config) | |||
2437 | static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | 2397 | static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) |
2438 | { | 2398 | { |
2439 | struct fsg_dev *fsg = fsg_from_func(f); | 2399 | struct fsg_dev *fsg = fsg_from_func(f); |
2440 | fsg->common->prev_fsg = fsg->common->fsg; | 2400 | fsg->common->new_fsg = fsg; |
2441 | fsg->common->fsg = fsg; | ||
2442 | fsg->common->new_config = 1; | ||
2443 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); | 2401 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); |
2444 | return 0; | 2402 | return 0; |
2445 | } | 2403 | } |
@@ -2447,9 +2405,7 @@ static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
2447 | static void fsg_disable(struct usb_function *f) | 2405 | static void fsg_disable(struct usb_function *f) |
2448 | { | 2406 | { |
2449 | struct fsg_dev *fsg = fsg_from_func(f); | 2407 | struct fsg_dev *fsg = fsg_from_func(f); |
2450 | fsg->common->prev_fsg = fsg->common->fsg; | 2408 | fsg->common->new_fsg = NULL; |
2451 | fsg->common->fsg = fsg; | ||
2452 | fsg->common->new_config = 0; | ||
2453 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); | 2409 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); |
2454 | } | 2410 | } |
2455 | 2411 | ||
@@ -2459,19 +2415,17 @@ static void fsg_disable(struct usb_function *f) | |||
2459 | static void handle_exception(struct fsg_common *common) | 2415 | static void handle_exception(struct fsg_common *common) |
2460 | { | 2416 | { |
2461 | siginfo_t info; | 2417 | siginfo_t info; |
2462 | int sig; | ||
2463 | int i; | 2418 | int i; |
2464 | struct fsg_buffhd *bh; | 2419 | struct fsg_buffhd *bh; |
2465 | enum fsg_state old_state; | 2420 | enum fsg_state old_state; |
2466 | u8 new_config; | ||
2467 | struct fsg_lun *curlun; | 2421 | struct fsg_lun *curlun; |
2468 | unsigned int exception_req_tag; | 2422 | unsigned int exception_req_tag; |
2469 | int rc; | ||
2470 | 2423 | ||
2471 | /* Clear the existing signals. Anything but SIGUSR1 is converted | 2424 | /* Clear the existing signals. Anything but SIGUSR1 is converted |
2472 | * into a high-priority EXIT exception. */ | 2425 | * into a high-priority EXIT exception. */ |
2473 | for (;;) { | 2426 | for (;;) { |
2474 | sig = dequeue_signal_lock(current, ¤t->blocked, &info); | 2427 | int sig = |
2428 | dequeue_signal_lock(current, ¤t->blocked, &info); | ||
2475 | if (!sig) | 2429 | if (!sig) |
2476 | break; | 2430 | break; |
2477 | if (sig != SIGUSR1) { | 2431 | if (sig != SIGUSR1) { |
@@ -2482,7 +2436,7 @@ static void handle_exception(struct fsg_common *common) | |||
2482 | } | 2436 | } |
2483 | 2437 | ||
2484 | /* Cancel all the pending transfers */ | 2438 | /* Cancel all the pending transfers */ |
2485 | if (fsg_is_set(common)) { | 2439 | if (likely(common->fsg)) { |
2486 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { | 2440 | for (i = 0; i < FSG_NUM_BUFFERS; ++i) { |
2487 | bh = &common->buffhds[i]; | 2441 | bh = &common->buffhds[i]; |
2488 | if (bh->inreq_busy) | 2442 | if (bh->inreq_busy) |
@@ -2523,7 +2477,6 @@ static void handle_exception(struct fsg_common *common) | |||
2523 | common->next_buffhd_to_fill = &common->buffhds[0]; | 2477 | common->next_buffhd_to_fill = &common->buffhds[0]; |
2524 | common->next_buffhd_to_drain = &common->buffhds[0]; | 2478 | common->next_buffhd_to_drain = &common->buffhds[0]; |
2525 | exception_req_tag = common->exception_req_tag; | 2479 | exception_req_tag = common->exception_req_tag; |
2526 | new_config = common->new_config; | ||
2527 | old_state = common->state; | 2480 | old_state = common->state; |
2528 | 2481 | ||
2529 | if (old_state == FSG_STATE_ABORT_BULK_OUT) | 2482 | if (old_state == FSG_STATE_ABORT_BULK_OUT) |
@@ -2573,12 +2526,12 @@ static void handle_exception(struct fsg_common *common) | |||
2573 | break; | 2526 | break; |
2574 | 2527 | ||
2575 | case FSG_STATE_CONFIG_CHANGE: | 2528 | case FSG_STATE_CONFIG_CHANGE: |
2576 | rc = do_set_config(common, new_config); | 2529 | do_set_interface(common, common->new_fsg); |
2577 | break; | 2530 | break; |
2578 | 2531 | ||
2579 | case FSG_STATE_EXIT: | 2532 | case FSG_STATE_EXIT: |
2580 | case FSG_STATE_TERMINATED: | 2533 | case FSG_STATE_TERMINATED: |
2581 | do_set_config(common, 0); /* Free resources */ | 2534 | do_set_interface(common, NULL); /* Free resources */ |
2582 | spin_lock_irq(&common->lock); | 2535 | spin_lock_irq(&common->lock); |
2583 | common->state = FSG_STATE_TERMINATED; /* Stop the thread */ | 2536 | common->state = FSG_STATE_TERMINATED; /* Stop the thread */ |
2584 | spin_unlock_irq(&common->lock); | 2537 | spin_unlock_irq(&common->lock); |
@@ -2863,6 +2816,7 @@ buffhds_first_it: | |||
2863 | goto error_release; | 2816 | goto error_release; |
2864 | } | 2817 | } |
2865 | init_completion(&common->thread_notifier); | 2818 | init_completion(&common->thread_notifier); |
2819 | init_waitqueue_head(&common->fsg_wait); | ||
2866 | #undef OR | 2820 | #undef OR |
2867 | 2821 | ||
2868 | 2822 | ||
@@ -2957,9 +2911,17 @@ static void fsg_common_release(struct kref *ref) | |||
2957 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) | 2911 | static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) |
2958 | { | 2912 | { |
2959 | struct fsg_dev *fsg = fsg_from_func(f); | 2913 | struct fsg_dev *fsg = fsg_from_func(f); |
2914 | struct fsg_common *common = fsg->common; | ||
2960 | 2915 | ||
2961 | DBG(fsg, "unbind\n"); | 2916 | DBG(fsg, "unbind\n"); |
2962 | fsg_common_put(fsg->common); | 2917 | if (fsg->common->fsg == fsg) { |
2918 | fsg->common->new_fsg = NULL; | ||
2919 | raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE); | ||
2920 | /* FIXME: make interruptible or killable somehow? */ | ||
2921 | wait_event(common->fsg_wait, common->fsg != fsg); | ||
2922 | } | ||
2923 | |||
2924 | fsg_common_put(common); | ||
2963 | usb_free_descriptors(fsg->function.descriptors); | 2925 | usb_free_descriptors(fsg->function.descriptors); |
2964 | usb_free_descriptors(fsg->function.hs_descriptors); | 2926 | usb_free_descriptors(fsg->function.hs_descriptors); |
2965 | kfree(fsg); | 2927 | kfree(fsg); |
@@ -2970,7 +2932,6 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | |||
2970 | { | 2932 | { |
2971 | struct fsg_dev *fsg = fsg_from_func(f); | 2933 | struct fsg_dev *fsg = fsg_from_func(f); |
2972 | struct usb_gadget *gadget = c->cdev->gadget; | 2934 | struct usb_gadget *gadget = c->cdev->gadget; |
2973 | int rc; | ||
2974 | int i; | 2935 | int i; |
2975 | struct usb_ep *ep; | 2936 | struct usb_ep *ep; |
2976 | 2937 | ||
@@ -2996,6 +2957,11 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | |||
2996 | ep->driver_data = fsg->common; /* claim the endpoint */ | 2957 | ep->driver_data = fsg->common; /* claim the endpoint */ |
2997 | fsg->bulk_out = ep; | 2958 | fsg->bulk_out = ep; |
2998 | 2959 | ||
2960 | /* Copy descriptors */ | ||
2961 | f->descriptors = usb_copy_descriptors(fsg_fs_function); | ||
2962 | if (unlikely(!f->descriptors)) | ||
2963 | return -ENOMEM; | ||
2964 | |||
2999 | if (gadget_is_dualspeed(gadget)) { | 2965 | if (gadget_is_dualspeed(gadget)) { |
3000 | /* Assume endpoint addresses are the same for both speeds */ | 2966 | /* Assume endpoint addresses are the same for both speeds */ |
3001 | fsg_hs_bulk_in_desc.bEndpointAddress = | 2967 | fsg_hs_bulk_in_desc.bEndpointAddress = |
@@ -3003,16 +2969,17 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) | |||
3003 | fsg_hs_bulk_out_desc.bEndpointAddress = | 2969 | fsg_hs_bulk_out_desc.bEndpointAddress = |
3004 | fsg_fs_bulk_out_desc.bEndpointAddress; | 2970 | fsg_fs_bulk_out_desc.bEndpointAddress; |
3005 | f->hs_descriptors = usb_copy_descriptors(fsg_hs_function); | 2971 | f->hs_descriptors = usb_copy_descriptors(fsg_hs_function); |
3006 | if (unlikely(!f->hs_descriptors)) | 2972 | if (unlikely(!f->hs_descriptors)) { |
2973 | usb_free_descriptors(f->descriptors); | ||
3007 | return -ENOMEM; | 2974 | return -ENOMEM; |
2975 | } | ||
3008 | } | 2976 | } |
3009 | 2977 | ||
3010 | return 0; | 2978 | return 0; |
3011 | 2979 | ||
3012 | autoconf_fail: | 2980 | autoconf_fail: |
3013 | ERROR(fsg, "unable to autoconfigure all endpoints\n"); | 2981 | ERROR(fsg, "unable to autoconfigure all endpoints\n"); |
3014 | rc = -ENOTSUPP; | 2982 | return -ENOTSUPP; |
3015 | return rc; | ||
3016 | } | 2983 | } |
3017 | 2984 | ||
3018 | 2985 | ||
@@ -3036,11 +3003,6 @@ static int fsg_add(struct usb_composite_dev *cdev, | |||
3036 | 3003 | ||
3037 | fsg->function.name = FSG_DRIVER_DESC; | 3004 | fsg->function.name = FSG_DRIVER_DESC; |
3038 | fsg->function.strings = fsg_strings_array; | 3005 | fsg->function.strings = fsg_strings_array; |
3039 | fsg->function.descriptors = usb_copy_descriptors(fsg_fs_function); | ||
3040 | if (unlikely(!fsg->function.descriptors)) { | ||
3041 | rc = -ENOMEM; | ||
3042 | goto error_free_fsg; | ||
3043 | } | ||
3044 | fsg->function.bind = fsg_bind; | 3006 | fsg->function.bind = fsg_bind; |
3045 | fsg->function.unbind = fsg_unbind; | 3007 | fsg->function.unbind = fsg_unbind; |
3046 | fsg->function.setup = fsg_setup; | 3008 | fsg->function.setup = fsg_setup; |
@@ -3056,19 +3018,9 @@ static int fsg_add(struct usb_composite_dev *cdev, | |||
3056 | 3018 | ||
3057 | rc = usb_add_function(c, &fsg->function); | 3019 | rc = usb_add_function(c, &fsg->function); |
3058 | if (unlikely(rc)) | 3020 | if (unlikely(rc)) |
3059 | goto error_free_all; | 3021 | kfree(fsg); |
3060 | 3022 | else | |
3061 | fsg_common_get(fsg->common); | 3023 | fsg_common_get(fsg->common); |
3062 | return 0; | ||
3063 | |||
3064 | error_free_all: | ||
3065 | usb_free_descriptors(fsg->function.descriptors); | ||
3066 | /* fsg_bind() might have copied those; or maybe not? who cares | ||
3067 | * -- free it just in case. */ | ||
3068 | usb_free_descriptors(fsg->function.hs_descriptors); | ||
3069 | error_free_fsg: | ||
3070 | kfree(fsg); | ||
3071 | |||
3072 | return rc; | 3024 | return rc; |
3073 | } | 3025 | } |
3074 | 3026 | ||
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c index fc2611f8b326..dbe6db0184fd 100644 --- a/drivers/usb/gadget/f_uvc.c +++ b/drivers/usb/gadget/f_uvc.c | |||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | #include "uvc.h" | 29 | #include "uvc.h" |
30 | 30 | ||
31 | unsigned int uvc_trace_param; | 31 | unsigned int uvc_gadget_trace_param; |
32 | 32 | ||
33 | /* -------------------------------------------------------------------------- | 33 | /* -------------------------------------------------------------------------- |
34 | * Function descriptors | 34 | * Function descriptors |
@@ -656,6 +656,6 @@ error: | |||
656 | return ret; | 656 | return ret; |
657 | } | 657 | } |
658 | 658 | ||
659 | module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR); | 659 | module_param_named(trace, uvc_gadget_trace_param, uint, S_IRUGO|S_IWUSR); |
660 | MODULE_PARM_DESC(trace, "Trace level bitmask"); | 660 | MODULE_PARM_DESC(trace, "Trace level bitmask"); |
661 | 661 | ||
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c index d0b8bde59e59..eafa6d2c5ed7 100644 --- a/drivers/usb/gadget/fsl_mxc_udc.c +++ b/drivers/usb/gadget/fsl_mxc_udc.c | |||
@@ -30,7 +30,7 @@ int fsl_udc_clk_init(struct platform_device *pdev) | |||
30 | 30 | ||
31 | pdata = pdev->dev.platform_data; | 31 | pdata = pdev->dev.platform_data; |
32 | 32 | ||
33 | if (!cpu_is_mx35()) { | 33 | if (!cpu_is_mx35() && !cpu_is_mx25()) { |
34 | mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb"); | 34 | mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb"); |
35 | if (IS_ERR(mxc_ahb_clk)) | 35 | if (IS_ERR(mxc_ahb_clk)) |
36 | return PTR_ERR(mxc_ahb_clk); | 36 | return PTR_ERR(mxc_ahb_clk); |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index 4b0e4a040d6f..d1af253a9105 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -392,6 +392,17 @@ static int __gfs_do_config(struct usb_configuration *c, | |||
392 | if (unlikely(ret < 0)) | 392 | if (unlikely(ret < 0)) |
393 | return ret; | 393 | return ret; |
394 | 394 | ||
395 | /* After previous do_configs there may be some invalid | ||
396 | * pointers in c->interface array. This happens every time | ||
397 | * a user space function with fewer interfaces than a user | ||
398 | * space function that was run before the new one is run. The | ||
399 | * compasit's set_config() assumes that if there is no more | ||
400 | * then MAX_CONFIG_INTERFACES interfaces in a configuration | ||
401 | * then there is a NULL pointer after the last interface in | ||
402 | * c->interface array. We need to make sure this is true. */ | ||
403 | if (c->next_interface_id < ARRAY_SIZE(c->interface)) | ||
404 | c->interface[c->next_interface_id] = NULL; | ||
405 | |||
395 | return 0; | 406 | return 0; |
396 | } | 407 | } |
397 | 408 | ||
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 43abf55d8c60..4c3ac5c42237 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -82,7 +82,7 @@ static struct class *usb_gadget_class; | |||
82 | struct printer_dev { | 82 | struct printer_dev { |
83 | spinlock_t lock; /* lock this structure */ | 83 | spinlock_t lock; /* lock this structure */ |
84 | /* lock buffer lists during read/write calls */ | 84 | /* lock buffer lists during read/write calls */ |
85 | spinlock_t lock_printer_io; | 85 | struct mutex lock_printer_io; |
86 | struct usb_gadget *gadget; | 86 | struct usb_gadget *gadget; |
87 | struct usb_request *req; /* for control responses */ | 87 | struct usb_request *req; /* for control responses */ |
88 | u8 config; | 88 | u8 config; |
@@ -567,7 +567,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | |||
567 | 567 | ||
568 | DBG(dev, "printer_read trying to read %d bytes\n", (int)len); | 568 | DBG(dev, "printer_read trying to read %d bytes\n", (int)len); |
569 | 569 | ||
570 | spin_lock(&dev->lock_printer_io); | 570 | mutex_lock(&dev->lock_printer_io); |
571 | spin_lock_irqsave(&dev->lock, flags); | 571 | spin_lock_irqsave(&dev->lock, flags); |
572 | 572 | ||
573 | /* We will use this flag later to check if a printer reset happened | 573 | /* We will use this flag later to check if a printer reset happened |
@@ -601,7 +601,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | |||
601 | * call or not. | 601 | * call or not. |
602 | */ | 602 | */ |
603 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | 603 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { |
604 | spin_unlock(&dev->lock_printer_io); | 604 | mutex_unlock(&dev->lock_printer_io); |
605 | return -EAGAIN; | 605 | return -EAGAIN; |
606 | } | 606 | } |
607 | 607 | ||
@@ -648,7 +648,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | |||
648 | if (dev->reset_printer) { | 648 | if (dev->reset_printer) { |
649 | list_add(¤t_rx_req->list, &dev->rx_reqs); | 649 | list_add(¤t_rx_req->list, &dev->rx_reqs); |
650 | spin_unlock_irqrestore(&dev->lock, flags); | 650 | spin_unlock_irqrestore(&dev->lock, flags); |
651 | spin_unlock(&dev->lock_printer_io); | 651 | mutex_unlock(&dev->lock_printer_io); |
652 | return -EAGAIN; | 652 | return -EAGAIN; |
653 | } | 653 | } |
654 | 654 | ||
@@ -673,7 +673,7 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) | |||
673 | dev->current_rx_buf = current_rx_buf; | 673 | dev->current_rx_buf = current_rx_buf; |
674 | 674 | ||
675 | spin_unlock_irqrestore(&dev->lock, flags); | 675 | spin_unlock_irqrestore(&dev->lock, flags); |
676 | spin_unlock(&dev->lock_printer_io); | 676 | mutex_unlock(&dev->lock_printer_io); |
677 | 677 | ||
678 | DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); | 678 | DBG(dev, "printer_read returned %d bytes\n", (int)bytes_copied); |
679 | 679 | ||
@@ -697,7 +697,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
697 | if (len == 0) | 697 | if (len == 0) |
698 | return -EINVAL; | 698 | return -EINVAL; |
699 | 699 | ||
700 | spin_lock(&dev->lock_printer_io); | 700 | mutex_lock(&dev->lock_printer_io); |
701 | spin_lock_irqsave(&dev->lock, flags); | 701 | spin_lock_irqsave(&dev->lock, flags); |
702 | 702 | ||
703 | /* Check if a printer reset happens while we have interrupts on */ | 703 | /* Check if a printer reset happens while we have interrupts on */ |
@@ -713,7 +713,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
713 | * a NON-Blocking call or not. | 713 | * a NON-Blocking call or not. |
714 | */ | 714 | */ |
715 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { | 715 | if (fd->f_flags & (O_NONBLOCK|O_NDELAY)) { |
716 | spin_unlock(&dev->lock_printer_io); | 716 | mutex_unlock(&dev->lock_printer_io); |
717 | return -EAGAIN; | 717 | return -EAGAIN; |
718 | } | 718 | } |
719 | 719 | ||
@@ -752,7 +752,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
752 | 752 | ||
753 | if (copy_from_user(req->buf, buf, size)) { | 753 | if (copy_from_user(req->buf, buf, size)) { |
754 | list_add(&req->list, &dev->tx_reqs); | 754 | list_add(&req->list, &dev->tx_reqs); |
755 | spin_unlock(&dev->lock_printer_io); | 755 | mutex_unlock(&dev->lock_printer_io); |
756 | return bytes_copied; | 756 | return bytes_copied; |
757 | } | 757 | } |
758 | 758 | ||
@@ -766,14 +766,14 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
766 | if (dev->reset_printer) { | 766 | if (dev->reset_printer) { |
767 | list_add(&req->list, &dev->tx_reqs); | 767 | list_add(&req->list, &dev->tx_reqs); |
768 | spin_unlock_irqrestore(&dev->lock, flags); | 768 | spin_unlock_irqrestore(&dev->lock, flags); |
769 | spin_unlock(&dev->lock_printer_io); | 769 | mutex_unlock(&dev->lock_printer_io); |
770 | return -EAGAIN; | 770 | return -EAGAIN; |
771 | } | 771 | } |
772 | 772 | ||
773 | if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { | 773 | if (usb_ep_queue(dev->in_ep, req, GFP_ATOMIC)) { |
774 | list_add(&req->list, &dev->tx_reqs); | 774 | list_add(&req->list, &dev->tx_reqs); |
775 | spin_unlock_irqrestore(&dev->lock, flags); | 775 | spin_unlock_irqrestore(&dev->lock, flags); |
776 | spin_unlock(&dev->lock_printer_io); | 776 | mutex_unlock(&dev->lock_printer_io); |
777 | return -EAGAIN; | 777 | return -EAGAIN; |
778 | } | 778 | } |
779 | 779 | ||
@@ -782,7 +782,7 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) | |||
782 | } | 782 | } |
783 | 783 | ||
784 | spin_unlock_irqrestore(&dev->lock, flags); | 784 | spin_unlock_irqrestore(&dev->lock, flags); |
785 | spin_unlock(&dev->lock_printer_io); | 785 | mutex_unlock(&dev->lock_printer_io); |
786 | 786 | ||
787 | DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); | 787 | DBG(dev, "printer_write sent %d bytes\n", (int)bytes_copied); |
788 | 788 | ||
@@ -820,11 +820,11 @@ printer_poll(struct file *fd, poll_table *wait) | |||
820 | unsigned long flags; | 820 | unsigned long flags; |
821 | int status = 0; | 821 | int status = 0; |
822 | 822 | ||
823 | spin_lock(&dev->lock_printer_io); | 823 | mutex_lock(&dev->lock_printer_io); |
824 | spin_lock_irqsave(&dev->lock, flags); | 824 | spin_lock_irqsave(&dev->lock, flags); |
825 | setup_rx_reqs(dev); | 825 | setup_rx_reqs(dev); |
826 | spin_unlock_irqrestore(&dev->lock, flags); | 826 | spin_unlock_irqrestore(&dev->lock, flags); |
827 | spin_unlock(&dev->lock_printer_io); | 827 | mutex_unlock(&dev->lock_printer_io); |
828 | 828 | ||
829 | poll_wait(fd, &dev->rx_wait, wait); | 829 | poll_wait(fd, &dev->rx_wait, wait); |
830 | poll_wait(fd, &dev->tx_wait, wait); | 830 | poll_wait(fd, &dev->tx_wait, wait); |
@@ -1461,7 +1461,7 @@ autoconf_fail: | |||
1461 | } | 1461 | } |
1462 | 1462 | ||
1463 | spin_lock_init(&dev->lock); | 1463 | spin_lock_init(&dev->lock); |
1464 | spin_lock_init(&dev->lock_printer_io); | 1464 | mutex_init(&dev->lock_printer_io); |
1465 | INIT_LIST_HEAD(&dev->tx_reqs); | 1465 | INIT_LIST_HEAD(&dev->tx_reqs); |
1466 | INIT_LIST_HEAD(&dev->tx_reqs_active); | 1466 | INIT_LIST_HEAD(&dev->tx_reqs_active); |
1467 | INIT_LIST_HEAD(&dev->rx_reqs); | 1467 | INIT_LIST_HEAD(&dev->rx_reqs); |
@@ -1594,7 +1594,7 @@ cleanup(void) | |||
1594 | { | 1594 | { |
1595 | int status; | 1595 | int status; |
1596 | 1596 | ||
1597 | spin_lock(&usb_printer_gadget.lock_printer_io); | 1597 | mutex_lock(&usb_printer_gadget.lock_printer_io); |
1598 | class_destroy(usb_gadget_class); | 1598 | class_destroy(usb_gadget_class); |
1599 | unregister_chrdev_region(g_printer_devno, 2); | 1599 | unregister_chrdev_region(g_printer_devno, 2); |
1600 | 1600 | ||
@@ -1602,6 +1602,6 @@ cleanup(void) | |||
1602 | if (status) | 1602 | if (status) |
1603 | ERROR(dev, "usb_gadget_unregister_driver %x\n", status); | 1603 | ERROR(dev, "usb_gadget_unregister_driver %x\n", status); |
1604 | 1604 | ||
1605 | spin_unlock(&usb_printer_gadget.lock_printer_io); | 1605 | mutex_unlock(&usb_printer_gadget.lock_printer_io); |
1606 | } | 1606 | } |
1607 | module_exit(cleanup); | 1607 | module_exit(cleanup); |
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c index 85b0d8921eae..980762453a9c 100644 --- a/drivers/usb/gadget/pxa27x_udc.c +++ b/drivers/usb/gadget/pxa27x_udc.c | |||
@@ -2561,7 +2561,7 @@ static void pxa_udc_shutdown(struct platform_device *_dev) | |||
2561 | udc_disable(udc); | 2561 | udc_disable(udc); |
2562 | } | 2562 | } |
2563 | 2563 | ||
2564 | #ifdef CONFIG_CPU_PXA27x | 2564 | #ifdef CONFIG_PXA27x |
2565 | extern void pxa27x_clear_otgph(void); | 2565 | extern void pxa27x_clear_otgph(void); |
2566 | #else | 2566 | #else |
2567 | #define pxa27x_clear_otgph() do {} while (0) | 2567 | #define pxa27x_clear_otgph() do {} while (0) |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index d5f4c1d45c97..ea2b3c7ebee5 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -735,6 +735,10 @@ static void s3c2410_udc_handle_ep0_idle(struct s3c2410_udc *dev, | |||
735 | else | 735 | else |
736 | dev->ep0state = EP0_OUT_DATA_PHASE; | 736 | dev->ep0state = EP0_OUT_DATA_PHASE; |
737 | 737 | ||
738 | if (!dev->driver) | ||
739 | return; | ||
740 | |||
741 | /* deliver the request to the gadget driver */ | ||
738 | ret = dev->driver->setup(&dev->gadget, crq); | 742 | ret = dev->driver->setup(&dev->gadget, crq); |
739 | if (ret < 0) { | 743 | if (ret < 0) { |
740 | if (dev->req_config) { | 744 | if (dev->req_config) { |
@@ -1700,9 +1704,13 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1700 | if (!driver || driver != udc->driver || !driver->unbind) | 1704 | if (!driver || driver != udc->driver || !driver->unbind) |
1701 | return -EINVAL; | 1705 | return -EINVAL; |
1702 | 1706 | ||
1703 | dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", | 1707 | dprintk(DEBUG_NORMAL, "usb_gadget_unregister_driver() '%s'\n", |
1704 | driver->driver.name); | 1708 | driver->driver.name); |
1705 | 1709 | ||
1710 | /* report disconnect */ | ||
1711 | if (driver->disconnect) | ||
1712 | driver->disconnect(&udc->gadget); | ||
1713 | |||
1706 | driver->unbind(&udc->gadget); | 1714 | driver->unbind(&udc->gadget); |
1707 | 1715 | ||
1708 | device_del(&udc->gadget.dev); | 1716 | device_del(&udc->gadget.dev); |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 16bdf77f582a..3e8dcb5455e3 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -536,17 +536,11 @@ recycle: | |||
536 | list_move(&req->list, &port->read_pool); | 536 | list_move(&req->list, &port->read_pool); |
537 | } | 537 | } |
538 | 538 | ||
539 | /* Push from tty to ldisc; this is immediate with low_latency, and | 539 | /* Push from tty to ldisc; without low_latency set this is handled by |
540 | * may trigger callbacks to this driver ... so drop the spinlock. | 540 | * a workqueue, so we won't get callbacks and can hold port_lock |
541 | */ | 541 | */ |
542 | if (tty && do_push) { | 542 | if (tty && do_push) { |
543 | spin_unlock_irq(&port->port_lock); | ||
544 | tty_flip_buffer_push(tty); | 543 | tty_flip_buffer_push(tty); |
545 | wake_up_interruptible(&tty->read_wait); | ||
546 | spin_lock_irq(&port->port_lock); | ||
547 | |||
548 | /* tty may have been closed */ | ||
549 | tty = port->port_tty; | ||
550 | } | 544 | } |
551 | 545 | ||
552 | 546 | ||
@@ -784,11 +778,6 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
784 | port->open_count = 1; | 778 | port->open_count = 1; |
785 | port->openclose = false; | 779 | port->openclose = false; |
786 | 780 | ||
787 | /* low_latency means ldiscs work in tasklet context, without | ||
788 | * needing a workqueue schedule ... easier to keep up. | ||
789 | */ | ||
790 | tty->low_latency = 1; | ||
791 | |||
792 | /* if connected, start the I/O stream */ | 781 | /* if connected, start the I/O stream */ |
793 | if (port->port_usb) { | 782 | if (port->port_usb) { |
794 | struct gserial *gser = port->port_usb; | 783 | struct gserial *gser = port->port_usb; |
@@ -1195,6 +1184,7 @@ void gserial_cleanup(void) | |||
1195 | n_ports = 0; | 1184 | n_ports = 0; |
1196 | 1185 | ||
1197 | tty_unregister_driver(gs_tty_driver); | 1186 | tty_unregister_driver(gs_tty_driver); |
1187 | put_tty_driver(gs_tty_driver); | ||
1198 | gs_tty_driver = NULL; | 1188 | gs_tty_driver = NULL; |
1199 | 1189 | ||
1200 | pr_debug("%s: cleaned up ttyGS* support\n", __func__); | 1190 | pr_debug("%s: cleaned up ttyGS* support\n", __func__); |
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h index 0a705e63c936..e92454cddd7d 100644 --- a/drivers/usb/gadget/uvc.h +++ b/drivers/usb/gadget/uvc.h | |||
@@ -107,11 +107,11 @@ struct uvc_streaming_control { | |||
107 | #define UVC_WARN_MINMAX 0 | 107 | #define UVC_WARN_MINMAX 0 |
108 | #define UVC_WARN_PROBE_DEF 1 | 108 | #define UVC_WARN_PROBE_DEF 1 |
109 | 109 | ||
110 | extern unsigned int uvc_trace_param; | 110 | extern unsigned int uvc_gadget_trace_param; |
111 | 111 | ||
112 | #define uvc_trace(flag, msg...) \ | 112 | #define uvc_trace(flag, msg...) \ |
113 | do { \ | 113 | do { \ |
114 | if (uvc_trace_param & flag) \ | 114 | if (uvc_gadget_trace_param & flag) \ |
115 | printk(KERN_DEBUG "uvcvideo: " msg); \ | 115 | printk(KERN_DEBUG "uvcvideo: " msg); \ |
116 | } while (0) | 116 | } while (0) |
117 | 117 | ||
@@ -220,16 +220,10 @@ struct uvc_file_handle | |||
220 | #define to_uvc_file_handle(handle) \ | 220 | #define to_uvc_file_handle(handle) \ |
221 | container_of(handle, struct uvc_file_handle, vfh) | 221 | container_of(handle, struct uvc_file_handle, vfh) |
222 | 222 | ||
223 | extern struct v4l2_file_operations uvc_v4l2_fops; | ||
224 | |||
225 | /* ------------------------------------------------------------------------ | 223 | /* ------------------------------------------------------------------------ |
226 | * Functions | 224 | * Functions |
227 | */ | 225 | */ |
228 | 226 | ||
229 | extern int uvc_video_enable(struct uvc_video *video, int enable); | ||
230 | extern int uvc_video_init(struct uvc_video *video); | ||
231 | extern int uvc_video_pump(struct uvc_video *video); | ||
232 | |||
233 | extern void uvc_endpoint_stream(struct uvc_device *dev); | 227 | extern void uvc_endpoint_stream(struct uvc_device *dev); |
234 | 228 | ||
235 | extern void uvc_function_connect(struct uvc_device *uvc); | 229 | extern void uvc_function_connect(struct uvc_device *uvc); |
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c index 43891991bf21..f7395ac5dc17 100644 --- a/drivers/usb/gadget/uvc_queue.c +++ b/drivers/usb/gadget/uvc_queue.c | |||
@@ -78,7 +78,8 @@ | |||
78 | * | 78 | * |
79 | */ | 79 | */ |
80 | 80 | ||
81 | void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | 81 | static void |
82 | uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | ||
82 | { | 83 | { |
83 | mutex_init(&queue->mutex); | 84 | mutex_init(&queue->mutex); |
84 | spin_lock_init(&queue->irqlock); | 85 | spin_lock_init(&queue->irqlock); |
@@ -88,6 +89,28 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | |||
88 | } | 89 | } |
89 | 90 | ||
90 | /* | 91 | /* |
92 | * Free the video buffers. | ||
93 | * | ||
94 | * This function must be called with the queue lock held. | ||
95 | */ | ||
96 | static int uvc_free_buffers(struct uvc_video_queue *queue) | ||
97 | { | ||
98 | unsigned int i; | ||
99 | |||
100 | for (i = 0; i < queue->count; ++i) { | ||
101 | if (queue->buffer[i].vma_use_count != 0) | ||
102 | return -EBUSY; | ||
103 | } | ||
104 | |||
105 | if (queue->count) { | ||
106 | vfree(queue->mem); | ||
107 | queue->count = 0; | ||
108 | } | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
91 | * Allocate the video buffers. | 114 | * Allocate the video buffers. |
92 | * | 115 | * |
93 | * Pages are reserved to make sure they will not be swapped, as they will be | 116 | * Pages are reserved to make sure they will not be swapped, as they will be |
@@ -95,8 +118,9 @@ void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) | |||
95 | * | 118 | * |
96 | * Buffers will be individually mapped, so they must all be page aligned. | 119 | * Buffers will be individually mapped, so they must all be page aligned. |
97 | */ | 120 | */ |
98 | int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, | 121 | static int |
99 | unsigned int buflength) | 122 | uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, |
123 | unsigned int buflength) | ||
100 | { | 124 | { |
101 | unsigned int bufsize = PAGE_ALIGN(buflength); | 125 | unsigned int bufsize = PAGE_ALIGN(buflength); |
102 | unsigned int i; | 126 | unsigned int i; |
@@ -150,28 +174,6 @@ done: | |||
150 | return ret; | 174 | return ret; |
151 | } | 175 | } |
152 | 176 | ||
153 | /* | ||
154 | * Free the video buffers. | ||
155 | * | ||
156 | * This function must be called with the queue lock held. | ||
157 | */ | ||
158 | int uvc_free_buffers(struct uvc_video_queue *queue) | ||
159 | { | ||
160 | unsigned int i; | ||
161 | |||
162 | for (i = 0; i < queue->count; ++i) { | ||
163 | if (queue->buffer[i].vma_use_count != 0) | ||
164 | return -EBUSY; | ||
165 | } | ||
166 | |||
167 | if (queue->count) { | ||
168 | vfree(queue->mem); | ||
169 | queue->count = 0; | ||
170 | } | ||
171 | |||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static void __uvc_query_buffer(struct uvc_buffer *buf, | 177 | static void __uvc_query_buffer(struct uvc_buffer *buf, |
176 | struct v4l2_buffer *v4l2_buf) | 178 | struct v4l2_buffer *v4l2_buf) |
177 | { | 179 | { |
@@ -195,8 +197,8 @@ static void __uvc_query_buffer(struct uvc_buffer *buf, | |||
195 | } | 197 | } |
196 | } | 198 | } |
197 | 199 | ||
198 | int uvc_query_buffer(struct uvc_video_queue *queue, | 200 | static int |
199 | struct v4l2_buffer *v4l2_buf) | 201 | uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) |
200 | { | 202 | { |
201 | int ret = 0; | 203 | int ret = 0; |
202 | 204 | ||
@@ -217,8 +219,8 @@ done: | |||
217 | * Queue a video buffer. Attempting to queue a buffer that has already been | 219 | * Queue a video buffer. Attempting to queue a buffer that has already been |
218 | * queued will return -EINVAL. | 220 | * queued will return -EINVAL. |
219 | */ | 221 | */ |
220 | int uvc_queue_buffer(struct uvc_video_queue *queue, | 222 | static int |
221 | struct v4l2_buffer *v4l2_buf) | 223 | uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) |
222 | { | 224 | { |
223 | struct uvc_buffer *buf; | 225 | struct uvc_buffer *buf; |
224 | unsigned long flags; | 226 | unsigned long flags; |
@@ -298,8 +300,9 @@ static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) | |||
298 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is | 300 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is |
299 | * available. | 301 | * available. |
300 | */ | 302 | */ |
301 | int uvc_dequeue_buffer(struct uvc_video_queue *queue, | 303 | static int |
302 | struct v4l2_buffer *v4l2_buf, int nonblocking) | 304 | uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf, |
305 | int nonblocking) | ||
303 | { | 306 | { |
304 | struct uvc_buffer *buf; | 307 | struct uvc_buffer *buf; |
305 | int ret = 0; | 308 | int ret = 0; |
@@ -359,8 +362,9 @@ done: | |||
359 | * This function implements video queue polling and is intended to be used by | 362 | * This function implements video queue polling and is intended to be used by |
360 | * the device poll handler. | 363 | * the device poll handler. |
361 | */ | 364 | */ |
362 | unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, | 365 | static unsigned int |
363 | poll_table *wait) | 366 | uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, |
367 | poll_table *wait) | ||
364 | { | 368 | { |
365 | struct uvc_buffer *buf; | 369 | struct uvc_buffer *buf; |
366 | unsigned int mask = 0; | 370 | unsigned int mask = 0; |
@@ -407,7 +411,8 @@ static struct vm_operations_struct uvc_vm_ops = { | |||
407 | * This function implements video buffer memory mapping and is intended to be | 411 | * This function implements video buffer memory mapping and is intended to be |
408 | * used by the device mmap handler. | 412 | * used by the device mmap handler. |
409 | */ | 413 | */ |
410 | int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) | 414 | static int |
415 | uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) | ||
411 | { | 416 | { |
412 | struct uvc_buffer *uninitialized_var(buffer); | 417 | struct uvc_buffer *uninitialized_var(buffer); |
413 | struct page *page; | 418 | struct page *page; |
@@ -458,6 +463,42 @@ done: | |||
458 | } | 463 | } |
459 | 464 | ||
460 | /* | 465 | /* |
466 | * Cancel the video buffers queue. | ||
467 | * | ||
468 | * Cancelling the queue marks all buffers on the irq queue as erroneous, | ||
469 | * wakes them up and removes them from the queue. | ||
470 | * | ||
471 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will | ||
472 | * fail with -ENODEV. | ||
473 | * | ||
474 | * This function acquires the irq spinlock and can be called from interrupt | ||
475 | * context. | ||
476 | */ | ||
477 | static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | ||
478 | { | ||
479 | struct uvc_buffer *buf; | ||
480 | unsigned long flags; | ||
481 | |||
482 | spin_lock_irqsave(&queue->irqlock, flags); | ||
483 | while (!list_empty(&queue->irqqueue)) { | ||
484 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
485 | queue); | ||
486 | list_del(&buf->queue); | ||
487 | buf->state = UVC_BUF_STATE_ERROR; | ||
488 | wake_up(&buf->wait); | ||
489 | } | ||
490 | /* This must be protected by the irqlock spinlock to avoid race | ||
491 | * conditions between uvc_queue_buffer and the disconnection event that | ||
492 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not | ||
493 | * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED | ||
494 | * state outside the queue code. | ||
495 | */ | ||
496 | if (disconnect) | ||
497 | queue->flags |= UVC_QUEUE_DISCONNECTED; | ||
498 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
499 | } | ||
500 | |||
501 | /* | ||
461 | * Enable or disable the video buffers queue. | 502 | * Enable or disable the video buffers queue. |
462 | * | 503 | * |
463 | * The queue must be enabled before starting video acquisition and must be | 504 | * The queue must be enabled before starting video acquisition and must be |
@@ -474,7 +515,7 @@ done: | |||
474 | * This function can't be called from interrupt context. Use | 515 | * This function can't be called from interrupt context. Use |
475 | * uvc_queue_cancel() instead. | 516 | * uvc_queue_cancel() instead. |
476 | */ | 517 | */ |
477 | int uvc_queue_enable(struct uvc_video_queue *queue, int enable) | 518 | static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) |
478 | { | 519 | { |
479 | unsigned int i; | 520 | unsigned int i; |
480 | int ret = 0; | 521 | int ret = 0; |
@@ -503,44 +544,8 @@ done: | |||
503 | return ret; | 544 | return ret; |
504 | } | 545 | } |
505 | 546 | ||
506 | /* | 547 | static struct uvc_buffer * |
507 | * Cancel the video buffers queue. | 548 | uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) |
508 | * | ||
509 | * Cancelling the queue marks all buffers on the irq queue as erroneous, | ||
510 | * wakes them up and removes them from the queue. | ||
511 | * | ||
512 | * If the disconnect parameter is set, further calls to uvc_queue_buffer will | ||
513 | * fail with -ENODEV. | ||
514 | * | ||
515 | * This function acquires the irq spinlock and can be called from interrupt | ||
516 | * context. | ||
517 | */ | ||
518 | void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | ||
519 | { | ||
520 | struct uvc_buffer *buf; | ||
521 | unsigned long flags; | ||
522 | |||
523 | spin_lock_irqsave(&queue->irqlock, flags); | ||
524 | while (!list_empty(&queue->irqqueue)) { | ||
525 | buf = list_first_entry(&queue->irqqueue, struct uvc_buffer, | ||
526 | queue); | ||
527 | list_del(&buf->queue); | ||
528 | buf->state = UVC_BUF_STATE_ERROR; | ||
529 | wake_up(&buf->wait); | ||
530 | } | ||
531 | /* This must be protected by the irqlock spinlock to avoid race | ||
532 | * conditions between uvc_queue_buffer and the disconnection event that | ||
533 | * could result in an interruptible wait in uvc_dequeue_buffer. Do not | ||
534 | * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED | ||
535 | * state outside the queue code. | ||
536 | */ | ||
537 | if (disconnect) | ||
538 | queue->flags |= UVC_QUEUE_DISCONNECTED; | ||
539 | spin_unlock_irqrestore(&queue->irqlock, flags); | ||
540 | } | ||
541 | |||
542 | struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
543 | struct uvc_buffer *buf) | ||
544 | { | 549 | { |
545 | struct uvc_buffer *nextbuf; | 550 | struct uvc_buffer *nextbuf; |
546 | unsigned long flags; | 551 | unsigned long flags; |
@@ -568,7 +573,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |||
568 | return nextbuf; | 573 | return nextbuf; |
569 | } | 574 | } |
570 | 575 | ||
571 | struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) | 576 | static struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) |
572 | { | 577 | { |
573 | struct uvc_buffer *buf = NULL; | 578 | struct uvc_buffer *buf = NULL; |
574 | 579 | ||
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h index 7f5a33fe7ae2..1812a8ecc5d0 100644 --- a/drivers/usb/gadget/uvc_queue.h +++ b/drivers/usb/gadget/uvc_queue.h | |||
@@ -58,30 +58,10 @@ struct uvc_video_queue { | |||
58 | struct list_head irqqueue; | 58 | struct list_head irqqueue; |
59 | }; | 59 | }; |
60 | 60 | ||
61 | extern void uvc_queue_init(struct uvc_video_queue *queue, | ||
62 | enum v4l2_buf_type type); | ||
63 | extern int uvc_alloc_buffers(struct uvc_video_queue *queue, | ||
64 | unsigned int nbuffers, unsigned int buflength); | ||
65 | extern int uvc_free_buffers(struct uvc_video_queue *queue); | ||
66 | extern int uvc_query_buffer(struct uvc_video_queue *queue, | ||
67 | struct v4l2_buffer *v4l2_buf); | ||
68 | extern int uvc_queue_buffer(struct uvc_video_queue *queue, | ||
69 | struct v4l2_buffer *v4l2_buf); | ||
70 | extern int uvc_dequeue_buffer(struct uvc_video_queue *queue, | ||
71 | struct v4l2_buffer *v4l2_buf, int nonblocking); | ||
72 | extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable); | ||
73 | extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); | ||
74 | extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | ||
75 | struct uvc_buffer *buf); | ||
76 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | ||
77 | struct file *file, poll_table *wait); | ||
78 | extern int uvc_queue_mmap(struct uvc_video_queue *queue, | ||
79 | struct vm_area_struct *vma); | ||
80 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | 61 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
81 | { | 62 | { |
82 | return queue->flags & UVC_QUEUE_STREAMING; | 63 | return queue->flags & UVC_QUEUE_STREAMING; |
83 | } | 64 | } |
84 | extern struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue); | ||
85 | 65 | ||
86 | #endif /* __KERNEL__ */ | 66 | #endif /* __KERNEL__ */ |
87 | 67 | ||
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c index a7989f29837e..2dcffdac86d2 100644 --- a/drivers/usb/gadget/uvc_v4l2.c +++ b/drivers/usb/gadget/uvc_v4l2.c | |||
@@ -363,7 +363,7 @@ uvc_v4l2_poll(struct file *file, poll_table *wait) | |||
363 | return mask; | 363 | return mask; |
364 | } | 364 | } |
365 | 365 | ||
366 | struct v4l2_file_operations uvc_v4l2_fops = { | 366 | static struct v4l2_file_operations uvc_v4l2_fops = { |
367 | .owner = THIS_MODULE, | 367 | .owner = THIS_MODULE, |
368 | .open = uvc_v4l2_open, | 368 | .open = uvc_v4l2_open, |
369 | .release = uvc_v4l2_release, | 369 | .release = uvc_v4l2_release, |
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c index de8cbc46518d..b08f35438d70 100644 --- a/drivers/usb/gadget/uvc_video.c +++ b/drivers/usb/gadget/uvc_video.c | |||
@@ -271,7 +271,7 @@ error: | |||
271 | * This function fills the available USB requests (listed in req_free) with | 271 | * This function fills the available USB requests (listed in req_free) with |
272 | * video data from the queued buffers. | 272 | * video data from the queued buffers. |
273 | */ | 273 | */ |
274 | int | 274 | static int |
275 | uvc_video_pump(struct uvc_video *video) | 275 | uvc_video_pump(struct uvc_video *video) |
276 | { | 276 | { |
277 | struct usb_request *req; | 277 | struct usb_request *req; |
@@ -328,7 +328,7 @@ uvc_video_pump(struct uvc_video *video) | |||
328 | /* | 328 | /* |
329 | * Enable or disable the video stream. | 329 | * Enable or disable the video stream. |
330 | */ | 330 | */ |
331 | int | 331 | static int |
332 | uvc_video_enable(struct uvc_video *video, int enable) | 332 | uvc_video_enable(struct uvc_video *video, int enable) |
333 | { | 333 | { |
334 | unsigned int i; | 334 | unsigned int i; |
@@ -367,7 +367,7 @@ uvc_video_enable(struct uvc_video *video, int enable) | |||
367 | /* | 367 | /* |
368 | * Initialize the UVC video stream. | 368 | * Initialize the UVC video stream. |
369 | */ | 369 | */ |
370 | int | 370 | static int |
371 | uvc_video_init(struct uvc_video *video) | 371 | uvc_video_init(struct uvc_video *video) |
372 | { | 372 | { |
373 | INIT_LIST_HEAD(&video->req_free); | 373 | INIT_LIST_HEAD(&video->req_free); |
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c index 417fd6887698..f5f3030cc416 100644 --- a/drivers/usb/gadget/webcam.c +++ b/drivers/usb/gadget/webcam.c | |||
@@ -28,10 +28,10 @@ | |||
28 | #include "config.c" | 28 | #include "config.c" |
29 | #include "epautoconf.c" | 29 | #include "epautoconf.c" |
30 | 30 | ||
31 | #include "f_uvc.c" | ||
32 | #include "uvc_queue.c" | 31 | #include "uvc_queue.c" |
33 | #include "uvc_v4l2.c" | ||
34 | #include "uvc_video.c" | 32 | #include "uvc_video.c" |
33 | #include "uvc_v4l2.c" | ||
34 | #include "f_uvc.c" | ||
35 | 35 | ||
36 | /* -------------------------------------------------------------------------- | 36 | /* -------------------------------------------------------------------------- |
37 | * Device descriptor | 37 | * Device descriptor |