pipe.c 15 KB

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