pipe.c 14 KB

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