ehci-rmobile.c 4.0 KB

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