2 * SAMSUNG EXYNOS USB HOST EHCI Controller
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Vivek Gautam <gautam.vivek@samsung.com>
7 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/ehci.h>
17 #include <asm/arch/system.h>
18 #include <asm/arch/power.h>
20 #include <asm-generic/errno.h>
21 #include <linux/compat.h>
24 /* Declare global data pointer */
25 DECLARE_GLOBAL_DATA_PTR
;
28 * Contains pointers to register base addresses
29 * for the usb controller.
32 struct exynos_usb_phy
*usb
;
33 struct ehci_hccr
*hcd
;
34 struct fdt_gpio_state vbus_gpio
;
37 static struct exynos_ehci exynos
;
39 #ifdef CONFIG_OF_CONTROL
40 static int exynos_usb_parse_dt(const void *blob
, struct exynos_ehci
*exynos
)
46 node
= fdtdec_next_compatible(blob
, 0, COMPAT_SAMSUNG_EXYNOS_EHCI
);
48 debug("EHCI: Can't get device node for ehci\n");
53 * Get the base address for EHCI controller from the device node
55 addr
= fdtdec_get_addr(blob
, node
, "reg");
56 if (addr
== FDT_ADDR_T_NONE
) {
57 debug("Can't get the EHCI register address\n");
61 exynos
->hcd
= (struct ehci_hccr
*)addr
;
64 fdtdec_decode_gpio(blob
, node
, "samsung,vbus-gpio", &exynos
->vbus_gpio
);
67 node
= fdtdec_next_compatible_subnode(blob
, node
,
68 COMPAT_SAMSUNG_EXYNOS_USB_PHY
, &depth
);
70 debug("EHCI: Can't get device node for usb-phy controller\n");
75 * Get the base address for usbphy from the device node
77 exynos
->usb
= (struct exynos_usb_phy
*)fdtdec_get_addr(blob
, node
,
79 if (exynos
->usb
== NULL
) {
80 debug("Can't get the usbphy register address\n");
88 /* Setup the EHCI host controller. */
89 static void setup_usb_phy(struct exynos_usb_phy
*usb
)
93 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN
);
95 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN
);
97 clrbits_le32(&usb
->usbphyctrl0
,
98 HOST_CTRL0_FSEL_MASK
|
99 HOST_CTRL0_COMMONON_N
|
100 /* HOST Phy setting */
101 HOST_CTRL0_PHYSWRST
|
102 HOST_CTRL0_PHYSWRSTALL
|
104 HOST_CTRL0_FORCESUSPEND
|
105 HOST_CTRL0_FORCESLEEP
);
107 setbits_le32(&usb
->usbphyctrl0
,
108 /* Setting up the ref freq */
110 /* HOST Phy setting */
111 HOST_CTRL0_LINKSWRST
|
112 HOST_CTRL0_UTMISWRST
);
114 clrbits_le32(&usb
->usbphyctrl0
,
115 HOST_CTRL0_LINKSWRST
|
116 HOST_CTRL0_UTMISWRST
);
118 /* HSIC Phy Setting */
119 hsic_ctrl
= (HSIC_CTRL_FORCESUSPEND
|
120 HSIC_CTRL_FORCESLEEP
|
123 clrbits_le32(&usb
->hsicphyctrl1
, hsic_ctrl
);
124 clrbits_le32(&usb
->hsicphyctrl2
, hsic_ctrl
);
126 hsic_ctrl
= (((HSIC_CTRL_REFCLKDIV_12
& HSIC_CTRL_REFCLKDIV_MASK
)
127 << HSIC_CTRL_REFCLKDIV_SHIFT
)
128 | ((HSIC_CTRL_REFCLKSEL
& HSIC_CTRL_REFCLKSEL_MASK
)
129 << HSIC_CTRL_REFCLKSEL_SHIFT
)
130 | HSIC_CTRL_UTMISWRST
);
132 setbits_le32(&usb
->hsicphyctrl1
, hsic_ctrl
);
133 setbits_le32(&usb
->hsicphyctrl2
, hsic_ctrl
);
137 clrbits_le32(&usb
->hsicphyctrl1
, HSIC_CTRL_PHYSWRST
|
138 HSIC_CTRL_UTMISWRST
);
140 clrbits_le32(&usb
->hsicphyctrl2
, HSIC_CTRL_PHYSWRST
|
141 HSIC_CTRL_UTMISWRST
);
145 /* EHCI Ctrl setting */
146 setbits_le32(&usb
->ehcictrl
,
147 EHCICTRL_ENAINCRXALIGN
|
153 /* Reset the EHCI host controller. */
154 static void reset_usb_phy(struct exynos_usb_phy
*usb
)
159 setbits_le32(&usb
->usbphyctrl0
,
160 HOST_CTRL0_PHYSWRST
|
161 HOST_CTRL0_PHYSWRSTALL
|
163 HOST_CTRL0_FORCESUSPEND
|
164 HOST_CTRL0_FORCESLEEP
);
167 hsic_ctrl
= (HSIC_CTRL_FORCESUSPEND
|
168 HSIC_CTRL_FORCESLEEP
|
172 setbits_le32(&usb
->hsicphyctrl1
, hsic_ctrl
);
173 setbits_le32(&usb
->hsicphyctrl2
, hsic_ctrl
);
175 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE
);
179 * EHCI-initialization
180 * Create the appropriate control structures to manage
181 * a new EHCI host controller.
183 int ehci_hcd_init(int index
, enum usb_init_type init
,
184 struct ehci_hccr
**hccr
, struct ehci_hcor
**hcor
)
186 struct exynos_ehci
*ctx
= &exynos
;
188 #ifdef CONFIG_OF_CONTROL
189 if (exynos_usb_parse_dt(gd
->fdt_blob
, ctx
)) {
190 debug("Unable to parse device tree for ehci-exynos\n");
194 ctx
->usb
= (struct exynos_usb_phy
*)samsung_get_base_usb_phy();
195 ctx
->hcd
= (struct ehci_hccr
*)samsung_get_base_usb_ehci();
198 #ifdef CONFIG_OF_CONTROL
199 /* setup the Vbus gpio here */
200 if (!fdtdec_setup_gpio(&ctx
->vbus_gpio
))
201 gpio_direction_output(ctx
->vbus_gpio
.gpio
, 1);
204 setup_usb_phy(ctx
->usb
);
206 board_usb_init(index
, init
);
209 *hcor
= (struct ehci_hcor
*)((uint32_t) *hccr
210 + HC_LENGTH(ehci_readl(&(*hccr
)->cr_capbase
)));
212 debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
213 (uint32_t)*hccr
, (uint32_t)*hcor
,
214 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr
)->cr_capbase
)));
220 * Destroy the appropriate control structures corresponding
221 * the EHCI host controller.
223 int ehci_hcd_stop(int index
)
225 struct exynos_ehci
*ctx
= &exynos
;
227 reset_usb_phy(ctx
->usb
);