mod_host.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. gfp_t mem_flags)
  295. {
  296. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  297. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  298. struct usbhsh_ep *uep;
  299. struct usbhsh_pipe_info *info;
  300. struct usbhs_pipe *pipe, *best_pipe;
  301. struct device *dev = usbhsh_hcd_to_dev(hcd);
  302. struct usb_endpoint_descriptor *desc = &ep->desc;
  303. int type, i;
  304. unsigned int min_usr;
  305. uep = kzalloc(sizeof(struct usbhsh_ep), mem_flags);
  306. if (!uep) {
  307. dev_err(dev, "usbhsh_ep alloc fail\n");
  308. return NULL;
  309. }
  310. type = usb_endpoint_type(desc);
  311. /*
  312. * find best pipe for endpoint
  313. * see
  314. * HARDWARE LIMITATION
  315. */
  316. min_usr = ~0;
  317. best_pipe = NULL;
  318. usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
  319. if (!usbhs_pipe_type_is(pipe, type))
  320. continue;
  321. info = usbhsh_pipe_info(pipe);
  322. if (min_usr > info->usr_cnt) {
  323. min_usr = info->usr_cnt;
  324. best_pipe = pipe;
  325. }
  326. }
  327. if (unlikely(!best_pipe)) {
  328. dev_err(dev, "couldn't find best pipe\n");
  329. kfree(uep);
  330. return NULL;
  331. }
  332. /*
  333. * init uep
  334. */
  335. uep->pipe = best_pipe;
  336. uep->maxp = usb_endpoint_maxp(desc);
  337. usbhsh_uep_to_udev(uep) = udev;
  338. usbhsh_ep_to_uep(ep) = uep;
  339. /*
  340. * update pipe user count
  341. */
  342. info = usbhsh_pipe_info(best_pipe);
  343. info->usr_cnt++;
  344. /* init this endpoint, and attach it to udev */
  345. INIT_LIST_HEAD(&uep->ep_list);
  346. list_add_tail(&uep->ep_list, &udev->ep_list_head);
  347. /*
  348. * usbhs_pipe_config_update() should be called after
  349. * usbhs_device_config()
  350. * see
  351. * DCPMAXP/PIPEMAXP
  352. */
  353. usbhs_pipe_config_update(uep->pipe,
  354. usbhsh_device_number(hpriv, udev),
  355. usb_endpoint_num(desc),
  356. uep->maxp);
  357. dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
  358. usbhsh_device_number(hpriv, udev),
  359. usbhs_pipe_name(pipe), uep);
  360. return uep;
  361. }
  362. void usbhsh_endpoint_free(struct usbhsh_hpriv *hpriv,
  363. struct usb_host_endpoint *ep)
  364. {
  365. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  366. struct device *dev = usbhs_priv_to_dev(priv);
  367. struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
  368. struct usbhsh_pipe_info *info;
  369. if (!uep)
  370. return;
  371. dev_dbg(dev, "%s [%d-%s](%p)\n", __func__,
  372. usbhsh_device_number(hpriv, usbhsh_uep_to_udev(uep)),
  373. usbhs_pipe_name(uep->pipe), uep);
  374. info = usbhsh_pipe_info(uep->pipe);
  375. info->usr_cnt--;
  376. /* remove this endpoint from udev */
  377. list_del_init(&uep->ep_list);
  378. usbhsh_uep_to_udev(uep) = NULL;
  379. usbhsh_ep_to_uep(ep) = NULL;
  380. kfree(uep);
  381. }
  382. /*
  383. * queue push/pop
  384. */
  385. static void usbhsh_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt)
  386. {
  387. struct usbhsh_request *ureq = usbhsh_pkt_to_req(pkt);
  388. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  389. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  390. struct urb *urb = ureq->urb;
  391. struct device *dev = usbhs_priv_to_dev(priv);
  392. dev_dbg(dev, "%s\n", __func__);
  393. if (!urb) {
  394. dev_warn(dev, "pkt doesn't have urb\n");
  395. return;
  396. }
  397. urb->actual_length = pkt->actual;
  398. usbhsh_req_free(hpriv, ureq);
  399. usbhsh_urb_to_ureq(urb) = NULL;
  400. usb_hcd_unlink_urb_from_ep(hcd, urb);
  401. usb_hcd_giveback_urb(hcd, urb, 0);
  402. }
  403. static int usbhsh_queue_push(struct usb_hcd *hcd,
  404. struct usbhs_pipe *pipe,
  405. struct urb *urb)
  406. {
  407. struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb);
  408. struct usbhs_pkt *pkt = &ureq->pkt;
  409. struct device *dev = usbhsh_hcd_to_dev(hcd);
  410. void *buf;
  411. int len;
  412. if (usb_pipeisoc(urb->pipe)) {
  413. dev_err(dev, "pipe iso is not supported now\n");
  414. return -EIO;
  415. }
  416. if (usb_pipein(urb->pipe))
  417. pipe->handler = &usbhs_fifo_pio_pop_handler;
  418. else
  419. pipe->handler = &usbhs_fifo_pio_push_handler;
  420. buf = (void *)(urb->transfer_buffer + urb->actual_length);
  421. len = urb->transfer_buffer_length - urb->actual_length;
  422. dev_dbg(dev, "%s\n", __func__);
  423. usbhs_pkt_push(pipe, pkt, usbhsh_queue_done,
  424. buf, len, (urb->transfer_flags & URB_ZERO_PACKET));
  425. usbhs_pkt_start(pipe);
  426. return 0;
  427. }
  428. /*
  429. * DCP setup stage
  430. */
  431. static int usbhsh_is_request_address(struct urb *urb)
  432. {
  433. struct usb_ctrlrequest *cmd;
  434. cmd = (struct usb_ctrlrequest *)urb->setup_packet;
  435. if ((DeviceOutRequest == cmd->bRequestType << 8) &&
  436. (USB_REQ_SET_ADDRESS == cmd->bRequest))
  437. return 1;
  438. else
  439. return 0;
  440. }
  441. static void usbhsh_setup_stage_packet_push(struct usbhsh_hpriv *hpriv,
  442. struct urb *urb,
  443. struct usbhs_pipe *pipe)
  444. {
  445. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  446. struct usb_ctrlrequest req;
  447. struct device *dev = usbhs_priv_to_dev(priv);
  448. /*
  449. * wait setup packet ACK
  450. * see
  451. * usbhsh_irq_setup_ack()
  452. * usbhsh_irq_setup_err()
  453. */
  454. init_completion(&hpriv->setup_ack_done);
  455. /* copy original request */
  456. memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest));
  457. /*
  458. * renesas_usbhs can not use original usb address.
  459. * see HARDWARE LIMITATION.
  460. * modify usb address here.
  461. */
  462. if (usbhsh_is_request_address(urb)) {
  463. /* FIXME */
  464. req.wValue = 1;
  465. dev_dbg(dev, "create new address - %d\n", req.wValue);
  466. }
  467. /* set request */
  468. usbhs_usbreq_set_val(priv, &req);
  469. /*
  470. * wait setup packet ACK
  471. */
  472. wait_for_completion(&hpriv->setup_ack_done);
  473. dev_dbg(dev, "%s done\n", __func__);
  474. }
  475. /*
  476. * DCP data stage
  477. */
  478. static void usbhsh_data_stage_packet_done(struct usbhs_priv *priv,
  479. struct usbhs_pkt *pkt)
  480. {
  481. struct usbhsh_request *ureq = usbhsh_pkt_to_req(pkt);
  482. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  483. struct urb *urb = ureq->urb;
  484. /* this ureq was connected to urb when usbhsh_urb_enqueue() */
  485. usbhsh_req_free(hpriv, ureq);
  486. usbhsh_urb_to_ureq(urb) = NULL;
  487. }
  488. static void usbhsh_data_stage_packet_push(struct usbhsh_hpriv *hpriv,
  489. struct urb *urb,
  490. struct usbhs_pipe *pipe)
  491. {
  492. struct usbhsh_request *ureq;
  493. struct usbhs_pkt *pkt;
  494. /*
  495. * FIXME
  496. *
  497. * data stage uses ureq which is connected to urb
  498. * see usbhsh_urb_enqueue() :: alloc new request.
  499. * it will be freed in usbhsh_data_stage_packet_done()
  500. */
  501. ureq = usbhsh_urb_to_ureq(urb);
  502. pkt = &ureq->pkt;
  503. if (usb_pipein(urb->pipe))
  504. pipe->handler = &usbhs_dcp_data_stage_in_handler;
  505. else
  506. pipe->handler = &usbhs_dcp_data_stage_out_handler;
  507. usbhs_pkt_push(pipe, pkt,
  508. usbhsh_data_stage_packet_done,
  509. urb->transfer_buffer,
  510. urb->transfer_buffer_length,
  511. (urb->transfer_flags & URB_ZERO_PACKET));
  512. }
  513. /*
  514. * DCP status stage
  515. */
  516. static void usbhsh_status_stage_packet_push(struct usbhsh_hpriv *hpriv,
  517. struct urb *urb,
  518. struct usbhs_pipe *pipe)
  519. {
  520. struct usbhsh_request *ureq;
  521. struct usbhs_pkt *pkt;
  522. /*
  523. * FIXME
  524. *
  525. * status stage uses allocated ureq.
  526. * it will be freed on usbhsh_queue_done()
  527. */
  528. ureq = usbhsh_req_alloc(hpriv, urb, GFP_KERNEL);
  529. pkt = &ureq->pkt;
  530. if (usb_pipein(urb->pipe))
  531. pipe->handler = &usbhs_dcp_status_stage_in_handler;
  532. else
  533. pipe->handler = &usbhs_dcp_status_stage_out_handler;
  534. usbhs_pkt_push(pipe, pkt,
  535. usbhsh_queue_done,
  536. NULL,
  537. urb->transfer_buffer_length,
  538. 0);
  539. }
  540. static int usbhsh_dcp_queue_push(struct usb_hcd *hcd,
  541. struct usbhsh_hpriv *hpriv,
  542. struct usbhs_pipe *pipe,
  543. struct urb *urb)
  544. {
  545. struct device *dev = usbhsh_hcd_to_dev(hcd);
  546. dev_dbg(dev, "%s\n", __func__);
  547. /*
  548. * setup stage
  549. *
  550. * usbhsh_send_setup_stage_packet() wait SACK/SIGN
  551. */
  552. usbhsh_setup_stage_packet_push(hpriv, urb, pipe);
  553. /*
  554. * data stage
  555. *
  556. * It is pushed only when urb has buffer.
  557. */
  558. if (urb->transfer_buffer_length)
  559. usbhsh_data_stage_packet_push(hpriv, urb, pipe);
  560. /*
  561. * status stage
  562. */
  563. usbhsh_status_stage_packet_push(hpriv, urb, pipe);
  564. /*
  565. * start pushed packets
  566. */
  567. usbhs_pkt_start(pipe);
  568. return 0;
  569. }
  570. /*
  571. * dma map functions
  572. */
  573. static int usbhsh_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
  574. {
  575. return 0;
  576. }
  577. /*
  578. * for hc_driver
  579. */
  580. static int usbhsh_host_start(struct usb_hcd *hcd)
  581. {
  582. return 0;
  583. }
  584. static void usbhsh_host_stop(struct usb_hcd *hcd)
  585. {
  586. }
  587. static int usbhsh_urb_enqueue(struct usb_hcd *hcd,
  588. struct urb *urb,
  589. gfp_t mem_flags)
  590. {
  591. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  592. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  593. struct device *dev = usbhs_priv_to_dev(priv);
  594. struct usb_device *usbv = usbhsh_urb_to_usbv(urb);
  595. struct usb_host_endpoint *ep = urb->ep;
  596. struct usbhsh_request *ureq;
  597. struct usbhsh_device *udev, *new_udev = NULL;
  598. struct usbhs_pipe *pipe;
  599. struct usbhsh_ep *uep;
  600. int ret;
  601. dev_dbg(dev, "%s (%s)\n",
  602. __func__, usb_pipein(urb->pipe) ? "in" : "out");
  603. ret = usb_hcd_link_urb_to_ep(hcd, urb);
  604. if (ret)
  605. goto usbhsh_urb_enqueue_error_not_linked;
  606. /*
  607. * get udev
  608. */
  609. udev = usbhsh_usbv_to_udev(usbv);
  610. if (!udev) {
  611. new_udev = usbhsh_device_alloc(hpriv, urb);
  612. if (!new_udev)
  613. goto usbhsh_urb_enqueue_error_not_linked;
  614. udev = new_udev;
  615. }
  616. /*
  617. * get uep
  618. */
  619. uep = usbhsh_ep_to_uep(ep);
  620. if (!uep) {
  621. uep = usbhsh_endpoint_alloc(hpriv, udev, ep, mem_flags);
  622. if (!uep)
  623. goto usbhsh_urb_enqueue_error_free_device;
  624. }
  625. pipe = usbhsh_uep_to_pipe(uep);
  626. /*
  627. * alloc new request
  628. */
  629. ureq = usbhsh_req_alloc(hpriv, urb, mem_flags);
  630. if (unlikely(!ureq)) {
  631. ret = -ENOMEM;
  632. goto usbhsh_urb_enqueue_error_free_endpoint;
  633. }
  634. usbhsh_urb_to_ureq(urb) = ureq;
  635. /*
  636. * push packet
  637. */
  638. if (usb_pipecontrol(urb->pipe))
  639. usbhsh_dcp_queue_push(hcd, hpriv, pipe, urb);
  640. else
  641. usbhsh_queue_push(hcd, pipe, urb);
  642. return 0;
  643. usbhsh_urb_enqueue_error_free_endpoint:
  644. usbhsh_endpoint_free(hpriv, ep);
  645. usbhsh_urb_enqueue_error_free_device:
  646. if (new_udev)
  647. usbhsh_device_free(hpriv, new_udev);
  648. usbhsh_urb_enqueue_error_not_linked:
  649. dev_dbg(dev, "%s error\n", __func__);
  650. return ret;
  651. }
  652. static int usbhsh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  653. {
  654. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  655. struct usbhsh_request *ureq = usbhsh_urb_to_ureq(urb);
  656. if (ureq) {
  657. usbhsh_req_free(hpriv, ureq);
  658. usbhsh_urb_to_ureq(urb) = NULL;
  659. }
  660. return 0;
  661. }
  662. static void usbhsh_endpoint_disable(struct usb_hcd *hcd,
  663. struct usb_host_endpoint *ep)
  664. {
  665. struct usbhsh_ep *uep = usbhsh_ep_to_uep(ep);
  666. struct usbhsh_device *udev;
  667. struct usbhsh_hpriv *hpriv;
  668. /*
  669. * this function might be called manytimes by same hcd/ep
  670. * in-endpoitn == out-endpoint if ep == dcp.
  671. */
  672. if (!uep)
  673. return;
  674. udev = usbhsh_uep_to_udev(uep);
  675. hpriv = usbhsh_hcd_to_hpriv(hcd);
  676. usbhsh_endpoint_free(hpriv, ep);
  677. ep->hcpriv = NULL;
  678. /*
  679. * if there is no endpoint,
  680. * free device
  681. */
  682. if (!usbhsh_device_has_endpoint(udev))
  683. usbhsh_device_free(hpriv, udev);
  684. }
  685. static int usbhsh_hub_status_data(struct usb_hcd *hcd, char *buf)
  686. {
  687. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  688. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  689. struct device *dev = usbhs_priv_to_dev(priv);
  690. int roothub_id = 1; /* only 1 root hub */
  691. /*
  692. * does port stat was changed ?
  693. * check USB_PORT_STAT_C_xxx << 16
  694. */
  695. if (usbhsh_port_stat_get(hpriv) & 0xFFFF0000)
  696. *buf = (1 << roothub_id);
  697. else
  698. *buf = 0;
  699. dev_dbg(dev, "%s (%02x)\n", __func__, *buf);
  700. return !!(*buf);
  701. }
  702. static int __usbhsh_hub_hub_feature(struct usbhsh_hpriv *hpriv,
  703. u16 typeReq, u16 wValue,
  704. u16 wIndex, char *buf, u16 wLength)
  705. {
  706. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  707. struct device *dev = usbhs_priv_to_dev(priv);
  708. switch (wValue) {
  709. case C_HUB_OVER_CURRENT:
  710. case C_HUB_LOCAL_POWER:
  711. dev_dbg(dev, "%s :: C_HUB_xx\n", __func__);
  712. return 0;
  713. }
  714. return -EPIPE;
  715. }
  716. static int __usbhsh_hub_port_feature(struct usbhsh_hpriv *hpriv,
  717. u16 typeReq, u16 wValue,
  718. u16 wIndex, char *buf, u16 wLength)
  719. {
  720. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  721. struct device *dev = usbhs_priv_to_dev(priv);
  722. int enable = (typeReq == SetPortFeature);
  723. int speed, i, timeout = 128;
  724. int roothub_id = 1; /* only 1 root hub */
  725. /* common error */
  726. if (wIndex > roothub_id || wLength != 0)
  727. return -EPIPE;
  728. /* check wValue */
  729. switch (wValue) {
  730. case USB_PORT_FEAT_POWER:
  731. usbhs_vbus_ctrl(priv, enable);
  732. dev_dbg(dev, "%s :: USB_PORT_FEAT_POWER\n", __func__);
  733. break;
  734. case USB_PORT_FEAT_ENABLE:
  735. case USB_PORT_FEAT_SUSPEND:
  736. case USB_PORT_FEAT_C_ENABLE:
  737. case USB_PORT_FEAT_C_SUSPEND:
  738. case USB_PORT_FEAT_C_CONNECTION:
  739. case USB_PORT_FEAT_C_OVER_CURRENT:
  740. case USB_PORT_FEAT_C_RESET:
  741. dev_dbg(dev, "%s :: USB_PORT_FEAT_xxx\n", __func__);
  742. break;
  743. case USB_PORT_FEAT_RESET:
  744. if (!enable)
  745. break;
  746. usbhsh_port_stat_clear(hpriv,
  747. USB_PORT_STAT_HIGH_SPEED |
  748. USB_PORT_STAT_LOW_SPEED);
  749. usbhs_bus_send_reset(priv);
  750. msleep(20);
  751. usbhs_bus_send_sof_enable(priv);
  752. for (i = 0; i < timeout ; i++) {
  753. switch (usbhs_bus_get_speed(priv)) {
  754. case USB_SPEED_LOW:
  755. speed = USB_PORT_STAT_LOW_SPEED;
  756. goto got_usb_bus_speed;
  757. case USB_SPEED_HIGH:
  758. speed = USB_PORT_STAT_HIGH_SPEED;
  759. goto got_usb_bus_speed;
  760. case USB_SPEED_FULL:
  761. speed = 0;
  762. goto got_usb_bus_speed;
  763. }
  764. msleep(20);
  765. }
  766. return -EPIPE;
  767. got_usb_bus_speed:
  768. usbhsh_port_stat_set(hpriv, speed);
  769. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_ENABLE);
  770. dev_dbg(dev, "%s :: USB_PORT_FEAT_RESET (speed = %d)\n",
  771. __func__, speed);
  772. /* status change is not needed */
  773. return 0;
  774. default:
  775. return -EPIPE;
  776. }
  777. /* set/clear status */
  778. if (enable)
  779. usbhsh_port_stat_set(hpriv, (1 << wValue));
  780. else
  781. usbhsh_port_stat_clear(hpriv, (1 << wValue));
  782. return 0;
  783. }
  784. static int __usbhsh_hub_get_status(struct usbhsh_hpriv *hpriv,
  785. u16 typeReq, u16 wValue,
  786. u16 wIndex, char *buf, u16 wLength)
  787. {
  788. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  789. struct usb_hub_descriptor *desc = (struct usb_hub_descriptor *)buf;
  790. struct device *dev = usbhs_priv_to_dev(priv);
  791. int roothub_id = 1; /* only 1 root hub */
  792. switch (typeReq) {
  793. case GetHubStatus:
  794. dev_dbg(dev, "%s :: GetHubStatus\n", __func__);
  795. *buf = 0x00;
  796. break;
  797. case GetPortStatus:
  798. if (wIndex != roothub_id)
  799. return -EPIPE;
  800. dev_dbg(dev, "%s :: GetPortStatus\n", __func__);
  801. *(__le32 *)buf = cpu_to_le32(usbhsh_port_stat_get(hpriv));
  802. break;
  803. case GetHubDescriptor:
  804. desc->bDescriptorType = 0x29;
  805. desc->bHubContrCurrent = 0;
  806. desc->bNbrPorts = roothub_id;
  807. desc->bDescLength = 9;
  808. desc->bPwrOn2PwrGood = 0;
  809. desc->wHubCharacteristics = cpu_to_le16(0x0011);
  810. desc->u.hs.DeviceRemovable[0] = (roothub_id << 1);
  811. desc->u.hs.DeviceRemovable[1] = ~0;
  812. dev_dbg(dev, "%s :: GetHubDescriptor\n", __func__);
  813. break;
  814. }
  815. return 0;
  816. }
  817. static int usbhsh_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  818. u16 wIndex, char *buf, u16 wLength)
  819. {
  820. struct usbhsh_hpriv *hpriv = usbhsh_hcd_to_hpriv(hcd);
  821. struct usbhs_priv *priv = usbhsh_hpriv_to_priv(hpriv);
  822. struct device *dev = usbhs_priv_to_dev(priv);
  823. int ret = -EPIPE;
  824. switch (typeReq) {
  825. /* Hub Feature */
  826. case ClearHubFeature:
  827. case SetHubFeature:
  828. ret = __usbhsh_hub_hub_feature(hpriv, typeReq,
  829. wValue, wIndex, buf, wLength);
  830. break;
  831. /* Port Feature */
  832. case SetPortFeature:
  833. case ClearPortFeature:
  834. ret = __usbhsh_hub_port_feature(hpriv, typeReq,
  835. wValue, wIndex, buf, wLength);
  836. break;
  837. /* Get status */
  838. case GetHubStatus:
  839. case GetPortStatus:
  840. case GetHubDescriptor:
  841. ret = __usbhsh_hub_get_status(hpriv, typeReq,
  842. wValue, wIndex, buf, wLength);
  843. break;
  844. }
  845. dev_dbg(dev, "typeReq = %x, ret = %d, port_stat = %x\n",
  846. typeReq, ret, usbhsh_port_stat_get(hpriv));
  847. return ret;
  848. }
  849. static struct hc_driver usbhsh_driver = {
  850. .description = usbhsh_hcd_name,
  851. .hcd_priv_size = sizeof(struct usbhsh_hpriv),
  852. /*
  853. * generic hardware linkage
  854. */
  855. .flags = HCD_USB2,
  856. .start = usbhsh_host_start,
  857. .stop = usbhsh_host_stop,
  858. /*
  859. * managing i/o requests and associated device resources
  860. */
  861. .urb_enqueue = usbhsh_urb_enqueue,
  862. .urb_dequeue = usbhsh_urb_dequeue,
  863. .endpoint_disable = usbhsh_endpoint_disable,
  864. /*
  865. * root hub
  866. */
  867. .hub_status_data = usbhsh_hub_status_data,
  868. .hub_control = usbhsh_hub_control,
  869. };
  870. /*
  871. * interrupt functions
  872. */
  873. static int usbhsh_irq_attch(struct usbhs_priv *priv,
  874. struct usbhs_irq_state *irq_state)
  875. {
  876. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  877. struct device *dev = usbhs_priv_to_dev(priv);
  878. dev_dbg(dev, "device attached\n");
  879. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_CONNECTION);
  880. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
  881. return 0;
  882. }
  883. static int usbhsh_irq_dtch(struct usbhs_priv *priv,
  884. struct usbhs_irq_state *irq_state)
  885. {
  886. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  887. struct device *dev = usbhs_priv_to_dev(priv);
  888. dev_dbg(dev, "device detached\n");
  889. usbhsh_port_stat_clear(hpriv, USB_PORT_STAT_CONNECTION);
  890. usbhsh_port_stat_set(hpriv, USB_PORT_STAT_C_CONNECTION << 16);
  891. return 0;
  892. }
  893. static int usbhsh_irq_setup_ack(struct usbhs_priv *priv,
  894. struct usbhs_irq_state *irq_state)
  895. {
  896. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  897. struct device *dev = usbhs_priv_to_dev(priv);
  898. dev_dbg(dev, "setup packet OK\n");
  899. complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
  900. return 0;
  901. }
  902. static int usbhsh_irq_setup_err(struct usbhs_priv *priv,
  903. struct usbhs_irq_state *irq_state)
  904. {
  905. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  906. struct device *dev = usbhs_priv_to_dev(priv);
  907. dev_dbg(dev, "setup packet Err\n");
  908. complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */
  909. return 0;
  910. }
  911. /*
  912. * module start/stop
  913. */
  914. static void usbhsh_pipe_init_for_host(struct usbhs_priv *priv)
  915. {
  916. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  917. struct usbhsh_pipe_info *pipe_info = hpriv->pipe_info;
  918. struct usbhs_pipe *pipe;
  919. u32 *pipe_type = usbhs_get_dparam(priv, pipe_type);
  920. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  921. int old_type, dir_in, i;
  922. /* init all pipe */
  923. old_type = USB_ENDPOINT_XFER_CONTROL;
  924. for (i = 0; i < pipe_size; i++) {
  925. pipe_info[i].usr_cnt = 0;
  926. /*
  927. * data "output" will be finished as soon as possible,
  928. * but there is no guaranty at data "input" case.
  929. *
  930. * "input" needs "standby" pipe.
  931. * So, "input" direction pipe > "output" direction pipe
  932. * is good idea.
  933. *
  934. * 1st USB_ENDPOINT_XFER_xxx will be output direction,
  935. * and the other will be input direction here.
  936. *
  937. * ex)
  938. * ...
  939. * USB_ENDPOINT_XFER_ISOC -> dir out
  940. * USB_ENDPOINT_XFER_ISOC -> dir in
  941. * USB_ENDPOINT_XFER_BULK -> dir out
  942. * USB_ENDPOINT_XFER_BULK -> dir in
  943. * USB_ENDPOINT_XFER_BULK -> dir in
  944. * ...
  945. */
  946. dir_in = (pipe_type[i] == old_type);
  947. old_type = pipe_type[i];
  948. if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) {
  949. pipe = usbhs_dcp_malloc(priv);
  950. usbhsh_hpriv_to_dcp(hpriv) = pipe;
  951. } else {
  952. pipe = usbhs_pipe_malloc(priv,
  953. pipe_type[i],
  954. dir_in);
  955. }
  956. pipe->mod_private = pipe_info + i;
  957. }
  958. }
  959. static int usbhsh_start(struct usbhs_priv *priv)
  960. {
  961. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  962. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  963. struct usbhs_mod *mod = usbhs_mod_get_current(priv);
  964. struct device *dev = usbhs_priv_to_dev(priv);
  965. int ret;
  966. /* add hcd */
  967. ret = usb_add_hcd(hcd, 0, 0);
  968. if (ret < 0)
  969. return 0;
  970. /*
  971. * pipe initialize and enable DCP
  972. */
  973. usbhs_pipe_init(priv,
  974. usbhsh_dma_map_ctrl);
  975. usbhs_fifo_init(priv);
  976. usbhsh_pipe_init_for_host(priv);
  977. /*
  978. * system config enble
  979. * - HI speed
  980. * - host
  981. * - usb module
  982. */
  983. usbhs_sys_hispeed_ctrl(priv, 1);
  984. usbhs_sys_host_ctrl(priv, 1);
  985. usbhs_sys_usb_ctrl(priv, 1);
  986. /*
  987. * enable irq callback
  988. */
  989. mod->irq_attch = usbhsh_irq_attch;
  990. mod->irq_dtch = usbhsh_irq_dtch;
  991. mod->irq_sack = usbhsh_irq_setup_ack;
  992. mod->irq_sign = usbhsh_irq_setup_err;
  993. usbhs_irq_callback_update(priv, mod);
  994. dev_dbg(dev, "start host\n");
  995. return ret;
  996. }
  997. static int usbhsh_stop(struct usbhs_priv *priv)
  998. {
  999. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  1000. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  1001. struct device *dev = usbhs_priv_to_dev(priv);
  1002. usb_remove_hcd(hcd);
  1003. /* disable sys */
  1004. usbhs_sys_hispeed_ctrl(priv, 0);
  1005. usbhs_sys_host_ctrl(priv, 0);
  1006. usbhs_sys_usb_ctrl(priv, 0);
  1007. dev_dbg(dev, "quit host\n");
  1008. return 0;
  1009. }
  1010. int __devinit usbhs_mod_host_probe(struct usbhs_priv *priv)
  1011. {
  1012. struct usbhsh_hpriv *hpriv;
  1013. struct usb_hcd *hcd;
  1014. struct usbhsh_pipe_info *pipe_info;
  1015. struct usbhsh_device *udev;
  1016. struct device *dev = usbhs_priv_to_dev(priv);
  1017. int pipe_size = usbhs_get_dparam(priv, pipe_size);
  1018. int i;
  1019. /* initialize hcd */
  1020. hcd = usb_create_hcd(&usbhsh_driver, dev, usbhsh_hcd_name);
  1021. if (!hcd) {
  1022. dev_err(dev, "Failed to create hcd\n");
  1023. return -ENOMEM;
  1024. }
  1025. pipe_info = kzalloc(sizeof(*pipe_info) * pipe_size, GFP_KERNEL);
  1026. if (!pipe_info) {
  1027. dev_err(dev, "Could not allocate pipe_info\n");
  1028. goto usbhs_mod_host_probe_err;
  1029. }
  1030. /*
  1031. * CAUTION
  1032. *
  1033. * There is no guarantee that it is possible to access usb module here.
  1034. * Don't accesses to it.
  1035. * The accesse will be enable after "usbhsh_start"
  1036. */
  1037. hpriv = usbhsh_hcd_to_hpriv(hcd);
  1038. /*
  1039. * register itself
  1040. */
  1041. usbhs_mod_register(priv, &hpriv->mod, USBHS_HOST);
  1042. /* init hpriv */
  1043. hpriv->mod.name = "host";
  1044. hpriv->mod.start = usbhsh_start;
  1045. hpriv->mod.stop = usbhsh_stop;
  1046. hpriv->pipe_info = pipe_info;
  1047. hpriv->pipe_size = pipe_size;
  1048. usbhsh_req_list_init(hpriv);
  1049. usbhsh_port_stat_init(hpriv);
  1050. /* init all device */
  1051. usbhsh_for_each_udev_with_dev0(udev, hpriv, i) {
  1052. udev->usbv = NULL;
  1053. INIT_LIST_HEAD(&udev->ep_list_head);
  1054. }
  1055. dev_info(dev, "host probed\n");
  1056. return 0;
  1057. usbhs_mod_host_probe_err:
  1058. usb_put_hcd(hcd);
  1059. return -ENOMEM;
  1060. }
  1061. int __devexit usbhs_mod_host_remove(struct usbhs_priv *priv)
  1062. {
  1063. struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv);
  1064. struct usb_hcd *hcd = usbhsh_hpriv_to_hcd(hpriv);
  1065. usbhsh_req_list_quit(hpriv);
  1066. usb_put_hcd(hcd);
  1067. return 0;
  1068. }