ohci-lh7a404.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for Sharp LH7A404
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Rusell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. *
  16. * This file is licenced under the GPL.
  17. */
  18. #include <linux/platform_device.h>
  19. #include <asm/hardware.h>
  20. extern int usb_disabled(void);
  21. /*-------------------------------------------------------------------------*/
  22. static void lh7a404_start_hc(struct platform_device *dev)
  23. {
  24. printk(KERN_DEBUG __FILE__
  25. ": starting LH7A404 OHCI USB Controller\n");
  26. /*
  27. * Now, carefully enable the USB clock, and take
  28. * the USB host controller out of reset.
  29. */
  30. CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
  31. udelay(1000);
  32. USBH_CMDSTATUS = OHCI_HCR;
  33. printk(KERN_DEBUG __FILE__
  34. ": Clock to USB host has been enabled \n");
  35. }
  36. static void lh7a404_stop_hc(struct platform_device *dev)
  37. {
  38. printk(KERN_DEBUG __FILE__
  39. ": stopping LH7A404 OHCI USB Controller\n");
  40. CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
  41. }
  42. /*-------------------------------------------------------------------------*/
  43. /* configure so an HC device and id are always provided */
  44. /* always called with process context; sleeping is OK */
  45. /**
  46. * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
  47. * Context: !in_interrupt()
  48. *
  49. * Allocates basic resources for this USB host controller, and
  50. * then invokes the start() method for the HCD associated with it
  51. * through the hotplug entry's driver_data.
  52. *
  53. */
  54. int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
  55. struct platform_device *dev)
  56. {
  57. int retval;
  58. struct usb_hcd *hcd;
  59. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  60. pr_debug("resource[1] is not IORESOURCE_IRQ");
  61. return -ENOMEM;
  62. }
  63. hcd = usb_create_hcd(driver, &dev->dev, "lh7a404");
  64. if (!hcd)
  65. return -ENOMEM;
  66. hcd->rsrc_start = dev->resource[0].start;
  67. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  68. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  69. pr_debug("request_mem_region failed");
  70. retval = -EBUSY;
  71. goto err1;
  72. }
  73. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  74. if (!hcd->regs) {
  75. pr_debug("ioremap failed");
  76. retval = -ENOMEM;
  77. goto err2;
  78. }
  79. lh7a404_start_hc(dev);
  80. ohci_hcd_init(hcd_to_ohci(hcd));
  81. retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
  82. if (retval == 0)
  83. return retval;
  84. lh7a404_stop_hc(dev);
  85. iounmap(hcd->regs);
  86. err2:
  87. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  88. err1:
  89. usb_put_hcd(hcd);
  90. return retval;
  91. }
  92. /* may be called without controller electrically present */
  93. /* may be called with controller, bus, and devices active */
  94. /**
  95. * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
  96. * @dev: USB Host Controller being removed
  97. * Context: !in_interrupt()
  98. *
  99. * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
  100. * the HCD's stop() method. It is always called from a thread
  101. * context, normally "rmmod", "apmd", or something similar.
  102. *
  103. */
  104. void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
  105. {
  106. usb_remove_hcd(hcd);
  107. lh7a404_stop_hc(dev);
  108. iounmap(hcd->regs);
  109. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  110. usb_put_hcd(hcd);
  111. }
  112. /*-------------------------------------------------------------------------*/
  113. static int __devinit
  114. ohci_lh7a404_start (struct usb_hcd *hcd)
  115. {
  116. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  117. int ret;
  118. ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
  119. if ((ret = ohci_init(ohci)) < 0)
  120. return ret;
  121. if ((ret = ohci_run (ohci)) < 0) {
  122. err ("can't start %s", hcd->self.bus_name);
  123. ohci_stop (hcd);
  124. return ret;
  125. }
  126. return 0;
  127. }
  128. /*-------------------------------------------------------------------------*/
  129. static const struct hc_driver ohci_lh7a404_hc_driver = {
  130. .description = hcd_name,
  131. .product_desc = "LH7A404 OHCI",
  132. .hcd_priv_size = sizeof(struct ohci_hcd),
  133. /*
  134. * generic hardware linkage
  135. */
  136. .irq = ohci_irq,
  137. .flags = HCD_USB11 | HCD_MEMORY,
  138. /*
  139. * basic lifecycle operations
  140. */
  141. .start = ohci_lh7a404_start,
  142. #ifdef CONFIG_PM
  143. /* suspend: ohci_lh7a404_suspend, -- tbd */
  144. /* resume: ohci_lh7a404_resume, -- tbd */
  145. #endif /*CONFIG_PM*/
  146. .stop = ohci_stop,
  147. /*
  148. * managing i/o requests and associated device resources
  149. */
  150. .urb_enqueue = ohci_urb_enqueue,
  151. .urb_dequeue = ohci_urb_dequeue,
  152. .endpoint_disable = ohci_endpoint_disable,
  153. /*
  154. * scheduling support
  155. */
  156. .get_frame_number = ohci_get_frame,
  157. /*
  158. * root hub support
  159. */
  160. .hub_status_data = ohci_hub_status_data,
  161. .hub_control = ohci_hub_control,
  162. #ifdef CONFIG_PM
  163. .bus_suspend = ohci_bus_suspend,
  164. .bus_resume = ohci_bus_resume,
  165. #endif
  166. .start_port_reset = ohci_start_port_reset,
  167. };
  168. /*-------------------------------------------------------------------------*/
  169. static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
  170. {
  171. int ret;
  172. pr_debug ("In ohci_hcd_lh7a404_drv_probe");
  173. if (usb_disabled())
  174. return -ENODEV;
  175. ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
  176. return ret;
  177. }
  178. static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
  179. {
  180. struct usb_hcd *hcd = platform_get_drvdata(dev);
  181. usb_hcd_lh7a404_remove(hcd, pdev);
  182. return 0;
  183. }
  184. /*TBD*/
  185. /*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
  186. {
  187. struct usb_hcd *hcd = platform_get_drvdata(dev);
  188. return 0;
  189. }
  190. static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
  191. {
  192. struct usb_hcd *hcd = platform_get_drvdata(dev);
  193. return 0;
  194. }
  195. */
  196. static struct platform_driver ohci_hcd_lh7a404_driver = {
  197. .probe = ohci_hcd_lh7a404_drv_probe,
  198. .remove = ohci_hcd_lh7a404_drv_remove,
  199. /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
  200. /*.resume = ohci_hcd_lh7a404_drv_resume, */
  201. .driver = {
  202. .name = "lh7a404-ohci",
  203. .owner = THIS_MODULE,
  204. },
  205. };
  206. static int __init ohci_hcd_lh7a404_init (void)
  207. {
  208. pr_debug (DRIVER_INFO " (LH7A404)");
  209. pr_debug ("block sizes: ed %d td %d\n",
  210. sizeof (struct ed), sizeof (struct td));
  211. return platform_driver_register(&ohci_hcd_lh7a404_driver);
  212. }
  213. static void __exit ohci_hcd_lh7a404_cleanup (void)
  214. {
  215. platform_driver_unregister(&ohci_hcd_lh7a404_driver);
  216. }
  217. module_init (ohci_hcd_lh7a404_init);
  218. module_exit (ohci_hcd_lh7a404_cleanup);