ohci-sunxi.c 3.3 KB

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