ehci-pci.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*-
  2. * Copyright (c) 2007-2008, Juniper Networks, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation version 2 of
  8. * the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <errno.h>
  22. #include <pci.h>
  23. #include <usb.h>
  24. #include "ehci.h"
  25. #ifdef CONFIG_PCI_EHCI_DEVICE
  26. static struct pci_device_id ehci_pci_ids[] = {
  27. /* Please add supported PCI EHCI controller ids here */
  28. {0x1033, 0x00E0}, /* NEC */
  29. {0x10B9, 0x5239}, /* ULI1575 PCI EHCI module ids */
  30. {0x12D8, 0x400F}, /* Pericom */
  31. {0, 0}
  32. };
  33. #else
  34. static pci_dev_t ehci_find_class(int index)
  35. {
  36. int bus;
  37. int devnum;
  38. pci_dev_t bdf;
  39. uint32_t class;
  40. for (bus = 0; bus <= pci_last_busno(); bus++) {
  41. for (devnum = 0; devnum < PCI_MAX_PCI_DEVICES-1; devnum++) {
  42. pci_read_config_dword(PCI_BDF(bus, devnum, 0),
  43. PCI_CLASS_REVISION, &class);
  44. if (class >> 16 == 0xffff)
  45. continue;
  46. for (bdf = PCI_BDF(bus, devnum, 0);
  47. bdf <= PCI_BDF(bus, devnum,
  48. PCI_MAX_PCI_FUNCTIONS - 1);
  49. bdf += PCI_BDF(0, 0, 1)) {
  50. pci_read_config_dword(bdf, PCI_CLASS_REVISION,
  51. &class);
  52. class >>= 8;
  53. /*
  54. * Here be dragons! In case we have multiple
  55. * PCI EHCI controllers, this function will
  56. * be called multiple times as well. This
  57. * function will scan the PCI busses, always
  58. * starting from bus 0, device 0, function 0,
  59. * until it finds an USB controller. The USB
  60. * stack gives us an 'index' of a controller
  61. * that is currently being registered, which
  62. * is a number, starting from 0 and growing
  63. * in ascending order as controllers are added.
  64. * To avoid probing the same controller in tne
  65. * subsequent runs of this function, we will
  66. * skip 'index - 1' detected controllers and
  67. * report the index'th controller.
  68. */
  69. if (class != PCI_CLASS_SERIAL_USB_EHCI)
  70. continue;
  71. if (index) {
  72. index--;
  73. continue;
  74. }
  75. /* Return index'th controller. */
  76. return bdf;
  77. }
  78. }
  79. }
  80. return -ENODEV;
  81. }
  82. #endif
  83. /*
  84. * Create the appropriate control structures to manage
  85. * a new EHCI host controller.
  86. */
  87. int ehci_hcd_init(int index, enum usb_init_type init,
  88. struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
  89. {
  90. pci_dev_t pdev;
  91. uint32_t cmd;
  92. struct ehci_hccr *hccr;
  93. struct ehci_hcor *hcor;
  94. #ifdef CONFIG_PCI_EHCI_DEVICE
  95. pdev = pci_find_devices(ehci_pci_ids, CONFIG_PCI_EHCI_DEVICE);
  96. #else
  97. pdev = ehci_find_class(index);
  98. #endif
  99. if (pdev < 0) {
  100. printf("EHCI host controller not found\n");
  101. return -1;
  102. }
  103. hccr = (struct ehci_hccr *)pci_map_bar(pdev,
  104. PCI_BASE_ADDRESS_0, PCI_REGION_MEM);
  105. hcor = (struct ehci_hcor *)((uint32_t) hccr +
  106. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  107. debug("EHCI-PCI init hccr 0x%x and hcor 0x%x hc_length %d\n",
  108. (uint32_t)hccr, (uint32_t)hcor,
  109. (uint32_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  110. *ret_hccr = hccr;
  111. *ret_hcor = hcor;
  112. /* enable busmaster */
  113. pci_read_config_dword(pdev, PCI_COMMAND, &cmd);
  114. cmd |= PCI_COMMAND_MASTER;
  115. pci_write_config_dword(pdev, PCI_COMMAND, cmd);
  116. return 0;
  117. }
  118. /*
  119. * Destroy the appropriate control structures corresponding
  120. * the the EHCI host controller.
  121. */
  122. int ehci_hcd_stop(int index)
  123. {
  124. return 0;
  125. }