hcd.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * Wireless Host Controller (WHC) driver.
  3. *
  4. * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/uwb/umc.h>
  21. #include "../../wusbcore/wusbhc.h"
  22. #include "whcd.h"
  23. /*
  24. * One time initialization.
  25. *
  26. * Nothing to do here.
  27. */
  28. static int whc_reset(struct usb_hcd *usb_hcd)
  29. {
  30. return 0;
  31. }
  32. /*
  33. * Start the wireless host controller.
  34. *
  35. * Start device notification.
  36. *
  37. * Put hc into run state, set DNTS parameters.
  38. */
  39. static int whc_start(struct usb_hcd *usb_hcd)
  40. {
  41. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  42. struct whc *whc = wusbhc_to_whc(wusbhc);
  43. u8 bcid;
  44. int ret;
  45. mutex_lock(&wusbhc->mutex);
  46. le_writel(WUSBINTR_GEN_CMD_DONE
  47. | WUSBINTR_HOST_ERR
  48. | WUSBINTR_ASYNC_SCHED_SYNCED
  49. | WUSBINTR_DNTS_INT
  50. | WUSBINTR_ERR_INT
  51. | WUSBINTR_INT,
  52. whc->base + WUSBINTR);
  53. /* set cluster ID */
  54. bcid = wusb_cluster_id_get();
  55. ret = whc_set_cluster_id(whc, bcid);
  56. if (ret < 0)
  57. goto out;
  58. wusbhc->cluster_id = bcid;
  59. /* start HC */
  60. whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
  61. usb_hcd->uses_new_polling = 1;
  62. usb_hcd->poll_rh = 1;
  63. usb_hcd->state = HC_STATE_RUNNING;
  64. out:
  65. mutex_unlock(&wusbhc->mutex);
  66. return ret;
  67. }
  68. /*
  69. * Stop the wireless host controller.
  70. *
  71. * Stop device notification.
  72. *
  73. * Wait for pending transfer to stop? Put hc into stop state?
  74. */
  75. static void whc_stop(struct usb_hcd *usb_hcd)
  76. {
  77. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  78. struct whc *whc = wusbhc_to_whc(wusbhc);
  79. mutex_lock(&wusbhc->mutex);
  80. /* stop HC */
  81. le_writel(0, whc->base + WUSBINTR);
  82. whc_write_wusbcmd(whc, WUSBCMD_RUN, 0);
  83. whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS,
  84. WUSBSTS_HCHALTED, WUSBSTS_HCHALTED,
  85. 100, "HC to halt");
  86. wusb_cluster_id_put(wusbhc->cluster_id);
  87. mutex_unlock(&wusbhc->mutex);
  88. }
  89. static int whc_get_frame_number(struct usb_hcd *usb_hcd)
  90. {
  91. /* Frame numbers are not applicable to WUSB. */
  92. return -ENOSYS;
  93. }
  94. /*
  95. * Queue an URB to the ASL or PZL
  96. */
  97. static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
  98. gfp_t mem_flags)
  99. {
  100. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  101. struct whc *whc = wusbhc_to_whc(wusbhc);
  102. int ret;
  103. switch (usb_pipetype(urb->pipe)) {
  104. case PIPE_INTERRUPT:
  105. ret = pzl_urb_enqueue(whc, urb, mem_flags);
  106. break;
  107. case PIPE_ISOCHRONOUS:
  108. dev_err(&whc->umc->dev, "isochronous transfers unsupported\n");
  109. ret = -ENOTSUPP;
  110. break;
  111. case PIPE_CONTROL:
  112. case PIPE_BULK:
  113. default:
  114. ret = asl_urb_enqueue(whc, urb, mem_flags);
  115. break;
  116. };
  117. return ret;
  118. }
  119. /*
  120. * Remove a queued URB from the ASL or PZL.
  121. */
  122. static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status)
  123. {
  124. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  125. struct whc *whc = wusbhc_to_whc(wusbhc);
  126. int ret;
  127. switch (usb_pipetype(urb->pipe)) {
  128. case PIPE_INTERRUPT:
  129. ret = pzl_urb_dequeue(whc, urb, status);
  130. break;
  131. case PIPE_ISOCHRONOUS:
  132. ret = -ENOTSUPP;
  133. break;
  134. case PIPE_CONTROL:
  135. case PIPE_BULK:
  136. default:
  137. ret = asl_urb_dequeue(whc, urb, status);
  138. break;
  139. };
  140. return ret;
  141. }
  142. /*
  143. * Wait for all URBs to the endpoint to be completed, then delete the
  144. * qset.
  145. */
  146. static void whc_endpoint_disable(struct usb_hcd *usb_hcd,
  147. struct usb_host_endpoint *ep)
  148. {
  149. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  150. struct whc *whc = wusbhc_to_whc(wusbhc);
  151. struct whc_qset *qset;
  152. qset = ep->hcpriv;
  153. if (qset) {
  154. ep->hcpriv = NULL;
  155. if (usb_endpoint_xfer_bulk(&ep->desc)
  156. || usb_endpoint_xfer_control(&ep->desc))
  157. asl_qset_delete(whc, qset);
  158. else
  159. pzl_qset_delete(whc, qset);
  160. }
  161. }
  162. static struct hc_driver whc_hc_driver = {
  163. .description = "whci-hcd",
  164. .product_desc = "Wireless host controller",
  165. .hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd),
  166. .irq = whc_int_handler,
  167. .flags = HCD_USB2,
  168. .reset = whc_reset,
  169. .start = whc_start,
  170. .stop = whc_stop,
  171. .get_frame_number = whc_get_frame_number,
  172. .urb_enqueue = whc_urb_enqueue,
  173. .urb_dequeue = whc_urb_dequeue,
  174. .endpoint_disable = whc_endpoint_disable,
  175. .hub_status_data = wusbhc_rh_status_data,
  176. .hub_control = wusbhc_rh_control,
  177. .bus_suspend = wusbhc_rh_suspend,
  178. .bus_resume = wusbhc_rh_resume,
  179. .start_port_reset = wusbhc_rh_start_port_reset,
  180. };
  181. static int whc_probe(struct umc_dev *umc)
  182. {
  183. int ret = -ENOMEM;
  184. struct usb_hcd *usb_hcd;
  185. struct wusbhc *wusbhc = NULL;
  186. struct whc *whc = NULL;
  187. struct device *dev = &umc->dev;
  188. usb_hcd = usb_create_hcd(&whc_hc_driver, dev, "whci");
  189. if (usb_hcd == NULL) {
  190. dev_err(dev, "unable to create hcd\n");
  191. goto error;
  192. }
  193. usb_hcd->wireless = 1;
  194. wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  195. whc = wusbhc_to_whc(wusbhc);
  196. whc->umc = umc;
  197. ret = whc_init(whc);
  198. if (ret)
  199. goto error;
  200. wusbhc->dev = dev;
  201. wusbhc->uwb_rc = uwb_rc_get_by_grandpa(umc->dev.parent);
  202. if (!wusbhc->uwb_rc) {
  203. ret = -ENODEV;
  204. dev_err(dev, "cannot get radio controller\n");
  205. goto error;
  206. }
  207. if (whc->n_devices > USB_MAXCHILDREN) {
  208. dev_warn(dev, "USB_MAXCHILDREN too low for WUSB adapter (%u ports)\n",
  209. whc->n_devices);
  210. wusbhc->ports_max = USB_MAXCHILDREN;
  211. } else
  212. wusbhc->ports_max = whc->n_devices;
  213. wusbhc->mmcies_max = whc->n_mmc_ies;
  214. wusbhc->start = whc_wusbhc_start;
  215. wusbhc->stop = whc_wusbhc_stop;
  216. wusbhc->mmcie_add = whc_mmcie_add;
  217. wusbhc->mmcie_rm = whc_mmcie_rm;
  218. wusbhc->dev_info_set = whc_dev_info_set;
  219. wusbhc->bwa_set = whc_bwa_set;
  220. wusbhc->set_num_dnts = whc_set_num_dnts;
  221. wusbhc->set_ptk = whc_set_ptk;
  222. wusbhc->set_gtk = whc_set_gtk;
  223. ret = wusbhc_create(wusbhc);
  224. if (ret)
  225. goto error_wusbhc_create;
  226. ret = usb_add_hcd(usb_hcd, whc->umc->irq, IRQF_SHARED);
  227. if (ret) {
  228. dev_err(dev, "cannot add HCD: %d\n", ret);
  229. goto error_usb_add_hcd;
  230. }
  231. ret = wusbhc_b_create(wusbhc);
  232. if (ret) {
  233. dev_err(dev, "WUSBHC phase B setup failed: %d\n", ret);
  234. goto error_wusbhc_b_create;
  235. }
  236. whc_dbg_init(whc);
  237. return 0;
  238. error_wusbhc_b_create:
  239. usb_remove_hcd(usb_hcd);
  240. error_usb_add_hcd:
  241. wusbhc_destroy(wusbhc);
  242. error_wusbhc_create:
  243. uwb_rc_put(wusbhc->uwb_rc);
  244. error:
  245. whc_clean_up(whc);
  246. if (usb_hcd)
  247. usb_put_hcd(usb_hcd);
  248. return ret;
  249. }
  250. static void whc_remove(struct umc_dev *umc)
  251. {
  252. struct usb_hcd *usb_hcd = dev_get_drvdata(&umc->dev);
  253. struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
  254. struct whc *whc = wusbhc_to_whc(wusbhc);
  255. if (usb_hcd) {
  256. whc_dbg_clean_up(whc);
  257. wusbhc_b_destroy(wusbhc);
  258. usb_remove_hcd(usb_hcd);
  259. wusbhc_destroy(wusbhc);
  260. uwb_rc_put(wusbhc->uwb_rc);
  261. whc_clean_up(whc);
  262. usb_put_hcd(usb_hcd);
  263. }
  264. }
  265. static struct umc_driver whci_hc_driver = {
  266. .name = "whci-hcd",
  267. .cap_id = UMC_CAP_ID_WHCI_WUSB_HC,
  268. .probe = whc_probe,
  269. .remove = whc_remove,
  270. };
  271. static int __init whci_hc_driver_init(void)
  272. {
  273. return umc_driver_register(&whci_hc_driver);
  274. }
  275. module_init(whci_hc_driver_init);
  276. static void __exit whci_hc_driver_exit(void)
  277. {
  278. umc_driver_unregister(&whci_hc_driver);
  279. }
  280. module_exit(whci_hc_driver_exit);
  281. /* PCI device ID's that we handle (so it gets loaded) */
  282. static struct pci_device_id whci_hcd_id_table[] = {
  283. { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) },
  284. { /* empty last entry */ }
  285. };
  286. MODULE_DEVICE_TABLE(pci, whci_hcd_id_table);
  287. MODULE_DESCRIPTION("WHCI Wireless USB host controller driver");
  288. MODULE_AUTHOR("Cambridge Silicon Radio Ltd.");
  289. MODULE_LICENSE("GPL");