ohci-at91.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 "This file is AT91RM9200 bus glue. 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. * Store this function in the HCD's struct pci_driver as probe().
  69. */
  70. int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
  71. {
  72. int retval;
  73. struct usb_hcd *hcd = NULL;
  74. if (pdev->num_resources != 2) {
  75. pr_debug("hcd probe: invalid num_resources");
  76. return -ENODEV;
  77. }
  78. if ((pdev->resource[0].flags != IORESOURCE_MEM) || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
  79. pr_debug("hcd probe: invalid resource type\n");
  80. return -ENODEV;
  81. }
  82. hcd = usb_create_hcd(driver, &pdev->dev, "at91rm9200");
  83. if (!hcd)
  84. return -ENOMEM;
  85. hcd->rsrc_start = pdev->resource[0].start;
  86. hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
  87. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  88. pr_debug("request_mem_region failed\n");
  89. retval = -EBUSY;
  90. goto err1;
  91. }
  92. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  93. if (!hcd->regs) {
  94. pr_debug("ioremap failed\n");
  95. retval = -EIO;
  96. goto err2;
  97. }
  98. iclk = clk_get(&pdev->dev, "ohci_clk");
  99. fclk = clk_get(&pdev->dev, "uhpck");
  100. at91_start_hc(pdev);
  101. ohci_hcd_init(hcd_to_ohci(hcd));
  102. retval = usb_add_hcd(hcd, pdev->resource[1].start, SA_INTERRUPT);
  103. if (retval == 0)
  104. return retval;
  105. /* Error handling */
  106. at91_stop_hc(pdev);
  107. clk_put(fclk);
  108. clk_put(iclk);
  109. iounmap(hcd->regs);
  110. err2:
  111. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  112. err1:
  113. usb_put_hcd(hcd);
  114. return retval;
  115. }
  116. /* may be called without controller electrically present */
  117. /* may be called with controller, bus, and devices active */
  118. /**
  119. * usb_hcd_at91_remove - shutdown processing for AT91RM9200-based HCDs
  120. * @dev: USB Host Controller being removed
  121. * Context: !in_interrupt()
  122. *
  123. * Reverses the effect of usb_hcd_at91_probe(), first invoking
  124. * the HCD's stop() method. It is always called from a thread
  125. * context, normally "rmmod", "apmd", or something similar.
  126. *
  127. */
  128. static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  129. {
  130. usb_remove_hcd(hcd);
  131. at91_stop_hc(pdev);
  132. iounmap(hcd->regs);
  133. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  134. clk_put(fclk);
  135. clk_put(iclk);
  136. fclk = iclk = NULL;
  137. dev_set_drvdata(&pdev->dev, NULL);
  138. return 0;
  139. }
  140. /*-------------------------------------------------------------------------*/
  141. static int __devinit
  142. ohci_at91_start (struct usb_hcd *hcd)
  143. {
  144. // struct at91_ohci_data *board = hcd->self.controller->platform_data;
  145. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  146. int ret;
  147. if ((ret = ohci_init(ohci)) < 0)
  148. return ret;
  149. if ((ret = ohci_run(ohci)) < 0) {
  150. err("can't start %s", hcd->self.bus_name);
  151. ohci_stop(hcd);
  152. return ret;
  153. }
  154. // hcd->self.root_hub->maxchild = board->ports;
  155. return 0;
  156. }
  157. /*-------------------------------------------------------------------------*/
  158. static const struct hc_driver ohci_at91_hc_driver = {
  159. .description = hcd_name,
  160. .product_desc = "AT91RM9200 OHCI",
  161. .hcd_priv_size = sizeof(struct ohci_hcd),
  162. /*
  163. * generic hardware linkage
  164. */
  165. .irq = ohci_irq,
  166. .flags = HCD_USB11 | HCD_MEMORY,
  167. /*
  168. * basic lifecycle operations
  169. */
  170. .start = ohci_at91_start,
  171. .stop = ohci_stop,
  172. /*
  173. * managing i/o requests and associated device resources
  174. */
  175. .urb_enqueue = ohci_urb_enqueue,
  176. .urb_dequeue = ohci_urb_dequeue,
  177. .endpoint_disable = ohci_endpoint_disable,
  178. /*
  179. * scheduling support
  180. */
  181. .get_frame_number = ohci_get_frame,
  182. /*
  183. * root hub support
  184. */
  185. .hub_status_data = ohci_hub_status_data,
  186. .hub_control = ohci_hub_control,
  187. #ifdef CONFIG_PM
  188. .hub_suspend = ohci_hub_suspend,
  189. .hub_resume = ohci_hub_resume,
  190. #endif
  191. .start_port_reset = ohci_start_port_reset,
  192. };
  193. /*-------------------------------------------------------------------------*/
  194. static int ohci_hcd_at91_drv_probe(struct platform_device *dev)
  195. {
  196. return usb_hcd_at91_probe(&ohci_at91_hc_driver, dev);
  197. }
  198. static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
  199. {
  200. return usb_hcd_at91_remove(platform_get_drvdata(dev), dev);
  201. }
  202. #ifdef CONFIG_PM
  203. static int ohci_hcd_at91_drv_suspend(struct platform_device *dev, u32 state, u32 level)
  204. {
  205. printk("%s(%s:%d): not implemented yet\n",
  206. __func__, __FILE__, __LINE__);
  207. clk_disable(fclk);
  208. return 0;
  209. }
  210. static int ohci_hcd_at91_drv_resume(struct platform_device *dev, u32 state)
  211. {
  212. printk("%s(%s:%d): not implemented yet\n",
  213. __func__, __FILE__, __LINE__);
  214. clk_enable(fclk);
  215. return 0;
  216. }
  217. #else
  218. #define ohci_hcd_at91_drv_suspend NULL
  219. #define ohci_hcd_at91_drv_resume NULL
  220. #endif
  221. static struct platform_driver ohci_hcd_at91_driver = {
  222. .probe = ohci_hcd_at91_drv_probe,
  223. .remove = ohci_hcd_at91_drv_remove,
  224. .suspend = ohci_hcd_at91_drv_suspend,
  225. .resume = ohci_hcd_at91_drv_resume,
  226. .driver = {
  227. .name = "at91rm9200-ohci",
  228. .owner = THIS_MODULE,
  229. },
  230. };
  231. static int __init ohci_hcd_at91_init (void)
  232. {
  233. if (usb_disabled())
  234. return -ENODEV;
  235. return platform_driver_register(&ohci_hcd_at91_driver);
  236. }
  237. static void __exit ohci_hcd_at91_cleanup (void)
  238. {
  239. platform_driver_unregister(&ohci_hcd_at91_driver);
  240. }
  241. module_init (ohci_hcd_at91_init);
  242. module_exit (ohci_hcd_at91_cleanup);