uhci-grlib.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #include <linux/platform_device.h>
  25. static int uhci_grlib_init(struct usb_hcd *hcd)
  26. {
  27. struct uhci_hcd *uhci = hcd_to_uhci(hcd);
  28. /*
  29. * Probe to determine the endianness of the controller.
  30. * We know that bit 7 of the PORTSC1 register is always set
  31. * and bit 15 is always clear. If uhci_readw() yields a value
  32. * with bit 7 (0x80) turned on then the current little-endian
  33. * setting is correct. Otherwise we assume the value was
  34. * byte-swapped; hence the register interface and presumably
  35. * also the descriptors are big-endian.
  36. */
  37. if (!(uhci_readw(uhci, USBPORTSC1) & 0x80)) {
  38. uhci->big_endian_mmio = 1;
  39. uhci->big_endian_desc = 1;
  40. }
  41. uhci->rh_numports = uhci_count_ports(hcd);
  42. /* Set up pointers to generic functions */
  43. uhci->reset_hc = uhci_generic_reset_hc;
  44. uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
  45. /* No special actions need to be taken for the functions below */
  46. uhci->configure_hc = NULL;
  47. uhci->resume_detect_interrupts_are_broken = NULL;
  48. uhci->global_suspend_mode_is_broken = NULL;
  49. /* Reset if the controller isn't already safely quiescent. */
  50. check_and_reset_hc(uhci);
  51. return 0;
  52. }
  53. static const struct hc_driver uhci_grlib_hc_driver = {
  54. .description = hcd_name,
  55. .product_desc = "GRLIB GRUSBHC UHCI Host Controller",
  56. .hcd_priv_size = sizeof(struct uhci_hcd),
  57. /* Generic hardware linkage */
  58. .irq = uhci_irq,
  59. .flags = HCD_MEMORY | HCD_DMA | HCD_USB11,
  60. /* Basic lifecycle operations */
  61. .reset = uhci_grlib_init,
  62. .start = uhci_start,
  63. #ifdef CONFIG_PM
  64. .pci_suspend = NULL,
  65. .pci_resume = NULL,
  66. .bus_suspend = uhci_rh_suspend,
  67. .bus_resume = uhci_rh_resume,
  68. #endif
  69. .stop = uhci_stop,
  70. .urb_enqueue = uhci_urb_enqueue,
  71. .urb_dequeue = uhci_urb_dequeue,
  72. .endpoint_disable = uhci_hcd_endpoint_disable,
  73. .get_frame_number = uhci_hcd_get_frame_number,
  74. .hub_status_data = uhci_hub_status_data,
  75. .hub_control = uhci_hub_control,
  76. };
  77. static int uhci_hcd_grlib_probe(struct platform_device *op)
  78. {
  79. struct device_node *dn = op->dev.of_node;
  80. struct usb_hcd *hcd;
  81. struct uhci_hcd *uhci = NULL;
  82. struct resource res;
  83. int irq;
  84. int rv;
  85. if (usb_disabled())
  86. return -ENODEV;
  87. dev_dbg(&op->dev, "initializing GRUSBHC UHCI USB Controller\n");
  88. rv = of_address_to_resource(dn, 0, &res);
  89. if (rv)
  90. return rv;
  91. /* usb_create_hcd requires dma_mask != NULL */
  92. op->dev.dma_mask = &op->dev.coherent_dma_mask;
  93. hcd = usb_create_hcd(&uhci_grlib_hc_driver, &op->dev,
  94. "GRUSBHC UHCI USB");
  95. if (!hcd)
  96. return -ENOMEM;
  97. hcd->rsrc_start = res.start;
  98. hcd->rsrc_len = resource_size(&res);
  99. irq = irq_of_parse_and_map(dn, 0);
  100. if (!irq) {
  101. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  102. rv = -EBUSY;
  103. goto err_usb;
  104. }
  105. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  106. if (IS_ERR(hcd->regs)) {
  107. rv = PTR_ERR(hcd->regs);
  108. goto err_irq;
  109. }
  110. uhci = hcd_to_uhci(hcd);
  111. uhci->regs = hcd->regs;
  112. rv = usb_add_hcd(hcd, irq, 0);
  113. if (rv)
  114. goto err_irq;
  115. device_wakeup_enable(hcd->self.controller);
  116. return 0;
  117. err_irq:
  118. irq_dispose_mapping(irq);
  119. err_usb:
  120. usb_put_hcd(hcd);
  121. return rv;
  122. }
  123. static void uhci_hcd_grlib_remove(struct platform_device *op)
  124. {
  125. struct usb_hcd *hcd = platform_get_drvdata(op);
  126. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC UHCI USB Controller\n");
  127. usb_remove_hcd(hcd);
  128. irq_dispose_mapping(hcd->irq);
  129. usb_put_hcd(hcd);
  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_new = 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. };