ehci-fsl.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * (C) Copyright David Brownell 2000-2002
  3. * Copyright (c) 2005 MontaVista Software
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided
  20. * by Hunter Wu.
  21. */
  22. #include <linux/platform_device.h>
  23. #include <linux/fsl_devices.h>
  24. #include "ehci-fsl.h"
  25. /* FIXME: Power Managment is un-ported so temporarily disable it */
  26. #undef CONFIG_PM
  27. /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
  28. /* configure so an HC device and id are always provided */
  29. /* always called with process context; sleeping is OK */
  30. /**
  31. * usb_hcd_fsl_probe - initialize FSL-based HCDs
  32. * @drvier: Driver to be used for this HCD
  33. * @pdev: USB Host Controller being probed
  34. * Context: !in_interrupt()
  35. *
  36. * Allocates basic resources for this USB host controller.
  37. *
  38. */
  39. int usb_hcd_fsl_probe(const struct hc_driver *driver,
  40. struct platform_device *pdev)
  41. {
  42. struct fsl_usb2_platform_data *pdata;
  43. struct usb_hcd *hcd;
  44. struct resource *res;
  45. int irq;
  46. int retval;
  47. unsigned int temp;
  48. pr_debug("initializing FSL-SOC USB Controller\n");
  49. /* Need platform data for setup */
  50. pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
  51. if (!pdata) {
  52. dev_err(&pdev->dev,
  53. "No platform data for %s.\n", pdev->dev.bus_id);
  54. return -ENODEV;
  55. }
  56. /*
  57. * This is a host mode driver, verify that we're supposed to be
  58. * in host mode.
  59. */
  60. if (!((pdata->operating_mode == FSL_USB2_DR_HOST) ||
  61. (pdata->operating_mode == FSL_USB2_MPH_HOST))) {
  62. dev_err(&pdev->dev,
  63. "Non Host Mode configured for %s. Wrong driver linked.\n",
  64. pdev->dev.bus_id);
  65. return -ENODEV;
  66. }
  67. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  68. if (!res) {
  69. dev_err(&pdev->dev,
  70. "Found HC with no IRQ. Check %s setup!\n",
  71. pdev->dev.bus_id);
  72. return -ENODEV;
  73. }
  74. irq = res->start;
  75. hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
  76. if (!hcd) {
  77. retval = -ENOMEM;
  78. goto err1;
  79. }
  80. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  81. if (!res) {
  82. dev_err(&pdev->dev,
  83. "Found HC with no register addr. Check %s setup!\n",
  84. pdev->dev.bus_id);
  85. retval = -ENODEV;
  86. goto err2;
  87. }
  88. hcd->rsrc_start = res->start;
  89. hcd->rsrc_len = res->end - res->start + 1;
  90. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  91. driver->description)) {
  92. dev_dbg(&pdev->dev, "controller already in use\n");
  93. retval = -EBUSY;
  94. goto err2;
  95. }
  96. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  97. if (hcd->regs == NULL) {
  98. dev_dbg(&pdev->dev, "error mapping memory\n");
  99. retval = -EFAULT;
  100. goto err3;
  101. }
  102. /* Enable USB controller */
  103. temp = in_be32(hcd->regs + 0x500);
  104. out_be32(hcd->regs + 0x500, temp | 0x4);
  105. /* Set to Host mode */
  106. temp = in_le32(hcd->regs + 0x1a8);
  107. out_le32(hcd->regs + 0x1a8, temp | 0x3);
  108. retval = usb_add_hcd(hcd, irq, SA_SHIRQ);
  109. if (retval != 0)
  110. goto err4;
  111. return retval;
  112. err4:
  113. iounmap(hcd->regs);
  114. err3:
  115. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  116. err2:
  117. usb_put_hcd(hcd);
  118. err1:
  119. dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
  120. return retval;
  121. }
  122. /* may be called without controller electrically present */
  123. /* may be called with controller, bus, and devices active */
  124. /**
  125. * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
  126. * @dev: USB Host Controller being removed
  127. * Context: !in_interrupt()
  128. *
  129. * Reverses the effect of usb_hcd_fsl_probe().
  130. *
  131. */
  132. void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  133. {
  134. usb_remove_hcd(hcd);
  135. iounmap(hcd->regs);
  136. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  137. usb_put_hcd(hcd);
  138. }
  139. static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
  140. enum fsl_usb2_phy_modes phy_mode,
  141. unsigned int port_offset)
  142. {
  143. u32 portsc = 0;
  144. switch (phy_mode) {
  145. case FSL_USB2_PHY_ULPI:
  146. portsc |= PORT_PTS_ULPI;
  147. break;
  148. case FSL_USB2_PHY_SERIAL:
  149. portsc |= PORT_PTS_SERIAL;
  150. break;
  151. case FSL_USB2_PHY_UTMI_WIDE:
  152. portsc |= PORT_PTS_PTW;
  153. /* fall through */
  154. case FSL_USB2_PHY_UTMI:
  155. portsc |= PORT_PTS_UTMI;
  156. break;
  157. case FSL_USB2_PHY_NONE:
  158. break;
  159. }
  160. writel(portsc, &ehci->regs->port_status[port_offset]);
  161. }
  162. static void mpc83xx_usb_setup(struct usb_hcd *hcd)
  163. {
  164. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  165. struct fsl_usb2_platform_data *pdata;
  166. void __iomem *non_ehci = hcd->regs;
  167. pdata =
  168. (struct fsl_usb2_platform_data *)hcd->self.controller->
  169. platform_data;
  170. /* Enable PHY interface in the control reg. */
  171. out_be32(non_ehci + FSL_SOC_USB_CTRL, 0x00000004);
  172. out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
  173. if (pdata->operating_mode == FSL_USB2_DR_HOST)
  174. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  175. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  176. unsigned int chip, rev, svr;
  177. svr = mfspr(SPRN_SVR);
  178. chip = svr >> 16;
  179. rev = (svr >> 4) & 0xf;
  180. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  181. if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
  182. ehci->has_fsl_port_bug = 1;
  183. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  184. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  185. if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
  186. mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
  187. }
  188. /* put controller in host mode. */
  189. writel(0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
  190. out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
  191. out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
  192. out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
  193. }
  194. /* called after powerup, by probe or system-pm "wakeup" */
  195. static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  196. {
  197. mpc83xx_usb_setup(ehci_to_hcd(ehci));
  198. ehci_port_power(ehci, 0);
  199. return 0;
  200. }
  201. /* called during probe() after chip reset completes */
  202. static int ehci_fsl_setup(struct usb_hcd *hcd)
  203. {
  204. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  205. int retval;
  206. /* EHCI registers start at offset 0x100 */
  207. ehci->caps = hcd->regs + 0x100;
  208. ehci->regs = hcd->regs + 0x100 +
  209. HC_LENGTH(readl(&ehci->caps->hc_capbase));
  210. dbg_hcs_params(ehci, "reset");
  211. dbg_hcc_params(ehci, "reset");
  212. /* cache this readonly data; minimize chip reads */
  213. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  214. retval = ehci_halt(ehci);
  215. if (retval)
  216. return retval;
  217. /* data structure init */
  218. retval = ehci_init(hcd);
  219. if (retval)
  220. return retval;
  221. ehci->is_tdi_rh_tt = 1;
  222. ehci->sbrn = 0x20;
  223. ehci_reset(ehci);
  224. retval = ehci_fsl_reinit(ehci);
  225. return retval;
  226. }
  227. static const struct hc_driver ehci_fsl_hc_driver = {
  228. .description = hcd_name,
  229. .product_desc = "Freescale On-Chip EHCI Host Controller",
  230. .hcd_priv_size = sizeof(struct ehci_hcd),
  231. /*
  232. * generic hardware linkage
  233. */
  234. .irq = ehci_irq,
  235. .flags = HCD_USB2,
  236. /*
  237. * basic lifecycle operations
  238. */
  239. .reset = ehci_fsl_setup,
  240. .start = ehci_run,
  241. #ifdef CONFIG_PM
  242. .suspend = ehci_bus_suspend,
  243. .resume = ehci_bus_resume,
  244. #endif
  245. .stop = ehci_stop,
  246. /*
  247. * managing i/o requests and associated device resources
  248. */
  249. .urb_enqueue = ehci_urb_enqueue,
  250. .urb_dequeue = ehci_urb_dequeue,
  251. .endpoint_disable = ehci_endpoint_disable,
  252. /*
  253. * scheduling support
  254. */
  255. .get_frame_number = ehci_get_frame,
  256. /*
  257. * root hub support
  258. */
  259. .hub_status_data = ehci_hub_status_data,
  260. .hub_control = ehci_hub_control,
  261. .bus_suspend = ehci_bus_suspend,
  262. .bus_resume = ehci_bus_resume,
  263. };
  264. static int ehci_fsl_drv_probe(struct platform_device *pdev)
  265. {
  266. if (usb_disabled())
  267. return -ENODEV;
  268. return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
  269. }
  270. static int ehci_fsl_drv_remove(struct platform_device *pdev)
  271. {
  272. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  273. usb_hcd_fsl_remove(hcd, pdev);
  274. return 0;
  275. }
  276. static struct platform_driver ehci_fsl_dr_driver = {
  277. .probe = ehci_fsl_drv_probe,
  278. .remove = ehci_fsl_drv_remove,
  279. .driver = {
  280. .name = "fsl-usb2-dr",
  281. },
  282. };
  283. static struct platform_driver ehci_fsl_mph_driver = {
  284. .probe = ehci_fsl_drv_probe,
  285. .remove = ehci_fsl_drv_remove,
  286. .driver = {
  287. .name = "fsl-usb2-mph",
  288. },
  289. };
  290. static int __init ehci_fsl_init(void)
  291. {
  292. int retval;
  293. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  294. hcd_name,
  295. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  296. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  297. retval = platform_driver_register(&ehci_fsl_dr_driver);
  298. if (retval)
  299. return retval;
  300. return platform_driver_register(&ehci_fsl_mph_driver);
  301. }
  302. static void __exit ehci_fsl_cleanup(void)
  303. {
  304. platform_driver_unregister(&ehci_fsl_mph_driver);
  305. platform_driver_unregister(&ehci_fsl_dr_driver);
  306. }
  307. module_init(ehci_fsl_init);
  308. module_exit(ehci_fsl_cleanup);