pipe.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /*
  2. * Renesas USB driver
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  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.
  11. *
  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
  15. *
  16. */
  17. #include <linux/delay.h>
  18. #include <linux/slab.h>
  19. #include "./common.h"
  20. #include "./pipe.h"
  21. /*
  22. * macros
  23. */
  24. #define usbhsp_addr_offset(p) ((usbhs_pipe_number(p) - 1) * 2)
  25. #define usbhsp_flags_set(p, f) ((p)->flags |= USBHS_PIPE_FLAGS_##f)
  26. #define usbhsp_flags_clr(p, f) ((p)->flags &= ~USBHS_PIPE_FLAGS_##f)
  27. #define usbhsp_flags_has(p, f) ((p)->flags & USBHS_PIPE_FLAGS_##f)
  28. #define usbhsp_flags_init(p) do {(p)->flags = 0; } while (0)
  29. /*
  30. * for debug
  31. */
  32. static char *usbhsp_pipe_name[] = {
  33. [USB_ENDPOINT_XFER_CONTROL] = "DCP",
  34. [USB_ENDPOINT_XFER_BULK] = "BULK",
  35. [USB_ENDPOINT_XFER_INT] = "INT",
  36. [USB_ENDPOINT_XFER_ISOC] = "ISO",
  37. };
  38. /*
  39. * DCPCTR/PIPEnCTR functions
  40. */
  41. static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
  42. {
  43. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  44. int offset = usbhsp_addr_offset(pipe);
  45. if (usbhs_pipe_is_dcp(pipe))
  46. usbhs_bset(priv, DCPCTR, mask, val);
  47. else
  48. usbhs_bset(priv, PIPEnCTR + offset, mask, val);
  49. }
  50. static u16 usbhsp_pipectrl_get(struct usbhs_pipe *pipe)
  51. {
  52. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  53. int offset = usbhsp_addr_offset(pipe);
  54. if (usbhs_pipe_is_dcp(pipe))
  55. return usbhs_read(priv, DCPCTR);
  56. else
  57. return usbhs_read(priv, PIPEnCTR + offset);
  58. }
  59. /*
  60. * DCP/PIPE functions
  61. */
  62. static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe,
  63. u16 dcp_reg, u16 pipe_reg,
  64. u16 mask, u16 val)
  65. {
  66. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  67. if (usbhs_pipe_is_dcp(pipe))
  68. usbhs_bset(priv, dcp_reg, mask, val);
  69. else
  70. usbhs_bset(priv, pipe_reg, mask, val);
  71. }
  72. /*
  73. * DCPCFG/PIPECFG functions
  74. */
  75. static void usbhsp_pipe_cfg_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
  76. {
  77. __usbhsp_pipe_xxx_set(pipe, DCPCFG, PIPECFG, mask, val);
  78. }
  79. /*
  80. * PIPEBUF
  81. */
  82. static void usbhsp_pipe_buf_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
  83. {
  84. if (usbhs_pipe_is_dcp(pipe))
  85. return;
  86. __usbhsp_pipe_xxx_set(pipe, 0, PIPEBUF, mask, val);
  87. }
  88. /*
  89. * DCPMAXP/PIPEMAXP
  90. */
  91. static void usbhsp_pipe_maxp_set(struct usbhs_pipe *pipe, u16 mask, u16 val)
  92. {
  93. __usbhsp_pipe_xxx_set(pipe, DCPMAXP, PIPEMAXP, mask, val);
  94. }
  95. /*
  96. * pipe control functions
  97. */
  98. static void usbhsp_pipe_select(struct usbhs_pipe *pipe)
  99. {
  100. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  101. /*
  102. * On pipe, this is necessary before
  103. * accesses to below registers.
  104. *
  105. * PIPESEL : usbhsp_pipe_select
  106. * PIPECFG : usbhsp_pipe_cfg_xxx
  107. * PIPEBUF : usbhsp_pipe_buf_xxx
  108. * PIPEMAXP : usbhsp_pipe_maxp_xxx
  109. * PIPEPERI
  110. */
  111. /*
  112. * if pipe is dcp, no pipe is selected.
  113. * it is no problem, because dcp have its register
  114. */
  115. usbhs_write(priv, PIPESEL, 0xF & usbhs_pipe_number(pipe));
  116. }
  117. static int usbhsp_pipe_barrier(struct usbhs_pipe *pipe)
  118. {
  119. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  120. int timeout = 1024;
  121. u16 val;
  122. /*
  123. * make sure....
  124. *
  125. * Modify these bits when CSSTS = 0, PID = NAK, and no pipe number is
  126. * specified by the CURPIPE bits.
  127. * When changing the setting of this bit after changing
  128. * the PID bits for the selected pipe from BUF to NAK,
  129. * check that CSSTS = 0 and PBUSY = 0.
  130. */
  131. /*
  132. * CURPIPE bit = 0
  133. *
  134. * see also
  135. * "Operation"
  136. * - "Pipe Control"
  137. * - "Pipe Control Registers Switching Procedure"
  138. */
  139. usbhs_write(priv, CFIFOSEL, 0);
  140. usbhs_pipe_disable(pipe);
  141. do {
  142. val = usbhsp_pipectrl_get(pipe);
  143. val &= CSSTS | PID_MASK;
  144. if (!val)
  145. return 0;
  146. udelay(10);
  147. } while (timeout--);
  148. return -EBUSY;
  149. }
  150. int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe)
  151. {
  152. u16 val;
  153. val = usbhsp_pipectrl_get(pipe);
  154. if (val & BSTS)
  155. return 0;
  156. return -EBUSY;
  157. }
  158. /*
  159. * PID ctrl
  160. */
  161. static void __usbhsp_pid_try_nak_if_stall(struct usbhs_pipe *pipe)
  162. {
  163. u16 pid = usbhsp_pipectrl_get(pipe);
  164. pid &= PID_MASK;
  165. /*
  166. * see
  167. * "Pipe n Control Register" - "PID"
  168. */
  169. switch (pid) {
  170. case PID_STALL11:
  171. usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
  172. /* fall-through */
  173. case PID_STALL10:
  174. usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
  175. }
  176. }
  177. void usbhs_pipe_disable(struct usbhs_pipe *pipe)
  178. {
  179. int timeout = 1024;
  180. u16 val;
  181. /* see "Pipe n Control Register" - "PID" */
  182. __usbhsp_pid_try_nak_if_stall(pipe);
  183. usbhsp_pipectrl_set(pipe, PID_MASK, PID_NAK);
  184. do {
  185. val = usbhsp_pipectrl_get(pipe);
  186. val &= PBUSY;
  187. if (!val)
  188. break;
  189. udelay(10);
  190. } while (timeout--);
  191. }
  192. void usbhs_pipe_enable(struct usbhs_pipe *pipe)
  193. {
  194. /* see "Pipe n Control Register" - "PID" */
  195. __usbhsp_pid_try_nak_if_stall(pipe);
  196. usbhsp_pipectrl_set(pipe, PID_MASK, PID_BUF);
  197. }
  198. void usbhs_pipe_stall(struct usbhs_pipe *pipe)
  199. {
  200. u16 pid = usbhsp_pipectrl_get(pipe);
  201. pid &= PID_MASK;
  202. /*
  203. * see
  204. * "Pipe n Control Register" - "PID"
  205. */
  206. switch (pid) {
  207. case PID_NAK:
  208. usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL10);
  209. break;
  210. case PID_BUF:
  211. usbhsp_pipectrl_set(pipe, PID_MASK, PID_STALL11);
  212. break;
  213. }
  214. }
  215. /*
  216. * pipe setup
  217. */
  218. static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
  219. {
  220. /*
  221. * only ISO / BULK pipe can use double buffer
  222. */
  223. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) ||
  224. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
  225. return 1;
  226. return 0;
  227. }
  228. static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
  229. int is_host,
  230. int dir_in)
  231. {
  232. u16 type = 0;
  233. u16 bfre = 0;
  234. u16 dblb = 0;
  235. u16 cntmd = 0;
  236. u16 dir = 0;
  237. u16 epnum = 0;
  238. u16 shtnak = 0;
  239. u16 type_array[] = {
  240. [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
  241. [USB_ENDPOINT_XFER_INT] = TYPE_INT,
  242. [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
  243. };
  244. int is_double = usbhsp_possible_double_buffer(pipe);
  245. if (usbhs_pipe_is_dcp(pipe))
  246. return -EINVAL;
  247. /*
  248. * PIPECFG
  249. *
  250. * see
  251. * - "Register Descriptions" - "PIPECFG" register
  252. * - "Features" - "Pipe configuration"
  253. * - "Operation" - "Pipe Control"
  254. */
  255. /* TYPE */
  256. type = type_array[usbhs_pipe_type(pipe)];
  257. /* BFRE */
  258. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
  259. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  260. bfre = 0; /* FIXME */
  261. /* DBLB */
  262. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
  263. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  264. dblb = (is_double) ? DBLB : 0;
  265. /* CNTMD */
  266. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  267. cntmd = 0; /* FIXME */
  268. /* DIR */
  269. if (dir_in)
  270. usbhsp_flags_set(pipe, IS_DIR_HOST);
  271. if ((is_host && !dir_in) ||
  272. (!is_host && dir_in))
  273. dir |= DIR_OUT;
  274. if (!dir)
  275. usbhsp_flags_set(pipe, IS_DIR_IN);
  276. /* SHTNAK */
  277. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
  278. !dir)
  279. shtnak = SHTNAK;
  280. /* EPNUM */
  281. epnum = 0; /* see usbhs_pipe_config_update() */
  282. return type |
  283. bfre |
  284. dblb |
  285. cntmd |
  286. dir |
  287. shtnak |
  288. epnum;
  289. }
  290. static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe)
  291. {
  292. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  293. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  294. struct device *dev = usbhs_priv_to_dev(priv);
  295. int pipe_num = usbhs_pipe_number(pipe);
  296. int is_double = usbhsp_possible_double_buffer(pipe);
  297. u16 buff_size;
  298. u16 bufnmb;
  299. u16 bufnmb_cnt;
  300. /*
  301. * PIPEBUF
  302. *
  303. * see
  304. * - "Register Descriptions" - "PIPEBUF" register
  305. * - "Features" - "Pipe configuration"
  306. * - "Operation" - "FIFO Buffer Memory"
  307. * - "Operation" - "Pipe Control"
  308. *
  309. * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724)
  310. *
  311. * BUFNMB: PIPE
  312. * 0: pipe0 (DCP 256byte)
  313. * 1: -
  314. * 2: -
  315. * 3: -
  316. * 4: pipe6 (INT 64byte)
  317. * 5: pipe7 (INT 64byte)
  318. * 6: pipe8 (INT 64byte)
  319. * 7: pipe9 (INT 64byte)
  320. * 8 - xx: free (for BULK, ISOC)
  321. */
  322. /*
  323. * FIXME
  324. *
  325. * it doesn't have good buffer allocator
  326. *
  327. * DCP : 256 byte
  328. * BULK: 512 byte
  329. * INT : 64 byte
  330. * ISOC: 512 byte
  331. */
  332. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_CONTROL))
  333. buff_size = 256;
  334. else if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT))
  335. buff_size = 64;
  336. else
  337. buff_size = 512;
  338. /* change buff_size to register value */
  339. bufnmb_cnt = (buff_size / 64) - 1;
  340. /* BUFNMB has been reserved for INT pipe
  341. * see above */
  342. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) {
  343. bufnmb = pipe_num - 2;
  344. } else {
  345. bufnmb = info->bufnmb_last;
  346. info->bufnmb_last += bufnmb_cnt + 1;
  347. /*
  348. * double buffer
  349. */
  350. if (is_double)
  351. info->bufnmb_last += bufnmb_cnt + 1;
  352. }
  353. dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
  354. pipe_num, buff_size, bufnmb);
  355. return (0x1f & bufnmb_cnt) << 10 |
  356. (0xff & bufnmb) << 0;
  357. }
  358. void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
  359. u16 epnum, u16 maxp)
  360. {
  361. if (devsel > 0xA) {
  362. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  363. struct device *dev = usbhs_priv_to_dev(priv);
  364. dev_err(dev, "devsel error %d\n", devsel);
  365. devsel = 0;
  366. }
  367. usbhsp_pipe_barrier(pipe);
  368. pipe->maxp = maxp;
  369. usbhsp_pipe_select(pipe);
  370. usbhsp_pipe_maxp_set(pipe, 0xFFFF,
  371. (devsel << 12) |
  372. maxp);
  373. if (!usbhs_pipe_is_dcp(pipe))
  374. usbhsp_pipe_cfg_set(pipe, 0x000F, epnum);
  375. }
  376. /*
  377. * pipe control
  378. */
  379. int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
  380. {
  381. /*
  382. * see
  383. * usbhs_pipe_config_update()
  384. * usbhs_dcp_malloc()
  385. */
  386. return pipe->maxp;
  387. }
  388. int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
  389. {
  390. return usbhsp_flags_has(pipe, IS_DIR_IN);
  391. }
  392. int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe)
  393. {
  394. return usbhsp_flags_has(pipe, IS_DIR_HOST);
  395. }
  396. void usbhs_pipe_clear_sequence(struct usbhs_pipe *pipe)
  397. {
  398. usbhsp_pipectrl_set(pipe, SQCLR, SQCLR);
  399. }
  400. void usbhs_pipe_clear(struct usbhs_pipe *pipe)
  401. {
  402. usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
  403. usbhsp_pipectrl_set(pipe, ACLRM, 0);
  404. }
  405. static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
  406. {
  407. struct usbhs_pipe *pos, *pipe;
  408. int i;
  409. /*
  410. * find target pipe
  411. */
  412. pipe = NULL;
  413. usbhs_for_each_pipe_with_dcp(pos, priv, i) {
  414. if (!usbhs_pipe_type_is(pos, type))
  415. continue;
  416. if (usbhsp_flags_has(pos, IS_USED))
  417. continue;
  418. pipe = pos;
  419. break;
  420. }
  421. if (!pipe)
  422. return NULL;
  423. /*
  424. * initialize pipe flags
  425. */
  426. usbhsp_flags_init(pipe);
  427. usbhsp_flags_set(pipe, IS_USED);
  428. return pipe;
  429. }
  430. void usbhs_pipe_init(struct usbhs_priv *priv,
  431. void (*done)(struct usbhs_priv *priv,
  432. struct usbhs_pkt *pkt),
  433. int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map))
  434. {
  435. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  436. struct device *dev = usbhs_priv_to_dev(priv);
  437. struct usbhs_pipe *pipe;
  438. int i;
  439. if (!done) {
  440. dev_err(dev, "no done function\n");
  441. return;
  442. }
  443. /*
  444. * FIXME
  445. *
  446. * driver needs good allocator.
  447. *
  448. * find first free buffer area (BULK, ISOC)
  449. * (DCP, INT area is fixed)
  450. *
  451. * buffer number 0 - 3 have been reserved for DCP
  452. * see
  453. * usbhsp_to_bufnmb
  454. */
  455. info->bufnmb_last = 4;
  456. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  457. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT))
  458. info->bufnmb_last++;
  459. usbhsp_flags_init(pipe);
  460. pipe->fifo = NULL;
  461. pipe->mod_private = NULL;
  462. INIT_LIST_HEAD(&pipe->list);
  463. /* pipe force init */
  464. usbhs_pipe_clear(pipe);
  465. }
  466. info->done = done;
  467. info->dma_map_ctrl = dma_map_ctrl;
  468. }
  469. struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
  470. int endpoint_type,
  471. int dir_in)
  472. {
  473. struct device *dev = usbhs_priv_to_dev(priv);
  474. struct usbhs_pipe *pipe;
  475. int is_host = usbhs_mod_is_host(priv);
  476. int ret;
  477. u16 pipecfg, pipebuf;
  478. pipe = usbhsp_get_pipe(priv, endpoint_type);
  479. if (!pipe) {
  480. dev_err(dev, "can't get pipe (%s)\n",
  481. usbhsp_pipe_name[endpoint_type]);
  482. return NULL;
  483. }
  484. INIT_LIST_HEAD(&pipe->list);
  485. usbhs_pipe_disable(pipe);
  486. /* make sure pipe is not busy */
  487. ret = usbhsp_pipe_barrier(pipe);
  488. if (ret < 0) {
  489. dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
  490. return NULL;
  491. }
  492. pipecfg = usbhsp_setup_pipecfg(pipe, is_host, dir_in);
  493. pipebuf = usbhsp_setup_pipebuff(pipe);
  494. usbhsp_pipe_select(pipe);
  495. usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
  496. usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
  497. usbhs_pipe_clear_sequence(pipe);
  498. dev_dbg(dev, "enable pipe %d : %s (%s)\n",
  499. usbhs_pipe_number(pipe),
  500. usbhsp_pipe_name[endpoint_type],
  501. usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
  502. /*
  503. * epnum / maxp are still not set to this pipe.
  504. * call usbhs_pipe_config_update() after this function !!
  505. */
  506. return pipe;
  507. }
  508. void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
  509. {
  510. if (pipe->fifo)
  511. pipe->fifo->pipe = NULL;
  512. pipe->fifo = fifo;
  513. if (fifo)
  514. fifo->pipe = pipe;
  515. }
  516. /*
  517. * dcp control
  518. */
  519. struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
  520. {
  521. struct usbhs_pipe *pipe;
  522. pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
  523. if (!pipe)
  524. return NULL;
  525. INIT_LIST_HEAD(&pipe->list);
  526. /*
  527. * call usbhs_pipe_config_update() after this function !!
  528. */
  529. return pipe;
  530. }
  531. void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
  532. {
  533. WARN_ON(!usbhs_pipe_is_dcp(pipe));
  534. usbhs_pipe_enable(pipe);
  535. usbhsp_pipectrl_set(pipe, CCPL, CCPL);
  536. }
  537. void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out)
  538. {
  539. usbhsp_pipe_cfg_set(pipe, DIR_OUT,
  540. dir_out ? DIR_OUT : 0);
  541. }
  542. /*
  543. * pipe module function
  544. */
  545. int usbhs_pipe_probe(struct usbhs_priv *priv)
  546. {
  547. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  548. struct usbhs_pipe *pipe;
  549. struct device *dev = usbhs_priv_to_dev(priv);
  550. u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
  551. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  552. int i;
  553. /* This driver expects 1st pipe is DCP */
  554. if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
  555. dev_err(dev, "1st PIPE is not DCP\n");
  556. return -EINVAL;
  557. }
  558. info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
  559. if (!info->pipe) {
  560. dev_err(dev, "Could not allocate pipe\n");
  561. return -ENOMEM;
  562. }
  563. info->size = pipe_size;
  564. /*
  565. * init pipe
  566. */
  567. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  568. pipe->priv = priv;
  569. usbhs_pipe_type(pipe) =
  570. pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
  571. dev_dbg(dev, "pipe %x\t: %s\n",
  572. i, usbhsp_pipe_name[pipe_type[i]]);
  573. }
  574. return 0;
  575. }
  576. void usbhs_pipe_remove(struct usbhs_priv *priv)
  577. {
  578. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  579. kfree(info->pipe);
  580. }