blob: a2b24f381440bfcec953c4c56329498692637dd2 [file] [log] [blame]
Vitaliy Vasylskyy50bb7582024-09-09 01:06:24 +02001// SPDX-License-Identifier: GPL-1.0+
2/*
3 * Renesas USB driver
4 *
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 */
8#include <linux/delay.h>
9#include "common.h"
10#include "pipe.h"
11
12/*
13 * macros
14 */
15#define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
16
17#define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
18#define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
19#define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
20#define usbhsp_flags_init(p) do {(p)->flags = 0; } while (0)
21
22/*
23 * for debug
24 */
25static char *usbhsp_pipe_name[] = {
26 [USB_ENDPOINT_XFER_CONTROL] = "DCP",
27 [USB_ENDPOINT_XFER_BULK] = "BULK",
28 [USB_ENDPOINT_XFER_INT] = "INT",
29 [USB_ENDPOINT_XFER_ISOC] = "ISO",
30};
31
32char *usbhs_pipe_name(struct usbhs_pipe *pipe)
33{
34 return usbhsp_pipe_name[usbhs_pipe_type(pipe)];
35}
36
37static struct renesas_usbhs_driver_pipe_config
38*usbhsp_get_pipe_config(struct usbhs_priv *priv, int pipe_num)
39{
40 struct renesas_usbhs_driver_pipe_config *pipe_configs =
41 usbhs_get_dparam(priv, pipe_configs);
42
43 return &pipe_configs[pipe_num];
44}
45
46/*
47 * DCPCTR/PIPEnCTR functions
48 */
49static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
50{
51 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
52 int offset = usbhsp_addr_offset(pipe);
53
54 if (usbhs_pipe_is_dcp(pipe))
55 usbhs_bset(priv, DCPCTR, mask, val);
56 else
57 usbhs_bset(priv, PIPEnCTR + offset, mask, val);
58}
59
60static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
61{
62 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
63 int offset = usbhsp_addr_offset(pipe);
64
65 if (usbhs_pipe_is_dcp(pipe))
66 return usbhs_read(priv, DCPCTR);
67 else
68 return usbhs_read(priv, PIPEnCTR + offset);
69}
70
71/*
72 * DCP/PIPE functions
73 */
74static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
75 u16 dcp_reg, u16 pipe_reg,
76 u16 mask, u16 val)
77{
78 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
79
80 if (usbhs_pipe_is_dcp(pipe))
81 usbhs_bset(priv, dcp_reg, mask, val);
82 else
83 usbhs_bset(priv, pipe_reg, mask, val);
84}
85
86static u16 __usbhsp_pipe_xxx_get(struct usbhs_pipe *pipe,
87 u16 dcp_reg, u16 pipe_reg)
88{
89 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
90
91 if (usbhs_pipe_is_dcp(pipe))
92 return usbhs_read(priv, dcp_reg);
93 else
94 return usbhs_read(priv, pipe_reg);
95}
96
97/*
98 * DCPCFG/PIPECFG functions
99 */
100static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
101{
102 __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
103}
104
105static u16 usbhsp_pipe_cfg_get(struct usbhs_pipe *pipe)
106{
107 return __usbhsp_pipe_xxx_get(pipe, DCPCFG, PIPECFG);
108}
109
110/*
111 * PIPEnTRN/PIPEnTRE functions
112 */
113static void usbhsp_pipe_trn_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
114{
115 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
116 struct device *dev = usbhs_priv_to_dev(priv);
117 int num = usbhs_pipe_number(pipe);
118 u16 reg;
119
120 /*
121 * It is impossible to calculate address,
122 * since PIPEnTRN addresses were mapped randomly.
123 */
124#define CASE_PIPExTRN(a) \
125 case 0x ## a: \
126 reg = PIPE ## a ## TRN; \
127 break;
128
129 switch (num) {
130 CASE_PIPExTRN(1);
131 CASE_PIPExTRN(2);
132 CASE_PIPExTRN(3);
133 CASE_PIPExTRN(4);
134 CASE_PIPExTRN(5);
135 CASE_PIPExTRN(B);
136 CASE_PIPExTRN(C);
137 CASE_PIPExTRN(D);
138 CASE_PIPExTRN(E);
139 CASE_PIPExTRN(F);
140 CASE_PIPExTRN(9);
141 CASE_PIPExTRN(A);
142 default:
143 dev_err(dev, "unknown pipe (%d)\n", num);
144 return;
145 }
146 __usbhsp_pipe_xxx_set(pipe, 0, reg, mask, val);
147}
148
149static void usbhsp_pipe_tre_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
150{
151 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
152 struct device *dev = usbhs_priv_to_dev(priv);
153 int num = usbhs_pipe_number(pipe);
154 u16 reg;
155
156 /*
157 * It is impossible to calculate address,
158 * since PIPEnTRE addresses were mapped randomly.
159 */
160#define CASE_PIPExTRE(a) \
161 case 0x ## a: \
162 reg = PIPE ## a ## TRE; \
163 break;
164
165 switch (num) {
166 CASE_PIPExTRE(1);
167 CASE_PIPExTRE(2);
168 CASE_PIPExTRE(3);
169 CASE_PIPExTRE(4);
170 CASE_PIPExTRE(5);
171 CASE_PIPExTRE(B);
172 CASE_PIPExTRE(C);
173 CASE_PIPExTRE(D);
174 CASE_PIPExTRE(E);
175 CASE_PIPExTRE(F);
176 CASE_PIPExTRE(9);
177 CASE_PIPExTRE(A);
178 default:
179 dev_err(dev, "unknown pipe (%d)\n", num);
180 return;
181 }
182
183 __usbhsp_pipe_xxx_set(pipe, 0, reg, mask, val);
184}
185
186/*
187 * PIPEBUF
188 */
189static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
190{
191 if (usbhs_pipe_is_dcp(pipe))
192 return;
193
194 __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
195}
196
197/*
198 * DCPMAXP/PIPEMAXP
199 */
200static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
201{
202 __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
203}
204
205/*
206 * pipe control functions
207 */
208static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
209{
210 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
211
212 /*
213 * On pipe, this is necessary before
214 * accesses to below registers.
215 *
216 * PIPESEL : usbhsp_pipe_select
217 * PIPECFG : usbhsp_pipe_cfg_xxx
218 * PIPEBUF : usbhsp_pipe_buf_xxx
219 * PIPEMAXP : usbhsp_pipe_maxp_xxx
220 * PIPEPERI
221 */
222
223 /*
224 * if pipe is dcp, no pipe is selected.
225 * it is no problem, because dcp have its register
226 */
227 usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
228}
229
230static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
231{
232 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
233 int timeout = 1024;
234 u16 mask = usbhs_mod_is_host(priv) ? (CSSTS | PID_MASK) : PID_MASK;
235
236 /*
237 * make sure....
238 *
239 * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
240 * specified by the CURPIPE bits.
241 * When changing the setting of this bit after changing
242 * the PID bits for the selected pipe from BUF to NAK,
243 * check that CSSTS = 0 and PBUSY = 0.
244 */
245
246 /*
247 * CURPIPE bit = 0
248 *
249 * see also
250 * "Operation"
251 * - "Pipe Control"
252 * - "Pipe Control Registers Switching Procedure"
253 */
254 usbhs_write(priv, CFIFOSEL, 0);
255 usbhs_pipe_disable(pipe);
256
257 do {
258 if (!(usbhsp_pipectrl_get(pipe) & mask))
259 return 0;
260
261 udelay(10);
262
263 } while (timeout--);
264
265 return -EBUSY;
266}
267
268int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
269{
270 u16 val;
271
272 val = usbhsp_pipectrl_get(pipe);
273 if (val & BSTS)
274 return 0;
275
276 return -EBUSY;
277}
278
279bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe)
280{
281 u16 val;
282
283 /* Do not support for DCP pipe */
284 if (usbhs_pipe_is_dcp(pipe))
285 return false;
286
287 val = usbhsp_pipectrl_get(pipe);
288 if (val & INBUFM)
289 return true;
290
291 return false;
292}
293
294/*
295 * PID ctrl
296 */
297static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
298{
299 u16 pid = usbhsp_pipectrl_get(pipe);
300
301 pid &= PID_MASK;
302
303 /*
304 * see
305 * "Pipe n Control Register" - "PID"
306 */
307 switch (pid) {
308 case PID_STALL11:
309 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
310 fallthrough;
311 case PID_STALL10:
312 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
313 }
314}
315
316void usbhs_pipe_disable(struct usbhs_pipe *pipe)
317{
318 int timeout = 1024;
319 u16 val;
320
321 /* see "Pipe n Control Register" - "PID" */
322 __usbhsp_pid_try_nak_if_stall(pipe);
323
324 usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
325
326 do {
327 val = usbhsp_pipectrl_get(pipe);
328 val &= PBUSY;
329 if (!val)
330 break;
331
332 udelay(10);
333 } while (timeout--);
334}
335
336void usbhs_pipe_enable(struct usbhs_pipe *pipe)
337{
338 /* see "Pipe n Control Register" - "PID" */
339 __usbhsp_pid_try_nak_if_stall(pipe);
340
341 usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
342}
343
344void usbhs_pipe_stall(struct usbhs_pipe *pipe)
345{
346 u16 pid = usbhsp_pipectrl_get(pipe);
347
348 pid &= PID_MASK;
349
350 /*
351 * see
352 * "Pipe n Control Register" - "PID"
353 */
354 switch (pid) {
355 case PID_NAK:
356 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
357 break;
358 case PID_BUF:
359 usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
360 break;
361 }
362}
363
364int usbhs_pipe_is_stall(struct usbhs_pipe *pipe)
365{
366 u16 pid = usbhsp_pipectrl_get(pipe) & PID_MASK;
367
368 return (int)(pid == PID_STALL10 || pid == PID_STALL11);
369}
370
371void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len)
372{
373 if (!usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
374 return;
375
376 /*
377 * clear and disable transfer counter for IN/OUT pipe
378 */
379 usbhsp_pipe_tre_set(pipe, TRCLR | TRENB, TRCLR);
380
381 /*
382 * Only IN direction bulk pipe can use transfer count.
383 * Without using this function,
384 * received data will break if it was large data size.
385 * see PIPEnTRN/PIPEnTRE for detail
386 */
387 if (usbhs_pipe_is_dir_in(pipe)) {
388 int maxp = usbhs_pipe_get_maxpacket(pipe);
389
390 usbhsp_pipe_trn_set(pipe, 0xffff, DIV_ROUND_UP(len, maxp));
391 usbhsp_pipe_tre_set(pipe, TRENB, TRENB); /* enable */
392 }
393}
394
395
396/*
397 * pipe setup
398 */
399static int usbhsp_setup_pipecfg(struct usbhs_pipe *pipe, int is_host,
400 int dir_in, u16 *pipecfg)
401{
402 u16 type = 0;
403 u16 bfre = 0;
404 u16 dblb = 0;
405 u16 cntmd = 0;
406 u16 dir = 0;
407 u16 epnum = 0;
408 u16 shtnak = 0;
409 static const u16 type_array[] = {
410 [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
411 [USB_ENDPOINT_XFER_INT] = TYPE_INT,
412 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
413 };
414
415 if (usbhs_pipe_is_dcp(pipe))
416 return -EINVAL;
417
418 /*
419 * PIPECFG
420 *
421 * see
422 * - "Register Descriptions" - "PIPECFG" register
423 * - "Features" - "Pipe configuration"
424 * - "Operation" - "Pipe Control"
425 */
426
427 /* TYPE */
428 type = type_array[usbhs_pipe_type(pipe)];
429
430 /* BFRE */
431 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
432 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
433 bfre = 0; /* FIXME */
434
435 /* DBLB: see usbhs_pipe_config_update() */
436
437 /* CNTMD */
438 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
439 cntmd = 0; /* FIXME */
440
441 /* DIR */
442 if (dir_in)
443 usbhsp_flags_set(pipe, IS_DIR_HOST);
444
445 if (!!is_host ^ !!dir_in)
446 dir |= DIR_OUT;
447
448 if (!dir)
449 usbhsp_flags_set(pipe, IS_DIR_IN);
450
451 /* SHTNAK */
452 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
453 !dir)
454 shtnak = SHTNAK;
455
456 /* EPNUM */
457 epnum = 0; /* see usbhs_pipe_config_update() */
458 *pipecfg = type |
459 bfre |
460 dblb |
461 cntmd |
462 dir |
463 shtnak |
464 epnum;
465 return 0;
466}
467
468static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe)
469{
470 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
471 struct device *dev = usbhs_priv_to_dev(priv);
472 int pipe_num = usbhs_pipe_number(pipe);
473 u16 buff_size;
474 u16 bufnmb;
475 u16 bufnmb_cnt;
476 struct renesas_usbhs_driver_pipe_config *pipe_config =
477 usbhsp_get_pipe_config(priv, pipe_num);
478
479 /*
480 * PIPEBUF
481 *
482 * see
483 * - "Register Descriptions" - "PIPEBUF" register
484 * - "Features" - "Pipe configuration"
485 * - "Operation" - "FIFO Buffer Memory"
486 * - "Operation" - "Pipe Control"
487 */
488 buff_size = pipe_config->bufsize;
489 bufnmb = pipe_config->bufnum;
490
491 /* change buff_size to register value */
492 bufnmb_cnt = (buff_size / 64) - 1;
493
494 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
495 pipe_num, buff_size, bufnmb);
496
497 return (0x1f & bufnmb_cnt) << 10 |
498 (0xff & bufnmb) << 0;
499}
500
501void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
502 u16 epnum, u16 maxp)
503{
504 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
505 int pipe_num = usbhs_pipe_number(pipe);
506 struct renesas_usbhs_driver_pipe_config *pipe_config =
507 usbhsp_get_pipe_config(priv, pipe_num);
508 u16 dblb = pipe_config->double_buf ? DBLB : 0;
509
510 if (devsel > 0xA) {
511 struct device *dev = usbhs_priv_to_dev(priv);
512
513 dev_err(dev, "devsel error %d\n", devsel);
514
515 devsel = 0;
516 }
517
518 usbhsp_pipe_barrier(pipe);
519
520 pipe->maxp = maxp;
521
522 usbhsp_pipe_select(pipe);
523 usbhsp_pipe_maxp_set(pipe, 0xFFFF,
524 (devsel << 12) |
525 maxp);
526
527 if (!usbhs_pipe_is_dcp(pipe))
528 usbhsp_pipe_cfg_set(pipe, 0x000F | DBLB, epnum | dblb);
529}
530
531/*
532 * pipe control
533 */
534int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
535{
536 /*
537 * see
538 * usbhs_pipe_config_update()
539 * usbhs_dcp_malloc()
540 */
541 return pipe->maxp;
542}
543
544int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
545{
546 return usbhsp_flags_has(pipe, IS_DIR_IN);
547}
548
549int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe)
550{
551 return usbhsp_flags_has(pipe, IS_DIR_HOST);
552}
553
554int usbhs_pipe_is_running(struct usbhs_pipe *pipe)
555{
556 return usbhsp_flags_has(pipe, IS_RUNNING);
557}
558
559void usbhs_pipe_running(struct usbhs_pipe *pipe, int running)
560{
561 if (running)
562 usbhsp_flags_set(pipe, IS_RUNNING);
563 else
564 usbhsp_flags_clr(pipe, IS_RUNNING);
565}
566
567void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence)
568{
569 u16 mask = (SQCLR | SQSET);
570 u16 val;
571
572 /*
573 * sequence
574 * 0 : data0
575 * 1 : data1
576 * -1 : no change
577 */
578 switch (sequence) {
579 case 0:
580 val = SQCLR;
581 break;
582 case 1:
583 val = SQSET;
584 break;
585 default:
586 return;
587 }
588
589 usbhsp_pipectrl_set(pipe, mask, val);
590}
591
592static int usbhs_pipe_get_data_sequence(struct usbhs_pipe *pipe)
593{
594 return !!(usbhsp_pipectrl_get(pipe) & SQMON);
595}
596
597void usbhs_pipe_clear(struct usbhs_pipe *pipe)
598{
599 if (usbhs_pipe_is_dcp(pipe)) {
600 usbhs_fifo_clear_dcp(pipe);
601 } else {
602 usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
603 usbhsp_pipectrl_set(pipe, ACLRM, 0);
604 }
605}
606
607/* Should call usbhsp_pipe_select() before */
608void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
609 int needs_bfre, int bfre_enable)
610{
611 int sequence;
612
613 usbhsp_pipe_select(pipe);
614 sequence = usbhs_pipe_get_data_sequence(pipe);
615 if (needs_bfre)
616 usbhsp_pipe_cfg_set(pipe, BFRE, bfre_enable ? BFRE : 0);
617 usbhs_pipe_clear(pipe);
618 usbhs_pipe_data_sequence(pipe, sequence);
619}
620
621void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable)
622{
623 if (usbhs_pipe_is_dcp(pipe))
624 return;
625
626 usbhsp_pipe_select(pipe);
627 /* check if the driver needs to change the BFRE value */
628 if (!(enable ^ !!(usbhsp_pipe_cfg_get(pipe) & BFRE)))
629 return;
630
631 usbhs_pipe_clear_without_sequence(pipe, 1, enable);
632}
633
634static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
635{
636 struct usbhs_pipe *pos, *pipe;
637 int i;
638
639 /*
640 * find target pipe
641 */
642 pipe = NULL;
643 usbhs_for_each_pipe_with_dcp(pos, priv, i) {
644 if (!usbhs_pipe_type_is(pos, type))
645 continue;
646 if (usbhsp_flags_has(pos, IS_USED))
647 continue;
648
649 pipe = pos;
650 break;
651 }
652
653 if (!pipe)
654 return NULL;
655
656 /*
657 * initialize pipe flags
658 */
659 usbhsp_flags_init(pipe);
660 usbhsp_flags_set(pipe, IS_USED);
661
662 return pipe;
663}
664
665static void usbhsp_put_pipe(struct usbhs_pipe *pipe)
666{
667 usbhsp_flags_init(pipe);
668}
669
670void usbhs_pipe_init(struct usbhs_priv *priv,
671 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map))
672{
673 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
674 struct usbhs_pipe *pipe;
675 int i;
676
677 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
678 usbhsp_flags_init(pipe);
679 pipe->fifo = NULL;
680 pipe->mod_private = NULL;
681 INIT_LIST_HEAD(&pipe->list);
682
683 /* pipe force init */
684 usbhs_pipe_clear(pipe);
685 }
686
687 info->dma_map_ctrl = dma_map_ctrl;
688}
689
690struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
691 int endpoint_type,
692 int dir_in)
693{
694 struct device *dev = usbhs_priv_to_dev(priv);
695 struct usbhs_pipe *pipe;
696 int is_host = usbhs_mod_is_host(priv);
697 int ret;
698 u16 pipecfg, pipebuf;
699
700 pipe = usbhsp_get_pipe(priv, endpoint_type);
701 if (!pipe) {
702 dev_err(dev, "can't get pipe (%s)\n",
703 usbhsp_pipe_name[endpoint_type]);
704 return NULL;
705 }
706
707 INIT_LIST_HEAD(&pipe->list);
708
709 usbhs_pipe_disable(pipe);
710
711 /* make sure pipe is not busy */
712 ret = usbhsp_pipe_barrier(pipe);
713 if (ret < 0) {
714 dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
715 return NULL;
716 }
717
718 if (usbhsp_setup_pipecfg(pipe, is_host, dir_in, &pipecfg)) {
719 dev_err(dev, "can't setup pipe\n");
720 return NULL;
721 }
722
723 pipebuf = usbhsp_setup_pipebuff(pipe);
724
725 usbhsp_pipe_select(pipe);
726 usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
727 usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
728 usbhs_pipe_clear(pipe);
729
730 usbhs_pipe_sequence_data0(pipe);
731
732 dev_dbg(dev, "enable pipe %d : %s (%s)\n",
733 usbhs_pipe_number(pipe),
734 usbhs_pipe_name(pipe),
735 usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
736
737 /*
738 * epnum / maxp are still not set to this pipe.
739 * call usbhs_pipe_config_update() after this function !!
740 */
741
742 return pipe;
743}
744
745void usbhs_pipe_free(struct usbhs_pipe *pipe)
746{
747 usbhsp_pipe_select(pipe);
748 usbhsp_pipe_cfg_set(pipe, 0xFFFF, 0);
749 usbhsp_put_pipe(pipe);
750}
751
752void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
753{
754 if (pipe->fifo)
755 pipe->fifo->pipe = NULL;
756
757 pipe->fifo = fifo;
758
759 if (fifo)
760 fifo->pipe = pipe;
761}
762
763
764/*
765 * dcp control
766 */
767struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
768{
769 struct usbhs_pipe *pipe;
770
771 pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
772 if (!pipe)
773 return NULL;
774
775 INIT_LIST_HEAD(&pipe->list);
776
777 /*
778 * call usbhs_pipe_config_update() after this function !!
779 */
780
781 return pipe;
782}
783
784void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
785{
786 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
787
788 WARN_ON(!usbhs_pipe_is_dcp(pipe));
789
790 usbhs_pipe_enable(pipe);
791
792 if (!usbhs_mod_is_host(priv)) /* funconly */
793 usbhsp_pipectrl_set(pipe, CCPL, CCPL);
794}
795
796void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out)
797{
798 usbhsp_pipe_cfg_set(pipe, DIR_OUT,
799 dir_out ? DIR_OUT : 0);
800}
801
802/*
803 * pipe module function
804 */
805int usbhs_pipe_probe(struct usbhs_priv *priv)
806{
807 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
808 struct usbhs_pipe *pipe;
809 struct device *dev = usbhs_priv_to_dev(priv);
810 struct renesas_usbhs_driver_pipe_config *pipe_configs =
811 usbhs_get_dparam(priv, pipe_configs);
812 int pipe_size = usbhs_get_dparam(priv, pipe_size);
813 int i;
814
815 /* This driver expects 1st pipe is DCP */
816 if (pipe_configs[0].type != USB_ENDPOINT_XFER_CONTROL) {
817 dev_err(dev, "1st PIPE is not DCP\n");
818 return -EINVAL;
819 }
820
821 info->pipe = kcalloc(pipe_size, sizeof(struct usbhs_pipe),
822 GFP_KERNEL);
823 if (!info->pipe)
824 return -ENOMEM;
825
826 info->size = pipe_size;
827
828 /*
829 * init pipe
830 */
831 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
832 pipe->priv = priv;
833
834 usbhs_pipe_type(pipe) =
835 pipe_configs[i].type & USB_ENDPOINT_XFERTYPE_MASK;
836
837 dev_dbg(dev, "pipe %x\t: %s\n",
838 i, usbhsp_pipe_name[pipe_configs[i].type]);
839 }
840
841 return 0;
842}
843
844void usbhs_pipe_remove(struct usbhs_priv *priv)
845{
846 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
847
848 kfree(info->pipe);
849}