8 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
10 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/arch/clock.h>
15 #include <asm/arch/usb_phy.h>
20 #ifdef CONFIG_SUNXI_GEN_SUN4I
21 #define BASE_DIST 0x8000
22 #define AHB_CLK_DIST 2
24 #define BASE_DIST 0x1000
25 #define AHB_CLK_DIST 1
28 struct ehci_sunxi_priv {
29 struct ehci_ctrl ehci;
30 int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
31 int phy_index; /* Index of the usb-phy attached to this hcd */
34 static int ehci_usb_probe(struct udevice *dev)
36 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
37 struct usb_platdata *plat = dev_get_platdata(dev);
38 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
39 struct ehci_hccr *hccr = (struct ehci_hccr *)devfdt_get_addr(dev);
40 struct ehci_hcor *hcor;
41 int extra_ahb_gate_mask = 0;
44 * This should go away once we've moved to the driver model for
47 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
48 #if defined(CONFIG_MACH_SUNXI_H3_H5) || defined(CONFIG_MACH_SUN50I)
49 extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
51 priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
52 priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
53 extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
54 priv->phy_index++; /* Non otg phys start at 1 */
56 setbits_le32(&ccm->ahb_gate0,
57 priv->ahb_gate_mask | extra_ahb_gate_mask);
58 #ifdef CONFIG_SUNXI_GEN_SUN6I
59 setbits_le32(&ccm->ahb_reset0_cfg,
60 priv->ahb_gate_mask | extra_ahb_gate_mask);
63 sunxi_usb_phy_init(priv->phy_index);
64 sunxi_usb_phy_power_on(priv->phy_index);
66 hcor = (struct ehci_hcor *)((uintptr_t)hccr +
67 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
69 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
72 static int ehci_usb_remove(struct udevice *dev)
74 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
75 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
78 ret = ehci_deregister(dev);
82 sunxi_usb_phy_exit(priv->phy_index);
84 #ifdef CONFIG_SUNXI_GEN_SUN6I
85 clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
87 clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
92 static const struct udevice_id ehci_usb_ids[] = {
93 { .compatible = "allwinner,sun4i-a10-ehci", },
94 { .compatible = "allwinner,sun5i-a13-ehci", },
95 { .compatible = "allwinner,sun6i-a31-ehci", },
96 { .compatible = "allwinner,sun7i-a20-ehci", },
97 { .compatible = "allwinner,sun8i-a23-ehci", },
98 { .compatible = "allwinner,sun8i-a83t-ehci", },
99 { .compatible = "allwinner,sun8i-h3-ehci", },
100 { .compatible = "allwinner,sun9i-a80-ehci", },
101 { .compatible = "allwinner,sun50i-a64-ehci", },
105 U_BOOT_DRIVER(ehci_sunxi) = {
106 .name = "ehci_sunxi",
108 .of_match = ehci_usb_ids,
109 .probe = ehci_usb_probe,
110 .remove = ehci_usb_remove,
111 .ops = &ehci_usb_ops,
112 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
113 .priv_auto_alloc_size = sizeof(struct ehci_sunxi_priv),
114 .flags = DM_FLAG_ALLOC_PRIV_DMA,