ehci-fsl.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 = readl(&ehci->regs->port_status[port_offset]);
  144. portsc &= ~PORT_PTS_MSK;
  145. switch (phy_mode) {
  146. case FSL_USB2_PHY_ULPI:
  147. portsc |= PORT_PTS_ULPI;
  148. break;
  149. case FSL_USB2_PHY_SERIAL:
  150. portsc |= PORT_PTS_SERIAL;
  151. break;
  152. case FSL_USB2_PHY_UTMI_WIDE:
  153. portsc |= PORT_PTS_PTW;
  154. /* fall through */
  155. case FSL_USB2_PHY_UTMI:
  156. portsc |= PORT_PTS_UTMI;
  157. break;
  158. case FSL_USB2_PHY_NONE:
  159. break;
  160. }
  161. writel(portsc, &ehci->regs->port_status[port_offset]);
  162. }
  163. static void mpc83xx_usb_setup(struct usb_hcd *hcd)
  164. {
  165. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  166. struct fsl_usb2_platform_data *pdata;
  167. void __iomem *non_ehci = hcd->regs;
  168. pdata =
  169. (struct fsl_usb2_platform_data *)hcd->self.controller->
  170. platform_data;
  171. /* Enable PHY interface in the control reg. */
  172. out_be32(non_ehci + FSL_SOC_USB_CTRL, 0x00000004);
  173. out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
  174. if (pdata->operating_mode == FSL_USB2_DR_HOST)
  175. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  176. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  177. unsigned int chip, rev, svr;
  178. svr = mfspr(SPRN_SVR);
  179. chip = svr >> 16;
  180. rev = (svr >> 4) & 0xf;
  181. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  182. if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
  183. ehci->has_fsl_port_bug = 1;
  184. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  185. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  186. if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
  187. mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
  188. }
  189. /* put controller in host mode. */
  190. writel(0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
  191. out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
  192. out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
  193. out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
  194. }
  195. /* called after powerup, by probe or system-pm "wakeup" */
  196. static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  197. {
  198. mpc83xx_usb_setup(ehci_to_hcd(ehci));
  199. ehci_port_power(ehci, 0);
  200. return 0;
  201. }
  202. /* called during probe() after chip reset completes */
  203. static int ehci_fsl_setup(struct usb_hcd *hcd)
  204. {
  205. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  206. int retval;
  207. /* EHCI registers start at offset 0x100 */
  208. ehci->caps = hcd->regs + 0x100;
  209. ehci->regs = hcd->regs + 0x100 +
  210. HC_LENGTH(readl(&ehci->caps->hc_capbase));
  211. dbg_hcs_params(ehci, "reset");
  212. dbg_hcc_params(ehci, "reset");
  213. /* cache this readonly data; minimize chip reads */
  214. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  215. retval = ehci_halt(ehci);
  216. if (retval)
  217. return retval;
  218. /* data structure init */
  219. retval = ehci_init(hcd);
  220. if (retval)
  221. return retval;
  222. ehci->is_tdi_rh_tt = 1;
  223. ehci->sbrn = 0x20;
  224. ehci_reset(ehci);
  225. retval = ehci_fsl_reinit(ehci);
  226. return retval;
  227. }
  228. static const struct hc_driver ehci_fsl_hc_driver = {
  229. .description = hcd_name,
  230. .product_desc = "Freescale On-Chip EHCI Host Controller",
  231. .hcd_priv_size = sizeof(struct ehci_hcd),
  232. /*
  233. * generic hardware linkage
  234. */
  235. .irq = ehci_irq,
  236. .flags = HCD_USB2,
  237. /*
  238. * basic lifecycle operations
  239. */
  240. .reset = ehci_fsl_setup,
  241. .start = ehci_run,
  242. #ifdef CONFIG_PM
  243. .suspend = ehci_bus_suspend,
  244. .resume = ehci_bus_resume,
  245. #endif
  246. .stop = ehci_stop,
  247. /*
  248. * managing i/o requests and associated device resources
  249. */
  250. .urb_enqueue = ehci_urb_enqueue,
  251. .urb_dequeue = ehci_urb_dequeue,
  252. .endpoint_disable = ehci_endpoint_disable,
  253. /*
  254. * scheduling support
  255. */
  256. .get_frame_number = ehci_get_frame,
  257. /*
  258. * root hub support
  259. */
  260. .hub_status_data = ehci_hub_status_data,
  261. .hub_control = ehci_hub_control,
  262. .bus_suspend = ehci_bus_suspend,
  263. .bus_resume = ehci_bus_resume,
  264. };
  265. static int ehci_fsl_drv_probe(struct platform_device *pdev)
  266. {
  267. if (usb_disabled())
  268. return -ENODEV;
  269. return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
  270. }
  271. static int ehci_fsl_drv_remove(struct platform_device *pdev)
  272. {
  273. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  274. usb_hcd_fsl_remove(hcd, pdev);
  275. return 0;
  276. }
  277. static struct platform_driver ehci_fsl_dr_driver = {
  278. .probe = ehci_fsl_drv_probe,
  279. .remove = ehci_fsl_drv_remove,
  280. .driver = {
  281. .name = "fsl-usb2-dr",
  282. },
  283. };
  284. static struct platform_driver ehci_fsl_mph_driver = {
  285. .probe = ehci_fsl_drv_probe,
  286. .remove = ehci_fsl_drv_remove,
  287. .driver = {
  288. .name = "fsl-usb2-mph",
  289. },
  290. };
  291. static int __init ehci_fsl_init(void)
  292. {
  293. int retval;
  294. pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
  295. hcd_name,
  296. sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
  297. sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
  298. retval = platform_driver_register(&ehci_fsl_dr_driver);
  299. if (retval)
  300. return retval;
  301. return platform_driver_register(&ehci_fsl_mph_driver);
  302. }
  303. static void __exit ehci_fsl_cleanup(void)
  304. {
  305. platform_driver_unregister(&ehci_fsl_mph_driver);
  306. platform_driver_unregister(&ehci_fsl_dr_driver);
  307. }
  308. module_init(ehci_fsl_init);
  309. module_exit(ehci_fsl_cleanup);