diff options
author | Lukasz Majewski <l.majewski@samsung.com> | 2012-05-04 08:17:11 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-05-04 08:53:16 -0400 |
commit | 8b9bc4608eefebd9958911017caac8d87e2e8b3c (patch) | |
tree | 5ce052b06980a3e394c43223997b02984eba3337 /drivers/usb/gadget/s3c-hsotg.c | |
parent | f65f0f109878d795854a0a879d5029c7ea560867 (diff) |
usb:hsotg:samsung: Comments reorganization and cleanup
Refactor all comments to comply with kernel codding style.
Moreover doxygen descriptions have been added for selected functions.
Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/s3c-hsotg.c')
-rw-r--r-- | drivers/usb/gadget/s3c-hsotg.c | 374 |
1 files changed, 252 insertions, 122 deletions
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c index b785eadc2921..710823b49dd4 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> |
@@ -44,7 +45,8 @@ static const char * const s3c_hsotg_supply_names[] = { | |||
44 | "vusb_a", /* analog USB supply, 1.1V */ | 45 | "vusb_a", /* analog USB supply, 1.1V */ |
45 | }; | 46 | }; |
46 | 47 | ||
47 | /* EP0_MPS_LIMIT | 48 | /* |
49 | * EP0_MPS_LIMIT | ||
48 | * | 50 | * |
49 | * 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 |
50 | * 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 |
@@ -324,13 +326,6 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
324 | int timeout; | 326 | int timeout; |
325 | u32 val; | 327 | u32 val; |
326 | 328 | ||
327 | /* the ryu 2.6.24 release ahs | ||
328 | writel(0x1C0, hsotg->regs + S3C_GRXFSIZ); | ||
329 | writel(S3C_GNPTXFSIZ_NPTxFStAddr(0x200) | | ||
330 | S3C_GNPTXFSIZ_NPTxFDep(0x1C0), | ||
331 | hsotg->regs + S3C_GNPTXFSIZ); | ||
332 | */ | ||
333 | |||
334 | /* set FIFO sizes to 2048/1024 */ | 329 | /* set FIFO sizes to 2048/1024 */ |
335 | 330 | ||
336 | writel(2048, hsotg->regs + S3C_GRXFSIZ); | 331 | writel(2048, hsotg->regs + S3C_GRXFSIZ); |
@@ -338,17 +333,21 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
338 | S3C_GNPTXFSIZ_NPTxFDep(1024), | 333 | S3C_GNPTXFSIZ_NPTxFDep(1024), |
339 | hsotg->regs + S3C_GNPTXFSIZ); | 334 | hsotg->regs + S3C_GNPTXFSIZ); |
340 | 335 | ||
341 | /* 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 | ||
342 | * block have overlapping default addresses. This also ensures | 338 | * block have overlapping default addresses. This also ensures |
343 | * 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 |
344 | * known values. */ | 340 | * known values. |
341 | */ | ||
345 | 342 | ||
346 | /* start at the end of the GNPTXFSIZ, rounded up */ | 343 | /* start at the end of the GNPTXFSIZ, rounded up */ |
347 | addr = 2048 + 1024; | 344 | addr = 2048 + 1024; |
348 | size = 768; | 345 | size = 768; |
349 | 346 | ||
350 | /* currently we allocate TX FIFOs for all possible endpoints, | 347 | /* |
351 | * 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 | */ | ||
352 | 351 | ||
353 | for (ep = 1; ep <= 15; ep++) { | 352 | for (ep = 1; ep <= 15; ep++) { |
354 | val = addr; | 353 | val = addr; |
@@ -358,8 +357,10 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
358 | writel(val, hsotg->regs + S3C_DPTXFSIZn(ep)); | 357 | writel(val, hsotg->regs + S3C_DPTXFSIZn(ep)); |
359 | } | 358 | } |
360 | 359 | ||
361 | /* according to p428 of the design guide, we need to ensure that | 360 | /* |
362 | * 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 | */ | ||
363 | 364 | ||
364 | writel(S3C_GRSTCTL_TxFNum(0x10) | S3C_GRSTCTL_TxFFlsh | | 365 | writel(S3C_GRSTCTL_TxFNum(0x10) | S3C_GRSTCTL_TxFFlsh | |
365 | S3C_GRSTCTL_RxFFlsh, hsotg->regs + S3C_GRSTCTL); | 366 | S3C_GRSTCTL_RxFFlsh, hsotg->regs + S3C_GRSTCTL); |
@@ -425,7 +426,7 @@ static inline int is_ep_periodic(struct s3c_hsotg_ep *hs_ep) | |||
425 | * | 426 | * |
426 | * 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 |
427 | * 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. |
428 | */ | 429 | */ |
429 | static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | 430 | static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, |
430 | struct s3c_hsotg_ep *hs_ep, | 431 | struct s3c_hsotg_ep *hs_ep, |
431 | struct s3c_hsotg_req *hs_req) | 432 | struct s3c_hsotg_req *hs_req) |
@@ -466,7 +467,7 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg, | |||
466 | * otherwise -ENOSPC is returned if the FIFO space was used up. | 467 | * otherwise -ENOSPC is returned if the FIFO space was used up. |
467 | * | 468 | * |
468 | * This routine is only needed for PIO | 469 | * This routine is only needed for PIO |
469 | */ | 470 | */ |
470 | static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | 471 | static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, |
471 | struct s3c_hsotg_ep *hs_ep, | 472 | struct s3c_hsotg_ep *hs_ep, |
472 | struct s3c_hsotg_req *hs_req) | 473 | struct s3c_hsotg_req *hs_req) |
@@ -490,12 +491,15 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
490 | int size_left; | 491 | int size_left; |
491 | int size_done; | 492 | int size_done; |
492 | 493 | ||
493 | /* work out how much data was loaded so we can calculate | 494 | /* |
494 | * 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 | */ | ||
495 | 498 | ||
496 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); | 499 | size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); |
497 | 500 | ||
498 | /* if shared fifo, we cannot write anything until the | 501 | /* |
502 | * if shared fifo, we cannot write anything until the | ||
499 | * previous data has been completely sent. | 503 | * previous data has been completely sent. |
500 | */ | 504 | */ |
501 | if (hs_ep->fifo_load != 0) { | 505 | if (hs_ep->fifo_load != 0) { |
@@ -545,16 +549,19 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
545 | 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", |
546 | __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); | 550 | __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); |
547 | 551 | ||
548 | /* 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 | ||
549 | * 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 |
550 | * fragment of the end of the transfer in it. | 555 | * fragment of the end of the transfer in it. |
551 | */ | 556 | */ |
552 | if (can_write > 512) | 557 | if (can_write > 512) |
553 | can_write = 512; | 558 | can_write = 512; |
554 | 559 | ||
555 | /* 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 | ||
556 | * 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 |
557 | * doing it. */ | 563 | * doing it. |
564 | */ | ||
558 | if (to_write > hs_ep->ep.maxpacket) { | 565 | if (to_write > hs_ep->ep.maxpacket) { |
559 | to_write = hs_ep->ep.maxpacket; | 566 | to_write = hs_ep->ep.maxpacket; |
560 | 567 | ||
@@ -569,8 +576,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
569 | to_write = can_write; | 576 | to_write = can_write; |
570 | pkt_round = to_write % hs_ep->ep.maxpacket; | 577 | pkt_round = to_write % hs_ep->ep.maxpacket; |
571 | 578 | ||
572 | /* Not sure, but we probably shouldn't be writing partial | 579 | /* |
573 | * packets into the FIFO, so round the write down to an | 580 | * Round the write down to an |
574 | * exact number of packets. | 581 | * exact number of packets. |
575 | * | 582 | * |
576 | * 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 |
@@ -580,8 +587,10 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
580 | if (pkt_round) | 587 | if (pkt_round) |
581 | to_write -= pkt_round; | 588 | to_write -= pkt_round; |
582 | 589 | ||
583 | /* enable correct FIFO interrupt to alert us when there | 590 | /* |
584 | * is more room left. */ | 591 | * enable correct FIFO interrupt to alert us when there |
592 | * is more room left. | ||
593 | */ | ||
585 | 594 | ||
586 | s3c_hsotg_en_gsint(hsotg, | 595 | s3c_hsotg_en_gsint(hsotg, |
587 | periodic ? S3C_GINTSTS_PTxFEmp : | 596 | periodic ? S3C_GINTSTS_PTxFEmp : |
@@ -636,8 +645,10 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
636 | maxpkt--; | 645 | maxpkt--; |
637 | maxsize--; | 646 | maxsize--; |
638 | 647 | ||
639 | /* constrain by packet count if maxpkts*pktsize is greater | 648 | /* |
640 | * than the length register size. */ | 649 | * constrain by packet count if maxpkts*pktsize is greater |
650 | * than the length register size. | ||
651 | */ | ||
641 | 652 | ||
642 | if ((maxpkt * hs_ep->ep.maxpacket) < maxsize) | 653 | if ((maxpkt * hs_ep->ep.maxpacket) < maxsize) |
643 | maxsize = maxpkt * hs_ep->ep.maxpacket; | 654 | maxsize = maxpkt * hs_ep->ep.maxpacket; |
@@ -733,8 +744,10 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
733 | epsize = 0; | 744 | epsize = 0; |
734 | 745 | ||
735 | if (index != 0 && ureq->zero) { | 746 | if (index != 0 && ureq->zero) { |
736 | /* test for the packets being exactly right for the | 747 | /* |
737 | * transfer */ | 748 | * test for the packets being exactly right for the |
749 | * transfer | ||
750 | */ | ||
738 | 751 | ||
739 | if (length == (packets * hs_ep->ep.maxpacket)) | 752 | if (length == (packets * hs_ep->ep.maxpacket)) |
740 | packets++; | 753 | packets++; |
@@ -755,8 +768,10 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
755 | if (using_dma(hsotg) && !continuing) { | 768 | if (using_dma(hsotg) && !continuing) { |
756 | unsigned int dma_reg; | 769 | unsigned int dma_reg; |
757 | 770 | ||
758 | /* write DMA address to control register, buffer already | 771 | /* |
759 | * synced by s3c_hsotg_ep_queue(). */ | 772 | * write DMA address to control register, buffer already |
773 | * synced by s3c_hsotg_ep_queue(). | ||
774 | */ | ||
760 | 775 | ||
761 | dma_reg = dir_in ? S3C_DIEPDMA(index) : S3C_DOEPDMA(index); | 776 | dma_reg = dir_in ? S3C_DIEPDMA(index) : S3C_DOEPDMA(index); |
762 | writel(ureq->dma, hsotg->regs + dma_reg); | 777 | writel(ureq->dma, hsotg->regs + dma_reg); |
@@ -780,9 +795,11 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
780 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); | 795 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
781 | writel(ctrl, hsotg->regs + epctrl_reg); | 796 | writel(ctrl, hsotg->regs + epctrl_reg); |
782 | 797 | ||
783 | /* set these, it seems that DMA support increments past the end | 798 | /* |
799 | * set these, it seems that DMA support increments past the end | ||
784 | * 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 |
785 | * this information. */ | 801 | * this information. |
802 | */ | ||
786 | hs_ep->size_loaded = length; | 803 | hs_ep->size_loaded = length; |
787 | hs_ep->last_load = ureq->actual; | 804 | hs_ep->last_load = ureq->actual; |
788 | 805 | ||
@@ -793,14 +810,18 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
793 | s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); | 810 | s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req); |
794 | } | 811 | } |
795 | 812 | ||
796 | /* clear the INTknTXFEmpMsk when we start request, more as a aide | 813 | /* |
797 | * 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 | */ | ||
798 | if (dir_in) | 817 | if (dir_in) |
799 | writel(S3C_DIEPMSK_INTknTXFEmpMsk, | 818 | writel(S3C_DIEPMSK_INTknTXFEmpMsk, |
800 | hsotg->regs + S3C_DIEPINT(index)); | 819 | hsotg->regs + S3C_DIEPINT(index)); |
801 | 820 | ||
802 | /* Note, trying to clear the NAK here causes problems with transmit | 821 | /* |
803 | * 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 | */ | ||
804 | 825 | ||
805 | /* check ep is enabled */ | 826 | /* check ep is enabled */ |
806 | if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna)) | 827 | if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna)) |
@@ -823,7 +844,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
823 | * 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 |
824 | * 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 |
825 | * cleanup on completion. | 846 | * cleanup on completion. |
826 | */ | 847 | */ |
827 | static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, | 848 | static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg, |
828 | struct s3c_hsotg_ep *hs_ep, | 849 | struct s3c_hsotg_ep *hs_ep, |
829 | struct usb_request *req) | 850 | struct usb_request *req) |
@@ -941,7 +962,7 @@ static void s3c_hsotg_complete_oursetup(struct usb_ep *ep, | |||
941 | * | 962 | * |
942 | * Convert the given wIndex into a pointer to an driver endpoint | 963 | * Convert the given wIndex into a pointer to an driver endpoint |
943 | * structure, or return NULL if it is not a valid endpoint. | 964 | * structure, or return NULL if it is not a valid endpoint. |
944 | */ | 965 | */ |
945 | 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, |
946 | u32 windex) | 967 | u32 windex) |
947 | { | 968 | { |
@@ -1170,14 +1191,18 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1170 | ctrl->bRequest, ctrl->bRequestType, | 1191 | ctrl->bRequest, ctrl->bRequestType, |
1171 | ctrl->wValue, ctrl->wLength); | 1192 | ctrl->wValue, ctrl->wLength); |
1172 | 1193 | ||
1173 | /* record the direction of the request, for later use when enquing | 1194 | /* |
1174 | * packets onto EP0. */ | 1195 | * record the direction of the request, for later use when enquing |
1196 | * packets onto EP0. | ||
1197 | */ | ||
1175 | 1198 | ||
1176 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; | 1199 | ep0->dir_in = (ctrl->bRequestType & USB_DIR_IN) ? 1 : 0; |
1177 | 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); |
1178 | 1201 | ||
1179 | /* if we've no data with this request, then the last part of the | 1202 | /* |
1180 | * 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 | */ | ||
1181 | if (ctrl->wLength == 0) | 1206 | if (ctrl->wLength == 0) |
1182 | ep0->dir_in = 1; | 1207 | ep0->dir_in = 1; |
1183 | 1208 | ||
@@ -1213,7 +1238,8 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1213 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); | 1238 | dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret); |
1214 | } | 1239 | } |
1215 | 1240 | ||
1216 | /* the request is either unhandlable, or is not formatted correctly | 1241 | /* |
1242 | * the request is either unhandlable, or is not formatted correctly | ||
1217 | * 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. |
1218 | */ | 1244 | */ |
1219 | 1245 | ||
@@ -1224,8 +1250,10 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1224 | 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); |
1225 | reg = (ep0->dir_in) ? S3C_DIEPCTL0 : S3C_DOEPCTL0; | 1251 | reg = (ep0->dir_in) ? S3C_DIEPCTL0 : S3C_DOEPCTL0; |
1226 | 1252 | ||
1227 | /* S3C_DxEPCTL_Stall will be cleared by EP once it has | 1253 | /* |
1228 | * taken effect, so no need to clear later. */ | 1254 | * S3C_DxEPCTL_Stall will be cleared by EP once it has |
1255 | * taken effect, so no need to clear later. | ||
1256 | */ | ||
1229 | 1257 | ||
1230 | ctrl = readl(hsotg->regs + reg); | 1258 | ctrl = readl(hsotg->regs + reg); |
1231 | ctrl |= S3C_DxEPCTL_Stall; | 1259 | ctrl |= S3C_DxEPCTL_Stall; |
@@ -1236,8 +1264,10 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1236 | "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", | 1264 | "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", |
1237 | ctrl, reg, readl(hsotg->regs + reg)); | 1265 | ctrl, reg, readl(hsotg->regs + reg)); |
1238 | 1266 | ||
1239 | /* don't believe we need to anything more to get the EP | 1267 | /* |
1240 | * 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 | */ | ||
1241 | } | 1271 | } |
1242 | } | 1272 | } |
1243 | 1273 | ||
@@ -1298,8 +1328,10 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | |||
1298 | 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); |
1299 | if (ret < 0) { | 1329 | if (ret < 0) { |
1300 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); | 1330 | dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret); |
1301 | /* Don't think there's much we can do other than watch the | 1331 | /* |
1302 | * driver fail. */ | 1332 | * Don't think there's much we can do other than watch the |
1333 | * driver fail. | ||
1334 | */ | ||
1303 | } | 1335 | } |
1304 | } | 1336 | } |
1305 | 1337 | ||
@@ -1315,7 +1347,7 @@ static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg) | |||
1315 | * on the endpoint. | 1347 | * on the endpoint. |
1316 | * | 1348 | * |
1317 | * Note, expects the ep to already be locked as appropriate. | 1349 | * Note, expects the ep to already be locked as appropriate. |
1318 | */ | 1350 | */ |
1319 | static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | 1351 | static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, |
1320 | struct s3c_hsotg_ep *hs_ep, | 1352 | struct s3c_hsotg_ep *hs_ep, |
1321 | struct s3c_hsotg_req *hs_req, | 1353 | struct s3c_hsotg_req *hs_req, |
@@ -1331,8 +1363,10 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1331 | 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", |
1332 | 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); |
1333 | 1365 | ||
1334 | /* only replace the status if we've not already set an error | 1366 | /* |
1335 | * from a previous transaction */ | 1367 | * only replace the status if we've not already set an error |
1368 | * from a previous transaction | ||
1369 | */ | ||
1336 | 1370 | ||
1337 | if (hs_req->req.status == -EINPROGRESS) | 1371 | if (hs_req->req.status == -EINPROGRESS) |
1338 | hs_req->req.status = result; | 1372 | hs_req->req.status = result; |
@@ -1343,8 +1377,10 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1343 | if (using_dma(hsotg)) | 1377 | if (using_dma(hsotg)) |
1344 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); | 1378 | s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req); |
1345 | 1379 | ||
1346 | /* call the complete request with the locks off, just in case the | 1380 | /* |
1347 | * 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 | */ | ||
1348 | 1384 | ||
1349 | if (hs_req->req.complete) { | 1385 | if (hs_req->req.complete) { |
1350 | spin_unlock(&hs_ep->lock); | 1386 | spin_unlock(&hs_ep->lock); |
@@ -1352,9 +1388,11 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1352 | spin_lock(&hs_ep->lock); | 1388 | spin_lock(&hs_ep->lock); |
1353 | } | 1389 | } |
1354 | 1390 | ||
1355 | /* 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 | ||
1356 | * 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 |
1357 | * so be careful when doing this. */ | 1394 | * so be careful when doing this. |
1395 | */ | ||
1358 | 1396 | ||
1359 | if (!hs_ep->req && result >= 0) { | 1397 | if (!hs_ep->req && result >= 0) { |
1360 | restart = !list_empty(&hs_ep->queue); | 1398 | restart = !list_empty(&hs_ep->queue); |
@@ -1374,7 +1412,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1374 | * | 1412 | * |
1375 | * See s3c_hsotg_complete_request(), but called with the endpoint's | 1413 | * See s3c_hsotg_complete_request(), but called with the endpoint's |
1376 | * lock held. | 1414 | * lock held. |
1377 | */ | 1415 | */ |
1378 | static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg, | 1416 | static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg, |
1379 | struct s3c_hsotg_ep *hs_ep, | 1417 | struct s3c_hsotg_ep *hs_ep, |
1380 | struct s3c_hsotg_req *hs_req, | 1418 | struct s3c_hsotg_req *hs_req, |
@@ -1431,7 +1469,8 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1431 | __func__, to_read, max_req, read_ptr, hs_req->req.length); | 1469 | __func__, to_read, max_req, read_ptr, hs_req->req.length); |
1432 | 1470 | ||
1433 | if (to_read > max_req) { | 1471 | if (to_read > max_req) { |
1434 | /* more data appeared than we where willing | 1472 | /* |
1473 | * more data appeared than we where willing | ||
1435 | * to deal with in this request. | 1474 | * to deal with in this request. |
1436 | */ | 1475 | */ |
1437 | 1476 | ||
@@ -1443,8 +1482,10 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1443 | hs_req->req.actual += to_read; | 1482 | hs_req->req.actual += to_read; |
1444 | to_read = DIV_ROUND_UP(to_read, 4); | 1483 | to_read = DIV_ROUND_UP(to_read, 4); |
1445 | 1484 | ||
1446 | /* note, we might over-write the buffer end by 3 bytes depending on | 1485 | /* |
1447 | * alignment of the data. */ | 1486 | * note, we might over-write the buffer end by 3 bytes depending on |
1487 | * alignment of the data. | ||
1488 | */ | ||
1448 | readsl(fifo, hs_req->req.buf + read_ptr, to_read); | 1489 | readsl(fifo, hs_req->req.buf + read_ptr, to_read); |
1449 | 1490 | ||
1450 | spin_unlock(&hs_ep->lock); | 1491 | spin_unlock(&hs_ep->lock); |
@@ -1503,7 +1544,7 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1503 | * 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 |
1504 | * 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 |
1505 | * packet or by the finish of a transfer. | 1546 | * packet or by the finish of a transfer. |
1506 | */ | 1547 | */ |
1507 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | 1548 | static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, |
1508 | int epnum, bool was_setup) | 1549 | int epnum, bool was_setup) |
1509 | { | 1550 | { |
@@ -1522,7 +1563,8 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1522 | if (using_dma(hsotg)) { | 1563 | if (using_dma(hsotg)) { |
1523 | unsigned size_done; | 1564 | unsigned size_done; |
1524 | 1565 | ||
1525 | /* Calculate the size of the transfer by checking how much | 1566 | /* |
1567 | * Calculate the size of the transfer by checking how much | ||
1526 | * is left in the endpoint size register and then working it | 1568 | * is left in the endpoint size register and then working it |
1527 | * out from the amount we loaded for the transfer. | 1569 | * out from the amount we loaded for the transfer. |
1528 | * | 1570 | * |
@@ -1552,8 +1594,10 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1552 | 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", |
1553 | __func__, req->actual, req->length); | 1595 | __func__, req->actual, req->length); |
1554 | 1596 | ||
1555 | /* todo - what should we return here? there's no one else | 1597 | /* |
1556 | * 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 | */ | ||
1557 | } | 1601 | } |
1558 | 1602 | ||
1559 | if (epnum == 0) { | 1603 | if (epnum == 0) { |
@@ -1573,7 +1617,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1573 | * @hsotg: The device instance | 1617 | * @hsotg: The device instance |
1574 | * | 1618 | * |
1575 | * Return the current frame number | 1619 | * Return the current frame number |
1576 | */ | 1620 | */ |
1577 | static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) | 1621 | static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg) |
1578 | { | 1622 | { |
1579 | u32 dsts; | 1623 | u32 dsts; |
@@ -1667,7 +1711,7 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1667 | /** | 1711 | /** |
1668 | * s3c_hsotg_ep0_mps - turn max packet size into register setting | 1712 | * s3c_hsotg_ep0_mps - turn max packet size into register setting |
1669 | * @mps: The maximum packet size in bytes. | 1713 | * @mps: The maximum packet size in bytes. |
1670 | */ | 1714 | */ |
1671 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) | 1715 | static u32 s3c_hsotg_ep0_mps(unsigned int mps) |
1672 | { | 1716 | { |
1673 | switch (mps) { | 1717 | switch (mps) { |
@@ -1717,8 +1761,10 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1717 | 1761 | ||
1718 | hs_ep->ep.maxpacket = mps; | 1762 | hs_ep->ep.maxpacket = mps; |
1719 | 1763 | ||
1720 | /* update both the in and out endpoint controldir_ registers, even | 1764 | /* |
1721 | * 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 | */ | ||
1722 | 1768 | ||
1723 | reg = readl(regs + S3C_DIEPCTL(ep)); | 1769 | reg = readl(regs + S3C_DIEPCTL(ep)); |
1724 | reg &= ~S3C_DxEPCTL_MPS_MASK; | 1770 | reg &= ~S3C_DxEPCTL_MPS_MASK; |
@@ -1822,7 +1868,8 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1822 | return; | 1868 | return; |
1823 | } | 1869 | } |
1824 | 1870 | ||
1825 | /* Calculate the size of the transfer by checking how much is left | 1871 | /* |
1872 | * Calculate the size of the transfer by checking how much is left | ||
1826 | * in the endpoint size register and then working it out from | 1873 | * in the endpoint size register and then working it out from |
1827 | * the amount we loaded for the transfer. | 1874 | * the amount we loaded for the transfer. |
1828 | * | 1875 | * |
@@ -1878,7 +1925,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1878 | * @dir_in: Set if this is an IN endpoint | 1925 | * @dir_in: Set if this is an IN endpoint |
1879 | * | 1926 | * |
1880 | * Process and clear any interrupt pending for an individual endpoint | 1927 | * Process and clear any interrupt pending for an individual endpoint |
1881 | */ | 1928 | */ |
1882 | 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, |
1883 | int dir_in) | 1930 | int dir_in) |
1884 | { | 1931 | { |
@@ -1902,16 +1949,20 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1902 | __func__, readl(hsotg->regs + epctl_reg), | 1949 | __func__, readl(hsotg->regs + epctl_reg), |
1903 | readl(hsotg->regs + epsiz_reg)); | 1950 | readl(hsotg->regs + epsiz_reg)); |
1904 | 1951 | ||
1905 | /* we get OutDone from the FIFO, so we only need to look | 1952 | /* |
1906 | * 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 | */ | ||
1907 | if (dir_in) { | 1956 | if (dir_in) { |
1908 | s3c_hsotg_complete_in(hsotg, hs_ep); | 1957 | s3c_hsotg_complete_in(hsotg, hs_ep); |
1909 | 1958 | ||
1910 | if (idx == 0 && !hs_ep->req) | 1959 | if (idx == 0 && !hs_ep->req) |
1911 | s3c_hsotg_enqueue_setup(hsotg); | 1960 | s3c_hsotg_enqueue_setup(hsotg); |
1912 | } else if (using_dma(hsotg)) { | 1961 | } else if (using_dma(hsotg)) { |
1913 | /* We're using DMA, we need to fire an OutDone here | 1962 | /* |
1914 | * as we ignore the RXFIFO. */ | 1963 | * We're using DMA, we need to fire an OutDone here |
1964 | * as we ignore the RXFIFO. | ||
1965 | */ | ||
1915 | 1966 | ||
1916 | s3c_hsotg_handle_outdone(hsotg, idx, false); | 1967 | s3c_hsotg_handle_outdone(hsotg, idx, false); |
1917 | } | 1968 | } |
@@ -1942,10 +1993,12 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1942 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); | 1993 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); |
1943 | 1994 | ||
1944 | if (using_dma(hsotg) && idx == 0) { | 1995 | if (using_dma(hsotg) && idx == 0) { |
1945 | /* this is the notification we've received a | 1996 | /* |
1997 | * this is the notification we've received a | ||
1946 | * setup packet. In non-DMA mode we'd get this | 1998 | * setup packet. In non-DMA mode we'd get this |
1947 | * from the RXFIFO, instead we need to process | 1999 | * from the RXFIFO, instead we need to process |
1948 | * the setup here. */ | 2000 | * the setup here. |
2001 | */ | ||
1949 | 2002 | ||
1950 | if (dir_in) | 2003 | if (dir_in) |
1951 | WARN_ON_ONCE(1); | 2004 | WARN_ON_ONCE(1); |
@@ -1958,8 +2011,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1958 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); | 2011 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
1959 | 2012 | ||
1960 | if (dir_in) { | 2013 | if (dir_in) { |
1961 | /* 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 */ |
1962 | */ | ||
1963 | if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) { | 2015 | if (ints & S3C_DIEPMSK_INTknTXFEmpMsk) { |
1964 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", | 2016 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
1965 | __func__, idx); | 2017 | __func__, idx); |
@@ -1988,21 +2040,25 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1988 | * | 2040 | * |
1989 | * Handle updating the device settings after the enumeration phase has | 2041 | * Handle updating the device settings after the enumeration phase has |
1990 | * been completed. | 2042 | * been completed. |
1991 | */ | 2043 | */ |
1992 | static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | 2044 | static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) |
1993 | { | 2045 | { |
1994 | u32 dsts = readl(hsotg->regs + S3C_DSTS); | 2046 | u32 dsts = readl(hsotg->regs + S3C_DSTS); |
1995 | int ep0_mps = 0, ep_mps; | 2047 | int ep0_mps = 0, ep_mps; |
1996 | 2048 | ||
1997 | /* This should signal the finish of the enumeration phase | 2049 | /* |
2050 | * This should signal the finish of the enumeration phase | ||
1998 | * of the USB handshaking, so we should now know what rate | 2051 | * of the USB handshaking, so we should now know what rate |
1999 | * we connected at. */ | 2052 | * we connected at. |
2053 | */ | ||
2000 | 2054 | ||
2001 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); | 2055 | dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts); |
2002 | 2056 | ||
2003 | /* 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 | ||
2004 | * 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 |
2005 | * not advertise a 64byte MPS on EP0. */ | 2060 | * not advertise a 64byte MPS on EP0. |
2061 | */ | ||
2006 | 2062 | ||
2007 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ | 2063 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ |
2008 | switch (dsts & S3C_DSTS_EnumSpd_MASK) { | 2064 | switch (dsts & S3C_DSTS_EnumSpd_MASK) { |
@@ -2021,7 +2077,8 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
2021 | 2077 | ||
2022 | case S3C_DSTS_EnumSpd_LS: | 2078 | case S3C_DSTS_EnumSpd_LS: |
2023 | hsotg->gadget.speed = USB_SPEED_LOW; | 2079 | hsotg->gadget.speed = USB_SPEED_LOW; |
2024 | /* 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 | ||
2025 | * moment, and the documentation seems to imply that it isn't | 2082 | * moment, and the documentation seems to imply that it isn't |
2026 | * supported by the PHYs on some of the devices. | 2083 | * supported by the PHYs on some of the devices. |
2027 | */ | 2084 | */ |
@@ -2030,8 +2087,10 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
2030 | dev_info(hsotg->dev, "new device is %s\n", | 2087 | dev_info(hsotg->dev, "new device is %s\n", |
2031 | usb_speed_string(hsotg->gadget.speed)); | 2088 | usb_speed_string(hsotg->gadget.speed)); |
2032 | 2089 | ||
2033 | /* we should now know the maximum packet size for an | 2090 | /* |
2034 | * 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 | */ | ||
2035 | 2094 | ||
2036 | if (ep0_mps) { | 2095 | if (ep0_mps) { |
2037 | int i; | 2096 | int i; |
@@ -2069,8 +2128,10 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2069 | spin_lock_irqsave(&ep->lock, flags); | 2128 | spin_lock_irqsave(&ep->lock, flags); |
2070 | 2129 | ||
2071 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { | 2130 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
2072 | /* currently, we can't do much about an already | 2131 | /* |
2073 | * running request on an in endpoint */ | 2132 | * currently, we can't do much about an already |
2133 | * running request on an in endpoint | ||
2134 | */ | ||
2074 | 2135 | ||
2075 | if (ep->req == req && ep->dir_in && !force) | 2136 | if (ep->req == req && ep->dir_in && !force) |
2076 | continue; | 2137 | continue; |
@@ -2094,7 +2155,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2094 | * The device has been disconnected. Remove all current | 2155 | * The device has been disconnected. Remove all current |
2095 | * transactions and signal the gadget driver that this | 2156 | * transactions and signal the gadget driver that this |
2096 | * has happened. | 2157 | * has happened. |
2097 | */ | 2158 | */ |
2098 | static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) | 2159 | static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) |
2099 | { | 2160 | { |
2100 | unsigned ep; | 2161 | unsigned ep; |
@@ -2145,7 +2206,7 @@ static struct s3c_hsotg *our_hsotg; | |||
2145 | * @hsotg: The device state | 2206 | * @hsotg: The device state |
2146 | * | 2207 | * |
2147 | * Issue a soft reset to the core, and await the core finishing it. | 2208 | * Issue a soft reset to the core, and await the core finishing it. |
2148 | */ | 2209 | */ |
2149 | static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | 2210 | static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) |
2150 | { | 2211 | { |
2151 | int timeout; | 2212 | int timeout; |
@@ -2188,6 +2249,12 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2188 | return 0; | 2249 | return 0; |
2189 | } | 2250 | } |
2190 | 2251 | ||
2252 | /** | ||
2253 | * s3c_hsotg_core_init - issue softreset to the core | ||
2254 | * @hsotg: The device state | ||
2255 | * | ||
2256 | * Issue a soft reset to the core, and await the core finishing it. | ||
2257 | */ | ||
2191 | static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | 2258 | static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) |
2192 | { | 2259 | { |
2193 | s3c_hsotg_corereset(hsotg); | 2260 | s3c_hsotg_corereset(hsotg); |
@@ -2406,9 +2473,11 @@ irq_retry: | |||
2406 | if (gintsts & S3C_GINTSTS_NPTxFEmp) { | 2473 | if (gintsts & S3C_GINTSTS_NPTxFEmp) { |
2407 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); | 2474 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); |
2408 | 2475 | ||
2409 | /* Disable the interrupt to stop it happening again | 2476 | /* |
2477 | * Disable the interrupt to stop it happening again | ||
2410 | * unless one of these endpoint routines decides that | 2478 | * unless one of these endpoint routines decides that |
2411 | * it needs re-enabling */ | 2479 | * it needs re-enabling |
2480 | */ | ||
2412 | 2481 | ||
2413 | s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp); | 2482 | s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp); |
2414 | s3c_hsotg_irq_fifoempty(hsotg, false); | 2483 | s3c_hsotg_irq_fifoempty(hsotg, false); |
@@ -2424,9 +2493,11 @@ irq_retry: | |||
2424 | } | 2493 | } |
2425 | 2494 | ||
2426 | if (gintsts & S3C_GINTSTS_RxFLvl) { | 2495 | if (gintsts & S3C_GINTSTS_RxFLvl) { |
2427 | /* note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, | 2496 | /* |
2497 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, | ||
2428 | * we need to retry s3c_hsotg_handle_rx if this is still | 2498 | * we need to retry s3c_hsotg_handle_rx if this is still |
2429 | * set. */ | 2499 | * set. |
2500 | */ | ||
2430 | 2501 | ||
2431 | s3c_hsotg_handle_rx(hsotg); | 2502 | s3c_hsotg_handle_rx(hsotg); |
2432 | } | 2503 | } |
@@ -2458,9 +2529,11 @@ irq_retry: | |||
2458 | s3c_hsotg_disconnect(hsotg); | 2529 | s3c_hsotg_disconnect(hsotg); |
2459 | } | 2530 | } |
2460 | 2531 | ||
2461 | /* these next two seem to crop-up occasionally causing the core | 2532 | /* |
2533 | * these next two seem to crop-up occasionally causing the core | ||
2462 | * to shutdown the USB transfer, so try clearing them and logging | 2534 | * to shutdown the USB transfer, so try clearing them and logging |
2463 | * the occurrence. */ | 2535 | * the occurrence. |
2536 | */ | ||
2464 | 2537 | ||
2465 | if (gintsts & S3C_GINTSTS_GOUTNakEff) { | 2538 | if (gintsts & S3C_GINTSTS_GOUTNakEff) { |
2466 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); | 2539 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); |
@@ -2478,8 +2551,10 @@ irq_retry: | |||
2478 | s3c_hsotg_dump(hsotg); | 2551 | s3c_hsotg_dump(hsotg); |
2479 | } | 2552 | } |
2480 | 2553 | ||
2481 | /* if we've had fifo events, we should try and go around the | 2554 | /* |
2482 | * loop again to see if there's any point in returning yet. */ | 2555 | * if we've had fifo events, we should try and go around the |
2556 | * loop again to see if there's any point in returning yet. | ||
2557 | */ | ||
2483 | 2558 | ||
2484 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) | 2559 | if (gintsts & IRQ_RETRY_MASK && --retry_count > 0) |
2485 | goto irq_retry; | 2560 | goto irq_retry; |
@@ -2493,7 +2568,7 @@ irq_retry: | |||
2493 | * @desc: The USB endpoint descriptor to configure with. | 2568 | * @desc: The USB endpoint descriptor to configure with. |
2494 | * | 2569 | * |
2495 | * This is called from the USB gadget code's usb_ep_enable(). | 2570 | * This is called from the USB gadget code's usb_ep_enable(). |
2496 | */ | 2571 | */ |
2497 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, | 2572 | static int s3c_hsotg_ep_enable(struct usb_ep *ep, |
2498 | const struct usb_endpoint_descriptor *desc) | 2573 | const struct usb_endpoint_descriptor *desc) |
2499 | { | 2574 | { |
@@ -2536,11 +2611,14 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2536 | epctrl &= ~(S3C_DxEPCTL_EPType_MASK | S3C_DxEPCTL_MPS_MASK); | 2611 | epctrl &= ~(S3C_DxEPCTL_EPType_MASK | S3C_DxEPCTL_MPS_MASK); |
2537 | epctrl |= S3C_DxEPCTL_MPS(mps); | 2612 | epctrl |= S3C_DxEPCTL_MPS(mps); |
2538 | 2613 | ||
2539 | /* mark the endpoint as active, otherwise the core may ignore | 2614 | /* |
2540 | * transactions entirely for this endpoint */ | 2615 | * mark the endpoint as active, otherwise the core may ignore |
2616 | * transactions entirely for this endpoint | ||
2617 | */ | ||
2541 | epctrl |= S3C_DxEPCTL_USBActEp; | 2618 | epctrl |= S3C_DxEPCTL_USBActEp; |
2542 | 2619 | ||
2543 | /* set the NAK status on the endpoint, otherwise we might try and | 2620 | /* |
2621 | * set the NAK status on the endpoint, otherwise we might try and | ||
2544 | * do something with data that we've yet got a request to process | 2622 | * do something with data that we've yet got a request to process |
2545 | * since the RXFIFO will take data for an endpoint even if the | 2623 | * since the RXFIFO will take data for an endpoint even if the |
2546 | * size register hasn't been set. | 2624 | * size register hasn't been set. |
@@ -2566,10 +2644,12 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2566 | 2644 | ||
2567 | case USB_ENDPOINT_XFER_INT: | 2645 | case USB_ENDPOINT_XFER_INT: |
2568 | if (dir_in) { | 2646 | if (dir_in) { |
2569 | /* Allocate our TxFNum by simply using the index | 2647 | /* |
2648 | * Allocate our TxFNum by simply using the index | ||
2570 | * of the endpoint for the moment. We could do | 2649 | * of the endpoint for the moment. We could do |
2571 | * something better if the host indicates how | 2650 | * something better if the host indicates how |
2572 | * many FIFOs we are expecting to use. */ | 2651 | * many FIFOs we are expecting to use. |
2652 | */ | ||
2573 | 2653 | ||
2574 | hs_ep->periodic = 1; | 2654 | hs_ep->periodic = 1; |
2575 | epctrl |= S3C_DxEPCTL_TxFNum(index); | 2655 | epctrl |= S3C_DxEPCTL_TxFNum(index); |
@@ -2583,7 +2663,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2583 | break; | 2663 | break; |
2584 | } | 2664 | } |
2585 | 2665 | ||
2586 | /* if the hardware has dedicated fifos, we must give each IN EP | 2666 | /* |
2667 | * if the hardware has dedicated fifos, we must give each IN EP | ||
2587 | * a unique tx-fifo even if it is non-periodic. | 2668 | * a unique tx-fifo even if it is non-periodic. |
2588 | */ | 2669 | */ |
2589 | if (dir_in && hsotg->dedicated_fifos) | 2670 | if (dir_in && hsotg->dedicated_fifos) |
@@ -2608,6 +2689,10 @@ out: | |||
2608 | return ret; | 2689 | return ret; |
2609 | } | 2690 | } |
2610 | 2691 | ||
2692 | /** | ||
2693 | * s3c_hsotg_ep_disable - disable given endpoint | ||
2694 | * @ep: The endpoint to disable. | ||
2695 | */ | ||
2611 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) | 2696 | static int s3c_hsotg_ep_disable(struct usb_ep *ep) |
2612 | { | 2697 | { |
2613 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2698 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
@@ -2651,7 +2736,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2651 | * on_list - check request is on the given endpoint | 2736 | * on_list - check request is on the given endpoint |
2652 | * @ep: The endpoint to check. | 2737 | * @ep: The endpoint to check. |
2653 | * @test: The request to test if it is on the endpoint. | 2738 | * @test: The request to test if it is on the endpoint. |
2654 | */ | 2739 | */ |
2655 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) | 2740 | static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) |
2656 | { | 2741 | { |
2657 | struct s3c_hsotg_req *req, *treq; | 2742 | struct s3c_hsotg_req *req, *treq; |
@@ -2664,6 +2749,11 @@ static bool on_list(struct s3c_hsotg_ep *ep, struct s3c_hsotg_req *test) | |||
2664 | return false; | 2749 | return false; |
2665 | } | 2750 | } |
2666 | 2751 | ||
2752 | /** | ||
2753 | * s3c_hsotg_ep_dequeue - dequeue given endpoint | ||
2754 | * @ep: The endpoint to dequeue. | ||
2755 | * @req: The request to be removed from a queue. | ||
2756 | */ | ||
2667 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | 2757 | static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) |
2668 | { | 2758 | { |
2669 | struct s3c_hsotg_req *hs_req = our_req(req); | 2759 | struct s3c_hsotg_req *hs_req = our_req(req); |
@@ -2686,6 +2776,11 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2686 | return 0; | 2776 | return 0; |
2687 | } | 2777 | } |
2688 | 2778 | ||
2779 | /** | ||
2780 | * s3c_hsotg_ep_sethalt - set halt on a given endpoint | ||
2781 | * @ep: The endpoint to set halt. | ||
2782 | * @value: Set or unset the halt. | ||
2783 | */ | ||
2689 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | 2784 | static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) |
2690 | { | 2785 | { |
2691 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); | 2786 | struct s3c_hsotg_ep *hs_ep = our_ep(ep); |
@@ -2752,8 +2847,7 @@ static struct usb_ep_ops s3c_hsotg_ep_ops = { | |||
2752 | 2847 | ||
2753 | /** | 2848 | /** |
2754 | * s3c_hsotg_phy_enable - enable platform phy dev | 2849 | * s3c_hsotg_phy_enable - enable platform phy dev |
2755 | * | 2850 | * @hsotg: The driver state |
2756 | * @param: The driver state | ||
2757 | * | 2851 | * |
2758 | * A wrapper for platform code responsible for controlling | 2852 | * A wrapper for platform code responsible for controlling |
2759 | * low-level USB code | 2853 | * low-level USB code |
@@ -2769,8 +2863,7 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg) | |||
2769 | 2863 | ||
2770 | /** | 2864 | /** |
2771 | * s3c_hsotg_phy_disable - disable platform phy dev | 2865 | * s3c_hsotg_phy_disable - disable platform phy dev |
2772 | * | 2866 | * @hsotg: The driver state |
2773 | * @param: The driver state | ||
2774 | * | 2867 | * |
2775 | * A wrapper for platform code responsible for controlling | 2868 | * A wrapper for platform code responsible for controlling |
2776 | * low-level USB code | 2869 | * low-level USB code |
@@ -2783,6 +2876,10 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg) | |||
2783 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); | 2876 | hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); |
2784 | } | 2877 | } |
2785 | 2878 | ||
2879 | /** | ||
2880 | * s3c_hsotg_init - initalize the usb core | ||
2881 | * @hsotg: The driver state | ||
2882 | */ | ||
2786 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | 2883 | static void s3c_hsotg_init(struct s3c_hsotg *hsotg) |
2787 | { | 2884 | { |
2788 | /* unmask subset of endpoint interrupts */ | 2885 | /* unmask subset of endpoint interrupts */ |
@@ -2822,6 +2919,14 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2822 | hsotg->regs + S3C_GAHBCFG); | 2919 | hsotg->regs + S3C_GAHBCFG); |
2823 | } | 2920 | } |
2824 | 2921 | ||
2922 | /** | ||
2923 | * s3c_hsotg_udc_start - prepare the udc for work | ||
2924 | * @gadget: The usb gadget state | ||
2925 | * @driver: The usb gadget driver | ||
2926 | * | ||
2927 | * Perform initialization to prepare udc device and driver | ||
2928 | * to work. | ||
2929 | */ | ||
2825 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | 2930 | static int s3c_hsotg_udc_start(struct usb_gadget *gadget, |
2826 | struct usb_gadget_driver *driver) | 2931 | struct usb_gadget_driver *driver) |
2827 | { | 2932 | { |
@@ -2874,6 +2979,13 @@ err: | |||
2874 | return ret; | 2979 | return ret; |
2875 | } | 2980 | } |
2876 | 2981 | ||
2982 | /** | ||
2983 | * s3c_hsotg_udc_stop - stop the udc | ||
2984 | * @gadget: The usb gadget state | ||
2985 | * @driver: The usb gadget driver | ||
2986 | * | ||
2987 | * Stop udc hw block and stay tunned for future transmissions | ||
2988 | */ | ||
2877 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | 2989 | static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, |
2878 | struct usb_gadget_driver *driver) | 2990 | struct usb_gadget_driver *driver) |
2879 | { | 2991 | { |
@@ -2903,6 +3015,12 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | |||
2903 | return 0; | 3015 | return 0; |
2904 | } | 3016 | } |
2905 | 3017 | ||
3018 | /** | ||
3019 | * s3c_hsotg_gadget_getframe - read the frame number | ||
3020 | * @gadget: The usb gadget state | ||
3021 | * | ||
3022 | * Read the {micro} frame number | ||
3023 | */ | ||
2906 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) | 3024 | static int s3c_hsotg_gadget_getframe(struct usb_gadget *gadget) |
2907 | { | 3025 | { |
2908 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); | 3026 | return s3c_hsotg_read_frameno(to_hsotg(gadget)); |
@@ -2958,7 +3076,8 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2958 | hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; | 3076 | hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; |
2959 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3077 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
2960 | 3078 | ||
2961 | /* Read the FIFO size for the Periodic TX FIFO, even if we're | 3079 | /* |
3080 | * Read the FIFO size for the Periodic TX FIFO, even if we're | ||
2962 | * an OUT endpoint, we may as well do this if in future the | 3081 | * an OUT endpoint, we may as well do this if in future the |
2963 | * code is changed to make each endpoint's direction changeable. | 3082 | * code is changed to make each endpoint's direction changeable. |
2964 | */ | 3083 | */ |
@@ -2966,7 +3085,8 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2966 | ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); | 3085 | ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); |
2967 | hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; | 3086 | hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; |
2968 | 3087 | ||
2969 | /* if we're using dma, we need to set the next-endpoint pointer | 3088 | /* |
3089 | * if we're using dma, we need to set the next-endpoint pointer | ||
2970 | * to be something valid. | 3090 | * to be something valid. |
2971 | */ | 3091 | */ |
2972 | 3092 | ||
@@ -2998,9 +3118,12 @@ static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) | |||
2998 | 3118 | ||
2999 | dev_info(hsotg->dev, "%s fifos\n", | 3119 | dev_info(hsotg->dev, "%s fifos\n", |
3000 | hsotg->dedicated_fifos ? "dedicated" : "shared"); | 3120 | hsotg->dedicated_fifos ? "dedicated" : "shared"); |
3001 | |||
3002 | } | 3121 | } |
3003 | 3122 | ||
3123 | /** | ||
3124 | * s3c_hsotg_dump - dump state of the udc | ||
3125 | * @param: The device state | ||
3126 | */ | ||
3004 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | 3127 | static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) |
3005 | { | 3128 | { |
3006 | #ifdef DEBUG | 3129 | #ifdef DEBUG |
@@ -3049,7 +3172,6 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | |||
3049 | #endif | 3172 | #endif |
3050 | } | 3173 | } |
3051 | 3174 | ||
3052 | |||
3053 | /** | 3175 | /** |
3054 | * state_show - debugfs: show overall driver and device state. | 3176 | * state_show - debugfs: show overall driver and device state. |
3055 | * @seq: The seq file to write to. | 3177 | * @seq: The seq file to write to. |
@@ -3128,7 +3250,7 @@ static const struct file_operations state_fops = { | |||
3128 | * | 3250 | * |
3129 | * Show the FIFO information for the overall fifo and all the | 3251 | * Show the FIFO information for the overall fifo and all the |
3130 | * periodic transmission FIFOs. | 3252 | * periodic transmission FIFOs. |
3131 | */ | 3253 | */ |
3132 | static int fifo_show(struct seq_file *seq, void *v) | 3254 | static int fifo_show(struct seq_file *seq, void *v) |
3133 | { | 3255 | { |
3134 | struct s3c_hsotg *hsotg = seq->private; | 3256 | struct s3c_hsotg *hsotg = seq->private; |
@@ -3183,7 +3305,7 @@ static const char *decode_direction(int is_in) | |||
3183 | * | 3305 | * |
3184 | * This debugfs entry shows the state of the given endpoint (one is | 3306 | * This debugfs entry shows the state of the given endpoint (one is |
3185 | * registered for each available). | 3307 | * registered for each available). |
3186 | */ | 3308 | */ |
3187 | static int ep_show(struct seq_file *seq, void *v) | 3309 | static int ep_show(struct seq_file *seq, void *v) |
3188 | { | 3310 | { |
3189 | struct s3c_hsotg_ep *ep = seq->private; | 3311 | struct s3c_hsotg_ep *ep = seq->private; |
@@ -3263,7 +3385,7 @@ static const struct file_operations ep_fops = { | |||
3263 | * about the state of the system. The directory name is created | 3385 | * about the state of the system. The directory name is created |
3264 | * with the same name as the device itself, in case we end up | 3386 | * with the same name as the device itself, in case we end up |
3265 | * with multiple blocks in future systems. | 3387 | * with multiple blocks in future systems. |
3266 | */ | 3388 | */ |
3267 | static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | 3389 | static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) |
3268 | { | 3390 | { |
3269 | struct dentry *root; | 3391 | struct dentry *root; |
@@ -3309,7 +3431,7 @@ static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg) | |||
3309 | * @hsotg: The driver state | 3431 | * @hsotg: The driver state |
3310 | * | 3432 | * |
3311 | * Cleanup (remove) the debugfs files for use on module exit. | 3433 | * Cleanup (remove) the debugfs files for use on module exit. |
3312 | */ | 3434 | */ |
3313 | static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | 3435 | static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) |
3314 | { | 3436 | { |
3315 | unsigned epidx; | 3437 | unsigned epidx; |
@@ -3324,6 +3446,10 @@ static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg) | |||
3324 | debugfs_remove(hsotg->debug_root); | 3446 | debugfs_remove(hsotg->debug_root); |
3325 | } | 3447 | } |
3326 | 3448 | ||
3449 | /** | ||
3450 | * s3c_hsotg_probe - probe function for hsotg driver | ||
3451 | * @pdev: The platform information for the driver | ||
3452 | */ | ||
3327 | static int __devinit s3c_hsotg_probe(struct platform_device *pdev) | 3453 | static int __devinit s3c_hsotg_probe(struct platform_device *pdev) |
3328 | { | 3454 | { |
3329 | struct s3c_hsotg_plat *plat = pdev->dev.platform_data; | 3455 | struct s3c_hsotg_plat *plat = pdev->dev.platform_data; |
@@ -3525,6 +3651,10 @@ err_mem: | |||
3525 | return ret; | 3651 | return ret; |
3526 | } | 3652 | } |
3527 | 3653 | ||
3654 | /** | ||
3655 | * s3c_hsotg_remove - remove function for hsotg driver | ||
3656 | * @pdev: The platform information for the driver | ||
3657 | */ | ||
3528 | static int __devexit s3c_hsotg_remove(struct platform_device *pdev) | 3658 | static int __devexit s3c_hsotg_remove(struct platform_device *pdev) |
3529 | { | 3659 | { |
3530 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); | 3660 | struct s3c_hsotg *hsotg = platform_get_drvdata(pdev); |