uhci-grlib.c 5.1 KB

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