ehci-sunxi.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Sunxi ehci glue
  3. *
  4. * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
  5. * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com>
  6. *
  7. * Based on code from
  8. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/usb_phy.h>
  15. #include <asm/io.h>
  16. #include <dm.h>
  17. #include "ehci.h"
  18. #ifdef CONFIG_SUNXI_GEN_SUN4I
  19. #define BASE_DIST 0x8000
  20. #define AHB_CLK_DIST 2
  21. #else
  22. #define BASE_DIST 0x1000
  23. #define AHB_CLK_DIST 1
  24. #endif
  25. struct ehci_sunxi_priv {
  26. struct ehci_ctrl ehci;
  27. int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
  28. int phy_index; /* Index of the usb-phy attached to this hcd */
  29. };
  30. static int ehci_usb_probe(struct udevice *dev)
  31. {
  32. struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  33. struct usb_platdata *plat = dev_get_platdata(dev);
  34. struct ehci_sunxi_priv *priv = dev_get_priv(dev);
  35. struct ehci_hccr *hccr = (struct ehci_hccr *)dev_get_addr(dev);
  36. struct ehci_hcor *hcor;
  37. int extra_ahb_gate_mask = 0;
  38. /*
  39. * This should go away once we've moved to the driver model for
  40. * clocks resp. phys.
  41. */
  42. priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
  43. #if defined(CONFIG_MACH_SUN8I_H3) || defined(CONFIG_MACH_SUN50I)
  44. extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
  45. #endif
  46. priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
  47. priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
  48. extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
  49. priv->phy_index++; /* Non otg phys start at 1 */
  50. setbits_le32(&ccm->ahb_gate0,
  51. priv->ahb_gate_mask | extra_ahb_gate_mask);
  52. #ifdef CONFIG_SUNXI_GEN_SUN6I
  53. setbits_le32(&ccm->ahb_reset0_cfg,
  54. priv->ahb_gate_mask | extra_ahb_gate_mask);
  55. #endif
  56. sunxi_usb_phy_init(priv->phy_index);
  57. sunxi_usb_phy_power_on(priv->phy_index);
  58. hcor = (struct ehci_hcor *)((uintptr_t)hccr +
  59. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  60. return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
  61. }
  62. static int ehci_usb_remove(struct udevice *dev)
  63. {
  64. struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  65. struct ehci_sunxi_priv *priv = dev_get_priv(dev);
  66. int ret;
  67. ret = ehci_deregister(dev);
  68. if (ret)
  69. return ret;
  70. sunxi_usb_phy_exit(priv->phy_index);
  71. #ifdef CONFIG_SUNXI_GEN_SUN6I
  72. clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
  73. #endif
  74. clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
  75. return 0;
  76. }
  77. static const struct udevice_id ehci_usb_ids[] = {
  78. { .compatible = "allwinner,sun4i-a10-ehci", },
  79. { .compatible = "allwinner,sun5i-a13-ehci", },
  80. { .compatible = "allwinner,sun6i-a31-ehci", },
  81. { .compatible = "allwinner,sun7i-a20-ehci", },
  82. { .compatible = "allwinner,sun8i-a23-ehci", },
  83. { .compatible = "allwinner,sun8i-a83t-ehci", },
  84. { .compatible = "allwinner,sun8i-h3-ehci", },
  85. { .compatible = "allwinner,sun9i-a80-ehci", },
  86. { .compatible = "allwinner,sun50i-a64-ehci", },
  87. { }
  88. };
  89. U_BOOT_DRIVER(ehci_sunxi) = {
  90. .name = "ehci_sunxi",
  91. .id = UCLASS_USB,
  92. .of_match = ehci_usb_ids,
  93. .probe = ehci_usb_probe,
  94. .remove = ehci_usb_remove,
  95. .ops = &ehci_usb_ops,
  96. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  97. .priv_auto_alloc_size = sizeof(struct ehci_sunxi_priv),
  98. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  99. };