ehci-fsl.c 9.1 KB

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