ehci-rmobile.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * EHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2013,2014 Renesas Electronics Corporation
  5. * Copyright (C) 2014 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0
  8. */
  9. #include <common.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/ehci-rmobile.h>
  12. #include "ehci.h"
  13. #if defined(CONFIG_R8A7740)
  14. static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  15. 0xC6700000
  16. };
  17. #elif defined(CONFIG_R8A7790)
  18. static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  19. 0xEE080000, /* USB0 (EHCI) */
  20. 0xEE0A0000, /* USB1 */
  21. 0xEE0C0000, /* USB2 */
  22. 0xEE000000 /* USB3 (USB3.0 Host)*/
  23. };
  24. #elif defined(CONFIG_R8A7791)
  25. static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  26. 0xEE080000, /* USB0 (EHCI) */
  27. 0xEE0C0000, /* USB1 */
  28. 0xEE000000 /* USB3 (USB3.0 Host)*/
  29. };
  30. #elif defined(CONFIG_R8A7794)
  31. static u32 usb_base_address[CONFIG_USB_MAX_CONTROLLER_COUNT] = {
  32. 0xEE080000, /* USB0 (EHCI) */
  33. 0xEE0C0000, /* USB1 */
  34. /* R8A7794 does not have USB 3.0. */
  35. };
  36. #else
  37. #error rmobile EHCI USB driver not supported on this platform
  38. #endif
  39. int ehci_hcd_stop(int index)
  40. {
  41. int i;
  42. u32 base;
  43. struct ahbcom_pci_bridge *ahbcom_pci;
  44. base = usb_base_address[index];
  45. ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  46. writel(0, &ahbcom_pci->ahb_bus_ctr);
  47. /* reset ehci */
  48. setbits_le32(base + EHCI_USBCMD, CMD_RESET);
  49. for (i = 100; i > 0; i--) {
  50. if (!(readl(base + EHCI_USBCMD) & CMD_RESET))
  51. break;
  52. udelay(100);
  53. }
  54. if (!i)
  55. printf("error : ehci(%d) reset failed.\n", index);
  56. if (index == (CONFIG_USB_MAX_CONTROLLER_COUNT - 1))
  57. setbits_le32(SMSTPCR7, SMSTPCR703);
  58. return 0;
  59. }
  60. int ehci_hcd_init(int index, enum usb_init_type init,
  61. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  62. {
  63. u32 base;
  64. u32 phys_base;
  65. struct rmobile_ehci_reg *rehci;
  66. struct ahbcom_pci_bridge *ahbcom_pci;
  67. struct ahbconf_pci_bridge *ahbconf_pci;
  68. struct ahb_pciconf *ahb_pciconf_ohci;
  69. struct ahb_pciconf *ahb_pciconf_ehci;
  70. uint32_t cap_base;
  71. base = usb_base_address[index];
  72. phys_base = base;
  73. if (index == 0)
  74. clrbits_le32(SMSTPCR7, SMSTPCR703);
  75. rehci = (struct rmobile_ehci_reg *)(base + EHCI_OFFSET);
  76. ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  77. ahbconf_pci =
  78. (struct ahbconf_pci_bridge *)(base + PCI_CONF_AHBPCI_OFFSET);
  79. ahb_pciconf_ohci = (struct ahb_pciconf *)(base + PCI_CONF_OHCI_OFFSET);
  80. ahb_pciconf_ehci = (struct ahb_pciconf *)(base + PCI_CONF_EHCI_OFFSET);
  81. /* Clock & Reset & Direct Power Down */
  82. clrsetbits_le32(&ahbcom_pci->usbctr,
  83. (DIRPD | PCICLK_MASK | USBH_RST), USBCTR_WIN_SIZE_1GB);
  84. clrbits_le32(&ahbcom_pci->usbctr, PLL_RST);
  85. /* AHB-PCI Bridge Communication Registers */
  86. writel(AHB_BUS_CTR_INIT, &ahbcom_pci->ahb_bus_ctr);
  87. writel((CONFIG_SYS_SDRAM_BASE & 0xf0000000) | PCIAHB_WIN_PREFETCH,
  88. &ahbcom_pci->pciahb_win1_ctr);
  89. writel(0xf0000000 | PCIAHB_WIN_PREFETCH,
  90. &ahbcom_pci->pciahb_win2_ctr);
  91. writel(phys_base | PCIWIN2_PCICMD, &ahbcom_pci->ahbpci_win2_ctr);
  92. setbits_le32(&ahbcom_pci->pci_arbiter_ctr,
  93. PCIBP_MODE | PCIREQ1 | PCIREQ0);
  94. /* PCI Configuration Registers for AHBPCI */
  95. writel(PCIWIN1_PCICMD | AHB_CFG_AHBPCI,
  96. &ahbcom_pci->ahbpci_win1_ctr);
  97. writel(phys_base + AHBPCI_OFFSET, &ahbconf_pci->basead);
  98. writel(CONFIG_SYS_SDRAM_BASE & 0xf0000000, &ahbconf_pci->win1_basead);
  99. writel(0xf0000000, &ahbconf_pci->win2_basead);
  100. writel(SERREN | PERREN | MASTEREN | MEMEN,
  101. &ahbconf_pci->cmnd_sts);
  102. /* PCI Configuration Registers for EHCI */
  103. writel(PCIWIN1_PCICMD | AHB_CFG_HOST, &ahbcom_pci->ahbpci_win1_ctr);
  104. writel(phys_base + OHCI_OFFSET, &ahb_pciconf_ohci->basead);
  105. writel(phys_base + EHCI_OFFSET, &ahb_pciconf_ehci->basead);
  106. writel(SERREN | PERREN | MASTEREN | MEMEN,
  107. &ahb_pciconf_ohci->cmnd_sts);
  108. writel(SERREN | PERREN | MASTEREN | MEMEN,
  109. &ahb_pciconf_ehci->cmnd_sts);
  110. /* Enable PCI interrupt */
  111. setbits_le32(&ahbcom_pci->pci_int_enable,
  112. USBH_PMEEN | USBH_INTBEN | USBH_INTAEN);
  113. *hccr = (struct ehci_hccr *)((uint32_t)&rehci->hciversion);
  114. cap_base = ehci_readl(&(*hccr)->cr_capbase);
  115. *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(cap_base));
  116. return 0;
  117. }