Add linux-next specific files for 20110421
[linux-2.6/next.git] / drivers / usb / renesas_usbhs / pipe.c
blobb7a9137f599baf7618e46aa49fef1fc4d1fe3de2
1 /*
2 * Renesas USB driver
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 #include <linux/delay.h>
18 #include <linux/io.h>
19 #include <linux/slab.h>
20 #include "./common.h"
21 #include "./pipe.h"
24 * macros
26 #define usbhsp_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
27 #define usbhsp_pipe_to_priv(p) ((p)->priv)
29 #define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
31 #define usbhsp_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
33 #define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
34 #define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
35 #define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
36 #define usbhsp_flags_init(p) do {(p)->flags = 0; } while (0)
38 #define usbhsp_type(p) ((p)->pipe_type)
39 #define usbhsp_type_is(p, t) ((p)->pipe_type == t)
42 * for debug
44 static char *usbhsp_pipe_name[] = {
45 [USB_ENDPOINT_XFER_CONTROL] = "DCP",
46 [USB_ENDPOINT_XFER_BULK] = "BULK",
47 [USB_ENDPOINT_XFER_INT] = "INT",
48 [USB_ENDPOINT_XFER_ISOC] = "ISO",
52 * usb request functions
54 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
56 u16 val;
58 val = usbhs_read(priv, USBREQ);
59 req->bRequest = (val >> 8) & 0xFF;
60 req->bRequestType = (val >> 0) & 0xFF;
62 req->wValue = usbhs_read(priv, USBVAL);
63 req->wIndex = usbhs_read(priv, USBINDX);
64 req->wLength = usbhs_read(priv, USBLENG);
67 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
69 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
70 usbhs_write(priv, USBVAL, req->wValue);
71 usbhs_write(priv, USBINDX, req->wIndex);
72 usbhs_write(priv, USBLENG, req->wLength);
76 * DCPCTR/PIPEnCTR functions
78 static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
80 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
81 int offset = usbhsp_addr_offset(pipe);
83 if (usbhsp_is_dcp(pipe))
84 usbhs_bset(priv, DCPCTR, mask, val);
85 else
86 usbhs_bset(priv, PIPEnCTR + offset, mask, val);
89 static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
91 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
92 int offset = usbhsp_addr_offset(pipe);
94 if (usbhsp_is_dcp(pipe))
95 return usbhs_read(priv, DCPCTR);
96 else
97 return usbhs_read(priv, PIPEnCTR + offset);
101 * DCP/PIPE functions
103 static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
104 u16 dcp_reg, u16 pipe_reg,
105 u16 mask, u16 val)
107 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
109 if (usbhsp_is_dcp(pipe))
110 usbhs_bset(priv, dcp_reg, mask, val);
111 else
112 usbhs_bset(priv, pipe_reg, mask, val);
115 static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
116 u16 dcp_reg, u16 pipe_reg)
118 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
120 if (usbhsp_is_dcp(pipe))
121 return usbhs_read(priv, dcp_reg);
122 else
123 return usbhs_read(priv, pipe_reg);
127 * DCPCFG/PIPECFG functions
129 static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
131 __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
135 * PIPEBUF
137 static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
139 if (usbhsp_is_dcp(pipe))
140 return;
142 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
146 * DCPMAXP/PIPEMAXP
148 static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
150 __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
153 static u16 usbhsp_pipe_maxp_get(struct usbhs_pipe *pipe)
155 return __usbhsp_pipe_xxx_get(pipe, DCPMAXP, PIPEMAXP);
159 * pipe control functions
161 static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
163 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
166 * On pipe, this is necessary before
167 * accesses to below registers.
169 * PIPESEL : usbhsp_pipe_select
170 * PIPECFG : usbhsp_pipe_cfg_xxx
171 * PIPEBUF : usbhsp_pipe_buf_xxx
172 * PIPEMAXP : usbhsp_pipe_maxp_xxx
173 * PIPEPERI
177 * if pipe is dcp, no pipe is selected.
178 * it is no problem, because dcp have its register
180 usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
183 static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
185 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
186 struct device *dev = usbhs_priv_to_dev(priv);
187 int timeout = 1024;
188 u16 val;
191 * make sure....
193 * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
194 * specified by the CURPIPE bits.
195 * When changing the setting of this bit after changing
196 * the PID bits for the selected pipe from BUF to NAK,
197 * check that CSSTS = 0 and PBUSY = 0.
201 * CURPIPE bit = 0
203 * see also
204 * "Operation"
205 * - "Pipe Control"
206 * - "Pipe Control Registers Switching Procedure"
208 usbhs_write(priv, CFIFOSEL, 0);
210 do {
211 val = usbhsp_pipectrl_get(pipe);
212 val &= CSSTS | PID_MASK;
213 if (!val)
214 return 0;
216 udelay(10);
218 } while (timeout--);
221 * force NAK
223 timeout = 1024;
224 usbhs_fifo_disable(pipe);
225 do {
226 val = usbhsp_pipectrl_get(pipe);
227 val &= PBUSY;
228 if (!val)
229 return 0;
231 } while (timeout--);
233 dev_err(dev, "pipe barrier failed\n");
235 return -EBUSY;
238 static int usbhsp_pipe_is_accessible(struct usbhs_pipe *pipe)
240 u16 val;
242 val = usbhsp_pipectrl_get(pipe);
243 if (val & BSTS)
244 return 0;
246 return -EBUSY;
250 * PID ctrl
252 static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
254 u16 pid = usbhsp_pipectrl_get(pipe);
256 pid &= PID_MASK;
259 * see
260 * "Pipe n Control Register" - "PID"
262 switch (pid) {
263 case PID_STALL11:
264 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
265 /* fall-through */
266 case PID_STALL10:
267 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
271 void usbhs_fifo_disable(struct usbhs_pipe *pipe)
273 /* see "Pipe n Control Register" - "PID" */
274 __usbhsp_pid_try_nak_if_stall(pipe);
276 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
279 void usbhs_fifo_enable(struct usbhs_pipe *pipe)
281 /* see "Pipe n Control Register" - "PID" */
282 __usbhsp_pid_try_nak_if_stall(pipe);
284 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
287 void usbhs_fifo_stall(struct usbhs_pipe *pipe)
289 u16 pid = usbhsp_pipectrl_get(pipe);
291 pid &= PID_MASK;
294 * see
295 * "Pipe n Control Register" - "PID"
297 switch (pid) {
298 case PID_NAK:
299 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
300 break;
301 case PID_BUF:
302 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
303 break;
308 * CFIFO ctrl
310 void usbhs_fifo_send_terminator(struct usbhs_pipe *pipe)
312 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
314 usbhs_bset(priv, CFIFOCTR, BVAL, BVAL);
317 static void usbhsp_fifo_clear(struct usbhs_pipe *pipe)
319 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
321 usbhs_write(priv, CFIFOCTR, BCLR);
324 static int usbhsp_fifo_barrier(struct usbhs_priv *priv)
326 int timeout = 1024;
328 do {
329 /* The FIFO port is accessible */
330 if (usbhs_read(priv, CFIFOCTR) & FRDY)
331 return 0;
333 udelay(10);
334 } while (timeout--);
336 return -EBUSY;
339 static int usbhsp_fifo_rcv_len(struct usbhs_priv *priv)
341 return usbhs_read(priv, CFIFOCTR) & DTLN_MASK;
344 static int usbhsp_fifo_select(struct usbhs_pipe *pipe, int write)
346 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
347 struct device *dev = usbhs_priv_to_dev(priv);
348 int timeout = 1024;
349 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
350 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
352 if (usbhsp_is_dcp(pipe))
353 base |= (1 == write) << 5; /* ISEL */
355 /* "base" will be used below */
356 usbhs_write(priv, CFIFOSEL, base | MBW_32);
358 /* check ISEL and CURPIPE value */
359 while (timeout--) {
360 if (base == (mask & usbhs_read(priv, CFIFOSEL)))
361 return 0;
362 udelay(10);
365 dev_err(dev, "fifo select error\n");
367 return -EIO;
370 int usbhs_fifo_prepare_write(struct usbhs_pipe *pipe)
372 int ret;
374 ret = usbhsp_fifo_select(pipe, 1);
375 if (ret < 0)
376 return ret;
378 usbhsp_fifo_clear(pipe);
380 return ret;
383 int usbhs_fifo_write(struct usbhs_pipe *pipe, u8 *buf, int len)
385 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
386 void __iomem *addr = priv->base + CFIFO;
387 int maxp = usbhs_pipe_get_maxpacket(pipe);
388 int total_len;
389 int i, ret;
391 ret = usbhsp_pipe_is_accessible(pipe);
392 if (ret < 0)
393 return ret;
395 ret = usbhs_fifo_prepare_write(pipe);
396 if (ret < 0)
397 return ret;
399 ret = usbhsp_fifo_barrier(priv);
400 if (ret < 0)
401 return ret;
403 len = min(len, maxp);
404 total_len = len;
407 * FIXME
409 * 32-bit access only
411 if (len >= 4 &&
412 !((unsigned long)buf & 0x03)) {
413 iowrite32_rep(addr, buf, len / 4);
414 len %= 4;
415 buf += total_len - len;
418 /* the rest operation */
419 for (i = 0; i < len; i++)
420 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
422 if (total_len < maxp)
423 usbhs_fifo_send_terminator(pipe);
425 return total_len;
428 int usbhs_fifo_prepare_read(struct usbhs_pipe *pipe)
430 int ret;
433 * select pipe and enable it to prepare packet receive
435 ret = usbhsp_fifo_select(pipe, 0);
436 if (ret < 0)
437 return ret;
439 usbhs_fifo_enable(pipe);
441 return ret;
444 int usbhs_fifo_read(struct usbhs_pipe *pipe, u8 *buf, int len)
446 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
447 void __iomem *addr = priv->base + CFIFO;
448 int rcv_len;
449 int i, ret;
450 int total_len;
451 u32 data = 0;
453 ret = usbhsp_fifo_select(pipe, 0);
454 if (ret < 0)
455 return ret;
457 ret = usbhsp_fifo_barrier(priv);
458 if (ret < 0)
459 return ret;
461 rcv_len = usbhsp_fifo_rcv_len(priv);
464 * Buffer clear if Zero-Length packet
466 * see
467 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
469 if (0 == rcv_len) {
470 usbhsp_fifo_clear(pipe);
471 return 0;
474 len = min(rcv_len, len);
475 total_len = len;
478 * FIXME
480 * 32-bit access only
482 if (len >= 4 &&
483 !((unsigned long)buf & 0x03)) {
484 ioread32_rep(addr, buf, len / 4);
485 len %= 4;
486 buf += rcv_len - len;
489 /* the rest operation */
490 for (i = 0; i < len; i++) {
491 if (!(i & 0x03))
492 data = ioread32(addr);
494 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
497 return total_len;
501 * pipe setup
503 static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
506 * only ISO / BULK pipe can use double buffer
508 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) ||
509 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
510 return 1;
512 return 0;
515 static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
516 const struct usb_endpoint_descriptor *desc,
517 int is_host)
519 u16 type = 0;
520 u16 bfre = 0;
521 u16 dblb = 0;
522 u16 cntmd = 0;
523 u16 dir = 0;
524 u16 epnum = 0;
525 u16 shtnak = 0;
526 u16 type_array[] = {
527 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
528 [USB_ENDPOINT_XFER_INT] = TYPE_INT,
529 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
531 int is_double = usbhsp_possible_double_buffer(pipe);
533 if (usbhsp_is_dcp(pipe))
534 return -EINVAL;
537 * PIPECFG
539 * see
540 * - "Register Descriptions" - "PIPECFG" register
541 * - "Features" - "Pipe configuration"
542 * - "Operation" - "Pipe Control"
545 /* TYPE */
546 type = type_array[usbhsp_type(pipe)];
548 /* BFRE */
549 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
550 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
551 bfre = 0; /* FIXME */
553 /* DBLB */
554 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
555 usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
556 dblb = (is_double) ? DBLB : 0;
558 /* CNTMD */
559 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK))
560 cntmd = 0; /* FIXME */
562 /* DIR */
563 if (usb_endpoint_dir_in(desc))
564 usbhsp_flags_set(pipe, IS_DIR_IN);
566 if ((is_host && usb_endpoint_dir_out(desc)) ||
567 (!is_host && usb_endpoint_dir_in(desc)))
568 dir |= DIR_OUT;
570 /* SHTNAK */
571 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
572 !dir)
573 shtnak = SHTNAK;
575 /* EPNUM */
576 epnum = 0xF & usb_endpoint_num(desc);
578 return type |
579 bfre |
580 dblb |
581 cntmd |
582 dir |
583 shtnak |
584 epnum;
587 static u16 usbhsp_setup_pipemaxp(struct usbhs_pipe *pipe,
588 const struct usb_endpoint_descriptor *desc,
589 int is_host)
591 /* host should set DEVSEL */
593 /* reutn MXPS */
594 return PIPE_MAXP_MASK & le16_to_cpu(desc->wMaxPacketSize);
597 static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
598 const struct usb_endpoint_descriptor *desc,
599 int is_host)
601 struct usbhs_priv *priv = usbhsp_pipe_to_priv(pipe);
602 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
603 struct device *dev = usbhs_priv_to_dev(priv);
604 int pipe_num = usbhs_pipe_number(pipe);
605 int is_double = usbhsp_possible_double_buffer(pipe);
606 u16 buff_size;
607 u16 bufnmb;
608 u16 bufnmb_cnt;
611 * PIPEBUF
613 * see
614 * - "Register Descriptions" - "PIPEBUF" register
615 * - "Features" - "Pipe configuration"
616 * - "Operation" - "FIFO Buffer Memory"
617 * - "Operation" - "Pipe Control"
619 * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724)
621 * BUFNMB: PIPE
622 * 0: pipe0 (DCP 256byte)
623 * 1: -
624 * 2: -
625 * 3: -
626 * 4: pipe6 (INT 64byte)
627 * 5: pipe7 (INT 64byte)
628 * 6: pipe8 (INT 64byte)
629 * 7: pipe9 (INT 64byte)
630 * 8 - xx: free (for BULK, ISOC)
634 * FIXME
636 * it doesn't have good buffer allocator
638 * DCP : 256 byte
639 * BULK: 512 byte
640 * INT : 64 byte
641 * ISOC: 512 byte
643 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_CONTROL))
644 buff_size = 256;
645 else if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
646 buff_size = 64;
647 else
648 buff_size = 512;
650 /* change buff_size to register value */
651 bufnmb_cnt = (buff_size / 64) - 1;
653 /* BUFNMB has been reserved for INT pipe
654 * see above */
655 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT)) {
656 bufnmb = pipe_num - 2;
657 } else {
658 bufnmb = info->bufnmb_last;
659 info->bufnmb_last += bufnmb_cnt + 1;
662 * double buffer
664 if (is_double)
665 info->bufnmb_last += bufnmb_cnt + 1;
668 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
669 pipe_num, buff_size, bufnmb);
671 return (0x1f & bufnmb_cnt) << 10 |
672 (0xff & bufnmb) << 0;
676 * pipe control
678 int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
680 u16 mask = usbhsp_is_dcp(pipe) ? DCP_MAXP_MASK : PIPE_MAXP_MASK;
682 usbhsp_pipe_select(pipe);
684 return (int)(usbhsp_pipe_maxp_get(pipe) & mask);
687 int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
689 return usbhsp_flags_has(pipe, IS_DIR_IN);
692 void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe)
694 usbhsp_pipectrl_set(pipe, SQCLR, SQCLR);
697 static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
699 struct usbhs_pipe *pos, *pipe;
700 int i;
703 * find target pipe
705 pipe = NULL;
706 usbhs_for_each_pipe_with_dcp(pos, priv, i) {
707 if (!usbhsp_type_is(pos, type))
708 continue;
709 if (usbhsp_flags_has(pos, IS_USED))
710 continue;
712 pipe = pos;
713 break;
716 if (!pipe)
717 return NULL;
720 * initialize pipe flags
722 usbhsp_flags_init(pipe);
723 usbhsp_flags_set(pipe, IS_USED);
725 return pipe;
728 void usbhs_pipe_init(struct usbhs_priv *priv)
730 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
731 struct usbhs_pipe *pipe;
732 int i;
735 * FIXME
737 * driver needs good allocator.
739 * find first free buffer area (BULK, ISOC)
740 * (DCP, INT area is fixed)
742 * buffer number 0 - 3 have been reserved for DCP
743 * see
744 * usbhsp_to_bufnmb
746 info->bufnmb_last = 4;
747 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
748 if (usbhsp_type_is(pipe, USB_ENDPOINT_XFER_INT))
749 info->bufnmb_last++;
751 usbhsp_flags_init(pipe);
752 pipe->mod_private = NULL;
756 struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
757 const struct usb_endpoint_descriptor *desc)
759 struct device *dev = usbhs_priv_to_dev(priv);
760 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
761 struct usbhs_pipe *pipe;
762 int is_host = usbhs_mod_is_host(priv, mod);
763 int ret;
764 u16 pipecfg, pipebuf, pipemaxp;
766 pipe = usbhsp_get_pipe(priv, usb_endpoint_type(desc));
767 if (!pipe)
768 return NULL;
770 usbhs_fifo_disable(pipe);
772 /* make sure pipe is not busy */
773 ret = usbhsp_pipe_barrier(pipe);
774 if (ret < 0) {
775 dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
776 return NULL;
779 pipecfg = usbhsp_setup_pipecfg(pipe, desc, is_host);
780 pipebuf = usbhsp_setup_pipebuff(pipe, desc, is_host);
781 pipemaxp = usbhsp_setup_pipemaxp(pipe, desc, is_host);
783 /* buffer clear
784 * see PIPECFG :: BFRE */
785 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
786 usbhsp_pipectrl_set(pipe, ACLRM, 0);
788 usbhsp_pipe_select(pipe);
789 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
790 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
791 usbhsp_pipe_maxp_set(pipe, 0xFFFF, pipemaxp);
793 usbhs_pipe_clear_sequence(pipe);
795 dev_dbg(dev, "enable pipe %d : %s (%s)\n",
796 usbhs_pipe_number(pipe),
797 usbhsp_pipe_name[usb_endpoint_type(desc)],
798 usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
800 return pipe;
804 * dcp control
806 struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
808 struct usbhs_pipe *pipe;
810 pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
811 if (!pipe)
812 return NULL;
815 * dcpcfg : default
816 * dcpmaxp : default
817 * pipebuf : nothing to do
820 usbhsp_pipe_select(pipe);
821 usbhs_pipe_clear_sequence(pipe);
823 return pipe;
826 void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
828 WARN_ON(!usbhsp_is_dcp(pipe));
830 usbhs_fifo_enable(pipe);
831 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
836 * pipe module function
838 int usbhs_pipe_probe(struct usbhs_priv *priv)
840 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
841 struct usbhs_pipe *pipe;
842 struct device *dev = usbhs_priv_to_dev(priv);
843 u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
844 int pipe_size = usbhs_get_dparam(priv, pipe_size);
845 int i;
847 /* This driver expects 1st pipe is DCP */
848 if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
849 dev_err(dev, "1st PIPE is not DCP\n");
850 return -EINVAL;
853 info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
854 if (!info->pipe) {
855 dev_err(dev, "Could not allocate pipe\n");
856 return -ENOMEM;
859 info->size = pipe_size;
862 * init pipe
864 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
865 pipe->priv = priv;
866 usbhsp_type(pipe) = pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
868 dev_dbg(dev, "pipe %x\t: %s\n",
869 i, usbhsp_pipe_name[pipe_type[i]]);
872 return 0;
875 void usbhs_pipe_remove(struct usbhs_priv *priv)
877 struct usbhs_pipe_info *info = usbhsp_priv_to_pipeinfo(priv);
879 kfree(info->pipe);