uhci-grlib.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * UHCI HCD (Host Controller Driver) for GRLIB GRUSBHC
  3. *
  4. * Copyright (c) 2011 Jan Andersson <jan@gaisler.com>
  5. *
  6. * This file is based on UHCI PCI HCD:
  7. * (C) Copyright 1999 Linus Torvalds
  8. * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
  9. * (C) Copyright 1999 Randy Dunlap
  10. * (C) Copyright 1999 Georg Acher, acher@in.tum.de
  11. * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
  12. * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
  13. * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
  14. * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
  15. * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
  16. * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
  17. * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
  18. */
  19. #include <linux/of_irq.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_platform.h>
  22. static int uhci_grlib_init(struct usb_hcd *hcd)
  23. {
  24. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  25. /*
  26. * Probe to determine the endianness of the controller.
  27. * We know that bit 7 of the PORTSC1 register is always set
  28. * and bit 15 is always clear. If uhci_readw() yields a value
  29. * with bit 7 (0x80) turned on then the current little-endian
  30. * setting is correct. Otherwise we assume the value was
  31. * byte-swapped; hence the register interface and presumably
  32. * also the descriptors are big-endian.
  33. */
  34. if (!(uhci_readw(uhci, USBPORTSC1) & 0x80)) {
  35. uhci->big_endian_mmio = 1;
  36. uhci->big_endian_desc = 1;
  37. }
  38. uhci->rh_numports = uhci_count_ports(hcd);
  39. /* Set up pointers to to generic functions */
  40. uhci->reset_hc = uhci_generic_reset_hc;
  41. uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
  42. /* No special actions need to be taken for the functions below */
  43. uhci->configure_hc = NULL;
  44. uhci->resume_detect_interrupts_are_broken = NULL;
  45. uhci->global_suspend_mode_is_broken = NULL;
  46. /* Reset if the controller isn't already safely quiescent. */
  47. check_and_reset_hc(uhci);
  48. return 0;
  49. }
  50. static const struct hc_driver uhci_grlib_hc_driver = {
  51. .description = hcd_name,
  52. .product_desc = "GRLIB GRUSBHC UHCI Host Controller",
  53. .hcd_priv_size = sizeof(struct uhci_hcd),
  54. /* Generic hardware linkage */
  55. .irq = uhci_irq,
  56. .flags = HCD_MEMORY | HCD_USB11,
  57. /* Basic lifecycle operations */
  58. .reset = uhci_grlib_init,
  59. .start = uhci_start,
  60. #ifdef CONFIG_PM
  61. .pci_suspend = NULL,
  62. .pci_resume = NULL,
  63. .bus_suspend = uhci_rh_suspend,
  64. .bus_resume = uhci_rh_resume,
  65. #endif
  66. .stop = uhci_stop,
  67. .urb_enqueue = uhci_urb_enqueue,
  68. .urb_dequeue = uhci_urb_dequeue,
  69. .endpoint_disable = uhci_hcd_endpoint_disable,
  70. .get_frame_number = uhci_hcd_get_frame_number,
  71. .hub_status_data = uhci_hub_status_data,
  72. .hub_control = uhci_hub_control,
  73. };
  74. static int __devinit uhci_hcd_grlib_probe(struct platform_device *op)
  75. {
  76. struct device_node *dn = op->dev.of_node;
  77. struct usb_hcd *hcd;
  78. struct uhci_hcd *uhci = NULL;
  79. struct resource res;
  80. int irq;
  81. int rv;
  82. if (usb_disabled())
  83. return -ENODEV;
  84. dev_dbg(&op->dev, "initializing GRUSBHC UHCI USB Controller\n");
  85. rv = of_address_to_resource(dn, 0, &res);
  86. if (rv)
  87. return rv;
  88. /* usb_create_hcd requires dma_mask != NULL */
  89. op->dev.dma_mask = &op->dev.coherent_dma_mask;
  90. hcd = usb_create_hcd(&uhci_grlib_hc_driver, &op->dev,
  91. "GRUSBHC UHCI USB");
  92. if (!hcd)
  93. return -ENOMEM;
  94. hcd->rsrc_start = res.start;
  95. hcd->rsrc_len = resource_size(&res);
  96. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  97. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  98. rv = -EBUSY;
  99. goto err_rmr;
  100. }
  101. irq = irq_of_parse_and_map(dn, 0);
  102. if (irq == NO_IRQ) {
  103. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  104. rv = -EBUSY;
  105. goto err_irq;
  106. }
  107. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  108. if (!hcd->regs) {
  109. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  110. rv = -ENOMEM;
  111. goto err_ioremap;
  112. }
  113. uhci = hcd_to_uhci(hcd);
  114. uhci->regs = hcd->regs;
  115. rv = usb_add_hcd(hcd, irq, 0);
  116. if (rv)
  117. goto err_uhci;
  118. return 0;
  119. err_uhci:
  120. iounmap(hcd->regs);
  121. err_ioremap:
  122. irq_dispose_mapping(irq);
  123. err_irq:
  124. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  125. err_rmr:
  126. usb_put_hcd(hcd);
  127. return rv;
  128. }
  129. static int uhci_hcd_grlib_remove(struct platform_device *op)
  130. {
  131. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  132. dev_set_drvdata(&op->dev, NULL);
  133. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC UHCI USB Controller\n");
  134. usb_remove_hcd(hcd);
  135. iounmap(hcd->regs);
  136. irq_dispose_mapping(hcd->irq);
  137. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  138. usb_put_hcd(hcd);
  139. return 0;
  140. }
  141. /* Make sure the controller is quiescent and that we're not using it
  142. * any more. This is mainly for the benefit of programs which, like kexec,
  143. * expect the hardware to be idle: not doing DMA or generating IRQs.
  144. *
  145. * This routine may be called in a damaged or failing kernel. Hence we
  146. * do not acquire the spinlock before shutting down the controller.
  147. */
  148. static void uhci_hcd_grlib_shutdown(struct platform_device *op)
  149. {
  150. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  151. uhci_hc_died(hcd_to_uhci(hcd));
  152. }
  153. static const struct of_device_id uhci_hcd_grlib_of_match[] = {
  154. { .name = "GAISLER_UHCI", },
  155. { .name = "01_027", },
  156. {},
  157. };
  158. MODULE_DEVICE_TABLE(of, uhci_hcd_grlib_of_match);
  159. static struct platform_driver uhci_grlib_driver = {
  160. .probe = uhci_hcd_grlib_probe,
  161. .remove = uhci_hcd_grlib_remove,
  162. .shutdown = uhci_hcd_grlib_shutdown,
  163. .driver = {
  164. .name = "grlib-uhci",
  165. .owner = THIS_MODULE,
  166. .of_match_table = uhci_hcd_grlib_of_match,
  167. },
  168. };