Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-gadget/next' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

* 'for-gadget/next' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (24 commits)
usb: dwc3: gadget: add support for SG lists
usb: dwc3: gadget: don't force 'LST' always
usb: dwc3: gadget: don't return anything on prepare trbs
usb: dwc3: gadget: re-factor dwc3_prepare_trbs()
usb: gadget: introduce support for sg lists
usb: renesas: pipe: convert a long if into a XOR operation
usb: gadget: remove useless depends on Kconfig
usb: gadget: s3c-hsudc: remove the_controller global
usb: gadget: s3c-hsudc: use release_mem_region instead of release_resource
usb: gadget: s3c-hsudc: Add regulator handling
usb: gadget: s3c-hsudc: use udc_start and udc_stop functions
usb: gadget: s3c-hsudc: move device registration to probe
usb: gadget: s3c-hsudc: add missing otg_put_transceiver in probe
usb: gadget: s3c-hsudc: add __devinit to probe function
usb: gadget: s3c-hsudc: move platform_data struct to global header
USB: EHCI: Add Marvell Host Controller driver
USB: OTG: add Marvell usb OTG driver support
usb: gadget: mv_udc: drop ARCH dependency
usb: gadget: mv_udc: fix bug in ep_dequeue
usb: gadget: enlarge maxburst bit width.
...

