23 #define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo))
24 #define usbhsf_get_d0fifo(p) (&((p)->fifo_info.d0fifo))
25 #define usbhsf_get_d1fifo(p) (&((p)->fifo_info.d1fifo))
26 #define usbhsf_is_cfifo(p, f) (usbhsf_get_cfifo(p) == f)
28 #define usbhsf_fifo_is_busy(f) ((f)->pipe)
36 INIT_LIST_HEAD(&pkt->
node);
42 static int usbhsf_null_handle(
struct usbhs_pkt *pkt,
int *is_done)
53 .prepare = usbhsf_null_handle,
54 .try_run = usbhsf_null_handle,
67 dev_err(dev,
"no done function\n");
75 dev_err(dev,
"no handler function\n");
76 pipe->
handler = &usbhsf_null_handler;
79 list_move_tail(&pkt->
node, &pipe->
list);
99 static void __usbhsf_pkt_del(
struct usbhs_pkt *pkt)
101 list_del_init(&pkt->
node);
106 if (list_empty(&pipe->
list))
121 pkt = __usbhsf_pkt_get(pipe);
124 __usbhsf_pkt_del(pkt);
151 pkt = __usbhsf_pkt_get(pipe);
153 goto __usbhs_pkt_handler_end;
166 dev_err(dev,
"unknown pkt hander\n");
167 goto __usbhs_pkt_handler_end;
170 ret =
func(pkt, &is_done);
173 __usbhsf_pkt_del(pkt);
175 __usbhs_pkt_handler_end:
180 pkt->
done(priv, pkt);
195 #define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
196 #define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
197 #define usbhsf_irq_callback_ctrl(pipe, status, enable) \
199 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
200 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
201 u16 status = (1 << usbhs_pipe_number(pipe)); \
205 mod->irq_##status |= status; \
207 mod->irq_##status &= ~status; \
208 usbhs_irq_callback_update(priv, mod); \
236 static void usbhsf_send_terminator(
struct usbhs_pipe *pipe,
244 static int usbhsf_fifo_barrier(
struct usbhs_priv *priv,
260 static void usbhsf_fifo_clear(
struct usbhs_pipe *pipe,
266 usbhsf_fifo_barrier(priv, fifo);
271 static int usbhsf_fifo_rcv_len(
struct usbhs_priv *priv,
277 static void usbhsf_fifo_unselect(
struct usbhs_pipe *pipe,
286 static int usbhsf_fifo_select(
struct usbhs_pipe *pipe,
301 base |= (1 ==
write) << 5;
322 dev_err(dev,
"fifo select error\n");
330 static int usbhs_dcp_dir_switch_to_write(
struct usbhs_pkt *pkt,
int *is_done)
340 ret = usbhsf_fifo_select(pipe, fifo, 1);
342 dev_err(dev,
"%s() faile\n", __func__);
348 usbhsf_fifo_clear(pipe, fifo);
349 usbhsf_send_terminator(pipe, fifo);
351 usbhsf_fifo_unselect(pipe, fifo);
353 usbhsf_tx_irq_ctrl(pipe, 1);
359 static int usbhs_dcp_dir_switch_to_read(
struct usbhs_pkt *pkt,
int *is_done)
369 ret = usbhsf_fifo_select(pipe, fifo, 0);
371 dev_err(dev,
"%s() fail\n", __func__);
376 usbhsf_fifo_clear(pipe, fifo);
378 usbhsf_fifo_unselect(pipe, fifo);
380 usbhsf_rx_irq_ctrl(pipe, 1);
387 static int usbhs_dcp_dir_switch_done(
struct usbhs_pkt *pkt,
int *is_done)
392 usbhsf_tx_irq_ctrl(pipe, 0);
394 usbhsf_rx_irq_ctrl(pipe, 0);
403 .prepare = usbhs_dcp_dir_switch_to_write,
404 .try_run = usbhs_dcp_dir_switch_done,
408 .prepare = usbhs_dcp_dir_switch_to_read,
409 .try_run = usbhs_dcp_dir_switch_done,
415 static int usbhsf_dcp_data_stage_try_push(
struct usbhs_pkt *pkt,
int *is_done)
426 return pkt->
handler->prepare(pkt, is_done);
430 .prepare = usbhsf_dcp_data_stage_try_push,
436 static int usbhsf_dcp_data_stage_prepare_pop(
struct usbhs_pkt *pkt,
456 usbhsf_fifo_select(pipe, fifo, 0);
457 usbhsf_fifo_clear(pipe, fifo);
458 usbhsf_fifo_unselect(pipe, fifo);
465 return pkt->
handler->prepare(pkt, is_done);
469 .prepare = usbhsf_dcp_data_stage_prepare_pop,
475 static int usbhsf_pio_try_push(
struct usbhs_pkt *pkt,
int *is_done)
491 ret = usbhsf_fifo_select(pipe, fifo, 1);
499 goto usbhs_fifo_write_busy;
502 ret = usbhsf_fifo_barrier(priv, fifo);
504 goto usbhs_fifo_write_busy;
508 len =
min(len, maxp);
510 is_short = total_len < maxp;
517 if (len >= 4 && !((
unsigned long)buf & 0x03)) {
520 buf += total_len - len;
524 for (i = 0; i < len; i++)
525 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
537 *is_done = !pkt->
zero;
543 usbhsf_send_terminator(pipe, fifo);
545 usbhsf_tx_irq_ctrl(pipe, !*is_done);
548 dev_dbg(dev,
" send %d (%d/ %d/ %d/ %d)\n",
560 usbhsf_fifo_unselect(pipe, fifo);
564 usbhs_fifo_write_busy:
565 usbhsf_fifo_unselect(pipe, fifo);
571 usbhsf_tx_irq_ctrl(pipe, 1);
577 .prepare = usbhsf_pio_try_push,
578 .try_run = usbhsf_pio_try_push,
584 static int usbhsf_prepare_pop(
struct usbhs_pkt *pkt,
int *is_done)
598 usbhsf_rx_irq_ctrl(pipe, 1);
603 static int usbhsf_pio_try_pop(
struct usbhs_pkt *pkt,
int *is_done)
617 ret = usbhsf_fifo_select(pipe, fifo, 0);
621 ret = usbhsf_fifo_barrier(priv, fifo);
623 goto usbhs_fifo_read_busy;
625 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
629 len =
min(len, rcv_len);
640 (total_len < maxp)) {
642 usbhsf_rx_irq_ctrl(pipe, 0);
654 usbhsf_fifo_clear(pipe, fifo);
655 goto usbhs_fifo_read_end;
663 if (len >= 4 && !((
unsigned long)buf & 0x03)) {
666 buf += total_len - len;
670 for (i = 0; i < len; i++) {
674 buf[
i] = (data >> ((i & 0x03) * 8)) & 0xff;
678 dev_dbg(dev,
" recv %d (%d/ %d/ %d/ %d)\n",
682 usbhs_fifo_read_busy:
683 usbhsf_fifo_unselect(pipe, fifo);
689 .prepare = usbhsf_prepare_pop,
690 .try_run = usbhsf_pio_try_pop,
696 static int usbhsf_ctrl_stage_end(
struct usbhs_pkt *pkt,
int *is_done)
706 .prepare = usbhsf_ctrl_stage_end,
707 .try_run = usbhsf_ctrl_stage_end,
732 if (usbhsf_dma_chan_get(fifo, pkt) &&
738 if (usbhsf_dma_chan_get(fifo, pkt) &&
745 #define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
746 #define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
747 static void __usbhsf_dma_ctrl(
struct usbhs_pipe *pipe,
756 #define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
757 #define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
758 static int __usbhsf_dma_map_ctrl(
struct usbhs_pkt *pkt,
int map)
767 static void usbhsf_dma_complete(
void *
arg);
781 desc = dmaengine_prep_slave_single(chan, pkt->
dma + pkt->
actual,
787 desc->
callback = usbhsf_dma_complete;
790 if (dmaengine_submit(desc) < 0) {
791 dev_err(dev,
"Failed to submit dma descriptor\n");
795 dev_dbg(dev,
" %s %d (%d/ %d)\n",
800 dma_async_issue_pending(chan);
806 static int usbhsf_dma_prepare_push(
struct usbhs_pkt *pkt,
int *is_done)
820 goto usbhsf_pio_prepare_push;
823 goto usbhsf_pio_prepare_push;
826 goto usbhsf_pio_prepare_push;
829 fifo = usbhsf_get_dma_fifo(priv, pkt);
831 goto usbhsf_pio_prepare_push;
834 goto usbhsf_pio_prepare_push;
836 ret = usbhsf_fifo_select(pipe, fifo, 0);
838 goto usbhsf_pio_prepare_push_unmap;
847 usbhsf_pio_prepare_push_unmap:
849 usbhsf_pio_prepare_push:
855 return pkt->
handler->prepare(pkt, is_done);
858 static int usbhsf_dma_push_done(
struct usbhs_pkt *pkt,
int *is_done)
864 *is_done = !pkt->
zero;
868 usbhsf_fifo_unselect(pipe, pipe->
fifo);
874 .prepare = usbhsf_dma_prepare_push,
875 .dma_done = usbhsf_dma_push_done,
881 static int usbhsf_dma_try_pop(
struct usbhs_pkt *pkt,
int *is_done)
892 goto usbhsf_pio_prepare_pop;
895 fifo = usbhsf_get_dma_fifo(priv, pkt);
897 goto usbhsf_pio_prepare_pop;
900 goto usbhsf_pio_prepare_pop;
902 ret = usbhsf_fifo_select(pipe, fifo, 0);
904 goto usbhsf_pio_prepare_pop;
907 len = usbhsf_fifo_rcv_len(priv, fifo);
910 goto usbhsf_pio_prepare_pop_unselect;
913 goto usbhsf_pio_prepare_pop_unselect;
915 ret = usbhsf_fifo_barrier(priv, fifo);
917 goto usbhsf_pio_prepare_pop_unselect;
920 goto usbhsf_pio_prepare_pop_unselect;
929 usbhsf_rx_irq_ctrl(pipe, 0);
938 usbhsf_pio_prepare_pop_unselect:
939 usbhsf_fifo_unselect(pipe, fifo);
940 usbhsf_pio_prepare_pop:
947 return pkt->
handler->try_run(pkt, is_done);
950 static int usbhsf_dma_pop_done(
struct usbhs_pkt *pkt,
int *is_done)
957 usbhsf_fifo_unselect(pipe, pipe->
fifo);
962 (pkt->
trans < maxp)) {
966 usbhsf_prepare_pop(pkt, is_done);
973 .prepare = usbhsf_prepare_pop,
974 .try_run = usbhsf_dma_try_pop,
975 .dma_done = usbhsf_dma_pop_done
981 static bool usbhsf_dma_filter(
struct dma_chan *chan,
void *
param)
1009 static void usbhsf_dma_init(
struct usbhs_priv *priv,
1026 dev_dbg(dev,
"enable DMAEngine (%s%s%s)\n",
1029 fifo->
rx_chan ?
"[RX]" :
" ");
1035 static int usbhsf_irq_empty(
struct usbhs_priv *priv,
1043 dev_err(dev,
"debug %s !!\n", __func__);
1054 if (!(irq_state->
bempsts & (1 << i)))
1059 dev_err(dev,
"irq_empty run_error %d : %d\n", i, ret);
1065 static int usbhsf_irq_ready(
struct usbhs_priv *priv,
1073 dev_err(dev,
"debug %s !!\n", __func__);
1084 if (!(irq_state->
brdysts & (1 << i)))
1089 dev_err(dev,
"irq_ready run_error %d : %d\n", i, ret);
1095 static void usbhsf_dma_complete(
void *
arg)
1104 dev_err(dev,
"dma_complete run_error %d : %d\n",
1158 fifo->
name =
"CFIFO";
1165 fifo->
name =
"D0FIFO";
1174 fifo->
name =
"D1FIFO";