ohci-sunxi.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Sunxi ohci glue
  3. *
  4. * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
  5. *
  6. * Based on code from
  7. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/arch/usb_phy.h>
  14. #include <asm/io.h>
  15. #include <dm.h>
  16. #include <usb.h>
  17. #include "ohci.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 ohci_sunxi_priv {
  26. ohci_t ohci;
  27. int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
  28. int usb_gate_mask; /* Mask of usb_clk_cfg clk gate bits for this hcd */
  29. int phy_index; /* Index of the usb-phy attached to this hcd */
  30. };
  31. static int ohci_usb_probe(struct udevice *dev)
  32. {
  33. struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  34. struct usb_bus_priv *bus_priv = dev_get_uclass_priv(dev);
  35. struct ohci_sunxi_priv *priv = dev_get_priv(dev);
  36. struct ohci_regs *regs = (struct ohci_regs *)dev_get_addr(dev);
  37. int extra_ahb_gate_mask = 0;
  38. bus_priv->companion = true;
  39. /*
  40. * This should go away once we've moved to the driver model for
  41. * clocks resp. phys.
  42. */
  43. priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
  44. #ifdef CONFIG_MACH_SUN8I_H3
  45. extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
  46. #endif
  47. priv->usb_gate_mask = CCM_USB_CTRL_OHCI0_CLK;
  48. priv->phy_index = ((uintptr_t)regs - (SUNXI_USB1_BASE + 0x400)) / BASE_DIST;
  49. priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
  50. extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
  51. priv->usb_gate_mask <<= priv->phy_index;
  52. priv->phy_index++; /* Non otg phys start at 1 */
  53. setbits_le32(&ccm->ahb_gate0,
  54. priv->ahb_gate_mask | extra_ahb_gate_mask);
  55. setbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
  56. #ifdef CONFIG_SUNXI_GEN_SUN6I
  57. setbits_le32(&ccm->ahb_reset0_cfg,
  58. priv->ahb_gate_mask | extra_ahb_gate_mask);
  59. #endif
  60. sunxi_usb_phy_init(priv->phy_index);
  61. sunxi_usb_phy_power_on(priv->phy_index);
  62. return ohci_register(dev, regs);
  63. }
  64. static int ohci_usb_remove(struct udevice *dev)
  65. {
  66. struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
  67. struct ohci_sunxi_priv *priv = dev_get_priv(dev);
  68. int ret;
  69. ret = ohci_deregister(dev);
  70. if (ret)
  71. return ret;
  72. sunxi_usb_phy_exit(priv->phy_index);
  73. #ifdef CONFIG_SUNXI_GEN_SUN6I
  74. clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
  75. #endif
  76. clrbits_le32(&ccm->usb_clk_cfg, priv->usb_gate_mask);
  77. clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
  78. return 0;
  79. }
  80. static const struct udevice_id ohci_usb_ids[] = {
  81. { .compatible = "allwinner,sun4i-a10-ohci", },
  82. { .compatible = "allwinner,sun5i-a13-ohci", },
  83. { .compatible = "allwinner,sun6i-a31-ohci", },
  84. { .compatible = "allwinner,sun7i-a20-ohci", },
  85. { .compatible = "allwinner,sun8i-a23-ohci", },
  86. { .compatible = "allwinner,sun8i-a83t-ohci", },
  87. { .compatible = "allwinner,sun8i-h3-ohci", },
  88. { .compatible = "allwinner,sun9i-a80-ohci", },
  89. { .compatible = "allwinner,sun50i-a64-ohci", },
  90. { }
  91. };
  92. U_BOOT_DRIVER(usb_ohci) = {
  93. .name = "ohci_sunxi",
  94. .id = UCLASS_USB,
  95. .of_match = ohci_usb_ids,
  96. .probe = ohci_usb_probe,
  97. .remove = ohci_usb_remove,
  98. .ops = &ohci_usb_ops,
  99. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  100. .priv_auto_alloc_size = sizeof(struct ohci_sunxi_priv),
  101. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  102. };