4 * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
7 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
9 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/clock.h>
14 #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 ohci_sunxi_priv
{
30 int ahb_gate_mask
; /* Mask of ahb_gate0 clk gate bits for this hcd */
31 int usb_gate_mask
; /* Mask of usb_clk_cfg clk gate bits for this hcd */
32 int phy_index
; /* Index of the usb-phy attached to this hcd */
35 static int ohci_usb_probe(struct udevice
*dev
)
37 struct sunxi_ccm_reg
*ccm
= (struct sunxi_ccm_reg
*)SUNXI_CCM_BASE
;
38 struct usb_bus_priv
*bus_priv
= dev_get_uclass_priv(dev
);
39 struct ohci_sunxi_priv
*priv
= dev_get_priv(dev
);
40 struct ohci_regs
*regs
= (struct ohci_regs
*)dev_get_addr(dev
);
42 bus_priv
->companion
= true;
45 * This should go away once we've moved to the driver model for
48 priv
->ahb_gate_mask
= 1 << AHB_GATE_OFFSET_USB_OHCI0
;
49 #ifdef CONFIG_MACH_SUN8I_H3
50 priv
->ahb_gate_mask
|= 1 << AHB_GATE_OFFSET_USB_EHCI0
;
52 priv
->usb_gate_mask
= CCM_USB_CTRL_OHCI0_CLK
;
53 priv
->phy_index
= ((u32
)regs
- (SUNXI_USB1_BASE
+ 0x400)) / BASE_DIST
;
54 priv
->ahb_gate_mask
<<= priv
->phy_index
* AHB_CLK_DIST
;
55 priv
->usb_gate_mask
<<= priv
->phy_index
;
56 priv
->phy_index
++; /* Non otg phys start at 1 */
58 setbits_le32(&ccm
->ahb_gate0
, priv
->ahb_gate_mask
);
59 setbits_le32(&ccm
->usb_clk_cfg
, priv
->usb_gate_mask
);
60 #ifdef CONFIG_SUNXI_GEN_SUN6I
61 setbits_le32(&ccm
->ahb_reset0_cfg
, priv
->ahb_gate_mask
);
64 sunxi_usb_phy_init(priv
->phy_index
);
65 sunxi_usb_phy_power_on(priv
->phy_index
);
67 return ohci_register(dev
, regs
);
70 static int ohci_usb_remove(struct udevice
*dev
)
72 struct sunxi_ccm_reg
*ccm
= (struct sunxi_ccm_reg
*)SUNXI_CCM_BASE
;
73 struct ohci_sunxi_priv
*priv
= dev_get_priv(dev
);
76 ret
= ohci_deregister(dev
);
80 sunxi_usb_phy_exit(priv
->phy_index
);
82 #ifdef CONFIG_SUNXI_GEN_SUN6I
83 clrbits_le32(&ccm
->ahb_reset0_cfg
, priv
->ahb_gate_mask
);
85 clrbits_le32(&ccm
->usb_clk_cfg
, priv
->usb_gate_mask
);
86 clrbits_le32(&ccm
->ahb_gate0
, priv
->ahb_gate_mask
);
91 static const struct udevice_id ohci_usb_ids
[] = {
92 { .compatible
= "allwinner,sun4i-a10-ohci", },
93 { .compatible
= "allwinner,sun5i-a13-ohci", },
94 { .compatible
= "allwinner,sun6i-a31-ohci", },
95 { .compatible
= "allwinner,sun7i-a20-ohci", },
96 { .compatible
= "allwinner,sun8i-a23-ohci", },
97 { .compatible
= "allwinner,sun8i-h3-ohci", },
98 { .compatible
= "allwinner,sun9i-a80-ohci", },
102 U_BOOT_DRIVER(usb_ohci
) = {
103 .name
= "ohci_sunxi",
105 .of_match
= ohci_usb_ids
,
106 .probe
= ohci_usb_probe
,
107 .remove
= ohci_usb_remove
,
108 .ops
= &ohci_usb_ops
,
109 .platdata_auto_alloc_size
= sizeof(struct usb_platdata
),
110 .priv_auto_alloc_size
= sizeof(struct ohci_sunxi_priv
),
111 .flags
= DM_FLAG_ALLOC_PRIV_DMA
,