ehci-marvell.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #define USB2_SBUSCFG_OFF 0x90
  25. #define USB_SBUSCFG_BAWR_OFF 0x6
  26. #define USB_SBUSCFG_BARD_OFF 0x3
  27. #define USB_SBUSCFG_AHBBRST_OFF 0x0
  28. #define USB_SBUSCFG_BAWR_ALIGN_64B 0x4
  29. #define USB_SBUSCFG_BARD_ALIGN_64B 0x4
  30. #define USB_SBUSCFG_AHBBRST_INCR16 0x7
  31. /*
  32. * USB 2.0 Bridge Address Decoding registers setup
  33. */
  34. #ifdef CONFIG_DM_USB
  35. struct ehci_mvebu_priv {
  36. struct ehci_ctrl ehci;
  37. fdt_addr_t hcd_base;
  38. };
  39. /*
  40. * Once all the older Marvell SoC's (Orion, Kirkwood) are converted
  41. * to the common mvebu archticture including the mbus setup, this
  42. * will be the only function needed to configure the access windows
  43. */
  44. static void usb_brg_adrdec_setup(void *base)
  45. {
  46. const struct mbus_dram_target_info *dram;
  47. int i;
  48. dram = mvebu_mbus_dram_info();
  49. for (i = 0; i < 4; i++) {
  50. writel(0, base + USB_WINDOW_CTRL(i));
  51. writel(0, base + USB_WINDOW_BASE(i));
  52. }
  53. for (i = 0; i < dram->num_cs; i++) {
  54. const struct mbus_dram_window *cs = dram->cs + i;
  55. /* Write size, attributes and target id to control register */
  56. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  57. (dram->mbus_dram_target_id << 4) | 1,
  58. base + USB_WINDOW_CTRL(i));
  59. /* Write base address to base register */
  60. writel(cs->base, base + USB_WINDOW_BASE(i));
  61. }
  62. }
  63. static void marvell_ehci_powerup_fixup(struct ehci_ctrl *ctrl,
  64. uint32_t *status_reg, uint32_t *reg)
  65. {
  66. struct ehci_mvebu_priv *priv = ctrl->priv;
  67. /*
  68. * Set default value for reg SBUSCFG, which is Control for the AMBA
  69. * system bus interface:
  70. * BAWR = BARD = 4 : Align rd/wr bursts packets larger than 64 bytes
  71. * AHBBRST = 7 : Align AHB burst for packets larger than 64 bytes
  72. */
  73. writel((USB_SBUSCFG_BAWR_ALIGN_64B << USB_SBUSCFG_BAWR_OFF) |
  74. (USB_SBUSCFG_BARD_ALIGN_64B << USB_SBUSCFG_BARD_OFF) |
  75. (USB_SBUSCFG_AHBBRST_INCR16 << USB_SBUSCFG_AHBBRST_OFF),
  76. priv->hcd_base + USB2_SBUSCFG_OFF);
  77. mdelay(50);
  78. }
  79. static struct ehci_ops marvell_ehci_ops = {
  80. .powerup_fixup = NULL,
  81. };
  82. static int ehci_mvebu_probe(struct udevice *dev)
  83. {
  84. struct ehci_mvebu_priv *priv = dev_get_priv(dev);
  85. struct ehci_hccr *hccr;
  86. struct ehci_hcor *hcor;
  87. /*
  88. * Get the base address for EHCI controller from the device node
  89. */
  90. priv->hcd_base = dev_get_addr(dev);
  91. if (priv->hcd_base == FDT_ADDR_T_NONE) {
  92. debug("Can't get the EHCI register base address\n");
  93. return -ENXIO;
  94. }
  95. /*
  96. * For SoCs without hlock like Armada3700 we need to program the sbuscfg
  97. * reg to guarantee AHB master's burst will not overrun or underrun
  98. * the FIFO. Otherwise all USB2 write option will fail.
  99. * Also, the address decoder doesn't need to get setup with this
  100. * SoC, so don't call usb_brg_adrdec_setup().
  101. */
  102. if (of_device_is_compatible(dev, "marvell,armada3700-ehci"))
  103. marvell_ehci_ops.powerup_fixup = marvell_ehci_powerup_fixup;
  104. else
  105. usb_brg_adrdec_setup((void *)priv->hcd_base);
  106. hccr = (struct ehci_hccr *)(priv->hcd_base + 0x100);
  107. hcor = (struct ehci_hcor *)
  108. ((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  109. debug("ehci-marvell: init hccr %lx and hcor %lx hc_length %ld\n",
  110. (uintptr_t)hccr, (uintptr_t)hcor,
  111. (uintptr_t)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  112. return ehci_register(dev, hccr, hcor, &marvell_ehci_ops, 0,
  113. USB_INIT_HOST);
  114. }
  115. static const struct udevice_id ehci_usb_ids[] = {
  116. { .compatible = "marvell,orion-ehci", },
  117. { .compatible = "marvell,armada3700-ehci", },
  118. { }
  119. };
  120. U_BOOT_DRIVER(ehci_mvebu) = {
  121. .name = "ehci_mvebu",
  122. .id = UCLASS_USB,
  123. .of_match = ehci_usb_ids,
  124. .probe = ehci_mvebu_probe,
  125. .remove = ehci_deregister,
  126. .ops = &ehci_usb_ops,
  127. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  128. .priv_auto_alloc_size = sizeof(struct ehci_mvebu_priv),
  129. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  130. };
  131. #else
  132. #define MVUSB_BASE(port) MVUSB0_BASE
  133. static void usb_brg_adrdec_setup(int index)
  134. {
  135. int i;
  136. u32 size, base, attrib;
  137. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  138. /* Enable DRAM bank */
  139. switch (i) {
  140. case 0:
  141. attrib = MVUSB0_CPU_ATTR_DRAM_CS0;
  142. break;
  143. case 1:
  144. attrib = MVUSB0_CPU_ATTR_DRAM_CS1;
  145. break;
  146. case 2:
  147. attrib = MVUSB0_CPU_ATTR_DRAM_CS2;
  148. break;
  149. case 3:
  150. attrib = MVUSB0_CPU_ATTR_DRAM_CS3;
  151. break;
  152. default:
  153. /* invalide bank, disable access */
  154. attrib = 0;
  155. break;
  156. }
  157. size = gd->bd->bi_dram[i].size;
  158. base = gd->bd->bi_dram[i].start;
  159. if ((size) && (attrib))
  160. writel(MVCPU_WIN_CTRL_DATA(size, USB_TARGET_DRAM,
  161. attrib, MVCPU_WIN_ENABLE),
  162. MVUSB0_BASE + USB_WINDOW_CTRL(i));
  163. else
  164. writel(MVCPU_WIN_DISABLE,
  165. MVUSB0_BASE + USB_WINDOW_CTRL(i));
  166. writel(base, MVUSB0_BASE + USB_WINDOW_BASE(i));
  167. }
  168. }
  169. /*
  170. * Create the appropriate control structures to manage
  171. * a new EHCI host controller.
  172. */
  173. int ehci_hcd_init(int index, enum usb_init_type init,
  174. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  175. {
  176. usb_brg_adrdec_setup(index);
  177. *hccr = (struct ehci_hccr *)(MVUSB_BASE(index) + 0x100);
  178. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  179. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  180. debug("ehci-marvell: init hccr %x and hcor %x hc_length %d\n",
  181. (uint32_t)*hccr, (uint32_t)*hcor,
  182. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  183. return 0;
  184. }
  185. /*
  186. * Destroy the appropriate control structures corresponding
  187. * the the EHCI host controller.
  188. */
  189. int ehci_hcd_stop(int index)
  190. {
  191. return 0;
  192. }
  193. #endif /* CONFIG_DM_USB */