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 <linux/signal.h>
  20. #include <asm/hardware.h>
  21. extern int usb_disabled(void);
  22. /*-------------------------------------------------------------------------*/
  23. static void lh7a404_start_hc(struct platform_device *dev)
  24. {
  25. printk(KERN_DEBUG __FILE__
  26. ": starting LH7A404 OHCI USB Controller\n");
  27. /*
  28. * Now, carefully enable the USB clock, and take
  29. * the USB host controller out of reset.
  30. */
  31. CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
  32. udelay(1000);
  33. USBH_CMDSTATUS = OHCI_HCR;
  34. printk(KERN_DEBUG __FILE__
  35. ": Clock to USB host has been enabled \n");
  36. }
  37. static void lh7a404_stop_hc(struct platform_device *dev)
  38. {
  39. printk(KERN_DEBUG __FILE__
  40. ": stopping LH7A404 OHCI USB Controller\n");
  41. CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
  42. }
  43. /*-------------------------------------------------------------------------*/
  44. /* configure so an HC device and id are always provided */
  45. /* always called with process context; sleeping is OK */
  46. /**
  47. * usb_hcd_lh7a404_probe - initialize LH7A404-based HCDs
  48. * Context: !in_interrupt()
  49. *
  50. * Allocates basic resources for this USB host controller, and
  51. * then invokes the start() method for the HCD associated with it
  52. * through the hotplug entry's driver_data.
  53. *
  54. */
  55. int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
  56. struct platform_device *dev)
  57. {
  58. int retval;
  59. struct usb_hcd *hcd;
  60. if (dev->resource[1].flags != IORESOURCE_IRQ) {
  61. pr_debug("resource[1] is not IORESOURCE_IRQ");
  62. return -ENOMEM;
  63. }
  64. hcd = usb_create_hcd(driver, &dev->dev, "lh7a404");
  65. if (!hcd)
  66. return -ENOMEM;
  67. hcd->rsrc_start = dev->resource[0].start;
  68. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  69. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  70. pr_debug("request_mem_region failed");
  71. retval = -EBUSY;
  72. goto err1;
  73. }
  74. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  75. if (!hcd->regs) {
  76. pr_debug("ioremap failed");
  77. retval = -ENOMEM;
  78. goto err2;
  79. }
  80. lh7a404_start_hc(dev);
  81. ohci_hcd_init(hcd_to_ohci(hcd));
  82. retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
  83. if (retval == 0)
  84. return retval;
  85. lh7a404_stop_hc(dev);
  86. iounmap(hcd->regs);
  87. err2:
  88. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  89. err1:
  90. usb_put_hcd(hcd);
  91. return retval;
  92. }
  93. /* may be called without controller electrically present */
  94. /* may be called with controller, bus, and devices active */
  95. /**
  96. * usb_hcd_lh7a404_remove - shutdown processing for LH7A404-based HCDs
  97. * @dev: USB Host Controller being removed
  98. * Context: !in_interrupt()
  99. *
  100. * Reverses the effect of usb_hcd_lh7a404_probe(), first invoking
  101. * the HCD's stop() method. It is always called from a thread
  102. * context, normally "rmmod", "apmd", or something similar.
  103. *
  104. */
  105. void usb_hcd_lh7a404_remove (struct usb_hcd *hcd, struct platform_device *dev)
  106. {
  107. usb_remove_hcd(hcd);
  108. lh7a404_stop_hc(dev);
  109. iounmap(hcd->regs);
  110. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  111. usb_put_hcd(hcd);
  112. }
  113. /*-------------------------------------------------------------------------*/
  114. static int __devinit
  115. ohci_lh7a404_start (struct usb_hcd *hcd)
  116. {
  117. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  118. int ret;
  119. ohci_dbg (ohci, "ohci_lh7a404_start, ohci:%p", ohci);
  120. if ((ret = ohci_init(ohci)) < 0)
  121. return ret;
  122. if ((ret = ohci_run (ohci)) < 0) {
  123. err ("can't start %s", hcd->self.bus_name);
  124. ohci_stop (hcd);
  125. return ret;
  126. }
  127. return 0;
  128. }
  129. /*-------------------------------------------------------------------------*/
  130. static const struct hc_driver ohci_lh7a404_hc_driver = {
  131. .description = hcd_name,
  132. .product_desc = "LH7A404 OHCI",
  133. .hcd_priv_size = sizeof(struct ohci_hcd),
  134. /*
  135. * generic hardware linkage
  136. */
  137. .irq = ohci_irq,
  138. .flags = HCD_USB11 | HCD_MEMORY,
  139. /*
  140. * basic lifecycle operations
  141. */
  142. .start = ohci_lh7a404_start,
  143. .stop = ohci_stop,
  144. .shutdown = ohci_shutdown,
  145. /*
  146. * managing i/o requests and associated device resources
  147. */
  148. .urb_enqueue = ohci_urb_enqueue,
  149. .urb_dequeue = ohci_urb_dequeue,
  150. .endpoint_disable = ohci_endpoint_disable,
  151. /*
  152. * scheduling support
  153. */
  154. .get_frame_number = ohci_get_frame,
  155. /*
  156. * root hub support
  157. */
  158. .hub_status_data = ohci_hub_status_data,
  159. .hub_control = ohci_hub_control,
  160. .hub_irq_enable = ohci_rhsc_enable,
  161. #ifdef CONFIG_PM
  162. .bus_suspend = ohci_bus_suspend,
  163. .bus_resume = ohci_bus_resume,
  164. #endif
  165. .start_port_reset = ohci_start_port_reset,
  166. };
  167. /*-------------------------------------------------------------------------*/
  168. static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
  169. {
  170. int ret;
  171. pr_debug ("In ohci_hcd_lh7a404_drv_probe");
  172. if (usb_disabled())
  173. return -ENODEV;
  174. ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
  175. return ret;
  176. }
  177. static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
  178. {
  179. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  180. usb_hcd_lh7a404_remove(hcd, pdev);
  181. return 0;
  182. }
  183. /*TBD*/
  184. /*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
  185. {
  186. struct usb_hcd *hcd = platform_get_drvdata(dev);
  187. return 0;
  188. }
  189. static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
  190. {
  191. struct usb_hcd *hcd = platform_get_drvdata(dev);
  192. return 0;
  193. }
  194. */
  195. static struct platform_driver ohci_hcd_lh7a404_driver = {
  196. .probe = ohci_hcd_lh7a404_drv_probe,
  197. .remove = ohci_hcd_lh7a404_drv_remove,
  198. .shutdown = usb_hcd_platform_shutdown,
  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);