pipe.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. int usbhs_pipe_is_stall(struct usbhs_pipe *pipe)
  220. {
  221. u16 pid = usbhsp_pipectrl_get(pipe) & PID_MASK;
  222. return (int)(pid == PID_STALL10 || pid == PID_STALL11);
  223. }
  224. /*
  225. * pipe setup
  226. */
  227. static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe)
  228. {
  229. /*
  230. * only ISO / BULK pipe can use double buffer
  231. */
  232. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) ||
  233. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC))
  234. return 1;
  235. return 0;
  236. }
  237. static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
  238. int is_host,
  239. int dir_in)
  240. {
  241. u16 type = 0;
  242. u16 bfre = 0;
  243. u16 dblb = 0;
  244. u16 cntmd = 0;
  245. u16 dir = 0;
  246. u16 epnum = 0;
  247. u16 shtnak = 0;
  248. u16 type_array[] = {
  249. [USB_ENDPOINT_XFER_BULK] = TYPE_BULK,
  250. [USB_ENDPOINT_XFER_INT] = TYPE_INT,
  251. [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
  252. };
  253. int is_double = usbhsp_possible_double_buffer(pipe);
  254. if (usbhs_pipe_is_dcp(pipe))
  255. return -EINVAL;
  256. /*
  257. * PIPECFG
  258. *
  259. * see
  260. * - "Register Descriptions" - "PIPECFG" register
  261. * - "Features" - "Pipe configuration"
  262. * - "Operation" - "Pipe Control"
  263. */
  264. /* TYPE */
  265. type = type_array[usbhs_pipe_type(pipe)];
  266. /* BFRE */
  267. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
  268. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  269. bfre = 0; /* FIXME */
  270. /* DBLB */
  271. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) ||
  272. usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  273. dblb = (is_double) ? DBLB : 0;
  274. /* CNTMD */
  275. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK))
  276. cntmd = 0; /* FIXME */
  277. /* DIR */
  278. if (dir_in)
  279. usbhsp_flags_set(pipe, IS_DIR_HOST);
  280. if ((is_host && !dir_in) ||
  281. (!is_host && dir_in))
  282. dir |= DIR_OUT;
  283. if (!dir)
  284. usbhsp_flags_set(pipe, IS_DIR_IN);
  285. /* SHTNAK */
  286. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) &&
  287. !dir)
  288. shtnak = SHTNAK;
  289. /* EPNUM */
  290. epnum = 0; /* see usbhs_pipe_config_update() */
  291. return type |
  292. bfre |
  293. dblb |
  294. cntmd |
  295. dir |
  296. shtnak |
  297. epnum;
  298. }
  299. static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe)
  300. {
  301. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  302. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  303. struct device *dev = usbhs_priv_to_dev(priv);
  304. int pipe_num = usbhs_pipe_number(pipe);
  305. int is_double = usbhsp_possible_double_buffer(pipe);
  306. u16 buff_size;
  307. u16 bufnmb;
  308. u16 bufnmb_cnt;
  309. /*
  310. * PIPEBUF
  311. *
  312. * see
  313. * - "Register Descriptions" - "PIPEBUF" register
  314. * - "Features" - "Pipe configuration"
  315. * - "Operation" - "FIFO Buffer Memory"
  316. * - "Operation" - "Pipe Control"
  317. *
  318. * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724)
  319. *
  320. * BUFNMB: PIPE
  321. * 0: pipe0 (DCP 256byte)
  322. * 1: -
  323. * 2: -
  324. * 3: -
  325. * 4: pipe6 (INT 64byte)
  326. * 5: pipe7 (INT 64byte)
  327. * 6: pipe8 (INT 64byte)
  328. * 7: pipe9 (INT 64byte)
  329. * 8 - xx: free (for BULK, ISOC)
  330. */
  331. /*
  332. * FIXME
  333. *
  334. * it doesn't have good buffer allocator
  335. *
  336. * DCP : 256 byte
  337. * BULK: 512 byte
  338. * INT : 64 byte
  339. * ISOC: 512 byte
  340. */
  341. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_CONTROL))
  342. buff_size = 256;
  343. else if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT))
  344. buff_size = 64;
  345. else
  346. buff_size = 512;
  347. /* change buff_size to register value */
  348. bufnmb_cnt = (buff_size / 64) - 1;
  349. /* BUFNMB has been reserved for INT pipe
  350. * see above */
  351. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) {
  352. bufnmb = pipe_num - 2;
  353. } else {
  354. bufnmb = info->bufnmb_last;
  355. info->bufnmb_last += bufnmb_cnt + 1;
  356. /*
  357. * double buffer
  358. */
  359. if (is_double)
  360. info->bufnmb_last += bufnmb_cnt + 1;
  361. }
  362. dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n",
  363. pipe_num, buff_size, bufnmb);
  364. return (0x1f & bufnmb_cnt) << 10 |
  365. (0xff & bufnmb) << 0;
  366. }
  367. void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
  368. u16 epnum, u16 maxp)
  369. {
  370. if (devsel > 0xA) {
  371. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  372. struct device *dev = usbhs_priv_to_dev(priv);
  373. dev_err(dev, "devsel error %d\n", devsel);
  374. devsel = 0;
  375. }
  376. usbhsp_pipe_barrier(pipe);
  377. pipe->maxp = maxp;
  378. usbhsp_pipe_select(pipe);
  379. usbhsp_pipe_maxp_set(pipe, 0xFFFF,
  380. (devsel << 12) |
  381. maxp);
  382. if (!usbhs_pipe_is_dcp(pipe))
  383. usbhsp_pipe_cfg_set(pipe, 0x000F, epnum);
  384. }
  385. /*
  386. * pipe control
  387. */
  388. int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe)
  389. {
  390. /*
  391. * see
  392. * usbhs_pipe_config_update()
  393. * usbhs_dcp_malloc()
  394. */
  395. return pipe->maxp;
  396. }
  397. int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe)
  398. {
  399. return usbhsp_flags_has(pipe, IS_DIR_IN);
  400. }
  401. int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe)
  402. {
  403. return usbhsp_flags_has(pipe, IS_DIR_HOST);
  404. }
  405. void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int data)
  406. {
  407. u16 mask = (SQCLR | SQSET);
  408. u16 val = (data) ? SQSET : SQCLR;
  409. usbhsp_pipectrl_set(pipe, mask, val);
  410. }
  411. void usbhs_pipe_clear(struct usbhs_pipe *pipe)
  412. {
  413. usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
  414. usbhsp_pipectrl_set(pipe, ACLRM, 0);
  415. }
  416. static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
  417. {
  418. struct usbhs_pipe *pos, *pipe;
  419. int i;
  420. /*
  421. * find target pipe
  422. */
  423. pipe = NULL;
  424. usbhs_for_each_pipe_with_dcp(pos, priv, i) {
  425. if (!usbhs_pipe_type_is(pos, type))
  426. continue;
  427. if (usbhsp_flags_has(pos, IS_USED))
  428. continue;
  429. pipe = pos;
  430. break;
  431. }
  432. if (!pipe)
  433. return NULL;
  434. /*
  435. * initialize pipe flags
  436. */
  437. usbhsp_flags_init(pipe);
  438. usbhsp_flags_set(pipe, IS_USED);
  439. return pipe;
  440. }
  441. void usbhs_pipe_init(struct usbhs_priv *priv,
  442. int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map))
  443. {
  444. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  445. struct usbhs_pipe *pipe;
  446. int i;
  447. /*
  448. * FIXME
  449. *
  450. * driver needs good allocator.
  451. *
  452. * find first free buffer area (BULK, ISOC)
  453. * (DCP, INT area is fixed)
  454. *
  455. * buffer number 0 - 3 have been reserved for DCP
  456. * see
  457. * usbhsp_to_bufnmb
  458. */
  459. info->bufnmb_last = 4;
  460. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  461. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT))
  462. info->bufnmb_last++;
  463. usbhsp_flags_init(pipe);
  464. pipe->fifo = NULL;
  465. pipe->mod_private = NULL;
  466. INIT_LIST_HEAD(&pipe->list);
  467. /* pipe force init */
  468. usbhs_pipe_clear(pipe);
  469. }
  470. info->dma_map_ctrl = dma_map_ctrl;
  471. }
  472. struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
  473. int endpoint_type,
  474. int dir_in)
  475. {
  476. struct device *dev = usbhs_priv_to_dev(priv);
  477. struct usbhs_pipe *pipe;
  478. int is_host = usbhs_mod_is_host(priv);
  479. int ret;
  480. u16 pipecfg, pipebuf;
  481. pipe = usbhsp_get_pipe(priv, endpoint_type);
  482. if (!pipe) {
  483. dev_err(dev, "can't get pipe (%s)\n",
  484. usbhsp_pipe_name[endpoint_type]);
  485. return NULL;
  486. }
  487. INIT_LIST_HEAD(&pipe->list);
  488. usbhs_pipe_disable(pipe);
  489. /* make sure pipe is not busy */
  490. ret = usbhsp_pipe_barrier(pipe);
  491. if (ret < 0) {
  492. dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
  493. return NULL;
  494. }
  495. pipecfg = usbhsp_setup_pipecfg(pipe, is_host, dir_in);
  496. pipebuf = usbhsp_setup_pipebuff(pipe);
  497. usbhsp_pipe_select(pipe);
  498. usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
  499. usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
  500. usbhs_pipe_sequence_data0(pipe);
  501. dev_dbg(dev, "enable pipe %d : %s (%s)\n",
  502. usbhs_pipe_number(pipe),
  503. usbhs_pipe_name(pipe),
  504. usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
  505. /*
  506. * epnum / maxp are still not set to this pipe.
  507. * call usbhs_pipe_config_update() after this function !!
  508. */
  509. return pipe;
  510. }
  511. void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
  512. {
  513. if (pipe->fifo)
  514. pipe->fifo->pipe = NULL;
  515. pipe->fifo = fifo;
  516. if (fifo)
  517. fifo->pipe = pipe;
  518. }
  519. /*
  520. * dcp control
  521. */
  522. struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
  523. {
  524. struct usbhs_pipe *pipe;
  525. pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
  526. if (!pipe)
  527. return NULL;
  528. INIT_LIST_HEAD(&pipe->list);
  529. /*
  530. * call usbhs_pipe_config_update() after this function !!
  531. */
  532. return pipe;
  533. }
  534. void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
  535. {
  536. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  537. WARN_ON(!usbhs_pipe_is_dcp(pipe));
  538. usbhs_pipe_enable(pipe);
  539. if (!usbhs_mod_is_host(priv)) /* funconly */
  540. usbhsp_pipectrl_set(pipe, CCPL, CCPL);
  541. }
  542. void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out)
  543. {
  544. usbhsp_pipe_cfg_set(pipe, DIR_OUT,
  545. dir_out ? DIR_OUT : 0);
  546. }
  547. /*
  548. * pipe module function
  549. */
  550. int usbhs_pipe_probe(struct usbhs_priv *priv)
  551. {
  552. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  553. struct usbhs_pipe *pipe;
  554. struct device *dev = usbhs_priv_to_dev(priv);
  555. u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
  556. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  557. int i;
  558. /* This driver expects 1st pipe is DCP */
  559. if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
  560. dev_err(dev, "1st PIPE is not DCP\n");
  561. return -EINVAL;
  562. }
  563. info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
  564. if (!info->pipe) {
  565. dev_err(dev, "Could not allocate pipe\n");
  566. return -ENOMEM;
  567. }
  568. info->size = pipe_size;
  569. /*
  570. * init pipe
  571. */
  572. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  573. pipe->priv = priv;
  574. usbhs_pipe_type(pipe) =
  575. pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
  576. dev_dbg(dev, "pipe %x\t: %s\n",
  577. i, usbhsp_pipe_name[pipe_type[i]]);
  578. }
  579. return 0;
  580. }
  581. void usbhs_pipe_remove(struct usbhs_priv *priv)
  582. {
  583. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  584. kfree(info->pipe);
  585. }