pipe.c 15 KB

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