ehci-marvell.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * (C) Copyright 2009
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <usb.h>
  11. #include "ehci.h"
  12. #include <linux/mbus.h>
  13. #include <asm/arch/cpu.h>
  14. #include <dm.h>
  15. #if defined(CONFIG_KIRKWOOD)
  16. #include <asm/arch/soc.h>
  17. #elif defined(CONFIG_ORION5X)
  18. #include <asm/arch/orion5x.h>
  19. #endif
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #define USB_WINDOW_CTRL(i) (0x320 + ((i) << 4))
  22. #define USB_WINDOW_BASE(i) (0x324 + ((i) << 4))
  23. #define USB_TARGET_DRAM 0x0
  24. /*
  25. * USB 2.0 Bridge Address Decoding registers setup
  26. */
  27. #ifdef CONFIG_DM_USB
  28. struct ehci_mvebu_priv {
  29. struct ehci_ctrl ehci;
  30. fdt_addr_t hcd_base;
  31. };
  32. /*
  33. * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
  34. * to the common mvebu archticture including the mbus setup, this
  35. * will be the only function needed to configure the access windows
  36. */
  37. static void usb_brg_adrdec_setup(u32 base)
  38. {
  39. const struct mbus_dram_target_info *dram;
  40. int i;
  41. dram = mvebu_mbus_dram_info();
  42. for (i = 0; i < 4; i++) {
  43. writel(0, base + USB_WINDOW_CTRL(i));
  44. writel(0, base + USB_WINDOW_BASE(i));
  45. }
  46. for (i = 0; i < dram->num_cs; i++) {
  47. const struct mbus_dram_window *cs = dram->cs + i;
  48. /* Write size, attributes and target id to control register */
  49. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  50. (dram->mbus_dram_target_id << 4) | 1,
  51. base + USB_WINDOW_CTRL(i));
  52. /* Write base address to base register */
  53. writel(cs->base, base + USB_WINDOW_BASE(i));
  54. }
  55. }
  56. static int ehci_mvebu_probe(struct udevice *dev)
  57. {
  58. struct ehci_mvebu_priv *priv = dev_get_priv(dev);
  59. struct ehci_hccr *hccr;
  60. struct ehci_hcor *hcor;
  61. /*
  62. * Get the base address for EHCI controller from the device node
  63. */
  64. priv->hcd_base = dev_get_addr(dev);
  65. if (priv->hcd_base == FDT_ADDR_T_NONE) {
  66. debug("Can't get the EHCI register base address\n");
  67. return -ENXIO;
  68. }
  69. usb_brg_adrdec_setup(priv->hcd_base);
  70. hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100);
  71. hcor = (struct ehci_hcor *)
  72. ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  73. debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
  74. (u32)hccr, (u32)hcor,
  75. (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  76. return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
  77. }
  78. static const struct udevice_id ehci_usb_ids[] = {
  79. { .compatible = "marvell,orion-ehci", },
  80. { }
  81. };
  82. U_BOOT_DRIVER(ehci_mvebu) = {
  83. .name = "ehci_mvebu",
  84. .id = UCLASS_USB,
  85. .of_match = ehci_usb_ids,
  86. .probe = ehci_mvebu_probe,
  87. .remove = ehci_deregister,
  88. .ops = &ehci_usb_ops,
  89. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  90. .priv_auto_alloc_size = sizeof(struct ehci_mvebu_priv),
  91. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  92. };
  93. #else
  94. #define MVUSB_BASE(port) MVUSB0_BASE
  95. static void usb_brg_adrdec_setup(int index)
  96. {
  97. int i;
  98. u32 size, base, attrib;
  99. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  100. /* Enable DRAM bank */
  101. switch (i) {
  102. case 0:
  103. attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
  104. break;
  105. case 1:
  106. attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
  107. break;
  108. case 2:
  109. attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
  110. break;
  111. case 3:
  112. attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
  113. break;
  114. default:
  115. /* invalide bank, disable access */
  116. attrib = 0;
  117. break;
  118. }
  119. size = gd->bd->bi_dram[i].size;
  120. base = gd->bd->bi_dram[i].start;
  121. if ((size) && (attrib))
  122. writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
  123. attrib, MVCPU_WIN_ENABLE),
  124. MVUSB0_BASE + USB_WINDOW_CTRL(i));
  125. else
  126. writel(MVCPU_WIN_DISABLE,
  127. MVUSB0_BASE + USB_WINDOW_CTRL(i));
  128. writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i));
  129. }
  130. }
  131. /*
  132. * Create the appropriate control structures to manage
  133. * a new EHCI host controller.
  134. */
  135. int ehci_hcd_init(int index, enum usb_init_type init,
  136. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  137. {
  138. usb_brg_adrdec_setup(index);
  139. *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100);
  140. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  141. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  142. debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
  143. (uint32_t)*hccr, (uint32_t)*hcor,
  144. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  145. return 0;
  146. }
  147. /*
  148. * Destroy the appropriate control structures corresponding
  149. * the the EHCI host controller.
  150. */
  151. int ehci_hcd_stop(int index)
  152. {
  153. return 0;
  154. }
  155. #endif /* CONFIG_DM_USB */