Lines Matching refs:pipe
11 #include "pipe.h"
33 char *usbhs_pipe_name(struct usbhs_pipe *pipe)
35 return usbhsp_pipe_name[usbhs_pipe_type(pipe)];
50 static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
52 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
53 int offset = usbhsp_addr_offset(pipe);
55 if (usbhs_pipe_is_dcp(pipe))
61 static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
63 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
64 int offset = usbhsp_addr_offset(pipe);
66 if (usbhs_pipe_is_dcp(pipe))
75 static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
79 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
81 if (usbhs_pipe_is_dcp(pipe))
87 static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
90 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
92 if (usbhs_pipe_is_dcp(pipe))
101 static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
103 __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
106 static u16 usbhsp_pipe_cfg_get(struct usbhs_pipe *pipe)
108 return __usbhsp_pipe_xxx_get(pipe, DCPCFG, PIPECFG);
114 static void usbhsp_pipe_trn_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
116 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
118 int num = usbhs_pipe_number(pipe);
144 dev_err(dev, "unknown pipe (%d)\n", num);
147 __usbhsp_pipe_xxx_set(pipe, 0, reg, mask, val);
150 static void usbhsp_pipe_tre_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
152 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
154 int num = usbhs_pipe_number(pipe);
180 dev_err(dev, "unknown pipe (%d)\n", num);
184 __usbhsp_pipe_xxx_set(pipe, 0, reg, mask, val);
190 static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
192 if (usbhs_pipe_is_dcp(pipe))
195 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
201 static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
203 __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
207 * pipe control functions
209 static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
211 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
214 * On pipe, this is necessary before
225 * if pipe is dcp, no pipe is selected.
228 usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
231 static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
233 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
240 * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
243 * the PID bits for the selected pipe from BUF to NAK,
256 usbhs_pipe_disable(pipe);
259 if (!(usbhsp_pipectrl_get(pipe) & mask))
269 int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
273 val = usbhsp_pipectrl_get(pipe);
280 bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
284 /* Do not support for DCP pipe */
285 if (usbhs_pipe_is_dcp(pipe))
288 val = usbhsp_pipectrl_get(pipe);
298 static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
300 u16 pid = usbhsp_pipectrl_get(pipe);
310 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
313 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
317 void usbhs_pipe_disable(struct usbhs_pipe *pipe)
323 __usbhsp_pid_try_nak_if_stall(pipe);
325 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
328 val = usbhsp_pipectrl_get(pipe);
337 void usbhs_pipe_enable(struct usbhs_pipe *pipe)
340 __usbhsp_pid_try_nak_if_stall(pipe);
342 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
345 void usbhs_pipe_stall(struct usbhs_pipe *pipe)
347 u16 pid = usbhsp_pipectrl_get(pipe);
357 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
360 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
365 int usbhs_pipe_is_stall(struct usbhs_pipe *pipe)
367 u16 pid = usbhsp_pipectrl_get(pipe) & PID_MASK;
372 void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len)
374 if (!usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
378 * clear and disable transfer counter for IN/OUT pipe
380 usbhsp_pipe_tre_set(pipe, TRCLR | TRENB, TRCLR);
383 * Only IN direction bulk pipe can use transfer count.
388 if (usbhs_pipe_is_dir_in(pipe)) {
389 int maxp = usbhs_pipe_get_maxpacket(pipe);
391 usbhsp_pipe_trn_set(pipe, 0xffff, DIV_ROUND_UP(len, maxp));
392 usbhsp_pipe_tre_set(pipe, TRENB, TRENB); /* enable */
398 * pipe setup
400 static int usbhsp_setup_pipecfg(struct usbhs_pipe *pipe, int is_host,
416 if (usbhs_pipe_is_dcp(pipe))
429 type = type_array[usbhs_pipe_type(pipe)];
432 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
433 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
439 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
444 usbhsp_flags_set(pipe, IS_DIR_HOST);
450 usbhsp_flags_set(pipe, IS_DIR_IN);
453 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
469 static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe)
471 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
473 int pipe_num = usbhs_pipe_number(pipe);
495 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
502 void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
505 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
506 int pipe_num = usbhs_pipe_number(pipe);
519 usbhsp_pipe_barrier(pipe);
521 pipe->maxp = maxp;
523 usbhsp_pipe_select(pipe);
524 usbhsp_pipe_maxp_set(pipe, 0xFFFF,
528 if (!usbhs_pipe_is_dcp(pipe))
529 usbhsp_pipe_cfg_set(pipe, 0x000F | DBLB, epnum | dblb);
533 * pipe control
535 int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
542 return pipe->maxp;
545 int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
547 return usbhsp_flags_has(pipe, IS_DIR_IN);
550 int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe)
552 return usbhsp_flags_has(pipe, IS_DIR_HOST);
555 int usbhs_pipe_is_running(struct usbhs_pipe *pipe)
557 return usbhsp_flags_has(pipe, IS_RUNNING);
560 void usbhs_pipe_running(struct usbhs_pipe *pipe, int running)
563 usbhsp_flags_set(pipe, IS_RUNNING);
565 usbhsp_flags_clr(pipe, IS_RUNNING);
568 void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence)
590 usbhsp_pipectrl_set(pipe, mask, val);
593 static int usbhs_pipe_get_data_sequence(struct usbhs_pipe *pipe)
595 return !!(usbhsp_pipectrl_get(pipe) & SQMON);
598 void usbhs_pipe_clear(struct usbhs_pipe *pipe)
600 if (usbhs_pipe_is_dcp(pipe)) {
601 usbhs_fifo_clear_dcp(pipe);
603 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
604 usbhsp_pipectrl_set(pipe, ACLRM, 0);
609 void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
614 usbhsp_pipe_select(pipe);
615 sequence = usbhs_pipe_get_data_sequence(pipe);
617 usbhsp_pipe_cfg_set(pipe, BFRE, bfre_enable ? BFRE : 0);
618 usbhs_pipe_clear(pipe);
619 usbhs_pipe_data_sequence(pipe, sequence);
622 void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable)
624 if (usbhs_pipe_is_dcp(pipe))
627 usbhsp_pipe_select(pipe);
629 if (!(enable ^ !!(usbhsp_pipe_cfg_get(pipe) & BFRE)))
632 usbhs_pipe_clear_without_sequence(pipe, 1, enable);
637 struct usbhs_pipe *pos, *pipe;
641 * find target pipe
643 pipe = NULL;
650 pipe = pos;
654 if (!pipe)
658 * initialize pipe flags
660 usbhsp_flags_init(pipe);
661 usbhsp_flags_set(pipe, IS_USED);
663 return pipe;
666 static void usbhsp_put_pipe(struct usbhs_pipe *pipe)
668 usbhsp_flags_init(pipe);
676 struct usbhs_pipe *pipe;
679 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
680 usbhsp_flags_init(pipe);
681 pipe->fifo = NULL;
682 pipe->mod_private = NULL;
683 INIT_LIST_HEAD(&pipe->list);
685 /* pipe force init */
686 usbhs_pipe_clear(pipe);
697 struct usbhs_pipe *pipe;
702 pipe = usbhsp_get_pipe(priv, endpoint_type);
703 if (!pipe) {
704 dev_err(dev, "can't get pipe (%s)\n",
709 INIT_LIST_HEAD(&pipe->list);
711 usbhs_pipe_disable(pipe);
713 /* make sure pipe is not busy */
714 ret = usbhsp_pipe_barrier(pipe);
716 dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
720 if (usbhsp_setup_pipecfg(pipe, is_host, dir_in, &pipecfg)) {
721 dev_err(dev, "can't setup pipe\n");
725 pipebuf = usbhsp_setup_pipebuff(pipe);
727 usbhsp_pipe_select(pipe);
728 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
729 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
730 usbhs_pipe_clear(pipe);
732 usbhs_pipe_sequence_data0(pipe);
734 dev_dbg(dev, "enable pipe %d : %s (%s)\n",
735 usbhs_pipe_number(pipe),
736 usbhs_pipe_name(pipe),
737 usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
740 * epnum / maxp are still not set to this pipe.
744 return pipe;
747 void usbhs_pipe_free(struct usbhs_pipe *pipe)
749 usbhsp_pipe_select(pipe);
750 usbhsp_pipe_cfg_set(pipe, 0xFFFF, 0);
751 usbhsp_put_pipe(pipe);
754 void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
756 if (pipe->fifo)
757 pipe->fifo->pipe = NULL;
759 pipe->fifo = fifo;
762 fifo->pipe = pipe;
771 struct usbhs_pipe *pipe;
773 pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
774 if (!pipe)
777 INIT_LIST_HEAD(&pipe->list);
783 return pipe;
786 void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
788 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
790 WARN_ON(!usbhs_pipe_is_dcp(pipe));
792 usbhs_pipe_enable(pipe);
795 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
798 void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out)
800 usbhsp_pipe_cfg_set(pipe, DIR_OUT,
805 * pipe module function
810 struct usbhs_pipe *pipe;
817 /* This driver expects 1st pipe is DCP */
823 info->pipe = kcalloc(pipe_size, sizeof(struct usbhs_pipe),
825 if (!info->pipe)
831 * init pipe
833 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
834 pipe->priv = priv;
836 usbhs_pipe_type(pipe) =
839 dev_dbg(dev, "pipe %x\t: %s\n",
850 kfree(info->pipe);