Lines Matching defs:hsotg
1 /* linux/drivers/usb/gadget/s3c-hsotg.c
33 #include <plat/regs-usb-hsotg-phy.h>
34 #include <plat/regs-usb-hsotg.h>
211 static void s3c_hsotg_dump(struct s3c_hsotg *hsotg);
215 * @hsotg: The driver state.
232 static inline bool using_dma(struct s3c_hsotg *hsotg)
239 * @hsotg: The device state
242 static void s3c_hsotg_en_gsint(struct s3c_hsotg *hsotg, u32 ints)
244 u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK);
250 dev_dbg(hsotg->dev, "gsintmsk now 0x%08x\n", new_gsintmsk);
251 writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK);
257 * @hsotg: The device state
260 static void s3c_hsotg_disable_gsint(struct s3c_hsotg *hsotg, u32 ints)
262 u32 gsintmsk = readl(hsotg->regs + S3C_GINTMSK);
268 writel(new_gsintmsk, hsotg->regs + S3C_GINTMSK);
273 * @hsotg: The device state
281 static void s3c_hsotg_ctrl_epint(struct s3c_hsotg *hsotg,
293 daint = readl(hsotg->regs + S3C_DAINTMSK);
298 writel(daint, hsotg->regs + S3C_DAINTMSK);
304 * @hsotg: The device instance.
306 static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
315 writel(0x1C0, hsotg->regs + S3C_GRXFSIZ);
318 hsotg->regs + S3C_GNPTXFSIZ);
323 writel(2048, hsotg->regs + S3C_GRXFSIZ);
326 hsotg->regs + S3C_GNPTXFSIZ);
345 writel(val, hsotg->regs + S3C_DPTXFSIZn(ep));
352 S3C_GRSTCTL_RxFFlsh, hsotg->regs + S3C_GRSTCTL);
357 val = readl(hsotg->regs + S3C_GRSTCTL);
363 dev_err(hsotg->dev,
371 dev_dbg(hsotg->dev, "FIFOs reset, timeout at %d\n", timeout);
409 * @hsotg: The device state.
416 static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg,
432 dma_unmap_single(hsotg->dev, req->dma, req->length, dir);
437 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
443 * @hsotg: The controller state.
457 static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
462 u32 gnptxsts = readl(hsotg->regs + S3C_GNPTXSTS);
475 if (periodic && !hsotg->dedicated_fifos) {
476 u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index));
489 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
493 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n",
502 dev_dbg(hsotg->dev, "%s: => can_write1=%d\n",
506 dev_dbg(hsotg->dev, "%s: => can_write2=%d\n",
510 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
513 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) {
514 can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index));
520 dev_dbg(hsotg->dev,
524 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_NPTxFEmp);
532 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n",
548 s3c_hsotg_en_gsint(hsotg,
573 s3c_hsotg_en_gsint(hsotg,
578 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n",
593 writesl(hsotg->regs + S3C_EPFIFO(hs_ep->index), data, to_write);
638 * @hsotg: The controller state.
646 static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
664 dev_err(hsotg->dev, "%s: active request\n", __func__);
668 dev_err(hsotg->dev,
678 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x, ep %d, dir %s\n",
679 __func__, readl(hsotg->regs + epctrl_reg), index,
685 dev_dbg(hsotg->dev,
694 dev_dbg(hsotg->dev, "%s: length %d, max-req %d, r %d\n",
725 dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n",
732 writel(epsize, hsotg->regs + epsize_reg);
734 ctrl = readl(hsotg->regs + epctrl_reg);
737 dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index);
746 if (using_dma(hsotg)) {
753 writel(ureq->dma, hsotg->regs + dma_reg);
755 dev_dbg(hsotg->dev, "%s: 0x%08x => 0x%08x\n",
763 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl);
764 writel(ctrl, hsotg->regs + epctrl_reg);
772 if (dir_in && !using_dma(hsotg)) {
776 s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
783 hsotg->regs + S3C_DIEPINT(index));
789 if (!(readl(hsotg->regs + epctrl_reg) & S3C_DxEPCTL_EPEna))
790 dev_warn(hsotg->dev,
792 index, readl(hsotg->regs + epctrl_reg));
794 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n",
795 __func__, readl(hsotg->regs + epctrl_reg));
800 * @hsotg: The device state.
810 static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg,
826 dma = dma_map_single(hsotg->dev, req->buf, req->length, dir);
828 if (unlikely(dma_mapping_error(hsotg->dev, dma)))
832 dev_err(hsotg->dev, "%s: unaligned dma buffer\n",
835 dma_unmap_single(hsotg->dev, dma, req->length, dir);
842 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
849 dev_err(hsotg->dev, "%s: failed to map buffer %p, %d bytes\n",
913 struct s3c_hsotg *hsotg = hs_ep->parent;
915 dev_dbg(hsotg->dev, "%s: ep %p, req %p\n", __func__, ep, req);
922 * @hsotg: The driver state.
928 static struct s3c_hsotg_ep *ep_from_windex(struct s3c_hsotg *hsotg,
931 struct s3c_hsotg_ep *ep = &hsotg->eps[windex & 0x7F];
949 * @hsotg: The device state
957 static int s3c_hsotg_send_reply(struct s3c_hsotg *hsotg,
965 dev_dbg(hsotg->dev, "%s: buff %p, len %d\n", __func__, buff, length);
968 hsotg->ep0_reply = req;
970 dev_warn(hsotg->dev, "%s: cannot alloc req\n", __func__);
974 req->buf = hsotg->ep0_buff;
986 dev_warn(hsotg->dev, "%s: cannot queue req\n", __func__);
995 * @hsotg: The device state
998 static int s3c_hsotg_process_req_status(struct s3c_hsotg *hsotg,
1001 struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
1006 dev_dbg(hsotg->dev, "%s: USB_REQ_GET_STATUS\n", __func__);
1009 dev_warn(hsotg->dev, "%s: direction out?\n", __func__);
1025 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex));
1039 ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2);
1041 dev_err(hsotg->dev, "%s: failed to send reply\n", __func__);
1052 * @hsotg: The device state
1055 static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1061 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n",
1065 ep = ep_from_windex(hsotg, le16_to_cpu(ctrl->wIndex));
1067 dev_dbg(hsotg->dev, "%s: no endpoint for 0x%04x\n",
1088 * @hsotg: The device state
1095 static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
1098 struct s3c_hsotg_ep *ep0 = &hsotg->eps[0];
1104 dev_dbg(hsotg->dev, "ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n",
1112 dev_dbg(hsotg->dev, "ctrl: dir_in=%d\n", ep0->dir_in);
1122 dcfg = readl(hsotg->regs + S3C_DCFG);
1125 writel(dcfg, hsotg->regs + S3C_DCFG);
1127 dev_info(hsotg->dev, "new address %d\n", ctrl->wValue);
1129 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
1133 ret = s3c_hsotg_process_req_status(hsotg, ctrl);
1138 ret = s3c_hsotg_process_req_feature(hsotg, ctrl);
1145 if (ret == 0 && hsotg->driver) {
1146 ret = hsotg->driver->setup(&hsotg->gadget, ctrl);
1148 dev_dbg(hsotg->dev, "driver->setup() ret %d\n", ret);
1155 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
1167 dev_dbg(hsotg->dev, "ep0 stall (dir=%d)\n", ep0->dir_in);
1173 ctrl = readl(hsotg->regs + reg);
1176 writel(ctrl, hsotg->regs + reg);
1178 dev_dbg(hsotg->dev,
1180 ctrl, reg, readl(hsotg->regs + reg));
1187 static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
1201 struct s3c_hsotg *hsotg = hs_ep->parent;
1204 dev_dbg(hsotg->dev, "%s: failed %d\n", __func__, req->status);
1209 s3c_hsotg_enqueue_setup(hsotg);
1211 s3c_hsotg_process_control(hsotg, req->buf);
1216 * @hsotg: The device state.
1221 static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg)
1223 struct usb_request *req = hsotg->ctrl_req;
1227 dev_dbg(hsotg->dev, "%s: queueing setup request\n", __func__);
1231 req->buf = hsotg->ctrl_buff;
1235 dev_dbg(hsotg->dev, "%s already queued???\n", __func__);
1239 hsotg->eps[0].dir_in = 0;
1241 ret = s3c_hsotg_ep_queue(&hsotg->eps[0].ep, req, GFP_ATOMIC);
1243 dev_err(hsotg->dev, "%s: failed queue (%d)\n", __func__, ret);
1265 * @hsotg: The device state.
1276 static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg,
1284 dev_dbg(hsotg->dev, "%s: nothing to complete?\n", __func__);
1288 dev_dbg(hsotg->dev, "complete: ep %p %s, req %p, %d => %p\n",
1300 if (using_dma(hsotg))
1301 s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req);
1320 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, false);
1327 * @hsotg: The device state.
1335 static void s3c_hsotg_complete_request_lock(struct s3c_hsotg *hsotg,
1343 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result);
1349 * @hsotg: The device state.
1357 static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1359 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep_idx];
1361 void __iomem *fifo = hsotg->regs + S3C_EPFIFO(ep_idx);
1367 u32 epctl = readl(hsotg->regs + S3C_DOEPCTL(ep_idx));
1370 dev_warn(hsotg->dev,
1387 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n",
1412 * @hsotg: The device instance
1422 static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg,
1428 dev_warn(hsotg->dev, "%s: no request?\n", __func__);
1433 hsotg->eps[0].sent_zlp = 1;
1434 s3c_hsotg_enqueue_setup(hsotg);
1438 hsotg->eps[0].dir_in = 1;
1439 hsotg->eps[0].sent_zlp = 1;
1441 dev_dbg(hsotg->dev, "sending zero-length packet\n");
1445 S3C_DxEPTSIZ_XferSize(0), hsotg->regs + S3C_DIEPTSIZ(0));
1447 ctrl = readl(hsotg->regs + S3C_DIEPCTL0);
1451 writel(ctrl, hsotg->regs + S3C_DIEPCTL0);
1456 * @hsotg: The device instance
1464 static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
1467 u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum));
1468 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum];
1475 dev_dbg(hsotg->dev, "%s: no request active\n", __func__);
1479 if (using_dma(hsotg)) {
1498 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
1503 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n",
1512 s3c_hsotg_send_zlp(hsotg, hs_req);
1515 s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, result);
1520 * @hsotg: The device instance
1524 static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg)
1528 dsts = readl(hsotg->regs + S3C_DSTS);
1537 * @hsotg: The device instance
1551 static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg)
1553 u32 grxstsr = readl(hsotg->regs + S3C_GRXSTSP);
1556 WARN_ON(using_dma(hsotg));
1565 dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n",
1572 dev_dbg(hsotg->dev, "GlobalOutNAK\n");
1576 dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n",
1577 s3c_hsotg_read_frameno(hsotg));
1579 if (!using_dma(hsotg))
1580 s3c_hsotg_handle_outdone(hsotg, epnum, false);
1584 dev_dbg(hsotg->dev,
1586 s3c_hsotg_read_frameno(hsotg),
1587 readl(hsotg->regs + S3C_DOEPCTL(0)));
1589 s3c_hsotg_handle_outdone(hsotg, epnum, true);
1593 s3c_hsotg_rx_data(hsotg, epnum, size);
1597 dev_dbg(hsotg->dev,
1599 s3c_hsotg_read_frameno(hsotg),
1600 readl(hsotg->regs + S3C_DOEPCTL(0)));
1602 s3c_hsotg_rx_data(hsotg, epnum, size);
1606 dev_warn(hsotg->dev, "%s: unknown status %08x\n",
1609 s3c_hsotg_dump(hsotg);
1638 * @hsotg: The driver state.
1645 static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1648 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep];
1649 void __iomem *regs = hsotg->regs;
1683 dev_err(hsotg->dev, "ep%d: bad mps of %d\n", ep, mps);
1689 * @hsotg: The driver state
1695 static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg,
1704 dev_dbg(hsotg->dev, "trying to write more for ep%d\n",
1706 return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
1714 * @hsotg: The device state.
1720 static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg,
1724 u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index));
1728 dev_dbg(hsotg->dev, "XferCompl but no req\n");
1747 dev_dbg(hsotg->dev, "%s: adjusting size done %d => %d\n",
1756 dev_dbg(hsotg->dev, "%s trying more for req...\n", __func__);
1757 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
1759 s3c_hsotg_complete_request_lock(hsotg, hs_ep, hs_req, 0);
1764 * @hsotg: The driver state
1770 static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1773 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[idx];
1780 ints = readl(hsotg->regs + epint_reg);
1782 dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n",
1786 dev_dbg(hsotg->dev,
1788 __func__, readl(hsotg->regs + epctl_reg),
1789 readl(hsotg->regs + epsiz_reg));
1794 s3c_hsotg_complete_in(hsotg, hs_ep);
1797 s3c_hsotg_enqueue_setup(hsotg);
1798 } else if (using_dma(hsotg)) {
1802 s3c_hsotg_handle_outdone(hsotg, idx, false);
1809 dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__);
1814 dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__);
1819 dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__);
1821 if (using_dma(hsotg) && idx == 0) {
1830 s3c_hsotg_handle_outdone(hsotg, 0, true);
1837 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
1845 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n",
1852 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n",
1858 if (hsotg->dedicated_fifos &&
1860 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
1862 s3c_hsotg_trytx(hsotg, hs_ep);
1867 writel(clear, hsotg->regs + epint_reg);
1872 * @hsotg: The device state.
1877 static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg)
1879 u32 dsts = readl(hsotg->regs + S3C_DSTS);
1886 dev_dbg(hsotg->dev, "EnumDone (DSTS=0x%08x)\n", dsts);
1896 hsotg->gadget.speed = USB_SPEED_FULL;
1897 dev_info(hsotg->dev, "new device is full-speed\n");
1904 dev_info(hsotg->dev, "new device is high-speed\n");
1905 hsotg->gadget.speed = USB_SPEED_HIGH;
1912 hsotg->gadget.speed = USB_SPEED_LOW;
1913 dev_info(hsotg->dev, "new device is low-speed\n");
1927 s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps);
1929 s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps);
1934 s3c_hsotg_enqueue_setup(hsotg);
1936 dev_dbg(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
1937 readl(hsotg->regs + S3C_DIEPCTL0),
1938 readl(hsotg->regs + S3C_DOEPCTL0));
1943 * @hsotg: The device state.
1951 static void kill_all_requests(struct s3c_hsotg *hsotg,
1967 s3c_hsotg_complete_request(hsotg, ep, req,
1981 * @hsotg: The device state.
1987 static void s3c_hsotg_disconnect_irq(struct s3c_hsotg *hsotg)
1992 kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true);
1994 call_gadget(hsotg, disconnect);
1999 * @hsotg: The device state:
2002 static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic)
2010 ep = &hsotg->eps[epno];
2019 ret = s3c_hsotg_trytx(hsotg, ep);
2039 struct s3c_hsotg *hsotg = pw;
2045 gintsts = readl(hsotg->regs + S3C_GINTSTS);
2046 gintmsk = readl(hsotg->regs + S3C_GINTMSK);
2048 dev_dbg(hsotg->dev, "%s: %08x %08x (%08x) retry %d\n",
2054 u32 otgint = readl(hsotg->regs + S3C_GOTGINT);
2056 dev_info(hsotg->dev, "OTGInt: %08x\n", otgint);
2058 writel(otgint, hsotg->regs + S3C_GOTGINT);
2059 writel(S3C_GINTSTS_OTGInt, hsotg->regs + S3C_GINTSTS);
2063 dev_dbg(hsotg->dev, "%s: DisconnInt\n", __func__);
2064 writel(S3C_GINTSTS_DisconnInt, hsotg->regs + S3C_GINTSTS);
2066 s3c_hsotg_disconnect_irq(hsotg);
2070 dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__);
2071 writel(S3C_GINTSTS_SessReqInt, hsotg->regs + S3C_GINTSTS);
2075 s3c_hsotg_irq_enumdone(hsotg);
2076 writel(S3C_GINTSTS_EnumDone, hsotg->regs + S3C_GINTSTS);
2080 dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n",
2081 readl(hsotg->regs + S3C_DSTS),
2082 readl(hsotg->regs + S3C_GOTGCTL));
2084 writel(S3C_GINTSTS_ConIDStsChng, hsotg->regs + S3C_GINTSTS);
2088 u32 daint = readl(hsotg->regs + S3C_DAINT);
2093 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint);
2097 s3c_hsotg_epint(hsotg, ep, 0);
2102 s3c_hsotg_epint(hsotg, ep, 1);
2105 writel(daint, hsotg->regs + S3C_DAINT);
2107 hsotg->regs + S3C_GINTSTS);
2111 dev_info(hsotg->dev, "%s: USBRst\n", __func__);
2112 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
2113 readl(hsotg->regs + S3C_GNPTXSTS));
2115 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true);
2123 s3c_hsotg_init_fifo(hsotg);
2125 s3c_hsotg_enqueue_setup(hsotg);
2127 writel(S3C_GINTSTS_USBRst, hsotg->regs + S3C_GINTSTS);
2133 dev_dbg(hsotg->dev, "NPTxFEmp\n");
2139 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_NPTxFEmp);
2140 s3c_hsotg_irq_fifoempty(hsotg, false);
2142 writel(S3C_GINTSTS_NPTxFEmp, hsotg->regs + S3C_GINTSTS);
2146 dev_dbg(hsotg->dev, "PTxFEmp\n");
2150 s3c_hsotg_disable_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
2151 s3c_hsotg_irq_fifoempty(hsotg, true);
2153 writel(S3C_GINTSTS_PTxFEmp, hsotg->regs + S3C_GINTSTS);
2161 s3c_hsotg_handle_rx(hsotg);
2162 writel(S3C_GINTSTS_RxFLvl, hsotg->regs + S3C_GINTSTS);
2166 dev_warn(hsotg->dev, "warning, mode mismatch triggered\n");
2167 writel(S3C_GINTSTS_ModeMis, hsotg->regs + S3C_GINTSTS);
2171 dev_info(hsotg->dev, "S3C_GINTSTS_USBSusp\n");
2172 writel(S3C_GINTSTS_USBSusp, hsotg->regs + S3C_GINTSTS);
2174 call_gadget(hsotg, suspend);
2178 dev_info(hsotg->dev, "S3C_GINTSTS_WkUpIn\n");
2179 writel(S3C_GINTSTS_WkUpInt, hsotg->regs + S3C_GINTSTS);
2181 call_gadget(hsotg, resume);
2185 dev_dbg(hsotg->dev, "S3C_GINTSTS_ErlySusp\n");
2186 writel(S3C_GINTSTS_ErlySusp, hsotg->regs + S3C_GINTSTS);
2194 dev_info(hsotg->dev, "GOUTNakEff triggered\n");
2196 s3c_hsotg_dump(hsotg);
2198 writel(S3C_DCTL_CGOUTNak, hsotg->regs + S3C_DCTL);
2199 writel(S3C_GINTSTS_GOUTNakEff, hsotg->regs + S3C_GINTSTS);
2203 dev_info(hsotg->dev, "GINNakEff triggered\n");
2205 s3c_hsotg_dump(hsotg);
2207 writel(S3C_DCTL_CGNPInNAK, hsotg->regs + S3C_DCTL);
2208 writel(S3C_GINTSTS_GINNakEff, hsotg->regs + S3C_GINTSTS);
2231 struct s3c_hsotg *hsotg = hs_ep->parent;
2240 dev_dbg(hsotg->dev,
2250 dev_err(hsotg->dev, "%s: direction mismatch!\n", __func__);
2259 epctrl = readl(hsotg->regs + epctrl_reg);
2261 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n",
2289 dev_err(hsotg->dev, "no current ISOC support\n");
2319 if (dir_in && hsotg->dedicated_fifos)
2326 dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n",
2329 writel(epctrl, hsotg->regs + epctrl_reg);
2330 dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x\n",
2331 __func__, readl(hsotg->regs + epctrl_reg));
2334 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2344 struct s3c_hsotg *hsotg = hs_ep->parent;
2351 dev_info(hsotg->dev, "%s(ep %p)\n", __func__, ep);
2353 if (ep == &hsotg->eps[0].ep) {
2354 dev_err(hsotg->dev, "%s: called for ep0\n", __func__);
2361 kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false);
2365 ctrl = readl(hsotg->regs + epctrl_reg);
2370 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl);
2371 writel(ctrl, hsotg->regs + epctrl_reg);
2374 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 0);
2477 * @hsotg: The device state
2481 static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2486 dev_dbg(hsotg->dev, "resetting core\n");
2489 writel(S3C_GRSTCTL_CSftRst, hsotg->regs + S3C_GRSTCTL);
2493 grstctl = readl(hsotg->regs + S3C_GRSTCTL);
2497 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n");
2504 u32 grstctl = readl(hsotg->regs + S3C_GRSTCTL);
2507 dev_info(hsotg->dev,
2522 dev_dbg(hsotg->dev, "reset successful\n");
2528 struct s3c_hsotg *hsotg = our_hsotg;
2531 if (!hsotg) {
2537 dev_err(hsotg->dev, "%s: no driver\n", __func__);
2543 dev_err(hsotg->dev, "%s: bad speed\n", __func__);
2547 dev_err(hsotg->dev, "%s: missing entry points\n", __func__);
2551 WARN_ON(hsotg->driver);
2554 hsotg->driver = driver;
2555 hsotg->gadget.dev.driver = &driver->driver;
2556 hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
2557 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2559 ret = device_add(&hsotg->gadget.dev);
2561 dev_err(hsotg->dev, "failed to register gadget device\n");
2565 ret = driver->bind(&hsotg->gadget);
2567 dev_err(hsotg->dev, "failed bind %s\n", driver->driver.name);
2569 hsotg->gadget.dev.driver = NULL;
2570 hsotg->driver = NULL;
2577 s3c_hsotg_corereset(hsotg);
2581 (0x5 << 10), hsotg->regs + S3C_GUSBCFG);
2584 s3c_hsotg_init_fifo(hsotg);
2586 __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
2588 writel(1 << 18 | S3C_DCFG_DevSpd_HS, hsotg->regs + S3C_DCFG);
2596 hsotg->regs + S3C_GINTMSK);
2598 if (using_dma(hsotg))
2601 hsotg->regs + S3C_GAHBCFG);
2603 writel(S3C_GAHBCFG_GlblIntrEn, hsotg->regs + S3C_GAHBCFG);
2612 ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0),
2613 hsotg->regs + S3C_DIEPMSK);
2619 (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk |
2621 hsotg->regs + S3C_DOEPMSK);
2623 writel(0, hsotg->regs + S3C_DAINTMSK);
2625 dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2626 readl(hsotg->regs + S3C_DIEPCTL0),
2627 readl(hsotg->regs + S3C_DOEPCTL0));
2630 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_OEPInt | S3C_GINTSTS_IEPInt);
2635 if (!using_dma(hsotg))
2636 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_RxFLvl);
2639 s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1);
2640 s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1);
2642 __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone);
2644 __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_PWROnPrgDone);
2646 dev_info(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + S3C_DCTL));
2653 S3C_DxEPTSIZ_XferSize(8), hsotg->regs + DOEPTSIZ0);
2655 writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) |
2658 hsotg->regs + S3C_DOEPCTL0);
2661 writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) |
2662 S3C_DxEPCTL_USBActEp, hsotg->regs + S3C_DIEPCTL0);
2664 s3c_hsotg_enqueue_setup(hsotg);
2666 dev_info(hsotg->dev, "EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2667 readl(hsotg->regs + S3C_DIEPCTL0),
2668 readl(hsotg->regs + S3C_DOEPCTL0));
2672 hsotg->regs + S3C_DCTL);
2678 __bic32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
2682 dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);
2686 hsotg->driver = NULL;
2687 hsotg->gadget.dev.driver = NULL;
2694 struct s3c_hsotg *hsotg = our_hsotg;
2697 if (!hsotg)
2700 if (!driver || driver != hsotg->driver || !driver->unbind)
2705 s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
2707 call_gadget(hsotg, disconnect);
2709 driver->unbind(&hsotg->gadget);
2710 hsotg->driver = NULL;
2711 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2713 device_del(&hsotg->gadget.dev);
2715 dev_info(hsotg->dev, "unregistered gadget driver '%s'\n",
2733 * @hsotg: The device state.
2741 static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg,
2768 list_add_tail(&hs_ep->ep.ep_list, &hsotg->gadget.ep_list);
2770 hs_ep->parent = hsotg;
2780 ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum));
2787 if (using_dma(hsotg)) {
2789 writel(next, hsotg->regs + S3C_DIEPCTL(epnum));
2790 writel(next, hsotg->regs + S3C_DOEPCTL(epnum));
2796 * @hsotg: The host state.
2800 static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg)
2810 osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0;
2812 xusbxti = clk_get(hsotg->dev, "xusbxti");
2839 static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
2847 hsotg->regs + S3C_DIEPMSK);
2851 hsotg->regs + S3C_DOEPMSK);
2853 writel(0, hsotg->regs + S3C_DAINTMSK);
2856 __orr32(hsotg->regs + S3C_DCTL, S3C_DCTL_SftDiscon);
2861 hsotg->regs + S3C_DCTL);
2866 dev_info(hsotg->dev, "GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
2867 readl(hsotg->regs + S3C_GRXFSIZ),
2868 readl(hsotg->regs + S3C_GNPTXFSIZ));
2870 s3c_hsotg_init_fifo(hsotg);
2874 hsotg->regs + S3C_GUSBCFG);
2876 writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0,
2877 hsotg->regs + S3C_GAHBCFG);
2881 cfg4 = readl(hsotg->regs + 0x50);
2882 hsotg->dedicated_fifos = (cfg4 >> 25) & 1;
2884 dev_info(hsotg->dev, "%s fifos\n",
2885 hsotg->dedicated_fifos ? "dedicated" : "shared");
2888 static void s3c_hsotg_dump(struct s3c_hsotg *hsotg)
2890 struct device *dev = hsotg->dev;
2891 void __iomem *regs = hsotg->regs;
2946 struct s3c_hsotg *hsotg = seq->private;
2947 void __iomem *regs = hsotg->regs;
3016 struct s3c_hsotg *hsotg = seq->private;
3017 void __iomem *regs = hsotg->regs;
3072 struct s3c_hsotg *hsotg = ep->parent;
3074 void __iomem *regs = hsotg->regs;
3142 * @hsotg: The driver state
3149 static void __devinit s3c_hsotg_create_debug(struct s3c_hsotg *hsotg)
3154 root = debugfs_create_dir(dev_name(hsotg->dev), NULL);
3155 hsotg->debug_root = root;
3157 dev_err(hsotg->dev, "cannot create debug root\n");
3163 hsotg->debug_file = debugfs_create_file("state", 0444, root,
3164 hsotg, &state_fops);
3166 if (IS_ERR(hsotg->debug_file))
3167 dev_err(hsotg->dev, "%s: failed to create state\n", __func__);
3169 hsotg->debug_fifo = debugfs_create_file("fifo", 0444, root,
3170 hsotg, &fifo_fops);
3172 if (IS_ERR(hsotg->debug_fifo))
3173 dev_err(hsotg->dev, "%s: failed to create fifo\n", __func__);
3178 struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
3184 dev_err(hsotg->dev, "failed to create %s debug file\n",
3191 * @hsotg: The driver state
3195 static void __devexit s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg)
3200 struct s3c_hsotg_ep *ep = &hsotg->eps[epidx];
3204 debugfs_remove(hsotg->debug_file);
3205 debugfs_remove(hsotg->debug_fifo);
3206 debugfs_remove(hsotg->debug_root);
3241 struct s3c_hsotg *hsotg;
3249 hsotg = kzalloc(sizeof(struct s3c_hsotg) +
3252 if (!hsotg) {
3257 hsotg->dev = dev;
3258 hsotg->plat = plat;
3260 hsotg->clk = clk_get(&pdev->dev, "otg");
3261 if (IS_ERR(hsotg->clk)) {
3267 platform_set_drvdata(pdev, hsotg);
3276 hsotg->regs_res = request_mem_region(res->start, resource_size(res),
3278 if (!hsotg->regs_res) {
3284 hsotg->regs = ioremap(res->start, resource_size(res));
3285 if (!hsotg->regs) {
3297 hsotg->irq = ret;
3299 ret = request_irq(ret, s3c_hsotg_irq, 0, dev_name(dev), hsotg);
3305 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
3307 device_initialize(&hsotg->gadget.dev);
3309 dev_set_name(&hsotg->gadget.dev, "gadget");
3311 hsotg->gadget.is_dualspeed = 1;
3312 hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
3313 hsotg->gadget.name = dev_name(dev);
3315 hsotg->gadget.dev.parent = dev;
3316 hsotg->gadget.dev.dma_mask = dev->dma_mask;
3320 INIT_LIST_HEAD(&hsotg->gadget.ep_list);
3321 hsotg->gadget.ep0 = &hsotg->eps[0].ep;
3325 hsotg->ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->eps[0].ep,
3327 if (!hsotg->ctrl_req) {
3334 clk_enable(hsotg->clk);
3338 s3c_hsotg_otgreset(hsotg);
3339 s3c_hsotg_corereset(hsotg);
3340 s3c_hsotg_init(hsotg);
3344 s3c_hsotg_initep(hsotg, &hsotg->eps[epnum], epnum);
3346 s3c_hsotg_create_debug(hsotg);
3348 s3c_hsotg_dump(hsotg);
3350 our_hsotg = hsotg;
3354 iounmap(hsotg->regs);
3357 release_resource(hsotg->regs_res);
3358 kfree(hsotg->regs_res);
3360 clk_put(hsotg->clk);
3362 kfree(hsotg);
3368 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
3370 s3c_hsotg_delete_debug(hsotg);
3372 usb_gadget_unregister_driver(hsotg->driver);
3374 free_irq(hsotg->irq, hsotg);
3375 iounmap(hsotg->regs);
3377 release_resource(hsotg->regs_res);
3378 kfree(hsotg->regs_res);
3382 clk_disable(hsotg->clk);
3383 clk_put(hsotg->clk);
3385 kfree(hsotg);
3394 .name = "s3c-hsotg",
3419 MODULE_ALIAS("platform:s3c-hsotg");