mod_host.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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/io.h>
  18. #include <linux/list.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/slab.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/hcd.h>
  24. #include "common.h"
  25. /*
  26. *** HARDWARE LIMITATION ***
  27. *
  28. * 1) renesas_usbhs has a limited number of controllable devices.
  29. * it can control only 9 devices in generally.
  30. * see DEVADDn / DCPMAXP / PIPEMAXP.
  31. *
  32. * 2) renesas_usbhs pipe number is limited.
  33. * the pipe will be re-used for each devices.
  34. * so, software should control DATA0/1 sequence of each devices.
  35. */
  36. /*
  37. * image of mod_host
  38. *
  39. * +--------+
  40. * | udev 0 | --> it is used when set address
  41. * +--------+
  42. *
  43. * +--------+ pipes are reused for each uep.
  44. * | udev 1 |-+- [uep 0 (dcp) ] --+ pipe will be switched when
  45. * +--------+ | | target device was changed
  46. * +- [uep 1 (bulk)] --|---+ +--------------+
  47. * | +--------------> | pipe0 (dcp) |
  48. * +- [uep 2 (bulk)] --|---|---+ +--------------+
  49. * | | | | pipe1 (isoc) |
  50. * +--------+ | | | +--------------+
  51. * | udev 2 |-+- [uep 0 (dcp) ] --+ +-- |------> | pipe2 (bulk) |
  52. * +--------+ | | | | +--------------+
  53. * +- [uep 1 (int) ] --|-+ | +------> | pipe3 (bulk) |
  54. * | | | | +--------------+
  55. * +--------+ | +-|---|------> | pipe4 (int) |
  56. * | udev 3 |-+- [uep 0 (dcp) ] --+ | | +--------------+
  57. * +--------+ | | | | .... |
  58. * +- [uep 1 (bulk)] ------+ | | .... |
  59. * | |
  60. * +- [uep 2 (bulk)]-----------+
  61. */
  62. /*
  63. * struct
  64. */
  65. struct usbhsh_pipe_info {
  66. unsigned int usr_cnt; /* see usbhsh_endpoint_alloc() */
  67. };
  68. struct usbhsh_request {
  69. struct urb *urb;
  70. struct usbhs_pkt pkt;
  71. struct list_head ureq_link; /* see hpriv :: ureq_link_xxx */
  72. };
  73. struct usbhsh_device {
  74. struct usb_device *usbv;
  75. struct list_head ep_list_head; /* list of usbhsh_ep */
  76. };
  77. struct usbhsh_ep {
  78. struct usbhs_pipe *pipe;
  79. struct usbhsh_device *udev; /* attached udev */
  80. struct list_head ep_list; /* list to usbhsh_device */
  81. int maxp;
  82. };
  83. #define USBHSH_DEVICE_MAX 10 /* see DEVADDn / DCPMAXP / PIPEMAXP */
  84. #define USBHSH_PORT_MAX 7 /* see DEVADDn :: HUBPORT */
  85. struct usbhsh_hpriv {
  86. struct usbhs_mod mod;
  87. struct usbhs_pipe *dcp;
  88. struct usbhsh_device udev[USBHSH_DEVICE_MAX];
  89. struct usbhsh_pipe_info *pipe_info;
  90. int pipe_size;
  91. u32 port_stat; /* USB_PORT_STAT_xxx */
  92. struct completion setup_ack_done;
  93. /* see usbhsh_req_alloc/free */
  94. struct list_head ureq_link_active;
  95. struct list_head ureq_link_free;
  96. };
  97. static const char usbhsh_hcd_name[] = "renesas_usbhs host";
  98. /*
  99. * macro
  100. */
  101. #define usbhsh_priv_to_hpriv(priv) \
  102. container_of(usbhs_mod_get(priv, USBHS_HOST), struct usbhsh_hpriv, mod)
  103. #define __usbhsh_for_each_hpipe(start, pos, h, i) \
  104. for (i = start, pos = (h)->hpipe + i; \
  105. i < (h)->hpipe_size; \
  106. i++, pos = (h)->hpipe + i)
  107. #define usbhsh_for_each_hpipe(pos, hpriv, i) \
  108. __usbhsh_for_each_hpipe(1, pos, hpriv, i)
  109. #define usbhsh_for_each_hpipe_with_dcp(pos, hpriv, i) \
  110. __usbhsh_for_each_hpipe(0, pos, hpriv, i)
  111. #define __usbhsh_for_each_udev(start, pos, h, i) \
  112. for (i = start, pos = (h)->udev + i; \
  113. i < USBHSH_DEVICE_MAX; \
  114. i++, pos = (h)->udev + i)
  115. #define usbhsh_for_each_udev(pos, hpriv, i) \
  116. __usbhsh_for_each_udev(1, pos, hpriv, i)
  117. #define usbhsh_for_each_udev_with_dev0(pos, hpriv, i) \
  118. __usbhsh_for_each_udev(0, pos, hpriv, i)
  119. #define usbhsh_hcd_to_hpriv(h) (struct usbhsh_hpriv *)((h)->hcd_priv)
  120. #define usbhsh_hcd_to_dev(h) ((h)->self.controller)
  121. #define usbhsh_hpriv_to_priv(h) ((h)->mod.priv)
  122. #define usbhsh_hpriv_to_dcp(h) ((h)->dcp)
  123. #define usbhsh_hpriv_to_hcd(h) \
  124. container_of((void *)h, struct usb_hcd, hcd_priv)
  125. #define usbhsh_ep_to_uep(u) ((u)->hcpriv)
  126. #define usbhsh_uep_to_pipe(u) ((u)->pipe)
  127. #define usbhsh_uep_to_udev(u) ((u)->udev)
  128. #define usbhsh_urb_to_ureq(u) ((u)->hcpriv)
  129. #define usbhsh_urb_to_usbv(u) ((u)->dev)
  130. #define usbhsh_usbv_to_udev(d) dev_get_drvdata(&(d)->dev)
  131. #define usbhsh_udev_to_usbv(h) ((h)->usbv)
  132. #define usbhsh_pipe_info(p) ((p)->mod_private)
  133. #define usbhsh_device_number(h, d) ((int)((d) - (h)->udev))
  134. #define usbhsh_device_nth(h, d) ((h)->udev + d)
  135. #define usbhsh_device0(h) usbhsh_device_nth(h, 0)
  136. #define usbhsh_port_stat_init(h) ((h)->port_stat = 0)
  137. #define usbhsh_port_stat_set(h, s) ((h)->port_stat |= (s))
  138. #define usbhsh_port_stat_clear(h, s) ((h)->port_stat &= ~(s))
  139. #define usbhsh_port_stat_get(h) ((h)->port_stat)
  140. #define usbhsh_pkt_to_req(p) \
  141. container_of((void *)p, struct usbhsh_request, pkt)
  142. /*
  143. * req alloc/free
  144. */
  145. static void usbhsh_req_list_init(struct usbhsh_hpriv *hpriv)
  146. {
  147. INIT_LIST_HEAD(&hpriv->ureq_link_active);
  148. INIT_LIST_HEAD(&hpriv->ureq_link_free);
  149. }
  150. static void usbhsh_req_list_quit(struct usbhsh_hpriv *hpriv)
  151. {
  152. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  153. struct device *dev = usbhsh_hcd_to_dev(hcd);
  154. struct usbhsh_request *ureq, *next;
  155. /* kfree all active ureq */
  156. list_for_each_entry_safe(ureq, next,
  157. &hpriv->ureq_link_active,
  158. ureq_link) {
  159. dev_err(dev, "active ureq (%p) is force freed\n", ureq);
  160. kfree(ureq);
  161. }
  162. /* kfree all free ureq */
  163. list_for_each_entry_safe(ureq, next, &hpriv->ureq_link_free, ureq_link)
  164. kfree(ureq);
  165. }
  166. static struct usbhsh_request *usbhsh_req_alloc(struct usbhsh_hpriv *hpriv,
  167. struct urb *urb,
  168. gfp_t mem_flags)
  169. {
  170. struct usbhsh_request *ureq;
  171. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  172. struct device *dev = usbhs_priv_to_dev(priv);
  173. if (list_empty(&hpriv->ureq_link_free)) {
  174. /*
  175. * create new one if there is no free ureq
  176. */
  177. ureq = kzalloc(sizeof(struct usbhsh_request), mem_flags);
  178. if (ureq)
  179. INIT_LIST_HEAD(&ureq->ureq_link);
  180. } else {
  181. /*
  182. * reuse "free" ureq if exist
  183. */
  184. ureq = list_entry(hpriv->ureq_link_free.next,
  185. struct usbhsh_request,
  186. ureq_link);
  187. if (ureq)
  188. list_del_init(&ureq->ureq_link);
  189. }
  190. if (!ureq) {
  191. dev_err(dev, "ureq alloc fail\n");
  192. return NULL;
  193. }
  194. usbhs_pkt_init(&ureq->pkt);
  195. /*
  196. * push it to "active" list
  197. */
  198. list_add_tail(&ureq->ureq_link, &hpriv->ureq_link_active);
  199. ureq->urb = urb;
  200. return ureq;
  201. }
  202. static void usbhsh_req_free(struct usbhsh_hpriv *hpriv,
  203. struct usbhsh_request *ureq)
  204. {
  205. struct usbhs_pkt *pkt = &ureq->pkt;
  206. usbhs_pkt_init(pkt);
  207. /*
  208. * removed from "active" list,
  209. * and push it to "free" list
  210. */
  211. ureq->urb = NULL;
  212. list_del_init(&ureq->ureq_link);
  213. list_add_tail(&ureq->ureq_link, &hpriv->ureq_link_free);
  214. }
  215. /*
  216. * device control
  217. */
  218. static int usbhsh_device_has_endpoint(struct usbhsh_device *udev)
  219. {
  220. return !list_empty(&udev->ep_list_head);
  221. }
  222. static struct usbhsh_device *usbhsh_device_alloc(struct usbhsh_hpriv *hpriv,
  223. struct urb *urb)
  224. {
  225. struct usbhsh_device *udev = NULL;
  226. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  227. struct device *dev = usbhsh_hcd_to_dev(hcd);
  228. struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
  229. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  230. int i;
  231. /*
  232. * device 0
  233. */
  234. if (0 == usb_pipedevice(urb->pipe)) {
  235. udev = usbhsh_device0(hpriv);
  236. goto usbhsh_device_find;
  237. }
  238. /*
  239. * find unused device
  240. */
  241. usbhsh_for_each_udev(udev, hpriv, i) {
  242. if (usbhsh_udev_to_usbv(udev))
  243. continue;
  244. goto usbhsh_device_find;
  245. }
  246. dev_err(dev, "no free usbhsh_device\n");
  247. return NULL;
  248. usbhsh_device_find:
  249. if (usbhsh_device_has_endpoint(udev))
  250. dev_warn(dev, "udev have old endpoint\n");
  251. /* uep will be attached */
  252. INIT_LIST_HEAD(&udev->ep_list_head);
  253. /*
  254. * usbhsh_usbv_to_udev()
  255. * usbhsh_udev_to_usbv()
  256. * will be enable
  257. */
  258. dev_set_drvdata(&usbv->dev, udev);
  259. udev->usbv = usbv;
  260. /* set device config */
  261. usbhs_set_device_speed(priv,
  262. usbhsh_device_number(hpriv, udev),
  263. usbhsh_device_number(hpriv, udev),
  264. 0, /* FIXME no parent */
  265. usbv->speed);
  266. dev_dbg(dev, "%s [%d](%p)\n", __func__,
  267. usbhsh_device_number(hpriv, udev), udev);
  268. return udev;
  269. }
  270. static void usbhsh_device_free(struct usbhsh_hpriv *hpriv,
  271. struct usbhsh_device *udev)
  272. {
  273. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  274. struct device *dev = usbhsh_hcd_to_dev(hcd);
  275. struct usb_device *usbv = usbhsh_udev_to_usbv(udev);
  276. dev_dbg(dev, "%s [%d](%p)\n", __func__,
  277. usbhsh_device_number(hpriv, udev), udev);
  278. if (usbhsh_device_has_endpoint(udev))
  279. dev_warn(dev, "udev still have endpoint\n");
  280. /*
  281. * usbhsh_usbv_to_udev()
  282. * usbhsh_udev_to_usbv()
  283. * will be disable
  284. */
  285. dev_set_drvdata(&usbv->dev, NULL);
  286. udev->usbv = NULL;
  287. }
  288. /*
  289. * end-point control
  290. */
  291. struct usbhsh_ep *usbhsh_endpoint_alloc(struct usbhsh_hpriv *hpriv,
  292. struct usbhsh_device *udev,
  293. struct usb_host_endpoint *ep,
  294. int dir_in_req,
  295. gfp_t mem_flags)
  296. {
  297. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  298. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  299. struct usbhsh_ep *uep;
  300. struct usbhsh_pipe_info *info;
  301. struct usbhs_pipe *pipe, *best_pipe;
  302. struct device *dev = usbhsh_hcd_to_dev(hcd);
  303. struct usb_endpoint_descriptor *desc = &ep->desc;
  304. int type, i, dir_in;
  305. unsigned int min_usr;
  306. dir_in_req = !!dir_in_req;
  307. uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags);
  308. if (!uep) {
  309. dev_err(dev, "usbhsh_ep alloc fail\n");
  310. return NULL;
  311. }
  312. if (usb_endpoint_xfer_control(desc)) {
  313. best_pipe = usbhsh_hpriv_to_dcp(hpriv);
  314. goto usbhsh_endpoint_alloc_find_pipe;
  315. }
  316. /*
  317. * find best pipe for endpoint
  318. * see
  319. * HARDWARE LIMITATION
  320. */
  321. type = usb_endpoint_type(desc);
  322. min_usr = ~0;
  323. best_pipe = NULL;
  324. usbhs_for_each_pipe(pipe, priv, i) {
  325. if (!usbhs_pipe_type_is(pipe, type))
  326. continue;
  327. dir_in = !!usbhs_pipe_is_dir_in(pipe);
  328. if (0 != (dir_in - dir_in_req))
  329. continue;
  330. info = usbhsh_pipe_info(pipe);
  331. if (min_usr > info->usr_cnt) {
  332. min_usr = info->usr_cnt;
  333. best_pipe = pipe;
  334. }
  335. }
  336. if (unlikely(!best_pipe)) {
  337. dev_err(dev, "couldn't find best pipe\n");
  338. kfree(uep);
  339. return NULL;
  340. }
  341. usbhsh_endpoint_alloc_find_pipe:
  342. /*
  343. * init uep
  344. */
  345. uep->pipe = best_pipe;
  346. uep->maxp = usb_endpoint_maxp(desc);
  347. usbhsh_uep_to_udev(uep) = udev;
  348. usbhsh_ep_to_uep(ep) = uep;
  349. /*
  350. * update pipe user count
  351. */
  352. info = usbhsh_pipe_info(best_pipe);
  353. info->usr_cnt++;
  354. /* init this endpoint, and attach it to udev */
  355. INIT_LIST_HEAD(&uep->ep_list);
  356. list_add_tail(&uep->ep_list, &udev->ep_list_head);
  357. /*
  358. * usbhs_pipe_config_update() should be called after
  359. * usbhs_device_config()
  360. * see
  361. * DCPMAXP/PIPEMAXP
  362. */
  363. usbhs_pipe_config_update(uep->pipe,
  364. usbhsh_device_number(hpriv, udev),
  365. usb_endpoint_num(desc),
  366. uep->maxp);
  367. dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
  368. usbhsh_device_number(hpriv, udev),
  369. usbhs_pipe_name(uep->pipe), uep);
  370. return uep;
  371. }
  372. void usbhsh_endpoint_free(struct usbhsh_hpriv *hpriv,
  373. struct usb_host_endpoint *ep)
  374. {
  375. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  376. struct device *dev = usbhs_priv_to_dev(priv);
  377. struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
  378. struct usbhsh_pipe_info *info;
  379. if (!uep)
  380. return;
  381. dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
  382. usbhsh_device_number(hpriv, usbhsh_uep_to_udev(uep)),
  383. usbhs_pipe_name(uep->pipe), uep);
  384. info = usbhsh_pipe_info(uep->pipe);
  385. info->usr_cnt--;
  386. /* remove this endpoint from udev */
  387. list_del_init(&uep->ep_list);
  388. usbhsh_uep_to_udev(uep) = NULL;
  389. usbhsh_ep_to_uep(ep) = NULL;
  390. kfree(uep);
  391. }
  392. /*
  393. * queue push/pop
  394. */
  395. static void usbhsh_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt)
  396. {
  397. struct usbhsh_request *ureq = usbhsh_pkt_to_req(pkt);
  398. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  399. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  400. struct urb *urb = ureq->urb;
  401. struct device *dev = usbhs_priv_to_dev(priv);
  402. dev_dbg(dev, "%s\n", __func__);
  403. if (!urb) {
  404. dev_warn(dev, "pkt doesn't have urb\n");
  405. return;
  406. }
  407. urb->actual_length = pkt->actual;
  408. usbhsh_req_free(hpriv, ureq);
  409. usbhsh_urb_to_ureq(urb) = NULL;
  410. usb_hcd_unlink_urb_from_ep(hcd, urb);
  411. usb_hcd_giveback_urb(hcd, urb, 0);
  412. }
  413. static int usbhsh_queue_push(struct usb_hcd *hcd,
  414. struct usbhs_pipe *pipe,
  415. struct urb *urb)
  416. {
  417. struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb);
  418. struct usbhs_pkt *pkt = &ureq->pkt;
  419. struct device *dev = usbhsh_hcd_to_dev(hcd);
  420. void *buf;
  421. int len;
  422. if (usb_pipeisoc(urb->pipe)) {
  423. dev_err(dev, "pipe iso is not supported now\n");
  424. return -EIO;
  425. }
  426. if (usb_pipein(urb->pipe))
  427. pipe->handler = &usbhs_fifo_pio_pop_handler;
  428. else
  429. pipe->handler = &usbhs_fifo_pio_push_handler;
  430. buf = (void *)(urb->transfer_buffer + urb->actual_length);
  431. len = urb->transfer_buffer_length - urb->actual_length;
  432. dev_dbg(dev, "%s\n", __func__);
  433. usbhs_pkt_push(pipe, pkt, usbhsh_queue_done,
  434. buf, len, (urb->transfer_flags & URB_ZERO_PACKET));
  435. usbhs_pkt_start(pipe);
  436. return 0;
  437. }
  438. /*
  439. * DCP setup stage
  440. */
  441. static int usbhsh_is_request_address(struct urb *urb)
  442. {
  443. struct usb_ctrlrequest *cmd;
  444. cmd = (struct usb_ctrlrequest *)urb->setup_packet;
  445. if ((DeviceOutRequest == cmd->bRequestType << 8) &&
  446. (USB_REQ_SET_ADDRESS == cmd->bRequest))
  447. return 1;
  448. else
  449. return 0;
  450. }
  451. static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv,
  452. struct urb *urb,
  453. struct usbhs_pipe *pipe)
  454. {
  455. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  456. struct usb_ctrlrequest req;
  457. struct device *dev = usbhs_priv_to_dev(priv);
  458. /*
  459. * wait setup packet ACK
  460. * see
  461. * usbhsh_irq_setup_ack()
  462. * usbhsh_irq_setup_err()
  463. */
  464. init_completion(&hpriv->setup_ack_done);
  465. /* copy original request */
  466. memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest));
  467. /*
  468. * renesas_usbhs can not use original usb address.
  469. * see HARDWARE LIMITATION.
  470. * modify usb address here.
  471. */
  472. if (usbhsh_is_request_address(urb)) {
  473. /* FIXME */
  474. req.wValue = 1;
  475. dev_dbg(dev, "create new address - %d\n", req.wValue);
  476. }
  477. /* set request */
  478. usbhs_usbreq_set_val(priv, &req);
  479. /*
  480. * wait setup packet ACK
  481. */
  482. wait_for_completion(&hpriv->setup_ack_done);
  483. dev_dbg(dev, "%s done\n", __func__);
  484. }
  485. /*
  486. * DCP data stage
  487. */
  488. static void usbhsh_data_stage_packet_done(struct usbhs_priv *priv,
  489. struct usbhs_pkt *pkt)
  490. {
  491. struct usbhsh_request *ureq = usbhsh_pkt_to_req(pkt);
  492. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  493. struct urb *urb = ureq->urb;
  494. /* this ureq was connected to urb when usbhsh_urb_enqueue() */
  495. usbhsh_req_free(hpriv, ureq);
  496. usbhsh_urb_to_ureq(urb) = NULL;
  497. }
  498. static void usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv,
  499. struct urb *urb,
  500. struct usbhs_pipe *pipe)
  501. {
  502. struct usbhsh_request *ureq;
  503. struct usbhs_pkt *pkt;
  504. /*
  505. * FIXME
  506. *
  507. * data stage uses ureq which is connected to urb
  508. * see usbhsh_urb_enqueue() :: alloc new request.
  509. * it will be freed in usbhsh_data_stage_packet_done()
  510. */
  511. ureq = usbhsh_urb_to_ureq(urb);
  512. pkt = &ureq->pkt;
  513. if (usb_pipein(urb->pipe))
  514. pipe->handler = &usbhs_dcp_data_stage_in_handler;
  515. else
  516. pipe->handler = &usbhs_dcp_data_stage_out_handler;
  517. usbhs_pkt_push(pipe, pkt,
  518. usbhsh_data_stage_packet_done,
  519. urb->transfer_buffer,
  520. urb->transfer_buffer_length,
  521. (urb->transfer_flags & URB_ZERO_PACKET));
  522. }
  523. /*
  524. * DCP status stage
  525. */
  526. static void usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv,
  527. struct urb *urb,
  528. struct usbhs_pipe *pipe)
  529. {
  530. struct usbhsh_request *ureq;
  531. struct usbhs_pkt *pkt;
  532. /*
  533. * FIXME
  534. *
  535. * status stage uses allocated ureq.
  536. * it will be freed on usbhsh_queue_done()
  537. */
  538. ureq = usbhsh_req_alloc(hpriv, urb, GFP_KERNEL);
  539. pkt = &ureq->pkt;
  540. if (usb_pipein(urb->pipe))
  541. pipe->handler = &usbhs_dcp_status_stage_in_handler;
  542. else
  543. pipe->handler = &usbhs_dcp_status_stage_out_handler;
  544. usbhs_pkt_push(pipe, pkt,
  545. usbhsh_queue_done,
  546. NULL,
  547. urb->transfer_buffer_length,
  548. 0);
  549. }
  550. static int usbhsh_dcp_queue_push(struct usb_hcd *hcd,
  551. struct usbhsh_hpriv *hpriv,
  552. struct usbhs_pipe *pipe,
  553. struct urb *urb)
  554. {
  555. struct device *dev = usbhsh_hcd_to_dev(hcd);
  556. dev_dbg(dev, "%s\n", __func__);
  557. /*
  558. * setup stage
  559. *
  560. * usbhsh_send_setup_stage_packet() wait SACK/SIGN
  561. */
  562. usbhsh_setup_stage_packet_push(hpriv, urb, pipe);
  563. /*
  564. * data stage
  565. *
  566. * It is pushed only when urb has buffer.
  567. */
  568. if (urb->transfer_buffer_length)
  569. usbhsh_data_stage_packet_push(hpriv, urb, pipe);
  570. /*
  571. * status stage
  572. */
  573. usbhsh_status_stage_packet_push(hpriv, urb, pipe);
  574. /*
  575. * start pushed packets
  576. */
  577. usbhs_pkt_start(pipe);
  578. return 0;
  579. }
  580. /*
  581. * dma map functions
  582. */
  583. static int usbhsh_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
  584. {
  585. return 0;
  586. }
  587. /*
  588. * for hc_driver
  589. */
  590. static int usbhsh_host_start(struct usb_hcd *hcd)
  591. {
  592. return 0;
  593. }
  594. static void usbhsh_host_stop(struct usb_hcd *hcd)
  595. {
  596. }
  597. static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
  598. struct urb *urb,
  599. gfp_t mem_flags)
  600. {
  601. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  602. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  603. struct device *dev = usbhs_priv_to_dev(priv);
  604. struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
  605. struct usb_host_endpoint *ep = urb->ep;
  606. struct usbhsh_request *ureq;
  607. struct usbhsh_device *udev, *new_udev = NULL;
  608. struct usbhs_pipe *pipe;
  609. struct usbhsh_ep *uep;
  610. int is_dir_in = usb_pipein(urb->pipe);
  611. int ret;
  612. dev_dbg(dev, "%s (%s)\n", __func__, is_dir_in ? "in" : "out");
  613. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  614. if (ret)
  615. goto usbhsh_urb_enqueue_error_not_linked;
  616. /*
  617. * get udev
  618. */
  619. udev = usbhsh_usbv_to_udev(usbv);
  620. if (!udev) {
  621. new_udev = usbhsh_device_alloc(hpriv, urb);
  622. if (!new_udev)
  623. goto usbhsh_urb_enqueue_error_not_linked;
  624. udev = new_udev;
  625. }
  626. /*
  627. * get uep
  628. */
  629. uep = usbhsh_ep_to_uep(ep);
  630. if (!uep) {
  631. uep = usbhsh_endpoint_alloc(hpriv, udev, ep,
  632. is_dir_in, mem_flags);
  633. if (!uep)
  634. goto usbhsh_urb_enqueue_error_free_device;
  635. }
  636. pipe = usbhsh_uep_to_pipe(uep);
  637. /*
  638. * alloc new request
  639. */
  640. ureq = usbhsh_req_alloc(hpriv, urb, mem_flags);
  641. if (unlikely(!ureq)) {
  642. ret = -ENOMEM;
  643. goto usbhsh_urb_enqueue_error_free_endpoint;
  644. }
  645. usbhsh_urb_to_ureq(urb) = ureq;
  646. /*
  647. * push packet
  648. */
  649. if (usb_pipecontrol(urb->pipe))
  650. usbhsh_dcp_queue_push(hcd, hpriv, pipe, urb);
  651. else
  652. usbhsh_queue_push(hcd, pipe, urb);
  653. return 0;
  654. usbhsh_urb_enqueue_error_free_endpoint:
  655. usbhsh_endpoint_free(hpriv, ep);
  656. usbhsh_urb_enqueue_error_free_device:
  657. if (new_udev)
  658. usbhsh_device_free(hpriv, new_udev);
  659. usbhsh_urb_enqueue_error_not_linked:
  660. dev_dbg(dev, "%s error\n", __func__);
  661. return ret;
  662. }
  663. static int usbhsh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  664. {
  665. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  666. struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb);
  667. if (ureq) {
  668. usbhsh_req_free(hpriv, ureq);
  669. usbhsh_urb_to_ureq(urb) = NULL;
  670. }
  671. return 0;
  672. }
  673. static void usbhsh_endpoint_disable(struct usb_hcd *hcd,
  674. struct usb_host_endpoint *ep)
  675. {
  676. struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
  677. struct usbhsh_device *udev;
  678. struct usbhsh_hpriv *hpriv;
  679. /*
  680. * this function might be called manytimes by same hcd/ep
  681. * in-endpoitn == out-endpoint if ep == dcp.
  682. */
  683. if (!uep)
  684. return;
  685. udev = usbhsh_uep_to_udev(uep);
  686. hpriv = usbhsh_hcd_to_hpriv(hcd);
  687. usbhsh_endpoint_free(hpriv, ep);
  688. ep->hcpriv = NULL;
  689. /*
  690. * if there is no endpoint,
  691. * free device
  692. */
  693. if (!usbhsh_device_has_endpoint(udev))
  694. usbhsh_device_free(hpriv, udev);
  695. }
  696. static int usbhsh_hub_status_data(struct usb_hcd *hcd, char *buf)
  697. {
  698. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  699. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  700. struct device *dev = usbhs_priv_to_dev(priv);
  701. int roothub_id = 1; /* only 1 root hub */
  702. /*
  703. * does port stat was changed ?
  704. * check USB_PORT_STAT_C_xxx << 16
  705. */
  706. if (usbhsh_port_stat_get(hpriv) & 0xFFFF0000)
  707. *buf = (1 << roothub_id);
  708. else
  709. *buf = 0;
  710. dev_dbg(dev, "%s (%02x)\n", __func__, *buf);
  711. return !!(*buf);
  712. }
  713. static int __usbhsh_hub_hub_feature(struct usbhsh_hpriv *hpriv,
  714. u16 typeReq, u16 wValue,
  715. u16 wIndex, char *buf, u16 wLength)
  716. {
  717. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  718. struct device *dev = usbhs_priv_to_dev(priv);
  719. switch (wValue) {
  720. case C_HUB_OVER_CURRENT:
  721. case C_HUB_LOCAL_POWER:
  722. dev_dbg(dev, "%s :: C_HUB_xx\n", __func__);
  723. return 0;
  724. }
  725. return -EPIPE;
  726. }
  727. static int __usbhsh_hub_port_feature(struct usbhsh_hpriv *hpriv,
  728. u16 typeReq, u16 wValue,
  729. u16 wIndex, char *buf, u16 wLength)
  730. {
  731. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  732. struct device *dev = usbhs_priv_to_dev(priv);
  733. int enable = (typeReq == SetPortFeature);
  734. int speed, i, timeout = 128;
  735. int roothub_id = 1; /* only 1 root hub */
  736. /* common error */
  737. if (wIndex > roothub_id || wLength != 0)
  738. return -EPIPE;
  739. /* check wValue */
  740. switch (wValue) {
  741. case USB_PORT_FEAT_POWER:
  742. usbhs_vbus_ctrl(priv, enable);
  743. dev_dbg(dev, "%s :: USB_PORT_FEAT_POWER\n", __func__);
  744. break;
  745. case USB_PORT_FEAT_ENABLE:
  746. case USB_PORT_FEAT_SUSPEND:
  747. case USB_PORT_FEAT_C_ENABLE:
  748. case USB_PORT_FEAT_C_SUSPEND:
  749. case USB_PORT_FEAT_C_CONNECTION:
  750. case USB_PORT_FEAT_C_OVER_CURRENT:
  751. case USB_PORT_FEAT_C_RESET:
  752. dev_dbg(dev, "%s :: USB_PORT_FEAT_xxx\n", __func__);
  753. break;
  754. case USB_PORT_FEAT_RESET:
  755. if (!enable)
  756. break;
  757. usbhsh_port_stat_clear(hpriv,
  758. USB_PORT_STAT_HIGH_SPEED |
  759. USB_PORT_STAT_LOW_SPEED);
  760. usbhs_bus_send_reset(priv);
  761. msleep(20);
  762. usbhs_bus_send_sof_enable(priv);
  763. for (i = 0; i < timeout ; i++) {
  764. switch (usbhs_bus_get_speed(priv)) {
  765. case USB_SPEED_LOW:
  766. speed = USB_PORT_STAT_LOW_SPEED;
  767. goto got_usb_bus_speed;
  768. case USB_SPEED_HIGH:
  769. speed = USB_PORT_STAT_HIGH_SPEED;
  770. goto got_usb_bus_speed;
  771. case USB_SPEED_FULL:
  772. speed = 0;
  773. goto got_usb_bus_speed;
  774. }
  775. msleep(20);
  776. }
  777. return -EPIPE;
  778. got_usb_bus_speed:
  779. usbhsh_port_stat_set(hpriv, speed);
  780. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_ENABLE);
  781. dev_dbg(dev, "%s :: USB_PORT_FEAT_RESET (speed = %d)\n",
  782. __func__, speed);
  783. /* status change is not needed */
  784. return 0;
  785. default:
  786. return -EPIPE;
  787. }
  788. /* set/clear status */
  789. if (enable)
  790. usbhsh_port_stat_set(hpriv, (1 << wValue));
  791. else
  792. usbhsh_port_stat_clear(hpriv, (1 << wValue));
  793. return 0;
  794. }
  795. static int __usbhsh_hub_get_status(struct usbhsh_hpriv *hpriv,
  796. u16 typeReq, u16 wValue,
  797. u16 wIndex, char *buf, u16 wLength)
  798. {
  799. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  800. struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buf;
  801. struct device *dev = usbhs_priv_to_dev(priv);
  802. int roothub_id = 1; /* only 1 root hub */
  803. switch (typeReq) {
  804. case GetHubStatus:
  805. dev_dbg(dev, "%s :: GetHubStatus\n", __func__);
  806. *buf = 0x00;
  807. break;
  808. case GetPortStatus:
  809. if (wIndex != roothub_id)
  810. return -EPIPE;
  811. dev_dbg(dev, "%s :: GetPortStatus\n", __func__);
  812. *(__le32 *)buf = cpu_to_le32(usbhsh_port_stat_get(hpriv));
  813. break;
  814. case GetHubDescriptor:
  815. desc->bDescriptorType = 0x29;
  816. desc->bHubContrCurrent = 0;
  817. desc->bNbrPorts = roothub_id;
  818. desc->bDescLength = 9;
  819. desc->bPwrOn2PwrGood = 0;
  820. desc->wHubCharacteristics = cpu_to_le16(0x0011);
  821. desc->u.hs.DeviceRemovable[0] = (roothub_id << 1);
  822. desc->u.hs.DeviceRemovable[1] = ~0;
  823. dev_dbg(dev, "%s :: GetHubDescriptor\n", __func__);
  824. break;
  825. }
  826. return 0;
  827. }
  828. static int usbhsh_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  829. u16 wIndex, char *buf, u16 wLength)
  830. {
  831. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  832. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  833. struct device *dev = usbhs_priv_to_dev(priv);
  834. int ret = -EPIPE;
  835. switch (typeReq) {
  836. /* Hub Feature */
  837. case ClearHubFeature:
  838. case SetHubFeature:
  839. ret = __usbhsh_hub_hub_feature(hpriv, typeReq,
  840. wValue, wIndex, buf, wLength);
  841. break;
  842. /* Port Feature */
  843. case SetPortFeature:
  844. case ClearPortFeature:
  845. ret = __usbhsh_hub_port_feature(hpriv, typeReq,
  846. wValue, wIndex, buf, wLength);
  847. break;
  848. /* Get status */
  849. case GetHubStatus:
  850. case GetPortStatus:
  851. case GetHubDescriptor:
  852. ret = __usbhsh_hub_get_status(hpriv, typeReq,
  853. wValue, wIndex, buf, wLength);
  854. break;
  855. }
  856. dev_dbg(dev, "typeReq = %x, ret = %d, port_stat = %x\n",
  857. typeReq, ret, usbhsh_port_stat_get(hpriv));
  858. return ret;
  859. }
  860. static struct hc_driver usbhsh_driver = {
  861. .description = usbhsh_hcd_name,
  862. .hcd_priv_size = sizeof(struct usbhsh_hpriv),
  863. /*
  864. * generic hardware linkage
  865. */
  866. .flags = HCD_USB2,
  867. .start = usbhsh_host_start,
  868. .stop = usbhsh_host_stop,
  869. /*
  870. * managing i/o requests and associated device resources
  871. */
  872. .urb_enqueue = usbhsh_urb_enqueue,
  873. .urb_dequeue = usbhsh_urb_dequeue,
  874. .endpoint_disable = usbhsh_endpoint_disable,
  875. /*
  876. * root hub
  877. */
  878. .hub_status_data = usbhsh_hub_status_data,
  879. .hub_control = usbhsh_hub_control,
  880. };
  881. /*
  882. * interrupt functions
  883. */
  884. static int usbhsh_irq_attch(struct usbhs_priv *priv,
  885. struct usbhs_irq_state *irq_state)
  886. {
  887. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  888. struct device *dev = usbhs_priv_to_dev(priv);
  889. dev_dbg(dev, "device attached\n");
  890. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_CONNECTION);
  891. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
  892. return 0;
  893. }
  894. static int usbhsh_irq_dtch(struct usbhs_priv *priv,
  895. struct usbhs_irq_state *irq_state)
  896. {
  897. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  898. struct device *dev = usbhs_priv_to_dev(priv);
  899. dev_dbg(dev, "device detached\n");
  900. usbhsh_port_stat_clear(hpriv, USB_PORT_STAT_CONNECTION);
  901. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
  902. return 0;
  903. }
  904. static int usbhsh_irq_setup_ack(struct usbhs_priv *priv,
  905. struct usbhs_irq_state *irq_state)
  906. {
  907. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  908. struct device *dev = usbhs_priv_to_dev(priv);
  909. dev_dbg(dev, "setup packet OK\n");
  910. complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
  911. return 0;
  912. }
  913. static int usbhsh_irq_setup_err(struct usbhs_priv *priv,
  914. struct usbhs_irq_state *irq_state)
  915. {
  916. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  917. struct device *dev = usbhs_priv_to_dev(priv);
  918. dev_dbg(dev, "setup packet Err\n");
  919. complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
  920. return 0;
  921. }
  922. /*
  923. * module start/stop
  924. */
  925. static void usbhsh_pipe_init_for_host(struct usbhs_priv *priv)
  926. {
  927. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  928. struct usbhsh_pipe_info *pipe_info = hpriv->pipe_info;
  929. struct usbhs_pipe *pipe;
  930. u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
  931. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  932. int old_type, dir_in, i;
  933. /* init all pipe */
  934. old_type = USB_ENDPOINT_XFER_CONTROL;
  935. for (i = 0; i < pipe_size; i++) {
  936. pipe_info[i].usr_cnt = 0;
  937. /*
  938. * data "output" will be finished as soon as possible,
  939. * but there is no guaranty at data "input" case.
  940. *
  941. * "input" needs "standby" pipe.
  942. * So, "input" direction pipe > "output" direction pipe
  943. * is good idea.
  944. *
  945. * 1st USB_ENDPOINT_XFER_xxx will be output direction,
  946. * and the other will be input direction here.
  947. *
  948. * ex)
  949. * ...
  950. * USB_ENDPOINT_XFER_ISOC -> dir out
  951. * USB_ENDPOINT_XFER_ISOC -> dir in
  952. * USB_ENDPOINT_XFER_BULK -> dir out
  953. * USB_ENDPOINT_XFER_BULK -> dir in
  954. * USB_ENDPOINT_XFER_BULK -> dir in
  955. * ...
  956. */
  957. dir_in = (pipe_type[i] == old_type);
  958. old_type = pipe_type[i];
  959. if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) {
  960. pipe = usbhs_dcp_malloc(priv);
  961. usbhsh_hpriv_to_dcp(hpriv) = pipe;
  962. } else {
  963. pipe = usbhs_pipe_malloc(priv,
  964. pipe_type[i],
  965. dir_in);
  966. }
  967. pipe->mod_private = pipe_info + i;
  968. }
  969. }
  970. static int usbhsh_start(struct usbhs_priv *priv)
  971. {
  972. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  973. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  974. struct usbhs_mod *mod = usbhs_mod_get_current(priv);
  975. struct device *dev = usbhs_priv_to_dev(priv);
  976. int ret;
  977. /* add hcd */
  978. ret = usb_add_hcd(hcd, 0, 0);
  979. if (ret < 0)
  980. return 0;
  981. /*
  982. * pipe initialize and enable DCP
  983. */
  984. usbhs_pipe_init(priv,
  985. usbhsh_dma_map_ctrl);
  986. usbhs_fifo_init(priv);
  987. usbhsh_pipe_init_for_host(priv);
  988. /*
  989. * system config enble
  990. * - HI speed
  991. * - host
  992. * - usb module
  993. */
  994. usbhs_sys_hispeed_ctrl(priv, 1);
  995. usbhs_sys_host_ctrl(priv, 1);
  996. usbhs_sys_usb_ctrl(priv, 1);
  997. /*
  998. * enable irq callback
  999. */
  1000. mod->irq_attch = usbhsh_irq_attch;
  1001. mod->irq_dtch = usbhsh_irq_dtch;
  1002. mod->irq_sack = usbhsh_irq_setup_ack;
  1003. mod->irq_sign = usbhsh_irq_setup_err;
  1004. usbhs_irq_callback_update(priv, mod);
  1005. dev_dbg(dev, "start host\n");
  1006. return ret;
  1007. }
  1008. static int usbhsh_stop(struct usbhs_priv *priv)
  1009. {
  1010. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  1011. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  1012. struct usbhs_mod *mod = usbhs_mod_get_current(priv);
  1013. struct device *dev = usbhs_priv_to_dev(priv);
  1014. /*
  1015. * disable irq callback
  1016. */
  1017. mod->irq_attch = NULL;
  1018. mod->irq_dtch = NULL;
  1019. mod->irq_sack = NULL;
  1020. mod->irq_sign = NULL;
  1021. usbhs_irq_callback_update(priv, mod);
  1022. usb_remove_hcd(hcd);
  1023. /* disable sys */
  1024. usbhs_sys_hispeed_ctrl(priv, 0);
  1025. usbhs_sys_host_ctrl(priv, 0);
  1026. usbhs_sys_usb_ctrl(priv, 0);
  1027. dev_dbg(dev, "quit host\n");
  1028. return 0;
  1029. }
  1030. int usbhs_mod_host_probe(struct usbhs_priv *priv)
  1031. {
  1032. struct usbhsh_hpriv *hpriv;
  1033. struct usb_hcd *hcd;
  1034. struct usbhsh_pipe_info *pipe_info;
  1035. struct usbhsh_device *udev;
  1036. struct device *dev = usbhs_priv_to_dev(priv);
  1037. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  1038. int i;
  1039. /* initialize hcd */
  1040. hcd = usb_create_hcd(&usbhsh_driver, dev, usbhsh_hcd_name);
  1041. if (!hcd) {
  1042. dev_err(dev, "Failed to create hcd\n");
  1043. return -ENOMEM;
  1044. }
  1045. pipe_info = kzalloc(sizeof(*pipe_info) * pipe_size, GFP_KERNEL);
  1046. if (!pipe_info) {
  1047. dev_err(dev, "Could not allocate pipe_info\n");
  1048. goto usbhs_mod_host_probe_err;
  1049. }
  1050. /*
  1051. * CAUTION
  1052. *
  1053. * There is no guarantee that it is possible to access usb module here.
  1054. * Don't accesses to it.
  1055. * The accesse will be enable after "usbhsh_start"
  1056. */
  1057. hpriv = usbhsh_hcd_to_hpriv(hcd);
  1058. /*
  1059. * register itself
  1060. */
  1061. usbhs_mod_register(priv, &hpriv->mod, USBHS_HOST);
  1062. /* init hpriv */
  1063. hpriv->mod.name = "host";
  1064. hpriv->mod.start = usbhsh_start;
  1065. hpriv->mod.stop = usbhsh_stop;
  1066. hpriv->pipe_info = pipe_info;
  1067. hpriv->pipe_size = pipe_size;
  1068. usbhsh_req_list_init(hpriv);
  1069. usbhsh_port_stat_init(hpriv);
  1070. /* init all device */
  1071. usbhsh_for_each_udev_with_dev0(udev, hpriv, i) {
  1072. udev->usbv = NULL;
  1073. INIT_LIST_HEAD(&udev->ep_list_head);
  1074. }
  1075. dev_info(dev, "host probed\n");
  1076. return 0;
  1077. usbhs_mod_host_probe_err:
  1078. usb_put_hcd(hcd);
  1079. return -ENOMEM;
  1080. }
  1081. int usbhs_mod_host_remove(struct usbhs_priv *priv)
  1082. {
  1083. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  1084. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  1085. usbhsh_req_list_quit(hpriv);
  1086. usb_put_hcd(hcd);
  1087. return 0;
  1088. }