ohci-lh7a404.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 Russell 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 <mach/hardware.h>
  21. extern int usb_disabled(void);
  22. /*-------------------------------------------------------------------------*/
  23. static void lh7a404_start_hc(struct platform_device *dev)
  24. {
  25. printk(KERN_DEBUG "%s: starting LH7A404 OHCI USB Controller\n",
  26. __FILE__);
  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 "%s: Clock to USB host has been enabled \n", __FILE__);
  35. }
  36. static void lh7a404_stop_hc(struct platform_device *dev)
  37. {
  38. printk(KERN_DEBUG "%s: stopping LH7A404 OHCI USB Controller\n",
  39. __FILE__);
  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, IRQF_DISABLED);
  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. .stop = ohci_stop,
  143. .shutdown = ohci_shutdown,
  144. /*
  145. * managing i/o requests and associated device resources
  146. */
  147. .urb_enqueue = ohci_urb_enqueue,
  148. .urb_dequeue = ohci_urb_dequeue,
  149. .endpoint_disable = ohci_endpoint_disable,
  150. /*
  151. * scheduling support
  152. */
  153. .get_frame_number = ohci_get_frame,
  154. /*
  155. * root hub support
  156. */
  157. .hub_status_data = ohci_hub_status_data,
  158. .hub_control = ohci_hub_control,
  159. #ifdef CONFIG_PM
  160. .bus_suspend = ohci_bus_suspend,
  161. .bus_resume = ohci_bus_resume,
  162. #endif
  163. .start_port_reset = ohci_start_port_reset,
  164. };
  165. /*-------------------------------------------------------------------------*/
  166. static int ohci_hcd_lh7a404_drv_probe(struct platform_device *pdev)
  167. {
  168. int ret;
  169. pr_debug ("In ohci_hcd_lh7a404_drv_probe");
  170. if (usb_disabled())
  171. return -ENODEV;
  172. ret = usb_hcd_lh7a404_probe(&ohci_lh7a404_hc_driver, pdev);
  173. return ret;
  174. }
  175. static int ohci_hcd_lh7a404_drv_remove(struct platform_device *pdev)
  176. {
  177. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  178. usb_hcd_lh7a404_remove(hcd, pdev);
  179. return 0;
  180. }
  181. /*TBD*/
  182. /*static int ohci_hcd_lh7a404_drv_suspend(struct platform_device *dev)
  183. {
  184. struct usb_hcd *hcd = platform_get_drvdata(dev);
  185. return 0;
  186. }
  187. static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
  188. {
  189. struct usb_hcd *hcd = platform_get_drvdata(dev);
  190. return 0;
  191. }
  192. */
  193. static struct platform_driver ohci_hcd_lh7a404_driver = {
  194. .probe = ohci_hcd_lh7a404_drv_probe,
  195. .remove = ohci_hcd_lh7a404_drv_remove,
  196. .shutdown = usb_hcd_platform_shutdown,
  197. /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
  198. /*.resume = ohci_hcd_lh7a404_drv_resume, */
  199. .driver = {
  200. .name = "lh7a404-ohci",
  201. .owner = THIS_MODULE,
  202. },
  203. };
  204. MODULE_ALIAS("platform:lh7a404-ohci");