ehci-rmobile.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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[] = {
  15. 0xC6700000
  16. };
  17. #elif defined(CONFIG_R8A7790)
  18. static u32 usb_base_address[] = {
  19. 0xEE080000, /* USB0 (EHCI) */
  20. 0xEE0A0000, /* USB1 */
  21. 0xEE0C0000, /* USB2 */
  22. };
  23. #elif defined(CONFIG_R8A7791) || defined(CONFIG_R8A7793) || \
  24. defined(CONFIG_R8A7794)
  25. static u32 usb_base_address[] = {
  26. 0xEE080000, /* USB0 (EHCI) */
  27. 0xEE0C0000, /* USB1 */
  28. };
  29. #else
  30. #error rmobile EHCI USB driver not supported on this platform
  31. #endif
  32. int ehci_hcd_stop(int index)
  33. {
  34. int i;
  35. u32 base;
  36. struct ahbcom_pci_bridge *ahbcom_pci;
  37. base = usb_base_address[index];
  38. ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  39. writel(0, &ahbcom_pci->ahb_bus_ctr);
  40. /* reset ehci */
  41. setbits_le32(base + EHCI_USBCMD, CMD_RESET);
  42. for (i = 100; i > 0; i--) {
  43. if (!(readl(base + EHCI_USBCMD) & CMD_RESET))
  44. break;
  45. udelay(100);
  46. }
  47. if (!i)
  48. printf("error : ehci(%d) reset failed.\n", index);
  49. if (index == (ARRAY_SIZE(usb_base_address) - 1))
  50. setbits_le32(SMSTPCR7, SMSTPCR703);
  51. return 0;
  52. }
  53. int ehci_hcd_init(int index, enum usb_init_type init,
  54. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  55. {
  56. u32 base;
  57. u32 phys_base;
  58. struct rmobile_ehci_reg *rehci;
  59. struct ahbcom_pci_bridge *ahbcom_pci;
  60. struct ahbconf_pci_bridge *ahbconf_pci;
  61. struct ahb_pciconf *ahb_pciconf_ohci;
  62. struct ahb_pciconf *ahb_pciconf_ehci;
  63. uint32_t cap_base;
  64. base = usb_base_address[index];
  65. phys_base = base;
  66. if (index == 0)
  67. clrbits_le32(SMSTPCR7, SMSTPCR703);
  68. rehci = (struct rmobile_ehci_reg *)(base + EHCI_OFFSET);
  69. ahbcom_pci = (struct ahbcom_pci_bridge *)(base + AHBPCI_OFFSET);
  70. ahbconf_pci =
  71. (struct ahbconf_pci_bridge *)(base + PCI_CONF_AHBPCI_OFFSET);
  72. ahb_pciconf_ohci = (struct ahb_pciconf *)(base + PCI_CONF_OHCI_OFFSET);
  73. ahb_pciconf_ehci = (struct ahb_pciconf *)(base + PCI_CONF_EHCI_OFFSET);
  74. /* Clock & Reset & Direct Power Down */
  75. clrsetbits_le32(&ahbcom_pci->usbctr,
  76. (DIRPD | PCICLK_MASK | USBH_RST), USBCTR_WIN_SIZE_1GB);
  77. clrbits_le32(&ahbcom_pci->usbctr, PLL_RST);
  78. /* AHB-PCI Bridge Communication Registers */
  79. writel(AHB_BUS_CTR_INIT, &ahbcom_pci->ahb_bus_ctr);
  80. writel((CONFIG_SYS_SDRAM_BASE & 0xf0000000) | PCIAHB_WIN_PREFETCH,
  81. &ahbcom_pci->pciahb_win1_ctr);
  82. writel(0xf0000000 | PCIAHB_WIN_PREFETCH,
  83. &ahbcom_pci->pciahb_win2_ctr);
  84. writel(phys_base | PCIWIN2_PCICMD, &ahbcom_pci->ahbpci_win2_ctr);
  85. setbits_le32(&ahbcom_pci->pci_arbiter_ctr,
  86. PCIBP_MODE | PCIREQ1 | PCIREQ0);
  87. /* PCI Configuration Registers for AHBPCI */
  88. writel(PCIWIN1_PCICMD | AHB_CFG_AHBPCI,
  89. &ahbcom_pci->ahbpci_win1_ctr);
  90. writel(phys_base + AHBPCI_OFFSET, &ahbconf_pci->basead);
  91. writel(CONFIG_SYS_SDRAM_BASE & 0xf0000000, &ahbconf_pci->win1_basead);
  92. writel(0xf0000000, &ahbconf_pci->win2_basead);
  93. writel(SERREN | PERREN | MASTEREN | MEMEN,
  94. &ahbconf_pci->cmnd_sts);
  95. /* PCI Configuration Registers for EHCI */
  96. writel(PCIWIN1_PCICMD | AHB_CFG_HOST, &ahbcom_pci->ahbpci_win1_ctr);
  97. writel(phys_base + OHCI_OFFSET, &ahb_pciconf_ohci->basead);
  98. writel(phys_base + EHCI_OFFSET, &ahb_pciconf_ehci->basead);
  99. writel(SERREN | PERREN | MASTEREN | MEMEN,
  100. &ahb_pciconf_ohci->cmnd_sts);
  101. writel(SERREN | PERREN | MASTEREN | MEMEN,
  102. &ahb_pciconf_ehci->cmnd_sts);
  103. /* Enable PCI interrupt */
  104. setbits_le32(&ahbcom_pci->pci_int_enable,
  105. USBH_PMEEN | USBH_INTBEN | USBH_INTAEN);
  106. *hccr = (struct ehci_hccr *)((uint32_t)&rehci->hciversion);
  107. cap_base = ehci_readl(&(*hccr)->cr_capbase);
  108. *hcor = (struct ehci_hcor *)((uint32_t)*hccr + HC_LENGTH(cap_base));
  109. return 0;
  110. }