ehci-faraday.c 3.5 KB

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