pipe.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 sequence)
  406. {
  407. u16 mask = (SQCLR | SQSET);
  408. u16 val;
  409. /*
  410. * sequence
  411. * 0 : data0
  412. * 1 : data1
  413. * -1 : no change
  414. */
  415. switch (sequence) {
  416. case 0:
  417. val = SQCLR;
  418. break;
  419. case 1:
  420. val = SQSET;
  421. break;
  422. default:
  423. return;
  424. }
  425. usbhsp_pipectrl_set(pipe, mask, val);
  426. }
  427. void usbhs_pipe_clear(struct usbhs_pipe *pipe)
  428. {
  429. usbhsp_pipectrl_set(pipe, ACLRM, ACLRM);
  430. usbhsp_pipectrl_set(pipe, ACLRM, 0);
  431. }
  432. static struct usbhs_pipe *usbhsp_get_pipe(struct usbhs_priv *priv, u32 type)
  433. {
  434. struct usbhs_pipe *pos, *pipe;
  435. int i;
  436. /*
  437. * find target pipe
  438. */
  439. pipe = NULL;
  440. usbhs_for_each_pipe_with_dcp(pos, priv, i) {
  441. if (!usbhs_pipe_type_is(pos, type))
  442. continue;
  443. if (usbhsp_flags_has(pos, IS_USED))
  444. continue;
  445. pipe = pos;
  446. break;
  447. }
  448. if (!pipe)
  449. return NULL;
  450. /*
  451. * initialize pipe flags
  452. */
  453. usbhsp_flags_init(pipe);
  454. usbhsp_flags_set(pipe, IS_USED);
  455. return pipe;
  456. }
  457. void usbhs_pipe_init(struct usbhs_priv *priv,
  458. int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map))
  459. {
  460. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  461. struct usbhs_pipe *pipe;
  462. int i;
  463. /*
  464. * FIXME
  465. *
  466. * driver needs good allocator.
  467. *
  468. * find first free buffer area (BULK, ISOC)
  469. * (DCP, INT area is fixed)
  470. *
  471. * buffer number 0 - 3 have been reserved for DCP
  472. * see
  473. * usbhsp_to_bufnmb
  474. */
  475. info->bufnmb_last = 4;
  476. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  477. if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT))
  478. info->bufnmb_last++;
  479. usbhsp_flags_init(pipe);
  480. pipe->fifo = NULL;
  481. pipe->mod_private = NULL;
  482. INIT_LIST_HEAD(&pipe->list);
  483. /* pipe force init */
  484. usbhs_pipe_clear(pipe);
  485. }
  486. info->dma_map_ctrl = dma_map_ctrl;
  487. }
  488. struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv *priv,
  489. int endpoint_type,
  490. int dir_in)
  491. {
  492. struct device *dev = usbhs_priv_to_dev(priv);
  493. struct usbhs_pipe *pipe;
  494. int is_host = usbhs_mod_is_host(priv);
  495. int ret;
  496. u16 pipecfg, pipebuf;
  497. pipe = usbhsp_get_pipe(priv, endpoint_type);
  498. if (!pipe) {
  499. dev_err(dev, "can't get pipe (%s)\n",
  500. usbhsp_pipe_name[endpoint_type]);
  501. return NULL;
  502. }
  503. INIT_LIST_HEAD(&pipe->list);
  504. usbhs_pipe_disable(pipe);
  505. /* make sure pipe is not busy */
  506. ret = usbhsp_pipe_barrier(pipe);
  507. if (ret < 0) {
  508. dev_err(dev, "pipe setup failed %d\n", usbhs_pipe_number(pipe));
  509. return NULL;
  510. }
  511. pipecfg = usbhsp_setup_pipecfg(pipe, is_host, dir_in);
  512. pipebuf = usbhsp_setup_pipebuff(pipe);
  513. usbhsp_pipe_select(pipe);
  514. usbhsp_pipe_cfg_set(pipe, 0xFFFF, pipecfg);
  515. usbhsp_pipe_buf_set(pipe, 0xFFFF, pipebuf);
  516. usbhs_pipe_sequence_data0(pipe);
  517. dev_dbg(dev, "enable pipe %d : %s (%s)\n",
  518. usbhs_pipe_number(pipe),
  519. usbhs_pipe_name(pipe),
  520. usbhs_pipe_is_dir_in(pipe) ? "in" : "out");
  521. /*
  522. * epnum / maxp are still not set to this pipe.
  523. * call usbhs_pipe_config_update() after this function !!
  524. */
  525. return pipe;
  526. }
  527. void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo)
  528. {
  529. if (pipe->fifo)
  530. pipe->fifo->pipe = NULL;
  531. pipe->fifo = fifo;
  532. if (fifo)
  533. fifo->pipe = pipe;
  534. }
  535. /*
  536. * dcp control
  537. */
  538. struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv)
  539. {
  540. struct usbhs_pipe *pipe;
  541. pipe = usbhsp_get_pipe(priv, USB_ENDPOINT_XFER_CONTROL);
  542. if (!pipe)
  543. return NULL;
  544. INIT_LIST_HEAD(&pipe->list);
  545. /*
  546. * call usbhs_pipe_config_update() after this function !!
  547. */
  548. return pipe;
  549. }
  550. void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe)
  551. {
  552. struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
  553. WARN_ON(!usbhs_pipe_is_dcp(pipe));
  554. usbhs_pipe_enable(pipe);
  555. if (!usbhs_mod_is_host(priv)) /* funconly */
  556. usbhsp_pipectrl_set(pipe, CCPL, CCPL);
  557. }
  558. void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out)
  559. {
  560. usbhsp_pipe_cfg_set(pipe, DIR_OUT,
  561. dir_out ? DIR_OUT : 0);
  562. }
  563. /*
  564. * pipe module function
  565. */
  566. int usbhs_pipe_probe(struct usbhs_priv *priv)
  567. {
  568. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  569. struct usbhs_pipe *pipe;
  570. struct device *dev = usbhs_priv_to_dev(priv);
  571. u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
  572. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  573. int i;
  574. /* This driver expects 1st pipe is DCP */
  575. if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) {
  576. dev_err(dev, "1st PIPE is not DCP\n");
  577. return -EINVAL;
  578. }
  579. info->pipe = kzalloc(sizeof(struct usbhs_pipe) * pipe_size, GFP_KERNEL);
  580. if (!info->pipe) {
  581. dev_err(dev, "Could not allocate pipe\n");
  582. return -ENOMEM;
  583. }
  584. info->size = pipe_size;
  585. /*
  586. * init pipe
  587. */
  588. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  589. pipe->priv = priv;
  590. usbhs_pipe_type(pipe) =
  591. pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK;
  592. dev_dbg(dev, "pipe %x\t: %s\n",
  593. i, usbhsp_pipe_name[pipe_type[i]]);
  594. }
  595. return 0;
  596. }
  597. void usbhs_pipe_remove(struct usbhs_priv *priv)
  598. {
  599. struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
  600. kfree(info->pipe);
  601. }