ehci-pci.c 2.8 KB

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