ehci-fsl.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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, IRQF_SHARED);
  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. ehci_writel(ehci, 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 defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
  174. /*
  175. * Turn on cache snooping hardware, since some PowerPC platforms
  176. * wholly rely on hardware to deal with cache coherent
  177. */
  178. /* Setup Snooping for all the 4GB space */
  179. /* SNOOP1 starts from 0x0, size 2G */
  180. out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
  181. /* SNOOP2 starts from 0x80000000, size 2G */
  182. out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
  183. #endif
  184. if (pdata->operating_mode == FSL_USB2_DR_HOST)
  185. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  186. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  187. unsigned int chip, rev, svr;
  188. svr = mfspr(SPRN_SVR);
  189. chip = svr >> 16;
  190. rev = (svr >> 4) & 0xf;
  191. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  192. if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
  193. ehci->has_fsl_port_bug = 1;
  194. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  195. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  196. if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
  197. mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
  198. }
  199. /* put controller in host mode. */
  200. ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
  201. out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
  202. out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
  203. out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
  204. }
  205. /* called after powerup, by probe or system-pm "wakeup" */
  206. static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  207. {
  208. mpc83xx_usb_setup(ehci_to_hcd(ehci));
  209. ehci_port_power(ehci, 0);
  210. return 0;
  211. }
  212. /* called during probe() after chip reset completes */
  213. static int ehci_fsl_setup(struct usb_hcd *hcd)
  214. {
  215. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  216. int retval;
  217. /* EHCI registers start at offset 0x100 */
  218. ehci->caps = hcd->regs + 0x100;
  219. ehci->regs = hcd->regs + 0x100 +
  220. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  221. dbg_hcs_params(ehci, "reset");
  222. dbg_hcc_params(ehci, "reset");
  223. /* cache this readonly data; minimize chip reads */
  224. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  225. retval = ehci_halt(ehci);
  226. if (retval)
  227. return retval;
  228. /* data structure init */
  229. retval = ehci_init(hcd);
  230. if (retval)
  231. return retval;
  232. ehci->is_tdi_rh_tt = 1;
  233. ehci->sbrn = 0x20;
  234. ehci_reset(ehci);
  235. retval = ehci_fsl_reinit(ehci);
  236. return retval;
  237. }
  238. static const struct hc_driver ehci_fsl_hc_driver = {
  239. .description = hcd_name,
  240. .product_desc = "Freescale On-Chip EHCI Host Controller",
  241. .hcd_priv_size = sizeof(struct ehci_hcd),
  242. /*
  243. * generic hardware linkage
  244. */
  245. .irq = ehci_irq,
  246. .flags = HCD_USB2,
  247. /*
  248. * basic lifecycle operations
  249. */
  250. .reset = ehci_fsl_setup,
  251. .start = ehci_run,
  252. #ifdef CONFIG_PM
  253. .suspend = ehci_bus_suspend,
  254. .resume = ehci_bus_resume,
  255. #endif
  256. .stop = ehci_stop,
  257. .shutdown = ehci_shutdown,
  258. /*
  259. * managing i/o requests and associated device resources
  260. */
  261. .urb_enqueue = ehci_urb_enqueue,
  262. .urb_dequeue = ehci_urb_dequeue,
  263. .endpoint_disable = ehci_endpoint_disable,
  264. /*
  265. * scheduling support
  266. */
  267. .get_frame_number = ehci_get_frame,
  268. /*
  269. * root hub support
  270. */
  271. .hub_status_data = ehci_hub_status_data,
  272. .hub_control = ehci_hub_control,
  273. .bus_suspend = ehci_bus_suspend,
  274. .bus_resume = ehci_bus_resume,
  275. };
  276. static int ehci_fsl_drv_probe(struct platform_device *pdev)
  277. {
  278. if (usb_disabled())
  279. return -ENODEV;
  280. return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
  281. }
  282. static int ehci_fsl_drv_remove(struct platform_device *pdev)
  283. {
  284. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  285. usb_hcd_fsl_remove(hcd, pdev);
  286. return 0;
  287. }
  288. MODULE_ALIAS("fsl-ehci");
  289. static struct platform_driver ehci_fsl_driver = {
  290. .probe = ehci_fsl_drv_probe,
  291. .remove = ehci_fsl_drv_remove,
  292. .shutdown = usb_hcd_platform_shutdown,
  293. .driver = {
  294. .name = "fsl-ehci",
  295. },
  296. };