ohci-pnx8550.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. * (C) Copyright 2005 Embedded Alley Solutions, Inc.
  8. *
  9. * Bus Glue for PNX8550
  10. *
  11. * Written by Christopher Hoover <ch@hpl.hp.com>
  12. * Based on fragments of previous driver by Russell King et al.
  13. *
  14. * Modified for LH7A404 from ohci-sa1111.c
  15. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  16. *
  17. * Modified for PNX8550 from ohci-sa1111.c and sa-omap.c
  18. * by Vitaly Wool <vitalywool@gmail.com>
  19. *
  20. * This file is licenced under the GPL.
  21. */
  22. #include <linux/device.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/mach-pnx8550/usb.h>
  25. #include <asm/mach-pnx8550/int.h>
  26. #include <asm/mach-pnx8550/pci.h>
  27. #ifndef CONFIG_PNX8550
  28. #error "This file is PNX8550 bus glue. CONFIG_PNX8550 must be defined."
  29. #endif
  30. extern int usb_disabled(void);
  31. /*-------------------------------------------------------------------------*/
  32. static void pnx8550_start_hc(struct platform_device *dev)
  33. {
  34. /*
  35. * Set register CLK48CTL to enable and 48MHz
  36. */
  37. outl(0x00000003, PCI_BASE | 0x0004770c);
  38. /*
  39. * Set register CLK12CTL to enable and 48MHz
  40. */
  41. outl(0x00000003, PCI_BASE | 0x00047710);
  42. udelay(100);
  43. }
  44. static void pnx8550_stop_hc(struct platform_device *dev)
  45. {
  46. udelay(10);
  47. }
  48. /*-------------------------------------------------------------------------*/
  49. /* configure so an HC device and id are always provided */
  50. /* always called with process context; sleeping is OK */
  51. /**
  52. * usb_hcd_pnx8550_probe - initialize pnx8550-based HCDs
  53. * Context: !in_interrupt()
  54. *
  55. * Allocates basic resources for this USB host controller, and
  56. * then invokes the start() method for the HCD associated with it
  57. * through the hotplug entry's driver_data.
  58. *
  59. */
  60. int usb_hcd_pnx8550_probe (const struct hc_driver *driver,
  61. struct platform_device *dev)
  62. {
  63. int retval;
  64. struct usb_hcd *hcd;
  65. if (dev->resource[0].flags != IORESOURCE_MEM ||
  66. dev->resource[1].flags != IORESOURCE_IRQ) {
  67. dev_err (&dev->dev,"invalid resource type\n");
  68. return -ENOMEM;
  69. }
  70. hcd = usb_create_hcd (driver, &dev->dev, "pnx8550");
  71. if (!hcd)
  72. return -ENOMEM;
  73. hcd->rsrc_start = dev->resource[0].start;
  74. hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
  75. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  76. dev_err(&dev->dev, "request_mem_region [0x%08llx, 0x%08llx] "
  77. "failed\n", hcd->rsrc_start, hcd->rsrc_len);
  78. retval = -EBUSY;
  79. goto err1;
  80. }
  81. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  82. if (!hcd->regs) {
  83. dev_err(&dev->dev, "ioremap [[0x%08llx, 0x%08llx] failed\n",
  84. hcd->rsrc_start, hcd->rsrc_len);
  85. retval = -ENOMEM;
  86. goto err2;
  87. }
  88. pnx8550_start_hc(dev);
  89. ohci_hcd_init(hcd_to_ohci(hcd));
  90. retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED);
  91. if (retval == 0)
  92. return retval;
  93. pnx8550_stop_hc(dev);
  94. iounmap(hcd->regs);
  95. err2:
  96. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  97. err1:
  98. usb_put_hcd(hcd);
  99. return retval;
  100. }
  101. /* may be called without controller electrically present */
  102. /* may be called with controller, bus, and devices active */
  103. /**
  104. * usb_hcd_pnx8550_remove - shutdown processing for pnx8550-based HCDs
  105. * @dev: USB Host Controller being removed
  106. * Context: !in_interrupt()
  107. *
  108. * Reverses the effect of usb_hcd_pnx8550_probe(), first invoking
  109. * the HCD's stop() method. It is always called from a thread
  110. * context, normally "rmmod", "apmd", or something similar.
  111. *
  112. */
  113. void usb_hcd_pnx8550_remove (struct usb_hcd *hcd, struct platform_device *dev)
  114. {
  115. usb_remove_hcd(hcd);
  116. pnx8550_stop_hc(dev);
  117. iounmap(hcd->regs);
  118. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  119. usb_put_hcd(hcd);
  120. }
  121. /*-------------------------------------------------------------------------*/
  122. static int __devinit
  123. ohci_pnx8550_start (struct usb_hcd *hcd)
  124. {
  125. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  126. int ret;
  127. ohci_dbg (ohci, "ohci_pnx8550_start, ohci:%p", ohci);
  128. if ((ret = ohci_init(ohci)) < 0)
  129. return ret;
  130. if ((ret = ohci_run (ohci)) < 0) {
  131. err ("can't start %s", hcd->self.bus_name);
  132. ohci_stop (hcd);
  133. return ret;
  134. }
  135. return 0;
  136. }
  137. /*-------------------------------------------------------------------------*/
  138. static const struct hc_driver ohci_pnx8550_hc_driver = {
  139. .description = hcd_name,
  140. .product_desc = "PNX8550 OHCI",
  141. .hcd_priv_size = sizeof(struct ohci_hcd),
  142. /*
  143. * generic hardware linkage
  144. */
  145. .irq = ohci_irq,
  146. .flags = HCD_USB11 | HCD_MEMORY,
  147. /*
  148. * basic lifecycle operations
  149. */
  150. .start = ohci_pnx8550_start,
  151. .stop = ohci_stop,
  152. /*
  153. * managing i/o requests and associated device resources
  154. */
  155. .urb_enqueue = ohci_urb_enqueue,
  156. .urb_dequeue = ohci_urb_dequeue,
  157. .endpoint_disable = ohci_endpoint_disable,
  158. /*
  159. * scheduling support
  160. */
  161. .get_frame_number = ohci_get_frame,
  162. /*
  163. * root hub support
  164. */
  165. .hub_status_data = ohci_hub_status_data,
  166. .hub_control = ohci_hub_control,
  167. #ifdef CONFIG_PM
  168. .bus_suspend = ohci_bus_suspend,
  169. .bus_resume = ohci_bus_resume,
  170. #endif
  171. .start_port_reset = ohci_start_port_reset,
  172. };
  173. /*-------------------------------------------------------------------------*/
  174. static int ohci_hcd_pnx8550_drv_probe(struct platform_device *pdev)
  175. {
  176. int ret;
  177. if (usb_disabled())
  178. return -ENODEV;
  179. ret = usb_hcd_pnx8550_probe(&ohci_pnx8550_hc_driver, pdev);
  180. return ret;
  181. }
  182. static int ohci_hcd_pnx8550_drv_remove(struct platform_device *pdev)
  183. {
  184. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  185. usb_hcd_pnx8550_remove(hcd, pdev);
  186. return 0;
  187. }
  188. MODULE_ALIAS("platform:pnx8550-ohci");
  189. static struct platform_driver ohci_hcd_pnx8550_driver = {
  190. .driver = {
  191. .name = "pnx8550-ohci",
  192. .owner = THIS_MODULE,
  193. },
  194. .probe = ohci_hcd_pnx8550_drv_probe,
  195. .remove = ohci_hcd_pnx8550_drv_remove,
  196. };