19 #include <linux/kernel.h>
20 #include <linux/module.h>
29 #include <linux/slab.h>
33 #include <linux/usb/ch9.h>
41 #define DMA_ADDR_INVALID (~((dma_addr_t)0))
43 static const char *
const s3c_hsotg_supply_names[] = {
66 #define EP0_MPS_LIMIT 64
219 static inline void __bic32(
void __iomem *ptr,
u32 val)
225 static void s3c_hsotg_dump(
struct s3c_hsotg *hsotg);
246 static inline bool using_dma(
struct s3c_hsotg *hsotg)
256 static void s3c_hsotg_en_gsint(
struct s3c_hsotg *hsotg,
u32 ints)
261 new_gsintmsk = gsintmsk | ints;
263 if (new_gsintmsk != gsintmsk) {
264 dev_dbg(hsotg->
dev,
"gsintmsk now 0x%08x\n", new_gsintmsk);
274 static void s3c_hsotg_disable_gsint(
struct s3c_hsotg *hsotg,
u32 ints)
279 new_gsintmsk = gsintmsk & ~ints;
281 if (new_gsintmsk != gsintmsk)
295 static void s3c_hsotg_ctrl_epint(
struct s3c_hsotg *hsotg,
296 unsigned int ep,
unsigned int dir_in,
320 static void s3c_hsotg_init_fifo(
struct s3c_hsotg *hsotg)
351 for (ep = 1; ep <= 15; ep++) {
375 if (--timeout == 0) {
377 "%s: timeout flushing fifos (GRSTCTL=%08x)\n",
384 dev_dbg(hsotg->
dev,
"FIFOs reset, timeout at %d\n", timeout);
402 INIT_LIST_HEAD(&req->
queue);
415 static inline int is_ep_periodic(
struct s3c_hsotg_ep *hs_ep)
429 static void s3c_hsotg_unmap_dma(
struct s3c_hsotg *hsotg,
439 if (hs_req->
req.length == 0)
470 static int s3c_hsotg_write_fifo(
struct s3c_hsotg *hsotg,
474 bool periodic = is_ep_periodic(hs_ep);
476 int buf_pos = hs_req->
req.actual;
482 to_write -= (buf_pos - hs_ep->
last_load);
509 dev_dbg(hsotg->
dev,
"%s: left=%d, load=%d, fifo=%d, size %d\n",
517 can_write = hs_ep->
fifo_load - size_done;
519 __func__, can_write);
521 can_write = hs_ep->
fifo_size - can_write;
523 __func__, can_write);
525 if (can_write <= 0) {
537 "%s: no queue slots available (0x%08x)\n",
548 dev_dbg(hsotg->
dev,
"%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n",
549 __func__, gnptxsts, can_write, to_write, hs_ep->
ep.maxpacket);
564 if (to_write > hs_ep->
ep.maxpacket) {
565 to_write = hs_ep->
ep.maxpacket;
567 s3c_hsotg_en_gsint(hsotg,
574 if (to_write > can_write) {
575 to_write = can_write;
576 pkt_round = to_write % hs_ep->
ep.maxpacket;
587 to_write -= pkt_round;
594 s3c_hsotg_en_gsint(hsotg,
599 dev_dbg(hsotg->
dev,
"write %d/%d, can_write %d, done %d\n",
600 to_write, hs_req->
req.length, can_write, buf_pos);
605 hs_req->
req.actual = buf_pos + to_write;
612 data = hs_req->
req.buf + buf_pos;
616 return (to_write >= can_write) ? -
ENOSPC : 0;
626 static unsigned get_ep_limit(
struct s3c_hsotg_ep *hs_ep)
652 if ((maxpkt * hs_ep->
ep.maxpacket) < maxsize)
653 maxsize = maxpkt * hs_ep->
ep.maxpacket;
668 static void s3c_hsotg_start_req(
struct s3c_hsotg *hsotg,
674 int index = hs_ep->
index;
675 int dir_in = hs_ep->
dir_in;
685 if (hs_ep->
req && !continuing) {
686 dev_err(hsotg->
dev,
"%s: active request\n", __func__);
689 }
else if (hs_ep->
req != hs_req && continuing) {
691 "%s: continue different req\n", __func__);
700 dev_dbg(hsotg->
dev,
"%s: DxEPCTL=0x%08x, ep %d, dir %s\n",
701 __func__,
readl(hsotg->
regs + epctrl_reg), index,
702 hs_ep->
dir_in ?
"in" :
"out");
708 dev_warn(hsotg->
dev,
"%s: ep%d is stalled\n", __func__, index);
713 dev_dbg(hsotg->
dev,
"ureq->length:%d ureq->actual:%d\n",
717 "REQ buf %p len %d dma 0x%08x noi=%d zp=%d snok=%d\n",
718 ureq->
buf, length, ureq->
dma,
721 maxreq = get_ep_limit(hs_ep);
722 if (length > maxreq) {
723 int round = maxreq % hs_ep->
ep.maxpacket;
725 dev_dbg(hsotg->
dev,
"%s: length %d, max-req %d, r %d\n",
726 __func__, length, maxreq, round);
740 if (dir_in && index != 0)
745 if (index != 0 && ureq->
zero) {
751 if (length == (packets * hs_ep->
ep.maxpacket))
758 dev_dbg(hsotg->
dev,
"%s: %d@%d/%d, 0x%08x => 0x%08x\n",
759 __func__, packets, length, ureq->
length, epsize, epsize_reg);
767 if (using_dma(hsotg) && !continuing) {
779 __func__, ureq->
dma, dma_reg);
788 if (hsotg->
setup && index == 0)
794 dev_dbg(hsotg->
dev,
"%s: DxEPCTL=0x%08x\n", __func__, ctrl);
805 if (dir_in && !using_dma(hsotg)) {
809 s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
828 "ep%d: failed to become enabled (DxEPCTL=0x%08x)?\n",
832 __func__,
readl(hsotg->
regs + epctrl_reg));
847 static int s3c_hsotg_map_dma(
struct s3c_hsotg *hsotg,
857 if (hs_req->
req.length == 0)
869 dev_err(hsotg->
dev,
"%s: unaligned dma buffer\n",
886 dev_err(hsotg->
dev,
"%s: failed to map buffer %p, %d bytes\n",
900 dev_dbg(hs->
dev,
"%s: req %p: %d@%p, noi=%d, zero=%d, snok=%d\n",
905 INIT_LIST_HEAD(&hs_req->
queue);
911 int ret = s3c_hsotg_map_dma(hs, hs_ep, req);
916 first = list_empty(&hs_ep->
queue);
920 s3c_hsotg_start_req(hs, hs_ep, hs_req,
false);
930 unsigned long flags = 0;
934 ret = s3c_hsotg_ep_queue(ep, req, gfp_flags);
935 spin_unlock_irqrestore(&hs->
lock, flags);
940 static void s3c_hsotg_ep_free_request(
struct usb_ep *ep,
956 static void s3c_hsotg_complete_oursetup(
struct usb_ep *ep,
962 dev_dbg(hsotg->
dev,
"%s: ep %p, req %p\n", __func__, ep, req);
964 s3c_hsotg_ep_free_request(ep, req);
980 int idx = windex & 0x7F;
988 if (idx && ep->
dir_in != dir)
1004 static int s3c_hsotg_send_reply(
struct s3c_hsotg *hsotg,
1012 dev_dbg(hsotg->
dev,
"%s: buff %p, len %d\n", __func__, buff, length);
1017 dev_warn(hsotg->
dev,
"%s: cannot alloc req\n", __func__);
1024 req->
complete = s3c_hsotg_complete_oursetup;
1033 dev_warn(hsotg->
dev,
"%s: cannot queue req\n", __func__);
1045 static int s3c_hsotg_process_req_status(
struct s3c_hsotg *hsotg,
1053 dev_dbg(hsotg->
dev,
"%s: USB_REQ_GET_STATUS\n", __func__);
1056 dev_warn(hsotg->
dev,
"%s: direction out?\n", __func__);
1086 ret = s3c_hsotg_send_reply(hsotg, ep0, &reply, 2);
1088 dev_err(hsotg->
dev,
"%s: failed to send reply\n", __func__);
1095 static int s3c_hsotg_ep_sethalt(
struct usb_ep *ep,
int value);
1105 if (list_empty(&hs_ep->
queue))
1116 static int s3c_hsotg_process_req_feature(
struct s3c_hsotg *hsotg,
1127 __func__,
set ?
"SET" :
"CLEAR");
1132 dev_dbg(hsotg->
dev,
"%s: no endpoint for 0x%04x\n",
1139 s3c_hsotg_ep_sethalt(&ep->
ep,
set);
1141 ret = s3c_hsotg_send_reply(hsotg, ep0,
NULL, 0);
1144 "%s: failed to send reply\n", __func__);
1156 list_del_init(&hs_req->
queue);
1157 hs_req->
req.complete(&ep->
ep,
1162 restart = !list_empty(&ep->
queue);
1164 hs_req = get_ep_head(ep);
1165 s3c_hsotg_start_req(hsotg, ep,
1190 static void s3c_hsotg_process_control(
struct s3c_hsotg *hsotg,
1199 dev_dbg(hsotg->
dev,
"ctrl Req=%02x, Type=%02x, V=%04x, L=%04x\n",
1228 ret = s3c_hsotg_send_reply(hsotg, ep0,
NULL, 0);
1232 ret = s3c_hsotg_process_req_status(hsotg, ctrl);
1237 ret = s3c_hsotg_process_req_feature(hsotg, ctrl);
1244 if (ret == 0 && hsotg->
driver) {
1247 dev_dbg(hsotg->
dev,
"driver->setup() ret %d\n", ret);
1273 "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n",
1283 static void s3c_hsotg_enqueue_setup(
struct s3c_hsotg *hsotg);
1293 static void s3c_hsotg_complete_setup(
struct usb_ep *ep,
1305 s3c_hsotg_enqueue_setup(hsotg);
1307 s3c_hsotg_process_control(hsotg, req->
buf);
1317 static void s3c_hsotg_enqueue_setup(
struct s3c_hsotg *hsotg)
1323 dev_dbg(hsotg->
dev,
"%s: queueing setup request\n", __func__);
1328 req->
complete = s3c_hsotg_complete_setup;
1330 if (!list_empty(&hs_req->
queue)) {
1331 dev_dbg(hsotg->
dev,
"%s already queued???\n", __func__);
1335 hsotg->
eps[0].dir_in = 0;
1337 ret = s3c_hsotg_ep_queue(&hsotg->
eps[0].ep, req,
GFP_ATOMIC);
1339 dev_err(hsotg->
dev,
"%s: failed queue (%d)\n", __func__, ret);
1360 static void s3c_hsotg_complete_request(
struct s3c_hsotg *hsotg,
1368 dev_dbg(hsotg->
dev,
"%s: nothing to complete?\n", __func__);
1372 dev_dbg(hsotg->
dev,
"complete: ep %p %s, req %p, %d => %p\n",
1373 hs_ep, hs_ep->
ep.name, hs_req, result, hs_req->
req.complete);
1384 list_del_init(&hs_req->
queue);
1386 if (using_dma(hsotg))
1387 s3c_hsotg_unmap_dma(hsotg, hs_ep, hs_req);
1394 if (hs_req->
req.complete) {
1395 spin_unlock(&hsotg->
lock);
1396 hs_req->
req.complete(&hs_ep->
ep, &hs_req->
req);
1397 spin_lock(&hsotg->
lock);
1406 if (!hs_ep->
req && result >= 0) {
1407 restart = !list_empty(&hs_ep->
queue);
1409 hs_req = get_ep_head(hs_ep);
1410 s3c_hsotg_start_req(hsotg, hs_ep, hs_req,
false);
1425 static void s3c_hsotg_rx_data(
struct s3c_hsotg *hsotg,
int ep_idx,
int size)
1440 "%s: FIFO %d bytes on ep%d but no req (DxEPCTl=0x%08x)\n",
1441 __func__, size, ep_idx, epctl);
1444 for (ptr = 0; ptr <
size; ptr += 4)
1451 read_ptr = hs_req->
req.actual;
1452 max_req = hs_req->
req.length - read_ptr;
1454 dev_dbg(hsotg->
dev,
"%s: read %d/%d, done %d/%d\n",
1455 __func__, to_read, max_req, read_ptr, hs_req->
req.length);
1457 if (to_read > max_req) {
1468 hs_req->
req.actual += to_read;
1475 readsl(fifo, hs_req->
req.buf + read_ptr, to_read);
1490 static void s3c_hsotg_send_zlp(
struct s3c_hsotg *hsotg,
1496 dev_warn(hsotg->
dev,
"%s: no request?\n", __func__);
1500 if (req->
req.length == 0) {
1501 hsotg->
eps[0].sent_zlp = 1;
1502 s3c_hsotg_enqueue_setup(hsotg);
1506 hsotg->
eps[0].dir_in = 1;
1507 hsotg->
eps[0].sent_zlp = 1;
1509 dev_dbg(hsotg->
dev,
"sending zero-length packet\n");
1532 static void s3c_hsotg_handle_outdone(
struct s3c_hsotg *hsotg,
1533 int epnum,
bool was_setup)
1543 dev_dbg(hsotg->
dev,
"%s: no request active\n", __func__);
1547 if (using_dma(hsotg)) {
1567 s3c_hsotg_start_req(hsotg, hs_ep, hs_req,
true);
1569 }
else if (epnum == 0) {
1574 hsotg->
setup = was_setup ? 0 : 1;
1578 dev_dbg(hsotg->
dev,
"%s: got %d/%d (short not ok) => error\n",
1592 if (!was_setup && req->
complete != s3c_hsotg_complete_setup)
1593 s3c_hsotg_send_zlp(hsotg, hs_req);
1596 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, result);
1605 static u32 s3c_hsotg_read_frameno(
struct s3c_hsotg *hsotg)
1632 static void s3c_hsotg_handle_rx(
struct s3c_hsotg *hsotg)
1646 dev_dbg(hsotg->
dev,
"%s: GRXSTSP=0x%08x (%d@%d)\n",
1647 __func__, grxstsr, size, epnum);
1649 #define __status(x) ((x) >> GRXSTS_PktSts_SHIFT)
1657 dev_dbg(hsotg->
dev,
"OutDone (Frame=0x%08x)\n",
1658 s3c_hsotg_read_frameno(hsotg));
1660 if (!using_dma(hsotg))
1661 s3c_hsotg_handle_outdone(hsotg, epnum,
false);
1666 "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n",
1667 s3c_hsotg_read_frameno(hsotg),
1670 s3c_hsotg_handle_outdone(hsotg, epnum,
true);
1674 s3c_hsotg_rx_data(hsotg, epnum, size);
1679 "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n",
1680 s3c_hsotg_read_frameno(hsotg),
1683 s3c_hsotg_rx_data(hsotg, epnum, size);
1690 s3c_hsotg_dump(hsotg);
1699 static u32 s3c_hsotg_ep0_mps(
unsigned int mps)
1726 static void s3c_hsotg_set_ep_maxpacket(
struct s3c_hsotg *hsotg,
1727 unsigned int ep,
unsigned int mps)
1736 mpsval = s3c_hsotg_ep0_mps(mps);
1746 hs_ep->
ep.maxpacket =
mps;
1768 dev_err(hsotg->
dev,
"ep%d: bad mps of %d\n", ep, mps);
1776 static void s3c_hsotg_txfifo_flush(
struct s3c_hsotg *hsotg,
unsigned int idx)
1793 if (--timeout == 0) {
1795 "%s: timeout flushing fifo (GRSTCTL=%08x)\n",
1811 static int s3c_hsotg_trytx(
struct s3c_hsotg *hsotg,
1816 if (!hs_ep->
dir_in || !hs_req)
1819 if (hs_req->
req.actual < hs_req->
req.length) {
1820 dev_dbg(hsotg->
dev,
"trying to write more for ep%d\n",
1822 return s3c_hsotg_write_fifo(hsotg, hs_ep, hs_req);
1836 static void s3c_hsotg_complete_in(
struct s3c_hsotg *hsotg,
1841 int size_left, size_done;
1844 dev_dbg(hsotg->
dev,
"XferCompl but no req\n");
1849 if (hsotg->
eps[0].sent_zlp) {
1850 dev_dbg(hsotg->
dev,
"zlp packet received\n");
1851 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
1870 if (hs_req->
req.actual != size_done)
1871 dev_dbg(hsotg->
dev,
"%s: adjusting size done %d => %d\n",
1872 __func__, hs_req->
req.actual, size_done);
1874 hs_req->
req.actual = size_done;
1875 dev_dbg(hsotg->
dev,
"req->length:%d req->actual:%d req->zero:%d\n",
1876 hs_req->
req.length, hs_req->
req.actual, hs_req->
req.zero);
1888 if (hs_req->
req.length && hs_ep->
index == 0 && hs_req->
req.zero &&
1889 hs_req->
req.length == hs_req->
req.actual &&
1890 !(hs_req->
req.length % hs_ep->
ep.maxpacket)) {
1892 dev_dbg(hsotg->
dev,
"ep0 zlp IN packet sent\n");
1893 s3c_hsotg_send_zlp(hsotg, hs_req);
1898 if (!size_left && hs_req->
req.actual < hs_req->
req.length) {
1899 dev_dbg(hsotg->
dev,
"%s trying more for req...\n", __func__);
1900 s3c_hsotg_start_req(hsotg, hs_ep, hs_req,
true);
1902 s3c_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
1913 static void s3c_hsotg_epint(
struct s3c_hsotg *hsotg,
unsigned int idx,
1927 dev_dbg(hsotg->
dev,
"%s: ep%d(%s) DxEPINT=0x%08x\n",
1928 __func__, idx, dir_in ?
"in" :
"out", ints);
1932 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n",
1933 __func__,
readl(hsotg->
regs + epctl_reg),
1941 s3c_hsotg_complete_in(hsotg, hs_ep);
1943 if (idx == 0 && !hs_ep->
req)
1944 s3c_hsotg_enqueue_setup(hsotg);
1945 }
else if (using_dma(hsotg)) {
1951 s3c_hsotg_handle_outdone(hsotg, idx,
false);
1956 dev_dbg(hsotg->
dev,
"%s: EPDisbld\n", __func__);
1959 int epctl =
readl(hsotg->
regs + epctl_reg);
1961 s3c_hsotg_txfifo_flush(hsotg, idx);
1963 if ((epctl & DxEPCTL_Stall) &&
1974 dev_dbg(hsotg->
dev,
"%s: AHBErr\n", __func__);
1977 dev_dbg(hsotg->
dev,
"%s: Setup/Timeout\n", __func__);
1979 if (using_dma(hsotg) && idx == 0) {
1990 s3c_hsotg_handle_outdone(hsotg, 0,
true);
1995 dev_dbg(hsotg->
dev,
"%s: B2BSetup/INEPNakEff\n", __func__);
2000 dev_dbg(hsotg->
dev,
"%s: ep%d: INTknTXFEmpMsk\n",
2013 dev_dbg(hsotg->
dev,
"%s: ep%d: TxFIFOEmpty\n",
2015 if (!using_dma(hsotg))
2016 s3c_hsotg_trytx(hsotg, hs_ep);
2028 static void s3c_hsotg_irq_enumdone(
struct s3c_hsotg *hsotg)
2031 int ep0_mps = 0, ep_mps;
2039 dev_dbg(hsotg->
dev,
"EnumDone (DSTS=0x%08x)\n", dsts);
2081 s3c_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps);
2083 s3c_hsotg_set_ep_maxpacket(hsotg, i, ep_mps);
2088 s3c_hsotg_enqueue_setup(hsotg);
2090 dev_dbg(hsotg->
dev,
"EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2105 static void kill_all_requests(
struct s3c_hsotg *hsotg,
2107 int result,
bool force)
2117 if (ep->
req == req && ep->
dir_in && !force)
2120 s3c_hsotg_complete_request(hsotg, ep, req,
2125 #define call_gadget(_hs, _entry) \
2126 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
2127 (_hs)->driver && (_hs)->driver->_entry) { \
2128 spin_unlock(&_hs->lock); \
2129 (_hs)->driver->_entry(&(_hs)->gadget); \
2130 spin_lock(&_hs->lock); \
2141 static void s3c_hsotg_disconnect(
struct s3c_hsotg *hsotg)
2146 kill_all_requests(hsotg, &hsotg->
eps[ep], -
ESHUTDOWN,
true);
2156 static void s3c_hsotg_irq_fifoempty(
struct s3c_hsotg *hsotg,
bool periodic)
2163 for (epno = 0; epno < hsotg->
num_of_eps; epno++) {
2164 ep = &hsotg->
eps[epno];
2173 ret = s3c_hsotg_trytx(hsotg, ep);
2180 #define IRQ_RETRY_MASK (GINTSTS_NPTxFEmp | \
2190 static int s3c_hsotg_corereset(
struct s3c_hsotg *hsotg)
2205 if (grstctl & GRSTCTL_CSftRst) {
2206 dev_err(hsotg->
dev,
"Failed to get CSftRst asserted\n");
2215 if (timeout-- < 0) {
2217 "%s: reset failed, GRSTCTL=%08x\n",
2238 static void s3c_hsotg_core_init(
struct s3c_hsotg *hsotg)
2240 s3c_hsotg_corereset(hsotg);
2251 s3c_hsotg_init_fifo(hsotg);
2270 if (using_dma(hsotg))
2286 DIEPMSK_INTknEPMisMsk,
2301 dev_dbg(hsotg->
dev,
"EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2313 if (!using_dma(hsotg))
2317 s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1);
2318 s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1);
2335 writel(s3c_hsotg_ep0_mps(hsotg->
eps[0].ep.maxpacket) |
2341 writel(s3c_hsotg_ep0_mps(hsotg->
eps[0].ep.maxpacket) |
2344 s3c_hsotg_enqueue_setup(hsotg);
2346 dev_dbg(hsotg->
dev,
"EP0: DIEPCTL0=0x%08x, DOEPCTL0=0x%08x\n",
2373 spin_lock(&hsotg->
lock);
2378 dev_dbg(hsotg->
dev,
"%s: %08x %08x (%08x) retry %d\n",
2379 __func__, gintsts, gintsts & gintmsk, gintmsk, retry_count);
2392 dev_dbg(hsotg->
dev,
"%s: SessReqInt\n", __func__);
2399 s3c_hsotg_irq_enumdone(hsotg);
2403 dev_dbg(hsotg->
dev,
"ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n",
2416 dev_dbg(hsotg->
dev,
"%s: daint=%08x\n", __func__, daint);
2418 for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) {
2420 s3c_hsotg_epint(hsotg, ep, 0);
2423 for (ep = 0; ep < 15 && daint_in; ep++, daint_in >>= 1) {
2425 s3c_hsotg_epint(hsotg, ep, 1);
2443 kill_all_requests(hsotg, &hsotg->
eps[0],
2446 s3c_hsotg_core_init(hsotg);
2463 s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTxFEmp);
2464 s3c_hsotg_irq_fifoempty(hsotg,
false);
2472 s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTxFEmp);
2473 s3c_hsotg_irq_fifoempty(hsotg,
true);
2483 s3c_hsotg_handle_rx(hsotg);
2487 dev_warn(hsotg->
dev,
"warning, mode mismatch triggered\n");
2496 s3c_hsotg_disconnect(hsotg);
2510 s3c_hsotg_disconnect(hsotg);
2524 s3c_hsotg_dump(hsotg);
2532 s3c_hsotg_dump(hsotg);
2543 spin_unlock(&hsotg->
lock);
2555 static int s3c_hsotg_ep_enable(
struct usb_ep *ep,
2560 unsigned long flags;
2561 int index = hs_ep->
index;
2569 "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n",
2577 if (dir_in != hs_ep->
dir_in) {
2578 dev_err(hsotg->
dev,
"%s: direction mismatch!\n", __func__);
2582 mps = usb_endpoint_maxp(desc);
2587 epctrl =
readl(hsotg->
regs + epctrl_reg);
2589 dev_dbg(hsotg->
dev,
"%s: read DxEPCTL=0x%08x from 0x%08x\n",
2590 __func__, epctrl, epctrl_reg);
2613 hs_ep->
ep.maxpacket =
mps;
2620 dev_err(hsotg->
dev,
"no current ISOC support\n");
2660 dev_dbg(hsotg->
dev,
"%s: write DxEPCTL=0x%08x\n",
2664 dev_dbg(hsotg->
dev,
"%s: read DxEPCTL=0x%08x\n",
2665 __func__,
readl(hsotg->
regs + epctrl_reg));
2668 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2671 spin_unlock_irqrestore(&hsotg->
lock, flags);
2679 static int s3c_hsotg_ep_disable(
struct usb_ep *ep)
2683 int dir_in = hs_ep->
dir_in;
2684 int index = hs_ep->
index;
2685 unsigned long flags;
2689 dev_info(hsotg->
dev,
"%s(ep %p)\n", __func__, ep);
2691 if (ep == &hsotg->
eps[0].ep) {
2692 dev_err(hsotg->
dev,
"%s: called for ep0\n", __func__);
2700 kill_all_requests(hsotg, hs_ep, -
ESHUTDOWN,
false);
2704 ctrl &= ~DxEPCTL_EPEna;
2708 dev_dbg(hsotg->
dev,
"%s: DxEPCTL=0x%08x\n", __func__, ctrl);
2712 s3c_hsotg_ctrl_epint(hsotg, hs_ep->
index, hs_ep->
dir_in, 0);
2714 spin_unlock_irqrestore(&hsotg->
lock, flags);
2745 unsigned long flags;
2747 dev_info(hs->
dev,
"ep_dequeue(%p,%p)\n", ep, req);
2751 if (!on_list(hs_ep, hs_req)) {
2752 spin_unlock_irqrestore(&hs->
lock, flags);
2756 s3c_hsotg_complete_request(hs, hs_ep, hs_req, -
ECONNRESET);
2757 spin_unlock_irqrestore(&hs->
lock, flags);
2767 static int s3c_hsotg_ep_sethalt(
struct usb_ep *ep,
int value)
2771 int index = hs_ep->
index;
2776 dev_info(hs->
dev,
"%s(ep %p %s, %d)\n", __func__, ep, ep->
name, value);
2785 if (epctl & DxEPCTL_EPEna)
2788 epctl &= ~DxEPCTL_Stall;
2803 epctl &= ~DxEPCTL_Stall;
2820 static int s3c_hsotg_ep_sethalt_lock(
struct usb_ep *ep,
int value)
2824 unsigned long flags = 0;
2828 ret = s3c_hsotg_ep_sethalt(ep, value);
2829 spin_unlock_irqrestore(&hs->
lock, flags);
2834 static struct usb_ep_ops s3c_hsotg_ep_ops = {
2835 .enable = s3c_hsotg_ep_enable,
2836 .disable = s3c_hsotg_ep_disable,
2837 .alloc_request = s3c_hsotg_ep_alloc_request,
2838 .free_request = s3c_hsotg_ep_free_request,
2839 .queue = s3c_hsotg_ep_queue_lock,
2840 .dequeue = s3c_hsotg_ep_dequeue,
2841 .set_halt = s3c_hsotg_ep_sethalt_lock,
2852 static void s3c_hsotg_phy_enable(
struct s3c_hsotg *hsotg)
2857 if (hsotg->
plat->phy_init)
2858 hsotg->
plat->phy_init(pdev, hsotg->
plat->phy_type);
2868 static void s3c_hsotg_phy_disable(
struct s3c_hsotg *hsotg)
2872 if (hsotg->
plat->phy_exit)
2873 hsotg->
plat->phy_exit(pdev, hsotg->
plat->phy_type);
2880 static void s3c_hsotg_init(
struct s3c_hsotg *hsotg)
2905 dev_dbg(hsotg->
dev,
"GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
2909 s3c_hsotg_init_fifo(hsotg);
2927 static int s3c_hsotg_udc_start(
struct usb_gadget *gadget,
2930 struct s3c_hsotg *hsotg = to_hsotg(gadget);
2939 dev_err(hsotg->
dev,
"%s: no driver\n", __func__);
2944 dev_err(hsotg->
dev,
"%s: bad speed\n", __func__);
2946 if (!driver->
setup) {
2947 dev_err(hsotg->
dev,
"%s: missing entry points\n", __func__);
2956 hsotg->
gadget.dev.of_node = hsotg->
dev->of_node;
2957 hsotg->
gadget.dev.dma_mask = hsotg->
dev->dma_mask;
2963 dev_err(hsotg->
dev,
"failed to enable supplies: %d\n", ret);
2984 static int s3c_hsotg_udc_stop(
struct usb_gadget *gadget,
2987 struct s3c_hsotg *hsotg = to_hsotg(gadget);
2988 unsigned long flags = 0;
2994 if (!driver || driver != hsotg->
driver || !driver->
unbind)
2999 s3c_hsotg_ep_disable(&hsotg->
eps[ep].ep);
3003 s3c_hsotg_phy_disable(hsotg);
3010 spin_unlock_irqrestore(&hsotg->
lock, flags);
3012 dev_info(hsotg->
dev,
"unregistered gadget driver '%s'\n",
3024 static int s3c_hsotg_gadget_getframe(
struct usb_gadget *gadget)
3026 return s3c_hsotg_read_frameno(to_hsotg(gadget));
3036 static int s3c_hsotg_pullup(
struct usb_gadget *gadget,
int is_on)
3038 struct s3c_hsotg *hsotg = to_hsotg(gadget);
3039 unsigned long flags = 0;
3041 dev_dbg(hsotg->
dev,
"%s: is_in: %d\n", __func__, is_on);
3045 s3c_hsotg_phy_enable(hsotg);
3046 s3c_hsotg_core_init(hsotg);
3048 s3c_hsotg_disconnect(hsotg);
3049 s3c_hsotg_phy_disable(hsotg);
3053 spin_unlock_irqrestore(&hsotg->
lock, flags);
3059 .get_frame = s3c_hsotg_gadget_getframe,
3060 .udc_start = s3c_hsotg_udc_start,
3061 .udc_stop = s3c_hsotg_udc_stop,
3062 .pullup = s3c_hsotg_pullup,
3084 else if ((epnum % 2) == 0) {
3091 hs_ep->
index = epnum;
3095 INIT_LIST_HEAD(&hs_ep->
queue);
3096 INIT_LIST_HEAD(&hs_ep->
ep.ep_list);
3103 hs_ep->
ep.name = hs_ep->
name;
3105 hs_ep->
ep.ops = &s3c_hsotg_ep_ops;
3121 if (using_dma(hsotg)) {
3134 static void s3c_hsotg_hw_cfg(
struct s3c_hsotg *hsotg)
3155 static void s3c_hsotg_dump(
struct s3c_hsotg *hsotg)
3163 dev_info(dev,
"DCFG=0x%08x, DCTL=0x%08x, DIEPMSK=%08x\n",
3167 dev_info(dev,
"GAHBCFG=0x%08x, 0x44=0x%08x\n",
3170 dev_info(dev,
"GRXFSIZ=0x%08x, GNPTXFSIZ=0x%08x\n",
3175 for (idx = 1; idx <= 15; idx++) {
3177 dev_info(dev,
"DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx,
3178 val >> DPTXFSIZn_DPTxFSize_SHIFT,
3182 for (idx = 0; idx < 15; idx++) {
3184 "ep%d-in: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n", idx,
3191 "ep%d-out: EPCTL=0x%08x, SIZ=0x%08x, DMA=0x%08x\n",
3198 dev_info(dev,
"DVBUSDIS=0x%08x, DVBUSPULSE=%08x\n",
3212 static int state_show(
struct seq_file *seq,
void *
v)
3218 seq_printf(seq,
"DCFG=0x%08x, DCTL=0x%08x, DSTS=0x%08x\n",
3223 seq_printf(seq,
"DIEPMSK=0x%08x, DOEPMASK=0x%08x\n",
3226 seq_printf(seq,
"GINTMSK=0x%08x, GINTSTS=0x%08x\n",
3230 seq_printf(seq,
"DAINTMSK=0x%08x, DAINT=0x%08x\n",
3234 seq_printf(seq,
"GNPTXSTS=0x%08x, GRXSTSR=%08x\n",
3240 for (idx = 0; idx < 15; idx++) {
3246 seq_printf(seq,
"ep%d: DIEPCTL=0x%08x, DOEPCTL=0x%08x",
3252 seq_printf(seq,
", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x",
3282 static int fifo_show(
struct seq_file *seq,
void *v)
3293 seq_printf(seq,
"NPTXFIFO: Size %d, Start 0x%08x\n",
3299 for (idx = 1; idx <= 15; idx++) {
3302 seq_printf(seq,
"\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx,
3303 val >> DPTXFSIZn_DPTxFSize_SHIFT,
3324 static const char *decode_direction(
int is_in)
3326 return is_in ?
"in" :
"out";
3337 static int ep_show(
struct seq_file *seq,
void *v)
3343 int index = ep->
index;
3344 int show_limit = 15;
3345 unsigned long flags;
3347 seq_printf(seq,
"Endpoint index %d, named %s, dir %s:\n",
3352 seq_printf(seq,
"\tDIEPCTL=0x%08x, DOEPCTL=0x%08x\n",
3356 seq_printf(seq,
"\tDIEPDMA=0x%08x, DOEPDMA=0x%08x\n",
3360 seq_printf(seq,
"\tDIEPINT=0x%08x, DOEPINT=0x%08x\n",
3364 seq_printf(seq,
"\tDIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x\n",
3378 if (--show_limit < 0) {
3379 seq_printf(seq,
"not showing more requests...\n");
3384 req == ep->
req ?
'*' :
' ',
3385 req, req->
req.length, req->
req.buf);
3387 req->
req.actual, req->
req.status);
3390 spin_unlock_irqrestore(&hsotg->
lock, flags);
3425 dev_err(hsotg->
dev,
"cannot create debug root\n");
3432 hsotg, &state_fops);
3435 dev_err(hsotg->
dev,
"%s: failed to create state\n", __func__);
3441 dev_err(hsotg->
dev,
"%s: failed to create fifo\n", __func__);
3445 for (epidx = 0; epidx < hsotg->
num_of_eps; epidx++) {
3449 root, ep, &ep_fops);
3452 dev_err(hsotg->
dev,
"failed to create %s debug file\n",
3467 for (epidx = 0; epidx < hsotg->
num_of_eps; epidx++) {
3481 static void s3c_hsotg_release(
struct device *dev)
3504 plat = pdev->
dev.platform_data;
3506 dev_err(&pdev->
dev,
"no platform data defined\n");
3512 dev_err(dev,
"cannot get memory\n");
3520 if (IS_ERR(hsotg->
clk)) {
3521 dev_err(dev,
"cannot get otg clock\n");
3522 return PTR_ERR(hsotg->
clk);
3525 platform_set_drvdata(pdev, hsotg);
3531 dev_err(dev,
"cannot map registers\n");
3538 dev_err(dev,
"cannot find IRQ\n");
3546 ret = devm_request_irq(&pdev->
dev, hsotg->
irq, s3c_hsotg_irq, 0,
3547 dev_name(dev), hsotg);
3549 dev_err(dev,
"cannot claim IRQ\n");
3560 hsotg->
gadget.ops = &s3c_hsotg_gadget_ops;
3561 hsotg->
gadget.name = dev_name(dev);
3565 hsotg->
gadget.dev.release = s3c_hsotg_release;
3569 clk_prepare_enable(hsotg->
clk);
3574 hsotg->
supplies[i].supply = s3c_hsotg_supply_names[i];
3579 dev_err(dev,
"failed to request supplies: %d\n", ret);
3587 dev_err(hsotg->
dev,
"failed to enable supplies: %d\n", ret);
3592 s3c_hsotg_phy_enable(hsotg);
3594 s3c_hsotg_corereset(hsotg);
3595 s3c_hsotg_init(hsotg);
3596 s3c_hsotg_hw_cfg(hsotg);
3601 dev_err(dev,
"wrong number of EPs (zero)\n");
3609 dev_err(dev,
"cannot get memory\n");
3618 INIT_LIST_HEAD(&hsotg->
gadget.ep_list);
3623 hsotg->
ctrl_req = s3c_hsotg_ep_alloc_request(&hsotg->
eps[0].ep,
3626 dev_err(dev,
"failed to allocate ctrl req\n");
3632 for (epnum = 0; epnum < hsotg->
num_of_eps; epnum++)
3633 s3c_hsotg_initep(hsotg, &hsotg->
eps[epnum], epnum);
3640 dev_err(hsotg->
dev,
"failed to disable supplies: %d\n", ret);
3644 s3c_hsotg_phy_disable(hsotg);
3656 s3c_hsotg_create_debug(hsotg);
3658 s3c_hsotg_dump(hsotg);
3665 s3c_hsotg_phy_disable(hsotg);
3669 clk_disable_unprepare(hsotg->
clk);
3680 struct s3c_hsotg *hsotg = platform_get_drvdata(pdev);
3684 s3c_hsotg_delete_debug(hsotg);
3691 s3c_hsotg_phy_disable(hsotg);
3694 clk_disable_unprepare(hsotg->
clk);
3701 #define s3c_hsotg_suspend NULL
3702 #define s3c_hsotg_resume NULL
3707 .name =
"s3c-hsotg",
3710 .probe = s3c_hsotg_probe,