ohci-at91.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2004 SAN People (Pty) Ltd.
  5. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  6. *
  7. * AT91RM9200 Bus Glue
  8. *
  9. * Based on fragments of 2.4 driver by Rick Bronson.
  10. * Based on ohci-omap.c
  11. *
  12. * This file is licenced under the GPL.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/hardware.h>
  18. #include <asm/arch/board.h>
  19. #ifndef CONFIG_ARCH_AT91RM9200
  20. #error "CONFIG_ARCH_AT91RM9200 must be defined."
  21. #endif
  22. /* interface and function clocks */
  23. static struct clk *iclk, *fclk;
  24. extern int usb_disabled(void);
  25. /*-------------------------------------------------------------------------*/
  26. static void at91_start_hc(struct platform_device *pdev)
  27. {
  28. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  29. struct ohci_regs __iomem *regs = hcd->regs;
  30. dev_dbg(&pdev->dev, "starting AT91RM9200 OHCI USB Controller\n");
  31. /*
  32. * Start the USB clocks.
  33. */
  34. clk_enable(iclk);
  35. clk_enable(fclk);
  36. /*
  37. * The USB host controller must remain in reset.
  38. */
  39. writel(0, &regs->control);
  40. }
  41. static void at91_stop_hc(struct platform_device *pdev)
  42. {
  43. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  44. struct ohci_regs __iomem *regs = hcd->regs;
  45. dev_dbg(&pdev->dev, "stopping AT91RM9200 OHCI USB Controller\n");
  46. /*
  47. * Put the USB host controller into reset.
  48. */
  49. writel(0, &regs->control);
  50. /*
  51. * Stop the USB clocks.
  52. */
  53. clk_disable(fclk);
  54. clk_disable(iclk);
  55. }
  56. /*-------------------------------------------------------------------------*/
  57. static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
  58. /* configure so an HC device and id are always provided */
  59. /* always called with process context; sleeping is OK */
  60. /**
  61. * usb_hcd_at91_probe - initialize AT91RM9200-based HCDs
  62. * Context: !in_interrupt()
  63. *
  64. * Allocates basic resources for this USB host controller, and
  65. * then invokes the start() method for the HCD associated with it
  66. * through the hotplug entry's driver_data.
  67. */
  68. int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
  69. {
  70. int retval;
  71. struct usb_hcd *hcd = NULL;
  72. if (pdev->num_resources != 2) {
  73. pr_debug("hcd probe: invalid num_resources");
  74. return -ENODEV;
  75. }
  76. if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
  77. pr_debug("hcd probe: invalid resource type\n");
  78. return -ENODEV;
  79. }
  80. hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200");
  81. if (!hcd)
  82. return -ENOMEM;
  83. hcd->rsrc_start = pdev->resource[0].start;
  84. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  85. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  86. pr_debug("request_mem_region failed\n");
  87. retval = -EBUSY;
  88. goto err1;
  89. }
  90. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  91. if (!hcd->regs) {
  92. pr_debug("ioremap failed\n");
  93. retval = -EIO;
  94. goto err2;
  95. }
  96. iclk = clk_get(&pdev->dev, "ohci_clk");
  97. fclk = clk_get(&pdev->dev, "uhpck");
  98. at91_start_hc(pdev);
  99. ohci_hcd_init(hcd_to_ohci(hcd));
  100. retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
  101. if (retval == 0)
  102. return retval;
  103. /* Error handling */
  104. at91_stop_hc(pdev);
  105. clk_put(fclk);
  106. clk_put(iclk);
  107. iounmap(hcd->regs);
  108. err2:
  109. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  110. err1:
  111. usb_put_hcd(hcd);
  112. return retval;
  113. }
  114. /* may be called with controller, bus, and devices active */
  115. /**
  116. * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs
  117. * @dev: USB Host Controller being removed
  118. * Context: !in_interrupt()
  119. *
  120. * Reverses the effect of usb_hcd_at91_probe(), first invoking
  121. * the HCD's stop() method. It is always called from a thread
  122. * context, normally "rmmod", "apmd", or something similar.
  123. *
  124. */
  125. static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  126. {
  127. usb_remove_hcd(hcd);
  128. at91_stop_hc(pdev);
  129. iounmap(hcd->regs);
  130. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  131. clk_put(fclk);
  132. clk_put(iclk);
  133. fclk = iclk = NULL;
  134. dev_set_drvdata(&pdev->dev, NULL);
  135. return 0;
  136. }
  137. /*-------------------------------------------------------------------------*/
  138. static int __devinit
  139. ohci_at91_start (struct usb_hcd *hcd)
  140. {
  141. // struct at91_ohci_data *board = hcd->self.controller->platform_data;
  142. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  143. int ret;
  144. if ((ret = ohci_init(ohci)) < 0)
  145. return ret;
  146. if ((ret = ohci_run(ohci)) < 0) {
  147. err("can't start %s", hcd->self.bus_name);
  148. ohci_stop(hcd);
  149. return ret;
  150. }
  151. // hcd->self.root_hub->maxchild = board->ports;
  152. return 0;
  153. }
  154. /*-------------------------------------------------------------------------*/
  155. static const struct hc_driver ohci_at91_hc_driver = {
  156. .description = hcd_name,
  157. .product_desc = "AT91RM9200 OHCI",
  158. .hcd_priv_size = sizeof(struct ohci_hcd),
  159. /*
  160. * generic hardware linkage
  161. */
  162. .irq = ohci_irq,
  163. .flags = HCD_USB11 | HCD_MEMORY,
  164. /*
  165. * basic lifecycle operations
  166. */
  167. .start = ohci_at91_start,
  168. .stop = ohci_stop,
  169. /*
  170. * managing i/o requests and associated device resources
  171. */
  172. .urb_enqueue = ohci_urb_enqueue,
  173. .urb_dequeue = ohci_urb_dequeue,
  174. .endpoint_disable = ohci_endpoint_disable,
  175. /*
  176. * scheduling support
  177. */
  178. .get_frame_number = ohci_get_frame,
  179. /*
  180. * root hub support
  181. */
  182. .hub_status_data = ohci_hub_status_data,
  183. .hub_control = ohci_hub_control,
  184. #ifdef CONFIG_PM
  185. .bus_suspend = ohci_bus_suspend,
  186. .bus_resume = ohci_bus_resume,
  187. #endif
  188. .start_port_reset = ohci_start_port_reset,
  189. };
  190. /*-------------------------------------------------------------------------*/
  191. static int ohci_hcd_at91_drv_probe(struct platform_device *dev)
  192. {
  193. return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev);
  194. }
  195. static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
  196. {
  197. return usb_hcd_at91_remove(platform_get_drvdata(dev), dev);
  198. }
  199. #ifdef CONFIG_PM
  200. /* REVISIT suspend/resume look "too" simple here */
  201. static int
  202. ohci_hcd_at91_drv_suspend(struct platform_device *dev, pm_message_t mesg)
  203. {
  204. clk_disable(fclk);
  205. clk_disable(iclk);
  206. return 0;
  207. }
  208. static int ohci_hcd_at91_drv_resume(struct platform_device *dev)
  209. {
  210. clk_enable(iclk);
  211. clk_enable(fclk);
  212. return 0;
  213. }
  214. #else
  215. #define ohci_hcd_at91_drv_suspend NULL
  216. #define ohci_hcd_at91_drv_resume NULL
  217. #endif
  218. MODULE_ALIAS("at91rm9200-ohci");
  219. static struct platform_driver ohci_hcd_at91_driver = {
  220. .probe = ohci_hcd_at91_drv_probe,
  221. .remove = ohci_hcd_at91_drv_remove,
  222. .suspend = ohci_hcd_at91_drv_suspend,
  223. .resume = ohci_hcd_at91_drv_resume,
  224. .driver = {
  225. .name = "at91rm9200-ohci",
  226. .owner = THIS_MODULE,
  227. },
  228. };
  229. static int __init ohci_hcd_at91_init (void)
  230. {
  231. if (usb_disabled())
  232. return -ENODEV;
  233. return platform_driver_register(&ohci_hcd_at91_driver);
  234. }
  235. static void __exit ohci_hcd_at91_cleanup (void)
  236. {
  237. platform_driver_unregister(&ohci_hcd_at91_driver);
  238. }
  239. module_init (ohci_hcd_at91_init);
  240. module_exit (ohci_hcd_at91_cleanup);