ehci-fsl.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. (pdata->operating_mode == FSL_USB2_DR_OTG))) {
  63. dev_err(&pdev->dev,
  64. "Non Host Mode configured for %s. Wrong driver linked.\n",
  65. pdev->dev.bus_id);
  66. return -ENODEV;
  67. }
  68. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  69. if (!res) {
  70. dev_err(&pdev->dev,
  71. "Found HC with no IRQ. Check %s setup!\n",
  72. pdev->dev.bus_id);
  73. return -ENODEV;
  74. }
  75. irq = res->start;
  76. hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
  77. if (!hcd) {
  78. retval = -ENOMEM;
  79. goto err1;
  80. }
  81. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  82. if (!res) {
  83. dev_err(&pdev->dev,
  84. "Found HC with no register addr. Check %s setup!\n",
  85. pdev->dev.bus_id);
  86. retval = -ENODEV;
  87. goto err2;
  88. }
  89. hcd->rsrc_start = res->start;
  90. hcd->rsrc_len = res->end - res->start + 1;
  91. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  92. driver->description)) {
  93. dev_dbg(&pdev->dev, "controller already in use\n");
  94. retval = -EBUSY;
  95. goto err2;
  96. }
  97. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  98. if (hcd->regs == NULL) {
  99. dev_dbg(&pdev->dev, "error mapping memory\n");
  100. retval = -EFAULT;
  101. goto err3;
  102. }
  103. /* Enable USB controller */
  104. temp = in_be32(hcd->regs + 0x500);
  105. out_be32(hcd->regs + 0x500, temp | 0x4);
  106. /* Set to Host mode */
  107. temp = in_le32(hcd->regs + 0x1a8);
  108. out_le32(hcd->regs + 0x1a8, temp | 0x3);
  109. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  110. if (retval != 0)
  111. goto err4;
  112. return retval;
  113. err4:
  114. iounmap(hcd->regs);
  115. err3:
  116. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  117. err2:
  118. usb_put_hcd(hcd);
  119. err1:
  120. dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
  121. return retval;
  122. }
  123. /* may be called without controller electrically present */
  124. /* may be called with controller, bus, and devices active */
  125. /**
  126. * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
  127. * @dev: USB Host Controller being removed
  128. * Context: !in_interrupt()
  129. *
  130. * Reverses the effect of usb_hcd_fsl_probe().
  131. *
  132. */
  133. void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev)
  134. {
  135. usb_remove_hcd(hcd);
  136. iounmap(hcd->regs);
  137. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  138. usb_put_hcd(hcd);
  139. }
  140. static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
  141. enum fsl_usb2_phy_modes phy_mode,
  142. unsigned int port_offset)
  143. {
  144. u32 portsc = 0;
  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. ehci_writel(ehci, 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. u32 temp;
  169. pdata =
  170. (struct fsl_usb2_platform_data *)hcd->self.controller->
  171. platform_data;
  172. /* Enable PHY interface in the control reg. */
  173. temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
  174. out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004);
  175. out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
  176. #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
  177. /*
  178. * Turn on cache snooping hardware, since some PowerPC platforms
  179. * wholly rely on hardware to deal with cache coherent
  180. */
  181. /* Setup Snooping for all the 4GB space */
  182. /* SNOOP1 starts from 0x0, size 2G */
  183. out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
  184. /* SNOOP2 starts from 0x80000000, size 2G */
  185. out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
  186. #endif
  187. if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
  188. (pdata->operating_mode == FSL_USB2_DR_OTG))
  189. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  190. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  191. unsigned int chip, rev, svr;
  192. svr = mfspr(SPRN_SVR);
  193. chip = svr >> 16;
  194. rev = (svr >> 4) & 0xf;
  195. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  196. if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
  197. ehci->has_fsl_port_bug = 1;
  198. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  199. mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
  200. if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
  201. mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
  202. }
  203. /* put controller in host mode. */
  204. ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
  205. out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
  206. out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
  207. out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
  208. }
  209. /* called after powerup, by probe or system-pm "wakeup" */
  210. static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  211. {
  212. mpc83xx_usb_setup(ehci_to_hcd(ehci));
  213. ehci_port_power(ehci, 0);
  214. return 0;
  215. }
  216. /* called during probe() after chip reset completes */
  217. static int ehci_fsl_setup(struct usb_hcd *hcd)
  218. {
  219. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  220. int retval;
  221. /* EHCI registers start at offset 0x100 */
  222. ehci->caps = hcd->regs + 0x100;
  223. ehci->regs = hcd->regs + 0x100 +
  224. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  225. dbg_hcs_params(ehci, "reset");
  226. dbg_hcc_params(ehci, "reset");
  227. /* cache this readonly data; minimize chip reads */
  228. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  229. retval = ehci_halt(ehci);
  230. if (retval)
  231. return retval;
  232. /* data structure init */
  233. retval = ehci_init(hcd);
  234. if (retval)
  235. return retval;
  236. ehci->is_tdi_rh_tt = 1;
  237. ehci->sbrn = 0x20;
  238. ehci_reset(ehci);
  239. retval = ehci_fsl_reinit(ehci);
  240. return retval;
  241. }
  242. static const struct hc_driver ehci_fsl_hc_driver = {
  243. .description = hcd_name,
  244. .product_desc = "Freescale On-Chip EHCI Host Controller",
  245. .hcd_priv_size = sizeof(struct ehci_hcd),
  246. /*
  247. * generic hardware linkage
  248. */
  249. .irq = ehci_irq,
  250. .flags = HCD_USB2,
  251. /*
  252. * basic lifecycle operations
  253. */
  254. .reset = ehci_fsl_setup,
  255. .start = ehci_run,
  256. #ifdef CONFIG_PM
  257. .suspend = ehci_bus_suspend,
  258. .resume = ehci_bus_resume,
  259. #endif
  260. .stop = ehci_stop,
  261. .shutdown = ehci_shutdown,
  262. /*
  263. * managing i/o requests and associated device resources
  264. */
  265. .urb_enqueue = ehci_urb_enqueue,
  266. .urb_dequeue = ehci_urb_dequeue,
  267. .endpoint_disable = ehci_endpoint_disable,
  268. /*
  269. * scheduling support
  270. */
  271. .get_frame_number = ehci_get_frame,
  272. /*
  273. * root hub support
  274. */
  275. .hub_status_data = ehci_hub_status_data,
  276. .hub_control = ehci_hub_control,
  277. .bus_suspend = ehci_bus_suspend,
  278. .bus_resume = ehci_bus_resume,
  279. };
  280. static int ehci_fsl_drv_probe(struct platform_device *pdev)
  281. {
  282. if (usb_disabled())
  283. return -ENODEV;
  284. return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
  285. }
  286. static int ehci_fsl_drv_remove(struct platform_device *pdev)
  287. {
  288. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  289. usb_hcd_fsl_remove(hcd, pdev);
  290. return 0;
  291. }
  292. MODULE_ALIAS("fsl-ehci");
  293. static struct platform_driver ehci_fsl_driver = {
  294. .probe = ehci_fsl_drv_probe,
  295. .remove = ehci_fsl_drv_remove,
  296. .shutdown = usb_hcd_platform_shutdown,
  297. .driver = {
  298. .name = "fsl-ehci",
  299. },
  300. };