ehci-rcar_gen3.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * drivers/usb/host/ehci-rcar_gen3.
  3. * This file is EHCI HCD (Host Controller Driver) for USB.
  4. *
  5. * Copyright (C) 2015-2017 Renesas Electronics Corporation
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <errno.h>
  11. #include <wait_bit.h>
  12. #include <asm/io.h>
  13. #include <usb/ehci-ci.h>
  14. #include "ehci.h"
  15. #define RCAR_GEN3_USB_BASE(n) (0xEE080000 + ((n) * 0x20000))
  16. #define EHCI_USBCMD 0x120
  17. #define CORE_SPD_RSM_TIMSET 0x30c
  18. #define CORE_OC_TIMSET 0x310
  19. /* Register offset */
  20. #define AHB_OFFSET 0x200
  21. #define BASE_HSUSB 0xE6590000
  22. #define REG_LPSTS (BASE_HSUSB + 0x0102) /* 16bit */
  23. #define SUSPM 0x4000
  24. #define SUSPM_NORMAL BIT(14)
  25. #define REG_UGCTRL2 (BASE_HSUSB + 0x0184) /* 32bit */
  26. #define USB0SEL 0x00000030
  27. #define USB0SEL_EHCI 0x00000010
  28. #define SMSTPCR7 0xE615014C
  29. #define SMSTPCR700 BIT(0) /* EHCI3 */
  30. #define SMSTPCR701 BIT(1) /* EHCI2 */
  31. #define SMSTPCR702 BIT(2) /* EHCI1 */
  32. #define SMSTPCR703 BIT(3) /* EHCI0 */
  33. #define SMSTPCR704 BIT(4) /* HSUSB */
  34. #define AHB_PLL_RST BIT(1)
  35. #define USBH_INTBEN BIT(2)
  36. #define USBH_INTAEN BIT(1)
  37. #define AHB_INT_ENABLE 0x200
  38. #define AHB_USBCTR 0x20c
  39. int ehci_hcd_stop(int index)
  40. {
  41. #if defined(CONFIG_R8A7795)
  42. const u32 mask = SMSTPCR703 | SMSTPCR702 | SMSTPCR701 | SMSTPCR700;
  43. #else
  44. const u32 mask = SMSTPCR703 | SMSTPCR702;
  45. #endif
  46. const u32 base = RCAR_GEN3_USB_BASE(index);
  47. int ret;
  48. /* Reset EHCI */
  49. setbits_le32((uintptr_t)(base + EHCI_USBCMD), CMD_RESET);
  50. ret = wait_for_bit("ehci-rcar", (void *)(uintptr_t)base + EHCI_USBCMD,
  51. CMD_RESET, false, 10, true);
  52. if (ret) {
  53. printf("ehci-rcar: reset failed (index=%i, ret=%i).\n",
  54. index, ret);
  55. }
  56. setbits_le32(SMSTPCR7, BIT(3 - index));
  57. if ((readl(SMSTPCR7) & mask) == mask)
  58. setbits_le32(SMSTPCR7, SMSTPCR704);
  59. return 0;
  60. }
  61. int ehci_hcd_init(int index, enum usb_init_type init,
  62. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  63. {
  64. const void __iomem *base =
  65. (void __iomem *)(uintptr_t)RCAR_GEN3_USB_BASE(index);
  66. struct usb_ehci *ehci = (struct usb_ehci *)(uintptr_t)base;
  67. clrbits_le32(SMSTPCR7, BIT(3 - index));
  68. clrbits_le32(SMSTPCR7, SMSTPCR704);
  69. *hccr = (struct ehci_hccr *)((uintptr_t)&ehci->caplength);
  70. *hcor = (struct ehci_hcor *)((uintptr_t)*hccr +
  71. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  72. /* Enable interrupt */
  73. setbits_le32(base + AHB_INT_ENABLE, USBH_INTBEN | USBH_INTAEN);
  74. writel(0x014e029b, base + CORE_SPD_RSM_TIMSET);
  75. writel(0x000209ab, base + CORE_OC_TIMSET);
  76. /* Choice USB0SEL */
  77. clrsetbits_le32(REG_UGCTRL2, USB0SEL, USB0SEL_EHCI);
  78. /* Clock & Reset */
  79. clrbits_le32(base + AHB_USBCTR, AHB_PLL_RST);
  80. /* low power status */
  81. clrsetbits_le16(REG_LPSTS, SUSPM, SUSPM_NORMAL);
  82. return 0;
  83. }