diff options
Diffstat (limited to 'drivers/usb/gadget')
65 files changed, 8854 insertions, 9357 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 2633f7595116..bddc8fd9a7be 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -123,13 +123,7 @@ config USB_GADGET_STORAGE_NUM_BUFFERS | |||
123 | # - discrete ones (including all PCI-only controllers) | 123 | # - discrete ones (including all PCI-only controllers) |
124 | # - debug/dummy gadget+hcd is last. | 124 | # - debug/dummy gadget+hcd is last. |
125 | # | 125 | # |
126 | choice | 126 | menu "USB Peripheral Controller" |
127 | prompt "USB Peripheral Controller" | ||
128 | help | ||
129 | A USB device uses a controller to talk to its host. | ||
130 | Systems should have only one such upstream link. | ||
131 | Many controller drivers are platform-specific; these | ||
132 | often need board-specific hooks. | ||
133 | 127 | ||
134 | # | 128 | # |
135 | # Integrated controllers | 129 | # Integrated controllers |
@@ -147,6 +141,17 @@ config USB_AT91 | |||
147 | dynamically linked module called "at91_udc" and force all | 141 | dynamically linked module called "at91_udc" and force all |
148 | gadget drivers to also be dynamically linked. | 142 | gadget drivers to also be dynamically linked. |
149 | 143 | ||
144 | config USB_LPC32XX | ||
145 | tristate "LPC32XX USB Peripheral Controller" | ||
146 | depends on ARCH_LPC32XX | ||
147 | select USB_ISP1301 | ||
148 | help | ||
149 | This option selects the USB device controller in the LPC32xx SoC. | ||
150 | |||
151 | Say "y" to link the driver statically, or "m" to build a | ||
152 | dynamically linked module called "lpc32xx_udc" and force all | ||
153 | gadget drivers to also be dynamically linked. | ||
154 | |||
150 | config USB_ATMEL_USBA | 155 | config USB_ATMEL_USBA |
151 | tristate "Atmel USBA" | 156 | tristate "Atmel USBA" |
152 | select USB_GADGET_DUALSPEED | 157 | select USB_GADGET_DUALSPEED |
@@ -161,7 +166,7 @@ config USB_FSL_USB2 | |||
161 | select USB_GADGET_DUALSPEED | 166 | select USB_GADGET_DUALSPEED |
162 | select USB_FSL_MPH_DR_OF if OF | 167 | select USB_FSL_MPH_DR_OF if OF |
163 | help | 168 | help |
164 | Some of Freescale PowerPC processors have a High Speed | 169 | Some of Freescale PowerPC and i.MX processors have a High Speed |
165 | Dual-Role(DR) USB controller, which supports device mode. | 170 | Dual-Role(DR) USB controller, which supports device mode. |
166 | 171 | ||
167 | The number of programmable endpoints is different through | 172 | The number of programmable endpoints is different through |
@@ -373,18 +378,6 @@ config USB_FSL_QE | |||
373 | Set CONFIG_USB_GADGET to "m" to build this driver as a | 378 | Set CONFIG_USB_GADGET to "m" to build this driver as a |
374 | dynamically linked module called "fsl_qe_udc". | 379 | dynamically linked module called "fsl_qe_udc". |
375 | 380 | ||
376 | config USB_CI13XXX_PCI | ||
377 | tristate "MIPS USB CI13xxx PCI UDC" | ||
378 | depends on PCI | ||
379 | select USB_GADGET_DUALSPEED | ||
380 | help | ||
381 | MIPS USB IP core family device controller | ||
382 | Currently it only supports IP part number CI13412 | ||
383 | |||
384 | Say "y" to link the driver statically, or "m" to build a | ||
385 | dynamically linked module called "ci13xxx_udc" and force all | ||
386 | gadget drivers to also be dynamically linked. | ||
387 | |||
388 | config USB_NET2272 | 381 | config USB_NET2272 |
389 | tristate "PLX NET2272" | 382 | tristate "PLX NET2272" |
390 | select USB_GADGET_DUALSPEED | 383 | select USB_GADGET_DUALSPEED |
@@ -438,22 +431,6 @@ config USB_GOKU | |||
438 | dynamically linked module called "goku_udc" and to force all | 431 | dynamically linked module called "goku_udc" and to force all |
439 | gadget drivers to also be dynamically linked. | 432 | gadget drivers to also be dynamically linked. |
440 | 433 | ||
441 | config USB_LANGWELL | ||
442 | tristate "Intel Langwell USB Device Controller" | ||
443 | depends on PCI | ||
444 | depends on !PHYS_ADDR_T_64BIT | ||
445 | select USB_GADGET_DUALSPEED | ||
446 | help | ||
447 | Intel Langwell USB Device Controller is a High-Speed USB | ||
448 | On-The-Go device controller. | ||
449 | |||
450 | The number of programmable endpoints is different through | ||
451 | controller revision. | ||
452 | |||
453 | Say "y" to link the driver statically, or "m" to build a | ||
454 | dynamically linked module called "langwell_udc" and force all | ||
455 | gadget drivers to also be dynamically linked. | ||
456 | |||
457 | config USB_EG20T | 434 | config USB_EG20T |
458 | tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" | 435 | tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7831) UDC" |
459 | depends on PCI | 436 | depends on PCI |
@@ -477,23 +454,6 @@ config USB_EG20T | |||
477 | ML7213/ML7831 is companion chip for Intel Atom E6xx series. | 454 | ML7213/ML7831 is companion chip for Intel Atom E6xx series. |
478 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. | 455 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. |
479 | 456 | ||
480 | config USB_CI13XXX_MSM | ||
481 | tristate "MIPS USB CI13xxx for MSM" | ||
482 | depends on ARCH_MSM | ||
483 | select USB_GADGET_DUALSPEED | ||
484 | select USB_MSM_OTG | ||
485 | help | ||
486 | MSM SoC has chipidea USB controller. This driver uses | ||
487 | ci13xxx_udc core. | ||
488 | This driver depends on OTG driver for PHY initialization, | ||
489 | clock management, powering up VBUS, and power management. | ||
490 | This driver is not supported on boards like trout which | ||
491 | has an external PHY. | ||
492 | |||
493 | Say "y" to link the driver statically, or "m" to build a | ||
494 | dynamically linked module called "ci13xxx_msm" and force all | ||
495 | gadget drivers to also be dynamically linked. | ||
496 | |||
497 | # | 457 | # |
498 | # LAST -- dummy/emulated controller | 458 | # LAST -- dummy/emulated controller |
499 | # | 459 | # |
@@ -525,7 +485,7 @@ config USB_DUMMY_HCD | |||
525 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears | 485 | # NOTE: Please keep dummy_hcd LAST so that "real hardware" appears |
526 | # first and will be selected by default. | 486 | # first and will be selected by default. |
527 | 487 | ||
528 | endchoice | 488 | endmenu |
529 | 489 | ||
530 | # Selected by UDC drivers that support high-speed operation. | 490 | # Selected by UDC drivers that support high-speed operation. |
531 | config USB_GADGET_DUALSPEED | 491 | config USB_GADGET_DUALSPEED |
@@ -798,6 +758,16 @@ config USB_MASS_STORAGE | |||
798 | Say "y" to link the driver statically, or "m" to build | 758 | Say "y" to link the driver statically, or "m" to build |
799 | a dynamically linked module called "g_mass_storage". | 759 | a dynamically linked module called "g_mass_storage". |
800 | 760 | ||
761 | config USB_GADGET_TARGET | ||
762 | tristate "USB Gadget Target Fabric Module" | ||
763 | depends on TARGET_CORE | ||
764 | help | ||
765 | This fabric is an USB gadget. Two USB protocols are supported that is | ||
766 | BBB or BOT (Bulk Only Transport) and UAS (USB Attached SCSI). BOT is | ||
767 | advertised on alternative interface 0 (primary) and UAS is on | ||
768 | alternative interface 1. Both protocols can work on USB2.0 and USB3.0. | ||
769 | UAS utilizes the USB 3.0 feature called streams support. | ||
770 | |||
801 | config USB_G_SERIAL | 771 | config USB_G_SERIAL |
802 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" | 772 | tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" |
803 | help | 773 | help |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index b7f6eefc3927..1811513f1c27 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -22,14 +22,12 @@ fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o | |||
22 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 22 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
23 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | 23 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o |
24 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 24 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
25 | obj-$(CONFIG_USB_CI13XXX_PCI) += ci13xxx_pci.o | ||
26 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o | 25 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o |
27 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o | 26 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o |
28 | obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o | 27 | obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o |
29 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | 28 | obj-$(CONFIG_USB_EG20T) += pch_udc.o |
30 | obj-$(CONFIG_USB_MV_UDC) += mv_udc.o | 29 | obj-$(CONFIG_USB_MV_UDC) += mv_udc.o |
31 | mv_udc-y := mv_udc_core.o | 30 | mv_udc-y := mv_udc_core.o |
32 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o | ||
33 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | 31 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o |
34 | 32 | ||
35 | # | 33 | # |
@@ -52,6 +50,7 @@ g_nokia-y := nokia.o | |||
52 | g_webcam-y := webcam.o | 50 | g_webcam-y := webcam.o |
53 | g_ncm-y := ncm.o | 51 | g_ncm-y := ncm.o |
54 | g_acm_ms-y := acm_ms.o | 52 | g_acm_ms-y := acm_ms.o |
53 | g_tcm_usb_gadget-y := tcm_usb_gadget.o | ||
55 | 54 | ||
56 | obj-$(CONFIG_USB_ZERO) += g_zero.o | 55 | obj-$(CONFIG_USB_ZERO) += g_zero.o |
57 | obj-$(CONFIG_USB_AUDIO) += g_audio.o | 56 | obj-$(CONFIG_USB_AUDIO) += g_audio.o |
@@ -71,3 +70,4 @@ obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o | |||
71 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o | 70 | obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o |
72 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o | 71 | obj-$(CONFIG_USB_G_NCM) += g_ncm.o |
73 | obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o | 72 | obj-$(CONFIG_USB_G_ACM_MS) += g_acm_ms.o |
73 | obj-$(CONFIG_USB_GADGET_TARGET) += tcm_usb_gadget.o | ||
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c index 77779271f487..187d21181cd5 100644 --- a/drivers/usb/gadget/amd5536udc.c +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -333,7 +333,7 @@ udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc) | |||
333 | return -ESHUTDOWN; | 333 | return -ESHUTDOWN; |
334 | 334 | ||
335 | spin_lock_irqsave(&dev->lock, iflags); | 335 | spin_lock_irqsave(&dev->lock, iflags); |
336 | ep->desc = desc; | 336 | ep->ep.desc = desc; |
337 | 337 | ||
338 | ep->halted = 0; | 338 | ep->halted = 0; |
339 | 339 | ||
@@ -442,7 +442,6 @@ static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep) | |||
442 | u32 tmp; | 442 | u32 tmp; |
443 | 443 | ||
444 | VDBG(ep->dev, "ep-%d reset\n", ep->num); | 444 | VDBG(ep->dev, "ep-%d reset\n", ep->num); |
445 | ep->desc = NULL; | ||
446 | ep->ep.desc = NULL; | 445 | ep->ep.desc = NULL; |
447 | ep->ep.ops = &udc_ep_ops; | 446 | ep->ep.ops = &udc_ep_ops; |
448 | INIT_LIST_HEAD(&ep->queue); | 447 | INIT_LIST_HEAD(&ep->queue); |
@@ -489,7 +488,7 @@ static int udc_ep_disable(struct usb_ep *usbep) | |||
489 | return -EINVAL; | 488 | return -EINVAL; |
490 | 489 | ||
491 | ep = container_of(usbep, struct udc_ep, ep); | 490 | ep = container_of(usbep, struct udc_ep, ep); |
492 | if (usbep->name == ep0_string || !ep->desc) | 491 | if (usbep->name == ep0_string || !ep->ep.desc) |
493 | return -EINVAL; | 492 | return -EINVAL; |
494 | 493 | ||
495 | DBG(ep->dev, "Disable ep-%d\n", ep->num); | 494 | DBG(ep->dev, "Disable ep-%d\n", ep->num); |
@@ -1066,7 +1065,7 @@ udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp) | |||
1066 | return -EINVAL; | 1065 | return -EINVAL; |
1067 | 1066 | ||
1068 | ep = container_of(usbep, struct udc_ep, ep); | 1067 | ep = container_of(usbep, struct udc_ep, ep); |
1069 | if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) | 1068 | if (!ep->ep.desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) |
1070 | return -EINVAL; | 1069 | return -EINVAL; |
1071 | 1070 | ||
1072 | VDBG(ep->dev, "udc_queue(): ep%d-in=%d\n", ep->num, ep->in); | 1071 | VDBG(ep->dev, "udc_queue(): ep%d-in=%d\n", ep->num, ep->in); |
@@ -1257,7 +1256,7 @@ static int udc_dequeue(struct usb_ep *usbep, struct usb_request *usbreq) | |||
1257 | unsigned long iflags; | 1256 | unsigned long iflags; |
1258 | 1257 | ||
1259 | ep = container_of(usbep, struct udc_ep, ep); | 1258 | ep = container_of(usbep, struct udc_ep, ep); |
1260 | if (!usbep || !usbreq || (!ep->desc && (ep->num != 0 | 1259 | if (!usbep || !usbreq || (!ep->ep.desc && (ep->num != 0 |
1261 | && ep->num != UDC_EP0OUT_IX))) | 1260 | && ep->num != UDC_EP0OUT_IX))) |
1262 | return -EINVAL; | 1261 | return -EINVAL; |
1263 | 1262 | ||
@@ -1317,7 +1316,7 @@ udc_set_halt(struct usb_ep *usbep, int halt) | |||
1317 | pr_debug("set_halt %s: halt=%d\n", usbep->name, halt); | 1316 | pr_debug("set_halt %s: halt=%d\n", usbep->name, halt); |
1318 | 1317 | ||
1319 | ep = container_of(usbep, struct udc_ep, ep); | 1318 | ep = container_of(usbep, struct udc_ep, ep); |
1320 | if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) | 1319 | if (!ep->ep.desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) |
1321 | return -EINVAL; | 1320 | return -EINVAL; |
1322 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | 1321 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) |
1323 | return -ESHUTDOWN; | 1322 | return -ESHUTDOWN; |
@@ -1539,7 +1538,7 @@ static void udc_setup_endpoints(struct udc *dev) | |||
1539 | * disabling ep interrupts when ENUM interrupt occurs but ep is | 1538 | * disabling ep interrupts when ENUM interrupt occurs but ep is |
1540 | * not enabled by gadget driver | 1539 | * not enabled by gadget driver |
1541 | */ | 1540 | */ |
1542 | if (!ep->desc) | 1541 | if (!ep->ep.desc) |
1543 | ep_init(dev->regs, ep); | 1542 | ep_init(dev->regs, ep); |
1544 | 1543 | ||
1545 | if (use_dma) { | 1544 | if (use_dma) { |
@@ -3402,19 +3401,7 @@ static struct pci_driver udc_pci_driver = { | |||
3402 | .remove = udc_pci_remove, | 3401 | .remove = udc_pci_remove, |
3403 | }; | 3402 | }; |
3404 | 3403 | ||
3405 | /* Inits driver */ | 3404 | module_pci_driver(udc_pci_driver); |
3406 | static int __init init(void) | ||
3407 | { | ||
3408 | return pci_register_driver(&udc_pci_driver); | ||
3409 | } | ||
3410 | module_init(init); | ||
3411 | |||
3412 | /* Cleans driver */ | ||
3413 | static void __exit cleanup(void) | ||
3414 | { | ||
3415 | pci_unregister_driver(&udc_pci_driver); | ||
3416 | } | ||
3417 | module_exit(cleanup); | ||
3418 | 3405 | ||
3419 | MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION); | 3406 | MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION); |
3420 | MODULE_AUTHOR("Thomas Dahlmann"); | 3407 | MODULE_AUTHOR("Thomas Dahlmann"); |
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h index f87e29c65325..14af87d65caa 100644 --- a/drivers/usb/gadget/amd5536udc.h +++ b/drivers/usb/gadget/amd5536udc.h | |||
@@ -512,7 +512,6 @@ struct udc_ep { | |||
512 | 512 | ||
513 | /* queue for requests */ | 513 | /* queue for requests */ |
514 | struct list_head queue; | 514 | struct list_head queue; |
515 | const struct usb_endpoint_descriptor *desc; | ||
516 | unsigned halted; | 515 | unsigned halted; |
517 | unsigned cancel_transfer; | 516 | unsigned cancel_transfer; |
518 | unsigned num : 5, | 517 | unsigned num : 5, |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 9d7bcd910074..1a4430f315c3 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -212,7 +212,7 @@ static int proc_udc_show(struct seq_file *s, void *unused) | |||
212 | if (udc->enabled && udc->vbus) { | 212 | if (udc->enabled && udc->vbus) { |
213 | proc_ep_show(s, &udc->ep[0]); | 213 | proc_ep_show(s, &udc->ep[0]); |
214 | list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { | 214 | list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { |
215 | if (ep->desc) | 215 | if (ep->ep.desc) |
216 | proc_ep_show(s, ep); | 216 | proc_ep_show(s, ep); |
217 | } | 217 | } |
218 | } | 218 | } |
@@ -475,7 +475,7 @@ static int at91_ep_enable(struct usb_ep *_ep, | |||
475 | unsigned long flags; | 475 | unsigned long flags; |
476 | 476 | ||
477 | if (!_ep || !ep | 477 | if (!_ep || !ep |
478 | || !desc || ep->desc | 478 | || !desc || ep->ep.desc |
479 | || _ep->name == ep0name | 479 | || _ep->name == ep0name |
480 | || desc->bDescriptorType != USB_DT_ENDPOINT | 480 | || desc->bDescriptorType != USB_DT_ENDPOINT |
481 | || (maxpacket = usb_endpoint_maxp(desc)) == 0 | 481 | || (maxpacket = usb_endpoint_maxp(desc)) == 0 |
@@ -530,7 +530,7 @@ ok: | |||
530 | tmp |= AT91_UDP_EPEDS; | 530 | tmp |= AT91_UDP_EPEDS; |
531 | __raw_writel(tmp, ep->creg); | 531 | __raw_writel(tmp, ep->creg); |
532 | 532 | ||
533 | ep->desc = desc; | 533 | ep->ep.desc = desc; |
534 | ep->ep.maxpacket = maxpacket; | 534 | ep->ep.maxpacket = maxpacket; |
535 | 535 | ||
536 | /* | 536 | /* |
@@ -558,7 +558,6 @@ static int at91_ep_disable (struct usb_ep * _ep) | |||
558 | nuke(ep, -ESHUTDOWN); | 558 | nuke(ep, -ESHUTDOWN); |
559 | 559 | ||
560 | /* restore the endpoint's pristine config */ | 560 | /* restore the endpoint's pristine config */ |
561 | ep->desc = NULL; | ||
562 | ep->ep.desc = NULL; | 561 | ep->ep.desc = NULL; |
563 | ep->ep.maxpacket = ep->maxpacket; | 562 | ep->ep.maxpacket = ep->maxpacket; |
564 | 563 | ||
@@ -618,7 +617,7 @@ static int at91_ep_queue(struct usb_ep *_ep, | |||
618 | return -EINVAL; | 617 | return -EINVAL; |
619 | } | 618 | } |
620 | 619 | ||
621 | if (!_ep || (!ep->desc && ep->ep.name != ep0name)) { | 620 | if (!_ep || (!ep->ep.desc && ep->ep.name != ep0name)) { |
622 | DBG("invalid ep\n"); | 621 | DBG("invalid ep\n"); |
623 | return -EINVAL; | 622 | return -EINVAL; |
624 | } | 623 | } |
@@ -833,7 +832,7 @@ static void udc_reinit(struct at91_udc *udc) | |||
833 | 832 | ||
834 | if (i != 0) | 833 | if (i != 0) |
835 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 834 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
836 | ep->desc = NULL; | 835 | ep->ep.desc = NULL; |
837 | ep->stopped = 0; | 836 | ep->stopped = 0; |
838 | ep->fifo_bank = 0; | 837 | ep->fifo_bank = 0; |
839 | ep->ep.maxpacket = ep->maxpacket; | 838 | ep->ep.maxpacket = ep->maxpacket; |
@@ -978,18 +977,18 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on) | |||
978 | return 0; | 977 | return 0; |
979 | } | 978 | } |
980 | 979 | ||
981 | static int at91_start(struct usb_gadget_driver *driver, | 980 | static int at91_start(struct usb_gadget *gadget, |
982 | int (*bind)(struct usb_gadget *)); | 981 | struct usb_gadget_driver *driver); |
983 | static int at91_stop(struct usb_gadget_driver *driver); | 982 | static int at91_stop(struct usb_gadget *gadget, |
984 | 983 | struct usb_gadget_driver *driver); | |
985 | static const struct usb_gadget_ops at91_udc_ops = { | 984 | static const struct usb_gadget_ops at91_udc_ops = { |
986 | .get_frame = at91_get_frame, | 985 | .get_frame = at91_get_frame, |
987 | .wakeup = at91_wakeup, | 986 | .wakeup = at91_wakeup, |
988 | .set_selfpowered = at91_set_selfpowered, | 987 | .set_selfpowered = at91_set_selfpowered, |
989 | .vbus_session = at91_vbus_session, | 988 | .vbus_session = at91_vbus_session, |
990 | .pullup = at91_pullup, | 989 | .pullup = at91_pullup, |
991 | .start = at91_start, | 990 | .udc_start = at91_start, |
992 | .stop = at91_stop, | 991 | .udc_stop = at91_stop, |
993 | 992 | ||
994 | /* | 993 | /* |
995 | * VBUS-powered devices may also also want to support bigger | 994 | * VBUS-powered devices may also also want to support bigger |
@@ -1172,7 +1171,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | |||
1172 | | USB_REQ_GET_STATUS: | 1171 | | USB_REQ_GET_STATUS: |
1173 | tmp = w_index & USB_ENDPOINT_NUMBER_MASK; | 1172 | tmp = w_index & USB_ENDPOINT_NUMBER_MASK; |
1174 | ep = &udc->ep[tmp]; | 1173 | ep = &udc->ep[tmp]; |
1175 | if (tmp >= NUM_ENDPOINTS || (tmp && !ep->desc)) | 1174 | if (tmp >= NUM_ENDPOINTS || (tmp && !ep->ep.desc)) |
1176 | goto stall; | 1175 | goto stall; |
1177 | 1176 | ||
1178 | if (tmp) { | 1177 | if (tmp) { |
@@ -1197,7 +1196,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | |||
1197 | ep = &udc->ep[tmp]; | 1196 | ep = &udc->ep[tmp]; |
1198 | if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS) | 1197 | if (w_value != USB_ENDPOINT_HALT || tmp >= NUM_ENDPOINTS) |
1199 | goto stall; | 1198 | goto stall; |
1200 | if (!ep->desc || ep->is_iso) | 1199 | if (!ep->ep.desc || ep->is_iso) |
1201 | goto stall; | 1200 | goto stall; |
1202 | if ((w_index & USB_DIR_IN)) { | 1201 | if ((w_index & USB_DIR_IN)) { |
1203 | if (!ep->is_in) | 1202 | if (!ep->is_in) |
@@ -1218,7 +1217,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) | |||
1218 | goto stall; | 1217 | goto stall; |
1219 | if (tmp == 0) | 1218 | if (tmp == 0) |
1220 | goto succeed; | 1219 | goto succeed; |
1221 | if (!ep->desc || ep->is_iso) | 1220 | if (!ep->ep.desc || ep->is_iso) |
1222 | goto stall; | 1221 | goto stall; |
1223 | if ((w_index & USB_DIR_IN)) { | 1222 | if ((w_index & USB_DIR_IN)) { |
1224 | if (!ep->is_in) | 1223 | if (!ep->is_in) |
@@ -1627,66 +1626,34 @@ static void at91_vbus_timer(unsigned long data) | |||
1627 | schedule_work(&udc->vbus_timer_work); | 1626 | schedule_work(&udc->vbus_timer_work); |
1628 | } | 1627 | } |
1629 | 1628 | ||
1630 | static int at91_start(struct usb_gadget_driver *driver, | 1629 | static int at91_start(struct usb_gadget *gadget, |
1631 | int (*bind)(struct usb_gadget *)) | 1630 | struct usb_gadget_driver *driver) |
1632 | { | 1631 | { |
1633 | struct at91_udc *udc = &controller; | 1632 | struct at91_udc *udc; |
1634 | int retval; | ||
1635 | unsigned long flags; | ||
1636 | |||
1637 | if (!driver | ||
1638 | || driver->max_speed < USB_SPEED_FULL | ||
1639 | || !bind | ||
1640 | || !driver->setup) { | ||
1641 | DBG("bad parameter.\n"); | ||
1642 | return -EINVAL; | ||
1643 | } | ||
1644 | |||
1645 | if (udc->driver) { | ||
1646 | DBG("UDC already has a gadget driver\n"); | ||
1647 | return -EBUSY; | ||
1648 | } | ||
1649 | 1633 | ||
1634 | udc = container_of(gadget, struct at91_udc, gadget); | ||
1650 | udc->driver = driver; | 1635 | udc->driver = driver; |
1651 | udc->gadget.dev.driver = &driver->driver; | 1636 | udc->gadget.dev.driver = &driver->driver; |
1652 | dev_set_drvdata(&udc->gadget.dev, &driver->driver); | 1637 | dev_set_drvdata(&udc->gadget.dev, &driver->driver); |
1653 | udc->enabled = 1; | 1638 | udc->enabled = 1; |
1654 | udc->selfpowered = 1; | 1639 | udc->selfpowered = 1; |
1655 | 1640 | ||
1656 | retval = bind(&udc->gadget); | ||
1657 | if (retval) { | ||
1658 | DBG("bind() returned %d\n", retval); | ||
1659 | udc->driver = NULL; | ||
1660 | udc->gadget.dev.driver = NULL; | ||
1661 | dev_set_drvdata(&udc->gadget.dev, NULL); | ||
1662 | udc->enabled = 0; | ||
1663 | udc->selfpowered = 0; | ||
1664 | return retval; | ||
1665 | } | ||
1666 | |||
1667 | spin_lock_irqsave(&udc->lock, flags); | ||
1668 | pullup(udc, 1); | ||
1669 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1670 | |||
1671 | DBG("bound to %s\n", driver->driver.name); | 1641 | DBG("bound to %s\n", driver->driver.name); |
1672 | return 0; | 1642 | return 0; |
1673 | } | 1643 | } |
1674 | 1644 | ||
1675 | static int at91_stop(struct usb_gadget_driver *driver) | 1645 | static int at91_stop(struct usb_gadget *gadget, |
1646 | struct usb_gadget_driver *driver) | ||
1676 | { | 1647 | { |
1677 | struct at91_udc *udc = &controller; | 1648 | struct at91_udc *udc; |
1678 | unsigned long flags; | 1649 | unsigned long flags; |
1679 | 1650 | ||
1680 | if (!driver || driver != udc->driver || !driver->unbind) | 1651 | udc = container_of(gadget, struct at91_udc, gadget); |
1681 | return -EINVAL; | ||
1682 | |||
1683 | spin_lock_irqsave(&udc->lock, flags); | 1652 | spin_lock_irqsave(&udc->lock, flags); |
1684 | udc->enabled = 0; | 1653 | udc->enabled = 0; |
1685 | at91_udp_write(udc, AT91_UDP_IDR, ~0); | 1654 | at91_udp_write(udc, AT91_UDP_IDR, ~0); |
1686 | pullup(udc, 0); | ||
1687 | spin_unlock_irqrestore(&udc->lock, flags); | 1655 | spin_unlock_irqrestore(&udc->lock, flags); |
1688 | 1656 | ||
1689 | driver->unbind(&udc->gadget); | ||
1690 | udc->gadget.dev.driver = NULL; | 1657 | udc->gadget.dev.driver = NULL; |
1691 | dev_set_drvdata(&udc->gadget.dev, NULL); | 1658 | dev_set_drvdata(&udc->gadget.dev, NULL); |
1692 | udc->driver = NULL; | 1659 | udc->driver = NULL; |
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h index 3c0315b86ace..e647d1c2ada4 100644 --- a/drivers/usb/gadget/at91_udc.h +++ b/drivers/usb/gadget/at91_udc.h | |||
@@ -105,9 +105,6 @@ struct at91_ep { | |||
105 | unsigned is_in:1; | 105 | unsigned is_in:1; |
106 | unsigned is_iso:1; | 106 | unsigned is_iso:1; |
107 | unsigned fifo_bank:1; | 107 | unsigned fifo_bank:1; |
108 | |||
109 | const struct usb_endpoint_descriptor | ||
110 | *desc; | ||
111 | }; | 108 | }; |
112 | 109 | ||
113 | /* | 110 | /* |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 9f98508966d1..e23bf7984aaf 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -599,13 +599,13 @@ usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
599 | 599 | ||
600 | spin_lock_irqsave(&ep->udc->lock, flags); | 600 | spin_lock_irqsave(&ep->udc->lock, flags); |
601 | 601 | ||
602 | if (ep->desc) { | 602 | if (ep->ep.desc) { |
603 | spin_unlock_irqrestore(&ep->udc->lock, flags); | 603 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
604 | DBG(DBG_ERR, "ep%d already enabled\n", ep->index); | 604 | DBG(DBG_ERR, "ep%d already enabled\n", ep->index); |
605 | return -EBUSY; | 605 | return -EBUSY; |
606 | } | 606 | } |
607 | 607 | ||
608 | ep->desc = desc; | 608 | ep->ep.desc = desc; |
609 | ep->ep.maxpacket = maxpacket; | 609 | ep->ep.maxpacket = maxpacket; |
610 | 610 | ||
611 | usba_ep_writel(ep, CFG, ept_cfg); | 611 | usba_ep_writel(ep, CFG, ept_cfg); |
@@ -647,7 +647,7 @@ static int usba_ep_disable(struct usb_ep *_ep) | |||
647 | 647 | ||
648 | spin_lock_irqsave(&udc->lock, flags); | 648 | spin_lock_irqsave(&udc->lock, flags); |
649 | 649 | ||
650 | if (!ep->desc) { | 650 | if (!ep->ep.desc) { |
651 | spin_unlock_irqrestore(&udc->lock, flags); | 651 | spin_unlock_irqrestore(&udc->lock, flags); |
652 | /* REVISIT because this driver disables endpoints in | 652 | /* REVISIT because this driver disables endpoints in |
653 | * reset_all_endpoints() before calling disconnect(), | 653 | * reset_all_endpoints() before calling disconnect(), |
@@ -658,7 +658,6 @@ static int usba_ep_disable(struct usb_ep *_ep) | |||
658 | ep->ep.name); | 658 | ep->ep.name); |
659 | return -EINVAL; | 659 | return -EINVAL; |
660 | } | 660 | } |
661 | ep->desc = NULL; | ||
662 | ep->ep.desc = NULL; | 661 | ep->ep.desc = NULL; |
663 | 662 | ||
664 | list_splice_init(&ep->queue, &req_list); | 663 | list_splice_init(&ep->queue, &req_list); |
@@ -752,7 +751,7 @@ static int queue_dma(struct usba_udc *udc, struct usba_ep *ep, | |||
752 | */ | 751 | */ |
753 | ret = -ESHUTDOWN; | 752 | ret = -ESHUTDOWN; |
754 | spin_lock_irqsave(&udc->lock, flags); | 753 | spin_lock_irqsave(&udc->lock, flags); |
755 | if (ep->desc) { | 754 | if (ep->ep.desc) { |
756 | if (list_empty(&ep->queue)) | 755 | if (list_empty(&ep->queue)) |
757 | submit_request(ep, req); | 756 | submit_request(ep, req); |
758 | 757 | ||
@@ -776,7 +775,8 @@ usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
776 | DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n", | 775 | DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n", |
777 | ep->ep.name, req, _req->length); | 776 | ep->ep.name, req, _req->length); |
778 | 777 | ||
779 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || !ep->desc) | 778 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || |
779 | !ep->ep.desc) | ||
780 | return -ESHUTDOWN; | 780 | return -ESHUTDOWN; |
781 | 781 | ||
782 | req->submitted = 0; | 782 | req->submitted = 0; |
@@ -792,7 +792,7 @@ usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
792 | /* May have received a reset since last time we checked */ | 792 | /* May have received a reset since last time we checked */ |
793 | ret = -ESHUTDOWN; | 793 | ret = -ESHUTDOWN; |
794 | spin_lock_irqsave(&udc->lock, flags); | 794 | spin_lock_irqsave(&udc->lock, flags); |
795 | if (ep->desc) { | 795 | if (ep->ep.desc) { |
796 | list_add_tail(&req->queue, &ep->queue); | 796 | list_add_tail(&req->queue, &ep->queue); |
797 | 797 | ||
798 | if ((!ep_is_control(ep) && ep->is_in) || | 798 | if ((!ep_is_control(ep) && ep->is_in) || |
@@ -905,7 +905,7 @@ static int usba_ep_set_halt(struct usb_ep *_ep, int value) | |||
905 | DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name, | 905 | DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name, |
906 | value ? "set" : "clear"); | 906 | value ? "set" : "clear"); |
907 | 907 | ||
908 | if (!ep->desc) { | 908 | if (!ep->ep.desc) { |
909 | DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n", | 909 | DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n", |
910 | ep->ep.name); | 910 | ep->ep.name); |
911 | return -ENODEV; | 911 | return -ENODEV; |
@@ -1008,16 +1008,16 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) | |||
1008 | return 0; | 1008 | return 0; |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | static int atmel_usba_start(struct usb_gadget_driver *driver, | 1011 | static int atmel_usba_start(struct usb_gadget *gadget, |
1012 | int (*bind)(struct usb_gadget *)); | 1012 | struct usb_gadget_driver *driver); |
1013 | static int atmel_usba_stop(struct usb_gadget_driver *driver); | 1013 | static int atmel_usba_stop(struct usb_gadget *gadget, |
1014 | 1014 | struct usb_gadget_driver *driver); | |
1015 | static const struct usb_gadget_ops usba_udc_ops = { | 1015 | static const struct usb_gadget_ops usba_udc_ops = { |
1016 | .get_frame = usba_udc_get_frame, | 1016 | .get_frame = usba_udc_get_frame, |
1017 | .wakeup = usba_udc_wakeup, | 1017 | .wakeup = usba_udc_wakeup, |
1018 | .set_selfpowered = usba_udc_set_selfpowered, | 1018 | .set_selfpowered = usba_udc_set_selfpowered, |
1019 | .start = atmel_usba_start, | 1019 | .udc_start = atmel_usba_start, |
1020 | .stop = atmel_usba_stop, | 1020 | .udc_stop = atmel_usba_stop, |
1021 | }; | 1021 | }; |
1022 | 1022 | ||
1023 | static struct usb_endpoint_descriptor usba_ep0_desc = { | 1023 | static struct usb_endpoint_descriptor usba_ep0_desc = { |
@@ -1071,7 +1071,7 @@ static void reset_all_endpoints(struct usba_udc *udc) | |||
1071 | * FIXME remove this code ... and retest thoroughly. | 1071 | * FIXME remove this code ... and retest thoroughly. |
1072 | */ | 1072 | */ |
1073 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | 1073 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { |
1074 | if (ep->desc) { | 1074 | if (ep->ep.desc) { |
1075 | spin_unlock(&udc->lock); | 1075 | spin_unlock(&udc->lock); |
1076 | usba_ep_disable(&ep->ep); | 1076 | usba_ep_disable(&ep->ep); |
1077 | spin_lock(&udc->lock); | 1077 | spin_lock(&udc->lock); |
@@ -1089,9 +1089,9 @@ static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex) | |||
1089 | list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { | 1089 | list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { |
1090 | u8 bEndpointAddress; | 1090 | u8 bEndpointAddress; |
1091 | 1091 | ||
1092 | if (!ep->desc) | 1092 | if (!ep->ep.desc) |
1093 | continue; | 1093 | continue; |
1094 | bEndpointAddress = ep->desc->bEndpointAddress; | 1094 | bEndpointAddress = ep->ep.desc->bEndpointAddress; |
1095 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) | 1095 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) |
1096 | continue; | 1096 | continue; |
1097 | if ((bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) | 1097 | if ((bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) |
@@ -1727,7 +1727,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) | |||
1727 | usb_speed_string(udc->gadget.speed)); | 1727 | usb_speed_string(udc->gadget.speed)); |
1728 | 1728 | ||
1729 | ep0 = &usba_ep[0]; | 1729 | ep0 = &usba_ep[0]; |
1730 | ep0->desc = &usba_ep0_desc; | 1730 | ep0->ep.desc = &usba_ep0_desc; |
1731 | ep0->state = WAIT_FOR_SETUP; | 1731 | ep0->state = WAIT_FOR_SETUP; |
1732 | usba_ep_writel(ep0, CFG, | 1732 | usba_ep_writel(ep0, CFG, |
1733 | (USBA_BF(EPT_SIZE, EP0_EPT_SIZE) | 1733 | (USBA_BF(EPT_SIZE, EP0_EPT_SIZE) |
@@ -1795,21 +1795,13 @@ out: | |||
1795 | return IRQ_HANDLED; | 1795 | return IRQ_HANDLED; |
1796 | } | 1796 | } |
1797 | 1797 | ||
1798 | static int atmel_usba_start(struct usb_gadget_driver *driver, | 1798 | static int atmel_usba_start(struct usb_gadget *gadget, |
1799 | int (*bind)(struct usb_gadget *)) | 1799 | struct usb_gadget_driver *driver) |
1800 | { | 1800 | { |
1801 | struct usba_udc *udc = &the_udc; | 1801 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); |
1802 | unsigned long flags; | 1802 | unsigned long flags; |
1803 | int ret; | ||
1804 | |||
1805 | if (!udc->pdev) | ||
1806 | return -ENODEV; | ||
1807 | 1803 | ||
1808 | spin_lock_irqsave(&udc->lock, flags); | 1804 | spin_lock_irqsave(&udc->lock, flags); |
1809 | if (udc->driver) { | ||
1810 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1811 | return -EBUSY; | ||
1812 | } | ||
1813 | 1805 | ||
1814 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; | 1806 | udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; |
1815 | udc->driver = driver; | 1807 | udc->driver = driver; |
@@ -1819,13 +1811,6 @@ static int atmel_usba_start(struct usb_gadget_driver *driver, | |||
1819 | clk_enable(udc->pclk); | 1811 | clk_enable(udc->pclk); |
1820 | clk_enable(udc->hclk); | 1812 | clk_enable(udc->hclk); |
1821 | 1813 | ||
1822 | ret = bind(&udc->gadget); | ||
1823 | if (ret) { | ||
1824 | DBG(DBG_ERR, "Could not bind to driver %s: error %d\n", | ||
1825 | driver->driver.name, ret); | ||
1826 | goto err_driver_bind; | ||
1827 | } | ||
1828 | |||
1829 | DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name); | 1814 | DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name); |
1830 | 1815 | ||
1831 | udc->vbus_prev = 0; | 1816 | udc->vbus_prev = 0; |
@@ -1842,23 +1827,14 @@ static int atmel_usba_start(struct usb_gadget_driver *driver, | |||
1842 | spin_unlock_irqrestore(&udc->lock, flags); | 1827 | spin_unlock_irqrestore(&udc->lock, flags); |
1843 | 1828 | ||
1844 | return 0; | 1829 | return 0; |
1845 | |||
1846 | err_driver_bind: | ||
1847 | udc->driver = NULL; | ||
1848 | udc->gadget.dev.driver = NULL; | ||
1849 | return ret; | ||
1850 | } | 1830 | } |
1851 | 1831 | ||
1852 | static int atmel_usba_stop(struct usb_gadget_driver *driver) | 1832 | static int atmel_usba_stop(struct usb_gadget *gadget, |
1833 | struct usb_gadget_driver *driver) | ||
1853 | { | 1834 | { |
1854 | struct usba_udc *udc = &the_udc; | 1835 | struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); |
1855 | unsigned long flags; | 1836 | unsigned long flags; |
1856 | 1837 | ||
1857 | if (!udc->pdev) | ||
1858 | return -ENODEV; | ||
1859 | if (driver != udc->driver || !driver->unbind) | ||
1860 | return -EINVAL; | ||
1861 | |||
1862 | if (gpio_is_valid(udc->vbus_pin)) | 1838 | if (gpio_is_valid(udc->vbus_pin)) |
1863 | disable_irq(gpio_to_irq(udc->vbus_pin)); | 1839 | disable_irq(gpio_to_irq(udc->vbus_pin)); |
1864 | 1840 | ||
@@ -1871,10 +1847,6 @@ static int atmel_usba_stop(struct usb_gadget_driver *driver) | |||
1871 | toggle_bias(0); | 1847 | toggle_bias(0); |
1872 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); | 1848 | usba_writel(udc, CTRL, USBA_DISABLE_MASK); |
1873 | 1849 | ||
1874 | if (udc->driver->disconnect) | ||
1875 | udc->driver->disconnect(&udc->gadget); | ||
1876 | |||
1877 | driver->unbind(&udc->gadget); | ||
1878 | udc->gadget.dev.driver = NULL; | 1850 | udc->gadget.dev.driver = NULL; |
1879 | udc->driver = NULL; | 1851 | udc->driver = NULL; |
1880 | 1852 | ||
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h index 88a2e07a11a8..9791259cbda7 100644 --- a/drivers/usb/gadget/atmel_usba_udc.h +++ b/drivers/usb/gadget/atmel_usba_udc.h | |||
@@ -280,7 +280,6 @@ struct usba_ep { | |||
280 | struct usba_udc *udc; | 280 | struct usba_udc *udc; |
281 | 281 | ||
282 | struct list_head queue; | 282 | struct list_head queue; |
283 | const struct usb_endpoint_descriptor *desc; | ||
284 | 283 | ||
285 | u16 fifo_size; | 284 | u16 fifo_size; |
286 | u8 nr_banks; | 285 | u8 nr_banks; |
diff --git a/drivers/usb/gadget/ci13xxx_msm.c b/drivers/usb/gadget/ci13xxx_msm.c deleted file mode 100644 index d07e44c05e9b..000000000000 --- a/drivers/usb/gadget/ci13xxx_msm.c +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | /* Copyright (c) 2010, Code Aurora Forum. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | */ | ||
7 | |||
8 | #include <linux/module.h> | ||
9 | #include <linux/platform_device.h> | ||
10 | #include <linux/pm_runtime.h> | ||
11 | #include <linux/usb/msm_hsusb_hw.h> | ||
12 | #include <linux/usb/ulpi.h> | ||
13 | |||
14 | #include "ci13xxx_udc.c" | ||
15 | |||
16 | #define MSM_USB_BASE (udc->regs) | ||
17 | |||
18 | static irqreturn_t msm_udc_irq(int irq, void *data) | ||
19 | { | ||
20 | return udc_irq(); | ||
21 | } | ||
22 | |||
23 | static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event) | ||
24 | { | ||
25 | struct device *dev = udc->gadget.dev.parent; | ||
26 | int val; | ||
27 | |||
28 | switch (event) { | ||
29 | case CI13XXX_CONTROLLER_RESET_EVENT: | ||
30 | dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n"); | ||
31 | writel(0, USB_AHBBURST); | ||
32 | writel(0, USB_AHBMODE); | ||
33 | break; | ||
34 | case CI13XXX_CONTROLLER_STOPPED_EVENT: | ||
35 | dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n"); | ||
36 | /* | ||
37 | * Put the transceiver in non-driving mode. Otherwise host | ||
38 | * may not detect soft-disconnection. | ||
39 | */ | ||
40 | val = usb_phy_io_read(udc->transceiver, ULPI_FUNC_CTRL); | ||
41 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; | ||
42 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; | ||
43 | usb_phy_io_write(udc->transceiver, val, ULPI_FUNC_CTRL); | ||
44 | break; | ||
45 | default: | ||
46 | dev_dbg(dev, "unknown ci13xxx_udc event\n"); | ||
47 | break; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = { | ||
52 | .name = "ci13xxx_msm", | ||
53 | .flags = CI13XXX_REGS_SHARED | | ||
54 | CI13XXX_REQUIRE_TRANSCEIVER | | ||
55 | CI13XXX_PULLUP_ON_VBUS | | ||
56 | CI13XXX_DISABLE_STREAMING, | ||
57 | |||
58 | .notify_event = ci13xxx_msm_notify_event, | ||
59 | }; | ||
60 | |||
61 | static int ci13xxx_msm_probe(struct platform_device *pdev) | ||
62 | { | ||
63 | struct resource *res; | ||
64 | void __iomem *regs; | ||
65 | int irq; | ||
66 | int ret; | ||
67 | |||
68 | dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); | ||
69 | |||
70 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
71 | if (!res) { | ||
72 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); | ||
73 | return -ENXIO; | ||
74 | } | ||
75 | |||
76 | regs = ioremap(res->start, resource_size(res)); | ||
77 | if (!regs) { | ||
78 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
79 | return -ENOMEM; | ||
80 | } | ||
81 | |||
82 | ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs); | ||
83 | if (ret < 0) { | ||
84 | dev_err(&pdev->dev, "udc_probe failed\n"); | ||
85 | goto iounmap; | ||
86 | } | ||
87 | |||
88 | irq = platform_get_irq(pdev, 0); | ||
89 | if (irq < 0) { | ||
90 | dev_err(&pdev->dev, "IRQ not found\n"); | ||
91 | ret = -ENXIO; | ||
92 | goto udc_remove; | ||
93 | } | ||
94 | |||
95 | ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev); | ||
96 | if (ret < 0) { | ||
97 | dev_err(&pdev->dev, "request_irq failed\n"); | ||
98 | goto udc_remove; | ||
99 | } | ||
100 | |||
101 | pm_runtime_no_callbacks(&pdev->dev); | ||
102 | pm_runtime_enable(&pdev->dev); | ||
103 | |||
104 | return 0; | ||
105 | |||
106 | udc_remove: | ||
107 | udc_remove(); | ||
108 | iounmap: | ||
109 | iounmap(regs); | ||
110 | |||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | static struct platform_driver ci13xxx_msm_driver = { | ||
115 | .probe = ci13xxx_msm_probe, | ||
116 | .driver = { .name = "msm_hsusb", }, | ||
117 | }; | ||
118 | MODULE_ALIAS("platform:msm_hsusb"); | ||
119 | |||
120 | static int __init ci13xxx_msm_init(void) | ||
121 | { | ||
122 | return platform_driver_register(&ci13xxx_msm_driver); | ||
123 | } | ||
124 | module_init(ci13xxx_msm_init); | ||
125 | |||
126 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/gadget/ci13xxx_pci.c b/drivers/usb/gadget/ci13xxx_pci.c deleted file mode 100644 index 883ab5e832d1..000000000000 --- a/drivers/usb/gadget/ci13xxx_pci.c +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
1 | /* | ||
2 | * ci13xxx_pci.c - MIPS USB IP core family device controller | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/pci.h> | ||
15 | |||
16 | #include "ci13xxx_udc.c" | ||
17 | |||
18 | /* driver name */ | ||
19 | #define UDC_DRIVER_NAME "ci13xxx_pci" | ||
20 | |||
21 | /****************************************************************************** | ||
22 | * PCI block | ||
23 | *****************************************************************************/ | ||
24 | /** | ||
25 | * ci13xxx_pci_irq: interrut handler | ||
26 | * @irq: irq number | ||
27 | * @pdev: USB Device Controller interrupt source | ||
28 | * | ||
29 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
30 | * This is an ISR don't trace, use attribute interface instead | ||
31 | */ | ||
32 | static irqreturn_t ci13xxx_pci_irq(int irq, void *pdev) | ||
33 | { | ||
34 | if (irq == 0) { | ||
35 | dev_err(&((struct pci_dev *)pdev)->dev, "Invalid IRQ0 usage!"); | ||
36 | return IRQ_HANDLED; | ||
37 | } | ||
38 | return udc_irq(); | ||
39 | } | ||
40 | |||
41 | static struct ci13xxx_udc_driver ci13xxx_pci_udc_driver = { | ||
42 | .name = UDC_DRIVER_NAME, | ||
43 | }; | ||
44 | |||
45 | /** | ||
46 | * ci13xxx_pci_probe: PCI probe | ||
47 | * @pdev: USB device controller being probed | ||
48 | * @id: PCI hotplug ID connecting controller to UDC framework | ||
49 | * | ||
50 | * This function returns an error code | ||
51 | * Allocates basic PCI resources for this USB device controller, and then | ||
52 | * invokes the udc_probe() method to start the UDC associated with it | ||
53 | */ | ||
54 | static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, | ||
55 | const struct pci_device_id *id) | ||
56 | { | ||
57 | void __iomem *regs = NULL; | ||
58 | int retval = 0; | ||
59 | |||
60 | if (id == NULL) | ||
61 | return -EINVAL; | ||
62 | |||
63 | retval = pci_enable_device(pdev); | ||
64 | if (retval) | ||
65 | goto done; | ||
66 | |||
67 | if (!pdev->irq) { | ||
68 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); | ||
69 | retval = -ENODEV; | ||
70 | goto disable_device; | ||
71 | } | ||
72 | |||
73 | retval = pci_request_regions(pdev, UDC_DRIVER_NAME); | ||
74 | if (retval) | ||
75 | goto disable_device; | ||
76 | |||
77 | /* BAR 0 holds all the registers */ | ||
78 | regs = pci_iomap(pdev, 0, 0); | ||
79 | if (!regs) { | ||
80 | dev_err(&pdev->dev, "Error mapping memory!"); | ||
81 | retval = -EFAULT; | ||
82 | goto release_regions; | ||
83 | } | ||
84 | pci_set_drvdata(pdev, (__force void *)regs); | ||
85 | |||
86 | pci_set_master(pdev); | ||
87 | pci_try_set_mwi(pdev); | ||
88 | |||
89 | retval = udc_probe(&ci13xxx_pci_udc_driver, &pdev->dev, regs); | ||
90 | if (retval) | ||
91 | goto iounmap; | ||
92 | |||
93 | /* our device does not have MSI capability */ | ||
94 | |||
95 | retval = request_irq(pdev->irq, ci13xxx_pci_irq, IRQF_SHARED, | ||
96 | UDC_DRIVER_NAME, pdev); | ||
97 | if (retval) | ||
98 | goto gadget_remove; | ||
99 | |||
100 | return 0; | ||
101 | |||
102 | gadget_remove: | ||
103 | udc_remove(); | ||
104 | iounmap: | ||
105 | pci_iounmap(pdev, regs); | ||
106 | release_regions: | ||
107 | pci_release_regions(pdev); | ||
108 | disable_device: | ||
109 | pci_disable_device(pdev); | ||
110 | done: | ||
111 | return retval; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * ci13xxx_pci_remove: PCI remove | ||
116 | * @pdev: USB Device Controller being removed | ||
117 | * | ||
118 | * Reverses the effect of ci13xxx_pci_probe(), | ||
119 | * first invoking the udc_remove() and then releases | ||
120 | * all PCI resources allocated for this USB device controller | ||
121 | */ | ||
122 | static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev) | ||
123 | { | ||
124 | free_irq(pdev->irq, pdev); | ||
125 | udc_remove(); | ||
126 | pci_iounmap(pdev, (__force void __iomem *)pci_get_drvdata(pdev)); | ||
127 | pci_release_regions(pdev); | ||
128 | pci_disable_device(pdev); | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * PCI device table | ||
133 | * PCI device structure | ||
134 | * | ||
135 | * Check "pci.h" for details | ||
136 | */ | ||
137 | static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { | ||
138 | { PCI_DEVICE(0x153F, 0x1004) }, | ||
139 | { PCI_DEVICE(0x153F, 0x1006) }, | ||
140 | { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } | ||
141 | }; | ||
142 | MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table); | ||
143 | |||
144 | static struct pci_driver ci13xxx_pci_driver = { | ||
145 | .name = UDC_DRIVER_NAME, | ||
146 | .id_table = ci13xxx_pci_id_table, | ||
147 | .probe = ci13xxx_pci_probe, | ||
148 | .remove = __devexit_p(ci13xxx_pci_remove), | ||
149 | }; | ||
150 | |||
151 | /** | ||
152 | * ci13xxx_pci_init: module init | ||
153 | * | ||
154 | * Driver load | ||
155 | */ | ||
156 | static int __init ci13xxx_pci_init(void) | ||
157 | { | ||
158 | return pci_register_driver(&ci13xxx_pci_driver); | ||
159 | } | ||
160 | module_init(ci13xxx_pci_init); | ||
161 | |||
162 | /** | ||
163 | * ci13xxx_pci_exit: module exit | ||
164 | * | ||
165 | * Driver unload | ||
166 | */ | ||
167 | static void __exit ci13xxx_pci_exit(void) | ||
168 | { | ||
169 | pci_unregister_driver(&ci13xxx_pci_driver); | ||
170 | } | ||
171 | module_exit(ci13xxx_pci_exit); | ||
172 | |||
173 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); | ||
174 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); | ||
175 | MODULE_LICENSE("GPL"); | ||
176 | MODULE_VERSION("June 2008"); | ||
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c deleted file mode 100644 index 243ef1adf969..000000000000 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ /dev/null | |||
@@ -1,2996 +0,0 @@ | |||
1 | /* | ||
2 | * ci13xxx_udc.c - MIPS USB IP core family device controller | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * Description: MIPS USB IP core family device controller | ||
15 | * Currently it only supports IP part number CI13412 | ||
16 | * | ||
17 | * This driver is composed of several blocks: | ||
18 | * - HW: hardware interface | ||
19 | * - DBG: debug facilities (optional) | ||
20 | * - UTIL: utilities | ||
21 | * - ISR: interrupts handling | ||
22 | * - ENDPT: endpoint operations (Gadget API) | ||
23 | * - GADGET: gadget operations (Gadget API) | ||
24 | * - BUS: bus glue code, bus abstraction layer | ||
25 | * | ||
26 | * Compile Options | ||
27 | * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities | ||
28 | * - STALL_IN: non-empty bulk-in pipes cannot be halted | ||
29 | * if defined mass storage compliance succeeds but with warnings | ||
30 | * => case 4: Hi > Dn | ||
31 | * => case 5: Hi > Di | ||
32 | * => case 8: Hi <> Do | ||
33 | * if undefined usbtest 13 fails | ||
34 | * - TRACE: enable function tracing (depends on DEBUG) | ||
35 | * | ||
36 | * Main Features | ||
37 | * - Chapter 9 & Mass Storage Compliance with Gadget File Storage | ||
38 | * - Chapter 9 Compliance with Gadget Zero (STALL_IN undefined) | ||
39 | * - Normal & LPM support | ||
40 | * | ||
41 | * USBTEST Report | ||
42 | * - OK: 0-12, 13 (STALL_IN defined) & 14 | ||
43 | * - Not Supported: 15 & 16 (ISO) | ||
44 | * | ||
45 | * TODO List | ||
46 | * - OTG | ||
47 | * - Isochronous & Interrupt Traffic | ||
48 | * - Handle requests which spawns into several TDs | ||
49 | * - GET_STATUS(device) - always reports 0 | ||
50 | * - Gadget API (majority of optional features) | ||
51 | * - Suspend & Remote Wakeup | ||
52 | */ | ||
53 | #include <linux/delay.h> | ||
54 | #include <linux/device.h> | ||
55 | #include <linux/dmapool.h> | ||
56 | #include <linux/dma-mapping.h> | ||
57 | #include <linux/init.h> | ||
58 | #include <linux/interrupt.h> | ||
59 | #include <linux/io.h> | ||
60 | #include <linux/irq.h> | ||
61 | #include <linux/kernel.h> | ||
62 | #include <linux/slab.h> | ||
63 | #include <linux/pm_runtime.h> | ||
64 | #include <linux/usb/ch9.h> | ||
65 | #include <linux/usb/gadget.h> | ||
66 | #include <linux/usb/otg.h> | ||
67 | |||
68 | #include "ci13xxx_udc.h" | ||
69 | |||
70 | |||
71 | /****************************************************************************** | ||
72 | * DEFINE | ||
73 | *****************************************************************************/ | ||
74 | |||
75 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) | ||
76 | |||
77 | /* ctrl register bank access */ | ||
78 | static DEFINE_SPINLOCK(udc_lock); | ||
79 | |||
80 | /* control endpoint description */ | ||
81 | static const struct usb_endpoint_descriptor | ||
82 | ctrl_endpt_out_desc = { | ||
83 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
84 | .bDescriptorType = USB_DT_ENDPOINT, | ||
85 | |||
86 | .bEndpointAddress = USB_DIR_OUT, | ||
87 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
88 | .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX), | ||
89 | }; | ||
90 | |||
91 | static const struct usb_endpoint_descriptor | ||
92 | ctrl_endpt_in_desc = { | ||
93 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
94 | .bDescriptorType = USB_DT_ENDPOINT, | ||
95 | |||
96 | .bEndpointAddress = USB_DIR_IN, | ||
97 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
98 | .wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX), | ||
99 | }; | ||
100 | |||
101 | /* UDC descriptor */ | ||
102 | static struct ci13xxx *_udc; | ||
103 | |||
104 | /* Interrupt statistics */ | ||
105 | #define ISR_MASK 0x1F | ||
106 | static struct { | ||
107 | u32 test; | ||
108 | u32 ui; | ||
109 | u32 uei; | ||
110 | u32 pci; | ||
111 | u32 uri; | ||
112 | u32 sli; | ||
113 | u32 none; | ||
114 | struct { | ||
115 | u32 cnt; | ||
116 | u32 buf[ISR_MASK+1]; | ||
117 | u32 idx; | ||
118 | } hndl; | ||
119 | } isr_statistics; | ||
120 | |||
121 | /** | ||
122 | * ffs_nr: find first (least significant) bit set | ||
123 | * @x: the word to search | ||
124 | * | ||
125 | * This function returns bit number (instead of position) | ||
126 | */ | ||
127 | static int ffs_nr(u32 x) | ||
128 | { | ||
129 | int n = ffs(x); | ||
130 | |||
131 | return n ? n-1 : 32; | ||
132 | } | ||
133 | |||
134 | /****************************************************************************** | ||
135 | * HW block | ||
136 | *****************************************************************************/ | ||
137 | /* register bank descriptor */ | ||
138 | static struct { | ||
139 | unsigned lpm; /* is LPM? */ | ||
140 | void __iomem *abs; /* bus map offset */ | ||
141 | void __iomem *cap; /* bus map offset + CAP offset + CAP data */ | ||
142 | size_t size; /* bank size */ | ||
143 | } hw_bank; | ||
144 | |||
145 | /* MSM specific */ | ||
146 | #define ABS_AHBBURST (0x0090UL) | ||
147 | #define ABS_AHBMODE (0x0098UL) | ||
148 | /* UDC register map */ | ||
149 | #define ABS_CAPLENGTH (0x100UL) | ||
150 | #define ABS_HCCPARAMS (0x108UL) | ||
151 | #define ABS_DCCPARAMS (0x124UL) | ||
152 | #define ABS_TESTMODE (hw_bank.lpm ? 0x0FCUL : 0x138UL) | ||
153 | /* offset to CAPLENTGH (addr + data) */ | ||
154 | #define CAP_USBCMD (0x000UL) | ||
155 | #define CAP_USBSTS (0x004UL) | ||
156 | #define CAP_USBINTR (0x008UL) | ||
157 | #define CAP_DEVICEADDR (0x014UL) | ||
158 | #define CAP_ENDPTLISTADDR (0x018UL) | ||
159 | #define CAP_PORTSC (0x044UL) | ||
160 | #define CAP_DEVLC (0x084UL) | ||
161 | #define CAP_USBMODE (hw_bank.lpm ? 0x0C8UL : 0x068UL) | ||
162 | #define CAP_ENDPTSETUPSTAT (hw_bank.lpm ? 0x0D8UL : 0x06CUL) | ||
163 | #define CAP_ENDPTPRIME (hw_bank.lpm ? 0x0DCUL : 0x070UL) | ||
164 | #define CAP_ENDPTFLUSH (hw_bank.lpm ? 0x0E0UL : 0x074UL) | ||
165 | #define CAP_ENDPTSTAT (hw_bank.lpm ? 0x0E4UL : 0x078UL) | ||
166 | #define CAP_ENDPTCOMPLETE (hw_bank.lpm ? 0x0E8UL : 0x07CUL) | ||
167 | #define CAP_ENDPTCTRL (hw_bank.lpm ? 0x0ECUL : 0x080UL) | ||
168 | #define CAP_LAST (hw_bank.lpm ? 0x12CUL : 0x0C0UL) | ||
169 | |||
170 | /* maximum number of enpoints: valid only after hw_device_reset() */ | ||
171 | static unsigned hw_ep_max; | ||
172 | |||
173 | /** | ||
174 | * hw_ep_bit: calculates the bit number | ||
175 | * @num: endpoint number | ||
176 | * @dir: endpoint direction | ||
177 | * | ||
178 | * This function returns bit number | ||
179 | */ | ||
180 | static inline int hw_ep_bit(int num, int dir) | ||
181 | { | ||
182 | return num + (dir ? 16 : 0); | ||
183 | } | ||
184 | |||
185 | static int ep_to_bit(int n) | ||
186 | { | ||
187 | int fill = 16 - hw_ep_max / 2; | ||
188 | |||
189 | if (n >= hw_ep_max / 2) | ||
190 | n += fill; | ||
191 | |||
192 | return n; | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * hw_aread: reads from register bitfield | ||
197 | * @addr: address relative to bus map | ||
198 | * @mask: bitfield mask | ||
199 | * | ||
200 | * This function returns register bitfield data | ||
201 | */ | ||
202 | static u32 hw_aread(u32 addr, u32 mask) | ||
203 | { | ||
204 | return ioread32(addr + hw_bank.abs) & mask; | ||
205 | } | ||
206 | |||
207 | /** | ||
208 | * hw_awrite: writes to register bitfield | ||
209 | * @addr: address relative to bus map | ||
210 | * @mask: bitfield mask | ||
211 | * @data: new data | ||
212 | */ | ||
213 | static void hw_awrite(u32 addr, u32 mask, u32 data) | ||
214 | { | ||
215 | iowrite32(hw_aread(addr, ~mask) | (data & mask), | ||
216 | addr + hw_bank.abs); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * hw_cread: reads from register bitfield | ||
221 | * @addr: address relative to CAP offset plus content | ||
222 | * @mask: bitfield mask | ||
223 | * | ||
224 | * This function returns register bitfield data | ||
225 | */ | ||
226 | static u32 hw_cread(u32 addr, u32 mask) | ||
227 | { | ||
228 | return ioread32(addr + hw_bank.cap) & mask; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * hw_cwrite: writes to register bitfield | ||
233 | * @addr: address relative to CAP offset plus content | ||
234 | * @mask: bitfield mask | ||
235 | * @data: new data | ||
236 | */ | ||
237 | static void hw_cwrite(u32 addr, u32 mask, u32 data) | ||
238 | { | ||
239 | iowrite32(hw_cread(addr, ~mask) | (data & mask), | ||
240 | addr + hw_bank.cap); | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * hw_ctest_and_clear: tests & clears register bitfield | ||
245 | * @addr: address relative to CAP offset plus content | ||
246 | * @mask: bitfield mask | ||
247 | * | ||
248 | * This function returns register bitfield data | ||
249 | */ | ||
250 | static u32 hw_ctest_and_clear(u32 addr, u32 mask) | ||
251 | { | ||
252 | u32 reg = hw_cread(addr, mask); | ||
253 | |||
254 | iowrite32(reg, addr + hw_bank.cap); | ||
255 | return reg; | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * hw_ctest_and_write: tests & writes register bitfield | ||
260 | * @addr: address relative to CAP offset plus content | ||
261 | * @mask: bitfield mask | ||
262 | * @data: new data | ||
263 | * | ||
264 | * This function returns register bitfield data | ||
265 | */ | ||
266 | static u32 hw_ctest_and_write(u32 addr, u32 mask, u32 data) | ||
267 | { | ||
268 | u32 reg = hw_cread(addr, ~0); | ||
269 | |||
270 | iowrite32((reg & ~mask) | (data & mask), addr + hw_bank.cap); | ||
271 | return (reg & mask) >> ffs_nr(mask); | ||
272 | } | ||
273 | |||
274 | static int hw_device_init(void __iomem *base) | ||
275 | { | ||
276 | u32 reg; | ||
277 | |||
278 | /* bank is a module variable */ | ||
279 | hw_bank.abs = base; | ||
280 | |||
281 | hw_bank.cap = hw_bank.abs; | ||
282 | hw_bank.cap += ABS_CAPLENGTH; | ||
283 | hw_bank.cap += ioread8(hw_bank.cap); | ||
284 | |||
285 | reg = hw_aread(ABS_HCCPARAMS, HCCPARAMS_LEN) >> ffs_nr(HCCPARAMS_LEN); | ||
286 | hw_bank.lpm = reg; | ||
287 | hw_bank.size = hw_bank.cap - hw_bank.abs; | ||
288 | hw_bank.size += CAP_LAST; | ||
289 | hw_bank.size /= sizeof(u32); | ||
290 | |||
291 | reg = hw_aread(ABS_DCCPARAMS, DCCPARAMS_DEN) >> ffs_nr(DCCPARAMS_DEN); | ||
292 | hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ | ||
293 | |||
294 | if (hw_ep_max == 0 || hw_ep_max > ENDPT_MAX) | ||
295 | return -ENODEV; | ||
296 | |||
297 | /* setup lock mode ? */ | ||
298 | |||
299 | /* ENDPTSETUPSTAT is '0' by default */ | ||
300 | |||
301 | /* HCSPARAMS.bf.ppc SHOULD BE zero for device */ | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | /** | ||
306 | * hw_device_reset: resets chip (execute without interruption) | ||
307 | * @base: register base address | ||
308 | * | ||
309 | * This function returns an error code | ||
310 | */ | ||
311 | static int hw_device_reset(struct ci13xxx *udc) | ||
312 | { | ||
313 | /* should flush & stop before reset */ | ||
314 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); | ||
315 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); | ||
316 | |||
317 | hw_cwrite(CAP_USBCMD, USBCMD_RST, USBCMD_RST); | ||
318 | while (hw_cread(CAP_USBCMD, USBCMD_RST)) | ||
319 | udelay(10); /* not RTOS friendly */ | ||
320 | |||
321 | |||
322 | if (udc->udc_driver->notify_event) | ||
323 | udc->udc_driver->notify_event(udc, | ||
324 | CI13XXX_CONTROLLER_RESET_EVENT); | ||
325 | |||
326 | if (udc->udc_driver->flags & CI13XXX_DISABLE_STREAMING) | ||
327 | hw_cwrite(CAP_USBMODE, USBMODE_SDIS, USBMODE_SDIS); | ||
328 | |||
329 | /* USBMODE should be configured step by step */ | ||
330 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_IDLE); | ||
331 | hw_cwrite(CAP_USBMODE, USBMODE_CM, USBMODE_CM_DEVICE); | ||
332 | hw_cwrite(CAP_USBMODE, USBMODE_SLOM, USBMODE_SLOM); /* HW >= 2.3 */ | ||
333 | |||
334 | if (hw_cread(CAP_USBMODE, USBMODE_CM) != USBMODE_CM_DEVICE) { | ||
335 | pr_err("cannot enter in device mode"); | ||
336 | pr_err("lpm = %i", hw_bank.lpm); | ||
337 | return -ENODEV; | ||
338 | } | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * hw_device_state: enables/disables interrupts & starts/stops device (execute | ||
345 | * without interruption) | ||
346 | * @dma: 0 => disable, !0 => enable and set dma engine | ||
347 | * | ||
348 | * This function returns an error code | ||
349 | */ | ||
350 | static int hw_device_state(u32 dma) | ||
351 | { | ||
352 | if (dma) { | ||
353 | hw_cwrite(CAP_ENDPTLISTADDR, ~0, dma); | ||
354 | /* interrupt, error, port change, reset, sleep/suspend */ | ||
355 | hw_cwrite(CAP_USBINTR, ~0, | ||
356 | USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); | ||
357 | hw_cwrite(CAP_USBCMD, USBCMD_RS, USBCMD_RS); | ||
358 | } else { | ||
359 | hw_cwrite(CAP_USBCMD, USBCMD_RS, 0); | ||
360 | hw_cwrite(CAP_USBINTR, ~0, 0); | ||
361 | } | ||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * hw_ep_flush: flush endpoint fifo (execute without interruption) | ||
367 | * @num: endpoint number | ||
368 | * @dir: endpoint direction | ||
369 | * | ||
370 | * This function returns an error code | ||
371 | */ | ||
372 | static int hw_ep_flush(int num, int dir) | ||
373 | { | ||
374 | int n = hw_ep_bit(num, dir); | ||
375 | |||
376 | do { | ||
377 | /* flush any pending transfer */ | ||
378 | hw_cwrite(CAP_ENDPTFLUSH, BIT(n), BIT(n)); | ||
379 | while (hw_cread(CAP_ENDPTFLUSH, BIT(n))) | ||
380 | cpu_relax(); | ||
381 | } while (hw_cread(CAP_ENDPTSTAT, BIT(n))); | ||
382 | |||
383 | return 0; | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * hw_ep_disable: disables endpoint (execute without interruption) | ||
388 | * @num: endpoint number | ||
389 | * @dir: endpoint direction | ||
390 | * | ||
391 | * This function returns an error code | ||
392 | */ | ||
393 | static int hw_ep_disable(int num, int dir) | ||
394 | { | ||
395 | hw_ep_flush(num, dir); | ||
396 | hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), | ||
397 | dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0); | ||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * hw_ep_enable: enables endpoint (execute without interruption) | ||
403 | * @num: endpoint number | ||
404 | * @dir: endpoint direction | ||
405 | * @type: endpoint type | ||
406 | * | ||
407 | * This function returns an error code | ||
408 | */ | ||
409 | static int hw_ep_enable(int num, int dir, int type) | ||
410 | { | ||
411 | u32 mask, data; | ||
412 | |||
413 | if (dir) { | ||
414 | mask = ENDPTCTRL_TXT; /* type */ | ||
415 | data = type << ffs_nr(mask); | ||
416 | |||
417 | mask |= ENDPTCTRL_TXS; /* unstall */ | ||
418 | mask |= ENDPTCTRL_TXR; /* reset data toggle */ | ||
419 | data |= ENDPTCTRL_TXR; | ||
420 | mask |= ENDPTCTRL_TXE; /* enable */ | ||
421 | data |= ENDPTCTRL_TXE; | ||
422 | } else { | ||
423 | mask = ENDPTCTRL_RXT; /* type */ | ||
424 | data = type << ffs_nr(mask); | ||
425 | |||
426 | mask |= ENDPTCTRL_RXS; /* unstall */ | ||
427 | mask |= ENDPTCTRL_RXR; /* reset data toggle */ | ||
428 | data |= ENDPTCTRL_RXR; | ||
429 | mask |= ENDPTCTRL_RXE; /* enable */ | ||
430 | data |= ENDPTCTRL_RXE; | ||
431 | } | ||
432 | hw_cwrite(CAP_ENDPTCTRL + num * sizeof(u32), mask, data); | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | /** | ||
437 | * hw_ep_get_halt: return endpoint halt status | ||
438 | * @num: endpoint number | ||
439 | * @dir: endpoint direction | ||
440 | * | ||
441 | * This function returns 1 if endpoint halted | ||
442 | */ | ||
443 | static int hw_ep_get_halt(int num, int dir) | ||
444 | { | ||
445 | u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | ||
446 | |||
447 | return hw_cread(CAP_ENDPTCTRL + num * sizeof(u32), mask) ? 1 : 0; | ||
448 | } | ||
449 | |||
450 | /** | ||
451 | * hw_test_and_clear_setup_status: test & clear setup status (execute without | ||
452 | * interruption) | ||
453 | * @n: endpoint number | ||
454 | * | ||
455 | * This function returns setup status | ||
456 | */ | ||
457 | static int hw_test_and_clear_setup_status(int n) | ||
458 | { | ||
459 | n = ep_to_bit(n); | ||
460 | return hw_ctest_and_clear(CAP_ENDPTSETUPSTAT, BIT(n)); | ||
461 | } | ||
462 | |||
463 | /** | ||
464 | * hw_ep_prime: primes endpoint (execute without interruption) | ||
465 | * @num: endpoint number | ||
466 | * @dir: endpoint direction | ||
467 | * @is_ctrl: true if control endpoint | ||
468 | * | ||
469 | * This function returns an error code | ||
470 | */ | ||
471 | static int hw_ep_prime(int num, int dir, int is_ctrl) | ||
472 | { | ||
473 | int n = hw_ep_bit(num, dir); | ||
474 | |||
475 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) | ||
476 | return -EAGAIN; | ||
477 | |||
478 | hw_cwrite(CAP_ENDPTPRIME, BIT(n), BIT(n)); | ||
479 | |||
480 | while (hw_cread(CAP_ENDPTPRIME, BIT(n))) | ||
481 | cpu_relax(); | ||
482 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) | ||
483 | return -EAGAIN; | ||
484 | |||
485 | /* status shoult be tested according with manual but it doesn't work */ | ||
486 | return 0; | ||
487 | } | ||
488 | |||
489 | /** | ||
490 | * hw_ep_set_halt: configures ep halt & resets data toggle after clear (execute | ||
491 | * without interruption) | ||
492 | * @num: endpoint number | ||
493 | * @dir: endpoint direction | ||
494 | * @value: true => stall, false => unstall | ||
495 | * | ||
496 | * This function returns an error code | ||
497 | */ | ||
498 | static int hw_ep_set_halt(int num, int dir, int value) | ||
499 | { | ||
500 | if (value != 0 && value != 1) | ||
501 | return -EINVAL; | ||
502 | |||
503 | do { | ||
504 | u32 addr = CAP_ENDPTCTRL + num * sizeof(u32); | ||
505 | u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS; | ||
506 | u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR; | ||
507 | |||
508 | /* data toggle - reserved for EP0 but it's in ESS */ | ||
509 | hw_cwrite(addr, mask_xs|mask_xr, value ? mask_xs : mask_xr); | ||
510 | |||
511 | } while (value != hw_ep_get_halt(num, dir)); | ||
512 | |||
513 | return 0; | ||
514 | } | ||
515 | |||
516 | /** | ||
517 | * hw_intr_clear: disables interrupt & clears interrupt status (execute without | ||
518 | * interruption) | ||
519 | * @n: interrupt bit | ||
520 | * | ||
521 | * This function returns an error code | ||
522 | */ | ||
523 | static int hw_intr_clear(int n) | ||
524 | { | ||
525 | if (n >= REG_BITS) | ||
526 | return -EINVAL; | ||
527 | |||
528 | hw_cwrite(CAP_USBINTR, BIT(n), 0); | ||
529 | hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | /** | ||
534 | * hw_intr_force: enables interrupt & forces interrupt status (execute without | ||
535 | * interruption) | ||
536 | * @n: interrupt bit | ||
537 | * | ||
538 | * This function returns an error code | ||
539 | */ | ||
540 | static int hw_intr_force(int n) | ||
541 | { | ||
542 | if (n >= REG_BITS) | ||
543 | return -EINVAL; | ||
544 | |||
545 | hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE); | ||
546 | hw_cwrite(CAP_USBINTR, BIT(n), BIT(n)); | ||
547 | hw_cwrite(CAP_USBSTS, BIT(n), BIT(n)); | ||
548 | hw_awrite(ABS_TESTMODE, TESTMODE_FORCE, 0); | ||
549 | return 0; | ||
550 | } | ||
551 | |||
552 | /** | ||
553 | * hw_is_port_high_speed: test if port is high speed | ||
554 | * | ||
555 | * This function returns true if high speed port | ||
556 | */ | ||
557 | static int hw_port_is_high_speed(void) | ||
558 | { | ||
559 | return hw_bank.lpm ? hw_cread(CAP_DEVLC, DEVLC_PSPD) : | ||
560 | hw_cread(CAP_PORTSC, PORTSC_HSP); | ||
561 | } | ||
562 | |||
563 | /** | ||
564 | * hw_port_test_get: reads port test mode value | ||
565 | * | ||
566 | * This function returns port test mode value | ||
567 | */ | ||
568 | static u8 hw_port_test_get(void) | ||
569 | { | ||
570 | return hw_cread(CAP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); | ||
571 | } | ||
572 | |||
573 | /** | ||
574 | * hw_port_test_set: writes port test mode (execute without interruption) | ||
575 | * @mode: new value | ||
576 | * | ||
577 | * This function returns an error code | ||
578 | */ | ||
579 | static int hw_port_test_set(u8 mode) | ||
580 | { | ||
581 | const u8 TEST_MODE_MAX = 7; | ||
582 | |||
583 | if (mode > TEST_MODE_MAX) | ||
584 | return -EINVAL; | ||
585 | |||
586 | hw_cwrite(CAP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | /** | ||
591 | * hw_read_intr_enable: returns interrupt enable register | ||
592 | * | ||
593 | * This function returns register data | ||
594 | */ | ||
595 | static u32 hw_read_intr_enable(void) | ||
596 | { | ||
597 | return hw_cread(CAP_USBINTR, ~0); | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * hw_read_intr_status: returns interrupt status register | ||
602 | * | ||
603 | * This function returns register data | ||
604 | */ | ||
605 | static u32 hw_read_intr_status(void) | ||
606 | { | ||
607 | return hw_cread(CAP_USBSTS, ~0); | ||
608 | } | ||
609 | |||
610 | /** | ||
611 | * hw_register_read: reads all device registers (execute without interruption) | ||
612 | * @buf: destination buffer | ||
613 | * @size: buffer size | ||
614 | * | ||
615 | * This function returns number of registers read | ||
616 | */ | ||
617 | static size_t hw_register_read(u32 *buf, size_t size) | ||
618 | { | ||
619 | unsigned i; | ||
620 | |||
621 | if (size > hw_bank.size) | ||
622 | size = hw_bank.size; | ||
623 | |||
624 | for (i = 0; i < size; i++) | ||
625 | buf[i] = hw_aread(i * sizeof(u32), ~0); | ||
626 | |||
627 | return size; | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * hw_register_write: writes to register | ||
632 | * @addr: register address | ||
633 | * @data: register value | ||
634 | * | ||
635 | * This function returns an error code | ||
636 | */ | ||
637 | static int hw_register_write(u16 addr, u32 data) | ||
638 | { | ||
639 | /* align */ | ||
640 | addr /= sizeof(u32); | ||
641 | |||
642 | if (addr >= hw_bank.size) | ||
643 | return -EINVAL; | ||
644 | |||
645 | /* align */ | ||
646 | addr *= sizeof(u32); | ||
647 | |||
648 | hw_awrite(addr, ~0, data); | ||
649 | return 0; | ||
650 | } | ||
651 | |||
652 | /** | ||
653 | * hw_test_and_clear_complete: test & clear complete status (execute without | ||
654 | * interruption) | ||
655 | * @n: endpoint number | ||
656 | * | ||
657 | * This function returns complete status | ||
658 | */ | ||
659 | static int hw_test_and_clear_complete(int n) | ||
660 | { | ||
661 | n = ep_to_bit(n); | ||
662 | return hw_ctest_and_clear(CAP_ENDPTCOMPLETE, BIT(n)); | ||
663 | } | ||
664 | |||
665 | /** | ||
666 | * hw_test_and_clear_intr_active: test & clear active interrupts (execute | ||
667 | * without interruption) | ||
668 | * | ||
669 | * This function returns active interrutps | ||
670 | */ | ||
671 | static u32 hw_test_and_clear_intr_active(void) | ||
672 | { | ||
673 | u32 reg = hw_read_intr_status() & hw_read_intr_enable(); | ||
674 | |||
675 | hw_cwrite(CAP_USBSTS, ~0, reg); | ||
676 | return reg; | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * hw_test_and_clear_setup_guard: test & clear setup guard (execute without | ||
681 | * interruption) | ||
682 | * | ||
683 | * This function returns guard value | ||
684 | */ | ||
685 | static int hw_test_and_clear_setup_guard(void) | ||
686 | { | ||
687 | return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, 0); | ||
688 | } | ||
689 | |||
690 | /** | ||
691 | * hw_test_and_set_setup_guard: test & set setup guard (execute without | ||
692 | * interruption) | ||
693 | * | ||
694 | * This function returns guard value | ||
695 | */ | ||
696 | static int hw_test_and_set_setup_guard(void) | ||
697 | { | ||
698 | return hw_ctest_and_write(CAP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); | ||
699 | } | ||
700 | |||
701 | /** | ||
702 | * hw_usb_set_address: configures USB address (execute without interruption) | ||
703 | * @value: new USB address | ||
704 | * | ||
705 | * This function returns an error code | ||
706 | */ | ||
707 | static int hw_usb_set_address(u8 value) | ||
708 | { | ||
709 | /* advance */ | ||
710 | hw_cwrite(CAP_DEVICEADDR, DEVICEADDR_USBADR | DEVICEADDR_USBADRA, | ||
711 | value << ffs_nr(DEVICEADDR_USBADR) | DEVICEADDR_USBADRA); | ||
712 | return 0; | ||
713 | } | ||
714 | |||
715 | /** | ||
716 | * hw_usb_reset: restart device after a bus reset (execute without | ||
717 | * interruption) | ||
718 | * | ||
719 | * This function returns an error code | ||
720 | */ | ||
721 | static int hw_usb_reset(void) | ||
722 | { | ||
723 | hw_usb_set_address(0); | ||
724 | |||
725 | /* ESS flushes only at end?!? */ | ||
726 | hw_cwrite(CAP_ENDPTFLUSH, ~0, ~0); /* flush all EPs */ | ||
727 | |||
728 | /* clear setup token semaphores */ | ||
729 | hw_cwrite(CAP_ENDPTSETUPSTAT, 0, 0); /* writes its content */ | ||
730 | |||
731 | /* clear complete status */ | ||
732 | hw_cwrite(CAP_ENDPTCOMPLETE, 0, 0); /* writes its content */ | ||
733 | |||
734 | /* wait until all bits cleared */ | ||
735 | while (hw_cread(CAP_ENDPTPRIME, ~0)) | ||
736 | udelay(10); /* not RTOS friendly */ | ||
737 | |||
738 | /* reset all endpoints ? */ | ||
739 | |||
740 | /* reset internal status and wait for further instructions | ||
741 | no need to verify the port reset status (ESS does it) */ | ||
742 | |||
743 | return 0; | ||
744 | } | ||
745 | |||
746 | /****************************************************************************** | ||
747 | * DBG block | ||
748 | *****************************************************************************/ | ||
749 | /** | ||
750 | * show_device: prints information about device capabilities and status | ||
751 | * | ||
752 | * Check "device.h" for details | ||
753 | */ | ||
754 | static ssize_t show_device(struct device *dev, struct device_attribute *attr, | ||
755 | char *buf) | ||
756 | { | ||
757 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
758 | struct usb_gadget *gadget = &udc->gadget; | ||
759 | int n = 0; | ||
760 | |||
761 | dbg_trace("[%s] %p\n", __func__, buf); | ||
762 | if (attr == NULL || buf == NULL) { | ||
763 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
764 | return 0; | ||
765 | } | ||
766 | |||
767 | n += scnprintf(buf + n, PAGE_SIZE - n, "speed = %d\n", | ||
768 | gadget->speed); | ||
769 | n += scnprintf(buf + n, PAGE_SIZE - n, "max_speed = %d\n", | ||
770 | gadget->max_speed); | ||
771 | /* TODO: Scheduled for removal in 3.8. */ | ||
772 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_dualspeed = %d\n", | ||
773 | gadget_is_dualspeed(gadget)); | ||
774 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_otg = %d\n", | ||
775 | gadget->is_otg); | ||
776 | n += scnprintf(buf + n, PAGE_SIZE - n, "is_a_peripheral = %d\n", | ||
777 | gadget->is_a_peripheral); | ||
778 | n += scnprintf(buf + n, PAGE_SIZE - n, "b_hnp_enable = %d\n", | ||
779 | gadget->b_hnp_enable); | ||
780 | n += scnprintf(buf + n, PAGE_SIZE - n, "a_hnp_support = %d\n", | ||
781 | gadget->a_hnp_support); | ||
782 | n += scnprintf(buf + n, PAGE_SIZE - n, "a_alt_hnp_support = %d\n", | ||
783 | gadget->a_alt_hnp_support); | ||
784 | n += scnprintf(buf + n, PAGE_SIZE - n, "name = %s\n", | ||
785 | (gadget->name ? gadget->name : "")); | ||
786 | |||
787 | return n; | ||
788 | } | ||
789 | static DEVICE_ATTR(device, S_IRUSR, show_device, NULL); | ||
790 | |||
791 | /** | ||
792 | * show_driver: prints information about attached gadget (if any) | ||
793 | * | ||
794 | * Check "device.h" for details | ||
795 | */ | ||
796 | static ssize_t show_driver(struct device *dev, struct device_attribute *attr, | ||
797 | char *buf) | ||
798 | { | ||
799 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
800 | struct usb_gadget_driver *driver = udc->driver; | ||
801 | int n = 0; | ||
802 | |||
803 | dbg_trace("[%s] %p\n", __func__, buf); | ||
804 | if (attr == NULL || buf == NULL) { | ||
805 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
806 | return 0; | ||
807 | } | ||
808 | |||
809 | if (driver == NULL) | ||
810 | return scnprintf(buf, PAGE_SIZE, | ||
811 | "There is no gadget attached!\n"); | ||
812 | |||
813 | n += scnprintf(buf + n, PAGE_SIZE - n, "function = %s\n", | ||
814 | (driver->function ? driver->function : "")); | ||
815 | n += scnprintf(buf + n, PAGE_SIZE - n, "max speed = %d\n", | ||
816 | driver->max_speed); | ||
817 | |||
818 | return n; | ||
819 | } | ||
820 | static DEVICE_ATTR(driver, S_IRUSR, show_driver, NULL); | ||
821 | |||
822 | /* Maximum event message length */ | ||
823 | #define DBG_DATA_MSG 64UL | ||
824 | |||
825 | /* Maximum event messages */ | ||
826 | #define DBG_DATA_MAX 128UL | ||
827 | |||
828 | /* Event buffer descriptor */ | ||
829 | static struct { | ||
830 | char (buf[DBG_DATA_MAX])[DBG_DATA_MSG]; /* buffer */ | ||
831 | unsigned idx; /* index */ | ||
832 | unsigned tty; /* print to console? */ | ||
833 | rwlock_t lck; /* lock */ | ||
834 | } dbg_data = { | ||
835 | .idx = 0, | ||
836 | .tty = 0, | ||
837 | .lck = __RW_LOCK_UNLOCKED(lck) | ||
838 | }; | ||
839 | |||
840 | /** | ||
841 | * dbg_dec: decrements debug event index | ||
842 | * @idx: buffer index | ||
843 | */ | ||
844 | static void dbg_dec(unsigned *idx) | ||
845 | { | ||
846 | *idx = (*idx - 1) & (DBG_DATA_MAX-1); | ||
847 | } | ||
848 | |||
849 | /** | ||
850 | * dbg_inc: increments debug event index | ||
851 | * @idx: buffer index | ||
852 | */ | ||
853 | static void dbg_inc(unsigned *idx) | ||
854 | { | ||
855 | *idx = (*idx + 1) & (DBG_DATA_MAX-1); | ||
856 | } | ||
857 | |||
858 | /** | ||
859 | * dbg_print: prints the common part of the event | ||
860 | * @addr: endpoint address | ||
861 | * @name: event name | ||
862 | * @status: status | ||
863 | * @extra: extra information | ||
864 | */ | ||
865 | static void dbg_print(u8 addr, const char *name, int status, const char *extra) | ||
866 | { | ||
867 | struct timeval tval; | ||
868 | unsigned int stamp; | ||
869 | unsigned long flags; | ||
870 | |||
871 | write_lock_irqsave(&dbg_data.lck, flags); | ||
872 | |||
873 | do_gettimeofday(&tval); | ||
874 | stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s */ | ||
875 | stamp = stamp * 1000000 + tval.tv_usec; | ||
876 | |||
877 | scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG, | ||
878 | "%04X\t? %02X %-7.7s %4i ?\t%s\n", | ||
879 | stamp, addr, name, status, extra); | ||
880 | |||
881 | dbg_inc(&dbg_data.idx); | ||
882 | |||
883 | write_unlock_irqrestore(&dbg_data.lck, flags); | ||
884 | |||
885 | if (dbg_data.tty != 0) | ||
886 | pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n", | ||
887 | stamp, addr, name, status, extra); | ||
888 | } | ||
889 | |||
890 | /** | ||
891 | * dbg_done: prints a DONE event | ||
892 | * @addr: endpoint address | ||
893 | * @td: transfer descriptor | ||
894 | * @status: status | ||
895 | */ | ||
896 | static void dbg_done(u8 addr, const u32 token, int status) | ||
897 | { | ||
898 | char msg[DBG_DATA_MSG]; | ||
899 | |||
900 | scnprintf(msg, sizeof(msg), "%d %02X", | ||
901 | (int)(token & TD_TOTAL_BYTES) >> ffs_nr(TD_TOTAL_BYTES), | ||
902 | (int)(token & TD_STATUS) >> ffs_nr(TD_STATUS)); | ||
903 | dbg_print(addr, "DONE", status, msg); | ||
904 | } | ||
905 | |||
906 | /** | ||
907 | * dbg_event: prints a generic event | ||
908 | * @addr: endpoint address | ||
909 | * @name: event name | ||
910 | * @status: status | ||
911 | */ | ||
912 | static void dbg_event(u8 addr, const char *name, int status) | ||
913 | { | ||
914 | if (name != NULL) | ||
915 | dbg_print(addr, name, status, ""); | ||
916 | } | ||
917 | |||
918 | /* | ||
919 | * dbg_queue: prints a QUEUE event | ||
920 | * @addr: endpoint address | ||
921 | * @req: USB request | ||
922 | * @status: status | ||
923 | */ | ||
924 | static void dbg_queue(u8 addr, const struct usb_request *req, int status) | ||
925 | { | ||
926 | char msg[DBG_DATA_MSG]; | ||
927 | |||
928 | if (req != NULL) { | ||
929 | scnprintf(msg, sizeof(msg), | ||
930 | "%d %d", !req->no_interrupt, req->length); | ||
931 | dbg_print(addr, "QUEUE", status, msg); | ||
932 | } | ||
933 | } | ||
934 | |||
935 | /** | ||
936 | * dbg_setup: prints a SETUP event | ||
937 | * @addr: endpoint address | ||
938 | * @req: setup request | ||
939 | */ | ||
940 | static void dbg_setup(u8 addr, const struct usb_ctrlrequest *req) | ||
941 | { | ||
942 | char msg[DBG_DATA_MSG]; | ||
943 | |||
944 | if (req != NULL) { | ||
945 | scnprintf(msg, sizeof(msg), | ||
946 | "%02X %02X %04X %04X %d", req->bRequestType, | ||
947 | req->bRequest, le16_to_cpu(req->wValue), | ||
948 | le16_to_cpu(req->wIndex), le16_to_cpu(req->wLength)); | ||
949 | dbg_print(addr, "SETUP", 0, msg); | ||
950 | } | ||
951 | } | ||
952 | |||
953 | /** | ||
954 | * show_events: displays the event buffer | ||
955 | * | ||
956 | * Check "device.h" for details | ||
957 | */ | ||
958 | static ssize_t show_events(struct device *dev, struct device_attribute *attr, | ||
959 | char *buf) | ||
960 | { | ||
961 | unsigned long flags; | ||
962 | unsigned i, j, n = 0; | ||
963 | |||
964 | dbg_trace("[%s] %p\n", __func__, buf); | ||
965 | if (attr == NULL || buf == NULL) { | ||
966 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
967 | return 0; | ||
968 | } | ||
969 | |||
970 | read_lock_irqsave(&dbg_data.lck, flags); | ||
971 | |||
972 | i = dbg_data.idx; | ||
973 | for (dbg_dec(&i); i != dbg_data.idx; dbg_dec(&i)) { | ||
974 | n += strlen(dbg_data.buf[i]); | ||
975 | if (n >= PAGE_SIZE) { | ||
976 | n -= strlen(dbg_data.buf[i]); | ||
977 | break; | ||
978 | } | ||
979 | } | ||
980 | for (j = 0, dbg_inc(&i); j < n; dbg_inc(&i)) | ||
981 | j += scnprintf(buf + j, PAGE_SIZE - j, | ||
982 | "%s", dbg_data.buf[i]); | ||
983 | |||
984 | read_unlock_irqrestore(&dbg_data.lck, flags); | ||
985 | |||
986 | return n; | ||
987 | } | ||
988 | |||
989 | /** | ||
990 | * store_events: configure if events are going to be also printed to console | ||
991 | * | ||
992 | * Check "device.h" for details | ||
993 | */ | ||
994 | static ssize_t store_events(struct device *dev, struct device_attribute *attr, | ||
995 | const char *buf, size_t count) | ||
996 | { | ||
997 | unsigned tty; | ||
998 | |||
999 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1000 | if (attr == NULL || buf == NULL) { | ||
1001 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1002 | goto done; | ||
1003 | } | ||
1004 | |||
1005 | if (sscanf(buf, "%u", &tty) != 1 || tty > 1) { | ||
1006 | dev_err(dev, "<1|0>: enable|disable console log\n"); | ||
1007 | goto done; | ||
1008 | } | ||
1009 | |||
1010 | dbg_data.tty = tty; | ||
1011 | dev_info(dev, "tty = %u", dbg_data.tty); | ||
1012 | |||
1013 | done: | ||
1014 | return count; | ||
1015 | } | ||
1016 | static DEVICE_ATTR(events, S_IRUSR | S_IWUSR, show_events, store_events); | ||
1017 | |||
1018 | /** | ||
1019 | * show_inters: interrupt status, enable status and historic | ||
1020 | * | ||
1021 | * Check "device.h" for details | ||
1022 | */ | ||
1023 | static ssize_t show_inters(struct device *dev, struct device_attribute *attr, | ||
1024 | char *buf) | ||
1025 | { | ||
1026 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1027 | unsigned long flags; | ||
1028 | u32 intr; | ||
1029 | unsigned i, j, n = 0; | ||
1030 | |||
1031 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1032 | if (attr == NULL || buf == NULL) { | ||
1033 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1034 | return 0; | ||
1035 | } | ||
1036 | |||
1037 | spin_lock_irqsave(udc->lock, flags); | ||
1038 | |||
1039 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1040 | "status = %08x\n", hw_read_intr_status()); | ||
1041 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1042 | "enable = %08x\n", hw_read_intr_enable()); | ||
1043 | |||
1044 | n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n", | ||
1045 | isr_statistics.test); | ||
1046 | n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n", | ||
1047 | isr_statistics.ui); | ||
1048 | n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n", | ||
1049 | isr_statistics.uei); | ||
1050 | n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n", | ||
1051 | isr_statistics.pci); | ||
1052 | n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n", | ||
1053 | isr_statistics.uri); | ||
1054 | n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n", | ||
1055 | isr_statistics.sli); | ||
1056 | n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n", | ||
1057 | isr_statistics.none); | ||
1058 | n += scnprintf(buf + n, PAGE_SIZE - n, "*hndl = %d\n", | ||
1059 | isr_statistics.hndl.cnt); | ||
1060 | |||
1061 | for (i = isr_statistics.hndl.idx, j = 0; j <= ISR_MASK; j++, i++) { | ||
1062 | i &= ISR_MASK; | ||
1063 | intr = isr_statistics.hndl.buf[i]; | ||
1064 | |||
1065 | if (USBi_UI & intr) | ||
1066 | n += scnprintf(buf + n, PAGE_SIZE - n, "ui "); | ||
1067 | intr &= ~USBi_UI; | ||
1068 | if (USBi_UEI & intr) | ||
1069 | n += scnprintf(buf + n, PAGE_SIZE - n, "uei "); | ||
1070 | intr &= ~USBi_UEI; | ||
1071 | if (USBi_PCI & intr) | ||
1072 | n += scnprintf(buf + n, PAGE_SIZE - n, "pci "); | ||
1073 | intr &= ~USBi_PCI; | ||
1074 | if (USBi_URI & intr) | ||
1075 | n += scnprintf(buf + n, PAGE_SIZE - n, "uri "); | ||
1076 | intr &= ~USBi_URI; | ||
1077 | if (USBi_SLI & intr) | ||
1078 | n += scnprintf(buf + n, PAGE_SIZE - n, "sli "); | ||
1079 | intr &= ~USBi_SLI; | ||
1080 | if (intr) | ||
1081 | n += scnprintf(buf + n, PAGE_SIZE - n, "??? "); | ||
1082 | if (isr_statistics.hndl.buf[i]) | ||
1083 | n += scnprintf(buf + n, PAGE_SIZE - n, "\n"); | ||
1084 | } | ||
1085 | |||
1086 | spin_unlock_irqrestore(udc->lock, flags); | ||
1087 | |||
1088 | return n; | ||
1089 | } | ||
1090 | |||
1091 | /** | ||
1092 | * store_inters: enable & force or disable an individual interrutps | ||
1093 | * (to be used for test purposes only) | ||
1094 | * | ||
1095 | * Check "device.h" for details | ||
1096 | */ | ||
1097 | static ssize_t store_inters(struct device *dev, struct device_attribute *attr, | ||
1098 | const char *buf, size_t count) | ||
1099 | { | ||
1100 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1101 | unsigned long flags; | ||
1102 | unsigned en, bit; | ||
1103 | |||
1104 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1105 | if (attr == NULL || buf == NULL) { | ||
1106 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1107 | goto done; | ||
1108 | } | ||
1109 | |||
1110 | if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) { | ||
1111 | dev_err(dev, "<1|0> <bit>: enable|disable interrupt"); | ||
1112 | goto done; | ||
1113 | } | ||
1114 | |||
1115 | spin_lock_irqsave(udc->lock, flags); | ||
1116 | if (en) { | ||
1117 | if (hw_intr_force(bit)) | ||
1118 | dev_err(dev, "invalid bit number\n"); | ||
1119 | else | ||
1120 | isr_statistics.test++; | ||
1121 | } else { | ||
1122 | if (hw_intr_clear(bit)) | ||
1123 | dev_err(dev, "invalid bit number\n"); | ||
1124 | } | ||
1125 | spin_unlock_irqrestore(udc->lock, flags); | ||
1126 | |||
1127 | done: | ||
1128 | return count; | ||
1129 | } | ||
1130 | static DEVICE_ATTR(inters, S_IRUSR | S_IWUSR, show_inters, store_inters); | ||
1131 | |||
1132 | /** | ||
1133 | * show_port_test: reads port test mode | ||
1134 | * | ||
1135 | * Check "device.h" for details | ||
1136 | */ | ||
1137 | static ssize_t show_port_test(struct device *dev, | ||
1138 | struct device_attribute *attr, char *buf) | ||
1139 | { | ||
1140 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1141 | unsigned long flags; | ||
1142 | unsigned mode; | ||
1143 | |||
1144 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1145 | if (attr == NULL || buf == NULL) { | ||
1146 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1147 | return 0; | ||
1148 | } | ||
1149 | |||
1150 | spin_lock_irqsave(udc->lock, flags); | ||
1151 | mode = hw_port_test_get(); | ||
1152 | spin_unlock_irqrestore(udc->lock, flags); | ||
1153 | |||
1154 | return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); | ||
1155 | } | ||
1156 | |||
1157 | /** | ||
1158 | * store_port_test: writes port test mode | ||
1159 | * | ||
1160 | * Check "device.h" for details | ||
1161 | */ | ||
1162 | static ssize_t store_port_test(struct device *dev, | ||
1163 | struct device_attribute *attr, | ||
1164 | const char *buf, size_t count) | ||
1165 | { | ||
1166 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1167 | unsigned long flags; | ||
1168 | unsigned mode; | ||
1169 | |||
1170 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1171 | if (attr == NULL || buf == NULL) { | ||
1172 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1173 | goto done; | ||
1174 | } | ||
1175 | |||
1176 | if (sscanf(buf, "%u", &mode) != 1) { | ||
1177 | dev_err(dev, "<mode>: set port test mode"); | ||
1178 | goto done; | ||
1179 | } | ||
1180 | |||
1181 | spin_lock_irqsave(udc->lock, flags); | ||
1182 | if (hw_port_test_set(mode)) | ||
1183 | dev_err(dev, "invalid mode\n"); | ||
1184 | spin_unlock_irqrestore(udc->lock, flags); | ||
1185 | |||
1186 | done: | ||
1187 | return count; | ||
1188 | } | ||
1189 | static DEVICE_ATTR(port_test, S_IRUSR | S_IWUSR, | ||
1190 | show_port_test, store_port_test); | ||
1191 | |||
1192 | /** | ||
1193 | * show_qheads: DMA contents of all queue heads | ||
1194 | * | ||
1195 | * Check "device.h" for details | ||
1196 | */ | ||
1197 | static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, | ||
1198 | char *buf) | ||
1199 | { | ||
1200 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1201 | unsigned long flags; | ||
1202 | unsigned i, j, n = 0; | ||
1203 | |||
1204 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1205 | if (attr == NULL || buf == NULL) { | ||
1206 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1207 | return 0; | ||
1208 | } | ||
1209 | |||
1210 | spin_lock_irqsave(udc->lock, flags); | ||
1211 | for (i = 0; i < hw_ep_max/2; i++) { | ||
1212 | struct ci13xxx_ep *mEpRx = &udc->ci13xxx_ep[i]; | ||
1213 | struct ci13xxx_ep *mEpTx = &udc->ci13xxx_ep[i + hw_ep_max/2]; | ||
1214 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1215 | "EP=%02i: RX=%08X TX=%08X\n", | ||
1216 | i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma); | ||
1217 | for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) { | ||
1218 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1219 | " %04X: %08X %08X\n", j, | ||
1220 | *((u32 *)mEpRx->qh.ptr + j), | ||
1221 | *((u32 *)mEpTx->qh.ptr + j)); | ||
1222 | } | ||
1223 | } | ||
1224 | spin_unlock_irqrestore(udc->lock, flags); | ||
1225 | |||
1226 | return n; | ||
1227 | } | ||
1228 | static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL); | ||
1229 | |||
1230 | /** | ||
1231 | * show_registers: dumps all registers | ||
1232 | * | ||
1233 | * Check "device.h" for details | ||
1234 | */ | ||
1235 | #define DUMP_ENTRIES 512 | ||
1236 | static ssize_t show_registers(struct device *dev, | ||
1237 | struct device_attribute *attr, char *buf) | ||
1238 | { | ||
1239 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1240 | unsigned long flags; | ||
1241 | u32 *dump; | ||
1242 | unsigned i, k, n = 0; | ||
1243 | |||
1244 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1245 | if (attr == NULL || buf == NULL) { | ||
1246 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1247 | return 0; | ||
1248 | } | ||
1249 | |||
1250 | dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL); | ||
1251 | if (!dump) { | ||
1252 | dev_err(dev, "%s: out of memory\n", __func__); | ||
1253 | return 0; | ||
1254 | } | ||
1255 | |||
1256 | spin_lock_irqsave(udc->lock, flags); | ||
1257 | k = hw_register_read(dump, DUMP_ENTRIES); | ||
1258 | spin_unlock_irqrestore(udc->lock, flags); | ||
1259 | |||
1260 | for (i = 0; i < k; i++) { | ||
1261 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1262 | "reg[0x%04X] = 0x%08X\n", | ||
1263 | i * (unsigned)sizeof(u32), dump[i]); | ||
1264 | } | ||
1265 | kfree(dump); | ||
1266 | |||
1267 | return n; | ||
1268 | } | ||
1269 | |||
1270 | /** | ||
1271 | * store_registers: writes value to register address | ||
1272 | * | ||
1273 | * Check "device.h" for details | ||
1274 | */ | ||
1275 | static ssize_t store_registers(struct device *dev, | ||
1276 | struct device_attribute *attr, | ||
1277 | const char *buf, size_t count) | ||
1278 | { | ||
1279 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1280 | unsigned long addr, data, flags; | ||
1281 | |||
1282 | dbg_trace("[%s] %p, %d\n", __func__, buf, count); | ||
1283 | if (attr == NULL || buf == NULL) { | ||
1284 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1285 | goto done; | ||
1286 | } | ||
1287 | |||
1288 | if (sscanf(buf, "%li %li", &addr, &data) != 2) { | ||
1289 | dev_err(dev, "<addr> <data>: write data to register address"); | ||
1290 | goto done; | ||
1291 | } | ||
1292 | |||
1293 | spin_lock_irqsave(udc->lock, flags); | ||
1294 | if (hw_register_write(addr, data)) | ||
1295 | dev_err(dev, "invalid address range\n"); | ||
1296 | spin_unlock_irqrestore(udc->lock, flags); | ||
1297 | |||
1298 | done: | ||
1299 | return count; | ||
1300 | } | ||
1301 | static DEVICE_ATTR(registers, S_IRUSR | S_IWUSR, | ||
1302 | show_registers, store_registers); | ||
1303 | |||
1304 | /** | ||
1305 | * show_requests: DMA contents of all requests currently queued (all endpts) | ||
1306 | * | ||
1307 | * Check "device.h" for details | ||
1308 | */ | ||
1309 | static ssize_t show_requests(struct device *dev, struct device_attribute *attr, | ||
1310 | char *buf) | ||
1311 | { | ||
1312 | struct ci13xxx *udc = container_of(dev, struct ci13xxx, gadget.dev); | ||
1313 | unsigned long flags; | ||
1314 | struct list_head *ptr = NULL; | ||
1315 | struct ci13xxx_req *req = NULL; | ||
1316 | unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); | ||
1317 | |||
1318 | dbg_trace("[%s] %p\n", __func__, buf); | ||
1319 | if (attr == NULL || buf == NULL) { | ||
1320 | dev_err(dev, "[%s] EINVAL\n", __func__); | ||
1321 | return 0; | ||
1322 | } | ||
1323 | |||
1324 | spin_lock_irqsave(udc->lock, flags); | ||
1325 | for (i = 0; i < hw_ep_max; i++) | ||
1326 | list_for_each(ptr, &udc->ci13xxx_ep[i].qh.queue) | ||
1327 | { | ||
1328 | req = list_entry(ptr, struct ci13xxx_req, queue); | ||
1329 | |||
1330 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1331 | "EP=%02i: TD=%08X %s\n", | ||
1332 | i % hw_ep_max/2, (u32)req->dma, | ||
1333 | ((i < hw_ep_max/2) ? "RX" : "TX")); | ||
1334 | |||
1335 | for (j = 0; j < qSize; j++) | ||
1336 | n += scnprintf(buf + n, PAGE_SIZE - n, | ||
1337 | " %04X: %08X\n", j, | ||
1338 | *((u32 *)req->ptr + j)); | ||
1339 | } | ||
1340 | spin_unlock_irqrestore(udc->lock, flags); | ||
1341 | |||
1342 | return n; | ||
1343 | } | ||
1344 | static DEVICE_ATTR(requests, S_IRUSR, show_requests, NULL); | ||
1345 | |||
1346 | /** | ||
1347 | * dbg_create_files: initializes the attribute interface | ||
1348 | * @dev: device | ||
1349 | * | ||
1350 | * This function returns an error code | ||
1351 | */ | ||
1352 | __maybe_unused static int dbg_create_files(struct device *dev) | ||
1353 | { | ||
1354 | int retval = 0; | ||
1355 | |||
1356 | if (dev == NULL) | ||
1357 | return -EINVAL; | ||
1358 | retval = device_create_file(dev, &dev_attr_device); | ||
1359 | if (retval) | ||
1360 | goto done; | ||
1361 | retval = device_create_file(dev, &dev_attr_driver); | ||
1362 | if (retval) | ||
1363 | goto rm_device; | ||
1364 | retval = device_create_file(dev, &dev_attr_events); | ||
1365 | if (retval) | ||
1366 | goto rm_driver; | ||
1367 | retval = device_create_file(dev, &dev_attr_inters); | ||
1368 | if (retval) | ||
1369 | goto rm_events; | ||
1370 | retval = device_create_file(dev, &dev_attr_port_test); | ||
1371 | if (retval) | ||
1372 | goto rm_inters; | ||
1373 | retval = device_create_file(dev, &dev_attr_qheads); | ||
1374 | if (retval) | ||
1375 | goto rm_port_test; | ||
1376 | retval = device_create_file(dev, &dev_attr_registers); | ||
1377 | if (retval) | ||
1378 | goto rm_qheads; | ||
1379 | retval = device_create_file(dev, &dev_attr_requests); | ||
1380 | if (retval) | ||
1381 | goto rm_registers; | ||
1382 | return 0; | ||
1383 | |||
1384 | rm_registers: | ||
1385 | device_remove_file(dev, &dev_attr_registers); | ||
1386 | rm_qheads: | ||
1387 | device_remove_file(dev, &dev_attr_qheads); | ||
1388 | rm_port_test: | ||
1389 | device_remove_file(dev, &dev_attr_port_test); | ||
1390 | rm_inters: | ||
1391 | device_remove_file(dev, &dev_attr_inters); | ||
1392 | rm_events: | ||
1393 | device_remove_file(dev, &dev_attr_events); | ||
1394 | rm_driver: | ||
1395 | device_remove_file(dev, &dev_attr_driver); | ||
1396 | rm_device: | ||
1397 | device_remove_file(dev, &dev_attr_device); | ||
1398 | done: | ||
1399 | return retval; | ||
1400 | } | ||
1401 | |||
1402 | /** | ||
1403 | * dbg_remove_files: destroys the attribute interface | ||
1404 | * @dev: device | ||
1405 | * | ||
1406 | * This function returns an error code | ||
1407 | */ | ||
1408 | __maybe_unused static int dbg_remove_files(struct device *dev) | ||
1409 | { | ||
1410 | if (dev == NULL) | ||
1411 | return -EINVAL; | ||
1412 | device_remove_file(dev, &dev_attr_requests); | ||
1413 | device_remove_file(dev, &dev_attr_registers); | ||
1414 | device_remove_file(dev, &dev_attr_qheads); | ||
1415 | device_remove_file(dev, &dev_attr_port_test); | ||
1416 | device_remove_file(dev, &dev_attr_inters); | ||
1417 | device_remove_file(dev, &dev_attr_events); | ||
1418 | device_remove_file(dev, &dev_attr_driver); | ||
1419 | device_remove_file(dev, &dev_attr_device); | ||
1420 | return 0; | ||
1421 | } | ||
1422 | |||
1423 | /****************************************************************************** | ||
1424 | * UTIL block | ||
1425 | *****************************************************************************/ | ||
1426 | /** | ||
1427 | * _usb_addr: calculates endpoint address from direction & number | ||
1428 | * @ep: endpoint | ||
1429 | */ | ||
1430 | static inline u8 _usb_addr(struct ci13xxx_ep *ep) | ||
1431 | { | ||
1432 | return ((ep->dir == TX) ? USB_ENDPOINT_DIR_MASK : 0) | ep->num; | ||
1433 | } | ||
1434 | |||
1435 | /** | ||
1436 | * _hardware_queue: configures a request at hardware level | ||
1437 | * @gadget: gadget | ||
1438 | * @mEp: endpoint | ||
1439 | * | ||
1440 | * This function returns an error code | ||
1441 | */ | ||
1442 | static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | ||
1443 | { | ||
1444 | unsigned i; | ||
1445 | int ret = 0; | ||
1446 | unsigned length = mReq->req.length; | ||
1447 | |||
1448 | trace("%p, %p", mEp, mReq); | ||
1449 | |||
1450 | /* don't queue twice */ | ||
1451 | if (mReq->req.status == -EALREADY) | ||
1452 | return -EALREADY; | ||
1453 | |||
1454 | mReq->req.status = -EALREADY; | ||
1455 | if (length && mReq->req.dma == DMA_ADDR_INVALID) { | ||
1456 | mReq->req.dma = \ | ||
1457 | dma_map_single(mEp->device, mReq->req.buf, | ||
1458 | length, mEp->dir ? DMA_TO_DEVICE : | ||
1459 | DMA_FROM_DEVICE); | ||
1460 | if (mReq->req.dma == 0) | ||
1461 | return -ENOMEM; | ||
1462 | |||
1463 | mReq->map = 1; | ||
1464 | } | ||
1465 | |||
1466 | if (mReq->req.zero && length && (length % mEp->ep.maxpacket == 0)) { | ||
1467 | mReq->zptr = dma_pool_alloc(mEp->td_pool, GFP_ATOMIC, | ||
1468 | &mReq->zdma); | ||
1469 | if (mReq->zptr == NULL) { | ||
1470 | if (mReq->map) { | ||
1471 | dma_unmap_single(mEp->device, mReq->req.dma, | ||
1472 | length, mEp->dir ? DMA_TO_DEVICE : | ||
1473 | DMA_FROM_DEVICE); | ||
1474 | mReq->req.dma = DMA_ADDR_INVALID; | ||
1475 | mReq->map = 0; | ||
1476 | } | ||
1477 | return -ENOMEM; | ||
1478 | } | ||
1479 | memset(mReq->zptr, 0, sizeof(*mReq->zptr)); | ||
1480 | mReq->zptr->next = TD_TERMINATE; | ||
1481 | mReq->zptr->token = TD_STATUS_ACTIVE; | ||
1482 | if (!mReq->req.no_interrupt) | ||
1483 | mReq->zptr->token |= TD_IOC; | ||
1484 | } | ||
1485 | /* | ||
1486 | * TD configuration | ||
1487 | * TODO - handle requests which spawns into several TDs | ||
1488 | */ | ||
1489 | memset(mReq->ptr, 0, sizeof(*mReq->ptr)); | ||
1490 | mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES); | ||
1491 | mReq->ptr->token &= TD_TOTAL_BYTES; | ||
1492 | mReq->ptr->token |= TD_STATUS_ACTIVE; | ||
1493 | if (mReq->zptr) { | ||
1494 | mReq->ptr->next = mReq->zdma; | ||
1495 | } else { | ||
1496 | mReq->ptr->next = TD_TERMINATE; | ||
1497 | if (!mReq->req.no_interrupt) | ||
1498 | mReq->ptr->token |= TD_IOC; | ||
1499 | } | ||
1500 | mReq->ptr->page[0] = mReq->req.dma; | ||
1501 | for (i = 1; i < 5; i++) | ||
1502 | mReq->ptr->page[i] = | ||
1503 | (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK; | ||
1504 | |||
1505 | if (!list_empty(&mEp->qh.queue)) { | ||
1506 | struct ci13xxx_req *mReqPrev; | ||
1507 | int n = hw_ep_bit(mEp->num, mEp->dir); | ||
1508 | int tmp_stat; | ||
1509 | |||
1510 | mReqPrev = list_entry(mEp->qh.queue.prev, | ||
1511 | struct ci13xxx_req, queue); | ||
1512 | if (mReqPrev->zptr) | ||
1513 | mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK; | ||
1514 | else | ||
1515 | mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; | ||
1516 | wmb(); | ||
1517 | if (hw_cread(CAP_ENDPTPRIME, BIT(n))) | ||
1518 | goto done; | ||
1519 | do { | ||
1520 | hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); | ||
1521 | tmp_stat = hw_cread(CAP_ENDPTSTAT, BIT(n)); | ||
1522 | } while (!hw_cread(CAP_USBCMD, USBCMD_ATDTW)); | ||
1523 | hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, 0); | ||
1524 | if (tmp_stat) | ||
1525 | goto done; | ||
1526 | } | ||
1527 | |||
1528 | /* QH configuration */ | ||
1529 | mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ | ||
1530 | mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ | ||
1531 | mEp->qh.ptr->cap |= QH_ZLT; | ||
1532 | |||
1533 | wmb(); /* synchronize before ep prime */ | ||
1534 | |||
1535 | ret = hw_ep_prime(mEp->num, mEp->dir, | ||
1536 | mEp->type == USB_ENDPOINT_XFER_CONTROL); | ||
1537 | done: | ||
1538 | return ret; | ||
1539 | } | ||
1540 | |||
1541 | /** | ||
1542 | * _hardware_dequeue: handles a request at hardware level | ||
1543 | * @gadget: gadget | ||
1544 | * @mEp: endpoint | ||
1545 | * | ||
1546 | * This function returns an error code | ||
1547 | */ | ||
1548 | static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | ||
1549 | { | ||
1550 | trace("%p, %p", mEp, mReq); | ||
1551 | |||
1552 | if (mReq->req.status != -EALREADY) | ||
1553 | return -EINVAL; | ||
1554 | |||
1555 | if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0) | ||
1556 | return -EBUSY; | ||
1557 | |||
1558 | if (mReq->zptr) { | ||
1559 | if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0) | ||
1560 | return -EBUSY; | ||
1561 | dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma); | ||
1562 | mReq->zptr = NULL; | ||
1563 | } | ||
1564 | |||
1565 | mReq->req.status = 0; | ||
1566 | |||
1567 | if (mReq->map) { | ||
1568 | dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, | ||
1569 | mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
1570 | mReq->req.dma = DMA_ADDR_INVALID; | ||
1571 | mReq->map = 0; | ||
1572 | } | ||
1573 | |||
1574 | mReq->req.status = mReq->ptr->token & TD_STATUS; | ||
1575 | if ((TD_STATUS_HALTED & mReq->req.status) != 0) | ||
1576 | mReq->req.status = -1; | ||
1577 | else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) | ||
1578 | mReq->req.status = -1; | ||
1579 | else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0) | ||
1580 | mReq->req.status = -1; | ||
1581 | |||
1582 | mReq->req.actual = mReq->ptr->token & TD_TOTAL_BYTES; | ||
1583 | mReq->req.actual >>= ffs_nr(TD_TOTAL_BYTES); | ||
1584 | mReq->req.actual = mReq->req.length - mReq->req.actual; | ||
1585 | mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual; | ||
1586 | |||
1587 | return mReq->req.actual; | ||
1588 | } | ||
1589 | |||
1590 | /** | ||
1591 | * _ep_nuke: dequeues all endpoint requests | ||
1592 | * @mEp: endpoint | ||
1593 | * | ||
1594 | * This function returns an error code | ||
1595 | * Caller must hold lock | ||
1596 | */ | ||
1597 | static int _ep_nuke(struct ci13xxx_ep *mEp) | ||
1598 | __releases(mEp->lock) | ||
1599 | __acquires(mEp->lock) | ||
1600 | { | ||
1601 | trace("%p", mEp); | ||
1602 | |||
1603 | if (mEp == NULL) | ||
1604 | return -EINVAL; | ||
1605 | |||
1606 | hw_ep_flush(mEp->num, mEp->dir); | ||
1607 | |||
1608 | while (!list_empty(&mEp->qh.queue)) { | ||
1609 | |||
1610 | /* pop oldest request */ | ||
1611 | struct ci13xxx_req *mReq = \ | ||
1612 | list_entry(mEp->qh.queue.next, | ||
1613 | struct ci13xxx_req, queue); | ||
1614 | list_del_init(&mReq->queue); | ||
1615 | mReq->req.status = -ESHUTDOWN; | ||
1616 | |||
1617 | if (mReq->req.complete != NULL) { | ||
1618 | spin_unlock(mEp->lock); | ||
1619 | mReq->req.complete(&mEp->ep, &mReq->req); | ||
1620 | spin_lock(mEp->lock); | ||
1621 | } | ||
1622 | } | ||
1623 | return 0; | ||
1624 | } | ||
1625 | |||
1626 | /** | ||
1627 | * _gadget_stop_activity: stops all USB activity, flushes & disables all endpts | ||
1628 | * @gadget: gadget | ||
1629 | * | ||
1630 | * This function returns an error code | ||
1631 | */ | ||
1632 | static int _gadget_stop_activity(struct usb_gadget *gadget) | ||
1633 | { | ||
1634 | struct usb_ep *ep; | ||
1635 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); | ||
1636 | unsigned long flags; | ||
1637 | |||
1638 | trace("%p", gadget); | ||
1639 | |||
1640 | if (gadget == NULL) | ||
1641 | return -EINVAL; | ||
1642 | |||
1643 | spin_lock_irqsave(udc->lock, flags); | ||
1644 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1645 | udc->remote_wakeup = 0; | ||
1646 | udc->suspended = 0; | ||
1647 | spin_unlock_irqrestore(udc->lock, flags); | ||
1648 | |||
1649 | /* flush all endpoints */ | ||
1650 | gadget_for_each_ep(ep, gadget) { | ||
1651 | usb_ep_fifo_flush(ep); | ||
1652 | } | ||
1653 | usb_ep_fifo_flush(&udc->ep0out.ep); | ||
1654 | usb_ep_fifo_flush(&udc->ep0in.ep); | ||
1655 | |||
1656 | udc->driver->disconnect(gadget); | ||
1657 | |||
1658 | /* make sure to disable all endpoints */ | ||
1659 | gadget_for_each_ep(ep, gadget) { | ||
1660 | usb_ep_disable(ep); | ||
1661 | } | ||
1662 | |||
1663 | if (udc->status != NULL) { | ||
1664 | usb_ep_free_request(&udc->ep0in.ep, udc->status); | ||
1665 | udc->status = NULL; | ||
1666 | } | ||
1667 | |||
1668 | return 0; | ||
1669 | } | ||
1670 | |||
1671 | /****************************************************************************** | ||
1672 | * ISR block | ||
1673 | *****************************************************************************/ | ||
1674 | /** | ||
1675 | * isr_reset_handler: USB reset interrupt handler | ||
1676 | * @udc: UDC device | ||
1677 | * | ||
1678 | * This function resets USB engine after a bus reset occurred | ||
1679 | */ | ||
1680 | static void isr_reset_handler(struct ci13xxx *udc) | ||
1681 | __releases(udc->lock) | ||
1682 | __acquires(udc->lock) | ||
1683 | { | ||
1684 | int retval; | ||
1685 | |||
1686 | trace("%p", udc); | ||
1687 | |||
1688 | if (udc == NULL) { | ||
1689 | err("EINVAL"); | ||
1690 | return; | ||
1691 | } | ||
1692 | |||
1693 | dbg_event(0xFF, "BUS RST", 0); | ||
1694 | |||
1695 | spin_unlock(udc->lock); | ||
1696 | retval = _gadget_stop_activity(&udc->gadget); | ||
1697 | if (retval) | ||
1698 | goto done; | ||
1699 | |||
1700 | retval = hw_usb_reset(); | ||
1701 | if (retval) | ||
1702 | goto done; | ||
1703 | |||
1704 | udc->status = usb_ep_alloc_request(&udc->ep0in.ep, GFP_ATOMIC); | ||
1705 | if (udc->status == NULL) | ||
1706 | retval = -ENOMEM; | ||
1707 | |||
1708 | spin_lock(udc->lock); | ||
1709 | |||
1710 | done: | ||
1711 | if (retval) | ||
1712 | err("error: %i", retval); | ||
1713 | } | ||
1714 | |||
1715 | /** | ||
1716 | * isr_get_status_complete: get_status request complete function | ||
1717 | * @ep: endpoint | ||
1718 | * @req: request handled | ||
1719 | * | ||
1720 | * Caller must release lock | ||
1721 | */ | ||
1722 | static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req) | ||
1723 | { | ||
1724 | trace("%p, %p", ep, req); | ||
1725 | |||
1726 | if (ep == NULL || req == NULL) { | ||
1727 | err("EINVAL"); | ||
1728 | return; | ||
1729 | } | ||
1730 | |||
1731 | kfree(req->buf); | ||
1732 | usb_ep_free_request(ep, req); | ||
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * isr_get_status_response: get_status request response | ||
1737 | * @udc: udc struct | ||
1738 | * @setup: setup request packet | ||
1739 | * | ||
1740 | * This function returns an error code | ||
1741 | */ | ||
1742 | static int isr_get_status_response(struct ci13xxx *udc, | ||
1743 | struct usb_ctrlrequest *setup) | ||
1744 | __releases(mEp->lock) | ||
1745 | __acquires(mEp->lock) | ||
1746 | { | ||
1747 | struct ci13xxx_ep *mEp = &udc->ep0in; | ||
1748 | struct usb_request *req = NULL; | ||
1749 | gfp_t gfp_flags = GFP_ATOMIC; | ||
1750 | int dir, num, retval; | ||
1751 | |||
1752 | trace("%p, %p", mEp, setup); | ||
1753 | |||
1754 | if (mEp == NULL || setup == NULL) | ||
1755 | return -EINVAL; | ||
1756 | |||
1757 | spin_unlock(mEp->lock); | ||
1758 | req = usb_ep_alloc_request(&mEp->ep, gfp_flags); | ||
1759 | spin_lock(mEp->lock); | ||
1760 | if (req == NULL) | ||
1761 | return -ENOMEM; | ||
1762 | |||
1763 | req->complete = isr_get_status_complete; | ||
1764 | req->length = 2; | ||
1765 | req->buf = kzalloc(req->length, gfp_flags); | ||
1766 | if (req->buf == NULL) { | ||
1767 | retval = -ENOMEM; | ||
1768 | goto err_free_req; | ||
1769 | } | ||
1770 | |||
1771 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
1772 | /* Assume that device is bus powered for now. */ | ||
1773 | *((u16 *)req->buf) = _udc->remote_wakeup << 1; | ||
1774 | retval = 0; | ||
1775 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ | ||
1776 | == USB_RECIP_ENDPOINT) { | ||
1777 | dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? | ||
1778 | TX : RX; | ||
1779 | num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK; | ||
1780 | *((u16 *)req->buf) = hw_ep_get_halt(num, dir); | ||
1781 | } | ||
1782 | /* else do nothing; reserved for future use */ | ||
1783 | |||
1784 | spin_unlock(mEp->lock); | ||
1785 | retval = usb_ep_queue(&mEp->ep, req, gfp_flags); | ||
1786 | spin_lock(mEp->lock); | ||
1787 | if (retval) | ||
1788 | goto err_free_buf; | ||
1789 | |||
1790 | return 0; | ||
1791 | |||
1792 | err_free_buf: | ||
1793 | kfree(req->buf); | ||
1794 | err_free_req: | ||
1795 | spin_unlock(mEp->lock); | ||
1796 | usb_ep_free_request(&mEp->ep, req); | ||
1797 | spin_lock(mEp->lock); | ||
1798 | return retval; | ||
1799 | } | ||
1800 | |||
1801 | /** | ||
1802 | * isr_setup_status_complete: setup_status request complete function | ||
1803 | * @ep: endpoint | ||
1804 | * @req: request handled | ||
1805 | * | ||
1806 | * Caller must release lock. Put the port in test mode if test mode | ||
1807 | * feature is selected. | ||
1808 | */ | ||
1809 | static void | ||
1810 | isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req) | ||
1811 | { | ||
1812 | struct ci13xxx *udc = req->context; | ||
1813 | unsigned long flags; | ||
1814 | |||
1815 | trace("%p, %p", ep, req); | ||
1816 | |||
1817 | spin_lock_irqsave(udc->lock, flags); | ||
1818 | if (udc->test_mode) | ||
1819 | hw_port_test_set(udc->test_mode); | ||
1820 | spin_unlock_irqrestore(udc->lock, flags); | ||
1821 | } | ||
1822 | |||
1823 | /** | ||
1824 | * isr_setup_status_phase: queues the status phase of a setup transation | ||
1825 | * @udc: udc struct | ||
1826 | * | ||
1827 | * This function returns an error code | ||
1828 | */ | ||
1829 | static int isr_setup_status_phase(struct ci13xxx *udc) | ||
1830 | __releases(mEp->lock) | ||
1831 | __acquires(mEp->lock) | ||
1832 | { | ||
1833 | int retval; | ||
1834 | struct ci13xxx_ep *mEp; | ||
1835 | |||
1836 | trace("%p", udc); | ||
1837 | |||
1838 | mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in; | ||
1839 | udc->status->context = udc; | ||
1840 | udc->status->complete = isr_setup_status_complete; | ||
1841 | |||
1842 | spin_unlock(mEp->lock); | ||
1843 | retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC); | ||
1844 | spin_lock(mEp->lock); | ||
1845 | |||
1846 | return retval; | ||
1847 | } | ||
1848 | |||
1849 | /** | ||
1850 | * isr_tr_complete_low: transaction complete low level handler | ||
1851 | * @mEp: endpoint | ||
1852 | * | ||
1853 | * This function returns an error code | ||
1854 | * Caller must hold lock | ||
1855 | */ | ||
1856 | static int isr_tr_complete_low(struct ci13xxx_ep *mEp) | ||
1857 | __releases(mEp->lock) | ||
1858 | __acquires(mEp->lock) | ||
1859 | { | ||
1860 | struct ci13xxx_req *mReq, *mReqTemp; | ||
1861 | struct ci13xxx_ep *mEpTemp = mEp; | ||
1862 | int uninitialized_var(retval); | ||
1863 | |||
1864 | trace("%p", mEp); | ||
1865 | |||
1866 | if (list_empty(&mEp->qh.queue)) | ||
1867 | return -EINVAL; | ||
1868 | |||
1869 | list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue, | ||
1870 | queue) { | ||
1871 | retval = _hardware_dequeue(mEp, mReq); | ||
1872 | if (retval < 0) | ||
1873 | break; | ||
1874 | list_del_init(&mReq->queue); | ||
1875 | dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); | ||
1876 | if (mReq->req.complete != NULL) { | ||
1877 | spin_unlock(mEp->lock); | ||
1878 | if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) && | ||
1879 | mReq->req.length) | ||
1880 | mEpTemp = &_udc->ep0in; | ||
1881 | mReq->req.complete(&mEpTemp->ep, &mReq->req); | ||
1882 | spin_lock(mEp->lock); | ||
1883 | } | ||
1884 | } | ||
1885 | |||
1886 | if (retval == -EBUSY) | ||
1887 | retval = 0; | ||
1888 | if (retval < 0) | ||
1889 | dbg_event(_usb_addr(mEp), "DONE", retval); | ||
1890 | |||
1891 | return retval; | ||
1892 | } | ||
1893 | |||
1894 | /** | ||
1895 | * isr_tr_complete_handler: transaction complete interrupt handler | ||
1896 | * @udc: UDC descriptor | ||
1897 | * | ||
1898 | * This function handles traffic events | ||
1899 | */ | ||
1900 | static void isr_tr_complete_handler(struct ci13xxx *udc) | ||
1901 | __releases(udc->lock) | ||
1902 | __acquires(udc->lock) | ||
1903 | { | ||
1904 | unsigned i; | ||
1905 | u8 tmode = 0; | ||
1906 | |||
1907 | trace("%p", udc); | ||
1908 | |||
1909 | if (udc == NULL) { | ||
1910 | err("EINVAL"); | ||
1911 | return; | ||
1912 | } | ||
1913 | |||
1914 | for (i = 0; i < hw_ep_max; i++) { | ||
1915 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
1916 | int type, num, dir, err = -EINVAL; | ||
1917 | struct usb_ctrlrequest req; | ||
1918 | |||
1919 | if (mEp->desc == NULL) | ||
1920 | continue; /* not configured */ | ||
1921 | |||
1922 | if (hw_test_and_clear_complete(i)) { | ||
1923 | err = isr_tr_complete_low(mEp); | ||
1924 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { | ||
1925 | if (err > 0) /* needs status phase */ | ||
1926 | err = isr_setup_status_phase(udc); | ||
1927 | if (err < 0) { | ||
1928 | dbg_event(_usb_addr(mEp), | ||
1929 | "ERROR", err); | ||
1930 | spin_unlock(udc->lock); | ||
1931 | if (usb_ep_set_halt(&mEp->ep)) | ||
1932 | err("error: ep_set_halt"); | ||
1933 | spin_lock(udc->lock); | ||
1934 | } | ||
1935 | } | ||
1936 | } | ||
1937 | |||
1938 | if (mEp->type != USB_ENDPOINT_XFER_CONTROL || | ||
1939 | !hw_test_and_clear_setup_status(i)) | ||
1940 | continue; | ||
1941 | |||
1942 | if (i != 0) { | ||
1943 | warn("ctrl traffic received at endpoint"); | ||
1944 | continue; | ||
1945 | } | ||
1946 | |||
1947 | /* | ||
1948 | * Flush data and handshake transactions of previous | ||
1949 | * setup packet. | ||
1950 | */ | ||
1951 | _ep_nuke(&udc->ep0out); | ||
1952 | _ep_nuke(&udc->ep0in); | ||
1953 | |||
1954 | /* read_setup_packet */ | ||
1955 | do { | ||
1956 | hw_test_and_set_setup_guard(); | ||
1957 | memcpy(&req, &mEp->qh.ptr->setup, sizeof(req)); | ||
1958 | } while (!hw_test_and_clear_setup_guard()); | ||
1959 | |||
1960 | type = req.bRequestType; | ||
1961 | |||
1962 | udc->ep0_dir = (type & USB_DIR_IN) ? TX : RX; | ||
1963 | |||
1964 | dbg_setup(_usb_addr(mEp), &req); | ||
1965 | |||
1966 | switch (req.bRequest) { | ||
1967 | case USB_REQ_CLEAR_FEATURE: | ||
1968 | if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | ||
1969 | le16_to_cpu(req.wValue) == | ||
1970 | USB_ENDPOINT_HALT) { | ||
1971 | if (req.wLength != 0) | ||
1972 | break; | ||
1973 | num = le16_to_cpu(req.wIndex); | ||
1974 | dir = num & USB_ENDPOINT_DIR_MASK; | ||
1975 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
1976 | if (dir) /* TX */ | ||
1977 | num += hw_ep_max/2; | ||
1978 | if (!udc->ci13xxx_ep[num].wedge) { | ||
1979 | spin_unlock(udc->lock); | ||
1980 | err = usb_ep_clear_halt( | ||
1981 | &udc->ci13xxx_ep[num].ep); | ||
1982 | spin_lock(udc->lock); | ||
1983 | if (err) | ||
1984 | break; | ||
1985 | } | ||
1986 | err = isr_setup_status_phase(udc); | ||
1987 | } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) && | ||
1988 | le16_to_cpu(req.wValue) == | ||
1989 | USB_DEVICE_REMOTE_WAKEUP) { | ||
1990 | if (req.wLength != 0) | ||
1991 | break; | ||
1992 | udc->remote_wakeup = 0; | ||
1993 | err = isr_setup_status_phase(udc); | ||
1994 | } else { | ||
1995 | goto delegate; | ||
1996 | } | ||
1997 | break; | ||
1998 | case USB_REQ_GET_STATUS: | ||
1999 | if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && | ||
2000 | type != (USB_DIR_IN|USB_RECIP_ENDPOINT) && | ||
2001 | type != (USB_DIR_IN|USB_RECIP_INTERFACE)) | ||
2002 | goto delegate; | ||
2003 | if (le16_to_cpu(req.wLength) != 2 || | ||
2004 | le16_to_cpu(req.wValue) != 0) | ||
2005 | break; | ||
2006 | err = isr_get_status_response(udc, &req); | ||
2007 | break; | ||
2008 | case USB_REQ_SET_ADDRESS: | ||
2009 | if (type != (USB_DIR_OUT|USB_RECIP_DEVICE)) | ||
2010 | goto delegate; | ||
2011 | if (le16_to_cpu(req.wLength) != 0 || | ||
2012 | le16_to_cpu(req.wIndex) != 0) | ||
2013 | break; | ||
2014 | err = hw_usb_set_address((u8)le16_to_cpu(req.wValue)); | ||
2015 | if (err) | ||
2016 | break; | ||
2017 | err = isr_setup_status_phase(udc); | ||
2018 | break; | ||
2019 | case USB_REQ_SET_FEATURE: | ||
2020 | if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | ||
2021 | le16_to_cpu(req.wValue) == | ||
2022 | USB_ENDPOINT_HALT) { | ||
2023 | if (req.wLength != 0) | ||
2024 | break; | ||
2025 | num = le16_to_cpu(req.wIndex); | ||
2026 | dir = num & USB_ENDPOINT_DIR_MASK; | ||
2027 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
2028 | if (dir) /* TX */ | ||
2029 | num += hw_ep_max/2; | ||
2030 | |||
2031 | spin_unlock(udc->lock); | ||
2032 | err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); | ||
2033 | spin_lock(udc->lock); | ||
2034 | if (!err) | ||
2035 | isr_setup_status_phase(udc); | ||
2036 | } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) { | ||
2037 | if (req.wLength != 0) | ||
2038 | break; | ||
2039 | switch (le16_to_cpu(req.wValue)) { | ||
2040 | case USB_DEVICE_REMOTE_WAKEUP: | ||
2041 | udc->remote_wakeup = 1; | ||
2042 | err = isr_setup_status_phase(udc); | ||
2043 | break; | ||
2044 | case USB_DEVICE_TEST_MODE: | ||
2045 | tmode = le16_to_cpu(req.wIndex) >> 8; | ||
2046 | switch (tmode) { | ||
2047 | case TEST_J: | ||
2048 | case TEST_K: | ||
2049 | case TEST_SE0_NAK: | ||
2050 | case TEST_PACKET: | ||
2051 | case TEST_FORCE_EN: | ||
2052 | udc->test_mode = tmode; | ||
2053 | err = isr_setup_status_phase( | ||
2054 | udc); | ||
2055 | break; | ||
2056 | default: | ||
2057 | break; | ||
2058 | } | ||
2059 | default: | ||
2060 | goto delegate; | ||
2061 | } | ||
2062 | } else { | ||
2063 | goto delegate; | ||
2064 | } | ||
2065 | break; | ||
2066 | default: | ||
2067 | delegate: | ||
2068 | if (req.wLength == 0) /* no data phase */ | ||
2069 | udc->ep0_dir = TX; | ||
2070 | |||
2071 | spin_unlock(udc->lock); | ||
2072 | err = udc->driver->setup(&udc->gadget, &req); | ||
2073 | spin_lock(udc->lock); | ||
2074 | break; | ||
2075 | } | ||
2076 | |||
2077 | if (err < 0) { | ||
2078 | dbg_event(_usb_addr(mEp), "ERROR", err); | ||
2079 | |||
2080 | spin_unlock(udc->lock); | ||
2081 | if (usb_ep_set_halt(&mEp->ep)) | ||
2082 | err("error: ep_set_halt"); | ||
2083 | spin_lock(udc->lock); | ||
2084 | } | ||
2085 | } | ||
2086 | } | ||
2087 | |||
2088 | /****************************************************************************** | ||
2089 | * ENDPT block | ||
2090 | *****************************************************************************/ | ||
2091 | /** | ||
2092 | * ep_enable: configure endpoint, making it usable | ||
2093 | * | ||
2094 | * Check usb_ep_enable() at "usb_gadget.h" for details | ||
2095 | */ | ||
2096 | static int ep_enable(struct usb_ep *ep, | ||
2097 | const struct usb_endpoint_descriptor *desc) | ||
2098 | { | ||
2099 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2100 | int retval = 0; | ||
2101 | unsigned long flags; | ||
2102 | |||
2103 | trace("%p, %p", ep, desc); | ||
2104 | |||
2105 | if (ep == NULL || desc == NULL) | ||
2106 | return -EINVAL; | ||
2107 | |||
2108 | spin_lock_irqsave(mEp->lock, flags); | ||
2109 | |||
2110 | /* only internal SW should enable ctrl endpts */ | ||
2111 | |||
2112 | mEp->desc = desc; | ||
2113 | |||
2114 | if (!list_empty(&mEp->qh.queue)) | ||
2115 | warn("enabling a non-empty endpoint!"); | ||
2116 | |||
2117 | mEp->dir = usb_endpoint_dir_in(desc) ? TX : RX; | ||
2118 | mEp->num = usb_endpoint_num(desc); | ||
2119 | mEp->type = usb_endpoint_type(desc); | ||
2120 | |||
2121 | mEp->ep.maxpacket = usb_endpoint_maxp(desc); | ||
2122 | |||
2123 | dbg_event(_usb_addr(mEp), "ENABLE", 0); | ||
2124 | |||
2125 | mEp->qh.ptr->cap = 0; | ||
2126 | |||
2127 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2128 | mEp->qh.ptr->cap |= QH_IOS; | ||
2129 | else if (mEp->type == USB_ENDPOINT_XFER_ISOC) | ||
2130 | mEp->qh.ptr->cap &= ~QH_MULT; | ||
2131 | else | ||
2132 | mEp->qh.ptr->cap &= ~QH_ZLT; | ||
2133 | |||
2134 | mEp->qh.ptr->cap |= | ||
2135 | (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT; | ||
2136 | mEp->qh.ptr->td.next |= TD_TERMINATE; /* needed? */ | ||
2137 | |||
2138 | /* | ||
2139 | * Enable endpoints in the HW other than ep0 as ep0 | ||
2140 | * is always enabled | ||
2141 | */ | ||
2142 | if (mEp->num) | ||
2143 | retval |= hw_ep_enable(mEp->num, mEp->dir, mEp->type); | ||
2144 | |||
2145 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2146 | return retval; | ||
2147 | } | ||
2148 | |||
2149 | /** | ||
2150 | * ep_disable: endpoint is no longer usable | ||
2151 | * | ||
2152 | * Check usb_ep_disable() at "usb_gadget.h" for details | ||
2153 | */ | ||
2154 | static int ep_disable(struct usb_ep *ep) | ||
2155 | { | ||
2156 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2157 | int direction, retval = 0; | ||
2158 | unsigned long flags; | ||
2159 | |||
2160 | trace("%p", ep); | ||
2161 | |||
2162 | if (ep == NULL) | ||
2163 | return -EINVAL; | ||
2164 | else if (mEp->desc == NULL) | ||
2165 | return -EBUSY; | ||
2166 | |||
2167 | spin_lock_irqsave(mEp->lock, flags); | ||
2168 | |||
2169 | /* only internal SW should disable ctrl endpts */ | ||
2170 | |||
2171 | direction = mEp->dir; | ||
2172 | do { | ||
2173 | dbg_event(_usb_addr(mEp), "DISABLE", 0); | ||
2174 | |||
2175 | retval |= _ep_nuke(mEp); | ||
2176 | retval |= hw_ep_disable(mEp->num, mEp->dir); | ||
2177 | |||
2178 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2179 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
2180 | |||
2181 | } while (mEp->dir != direction); | ||
2182 | |||
2183 | mEp->desc = NULL; | ||
2184 | mEp->ep.desc = NULL; | ||
2185 | |||
2186 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2187 | return retval; | ||
2188 | } | ||
2189 | |||
2190 | /** | ||
2191 | * ep_alloc_request: allocate a request object to use with this endpoint | ||
2192 | * | ||
2193 | * Check usb_ep_alloc_request() at "usb_gadget.h" for details | ||
2194 | */ | ||
2195 | static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | ||
2196 | { | ||
2197 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2198 | struct ci13xxx_req *mReq = NULL; | ||
2199 | |||
2200 | trace("%p, %i", ep, gfp_flags); | ||
2201 | |||
2202 | if (ep == NULL) { | ||
2203 | err("EINVAL"); | ||
2204 | return NULL; | ||
2205 | } | ||
2206 | |||
2207 | mReq = kzalloc(sizeof(struct ci13xxx_req), gfp_flags); | ||
2208 | if (mReq != NULL) { | ||
2209 | INIT_LIST_HEAD(&mReq->queue); | ||
2210 | mReq->req.dma = DMA_ADDR_INVALID; | ||
2211 | |||
2212 | mReq->ptr = dma_pool_alloc(mEp->td_pool, gfp_flags, | ||
2213 | &mReq->dma); | ||
2214 | if (mReq->ptr == NULL) { | ||
2215 | kfree(mReq); | ||
2216 | mReq = NULL; | ||
2217 | } | ||
2218 | } | ||
2219 | |||
2220 | dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL); | ||
2221 | |||
2222 | return (mReq == NULL) ? NULL : &mReq->req; | ||
2223 | } | ||
2224 | |||
2225 | /** | ||
2226 | * ep_free_request: frees a request object | ||
2227 | * | ||
2228 | * Check usb_ep_free_request() at "usb_gadget.h" for details | ||
2229 | */ | ||
2230 | static void ep_free_request(struct usb_ep *ep, struct usb_request *req) | ||
2231 | { | ||
2232 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2233 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2234 | unsigned long flags; | ||
2235 | |||
2236 | trace("%p, %p", ep, req); | ||
2237 | |||
2238 | if (ep == NULL || req == NULL) { | ||
2239 | err("EINVAL"); | ||
2240 | return; | ||
2241 | } else if (!list_empty(&mReq->queue)) { | ||
2242 | err("EBUSY"); | ||
2243 | return; | ||
2244 | } | ||
2245 | |||
2246 | spin_lock_irqsave(mEp->lock, flags); | ||
2247 | |||
2248 | if (mReq->ptr) | ||
2249 | dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma); | ||
2250 | kfree(mReq); | ||
2251 | |||
2252 | dbg_event(_usb_addr(mEp), "FREE", 0); | ||
2253 | |||
2254 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2255 | } | ||
2256 | |||
2257 | /** | ||
2258 | * ep_queue: queues (submits) an I/O request to an endpoint | ||
2259 | * | ||
2260 | * Check usb_ep_queue()* at usb_gadget.h" for details | ||
2261 | */ | ||
2262 | static int ep_queue(struct usb_ep *ep, struct usb_request *req, | ||
2263 | gfp_t __maybe_unused gfp_flags) | ||
2264 | { | ||
2265 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2266 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2267 | int retval = 0; | ||
2268 | unsigned long flags; | ||
2269 | |||
2270 | trace("%p, %p, %X", ep, req, gfp_flags); | ||
2271 | |||
2272 | if (ep == NULL || req == NULL || mEp->desc == NULL) | ||
2273 | return -EINVAL; | ||
2274 | |||
2275 | spin_lock_irqsave(mEp->lock, flags); | ||
2276 | |||
2277 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) { | ||
2278 | if (req->length) | ||
2279 | mEp = (_udc->ep0_dir == RX) ? | ||
2280 | &_udc->ep0out : &_udc->ep0in; | ||
2281 | if (!list_empty(&mEp->qh.queue)) { | ||
2282 | _ep_nuke(mEp); | ||
2283 | retval = -EOVERFLOW; | ||
2284 | warn("endpoint ctrl %X nuked", _usb_addr(mEp)); | ||
2285 | } | ||
2286 | } | ||
2287 | |||
2288 | /* first nuke then test link, e.g. previous status has not sent */ | ||
2289 | if (!list_empty(&mReq->queue)) { | ||
2290 | retval = -EBUSY; | ||
2291 | err("request already in queue"); | ||
2292 | goto done; | ||
2293 | } | ||
2294 | |||
2295 | if (req->length > (4 * CI13XXX_PAGE_SIZE)) { | ||
2296 | req->length = (4 * CI13XXX_PAGE_SIZE); | ||
2297 | retval = -EMSGSIZE; | ||
2298 | warn("request length truncated"); | ||
2299 | } | ||
2300 | |||
2301 | dbg_queue(_usb_addr(mEp), req, retval); | ||
2302 | |||
2303 | /* push request */ | ||
2304 | mReq->req.status = -EINPROGRESS; | ||
2305 | mReq->req.actual = 0; | ||
2306 | |||
2307 | retval = _hardware_enqueue(mEp, mReq); | ||
2308 | |||
2309 | if (retval == -EALREADY) { | ||
2310 | dbg_event(_usb_addr(mEp), "QUEUE", retval); | ||
2311 | retval = 0; | ||
2312 | } | ||
2313 | if (!retval) | ||
2314 | list_add_tail(&mReq->queue, &mEp->qh.queue); | ||
2315 | |||
2316 | done: | ||
2317 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2318 | return retval; | ||
2319 | } | ||
2320 | |||
2321 | /** | ||
2322 | * ep_dequeue: dequeues (cancels, unlinks) an I/O request from an endpoint | ||
2323 | * | ||
2324 | * Check usb_ep_dequeue() at "usb_gadget.h" for details | ||
2325 | */ | ||
2326 | static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) | ||
2327 | { | ||
2328 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2329 | struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req); | ||
2330 | unsigned long flags; | ||
2331 | |||
2332 | trace("%p, %p", ep, req); | ||
2333 | |||
2334 | if (ep == NULL || req == NULL || mReq->req.status != -EALREADY || | ||
2335 | mEp->desc == NULL || list_empty(&mReq->queue) || | ||
2336 | list_empty(&mEp->qh.queue)) | ||
2337 | return -EINVAL; | ||
2338 | |||
2339 | spin_lock_irqsave(mEp->lock, flags); | ||
2340 | |||
2341 | dbg_event(_usb_addr(mEp), "DEQUEUE", 0); | ||
2342 | |||
2343 | hw_ep_flush(mEp->num, mEp->dir); | ||
2344 | |||
2345 | /* pop request */ | ||
2346 | list_del_init(&mReq->queue); | ||
2347 | if (mReq->map) { | ||
2348 | dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, | ||
2349 | mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
2350 | mReq->req.dma = DMA_ADDR_INVALID; | ||
2351 | mReq->map = 0; | ||
2352 | } | ||
2353 | req->status = -ECONNRESET; | ||
2354 | |||
2355 | if (mReq->req.complete != NULL) { | ||
2356 | spin_unlock(mEp->lock); | ||
2357 | mReq->req.complete(&mEp->ep, &mReq->req); | ||
2358 | spin_lock(mEp->lock); | ||
2359 | } | ||
2360 | |||
2361 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2362 | return 0; | ||
2363 | } | ||
2364 | |||
2365 | /** | ||
2366 | * ep_set_halt: sets the endpoint halt feature | ||
2367 | * | ||
2368 | * Check usb_ep_set_halt() at "usb_gadget.h" for details | ||
2369 | */ | ||
2370 | static int ep_set_halt(struct usb_ep *ep, int value) | ||
2371 | { | ||
2372 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2373 | int direction, retval = 0; | ||
2374 | unsigned long flags; | ||
2375 | |||
2376 | trace("%p, %i", ep, value); | ||
2377 | |||
2378 | if (ep == NULL || mEp->desc == NULL) | ||
2379 | return -EINVAL; | ||
2380 | |||
2381 | spin_lock_irqsave(mEp->lock, flags); | ||
2382 | |||
2383 | #ifndef STALL_IN | ||
2384 | /* g_file_storage MS compliant but g_zero fails chapter 9 compliance */ | ||
2385 | if (value && mEp->type == USB_ENDPOINT_XFER_BULK && mEp->dir == TX && | ||
2386 | !list_empty(&mEp->qh.queue)) { | ||
2387 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2388 | return -EAGAIN; | ||
2389 | } | ||
2390 | #endif | ||
2391 | |||
2392 | direction = mEp->dir; | ||
2393 | do { | ||
2394 | dbg_event(_usb_addr(mEp), "HALT", value); | ||
2395 | retval |= hw_ep_set_halt(mEp->num, mEp->dir, value); | ||
2396 | |||
2397 | if (!value) | ||
2398 | mEp->wedge = 0; | ||
2399 | |||
2400 | if (mEp->type == USB_ENDPOINT_XFER_CONTROL) | ||
2401 | mEp->dir = (mEp->dir == TX) ? RX : TX; | ||
2402 | |||
2403 | } while (mEp->dir != direction); | ||
2404 | |||
2405 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2406 | return retval; | ||
2407 | } | ||
2408 | |||
2409 | /** | ||
2410 | * ep_set_wedge: sets the halt feature and ignores clear requests | ||
2411 | * | ||
2412 | * Check usb_ep_set_wedge() at "usb_gadget.h" for details | ||
2413 | */ | ||
2414 | static int ep_set_wedge(struct usb_ep *ep) | ||
2415 | { | ||
2416 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2417 | unsigned long flags; | ||
2418 | |||
2419 | trace("%p", ep); | ||
2420 | |||
2421 | if (ep == NULL || mEp->desc == NULL) | ||
2422 | return -EINVAL; | ||
2423 | |||
2424 | spin_lock_irqsave(mEp->lock, flags); | ||
2425 | |||
2426 | dbg_event(_usb_addr(mEp), "WEDGE", 0); | ||
2427 | mEp->wedge = 1; | ||
2428 | |||
2429 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2430 | |||
2431 | return usb_ep_set_halt(ep); | ||
2432 | } | ||
2433 | |||
2434 | /** | ||
2435 | * ep_fifo_flush: flushes contents of a fifo | ||
2436 | * | ||
2437 | * Check usb_ep_fifo_flush() at "usb_gadget.h" for details | ||
2438 | */ | ||
2439 | static void ep_fifo_flush(struct usb_ep *ep) | ||
2440 | { | ||
2441 | struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); | ||
2442 | unsigned long flags; | ||
2443 | |||
2444 | trace("%p", ep); | ||
2445 | |||
2446 | if (ep == NULL) { | ||
2447 | err("%02X: -EINVAL", _usb_addr(mEp)); | ||
2448 | return; | ||
2449 | } | ||
2450 | |||
2451 | spin_lock_irqsave(mEp->lock, flags); | ||
2452 | |||
2453 | dbg_event(_usb_addr(mEp), "FFLUSH", 0); | ||
2454 | hw_ep_flush(mEp->num, mEp->dir); | ||
2455 | |||
2456 | spin_unlock_irqrestore(mEp->lock, flags); | ||
2457 | } | ||
2458 | |||
2459 | /** | ||
2460 | * Endpoint-specific part of the API to the USB controller hardware | ||
2461 | * Check "usb_gadget.h" for details | ||
2462 | */ | ||
2463 | static const struct usb_ep_ops usb_ep_ops = { | ||
2464 | .enable = ep_enable, | ||
2465 | .disable = ep_disable, | ||
2466 | .alloc_request = ep_alloc_request, | ||
2467 | .free_request = ep_free_request, | ||
2468 | .queue = ep_queue, | ||
2469 | .dequeue = ep_dequeue, | ||
2470 | .set_halt = ep_set_halt, | ||
2471 | .set_wedge = ep_set_wedge, | ||
2472 | .fifo_flush = ep_fifo_flush, | ||
2473 | }; | ||
2474 | |||
2475 | /****************************************************************************** | ||
2476 | * GADGET block | ||
2477 | *****************************************************************************/ | ||
2478 | static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) | ||
2479 | { | ||
2480 | struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); | ||
2481 | unsigned long flags; | ||
2482 | int gadget_ready = 0; | ||
2483 | |||
2484 | if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS)) | ||
2485 | return -EOPNOTSUPP; | ||
2486 | |||
2487 | spin_lock_irqsave(udc->lock, flags); | ||
2488 | udc->vbus_active = is_active; | ||
2489 | if (udc->driver) | ||
2490 | gadget_ready = 1; | ||
2491 | spin_unlock_irqrestore(udc->lock, flags); | ||
2492 | |||
2493 | if (gadget_ready) { | ||
2494 | if (is_active) { | ||
2495 | pm_runtime_get_sync(&_gadget->dev); | ||
2496 | hw_device_reset(udc); | ||
2497 | hw_device_state(udc->ep0out.qh.dma); | ||
2498 | } else { | ||
2499 | hw_device_state(0); | ||
2500 | if (udc->udc_driver->notify_event) | ||
2501 | udc->udc_driver->notify_event(udc, | ||
2502 | CI13XXX_CONTROLLER_STOPPED_EVENT); | ||
2503 | _gadget_stop_activity(&udc->gadget); | ||
2504 | pm_runtime_put_sync(&_gadget->dev); | ||
2505 | } | ||
2506 | } | ||
2507 | |||
2508 | return 0; | ||
2509 | } | ||
2510 | |||
2511 | static int ci13xxx_wakeup(struct usb_gadget *_gadget) | ||
2512 | { | ||
2513 | struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); | ||
2514 | unsigned long flags; | ||
2515 | int ret = 0; | ||
2516 | |||
2517 | trace(); | ||
2518 | |||
2519 | spin_lock_irqsave(udc->lock, flags); | ||
2520 | if (!udc->remote_wakeup) { | ||
2521 | ret = -EOPNOTSUPP; | ||
2522 | trace("remote wakeup feature is not enabled\n"); | ||
2523 | goto out; | ||
2524 | } | ||
2525 | if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) { | ||
2526 | ret = -EINVAL; | ||
2527 | trace("port is not suspended\n"); | ||
2528 | goto out; | ||
2529 | } | ||
2530 | hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR); | ||
2531 | out: | ||
2532 | spin_unlock_irqrestore(udc->lock, flags); | ||
2533 | return ret; | ||
2534 | } | ||
2535 | |||
2536 | static int ci13xxx_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | ||
2537 | { | ||
2538 | struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); | ||
2539 | |||
2540 | if (udc->transceiver) | ||
2541 | return usb_phy_set_power(udc->transceiver, mA); | ||
2542 | return -ENOTSUPP; | ||
2543 | } | ||
2544 | |||
2545 | static int ci13xxx_start(struct usb_gadget_driver *driver, | ||
2546 | int (*bind)(struct usb_gadget *)); | ||
2547 | static int ci13xxx_stop(struct usb_gadget_driver *driver); | ||
2548 | /** | ||
2549 | * Device operations part of the API to the USB controller hardware, | ||
2550 | * which don't involve endpoints (or i/o) | ||
2551 | * Check "usb_gadget.h" for details | ||
2552 | */ | ||
2553 | static const struct usb_gadget_ops usb_gadget_ops = { | ||
2554 | .vbus_session = ci13xxx_vbus_session, | ||
2555 | .wakeup = ci13xxx_wakeup, | ||
2556 | .vbus_draw = ci13xxx_vbus_draw, | ||
2557 | .start = ci13xxx_start, | ||
2558 | .stop = ci13xxx_stop, | ||
2559 | }; | ||
2560 | |||
2561 | /** | ||
2562 | * ci13xxx_start: register a gadget driver | ||
2563 | * @driver: the driver being registered | ||
2564 | * @bind: the driver's bind callback | ||
2565 | * | ||
2566 | * Check ci13xxx_start() at <linux/usb/gadget.h> for details. | ||
2567 | * Interrupts are enabled here. | ||
2568 | */ | ||
2569 | static int ci13xxx_start(struct usb_gadget_driver *driver, | ||
2570 | int (*bind)(struct usb_gadget *)) | ||
2571 | { | ||
2572 | struct ci13xxx *udc = _udc; | ||
2573 | unsigned long flags; | ||
2574 | int i, j; | ||
2575 | int retval = -ENOMEM; | ||
2576 | |||
2577 | trace("%p", driver); | ||
2578 | |||
2579 | if (driver == NULL || | ||
2580 | bind == NULL || | ||
2581 | driver->setup == NULL || | ||
2582 | driver->disconnect == NULL) | ||
2583 | return -EINVAL; | ||
2584 | else if (udc == NULL) | ||
2585 | return -ENODEV; | ||
2586 | else if (udc->driver != NULL) | ||
2587 | return -EBUSY; | ||
2588 | |||
2589 | /* alloc resources */ | ||
2590 | udc->qh_pool = dma_pool_create("ci13xxx_qh", &udc->gadget.dev, | ||
2591 | sizeof(struct ci13xxx_qh), | ||
2592 | 64, CI13XXX_PAGE_SIZE); | ||
2593 | if (udc->qh_pool == NULL) | ||
2594 | return -ENOMEM; | ||
2595 | |||
2596 | udc->td_pool = dma_pool_create("ci13xxx_td", &udc->gadget.dev, | ||
2597 | sizeof(struct ci13xxx_td), | ||
2598 | 64, CI13XXX_PAGE_SIZE); | ||
2599 | if (udc->td_pool == NULL) { | ||
2600 | dma_pool_destroy(udc->qh_pool); | ||
2601 | udc->qh_pool = NULL; | ||
2602 | return -ENOMEM; | ||
2603 | } | ||
2604 | |||
2605 | spin_lock_irqsave(udc->lock, flags); | ||
2606 | |||
2607 | info("hw_ep_max = %d", hw_ep_max); | ||
2608 | |||
2609 | udc->gadget.dev.driver = NULL; | ||
2610 | |||
2611 | retval = 0; | ||
2612 | for (i = 0; i < hw_ep_max/2; i++) { | ||
2613 | for (j = RX; j <= TX; j++) { | ||
2614 | int k = i + j * hw_ep_max/2; | ||
2615 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[k]; | ||
2616 | |||
2617 | scnprintf(mEp->name, sizeof(mEp->name), "ep%i%s", i, | ||
2618 | (j == TX) ? "in" : "out"); | ||
2619 | |||
2620 | mEp->lock = udc->lock; | ||
2621 | mEp->device = &udc->gadget.dev; | ||
2622 | mEp->td_pool = udc->td_pool; | ||
2623 | |||
2624 | mEp->ep.name = mEp->name; | ||
2625 | mEp->ep.ops = &usb_ep_ops; | ||
2626 | mEp->ep.maxpacket = CTRL_PAYLOAD_MAX; | ||
2627 | |||
2628 | INIT_LIST_HEAD(&mEp->qh.queue); | ||
2629 | spin_unlock_irqrestore(udc->lock, flags); | ||
2630 | mEp->qh.ptr = dma_pool_alloc(udc->qh_pool, GFP_KERNEL, | ||
2631 | &mEp->qh.dma); | ||
2632 | spin_lock_irqsave(udc->lock, flags); | ||
2633 | if (mEp->qh.ptr == NULL) | ||
2634 | retval = -ENOMEM; | ||
2635 | else | ||
2636 | memset(mEp->qh.ptr, 0, sizeof(*mEp->qh.ptr)); | ||
2637 | |||
2638 | /* skip ep0 out and in endpoints */ | ||
2639 | if (i == 0) | ||
2640 | continue; | ||
2641 | |||
2642 | list_add_tail(&mEp->ep.ep_list, &udc->gadget.ep_list); | ||
2643 | } | ||
2644 | } | ||
2645 | if (retval) | ||
2646 | goto done; | ||
2647 | spin_unlock_irqrestore(udc->lock, flags); | ||
2648 | udc->ep0out.ep.desc = &ctrl_endpt_out_desc; | ||
2649 | retval = usb_ep_enable(&udc->ep0out.ep); | ||
2650 | if (retval) | ||
2651 | return retval; | ||
2652 | |||
2653 | udc->ep0in.ep.desc = &ctrl_endpt_in_desc; | ||
2654 | retval = usb_ep_enable(&udc->ep0in.ep); | ||
2655 | if (retval) | ||
2656 | return retval; | ||
2657 | spin_lock_irqsave(udc->lock, flags); | ||
2658 | |||
2659 | udc->gadget.ep0 = &udc->ep0in.ep; | ||
2660 | /* bind gadget */ | ||
2661 | driver->driver.bus = NULL; | ||
2662 | udc->gadget.dev.driver = &driver->driver; | ||
2663 | |||
2664 | spin_unlock_irqrestore(udc->lock, flags); | ||
2665 | retval = bind(&udc->gadget); /* MAY SLEEP */ | ||
2666 | spin_lock_irqsave(udc->lock, flags); | ||
2667 | |||
2668 | if (retval) { | ||
2669 | udc->gadget.dev.driver = NULL; | ||
2670 | goto done; | ||
2671 | } | ||
2672 | |||
2673 | udc->driver = driver; | ||
2674 | pm_runtime_get_sync(&udc->gadget.dev); | ||
2675 | if (udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) { | ||
2676 | if (udc->vbus_active) { | ||
2677 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) | ||
2678 | hw_device_reset(udc); | ||
2679 | } else { | ||
2680 | pm_runtime_put_sync(&udc->gadget.dev); | ||
2681 | goto done; | ||
2682 | } | ||
2683 | } | ||
2684 | |||
2685 | retval = hw_device_state(udc->ep0out.qh.dma); | ||
2686 | if (retval) | ||
2687 | pm_runtime_put_sync(&udc->gadget.dev); | ||
2688 | |||
2689 | done: | ||
2690 | spin_unlock_irqrestore(udc->lock, flags); | ||
2691 | return retval; | ||
2692 | } | ||
2693 | |||
2694 | /** | ||
2695 | * ci13xxx_stop: unregister a gadget driver | ||
2696 | * | ||
2697 | * Check usb_gadget_unregister_driver() at "usb_gadget.h" for details | ||
2698 | */ | ||
2699 | static int ci13xxx_stop(struct usb_gadget_driver *driver) | ||
2700 | { | ||
2701 | struct ci13xxx *udc = _udc; | ||
2702 | unsigned long i, flags; | ||
2703 | |||
2704 | trace("%p", driver); | ||
2705 | |||
2706 | if (driver == NULL || | ||
2707 | driver->unbind == NULL || | ||
2708 | driver->setup == NULL || | ||
2709 | driver->disconnect == NULL || | ||
2710 | driver != udc->driver) | ||
2711 | return -EINVAL; | ||
2712 | |||
2713 | spin_lock_irqsave(udc->lock, flags); | ||
2714 | |||
2715 | if (!(udc->udc_driver->flags & CI13XXX_PULLUP_ON_VBUS) || | ||
2716 | udc->vbus_active) { | ||
2717 | hw_device_state(0); | ||
2718 | if (udc->udc_driver->notify_event) | ||
2719 | udc->udc_driver->notify_event(udc, | ||
2720 | CI13XXX_CONTROLLER_STOPPED_EVENT); | ||
2721 | spin_unlock_irqrestore(udc->lock, flags); | ||
2722 | _gadget_stop_activity(&udc->gadget); | ||
2723 | spin_lock_irqsave(udc->lock, flags); | ||
2724 | pm_runtime_put(&udc->gadget.dev); | ||
2725 | } | ||
2726 | |||
2727 | /* unbind gadget */ | ||
2728 | spin_unlock_irqrestore(udc->lock, flags); | ||
2729 | driver->unbind(&udc->gadget); /* MAY SLEEP */ | ||
2730 | spin_lock_irqsave(udc->lock, flags); | ||
2731 | |||
2732 | udc->gadget.dev.driver = NULL; | ||
2733 | |||
2734 | /* free resources */ | ||
2735 | for (i = 0; i < hw_ep_max; i++) { | ||
2736 | struct ci13xxx_ep *mEp = &udc->ci13xxx_ep[i]; | ||
2737 | |||
2738 | if (!list_empty(&mEp->ep.ep_list)) | ||
2739 | list_del_init(&mEp->ep.ep_list); | ||
2740 | |||
2741 | if (mEp->qh.ptr != NULL) | ||
2742 | dma_pool_free(udc->qh_pool, mEp->qh.ptr, mEp->qh.dma); | ||
2743 | } | ||
2744 | |||
2745 | udc->gadget.ep0 = NULL; | ||
2746 | udc->driver = NULL; | ||
2747 | |||
2748 | spin_unlock_irqrestore(udc->lock, flags); | ||
2749 | |||
2750 | if (udc->td_pool != NULL) { | ||
2751 | dma_pool_destroy(udc->td_pool); | ||
2752 | udc->td_pool = NULL; | ||
2753 | } | ||
2754 | if (udc->qh_pool != NULL) { | ||
2755 | dma_pool_destroy(udc->qh_pool); | ||
2756 | udc->qh_pool = NULL; | ||
2757 | } | ||
2758 | |||
2759 | return 0; | ||
2760 | } | ||
2761 | |||
2762 | /****************************************************************************** | ||
2763 | * BUS block | ||
2764 | *****************************************************************************/ | ||
2765 | /** | ||
2766 | * udc_irq: global interrupt handler | ||
2767 | * | ||
2768 | * This function returns IRQ_HANDLED if the IRQ has been handled | ||
2769 | * It locks access to registers | ||
2770 | */ | ||
2771 | static irqreturn_t udc_irq(void) | ||
2772 | { | ||
2773 | struct ci13xxx *udc = _udc; | ||
2774 | irqreturn_t retval; | ||
2775 | u32 intr; | ||
2776 | |||
2777 | trace(); | ||
2778 | |||
2779 | if (udc == NULL) { | ||
2780 | err("ENODEV"); | ||
2781 | return IRQ_HANDLED; | ||
2782 | } | ||
2783 | |||
2784 | spin_lock(udc->lock); | ||
2785 | |||
2786 | if (udc->udc_driver->flags & CI13XXX_REGS_SHARED) { | ||
2787 | if (hw_cread(CAP_USBMODE, USBMODE_CM) != | ||
2788 | USBMODE_CM_DEVICE) { | ||
2789 | spin_unlock(udc->lock); | ||
2790 | return IRQ_NONE; | ||
2791 | } | ||
2792 | } | ||
2793 | intr = hw_test_and_clear_intr_active(); | ||
2794 | if (intr) { | ||
2795 | isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intr; | ||
2796 | isr_statistics.hndl.idx &= ISR_MASK; | ||
2797 | isr_statistics.hndl.cnt++; | ||
2798 | |||
2799 | /* order defines priority - do NOT change it */ | ||
2800 | if (USBi_URI & intr) { | ||
2801 | isr_statistics.uri++; | ||
2802 | isr_reset_handler(udc); | ||
2803 | } | ||
2804 | if (USBi_PCI & intr) { | ||
2805 | isr_statistics.pci++; | ||
2806 | udc->gadget.speed = hw_port_is_high_speed() ? | ||
2807 | USB_SPEED_HIGH : USB_SPEED_FULL; | ||
2808 | if (udc->suspended && udc->driver->resume) { | ||
2809 | spin_unlock(udc->lock); | ||
2810 | udc->driver->resume(&udc->gadget); | ||
2811 | spin_lock(udc->lock); | ||
2812 | udc->suspended = 0; | ||
2813 | } | ||
2814 | } | ||
2815 | if (USBi_UEI & intr) | ||
2816 | isr_statistics.uei++; | ||
2817 | if (USBi_UI & intr) { | ||
2818 | isr_statistics.ui++; | ||
2819 | isr_tr_complete_handler(udc); | ||
2820 | } | ||
2821 | if (USBi_SLI & intr) { | ||
2822 | if (udc->gadget.speed != USB_SPEED_UNKNOWN && | ||
2823 | udc->driver->suspend) { | ||
2824 | udc->suspended = 1; | ||
2825 | spin_unlock(udc->lock); | ||
2826 | udc->driver->suspend(&udc->gadget); | ||
2827 | spin_lock(udc->lock); | ||
2828 | } | ||
2829 | isr_statistics.sli++; | ||
2830 | } | ||
2831 | retval = IRQ_HANDLED; | ||
2832 | } else { | ||
2833 | isr_statistics.none++; | ||
2834 | retval = IRQ_NONE; | ||
2835 | } | ||
2836 | spin_unlock(udc->lock); | ||
2837 | |||
2838 | return retval; | ||
2839 | } | ||
2840 | |||
2841 | /** | ||
2842 | * udc_release: driver release function | ||
2843 | * @dev: device | ||
2844 | * | ||
2845 | * Currently does nothing | ||
2846 | */ | ||
2847 | static void udc_release(struct device *dev) | ||
2848 | { | ||
2849 | trace("%p", dev); | ||
2850 | |||
2851 | if (dev == NULL) | ||
2852 | err("EINVAL"); | ||
2853 | } | ||
2854 | |||
2855 | /** | ||
2856 | * udc_probe: parent probe must call this to initialize UDC | ||
2857 | * @dev: parent device | ||
2858 | * @regs: registers base address | ||
2859 | * @name: driver name | ||
2860 | * | ||
2861 | * This function returns an error code | ||
2862 | * No interrupts active, the IRQ has not been requested yet | ||
2863 | * Kernel assumes 32-bit DMA operations by default, no need to dma_set_mask | ||
2864 | */ | ||
2865 | static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev, | ||
2866 | void __iomem *regs) | ||
2867 | { | ||
2868 | struct ci13xxx *udc; | ||
2869 | int retval = 0; | ||
2870 | |||
2871 | trace("%p, %p, %p", dev, regs, driver->name); | ||
2872 | |||
2873 | if (dev == NULL || regs == NULL || driver == NULL || | ||
2874 | driver->name == NULL) | ||
2875 | return -EINVAL; | ||
2876 | |||
2877 | udc = kzalloc(sizeof(struct ci13xxx), GFP_KERNEL); | ||
2878 | if (udc == NULL) | ||
2879 | return -ENOMEM; | ||
2880 | |||
2881 | udc->lock = &udc_lock; | ||
2882 | udc->regs = regs; | ||
2883 | udc->udc_driver = driver; | ||
2884 | |||
2885 | udc->gadget.ops = &usb_gadget_ops; | ||
2886 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
2887 | udc->gadget.max_speed = USB_SPEED_HIGH; | ||
2888 | udc->gadget.is_otg = 0; | ||
2889 | udc->gadget.name = driver->name; | ||
2890 | |||
2891 | INIT_LIST_HEAD(&udc->gadget.ep_list); | ||
2892 | udc->gadget.ep0 = NULL; | ||
2893 | |||
2894 | dev_set_name(&udc->gadget.dev, "gadget"); | ||
2895 | udc->gadget.dev.dma_mask = dev->dma_mask; | ||
2896 | udc->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask; | ||
2897 | udc->gadget.dev.parent = dev; | ||
2898 | udc->gadget.dev.release = udc_release; | ||
2899 | |||
2900 | retval = hw_device_init(regs); | ||
2901 | if (retval < 0) | ||
2902 | goto free_udc; | ||
2903 | |||
2904 | udc->transceiver = usb_get_transceiver(); | ||
2905 | |||
2906 | if (udc->udc_driver->flags & CI13XXX_REQUIRE_TRANSCEIVER) { | ||
2907 | if (udc->transceiver == NULL) { | ||
2908 | retval = -ENODEV; | ||
2909 | goto free_udc; | ||
2910 | } | ||
2911 | } | ||
2912 | |||
2913 | if (!(udc->udc_driver->flags & CI13XXX_REGS_SHARED)) { | ||
2914 | retval = hw_device_reset(udc); | ||
2915 | if (retval) | ||
2916 | goto put_transceiver; | ||
2917 | } | ||
2918 | |||
2919 | retval = device_register(&udc->gadget.dev); | ||
2920 | if (retval) { | ||
2921 | put_device(&udc->gadget.dev); | ||
2922 | goto put_transceiver; | ||
2923 | } | ||
2924 | |||
2925 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2926 | retval = dbg_create_files(&udc->gadget.dev); | ||
2927 | #endif | ||
2928 | if (retval) | ||
2929 | goto unreg_device; | ||
2930 | |||
2931 | if (udc->transceiver) { | ||
2932 | retval = otg_set_peripheral(udc->transceiver->otg, | ||
2933 | &udc->gadget); | ||
2934 | if (retval) | ||
2935 | goto remove_dbg; | ||
2936 | } | ||
2937 | |||
2938 | retval = usb_add_gadget_udc(dev, &udc->gadget); | ||
2939 | if (retval) | ||
2940 | goto remove_trans; | ||
2941 | |||
2942 | pm_runtime_no_callbacks(&udc->gadget.dev); | ||
2943 | pm_runtime_enable(&udc->gadget.dev); | ||
2944 | |||
2945 | _udc = udc; | ||
2946 | return retval; | ||
2947 | |||
2948 | remove_trans: | ||
2949 | if (udc->transceiver) { | ||
2950 | otg_set_peripheral(udc->transceiver->otg, &udc->gadget); | ||
2951 | usb_put_transceiver(udc->transceiver); | ||
2952 | } | ||
2953 | |||
2954 | err("error = %i", retval); | ||
2955 | remove_dbg: | ||
2956 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2957 | dbg_remove_files(&udc->gadget.dev); | ||
2958 | #endif | ||
2959 | unreg_device: | ||
2960 | device_unregister(&udc->gadget.dev); | ||
2961 | put_transceiver: | ||
2962 | if (udc->transceiver) | ||
2963 | usb_put_transceiver(udc->transceiver); | ||
2964 | free_udc: | ||
2965 | kfree(udc); | ||
2966 | _udc = NULL; | ||
2967 | return retval; | ||
2968 | } | ||
2969 | |||
2970 | /** | ||
2971 | * udc_remove: parent remove must call this to remove UDC | ||
2972 | * | ||
2973 | * No interrupts active, the IRQ has been released | ||
2974 | */ | ||
2975 | static void udc_remove(void) | ||
2976 | { | ||
2977 | struct ci13xxx *udc = _udc; | ||
2978 | |||
2979 | if (udc == NULL) { | ||
2980 | err("EINVAL"); | ||
2981 | return; | ||
2982 | } | ||
2983 | usb_del_gadget_udc(&udc->gadget); | ||
2984 | |||
2985 | if (udc->transceiver) { | ||
2986 | otg_set_peripheral(udc->transceiver->otg, &udc->gadget); | ||
2987 | usb_put_transceiver(udc->transceiver); | ||
2988 | } | ||
2989 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2990 | dbg_remove_files(&udc->gadget.dev); | ||
2991 | #endif | ||
2992 | device_unregister(&udc->gadget.dev); | ||
2993 | |||
2994 | kfree(udc); | ||
2995 | _udc = NULL; | ||
2996 | } | ||
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h deleted file mode 100644 index 0d31af56c989..000000000000 --- a/drivers/usb/gadget/ci13xxx_udc.h +++ /dev/null | |||
@@ -1,227 +0,0 @@ | |||
1 | /* | ||
2 | * ci13xxx_udc.h - structures, registers, and macros MIPS USB IP core | ||
3 | * | ||
4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. | ||
5 | * | ||
6 | * Author: David Lopo | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * Description: MIPS USB IP core family device controller | ||
13 | * Structures, registers and logging macros | ||
14 | */ | ||
15 | |||
16 | #ifndef _CI13XXX_h_ | ||
17 | #define _CI13XXX_h_ | ||
18 | |||
19 | /****************************************************************************** | ||
20 | * DEFINE | ||
21 | *****************************************************************************/ | ||
22 | #define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */ | ||
23 | #define ENDPT_MAX (32) | ||
24 | #define CTRL_PAYLOAD_MAX (64) | ||
25 | #define RX (0) /* similar to USB_DIR_OUT but can be used as an index */ | ||
26 | #define TX (1) /* similar to USB_DIR_IN but can be used as an index */ | ||
27 | |||
28 | /****************************************************************************** | ||
29 | * STRUCTURES | ||
30 | *****************************************************************************/ | ||
31 | /* DMA layout of transfer descriptors */ | ||
32 | struct ci13xxx_td { | ||
33 | /* 0 */ | ||
34 | u32 next; | ||
35 | #define TD_TERMINATE BIT(0) | ||
36 | #define TD_ADDR_MASK (0xFFFFFFEUL << 5) | ||
37 | /* 1 */ | ||
38 | u32 token; | ||
39 | #define TD_STATUS (0x00FFUL << 0) | ||
40 | #define TD_STATUS_TR_ERR BIT(3) | ||
41 | #define TD_STATUS_DT_ERR BIT(5) | ||
42 | #define TD_STATUS_HALTED BIT(6) | ||
43 | #define TD_STATUS_ACTIVE BIT(7) | ||
44 | #define TD_MULTO (0x0003UL << 10) | ||
45 | #define TD_IOC BIT(15) | ||
46 | #define TD_TOTAL_BYTES (0x7FFFUL << 16) | ||
47 | /* 2 */ | ||
48 | u32 page[5]; | ||
49 | #define TD_CURR_OFFSET (0x0FFFUL << 0) | ||
50 | #define TD_FRAME_NUM (0x07FFUL << 0) | ||
51 | #define TD_RESERVED_MASK (0x0FFFUL << 0) | ||
52 | } __attribute__ ((packed)); | ||
53 | |||
54 | /* DMA layout of queue heads */ | ||
55 | struct ci13xxx_qh { | ||
56 | /* 0 */ | ||
57 | u32 cap; | ||
58 | #define QH_IOS BIT(15) | ||
59 | #define QH_MAX_PKT (0x07FFUL << 16) | ||
60 | #define QH_ZLT BIT(29) | ||
61 | #define QH_MULT (0x0003UL << 30) | ||
62 | /* 1 */ | ||
63 | u32 curr; | ||
64 | /* 2 - 8 */ | ||
65 | struct ci13xxx_td td; | ||
66 | /* 9 */ | ||
67 | u32 RESERVED; | ||
68 | struct usb_ctrlrequest setup; | ||
69 | } __attribute__ ((packed)); | ||
70 | |||
71 | /* Extension of usb_request */ | ||
72 | struct ci13xxx_req { | ||
73 | struct usb_request req; | ||
74 | unsigned map; | ||
75 | struct list_head queue; | ||
76 | struct ci13xxx_td *ptr; | ||
77 | dma_addr_t dma; | ||
78 | struct ci13xxx_td *zptr; | ||
79 | dma_addr_t zdma; | ||
80 | }; | ||
81 | |||
82 | /* Extension of usb_ep */ | ||
83 | struct ci13xxx_ep { | ||
84 | struct usb_ep ep; | ||
85 | const struct usb_endpoint_descriptor *desc; | ||
86 | u8 dir; | ||
87 | u8 num; | ||
88 | u8 type; | ||
89 | char name[16]; | ||
90 | struct { | ||
91 | struct list_head queue; | ||
92 | struct ci13xxx_qh *ptr; | ||
93 | dma_addr_t dma; | ||
94 | } qh; | ||
95 | int wedge; | ||
96 | |||
97 | /* global resources */ | ||
98 | spinlock_t *lock; | ||
99 | struct device *device; | ||
100 | struct dma_pool *td_pool; | ||
101 | }; | ||
102 | |||
103 | struct ci13xxx; | ||
104 | struct ci13xxx_udc_driver { | ||
105 | const char *name; | ||
106 | unsigned long flags; | ||
107 | #define CI13XXX_REGS_SHARED BIT(0) | ||
108 | #define CI13XXX_REQUIRE_TRANSCEIVER BIT(1) | ||
109 | #define CI13XXX_PULLUP_ON_VBUS BIT(2) | ||
110 | #define CI13XXX_DISABLE_STREAMING BIT(3) | ||
111 | |||
112 | #define CI13XXX_CONTROLLER_RESET_EVENT 0 | ||
113 | #define CI13XXX_CONTROLLER_STOPPED_EVENT 1 | ||
114 | void (*notify_event) (struct ci13xxx *udc, unsigned event); | ||
115 | }; | ||
116 | |||
117 | /* CI13XXX UDC descriptor & global resources */ | ||
118 | struct ci13xxx { | ||
119 | spinlock_t *lock; /* ctrl register bank access */ | ||
120 | void __iomem *regs; /* registers address space */ | ||
121 | |||
122 | struct dma_pool *qh_pool; /* DMA pool for queue heads */ | ||
123 | struct dma_pool *td_pool; /* DMA pool for transfer descs */ | ||
124 | struct usb_request *status; /* ep0 status request */ | ||
125 | |||
126 | struct usb_gadget gadget; /* USB slave device */ | ||
127 | struct ci13xxx_ep ci13xxx_ep[ENDPT_MAX]; /* extended endpts */ | ||
128 | u32 ep0_dir; /* ep0 direction */ | ||
129 | #define ep0out ci13xxx_ep[0] | ||
130 | #define ep0in ci13xxx_ep[hw_ep_max / 2] | ||
131 | u8 remote_wakeup; /* Is remote wakeup feature | ||
132 | enabled by the host? */ | ||
133 | u8 suspended; /* suspended by the host */ | ||
134 | u8 test_mode; /* the selected test mode */ | ||
135 | |||
136 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ | ||
137 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ | ||
138 | int vbus_active; /* is VBUS active */ | ||
139 | struct usb_phy *transceiver; /* Transceiver struct */ | ||
140 | }; | ||
141 | |||
142 | /****************************************************************************** | ||
143 | * REGISTERS | ||
144 | *****************************************************************************/ | ||
145 | /* register size */ | ||
146 | #define REG_BITS (32) | ||
147 | |||
148 | /* HCCPARAMS */ | ||
149 | #define HCCPARAMS_LEN BIT(17) | ||
150 | |||
151 | /* DCCPARAMS */ | ||
152 | #define DCCPARAMS_DEN (0x1F << 0) | ||
153 | #define DCCPARAMS_DC BIT(7) | ||
154 | |||
155 | /* TESTMODE */ | ||
156 | #define TESTMODE_FORCE BIT(0) | ||
157 | |||
158 | /* USBCMD */ | ||
159 | #define USBCMD_RS BIT(0) | ||
160 | #define USBCMD_RST BIT(1) | ||
161 | #define USBCMD_SUTW BIT(13) | ||
162 | #define USBCMD_ATDTW BIT(14) | ||
163 | |||
164 | /* USBSTS & USBINTR */ | ||
165 | #define USBi_UI BIT(0) | ||
166 | #define USBi_UEI BIT(1) | ||
167 | #define USBi_PCI BIT(2) | ||
168 | #define USBi_URI BIT(6) | ||
169 | #define USBi_SLI BIT(8) | ||
170 | |||
171 | /* DEVICEADDR */ | ||
172 | #define DEVICEADDR_USBADRA BIT(24) | ||
173 | #define DEVICEADDR_USBADR (0x7FUL << 25) | ||
174 | |||
175 | /* PORTSC */ | ||
176 | #define PORTSC_FPR BIT(6) | ||
177 | #define PORTSC_SUSP BIT(7) | ||
178 | #define PORTSC_HSP BIT(9) | ||
179 | #define PORTSC_PTC (0x0FUL << 16) | ||
180 | |||
181 | /* DEVLC */ | ||
182 | #define DEVLC_PSPD (0x03UL << 25) | ||
183 | #define DEVLC_PSPD_HS (0x02UL << 25) | ||
184 | |||
185 | /* USBMODE */ | ||
186 | #define USBMODE_CM (0x03UL << 0) | ||
187 | #define USBMODE_CM_IDLE (0x00UL << 0) | ||
188 | #define USBMODE_CM_DEVICE (0x02UL << 0) | ||
189 | #define USBMODE_CM_HOST (0x03UL << 0) | ||
190 | #define USBMODE_SLOM BIT(3) | ||
191 | #define USBMODE_SDIS BIT(4) | ||
192 | |||
193 | /* ENDPTCTRL */ | ||
194 | #define ENDPTCTRL_RXS BIT(0) | ||
195 | #define ENDPTCTRL_RXT (0x03UL << 2) | ||
196 | #define ENDPTCTRL_RXR BIT(6) /* reserved for port 0 */ | ||
197 | #define ENDPTCTRL_RXE BIT(7) | ||
198 | #define ENDPTCTRL_TXS BIT(16) | ||
199 | #define ENDPTCTRL_TXT (0x03UL << 18) | ||
200 | #define ENDPTCTRL_TXR BIT(22) /* reserved for port 0 */ | ||
201 | #define ENDPTCTRL_TXE BIT(23) | ||
202 | |||
203 | /****************************************************************************** | ||
204 | * LOGGING | ||
205 | *****************************************************************************/ | ||
206 | #define ci13xxx_printk(level, format, args...) \ | ||
207 | do { \ | ||
208 | if (_udc == NULL) \ | ||
209 | printk(level "[%s] " format "\n", __func__, ## args); \ | ||
210 | else \ | ||
211 | dev_printk(level, _udc->gadget.dev.parent, \ | ||
212 | "[%s] " format "\n", __func__, ## args); \ | ||
213 | } while (0) | ||
214 | |||
215 | #define err(format, args...) ci13xxx_printk(KERN_ERR, format, ## args) | ||
216 | #define warn(format, args...) ci13xxx_printk(KERN_WARNING, format, ## args) | ||
217 | #define info(format, args...) ci13xxx_printk(KERN_INFO, format, ## args) | ||
218 | |||
219 | #ifdef TRACE | ||
220 | #define trace(format, args...) ci13xxx_printk(KERN_DEBUG, format, ## args) | ||
221 | #define dbg_trace(format, args...) dev_dbg(dev, format, ##args) | ||
222 | #else | ||
223 | #define trace(format, args...) do {} while (0) | ||
224 | #define dbg_trace(format, args...) do {} while (0) | ||
225 | #endif | ||
226 | |||
227 | #endif /* _CI13XXX_h_ */ | ||
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index baaebf2830fc..390749bbb0c3 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -40,27 +40,27 @@ static int (*composite_gadget_bind)(struct usb_composite_dev *cdev); | |||
40 | */ | 40 | */ |
41 | 41 | ||
42 | static ushort idVendor; | 42 | static ushort idVendor; |
43 | module_param(idVendor, ushort, 0); | 43 | module_param(idVendor, ushort, 0644); |
44 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); | 44 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); |
45 | 45 | ||
46 | static ushort idProduct; | 46 | static ushort idProduct; |
47 | module_param(idProduct, ushort, 0); | 47 | module_param(idProduct, ushort, 0644); |
48 | MODULE_PARM_DESC(idProduct, "USB Product ID"); | 48 | MODULE_PARM_DESC(idProduct, "USB Product ID"); |
49 | 49 | ||
50 | static ushort bcdDevice; | 50 | static ushort bcdDevice; |
51 | module_param(bcdDevice, ushort, 0); | 51 | module_param(bcdDevice, ushort, 0644); |
52 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); | 52 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); |
53 | 53 | ||
54 | static char *iManufacturer; | 54 | static char *iManufacturer; |
55 | module_param(iManufacturer, charp, 0); | 55 | module_param(iManufacturer, charp, 0644); |
56 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); | 56 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); |
57 | 57 | ||
58 | static char *iProduct; | 58 | static char *iProduct; |
59 | module_param(iProduct, charp, 0); | 59 | module_param(iProduct, charp, 0644); |
60 | MODULE_PARM_DESC(iProduct, "USB Product string"); | 60 | MODULE_PARM_DESC(iProduct, "USB Product string"); |
61 | 61 | ||
62 | static char *iSerialNumber; | 62 | static char *iSerialNumber; |
63 | module_param(iSerialNumber, charp, 0); | 63 | module_param(iSerialNumber, charp, 0644); |
64 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); | 64 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); |
65 | 65 | ||
66 | static char composite_manufacturer[50]; | 66 | static char composite_manufacturer[50]; |
@@ -734,9 +734,23 @@ int usb_add_config(struct usb_composite_dev *cdev, | |||
734 | 734 | ||
735 | INIT_LIST_HEAD(&config->functions); | 735 | INIT_LIST_HEAD(&config->functions); |
736 | config->next_interface_id = 0; | 736 | config->next_interface_id = 0; |
737 | memset(config->interface, 0, sizeof(config->interface)); | ||
737 | 738 | ||
738 | status = bind(config); | 739 | status = bind(config); |
739 | if (status < 0) { | 740 | if (status < 0) { |
741 | while (!list_empty(&config->functions)) { | ||
742 | struct usb_function *f; | ||
743 | |||
744 | f = list_first_entry(&config->functions, | ||
745 | struct usb_function, list); | ||
746 | list_del(&f->list); | ||
747 | if (f->unbind) { | ||
748 | DBG(cdev, "unbind function '%s'/%p\n", | ||
749 | f->name, f); | ||
750 | f->unbind(config, f); | ||
751 | /* may free memory for "f" */ | ||
752 | } | ||
753 | } | ||
740 | list_del(&config->list); | 754 | list_del(&config->list); |
741 | config->cdev = NULL; | 755 | config->cdev = NULL; |
742 | } else { | 756 | } else { |
@@ -774,6 +788,53 @@ done: | |||
774 | return status; | 788 | return status; |
775 | } | 789 | } |
776 | 790 | ||
791 | static void remove_config(struct usb_composite_dev *cdev, | ||
792 | struct usb_configuration *config) | ||
793 | { | ||
794 | while (!list_empty(&config->functions)) { | ||
795 | struct usb_function *f; | ||
796 | |||
797 | f = list_first_entry(&config->functions, | ||
798 | struct usb_function, list); | ||
799 | list_del(&f->list); | ||
800 | if (f->unbind) { | ||
801 | DBG(cdev, "unbind function '%s'/%p\n", f->name, f); | ||
802 | f->unbind(config, f); | ||
803 | /* may free memory for "f" */ | ||
804 | } | ||
805 | } | ||
806 | list_del(&config->list); | ||
807 | if (config->unbind) { | ||
808 | DBG(cdev, "unbind config '%s'/%p\n", config->label, config); | ||
809 | config->unbind(config); | ||
810 | /* may free memory for "c" */ | ||
811 | } | ||
812 | } | ||
813 | |||
814 | /** | ||
815 | * usb_remove_config() - remove a configuration from a device. | ||
816 | * @cdev: wraps the USB gadget | ||
817 | * @config: the configuration | ||
818 | * | ||
819 | * Drivers must call usb_gadget_disconnect before calling this function | ||
820 | * to disconnect the device from the host and make sure the host will not | ||
821 | * try to enumerate the device while we are changing the config list. | ||
822 | */ | ||
823 | void usb_remove_config(struct usb_composite_dev *cdev, | ||
824 | struct usb_configuration *config) | ||
825 | { | ||
826 | unsigned long flags; | ||
827 | |||
828 | spin_lock_irqsave(&cdev->lock, flags); | ||
829 | |||
830 | if (cdev->config == config) | ||
831 | reset_config(cdev); | ||
832 | |||
833 | spin_unlock_irqrestore(&cdev->lock, flags); | ||
834 | |||
835 | remove_config(cdev, config); | ||
836 | } | ||
837 | |||
777 | /*-------------------------------------------------------------------------*/ | 838 | /*-------------------------------------------------------------------------*/ |
778 | 839 | ||
779 | /* We support strings in multiple languages ... string descriptor zero | 840 | /* We support strings in multiple languages ... string descriptor zero |
@@ -785,7 +846,7 @@ done: | |||
785 | static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf) | 846 | static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf) |
786 | { | 847 | { |
787 | const struct usb_gadget_strings *s; | 848 | const struct usb_gadget_strings *s; |
788 | u16 language; | 849 | __le16 language; |
789 | __le16 *tmp; | 850 | __le16 *tmp; |
790 | 851 | ||
791 | while (*sp) { | 852 | while (*sp) { |
@@ -877,7 +938,7 @@ static int get_string(struct usb_composite_dev *cdev, | |||
877 | else if (cdev->product_override == id) | 938 | else if (cdev->product_override == id) |
878 | str = iProduct ?: composite->iProduct; | 939 | str = iProduct ?: composite->iProduct; |
879 | else if (cdev->serial_override == id) | 940 | else if (cdev->serial_override == id) |
880 | str = iSerialNumber; | 941 | str = iSerialNumber ?: composite->iSerialNumber; |
881 | else | 942 | else |
882 | str = NULL; | 943 | str = NULL; |
883 | if (str) { | 944 | if (str) { |
@@ -1328,28 +1389,9 @@ composite_unbind(struct usb_gadget *gadget) | |||
1328 | 1389 | ||
1329 | while (!list_empty(&cdev->configs)) { | 1390 | while (!list_empty(&cdev->configs)) { |
1330 | struct usb_configuration *c; | 1391 | struct usb_configuration *c; |
1331 | |||
1332 | c = list_first_entry(&cdev->configs, | 1392 | c = list_first_entry(&cdev->configs, |
1333 | struct usb_configuration, list); | 1393 | struct usb_configuration, list); |
1334 | while (!list_empty(&c->functions)) { | 1394 | remove_config(cdev, c); |
1335 | struct usb_function *f; | ||
1336 | |||
1337 | f = list_first_entry(&c->functions, | ||
1338 | struct usb_function, list); | ||
1339 | list_del(&f->list); | ||
1340 | if (f->unbind) { | ||
1341 | DBG(cdev, "unbind function '%s'/%p\n", | ||
1342 | f->name, f); | ||
1343 | f->unbind(c, f); | ||
1344 | /* may free memory for "f" */ | ||
1345 | } | ||
1346 | } | ||
1347 | list_del(&c->list); | ||
1348 | if (c->unbind) { | ||
1349 | DBG(cdev, "unbind config '%s'/%p\n", c->label, c); | ||
1350 | c->unbind(c); | ||
1351 | /* may free memory for "c" */ | ||
1352 | } | ||
1353 | } | 1395 | } |
1354 | if (composite->unbind) | 1396 | if (composite->unbind) |
1355 | composite->unbind(cdev); | 1397 | composite->unbind(cdev); |
@@ -1431,10 +1473,16 @@ static int composite_bind(struct usb_gadget *gadget) | |||
1431 | /* standardized runtime overrides for device ID data */ | 1473 | /* standardized runtime overrides for device ID data */ |
1432 | if (idVendor) | 1474 | if (idVendor) |
1433 | cdev->desc.idVendor = cpu_to_le16(idVendor); | 1475 | cdev->desc.idVendor = cpu_to_le16(idVendor); |
1476 | else | ||
1477 | idVendor = le16_to_cpu(cdev->desc.idVendor); | ||
1434 | if (idProduct) | 1478 | if (idProduct) |
1435 | cdev->desc.idProduct = cpu_to_le16(idProduct); | 1479 | cdev->desc.idProduct = cpu_to_le16(idProduct); |
1480 | else | ||
1481 | idProduct = le16_to_cpu(cdev->desc.idProduct); | ||
1436 | if (bcdDevice) | 1482 | if (bcdDevice) |
1437 | cdev->desc.bcdDevice = cpu_to_le16(bcdDevice); | 1483 | cdev->desc.bcdDevice = cpu_to_le16(bcdDevice); |
1484 | else | ||
1485 | bcdDevice = le16_to_cpu(cdev->desc.bcdDevice); | ||
1438 | 1486 | ||
1439 | /* string overrides */ | 1487 | /* string overrides */ |
1440 | if (iManufacturer || !cdev->desc.iManufacturer) { | 1488 | if (iManufacturer || !cdev->desc.iManufacturer) { |
@@ -1455,7 +1503,8 @@ static int composite_bind(struct usb_gadget *gadget) | |||
1455 | cdev->product_override = | 1503 | cdev->product_override = |
1456 | override_id(cdev, &cdev->desc.iProduct); | 1504 | override_id(cdev, &cdev->desc.iProduct); |
1457 | 1505 | ||
1458 | if (iSerialNumber) | 1506 | if (iSerialNumber || |
1507 | (!cdev->desc.iSerialNumber && composite->iSerialNumber)) | ||
1459 | cdev->serial_override = | 1508 | cdev->serial_override = |
1460 | override_id(cdev, &cdev->desc.iSerialNumber); | 1509 | override_id(cdev, &cdev->desc.iSerialNumber); |
1461 | 1510 | ||
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index a6dfd2164166..b799106027ad 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -595,14 +595,12 @@ static struct usb_request *dummy_alloc_request(struct usb_ep *_ep, | |||
595 | 595 | ||
596 | static void dummy_free_request(struct usb_ep *_ep, struct usb_request *_req) | 596 | static void dummy_free_request(struct usb_ep *_ep, struct usb_request *_req) |
597 | { | 597 | { |
598 | struct dummy_ep *ep; | ||
599 | struct dummy_request *req; | 598 | struct dummy_request *req; |
600 | 599 | ||
601 | if (!_ep || !_req) | 600 | if (!_ep || !_req) { |
602 | return; | 601 | WARN_ON(1); |
603 | ep = usb_ep_to_dummy_ep(_ep); | ||
604 | if (!ep->desc && _ep->name != ep0name) | ||
605 | return; | 602 | return; |
603 | } | ||
606 | 604 | ||
607 | req = usb_request_to_dummy_request(_req); | 605 | req = usb_request_to_dummy_request(_req); |
608 | WARN_ON(!list_empty(&req->queue)); | 606 | WARN_ON(!list_empty(&req->queue)); |
@@ -927,7 +925,6 @@ static int dummy_udc_stop(struct usb_gadget *g, | |||
927 | 925 | ||
928 | dum->driver = NULL; | 926 | dum->driver = NULL; |
929 | 927 | ||
930 | dummy_pullup(&dum->gadget, 0); | ||
931 | return 0; | 928 | return 0; |
932 | } | 929 | } |
933 | 930 | ||
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index f52cb1ae45d9..dcd1c7fbb016 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -1031,6 +1031,12 @@ struct ffs_sb_fill_data { | |||
1031 | struct ffs_file_perms perms; | 1031 | struct ffs_file_perms perms; |
1032 | umode_t root_mode; | 1032 | umode_t root_mode; |
1033 | const char *dev_name; | 1033 | const char *dev_name; |
1034 | union { | ||
1035 | /* set by ffs_fs_mount(), read by ffs_sb_fill() */ | ||
1036 | void *private_data; | ||
1037 | /* set by ffs_sb_fill(), read by ffs_fs_mount */ | ||
1038 | struct ffs_data *ffs_data; | ||
1039 | }; | ||
1034 | }; | 1040 | }; |
1035 | 1041 | ||
1036 | static int ffs_sb_fill(struct super_block *sb, void *_data, int silent) | 1042 | static int ffs_sb_fill(struct super_block *sb, void *_data, int silent) |
@@ -1047,8 +1053,14 @@ static int ffs_sb_fill(struct super_block *sb, void *_data, int silent) | |||
1047 | goto Enomem; | 1053 | goto Enomem; |
1048 | 1054 | ||
1049 | ffs->sb = sb; | 1055 | ffs->sb = sb; |
1050 | ffs->dev_name = data->dev_name; | 1056 | ffs->dev_name = kstrdup(data->dev_name, GFP_KERNEL); |
1057 | if (unlikely(!ffs->dev_name)) | ||
1058 | goto Enomem; | ||
1051 | ffs->file_perms = data->perms; | 1059 | ffs->file_perms = data->perms; |
1060 | ffs->private_data = data->private_data; | ||
1061 | |||
1062 | /* used by the caller of this function */ | ||
1063 | data->ffs_data = ffs; | ||
1052 | 1064 | ||
1053 | sb->s_fs_info = ffs; | 1065 | sb->s_fs_info = ffs; |
1054 | sb->s_blocksize = PAGE_CACHE_SIZE; | 1066 | sb->s_blocksize = PAGE_CACHE_SIZE; |
@@ -1167,20 +1179,29 @@ ffs_fs_mount(struct file_system_type *t, int flags, | |||
1167 | }, | 1179 | }, |
1168 | .root_mode = S_IFDIR | 0500, | 1180 | .root_mode = S_IFDIR | 0500, |
1169 | }; | 1181 | }; |
1182 | struct dentry *rv; | ||
1170 | int ret; | 1183 | int ret; |
1184 | void *ffs_dev; | ||
1171 | 1185 | ||
1172 | ENTER(); | 1186 | ENTER(); |
1173 | 1187 | ||
1174 | ret = functionfs_check_dev_callback(dev_name); | ||
1175 | if (unlikely(ret < 0)) | ||
1176 | return ERR_PTR(ret); | ||
1177 | |||
1178 | ret = ffs_fs_parse_opts(&data, opts); | 1188 | ret = ffs_fs_parse_opts(&data, opts); |
1179 | if (unlikely(ret < 0)) | 1189 | if (unlikely(ret < 0)) |
1180 | return ERR_PTR(ret); | 1190 | return ERR_PTR(ret); |
1181 | 1191 | ||
1192 | ffs_dev = functionfs_acquire_dev_callback(dev_name); | ||
1193 | if (IS_ERR(ffs_dev)) | ||
1194 | return ffs_dev; | ||
1195 | |||
1182 | data.dev_name = dev_name; | 1196 | data.dev_name = dev_name; |
1183 | return mount_single(t, flags, &data, ffs_sb_fill); | 1197 | data.private_data = ffs_dev; |
1198 | rv = mount_nodev(t, flags, &data, ffs_sb_fill); | ||
1199 | |||
1200 | /* data.ffs_data is set by ffs_sb_fill */ | ||
1201 | if (IS_ERR(rv)) | ||
1202 | functionfs_release_dev_callback(data.ffs_data); | ||
1203 | |||
1204 | return rv; | ||
1184 | } | 1205 | } |
1185 | 1206 | ||
1186 | static void | 1207 | static void |
@@ -1189,8 +1210,10 @@ ffs_fs_kill_sb(struct super_block *sb) | |||
1189 | ENTER(); | 1210 | ENTER(); |
1190 | 1211 | ||
1191 | kill_litter_super(sb); | 1212 | kill_litter_super(sb); |
1192 | if (sb->s_fs_info) | 1213 | if (sb->s_fs_info) { |
1214 | functionfs_release_dev_callback(sb->s_fs_info); | ||
1193 | ffs_data_put(sb->s_fs_info); | 1215 | ffs_data_put(sb->s_fs_info); |
1216 | } | ||
1194 | } | 1217 | } |
1195 | 1218 | ||
1196 | static struct file_system_type ffs_fs_type = { | 1219 | static struct file_system_type ffs_fs_type = { |
@@ -1256,6 +1279,7 @@ static void ffs_data_put(struct ffs_data *ffs) | |||
1256 | ffs_data_clear(ffs); | 1279 | ffs_data_clear(ffs); |
1257 | BUG_ON(waitqueue_active(&ffs->ev.waitq) || | 1280 | BUG_ON(waitqueue_active(&ffs->ev.waitq) || |
1258 | waitqueue_active(&ffs->ep0req_completion.wait)); | 1281 | waitqueue_active(&ffs->ep0req_completion.wait)); |
1282 | kfree(ffs->dev_name); | ||
1259 | kfree(ffs); | 1283 | kfree(ffs); |
1260 | } | 1284 | } |
1261 | } | 1285 | } |
@@ -1473,8 +1497,22 @@ static int functionfs_bind_config(struct usb_composite_dev *cdev, | |||
1473 | 1497 | ||
1474 | static void ffs_func_free(struct ffs_function *func) | 1498 | static void ffs_func_free(struct ffs_function *func) |
1475 | { | 1499 | { |
1500 | struct ffs_ep *ep = func->eps; | ||
1501 | unsigned count = func->ffs->eps_count; | ||
1502 | unsigned long flags; | ||
1503 | |||
1476 | ENTER(); | 1504 | ENTER(); |
1477 | 1505 | ||
1506 | /* cleanup after autoconfig */ | ||
1507 | spin_lock_irqsave(&func->ffs->eps_lock, flags); | ||
1508 | do { | ||
1509 | if (ep->ep && ep->req) | ||
1510 | usb_ep_free_request(ep->ep, ep->req); | ||
1511 | ep->req = NULL; | ||
1512 | ++ep; | ||
1513 | } while (--count); | ||
1514 | spin_unlock_irqrestore(&func->ffs->eps_lock, flags); | ||
1515 | |||
1478 | ffs_data_put(func->ffs); | 1516 | ffs_data_put(func->ffs); |
1479 | 1517 | ||
1480 | kfree(func->eps); | 1518 | kfree(func->eps); |
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c index b2113420b806..3b3932c55361 100644 --- a/drivers/usb/gadget/f_hid.c +++ b/drivers/usb/gadget/f_hid.c | |||
@@ -374,7 +374,7 @@ static int hidg_setup(struct usb_function *f, | |||
374 | break; | 374 | break; |
375 | 375 | ||
376 | default: | 376 | default: |
377 | VDBG(cdev, "Unknown decriptor request 0x%x\n", | 377 | VDBG(cdev, "Unknown descriptor request 0x%x\n", |
378 | value >> 8); | 378 | value >> 8); |
379 | goto stall; | 379 | goto stall; |
380 | break; | 380 | break; |
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index 2c0cd824c667..7275706caeb0 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -286,7 +286,7 @@ static void disable_loopback(struct f_loopback *loop) | |||
286 | struct usb_composite_dev *cdev; | 286 | struct usb_composite_dev *cdev; |
287 | 287 | ||
288 | cdev = loop->function.config->cdev; | 288 | cdev = loop->function.config->cdev; |
289 | disable_endpoints(cdev, loop->in_ep, loop->out_ep); | 289 | disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL); |
290 | VDBG(cdev, "%s disabled\n", loop->function.name); | 290 | VDBG(cdev, "%s disabled\n", loop->function.name); |
291 | } | 291 | } |
292 | 292 | ||
@@ -329,7 +329,7 @@ fail0: | |||
329 | * than 'buflen' bytes each. | 329 | * than 'buflen' bytes each. |
330 | */ | 330 | */ |
331 | for (i = 0; i < qlen && result == 0; i++) { | 331 | for (i = 0; i < qlen && result == 0; i++) { |
332 | req = alloc_ep_req(ep); | 332 | req = alloc_ep_req(ep, 0); |
333 | if (req) { | 333 | if (req) { |
334 | req->complete = loopback_complete; | 334 | req->complete = loopback_complete; |
335 | result = usb_ep_queue(ep, req, GFP_ATOMIC); | 335 | result = usb_ep_queue(ep, req, GFP_ATOMIC); |
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index a371e966425f..f67b453740bd 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -2189,7 +2189,7 @@ unknown_cmnd: | |||
2189 | common->data_size_from_cmnd = 0; | 2189 | common->data_size_from_cmnd = 0; |
2190 | sprintf(unknown, "Unknown x%02x", common->cmnd[0]); | 2190 | sprintf(unknown, "Unknown x%02x", common->cmnd[0]); |
2191 | reply = check_command(common, common->cmnd_size, | 2191 | reply = check_command(common, common->cmnd_size, |
2192 | DATA_DIR_UNKNOWN, 0xff, 0, unknown); | 2192 | DATA_DIR_UNKNOWN, ~0, 0, unknown); |
2193 | if (reply == 0) { | 2193 | if (reply == 0) { |
2194 | common->curlun->sense_data = SS_INVALID_COMMAND; | 2194 | common->curlun->sense_data = SS_INVALID_COMMAND; |
2195 | reply = -EINVAL; | 2195 | reply = -EINVAL; |
@@ -3110,13 +3110,6 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, | |||
3110 | return rc; | 3110 | return rc; |
3111 | } | 3111 | } |
3112 | 3112 | ||
3113 | static inline int __deprecated __maybe_unused | ||
3114 | fsg_add(struct usb_composite_dev *cdev, struct usb_configuration *c, | ||
3115 | struct fsg_common *common) | ||
3116 | { | ||
3117 | return fsg_bind_config(cdev, c, common); | ||
3118 | } | ||
3119 | |||
3120 | 3113 | ||
3121 | /************************* Module parameters *************************/ | 3114 | /************************* Module parameters *************************/ |
3122 | 3115 | ||
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 52343654f5df..b1681e45aca7 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -71,6 +71,8 @@ struct f_rndis { | |||
71 | struct gether port; | 71 | struct gether port; |
72 | u8 ctrl_id, data_id; | 72 | u8 ctrl_id, data_id; |
73 | u8 ethaddr[ETH_ALEN]; | 73 | u8 ethaddr[ETH_ALEN]; |
74 | u32 vendorID; | ||
75 | const char *manufacturer; | ||
74 | int config; | 76 | int config; |
75 | 77 | ||
76 | struct usb_ep *notify; | 78 | struct usb_ep *notify; |
@@ -637,7 +639,7 @@ static void rndis_open(struct gether *geth) | |||
637 | 639 | ||
638 | DBG(cdev, "%s\n", __func__); | 640 | DBG(cdev, "%s\n", __func__); |
639 | 641 | ||
640 | rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, | 642 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, |
641 | bitrate(cdev->gadget) / 100); | 643 | bitrate(cdev->gadget) / 100); |
642 | rndis_signal_connect(rndis->config); | 644 | rndis_signal_connect(rndis->config); |
643 | } | 645 | } |
@@ -648,7 +650,7 @@ static void rndis_close(struct gether *geth) | |||
648 | 650 | ||
649 | DBG(geth->func.config->cdev, "%s\n", __func__); | 651 | DBG(geth->func.config->cdev, "%s\n", __func__); |
650 | 652 | ||
651 | rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0); | 653 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); |
652 | rndis_signal_disconnect(rndis->config); | 654 | rndis_signal_disconnect(rndis->config); |
653 | } | 655 | } |
654 | 656 | ||
@@ -765,15 +767,13 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
765 | goto fail; | 767 | goto fail; |
766 | rndis->config = status; | 768 | rndis->config = status; |
767 | 769 | ||
768 | rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0); | 770 | rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); |
769 | rndis_set_host_mac(rndis->config, rndis->ethaddr); | 771 | rndis_set_host_mac(rndis->config, rndis->ethaddr); |
770 | 772 | ||
771 | #if 0 | 773 | if (rndis->manufacturer && rndis->vendorID && |
772 | // FIXME | 774 | rndis_set_param_vendor(rndis->config, rndis->vendorID, |
773 | if (rndis_set_param_vendor(rndis->config, vendorID, | 775 | rndis->manufacturer)) |
774 | manufacturer)) | 776 | goto fail; |
775 | goto fail0; | ||
776 | #endif | ||
777 | 777 | ||
778 | /* NOTE: all that is done without knowing or caring about | 778 | /* NOTE: all that is done without knowing or caring about |
779 | * the network link ... which is unavailable to this code | 779 | * the network link ... which is unavailable to this code |
@@ -820,6 +820,7 @@ rndis_unbind(struct usb_configuration *c, struct usb_function *f) | |||
820 | 820 | ||
821 | rndis_deregister(rndis->config); | 821 | rndis_deregister(rndis->config); |
822 | rndis_exit(); | 822 | rndis_exit(); |
823 | rndis_string_defs[0].id = 0; | ||
823 | 824 | ||
824 | if (gadget_is_superspeed(c->cdev->gadget)) | 825 | if (gadget_is_superspeed(c->cdev->gadget)) |
825 | usb_free_descriptors(f->ss_descriptors); | 826 | usb_free_descriptors(f->ss_descriptors); |
@@ -840,20 +841,9 @@ static inline bool can_support_rndis(struct usb_configuration *c) | |||
840 | return true; | 841 | return true; |
841 | } | 842 | } |
842 | 843 | ||
843 | /** | ||
844 | * rndis_bind_config - add RNDIS network link to a configuration | ||
845 | * @c: the configuration to support the network link | ||
846 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
847 | * side of the link was recorded | ||
848 | * Context: single threaded during gadget setup | ||
849 | * | ||
850 | * Returns zero on success, else negative errno. | ||
851 | * | ||
852 | * Caller must have called @gether_setup(). Caller is also responsible | ||
853 | * for calling @gether_cleanup() before module unload. | ||
854 | */ | ||
855 | int | 844 | int |
856 | rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 845 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
846 | u32 vendorID, const char *manufacturer) | ||
857 | { | 847 | { |
858 | struct f_rndis *rndis; | 848 | struct f_rndis *rndis; |
859 | int status; | 849 | int status; |
@@ -898,6 +888,8 @@ rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | |||
898 | goto fail; | 888 | goto fail; |
899 | 889 | ||
900 | memcpy(rndis->ethaddr, ethaddr, ETH_ALEN); | 890 | memcpy(rndis->ethaddr, ethaddr, ETH_ALEN); |
891 | rndis->vendorID = vendorID; | ||
892 | rndis->manufacturer = manufacturer; | ||
901 | 893 | ||
902 | /* RNDIS activates when the host changes this filter */ | 894 | /* RNDIS activates when the host changes this filter */ |
903 | rndis->port.cdc_filter = 0; | 895 | rndis->port.cdc_filter = 0; |
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c index 7aa7ac82c02c..5c1b68b63c98 100644 --- a/drivers/usb/gadget/f_sourcesink.c +++ b/drivers/usb/gadget/f_sourcesink.c | |||
@@ -51,6 +51,9 @@ struct f_sourcesink { | |||
51 | 51 | ||
52 | struct usb_ep *in_ep; | 52 | struct usb_ep *in_ep; |
53 | struct usb_ep *out_ep; | 53 | struct usb_ep *out_ep; |
54 | struct usb_ep *iso_in_ep; | ||
55 | struct usb_ep *iso_out_ep; | ||
56 | int cur_alt; | ||
54 | }; | 57 | }; |
55 | 58 | ||
56 | static inline struct f_sourcesink *func_to_ss(struct usb_function *f) | 59 | static inline struct f_sourcesink *func_to_ss(struct usb_function *f) |
@@ -59,18 +62,45 @@ static inline struct f_sourcesink *func_to_ss(struct usb_function *f) | |||
59 | } | 62 | } |
60 | 63 | ||
61 | static unsigned pattern; | 64 | static unsigned pattern; |
62 | module_param(pattern, uint, 0); | 65 | module_param(pattern, uint, S_IRUGO|S_IWUSR); |
63 | MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 "); | 66 | MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63, 2 = none"); |
67 | |||
68 | static unsigned isoc_interval = 4; | ||
69 | module_param(isoc_interval, uint, S_IRUGO|S_IWUSR); | ||
70 | MODULE_PARM_DESC(isoc_interval, "1 - 16"); | ||
71 | |||
72 | static unsigned isoc_maxpacket = 1024; | ||
73 | module_param(isoc_maxpacket, uint, S_IRUGO|S_IWUSR); | ||
74 | MODULE_PARM_DESC(isoc_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); | ||
75 | |||
76 | static unsigned isoc_mult; | ||
77 | module_param(isoc_mult, uint, S_IRUGO|S_IWUSR); | ||
78 | MODULE_PARM_DESC(isoc_mult, "0 - 2 (hs/ss only)"); | ||
79 | |||
80 | static unsigned isoc_maxburst; | ||
81 | module_param(isoc_maxburst, uint, S_IRUGO|S_IWUSR); | ||
82 | MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); | ||
64 | 83 | ||
65 | /*-------------------------------------------------------------------------*/ | 84 | /*-------------------------------------------------------------------------*/ |
66 | 85 | ||
67 | static struct usb_interface_descriptor source_sink_intf = { | 86 | static struct usb_interface_descriptor source_sink_intf_alt0 = { |
68 | .bLength = sizeof source_sink_intf, | 87 | .bLength = USB_DT_INTERFACE_SIZE, |
69 | .bDescriptorType = USB_DT_INTERFACE, | 88 | .bDescriptorType = USB_DT_INTERFACE, |
70 | 89 | ||
90 | .bAlternateSetting = 0, | ||
71 | .bNumEndpoints = 2, | 91 | .bNumEndpoints = 2, |
72 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | 92 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, |
73 | /* .iInterface = DYNAMIC */ | 93 | /* .iInterface = DYNAMIC */ |
94 | }; | ||
95 | |||
96 | static struct usb_interface_descriptor source_sink_intf_alt1 = { | ||
97 | .bLength = USB_DT_INTERFACE_SIZE, | ||
98 | .bDescriptorType = USB_DT_INTERFACE, | ||
99 | |||
100 | .bAlternateSetting = 1, | ||
101 | .bNumEndpoints = 4, | ||
102 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
103 | /* .iInterface = DYNAMIC */ | ||
74 | }; | 104 | }; |
75 | 105 | ||
76 | /* full speed support: */ | 106 | /* full speed support: */ |
@@ -91,10 +121,36 @@ static struct usb_endpoint_descriptor fs_sink_desc = { | |||
91 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 121 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
92 | }; | 122 | }; |
93 | 123 | ||
124 | static struct usb_endpoint_descriptor fs_iso_source_desc = { | ||
125 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
126 | .bDescriptorType = USB_DT_ENDPOINT, | ||
127 | |||
128 | .bEndpointAddress = USB_DIR_IN, | ||
129 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
130 | .wMaxPacketSize = cpu_to_le16(1023), | ||
131 | .bInterval = 4, | ||
132 | }; | ||
133 | |||
134 | static struct usb_endpoint_descriptor fs_iso_sink_desc = { | ||
135 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
136 | .bDescriptorType = USB_DT_ENDPOINT, | ||
137 | |||
138 | .bEndpointAddress = USB_DIR_OUT, | ||
139 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
140 | .wMaxPacketSize = cpu_to_le16(1023), | ||
141 | .bInterval = 4, | ||
142 | }; | ||
143 | |||
94 | static struct usb_descriptor_header *fs_source_sink_descs[] = { | 144 | static struct usb_descriptor_header *fs_source_sink_descs[] = { |
95 | (struct usb_descriptor_header *) &source_sink_intf, | 145 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
96 | (struct usb_descriptor_header *) &fs_sink_desc, | 146 | (struct usb_descriptor_header *) &fs_sink_desc, |
97 | (struct usb_descriptor_header *) &fs_source_desc, | 147 | (struct usb_descriptor_header *) &fs_source_desc, |
148 | (struct usb_descriptor_header *) &source_sink_intf_alt1, | ||
149 | #define FS_ALT_IFC_1_OFFSET 3 | ||
150 | (struct usb_descriptor_header *) &fs_sink_desc, | ||
151 | (struct usb_descriptor_header *) &fs_source_desc, | ||
152 | (struct usb_descriptor_header *) &fs_iso_sink_desc, | ||
153 | (struct usb_descriptor_header *) &fs_iso_source_desc, | ||
98 | NULL, | 154 | NULL, |
99 | }; | 155 | }; |
100 | 156 | ||
@@ -116,10 +172,34 @@ static struct usb_endpoint_descriptor hs_sink_desc = { | |||
116 | .wMaxPacketSize = cpu_to_le16(512), | 172 | .wMaxPacketSize = cpu_to_le16(512), |
117 | }; | 173 | }; |
118 | 174 | ||
175 | static struct usb_endpoint_descriptor hs_iso_source_desc = { | ||
176 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
177 | .bDescriptorType = USB_DT_ENDPOINT, | ||
178 | |||
179 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
180 | .wMaxPacketSize = cpu_to_le16(1024), | ||
181 | .bInterval = 4, | ||
182 | }; | ||
183 | |||
184 | static struct usb_endpoint_descriptor hs_iso_sink_desc = { | ||
185 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
186 | .bDescriptorType = USB_DT_ENDPOINT, | ||
187 | |||
188 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
189 | .wMaxPacketSize = cpu_to_le16(1024), | ||
190 | .bInterval = 4, | ||
191 | }; | ||
192 | |||
119 | static struct usb_descriptor_header *hs_source_sink_descs[] = { | 193 | static struct usb_descriptor_header *hs_source_sink_descs[] = { |
120 | (struct usb_descriptor_header *) &source_sink_intf, | 194 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
121 | (struct usb_descriptor_header *) &hs_source_desc, | 195 | (struct usb_descriptor_header *) &hs_source_desc, |
122 | (struct usb_descriptor_header *) &hs_sink_desc, | 196 | (struct usb_descriptor_header *) &hs_sink_desc, |
197 | (struct usb_descriptor_header *) &source_sink_intf_alt1, | ||
198 | #define HS_ALT_IFC_1_OFFSET 3 | ||
199 | (struct usb_descriptor_header *) &hs_source_desc, | ||
200 | (struct usb_descriptor_header *) &hs_sink_desc, | ||
201 | (struct usb_descriptor_header *) &hs_iso_source_desc, | ||
202 | (struct usb_descriptor_header *) &hs_iso_sink_desc, | ||
123 | NULL, | 203 | NULL, |
124 | }; | 204 | }; |
125 | 205 | ||
@@ -136,6 +216,7 @@ static struct usb_endpoint_descriptor ss_source_desc = { | |||
136 | struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { | 216 | struct usb_ss_ep_comp_descriptor ss_source_comp_desc = { |
137 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 217 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
138 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 218 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
219 | |||
139 | .bMaxBurst = 0, | 220 | .bMaxBurst = 0, |
140 | .bmAttributes = 0, | 221 | .bmAttributes = 0, |
141 | .wBytesPerInterval = 0, | 222 | .wBytesPerInterval = 0, |
@@ -152,17 +233,64 @@ static struct usb_endpoint_descriptor ss_sink_desc = { | |||
152 | struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { | 233 | struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = { |
153 | .bLength = USB_DT_SS_EP_COMP_SIZE, | 234 | .bLength = USB_DT_SS_EP_COMP_SIZE, |
154 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 235 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
236 | |||
155 | .bMaxBurst = 0, | 237 | .bMaxBurst = 0, |
156 | .bmAttributes = 0, | 238 | .bmAttributes = 0, |
157 | .wBytesPerInterval = 0, | 239 | .wBytesPerInterval = 0, |
158 | }; | 240 | }; |
159 | 241 | ||
242 | static struct usb_endpoint_descriptor ss_iso_source_desc = { | ||
243 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
244 | .bDescriptorType = USB_DT_ENDPOINT, | ||
245 | |||
246 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
247 | .wMaxPacketSize = cpu_to_le16(1024), | ||
248 | .bInterval = 4, | ||
249 | }; | ||
250 | |||
251 | struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = { | ||
252 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
253 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
254 | |||
255 | .bMaxBurst = 0, | ||
256 | .bmAttributes = 0, | ||
257 | .wBytesPerInterval = cpu_to_le16(1024), | ||
258 | }; | ||
259 | |||
260 | static struct usb_endpoint_descriptor ss_iso_sink_desc = { | ||
261 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
262 | .bDescriptorType = USB_DT_ENDPOINT, | ||
263 | |||
264 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, | ||
265 | .wMaxPacketSize = cpu_to_le16(1024), | ||
266 | .bInterval = 4, | ||
267 | }; | ||
268 | |||
269 | struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { | ||
270 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
271 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
272 | |||
273 | .bMaxBurst = 0, | ||
274 | .bmAttributes = 0, | ||
275 | .wBytesPerInterval = cpu_to_le16(1024), | ||
276 | }; | ||
277 | |||
160 | static struct usb_descriptor_header *ss_source_sink_descs[] = { | 278 | static struct usb_descriptor_header *ss_source_sink_descs[] = { |
161 | (struct usb_descriptor_header *) &source_sink_intf, | 279 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
162 | (struct usb_descriptor_header *) &ss_source_desc, | 280 | (struct usb_descriptor_header *) &ss_source_desc, |
163 | (struct usb_descriptor_header *) &ss_source_comp_desc, | 281 | (struct usb_descriptor_header *) &ss_source_comp_desc, |
164 | (struct usb_descriptor_header *) &ss_sink_desc, | 282 | (struct usb_descriptor_header *) &ss_sink_desc, |
165 | (struct usb_descriptor_header *) &ss_sink_comp_desc, | 283 | (struct usb_descriptor_header *) &ss_sink_comp_desc, |
284 | (struct usb_descriptor_header *) &source_sink_intf_alt1, | ||
285 | #define SS_ALT_IFC_1_OFFSET 5 | ||
286 | (struct usb_descriptor_header *) &ss_source_desc, | ||
287 | (struct usb_descriptor_header *) &ss_source_comp_desc, | ||
288 | (struct usb_descriptor_header *) &ss_sink_desc, | ||
289 | (struct usb_descriptor_header *) &ss_sink_comp_desc, | ||
290 | (struct usb_descriptor_header *) &ss_iso_source_desc, | ||
291 | (struct usb_descriptor_header *) &ss_iso_source_comp_desc, | ||
292 | (struct usb_descriptor_header *) &ss_iso_sink_desc, | ||
293 | (struct usb_descriptor_header *) &ss_iso_sink_comp_desc, | ||
166 | NULL, | 294 | NULL, |
167 | }; | 295 | }; |
168 | 296 | ||
@@ -196,9 +324,10 @@ sourcesink_bind(struct usb_configuration *c, struct usb_function *f) | |||
196 | id = usb_interface_id(c, f); | 324 | id = usb_interface_id(c, f); |
197 | if (id < 0) | 325 | if (id < 0) |
198 | return id; | 326 | return id; |
199 | source_sink_intf.bInterfaceNumber = id; | 327 | source_sink_intf_alt0.bInterfaceNumber = id; |
328 | source_sink_intf_alt1.bInterfaceNumber = id; | ||
200 | 329 | ||
201 | /* allocate endpoints */ | 330 | /* allocate bulk endpoints */ |
202 | ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); | 331 | ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); |
203 | if (!ss->in_ep) { | 332 | if (!ss->in_ep) { |
204 | autoconf_fail: | 333 | autoconf_fail: |
@@ -213,12 +342,74 @@ autoconf_fail: | |||
213 | goto autoconf_fail; | 342 | goto autoconf_fail; |
214 | ss->out_ep->driver_data = cdev; /* claim */ | 343 | ss->out_ep->driver_data = cdev; /* claim */ |
215 | 344 | ||
345 | /* sanity check the isoc module parameters */ | ||
346 | if (isoc_interval < 1) | ||
347 | isoc_interval = 1; | ||
348 | if (isoc_interval > 16) | ||
349 | isoc_interval = 16; | ||
350 | if (isoc_mult > 2) | ||
351 | isoc_mult = 2; | ||
352 | if (isoc_maxburst > 15) | ||
353 | isoc_maxburst = 15; | ||
354 | |||
355 | /* fill in the FS isoc descriptors from the module parameters */ | ||
356 | fs_iso_source_desc.wMaxPacketSize = isoc_maxpacket > 1023 ? | ||
357 | 1023 : isoc_maxpacket; | ||
358 | fs_iso_source_desc.bInterval = isoc_interval; | ||
359 | fs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket > 1023 ? | ||
360 | 1023 : isoc_maxpacket; | ||
361 | fs_iso_sink_desc.bInterval = isoc_interval; | ||
362 | |||
363 | /* allocate iso endpoints */ | ||
364 | ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_source_desc); | ||
365 | if (!ss->iso_in_ep) | ||
366 | goto no_iso; | ||
367 | ss->iso_in_ep->driver_data = cdev; /* claim */ | ||
368 | |||
369 | ss->iso_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_sink_desc); | ||
370 | if (ss->iso_out_ep) { | ||
371 | ss->iso_out_ep->driver_data = cdev; /* claim */ | ||
372 | } else { | ||
373 | ss->iso_in_ep->driver_data = NULL; | ||
374 | ss->iso_in_ep = NULL; | ||
375 | no_iso: | ||
376 | /* | ||
377 | * We still want to work even if the UDC doesn't have isoc | ||
378 | * endpoints, so null out the alt interface that contains | ||
379 | * them and continue. | ||
380 | */ | ||
381 | fs_source_sink_descs[FS_ALT_IFC_1_OFFSET] = NULL; | ||
382 | hs_source_sink_descs[HS_ALT_IFC_1_OFFSET] = NULL; | ||
383 | ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL; | ||
384 | } | ||
385 | |||
386 | if (isoc_maxpacket > 1024) | ||
387 | isoc_maxpacket = 1024; | ||
388 | |||
216 | /* support high speed hardware */ | 389 | /* support high speed hardware */ |
217 | if (gadget_is_dualspeed(c->cdev->gadget)) { | 390 | if (gadget_is_dualspeed(c->cdev->gadget)) { |
218 | hs_source_desc.bEndpointAddress = | 391 | hs_source_desc.bEndpointAddress = |
219 | fs_source_desc.bEndpointAddress; | 392 | fs_source_desc.bEndpointAddress; |
220 | hs_sink_desc.bEndpointAddress = | 393 | hs_sink_desc.bEndpointAddress = |
221 | fs_sink_desc.bEndpointAddress; | 394 | fs_sink_desc.bEndpointAddress; |
395 | |||
396 | /* | ||
397 | * Fill in the HS isoc descriptors from the module parameters. | ||
398 | * We assume that the user knows what they are doing and won't | ||
399 | * give parameters that their UDC doesn't support. | ||
400 | */ | ||
401 | hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket; | ||
402 | hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11; | ||
403 | hs_iso_source_desc.bInterval = isoc_interval; | ||
404 | hs_iso_source_desc.bEndpointAddress = | ||
405 | fs_iso_source_desc.bEndpointAddress; | ||
406 | |||
407 | hs_iso_sink_desc.wMaxPacketSize = isoc_maxpacket; | ||
408 | hs_iso_sink_desc.wMaxPacketSize |= isoc_mult << 11; | ||
409 | hs_iso_sink_desc.bInterval = isoc_interval; | ||
410 | hs_iso_sink_desc.bEndpointAddress = | ||
411 | fs_iso_sink_desc.bEndpointAddress; | ||
412 | |||
222 | f->hs_descriptors = hs_source_sink_descs; | 413 | f->hs_descriptors = hs_source_sink_descs; |
223 | } | 414 | } |
224 | 415 | ||
@@ -228,13 +419,39 @@ autoconf_fail: | |||
228 | fs_source_desc.bEndpointAddress; | 419 | fs_source_desc.bEndpointAddress; |
229 | ss_sink_desc.bEndpointAddress = | 420 | ss_sink_desc.bEndpointAddress = |
230 | fs_sink_desc.bEndpointAddress; | 421 | fs_sink_desc.bEndpointAddress; |
422 | |||
423 | /* | ||
424 | * Fill in the SS isoc descriptors from the module parameters. | ||
425 | * We assume that the user knows what they are doing and won't | ||
426 | * give parameters that their UDC doesn't support. | ||
427 | */ | ||
428 | ss_iso_source_desc.wMaxPacketSize = isoc_maxpacket; | ||
429 | ss_iso_source_desc.bInterval = isoc_interval; | ||
430 | ss_iso_source_comp_desc.bmAttributes = isoc_mult; | ||
431 | ss_iso_source_comp_desc.bMaxBurst = isoc_maxburst; | ||
432 | ss_iso_source_comp_desc.wBytesPerInterval = | ||
433 | isoc_maxpacket * (isoc_mult + 1) * (isoc_maxburst + 1); | ||
434 | ss_iso_source_desc.bEndpointAddress = | ||
435 | fs_iso_source_desc.bEndpointAddress; | ||
436 | |||
437 | ss_iso_sink_desc.wMaxPacketSize = isoc_maxpacket; | ||
438 | ss_iso_sink_desc.bInterval = isoc_interval; | ||
439 | ss_iso_sink_comp_desc.bmAttributes = isoc_mult; | ||
440 | ss_iso_sink_comp_desc.bMaxBurst = isoc_maxburst; | ||
441 | ss_iso_sink_comp_desc.wBytesPerInterval = | ||
442 | isoc_maxpacket * (isoc_mult + 1) * (isoc_maxburst + 1); | ||
443 | ss_iso_sink_desc.bEndpointAddress = | ||
444 | fs_iso_sink_desc.bEndpointAddress; | ||
445 | |||
231 | f->ss_descriptors = ss_source_sink_descs; | 446 | f->ss_descriptors = ss_source_sink_descs; |
232 | } | 447 | } |
233 | 448 | ||
234 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s\n", | 449 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n", |
235 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : | 450 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : |
236 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), | 451 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), |
237 | f->name, ss->in_ep->name, ss->out_ep->name); | 452 | f->name, ss->in_ep->name, ss->out_ep->name, |
453 | ss->iso_in_ep ? ss->iso_in_ep->name : "<none>", | ||
454 | ss->iso_out_ep ? ss->iso_out_ep->name : "<none>"); | ||
238 | return 0; | 455 | return 0; |
239 | } | 456 | } |
240 | 457 | ||
@@ -251,6 +468,9 @@ static int check_read_data(struct f_sourcesink *ss, struct usb_request *req) | |||
251 | u8 *buf = req->buf; | 468 | u8 *buf = req->buf; |
252 | struct usb_composite_dev *cdev = ss->function.config->cdev; | 469 | struct usb_composite_dev *cdev = ss->function.config->cdev; |
253 | 470 | ||
471 | if (pattern == 2) | ||
472 | return 0; | ||
473 | |||
254 | for (i = 0; i < req->actual; i++, buf++) { | 474 | for (i = 0; i < req->actual; i++, buf++) { |
255 | switch (pattern) { | 475 | switch (pattern) { |
256 | 476 | ||
@@ -265,7 +485,7 @@ static int check_read_data(struct f_sourcesink *ss, struct usb_request *req) | |||
265 | * each usb transfer request should be. Resync is done | 485 | * each usb transfer request should be. Resync is done |
266 | * with set_interface or set_config. (We *WANT* it to | 486 | * with set_interface or set_config. (We *WANT* it to |
267 | * get quickly out of sync if controllers or their drivers | 487 | * get quickly out of sync if controllers or their drivers |
268 | * stutter for any reason, including buffer duplcation...) | 488 | * stutter for any reason, including buffer duplication...) |
269 | */ | 489 | */ |
270 | case 1: | 490 | case 1: |
271 | if (*buf == (u8)(i % 63)) | 491 | if (*buf == (u8)(i % 63)) |
@@ -292,21 +512,30 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req) | |||
292 | for (i = 0; i < req->length; i++) | 512 | for (i = 0; i < req->length; i++) |
293 | *buf++ = (u8) (i % 63); | 513 | *buf++ = (u8) (i % 63); |
294 | break; | 514 | break; |
515 | case 2: | ||
516 | break; | ||
295 | } | 517 | } |
296 | } | 518 | } |
297 | 519 | ||
298 | static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) | 520 | static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) |
299 | { | 521 | { |
300 | struct f_sourcesink *ss = ep->driver_data; | 522 | struct usb_composite_dev *cdev; |
301 | struct usb_composite_dev *cdev = ss->function.config->cdev; | 523 | struct f_sourcesink *ss = ep->driver_data; |
302 | int status = req->status; | 524 | int status = req->status; |
525 | |||
526 | /* driver_data will be null if ep has been disabled */ | ||
527 | if (!ss) | ||
528 | return; | ||
529 | |||
530 | cdev = ss->function.config->cdev; | ||
303 | 531 | ||
304 | switch (status) { | 532 | switch (status) { |
305 | 533 | ||
306 | case 0: /* normal completion? */ | 534 | case 0: /* normal completion? */ |
307 | if (ep == ss->out_ep) { | 535 | if (ep == ss->out_ep) { |
308 | check_read_data(ss, req); | 536 | check_read_data(ss, req); |
309 | memset(req->buf, 0x55, req->length); | 537 | if (pattern != 2) |
538 | memset(req->buf, 0x55, req->length); | ||
310 | } else | 539 | } else |
311 | reinit_write_data(ep, req); | 540 | reinit_write_data(ep, req); |
312 | break; | 541 | break; |
@@ -344,32 +573,57 @@ static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) | |||
344 | } | 573 | } |
345 | } | 574 | } |
346 | 575 | ||
347 | static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in) | 576 | static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, |
577 | bool is_iso, int speed) | ||
348 | { | 578 | { |
349 | struct usb_ep *ep; | 579 | struct usb_ep *ep; |
350 | struct usb_request *req; | 580 | struct usb_request *req; |
351 | int status; | 581 | int i, size, status; |
582 | |||
583 | for (i = 0; i < 8; i++) { | ||
584 | if (is_iso) { | ||
585 | switch (speed) { | ||
586 | case USB_SPEED_SUPER: | ||
587 | size = isoc_maxpacket * (isoc_mult + 1) * | ||
588 | (isoc_maxburst + 1); | ||
589 | break; | ||
590 | case USB_SPEED_HIGH: | ||
591 | size = isoc_maxpacket * (isoc_mult + 1); | ||
592 | break; | ||
593 | default: | ||
594 | size = isoc_maxpacket > 1023 ? | ||
595 | 1023 : isoc_maxpacket; | ||
596 | break; | ||
597 | } | ||
598 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; | ||
599 | req = alloc_ep_req(ep, size); | ||
600 | } else { | ||
601 | ep = is_in ? ss->in_ep : ss->out_ep; | ||
602 | req = alloc_ep_req(ep, 0); | ||
603 | } | ||
352 | 604 | ||
353 | ep = is_in ? ss->in_ep : ss->out_ep; | 605 | if (!req) |
354 | req = alloc_ep_req(ep); | 606 | return -ENOMEM; |
355 | if (!req) | ||
356 | return -ENOMEM; | ||
357 | 607 | ||
358 | req->complete = source_sink_complete; | 608 | req->complete = source_sink_complete; |
359 | if (is_in) | 609 | if (is_in) |
360 | reinit_write_data(ep, req); | 610 | reinit_write_data(ep, req); |
361 | else | 611 | else if (pattern != 2) |
362 | memset(req->buf, 0x55, req->length); | 612 | memset(req->buf, 0x55, req->length); |
363 | 613 | ||
364 | status = usb_ep_queue(ep, req, GFP_ATOMIC); | 614 | status = usb_ep_queue(ep, req, GFP_ATOMIC); |
365 | if (status) { | 615 | if (status) { |
366 | struct usb_composite_dev *cdev; | 616 | struct usb_composite_dev *cdev; |
367 | 617 | ||
368 | cdev = ss->function.config->cdev; | 618 | cdev = ss->function.config->cdev; |
369 | ERROR(cdev, "start %s %s --> %d\n", | 619 | ERROR(cdev, "start %s%s %s --> %d\n", |
370 | is_in ? "IN" : "OUT", | 620 | is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", |
371 | ep->name, status); | 621 | ep->name, status); |
372 | free_ep_req(ep, req); | 622 | free_ep_req(ep, req); |
623 | } | ||
624 | |||
625 | if (!is_iso) | ||
626 | break; | ||
373 | } | 627 | } |
374 | 628 | ||
375 | return status; | 629 | return status; |
@@ -380,17 +634,20 @@ static void disable_source_sink(struct f_sourcesink *ss) | |||
380 | struct usb_composite_dev *cdev; | 634 | struct usb_composite_dev *cdev; |
381 | 635 | ||
382 | cdev = ss->function.config->cdev; | 636 | cdev = ss->function.config->cdev; |
383 | disable_endpoints(cdev, ss->in_ep, ss->out_ep); | 637 | disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep, |
638 | ss->iso_out_ep); | ||
384 | VDBG(cdev, "%s disabled\n", ss->function.name); | 639 | VDBG(cdev, "%s disabled\n", ss->function.name); |
385 | } | 640 | } |
386 | 641 | ||
387 | static int | 642 | static int |
388 | enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss) | 643 | enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss, |
644 | int alt) | ||
389 | { | 645 | { |
390 | int result = 0; | 646 | int result = 0; |
647 | int speed = cdev->gadget->speed; | ||
391 | struct usb_ep *ep; | 648 | struct usb_ep *ep; |
392 | 649 | ||
393 | /* one endpoint writes (sources) zeroes IN (to the host) */ | 650 | /* one bulk endpoint writes (sources) zeroes IN (to the host) */ |
394 | ep = ss->in_ep; | 651 | ep = ss->in_ep; |
395 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); | 652 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); |
396 | if (result) | 653 | if (result) |
@@ -400,7 +657,7 @@ enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss) | |||
400 | return result; | 657 | return result; |
401 | ep->driver_data = ss; | 658 | ep->driver_data = ss; |
402 | 659 | ||
403 | result = source_sink_start_ep(ss, true); | 660 | result = source_sink_start_ep(ss, true, false, speed); |
404 | if (result < 0) { | 661 | if (result < 0) { |
405 | fail: | 662 | fail: |
406 | ep = ss->in_ep; | 663 | ep = ss->in_ep; |
@@ -409,7 +666,7 @@ fail: | |||
409 | return result; | 666 | return result; |
410 | } | 667 | } |
411 | 668 | ||
412 | /* one endpoint reads (sinks) anything OUT (from the host) */ | 669 | /* one bulk endpoint reads (sinks) anything OUT (from the host) */ |
413 | ep = ss->out_ep; | 670 | ep = ss->out_ep; |
414 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); | 671 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); |
415 | if (result) | 672 | if (result) |
@@ -419,27 +676,82 @@ fail: | |||
419 | goto fail; | 676 | goto fail; |
420 | ep->driver_data = ss; | 677 | ep->driver_data = ss; |
421 | 678 | ||
422 | result = source_sink_start_ep(ss, false); | 679 | result = source_sink_start_ep(ss, false, false, speed); |
423 | if (result < 0) { | 680 | if (result < 0) { |
681 | fail2: | ||
682 | ep = ss->out_ep; | ||
424 | usb_ep_disable(ep); | 683 | usb_ep_disable(ep); |
425 | ep->driver_data = NULL; | 684 | ep->driver_data = NULL; |
426 | goto fail; | 685 | goto fail; |
427 | } | 686 | } |
428 | 687 | ||
429 | DBG(cdev, "%s enabled\n", ss->function.name); | 688 | if (alt == 0) |
689 | goto out; | ||
690 | |||
691 | /* one iso endpoint writes (sources) zeroes IN (to the host) */ | ||
692 | ep = ss->iso_in_ep; | ||
693 | if (ep) { | ||
694 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); | ||
695 | if (result) | ||
696 | goto fail2; | ||
697 | result = usb_ep_enable(ep); | ||
698 | if (result < 0) | ||
699 | goto fail2; | ||
700 | ep->driver_data = ss; | ||
701 | |||
702 | result = source_sink_start_ep(ss, true, true, speed); | ||
703 | if (result < 0) { | ||
704 | fail3: | ||
705 | ep = ss->iso_in_ep; | ||
706 | if (ep) { | ||
707 | usb_ep_disable(ep); | ||
708 | ep->driver_data = NULL; | ||
709 | } | ||
710 | goto fail2; | ||
711 | } | ||
712 | } | ||
713 | |||
714 | /* one iso endpoint reads (sinks) anything OUT (from the host) */ | ||
715 | ep = ss->iso_out_ep; | ||
716 | if (ep) { | ||
717 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); | ||
718 | if (result) | ||
719 | goto fail3; | ||
720 | result = usb_ep_enable(ep); | ||
721 | if (result < 0) | ||
722 | goto fail3; | ||
723 | ep->driver_data = ss; | ||
724 | |||
725 | result = source_sink_start_ep(ss, false, true, speed); | ||
726 | if (result < 0) { | ||
727 | usb_ep_disable(ep); | ||
728 | ep->driver_data = NULL; | ||
729 | goto fail3; | ||
730 | } | ||
731 | } | ||
732 | out: | ||
733 | ss->cur_alt = alt; | ||
734 | |||
735 | DBG(cdev, "%s enabled, alt intf %d\n", ss->function.name, alt); | ||
430 | return result; | 736 | return result; |
431 | } | 737 | } |
432 | 738 | ||
433 | static int sourcesink_set_alt(struct usb_function *f, | 739 | static int sourcesink_set_alt(struct usb_function *f, |
434 | unsigned intf, unsigned alt) | 740 | unsigned intf, unsigned alt) |
435 | { | 741 | { |
436 | struct f_sourcesink *ss = func_to_ss(f); | 742 | struct f_sourcesink *ss = func_to_ss(f); |
437 | struct usb_composite_dev *cdev = f->config->cdev; | 743 | struct usb_composite_dev *cdev = f->config->cdev; |
438 | 744 | ||
439 | /* we know alt is zero */ | ||
440 | if (ss->in_ep->driver_data) | 745 | if (ss->in_ep->driver_data) |
441 | disable_source_sink(ss); | 746 | disable_source_sink(ss); |
442 | return enable_source_sink(cdev, ss); | 747 | return enable_source_sink(cdev, ss, alt); |
748 | } | ||
749 | |||
750 | static int sourcesink_get_alt(struct usb_function *f, unsigned intf) | ||
751 | { | ||
752 | struct f_sourcesink *ss = func_to_ss(f); | ||
753 | |||
754 | return ss->cur_alt; | ||
443 | } | 755 | } |
444 | 756 | ||
445 | static void sourcesink_disable(struct usb_function *f) | 757 | static void sourcesink_disable(struct usb_function *f) |
@@ -465,6 +777,7 @@ static int __init sourcesink_bind_config(struct usb_configuration *c) | |||
465 | ss->function.bind = sourcesink_bind; | 777 | ss->function.bind = sourcesink_bind; |
466 | ss->function.unbind = sourcesink_unbind; | 778 | ss->function.unbind = sourcesink_unbind; |
467 | ss->function.set_alt = sourcesink_set_alt; | 779 | ss->function.set_alt = sourcesink_set_alt; |
780 | ss->function.get_alt = sourcesink_get_alt; | ||
468 | ss->function.disable = sourcesink_disable; | 781 | ss->function.disable = sourcesink_disable; |
469 | 782 | ||
470 | status = usb_add_function(c, &ss->function); | 783 | status = usb_add_function(c, &ss->function); |
@@ -536,7 +849,7 @@ unknown: | |||
536 | req->length = value; | 849 | req->length = value; |
537 | value = usb_ep_queue(c->cdev->gadget->ep0, req, GFP_ATOMIC); | 850 | value = usb_ep_queue(c->cdev->gadget->ep0, req, GFP_ATOMIC); |
538 | if (value < 0) | 851 | if (value < 0) |
539 | ERROR(c->cdev, "source/sinkc response, err %d\n", | 852 | ERROR(c->cdev, "source/sink response, err %d\n", |
540 | value); | 853 | value); |
541 | } | 854 | } |
542 | 855 | ||
@@ -545,12 +858,12 @@ unknown: | |||
545 | } | 858 | } |
546 | 859 | ||
547 | static struct usb_configuration sourcesink_driver = { | 860 | static struct usb_configuration sourcesink_driver = { |
548 | .label = "source/sink", | 861 | .label = "source/sink", |
549 | .strings = sourcesink_strings, | 862 | .strings = sourcesink_strings, |
550 | .setup = sourcesink_setup, | 863 | .setup = sourcesink_setup, |
551 | .bConfigurationValue = 3, | 864 | .bConfigurationValue = 3, |
552 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 865 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
553 | /* .iConfiguration = DYNAMIC */ | 866 | /* .iConfiguration = DYNAMIC */ |
554 | }; | 867 | }; |
555 | 868 | ||
556 | /** | 869 | /** |
@@ -567,7 +880,8 @@ int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume) | |||
567 | return id; | 880 | return id; |
568 | strings_sourcesink[0].id = id; | 881 | strings_sourcesink[0].id = id; |
569 | 882 | ||
570 | source_sink_intf.iInterface = id; | 883 | source_sink_intf_alt0.iInterface = id; |
884 | source_sink_intf_alt1.iInterface = id; | ||
571 | sourcesink_driver.iConfiguration = id; | 885 | sourcesink_driver.iConfiguration = id; |
572 | 886 | ||
573 | /* support autoresume for remote wakeup testing */ | 887 | /* support autoresume for remote wakeup testing */ |
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index 4fac56927741..a896d73f7a93 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -2579,7 +2579,7 @@ static int do_scsi_command(struct fsg_dev *fsg) | |||
2579 | fsg->data_size_from_cmnd = 0; | 2579 | fsg->data_size_from_cmnd = 0; |
2580 | sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]); | 2580 | sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]); |
2581 | if ((reply = check_command(fsg, fsg->cmnd_size, | 2581 | if ((reply = check_command(fsg, fsg->cmnd_size, |
2582 | DATA_DIR_UNKNOWN, 0xff, 0, unknown)) == 0) { | 2582 | DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) { |
2583 | fsg->curlun->sense_data = SS_INVALID_COMMAND; | 2583 | fsg->curlun->sense_data = SS_INVALID_COMMAND; |
2584 | reply = -EINVAL; | 2584 | reply = -EINVAL; |
2585 | } | 2585 | } |
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c index 877a2c46672b..51881f3bd07a 100644 --- a/drivers/usb/gadget/fsl_qe_udc.c +++ b/drivers/usb/gadget/fsl_qe_udc.c | |||
@@ -71,9 +71,6 @@ static struct usb_endpoint_descriptor qe_ep0_desc = { | |||
71 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, | 71 | .wMaxPacketSize = USB_MAX_CTRL_PAYLOAD, |
72 | }; | 72 | }; |
73 | 73 | ||
74 | /* it is initialized in probe() */ | ||
75 | static struct qe_udc *udc_controller; | ||
76 | |||
77 | /******************************************************************** | 74 | /******************************************************************** |
78 | * Internal Used Function Start | 75 | * Internal Used Function Start |
79 | ********************************************************************/ | 76 | ********************************************************************/ |
@@ -188,8 +185,8 @@ static int qe_ep0_stall(struct qe_udc *udc) | |||
188 | { | 185 | { |
189 | qe_eptx_stall_change(&udc->eps[0], 1); | 186 | qe_eptx_stall_change(&udc->eps[0], 1); |
190 | qe_eprx_stall_change(&udc->eps[0], 1); | 187 | qe_eprx_stall_change(&udc->eps[0], 1); |
191 | udc_controller->ep0_state = WAIT_FOR_SETUP; | 188 | udc->ep0_state = WAIT_FOR_SETUP; |
192 | udc_controller->ep0_dir = 0; | 189 | udc->ep0_dir = 0; |
193 | return 0; | 190 | return 0; |
194 | } | 191 | } |
195 | 192 | ||
@@ -450,13 +447,13 @@ static int qe_ep_rxbd_update(struct qe_ep *ep) | |||
450 | 447 | ||
451 | ep->rxbuf_d = virt_to_phys((void *)ep->rxbuffer); | 448 | ep->rxbuf_d = virt_to_phys((void *)ep->rxbuffer); |
452 | if (ep->rxbuf_d == DMA_ADDR_INVALID) { | 449 | if (ep->rxbuf_d == DMA_ADDR_INVALID) { |
453 | ep->rxbuf_d = dma_map_single(udc_controller->gadget.dev.parent, | 450 | ep->rxbuf_d = dma_map_single(ep->udc->gadget.dev.parent, |
454 | ep->rxbuffer, | 451 | ep->rxbuffer, |
455 | size, | 452 | size, |
456 | DMA_FROM_DEVICE); | 453 | DMA_FROM_DEVICE); |
457 | ep->rxbufmap = 1; | 454 | ep->rxbufmap = 1; |
458 | } else { | 455 | } else { |
459 | dma_sync_single_for_device(udc_controller->gadget.dev.parent, | 456 | dma_sync_single_for_device(ep->udc->gadget.dev.parent, |
460 | ep->rxbuf_d, size, | 457 | ep->rxbuf_d, size, |
461 | DMA_FROM_DEVICE); | 458 | DMA_FROM_DEVICE); |
462 | ep->rxbufmap = 0; | 459 | ep->rxbufmap = 0; |
@@ -489,10 +486,10 @@ static int qe_ep_register_init(struct qe_udc *udc, unsigned char pipe_num) | |||
489 | epparam = udc->ep_param[pipe_num]; | 486 | epparam = udc->ep_param[pipe_num]; |
490 | 487 | ||
491 | usep = 0; | 488 | usep = 0; |
492 | logepnum = (ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); | 489 | logepnum = (ep->ep.desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
493 | usep |= (logepnum << USB_EPNUM_SHIFT); | 490 | usep |= (logepnum << USB_EPNUM_SHIFT); |
494 | 491 | ||
495 | switch (ep->desc->bmAttributes & 0x03) { | 492 | switch (ep->ep.desc->bmAttributes & 0x03) { |
496 | case USB_ENDPOINT_XFER_BULK: | 493 | case USB_ENDPOINT_XFER_BULK: |
497 | usep |= USB_TRANS_BULK; | 494 | usep |= USB_TRANS_BULK; |
498 | break; | 495 | break; |
@@ -644,7 +641,7 @@ static int qe_ep_init(struct qe_udc *udc, | |||
644 | /* initialize ep structure */ | 641 | /* initialize ep structure */ |
645 | ep->ep.maxpacket = max; | 642 | ep->ep.maxpacket = max; |
646 | ep->tm = (u8)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); | 643 | ep->tm = (u8)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); |
647 | ep->desc = desc; | 644 | ep->ep.desc = desc; |
648 | ep->stopped = 0; | 645 | ep->stopped = 0; |
649 | ep->init = 1; | 646 | ep->init = 1; |
650 | 647 | ||
@@ -698,14 +695,14 @@ en_done: | |||
698 | return -ENODEV; | 695 | return -ENODEV; |
699 | } | 696 | } |
700 | 697 | ||
701 | static inline void qe_usb_enable(void) | 698 | static inline void qe_usb_enable(struct qe_udc *udc) |
702 | { | 699 | { |
703 | setbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); | 700 | setbits8(&udc->usb_regs->usb_usmod, USB_MODE_EN); |
704 | } | 701 | } |
705 | 702 | ||
706 | static inline void qe_usb_disable(void) | 703 | static inline void qe_usb_disable(struct qe_udc *udc) |
707 | { | 704 | { |
708 | clrbits8(&udc_controller->usb_regs->usb_usmod, USB_MODE_EN); | 705 | clrbits8(&udc->usb_regs->usb_usmod, USB_MODE_EN); |
709 | } | 706 | } |
710 | 707 | ||
711 | /*----------------------------------------------------------------------------* | 708 | /*----------------------------------------------------------------------------* |
@@ -1599,7 +1596,7 @@ static int qe_ep_enable(struct usb_ep *_ep, | |||
1599 | ep = container_of(_ep, struct qe_ep, ep); | 1596 | ep = container_of(_ep, struct qe_ep, ep); |
1600 | 1597 | ||
1601 | /* catch various bogus parameters */ | 1598 | /* catch various bogus parameters */ |
1602 | if (!_ep || !desc || ep->desc || _ep->name == ep_name[0] || | 1599 | if (!_ep || !desc || ep->ep.desc || _ep->name == ep_name[0] || |
1603 | (desc->bDescriptorType != USB_DT_ENDPOINT)) | 1600 | (desc->bDescriptorType != USB_DT_ENDPOINT)) |
1604 | return -EINVAL; | 1601 | return -EINVAL; |
1605 | 1602 | ||
@@ -1629,7 +1626,7 @@ static int qe_ep_disable(struct usb_ep *_ep) | |||
1629 | ep = container_of(_ep, struct qe_ep, ep); | 1626 | ep = container_of(_ep, struct qe_ep, ep); |
1630 | udc = ep->udc; | 1627 | udc = ep->udc; |
1631 | 1628 | ||
1632 | if (!_ep || !ep->desc) { | 1629 | if (!_ep || !ep->ep.desc) { |
1633 | dev_dbg(udc->dev, "%s not enabled\n", _ep ? ep->ep.name : NULL); | 1630 | dev_dbg(udc->dev, "%s not enabled\n", _ep ? ep->ep.name : NULL); |
1634 | return -EINVAL; | 1631 | return -EINVAL; |
1635 | } | 1632 | } |
@@ -1637,7 +1634,6 @@ static int qe_ep_disable(struct usb_ep *_ep) | |||
1637 | spin_lock_irqsave(&udc->lock, flags); | 1634 | spin_lock_irqsave(&udc->lock, flags); |
1638 | /* Nuke all pending requests (does flush) */ | 1635 | /* Nuke all pending requests (does flush) */ |
1639 | nuke(ep, -ESHUTDOWN); | 1636 | nuke(ep, -ESHUTDOWN); |
1640 | ep->desc = NULL; | ||
1641 | ep->ep.desc = NULL; | 1637 | ep->ep.desc = NULL; |
1642 | ep->stopped = 1; | 1638 | ep->stopped = 1; |
1643 | ep->tx_req = NULL; | 1639 | ep->tx_req = NULL; |
@@ -1656,13 +1652,13 @@ static int qe_ep_disable(struct usb_ep *_ep) | |||
1656 | if (ep->dir != USB_DIR_IN) { | 1652 | if (ep->dir != USB_DIR_IN) { |
1657 | kfree(ep->rxframe); | 1653 | kfree(ep->rxframe); |
1658 | if (ep->rxbufmap) { | 1654 | if (ep->rxbufmap) { |
1659 | dma_unmap_single(udc_controller->gadget.dev.parent, | 1655 | dma_unmap_single(udc->gadget.dev.parent, |
1660 | ep->rxbuf_d, size, | 1656 | ep->rxbuf_d, size, |
1661 | DMA_FROM_DEVICE); | 1657 | DMA_FROM_DEVICE); |
1662 | ep->rxbuf_d = DMA_ADDR_INVALID; | 1658 | ep->rxbuf_d = DMA_ADDR_INVALID; |
1663 | } else { | 1659 | } else { |
1664 | dma_sync_single_for_cpu( | 1660 | dma_sync_single_for_cpu( |
1665 | udc_controller->gadget.dev.parent, | 1661 | udc->gadget.dev.parent, |
1666 | ep->rxbuf_d, size, | 1662 | ep->rxbuf_d, size, |
1667 | DMA_FROM_DEVICE); | 1663 | DMA_FROM_DEVICE); |
1668 | } | 1664 | } |
@@ -1715,7 +1711,7 @@ static int __qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req) | |||
1715 | dev_dbg(udc->dev, "bad params\n"); | 1711 | dev_dbg(udc->dev, "bad params\n"); |
1716 | return -EINVAL; | 1712 | return -EINVAL; |
1717 | } | 1713 | } |
1718 | if (!_ep || (!ep->desc && ep_index(ep))) { | 1714 | if (!_ep || (!ep->ep.desc && ep_index(ep))) { |
1719 | dev_dbg(udc->dev, "bad ep\n"); | 1715 | dev_dbg(udc->dev, "bad ep\n"); |
1720 | return -EINVAL; | 1716 | return -EINVAL; |
1721 | } | 1717 | } |
@@ -1826,7 +1822,7 @@ static int qe_ep_set_halt(struct usb_ep *_ep, int value) | |||
1826 | struct qe_udc *udc; | 1822 | struct qe_udc *udc; |
1827 | 1823 | ||
1828 | ep = container_of(_ep, struct qe_ep, ep); | 1824 | ep = container_of(_ep, struct qe_ep, ep); |
1829 | if (!_ep || !ep->desc) { | 1825 | if (!_ep || !ep->ep.desc) { |
1830 | status = -EINVAL; | 1826 | status = -EINVAL; |
1831 | goto out; | 1827 | goto out; |
1832 | } | 1828 | } |
@@ -1880,9 +1876,10 @@ static struct usb_ep_ops qe_ep_ops = { | |||
1880 | /* Get the current frame number */ | 1876 | /* Get the current frame number */ |
1881 | static int qe_get_frame(struct usb_gadget *gadget) | 1877 | static int qe_get_frame(struct usb_gadget *gadget) |
1882 | { | 1878 | { |
1879 | struct qe_udc *udc = container_of(gadget, struct qe_udc, gadget); | ||
1883 | u16 tmp; | 1880 | u16 tmp; |
1884 | 1881 | ||
1885 | tmp = in_be16(&udc_controller->usb_param->frame_n); | 1882 | tmp = in_be16(&udc->usb_param->frame_n); |
1886 | if (tmp & 0x8000) | 1883 | if (tmp & 0x8000) |
1887 | tmp = tmp & 0x07ff; | 1884 | tmp = tmp & 0x07ff; |
1888 | else | 1885 | else |
@@ -1891,57 +1888,16 @@ static int qe_get_frame(struct usb_gadget *gadget) | |||
1891 | return (int)tmp; | 1888 | return (int)tmp; |
1892 | } | 1889 | } |
1893 | 1890 | ||
1894 | /* Tries to wake up the host connected to this gadget | 1891 | static int fsl_qe_start(struct usb_gadget *gadget, |
1895 | * | 1892 | struct usb_gadget_driver *driver); |
1896 | * Return : 0-success | 1893 | static int fsl_qe_stop(struct usb_gadget *gadget, |
1897 | * Negative-this feature not enabled by host or not supported by device hw | 1894 | struct usb_gadget_driver *driver); |
1898 | */ | ||
1899 | static int qe_wakeup(struct usb_gadget *gadget) | ||
1900 | { | ||
1901 | return -ENOTSUPP; | ||
1902 | } | ||
1903 | |||
1904 | /* Notify controller that VBUS is powered, Called by whatever | ||
1905 | detects VBUS sessions */ | ||
1906 | static int qe_vbus_session(struct usb_gadget *gadget, int is_active) | ||
1907 | { | ||
1908 | return -ENOTSUPP; | ||
1909 | } | ||
1910 | |||
1911 | /* constrain controller's VBUS power usage | ||
1912 | * This call is used by gadget drivers during SET_CONFIGURATION calls, | ||
1913 | * reporting how much power the device may consume. For example, this | ||
1914 | * could affect how quickly batteries are recharged. | ||
1915 | * | ||
1916 | * Returns zero on success, else negative errno. | ||
1917 | */ | ||
1918 | static int qe_vbus_draw(struct usb_gadget *gadget, unsigned mA) | ||
1919 | { | ||
1920 | return -ENOTSUPP; | ||
1921 | } | ||
1922 | |||
1923 | /* Change Data+ pullup status | ||
1924 | * this func is used by usb_gadget_connect/disconnect | ||
1925 | */ | ||
1926 | static int qe_pullup(struct usb_gadget *gadget, int is_on) | ||
1927 | { | ||
1928 | return -ENOTSUPP; | ||
1929 | } | ||
1930 | |||
1931 | static int fsl_qe_start(struct usb_gadget_driver *driver, | ||
1932 | int (*bind)(struct usb_gadget *)); | ||
1933 | static int fsl_qe_stop(struct usb_gadget_driver *driver); | ||
1934 | 1895 | ||
1935 | /* defined in usb_gadget.h */ | 1896 | /* defined in usb_gadget.h */ |
1936 | static struct usb_gadget_ops qe_gadget_ops = { | 1897 | static struct usb_gadget_ops qe_gadget_ops = { |
1937 | .get_frame = qe_get_frame, | 1898 | .get_frame = qe_get_frame, |
1938 | .wakeup = qe_wakeup, | 1899 | .udc_start = fsl_qe_start, |
1939 | /* .set_selfpowered = qe_set_selfpowered,*/ /* always selfpowered */ | 1900 | .udc_stop = fsl_qe_stop, |
1940 | .vbus_session = qe_vbus_session, | ||
1941 | .vbus_draw = qe_vbus_draw, | ||
1942 | .pullup = qe_pullup, | ||
1943 | .start = fsl_qe_start, | ||
1944 | .stop = fsl_qe_stop, | ||
1945 | }; | 1901 | }; |
1946 | 1902 | ||
1947 | /*------------------------------------------------------------------------- | 1903 | /*------------------------------------------------------------------------- |
@@ -2015,7 +1971,7 @@ static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value, | |||
2015 | u16 usep; | 1971 | u16 usep; |
2016 | 1972 | ||
2017 | /* stall if endpoint doesn't exist */ | 1973 | /* stall if endpoint doesn't exist */ |
2018 | if (!target_ep->desc) | 1974 | if (!target_ep->ep.desc) |
2019 | goto stall; | 1975 | goto stall; |
2020 | 1976 | ||
2021 | usep = in_be16(&udc->usb_regs->usb_usep[pipe]); | 1977 | usep = in_be16(&udc->usb_regs->usb_usep[pipe]); |
@@ -2190,7 +2146,7 @@ static int reset_irq(struct qe_udc *udc) | |||
2190 | if (udc->usb_state == USB_STATE_DEFAULT) | 2146 | if (udc->usb_state == USB_STATE_DEFAULT) |
2191 | return 0; | 2147 | return 0; |
2192 | 2148 | ||
2193 | qe_usb_disable(); | 2149 | qe_usb_disable(udc); |
2194 | out_8(&udc->usb_regs->usb_usadr, 0); | 2150 | out_8(&udc->usb_regs->usb_usadr, 0); |
2195 | 2151 | ||
2196 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { | 2152 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) { |
@@ -2202,7 +2158,7 @@ static int reset_irq(struct qe_udc *udc) | |||
2202 | udc->usb_state = USB_STATE_DEFAULT; | 2158 | udc->usb_state = USB_STATE_DEFAULT; |
2203 | udc->ep0_state = WAIT_FOR_SETUP; | 2159 | udc->ep0_state = WAIT_FOR_SETUP; |
2204 | udc->ep0_dir = USB_DIR_OUT; | 2160 | udc->ep0_dir = USB_DIR_OUT; |
2205 | qe_usb_enable(); | 2161 | qe_usb_enable(udc); |
2206 | return 0; | 2162 | return 0; |
2207 | } | 2163 | } |
2208 | 2164 | ||
@@ -2327,92 +2283,65 @@ static irqreturn_t qe_udc_irq(int irq, void *_udc) | |||
2327 | /*------------------------------------------------------------------------- | 2283 | /*------------------------------------------------------------------------- |
2328 | Gadget driver probe and unregister. | 2284 | Gadget driver probe and unregister. |
2329 | --------------------------------------------------------------------------*/ | 2285 | --------------------------------------------------------------------------*/ |
2330 | static int fsl_qe_start(struct usb_gadget_driver *driver, | 2286 | static int fsl_qe_start(struct usb_gadget *gadget, |
2331 | int (*bind)(struct usb_gadget *)) | 2287 | struct usb_gadget_driver *driver) |
2332 | { | 2288 | { |
2333 | int retval; | 2289 | struct qe_udc *udc; |
2334 | unsigned long flags = 0; | 2290 | unsigned long flags; |
2335 | |||
2336 | /* standard operations */ | ||
2337 | if (!udc_controller) | ||
2338 | return -ENODEV; | ||
2339 | |||
2340 | if (!driver || driver->max_speed < USB_SPEED_FULL | ||
2341 | || !bind || !driver->disconnect || !driver->setup) | ||
2342 | return -EINVAL; | ||
2343 | |||
2344 | if (udc_controller->driver) | ||
2345 | return -EBUSY; | ||
2346 | 2291 | ||
2292 | udc = container_of(gadget, struct qe_udc, gadget); | ||
2347 | /* lock is needed but whether should use this lock or another */ | 2293 | /* lock is needed but whether should use this lock or another */ |
2348 | spin_lock_irqsave(&udc_controller->lock, flags); | 2294 | spin_lock_irqsave(&udc->lock, flags); |
2349 | 2295 | ||
2350 | driver->driver.bus = NULL; | 2296 | driver->driver.bus = NULL; |
2351 | /* hook up the driver */ | 2297 | /* hook up the driver */ |
2352 | udc_controller->driver = driver; | 2298 | udc->driver = driver; |
2353 | udc_controller->gadget.dev.driver = &driver->driver; | 2299 | udc->gadget.dev.driver = &driver->driver; |
2354 | udc_controller->gadget.speed = driver->max_speed; | 2300 | udc->gadget.speed = driver->max_speed; |
2355 | spin_unlock_irqrestore(&udc_controller->lock, flags); | ||
2356 | |||
2357 | retval = bind(&udc_controller->gadget); | ||
2358 | if (retval) { | ||
2359 | dev_err(udc_controller->dev, "bind to %s --> %d", | ||
2360 | driver->driver.name, retval); | ||
2361 | udc_controller->gadget.dev.driver = NULL; | ||
2362 | udc_controller->driver = NULL; | ||
2363 | return retval; | ||
2364 | } | ||
2365 | 2301 | ||
2366 | /* Enable IRQ reg and Set usbcmd reg EN bit */ | 2302 | /* Enable IRQ reg and Set usbcmd reg EN bit */ |
2367 | qe_usb_enable(); | 2303 | qe_usb_enable(udc); |
2368 | 2304 | ||
2369 | out_be16(&udc_controller->usb_regs->usb_usber, 0xffff); | 2305 | out_be16(&udc->usb_regs->usb_usber, 0xffff); |
2370 | out_be16(&udc_controller->usb_regs->usb_usbmr, USB_E_DEFAULT_DEVICE); | 2306 | out_be16(&udc->usb_regs->usb_usbmr, USB_E_DEFAULT_DEVICE); |
2371 | udc_controller->usb_state = USB_STATE_ATTACHED; | 2307 | udc->usb_state = USB_STATE_ATTACHED; |
2372 | udc_controller->ep0_state = WAIT_FOR_SETUP; | 2308 | udc->ep0_state = WAIT_FOR_SETUP; |
2373 | udc_controller->ep0_dir = USB_DIR_OUT; | 2309 | udc->ep0_dir = USB_DIR_OUT; |
2374 | dev_info(udc_controller->dev, "%s bind to driver %s \n", | 2310 | spin_unlock_irqrestore(&udc->lock, flags); |
2375 | udc_controller->gadget.name, driver->driver.name); | 2311 | |
2312 | dev_info(udc->dev, "%s bind to driver %s\n", udc->gadget.name, | ||
2313 | driver->driver.name); | ||
2376 | return 0; | 2314 | return 0; |
2377 | } | 2315 | } |
2378 | 2316 | ||
2379 | static int fsl_qe_stop(struct usb_gadget_driver *driver) | 2317 | static int fsl_qe_stop(struct usb_gadget *gadget, |
2318 | struct usb_gadget_driver *driver) | ||
2380 | { | 2319 | { |
2320 | struct qe_udc *udc; | ||
2381 | struct qe_ep *loop_ep; | 2321 | struct qe_ep *loop_ep; |
2382 | unsigned long flags; | 2322 | unsigned long flags; |
2383 | 2323 | ||
2384 | if (!udc_controller) | 2324 | udc = container_of(gadget, struct qe_udc, gadget); |
2385 | return -ENODEV; | ||
2386 | |||
2387 | if (!driver || driver != udc_controller->driver) | ||
2388 | return -EINVAL; | ||
2389 | |||
2390 | /* stop usb controller, disable intr */ | 2325 | /* stop usb controller, disable intr */ |
2391 | qe_usb_disable(); | 2326 | qe_usb_disable(udc); |
2392 | 2327 | ||
2393 | /* in fact, no needed */ | 2328 | /* in fact, no needed */ |
2394 | udc_controller->usb_state = USB_STATE_ATTACHED; | 2329 | udc->usb_state = USB_STATE_ATTACHED; |
2395 | udc_controller->ep0_state = WAIT_FOR_SETUP; | 2330 | udc->ep0_state = WAIT_FOR_SETUP; |
2396 | udc_controller->ep0_dir = 0; | 2331 | udc->ep0_dir = 0; |
2397 | 2332 | ||
2398 | /* stand operation */ | 2333 | /* stand operation */ |
2399 | spin_lock_irqsave(&udc_controller->lock, flags); | 2334 | spin_lock_irqsave(&udc->lock, flags); |
2400 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | 2335 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
2401 | nuke(&udc_controller->eps[0], -ESHUTDOWN); | 2336 | nuke(&udc->eps[0], -ESHUTDOWN); |
2402 | list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list, | 2337 | list_for_each_entry(loop_ep, &udc->gadget.ep_list, ep.ep_list) |
2403 | ep.ep_list) | ||
2404 | nuke(loop_ep, -ESHUTDOWN); | 2338 | nuke(loop_ep, -ESHUTDOWN); |
2405 | spin_unlock_irqrestore(&udc_controller->lock, flags); | 2339 | spin_unlock_irqrestore(&udc->lock, flags); |
2406 | |||
2407 | /* report disconnect; the controller is already quiesced */ | ||
2408 | driver->disconnect(&udc_controller->gadget); | ||
2409 | 2340 | ||
2410 | /* unbind gadget and unhook driver. */ | 2341 | udc->gadget.dev.driver = NULL; |
2411 | driver->unbind(&udc_controller->gadget); | 2342 | udc->driver = NULL; |
2412 | udc_controller->gadget.dev.driver = NULL; | ||
2413 | udc_controller->driver = NULL; | ||
2414 | 2343 | ||
2415 | dev_info(udc_controller->dev, "unregistered gadget driver '%s'\r\n", | 2344 | dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", |
2416 | driver->driver.name); | 2345 | driver->driver.name); |
2417 | return 0; | 2346 | return 0; |
2418 | } | 2347 | } |
@@ -2502,7 +2431,7 @@ static int __devinit qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) | |||
2502 | ep->ep.ops = &qe_ep_ops; | 2431 | ep->ep.ops = &qe_ep_ops; |
2503 | ep->stopped = 1; | 2432 | ep->stopped = 1; |
2504 | ep->ep.maxpacket = (unsigned short) ~0; | 2433 | ep->ep.maxpacket = (unsigned short) ~0; |
2505 | ep->desc = NULL; | 2434 | ep->ep.desc = NULL; |
2506 | ep->dir = 0xff; | 2435 | ep->dir = 0xff; |
2507 | ep->epnum = (u8)pipe_num; | 2436 | ep->epnum = (u8)pipe_num; |
2508 | ep->sent = 0; | 2437 | ep->sent = 0; |
@@ -2531,21 +2460,22 @@ static int __devinit qe_ep_config(struct qe_udc *udc, unsigned char pipe_num) | |||
2531 | *----------------------------------------------------------------------*/ | 2460 | *----------------------------------------------------------------------*/ |
2532 | static void qe_udc_release(struct device *dev) | 2461 | static void qe_udc_release(struct device *dev) |
2533 | { | 2462 | { |
2534 | int i = 0; | 2463 | struct qe_udc *udc = container_of(dev, struct qe_udc, gadget.dev); |
2464 | int i; | ||
2535 | 2465 | ||
2536 | complete(udc_controller->done); | 2466 | complete(udc->done); |
2537 | cpm_muram_free(cpm_muram_offset(udc_controller->ep_param[0])); | 2467 | cpm_muram_free(cpm_muram_offset(udc->ep_param[0])); |
2538 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) | 2468 | for (i = 0; i < USB_MAX_ENDPOINTS; i++) |
2539 | udc_controller->ep_param[i] = NULL; | 2469 | udc->ep_param[i] = NULL; |
2540 | 2470 | ||
2541 | kfree(udc_controller); | 2471 | kfree(udc); |
2542 | udc_controller = NULL; | ||
2543 | } | 2472 | } |
2544 | 2473 | ||
2545 | /* Driver probe functions */ | 2474 | /* Driver probe functions */ |
2546 | static const struct of_device_id qe_udc_match[]; | 2475 | static const struct of_device_id qe_udc_match[]; |
2547 | static int __devinit qe_udc_probe(struct platform_device *ofdev) | 2476 | static int __devinit qe_udc_probe(struct platform_device *ofdev) |
2548 | { | 2477 | { |
2478 | struct qe_udc *udc; | ||
2549 | const struct of_device_id *match; | 2479 | const struct of_device_id *match; |
2550 | struct device_node *np = ofdev->dev.of_node; | 2480 | struct device_node *np = ofdev->dev.of_node; |
2551 | struct qe_ep *ep; | 2481 | struct qe_ep *ep; |
@@ -2562,44 +2492,44 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev) | |||
2562 | return -ENODEV; | 2492 | return -ENODEV; |
2563 | 2493 | ||
2564 | /* Initialize the udc structure including QH member and other member */ | 2494 | /* Initialize the udc structure including QH member and other member */ |
2565 | udc_controller = qe_udc_config(ofdev); | 2495 | udc = qe_udc_config(ofdev); |
2566 | if (!udc_controller) { | 2496 | if (!udc) { |
2567 | dev_err(&ofdev->dev, "failed to initialize\n"); | 2497 | dev_err(&ofdev->dev, "failed to initialize\n"); |
2568 | return -ENOMEM; | 2498 | return -ENOMEM; |
2569 | } | 2499 | } |
2570 | 2500 | ||
2571 | udc_controller->soc_type = (unsigned long)match->data; | 2501 | udc->soc_type = (unsigned long)match->data; |
2572 | udc_controller->usb_regs = of_iomap(np, 0); | 2502 | udc->usb_regs = of_iomap(np, 0); |
2573 | if (!udc_controller->usb_regs) { | 2503 | if (!udc->usb_regs) { |
2574 | ret = -ENOMEM; | 2504 | ret = -ENOMEM; |
2575 | goto err1; | 2505 | goto err1; |
2576 | } | 2506 | } |
2577 | 2507 | ||
2578 | /* initialize usb hw reg except for regs for EP, | 2508 | /* initialize usb hw reg except for regs for EP, |
2579 | * leave usbintr reg untouched*/ | 2509 | * leave usbintr reg untouched*/ |
2580 | qe_udc_reg_init(udc_controller); | 2510 | qe_udc_reg_init(udc); |
2581 | 2511 | ||
2582 | /* here comes the stand operations for probe | 2512 | /* here comes the stand operations for probe |
2583 | * set the qe_udc->gadget.xxx */ | 2513 | * set the qe_udc->gadget.xxx */ |
2584 | udc_controller->gadget.ops = &qe_gadget_ops; | 2514 | udc->gadget.ops = &qe_gadget_ops; |
2585 | 2515 | ||
2586 | /* gadget.ep0 is a pointer */ | 2516 | /* gadget.ep0 is a pointer */ |
2587 | udc_controller->gadget.ep0 = &udc_controller->eps[0].ep; | 2517 | udc->gadget.ep0 = &udc->eps[0].ep; |
2588 | 2518 | ||
2589 | INIT_LIST_HEAD(&udc_controller->gadget.ep_list); | 2519 | INIT_LIST_HEAD(&udc->gadget.ep_list); |
2590 | 2520 | ||
2591 | /* modify in register gadget process */ | 2521 | /* modify in register gadget process */ |
2592 | udc_controller->gadget.speed = USB_SPEED_UNKNOWN; | 2522 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
2593 | 2523 | ||
2594 | /* name: Identifies the controller hardware type. */ | 2524 | /* name: Identifies the controller hardware type. */ |
2595 | udc_controller->gadget.name = driver_name; | 2525 | udc->gadget.name = driver_name; |
2596 | 2526 | ||
2597 | device_initialize(&udc_controller->gadget.dev); | 2527 | device_initialize(&udc->gadget.dev); |
2598 | 2528 | ||
2599 | dev_set_name(&udc_controller->gadget.dev, "gadget"); | 2529 | dev_set_name(&udc->gadget.dev, "gadget"); |
2600 | 2530 | ||
2601 | udc_controller->gadget.dev.release = qe_udc_release; | 2531 | udc->gadget.dev.release = qe_udc_release; |
2602 | udc_controller->gadget.dev.parent = &ofdev->dev; | 2532 | udc->gadget.dev.parent = &ofdev->dev; |
2603 | 2533 | ||
2604 | /* initialize qe_ep struct */ | 2534 | /* initialize qe_ep struct */ |
2605 | for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { | 2535 | for (i = 0; i < USB_MAX_ENDPOINTS ; i++) { |
@@ -2608,104 +2538,104 @@ static int __devinit qe_udc_probe(struct platform_device *ofdev) | |||
2608 | 2538 | ||
2609 | /* setup the qe_ep struct and link ep.ep.list | 2539 | /* setup the qe_ep struct and link ep.ep.list |
2610 | * into gadget.ep_list */ | 2540 | * into gadget.ep_list */ |
2611 | qe_ep_config(udc_controller, (unsigned char)i); | 2541 | qe_ep_config(udc, (unsigned char)i); |
2612 | } | 2542 | } |
2613 | 2543 | ||
2614 | /* ep0 initialization in here */ | 2544 | /* ep0 initialization in here */ |
2615 | ret = qe_ep_init(udc_controller, 0, &qe_ep0_desc); | 2545 | ret = qe_ep_init(udc, 0, &qe_ep0_desc); |
2616 | if (ret) | 2546 | if (ret) |
2617 | goto err2; | 2547 | goto err2; |
2618 | 2548 | ||
2619 | /* create a buf for ZLP send, need to remain zeroed */ | 2549 | /* create a buf for ZLP send, need to remain zeroed */ |
2620 | udc_controller->nullbuf = kzalloc(256, GFP_KERNEL); | 2550 | udc->nullbuf = kzalloc(256, GFP_KERNEL); |
2621 | if (udc_controller->nullbuf == NULL) { | 2551 | if (udc->nullbuf == NULL) { |
2622 | dev_err(udc_controller->dev, "cannot alloc nullbuf\n"); | 2552 | dev_err(udc->dev, "cannot alloc nullbuf\n"); |
2623 | ret = -ENOMEM; | 2553 | ret = -ENOMEM; |
2624 | goto err3; | 2554 | goto err3; |
2625 | } | 2555 | } |
2626 | 2556 | ||
2627 | /* buffer for data of get_status request */ | 2557 | /* buffer for data of get_status request */ |
2628 | udc_controller->statusbuf = kzalloc(2, GFP_KERNEL); | 2558 | udc->statusbuf = kzalloc(2, GFP_KERNEL); |
2629 | if (udc_controller->statusbuf == NULL) { | 2559 | if (udc->statusbuf == NULL) { |
2630 | ret = -ENOMEM; | 2560 | ret = -ENOMEM; |
2631 | goto err4; | 2561 | goto err4; |
2632 | } | 2562 | } |
2633 | 2563 | ||
2634 | udc_controller->nullp = virt_to_phys((void *)udc_controller->nullbuf); | 2564 | udc->nullp = virt_to_phys((void *)udc->nullbuf); |
2635 | if (udc_controller->nullp == DMA_ADDR_INVALID) { | 2565 | if (udc->nullp == DMA_ADDR_INVALID) { |
2636 | udc_controller->nullp = dma_map_single( | 2566 | udc->nullp = dma_map_single( |
2637 | udc_controller->gadget.dev.parent, | 2567 | udc->gadget.dev.parent, |
2638 | udc_controller->nullbuf, | 2568 | udc->nullbuf, |
2639 | 256, | 2569 | 256, |
2640 | DMA_TO_DEVICE); | 2570 | DMA_TO_DEVICE); |
2641 | udc_controller->nullmap = 1; | 2571 | udc->nullmap = 1; |
2642 | } else { | 2572 | } else { |
2643 | dma_sync_single_for_device(udc_controller->gadget.dev.parent, | 2573 | dma_sync_single_for_device(udc->gadget.dev.parent, |
2644 | udc_controller->nullp, 256, | 2574 | udc->nullp, 256, |
2645 | DMA_TO_DEVICE); | 2575 | DMA_TO_DEVICE); |
2646 | } | 2576 | } |
2647 | 2577 | ||
2648 | tasklet_init(&udc_controller->rx_tasklet, ep_rx_tasklet, | 2578 | tasklet_init(&udc->rx_tasklet, ep_rx_tasklet, |
2649 | (unsigned long)udc_controller); | 2579 | (unsigned long)udc); |
2650 | /* request irq and disable DR */ | 2580 | /* request irq and disable DR */ |
2651 | udc_controller->usb_irq = irq_of_parse_and_map(np, 0); | 2581 | udc->usb_irq = irq_of_parse_and_map(np, 0); |
2652 | if (!udc_controller->usb_irq) { | 2582 | if (!udc->usb_irq) { |
2653 | ret = -EINVAL; | 2583 | ret = -EINVAL; |
2654 | goto err_noirq; | 2584 | goto err_noirq; |
2655 | } | 2585 | } |
2656 | 2586 | ||
2657 | ret = request_irq(udc_controller->usb_irq, qe_udc_irq, 0, | 2587 | ret = request_irq(udc->usb_irq, qe_udc_irq, 0, |
2658 | driver_name, udc_controller); | 2588 | driver_name, udc); |
2659 | if (ret) { | 2589 | if (ret) { |
2660 | dev_err(udc_controller->dev, "cannot request irq %d err %d \n", | 2590 | dev_err(udc->dev, "cannot request irq %d err %d\n", |
2661 | udc_controller->usb_irq, ret); | 2591 | udc->usb_irq, ret); |
2662 | goto err5; | 2592 | goto err5; |
2663 | } | 2593 | } |
2664 | 2594 | ||
2665 | ret = device_add(&udc_controller->gadget.dev); | 2595 | ret = device_add(&udc->gadget.dev); |
2666 | if (ret) | 2596 | if (ret) |
2667 | goto err6; | 2597 | goto err6; |
2668 | 2598 | ||
2669 | ret = usb_add_gadget_udc(&ofdev->dev, &udc_controller->gadget); | 2599 | ret = usb_add_gadget_udc(&ofdev->dev, &udc->gadget); |
2670 | if (ret) | 2600 | if (ret) |
2671 | goto err7; | 2601 | goto err7; |
2672 | 2602 | ||
2673 | dev_info(udc_controller->dev, | 2603 | dev_set_drvdata(&ofdev->dev, udc); |
2604 | dev_info(udc->dev, | ||
2674 | "%s USB controller initialized as device\n", | 2605 | "%s USB controller initialized as device\n", |
2675 | (udc_controller->soc_type == PORT_QE) ? "QE" : "CPM"); | 2606 | (udc->soc_type == PORT_QE) ? "QE" : "CPM"); |
2676 | return 0; | 2607 | return 0; |
2677 | 2608 | ||
2678 | err7: | 2609 | err7: |
2679 | device_unregister(&udc_controller->gadget.dev); | 2610 | device_unregister(&udc->gadget.dev); |
2680 | err6: | 2611 | err6: |
2681 | free_irq(udc_controller->usb_irq, udc_controller); | 2612 | free_irq(udc->usb_irq, udc); |
2682 | err5: | 2613 | err5: |
2683 | irq_dispose_mapping(udc_controller->usb_irq); | 2614 | irq_dispose_mapping(udc->usb_irq); |
2684 | err_noirq: | 2615 | err_noirq: |
2685 | if (udc_controller->nullmap) { | 2616 | if (udc->nullmap) { |
2686 | dma_unmap_single(udc_controller->gadget.dev.parent, | 2617 | dma_unmap_single(udc->gadget.dev.parent, |
2687 | udc_controller->nullp, 256, | 2618 | udc->nullp, 256, |
2688 | DMA_TO_DEVICE); | 2619 | DMA_TO_DEVICE); |
2689 | udc_controller->nullp = DMA_ADDR_INVALID; | 2620 | udc->nullp = DMA_ADDR_INVALID; |
2690 | } else { | 2621 | } else { |
2691 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | 2622 | dma_sync_single_for_cpu(udc->gadget.dev.parent, |
2692 | udc_controller->nullp, 256, | 2623 | udc->nullp, 256, |
2693 | DMA_TO_DEVICE); | 2624 | DMA_TO_DEVICE); |
2694 | } | 2625 | } |
2695 | kfree(udc_controller->statusbuf); | 2626 | kfree(udc->statusbuf); |
2696 | err4: | 2627 | err4: |
2697 | kfree(udc_controller->nullbuf); | 2628 | kfree(udc->nullbuf); |
2698 | err3: | 2629 | err3: |
2699 | ep = &udc_controller->eps[0]; | 2630 | ep = &udc->eps[0]; |
2700 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | 2631 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); |
2701 | kfree(ep->rxframe); | 2632 | kfree(ep->rxframe); |
2702 | kfree(ep->rxbuffer); | 2633 | kfree(ep->rxbuffer); |
2703 | kfree(ep->txframe); | 2634 | kfree(ep->txframe); |
2704 | err2: | 2635 | err2: |
2705 | iounmap(udc_controller->usb_regs); | 2636 | iounmap(udc->usb_regs); |
2706 | err1: | 2637 | err1: |
2707 | kfree(udc_controller); | 2638 | kfree(udc); |
2708 | udc_controller = NULL; | ||
2709 | return ret; | 2639 | return ret; |
2710 | } | 2640 | } |
2711 | 2641 | ||
@@ -2723,44 +2653,41 @@ static int qe_udc_resume(struct platform_device *dev) | |||
2723 | 2653 | ||
2724 | static int __devexit qe_udc_remove(struct platform_device *ofdev) | 2654 | static int __devexit qe_udc_remove(struct platform_device *ofdev) |
2725 | { | 2655 | { |
2656 | struct qe_udc *udc = dev_get_drvdata(&ofdev->dev); | ||
2726 | struct qe_ep *ep; | 2657 | struct qe_ep *ep; |
2727 | unsigned int size; | 2658 | unsigned int size; |
2728 | |||
2729 | DECLARE_COMPLETION(done); | 2659 | DECLARE_COMPLETION(done); |
2730 | 2660 | ||
2731 | if (!udc_controller) | 2661 | usb_del_gadget_udc(&udc->gadget); |
2732 | return -ENODEV; | ||
2733 | |||
2734 | usb_del_gadget_udc(&udc_controller->gadget); | ||
2735 | 2662 | ||
2736 | udc_controller->done = &done; | 2663 | udc->done = &done; |
2737 | tasklet_disable(&udc_controller->rx_tasklet); | 2664 | tasklet_disable(&udc->rx_tasklet); |
2738 | 2665 | ||
2739 | if (udc_controller->nullmap) { | 2666 | if (udc->nullmap) { |
2740 | dma_unmap_single(udc_controller->gadget.dev.parent, | 2667 | dma_unmap_single(udc->gadget.dev.parent, |
2741 | udc_controller->nullp, 256, | 2668 | udc->nullp, 256, |
2742 | DMA_TO_DEVICE); | 2669 | DMA_TO_DEVICE); |
2743 | udc_controller->nullp = DMA_ADDR_INVALID; | 2670 | udc->nullp = DMA_ADDR_INVALID; |
2744 | } else { | 2671 | } else { |
2745 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | 2672 | dma_sync_single_for_cpu(udc->gadget.dev.parent, |
2746 | udc_controller->nullp, 256, | 2673 | udc->nullp, 256, |
2747 | DMA_TO_DEVICE); | 2674 | DMA_TO_DEVICE); |
2748 | } | 2675 | } |
2749 | kfree(udc_controller->statusbuf); | 2676 | kfree(udc->statusbuf); |
2750 | kfree(udc_controller->nullbuf); | 2677 | kfree(udc->nullbuf); |
2751 | 2678 | ||
2752 | ep = &udc_controller->eps[0]; | 2679 | ep = &udc->eps[0]; |
2753 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); | 2680 | cpm_muram_free(cpm_muram_offset(ep->rxbase)); |
2754 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (USB_BDRING_LEN + 1); | 2681 | size = (ep->ep.maxpacket + USB_CRC_SIZE + 2) * (USB_BDRING_LEN + 1); |
2755 | 2682 | ||
2756 | kfree(ep->rxframe); | 2683 | kfree(ep->rxframe); |
2757 | if (ep->rxbufmap) { | 2684 | if (ep->rxbufmap) { |
2758 | dma_unmap_single(udc_controller->gadget.dev.parent, | 2685 | dma_unmap_single(udc->gadget.dev.parent, |
2759 | ep->rxbuf_d, size, | 2686 | ep->rxbuf_d, size, |
2760 | DMA_FROM_DEVICE); | 2687 | DMA_FROM_DEVICE); |
2761 | ep->rxbuf_d = DMA_ADDR_INVALID; | 2688 | ep->rxbuf_d = DMA_ADDR_INVALID; |
2762 | } else { | 2689 | } else { |
2763 | dma_sync_single_for_cpu(udc_controller->gadget.dev.parent, | 2690 | dma_sync_single_for_cpu(udc->gadget.dev.parent, |
2764 | ep->rxbuf_d, size, | 2691 | ep->rxbuf_d, size, |
2765 | DMA_FROM_DEVICE); | 2692 | DMA_FROM_DEVICE); |
2766 | } | 2693 | } |
@@ -2768,14 +2695,14 @@ static int __devexit qe_udc_remove(struct platform_device *ofdev) | |||
2768 | kfree(ep->rxbuffer); | 2695 | kfree(ep->rxbuffer); |
2769 | kfree(ep->txframe); | 2696 | kfree(ep->txframe); |
2770 | 2697 | ||
2771 | free_irq(udc_controller->usb_irq, udc_controller); | 2698 | free_irq(udc->usb_irq, udc); |
2772 | irq_dispose_mapping(udc_controller->usb_irq); | 2699 | irq_dispose_mapping(udc->usb_irq); |
2773 | 2700 | ||
2774 | tasklet_kill(&udc_controller->rx_tasklet); | 2701 | tasklet_kill(&udc->rx_tasklet); |
2775 | 2702 | ||
2776 | iounmap(udc_controller->usb_regs); | 2703 | iounmap(udc->usb_regs); |
2777 | 2704 | ||
2778 | device_unregister(&udc_controller->gadget.dev); | 2705 | device_unregister(&udc->gadget.dev); |
2779 | /* wait for release() of gadget.dev to free udc */ | 2706 | /* wait for release() of gadget.dev to free udc */ |
2780 | wait_for_completion(&done); | 2707 | wait_for_completion(&done); |
2781 | 2708 | ||
diff --git a/drivers/usb/gadget/fsl_qe_udc.h b/drivers/usb/gadget/fsl_qe_udc.h index 1da5fb03d218..4c07ca9cebf3 100644 --- a/drivers/usb/gadget/fsl_qe_udc.h +++ b/drivers/usb/gadget/fsl_qe_udc.h | |||
@@ -266,7 +266,6 @@ struct qe_ep { | |||
266 | struct usb_ep ep; | 266 | struct usb_ep ep; |
267 | struct list_head queue; | 267 | struct list_head queue; |
268 | struct qe_udc *udc; | 268 | struct qe_udc *udc; |
269 | const struct usb_endpoint_descriptor *desc; | ||
270 | struct usb_gadget *gadget; | 269 | struct usb_gadget *gadget; |
271 | 270 | ||
272 | u8 state; | 271 | u8 state; |
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 55abfb6bd612..28316858208b 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004-2007,2011 Freescale Semiconductor, Inc. | 2 | * Copyright (C) 2004-2007,2011-2012 Freescale Semiconductor, Inc. |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * Author: Li Yang <leoli@freescale.com> | 5 | * Author: Li Yang <leoli@freescale.com> |
@@ -58,9 +58,8 @@ static const char driver_name[] = "fsl-usb2-udc"; | |||
58 | static const char driver_desc[] = DRIVER_DESC; | 58 | static const char driver_desc[] = DRIVER_DESC; |
59 | 59 | ||
60 | static struct usb_dr_device *dr_regs; | 60 | static struct usb_dr_device *dr_regs; |
61 | #ifndef CONFIG_ARCH_MXC | 61 | |
62 | static struct usb_sys_interface *usb_sys_regs; | 62 | static struct usb_sys_interface *usb_sys_regs; |
63 | #endif | ||
64 | 63 | ||
65 | /* it is initialized in probe() */ | 64 | /* it is initialized in probe() */ |
66 | static struct fsl_udc *udc_controller = NULL; | 65 | static struct fsl_udc *udc_controller = NULL; |
@@ -244,10 +243,9 @@ static int dr_controller_setup(struct fsl_udc *udc) | |||
244 | { | 243 | { |
245 | unsigned int tmp, portctrl, ep_num; | 244 | unsigned int tmp, portctrl, ep_num; |
246 | unsigned int max_no_of_ep; | 245 | unsigned int max_no_of_ep; |
247 | #ifndef CONFIG_ARCH_MXC | ||
248 | unsigned int ctrl; | 246 | unsigned int ctrl; |
249 | #endif | ||
250 | unsigned long timeout; | 247 | unsigned long timeout; |
248 | |||
251 | #define FSL_UDC_RESET_TIMEOUT 1000 | 249 | #define FSL_UDC_RESET_TIMEOUT 1000 |
252 | 250 | ||
253 | /* Config PHY interface */ | 251 | /* Config PHY interface */ |
@@ -255,12 +253,32 @@ static int dr_controller_setup(struct fsl_udc *udc) | |||
255 | portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH); | 253 | portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH); |
256 | switch (udc->phy_mode) { | 254 | switch (udc->phy_mode) { |
257 | case FSL_USB2_PHY_ULPI: | 255 | case FSL_USB2_PHY_ULPI: |
256 | if (udc->pdata->have_sysif_regs) { | ||
257 | if (udc->pdata->controller_ver) { | ||
258 | /* controller version 1.6 or above */ | ||
259 | ctrl = __raw_readl(&usb_sys_regs->control); | ||
260 | ctrl &= ~USB_CTRL_UTMI_PHY_EN; | ||
261 | ctrl |= USB_CTRL_USB_EN; | ||
262 | __raw_writel(ctrl, &usb_sys_regs->control); | ||
263 | } | ||
264 | } | ||
258 | portctrl |= PORTSCX_PTS_ULPI; | 265 | portctrl |= PORTSCX_PTS_ULPI; |
259 | break; | 266 | break; |
260 | case FSL_USB2_PHY_UTMI_WIDE: | 267 | case FSL_USB2_PHY_UTMI_WIDE: |
261 | portctrl |= PORTSCX_PTW_16BIT; | 268 | portctrl |= PORTSCX_PTW_16BIT; |
262 | /* fall through */ | 269 | /* fall through */ |
263 | case FSL_USB2_PHY_UTMI: | 270 | case FSL_USB2_PHY_UTMI: |
271 | if (udc->pdata->have_sysif_regs) { | ||
272 | if (udc->pdata->controller_ver) { | ||
273 | /* controller version 1.6 or above */ | ||
274 | ctrl = __raw_readl(&usb_sys_regs->control); | ||
275 | ctrl |= (USB_CTRL_UTMI_PHY_EN | | ||
276 | USB_CTRL_USB_EN); | ||
277 | __raw_writel(ctrl, &usb_sys_regs->control); | ||
278 | mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI | ||
279 | PHY CLK to become stable - 10ms*/ | ||
280 | } | ||
281 | } | ||
264 | portctrl |= PORTSCX_PTS_UTMI; | 282 | portctrl |= PORTSCX_PTS_UTMI; |
265 | break; | 283 | break; |
266 | case FSL_USB2_PHY_SERIAL: | 284 | case FSL_USB2_PHY_SERIAL: |
@@ -549,7 +567,7 @@ static int fsl_ep_enable(struct usb_ep *_ep, | |||
549 | ep = container_of(_ep, struct fsl_ep, ep); | 567 | ep = container_of(_ep, struct fsl_ep, ep); |
550 | 568 | ||
551 | /* catch various bogus parameters */ | 569 | /* catch various bogus parameters */ |
552 | if (!_ep || !desc || ep->desc | 570 | if (!_ep || !desc || ep->ep.desc |
553 | || (desc->bDescriptorType != USB_DT_ENDPOINT)) | 571 | || (desc->bDescriptorType != USB_DT_ENDPOINT)) |
554 | return -EINVAL; | 572 | return -EINVAL; |
555 | 573 | ||
@@ -590,7 +608,7 @@ static int fsl_ep_enable(struct usb_ep *_ep, | |||
590 | 608 | ||
591 | spin_lock_irqsave(&udc->lock, flags); | 609 | spin_lock_irqsave(&udc->lock, flags); |
592 | ep->ep.maxpacket = max; | 610 | ep->ep.maxpacket = max; |
593 | ep->desc = desc; | 611 | ep->ep.desc = desc; |
594 | ep->stopped = 0; | 612 | ep->stopped = 0; |
595 | 613 | ||
596 | /* Controller related setup */ | 614 | /* Controller related setup */ |
@@ -614,7 +632,7 @@ static int fsl_ep_enable(struct usb_ep *_ep, | |||
614 | retval = 0; | 632 | retval = 0; |
615 | 633 | ||
616 | VDBG("enabled %s (ep%d%s) maxpacket %d",ep->ep.name, | 634 | VDBG("enabled %s (ep%d%s) maxpacket %d",ep->ep.name, |
617 | ep->desc->bEndpointAddress & 0x0f, | 635 | ep->ep.desc->bEndpointAddress & 0x0f, |
618 | (desc->bEndpointAddress & USB_DIR_IN) | 636 | (desc->bEndpointAddress & USB_DIR_IN) |
619 | ? "in" : "out", max); | 637 | ? "in" : "out", max); |
620 | en_done: | 638 | en_done: |
@@ -634,7 +652,7 @@ static int fsl_ep_disable(struct usb_ep *_ep) | |||
634 | int ep_num; | 652 | int ep_num; |
635 | 653 | ||
636 | ep = container_of(_ep, struct fsl_ep, ep); | 654 | ep = container_of(_ep, struct fsl_ep, ep); |
637 | if (!_ep || !ep->desc) { | 655 | if (!_ep || !ep->ep.desc) { |
638 | VDBG("%s not enabled", _ep ? ep->ep.name : NULL); | 656 | VDBG("%s not enabled", _ep ? ep->ep.name : NULL); |
639 | return -EINVAL; | 657 | return -EINVAL; |
640 | } | 658 | } |
@@ -657,7 +675,6 @@ static int fsl_ep_disable(struct usb_ep *_ep) | |||
657 | /* nuke all pending requests (does flush) */ | 675 | /* nuke all pending requests (does flush) */ |
658 | nuke(ep, -ESHUTDOWN); | 676 | nuke(ep, -ESHUTDOWN); |
659 | 677 | ||
660 | ep->desc = NULL; | ||
661 | ep->ep.desc = NULL; | 678 | ep->ep.desc = NULL; |
662 | ep->stopped = 1; | 679 | ep->stopped = 1; |
663 | spin_unlock_irqrestore(&udc->lock, flags); | 680 | spin_unlock_irqrestore(&udc->lock, flags); |
@@ -736,6 +753,8 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req) | |||
736 | lastreq = list_entry(ep->queue.prev, struct fsl_req, queue); | 753 | lastreq = list_entry(ep->queue.prev, struct fsl_req, queue); |
737 | lastreq->tail->next_td_ptr = | 754 | lastreq->tail->next_td_ptr = |
738 | cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK); | 755 | cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK); |
756 | /* Ensure dTD's next dtd pointer to be updated */ | ||
757 | wmb(); | ||
739 | /* Read prime bit, if 1 goto done */ | 758 | /* Read prime bit, if 1 goto done */ |
740 | if (fsl_readl(&dr_regs->endpointprime) & bitmask) | 759 | if (fsl_readl(&dr_regs->endpointprime) & bitmask) |
741 | return; | 760 | return; |
@@ -874,11 +893,11 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
874 | VDBG("%s, bad params", __func__); | 893 | VDBG("%s, bad params", __func__); |
875 | return -EINVAL; | 894 | return -EINVAL; |
876 | } | 895 | } |
877 | if (unlikely(!_ep || !ep->desc)) { | 896 | if (unlikely(!_ep || !ep->ep.desc)) { |
878 | VDBG("%s, bad ep", __func__); | 897 | VDBG("%s, bad ep", __func__); |
879 | return -EINVAL; | 898 | return -EINVAL; |
880 | } | 899 | } |
881 | if (usb_endpoint_xfer_isoc(ep->desc)) { | 900 | if (usb_endpoint_xfer_isoc(ep->ep.desc)) { |
882 | if (req->req.length > ep->ep.maxpacket) | 901 | if (req->req.length > ep->ep.maxpacket) |
883 | return -EMSGSIZE; | 902 | return -EMSGSIZE; |
884 | } | 903 | } |
@@ -1017,12 +1036,12 @@ static int fsl_ep_set_halt(struct usb_ep *_ep, int value) | |||
1017 | 1036 | ||
1018 | ep = container_of(_ep, struct fsl_ep, ep); | 1037 | ep = container_of(_ep, struct fsl_ep, ep); |
1019 | udc = ep->udc; | 1038 | udc = ep->udc; |
1020 | if (!_ep || !ep->desc) { | 1039 | if (!_ep || !ep->ep.desc) { |
1021 | status = -EINVAL; | 1040 | status = -EINVAL; |
1022 | goto out; | 1041 | goto out; |
1023 | } | 1042 | } |
1024 | 1043 | ||
1025 | if (usb_endpoint_xfer_isoc(ep->desc)) { | 1044 | if (usb_endpoint_xfer_isoc(ep->ep.desc)) { |
1026 | status = -EOPNOTSUPP; | 1045 | status = -EOPNOTSUPP; |
1027 | goto out; | 1046 | goto out; |
1028 | } | 1047 | } |
@@ -1061,7 +1080,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep) | |||
1061 | struct ep_queue_head *qh; | 1080 | struct ep_queue_head *qh; |
1062 | 1081 | ||
1063 | ep = container_of(_ep, struct fsl_ep, ep); | 1082 | ep = container_of(_ep, struct fsl_ep, ep); |
1064 | if (!_ep || (!ep->desc && ep_index(ep) != 0)) | 1083 | if (!_ep || (!ep->ep.desc && ep_index(ep) != 0)) |
1065 | return -ENODEV; | 1084 | return -ENODEV; |
1066 | 1085 | ||
1067 | udc = (struct fsl_udc *)ep->udc; | 1086 | udc = (struct fsl_udc *)ep->udc; |
@@ -1094,7 +1113,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep) | |||
1094 | return; | 1113 | return; |
1095 | } else { | 1114 | } else { |
1096 | ep = container_of(_ep, struct fsl_ep, ep); | 1115 | ep = container_of(_ep, struct fsl_ep, ep); |
1097 | if (!ep->desc) | 1116 | if (!ep->ep.desc) |
1098 | return; | 1117 | return; |
1099 | } | 1118 | } |
1100 | ep_num = ep_index(ep); | 1119 | ep_num = ep_index(ep); |
@@ -1349,7 +1368,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value, | |||
1349 | target_ep = get_ep_by_pipe(udc, get_pipe_by_windex(index)); | 1368 | target_ep = get_ep_by_pipe(udc, get_pipe_by_windex(index)); |
1350 | 1369 | ||
1351 | /* stall if endpoint doesn't exist */ | 1370 | /* stall if endpoint doesn't exist */ |
1352 | if (!target_ep->desc) | 1371 | if (!target_ep->ep.desc) |
1353 | goto stall; | 1372 | goto stall; |
1354 | tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep)) | 1373 | tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep)) |
1355 | << USB_ENDPOINT_HALT; | 1374 | << USB_ENDPOINT_HALT; |
@@ -2259,7 +2278,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count, | |||
2259 | } | 2278 | } |
2260 | /* other gadget->eplist ep */ | 2279 | /* other gadget->eplist ep */ |
2261 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | 2280 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { |
2262 | if (ep->desc) { | 2281 | if (ep->ep.desc) { |
2263 | t = scnprintf(next, size, | 2282 | t = scnprintf(next, size, |
2264 | "\nFor %s Maxpkt is 0x%x " | 2283 | "\nFor %s Maxpkt is 0x%x " |
2265 | "index is 0x%x\n", | 2284 | "index is 0x%x\n", |
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h index e651469fd39b..5cd7b7e7ddb4 100644 --- a/drivers/usb/gadget/fsl_usb2_udc.h +++ b/drivers/usb/gadget/fsl_usb2_udc.h | |||
@@ -1,4 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2004,2012 Freescale Semiconductor, Inc | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2 of the License, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
2 | * Freescale USB device/endpoint management registers | 10 | * Freescale USB device/endpoint management registers |
3 | */ | 11 | */ |
4 | #ifndef __FSL_USB2_UDC_H | 12 | #ifndef __FSL_USB2_UDC_H |
@@ -348,6 +356,9 @@ struct usb_sys_interface { | |||
348 | /* control Register Bit Masks */ | 356 | /* control Register Bit Masks */ |
349 | #define USB_CTRL_IOENB 0x00000004 | 357 | #define USB_CTRL_IOENB 0x00000004 |
350 | #define USB_CTRL_ULPI_INT0EN 0x00000001 | 358 | #define USB_CTRL_ULPI_INT0EN 0x00000001 |
359 | #define USB_CTRL_UTMI_PHY_EN 0x00000200 | ||
360 | #define USB_CTRL_USB_EN 0x00000004 | ||
361 | #define USB_CTRL_ULPI_PHY_CLK_SEL 0x00000400 | ||
351 | 362 | ||
352 | /* Endpoint Queue Head data struct | 363 | /* Endpoint Queue Head data struct |
353 | * Rem: all the variables of qh are LittleEndian Mode | 364 | * Rem: all the variables of qh are LittleEndian Mode |
@@ -450,7 +461,6 @@ struct fsl_ep { | |||
450 | struct list_head queue; | 461 | struct list_head queue; |
451 | struct fsl_udc *udc; | 462 | struct fsl_udc *udc; |
452 | struct ep_queue_head *qh; | 463 | struct ep_queue_head *qh; |
453 | const struct usb_endpoint_descriptor *desc; | ||
454 | struct usb_gadget *gadget; | 464 | struct usb_gadget *gadget; |
455 | 465 | ||
456 | char name[14]; | 466 | char name[14]; |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index 5831cb4a0b35..cdd94540e1cd 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -203,7 +203,7 @@ static int config_ep(struct fusb300_ep *ep, | |||
203 | struct fusb300 *fusb300 = ep->fusb300; | 203 | struct fusb300 *fusb300 = ep->fusb300; |
204 | struct fusb300_ep_info info; | 204 | struct fusb300_ep_info info; |
205 | 205 | ||
206 | ep->desc = desc; | 206 | ep->ep.desc = desc; |
207 | 207 | ||
208 | info.interval = 0; | 208 | info.interval = 0; |
209 | info.addrofs = 0; | 209 | info.addrofs = 0; |
@@ -443,7 +443,7 @@ static int fusb300_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
443 | req->req.actual = 0; | 443 | req->req.actual = 0; |
444 | req->req.status = -EINPROGRESS; | 444 | req->req.status = -EINPROGRESS; |
445 | 445 | ||
446 | if (ep->desc == NULL) /* ep0 */ | 446 | if (ep->ep.desc == NULL) /* ep0 */ |
447 | ep0_queue(ep, req); | 447 | ep0_queue(ep, req); |
448 | else if (request && !ep->stall) | 448 | else if (request && !ep->stall) |
449 | enable_fifo_int(ep); | 449 | enable_fifo_int(ep); |
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h index 92745bd03064..542cd83cc806 100644 --- a/drivers/usb/gadget/fusb300_udc.h +++ b/drivers/usb/gadget/fusb300_udc.h | |||
@@ -650,7 +650,6 @@ struct fusb300_ep { | |||
650 | 650 | ||
651 | unsigned char epnum; | 651 | unsigned char epnum; |
652 | unsigned char type; | 652 | unsigned char type; |
653 | const struct usb_endpoint_descriptor *desc; | ||
654 | }; | 653 | }; |
655 | 654 | ||
656 | struct fusb300 { | 655 | struct fusb300 { |
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c index a85eaf40b948..d3ace9002a6a 100644 --- a/drivers/usb/gadget/g_ffs.c +++ b/drivers/usb/gadget/g_ffs.c | |||
@@ -67,6 +67,15 @@ MODULE_LICENSE("GPL"); | |||
67 | #define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */ | 67 | #define GFS_VENDOR_ID 0x1d6b /* Linux Foundation */ |
68 | #define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */ | 68 | #define GFS_PRODUCT_ID 0x0105 /* FunctionFS Gadget */ |
69 | 69 | ||
70 | #define GFS_MAX_DEVS 10 | ||
71 | |||
72 | struct gfs_ffs_obj { | ||
73 | const char *name; | ||
74 | bool mounted; | ||
75 | bool desc_ready; | ||
76 | struct ffs_data *ffs_data; | ||
77 | }; | ||
78 | |||
70 | static struct usb_device_descriptor gfs_dev_desc = { | 79 | static struct usb_device_descriptor gfs_dev_desc = { |
71 | .bLength = sizeof gfs_dev_desc, | 80 | .bLength = sizeof gfs_dev_desc, |
72 | .bDescriptorType = USB_DT_DEVICE, | 81 | .bDescriptorType = USB_DT_DEVICE, |
@@ -78,12 +87,17 @@ static struct usb_device_descriptor gfs_dev_desc = { | |||
78 | .idProduct = cpu_to_le16(GFS_PRODUCT_ID), | 87 | .idProduct = cpu_to_le16(GFS_PRODUCT_ID), |
79 | }; | 88 | }; |
80 | 89 | ||
90 | static char *func_names[GFS_MAX_DEVS]; | ||
91 | static unsigned int func_num; | ||
92 | |||
81 | module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644); | 93 | module_param_named(bDeviceClass, gfs_dev_desc.bDeviceClass, byte, 0644); |
82 | MODULE_PARM_DESC(bDeviceClass, "USB Device class"); | 94 | MODULE_PARM_DESC(bDeviceClass, "USB Device class"); |
83 | module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644); | 95 | module_param_named(bDeviceSubClass, gfs_dev_desc.bDeviceSubClass, byte, 0644); |
84 | MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass"); | 96 | MODULE_PARM_DESC(bDeviceSubClass, "USB Device subclass"); |
85 | module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); | 97 | module_param_named(bDeviceProtocol, gfs_dev_desc.bDeviceProtocol, byte, 0644); |
86 | MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); | 98 | MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol"); |
99 | module_param_array_named(functions, func_names, charp, &func_num, 0); | ||
100 | MODULE_PARM_DESC(functions, "USB Functions list"); | ||
87 | 101 | ||
88 | static const struct usb_descriptor_header *gfs_otg_desc[] = { | 102 | static const struct usb_descriptor_header *gfs_otg_desc[] = { |
89 | (const struct usb_descriptor_header *) | 103 | (const struct usb_descriptor_header *) |
@@ -158,13 +172,34 @@ static struct usb_composite_driver gfs_driver = { | |||
158 | .iProduct = DRIVER_DESC, | 172 | .iProduct = DRIVER_DESC, |
159 | }; | 173 | }; |
160 | 174 | ||
161 | static struct ffs_data *gfs_ffs_data; | 175 | static DEFINE_MUTEX(gfs_lock); |
162 | static unsigned long gfs_registered; | 176 | static unsigned int missing_funcs; |
177 | static bool gfs_ether_setup; | ||
178 | static bool gfs_registered; | ||
179 | static bool gfs_single_func; | ||
180 | static struct gfs_ffs_obj *ffs_tab; | ||
163 | 181 | ||
164 | static int __init gfs_init(void) | 182 | static int __init gfs_init(void) |
165 | { | 183 | { |
184 | int i; | ||
185 | |||
166 | ENTER(); | 186 | ENTER(); |
167 | 187 | ||
188 | if (!func_num) { | ||
189 | gfs_single_func = true; | ||
190 | func_num = 1; | ||
191 | } | ||
192 | |||
193 | ffs_tab = kcalloc(func_num, sizeof *ffs_tab, GFP_KERNEL); | ||
194 | if (!ffs_tab) | ||
195 | return -ENOMEM; | ||
196 | |||
197 | if (!gfs_single_func) | ||
198 | for (i = 0; i < func_num; i++) | ||
199 | ffs_tab[i].name = func_names[i]; | ||
200 | |||
201 | missing_funcs = func_num; | ||
202 | |||
168 | return functionfs_init(); | 203 | return functionfs_init(); |
169 | } | 204 | } |
170 | module_init(gfs_init); | 205 | module_init(gfs_init); |
@@ -172,63 +207,165 @@ module_init(gfs_init); | |||
172 | static void __exit gfs_exit(void) | 207 | static void __exit gfs_exit(void) |
173 | { | 208 | { |
174 | ENTER(); | 209 | ENTER(); |
210 | mutex_lock(&gfs_lock); | ||
175 | 211 | ||
176 | if (test_and_clear_bit(0, &gfs_registered)) | 212 | if (gfs_registered) |
177 | usb_composite_unregister(&gfs_driver); | 213 | usb_composite_unregister(&gfs_driver); |
214 | gfs_registered = false; | ||
178 | 215 | ||
179 | functionfs_cleanup(); | 216 | functionfs_cleanup(); |
217 | |||
218 | mutex_unlock(&gfs_lock); | ||
219 | kfree(ffs_tab); | ||
180 | } | 220 | } |
181 | module_exit(gfs_exit); | 221 | module_exit(gfs_exit); |
182 | 222 | ||
223 | static struct gfs_ffs_obj *gfs_find_dev(const char *dev_name) | ||
224 | { | ||
225 | int i; | ||
226 | |||
227 | ENTER(); | ||
228 | |||
229 | if (gfs_single_func) | ||
230 | return &ffs_tab[0]; | ||
231 | |||
232 | for (i = 0; i < func_num; i++) | ||
233 | if (strcmp(ffs_tab[i].name, dev_name) == 0) | ||
234 | return &ffs_tab[i]; | ||
235 | |||
236 | return NULL; | ||
237 | } | ||
238 | |||
183 | static int functionfs_ready_callback(struct ffs_data *ffs) | 239 | static int functionfs_ready_callback(struct ffs_data *ffs) |
184 | { | 240 | { |
241 | struct gfs_ffs_obj *ffs_obj; | ||
185 | int ret; | 242 | int ret; |
186 | 243 | ||
187 | ENTER(); | 244 | ENTER(); |
245 | mutex_lock(&gfs_lock); | ||
246 | |||
247 | ffs_obj = ffs->private_data; | ||
248 | if (!ffs_obj) { | ||
249 | ret = -EINVAL; | ||
250 | goto done; | ||
251 | } | ||
252 | |||
253 | if (WARN_ON(ffs_obj->desc_ready)) { | ||
254 | ret = -EBUSY; | ||
255 | goto done; | ||
256 | } | ||
257 | ffs_obj->desc_ready = true; | ||
258 | ffs_obj->ffs_data = ffs; | ||
188 | 259 | ||
189 | if (WARN_ON(test_and_set_bit(0, &gfs_registered))) | 260 | if (--missing_funcs) { |
190 | return -EBUSY; | 261 | ret = 0; |
262 | goto done; | ||
263 | } | ||
264 | |||
265 | if (gfs_registered) { | ||
266 | ret = -EBUSY; | ||
267 | goto done; | ||
268 | } | ||
269 | gfs_registered = true; | ||
191 | 270 | ||
192 | gfs_ffs_data = ffs; | ||
193 | ret = usb_composite_probe(&gfs_driver, gfs_bind); | 271 | ret = usb_composite_probe(&gfs_driver, gfs_bind); |
194 | if (unlikely(ret < 0)) | 272 | if (unlikely(ret < 0)) |
195 | clear_bit(0, &gfs_registered); | 273 | gfs_registered = false; |
274 | |||
275 | done: | ||
276 | mutex_unlock(&gfs_lock); | ||
196 | return ret; | 277 | return ret; |
197 | } | 278 | } |
198 | 279 | ||
199 | static void functionfs_closed_callback(struct ffs_data *ffs) | 280 | static void functionfs_closed_callback(struct ffs_data *ffs) |
200 | { | 281 | { |
282 | struct gfs_ffs_obj *ffs_obj; | ||
283 | |||
201 | ENTER(); | 284 | ENTER(); |
285 | mutex_lock(&gfs_lock); | ||
202 | 286 | ||
203 | if (test_and_clear_bit(0, &gfs_registered)) | 287 | ffs_obj = ffs->private_data; |
288 | if (!ffs_obj) | ||
289 | goto done; | ||
290 | |||
291 | ffs_obj->desc_ready = false; | ||
292 | missing_funcs++; | ||
293 | |||
294 | if (gfs_registered) | ||
204 | usb_composite_unregister(&gfs_driver); | 295 | usb_composite_unregister(&gfs_driver); |
296 | gfs_registered = false; | ||
297 | |||
298 | done: | ||
299 | mutex_unlock(&gfs_lock); | ||
205 | } | 300 | } |
206 | 301 | ||
207 | static int functionfs_check_dev_callback(const char *dev_name) | 302 | static void *functionfs_acquire_dev_callback(const char *dev_name) |
208 | { | 303 | { |
209 | return 0; | 304 | struct gfs_ffs_obj *ffs_dev; |
305 | |||
306 | ENTER(); | ||
307 | mutex_lock(&gfs_lock); | ||
308 | |||
309 | ffs_dev = gfs_find_dev(dev_name); | ||
310 | if (!ffs_dev) { | ||
311 | ffs_dev = ERR_PTR(-ENODEV); | ||
312 | goto done; | ||
313 | } | ||
314 | |||
315 | if (ffs_dev->mounted) { | ||
316 | ffs_dev = ERR_PTR(-EBUSY); | ||
317 | goto done; | ||
318 | } | ||
319 | ffs_dev->mounted = true; | ||
320 | |||
321 | done: | ||
322 | mutex_unlock(&gfs_lock); | ||
323 | return ffs_dev; | ||
210 | } | 324 | } |
211 | 325 | ||
326 | static void functionfs_release_dev_callback(struct ffs_data *ffs_data) | ||
327 | { | ||
328 | struct gfs_ffs_obj *ffs_dev; | ||
329 | |||
330 | ENTER(); | ||
331 | mutex_lock(&gfs_lock); | ||
332 | |||
333 | ffs_dev = ffs_data->private_data; | ||
334 | if (ffs_dev) | ||
335 | ffs_dev->mounted = false; | ||
336 | |||
337 | mutex_unlock(&gfs_lock); | ||
338 | } | ||
339 | |||
340 | /* | ||
341 | * It is assumed that gfs_bind is called from a context where gfs_lock is held | ||
342 | */ | ||
212 | static int gfs_bind(struct usb_composite_dev *cdev) | 343 | static int gfs_bind(struct usb_composite_dev *cdev) |
213 | { | 344 | { |
214 | int ret, i; | 345 | int ret, i; |
215 | 346 | ||
216 | ENTER(); | 347 | ENTER(); |
217 | 348 | ||
218 | if (WARN_ON(!gfs_ffs_data)) | 349 | if (missing_funcs) |
219 | return -ENODEV; | 350 | return -ENODEV; |
220 | 351 | ||
221 | ret = gether_setup(cdev->gadget, gfs_hostaddr); | 352 | ret = gether_setup(cdev->gadget, gfs_hostaddr); |
222 | if (unlikely(ret < 0)) | 353 | if (unlikely(ret < 0)) |
223 | goto error_quick; | 354 | goto error_quick; |
355 | gfs_ether_setup = true; | ||
224 | 356 | ||
225 | ret = usb_string_ids_tab(cdev, gfs_strings); | 357 | ret = usb_string_ids_tab(cdev, gfs_strings); |
226 | if (unlikely(ret < 0)) | 358 | if (unlikely(ret < 0)) |
227 | goto error; | 359 | goto error; |
228 | 360 | ||
229 | ret = functionfs_bind(gfs_ffs_data, cdev); | 361 | for (i = func_num; --i; ) { |
230 | if (unlikely(ret < 0)) | 362 | ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); |
231 | goto error; | 363 | if (unlikely(ret < 0)) { |
364 | while (++i < func_num) | ||
365 | functionfs_unbind(ffs_tab[i].ffs_data); | ||
366 | goto error; | ||
367 | } | ||
368 | } | ||
232 | 369 | ||
233 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { | 370 | for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { |
234 | struct gfs_configuration *c = gfs_configurations + i; | 371 | struct gfs_configuration *c = gfs_configurations + i; |
@@ -246,16 +383,22 @@ static int gfs_bind(struct usb_composite_dev *cdev) | |||
246 | return 0; | 383 | return 0; |
247 | 384 | ||
248 | error_unbind: | 385 | error_unbind: |
249 | functionfs_unbind(gfs_ffs_data); | 386 | for (i = 0; i < func_num; i++) |
387 | functionfs_unbind(ffs_tab[i].ffs_data); | ||
250 | error: | 388 | error: |
251 | gether_cleanup(); | 389 | gether_cleanup(); |
252 | error_quick: | 390 | error_quick: |
253 | gfs_ffs_data = NULL; | 391 | gfs_ether_setup = false; |
254 | return ret; | 392 | return ret; |
255 | } | 393 | } |
256 | 394 | ||
395 | /* | ||
396 | * It is assumed that gfs_unbind is called from a context where gfs_lock is held | ||
397 | */ | ||
257 | static int gfs_unbind(struct usb_composite_dev *cdev) | 398 | static int gfs_unbind(struct usb_composite_dev *cdev) |
258 | { | 399 | { |
400 | int i; | ||
401 | |||
259 | ENTER(); | 402 | ENTER(); |
260 | 403 | ||
261 | /* | 404 | /* |
@@ -266,22 +409,29 @@ static int gfs_unbind(struct usb_composite_dev *cdev) | |||
266 | * from composite on orror recovery, but what you're gonna | 409 | * from composite on orror recovery, but what you're gonna |
267 | * do...? | 410 | * do...? |
268 | */ | 411 | */ |
269 | if (gfs_ffs_data) { | 412 | if (gfs_ether_setup) |
270 | gether_cleanup(); | 413 | gether_cleanup(); |
271 | functionfs_unbind(gfs_ffs_data); | 414 | gfs_ether_setup = false; |
272 | gfs_ffs_data = NULL; | 415 | |
273 | } | 416 | for (i = func_num; --i; ) |
417 | if (ffs_tab[i].ffs_data) | ||
418 | functionfs_unbind(ffs_tab[i].ffs_data); | ||
274 | 419 | ||
275 | return 0; | 420 | return 0; |
276 | } | 421 | } |
277 | 422 | ||
423 | /* | ||
424 | * It is assumed that gfs_do_config is called from a context where | ||
425 | * gfs_lock is held | ||
426 | */ | ||
278 | static int gfs_do_config(struct usb_configuration *c) | 427 | static int gfs_do_config(struct usb_configuration *c) |
279 | { | 428 | { |
280 | struct gfs_configuration *gc = | 429 | struct gfs_configuration *gc = |
281 | container_of(c, struct gfs_configuration, c); | 430 | container_of(c, struct gfs_configuration, c); |
431 | int i; | ||
282 | int ret; | 432 | int ret; |
283 | 433 | ||
284 | if (WARN_ON(!gfs_ffs_data)) | 434 | if (missing_funcs) |
285 | return -ENODEV; | 435 | return -ENODEV; |
286 | 436 | ||
287 | if (gadget_is_otg(c->cdev->gadget)) { | 437 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -295,9 +445,11 @@ static int gfs_do_config(struct usb_configuration *c) | |||
295 | return ret; | 445 | return ret; |
296 | } | 446 | } |
297 | 447 | ||
298 | ret = functionfs_bind_config(c->cdev, c, gfs_ffs_data); | 448 | for (i = 0; i < func_num; i++) { |
299 | if (unlikely(ret < 0)) | 449 | ret = functionfs_bind_config(c->cdev, c, ffs_tab[i].ffs_data); |
300 | return ret; | 450 | if (unlikely(ret < 0)) |
451 | return ret; | ||
452 | } | ||
301 | 453 | ||
302 | /* | 454 | /* |
303 | * After previous do_configs there may be some invalid | 455 | * After previous do_configs there may be some invalid |
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h index e84b3c47ed3c..71ca193358b8 100644 --- a/drivers/usb/gadget/g_zero.h +++ b/drivers/usb/gadget/g_zero.h | |||
@@ -13,10 +13,11 @@ extern unsigned buflen; | |||
13 | extern const struct usb_descriptor_header *otg_desc[]; | 13 | extern const struct usb_descriptor_header *otg_desc[]; |
14 | 14 | ||
15 | /* common utilities */ | 15 | /* common utilities */ |
16 | struct usb_request *alloc_ep_req(struct usb_ep *ep); | 16 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len); |
17 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); | 17 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); |
18 | void disable_endpoints(struct usb_composite_dev *cdev, | 18 | void disable_endpoints(struct usb_composite_dev *cdev, |
19 | struct usb_ep *in, struct usb_ep *out); | 19 | struct usb_ep *in, struct usb_ep *out, |
20 | struct usb_ep *iso_in, struct usb_ep *iso_out); | ||
20 | 21 | ||
21 | /* configuration-specific linkup */ | 22 | /* configuration-specific linkup */ |
22 | int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume); | 23 | int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume); |
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index a8855d0b7f3b..b8b3a3411218 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -37,6 +37,7 @@ | |||
37 | #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) | 37 | #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) |
38 | #define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name)) | 38 | #define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name)) |
39 | #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name)) | 39 | #define gadget_is_langwell(g) (!strcmp("langwell_udc", (g)->name)) |
40 | #define gadget_is_lpc32xx(g) (!strcmp("lpc32xx_udc", (g)->name)) | ||
40 | #define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name)) | 41 | #define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name)) |
41 | #define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name)) | 42 | #define gadget_is_musbhdrc(g) (!strcmp("musb-hdrc", (g)->name)) |
42 | #define gadget_is_net2272(g) (!strcmp("net2272", (g)->name)) | 43 | #define gadget_is_net2272(g) (!strcmp("net2272", (g)->name)) |
@@ -118,6 +119,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
118 | return 0x31; | 119 | return 0x31; |
119 | else if (gadget_is_dwc3(gadget)) | 120 | else if (gadget_is_dwc3(gadget)) |
120 | return 0x32; | 121 | return 0x32; |
122 | else if (gadget_is_lpc32xx(gadget)) | ||
123 | return 0x33; | ||
121 | 124 | ||
122 | return -ENOENT; | 125 | return -ENOENT; |
123 | } | 126 | } |
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c index e151d6b87dee..b241e6c6a7f2 100644 --- a/drivers/usb/gadget/goku_udc.c +++ b/drivers/usb/gadget/goku_udc.c | |||
@@ -102,7 +102,7 @@ goku_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
102 | unsigned long flags; | 102 | unsigned long flags; |
103 | 103 | ||
104 | ep = container_of(_ep, struct goku_ep, ep); | 104 | ep = container_of(_ep, struct goku_ep, ep); |
105 | if (!_ep || !desc || ep->desc | 105 | if (!_ep || !desc || ep->ep.desc |
106 | || desc->bDescriptorType != USB_DT_ENDPOINT) | 106 | || desc->bDescriptorType != USB_DT_ENDPOINT) |
107 | return -EINVAL; | 107 | return -EINVAL; |
108 | dev = ep->dev; | 108 | dev = ep->dev; |
@@ -176,7 +176,7 @@ goku_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) | |||
176 | command(ep->dev->regs, COMMAND_RESET, ep->num); | 176 | command(ep->dev->regs, COMMAND_RESET, ep->num); |
177 | ep->ep.maxpacket = max; | 177 | ep->ep.maxpacket = max; |
178 | ep->stopped = 0; | 178 | ep->stopped = 0; |
179 | ep->desc = desc; | 179 | ep->ep.desc = desc; |
180 | spin_unlock_irqrestore(&ep->dev->lock, flags); | 180 | spin_unlock_irqrestore(&ep->dev->lock, flags); |
181 | 181 | ||
182 | DBG(dev, "enable %s %s %s maxpacket %u\n", ep->ep.name, | 182 | DBG(dev, "enable %s %s %s maxpacket %u\n", ep->ep.name, |
@@ -233,7 +233,6 @@ static void ep_reset(struct goku_udc_regs __iomem *regs, struct goku_ep *ep) | |||
233 | } | 233 | } |
234 | 234 | ||
235 | ep->ep.maxpacket = MAX_FIFO_SIZE; | 235 | ep->ep.maxpacket = MAX_FIFO_SIZE; |
236 | ep->desc = NULL; | ||
237 | ep->ep.desc = NULL; | 236 | ep->ep.desc = NULL; |
238 | ep->stopped = 1; | 237 | ep->stopped = 1; |
239 | ep->irqs = 0; | 238 | ep->irqs = 0; |
@@ -247,7 +246,7 @@ static int goku_ep_disable(struct usb_ep *_ep) | |||
247 | unsigned long flags; | 246 | unsigned long flags; |
248 | 247 | ||
249 | ep = container_of(_ep, struct goku_ep, ep); | 248 | ep = container_of(_ep, struct goku_ep, ep); |
250 | if (!_ep || !ep->desc) | 249 | if (!_ep || !ep->ep.desc) |
251 | return -ENODEV; | 250 | return -ENODEV; |
252 | dev = ep->dev; | 251 | dev = ep->dev; |
253 | if (dev->ep0state == EP0_SUSPEND) | 252 | if (dev->ep0state == EP0_SUSPEND) |
@@ -722,7 +721,7 @@ goku_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
722 | || !_req->buf || !list_empty(&req->queue))) | 721 | || !_req->buf || !list_empty(&req->queue))) |
723 | return -EINVAL; | 722 | return -EINVAL; |
724 | ep = container_of(_ep, struct goku_ep, ep); | 723 | ep = container_of(_ep, struct goku_ep, ep); |
725 | if (unlikely(!_ep || (!ep->desc && ep->num != 0))) | 724 | if (unlikely(!_ep || (!ep->ep.desc && ep->num != 0))) |
726 | return -EINVAL; | 725 | return -EINVAL; |
727 | dev = ep->dev; | 726 | dev = ep->dev; |
728 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) | 727 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) |
@@ -815,7 +814,7 @@ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
815 | unsigned long flags; | 814 | unsigned long flags; |
816 | 815 | ||
817 | ep = container_of(_ep, struct goku_ep, ep); | 816 | ep = container_of(_ep, struct goku_ep, ep); |
818 | if (!_ep || !_req || (!ep->desc && ep->num != 0)) | 817 | if (!_ep || !_req || (!ep->ep.desc && ep->num != 0)) |
819 | return -EINVAL; | 818 | return -EINVAL; |
820 | dev = ep->dev; | 819 | dev = ep->dev; |
821 | if (!dev->driver) | 820 | if (!dev->driver) |
@@ -896,7 +895,7 @@ static int goku_set_halt(struct usb_ep *_ep, int value) | |||
896 | return -EINVAL; | 895 | return -EINVAL; |
897 | 896 | ||
898 | /* don't change EPxSTATUS_EP_INVALID to READY */ | 897 | /* don't change EPxSTATUS_EP_INVALID to READY */ |
899 | } else if (!ep->desc) { | 898 | } else if (!ep->ep.desc) { |
900 | DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); | 899 | DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); |
901 | return -EINVAL; | 900 | return -EINVAL; |
902 | } | 901 | } |
@@ -955,7 +954,7 @@ static void goku_fifo_flush(struct usb_ep *_ep) | |||
955 | VDBG(ep->dev, "%s %s\n", __func__, ep->ep.name); | 954 | VDBG(ep->dev, "%s %s\n", __func__, ep->ep.name); |
956 | 955 | ||
957 | /* don't change EPxSTATUS_EP_INVALID to READY */ | 956 | /* don't change EPxSTATUS_EP_INVALID to READY */ |
958 | if (!ep->desc && ep->num != 0) { | 957 | if (!ep->ep.desc && ep->num != 0) { |
959 | DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); | 958 | DBG(ep->dev, "%s %s inactive?\n", __func__, ep->ep.name); |
960 | return; | 959 | return; |
961 | } | 960 | } |
@@ -1152,7 +1151,7 @@ udc_proc_read(char *buffer, char **start, off_t off, int count, | |||
1152 | struct goku_ep *ep = &dev->ep [i]; | 1151 | struct goku_ep *ep = &dev->ep [i]; |
1153 | struct goku_request *req; | 1152 | struct goku_request *req; |
1154 | 1153 | ||
1155 | if (i && !ep->desc) | 1154 | if (i && !ep->ep.desc) |
1156 | continue; | 1155 | continue; |
1157 | 1156 | ||
1158 | tmp = readl(ep->reg_status); | 1157 | tmp = readl(ep->reg_status); |
@@ -1473,7 +1472,8 @@ static void ep0_setup(struct goku_udc *dev) | |||
1473 | case USB_RECIP_ENDPOINT: | 1472 | case USB_RECIP_ENDPOINT: |
1474 | tmp = le16_to_cpu(ctrl.wIndex) & 0x0f; | 1473 | tmp = le16_to_cpu(ctrl.wIndex) & 0x0f; |
1475 | /* active endpoint */ | 1474 | /* active endpoint */ |
1476 | if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) | 1475 | if (tmp > 3 || |
1476 | (!dev->ep[tmp].ep.desc && tmp != 0)) | ||
1477 | goto stall; | 1477 | goto stall; |
1478 | if (ctrl.wIndex & cpu_to_le16( | 1478 | if (ctrl.wIndex & cpu_to_le16( |
1479 | USB_DIR_IN)) { | 1479 | USB_DIR_IN)) { |
@@ -1895,14 +1895,4 @@ static struct pci_driver goku_pci_driver = { | |||
1895 | /* FIXME add power management support */ | 1895 | /* FIXME add power management support */ |
1896 | }; | 1896 | }; |
1897 | 1897 | ||
1898 | static int __init init (void) | 1898 | module_pci_driver(goku_pci_driver); |
1899 | { | ||
1900 | return pci_register_driver (&goku_pci_driver); | ||
1901 | } | ||
1902 | module_init (init); | ||
1903 | |||
1904 | static void __exit cleanup (void) | ||
1905 | { | ||
1906 | pci_unregister_driver (&goku_pci_driver); | ||
1907 | } | ||
1908 | module_exit (cleanup); | ||
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h index e7e0c69d3b1f..85cdce0d1901 100644 --- a/drivers/usb/gadget/goku_udc.h +++ b/drivers/usb/gadget/goku_udc.h | |||
@@ -216,7 +216,6 @@ struct goku_ep { | |||
216 | 216 | ||
217 | /* analogous to a host-side qh */ | 217 | /* analogous to a host-side qh */ |
218 | struct list_head queue; | 218 | struct list_head queue; |
219 | const struct usb_endpoint_descriptor *desc; | ||
220 | 219 | ||
221 | u32 __iomem *reg_fifo; | 220 | u32 __iomem *reg_fifo; |
222 | u32 __iomem *reg_mode; | 221 | u32 __iomem *reg_mode; |
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c index 8d1c75abd73d..54034f84f992 100644 --- a/drivers/usb/gadget/imx_udc.c +++ b/drivers/usb/gadget/imx_udc.c | |||
@@ -1237,14 +1237,15 @@ irq_handler_t intr_handler(int i) | |||
1237 | ******************************************************************************* | 1237 | ******************************************************************************* |
1238 | */ | 1238 | */ |
1239 | 1239 | ||
1240 | static int imx_udc_start(struct usb_gadget_driver *driver, | 1240 | static int imx_udc_start(struct usb_gadget *gadget, |
1241 | int (*bind)(struct usb_gadget *)); | 1241 | struct usb_gadget_driver *driver); |
1242 | static int imx_udc_stop(struct usb_gadget_driver *driver); | 1242 | static int imx_udc_stop(struct usb_gadget *gadget, |
1243 | struct usb_gadget_driver *driver); | ||
1243 | static const struct usb_gadget_ops imx_udc_ops = { | 1244 | static const struct usb_gadget_ops imx_udc_ops = { |
1244 | .get_frame = imx_udc_get_frame, | 1245 | .get_frame = imx_udc_get_frame, |
1245 | .wakeup = imx_udc_wakeup, | 1246 | .wakeup = imx_udc_wakeup, |
1246 | .start = imx_udc_start, | 1247 | .udc_start = imx_udc_start, |
1247 | .stop = imx_udc_stop, | 1248 | .udc_stop = imx_udc_stop, |
1248 | }; | 1249 | }; |
1249 | 1250 | ||
1250 | static struct imx_udc_struct controller = { | 1251 | static struct imx_udc_struct controller = { |
@@ -1329,23 +1330,13 @@ static struct imx_udc_struct controller = { | |||
1329 | * USB gadget driver functions | 1330 | * USB gadget driver functions |
1330 | ******************************************************************************* | 1331 | ******************************************************************************* |
1331 | */ | 1332 | */ |
1332 | static int imx_udc_start(struct usb_gadget_driver *driver, | 1333 | static int imx_udc_start(struct usb_gadget *gadget, |
1333 | int (*bind)(struct usb_gadget *)) | 1334 | struct usb_gadget_driver *driver) |
1334 | { | 1335 | { |
1335 | struct imx_udc_struct *imx_usb = &controller; | 1336 | struct imx_udc_struct *imx_usb; |
1336 | int retval; | 1337 | int retval; |
1337 | 1338 | ||
1338 | if (!driver | 1339 | imx_usb = container_of(gadget, struct imx_udc_struct, gadget); |
1339 | || driver->max_speed < USB_SPEED_FULL | ||
1340 | || !bind | ||
1341 | || !driver->disconnect | ||
1342 | || !driver->setup) | ||
1343 | return -EINVAL; | ||
1344 | if (!imx_usb) | ||
1345 | return -ENODEV; | ||
1346 | if (imx_usb->driver) | ||
1347 | return -EBUSY; | ||
1348 | |||
1349 | /* first hook up the driver ... */ | 1340 | /* first hook up the driver ... */ |
1350 | imx_usb->driver = driver; | 1341 | imx_usb->driver = driver; |
1351 | imx_usb->gadget.dev.driver = &driver->driver; | 1342 | imx_usb->gadget.dev.driver = &driver->driver; |
@@ -1353,14 +1344,6 @@ static int imx_udc_start(struct usb_gadget_driver *driver, | |||
1353 | retval = device_add(&imx_usb->gadget.dev); | 1344 | retval = device_add(&imx_usb->gadget.dev); |
1354 | if (retval) | 1345 | if (retval) |
1355 | goto fail; | 1346 | goto fail; |
1356 | retval = bind(&imx_usb->gadget); | ||
1357 | if (retval) { | ||
1358 | D_ERR(imx_usb->dev, "<%s> bind to driver %s --> error %d\n", | ||
1359 | __func__, driver->driver.name, retval); | ||
1360 | device_del(&imx_usb->gadget.dev); | ||
1361 | |||
1362 | goto fail; | ||
1363 | } | ||
1364 | 1347 | ||
1365 | D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", | 1348 | D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", |
1366 | __func__, driver->driver.name); | 1349 | __func__, driver->driver.name); |
@@ -1374,20 +1357,16 @@ fail: | |||
1374 | return retval; | 1357 | return retval; |
1375 | } | 1358 | } |
1376 | 1359 | ||
1377 | static int imx_udc_stop(struct usb_gadget_driver *driver) | 1360 | static int imx_udc_stop(struct usb_gadget *gadget, |
1361 | struct usb_gadget_driver *driver) | ||
1378 | { | 1362 | { |
1379 | struct imx_udc_struct *imx_usb = &controller; | 1363 | struct imx_udc_struct *imx_usb = container_of(gadget, |
1380 | 1364 | struct imx_udc_struct, gadget); | |
1381 | if (!imx_usb) | ||
1382 | return -ENODEV; | ||
1383 | if (!driver || driver != imx_usb->driver || !driver->unbind) | ||
1384 | return -EINVAL; | ||
1385 | 1365 | ||
1386 | udc_stop_activity(imx_usb, driver); | 1366 | udc_stop_activity(imx_usb, driver); |
1387 | imx_udc_disable(imx_usb); | 1367 | imx_udc_disable(imx_usb); |
1388 | del_timer(&imx_usb->timer); | 1368 | del_timer(&imx_usb->timer); |
1389 | 1369 | ||
1390 | driver->unbind(&imx_usb->gadget); | ||
1391 | imx_usb->gadget.dev.driver = NULL; | 1370 | imx_usb->gadget.dev.driver = NULL; |
1392 | imx_usb->driver = NULL; | 1371 | imx_usb->driver = NULL; |
1393 | 1372 | ||
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c deleted file mode 100644 index f9cedd52cf20..000000000000 --- a/drivers/usb/gadget/langwell_udc.c +++ /dev/null | |||
@@ -1,3434 +0,0 @@ | |||
1 | /* | ||
2 | * Intel Langwell USB Device Controller driver | ||
3 | * Copyright (C) 2008-2009, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | |||
11 | /* #undef DEBUG */ | ||
12 | /* #undef VERBOSE_DEBUG */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/pci.h> | ||
16 | #include <linux/dma-mapping.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/ioport.h> | ||
20 | #include <linux/sched.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/timer.h> | ||
25 | #include <linux/list.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/moduleparam.h> | ||
28 | #include <linux/device.h> | ||
29 | #include <linux/usb/ch9.h> | ||
30 | #include <linux/usb/gadget.h> | ||
31 | #include <linux/usb/otg.h> | ||
32 | #include <linux/pm.h> | ||
33 | #include <linux/io.h> | ||
34 | #include <linux/irq.h> | ||
35 | #include <asm/unaligned.h> | ||
36 | |||
37 | #include "langwell_udc.h" | ||
38 | |||
39 | |||
40 | #define DRIVER_DESC "Intel Langwell USB Device Controller driver" | ||
41 | #define DRIVER_VERSION "16 May 2009" | ||
42 | |||
43 | static const char driver_name[] = "langwell_udc"; | ||
44 | static const char driver_desc[] = DRIVER_DESC; | ||
45 | |||
46 | |||
47 | /* for endpoint 0 operations */ | ||
48 | static const struct usb_endpoint_descriptor | ||
49 | langwell_ep0_desc = { | ||
50 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
51 | .bDescriptorType = USB_DT_ENDPOINT, | ||
52 | .bEndpointAddress = 0, | ||
53 | .bmAttributes = USB_ENDPOINT_XFER_CONTROL, | ||
54 | .wMaxPacketSize = EP0_MAX_PKT_SIZE, | ||
55 | }; | ||
56 | |||
57 | |||
58 | /*-------------------------------------------------------------------------*/ | ||
59 | /* debugging */ | ||
60 | |||
61 | #ifdef VERBOSE_DEBUG | ||
62 | static inline void print_all_registers(struct langwell_udc *dev) | ||
63 | { | ||
64 | int i; | ||
65 | |||
66 | /* Capability Registers */ | ||
67 | dev_dbg(&dev->pdev->dev, | ||
68 | "Capability Registers (offset: 0x%04x, length: 0x%08x)\n", | ||
69 | CAP_REG_OFFSET, (u32)sizeof(struct langwell_cap_regs)); | ||
70 | dev_dbg(&dev->pdev->dev, "caplength=0x%02x\n", | ||
71 | readb(&dev->cap_regs->caplength)); | ||
72 | dev_dbg(&dev->pdev->dev, "hciversion=0x%04x\n", | ||
73 | readw(&dev->cap_regs->hciversion)); | ||
74 | dev_dbg(&dev->pdev->dev, "hcsparams=0x%08x\n", | ||
75 | readl(&dev->cap_regs->hcsparams)); | ||
76 | dev_dbg(&dev->pdev->dev, "hccparams=0x%08x\n", | ||
77 | readl(&dev->cap_regs->hccparams)); | ||
78 | dev_dbg(&dev->pdev->dev, "dciversion=0x%04x\n", | ||
79 | readw(&dev->cap_regs->dciversion)); | ||
80 | dev_dbg(&dev->pdev->dev, "dccparams=0x%08x\n", | ||
81 | readl(&dev->cap_regs->dccparams)); | ||
82 | |||
83 | /* Operational Registers */ | ||
84 | dev_dbg(&dev->pdev->dev, | ||
85 | "Operational Registers (offset: 0x%04x, length: 0x%08x)\n", | ||
86 | OP_REG_OFFSET, (u32)sizeof(struct langwell_op_regs)); | ||
87 | dev_dbg(&dev->pdev->dev, "extsts=0x%08x\n", | ||
88 | readl(&dev->op_regs->extsts)); | ||
89 | dev_dbg(&dev->pdev->dev, "extintr=0x%08x\n", | ||
90 | readl(&dev->op_regs->extintr)); | ||
91 | dev_dbg(&dev->pdev->dev, "usbcmd=0x%08x\n", | ||
92 | readl(&dev->op_regs->usbcmd)); | ||
93 | dev_dbg(&dev->pdev->dev, "usbsts=0x%08x\n", | ||
94 | readl(&dev->op_regs->usbsts)); | ||
95 | dev_dbg(&dev->pdev->dev, "usbintr=0x%08x\n", | ||
96 | readl(&dev->op_regs->usbintr)); | ||
97 | dev_dbg(&dev->pdev->dev, "frindex=0x%08x\n", | ||
98 | readl(&dev->op_regs->frindex)); | ||
99 | dev_dbg(&dev->pdev->dev, "ctrldssegment=0x%08x\n", | ||
100 | readl(&dev->op_regs->ctrldssegment)); | ||
101 | dev_dbg(&dev->pdev->dev, "deviceaddr=0x%08x\n", | ||
102 | readl(&dev->op_regs->deviceaddr)); | ||
103 | dev_dbg(&dev->pdev->dev, "endpointlistaddr=0x%08x\n", | ||
104 | readl(&dev->op_regs->endpointlistaddr)); | ||
105 | dev_dbg(&dev->pdev->dev, "ttctrl=0x%08x\n", | ||
106 | readl(&dev->op_regs->ttctrl)); | ||
107 | dev_dbg(&dev->pdev->dev, "burstsize=0x%08x\n", | ||
108 | readl(&dev->op_regs->burstsize)); | ||
109 | dev_dbg(&dev->pdev->dev, "txfilltuning=0x%08x\n", | ||
110 | readl(&dev->op_regs->txfilltuning)); | ||
111 | dev_dbg(&dev->pdev->dev, "txttfilltuning=0x%08x\n", | ||
112 | readl(&dev->op_regs->txttfilltuning)); | ||
113 | dev_dbg(&dev->pdev->dev, "ic_usb=0x%08x\n", | ||
114 | readl(&dev->op_regs->ic_usb)); | ||
115 | dev_dbg(&dev->pdev->dev, "ulpi_viewport=0x%08x\n", | ||
116 | readl(&dev->op_regs->ulpi_viewport)); | ||
117 | dev_dbg(&dev->pdev->dev, "configflag=0x%08x\n", | ||
118 | readl(&dev->op_regs->configflag)); | ||
119 | dev_dbg(&dev->pdev->dev, "portsc1=0x%08x\n", | ||
120 | readl(&dev->op_regs->portsc1)); | ||
121 | dev_dbg(&dev->pdev->dev, "devlc=0x%08x\n", | ||
122 | readl(&dev->op_regs->devlc)); | ||
123 | dev_dbg(&dev->pdev->dev, "otgsc=0x%08x\n", | ||
124 | readl(&dev->op_regs->otgsc)); | ||
125 | dev_dbg(&dev->pdev->dev, "usbmode=0x%08x\n", | ||
126 | readl(&dev->op_regs->usbmode)); | ||
127 | dev_dbg(&dev->pdev->dev, "endptnak=0x%08x\n", | ||
128 | readl(&dev->op_regs->endptnak)); | ||
129 | dev_dbg(&dev->pdev->dev, "endptnaken=0x%08x\n", | ||
130 | readl(&dev->op_regs->endptnaken)); | ||
131 | dev_dbg(&dev->pdev->dev, "endptsetupstat=0x%08x\n", | ||
132 | readl(&dev->op_regs->endptsetupstat)); | ||
133 | dev_dbg(&dev->pdev->dev, "endptprime=0x%08x\n", | ||
134 | readl(&dev->op_regs->endptprime)); | ||
135 | dev_dbg(&dev->pdev->dev, "endptflush=0x%08x\n", | ||
136 | readl(&dev->op_regs->endptflush)); | ||
137 | dev_dbg(&dev->pdev->dev, "endptstat=0x%08x\n", | ||
138 | readl(&dev->op_regs->endptstat)); | ||
139 | dev_dbg(&dev->pdev->dev, "endptcomplete=0x%08x\n", | ||
140 | readl(&dev->op_regs->endptcomplete)); | ||
141 | |||
142 | for (i = 0; i < dev->ep_max / 2; i++) { | ||
143 | dev_dbg(&dev->pdev->dev, "endptctrl[%d]=0x%08x\n", | ||
144 | i, readl(&dev->op_regs->endptctrl[i])); | ||
145 | } | ||
146 | } | ||
147 | #else | ||
148 | |||
149 | #define print_all_registers(dev) do { } while (0) | ||
150 | |||
151 | #endif /* VERBOSE_DEBUG */ | ||
152 | |||
153 | |||
154 | /*-------------------------------------------------------------------------*/ | ||
155 | |||
156 | #define is_in(ep) (((ep)->ep_num == 0) ? ((ep)->dev->ep0_dir == \ | ||
157 | USB_DIR_IN) : (usb_endpoint_dir_in((ep)->desc))) | ||
158 | |||
159 | #define DIR_STRING(ep) (is_in(ep) ? "in" : "out") | ||
160 | |||
161 | |||
162 | static char *type_string(const struct usb_endpoint_descriptor *desc) | ||
163 | { | ||
164 | switch (usb_endpoint_type(desc)) { | ||
165 | case USB_ENDPOINT_XFER_BULK: | ||
166 | return "bulk"; | ||
167 | case USB_ENDPOINT_XFER_ISOC: | ||
168 | return "iso"; | ||
169 | case USB_ENDPOINT_XFER_INT: | ||
170 | return "int"; | ||
171 | }; | ||
172 | |||
173 | return "control"; | ||
174 | } | ||
175 | |||
176 | |||
177 | /* configure endpoint control registers */ | ||
178 | static void ep_reset(struct langwell_ep *ep, unsigned char ep_num, | ||
179 | unsigned char is_in, unsigned char ep_type) | ||
180 | { | ||
181 | struct langwell_udc *dev; | ||
182 | u32 endptctrl; | ||
183 | |||
184 | dev = ep->dev; | ||
185 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
186 | |||
187 | endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); | ||
188 | if (is_in) { /* TX */ | ||
189 | if (ep_num) | ||
190 | endptctrl |= EPCTRL_TXR; | ||
191 | endptctrl |= EPCTRL_TXE; | ||
192 | endptctrl |= ep_type << EPCTRL_TXT_SHIFT; | ||
193 | } else { /* RX */ | ||
194 | if (ep_num) | ||
195 | endptctrl |= EPCTRL_RXR; | ||
196 | endptctrl |= EPCTRL_RXE; | ||
197 | endptctrl |= ep_type << EPCTRL_RXT_SHIFT; | ||
198 | } | ||
199 | |||
200 | writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); | ||
201 | |||
202 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
203 | } | ||
204 | |||
205 | |||
206 | /* reset ep0 dQH and endptctrl */ | ||
207 | static void ep0_reset(struct langwell_udc *dev) | ||
208 | { | ||
209 | struct langwell_ep *ep; | ||
210 | int i; | ||
211 | |||
212 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
213 | |||
214 | /* ep0 in and out */ | ||
215 | for (i = 0; i < 2; i++) { | ||
216 | ep = &dev->ep[i]; | ||
217 | ep->dev = dev; | ||
218 | |||
219 | /* ep0 dQH */ | ||
220 | ep->dqh = &dev->ep_dqh[i]; | ||
221 | |||
222 | /* configure ep0 endpoint capabilities in dQH */ | ||
223 | ep->dqh->dqh_ios = 1; | ||
224 | ep->dqh->dqh_mpl = EP0_MAX_PKT_SIZE; | ||
225 | |||
226 | /* enable ep0-in HW zero length termination select */ | ||
227 | if (is_in(ep)) | ||
228 | ep->dqh->dqh_zlt = 0; | ||
229 | ep->dqh->dqh_mult = 0; | ||
230 | |||
231 | ep->dqh->dtd_next = DTD_TERM; | ||
232 | |||
233 | /* configure ep0 control registers */ | ||
234 | ep_reset(&dev->ep[0], 0, i, USB_ENDPOINT_XFER_CONTROL); | ||
235 | } | ||
236 | |||
237 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
238 | } | ||
239 | |||
240 | |||
241 | /*-------------------------------------------------------------------------*/ | ||
242 | |||
243 | /* endpoints operations */ | ||
244 | |||
245 | /* configure endpoint, making it usable */ | ||
246 | static int langwell_ep_enable(struct usb_ep *_ep, | ||
247 | const struct usb_endpoint_descriptor *desc) | ||
248 | { | ||
249 | struct langwell_udc *dev; | ||
250 | struct langwell_ep *ep; | ||
251 | u16 max = 0; | ||
252 | unsigned long flags; | ||
253 | int i, retval = 0; | ||
254 | unsigned char zlt, ios = 0, mult = 0; | ||
255 | |||
256 | ep = container_of(_ep, struct langwell_ep, ep); | ||
257 | dev = ep->dev; | ||
258 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
259 | |||
260 | if (!_ep || !desc || ep->desc | ||
261 | || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
262 | return -EINVAL; | ||
263 | |||
264 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
265 | return -ESHUTDOWN; | ||
266 | |||
267 | max = usb_endpoint_maxp(desc); | ||
268 | |||
269 | /* | ||
270 | * disable HW zero length termination select | ||
271 | * driver handles zero length packet through req->req.zero | ||
272 | */ | ||
273 | zlt = 1; | ||
274 | |||
275 | /* | ||
276 | * sanity check type, direction, address, and then | ||
277 | * initialize the endpoint capabilities fields in dQH | ||
278 | */ | ||
279 | switch (usb_endpoint_type(desc)) { | ||
280 | case USB_ENDPOINT_XFER_CONTROL: | ||
281 | ios = 1; | ||
282 | break; | ||
283 | case USB_ENDPOINT_XFER_BULK: | ||
284 | if ((dev->gadget.speed == USB_SPEED_HIGH | ||
285 | && max != 512) | ||
286 | || (dev->gadget.speed == USB_SPEED_FULL | ||
287 | && max > 64)) { | ||
288 | goto done; | ||
289 | } | ||
290 | break; | ||
291 | case USB_ENDPOINT_XFER_INT: | ||
292 | if (strstr(ep->ep.name, "-iso")) /* bulk is ok */ | ||
293 | goto done; | ||
294 | |||
295 | switch (dev->gadget.speed) { | ||
296 | case USB_SPEED_HIGH: | ||
297 | if (max <= 1024) | ||
298 | break; | ||
299 | case USB_SPEED_FULL: | ||
300 | if (max <= 64) | ||
301 | break; | ||
302 | default: | ||
303 | if (max <= 8) | ||
304 | break; | ||
305 | goto done; | ||
306 | } | ||
307 | break; | ||
308 | case USB_ENDPOINT_XFER_ISOC: | ||
309 | if (strstr(ep->ep.name, "-bulk") | ||
310 | || strstr(ep->ep.name, "-int")) | ||
311 | goto done; | ||
312 | |||
313 | switch (dev->gadget.speed) { | ||
314 | case USB_SPEED_HIGH: | ||
315 | if (max <= 1024) | ||
316 | break; | ||
317 | case USB_SPEED_FULL: | ||
318 | if (max <= 1023) | ||
319 | break; | ||
320 | default: | ||
321 | goto done; | ||
322 | } | ||
323 | /* | ||
324 | * FIXME: | ||
325 | * calculate transactions needed for high bandwidth iso | ||
326 | */ | ||
327 | mult = (unsigned char)(1 + ((max >> 11) & 0x03)); | ||
328 | max = max & 0x8ff; /* bit 0~10 */ | ||
329 | /* 3 transactions at most */ | ||
330 | if (mult > 3) | ||
331 | goto done; | ||
332 | break; | ||
333 | default: | ||
334 | goto done; | ||
335 | } | ||
336 | |||
337 | spin_lock_irqsave(&dev->lock, flags); | ||
338 | |||
339 | ep->ep.maxpacket = max; | ||
340 | ep->desc = desc; | ||
341 | ep->stopped = 0; | ||
342 | ep->ep_num = usb_endpoint_num(desc); | ||
343 | |||
344 | /* ep_type */ | ||
345 | ep->ep_type = usb_endpoint_type(desc); | ||
346 | |||
347 | /* configure endpoint control registers */ | ||
348 | ep_reset(ep, ep->ep_num, is_in(ep), ep->ep_type); | ||
349 | |||
350 | /* configure endpoint capabilities in dQH */ | ||
351 | i = ep->ep_num * 2 + is_in(ep); | ||
352 | ep->dqh = &dev->ep_dqh[i]; | ||
353 | ep->dqh->dqh_ios = ios; | ||
354 | ep->dqh->dqh_mpl = cpu_to_le16(max); | ||
355 | ep->dqh->dqh_zlt = zlt; | ||
356 | ep->dqh->dqh_mult = mult; | ||
357 | ep->dqh->dtd_next = DTD_TERM; | ||
358 | |||
359 | dev_dbg(&dev->pdev->dev, "enabled %s (ep%d%s-%s), max %04x\n", | ||
360 | _ep->name, | ||
361 | ep->ep_num, | ||
362 | DIR_STRING(ep), | ||
363 | type_string(desc), | ||
364 | max); | ||
365 | |||
366 | spin_unlock_irqrestore(&dev->lock, flags); | ||
367 | done: | ||
368 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
369 | return retval; | ||
370 | } | ||
371 | |||
372 | |||
373 | /*-------------------------------------------------------------------------*/ | ||
374 | |||
375 | /* retire a request */ | ||
376 | static void done(struct langwell_ep *ep, struct langwell_request *req, | ||
377 | int status) | ||
378 | { | ||
379 | struct langwell_udc *dev = ep->dev; | ||
380 | unsigned stopped = ep->stopped; | ||
381 | struct langwell_dtd *curr_dtd, *next_dtd; | ||
382 | int i; | ||
383 | |||
384 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
385 | |||
386 | /* remove the req from ep->queue */ | ||
387 | list_del_init(&req->queue); | ||
388 | |||
389 | if (req->req.status == -EINPROGRESS) | ||
390 | req->req.status = status; | ||
391 | else | ||
392 | status = req->req.status; | ||
393 | |||
394 | /* free dTD for the request */ | ||
395 | next_dtd = req->head; | ||
396 | for (i = 0; i < req->dtd_count; i++) { | ||
397 | curr_dtd = next_dtd; | ||
398 | if (i != req->dtd_count - 1) | ||
399 | next_dtd = curr_dtd->next_dtd_virt; | ||
400 | dma_pool_free(dev->dtd_pool, curr_dtd, curr_dtd->dtd_dma); | ||
401 | } | ||
402 | |||
403 | usb_gadget_unmap_request(&dev->gadget, &req->req, is_in(ep)); | ||
404 | |||
405 | if (status != -ESHUTDOWN) | ||
406 | dev_dbg(&dev->pdev->dev, | ||
407 | "complete %s, req %p, stat %d, len %u/%u\n", | ||
408 | ep->ep.name, &req->req, status, | ||
409 | req->req.actual, req->req.length); | ||
410 | |||
411 | /* don't modify queue heads during completion callback */ | ||
412 | ep->stopped = 1; | ||
413 | |||
414 | spin_unlock(&dev->lock); | ||
415 | /* complete routine from gadget driver */ | ||
416 | if (req->req.complete) | ||
417 | req->req.complete(&ep->ep, &req->req); | ||
418 | |||
419 | spin_lock(&dev->lock); | ||
420 | ep->stopped = stopped; | ||
421 | |||
422 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
423 | } | ||
424 | |||
425 | |||
426 | static void langwell_ep_fifo_flush(struct usb_ep *_ep); | ||
427 | |||
428 | /* delete all endpoint requests, called with spinlock held */ | ||
429 | static void nuke(struct langwell_ep *ep, int status) | ||
430 | { | ||
431 | /* called with spinlock held */ | ||
432 | ep->stopped = 1; | ||
433 | |||
434 | /* endpoint fifo flush */ | ||
435 | if (&ep->ep && ep->desc) | ||
436 | langwell_ep_fifo_flush(&ep->ep); | ||
437 | |||
438 | while (!list_empty(&ep->queue)) { | ||
439 | struct langwell_request *req = NULL; | ||
440 | req = list_entry(ep->queue.next, struct langwell_request, | ||
441 | queue); | ||
442 | done(ep, req, status); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | |||
447 | /*-------------------------------------------------------------------------*/ | ||
448 | |||
449 | /* endpoint is no longer usable */ | ||
450 | static int langwell_ep_disable(struct usb_ep *_ep) | ||
451 | { | ||
452 | struct langwell_ep *ep; | ||
453 | unsigned long flags; | ||
454 | struct langwell_udc *dev; | ||
455 | int ep_num; | ||
456 | u32 endptctrl; | ||
457 | |||
458 | ep = container_of(_ep, struct langwell_ep, ep); | ||
459 | dev = ep->dev; | ||
460 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
461 | |||
462 | if (!_ep || !ep->desc) | ||
463 | return -EINVAL; | ||
464 | |||
465 | spin_lock_irqsave(&dev->lock, flags); | ||
466 | |||
467 | /* disable endpoint control register */ | ||
468 | ep_num = ep->ep_num; | ||
469 | endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); | ||
470 | if (is_in(ep)) | ||
471 | endptctrl &= ~EPCTRL_TXE; | ||
472 | else | ||
473 | endptctrl &= ~EPCTRL_RXE; | ||
474 | writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); | ||
475 | |||
476 | /* nuke all pending requests (does flush) */ | ||
477 | nuke(ep, -ESHUTDOWN); | ||
478 | |||
479 | ep->desc = NULL; | ||
480 | ep->ep.desc = NULL; | ||
481 | ep->stopped = 1; | ||
482 | |||
483 | spin_unlock_irqrestore(&dev->lock, flags); | ||
484 | |||
485 | dev_dbg(&dev->pdev->dev, "disabled %s\n", _ep->name); | ||
486 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
487 | |||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | |||
492 | /* allocate a request object to use with this endpoint */ | ||
493 | static struct usb_request *langwell_alloc_request(struct usb_ep *_ep, | ||
494 | gfp_t gfp_flags) | ||
495 | { | ||
496 | struct langwell_ep *ep; | ||
497 | struct langwell_udc *dev; | ||
498 | struct langwell_request *req = NULL; | ||
499 | |||
500 | if (!_ep) | ||
501 | return NULL; | ||
502 | |||
503 | ep = container_of(_ep, struct langwell_ep, ep); | ||
504 | dev = ep->dev; | ||
505 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
506 | |||
507 | req = kzalloc(sizeof(*req), gfp_flags); | ||
508 | if (!req) | ||
509 | return NULL; | ||
510 | |||
511 | req->req.dma = DMA_ADDR_INVALID; | ||
512 | INIT_LIST_HEAD(&req->queue); | ||
513 | |||
514 | dev_vdbg(&dev->pdev->dev, "alloc request for %s\n", _ep->name); | ||
515 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
516 | return &req->req; | ||
517 | } | ||
518 | |||
519 | |||
520 | /* free a request object */ | ||
521 | static void langwell_free_request(struct usb_ep *_ep, | ||
522 | struct usb_request *_req) | ||
523 | { | ||
524 | struct langwell_ep *ep; | ||
525 | struct langwell_udc *dev; | ||
526 | struct langwell_request *req = NULL; | ||
527 | |||
528 | ep = container_of(_ep, struct langwell_ep, ep); | ||
529 | dev = ep->dev; | ||
530 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
531 | |||
532 | if (!_ep || !_req) | ||
533 | return; | ||
534 | |||
535 | req = container_of(_req, struct langwell_request, req); | ||
536 | WARN_ON(!list_empty(&req->queue)); | ||
537 | |||
538 | if (_req) | ||
539 | kfree(req); | ||
540 | |||
541 | dev_vdbg(&dev->pdev->dev, "free request for %s\n", _ep->name); | ||
542 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
543 | } | ||
544 | |||
545 | |||
546 | /*-------------------------------------------------------------------------*/ | ||
547 | |||
548 | /* queue dTD and PRIME endpoint */ | ||
549 | static int queue_dtd(struct langwell_ep *ep, struct langwell_request *req) | ||
550 | { | ||
551 | u32 bit_mask, usbcmd, endptstat, dtd_dma; | ||
552 | u8 dtd_status; | ||
553 | int i; | ||
554 | struct langwell_dqh *dqh; | ||
555 | struct langwell_udc *dev; | ||
556 | |||
557 | dev = ep->dev; | ||
558 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
559 | |||
560 | i = ep->ep_num * 2 + is_in(ep); | ||
561 | dqh = &dev->ep_dqh[i]; | ||
562 | |||
563 | if (ep->ep_num) | ||
564 | dev_vdbg(&dev->pdev->dev, "%s\n", ep->name); | ||
565 | else | ||
566 | /* ep0 */ | ||
567 | dev_vdbg(&dev->pdev->dev, "%s-%s\n", ep->name, DIR_STRING(ep)); | ||
568 | |||
569 | dev_vdbg(&dev->pdev->dev, "ep_dqh[%d] addr: 0x%p\n", | ||
570 | i, &(dev->ep_dqh[i])); | ||
571 | |||
572 | bit_mask = is_in(ep) ? | ||
573 | (1 << (ep->ep_num + 16)) : (1 << (ep->ep_num)); | ||
574 | |||
575 | dev_vdbg(&dev->pdev->dev, "bit_mask = 0x%08x\n", bit_mask); | ||
576 | |||
577 | /* check if the pipe is empty */ | ||
578 | if (!(list_empty(&ep->queue))) { | ||
579 | /* add dTD to the end of linked list */ | ||
580 | struct langwell_request *lastreq; | ||
581 | lastreq = list_entry(ep->queue.prev, | ||
582 | struct langwell_request, queue); | ||
583 | |||
584 | lastreq->tail->dtd_next = | ||
585 | cpu_to_le32(req->head->dtd_dma & DTD_NEXT_MASK); | ||
586 | |||
587 | /* read prime bit, if 1 goto out */ | ||
588 | if (readl(&dev->op_regs->endptprime) & bit_mask) | ||
589 | goto out; | ||
590 | |||
591 | do { | ||
592 | /* set ATDTW bit in USBCMD */ | ||
593 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
594 | writel(usbcmd | CMD_ATDTW, &dev->op_regs->usbcmd); | ||
595 | |||
596 | /* read correct status bit */ | ||
597 | endptstat = readl(&dev->op_regs->endptstat) & bit_mask; | ||
598 | |||
599 | } while (!(readl(&dev->op_regs->usbcmd) & CMD_ATDTW)); | ||
600 | |||
601 | /* write ATDTW bit to 0 */ | ||
602 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
603 | writel(usbcmd & ~CMD_ATDTW, &dev->op_regs->usbcmd); | ||
604 | |||
605 | if (endptstat) | ||
606 | goto out; | ||
607 | } | ||
608 | |||
609 | /* write dQH next pointer and terminate bit to 0 */ | ||
610 | dtd_dma = req->head->dtd_dma & DTD_NEXT_MASK; | ||
611 | dqh->dtd_next = cpu_to_le32(dtd_dma); | ||
612 | |||
613 | /* clear active and halt bit */ | ||
614 | dtd_status = (u8) ~(DTD_STS_ACTIVE | DTD_STS_HALTED); | ||
615 | dqh->dtd_status &= dtd_status; | ||
616 | dev_vdbg(&dev->pdev->dev, "dqh->dtd_status = 0x%x\n", dqh->dtd_status); | ||
617 | |||
618 | /* ensure that updates to the dQH will occur before priming */ | ||
619 | wmb(); | ||
620 | |||
621 | /* write 1 to endptprime register to PRIME endpoint */ | ||
622 | bit_mask = is_in(ep) ? (1 << (ep->ep_num + 16)) : (1 << ep->ep_num); | ||
623 | dev_vdbg(&dev->pdev->dev, "endprime bit_mask = 0x%08x\n", bit_mask); | ||
624 | writel(bit_mask, &dev->op_regs->endptprime); | ||
625 | out: | ||
626 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | |||
631 | /* fill in the dTD structure to build a transfer descriptor */ | ||
632 | static struct langwell_dtd *build_dtd(struct langwell_request *req, | ||
633 | unsigned *length, dma_addr_t *dma, int *is_last) | ||
634 | { | ||
635 | u32 buf_ptr; | ||
636 | struct langwell_dtd *dtd; | ||
637 | struct langwell_udc *dev; | ||
638 | int i; | ||
639 | |||
640 | dev = req->ep->dev; | ||
641 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
642 | |||
643 | /* the maximum transfer length, up to 16k bytes */ | ||
644 | *length = min(req->req.length - req->req.actual, | ||
645 | (unsigned)DTD_MAX_TRANSFER_LENGTH); | ||
646 | |||
647 | /* create dTD dma_pool resource */ | ||
648 | dtd = dma_pool_alloc(dev->dtd_pool, GFP_KERNEL, dma); | ||
649 | if (dtd == NULL) | ||
650 | return dtd; | ||
651 | dtd->dtd_dma = *dma; | ||
652 | |||
653 | /* initialize buffer page pointers */ | ||
654 | buf_ptr = (u32)(req->req.dma + req->req.actual); | ||
655 | for (i = 0; i < 5; i++) | ||
656 | dtd->dtd_buf[i] = cpu_to_le32(buf_ptr + i * PAGE_SIZE); | ||
657 | |||
658 | req->req.actual += *length; | ||
659 | |||
660 | /* fill in total bytes with transfer size */ | ||
661 | dtd->dtd_total = cpu_to_le16(*length); | ||
662 | dev_vdbg(&dev->pdev->dev, "dtd->dtd_total = %d\n", dtd->dtd_total); | ||
663 | |||
664 | /* set is_last flag if req->req.zero is set or not */ | ||
665 | if (req->req.zero) { | ||
666 | if (*length == 0 || (*length % req->ep->ep.maxpacket) != 0) | ||
667 | *is_last = 1; | ||
668 | else | ||
669 | *is_last = 0; | ||
670 | } else if (req->req.length == req->req.actual) { | ||
671 | *is_last = 1; | ||
672 | } else | ||
673 | *is_last = 0; | ||
674 | |||
675 | if (*is_last == 0) | ||
676 | dev_vdbg(&dev->pdev->dev, "multi-dtd request!\n"); | ||
677 | |||
678 | /* set interrupt on complete bit for the last dTD */ | ||
679 | if (*is_last && !req->req.no_interrupt) | ||
680 | dtd->dtd_ioc = 1; | ||
681 | |||
682 | /* set multiplier override 0 for non-ISO and non-TX endpoint */ | ||
683 | dtd->dtd_multo = 0; | ||
684 | |||
685 | /* set the active bit of status field to 1 */ | ||
686 | dtd->dtd_status = DTD_STS_ACTIVE; | ||
687 | dev_vdbg(&dev->pdev->dev, "dtd->dtd_status = 0x%02x\n", | ||
688 | dtd->dtd_status); | ||
689 | |||
690 | dev_vdbg(&dev->pdev->dev, "length = %d, dma addr= 0x%08x\n", | ||
691 | *length, (int)*dma); | ||
692 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
693 | return dtd; | ||
694 | } | ||
695 | |||
696 | |||
697 | /* generate dTD linked list for a request */ | ||
698 | static int req_to_dtd(struct langwell_request *req) | ||
699 | { | ||
700 | unsigned count; | ||
701 | int is_last, is_first = 1; | ||
702 | struct langwell_dtd *dtd, *last_dtd = NULL; | ||
703 | struct langwell_udc *dev; | ||
704 | dma_addr_t dma; | ||
705 | |||
706 | dev = req->ep->dev; | ||
707 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
708 | do { | ||
709 | dtd = build_dtd(req, &count, &dma, &is_last); | ||
710 | if (dtd == NULL) | ||
711 | return -ENOMEM; | ||
712 | |||
713 | if (is_first) { | ||
714 | is_first = 0; | ||
715 | req->head = dtd; | ||
716 | } else { | ||
717 | last_dtd->dtd_next = cpu_to_le32(dma); | ||
718 | last_dtd->next_dtd_virt = dtd; | ||
719 | } | ||
720 | last_dtd = dtd; | ||
721 | req->dtd_count++; | ||
722 | } while (!is_last); | ||
723 | |||
724 | /* set terminate bit to 1 for the last dTD */ | ||
725 | dtd->dtd_next = DTD_TERM; | ||
726 | |||
727 | req->tail = dtd; | ||
728 | |||
729 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
730 | return 0; | ||
731 | } | ||
732 | |||
733 | /*-------------------------------------------------------------------------*/ | ||
734 | |||
735 | /* queue (submits) an I/O requests to an endpoint */ | ||
736 | static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
737 | gfp_t gfp_flags) | ||
738 | { | ||
739 | struct langwell_request *req; | ||
740 | struct langwell_ep *ep; | ||
741 | struct langwell_udc *dev; | ||
742 | unsigned long flags; | ||
743 | int is_iso = 0; | ||
744 | int ret; | ||
745 | |||
746 | /* always require a cpu-view buffer */ | ||
747 | req = container_of(_req, struct langwell_request, req); | ||
748 | ep = container_of(_ep, struct langwell_ep, ep); | ||
749 | |||
750 | if (!_req || !_req->complete || !_req->buf | ||
751 | || !list_empty(&req->queue)) { | ||
752 | return -EINVAL; | ||
753 | } | ||
754 | |||
755 | if (unlikely(!_ep || !ep->desc)) | ||
756 | return -EINVAL; | ||
757 | |||
758 | dev = ep->dev; | ||
759 | req->ep = ep; | ||
760 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
761 | |||
762 | if (usb_endpoint_xfer_isoc(ep->desc)) { | ||
763 | if (req->req.length > ep->ep.maxpacket) | ||
764 | return -EMSGSIZE; | ||
765 | is_iso = 1; | ||
766 | } | ||
767 | |||
768 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) | ||
769 | return -ESHUTDOWN; | ||
770 | |||
771 | /* set up dma mapping */ | ||
772 | ret = usb_gadget_map_request(&dev->gadget, &req->req, is_in(ep)); | ||
773 | if (ret) | ||
774 | return ret; | ||
775 | |||
776 | dev_dbg(&dev->pdev->dev, | ||
777 | "%s queue req %p, len %u, buf %p, dma 0x%08x\n", | ||
778 | _ep->name, | ||
779 | _req, _req->length, _req->buf, (int)_req->dma); | ||
780 | |||
781 | _req->status = -EINPROGRESS; | ||
782 | _req->actual = 0; | ||
783 | req->dtd_count = 0; | ||
784 | |||
785 | spin_lock_irqsave(&dev->lock, flags); | ||
786 | |||
787 | /* build and put dTDs to endpoint queue */ | ||
788 | if (!req_to_dtd(req)) { | ||
789 | queue_dtd(ep, req); | ||
790 | } else { | ||
791 | spin_unlock_irqrestore(&dev->lock, flags); | ||
792 | return -ENOMEM; | ||
793 | } | ||
794 | |||
795 | /* update ep0 state */ | ||
796 | if (ep->ep_num == 0) | ||
797 | dev->ep0_state = DATA_STATE_XMIT; | ||
798 | |||
799 | if (likely(req != NULL)) { | ||
800 | list_add_tail(&req->queue, &ep->queue); | ||
801 | dev_vdbg(&dev->pdev->dev, "list_add_tail()\n"); | ||
802 | } | ||
803 | |||
804 | spin_unlock_irqrestore(&dev->lock, flags); | ||
805 | |||
806 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | |||
811 | /* dequeue (cancels, unlinks) an I/O request from an endpoint */ | ||
812 | static int langwell_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
813 | { | ||
814 | struct langwell_ep *ep; | ||
815 | struct langwell_udc *dev; | ||
816 | struct langwell_request *req; | ||
817 | unsigned long flags; | ||
818 | int stopped, ep_num, retval = 0; | ||
819 | u32 endptctrl; | ||
820 | |||
821 | ep = container_of(_ep, struct langwell_ep, ep); | ||
822 | dev = ep->dev; | ||
823 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
824 | |||
825 | if (!_ep || !ep->desc || !_req) | ||
826 | return -EINVAL; | ||
827 | |||
828 | if (!dev->driver) | ||
829 | return -ESHUTDOWN; | ||
830 | |||
831 | spin_lock_irqsave(&dev->lock, flags); | ||
832 | stopped = ep->stopped; | ||
833 | |||
834 | /* quiesce dma while we patch the queue */ | ||
835 | ep->stopped = 1; | ||
836 | ep_num = ep->ep_num; | ||
837 | |||
838 | /* disable endpoint control register */ | ||
839 | endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); | ||
840 | if (is_in(ep)) | ||
841 | endptctrl &= ~EPCTRL_TXE; | ||
842 | else | ||
843 | endptctrl &= ~EPCTRL_RXE; | ||
844 | writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); | ||
845 | |||
846 | /* make sure it's still queued on this endpoint */ | ||
847 | list_for_each_entry(req, &ep->queue, queue) { | ||
848 | if (&req->req == _req) | ||
849 | break; | ||
850 | } | ||
851 | |||
852 | if (&req->req != _req) { | ||
853 | retval = -EINVAL; | ||
854 | goto done; | ||
855 | } | ||
856 | |||
857 | /* queue head may be partially complete. */ | ||
858 | if (ep->queue.next == &req->queue) { | ||
859 | dev_dbg(&dev->pdev->dev, "unlink (%s) dma\n", _ep->name); | ||
860 | _req->status = -ECONNRESET; | ||
861 | langwell_ep_fifo_flush(&ep->ep); | ||
862 | |||
863 | /* not the last request in endpoint queue */ | ||
864 | if (likely(ep->queue.next == &req->queue)) { | ||
865 | struct langwell_dqh *dqh; | ||
866 | struct langwell_request *next_req; | ||
867 | |||
868 | dqh = ep->dqh; | ||
869 | next_req = list_entry(req->queue.next, | ||
870 | struct langwell_request, queue); | ||
871 | |||
872 | /* point the dQH to the first dTD of next request */ | ||
873 | writel((u32) next_req->head, &dqh->dqh_current); | ||
874 | } | ||
875 | } else { | ||
876 | struct langwell_request *prev_req; | ||
877 | |||
878 | prev_req = list_entry(req->queue.prev, | ||
879 | struct langwell_request, queue); | ||
880 | writel(readl(&req->tail->dtd_next), | ||
881 | &prev_req->tail->dtd_next); | ||
882 | } | ||
883 | |||
884 | done(ep, req, -ECONNRESET); | ||
885 | |||
886 | done: | ||
887 | /* enable endpoint again */ | ||
888 | endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); | ||
889 | if (is_in(ep)) | ||
890 | endptctrl |= EPCTRL_TXE; | ||
891 | else | ||
892 | endptctrl |= EPCTRL_RXE; | ||
893 | writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); | ||
894 | |||
895 | ep->stopped = stopped; | ||
896 | spin_unlock_irqrestore(&dev->lock, flags); | ||
897 | |||
898 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
899 | return retval; | ||
900 | } | ||
901 | |||
902 | |||
903 | /*-------------------------------------------------------------------------*/ | ||
904 | |||
905 | /* endpoint set/clear halt */ | ||
906 | static void ep_set_halt(struct langwell_ep *ep, int value) | ||
907 | { | ||
908 | u32 endptctrl = 0; | ||
909 | int ep_num; | ||
910 | struct langwell_udc *dev = ep->dev; | ||
911 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
912 | |||
913 | ep_num = ep->ep_num; | ||
914 | endptctrl = readl(&dev->op_regs->endptctrl[ep_num]); | ||
915 | |||
916 | /* value: 1 - set halt, 0 - clear halt */ | ||
917 | if (value) { | ||
918 | /* set the stall bit */ | ||
919 | if (is_in(ep)) | ||
920 | endptctrl |= EPCTRL_TXS; | ||
921 | else | ||
922 | endptctrl |= EPCTRL_RXS; | ||
923 | } else { | ||
924 | /* clear the stall bit and reset data toggle */ | ||
925 | if (is_in(ep)) { | ||
926 | endptctrl &= ~EPCTRL_TXS; | ||
927 | endptctrl |= EPCTRL_TXR; | ||
928 | } else { | ||
929 | endptctrl &= ~EPCTRL_RXS; | ||
930 | endptctrl |= EPCTRL_RXR; | ||
931 | } | ||
932 | } | ||
933 | |||
934 | writel(endptctrl, &dev->op_regs->endptctrl[ep_num]); | ||
935 | |||
936 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
937 | } | ||
938 | |||
939 | |||
940 | /* set the endpoint halt feature */ | ||
941 | static int langwell_ep_set_halt(struct usb_ep *_ep, int value) | ||
942 | { | ||
943 | struct langwell_ep *ep; | ||
944 | struct langwell_udc *dev; | ||
945 | unsigned long flags; | ||
946 | int retval = 0; | ||
947 | |||
948 | ep = container_of(_ep, struct langwell_ep, ep); | ||
949 | dev = ep->dev; | ||
950 | |||
951 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
952 | |||
953 | if (!_ep || !ep->desc) | ||
954 | return -EINVAL; | ||
955 | |||
956 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
957 | return -ESHUTDOWN; | ||
958 | |||
959 | if (usb_endpoint_xfer_isoc(ep->desc)) | ||
960 | return -EOPNOTSUPP; | ||
961 | |||
962 | spin_lock_irqsave(&dev->lock, flags); | ||
963 | |||
964 | /* | ||
965 | * attempt to halt IN ep will fail if any transfer requests | ||
966 | * are still queue | ||
967 | */ | ||
968 | if (!list_empty(&ep->queue) && is_in(ep) && value) { | ||
969 | /* IN endpoint FIFO holds bytes */ | ||
970 | dev_dbg(&dev->pdev->dev, "%s FIFO holds bytes\n", _ep->name); | ||
971 | retval = -EAGAIN; | ||
972 | goto done; | ||
973 | } | ||
974 | |||
975 | /* endpoint set/clear halt */ | ||
976 | if (ep->ep_num) { | ||
977 | ep_set_halt(ep, value); | ||
978 | } else { /* endpoint 0 */ | ||
979 | dev->ep0_state = WAIT_FOR_SETUP; | ||
980 | dev->ep0_dir = USB_DIR_OUT; | ||
981 | } | ||
982 | done: | ||
983 | spin_unlock_irqrestore(&dev->lock, flags); | ||
984 | dev_dbg(&dev->pdev->dev, "%s %s halt\n", | ||
985 | _ep->name, value ? "set" : "clear"); | ||
986 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
987 | return retval; | ||
988 | } | ||
989 | |||
990 | |||
991 | /* set the halt feature and ignores clear requests */ | ||
992 | static int langwell_ep_set_wedge(struct usb_ep *_ep) | ||
993 | { | ||
994 | struct langwell_ep *ep; | ||
995 | struct langwell_udc *dev; | ||
996 | |||
997 | ep = container_of(_ep, struct langwell_ep, ep); | ||
998 | dev = ep->dev; | ||
999 | |||
1000 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1001 | |||
1002 | if (!_ep || !ep->desc) | ||
1003 | return -EINVAL; | ||
1004 | |||
1005 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1006 | return usb_ep_set_halt(_ep); | ||
1007 | } | ||
1008 | |||
1009 | |||
1010 | /* flush contents of a fifo */ | ||
1011 | static void langwell_ep_fifo_flush(struct usb_ep *_ep) | ||
1012 | { | ||
1013 | struct langwell_ep *ep; | ||
1014 | struct langwell_udc *dev; | ||
1015 | u32 flush_bit; | ||
1016 | unsigned long timeout; | ||
1017 | |||
1018 | ep = container_of(_ep, struct langwell_ep, ep); | ||
1019 | dev = ep->dev; | ||
1020 | |||
1021 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1022 | |||
1023 | if (!_ep || !ep->desc) { | ||
1024 | dev_vdbg(&dev->pdev->dev, "ep or ep->desc is NULL\n"); | ||
1025 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1026 | return; | ||
1027 | } | ||
1028 | |||
1029 | dev_vdbg(&dev->pdev->dev, "%s-%s fifo flush\n", | ||
1030 | _ep->name, DIR_STRING(ep)); | ||
1031 | |||
1032 | /* flush endpoint buffer */ | ||
1033 | if (ep->ep_num == 0) | ||
1034 | flush_bit = (1 << 16) | 1; | ||
1035 | else if (is_in(ep)) | ||
1036 | flush_bit = 1 << (ep->ep_num + 16); /* TX */ | ||
1037 | else | ||
1038 | flush_bit = 1 << ep->ep_num; /* RX */ | ||
1039 | |||
1040 | /* wait until flush complete */ | ||
1041 | timeout = jiffies + FLUSH_TIMEOUT; | ||
1042 | do { | ||
1043 | writel(flush_bit, &dev->op_regs->endptflush); | ||
1044 | while (readl(&dev->op_regs->endptflush)) { | ||
1045 | if (time_after(jiffies, timeout)) { | ||
1046 | dev_err(&dev->pdev->dev, "ep flush timeout\n"); | ||
1047 | goto done; | ||
1048 | } | ||
1049 | cpu_relax(); | ||
1050 | } | ||
1051 | } while (readl(&dev->op_regs->endptstat) & flush_bit); | ||
1052 | done: | ||
1053 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1054 | } | ||
1055 | |||
1056 | |||
1057 | /* endpoints operations structure */ | ||
1058 | static const struct usb_ep_ops langwell_ep_ops = { | ||
1059 | |||
1060 | /* configure endpoint, making it usable */ | ||
1061 | .enable = langwell_ep_enable, | ||
1062 | |||
1063 | /* endpoint is no longer usable */ | ||
1064 | .disable = langwell_ep_disable, | ||
1065 | |||
1066 | /* allocate a request object to use with this endpoint */ | ||
1067 | .alloc_request = langwell_alloc_request, | ||
1068 | |||
1069 | /* free a request object */ | ||
1070 | .free_request = langwell_free_request, | ||
1071 | |||
1072 | /* queue (submits) an I/O requests to an endpoint */ | ||
1073 | .queue = langwell_ep_queue, | ||
1074 | |||
1075 | /* dequeue (cancels, unlinks) an I/O request from an endpoint */ | ||
1076 | .dequeue = langwell_ep_dequeue, | ||
1077 | |||
1078 | /* set the endpoint halt feature */ | ||
1079 | .set_halt = langwell_ep_set_halt, | ||
1080 | |||
1081 | /* set the halt feature and ignores clear requests */ | ||
1082 | .set_wedge = langwell_ep_set_wedge, | ||
1083 | |||
1084 | /* flush contents of a fifo */ | ||
1085 | .fifo_flush = langwell_ep_fifo_flush, | ||
1086 | }; | ||
1087 | |||
1088 | |||
1089 | /*-------------------------------------------------------------------------*/ | ||
1090 | |||
1091 | /* device controller usb_gadget_ops structure */ | ||
1092 | |||
1093 | /* returns the current frame number */ | ||
1094 | static int langwell_get_frame(struct usb_gadget *_gadget) | ||
1095 | { | ||
1096 | struct langwell_udc *dev; | ||
1097 | u16 retval; | ||
1098 | |||
1099 | if (!_gadget) | ||
1100 | return -ENODEV; | ||
1101 | |||
1102 | dev = container_of(_gadget, struct langwell_udc, gadget); | ||
1103 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1104 | |||
1105 | retval = readl(&dev->op_regs->frindex) & FRINDEX_MASK; | ||
1106 | |||
1107 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1108 | return retval; | ||
1109 | } | ||
1110 | |||
1111 | |||
1112 | /* enter or exit PHY low power state */ | ||
1113 | static void langwell_phy_low_power(struct langwell_udc *dev, bool flag) | ||
1114 | { | ||
1115 | u32 devlc; | ||
1116 | u8 devlc_byte2; | ||
1117 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1118 | |||
1119 | devlc = readl(&dev->op_regs->devlc); | ||
1120 | dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc); | ||
1121 | |||
1122 | if (flag) | ||
1123 | devlc |= LPM_PHCD; | ||
1124 | else | ||
1125 | devlc &= ~LPM_PHCD; | ||
1126 | |||
1127 | /* FIXME: workaround for Langwell A1/A2/A3 sighting */ | ||
1128 | devlc_byte2 = (devlc >> 16) & 0xff; | ||
1129 | writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2); | ||
1130 | |||
1131 | devlc = readl(&dev->op_regs->devlc); | ||
1132 | dev_vdbg(&dev->pdev->dev, | ||
1133 | "%s PHY low power suspend, devlc = 0x%08x\n", | ||
1134 | flag ? "enter" : "exit", devlc); | ||
1135 | } | ||
1136 | |||
1137 | |||
1138 | /* tries to wake up the host connected to this gadget */ | ||
1139 | static int langwell_wakeup(struct usb_gadget *_gadget) | ||
1140 | { | ||
1141 | struct langwell_udc *dev; | ||
1142 | u32 portsc1; | ||
1143 | unsigned long flags; | ||
1144 | |||
1145 | if (!_gadget) | ||
1146 | return 0; | ||
1147 | |||
1148 | dev = container_of(_gadget, struct langwell_udc, gadget); | ||
1149 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1150 | |||
1151 | /* remote wakeup feature not enabled by host */ | ||
1152 | if (!dev->remote_wakeup) { | ||
1153 | dev_info(&dev->pdev->dev, "remote wakeup is disabled\n"); | ||
1154 | return -ENOTSUPP; | ||
1155 | } | ||
1156 | |||
1157 | spin_lock_irqsave(&dev->lock, flags); | ||
1158 | |||
1159 | portsc1 = readl(&dev->op_regs->portsc1); | ||
1160 | if (!(portsc1 & PORTS_SUSP)) { | ||
1161 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1162 | return 0; | ||
1163 | } | ||
1164 | |||
1165 | /* LPM L1 to L0 or legacy remote wakeup */ | ||
1166 | if (dev->lpm && dev->lpm_state == LPM_L1) | ||
1167 | dev_info(&dev->pdev->dev, "LPM L1 to L0 remote wakeup\n"); | ||
1168 | else | ||
1169 | dev_info(&dev->pdev->dev, "device remote wakeup\n"); | ||
1170 | |||
1171 | /* exit PHY low power suspend */ | ||
1172 | if (dev->pdev->device != 0x0829) | ||
1173 | langwell_phy_low_power(dev, 0); | ||
1174 | |||
1175 | /* force port resume */ | ||
1176 | portsc1 |= PORTS_FPR; | ||
1177 | writel(portsc1, &dev->op_regs->portsc1); | ||
1178 | |||
1179 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1180 | |||
1181 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1182 | return 0; | ||
1183 | } | ||
1184 | |||
1185 | |||
1186 | /* notify controller that VBUS is powered or not */ | ||
1187 | static int langwell_vbus_session(struct usb_gadget *_gadget, int is_active) | ||
1188 | { | ||
1189 | struct langwell_udc *dev; | ||
1190 | unsigned long flags; | ||
1191 | u32 usbcmd; | ||
1192 | |||
1193 | if (!_gadget) | ||
1194 | return -ENODEV; | ||
1195 | |||
1196 | dev = container_of(_gadget, struct langwell_udc, gadget); | ||
1197 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1198 | |||
1199 | spin_lock_irqsave(&dev->lock, flags); | ||
1200 | dev_vdbg(&dev->pdev->dev, "VBUS status: %s\n", | ||
1201 | is_active ? "on" : "off"); | ||
1202 | |||
1203 | dev->vbus_active = (is_active != 0); | ||
1204 | if (dev->driver && dev->softconnected && dev->vbus_active) { | ||
1205 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1206 | usbcmd |= CMD_RUNSTOP; | ||
1207 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1208 | } else { | ||
1209 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1210 | usbcmd &= ~CMD_RUNSTOP; | ||
1211 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1212 | } | ||
1213 | |||
1214 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1215 | |||
1216 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1217 | return 0; | ||
1218 | } | ||
1219 | |||
1220 | |||
1221 | /* constrain controller's VBUS power usage */ | ||
1222 | static int langwell_vbus_draw(struct usb_gadget *_gadget, unsigned mA) | ||
1223 | { | ||
1224 | struct langwell_udc *dev; | ||
1225 | |||
1226 | if (!_gadget) | ||
1227 | return -ENODEV; | ||
1228 | |||
1229 | dev = container_of(_gadget, struct langwell_udc, gadget); | ||
1230 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1231 | |||
1232 | if (dev->transceiver) { | ||
1233 | dev_vdbg(&dev->pdev->dev, "usb_phy_set_power\n"); | ||
1234 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1235 | return usb_phy_set_power(dev->transceiver, mA); | ||
1236 | } | ||
1237 | |||
1238 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1239 | return -ENOTSUPP; | ||
1240 | } | ||
1241 | |||
1242 | |||
1243 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | ||
1244 | static int langwell_pullup(struct usb_gadget *_gadget, int is_on) | ||
1245 | { | ||
1246 | struct langwell_udc *dev; | ||
1247 | u32 usbcmd; | ||
1248 | unsigned long flags; | ||
1249 | |||
1250 | if (!_gadget) | ||
1251 | return -ENODEV; | ||
1252 | |||
1253 | dev = container_of(_gadget, struct langwell_udc, gadget); | ||
1254 | |||
1255 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1256 | |||
1257 | spin_lock_irqsave(&dev->lock, flags); | ||
1258 | dev->softconnected = (is_on != 0); | ||
1259 | |||
1260 | if (dev->driver && dev->softconnected && dev->vbus_active) { | ||
1261 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1262 | usbcmd |= CMD_RUNSTOP; | ||
1263 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1264 | } else { | ||
1265 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1266 | usbcmd &= ~CMD_RUNSTOP; | ||
1267 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1268 | } | ||
1269 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1270 | |||
1271 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1272 | return 0; | ||
1273 | } | ||
1274 | |||
1275 | static int langwell_start(struct usb_gadget *g, | ||
1276 | struct usb_gadget_driver *driver); | ||
1277 | |||
1278 | static int langwell_stop(struct usb_gadget *g, | ||
1279 | struct usb_gadget_driver *driver); | ||
1280 | |||
1281 | /* device controller usb_gadget_ops structure */ | ||
1282 | static const struct usb_gadget_ops langwell_ops = { | ||
1283 | |||
1284 | /* returns the current frame number */ | ||
1285 | .get_frame = langwell_get_frame, | ||
1286 | |||
1287 | /* tries to wake up the host connected to this gadget */ | ||
1288 | .wakeup = langwell_wakeup, | ||
1289 | |||
1290 | /* set the device selfpowered feature, always selfpowered */ | ||
1291 | /* .set_selfpowered = langwell_set_selfpowered, */ | ||
1292 | |||
1293 | /* notify controller that VBUS is powered or not */ | ||
1294 | .vbus_session = langwell_vbus_session, | ||
1295 | |||
1296 | /* constrain controller's VBUS power usage */ | ||
1297 | .vbus_draw = langwell_vbus_draw, | ||
1298 | |||
1299 | /* D+ pullup, software-controlled connect/disconnect to USB host */ | ||
1300 | .pullup = langwell_pullup, | ||
1301 | |||
1302 | .udc_start = langwell_start, | ||
1303 | .udc_stop = langwell_stop, | ||
1304 | }; | ||
1305 | |||
1306 | |||
1307 | /*-------------------------------------------------------------------------*/ | ||
1308 | |||
1309 | /* device controller operations */ | ||
1310 | |||
1311 | /* reset device controller */ | ||
1312 | static int langwell_udc_reset(struct langwell_udc *dev) | ||
1313 | { | ||
1314 | u32 usbcmd, usbmode, devlc, endpointlistaddr; | ||
1315 | u8 devlc_byte0, devlc_byte2; | ||
1316 | unsigned long timeout; | ||
1317 | |||
1318 | if (!dev) | ||
1319 | return -EINVAL; | ||
1320 | |||
1321 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1322 | |||
1323 | /* set controller to stop state */ | ||
1324 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1325 | usbcmd &= ~CMD_RUNSTOP; | ||
1326 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1327 | |||
1328 | /* reset device controller */ | ||
1329 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1330 | usbcmd |= CMD_RST; | ||
1331 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1332 | |||
1333 | /* wait for reset to complete */ | ||
1334 | timeout = jiffies + RESET_TIMEOUT; | ||
1335 | while (readl(&dev->op_regs->usbcmd) & CMD_RST) { | ||
1336 | if (time_after(jiffies, timeout)) { | ||
1337 | dev_err(&dev->pdev->dev, "device reset timeout\n"); | ||
1338 | return -ETIMEDOUT; | ||
1339 | } | ||
1340 | cpu_relax(); | ||
1341 | } | ||
1342 | |||
1343 | /* set controller to device mode */ | ||
1344 | usbmode = readl(&dev->op_regs->usbmode); | ||
1345 | usbmode |= MODE_DEVICE; | ||
1346 | |||
1347 | /* turn setup lockout off, require setup tripwire in usbcmd */ | ||
1348 | usbmode |= MODE_SLOM; | ||
1349 | |||
1350 | writel(usbmode, &dev->op_regs->usbmode); | ||
1351 | usbmode = readl(&dev->op_regs->usbmode); | ||
1352 | dev_vdbg(&dev->pdev->dev, "usbmode=0x%08x\n", usbmode); | ||
1353 | |||
1354 | /* Write-Clear setup status */ | ||
1355 | writel(0, &dev->op_regs->usbsts); | ||
1356 | |||
1357 | /* if support USB LPM, ACK all LPM token */ | ||
1358 | if (dev->lpm) { | ||
1359 | devlc = readl(&dev->op_regs->devlc); | ||
1360 | dev_vdbg(&dev->pdev->dev, "devlc = 0x%08x\n", devlc); | ||
1361 | /* FIXME: workaround for Langwell A1/A2/A3 sighting */ | ||
1362 | devlc &= ~LPM_STL; /* don't STALL LPM token */ | ||
1363 | devlc &= ~LPM_NYT_ACK; /* ACK LPM token */ | ||
1364 | devlc_byte0 = devlc & 0xff; | ||
1365 | devlc_byte2 = (devlc >> 16) & 0xff; | ||
1366 | writeb(devlc_byte0, (u8 *)&dev->op_regs->devlc); | ||
1367 | writeb(devlc_byte2, (u8 *)&dev->op_regs->devlc + 2); | ||
1368 | devlc = readl(&dev->op_regs->devlc); | ||
1369 | dev_vdbg(&dev->pdev->dev, | ||
1370 | "ACK LPM token, devlc = 0x%08x\n", devlc); | ||
1371 | } | ||
1372 | |||
1373 | /* fill endpointlistaddr register */ | ||
1374 | endpointlistaddr = dev->ep_dqh_dma; | ||
1375 | endpointlistaddr &= ENDPOINTLISTADDR_MASK; | ||
1376 | writel(endpointlistaddr, &dev->op_regs->endpointlistaddr); | ||
1377 | |||
1378 | dev_vdbg(&dev->pdev->dev, | ||
1379 | "dQH base (vir: %p, phy: 0x%08x), endpointlistaddr=0x%08x\n", | ||
1380 | dev->ep_dqh, endpointlistaddr, | ||
1381 | readl(&dev->op_regs->endpointlistaddr)); | ||
1382 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1383 | return 0; | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | /* reinitialize device controller endpoints */ | ||
1388 | static int eps_reinit(struct langwell_udc *dev) | ||
1389 | { | ||
1390 | struct langwell_ep *ep; | ||
1391 | char name[14]; | ||
1392 | int i; | ||
1393 | |||
1394 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1395 | |||
1396 | /* initialize ep0 */ | ||
1397 | ep = &dev->ep[0]; | ||
1398 | ep->dev = dev; | ||
1399 | strncpy(ep->name, "ep0", sizeof(ep->name)); | ||
1400 | ep->ep.name = ep->name; | ||
1401 | ep->ep.ops = &langwell_ep_ops; | ||
1402 | ep->stopped = 0; | ||
1403 | ep->ep.maxpacket = EP0_MAX_PKT_SIZE; | ||
1404 | ep->ep_num = 0; | ||
1405 | ep->desc = &langwell_ep0_desc; | ||
1406 | INIT_LIST_HEAD(&ep->queue); | ||
1407 | |||
1408 | ep->ep_type = USB_ENDPOINT_XFER_CONTROL; | ||
1409 | |||
1410 | /* initialize other endpoints */ | ||
1411 | for (i = 2; i < dev->ep_max; i++) { | ||
1412 | ep = &dev->ep[i]; | ||
1413 | if (i % 2) | ||
1414 | snprintf(name, sizeof(name), "ep%din", i / 2); | ||
1415 | else | ||
1416 | snprintf(name, sizeof(name), "ep%dout", i / 2); | ||
1417 | ep->dev = dev; | ||
1418 | strncpy(ep->name, name, sizeof(ep->name)); | ||
1419 | ep->ep.name = ep->name; | ||
1420 | |||
1421 | ep->ep.ops = &langwell_ep_ops; | ||
1422 | ep->stopped = 0; | ||
1423 | ep->ep.maxpacket = (unsigned short) ~0; | ||
1424 | ep->ep_num = i / 2; | ||
1425 | |||
1426 | INIT_LIST_HEAD(&ep->queue); | ||
1427 | list_add_tail(&ep->ep.ep_list, &dev->gadget.ep_list); | ||
1428 | } | ||
1429 | |||
1430 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1431 | return 0; | ||
1432 | } | ||
1433 | |||
1434 | |||
1435 | /* enable interrupt and set controller to run state */ | ||
1436 | static void langwell_udc_start(struct langwell_udc *dev) | ||
1437 | { | ||
1438 | u32 usbintr, usbcmd; | ||
1439 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1440 | |||
1441 | /* enable interrupts */ | ||
1442 | usbintr = INTR_ULPIE /* ULPI */ | ||
1443 | | INTR_SLE /* suspend */ | ||
1444 | /* | INTR_SRE SOF received */ | ||
1445 | | INTR_URE /* USB reset */ | ||
1446 | | INTR_AAE /* async advance */ | ||
1447 | | INTR_SEE /* system error */ | ||
1448 | | INTR_FRE /* frame list rollover */ | ||
1449 | | INTR_PCE /* port change detect */ | ||
1450 | | INTR_UEE /* USB error interrupt */ | ||
1451 | | INTR_UE; /* USB interrupt */ | ||
1452 | writel(usbintr, &dev->op_regs->usbintr); | ||
1453 | |||
1454 | /* clear stopped bit */ | ||
1455 | dev->stopped = 0; | ||
1456 | |||
1457 | /* set controller to run */ | ||
1458 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1459 | usbcmd |= CMD_RUNSTOP; | ||
1460 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1461 | |||
1462 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1463 | } | ||
1464 | |||
1465 | |||
1466 | /* disable interrupt and set controller to stop state */ | ||
1467 | static void langwell_udc_stop(struct langwell_udc *dev) | ||
1468 | { | ||
1469 | u32 usbcmd; | ||
1470 | |||
1471 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1472 | |||
1473 | /* disable all interrupts */ | ||
1474 | writel(0, &dev->op_regs->usbintr); | ||
1475 | |||
1476 | /* set stopped bit */ | ||
1477 | dev->stopped = 1; | ||
1478 | |||
1479 | /* set controller to stop state */ | ||
1480 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1481 | usbcmd &= ~CMD_RUNSTOP; | ||
1482 | writel(usbcmd, &dev->op_regs->usbcmd); | ||
1483 | |||
1484 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1485 | } | ||
1486 | |||
1487 | |||
1488 | /* stop all USB activities */ | ||
1489 | static void stop_activity(struct langwell_udc *dev) | ||
1490 | { | ||
1491 | struct langwell_ep *ep; | ||
1492 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1493 | |||
1494 | nuke(&dev->ep[0], -ESHUTDOWN); | ||
1495 | |||
1496 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { | ||
1497 | nuke(ep, -ESHUTDOWN); | ||
1498 | } | ||
1499 | |||
1500 | /* report disconnect; the driver is already quiesced */ | ||
1501 | if (dev->driver) { | ||
1502 | spin_unlock(&dev->lock); | ||
1503 | dev->driver->disconnect(&dev->gadget); | ||
1504 | spin_lock(&dev->lock); | ||
1505 | } | ||
1506 | |||
1507 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1508 | } | ||
1509 | |||
1510 | |||
1511 | /*-------------------------------------------------------------------------*/ | ||
1512 | |||
1513 | /* device "function" sysfs attribute file */ | ||
1514 | static ssize_t show_function(struct device *_dev, | ||
1515 | struct device_attribute *attr, char *buf) | ||
1516 | { | ||
1517 | struct langwell_udc *dev = dev_get_drvdata(_dev); | ||
1518 | |||
1519 | if (!dev->driver || !dev->driver->function | ||
1520 | || strlen(dev->driver->function) > PAGE_SIZE) | ||
1521 | return 0; | ||
1522 | |||
1523 | return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function); | ||
1524 | } | ||
1525 | static DEVICE_ATTR(function, S_IRUGO, show_function, NULL); | ||
1526 | |||
1527 | |||
1528 | static inline enum usb_device_speed lpm_device_speed(u32 reg) | ||
1529 | { | ||
1530 | switch (LPM_PSPD(reg)) { | ||
1531 | case LPM_SPEED_HIGH: | ||
1532 | return USB_SPEED_HIGH; | ||
1533 | case LPM_SPEED_FULL: | ||
1534 | return USB_SPEED_FULL; | ||
1535 | case LPM_SPEED_LOW: | ||
1536 | return USB_SPEED_LOW; | ||
1537 | default: | ||
1538 | return USB_SPEED_UNKNOWN; | ||
1539 | } | ||
1540 | } | ||
1541 | |||
1542 | /* device "langwell_udc" sysfs attribute file */ | ||
1543 | static ssize_t show_langwell_udc(struct device *_dev, | ||
1544 | struct device_attribute *attr, char *buf) | ||
1545 | { | ||
1546 | struct langwell_udc *dev = dev_get_drvdata(_dev); | ||
1547 | struct langwell_request *req; | ||
1548 | struct langwell_ep *ep = NULL; | ||
1549 | char *next; | ||
1550 | unsigned size; | ||
1551 | unsigned t; | ||
1552 | unsigned i; | ||
1553 | unsigned long flags; | ||
1554 | u32 tmp_reg; | ||
1555 | |||
1556 | next = buf; | ||
1557 | size = PAGE_SIZE; | ||
1558 | spin_lock_irqsave(&dev->lock, flags); | ||
1559 | |||
1560 | /* driver basic information */ | ||
1561 | t = scnprintf(next, size, | ||
1562 | DRIVER_DESC "\n" | ||
1563 | "%s version: %s\n" | ||
1564 | "Gadget driver: %s\n\n", | ||
1565 | driver_name, DRIVER_VERSION, | ||
1566 | dev->driver ? dev->driver->driver.name : "(none)"); | ||
1567 | size -= t; | ||
1568 | next += t; | ||
1569 | |||
1570 | /* device registers */ | ||
1571 | tmp_reg = readl(&dev->op_regs->usbcmd); | ||
1572 | t = scnprintf(next, size, | ||
1573 | "USBCMD reg:\n" | ||
1574 | "SetupTW: %d\n" | ||
1575 | "Run/Stop: %s\n\n", | ||
1576 | (tmp_reg & CMD_SUTW) ? 1 : 0, | ||
1577 | (tmp_reg & CMD_RUNSTOP) ? "Run" : "Stop"); | ||
1578 | size -= t; | ||
1579 | next += t; | ||
1580 | |||
1581 | tmp_reg = readl(&dev->op_regs->usbsts); | ||
1582 | t = scnprintf(next, size, | ||
1583 | "USB Status Reg:\n" | ||
1584 | "Device Suspend: %d\n" | ||
1585 | "Reset Received: %d\n" | ||
1586 | "System Error: %s\n" | ||
1587 | "USB Error Interrupt: %s\n\n", | ||
1588 | (tmp_reg & STS_SLI) ? 1 : 0, | ||
1589 | (tmp_reg & STS_URI) ? 1 : 0, | ||
1590 | (tmp_reg & STS_SEI) ? "Error" : "No error", | ||
1591 | (tmp_reg & STS_UEI) ? "Error detected" : "No error"); | ||
1592 | size -= t; | ||
1593 | next += t; | ||
1594 | |||
1595 | tmp_reg = readl(&dev->op_regs->usbintr); | ||
1596 | t = scnprintf(next, size, | ||
1597 | "USB Intrrupt Enable Reg:\n" | ||
1598 | "Sleep Enable: %d\n" | ||
1599 | "SOF Received Enable: %d\n" | ||
1600 | "Reset Enable: %d\n" | ||
1601 | "System Error Enable: %d\n" | ||
1602 | "Port Change Dectected Enable: %d\n" | ||
1603 | "USB Error Intr Enable: %d\n" | ||
1604 | "USB Intr Enable: %d\n\n", | ||
1605 | (tmp_reg & INTR_SLE) ? 1 : 0, | ||
1606 | (tmp_reg & INTR_SRE) ? 1 : 0, | ||
1607 | (tmp_reg & INTR_URE) ? 1 : 0, | ||
1608 | (tmp_reg & INTR_SEE) ? 1 : 0, | ||
1609 | (tmp_reg & INTR_PCE) ? 1 : 0, | ||
1610 | (tmp_reg & INTR_UEE) ? 1 : 0, | ||
1611 | (tmp_reg & INTR_UE) ? 1 : 0); | ||
1612 | size -= t; | ||
1613 | next += t; | ||
1614 | |||
1615 | tmp_reg = readl(&dev->op_regs->frindex); | ||
1616 | t = scnprintf(next, size, | ||
1617 | "USB Frame Index Reg:\n" | ||
1618 | "Frame Number is 0x%08x\n\n", | ||
1619 | (tmp_reg & FRINDEX_MASK)); | ||
1620 | size -= t; | ||
1621 | next += t; | ||
1622 | |||
1623 | tmp_reg = readl(&dev->op_regs->deviceaddr); | ||
1624 | t = scnprintf(next, size, | ||
1625 | "USB Device Address Reg:\n" | ||
1626 | "Device Addr is 0x%x\n\n", | ||
1627 | USBADR(tmp_reg)); | ||
1628 | size -= t; | ||
1629 | next += t; | ||
1630 | |||
1631 | tmp_reg = readl(&dev->op_regs->endpointlistaddr); | ||
1632 | t = scnprintf(next, size, | ||
1633 | "USB Endpoint List Address Reg:\n" | ||
1634 | "Endpoint List Pointer is 0x%x\n\n", | ||
1635 | EPBASE(tmp_reg)); | ||
1636 | size -= t; | ||
1637 | next += t; | ||
1638 | |||
1639 | tmp_reg = readl(&dev->op_regs->portsc1); | ||
1640 | t = scnprintf(next, size, | ||
1641 | "USB Port Status & Control Reg:\n" | ||
1642 | "Port Reset: %s\n" | ||
1643 | "Port Suspend Mode: %s\n" | ||
1644 | "Over-current Change: %s\n" | ||
1645 | "Port Enable/Disable Change: %s\n" | ||
1646 | "Port Enabled/Disabled: %s\n" | ||
1647 | "Current Connect Status: %s\n" | ||
1648 | "LPM Suspend Status: %s\n\n", | ||
1649 | (tmp_reg & PORTS_PR) ? "Reset" : "Not Reset", | ||
1650 | (tmp_reg & PORTS_SUSP) ? "Suspend " : "Not Suspend", | ||
1651 | (tmp_reg & PORTS_OCC) ? "Detected" : "No", | ||
1652 | (tmp_reg & PORTS_PEC) ? "Changed" : "Not Changed", | ||
1653 | (tmp_reg & PORTS_PE) ? "Enable" : "Not Correct", | ||
1654 | (tmp_reg & PORTS_CCS) ? "Attached" : "Not Attached", | ||
1655 | (tmp_reg & PORTS_SLP) ? "LPM L1" : "LPM L0"); | ||
1656 | size -= t; | ||
1657 | next += t; | ||
1658 | |||
1659 | tmp_reg = readl(&dev->op_regs->devlc); | ||
1660 | t = scnprintf(next, size, | ||
1661 | "Device LPM Control Reg:\n" | ||
1662 | "Parallel Transceiver : %d\n" | ||
1663 | "Serial Transceiver : %d\n" | ||
1664 | "Port Speed: %s\n" | ||
1665 | "Port Force Full Speed Connenct: %s\n" | ||
1666 | "PHY Low Power Suspend Clock: %s\n" | ||
1667 | "BmAttributes: %d\n\n", | ||
1668 | LPM_PTS(tmp_reg), | ||
1669 | (tmp_reg & LPM_STS) ? 1 : 0, | ||
1670 | usb_speed_string(lpm_device_speed(tmp_reg)), | ||
1671 | (tmp_reg & LPM_PFSC) ? "Force Full Speed" : "Not Force", | ||
1672 | (tmp_reg & LPM_PHCD) ? "Disabled" : "Enabled", | ||
1673 | LPM_BA(tmp_reg)); | ||
1674 | size -= t; | ||
1675 | next += t; | ||
1676 | |||
1677 | tmp_reg = readl(&dev->op_regs->usbmode); | ||
1678 | t = scnprintf(next, size, | ||
1679 | "USB Mode Reg:\n" | ||
1680 | "Controller Mode is : %s\n\n", ({ | ||
1681 | char *s; | ||
1682 | switch (MODE_CM(tmp_reg)) { | ||
1683 | case MODE_IDLE: | ||
1684 | s = "Idle"; break; | ||
1685 | case MODE_DEVICE: | ||
1686 | s = "Device Controller"; break; | ||
1687 | case MODE_HOST: | ||
1688 | s = "Host Controller"; break; | ||
1689 | default: | ||
1690 | s = "None"; break; | ||
1691 | } | ||
1692 | s; | ||
1693 | })); | ||
1694 | size -= t; | ||
1695 | next += t; | ||
1696 | |||
1697 | tmp_reg = readl(&dev->op_regs->endptsetupstat); | ||
1698 | t = scnprintf(next, size, | ||
1699 | "Endpoint Setup Status Reg:\n" | ||
1700 | "SETUP on ep 0x%04x\n\n", | ||
1701 | tmp_reg & SETUPSTAT_MASK); | ||
1702 | size -= t; | ||
1703 | next += t; | ||
1704 | |||
1705 | for (i = 0; i < dev->ep_max / 2; i++) { | ||
1706 | tmp_reg = readl(&dev->op_regs->endptctrl[i]); | ||
1707 | t = scnprintf(next, size, "EP Ctrl Reg [%d]: 0x%08x\n", | ||
1708 | i, tmp_reg); | ||
1709 | size -= t; | ||
1710 | next += t; | ||
1711 | } | ||
1712 | tmp_reg = readl(&dev->op_regs->endptprime); | ||
1713 | t = scnprintf(next, size, "EP Prime Reg: 0x%08x\n\n", tmp_reg); | ||
1714 | size -= t; | ||
1715 | next += t; | ||
1716 | |||
1717 | /* langwell_udc, langwell_ep, langwell_request structure information */ | ||
1718 | ep = &dev->ep[0]; | ||
1719 | t = scnprintf(next, size, "%s MaxPacketSize: 0x%x, ep_num: %d\n", | ||
1720 | ep->ep.name, ep->ep.maxpacket, ep->ep_num); | ||
1721 | size -= t; | ||
1722 | next += t; | ||
1723 | |||
1724 | if (list_empty(&ep->queue)) { | ||
1725 | t = scnprintf(next, size, "its req queue is empty\n\n"); | ||
1726 | size -= t; | ||
1727 | next += t; | ||
1728 | } else { | ||
1729 | list_for_each_entry(req, &ep->queue, queue) { | ||
1730 | t = scnprintf(next, size, | ||
1731 | "req %p actual 0x%x length 0x%x buf %p\n", | ||
1732 | &req->req, req->req.actual, | ||
1733 | req->req.length, req->req.buf); | ||
1734 | size -= t; | ||
1735 | next += t; | ||
1736 | } | ||
1737 | } | ||
1738 | /* other gadget->eplist ep */ | ||
1739 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { | ||
1740 | if (ep->desc) { | ||
1741 | t = scnprintf(next, size, | ||
1742 | "\n%s MaxPacketSize: 0x%x, " | ||
1743 | "ep_num: %d\n", | ||
1744 | ep->ep.name, ep->ep.maxpacket, | ||
1745 | ep->ep_num); | ||
1746 | size -= t; | ||
1747 | next += t; | ||
1748 | |||
1749 | if (list_empty(&ep->queue)) { | ||
1750 | t = scnprintf(next, size, | ||
1751 | "its req queue is empty\n\n"); | ||
1752 | size -= t; | ||
1753 | next += t; | ||
1754 | } else { | ||
1755 | list_for_each_entry(req, &ep->queue, queue) { | ||
1756 | t = scnprintf(next, size, | ||
1757 | "req %p actual 0x%x length " | ||
1758 | "0x%x buf %p\n", | ||
1759 | &req->req, req->req.actual, | ||
1760 | req->req.length, req->req.buf); | ||
1761 | size -= t; | ||
1762 | next += t; | ||
1763 | } | ||
1764 | } | ||
1765 | } | ||
1766 | } | ||
1767 | |||
1768 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1769 | return PAGE_SIZE - size; | ||
1770 | } | ||
1771 | static DEVICE_ATTR(langwell_udc, S_IRUGO, show_langwell_udc, NULL); | ||
1772 | |||
1773 | |||
1774 | /* device "remote_wakeup" sysfs attribute file */ | ||
1775 | static ssize_t store_remote_wakeup(struct device *_dev, | ||
1776 | struct device_attribute *attr, const char *buf, size_t count) | ||
1777 | { | ||
1778 | struct langwell_udc *dev = dev_get_drvdata(_dev); | ||
1779 | unsigned long flags; | ||
1780 | ssize_t rc = count; | ||
1781 | |||
1782 | if (count > 2) | ||
1783 | return -EINVAL; | ||
1784 | |||
1785 | if (count > 0 && buf[count-1] == '\n') | ||
1786 | ((char *) buf)[count-1] = 0; | ||
1787 | |||
1788 | if (buf[0] != '1') | ||
1789 | return -EINVAL; | ||
1790 | |||
1791 | /* force remote wakeup enabled in case gadget driver doesn't support */ | ||
1792 | spin_lock_irqsave(&dev->lock, flags); | ||
1793 | dev->remote_wakeup = 1; | ||
1794 | dev->dev_status |= (1 << USB_DEVICE_REMOTE_WAKEUP); | ||
1795 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1796 | |||
1797 | langwell_wakeup(&dev->gadget); | ||
1798 | |||
1799 | return rc; | ||
1800 | } | ||
1801 | static DEVICE_ATTR(remote_wakeup, S_IWUSR, NULL, store_remote_wakeup); | ||
1802 | |||
1803 | |||
1804 | /*-------------------------------------------------------------------------*/ | ||
1805 | |||
1806 | /* | ||
1807 | * when a driver is successfully registered, it will receive | ||
1808 | * control requests including set_configuration(), which enables | ||
1809 | * non-control requests. then usb traffic follows until a | ||
1810 | * disconnect is reported. then a host may connect again, or | ||
1811 | * the driver might get unbound. | ||
1812 | */ | ||
1813 | |||
1814 | static int langwell_start(struct usb_gadget *g, | ||
1815 | struct usb_gadget_driver *driver) | ||
1816 | { | ||
1817 | struct langwell_udc *dev = gadget_to_langwell(g); | ||
1818 | unsigned long flags; | ||
1819 | int retval; | ||
1820 | |||
1821 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1822 | |||
1823 | spin_lock_irqsave(&dev->lock, flags); | ||
1824 | |||
1825 | /* hook up the driver ... */ | ||
1826 | driver->driver.bus = NULL; | ||
1827 | dev->driver = driver; | ||
1828 | dev->gadget.dev.driver = &driver->driver; | ||
1829 | |||
1830 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1831 | |||
1832 | retval = device_create_file(&dev->pdev->dev, &dev_attr_function); | ||
1833 | if (retval) | ||
1834 | goto err; | ||
1835 | |||
1836 | dev->usb_state = USB_STATE_ATTACHED; | ||
1837 | dev->ep0_state = WAIT_FOR_SETUP; | ||
1838 | dev->ep0_dir = USB_DIR_OUT; | ||
1839 | |||
1840 | /* enable interrupt and set controller to run state */ | ||
1841 | if (dev->got_irq) | ||
1842 | langwell_udc_start(dev); | ||
1843 | |||
1844 | dev_vdbg(&dev->pdev->dev, | ||
1845 | "After langwell_udc_start(), print all registers:\n"); | ||
1846 | print_all_registers(dev); | ||
1847 | |||
1848 | dev_info(&dev->pdev->dev, "register driver: %s\n", | ||
1849 | driver->driver.name); | ||
1850 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1851 | |||
1852 | return 0; | ||
1853 | |||
1854 | err: | ||
1855 | dev->gadget.dev.driver = NULL; | ||
1856 | dev->driver = NULL; | ||
1857 | |||
1858 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1859 | |||
1860 | return retval; | ||
1861 | } | ||
1862 | |||
1863 | /* unregister gadget driver */ | ||
1864 | static int langwell_stop(struct usb_gadget *g, | ||
1865 | struct usb_gadget_driver *driver) | ||
1866 | { | ||
1867 | struct langwell_udc *dev = gadget_to_langwell(g); | ||
1868 | unsigned long flags; | ||
1869 | |||
1870 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1871 | |||
1872 | /* exit PHY low power suspend */ | ||
1873 | if (dev->pdev->device != 0x0829) | ||
1874 | langwell_phy_low_power(dev, 0); | ||
1875 | |||
1876 | /* unbind OTG transceiver */ | ||
1877 | if (dev->transceiver) | ||
1878 | (void)otg_set_peripheral(dev->transceiver->otg, 0); | ||
1879 | |||
1880 | /* disable interrupt and set controller to stop state */ | ||
1881 | langwell_udc_stop(dev); | ||
1882 | |||
1883 | dev->usb_state = USB_STATE_ATTACHED; | ||
1884 | dev->ep0_state = WAIT_FOR_SETUP; | ||
1885 | dev->ep0_dir = USB_DIR_OUT; | ||
1886 | |||
1887 | spin_lock_irqsave(&dev->lock, flags); | ||
1888 | |||
1889 | /* stop all usb activities */ | ||
1890 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
1891 | dev->gadget.dev.driver = NULL; | ||
1892 | dev->driver = NULL; | ||
1893 | stop_activity(dev); | ||
1894 | spin_unlock_irqrestore(&dev->lock, flags); | ||
1895 | |||
1896 | device_remove_file(&dev->pdev->dev, &dev_attr_function); | ||
1897 | |||
1898 | dev_info(&dev->pdev->dev, "unregistered driver '%s'\n", | ||
1899 | driver->driver.name); | ||
1900 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1901 | |||
1902 | return 0; | ||
1903 | } | ||
1904 | |||
1905 | /*-------------------------------------------------------------------------*/ | ||
1906 | |||
1907 | /* | ||
1908 | * setup tripwire is used as a semaphore to ensure that the setup data | ||
1909 | * payload is extracted from a dQH without being corrupted | ||
1910 | */ | ||
1911 | static void setup_tripwire(struct langwell_udc *dev) | ||
1912 | { | ||
1913 | u32 usbcmd, | ||
1914 | endptsetupstat; | ||
1915 | unsigned long timeout; | ||
1916 | struct langwell_dqh *dqh; | ||
1917 | |||
1918 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1919 | |||
1920 | /* ep0 OUT dQH */ | ||
1921 | dqh = &dev->ep_dqh[EP_DIR_OUT]; | ||
1922 | |||
1923 | /* Write-Clear endptsetupstat */ | ||
1924 | endptsetupstat = readl(&dev->op_regs->endptsetupstat); | ||
1925 | writel(endptsetupstat, &dev->op_regs->endptsetupstat); | ||
1926 | |||
1927 | /* wait until endptsetupstat is cleared */ | ||
1928 | timeout = jiffies + SETUPSTAT_TIMEOUT; | ||
1929 | while (readl(&dev->op_regs->endptsetupstat)) { | ||
1930 | if (time_after(jiffies, timeout)) { | ||
1931 | dev_err(&dev->pdev->dev, "setup_tripwire timeout\n"); | ||
1932 | break; | ||
1933 | } | ||
1934 | cpu_relax(); | ||
1935 | } | ||
1936 | |||
1937 | /* while a hazard exists when setup packet arrives */ | ||
1938 | do { | ||
1939 | /* set setup tripwire bit */ | ||
1940 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1941 | writel(usbcmd | CMD_SUTW, &dev->op_regs->usbcmd); | ||
1942 | |||
1943 | /* copy the setup packet to local buffer */ | ||
1944 | memcpy(&dev->local_setup_buff, &dqh->dqh_setup, 8); | ||
1945 | } while (!(readl(&dev->op_regs->usbcmd) & CMD_SUTW)); | ||
1946 | |||
1947 | /* Write-Clear setup tripwire bit */ | ||
1948 | usbcmd = readl(&dev->op_regs->usbcmd); | ||
1949 | writel(usbcmd & ~CMD_SUTW, &dev->op_regs->usbcmd); | ||
1950 | |||
1951 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1952 | } | ||
1953 | |||
1954 | |||
1955 | /* protocol ep0 stall, will automatically be cleared on new transaction */ | ||
1956 | static void ep0_stall(struct langwell_udc *dev) | ||
1957 | { | ||
1958 | u32 endptctrl; | ||
1959 | |||
1960 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1961 | |||
1962 | /* set TX and RX to stall */ | ||
1963 | endptctrl = readl(&dev->op_regs->endptctrl[0]); | ||
1964 | endptctrl |= EPCTRL_TXS | EPCTRL_RXS; | ||
1965 | writel(endptctrl, &dev->op_regs->endptctrl[0]); | ||
1966 | |||
1967 | /* update ep0 state */ | ||
1968 | dev->ep0_state = WAIT_FOR_SETUP; | ||
1969 | dev->ep0_dir = USB_DIR_OUT; | ||
1970 | |||
1971 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
1972 | } | ||
1973 | |||
1974 | |||
1975 | /* PRIME a status phase for ep0 */ | ||
1976 | static int prime_status_phase(struct langwell_udc *dev, int dir) | ||
1977 | { | ||
1978 | struct langwell_request *req; | ||
1979 | struct langwell_ep *ep; | ||
1980 | int status = 0; | ||
1981 | |||
1982 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
1983 | |||
1984 | if (dir == EP_DIR_IN) | ||
1985 | dev->ep0_dir = USB_DIR_IN; | ||
1986 | else | ||
1987 | dev->ep0_dir = USB_DIR_OUT; | ||
1988 | |||
1989 | ep = &dev->ep[0]; | ||
1990 | dev->ep0_state = WAIT_FOR_OUT_STATUS; | ||
1991 | |||
1992 | req = dev->status_req; | ||
1993 | |||
1994 | req->ep = ep; | ||
1995 | req->req.length = 0; | ||
1996 | req->req.status = -EINPROGRESS; | ||
1997 | req->req.actual = 0; | ||
1998 | req->req.complete = NULL; | ||
1999 | req->dtd_count = 0; | ||
2000 | |||
2001 | if (!req_to_dtd(req)) | ||
2002 | status = queue_dtd(ep, req); | ||
2003 | else | ||
2004 | return -ENOMEM; | ||
2005 | |||
2006 | if (status) | ||
2007 | dev_err(&dev->pdev->dev, "can't queue ep0 status request\n"); | ||
2008 | |||
2009 | list_add_tail(&req->queue, &ep->queue); | ||
2010 | |||
2011 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2012 | return status; | ||
2013 | } | ||
2014 | |||
2015 | |||
2016 | /* SET_ADDRESS request routine */ | ||
2017 | static void set_address(struct langwell_udc *dev, u16 value, | ||
2018 | u16 index, u16 length) | ||
2019 | { | ||
2020 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2021 | |||
2022 | /* save the new address to device struct */ | ||
2023 | dev->dev_addr = (u8) value; | ||
2024 | dev_vdbg(&dev->pdev->dev, "dev->dev_addr = %d\n", dev->dev_addr); | ||
2025 | |||
2026 | /* update usb state */ | ||
2027 | dev->usb_state = USB_STATE_ADDRESS; | ||
2028 | |||
2029 | /* STATUS phase */ | ||
2030 | if (prime_status_phase(dev, EP_DIR_IN)) | ||
2031 | ep0_stall(dev); | ||
2032 | |||
2033 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2034 | } | ||
2035 | |||
2036 | |||
2037 | /* return endpoint by windex */ | ||
2038 | static struct langwell_ep *get_ep_by_windex(struct langwell_udc *dev, | ||
2039 | u16 wIndex) | ||
2040 | { | ||
2041 | struct langwell_ep *ep; | ||
2042 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2043 | |||
2044 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0) | ||
2045 | return &dev->ep[0]; | ||
2046 | |||
2047 | list_for_each_entry(ep, &dev->gadget.ep_list, ep.ep_list) { | ||
2048 | u8 bEndpointAddress; | ||
2049 | if (!ep->desc) | ||
2050 | continue; | ||
2051 | |||
2052 | bEndpointAddress = ep->desc->bEndpointAddress; | ||
2053 | if ((wIndex ^ bEndpointAddress) & USB_DIR_IN) | ||
2054 | continue; | ||
2055 | |||
2056 | if ((wIndex & USB_ENDPOINT_NUMBER_MASK) | ||
2057 | == (bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)) | ||
2058 | return ep; | ||
2059 | } | ||
2060 | |||
2061 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2062 | return NULL; | ||
2063 | } | ||
2064 | |||
2065 | |||
2066 | /* return whether endpoint is stalled, 0: not stalled; 1: stalled */ | ||
2067 | static int ep_is_stall(struct langwell_ep *ep) | ||
2068 | { | ||
2069 | struct langwell_udc *dev = ep->dev; | ||
2070 | u32 endptctrl; | ||
2071 | int retval; | ||
2072 | |||
2073 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2074 | |||
2075 | endptctrl = readl(&dev->op_regs->endptctrl[ep->ep_num]); | ||
2076 | if (is_in(ep)) | ||
2077 | retval = endptctrl & EPCTRL_TXS ? 1 : 0; | ||
2078 | else | ||
2079 | retval = endptctrl & EPCTRL_RXS ? 1 : 0; | ||
2080 | |||
2081 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2082 | return retval; | ||
2083 | } | ||
2084 | |||
2085 | |||
2086 | /* GET_STATUS request routine */ | ||
2087 | static void get_status(struct langwell_udc *dev, u8 request_type, u16 value, | ||
2088 | u16 index, u16 length) | ||
2089 | { | ||
2090 | struct langwell_request *req; | ||
2091 | struct langwell_ep *ep; | ||
2092 | u16 status_data = 0; /* 16 bits cpu view status data */ | ||
2093 | int status = 0; | ||
2094 | |||
2095 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2096 | |||
2097 | ep = &dev->ep[0]; | ||
2098 | |||
2099 | if ((request_type & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | ||
2100 | /* get device status */ | ||
2101 | status_data = dev->dev_status; | ||
2102 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_INTERFACE) { | ||
2103 | /* get interface status */ | ||
2104 | status_data = 0; | ||
2105 | } else if ((request_type & USB_RECIP_MASK) == USB_RECIP_ENDPOINT) { | ||
2106 | /* get endpoint status */ | ||
2107 | struct langwell_ep *epn; | ||
2108 | epn = get_ep_by_windex(dev, index); | ||
2109 | /* stall if endpoint doesn't exist */ | ||
2110 | if (!epn) | ||
2111 | goto stall; | ||
2112 | |||
2113 | status_data = ep_is_stall(epn) << USB_ENDPOINT_HALT; | ||
2114 | } | ||
2115 | |||
2116 | dev_dbg(&dev->pdev->dev, "get status data: 0x%04x\n", status_data); | ||
2117 | |||
2118 | dev->ep0_dir = USB_DIR_IN; | ||
2119 | |||
2120 | /* borrow the per device status_req */ | ||
2121 | req = dev->status_req; | ||
2122 | |||
2123 | /* fill in the reqest structure */ | ||
2124 | *((u16 *) req->req.buf) = cpu_to_le16(status_data); | ||
2125 | req->ep = ep; | ||
2126 | req->req.length = 2; | ||
2127 | req->req.status = -EINPROGRESS; | ||
2128 | req->req.actual = 0; | ||
2129 | req->req.complete = NULL; | ||
2130 | req->dtd_count = 0; | ||
2131 | |||
2132 | /* prime the data phase */ | ||
2133 | if (!req_to_dtd(req)) | ||
2134 | status = queue_dtd(ep, req); | ||
2135 | else /* no mem */ | ||
2136 | goto stall; | ||
2137 | |||
2138 | if (status) { | ||
2139 | dev_err(&dev->pdev->dev, | ||
2140 | "response error on GET_STATUS request\n"); | ||
2141 | goto stall; | ||
2142 | } | ||
2143 | |||
2144 | list_add_tail(&req->queue, &ep->queue); | ||
2145 | dev->ep0_state = DATA_STATE_XMIT; | ||
2146 | |||
2147 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2148 | return; | ||
2149 | stall: | ||
2150 | ep0_stall(dev); | ||
2151 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2152 | } | ||
2153 | |||
2154 | |||
2155 | /* setup packet interrupt handler */ | ||
2156 | static void handle_setup_packet(struct langwell_udc *dev, | ||
2157 | struct usb_ctrlrequest *setup) | ||
2158 | { | ||
2159 | u16 wValue = le16_to_cpu(setup->wValue); | ||
2160 | u16 wIndex = le16_to_cpu(setup->wIndex); | ||
2161 | u16 wLength = le16_to_cpu(setup->wLength); | ||
2162 | u32 portsc1; | ||
2163 | |||
2164 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2165 | |||
2166 | /* ep0 fifo flush */ | ||
2167 | nuke(&dev->ep[0], -ESHUTDOWN); | ||
2168 | |||
2169 | dev_dbg(&dev->pdev->dev, "SETUP %02x.%02x v%04x i%04x l%04x\n", | ||
2170 | setup->bRequestType, setup->bRequest, | ||
2171 | wValue, wIndex, wLength); | ||
2172 | |||
2173 | /* RNDIS gadget delegate */ | ||
2174 | if ((setup->bRequestType == 0x21) && (setup->bRequest == 0x00)) { | ||
2175 | /* USB_CDC_SEND_ENCAPSULATED_COMMAND */ | ||
2176 | goto delegate; | ||
2177 | } | ||
2178 | |||
2179 | /* USB_CDC_GET_ENCAPSULATED_RESPONSE */ | ||
2180 | if ((setup->bRequestType == 0xa1) && (setup->bRequest == 0x01)) { | ||
2181 | /* USB_CDC_GET_ENCAPSULATED_RESPONSE */ | ||
2182 | goto delegate; | ||
2183 | } | ||
2184 | |||
2185 | /* We process some stardard setup requests here */ | ||
2186 | switch (setup->bRequest) { | ||
2187 | case USB_REQ_GET_STATUS: | ||
2188 | dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_GET_STATUS\n"); | ||
2189 | /* get status, DATA and STATUS phase */ | ||
2190 | if ((setup->bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) | ||
2191 | != (USB_DIR_IN | USB_TYPE_STANDARD)) | ||
2192 | break; | ||
2193 | get_status(dev, setup->bRequestType, wValue, wIndex, wLength); | ||
2194 | goto end; | ||
2195 | |||
2196 | case USB_REQ_SET_ADDRESS: | ||
2197 | dev_dbg(&dev->pdev->dev, "SETUP: USB_REQ_SET_ADDRESS\n"); | ||
2198 | /* STATUS phase */ | ||
2199 | if (setup->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD | ||
2200 | | USB_RECIP_DEVICE)) | ||
2201 | break; | ||
2202 | set_address(dev, wValue, wIndex, wLength); | ||
2203 | goto end; | ||
2204 | |||
2205 | case USB_REQ_CLEAR_FEATURE: | ||
2206 | case USB_REQ_SET_FEATURE: | ||
2207 | /* STATUS phase */ | ||
2208 | { | ||
2209 | int rc = -EOPNOTSUPP; | ||
2210 | if (setup->bRequest == USB_REQ_SET_FEATURE) | ||
2211 | dev_dbg(&dev->pdev->dev, | ||
2212 | "SETUP: USB_REQ_SET_FEATURE\n"); | ||
2213 | else if (setup->bRequest == USB_REQ_CLEAR_FEATURE) | ||
2214 | dev_dbg(&dev->pdev->dev, | ||
2215 | "SETUP: USB_REQ_CLEAR_FEATURE\n"); | ||
2216 | |||
2217 | if ((setup->bRequestType & (USB_RECIP_MASK | USB_TYPE_MASK)) | ||
2218 | == (USB_RECIP_ENDPOINT | USB_TYPE_STANDARD)) { | ||
2219 | struct langwell_ep *epn; | ||
2220 | epn = get_ep_by_windex(dev, wIndex); | ||
2221 | /* stall if endpoint doesn't exist */ | ||
2222 | if (!epn) { | ||
2223 | ep0_stall(dev); | ||
2224 | goto end; | ||
2225 | } | ||
2226 | |||
2227 | if (wValue != 0 || wLength != 0 | ||
2228 | || epn->ep_num > dev->ep_max) | ||
2229 | break; | ||
2230 | |||
2231 | spin_unlock(&dev->lock); | ||
2232 | rc = langwell_ep_set_halt(&epn->ep, | ||
2233 | (setup->bRequest == USB_REQ_SET_FEATURE) | ||
2234 | ? 1 : 0); | ||
2235 | spin_lock(&dev->lock); | ||
2236 | |||
2237 | } else if ((setup->bRequestType & (USB_RECIP_MASK | ||
2238 | | USB_TYPE_MASK)) == (USB_RECIP_DEVICE | ||
2239 | | USB_TYPE_STANDARD)) { | ||
2240 | rc = 0; | ||
2241 | switch (wValue) { | ||
2242 | case USB_DEVICE_REMOTE_WAKEUP: | ||
2243 | if (setup->bRequest == USB_REQ_SET_FEATURE) { | ||
2244 | dev->remote_wakeup = 1; | ||
2245 | dev->dev_status |= (1 << wValue); | ||
2246 | } else { | ||
2247 | dev->remote_wakeup = 0; | ||
2248 | dev->dev_status &= ~(1 << wValue); | ||
2249 | } | ||
2250 | break; | ||
2251 | case USB_DEVICE_TEST_MODE: | ||
2252 | dev_dbg(&dev->pdev->dev, "SETUP: TEST MODE\n"); | ||
2253 | if ((wIndex & 0xff) || | ||
2254 | (dev->gadget.speed != USB_SPEED_HIGH)) | ||
2255 | ep0_stall(dev); | ||
2256 | |||
2257 | switch (wIndex >> 8) { | ||
2258 | case TEST_J: | ||
2259 | case TEST_K: | ||
2260 | case TEST_SE0_NAK: | ||
2261 | case TEST_PACKET: | ||
2262 | case TEST_FORCE_EN: | ||
2263 | if (prime_status_phase(dev, EP_DIR_IN)) | ||
2264 | ep0_stall(dev); | ||
2265 | portsc1 = readl(&dev->op_regs->portsc1); | ||
2266 | portsc1 |= (wIndex & 0xf00) << 8; | ||
2267 | writel(portsc1, &dev->op_regs->portsc1); | ||
2268 | goto end; | ||
2269 | default: | ||
2270 | rc = -EOPNOTSUPP; | ||
2271 | } | ||
2272 | break; | ||
2273 | default: | ||
2274 | rc = -EOPNOTSUPP; | ||
2275 | break; | ||
2276 | } | ||
2277 | |||
2278 | if (!gadget_is_otg(&dev->gadget)) | ||
2279 | break; | ||
2280 | else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) | ||
2281 | dev->gadget.b_hnp_enable = 1; | ||
2282 | else if (setup->bRequest == USB_DEVICE_A_HNP_SUPPORT) | ||
2283 | dev->gadget.a_hnp_support = 1; | ||
2284 | else if (setup->bRequest == | ||
2285 | USB_DEVICE_A_ALT_HNP_SUPPORT) | ||
2286 | dev->gadget.a_alt_hnp_support = 1; | ||
2287 | else | ||
2288 | break; | ||
2289 | } else | ||
2290 | break; | ||
2291 | |||
2292 | if (rc == 0) { | ||
2293 | if (prime_status_phase(dev, EP_DIR_IN)) | ||
2294 | ep0_stall(dev); | ||
2295 | } | ||
2296 | goto end; | ||
2297 | } | ||
2298 | |||
2299 | case USB_REQ_GET_DESCRIPTOR: | ||
2300 | dev_dbg(&dev->pdev->dev, | ||
2301 | "SETUP: USB_REQ_GET_DESCRIPTOR\n"); | ||
2302 | goto delegate; | ||
2303 | |||
2304 | case USB_REQ_SET_DESCRIPTOR: | ||
2305 | dev_dbg(&dev->pdev->dev, | ||
2306 | "SETUP: USB_REQ_SET_DESCRIPTOR unsupported\n"); | ||
2307 | goto delegate; | ||
2308 | |||
2309 | case USB_REQ_GET_CONFIGURATION: | ||
2310 | dev_dbg(&dev->pdev->dev, | ||
2311 | "SETUP: USB_REQ_GET_CONFIGURATION\n"); | ||
2312 | goto delegate; | ||
2313 | |||
2314 | case USB_REQ_SET_CONFIGURATION: | ||
2315 | dev_dbg(&dev->pdev->dev, | ||
2316 | "SETUP: USB_REQ_SET_CONFIGURATION\n"); | ||
2317 | goto delegate; | ||
2318 | |||
2319 | case USB_REQ_GET_INTERFACE: | ||
2320 | dev_dbg(&dev->pdev->dev, | ||
2321 | "SETUP: USB_REQ_GET_INTERFACE\n"); | ||
2322 | goto delegate; | ||
2323 | |||
2324 | case USB_REQ_SET_INTERFACE: | ||
2325 | dev_dbg(&dev->pdev->dev, | ||
2326 | "SETUP: USB_REQ_SET_INTERFACE\n"); | ||
2327 | goto delegate; | ||
2328 | |||
2329 | case USB_REQ_SYNCH_FRAME: | ||
2330 | dev_dbg(&dev->pdev->dev, | ||
2331 | "SETUP: USB_REQ_SYNCH_FRAME unsupported\n"); | ||
2332 | goto delegate; | ||
2333 | |||
2334 | default: | ||
2335 | /* delegate USB standard requests to the gadget driver */ | ||
2336 | goto delegate; | ||
2337 | delegate: | ||
2338 | /* USB requests handled by gadget */ | ||
2339 | if (wLength) { | ||
2340 | /* DATA phase from gadget, STATUS phase from udc */ | ||
2341 | dev->ep0_dir = (setup->bRequestType & USB_DIR_IN) | ||
2342 | ? USB_DIR_IN : USB_DIR_OUT; | ||
2343 | dev_vdbg(&dev->pdev->dev, | ||
2344 | "dev->ep0_dir = 0x%x, wLength = %d\n", | ||
2345 | dev->ep0_dir, wLength); | ||
2346 | spin_unlock(&dev->lock); | ||
2347 | if (dev->driver->setup(&dev->gadget, | ||
2348 | &dev->local_setup_buff) < 0) | ||
2349 | ep0_stall(dev); | ||
2350 | spin_lock(&dev->lock); | ||
2351 | dev->ep0_state = (setup->bRequestType & USB_DIR_IN) | ||
2352 | ? DATA_STATE_XMIT : DATA_STATE_RECV; | ||
2353 | } else { | ||
2354 | /* no DATA phase, IN STATUS phase from gadget */ | ||
2355 | dev->ep0_dir = USB_DIR_IN; | ||
2356 | dev_vdbg(&dev->pdev->dev, | ||
2357 | "dev->ep0_dir = 0x%x, wLength = %d\n", | ||
2358 | dev->ep0_dir, wLength); | ||
2359 | spin_unlock(&dev->lock); | ||
2360 | if (dev->driver->setup(&dev->gadget, | ||
2361 | &dev->local_setup_buff) < 0) | ||
2362 | ep0_stall(dev); | ||
2363 | spin_lock(&dev->lock); | ||
2364 | dev->ep0_state = WAIT_FOR_OUT_STATUS; | ||
2365 | } | ||
2366 | break; | ||
2367 | } | ||
2368 | end: | ||
2369 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2370 | } | ||
2371 | |||
2372 | |||
2373 | /* transfer completion, process endpoint request and free the completed dTDs | ||
2374 | * for this request | ||
2375 | */ | ||
2376 | static int process_ep_req(struct langwell_udc *dev, int index, | ||
2377 | struct langwell_request *curr_req) | ||
2378 | { | ||
2379 | struct langwell_dtd *curr_dtd; | ||
2380 | struct langwell_dqh *curr_dqh; | ||
2381 | int td_complete, actual, remaining_length; | ||
2382 | int i, dir; | ||
2383 | u8 dtd_status = 0; | ||
2384 | int retval = 0; | ||
2385 | |||
2386 | curr_dqh = &dev->ep_dqh[index]; | ||
2387 | dir = index % 2; | ||
2388 | |||
2389 | curr_dtd = curr_req->head; | ||
2390 | td_complete = 0; | ||
2391 | actual = curr_req->req.length; | ||
2392 | |||
2393 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2394 | |||
2395 | for (i = 0; i < curr_req->dtd_count; i++) { | ||
2396 | |||
2397 | /* command execution states by dTD */ | ||
2398 | dtd_status = curr_dtd->dtd_status; | ||
2399 | |||
2400 | barrier(); | ||
2401 | remaining_length = le16_to_cpu(curr_dtd->dtd_total); | ||
2402 | actual -= remaining_length; | ||
2403 | |||
2404 | if (!dtd_status) { | ||
2405 | /* transfers completed successfully */ | ||
2406 | if (!remaining_length) { | ||
2407 | td_complete++; | ||
2408 | dev_vdbg(&dev->pdev->dev, | ||
2409 | "dTD transmitted successfully\n"); | ||
2410 | } else { | ||
2411 | if (dir) { | ||
2412 | dev_vdbg(&dev->pdev->dev, | ||
2413 | "TX dTD remains data\n"); | ||
2414 | retval = -EPROTO; | ||
2415 | break; | ||
2416 | |||
2417 | } else { | ||
2418 | td_complete++; | ||
2419 | break; | ||
2420 | } | ||
2421 | } | ||
2422 | } else { | ||
2423 | /* transfers completed with errors */ | ||
2424 | if (dtd_status & DTD_STS_ACTIVE) { | ||
2425 | dev_dbg(&dev->pdev->dev, | ||
2426 | "dTD status ACTIVE dQH[%d]\n", index); | ||
2427 | retval = 1; | ||
2428 | return retval; | ||
2429 | } else if (dtd_status & DTD_STS_HALTED) { | ||
2430 | dev_err(&dev->pdev->dev, | ||
2431 | "dTD error %08x dQH[%d]\n", | ||
2432 | dtd_status, index); | ||
2433 | /* clear the errors and halt condition */ | ||
2434 | curr_dqh->dtd_status = 0; | ||
2435 | retval = -EPIPE; | ||
2436 | break; | ||
2437 | } else if (dtd_status & DTD_STS_DBE) { | ||
2438 | dev_dbg(&dev->pdev->dev, | ||
2439 | "data buffer (overflow) error\n"); | ||
2440 | retval = -EPROTO; | ||
2441 | break; | ||
2442 | } else if (dtd_status & DTD_STS_TRE) { | ||
2443 | dev_dbg(&dev->pdev->dev, | ||
2444 | "transaction(ISO) error\n"); | ||
2445 | retval = -EILSEQ; | ||
2446 | break; | ||
2447 | } else | ||
2448 | dev_err(&dev->pdev->dev, | ||
2449 | "unknown error (0x%x)!\n", | ||
2450 | dtd_status); | ||
2451 | } | ||
2452 | |||
2453 | if (i != curr_req->dtd_count - 1) | ||
2454 | curr_dtd = (struct langwell_dtd *) | ||
2455 | curr_dtd->next_dtd_virt; | ||
2456 | } | ||
2457 | |||
2458 | if (retval) | ||
2459 | return retval; | ||
2460 | |||
2461 | curr_req->req.actual = actual; | ||
2462 | |||
2463 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2464 | return 0; | ||
2465 | } | ||
2466 | |||
2467 | |||
2468 | /* complete DATA or STATUS phase of ep0 prime status phase if needed */ | ||
2469 | static void ep0_req_complete(struct langwell_udc *dev, | ||
2470 | struct langwell_ep *ep0, struct langwell_request *req) | ||
2471 | { | ||
2472 | u32 new_addr; | ||
2473 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2474 | |||
2475 | if (dev->usb_state == USB_STATE_ADDRESS) { | ||
2476 | /* set the new address */ | ||
2477 | new_addr = (u32)dev->dev_addr; | ||
2478 | writel(new_addr << USBADR_SHIFT, &dev->op_regs->deviceaddr); | ||
2479 | |||
2480 | new_addr = USBADR(readl(&dev->op_regs->deviceaddr)); | ||
2481 | dev_vdbg(&dev->pdev->dev, "new_addr = %d\n", new_addr); | ||
2482 | } | ||
2483 | |||
2484 | done(ep0, req, 0); | ||
2485 | |||
2486 | switch (dev->ep0_state) { | ||
2487 | case DATA_STATE_XMIT: | ||
2488 | /* receive status phase */ | ||
2489 | if (prime_status_phase(dev, EP_DIR_OUT)) | ||
2490 | ep0_stall(dev); | ||
2491 | break; | ||
2492 | case DATA_STATE_RECV: | ||
2493 | /* send status phase */ | ||
2494 | if (prime_status_phase(dev, EP_DIR_IN)) | ||
2495 | ep0_stall(dev); | ||
2496 | break; | ||
2497 | case WAIT_FOR_OUT_STATUS: | ||
2498 | dev->ep0_state = WAIT_FOR_SETUP; | ||
2499 | break; | ||
2500 | case WAIT_FOR_SETUP: | ||
2501 | dev_err(&dev->pdev->dev, "unexpect ep0 packets\n"); | ||
2502 | break; | ||
2503 | default: | ||
2504 | ep0_stall(dev); | ||
2505 | break; | ||
2506 | } | ||
2507 | |||
2508 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2509 | } | ||
2510 | |||
2511 | |||
2512 | /* USB transfer completion interrupt */ | ||
2513 | static void handle_trans_complete(struct langwell_udc *dev) | ||
2514 | { | ||
2515 | u32 complete_bits; | ||
2516 | int i, ep_num, dir, bit_mask, status; | ||
2517 | struct langwell_ep *epn; | ||
2518 | struct langwell_request *curr_req, *temp_req; | ||
2519 | |||
2520 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2521 | |||
2522 | complete_bits = readl(&dev->op_regs->endptcomplete); | ||
2523 | dev_vdbg(&dev->pdev->dev, "endptcomplete register: 0x%08x\n", | ||
2524 | complete_bits); | ||
2525 | |||
2526 | /* Write-Clear the bits in endptcomplete register */ | ||
2527 | writel(complete_bits, &dev->op_regs->endptcomplete); | ||
2528 | |||
2529 | if (!complete_bits) { | ||
2530 | dev_dbg(&dev->pdev->dev, "complete_bits = 0\n"); | ||
2531 | goto done; | ||
2532 | } | ||
2533 | |||
2534 | for (i = 0; i < dev->ep_max; i++) { | ||
2535 | ep_num = i / 2; | ||
2536 | dir = i % 2; | ||
2537 | |||
2538 | bit_mask = 1 << (ep_num + 16 * dir); | ||
2539 | |||
2540 | if (!(complete_bits & bit_mask)) | ||
2541 | continue; | ||
2542 | |||
2543 | /* ep0 */ | ||
2544 | if (i == 1) | ||
2545 | epn = &dev->ep[0]; | ||
2546 | else | ||
2547 | epn = &dev->ep[i]; | ||
2548 | |||
2549 | if (epn->name == NULL) { | ||
2550 | dev_warn(&dev->pdev->dev, "invalid endpoint\n"); | ||
2551 | continue; | ||
2552 | } | ||
2553 | |||
2554 | if (i < 2) | ||
2555 | /* ep0 in and out */ | ||
2556 | dev_dbg(&dev->pdev->dev, "%s-%s transfer completed\n", | ||
2557 | epn->name, | ||
2558 | is_in(epn) ? "in" : "out"); | ||
2559 | else | ||
2560 | dev_dbg(&dev->pdev->dev, "%s transfer completed\n", | ||
2561 | epn->name); | ||
2562 | |||
2563 | /* process the req queue until an uncomplete request */ | ||
2564 | list_for_each_entry_safe(curr_req, temp_req, | ||
2565 | &epn->queue, queue) { | ||
2566 | status = process_ep_req(dev, i, curr_req); | ||
2567 | dev_vdbg(&dev->pdev->dev, "%s req status: %d\n", | ||
2568 | epn->name, status); | ||
2569 | |||
2570 | if (status) | ||
2571 | break; | ||
2572 | |||
2573 | /* write back status to req */ | ||
2574 | curr_req->req.status = status; | ||
2575 | |||
2576 | /* ep0 request completion */ | ||
2577 | if (ep_num == 0) { | ||
2578 | ep0_req_complete(dev, epn, curr_req); | ||
2579 | break; | ||
2580 | } else { | ||
2581 | done(epn, curr_req, status); | ||
2582 | } | ||
2583 | } | ||
2584 | } | ||
2585 | done: | ||
2586 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2587 | } | ||
2588 | |||
2589 | /* port change detect interrupt handler */ | ||
2590 | static void handle_port_change(struct langwell_udc *dev) | ||
2591 | { | ||
2592 | u32 portsc1, devlc; | ||
2593 | |||
2594 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2595 | |||
2596 | if (dev->bus_reset) | ||
2597 | dev->bus_reset = 0; | ||
2598 | |||
2599 | portsc1 = readl(&dev->op_regs->portsc1); | ||
2600 | devlc = readl(&dev->op_regs->devlc); | ||
2601 | dev_vdbg(&dev->pdev->dev, "portsc1 = 0x%08x, devlc = 0x%08x\n", | ||
2602 | portsc1, devlc); | ||
2603 | |||
2604 | /* bus reset is finished */ | ||
2605 | if (!(portsc1 & PORTS_PR)) { | ||
2606 | /* get the speed */ | ||
2607 | dev->gadget.speed = lpm_device_speed(devlc); | ||
2608 | dev_vdbg(&dev->pdev->dev, "dev->gadget.speed = %d\n", | ||
2609 | dev->gadget.speed); | ||
2610 | } | ||
2611 | |||
2612 | /* LPM L0 to L1 */ | ||
2613 | if (dev->lpm && dev->lpm_state == LPM_L0) | ||
2614 | if (portsc1 & PORTS_SUSP && portsc1 & PORTS_SLP) { | ||
2615 | dev_info(&dev->pdev->dev, "LPM L0 to L1\n"); | ||
2616 | dev->lpm_state = LPM_L1; | ||
2617 | } | ||
2618 | |||
2619 | /* LPM L1 to L0, force resume or remote wakeup finished */ | ||
2620 | if (dev->lpm && dev->lpm_state == LPM_L1) | ||
2621 | if (!(portsc1 & PORTS_SUSP)) { | ||
2622 | dev_info(&dev->pdev->dev, "LPM L1 to L0\n"); | ||
2623 | dev->lpm_state = LPM_L0; | ||
2624 | } | ||
2625 | |||
2626 | /* update USB state */ | ||
2627 | if (!dev->resume_state) | ||
2628 | dev->usb_state = USB_STATE_DEFAULT; | ||
2629 | |||
2630 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2631 | } | ||
2632 | |||
2633 | |||
2634 | /* USB reset interrupt handler */ | ||
2635 | static void handle_usb_reset(struct langwell_udc *dev) | ||
2636 | { | ||
2637 | u32 deviceaddr, | ||
2638 | endptsetupstat, | ||
2639 | endptcomplete; | ||
2640 | unsigned long timeout; | ||
2641 | |||
2642 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2643 | |||
2644 | /* Write-Clear the device address */ | ||
2645 | deviceaddr = readl(&dev->op_regs->deviceaddr); | ||
2646 | writel(deviceaddr & ~USBADR_MASK, &dev->op_regs->deviceaddr); | ||
2647 | |||
2648 | dev->dev_addr = 0; | ||
2649 | |||
2650 | /* clear usb state */ | ||
2651 | dev->resume_state = 0; | ||
2652 | |||
2653 | /* LPM L1 to L0, reset */ | ||
2654 | if (dev->lpm) | ||
2655 | dev->lpm_state = LPM_L0; | ||
2656 | |||
2657 | dev->ep0_dir = USB_DIR_OUT; | ||
2658 | dev->ep0_state = WAIT_FOR_SETUP; | ||
2659 | |||
2660 | /* remote wakeup reset to 0 when the device is reset */ | ||
2661 | dev->remote_wakeup = 0; | ||
2662 | dev->dev_status = 1 << USB_DEVICE_SELF_POWERED; | ||
2663 | dev->gadget.b_hnp_enable = 0; | ||
2664 | dev->gadget.a_hnp_support = 0; | ||
2665 | dev->gadget.a_alt_hnp_support = 0; | ||
2666 | |||
2667 | /* Write-Clear all the setup token semaphores */ | ||
2668 | endptsetupstat = readl(&dev->op_regs->endptsetupstat); | ||
2669 | writel(endptsetupstat, &dev->op_regs->endptsetupstat); | ||
2670 | |||
2671 | /* Write-Clear all the endpoint complete status bits */ | ||
2672 | endptcomplete = readl(&dev->op_regs->endptcomplete); | ||
2673 | writel(endptcomplete, &dev->op_regs->endptcomplete); | ||
2674 | |||
2675 | /* wait until all endptprime bits cleared */ | ||
2676 | timeout = jiffies + PRIME_TIMEOUT; | ||
2677 | while (readl(&dev->op_regs->endptprime)) { | ||
2678 | if (time_after(jiffies, timeout)) { | ||
2679 | dev_err(&dev->pdev->dev, "USB reset timeout\n"); | ||
2680 | break; | ||
2681 | } | ||
2682 | cpu_relax(); | ||
2683 | } | ||
2684 | |||
2685 | /* write 1s to endptflush register to clear any primed buffers */ | ||
2686 | writel((u32) ~0, &dev->op_regs->endptflush); | ||
2687 | |||
2688 | if (readl(&dev->op_regs->portsc1) & PORTS_PR) { | ||
2689 | dev_vdbg(&dev->pdev->dev, "USB bus reset\n"); | ||
2690 | /* bus is reseting */ | ||
2691 | dev->bus_reset = 1; | ||
2692 | |||
2693 | /* reset all the queues, stop all USB activities */ | ||
2694 | stop_activity(dev); | ||
2695 | dev->usb_state = USB_STATE_DEFAULT; | ||
2696 | } else { | ||
2697 | dev_vdbg(&dev->pdev->dev, "device controller reset\n"); | ||
2698 | /* controller reset */ | ||
2699 | langwell_udc_reset(dev); | ||
2700 | |||
2701 | /* reset all the queues, stop all USB activities */ | ||
2702 | stop_activity(dev); | ||
2703 | |||
2704 | /* reset ep0 dQH and endptctrl */ | ||
2705 | ep0_reset(dev); | ||
2706 | |||
2707 | /* enable interrupt and set controller to run state */ | ||
2708 | langwell_udc_start(dev); | ||
2709 | |||
2710 | dev->usb_state = USB_STATE_ATTACHED; | ||
2711 | } | ||
2712 | |||
2713 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2714 | } | ||
2715 | |||
2716 | |||
2717 | /* USB bus suspend/resume interrupt */ | ||
2718 | static void handle_bus_suspend(struct langwell_udc *dev) | ||
2719 | { | ||
2720 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2721 | |||
2722 | dev->resume_state = dev->usb_state; | ||
2723 | dev->usb_state = USB_STATE_SUSPENDED; | ||
2724 | |||
2725 | /* report suspend to the driver */ | ||
2726 | if (dev->driver) { | ||
2727 | if (dev->driver->suspend) { | ||
2728 | spin_unlock(&dev->lock); | ||
2729 | dev->driver->suspend(&dev->gadget); | ||
2730 | spin_lock(&dev->lock); | ||
2731 | dev_dbg(&dev->pdev->dev, "suspend %s\n", | ||
2732 | dev->driver->driver.name); | ||
2733 | } | ||
2734 | } | ||
2735 | |||
2736 | /* enter PHY low power suspend */ | ||
2737 | if (dev->pdev->device != 0x0829) | ||
2738 | langwell_phy_low_power(dev, 0); | ||
2739 | |||
2740 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2741 | } | ||
2742 | |||
2743 | |||
2744 | static void handle_bus_resume(struct langwell_udc *dev) | ||
2745 | { | ||
2746 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2747 | |||
2748 | dev->usb_state = dev->resume_state; | ||
2749 | dev->resume_state = 0; | ||
2750 | |||
2751 | /* exit PHY low power suspend */ | ||
2752 | if (dev->pdev->device != 0x0829) | ||
2753 | langwell_phy_low_power(dev, 0); | ||
2754 | |||
2755 | /* report resume to the driver */ | ||
2756 | if (dev->driver) { | ||
2757 | if (dev->driver->resume) { | ||
2758 | spin_unlock(&dev->lock); | ||
2759 | dev->driver->resume(&dev->gadget); | ||
2760 | spin_lock(&dev->lock); | ||
2761 | dev_dbg(&dev->pdev->dev, "resume %s\n", | ||
2762 | dev->driver->driver.name); | ||
2763 | } | ||
2764 | } | ||
2765 | |||
2766 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2767 | } | ||
2768 | |||
2769 | |||
2770 | /* USB device controller interrupt handler */ | ||
2771 | static irqreturn_t langwell_irq(int irq, void *_dev) | ||
2772 | { | ||
2773 | struct langwell_udc *dev = _dev; | ||
2774 | u32 usbsts, | ||
2775 | usbintr, | ||
2776 | irq_sts, | ||
2777 | portsc1; | ||
2778 | |||
2779 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2780 | |||
2781 | if (dev->stopped) { | ||
2782 | dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n"); | ||
2783 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2784 | return IRQ_NONE; | ||
2785 | } | ||
2786 | |||
2787 | spin_lock(&dev->lock); | ||
2788 | |||
2789 | /* USB status */ | ||
2790 | usbsts = readl(&dev->op_regs->usbsts); | ||
2791 | |||
2792 | /* USB interrupt enable */ | ||
2793 | usbintr = readl(&dev->op_regs->usbintr); | ||
2794 | |||
2795 | irq_sts = usbsts & usbintr; | ||
2796 | dev_vdbg(&dev->pdev->dev, | ||
2797 | "usbsts = 0x%08x, usbintr = 0x%08x, irq_sts = 0x%08x\n", | ||
2798 | usbsts, usbintr, irq_sts); | ||
2799 | |||
2800 | if (!irq_sts) { | ||
2801 | dev_vdbg(&dev->pdev->dev, "handle IRQ_NONE\n"); | ||
2802 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2803 | spin_unlock(&dev->lock); | ||
2804 | return IRQ_NONE; | ||
2805 | } | ||
2806 | |||
2807 | /* Write-Clear interrupt status bits */ | ||
2808 | writel(irq_sts, &dev->op_regs->usbsts); | ||
2809 | |||
2810 | /* resume from suspend */ | ||
2811 | portsc1 = readl(&dev->op_regs->portsc1); | ||
2812 | if (dev->usb_state == USB_STATE_SUSPENDED) | ||
2813 | if (!(portsc1 & PORTS_SUSP)) | ||
2814 | handle_bus_resume(dev); | ||
2815 | |||
2816 | /* USB interrupt */ | ||
2817 | if (irq_sts & STS_UI) { | ||
2818 | dev_vdbg(&dev->pdev->dev, "USB interrupt\n"); | ||
2819 | |||
2820 | /* setup packet received from ep0 */ | ||
2821 | if (readl(&dev->op_regs->endptsetupstat) | ||
2822 | & EP0SETUPSTAT_MASK) { | ||
2823 | dev_vdbg(&dev->pdev->dev, | ||
2824 | "USB SETUP packet received interrupt\n"); | ||
2825 | /* setup tripwire semaphone */ | ||
2826 | setup_tripwire(dev); | ||
2827 | handle_setup_packet(dev, &dev->local_setup_buff); | ||
2828 | } | ||
2829 | |||
2830 | /* USB transfer completion */ | ||
2831 | if (readl(&dev->op_regs->endptcomplete)) { | ||
2832 | dev_vdbg(&dev->pdev->dev, | ||
2833 | "USB transfer completion interrupt\n"); | ||
2834 | handle_trans_complete(dev); | ||
2835 | } | ||
2836 | } | ||
2837 | |||
2838 | /* SOF received interrupt (for ISO transfer) */ | ||
2839 | if (irq_sts & STS_SRI) { | ||
2840 | /* FIXME */ | ||
2841 | /* dev_vdbg(&dev->pdev->dev, "SOF received interrupt\n"); */ | ||
2842 | } | ||
2843 | |||
2844 | /* port change detect interrupt */ | ||
2845 | if (irq_sts & STS_PCI) { | ||
2846 | dev_vdbg(&dev->pdev->dev, "port change detect interrupt\n"); | ||
2847 | handle_port_change(dev); | ||
2848 | } | ||
2849 | |||
2850 | /* suspend interrupt */ | ||
2851 | if (irq_sts & STS_SLI) { | ||
2852 | dev_vdbg(&dev->pdev->dev, "suspend interrupt\n"); | ||
2853 | handle_bus_suspend(dev); | ||
2854 | } | ||
2855 | |||
2856 | /* USB reset interrupt */ | ||
2857 | if (irq_sts & STS_URI) { | ||
2858 | dev_vdbg(&dev->pdev->dev, "USB reset interrupt\n"); | ||
2859 | handle_usb_reset(dev); | ||
2860 | } | ||
2861 | |||
2862 | /* USB error or system error interrupt */ | ||
2863 | if (irq_sts & (STS_UEI | STS_SEI)) { | ||
2864 | /* FIXME */ | ||
2865 | dev_warn(&dev->pdev->dev, "error IRQ, irq_sts: %x\n", irq_sts); | ||
2866 | } | ||
2867 | |||
2868 | spin_unlock(&dev->lock); | ||
2869 | |||
2870 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2871 | return IRQ_HANDLED; | ||
2872 | } | ||
2873 | |||
2874 | |||
2875 | /*-------------------------------------------------------------------------*/ | ||
2876 | |||
2877 | /* release device structure */ | ||
2878 | static void gadget_release(struct device *_dev) | ||
2879 | { | ||
2880 | struct langwell_udc *dev = dev_get_drvdata(_dev); | ||
2881 | |||
2882 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2883 | |||
2884 | complete(dev->done); | ||
2885 | |||
2886 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2887 | kfree(dev); | ||
2888 | } | ||
2889 | |||
2890 | |||
2891 | /* enable SRAM caching if SRAM detected */ | ||
2892 | static void sram_init(struct langwell_udc *dev) | ||
2893 | { | ||
2894 | struct pci_dev *pdev = dev->pdev; | ||
2895 | |||
2896 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2897 | |||
2898 | dev->sram_addr = pci_resource_start(pdev, 1); | ||
2899 | dev->sram_size = pci_resource_len(pdev, 1); | ||
2900 | dev_info(&dev->pdev->dev, "Found private SRAM at %x size:%x\n", | ||
2901 | dev->sram_addr, dev->sram_size); | ||
2902 | dev->got_sram = 1; | ||
2903 | |||
2904 | if (pci_request_region(pdev, 1, kobject_name(&pdev->dev.kobj))) { | ||
2905 | dev_warn(&dev->pdev->dev, "SRAM request failed\n"); | ||
2906 | dev->got_sram = 0; | ||
2907 | } else if (!dma_declare_coherent_memory(&pdev->dev, dev->sram_addr, | ||
2908 | dev->sram_addr, dev->sram_size, DMA_MEMORY_MAP)) { | ||
2909 | dev_warn(&dev->pdev->dev, "SRAM DMA declare failed\n"); | ||
2910 | pci_release_region(pdev, 1); | ||
2911 | dev->got_sram = 0; | ||
2912 | } | ||
2913 | |||
2914 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2915 | } | ||
2916 | |||
2917 | |||
2918 | /* release SRAM caching */ | ||
2919 | static void sram_deinit(struct langwell_udc *dev) | ||
2920 | { | ||
2921 | struct pci_dev *pdev = dev->pdev; | ||
2922 | |||
2923 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2924 | |||
2925 | dma_release_declared_memory(&pdev->dev); | ||
2926 | pci_release_region(pdev, 1); | ||
2927 | |||
2928 | dev->got_sram = 0; | ||
2929 | |||
2930 | dev_info(&dev->pdev->dev, "release SRAM caching\n"); | ||
2931 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2932 | } | ||
2933 | |||
2934 | |||
2935 | /* tear down the binding between this driver and the pci device */ | ||
2936 | static void langwell_udc_remove(struct pci_dev *pdev) | ||
2937 | { | ||
2938 | struct langwell_udc *dev = pci_get_drvdata(pdev); | ||
2939 | |||
2940 | DECLARE_COMPLETION(done); | ||
2941 | |||
2942 | BUG_ON(dev->driver); | ||
2943 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
2944 | |||
2945 | dev->done = &done; | ||
2946 | |||
2947 | /* free dTD dma_pool and dQH */ | ||
2948 | if (dev->dtd_pool) | ||
2949 | dma_pool_destroy(dev->dtd_pool); | ||
2950 | |||
2951 | if (dev->ep_dqh) | ||
2952 | dma_free_coherent(&pdev->dev, dev->ep_dqh_size, | ||
2953 | dev->ep_dqh, dev->ep_dqh_dma); | ||
2954 | |||
2955 | /* release SRAM caching */ | ||
2956 | if (dev->has_sram && dev->got_sram) | ||
2957 | sram_deinit(dev); | ||
2958 | |||
2959 | if (dev->status_req) { | ||
2960 | kfree(dev->status_req->req.buf); | ||
2961 | kfree(dev->status_req); | ||
2962 | } | ||
2963 | |||
2964 | kfree(dev->ep); | ||
2965 | |||
2966 | /* disable IRQ handler */ | ||
2967 | if (dev->got_irq) | ||
2968 | free_irq(pdev->irq, dev); | ||
2969 | |||
2970 | if (dev->cap_regs) | ||
2971 | iounmap(dev->cap_regs); | ||
2972 | |||
2973 | if (dev->region) | ||
2974 | release_mem_region(pci_resource_start(pdev, 0), | ||
2975 | pci_resource_len(pdev, 0)); | ||
2976 | |||
2977 | if (dev->enabled) | ||
2978 | pci_disable_device(pdev); | ||
2979 | |||
2980 | dev->cap_regs = NULL; | ||
2981 | |||
2982 | dev_info(&dev->pdev->dev, "unbind\n"); | ||
2983 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
2984 | |||
2985 | device_unregister(&dev->gadget.dev); | ||
2986 | device_remove_file(&pdev->dev, &dev_attr_langwell_udc); | ||
2987 | device_remove_file(&pdev->dev, &dev_attr_remote_wakeup); | ||
2988 | |||
2989 | pci_set_drvdata(pdev, NULL); | ||
2990 | |||
2991 | /* free dev, wait for the release() finished */ | ||
2992 | wait_for_completion(&done); | ||
2993 | } | ||
2994 | |||
2995 | |||
2996 | /* | ||
2997 | * wrap this driver around the specified device, but | ||
2998 | * don't respond over USB until a gadget driver binds to us. | ||
2999 | */ | ||
3000 | static int langwell_udc_probe(struct pci_dev *pdev, | ||
3001 | const struct pci_device_id *id) | ||
3002 | { | ||
3003 | struct langwell_udc *dev; | ||
3004 | unsigned long resource, len; | ||
3005 | void __iomem *base = NULL; | ||
3006 | size_t size; | ||
3007 | int retval; | ||
3008 | |||
3009 | /* alloc, and start init */ | ||
3010 | dev = kzalloc(sizeof *dev, GFP_KERNEL); | ||
3011 | if (dev == NULL) { | ||
3012 | retval = -ENOMEM; | ||
3013 | goto error; | ||
3014 | } | ||
3015 | |||
3016 | /* initialize device spinlock */ | ||
3017 | spin_lock_init(&dev->lock); | ||
3018 | |||
3019 | dev->pdev = pdev; | ||
3020 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
3021 | |||
3022 | pci_set_drvdata(pdev, dev); | ||
3023 | |||
3024 | /* now all the pci goodies ... */ | ||
3025 | if (pci_enable_device(pdev) < 0) { | ||
3026 | retval = -ENODEV; | ||
3027 | goto error; | ||
3028 | } | ||
3029 | dev->enabled = 1; | ||
3030 | |||
3031 | /* control register: BAR 0 */ | ||
3032 | resource = pci_resource_start(pdev, 0); | ||
3033 | len = pci_resource_len(pdev, 0); | ||
3034 | if (!request_mem_region(resource, len, driver_name)) { | ||
3035 | dev_err(&dev->pdev->dev, "controller already in use\n"); | ||
3036 | retval = -EBUSY; | ||
3037 | goto error; | ||
3038 | } | ||
3039 | dev->region = 1; | ||
3040 | |||
3041 | base = ioremap_nocache(resource, len); | ||
3042 | if (base == NULL) { | ||
3043 | dev_err(&dev->pdev->dev, "can't map memory\n"); | ||
3044 | retval = -EFAULT; | ||
3045 | goto error; | ||
3046 | } | ||
3047 | |||
3048 | dev->cap_regs = (struct langwell_cap_regs __iomem *) base; | ||
3049 | dev_vdbg(&dev->pdev->dev, "dev->cap_regs: %p\n", dev->cap_regs); | ||
3050 | dev->op_regs = (struct langwell_op_regs __iomem *) | ||
3051 | (base + OP_REG_OFFSET); | ||
3052 | dev_vdbg(&dev->pdev->dev, "dev->op_regs: %p\n", dev->op_regs); | ||
3053 | |||
3054 | /* irq setup after old hardware is cleaned up */ | ||
3055 | if (!pdev->irq) { | ||
3056 | dev_err(&dev->pdev->dev, "No IRQ. Check PCI setup!\n"); | ||
3057 | retval = -ENODEV; | ||
3058 | goto error; | ||
3059 | } | ||
3060 | |||
3061 | dev->has_sram = 1; | ||
3062 | dev->got_sram = 0; | ||
3063 | dev_vdbg(&dev->pdev->dev, "dev->has_sram: %d\n", dev->has_sram); | ||
3064 | |||
3065 | /* enable SRAM caching if detected */ | ||
3066 | if (dev->has_sram && !dev->got_sram) | ||
3067 | sram_init(dev); | ||
3068 | |||
3069 | dev_info(&dev->pdev->dev, | ||
3070 | "irq %d, io mem: 0x%08lx, len: 0x%08lx, pci mem 0x%p\n", | ||
3071 | pdev->irq, resource, len, base); | ||
3072 | /* enables bus-mastering for device dev */ | ||
3073 | pci_set_master(pdev); | ||
3074 | |||
3075 | if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, | ||
3076 | driver_name, dev) != 0) { | ||
3077 | dev_err(&dev->pdev->dev, | ||
3078 | "request interrupt %d failed\n", pdev->irq); | ||
3079 | retval = -EBUSY; | ||
3080 | goto error; | ||
3081 | } | ||
3082 | dev->got_irq = 1; | ||
3083 | |||
3084 | /* set stopped bit */ | ||
3085 | dev->stopped = 1; | ||
3086 | |||
3087 | /* capabilities and endpoint number */ | ||
3088 | dev->lpm = (readl(&dev->cap_regs->hccparams) & HCC_LEN) ? 1 : 0; | ||
3089 | dev->dciversion = readw(&dev->cap_regs->dciversion); | ||
3090 | dev->devcap = (readl(&dev->cap_regs->dccparams) & DEVCAP) ? 1 : 0; | ||
3091 | dev_vdbg(&dev->pdev->dev, "dev->lpm: %d\n", dev->lpm); | ||
3092 | dev_vdbg(&dev->pdev->dev, "dev->dciversion: 0x%04x\n", | ||
3093 | dev->dciversion); | ||
3094 | dev_vdbg(&dev->pdev->dev, "dccparams: 0x%08x\n", | ||
3095 | readl(&dev->cap_regs->dccparams)); | ||
3096 | dev_vdbg(&dev->pdev->dev, "dev->devcap: %d\n", dev->devcap); | ||
3097 | if (!dev->devcap) { | ||
3098 | dev_err(&dev->pdev->dev, "can't support device mode\n"); | ||
3099 | retval = -ENODEV; | ||
3100 | goto error; | ||
3101 | } | ||
3102 | |||
3103 | /* a pair of endpoints (out/in) for each address */ | ||
3104 | dev->ep_max = DEN(readl(&dev->cap_regs->dccparams)) * 2; | ||
3105 | dev_vdbg(&dev->pdev->dev, "dev->ep_max: %d\n", dev->ep_max); | ||
3106 | |||
3107 | /* allocate endpoints memory */ | ||
3108 | dev->ep = kzalloc(sizeof(struct langwell_ep) * dev->ep_max, | ||
3109 | GFP_KERNEL); | ||
3110 | if (!dev->ep) { | ||
3111 | dev_err(&dev->pdev->dev, "allocate endpoints memory failed\n"); | ||
3112 | retval = -ENOMEM; | ||
3113 | goto error; | ||
3114 | } | ||
3115 | |||
3116 | /* allocate device dQH memory */ | ||
3117 | size = dev->ep_max * sizeof(struct langwell_dqh); | ||
3118 | dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size); | ||
3119 | if (size < DQH_ALIGNMENT) | ||
3120 | size = DQH_ALIGNMENT; | ||
3121 | else if ((size % DQH_ALIGNMENT) != 0) { | ||
3122 | size += DQH_ALIGNMENT + 1; | ||
3123 | size &= ~(DQH_ALIGNMENT - 1); | ||
3124 | } | ||
3125 | dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size, | ||
3126 | &dev->ep_dqh_dma, GFP_KERNEL); | ||
3127 | if (!dev->ep_dqh) { | ||
3128 | dev_err(&dev->pdev->dev, "allocate dQH memory failed\n"); | ||
3129 | retval = -ENOMEM; | ||
3130 | goto error; | ||
3131 | } | ||
3132 | dev->ep_dqh_size = size; | ||
3133 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size); | ||
3134 | |||
3135 | /* initialize ep0 status request structure */ | ||
3136 | dev->status_req = kzalloc(sizeof(struct langwell_request), GFP_KERNEL); | ||
3137 | if (!dev->status_req) { | ||
3138 | dev_err(&dev->pdev->dev, | ||
3139 | "allocate status_req memory failed\n"); | ||
3140 | retval = -ENOMEM; | ||
3141 | goto error; | ||
3142 | } | ||
3143 | INIT_LIST_HEAD(&dev->status_req->queue); | ||
3144 | |||
3145 | /* allocate a small amount of memory to get valid address */ | ||
3146 | dev->status_req->req.buf = kmalloc(8, GFP_KERNEL); | ||
3147 | dev->status_req->req.dma = virt_to_phys(dev->status_req->req.buf); | ||
3148 | |||
3149 | dev->resume_state = USB_STATE_NOTATTACHED; | ||
3150 | dev->usb_state = USB_STATE_POWERED; | ||
3151 | dev->ep0_dir = USB_DIR_OUT; | ||
3152 | |||
3153 | /* remote wakeup reset to 0 when the device is reset */ | ||
3154 | dev->remote_wakeup = 0; | ||
3155 | dev->dev_status = 1 << USB_DEVICE_SELF_POWERED; | ||
3156 | |||
3157 | /* reset device controller */ | ||
3158 | langwell_udc_reset(dev); | ||
3159 | |||
3160 | /* initialize gadget structure */ | ||
3161 | dev->gadget.ops = &langwell_ops; /* usb_gadget_ops */ | ||
3162 | dev->gadget.ep0 = &dev->ep[0].ep; /* gadget ep0 */ | ||
3163 | INIT_LIST_HEAD(&dev->gadget.ep_list); /* ep_list */ | ||
3164 | dev->gadget.speed = USB_SPEED_UNKNOWN; /* speed */ | ||
3165 | dev->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */ | ||
3166 | |||
3167 | /* the "gadget" abstracts/virtualizes the controller */ | ||
3168 | dev_set_name(&dev->gadget.dev, "gadget"); | ||
3169 | dev->gadget.dev.parent = &pdev->dev; | ||
3170 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
3171 | dev->gadget.dev.release = gadget_release; | ||
3172 | dev->gadget.name = driver_name; /* gadget name */ | ||
3173 | |||
3174 | /* controller endpoints reinit */ | ||
3175 | eps_reinit(dev); | ||
3176 | |||
3177 | /* reset ep0 dQH and endptctrl */ | ||
3178 | ep0_reset(dev); | ||
3179 | |||
3180 | /* create dTD dma_pool resource */ | ||
3181 | dev->dtd_pool = dma_pool_create("langwell_dtd", | ||
3182 | &dev->pdev->dev, | ||
3183 | sizeof(struct langwell_dtd), | ||
3184 | DTD_ALIGNMENT, | ||
3185 | DMA_BOUNDARY); | ||
3186 | |||
3187 | if (!dev->dtd_pool) { | ||
3188 | retval = -ENOMEM; | ||
3189 | goto error; | ||
3190 | } | ||
3191 | |||
3192 | /* done */ | ||
3193 | dev_info(&dev->pdev->dev, "%s\n", driver_desc); | ||
3194 | dev_info(&dev->pdev->dev, "irq %d, pci mem %p\n", pdev->irq, base); | ||
3195 | dev_info(&dev->pdev->dev, "Driver version: " DRIVER_VERSION "\n"); | ||
3196 | dev_info(&dev->pdev->dev, "Support (max) %d endpoints\n", dev->ep_max); | ||
3197 | dev_info(&dev->pdev->dev, "Device interface version: 0x%04x\n", | ||
3198 | dev->dciversion); | ||
3199 | dev_info(&dev->pdev->dev, "Controller mode: %s\n", | ||
3200 | dev->devcap ? "Device" : "Host"); | ||
3201 | dev_info(&dev->pdev->dev, "Support USB LPM: %s\n", | ||
3202 | dev->lpm ? "Yes" : "No"); | ||
3203 | |||
3204 | dev_vdbg(&dev->pdev->dev, | ||
3205 | "After langwell_udc_probe(), print all registers:\n"); | ||
3206 | print_all_registers(dev); | ||
3207 | |||
3208 | retval = device_register(&dev->gadget.dev); | ||
3209 | if (retval) | ||
3210 | goto error; | ||
3211 | |||
3212 | retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); | ||
3213 | if (retval) | ||
3214 | goto error; | ||
3215 | |||
3216 | retval = device_create_file(&pdev->dev, &dev_attr_langwell_udc); | ||
3217 | if (retval) | ||
3218 | goto error; | ||
3219 | |||
3220 | retval = device_create_file(&pdev->dev, &dev_attr_remote_wakeup); | ||
3221 | if (retval) | ||
3222 | goto error_attr1; | ||
3223 | |||
3224 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
3225 | return 0; | ||
3226 | |||
3227 | error_attr1: | ||
3228 | device_remove_file(&pdev->dev, &dev_attr_langwell_udc); | ||
3229 | error: | ||
3230 | if (dev) { | ||
3231 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
3232 | langwell_udc_remove(pdev); | ||
3233 | } | ||
3234 | |||
3235 | return retval; | ||
3236 | } | ||
3237 | |||
3238 | |||
3239 | /* device controller suspend */ | ||
3240 | static int langwell_udc_suspend(struct pci_dev *pdev, pm_message_t state) | ||
3241 | { | ||
3242 | struct langwell_udc *dev = pci_get_drvdata(pdev); | ||
3243 | |||
3244 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
3245 | |||
3246 | usb_del_gadget_udc(&dev->gadget); | ||
3247 | /* disable interrupt and set controller to stop state */ | ||
3248 | langwell_udc_stop(dev); | ||
3249 | |||
3250 | /* disable IRQ handler */ | ||
3251 | if (dev->got_irq) | ||
3252 | free_irq(pdev->irq, dev); | ||
3253 | dev->got_irq = 0; | ||
3254 | |||
3255 | /* save PCI state */ | ||
3256 | pci_save_state(pdev); | ||
3257 | |||
3258 | spin_lock_irq(&dev->lock); | ||
3259 | /* stop all usb activities */ | ||
3260 | stop_activity(dev); | ||
3261 | spin_unlock_irq(&dev->lock); | ||
3262 | |||
3263 | /* free dTD dma_pool and dQH */ | ||
3264 | if (dev->dtd_pool) | ||
3265 | dma_pool_destroy(dev->dtd_pool); | ||
3266 | |||
3267 | if (dev->ep_dqh) | ||
3268 | dma_free_coherent(&pdev->dev, dev->ep_dqh_size, | ||
3269 | dev->ep_dqh, dev->ep_dqh_dma); | ||
3270 | |||
3271 | /* release SRAM caching */ | ||
3272 | if (dev->has_sram && dev->got_sram) | ||
3273 | sram_deinit(dev); | ||
3274 | |||
3275 | /* set device power state */ | ||
3276 | pci_set_power_state(pdev, PCI_D3hot); | ||
3277 | |||
3278 | /* enter PHY low power suspend */ | ||
3279 | if (dev->pdev->device != 0x0829) | ||
3280 | langwell_phy_low_power(dev, 1); | ||
3281 | |||
3282 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
3283 | return 0; | ||
3284 | } | ||
3285 | |||
3286 | |||
3287 | /* device controller resume */ | ||
3288 | static int langwell_udc_resume(struct pci_dev *pdev) | ||
3289 | { | ||
3290 | struct langwell_udc *dev = pci_get_drvdata(pdev); | ||
3291 | size_t size; | ||
3292 | |||
3293 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
3294 | |||
3295 | /* exit PHY low power suspend */ | ||
3296 | if (dev->pdev->device != 0x0829) | ||
3297 | langwell_phy_low_power(dev, 0); | ||
3298 | |||
3299 | /* set device D0 power state */ | ||
3300 | pci_set_power_state(pdev, PCI_D0); | ||
3301 | |||
3302 | /* enable SRAM caching if detected */ | ||
3303 | if (dev->has_sram && !dev->got_sram) | ||
3304 | sram_init(dev); | ||
3305 | |||
3306 | /* allocate device dQH memory */ | ||
3307 | size = dev->ep_max * sizeof(struct langwell_dqh); | ||
3308 | dev_vdbg(&dev->pdev->dev, "orig size = %zd\n", size); | ||
3309 | if (size < DQH_ALIGNMENT) | ||
3310 | size = DQH_ALIGNMENT; | ||
3311 | else if ((size % DQH_ALIGNMENT) != 0) { | ||
3312 | size += DQH_ALIGNMENT + 1; | ||
3313 | size &= ~(DQH_ALIGNMENT - 1); | ||
3314 | } | ||
3315 | dev->ep_dqh = dma_alloc_coherent(&pdev->dev, size, | ||
3316 | &dev->ep_dqh_dma, GFP_KERNEL); | ||
3317 | if (!dev->ep_dqh) { | ||
3318 | dev_err(&dev->pdev->dev, "allocate dQH memory failed\n"); | ||
3319 | return -ENOMEM; | ||
3320 | } | ||
3321 | dev->ep_dqh_size = size; | ||
3322 | dev_vdbg(&dev->pdev->dev, "ep_dqh_size = %zd\n", dev->ep_dqh_size); | ||
3323 | |||
3324 | /* create dTD dma_pool resource */ | ||
3325 | dev->dtd_pool = dma_pool_create("langwell_dtd", | ||
3326 | &dev->pdev->dev, | ||
3327 | sizeof(struct langwell_dtd), | ||
3328 | DTD_ALIGNMENT, | ||
3329 | DMA_BOUNDARY); | ||
3330 | |||
3331 | if (!dev->dtd_pool) | ||
3332 | return -ENOMEM; | ||
3333 | |||
3334 | /* restore PCI state */ | ||
3335 | pci_restore_state(pdev); | ||
3336 | |||
3337 | /* enable IRQ handler */ | ||
3338 | if (request_irq(pdev->irq, langwell_irq, IRQF_SHARED, | ||
3339 | driver_name, dev) != 0) { | ||
3340 | dev_err(&dev->pdev->dev, "request interrupt %d failed\n", | ||
3341 | pdev->irq); | ||
3342 | return -EBUSY; | ||
3343 | } | ||
3344 | dev->got_irq = 1; | ||
3345 | |||
3346 | /* reset and start controller to run state */ | ||
3347 | if (dev->stopped) { | ||
3348 | /* reset device controller */ | ||
3349 | langwell_udc_reset(dev); | ||
3350 | |||
3351 | /* reset ep0 dQH and endptctrl */ | ||
3352 | ep0_reset(dev); | ||
3353 | |||
3354 | /* start device if gadget is loaded */ | ||
3355 | if (dev->driver) | ||
3356 | langwell_udc_start(dev); | ||
3357 | } | ||
3358 | |||
3359 | /* reset USB status */ | ||
3360 | dev->usb_state = USB_STATE_ATTACHED; | ||
3361 | dev->ep0_state = WAIT_FOR_SETUP; | ||
3362 | dev->ep0_dir = USB_DIR_OUT; | ||
3363 | |||
3364 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
3365 | return 0; | ||
3366 | } | ||
3367 | |||
3368 | |||
3369 | /* pci driver shutdown */ | ||
3370 | static void langwell_udc_shutdown(struct pci_dev *pdev) | ||
3371 | { | ||
3372 | struct langwell_udc *dev = pci_get_drvdata(pdev); | ||
3373 | u32 usbmode; | ||
3374 | |||
3375 | dev_dbg(&dev->pdev->dev, "---> %s()\n", __func__); | ||
3376 | |||
3377 | /* reset controller mode to IDLE */ | ||
3378 | usbmode = readl(&dev->op_regs->usbmode); | ||
3379 | dev_dbg(&dev->pdev->dev, "usbmode = 0x%08x\n", usbmode); | ||
3380 | usbmode &= (~3 | MODE_IDLE); | ||
3381 | writel(usbmode, &dev->op_regs->usbmode); | ||
3382 | |||
3383 | dev_dbg(&dev->pdev->dev, "<--- %s()\n", __func__); | ||
3384 | } | ||
3385 | |||
3386 | /*-------------------------------------------------------------------------*/ | ||
3387 | |||
3388 | static const struct pci_device_id pci_ids[] = { { | ||
3389 | .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), | ||
3390 | .class_mask = ~0, | ||
3391 | .vendor = 0x8086, | ||
3392 | .device = 0x0811, | ||
3393 | .subvendor = PCI_ANY_ID, | ||
3394 | .subdevice = PCI_ANY_ID, | ||
3395 | }, { /* end: all zeroes */ } | ||
3396 | }; | ||
3397 | |||
3398 | MODULE_DEVICE_TABLE(pci, pci_ids); | ||
3399 | |||
3400 | |||
3401 | static struct pci_driver langwell_pci_driver = { | ||
3402 | .name = (char *) driver_name, | ||
3403 | .id_table = pci_ids, | ||
3404 | |||
3405 | .probe = langwell_udc_probe, | ||
3406 | .remove = langwell_udc_remove, | ||
3407 | |||
3408 | /* device controller suspend/resume */ | ||
3409 | .suspend = langwell_udc_suspend, | ||
3410 | .resume = langwell_udc_resume, | ||
3411 | |||
3412 | .shutdown = langwell_udc_shutdown, | ||
3413 | }; | ||
3414 | |||
3415 | |||
3416 | static int __init init(void) | ||
3417 | { | ||
3418 | return pci_register_driver(&langwell_pci_driver); | ||
3419 | } | ||
3420 | module_init(init); | ||
3421 | |||
3422 | |||
3423 | static void __exit cleanup(void) | ||
3424 | { | ||
3425 | pci_unregister_driver(&langwell_pci_driver); | ||
3426 | } | ||
3427 | module_exit(cleanup); | ||
3428 | |||
3429 | |||
3430 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
3431 | MODULE_AUTHOR("Xiaochen Shen <xiaochen.shen@intel.com>"); | ||
3432 | MODULE_VERSION(DRIVER_VERSION); | ||
3433 | MODULE_LICENSE("GPL"); | ||
3434 | |||
diff --git a/drivers/usb/gadget/langwell_udc.h b/drivers/usb/gadget/langwell_udc.h deleted file mode 100644 index 8c8087abb481..000000000000 --- a/drivers/usb/gadget/langwell_udc.h +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* | ||
2 | * Intel Langwell USB Device Controller driver | ||
3 | * Copyright (C) 2008-2009, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/usb/langwell_udc.h> | ||
11 | |||
12 | /*-------------------------------------------------------------------------*/ | ||
13 | |||
14 | /* driver data structures and utilities */ | ||
15 | |||
16 | /* | ||
17 | * dTD: Device Endpoint Transfer Descriptor | ||
18 | * describe to the device controller the location and quantity of | ||
19 | * data to be send/received for given transfer | ||
20 | */ | ||
21 | struct langwell_dtd { | ||
22 | u32 dtd_next; | ||
23 | /* bits 31:5, next transfer element pointer */ | ||
24 | #define DTD_NEXT(d) (((d)>>5)&0x7ffffff) | ||
25 | #define DTD_NEXT_MASK (0x7ffffff << 5) | ||
26 | /* terminate */ | ||
27 | #define DTD_TERM BIT(0) | ||
28 | /* bits 7:0, execution back states */ | ||
29 | u32 dtd_status:8; | ||
30 | #define DTD_STATUS(d) (((d)>>0)&0xff) | ||
31 | #define DTD_STS_ACTIVE BIT(7) /* active */ | ||
32 | #define DTD_STS_HALTED BIT(6) /* halted */ | ||
33 | #define DTD_STS_DBE BIT(5) /* data buffer error */ | ||
34 | #define DTD_STS_TRE BIT(3) /* transaction error */ | ||
35 | /* bits 9:8 */ | ||
36 | u32 dtd_res0:2; | ||
37 | /* bits 11:10, multipier override */ | ||
38 | u32 dtd_multo:2; | ||
39 | #define DTD_MULTO (BIT(11) | BIT(10)) | ||
40 | /* bits 14:12 */ | ||
41 | u32 dtd_res1:3; | ||
42 | /* bit 15, interrupt on complete */ | ||
43 | u32 dtd_ioc:1; | ||
44 | #define DTD_IOC BIT(15) | ||
45 | /* bits 30:16, total bytes */ | ||
46 | u32 dtd_total:15; | ||
47 | #define DTD_TOTAL(d) (((d)>>16)&0x7fff) | ||
48 | #define DTD_MAX_TRANSFER_LENGTH 0x4000 | ||
49 | /* bit 31 */ | ||
50 | u32 dtd_res2:1; | ||
51 | /* dTD buffer pointer page 0 to 4 */ | ||
52 | u32 dtd_buf[5]; | ||
53 | #define DTD_OFFSET_MASK 0xfff | ||
54 | /* bits 31:12, buffer pointer */ | ||
55 | #define DTD_BUFFER(d) (((d)>>12)&0x3ff) | ||
56 | /* bits 11:0, current offset */ | ||
57 | #define DTD_C_OFFSET(d) (((d)>>0)&0xfff) | ||
58 | /* bits 10:0, frame number */ | ||
59 | #define DTD_FRAME(d) (((d)>>0)&0x7ff) | ||
60 | |||
61 | /* driver-private parts */ | ||
62 | |||
63 | /* dtd dma address */ | ||
64 | dma_addr_t dtd_dma; | ||
65 | /* next dtd virtual address */ | ||
66 | struct langwell_dtd *next_dtd_virt; | ||
67 | }; | ||
68 | |||
69 | |||
70 | /* | ||
71 | * dQH: Device Endpoint Queue Head | ||
72 | * describe where all transfers are managed | ||
73 | * 48-byte data structure, aligned on 64-byte boundary | ||
74 | * | ||
75 | * These are associated with dTD structure | ||
76 | */ | ||
77 | struct langwell_dqh { | ||
78 | /* endpoint capabilities and characteristics */ | ||
79 | u32 dqh_res0:15; /* bits 14:0 */ | ||
80 | u32 dqh_ios:1; /* bit 15, interrupt on setup */ | ||
81 | #define DQH_IOS BIT(15) | ||
82 | u32 dqh_mpl:11; /* bits 26:16, maximum packet length */ | ||
83 | #define DQH_MPL (0x7ff << 16) | ||
84 | u32 dqh_res1:2; /* bits 28:27 */ | ||
85 | u32 dqh_zlt:1; /* bit 29, zero length termination */ | ||
86 | #define DQH_ZLT BIT(29) | ||
87 | u32 dqh_mult:2; /* bits 31:30 */ | ||
88 | #define DQH_MULT (BIT(30) | BIT(31)) | ||
89 | |||
90 | /* current dTD pointer */ | ||
91 | u32 dqh_current; /* locate the transfer in progress */ | ||
92 | #define DQH_C_DTD(e) \ | ||
93 | (((e)>>5)&0x7ffffff) /* bits 31:5, current dTD pointer */ | ||
94 | |||
95 | /* transfer overlay, hardware parts of a struct langwell_dtd */ | ||
96 | u32 dtd_next; | ||
97 | u32 dtd_status:8; /* bits 7:0, execution back states */ | ||
98 | u32 dtd_res0:2; /* bits 9:8 */ | ||
99 | u32 dtd_multo:2; /* bits 11:10, multipier override */ | ||
100 | u32 dtd_res1:3; /* bits 14:12 */ | ||
101 | u32 dtd_ioc:1; /* bit 15, interrupt on complete */ | ||
102 | u32 dtd_total:15; /* bits 30:16, total bytes */ | ||
103 | u32 dtd_res2:1; /* bit 31 */ | ||
104 | u32 dtd_buf[5]; /* dTD buffer pointer page 0 to 4 */ | ||
105 | |||
106 | u32 dqh_res2; | ||
107 | struct usb_ctrlrequest dqh_setup; /* setup packet buffer */ | ||
108 | } __attribute__ ((aligned(64))); | ||
109 | |||
110 | |||
111 | /* endpoint data structure */ | ||
112 | struct langwell_ep { | ||
113 | struct usb_ep ep; | ||
114 | dma_addr_t dma; | ||
115 | struct langwell_udc *dev; | ||
116 | unsigned long irqs; | ||
117 | struct list_head queue; | ||
118 | struct langwell_dqh *dqh; | ||
119 | const struct usb_endpoint_descriptor *desc; | ||
120 | char name[14]; | ||
121 | unsigned stopped:1, | ||
122 | ep_type:2, | ||
123 | ep_num:8; | ||
124 | }; | ||
125 | |||
126 | |||
127 | /* request data structure */ | ||
128 | struct langwell_request { | ||
129 | struct usb_request req; | ||
130 | struct langwell_dtd *dtd, *head, *tail; | ||
131 | struct langwell_ep *ep; | ||
132 | dma_addr_t dtd_dma; | ||
133 | struct list_head queue; | ||
134 | unsigned dtd_count; | ||
135 | unsigned mapped:1; | ||
136 | }; | ||
137 | |||
138 | |||
139 | /* ep0 transfer state */ | ||
140 | enum ep0_state { | ||
141 | WAIT_FOR_SETUP, | ||
142 | DATA_STATE_XMIT, | ||
143 | DATA_STATE_NEED_ZLP, | ||
144 | WAIT_FOR_OUT_STATUS, | ||
145 | DATA_STATE_RECV, | ||
146 | }; | ||
147 | |||
148 | |||
149 | /* device suspend state */ | ||
150 | enum lpm_state { | ||
151 | LPM_L0, /* on */ | ||
152 | LPM_L1, /* LPM L1 sleep */ | ||
153 | LPM_L2, /* suspend */ | ||
154 | LPM_L3, /* off */ | ||
155 | }; | ||
156 | |||
157 | |||
158 | /* device data structure */ | ||
159 | struct langwell_udc { | ||
160 | /* each pci device provides one gadget, several endpoints */ | ||
161 | struct usb_gadget gadget; | ||
162 | spinlock_t lock; /* device lock */ | ||
163 | struct langwell_ep *ep; | ||
164 | struct usb_gadget_driver *driver; | ||
165 | struct usb_phy *transceiver; | ||
166 | u8 dev_addr; | ||
167 | u32 usb_state; | ||
168 | u32 resume_state; | ||
169 | u32 bus_reset; | ||
170 | enum lpm_state lpm_state; | ||
171 | enum ep0_state ep0_state; | ||
172 | u32 ep0_dir; | ||
173 | u16 dciversion; | ||
174 | unsigned ep_max; | ||
175 | unsigned devcap:1, | ||
176 | enabled:1, | ||
177 | region:1, | ||
178 | got_irq:1, | ||
179 | powered:1, | ||
180 | remote_wakeup:1, | ||
181 | rate:1, | ||
182 | is_reset:1, | ||
183 | softconnected:1, | ||
184 | vbus_active:1, | ||
185 | suspended:1, | ||
186 | stopped:1, | ||
187 | lpm:1, /* LPM capability */ | ||
188 | has_sram:1, /* SRAM caching */ | ||
189 | got_sram:1; | ||
190 | |||
191 | /* pci state used to access those endpoints */ | ||
192 | struct pci_dev *pdev; | ||
193 | |||
194 | /* Langwell otg transceiver */ | ||
195 | struct langwell_otg *lotg; | ||
196 | |||
197 | /* control registers */ | ||
198 | struct langwell_cap_regs __iomem *cap_regs; | ||
199 | struct langwell_op_regs __iomem *op_regs; | ||
200 | |||
201 | struct usb_ctrlrequest local_setup_buff; | ||
202 | struct langwell_dqh *ep_dqh; | ||
203 | size_t ep_dqh_size; | ||
204 | dma_addr_t ep_dqh_dma; | ||
205 | |||
206 | /* ep0 status request */ | ||
207 | struct langwell_request *status_req; | ||
208 | |||
209 | /* dma pool */ | ||
210 | struct dma_pool *dtd_pool; | ||
211 | |||
212 | /* make sure release() is done */ | ||
213 | struct completion *done; | ||
214 | |||
215 | /* for private SRAM caching */ | ||
216 | unsigned int sram_addr; | ||
217 | unsigned int sram_size; | ||
218 | |||
219 | /* device status data for get_status request */ | ||
220 | u16 dev_status; | ||
221 | }; | ||
222 | |||
223 | #define gadget_to_langwell(g) container_of((g), struct langwell_udc, gadget) | ||
224 | |||
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c new file mode 100644 index 000000000000..262acfd53e32 --- /dev/null +++ b/drivers/usb/gadget/lpc32xx_udc.c | |||
@@ -0,0 +1,3538 @@ | |||
1 | /* | ||
2 | * USB Gadget driver for LPC32xx | ||
3 | * | ||
4 | * Authors: | ||
5 | * Kevin Wells <kevin.wells@nxp.com> | ||
6 | * Mike James | ||
7 | * Roland Stigge <stigge@antcom.de> | ||
8 | * | ||
9 | * Copyright (C) 2006 Philips Semiconductors | ||
10 | * Copyright (C) 2009 NXP Semiconductors | ||
11 | * Copyright (C) 2012 Roland Stigge | ||
12 | * | ||
13 | * Note: This driver is based on original work done by Mike James for | ||
14 | * the LPC3180. | ||
15 | * | ||
16 | * This program is free software; you can redistribute it and/or modify | ||
17 | * it under the terms of the GNU General Public License as published by | ||
18 | * the Free Software Foundation; either version 2 of the License, or | ||
19 | * (at your option) any later version. | ||
20 | * | ||
21 | * This program is distributed in the hope that it will be useful, | ||
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
24 | * GNU General Public License for more details. | ||
25 | * | ||
26 | * You should have received a copy of the GNU General Public License | ||
27 | * along with this program; if not, write to the Free Software | ||
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
29 | */ | ||
30 | |||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/platform_device.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/ioport.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/errno.h> | ||
38 | #include <linux/init.h> | ||
39 | #include <linux/list.h> | ||
40 | #include <linux/interrupt.h> | ||
41 | #include <linux/proc_fs.h> | ||
42 | #include <linux/clk.h> | ||
43 | #include <linux/usb/ch9.h> | ||
44 | #include <linux/usb/gadget.h> | ||
45 | #include <linux/i2c.h> | ||
46 | #include <linux/kthread.h> | ||
47 | #include <linux/freezer.h> | ||
48 | #include <linux/dma-mapping.h> | ||
49 | #include <linux/dmapool.h> | ||
50 | #include <linux/workqueue.h> | ||
51 | #include <linux/of.h> | ||
52 | #include <linux/usb/isp1301.h> | ||
53 | |||
54 | #include <asm/byteorder.h> | ||
55 | #include <mach/hardware.h> | ||
56 | #include <linux/io.h> | ||
57 | #include <asm/irq.h> | ||
58 | #include <asm/system.h> | ||
59 | |||
60 | #include <mach/platform.h> | ||
61 | #include <mach/irqs.h> | ||
62 | #include <mach/board.h> | ||
63 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
64 | #include <linux/seq_file.h> | ||
65 | #endif | ||
66 | |||
67 | /* | ||
68 | * USB device configuration structure | ||
69 | */ | ||
70 | typedef void (*usc_chg_event)(int); | ||
71 | struct lpc32xx_usbd_cfg { | ||
72 | int vbus_drv_pol; /* 0=active low drive for VBUS via ISP1301 */ | ||
73 | usc_chg_event conn_chgb; /* Connection change event (optional) */ | ||
74 | usc_chg_event susp_chgb; /* Suspend/resume event (optional) */ | ||
75 | usc_chg_event rmwk_chgb; /* Enable/disable remote wakeup */ | ||
76 | }; | ||
77 | |||
78 | /* | ||
79 | * controller driver data structures | ||
80 | */ | ||
81 | |||
82 | /* 16 endpoints (not to be confused with 32 hardware endpoints) */ | ||
83 | #define NUM_ENDPOINTS 16 | ||
84 | |||
85 | /* | ||
86 | * IRQ indices make reading the code a little easier | ||
87 | */ | ||
88 | #define IRQ_USB_LP 0 | ||
89 | #define IRQ_USB_HP 1 | ||
90 | #define IRQ_USB_DEVDMA 2 | ||
91 | #define IRQ_USB_ATX 3 | ||
92 | |||
93 | #define EP_OUT 0 /* RX (from host) */ | ||
94 | #define EP_IN 1 /* TX (to host) */ | ||
95 | |||
96 | /* Returns the interrupt mask for the selected hardware endpoint */ | ||
97 | #define EP_MASK_SEL(ep, dir) (1 << (((ep) * 2) + dir)) | ||
98 | |||
99 | #define EP_INT_TYPE 0 | ||
100 | #define EP_ISO_TYPE 1 | ||
101 | #define EP_BLK_TYPE 2 | ||
102 | #define EP_CTL_TYPE 3 | ||
103 | |||
104 | /* EP0 states */ | ||
105 | #define WAIT_FOR_SETUP 0 /* Wait for setup packet */ | ||
106 | #define DATA_IN 1 /* Expect dev->host transfer */ | ||
107 | #define DATA_OUT 2 /* Expect host->dev transfer */ | ||
108 | |||
109 | /* DD (DMA Descriptor) structure, requires word alignment, this is already | ||
110 | * defined in the LPC32XX USB device header file, but this version is slightly | ||
111 | * modified to tag some work data with each DMA descriptor. */ | ||
112 | struct lpc32xx_usbd_dd_gad { | ||
113 | u32 dd_next_phy; | ||
114 | u32 dd_setup; | ||
115 | u32 dd_buffer_addr; | ||
116 | u32 dd_status; | ||
117 | u32 dd_iso_ps_mem_addr; | ||
118 | u32 this_dma; | ||
119 | u32 iso_status[6]; /* 5 spare */ | ||
120 | u32 dd_next_v; | ||
121 | }; | ||
122 | |||
123 | /* | ||
124 | * Logical endpoint structure | ||
125 | */ | ||
126 | struct lpc32xx_ep { | ||
127 | struct usb_ep ep; | ||
128 | struct list_head queue; | ||
129 | struct lpc32xx_udc *udc; | ||
130 | |||
131 | u32 hwep_num_base; /* Physical hardware EP */ | ||
132 | u32 hwep_num; /* Maps to hardware endpoint */ | ||
133 | u32 maxpacket; | ||
134 | u32 lep; | ||
135 | |||
136 | bool is_in; | ||
137 | bool req_pending; | ||
138 | u32 eptype; | ||
139 | |||
140 | u32 totalints; | ||
141 | |||
142 | bool wedge; | ||
143 | |||
144 | const struct usb_endpoint_descriptor *desc; | ||
145 | }; | ||
146 | |||
147 | /* | ||
148 | * Common UDC structure | ||
149 | */ | ||
150 | struct lpc32xx_udc { | ||
151 | struct usb_gadget gadget; | ||
152 | struct usb_gadget_driver *driver; | ||
153 | struct platform_device *pdev; | ||
154 | struct device *dev; | ||
155 | struct dentry *pde; | ||
156 | spinlock_t lock; | ||
157 | struct i2c_client *isp1301_i2c_client; | ||
158 | |||
159 | /* Board and device specific */ | ||
160 | struct lpc32xx_usbd_cfg *board; | ||
161 | u32 io_p_start; | ||
162 | u32 io_p_size; | ||
163 | void __iomem *udp_baseaddr; | ||
164 | int udp_irq[4]; | ||
165 | struct clk *usb_pll_clk; | ||
166 | struct clk *usb_slv_clk; | ||
167 | |||
168 | /* DMA support */ | ||
169 | u32 *udca_v_base; | ||
170 | u32 udca_p_base; | ||
171 | struct dma_pool *dd_cache; | ||
172 | |||
173 | /* Common EP and control data */ | ||
174 | u32 enabled_devints; | ||
175 | u32 enabled_hwepints; | ||
176 | u32 dev_status; | ||
177 | u32 realized_eps; | ||
178 | |||
179 | /* VBUS detection, pullup, and power flags */ | ||
180 | u8 vbus; | ||
181 | u8 last_vbus; | ||
182 | int pullup; | ||
183 | int poweron; | ||
184 | |||
185 | /* Work queues related to I2C support */ | ||
186 | struct work_struct pullup_job; | ||
187 | struct work_struct vbus_job; | ||
188 | struct work_struct power_job; | ||
189 | |||
190 | /* USB device peripheral - various */ | ||
191 | struct lpc32xx_ep ep[NUM_ENDPOINTS]; | ||
192 | bool enabled; | ||
193 | bool clocked; | ||
194 | bool suspended; | ||
195 | bool selfpowered; | ||
196 | int ep0state; | ||
197 | atomic_t enabled_ep_cnt; | ||
198 | wait_queue_head_t ep_disable_wait_queue; | ||
199 | }; | ||
200 | |||
201 | /* | ||
202 | * Endpoint request | ||
203 | */ | ||
204 | struct lpc32xx_request { | ||
205 | struct usb_request req; | ||
206 | struct list_head queue; | ||
207 | struct lpc32xx_usbd_dd_gad *dd_desc_ptr; | ||
208 | bool mapped; | ||
209 | bool send_zlp; | ||
210 | }; | ||
211 | |||
212 | static inline struct lpc32xx_udc *to_udc(struct usb_gadget *g) | ||
213 | { | ||
214 | return container_of(g, struct lpc32xx_udc, gadget); | ||
215 | } | ||
216 | |||
217 | #define ep_dbg(epp, fmt, arg...) \ | ||
218 | dev_dbg(epp->udc->dev, "%s: " fmt, __func__, ## arg) | ||
219 | #define ep_err(epp, fmt, arg...) \ | ||
220 | dev_err(epp->udc->dev, "%s: " fmt, __func__, ## arg) | ||
221 | #define ep_info(epp, fmt, arg...) \ | ||
222 | dev_info(epp->udc->dev, "%s: " fmt, __func__, ## arg) | ||
223 | #define ep_warn(epp, fmt, arg...) \ | ||
224 | dev_warn(epp->udc->dev, "%s:" fmt, __func__, ## arg) | ||
225 | |||
226 | #define UDCA_BUFF_SIZE (128) | ||
227 | |||
228 | /* TODO: When the clock framework is introduced in LPC32xx, IO_ADDRESS will | ||
229 | * be replaced with an inremap()ed pointer, see USB_OTG_CLK_CTRL() | ||
230 | * */ | ||
231 | #define USB_CTRL IO_ADDRESS(LPC32XX_CLK_PM_BASE + 0x64) | ||
232 | #define USB_CLOCK_MASK (AHB_M_CLOCK_ON | OTG_CLOCK_ON | \ | ||
233 | DEV_CLOCK_ON | I2C_CLOCK_ON) | ||
234 | |||
235 | /* USB_CTRL bit defines */ | ||
236 | #define USB_SLAVE_HCLK_EN (1 << 24) | ||
237 | #define USB_HOST_NEED_CLK_EN (1 << 21) | ||
238 | #define USB_DEV_NEED_CLK_EN (1 << 22) | ||
239 | |||
240 | #define USB_OTG_CLK_CTRL(udc) ((udc)->udp_baseaddr + 0xFF4) | ||
241 | #define USB_OTG_CLK_STAT(udc) ((udc)->udp_baseaddr + 0xFF8) | ||
242 | |||
243 | /* USB_OTG_CLK_CTRL bit defines */ | ||
244 | #define AHB_M_CLOCK_ON (1 << 4) | ||
245 | #define OTG_CLOCK_ON (1 << 3) | ||
246 | #define I2C_CLOCK_ON (1 << 2) | ||
247 | #define DEV_CLOCK_ON (1 << 1) | ||
248 | #define HOST_CLOCK_ON (1 << 0) | ||
249 | |||
250 | #define USB_OTG_STAT_CONTROL(udc) (udc->udp_baseaddr + 0x110) | ||
251 | |||
252 | /* USB_OTG_STAT_CONTROL bit defines */ | ||
253 | #define TRANSPARENT_I2C_EN (1 << 7) | ||
254 | #define HOST_EN (1 << 0) | ||
255 | |||
256 | /********************************************************************** | ||
257 | * USB device controller register offsets | ||
258 | **********************************************************************/ | ||
259 | |||
260 | #define USBD_DEVINTST(x) ((x) + 0x200) | ||
261 | #define USBD_DEVINTEN(x) ((x) + 0x204) | ||
262 | #define USBD_DEVINTCLR(x) ((x) + 0x208) | ||
263 | #define USBD_DEVINTSET(x) ((x) + 0x20C) | ||
264 | #define USBD_CMDCODE(x) ((x) + 0x210) | ||
265 | #define USBD_CMDDATA(x) ((x) + 0x214) | ||
266 | #define USBD_RXDATA(x) ((x) + 0x218) | ||
267 | #define USBD_TXDATA(x) ((x) + 0x21C) | ||
268 | #define USBD_RXPLEN(x) ((x) + 0x220) | ||
269 | #define USBD_TXPLEN(x) ((x) + 0x224) | ||
270 | #define USBD_CTRL(x) ((x) + 0x228) | ||
271 | #define USBD_DEVINTPRI(x) ((x) + 0x22C) | ||
272 | #define USBD_EPINTST(x) ((x) + 0x230) | ||
273 | #define USBD_EPINTEN(x) ((x) + 0x234) | ||
274 | #define USBD_EPINTCLR(x) ((x) + 0x238) | ||
275 | #define USBD_EPINTSET(x) ((x) + 0x23C) | ||
276 | #define USBD_EPINTPRI(x) ((x) + 0x240) | ||
277 | #define USBD_REEP(x) ((x) + 0x244) | ||
278 | #define USBD_EPIND(x) ((x) + 0x248) | ||
279 | #define USBD_EPMAXPSIZE(x) ((x) + 0x24C) | ||
280 | /* DMA support registers only below */ | ||
281 | /* Set, clear, or get enabled state of the DMA request status. If | ||
282 | * enabled, an IN or OUT token will start a DMA transfer for the EP */ | ||
283 | #define USBD_DMARST(x) ((x) + 0x250) | ||
284 | #define USBD_DMARCLR(x) ((x) + 0x254) | ||
285 | #define USBD_DMARSET(x) ((x) + 0x258) | ||
286 | /* DMA UDCA head pointer */ | ||
287 | #define USBD_UDCAH(x) ((x) + 0x280) | ||
288 | /* EP DMA status, enable, and disable. This is used to specifically | ||
289 | * enabled or disable DMA for a specific EP */ | ||
290 | #define USBD_EPDMAST(x) ((x) + 0x284) | ||
291 | #define USBD_EPDMAEN(x) ((x) + 0x288) | ||
292 | #define USBD_EPDMADIS(x) ((x) + 0x28C) | ||
293 | /* DMA master interrupts enable and pending interrupts */ | ||
294 | #define USBD_DMAINTST(x) ((x) + 0x290) | ||
295 | #define USBD_DMAINTEN(x) ((x) + 0x294) | ||
296 | /* DMA end of transfer interrupt enable, disable, status */ | ||
297 | #define USBD_EOTINTST(x) ((x) + 0x2A0) | ||
298 | #define USBD_EOTINTCLR(x) ((x) + 0x2A4) | ||
299 | #define USBD_EOTINTSET(x) ((x) + 0x2A8) | ||
300 | /* New DD request interrupt enable, disable, status */ | ||
301 | #define USBD_NDDRTINTST(x) ((x) + 0x2AC) | ||
302 | #define USBD_NDDRTINTCLR(x) ((x) + 0x2B0) | ||
303 | #define USBD_NDDRTINTSET(x) ((x) + 0x2B4) | ||
304 | /* DMA error interrupt enable, disable, status */ | ||
305 | #define USBD_SYSERRTINTST(x) ((x) + 0x2B8) | ||
306 | #define USBD_SYSERRTINTCLR(x) ((x) + 0x2BC) | ||
307 | #define USBD_SYSERRTINTSET(x) ((x) + 0x2C0) | ||
308 | |||
309 | /********************************************************************** | ||
310 | * USBD_DEVINTST/USBD_DEVINTEN/USBD_DEVINTCLR/USBD_DEVINTSET/ | ||
311 | * USBD_DEVINTPRI register definitions | ||
312 | **********************************************************************/ | ||
313 | #define USBD_ERR_INT (1 << 9) | ||
314 | #define USBD_EP_RLZED (1 << 8) | ||
315 | #define USBD_TXENDPKT (1 << 7) | ||
316 | #define USBD_RXENDPKT (1 << 6) | ||
317 | #define USBD_CDFULL (1 << 5) | ||
318 | #define USBD_CCEMPTY (1 << 4) | ||
319 | #define USBD_DEV_STAT (1 << 3) | ||
320 | #define USBD_EP_SLOW (1 << 2) | ||
321 | #define USBD_EP_FAST (1 << 1) | ||
322 | #define USBD_FRAME (1 << 0) | ||
323 | |||
324 | /********************************************************************** | ||
325 | * USBD_EPINTST/USBD_EPINTEN/USBD_EPINTCLR/USBD_EPINTSET/ | ||
326 | * USBD_EPINTPRI register definitions | ||
327 | **********************************************************************/ | ||
328 | /* End point selection macro (RX) */ | ||
329 | #define USBD_RX_EP_SEL(e) (1 << ((e) << 1)) | ||
330 | |||
331 | /* End point selection macro (TX) */ | ||
332 | #define USBD_TX_EP_SEL(e) (1 << (((e) << 1) + 1)) | ||
333 | |||
334 | /********************************************************************** | ||
335 | * USBD_REEP/USBD_DMARST/USBD_DMARCLR/USBD_DMARSET/USBD_EPDMAST/ | ||
336 | * USBD_EPDMAEN/USBD_EPDMADIS/ | ||
337 | * USBD_NDDRTINTST/USBD_NDDRTINTCLR/USBD_NDDRTINTSET/ | ||
338 | * USBD_EOTINTST/USBD_EOTINTCLR/USBD_EOTINTSET/ | ||
339 | * USBD_SYSERRTINTST/USBD_SYSERRTINTCLR/USBD_SYSERRTINTSET | ||
340 | * register definitions | ||
341 | **********************************************************************/ | ||
342 | /* Endpoint selection macro */ | ||
343 | #define USBD_EP_SEL(e) (1 << (e)) | ||
344 | |||
345 | /********************************************************************** | ||
346 | * SBD_DMAINTST/USBD_DMAINTEN | ||
347 | **********************************************************************/ | ||
348 | #define USBD_SYS_ERR_INT (1 << 2) | ||
349 | #define USBD_NEW_DD_INT (1 << 1) | ||
350 | #define USBD_EOT_INT (1 << 0) | ||
351 | |||
352 | /********************************************************************** | ||
353 | * USBD_RXPLEN register definitions | ||
354 | **********************************************************************/ | ||
355 | #define USBD_PKT_RDY (1 << 11) | ||
356 | #define USBD_DV (1 << 10) | ||
357 | #define USBD_PK_LEN_MASK 0x3FF | ||
358 | |||
359 | /********************************************************************** | ||
360 | * USBD_CTRL register definitions | ||
361 | **********************************************************************/ | ||
362 | #define USBD_LOG_ENDPOINT(e) ((e) << 2) | ||
363 | #define USBD_WR_EN (1 << 1) | ||
364 | #define USBD_RD_EN (1 << 0) | ||
365 | |||
366 | /********************************************************************** | ||
367 | * USBD_CMDCODE register definitions | ||
368 | **********************************************************************/ | ||
369 | #define USBD_CMD_CODE(c) ((c) << 16) | ||
370 | #define USBD_CMD_PHASE(p) ((p) << 8) | ||
371 | |||
372 | /********************************************************************** | ||
373 | * USBD_DMARST/USBD_DMARCLR/USBD_DMARSET register definitions | ||
374 | **********************************************************************/ | ||
375 | #define USBD_DMAEP(e) (1 << (e)) | ||
376 | |||
377 | /* DD (DMA Descriptor) structure, requires word alignment */ | ||
378 | struct lpc32xx_usbd_dd { | ||
379 | u32 *dd_next; | ||
380 | u32 dd_setup; | ||
381 | u32 dd_buffer_addr; | ||
382 | u32 dd_status; | ||
383 | u32 dd_iso_ps_mem_addr; | ||
384 | }; | ||
385 | |||
386 | /* dd_setup bit defines */ | ||
387 | #define DD_SETUP_ATLE_DMA_MODE 0x01 | ||
388 | #define DD_SETUP_NEXT_DD_VALID 0x04 | ||
389 | #define DD_SETUP_ISO_EP 0x10 | ||
390 | #define DD_SETUP_PACKETLEN(n) (((n) & 0x7FF) << 5) | ||
391 | #define DD_SETUP_DMALENBYTES(n) (((n) & 0xFFFF) << 16) | ||
392 | |||
393 | /* dd_status bit defines */ | ||
394 | #define DD_STATUS_DD_RETIRED 0x01 | ||
395 | #define DD_STATUS_STS_MASK 0x1E | ||
396 | #define DD_STATUS_STS_NS 0x00 /* Not serviced */ | ||
397 | #define DD_STATUS_STS_BS 0x02 /* Being serviced */ | ||
398 | #define DD_STATUS_STS_NC 0x04 /* Normal completion */ | ||
399 | #define DD_STATUS_STS_DUR 0x06 /* Data underrun (short packet) */ | ||
400 | #define DD_STATUS_STS_DOR 0x08 /* Data overrun */ | ||
401 | #define DD_STATUS_STS_SE 0x12 /* System error */ | ||
402 | #define DD_STATUS_PKT_VAL 0x20 /* Packet valid */ | ||
403 | #define DD_STATUS_LSB_EX 0x40 /* LS byte extracted (ATLE) */ | ||
404 | #define DD_STATUS_MSB_EX 0x80 /* MS byte extracted (ATLE) */ | ||
405 | #define DD_STATUS_MLEN(n) (((n) >> 8) & 0x3F) | ||
406 | #define DD_STATUS_CURDMACNT(n) (((n) >> 16) & 0xFFFF) | ||
407 | |||
408 | /* | ||
409 | * | ||
410 | * Protocol engine bits below | ||
411 | * | ||
412 | */ | ||
413 | /* Device Interrupt Bit Definitions */ | ||
414 | #define FRAME_INT 0x00000001 | ||
415 | #define EP_FAST_INT 0x00000002 | ||
416 | #define EP_SLOW_INT 0x00000004 | ||
417 | #define DEV_STAT_INT 0x00000008 | ||
418 | #define CCEMTY_INT 0x00000010 | ||
419 | #define CDFULL_INT 0x00000020 | ||
420 | #define RxENDPKT_INT 0x00000040 | ||
421 | #define TxENDPKT_INT 0x00000080 | ||
422 | #define EP_RLZED_INT 0x00000100 | ||
423 | #define ERR_INT 0x00000200 | ||
424 | |||
425 | /* Rx & Tx Packet Length Definitions */ | ||
426 | #define PKT_LNGTH_MASK 0x000003FF | ||
427 | #define PKT_DV 0x00000400 | ||
428 | #define PKT_RDY 0x00000800 | ||
429 | |||
430 | /* USB Control Definitions */ | ||
431 | #define CTRL_RD_EN 0x00000001 | ||
432 | #define CTRL_WR_EN 0x00000002 | ||
433 | |||
434 | /* Command Codes */ | ||
435 | #define CMD_SET_ADDR 0x00D00500 | ||
436 | #define CMD_CFG_DEV 0x00D80500 | ||
437 | #define CMD_SET_MODE 0x00F30500 | ||
438 | #define CMD_RD_FRAME 0x00F50500 | ||
439 | #define DAT_RD_FRAME 0x00F50200 | ||
440 | #define CMD_RD_TEST 0x00FD0500 | ||
441 | #define DAT_RD_TEST 0x00FD0200 | ||
442 | #define CMD_SET_DEV_STAT 0x00FE0500 | ||
443 | #define CMD_GET_DEV_STAT 0x00FE0500 | ||
444 | #define DAT_GET_DEV_STAT 0x00FE0200 | ||
445 | #define CMD_GET_ERR_CODE 0x00FF0500 | ||
446 | #define DAT_GET_ERR_CODE 0x00FF0200 | ||
447 | #define CMD_RD_ERR_STAT 0x00FB0500 | ||
448 | #define DAT_RD_ERR_STAT 0x00FB0200 | ||
449 | #define DAT_WR_BYTE(x) (0x00000100 | ((x) << 16)) | ||
450 | #define CMD_SEL_EP(x) (0x00000500 | ((x) << 16)) | ||
451 | #define DAT_SEL_EP(x) (0x00000200 | ((x) << 16)) | ||
452 | #define CMD_SEL_EP_CLRI(x) (0x00400500 | ((x) << 16)) | ||
453 | #define DAT_SEL_EP_CLRI(x) (0x00400200 | ((x) << 16)) | ||
454 | #define CMD_SET_EP_STAT(x) (0x00400500 | ((x) << 16)) | ||
455 | #define CMD_CLR_BUF 0x00F20500 | ||
456 | #define DAT_CLR_BUF 0x00F20200 | ||
457 | #define CMD_VALID_BUF 0x00FA0500 | ||
458 | |||
459 | /* Device Address Register Definitions */ | ||
460 | #define DEV_ADDR_MASK 0x7F | ||
461 | #define DEV_EN 0x80 | ||
462 | |||
463 | /* Device Configure Register Definitions */ | ||
464 | #define CONF_DVICE 0x01 | ||
465 | |||
466 | /* Device Mode Register Definitions */ | ||
467 | #define AP_CLK 0x01 | ||
468 | #define INAK_CI 0x02 | ||
469 | #define INAK_CO 0x04 | ||
470 | #define INAK_II 0x08 | ||
471 | #define INAK_IO 0x10 | ||
472 | #define INAK_BI 0x20 | ||
473 | #define INAK_BO 0x40 | ||
474 | |||
475 | /* Device Status Register Definitions */ | ||
476 | #define DEV_CON 0x01 | ||
477 | #define DEV_CON_CH 0x02 | ||
478 | #define DEV_SUS 0x04 | ||
479 | #define DEV_SUS_CH 0x08 | ||
480 | #define DEV_RST 0x10 | ||
481 | |||
482 | /* Error Code Register Definitions */ | ||
483 | #define ERR_EC_MASK 0x0F | ||
484 | #define ERR_EA 0x10 | ||
485 | |||
486 | /* Error Status Register Definitions */ | ||
487 | #define ERR_PID 0x01 | ||
488 | #define ERR_UEPKT 0x02 | ||
489 | #define ERR_DCRC 0x04 | ||
490 | #define ERR_TIMOUT 0x08 | ||
491 | #define ERR_EOP 0x10 | ||
492 | #define ERR_B_OVRN 0x20 | ||
493 | #define ERR_BTSTF 0x40 | ||
494 | #define ERR_TGL 0x80 | ||
495 | |||
496 | /* Endpoint Select Register Definitions */ | ||
497 | #define EP_SEL_F 0x01 | ||
498 | #define EP_SEL_ST 0x02 | ||
499 | #define EP_SEL_STP 0x04 | ||
500 | #define EP_SEL_PO 0x08 | ||
501 | #define EP_SEL_EPN 0x10 | ||
502 | #define EP_SEL_B_1_FULL 0x20 | ||
503 | #define EP_SEL_B_2_FULL 0x40 | ||
504 | |||
505 | /* Endpoint Status Register Definitions */ | ||
506 | #define EP_STAT_ST 0x01 | ||
507 | #define EP_STAT_DA 0x20 | ||
508 | #define EP_STAT_RF_MO 0x40 | ||
509 | #define EP_STAT_CND_ST 0x80 | ||
510 | |||
511 | /* Clear Buffer Register Definitions */ | ||
512 | #define CLR_BUF_PO 0x01 | ||
513 | |||
514 | /* DMA Interrupt Bit Definitions */ | ||
515 | #define EOT_INT 0x01 | ||
516 | #define NDD_REQ_INT 0x02 | ||
517 | #define SYS_ERR_INT 0x04 | ||
518 | |||
519 | #define DRIVER_VERSION "1.03" | ||
520 | static const char driver_name[] = "lpc32xx_udc"; | ||
521 | |||
522 | /* | ||
523 | * | ||
524 | * proc interface support | ||
525 | * | ||
526 | */ | ||
527 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
528 | static char *epnames[] = {"INT", "ISO", "BULK", "CTRL"}; | ||
529 | static const char debug_filename[] = "driver/udc"; | ||
530 | |||
531 | static void proc_ep_show(struct seq_file *s, struct lpc32xx_ep *ep) | ||
532 | { | ||
533 | struct lpc32xx_request *req; | ||
534 | |||
535 | seq_printf(s, "\n"); | ||
536 | seq_printf(s, "%12s, maxpacket %4d %3s", | ||
537 | ep->ep.name, ep->ep.maxpacket, | ||
538 | ep->is_in ? "in" : "out"); | ||
539 | seq_printf(s, " type %4s", epnames[ep->eptype]); | ||
540 | seq_printf(s, " ints: %12d", ep->totalints); | ||
541 | |||
542 | if (list_empty(&ep->queue)) | ||
543 | seq_printf(s, "\t(queue empty)\n"); | ||
544 | else { | ||
545 | list_for_each_entry(req, &ep->queue, queue) { | ||
546 | u32 length = req->req.actual; | ||
547 | |||
548 | seq_printf(s, "\treq %p len %d/%d buf %p\n", | ||
549 | &req->req, length, | ||
550 | req->req.length, req->req.buf); | ||
551 | } | ||
552 | } | ||
553 | } | ||
554 | |||
555 | static int proc_udc_show(struct seq_file *s, void *unused) | ||
556 | { | ||
557 | struct lpc32xx_udc *udc = s->private; | ||
558 | struct lpc32xx_ep *ep; | ||
559 | unsigned long flags; | ||
560 | |||
561 | seq_printf(s, "%s: version %s\n", driver_name, DRIVER_VERSION); | ||
562 | |||
563 | spin_lock_irqsave(&udc->lock, flags); | ||
564 | |||
565 | seq_printf(s, "vbus %s, pullup %s, %s powered%s, gadget %s\n\n", | ||
566 | udc->vbus ? "present" : "off", | ||
567 | udc->enabled ? (udc->vbus ? "active" : "enabled") : | ||
568 | "disabled", | ||
569 | udc->selfpowered ? "self" : "VBUS", | ||
570 | udc->suspended ? ", suspended" : "", | ||
571 | udc->driver ? udc->driver->driver.name : "(none)"); | ||
572 | |||
573 | if (udc->enabled && udc->vbus) { | ||
574 | proc_ep_show(s, &udc->ep[0]); | ||
575 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | ||
576 | if (ep->desc) | ||
577 | proc_ep_show(s, ep); | ||
578 | } | ||
579 | } | ||
580 | |||
581 | spin_unlock_irqrestore(&udc->lock, flags); | ||
582 | |||
583 | return 0; | ||
584 | } | ||
585 | |||
586 | static int proc_udc_open(struct inode *inode, struct file *file) | ||
587 | { | ||
588 | return single_open(file, proc_udc_show, PDE(inode)->data); | ||
589 | } | ||
590 | |||
591 | static const struct file_operations proc_ops = { | ||
592 | .owner = THIS_MODULE, | ||
593 | .open = proc_udc_open, | ||
594 | .read = seq_read, | ||
595 | .llseek = seq_lseek, | ||
596 | .release = single_release, | ||
597 | }; | ||
598 | |||
599 | static void create_debug_file(struct lpc32xx_udc *udc) | ||
600 | { | ||
601 | udc->pde = debugfs_create_file(debug_filename, 0, NULL, udc, &proc_ops); | ||
602 | } | ||
603 | |||
604 | static void remove_debug_file(struct lpc32xx_udc *udc) | ||
605 | { | ||
606 | if (udc->pde) | ||
607 | debugfs_remove(udc->pde); | ||
608 | } | ||
609 | |||
610 | #else | ||
611 | static inline void create_debug_file(struct lpc32xx_udc *udc) {} | ||
612 | static inline void remove_debug_file(struct lpc32xx_udc *udc) {} | ||
613 | #endif | ||
614 | |||
615 | /* Primary initialization sequence for the ISP1301 transceiver */ | ||
616 | static void isp1301_udc_configure(struct lpc32xx_udc *udc) | ||
617 | { | ||
618 | /* LPC32XX only supports DAT_SE0 USB mode */ | ||
619 | /* This sequence is important */ | ||
620 | |||
621 | /* Disable transparent UART mode first */ | ||
622 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
623 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), | ||
624 | MC1_UART_EN); | ||
625 | |||
626 | /* Set full speed and SE0 mode */ | ||
627 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
628 | (ISP1301_I2C_MODE_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); | ||
629 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
630 | ISP1301_I2C_MODE_CONTROL_1, (MC1_SPEED_REG | MC1_DAT_SE0)); | ||
631 | |||
632 | /* | ||
633 | * The PSW_OE enable bit state is reversed in the ISP1301 User's Guide | ||
634 | */ | ||
635 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
636 | (ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); | ||
637 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
638 | ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_SPD_SUSP_CTRL)); | ||
639 | |||
640 | /* Driver VBUS_DRV high or low depending on board setup */ | ||
641 | if (udc->board->vbus_drv_pol != 0) | ||
642 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
643 | ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV); | ||
644 | else | ||
645 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
646 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, | ||
647 | OTG1_VBUS_DRV); | ||
648 | |||
649 | /* Bi-directional mode with suspend control | ||
650 | * Enable both pulldowns for now - the pullup will be enable when VBUS | ||
651 | * is detected */ | ||
652 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
653 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), ~0); | ||
654 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
655 | ISP1301_I2C_OTG_CONTROL_1, | ||
656 | (0 | OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN)); | ||
657 | |||
658 | /* Discharge VBUS (just in case) */ | ||
659 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
660 | ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DISCHRG); | ||
661 | msleep(1); | ||
662 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
663 | (ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR), | ||
664 | OTG1_VBUS_DISCHRG); | ||
665 | |||
666 | /* Clear and enable VBUS high edge interrupt */ | ||
667 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
668 | ISP1301_I2C_INTERRUPT_LATCH | ISP1301_I2C_REG_CLEAR_ADDR, ~0); | ||
669 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
670 | ISP1301_I2C_INTERRUPT_FALLING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); | ||
671 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
672 | ISP1301_I2C_INTERRUPT_FALLING, INT_VBUS_VLD); | ||
673 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
674 | ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); | ||
675 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
676 | ISP1301_I2C_INTERRUPT_RISING, INT_VBUS_VLD); | ||
677 | |||
678 | /* Enable usb_need_clk clock after transceiver is initialized */ | ||
679 | writel((readl(USB_CTRL) | (1 << 22)), USB_CTRL); | ||
680 | |||
681 | dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", | ||
682 | i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00)); | ||
683 | dev_info(udc->dev, "ISP1301 Product ID : 0x%04x\n", | ||
684 | i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x02)); | ||
685 | dev_info(udc->dev, "ISP1301 Version ID : 0x%04x\n", | ||
686 | i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x14)); | ||
687 | } | ||
688 | |||
689 | /* Enables or disables the USB device pullup via the ISP1301 transceiver */ | ||
690 | static void isp1301_pullup_set(struct lpc32xx_udc *udc) | ||
691 | { | ||
692 | if (udc->pullup) | ||
693 | /* Enable pullup for bus signalling */ | ||
694 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
695 | ISP1301_I2C_OTG_CONTROL_1, OTG1_DP_PULLUP); | ||
696 | else | ||
697 | /* Enable pullup for bus signalling */ | ||
698 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
699 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, | ||
700 | OTG1_DP_PULLUP); | ||
701 | } | ||
702 | |||
703 | static void pullup_work(struct work_struct *work) | ||
704 | { | ||
705 | struct lpc32xx_udc *udc = | ||
706 | container_of(work, struct lpc32xx_udc, pullup_job); | ||
707 | |||
708 | isp1301_pullup_set(udc); | ||
709 | } | ||
710 | |||
711 | static void isp1301_pullup_enable(struct lpc32xx_udc *udc, int en_pullup, | ||
712 | int block) | ||
713 | { | ||
714 | if (en_pullup == udc->pullup) | ||
715 | return; | ||
716 | |||
717 | udc->pullup = en_pullup; | ||
718 | if (block) | ||
719 | isp1301_pullup_set(udc); | ||
720 | else | ||
721 | /* defer slow i2c pull up setting */ | ||
722 | schedule_work(&udc->pullup_job); | ||
723 | } | ||
724 | |||
725 | #ifdef CONFIG_PM | ||
726 | /* Powers up or down the ISP1301 transceiver */ | ||
727 | static void isp1301_set_powerstate(struct lpc32xx_udc *udc, int enable) | ||
728 | { | ||
729 | if (enable != 0) | ||
730 | /* Power up ISP1301 - this ISP1301 will automatically wakeup | ||
731 | when VBUS is detected */ | ||
732 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
733 | ISP1301_I2C_MODE_CONTROL_2 | ISP1301_I2C_REG_CLEAR_ADDR, | ||
734 | MC2_GLOBAL_PWR_DN); | ||
735 | else | ||
736 | /* Power down ISP1301 */ | ||
737 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
738 | ISP1301_I2C_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); | ||
739 | } | ||
740 | |||
741 | static void power_work(struct work_struct *work) | ||
742 | { | ||
743 | struct lpc32xx_udc *udc = | ||
744 | container_of(work, struct lpc32xx_udc, power_job); | ||
745 | |||
746 | isp1301_set_powerstate(udc, udc->poweron); | ||
747 | } | ||
748 | #endif | ||
749 | |||
750 | /* | ||
751 | * | ||
752 | * USB protocol engine command/data read/write helper functions | ||
753 | * | ||
754 | */ | ||
755 | /* Issues a single command to the USB device state machine */ | ||
756 | static void udc_protocol_cmd_w(struct lpc32xx_udc *udc, u32 cmd) | ||
757 | { | ||
758 | u32 pass = 0; | ||
759 | int to; | ||
760 | |||
761 | /* EP may lock on CLRI if this read isn't done */ | ||
762 | u32 tmp = readl(USBD_DEVINTST(udc->udp_baseaddr)); | ||
763 | (void) tmp; | ||
764 | |||
765 | while (pass == 0) { | ||
766 | writel(USBD_CCEMPTY, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
767 | |||
768 | /* Write command code */ | ||
769 | writel(cmd, USBD_CMDCODE(udc->udp_baseaddr)); | ||
770 | to = 10000; | ||
771 | while (((readl(USBD_DEVINTST(udc->udp_baseaddr)) & | ||
772 | USBD_CCEMPTY) == 0) && (to > 0)) { | ||
773 | to--; | ||
774 | } | ||
775 | |||
776 | if (to > 0) | ||
777 | pass = 1; | ||
778 | |||
779 | cpu_relax(); | ||
780 | } | ||
781 | } | ||
782 | |||
783 | /* Issues 2 commands (or command and data) to the USB device state machine */ | ||
784 | static inline void udc_protocol_cmd_data_w(struct lpc32xx_udc *udc, u32 cmd, | ||
785 | u32 data) | ||
786 | { | ||
787 | udc_protocol_cmd_w(udc, cmd); | ||
788 | udc_protocol_cmd_w(udc, data); | ||
789 | } | ||
790 | |||
791 | /* Issues a single command to the USB device state machine and reads | ||
792 | * response data */ | ||
793 | static u32 udc_protocol_cmd_r(struct lpc32xx_udc *udc, u32 cmd) | ||
794 | { | ||
795 | u32 tmp; | ||
796 | int to = 1000; | ||
797 | |||
798 | /* Write a command and read data from the protocol engine */ | ||
799 | writel((USBD_CDFULL | USBD_CCEMPTY), | ||
800 | USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
801 | |||
802 | /* Write command code */ | ||
803 | udc_protocol_cmd_w(udc, cmd); | ||
804 | |||
805 | tmp = readl(USBD_DEVINTST(udc->udp_baseaddr)); | ||
806 | while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & USBD_CDFULL)) | ||
807 | && (to > 0)) | ||
808 | to--; | ||
809 | if (!to) | ||
810 | dev_dbg(udc->dev, | ||
811 | "Protocol engine didn't receive response (CDFULL)\n"); | ||
812 | |||
813 | return readl(USBD_CMDDATA(udc->udp_baseaddr)); | ||
814 | } | ||
815 | |||
816 | /* | ||
817 | * | ||
818 | * USB device interrupt mask support functions | ||
819 | * | ||
820 | */ | ||
821 | /* Enable one or more USB device interrupts */ | ||
822 | static inline void uda_enable_devint(struct lpc32xx_udc *udc, u32 devmask) | ||
823 | { | ||
824 | udc->enabled_devints |= devmask; | ||
825 | writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); | ||
826 | } | ||
827 | |||
828 | /* Disable one or more USB device interrupts */ | ||
829 | static inline void uda_disable_devint(struct lpc32xx_udc *udc, u32 mask) | ||
830 | { | ||
831 | udc->enabled_devints &= ~mask; | ||
832 | writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); | ||
833 | } | ||
834 | |||
835 | /* Clear one or more USB device interrupts */ | ||
836 | static inline void uda_clear_devint(struct lpc32xx_udc *udc, u32 mask) | ||
837 | { | ||
838 | writel(mask, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
839 | } | ||
840 | |||
841 | /* | ||
842 | * | ||
843 | * Endpoint interrupt disable/enable functions | ||
844 | * | ||
845 | */ | ||
846 | /* Enable one or more USB endpoint interrupts */ | ||
847 | static void uda_enable_hwepint(struct lpc32xx_udc *udc, u32 hwep) | ||
848 | { | ||
849 | udc->enabled_hwepints |= (1 << hwep); | ||
850 | writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); | ||
851 | } | ||
852 | |||
853 | /* Disable one or more USB endpoint interrupts */ | ||
854 | static void uda_disable_hwepint(struct lpc32xx_udc *udc, u32 hwep) | ||
855 | { | ||
856 | udc->enabled_hwepints &= ~(1 << hwep); | ||
857 | writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); | ||
858 | } | ||
859 | |||
860 | /* Clear one or more USB endpoint interrupts */ | ||
861 | static inline void uda_clear_hwepint(struct lpc32xx_udc *udc, u32 hwep) | ||
862 | { | ||
863 | writel((1 << hwep), USBD_EPINTCLR(udc->udp_baseaddr)); | ||
864 | } | ||
865 | |||
866 | /* Enable DMA for the HW channel */ | ||
867 | static inline void udc_ep_dma_enable(struct lpc32xx_udc *udc, u32 hwep) | ||
868 | { | ||
869 | writel((1 << hwep), USBD_EPDMAEN(udc->udp_baseaddr)); | ||
870 | } | ||
871 | |||
872 | /* Disable DMA for the HW channel */ | ||
873 | static inline void udc_ep_dma_disable(struct lpc32xx_udc *udc, u32 hwep) | ||
874 | { | ||
875 | writel((1 << hwep), USBD_EPDMADIS(udc->udp_baseaddr)); | ||
876 | } | ||
877 | |||
878 | /* | ||
879 | * | ||
880 | * Endpoint realize/unrealize functions | ||
881 | * | ||
882 | */ | ||
883 | /* Before an endpoint can be used, it needs to be realized | ||
884 | * in the USB protocol engine - this realizes the endpoint. | ||
885 | * The interrupt (FIFO or DMA) is not enabled with this function */ | ||
886 | static void udc_realize_hwep(struct lpc32xx_udc *udc, u32 hwep, | ||
887 | u32 maxpacket) | ||
888 | { | ||
889 | int to = 1000; | ||
890 | |||
891 | writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
892 | writel(hwep, USBD_EPIND(udc->udp_baseaddr)); | ||
893 | udc->realized_eps |= (1 << hwep); | ||
894 | writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); | ||
895 | writel(maxpacket, USBD_EPMAXPSIZE(udc->udp_baseaddr)); | ||
896 | |||
897 | /* Wait until endpoint is realized in hardware */ | ||
898 | while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & | ||
899 | USBD_EP_RLZED)) && (to > 0)) | ||
900 | to--; | ||
901 | if (!to) | ||
902 | dev_dbg(udc->dev, "EP not correctly realized in hardware\n"); | ||
903 | |||
904 | writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
905 | } | ||
906 | |||
907 | /* Unrealize an EP */ | ||
908 | static void udc_unrealize_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
909 | { | ||
910 | udc->realized_eps &= ~(1 << hwep); | ||
911 | writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); | ||
912 | } | ||
913 | |||
914 | /* | ||
915 | * | ||
916 | * Endpoint support functions | ||
917 | * | ||
918 | */ | ||
919 | /* Select and clear endpoint interrupt */ | ||
920 | static u32 udc_selep_clrint(struct lpc32xx_udc *udc, u32 hwep) | ||
921 | { | ||
922 | udc_protocol_cmd_w(udc, CMD_SEL_EP_CLRI(hwep)); | ||
923 | return udc_protocol_cmd_r(udc, DAT_SEL_EP_CLRI(hwep)); | ||
924 | } | ||
925 | |||
926 | /* Disables the endpoint in the USB protocol engine */ | ||
927 | static void udc_disable_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
928 | { | ||
929 | udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), | ||
930 | DAT_WR_BYTE(EP_STAT_DA)); | ||
931 | } | ||
932 | |||
933 | /* Stalls the endpoint - endpoint will return STALL */ | ||
934 | static void udc_stall_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
935 | { | ||
936 | udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), | ||
937 | DAT_WR_BYTE(EP_STAT_ST)); | ||
938 | } | ||
939 | |||
940 | /* Clear stall or reset endpoint */ | ||
941 | static void udc_clrstall_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
942 | { | ||
943 | udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(hwep), | ||
944 | DAT_WR_BYTE(0)); | ||
945 | } | ||
946 | |||
947 | /* Select an endpoint for endpoint status, clear, validate */ | ||
948 | static void udc_select_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
949 | { | ||
950 | udc_protocol_cmd_w(udc, CMD_SEL_EP(hwep)); | ||
951 | } | ||
952 | |||
953 | /* | ||
954 | * | ||
955 | * Endpoint buffer management functions | ||
956 | * | ||
957 | */ | ||
958 | /* Clear the current endpoint's buffer */ | ||
959 | static void udc_clr_buffer_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
960 | { | ||
961 | udc_select_hwep(udc, hwep); | ||
962 | udc_protocol_cmd_w(udc, CMD_CLR_BUF); | ||
963 | } | ||
964 | |||
965 | /* Validate the current endpoint's buffer */ | ||
966 | static void udc_val_buffer_hwep(struct lpc32xx_udc *udc, u32 hwep) | ||
967 | { | ||
968 | udc_select_hwep(udc, hwep); | ||
969 | udc_protocol_cmd_w(udc, CMD_VALID_BUF); | ||
970 | } | ||
971 | |||
972 | static inline u32 udc_clearep_getsts(struct lpc32xx_udc *udc, u32 hwep) | ||
973 | { | ||
974 | /* Clear EP interrupt */ | ||
975 | uda_clear_hwepint(udc, hwep); | ||
976 | return udc_selep_clrint(udc, hwep); | ||
977 | } | ||
978 | |||
979 | /* | ||
980 | * | ||
981 | * USB EP DMA support | ||
982 | * | ||
983 | */ | ||
984 | /* Allocate a DMA Descriptor */ | ||
985 | static struct lpc32xx_usbd_dd_gad *udc_dd_alloc(struct lpc32xx_udc *udc) | ||
986 | { | ||
987 | dma_addr_t dma; | ||
988 | struct lpc32xx_usbd_dd_gad *dd; | ||
989 | |||
990 | dd = (struct lpc32xx_usbd_dd_gad *) dma_pool_alloc( | ||
991 | udc->dd_cache, (GFP_KERNEL | GFP_DMA), &dma); | ||
992 | if (dd) | ||
993 | dd->this_dma = dma; | ||
994 | |||
995 | return dd; | ||
996 | } | ||
997 | |||
998 | /* Free a DMA Descriptor */ | ||
999 | static void udc_dd_free(struct lpc32xx_udc *udc, struct lpc32xx_usbd_dd_gad *dd) | ||
1000 | { | ||
1001 | dma_pool_free(udc->dd_cache, dd, dd->this_dma); | ||
1002 | } | ||
1003 | |||
1004 | /* | ||
1005 | * | ||
1006 | * USB setup and shutdown functions | ||
1007 | * | ||
1008 | */ | ||
1009 | /* Enables or disables most of the USB system clocks when low power mode is | ||
1010 | * needed. Clocks are typically started on a connection event, and disabled | ||
1011 | * when a cable is disconnected */ | ||
1012 | #define OTGOFF_CLK_MASK (AHB_M_CLOCK_ON | I2C_CLOCK_ON) | ||
1013 | static void udc_clk_set(struct lpc32xx_udc *udc, int enable) | ||
1014 | { | ||
1015 | int to = 1000; | ||
1016 | |||
1017 | if (enable != 0) { | ||
1018 | if (udc->clocked) | ||
1019 | return; | ||
1020 | |||
1021 | udc->clocked = 1; | ||
1022 | |||
1023 | /* 48MHz PLL up */ | ||
1024 | clk_enable(udc->usb_pll_clk); | ||
1025 | |||
1026 | /* Enable the USB device clock */ | ||
1027 | writel(readl(USB_CTRL) | USB_DEV_NEED_CLK_EN, | ||
1028 | USB_CTRL); | ||
1029 | |||
1030 | /* Set to enable all needed USB OTG clocks */ | ||
1031 | writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL(udc)); | ||
1032 | |||
1033 | while (((readl(USB_OTG_CLK_STAT(udc)) & USB_CLOCK_MASK) != | ||
1034 | USB_CLOCK_MASK) && (to > 0)) | ||
1035 | to--; | ||
1036 | if (!to) | ||
1037 | dev_dbg(udc->dev, "Cannot enable USB OTG clocking\n"); | ||
1038 | } else { | ||
1039 | if (!udc->clocked) | ||
1040 | return; | ||
1041 | |||
1042 | udc->clocked = 0; | ||
1043 | |||
1044 | /* Never disable the USB_HCLK during normal operation */ | ||
1045 | |||
1046 | /* 48MHz PLL dpwn */ | ||
1047 | clk_disable(udc->usb_pll_clk); | ||
1048 | |||
1049 | /* Enable the USB device clock */ | ||
1050 | writel(readl(USB_CTRL) & ~USB_DEV_NEED_CLK_EN, | ||
1051 | USB_CTRL); | ||
1052 | |||
1053 | /* Set to enable all needed USB OTG clocks */ | ||
1054 | writel(OTGOFF_CLK_MASK, USB_OTG_CLK_CTRL(udc)); | ||
1055 | |||
1056 | while (((readl(USB_OTG_CLK_STAT(udc)) & | ||
1057 | OTGOFF_CLK_MASK) != | ||
1058 | OTGOFF_CLK_MASK) && (to > 0)) | ||
1059 | to--; | ||
1060 | if (!to) | ||
1061 | dev_dbg(udc->dev, "Cannot disable USB OTG clocking\n"); | ||
1062 | } | ||
1063 | } | ||
1064 | |||
1065 | /* Set/reset USB device address */ | ||
1066 | static void udc_set_address(struct lpc32xx_udc *udc, u32 addr) | ||
1067 | { | ||
1068 | /* Address will be latched at the end of the status phase, or | ||
1069 | latched immediately if function is called twice */ | ||
1070 | udc_protocol_cmd_data_w(udc, CMD_SET_ADDR, | ||
1071 | DAT_WR_BYTE(DEV_EN | addr)); | ||
1072 | } | ||
1073 | |||
1074 | /* Setup up a IN request for DMA transfer - this consists of determining the | ||
1075 | * list of DMA addresses for the transfer, allocating DMA Descriptors, | ||
1076 | * installing the DD into the UDCA, and then enabling the DMA for that EP */ | ||
1077 | static int udc_ep_in_req_dma(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) | ||
1078 | { | ||
1079 | struct lpc32xx_request *req; | ||
1080 | u32 hwep = ep->hwep_num; | ||
1081 | |||
1082 | ep->req_pending = 1; | ||
1083 | |||
1084 | /* There will always be a request waiting here */ | ||
1085 | req = list_entry(ep->queue.next, struct lpc32xx_request, queue); | ||
1086 | |||
1087 | /* Place the DD Descriptor into the UDCA */ | ||
1088 | udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; | ||
1089 | |||
1090 | /* Enable DMA and interrupt for the HW EP */ | ||
1091 | udc_ep_dma_enable(udc, hwep); | ||
1092 | |||
1093 | /* Clear ZLP if last packet is not of MAXP size */ | ||
1094 | if (req->req.length % ep->ep.maxpacket) | ||
1095 | req->send_zlp = 0; | ||
1096 | |||
1097 | return 0; | ||
1098 | } | ||
1099 | |||
1100 | /* Setup up a OUT request for DMA transfer - this consists of determining the | ||
1101 | * list of DMA addresses for the transfer, allocating DMA Descriptors, | ||
1102 | * installing the DD into the UDCA, and then enabling the DMA for that EP */ | ||
1103 | static int udc_ep_out_req_dma(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) | ||
1104 | { | ||
1105 | struct lpc32xx_request *req; | ||
1106 | u32 hwep = ep->hwep_num; | ||
1107 | |||
1108 | ep->req_pending = 1; | ||
1109 | |||
1110 | /* There will always be a request waiting here */ | ||
1111 | req = list_entry(ep->queue.next, struct lpc32xx_request, queue); | ||
1112 | |||
1113 | /* Place the DD Descriptor into the UDCA */ | ||
1114 | udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; | ||
1115 | |||
1116 | /* Enable DMA and interrupt for the HW EP */ | ||
1117 | udc_ep_dma_enable(udc, hwep); | ||
1118 | return 0; | ||
1119 | } | ||
1120 | |||
1121 | static void udc_disable(struct lpc32xx_udc *udc) | ||
1122 | { | ||
1123 | u32 i; | ||
1124 | |||
1125 | /* Disable device */ | ||
1126 | udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(0)); | ||
1127 | udc_protocol_cmd_data_w(udc, CMD_SET_DEV_STAT, DAT_WR_BYTE(0)); | ||
1128 | |||
1129 | /* Disable all device interrupts (including EP0) */ | ||
1130 | uda_disable_devint(udc, 0x3FF); | ||
1131 | |||
1132 | /* Disable and reset all endpoint interrupts */ | ||
1133 | for (i = 0; i < 32; i++) { | ||
1134 | uda_disable_hwepint(udc, i); | ||
1135 | uda_clear_hwepint(udc, i); | ||
1136 | udc_disable_hwep(udc, i); | ||
1137 | udc_unrealize_hwep(udc, i); | ||
1138 | udc->udca_v_base[i] = 0; | ||
1139 | |||
1140 | /* Disable and clear all interrupts and DMA */ | ||
1141 | udc_ep_dma_disable(udc, i); | ||
1142 | writel((1 << i), USBD_EOTINTCLR(udc->udp_baseaddr)); | ||
1143 | writel((1 << i), USBD_NDDRTINTCLR(udc->udp_baseaddr)); | ||
1144 | writel((1 << i), USBD_SYSERRTINTCLR(udc->udp_baseaddr)); | ||
1145 | writel((1 << i), USBD_DMARCLR(udc->udp_baseaddr)); | ||
1146 | } | ||
1147 | |||
1148 | /* Disable DMA interrupts */ | ||
1149 | writel(0, USBD_DMAINTEN(udc->udp_baseaddr)); | ||
1150 | |||
1151 | writel(0, USBD_UDCAH(udc->udp_baseaddr)); | ||
1152 | } | ||
1153 | |||
1154 | static void udc_enable(struct lpc32xx_udc *udc) | ||
1155 | { | ||
1156 | u32 i; | ||
1157 | struct lpc32xx_ep *ep = &udc->ep[0]; | ||
1158 | |||
1159 | /* Start with known state */ | ||
1160 | udc_disable(udc); | ||
1161 | |||
1162 | /* Enable device */ | ||
1163 | udc_protocol_cmd_data_w(udc, CMD_SET_DEV_STAT, DAT_WR_BYTE(DEV_CON)); | ||
1164 | |||
1165 | /* EP interrupts on high priority, FRAME interrupt on low priority */ | ||
1166 | writel(USBD_EP_FAST, USBD_DEVINTPRI(udc->udp_baseaddr)); | ||
1167 | writel(0xFFFF, USBD_EPINTPRI(udc->udp_baseaddr)); | ||
1168 | |||
1169 | /* Clear any pending device interrupts */ | ||
1170 | writel(0x3FF, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
1171 | |||
1172 | /* Setup UDCA - not yet used (DMA) */ | ||
1173 | writel(udc->udca_p_base, USBD_UDCAH(udc->udp_baseaddr)); | ||
1174 | |||
1175 | /* Only enable EP0 in and out for now, EP0 only works in FIFO mode */ | ||
1176 | for (i = 0; i <= 1; i++) { | ||
1177 | udc_realize_hwep(udc, i, ep->ep.maxpacket); | ||
1178 | uda_enable_hwepint(udc, i); | ||
1179 | udc_select_hwep(udc, i); | ||
1180 | udc_clrstall_hwep(udc, i); | ||
1181 | udc_clr_buffer_hwep(udc, i); | ||
1182 | } | ||
1183 | |||
1184 | /* Device interrupt setup */ | ||
1185 | uda_clear_devint(udc, (USBD_ERR_INT | USBD_DEV_STAT | USBD_EP_SLOW | | ||
1186 | USBD_EP_FAST)); | ||
1187 | uda_enable_devint(udc, (USBD_ERR_INT | USBD_DEV_STAT | USBD_EP_SLOW | | ||
1188 | USBD_EP_FAST)); | ||
1189 | |||
1190 | /* Set device address to 0 - called twice to force a latch in the USB | ||
1191 | engine without the need of a setup packet status closure */ | ||
1192 | udc_set_address(udc, 0); | ||
1193 | udc_set_address(udc, 0); | ||
1194 | |||
1195 | /* Enable master DMA interrupts */ | ||
1196 | writel((USBD_SYS_ERR_INT | USBD_EOT_INT), | ||
1197 | USBD_DMAINTEN(udc->udp_baseaddr)); | ||
1198 | |||
1199 | udc->dev_status = 0; | ||
1200 | } | ||
1201 | |||
1202 | /* | ||
1203 | * | ||
1204 | * USB device board specific events handled via callbacks | ||
1205 | * | ||
1206 | */ | ||
1207 | /* Connection change event - notify board function of change */ | ||
1208 | static void uda_power_event(struct lpc32xx_udc *udc, u32 conn) | ||
1209 | { | ||
1210 | /* Just notify of a connection change event (optional) */ | ||
1211 | if (udc->board->conn_chgb != NULL) | ||
1212 | udc->board->conn_chgb(conn); | ||
1213 | } | ||
1214 | |||
1215 | /* Suspend/resume event - notify board function of change */ | ||
1216 | static void uda_resm_susp_event(struct lpc32xx_udc *udc, u32 conn) | ||
1217 | { | ||
1218 | /* Just notify of a Suspend/resume change event (optional) */ | ||
1219 | if (udc->board->susp_chgb != NULL) | ||
1220 | udc->board->susp_chgb(conn); | ||
1221 | |||
1222 | if (conn) | ||
1223 | udc->suspended = 0; | ||
1224 | else | ||
1225 | udc->suspended = 1; | ||
1226 | } | ||
1227 | |||
1228 | /* Remote wakeup enable/disable - notify board function of change */ | ||
1229 | static void uda_remwkp_cgh(struct lpc32xx_udc *udc) | ||
1230 | { | ||
1231 | if (udc->board->rmwk_chgb != NULL) | ||
1232 | udc->board->rmwk_chgb(udc->dev_status & | ||
1233 | (1 << USB_DEVICE_REMOTE_WAKEUP)); | ||
1234 | } | ||
1235 | |||
1236 | /* Reads data from FIFO, adjusts for alignment and data size */ | ||
1237 | static void udc_pop_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes) | ||
1238 | { | ||
1239 | int n, i, bl; | ||
1240 | u16 *p16; | ||
1241 | u32 *p32, tmp, cbytes; | ||
1242 | |||
1243 | /* Use optimal data transfer method based on source address and size */ | ||
1244 | switch (((u32) data) & 0x3) { | ||
1245 | case 0: /* 32-bit aligned */ | ||
1246 | p32 = (u32 *) data; | ||
1247 | cbytes = (bytes & ~0x3); | ||
1248 | |||
1249 | /* Copy 32-bit aligned data first */ | ||
1250 | for (n = 0; n < cbytes; n += 4) | ||
1251 | *p32++ = readl(USBD_RXDATA(udc->udp_baseaddr)); | ||
1252 | |||
1253 | /* Handle any remaining bytes */ | ||
1254 | bl = bytes - cbytes; | ||
1255 | if (bl) { | ||
1256 | tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); | ||
1257 | for (n = 0; n < bl; n++) | ||
1258 | data[cbytes + n] = ((tmp >> (n * 8)) & 0xFF); | ||
1259 | |||
1260 | } | ||
1261 | break; | ||
1262 | |||
1263 | case 1: /* 8-bit aligned */ | ||
1264 | case 3: | ||
1265 | /* Each byte has to be handled independently */ | ||
1266 | for (n = 0; n < bytes; n += 4) { | ||
1267 | tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); | ||
1268 | |||
1269 | bl = bytes - n; | ||
1270 | if (bl > 3) | ||
1271 | bl = 3; | ||
1272 | |||
1273 | for (i = 0; i < bl; i++) | ||
1274 | data[n + i] = (u8) ((tmp >> (n * 8)) & 0xFF); | ||
1275 | } | ||
1276 | break; | ||
1277 | |||
1278 | case 2: /* 16-bit aligned */ | ||
1279 | p16 = (u16 *) data; | ||
1280 | cbytes = (bytes & ~0x3); | ||
1281 | |||
1282 | /* Copy 32-bit sized objects first with 16-bit alignment */ | ||
1283 | for (n = 0; n < cbytes; n += 4) { | ||
1284 | tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); | ||
1285 | *p16++ = (u16)(tmp & 0xFFFF); | ||
1286 | *p16++ = (u16)((tmp >> 16) & 0xFFFF); | ||
1287 | } | ||
1288 | |||
1289 | /* Handle any remaining bytes */ | ||
1290 | bl = bytes - cbytes; | ||
1291 | if (bl) { | ||
1292 | tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); | ||
1293 | for (n = 0; n < bl; n++) | ||
1294 | data[cbytes + n] = ((tmp >> (n * 8)) & 0xFF); | ||
1295 | } | ||
1296 | break; | ||
1297 | } | ||
1298 | } | ||
1299 | |||
1300 | /* Read data from the FIFO for an endpoint. This function is for endpoints (such | ||
1301 | * as EP0) that don't use DMA. This function should only be called if a packet | ||
1302 | * is known to be ready to read for the endpoint. Note that the endpoint must | ||
1303 | * be selected in the protocol engine prior to this call. */ | ||
1304 | static u32 udc_read_hwep(struct lpc32xx_udc *udc, u32 hwep, u32 *data, | ||
1305 | u32 bytes) | ||
1306 | { | ||
1307 | u32 tmpv; | ||
1308 | int to = 1000; | ||
1309 | u32 tmp, hwrep = ((hwep & 0x1E) << 1) | CTRL_RD_EN; | ||
1310 | |||
1311 | /* Setup read of endpoint */ | ||
1312 | writel(hwrep, USBD_CTRL(udc->udp_baseaddr)); | ||
1313 | |||
1314 | /* Wait until packet is ready */ | ||
1315 | while ((((tmpv = readl(USBD_RXPLEN(udc->udp_baseaddr))) & | ||
1316 | PKT_RDY) == 0) && (to > 0)) | ||
1317 | to--; | ||
1318 | if (!to) | ||
1319 | dev_dbg(udc->dev, "No packet ready on FIFO EP read\n"); | ||
1320 | |||
1321 | /* Mask out count */ | ||
1322 | tmp = tmpv & PKT_LNGTH_MASK; | ||
1323 | if (bytes < tmp) | ||
1324 | tmp = bytes; | ||
1325 | |||
1326 | if ((tmp > 0) && (data != NULL)) | ||
1327 | udc_pop_fifo(udc, (u8 *) data, tmp); | ||
1328 | |||
1329 | writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); | ||
1330 | |||
1331 | /* Clear the buffer */ | ||
1332 | udc_clr_buffer_hwep(udc, hwep); | ||
1333 | |||
1334 | return tmp; | ||
1335 | } | ||
1336 | |||
1337 | /* Stuffs data into the FIFO, adjusts for alignment and data size */ | ||
1338 | static void udc_stuff_fifo(struct lpc32xx_udc *udc, u8 *data, u32 bytes) | ||
1339 | { | ||
1340 | int n, i, bl; | ||
1341 | u16 *p16; | ||
1342 | u32 *p32, tmp, cbytes; | ||
1343 | |||
1344 | /* Use optimal data transfer method based on source address and size */ | ||
1345 | switch (((u32) data) & 0x3) { | ||
1346 | case 0: /* 32-bit aligned */ | ||
1347 | p32 = (u32 *) data; | ||
1348 | cbytes = (bytes & ~0x3); | ||
1349 | |||
1350 | /* Copy 32-bit aligned data first */ | ||
1351 | for (n = 0; n < cbytes; n += 4) | ||
1352 | writel(*p32++, USBD_TXDATA(udc->udp_baseaddr)); | ||
1353 | |||
1354 | /* Handle any remaining bytes */ | ||
1355 | bl = bytes - cbytes; | ||
1356 | if (bl) { | ||
1357 | tmp = 0; | ||
1358 | for (n = 0; n < bl; n++) | ||
1359 | tmp |= data[cbytes + n] << (n * 8); | ||
1360 | |||
1361 | writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); | ||
1362 | } | ||
1363 | break; | ||
1364 | |||
1365 | case 1: /* 8-bit aligned */ | ||
1366 | case 3: | ||
1367 | /* Each byte has to be handled independently */ | ||
1368 | for (n = 0; n < bytes; n += 4) { | ||
1369 | bl = bytes - n; | ||
1370 | if (bl > 4) | ||
1371 | bl = 4; | ||
1372 | |||
1373 | tmp = 0; | ||
1374 | for (i = 0; i < bl; i++) | ||
1375 | tmp |= data[n + i] << (i * 8); | ||
1376 | |||
1377 | writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); | ||
1378 | } | ||
1379 | break; | ||
1380 | |||
1381 | case 2: /* 16-bit aligned */ | ||
1382 | p16 = (u16 *) data; | ||
1383 | cbytes = (bytes & ~0x3); | ||
1384 | |||
1385 | /* Copy 32-bit aligned data first */ | ||
1386 | for (n = 0; n < cbytes; n += 4) { | ||
1387 | tmp = *p16++ & 0xFFFF; | ||
1388 | tmp |= (*p16++ & 0xFFFF) << 16; | ||
1389 | writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); | ||
1390 | } | ||
1391 | |||
1392 | /* Handle any remaining bytes */ | ||
1393 | bl = bytes - cbytes; | ||
1394 | if (bl) { | ||
1395 | tmp = 0; | ||
1396 | for (n = 0; n < bl; n++) | ||
1397 | tmp |= data[cbytes + n] << (n * 8); | ||
1398 | |||
1399 | writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); | ||
1400 | } | ||
1401 | break; | ||
1402 | } | ||
1403 | } | ||
1404 | |||
1405 | /* Write data to the FIFO for an endpoint. This function is for endpoints (such | ||
1406 | * as EP0) that don't use DMA. Note that the endpoint must be selected in the | ||
1407 | * protocol engine prior to this call. */ | ||
1408 | static void udc_write_hwep(struct lpc32xx_udc *udc, u32 hwep, u32 *data, | ||
1409 | u32 bytes) | ||
1410 | { | ||
1411 | u32 hwwep = ((hwep & 0x1E) << 1) | CTRL_WR_EN; | ||
1412 | |||
1413 | if ((bytes > 0) && (data == NULL)) | ||
1414 | return; | ||
1415 | |||
1416 | /* Setup write of endpoint */ | ||
1417 | writel(hwwep, USBD_CTRL(udc->udp_baseaddr)); | ||
1418 | |||
1419 | writel(bytes, USBD_TXPLEN(udc->udp_baseaddr)); | ||
1420 | |||
1421 | /* Need at least 1 byte to trigger TX */ | ||
1422 | if (bytes == 0) | ||
1423 | writel(0, USBD_TXDATA(udc->udp_baseaddr)); | ||
1424 | else | ||
1425 | udc_stuff_fifo(udc, (u8 *) data, bytes); | ||
1426 | |||
1427 | writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); | ||
1428 | |||
1429 | udc_val_buffer_hwep(udc, hwep); | ||
1430 | } | ||
1431 | |||
1432 | /* USB device reset - resets USB to a default state with just EP0 | ||
1433 | enabled */ | ||
1434 | static void uda_usb_reset(struct lpc32xx_udc *udc) | ||
1435 | { | ||
1436 | u32 i = 0; | ||
1437 | /* Re-init device controller and EP0 */ | ||
1438 | udc_enable(udc); | ||
1439 | udc->gadget.speed = USB_SPEED_FULL; | ||
1440 | |||
1441 | for (i = 1; i < NUM_ENDPOINTS; i++) { | ||
1442 | struct lpc32xx_ep *ep = &udc->ep[i]; | ||
1443 | ep->req_pending = 0; | ||
1444 | } | ||
1445 | } | ||
1446 | |||
1447 | /* Send a ZLP on EP0 */ | ||
1448 | static void udc_ep0_send_zlp(struct lpc32xx_udc *udc) | ||
1449 | { | ||
1450 | udc_write_hwep(udc, EP_IN, NULL, 0); | ||
1451 | } | ||
1452 | |||
1453 | /* Get current frame number */ | ||
1454 | static u16 udc_get_current_frame(struct lpc32xx_udc *udc) | ||
1455 | { | ||
1456 | u16 flo, fhi; | ||
1457 | |||
1458 | udc_protocol_cmd_w(udc, CMD_RD_FRAME); | ||
1459 | flo = (u16) udc_protocol_cmd_r(udc, DAT_RD_FRAME); | ||
1460 | fhi = (u16) udc_protocol_cmd_r(udc, DAT_RD_FRAME); | ||
1461 | |||
1462 | return (fhi << 8) | flo; | ||
1463 | } | ||
1464 | |||
1465 | /* Set the device as configured - enables all endpoints */ | ||
1466 | static inline void udc_set_device_configured(struct lpc32xx_udc *udc) | ||
1467 | { | ||
1468 | udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(CONF_DVICE)); | ||
1469 | } | ||
1470 | |||
1471 | /* Set the device as unconfigured - disables all endpoints */ | ||
1472 | static inline void udc_set_device_unconfigured(struct lpc32xx_udc *udc) | ||
1473 | { | ||
1474 | udc_protocol_cmd_data_w(udc, CMD_CFG_DEV, DAT_WR_BYTE(0)); | ||
1475 | } | ||
1476 | |||
1477 | /* reinit == restore initial software state */ | ||
1478 | static void udc_reinit(struct lpc32xx_udc *udc) | ||
1479 | { | ||
1480 | u32 i; | ||
1481 | |||
1482 | INIT_LIST_HEAD(&udc->gadget.ep_list); | ||
1483 | INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); | ||
1484 | |||
1485 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
1486 | struct lpc32xx_ep *ep = &udc->ep[i]; | ||
1487 | |||
1488 | if (i != 0) | ||
1489 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | ||
1490 | ep->desc = NULL; | ||
1491 | ep->ep.maxpacket = ep->maxpacket; | ||
1492 | INIT_LIST_HEAD(&ep->queue); | ||
1493 | ep->req_pending = 0; | ||
1494 | } | ||
1495 | |||
1496 | udc->ep0state = WAIT_FOR_SETUP; | ||
1497 | } | ||
1498 | |||
1499 | /* Must be called with lock */ | ||
1500 | static void done(struct lpc32xx_ep *ep, struct lpc32xx_request *req, int status) | ||
1501 | { | ||
1502 | struct lpc32xx_udc *udc = ep->udc; | ||
1503 | |||
1504 | list_del_init(&req->queue); | ||
1505 | if (req->req.status == -EINPROGRESS) | ||
1506 | req->req.status = status; | ||
1507 | else | ||
1508 | status = req->req.status; | ||
1509 | |||
1510 | if (ep->lep) { | ||
1511 | enum dma_data_direction direction; | ||
1512 | |||
1513 | if (ep->is_in) | ||
1514 | direction = DMA_TO_DEVICE; | ||
1515 | else | ||
1516 | direction = DMA_FROM_DEVICE; | ||
1517 | |||
1518 | if (req->mapped) { | ||
1519 | dma_unmap_single(ep->udc->gadget.dev.parent, | ||
1520 | req->req.dma, req->req.length, | ||
1521 | direction); | ||
1522 | req->req.dma = 0; | ||
1523 | req->mapped = 0; | ||
1524 | } else | ||
1525 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, | ||
1526 | req->req.dma, req->req.length, | ||
1527 | direction); | ||
1528 | |||
1529 | /* Free DDs */ | ||
1530 | udc_dd_free(udc, req->dd_desc_ptr); | ||
1531 | } | ||
1532 | |||
1533 | if (status && status != -ESHUTDOWN) | ||
1534 | ep_dbg(ep, "%s done %p, status %d\n", ep->ep.name, req, status); | ||
1535 | |||
1536 | ep->req_pending = 0; | ||
1537 | spin_unlock(&udc->lock); | ||
1538 | req->req.complete(&ep->ep, &req->req); | ||
1539 | spin_lock(&udc->lock); | ||
1540 | } | ||
1541 | |||
1542 | /* Must be called with lock */ | ||
1543 | static void nuke(struct lpc32xx_ep *ep, int status) | ||
1544 | { | ||
1545 | struct lpc32xx_request *req; | ||
1546 | |||
1547 | while (!list_empty(&ep->queue)) { | ||
1548 | req = list_entry(ep->queue.next, struct lpc32xx_request, queue); | ||
1549 | done(ep, req, status); | ||
1550 | } | ||
1551 | |||
1552 | if (ep->desc && status == -ESHUTDOWN) { | ||
1553 | uda_disable_hwepint(ep->udc, ep->hwep_num); | ||
1554 | udc_disable_hwep(ep->udc, ep->hwep_num); | ||
1555 | } | ||
1556 | } | ||
1557 | |||
1558 | /* IN endpoint 0 transfer */ | ||
1559 | static int udc_ep0_in_req(struct lpc32xx_udc *udc) | ||
1560 | { | ||
1561 | struct lpc32xx_request *req; | ||
1562 | struct lpc32xx_ep *ep0 = &udc->ep[0]; | ||
1563 | u32 tsend, ts = 0; | ||
1564 | |||
1565 | if (list_empty(&ep0->queue)) | ||
1566 | /* Nothing to send */ | ||
1567 | return 0; | ||
1568 | else | ||
1569 | req = list_entry(ep0->queue.next, struct lpc32xx_request, | ||
1570 | queue); | ||
1571 | |||
1572 | tsend = ts = req->req.length - req->req.actual; | ||
1573 | if (ts == 0) { | ||
1574 | /* Send a ZLP */ | ||
1575 | udc_ep0_send_zlp(udc); | ||
1576 | done(ep0, req, 0); | ||
1577 | return 1; | ||
1578 | } else if (ts > ep0->ep.maxpacket) | ||
1579 | ts = ep0->ep.maxpacket; /* Just send what we can */ | ||
1580 | |||
1581 | /* Write data to the EP0 FIFO and start transfer */ | ||
1582 | udc_write_hwep(udc, EP_IN, (req->req.buf + req->req.actual), ts); | ||
1583 | |||
1584 | /* Increment data pointer */ | ||
1585 | req->req.actual += ts; | ||
1586 | |||
1587 | if (tsend >= ep0->ep.maxpacket) | ||
1588 | return 0; /* Stay in data transfer state */ | ||
1589 | |||
1590 | /* Transfer request is complete */ | ||
1591 | udc->ep0state = WAIT_FOR_SETUP; | ||
1592 | done(ep0, req, 0); | ||
1593 | return 1; | ||
1594 | } | ||
1595 | |||
1596 | /* OUT endpoint 0 transfer */ | ||
1597 | static int udc_ep0_out_req(struct lpc32xx_udc *udc) | ||
1598 | { | ||
1599 | struct lpc32xx_request *req; | ||
1600 | struct lpc32xx_ep *ep0 = &udc->ep[0]; | ||
1601 | u32 tr, bufferspace; | ||
1602 | |||
1603 | if (list_empty(&ep0->queue)) | ||
1604 | return 0; | ||
1605 | else | ||
1606 | req = list_entry(ep0->queue.next, struct lpc32xx_request, | ||
1607 | queue); | ||
1608 | |||
1609 | if (req) { | ||
1610 | if (req->req.length == 0) { | ||
1611 | /* Just dequeue request */ | ||
1612 | done(ep0, req, 0); | ||
1613 | udc->ep0state = WAIT_FOR_SETUP; | ||
1614 | return 1; | ||
1615 | } | ||
1616 | |||
1617 | /* Get data from FIFO */ | ||
1618 | bufferspace = req->req.length - req->req.actual; | ||
1619 | if (bufferspace > ep0->ep.maxpacket) | ||
1620 | bufferspace = ep0->ep.maxpacket; | ||
1621 | |||
1622 | /* Copy data to buffer */ | ||
1623 | prefetchw(req->req.buf + req->req.actual); | ||
1624 | tr = udc_read_hwep(udc, EP_OUT, req->req.buf + req->req.actual, | ||
1625 | bufferspace); | ||
1626 | req->req.actual += bufferspace; | ||
1627 | |||
1628 | if (tr < ep0->ep.maxpacket) { | ||
1629 | /* This is the last packet */ | ||
1630 | done(ep0, req, 0); | ||
1631 | udc->ep0state = WAIT_FOR_SETUP; | ||
1632 | return 1; | ||
1633 | } | ||
1634 | } | ||
1635 | |||
1636 | return 0; | ||
1637 | } | ||
1638 | |||
1639 | /* Must be called with lock */ | ||
1640 | static void stop_activity(struct lpc32xx_udc *udc) | ||
1641 | { | ||
1642 | struct usb_gadget_driver *driver = udc->driver; | ||
1643 | int i; | ||
1644 | |||
1645 | if (udc->gadget.speed == USB_SPEED_UNKNOWN) | ||
1646 | driver = NULL; | ||
1647 | |||
1648 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1649 | udc->suspended = 0; | ||
1650 | |||
1651 | for (i = 0; i < NUM_ENDPOINTS; i++) { | ||
1652 | struct lpc32xx_ep *ep = &udc->ep[i]; | ||
1653 | nuke(ep, -ESHUTDOWN); | ||
1654 | } | ||
1655 | if (driver) { | ||
1656 | spin_unlock(&udc->lock); | ||
1657 | driver->disconnect(&udc->gadget); | ||
1658 | spin_lock(&udc->lock); | ||
1659 | } | ||
1660 | |||
1661 | isp1301_pullup_enable(udc, 0, 0); | ||
1662 | udc_disable(udc); | ||
1663 | udc_reinit(udc); | ||
1664 | } | ||
1665 | |||
1666 | /* | ||
1667 | * Activate or kill host pullup | ||
1668 | * Can be called with or without lock | ||
1669 | */ | ||
1670 | static void pullup(struct lpc32xx_udc *udc, int is_on) | ||
1671 | { | ||
1672 | if (!udc->clocked) | ||
1673 | return; | ||
1674 | |||
1675 | if (!udc->enabled || !udc->vbus) | ||
1676 | is_on = 0; | ||
1677 | |||
1678 | if (is_on != udc->pullup) | ||
1679 | isp1301_pullup_enable(udc, is_on, 0); | ||
1680 | } | ||
1681 | |||
1682 | /* Must be called without lock */ | ||
1683 | static int lpc32xx_ep_disable(struct usb_ep *_ep) | ||
1684 | { | ||
1685 | struct lpc32xx_ep *ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
1686 | struct lpc32xx_udc *udc = ep->udc; | ||
1687 | unsigned long flags; | ||
1688 | |||
1689 | if ((ep->hwep_num_base == 0) || (ep->hwep_num == 0)) | ||
1690 | return -EINVAL; | ||
1691 | spin_lock_irqsave(&udc->lock, flags); | ||
1692 | |||
1693 | nuke(ep, -ESHUTDOWN); | ||
1694 | |||
1695 | /* restore the endpoint's pristine config */ | ||
1696 | ep->desc = NULL; | ||
1697 | |||
1698 | /* Clear all DMA statuses for this EP */ | ||
1699 | udc_ep_dma_disable(udc, ep->hwep_num); | ||
1700 | writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); | ||
1701 | writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); | ||
1702 | writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); | ||
1703 | writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); | ||
1704 | |||
1705 | /* Remove the DD pointer in the UDCA */ | ||
1706 | udc->udca_v_base[ep->hwep_num] = 0; | ||
1707 | |||
1708 | /* Disable and reset endpoint and interrupt */ | ||
1709 | uda_clear_hwepint(udc, ep->hwep_num); | ||
1710 | udc_unrealize_hwep(udc, ep->hwep_num); | ||
1711 | |||
1712 | ep->hwep_num = 0; | ||
1713 | |||
1714 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1715 | |||
1716 | atomic_dec(&udc->enabled_ep_cnt); | ||
1717 | wake_up(&udc->ep_disable_wait_queue); | ||
1718 | |||
1719 | return 0; | ||
1720 | } | ||
1721 | |||
1722 | /* Must be called without lock */ | ||
1723 | static int lpc32xx_ep_enable(struct usb_ep *_ep, | ||
1724 | const struct usb_endpoint_descriptor *desc) | ||
1725 | { | ||
1726 | struct lpc32xx_ep *ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
1727 | struct lpc32xx_udc *udc = ep->udc; | ||
1728 | u16 maxpacket; | ||
1729 | u32 tmp; | ||
1730 | unsigned long flags; | ||
1731 | |||
1732 | /* Verify EP data */ | ||
1733 | if ((!_ep) || (!ep) || (!desc) || (ep->desc) || | ||
1734 | (desc->bDescriptorType != USB_DT_ENDPOINT)) { | ||
1735 | dev_dbg(udc->dev, "bad ep or descriptor\n"); | ||
1736 | return -EINVAL; | ||
1737 | } | ||
1738 | maxpacket = usb_endpoint_maxp(desc); | ||
1739 | if ((maxpacket == 0) || (maxpacket > ep->maxpacket)) { | ||
1740 | dev_dbg(udc->dev, "bad ep descriptor's packet size\n"); | ||
1741 | return -EINVAL; | ||
1742 | } | ||
1743 | |||
1744 | /* Don't touch EP0 */ | ||
1745 | if (ep->hwep_num_base == 0) { | ||
1746 | dev_dbg(udc->dev, "Can't re-enable EP0!!!\n"); | ||
1747 | return -EINVAL; | ||
1748 | } | ||
1749 | |||
1750 | /* Is driver ready? */ | ||
1751 | if ((!udc->driver) || (udc->gadget.speed == USB_SPEED_UNKNOWN)) { | ||
1752 | dev_dbg(udc->dev, "bogus device state\n"); | ||
1753 | return -ESHUTDOWN; | ||
1754 | } | ||
1755 | |||
1756 | tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
1757 | switch (tmp) { | ||
1758 | case USB_ENDPOINT_XFER_CONTROL: | ||
1759 | return -EINVAL; | ||
1760 | |||
1761 | case USB_ENDPOINT_XFER_INT: | ||
1762 | if (maxpacket > ep->maxpacket) { | ||
1763 | dev_dbg(udc->dev, | ||
1764 | "Bad INT endpoint maxpacket %d\n", maxpacket); | ||
1765 | return -EINVAL; | ||
1766 | } | ||
1767 | break; | ||
1768 | |||
1769 | case USB_ENDPOINT_XFER_BULK: | ||
1770 | switch (maxpacket) { | ||
1771 | case 8: | ||
1772 | case 16: | ||
1773 | case 32: | ||
1774 | case 64: | ||
1775 | break; | ||
1776 | |||
1777 | default: | ||
1778 | dev_dbg(udc->dev, | ||
1779 | "Bad BULK endpoint maxpacket %d\n", maxpacket); | ||
1780 | return -EINVAL; | ||
1781 | } | ||
1782 | break; | ||
1783 | |||
1784 | case USB_ENDPOINT_XFER_ISOC: | ||
1785 | break; | ||
1786 | } | ||
1787 | spin_lock_irqsave(&udc->lock, flags); | ||
1788 | |||
1789 | /* Initialize endpoint to match the selected descriptor */ | ||
1790 | ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0; | ||
1791 | ep->desc = desc; | ||
1792 | ep->ep.maxpacket = maxpacket; | ||
1793 | |||
1794 | /* Map hardware endpoint from base and direction */ | ||
1795 | if (ep->is_in) | ||
1796 | /* IN endpoints are offset 1 from the OUT endpoint */ | ||
1797 | ep->hwep_num = ep->hwep_num_base + EP_IN; | ||
1798 | else | ||
1799 | ep->hwep_num = ep->hwep_num_base; | ||
1800 | |||
1801 | ep_dbg(ep, "EP enabled: %s, HW:%d, MP:%d IN:%d\n", ep->ep.name, | ||
1802 | ep->hwep_num, maxpacket, (ep->is_in == 1)); | ||
1803 | |||
1804 | /* Realize the endpoint, interrupt is enabled later when | ||
1805 | * buffers are queued, IN EPs will NAK until buffers are ready */ | ||
1806 | udc_realize_hwep(udc, ep->hwep_num, ep->ep.maxpacket); | ||
1807 | udc_clr_buffer_hwep(udc, ep->hwep_num); | ||
1808 | uda_disable_hwepint(udc, ep->hwep_num); | ||
1809 | udc_clrstall_hwep(udc, ep->hwep_num); | ||
1810 | |||
1811 | /* Clear all DMA statuses for this EP */ | ||
1812 | udc_ep_dma_disable(udc, ep->hwep_num); | ||
1813 | writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); | ||
1814 | writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); | ||
1815 | writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); | ||
1816 | writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); | ||
1817 | |||
1818 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1819 | |||
1820 | atomic_inc(&udc->enabled_ep_cnt); | ||
1821 | return 0; | ||
1822 | } | ||
1823 | |||
1824 | /* | ||
1825 | * Allocate a USB request list | ||
1826 | * Can be called with or without lock | ||
1827 | */ | ||
1828 | static struct usb_request *lpc32xx_ep_alloc_request(struct usb_ep *_ep, | ||
1829 | gfp_t gfp_flags) | ||
1830 | { | ||
1831 | struct lpc32xx_request *req; | ||
1832 | |||
1833 | req = kzalloc(sizeof(struct lpc32xx_request), gfp_flags); | ||
1834 | if (!req) | ||
1835 | return NULL; | ||
1836 | |||
1837 | INIT_LIST_HEAD(&req->queue); | ||
1838 | return &req->req; | ||
1839 | } | ||
1840 | |||
1841 | /* | ||
1842 | * De-allocate a USB request list | ||
1843 | * Can be called with or without lock | ||
1844 | */ | ||
1845 | static void lpc32xx_ep_free_request(struct usb_ep *_ep, | ||
1846 | struct usb_request *_req) | ||
1847 | { | ||
1848 | struct lpc32xx_request *req; | ||
1849 | |||
1850 | req = container_of(_req, struct lpc32xx_request, req); | ||
1851 | BUG_ON(!list_empty(&req->queue)); | ||
1852 | kfree(req); | ||
1853 | } | ||
1854 | |||
1855 | /* Must be called without lock */ | ||
1856 | static int lpc32xx_ep_queue(struct usb_ep *_ep, | ||
1857 | struct usb_request *_req, gfp_t gfp_flags) | ||
1858 | { | ||
1859 | struct lpc32xx_request *req; | ||
1860 | struct lpc32xx_ep *ep; | ||
1861 | struct lpc32xx_udc *udc; | ||
1862 | unsigned long flags; | ||
1863 | int status = 0; | ||
1864 | |||
1865 | req = container_of(_req, struct lpc32xx_request, req); | ||
1866 | ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
1867 | |||
1868 | if (!_req || !_req->complete || !_req->buf || | ||
1869 | !list_empty(&req->queue)) | ||
1870 | return -EINVAL; | ||
1871 | |||
1872 | udc = ep->udc; | ||
1873 | |||
1874 | if (!_ep || (!ep->desc && ep->hwep_num_base != 0)) { | ||
1875 | dev_dbg(udc->dev, "invalid ep\n"); | ||
1876 | return -EINVAL; | ||
1877 | } | ||
1878 | |||
1879 | |||
1880 | if ((!udc) || (!udc->driver) || | ||
1881 | (udc->gadget.speed == USB_SPEED_UNKNOWN)) { | ||
1882 | dev_dbg(udc->dev, "invalid device\n"); | ||
1883 | return -EINVAL; | ||
1884 | } | ||
1885 | |||
1886 | if (ep->lep) { | ||
1887 | enum dma_data_direction direction; | ||
1888 | struct lpc32xx_usbd_dd_gad *dd; | ||
1889 | |||
1890 | /* Map DMA pointer */ | ||
1891 | if (ep->is_in) | ||
1892 | direction = DMA_TO_DEVICE; | ||
1893 | else | ||
1894 | direction = DMA_FROM_DEVICE; | ||
1895 | |||
1896 | if (req->req.dma == 0) { | ||
1897 | req->req.dma = dma_map_single( | ||
1898 | ep->udc->gadget.dev.parent, | ||
1899 | req->req.buf, req->req.length, direction); | ||
1900 | req->mapped = 1; | ||
1901 | } else { | ||
1902 | dma_sync_single_for_device( | ||
1903 | ep->udc->gadget.dev.parent, req->req.dma, | ||
1904 | req->req.length, direction); | ||
1905 | req->mapped = 0; | ||
1906 | } | ||
1907 | |||
1908 | /* For the request, build a list of DDs */ | ||
1909 | dd = udc_dd_alloc(udc); | ||
1910 | if (!dd) { | ||
1911 | /* Error allocating DD */ | ||
1912 | return -ENOMEM; | ||
1913 | } | ||
1914 | req->dd_desc_ptr = dd; | ||
1915 | |||
1916 | /* Setup the DMA descriptor */ | ||
1917 | dd->dd_next_phy = dd->dd_next_v = 0; | ||
1918 | dd->dd_buffer_addr = req->req.dma; | ||
1919 | dd->dd_status = 0; | ||
1920 | |||
1921 | /* Special handling for ISO EPs */ | ||
1922 | if (ep->eptype == EP_ISO_TYPE) { | ||
1923 | dd->dd_setup = DD_SETUP_ISO_EP | | ||
1924 | DD_SETUP_PACKETLEN(0) | | ||
1925 | DD_SETUP_DMALENBYTES(1); | ||
1926 | dd->dd_iso_ps_mem_addr = dd->this_dma + 24; | ||
1927 | if (ep->is_in) | ||
1928 | dd->iso_status[0] = req->req.length; | ||
1929 | else | ||
1930 | dd->iso_status[0] = 0; | ||
1931 | } else | ||
1932 | dd->dd_setup = DD_SETUP_PACKETLEN(ep->ep.maxpacket) | | ||
1933 | DD_SETUP_DMALENBYTES(req->req.length); | ||
1934 | } | ||
1935 | |||
1936 | ep_dbg(ep, "%s queue req %p len %d buf %p (in=%d) z=%d\n", _ep->name, | ||
1937 | _req, _req->length, _req->buf, ep->is_in, _req->zero); | ||
1938 | |||
1939 | spin_lock_irqsave(&udc->lock, flags); | ||
1940 | |||
1941 | _req->status = -EINPROGRESS; | ||
1942 | _req->actual = 0; | ||
1943 | req->send_zlp = _req->zero; | ||
1944 | |||
1945 | /* Kickstart empty queues */ | ||
1946 | if (list_empty(&ep->queue)) { | ||
1947 | list_add_tail(&req->queue, &ep->queue); | ||
1948 | |||
1949 | if (ep->hwep_num_base == 0) { | ||
1950 | /* Handle expected data direction */ | ||
1951 | if (ep->is_in) { | ||
1952 | /* IN packet to host */ | ||
1953 | udc->ep0state = DATA_IN; | ||
1954 | status = udc_ep0_in_req(udc); | ||
1955 | } else { | ||
1956 | /* OUT packet from host */ | ||
1957 | udc->ep0state = DATA_OUT; | ||
1958 | status = udc_ep0_out_req(udc); | ||
1959 | } | ||
1960 | } else if (ep->is_in) { | ||
1961 | /* IN packet to host and kick off transfer */ | ||
1962 | if (!ep->req_pending) | ||
1963 | udc_ep_in_req_dma(udc, ep); | ||
1964 | } else | ||
1965 | /* OUT packet from host and kick off list */ | ||
1966 | if (!ep->req_pending) | ||
1967 | udc_ep_out_req_dma(udc, ep); | ||
1968 | } else | ||
1969 | list_add_tail(&req->queue, &ep->queue); | ||
1970 | |||
1971 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1972 | |||
1973 | return (status < 0) ? status : 0; | ||
1974 | } | ||
1975 | |||
1976 | /* Must be called without lock */ | ||
1977 | static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1978 | { | ||
1979 | struct lpc32xx_ep *ep; | ||
1980 | struct lpc32xx_request *req; | ||
1981 | unsigned long flags; | ||
1982 | |||
1983 | ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
1984 | if (!_ep || ep->hwep_num_base == 0) | ||
1985 | return -EINVAL; | ||
1986 | |||
1987 | spin_lock_irqsave(&ep->udc->lock, flags); | ||
1988 | |||
1989 | /* make sure it's actually queued on this endpoint */ | ||
1990 | list_for_each_entry(req, &ep->queue, queue) { | ||
1991 | if (&req->req == _req) | ||
1992 | break; | ||
1993 | } | ||
1994 | if (&req->req != _req) { | ||
1995 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
1996 | return -EINVAL; | ||
1997 | } | ||
1998 | |||
1999 | done(ep, req, -ECONNRESET); | ||
2000 | |||
2001 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
2002 | |||
2003 | return 0; | ||
2004 | } | ||
2005 | |||
2006 | /* Must be called without lock */ | ||
2007 | static int lpc32xx_ep_set_halt(struct usb_ep *_ep, int value) | ||
2008 | { | ||
2009 | struct lpc32xx_ep *ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
2010 | struct lpc32xx_udc *udc = ep->udc; | ||
2011 | unsigned long flags; | ||
2012 | |||
2013 | if ((!ep) || (ep->desc == NULL) || (ep->hwep_num <= 1)) | ||
2014 | return -EINVAL; | ||
2015 | |||
2016 | /* Don't halt an IN EP */ | ||
2017 | if (ep->is_in) | ||
2018 | return -EAGAIN; | ||
2019 | |||
2020 | spin_lock_irqsave(&udc->lock, flags); | ||
2021 | |||
2022 | if (value == 1) { | ||
2023 | /* stall */ | ||
2024 | udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), | ||
2025 | DAT_WR_BYTE(EP_STAT_ST)); | ||
2026 | } else { | ||
2027 | /* End stall */ | ||
2028 | ep->wedge = 0; | ||
2029 | udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), | ||
2030 | DAT_WR_BYTE(0)); | ||
2031 | } | ||
2032 | |||
2033 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2034 | |||
2035 | return 0; | ||
2036 | } | ||
2037 | |||
2038 | /* set the halt feature and ignores clear requests */ | ||
2039 | static int lpc32xx_ep_set_wedge(struct usb_ep *_ep) | ||
2040 | { | ||
2041 | struct lpc32xx_ep *ep = container_of(_ep, struct lpc32xx_ep, ep); | ||
2042 | |||
2043 | if (!_ep || !ep->udc) | ||
2044 | return -EINVAL; | ||
2045 | |||
2046 | ep->wedge = 1; | ||
2047 | |||
2048 | return usb_ep_set_halt(_ep); | ||
2049 | } | ||
2050 | |||
2051 | static const struct usb_ep_ops lpc32xx_ep_ops = { | ||
2052 | .enable = lpc32xx_ep_enable, | ||
2053 | .disable = lpc32xx_ep_disable, | ||
2054 | .alloc_request = lpc32xx_ep_alloc_request, | ||
2055 | .free_request = lpc32xx_ep_free_request, | ||
2056 | .queue = lpc32xx_ep_queue, | ||
2057 | .dequeue = lpc32xx_ep_dequeue, | ||
2058 | .set_halt = lpc32xx_ep_set_halt, | ||
2059 | .set_wedge = lpc32xx_ep_set_wedge, | ||
2060 | }; | ||
2061 | |||
2062 | /* Send a ZLP on a non-0 IN EP */ | ||
2063 | void udc_send_in_zlp(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) | ||
2064 | { | ||
2065 | /* Clear EP status */ | ||
2066 | udc_clearep_getsts(udc, ep->hwep_num); | ||
2067 | |||
2068 | /* Send ZLP via FIFO mechanism */ | ||
2069 | udc_write_hwep(udc, ep->hwep_num, NULL, 0); | ||
2070 | } | ||
2071 | |||
2072 | /* | ||
2073 | * Handle EP completion for ZLP | ||
2074 | * This function will only be called when a delayed ZLP needs to be sent out | ||
2075 | * after a DMA transfer has filled both buffers. | ||
2076 | */ | ||
2077 | void udc_handle_eps(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) | ||
2078 | { | ||
2079 | u32 epstatus; | ||
2080 | struct lpc32xx_request *req; | ||
2081 | |||
2082 | if (ep->hwep_num <= 0) | ||
2083 | return; | ||
2084 | |||
2085 | uda_clear_hwepint(udc, ep->hwep_num); | ||
2086 | |||
2087 | /* If this interrupt isn't enabled, return now */ | ||
2088 | if (!(udc->enabled_hwepints & (1 << ep->hwep_num))) | ||
2089 | return; | ||
2090 | |||
2091 | /* Get endpoint status */ | ||
2092 | epstatus = udc_clearep_getsts(udc, ep->hwep_num); | ||
2093 | |||
2094 | /* | ||
2095 | * This should never happen, but protect against writing to the | ||
2096 | * buffer when full. | ||
2097 | */ | ||
2098 | if (epstatus & EP_SEL_F) | ||
2099 | return; | ||
2100 | |||
2101 | if (ep->is_in) { | ||
2102 | udc_send_in_zlp(udc, ep); | ||
2103 | uda_disable_hwepint(udc, ep->hwep_num); | ||
2104 | } else | ||
2105 | return; | ||
2106 | |||
2107 | /* If there isn't a request waiting, something went wrong */ | ||
2108 | req = list_entry(ep->queue.next, struct lpc32xx_request, queue); | ||
2109 | if (req) { | ||
2110 | done(ep, req, 0); | ||
2111 | |||
2112 | /* Start another request if ready */ | ||
2113 | if (!list_empty(&ep->queue)) { | ||
2114 | if (ep->is_in) | ||
2115 | udc_ep_in_req_dma(udc, ep); | ||
2116 | else | ||
2117 | udc_ep_out_req_dma(udc, ep); | ||
2118 | } else | ||
2119 | ep->req_pending = 0; | ||
2120 | } | ||
2121 | } | ||
2122 | |||
2123 | |||
2124 | /* DMA end of transfer completion */ | ||
2125 | static void udc_handle_dma_ep(struct lpc32xx_udc *udc, struct lpc32xx_ep *ep) | ||
2126 | { | ||
2127 | u32 status, epstatus; | ||
2128 | struct lpc32xx_request *req; | ||
2129 | struct lpc32xx_usbd_dd_gad *dd; | ||
2130 | |||
2131 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2132 | ep->totalints++; | ||
2133 | #endif | ||
2134 | |||
2135 | req = list_entry(ep->queue.next, struct lpc32xx_request, queue); | ||
2136 | if (!req) { | ||
2137 | ep_err(ep, "DMA interrupt on no req!\n"); | ||
2138 | return; | ||
2139 | } | ||
2140 | dd = req->dd_desc_ptr; | ||
2141 | |||
2142 | /* DMA descriptor should always be retired for this call */ | ||
2143 | if (!(dd->dd_status & DD_STATUS_DD_RETIRED)) | ||
2144 | ep_warn(ep, "DMA descriptor did not retire\n"); | ||
2145 | |||
2146 | /* Disable DMA */ | ||
2147 | udc_ep_dma_disable(udc, ep->hwep_num); | ||
2148 | writel((1 << ep->hwep_num), USBD_EOTINTCLR(udc->udp_baseaddr)); | ||
2149 | writel((1 << ep->hwep_num), USBD_NDDRTINTCLR(udc->udp_baseaddr)); | ||
2150 | |||
2151 | /* System error? */ | ||
2152 | if (readl(USBD_SYSERRTINTST(udc->udp_baseaddr)) & | ||
2153 | (1 << ep->hwep_num)) { | ||
2154 | writel((1 << ep->hwep_num), | ||
2155 | USBD_SYSERRTINTCLR(udc->udp_baseaddr)); | ||
2156 | ep_err(ep, "AHB critical error!\n"); | ||
2157 | ep->req_pending = 0; | ||
2158 | |||
2159 | /* The error could have occurred on a packet of a multipacket | ||
2160 | * transfer, so recovering the transfer is not possible. Close | ||
2161 | * the request with an error */ | ||
2162 | done(ep, req, -ECONNABORTED); | ||
2163 | return; | ||
2164 | } | ||
2165 | |||
2166 | /* Handle the current DD's status */ | ||
2167 | status = dd->dd_status; | ||
2168 | switch (status & DD_STATUS_STS_MASK) { | ||
2169 | case DD_STATUS_STS_NS: | ||
2170 | /* DD not serviced? This shouldn't happen! */ | ||
2171 | ep->req_pending = 0; | ||
2172 | ep_err(ep, "DMA critical EP error: DD not serviced (0x%x)!\n", | ||
2173 | status); | ||
2174 | |||
2175 | done(ep, req, -ECONNABORTED); | ||
2176 | return; | ||
2177 | |||
2178 | case DD_STATUS_STS_BS: | ||
2179 | /* Interrupt only fires on EOT - This shouldn't happen! */ | ||
2180 | ep->req_pending = 0; | ||
2181 | ep_err(ep, "DMA critical EP error: EOT prior to service completion (0x%x)!\n", | ||
2182 | status); | ||
2183 | done(ep, req, -ECONNABORTED); | ||
2184 | return; | ||
2185 | |||
2186 | case DD_STATUS_STS_NC: | ||
2187 | case DD_STATUS_STS_DUR: | ||
2188 | /* Really just a short packet, not an underrun */ | ||
2189 | /* This is a good status and what we expect */ | ||
2190 | break; | ||
2191 | |||
2192 | default: | ||
2193 | /* Data overrun, system error, or unknown */ | ||
2194 | ep->req_pending = 0; | ||
2195 | ep_err(ep, "DMA critical EP error: System error (0x%x)!\n", | ||
2196 | status); | ||
2197 | done(ep, req, -ECONNABORTED); | ||
2198 | return; | ||
2199 | } | ||
2200 | |||
2201 | /* ISO endpoints are handled differently */ | ||
2202 | if (ep->eptype == EP_ISO_TYPE) { | ||
2203 | if (ep->is_in) | ||
2204 | req->req.actual = req->req.length; | ||
2205 | else | ||
2206 | req->req.actual = dd->iso_status[0] & 0xFFFF; | ||
2207 | } else | ||
2208 | req->req.actual += DD_STATUS_CURDMACNT(status); | ||
2209 | |||
2210 | /* Send a ZLP if necessary. This will be done for non-int | ||
2211 | * packets which have a size that is a divisor of MAXP */ | ||
2212 | if (req->send_zlp) { | ||
2213 | /* | ||
2214 | * If at least 1 buffer is available, send the ZLP now. | ||
2215 | * Otherwise, the ZLP send needs to be deferred until a | ||
2216 | * buffer is available. | ||
2217 | */ | ||
2218 | if (udc_clearep_getsts(udc, ep->hwep_num) & EP_SEL_F) { | ||
2219 | udc_clearep_getsts(udc, ep->hwep_num); | ||
2220 | uda_enable_hwepint(udc, ep->hwep_num); | ||
2221 | epstatus = udc_clearep_getsts(udc, ep->hwep_num); | ||
2222 | |||
2223 | /* Let the EP interrupt handle the ZLP */ | ||
2224 | return; | ||
2225 | } else | ||
2226 | udc_send_in_zlp(udc, ep); | ||
2227 | } | ||
2228 | |||
2229 | /* Transfer request is complete */ | ||
2230 | done(ep, req, 0); | ||
2231 | |||
2232 | /* Start another request if ready */ | ||
2233 | udc_clearep_getsts(udc, ep->hwep_num); | ||
2234 | if (!list_empty((&ep->queue))) { | ||
2235 | if (ep->is_in) | ||
2236 | udc_ep_in_req_dma(udc, ep); | ||
2237 | else | ||
2238 | udc_ep_out_req_dma(udc, ep); | ||
2239 | } else | ||
2240 | ep->req_pending = 0; | ||
2241 | |||
2242 | } | ||
2243 | |||
2244 | /* | ||
2245 | * | ||
2246 | * Endpoint 0 functions | ||
2247 | * | ||
2248 | */ | ||
2249 | static void udc_handle_dev(struct lpc32xx_udc *udc) | ||
2250 | { | ||
2251 | u32 tmp; | ||
2252 | |||
2253 | udc_protocol_cmd_w(udc, CMD_GET_DEV_STAT); | ||
2254 | tmp = udc_protocol_cmd_r(udc, DAT_GET_DEV_STAT); | ||
2255 | |||
2256 | if (tmp & DEV_RST) | ||
2257 | uda_usb_reset(udc); | ||
2258 | else if (tmp & DEV_CON_CH) | ||
2259 | uda_power_event(udc, (tmp & DEV_CON)); | ||
2260 | else if (tmp & DEV_SUS_CH) { | ||
2261 | if (tmp & DEV_SUS) { | ||
2262 | if (udc->vbus == 0) | ||
2263 | stop_activity(udc); | ||
2264 | else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && | ||
2265 | udc->driver) { | ||
2266 | /* Power down transceiver */ | ||
2267 | udc->poweron = 0; | ||
2268 | schedule_work(&udc->pullup_job); | ||
2269 | uda_resm_susp_event(udc, 1); | ||
2270 | } | ||
2271 | } else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && | ||
2272 | udc->driver && udc->vbus) { | ||
2273 | uda_resm_susp_event(udc, 0); | ||
2274 | /* Power up transceiver */ | ||
2275 | udc->poweron = 1; | ||
2276 | schedule_work(&udc->pullup_job); | ||
2277 | } | ||
2278 | } | ||
2279 | } | ||
2280 | |||
2281 | static int udc_get_status(struct lpc32xx_udc *udc, u16 reqtype, u16 wIndex) | ||
2282 | { | ||
2283 | struct lpc32xx_ep *ep; | ||
2284 | u32 ep0buff = 0, tmp; | ||
2285 | |||
2286 | switch (reqtype & USB_RECIP_MASK) { | ||
2287 | case USB_RECIP_INTERFACE: | ||
2288 | break; /* Not supported */ | ||
2289 | |||
2290 | case USB_RECIP_DEVICE: | ||
2291 | ep0buff = (udc->selfpowered << USB_DEVICE_SELF_POWERED); | ||
2292 | if (udc->dev_status & (1 << USB_DEVICE_REMOTE_WAKEUP)) | ||
2293 | ep0buff |= (1 << USB_DEVICE_REMOTE_WAKEUP); | ||
2294 | break; | ||
2295 | |||
2296 | case USB_RECIP_ENDPOINT: | ||
2297 | tmp = wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
2298 | ep = &udc->ep[tmp]; | ||
2299 | if ((tmp == 0) || (tmp >= NUM_ENDPOINTS) || (tmp && !ep->desc)) | ||
2300 | return -EOPNOTSUPP; | ||
2301 | |||
2302 | if (wIndex & USB_DIR_IN) { | ||
2303 | if (!ep->is_in) | ||
2304 | return -EOPNOTSUPP; /* Something's wrong */ | ||
2305 | } else if (ep->is_in) | ||
2306 | return -EOPNOTSUPP; /* Not an IN endpoint */ | ||
2307 | |||
2308 | /* Get status of the endpoint */ | ||
2309 | udc_protocol_cmd_w(udc, CMD_SEL_EP(ep->hwep_num)); | ||
2310 | tmp = udc_protocol_cmd_r(udc, DAT_SEL_EP(ep->hwep_num)); | ||
2311 | |||
2312 | if (tmp & EP_SEL_ST) | ||
2313 | ep0buff = (1 << USB_ENDPOINT_HALT); | ||
2314 | else | ||
2315 | ep0buff = 0; | ||
2316 | break; | ||
2317 | |||
2318 | default: | ||
2319 | break; | ||
2320 | } | ||
2321 | |||
2322 | /* Return data */ | ||
2323 | udc_write_hwep(udc, EP_IN, &ep0buff, 2); | ||
2324 | |||
2325 | return 0; | ||
2326 | } | ||
2327 | |||
2328 | static void udc_handle_ep0_setup(struct lpc32xx_udc *udc) | ||
2329 | { | ||
2330 | struct lpc32xx_ep *ep, *ep0 = &udc->ep[0]; | ||
2331 | struct usb_ctrlrequest ctrlpkt; | ||
2332 | int i, bytes; | ||
2333 | u16 wIndex, wValue, wLength, reqtype, req, tmp; | ||
2334 | |||
2335 | /* Nuke previous transfers */ | ||
2336 | nuke(ep0, -EPROTO); | ||
2337 | |||
2338 | /* Get setup packet */ | ||
2339 | bytes = udc_read_hwep(udc, EP_OUT, (u32 *) &ctrlpkt, 8); | ||
2340 | if (bytes != 8) { | ||
2341 | ep_warn(ep0, "Incorrectly sized setup packet (s/b 8, is %d)!\n", | ||
2342 | bytes); | ||
2343 | return; | ||
2344 | } | ||
2345 | |||
2346 | /* Native endianness */ | ||
2347 | wIndex = le16_to_cpu(ctrlpkt.wIndex); | ||
2348 | wValue = le16_to_cpu(ctrlpkt.wValue); | ||
2349 | wLength = le16_to_cpu(ctrlpkt.wLength); | ||
2350 | reqtype = le16_to_cpu(ctrlpkt.bRequestType); | ||
2351 | |||
2352 | /* Set direction of EP0 */ | ||
2353 | if (likely(reqtype & USB_DIR_IN)) | ||
2354 | ep0->is_in = 1; | ||
2355 | else | ||
2356 | ep0->is_in = 0; | ||
2357 | |||
2358 | /* Handle SETUP packet */ | ||
2359 | req = le16_to_cpu(ctrlpkt.bRequest); | ||
2360 | switch (req) { | ||
2361 | case USB_REQ_CLEAR_FEATURE: | ||
2362 | case USB_REQ_SET_FEATURE: | ||
2363 | switch (reqtype) { | ||
2364 | case (USB_TYPE_STANDARD | USB_RECIP_DEVICE): | ||
2365 | if (wValue != USB_DEVICE_REMOTE_WAKEUP) | ||
2366 | goto stall; /* Nothing else handled */ | ||
2367 | |||
2368 | /* Tell board about event */ | ||
2369 | if (req == USB_REQ_CLEAR_FEATURE) | ||
2370 | udc->dev_status &= | ||
2371 | ~(1 << USB_DEVICE_REMOTE_WAKEUP); | ||
2372 | else | ||
2373 | udc->dev_status |= | ||
2374 | (1 << USB_DEVICE_REMOTE_WAKEUP); | ||
2375 | uda_remwkp_cgh(udc); | ||
2376 | goto zlp_send; | ||
2377 | |||
2378 | case (USB_TYPE_STANDARD | USB_RECIP_ENDPOINT): | ||
2379 | tmp = wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
2380 | if ((wValue != USB_ENDPOINT_HALT) || | ||
2381 | (tmp >= NUM_ENDPOINTS)) | ||
2382 | break; | ||
2383 | |||
2384 | /* Find hardware endpoint from logical endpoint */ | ||
2385 | ep = &udc->ep[tmp]; | ||
2386 | tmp = ep->hwep_num; | ||
2387 | if (tmp == 0) | ||
2388 | break; | ||
2389 | |||
2390 | if (req == USB_REQ_SET_FEATURE) | ||
2391 | udc_stall_hwep(udc, tmp); | ||
2392 | else if (!ep->wedge) | ||
2393 | udc_clrstall_hwep(udc, tmp); | ||
2394 | |||
2395 | goto zlp_send; | ||
2396 | |||
2397 | default: | ||
2398 | break; | ||
2399 | } | ||
2400 | |||
2401 | |||
2402 | case USB_REQ_SET_ADDRESS: | ||
2403 | if (reqtype == (USB_TYPE_STANDARD | USB_RECIP_DEVICE)) { | ||
2404 | udc_set_address(udc, wValue); | ||
2405 | goto zlp_send; | ||
2406 | } | ||
2407 | break; | ||
2408 | |||
2409 | case USB_REQ_GET_STATUS: | ||
2410 | udc_get_status(udc, reqtype, wIndex); | ||
2411 | return; | ||
2412 | |||
2413 | default: | ||
2414 | break; /* Let GadgetFS handle the descriptor instead */ | ||
2415 | } | ||
2416 | |||
2417 | if (likely(udc->driver)) { | ||
2418 | /* device-2-host (IN) or no data setup command, process | ||
2419 | * immediately */ | ||
2420 | spin_unlock(&udc->lock); | ||
2421 | i = udc->driver->setup(&udc->gadget, &ctrlpkt); | ||
2422 | |||
2423 | spin_lock(&udc->lock); | ||
2424 | if (req == USB_REQ_SET_CONFIGURATION) { | ||
2425 | /* Configuration is set after endpoints are realized */ | ||
2426 | if (wValue) { | ||
2427 | /* Set configuration */ | ||
2428 | udc_set_device_configured(udc); | ||
2429 | |||
2430 | udc_protocol_cmd_data_w(udc, CMD_SET_MODE, | ||
2431 | DAT_WR_BYTE(AP_CLK | | ||
2432 | INAK_BI | INAK_II)); | ||
2433 | } else { | ||
2434 | /* Clear configuration */ | ||
2435 | udc_set_device_unconfigured(udc); | ||
2436 | |||
2437 | /* Disable NAK interrupts */ | ||
2438 | udc_protocol_cmd_data_w(udc, CMD_SET_MODE, | ||
2439 | DAT_WR_BYTE(AP_CLK)); | ||
2440 | } | ||
2441 | } | ||
2442 | |||
2443 | if (i < 0) { | ||
2444 | /* setup processing failed, force stall */ | ||
2445 | dev_err(udc->dev, | ||
2446 | "req %02x.%02x protocol STALL; stat %d\n", | ||
2447 | reqtype, req, i); | ||
2448 | udc->ep0state = WAIT_FOR_SETUP; | ||
2449 | goto stall; | ||
2450 | } | ||
2451 | } | ||
2452 | |||
2453 | if (!ep0->is_in) | ||
2454 | udc_ep0_send_zlp(udc); /* ZLP IN packet on data phase */ | ||
2455 | |||
2456 | return; | ||
2457 | |||
2458 | stall: | ||
2459 | udc_stall_hwep(udc, EP_IN); | ||
2460 | return; | ||
2461 | |||
2462 | zlp_send: | ||
2463 | udc_ep0_send_zlp(udc); | ||
2464 | return; | ||
2465 | } | ||
2466 | |||
2467 | /* IN endpoint 0 transfer */ | ||
2468 | static void udc_handle_ep0_in(struct lpc32xx_udc *udc) | ||
2469 | { | ||
2470 | struct lpc32xx_ep *ep0 = &udc->ep[0]; | ||
2471 | u32 epstatus; | ||
2472 | |||
2473 | /* Clear EP interrupt */ | ||
2474 | epstatus = udc_clearep_getsts(udc, EP_IN); | ||
2475 | |||
2476 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2477 | ep0->totalints++; | ||
2478 | #endif | ||
2479 | |||
2480 | /* Stalled? Clear stall and reset buffers */ | ||
2481 | if (epstatus & EP_SEL_ST) { | ||
2482 | udc_clrstall_hwep(udc, EP_IN); | ||
2483 | nuke(ep0, -ECONNABORTED); | ||
2484 | udc->ep0state = WAIT_FOR_SETUP; | ||
2485 | return; | ||
2486 | } | ||
2487 | |||
2488 | /* Is a buffer available? */ | ||
2489 | if (!(epstatus & EP_SEL_F)) { | ||
2490 | /* Handle based on current state */ | ||
2491 | if (udc->ep0state == DATA_IN) | ||
2492 | udc_ep0_in_req(udc); | ||
2493 | else { | ||
2494 | /* Unknown state for EP0 oe end of DATA IN phase */ | ||
2495 | nuke(ep0, -ECONNABORTED); | ||
2496 | udc->ep0state = WAIT_FOR_SETUP; | ||
2497 | } | ||
2498 | } | ||
2499 | } | ||
2500 | |||
2501 | /* OUT endpoint 0 transfer */ | ||
2502 | static void udc_handle_ep0_out(struct lpc32xx_udc *udc) | ||
2503 | { | ||
2504 | struct lpc32xx_ep *ep0 = &udc->ep[0]; | ||
2505 | u32 epstatus; | ||
2506 | |||
2507 | /* Clear EP interrupt */ | ||
2508 | epstatus = udc_clearep_getsts(udc, EP_OUT); | ||
2509 | |||
2510 | |||
2511 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | ||
2512 | ep0->totalints++; | ||
2513 | #endif | ||
2514 | |||
2515 | /* Stalled? */ | ||
2516 | if (epstatus & EP_SEL_ST) { | ||
2517 | udc_clrstall_hwep(udc, EP_OUT); | ||
2518 | nuke(ep0, -ECONNABORTED); | ||
2519 | udc->ep0state = WAIT_FOR_SETUP; | ||
2520 | return; | ||
2521 | } | ||
2522 | |||
2523 | /* A NAK may occur if a packet couldn't be received yet */ | ||
2524 | if (epstatus & EP_SEL_EPN) | ||
2525 | return; | ||
2526 | /* Setup packet incoming? */ | ||
2527 | if (epstatus & EP_SEL_STP) { | ||
2528 | nuke(ep0, 0); | ||
2529 | udc->ep0state = WAIT_FOR_SETUP; | ||
2530 | } | ||
2531 | |||
2532 | /* Data available? */ | ||
2533 | if (epstatus & EP_SEL_F) | ||
2534 | /* Handle based on current state */ | ||
2535 | switch (udc->ep0state) { | ||
2536 | case WAIT_FOR_SETUP: | ||
2537 | udc_handle_ep0_setup(udc); | ||
2538 | break; | ||
2539 | |||
2540 | case DATA_OUT: | ||
2541 | udc_ep0_out_req(udc); | ||
2542 | break; | ||
2543 | |||
2544 | default: | ||
2545 | /* Unknown state for EP0 */ | ||
2546 | nuke(ep0, -ECONNABORTED); | ||
2547 | udc->ep0state = WAIT_FOR_SETUP; | ||
2548 | } | ||
2549 | } | ||
2550 | |||
2551 | /* Must be called without lock */ | ||
2552 | static int lpc32xx_get_frame(struct usb_gadget *gadget) | ||
2553 | { | ||
2554 | int frame; | ||
2555 | unsigned long flags; | ||
2556 | struct lpc32xx_udc *udc = to_udc(gadget); | ||
2557 | |||
2558 | if (!udc->clocked) | ||
2559 | return -EINVAL; | ||
2560 | |||
2561 | spin_lock_irqsave(&udc->lock, flags); | ||
2562 | |||
2563 | frame = (int) udc_get_current_frame(udc); | ||
2564 | |||
2565 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2566 | |||
2567 | return frame; | ||
2568 | } | ||
2569 | |||
2570 | static int lpc32xx_wakeup(struct usb_gadget *gadget) | ||
2571 | { | ||
2572 | return -ENOTSUPP; | ||
2573 | } | ||
2574 | |||
2575 | static int lpc32xx_set_selfpowered(struct usb_gadget *gadget, int is_on) | ||
2576 | { | ||
2577 | struct lpc32xx_udc *udc = to_udc(gadget); | ||
2578 | |||
2579 | /* Always self-powered */ | ||
2580 | udc->selfpowered = (is_on != 0); | ||
2581 | |||
2582 | return 0; | ||
2583 | } | ||
2584 | |||
2585 | /* | ||
2586 | * vbus is here! turn everything on that's ready | ||
2587 | * Must be called without lock | ||
2588 | */ | ||
2589 | static int lpc32xx_vbus_session(struct usb_gadget *gadget, int is_active) | ||
2590 | { | ||
2591 | unsigned long flags; | ||
2592 | struct lpc32xx_udc *udc = to_udc(gadget); | ||
2593 | |||
2594 | spin_lock_irqsave(&udc->lock, flags); | ||
2595 | |||
2596 | /* Doesn't need lock */ | ||
2597 | if (udc->driver) { | ||
2598 | udc_clk_set(udc, 1); | ||
2599 | udc_enable(udc); | ||
2600 | pullup(udc, is_active); | ||
2601 | } else { | ||
2602 | stop_activity(udc); | ||
2603 | pullup(udc, 0); | ||
2604 | |||
2605 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2606 | /* | ||
2607 | * Wait for all the endpoints to disable, | ||
2608 | * before disabling clocks. Don't wait if | ||
2609 | * endpoints are not enabled. | ||
2610 | */ | ||
2611 | if (atomic_read(&udc->enabled_ep_cnt)) | ||
2612 | wait_event_interruptible(udc->ep_disable_wait_queue, | ||
2613 | (atomic_read(&udc->enabled_ep_cnt) == 0)); | ||
2614 | |||
2615 | spin_lock_irqsave(&udc->lock, flags); | ||
2616 | |||
2617 | udc_clk_set(udc, 0); | ||
2618 | } | ||
2619 | |||
2620 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2621 | |||
2622 | return 0; | ||
2623 | } | ||
2624 | |||
2625 | /* Can be called with or without lock */ | ||
2626 | static int lpc32xx_pullup(struct usb_gadget *gadget, int is_on) | ||
2627 | { | ||
2628 | struct lpc32xx_udc *udc = to_udc(gadget); | ||
2629 | |||
2630 | /* Doesn't need lock */ | ||
2631 | pullup(udc, is_on); | ||
2632 | |||
2633 | return 0; | ||
2634 | } | ||
2635 | |||
2636 | static int lpc32xx_start(struct usb_gadget_driver *driver, | ||
2637 | int (*bind)(struct usb_gadget *)); | ||
2638 | static int lpc32xx_stop(struct usb_gadget_driver *driver); | ||
2639 | |||
2640 | static const struct usb_gadget_ops lpc32xx_udc_ops = { | ||
2641 | .get_frame = lpc32xx_get_frame, | ||
2642 | .wakeup = lpc32xx_wakeup, | ||
2643 | .set_selfpowered = lpc32xx_set_selfpowered, | ||
2644 | .vbus_session = lpc32xx_vbus_session, | ||
2645 | .pullup = lpc32xx_pullup, | ||
2646 | .start = lpc32xx_start, | ||
2647 | .stop = lpc32xx_stop, | ||
2648 | }; | ||
2649 | |||
2650 | static void nop_release(struct device *dev) | ||
2651 | { | ||
2652 | /* nothing to free */ | ||
2653 | } | ||
2654 | |||
2655 | static struct lpc32xx_udc controller = { | ||
2656 | .gadget = { | ||
2657 | .ops = &lpc32xx_udc_ops, | ||
2658 | .ep0 = &controller.ep[0].ep, | ||
2659 | .name = driver_name, | ||
2660 | .dev = { | ||
2661 | .init_name = "gadget", | ||
2662 | .release = nop_release, | ||
2663 | } | ||
2664 | }, | ||
2665 | .ep[0] = { | ||
2666 | .ep = { | ||
2667 | .name = "ep0", | ||
2668 | .ops = &lpc32xx_ep_ops, | ||
2669 | }, | ||
2670 | .udc = &controller, | ||
2671 | .maxpacket = 64, | ||
2672 | .hwep_num_base = 0, | ||
2673 | .hwep_num = 0, /* Can be 0 or 1, has special handling */ | ||
2674 | .lep = 0, | ||
2675 | .eptype = EP_CTL_TYPE, | ||
2676 | }, | ||
2677 | .ep[1] = { | ||
2678 | .ep = { | ||
2679 | .name = "ep1-int", | ||
2680 | .ops = &lpc32xx_ep_ops, | ||
2681 | }, | ||
2682 | .udc = &controller, | ||
2683 | .maxpacket = 64, | ||
2684 | .hwep_num_base = 2, | ||
2685 | .hwep_num = 0, /* 2 or 3, will be set later */ | ||
2686 | .lep = 1, | ||
2687 | .eptype = EP_INT_TYPE, | ||
2688 | }, | ||
2689 | .ep[2] = { | ||
2690 | .ep = { | ||
2691 | .name = "ep2-bulk", | ||
2692 | .ops = &lpc32xx_ep_ops, | ||
2693 | }, | ||
2694 | .udc = &controller, | ||
2695 | .maxpacket = 64, | ||
2696 | .hwep_num_base = 4, | ||
2697 | .hwep_num = 0, /* 4 or 5, will be set later */ | ||
2698 | .lep = 2, | ||
2699 | .eptype = EP_BLK_TYPE, | ||
2700 | }, | ||
2701 | .ep[3] = { | ||
2702 | .ep = { | ||
2703 | .name = "ep3-iso", | ||
2704 | .ops = &lpc32xx_ep_ops, | ||
2705 | }, | ||
2706 | .udc = &controller, | ||
2707 | .maxpacket = 1023, | ||
2708 | .hwep_num_base = 6, | ||
2709 | .hwep_num = 0, /* 6 or 7, will be set later */ | ||
2710 | .lep = 3, | ||
2711 | .eptype = EP_ISO_TYPE, | ||
2712 | }, | ||
2713 | .ep[4] = { | ||
2714 | .ep = { | ||
2715 | .name = "ep4-int", | ||
2716 | .ops = &lpc32xx_ep_ops, | ||
2717 | }, | ||
2718 | .udc = &controller, | ||
2719 | .maxpacket = 64, | ||
2720 | .hwep_num_base = 8, | ||
2721 | .hwep_num = 0, /* 8 or 9, will be set later */ | ||
2722 | .lep = 4, | ||
2723 | .eptype = EP_INT_TYPE, | ||
2724 | }, | ||
2725 | .ep[5] = { | ||
2726 | .ep = { | ||
2727 | .name = "ep5-bulk", | ||
2728 | .ops = &lpc32xx_ep_ops, | ||
2729 | }, | ||
2730 | .udc = &controller, | ||
2731 | .maxpacket = 64, | ||
2732 | .hwep_num_base = 10, | ||
2733 | .hwep_num = 0, /* 10 or 11, will be set later */ | ||
2734 | .lep = 5, | ||
2735 | .eptype = EP_BLK_TYPE, | ||
2736 | }, | ||
2737 | .ep[6] = { | ||
2738 | .ep = { | ||
2739 | .name = "ep6-iso", | ||
2740 | .ops = &lpc32xx_ep_ops, | ||
2741 | }, | ||
2742 | .udc = &controller, | ||
2743 | .maxpacket = 1023, | ||
2744 | .hwep_num_base = 12, | ||
2745 | .hwep_num = 0, /* 12 or 13, will be set later */ | ||
2746 | .lep = 6, | ||
2747 | .eptype = EP_ISO_TYPE, | ||
2748 | }, | ||
2749 | .ep[7] = { | ||
2750 | .ep = { | ||
2751 | .name = "ep7-int", | ||
2752 | .ops = &lpc32xx_ep_ops, | ||
2753 | }, | ||
2754 | .udc = &controller, | ||
2755 | .maxpacket = 64, | ||
2756 | .hwep_num_base = 14, | ||
2757 | .hwep_num = 0, | ||
2758 | .lep = 7, | ||
2759 | .eptype = EP_INT_TYPE, | ||
2760 | }, | ||
2761 | .ep[8] = { | ||
2762 | .ep = { | ||
2763 | .name = "ep8-bulk", | ||
2764 | .ops = &lpc32xx_ep_ops, | ||
2765 | }, | ||
2766 | .udc = &controller, | ||
2767 | .maxpacket = 64, | ||
2768 | .hwep_num_base = 16, | ||
2769 | .hwep_num = 0, | ||
2770 | .lep = 8, | ||
2771 | .eptype = EP_BLK_TYPE, | ||
2772 | }, | ||
2773 | .ep[9] = { | ||
2774 | .ep = { | ||
2775 | .name = "ep9-iso", | ||
2776 | .ops = &lpc32xx_ep_ops, | ||
2777 | }, | ||
2778 | .udc = &controller, | ||
2779 | .maxpacket = 1023, | ||
2780 | .hwep_num_base = 18, | ||
2781 | .hwep_num = 0, | ||
2782 | .lep = 9, | ||
2783 | .eptype = EP_ISO_TYPE, | ||
2784 | }, | ||
2785 | .ep[10] = { | ||
2786 | .ep = { | ||
2787 | .name = "ep10-int", | ||
2788 | .ops = &lpc32xx_ep_ops, | ||
2789 | }, | ||
2790 | .udc = &controller, | ||
2791 | .maxpacket = 64, | ||
2792 | .hwep_num_base = 20, | ||
2793 | .hwep_num = 0, | ||
2794 | .lep = 10, | ||
2795 | .eptype = EP_INT_TYPE, | ||
2796 | }, | ||
2797 | .ep[11] = { | ||
2798 | .ep = { | ||
2799 | .name = "ep11-bulk", | ||
2800 | .ops = &lpc32xx_ep_ops, | ||
2801 | }, | ||
2802 | .udc = &controller, | ||
2803 | .maxpacket = 64, | ||
2804 | .hwep_num_base = 22, | ||
2805 | .hwep_num = 0, | ||
2806 | .lep = 11, | ||
2807 | .eptype = EP_BLK_TYPE, | ||
2808 | }, | ||
2809 | .ep[12] = { | ||
2810 | .ep = { | ||
2811 | .name = "ep12-iso", | ||
2812 | .ops = &lpc32xx_ep_ops, | ||
2813 | }, | ||
2814 | .udc = &controller, | ||
2815 | .maxpacket = 1023, | ||
2816 | .hwep_num_base = 24, | ||
2817 | .hwep_num = 0, | ||
2818 | .lep = 12, | ||
2819 | .eptype = EP_ISO_TYPE, | ||
2820 | }, | ||
2821 | .ep[13] = { | ||
2822 | .ep = { | ||
2823 | .name = "ep13-int", | ||
2824 | .ops = &lpc32xx_ep_ops, | ||
2825 | }, | ||
2826 | .udc = &controller, | ||
2827 | .maxpacket = 64, | ||
2828 | .hwep_num_base = 26, | ||
2829 | .hwep_num = 0, | ||
2830 | .lep = 13, | ||
2831 | .eptype = EP_INT_TYPE, | ||
2832 | }, | ||
2833 | .ep[14] = { | ||
2834 | .ep = { | ||
2835 | .name = "ep14-bulk", | ||
2836 | .ops = &lpc32xx_ep_ops, | ||
2837 | }, | ||
2838 | .udc = &controller, | ||
2839 | .maxpacket = 64, | ||
2840 | .hwep_num_base = 28, | ||
2841 | .hwep_num = 0, | ||
2842 | .lep = 14, | ||
2843 | .eptype = EP_BLK_TYPE, | ||
2844 | }, | ||
2845 | .ep[15] = { | ||
2846 | .ep = { | ||
2847 | .name = "ep15-bulk", | ||
2848 | .ops = &lpc32xx_ep_ops, | ||
2849 | }, | ||
2850 | .udc = &controller, | ||
2851 | .maxpacket = 1023, | ||
2852 | .hwep_num_base = 30, | ||
2853 | .hwep_num = 0, | ||
2854 | .lep = 15, | ||
2855 | .eptype = EP_BLK_TYPE, | ||
2856 | }, | ||
2857 | }; | ||
2858 | |||
2859 | /* ISO and status interrupts */ | ||
2860 | static irqreturn_t lpc32xx_usb_lp_irq(int irq, void *_udc) | ||
2861 | { | ||
2862 | u32 tmp, devstat; | ||
2863 | struct lpc32xx_udc *udc = _udc; | ||
2864 | |||
2865 | spin_lock(&udc->lock); | ||
2866 | |||
2867 | /* Read the device status register */ | ||
2868 | devstat = readl(USBD_DEVINTST(udc->udp_baseaddr)); | ||
2869 | |||
2870 | devstat &= ~USBD_EP_FAST; | ||
2871 | writel(devstat, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
2872 | devstat = devstat & udc->enabled_devints; | ||
2873 | |||
2874 | /* Device specific handling needed? */ | ||
2875 | if (devstat & USBD_DEV_STAT) | ||
2876 | udc_handle_dev(udc); | ||
2877 | |||
2878 | /* Start of frame? (devstat & FRAME_INT): | ||
2879 | * The frame interrupt isn't really needed for ISO support, | ||
2880 | * as the driver will queue the necessary packets */ | ||
2881 | |||
2882 | /* Error? */ | ||
2883 | if (devstat & ERR_INT) { | ||
2884 | /* All types of errors, from cable removal during transfer to | ||
2885 | * misc protocol and bit errors. These are mostly for just info, | ||
2886 | * as the USB hardware will work around these. If these errors | ||
2887 | * happen alot, something is wrong. */ | ||
2888 | udc_protocol_cmd_w(udc, CMD_RD_ERR_STAT); | ||
2889 | tmp = udc_protocol_cmd_r(udc, DAT_RD_ERR_STAT); | ||
2890 | dev_dbg(udc->dev, "Device error (0x%x)!\n", tmp); | ||
2891 | } | ||
2892 | |||
2893 | spin_unlock(&udc->lock); | ||
2894 | |||
2895 | return IRQ_HANDLED; | ||
2896 | } | ||
2897 | |||
2898 | /* EP interrupts */ | ||
2899 | static irqreturn_t lpc32xx_usb_hp_irq(int irq, void *_udc) | ||
2900 | { | ||
2901 | u32 tmp; | ||
2902 | struct lpc32xx_udc *udc = _udc; | ||
2903 | |||
2904 | spin_lock(&udc->lock); | ||
2905 | |||
2906 | /* Read the device status register */ | ||
2907 | writel(USBD_EP_FAST, USBD_DEVINTCLR(udc->udp_baseaddr)); | ||
2908 | |||
2909 | /* Endpoints */ | ||
2910 | tmp = readl(USBD_EPINTST(udc->udp_baseaddr)); | ||
2911 | |||
2912 | /* Special handling for EP0 */ | ||
2913 | if (tmp & (EP_MASK_SEL(0, EP_OUT) | EP_MASK_SEL(0, EP_IN))) { | ||
2914 | /* Handle EP0 IN */ | ||
2915 | if (tmp & (EP_MASK_SEL(0, EP_IN))) | ||
2916 | udc_handle_ep0_in(udc); | ||
2917 | |||
2918 | /* Handle EP0 OUT */ | ||
2919 | if (tmp & (EP_MASK_SEL(0, EP_OUT))) | ||
2920 | udc_handle_ep0_out(udc); | ||
2921 | } | ||
2922 | |||
2923 | /* All other EPs */ | ||
2924 | if (tmp & ~(EP_MASK_SEL(0, EP_OUT) | EP_MASK_SEL(0, EP_IN))) { | ||
2925 | int i; | ||
2926 | |||
2927 | /* Handle other EP interrupts */ | ||
2928 | for (i = 1; i < NUM_ENDPOINTS; i++) { | ||
2929 | if (tmp & (1 << udc->ep[i].hwep_num)) | ||
2930 | udc_handle_eps(udc, &udc->ep[i]); | ||
2931 | } | ||
2932 | } | ||
2933 | |||
2934 | spin_unlock(&udc->lock); | ||
2935 | |||
2936 | return IRQ_HANDLED; | ||
2937 | } | ||
2938 | |||
2939 | static irqreturn_t lpc32xx_usb_devdma_irq(int irq, void *_udc) | ||
2940 | { | ||
2941 | struct lpc32xx_udc *udc = _udc; | ||
2942 | |||
2943 | int i; | ||
2944 | u32 tmp; | ||
2945 | |||
2946 | spin_lock(&udc->lock); | ||
2947 | |||
2948 | /* Handle EP DMA EOT interrupts */ | ||
2949 | tmp = readl(USBD_EOTINTST(udc->udp_baseaddr)) | | ||
2950 | (readl(USBD_EPDMAST(udc->udp_baseaddr)) & | ||
2951 | readl(USBD_NDDRTINTST(udc->udp_baseaddr))) | | ||
2952 | readl(USBD_SYSERRTINTST(udc->udp_baseaddr)); | ||
2953 | for (i = 1; i < NUM_ENDPOINTS; i++) { | ||
2954 | if (tmp & (1 << udc->ep[i].hwep_num)) | ||
2955 | udc_handle_dma_ep(udc, &udc->ep[i]); | ||
2956 | } | ||
2957 | |||
2958 | spin_unlock(&udc->lock); | ||
2959 | |||
2960 | return IRQ_HANDLED; | ||
2961 | } | ||
2962 | |||
2963 | /* | ||
2964 | * | ||
2965 | * VBUS detection, pullup handler, and Gadget cable state notification | ||
2966 | * | ||
2967 | */ | ||
2968 | static void vbus_work(struct work_struct *work) | ||
2969 | { | ||
2970 | u8 value; | ||
2971 | struct lpc32xx_udc *udc = container_of(work, struct lpc32xx_udc, | ||
2972 | vbus_job); | ||
2973 | |||
2974 | if (udc->enabled != 0) { | ||
2975 | /* Discharge VBUS real quick */ | ||
2976 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
2977 | ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DISCHRG); | ||
2978 | |||
2979 | /* Give VBUS some time (100mS) to discharge */ | ||
2980 | msleep(100); | ||
2981 | |||
2982 | /* Disable VBUS discharge resistor */ | ||
2983 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
2984 | ISP1301_I2C_OTG_CONTROL_1 | ISP1301_I2C_REG_CLEAR_ADDR, | ||
2985 | OTG1_VBUS_DISCHRG); | ||
2986 | |||
2987 | /* Clear interrupt */ | ||
2988 | i2c_smbus_write_byte_data(udc->isp1301_i2c_client, | ||
2989 | ISP1301_I2C_INTERRUPT_LATCH | | ||
2990 | ISP1301_I2C_REG_CLEAR_ADDR, ~0); | ||
2991 | |||
2992 | /* Get the VBUS status from the transceiver */ | ||
2993 | value = i2c_smbus_read_byte_data(udc->isp1301_i2c_client, | ||
2994 | ISP1301_I2C_OTG_CONTROL_2); | ||
2995 | |||
2996 | /* VBUS on or off? */ | ||
2997 | if (value & OTG_B_SESS_VLD) | ||
2998 | udc->vbus = 1; | ||
2999 | else | ||
3000 | udc->vbus = 0; | ||
3001 | |||
3002 | /* VBUS changed? */ | ||
3003 | if (udc->last_vbus != udc->vbus) { | ||
3004 | udc->last_vbus = udc->vbus; | ||
3005 | lpc32xx_vbus_session(&udc->gadget, udc->vbus); | ||
3006 | } | ||
3007 | } | ||
3008 | |||
3009 | /* Re-enable after completion */ | ||
3010 | enable_irq(udc->udp_irq[IRQ_USB_ATX]); | ||
3011 | } | ||
3012 | |||
3013 | static irqreturn_t lpc32xx_usb_vbus_irq(int irq, void *_udc) | ||
3014 | { | ||
3015 | struct lpc32xx_udc *udc = _udc; | ||
3016 | |||
3017 | /* Defer handling of VBUS IRQ to work queue */ | ||
3018 | disable_irq_nosync(udc->udp_irq[IRQ_USB_ATX]); | ||
3019 | schedule_work(&udc->vbus_job); | ||
3020 | |||
3021 | return IRQ_HANDLED; | ||
3022 | } | ||
3023 | |||
3024 | static int lpc32xx_start(struct usb_gadget_driver *driver, | ||
3025 | int (*bind)(struct usb_gadget *)) | ||
3026 | { | ||
3027 | struct lpc32xx_udc *udc = &controller; | ||
3028 | int retval, i; | ||
3029 | |||
3030 | if (!driver || driver->max_speed < USB_SPEED_FULL || | ||
3031 | !bind || !driver->setup) { | ||
3032 | dev_err(udc->dev, "bad parameter.\n"); | ||
3033 | return -EINVAL; | ||
3034 | } | ||
3035 | |||
3036 | if (udc->driver) { | ||
3037 | dev_err(udc->dev, "UDC already has a gadget driver\n"); | ||
3038 | return -EBUSY; | ||
3039 | } | ||
3040 | |||
3041 | udc->driver = driver; | ||
3042 | udc->gadget.dev.driver = &driver->driver; | ||
3043 | udc->enabled = 1; | ||
3044 | udc->selfpowered = 1; | ||
3045 | udc->vbus = 0; | ||
3046 | |||
3047 | retval = bind(&udc->gadget); | ||
3048 | if (retval) { | ||
3049 | dev_err(udc->dev, "bind() returned %d\n", retval); | ||
3050 | udc->enabled = 0; | ||
3051 | udc->selfpowered = 0; | ||
3052 | udc->driver = NULL; | ||
3053 | udc->gadget.dev.driver = NULL; | ||
3054 | return retval; | ||
3055 | } | ||
3056 | |||
3057 | dev_dbg(udc->dev, "bound to %s\n", driver->driver.name); | ||
3058 | |||
3059 | /* Force VBUS process once to check for cable insertion */ | ||
3060 | udc->last_vbus = udc->vbus = 0; | ||
3061 | schedule_work(&udc->vbus_job); | ||
3062 | |||
3063 | /* Do not re-enable ATX IRQ (3) */ | ||
3064 | for (i = IRQ_USB_LP; i < IRQ_USB_ATX; i++) | ||
3065 | enable_irq(udc->udp_irq[i]); | ||
3066 | |||
3067 | return 0; | ||
3068 | } | ||
3069 | |||
3070 | static int lpc32xx_stop(struct usb_gadget_driver *driver) | ||
3071 | { | ||
3072 | int i; | ||
3073 | struct lpc32xx_udc *udc = &controller; | ||
3074 | |||
3075 | if (!driver || driver != udc->driver || !driver->unbind) | ||
3076 | return -EINVAL; | ||
3077 | |||
3078 | /* Disable USB pullup */ | ||
3079 | isp1301_pullup_enable(udc, 0, 1); | ||
3080 | |||
3081 | for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) | ||
3082 | disable_irq(udc->udp_irq[i]); | ||
3083 | |||
3084 | if (udc->clocked) { | ||
3085 | |||
3086 | spin_lock(&udc->lock); | ||
3087 | stop_activity(udc); | ||
3088 | spin_unlock(&udc->lock); | ||
3089 | |||
3090 | /* | ||
3091 | * Wait for all the endpoints to disable, | ||
3092 | * before disabling clocks. Don't wait if | ||
3093 | * endpoints are not enabled. | ||
3094 | */ | ||
3095 | if (atomic_read(&udc->enabled_ep_cnt)) | ||
3096 | wait_event_interruptible(udc->ep_disable_wait_queue, | ||
3097 | (atomic_read(&udc->enabled_ep_cnt) == 0)); | ||
3098 | |||
3099 | spin_lock(&udc->lock); | ||
3100 | udc_clk_set(udc, 0); | ||
3101 | spin_unlock(&udc->lock); | ||
3102 | } | ||
3103 | |||
3104 | udc->enabled = 0; | ||
3105 | pullup(udc, 0); | ||
3106 | |||
3107 | driver->unbind(&udc->gadget); | ||
3108 | udc->gadget.dev.driver = NULL; | ||
3109 | udc->driver = NULL; | ||
3110 | |||
3111 | dev_dbg(udc->dev, "unbound from %s\n", driver->driver.name); | ||
3112 | return 0; | ||
3113 | } | ||
3114 | |||
3115 | static void lpc32xx_udc_shutdown(struct platform_device *dev) | ||
3116 | { | ||
3117 | /* Force disconnect on reboot */ | ||
3118 | struct lpc32xx_udc *udc = &controller; | ||
3119 | |||
3120 | pullup(udc, 0); | ||
3121 | } | ||
3122 | |||
3123 | /* | ||
3124 | * Callbacks to be overridden by options passed via OF (TODO) | ||
3125 | */ | ||
3126 | |||
3127 | static void lpc32xx_usbd_conn_chg(int conn) | ||
3128 | { | ||
3129 | /* Do nothing, it might be nice to enable an LED | ||
3130 | * based on conn state being !0 */ | ||
3131 | } | ||
3132 | |||
3133 | static void lpc32xx_usbd_susp_chg(int susp) | ||
3134 | { | ||
3135 | /* Device suspend if susp != 0 */ | ||
3136 | } | ||
3137 | |||
3138 | static void lpc32xx_rmwkup_chg(int remote_wakup_enable) | ||
3139 | { | ||
3140 | /* Enable or disable USB remote wakeup */ | ||
3141 | } | ||
3142 | |||
3143 | struct lpc32xx_usbd_cfg lpc32xx_usbddata = { | ||
3144 | .vbus_drv_pol = 0, | ||
3145 | .conn_chgb = &lpc32xx_usbd_conn_chg, | ||
3146 | .susp_chgb = &lpc32xx_usbd_susp_chg, | ||
3147 | .rmwk_chgb = &lpc32xx_rmwkup_chg, | ||
3148 | }; | ||
3149 | |||
3150 | |||
3151 | static u64 lpc32xx_usbd_dmamask = ~(u32) 0x7F; | ||
3152 | |||
3153 | static int __init lpc32xx_udc_probe(struct platform_device *pdev) | ||
3154 | { | ||
3155 | struct device *dev = &pdev->dev; | ||
3156 | struct lpc32xx_udc *udc = &controller; | ||
3157 | int retval, i; | ||
3158 | struct resource *res; | ||
3159 | dma_addr_t dma_handle; | ||
3160 | struct device_node *isp1301_node; | ||
3161 | |||
3162 | /* init software state */ | ||
3163 | udc->gadget.dev.parent = dev; | ||
3164 | udc->pdev = pdev; | ||
3165 | udc->dev = &pdev->dev; | ||
3166 | udc->enabled = 0; | ||
3167 | |||
3168 | if (pdev->dev.of_node) { | ||
3169 | isp1301_node = of_parse_phandle(pdev->dev.of_node, | ||
3170 | "transceiver", 0); | ||
3171 | } else { | ||
3172 | isp1301_node = NULL; | ||
3173 | } | ||
3174 | |||
3175 | udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); | ||
3176 | if (!udc->isp1301_i2c_client) | ||
3177 | return -EPROBE_DEFER; | ||
3178 | |||
3179 | dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n", | ||
3180 | udc->isp1301_i2c_client->addr); | ||
3181 | |||
3182 | pdev->dev.dma_mask = &lpc32xx_usbd_dmamask; | ||
3183 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | ||
3184 | |||
3185 | udc->board = &lpc32xx_usbddata; | ||
3186 | |||
3187 | /* | ||
3188 | * Resources are mapped as follows: | ||
3189 | * IORESOURCE_MEM, base address and size of USB space | ||
3190 | * IORESOURCE_IRQ, USB device low priority interrupt number | ||
3191 | * IORESOURCE_IRQ, USB device high priority interrupt number | ||
3192 | * IORESOURCE_IRQ, USB device interrupt number | ||
3193 | * IORESOURCE_IRQ, USB transceiver interrupt number | ||
3194 | */ | ||
3195 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
3196 | if (!res) | ||
3197 | return -ENXIO; | ||
3198 | |||
3199 | spin_lock_init(&udc->lock); | ||
3200 | |||
3201 | /* Get IRQs */ | ||
3202 | for (i = 0; i < 4; i++) { | ||
3203 | udc->udp_irq[i] = platform_get_irq(pdev, i); | ||
3204 | if (udc->udp_irq[i] < 0) { | ||
3205 | dev_err(udc->dev, | ||
3206 | "irq resource %d not available!\n", i); | ||
3207 | return udc->udp_irq[i]; | ||
3208 | } | ||
3209 | } | ||
3210 | |||
3211 | udc->io_p_start = res->start; | ||
3212 | udc->io_p_size = resource_size(res); | ||
3213 | if (!request_mem_region(udc->io_p_start, udc->io_p_size, driver_name)) { | ||
3214 | dev_err(udc->dev, "someone's using UDC memory\n"); | ||
3215 | return -EBUSY; | ||
3216 | } | ||
3217 | |||
3218 | udc->udp_baseaddr = ioremap(udc->io_p_start, udc->io_p_size); | ||
3219 | if (!udc->udp_baseaddr) { | ||
3220 | retval = -ENOMEM; | ||
3221 | dev_err(udc->dev, "IO map failure\n"); | ||
3222 | goto io_map_fail; | ||
3223 | } | ||
3224 | |||
3225 | /* Enable AHB slave USB clock, needed for further USB clock control */ | ||
3226 | writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL); | ||
3227 | |||
3228 | /* Get required clocks */ | ||
3229 | udc->usb_pll_clk = clk_get(&pdev->dev, "ck_pll5"); | ||
3230 | if (IS_ERR(udc->usb_pll_clk)) { | ||
3231 | dev_err(udc->dev, "failed to acquire USB PLL\n"); | ||
3232 | retval = PTR_ERR(udc->usb_pll_clk); | ||
3233 | goto pll_get_fail; | ||
3234 | } | ||
3235 | udc->usb_slv_clk = clk_get(&pdev->dev, "ck_usbd"); | ||
3236 | if (IS_ERR(udc->usb_slv_clk)) { | ||
3237 | dev_err(udc->dev, "failed to acquire USB device clock\n"); | ||
3238 | retval = PTR_ERR(udc->usb_slv_clk); | ||
3239 | goto usb_clk_get_fail; | ||
3240 | } | ||
3241 | |||
3242 | /* Setup PLL clock to 48MHz */ | ||
3243 | retval = clk_enable(udc->usb_pll_clk); | ||
3244 | if (retval < 0) { | ||
3245 | dev_err(udc->dev, "failed to start USB PLL\n"); | ||
3246 | goto pll_enable_fail; | ||
3247 | } | ||
3248 | |||
3249 | retval = clk_set_rate(udc->usb_pll_clk, 48000); | ||
3250 | if (retval < 0) { | ||
3251 | dev_err(udc->dev, "failed to set USB clock rate\n"); | ||
3252 | goto pll_set_fail; | ||
3253 | } | ||
3254 | |||
3255 | writel(readl(USB_CTRL) | USB_DEV_NEED_CLK_EN, USB_CTRL); | ||
3256 | |||
3257 | /* Enable USB device clock */ | ||
3258 | retval = clk_enable(udc->usb_slv_clk); | ||
3259 | if (retval < 0) { | ||
3260 | dev_err(udc->dev, "failed to start USB device clock\n"); | ||
3261 | goto usb_clk_enable_fail; | ||
3262 | } | ||
3263 | |||
3264 | /* Set to enable all needed USB OTG clocks */ | ||
3265 | writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL(udc)); | ||
3266 | |||
3267 | i = 1000; | ||
3268 | while (((readl(USB_OTG_CLK_STAT(udc)) & USB_CLOCK_MASK) != | ||
3269 | USB_CLOCK_MASK) && (i > 0)) | ||
3270 | i--; | ||
3271 | if (!i) | ||
3272 | dev_dbg(udc->dev, "USB OTG clocks not correctly enabled\n"); | ||
3273 | |||
3274 | /* Setup deferred workqueue data */ | ||
3275 | udc->poweron = udc->pullup = 0; | ||
3276 | INIT_WORK(&udc->pullup_job, pullup_work); | ||
3277 | INIT_WORK(&udc->vbus_job, vbus_work); | ||
3278 | #ifdef CONFIG_PM | ||
3279 | INIT_WORK(&udc->power_job, power_work); | ||
3280 | #endif | ||
3281 | |||
3282 | /* All clocks are now on */ | ||
3283 | udc->clocked = 1; | ||
3284 | |||
3285 | isp1301_udc_configure(udc); | ||
3286 | /* Allocate memory for the UDCA */ | ||
3287 | udc->udca_v_base = dma_alloc_coherent(&pdev->dev, UDCA_BUFF_SIZE, | ||
3288 | &dma_handle, | ||
3289 | (GFP_KERNEL | GFP_DMA)); | ||
3290 | if (!udc->udca_v_base) { | ||
3291 | dev_err(udc->dev, "error getting UDCA region\n"); | ||
3292 | retval = -ENOMEM; | ||
3293 | goto i2c_fail; | ||
3294 | } | ||
3295 | udc->udca_p_base = dma_handle; | ||
3296 | dev_dbg(udc->dev, "DMA buffer(0x%x bytes), P:0x%08x, V:0x%p\n", | ||
3297 | UDCA_BUFF_SIZE, udc->udca_p_base, udc->udca_v_base); | ||
3298 | |||
3299 | /* Setup the DD DMA memory pool */ | ||
3300 | udc->dd_cache = dma_pool_create("udc_dd", udc->dev, | ||
3301 | sizeof(struct lpc32xx_usbd_dd_gad), | ||
3302 | sizeof(u32), 0); | ||
3303 | if (!udc->dd_cache) { | ||
3304 | dev_err(udc->dev, "error getting DD DMA region\n"); | ||
3305 | retval = -ENOMEM; | ||
3306 | goto dma_alloc_fail; | ||
3307 | } | ||
3308 | |||
3309 | /* Clear USB peripheral and initialize gadget endpoints */ | ||
3310 | udc_disable(udc); | ||
3311 | udc_reinit(udc); | ||
3312 | |||
3313 | retval = device_register(&udc->gadget.dev); | ||
3314 | if (retval < 0) { | ||
3315 | dev_err(udc->dev, "Device registration failure\n"); | ||
3316 | goto dev_register_fail; | ||
3317 | } | ||
3318 | |||
3319 | /* Request IRQs - low and high priority USB device IRQs are routed to | ||
3320 | * the same handler, while the DMA interrupt is routed elsewhere */ | ||
3321 | retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, | ||
3322 | 0, "udc_lp", udc); | ||
3323 | if (retval < 0) { | ||
3324 | dev_err(udc->dev, "LP request irq %d failed\n", | ||
3325 | udc->udp_irq[IRQ_USB_LP]); | ||
3326 | goto irq_lp_fail; | ||
3327 | } | ||
3328 | retval = request_irq(udc->udp_irq[IRQ_USB_HP], lpc32xx_usb_hp_irq, | ||
3329 | 0, "udc_hp", udc); | ||
3330 | if (retval < 0) { | ||
3331 | dev_err(udc->dev, "HP request irq %d failed\n", | ||
3332 | udc->udp_irq[IRQ_USB_HP]); | ||
3333 | goto irq_hp_fail; | ||
3334 | } | ||
3335 | |||
3336 | retval = request_irq(udc->udp_irq[IRQ_USB_DEVDMA], | ||
3337 | lpc32xx_usb_devdma_irq, 0, "udc_dma", udc); | ||
3338 | if (retval < 0) { | ||
3339 | dev_err(udc->dev, "DEV request irq %d failed\n", | ||
3340 | udc->udp_irq[IRQ_USB_DEVDMA]); | ||
3341 | goto irq_dev_fail; | ||
3342 | } | ||
3343 | |||
3344 | /* The transceiver interrupt is used for VBUS detection and will | ||
3345 | kick off the VBUS handler function */ | ||
3346 | retval = request_irq(udc->udp_irq[IRQ_USB_ATX], lpc32xx_usb_vbus_irq, | ||
3347 | 0, "udc_otg", udc); | ||
3348 | if (retval < 0) { | ||
3349 | dev_err(udc->dev, "VBUS request irq %d failed\n", | ||
3350 | udc->udp_irq[IRQ_USB_ATX]); | ||
3351 | goto irq_xcvr_fail; | ||
3352 | } | ||
3353 | |||
3354 | /* Initialize wait queue */ | ||
3355 | init_waitqueue_head(&udc->ep_disable_wait_queue); | ||
3356 | atomic_set(&udc->enabled_ep_cnt, 0); | ||
3357 | |||
3358 | /* Keep all IRQs disabled until GadgetFS starts up */ | ||
3359 | for (i = IRQ_USB_LP; i <= IRQ_USB_ATX; i++) | ||
3360 | disable_irq(udc->udp_irq[i]); | ||
3361 | |||
3362 | retval = usb_add_gadget_udc(dev, &udc->gadget); | ||
3363 | if (retval < 0) | ||
3364 | goto add_gadget_fail; | ||
3365 | |||
3366 | dev_set_drvdata(dev, udc); | ||
3367 | device_init_wakeup(dev, 1); | ||
3368 | create_debug_file(udc); | ||
3369 | |||
3370 | /* Disable clocks for now */ | ||
3371 | udc_clk_set(udc, 0); | ||
3372 | |||
3373 | dev_info(udc->dev, "%s version %s\n", driver_name, DRIVER_VERSION); | ||
3374 | return 0; | ||
3375 | |||
3376 | add_gadget_fail: | ||
3377 | free_irq(udc->udp_irq[IRQ_USB_ATX], udc); | ||
3378 | irq_xcvr_fail: | ||
3379 | free_irq(udc->udp_irq[IRQ_USB_DEVDMA], udc); | ||
3380 | irq_dev_fail: | ||
3381 | free_irq(udc->udp_irq[IRQ_USB_HP], udc); | ||
3382 | irq_hp_fail: | ||
3383 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); | ||
3384 | irq_lp_fail: | ||
3385 | device_unregister(&udc->gadget.dev); | ||
3386 | dev_register_fail: | ||
3387 | dma_pool_destroy(udc->dd_cache); | ||
3388 | dma_alloc_fail: | ||
3389 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, | ||
3390 | udc->udca_v_base, udc->udca_p_base); | ||
3391 | i2c_fail: | ||
3392 | clk_disable(udc->usb_slv_clk); | ||
3393 | usb_clk_enable_fail: | ||
3394 | pll_set_fail: | ||
3395 | clk_disable(udc->usb_pll_clk); | ||
3396 | pll_enable_fail: | ||
3397 | clk_put(udc->usb_slv_clk); | ||
3398 | usb_clk_get_fail: | ||
3399 | clk_put(udc->usb_pll_clk); | ||
3400 | pll_get_fail: | ||
3401 | iounmap(udc->udp_baseaddr); | ||
3402 | io_map_fail: | ||
3403 | release_mem_region(udc->io_p_start, udc->io_p_size); | ||
3404 | dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); | ||
3405 | |||
3406 | return retval; | ||
3407 | } | ||
3408 | |||
3409 | static int __devexit lpc32xx_udc_remove(struct platform_device *pdev) | ||
3410 | { | ||
3411 | struct lpc32xx_udc *udc = platform_get_drvdata(pdev); | ||
3412 | |||
3413 | usb_del_gadget_udc(&udc->gadget); | ||
3414 | if (udc->driver) | ||
3415 | return -EBUSY; | ||
3416 | |||
3417 | udc_clk_set(udc, 1); | ||
3418 | udc_disable(udc); | ||
3419 | pullup(udc, 0); | ||
3420 | |||
3421 | free_irq(udc->udp_irq[IRQ_USB_ATX], udc); | ||
3422 | |||
3423 | device_init_wakeup(&pdev->dev, 0); | ||
3424 | remove_debug_file(udc); | ||
3425 | |||
3426 | dma_pool_destroy(udc->dd_cache); | ||
3427 | dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, | ||
3428 | udc->udca_v_base, udc->udca_p_base); | ||
3429 | free_irq(udc->udp_irq[IRQ_USB_DEVDMA], udc); | ||
3430 | free_irq(udc->udp_irq[IRQ_USB_HP], udc); | ||
3431 | free_irq(udc->udp_irq[IRQ_USB_LP], udc); | ||
3432 | |||
3433 | device_unregister(&udc->gadget.dev); | ||
3434 | |||
3435 | clk_disable(udc->usb_slv_clk); | ||
3436 | clk_put(udc->usb_slv_clk); | ||
3437 | clk_disable(udc->usb_pll_clk); | ||
3438 | clk_put(udc->usb_pll_clk); | ||
3439 | iounmap(udc->udp_baseaddr); | ||
3440 | release_mem_region(udc->io_p_start, udc->io_p_size); | ||
3441 | |||
3442 | return 0; | ||
3443 | } | ||
3444 | |||
3445 | #ifdef CONFIG_PM | ||
3446 | static int lpc32xx_udc_suspend(struct platform_device *pdev, pm_message_t mesg) | ||
3447 | { | ||
3448 | int to = 1000; | ||
3449 | struct lpc32xx_udc *udc = platform_get_drvdata(pdev); | ||
3450 | |||
3451 | if (udc->clocked) { | ||
3452 | /* Power down ISP */ | ||
3453 | udc->poweron = 0; | ||
3454 | isp1301_set_powerstate(udc, 0); | ||
3455 | |||
3456 | /* Disable clocking */ | ||
3457 | udc_clk_set(udc, 0); | ||
3458 | |||
3459 | /* Keep clock flag on, so we know to re-enable clocks | ||
3460 | on resume */ | ||
3461 | udc->clocked = 1; | ||
3462 | |||
3463 | /* Kill OTG and I2C clocks */ | ||
3464 | writel(0, USB_OTG_CLK_CTRL(udc)); | ||
3465 | while (((readl(USB_OTG_CLK_STAT(udc)) & OTGOFF_CLK_MASK) != | ||
3466 | OTGOFF_CLK_MASK) && (to > 0)) | ||
3467 | to--; | ||
3468 | if (!to) | ||
3469 | dev_dbg(udc->dev, | ||
3470 | "USB OTG clocks not correctly enabled\n"); | ||
3471 | |||
3472 | /* Kill global USB clock */ | ||
3473 | clk_disable(udc->usb_slv_clk); | ||
3474 | } | ||
3475 | |||
3476 | return 0; | ||
3477 | } | ||
3478 | |||
3479 | static int lpc32xx_udc_resume(struct platform_device *pdev) | ||
3480 | { | ||
3481 | struct lpc32xx_udc *udc = platform_get_drvdata(pdev); | ||
3482 | |||
3483 | if (udc->clocked) { | ||
3484 | /* Enable global USB clock */ | ||
3485 | clk_enable(udc->usb_slv_clk); | ||
3486 | |||
3487 | /* Enable clocking */ | ||
3488 | udc_clk_set(udc, 1); | ||
3489 | |||
3490 | /* ISP back to normal power mode */ | ||
3491 | udc->poweron = 1; | ||
3492 | isp1301_set_powerstate(udc, 1); | ||
3493 | } | ||
3494 | |||
3495 | return 0; | ||
3496 | } | ||
3497 | #else | ||
3498 | #define lpc32xx_udc_suspend NULL | ||
3499 | #define lpc32xx_udc_resume NULL | ||
3500 | #endif | ||
3501 | |||
3502 | #ifdef CONFIG_OF | ||
3503 | static struct of_device_id lpc32xx_udc_of_match[] = { | ||
3504 | { .compatible = "nxp,lpc3220-udc", }, | ||
3505 | { }, | ||
3506 | }; | ||
3507 | MODULE_DEVICE_TABLE(of, lpc32xx_udc_of_match); | ||
3508 | #endif | ||
3509 | |||
3510 | static struct platform_driver lpc32xx_udc_driver = { | ||
3511 | .remove = __devexit_p(lpc32xx_udc_remove), | ||
3512 | .shutdown = lpc32xx_udc_shutdown, | ||
3513 | .suspend = lpc32xx_udc_suspend, | ||
3514 | .resume = lpc32xx_udc_resume, | ||
3515 | .driver = { | ||
3516 | .name = (char *) driver_name, | ||
3517 | .owner = THIS_MODULE, | ||
3518 | .of_match_table = of_match_ptr(lpc32xx_udc_of_match), | ||
3519 | }, | ||
3520 | }; | ||
3521 | |||
3522 | static int __init udc_init_module(void) | ||
3523 | { | ||
3524 | return platform_driver_probe(&lpc32xx_udc_driver, lpc32xx_udc_probe); | ||
3525 | } | ||
3526 | module_init(udc_init_module); | ||
3527 | |||
3528 | static void __exit udc_exit_module(void) | ||
3529 | { | ||
3530 | platform_driver_unregister(&lpc32xx_udc_driver); | ||
3531 | } | ||
3532 | module_exit(udc_exit_module); | ||
3533 | |||
3534 | MODULE_DESCRIPTION("LPC32XX udc driver"); | ||
3535 | MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>"); | ||
3536 | MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); | ||
3537 | MODULE_LICENSE("GPL"); | ||
3538 | MODULE_ALIAS("platform:lpc32xx_udc"); | ||
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 3608b3bd5732..8981fbb5748c 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -390,7 +390,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, | |||
390 | int *counter; | 390 | int *counter; |
391 | int ret; | 391 | int ret; |
392 | 392 | ||
393 | ep->desc = desc; | 393 | ep->ep.desc = desc; |
394 | 394 | ||
395 | BUG_ON(ep->pipenum); | 395 | BUG_ON(ep->pipenum); |
396 | 396 | ||
@@ -558,7 +558,7 @@ static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req) | |||
558 | 558 | ||
559 | static void start_packet(struct m66592_ep *ep, struct m66592_request *req) | 559 | static void start_packet(struct m66592_ep *ep, struct m66592_request *req) |
560 | { | 560 | { |
561 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | 561 | if (ep->ep.desc->bEndpointAddress & USB_DIR_IN) |
562 | start_packet_write(ep, req); | 562 | start_packet_write(ep, req); |
563 | else | 563 | else |
564 | start_packet_read(ep, req); | 564 | start_packet_read(ep, req); |
@@ -734,7 +734,7 @@ __acquires(m66592->lock) | |||
734 | 734 | ||
735 | if (restart) { | 735 | if (restart) { |
736 | req = list_entry(ep->queue.next, struct m66592_request, queue); | 736 | req = list_entry(ep->queue.next, struct m66592_request, queue); |
737 | if (ep->desc) | 737 | if (ep->ep.desc) |
738 | start_packet(ep, req); | 738 | start_packet(ep, req); |
739 | } | 739 | } |
740 | } | 740 | } |
@@ -917,7 +917,7 @@ static void irq_pipe_ready(struct m66592 *m66592, u16 status, u16 enb) | |||
917 | ep = m66592->pipenum2ep[pipenum]; | 917 | ep = m66592->pipenum2ep[pipenum]; |
918 | req = list_entry(ep->queue.next, | 918 | req = list_entry(ep->queue.next, |
919 | struct m66592_request, queue); | 919 | struct m66592_request, queue); |
920 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | 920 | if (ep->ep.desc->bEndpointAddress & USB_DIR_IN) |
921 | irq_packet_write(ep, req); | 921 | irq_packet_write(ep, req); |
922 | else | 922 | else |
923 | irq_packet_read(ep, req); | 923 | irq_packet_read(ep, req); |
@@ -1377,7 +1377,7 @@ static int m66592_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
1377 | req->req.actual = 0; | 1377 | req->req.actual = 0; |
1378 | req->req.status = -EINPROGRESS; | 1378 | req->req.status = -EINPROGRESS; |
1379 | 1379 | ||
1380 | if (ep->desc == NULL) /* control */ | 1380 | if (ep->ep.desc == NULL) /* control */ |
1381 | start_ep0(ep, req); | 1381 | start_ep0(ep, req); |
1382 | else { | 1382 | else { |
1383 | if (request && !ep->busy) | 1383 | if (request && !ep->busy) |
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index 9d9f7e39f037..88c85b4116a2 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -456,7 +456,7 @@ struct m66592_ep { | |||
456 | unsigned use_dma:1; | 456 | unsigned use_dma:1; |
457 | u16 pipenum; | 457 | u16 pipenum; |
458 | u16 type; | 458 | u16 type; |
459 | const struct usb_endpoint_descriptor *desc; | 459 | |
460 | /* register address */ | 460 | /* register address */ |
461 | unsigned long fifoaddr; | 461 | unsigned long fifoaddr; |
462 | unsigned long fifosel; | 462 | unsigned long fifosel; |
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h index e2be9519abbe..9073436d8b24 100644 --- a/drivers/usb/gadget/mv_udc.h +++ b/drivers/usb/gadget/mv_udc.h | |||
@@ -232,7 +232,6 @@ struct mv_ep { | |||
232 | struct mv_udc *udc; | 232 | struct mv_udc *udc; |
233 | struct list_head queue; | 233 | struct list_head queue; |
234 | struct mv_dqh *dqh; | 234 | struct mv_dqh *dqh; |
235 | const struct usb_endpoint_descriptor *desc; | ||
236 | u32 direction; | 235 | u32 direction; |
237 | char name[14]; | 236 | char name[14]; |
238 | unsigned stopped:1, | 237 | unsigned stopped:1, |
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c index a73cf406e2a4..dbcd1329495e 100644 --- a/drivers/usb/gadget/mv_udc_core.c +++ b/drivers/usb/gadget/mv_udc_core.c | |||
@@ -464,7 +464,7 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
464 | ep = container_of(_ep, struct mv_ep, ep); | 464 | ep = container_of(_ep, struct mv_ep, ep); |
465 | udc = ep->udc; | 465 | udc = ep->udc; |
466 | 466 | ||
467 | if (!_ep || !desc || ep->desc | 467 | if (!_ep || !desc || ep->ep.desc |
468 | || desc->bDescriptorType != USB_DT_ENDPOINT) | 468 | || desc->bDescriptorType != USB_DT_ENDPOINT) |
469 | return -EINVAL; | 469 | return -EINVAL; |
470 | 470 | ||
@@ -528,7 +528,7 @@ static int mv_ep_enable(struct usb_ep *_ep, | |||
528 | dqh->size_ioc_int_sts = 0; | 528 | dqh->size_ioc_int_sts = 0; |
529 | 529 | ||
530 | ep->ep.maxpacket = max; | 530 | ep->ep.maxpacket = max; |
531 | ep->desc = desc; | 531 | ep->ep.desc = desc; |
532 | ep->stopped = 0; | 532 | ep->stopped = 0; |
533 | 533 | ||
534 | /* Enable the endpoint for Rx or Tx and set the endpoint type */ | 534 | /* Enable the endpoint for Rx or Tx and set the endpoint type */ |
@@ -580,7 +580,7 @@ static int mv_ep_disable(struct usb_ep *_ep) | |||
580 | unsigned long flags; | 580 | unsigned long flags; |
581 | 581 | ||
582 | ep = container_of(_ep, struct mv_ep, ep); | 582 | ep = container_of(_ep, struct mv_ep, ep); |
583 | if ((_ep == NULL) || !ep->desc) | 583 | if ((_ep == NULL) || !ep->ep.desc) |
584 | return -EINVAL; | 584 | return -EINVAL; |
585 | 585 | ||
586 | udc = ep->udc; | 586 | udc = ep->udc; |
@@ -606,7 +606,6 @@ static int mv_ep_disable(struct usb_ep *_ep) | |||
606 | /* nuke all pending requests (does flush) */ | 606 | /* nuke all pending requests (does flush) */ |
607 | nuke(ep, -ESHUTDOWN); | 607 | nuke(ep, -ESHUTDOWN); |
608 | 608 | ||
609 | ep->desc = NULL; | ||
610 | ep->ep.desc = NULL; | 609 | ep->ep.desc = NULL; |
611 | ep->stopped = 1; | 610 | ep->stopped = 1; |
612 | 611 | ||
@@ -651,7 +650,7 @@ static void mv_ep_fifo_flush(struct usb_ep *_ep) | |||
651 | return; | 650 | return; |
652 | 651 | ||
653 | ep = container_of(_ep, struct mv_ep, ep); | 652 | ep = container_of(_ep, struct mv_ep, ep); |
654 | if (!ep->desc) | 653 | if (!ep->ep.desc) |
655 | return; | 654 | return; |
656 | 655 | ||
657 | udc = ep->udc; | 656 | udc = ep->udc; |
@@ -715,11 +714,11 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
715 | dev_err(&udc->dev->dev, "%s, bad params", __func__); | 714 | dev_err(&udc->dev->dev, "%s, bad params", __func__); |
716 | return -EINVAL; | 715 | return -EINVAL; |
717 | } | 716 | } |
718 | if (unlikely(!_ep || !ep->desc)) { | 717 | if (unlikely(!_ep || !ep->ep.desc)) { |
719 | dev_err(&udc->dev->dev, "%s, bad ep", __func__); | 718 | dev_err(&udc->dev->dev, "%s, bad ep", __func__); |
720 | return -EINVAL; | 719 | return -EINVAL; |
721 | } | 720 | } |
722 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 721 | if (ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
723 | if (req->req.length > ep->ep.maxpacket) | 722 | if (req->req.length > ep->ep.maxpacket) |
724 | return -EMSGSIZE; | 723 | return -EMSGSIZE; |
725 | } | 724 | } |
@@ -925,12 +924,12 @@ static int mv_ep_set_halt_wedge(struct usb_ep *_ep, int halt, int wedge) | |||
925 | 924 | ||
926 | ep = container_of(_ep, struct mv_ep, ep); | 925 | ep = container_of(_ep, struct mv_ep, ep); |
927 | udc = ep->udc; | 926 | udc = ep->udc; |
928 | if (!_ep || !ep->desc) { | 927 | if (!_ep || !ep->ep.desc) { |
929 | status = -EINVAL; | 928 | status = -EINVAL; |
930 | goto out; | 929 | goto out; |
931 | } | 930 | } |
932 | 931 | ||
933 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 932 | if (ep->ep.desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
934 | status = -EOPNOTSUPP; | 933 | status = -EOPNOTSUPP; |
935 | goto out; | 934 | goto out; |
936 | } | 935 | } |
@@ -1279,7 +1278,7 @@ static int eps_init(struct mv_udc *udc) | |||
1279 | ep->stopped = 0; | 1278 | ep->stopped = 0; |
1280 | ep->ep.maxpacket = EP0_MAX_PKT_SIZE; | 1279 | ep->ep.maxpacket = EP0_MAX_PKT_SIZE; |
1281 | ep->ep_num = 0; | 1280 | ep->ep_num = 0; |
1282 | ep->desc = &mv_ep0_desc; | 1281 | ep->ep.desc = &mv_ep0_desc; |
1283 | INIT_LIST_HEAD(&ep->queue); | 1282 | INIT_LIST_HEAD(&ep->queue); |
1284 | 1283 | ||
1285 | ep->ep_type = USB_ENDPOINT_XFER_CONTROL; | 1284 | ep->ep_type = USB_ENDPOINT_XFER_CONTROL; |
diff --git a/drivers/usb/gadget/ndis.h b/drivers/usb/gadget/ndis.h index b0e52fc277b4..a19f72dec0cd 100644 --- a/drivers/usb/gadget/ndis.h +++ b/drivers/usb/gadget/ndis.h | |||
@@ -15,11 +15,6 @@ | |||
15 | #ifndef _LINUX_NDIS_H | 15 | #ifndef _LINUX_NDIS_H |
16 | #define _LINUX_NDIS_H | 16 | #define _LINUX_NDIS_H |
17 | 17 | ||
18 | |||
19 | #define NDIS_STATUS_MULTICAST_FULL 0xC0010009 | ||
20 | #define NDIS_STATUS_MULTICAST_EXISTS 0xC001000A | ||
21 | #define NDIS_STATUS_MULTICAST_NOT_FOUND 0xC001000B | ||
22 | |||
23 | enum NDIS_DEVICE_POWER_STATE { | 18 | enum NDIS_DEVICE_POWER_STATE { |
24 | NdisDeviceStateUnspecified = 0, | 19 | NdisDeviceStateUnspecified = 0, |
25 | NdisDeviceStateD0, | 20 | NdisDeviceStateD0, |
@@ -35,11 +30,6 @@ struct NDIS_PM_WAKE_UP_CAPABILITIES { | |||
35 | enum NDIS_DEVICE_POWER_STATE MinLinkChangeWakeUp; | 30 | enum NDIS_DEVICE_POWER_STATE MinLinkChangeWakeUp; |
36 | }; | 31 | }; |
37 | 32 | ||
38 | /* NDIS_PNP_CAPABILITIES.Flags constants */ | ||
39 | #define NDIS_DEVICE_WAKE_UP_ENABLE 0x00000001 | ||
40 | #define NDIS_DEVICE_WAKE_ON_PATTERN_MATCH_ENABLE 0x00000002 | ||
41 | #define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 | ||
42 | |||
43 | struct NDIS_PNP_CAPABILITIES { | 33 | struct NDIS_PNP_CAPABILITIES { |
44 | __le32 Flags; | 34 | __le32 Flags; |
45 | struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; | 35 | struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; |
@@ -54,158 +44,4 @@ struct NDIS_PM_PACKET_PATTERN { | |||
54 | __le32 PatternFlags; | 44 | __le32 PatternFlags; |
55 | }; | 45 | }; |
56 | 46 | ||
57 | |||
58 | /* Required Object IDs (OIDs) */ | ||
59 | #define OID_GEN_SUPPORTED_LIST 0x00010101 | ||
60 | #define OID_GEN_HARDWARE_STATUS 0x00010102 | ||
61 | #define OID_GEN_MEDIA_SUPPORTED 0x00010103 | ||
62 | #define OID_GEN_MEDIA_IN_USE 0x00010104 | ||
63 | #define OID_GEN_MAXIMUM_LOOKAHEAD 0x00010105 | ||
64 | #define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106 | ||
65 | #define OID_GEN_LINK_SPEED 0x00010107 | ||
66 | #define OID_GEN_TRANSMIT_BUFFER_SPACE 0x00010108 | ||
67 | #define OID_GEN_RECEIVE_BUFFER_SPACE 0x00010109 | ||
68 | #define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010A | ||
69 | #define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010B | ||
70 | #define OID_GEN_VENDOR_ID 0x0001010C | ||
71 | #define OID_GEN_VENDOR_DESCRIPTION 0x0001010D | ||
72 | #define OID_GEN_CURRENT_PACKET_FILTER 0x0001010E | ||
73 | #define OID_GEN_CURRENT_LOOKAHEAD 0x0001010F | ||
74 | #define OID_GEN_DRIVER_VERSION 0x00010110 | ||
75 | #define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111 | ||
76 | #define OID_GEN_PROTOCOL_OPTIONS 0x00010112 | ||
77 | #define OID_GEN_MAC_OPTIONS 0x00010113 | ||
78 | #define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114 | ||
79 | #define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115 | ||
80 | #define OID_GEN_VENDOR_DRIVER_VERSION 0x00010116 | ||
81 | #define OID_GEN_SUPPORTED_GUIDS 0x00010117 | ||
82 | #define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118 | ||
83 | #define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119 | ||
84 | #define OID_GEN_MACHINE_NAME 0x0001021A | ||
85 | #define OID_GEN_RNDIS_CONFIG_PARAMETER 0x0001021B | ||
86 | #define OID_GEN_VLAN_ID 0x0001021C | ||
87 | |||
88 | /* Optional OIDs */ | ||
89 | #define OID_GEN_MEDIA_CAPABILITIES 0x00010201 | ||
90 | #define OID_GEN_PHYSICAL_MEDIUM 0x00010202 | ||
91 | |||
92 | /* Required statistics OIDs */ | ||
93 | #define OID_GEN_XMIT_OK 0x00020101 | ||
94 | #define OID_GEN_RCV_OK 0x00020102 | ||
95 | #define OID_GEN_XMIT_ERROR 0x00020103 | ||
96 | #define OID_GEN_RCV_ERROR 0x00020104 | ||
97 | #define OID_GEN_RCV_NO_BUFFER 0x00020105 | ||
98 | |||
99 | /* Optional statistics OIDs */ | ||
100 | #define OID_GEN_DIRECTED_BYTES_XMIT 0x00020201 | ||
101 | #define OID_GEN_DIRECTED_FRAMES_XMIT 0x00020202 | ||
102 | #define OID_GEN_MULTICAST_BYTES_XMIT 0x00020203 | ||
103 | #define OID_GEN_MULTICAST_FRAMES_XMIT 0x00020204 | ||
104 | #define OID_GEN_BROADCAST_BYTES_XMIT 0x00020205 | ||
105 | #define OID_GEN_BROADCAST_FRAMES_XMIT 0x00020206 | ||
106 | #define OID_GEN_DIRECTED_BYTES_RCV 0x00020207 | ||
107 | #define OID_GEN_DIRECTED_FRAMES_RCV 0x00020208 | ||
108 | #define OID_GEN_MULTICAST_BYTES_RCV 0x00020209 | ||
109 | #define OID_GEN_MULTICAST_FRAMES_RCV 0x0002020A | ||
110 | #define OID_GEN_BROADCAST_BYTES_RCV 0x0002020B | ||
111 | #define OID_GEN_BROADCAST_FRAMES_RCV 0x0002020C | ||
112 | #define OID_GEN_RCV_CRC_ERROR 0x0002020D | ||
113 | #define OID_GEN_TRANSMIT_QUEUE_LENGTH 0x0002020E | ||
114 | #define OID_GEN_GET_TIME_CAPS 0x0002020F | ||
115 | #define OID_GEN_GET_NETCARD_TIME 0x00020210 | ||
116 | #define OID_GEN_NETCARD_LOAD 0x00020211 | ||
117 | #define OID_GEN_DEVICE_PROFILE 0x00020212 | ||
118 | #define OID_GEN_INIT_TIME_MS 0x00020213 | ||
119 | #define OID_GEN_RESET_COUNTS 0x00020214 | ||
120 | #define OID_GEN_MEDIA_SENSE_COUNTS 0x00020215 | ||
121 | #define OID_GEN_FRIENDLY_NAME 0x00020216 | ||
122 | #define OID_GEN_MINIPORT_INFO 0x00020217 | ||
123 | #define OID_GEN_RESET_VERIFY_PARAMETERS 0x00020218 | ||
124 | |||
125 | /* IEEE 802.3 (Ethernet) OIDs */ | ||
126 | #define NDIS_802_3_MAC_OPTION_PRIORITY 0x00000001 | ||
127 | |||
128 | #define OID_802_3_PERMANENT_ADDRESS 0x01010101 | ||
129 | #define OID_802_3_CURRENT_ADDRESS 0x01010102 | ||
130 | #define OID_802_3_MULTICAST_LIST 0x01010103 | ||
131 | #define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104 | ||
132 | #define OID_802_3_MAC_OPTIONS 0x01010105 | ||
133 | #define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101 | ||
134 | #define OID_802_3_XMIT_ONE_COLLISION 0x01020102 | ||
135 | #define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103 | ||
136 | #define OID_802_3_XMIT_DEFERRED 0x01020201 | ||
137 | #define OID_802_3_XMIT_MAX_COLLISIONS 0x01020202 | ||
138 | #define OID_802_3_RCV_OVERRUN 0x01020203 | ||
139 | #define OID_802_3_XMIT_UNDERRUN 0x01020204 | ||
140 | #define OID_802_3_XMIT_HEARTBEAT_FAILURE 0x01020205 | ||
141 | #define OID_802_3_XMIT_TIMES_CRS_LOST 0x01020206 | ||
142 | #define OID_802_3_XMIT_LATE_COLLISIONS 0x01020207 | ||
143 | |||
144 | /* OID_GEN_MINIPORT_INFO constants */ | ||
145 | #define NDIS_MINIPORT_BUS_MASTER 0x00000001 | ||
146 | #define NDIS_MINIPORT_WDM_DRIVER 0x00000002 | ||
147 | #define NDIS_MINIPORT_SG_LIST 0x00000004 | ||
148 | #define NDIS_MINIPORT_SUPPORTS_MEDIA_QUERY 0x00000008 | ||
149 | #define NDIS_MINIPORT_INDICATES_PACKETS 0x00000010 | ||
150 | #define NDIS_MINIPORT_IGNORE_PACKET_QUEUE 0x00000020 | ||
151 | #define NDIS_MINIPORT_IGNORE_REQUEST_QUEUE 0x00000040 | ||
152 | #define NDIS_MINIPORT_IGNORE_TOKEN_RING_ERRORS 0x00000080 | ||
153 | #define NDIS_MINIPORT_INTERMEDIATE_DRIVER 0x00000100 | ||
154 | #define NDIS_MINIPORT_IS_NDIS_5 0x00000200 | ||
155 | #define NDIS_MINIPORT_IS_CO 0x00000400 | ||
156 | #define NDIS_MINIPORT_DESERIALIZE 0x00000800 | ||
157 | #define NDIS_MINIPORT_REQUIRES_MEDIA_POLLING 0x00001000 | ||
158 | #define NDIS_MINIPORT_SUPPORTS_MEDIA_SENSE 0x00002000 | ||
159 | #define NDIS_MINIPORT_NETBOOT_CARD 0x00004000 | ||
160 | #define NDIS_MINIPORT_PM_SUPPORTED 0x00008000 | ||
161 | #define NDIS_MINIPORT_SUPPORTS_MAC_ADDRESS_OVERWRITE 0x00010000 | ||
162 | #define NDIS_MINIPORT_USES_SAFE_BUFFER_APIS 0x00020000 | ||
163 | #define NDIS_MINIPORT_HIDDEN 0x00040000 | ||
164 | #define NDIS_MINIPORT_SWENUM 0x00080000 | ||
165 | #define NDIS_MINIPORT_SURPRISE_REMOVE_OK 0x00100000 | ||
166 | #define NDIS_MINIPORT_NO_HALT_ON_SUSPEND 0x00200000 | ||
167 | #define NDIS_MINIPORT_HARDWARE_DEVICE 0x00400000 | ||
168 | #define NDIS_MINIPORT_SUPPORTS_CANCEL_SEND_PACKETS 0x00800000 | ||
169 | #define NDIS_MINIPORT_64BITS_DMA 0x01000000 | ||
170 | |||
171 | #define NDIS_MEDIUM_802_3 0x00000000 | ||
172 | #define NDIS_MEDIUM_802_5 0x00000001 | ||
173 | #define NDIS_MEDIUM_FDDI 0x00000002 | ||
174 | #define NDIS_MEDIUM_WAN 0x00000003 | ||
175 | #define NDIS_MEDIUM_LOCAL_TALK 0x00000004 | ||
176 | #define NDIS_MEDIUM_DIX 0x00000005 | ||
177 | #define NDIS_MEDIUM_ARCENT_RAW 0x00000006 | ||
178 | #define NDIS_MEDIUM_ARCENT_878_2 0x00000007 | ||
179 | #define NDIS_MEDIUM_ATM 0x00000008 | ||
180 | #define NDIS_MEDIUM_WIRELESS_LAN 0x00000009 | ||
181 | #define NDIS_MEDIUM_IRDA 0x0000000A | ||
182 | #define NDIS_MEDIUM_BPC 0x0000000B | ||
183 | #define NDIS_MEDIUM_CO_WAN 0x0000000C | ||
184 | #define NDIS_MEDIUM_1394 0x0000000D | ||
185 | |||
186 | #define NDIS_PACKET_TYPE_DIRECTED 0x00000001 | ||
187 | #define NDIS_PACKET_TYPE_MULTICAST 0x00000002 | ||
188 | #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 | ||
189 | #define NDIS_PACKET_TYPE_BROADCAST 0x00000008 | ||
190 | #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010 | ||
191 | #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020 | ||
192 | #define NDIS_PACKET_TYPE_SMT 0x00000040 | ||
193 | #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080 | ||
194 | #define NDIS_PACKET_TYPE_GROUP 0x00000100 | ||
195 | #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200 | ||
196 | #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400 | ||
197 | #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800 | ||
198 | |||
199 | #define NDIS_MEDIA_STATE_CONNECTED 0x00000000 | ||
200 | #define NDIS_MEDIA_STATE_DISCONNECTED 0x00000001 | ||
201 | |||
202 | #define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA 0x00000001 | ||
203 | #define NDIS_MAC_OPTION_RECEIVE_SERIALIZED 0x00000002 | ||
204 | #define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND 0x00000004 | ||
205 | #define NDIS_MAC_OPTION_NO_LOOPBACK 0x00000008 | ||
206 | #define NDIS_MAC_OPTION_FULL_DUPLEX 0x00000010 | ||
207 | #define NDIS_MAC_OPTION_EOTX_INDICATION 0x00000020 | ||
208 | #define NDIS_MAC_OPTION_8021P_PRIORITY 0x00000040 | ||
209 | #define NDIS_MAC_OPTION_RESERVED 0x80000000 | ||
210 | |||
211 | #endif /* _LINUX_NDIS_H */ | 47 | #endif /* _LINUX_NDIS_H */ |
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c index 3b4b6dd0f95a..7ba32469c5bd 100644 --- a/drivers/usb/gadget/omap_udc.c +++ b/drivers/usb/gadget/omap_udc.c | |||
@@ -153,7 +153,7 @@ static int omap_ep_enable(struct usb_ep *_ep, | |||
153 | u16 maxp; | 153 | u16 maxp; |
154 | 154 | ||
155 | /* catch various bogus parameters */ | 155 | /* catch various bogus parameters */ |
156 | if (!_ep || !desc || ep->desc | 156 | if (!_ep || !desc || ep->ep.desc |
157 | || desc->bDescriptorType != USB_DT_ENDPOINT | 157 | || desc->bDescriptorType != USB_DT_ENDPOINT |
158 | || ep->bEndpointAddress != desc->bEndpointAddress | 158 | || ep->bEndpointAddress != desc->bEndpointAddress |
159 | || ep->maxpacket < usb_endpoint_maxp(desc)) { | 159 | || ep->maxpacket < usb_endpoint_maxp(desc)) { |
@@ -200,7 +200,7 @@ static int omap_ep_enable(struct usb_ep *_ep, | |||
200 | 200 | ||
201 | spin_lock_irqsave(&udc->lock, flags); | 201 | spin_lock_irqsave(&udc->lock, flags); |
202 | 202 | ||
203 | ep->desc = desc; | 203 | ep->ep.desc = desc; |
204 | ep->irqs = 0; | 204 | ep->irqs = 0; |
205 | ep->stopped = 0; | 205 | ep->stopped = 0; |
206 | ep->ep.maxpacket = maxp; | 206 | ep->ep.maxpacket = maxp; |
@@ -242,14 +242,13 @@ static int omap_ep_disable(struct usb_ep *_ep) | |||
242 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); | 242 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
243 | unsigned long flags; | 243 | unsigned long flags; |
244 | 244 | ||
245 | if (!_ep || !ep->desc) { | 245 | if (!_ep || !ep->ep.desc) { |
246 | DBG("%s, %s not enabled\n", __func__, | 246 | DBG("%s, %s not enabled\n", __func__, |
247 | _ep ? ep->ep.name : NULL); | 247 | _ep ? ep->ep.name : NULL); |
248 | return -EINVAL; | 248 | return -EINVAL; |
249 | } | 249 | } |
250 | 250 | ||
251 | spin_lock_irqsave(&ep->udc->lock, flags); | 251 | spin_lock_irqsave(&ep->udc->lock, flags); |
252 | ep->desc = NULL; | ||
253 | ep->ep.desc = NULL; | 252 | ep->ep.desc = NULL; |
254 | nuke (ep, -ESHUTDOWN); | 253 | nuke (ep, -ESHUTDOWN); |
255 | ep->ep.maxpacket = ep->maxpacket; | 254 | ep->ep.maxpacket = ep->maxpacket; |
@@ -917,7 +916,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
917 | DBG("%s, bad params\n", __func__); | 916 | DBG("%s, bad params\n", __func__); |
918 | return -EINVAL; | 917 | return -EINVAL; |
919 | } | 918 | } |
920 | if (!_ep || (!ep->desc && ep->bEndpointAddress)) { | 919 | if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) { |
921 | DBG("%s, bad ep\n", __func__); | 920 | DBG("%s, bad ep\n", __func__); |
922 | return -EINVAL; | 921 | return -EINVAL; |
923 | } | 922 | } |
@@ -1121,7 +1120,7 @@ static int omap_ep_set_halt(struct usb_ep *_ep, int value) | |||
1121 | status = 0; | 1120 | status = 0; |
1122 | 1121 | ||
1123 | /* otherwise, all active non-ISO endpoints can halt */ | 1122 | /* otherwise, all active non-ISO endpoints can halt */ |
1124 | } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->desc) { | 1123 | } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) { |
1125 | 1124 | ||
1126 | /* IN endpoints must already be idle */ | 1125 | /* IN endpoints must already be idle */ |
1127 | if ((ep->bEndpointAddress & USB_DIR_IN) | 1126 | if ((ep->bEndpointAddress & USB_DIR_IN) |
@@ -1625,7 +1624,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src) | |||
1625 | if (w_index & USB_DIR_IN) | 1624 | if (w_index & USB_DIR_IN) |
1626 | ep += 16; | 1625 | ep += 16; |
1627 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 1626 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
1628 | || !ep->desc) | 1627 | || !ep->ep.desc) |
1629 | goto do_stall; | 1628 | goto do_stall; |
1630 | use_ep(ep, 0); | 1629 | use_ep(ep, 0); |
1631 | omap_writew(udc->clr_halt, UDC_CTRL); | 1630 | omap_writew(udc->clr_halt, UDC_CTRL); |
@@ -1653,7 +1652,7 @@ static void ep0_irq(struct omap_udc *udc, u16 irq_src) | |||
1653 | if (w_index & USB_DIR_IN) | 1652 | if (w_index & USB_DIR_IN) |
1654 | ep += 16; | 1653 | ep += 16; |
1655 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 1654 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
1656 | || ep == ep0 || !ep->desc) | 1655 | || ep == ep0 || !ep->ep.desc) |
1657 | goto do_stall; | 1656 | goto do_stall; |
1658 | if (use_dma && ep->has_dma) { | 1657 | if (use_dma && ep->has_dma) { |
1659 | /* this has rude side-effects (aborts) and | 1658 | /* this has rude side-effects (aborts) and |
@@ -1688,7 +1687,7 @@ ep0out_status_stage: | |||
1688 | ep = &udc->ep[w_index & 0xf]; | 1687 | ep = &udc->ep[w_index & 0xf]; |
1689 | if (w_index & USB_DIR_IN) | 1688 | if (w_index & USB_DIR_IN) |
1690 | ep += 16; | 1689 | ep += 16; |
1691 | if (!ep->desc) | 1690 | if (!ep->ep.desc) |
1692 | goto do_stall; | 1691 | goto do_stall; |
1693 | 1692 | ||
1694 | /* iso never stalls */ | 1693 | /* iso never stalls */ |
@@ -2509,7 +2508,7 @@ static int proc_udc_show(struct seq_file *s, void *_) | |||
2509 | if (tmp & UDC_ADD) { | 2508 | if (tmp & UDC_ADD) { |
2510 | list_for_each_entry (ep, &udc->gadget.ep_list, | 2509 | list_for_each_entry (ep, &udc->gadget.ep_list, |
2511 | ep.ep_list) { | 2510 | ep.ep_list) { |
2512 | if (ep->desc) | 2511 | if (ep->ep.desc) |
2513 | proc_ep_show(s, ep); | 2512 | proc_ep_show(s, ep); |
2514 | } | 2513 | } |
2515 | } | 2514 | } |
diff --git a/drivers/usb/gadget/omap_udc.h b/drivers/usb/gadget/omap_udc.h index 59d3b2213cb1..cfadeb5fc5de 100644 --- a/drivers/usb/gadget/omap_udc.h +++ b/drivers/usb/gadget/omap_udc.h | |||
@@ -140,7 +140,6 @@ struct omap_ep { | |||
140 | struct list_head queue; | 140 | struct list_head queue; |
141 | unsigned long irqs; | 141 | unsigned long irqs; |
142 | struct list_head iso; | 142 | struct list_head iso; |
143 | const struct usb_endpoint_descriptor *desc; | ||
144 | char name[14]; | 143 | char name[14]; |
145 | u16 maxpacket; | 144 | u16 maxpacket; |
146 | u8 bEndpointAddress; | 145 | u8 bEndpointAddress; |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index 65307064a6fd..1cfcc9ecbfbc 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -295,7 +295,6 @@ struct pch_udc_ep { | |||
295 | struct pch_udc_data_dma_desc *td_data; | 295 | struct pch_udc_data_dma_desc *td_data; |
296 | struct pch_udc_dev *dev; | 296 | struct pch_udc_dev *dev; |
297 | unsigned long offset_addr; | 297 | unsigned long offset_addr; |
298 | const struct usb_endpoint_descriptor *desc; | ||
299 | struct list_head queue; | 298 | struct list_head queue; |
300 | unsigned num:5, | 299 | unsigned num:5, |
301 | in:1, | 300 | in:1, |
@@ -1705,7 +1704,7 @@ static int pch_udc_pcd_ep_enable(struct usb_ep *usbep, | |||
1705 | if (!dev->driver || (dev->gadget.speed == USB_SPEED_UNKNOWN)) | 1704 | if (!dev->driver || (dev->gadget.speed == USB_SPEED_UNKNOWN)) |
1706 | return -ESHUTDOWN; | 1705 | return -ESHUTDOWN; |
1707 | spin_lock_irqsave(&dev->lock, iflags); | 1706 | spin_lock_irqsave(&dev->lock, iflags); |
1708 | ep->desc = desc; | 1707 | ep->ep.desc = desc; |
1709 | ep->halted = 0; | 1708 | ep->halted = 0; |
1710 | pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc); | 1709 | pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc); |
1711 | ep->ep.maxpacket = usb_endpoint_maxp(desc); | 1710 | ep->ep.maxpacket = usb_endpoint_maxp(desc); |
@@ -1734,7 +1733,7 @@ static int pch_udc_pcd_ep_disable(struct usb_ep *usbep) | |||
1734 | 1733 | ||
1735 | ep = container_of(usbep, struct pch_udc_ep, ep); | 1734 | ep = container_of(usbep, struct pch_udc_ep, ep); |
1736 | dev = ep->dev; | 1735 | dev = ep->dev; |
1737 | if ((usbep->name == ep0_string) || !ep->desc) | 1736 | if ((usbep->name == ep0_string) || !ep->ep.desc) |
1738 | return -EINVAL; | 1737 | return -EINVAL; |
1739 | 1738 | ||
1740 | spin_lock_irqsave(&ep->dev->lock, iflags); | 1739 | spin_lock_irqsave(&ep->dev->lock, iflags); |
@@ -1742,7 +1741,6 @@ static int pch_udc_pcd_ep_disable(struct usb_ep *usbep) | |||
1742 | ep->halted = 1; | 1741 | ep->halted = 1; |
1743 | pch_udc_ep_disable(ep); | 1742 | pch_udc_ep_disable(ep); |
1744 | pch_udc_disable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); | 1743 | pch_udc_disable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); |
1745 | ep->desc = NULL; | ||
1746 | ep->ep.desc = NULL; | 1744 | ep->ep.desc = NULL; |
1747 | INIT_LIST_HEAD(&ep->queue); | 1745 | INIT_LIST_HEAD(&ep->queue); |
1748 | spin_unlock_irqrestore(&ep->dev->lock, iflags); | 1746 | spin_unlock_irqrestore(&ep->dev->lock, iflags); |
@@ -1849,7 +1847,7 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq, | |||
1849 | return -EINVAL; | 1847 | return -EINVAL; |
1850 | ep = container_of(usbep, struct pch_udc_ep, ep); | 1848 | ep = container_of(usbep, struct pch_udc_ep, ep); |
1851 | dev = ep->dev; | 1849 | dev = ep->dev; |
1852 | if (!ep->desc && ep->num) | 1850 | if (!ep->ep.desc && ep->num) |
1853 | return -EINVAL; | 1851 | return -EINVAL; |
1854 | req = container_of(usbreq, struct pch_udc_request, req); | 1852 | req = container_of(usbreq, struct pch_udc_request, req); |
1855 | if (!list_empty(&req->queue)) | 1853 | if (!list_empty(&req->queue)) |
@@ -1949,7 +1947,7 @@ static int pch_udc_pcd_dequeue(struct usb_ep *usbep, | |||
1949 | 1947 | ||
1950 | ep = container_of(usbep, struct pch_udc_ep, ep); | 1948 | ep = container_of(usbep, struct pch_udc_ep, ep); |
1951 | dev = ep->dev; | 1949 | dev = ep->dev; |
1952 | if (!usbep || !usbreq || (!ep->desc && ep->num)) | 1950 | if (!usbep || !usbreq || (!ep->ep.desc && ep->num)) |
1953 | return ret; | 1951 | return ret; |
1954 | req = container_of(usbreq, struct pch_udc_request, req); | 1952 | req = container_of(usbreq, struct pch_udc_request, req); |
1955 | spin_lock_irqsave(&ep->dev->lock, flags); | 1953 | spin_lock_irqsave(&ep->dev->lock, flags); |
@@ -1988,7 +1986,7 @@ static int pch_udc_pcd_set_halt(struct usb_ep *usbep, int halt) | |||
1988 | return -EINVAL; | 1986 | return -EINVAL; |
1989 | ep = container_of(usbep, struct pch_udc_ep, ep); | 1987 | ep = container_of(usbep, struct pch_udc_ep, ep); |
1990 | dev = ep->dev; | 1988 | dev = ep->dev; |
1991 | if (!ep->desc && !ep->num) | 1989 | if (!ep->ep.desc && !ep->num) |
1992 | return -EINVAL; | 1990 | return -EINVAL; |
1993 | if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN)) | 1991 | if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN)) |
1994 | return -ESHUTDOWN; | 1992 | return -ESHUTDOWN; |
@@ -2033,7 +2031,7 @@ static int pch_udc_pcd_set_wedge(struct usb_ep *usbep) | |||
2033 | return -EINVAL; | 2031 | return -EINVAL; |
2034 | ep = container_of(usbep, struct pch_udc_ep, ep); | 2032 | ep = container_of(usbep, struct pch_udc_ep, ep); |
2035 | dev = ep->dev; | 2033 | dev = ep->dev; |
2036 | if (!ep->desc && !ep->num) | 2034 | if (!ep->ep.desc && !ep->num) |
2037 | return -EINVAL; | 2035 | return -EINVAL; |
2038 | if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN)) | 2036 | if (!ep->dev->driver || (ep->dev->gadget.speed == USB_SPEED_UNKNOWN)) |
2039 | return -ESHUTDOWN; | 2037 | return -ESHUTDOWN; |
@@ -2065,7 +2063,7 @@ static void pch_udc_pcd_fifo_flush(struct usb_ep *usbep) | |||
2065 | return; | 2063 | return; |
2066 | 2064 | ||
2067 | ep = container_of(usbep, struct pch_udc_ep, ep); | 2065 | ep = container_of(usbep, struct pch_udc_ep, ep); |
2068 | if (ep->desc || !ep->num) | 2066 | if (ep->ep.desc || !ep->num) |
2069 | pch_udc_ep_fifo_flush(ep, ep->in); | 2067 | pch_udc_ep_fifo_flush(ep, ep->in); |
2070 | } | 2068 | } |
2071 | 2069 | ||
@@ -3282,7 +3280,6 @@ static DEFINE_PCI_DEVICE_TABLE(pch_udc_pcidev_id) = { | |||
3282 | 3280 | ||
3283 | MODULE_DEVICE_TABLE(pci, pch_udc_pcidev_id); | 3281 | MODULE_DEVICE_TABLE(pci, pch_udc_pcidev_id); |
3284 | 3282 | ||
3285 | |||
3286 | static struct pci_driver pch_udc_driver = { | 3283 | static struct pci_driver pch_udc_driver = { |
3287 | .name = KBUILD_MODNAME, | 3284 | .name = KBUILD_MODNAME, |
3288 | .id_table = pch_udc_pcidev_id, | 3285 | .id_table = pch_udc_pcidev_id, |
@@ -3293,17 +3290,7 @@ static struct pci_driver pch_udc_driver = { | |||
3293 | .shutdown = pch_udc_shutdown, | 3290 | .shutdown = pch_udc_shutdown, |
3294 | }; | 3291 | }; |
3295 | 3292 | ||
3296 | static int __init pch_udc_pci_init(void) | 3293 | module_pci_driver(pch_udc_driver); |
3297 | { | ||
3298 | return pci_register_driver(&pch_udc_driver); | ||
3299 | } | ||
3300 | module_init(pch_udc_pci_init); | ||
3301 | |||
3302 | static void __exit pch_udc_pci_exit(void) | ||
3303 | { | ||
3304 | pci_unregister_driver(&pch_udc_driver); | ||
3305 | } | ||
3306 | module_exit(pch_udc_pci_exit); | ||
3307 | 3294 | ||
3308 | MODULE_DESCRIPTION("Intel EG20T USB Device Controller"); | 3295 | MODULE_DESCRIPTION("Intel EG20T USB Device Controller"); |
3309 | MODULE_AUTHOR("LAPIS Semiconductor, <tomoya-linux@dsn.lapis-semi.com>"); | 3296 | MODULE_AUTHOR("LAPIS Semiconductor, <tomoya-linux@dsn.lapis-semi.com>"); |
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c index 4e4dc1f5f388..f1f9290a2f47 100644 --- a/drivers/usb/gadget/printer.c +++ b/drivers/usb/gadget/printer.c | |||
@@ -51,6 +51,7 @@ | |||
51 | * the runtime footprint, and giving us at least some parts of what | 51 | * the runtime footprint, and giving us at least some parts of what |
52 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | 52 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
53 | */ | 53 | */ |
54 | #include "composite.c" | ||
54 | #include "usbstring.c" | 55 | #include "usbstring.c" |
55 | #include "config.c" | 56 | #include "config.c" |
56 | #include "epautoconf.c" | 57 | #include "epautoconf.c" |
@@ -75,8 +76,6 @@ struct printer_dev { | |||
75 | /* lock buffer lists during read/write calls */ | 76 | /* lock buffer lists during read/write calls */ |
76 | struct mutex lock_printer_io; | 77 | struct mutex lock_printer_io; |
77 | struct usb_gadget *gadget; | 78 | struct usb_gadget *gadget; |
78 | struct usb_request *req; /* for control responses */ | ||
79 | u8 config; | ||
80 | s8 interface; | 79 | s8 interface; |
81 | struct usb_ep *in_ep, *out_ep; | 80 | struct usb_ep *in_ep, *out_ep; |
82 | 81 | ||
@@ -100,6 +99,7 @@ struct printer_dev { | |||
100 | struct device *pdev; | 99 | struct device *pdev; |
101 | u8 printer_cdev_open; | 100 | u8 printer_cdev_open; |
102 | wait_queue_head_t wait; | 101 | wait_queue_head_t wait; |
102 | struct usb_function function; | ||
103 | }; | 103 | }; |
104 | 104 | ||
105 | static struct printer_dev usb_printer_gadget; | 105 | static struct printer_dev usb_printer_gadget; |
@@ -120,26 +120,6 @@ static struct printer_dev usb_printer_gadget; | |||
120 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). | 120 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). |
121 | */ | 121 | */ |
122 | 122 | ||
123 | static ushort idVendor; | ||
124 | module_param(idVendor, ushort, S_IRUGO); | ||
125 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); | ||
126 | |||
127 | static ushort idProduct; | ||
128 | module_param(idProduct, ushort, S_IRUGO); | ||
129 | MODULE_PARM_DESC(idProduct, "USB Product ID"); | ||
130 | |||
131 | static ushort bcdDevice; | ||
132 | module_param(bcdDevice, ushort, S_IRUGO); | ||
133 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); | ||
134 | |||
135 | static char *iManufacturer; | ||
136 | module_param(iManufacturer, charp, S_IRUGO); | ||
137 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); | ||
138 | |||
139 | static char *iProduct; | ||
140 | module_param(iProduct, charp, S_IRUGO); | ||
141 | MODULE_PARM_DESC(iProduct, "USB Product string"); | ||
142 | |||
143 | static char *iSerialNum; | 123 | static char *iSerialNum; |
144 | module_param(iSerialNum, charp, S_IRUGO); | 124 | module_param(iSerialNum, charp, S_IRUGO); |
145 | MODULE_PARM_DESC(iSerialNum, "1"); | 125 | MODULE_PARM_DESC(iSerialNum, "1"); |
@@ -154,47 +134,8 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR); | |||
154 | 134 | ||
155 | #define QLEN qlen | 135 | #define QLEN qlen |
156 | 136 | ||
157 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
158 | #define DEVSPEED USB_SPEED_HIGH | ||
159 | #else /* full speed (low speed doesn't do bulk) */ | ||
160 | #define DEVSPEED USB_SPEED_FULL | ||
161 | #endif | ||
162 | |||
163 | /*-------------------------------------------------------------------------*/ | 137 | /*-------------------------------------------------------------------------*/ |
164 | 138 | ||
165 | #define xprintk(d, level, fmt, args...) \ | ||
166 | printk(level "%s: " fmt, DRIVER_DESC, ## args) | ||
167 | |||
168 | #ifdef DEBUG | ||
169 | #define DBG(dev, fmt, args...) \ | ||
170 | xprintk(dev, KERN_DEBUG, fmt, ## args) | ||
171 | #else | ||
172 | #define DBG(dev, fmt, args...) \ | ||
173 | do { } while (0) | ||
174 | #endif /* DEBUG */ | ||
175 | |||
176 | #ifdef VERBOSE | ||
177 | #define VDBG(dev, fmt, args...) \ | ||
178 | xprintk(dev, KERN_DEBUG, fmt, ## args) | ||
179 | #else | ||
180 | #define VDBG(dev, fmt, args...) \ | ||
181 | do { } while (0) | ||
182 | #endif /* VERBOSE */ | ||
183 | |||
184 | #define ERROR(dev, fmt, args...) \ | ||
185 | xprintk(dev, KERN_ERR, fmt, ## args) | ||
186 | #define WARNING(dev, fmt, args...) \ | ||
187 | xprintk(dev, KERN_WARNING, fmt, ## args) | ||
188 | #define INFO(dev, fmt, args...) \ | ||
189 | xprintk(dev, KERN_INFO, fmt, ## args) | ||
190 | |||
191 | /*-------------------------------------------------------------------------*/ | ||
192 | |||
193 | /* USB DRIVER HOOKUP (to the hardware driver, below us), mostly | ||
194 | * ep0 implementation: descriptors, config management, setup(). | ||
195 | * also optional class-specific notification interrupt transfer. | ||
196 | */ | ||
197 | |||
198 | /* | 139 | /* |
199 | * DESCRIPTORS ... most are static, but strings and (full) configuration | 140 | * DESCRIPTORS ... most are static, but strings and (full) configuration |
200 | * descriptors are built on demand. | 141 | * descriptors are built on demand. |
@@ -227,24 +168,6 @@ static struct usb_device_descriptor device_desc = { | |||
227 | .bNumConfigurations = 1 | 168 | .bNumConfigurations = 1 |
228 | }; | 169 | }; |
229 | 170 | ||
230 | static struct usb_otg_descriptor otg_desc = { | ||
231 | .bLength = sizeof otg_desc, | ||
232 | .bDescriptorType = USB_DT_OTG, | ||
233 | .bmAttributes = USB_OTG_SRP | ||
234 | }; | ||
235 | |||
236 | static struct usb_config_descriptor config_desc = { | ||
237 | .bLength = sizeof config_desc, | ||
238 | .bDescriptorType = USB_DT_CONFIG, | ||
239 | |||
240 | /* compute wTotalLength on the fly */ | ||
241 | .bNumInterfaces = 1, | ||
242 | .bConfigurationValue = DEV_CONFIG_VALUE, | ||
243 | .iConfiguration = 0, | ||
244 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | ||
245 | .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, | ||
246 | }; | ||
247 | |||
248 | static struct usb_interface_descriptor intf_desc = { | 171 | static struct usb_interface_descriptor intf_desc = { |
249 | .bLength = sizeof intf_desc, | 172 | .bLength = sizeof intf_desc, |
250 | .bDescriptorType = USB_DT_INTERFACE, | 173 | .bDescriptorType = USB_DT_INTERFACE, |
@@ -270,16 +193,13 @@ static struct usb_endpoint_descriptor fs_ep_out_desc = { | |||
270 | .bmAttributes = USB_ENDPOINT_XFER_BULK | 193 | .bmAttributes = USB_ENDPOINT_XFER_BULK |
271 | }; | 194 | }; |
272 | 195 | ||
273 | static const struct usb_descriptor_header *fs_printer_function [11] = { | 196 | static struct usb_descriptor_header *fs_printer_function[] = { |
274 | (struct usb_descriptor_header *) &otg_desc, | ||
275 | (struct usb_descriptor_header *) &intf_desc, | 197 | (struct usb_descriptor_header *) &intf_desc, |
276 | (struct usb_descriptor_header *) &fs_ep_in_desc, | 198 | (struct usb_descriptor_header *) &fs_ep_in_desc, |
277 | (struct usb_descriptor_header *) &fs_ep_out_desc, | 199 | (struct usb_descriptor_header *) &fs_ep_out_desc, |
278 | NULL | 200 | NULL |
279 | }; | 201 | }; |
280 | 202 | ||
281 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
282 | |||
283 | /* | 203 | /* |
284 | * usb 2.0 devices need to expose both high speed and full speed | 204 | * usb 2.0 devices need to expose both high speed and full speed |
285 | * descriptors, unless they only run at full speed. | 205 | * descriptors, unless they only run at full speed. |
@@ -307,23 +227,26 @@ static struct usb_qualifier_descriptor dev_qualifier = { | |||
307 | .bNumConfigurations = 1 | 227 | .bNumConfigurations = 1 |
308 | }; | 228 | }; |
309 | 229 | ||
310 | static const struct usb_descriptor_header *hs_printer_function [11] = { | 230 | static struct usb_descriptor_header *hs_printer_function[] = { |
311 | (struct usb_descriptor_header *) &otg_desc, | ||
312 | (struct usb_descriptor_header *) &intf_desc, | 231 | (struct usb_descriptor_header *) &intf_desc, |
313 | (struct usb_descriptor_header *) &hs_ep_in_desc, | 232 | (struct usb_descriptor_header *) &hs_ep_in_desc, |
314 | (struct usb_descriptor_header *) &hs_ep_out_desc, | 233 | (struct usb_descriptor_header *) &hs_ep_out_desc, |
315 | NULL | 234 | NULL |
316 | }; | 235 | }; |
317 | 236 | ||
318 | /* maxpacket and other transfer characteristics vary by speed. */ | 237 | static struct usb_otg_descriptor otg_descriptor = { |
319 | #define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs)) | 238 | .bLength = sizeof otg_descriptor, |
320 | 239 | .bDescriptorType = USB_DT_OTG, | |
321 | #else | 240 | .bmAttributes = USB_OTG_SRP, |
241 | }; | ||
322 | 242 | ||
323 | /* if there's no high speed support, maxpacket doesn't change. */ | 243 | static const struct usb_descriptor_header *otg_desc[] = { |
324 | #define ep_desc(g, hs, fs) (((void)(g)), (fs)) | 244 | (struct usb_descriptor_header *) &otg_descriptor, |
245 | NULL, | ||
246 | }; | ||
325 | 247 | ||
326 | #endif /* !CONFIG_USB_GADGET_DUALSPEED */ | 248 | /* maxpacket and other transfer characteristics vary by speed. */ |
249 | #define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs)) | ||
327 | 250 | ||
328 | /*-------------------------------------------------------------------------*/ | 251 | /*-------------------------------------------------------------------------*/ |
329 | 252 | ||
@@ -343,11 +266,16 @@ static struct usb_string strings [] = { | |||
343 | { } /* end of list */ | 266 | { } /* end of list */ |
344 | }; | 267 | }; |
345 | 268 | ||
346 | static struct usb_gadget_strings stringtab = { | 269 | static struct usb_gadget_strings stringtab_dev = { |
347 | .language = 0x0409, /* en-us */ | 270 | .language = 0x0409, /* en-us */ |
348 | .strings = strings, | 271 | .strings = strings, |
349 | }; | 272 | }; |
350 | 273 | ||
274 | static struct usb_gadget_strings *dev_strings[] = { | ||
275 | &stringtab_dev, | ||
276 | NULL, | ||
277 | }; | ||
278 | |||
351 | /*-------------------------------------------------------------------------*/ | 279 | /*-------------------------------------------------------------------------*/ |
352 | 280 | ||
353 | static struct usb_request * | 281 | static struct usb_request * |
@@ -937,82 +865,8 @@ static void printer_reset_interface(struct printer_dev *dev) | |||
937 | dev->interface = -1; | 865 | dev->interface = -1; |
938 | } | 866 | } |
939 | 867 | ||
940 | /* change our operational config. must agree with the code | ||
941 | * that returns config descriptors, and altsetting code. | ||
942 | */ | ||
943 | static int | ||
944 | printer_set_config(struct printer_dev *dev, unsigned number) | ||
945 | { | ||
946 | int result = 0; | ||
947 | struct usb_gadget *gadget = dev->gadget; | ||
948 | |||
949 | switch (number) { | ||
950 | case DEV_CONFIG_VALUE: | ||
951 | result = 0; | ||
952 | break; | ||
953 | default: | ||
954 | result = -EINVAL; | ||
955 | /* FALL THROUGH */ | ||
956 | case 0: | ||
957 | break; | ||
958 | } | ||
959 | |||
960 | if (result) { | ||
961 | usb_gadget_vbus_draw(dev->gadget, | ||
962 | dev->gadget->is_otg ? 8 : 100); | ||
963 | } else { | ||
964 | unsigned power; | ||
965 | |||
966 | power = 2 * config_desc.bMaxPower; | ||
967 | usb_gadget_vbus_draw(dev->gadget, power); | ||
968 | |||
969 | dev->config = number; | ||
970 | INFO(dev, "%s config #%d: %d mA, %s\n", | ||
971 | usb_speed_string(gadget->speed), | ||
972 | number, power, driver_desc); | ||
973 | } | ||
974 | return result; | ||
975 | } | ||
976 | |||
977 | static int | ||
978 | config_buf(enum usb_device_speed speed, u8 *buf, u8 type, unsigned index, | ||
979 | int is_otg) | ||
980 | { | ||
981 | int len; | ||
982 | const struct usb_descriptor_header **function; | ||
983 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
984 | int hs = (speed == USB_SPEED_HIGH); | ||
985 | |||
986 | if (type == USB_DT_OTHER_SPEED_CONFIG) | ||
987 | hs = !hs; | ||
988 | |||
989 | if (hs) { | ||
990 | function = hs_printer_function; | ||
991 | } else { | ||
992 | function = fs_printer_function; | ||
993 | } | ||
994 | #else | ||
995 | function = fs_printer_function; | ||
996 | #endif | ||
997 | |||
998 | if (index >= device_desc.bNumConfigurations) | ||
999 | return -EINVAL; | ||
1000 | |||
1001 | /* for now, don't advertise srp-only devices */ | ||
1002 | if (!is_otg) | ||
1003 | function++; | ||
1004 | |||
1005 | len = usb_gadget_config_buf(&config_desc, buf, USB_DESC_BUFSIZE, | ||
1006 | function); | ||
1007 | if (len < 0) | ||
1008 | return len; | ||
1009 | ((struct usb_config_descriptor *) buf)->bDescriptorType = type; | ||
1010 | return len; | ||
1011 | } | ||
1012 | |||
1013 | /* Change our operational Interface. */ | 868 | /* Change our operational Interface. */ |
1014 | static int | 869 | static int set_interface(struct printer_dev *dev, unsigned number) |
1015 | set_interface(struct printer_dev *dev, unsigned number) | ||
1016 | { | 870 | { |
1017 | int result = 0; | 871 | int result = 0; |
1018 | 872 | ||
@@ -1043,14 +897,6 @@ set_interface(struct printer_dev *dev, unsigned number) | |||
1043 | return result; | 897 | return result; |
1044 | } | 898 | } |
1045 | 899 | ||
1046 | static void printer_setup_complete(struct usb_ep *ep, struct usb_request *req) | ||
1047 | { | ||
1048 | if (req->status || req->actual != req->length) | ||
1049 | DBG((struct printer_dev *) ep->driver_data, | ||
1050 | "setup complete --> %d, %d/%d\n", | ||
1051 | req->status, req->actual, req->length); | ||
1052 | } | ||
1053 | |||
1054 | static void printer_soft_reset(struct printer_dev *dev) | 900 | static void printer_soft_reset(struct printer_dev *dev) |
1055 | { | 901 | { |
1056 | struct usb_request *req; | 902 | struct usb_request *req; |
@@ -1107,11 +953,12 @@ static void printer_soft_reset(struct printer_dev *dev) | |||
1107 | * The setup() callback implements all the ep0 functionality that's not | 953 | * The setup() callback implements all the ep0 functionality that's not |
1108 | * handled lower down. | 954 | * handled lower down. |
1109 | */ | 955 | */ |
1110 | static int | 956 | static int printer_func_setup(struct usb_function *f, |
1111 | printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | 957 | const struct usb_ctrlrequest *ctrl) |
1112 | { | 958 | { |
1113 | struct printer_dev *dev = get_gadget_data(gadget); | 959 | struct printer_dev *dev = container_of(f, struct printer_dev, function); |
1114 | struct usb_request *req = dev->req; | 960 | struct usb_composite_dev *cdev = f->config->cdev; |
961 | struct usb_request *req = cdev->req; | ||
1115 | int value = -EOPNOTSUPP; | 962 | int value = -EOPNOTSUPP; |
1116 | u16 wIndex = le16_to_cpu(ctrl->wIndex); | 963 | u16 wIndex = le16_to_cpu(ctrl->wIndex); |
1117 | u16 wValue = le16_to_cpu(ctrl->wValue); | 964 | u16 wValue = le16_to_cpu(ctrl->wValue); |
@@ -1120,102 +967,7 @@ printer_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1120 | DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", | 967 | DBG(dev, "ctrl req%02x.%02x v%04x i%04x l%d\n", |
1121 | ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); | 968 | ctrl->bRequestType, ctrl->bRequest, wValue, wIndex, wLength); |
1122 | 969 | ||
1123 | req->complete = printer_setup_complete; | ||
1124 | |||
1125 | switch (ctrl->bRequestType&USB_TYPE_MASK) { | 970 | switch (ctrl->bRequestType&USB_TYPE_MASK) { |
1126 | |||
1127 | case USB_TYPE_STANDARD: | ||
1128 | switch (ctrl->bRequest) { | ||
1129 | |||
1130 | case USB_REQ_GET_DESCRIPTOR: | ||
1131 | if (ctrl->bRequestType != USB_DIR_IN) | ||
1132 | break; | ||
1133 | switch (wValue >> 8) { | ||
1134 | |||
1135 | case USB_DT_DEVICE: | ||
1136 | device_desc.bMaxPacketSize0 = | ||
1137 | gadget->ep0->maxpacket; | ||
1138 | value = min(wLength, (u16) sizeof device_desc); | ||
1139 | memcpy(req->buf, &device_desc, value); | ||
1140 | break; | ||
1141 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
1142 | case USB_DT_DEVICE_QUALIFIER: | ||
1143 | if (!gadget_is_dualspeed(gadget)) | ||
1144 | break; | ||
1145 | /* | ||
1146 | * assumes ep0 uses the same value for both | ||
1147 | * speeds | ||
1148 | */ | ||
1149 | dev_qualifier.bMaxPacketSize0 = | ||
1150 | gadget->ep0->maxpacket; | ||
1151 | value = min(wLength, | ||
1152 | (u16) sizeof dev_qualifier); | ||
1153 | memcpy(req->buf, &dev_qualifier, value); | ||
1154 | break; | ||
1155 | |||
1156 | case USB_DT_OTHER_SPEED_CONFIG: | ||
1157 | if (!gadget_is_dualspeed(gadget)) | ||
1158 | break; | ||
1159 | /* FALLTHROUGH */ | ||
1160 | #endif /* CONFIG_USB_GADGET_DUALSPEED */ | ||
1161 | case USB_DT_CONFIG: | ||
1162 | value = config_buf(gadget->speed, req->buf, | ||
1163 | wValue >> 8, | ||
1164 | wValue & 0xff, | ||
1165 | gadget->is_otg); | ||
1166 | if (value >= 0) | ||
1167 | value = min(wLength, (u16) value); | ||
1168 | break; | ||
1169 | |||
1170 | case USB_DT_STRING: | ||
1171 | value = usb_gadget_get_string(&stringtab, | ||
1172 | wValue & 0xff, req->buf); | ||
1173 | if (value >= 0) | ||
1174 | value = min(wLength, (u16) value); | ||
1175 | break; | ||
1176 | } | ||
1177 | break; | ||
1178 | |||
1179 | case USB_REQ_SET_CONFIGURATION: | ||
1180 | if (ctrl->bRequestType != 0) | ||
1181 | break; | ||
1182 | if (gadget->a_hnp_support) | ||
1183 | DBG(dev, "HNP available\n"); | ||
1184 | else if (gadget->a_alt_hnp_support) | ||
1185 | DBG(dev, "HNP needs a different root port\n"); | ||
1186 | value = printer_set_config(dev, wValue); | ||
1187 | if (!value) | ||
1188 | value = set_interface(dev, PRINTER_INTERFACE); | ||
1189 | break; | ||
1190 | case USB_REQ_GET_CONFIGURATION: | ||
1191 | if (ctrl->bRequestType != USB_DIR_IN) | ||
1192 | break; | ||
1193 | *(u8 *)req->buf = dev->config; | ||
1194 | value = min(wLength, (u16) 1); | ||
1195 | break; | ||
1196 | |||
1197 | case USB_REQ_SET_INTERFACE: | ||
1198 | if (ctrl->bRequestType != USB_RECIP_INTERFACE || | ||
1199 | !dev->config) | ||
1200 | break; | ||
1201 | |||
1202 | value = set_interface(dev, PRINTER_INTERFACE); | ||
1203 | break; | ||
1204 | case USB_REQ_GET_INTERFACE: | ||
1205 | if (ctrl->bRequestType != | ||
1206 | (USB_DIR_IN|USB_RECIP_INTERFACE) | ||
1207 | || !dev->config) | ||
1208 | break; | ||
1209 | |||
1210 | *(u8 *)req->buf = dev->interface; | ||
1211 | value = min(wLength, (u16) 1); | ||
1212 | break; | ||
1213 | |||
1214 | default: | ||
1215 | goto unknown; | ||
1216 | } | ||
1217 | break; | ||
1218 | |||
1219 | case USB_TYPE_CLASS: | 971 | case USB_TYPE_CLASS: |
1220 | switch (ctrl->bRequest) { | 972 | switch (ctrl->bRequest) { |
1221 | case 0: /* Get the IEEE-1284 PNP String */ | 973 | case 0: /* Get the IEEE-1284 PNP String */ |
@@ -1261,44 +1013,50 @@ unknown: | |||
1261 | wValue, wIndex, wLength); | 1013 | wValue, wIndex, wLength); |
1262 | break; | 1014 | break; |
1263 | } | 1015 | } |
1264 | |||
1265 | /* respond with data transfer before status phase? */ | ||
1266 | if (value >= 0) { | ||
1267 | req->length = value; | ||
1268 | req->zero = value < wLength; | ||
1269 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | ||
1270 | if (value < 0) { | ||
1271 | DBG(dev, "ep_queue --> %d\n", value); | ||
1272 | req->status = 0; | ||
1273 | printer_setup_complete(gadget->ep0, req); | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1277 | /* host either stalls (value < 0) or reports success */ | 1016 | /* host either stalls (value < 0) or reports success */ |
1278 | return value; | 1017 | return value; |
1279 | } | 1018 | } |
1280 | 1019 | ||
1281 | static void | 1020 | static int __init printer_func_bind(struct usb_configuration *c, |
1282 | printer_disconnect(struct usb_gadget *gadget) | 1021 | struct usb_function *f) |
1283 | { | 1022 | { |
1284 | struct printer_dev *dev = get_gadget_data(gadget); | 1023 | return 0; |
1024 | } | ||
1025 | |||
1026 | static void printer_func_unbind(struct usb_configuration *c, | ||
1027 | struct usb_function *f) | ||
1028 | { | ||
1029 | } | ||
1030 | |||
1031 | static int printer_func_set_alt(struct usb_function *f, | ||
1032 | unsigned intf, unsigned alt) | ||
1033 | { | ||
1034 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
1035 | int ret = -ENOTSUPP; | ||
1036 | |||
1037 | if (!alt) | ||
1038 | ret = set_interface(dev, PRINTER_INTERFACE); | ||
1039 | return ret; | ||
1040 | } | ||
1041 | |||
1042 | static void printer_func_disable(struct usb_function *f) | ||
1043 | { | ||
1044 | struct printer_dev *dev = container_of(f, struct printer_dev, function); | ||
1285 | unsigned long flags; | 1045 | unsigned long flags; |
1286 | 1046 | ||
1287 | DBG(dev, "%s\n", __func__); | 1047 | DBG(dev, "%s\n", __func__); |
1288 | 1048 | ||
1289 | spin_lock_irqsave(&dev->lock, flags); | 1049 | spin_lock_irqsave(&dev->lock, flags); |
1290 | |||
1291 | printer_reset_interface(dev); | 1050 | printer_reset_interface(dev); |
1292 | |||
1293 | spin_unlock_irqrestore(&dev->lock, flags); | 1051 | spin_unlock_irqrestore(&dev->lock, flags); |
1294 | } | 1052 | } |
1295 | 1053 | ||
1296 | static void | 1054 | static void printer_cfg_unbind(struct usb_configuration *c) |
1297 | printer_unbind(struct usb_gadget *gadget) | ||
1298 | { | 1055 | { |
1299 | struct printer_dev *dev = get_gadget_data(gadget); | 1056 | struct printer_dev *dev; |
1300 | struct usb_request *req; | 1057 | struct usb_request *req; |
1301 | 1058 | ||
1059 | dev = &usb_printer_gadget; | ||
1302 | 1060 | ||
1303 | DBG(dev, "%s\n", __func__); | 1061 | DBG(dev, "%s\n", __func__); |
1304 | 1062 | ||
@@ -1336,18 +1094,18 @@ printer_unbind(struct usb_gadget *gadget) | |||
1336 | list_del(&req->list); | 1094 | list_del(&req->list); |
1337 | printer_req_free(dev->out_ep, req); | 1095 | printer_req_free(dev->out_ep, req); |
1338 | } | 1096 | } |
1339 | |||
1340 | if (dev->req) { | ||
1341 | printer_req_free(gadget->ep0, dev->req); | ||
1342 | dev->req = NULL; | ||
1343 | } | ||
1344 | |||
1345 | set_gadget_data(gadget, NULL); | ||
1346 | } | 1097 | } |
1347 | 1098 | ||
1348 | static int __init | 1099 | static struct usb_configuration printer_cfg_driver = { |
1349 | printer_bind(struct usb_gadget *gadget) | 1100 | .label = "printer", |
1101 | .unbind = printer_cfg_unbind, | ||
1102 | .bConfigurationValue = 1, | ||
1103 | .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, | ||
1104 | }; | ||
1105 | |||
1106 | static int __init printer_bind_config(struct usb_configuration *c) | ||
1350 | { | 1107 | { |
1108 | struct usb_gadget *gadget = c->cdev->gadget; | ||
1351 | struct printer_dev *dev; | 1109 | struct printer_dev *dev; |
1352 | struct usb_ep *in_ep, *out_ep; | 1110 | struct usb_ep *in_ep, *out_ep; |
1353 | int status = -ENOMEM; | 1111 | int status = -ENOMEM; |
@@ -1358,6 +1116,14 @@ printer_bind(struct usb_gadget *gadget) | |||
1358 | 1116 | ||
1359 | dev = &usb_printer_gadget; | 1117 | dev = &usb_printer_gadget; |
1360 | 1118 | ||
1119 | dev->function.name = shortname; | ||
1120 | dev->function.descriptors = fs_printer_function; | ||
1121 | dev->function.hs_descriptors = hs_printer_function; | ||
1122 | dev->function.bind = printer_func_bind; | ||
1123 | dev->function.setup = printer_func_setup; | ||
1124 | dev->function.unbind = printer_func_unbind; | ||
1125 | dev->function.set_alt = printer_func_set_alt; | ||
1126 | dev->function.disable = printer_func_disable; | ||
1361 | 1127 | ||
1362 | /* Setup the sysfs files for the printer gadget. */ | 1128 | /* Setup the sysfs files for the printer gadget. */ |
1363 | dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, | 1129 | dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, |
@@ -1393,29 +1159,6 @@ printer_bind(struct usb_gadget *gadget) | |||
1393 | init_utsname()->sysname, init_utsname()->release, | 1159 | init_utsname()->sysname, init_utsname()->release, |
1394 | gadget->name); | 1160 | gadget->name); |
1395 | 1161 | ||
1396 | device_desc.idVendor = | ||
1397 | cpu_to_le16(PRINTER_VENDOR_NUM); | ||
1398 | device_desc.idProduct = | ||
1399 | cpu_to_le16(PRINTER_PRODUCT_NUM); | ||
1400 | |||
1401 | /* support optional vendor/distro customization */ | ||
1402 | if (idVendor) { | ||
1403 | if (!idProduct) { | ||
1404 | dev_err(&gadget->dev, "idVendor needs idProduct!\n"); | ||
1405 | return -ENODEV; | ||
1406 | } | ||
1407 | device_desc.idVendor = cpu_to_le16(idVendor); | ||
1408 | device_desc.idProduct = cpu_to_le16(idProduct); | ||
1409 | if (bcdDevice) | ||
1410 | device_desc.bcdDevice = cpu_to_le16(bcdDevice); | ||
1411 | } | ||
1412 | |||
1413 | if (iManufacturer) | ||
1414 | strlcpy(manufacturer, iManufacturer, sizeof manufacturer); | ||
1415 | |||
1416 | if (iProduct) | ||
1417 | strlcpy(product_desc, iProduct, sizeof product_desc); | ||
1418 | |||
1419 | if (iSerialNum) | 1162 | if (iSerialNum) |
1420 | strlcpy(serial_num, iSerialNum, sizeof serial_num); | 1163 | strlcpy(serial_num, iSerialNum, sizeof serial_num); |
1421 | 1164 | ||
@@ -1442,17 +1185,16 @@ autoconf_fail: | |||
1442 | goto autoconf_fail; | 1185 | goto autoconf_fail; |
1443 | out_ep->driver_data = out_ep; /* claim */ | 1186 | out_ep->driver_data = out_ep; /* claim */ |
1444 | 1187 | ||
1445 | #ifdef CONFIG_USB_GADGET_DUALSPEED | ||
1446 | /* assumes that all endpoints are dual-speed */ | 1188 | /* assumes that all endpoints are dual-speed */ |
1447 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; | 1189 | hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress; |
1448 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; | 1190 | hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress; |
1449 | #endif /* DUALSPEED */ | ||
1450 | 1191 | ||
1451 | usb_gadget_set_selfpowered(gadget); | 1192 | usb_gadget_set_selfpowered(gadget); |
1452 | 1193 | ||
1453 | if (gadget->is_otg) { | 1194 | if (gadget->is_otg) { |
1454 | otg_desc.bmAttributes |= USB_OTG_HNP, | 1195 | otg_descriptor.bmAttributes |= USB_OTG_HNP; |
1455 | config_desc.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 1196 | printer_cfg_driver.descriptors = otg_desc; |
1197 | printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; | ||
1456 | } | 1198 | } |
1457 | 1199 | ||
1458 | spin_lock_init(&dev->lock); | 1200 | spin_lock_init(&dev->lock); |
@@ -1466,7 +1208,6 @@ autoconf_fail: | |||
1466 | init_waitqueue_head(&dev->tx_wait); | 1208 | init_waitqueue_head(&dev->tx_wait); |
1467 | init_waitqueue_head(&dev->tx_flush_wait); | 1209 | init_waitqueue_head(&dev->tx_flush_wait); |
1468 | 1210 | ||
1469 | dev->config = 0; | ||
1470 | dev->interface = -1; | 1211 | dev->interface = -1; |
1471 | dev->printer_cdev_open = 0; | 1212 | dev->printer_cdev_open = 0; |
1472 | dev->printer_status = PRINTER_NOT_ERROR; | 1213 | dev->printer_status = PRINTER_NOT_ERROR; |
@@ -1477,14 +1218,6 @@ autoconf_fail: | |||
1477 | dev->in_ep = in_ep; | 1218 | dev->in_ep = in_ep; |
1478 | dev->out_ep = out_ep; | 1219 | dev->out_ep = out_ep; |
1479 | 1220 | ||
1480 | /* preallocate control message data and buffer */ | ||
1481 | dev->req = printer_req_alloc(gadget->ep0, USB_DESC_BUFSIZE, | ||
1482 | GFP_KERNEL); | ||
1483 | if (!dev->req) { | ||
1484 | status = -ENOMEM; | ||
1485 | goto fail; | ||
1486 | } | ||
1487 | |||
1488 | for (i = 0; i < QLEN; i++) { | 1221 | for (i = 0; i < QLEN; i++) { |
1489 | req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); | 1222 | req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); |
1490 | if (!req) { | 1223 | if (!req) { |
@@ -1513,45 +1246,37 @@ autoconf_fail: | |||
1513 | list_add(&req->list, &dev->rx_reqs); | 1246 | list_add(&req->list, &dev->rx_reqs); |
1514 | } | 1247 | } |
1515 | 1248 | ||
1516 | dev->req->complete = printer_setup_complete; | ||
1517 | |||
1518 | /* finish hookup to lower layer ... */ | 1249 | /* finish hookup to lower layer ... */ |
1519 | dev->gadget = gadget; | 1250 | dev->gadget = gadget; |
1520 | set_gadget_data(gadget, dev); | ||
1521 | gadget->ep0->driver_data = dev; | ||
1522 | 1251 | ||
1523 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); | 1252 | INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); |
1524 | INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name, | 1253 | INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name, |
1525 | in_ep->name); | 1254 | in_ep->name); |
1526 | |||
1527 | return 0; | 1255 | return 0; |
1528 | 1256 | ||
1529 | fail: | 1257 | fail: |
1530 | printer_unbind(gadget); | 1258 | printer_cfg_unbind(c); |
1531 | return status; | 1259 | return status; |
1532 | } | 1260 | } |
1533 | 1261 | ||
1534 | /*-------------------------------------------------------------------------*/ | 1262 | static int printer_unbind(struct usb_composite_dev *cdev) |
1263 | { | ||
1264 | return 0; | ||
1265 | } | ||
1535 | 1266 | ||
1536 | static struct usb_gadget_driver printer_driver = { | 1267 | static int __init printer_bind(struct usb_composite_dev *cdev) |
1537 | .max_speed = DEVSPEED, | 1268 | { |
1269 | return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); | ||
1270 | } | ||
1538 | 1271 | ||
1539 | .function = (char *) driver_desc, | 1272 | static struct usb_composite_driver printer_driver = { |
1273 | .name = shortname, | ||
1274 | .dev = &device_desc, | ||
1275 | .strings = dev_strings, | ||
1276 | .max_speed = USB_SPEED_HIGH, | ||
1540 | .unbind = printer_unbind, | 1277 | .unbind = printer_unbind, |
1541 | |||
1542 | .setup = printer_setup, | ||
1543 | .disconnect = printer_disconnect, | ||
1544 | |||
1545 | .driver = { | ||
1546 | .name = (char *) shortname, | ||
1547 | .owner = THIS_MODULE, | ||
1548 | }, | ||
1549 | }; | 1278 | }; |
1550 | 1279 | ||
1551 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1552 | MODULE_AUTHOR("Craig Nadler"); | ||
1553 | MODULE_LICENSE("GPL"); | ||
1554 | |||
1555 | static int __init | 1280 | static int __init |
1556 | init(void) | 1281 | init(void) |
1557 | { | 1282 | { |
@@ -1560,23 +1285,23 @@ init(void) | |||
1560 | usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); | 1285 | usb_gadget_class = class_create(THIS_MODULE, "usb_printer_gadget"); |
1561 | if (IS_ERR(usb_gadget_class)) { | 1286 | if (IS_ERR(usb_gadget_class)) { |
1562 | status = PTR_ERR(usb_gadget_class); | 1287 | status = PTR_ERR(usb_gadget_class); |
1563 | ERROR(dev, "unable to create usb_gadget class %d\n", status); | 1288 | pr_err("unable to create usb_gadget class %d\n", status); |
1564 | return status; | 1289 | return status; |
1565 | } | 1290 | } |
1566 | 1291 | ||
1567 | status = alloc_chrdev_region(&g_printer_devno, 0, 1, | 1292 | status = alloc_chrdev_region(&g_printer_devno, 0, 1, |
1568 | "USB printer gadget"); | 1293 | "USB printer gadget"); |
1569 | if (status) { | 1294 | if (status) { |
1570 | ERROR(dev, "alloc_chrdev_region %d\n", status); | 1295 | pr_err("alloc_chrdev_region %d\n", status); |
1571 | class_destroy(usb_gadget_class); | 1296 | class_destroy(usb_gadget_class); |
1572 | return status; | 1297 | return status; |
1573 | } | 1298 | } |
1574 | 1299 | ||
1575 | status = usb_gadget_probe_driver(&printer_driver, printer_bind); | 1300 | status = usb_composite_probe(&printer_driver, printer_bind); |
1576 | if (status) { | 1301 | if (status) { |
1577 | class_destroy(usb_gadget_class); | 1302 | class_destroy(usb_gadget_class); |
1578 | unregister_chrdev_region(g_printer_devno, 1); | 1303 | unregister_chrdev_region(g_printer_devno, 1); |
1579 | DBG(dev, "usb_gadget_probe_driver %x\n", status); | 1304 | pr_err("usb_gadget_probe_driver %x\n", status); |
1580 | } | 1305 | } |
1581 | 1306 | ||
1582 | return status; | 1307 | return status; |
@@ -1586,15 +1311,14 @@ module_init(init); | |||
1586 | static void __exit | 1311 | static void __exit |
1587 | cleanup(void) | 1312 | cleanup(void) |
1588 | { | 1313 | { |
1589 | int status; | ||
1590 | |||
1591 | mutex_lock(&usb_printer_gadget.lock_printer_io); | 1314 | mutex_lock(&usb_printer_gadget.lock_printer_io); |
1592 | status = usb_gadget_unregister_driver(&printer_driver); | 1315 | usb_composite_unregister(&printer_driver); |
1593 | if (status) | ||
1594 | ERROR(dev, "usb_gadget_unregister_driver %x\n", status); | ||
1595 | |||
1596 | unregister_chrdev_region(g_printer_devno, 1); | 1316 | unregister_chrdev_region(g_printer_devno, 1); |
1597 | class_destroy(usb_gadget_class); | 1317 | class_destroy(usb_gadget_class); |
1598 | mutex_unlock(&usb_printer_gadget.lock_printer_io); | 1318 | mutex_unlock(&usb_printer_gadget.lock_printer_io); |
1599 | } | 1319 | } |
1600 | module_exit(cleanup); | 1320 | module_exit(cleanup); |
1321 | |||
1322 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1323 | MODULE_AUTHOR("Craig Nadler"); | ||
1324 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 41ed69c96d8c..d7c8cb3bf759 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c | |||
@@ -218,7 +218,7 @@ static int pxa25x_ep_enable (struct usb_ep *_ep, | |||
218 | struct pxa25x_udc *dev; | 218 | struct pxa25x_udc *dev; |
219 | 219 | ||
220 | ep = container_of (_ep, struct pxa25x_ep, ep); | 220 | ep = container_of (_ep, struct pxa25x_ep, ep); |
221 | if (!_ep || !desc || ep->desc || _ep->name == ep0name | 221 | if (!_ep || !desc || ep->ep.desc || _ep->name == ep0name |
222 | || desc->bDescriptorType != USB_DT_ENDPOINT | 222 | || desc->bDescriptorType != USB_DT_ENDPOINT |
223 | || ep->bEndpointAddress != desc->bEndpointAddress | 223 | || ep->bEndpointAddress != desc->bEndpointAddress |
224 | || ep->fifo_size < usb_endpoint_maxp (desc)) { | 224 | || ep->fifo_size < usb_endpoint_maxp (desc)) { |
@@ -249,7 +249,7 @@ static int pxa25x_ep_enable (struct usb_ep *_ep, | |||
249 | return -ESHUTDOWN; | 249 | return -ESHUTDOWN; |
250 | } | 250 | } |
251 | 251 | ||
252 | ep->desc = desc; | 252 | ep->ep.desc = desc; |
253 | ep->stopped = 0; | 253 | ep->stopped = 0; |
254 | ep->pio_irqs = 0; | 254 | ep->pio_irqs = 0; |
255 | ep->ep.maxpacket = usb_endpoint_maxp (desc); | 255 | ep->ep.maxpacket = usb_endpoint_maxp (desc); |
@@ -269,7 +269,7 @@ static int pxa25x_ep_disable (struct usb_ep *_ep) | |||
269 | unsigned long flags; | 269 | unsigned long flags; |
270 | 270 | ||
271 | ep = container_of (_ep, struct pxa25x_ep, ep); | 271 | ep = container_of (_ep, struct pxa25x_ep, ep); |
272 | if (!_ep || !ep->desc) { | 272 | if (!_ep || !ep->ep.desc) { |
273 | DMSG("%s, %s not enabled\n", __func__, | 273 | DMSG("%s, %s not enabled\n", __func__, |
274 | _ep ? ep->ep.name : NULL); | 274 | _ep ? ep->ep.name : NULL); |
275 | return -EINVAL; | 275 | return -EINVAL; |
@@ -281,7 +281,6 @@ static int pxa25x_ep_disable (struct usb_ep *_ep) | |||
281 | /* flush fifo (mostly for IN buffers) */ | 281 | /* flush fifo (mostly for IN buffers) */ |
282 | pxa25x_ep_fifo_flush (_ep); | 282 | pxa25x_ep_fifo_flush (_ep); |
283 | 283 | ||
284 | ep->desc = NULL; | ||
285 | ep->ep.desc = NULL; | 284 | ep->ep.desc = NULL; |
286 | ep->stopped = 1; | 285 | ep->stopped = 1; |
287 | 286 | ||
@@ -390,7 +389,7 @@ write_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req) | |||
390 | { | 389 | { |
391 | unsigned max; | 390 | unsigned max; |
392 | 391 | ||
393 | max = usb_endpoint_maxp(ep->desc); | 392 | max = usb_endpoint_maxp(ep->ep.desc); |
394 | do { | 393 | do { |
395 | unsigned count; | 394 | unsigned count; |
396 | int is_last, is_short; | 395 | int is_last, is_short; |
@@ -644,7 +643,7 @@ pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
644 | } | 643 | } |
645 | 644 | ||
646 | ep = container_of(_ep, struct pxa25x_ep, ep); | 645 | ep = container_of(_ep, struct pxa25x_ep, ep); |
647 | if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) { | 646 | if (unlikely(!_ep || (!ep->ep.desc && ep->ep.name != ep0name))) { |
648 | DMSG("%s, bad ep\n", __func__); | 647 | DMSG("%s, bad ep\n", __func__); |
649 | return -EINVAL; | 648 | return -EINVAL; |
650 | } | 649 | } |
@@ -660,7 +659,7 @@ pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
660 | * we can report per-packet status. that also helps with dma. | 659 | * we can report per-packet status. that also helps with dma. |
661 | */ | 660 | */ |
662 | if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 661 | if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
663 | && req->req.length > usb_endpoint_maxp (ep->desc))) | 662 | && req->req.length > usb_endpoint_maxp(ep->ep.desc))) |
664 | return -EMSGSIZE; | 663 | return -EMSGSIZE; |
665 | 664 | ||
666 | DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", | 665 | DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", |
@@ -673,7 +672,7 @@ pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
673 | 672 | ||
674 | /* kickstart this i/o queue? */ | 673 | /* kickstart this i/o queue? */ |
675 | if (list_empty(&ep->queue) && !ep->stopped) { | 674 | if (list_empty(&ep->queue) && !ep->stopped) { |
676 | if (ep->desc == NULL/* ep0 */) { | 675 | if (ep->ep.desc == NULL/* ep0 */) { |
677 | unsigned length = _req->length; | 676 | unsigned length = _req->length; |
678 | 677 | ||
679 | switch (dev->ep0state) { | 678 | switch (dev->ep0state) { |
@@ -722,7 +721,7 @@ pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
722 | req = NULL; | 721 | req = NULL; |
723 | } | 722 | } |
724 | 723 | ||
725 | if (likely (req && ep->desc)) | 724 | if (likely(req && ep->ep.desc)) |
726 | pio_irq_enable(ep->bEndpointAddress); | 725 | pio_irq_enable(ep->bEndpointAddress); |
727 | } | 726 | } |
728 | 727 | ||
@@ -749,7 +748,7 @@ static void nuke(struct pxa25x_ep *ep, int status) | |||
749 | queue); | 748 | queue); |
750 | done(ep, req, status); | 749 | done(ep, req, status); |
751 | } | 750 | } |
752 | if (ep->desc) | 751 | if (ep->ep.desc) |
753 | pio_irq_disable (ep->bEndpointAddress); | 752 | pio_irq_disable (ep->bEndpointAddress); |
754 | } | 753 | } |
755 | 754 | ||
@@ -792,7 +791,7 @@ static int pxa25x_ep_set_halt(struct usb_ep *_ep, int value) | |||
792 | 791 | ||
793 | ep = container_of(_ep, struct pxa25x_ep, ep); | 792 | ep = container_of(_ep, struct pxa25x_ep, ep); |
794 | if (unlikely (!_ep | 793 | if (unlikely (!_ep |
795 | || (!ep->desc && ep->ep.name != ep0name)) | 794 | || (!ep->ep.desc && ep->ep.name != ep0name)) |
796 | || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 795 | || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
797 | DMSG("%s, bad ep\n", __func__); | 796 | DMSG("%s, bad ep\n", __func__); |
798 | return -EINVAL; | 797 | return -EINVAL; |
@@ -820,7 +819,7 @@ static int pxa25x_ep_set_halt(struct usb_ep *_ep, int value) | |||
820 | *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF; | 819 | *ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF; |
821 | 820 | ||
822 | /* ep0 needs special care */ | 821 | /* ep0 needs special care */ |
823 | if (!ep->desc) { | 822 | if (!ep->ep.desc) { |
824 | start_watchdog(ep->dev); | 823 | start_watchdog(ep->dev); |
825 | ep->dev->req_pending = 0; | 824 | ep->dev->req_pending = 0; |
826 | ep->dev->ep0state = EP0_STALL; | 825 | ep->dev->ep0state = EP0_STALL; |
@@ -1087,7 +1086,7 @@ udc_seq_show(struct seq_file *m, void *_d) | |||
1087 | if (i != 0) { | 1086 | if (i != 0) { |
1088 | const struct usb_endpoint_descriptor *desc; | 1087 | const struct usb_endpoint_descriptor *desc; |
1089 | 1088 | ||
1090 | desc = ep->desc; | 1089 | desc = ep->ep.desc; |
1091 | if (!desc) | 1090 | if (!desc) |
1092 | continue; | 1091 | continue; |
1093 | tmp = *dev->ep [i].reg_udccs; | 1092 | tmp = *dev->ep [i].reg_udccs; |
@@ -1191,7 +1190,6 @@ static void udc_reinit(struct pxa25x_udc *dev) | |||
1191 | if (i != 0) | 1190 | if (i != 0) |
1192 | list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); | 1191 | list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); |
1193 | 1192 | ||
1194 | ep->desc = NULL; | ||
1195 | ep->ep.desc = NULL; | 1193 | ep->ep.desc = NULL; |
1196 | ep->stopped = 0; | 1194 | ep->stopped = 0; |
1197 | INIT_LIST_HEAD (&ep->queue); | 1195 | INIT_LIST_HEAD (&ep->queue); |
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h index 893e917f048e..861f4df6ea22 100644 --- a/drivers/usb/gadget/pxa25x_udc.h +++ b/drivers/usb/gadget/pxa25x_udc.h | |||
@@ -41,7 +41,6 @@ struct pxa25x_ep { | |||
41 | struct usb_ep ep; | 41 | struct usb_ep ep; |
42 | struct pxa25x_udc *dev; | 42 | struct pxa25x_udc *dev; |
43 | 43 | ||
44 | const struct usb_endpoint_descriptor *desc; | ||
45 | struct list_head queue; | 44 | struct list_head queue; |
46 | unsigned long pio_irqs; | 45 | unsigned long pio_irqs; |
47 | 46 | ||
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index c4401e7dd3a6..f3ac2a20c27c 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -459,7 +459,7 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
459 | unsigned char *counter; | 459 | unsigned char *counter; |
460 | int ret; | 460 | int ret; |
461 | 461 | ||
462 | ep->desc = desc; | 462 | ep->ep.desc = desc; |
463 | 463 | ||
464 | if (ep->pipenum) /* already allocated pipe */ | 464 | if (ep->pipenum) /* already allocated pipe */ |
465 | return 0; | 465 | return 0; |
@@ -648,7 +648,7 @@ static int sudmac_alloc_channel(struct r8a66597 *r8a66597, | |||
648 | /* set SUDMAC parameters */ | 648 | /* set SUDMAC parameters */ |
649 | dma = &r8a66597->dma; | 649 | dma = &r8a66597->dma; |
650 | dma->used = 1; | 650 | dma->used = 1; |
651 | if (ep->desc->bEndpointAddress & USB_DIR_IN) { | 651 | if (ep->ep.desc->bEndpointAddress & USB_DIR_IN) { |
652 | dma->dir = 1; | 652 | dma->dir = 1; |
653 | } else { | 653 | } else { |
654 | dma->dir = 0; | 654 | dma->dir = 0; |
@@ -770,7 +770,7 @@ static void start_packet_read(struct r8a66597_ep *ep, | |||
770 | 770 | ||
771 | static void start_packet(struct r8a66597_ep *ep, struct r8a66597_request *req) | 771 | static void start_packet(struct r8a66597_ep *ep, struct r8a66597_request *req) |
772 | { | 772 | { |
773 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | 773 | if (ep->ep.desc->bEndpointAddress & USB_DIR_IN) |
774 | start_packet_write(ep, req); | 774 | start_packet_write(ep, req); |
775 | else | 775 | else |
776 | start_packet_read(ep, req); | 776 | start_packet_read(ep, req); |
@@ -930,7 +930,7 @@ __acquires(r8a66597->lock) | |||
930 | 930 | ||
931 | if (restart) { | 931 | if (restart) { |
932 | req = get_request_from_ep(ep); | 932 | req = get_request_from_ep(ep); |
933 | if (ep->desc) | 933 | if (ep->ep.desc) |
934 | start_packet(ep, req); | 934 | start_packet(ep, req); |
935 | } | 935 | } |
936 | } | 936 | } |
@@ -1116,7 +1116,7 @@ static void irq_pipe_ready(struct r8a66597 *r8a66597, u16 status, u16 enb) | |||
1116 | r8a66597_write(r8a66597, ~check, BRDYSTS); | 1116 | r8a66597_write(r8a66597, ~check, BRDYSTS); |
1117 | ep = r8a66597->pipenum2ep[pipenum]; | 1117 | ep = r8a66597->pipenum2ep[pipenum]; |
1118 | req = get_request_from_ep(ep); | 1118 | req = get_request_from_ep(ep); |
1119 | if (ep->desc->bEndpointAddress & USB_DIR_IN) | 1119 | if (ep->ep.desc->bEndpointAddress & USB_DIR_IN) |
1120 | irq_packet_write(ep, req); | 1120 | irq_packet_write(ep, req); |
1121 | else | 1121 | else |
1122 | irq_packet_read(ep, req); | 1122 | irq_packet_read(ep, req); |
@@ -1170,7 +1170,7 @@ __acquires(r8a66597->lock) | |||
1170 | 1170 | ||
1171 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 1171 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
1172 | case USB_RECIP_DEVICE: | 1172 | case USB_RECIP_DEVICE: |
1173 | status = 1 << USB_DEVICE_SELF_POWERED; | 1173 | status = r8a66597->device_status; |
1174 | break; | 1174 | break; |
1175 | case USB_RECIP_INTERFACE: | 1175 | case USB_RECIP_INTERFACE: |
1176 | status = 0; | 1176 | status = 0; |
@@ -1627,7 +1627,7 @@ static int r8a66597_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
1627 | req->req.actual = 0; | 1627 | req->req.actual = 0; |
1628 | req->req.status = -EINPROGRESS; | 1628 | req->req.status = -EINPROGRESS; |
1629 | 1629 | ||
1630 | if (ep->desc == NULL) /* control */ | 1630 | if (ep->ep.desc == NULL) /* control */ |
1631 | start_ep0(ep, req); | 1631 | start_ep0(ep, req); |
1632 | else { | 1632 | else { |
1633 | if (request && !ep->busy) | 1633 | if (request && !ep->busy) |
@@ -1692,7 +1692,7 @@ static int r8a66597_set_wedge(struct usb_ep *_ep) | |||
1692 | 1692 | ||
1693 | ep = container_of(_ep, struct r8a66597_ep, ep); | 1693 | ep = container_of(_ep, struct r8a66597_ep, ep); |
1694 | 1694 | ||
1695 | if (!ep || !ep->desc) | 1695 | if (!ep || !ep->ep.desc) |
1696 | return -EINVAL; | 1696 | return -EINVAL; |
1697 | 1697 | ||
1698 | spin_lock_irqsave(&ep->r8a66597->lock, flags); | 1698 | spin_lock_irqsave(&ep->r8a66597->lock, flags); |
@@ -1800,11 +1800,24 @@ static int r8a66597_pullup(struct usb_gadget *gadget, int is_on) | |||
1800 | return 0; | 1800 | return 0; |
1801 | } | 1801 | } |
1802 | 1802 | ||
1803 | static int r8a66597_set_selfpowered(struct usb_gadget *gadget, int is_self) | ||
1804 | { | ||
1805 | struct r8a66597 *r8a66597 = gadget_to_r8a66597(gadget); | ||
1806 | |||
1807 | if (is_self) | ||
1808 | r8a66597->device_status |= 1 << USB_DEVICE_SELF_POWERED; | ||
1809 | else | ||
1810 | r8a66597->device_status &= ~(1 << USB_DEVICE_SELF_POWERED); | ||
1811 | |||
1812 | return 0; | ||
1813 | } | ||
1814 | |||
1803 | static struct usb_gadget_ops r8a66597_gadget_ops = { | 1815 | static struct usb_gadget_ops r8a66597_gadget_ops = { |
1804 | .get_frame = r8a66597_get_frame, | 1816 | .get_frame = r8a66597_get_frame, |
1805 | .udc_start = r8a66597_start, | 1817 | .udc_start = r8a66597_start, |
1806 | .udc_stop = r8a66597_stop, | 1818 | .udc_stop = r8a66597_stop, |
1807 | .pullup = r8a66597_pullup, | 1819 | .pullup = r8a66597_pullup, |
1820 | .set_selfpowered = r8a66597_set_selfpowered, | ||
1808 | }; | 1821 | }; |
1809 | 1822 | ||
1810 | static int __exit r8a66597_remove(struct platform_device *pdev) | 1823 | static int __exit r8a66597_remove(struct platform_device *pdev) |
diff --git a/drivers/usb/gadget/r8a66597-udc.h b/drivers/usb/gadget/r8a66597-udc.h index 8e3de61cd4b8..99908c76ccd1 100644 --- a/drivers/usb/gadget/r8a66597-udc.h +++ b/drivers/usb/gadget/r8a66597-udc.h | |||
@@ -72,7 +72,7 @@ struct r8a66597_ep { | |||
72 | unsigned use_dma:1; | 72 | unsigned use_dma:1; |
73 | u16 pipenum; | 73 | u16 pipenum; |
74 | u16 type; | 74 | u16 type; |
75 | const struct usb_endpoint_descriptor *desc; | 75 | |
76 | /* register address */ | 76 | /* register address */ |
77 | unsigned char fifoaddr; | 77 | unsigned char fifoaddr; |
78 | unsigned char fifosel; | 78 | unsigned char fifosel; |
@@ -111,6 +111,7 @@ struct r8a66597 { | |||
111 | u16 old_vbus; | 111 | u16 old_vbus; |
112 | u16 scount; | 112 | u16 scount; |
113 | u16 old_dvsq; | 113 | u16 old_dvsq; |
114 | u16 device_status; /* for GET_STATUS */ | ||
114 | 115 | ||
115 | /* pipe config */ | 116 | /* pipe config */ |
116 | unsigned char bulk; | 117 | unsigned char bulk; |
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 73a934a170d1..b35babed6fcb 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -73,65 +73,65 @@ static rndis_resp_t *rndis_add_response(int configNr, u32 length); | |||
73 | static const u32 oid_supported_list[] = | 73 | static const u32 oid_supported_list[] = |
74 | { | 74 | { |
75 | /* the general stuff */ | 75 | /* the general stuff */ |
76 | OID_GEN_SUPPORTED_LIST, | 76 | RNDIS_OID_GEN_SUPPORTED_LIST, |
77 | OID_GEN_HARDWARE_STATUS, | 77 | RNDIS_OID_GEN_HARDWARE_STATUS, |
78 | OID_GEN_MEDIA_SUPPORTED, | 78 | RNDIS_OID_GEN_MEDIA_SUPPORTED, |
79 | OID_GEN_MEDIA_IN_USE, | 79 | RNDIS_OID_GEN_MEDIA_IN_USE, |
80 | OID_GEN_MAXIMUM_FRAME_SIZE, | 80 | RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE, |
81 | OID_GEN_LINK_SPEED, | 81 | RNDIS_OID_GEN_LINK_SPEED, |
82 | OID_GEN_TRANSMIT_BLOCK_SIZE, | 82 | RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE, |
83 | OID_GEN_RECEIVE_BLOCK_SIZE, | 83 | RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE, |
84 | OID_GEN_VENDOR_ID, | 84 | RNDIS_OID_GEN_VENDOR_ID, |
85 | OID_GEN_VENDOR_DESCRIPTION, | 85 | RNDIS_OID_GEN_VENDOR_DESCRIPTION, |
86 | OID_GEN_VENDOR_DRIVER_VERSION, | 86 | RNDIS_OID_GEN_VENDOR_DRIVER_VERSION, |
87 | OID_GEN_CURRENT_PACKET_FILTER, | 87 | RNDIS_OID_GEN_CURRENT_PACKET_FILTER, |
88 | OID_GEN_MAXIMUM_TOTAL_SIZE, | 88 | RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE, |
89 | OID_GEN_MEDIA_CONNECT_STATUS, | 89 | RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, |
90 | OID_GEN_PHYSICAL_MEDIUM, | 90 | RNDIS_OID_GEN_PHYSICAL_MEDIUM, |
91 | 91 | ||
92 | /* the statistical stuff */ | 92 | /* the statistical stuff */ |
93 | OID_GEN_XMIT_OK, | 93 | RNDIS_OID_GEN_XMIT_OK, |
94 | OID_GEN_RCV_OK, | 94 | RNDIS_OID_GEN_RCV_OK, |
95 | OID_GEN_XMIT_ERROR, | 95 | RNDIS_OID_GEN_XMIT_ERROR, |
96 | OID_GEN_RCV_ERROR, | 96 | RNDIS_OID_GEN_RCV_ERROR, |
97 | OID_GEN_RCV_NO_BUFFER, | 97 | RNDIS_OID_GEN_RCV_NO_BUFFER, |
98 | #ifdef RNDIS_OPTIONAL_STATS | 98 | #ifdef RNDIS_OPTIONAL_STATS |
99 | OID_GEN_DIRECTED_BYTES_XMIT, | 99 | RNDIS_OID_GEN_DIRECTED_BYTES_XMIT, |
100 | OID_GEN_DIRECTED_FRAMES_XMIT, | 100 | RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT, |
101 | OID_GEN_MULTICAST_BYTES_XMIT, | 101 | RNDIS_OID_GEN_MULTICAST_BYTES_XMIT, |
102 | OID_GEN_MULTICAST_FRAMES_XMIT, | 102 | RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT, |
103 | OID_GEN_BROADCAST_BYTES_XMIT, | 103 | RNDIS_OID_GEN_BROADCAST_BYTES_XMIT, |
104 | OID_GEN_BROADCAST_FRAMES_XMIT, | 104 | RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT, |
105 | OID_GEN_DIRECTED_BYTES_RCV, | 105 | RNDIS_OID_GEN_DIRECTED_BYTES_RCV, |
106 | OID_GEN_DIRECTED_FRAMES_RCV, | 106 | RNDIS_OID_GEN_DIRECTED_FRAMES_RCV, |
107 | OID_GEN_MULTICAST_BYTES_RCV, | 107 | RNDIS_OID_GEN_MULTICAST_BYTES_RCV, |
108 | OID_GEN_MULTICAST_FRAMES_RCV, | 108 | RNDIS_OID_GEN_MULTICAST_FRAMES_RCV, |
109 | OID_GEN_BROADCAST_BYTES_RCV, | 109 | RNDIS_OID_GEN_BROADCAST_BYTES_RCV, |
110 | OID_GEN_BROADCAST_FRAMES_RCV, | 110 | RNDIS_OID_GEN_BROADCAST_FRAMES_RCV, |
111 | OID_GEN_RCV_CRC_ERROR, | 111 | RNDIS_OID_GEN_RCV_CRC_ERROR, |
112 | OID_GEN_TRANSMIT_QUEUE_LENGTH, | 112 | RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH, |
113 | #endif /* RNDIS_OPTIONAL_STATS */ | 113 | #endif /* RNDIS_OPTIONAL_STATS */ |
114 | 114 | ||
115 | /* mandatory 802.3 */ | 115 | /* mandatory 802.3 */ |
116 | /* the general stuff */ | 116 | /* the general stuff */ |
117 | OID_802_3_PERMANENT_ADDRESS, | 117 | RNDIS_OID_802_3_PERMANENT_ADDRESS, |
118 | OID_802_3_CURRENT_ADDRESS, | 118 | RNDIS_OID_802_3_CURRENT_ADDRESS, |
119 | OID_802_3_MULTICAST_LIST, | 119 | RNDIS_OID_802_3_MULTICAST_LIST, |
120 | OID_802_3_MAC_OPTIONS, | 120 | RNDIS_OID_802_3_MAC_OPTIONS, |
121 | OID_802_3_MAXIMUM_LIST_SIZE, | 121 | RNDIS_OID_802_3_MAXIMUM_LIST_SIZE, |
122 | 122 | ||
123 | /* the statistical stuff */ | 123 | /* the statistical stuff */ |
124 | OID_802_3_RCV_ERROR_ALIGNMENT, | 124 | RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT, |
125 | OID_802_3_XMIT_ONE_COLLISION, | 125 | RNDIS_OID_802_3_XMIT_ONE_COLLISION, |
126 | OID_802_3_XMIT_MORE_COLLISIONS, | 126 | RNDIS_OID_802_3_XMIT_MORE_COLLISIONS, |
127 | #ifdef RNDIS_OPTIONAL_STATS | 127 | #ifdef RNDIS_OPTIONAL_STATS |
128 | OID_802_3_XMIT_DEFERRED, | 128 | RNDIS_OID_802_3_XMIT_DEFERRED, |
129 | OID_802_3_XMIT_MAX_COLLISIONS, | 129 | RNDIS_OID_802_3_XMIT_MAX_COLLISIONS, |
130 | OID_802_3_RCV_OVERRUN, | 130 | RNDIS_OID_802_3_RCV_OVERRUN, |
131 | OID_802_3_XMIT_UNDERRUN, | 131 | RNDIS_OID_802_3_XMIT_UNDERRUN, |
132 | OID_802_3_XMIT_HEARTBEAT_FAILURE, | 132 | RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE, |
133 | OID_802_3_XMIT_TIMES_CRS_LOST, | 133 | RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST, |
134 | OID_802_3_XMIT_LATE_COLLISIONS, | 134 | RNDIS_OID_802_3_XMIT_LATE_COLLISIONS, |
135 | #endif /* RNDIS_OPTIONAL_STATS */ | 135 | #endif /* RNDIS_OPTIONAL_STATS */ |
136 | 136 | ||
137 | #ifdef RNDIS_PM | 137 | #ifdef RNDIS_PM |
@@ -200,8 +200,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
200 | /* general oids (table 4-1) */ | 200 | /* general oids (table 4-1) */ |
201 | 201 | ||
202 | /* mandatory */ | 202 | /* mandatory */ |
203 | case OID_GEN_SUPPORTED_LIST: | 203 | case RNDIS_OID_GEN_SUPPORTED_LIST: |
204 | pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__); | 204 | pr_debug("%s: RNDIS_OID_GEN_SUPPORTED_LIST\n", __func__); |
205 | length = sizeof(oid_supported_list); | 205 | length = sizeof(oid_supported_list); |
206 | count = length / sizeof(u32); | 206 | count = length / sizeof(u32); |
207 | for (i = 0; i < count; i++) | 207 | for (i = 0; i < count; i++) |
@@ -210,8 +210,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
210 | break; | 210 | break; |
211 | 211 | ||
212 | /* mandatory */ | 212 | /* mandatory */ |
213 | case OID_GEN_HARDWARE_STATUS: | 213 | case RNDIS_OID_GEN_HARDWARE_STATUS: |
214 | pr_debug("%s: OID_GEN_HARDWARE_STATUS\n", __func__); | 214 | pr_debug("%s: RNDIS_OID_GEN_HARDWARE_STATUS\n", __func__); |
215 | /* Bogus question! | 215 | /* Bogus question! |
216 | * Hardware must be ready to receive high level protocols. | 216 | * Hardware must be ready to receive high level protocols. |
217 | * BTW: | 217 | * BTW: |
@@ -223,23 +223,23 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
223 | break; | 223 | break; |
224 | 224 | ||
225 | /* mandatory */ | 225 | /* mandatory */ |
226 | case OID_GEN_MEDIA_SUPPORTED: | 226 | case RNDIS_OID_GEN_MEDIA_SUPPORTED: |
227 | pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); | 227 | pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__); |
228 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); | 228 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); |
229 | retval = 0; | 229 | retval = 0; |
230 | break; | 230 | break; |
231 | 231 | ||
232 | /* mandatory */ | 232 | /* mandatory */ |
233 | case OID_GEN_MEDIA_IN_USE: | 233 | case RNDIS_OID_GEN_MEDIA_IN_USE: |
234 | pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__); | 234 | pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__); |
235 | /* one medium, one transport... (maybe you do it better) */ | 235 | /* one medium, one transport... (maybe you do it better) */ |
236 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); | 236 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); |
237 | retval = 0; | 237 | retval = 0; |
238 | break; | 238 | break; |
239 | 239 | ||
240 | /* mandatory */ | 240 | /* mandatory */ |
241 | case OID_GEN_MAXIMUM_FRAME_SIZE: | 241 | case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE: |
242 | pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); | 242 | pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); |
243 | if (rndis_per_dev_params[configNr].dev) { | 243 | if (rndis_per_dev_params[configNr].dev) { |
244 | *outbuf = cpu_to_le32( | 244 | *outbuf = cpu_to_le32( |
245 | rndis_per_dev_params[configNr].dev->mtu); | 245 | rndis_per_dev_params[configNr].dev->mtu); |
@@ -248,11 +248,11 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
248 | break; | 248 | break; |
249 | 249 | ||
250 | /* mandatory */ | 250 | /* mandatory */ |
251 | case OID_GEN_LINK_SPEED: | 251 | case RNDIS_OID_GEN_LINK_SPEED: |
252 | if (rndis_debug > 1) | 252 | if (rndis_debug > 1) |
253 | pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__); | 253 | pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__); |
254 | if (rndis_per_dev_params[configNr].media_state | 254 | if (rndis_per_dev_params[configNr].media_state |
255 | == NDIS_MEDIA_STATE_DISCONNECTED) | 255 | == RNDIS_MEDIA_STATE_DISCONNECTED) |
256 | *outbuf = cpu_to_le32(0); | 256 | *outbuf = cpu_to_le32(0); |
257 | else | 257 | else |
258 | *outbuf = cpu_to_le32( | 258 | *outbuf = cpu_to_le32( |
@@ -261,8 +261,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
261 | break; | 261 | break; |
262 | 262 | ||
263 | /* mandatory */ | 263 | /* mandatory */ |
264 | case OID_GEN_TRANSMIT_BLOCK_SIZE: | 264 | case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE: |
265 | pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); | 265 | pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); |
266 | if (rndis_per_dev_params[configNr].dev) { | 266 | if (rndis_per_dev_params[configNr].dev) { |
267 | *outbuf = cpu_to_le32( | 267 | *outbuf = cpu_to_le32( |
268 | rndis_per_dev_params[configNr].dev->mtu); | 268 | rndis_per_dev_params[configNr].dev->mtu); |
@@ -271,8 +271,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
271 | break; | 271 | break; |
272 | 272 | ||
273 | /* mandatory */ | 273 | /* mandatory */ |
274 | case OID_GEN_RECEIVE_BLOCK_SIZE: | 274 | case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE: |
275 | pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); | 275 | pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); |
276 | if (rndis_per_dev_params[configNr].dev) { | 276 | if (rndis_per_dev_params[configNr].dev) { |
277 | *outbuf = cpu_to_le32( | 277 | *outbuf = cpu_to_le32( |
278 | rndis_per_dev_params[configNr].dev->mtu); | 278 | rndis_per_dev_params[configNr].dev->mtu); |
@@ -281,16 +281,16 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
281 | break; | 281 | break; |
282 | 282 | ||
283 | /* mandatory */ | 283 | /* mandatory */ |
284 | case OID_GEN_VENDOR_ID: | 284 | case RNDIS_OID_GEN_VENDOR_ID: |
285 | pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__); | 285 | pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__); |
286 | *outbuf = cpu_to_le32( | 286 | *outbuf = cpu_to_le32( |
287 | rndis_per_dev_params[configNr].vendorID); | 287 | rndis_per_dev_params[configNr].vendorID); |
288 | retval = 0; | 288 | retval = 0; |
289 | break; | 289 | break; |
290 | 290 | ||
291 | /* mandatory */ | 291 | /* mandatory */ |
292 | case OID_GEN_VENDOR_DESCRIPTION: | 292 | case RNDIS_OID_GEN_VENDOR_DESCRIPTION: |
293 | pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); | 293 | pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__); |
294 | if (rndis_per_dev_params[configNr].vendorDescr) { | 294 | if (rndis_per_dev_params[configNr].vendorDescr) { |
295 | length = strlen(rndis_per_dev_params[configNr]. | 295 | length = strlen(rndis_per_dev_params[configNr]. |
296 | vendorDescr); | 296 | vendorDescr); |
@@ -303,38 +303,38 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
303 | retval = 0; | 303 | retval = 0; |
304 | break; | 304 | break; |
305 | 305 | ||
306 | case OID_GEN_VENDOR_DRIVER_VERSION: | 306 | case RNDIS_OID_GEN_VENDOR_DRIVER_VERSION: |
307 | pr_debug("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); | 307 | pr_debug("%s: RNDIS_OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); |
308 | /* Created as LE */ | 308 | /* Created as LE */ |
309 | *outbuf = rndis_driver_version; | 309 | *outbuf = rndis_driver_version; |
310 | retval = 0; | 310 | retval = 0; |
311 | break; | 311 | break; |
312 | 312 | ||
313 | /* mandatory */ | 313 | /* mandatory */ |
314 | case OID_GEN_CURRENT_PACKET_FILTER: | 314 | case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: |
315 | pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); | 315 | pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__); |
316 | *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter); | 316 | *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter); |
317 | retval = 0; | 317 | retval = 0; |
318 | break; | 318 | break; |
319 | 319 | ||
320 | /* mandatory */ | 320 | /* mandatory */ |
321 | case OID_GEN_MAXIMUM_TOTAL_SIZE: | 321 | case RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE: |
322 | pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); | 322 | pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); |
323 | *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); | 323 | *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); |
324 | retval = 0; | 324 | retval = 0; |
325 | break; | 325 | break; |
326 | 326 | ||
327 | /* mandatory */ | 327 | /* mandatory */ |
328 | case OID_GEN_MEDIA_CONNECT_STATUS: | 328 | case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS: |
329 | if (rndis_debug > 1) | 329 | if (rndis_debug > 1) |
330 | pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); | 330 | pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); |
331 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr] | 331 | *outbuf = cpu_to_le32(rndis_per_dev_params[configNr] |
332 | .media_state); | 332 | .media_state); |
333 | retval = 0; | 333 | retval = 0; |
334 | break; | 334 | break; |
335 | 335 | ||
336 | case OID_GEN_PHYSICAL_MEDIUM: | 336 | case RNDIS_OID_GEN_PHYSICAL_MEDIUM: |
337 | pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); | 337 | pr_debug("%s: RNDIS_OID_GEN_PHYSICAL_MEDIUM\n", __func__); |
338 | *outbuf = cpu_to_le32(0); | 338 | *outbuf = cpu_to_le32(0); |
339 | retval = 0; | 339 | retval = 0; |
340 | break; | 340 | break; |
@@ -343,20 +343,20 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
343 | * of MS-Windows expect OIDs that aren't specified there. Other | 343 | * of MS-Windows expect OIDs that aren't specified there. Other |
344 | * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! | 344 | * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! |
345 | */ | 345 | */ |
346 | case OID_GEN_MAC_OPTIONS: /* from WinME */ | 346 | case RNDIS_OID_GEN_MAC_OPTIONS: /* from WinME */ |
347 | pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__); | 347 | pr_debug("%s: RNDIS_OID_GEN_MAC_OPTIONS\n", __func__); |
348 | *outbuf = cpu_to_le32( | 348 | *outbuf = cpu_to_le32( |
349 | NDIS_MAC_OPTION_RECEIVE_SERIALIZED | 349 | RNDIS_MAC_OPTION_RECEIVE_SERIALIZED |
350 | | NDIS_MAC_OPTION_FULL_DUPLEX); | 350 | | RNDIS_MAC_OPTION_FULL_DUPLEX); |
351 | retval = 0; | 351 | retval = 0; |
352 | break; | 352 | break; |
353 | 353 | ||
354 | /* statistics OIDs (table 4-2) */ | 354 | /* statistics OIDs (table 4-2) */ |
355 | 355 | ||
356 | /* mandatory */ | 356 | /* mandatory */ |
357 | case OID_GEN_XMIT_OK: | 357 | case RNDIS_OID_GEN_XMIT_OK: |
358 | if (rndis_debug > 1) | 358 | if (rndis_debug > 1) |
359 | pr_debug("%s: OID_GEN_XMIT_OK\n", __func__); | 359 | pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__); |
360 | if (stats) { | 360 | if (stats) { |
361 | *outbuf = cpu_to_le32(stats->tx_packets | 361 | *outbuf = cpu_to_le32(stats->tx_packets |
362 | - stats->tx_errors - stats->tx_dropped); | 362 | - stats->tx_errors - stats->tx_dropped); |
@@ -365,9 +365,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
365 | break; | 365 | break; |
366 | 366 | ||
367 | /* mandatory */ | 367 | /* mandatory */ |
368 | case OID_GEN_RCV_OK: | 368 | case RNDIS_OID_GEN_RCV_OK: |
369 | if (rndis_debug > 1) | 369 | if (rndis_debug > 1) |
370 | pr_debug("%s: OID_GEN_RCV_OK\n", __func__); | 370 | pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__); |
371 | if (stats) { | 371 | if (stats) { |
372 | *outbuf = cpu_to_le32(stats->rx_packets | 372 | *outbuf = cpu_to_le32(stats->rx_packets |
373 | - stats->rx_errors - stats->rx_dropped); | 373 | - stats->rx_errors - stats->rx_dropped); |
@@ -376,9 +376,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
376 | break; | 376 | break; |
377 | 377 | ||
378 | /* mandatory */ | 378 | /* mandatory */ |
379 | case OID_GEN_XMIT_ERROR: | 379 | case RNDIS_OID_GEN_XMIT_ERROR: |
380 | if (rndis_debug > 1) | 380 | if (rndis_debug > 1) |
381 | pr_debug("%s: OID_GEN_XMIT_ERROR\n", __func__); | 381 | pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__); |
382 | if (stats) { | 382 | if (stats) { |
383 | *outbuf = cpu_to_le32(stats->tx_errors); | 383 | *outbuf = cpu_to_le32(stats->tx_errors); |
384 | retval = 0; | 384 | retval = 0; |
@@ -386,9 +386,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
386 | break; | 386 | break; |
387 | 387 | ||
388 | /* mandatory */ | 388 | /* mandatory */ |
389 | case OID_GEN_RCV_ERROR: | 389 | case RNDIS_OID_GEN_RCV_ERROR: |
390 | if (rndis_debug > 1) | 390 | if (rndis_debug > 1) |
391 | pr_debug("%s: OID_GEN_RCV_ERROR\n", __func__); | 391 | pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__); |
392 | if (stats) { | 392 | if (stats) { |
393 | *outbuf = cpu_to_le32(stats->rx_errors); | 393 | *outbuf = cpu_to_le32(stats->rx_errors); |
394 | retval = 0; | 394 | retval = 0; |
@@ -396,8 +396,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
396 | break; | 396 | break; |
397 | 397 | ||
398 | /* mandatory */ | 398 | /* mandatory */ |
399 | case OID_GEN_RCV_NO_BUFFER: | 399 | case RNDIS_OID_GEN_RCV_NO_BUFFER: |
400 | pr_debug("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); | 400 | pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__); |
401 | if (stats) { | 401 | if (stats) { |
402 | *outbuf = cpu_to_le32(stats->rx_dropped); | 402 | *outbuf = cpu_to_le32(stats->rx_dropped); |
403 | retval = 0; | 403 | retval = 0; |
@@ -407,8 +407,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
407 | /* ieee802.3 OIDs (table 4-3) */ | 407 | /* ieee802.3 OIDs (table 4-3) */ |
408 | 408 | ||
409 | /* mandatory */ | 409 | /* mandatory */ |
410 | case OID_802_3_PERMANENT_ADDRESS: | 410 | case RNDIS_OID_802_3_PERMANENT_ADDRESS: |
411 | pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); | 411 | pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__); |
412 | if (rndis_per_dev_params[configNr].dev) { | 412 | if (rndis_per_dev_params[configNr].dev) { |
413 | length = ETH_ALEN; | 413 | length = ETH_ALEN; |
414 | memcpy(outbuf, | 414 | memcpy(outbuf, |
@@ -419,8 +419,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
419 | break; | 419 | break; |
420 | 420 | ||
421 | /* mandatory */ | 421 | /* mandatory */ |
422 | case OID_802_3_CURRENT_ADDRESS: | 422 | case RNDIS_OID_802_3_CURRENT_ADDRESS: |
423 | pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); | 423 | pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__); |
424 | if (rndis_per_dev_params[configNr].dev) { | 424 | if (rndis_per_dev_params[configNr].dev) { |
425 | length = ETH_ALEN; | 425 | length = ETH_ALEN; |
426 | memcpy(outbuf, | 426 | memcpy(outbuf, |
@@ -431,23 +431,23 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
431 | break; | 431 | break; |
432 | 432 | ||
433 | /* mandatory */ | 433 | /* mandatory */ |
434 | case OID_802_3_MULTICAST_LIST: | 434 | case RNDIS_OID_802_3_MULTICAST_LIST: |
435 | pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 435 | pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__); |
436 | /* Multicast base address only */ | 436 | /* Multicast base address only */ |
437 | *outbuf = cpu_to_le32(0xE0000000); | 437 | *outbuf = cpu_to_le32(0xE0000000); |
438 | retval = 0; | 438 | retval = 0; |
439 | break; | 439 | break; |
440 | 440 | ||
441 | /* mandatory */ | 441 | /* mandatory */ |
442 | case OID_802_3_MAXIMUM_LIST_SIZE: | 442 | case RNDIS_OID_802_3_MAXIMUM_LIST_SIZE: |
443 | pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); | 443 | pr_debug("%s: RNDIS_OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); |
444 | /* Multicast base address only */ | 444 | /* Multicast base address only */ |
445 | *outbuf = cpu_to_le32(1); | 445 | *outbuf = cpu_to_le32(1); |
446 | retval = 0; | 446 | retval = 0; |
447 | break; | 447 | break; |
448 | 448 | ||
449 | case OID_802_3_MAC_OPTIONS: | 449 | case RNDIS_OID_802_3_MAC_OPTIONS: |
450 | pr_debug("%s: OID_802_3_MAC_OPTIONS\n", __func__); | 450 | pr_debug("%s: RNDIS_OID_802_3_MAC_OPTIONS\n", __func__); |
451 | *outbuf = cpu_to_le32(0); | 451 | *outbuf = cpu_to_le32(0); |
452 | retval = 0; | 452 | retval = 0; |
453 | break; | 453 | break; |
@@ -455,8 +455,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
455 | /* ieee802.3 statistics OIDs (table 4-4) */ | 455 | /* ieee802.3 statistics OIDs (table 4-4) */ |
456 | 456 | ||
457 | /* mandatory */ | 457 | /* mandatory */ |
458 | case OID_802_3_RCV_ERROR_ALIGNMENT: | 458 | case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT: |
459 | pr_debug("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); | 459 | pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); |
460 | if (stats) { | 460 | if (stats) { |
461 | *outbuf = cpu_to_le32(stats->rx_frame_errors); | 461 | *outbuf = cpu_to_le32(stats->rx_frame_errors); |
462 | retval = 0; | 462 | retval = 0; |
@@ -464,15 +464,15 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, | |||
464 | break; | 464 | break; |
465 | 465 | ||
466 | /* mandatory */ | 466 | /* mandatory */ |
467 | case OID_802_3_XMIT_ONE_COLLISION: | 467 | case RNDIS_OID_802_3_XMIT_ONE_COLLISION: |
468 | pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); | 468 | pr_debug("%s: RNDIS_OID_802_3_XMIT_ONE_COLLISION\n", __func__); |
469 | *outbuf = cpu_to_le32(0); | 469 | *outbuf = cpu_to_le32(0); |
470 | retval = 0; | 470 | retval = 0; |
471 | break; | 471 | break; |
472 | 472 | ||
473 | /* mandatory */ | 473 | /* mandatory */ |
474 | case OID_802_3_XMIT_MORE_COLLISIONS: | 474 | case RNDIS_OID_802_3_XMIT_MORE_COLLISIONS: |
475 | pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); | 475 | pr_debug("%s: RNDIS_OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); |
476 | *outbuf = cpu_to_le32(0); | 476 | *outbuf = cpu_to_le32(0); |
477 | retval = 0; | 477 | retval = 0; |
478 | break; | 478 | break; |
@@ -516,7 +516,7 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
516 | 516 | ||
517 | params = &rndis_per_dev_params[configNr]; | 517 | params = &rndis_per_dev_params[configNr]; |
518 | switch (OID) { | 518 | switch (OID) { |
519 | case OID_GEN_CURRENT_PACKET_FILTER: | 519 | case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: |
520 | 520 | ||
521 | /* these NDIS_PACKET_TYPE_* bitflags are shared with | 521 | /* these NDIS_PACKET_TYPE_* bitflags are shared with |
522 | * cdc_filter; it's not RNDIS-specific | 522 | * cdc_filter; it's not RNDIS-specific |
@@ -525,7 +525,7 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
525 | * MULTICAST, ALL_MULTICAST, BROADCAST | 525 | * MULTICAST, ALL_MULTICAST, BROADCAST |
526 | */ | 526 | */ |
527 | *params->filter = (u16)get_unaligned_le32(buf); | 527 | *params->filter = (u16)get_unaligned_le32(buf); |
528 | pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", | 528 | pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER %08x\n", |
529 | __func__, *params->filter); | 529 | __func__, *params->filter); |
530 | 530 | ||
531 | /* this call has a significant side effect: it's | 531 | /* this call has a significant side effect: it's |
@@ -545,9 +545,9 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, | |||
545 | } | 545 | } |
546 | break; | 546 | break; |
547 | 547 | ||
548 | case OID_802_3_MULTICAST_LIST: | 548 | case RNDIS_OID_802_3_MULTICAST_LIST: |
549 | /* I think we can ignore this */ | 549 | /* I think we can ignore this */ |
550 | pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 550 | pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__); |
551 | retval = 0; | 551 | retval = 0; |
552 | break; | 552 | break; |
553 | 553 | ||
@@ -577,7 +577,7 @@ static int rndis_init_response(int configNr, rndis_init_msg_type *buf) | |||
577 | return -ENOMEM; | 577 | return -ENOMEM; |
578 | resp = (rndis_init_cmplt_type *)r->buf; | 578 | resp = (rndis_init_cmplt_type *)r->buf; |
579 | 579 | ||
580 | resp->MessageType = cpu_to_le32(REMOTE_NDIS_INITIALIZE_CMPLT); | 580 | resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C); |
581 | resp->MessageLength = cpu_to_le32(52); | 581 | resp->MessageLength = cpu_to_le32(52); |
582 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 582 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
583 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); | 583 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
@@ -621,7 +621,7 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf) | |||
621 | return -ENOMEM; | 621 | return -ENOMEM; |
622 | resp = (rndis_query_cmplt_type *)r->buf; | 622 | resp = (rndis_query_cmplt_type *)r->buf; |
623 | 623 | ||
624 | resp->MessageType = cpu_to_le32(REMOTE_NDIS_QUERY_CMPLT); | 624 | resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C); |
625 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 625 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
626 | 626 | ||
627 | if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID), | 627 | if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID), |
@@ -668,7 +668,7 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf) | |||
668 | pr_debug("\n"); | 668 | pr_debug("\n"); |
669 | #endif | 669 | #endif |
670 | 670 | ||
671 | resp->MessageType = cpu_to_le32(REMOTE_NDIS_SET_CMPLT); | 671 | resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C); |
672 | resp->MessageLength = cpu_to_le32(16); | 672 | resp->MessageLength = cpu_to_le32(16); |
673 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 673 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
674 | if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID), | 674 | if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID), |
@@ -692,7 +692,7 @@ static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf) | |||
692 | return -ENOMEM; | 692 | return -ENOMEM; |
693 | resp = (rndis_reset_cmplt_type *)r->buf; | 693 | resp = (rndis_reset_cmplt_type *)r->buf; |
694 | 694 | ||
695 | resp->MessageType = cpu_to_le32(REMOTE_NDIS_RESET_CMPLT); | 695 | resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C); |
696 | resp->MessageLength = cpu_to_le32(16); | 696 | resp->MessageLength = cpu_to_le32(16); |
697 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); | 697 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
698 | /* resent information */ | 698 | /* resent information */ |
@@ -716,8 +716,7 @@ static int rndis_keepalive_response(int configNr, | |||
716 | return -ENOMEM; | 716 | return -ENOMEM; |
717 | resp = (rndis_keepalive_cmplt_type *)r->buf; | 717 | resp = (rndis_keepalive_cmplt_type *)r->buf; |
718 | 718 | ||
719 | resp->MessageType = cpu_to_le32( | 719 | resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C); |
720 | REMOTE_NDIS_KEEPALIVE_CMPLT); | ||
721 | resp->MessageLength = cpu_to_le32(16); | 720 | resp->MessageLength = cpu_to_le32(16); |
722 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 721 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
723 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); | 722 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
@@ -745,7 +744,7 @@ static int rndis_indicate_status_msg(int configNr, u32 status) | |||
745 | return -ENOMEM; | 744 | return -ENOMEM; |
746 | resp = (rndis_indicate_status_msg_type *)r->buf; | 745 | resp = (rndis_indicate_status_msg_type *)r->buf; |
747 | 746 | ||
748 | resp->MessageType = cpu_to_le32(REMOTE_NDIS_INDICATE_STATUS_MSG); | 747 | resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE); |
749 | resp->MessageLength = cpu_to_le32(20); | 748 | resp->MessageLength = cpu_to_le32(20); |
750 | resp->Status = cpu_to_le32(status); | 749 | resp->Status = cpu_to_le32(status); |
751 | resp->StatusBufferLength = cpu_to_le32(0); | 750 | resp->StatusBufferLength = cpu_to_le32(0); |
@@ -758,7 +757,7 @@ static int rndis_indicate_status_msg(int configNr, u32 status) | |||
758 | int rndis_signal_connect(int configNr) | 757 | int rndis_signal_connect(int configNr) |
759 | { | 758 | { |
760 | rndis_per_dev_params[configNr].media_state | 759 | rndis_per_dev_params[configNr].media_state |
761 | = NDIS_MEDIA_STATE_CONNECTED; | 760 | = RNDIS_MEDIA_STATE_CONNECTED; |
762 | return rndis_indicate_status_msg(configNr, | 761 | return rndis_indicate_status_msg(configNr, |
763 | RNDIS_STATUS_MEDIA_CONNECT); | 762 | RNDIS_STATUS_MEDIA_CONNECT); |
764 | } | 763 | } |
@@ -766,7 +765,7 @@ int rndis_signal_connect(int configNr) | |||
766 | int rndis_signal_disconnect(int configNr) | 765 | int rndis_signal_disconnect(int configNr) |
767 | { | 766 | { |
768 | rndis_per_dev_params[configNr].media_state | 767 | rndis_per_dev_params[configNr].media_state |
769 | = NDIS_MEDIA_STATE_DISCONNECTED; | 768 | = RNDIS_MEDIA_STATE_DISCONNECTED; |
770 | return rndis_indicate_status_msg(configNr, | 769 | return rndis_indicate_status_msg(configNr, |
771 | RNDIS_STATUS_MEDIA_DISCONNECT); | 770 | RNDIS_STATUS_MEDIA_DISCONNECT); |
772 | } | 771 | } |
@@ -817,15 +816,15 @@ int rndis_msg_parser(u8 configNr, u8 *buf) | |||
817 | 816 | ||
818 | /* For USB: responses may take up to 10 seconds */ | 817 | /* For USB: responses may take up to 10 seconds */ |
819 | switch (MsgType) { | 818 | switch (MsgType) { |
820 | case REMOTE_NDIS_INITIALIZE_MSG: | 819 | case RNDIS_MSG_INIT: |
821 | pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n", | 820 | pr_debug("%s: RNDIS_MSG_INIT\n", |
822 | __func__); | 821 | __func__); |
823 | params->state = RNDIS_INITIALIZED; | 822 | params->state = RNDIS_INITIALIZED; |
824 | return rndis_init_response(configNr, | 823 | return rndis_init_response(configNr, |
825 | (rndis_init_msg_type *)buf); | 824 | (rndis_init_msg_type *)buf); |
826 | 825 | ||
827 | case REMOTE_NDIS_HALT_MSG: | 826 | case RNDIS_MSG_HALT: |
828 | pr_debug("%s: REMOTE_NDIS_HALT_MSG\n", | 827 | pr_debug("%s: RNDIS_MSG_HALT\n", |
829 | __func__); | 828 | __func__); |
830 | params->state = RNDIS_UNINITIALIZED; | 829 | params->state = RNDIS_UNINITIALIZED; |
831 | if (params->dev) { | 830 | if (params->dev) { |
@@ -834,24 +833,24 @@ int rndis_msg_parser(u8 configNr, u8 *buf) | |||
834 | } | 833 | } |
835 | return 0; | 834 | return 0; |
836 | 835 | ||
837 | case REMOTE_NDIS_QUERY_MSG: | 836 | case RNDIS_MSG_QUERY: |
838 | return rndis_query_response(configNr, | 837 | return rndis_query_response(configNr, |
839 | (rndis_query_msg_type *)buf); | 838 | (rndis_query_msg_type *)buf); |
840 | 839 | ||
841 | case REMOTE_NDIS_SET_MSG: | 840 | case RNDIS_MSG_SET: |
842 | return rndis_set_response(configNr, | 841 | return rndis_set_response(configNr, |
843 | (rndis_set_msg_type *)buf); | 842 | (rndis_set_msg_type *)buf); |
844 | 843 | ||
845 | case REMOTE_NDIS_RESET_MSG: | 844 | case RNDIS_MSG_RESET: |
846 | pr_debug("%s: REMOTE_NDIS_RESET_MSG\n", | 845 | pr_debug("%s: RNDIS_MSG_RESET\n", |
847 | __func__); | 846 | __func__); |
848 | return rndis_reset_response(configNr, | 847 | return rndis_reset_response(configNr, |
849 | (rndis_reset_msg_type *)buf); | 848 | (rndis_reset_msg_type *)buf); |
850 | 849 | ||
851 | case REMOTE_NDIS_KEEPALIVE_MSG: | 850 | case RNDIS_MSG_KEEPALIVE: |
852 | /* For USB: host does this every 5 seconds */ | 851 | /* For USB: host does this every 5 seconds */ |
853 | if (rndis_debug > 1) | 852 | if (rndis_debug > 1) |
854 | pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", | 853 | pr_debug("%s: RNDIS_MSG_KEEPALIVE\n", |
855 | __func__); | 854 | __func__); |
856 | return rndis_keepalive_response(configNr, | 855 | return rndis_keepalive_response(configNr, |
857 | (rndis_keepalive_msg_type *) | 856 | (rndis_keepalive_msg_type *) |
@@ -963,7 +962,7 @@ void rndis_add_hdr(struct sk_buff *skb) | |||
963 | return; | 962 | return; |
964 | header = (void *)skb_push(skb, sizeof(*header)); | 963 | header = (void *)skb_push(skb, sizeof(*header)); |
965 | memset(header, 0, sizeof *header); | 964 | memset(header, 0, sizeof *header); |
966 | header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG); | 965 | header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET); |
967 | header->MessageLength = cpu_to_le32(skb->len); | 966 | header->MessageLength = cpu_to_le32(skb->len); |
968 | header->DataOffset = cpu_to_le32(36); | 967 | header->DataOffset = cpu_to_le32(36); |
969 | header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); | 968 | header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); |
@@ -1031,7 +1030,7 @@ int rndis_rm_hdr(struct gether *port, | |||
1031 | __le32 *tmp = (void *)skb->data; | 1030 | __le32 *tmp = (void *)skb->data; |
1032 | 1031 | ||
1033 | /* MessageType, MessageLength */ | 1032 | /* MessageType, MessageLength */ |
1034 | if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) | 1033 | if (cpu_to_le32(RNDIS_MSG_PACKET) |
1035 | != get_unaligned(tmp++)) { | 1034 | != get_unaligned(tmp++)) { |
1036 | dev_kfree_skb_any(skb); | 1035 | dev_kfree_skb_any(skb); |
1037 | return -EINVAL; | 1036 | return -EINVAL; |
@@ -1173,7 +1172,7 @@ int rndis_init(void) | |||
1173 | rndis_per_dev_params[i].used = 0; | 1172 | rndis_per_dev_params[i].used = 0; |
1174 | rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED; | 1173 | rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED; |
1175 | rndis_per_dev_params[i].media_state | 1174 | rndis_per_dev_params[i].media_state |
1176 | = NDIS_MEDIA_STATE_DISCONNECTED; | 1175 | = RNDIS_MEDIA_STATE_DISCONNECTED; |
1177 | INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue)); | 1176 | INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue)); |
1178 | } | 1177 | } |
1179 | 1178 | ||
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 907c33008118..0647f2f34e89 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h | |||
@@ -15,58 +15,12 @@ | |||
15 | #ifndef _LINUX_RNDIS_H | 15 | #ifndef _LINUX_RNDIS_H |
16 | #define _LINUX_RNDIS_H | 16 | #define _LINUX_RNDIS_H |
17 | 17 | ||
18 | #include <linux/rndis.h> | ||
18 | #include "ndis.h" | 19 | #include "ndis.h" |
19 | 20 | ||
20 | #define RNDIS_MAXIMUM_FRAME_SIZE 1518 | 21 | #define RNDIS_MAXIMUM_FRAME_SIZE 1518 |
21 | #define RNDIS_MAX_TOTAL_SIZE 1558 | 22 | #define RNDIS_MAX_TOTAL_SIZE 1558 |
22 | 23 | ||
23 | /* Remote NDIS Versions */ | ||
24 | #define RNDIS_MAJOR_VERSION 1 | ||
25 | #define RNDIS_MINOR_VERSION 0 | ||
26 | |||
27 | /* Status Values */ | ||
28 | #define RNDIS_STATUS_SUCCESS 0x00000000U /* Success */ | ||
29 | #define RNDIS_STATUS_FAILURE 0xC0000001U /* Unspecified error */ | ||
30 | #define RNDIS_STATUS_INVALID_DATA 0xC0010015U /* Invalid data */ | ||
31 | #define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBU /* Unsupported request */ | ||
32 | #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000BU /* Device connected */ | ||
33 | #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CU /* Device disconnected */ | ||
34 | /* For all not specified status messages: | ||
35 | * RNDIS_STATUS_Xxx -> NDIS_STATUS_Xxx | ||
36 | */ | ||
37 | |||
38 | /* Message Set for Connectionless (802.3) Devices */ | ||
39 | #define REMOTE_NDIS_PACKET_MSG 0x00000001U | ||
40 | #define REMOTE_NDIS_INITIALIZE_MSG 0x00000002U /* Initialize device */ | ||
41 | #define REMOTE_NDIS_HALT_MSG 0x00000003U | ||
42 | #define REMOTE_NDIS_QUERY_MSG 0x00000004U | ||
43 | #define REMOTE_NDIS_SET_MSG 0x00000005U | ||
44 | #define REMOTE_NDIS_RESET_MSG 0x00000006U | ||
45 | #define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007U | ||
46 | #define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008U | ||
47 | |||
48 | /* Message completion */ | ||
49 | #define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002U | ||
50 | #define REMOTE_NDIS_QUERY_CMPLT 0x80000004U | ||
51 | #define REMOTE_NDIS_SET_CMPLT 0x80000005U | ||
52 | #define REMOTE_NDIS_RESET_CMPLT 0x80000006U | ||
53 | #define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008U | ||
54 | |||
55 | /* Device Flags */ | ||
56 | #define RNDIS_DF_CONNECTIONLESS 0x00000001U | ||
57 | #define RNDIS_DF_CONNECTION_ORIENTED 0x00000002U | ||
58 | |||
59 | #define RNDIS_MEDIUM_802_3 0x00000000U | ||
60 | |||
61 | /* from drivers/net/sk98lin/h/skgepnmi.h */ | ||
62 | #define OID_PNP_CAPABILITIES 0xFD010100 | ||
63 | #define OID_PNP_SET_POWER 0xFD010101 | ||
64 | #define OID_PNP_QUERY_POWER 0xFD010102 | ||
65 | #define OID_PNP_ADD_WAKE_UP_PATTERN 0xFD010103 | ||
66 | #define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xFD010104 | ||
67 | #define OID_PNP_ENABLE_WAKE_UP 0xFD010106 | ||
68 | |||
69 | |||
70 | typedef struct rndis_init_msg_type | 24 | typedef struct rndis_init_msg_type |
71 | { | 25 | { |
72 | __le32 MessageType; | 26 | __le32 MessageType; |
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index 105b206cd844..f4abb0ed9872 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/gadget/s3c-hsotg.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* linux/drivers/usb/gadget/s3c-hsotg.c | 1 | /** |
2 | * linux/drivers/usb/gadget/s3c-hsotg.c | ||
2 | * | 3 | * |
3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
4 | * http://www.samsung.com | 5 | * http://www.samsung.com |
@@ -13,7 +14,7 @@ | |||
13 | * This program is free software; you can redistribute it and/or modify | 14 | * This program is free software; you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License version 2 as | 15 | * it under the terms of the GNU General Public License version 2 as |
15 | * published by the Free Software Foundation. | 16 | * published by the Free Software Foundation. |
16 | */ | 17 | */ |
17 | 18 | ||
18 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
@@ -27,21 +28,25 @@ | |||
27 | #include <linux/io.h> | 28 | #include <linux/io.h> |
28 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
29 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #include <linux/regulator/consumer.h> | ||
30 | 32 | ||
31 | #include <linux/usb/ch9.h> | 33 | #include <linux/usb/ch9.h> |
32 | #include <linux/usb/gadget.h> | 34 | #include <linux/usb/gadget.h> |
35 | #include <linux/platform_data/s3c-hsotg.h> | ||
33 | 36 | ||
34 | #include <mach/map.h> | 37 | #include <mach/map.h> |
35 | 38 | ||
36 | #include <plat/regs-usb-hsotg-phy.h> | 39 | #include "s3c-hsotg.h" |
37 | #include <plat/regs-usb-hsotg.h> | ||
38 | #include <mach/regs-sys.h> | ||
39 | #include <plat/udc-hs.h> | ||
40 | #include <plat/cpu.h> | ||
41 | 40 | ||
42 | #define DMA_ADDR_INVALID (~((dma_addr_t)0)) | 41 | #define DMA_ADDR_INVALID (~((dma_addr_t)0)) |
43 | 42 | ||
44 | /* EP0_MPS_LIMIT | 43 | static const char * const s3c_hsotg_supply_names[] = { |
44 | "vusb_d", /* digital USB supply, 1.2V */ | ||
45 | "vusb_a", /* analog USB supply, 1.1V */ | ||
46 | }; | ||
47 | |||
48 | /* | ||
49 | * EP0_MPS_LIMIT | ||
45 | * | 50 | * |
46 | * Unfortunately there seems to be a limit of the amount of data that can | 51 | * Unfortunately there seems to be a limit of the amount of data that can |
47 | * be transferred by IN transactions on EP0. This is either 127 bytes or 3 | 52 | * be transferred by IN transactions on EP0. This is either 127 bytes or 3 |
@@ -125,8 +130,6 @@ struct s3c_hsotg_ep { | |||
125 | char name[10]; | 130 | char name[10]; |
126 | }; | 131 | }; |
127 | 132 | ||
128 | #define S3C_HSOTG_EPS (8+1) /* limit to 9 for the moment */ | ||
129 | |||
130 | /** | 133 | /** |
131 | * struct s3c_hsotg - driver state. | 134 | * struct s3c_hsotg - driver state. |
132 | * @dev: The parent device supplied to the probe function | 135 | * @dev: The parent device supplied to the probe function |
@@ -135,7 +138,9 @@ struct s3c_hsotg_ep { | |||
135 | * @regs: The memory area mapped for accessing registers. | 138 | * @regs: The memory area mapped for accessing registers. |
136 | * @regs_res: The resource that was allocated when claiming register space. | 139 | * @regs_res: The resource that was allocated when claiming register space. |
137 | * @irq: The IRQ number we are using | 140 | * @irq: The IRQ number we are using |
141 | * @supplies: Definition of USB power supplies | ||
138 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | 142 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. |
143 | * @num_of_eps: Number of available EPs (excluding EP0) | ||
139 | * @debug_root: root directrory for debugfs. | 144 | * @debug_root: root directrory for debugfs. |
140 | * @debug_file: main status file for debugfs. | 145 | * @debug_file: main status file for debugfs. |
141 | * @debug_fifo: FIFO status file for debugfs. | 146 | * @debug_fifo: FIFO status file for debugfs. |
@@ -143,6 +148,8 @@ struct s3c_hsotg_ep { | |||
143 | * @ep0_buff: Buffer for EP0 reply data, if needed. | 148 | * @ep0_buff: Buffer for EP0 reply data, if needed. |
144 | * @ctrl_buff: Buffer for EP0 control requests. | 149 | * @ctrl_buff: Buffer for EP0 control requests. |
145 | * @ctrl_req: Request for EP0 control packets. | 150 | * @ctrl_req: Request for EP0 control packets. |
151 | * @setup: NAK management for EP0 SETUP | ||
152 | * @last_rst: Time of last reset | ||
146 | * @eps: The endpoints being supplied to the gadget framework | 153 | * @eps: The endpoints being supplied to the gadget framework |
147 | */ | 154 | */ |
148 | struct s3c_hsotg { | 155 | struct s3c_hsotg { |
@@ -155,7 +162,10 @@ struct s3c_hsotg { | |||
155 | int irq; | 162 | int irq; |
156 | struct clk *clk; | 163 | struct clk *clk; |
157 | 164 | ||
165 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | ||
166 | |||
158 | unsigned int dedicated_fifos:1; | 167 | unsigned int dedicated_fifos:1; |
168 | unsigned char num_of_eps; | ||
159 | 169 | ||
160 | struct dentry *debug_root; | 170 | struct dentry *debug_root; |
161 | struct dentry *debug_file; | 171 | struct dentry *debug_file; |
@@ -167,7 +177,9 @@ struct s3c_hsotg { | |||
167 | u8 ctrl_buff[8]; | 177 | u8 ctrl_buff[8]; |
168 | 178 | ||
169 | struct usb_gadget gadget; | 179 | struct usb_gadget gadget; |
170 | struct s3c_hsotg_ep eps[]; | 180 | unsigned int setup; |
181 | unsigned long last_rst; | ||
182 | struct s3c_hsotg_ep *eps; | ||
171 | }; | 183 | }; |
172 | 184 | ||
173 | /** | 185 | /** |
@@ -244,14 +256,14 @@ static inline bool using_dma(struct s3c_hsotg *hsotg) | |||
244 | */ | 256 | */ |
245 | static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) | 257 | static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) |
246 | { | 258 | { |
247 | u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK); | 259 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
248 | u32 new_gsintmsk; | 260 | u32 new_gsintmsk; |
249 | 261 | ||
250 | new_gsintmsk = gsintmsk | ints; | 262 | new_gsintmsk = gsintmsk | ints; |
251 | 263 | ||
252 | if (new_gsintmsk != gsintmsk) { | 264 | if (new_gsintmsk != gsintmsk) { |
253 | dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); | 265 | dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk); |
254 | writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK); | 266 | writel(new_gsintmsk, hsotg->regs + GINTMSK); |
255 | } | 267 | } |
256 | } | 268 | } |
257 | 269 | ||
@@ -262,13 +274,13 @@ static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints) | |||
262 | */ | 274 | */ |
263 | static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) | 275 | static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints) |
264 | { | 276 | { |
265 | u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK); | 277 | u32 gsintmsk = readl(hsotg->regs + GINTMSK); |
266 | u32 new_gsintmsk; | 278 | u32 new_gsintmsk; |
267 | 279 | ||
268 | new_gsintmsk = gsintmsk & ~ints; | 280 | new_gsintmsk = gsintmsk & ~ints; |
269 | 281 | ||
270 | if (new_gsintmsk != gsintmsk) | 282 | if (new_gsintmsk != gsintmsk) |
271 | writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK); | 283 | writel(new_gsintmsk, hsotg->regs + GINTMSK); |
272 | } | 284 | } |
273 | 285 | ||
274 | /** | 286 | /** |
@@ -293,12 +305,12 @@ static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg, | |||
293 | bit <<= 16; | 305 | bit <<= 16; |
294 | 306 | ||
295 | local_irq_save(flags); | 307 | local_irq_save(flags); |
296 | daint = readl(hsotg->regs + S3C_DAINTMSK); | 308 | daint = readl(hsotg->regs + DAINTMSK); |
297 | if (en) | 309 | if (en) |
298 | daint |= bit; | 310 | daint |= bit; |
299 | else | 311 | else |
300 | daint &= ~bit; | 312 | daint &= ~bit; |
301 | writel(daint, hsotg->regs + S3C_DAINTMSK); | 313 | writel(daint, hsotg->regs + DAINTMSK); |
302 | local_irq_restore(flags); | 314 | local_irq_restore(flags); |
303 | } | 315 | } |
304 | 316 | ||
@@ -314,52 +326,51 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
314 | int timeout; | 326 | int timeout; |
315 | u32 val; | 327 | u32 val; |
316 | 328 | ||
317 | /* the ryu 2.6.24 release ahs | ||
318 | writel(0x1C0, hsotg->regs + S3C_GRXFSIZ); | ||
319 | writel(S3C_GNPTXFSIZ_NPTxFStAddr(0x200) | | ||
320 | S3C_GNPTXFSIZ_NPTxFDep(0x1C0), | ||
321 | hsotg->regs + S3C_GNPTXFSIZ); | ||
322 | */ | ||
323 | |||
324 | /* set FIFO sizes to 2048/1024 */ | 329 | /* set FIFO sizes to 2048/1024 */ |
325 | 330 | ||
326 | writel(2048, hsotg->regs + S3C_GRXFSIZ); | 331 | writel(2048, hsotg->regs + GRXFSIZ); |
327 | writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) | | 332 | writel(GNPTXFSIZ_NPTxFStAddr(2048) | |
328 | S3C_GNPTXFSIZ_NPTxFDep(1024), | 333 | GNPTXFSIZ_NPTxFDep(1024), |
329 | hsotg->regs + S3C_GNPTXFSIZ); | 334 | hsotg->regs + GNPTXFSIZ); |
330 | 335 | ||
331 | /* arange all the rest of the TX FIFOs, as some versions of this | 336 | /* |
337 | * arange all the rest of the TX FIFOs, as some versions of this | ||
332 | * block have overlapping default addresses. This also ensures | 338 | * block have overlapping default addresses. This also ensures |
333 | * that if the settings have been changed, then they are set to | 339 | * that if the settings have been changed, then they are set to |
334 | * known values. */ | 340 | * known values. |
341 | */ | ||
335 | 342 | ||
336 | /* start at the end of the GNPTXFSIZ, rounded up */ | 343 | /* start at the end of the GNPTXFSIZ, rounded up */ |
337 | addr = 2048 + 1024; | 344 | addr = 2048 + 1024; |
338 | size = 768; | 345 | size = 768; |
339 | 346 | ||
340 | /* currently we allocate TX FIFOs for all possible endpoints, | 347 | /* |
341 | * and assume that they are all the same size. */ | 348 | * currently we allocate TX FIFOs for all possible endpoints, |
349 | * and assume that they are all the same size. | ||
350 | */ | ||
342 | 351 | ||
343 | for (ep = 1; ep <= 15; ep++) { | 352 | for (ep = 1; ep <= 15; ep++) { |
344 | val = addr; | 353 | val = addr; |
345 | val |= size << S3C_DPTXFSIZn_DPTxFSize_SHIFT; | 354 | val |= size << DPTXFSIZn_DPTxFSize_SHIFT; |
346 | addr += size; | 355 | addr += size; |
347 | 356 | ||
348 | writel(val, hsotg->regs + S3C_DPTXFSIZn(ep)); | 357 | writel(val, hsotg->regs + DPTXFSIZn(ep)); |
349 | } | 358 | } |
350 | 359 | ||
351 | /* according to p428 of the design guide, we need to ensure that | 360 | /* |
352 | * all fifos are flushed before continuing */ | 361 | * according to p428 of the design guide, we need to ensure that |
362 | * all fifos are flushed before continuing | ||
363 | */ | ||
353 | 364 | ||
354 | writel(S3C_GRSTCTL_TxFNum(0x10) | S3C_GRSTCTL_TxFFlsh | | 365 | writel(GRSTCTL_TxFNum(0x10) | GRSTCTL_TxFFlsh | |
355 | S3C_GRSTCTL_RxFFlsh, hsotg->regs + S3C_GRSTCTL); | 366 | GRSTCTL_RxFFlsh, hsotg->regs + GRSTCTL); |
356 | 367 | ||
357 | /* wait until the fifos are both flushed */ | 368 | /* wait until the fifos are both flushed */ |
358 | timeout = 100; | 369 | timeout = 100; |
359 | while (1) { | 370 | while (1) { |
360 | val = readl(hsotg->regs + S3C_GRSTCTL); | 371 | val = readl(hsotg->regs + GRSTCTL); |
361 | 372 | ||
362 | if ((val & (S3C_GRSTCTL_TxFFlsh | S3C_GRSTCTL_RxFFlsh)) == 0) | 373 | if ((val & (GRSTCTL_TxFFlsh | GRSTCTL_RxFFlsh)) == 0) |
363 | break; | 374 | break; |
364 | 375 | ||
365 | if (--timeout == 0) { | 376 | if (--timeout == 0) { |
@@ -415,7 +426,7 @@ static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep) | |||
415 | * | 426 | * |
416 | * This is the reverse of s3c_hsotg_map_dma(), called for the completion | 427 | * This is the reverse of s3c_hsotg_map_dma(), called for the completion |
417 | * of a request to ensure the buffer is ready for access by the caller. | 428 | * of a request to ensure the buffer is ready for access by the caller. |
418 | */ | 429 | */ |
419 | static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | 430 | static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, |
420 | struct s3c_hsotg_ep *hs_ep, | 431 | struct s3c_hsotg_ep *hs_ep, |
421 | struct s3c_hsotg_req *hs_req) | 432 | struct s3c_hsotg_req *hs_req) |
@@ -456,13 +467,13 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | |||
456 | * otherwise -ENOSPC is returned if the FIFO space was used up. | 467 | * otherwise -ENOSPC is returned if the FIFO space was used up. |
457 | * | 468 | * |
458 | * This routine is only needed for PIO | 469 | * This routine is only needed for PIO |
459 | */ | 470 | */ |
460 | static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | 471 | static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, |
461 | struct s3c_hsotg_ep *hs_ep, | 472 | struct s3c_hsotg_ep *hs_ep, |
462 | struct s3c_hsotg_req *hs_req) | 473 | struct s3c_hsotg_req *hs_req) |
463 | { | 474 | { |
464 | bool periodic = is_ep_periodic(hs_ep); | 475 | bool periodic = is_ep_periodic(hs_ep); |
465 | u32 gnptxsts = readl(hsotg->regs + S3C_GNPTXSTS); | 476 | u32 gnptxsts = readl(hsotg->regs + GNPTXSTS); |
466 | int buf_pos = hs_req->req.actual; | 477 | int buf_pos = hs_req->req.actual; |
467 | int to_write = hs_ep->size_loaded; | 478 | int to_write = hs_ep->size_loaded; |
468 | void *data; | 479 | void *data; |
@@ -476,20 +487,23 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
476 | return 0; | 487 | return 0; |
477 | 488 | ||
478 | if (periodic && !hsotg->dedicated_fifos) { | 489 | if (periodic && !hsotg->dedicated_fifos) { |
479 | u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); | 490 | u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); |
480 | int size_left; | 491 | int size_left; |
481 | int size_done; | 492 | int size_done; |
482 | 493 | ||
483 | /* work out how much data was loaded so we can calculate | 494 | /* |
484 | * how much data is left in the fifo. */ | 495 | * work out how much data was loaded so we can calculate |
496 | * how much data is left in the fifo. | ||
497 | */ | ||
485 | 498 | ||
486 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | 499 | size_left = DxEPTSIZ_XferSize_GET(epsize); |
487 | 500 | ||
488 | /* if shared fifo, we cannot write anything until the | 501 | /* |
502 | * if shared fifo, we cannot write anything until the | ||
489 | * previous data has been completely sent. | 503 | * previous data has been completely sent. |
490 | */ | 504 | */ |
491 | if (hs_ep->fifo_load != 0) { | 505 | if (hs_ep->fifo_load != 0) { |
492 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); | 506 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp); |
493 | return -ENOSPC; | 507 | return -ENOSPC; |
494 | } | 508 | } |
495 | 509 | ||
@@ -510,47 +524,50 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
510 | __func__, can_write); | 524 | __func__, can_write); |
511 | 525 | ||
512 | if (can_write <= 0) { | 526 | if (can_write <= 0) { |
513 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); | 527 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp); |
514 | return -ENOSPC; | 528 | return -ENOSPC; |
515 | } | 529 | } |
516 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { | 530 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { |
517 | can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index)); | 531 | can_write = readl(hsotg->regs + DTXFSTS(hs_ep->index)); |
518 | 532 | ||
519 | can_write &= 0xffff; | 533 | can_write &= 0xffff; |
520 | can_write *= 4; | 534 | can_write *= 4; |
521 | } else { | 535 | } else { |
522 | if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { | 536 | if (GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { |
523 | dev_dbg(hsotg->dev, | 537 | dev_dbg(hsotg->dev, |
524 | "%s: no queue slots available (0x%08x)\n", | 538 | "%s: no queue slots available (0x%08x)\n", |
525 | __func__, gnptxsts); | 539 | __func__, gnptxsts); |
526 | 540 | ||
527 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_NPTxFEmp); | 541 | s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTxFEmp); |
528 | return -ENOSPC; | 542 | return -ENOSPC; |
529 | } | 543 | } |
530 | 544 | ||
531 | can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); | 545 | can_write = GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); |
532 | can_write *= 4; /* fifo size is in 32bit quantities. */ | 546 | can_write *= 4; /* fifo size is in 32bit quantities. */ |
533 | } | 547 | } |
534 | 548 | ||
535 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", | 549 | dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", |
536 | __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); | 550 | __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); |
537 | 551 | ||
538 | /* limit to 512 bytes of data, it seems at least on the non-periodic | 552 | /* |
553 | * limit to 512 bytes of data, it seems at least on the non-periodic | ||
539 | * FIFO, requests of >512 cause the endpoint to get stuck with a | 554 | * FIFO, requests of >512 cause the endpoint to get stuck with a |
540 | * fragment of the end of the transfer in it. | 555 | * fragment of the end of the transfer in it. |
541 | */ | 556 | */ |
542 | if (can_write > 512) | 557 | if (can_write > 512) |
543 | can_write = 512; | 558 | can_write = 512; |
544 | 559 | ||
545 | /* limit the write to one max-packet size worth of data, but allow | 560 | /* |
561 | * limit the write to one max-packet size worth of data, but allow | ||
546 | * the transfer to return that it did not run out of fifo space | 562 | * the transfer to return that it did not run out of fifo space |
547 | * doing it. */ | 563 | * doing it. |
564 | */ | ||
548 | if (to_write > hs_ep->ep.maxpacket) { | 565 | if (to_write > hs_ep->ep.maxpacket) { |
549 | to_write = hs_ep->ep.maxpacket; | 566 | to_write = hs_ep->ep.maxpacket; |
550 | 567 | ||
551 | s3c_hsotg_en_gsint(hsotg, | 568 | s3c_hsotg_en_gsint(hsotg, |
552 | periodic ? S3C_GINTSTS_PTxFEmp : | 569 | periodic ? GINTSTS_PTxFEmp : |
553 | S3C_GINTSTS_NPTxFEmp); | 570 | GINTSTS_NPTxFEmp); |
554 | } | 571 | } |
555 | 572 | ||
556 | /* see if we can write data */ | 573 | /* see if we can write data */ |
@@ -559,8 +576,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
559 | to_write = can_write; | 576 | to_write = can_write; |
560 | pkt_round = to_write % hs_ep->ep.maxpacket; | 577 | pkt_round = to_write % hs_ep->ep.maxpacket; |
561 | 578 | ||
562 | /* Not sure, but we probably shouldn't be writing partial | 579 | /* |
563 | * packets into the FIFO, so round the write down to an | 580 | * Round the write down to an |
564 | * exact number of packets. | 581 | * exact number of packets. |
565 | * | 582 | * |
566 | * Note, we do not currently check to see if we can ever | 583 | * Note, we do not currently check to see if we can ever |
@@ -570,12 +587,14 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
570 | if (pkt_round) | 587 | if (pkt_round) |
571 | to_write -= pkt_round; | 588 | to_write -= pkt_round; |
572 | 589 | ||
573 | /* enable correct FIFO interrupt to alert us when there | 590 | /* |
574 | * is more room left. */ | 591 | * enable correct FIFO interrupt to alert us when there |
592 | * is more room left. | ||
593 | */ | ||
575 | 594 | ||
576 | s3c_hsotg_en_gsint(hsotg, | 595 | s3c_hsotg_en_gsint(hsotg, |
577 | periodic ? S3C_GINTSTS_PTxFEmp : | 596 | periodic ? GINTSTS_PTxFEmp : |
578 | S3C_GINTSTS_NPTxFEmp); | 597 | GINTSTS_NPTxFEmp); |
579 | } | 598 | } |
580 | 599 | ||
581 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", | 600 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", |
@@ -593,7 +612,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
593 | to_write = DIV_ROUND_UP(to_write, 4); | 612 | to_write = DIV_ROUND_UP(to_write, 4); |
594 | data = hs_req->req.buf + buf_pos; | 613 | data = hs_req->req.buf + buf_pos; |
595 | 614 | ||
596 | writesl(hsotg->regs + S3C_EPFIFO(hs_ep->index), data, to_write); | 615 | writesl(hsotg->regs + EPFIFO(hs_ep->index), data, to_write); |
597 | 616 | ||
598 | return (to_write >= can_write) ? -ENOSPC : 0; | 617 | return (to_write >= can_write) ? -ENOSPC : 0; |
599 | } | 618 | } |
@@ -612,12 +631,12 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
612 | unsigned maxpkt; | 631 | unsigned maxpkt; |
613 | 632 | ||
614 | if (index != 0) { | 633 | if (index != 0) { |
615 | maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1; | 634 | maxsize = DxEPTSIZ_XferSize_LIMIT + 1; |
616 | maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; | 635 | maxpkt = DxEPTSIZ_PktCnt_LIMIT + 1; |
617 | } else { | 636 | } else { |
618 | maxsize = 64+64; | 637 | maxsize = 64+64; |
619 | if (hs_ep->dir_in) | 638 | if (hs_ep->dir_in) |
620 | maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; | 639 | maxpkt = DIEPTSIZ0_PktCnt_LIMIT + 1; |
621 | else | 640 | else |
622 | maxpkt = 2; | 641 | maxpkt = 2; |
623 | } | 642 | } |
@@ -626,8 +645,10 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
626 | maxpkt--; | 645 | maxpkt--; |
627 | maxsize--; | 646 | maxsize--; |
628 | 647 | ||
629 | /* constrain by packet count if maxpkts*pktsize is greater | 648 | /* |
630 | * than the length register size. */ | 649 | * constrain by packet count if maxpkts*pktsize is greater |
650 | * than the length register size. | ||
651 | */ | ||
631 | 652 | ||
632 | if ((maxpkt * hs_ep->ep.maxpacket) < maxsize) | 653 | if ((maxpkt * hs_ep->ep.maxpacket) < maxsize) |
633 | maxsize = maxpkt * hs_ep->ep.maxpacket; | 654 | maxsize = maxpkt * hs_ep->ep.maxpacket; |
@@ -674,8 +695,8 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
674 | } | 695 | } |
675 | } | 696 | } |
676 | 697 | ||
677 | epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index); | 698 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
678 | epsize_reg = dir_in ? S3C_DIEPTSIZ(index) : S3C_DOEPTSIZ(index); | 699 | epsize_reg = dir_in ? DIEPTSIZ(index) : DOEPTSIZ(index); |
679 | 700 | ||
680 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", | 701 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n", |
681 | __func__, readl(hsotg->regs + epctrl_reg), index, | 702 | __func__, readl(hsotg->regs + epctrl_reg), index, |
@@ -684,13 +705,14 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
684 | /* If endpoint is stalled, we will restart request later */ | 705 | /* If endpoint is stalled, we will restart request later */ |
685 | ctrl = readl(hsotg->regs + epctrl_reg); | 706 | ctrl = readl(hsotg->regs + epctrl_reg); |
686 | 707 | ||
687 | if (ctrl & S3C_DxEPCTL_Stall) { | 708 | if (ctrl & DxEPCTL_Stall) { |
688 | dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); | 709 | dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); |
689 | return; | 710 | return; |
690 | } | 711 | } |
691 | 712 | ||
692 | length = ureq->length - ureq->actual; | 713 | length = ureq->length - ureq->actual; |
693 | 714 | dev_dbg(hsotg->dev, "ureq->length:%d ureq->actual:%d\n", | |
715 | ureq->length, ureq->actual); | ||
694 | if (0) | 716 | if (0) |
695 | dev_dbg(hsotg->dev, | 717 | dev_dbg(hsotg->dev, |
696 | "REQ buf %p len %d dma 0x%08x noi=%d zp=%d snok=%d\n", | 718 | "REQ buf %p len %d dma 0x%08x noi=%d zp=%d snok=%d\n", |
@@ -717,20 +739,22 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
717 | packets = 1; /* send one packet if length is zero. */ | 739 | packets = 1; /* send one packet if length is zero. */ |
718 | 740 | ||
719 | if (dir_in && index != 0) | 741 | if (dir_in && index != 0) |
720 | epsize = S3C_DxEPTSIZ_MC(1); | 742 | epsize = DxEPTSIZ_MC(1); |
721 | else | 743 | else |
722 | epsize = 0; | 744 | epsize = 0; |
723 | 745 | ||
724 | if (index != 0 && ureq->zero) { | 746 | if (index != 0 && ureq->zero) { |
725 | /* test for the packets being exactly right for the | 747 | /* |
726 | * transfer */ | 748 | * test for the packets being exactly right for the |
749 | * transfer | ||
750 | */ | ||
727 | 751 | ||
728 | if (length == (packets * hs_ep->ep.maxpacket)) | 752 | if (length == (packets * hs_ep->ep.maxpacket)) |
729 | packets++; | 753 | packets++; |
730 | } | 754 | } |
731 | 755 | ||
732 | epsize |= S3C_DxEPTSIZ_PktCnt(packets); | 756 | epsize |= DxEPTSIZ_PktCnt(packets); |
733 | epsize |= S3C_DxEPTSIZ_XferSize(length); | 757 | epsize |= DxEPTSIZ_XferSize(length); |
734 | 758 | ||
735 | dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", | 759 | dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", |
736 | __func__, packets, length, ureq->length, epsize, epsize_reg); | 760 | __func__, packets, length, ureq->length, epsize, epsize_reg); |
@@ -744,26 +768,38 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
744 | if (using_dma(hsotg) && !continuing) { | 768 | if (using_dma(hsotg) && !continuing) { |
745 | unsigned int dma_reg; | 769 | unsigned int dma_reg; |
746 | 770 | ||
747 | /* write DMA address to control register, buffer already | 771 | /* |
748 | * synced by s3c_hsotg_ep_queue(). */ | 772 | * write DMA address to control register, buffer already |
773 | * synced by s3c_hsotg_ep_queue(). | ||
774 | */ | ||
749 | 775 | ||
750 | dma_reg = dir_in ? S3C_DIEPDMA(index) : S3C_DOEPDMA(index); | 776 | dma_reg = dir_in ? DIEPDMA(index) : DOEPDMA(index); |
751 | writel(ureq->dma, hsotg->regs + dma_reg); | 777 | writel(ureq->dma, hsotg->regs + dma_reg); |
752 | 778 | ||
753 | dev_dbg(hsotg->dev, "%s: 0x%08x => 0x%08x\n", | 779 | dev_dbg(hsotg->dev, "%s: 0x%08x => 0x%08x\n", |
754 | __func__, ureq->dma, dma_reg); | 780 | __func__, ureq->dma, dma_reg); |
755 | } | 781 | } |
756 | 782 | ||
757 | ctrl |= S3C_DxEPCTL_EPEna; /* ensure ep enabled */ | 783 | ctrl |= DxEPCTL_EPEna; /* ensure ep enabled */ |
758 | ctrl |= S3C_DxEPCTL_USBActEp; | 784 | ctrl |= DxEPCTL_USBActEp; |
759 | ctrl |= S3C_DxEPCTL_CNAK; /* clear NAK set by core */ | 785 | |
786 | dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup); | ||
787 | |||
788 | /* For Setup request do not clear NAK */ | ||
789 | if (hsotg->setup && index == 0) | ||
790 | hsotg->setup = 0; | ||
791 | else | ||
792 | ctrl |= DxEPCTL_CNAK; /* clear NAK set by core */ | ||
793 | |||
760 | 794 | ||
761 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); | 795 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
762 | writel(ctrl, hsotg->regs + epctrl_reg); | 796 | writel(ctrl, hsotg->regs + epctrl_reg); |
763 | 797 | ||
764 | /* set these, it seems that DMA support increments past the end | 798 | /* |
799 | * set these, it seems that DMA support increments past the end | ||
765 | * of the packet buffer so we need to calculate the length from | 800 | * of the packet buffer so we need to calculate the length from |
766 | * this information. */ | 801 | * this information. |
802 | */ | ||
767 | hs_ep->size_loaded = length; | 803 | hs_ep->size_loaded = length; |
768 | hs_ep->last_load = ureq->actual; | 804 | hs_ep->last_load = ureq->actual; |
769 | 805 | ||
@@ -774,17 +810,21 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
774 | s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); | 810 | s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); |
775 | } | 811 | } |
776 | 812 | ||
777 | /* clear the INTknTXFEmpMsk when we start request, more as a aide | 813 | /* |
778 | * to debugging to see what is going on. */ | 814 | * clear the INTknTXFEmpMsk when we start request, more as a aide |
815 | * to debugging to see what is going on. | ||
816 | */ | ||
779 | if (dir_in) | 817 | if (dir_in) |
780 | writel(S3C_DIEPMSK_INTknTXFEmpMsk, | 818 | writel(DIEPMSK_INTknTXFEmpMsk, |
781 | hsotg->regs + S3C_DIEPINT(index)); | 819 | hsotg->regs + DIEPINT(index)); |
782 | 820 | ||
783 | /* Note, trying to clear the NAK here causes problems with transmit | 821 | /* |
784 | * on the S3C6400 ending up with the TXFIFO becoming full. */ | 822 | * Note, trying to clear the NAK here causes problems with transmit |
823 | * on the S3C6400 ending up with the TXFIFO becoming full. | ||
824 | */ | ||
785 | 825 | ||
786 | /* check ep is enabled */ | 826 | /* check ep is enabled */ |
787 | if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna)) | 827 | if (!(readl(hsotg->regs + epctrl_reg) & DxEPCTL_EPEna)) |
788 | dev_warn(hsotg->dev, | 828 | dev_warn(hsotg->dev, |
789 | "ep%d: failed to become enabled (DxEPCTL=0x%08x)?\n", | 829 | "ep%d: failed to become enabled (DxEPCTL=0x%08x)?\n", |
790 | index, readl(hsotg->regs + epctrl_reg)); | 830 | index, readl(hsotg->regs + epctrl_reg)); |
@@ -804,7 +844,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
804 | * then ensure the buffer has been synced to memory. If our buffer has no | 844 | * then ensure the buffer has been synced to memory. If our buffer has no |
805 | * DMA memory, then we map the memory and mark our request to allow us to | 845 | * DMA memory, then we map the memory and mark our request to allow us to |
806 | * cleanup on completion. | 846 | * cleanup on completion. |
807 | */ | 847 | */ |
808 | static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, | 848 | static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, |
809 | struct s3c_hsotg_ep *hs_ep, | 849 | struct s3c_hsotg_ep *hs_ep, |
810 | struct usb_request *req) | 850 | struct usb_request *req) |
@@ -922,7 +962,7 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, | |||
922 | * | 962 | * |
923 | * Convert the given wIndex into a pointer to an driver endpoint | 963 | * Convert the given wIndex into a pointer to an driver endpoint |
924 | * structure, or return NULL if it is not a valid endpoint. | 964 | * structure, or return NULL if it is not a valid endpoint. |
925 | */ | 965 | */ |
926 | static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, | 966 | static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, |
927 | u32 windex) | 967 | u32 windex) |
928 | { | 968 | { |
@@ -933,7 +973,7 @@ static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg, | |||
933 | if (windex >= 0x100) | 973 | if (windex >= 0x100) |
934 | return NULL; | 974 | return NULL; |
935 | 975 | ||
936 | if (idx > S3C_HSOTG_EPS) | 976 | if (idx > hsotg->num_of_eps) |
937 | return NULL; | 977 | return NULL; |
938 | 978 | ||
939 | if (idx && ep->dir_in != dir) | 979 | if (idx && ep->dir_in != dir) |
@@ -1151,24 +1191,28 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1151 | ctrl->bRequest, ctrl->bRequestType, | 1191 | ctrl->bRequest, ctrl->bRequestType, |
1152 | ctrl->wValue, ctrl->wLength); | 1192 | ctrl->wValue, ctrl->wLength); |
1153 | 1193 | ||
1154 | /* record the direction of the request, for later use when enquing | 1194 | /* |
1155 | * packets onto EP0. */ | 1195 | * record the direction of the request, for later use when enquing |
1196 | * packets onto EP0. | ||
1197 | */ | ||
1156 | 1198 | ||
1157 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; | 1199 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; |
1158 | dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in); | 1200 | dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in); |
1159 | 1201 | ||
1160 | /* if we've no data with this request, then the last part of the | 1202 | /* |
1161 | * transaction is going to implicitly be IN. */ | 1203 | * if we've no data with this request, then the last part of the |
1204 | * transaction is going to implicitly be IN. | ||
1205 | */ | ||
1162 | if (ctrl->wLength == 0) | 1206 | if (ctrl->wLength == 0) |
1163 | ep0->dir_in = 1; | 1207 | ep0->dir_in = 1; |
1164 | 1208 | ||
1165 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | 1209 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { |
1166 | switch (ctrl->bRequest) { | 1210 | switch (ctrl->bRequest) { |
1167 | case USB_REQ_SET_ADDRESS: | 1211 | case USB_REQ_SET_ADDRESS: |
1168 | dcfg = readl(hsotg->regs + S3C_DCFG); | 1212 | dcfg = readl(hsotg->regs + DCFG); |
1169 | dcfg &= ~S3C_DCFG_DevAddr_MASK; | 1213 | dcfg &= ~DCFG_DevAddr_MASK; |
1170 | dcfg |= ctrl->wValue << S3C_DCFG_DevAddr_SHIFT; | 1214 | dcfg |= ctrl->wValue << DCFG_DevAddr_SHIFT; |
1171 | writel(dcfg, hsotg->regs + S3C_DCFG); | 1215 | writel(dcfg, hsotg->regs + DCFG); |
1172 | 1216 | ||
1173 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); | 1217 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); |
1174 | 1218 | ||
@@ -1194,7 +1238,8 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1194 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); | 1238 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); |
1195 | } | 1239 | } |
1196 | 1240 | ||
1197 | /* the request is either unhandlable, or is not formatted correctly | 1241 | /* |
1242 | * the request is either unhandlable, or is not formatted correctly | ||
1198 | * so respond with a STALL for the status stage to indicate failure. | 1243 | * so respond with a STALL for the status stage to indicate failure. |
1199 | */ | 1244 | */ |
1200 | 1245 | ||
@@ -1203,22 +1248,26 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1203 | u32 ctrl; | 1248 | u32 ctrl; |
1204 | 1249 | ||
1205 | dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); | 1250 | dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in); |
1206 | reg = (ep0->dir_in) ? S3C_DIEPCTL0 : S3C_DOEPCTL0; | 1251 | reg = (ep0->dir_in) ? DIEPCTL0 : DOEPCTL0; |
1207 | 1252 | ||
1208 | /* S3C_DxEPCTL_Stall will be cleared by EP once it has | 1253 | /* |
1209 | * taken effect, so no need to clear later. */ | 1254 | * DxEPCTL_Stall will be cleared by EP once it has |
1255 | * taken effect, so no need to clear later. | ||
1256 | */ | ||
1210 | 1257 | ||
1211 | ctrl = readl(hsotg->regs + reg); | 1258 | ctrl = readl(hsotg->regs + reg); |
1212 | ctrl |= S3C_DxEPCTL_Stall; | 1259 | ctrl |= DxEPCTL_Stall; |
1213 | ctrl |= S3C_DxEPCTL_CNAK; | 1260 | ctrl |= DxEPCTL_CNAK; |
1214 | writel(ctrl, hsotg->regs + reg); | 1261 | writel(ctrl, hsotg->regs + reg); |
1215 | 1262 | ||
1216 | dev_dbg(hsotg->dev, | 1263 | dev_dbg(hsotg->dev, |
1217 | "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", | 1264 | "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", |
1218 | ctrl, reg, readl(hsotg->regs + reg)); | 1265 | ctrl, reg, readl(hsotg->regs + reg)); |
1219 | 1266 | ||
1220 | /* don't believe we need to anything more to get the EP | 1267 | /* |
1221 | * to reply with a STALL packet */ | 1268 | * don't believe we need to anything more to get the EP |
1269 | * to reply with a STALL packet | ||
1270 | */ | ||
1222 | } | 1271 | } |
1223 | } | 1272 | } |
1224 | 1273 | ||
@@ -1279,8 +1328,10 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | |||
1279 | ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC); | 1328 | ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC); |
1280 | if (ret < 0) { | 1329 | if (ret < 0) { |
1281 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); | 1330 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); |
1282 | /* Don't think there's much we can do other than watch the | 1331 | /* |
1283 | * driver fail. */ | 1332 | * Don't think there's much we can do other than watch the |
1333 | * driver fail. | ||
1334 | */ | ||
1284 | } | 1335 | } |
1285 | } | 1336 | } |
1286 | 1337 | ||
@@ -1296,7 +1347,7 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | |||
1296 | * on the endpoint. | 1347 | * on the endpoint. |
1297 | * | 1348 | * |
1298 | * Note, expects the ep to already be locked as appropriate. | 1349 | * Note, expects the ep to already be locked as appropriate. |
1299 | */ | 1350 | */ |
1300 | static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | 1351 | static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, |
1301 | struct s3c_hsotg_ep *hs_ep, | 1352 | struct s3c_hsotg_ep *hs_ep, |
1302 | struct s3c_hsotg_req *hs_req, | 1353 | struct s3c_hsotg_req *hs_req, |
@@ -1312,8 +1363,10 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1312 | dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", | 1363 | dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n", |
1313 | hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete); | 1364 | hs_ep, hs_ep->ep.name, hs_req, result, hs_req->req.complete); |
1314 | 1365 | ||
1315 | /* only replace the status if we've not already set an error | 1366 | /* |
1316 | * from a previous transaction */ | 1367 | * only replace the status if we've not already set an error |
1368 | * from a previous transaction | ||
1369 | */ | ||
1317 | 1370 | ||
1318 | if (hs_req->req.status == -EINPROGRESS) | 1371 | if (hs_req->req.status == -EINPROGRESS) |
1319 | hs_req->req.status = result; | 1372 | hs_req->req.status = result; |
@@ -1324,8 +1377,10 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1324 | if (using_dma(hsotg)) | 1377 | if (using_dma(hsotg)) |
1325 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); | 1378 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); |
1326 | 1379 | ||
1327 | /* call the complete request with the locks off, just in case the | 1380 | /* |
1328 | * request tries to queue more work for this endpoint. */ | 1381 | * call the complete request with the locks off, just in case the |
1382 | * request tries to queue more work for this endpoint. | ||
1383 | */ | ||
1329 | 1384 | ||
1330 | if (hs_req->req.complete) { | 1385 | if (hs_req->req.complete) { |
1331 | spin_unlock(&hs_ep->lock); | 1386 | spin_unlock(&hs_ep->lock); |
@@ -1333,9 +1388,11 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1333 | spin_lock(&hs_ep->lock); | 1388 | spin_lock(&hs_ep->lock); |
1334 | } | 1389 | } |
1335 | 1390 | ||
1336 | /* Look to see if there is anything else to do. Note, the completion | 1391 | /* |
1392 | * Look to see if there is anything else to do. Note, the completion | ||
1337 | * of the previous request may have caused a new request to be started | 1393 | * of the previous request may have caused a new request to be started |
1338 | * so be careful when doing this. */ | 1394 | * so be careful when doing this. |
1395 | */ | ||
1339 | 1396 | ||
1340 | if (!hs_ep->req && result >= 0) { | 1397 | if (!hs_ep->req && result >= 0) { |
1341 | restart = !list_empty(&hs_ep->queue); | 1398 | restart = !list_empty(&hs_ep->queue); |
@@ -1355,7 +1412,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1355 | * | 1412 | * |
1356 | * See s3c_hsotg_complete_request(), but called with the endpoint's | 1413 | * See s3c_hsotg_complete_request(), but called with the endpoint's |
1357 | * lock held. | 1414 | * lock held. |
1358 | */ | 1415 | */ |
1359 | static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg, | 1416 | static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg, |
1360 | struct s3c_hsotg_ep *hs_ep, | 1417 | struct s3c_hsotg_ep *hs_ep, |
1361 | struct s3c_hsotg_req *hs_req, | 1418 | struct s3c_hsotg_req *hs_req, |
@@ -1382,13 +1439,13 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1382 | { | 1439 | { |
1383 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; | 1440 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx]; |
1384 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1441 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1385 | void __iomem *fifo = hsotg->regs + S3C_EPFIFO(ep_idx); | 1442 | void __iomem *fifo = hsotg->regs + EPFIFO(ep_idx); |
1386 | int to_read; | 1443 | int to_read; |
1387 | int max_req; | 1444 | int max_req; |
1388 | int read_ptr; | 1445 | int read_ptr; |
1389 | 1446 | ||
1390 | if (!hs_req) { | 1447 | if (!hs_req) { |
1391 | u32 epctl = readl(hsotg->regs + S3C_DOEPCTL(ep_idx)); | 1448 | u32 epctl = readl(hsotg->regs + DOEPCTL(ep_idx)); |
1392 | int ptr; | 1449 | int ptr; |
1393 | 1450 | ||
1394 | dev_warn(hsotg->dev, | 1451 | dev_warn(hsotg->dev, |
@@ -1412,7 +1469,8 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1412 | __func__, to_read, max_req, read_ptr, hs_req->req.length); | 1469 | __func__, to_read, max_req, read_ptr, hs_req->req.length); |
1413 | 1470 | ||
1414 | if (to_read > max_req) { | 1471 | if (to_read > max_req) { |
1415 | /* more data appeared than we where willing | 1472 | /* |
1473 | * more data appeared than we where willing | ||
1416 | * to deal with in this request. | 1474 | * to deal with in this request. |
1417 | */ | 1475 | */ |
1418 | 1476 | ||
@@ -1424,8 +1482,10 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1424 | hs_req->req.actual += to_read; | 1482 | hs_req->req.actual += to_read; |
1425 | to_read = DIV_ROUND_UP(to_read, 4); | 1483 | to_read = DIV_ROUND_UP(to_read, 4); |
1426 | 1484 | ||
1427 | /* note, we might over-write the buffer end by 3 bytes depending on | 1485 | /* |
1428 | * alignment of the data. */ | 1486 | * note, we might over-write the buffer end by 3 bytes depending on |
1487 | * alignment of the data. | ||
1488 | */ | ||
1429 | readsl(fifo, hs_req->req.buf + read_ptr, to_read); | 1489 | readsl(fifo, hs_req->req.buf + read_ptr, to_read); |
1430 | 1490 | ||
1431 | spin_unlock(&hs_ep->lock); | 1491 | spin_unlock(&hs_ep->lock); |
@@ -1465,14 +1525,14 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1465 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); | 1525 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); |
1466 | 1526 | ||
1467 | /* issue a zero-sized packet to terminate this */ | 1527 | /* issue a zero-sized packet to terminate this */ |
1468 | writel(S3C_DxEPTSIZ_MC(1) | S3C_DxEPTSIZ_PktCnt(1) | | 1528 | writel(DxEPTSIZ_MC(1) | DxEPTSIZ_PktCnt(1) | |
1469 | S3C_DxEPTSIZ_XferSize(0), hsotg->regs + S3C_DIEPTSIZ(0)); | 1529 | DxEPTSIZ_XferSize(0), hsotg->regs + DIEPTSIZ(0)); |
1470 | 1530 | ||
1471 | ctrl = readl(hsotg->regs + S3C_DIEPCTL0); | 1531 | ctrl = readl(hsotg->regs + DIEPCTL0); |
1472 | ctrl |= S3C_DxEPCTL_CNAK; /* clear NAK set by core */ | 1532 | ctrl |= DxEPCTL_CNAK; /* clear NAK set by core */ |
1473 | ctrl |= S3C_DxEPCTL_EPEna; /* ensure ep enabled */ | 1533 | ctrl |= DxEPCTL_EPEna; /* ensure ep enabled */ |
1474 | ctrl |= S3C_DxEPCTL_USBActEp; | 1534 | ctrl |= DxEPCTL_USBActEp; |
1475 | writel(ctrl, hsotg->regs + S3C_DIEPCTL0); | 1535 | writel(ctrl, hsotg->regs + DIEPCTL0); |
1476 | } | 1536 | } |
1477 | 1537 | ||
1478 | /** | 1538 | /** |
@@ -1484,15 +1544,15 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1484 | * The RXFIFO has delivered an OutDone event, which means that the data | 1544 | * The RXFIFO has delivered an OutDone event, which means that the data |
1485 | * transfer for an OUT endpoint has been completed, either by a short | 1545 | * transfer for an OUT endpoint has been completed, either by a short |
1486 | * packet or by the finish of a transfer. | 1546 | * packet or by the finish of a transfer. |
1487 | */ | 1547 | */ |
1488 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | 1548 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, |
1489 | int epnum, bool was_setup) | 1549 | int epnum, bool was_setup) |
1490 | { | 1550 | { |
1491 | u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum)); | 1551 | u32 epsize = readl(hsotg->regs + DOEPTSIZ(epnum)); |
1492 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; | 1552 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; |
1493 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1553 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1494 | struct usb_request *req = &hs_req->req; | 1554 | struct usb_request *req = &hs_req->req; |
1495 | unsigned size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | 1555 | unsigned size_left = DxEPTSIZ_XferSize_GET(epsize); |
1496 | int result = 0; | 1556 | int result = 0; |
1497 | 1557 | ||
1498 | if (!hs_req) { | 1558 | if (!hs_req) { |
@@ -1503,7 +1563,8 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1503 | if (using_dma(hsotg)) { | 1563 | if (using_dma(hsotg)) { |
1504 | unsigned size_done; | 1564 | unsigned size_done; |
1505 | 1565 | ||
1506 | /* Calculate the size of the transfer by checking how much | 1566 | /* |
1567 | * Calculate the size of the transfer by checking how much | ||
1507 | * is left in the endpoint size register and then working it | 1568 | * is left in the endpoint size register and then working it |
1508 | * out from the amount we loaded for the transfer. | 1569 | * out from the amount we loaded for the transfer. |
1509 | * | 1570 | * |
@@ -1521,17 +1582,29 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1521 | if (req->actual < req->length && size_left == 0) { | 1582 | if (req->actual < req->length && size_left == 0) { |
1522 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); | 1583 | s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); |
1523 | return; | 1584 | return; |
1585 | } else if (epnum == 0) { | ||
1586 | /* | ||
1587 | * After was_setup = 1 => | ||
1588 | * set CNAK for non Setup requests | ||
1589 | */ | ||
1590 | hsotg->setup = was_setup ? 0 : 1; | ||
1524 | } | 1591 | } |
1525 | 1592 | ||
1526 | if (req->actual < req->length && req->short_not_ok) { | 1593 | if (req->actual < req->length && req->short_not_ok) { |
1527 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", | 1594 | dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", |
1528 | __func__, req->actual, req->length); | 1595 | __func__, req->actual, req->length); |
1529 | 1596 | ||
1530 | /* todo - what should we return here? there's no one else | 1597 | /* |
1531 | * even bothering to check the status. */ | 1598 | * todo - what should we return here? there's no one else |
1599 | * even bothering to check the status. | ||
1600 | */ | ||
1532 | } | 1601 | } |
1533 | 1602 | ||
1534 | if (epnum == 0) { | 1603 | if (epnum == 0) { |
1604 | /* | ||
1605 | * Condition req->complete != s3c_hsotg_complete_setup says: | ||
1606 | * send ZLP when we have an asynchronous request from gadget | ||
1607 | */ | ||
1535 | if (!was_setup && req->complete != s3c_hsotg_complete_setup) | 1608 | if (!was_setup && req->complete != s3c_hsotg_complete_setup) |
1536 | s3c_hsotg_send_zlp(hsotg, hs_req); | 1609 | s3c_hsotg_send_zlp(hsotg, hs_req); |
1537 | } | 1610 | } |
@@ -1544,14 +1617,14 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1544 | * @hsotg: The device instance | 1617 | * @hsotg: The device instance |
1545 | * | 1618 | * |
1546 | * Return the current frame number | 1619 | * Return the current frame number |
1547 | */ | 1620 | */ |
1548 | static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) | 1621 | static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) |
1549 | { | 1622 | { |
1550 | u32 dsts; | 1623 | u32 dsts; |
1551 | 1624 | ||
1552 | dsts = readl(hsotg->regs + S3C_DSTS); | 1625 | dsts = readl(hsotg->regs + DSTS); |
1553 | dsts &= S3C_DSTS_SOFFN_MASK; | 1626 | dsts &= DSTS_SOFFN_MASK; |
1554 | dsts >>= S3C_DSTS_SOFFN_SHIFT; | 1627 | dsts >>= DSTS_SOFFN_SHIFT; |
1555 | 1628 | ||
1556 | return dsts; | 1629 | return dsts; |
1557 | } | 1630 | } |
@@ -1574,29 +1647,29 @@ static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) | |||
1574 | */ | 1647 | */ |
1575 | static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | 1648 | static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) |
1576 | { | 1649 | { |
1577 | u32 grxstsr = readl(hsotg->regs + S3C_GRXSTSP); | 1650 | u32 grxstsr = readl(hsotg->regs + GRXSTSP); |
1578 | u32 epnum, status, size; | 1651 | u32 epnum, status, size; |
1579 | 1652 | ||
1580 | WARN_ON(using_dma(hsotg)); | 1653 | WARN_ON(using_dma(hsotg)); |
1581 | 1654 | ||
1582 | epnum = grxstsr & S3C_GRXSTS_EPNum_MASK; | 1655 | epnum = grxstsr & GRXSTS_EPNum_MASK; |
1583 | status = grxstsr & S3C_GRXSTS_PktSts_MASK; | 1656 | status = grxstsr & GRXSTS_PktSts_MASK; |
1584 | 1657 | ||
1585 | size = grxstsr & S3C_GRXSTS_ByteCnt_MASK; | 1658 | size = grxstsr & GRXSTS_ByteCnt_MASK; |
1586 | size >>= S3C_GRXSTS_ByteCnt_SHIFT; | 1659 | size >>= GRXSTS_ByteCnt_SHIFT; |
1587 | 1660 | ||
1588 | if (1) | 1661 | if (1) |
1589 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", | 1662 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", |
1590 | __func__, grxstsr, size, epnum); | 1663 | __func__, grxstsr, size, epnum); |
1591 | 1664 | ||
1592 | #define __status(x) ((x) >> S3C_GRXSTS_PktSts_SHIFT) | 1665 | #define __status(x) ((x) >> GRXSTS_PktSts_SHIFT) |
1593 | 1666 | ||
1594 | switch (status >> S3C_GRXSTS_PktSts_SHIFT) { | 1667 | switch (status >> GRXSTS_PktSts_SHIFT) { |
1595 | case __status(S3C_GRXSTS_PktSts_GlobalOutNAK): | 1668 | case __status(GRXSTS_PktSts_GlobalOutNAK): |
1596 | dev_dbg(hsotg->dev, "GlobalOutNAK\n"); | 1669 | dev_dbg(hsotg->dev, "GlobalOutNAK\n"); |
1597 | break; | 1670 | break; |
1598 | 1671 | ||
1599 | case __status(S3C_GRXSTS_PktSts_OutDone): | 1672 | case __status(GRXSTS_PktSts_OutDone): |
1600 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", | 1673 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", |
1601 | s3c_hsotg_read_frameno(hsotg)); | 1674 | s3c_hsotg_read_frameno(hsotg)); |
1602 | 1675 | ||
@@ -1604,24 +1677,24 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1604 | s3c_hsotg_handle_outdone(hsotg, epnum, false); | 1677 | s3c_hsotg_handle_outdone(hsotg, epnum, false); |
1605 | break; | 1678 | break; |
1606 | 1679 | ||
1607 | case __status(S3C_GRXSTS_PktSts_SetupDone): | 1680 | case __status(GRXSTS_PktSts_SetupDone): |
1608 | dev_dbg(hsotg->dev, | 1681 | dev_dbg(hsotg->dev, |
1609 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", | 1682 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
1610 | s3c_hsotg_read_frameno(hsotg), | 1683 | s3c_hsotg_read_frameno(hsotg), |
1611 | readl(hsotg->regs + S3C_DOEPCTL(0))); | 1684 | readl(hsotg->regs + DOEPCTL(0))); |
1612 | 1685 | ||
1613 | s3c_hsotg_handle_outdone(hsotg, epnum, true); | 1686 | s3c_hsotg_handle_outdone(hsotg, epnum, true); |
1614 | break; | 1687 | break; |
1615 | 1688 | ||
1616 | case __status(S3C_GRXSTS_PktSts_OutRX): | 1689 | case __status(GRXSTS_PktSts_OutRX): |
1617 | s3c_hsotg_rx_data(hsotg, epnum, size); | 1690 | s3c_hsotg_rx_data(hsotg, epnum, size); |
1618 | break; | 1691 | break; |
1619 | 1692 | ||
1620 | case __status(S3C_GRXSTS_PktSts_SetupRX): | 1693 | case __status(GRXSTS_PktSts_SetupRX): |
1621 | dev_dbg(hsotg->dev, | 1694 | dev_dbg(hsotg->dev, |
1622 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", | 1695 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
1623 | s3c_hsotg_read_frameno(hsotg), | 1696 | s3c_hsotg_read_frameno(hsotg), |
1624 | readl(hsotg->regs + S3C_DOEPCTL(0))); | 1697 | readl(hsotg->regs + DOEPCTL(0))); |
1625 | 1698 | ||
1626 | s3c_hsotg_rx_data(hsotg, epnum, size); | 1699 | s3c_hsotg_rx_data(hsotg, epnum, size); |
1627 | break; | 1700 | break; |
@@ -1638,18 +1711,18 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1638 | /** | 1711 | /** |
1639 | * s3c_hsotg_ep0_mps - turn max packet size into register setting | 1712 | * s3c_hsotg_ep0_mps - turn max packet size into register setting |
1640 | * @mps: The maximum packet size in bytes. | 1713 | * @mps: The maximum packet size in bytes. |
1641 | */ | 1714 | */ |
1642 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) | 1715 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) |
1643 | { | 1716 | { |
1644 | switch (mps) { | 1717 | switch (mps) { |
1645 | case 64: | 1718 | case 64: |
1646 | return S3C_D0EPCTL_MPS_64; | 1719 | return D0EPCTL_MPS_64; |
1647 | case 32: | 1720 | case 32: |
1648 | return S3C_D0EPCTL_MPS_32; | 1721 | return D0EPCTL_MPS_32; |
1649 | case 16: | 1722 | case 16: |
1650 | return S3C_D0EPCTL_MPS_16; | 1723 | return D0EPCTL_MPS_16; |
1651 | case 8: | 1724 | case 8: |
1652 | return S3C_D0EPCTL_MPS_8; | 1725 | return D0EPCTL_MPS_8; |
1653 | } | 1726 | } |
1654 | 1727 | ||
1655 | /* bad max packet size, warn and return invalid result */ | 1728 | /* bad max packet size, warn and return invalid result */ |
@@ -1680,7 +1753,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1680 | if (mpsval > 3) | 1753 | if (mpsval > 3) |
1681 | goto bad_mps; | 1754 | goto bad_mps; |
1682 | } else { | 1755 | } else { |
1683 | if (mps >= S3C_DxEPCTL_MPS_LIMIT+1) | 1756 | if (mps >= DxEPCTL_MPS_LIMIT+1) |
1684 | goto bad_mps; | 1757 | goto bad_mps; |
1685 | 1758 | ||
1686 | mpsval = mps; | 1759 | mpsval = mps; |
@@ -1688,19 +1761,21 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1688 | 1761 | ||
1689 | hs_ep->ep.maxpacket = mps; | 1762 | hs_ep->ep.maxpacket = mps; |
1690 | 1763 | ||
1691 | /* update both the in and out endpoint controldir_ registers, even | 1764 | /* |
1692 | * if one of the directions may not be in use. */ | 1765 | * update both the in and out endpoint controldir_ registers, even |
1766 | * if one of the directions may not be in use. | ||
1767 | */ | ||
1693 | 1768 | ||
1694 | reg = readl(regs + S3C_DIEPCTL(ep)); | 1769 | reg = readl(regs + DIEPCTL(ep)); |
1695 | reg &= ~S3C_DxEPCTL_MPS_MASK; | 1770 | reg &= ~DxEPCTL_MPS_MASK; |
1696 | reg |= mpsval; | 1771 | reg |= mpsval; |
1697 | writel(reg, regs + S3C_DIEPCTL(ep)); | 1772 | writel(reg, regs + DIEPCTL(ep)); |
1698 | 1773 | ||
1699 | if (ep) { | 1774 | if (ep) { |
1700 | reg = readl(regs + S3C_DOEPCTL(ep)); | 1775 | reg = readl(regs + DOEPCTL(ep)); |
1701 | reg &= ~S3C_DxEPCTL_MPS_MASK; | 1776 | reg &= ~DxEPCTL_MPS_MASK; |
1702 | reg |= mpsval; | 1777 | reg |= mpsval; |
1703 | writel(reg, regs + S3C_DOEPCTL(ep)); | 1778 | writel(reg, regs + DOEPCTL(ep)); |
1704 | } | 1779 | } |
1705 | 1780 | ||
1706 | return; | 1781 | return; |
@@ -1719,16 +1794,16 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) | |||
1719 | int timeout; | 1794 | int timeout; |
1720 | int val; | 1795 | int val; |
1721 | 1796 | ||
1722 | writel(S3C_GRSTCTL_TxFNum(idx) | S3C_GRSTCTL_TxFFlsh, | 1797 | writel(GRSTCTL_TxFNum(idx) | GRSTCTL_TxFFlsh, |
1723 | hsotg->regs + S3C_GRSTCTL); | 1798 | hsotg->regs + GRSTCTL); |
1724 | 1799 | ||
1725 | /* wait until the fifo is flushed */ | 1800 | /* wait until the fifo is flushed */ |
1726 | timeout = 100; | 1801 | timeout = 100; |
1727 | 1802 | ||
1728 | while (1) { | 1803 | while (1) { |
1729 | val = readl(hsotg->regs + S3C_GRSTCTL); | 1804 | val = readl(hsotg->regs + GRSTCTL); |
1730 | 1805 | ||
1731 | if ((val & (S3C_GRSTCTL_TxFFlsh)) == 0) | 1806 | if ((val & (GRSTCTL_TxFFlsh)) == 0) |
1732 | break; | 1807 | break; |
1733 | 1808 | ||
1734 | if (--timeout == 0) { | 1809 | if (--timeout == 0) { |
@@ -1778,7 +1853,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1778 | struct s3c_hsotg_ep *hs_ep) | 1853 | struct s3c_hsotg_ep *hs_ep) |
1779 | { | 1854 | { |
1780 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1855 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1781 | u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); | 1856 | u32 epsize = readl(hsotg->regs + DIEPTSIZ(hs_ep->index)); |
1782 | int size_left, size_done; | 1857 | int size_left, size_done; |
1783 | 1858 | ||
1784 | if (!hs_req) { | 1859 | if (!hs_req) { |
@@ -1786,7 +1861,15 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1786 | return; | 1861 | return; |
1787 | } | 1862 | } |
1788 | 1863 | ||
1789 | /* Calculate the size of the transfer by checking how much is left | 1864 | /* Finish ZLP handling for IN EP0 transactions */ |
1865 | if (hsotg->eps[0].sent_zlp) { | ||
1866 | dev_dbg(hsotg->dev, "zlp packet received\n"); | ||
1867 | s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, 0); | ||
1868 | return; | ||
1869 | } | ||
1870 | |||
1871 | /* | ||
1872 | * Calculate the size of the transfer by checking how much is left | ||
1790 | * in the endpoint size register and then working it out from | 1873 | * in the endpoint size register and then working it out from |
1791 | * the amount we loaded for the transfer. | 1874 | * the amount we loaded for the transfer. |
1792 | * | 1875 | * |
@@ -1795,7 +1878,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1795 | * aligned). | 1878 | * aligned). |
1796 | */ | 1879 | */ |
1797 | 1880 | ||
1798 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | 1881 | size_left = DxEPTSIZ_XferSize_GET(epsize); |
1799 | 1882 | ||
1800 | size_done = hs_ep->size_loaded - size_left; | 1883 | size_done = hs_ep->size_loaded - size_left; |
1801 | size_done += hs_ep->last_load; | 1884 | size_done += hs_ep->last_load; |
@@ -1805,9 +1888,28 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1805 | __func__, hs_req->req.actual, size_done); | 1888 | __func__, hs_req->req.actual, size_done); |
1806 | 1889 | ||
1807 | hs_req->req.actual = size_done; | 1890 | hs_req->req.actual = size_done; |
1891 | dev_dbg(hsotg->dev, "req->length:%d req->actual:%d req->zero:%d\n", | ||
1892 | hs_req->req.length, hs_req->req.actual, hs_req->req.zero); | ||
1893 | |||
1894 | /* | ||
1895 | * Check if dealing with Maximum Packet Size(MPS) IN transfer at EP0 | ||
1896 | * When sent data is a multiple MPS size (e.g. 64B ,128B ,192B | ||
1897 | * ,256B ... ), after last MPS sized packet send IN ZLP packet to | ||
1898 | * inform the host that no more data is available. | ||
1899 | * The state of req.zero member is checked to be sure that the value to | ||
1900 | * send is smaller than wValue expected from host. | ||
1901 | * Check req.length to NOT send another ZLP when the current one is | ||
1902 | * under completion (the one for which this completion has been called). | ||
1903 | */ | ||
1904 | if (hs_req->req.length && hs_ep->index == 0 && hs_req->req.zero && | ||
1905 | hs_req->req.length == hs_req->req.actual && | ||
1906 | !(hs_req->req.length % hs_ep->ep.maxpacket)) { | ||
1808 | 1907 | ||
1809 | /* if we did all of the transfer, and there is more data left | 1908 | dev_dbg(hsotg->dev, "ep0 zlp IN packet sent\n"); |
1810 | * around, then try restarting the rest of the request */ | 1909 | s3c_hsotg_send_zlp(hsotg, hs_req); |
1910 | |||
1911 | return; | ||
1912 | } | ||
1811 | 1913 | ||
1812 | if (!size_left && hs_req->req.actual < hs_req->req.length) { | 1914 | if (!size_left && hs_req->req.actual < hs_req->req.length) { |
1813 | dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); | 1915 | dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__); |
@@ -1823,14 +1925,14 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1823 | * @dir_in: Set if this is an IN endpoint | 1925 | * @dir_in: Set if this is an IN endpoint |
1824 | * | 1926 | * |
1825 | * Process and clear any interrupt pending for an individual endpoint | 1927 | * Process and clear any interrupt pending for an individual endpoint |
1826 | */ | 1928 | */ |
1827 | static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | 1929 | static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, |
1828 | int dir_in) | 1930 | int dir_in) |
1829 | { | 1931 | { |
1830 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; | 1932 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx]; |
1831 | u32 epint_reg = dir_in ? S3C_DIEPINT(idx) : S3C_DOEPINT(idx); | 1933 | u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx); |
1832 | u32 epctl_reg = dir_in ? S3C_DIEPCTL(idx) : S3C_DOEPCTL(idx); | 1934 | u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); |
1833 | u32 epsiz_reg = dir_in ? S3C_DIEPTSIZ(idx) : S3C_DOEPTSIZ(idx); | 1935 | u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); |
1834 | u32 ints; | 1936 | u32 ints; |
1835 | 1937 | ||
1836 | ints = readl(hsotg->regs + epint_reg); | 1938 | ints = readl(hsotg->regs + epint_reg); |
@@ -1841,28 +1943,32 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1841 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", | 1943 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", |
1842 | __func__, idx, dir_in ? "in" : "out", ints); | 1944 | __func__, idx, dir_in ? "in" : "out", ints); |
1843 | 1945 | ||
1844 | if (ints & S3C_DxEPINT_XferCompl) { | 1946 | if (ints & DxEPINT_XferCompl) { |
1845 | dev_dbg(hsotg->dev, | 1947 | dev_dbg(hsotg->dev, |
1846 | "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", | 1948 | "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", |
1847 | __func__, readl(hsotg->regs + epctl_reg), | 1949 | __func__, readl(hsotg->regs + epctl_reg), |
1848 | readl(hsotg->regs + epsiz_reg)); | 1950 | readl(hsotg->regs + epsiz_reg)); |
1849 | 1951 | ||
1850 | /* we get OutDone from the FIFO, so we only need to look | 1952 | /* |
1851 | * at completing IN requests here */ | 1953 | * we get OutDone from the FIFO, so we only need to look |
1954 | * at completing IN requests here | ||
1955 | */ | ||
1852 | if (dir_in) { | 1956 | if (dir_in) { |
1853 | s3c_hsotg_complete_in(hsotg, hs_ep); | 1957 | s3c_hsotg_complete_in(hsotg, hs_ep); |
1854 | 1958 | ||
1855 | if (idx == 0 && !hs_ep->req) | 1959 | if (idx == 0 && !hs_ep->req) |
1856 | s3c_hsotg_enqueue_setup(hsotg); | 1960 | s3c_hsotg_enqueue_setup(hsotg); |
1857 | } else if (using_dma(hsotg)) { | 1961 | } else if (using_dma(hsotg)) { |
1858 | /* We're using DMA, we need to fire an OutDone here | 1962 | /* |
1859 | * as we ignore the RXFIFO. */ | 1963 | * We're using DMA, we need to fire an OutDone here |
1964 | * as we ignore the RXFIFO. | ||
1965 | */ | ||
1860 | 1966 | ||
1861 | s3c_hsotg_handle_outdone(hsotg, idx, false); | 1967 | s3c_hsotg_handle_outdone(hsotg, idx, false); |
1862 | } | 1968 | } |
1863 | } | 1969 | } |
1864 | 1970 | ||
1865 | if (ints & S3C_DxEPINT_EPDisbld) { | 1971 | if (ints & DxEPINT_EPDisbld) { |
1866 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); | 1972 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); |
1867 | 1973 | ||
1868 | if (dir_in) { | 1974 | if (dir_in) { |
@@ -1870,27 +1976,29 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1870 | 1976 | ||
1871 | s3c_hsotg_txfifo_flush(hsotg, idx); | 1977 | s3c_hsotg_txfifo_flush(hsotg, idx); |
1872 | 1978 | ||
1873 | if ((epctl & S3C_DxEPCTL_Stall) && | 1979 | if ((epctl & DxEPCTL_Stall) && |
1874 | (epctl & S3C_DxEPCTL_EPType_Bulk)) { | 1980 | (epctl & DxEPCTL_EPType_Bulk)) { |
1875 | int dctl = readl(hsotg->regs + S3C_DCTL); | 1981 | int dctl = readl(hsotg->regs + DCTL); |
1876 | 1982 | ||
1877 | dctl |= S3C_DCTL_CGNPInNAK; | 1983 | dctl |= DCTL_CGNPInNAK; |
1878 | writel(dctl, hsotg->regs + S3C_DCTL); | 1984 | writel(dctl, hsotg->regs + DCTL); |
1879 | } | 1985 | } |
1880 | } | 1986 | } |
1881 | } | 1987 | } |
1882 | 1988 | ||
1883 | if (ints & S3C_DxEPINT_AHBErr) | 1989 | if (ints & DxEPINT_AHBErr) |
1884 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); | 1990 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); |
1885 | 1991 | ||
1886 | if (ints & S3C_DxEPINT_Setup) { /* Setup or Timeout */ | 1992 | if (ints & DxEPINT_Setup) { /* Setup or Timeout */ |
1887 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); | 1993 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); |
1888 | 1994 | ||
1889 | if (using_dma(hsotg) && idx == 0) { | 1995 | if (using_dma(hsotg) && idx == 0) { |
1890 | /* this is the notification we've received a | 1996 | /* |
1997 | * this is the notification we've received a | ||
1891 | * setup packet. In non-DMA mode we'd get this | 1998 | * setup packet. In non-DMA mode we'd get this |
1892 | * from the RXFIFO, instead we need to process | 1999 | * from the RXFIFO, instead we need to process |
1893 | * the setup here. */ | 2000 | * the setup here. |
2001 | */ | ||
1894 | 2002 | ||
1895 | if (dir_in) | 2003 | if (dir_in) |
1896 | WARN_ON_ONCE(1); | 2004 | WARN_ON_ONCE(1); |
@@ -1899,26 +2007,25 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1899 | } | 2007 | } |
1900 | } | 2008 | } |
1901 | 2009 | ||
1902 | if (ints & S3C_DxEPINT_Back2BackSetup) | 2010 | if (ints & DxEPINT_Back2BackSetup) |
1903 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); | 2011 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
1904 | 2012 | ||
1905 | if (dir_in) { | 2013 | if (dir_in) { |
1906 | /* not sure if this is important, but we'll clear it anyway | 2014 | /* not sure if this is important, but we'll clear it anyway */ |
1907 | */ | 2015 | if (ints & DIEPMSK_INTknTXFEmpMsk) { |
1908 | if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) { | ||
1909 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", | 2016 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
1910 | __func__, idx); | 2017 | __func__, idx); |
1911 | } | 2018 | } |
1912 | 2019 | ||
1913 | /* this probably means something bad is happening */ | 2020 | /* this probably means something bad is happening */ |
1914 | if (ints & S3C_DIEPMSK_INTknEPMisMsk) { | 2021 | if (ints & DIEPMSK_INTknEPMisMsk) { |
1915 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", | 2022 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", |
1916 | __func__, idx); | 2023 | __func__, idx); |
1917 | } | 2024 | } |
1918 | 2025 | ||
1919 | /* FIFO has space or is empty (see GAHBCFG) */ | 2026 | /* FIFO has space or is empty (see GAHBCFG) */ |
1920 | if (hsotg->dedicated_fifos && | 2027 | if (hsotg->dedicated_fifos && |
1921 | ints & S3C_DIEPMSK_TxFIFOEmpty) { | 2028 | ints & DIEPMSK_TxFIFOEmpty) { |
1922 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", | 2029 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", |
1923 | __func__, idx); | 2030 | __func__, idx); |
1924 | if (!using_dma(hsotg)) | 2031 | if (!using_dma(hsotg)) |
@@ -1933,40 +2040,45 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1933 | * | 2040 | * |
1934 | * Handle updating the device settings after the enumeration phase has | 2041 | * Handle updating the device settings after the enumeration phase has |
1935 | * been completed. | 2042 | * been completed. |
1936 | */ | 2043 | */ |
1937 | static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | 2044 | static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) |
1938 | { | 2045 | { |
1939 | u32 dsts = readl(hsotg->regs + S3C_DSTS); | 2046 | u32 dsts = readl(hsotg->regs + DSTS); |
1940 | int ep0_mps = 0, ep_mps; | 2047 | int ep0_mps = 0, ep_mps; |
1941 | 2048 | ||
1942 | /* This should signal the finish of the enumeration phase | 2049 | /* |
2050 | * This should signal the finish of the enumeration phase | ||
1943 | * of the USB handshaking, so we should now know what rate | 2051 | * of the USB handshaking, so we should now know what rate |
1944 | * we connected at. */ | 2052 | * we connected at. |
2053 | */ | ||
1945 | 2054 | ||
1946 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); | 2055 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); |
1947 | 2056 | ||
1948 | /* note, since we're limited by the size of transfer on EP0, and | 2057 | /* |
2058 | * note, since we're limited by the size of transfer on EP0, and | ||
1949 | * it seems IN transfers must be a even number of packets we do | 2059 | * it seems IN transfers must be a even number of packets we do |
1950 | * not advertise a 64byte MPS on EP0. */ | 2060 | * not advertise a 64byte MPS on EP0. |
2061 | */ | ||
1951 | 2062 | ||
1952 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ | 2063 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ |
1953 | switch (dsts & S3C_DSTS_EnumSpd_MASK) { | 2064 | switch (dsts & DSTS_EnumSpd_MASK) { |
1954 | case S3C_DSTS_EnumSpd_FS: | 2065 | case DSTS_EnumSpd_FS: |
1955 | case S3C_DSTS_EnumSpd_FS48: | 2066 | case DSTS_EnumSpd_FS48: |
1956 | hsotg->gadget.speed = USB_SPEED_FULL; | 2067 | hsotg->gadget.speed = USB_SPEED_FULL; |
1957 | ep0_mps = EP0_MPS_LIMIT; | 2068 | ep0_mps = EP0_MPS_LIMIT; |
1958 | ep_mps = 64; | 2069 | ep_mps = 64; |
1959 | break; | 2070 | break; |
1960 | 2071 | ||
1961 | case S3C_DSTS_EnumSpd_HS: | 2072 | case DSTS_EnumSpd_HS: |
1962 | hsotg->gadget.speed = USB_SPEED_HIGH; | 2073 | hsotg->gadget.speed = USB_SPEED_HIGH; |
1963 | ep0_mps = EP0_MPS_LIMIT; | 2074 | ep0_mps = EP0_MPS_LIMIT; |
1964 | ep_mps = 512; | 2075 | ep_mps = 512; |
1965 | break; | 2076 | break; |
1966 | 2077 | ||
1967 | case S3C_DSTS_EnumSpd_LS: | 2078 | case DSTS_EnumSpd_LS: |
1968 | hsotg->gadget.speed = USB_SPEED_LOW; | 2079 | hsotg->gadget.speed = USB_SPEED_LOW; |
1969 | /* note, we don't actually support LS in this driver at the | 2080 | /* |
2081 | * note, we don't actually support LS in this driver at the | ||
1970 | * moment, and the documentation seems to imply that it isn't | 2082 | * moment, and the documentation seems to imply that it isn't |
1971 | * supported by the PHYs on some of the devices. | 2083 | * supported by the PHYs on some of the devices. |
1972 | */ | 2084 | */ |
@@ -1975,13 +2087,15 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
1975 | dev_info(hsotg->dev, "new device is %s\n", | 2087 | dev_info(hsotg->dev, "new device is %s\n", |
1976 | usb_speed_string(hsotg->gadget.speed)); | 2088 | usb_speed_string(hsotg->gadget.speed)); |
1977 | 2089 | ||
1978 | /* we should now know the maximum packet size for an | 2090 | /* |
1979 | * endpoint, so set the endpoints to a default value. */ | 2091 | * we should now know the maximum packet size for an |
2092 | * endpoint, so set the endpoints to a default value. | ||
2093 | */ | ||
1980 | 2094 | ||
1981 | if (ep0_mps) { | 2095 | if (ep0_mps) { |
1982 | int i; | 2096 | int i; |
1983 | s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps); | 2097 | s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps); |
1984 | for (i = 1; i < S3C_HSOTG_EPS; i++) | 2098 | for (i = 1; i < hsotg->num_of_eps; i++) |
1985 | s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps); | 2099 | s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps); |
1986 | } | 2100 | } |
1987 | 2101 | ||
@@ -1990,8 +2104,8 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
1990 | s3c_hsotg_enqueue_setup(hsotg); | 2104 | s3c_hsotg_enqueue_setup(hsotg); |
1991 | 2105 | ||
1992 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", | 2106 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", |
1993 | readl(hsotg->regs + S3C_DIEPCTL0), | 2107 | readl(hsotg->regs + DIEPCTL0), |
1994 | readl(hsotg->regs + S3C_DOEPCTL0)); | 2108 | readl(hsotg->regs + DOEPCTL0)); |
1995 | } | 2109 | } |
1996 | 2110 | ||
1997 | /** | 2111 | /** |
@@ -2014,8 +2128,10 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2014 | spin_lock_irqsave(&ep->lock, flags); | 2128 | spin_lock_irqsave(&ep->lock, flags); |
2015 | 2129 | ||
2016 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { | 2130 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
2017 | /* currently, we can't do much about an already | 2131 | /* |
2018 | * running request on an in endpoint */ | 2132 | * currently, we can't do much about an already |
2133 | * running request on an in endpoint | ||
2134 | */ | ||
2019 | 2135 | ||
2020 | if (ep->req == req && ep->dir_in && !force) | 2136 | if (ep->req == req && ep->dir_in && !force) |
2021 | continue; | 2137 | continue; |
@@ -2033,18 +2149,18 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2033 | (_hs)->driver->_entry(&(_hs)->gadget); | 2149 | (_hs)->driver->_entry(&(_hs)->gadget); |
2034 | 2150 | ||
2035 | /** | 2151 | /** |
2036 | * s3c_hsotg_disconnect_irq - disconnect irq service | 2152 | * s3c_hsotg_disconnect - disconnect service |
2037 | * @hsotg: The device state. | 2153 | * @hsotg: The device state. |
2038 | * | 2154 | * |
2039 | * A disconnect IRQ has been received, meaning that the host has | 2155 | * The device has been disconnected. Remove all current |
2040 | * lost contact with the bus. Remove all current transactions | 2156 | * transactions and signal the gadget driver that this |
2041 | * and signal the gadget driver that this has happened. | 2157 | * has happened. |
2042 | */ | 2158 | */ |
2043 | static void s3c_hsotg_disconnect_irq(struct s3c_hsotg *hsotg) | 2159 | static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) |
2044 | { | 2160 | { |
2045 | unsigned ep; | 2161 | unsigned ep; |
2046 | 2162 | ||
2047 | for (ep = 0; ep < S3C_HSOTG_EPS; ep++) | 2163 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
2048 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); | 2164 | kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); |
2049 | 2165 | ||
2050 | call_gadget(hsotg, disconnect); | 2166 | call_gadget(hsotg, disconnect); |
@@ -2062,7 +2178,7 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) | |||
2062 | 2178 | ||
2063 | /* look through for any more data to transmit */ | 2179 | /* look through for any more data to transmit */ |
2064 | 2180 | ||
2065 | for (epno = 0; epno < S3C_HSOTG_EPS; epno++) { | 2181 | for (epno = 0; epno < hsotg->num_of_eps; epno++) { |
2066 | ep = &hsotg->eps[epno]; | 2182 | ep = &hsotg->eps[epno]; |
2067 | 2183 | ||
2068 | if (!ep->dir_in) | 2184 | if (!ep->dir_in) |
@@ -2078,12 +2194,187 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) | |||
2078 | } | 2194 | } |
2079 | } | 2195 | } |
2080 | 2196 | ||
2081 | static struct s3c_hsotg *our_hsotg; | ||
2082 | |||
2083 | /* IRQ flags which will trigger a retry around the IRQ loop */ | 2197 | /* IRQ flags which will trigger a retry around the IRQ loop */ |
2084 | #define IRQ_RETRY_MASK (S3C_GINTSTS_NPTxFEmp | \ | 2198 | #define IRQ_RETRY_MASK (GINTSTS_NPTxFEmp | \ |
2085 | S3C_GINTSTS_PTxFEmp | \ | 2199 | GINTSTS_PTxFEmp | \ |
2086 | S3C_GINTSTS_RxFLvl) | 2200 | GINTSTS_RxFLvl) |
2201 | |||
2202 | /** | ||
2203 | * s3c_hsotg_corereset - issue softreset to the core | ||
2204 | * @hsotg: The device state | ||
2205 | * | ||
2206 | * Issue a soft reset to the core, and await the core finishing it. | ||
2207 | */ | ||
2208 | static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | ||
2209 | { | ||
2210 | int timeout; | ||
2211 | u32 grstctl; | ||
2212 | |||
2213 | dev_dbg(hsotg->dev, "resetting core\n"); | ||
2214 | |||
2215 | /* issue soft reset */ | ||
2216 | writel(GRSTCTL_CSftRst, hsotg->regs + GRSTCTL); | ||
2217 | |||
2218 | timeout = 1000; | ||
2219 | do { | ||
2220 | grstctl = readl(hsotg->regs + GRSTCTL); | ||
2221 | } while ((grstctl & GRSTCTL_CSftRst) && timeout-- > 0); | ||
2222 | |||
2223 | if (grstctl & GRSTCTL_CSftRst) { | ||
2224 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); | ||
2225 | return -EINVAL; | ||
2226 | } | ||
2227 | |||
2228 | timeout = 1000; | ||
2229 | |||
2230 | while (1) { | ||
2231 | u32 grstctl = readl(hsotg->regs + GRSTCTL); | ||
2232 | |||
2233 | if (timeout-- < 0) { | ||
2234 | dev_info(hsotg->dev, | ||
2235 | "%s: reset failed, GRSTCTL=%08x\n", | ||
2236 | __func__, grstctl); | ||
2237 | return -ETIMEDOUT; | ||
2238 | } | ||
2239 | |||
2240 | if (!(grstctl & GRSTCTL_AHBIdle)) | ||
2241 | continue; | ||
2242 | |||
2243 | break; /* reset done */ | ||
2244 | } | ||
2245 | |||
2246 | dev_dbg(hsotg->dev, "reset successful\n"); | ||
2247 | return 0; | ||
2248 | } | ||
2249 | |||
2250 | /** | ||
2251 | * s3c_hsotg_core_init - issue softreset to the core | ||
2252 | * @hsotg: The device state | ||
2253 | * | ||
2254 | * Issue a soft reset to the core, and await the core finishing it. | ||
2255 | */ | ||
2256 | static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | ||
2257 | { | ||
2258 | s3c_hsotg_corereset(hsotg); | ||
2259 | |||
2260 | /* | ||
2261 | * we must now enable ep0 ready for host detection and then | ||
2262 | * set configuration. | ||
2263 | */ | ||
2264 | |||
2265 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | ||
2266 | writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | | ||
2267 | (0x5 << 10), hsotg->regs + GUSBCFG); | ||
2268 | |||
2269 | s3c_hsotg_init_fifo(hsotg); | ||
2270 | |||
2271 | __orr32(hsotg->regs + DCTL, DCTL_SftDiscon); | ||
2272 | |||
2273 | writel(1 << 18 | DCFG_DevSpd_HS, hsotg->regs + DCFG); | ||
2274 | |||
2275 | /* Clear any pending OTG interrupts */ | ||
2276 | writel(0xffffffff, hsotg->regs + GOTGINT); | ||
2277 | |||
2278 | /* Clear any pending interrupts */ | ||
2279 | writel(0xffffffff, hsotg->regs + GINTSTS); | ||
2280 | |||
2281 | writel(GINTSTS_ErlySusp | GINTSTS_SessReqInt | | ||
2282 | GINTSTS_GOUTNakEff | GINTSTS_GINNakEff | | ||
2283 | GINTSTS_ConIDStsChng | GINTSTS_USBRst | | ||
2284 | GINTSTS_EnumDone | GINTSTS_OTGInt | | ||
2285 | GINTSTS_USBSusp | GINTSTS_WkUpInt, | ||
2286 | hsotg->regs + GINTMSK); | ||
2287 | |||
2288 | if (using_dma(hsotg)) | ||
2289 | writel(GAHBCFG_GlblIntrEn | GAHBCFG_DMAEn | | ||
2290 | GAHBCFG_HBstLen_Incr4, | ||
2291 | hsotg->regs + GAHBCFG); | ||
2292 | else | ||
2293 | writel(GAHBCFG_GlblIntrEn, hsotg->regs + GAHBCFG); | ||
2294 | |||
2295 | /* | ||
2296 | * Enabling INTknTXFEmpMsk here seems to be a big mistake, we end | ||
2297 | * up being flooded with interrupts if the host is polling the | ||
2298 | * endpoint to try and read data. | ||
2299 | */ | ||
2300 | |||
2301 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty : 0) | | ||
2302 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | | ||
2303 | DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | | ||
2304 | DIEPMSK_INTknEPMisMsk, | ||
2305 | hsotg->regs + DIEPMSK); | ||
2306 | |||
2307 | /* | ||
2308 | * don't need XferCompl, we get that from RXFIFO in slave mode. In | ||
2309 | * DMA mode we may need this. | ||
2310 | */ | ||
2311 | writel((using_dma(hsotg) ? (DIEPMSK_XferComplMsk | | ||
2312 | DIEPMSK_TimeOUTMsk) : 0) | | ||
2313 | DOEPMSK_EPDisbldMsk | DOEPMSK_AHBErrMsk | | ||
2314 | DOEPMSK_SetupMsk, | ||
2315 | hsotg->regs + DOEPMSK); | ||
2316 | |||
2317 | writel(0, hsotg->regs + DAINTMSK); | ||
2318 | |||
2319 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", | ||
2320 | readl(hsotg->regs + DIEPCTL0), | ||
2321 | readl(hsotg->regs + DOEPCTL0)); | ||
2322 | |||
2323 | /* enable in and out endpoint interrupts */ | ||
2324 | s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPInt | GINTSTS_IEPInt); | ||
2325 | |||
2326 | /* | ||
2327 | * Enable the RXFIFO when in slave mode, as this is how we collect | ||
2328 | * the data. In DMA mode, we get events from the FIFO but also | ||
2329 | * things we cannot process, so do not use it. | ||
2330 | */ | ||
2331 | if (!using_dma(hsotg)) | ||
2332 | s3c_hsotg_en_gsint(hsotg, GINTSTS_RxFLvl); | ||
2333 | |||
2334 | /* Enable interrupts for EP0 in and out */ | ||
2335 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); | ||
2336 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); | ||
2337 | |||
2338 | __orr32(hsotg->regs + DCTL, DCTL_PWROnPrgDone); | ||
2339 | udelay(10); /* see openiboot */ | ||
2340 | __bic32(hsotg->regs + DCTL, DCTL_PWROnPrgDone); | ||
2341 | |||
2342 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); | ||
2343 | |||
2344 | /* | ||
2345 | * DxEPCTL_USBActEp says RO in manual, but seems to be set by | ||
2346 | * writing to the EPCTL register.. | ||
2347 | */ | ||
2348 | |||
2349 | /* set to read 1 8byte packet */ | ||
2350 | writel(DxEPTSIZ_MC(1) | DxEPTSIZ_PktCnt(1) | | ||
2351 | DxEPTSIZ_XferSize(8), hsotg->regs + DOEPTSIZ0); | ||
2352 | |||
2353 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | ||
2354 | DxEPCTL_CNAK | DxEPCTL_EPEna | | ||
2355 | DxEPCTL_USBActEp, | ||
2356 | hsotg->regs + DOEPCTL0); | ||
2357 | |||
2358 | /* enable, but don't activate EP0in */ | ||
2359 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | ||
2360 | DxEPCTL_USBActEp, hsotg->regs + DIEPCTL0); | ||
2361 | |||
2362 | s3c_hsotg_enqueue_setup(hsotg); | ||
2363 | |||
2364 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", | ||
2365 | readl(hsotg->regs + DIEPCTL0), | ||
2366 | readl(hsotg->regs + DOEPCTL0)); | ||
2367 | |||
2368 | /* clear global NAKs */ | ||
2369 | writel(DCTL_CGOUTNak | DCTL_CGNPInNAK, | ||
2370 | hsotg->regs + DCTL); | ||
2371 | |||
2372 | /* must be at-least 3ms to allow bus to see disconnect */ | ||
2373 | mdelay(3); | ||
2374 | |||
2375 | /* remove the soft-disconnect and let's go */ | ||
2376 | __bic32(hsotg->regs + DCTL, DCTL_SftDiscon); | ||
2377 | } | ||
2087 | 2378 | ||
2088 | /** | 2379 | /** |
2089 | * s3c_hsotg_irq - handle device interrupt | 2380 | * s3c_hsotg_irq - handle device interrupt |
@@ -2098,52 +2389,45 @@ static irqreturn_t s3c_hsotg_irq(int irq, void *pw) | |||
2098 | u32 gintmsk; | 2389 | u32 gintmsk; |
2099 | 2390 | ||
2100 | irq_retry: | 2391 | irq_retry: |
2101 | gintsts = readl(hsotg->regs + S3C_GINTSTS); | 2392 | gintsts = readl(hsotg->regs + GINTSTS); |
2102 | gintmsk = readl(hsotg->regs + S3C_GINTMSK); | 2393 | gintmsk = readl(hsotg->regs + GINTMSK); |
2103 | 2394 | ||
2104 | dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", | 2395 | dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n", |
2105 | __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); | 2396 | __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count); |
2106 | 2397 | ||
2107 | gintsts &= gintmsk; | 2398 | gintsts &= gintmsk; |
2108 | 2399 | ||
2109 | if (gintsts & S3C_GINTSTS_OTGInt) { | 2400 | if (gintsts & GINTSTS_OTGInt) { |
2110 | u32 otgint = readl(hsotg->regs + S3C_GOTGINT); | 2401 | u32 otgint = readl(hsotg->regs + GOTGINT); |
2111 | 2402 | ||
2112 | dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); | 2403 | dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); |
2113 | 2404 | ||
2114 | writel(otgint, hsotg->regs + S3C_GOTGINT); | 2405 | writel(otgint, hsotg->regs + GOTGINT); |
2115 | } | ||
2116 | |||
2117 | if (gintsts & S3C_GINTSTS_DisconnInt) { | ||
2118 | dev_dbg(hsotg->dev, "%s: DisconnInt\n", __func__); | ||
2119 | writel(S3C_GINTSTS_DisconnInt, hsotg->regs + S3C_GINTSTS); | ||
2120 | |||
2121 | s3c_hsotg_disconnect_irq(hsotg); | ||
2122 | } | 2406 | } |
2123 | 2407 | ||
2124 | if (gintsts & S3C_GINTSTS_SessReqInt) { | 2408 | if (gintsts & GINTSTS_SessReqInt) { |
2125 | dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); | 2409 | dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); |
2126 | writel(S3C_GINTSTS_SessReqInt, hsotg->regs + S3C_GINTSTS); | 2410 | writel(GINTSTS_SessReqInt, hsotg->regs + GINTSTS); |
2127 | } | 2411 | } |
2128 | 2412 | ||
2129 | if (gintsts & S3C_GINTSTS_EnumDone) { | 2413 | if (gintsts & GINTSTS_EnumDone) { |
2130 | writel(S3C_GINTSTS_EnumDone, hsotg->regs + S3C_GINTSTS); | 2414 | writel(GINTSTS_EnumDone, hsotg->regs + GINTSTS); |
2131 | 2415 | ||
2132 | s3c_hsotg_irq_enumdone(hsotg); | 2416 | s3c_hsotg_irq_enumdone(hsotg); |
2133 | } | 2417 | } |
2134 | 2418 | ||
2135 | if (gintsts & S3C_GINTSTS_ConIDStsChng) { | 2419 | if (gintsts & GINTSTS_ConIDStsChng) { |
2136 | dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", | 2420 | dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", |
2137 | readl(hsotg->regs + S3C_DSTS), | 2421 | readl(hsotg->regs + DSTS), |
2138 | readl(hsotg->regs + S3C_GOTGCTL)); | 2422 | readl(hsotg->regs + GOTGCTL)); |
2139 | 2423 | ||
2140 | writel(S3C_GINTSTS_ConIDStsChng, hsotg->regs + S3C_GINTSTS); | 2424 | writel(GINTSTS_ConIDStsChng, hsotg->regs + GINTSTS); |
2141 | } | 2425 | } |
2142 | 2426 | ||
2143 | if (gintsts & (S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt)) { | 2427 | if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { |
2144 | u32 daint = readl(hsotg->regs + S3C_DAINT); | 2428 | u32 daint = readl(hsotg->regs + DAINT); |
2145 | u32 daint_out = daint >> S3C_DAINT_OutEP_SHIFT; | 2429 | u32 daint_out = daint >> DAINT_OutEP_SHIFT; |
2146 | u32 daint_in = daint & ~(daint_out << S3C_DAINT_OutEP_SHIFT); | 2430 | u32 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); |
2147 | int ep; | 2431 | int ep; |
2148 | 2432 | ||
2149 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); | 2433 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); |
@@ -2159,102 +2443,116 @@ irq_retry: | |||
2159 | } | 2443 | } |
2160 | } | 2444 | } |
2161 | 2445 | ||
2162 | if (gintsts & S3C_GINTSTS_USBRst) { | 2446 | if (gintsts & GINTSTS_USBRst) { |
2447 | |||
2448 | u32 usb_status = readl(hsotg->regs + GOTGCTL); | ||
2449 | |||
2163 | dev_info(hsotg->dev, "%s: USBRst\n", __func__); | 2450 | dev_info(hsotg->dev, "%s: USBRst\n", __func__); |
2164 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", | 2451 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", |
2165 | readl(hsotg->regs + S3C_GNPTXSTS)); | 2452 | readl(hsotg->regs + GNPTXSTS)); |
2166 | 2453 | ||
2167 | writel(S3C_GINTSTS_USBRst, hsotg->regs + S3C_GINTSTS); | 2454 | writel(GINTSTS_USBRst, hsotg->regs + GINTSTS); |
2168 | 2455 | ||
2169 | kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); | 2456 | if (usb_status & GOTGCTL_BSESVLD) { |
2457 | if (time_after(jiffies, hsotg->last_rst + | ||
2458 | msecs_to_jiffies(200))) { | ||
2170 | 2459 | ||
2171 | /* it seems after a reset we can end up with a situation | 2460 | kill_all_requests(hsotg, &hsotg->eps[0], |
2172 | * where the TXFIFO still has data in it... the docs | 2461 | -ECONNRESET, true); |
2173 | * suggest resetting all the fifos, so use the init_fifo | ||
2174 | * code to relayout and flush the fifos. | ||
2175 | */ | ||
2176 | 2462 | ||
2177 | s3c_hsotg_init_fifo(hsotg); | 2463 | s3c_hsotg_core_init(hsotg); |
2178 | 2464 | hsotg->last_rst = jiffies; | |
2179 | s3c_hsotg_enqueue_setup(hsotg); | 2465 | } |
2466 | } | ||
2180 | } | 2467 | } |
2181 | 2468 | ||
2182 | /* check both FIFOs */ | 2469 | /* check both FIFOs */ |
2183 | 2470 | ||
2184 | if (gintsts & S3C_GINTSTS_NPTxFEmp) { | 2471 | if (gintsts & GINTSTS_NPTxFEmp) { |
2185 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); | 2472 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); |
2186 | 2473 | ||
2187 | /* Disable the interrupt to stop it happening again | 2474 | /* |
2475 | * Disable the interrupt to stop it happening again | ||
2188 | * unless one of these endpoint routines decides that | 2476 | * unless one of these endpoint routines decides that |
2189 | * it needs re-enabling */ | 2477 | * it needs re-enabling |
2478 | */ | ||
2190 | 2479 | ||
2191 | s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp); | 2480 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTxFEmp); |
2192 | s3c_hsotg_irq_fifoempty(hsotg, false); | 2481 | s3c_hsotg_irq_fifoempty(hsotg, false); |
2193 | } | 2482 | } |
2194 | 2483 | ||
2195 | if (gintsts & S3C_GINTSTS_PTxFEmp) { | 2484 | if (gintsts & GINTSTS_PTxFEmp) { |
2196 | dev_dbg(hsotg->dev, "PTxFEmp\n"); | 2485 | dev_dbg(hsotg->dev, "PTxFEmp\n"); |
2197 | 2486 | ||
2198 | /* See note in S3C_GINTSTS_NPTxFEmp */ | 2487 | /* See note in GINTSTS_NPTxFEmp */ |
2199 | 2488 | ||
2200 | s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_PTxFEmp); | 2489 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTxFEmp); |
2201 | s3c_hsotg_irq_fifoempty(hsotg, true); | 2490 | s3c_hsotg_irq_fifoempty(hsotg, true); |
2202 | } | 2491 | } |
2203 | 2492 | ||
2204 | if (gintsts & S3C_GINTSTS_RxFLvl) { | 2493 | if (gintsts & GINTSTS_RxFLvl) { |
2205 | /* note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, | 2494 | /* |
2495 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, | ||
2206 | * we need to retry s3c_hsotg_handle_rx if this is still | 2496 | * we need to retry s3c_hsotg_handle_rx if this is still |
2207 | * set. */ | 2497 | * set. |
2498 | */ | ||
2208 | 2499 | ||
2209 | s3c_hsotg_handle_rx(hsotg); | 2500 | s3c_hsotg_handle_rx(hsotg); |
2210 | } | 2501 | } |
2211 | 2502 | ||
2212 | if (gintsts & S3C_GINTSTS_ModeMis) { | 2503 | if (gintsts & GINTSTS_ModeMis) { |
2213 | dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); | 2504 | dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); |
2214 | writel(S3C_GINTSTS_ModeMis, hsotg->regs + S3C_GINTSTS); | 2505 | writel(GINTSTS_ModeMis, hsotg->regs + GINTSTS); |
2215 | } | 2506 | } |
2216 | 2507 | ||
2217 | if (gintsts & S3C_GINTSTS_USBSusp) { | 2508 | if (gintsts & GINTSTS_USBSusp) { |
2218 | dev_info(hsotg->dev, "S3C_GINTSTS_USBSusp\n"); | 2509 | dev_info(hsotg->dev, "GINTSTS_USBSusp\n"); |
2219 | writel(S3C_GINTSTS_USBSusp, hsotg->regs + S3C_GINTSTS); | 2510 | writel(GINTSTS_USBSusp, hsotg->regs + GINTSTS); |
2220 | 2511 | ||
2221 | call_gadget(hsotg, suspend); | 2512 | call_gadget(hsotg, suspend); |
2513 | s3c_hsotg_disconnect(hsotg); | ||
2222 | } | 2514 | } |
2223 | 2515 | ||
2224 | if (gintsts & S3C_GINTSTS_WkUpInt) { | 2516 | if (gintsts & GINTSTS_WkUpInt) { |
2225 | dev_info(hsotg->dev, "S3C_GINTSTS_WkUpIn\n"); | 2517 | dev_info(hsotg->dev, "GINTSTS_WkUpIn\n"); |
2226 | writel(S3C_GINTSTS_WkUpInt, hsotg->regs + S3C_GINTSTS); | 2518 | writel(GINTSTS_WkUpInt, hsotg->regs + GINTSTS); |
2227 | 2519 | ||
2228 | call_gadget(hsotg, resume); | 2520 | call_gadget(hsotg, resume); |
2229 | } | 2521 | } |
2230 | 2522 | ||
2231 | if (gintsts & S3C_GINTSTS_ErlySusp) { | 2523 | if (gintsts & GINTSTS_ErlySusp) { |
2232 | dev_dbg(hsotg->dev, "S3C_GINTSTS_ErlySusp\n"); | 2524 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); |
2233 | writel(S3C_GINTSTS_ErlySusp, hsotg->regs + S3C_GINTSTS); | 2525 | writel(GINTSTS_ErlySusp, hsotg->regs + GINTSTS); |
2526 | |||
2527 | s3c_hsotg_disconnect(hsotg); | ||
2234 | } | 2528 | } |
2235 | 2529 | ||
2236 | /* these next two seem to crop-up occasionally causing the core | 2530 | /* |
2531 | * these next two seem to crop-up occasionally causing the core | ||
2237 | * to shutdown the USB transfer, so try clearing them and logging | 2532 | * to shutdown the USB transfer, so try clearing them and logging |
2238 | * the occurrence. */ | 2533 | * the occurrence. |
2534 | */ | ||
2239 | 2535 | ||
2240 | if (gintsts & S3C_GINTSTS_GOUTNakEff) { | 2536 | if (gintsts & GINTSTS_GOUTNakEff) { |
2241 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); | 2537 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); |
2242 | 2538 | ||
2243 | writel(S3C_DCTL_CGOUTNak, hsotg->regs + S3C_DCTL); | 2539 | writel(DCTL_CGOUTNak, hsotg->regs + DCTL); |
2244 | 2540 | ||
2245 | s3c_hsotg_dump(hsotg); | 2541 | s3c_hsotg_dump(hsotg); |
2246 | } | 2542 | } |
2247 | 2543 | ||
2248 | if (gintsts & S3C_GINTSTS_GINNakEff) { | 2544 | if (gintsts & GINTSTS_GINNakEff) { |
2249 | dev_info(hsotg->dev, "GINNakEff triggered\n"); | 2545 | dev_info(hsotg->dev, "GINNakEff triggered\n"); |
2250 | 2546 | ||
2251 | writel(S3C_DCTL_CGNPInNAK, hsotg->regs + S3C_DCTL); | 2547 | writel(DCTL_CGNPInNAK, hsotg->regs + DCTL); |
2252 | 2548 | ||
2253 | s3c_hsotg_dump(hsotg); | 2549 | s3c_hsotg_dump(hsotg); |
2254 | } | 2550 | } |
2255 | 2551 | ||
2256 | /* if we've had fifo events, we should try and go around the | 2552 | /* |
2257 | * loop again to see if there's any point in returning yet. */ | 2553 | * if we've had fifo events, we should try and go around the |
2554 | * loop again to see if there's any point in returning yet. | ||
2555 | */ | ||
2258 | 2556 | ||
2259 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) | 2557 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) |
2260 | goto irq_retry; | 2558 | goto irq_retry; |
@@ -2268,7 +2566,7 @@ irq_retry: | |||
2268 | * @desc: The USB endpoint descriptor to configure with. | 2566 | * @desc: The USB endpoint descriptor to configure with. |
2269 | * | 2567 | * |
2270 | * This is called from the USB gadget code's usb_ep_enable(). | 2568 | * This is called from the USB gadget code's usb_ep_enable(). |
2271 | */ | 2569 | */ |
2272 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, | 2570 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, |
2273 | const struct usb_endpoint_descriptor *desc) | 2571 | const struct usb_endpoint_descriptor *desc) |
2274 | { | 2572 | { |
@@ -2300,7 +2598,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2300 | 2598 | ||
2301 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ | 2599 | /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ |
2302 | 2600 | ||
2303 | epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index); | 2601 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
2304 | epctrl = readl(hsotg->regs + epctrl_reg); | 2602 | epctrl = readl(hsotg->regs + epctrl_reg); |
2305 | 2603 | ||
2306 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", | 2604 | dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n", |
@@ -2308,20 +2606,23 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2308 | 2606 | ||
2309 | spin_lock_irqsave(&hs_ep->lock, flags); | 2607 | spin_lock_irqsave(&hs_ep->lock, flags); |
2310 | 2608 | ||
2311 | epctrl &= ~(S3C_DxEPCTL_EPType_MASK | S3C_DxEPCTL_MPS_MASK); | 2609 | epctrl &= ~(DxEPCTL_EPType_MASK | DxEPCTL_MPS_MASK); |
2312 | epctrl |= S3C_DxEPCTL_MPS(mps); | 2610 | epctrl |= DxEPCTL_MPS(mps); |
2313 | 2611 | ||
2314 | /* mark the endpoint as active, otherwise the core may ignore | 2612 | /* |
2315 | * transactions entirely for this endpoint */ | 2613 | * mark the endpoint as active, otherwise the core may ignore |
2316 | epctrl |= S3C_DxEPCTL_USBActEp; | 2614 | * transactions entirely for this endpoint |
2615 | */ | ||
2616 | epctrl |= DxEPCTL_USBActEp; | ||
2317 | 2617 | ||
2318 | /* set the NAK status on the endpoint, otherwise we might try and | 2618 | /* |
2619 | * set the NAK status on the endpoint, otherwise we might try and | ||
2319 | * do something with data that we've yet got a request to process | 2620 | * do something with data that we've yet got a request to process |
2320 | * since the RXFIFO will take data for an endpoint even if the | 2621 | * since the RXFIFO will take data for an endpoint even if the |
2321 | * size register hasn't been set. | 2622 | * size register hasn't been set. |
2322 | */ | 2623 | */ |
2323 | 2624 | ||
2324 | epctrl |= S3C_DxEPCTL_SNAK; | 2625 | epctrl |= DxEPCTL_SNAK; |
2325 | 2626 | ||
2326 | /* update the endpoint state */ | 2627 | /* update the endpoint state */ |
2327 | hs_ep->ep.maxpacket = mps; | 2628 | hs_ep->ep.maxpacket = mps; |
@@ -2336,37 +2637,40 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2336 | goto out; | 2637 | goto out; |
2337 | 2638 | ||
2338 | case USB_ENDPOINT_XFER_BULK: | 2639 | case USB_ENDPOINT_XFER_BULK: |
2339 | epctrl |= S3C_DxEPCTL_EPType_Bulk; | 2640 | epctrl |= DxEPCTL_EPType_Bulk; |
2340 | break; | 2641 | break; |
2341 | 2642 | ||
2342 | case USB_ENDPOINT_XFER_INT: | 2643 | case USB_ENDPOINT_XFER_INT: |
2343 | if (dir_in) { | 2644 | if (dir_in) { |
2344 | /* Allocate our TxFNum by simply using the index | 2645 | /* |
2646 | * Allocate our TxFNum by simply using the index | ||
2345 | * of the endpoint for the moment. We could do | 2647 | * of the endpoint for the moment. We could do |
2346 | * something better if the host indicates how | 2648 | * something better if the host indicates how |
2347 | * many FIFOs we are expecting to use. */ | 2649 | * many FIFOs we are expecting to use. |
2650 | */ | ||
2348 | 2651 | ||
2349 | hs_ep->periodic = 1; | 2652 | hs_ep->periodic = 1; |
2350 | epctrl |= S3C_DxEPCTL_TxFNum(index); | 2653 | epctrl |= DxEPCTL_TxFNum(index); |
2351 | } | 2654 | } |
2352 | 2655 | ||
2353 | epctrl |= S3C_DxEPCTL_EPType_Intterupt; | 2656 | epctrl |= DxEPCTL_EPType_Intterupt; |
2354 | break; | 2657 | break; |
2355 | 2658 | ||
2356 | case USB_ENDPOINT_XFER_CONTROL: | 2659 | case USB_ENDPOINT_XFER_CONTROL: |
2357 | epctrl |= S3C_DxEPCTL_EPType_Control; | 2660 | epctrl |= DxEPCTL_EPType_Control; |
2358 | break; | 2661 | break; |
2359 | } | 2662 | } |
2360 | 2663 | ||
2361 | /* if the hardware has dedicated fifos, we must give each IN EP | 2664 | /* |
2665 | * if the hardware has dedicated fifos, we must give each IN EP | ||
2362 | * a unique tx-fifo even if it is non-periodic. | 2666 | * a unique tx-fifo even if it is non-periodic. |
2363 | */ | 2667 | */ |
2364 | if (dir_in && hsotg->dedicated_fifos) | 2668 | if (dir_in && hsotg->dedicated_fifos) |
2365 | epctrl |= S3C_DxEPCTL_TxFNum(index); | 2669 | epctrl |= DxEPCTL_TxFNum(index); |
2366 | 2670 | ||
2367 | /* for non control endpoints, set PID to D0 */ | 2671 | /* for non control endpoints, set PID to D0 */ |
2368 | if (index) | 2672 | if (index) |
2369 | epctrl |= S3C_DxEPCTL_SetD0PID; | 2673 | epctrl |= DxEPCTL_SetD0PID; |
2370 | 2674 | ||
2371 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", | 2675 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", |
2372 | __func__, epctrl); | 2676 | __func__, epctrl); |
@@ -2383,6 +2687,10 @@ out: | |||
2383 | return ret; | 2687 | return ret; |
2384 | } | 2688 | } |
2385 | 2689 | ||
2690 | /** | ||
2691 | * s3c_hsotg_ep_disable - disable given endpoint | ||
2692 | * @ep: The endpoint to disable. | ||
2693 | */ | ||
2386 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) | 2694 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) |
2387 | { | 2695 | { |
2388 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2696 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
@@ -2400,7 +2708,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2400 | return -EINVAL; | 2708 | return -EINVAL; |
2401 | } | 2709 | } |
2402 | 2710 | ||
2403 | epctrl_reg = dir_in ? S3C_DIEPCTL(index) : S3C_DOEPCTL(index); | 2711 | epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); |
2404 | 2712 | ||
2405 | /* terminate all requests with shutdown */ | 2713 | /* terminate all requests with shutdown */ |
2406 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); | 2714 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); |
@@ -2408,9 +2716,9 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2408 | spin_lock_irqsave(&hs_ep->lock, flags); | 2716 | spin_lock_irqsave(&hs_ep->lock, flags); |
2409 | 2717 | ||
2410 | ctrl = readl(hsotg->regs + epctrl_reg); | 2718 | ctrl = readl(hsotg->regs + epctrl_reg); |
2411 | ctrl &= ~S3C_DxEPCTL_EPEna; | 2719 | ctrl &= ~DxEPCTL_EPEna; |
2412 | ctrl &= ~S3C_DxEPCTL_USBActEp; | 2720 | ctrl &= ~DxEPCTL_USBActEp; |
2413 | ctrl |= S3C_DxEPCTL_SNAK; | 2721 | ctrl |= DxEPCTL_SNAK; |
2414 | 2722 | ||
2415 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); | 2723 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
2416 | writel(ctrl, hsotg->regs + epctrl_reg); | 2724 | writel(ctrl, hsotg->regs + epctrl_reg); |
@@ -2426,7 +2734,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2426 | * on_list - check request is on the given endpoint | 2734 | * on_list - check request is on the given endpoint |
2427 | * @ep: The endpoint to check. | 2735 | * @ep: The endpoint to check. |
2428 | * @test: The request to test if it is on the endpoint. | 2736 | * @test: The request to test if it is on the endpoint. |
2429 | */ | 2737 | */ |
2430 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) | 2738 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) |
2431 | { | 2739 | { |
2432 | struct s3c_hsotg_req *req, *treq; | 2740 | struct s3c_hsotg_req *req, *treq; |
@@ -2439,6 +2747,11 @@ static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) | |||
2439 | return false; | 2747 | return false; |
2440 | } | 2748 | } |
2441 | 2749 | ||
2750 | /** | ||
2751 | * s3c_hsotg_ep_dequeue - dequeue given endpoint | ||
2752 | * @ep: The endpoint to dequeue. | ||
2753 | * @req: The request to be removed from a queue. | ||
2754 | */ | ||
2442 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | 2755 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) |
2443 | { | 2756 | { |
2444 | struct s3c_hsotg_req *hs_req = our_req(req); | 2757 | struct s3c_hsotg_req *hs_req = our_req(req); |
@@ -2461,6 +2774,11 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2461 | return 0; | 2774 | return 0; |
2462 | } | 2775 | } |
2463 | 2776 | ||
2777 | /** | ||
2778 | * s3c_hsotg_ep_sethalt - set halt on a given endpoint | ||
2779 | * @ep: The endpoint to set halt. | ||
2780 | * @value: Set or unset the halt. | ||
2781 | */ | ||
2464 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | 2782 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) |
2465 | { | 2783 | { |
2466 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2784 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
@@ -2477,34 +2795,34 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | |||
2477 | 2795 | ||
2478 | /* write both IN and OUT control registers */ | 2796 | /* write both IN and OUT control registers */ |
2479 | 2797 | ||
2480 | epreg = S3C_DIEPCTL(index); | 2798 | epreg = DIEPCTL(index); |
2481 | epctl = readl(hs->regs + epreg); | 2799 | epctl = readl(hs->regs + epreg); |
2482 | 2800 | ||
2483 | if (value) { | 2801 | if (value) { |
2484 | epctl |= S3C_DxEPCTL_Stall + S3C_DxEPCTL_SNAK; | 2802 | epctl |= DxEPCTL_Stall + DxEPCTL_SNAK; |
2485 | if (epctl & S3C_DxEPCTL_EPEna) | 2803 | if (epctl & DxEPCTL_EPEna) |
2486 | epctl |= S3C_DxEPCTL_EPDis; | 2804 | epctl |= DxEPCTL_EPDis; |
2487 | } else { | 2805 | } else { |
2488 | epctl &= ~S3C_DxEPCTL_Stall; | 2806 | epctl &= ~DxEPCTL_Stall; |
2489 | xfertype = epctl & S3C_DxEPCTL_EPType_MASK; | 2807 | xfertype = epctl & DxEPCTL_EPType_MASK; |
2490 | if (xfertype == S3C_DxEPCTL_EPType_Bulk || | 2808 | if (xfertype == DxEPCTL_EPType_Bulk || |
2491 | xfertype == S3C_DxEPCTL_EPType_Intterupt) | 2809 | xfertype == DxEPCTL_EPType_Intterupt) |
2492 | epctl |= S3C_DxEPCTL_SetD0PID; | 2810 | epctl |= DxEPCTL_SetD0PID; |
2493 | } | 2811 | } |
2494 | 2812 | ||
2495 | writel(epctl, hs->regs + epreg); | 2813 | writel(epctl, hs->regs + epreg); |
2496 | 2814 | ||
2497 | epreg = S3C_DOEPCTL(index); | 2815 | epreg = DOEPCTL(index); |
2498 | epctl = readl(hs->regs + epreg); | 2816 | epctl = readl(hs->regs + epreg); |
2499 | 2817 | ||
2500 | if (value) | 2818 | if (value) |
2501 | epctl |= S3C_DxEPCTL_Stall; | 2819 | epctl |= DxEPCTL_Stall; |
2502 | else { | 2820 | else { |
2503 | epctl &= ~S3C_DxEPCTL_Stall; | 2821 | epctl &= ~DxEPCTL_Stall; |
2504 | xfertype = epctl & S3C_DxEPCTL_EPType_MASK; | 2822 | xfertype = epctl & DxEPCTL_EPType_MASK; |
2505 | if (xfertype == S3C_DxEPCTL_EPType_Bulk || | 2823 | if (xfertype == DxEPCTL_EPType_Bulk || |
2506 | xfertype == S3C_DxEPCTL_EPType_Intterupt) | 2824 | xfertype == DxEPCTL_EPType_Intterupt) |
2507 | epctl |= S3C_DxEPCTL_SetD0PID; | 2825 | epctl |= DxEPCTL_SetD0PID; |
2508 | } | 2826 | } |
2509 | 2827 | ||
2510 | writel(epctl, hs->regs + epreg); | 2828 | writel(epctl, hs->regs + epreg); |
@@ -2526,57 +2844,91 @@ static struct usb_ep_ops s3c_hsotg_ep_ops = { | |||
2526 | }; | 2844 | }; |
2527 | 2845 | ||
2528 | /** | 2846 | /** |
2529 | * s3c_hsotg_corereset - issue softreset to the core | 2847 | * s3c_hsotg_phy_enable - enable platform phy dev |
2530 | * @hsotg: The device state | 2848 | * @hsotg: The driver state |
2531 | * | 2849 | * |
2532 | * Issue a soft reset to the core, and await the core finishing it. | 2850 | * A wrapper for platform code responsible for controlling |
2533 | */ | 2851 | * low-level USB code |
2534 | static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | 2852 | */ |
2853 | static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | ||
2535 | { | 2854 | { |
2536 | int timeout; | 2855 | struct platform_device *pdev = to_platform_device(hsotg->dev); |
2537 | u32 grstctl; | ||
2538 | 2856 | ||
2539 | dev_dbg(hsotg->dev, "resetting core\n"); | 2857 | dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev); |
2858 | if (hsotg->plat->phy_init) | ||
2859 | hsotg->plat->phy_init(pdev, hsotg->plat->phy_type); | ||
2860 | } | ||
2540 | 2861 | ||
2541 | /* issue soft reset */ | 2862 | /** |
2542 | writel(S3C_GRSTCTL_CSftRst, hsotg->regs + S3C_GRSTCTL); | 2863 | * s3c_hsotg_phy_disable - disable platform phy dev |
2864 | * @hsotg: The driver state | ||
2865 | * | ||
2866 | * A wrapper for platform code responsible for controlling | ||
2867 | * low-level USB code | ||
2868 | */ | ||
2869 | static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | ||
2870 | { | ||
2871 | struct platform_device *pdev = to_platform_device(hsotg->dev); | ||
2543 | 2872 | ||
2544 | timeout = 1000; | 2873 | if (hsotg->plat->phy_exit) |
2545 | do { | 2874 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
2546 | grstctl = readl(hsotg->regs + S3C_GRSTCTL); | 2875 | } |
2547 | } while ((grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); | ||
2548 | 2876 | ||
2549 | if (grstctl & S3C_GRSTCTL_CSftRst) { | 2877 | /** |
2550 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); | 2878 | * s3c_hsotg_init - initalize the usb core |
2551 | return -EINVAL; | 2879 | * @hsotg: The driver state |
2552 | } | 2880 | */ |
2881 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | ||
2882 | { | ||
2883 | /* unmask subset of endpoint interrupts */ | ||
2553 | 2884 | ||
2554 | timeout = 1000; | 2885 | writel(DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | |
2886 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk, | ||
2887 | hsotg->regs + DIEPMSK); | ||
2555 | 2888 | ||
2556 | while (1) { | 2889 | writel(DOEPMSK_SetupMsk | DOEPMSK_AHBErrMsk | |
2557 | u32 grstctl = readl(hsotg->regs + S3C_GRSTCTL); | 2890 | DOEPMSK_EPDisbldMsk | DOEPMSK_XferComplMsk, |
2891 | hsotg->regs + DOEPMSK); | ||
2558 | 2892 | ||
2559 | if (timeout-- < 0) { | 2893 | writel(0, hsotg->regs + DAINTMSK); |
2560 | dev_info(hsotg->dev, | ||
2561 | "%s: reset failed, GRSTCTL=%08x\n", | ||
2562 | __func__, grstctl); | ||
2563 | return -ETIMEDOUT; | ||
2564 | } | ||
2565 | 2894 | ||
2566 | if (!(grstctl & S3C_GRSTCTL_AHBIdle)) | 2895 | /* Be in disconnected state until gadget is registered */ |
2567 | continue; | 2896 | __orr32(hsotg->regs + DCTL, DCTL_SftDiscon); |
2568 | 2897 | ||
2569 | break; /* reset done */ | 2898 | if (0) { |
2899 | /* post global nak until we're ready */ | ||
2900 | writel(DCTL_SGNPInNAK | DCTL_SGOUTNak, | ||
2901 | hsotg->regs + DCTL); | ||
2570 | } | 2902 | } |
2571 | 2903 | ||
2572 | dev_dbg(hsotg->dev, "reset successful\n"); | 2904 | /* setup fifos */ |
2573 | return 0; | 2905 | |
2906 | dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", | ||
2907 | readl(hsotg->regs + GRXFSIZ), | ||
2908 | readl(hsotg->regs + GNPTXFSIZ)); | ||
2909 | |||
2910 | s3c_hsotg_init_fifo(hsotg); | ||
2911 | |||
2912 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | ||
2913 | writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | (0x5 << 10), | ||
2914 | hsotg->regs + GUSBCFG); | ||
2915 | |||
2916 | writel(using_dma(hsotg) ? GAHBCFG_DMAEn : 0x0, | ||
2917 | hsotg->regs + GAHBCFG); | ||
2574 | } | 2918 | } |
2575 | 2919 | ||
2576 | static int s3c_hsotg_start(struct usb_gadget_driver *driver, | 2920 | /** |
2577 | int (*bind)(struct usb_gadget *)) | 2921 | * s3c_hsotg_udc_start - prepare the udc for work |
2922 | * @gadget: The usb gadget state | ||
2923 | * @driver: The usb gadget driver | ||
2924 | * | ||
2925 | * Perform initialization to prepare udc device and driver | ||
2926 | * to work. | ||
2927 | */ | ||
2928 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | ||
2929 | struct usb_gadget_driver *driver) | ||
2578 | { | 2930 | { |
2579 | struct s3c_hsotg *hsotg = our_hsotg; | 2931 | struct s3c_hsotg *hsotg = to_hsotg(gadget); |
2580 | int ret; | 2932 | int ret; |
2581 | 2933 | ||
2582 | if (!hsotg) { | 2934 | if (!hsotg) { |
@@ -2592,7 +2944,7 @@ static int s3c_hsotg_start(struct usb_gadget_driver *driver, | |||
2592 | if (driver->max_speed < USB_SPEED_FULL) | 2944 | if (driver->max_speed < USB_SPEED_FULL) |
2593 | dev_err(hsotg->dev, "%s: bad speed\n", __func__); | 2945 | dev_err(hsotg->dev, "%s: bad speed\n", __func__); |
2594 | 2946 | ||
2595 | if (!bind || !driver->setup) { | 2947 | if (!driver->setup) { |
2596 | dev_err(hsotg->dev, "%s: missing entry points\n", __func__); | 2948 | dev_err(hsotg->dev, "%s: missing entry points\n", __func__); |
2597 | return -EINVAL; | 2949 | return -EINVAL; |
2598 | } | 2950 | } |
@@ -2605,135 +2957,17 @@ static int s3c_hsotg_start(struct usb_gadget_driver *driver, | |||
2605 | hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask; | 2957 | hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask; |
2606 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2958 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2607 | 2959 | ||
2608 | ret = device_add(&hsotg->gadget.dev); | 2960 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
2961 | hsotg->supplies); | ||
2609 | if (ret) { | 2962 | if (ret) { |
2610 | dev_err(hsotg->dev, "failed to register gadget device\n"); | 2963 | dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); |
2611 | goto err; | 2964 | goto err; |
2612 | } | 2965 | } |
2613 | 2966 | ||
2614 | ret = bind(&hsotg->gadget); | 2967 | s3c_hsotg_phy_enable(hsotg); |
2615 | if (ret) { | ||
2616 | dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name); | ||
2617 | |||
2618 | hsotg->gadget.dev.driver = NULL; | ||
2619 | hsotg->driver = NULL; | ||
2620 | goto err; | ||
2621 | } | ||
2622 | |||
2623 | /* we must now enable ep0 ready for host detection and then | ||
2624 | * set configuration. */ | ||
2625 | |||
2626 | s3c_hsotg_corereset(hsotg); | ||
2627 | |||
2628 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | ||
2629 | writel(S3C_GUSBCFG_PHYIf16 | S3C_GUSBCFG_TOutCal(7) | | ||
2630 | (0x5 << 10), hsotg->regs + S3C_GUSBCFG); | ||
2631 | |||
2632 | /* looks like soft-reset changes state of FIFOs */ | ||
2633 | s3c_hsotg_init_fifo(hsotg); | ||
2634 | |||
2635 | __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon); | ||
2636 | |||
2637 | writel(1 << 18 | S3C_DCFG_DevSpd_HS, hsotg->regs + S3C_DCFG); | ||
2638 | |||
2639 | /* Clear any pending OTG interrupts */ | ||
2640 | writel(0xffffffff, hsotg->regs + S3C_GOTGINT); | ||
2641 | |||
2642 | /* Clear any pending interrupts */ | ||
2643 | writel(0xffffffff, hsotg->regs + S3C_GINTSTS); | ||
2644 | |||
2645 | writel(S3C_GINTSTS_DisconnInt | S3C_GINTSTS_SessReqInt | | ||
2646 | S3C_GINTSTS_ConIDStsChng | S3C_GINTSTS_USBRst | | ||
2647 | S3C_GINTSTS_EnumDone | S3C_GINTSTS_OTGInt | | ||
2648 | S3C_GINTSTS_USBSusp | S3C_GINTSTS_WkUpInt | | ||
2649 | S3C_GINTSTS_GOUTNakEff | S3C_GINTSTS_GINNakEff | | ||
2650 | S3C_GINTSTS_ErlySusp, | ||
2651 | hsotg->regs + S3C_GINTMSK); | ||
2652 | |||
2653 | if (using_dma(hsotg)) | ||
2654 | writel(S3C_GAHBCFG_GlblIntrEn | S3C_GAHBCFG_DMAEn | | ||
2655 | S3C_GAHBCFG_HBstLen_Incr4, | ||
2656 | hsotg->regs + S3C_GAHBCFG); | ||
2657 | else | ||
2658 | writel(S3C_GAHBCFG_GlblIntrEn, hsotg->regs + S3C_GAHBCFG); | ||
2659 | |||
2660 | /* Enabling INTknTXFEmpMsk here seems to be a big mistake, we end | ||
2661 | * up being flooded with interrupts if the host is polling the | ||
2662 | * endpoint to try and read data. */ | ||
2663 | |||
2664 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | | ||
2665 | S3C_DIEPMSK_INTknEPMisMsk | | ||
2666 | S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk | | ||
2667 | ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0), | ||
2668 | hsotg->regs + S3C_DIEPMSK); | ||
2669 | |||
2670 | /* don't need XferCompl, we get that from RXFIFO in slave mode. In | ||
2671 | * DMA mode we may need this. */ | ||
2672 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | | ||
2673 | S3C_DOEPMSK_EPDisbldMsk | | ||
2674 | (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | | ||
2675 | S3C_DIEPMSK_TimeOUTMsk) : 0), | ||
2676 | hsotg->regs + S3C_DOEPMSK); | ||
2677 | |||
2678 | writel(0, hsotg->regs + S3C_DAINTMSK); | ||
2679 | |||
2680 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", | ||
2681 | readl(hsotg->regs + S3C_DIEPCTL0), | ||
2682 | readl(hsotg->regs + S3C_DOEPCTL0)); | ||
2683 | |||
2684 | /* enable in and out endpoint interrupts */ | ||
2685 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt); | ||
2686 | |||
2687 | /* Enable the RXFIFO when in slave mode, as this is how we collect | ||
2688 | * the data. In DMA mode, we get events from the FIFO but also | ||
2689 | * things we cannot process, so do not use it. */ | ||
2690 | if (!using_dma(hsotg)) | ||
2691 | s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_RxFLvl); | ||
2692 | |||
2693 | /* Enable interrupts for EP0 in and out */ | ||
2694 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); | ||
2695 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); | ||
2696 | |||
2697 | __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone); | ||
2698 | udelay(10); /* see openiboot */ | ||
2699 | __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone); | ||
2700 | |||
2701 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + S3C_DCTL)); | ||
2702 | |||
2703 | /* S3C_DxEPCTL_USBActEp says RO in manual, but seems to be set by | ||
2704 | writing to the EPCTL register.. */ | ||
2705 | |||
2706 | /* set to read 1 8byte packet */ | ||
2707 | writel(S3C_DxEPTSIZ_MC(1) | S3C_DxEPTSIZ_PktCnt(1) | | ||
2708 | S3C_DxEPTSIZ_XferSize(8), hsotg->regs + DOEPTSIZ0); | ||
2709 | |||
2710 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | ||
2711 | S3C_DxEPCTL_CNAK | S3C_DxEPCTL_EPEna | | ||
2712 | S3C_DxEPCTL_USBActEp, | ||
2713 | hsotg->regs + S3C_DOEPCTL0); | ||
2714 | |||
2715 | /* enable, but don't activate EP0in */ | ||
2716 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | ||
2717 | S3C_DxEPCTL_USBActEp, hsotg->regs + S3C_DIEPCTL0); | ||
2718 | |||
2719 | s3c_hsotg_enqueue_setup(hsotg); | ||
2720 | |||
2721 | dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n", | ||
2722 | readl(hsotg->regs + S3C_DIEPCTL0), | ||
2723 | readl(hsotg->regs + S3C_DOEPCTL0)); | ||
2724 | |||
2725 | /* clear global NAKs */ | ||
2726 | writel(S3C_DCTL_CGOUTNak | S3C_DCTL_CGNPInNAK, | ||
2727 | hsotg->regs + S3C_DCTL); | ||
2728 | |||
2729 | /* must be at-least 3ms to allow bus to see disconnect */ | ||
2730 | msleep(3); | ||
2731 | |||
2732 | /* remove the soft-disconnect and let's go */ | ||
2733 | __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon); | ||
2734 | |||
2735 | /* report to the user, and return */ | ||
2736 | 2968 | ||
2969 | s3c_hsotg_core_init(hsotg); | ||
2970 | hsotg->last_rst = jiffies; | ||
2737 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); | 2971 | dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); |
2738 | return 0; | 2972 | return 0; |
2739 | 2973 | ||
@@ -2743,9 +2977,17 @@ err: | |||
2743 | return ret; | 2977 | return ret; |
2744 | } | 2978 | } |
2745 | 2979 | ||
2746 | static int s3c_hsotg_stop(struct usb_gadget_driver *driver) | 2980 | /** |
2981 | * s3c_hsotg_udc_stop - stop the udc | ||
2982 | * @gadget: The usb gadget state | ||
2983 | * @driver: The usb gadget driver | ||
2984 | * | ||
2985 | * Stop udc hw block and stay tunned for future transmissions | ||
2986 | */ | ||
2987 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | ||
2988 | struct usb_gadget_driver *driver) | ||
2747 | { | 2989 | { |
2748 | struct s3c_hsotg *hsotg = our_hsotg; | 2990 | struct s3c_hsotg *hsotg = to_hsotg(gadget); |
2749 | int ep; | 2991 | int ep; |
2750 | 2992 | ||
2751 | if (!hsotg) | 2993 | if (!hsotg) |
@@ -2755,16 +2997,15 @@ static int s3c_hsotg_stop(struct usb_gadget_driver *driver) | |||
2755 | return -EINVAL; | 2997 | return -EINVAL; |
2756 | 2998 | ||
2757 | /* all endpoints should be shutdown */ | 2999 | /* all endpoints should be shutdown */ |
2758 | for (ep = 0; ep < S3C_HSOTG_EPS; ep++) | 3000 | for (ep = 0; ep < hsotg->num_of_eps; ep++) |
2759 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); | 3001 | s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); |
2760 | 3002 | ||
2761 | call_gadget(hsotg, disconnect); | 3003 | s3c_hsotg_phy_disable(hsotg); |
3004 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); | ||
2762 | 3005 | ||
2763 | driver->unbind(&hsotg->gadget); | ||
2764 | hsotg->driver = NULL; | 3006 | hsotg->driver = NULL; |
2765 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 3007 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2766 | 3008 | hsotg->gadget.dev.driver = NULL; | |
2767 | device_del(&hsotg->gadget.dev); | ||
2768 | 3009 | ||
2769 | dev_info(hsotg->dev, "unregistered gadget driver '%s'\n", | 3010 | dev_info(hsotg->dev, "unregistered gadget driver '%s'\n", |
2770 | driver->driver.name); | 3011 | driver->driver.name); |
@@ -2772,6 +3013,12 @@ static int s3c_hsotg_stop(struct usb_gadget_driver *driver) | |||
2772 | return 0; | 3013 | return 0; |
2773 | } | 3014 | } |
2774 | 3015 | ||
3016 | /** | ||
3017 | * s3c_hsotg_gadget_getframe - read the frame number | ||
3018 | * @gadget: The usb gadget state | ||
3019 | * | ||
3020 | * Read the {micro} frame number | ||
3021 | */ | ||
2775 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | 3022 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) |
2776 | { | 3023 | { |
2777 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); | 3024 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); |
@@ -2779,8 +3026,8 @@ static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | |||
2779 | 3026 | ||
2780 | static struct usb_gadget_ops s3c_hsotg_gadget_ops = { | 3027 | static struct usb_gadget_ops s3c_hsotg_gadget_ops = { |
2781 | .get_frame = s3c_hsotg_gadget_getframe, | 3028 | .get_frame = s3c_hsotg_gadget_getframe, |
2782 | .start = s3c_hsotg_start, | 3029 | .udc_start = s3c_hsotg_udc_start, |
2783 | .stop = s3c_hsotg_stop, | 3030 | .udc_stop = s3c_hsotg_udc_stop, |
2784 | }; | 3031 | }; |
2785 | 3032 | ||
2786 | /** | 3033 | /** |
@@ -2827,111 +3074,42 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2827 | hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; | 3074 | hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; |
2828 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3075 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
2829 | 3076 | ||
2830 | /* Read the FIFO size for the Periodic TX FIFO, even if we're | 3077 | /* |
3078 | * Read the FIFO size for the Periodic TX FIFO, even if we're | ||
2831 | * an OUT endpoint, we may as well do this if in future the | 3079 | * an OUT endpoint, we may as well do this if in future the |
2832 | * code is changed to make each endpoint's direction changeable. | 3080 | * code is changed to make each endpoint's direction changeable. |
2833 | */ | 3081 | */ |
2834 | 3082 | ||
2835 | ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); | 3083 | ptxfifo = readl(hsotg->regs + DPTXFSIZn(epnum)); |
2836 | hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; | 3084 | hs_ep->fifo_size = DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; |
2837 | 3085 | ||
2838 | /* if we're using dma, we need to set the next-endpoint pointer | 3086 | /* |
3087 | * if we're using dma, we need to set the next-endpoint pointer | ||
2839 | * to be something valid. | 3088 | * to be something valid. |
2840 | */ | 3089 | */ |
2841 | 3090 | ||
2842 | if (using_dma(hsotg)) { | 3091 | if (using_dma(hsotg)) { |
2843 | u32 next = S3C_DxEPCTL_NextEp((epnum + 1) % 15); | 3092 | u32 next = DxEPCTL_NextEp((epnum + 1) % 15); |
2844 | writel(next, hsotg->regs + S3C_DIEPCTL(epnum)); | 3093 | writel(next, hsotg->regs + DIEPCTL(epnum)); |
2845 | writel(next, hsotg->regs + S3C_DOEPCTL(epnum)); | 3094 | writel(next, hsotg->regs + DOEPCTL(epnum)); |
2846 | } | 3095 | } |
2847 | } | 3096 | } |
2848 | 3097 | ||
2849 | /** | 3098 | /** |
2850 | * s3c_hsotg_otgreset - reset the OtG phy block | 3099 | * s3c_hsotg_hw_cfg - read HW configuration registers |
2851 | * @hsotg: The host state. | 3100 | * @param: The device state |
2852 | * | 3101 | * |
2853 | * Power up the phy, set the basic configuration and start the PHY. | 3102 | * Read the USB core HW configuration registers |
2854 | */ | 3103 | */ |
2855 | static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) | 3104 | static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) |
2856 | { | ||
2857 | struct clk *xusbxti; | ||
2858 | u32 pwr, osc; | ||
2859 | |||
2860 | pwr = readl(S3C_PHYPWR); | ||
2861 | pwr &= ~0x19; | ||
2862 | writel(pwr, S3C_PHYPWR); | ||
2863 | mdelay(1); | ||
2864 | |||
2865 | osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0; | ||
2866 | |||
2867 | xusbxti = clk_get(hsotg->dev, "xusbxti"); | ||
2868 | if (xusbxti && !IS_ERR(xusbxti)) { | ||
2869 | switch (clk_get_rate(xusbxti)) { | ||
2870 | case 12*MHZ: | ||
2871 | osc |= S3C_PHYCLK_CLKSEL_12M; | ||
2872 | break; | ||
2873 | case 24*MHZ: | ||
2874 | osc |= S3C_PHYCLK_CLKSEL_24M; | ||
2875 | break; | ||
2876 | default: | ||
2877 | case 48*MHZ: | ||
2878 | /* default reference clock */ | ||
2879 | break; | ||
2880 | } | ||
2881 | clk_put(xusbxti); | ||
2882 | } | ||
2883 | |||
2884 | writel(osc | 0x10, S3C_PHYCLK); | ||
2885 | |||
2886 | /* issue a full set of resets to the otg and core */ | ||
2887 | |||
2888 | writel(S3C_RSTCON_PHY, S3C_RSTCON); | ||
2889 | udelay(20); /* at-least 10uS */ | ||
2890 | writel(0, S3C_RSTCON); | ||
2891 | } | ||
2892 | |||
2893 | |||
2894 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | ||
2895 | { | 3105 | { |
2896 | u32 cfg4; | 3106 | u32 cfg2, cfg4; |
2897 | 3107 | /* check hardware configuration */ | |
2898 | /* unmask subset of endpoint interrupts */ | ||
2899 | |||
2900 | writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | | ||
2901 | S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk, | ||
2902 | hsotg->regs + S3C_DIEPMSK); | ||
2903 | |||
2904 | writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | | ||
2905 | S3C_DOEPMSK_EPDisbldMsk | S3C_DOEPMSK_XferComplMsk, | ||
2906 | hsotg->regs + S3C_DOEPMSK); | ||
2907 | |||
2908 | writel(0, hsotg->regs + S3C_DAINTMSK); | ||
2909 | |||
2910 | /* Be in disconnected state until gadget is registered */ | ||
2911 | __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon); | ||
2912 | |||
2913 | if (0) { | ||
2914 | /* post global nak until we're ready */ | ||
2915 | writel(S3C_DCTL_SGNPInNAK | S3C_DCTL_SGOUTNak, | ||
2916 | hsotg->regs + S3C_DCTL); | ||
2917 | } | ||
2918 | |||
2919 | /* setup fifos */ | ||
2920 | |||
2921 | dev_dbg(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", | ||
2922 | readl(hsotg->regs + S3C_GRXFSIZ), | ||
2923 | readl(hsotg->regs + S3C_GNPTXFSIZ)); | ||
2924 | |||
2925 | s3c_hsotg_init_fifo(hsotg); | ||
2926 | |||
2927 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | ||
2928 | writel(S3C_GUSBCFG_PHYIf16 | S3C_GUSBCFG_TOutCal(7) | (0x5 << 10), | ||
2929 | hsotg->regs + S3C_GUSBCFG); | ||
2930 | 3108 | ||
2931 | writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0, | 3109 | cfg2 = readl(hsotg->regs + 0x48); |
2932 | hsotg->regs + S3C_GAHBCFG); | 3110 | hsotg->num_of_eps = (cfg2 >> 10) & 0xF; |
2933 | 3111 | ||
2934 | /* check hardware configuration */ | 3112 | dev_info(hsotg->dev, "EPs:%d\n", hsotg->num_of_eps); |
2935 | 3113 | ||
2936 | cfg4 = readl(hsotg->regs + 0x50); | 3114 | cfg4 = readl(hsotg->regs + 0x50); |
2937 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; | 3115 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; |
@@ -2940,6 +3118,10 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2940 | hsotg->dedicated_fifos ? "dedicated" : "shared"); | 3118 | hsotg->dedicated_fifos ? "dedicated" : "shared"); |
2941 | } | 3119 | } |
2942 | 3120 | ||
3121 | /** | ||
3122 | * s3c_hsotg_dump - dump state of the udc | ||
3123 | * @param: The device state | ||
3124 | */ | ||
2943 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | 3125 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) |
2944 | { | 3126 | { |
2945 | #ifdef DEBUG | 3127 | #ifdef DEBUG |
@@ -2949,46 +3131,45 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | |||
2949 | int idx; | 3131 | int idx; |
2950 | 3132 | ||
2951 | dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n", | 3133 | dev_info(dev, "DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n", |
2952 | readl(regs + S3C_DCFG), readl(regs + S3C_DCTL), | 3134 | readl(regs + DCFG), readl(regs + DCTL), |
2953 | readl(regs + S3C_DIEPMSK)); | 3135 | readl(regs + DIEPMSK)); |
2954 | 3136 | ||
2955 | dev_info(dev, "GAHBCFG=0x%08x, 0x44=0x%08x\n", | 3137 | dev_info(dev, "GAHBCFG=0x%08x, 0x44=0x%08x\n", |
2956 | readl(regs + S3C_GAHBCFG), readl(regs + 0x44)); | 3138 | readl(regs + GAHBCFG), readl(regs + 0x44)); |
2957 | 3139 | ||
2958 | dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", | 3140 | dev_info(dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n", |
2959 | readl(regs + S3C_GRXFSIZ), readl(regs + S3C_GNPTXFSIZ)); | 3141 | readl(regs + GRXFSIZ), readl(regs + GNPTXFSIZ)); |
2960 | 3142 | ||
2961 | /* show periodic fifo settings */ | 3143 | /* show periodic fifo settings */ |
2962 | 3144 | ||
2963 | for (idx = 1; idx <= 15; idx++) { | 3145 | for (idx = 1; idx <= 15; idx++) { |
2964 | val = readl(regs + S3C_DPTXFSIZn(idx)); | 3146 | val = readl(regs + DPTXFSIZn(idx)); |
2965 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, | 3147 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, |
2966 | val >> S3C_DPTXFSIZn_DPTxFSize_SHIFT, | 3148 | val >> DPTXFSIZn_DPTxFSize_SHIFT, |
2967 | val & S3C_DPTXFSIZn_DPTxFStAddr_MASK); | 3149 | val & DPTXFSIZn_DPTxFStAddr_MASK); |
2968 | } | 3150 | } |
2969 | 3151 | ||
2970 | for (idx = 0; idx < 15; idx++) { | 3152 | for (idx = 0; idx < 15; idx++) { |
2971 | dev_info(dev, | 3153 | dev_info(dev, |
2972 | "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx, | 3154 | "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx, |
2973 | readl(regs + S3C_DIEPCTL(idx)), | 3155 | readl(regs + DIEPCTL(idx)), |
2974 | readl(regs + S3C_DIEPTSIZ(idx)), | 3156 | readl(regs + DIEPTSIZ(idx)), |
2975 | readl(regs + S3C_DIEPDMA(idx))); | 3157 | readl(regs + DIEPDMA(idx))); |
2976 | 3158 | ||
2977 | val = readl(regs + S3C_DOEPCTL(idx)); | 3159 | val = readl(regs + DOEPCTL(idx)); |
2978 | dev_info(dev, | 3160 | dev_info(dev, |
2979 | "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", | 3161 | "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", |
2980 | idx, readl(regs + S3C_DOEPCTL(idx)), | 3162 | idx, readl(regs + DOEPCTL(idx)), |
2981 | readl(regs + S3C_DOEPTSIZ(idx)), | 3163 | readl(regs + DOEPTSIZ(idx)), |
2982 | readl(regs + S3C_DOEPDMA(idx))); | 3164 | readl(regs + DOEPDMA(idx))); |
2983 | 3165 | ||
2984 | } | 3166 | } |
2985 | 3167 | ||
2986 | dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", | 3168 | dev_info(dev, "DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n", |
2987 | readl(regs + S3C_DVBUSDIS), readl(regs + S3C_DVBUSPULSE)); | 3169 | readl(regs + DVBUSDIS), readl(regs + DVBUSPULSE)); |
2988 | #endif | 3170 | #endif |
2989 | } | 3171 | } |
2990 | 3172 | ||
2991 | |||
2992 | /** | 3173 | /** |
2993 | * state_show - debugfs: show overall driver and device state. | 3174 | * state_show - debugfs: show overall driver and device state. |
2994 | * @seq: The seq file to write to. | 3175 | * @seq: The seq file to write to. |
@@ -3005,38 +3186,38 @@ static int state_show(struct seq_file *seq, void *v) | |||
3005 | int idx; | 3186 | int idx; |
3006 | 3187 | ||
3007 | seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", | 3188 | seq_printf(seq, "DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n", |
3008 | readl(regs + S3C_DCFG), | 3189 | readl(regs + DCFG), |
3009 | readl(regs + S3C_DCTL), | 3190 | readl(regs + DCTL), |
3010 | readl(regs + S3C_DSTS)); | 3191 | readl(regs + DSTS)); |
3011 | 3192 | ||
3012 | seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", | 3193 | seq_printf(seq, "DIEPMSK=0x%08x, DOEPMASK=0x%08x\n", |
3013 | readl(regs + S3C_DIEPMSK), readl(regs + S3C_DOEPMSK)); | 3194 | readl(regs + DIEPMSK), readl(regs + DOEPMSK)); |
3014 | 3195 | ||
3015 | seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", | 3196 | seq_printf(seq, "GINTMSK=0x%08x, GINTSTS=0x%08x\n", |
3016 | readl(regs + S3C_GINTMSK), | 3197 | readl(regs + GINTMSK), |
3017 | readl(regs + S3C_GINTSTS)); | 3198 | readl(regs + GINTSTS)); |
3018 | 3199 | ||
3019 | seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", | 3200 | seq_printf(seq, "DAINTMSK=0x%08x, DAINT=0x%08x\n", |
3020 | readl(regs + S3C_DAINTMSK), | 3201 | readl(regs + DAINTMSK), |
3021 | readl(regs + S3C_DAINT)); | 3202 | readl(regs + DAINT)); |
3022 | 3203 | ||
3023 | seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", | 3204 | seq_printf(seq, "GNPTXSTS=0x%08x, GRXSTSR=%08x\n", |
3024 | readl(regs + S3C_GNPTXSTS), | 3205 | readl(regs + GNPTXSTS), |
3025 | readl(regs + S3C_GRXSTSR)); | 3206 | readl(regs + GRXSTSR)); |
3026 | 3207 | ||
3027 | seq_printf(seq, "\nEndpoint status:\n"); | 3208 | seq_printf(seq, "\nEndpoint status:\n"); |
3028 | 3209 | ||
3029 | for (idx = 0; idx < 15; idx++) { | 3210 | for (idx = 0; idx < 15; idx++) { |
3030 | u32 in, out; | 3211 | u32 in, out; |
3031 | 3212 | ||
3032 | in = readl(regs + S3C_DIEPCTL(idx)); | 3213 | in = readl(regs + DIEPCTL(idx)); |
3033 | out = readl(regs + S3C_DOEPCTL(idx)); | 3214 | out = readl(regs + DOEPCTL(idx)); |
3034 | 3215 | ||
3035 | seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", | 3216 | seq_printf(seq, "ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x", |
3036 | idx, in, out); | 3217 | idx, in, out); |
3037 | 3218 | ||
3038 | in = readl(regs + S3C_DIEPTSIZ(idx)); | 3219 | in = readl(regs + DIEPTSIZ(idx)); |
3039 | out = readl(regs + S3C_DOEPTSIZ(idx)); | 3220 | out = readl(regs + DOEPTSIZ(idx)); |
3040 | 3221 | ||
3041 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", | 3222 | seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", |
3042 | in, out); | 3223 | in, out); |
@@ -3067,7 +3248,7 @@ static const struct file_operations state_fops = { | |||
3067 | * | 3248 | * |
3068 | * Show the FIFO information for the overall fifo and all the | 3249 | * Show the FIFO information for the overall fifo and all the |
3069 | * periodic transmission FIFOs. | 3250 | * periodic transmission FIFOs. |
3070 | */ | 3251 | */ |
3071 | static int fifo_show(struct seq_file *seq, void *v) | 3252 | static int fifo_show(struct seq_file *seq, void *v) |
3072 | { | 3253 | { |
3073 | struct s3c_hsotg *hsotg = seq->private; | 3254 | struct s3c_hsotg *hsotg = seq->private; |
@@ -3076,21 +3257,21 @@ static int fifo_show(struct seq_file *seq, void *v) | |||
3076 | int idx; | 3257 | int idx; |
3077 | 3258 | ||
3078 | seq_printf(seq, "Non-periodic FIFOs:\n"); | 3259 | seq_printf(seq, "Non-periodic FIFOs:\n"); |
3079 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + S3C_GRXFSIZ)); | 3260 | seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); |
3080 | 3261 | ||
3081 | val = readl(regs + S3C_GNPTXFSIZ); | 3262 | val = readl(regs + GNPTXFSIZ); |
3082 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", | 3263 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", |
3083 | val >> S3C_GNPTXFSIZ_NPTxFDep_SHIFT, | 3264 | val >> GNPTXFSIZ_NPTxFDep_SHIFT, |
3084 | val & S3C_GNPTXFSIZ_NPTxFStAddr_MASK); | 3265 | val & GNPTXFSIZ_NPTxFStAddr_MASK); |
3085 | 3266 | ||
3086 | seq_printf(seq, "\nPeriodic TXFIFOs:\n"); | 3267 | seq_printf(seq, "\nPeriodic TXFIFOs:\n"); |
3087 | 3268 | ||
3088 | for (idx = 1; idx <= 15; idx++) { | 3269 | for (idx = 1; idx <= 15; idx++) { |
3089 | val = readl(regs + S3C_DPTXFSIZn(idx)); | 3270 | val = readl(regs + DPTXFSIZn(idx)); |
3090 | 3271 | ||
3091 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, | 3272 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, |
3092 | val >> S3C_DPTXFSIZn_DPTxFSize_SHIFT, | 3273 | val >> DPTXFSIZn_DPTxFSize_SHIFT, |
3093 | val & S3C_DPTXFSIZn_DPTxFStAddr_MASK); | 3274 | val & DPTXFSIZn_DPTxFStAddr_MASK); |
3094 | } | 3275 | } |
3095 | 3276 | ||
3096 | return 0; | 3277 | return 0; |
@@ -3122,7 +3303,7 @@ static const char *decode_direction(int is_in) | |||
3122 | * | 3303 | * |
3123 | * This debugfs entry shows the state of the given endpoint (one is | 3304 | * This debugfs entry shows the state of the given endpoint (one is |
3124 | * registered for each available). | 3305 | * registered for each available). |
3125 | */ | 3306 | */ |
3126 | static int ep_show(struct seq_file *seq, void *v) | 3307 | static int ep_show(struct seq_file *seq, void *v) |
3127 | { | 3308 | { |
3128 | struct s3c_hsotg_ep *ep = seq->private; | 3309 | struct s3c_hsotg_ep *ep = seq->private; |
@@ -3139,20 +3320,20 @@ static int ep_show(struct seq_file *seq, void *v) | |||
3139 | /* first show the register state */ | 3320 | /* first show the register state */ |
3140 | 3321 | ||
3141 | seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", | 3322 | seq_printf(seq, "\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n", |
3142 | readl(regs + S3C_DIEPCTL(index)), | 3323 | readl(regs + DIEPCTL(index)), |
3143 | readl(regs + S3C_DOEPCTL(index))); | 3324 | readl(regs + DOEPCTL(index))); |
3144 | 3325 | ||
3145 | seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", | 3326 | seq_printf(seq, "\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n", |
3146 | readl(regs + S3C_DIEPDMA(index)), | 3327 | readl(regs + DIEPDMA(index)), |
3147 | readl(regs + S3C_DOEPDMA(index))); | 3328 | readl(regs + DOEPDMA(index))); |
3148 | 3329 | ||
3149 | seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", | 3330 | seq_printf(seq, "\tDIEPINT=0x%08x, DOEPINT=0x%08x\n", |
3150 | readl(regs + S3C_DIEPINT(index)), | 3331 | readl(regs + DIEPINT(index)), |
3151 | readl(regs + S3C_DOEPINT(index))); | 3332 | readl(regs + DOEPINT(index))); |
3152 | 3333 | ||
3153 | seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", | 3334 | seq_printf(seq, "\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n", |
3154 | readl(regs + S3C_DIEPTSIZ(index)), | 3335 | readl(regs + DIEPTSIZ(index)), |
3155 | readl(regs + S3C_DOEPTSIZ(index))); | 3336 | readl(regs + DOEPTSIZ(index))); |
3156 | 3337 | ||
3157 | seq_printf(seq, "\n"); | 3338 | seq_printf(seq, "\n"); |
3158 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); | 3339 | seq_printf(seq, "mps %d\n", ep->ep.maxpacket); |
@@ -3202,7 +3383,7 @@ static const struct file_operations ep_fops = { | |||
3202 | * about the state of the system. The directory name is created | 3383 | * about the state of the system. The directory name is created |
3203 | * with the same name as the device itself, in case we end up | 3384 | * with the same name as the device itself, in case we end up |
3204 | * with multiple blocks in future systems. | 3385 | * with multiple blocks in future systems. |
3205 | */ | 3386 | */ |
3206 | static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | 3387 | static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) |
3207 | { | 3388 | { |
3208 | struct dentry *root; | 3389 | struct dentry *root; |
@@ -3231,7 +3412,7 @@ static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | |||
3231 | 3412 | ||
3232 | /* create one file for each endpoint */ | 3413 | /* create one file for each endpoint */ |
3233 | 3414 | ||
3234 | for (epidx = 0; epidx < S3C_HSOTG_EPS; epidx++) { | 3415 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
3235 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; | 3416 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
3236 | 3417 | ||
3237 | ep->debugfs = debugfs_create_file(ep->name, 0444, | 3418 | ep->debugfs = debugfs_create_file(ep->name, 0444, |
@@ -3248,12 +3429,12 @@ static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | |||
3248 | * @hsotg: The driver state | 3429 | * @hsotg: The driver state |
3249 | * | 3430 | * |
3250 | * Cleanup (remove) the debugfs files for use on module exit. | 3431 | * Cleanup (remove) the debugfs files for use on module exit. |
3251 | */ | 3432 | */ |
3252 | static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | 3433 | static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) |
3253 | { | 3434 | { |
3254 | unsigned epidx; | 3435 | unsigned epidx; |
3255 | 3436 | ||
3256 | for (epidx = 0; epidx < S3C_HSOTG_EPS; epidx++) { | 3437 | for (epidx = 0; epidx < hsotg->num_of_eps; epidx++) { |
3257 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; | 3438 | struct s3c_hsotg_ep *ep = &hsotg->eps[epidx]; |
3258 | debugfs_remove(ep->debugfs); | 3439 | debugfs_remove(ep->debugfs); |
3259 | } | 3440 | } |
@@ -3264,48 +3445,39 @@ static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3264 | } | 3445 | } |
3265 | 3446 | ||
3266 | /** | 3447 | /** |
3267 | * s3c_hsotg_gate - set the hardware gate for the block | 3448 | * s3c_hsotg_release - release callback for hsotg device |
3268 | * @pdev: The device we bound to | 3449 | * @dev: Device to for which release is called |
3269 | * @on: On or off. | ||
3270 | * | ||
3271 | * Set the hardware gate setting into the block. If we end up on | ||
3272 | * something other than an S3C64XX, then we might need to change this | ||
3273 | * to using a platform data callback, or some other mechanism. | ||
3274 | */ | 3450 | */ |
3275 | static void s3c_hsotg_gate(struct platform_device *pdev, bool on) | 3451 | static void s3c_hsotg_release(struct device *dev) |
3276 | { | 3452 | { |
3277 | unsigned long flags; | 3453 | struct s3c_hsotg *hsotg = dev_get_drvdata(dev); |
3278 | u32 others; | ||
3279 | |||
3280 | local_irq_save(flags); | ||
3281 | |||
3282 | others = __raw_readl(S3C64XX_OTHERS); | ||
3283 | if (on) | ||
3284 | others |= S3C64XX_OTHERS_USBMASK; | ||
3285 | else | ||
3286 | others &= ~S3C64XX_OTHERS_USBMASK; | ||
3287 | __raw_writel(others, S3C64XX_OTHERS); | ||
3288 | 3454 | ||
3289 | local_irq_restore(flags); | 3455 | kfree(hsotg); |
3290 | } | 3456 | } |
3291 | 3457 | ||
3292 | static struct s3c_hsotg_plat s3c_hsotg_default_pdata; | 3458 | /** |
3459 | * s3c_hsotg_probe - probe function for hsotg driver | ||
3460 | * @pdev: The platform information for the driver | ||
3461 | */ | ||
3293 | 3462 | ||
3294 | static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | 3463 | static int __devinit s3c_hsotg_probe(struct platform_device *pdev) |
3295 | { | 3464 | { |
3296 | struct s3c_hsotg_plat *plat = pdev->dev.platform_data; | 3465 | struct s3c_hsotg_plat *plat = pdev->dev.platform_data; |
3297 | struct device *dev = &pdev->dev; | 3466 | struct device *dev = &pdev->dev; |
3467 | struct s3c_hsotg_ep *eps; | ||
3298 | struct s3c_hsotg *hsotg; | 3468 | struct s3c_hsotg *hsotg; |
3299 | struct resource *res; | 3469 | struct resource *res; |
3300 | int epnum; | 3470 | int epnum; |
3301 | int ret; | 3471 | int ret; |
3472 | int i; | ||
3302 | 3473 | ||
3303 | if (!plat) | 3474 | plat = pdev->dev.platform_data; |
3304 | plat = &s3c_hsotg_default_pdata; | 3475 | if (!plat) { |
3476 | dev_err(&pdev->dev, "no platform data defined\n"); | ||
3477 | return -EINVAL; | ||
3478 | } | ||
3305 | 3479 | ||
3306 | hsotg = kzalloc(sizeof(struct s3c_hsotg) + | 3480 | hsotg = kzalloc(sizeof(struct s3c_hsotg), GFP_KERNEL); |
3307 | sizeof(struct s3c_hsotg_ep) * S3C_HSOTG_EPS, | ||
3308 | GFP_KERNEL); | ||
3309 | if (!hsotg) { | 3481 | if (!hsotg) { |
3310 | dev_err(dev, "cannot get memory\n"); | 3482 | dev_err(dev, "cannot get memory\n"); |
3311 | return -ENOMEM; | 3483 | return -ENOMEM; |
@@ -3371,6 +3543,54 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3371 | 3543 | ||
3372 | hsotg->gadget.dev.parent = dev; | 3544 | hsotg->gadget.dev.parent = dev; |
3373 | hsotg->gadget.dev.dma_mask = dev->dma_mask; | 3545 | hsotg->gadget.dev.dma_mask = dev->dma_mask; |
3546 | hsotg->gadget.dev.release = s3c_hsotg_release; | ||
3547 | |||
3548 | /* reset the system */ | ||
3549 | |||
3550 | clk_prepare_enable(hsotg->clk); | ||
3551 | |||
3552 | /* regulators */ | ||
3553 | |||
3554 | for (i = 0; i < ARRAY_SIZE(hsotg->supplies); i++) | ||
3555 | hsotg->supplies[i].supply = s3c_hsotg_supply_names[i]; | ||
3556 | |||
3557 | ret = regulator_bulk_get(dev, ARRAY_SIZE(hsotg->supplies), | ||
3558 | hsotg->supplies); | ||
3559 | if (ret) { | ||
3560 | dev_err(dev, "failed to request supplies: %d\n", ret); | ||
3561 | goto err_irq; | ||
3562 | } | ||
3563 | |||
3564 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), | ||
3565 | hsotg->supplies); | ||
3566 | |||
3567 | if (ret) { | ||
3568 | dev_err(hsotg->dev, "failed to enable supplies: %d\n", ret); | ||
3569 | goto err_supplies; | ||
3570 | } | ||
3571 | |||
3572 | /* usb phy enable */ | ||
3573 | s3c_hsotg_phy_enable(hsotg); | ||
3574 | |||
3575 | s3c_hsotg_corereset(hsotg); | ||
3576 | s3c_hsotg_init(hsotg); | ||
3577 | s3c_hsotg_hw_cfg(hsotg); | ||
3578 | |||
3579 | /* hsotg->num_of_eps holds number of EPs other than ep0 */ | ||
3580 | |||
3581 | if (hsotg->num_of_eps == 0) { | ||
3582 | dev_err(dev, "wrong number of EPs (zero)\n"); | ||
3583 | goto err_supplies; | ||
3584 | } | ||
3585 | |||
3586 | eps = kcalloc(hsotg->num_of_eps + 1, sizeof(struct s3c_hsotg_ep), | ||
3587 | GFP_KERNEL); | ||
3588 | if (!eps) { | ||
3589 | dev_err(dev, "cannot get memory\n"); | ||
3590 | goto err_supplies; | ||
3591 | } | ||
3592 | |||
3593 | hsotg->eps = eps; | ||
3374 | 3594 | ||
3375 | /* setup endpoint information */ | 3595 | /* setup endpoint information */ |
3376 | 3596 | ||
@@ -3383,39 +3603,47 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | |||
3383 | GFP_KERNEL); | 3603 | GFP_KERNEL); |
3384 | if (!hsotg->ctrl_req) { | 3604 | if (!hsotg->ctrl_req) { |
3385 | dev_err(dev, "failed to allocate ctrl req\n"); | 3605 | dev_err(dev, "failed to allocate ctrl req\n"); |
3386 | goto err_regs; | 3606 | goto err_ep_mem; |
3387 | } | 3607 | } |
3388 | 3608 | ||
3389 | /* reset the system */ | 3609 | /* initialise the endpoints now the core has been initialised */ |
3610 | for (epnum = 0; epnum < hsotg->num_of_eps; epnum++) | ||
3611 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); | ||
3390 | 3612 | ||
3391 | clk_enable(hsotg->clk); | 3613 | /* disable power and clock */ |
3392 | 3614 | ||
3393 | s3c_hsotg_gate(pdev, true); | 3615 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
3616 | hsotg->supplies); | ||
3617 | if (ret) { | ||
3618 | dev_err(hsotg->dev, "failed to disable supplies: %d\n", ret); | ||
3619 | goto err_ep_mem; | ||
3620 | } | ||
3394 | 3621 | ||
3395 | s3c_hsotg_otgreset(hsotg); | 3622 | s3c_hsotg_phy_disable(hsotg); |
3396 | s3c_hsotg_corereset(hsotg); | ||
3397 | s3c_hsotg_init(hsotg); | ||
3398 | 3623 | ||
3399 | /* initialise the endpoints now the core has been initialised */ | 3624 | ret = device_add(&hsotg->gadget.dev); |
3400 | for (epnum = 0; epnum < S3C_HSOTG_EPS; epnum++) | 3625 | if (ret) { |
3401 | s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum); | 3626 | put_device(&hsotg->gadget.dev); |
3627 | goto err_ep_mem; | ||
3628 | } | ||
3402 | 3629 | ||
3403 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); | 3630 | ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); |
3404 | if (ret) | 3631 | if (ret) |
3405 | goto err_add_udc; | 3632 | goto err_ep_mem; |
3406 | 3633 | ||
3407 | s3c_hsotg_create_debug(hsotg); | 3634 | s3c_hsotg_create_debug(hsotg); |
3408 | 3635 | ||
3409 | s3c_hsotg_dump(hsotg); | 3636 | s3c_hsotg_dump(hsotg); |
3410 | 3637 | ||
3411 | our_hsotg = hsotg; | ||
3412 | return 0; | 3638 | return 0; |
3413 | 3639 | ||
3414 | err_add_udc: | 3640 | err_ep_mem: |
3415 | s3c_hsotg_gate(pdev, false); | 3641 | kfree(eps); |
3416 | clk_disable(hsotg->clk); | 3642 | err_supplies: |
3417 | clk_put(hsotg->clk); | 3643 | s3c_hsotg_phy_disable(hsotg); |
3418 | 3644 | regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); | |
3645 | err_irq: | ||
3646 | free_irq(hsotg->irq, hsotg); | ||
3419 | err_regs: | 3647 | err_regs: |
3420 | iounmap(hsotg->regs); | 3648 | iounmap(hsotg->regs); |
3421 | 3649 | ||
@@ -3423,12 +3651,17 @@ err_regs_res: | |||
3423 | release_resource(hsotg->regs_res); | 3651 | release_resource(hsotg->regs_res); |
3424 | kfree(hsotg->regs_res); | 3652 | kfree(hsotg->regs_res); |
3425 | err_clk: | 3653 | err_clk: |
3654 | clk_disable_unprepare(hsotg->clk); | ||
3426 | clk_put(hsotg->clk); | 3655 | clk_put(hsotg->clk); |
3427 | err_mem: | 3656 | err_mem: |
3428 | kfree(hsotg); | 3657 | kfree(hsotg); |
3429 | return ret; | 3658 | return ret; |
3430 | } | 3659 | } |
3431 | 3660 | ||
3661 | /** | ||
3662 | * s3c_hsotg_remove - remove function for hsotg driver | ||
3663 | * @pdev: The platform information for the driver | ||
3664 | */ | ||
3432 | static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | 3665 | static int __devexit s3c_hsotg_remove(struct platform_device *pdev) |
3433 | { | 3666 | { |
3434 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | 3667 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); |
@@ -3437,7 +3670,10 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | |||
3437 | 3670 | ||
3438 | s3c_hsotg_delete_debug(hsotg); | 3671 | s3c_hsotg_delete_debug(hsotg); |
3439 | 3672 | ||
3440 | usb_gadget_unregister_driver(hsotg->driver); | 3673 | if (hsotg->driver) { |
3674 | /* should have been done already by driver model core */ | ||
3675 | usb_gadget_unregister_driver(hsotg->driver); | ||
3676 | } | ||
3441 | 3677 | ||
3442 | free_irq(hsotg->irq, hsotg); | 3678 | free_irq(hsotg->irq, hsotg); |
3443 | iounmap(hsotg->regs); | 3679 | iounmap(hsotg->regs); |
@@ -3445,12 +3681,13 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | |||
3445 | release_resource(hsotg->regs_res); | 3681 | release_resource(hsotg->regs_res); |
3446 | kfree(hsotg->regs_res); | 3682 | kfree(hsotg->regs_res); |
3447 | 3683 | ||
3448 | s3c_hsotg_gate(pdev, false); | 3684 | s3c_hsotg_phy_disable(hsotg); |
3685 | regulator_bulk_free(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); | ||
3449 | 3686 | ||
3450 | clk_disable(hsotg->clk); | 3687 | clk_disable_unprepare(hsotg->clk); |
3451 | clk_put(hsotg->clk); | 3688 | clk_put(hsotg->clk); |
3452 | 3689 | ||
3453 | kfree(hsotg); | 3690 | device_unregister(&hsotg->gadget.dev); |
3454 | return 0; | 3691 | return 0; |
3455 | } | 3692 | } |
3456 | 3693 | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.h b/drivers/usb/gadget/s3c-hsotg.h new file mode 100644 index 000000000000..d650b1295831 --- /dev/null +++ b/drivers/usb/gadget/s3c-hsotg.h | |||
@@ -0,0 +1,377 @@ | |||
1 | /* drivers/usb/gadget/s3c-hsotg.h | ||
2 | * | ||
3 | * Copyright 2008 Openmoko, Inc. | ||
4 | * Copyright 2008 Simtec Electronics | ||
5 | * http://armlinux.simtec.co.uk/ | ||
6 | * Ben Dooks <ben@simtec.co.uk> | ||
7 | * | ||
8 | * USB2.0 Highspeed/OtG Synopsis DWC2 device block registers | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #ifndef __REGS_USB_HSOTG_H | ||
16 | #define __REGS_USB_HSOTG_H __FILE__ | ||
17 | |||
18 | #define HSOTG_REG(x) (x) | ||
19 | |||
20 | #define GOTGCTL HSOTG_REG(0x000) | ||
21 | #define GOTGCTL_BSESVLD (1 << 19) | ||
22 | #define GOTGCTL_ASESVLD (1 << 18) | ||
23 | #define GOTGCTL_DBNC_SHORT (1 << 17) | ||
24 | #define GOTGCTL_CONID_B (1 << 16) | ||
25 | #define GOTGCTL_DEVHNPEN (1 << 11) | ||
26 | #define GOTGCTL_HSSETHNPEN (1 << 10) | ||
27 | #define GOTGCTL_HNPREQ (1 << 9) | ||
28 | #define GOTGCTL_HSTNEGSCS (1 << 8) | ||
29 | #define GOTGCTL_SESREQ (1 << 1) | ||
30 | #define GOTGCTL_SESREQSCS (1 << 0) | ||
31 | |||
32 | #define GOTGINT HSOTG_REG(0x004) | ||
33 | #define GOTGINT_DbnceDone (1 << 19) | ||
34 | #define GOTGINT_ADevTOUTChg (1 << 18) | ||
35 | #define GOTGINT_HstNegDet (1 << 17) | ||
36 | #define GOTGINT_HstnegSucStsChng (1 << 9) | ||
37 | #define GOTGINT_SesReqSucStsChng (1 << 8) | ||
38 | #define GOTGINT_SesEndDet (1 << 2) | ||
39 | |||
40 | #define GAHBCFG HSOTG_REG(0x008) | ||
41 | #define GAHBCFG_PTxFEmpLvl (1 << 8) | ||
42 | #define GAHBCFG_NPTxFEmpLvl (1 << 7) | ||
43 | #define GAHBCFG_DMAEn (1 << 5) | ||
44 | #define GAHBCFG_HBstLen_MASK (0xf << 1) | ||
45 | #define GAHBCFG_HBstLen_SHIFT (1) | ||
46 | #define GAHBCFG_HBstLen_Single (0x0 << 1) | ||
47 | #define GAHBCFG_HBstLen_Incr (0x1 << 1) | ||
48 | #define GAHBCFG_HBstLen_Incr4 (0x3 << 1) | ||
49 | #define GAHBCFG_HBstLen_Incr8 (0x5 << 1) | ||
50 | #define GAHBCFG_HBstLen_Incr16 (0x7 << 1) | ||
51 | #define GAHBCFG_GlblIntrEn (1 << 0) | ||
52 | |||
53 | #define GUSBCFG HSOTG_REG(0x00C) | ||
54 | #define GUSBCFG_PHYLPClkSel (1 << 15) | ||
55 | #define GUSBCFG_HNPCap (1 << 9) | ||
56 | #define GUSBCFG_SRPCap (1 << 8) | ||
57 | #define GUSBCFG_PHYIf16 (1 << 3) | ||
58 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) | ||
59 | #define GUSBCFG_TOutCal_SHIFT (0) | ||
60 | #define GUSBCFG_TOutCal_LIMIT (0x7) | ||
61 | #define GUSBCFG_TOutCal(_x) ((_x) << 0) | ||
62 | |||
63 | #define GRSTCTL HSOTG_REG(0x010) | ||
64 | |||
65 | #define GRSTCTL_AHBIdle (1 << 31) | ||
66 | #define GRSTCTL_DMAReq (1 << 30) | ||
67 | #define GRSTCTL_TxFNum_MASK (0x1f << 6) | ||
68 | #define GRSTCTL_TxFNum_SHIFT (6) | ||
69 | #define GRSTCTL_TxFNum_LIMIT (0x1f) | ||
70 | #define GRSTCTL_TxFNum(_x) ((_x) << 6) | ||
71 | #define GRSTCTL_TxFFlsh (1 << 5) | ||
72 | #define GRSTCTL_RxFFlsh (1 << 4) | ||
73 | #define GRSTCTL_INTknQFlsh (1 << 3) | ||
74 | #define GRSTCTL_FrmCntrRst (1 << 2) | ||
75 | #define GRSTCTL_HSftRst (1 << 1) | ||
76 | #define GRSTCTL_CSftRst (1 << 0) | ||
77 | |||
78 | #define GINTSTS HSOTG_REG(0x014) | ||
79 | #define GINTMSK HSOTG_REG(0x018) | ||
80 | |||
81 | #define GINTSTS_WkUpInt (1 << 31) | ||
82 | #define GINTSTS_SessReqInt (1 << 30) | ||
83 | #define GINTSTS_DisconnInt (1 << 29) | ||
84 | #define GINTSTS_ConIDStsChng (1 << 28) | ||
85 | #define GINTSTS_PTxFEmp (1 << 26) | ||
86 | #define GINTSTS_HChInt (1 << 25) | ||
87 | #define GINTSTS_PrtInt (1 << 24) | ||
88 | #define GINTSTS_FetSusp (1 << 22) | ||
89 | #define GINTSTS_incompIP (1 << 21) | ||
90 | #define GINTSTS_IncomplSOIN (1 << 20) | ||
91 | #define GINTSTS_OEPInt (1 << 19) | ||
92 | #define GINTSTS_IEPInt (1 << 18) | ||
93 | #define GINTSTS_EPMis (1 << 17) | ||
94 | #define GINTSTS_EOPF (1 << 15) | ||
95 | #define GINTSTS_ISOutDrop (1 << 14) | ||
96 | #define GINTSTS_EnumDone (1 << 13) | ||
97 | #define GINTSTS_USBRst (1 << 12) | ||
98 | #define GINTSTS_USBSusp (1 << 11) | ||
99 | #define GINTSTS_ErlySusp (1 << 10) | ||
100 | #define GINTSTS_GOUTNakEff (1 << 7) | ||
101 | #define GINTSTS_GINNakEff (1 << 6) | ||
102 | #define GINTSTS_NPTxFEmp (1 << 5) | ||
103 | #define GINTSTS_RxFLvl (1 << 4) | ||
104 | #define GINTSTS_SOF (1 << 3) | ||
105 | #define GINTSTS_OTGInt (1 << 2) | ||
106 | #define GINTSTS_ModeMis (1 << 1) | ||
107 | #define GINTSTS_CurMod_Host (1 << 0) | ||
108 | |||
109 | #define GRXSTSR HSOTG_REG(0x01C) | ||
110 | #define GRXSTSP HSOTG_REG(0x020) | ||
111 | |||
112 | #define GRXSTS_FN_MASK (0x7f << 25) | ||
113 | #define GRXSTS_FN_SHIFT (25) | ||
114 | |||
115 | #define GRXSTS_PktSts_MASK (0xf << 17) | ||
116 | #define GRXSTS_PktSts_SHIFT (17) | ||
117 | #define GRXSTS_PktSts_GlobalOutNAK (0x1 << 17) | ||
118 | #define GRXSTS_PktSts_OutRX (0x2 << 17) | ||
119 | #define GRXSTS_PktSts_OutDone (0x3 << 17) | ||
120 | #define GRXSTS_PktSts_SetupDone (0x4 << 17) | ||
121 | #define GRXSTS_PktSts_SetupRX (0x6 << 17) | ||
122 | |||
123 | #define GRXSTS_DPID_MASK (0x3 << 15) | ||
124 | #define GRXSTS_DPID_SHIFT (15) | ||
125 | #define GRXSTS_ByteCnt_MASK (0x7ff << 4) | ||
126 | #define GRXSTS_ByteCnt_SHIFT (4) | ||
127 | #define GRXSTS_EPNum_MASK (0xf << 0) | ||
128 | #define GRXSTS_EPNum_SHIFT (0) | ||
129 | |||
130 | #define GRXFSIZ HSOTG_REG(0x024) | ||
131 | |||
132 | #define GNPTXFSIZ HSOTG_REG(0x028) | ||
133 | |||
134 | #define GNPTXFSIZ_NPTxFDep_MASK (0xffff << 16) | ||
135 | #define GNPTXFSIZ_NPTxFDep_SHIFT (16) | ||
136 | #define GNPTXFSIZ_NPTxFDep_LIMIT (0xffff) | ||
137 | #define GNPTXFSIZ_NPTxFDep(_x) ((_x) << 16) | ||
138 | #define GNPTXFSIZ_NPTxFStAddr_MASK (0xffff << 0) | ||
139 | #define GNPTXFSIZ_NPTxFStAddr_SHIFT (0) | ||
140 | #define GNPTXFSIZ_NPTxFStAddr_LIMIT (0xffff) | ||
141 | #define GNPTXFSIZ_NPTxFStAddr(_x) ((_x) << 0) | ||
142 | |||
143 | #define GNPTXSTS HSOTG_REG(0x02C) | ||
144 | |||
145 | #define GNPTXSTS_NPtxQTop_MASK (0x7f << 24) | ||
146 | #define GNPTXSTS_NPtxQTop_SHIFT (24) | ||
147 | |||
148 | #define GNPTXSTS_NPTxQSpcAvail_MASK (0xff << 16) | ||
149 | #define GNPTXSTS_NPTxQSpcAvail_SHIFT (16) | ||
150 | #define GNPTXSTS_NPTxQSpcAvail_GET(_v) (((_v) >> 16) & 0xff) | ||
151 | |||
152 | #define GNPTXSTS_NPTxFSpcAvail_MASK (0xffff << 0) | ||
153 | #define GNPTXSTS_NPTxFSpcAvail_SHIFT (0) | ||
154 | #define GNPTXSTS_NPTxFSpcAvail_GET(_v) (((_v) >> 0) & 0xffff) | ||
155 | |||
156 | |||
157 | #define HPTXFSIZ HSOTG_REG(0x100) | ||
158 | |||
159 | #define DPTXFSIZn(_a) HSOTG_REG(0x104 + (((_a) - 1) * 4)) | ||
160 | |||
161 | #define DPTXFSIZn_DPTxFSize_MASK (0xffff << 16) | ||
162 | #define DPTXFSIZn_DPTxFSize_SHIFT (16) | ||
163 | #define DPTXFSIZn_DPTxFSize_GET(_v) (((_v) >> 16) & 0xffff) | ||
164 | #define DPTXFSIZn_DPTxFSize_LIMIT (0xffff) | ||
165 | #define DPTXFSIZn_DPTxFSize(_x) ((_x) << 16) | ||
166 | |||
167 | #define DPTXFSIZn_DPTxFStAddr_MASK (0xffff << 0) | ||
168 | #define DPTXFSIZn_DPTxFStAddr_SHIFT (0) | ||
169 | |||
170 | /* Device mode registers */ | ||
171 | #define DCFG HSOTG_REG(0x800) | ||
172 | |||
173 | #define DCFG_EPMisCnt_MASK (0x1f << 18) | ||
174 | #define DCFG_EPMisCnt_SHIFT (18) | ||
175 | #define DCFG_EPMisCnt_LIMIT (0x1f) | ||
176 | #define DCFG_EPMisCnt(_x) ((_x) << 18) | ||
177 | |||
178 | #define DCFG_PerFrInt_MASK (0x3 << 11) | ||
179 | #define DCFG_PerFrInt_SHIFT (11) | ||
180 | #define DCFG_PerFrInt_LIMIT (0x3) | ||
181 | #define DCFG_PerFrInt(_x) ((_x) << 11) | ||
182 | |||
183 | #define DCFG_DevAddr_MASK (0x7f << 4) | ||
184 | #define DCFG_DevAddr_SHIFT (4) | ||
185 | #define DCFG_DevAddr_LIMIT (0x7f) | ||
186 | #define DCFG_DevAddr(_x) ((_x) << 4) | ||
187 | |||
188 | #define DCFG_NZStsOUTHShk (1 << 2) | ||
189 | |||
190 | #define DCFG_DevSpd_MASK (0x3 << 0) | ||
191 | #define DCFG_DevSpd_SHIFT (0) | ||
192 | #define DCFG_DevSpd_HS (0x0 << 0) | ||
193 | #define DCFG_DevSpd_FS (0x1 << 0) | ||
194 | #define DCFG_DevSpd_LS (0x2 << 0) | ||
195 | #define DCFG_DevSpd_FS48 (0x3 << 0) | ||
196 | |||
197 | #define DCTL HSOTG_REG(0x804) | ||
198 | |||
199 | #define DCTL_PWROnPrgDone (1 << 11) | ||
200 | #define DCTL_CGOUTNak (1 << 10) | ||
201 | #define DCTL_SGOUTNak (1 << 9) | ||
202 | #define DCTL_CGNPInNAK (1 << 8) | ||
203 | #define DCTL_SGNPInNAK (1 << 7) | ||
204 | #define DCTL_TstCtl_MASK (0x7 << 4) | ||
205 | #define DCTL_TstCtl_SHIFT (4) | ||
206 | #define DCTL_GOUTNakSts (1 << 3) | ||
207 | #define DCTL_GNPINNakSts (1 << 2) | ||
208 | #define DCTL_SftDiscon (1 << 1) | ||
209 | #define DCTL_RmtWkUpSig (1 << 0) | ||
210 | |||
211 | #define DSTS HSOTG_REG(0x808) | ||
212 | |||
213 | #define DSTS_SOFFN_MASK (0x3fff << 8) | ||
214 | #define DSTS_SOFFN_SHIFT (8) | ||
215 | #define DSTS_SOFFN_LIMIT (0x3fff) | ||
216 | #define DSTS_SOFFN(_x) ((_x) << 8) | ||
217 | #define DSTS_ErraticErr (1 << 3) | ||
218 | #define DSTS_EnumSpd_MASK (0x3 << 1) | ||
219 | #define DSTS_EnumSpd_SHIFT (1) | ||
220 | #define DSTS_EnumSpd_HS (0x0 << 1) | ||
221 | #define DSTS_EnumSpd_FS (0x1 << 1) | ||
222 | #define DSTS_EnumSpd_LS (0x2 << 1) | ||
223 | #define DSTS_EnumSpd_FS48 (0x3 << 1) | ||
224 | |||
225 | #define DSTS_SuspSts (1 << 0) | ||
226 | |||
227 | #define DIEPMSK HSOTG_REG(0x810) | ||
228 | |||
229 | #define DIEPMSK_TxFIFOEmpty (1 << 7) | ||
230 | #define DIEPMSK_INEPNakEffMsk (1 << 6) | ||
231 | #define DIEPMSK_INTknEPMisMsk (1 << 5) | ||
232 | #define DIEPMSK_INTknTXFEmpMsk (1 << 4) | ||
233 | #define DIEPMSK_TimeOUTMsk (1 << 3) | ||
234 | #define DIEPMSK_AHBErrMsk (1 << 2) | ||
235 | #define DIEPMSK_EPDisbldMsk (1 << 1) | ||
236 | #define DIEPMSK_XferComplMsk (1 << 0) | ||
237 | |||
238 | #define DOEPMSK HSOTG_REG(0x814) | ||
239 | |||
240 | #define DOEPMSK_Back2BackSetup (1 << 6) | ||
241 | #define DOEPMSK_OUTTknEPdisMsk (1 << 4) | ||
242 | #define DOEPMSK_SetupMsk (1 << 3) | ||
243 | #define DOEPMSK_AHBErrMsk (1 << 2) | ||
244 | #define DOEPMSK_EPDisbldMsk (1 << 1) | ||
245 | #define DOEPMSK_XferComplMsk (1 << 0) | ||
246 | |||
247 | #define DAINT HSOTG_REG(0x818) | ||
248 | #define DAINTMSK HSOTG_REG(0x81C) | ||
249 | |||
250 | #define DAINT_OutEP_SHIFT (16) | ||
251 | #define DAINT_OutEP(x) (1 << ((x) + 16)) | ||
252 | #define DAINT_InEP(x) (1 << (x)) | ||
253 | |||
254 | #define DTKNQR1 HSOTG_REG(0x820) | ||
255 | #define DTKNQR2 HSOTG_REG(0x824) | ||
256 | #define DTKNQR3 HSOTG_REG(0x830) | ||
257 | #define DTKNQR4 HSOTG_REG(0x834) | ||
258 | |||
259 | #define DVBUSDIS HSOTG_REG(0x828) | ||
260 | #define DVBUSPULSE HSOTG_REG(0x82C) | ||
261 | |||
262 | #define DIEPCTL0 HSOTG_REG(0x900) | ||
263 | #define DOEPCTL0 HSOTG_REG(0xB00) | ||
264 | #define DIEPCTL(_a) HSOTG_REG(0x900 + ((_a) * 0x20)) | ||
265 | #define DOEPCTL(_a) HSOTG_REG(0xB00 + ((_a) * 0x20)) | ||
266 | |||
267 | /* EP0 specialness: | ||
268 | * bits[29..28] - reserved (no SetD0PID, SetD1PID) | ||
269 | * bits[25..22] - should always be zero, this isn't a periodic endpoint | ||
270 | * bits[10..0] - MPS setting differenct for EP0 | ||
271 | */ | ||
272 | #define D0EPCTL_MPS_MASK (0x3 << 0) | ||
273 | #define D0EPCTL_MPS_SHIFT (0) | ||
274 | #define D0EPCTL_MPS_64 (0x0 << 0) | ||
275 | #define D0EPCTL_MPS_32 (0x1 << 0) | ||
276 | #define D0EPCTL_MPS_16 (0x2 << 0) | ||
277 | #define D0EPCTL_MPS_8 (0x3 << 0) | ||
278 | |||
279 | #define DxEPCTL_EPEna (1 << 31) | ||
280 | #define DxEPCTL_EPDis (1 << 30) | ||
281 | #define DxEPCTL_SetD1PID (1 << 29) | ||
282 | #define DxEPCTL_SetOddFr (1 << 29) | ||
283 | #define DxEPCTL_SetD0PID (1 << 28) | ||
284 | #define DxEPCTL_SetEvenFr (1 << 28) | ||
285 | #define DxEPCTL_SNAK (1 << 27) | ||
286 | #define DxEPCTL_CNAK (1 << 26) | ||
287 | #define DxEPCTL_TxFNum_MASK (0xf << 22) | ||
288 | #define DxEPCTL_TxFNum_SHIFT (22) | ||
289 | #define DxEPCTL_TxFNum_LIMIT (0xf) | ||
290 | #define DxEPCTL_TxFNum(_x) ((_x) << 22) | ||
291 | |||
292 | #define DxEPCTL_Stall (1 << 21) | ||
293 | #define DxEPCTL_Snp (1 << 20) | ||
294 | #define DxEPCTL_EPType_MASK (0x3 << 18) | ||
295 | #define DxEPCTL_EPType_SHIFT (18) | ||
296 | #define DxEPCTL_EPType_Control (0x0 << 18) | ||
297 | #define DxEPCTL_EPType_Iso (0x1 << 18) | ||
298 | #define DxEPCTL_EPType_Bulk (0x2 << 18) | ||
299 | #define DxEPCTL_EPType_Intterupt (0x3 << 18) | ||
300 | |||
301 | #define DxEPCTL_NAKsts (1 << 17) | ||
302 | #define DxEPCTL_DPID (1 << 16) | ||
303 | #define DxEPCTL_EOFrNum (1 << 16) | ||
304 | #define DxEPCTL_USBActEp (1 << 15) | ||
305 | #define DxEPCTL_NextEp_MASK (0xf << 11) | ||
306 | #define DxEPCTL_NextEp_SHIFT (11) | ||
307 | #define DxEPCTL_NextEp_LIMIT (0xf) | ||
308 | #define DxEPCTL_NextEp(_x) ((_x) << 11) | ||
309 | |||
310 | #define DxEPCTL_MPS_MASK (0x7ff << 0) | ||
311 | #define DxEPCTL_MPS_SHIFT (0) | ||
312 | #define DxEPCTL_MPS_LIMIT (0x7ff) | ||
313 | #define DxEPCTL_MPS(_x) ((_x) << 0) | ||
314 | |||
315 | #define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20)) | ||
316 | #define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20)) | ||
317 | |||
318 | #define DxEPINT_INEPNakEff (1 << 6) | ||
319 | #define DxEPINT_Back2BackSetup (1 << 6) | ||
320 | #define DxEPINT_INTknEPMis (1 << 5) | ||
321 | #define DxEPINT_INTknTXFEmp (1 << 4) | ||
322 | #define DxEPINT_OUTTknEPdis (1 << 4) | ||
323 | #define DxEPINT_Timeout (1 << 3) | ||
324 | #define DxEPINT_Setup (1 << 3) | ||
325 | #define DxEPINT_AHBErr (1 << 2) | ||
326 | #define DxEPINT_EPDisbld (1 << 1) | ||
327 | #define DxEPINT_XferCompl (1 << 0) | ||
328 | |||
329 | #define DIEPTSIZ0 HSOTG_REG(0x910) | ||
330 | |||
331 | #define DIEPTSIZ0_PktCnt_MASK (0x3 << 19) | ||
332 | #define DIEPTSIZ0_PktCnt_SHIFT (19) | ||
333 | #define DIEPTSIZ0_PktCnt_LIMIT (0x3) | ||
334 | #define DIEPTSIZ0_PktCnt(_x) ((_x) << 19) | ||
335 | |||
336 | #define DIEPTSIZ0_XferSize_MASK (0x7f << 0) | ||
337 | #define DIEPTSIZ0_XferSize_SHIFT (0) | ||
338 | #define DIEPTSIZ0_XferSize_LIMIT (0x7f) | ||
339 | #define DIEPTSIZ0_XferSize(_x) ((_x) << 0) | ||
340 | |||
341 | #define DOEPTSIZ0 HSOTG_REG(0xB10) | ||
342 | #define DOEPTSIZ0_SUPCnt_MASK (0x3 << 29) | ||
343 | #define DOEPTSIZ0_SUPCnt_SHIFT (29) | ||
344 | #define DOEPTSIZ0_SUPCnt_LIMIT (0x3) | ||
345 | #define DOEPTSIZ0_SUPCnt(_x) ((_x) << 29) | ||
346 | |||
347 | #define DOEPTSIZ0_PktCnt (1 << 19) | ||
348 | #define DOEPTSIZ0_XferSize_MASK (0x7f << 0) | ||
349 | #define DOEPTSIZ0_XferSize_SHIFT (0) | ||
350 | |||
351 | #define DIEPTSIZ(_a) HSOTG_REG(0x910 + ((_a) * 0x20)) | ||
352 | #define DOEPTSIZ(_a) HSOTG_REG(0xB10 + ((_a) * 0x20)) | ||
353 | |||
354 | #define DxEPTSIZ_MC_MASK (0x3 << 29) | ||
355 | #define DxEPTSIZ_MC_SHIFT (29) | ||
356 | #define DxEPTSIZ_MC_LIMIT (0x3) | ||
357 | #define DxEPTSIZ_MC(_x) ((_x) << 29) | ||
358 | |||
359 | #define DxEPTSIZ_PktCnt_MASK (0x3ff << 19) | ||
360 | #define DxEPTSIZ_PktCnt_SHIFT (19) | ||
361 | #define DxEPTSIZ_PktCnt_GET(_v) (((_v) >> 19) & 0x3ff) | ||
362 | #define DxEPTSIZ_PktCnt_LIMIT (0x3ff) | ||
363 | #define DxEPTSIZ_PktCnt(_x) ((_x) << 19) | ||
364 | |||
365 | #define DxEPTSIZ_XferSize_MASK (0x7ffff << 0) | ||
366 | #define DxEPTSIZ_XferSize_SHIFT (0) | ||
367 | #define DxEPTSIZ_XferSize_GET(_v) (((_v) >> 0) & 0x7ffff) | ||
368 | #define DxEPTSIZ_XferSize_LIMIT (0x7ffff) | ||
369 | #define DxEPTSIZ_XferSize(_x) ((_x) << 0) | ||
370 | |||
371 | #define DIEPDMA(_a) HSOTG_REG(0x914 + ((_a) * 0x20)) | ||
372 | #define DOEPDMA(_a) HSOTG_REG(0xB14 + ((_a) * 0x20)) | ||
373 | #define DTXFSTS(_a) HSOTG_REG(0x918 + ((_a) * 0x20)) | ||
374 | |||
375 | #define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000)) | ||
376 | |||
377 | #endif /* __REGS_USB_HSOTG_H */ | ||
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c index cef9b82ff911..36c6836eeb0f 100644 --- a/drivers/usb/gadget/s3c-hsudc.c +++ b/drivers/usb/gadget/s3c-hsudc.c | |||
@@ -110,7 +110,6 @@ struct s3c_hsudc_ep { | |||
110 | struct usb_ep ep; | 110 | struct usb_ep ep; |
111 | char name[20]; | 111 | char name[20]; |
112 | struct s3c_hsudc *dev; | 112 | struct s3c_hsudc *dev; |
113 | const struct usb_endpoint_descriptor *desc; | ||
114 | struct list_head queue; | 113 | struct list_head queue; |
115 | u8 stopped; | 114 | u8 stopped; |
116 | u8 wedge; | 115 | u8 wedge; |
@@ -761,7 +760,7 @@ static int s3c_hsudc_ep_enable(struct usb_ep *_ep, | |||
761 | u32 ecr = 0; | 760 | u32 ecr = 0; |
762 | 761 | ||
763 | hsep = our_ep(_ep); | 762 | hsep = our_ep(_ep); |
764 | if (!_ep || !desc || hsep->desc || _ep->name == ep0name | 763 | if (!_ep || !desc || hsep->ep.desc || _ep->name == ep0name |
765 | || desc->bDescriptorType != USB_DT_ENDPOINT | 764 | || desc->bDescriptorType != USB_DT_ENDPOINT |
766 | || hsep->bEndpointAddress != desc->bEndpointAddress | 765 | || hsep->bEndpointAddress != desc->bEndpointAddress |
767 | || ep_maxpacket(hsep) < usb_endpoint_maxp(desc)) | 766 | || ep_maxpacket(hsep) < usb_endpoint_maxp(desc)) |
@@ -783,7 +782,7 @@ static int s3c_hsudc_ep_enable(struct usb_ep *_ep, | |||
783 | writel(ecr, hsudc->regs + S3C_ECR); | 782 | writel(ecr, hsudc->regs + S3C_ECR); |
784 | 783 | ||
785 | hsep->stopped = hsep->wedge = 0; | 784 | hsep->stopped = hsep->wedge = 0; |
786 | hsep->desc = desc; | 785 | hsep->ep.desc = desc; |
787 | hsep->ep.maxpacket = usb_endpoint_maxp(desc); | 786 | hsep->ep.maxpacket = usb_endpoint_maxp(desc); |
788 | 787 | ||
789 | s3c_hsudc_set_halt(_ep, 0); | 788 | s3c_hsudc_set_halt(_ep, 0); |
@@ -806,7 +805,7 @@ static int s3c_hsudc_ep_disable(struct usb_ep *_ep) | |||
806 | struct s3c_hsudc *hsudc = hsep->dev; | 805 | struct s3c_hsudc *hsudc = hsep->dev; |
807 | unsigned long flags; | 806 | unsigned long flags; |
808 | 807 | ||
809 | if (!_ep || !hsep->desc) | 808 | if (!_ep || !hsep->ep.desc) |
810 | return -EINVAL; | 809 | return -EINVAL; |
811 | 810 | ||
812 | spin_lock_irqsave(&hsudc->lock, flags); | 811 | spin_lock_irqsave(&hsudc->lock, flags); |
@@ -816,7 +815,6 @@ static int s3c_hsudc_ep_disable(struct usb_ep *_ep) | |||
816 | 815 | ||
817 | s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); | 816 | s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); |
818 | 817 | ||
819 | hsep->desc = 0; | ||
820 | hsep->ep.desc = NULL; | 818 | hsep->ep.desc = NULL; |
821 | hsep->stopped = 1; | 819 | hsep->stopped = 1; |
822 | 820 | ||
@@ -1006,7 +1004,6 @@ static void s3c_hsudc_initep(struct s3c_hsudc *hsudc, | |||
1006 | hsep->ep.maxpacket = epnum ? 512 : 64; | 1004 | hsep->ep.maxpacket = epnum ? 512 : 64; |
1007 | hsep->ep.ops = &s3c_hsudc_ep_ops; | 1005 | hsep->ep.ops = &s3c_hsudc_ep_ops; |
1008 | hsep->fifo = hsudc->regs + S3C_BR(epnum); | 1006 | hsep->fifo = hsudc->regs + S3C_BR(epnum); |
1009 | hsep->desc = 0; | ||
1010 | hsep->ep.desc = NULL; | 1007 | hsep->ep.desc = NULL; |
1011 | hsep->stopped = 0; | 1008 | hsep->stopped = 0; |
1012 | hsep->wedge = 0; | 1009 | hsep->wedge = 0; |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index 195524cde6c3..3de71d37d75e 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -1062,7 +1062,7 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep, | |||
1062 | 1062 | ||
1063 | ep = to_s3c2410_ep(_ep); | 1063 | ep = to_s3c2410_ep(_ep); |
1064 | 1064 | ||
1065 | if (!_ep || !desc || ep->desc | 1065 | if (!_ep || !desc || ep->ep.desc |
1066 | || _ep->name == ep0name | 1066 | || _ep->name == ep0name |
1067 | || desc->bDescriptorType != USB_DT_ENDPOINT) | 1067 | || desc->bDescriptorType != USB_DT_ENDPOINT) |
1068 | return -EINVAL; | 1068 | return -EINVAL; |
@@ -1075,7 +1075,7 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep, | |||
1075 | 1075 | ||
1076 | local_irq_save (flags); | 1076 | local_irq_save (flags); |
1077 | _ep->maxpacket = max & 0x7ff; | 1077 | _ep->maxpacket = max & 0x7ff; |
1078 | ep->desc = desc; | 1078 | ep->ep.desc = desc; |
1079 | ep->halted = 0; | 1079 | ep->halted = 0; |
1080 | ep->bEndpointAddress = desc->bEndpointAddress; | 1080 | ep->bEndpointAddress = desc->bEndpointAddress; |
1081 | 1081 | ||
@@ -1136,7 +1136,7 @@ static int s3c2410_udc_ep_disable(struct usb_ep *_ep) | |||
1136 | unsigned long flags; | 1136 | unsigned long flags; |
1137 | u32 int_en_reg; | 1137 | u32 int_en_reg; |
1138 | 1138 | ||
1139 | if (!_ep || !ep->desc) { | 1139 | if (!_ep || !ep->ep.desc) { |
1140 | dprintk(DEBUG_NORMAL, "%s not enabled\n", | 1140 | dprintk(DEBUG_NORMAL, "%s not enabled\n", |
1141 | _ep ? ep->ep.name : NULL); | 1141 | _ep ? ep->ep.name : NULL); |
1142 | return -EINVAL; | 1142 | return -EINVAL; |
@@ -1146,7 +1146,6 @@ static int s3c2410_udc_ep_disable(struct usb_ep *_ep) | |||
1146 | 1146 | ||
1147 | dprintk(DEBUG_NORMAL, "ep_disable: %s\n", _ep->name); | 1147 | dprintk(DEBUG_NORMAL, "ep_disable: %s\n", _ep->name); |
1148 | 1148 | ||
1149 | ep->desc = NULL; | ||
1150 | ep->ep.desc = NULL; | 1149 | ep->ep.desc = NULL; |
1151 | ep->halted = 1; | 1150 | ep->halted = 1; |
1152 | 1151 | ||
@@ -1195,7 +1194,7 @@ s3c2410_udc_free_request(struct usb_ep *_ep, struct usb_request *_req) | |||
1195 | 1194 | ||
1196 | dprintk(DEBUG_VERBOSE, "%s(%p,%p)\n", __func__, _ep, _req); | 1195 | dprintk(DEBUG_VERBOSE, "%s(%p,%p)\n", __func__, _ep, _req); |
1197 | 1196 | ||
1198 | if (!ep || !_req || (!ep->desc && _ep->name != ep0name)) | 1197 | if (!ep || !_req || (!ep->ep.desc && _ep->name != ep0name)) |
1199 | return; | 1198 | return; |
1200 | 1199 | ||
1201 | WARN_ON (!list_empty (&req->queue)); | 1200 | WARN_ON (!list_empty (&req->queue)); |
@@ -1215,7 +1214,7 @@ static int s3c2410_udc_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
1215 | int fifo_count = 0; | 1214 | int fifo_count = 0; |
1216 | unsigned long flags; | 1215 | unsigned long flags; |
1217 | 1216 | ||
1218 | if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) { | 1217 | if (unlikely(!_ep || (!ep->ep.desc && ep->ep.name != ep0name))) { |
1219 | dprintk(DEBUG_NORMAL, "%s: invalid args\n", __func__); | 1218 | dprintk(DEBUG_NORMAL, "%s: invalid args\n", __func__); |
1220 | return -EINVAL; | 1219 | return -EINVAL; |
1221 | } | 1220 | } |
@@ -1363,7 +1362,7 @@ static int s3c2410_udc_set_halt(struct usb_ep *_ep, int value) | |||
1363 | unsigned long flags; | 1362 | unsigned long flags; |
1364 | u32 idx; | 1363 | u32 idx; |
1365 | 1364 | ||
1366 | if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) { | 1365 | if (unlikely(!_ep || (!ep->ep.desc && ep->ep.name != ep0name))) { |
1367 | dprintk(DEBUG_NORMAL, "%s: inval 2\n", __func__); | 1366 | dprintk(DEBUG_NORMAL, "%s: inval 2\n", __func__); |
1368 | return -EINVAL; | 1367 | return -EINVAL; |
1369 | } | 1368 | } |
@@ -1629,7 +1628,6 @@ static void s3c2410_udc_reinit(struct s3c2410_udc *dev) | |||
1629 | list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); | 1628 | list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); |
1630 | 1629 | ||
1631 | ep->dev = dev; | 1630 | ep->dev = dev; |
1632 | ep->desc = NULL; | ||
1633 | ep->ep.desc = NULL; | 1631 | ep->ep.desc = NULL; |
1634 | ep->halted = 0; | 1632 | ep->halted = 0; |
1635 | INIT_LIST_HEAD (&ep->queue); | 1633 | INIT_LIST_HEAD (&ep->queue); |
diff --git a/drivers/usb/gadget/s3c2410_udc.h b/drivers/usb/gadget/s3c2410_udc.h index 1653bae08b80..3e80fd5c820f 100644 --- a/drivers/usb/gadget/s3c2410_udc.h +++ b/drivers/usb/gadget/s3c2410_udc.h | |||
@@ -19,7 +19,6 @@ struct s3c2410_ep { | |||
19 | unsigned long last_io; /* jiffies timestamp */ | 19 | unsigned long last_io; /* jiffies timestamp */ |
20 | struct usb_gadget *gadget; | 20 | struct usb_gadget *gadget; |
21 | struct s3c2410_udc *dev; | 21 | struct s3c2410_udc *dev; |
22 | const struct usb_endpoint_descriptor *desc; | ||
23 | struct usb_ep ep; | 22 | struct usb_ep ep; |
24 | u8 num; | 23 | u8 num; |
25 | 24 | ||
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c new file mode 100644 index 000000000000..c46439c8dd74 --- /dev/null +++ b/drivers/usb/gadget/tcm_usb_gadget.c | |||
@@ -0,0 +1,2480 @@ | |||
1 | /* Target based USB-Gadget | ||
2 | * | ||
3 | * UAS protocol handling, target callbacks, configfs handling, | ||
4 | * BBB (USB Mass Storage Class Bulk-Only (BBB) and Transport protocol handling. | ||
5 | * | ||
6 | * Author: Sebastian Andrzej Siewior <bigeasy at linutronix dot de> | ||
7 | * License: GPLv2 as published by FSF. | ||
8 | */ | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/configfs.h> | ||
14 | #include <linux/ctype.h> | ||
15 | #include <linux/usb/ch9.h> | ||
16 | #include <linux/usb/composite.h> | ||
17 | #include <linux/usb/gadget.h> | ||
18 | #include <linux/usb/storage.h> | ||
19 | #include <scsi/scsi.h> | ||
20 | #include <scsi/scsi_tcq.h> | ||
21 | #include <target/target_core_base.h> | ||
22 | #include <target/target_core_fabric.h> | ||
23 | #include <target/target_core_fabric_configfs.h> | ||
24 | #include <target/target_core_configfs.h> | ||
25 | #include <target/configfs_macros.h> | ||
26 | #include <asm/unaligned.h> | ||
27 | |||
28 | #include "usbstring.c" | ||
29 | #include "epautoconf.c" | ||
30 | #include "config.c" | ||
31 | #include "composite.c" | ||
32 | |||
33 | #include "tcm_usb_gadget.h" | ||
34 | |||
35 | static struct target_fabric_configfs *usbg_fabric_configfs; | ||
36 | |||
37 | static inline struct f_uas *to_f_uas(struct usb_function *f) | ||
38 | { | ||
39 | return container_of(f, struct f_uas, function); | ||
40 | } | ||
41 | |||
42 | static void usbg_cmd_release(struct kref *); | ||
43 | |||
44 | static inline void usbg_cleanup_cmd(struct usbg_cmd *cmd) | ||
45 | { | ||
46 | kref_put(&cmd->ref, usbg_cmd_release); | ||
47 | } | ||
48 | |||
49 | /* Start bot.c code */ | ||
50 | |||
51 | static int bot_enqueue_cmd_cbw(struct f_uas *fu) | ||
52 | { | ||
53 | int ret; | ||
54 | |||
55 | if (fu->flags & USBG_BOT_CMD_PEND) | ||
56 | return 0; | ||
57 | |||
58 | ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); | ||
59 | if (!ret) | ||
60 | fu->flags |= USBG_BOT_CMD_PEND; | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | static void bot_status_complete(struct usb_ep *ep, struct usb_request *req) | ||
65 | { | ||
66 | struct usbg_cmd *cmd = req->context; | ||
67 | struct f_uas *fu = cmd->fu; | ||
68 | |||
69 | usbg_cleanup_cmd(cmd); | ||
70 | if (req->status < 0) { | ||
71 | pr_err("ERR %s(%d)\n", __func__, __LINE__); | ||
72 | return; | ||
73 | } | ||
74 | |||
75 | /* CSW completed, wait for next CBW */ | ||
76 | bot_enqueue_cmd_cbw(fu); | ||
77 | } | ||
78 | |||
79 | static void bot_enqueue_sense_code(struct f_uas *fu, struct usbg_cmd *cmd) | ||
80 | { | ||
81 | struct bulk_cs_wrap *csw = &fu->bot_status.csw; | ||
82 | int ret; | ||
83 | u8 *sense; | ||
84 | unsigned int csw_stat; | ||
85 | |||
86 | csw_stat = cmd->csw_code; | ||
87 | |||
88 | /* | ||
89 | * We can't send SENSE as a response. So we take ASC & ASCQ from our | ||
90 | * sense buffer and queue it and hope the host sends a REQUEST_SENSE | ||
91 | * command where it learns why we failed. | ||
92 | */ | ||
93 | sense = cmd->sense_iu.sense; | ||
94 | |||
95 | csw->Tag = cmd->bot_tag; | ||
96 | csw->Status = csw_stat; | ||
97 | fu->bot_status.req->context = cmd; | ||
98 | ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_ATOMIC); | ||
99 | if (ret) | ||
100 | pr_err("%s(%d) ERR: %d\n", __func__, __LINE__, ret); | ||
101 | } | ||
102 | |||
103 | static void bot_err_compl(struct usb_ep *ep, struct usb_request *req) | ||
104 | { | ||
105 | struct usbg_cmd *cmd = req->context; | ||
106 | struct f_uas *fu = cmd->fu; | ||
107 | |||
108 | if (req->status < 0) | ||
109 | pr_err("ERR %s(%d)\n", __func__, __LINE__); | ||
110 | |||
111 | if (cmd->data_len) { | ||
112 | if (cmd->data_len > ep->maxpacket) { | ||
113 | req->length = ep->maxpacket; | ||
114 | cmd->data_len -= ep->maxpacket; | ||
115 | } else { | ||
116 | req->length = cmd->data_len; | ||
117 | cmd->data_len = 0; | ||
118 | } | ||
119 | |||
120 | usb_ep_queue(ep, req, GFP_ATOMIC); | ||
121 | return ; | ||
122 | } | ||
123 | bot_enqueue_sense_code(fu, cmd); | ||
124 | } | ||
125 | |||
126 | static void bot_send_bad_status(struct usbg_cmd *cmd) | ||
127 | { | ||
128 | struct f_uas *fu = cmd->fu; | ||
129 | struct bulk_cs_wrap *csw = &fu->bot_status.csw; | ||
130 | struct usb_request *req; | ||
131 | struct usb_ep *ep; | ||
132 | |||
133 | csw->Residue = cpu_to_le32(cmd->data_len); | ||
134 | |||
135 | if (cmd->data_len) { | ||
136 | if (cmd->is_read) { | ||
137 | ep = fu->ep_in; | ||
138 | req = fu->bot_req_in; | ||
139 | } else { | ||
140 | ep = fu->ep_out; | ||
141 | req = fu->bot_req_out; | ||
142 | } | ||
143 | |||
144 | if (cmd->data_len > fu->ep_in->maxpacket) { | ||
145 | req->length = ep->maxpacket; | ||
146 | cmd->data_len -= ep->maxpacket; | ||
147 | } else { | ||
148 | req->length = cmd->data_len; | ||
149 | cmd->data_len = 0; | ||
150 | } | ||
151 | req->complete = bot_err_compl; | ||
152 | req->context = cmd; | ||
153 | req->buf = fu->cmd.buf; | ||
154 | usb_ep_queue(ep, req, GFP_KERNEL); | ||
155 | } else { | ||
156 | bot_enqueue_sense_code(fu, cmd); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static int bot_send_status(struct usbg_cmd *cmd, bool moved_data) | ||
161 | { | ||
162 | struct f_uas *fu = cmd->fu; | ||
163 | struct bulk_cs_wrap *csw = &fu->bot_status.csw; | ||
164 | int ret; | ||
165 | |||
166 | if (cmd->se_cmd.scsi_status == SAM_STAT_GOOD) { | ||
167 | if (!moved_data && cmd->data_len) { | ||
168 | /* | ||
169 | * the host wants to move data, we don't. Fill / empty | ||
170 | * the pipe and then send the csw with reside set. | ||
171 | */ | ||
172 | cmd->csw_code = US_BULK_STAT_OK; | ||
173 | bot_send_bad_status(cmd); | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | csw->Tag = cmd->bot_tag; | ||
178 | csw->Residue = cpu_to_le32(0); | ||
179 | csw->Status = US_BULK_STAT_OK; | ||
180 | fu->bot_status.req->context = cmd; | ||
181 | |||
182 | ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_KERNEL); | ||
183 | if (ret) | ||
184 | pr_err("%s(%d) ERR: %d\n", __func__, __LINE__, ret); | ||
185 | } else { | ||
186 | cmd->csw_code = US_BULK_STAT_FAIL; | ||
187 | bot_send_bad_status(cmd); | ||
188 | } | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | /* | ||
193 | * Called after command (no data transfer) or after the write (to device) | ||
194 | * operation is completed | ||
195 | */ | ||
196 | static int bot_send_status_response(struct usbg_cmd *cmd) | ||
197 | { | ||
198 | bool moved_data = false; | ||
199 | |||
200 | if (!cmd->is_read) | ||
201 | moved_data = true; | ||
202 | return bot_send_status(cmd, moved_data); | ||
203 | } | ||
204 | |||
205 | /* Read request completed, now we have to send the CSW */ | ||
206 | static void bot_read_compl(struct usb_ep *ep, struct usb_request *req) | ||
207 | { | ||
208 | struct usbg_cmd *cmd = req->context; | ||
209 | |||
210 | if (req->status < 0) | ||
211 | pr_err("ERR %s(%d)\n", __func__, __LINE__); | ||
212 | |||
213 | bot_send_status(cmd, true); | ||
214 | } | ||
215 | |||
216 | static int bot_send_read_response(struct usbg_cmd *cmd) | ||
217 | { | ||
218 | struct f_uas *fu = cmd->fu; | ||
219 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
220 | struct usb_gadget *gadget = fuas_to_gadget(fu); | ||
221 | int ret; | ||
222 | |||
223 | if (!cmd->data_len) { | ||
224 | cmd->csw_code = US_BULK_STAT_PHASE; | ||
225 | bot_send_bad_status(cmd); | ||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | if (!gadget->sg_supported) { | ||
230 | cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); | ||
231 | if (!cmd->data_buf) | ||
232 | return -ENOMEM; | ||
233 | |||
234 | sg_copy_to_buffer(se_cmd->t_data_sg, | ||
235 | se_cmd->t_data_nents, | ||
236 | cmd->data_buf, | ||
237 | se_cmd->data_length); | ||
238 | |||
239 | fu->bot_req_in->buf = cmd->data_buf; | ||
240 | } else { | ||
241 | fu->bot_req_in->buf = NULL; | ||
242 | fu->bot_req_in->num_sgs = se_cmd->t_data_nents; | ||
243 | fu->bot_req_in->sg = se_cmd->t_data_sg; | ||
244 | } | ||
245 | |||
246 | fu->bot_req_in->complete = bot_read_compl; | ||
247 | fu->bot_req_in->length = se_cmd->data_length; | ||
248 | fu->bot_req_in->context = cmd; | ||
249 | ret = usb_ep_queue(fu->ep_in, fu->bot_req_in, GFP_ATOMIC); | ||
250 | if (ret) | ||
251 | pr_err("%s(%d)\n", __func__, __LINE__); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static void usbg_data_write_cmpl(struct usb_ep *, struct usb_request *); | ||
256 | static int usbg_prepare_w_request(struct usbg_cmd *, struct usb_request *); | ||
257 | |||
258 | static int bot_send_write_request(struct usbg_cmd *cmd) | ||
259 | { | ||
260 | struct f_uas *fu = cmd->fu; | ||
261 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
262 | struct usb_gadget *gadget = fuas_to_gadget(fu); | ||
263 | int ret; | ||
264 | |||
265 | init_completion(&cmd->write_complete); | ||
266 | cmd->fu = fu; | ||
267 | |||
268 | if (!cmd->data_len) { | ||
269 | cmd->csw_code = US_BULK_STAT_PHASE; | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | |||
273 | if (!gadget->sg_supported) { | ||
274 | cmd->data_buf = kmalloc(se_cmd->data_length, GFP_KERNEL); | ||
275 | if (!cmd->data_buf) | ||
276 | return -ENOMEM; | ||
277 | |||
278 | fu->bot_req_out->buf = cmd->data_buf; | ||
279 | } else { | ||
280 | fu->bot_req_out->buf = NULL; | ||
281 | fu->bot_req_out->num_sgs = se_cmd->t_data_nents; | ||
282 | fu->bot_req_out->sg = se_cmd->t_data_sg; | ||
283 | } | ||
284 | |||
285 | fu->bot_req_out->complete = usbg_data_write_cmpl; | ||
286 | fu->bot_req_out->length = se_cmd->data_length; | ||
287 | fu->bot_req_out->context = cmd; | ||
288 | |||
289 | ret = usbg_prepare_w_request(cmd, fu->bot_req_out); | ||
290 | if (ret) | ||
291 | goto cleanup; | ||
292 | ret = usb_ep_queue(fu->ep_out, fu->bot_req_out, GFP_KERNEL); | ||
293 | if (ret) | ||
294 | pr_err("%s(%d)\n", __func__, __LINE__); | ||
295 | |||
296 | wait_for_completion(&cmd->write_complete); | ||
297 | transport_generic_process_write(se_cmd); | ||
298 | cleanup: | ||
299 | return ret; | ||
300 | } | ||
301 | |||
302 | static int bot_submit_command(struct f_uas *, void *, unsigned int); | ||
303 | |||
304 | static void bot_cmd_complete(struct usb_ep *ep, struct usb_request *req) | ||
305 | { | ||
306 | struct f_uas *fu = req->context; | ||
307 | int ret; | ||
308 | |||
309 | fu->flags &= ~USBG_BOT_CMD_PEND; | ||
310 | |||
311 | if (req->status < 0) | ||
312 | return; | ||
313 | |||
314 | ret = bot_submit_command(fu, req->buf, req->actual); | ||
315 | if (ret) | ||
316 | pr_err("%s(%d): %d\n", __func__, __LINE__, ret); | ||
317 | } | ||
318 | |||
319 | static int bot_prepare_reqs(struct f_uas *fu) | ||
320 | { | ||
321 | int ret; | ||
322 | |||
323 | fu->bot_req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); | ||
324 | if (!fu->bot_req_in) | ||
325 | goto err; | ||
326 | |||
327 | fu->bot_req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); | ||
328 | if (!fu->bot_req_out) | ||
329 | goto err_out; | ||
330 | |||
331 | fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); | ||
332 | if (!fu->cmd.req) | ||
333 | goto err_cmd; | ||
334 | |||
335 | fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); | ||
336 | if (!fu->bot_status.req) | ||
337 | goto err_sts; | ||
338 | |||
339 | fu->bot_status.req->buf = &fu->bot_status.csw; | ||
340 | fu->bot_status.req->length = US_BULK_CS_WRAP_LEN; | ||
341 | fu->bot_status.req->complete = bot_status_complete; | ||
342 | fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); | ||
343 | |||
344 | fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); | ||
345 | if (!fu->cmd.buf) | ||
346 | goto err_buf; | ||
347 | |||
348 | fu->cmd.req->complete = bot_cmd_complete; | ||
349 | fu->cmd.req->buf = fu->cmd.buf; | ||
350 | fu->cmd.req->length = fu->ep_out->maxpacket; | ||
351 | fu->cmd.req->context = fu; | ||
352 | |||
353 | ret = bot_enqueue_cmd_cbw(fu); | ||
354 | if (ret) | ||
355 | goto err_queue; | ||
356 | return 0; | ||
357 | err_queue: | ||
358 | kfree(fu->cmd.buf); | ||
359 | fu->cmd.buf = NULL; | ||
360 | err_buf: | ||
361 | usb_ep_free_request(fu->ep_in, fu->bot_status.req); | ||
362 | err_sts: | ||
363 | usb_ep_free_request(fu->ep_out, fu->cmd.req); | ||
364 | fu->cmd.req = NULL; | ||
365 | err_cmd: | ||
366 | usb_ep_free_request(fu->ep_out, fu->bot_req_out); | ||
367 | fu->bot_req_out = NULL; | ||
368 | err_out: | ||
369 | usb_ep_free_request(fu->ep_in, fu->bot_req_in); | ||
370 | fu->bot_req_in = NULL; | ||
371 | err: | ||
372 | pr_err("BOT: endpoint setup failed\n"); | ||
373 | return -ENOMEM; | ||
374 | } | ||
375 | |||
376 | void bot_cleanup_old_alt(struct f_uas *fu) | ||
377 | { | ||
378 | if (!(fu->flags & USBG_ENABLED)) | ||
379 | return; | ||
380 | |||
381 | usb_ep_disable(fu->ep_in); | ||
382 | usb_ep_disable(fu->ep_out); | ||
383 | |||
384 | if (!fu->bot_req_in) | ||
385 | return; | ||
386 | |||
387 | usb_ep_free_request(fu->ep_in, fu->bot_req_in); | ||
388 | usb_ep_free_request(fu->ep_out, fu->bot_req_out); | ||
389 | usb_ep_free_request(fu->ep_out, fu->cmd.req); | ||
390 | usb_ep_free_request(fu->ep_out, fu->bot_status.req); | ||
391 | |||
392 | kfree(fu->cmd.buf); | ||
393 | |||
394 | fu->bot_req_in = NULL; | ||
395 | fu->bot_req_out = NULL; | ||
396 | fu->cmd.req = NULL; | ||
397 | fu->bot_status.req = NULL; | ||
398 | fu->cmd.buf = NULL; | ||
399 | } | ||
400 | |||
401 | static void bot_set_alt(struct f_uas *fu) | ||
402 | { | ||
403 | struct usb_function *f = &fu->function; | ||
404 | struct usb_gadget *gadget = f->config->cdev->gadget; | ||
405 | int ret; | ||
406 | |||
407 | fu->flags = USBG_IS_BOT; | ||
408 | |||
409 | config_ep_by_speed(gadget, f, fu->ep_in); | ||
410 | ret = usb_ep_enable(fu->ep_in); | ||
411 | if (ret) | ||
412 | goto err_b_in; | ||
413 | |||
414 | config_ep_by_speed(gadget, f, fu->ep_out); | ||
415 | ret = usb_ep_enable(fu->ep_out); | ||
416 | if (ret) | ||
417 | goto err_b_out; | ||
418 | |||
419 | ret = bot_prepare_reqs(fu); | ||
420 | if (ret) | ||
421 | goto err_wq; | ||
422 | fu->flags |= USBG_ENABLED; | ||
423 | pr_info("Using the BOT protocol\n"); | ||
424 | return; | ||
425 | err_wq: | ||
426 | usb_ep_disable(fu->ep_out); | ||
427 | err_b_out: | ||
428 | usb_ep_disable(fu->ep_in); | ||
429 | err_b_in: | ||
430 | fu->flags = USBG_IS_BOT; | ||
431 | } | ||
432 | |||
433 | static int usbg_bot_setup(struct usb_function *f, | ||
434 | const struct usb_ctrlrequest *ctrl) | ||
435 | { | ||
436 | struct f_uas *fu = to_f_uas(f); | ||
437 | struct usb_composite_dev *cdev = f->config->cdev; | ||
438 | u16 w_value = le16_to_cpu(ctrl->wValue); | ||
439 | u16 w_length = le16_to_cpu(ctrl->wLength); | ||
440 | int luns; | ||
441 | u8 *ret_lun; | ||
442 | |||
443 | switch (ctrl->bRequest) { | ||
444 | case US_BULK_GET_MAX_LUN: | ||
445 | if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_CLASS | | ||
446 | USB_RECIP_INTERFACE)) | ||
447 | return -ENOTSUPP; | ||
448 | |||
449 | if (w_length < 1) | ||
450 | return -EINVAL; | ||
451 | if (w_value != 0) | ||
452 | return -EINVAL; | ||
453 | luns = atomic_read(&fu->tpg->tpg_port_count); | ||
454 | if (!luns) { | ||
455 | pr_err("No LUNs configured?\n"); | ||
456 | return -EINVAL; | ||
457 | } | ||
458 | /* | ||
459 | * If 4 LUNs are present we return 3 i.e. LUN 0..3 can be | ||
460 | * accessed. The upper limit is 0xf | ||
461 | */ | ||
462 | luns--; | ||
463 | if (luns > 0xf) { | ||
464 | pr_info_once("Limiting the number of luns to 16\n"); | ||
465 | luns = 0xf; | ||
466 | } | ||
467 | ret_lun = cdev->req->buf; | ||
468 | *ret_lun = luns; | ||
469 | cdev->req->length = 1; | ||
470 | return usb_ep_queue(cdev->gadget->ep0, cdev->req, GFP_ATOMIC); | ||
471 | break; | ||
472 | |||
473 | case US_BULK_RESET_REQUEST: | ||
474 | /* XXX maybe we should remove previous requests for IN + OUT */ | ||
475 | bot_enqueue_cmd_cbw(fu); | ||
476 | return 0; | ||
477 | break; | ||
478 | }; | ||
479 | return -ENOTSUPP; | ||
480 | } | ||
481 | |||
482 | /* Start uas.c code */ | ||
483 | |||
484 | static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) | ||
485 | { | ||
486 | /* We have either all three allocated or none */ | ||
487 | if (!stream->req_in) | ||
488 | return; | ||
489 | |||
490 | usb_ep_free_request(fu->ep_in, stream->req_in); | ||
491 | usb_ep_free_request(fu->ep_out, stream->req_out); | ||
492 | usb_ep_free_request(fu->ep_status, stream->req_status); | ||
493 | |||
494 | stream->req_in = NULL; | ||
495 | stream->req_out = NULL; | ||
496 | stream->req_status = NULL; | ||
497 | } | ||
498 | |||
499 | static void uasp_free_cmdreq(struct f_uas *fu) | ||
500 | { | ||
501 | usb_ep_free_request(fu->ep_cmd, fu->cmd.req); | ||
502 | kfree(fu->cmd.buf); | ||
503 | fu->cmd.req = NULL; | ||
504 | fu->cmd.buf = NULL; | ||
505 | } | ||
506 | |||
507 | static void uasp_cleanup_old_alt(struct f_uas *fu) | ||
508 | { | ||
509 | int i; | ||
510 | |||
511 | if (!(fu->flags & USBG_ENABLED)) | ||
512 | return; | ||
513 | |||
514 | usb_ep_disable(fu->ep_in); | ||
515 | usb_ep_disable(fu->ep_out); | ||
516 | usb_ep_disable(fu->ep_status); | ||
517 | usb_ep_disable(fu->ep_cmd); | ||
518 | |||
519 | for (i = 0; i < UASP_SS_EP_COMP_NUM_STREAMS; i++) | ||
520 | uasp_cleanup_one_stream(fu, &fu->stream[i]); | ||
521 | uasp_free_cmdreq(fu); | ||
522 | } | ||
523 | |||
524 | static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req); | ||
525 | |||
526 | static int uasp_prepare_r_request(struct usbg_cmd *cmd) | ||
527 | { | ||
528 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
529 | struct f_uas *fu = cmd->fu; | ||
530 | struct usb_gadget *gadget = fuas_to_gadget(fu); | ||
531 | struct uas_stream *stream = cmd->stream; | ||
532 | |||
533 | if (!gadget->sg_supported) { | ||
534 | cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); | ||
535 | if (!cmd->data_buf) | ||
536 | return -ENOMEM; | ||
537 | |||
538 | sg_copy_to_buffer(se_cmd->t_data_sg, | ||
539 | se_cmd->t_data_nents, | ||
540 | cmd->data_buf, | ||
541 | se_cmd->data_length); | ||
542 | |||
543 | stream->req_in->buf = cmd->data_buf; | ||
544 | } else { | ||
545 | stream->req_in->buf = NULL; | ||
546 | stream->req_in->num_sgs = se_cmd->t_data_nents; | ||
547 | stream->req_in->sg = se_cmd->t_data_sg; | ||
548 | } | ||
549 | |||
550 | stream->req_in->complete = uasp_status_data_cmpl; | ||
551 | stream->req_in->length = se_cmd->data_length; | ||
552 | stream->req_in->context = cmd; | ||
553 | |||
554 | cmd->state = UASP_SEND_STATUS; | ||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | static void uasp_prepare_status(struct usbg_cmd *cmd) | ||
559 | { | ||
560 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
561 | struct sense_iu *iu = &cmd->sense_iu; | ||
562 | struct uas_stream *stream = cmd->stream; | ||
563 | |||
564 | cmd->state = UASP_QUEUE_COMMAND; | ||
565 | iu->iu_id = IU_ID_STATUS; | ||
566 | iu->tag = cpu_to_be16(cmd->tag); | ||
567 | |||
568 | /* | ||
569 | * iu->status_qual = cpu_to_be16(STATUS QUALIFIER SAM-4. Where R U?); | ||
570 | */ | ||
571 | iu->len = cpu_to_be16(se_cmd->scsi_sense_length); | ||
572 | iu->status = se_cmd->scsi_status; | ||
573 | stream->req_status->context = cmd; | ||
574 | stream->req_status->length = se_cmd->scsi_sense_length + 16; | ||
575 | stream->req_status->buf = iu; | ||
576 | stream->req_status->complete = uasp_status_data_cmpl; | ||
577 | } | ||
578 | |||
579 | static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) | ||
580 | { | ||
581 | struct usbg_cmd *cmd = req->context; | ||
582 | struct uas_stream *stream = cmd->stream; | ||
583 | struct f_uas *fu = cmd->fu; | ||
584 | int ret; | ||
585 | |||
586 | if (req->status < 0) | ||
587 | goto cleanup; | ||
588 | |||
589 | switch (cmd->state) { | ||
590 | case UASP_SEND_DATA: | ||
591 | ret = uasp_prepare_r_request(cmd); | ||
592 | if (ret) | ||
593 | goto cleanup; | ||
594 | ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); | ||
595 | if (ret) | ||
596 | pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); | ||
597 | break; | ||
598 | |||
599 | case UASP_RECEIVE_DATA: | ||
600 | ret = usbg_prepare_w_request(cmd, stream->req_out); | ||
601 | if (ret) | ||
602 | goto cleanup; | ||
603 | ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); | ||
604 | if (ret) | ||
605 | pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); | ||
606 | break; | ||
607 | |||
608 | case UASP_SEND_STATUS: | ||
609 | uasp_prepare_status(cmd); | ||
610 | ret = usb_ep_queue(fu->ep_status, stream->req_status, | ||
611 | GFP_ATOMIC); | ||
612 | if (ret) | ||
613 | pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); | ||
614 | break; | ||
615 | |||
616 | case UASP_QUEUE_COMMAND: | ||
617 | usbg_cleanup_cmd(cmd); | ||
618 | usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); | ||
619 | break; | ||
620 | |||
621 | default: | ||
622 | BUG(); | ||
623 | }; | ||
624 | return; | ||
625 | |||
626 | cleanup: | ||
627 | usbg_cleanup_cmd(cmd); | ||
628 | } | ||
629 | |||
630 | static int uasp_send_status_response(struct usbg_cmd *cmd) | ||
631 | { | ||
632 | struct f_uas *fu = cmd->fu; | ||
633 | struct uas_stream *stream = cmd->stream; | ||
634 | struct sense_iu *iu = &cmd->sense_iu; | ||
635 | |||
636 | iu->tag = cpu_to_be16(cmd->tag); | ||
637 | stream->req_status->complete = uasp_status_data_cmpl; | ||
638 | stream->req_status->context = cmd; | ||
639 | cmd->fu = fu; | ||
640 | uasp_prepare_status(cmd); | ||
641 | return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); | ||
642 | } | ||
643 | |||
644 | static int uasp_send_read_response(struct usbg_cmd *cmd) | ||
645 | { | ||
646 | struct f_uas *fu = cmd->fu; | ||
647 | struct uas_stream *stream = cmd->stream; | ||
648 | struct sense_iu *iu = &cmd->sense_iu; | ||
649 | int ret; | ||
650 | |||
651 | cmd->fu = fu; | ||
652 | |||
653 | iu->tag = cpu_to_be16(cmd->tag); | ||
654 | if (fu->flags & USBG_USE_STREAMS) { | ||
655 | |||
656 | ret = uasp_prepare_r_request(cmd); | ||
657 | if (ret) | ||
658 | goto out; | ||
659 | ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); | ||
660 | if (ret) { | ||
661 | pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); | ||
662 | kfree(cmd->data_buf); | ||
663 | cmd->data_buf = NULL; | ||
664 | } | ||
665 | |||
666 | } else { | ||
667 | |||
668 | iu->iu_id = IU_ID_READ_READY; | ||
669 | iu->tag = cpu_to_be16(cmd->tag); | ||
670 | |||
671 | stream->req_status->complete = uasp_status_data_cmpl; | ||
672 | stream->req_status->context = cmd; | ||
673 | |||
674 | cmd->state = UASP_SEND_DATA; | ||
675 | stream->req_status->buf = iu; | ||
676 | stream->req_status->length = sizeof(struct iu); | ||
677 | |||
678 | ret = usb_ep_queue(fu->ep_status, stream->req_status, | ||
679 | GFP_ATOMIC); | ||
680 | if (ret) | ||
681 | pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); | ||
682 | } | ||
683 | out: | ||
684 | return ret; | ||
685 | } | ||
686 | |||
687 | static int uasp_send_write_request(struct usbg_cmd *cmd) | ||
688 | { | ||
689 | struct f_uas *fu = cmd->fu; | ||
690 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
691 | struct uas_stream *stream = cmd->stream; | ||
692 | struct sense_iu *iu = &cmd->sense_iu; | ||
693 | int ret; | ||
694 | |||
695 | init_completion(&cmd->write_complete); | ||
696 | cmd->fu = fu; | ||
697 | |||
698 | iu->tag = cpu_to_be16(cmd->tag); | ||
699 | |||
700 | if (fu->flags & USBG_USE_STREAMS) { | ||
701 | |||
702 | ret = usbg_prepare_w_request(cmd, stream->req_out); | ||
703 | if (ret) | ||
704 | goto cleanup; | ||
705 | ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); | ||
706 | if (ret) | ||
707 | pr_err("%s(%d)\n", __func__, __LINE__); | ||
708 | |||
709 | } else { | ||
710 | |||
711 | iu->iu_id = IU_ID_WRITE_READY; | ||
712 | iu->tag = cpu_to_be16(cmd->tag); | ||
713 | |||
714 | stream->req_status->complete = uasp_status_data_cmpl; | ||
715 | stream->req_status->context = cmd; | ||
716 | |||
717 | cmd->state = UASP_RECEIVE_DATA; | ||
718 | stream->req_status->buf = iu; | ||
719 | stream->req_status->length = sizeof(struct iu); | ||
720 | |||
721 | ret = usb_ep_queue(fu->ep_status, stream->req_status, | ||
722 | GFP_ATOMIC); | ||
723 | if (ret) | ||
724 | pr_err("%s(%d)\n", __func__, __LINE__); | ||
725 | } | ||
726 | |||
727 | wait_for_completion(&cmd->write_complete); | ||
728 | transport_generic_process_write(se_cmd); | ||
729 | cleanup: | ||
730 | return ret; | ||
731 | } | ||
732 | |||
733 | static int usbg_submit_command(struct f_uas *, void *, unsigned int); | ||
734 | |||
735 | static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) | ||
736 | { | ||
737 | struct f_uas *fu = req->context; | ||
738 | int ret; | ||
739 | |||
740 | if (req->status < 0) | ||
741 | return; | ||
742 | |||
743 | ret = usbg_submit_command(fu, req->buf, req->actual); | ||
744 | /* | ||
745 | * Once we tune for performance enqueue the command req here again so | ||
746 | * we can receive a second command while we processing this one. Pay | ||
747 | * attention to properly sync STAUS endpoint with DATA IN + OUT so you | ||
748 | * don't break HS. | ||
749 | */ | ||
750 | if (!ret) | ||
751 | return; | ||
752 | usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); | ||
753 | } | ||
754 | |||
755 | static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) | ||
756 | { | ||
757 | stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); | ||
758 | if (!stream->req_in) | ||
759 | goto out; | ||
760 | |||
761 | stream->req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); | ||
762 | if (!stream->req_out) | ||
763 | goto err_out; | ||
764 | |||
765 | stream->req_status = usb_ep_alloc_request(fu->ep_status, GFP_KERNEL); | ||
766 | if (!stream->req_status) | ||
767 | goto err_sts; | ||
768 | |||
769 | return 0; | ||
770 | err_sts: | ||
771 | usb_ep_free_request(fu->ep_status, stream->req_status); | ||
772 | stream->req_status = NULL; | ||
773 | err_out: | ||
774 | usb_ep_free_request(fu->ep_out, stream->req_out); | ||
775 | stream->req_out = NULL; | ||
776 | out: | ||
777 | return -ENOMEM; | ||
778 | } | ||
779 | |||
780 | static int uasp_alloc_cmd(struct f_uas *fu) | ||
781 | { | ||
782 | fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); | ||
783 | if (!fu->cmd.req) | ||
784 | goto err; | ||
785 | |||
786 | fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); | ||
787 | if (!fu->cmd.buf) | ||
788 | goto err_buf; | ||
789 | |||
790 | fu->cmd.req->complete = uasp_cmd_complete; | ||
791 | fu->cmd.req->buf = fu->cmd.buf; | ||
792 | fu->cmd.req->length = fu->ep_cmd->maxpacket; | ||
793 | fu->cmd.req->context = fu; | ||
794 | return 0; | ||
795 | |||
796 | err_buf: | ||
797 | usb_ep_free_request(fu->ep_cmd, fu->cmd.req); | ||
798 | err: | ||
799 | return -ENOMEM; | ||
800 | } | ||
801 | |||
802 | static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) | ||
803 | { | ||
804 | int i; | ||
805 | |||
806 | for (i = 0; i < max_streams; i++) { | ||
807 | struct uas_stream *s = &fu->stream[i]; | ||
808 | |||
809 | s->req_in->stream_id = i + 1; | ||
810 | s->req_out->stream_id = i + 1; | ||
811 | s->req_status->stream_id = i + 1; | ||
812 | } | ||
813 | } | ||
814 | |||
815 | static int uasp_prepare_reqs(struct f_uas *fu) | ||
816 | { | ||
817 | int ret; | ||
818 | int i; | ||
819 | int max_streams; | ||
820 | |||
821 | if (fu->flags & USBG_USE_STREAMS) | ||
822 | max_streams = UASP_SS_EP_COMP_NUM_STREAMS; | ||
823 | else | ||
824 | max_streams = 1; | ||
825 | |||
826 | for (i = 0; i < max_streams; i++) { | ||
827 | ret = uasp_alloc_stream_res(fu, &fu->stream[i]); | ||
828 | if (ret) | ||
829 | goto err_cleanup; | ||
830 | } | ||
831 | |||
832 | ret = uasp_alloc_cmd(fu); | ||
833 | if (ret) | ||
834 | goto err_free_stream; | ||
835 | uasp_setup_stream_res(fu, max_streams); | ||
836 | |||
837 | ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); | ||
838 | if (ret) | ||
839 | goto err_free_stream; | ||
840 | |||
841 | return 0; | ||
842 | |||
843 | err_free_stream: | ||
844 | uasp_free_cmdreq(fu); | ||
845 | |||
846 | err_cleanup: | ||
847 | if (i) { | ||
848 | do { | ||
849 | uasp_cleanup_one_stream(fu, &fu->stream[i - 1]); | ||
850 | i--; | ||
851 | } while (i); | ||
852 | } | ||
853 | pr_err("UASP: endpoint setup failed\n"); | ||
854 | return ret; | ||
855 | } | ||
856 | |||
857 | static void uasp_set_alt(struct f_uas *fu) | ||
858 | { | ||
859 | struct usb_function *f = &fu->function; | ||
860 | struct usb_gadget *gadget = f->config->cdev->gadget; | ||
861 | int ret; | ||
862 | |||
863 | fu->flags = USBG_IS_UAS; | ||
864 | |||
865 | if (gadget->speed == USB_SPEED_SUPER) | ||
866 | fu->flags |= USBG_USE_STREAMS; | ||
867 | |||
868 | config_ep_by_speed(gadget, f, fu->ep_in); | ||
869 | ret = usb_ep_enable(fu->ep_in); | ||
870 | if (ret) | ||
871 | goto err_b_in; | ||
872 | |||
873 | config_ep_by_speed(gadget, f, fu->ep_out); | ||
874 | ret = usb_ep_enable(fu->ep_out); | ||
875 | if (ret) | ||
876 | goto err_b_out; | ||
877 | |||
878 | config_ep_by_speed(gadget, f, fu->ep_cmd); | ||
879 | ret = usb_ep_enable(fu->ep_cmd); | ||
880 | if (ret) | ||
881 | goto err_cmd; | ||
882 | config_ep_by_speed(gadget, f, fu->ep_status); | ||
883 | ret = usb_ep_enable(fu->ep_status); | ||
884 | if (ret) | ||
885 | goto err_status; | ||
886 | |||
887 | ret = uasp_prepare_reqs(fu); | ||
888 | if (ret) | ||
889 | goto err_wq; | ||
890 | fu->flags |= USBG_ENABLED; | ||
891 | |||
892 | pr_info("Using the UAS protocol\n"); | ||
893 | return; | ||
894 | err_wq: | ||
895 | usb_ep_disable(fu->ep_status); | ||
896 | err_status: | ||
897 | usb_ep_disable(fu->ep_cmd); | ||
898 | err_cmd: | ||
899 | usb_ep_disable(fu->ep_out); | ||
900 | err_b_out: | ||
901 | usb_ep_disable(fu->ep_in); | ||
902 | err_b_in: | ||
903 | fu->flags = 0; | ||
904 | } | ||
905 | |||
906 | static int get_cmd_dir(const unsigned char *cdb) | ||
907 | { | ||
908 | int ret; | ||
909 | |||
910 | switch (cdb[0]) { | ||
911 | case READ_6: | ||
912 | case READ_10: | ||
913 | case READ_12: | ||
914 | case READ_16: | ||
915 | case INQUIRY: | ||
916 | case MODE_SENSE: | ||
917 | case MODE_SENSE_10: | ||
918 | case SERVICE_ACTION_IN: | ||
919 | case MAINTENANCE_IN: | ||
920 | case PERSISTENT_RESERVE_IN: | ||
921 | case SECURITY_PROTOCOL_IN: | ||
922 | case ACCESS_CONTROL_IN: | ||
923 | case REPORT_LUNS: | ||
924 | case READ_BLOCK_LIMITS: | ||
925 | case READ_POSITION: | ||
926 | case READ_CAPACITY: | ||
927 | case READ_TOC: | ||
928 | case READ_FORMAT_CAPACITIES: | ||
929 | case REQUEST_SENSE: | ||
930 | ret = DMA_FROM_DEVICE; | ||
931 | break; | ||
932 | |||
933 | case WRITE_6: | ||
934 | case WRITE_10: | ||
935 | case WRITE_12: | ||
936 | case WRITE_16: | ||
937 | case MODE_SELECT: | ||
938 | case MODE_SELECT_10: | ||
939 | case WRITE_VERIFY: | ||
940 | case WRITE_VERIFY_12: | ||
941 | case PERSISTENT_RESERVE_OUT: | ||
942 | case MAINTENANCE_OUT: | ||
943 | case SECURITY_PROTOCOL_OUT: | ||
944 | case ACCESS_CONTROL_OUT: | ||
945 | ret = DMA_TO_DEVICE; | ||
946 | break; | ||
947 | case ALLOW_MEDIUM_REMOVAL: | ||
948 | case TEST_UNIT_READY: | ||
949 | case SYNCHRONIZE_CACHE: | ||
950 | case START_STOP: | ||
951 | case ERASE: | ||
952 | case REZERO_UNIT: | ||
953 | case SEEK_10: | ||
954 | case SPACE: | ||
955 | case VERIFY: | ||
956 | case WRITE_FILEMARKS: | ||
957 | ret = DMA_NONE; | ||
958 | break; | ||
959 | default: | ||
960 | pr_warn("target: Unknown data direction for SCSI Opcode " | ||
961 | "0x%02x\n", cdb[0]); | ||
962 | ret = -EINVAL; | ||
963 | } | ||
964 | return ret; | ||
965 | } | ||
966 | |||
967 | static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) | ||
968 | { | ||
969 | struct usbg_cmd *cmd = req->context; | ||
970 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
971 | |||
972 | if (req->status < 0) { | ||
973 | pr_err("%s() state %d transfer failed\n", __func__, cmd->state); | ||
974 | goto cleanup; | ||
975 | } | ||
976 | |||
977 | if (req->num_sgs == 0) { | ||
978 | sg_copy_from_buffer(se_cmd->t_data_sg, | ||
979 | se_cmd->t_data_nents, | ||
980 | cmd->data_buf, | ||
981 | se_cmd->data_length); | ||
982 | } | ||
983 | |||
984 | complete(&cmd->write_complete); | ||
985 | return; | ||
986 | |||
987 | cleanup: | ||
988 | usbg_cleanup_cmd(cmd); | ||
989 | } | ||
990 | |||
991 | static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) | ||
992 | { | ||
993 | struct se_cmd *se_cmd = &cmd->se_cmd; | ||
994 | struct f_uas *fu = cmd->fu; | ||
995 | struct usb_gadget *gadget = fuas_to_gadget(fu); | ||
996 | |||
997 | if (!gadget->sg_supported) { | ||
998 | cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); | ||
999 | if (!cmd->data_buf) | ||
1000 | return -ENOMEM; | ||
1001 | |||
1002 | req->buf = cmd->data_buf; | ||
1003 | } else { | ||
1004 | req->buf = NULL; | ||
1005 | req->num_sgs = se_cmd->t_data_nents; | ||
1006 | req->sg = se_cmd->t_data_sg; | ||
1007 | } | ||
1008 | |||
1009 | req->complete = usbg_data_write_cmpl; | ||
1010 | req->length = se_cmd->data_length; | ||
1011 | req->context = cmd; | ||
1012 | return 0; | ||
1013 | } | ||
1014 | |||
1015 | static int usbg_send_status_response(struct se_cmd *se_cmd) | ||
1016 | { | ||
1017 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1018 | se_cmd); | ||
1019 | struct f_uas *fu = cmd->fu; | ||
1020 | |||
1021 | if (fu->flags & USBG_IS_BOT) | ||
1022 | return bot_send_status_response(cmd); | ||
1023 | else | ||
1024 | return uasp_send_status_response(cmd); | ||
1025 | } | ||
1026 | |||
1027 | static int usbg_send_write_request(struct se_cmd *se_cmd) | ||
1028 | { | ||
1029 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1030 | se_cmd); | ||
1031 | struct f_uas *fu = cmd->fu; | ||
1032 | |||
1033 | if (fu->flags & USBG_IS_BOT) | ||
1034 | return bot_send_write_request(cmd); | ||
1035 | else | ||
1036 | return uasp_send_write_request(cmd); | ||
1037 | } | ||
1038 | |||
1039 | static int usbg_send_read_response(struct se_cmd *se_cmd) | ||
1040 | { | ||
1041 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1042 | se_cmd); | ||
1043 | struct f_uas *fu = cmd->fu; | ||
1044 | |||
1045 | if (fu->flags & USBG_IS_BOT) | ||
1046 | return bot_send_read_response(cmd); | ||
1047 | else | ||
1048 | return uasp_send_read_response(cmd); | ||
1049 | } | ||
1050 | |||
1051 | static void usbg_cmd_work(struct work_struct *work) | ||
1052 | { | ||
1053 | struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); | ||
1054 | struct se_cmd *se_cmd; | ||
1055 | struct tcm_usbg_nexus *tv_nexus; | ||
1056 | struct usbg_tpg *tpg; | ||
1057 | int dir; | ||
1058 | |||
1059 | se_cmd = &cmd->se_cmd; | ||
1060 | tpg = cmd->fu->tpg; | ||
1061 | tv_nexus = tpg->tpg_nexus; | ||
1062 | dir = get_cmd_dir(cmd->cmd_buf); | ||
1063 | if (dir < 0) { | ||
1064 | transport_init_se_cmd(se_cmd, | ||
1065 | tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, | ||
1066 | tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, | ||
1067 | cmd->prio_attr, cmd->sense_iu.sense); | ||
1068 | |||
1069 | transport_send_check_condition_and_sense(se_cmd, | ||
1070 | TCM_UNSUPPORTED_SCSI_OPCODE, 1); | ||
1071 | usbg_cleanup_cmd(cmd); | ||
1072 | return; | ||
1073 | } | ||
1074 | |||
1075 | target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, | ||
1076 | cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, | ||
1077 | 0, cmd->prio_attr, dir, TARGET_SCF_UNKNOWN_SIZE); | ||
1078 | } | ||
1079 | |||
1080 | static int usbg_submit_command(struct f_uas *fu, | ||
1081 | void *cmdbuf, unsigned int len) | ||
1082 | { | ||
1083 | struct command_iu *cmd_iu = cmdbuf; | ||
1084 | struct usbg_cmd *cmd; | ||
1085 | struct usbg_tpg *tpg; | ||
1086 | struct se_cmd *se_cmd; | ||
1087 | struct tcm_usbg_nexus *tv_nexus; | ||
1088 | u32 cmd_len; | ||
1089 | int ret; | ||
1090 | |||
1091 | if (cmd_iu->iu_id != IU_ID_COMMAND) { | ||
1092 | pr_err("Unsupported type %d\n", cmd_iu->iu_id); | ||
1093 | return -EINVAL; | ||
1094 | } | ||
1095 | |||
1096 | cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); | ||
1097 | if (!cmd) | ||
1098 | return -ENOMEM; | ||
1099 | |||
1100 | cmd->fu = fu; | ||
1101 | |||
1102 | /* XXX until I figure out why I can't free in on complete */ | ||
1103 | kref_init(&cmd->ref); | ||
1104 | kref_get(&cmd->ref); | ||
1105 | |||
1106 | tpg = fu->tpg; | ||
1107 | cmd_len = (cmd_iu->len & ~0x3) + 16; | ||
1108 | if (cmd_len > USBG_MAX_CMD) | ||
1109 | goto err; | ||
1110 | |||
1111 | memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); | ||
1112 | |||
1113 | cmd->tag = be16_to_cpup(&cmd_iu->tag); | ||
1114 | if (fu->flags & USBG_USE_STREAMS) { | ||
1115 | if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) | ||
1116 | goto err; | ||
1117 | if (!cmd->tag) | ||
1118 | cmd->stream = &fu->stream[0]; | ||
1119 | else | ||
1120 | cmd->stream = &fu->stream[cmd->tag - 1]; | ||
1121 | } else { | ||
1122 | cmd->stream = &fu->stream[0]; | ||
1123 | } | ||
1124 | |||
1125 | tv_nexus = tpg->tpg_nexus; | ||
1126 | if (!tv_nexus) { | ||
1127 | pr_err("Missing nexus, ignoring command\n"); | ||
1128 | goto err; | ||
1129 | } | ||
1130 | |||
1131 | switch (cmd_iu->prio_attr & 0x7) { | ||
1132 | case UAS_HEAD_TAG: | ||
1133 | cmd->prio_attr = MSG_HEAD_TAG; | ||
1134 | break; | ||
1135 | case UAS_ORDERED_TAG: | ||
1136 | cmd->prio_attr = MSG_ORDERED_TAG; | ||
1137 | break; | ||
1138 | case UAS_ACA: | ||
1139 | cmd->prio_attr = MSG_ACA_TAG; | ||
1140 | break; | ||
1141 | default: | ||
1142 | pr_debug_once("Unsupported prio_attr: %02x.\n", | ||
1143 | cmd_iu->prio_attr); | ||
1144 | case UAS_SIMPLE_TAG: | ||
1145 | cmd->prio_attr = MSG_SIMPLE_TAG; | ||
1146 | break; | ||
1147 | } | ||
1148 | |||
1149 | se_cmd = &cmd->se_cmd; | ||
1150 | cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); | ||
1151 | |||
1152 | INIT_WORK(&cmd->work, usbg_cmd_work); | ||
1153 | ret = queue_work(tpg->workqueue, &cmd->work); | ||
1154 | if (ret < 0) | ||
1155 | goto err; | ||
1156 | |||
1157 | return 0; | ||
1158 | err: | ||
1159 | kfree(cmd); | ||
1160 | return -EINVAL; | ||
1161 | } | ||
1162 | |||
1163 | static void bot_cmd_work(struct work_struct *work) | ||
1164 | { | ||
1165 | struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); | ||
1166 | struct se_cmd *se_cmd; | ||
1167 | struct tcm_usbg_nexus *tv_nexus; | ||
1168 | struct usbg_tpg *tpg; | ||
1169 | int dir; | ||
1170 | |||
1171 | se_cmd = &cmd->se_cmd; | ||
1172 | tpg = cmd->fu->tpg; | ||
1173 | tv_nexus = tpg->tpg_nexus; | ||
1174 | dir = get_cmd_dir(cmd->cmd_buf); | ||
1175 | if (dir < 0) { | ||
1176 | transport_init_se_cmd(se_cmd, | ||
1177 | tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, | ||
1178 | tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, | ||
1179 | cmd->prio_attr, cmd->sense_iu.sense); | ||
1180 | |||
1181 | transport_send_check_condition_and_sense(se_cmd, | ||
1182 | TCM_UNSUPPORTED_SCSI_OPCODE, 1); | ||
1183 | usbg_cleanup_cmd(cmd); | ||
1184 | return; | ||
1185 | } | ||
1186 | |||
1187 | target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, | ||
1188 | cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, | ||
1189 | cmd->data_len, cmd->prio_attr, dir, 0); | ||
1190 | } | ||
1191 | |||
1192 | static int bot_submit_command(struct f_uas *fu, | ||
1193 | void *cmdbuf, unsigned int len) | ||
1194 | { | ||
1195 | struct bulk_cb_wrap *cbw = cmdbuf; | ||
1196 | struct usbg_cmd *cmd; | ||
1197 | struct usbg_tpg *tpg; | ||
1198 | struct se_cmd *se_cmd; | ||
1199 | struct tcm_usbg_nexus *tv_nexus; | ||
1200 | u32 cmd_len; | ||
1201 | int ret; | ||
1202 | |||
1203 | if (cbw->Signature != cpu_to_le32(US_BULK_CB_SIGN)) { | ||
1204 | pr_err("Wrong signature on CBW\n"); | ||
1205 | return -EINVAL; | ||
1206 | } | ||
1207 | if (len != 31) { | ||
1208 | pr_err("Wrong length for CBW\n"); | ||
1209 | return -EINVAL; | ||
1210 | } | ||
1211 | |||
1212 | cmd_len = cbw->Length; | ||
1213 | if (cmd_len < 1 || cmd_len > 16) | ||
1214 | return -EINVAL; | ||
1215 | |||
1216 | cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); | ||
1217 | if (!cmd) | ||
1218 | return -ENOMEM; | ||
1219 | |||
1220 | cmd->fu = fu; | ||
1221 | |||
1222 | /* XXX until I figure out why I can't free in on complete */ | ||
1223 | kref_init(&cmd->ref); | ||
1224 | kref_get(&cmd->ref); | ||
1225 | |||
1226 | tpg = fu->tpg; | ||
1227 | |||
1228 | memcpy(cmd->cmd_buf, cbw->CDB, cmd_len); | ||
1229 | |||
1230 | cmd->bot_tag = cbw->Tag; | ||
1231 | |||
1232 | tv_nexus = tpg->tpg_nexus; | ||
1233 | if (!tv_nexus) { | ||
1234 | pr_err("Missing nexus, ignoring command\n"); | ||
1235 | goto err; | ||
1236 | } | ||
1237 | |||
1238 | cmd->prio_attr = MSG_SIMPLE_TAG; | ||
1239 | se_cmd = &cmd->se_cmd; | ||
1240 | cmd->unpacked_lun = cbw->Lun; | ||
1241 | cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; | ||
1242 | cmd->data_len = le32_to_cpu(cbw->DataTransferLength); | ||
1243 | |||
1244 | INIT_WORK(&cmd->work, bot_cmd_work); | ||
1245 | ret = queue_work(tpg->workqueue, &cmd->work); | ||
1246 | if (ret < 0) | ||
1247 | goto err; | ||
1248 | |||
1249 | return 0; | ||
1250 | err: | ||
1251 | kfree(cmd); | ||
1252 | return -EINVAL; | ||
1253 | } | ||
1254 | |||
1255 | /* Start fabric.c code */ | ||
1256 | |||
1257 | static int usbg_check_true(struct se_portal_group *se_tpg) | ||
1258 | { | ||
1259 | return 1; | ||
1260 | } | ||
1261 | |||
1262 | static int usbg_check_false(struct se_portal_group *se_tpg) | ||
1263 | { | ||
1264 | return 0; | ||
1265 | } | ||
1266 | |||
1267 | static char *usbg_get_fabric_name(void) | ||
1268 | { | ||
1269 | return "usb_gadget"; | ||
1270 | } | ||
1271 | |||
1272 | static u8 usbg_get_fabric_proto_ident(struct se_portal_group *se_tpg) | ||
1273 | { | ||
1274 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1275 | struct usbg_tpg, se_tpg); | ||
1276 | struct usbg_tport *tport = tpg->tport; | ||
1277 | u8 proto_id; | ||
1278 | |||
1279 | switch (tport->tport_proto_id) { | ||
1280 | case SCSI_PROTOCOL_SAS: | ||
1281 | default: | ||
1282 | proto_id = sas_get_fabric_proto_ident(se_tpg); | ||
1283 | break; | ||
1284 | } | ||
1285 | |||
1286 | return proto_id; | ||
1287 | } | ||
1288 | |||
1289 | static char *usbg_get_fabric_wwn(struct se_portal_group *se_tpg) | ||
1290 | { | ||
1291 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1292 | struct usbg_tpg, se_tpg); | ||
1293 | struct usbg_tport *tport = tpg->tport; | ||
1294 | |||
1295 | return &tport->tport_name[0]; | ||
1296 | } | ||
1297 | |||
1298 | static u16 usbg_get_tag(struct se_portal_group *se_tpg) | ||
1299 | { | ||
1300 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1301 | struct usbg_tpg, se_tpg); | ||
1302 | return tpg->tport_tpgt; | ||
1303 | } | ||
1304 | |||
1305 | static u32 usbg_get_default_depth(struct se_portal_group *se_tpg) | ||
1306 | { | ||
1307 | return 1; | ||
1308 | } | ||
1309 | |||
1310 | static u32 usbg_get_pr_transport_id( | ||
1311 | struct se_portal_group *se_tpg, | ||
1312 | struct se_node_acl *se_nacl, | ||
1313 | struct t10_pr_registration *pr_reg, | ||
1314 | int *format_code, | ||
1315 | unsigned char *buf) | ||
1316 | { | ||
1317 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1318 | struct usbg_tpg, se_tpg); | ||
1319 | struct usbg_tport *tport = tpg->tport; | ||
1320 | int ret = 0; | ||
1321 | |||
1322 | switch (tport->tport_proto_id) { | ||
1323 | case SCSI_PROTOCOL_SAS: | ||
1324 | default: | ||
1325 | ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, | ||
1326 | format_code, buf); | ||
1327 | break; | ||
1328 | } | ||
1329 | |||
1330 | return ret; | ||
1331 | } | ||
1332 | |||
1333 | static u32 usbg_get_pr_transport_id_len( | ||
1334 | struct se_portal_group *se_tpg, | ||
1335 | struct se_node_acl *se_nacl, | ||
1336 | struct t10_pr_registration *pr_reg, | ||
1337 | int *format_code) | ||
1338 | { | ||
1339 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1340 | struct usbg_tpg, se_tpg); | ||
1341 | struct usbg_tport *tport = tpg->tport; | ||
1342 | int ret = 0; | ||
1343 | |||
1344 | switch (tport->tport_proto_id) { | ||
1345 | case SCSI_PROTOCOL_SAS: | ||
1346 | default: | ||
1347 | ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, | ||
1348 | format_code); | ||
1349 | break; | ||
1350 | } | ||
1351 | |||
1352 | return ret; | ||
1353 | } | ||
1354 | |||
1355 | static char *usbg_parse_pr_out_transport_id( | ||
1356 | struct se_portal_group *se_tpg, | ||
1357 | const char *buf, | ||
1358 | u32 *out_tid_len, | ||
1359 | char **port_nexus_ptr) | ||
1360 | { | ||
1361 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1362 | struct usbg_tpg, se_tpg); | ||
1363 | struct usbg_tport *tport = tpg->tport; | ||
1364 | char *tid = NULL; | ||
1365 | |||
1366 | switch (tport->tport_proto_id) { | ||
1367 | case SCSI_PROTOCOL_SAS: | ||
1368 | default: | ||
1369 | tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, | ||
1370 | port_nexus_ptr); | ||
1371 | } | ||
1372 | |||
1373 | return tid; | ||
1374 | } | ||
1375 | |||
1376 | static struct se_node_acl *usbg_alloc_fabric_acl(struct se_portal_group *se_tpg) | ||
1377 | { | ||
1378 | struct usbg_nacl *nacl; | ||
1379 | |||
1380 | nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL); | ||
1381 | if (!nacl) { | ||
1382 | printk(KERN_ERR "Unable to alocate struct usbg_nacl\n"); | ||
1383 | return NULL; | ||
1384 | } | ||
1385 | |||
1386 | return &nacl->se_node_acl; | ||
1387 | } | ||
1388 | |||
1389 | static void usbg_release_fabric_acl( | ||
1390 | struct se_portal_group *se_tpg, | ||
1391 | struct se_node_acl *se_nacl) | ||
1392 | { | ||
1393 | struct usbg_nacl *nacl = container_of(se_nacl, | ||
1394 | struct usbg_nacl, se_node_acl); | ||
1395 | kfree(nacl); | ||
1396 | } | ||
1397 | |||
1398 | static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg) | ||
1399 | { | ||
1400 | return 1; | ||
1401 | } | ||
1402 | |||
1403 | static int usbg_new_cmd(struct se_cmd *se_cmd) | ||
1404 | { | ||
1405 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1406 | se_cmd); | ||
1407 | int ret; | ||
1408 | |||
1409 | ret = target_setup_cmd_from_cdb(se_cmd, cmd->cmd_buf); | ||
1410 | if (ret) | ||
1411 | return ret; | ||
1412 | |||
1413 | return transport_generic_map_mem_to_cmd(se_cmd, NULL, 0, NULL, 0); | ||
1414 | } | ||
1415 | |||
1416 | static void usbg_cmd_release(struct kref *ref) | ||
1417 | { | ||
1418 | struct usbg_cmd *cmd = container_of(ref, struct usbg_cmd, | ||
1419 | ref); | ||
1420 | |||
1421 | transport_generic_free_cmd(&cmd->se_cmd, 0); | ||
1422 | } | ||
1423 | |||
1424 | static void usbg_release_cmd(struct se_cmd *se_cmd) | ||
1425 | { | ||
1426 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1427 | se_cmd); | ||
1428 | kfree(cmd->data_buf); | ||
1429 | kfree(cmd); | ||
1430 | return; | ||
1431 | } | ||
1432 | |||
1433 | static int usbg_shutdown_session(struct se_session *se_sess) | ||
1434 | { | ||
1435 | return 0; | ||
1436 | } | ||
1437 | |||
1438 | static void usbg_close_session(struct se_session *se_sess) | ||
1439 | { | ||
1440 | return; | ||
1441 | } | ||
1442 | |||
1443 | static u32 usbg_sess_get_index(struct se_session *se_sess) | ||
1444 | { | ||
1445 | return 0; | ||
1446 | } | ||
1447 | |||
1448 | /* | ||
1449 | * XXX Error recovery: return != 0 if we expect writes. Dunno when that could be | ||
1450 | */ | ||
1451 | static int usbg_write_pending_status(struct se_cmd *se_cmd) | ||
1452 | { | ||
1453 | return 0; | ||
1454 | } | ||
1455 | |||
1456 | static void usbg_set_default_node_attrs(struct se_node_acl *nacl) | ||
1457 | { | ||
1458 | return; | ||
1459 | } | ||
1460 | |||
1461 | static u32 usbg_get_task_tag(struct se_cmd *se_cmd) | ||
1462 | { | ||
1463 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1464 | se_cmd); | ||
1465 | struct f_uas *fu = cmd->fu; | ||
1466 | |||
1467 | if (fu->flags & USBG_IS_BOT) | ||
1468 | return le32_to_cpu(cmd->bot_tag); | ||
1469 | else | ||
1470 | return cmd->tag; | ||
1471 | } | ||
1472 | |||
1473 | static int usbg_get_cmd_state(struct se_cmd *se_cmd) | ||
1474 | { | ||
1475 | return 0; | ||
1476 | } | ||
1477 | |||
1478 | static int usbg_queue_tm_rsp(struct se_cmd *se_cmd) | ||
1479 | { | ||
1480 | return 0; | ||
1481 | } | ||
1482 | |||
1483 | static u16 usbg_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length) | ||
1484 | { | ||
1485 | return 0; | ||
1486 | } | ||
1487 | |||
1488 | static u16 usbg_get_fabric_sense_len(void) | ||
1489 | { | ||
1490 | return 0; | ||
1491 | } | ||
1492 | |||
1493 | static const char *usbg_check_wwn(const char *name) | ||
1494 | { | ||
1495 | const char *n; | ||
1496 | unsigned int len; | ||
1497 | |||
1498 | n = strstr(name, "naa."); | ||
1499 | if (!n) | ||
1500 | return NULL; | ||
1501 | n += 4; | ||
1502 | len = strlen(n); | ||
1503 | if (len == 0 || len > USBG_NAMELEN - 1) | ||
1504 | return NULL; | ||
1505 | return n; | ||
1506 | } | ||
1507 | |||
1508 | static struct se_node_acl *usbg_make_nodeacl( | ||
1509 | struct se_portal_group *se_tpg, | ||
1510 | struct config_group *group, | ||
1511 | const char *name) | ||
1512 | { | ||
1513 | struct se_node_acl *se_nacl, *se_nacl_new; | ||
1514 | struct usbg_nacl *nacl; | ||
1515 | u64 wwpn = 0; | ||
1516 | u32 nexus_depth; | ||
1517 | const char *wnn_name; | ||
1518 | |||
1519 | wnn_name = usbg_check_wwn(name); | ||
1520 | if (!wnn_name) | ||
1521 | return ERR_PTR(-EINVAL); | ||
1522 | se_nacl_new = usbg_alloc_fabric_acl(se_tpg); | ||
1523 | if (!(se_nacl_new)) | ||
1524 | return ERR_PTR(-ENOMEM); | ||
1525 | |||
1526 | nexus_depth = 1; | ||
1527 | /* | ||
1528 | * se_nacl_new may be released by core_tpg_add_initiator_node_acl() | ||
1529 | * when converting a NodeACL from demo mode -> explict | ||
1530 | */ | ||
1531 | se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, | ||
1532 | name, nexus_depth); | ||
1533 | if (IS_ERR(se_nacl)) { | ||
1534 | usbg_release_fabric_acl(se_tpg, se_nacl_new); | ||
1535 | return se_nacl; | ||
1536 | } | ||
1537 | /* | ||
1538 | * Locate our struct usbg_nacl and set the FC Nport WWPN | ||
1539 | */ | ||
1540 | nacl = container_of(se_nacl, struct usbg_nacl, se_node_acl); | ||
1541 | nacl->iport_wwpn = wwpn; | ||
1542 | snprintf(nacl->iport_name, sizeof(nacl->iport_name), "%s", name); | ||
1543 | return se_nacl; | ||
1544 | } | ||
1545 | |||
1546 | static void usbg_drop_nodeacl(struct se_node_acl *se_acl) | ||
1547 | { | ||
1548 | struct usbg_nacl *nacl = container_of(se_acl, | ||
1549 | struct usbg_nacl, se_node_acl); | ||
1550 | core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1); | ||
1551 | kfree(nacl); | ||
1552 | } | ||
1553 | |||
1554 | struct usbg_tpg *the_only_tpg_I_currently_have; | ||
1555 | |||
1556 | static struct se_portal_group *usbg_make_tpg( | ||
1557 | struct se_wwn *wwn, | ||
1558 | struct config_group *group, | ||
1559 | const char *name) | ||
1560 | { | ||
1561 | struct usbg_tport *tport = container_of(wwn, struct usbg_tport, | ||
1562 | tport_wwn); | ||
1563 | struct usbg_tpg *tpg; | ||
1564 | unsigned long tpgt; | ||
1565 | int ret; | ||
1566 | |||
1567 | if (strstr(name, "tpgt_") != name) | ||
1568 | return ERR_PTR(-EINVAL); | ||
1569 | if (kstrtoul(name + 5, 0, &tpgt) || tpgt > UINT_MAX) | ||
1570 | return ERR_PTR(-EINVAL); | ||
1571 | if (the_only_tpg_I_currently_have) { | ||
1572 | pr_err("Until the gadget framework can't handle multiple\n"); | ||
1573 | pr_err("gadgets, you can't do this here.\n"); | ||
1574 | return ERR_PTR(-EBUSY); | ||
1575 | } | ||
1576 | |||
1577 | tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); | ||
1578 | if (!tpg) { | ||
1579 | printk(KERN_ERR "Unable to allocate struct usbg_tpg"); | ||
1580 | return ERR_PTR(-ENOMEM); | ||
1581 | } | ||
1582 | mutex_init(&tpg->tpg_mutex); | ||
1583 | atomic_set(&tpg->tpg_port_count, 0); | ||
1584 | tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); | ||
1585 | if (!tpg->workqueue) { | ||
1586 | kfree(tpg); | ||
1587 | return NULL; | ||
1588 | } | ||
1589 | |||
1590 | tpg->tport = tport; | ||
1591 | tpg->tport_tpgt = tpgt; | ||
1592 | |||
1593 | ret = core_tpg_register(&usbg_fabric_configfs->tf_ops, wwn, | ||
1594 | &tpg->se_tpg, tpg, | ||
1595 | TRANSPORT_TPG_TYPE_NORMAL); | ||
1596 | if (ret < 0) { | ||
1597 | destroy_workqueue(tpg->workqueue); | ||
1598 | kfree(tpg); | ||
1599 | return NULL; | ||
1600 | } | ||
1601 | the_only_tpg_I_currently_have = tpg; | ||
1602 | return &tpg->se_tpg; | ||
1603 | } | ||
1604 | |||
1605 | static void usbg_drop_tpg(struct se_portal_group *se_tpg) | ||
1606 | { | ||
1607 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1608 | struct usbg_tpg, se_tpg); | ||
1609 | |||
1610 | core_tpg_deregister(se_tpg); | ||
1611 | destroy_workqueue(tpg->workqueue); | ||
1612 | kfree(tpg); | ||
1613 | the_only_tpg_I_currently_have = NULL; | ||
1614 | } | ||
1615 | |||
1616 | static struct se_wwn *usbg_make_tport( | ||
1617 | struct target_fabric_configfs *tf, | ||
1618 | struct config_group *group, | ||
1619 | const char *name) | ||
1620 | { | ||
1621 | struct usbg_tport *tport; | ||
1622 | const char *wnn_name; | ||
1623 | u64 wwpn = 0; | ||
1624 | |||
1625 | wnn_name = usbg_check_wwn(name); | ||
1626 | if (!wnn_name) | ||
1627 | return ERR_PTR(-EINVAL); | ||
1628 | |||
1629 | tport = kzalloc(sizeof(struct usbg_tport), GFP_KERNEL); | ||
1630 | if (!(tport)) { | ||
1631 | printk(KERN_ERR "Unable to allocate struct usbg_tport"); | ||
1632 | return ERR_PTR(-ENOMEM); | ||
1633 | } | ||
1634 | tport->tport_wwpn = wwpn; | ||
1635 | snprintf(tport->tport_name, sizeof(tport->tport_name), wnn_name); | ||
1636 | return &tport->tport_wwn; | ||
1637 | } | ||
1638 | |||
1639 | static void usbg_drop_tport(struct se_wwn *wwn) | ||
1640 | { | ||
1641 | struct usbg_tport *tport = container_of(wwn, | ||
1642 | struct usbg_tport, tport_wwn); | ||
1643 | kfree(tport); | ||
1644 | } | ||
1645 | |||
1646 | /* | ||
1647 | * If somebody feels like dropping the version property, go ahead. | ||
1648 | */ | ||
1649 | static ssize_t usbg_wwn_show_attr_version( | ||
1650 | struct target_fabric_configfs *tf, | ||
1651 | char *page) | ||
1652 | { | ||
1653 | return sprintf(page, "usb-gadget fabric module\n"); | ||
1654 | } | ||
1655 | TF_WWN_ATTR_RO(usbg, version); | ||
1656 | |||
1657 | static struct configfs_attribute *usbg_wwn_attrs[] = { | ||
1658 | &usbg_wwn_version.attr, | ||
1659 | NULL, | ||
1660 | }; | ||
1661 | |||
1662 | static ssize_t tcm_usbg_tpg_show_enable( | ||
1663 | struct se_portal_group *se_tpg, | ||
1664 | char *page) | ||
1665 | { | ||
1666 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1667 | |||
1668 | return snprintf(page, PAGE_SIZE, "%u\n", tpg->gadget_connect); | ||
1669 | } | ||
1670 | |||
1671 | static int usbg_attach(struct usbg_tpg *); | ||
1672 | static void usbg_detach(struct usbg_tpg *); | ||
1673 | |||
1674 | static ssize_t tcm_usbg_tpg_store_enable( | ||
1675 | struct se_portal_group *se_tpg, | ||
1676 | const char *page, | ||
1677 | size_t count) | ||
1678 | { | ||
1679 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1680 | unsigned long op; | ||
1681 | ssize_t ret; | ||
1682 | |||
1683 | ret = kstrtoul(page, 0, &op); | ||
1684 | if (ret < 0) | ||
1685 | return -EINVAL; | ||
1686 | if (op > 1) | ||
1687 | return -EINVAL; | ||
1688 | |||
1689 | if (op && tpg->gadget_connect) | ||
1690 | goto out; | ||
1691 | if (!op && !tpg->gadget_connect) | ||
1692 | goto out; | ||
1693 | |||
1694 | if (op) { | ||
1695 | ret = usbg_attach(tpg); | ||
1696 | if (ret) | ||
1697 | goto out; | ||
1698 | } else { | ||
1699 | usbg_detach(tpg); | ||
1700 | } | ||
1701 | tpg->gadget_connect = op; | ||
1702 | out: | ||
1703 | return count; | ||
1704 | } | ||
1705 | TF_TPG_BASE_ATTR(tcm_usbg, enable, S_IRUGO | S_IWUSR); | ||
1706 | |||
1707 | static ssize_t tcm_usbg_tpg_show_nexus( | ||
1708 | struct se_portal_group *se_tpg, | ||
1709 | char *page) | ||
1710 | { | ||
1711 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1712 | struct tcm_usbg_nexus *tv_nexus; | ||
1713 | ssize_t ret; | ||
1714 | |||
1715 | mutex_lock(&tpg->tpg_mutex); | ||
1716 | tv_nexus = tpg->tpg_nexus; | ||
1717 | if (!tv_nexus) { | ||
1718 | ret = -ENODEV; | ||
1719 | goto out; | ||
1720 | } | ||
1721 | ret = snprintf(page, PAGE_SIZE, "%s\n", | ||
1722 | tv_nexus->tvn_se_sess->se_node_acl->initiatorname); | ||
1723 | out: | ||
1724 | mutex_unlock(&tpg->tpg_mutex); | ||
1725 | return ret; | ||
1726 | } | ||
1727 | |||
1728 | static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name) | ||
1729 | { | ||
1730 | struct se_portal_group *se_tpg; | ||
1731 | struct tcm_usbg_nexus *tv_nexus; | ||
1732 | int ret; | ||
1733 | |||
1734 | mutex_lock(&tpg->tpg_mutex); | ||
1735 | if (tpg->tpg_nexus) { | ||
1736 | ret = -EEXIST; | ||
1737 | pr_debug("tpg->tpg_nexus already exists\n"); | ||
1738 | goto err_unlock; | ||
1739 | } | ||
1740 | se_tpg = &tpg->se_tpg; | ||
1741 | |||
1742 | ret = -ENOMEM; | ||
1743 | tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); | ||
1744 | if (!tv_nexus) { | ||
1745 | pr_err("Unable to allocate struct tcm_vhost_nexus\n"); | ||
1746 | goto err_unlock; | ||
1747 | } | ||
1748 | tv_nexus->tvn_se_sess = transport_init_session(); | ||
1749 | if (IS_ERR(tv_nexus->tvn_se_sess)) | ||
1750 | goto err_free; | ||
1751 | |||
1752 | /* | ||
1753 | * Since we are running in 'demo mode' this call with generate a | ||
1754 | * struct se_node_acl for the tcm_vhost struct se_portal_group with | ||
1755 | * the SCSI Initiator port name of the passed configfs group 'name'. | ||
1756 | */ | ||
1757 | tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl( | ||
1758 | se_tpg, name); | ||
1759 | if (!tv_nexus->tvn_se_sess->se_node_acl) { | ||
1760 | pr_debug("core_tpg_check_initiator_node_acl() failed" | ||
1761 | " for %s\n", name); | ||
1762 | goto err_session; | ||
1763 | } | ||
1764 | /* | ||
1765 | * Now register the TCM vHost virtual I_T Nexus as active with the | ||
1766 | * call to __transport_register_session() | ||
1767 | */ | ||
1768 | __transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl, | ||
1769 | tv_nexus->tvn_se_sess, tv_nexus); | ||
1770 | tpg->tpg_nexus = tv_nexus; | ||
1771 | mutex_unlock(&tpg->tpg_mutex); | ||
1772 | return 0; | ||
1773 | |||
1774 | err_session: | ||
1775 | transport_free_session(tv_nexus->tvn_se_sess); | ||
1776 | err_free: | ||
1777 | kfree(tv_nexus); | ||
1778 | err_unlock: | ||
1779 | mutex_unlock(&tpg->tpg_mutex); | ||
1780 | return ret; | ||
1781 | } | ||
1782 | |||
1783 | static int tcm_usbg_drop_nexus(struct usbg_tpg *tpg) | ||
1784 | { | ||
1785 | struct se_session *se_sess; | ||
1786 | struct tcm_usbg_nexus *tv_nexus; | ||
1787 | int ret = -ENODEV; | ||
1788 | |||
1789 | mutex_lock(&tpg->tpg_mutex); | ||
1790 | tv_nexus = tpg->tpg_nexus; | ||
1791 | if (!tv_nexus) | ||
1792 | goto out; | ||
1793 | |||
1794 | se_sess = tv_nexus->tvn_se_sess; | ||
1795 | if (!se_sess) | ||
1796 | goto out; | ||
1797 | |||
1798 | if (atomic_read(&tpg->tpg_port_count)) { | ||
1799 | ret = -EPERM; | ||
1800 | pr_err("Unable to remove Host I_T Nexus with" | ||
1801 | " active TPG port count: %d\n", | ||
1802 | atomic_read(&tpg->tpg_port_count)); | ||
1803 | goto out; | ||
1804 | } | ||
1805 | |||
1806 | pr_debug("Removing I_T Nexus to Initiator Port: %s\n", | ||
1807 | tv_nexus->tvn_se_sess->se_node_acl->initiatorname); | ||
1808 | /* | ||
1809 | * Release the SCSI I_T Nexus to the emulated vHost Target Port | ||
1810 | */ | ||
1811 | transport_deregister_session(tv_nexus->tvn_se_sess); | ||
1812 | tpg->tpg_nexus = NULL; | ||
1813 | |||
1814 | kfree(tv_nexus); | ||
1815 | out: | ||
1816 | mutex_unlock(&tpg->tpg_mutex); | ||
1817 | return 0; | ||
1818 | } | ||
1819 | |||
1820 | static ssize_t tcm_usbg_tpg_store_nexus( | ||
1821 | struct se_portal_group *se_tpg, | ||
1822 | const char *page, | ||
1823 | size_t count) | ||
1824 | { | ||
1825 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1826 | unsigned char i_port[USBG_NAMELEN], *ptr; | ||
1827 | int ret; | ||
1828 | |||
1829 | if (!strncmp(page, "NULL", 4)) { | ||
1830 | ret = tcm_usbg_drop_nexus(tpg); | ||
1831 | return (!ret) ? count : ret; | ||
1832 | } | ||
1833 | if (strlen(page) > USBG_NAMELEN) { | ||
1834 | pr_err("Emulated NAA Sas Address: %s, exceeds" | ||
1835 | " max: %d\n", page, USBG_NAMELEN); | ||
1836 | return -EINVAL; | ||
1837 | } | ||
1838 | snprintf(i_port, USBG_NAMELEN, "%s", page); | ||
1839 | |||
1840 | ptr = strstr(i_port, "naa."); | ||
1841 | if (!ptr) { | ||
1842 | pr_err("Missing 'naa.' prefix\n"); | ||
1843 | return -EINVAL; | ||
1844 | } | ||
1845 | |||
1846 | if (i_port[strlen(i_port) - 1] == '\n') | ||
1847 | i_port[strlen(i_port) - 1] = '\0'; | ||
1848 | |||
1849 | ret = tcm_usbg_make_nexus(tpg, &i_port[4]); | ||
1850 | if (ret < 0) | ||
1851 | return ret; | ||
1852 | return count; | ||
1853 | } | ||
1854 | TF_TPG_BASE_ATTR(tcm_usbg, nexus, S_IRUGO | S_IWUSR); | ||
1855 | |||
1856 | static struct configfs_attribute *usbg_base_attrs[] = { | ||
1857 | &tcm_usbg_tpg_enable.attr, | ||
1858 | &tcm_usbg_tpg_nexus.attr, | ||
1859 | NULL, | ||
1860 | }; | ||
1861 | |||
1862 | static int usbg_port_link(struct se_portal_group *se_tpg, struct se_lun *lun) | ||
1863 | { | ||
1864 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1865 | |||
1866 | atomic_inc(&tpg->tpg_port_count); | ||
1867 | smp_mb__after_atomic_inc(); | ||
1868 | return 0; | ||
1869 | } | ||
1870 | |||
1871 | static void usbg_port_unlink(struct se_portal_group *se_tpg, | ||
1872 | struct se_lun *se_lun) | ||
1873 | { | ||
1874 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | ||
1875 | |||
1876 | atomic_dec(&tpg->tpg_port_count); | ||
1877 | smp_mb__after_atomic_dec(); | ||
1878 | } | ||
1879 | |||
1880 | static int usbg_check_stop_free(struct se_cmd *se_cmd) | ||
1881 | { | ||
1882 | struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, | ||
1883 | se_cmd); | ||
1884 | |||
1885 | kref_put(&cmd->ref, usbg_cmd_release); | ||
1886 | return 1; | ||
1887 | } | ||
1888 | |||
1889 | static struct target_core_fabric_ops usbg_ops = { | ||
1890 | .get_fabric_name = usbg_get_fabric_name, | ||
1891 | .get_fabric_proto_ident = usbg_get_fabric_proto_ident, | ||
1892 | .tpg_get_wwn = usbg_get_fabric_wwn, | ||
1893 | .tpg_get_tag = usbg_get_tag, | ||
1894 | .tpg_get_default_depth = usbg_get_default_depth, | ||
1895 | .tpg_get_pr_transport_id = usbg_get_pr_transport_id, | ||
1896 | .tpg_get_pr_transport_id_len = usbg_get_pr_transport_id_len, | ||
1897 | .tpg_parse_pr_out_transport_id = usbg_parse_pr_out_transport_id, | ||
1898 | .tpg_check_demo_mode = usbg_check_true, | ||
1899 | .tpg_check_demo_mode_cache = usbg_check_false, | ||
1900 | .tpg_check_demo_mode_write_protect = usbg_check_false, | ||
1901 | .tpg_check_prod_mode_write_protect = usbg_check_false, | ||
1902 | .tpg_alloc_fabric_acl = usbg_alloc_fabric_acl, | ||
1903 | .tpg_release_fabric_acl = usbg_release_fabric_acl, | ||
1904 | .tpg_get_inst_index = usbg_tpg_get_inst_index, | ||
1905 | .new_cmd_map = usbg_new_cmd, | ||
1906 | .release_cmd = usbg_release_cmd, | ||
1907 | .shutdown_session = usbg_shutdown_session, | ||
1908 | .close_session = usbg_close_session, | ||
1909 | .sess_get_index = usbg_sess_get_index, | ||
1910 | .sess_get_initiator_sid = NULL, | ||
1911 | .write_pending = usbg_send_write_request, | ||
1912 | .write_pending_status = usbg_write_pending_status, | ||
1913 | .set_default_node_attributes = usbg_set_default_node_attrs, | ||
1914 | .get_task_tag = usbg_get_task_tag, | ||
1915 | .get_cmd_state = usbg_get_cmd_state, | ||
1916 | .queue_data_in = usbg_send_read_response, | ||
1917 | .queue_status = usbg_send_status_response, | ||
1918 | .queue_tm_rsp = usbg_queue_tm_rsp, | ||
1919 | .get_fabric_sense_len = usbg_get_fabric_sense_len, | ||
1920 | .set_fabric_sense_len = usbg_set_fabric_sense_len, | ||
1921 | .check_stop_free = usbg_check_stop_free, | ||
1922 | |||
1923 | .fabric_make_wwn = usbg_make_tport, | ||
1924 | .fabric_drop_wwn = usbg_drop_tport, | ||
1925 | .fabric_make_tpg = usbg_make_tpg, | ||
1926 | .fabric_drop_tpg = usbg_drop_tpg, | ||
1927 | .fabric_post_link = usbg_port_link, | ||
1928 | .fabric_pre_unlink = usbg_port_unlink, | ||
1929 | .fabric_make_np = NULL, | ||
1930 | .fabric_drop_np = NULL, | ||
1931 | .fabric_make_nodeacl = usbg_make_nodeacl, | ||
1932 | .fabric_drop_nodeacl = usbg_drop_nodeacl, | ||
1933 | }; | ||
1934 | |||
1935 | static int usbg_register_configfs(void) | ||
1936 | { | ||
1937 | struct target_fabric_configfs *fabric; | ||
1938 | int ret; | ||
1939 | |||
1940 | fabric = target_fabric_configfs_init(THIS_MODULE, "usb_gadget"); | ||
1941 | if (IS_ERR(fabric)) { | ||
1942 | printk(KERN_ERR "target_fabric_configfs_init() failed\n"); | ||
1943 | return PTR_ERR(fabric); | ||
1944 | } | ||
1945 | |||
1946 | fabric->tf_ops = usbg_ops; | ||
1947 | TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = usbg_wwn_attrs; | ||
1948 | TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = usbg_base_attrs; | ||
1949 | TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL; | ||
1950 | TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL; | ||
1951 | TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
1952 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL; | ||
1953 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; | ||
1954 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL; | ||
1955 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL; | ||
1956 | ret = target_fabric_configfs_register(fabric); | ||
1957 | if (ret < 0) { | ||
1958 | printk(KERN_ERR "target_fabric_configfs_register() failed" | ||
1959 | " for usb-gadget\n"); | ||
1960 | return ret; | ||
1961 | } | ||
1962 | usbg_fabric_configfs = fabric; | ||
1963 | return 0; | ||
1964 | }; | ||
1965 | |||
1966 | static void usbg_deregister_configfs(void) | ||
1967 | { | ||
1968 | if (!(usbg_fabric_configfs)) | ||
1969 | return; | ||
1970 | |||
1971 | target_fabric_configfs_deregister(usbg_fabric_configfs); | ||
1972 | usbg_fabric_configfs = NULL; | ||
1973 | }; | ||
1974 | |||
1975 | /* Start gadget.c code */ | ||
1976 | |||
1977 | static struct usb_interface_descriptor bot_intf_desc = { | ||
1978 | .bLength = sizeof(bot_intf_desc), | ||
1979 | .bDescriptorType = USB_DT_INTERFACE, | ||
1980 | .bAlternateSetting = 0, | ||
1981 | .bNumEndpoints = 2, | ||
1982 | .bAlternateSetting = USB_G_ALT_INT_BBB, | ||
1983 | .bInterfaceClass = USB_CLASS_MASS_STORAGE, | ||
1984 | .bInterfaceSubClass = USB_SC_SCSI, | ||
1985 | .bInterfaceProtocol = USB_PR_BULK, | ||
1986 | .iInterface = USB_G_STR_INT_UAS, | ||
1987 | }; | ||
1988 | |||
1989 | static struct usb_interface_descriptor uasp_intf_desc = { | ||
1990 | .bLength = sizeof(uasp_intf_desc), | ||
1991 | .bDescriptorType = USB_DT_INTERFACE, | ||
1992 | .bNumEndpoints = 4, | ||
1993 | .bAlternateSetting = USB_G_ALT_INT_UAS, | ||
1994 | .bInterfaceClass = USB_CLASS_MASS_STORAGE, | ||
1995 | .bInterfaceSubClass = USB_SC_SCSI, | ||
1996 | .bInterfaceProtocol = USB_PR_UAS, | ||
1997 | .iInterface = USB_G_STR_INT_BBB, | ||
1998 | }; | ||
1999 | |||
2000 | static struct usb_endpoint_descriptor uasp_bi_desc = { | ||
2001 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2002 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2003 | .bEndpointAddress = USB_DIR_IN, | ||
2004 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2005 | .wMaxPacketSize = cpu_to_le16(512), | ||
2006 | }; | ||
2007 | |||
2008 | static struct usb_endpoint_descriptor uasp_fs_bi_desc = { | ||
2009 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2010 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2011 | .bEndpointAddress = USB_DIR_IN, | ||
2012 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2013 | }; | ||
2014 | |||
2015 | static struct usb_pipe_usage_descriptor uasp_bi_pipe_desc = { | ||
2016 | .bLength = sizeof(uasp_bi_pipe_desc), | ||
2017 | .bDescriptorType = USB_DT_PIPE_USAGE, | ||
2018 | .bPipeID = DATA_IN_PIPE_ID, | ||
2019 | }; | ||
2020 | |||
2021 | static struct usb_endpoint_descriptor uasp_ss_bi_desc = { | ||
2022 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2023 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2024 | .bEndpointAddress = USB_DIR_IN, | ||
2025 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2026 | .wMaxPacketSize = cpu_to_le16(1024), | ||
2027 | }; | ||
2028 | |||
2029 | static struct usb_ss_ep_comp_descriptor uasp_bi_ep_comp_desc = { | ||
2030 | .bLength = sizeof(uasp_bi_ep_comp_desc), | ||
2031 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2032 | .bMaxBurst = 0, | ||
2033 | .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, | ||
2034 | .wBytesPerInterval = 0, | ||
2035 | }; | ||
2036 | |||
2037 | static struct usb_ss_ep_comp_descriptor bot_bi_ep_comp_desc = { | ||
2038 | .bLength = sizeof(bot_bi_ep_comp_desc), | ||
2039 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2040 | .bMaxBurst = 0, | ||
2041 | }; | ||
2042 | |||
2043 | static struct usb_endpoint_descriptor uasp_bo_desc = { | ||
2044 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2045 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2046 | .bEndpointAddress = USB_DIR_OUT, | ||
2047 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2048 | .wMaxPacketSize = cpu_to_le16(512), | ||
2049 | }; | ||
2050 | |||
2051 | static struct usb_endpoint_descriptor uasp_fs_bo_desc = { | ||
2052 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2053 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2054 | .bEndpointAddress = USB_DIR_OUT, | ||
2055 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2056 | }; | ||
2057 | |||
2058 | static struct usb_pipe_usage_descriptor uasp_bo_pipe_desc = { | ||
2059 | .bLength = sizeof(uasp_bo_pipe_desc), | ||
2060 | .bDescriptorType = USB_DT_PIPE_USAGE, | ||
2061 | .bPipeID = DATA_OUT_PIPE_ID, | ||
2062 | }; | ||
2063 | |||
2064 | static struct usb_endpoint_descriptor uasp_ss_bo_desc = { | ||
2065 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2066 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2067 | .bEndpointAddress = USB_DIR_OUT, | ||
2068 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2069 | .wMaxPacketSize = cpu_to_le16(0x400), | ||
2070 | }; | ||
2071 | |||
2072 | static struct usb_ss_ep_comp_descriptor uasp_bo_ep_comp_desc = { | ||
2073 | .bLength = sizeof(uasp_bo_ep_comp_desc), | ||
2074 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2075 | .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, | ||
2076 | }; | ||
2077 | |||
2078 | static struct usb_ss_ep_comp_descriptor bot_bo_ep_comp_desc = { | ||
2079 | .bLength = sizeof(bot_bo_ep_comp_desc), | ||
2080 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2081 | }; | ||
2082 | |||
2083 | static struct usb_endpoint_descriptor uasp_status_desc = { | ||
2084 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2085 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2086 | .bEndpointAddress = USB_DIR_IN, | ||
2087 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2088 | .wMaxPacketSize = cpu_to_le16(512), | ||
2089 | }; | ||
2090 | |||
2091 | static struct usb_endpoint_descriptor uasp_fs_status_desc = { | ||
2092 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2093 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2094 | .bEndpointAddress = USB_DIR_IN, | ||
2095 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2096 | }; | ||
2097 | |||
2098 | static struct usb_pipe_usage_descriptor uasp_status_pipe_desc = { | ||
2099 | .bLength = sizeof(uasp_status_pipe_desc), | ||
2100 | .bDescriptorType = USB_DT_PIPE_USAGE, | ||
2101 | .bPipeID = STATUS_PIPE_ID, | ||
2102 | }; | ||
2103 | |||
2104 | static struct usb_endpoint_descriptor uasp_ss_status_desc = { | ||
2105 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2106 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2107 | .bEndpointAddress = USB_DIR_IN, | ||
2108 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2109 | .wMaxPacketSize = cpu_to_le16(1024), | ||
2110 | }; | ||
2111 | |||
2112 | static struct usb_ss_ep_comp_descriptor uasp_status_in_ep_comp_desc = { | ||
2113 | .bLength = sizeof(uasp_status_in_ep_comp_desc), | ||
2114 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2115 | .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, | ||
2116 | }; | ||
2117 | |||
2118 | static struct usb_endpoint_descriptor uasp_cmd_desc = { | ||
2119 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2120 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2121 | .bEndpointAddress = USB_DIR_OUT, | ||
2122 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2123 | .wMaxPacketSize = cpu_to_le16(512), | ||
2124 | }; | ||
2125 | |||
2126 | static struct usb_endpoint_descriptor uasp_fs_cmd_desc = { | ||
2127 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2128 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2129 | .bEndpointAddress = USB_DIR_OUT, | ||
2130 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2131 | }; | ||
2132 | |||
2133 | static struct usb_pipe_usage_descriptor uasp_cmd_pipe_desc = { | ||
2134 | .bLength = sizeof(uasp_cmd_pipe_desc), | ||
2135 | .bDescriptorType = USB_DT_PIPE_USAGE, | ||
2136 | .bPipeID = CMD_PIPE_ID, | ||
2137 | }; | ||
2138 | |||
2139 | static struct usb_endpoint_descriptor uasp_ss_cmd_desc = { | ||
2140 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
2141 | .bDescriptorType = USB_DT_ENDPOINT, | ||
2142 | .bEndpointAddress = USB_DIR_OUT, | ||
2143 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
2144 | .wMaxPacketSize = cpu_to_le16(1024), | ||
2145 | }; | ||
2146 | |||
2147 | static struct usb_ss_ep_comp_descriptor uasp_cmd_comp_desc = { | ||
2148 | .bLength = sizeof(uasp_cmd_comp_desc), | ||
2149 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
2150 | }; | ||
2151 | |||
2152 | static struct usb_descriptor_header *uasp_fs_function_desc[] = { | ||
2153 | (struct usb_descriptor_header *) &bot_intf_desc, | ||
2154 | (struct usb_descriptor_header *) &uasp_fs_bi_desc, | ||
2155 | (struct usb_descriptor_header *) &uasp_fs_bo_desc, | ||
2156 | |||
2157 | (struct usb_descriptor_header *) &uasp_intf_desc, | ||
2158 | (struct usb_descriptor_header *) &uasp_fs_bi_desc, | ||
2159 | (struct usb_descriptor_header *) &uasp_bi_pipe_desc, | ||
2160 | (struct usb_descriptor_header *) &uasp_fs_bo_desc, | ||
2161 | (struct usb_descriptor_header *) &uasp_bo_pipe_desc, | ||
2162 | (struct usb_descriptor_header *) &uasp_fs_status_desc, | ||
2163 | (struct usb_descriptor_header *) &uasp_status_pipe_desc, | ||
2164 | (struct usb_descriptor_header *) &uasp_fs_cmd_desc, | ||
2165 | (struct usb_descriptor_header *) &uasp_cmd_pipe_desc, | ||
2166 | }; | ||
2167 | |||
2168 | static struct usb_descriptor_header *uasp_hs_function_desc[] = { | ||
2169 | (struct usb_descriptor_header *) &bot_intf_desc, | ||
2170 | (struct usb_descriptor_header *) &uasp_bi_desc, | ||
2171 | (struct usb_descriptor_header *) &uasp_bo_desc, | ||
2172 | |||
2173 | (struct usb_descriptor_header *) &uasp_intf_desc, | ||
2174 | (struct usb_descriptor_header *) &uasp_bi_desc, | ||
2175 | (struct usb_descriptor_header *) &uasp_bi_pipe_desc, | ||
2176 | (struct usb_descriptor_header *) &uasp_bo_desc, | ||
2177 | (struct usb_descriptor_header *) &uasp_bo_pipe_desc, | ||
2178 | (struct usb_descriptor_header *) &uasp_status_desc, | ||
2179 | (struct usb_descriptor_header *) &uasp_status_pipe_desc, | ||
2180 | (struct usb_descriptor_header *) &uasp_cmd_desc, | ||
2181 | (struct usb_descriptor_header *) &uasp_cmd_pipe_desc, | ||
2182 | NULL, | ||
2183 | }; | ||
2184 | |||
2185 | static struct usb_descriptor_header *uasp_ss_function_desc[] = { | ||
2186 | (struct usb_descriptor_header *) &bot_intf_desc, | ||
2187 | (struct usb_descriptor_header *) &uasp_ss_bi_desc, | ||
2188 | (struct usb_descriptor_header *) &bot_bi_ep_comp_desc, | ||
2189 | (struct usb_descriptor_header *) &uasp_ss_bo_desc, | ||
2190 | (struct usb_descriptor_header *) &bot_bo_ep_comp_desc, | ||
2191 | |||
2192 | (struct usb_descriptor_header *) &uasp_intf_desc, | ||
2193 | (struct usb_descriptor_header *) &uasp_ss_bi_desc, | ||
2194 | (struct usb_descriptor_header *) &uasp_bi_ep_comp_desc, | ||
2195 | (struct usb_descriptor_header *) &uasp_bi_pipe_desc, | ||
2196 | (struct usb_descriptor_header *) &uasp_ss_bo_desc, | ||
2197 | (struct usb_descriptor_header *) &uasp_bo_ep_comp_desc, | ||
2198 | (struct usb_descriptor_header *) &uasp_bo_pipe_desc, | ||
2199 | (struct usb_descriptor_header *) &uasp_ss_status_desc, | ||
2200 | (struct usb_descriptor_header *) &uasp_status_in_ep_comp_desc, | ||
2201 | (struct usb_descriptor_header *) &uasp_status_pipe_desc, | ||
2202 | (struct usb_descriptor_header *) &uasp_ss_cmd_desc, | ||
2203 | (struct usb_descriptor_header *) &uasp_cmd_comp_desc, | ||
2204 | (struct usb_descriptor_header *) &uasp_cmd_pipe_desc, | ||
2205 | NULL, | ||
2206 | }; | ||
2207 | |||
2208 | #define UAS_VENDOR_ID 0x0525 /* NetChip */ | ||
2209 | #define UAS_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ | ||
2210 | |||
2211 | static struct usb_device_descriptor usbg_device_desc = { | ||
2212 | .bLength = sizeof(usbg_device_desc), | ||
2213 | .bDescriptorType = USB_DT_DEVICE, | ||
2214 | .bcdUSB = cpu_to_le16(0x0200), | ||
2215 | .bDeviceClass = USB_CLASS_PER_INTERFACE, | ||
2216 | .idVendor = cpu_to_le16(UAS_VENDOR_ID), | ||
2217 | .idProduct = cpu_to_le16(UAS_PRODUCT_ID), | ||
2218 | .iManufacturer = USB_G_STR_MANUFACTOR, | ||
2219 | .iProduct = USB_G_STR_PRODUCT, | ||
2220 | .iSerialNumber = USB_G_STR_SERIAL, | ||
2221 | |||
2222 | .bNumConfigurations = 1, | ||
2223 | }; | ||
2224 | |||
2225 | static struct usb_string usbg_us_strings[] = { | ||
2226 | { USB_G_STR_MANUFACTOR, "Target Manufactor"}, | ||
2227 | { USB_G_STR_PRODUCT, "Target Product"}, | ||
2228 | { USB_G_STR_SERIAL, "000000000001"}, | ||
2229 | { USB_G_STR_CONFIG, "default config"}, | ||
2230 | { USB_G_STR_INT_UAS, "USB Attached SCSI"}, | ||
2231 | { USB_G_STR_INT_BBB, "Bulk Only Transport"}, | ||
2232 | { }, | ||
2233 | }; | ||
2234 | |||
2235 | static struct usb_gadget_strings usbg_stringtab = { | ||
2236 | .language = 0x0409, | ||
2237 | .strings = usbg_us_strings, | ||
2238 | }; | ||
2239 | |||
2240 | static struct usb_gadget_strings *usbg_strings[] = { | ||
2241 | &usbg_stringtab, | ||
2242 | NULL, | ||
2243 | }; | ||
2244 | |||
2245 | static int guas_unbind(struct usb_composite_dev *cdev) | ||
2246 | { | ||
2247 | return 0; | ||
2248 | } | ||
2249 | |||
2250 | static struct usb_configuration usbg_config_driver = { | ||
2251 | .label = "Linux Target", | ||
2252 | .bConfigurationValue = 1, | ||
2253 | .iConfiguration = USB_G_STR_CONFIG, | ||
2254 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | ||
2255 | }; | ||
2256 | |||
2257 | static void give_back_ep(struct usb_ep **pep) | ||
2258 | { | ||
2259 | struct usb_ep *ep = *pep; | ||
2260 | if (!ep) | ||
2261 | return; | ||
2262 | ep->driver_data = NULL; | ||
2263 | } | ||
2264 | |||
2265 | static int usbg_bind(struct usb_configuration *c, struct usb_function *f) | ||
2266 | { | ||
2267 | struct f_uas *fu = to_f_uas(f); | ||
2268 | struct usb_gadget *gadget = c->cdev->gadget; | ||
2269 | struct usb_ep *ep; | ||
2270 | int iface; | ||
2271 | |||
2272 | iface = usb_interface_id(c, f); | ||
2273 | if (iface < 0) | ||
2274 | return iface; | ||
2275 | |||
2276 | bot_intf_desc.bInterfaceNumber = iface; | ||
2277 | uasp_intf_desc.bInterfaceNumber = iface; | ||
2278 | fu->iface = iface; | ||
2279 | ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_bi_desc, | ||
2280 | &uasp_bi_ep_comp_desc); | ||
2281 | if (!ep) | ||
2282 | goto ep_fail; | ||
2283 | |||
2284 | ep->driver_data = fu; | ||
2285 | fu->ep_in = ep; | ||
2286 | |||
2287 | ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_bo_desc, | ||
2288 | &uasp_bo_ep_comp_desc); | ||
2289 | if (!ep) | ||
2290 | goto ep_fail; | ||
2291 | ep->driver_data = fu; | ||
2292 | fu->ep_out = ep; | ||
2293 | |||
2294 | ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_status_desc, | ||
2295 | &uasp_status_in_ep_comp_desc); | ||
2296 | if (!ep) | ||
2297 | goto ep_fail; | ||
2298 | ep->driver_data = fu; | ||
2299 | fu->ep_status = ep; | ||
2300 | |||
2301 | ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_cmd_desc, | ||
2302 | &uasp_cmd_comp_desc); | ||
2303 | if (!ep) | ||
2304 | goto ep_fail; | ||
2305 | ep->driver_data = fu; | ||
2306 | fu->ep_cmd = ep; | ||
2307 | |||
2308 | /* Assume endpoint addresses are the same for both speeds */ | ||
2309 | uasp_bi_desc.bEndpointAddress = uasp_ss_bi_desc.bEndpointAddress; | ||
2310 | uasp_bo_desc.bEndpointAddress = uasp_ss_bo_desc.bEndpointAddress; | ||
2311 | uasp_status_desc.bEndpointAddress = | ||
2312 | uasp_ss_status_desc.bEndpointAddress; | ||
2313 | uasp_cmd_desc.bEndpointAddress = uasp_ss_cmd_desc.bEndpointAddress; | ||
2314 | |||
2315 | uasp_fs_bi_desc.bEndpointAddress = uasp_ss_bi_desc.bEndpointAddress; | ||
2316 | uasp_fs_bo_desc.bEndpointAddress = uasp_ss_bo_desc.bEndpointAddress; | ||
2317 | uasp_fs_status_desc.bEndpointAddress = | ||
2318 | uasp_ss_status_desc.bEndpointAddress; | ||
2319 | uasp_fs_cmd_desc.bEndpointAddress = uasp_ss_cmd_desc.bEndpointAddress; | ||
2320 | |||
2321 | return 0; | ||
2322 | ep_fail: | ||
2323 | pr_err("Can't claim all required eps\n"); | ||
2324 | |||
2325 | give_back_ep(&fu->ep_in); | ||
2326 | give_back_ep(&fu->ep_out); | ||
2327 | give_back_ep(&fu->ep_status); | ||
2328 | give_back_ep(&fu->ep_cmd); | ||
2329 | return -ENOTSUPP; | ||
2330 | } | ||
2331 | |||
2332 | static void usbg_unbind(struct usb_configuration *c, struct usb_function *f) | ||
2333 | { | ||
2334 | struct f_uas *fu = to_f_uas(f); | ||
2335 | |||
2336 | kfree(fu); | ||
2337 | } | ||
2338 | |||
2339 | struct guas_setup_wq { | ||
2340 | struct work_struct work; | ||
2341 | struct f_uas *fu; | ||
2342 | unsigned int alt; | ||
2343 | }; | ||
2344 | |||
2345 | static void usbg_delayed_set_alt(struct work_struct *wq) | ||
2346 | { | ||
2347 | struct guas_setup_wq *work = container_of(wq, struct guas_setup_wq, | ||
2348 | work); | ||
2349 | struct f_uas *fu = work->fu; | ||
2350 | int alt = work->alt; | ||
2351 | |||
2352 | kfree(work); | ||
2353 | |||
2354 | if (fu->flags & USBG_IS_BOT) | ||
2355 | bot_cleanup_old_alt(fu); | ||
2356 | if (fu->flags & USBG_IS_UAS) | ||
2357 | uasp_cleanup_old_alt(fu); | ||
2358 | |||
2359 | if (alt == USB_G_ALT_INT_BBB) | ||
2360 | bot_set_alt(fu); | ||
2361 | else if (alt == USB_G_ALT_INT_UAS) | ||
2362 | uasp_set_alt(fu); | ||
2363 | usb_composite_setup_continue(fu->function.config->cdev); | ||
2364 | } | ||
2365 | |||
2366 | static int usbg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | ||
2367 | { | ||
2368 | struct f_uas *fu = to_f_uas(f); | ||
2369 | |||
2370 | if ((alt == USB_G_ALT_INT_BBB) || (alt == USB_G_ALT_INT_UAS)) { | ||
2371 | struct guas_setup_wq *work; | ||
2372 | |||
2373 | work = kmalloc(sizeof(*work), GFP_ATOMIC); | ||
2374 | if (!work) | ||
2375 | return -ENOMEM; | ||
2376 | INIT_WORK(&work->work, usbg_delayed_set_alt); | ||
2377 | work->fu = fu; | ||
2378 | work->alt = alt; | ||
2379 | schedule_work(&work->work); | ||
2380 | return USB_GADGET_DELAYED_STATUS; | ||
2381 | } | ||
2382 | return -EOPNOTSUPP; | ||
2383 | } | ||
2384 | |||
2385 | static void usbg_disable(struct usb_function *f) | ||
2386 | { | ||
2387 | struct f_uas *fu = to_f_uas(f); | ||
2388 | |||
2389 | if (fu->flags & USBG_IS_UAS) | ||
2390 | uasp_cleanup_old_alt(fu); | ||
2391 | else if (fu->flags & USBG_IS_BOT) | ||
2392 | bot_cleanup_old_alt(fu); | ||
2393 | fu->flags = 0; | ||
2394 | } | ||
2395 | |||
2396 | static int usbg_setup(struct usb_function *f, | ||
2397 | const struct usb_ctrlrequest *ctrl) | ||
2398 | { | ||
2399 | struct f_uas *fu = to_f_uas(f); | ||
2400 | |||
2401 | if (!(fu->flags & USBG_IS_BOT)) | ||
2402 | return -EOPNOTSUPP; | ||
2403 | |||
2404 | return usbg_bot_setup(f, ctrl); | ||
2405 | } | ||
2406 | |||
2407 | static int usbg_cfg_bind(struct usb_configuration *c) | ||
2408 | { | ||
2409 | struct f_uas *fu; | ||
2410 | int ret; | ||
2411 | |||
2412 | fu = kzalloc(sizeof(*fu), GFP_KERNEL); | ||
2413 | if (!fu) | ||
2414 | return -ENOMEM; | ||
2415 | fu->function.name = "Target Function"; | ||
2416 | fu->function.descriptors = uasp_fs_function_desc; | ||
2417 | fu->function.hs_descriptors = uasp_hs_function_desc; | ||
2418 | fu->function.ss_descriptors = uasp_ss_function_desc; | ||
2419 | fu->function.bind = usbg_bind; | ||
2420 | fu->function.unbind = usbg_unbind; | ||
2421 | fu->function.set_alt = usbg_set_alt; | ||
2422 | fu->function.setup = usbg_setup; | ||
2423 | fu->function.disable = usbg_disable; | ||
2424 | fu->tpg = the_only_tpg_I_currently_have; | ||
2425 | |||
2426 | ret = usb_add_function(c, &fu->function); | ||
2427 | if (ret) | ||
2428 | goto err; | ||
2429 | |||
2430 | return 0; | ||
2431 | err: | ||
2432 | kfree(fu); | ||
2433 | return ret; | ||
2434 | } | ||
2435 | |||
2436 | static int usb_target_bind(struct usb_composite_dev *cdev) | ||
2437 | { | ||
2438 | int ret; | ||
2439 | |||
2440 | ret = usb_add_config(cdev, &usbg_config_driver, | ||
2441 | usbg_cfg_bind); | ||
2442 | return 0; | ||
2443 | } | ||
2444 | |||
2445 | static struct usb_composite_driver usbg_driver = { | ||
2446 | .name = "g_target", | ||
2447 | .dev = &usbg_device_desc, | ||
2448 | .strings = usbg_strings, | ||
2449 | .max_speed = USB_SPEED_SUPER, | ||
2450 | .unbind = guas_unbind, | ||
2451 | }; | ||
2452 | |||
2453 | static int usbg_attach(struct usbg_tpg *tpg) | ||
2454 | { | ||
2455 | return usb_composite_probe(&usbg_driver, usb_target_bind); | ||
2456 | } | ||
2457 | |||
2458 | static void usbg_detach(struct usbg_tpg *tpg) | ||
2459 | { | ||
2460 | usb_composite_unregister(&usbg_driver); | ||
2461 | } | ||
2462 | |||
2463 | static int __init usb_target_gadget_init(void) | ||
2464 | { | ||
2465 | int ret; | ||
2466 | |||
2467 | ret = usbg_register_configfs(); | ||
2468 | return ret; | ||
2469 | } | ||
2470 | module_init(usb_target_gadget_init); | ||
2471 | |||
2472 | static void __exit usb_target_gadget_exit(void) | ||
2473 | { | ||
2474 | usbg_deregister_configfs(); | ||
2475 | } | ||
2476 | module_exit(usb_target_gadget_exit); | ||
2477 | |||
2478 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); | ||
2479 | MODULE_DESCRIPTION("usb-gadget fabric"); | ||
2480 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/gadget/tcm_usb_gadget.h b/drivers/usb/gadget/tcm_usb_gadget.h new file mode 100644 index 000000000000..bb18999a9a8d --- /dev/null +++ b/drivers/usb/gadget/tcm_usb_gadget.h | |||
@@ -0,0 +1,146 @@ | |||
1 | #ifndef __TARGET_USB_GADGET_H__ | ||
2 | #define __TARGET_USB_GADGET_H__ | ||
3 | |||
4 | #include <linux/kref.h> | ||
5 | /* #include <linux/usb/uas.h> */ | ||
6 | #include <linux/usb/composite.h> | ||
7 | #include <linux/usb/uas.h> | ||
8 | #include <linux/usb/storage.h> | ||
9 | #include <scsi/scsi.h> | ||
10 | #include <target/target_core_base.h> | ||
11 | #include <target/target_core_fabric.h> | ||
12 | |||
13 | #define USBG_NAMELEN 32 | ||
14 | |||
15 | #define fuas_to_gadget(f) (f->function.config->cdev->gadget) | ||
16 | #define UASP_SS_EP_COMP_LOG_STREAMS 4 | ||
17 | #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) | ||
18 | |||
19 | #define USB_G_STR_MANUFACTOR 1 | ||
20 | #define USB_G_STR_PRODUCT 2 | ||
21 | #define USB_G_STR_SERIAL 3 | ||
22 | #define USB_G_STR_CONFIG 4 | ||
23 | #define USB_G_STR_INT_UAS 5 | ||
24 | #define USB_G_STR_INT_BBB 6 | ||
25 | |||
26 | #define USB_G_ALT_INT_BBB 0 | ||
27 | #define USB_G_ALT_INT_UAS 1 | ||
28 | |||
29 | struct usbg_nacl { | ||
30 | /* Binary World Wide unique Port Name for SAS Initiator port */ | ||
31 | u64 iport_wwpn; | ||
32 | /* ASCII formatted WWPN for Sas Initiator port */ | ||
33 | char iport_name[USBG_NAMELEN]; | ||
34 | /* Returned by usbg_make_nodeacl() */ | ||
35 | struct se_node_acl se_node_acl; | ||
36 | }; | ||
37 | |||
38 | struct tcm_usbg_nexus { | ||
39 | struct se_session *tvn_se_sess; | ||
40 | }; | ||
41 | |||
42 | struct usbg_tpg { | ||
43 | struct mutex tpg_mutex; | ||
44 | /* SAS port target portal group tag for TCM */ | ||
45 | u16 tport_tpgt; | ||
46 | /* Pointer back to usbg_tport */ | ||
47 | struct usbg_tport *tport; | ||
48 | struct workqueue_struct *workqueue; | ||
49 | /* Returned by usbg_make_tpg() */ | ||
50 | struct se_portal_group se_tpg; | ||
51 | u32 gadget_connect; | ||
52 | struct tcm_usbg_nexus *tpg_nexus; | ||
53 | atomic_t tpg_port_count; | ||
54 | }; | ||
55 | |||
56 | struct usbg_tport { | ||
57 | /* SCSI protocol the tport is providing */ | ||
58 | u8 tport_proto_id; | ||
59 | /* Binary World Wide unique Port Name for SAS Target port */ | ||
60 | u64 tport_wwpn; | ||
61 | /* ASCII formatted WWPN for SAS Target port */ | ||
62 | char tport_name[USBG_NAMELEN]; | ||
63 | /* Returned by usbg_make_tport() */ | ||
64 | struct se_wwn tport_wwn; | ||
65 | }; | ||
66 | |||
67 | enum uas_state { | ||
68 | UASP_SEND_DATA, | ||
69 | UASP_RECEIVE_DATA, | ||
70 | UASP_SEND_STATUS, | ||
71 | UASP_QUEUE_COMMAND, | ||
72 | }; | ||
73 | |||
74 | #define USBG_MAX_CMD 64 | ||
75 | struct usbg_cmd { | ||
76 | /* common */ | ||
77 | u8 cmd_buf[USBG_MAX_CMD]; | ||
78 | u32 data_len; | ||
79 | struct work_struct work; | ||
80 | int unpacked_lun; | ||
81 | struct se_cmd se_cmd; | ||
82 | void *data_buf; /* used if no sg support available */ | ||
83 | struct f_uas *fu; | ||
84 | struct completion write_complete; | ||
85 | struct kref ref; | ||
86 | |||
87 | /* UAS only */ | ||
88 | u16 tag; | ||
89 | u16 prio_attr; | ||
90 | struct sense_iu sense_iu; | ||
91 | enum uas_state state; | ||
92 | struct uas_stream *stream; | ||
93 | |||
94 | /* BOT only */ | ||
95 | __le32 bot_tag; | ||
96 | unsigned int csw_code; | ||
97 | unsigned is_read:1; | ||
98 | |||
99 | }; | ||
100 | |||
101 | struct uas_stream { | ||
102 | struct usb_request *req_in; | ||
103 | struct usb_request *req_out; | ||
104 | struct usb_request *req_status; | ||
105 | }; | ||
106 | |||
107 | struct usbg_cdb { | ||
108 | struct usb_request *req; | ||
109 | void *buf; | ||
110 | }; | ||
111 | |||
112 | struct bot_status { | ||
113 | struct usb_request *req; | ||
114 | struct bulk_cs_wrap csw; | ||
115 | }; | ||
116 | |||
117 | struct f_uas { | ||
118 | struct usbg_tpg *tpg; | ||
119 | struct usb_function function; | ||
120 | u16 iface; | ||
121 | |||
122 | u32 flags; | ||
123 | #define USBG_ENABLED (1 << 0) | ||
124 | #define USBG_IS_UAS (1 << 1) | ||
125 | #define USBG_USE_STREAMS (1 << 2) | ||
126 | #define USBG_IS_BOT (1 << 3) | ||
127 | #define USBG_BOT_CMD_PEND (1 << 4) | ||
128 | |||
129 | struct usbg_cdb cmd; | ||
130 | struct usb_ep *ep_in; | ||
131 | struct usb_ep *ep_out; | ||
132 | |||
133 | /* UAS */ | ||
134 | struct usb_ep *ep_status; | ||
135 | struct usb_ep *ep_cmd; | ||
136 | struct uas_stream stream[UASP_SS_EP_COMP_NUM_STREAMS]; | ||
137 | |||
138 | /* BOT */ | ||
139 | struct bot_status bot_status; | ||
140 | struct usb_request *bot_req_in; | ||
141 | struct usb_request *bot_req_out; | ||
142 | }; | ||
143 | |||
144 | extern struct usbg_tpg *the_only_tpg_I_currently_have; | ||
145 | |||
146 | #endif | ||
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 29c854bbca44..47cf48b51c9d 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -744,10 +744,11 @@ static struct device_type gadget_type = { | |||
744 | }; | 744 | }; |
745 | 745 | ||
746 | /** | 746 | /** |
747 | * gether_setup - initialize one ethernet-over-usb link | 747 | * gether_setup_name - initialize one ethernet-over-usb link |
748 | * @g: gadget to associated with these links | 748 | * @g: gadget to associated with these links |
749 | * @ethaddr: NULL, or a buffer in which the ethernet address of the | 749 | * @ethaddr: NULL, or a buffer in which the ethernet address of the |
750 | * host side of the link is recorded | 750 | * host side of the link is recorded |
751 | * @netname: name for network device (for example, "usb") | ||
751 | * Context: may sleep | 752 | * Context: may sleep |
752 | * | 753 | * |
753 | * This sets up the single network link that may be exported by a | 754 | * This sets up the single network link that may be exported by a |
@@ -756,7 +757,8 @@ static struct device_type gadget_type = { | |||
756 | * | 757 | * |
757 | * Returns negative errno, or zero on success | 758 | * Returns negative errno, or zero on success |
758 | */ | 759 | */ |
759 | int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | 760 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
761 | const char *netname) | ||
760 | { | 762 | { |
761 | struct eth_dev *dev; | 763 | struct eth_dev *dev; |
762 | struct net_device *net; | 764 | struct net_device *net; |
@@ -780,7 +782,7 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | |||
780 | 782 | ||
781 | /* network device setup */ | 783 | /* network device setup */ |
782 | dev->net = net; | 784 | dev->net = net; |
783 | strcpy(net->name, "usb%d"); | 785 | snprintf(net->name, sizeof(net->name), "%s%%d", netname); |
784 | 786 | ||
785 | if (get_ether_addr(dev_addr, net->dev_addr)) | 787 | if (get_ether_addr(dev_addr, net->dev_addr)) |
786 | dev_warn(&g->dev, | 788 | dev_warn(&g->dev, |
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 8012357e98aa..6f4a1623d854 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h | |||
@@ -69,9 +69,28 @@ struct gether { | |||
69 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ | 69 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ |
70 | |USB_CDC_PACKET_TYPE_DIRECTED) | 70 | |USB_CDC_PACKET_TYPE_DIRECTED) |
71 | 71 | ||
72 | /* variant of gether_setup that allows customizing network device name */ | ||
73 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | ||
74 | const char *netname); | ||
72 | 75 | ||
73 | /* netdev setup/teardown as directed by the gadget driver */ | 76 | /* netdev setup/teardown as directed by the gadget driver */ |
74 | int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]); | 77 | /* gether_setup - initialize one ethernet-over-usb link |
78 | * @g: gadget to associated with these links | ||
79 | * @ethaddr: NULL, or a buffer in which the ethernet address of the | ||
80 | * host side of the link is recorded | ||
81 | * Context: may sleep | ||
82 | * | ||
83 | * This sets up the single network link that may be exported by a | ||
84 | * gadget driver using this framework. The link layer addresses are | ||
85 | * set up using module parameters. | ||
86 | * | ||
87 | * Returns negative errno, or zero on success | ||
88 | */ | ||
89 | static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) | ||
90 | { | ||
91 | return gether_setup_name(g, ethaddr, "usb"); | ||
92 | } | ||
93 | |||
75 | void gether_cleanup(void); | 94 | void gether_cleanup(void); |
76 | 95 | ||
77 | /* connect/disconnect is handled by individual functions */ | 96 | /* connect/disconnect is handled by individual functions */ |
@@ -99,16 +118,37 @@ int eem_bind_config(struct usb_configuration *c); | |||
99 | 118 | ||
100 | #ifdef USB_ETH_RNDIS | 119 | #ifdef USB_ETH_RNDIS |
101 | 120 | ||
102 | int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); | 121 | int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
122 | u32 vendorID, const char *manufacturer); | ||
103 | 123 | ||
104 | #else | 124 | #else |
105 | 125 | ||
106 | static inline int | 126 | static inline int |
107 | rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) | 127 | rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], |
128 | u32 vendorID, const char *manufacturer) | ||
108 | { | 129 | { |
109 | return 0; | 130 | return 0; |
110 | } | 131 | } |
111 | 132 | ||
112 | #endif | 133 | #endif |
113 | 134 | ||
135 | /** | ||
136 | * rndis_bind_config - add RNDIS network link to a configuration | ||
137 | * @c: the configuration to support the network link | ||
138 | * @ethaddr: a buffer in which the ethernet address of the host side | ||
139 | * side of the link was recorded | ||
140 | * Context: single threaded during gadget setup | ||
141 | * | ||
142 | * Returns zero on success, else negative errno. | ||
143 | * | ||
144 | * Caller must have called @gether_setup(). Caller is also responsible | ||
145 | * for calling @gether_cleanup() before module unload. | ||
146 | */ | ||
147 | static inline int rndis_bind_config(struct usb_configuration *c, | ||
148 | u8 ethaddr[ETH_ALEN]) | ||
149 | { | ||
150 | return rndis_bind_config_vendor(c, ethaddr, 0, NULL); | ||
151 | } | ||
152 | |||
153 | |||
114 | #endif /* __U_ETHER_H */ | 154 | #endif /* __U_ETHER_H */ |
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 71ecae743cd2..15a42c8c1943 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -1022,7 +1022,7 @@ static const struct tty_operations gs_tty_ops = { | |||
1022 | 1022 | ||
1023 | static struct tty_driver *gs_tty_driver; | 1023 | static struct tty_driver *gs_tty_driver; |
1024 | 1024 | ||
1025 | static int __init | 1025 | static int |
1026 | gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) | 1026 | gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) |
1027 | { | 1027 | { |
1028 | struct gs_port *port; | 1028 | struct gs_port *port; |
@@ -1068,7 +1068,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) | |||
1068 | * | 1068 | * |
1069 | * Returns negative errno or zero. | 1069 | * Returns negative errno or zero. |
1070 | */ | 1070 | */ |
1071 | int __init gserial_setup(struct usb_gadget *g, unsigned count) | 1071 | int gserial_setup(struct usb_gadget *g, unsigned count) |
1072 | { | 1072 | { |
1073 | unsigned i; | 1073 | unsigned i; |
1074 | struct usb_cdc_line_coding coding; | 1074 | struct usb_cdc_line_coding coding; |
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 2fa9865babed..e5e44f8cde9a 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -263,8 +263,8 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) | |||
263 | 263 | ||
264 | if (udc_is_newstyle(udc)) { | 264 | if (udc_is_newstyle(udc)) { |
265 | udc->driver->disconnect(udc->gadget); | 265 | udc->driver->disconnect(udc->gadget); |
266 | udc->driver->unbind(udc->gadget); | ||
267 | usb_gadget_disconnect(udc->gadget); | 266 | usb_gadget_disconnect(udc->gadget); |
267 | udc->driver->unbind(udc->gadget); | ||
268 | usb_gadget_udc_stop(udc->gadget, udc->driver); | 268 | usb_gadget_udc_stop(udc->gadget, udc->driver); |
269 | } else { | 269 | } else { |
270 | usb_gadget_stop(udc->gadget, udc->driver); | 270 | usb_gadget_stop(udc->gadget, udc->driver); |
@@ -415,9 +415,9 @@ static ssize_t usb_udc_softconn_store(struct device *dev, | |||
415 | usb_gadget_udc_start(udc->gadget, udc->driver); | 415 | usb_gadget_udc_start(udc->gadget, udc->driver); |
416 | usb_gadget_connect(udc->gadget); | 416 | usb_gadget_connect(udc->gadget); |
417 | } else if (sysfs_streq(buf, "disconnect")) { | 417 | } else if (sysfs_streq(buf, "disconnect")) { |
418 | usb_gadget_disconnect(udc->gadget); | ||
418 | if (udc_is_newstyle(udc)) | 419 | if (udc_is_newstyle(udc)) |
419 | usb_gadget_udc_stop(udc->gadget, udc->driver); | 420 | usb_gadget_udc_stop(udc->gadget, udc->driver); |
420 | usb_gadget_disconnect(udc->gadget); | ||
421 | } else { | 421 | } else { |
422 | dev_err(dev, "unsupported command '%s'\n", buf); | 422 | dev_err(dev, "unsupported command '%s'\n", buf); |
423 | return -EINVAL; | 423 | return -EINVAL; |
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h index bc78c606c12b..ca4e03a1c73a 100644 --- a/drivers/usb/gadget/uvc.h +++ b/drivers/usb/gadget/uvc.h | |||
@@ -28,7 +28,7 @@ | |||
28 | 28 | ||
29 | struct uvc_request_data | 29 | struct uvc_request_data |
30 | { | 30 | { |
31 | unsigned int length; | 31 | __s32 length; |
32 | __u8 data[60]; | 32 | __u8 data[60]; |
33 | }; | 33 | }; |
34 | 34 | ||
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c index f6e083b50191..54d7ca559cb2 100644 --- a/drivers/usb/gadget/uvc_v4l2.c +++ b/drivers/usb/gadget/uvc_v4l2.c | |||
@@ -39,7 +39,7 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data) | |||
39 | if (data->length < 0) | 39 | if (data->length < 0) |
40 | return usb_ep_set_halt(cdev->gadget->ep0); | 40 | return usb_ep_set_halt(cdev->gadget->ep0); |
41 | 41 | ||
42 | req->length = min(uvc->event_length, data->length); | 42 | req->length = min_t(unsigned int, uvc->event_length, data->length); |
43 | req->zero = data->length < uvc->event_length; | 43 | req->zero = data->length < uvc->event_length; |
44 | req->dma = DMA_ADDR_INVALID; | 44 | req->dma = DMA_ADDR_INVALID; |
45 | 45 | ||
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c index 31d34832907e..12ad516ada77 100644 --- a/drivers/usb/gadget/zero.c +++ b/drivers/usb/gadget/zero.c | |||
@@ -72,7 +72,7 @@ | |||
72 | 72 | ||
73 | static const char longname[] = "Gadget Zero"; | 73 | static const char longname[] = "Gadget Zero"; |
74 | 74 | ||
75 | unsigned buflen = 4096; | 75 | unsigned buflen = 4096; /* only used for bulk endpoints */ |
76 | module_param(buflen, uint, 0); | 76 | module_param(buflen, uint, 0); |
77 | 77 | ||
78 | /* | 78 | /* |
@@ -170,14 +170,17 @@ static struct usb_gadget_strings *dev_strings[] = { | |||
170 | 170 | ||
171 | /*-------------------------------------------------------------------------*/ | 171 | /*-------------------------------------------------------------------------*/ |
172 | 172 | ||
173 | struct usb_request *alloc_ep_req(struct usb_ep *ep) | 173 | struct usb_request *alloc_ep_req(struct usb_ep *ep, int len) |
174 | { | 174 | { |
175 | struct usb_request *req; | 175 | struct usb_request *req; |
176 | 176 | ||
177 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | 177 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); |
178 | if (req) { | 178 | if (req) { |
179 | req->length = buflen; | 179 | if (len) |
180 | req->buf = kmalloc(buflen, GFP_ATOMIC); | 180 | req->length = len; |
181 | else | ||
182 | req->length = buflen; | ||
183 | req->buf = kmalloc(req->length, GFP_ATOMIC); | ||
181 | if (!req->buf) { | 184 | if (!req->buf) { |
182 | usb_ep_free_request(ep, req); | 185 | usb_ep_free_request(ep, req); |
183 | req = NULL; | 186 | req = NULL; |
@@ -206,10 +209,15 @@ static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) | |||
206 | } | 209 | } |
207 | 210 | ||
208 | void disable_endpoints(struct usb_composite_dev *cdev, | 211 | void disable_endpoints(struct usb_composite_dev *cdev, |
209 | struct usb_ep *in, struct usb_ep *out) | 212 | struct usb_ep *in, struct usb_ep *out, |
213 | struct usb_ep *iso_in, struct usb_ep *iso_out) | ||
210 | { | 214 | { |
211 | disable_ep(cdev, in); | 215 | disable_ep(cdev, in); |
212 | disable_ep(cdev, out); | 216 | disable_ep(cdev, out); |
217 | if (iso_in) | ||
218 | disable_ep(cdev, iso_in); | ||
219 | if (iso_out) | ||
220 | disable_ep(cdev, iso_out); | ||
213 | } | 221 | } |
214 | 222 | ||
215 | /*-------------------------------------------------------------------------*/ | 223 | /*-------------------------------------------------------------------------*/ |
@@ -311,7 +319,6 @@ static int __init zero_bind(struct usb_composite_dev *cdev) | |||
311 | device_desc.bcdDevice = cpu_to_le16(0x9999); | 319 | device_desc.bcdDevice = cpu_to_le16(0x9999); |
312 | } | 320 | } |
313 | 321 | ||
314 | |||
315 | INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); | 322 | INFO(cdev, "%s, version: " DRIVER_VERSION "\n", longname); |
316 | 323 | ||
317 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", | 324 | snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", |