ehci-faraday.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Faraday USB 2.0 EHCI Controller
  4. *
  5. * (C) Copyright 2010 Faraday Technology
  6. * Dante Su <dantesu@faraday-tech.com>
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <usb.h>
  11. #include <usb/fusbh200.h>
  12. #include <usb/fotg210.h>
  13. #include "ehci.h"
  14. #ifndef CONFIG_USB_EHCI_BASE_LIST
  15. #define CONFIG_USB_EHCI_BASE_LIST { CONFIG_USB_EHCI_BASE }
  16. #endif
  17. union ehci_faraday_regs {
  18. struct fusbh200_regs usb;
  19. struct fotg210_regs otg;
  20. };
  21. static inline int ehci_is_fotg2xx(union ehci_faraday_regs *regs)
  22. {
  23. return !readl(&regs->usb.easstr);
  24. }
  25. void faraday_ehci_set_usbmode(struct ehci_ctrl *ctrl)
  26. {
  27. /* nothing needs to be done */
  28. }
  29. int faraday_ehci_get_port_speed(struct ehci_ctrl *ctrl, uint32_t reg)
  30. {
  31. int spd, ret = PORTSC_PSPD_HS;
  32. union ehci_faraday_regs *regs;
  33. ret = (void __iomem *)((ulong)ctrl->hcor - 0x10);
  34. if (ehci_is_fotg2xx(regs))
  35. spd = OTGCSR_SPD(readl(&regs->otg.otgcsr));
  36. else
  37. spd = BMCSR_SPD(readl(&regs->usb.bmcsr));
  38. switch (spd) {
  39. case 0: /* full speed */
  40. ret = PORTSC_PSPD_FS;
  41. break;
  42. case 1: /* low speed */
  43. ret = PORTSC_PSPD_LS;
  44. break;
  45. case 2: /* high speed */
  46. ret = PORTSC_PSPD_HS;
  47. break;
  48. default:
  49. printf("ehci-faraday: invalid device speed\n");
  50. break;
  51. }
  52. return ret;
  53. }
  54. uint32_t *faraday_ehci_get_portsc_register(struct ehci_ctrl *ctrl, int port)
  55. {
  56. /* Faraday EHCI has one and only one portsc register */
  57. if (port) {
  58. /* Printing the message would cause a scan failure! */
  59. debug("The request port(%d) is not configured\n", port);
  60. return NULL;
  61. }
  62. /* Faraday EHCI PORTSC register offset is 0x20 from hcor */
  63. return (uint32_t *)((uint8_t *)ctrl->hcor + 0x20);
  64. }
  65. static const struct ehci_ops faraday_ehci_ops = {
  66. .set_usb_mode = faraday_ehci_set_usbmode,
  67. .get_port_speed = faraday_ehci_get_port_speed,
  68. .get_portsc_register = faraday_ehci_get_portsc_register,
  69. };
  70. /*
  71. * Create the appropriate control structures to manage
  72. * a new EHCI host controller.
  73. */
  74. int ehci_hcd_init(int index, enum usb_init_type init,
  75. struct ehci_hccr **ret_hccr, struct ehci_hcor **ret_hcor)
  76. {
  77. struct ehci_hccr *hccr;
  78. struct ehci_hcor *hcor;
  79. union ehci_faraday_regs *regs;
  80. uint32_t base_list[] = CONFIG_USB_EHCI_BASE_LIST;
  81. if (index < 0 || index >= ARRAY_SIZE(base_list))
  82. return -1;
  83. ehci_set_controller_priv(index, NULL, &faraday_ehci_ops);
  84. regs = (void __iomem *)base_list[index];
  85. hccr = (struct ehci_hccr *)&regs->usb.hccr;
  86. hcor = (struct ehci_hcor *)&regs->usb.hcor;
  87. if (ehci_is_fotg2xx(regs)) {
  88. /* A-device bus reset */
  89. /* ... Power off A-device */
  90. setbits_le32(&regs->otg.otgcsr, OTGCSR_A_BUSDROP);
  91. /* ... Drop vbus and bus traffic */
  92. clrbits_le32(&regs->otg.otgcsr, OTGCSR_A_BUSREQ);
  93. mdelay(1);
  94. /* ... Power on A-device */
  95. clrbits_le32(&regs->otg.otgcsr, OTGCSR_A_BUSDROP);
  96. /* ... Drive vbus and bus traffic */
  97. setbits_le32(&regs->otg.otgcsr, OTGCSR_A_BUSREQ);
  98. mdelay(1);
  99. /* Disable OTG & DEV interrupts, triggered at level-high */
  100. writel(IMR_IRQLH | IMR_OTG | IMR_DEV, &regs->otg.imr);
  101. /* Clear all interrupt status */
  102. writel(ISR_HOST | ISR_OTG | ISR_DEV, &regs->otg.isr);
  103. } else {
  104. /* Interrupt=level-high */
  105. setbits_le32(&regs->usb.bmcsr, BMCSR_IRQLH);
  106. /* VBUS on */
  107. clrbits_le32(&regs->usb.bmcsr, BMCSR_VBUS_OFF);
  108. /* Disable all interrupts */
  109. writel(0x00, &regs->usb.bmier);
  110. writel(0x1f, &regs->usb.bmisr);
  111. }
  112. *ret_hccr = hccr;
  113. *ret_hcor = hcor;
  114. return 0;
  115. }
  116. /*
  117. * Destroy the appropriate control structures corresponding
  118. * the the EHCI host controller.
  119. */
  120. int ehci_hcd_stop(int index)
  121. {
  122. return 0;
  123. }