ehci-pci.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*-
  3. * Copyright (c) 2007-2008, Juniper Networks, Inc.
  4. * All rights reserved.
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <pci.h>
  10. #include <usb.h>
  11. #include <asm/io.h>
  12. #include "ehci.h"
  13. /* Information about a USB port */
  14. struct ehci_pci_priv {
  15. struct ehci_ctrl ehci;
  16. };
  17. #ifdef CONFIG_DM_USB
  18. static void ehci_pci_init(struct udevice *dev, struct ehci_hccr **ret_hccr,
  19. struct ehci_hcor **ret_hcor)
  20. {
  21. struct ehci_hccr *hccr;
  22. struct ehci_hcor *hcor;
  23. u32 cmd;
  24. hccr = (struct ehci_hccr *)dm_pci_map_bar(dev,
  25. PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
  26. hcor = (struct ehci_hcor *)((uintptr_t) hccr +
  27. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  28. debug("EHCI-PCI init hccr %#lx and hcor %#lx hc_length %d\n",
  29. (ulong)hccr, (ulong)hcor,
  30. (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  31. *ret_hccr = hccr;
  32. *ret_hcor = hcor;
  33. /* enable busmaster */
  34. dm_pci_read_config32(dev, PCI_COMMAND, &cmd);
  35. cmd |= PCI_COMMAND_MASTER;
  36. dm_pci_write_config32(dev, PCI_COMMAND, cmd);
  37. }
  38. #else
  39. #ifdef CONFIG_PCI_EHCI_DEVICE
  40. static struct pci_device_id ehci_pci_ids[] = {
  41. /* Please add supported PCI EHCI controller ids here */
  42. {0x1033, 0x00E0}, /* NEC */
  43. {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
  44. {0x12D8, 0x400F}, /* Pericom */
  45. {0, 0}
  46. };
  47. #endif
  48. static void ehci_pci_legacy_init(pci_dev_t pdev, struct ehci_hccr **ret_hccr,
  49. struct ehci_hcor **ret_hcor)
  50. {
  51. struct ehci_hccr *hccr;
  52. struct ehci_hcor *hcor;
  53. u32 cmd;
  54. hccr = (struct ehci_hccr *)pci_map_bar(pdev,
  55. PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
  56. hcor = (struct ehci_hcor *)((uintptr_t) hccr +
  57. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  58. debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
  59. (u32)hccr, (u32)hcor,
  60. (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  61. *ret_hccr = hccr;
  62. *ret_hcor = hcor;
  63. /* enable busmaster */
  64. pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
  65. cmd |= PCI_COMMAND_MASTER;
  66. pci_write_config_dword(pdev, PCI_COMMAND, cmd);
  67. }
  68. /*
  69. * Create the appropriate control structures to manage
  70. * a new EHCI host controller.
  71. */
  72. int ehci_hcd_init(int index, enum usb_init_type init,
  73. struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
  74. {
  75. pci_dev_t pdev;
  76. #ifdef CONFIG_PCI_EHCI_DEVICE
  77. pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
  78. #else
  79. pdev = pci_find_class(PCI_CLASS_SERIAL_USB_EHCI, index);
  80. #endif
  81. if (pdev < 0) {
  82. printf("EHCI host controller not found\n");
  83. return -1;
  84. }
  85. ehci_pci_legacy_init(pdev, ret_hccr, ret_hcor);
  86. return 0;
  87. }
  88. /*
  89. * Destroy the appropriate control structures corresponding
  90. * the the EHCI host controller.
  91. */
  92. int ehci_hcd_stop(int index)
  93. {
  94. return 0;
  95. }
  96. #endif /* nCONFIG_DM_USB */
  97. #ifdef CONFIG_DM_USB
  98. static int ehci_pci_probe(struct udevice *dev)
  99. {
  100. struct ehci_hccr *hccr;
  101. struct ehci_hcor *hcor;
  102. ehci_pci_init(dev, &hccr, &hcor);
  103. return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
  104. }
  105. static const struct udevice_id ehci_pci_ids[] = {
  106. { .compatible = "ehci-pci" },
  107. { }
  108. };
  109. U_BOOT_DRIVER(ehci_pci) = {
  110. .name = "ehci_pci",
  111. .id = UCLASS_USB,
  112. .probe = ehci_pci_probe,
  113. .remove = ehci_deregister,
  114. .of_match = ehci_pci_ids,
  115. .ops = &ehci_usb_ops,
  116. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  117. .priv_auto_alloc_size = sizeof(struct ehci_pci_priv),
  118. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  119. };
  120. static struct pci_device_id ehci_pci_supported[] = {
  121. { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0) },
  122. {},
  123. };
  124. U_BOOT_PCI_DEVICE(ehci_pci, ehci_pci_supported);
  125. #endif /* CONFIG_DM_USB */