+1919 -288
+1
arch/arm/mach-s3c2416/mach-smdk2416.c
··· 50 50 #include <plat/nand.h> 51 51 #include <plat/sdhci.h> 52 52 #include <plat/udc.h> 53 + #include <linux/platform_data/s3c-hsudc.h> 53 54 54 55 #include <plat/regs-fb-v4.h> 55 56 #include <plat/fb.h>
+1
arch/arm/plat-samsung/devs.c
··· 29 29 #include <linux/mtd/partitions.h> 30 30 #include <linux/mmc/host.h> 31 31 #include <linux/ioport.h> 32 + #include <linux/platform_data/s3c-hsudc.h> 32 33 33 34 #include <asm/irq.h> 34 35 #include <asm/pmu.h>
+1 -14
arch/arm/plat-samsung/include/plat/udc.h
··· 37 37 38 38 extern void __init s3c24xx_udc_set_platdata(struct s3c2410_udc_mach_info *); 39 39 40 - /** 41 - * s3c24xx_hsudc_platdata - Platform data for USB High-Speed gadget controller. 42 - * @epnum: Number of endpoints to be instantiated by the controller driver. 43 - * @gpio_init: Platform specific USB related GPIO initialization. 44 - * @gpio_uninit: Platform specific USB releted GPIO uninitialzation. 45 - * 46 - * Representation of platform data for the S3C24XX USB 2.0 High Speed gadget 47 - * controllers. 48 - */ 49 - struct s3c24xx_hsudc_platdata { 50 - unsigned int epnum; 51 - void (*gpio_init)(void); 52 - void (*gpio_uninit)(void); 53 - }; 40 + struct s3c24xx_hsudc_platdata; 54 41 55 42 extern void __init s3c24xx_hsudc_set_platdata(struct s3c24xx_hsudc_platdata *pd); 56 43
+164 -83
drivers/usb/dwc3/gadget.c
··· 65 65 return; 66 66 } 67 67 68 + if (req->request.num_sgs) { 69 + int mapped; 70 + 71 + mapped = dma_map_sg(dwc->dev, req->request.sg, 72 + req->request.num_sgs, 73 + req->direction ? DMA_TO_DEVICE 74 + : DMA_FROM_DEVICE); 75 + if (mapped < 0) { 76 + dev_err(dwc->dev, "failed to map SGs\n"); 77 + return; 78 + } 79 + 80 + req->request.num_mapped_sgs = mapped; 81 + return; 82 + } 83 + 68 84 if (req->request.dma == DMA_ADDR_INVALID) { 69 85 req->request.dma = dma_map_single(dwc->dev, req->request.buf, 70 86 req->request.length, req->direction ··· 95 79 96 80 if (req->request.length == 0) { 97 81 req->request.dma = DMA_ADDR_INVALID; 82 + return; 83 + } 84 + 85 + if (req->request.num_mapped_sgs) { 86 + req->request.dma = DMA_ADDR_INVALID; 87 + dma_unmap_sg(dwc->dev, req->request.sg, 88 + req->request.num_sgs, 89 + req->direction ? DMA_TO_DEVICE 90 + : DMA_FROM_DEVICE); 91 + 92 + req->request.num_mapped_sgs = 0; 98 93 return; 99 94 } 100 95 ··· 124 97 struct dwc3 *dwc = dep->dwc; 125 98 126 99 if (req->queued) { 127 - dep->busy_slot++; 100 + if (req->request.num_mapped_sgs) 101 + dep->busy_slot += req->request.num_mapped_sgs; 102 + else 103 + dep->busy_slot++; 104 + 128 105 /* 129 106 * Skip LINK TRB. We can't use req->trb and check for 130 107 * DWC3_TRBCTL_LINK_TRB because it points the TRB we just ··· 139 108 dep->busy_slot++; 140 109 } 141 110 list_del(&req->list); 111 + req->trb = NULL; 142 112 143 113 if (req->request.status == -EINPROGRESS) 144 114 req->request.status = status; ··· 576 544 kfree(req); 577 545 } 578 546 547 + /** 548 + * dwc3_prepare_one_trb - setup one TRB from one request 549 + * @dep: endpoint for which this request is prepared 550 + * @req: dwc3_request pointer 551 + */ 552 + static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 553 + struct dwc3_request *req, dma_addr_t dma, 554 + unsigned length, unsigned last, unsigned chain) 555 + { 556 + struct dwc3 *dwc = dep->dwc; 557 + struct dwc3_trb_hw *trb_hw; 558 + struct dwc3_trb trb; 559 + 560 + unsigned int cur_slot; 561 + 562 + dev_vdbg(dwc->dev, "%s: req %p dma %08llx length %d%s%s\n", 563 + dep->name, req, (unsigned long long) dma, 564 + length, last ? " last" : "", 565 + chain ? " chain" : ""); 566 + 567 + trb_hw = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; 568 + cur_slot = dep->free_slot; 569 + dep->free_slot++; 570 + 571 + /* Skip the LINK-TRB on ISOC */ 572 + if (((cur_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 573 + usb_endpoint_xfer_isoc(dep->desc)) 574 + return; 575 + 576 + memset(&trb, 0, sizeof(trb)); 577 + if (!req->trb) { 578 + dwc3_gadget_move_request_queued(req); 579 + req->trb = trb_hw; 580 + req->trb_dma = dwc3_trb_dma_offset(dep, trb_hw); 581 + } 582 + 583 + if (usb_endpoint_xfer_isoc(dep->desc)) { 584 + trb.isp_imi = true; 585 + trb.csp = true; 586 + } else { 587 + trb.chn = chain; 588 + trb.lst = last; 589 + } 590 + 591 + if (usb_endpoint_xfer_bulk(dep->desc) && dep->stream_capable) 592 + trb.sid_sofn = req->request.stream_id; 593 + 594 + switch (usb_endpoint_type(dep->desc)) { 595 + case USB_ENDPOINT_XFER_CONTROL: 596 + trb.trbctl = DWC3_TRBCTL_CONTROL_SETUP; 597 + break; 598 + 599 + case USB_ENDPOINT_XFER_ISOC: 600 + trb.trbctl = DWC3_TRBCTL_ISOCHRONOUS_FIRST; 601 + 602 + /* IOC every DWC3_TRB_NUM / 4 so we can refill */ 603 + if (!(cur_slot % (DWC3_TRB_NUM / 4))) 604 + trb.ioc = last; 605 + break; 606 + 607 + case USB_ENDPOINT_XFER_BULK: 608 + case USB_ENDPOINT_XFER_INT: 609 + trb.trbctl = DWC3_TRBCTL_NORMAL; 610 + break; 611 + default: 612 + /* 613 + * This is only possible with faulty memory because we 614 + * checked it already :) 615 + */ 616 + BUG(); 617 + } 618 + 619 + trb.length = length; 620 + trb.bplh = dma; 621 + trb.hwo = true; 622 + 623 + dwc3_trb_to_hw(&trb, trb_hw); 624 + } 625 + 579 626 /* 580 627 * dwc3_prepare_trbs - setup TRBs from requests 581 628 * @dep: endpoint for which requests are being prepared ··· 664 553 * transfers. The functions returns once there are not more TRBs available or 665 554 * it run out of requests. 666 555 */ 667 - static struct dwc3_request *dwc3_prepare_trbs(struct dwc3_ep *dep, 668 - bool starting) 556 + static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting) 669 557 { 670 - struct dwc3_request *req, *n, *ret = NULL; 671 - struct dwc3_trb_hw *trb_hw; 672 - struct dwc3_trb trb; 558 + struct dwc3_request *req, *n; 673 559 u32 trbs_left; 560 + unsigned int last_one = 0; 674 561 675 562 BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); 676 563 677 564 /* the first request must not be queued */ 678 565 trbs_left = (dep->busy_slot - dep->free_slot) & DWC3_TRB_MASK; 566 + 679 567 /* 680 568 * if busy & slot are equal than it is either full or empty. If we are 681 569 * starting to proceed requests then we are empty. Otherwise we ar ··· 682 572 */ 683 573 if (!trbs_left) { 684 574 if (!starting) 685 - return NULL; 575 + return; 686 576 trbs_left = DWC3_TRB_NUM; 687 577 /* 688 578 * In case we start from scratch, we queue the ISOC requests ··· 706 596 707 597 /* The last TRB is a link TRB, not used for xfer */ 708 598 if ((trbs_left <= 1) && usb_endpoint_xfer_isoc(dep->desc)) 709 - return NULL; 599 + return; 710 600 711 601 list_for_each_entry_safe(req, n, &dep->request_list, list) { 712 - unsigned int last_one = 0; 713 - unsigned int cur_slot; 602 + unsigned length; 603 + dma_addr_t dma; 714 604 715 - trb_hw = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; 716 - cur_slot = dep->free_slot; 717 - dep->free_slot++; 605 + if (req->request.num_mapped_sgs > 0) { 606 + struct usb_request *request = &req->request; 607 + struct scatterlist *sg = request->sg; 608 + struct scatterlist *s; 609 + int i; 718 610 719 - /* Skip the LINK-TRB on ISOC */ 720 - if (((cur_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 721 - usb_endpoint_xfer_isoc(dep->desc)) 722 - continue; 611 + for_each_sg(sg, s, request->num_mapped_sgs, i) { 612 + unsigned chain = true; 723 613 724 - dwc3_gadget_move_request_queued(req); 725 - memset(&trb, 0, sizeof(trb)); 726 - trbs_left--; 614 + length = sg_dma_len(s); 615 + dma = sg_dma_address(s); 727 616 728 - /* Is our TRB pool empty? */ 729 - if (!trbs_left) 730 - last_one = 1; 731 - /* Is this the last request? */ 732 - if (list_empty(&dep->request_list)) 733 - last_one = 1; 617 + if (i == (request->num_mapped_sgs - 1) 618 + || sg_is_last(s)) { 619 + last_one = true; 620 + chain = false; 621 + } 734 622 735 - /* 736 - * FIXME we shouldn't need to set LST bit always but we are 737 - * facing some weird problem with the Hardware where it doesn't 738 - * complete even though it has been previously started. 739 - * 740 - * While we're debugging the problem, as a workaround to 741 - * multiple TRBs handling, use only one TRB at a time. 742 - */ 743 - last_one = 1; 623 + trbs_left--; 624 + if (!trbs_left) 625 + last_one = true; 744 626 745 - req->trb = trb_hw; 746 - if (!ret) 747 - ret = req; 627 + if (last_one) 628 + chain = false; 748 629 749 - trb.bplh = req->request.dma; 630 + dwc3_prepare_one_trb(dep, req, dma, length, 631 + last_one, chain); 750 632 751 - if (usb_endpoint_xfer_isoc(dep->desc)) { 752 - trb.isp_imi = true; 753 - trb.csp = true; 633 + if (last_one) 634 + break; 635 + } 754 636 } else { 755 - trb.lst = last_one; 637 + dma = req->request.dma; 638 + length = req->request.length; 639 + trbs_left--; 640 + 641 + if (!trbs_left) 642 + last_one = 1; 643 + 644 + /* Is this the last request? */ 645 + if (list_is_last(&req->list, &dep->request_list)) 646 + last_one = 1; 647 + 648 + dwc3_prepare_one_trb(dep, req, dma, length, 649 + last_one, false); 650 + 651 + if (last_one) 652 + break; 756 653 } 757 - 758 - if (usb_endpoint_xfer_bulk(dep->desc) && dep->stream_capable) 759 - trb.sid_sofn = req->request.stream_id; 760 - 761 - switch (usb_endpoint_type(dep->desc)) { 762 - case USB_ENDPOINT_XFER_CONTROL: 763 - trb.trbctl = DWC3_TRBCTL_CONTROL_SETUP; 764 - break; 765 - 766 - case USB_ENDPOINT_XFER_ISOC: 767 - trb.trbctl = DWC3_TRBCTL_ISOCHRONOUS_FIRST; 768 - 769 - /* IOC every DWC3_TRB_NUM / 4 so we can refill */ 770 - if (!(cur_slot % (DWC3_TRB_NUM / 4))) 771 - trb.ioc = last_one; 772 - break; 773 - 774 - case USB_ENDPOINT_XFER_BULK: 775 - case USB_ENDPOINT_XFER_INT: 776 - trb.trbctl = DWC3_TRBCTL_NORMAL; 777 - break; 778 - default: 779 - /* 780 - * This is only possible with faulty memory because we 781 - * checked it already :) 782 - */ 783 - BUG(); 784 - } 785 - 786 - trb.length = req->request.length; 787 - trb.hwo = true; 788 - 789 - dwc3_trb_to_hw(&trb, trb_hw); 790 - req->trb_dma = dwc3_trb_dma_offset(dep, trb_hw); 791 - 792 - if (last_one) 793 - break; 794 654 } 795 - 796 - return ret; 797 655 } 798 656 799 657 static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param, ··· 790 712 /* req points to the first request which will be sent */ 791 713 req = next_request(&dep->req_queued); 792 714 } else { 715 + dwc3_prepare_trbs(dep, start_new); 716 + 793 717 /* 794 718 * req points to the first request where HWO changed 795 719 * from 0 to 1 796 720 */ 797 - req = dwc3_prepare_trbs(dep, start_new); 721 + req = next_request(&dep->req_queued); 798 722 } 799 723 if (!req) { 800 724 dep->flags |= DWC3_EP_PENDING_REQUEST; ··· 2173 2093 dwc->gadget.max_speed = USB_SPEED_SUPER; 2174 2094 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2175 2095 dwc->gadget.dev.parent = dwc->dev; 2096 + dwc->gadget.sg_supported = true; 2176 2097 2177 2098 dma_set_coherent_mask(&dwc->gadget.dev, dwc->dev->coherent_dma_mask); 2178 2099
+5 -9
drivers/usb/gadget/Kconfig
··· 125 125 # 126 126 choice 127 127 prompt "USB Peripheral Controller" 128 - depends on USB_GADGET 129 128 help 130 129 A USB device uses a controller to talk to its host. 131 130 Systems should have only one such upstream link. ··· 309 310 310 311 This driver has been tested on S3C2416 and S3C2450 processors. 311 312 312 - config USB_PXA_U2O 313 - tristate "PXA9xx Processor USB2.0 controller" 314 - depends on ARCH_MMP 313 + config USB_MV_UDC 314 + tristate "Marvell USB2.0 Device Controller" 315 315 select USB_GADGET_DUALSPEED 316 316 help 317 - PXA9xx Processor series include a high speed USB2.0 device 318 - controller, which support high speed and full speed USB peripheral. 317 + Marvell Socs (including PXA and MMP series) include a high speed 318 + USB2.0 OTG controller, which can be configured as high speed or 319 + full speed USB peripheral. 319 320 320 321 # 321 322 # Controllers available in both integrated and discrete versions ··· 531 532 # Selected by UDC drivers that support high-speed operation. 532 533 config USB_GADGET_DUALSPEED 533 534 bool 534 - depends on USB_GADGET 535 535 536 536 # Selected by UDC drivers that support super-speed opperation 537 537 config USB_GADGET_SUPERSPEED 538 538 bool 539 - depends on USB_GADGET 540 539 depends on USB_GADGET_DUALSPEED 541 540 542 541 # ··· 542 545 # 543 546 choice 544 547 tristate "USB Gadget Drivers" 545 - depends on USB_GADGET 546 548 default USB_ETH 547 549 help 548 550 A Linux "Gadget Driver" talks to the USB Peripheral Controller
+1 -1
drivers/usb/gadget/Makefile
··· 27 27 obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o 28 28 obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o 29 29 obj-$(CONFIG_USB_EG20T) += pch_udc.o 30 - obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o 30 + obj-$(CONFIG_USB_MV_UDC) += mv_udc.o 31 31 mv_udc-y := mv_udc_core.o 32 32 obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o 33 33 obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
+1 -1
drivers/usb/gadget/mv_udc.h
··· 180 180 181 181 struct mv_cap_regs __iomem *cap_regs; 182 182 struct mv_op_regs __iomem *op_regs; 183 - unsigned int phy_regs; 183 + void __iomem *phy_regs; 184 184 unsigned int max_eps; 185 185 struct mv_dqh *ep_dqh; 186 186 size_t ep_dqh_size;
+75 -121
drivers/usb/gadget/mv_udc_core.c
··· 276 276 277 277 static int queue_dtd(struct mv_ep *ep, struct mv_req *req) 278 278 { 279 - u32 tmp, epstatus, bit_pos, direction; 280 279 struct mv_udc *udc; 281 280 struct mv_dqh *dqh; 281 + u32 bit_pos, direction; 282 + u32 usbcmd, epstatus; 282 283 unsigned int loops; 283 - int readsafe, retval = 0; 284 + int retval = 0; 284 285 285 286 udc = ep->udc; 286 287 direction = ep_dir(ep); ··· 294 293 lastreq = list_entry(ep->queue.prev, struct mv_req, queue); 295 294 lastreq->tail->dtd_next = 296 295 req->head->td_dma & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 297 - if (readl(&udc->op_regs->epprime) & bit_pos) { 298 - loops = LOOPS(PRIME_TIMEOUT); 299 - while (readl(&udc->op_regs->epprime) & bit_pos) { 300 - if (loops == 0) { 301 - retval = -ETIME; 302 - goto done; 303 - } 304 - udelay(LOOPS_USEC); 305 - loops--; 306 - } 307 - if (readl(&udc->op_regs->epstatus) & bit_pos) 308 - goto done; 309 - } 310 - readsafe = 0; 296 + 297 + wmb(); 298 + 299 + if (readl(&udc->op_regs->epprime) & bit_pos) 300 + goto done; 301 + 311 302 loops = LOOPS(READSAFE_TIMEOUT); 312 - while (readsafe == 0) { 313 - if (loops == 0) { 314 - retval = -ETIME; 315 - goto done; 316 - } 303 + while (1) { 317 304 /* start with setting the semaphores */ 318 - tmp = readl(&udc->op_regs->usbcmd); 319 - tmp |= USBCMD_ATDTW_TRIPWIRE_SET; 320 - writel(tmp, &udc->op_regs->usbcmd); 305 + usbcmd = readl(&udc->op_regs->usbcmd); 306 + usbcmd |= USBCMD_ATDTW_TRIPWIRE_SET; 307 + writel(usbcmd, &udc->op_regs->usbcmd); 321 308 322 309 /* read the endpoint status */ 323 310 epstatus = readl(&udc->op_regs->epstatus) & bit_pos; ··· 318 329 * primed. 319 330 */ 320 331 if (readl(&udc->op_regs->usbcmd) 321 - & USBCMD_ATDTW_TRIPWIRE_SET) { 322 - readsafe = 1; 323 - } 332 + & USBCMD_ATDTW_TRIPWIRE_SET) 333 + break; 334 + 324 335 loops--; 336 + if (loops == 0) { 337 + dev_err(&udc->dev->dev, 338 + "Timeout for ATDTW_TRIPWIRE...\n"); 339 + retval = -ETIME; 340 + goto done; 341 + } 325 342 udelay(LOOPS_USEC); 326 343 } 327 344 328 345 /* Clear the semaphore */ 329 - tmp = readl(&udc->op_regs->usbcmd); 330 - tmp &= USBCMD_ATDTW_TRIPWIRE_CLEAR; 331 - writel(tmp, &udc->op_regs->usbcmd); 346 + usbcmd = readl(&udc->op_regs->usbcmd); 347 + usbcmd &= USBCMD_ATDTW_TRIPWIRE_CLEAR; 348 + writel(usbcmd, &udc->op_regs->usbcmd); 332 349 333 - /* If endpoint is not active, we activate it now. */ 334 - if (!epstatus) { 335 - if (direction == EP_DIR_IN) { 336 - struct mv_dtd *curr_dtd = dma_to_virt( 337 - &udc->dev->dev, dqh->curr_dtd_ptr); 338 - 339 - loops = LOOPS(DTD_TIMEOUT); 340 - while (curr_dtd->size_ioc_sts 341 - & DTD_STATUS_ACTIVE) { 342 - if (loops == 0) { 343 - retval = -ETIME; 344 - goto done; 345 - } 346 - loops--; 347 - udelay(LOOPS_USEC); 348 - } 349 - } 350 - /* No other transfers on the queue */ 351 - 352 - /* Write dQH next pointer and terminate bit to 0 */ 353 - dqh->next_dtd_ptr = req->head->td_dma 354 - & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 355 - dqh->size_ioc_int_sts = 0; 356 - 357 - /* 358 - * Ensure that updates to the QH will 359 - * occur before priming. 360 - */ 361 - wmb(); 362 - 363 - /* Prime the Endpoint */ 364 - writel(bit_pos, &udc->op_regs->epprime); 365 - } 366 - } else { 367 - /* Write dQH next pointer and terminate bit to 0 */ 368 - dqh->next_dtd_ptr = req->head->td_dma 369 - & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 370 - dqh->size_ioc_int_sts = 0; 371 - 372 - /* Ensure that updates to the QH will occur before priming. */ 373 - wmb(); 374 - 375 - /* Prime the Endpoint */ 376 - writel(bit_pos, &udc->op_regs->epprime); 377 - 378 - if (direction == EP_DIR_IN) { 379 - /* FIXME add status check after prime the IN ep */ 380 - int prime_again; 381 - u32 curr_dtd_ptr = dqh->curr_dtd_ptr; 382 - 383 - loops = LOOPS(DTD_TIMEOUT); 384 - prime_again = 0; 385 - while ((curr_dtd_ptr != req->head->td_dma)) { 386 - curr_dtd_ptr = dqh->curr_dtd_ptr; 387 - if (loops == 0) { 388 - dev_err(&udc->dev->dev, 389 - "failed to prime %s\n", 390 - ep->name); 391 - retval = -ETIME; 392 - goto done; 393 - } 394 - loops--; 395 - udelay(LOOPS_USEC); 396 - 397 - if (loops == (LOOPS(DTD_TIMEOUT) >> 2)) { 398 - if (prime_again) 399 - goto done; 400 - dev_info(&udc->dev->dev, 401 - "prime again\n"); 402 - writel(bit_pos, 403 - &udc->op_regs->epprime); 404 - prime_again = 1; 405 - } 406 - } 407 - } 350 + if (epstatus) 351 + goto done; 408 352 } 353 + 354 + /* Write dQH next pointer and terminate bit to 0 */ 355 + dqh->next_dtd_ptr = req->head->td_dma 356 + & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 357 + 358 + /* clear active and halt bit, in case set from a previous error */ 359 + dqh->size_ioc_int_sts &= ~(DTD_STATUS_ACTIVE | DTD_STATUS_HALTED); 360 + 361 + /* Ensure that updates to the QH will occure before priming. */ 362 + wmb(); 363 + 364 + /* Prime the Endpoint */ 365 + writel(bit_pos, &udc->op_regs->epprime); 366 + 409 367 done: 410 368 return retval; 411 369 } 370 + 412 371 413 372 static struct mv_dtd *build_dtd(struct mv_req *req, unsigned *length, 414 373 dma_addr_t *dma, int *is_last) ··· 778 841 return 0; 779 842 } 780 843 844 + static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req) 845 + { 846 + struct mv_dqh *dqh = ep->dqh; 847 + u32 bit_pos; 848 + 849 + /* Write dQH next pointer and terminate bit to 0 */ 850 + dqh->next_dtd_ptr = req->head->td_dma 851 + & EP_QUEUE_HEAD_NEXT_POINTER_MASK; 852 + 853 + /* clear active and halt bit, in case set from a previous error */ 854 + dqh->size_ioc_int_sts &= ~(DTD_STATUS_ACTIVE | DTD_STATUS_HALTED); 855 + 856 + /* Ensure that updates to the QH will occure before priming. */ 857 + wmb(); 858 + 859 + bit_pos = 1 << (((ep_dir(ep) == EP_DIR_OUT) ? 0 : 16) + ep->ep_num); 860 + 861 + /* Prime the Endpoint */ 862 + writel(bit_pos, &ep->udc->op_regs->epprime); 863 + } 864 + 781 865 /* dequeues (cancels, unlinks) an I/O request from an endpoint */ 782 866 static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 783 867 { ··· 841 883 842 884 /* The request isn't the last request in this ep queue */ 843 885 if (req->queue.next != &ep->queue) { 844 - struct mv_dqh *qh; 845 886 struct mv_req *next_req; 846 887 847 - qh = ep->dqh; 848 - next_req = list_entry(req->queue.next, struct mv_req, 849 - queue); 888 + next_req = list_entry(req->queue.next, 889 + struct mv_req, queue); 850 890 851 891 /* Point the QH to the first TD of next request */ 852 - writel((u32) next_req->head, &qh->curr_dtd_ptr); 892 + mv_prime_ep(ep, next_req); 853 893 } else { 854 894 struct mv_dqh *qh; 855 895 ··· 1152 1196 1153 1197 udc = container_of(gadget, struct mv_udc, gadget); 1154 1198 1155 - retval = readl(udc->op_regs->frindex) & USB_FRINDEX_MASKS; 1199 + retval = readl(&udc->op_regs->frindex) & USB_FRINDEX_MASKS; 1156 1200 1157 1201 return retval; 1158 1202 } ··· 2128 2172 2129 2173 if (udc->cap_regs) 2130 2174 iounmap(udc->cap_regs); 2131 - udc->cap_regs = NULL; 2132 2175 2133 2176 if (udc->phy_regs) 2134 - iounmap((void *)udc->phy_regs); 2135 - udc->phy_regs = 0; 2177 + iounmap(udc->phy_regs); 2136 2178 2137 2179 if (udc->status_req) { 2138 2180 kfree(udc->status_req->req.buf); ··· 2215 2261 goto err_iounmap_capreg; 2216 2262 } 2217 2263 2218 - udc->phy_regs = (unsigned int)ioremap(r->start, resource_size(r)); 2219 - if (udc->phy_regs == 0) { 2264 + udc->phy_regs = ioremap(r->start, resource_size(r)); 2265 + if (udc->phy_regs == NULL) { 2220 2266 dev_err(&dev->dev, "failed to map phy I/O memory\n"); 2221 2267 retval = -EBUSY; 2222 2268 goto err_iounmap_capreg; ··· 2227 2273 if (retval) 2228 2274 goto err_iounmap_phyreg; 2229 2275 2230 - udc->op_regs = (struct mv_op_regs __iomem *)((u32)udc->cap_regs 2276 + udc->op_regs = 2277 + (struct mv_op_regs __iomem *)((unsigned long)udc->cap_regs 2231 2278 + (readl(&udc->cap_regs->caplength_hciversion) 2232 2279 & CAPLENGTH_MASK)); 2233 2280 udc->max_eps = readl(&udc->cap_regs->dccparams) & DCCPARAMS_DEN_MASK; ··· 2388 2433 err_disable_clock: 2389 2434 mv_udc_disable_internal(udc); 2390 2435 err_iounmap_phyreg: 2391 - iounmap((void *)udc->phy_regs); 2436 + iounmap(udc->phy_regs); 2392 2437 err_iounmap_capreg: 2393 2438 iounmap(udc->cap_regs); 2394 2439 err_put_clk: ··· 2479 2524 .shutdown = mv_udc_shutdown, 2480 2525 .driver = { 2481 2526 .owner = THIS_MODULE, 2482 - .name = "pxa-u2o", 2527 + .name = "mv-udc", 2483 2528 #ifdef CONFIG_PM 2484 2529 .pm = &mv_udc_pm_ops, 2485 2530 #endif ··· 2487 2532 }; 2488 2533 2489 2534 module_platform_driver(udc_driver); 2490 - 2535 + MODULE_ALIAS("platform:mv-udc"); 2491 2536 MODULE_DESCRIPTION(DRIVER_DESC); 2492 2537 MODULE_AUTHOR("Chao Xie <chao.xie@marvell.com>"); 2493 2538 MODULE_VERSION(DRIVER_VERSION); 2494 2539 MODULE_LICENSE("GPL"); 2495 - MODULE_ALIAS("platform:pxa-u2o");
+66 -51
drivers/usb/gadget/s3c-hsudc.c
··· 28 28 #include <linux/usb/gadget.h> 29 29 #include <linux/usb/otg.h> 30 30 #include <linux/prefetch.h> 31 + #include <linux/platform_data/s3c-hsudc.h> 32 + #include <linux/regulator/consumer.h> 31 33 32 34 #include <mach/regs-s3c2443-clock.h> 33 - #include <plat/udc.h> 34 35 35 36 #define S3C_HSUDC_REG(x) (x) 36 37 ··· 88 87 #define DATA_STATE_XMIT (1) 89 88 #define DATA_STATE_RECV (2) 90 89 90 + static const char * const s3c_hsudc_supply_names[] = { 91 + "vdda", /* analog phy supply, 3.3V */ 92 + "vddi", /* digital phy supply, 1.2V */ 93 + "vddosc", /* oscillator supply, 1.8V - 3.3V */ 94 + }; 95 + 91 96 /** 92 97 * struct s3c_hsudc_ep - Endpoint representation used by driver. 93 98 * @ep: USB gadget layer representation of device endpoint. ··· 146 139 struct device *dev; 147 140 struct s3c24xx_hsudc_platdata *pd; 148 141 struct otg_transceiver *transceiver; 142 + struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsudc_supply_names)]; 149 143 spinlock_t lock; 150 144 void __iomem *regs; 151 145 struct resource *mem_rsrc; ··· 161 153 #define ep_index(_ep) ((_ep)->bEndpointAddress & \ 162 154 USB_ENDPOINT_NUMBER_MASK) 163 155 164 - static struct s3c_hsudc *the_controller; 165 156 static const char driver_name[] = "s3c-udc"; 166 157 static const char ep0name[] = "ep0-control"; 167 158 ··· 289 282 * All the endpoints are stopped and any pending transfer requests if any on 290 283 * the endpoint are terminated. 291 284 */ 292 - static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc, 293 - struct usb_gadget_driver *driver) 285 + static void s3c_hsudc_stop_activity(struct s3c_hsudc *hsudc) 294 286 { 295 287 struct s3c_hsudc_ep *hsep; 296 288 int epnum; ··· 301 295 hsep->stopped = 1; 302 296 s3c_hsudc_nuke_ep(hsep, -ESHUTDOWN); 303 297 } 304 - 305 - spin_unlock(&hsudc->lock); 306 - driver->disconnect(&hsudc->gadget); 307 - spin_lock(&hsudc->lock); 308 298 } 309 299 310 300 /** ··· 1137 1135 return IRQ_HANDLED; 1138 1136 } 1139 1137 1140 - static int s3c_hsudc_start(struct usb_gadget_driver *driver, 1141 - int (*bind)(struct usb_gadget *)) 1138 + static int s3c_hsudc_start(struct usb_gadget *gadget, 1139 + struct usb_gadget_driver *driver) 1142 1140 { 1143 - struct s3c_hsudc *hsudc = the_controller; 1141 + struct s3c_hsudc *hsudc = to_hsudc(gadget); 1144 1142 int ret; 1145 1143 1146 1144 if (!driver 1147 1145 || driver->max_speed < USB_SPEED_FULL 1148 - || !bind 1149 - || !driver->unbind || !driver->disconnect || !driver->setup) 1146 + || !driver->setup) 1150 1147 return -EINVAL; 1151 1148 1152 1149 if (!hsudc) ··· 1156 1155 1157 1156 hsudc->driver = driver; 1158 1157 hsudc->gadget.dev.driver = &driver->driver; 1159 - hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1160 - ret = device_add(&hsudc->gadget.dev); 1161 - if (ret) { 1162 - dev_err(hsudc->dev, "failed to probe gadget device"); 1163 - return ret; 1164 - } 1165 1158 1166 - ret = bind(&hsudc->gadget); 1167 - if (ret) { 1168 - dev_err(hsudc->dev, "%s: bind failed\n", hsudc->gadget.name); 1169 - device_del(&hsudc->gadget.dev); 1170 - 1171 - hsudc->driver = NULL; 1172 - hsudc->gadget.dev.driver = NULL; 1173 - return ret; 1159 + ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies), 1160 + hsudc->supplies); 1161 + if (ret != 0) { 1162 + dev_err(hsudc->dev, "failed to enable supplies: %d\n", ret); 1163 + goto err_supplies; 1174 1164 } 1175 1165 1176 1166 /* connect to bus through transceiver */ ··· 1170 1178 if (ret) { 1171 1179 dev_err(hsudc->dev, "%s: can't bind to transceiver\n", 1172 1180 hsudc->gadget.name); 1173 - driver->unbind(&hsudc->gadget); 1174 - 1175 - device_del(&hsudc->gadget.dev); 1176 - 1177 - hsudc->driver = NULL; 1178 - hsudc->gadget.dev.driver = NULL; 1179 - return ret; 1181 + goto err_otg; 1180 1182 } 1181 1183 } 1182 1184 ··· 1183 1197 hsudc->pd->gpio_init(); 1184 1198 1185 1199 return 0; 1200 + err_otg: 1201 + regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1202 + err_supplies: 1203 + hsudc->driver = NULL; 1204 + hsudc->gadget.dev.driver = NULL; 1205 + return ret; 1186 1206 } 1187 1207 1188 - static int s3c_hsudc_stop(struct usb_gadget_driver *driver) 1208 + static int s3c_hsudc_stop(struct usb_gadget *gadget, 1209 + struct usb_gadget_driver *driver) 1189 1210 { 1190 - struct s3c_hsudc *hsudc = the_controller; 1211 + struct s3c_hsudc *hsudc = to_hsudc(gadget); 1191 1212 unsigned long flags; 1192 1213 1193 1214 if (!hsudc) 1194 1215 return -ENODEV; 1195 1216 1196 - if (!driver || driver != hsudc->driver || !driver->unbind) 1217 + if (!driver || driver != hsudc->driver) 1197 1218 return -EINVAL; 1198 1219 1199 1220 spin_lock_irqsave(&hsudc->lock, flags); 1200 - hsudc->driver = 0; 1221 + hsudc->driver = NULL; 1222 + hsudc->gadget.dev.driver = NULL; 1223 + hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1201 1224 s3c_hsudc_uninit_phy(); 1202 1225 if (hsudc->pd->gpio_uninit) 1203 1226 hsudc->pd->gpio_uninit(); 1204 - s3c_hsudc_stop_activity(hsudc, driver); 1227 + s3c_hsudc_stop_activity(hsudc); 1205 1228 spin_unlock_irqrestore(&hsudc->lock, flags); 1206 1229 1207 1230 if (hsudc->transceiver) 1208 1231 (void) otg_set_peripheral(hsudc->transceiver, NULL); 1209 1232 1210 - driver->unbind(&hsudc->gadget); 1211 - device_del(&hsudc->gadget.dev); 1212 1233 disable_irq(hsudc->irq); 1234 + 1235 + regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1213 1236 1214 1237 dev_info(hsudc->dev, "unregistered gadget driver '%s'\n", 1215 1238 driver->driver.name); ··· 1237 1242 1238 1243 static int s3c_hsudc_vbus_draw(struct usb_gadget *gadget, unsigned mA) 1239 1244 { 1240 - struct s3c_hsudc *hsudc = the_controller; 1245 + struct s3c_hsudc *hsudc = to_hsudc(gadget); 1241 1246 1242 1247 if (!hsudc) 1243 1248 return -ENODEV; ··· 1250 1255 1251 1256 static struct usb_gadget_ops s3c_hsudc_gadget_ops = { 1252 1257 .get_frame = s3c_hsudc_gadget_getframe, 1253 - .start = s3c_hsudc_start, 1254 - .stop = s3c_hsudc_stop, 1258 + .udc_start = s3c_hsudc_start, 1259 + .udc_stop = s3c_hsudc_stop, 1255 1260 .vbus_draw = s3c_hsudc_vbus_draw, 1256 1261 }; 1257 1262 1258 - static int s3c_hsudc_probe(struct platform_device *pdev) 1263 + static int __devinit s3c_hsudc_probe(struct platform_device *pdev) 1259 1264 { 1260 1265 struct device *dev = &pdev->dev; 1261 1266 struct resource *res; 1262 1267 struct s3c_hsudc *hsudc; 1263 1268 struct s3c24xx_hsudc_platdata *pd = pdev->dev.platform_data; 1264 - int ret; 1269 + int ret, i; 1265 1270 1266 1271 hsudc = kzalloc(sizeof(struct s3c_hsudc) + 1267 1272 sizeof(struct s3c_hsudc_ep) * pd->epnum, ··· 1271 1276 return -ENOMEM; 1272 1277 } 1273 1278 1274 - the_controller = hsudc; 1275 1279 platform_set_drvdata(pdev, dev); 1276 1280 hsudc->dev = dev; 1277 1281 hsudc->pd = pdev->dev.platform_data; 1278 1282 1279 1283 hsudc->transceiver = otg_get_transceiver(); 1284 + 1285 + for (i = 0; i < ARRAY_SIZE(hsudc->supplies); i++) 1286 + hsudc->supplies[i].supply = s3c_hsudc_supply_names[i]; 1287 + 1288 + ret = regulator_bulk_get(dev, ARRAY_SIZE(hsudc->supplies), 1289 + hsudc->supplies); 1290 + if (ret != 0) { 1291 + dev_err(dev, "failed to request supplies: %d\n", ret); 1292 + goto err_supplies; 1293 + } 1280 1294 1281 1295 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1282 1296 if (!res) { ··· 1311 1307 1312 1308 spin_lock_init(&hsudc->lock); 1313 1309 1314 - device_initialize(&hsudc->gadget.dev); 1315 1310 dev_set_name(&hsudc->gadget.dev, "gadget"); 1316 1311 1317 1312 hsudc->gadget.max_speed = USB_SPEED_HIGH; ··· 1322 1319 1323 1320 hsudc->gadget.is_otg = 0; 1324 1321 hsudc->gadget.is_a_peripheral = 0; 1322 + hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1325 1323 1326 1324 s3c_hsudc_setup_ep(hsudc); 1327 1325 ··· 1352 1348 disable_irq(hsudc->irq); 1353 1349 local_irq_enable(); 1354 1350 1351 + ret = device_register(&hsudc->gadget.dev); 1352 + if (ret) { 1353 + put_device(&hsudc->gadget.dev); 1354 + goto err_add_device; 1355 + } 1356 + 1355 1357 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); 1356 1358 if (ret) 1357 1359 goto err_add_udc; 1358 1360 1359 1361 return 0; 1360 1362 err_add_udc: 1363 + device_unregister(&hsudc->gadget.dev); 1364 + err_add_device: 1361 1365 clk_disable(hsudc->uclk); 1362 1366 clk_put(hsudc->uclk); 1363 1367 err_clk: ··· 1374 1362 iounmap(hsudc->regs); 1375 1363 1376 1364 err_remap: 1377 - release_resource(hsudc->mem_rsrc); 1378 - kfree(hsudc->mem_rsrc); 1379 - 1365 + release_mem_region(res->start, resource_size(res)); 1380 1366 err_res: 1367 + if (hsudc->transceiver) 1368 + otg_put_transceiver(hsudc->transceiver); 1369 + 1370 + regulator_bulk_free(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1371 + err_supplies: 1381 1372 kfree(hsudc); 1382 1373 return ret; 1383 1374 }
+9
drivers/usb/host/Kconfig
··· 194 194 help 195 195 Enable support for the S5P SOC's on-chip EHCI controller. 196 196 197 + config USB_EHCI_MV 198 + bool "EHCI support for Marvell on-chip controller" 199 + depends on USB_EHCI_HCD 200 + select USB_EHCI_ROOT_HUB_TT 201 + ---help--- 202 + Enables support for Marvell (including PXA and MMP series) on-chip 203 + USB SPH and OTG controller. SPH is a single port host, and it can 204 + only be EHCI host. OTG is controller that can switch to host mode. 205 + 197 206 config USB_W90X900_EHCI 198 207 bool "W90X900(W90P910) EHCI support" 199 208 depends on USB_EHCI_HCD && ARCH_W90X900
+5
drivers/usb/host/ehci-hcd.c
··· 1371 1371 #define PLATFORM_DRIVER ehci_xls_driver 1372 1372 #endif 1373 1373 1374 + #ifdef CONFIG_USB_EHCI_MV 1375 + #include "ehci-mv.c" 1376 + #define PLATFORM_DRIVER ehci_mv_driver 1377 + #endif 1378 + 1374 1379 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1375 1380 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ 1376 1381 !defined(XILINX_OF_PLATFORM_DRIVER)
+391
drivers/usb/host/ehci-mv.c
··· 1 + /* 2 + * Copyright (C) 2011 Marvell International Ltd. All rights reserved. 3 + * Author: Chao Xie <chao.xie@marvell.com> 4 + * Neil Zhang <zhangwm@marvell.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License as published by the 8 + * Free Software Foundation; either version 2 of the License, or (at your 9 + * option) any later version. 10 + */ 11 + 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/clk.h> 16 + #include <linux/usb/otg.h> 17 + #include <linux/platform_data/mv_usb.h> 18 + 19 + #define CAPLENGTH_MASK (0xff) 20 + 21 + struct ehci_hcd_mv { 22 + struct usb_hcd *hcd; 23 + 24 + /* Which mode does this ehci running OTG/Host ? */ 25 + int mode; 26 + 27 + void __iomem *phy_regs; 28 + void __iomem *cap_regs; 29 + void __iomem *op_regs; 30 + 31 + struct otg_transceiver *otg; 32 + 33 + struct mv_usb_platform_data *pdata; 34 + 35 + /* clock source and total clock number */ 36 + unsigned int clknum; 37 + struct clk *clk[0]; 38 + }; 39 + 40 + static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) 41 + { 42 + unsigned int i; 43 + 44 + for (i = 0; i < ehci_mv->clknum; i++) 45 + clk_enable(ehci_mv->clk[i]); 46 + } 47 + 48 + static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) 49 + { 50 + unsigned int i; 51 + 52 + for (i = 0; i < ehci_mv->clknum; i++) 53 + clk_disable(ehci_mv->clk[i]); 54 + } 55 + 56 + static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) 57 + { 58 + int retval; 59 + 60 + ehci_clock_enable(ehci_mv); 61 + if (ehci_mv->pdata->phy_init) { 62 + retval = ehci_mv->pdata->phy_init(ehci_mv->phy_regs); 63 + if (retval) 64 + return retval; 65 + } 66 + 67 + return 0; 68 + } 69 + 70 + static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv) 71 + { 72 + if (ehci_mv->pdata->phy_deinit) 73 + ehci_mv->pdata->phy_deinit(ehci_mv->phy_regs); 74 + ehci_clock_disable(ehci_mv); 75 + } 76 + 77 + static int mv_ehci_reset(struct usb_hcd *hcd) 78 + { 79 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 80 + struct device *dev = hcd->self.controller; 81 + struct ehci_hcd_mv *ehci_mv = dev_get_drvdata(dev); 82 + int retval; 83 + 84 + if (ehci_mv == NULL) { 85 + dev_err(dev, "Can not find private ehci data\n"); 86 + return -ENODEV; 87 + } 88 + 89 + /* 90 + * data structure init 91 + */ 92 + retval = ehci_init(hcd); 93 + if (retval) { 94 + dev_err(dev, "ehci_init failed %d\n", retval); 95 + return retval; 96 + } 97 + 98 + hcd->has_tt = 1; 99 + ehci->sbrn = 0x20; 100 + 101 + retval = ehci_reset(ehci); 102 + if (retval) { 103 + dev_err(dev, "ehci_reset failed %d\n", retval); 104 + return retval; 105 + } 106 + 107 + return 0; 108 + } 109 + 110 + static const struct hc_driver mv_ehci_hc_driver = { 111 + .description = hcd_name, 112 + .product_desc = "Marvell EHCI", 113 + .hcd_priv_size = sizeof(struct ehci_hcd), 114 + 115 + /* 116 + * generic hardware linkage 117 + */ 118 + .irq = ehci_irq, 119 + .flags = HCD_MEMORY | HCD_USB2, 120 + 121 + /* 122 + * basic lifecycle operations 123 + */ 124 + .reset = mv_ehci_reset, 125 + .start = ehci_run, 126 + .stop = ehci_stop, 127 + .shutdown = ehci_shutdown, 128 + 129 + /* 130 + * managing i/o requests and associated device resources 131 + */ 132 + .urb_enqueue = ehci_urb_enqueue, 133 + .urb_dequeue = ehci_urb_dequeue, 134 + .endpoint_disable = ehci_endpoint_disable, 135 + .endpoint_reset = ehci_endpoint_reset, 136 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 137 + 138 + /* 139 + * scheduling support 140 + */ 141 + .get_frame_number = ehci_get_frame, 142 + 143 + /* 144 + * root hub support 145 + */ 146 + .hub_status_data = ehci_hub_status_data, 147 + .hub_control = ehci_hub_control, 148 + .bus_suspend = ehci_bus_suspend, 149 + .bus_resume = ehci_bus_resume, 150 + }; 151 + 152 + static int mv_ehci_probe(struct platform_device *pdev) 153 + { 154 + struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 155 + struct usb_hcd *hcd; 156 + struct ehci_hcd *ehci; 157 + struct ehci_hcd_mv *ehci_mv; 158 + struct resource *r; 159 + int clk_i, retval = -ENODEV; 160 + u32 offset; 161 + size_t size; 162 + 163 + if (!pdata) { 164 + dev_err(&pdev->dev, "missing platform_data\n"); 165 + return -ENODEV; 166 + } 167 + 168 + if (usb_disabled()) 169 + return -ENODEV; 170 + 171 + hcd = usb_create_hcd(&mv_ehci_hc_driver, &pdev->dev, "mv ehci"); 172 + if (!hcd) 173 + return -ENOMEM; 174 + 175 + size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; 176 + ehci_mv = kzalloc(size, GFP_KERNEL); 177 + if (ehci_mv == NULL) { 178 + dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); 179 + retval = -ENOMEM; 180 + goto err_put_hcd; 181 + } 182 + 183 + platform_set_drvdata(pdev, ehci_mv); 184 + ehci_mv->pdata = pdata; 185 + ehci_mv->hcd = hcd; 186 + 187 + ehci_mv->clknum = pdata->clknum; 188 + for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { 189 + ehci_mv->clk[clk_i] = 190 + clk_get(&pdev->dev, pdata->clkname[clk_i]); 191 + if (IS_ERR(ehci_mv->clk[clk_i])) { 192 + dev_err(&pdev->dev, "error get clck \"%s\"\n", 193 + pdata->clkname[clk_i]); 194 + retval = PTR_ERR(ehci_mv->clk[clk_i]); 195 + goto err_put_clk; 196 + } 197 + } 198 + 199 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs"); 200 + if (r == NULL) { 201 + dev_err(&pdev->dev, "no phy I/O memory resource defined\n"); 202 + retval = -ENODEV; 203 + goto err_put_clk; 204 + } 205 + 206 + ehci_mv->phy_regs = ioremap(r->start, resource_size(r)); 207 + if (ehci_mv->phy_regs == 0) { 208 + dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 209 + retval = -EFAULT; 210 + goto err_put_clk; 211 + } 212 + 213 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "capregs"); 214 + if (!r) { 215 + dev_err(&pdev->dev, "no I/O memory resource defined\n"); 216 + retval = -ENODEV; 217 + goto err_iounmap_phyreg; 218 + } 219 + 220 + ehci_mv->cap_regs = ioremap(r->start, resource_size(r)); 221 + if (ehci_mv->cap_regs == NULL) { 222 + dev_err(&pdev->dev, "failed to map I/O memory\n"); 223 + retval = -EFAULT; 224 + goto err_iounmap_phyreg; 225 + } 226 + 227 + retval = mv_ehci_enable(ehci_mv); 228 + if (retval) { 229 + dev_err(&pdev->dev, "init phy error %d\n", retval); 230 + goto err_iounmap_capreg; 231 + } 232 + 233 + offset = readl(ehci_mv->cap_regs) & CAPLENGTH_MASK; 234 + ehci_mv->op_regs = 235 + (void __iomem *) ((unsigned long) ehci_mv->cap_regs + offset); 236 + 237 + hcd->rsrc_start = r->start; 238 + hcd->rsrc_len = r->end - r->start + 1; 239 + hcd->regs = ehci_mv->op_regs; 240 + 241 + hcd->irq = platform_get_irq(pdev, 0); 242 + if (!hcd->irq) { 243 + dev_err(&pdev->dev, "Cannot get irq."); 244 + retval = -ENODEV; 245 + goto err_disable_clk; 246 + } 247 + 248 + ehci = hcd_to_ehci(hcd); 249 + ehci->caps = (struct ehci_caps *) ehci_mv->cap_regs; 250 + ehci->regs = (struct ehci_regs *) ehci_mv->op_regs; 251 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 252 + 253 + ehci_mv->mode = pdata->mode; 254 + if (ehci_mv->mode == MV_USB_MODE_OTG) { 255 + #ifdef CONFIG_USB_OTG_UTILS 256 + ehci_mv->otg = otg_get_transceiver(); 257 + if (!ehci_mv->otg) { 258 + dev_err(&pdev->dev, 259 + "unable to find transceiver\n"); 260 + retval = -ENODEV; 261 + goto err_disable_clk; 262 + } 263 + 264 + retval = otg_set_host(ehci_mv->otg, &hcd->self); 265 + if (retval < 0) { 266 + dev_err(&pdev->dev, 267 + "unable to register with transceiver\n"); 268 + retval = -ENODEV; 269 + goto err_put_transceiver; 270 + } 271 + /* otg will enable clock before use as host */ 272 + mv_ehci_disable(ehci_mv); 273 + #else 274 + dev_info(&pdev->dev, "MV_USB_MODE_OTG " 275 + "must have CONFIG_USB_OTG_UTILS enabled\n"); 276 + goto err_disable_clk; 277 + #endif 278 + } else { 279 + if (pdata->set_vbus) 280 + pdata->set_vbus(1); 281 + 282 + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); 283 + if (retval) { 284 + dev_err(&pdev->dev, 285 + "failed to add hcd with err %d\n", retval); 286 + goto err_set_vbus; 287 + } 288 + } 289 + 290 + if (pdata->private_init) 291 + pdata->private_init(ehci_mv->op_regs, ehci_mv->phy_regs); 292 + 293 + dev_info(&pdev->dev, 294 + "successful find EHCI device with regs 0x%p irq %d" 295 + " working in %s mode\n", hcd->regs, hcd->irq, 296 + ehci_mv->mode == MV_USB_MODE_OTG ? "OTG" : "Host"); 297 + 298 + return 0; 299 + 300 + err_set_vbus: 301 + if (pdata->set_vbus) 302 + pdata->set_vbus(0); 303 + #ifdef CONFIG_USB_OTG_UTILS 304 + err_put_transceiver: 305 + if (ehci_mv->otg) 306 + otg_put_transceiver(ehci_mv->otg); 307 + #endif 308 + err_disable_clk: 309 + mv_ehci_disable(ehci_mv); 310 + err_iounmap_capreg: 311 + iounmap(ehci_mv->cap_regs); 312 + err_iounmap_phyreg: 313 + iounmap(ehci_mv->phy_regs); 314 + err_put_clk: 315 + for (clk_i--; clk_i >= 0; clk_i--) 316 + clk_put(ehci_mv->clk[clk_i]); 317 + platform_set_drvdata(pdev, NULL); 318 + kfree(ehci_mv); 319 + err_put_hcd: 320 + usb_put_hcd(hcd); 321 + 322 + return retval; 323 + } 324 + 325 + static int mv_ehci_remove(struct platform_device *pdev) 326 + { 327 + struct ehci_hcd_mv *ehci_mv = platform_get_drvdata(pdev); 328 + struct usb_hcd *hcd = ehci_mv->hcd; 329 + int clk_i; 330 + 331 + if (hcd->rh_registered) 332 + usb_remove_hcd(hcd); 333 + 334 + if (ehci_mv->otg) { 335 + otg_set_host(ehci_mv->otg, NULL); 336 + otg_put_transceiver(ehci_mv->otg); 337 + } 338 + 339 + if (ehci_mv->mode == MV_USB_MODE_HOST) { 340 + if (ehci_mv->pdata->set_vbus) 341 + ehci_mv->pdata->set_vbus(0); 342 + 343 + mv_ehci_disable(ehci_mv); 344 + } 345 + 346 + iounmap(ehci_mv->cap_regs); 347 + iounmap(ehci_mv->phy_regs); 348 + 349 + for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) 350 + clk_put(ehci_mv->clk[clk_i]); 351 + 352 + platform_set_drvdata(pdev, NULL); 353 + 354 + kfree(ehci_mv); 355 + usb_put_hcd(hcd); 356 + 357 + return 0; 358 + } 359 + 360 + MODULE_ALIAS("mv-ehci"); 361 + 362 + static const struct platform_device_id ehci_id_table[] = { 363 + {"pxa-u2oehci", PXA_U2OEHCI}, 364 + {"pxa-sph", PXA_SPH}, 365 + {"mmp3-hsic", MMP3_HSIC}, 366 + {"mmp3-fsic", MMP3_FSIC}, 367 + {}, 368 + }; 369 + 370 + static void mv_ehci_shutdown(struct platform_device *pdev) 371 + { 372 + struct ehci_hcd_mv *ehci_mv = platform_get_drvdata(pdev); 373 + struct usb_hcd *hcd = ehci_mv->hcd; 374 + 375 + if (!hcd->rh_registered) 376 + return; 377 + 378 + if (hcd->driver->shutdown) 379 + hcd->driver->shutdown(hcd); 380 + } 381 + 382 + static struct platform_driver ehci_mv_driver = { 383 + .probe = mv_ehci_probe, 384 + .remove = mv_ehci_remove, 385 + .shutdown = mv_ehci_shutdown, 386 + .driver = { 387 + .name = "mv-ehci", 388 + .bus = &platform_bus_type, 389 + }, 390 + .id_table = ehci_id_table, 391 + };
+12
drivers/usb/otg/Kconfig
··· 130 130 help 131 131 Enable this to support Freescale USB OTG transceiver. 132 132 133 + config USB_MV_OTG 134 + tristate "Marvell USB OTG support" 135 + depends on USB_MV_UDC 136 + select USB_OTG 137 + select USB_OTG_UTILS 138 + help 139 + Say Y here if you want to build Marvell USB OTG transciever 140 + driver in kernel (including PXA and MMP series). This driver 141 + implements role switch between EHCI host driver and gadget driver. 142 + 143 + To compile this driver as a module, choose M here. 144 + 133 145 endif # USB || OTG
+1
drivers/usb/otg/Makefile
··· 21 21 obj-$(CONFIG_AB8500_USB) += ab8500-usb.o 22 22 fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o 23 23 obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o 24 + obj-$(CONFIG_USB_MV_OTG) += mv_otg.o
+957
drivers/usb/otg/mv_otg.c
··· 1 + /* 2 + * Copyright (C) 2011 Marvell International Ltd. All rights reserved. 3 + * Author: Chao Xie <chao.xie@marvell.com> 4 + * Neil Zhang <zhangwm@marvell.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License as published by the 8 + * Free Software Foundation; either version 2 of the License, or (at your 9 + * option) any later version. 10 + */ 11 + 12 + #include <linux/module.h> 13 + #include <linux/kernel.h> 14 + #include <linux/init.h> 15 + #include <linux/io.h> 16 + #include <linux/uaccess.h> 17 + #include <linux/device.h> 18 + #include <linux/proc_fs.h> 19 + #include <linux/clk.h> 20 + #include <linux/workqueue.h> 21 + #include <linux/platform_device.h> 22 + 23 + #include <linux/usb.h> 24 + #include <linux/usb/ch9.h> 25 + #include <linux/usb/otg.h> 26 + #include <linux/usb/gadget.h> 27 + #include <linux/usb/hcd.h> 28 + #include <linux/platform_data/mv_usb.h> 29 + 30 + #include "mv_otg.h" 31 + 32 + #define DRIVER_DESC "Marvell USB OTG transceiver driver" 33 + #define DRIVER_VERSION "Jan 20, 2010" 34 + 35 + MODULE_DESCRIPTION(DRIVER_DESC); 36 + MODULE_VERSION(DRIVER_VERSION); 37 + MODULE_LICENSE("GPL"); 38 + 39 + static const char driver_name[] = "mv-otg"; 40 + 41 + static char *state_string[] = { 42 + "undefined", 43 + "b_idle", 44 + "b_srp_init", 45 + "b_peripheral", 46 + "b_wait_acon", 47 + "b_host", 48 + "a_idle", 49 + "a_wait_vrise", 50 + "a_wait_bcon", 51 + "a_host", 52 + "a_suspend", 53 + "a_peripheral", 54 + "a_wait_vfall", 55 + "a_vbus_err" 56 + }; 57 + 58 + static int mv_otg_set_vbus(struct otg_transceiver *otg, bool on) 59 + { 60 + struct mv_otg *mvotg = container_of(otg, struct mv_otg, otg); 61 + if (mvotg->pdata->set_vbus == NULL) 62 + return -ENODEV; 63 + 64 + return mvotg->pdata->set_vbus(on); 65 + } 66 + 67 + static int mv_otg_set_host(struct otg_transceiver *otg, 68 + struct usb_bus *host) 69 + { 70 + otg->host = host; 71 + 72 + return 0; 73 + } 74 + 75 + static int mv_otg_set_peripheral(struct otg_transceiver *otg, 76 + struct usb_gadget *gadget) 77 + { 78 + otg->gadget = gadget; 79 + 80 + return 0; 81 + } 82 + 83 + static void mv_otg_run_state_machine(struct mv_otg *mvotg, 84 + unsigned long delay) 85 + { 86 + dev_dbg(&mvotg->pdev->dev, "transceiver is updated\n"); 87 + if (!mvotg->qwork) 88 + return; 89 + 90 + queue_delayed_work(mvotg->qwork, &mvotg->work, delay); 91 + } 92 + 93 + static void mv_otg_timer_await_bcon(unsigned long data) 94 + { 95 + struct mv_otg *mvotg = (struct mv_otg *) data; 96 + 97 + mvotg->otg_ctrl.a_wait_bcon_timeout = 1; 98 + 99 + dev_info(&mvotg->pdev->dev, "B Device No Response!\n"); 100 + 101 + if (spin_trylock(&mvotg->wq_lock)) { 102 + mv_otg_run_state_machine(mvotg, 0); 103 + spin_unlock(&mvotg->wq_lock); 104 + } 105 + } 106 + 107 + static int mv_otg_cancel_timer(struct mv_otg *mvotg, unsigned int id) 108 + { 109 + struct timer_list *timer; 110 + 111 + if (id >= OTG_TIMER_NUM) 112 + return -EINVAL; 113 + 114 + timer = &mvotg->otg_ctrl.timer[id]; 115 + 116 + if (timer_pending(timer)) 117 + del_timer(timer); 118 + 119 + return 0; 120 + } 121 + 122 + static int mv_otg_set_timer(struct mv_otg *mvotg, unsigned int id, 123 + unsigned long interval, 124 + void (*callback) (unsigned long)) 125 + { 126 + struct timer_list *timer; 127 + 128 + if (id >= OTG_TIMER_NUM) 129 + return -EINVAL; 130 + 131 + timer = &mvotg->otg_ctrl.timer[id]; 132 + if (timer_pending(timer)) { 133 + dev_err(&mvotg->pdev->dev, "Timer%d is already running\n", id); 134 + return -EBUSY; 135 + } 136 + 137 + init_timer(timer); 138 + timer->data = (unsigned long) mvotg; 139 + timer->function = callback; 140 + timer->expires = jiffies + interval; 141 + add_timer(timer); 142 + 143 + return 0; 144 + } 145 + 146 + static int mv_otg_reset(struct mv_otg *mvotg) 147 + { 148 + unsigned int loops; 149 + u32 tmp; 150 + 151 + /* Stop the controller */ 152 + tmp = readl(&mvotg->op_regs->usbcmd); 153 + tmp &= ~USBCMD_RUN_STOP; 154 + writel(tmp, &mvotg->op_regs->usbcmd); 155 + 156 + /* Reset the controller to get default values */ 157 + writel(USBCMD_CTRL_RESET, &mvotg->op_regs->usbcmd); 158 + 159 + loops = 500; 160 + while (readl(&mvotg->op_regs->usbcmd) & USBCMD_CTRL_RESET) { 161 + if (loops == 0) { 162 + dev_err(&mvotg->pdev->dev, 163 + "Wait for RESET completed TIMEOUT\n"); 164 + return -ETIMEDOUT; 165 + } 166 + loops--; 167 + udelay(20); 168 + } 169 + 170 + writel(0x0, &mvotg->op_regs->usbintr); 171 + tmp = readl(&mvotg->op_regs->usbsts); 172 + writel(tmp, &mvotg->op_regs->usbsts); 173 + 174 + return 0; 175 + } 176 + 177 + static void mv_otg_init_irq(struct mv_otg *mvotg) 178 + { 179 + u32 otgsc; 180 + 181 + mvotg->irq_en = OTGSC_INTR_A_SESSION_VALID 182 + | OTGSC_INTR_A_VBUS_VALID; 183 + mvotg->irq_status = OTGSC_INTSTS_A_SESSION_VALID 184 + | OTGSC_INTSTS_A_VBUS_VALID; 185 + 186 + if (mvotg->pdata->vbus == NULL) { 187 + mvotg->irq_en |= OTGSC_INTR_B_SESSION_VALID 188 + | OTGSC_INTR_B_SESSION_END; 189 + mvotg->irq_status |= OTGSC_INTSTS_B_SESSION_VALID 190 + | OTGSC_INTSTS_B_SESSION_END; 191 + } 192 + 193 + if (mvotg->pdata->id == NULL) { 194 + mvotg->irq_en |= OTGSC_INTR_USB_ID; 195 + mvotg->irq_status |= OTGSC_INTSTS_USB_ID; 196 + } 197 + 198 + otgsc = readl(&mvotg->op_regs->otgsc); 199 + otgsc |= mvotg->irq_en; 200 + writel(otgsc, &mvotg->op_regs->otgsc); 201 + } 202 + 203 + static void mv_otg_start_host(struct mv_otg *mvotg, int on) 204 + { 205 + struct otg_transceiver *otg = &mvotg->otg; 206 + struct usb_hcd *hcd; 207 + 208 + if (!otg->host) 209 + return; 210 + 211 + dev_info(&mvotg->pdev->dev, "%s host\n", on ? "start" : "stop"); 212 + 213 + hcd = bus_to_hcd(otg->host); 214 + 215 + if (on) 216 + usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); 217 + else 218 + usb_remove_hcd(hcd); 219 + } 220 + 221 + static void mv_otg_start_periphrals(struct mv_otg *mvotg, int on) 222 + { 223 + struct otg_transceiver *otg = &mvotg->otg; 224 + 225 + if (!otg->gadget) 226 + return; 227 + 228 + dev_info(otg->dev, "gadget %s\n", on ? "on" : "off"); 229 + 230 + if (on) 231 + usb_gadget_vbus_connect(otg->gadget); 232 + else 233 + usb_gadget_vbus_disconnect(otg->gadget); 234 + } 235 + 236 + static void otg_clock_enable(struct mv_otg *mvotg) 237 + { 238 + unsigned int i; 239 + 240 + for (i = 0; i < mvotg->clknum; i++) 241 + clk_enable(mvotg->clk[i]); 242 + } 243 + 244 + static void otg_clock_disable(struct mv_otg *mvotg) 245 + { 246 + unsigned int i; 247 + 248 + for (i = 0; i < mvotg->clknum; i++) 249 + clk_disable(mvotg->clk[i]); 250 + } 251 + 252 + static int mv_otg_enable_internal(struct mv_otg *mvotg) 253 + { 254 + int retval = 0; 255 + 256 + if (mvotg->active) 257 + return 0; 258 + 259 + dev_dbg(&mvotg->pdev->dev, "otg enabled\n"); 260 + 261 + otg_clock_enable(mvotg); 262 + if (mvotg->pdata->phy_init) { 263 + retval = mvotg->pdata->phy_init(mvotg->phy_regs); 264 + if (retval) { 265 + dev_err(&mvotg->pdev->dev, 266 + "init phy error %d\n", retval); 267 + otg_clock_disable(mvotg); 268 + return retval; 269 + } 270 + } 271 + mvotg->active = 1; 272 + 273 + return 0; 274 + 275 + } 276 + 277 + static int mv_otg_enable(struct mv_otg *mvotg) 278 + { 279 + if (mvotg->clock_gating) 280 + return mv_otg_enable_internal(mvotg); 281 + 282 + return 0; 283 + } 284 + 285 + static void mv_otg_disable_internal(struct mv_otg *mvotg) 286 + { 287 + if (mvotg->active) { 288 + dev_dbg(&mvotg->pdev->dev, "otg disabled\n"); 289 + if (mvotg->pdata->phy_deinit) 290 + mvotg->pdata->phy_deinit(mvotg->phy_regs); 291 + otg_clock_disable(mvotg); 292 + mvotg->active = 0; 293 + } 294 + } 295 + 296 + static void mv_otg_disable(struct mv_otg *mvotg) 297 + { 298 + if (mvotg->clock_gating) 299 + mv_otg_disable_internal(mvotg); 300 + } 301 + 302 + static void mv_otg_update_inputs(struct mv_otg *mvotg) 303 + { 304 + struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; 305 + u32 otgsc; 306 + 307 + otgsc = readl(&mvotg->op_regs->otgsc); 308 + 309 + if (mvotg->pdata->vbus) { 310 + if (mvotg->pdata->vbus->poll() == VBUS_HIGH) { 311 + otg_ctrl->b_sess_vld = 1; 312 + otg_ctrl->b_sess_end = 0; 313 + } else { 314 + otg_ctrl->b_sess_vld = 0; 315 + otg_ctrl->b_sess_end = 1; 316 + } 317 + } else { 318 + otg_ctrl->b_sess_vld = !!(otgsc & OTGSC_STS_B_SESSION_VALID); 319 + otg_ctrl->b_sess_end = !!(otgsc & OTGSC_STS_B_SESSION_END); 320 + } 321 + 322 + if (mvotg->pdata->id) 323 + otg_ctrl->id = !!mvotg->pdata->id->poll(); 324 + else 325 + otg_ctrl->id = !!(otgsc & OTGSC_STS_USB_ID); 326 + 327 + if (mvotg->pdata->otg_force_a_bus_req && !otg_ctrl->id) 328 + otg_ctrl->a_bus_req = 1; 329 + 330 + otg_ctrl->a_sess_vld = !!(otgsc & OTGSC_STS_A_SESSION_VALID); 331 + otg_ctrl->a_vbus_vld = !!(otgsc & OTGSC_STS_A_VBUS_VALID); 332 + 333 + dev_dbg(&mvotg->pdev->dev, "%s: ", __func__); 334 + dev_dbg(&mvotg->pdev->dev, "id %d\n", otg_ctrl->id); 335 + dev_dbg(&mvotg->pdev->dev, "b_sess_vld %d\n", otg_ctrl->b_sess_vld); 336 + dev_dbg(&mvotg->pdev->dev, "b_sess_end %d\n", otg_ctrl->b_sess_end); 337 + dev_dbg(&mvotg->pdev->dev, "a_vbus_vld %d\n", otg_ctrl->a_vbus_vld); 338 + dev_dbg(&mvotg->pdev->dev, "a_sess_vld %d\n", otg_ctrl->a_sess_vld); 339 + } 340 + 341 + static void mv_otg_update_state(struct mv_otg *mvotg) 342 + { 343 + struct mv_otg_ctrl *otg_ctrl = &mvotg->otg_ctrl; 344 + struct otg_transceiver *otg = &mvotg->otg; 345 + int old_state = otg->state; 346 + 347 + switch (old_state) { 348 + case OTG_STATE_UNDEFINED: 349 + otg->state = OTG_STATE_B_IDLE; 350 + /* FALL THROUGH */ 351 + case OTG_STATE_B_IDLE: 352 + if (otg_ctrl->id == 0) 353 + otg->state = OTG_STATE_A_IDLE; 354 + else if (otg_ctrl->b_sess_vld) 355 + otg->state = OTG_STATE_B_PERIPHERAL; 356 + break; 357 + case OTG_STATE_B_PERIPHERAL: 358 + if (!otg_ctrl->b_sess_vld || otg_ctrl->id == 0) 359 + otg->state = OTG_STATE_B_IDLE; 360 + break; 361 + case OTG_STATE_A_IDLE: 362 + if (otg_ctrl->id) 363 + otg->state = OTG_STATE_B_IDLE; 364 + else if (!(otg_ctrl->a_bus_drop) && 365 + (otg_ctrl->a_bus_req || otg_ctrl->a_srp_det)) 366 + otg->state = OTG_STATE_A_WAIT_VRISE; 367 + break; 368 + case OTG_STATE_A_WAIT_VRISE: 369 + if (otg_ctrl->a_vbus_vld) 370 + otg->state = OTG_STATE_A_WAIT_BCON; 371 + break; 372 + case OTG_STATE_A_WAIT_BCON: 373 + if (otg_ctrl->id || otg_ctrl->a_bus_drop 374 + || otg_ctrl->a_wait_bcon_timeout) { 375 + mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); 376 + mvotg->otg_ctrl.a_wait_bcon_timeout = 0; 377 + otg->state = OTG_STATE_A_WAIT_VFALL; 378 + otg_ctrl->a_bus_req = 0; 379 + } else if (!otg_ctrl->a_vbus_vld) { 380 + mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); 381 + mvotg->otg_ctrl.a_wait_bcon_timeout = 0; 382 + otg->state = OTG_STATE_A_VBUS_ERR; 383 + } else if (otg_ctrl->b_conn) { 384 + mv_otg_cancel_timer(mvotg, A_WAIT_BCON_TIMER); 385 + mvotg->otg_ctrl.a_wait_bcon_timeout = 0; 386 + otg->state = OTG_STATE_A_HOST; 387 + } 388 + break; 389 + case OTG_STATE_A_HOST: 390 + if (otg_ctrl->id || !otg_ctrl->b_conn 391 + || otg_ctrl->a_bus_drop) 392 + otg->state = OTG_STATE_A_WAIT_BCON; 393 + else if (!otg_ctrl->a_vbus_vld) 394 + otg->state = OTG_STATE_A_VBUS_ERR; 395 + break; 396 + case OTG_STATE_A_WAIT_VFALL: 397 + if (otg_ctrl->id 398 + || (!otg_ctrl->b_conn && otg_ctrl->a_sess_vld) 399 + || otg_ctrl->a_bus_req) 400 + otg->state = OTG_STATE_A_IDLE; 401 + break; 402 + case OTG_STATE_A_VBUS_ERR: 403 + if (otg_ctrl->id || otg_ctrl->a_clr_err 404 + || otg_ctrl->a_bus_drop) { 405 + otg_ctrl->a_clr_err = 0; 406 + otg->state = OTG_STATE_A_WAIT_VFALL; 407 + } 408 + break; 409 + default: 410 + break; 411 + } 412 + } 413 + 414 + static void mv_otg_work(struct work_struct *work) 415 + { 416 + struct mv_otg *mvotg; 417 + struct otg_transceiver *otg; 418 + int old_state; 419 + 420 + mvotg = container_of((struct delayed_work *)work, struct mv_otg, work); 421 + 422 + run: 423 + /* work queue is single thread, or we need spin_lock to protect */ 424 + otg = &mvotg->otg; 425 + old_state = otg->state; 426 + 427 + if (!mvotg->active) 428 + return; 429 + 430 + mv_otg_update_inputs(mvotg); 431 + mv_otg_update_state(mvotg); 432 + 433 + if (old_state != otg->state) { 434 + dev_info(&mvotg->pdev->dev, "change from state %s to %s\n", 435 + state_string[old_state], 436 + state_string[otg->state]); 437 + 438 + switch (otg->state) { 439 + case OTG_STATE_B_IDLE: 440 + mvotg->otg.default_a = 0; 441 + if (old_state == OTG_STATE_B_PERIPHERAL) 442 + mv_otg_start_periphrals(mvotg, 0); 443 + mv_otg_reset(mvotg); 444 + mv_otg_disable(mvotg); 445 + break; 446 + case OTG_STATE_B_PERIPHERAL: 447 + mv_otg_enable(mvotg); 448 + mv_otg_start_periphrals(mvotg, 1); 449 + break; 450 + case OTG_STATE_A_IDLE: 451 + mvotg->otg.default_a = 1; 452 + mv_otg_enable(mvotg); 453 + if (old_state == OTG_STATE_A_WAIT_VFALL) 454 + mv_otg_start_host(mvotg, 0); 455 + mv_otg_reset(mvotg); 456 + break; 457 + case OTG_STATE_A_WAIT_VRISE: 458 + mv_otg_set_vbus(&mvotg->otg, 1); 459 + break; 460 + case OTG_STATE_A_WAIT_BCON: 461 + if (old_state != OTG_STATE_A_HOST) 462 + mv_otg_start_host(mvotg, 1); 463 + mv_otg_set_timer(mvotg, A_WAIT_BCON_TIMER, 464 + T_A_WAIT_BCON, 465 + mv_otg_timer_await_bcon); 466 + /* 467 + * Now, we directly enter A_HOST. So set b_conn = 1 468 + * here. In fact, it need host driver to notify us. 469 + */ 470 + mvotg->otg_ctrl.b_conn = 1; 471 + break; 472 + case OTG_STATE_A_HOST: 473 + break; 474 + case OTG_STATE_A_WAIT_VFALL: 475 + /* 476 + * Now, we has exited A_HOST. So set b_conn = 0 477 + * here. In fact, it need host driver to notify us. 478 + */ 479 + mvotg->otg_ctrl.b_conn = 0; 480 + mv_otg_set_vbus(&mvotg->otg, 0); 481 + break; 482 + case OTG_STATE_A_VBUS_ERR: 483 + break; 484 + default: 485 + break; 486 + } 487 + goto run; 488 + } 489 + } 490 + 491 + static irqreturn_t mv_otg_irq(int irq, void *dev) 492 + { 493 + struct mv_otg *mvotg = dev; 494 + u32 otgsc; 495 + 496 + otgsc = readl(&mvotg->op_regs->otgsc); 497 + writel(otgsc, &mvotg->op_regs->otgsc); 498 + 499 + /* 500 + * if we have vbus, then the vbus detection for B-device 501 + * will be done by mv_otg_inputs_irq(). 502 + */ 503 + if (mvotg->pdata->vbus) 504 + if ((otgsc & OTGSC_STS_USB_ID) && 505 + !(otgsc & OTGSC_INTSTS_USB_ID)) 506 + return IRQ_NONE; 507 + 508 + if ((otgsc & mvotg->irq_status) == 0) 509 + return IRQ_NONE; 510 + 511 + mv_otg_run_state_machine(mvotg, 0); 512 + 513 + return IRQ_HANDLED; 514 + } 515 + 516 + static irqreturn_t mv_otg_inputs_irq(int irq, void *dev) 517 + { 518 + struct mv_otg *mvotg = dev; 519 + 520 + /* The clock may disabled at this time */ 521 + if (!mvotg->active) { 522 + mv_otg_enable(mvotg); 523 + mv_otg_init_irq(mvotg); 524 + } 525 + 526 + mv_otg_run_state_machine(mvotg, 0); 527 + 528 + return IRQ_HANDLED; 529 + } 530 + 531 + static ssize_t 532 + get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf) 533 + { 534 + struct mv_otg *mvotg = dev_get_drvdata(dev); 535 + return scnprintf(buf, PAGE_SIZE, "%d\n", 536 + mvotg->otg_ctrl.a_bus_req); 537 + } 538 + 539 + static ssize_t 540 + set_a_bus_req(struct device *dev, struct device_attribute *attr, 541 + const char *buf, size_t count) 542 + { 543 + struct mv_otg *mvotg = dev_get_drvdata(dev); 544 + 545 + if (count > 2) 546 + return -1; 547 + 548 + /* We will use this interface to change to A device */ 549 + if (mvotg->otg.state != OTG_STATE_B_IDLE 550 + && mvotg->otg.state != OTG_STATE_A_IDLE) 551 + return -1; 552 + 553 + /* The clock may disabled and we need to set irq for ID detected */ 554 + mv_otg_enable(mvotg); 555 + mv_otg_init_irq(mvotg); 556 + 557 + if (buf[0] == '1') { 558 + mvotg->otg_ctrl.a_bus_req = 1; 559 + mvotg->otg_ctrl.a_bus_drop = 0; 560 + dev_dbg(&mvotg->pdev->dev, 561 + "User request: a_bus_req = 1\n"); 562 + 563 + if (spin_trylock(&mvotg->wq_lock)) { 564 + mv_otg_run_state_machine(mvotg, 0); 565 + spin_unlock(&mvotg->wq_lock); 566 + } 567 + } 568 + 569 + return count; 570 + } 571 + 572 + static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, 573 + set_a_bus_req); 574 + 575 + static ssize_t 576 + set_a_clr_err(struct device *dev, struct device_attribute *attr, 577 + const char *buf, size_t count) 578 + { 579 + struct mv_otg *mvotg = dev_get_drvdata(dev); 580 + if (!mvotg->otg.default_a) 581 + return -1; 582 + 583 + if (count > 2) 584 + return -1; 585 + 586 + if (buf[0] == '1') { 587 + mvotg->otg_ctrl.a_clr_err = 1; 588 + dev_dbg(&mvotg->pdev->dev, 589 + "User request: a_clr_err = 1\n"); 590 + } 591 + 592 + if (spin_trylock(&mvotg->wq_lock)) { 593 + mv_otg_run_state_machine(mvotg, 0); 594 + spin_unlock(&mvotg->wq_lock); 595 + } 596 + 597 + return count; 598 + } 599 + 600 + static DEVICE_ATTR(a_clr_err, S_IWUSR, NULL, set_a_clr_err); 601 + 602 + static ssize_t 603 + get_a_bus_drop(struct device *dev, struct device_attribute *attr, 604 + char *buf) 605 + { 606 + struct mv_otg *mvotg = dev_get_drvdata(dev); 607 + return scnprintf(buf, PAGE_SIZE, "%d\n", 608 + mvotg->otg_ctrl.a_bus_drop); 609 + } 610 + 611 + static ssize_t 612 + set_a_bus_drop(struct device *dev, struct device_attribute *attr, 613 + const char *buf, size_t count) 614 + { 615 + struct mv_otg *mvotg = dev_get_drvdata(dev); 616 + if (!mvotg->otg.default_a) 617 + return -1; 618 + 619 + if (count > 2) 620 + return -1; 621 + 622 + if (buf[0] == '0') { 623 + mvotg->otg_ctrl.a_bus_drop = 0; 624 + dev_dbg(&mvotg->pdev->dev, 625 + "User request: a_bus_drop = 0\n"); 626 + } else if (buf[0] == '1') { 627 + mvotg->otg_ctrl.a_bus_drop = 1; 628 + mvotg->otg_ctrl.a_bus_req = 0; 629 + dev_dbg(&mvotg->pdev->dev, 630 + "User request: a_bus_drop = 1\n"); 631 + dev_dbg(&mvotg->pdev->dev, 632 + "User request: and a_bus_req = 0\n"); 633 + } 634 + 635 + if (spin_trylock(&mvotg->wq_lock)) { 636 + mv_otg_run_state_machine(mvotg, 0); 637 + spin_unlock(&mvotg->wq_lock); 638 + } 639 + 640 + return count; 641 + } 642 + 643 + static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, 644 + get_a_bus_drop, set_a_bus_drop); 645 + 646 + static struct attribute *inputs_attrs[] = { 647 + &dev_attr_a_bus_req.attr, 648 + &dev_attr_a_clr_err.attr, 649 + &dev_attr_a_bus_drop.attr, 650 + NULL, 651 + }; 652 + 653 + static struct attribute_group inputs_attr_group = { 654 + .name = "inputs", 655 + .attrs = inputs_attrs, 656 + }; 657 + 658 + int mv_otg_remove(struct platform_device *pdev) 659 + { 660 + struct mv_otg *mvotg = platform_get_drvdata(pdev); 661 + int clk_i; 662 + 663 + sysfs_remove_group(&mvotg->pdev->dev.kobj, &inputs_attr_group); 664 + 665 + if (mvotg->irq) 666 + free_irq(mvotg->irq, mvotg); 667 + 668 + if (mvotg->pdata->vbus) 669 + free_irq(mvotg->pdata->vbus->irq, mvotg); 670 + if (mvotg->pdata->id) 671 + free_irq(mvotg->pdata->id->irq, mvotg); 672 + 673 + if (mvotg->qwork) { 674 + flush_workqueue(mvotg->qwork); 675 + destroy_workqueue(mvotg->qwork); 676 + } 677 + 678 + mv_otg_disable(mvotg); 679 + 680 + if (mvotg->cap_regs) 681 + iounmap(mvotg->cap_regs); 682 + 683 + if (mvotg->phy_regs) 684 + iounmap(mvotg->phy_regs); 685 + 686 + for (clk_i = 0; clk_i <= mvotg->clknum; clk_i++) 687 + clk_put(mvotg->clk[clk_i]); 688 + 689 + otg_set_transceiver(NULL); 690 + platform_set_drvdata(pdev, NULL); 691 + 692 + kfree(mvotg); 693 + 694 + return 0; 695 + } 696 + 697 + static int mv_otg_probe(struct platform_device *pdev) 698 + { 699 + struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 700 + struct mv_otg *mvotg; 701 + struct resource *r; 702 + int retval = 0, clk_i, i; 703 + size_t size; 704 + 705 + if (pdata == NULL) { 706 + dev_err(&pdev->dev, "failed to get platform data\n"); 707 + return -ENODEV; 708 + } 709 + 710 + size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 711 + mvotg = kzalloc(size, GFP_KERNEL); 712 + if (!mvotg) { 713 + dev_err(&pdev->dev, "failed to allocate memory!\n"); 714 + return -ENOMEM; 715 + } 716 + 717 + platform_set_drvdata(pdev, mvotg); 718 + 719 + mvotg->pdev = pdev; 720 + mvotg->pdata = pdata; 721 + 722 + mvotg->clknum = pdata->clknum; 723 + for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 724 + mvotg->clk[clk_i] = clk_get(&pdev->dev, pdata->clkname[clk_i]); 725 + if (IS_ERR(mvotg->clk[clk_i])) { 726 + retval = PTR_ERR(mvotg->clk[clk_i]); 727 + goto err_put_clk; 728 + } 729 + } 730 + 731 + mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 732 + if (!mvotg->qwork) { 733 + dev_dbg(&pdev->dev, "cannot create workqueue for OTG\n"); 734 + retval = -ENOMEM; 735 + goto err_put_clk; 736 + } 737 + 738 + INIT_DELAYED_WORK(&mvotg->work, mv_otg_work); 739 + 740 + /* OTG common part */ 741 + mvotg->pdev = pdev; 742 + mvotg->otg.dev = &pdev->dev; 743 + mvotg->otg.label = driver_name; 744 + mvotg->otg.set_host = mv_otg_set_host; 745 + mvotg->otg.set_peripheral = mv_otg_set_peripheral; 746 + mvotg->otg.set_vbus = mv_otg_set_vbus; 747 + mvotg->otg.state = OTG_STATE_UNDEFINED; 748 + 749 + for (i = 0; i < OTG_TIMER_NUM; i++) 750 + init_timer(&mvotg->otg_ctrl.timer[i]); 751 + 752 + r = platform_get_resource_byname(mvotg->pdev, 753 + IORESOURCE_MEM, "phyregs"); 754 + if (r == NULL) { 755 + dev_err(&pdev->dev, "no phy I/O memory resource defined\n"); 756 + retval = -ENODEV; 757 + goto err_destroy_workqueue; 758 + } 759 + 760 + mvotg->phy_regs = ioremap(r->start, resource_size(r)); 761 + if (mvotg->phy_regs == NULL) { 762 + dev_err(&pdev->dev, "failed to map phy I/O memory\n"); 763 + retval = -EFAULT; 764 + goto err_destroy_workqueue; 765 + } 766 + 767 + r = platform_get_resource_byname(mvotg->pdev, 768 + IORESOURCE_MEM, "capregs"); 769 + if (r == NULL) { 770 + dev_err(&pdev->dev, "no I/O memory resource defined\n"); 771 + retval = -ENODEV; 772 + goto err_unmap_phyreg; 773 + } 774 + 775 + mvotg->cap_regs = ioremap(r->start, resource_size(r)); 776 + if (mvotg->cap_regs == NULL) { 777 + dev_err(&pdev->dev, "failed to map I/O memory\n"); 778 + retval = -EFAULT; 779 + goto err_unmap_phyreg; 780 + } 781 + 782 + /* we will acces controller register, so enable the udc controller */ 783 + retval = mv_otg_enable_internal(mvotg); 784 + if (retval) { 785 + dev_err(&pdev->dev, "mv otg enable error %d\n", retval); 786 + goto err_unmap_capreg; 787 + } 788 + 789 + mvotg->op_regs = 790 + (struct mv_otg_regs __iomem *) ((unsigned long) mvotg->cap_regs 791 + + (readl(mvotg->cap_regs) & CAPLENGTH_MASK)); 792 + 793 + if (pdata->id) { 794 + retval = request_threaded_irq(pdata->id->irq, NULL, 795 + mv_otg_inputs_irq, 796 + IRQF_ONESHOT, "id", mvotg); 797 + if (retval) { 798 + dev_info(&pdev->dev, 799 + "Failed to request irq for ID\n"); 800 + pdata->id = NULL; 801 + } 802 + } 803 + 804 + if (pdata->vbus) { 805 + mvotg->clock_gating = 1; 806 + retval = request_threaded_irq(pdata->vbus->irq, NULL, 807 + mv_otg_inputs_irq, 808 + IRQF_ONESHOT, "vbus", mvotg); 809 + if (retval) { 810 + dev_info(&pdev->dev, 811 + "Failed to request irq for VBUS, " 812 + "disable clock gating\n"); 813 + mvotg->clock_gating = 0; 814 + pdata->vbus = NULL; 815 + } 816 + } 817 + 818 + if (pdata->disable_otg_clock_gating) 819 + mvotg->clock_gating = 0; 820 + 821 + mv_otg_reset(mvotg); 822 + mv_otg_init_irq(mvotg); 823 + 824 + r = platform_get_resource(mvotg->pdev, IORESOURCE_IRQ, 0); 825 + if (r == NULL) { 826 + dev_err(&pdev->dev, "no IRQ resource defined\n"); 827 + retval = -ENODEV; 828 + goto err_disable_clk; 829 + } 830 + 831 + mvotg->irq = r->start; 832 + if (request_irq(mvotg->irq, mv_otg_irq, IRQF_SHARED, 833 + driver_name, mvotg)) { 834 + dev_err(&pdev->dev, "Request irq %d for OTG failed\n", 835 + mvotg->irq); 836 + mvotg->irq = 0; 837 + retval = -ENODEV; 838 + goto err_disable_clk; 839 + } 840 + 841 + retval = otg_set_transceiver(&mvotg->otg); 842 + if (retval < 0) { 843 + dev_err(&pdev->dev, "can't register transceiver, %d\n", 844 + retval); 845 + goto err_free_irq; 846 + } 847 + 848 + retval = sysfs_create_group(&pdev->dev.kobj, &inputs_attr_group); 849 + if (retval < 0) { 850 + dev_dbg(&pdev->dev, 851 + "Can't register sysfs attr group: %d\n", retval); 852 + goto err_set_transceiver; 853 + } 854 + 855 + spin_lock_init(&mvotg->wq_lock); 856 + if (spin_trylock(&mvotg->wq_lock)) { 857 + mv_otg_run_state_machine(mvotg, 2 * HZ); 858 + spin_unlock(&mvotg->wq_lock); 859 + } 860 + 861 + dev_info(&pdev->dev, 862 + "successful probe OTG device %s clock gating.\n", 863 + mvotg->clock_gating ? "with" : "without"); 864 + 865 + return 0; 866 + 867 + err_set_transceiver: 868 + otg_set_transceiver(NULL); 869 + err_free_irq: 870 + free_irq(mvotg->irq, mvotg); 871 + err_disable_clk: 872 + if (pdata->vbus) 873 + free_irq(pdata->vbus->irq, mvotg); 874 + if (pdata->id) 875 + free_irq(pdata->id->irq, mvotg); 876 + mv_otg_disable_internal(mvotg); 877 + err_unmap_capreg: 878 + iounmap(mvotg->cap_regs); 879 + err_unmap_phyreg: 880 + iounmap(mvotg->phy_regs); 881 + err_destroy_workqueue: 882 + flush_workqueue(mvotg->qwork); 883 + destroy_workqueue(mvotg->qwork); 884 + err_put_clk: 885 + for (clk_i--; clk_i >= 0; clk_i--) 886 + clk_put(mvotg->clk[clk_i]); 887 + 888 + platform_set_drvdata(pdev, NULL); 889 + kfree(mvotg); 890 + 891 + return retval; 892 + } 893 + 894 + #ifdef CONFIG_PM 895 + static int mv_otg_suspend(struct platform_device *pdev, pm_message_t state) 896 + { 897 + struct mv_otg *mvotg = platform_get_drvdata(pdev); 898 + 899 + if (mvotg->otg.state != OTG_STATE_B_IDLE) { 900 + dev_info(&pdev->dev, 901 + "OTG state is not B_IDLE, it is %d!\n", 902 + mvotg->otg.state); 903 + return -EAGAIN; 904 + } 905 + 906 + if (!mvotg->clock_gating) 907 + mv_otg_disable_internal(mvotg); 908 + 909 + return 0; 910 + } 911 + 912 + static int mv_otg_resume(struct platform_device *pdev) 913 + { 914 + struct mv_otg *mvotg = platform_get_drvdata(pdev); 915 + u32 otgsc; 916 + 917 + if (!mvotg->clock_gating) { 918 + mv_otg_enable_internal(mvotg); 919 + 920 + otgsc = readl(&mvotg->op_regs->otgsc); 921 + otgsc |= mvotg->irq_en; 922 + writel(otgsc, &mvotg->op_regs->otgsc); 923 + 924 + if (spin_trylock(&mvotg->wq_lock)) { 925 + mv_otg_run_state_machine(mvotg, 0); 926 + spin_unlock(&mvotg->wq_lock); 927 + } 928 + } 929 + return 0; 930 + } 931 + #endif 932 + 933 + static struct platform_driver mv_otg_driver = { 934 + .probe = mv_otg_probe, 935 + .remove = __exit_p(mv_otg_remove), 936 + .driver = { 937 + .owner = THIS_MODULE, 938 + .name = driver_name, 939 + }, 940 + #ifdef CONFIG_PM 941 + .suspend = mv_otg_suspend, 942 + .resume = mv_otg_resume, 943 + #endif 944 + }; 945 + 946 + static int __init mv_otg_init(void) 947 + { 948 + return platform_driver_register(&mv_otg_driver); 949 + } 950 + 951 + static void __exit mv_otg_exit(void) 952 + { 953 + platform_driver_unregister(&mv_otg_driver); 954 + } 955 + 956 + module_init(mv_otg_init); 957 + module_exit(mv_otg_exit);
+165
drivers/usb/otg/mv_otg.h
··· 1 + /* 2 + * Copyright (C) 2011 Marvell International Ltd. All rights reserved. 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms of the GNU General Public License as published by the 6 + * Free Software Foundation; either version 2 of the License, or (at your 7 + * option) any later version. 8 + */ 9 + 10 + #ifndef __MV_USB_OTG_CONTROLLER__ 11 + #define __MV_USB_OTG_CONTROLLER__ 12 + 13 + #include <linux/types.h> 14 + 15 + /* Command Register Bit Masks */ 16 + #define USBCMD_RUN_STOP (0x00000001) 17 + #define USBCMD_CTRL_RESET (0x00000002) 18 + 19 + /* otgsc Register Bit Masks */ 20 + #define OTGSC_CTRL_VUSB_DISCHARGE 0x00000001 21 + #define OTGSC_CTRL_VUSB_CHARGE 0x00000002 22 + #define OTGSC_CTRL_OTG_TERM 0x00000008 23 + #define OTGSC_CTRL_DATA_PULSING 0x00000010 24 + #define OTGSC_STS_USB_ID 0x00000100 25 + #define OTGSC_STS_A_VBUS_VALID 0x00000200 26 + #define OTGSC_STS_A_SESSION_VALID 0x00000400 27 + #define OTGSC_STS_B_SESSION_VALID 0x00000800 28 + #define OTGSC_STS_B_SESSION_END 0x00001000 29 + #define OTGSC_STS_1MS_TOGGLE 0x00002000 30 + #define OTGSC_STS_DATA_PULSING 0x00004000 31 + #define OTGSC_INTSTS_USB_ID 0x00010000 32 + #define OTGSC_INTSTS_A_VBUS_VALID 0x00020000 33 + #define OTGSC_INTSTS_A_SESSION_VALID 0x00040000 34 + #define OTGSC_INTSTS_B_SESSION_VALID 0x00080000 35 + #define OTGSC_INTSTS_B_SESSION_END 0x00100000 36 + #define OTGSC_INTSTS_1MS 0x00200000 37 + #define OTGSC_INTSTS_DATA_PULSING 0x00400000 38 + #define OTGSC_INTR_USB_ID 0x01000000 39 + #define OTGSC_INTR_A_VBUS_VALID 0x02000000 40 + #define OTGSC_INTR_A_SESSION_VALID 0x04000000 41 + #define OTGSC_INTR_B_SESSION_VALID 0x08000000 42 + #define OTGSC_INTR_B_SESSION_END 0x10000000 43 + #define OTGSC_INTR_1MS_TIMER 0x20000000 44 + #define OTGSC_INTR_DATA_PULSING 0x40000000 45 + 46 + #define CAPLENGTH_MASK (0xff) 47 + 48 + /* Timer's interval, unit 10ms */ 49 + #define T_A_WAIT_VRISE 100 50 + #define T_A_WAIT_BCON 2000 51 + #define T_A_AIDL_BDIS 100 52 + #define T_A_BIDL_ADIS 20 53 + #define T_B_ASE0_BRST 400 54 + #define T_B_SE0_SRP 300 55 + #define T_B_SRP_FAIL 2000 56 + #define T_B_DATA_PLS 10 57 + #define T_B_SRP_INIT 100 58 + #define T_A_SRP_RSPNS 10 59 + #define T_A_DRV_RSM 5 60 + 61 + enum otg_function { 62 + OTG_B_DEVICE = 0, 63 + OTG_A_DEVICE 64 + }; 65 + 66 + enum mv_otg_timer { 67 + A_WAIT_BCON_TIMER = 0, 68 + OTG_TIMER_NUM 69 + }; 70 + 71 + /* PXA OTG state machine */ 72 + struct mv_otg_ctrl { 73 + /* internal variables */ 74 + u8 a_set_b_hnp_en; /* A-Device set b_hnp_en */ 75 + u8 b_srp_done; 76 + u8 b_hnp_en; 77 + 78 + /* OTG inputs */ 79 + u8 a_bus_drop; 80 + u8 a_bus_req; 81 + u8 a_clr_err; 82 + u8 a_bus_resume; 83 + u8 a_bus_suspend; 84 + u8 a_conn; 85 + u8 a_sess_vld; 86 + u8 a_srp_det; 87 + u8 a_vbus_vld; 88 + u8 b_bus_req; /* B-Device Require Bus */ 89 + u8 b_bus_resume; 90 + u8 b_bus_suspend; 91 + u8 b_conn; 92 + u8 b_se0_srp; 93 + u8 b_sess_end; 94 + u8 b_sess_vld; 95 + u8 id; 96 + u8 a_suspend_req; 97 + 98 + /*Timer event */ 99 + u8 a_aidl_bdis_timeout; 100 + u8 b_ase0_brst_timeout; 101 + u8 a_bidl_adis_timeout; 102 + u8 a_wait_bcon_timeout; 103 + 104 + struct timer_list timer[OTG_TIMER_NUM]; 105 + }; 106 + 107 + #define VUSBHS_MAX_PORTS 8 108 + 109 + struct mv_otg_regs { 110 + u32 usbcmd; /* Command register */ 111 + u32 usbsts; /* Status register */ 112 + u32 usbintr; /* Interrupt enable */ 113 + u32 frindex; /* Frame index */ 114 + u32 reserved1[1]; 115 + u32 deviceaddr; /* Device Address */ 116 + u32 eplistaddr; /* Endpoint List Address */ 117 + u32 ttctrl; /* HOST TT status and control */ 118 + u32 burstsize; /* Programmable Burst Size */ 119 + u32 txfilltuning; /* Host Transmit Pre-Buffer Packet Tuning */ 120 + u32 reserved[4]; 121 + u32 epnak; /* Endpoint NAK */ 122 + u32 epnaken; /* Endpoint NAK Enable */ 123 + u32 configflag; /* Configured Flag register */ 124 + u32 portsc[VUSBHS_MAX_PORTS]; /* Port Status/Control x, x = 1..8 */ 125 + u32 otgsc; 126 + u32 usbmode; /* USB Host/Device mode */ 127 + u32 epsetupstat; /* Endpoint Setup Status */ 128 + u32 epprime; /* Endpoint Initialize */ 129 + u32 epflush; /* Endpoint De-initialize */ 130 + u32 epstatus; /* Endpoint Status */ 131 + u32 epcomplete; /* Endpoint Interrupt On Complete */ 132 + u32 epctrlx[16]; /* Endpoint Control, where x = 0.. 15 */ 133 + u32 mcr; /* Mux Control */ 134 + u32 isr; /* Interrupt Status */ 135 + u32 ier; /* Interrupt Enable */ 136 + }; 137 + 138 + struct mv_otg { 139 + struct otg_transceiver otg; 140 + struct mv_otg_ctrl otg_ctrl; 141 + 142 + /* base address */ 143 + void __iomem *phy_regs; 144 + void __iomem *cap_regs; 145 + struct mv_otg_regs __iomem *op_regs; 146 + 147 + struct platform_device *pdev; 148 + int irq; 149 + u32 irq_status; 150 + u32 irq_en; 151 + 152 + struct delayed_work work; 153 + struct workqueue_struct *qwork; 154 + 155 + spinlock_t wq_lock; 156 + 157 + struct mv_usb_platform_data *pdata; 158 + 159 + unsigned int active; 160 + unsigned int clock_gating; 161 + unsigned int clknum; 162 + struct clk *clk[0]; 163 + }; 164 + 165 + #endif
+1 -1
drivers/usb/renesas_usbhs/mod_gadget.c
··· 185 185 } 186 186 187 187 if (dma_mapping_error(dev, pkt->dma)) { 188 - dev_err(dev, "dma mapping error %x\n", pkt->dma); 188 + dev_err(dev, "dma mapping error %llx\n", (u64)pkt->dma); 189 189 return -EIO; 190 190 } 191 191
+1 -2
drivers/usb/renesas_usbhs/mod_host.c
··· 633 633 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); 634 634 struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv); 635 635 struct urb *urb = ureq->urb; 636 - struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); 637 636 struct device *dev = usbhs_priv_to_dev(priv); 638 637 int status = 0; 639 638 ··· 650 651 usbhsh_ureq_free(hpriv, ureq); 651 652 652 653 usbhsh_endpoint_sequence_save(hpriv, urb, pkt); 653 - usbhsh_pipe_detach(hpriv, uep); 654 + usbhsh_pipe_detach(hpriv, usbhsh_ep_to_uep(urb->ep)); 654 655 655 656 usb_hcd_unlink_urb_from_ep(hcd, urb); 656 657 usb_hcd_giveback_urb(hcd, urb, status);
+1 -2
drivers/usb/renesas_usbhs/pipe.c
··· 330 330 if (dir_in) 331 331 usbhsp_flags_set(pipe, IS_DIR_HOST); 332 332 333 - if ((is_host && !dir_in) || 334 - (!is_host && dir_in)) 333 + if (!!is_host ^ !!dir_in) 335 334 dir |= DIR_OUT; 336 335 337 336 if (!dir)
+16 -2
include/linux/platform_data/mv_usb.h
··· 42 42 /* only valid for HCD. OTG or Host only*/ 43 43 unsigned int mode; 44 44 45 - int (*phy_init)(unsigned int regbase); 46 - void (*phy_deinit)(unsigned int regbase); 45 + /* This flag is used for that needs id pin checked by otg */ 46 + unsigned int disable_otg_clock_gating:1; 47 + /* Force a_bus_req to be asserted */ 48 + unsigned int otg_force_a_bus_req:1; 49 + 50 + int (*phy_init)(void __iomem *regbase); 51 + void (*phy_deinit)(void __iomem *regbase); 47 52 int (*set_vbus)(unsigned int vbus); 53 + int (*private_init)(void __iomem *opregs, void __iomem *phyregs); 48 54 }; 55 + 56 + #ifndef CONFIG_HAVE_CLK 57 + /* Dummy stub for clk framework */ 58 + #define clk_get(dev, id) NULL 59 + #define clk_put(clock) do {} while (0) 60 + #define clk_enable(clock) do {} while (0) 61 + #define clk_disable(clock) do {} while (0) 62 + #endif 49 63 50 64 #endif
+34
include/linux/platform_data/s3c-hsudc.h
··· 1 + /* 2 + * S3C24XX USB 2.0 High-speed USB controller gadget driver 3 + * 4 + * Copyright (c) 2010 Samsung Electronics Co., Ltd. 5 + * http://www.samsung.com/ 6 + * 7 + * The S3C24XX USB 2.0 high-speed USB controller supports upto 9 endpoints. 8 + * Each endpoint can be configured as either in or out endpoint. Endpoints 9 + * can be configured for Bulk or Interrupt transfer mode. 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef __LINUX_USB_S3C_HSUDC_H 17 + #define __LINUX_USB_S3C_HSUDC_H 18 + 19 + /** 20 + * s3c24xx_hsudc_platdata - Platform data for USB High-Speed gadget controller. 21 + * @epnum: Number of endpoints to be instantiated by the controller driver. 22 + * @gpio_init: Platform specific USB related GPIO initialization. 23 + * @gpio_uninit: Platform specific USB releted GPIO uninitialzation. 24 + * 25 + * Representation of platform data for the S3C24XX USB 2.0 High Speed gadget 26 + * controllers. 27 + */ 28 + struct s3c24xx_hsudc_platdata { 29 + unsigned int epnum; 30 + void (*gpio_init)(void); 31 + void (*gpio_uninit)(void); 32 + }; 33 + 34 + #endif /* __LINUX_USB_S3C_HSUDC_H */
+11 -1
include/linux/usb/gadget.h
··· 20 20 #include <linux/init.h> 21 21 #include <linux/list.h> 22 22 #include <linux/slab.h> 23 + #include <linux/scatterlist.h> 23 24 #include <linux/types.h> 24 25 #include <linux/usb/ch9.h> 25 26 ··· 33 32 * @dma: DMA address corresponding to 'buf'. If you don't set this 34 33 * field, and the usb controller needs one, it is responsible 35 34 * for mapping and unmapping the buffer. 35 + * @sg: a scatterlist for SG-capable controllers. 36 + * @num_sgs: number of SG entries 37 + * @num_mapped_sgs: number of SG entries mapped to DMA (internal) 36 38 * @length: Length of that data 37 39 * @stream_id: The stream id, when USB3.0 bulk streams are being used 38 40 * @no_interrupt: If true, hints that no completion irq is needed. ··· 91 87 void *buf; 92 88 unsigned length; 93 89 dma_addr_t dma; 90 + 91 + struct scatterlist *sg; 92 + unsigned num_sgs; 93 + unsigned num_mapped_sgs; 94 94 95 95 unsigned stream_id:16; 96 96 unsigned no_interrupt:1; ··· 172 164 unsigned maxpacket:16; 173 165 unsigned max_streams:16; 174 166 unsigned mult:2; 175 - unsigned maxburst:4; 167 + unsigned maxburst:5; 176 168 u8 address; 177 169 const struct usb_endpoint_descriptor *desc; 178 170 const struct usb_ss_ep_comp_descriptor *comp_desc; ··· 487 479 * @speed: Speed of current connection to USB host. 488 480 * @max_speed: Maximal speed the UDC can handle. UDC must support this 489 481 * and all slower speeds. 482 + * @sg_supported: true if we can handle scatter-gather 490 483 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the 491 484 * gadget driver must provide a USB OTG descriptor. 492 485 * @is_a_peripheral: False unless is_otg, the "A" end of a USB cable ··· 528 519 struct list_head ep_list; /* of usb_ep */ 529 520 enum usb_device_speed speed; 530 521 enum usb_device_speed max_speed; 522 + unsigned sg_supported:1; 531 523 unsigned is_otg:1; 532 524 unsigned is_a_peripheral:1; 533 525 unsigned b_hnp_enable:1;