1 // SPDX-License-Identifier: GPL-2.0+
3 * SAMSUNG EXYNOS USB HOST EHCI Controller
5 * Copyright (C) 2012 Samsung Electronics Co.Ltd
6 * Vivek Gautam <gautam.vivek@samsung.com>
13 #include <asm/global_data.h>
14 #include <linux/delay.h>
15 #include <linux/libfdt.h>
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/ehci.h>
20 #include <asm/arch/system.h>
21 #include <asm/arch/power.h>
23 #include <linux/errno.h>
24 #include <linux/compat.h>
27 /* Declare global data pointer */
28 DECLARE_GLOBAL_DATA_PTR;
30 struct exynos_ehci_plat {
31 struct usb_plat usb_plat;
34 struct gpio_desc vbus_gpio;
38 * Contains pointers to register base addresses
39 * for the usb controller.
42 struct ehci_ctrl ctrl;
43 struct exynos_usb_phy *usb;
44 struct ehci_hccr *hcd;
47 static int ehci_usb_of_to_plat(struct udevice *dev)
49 struct exynos_ehci_plat *plat = dev_get_plat(dev);
50 const void *blob = gd->fdt_blob;
55 * Get the base address for XHCI controller from the device node
57 plat->hcd_base = dev_read_addr(dev);
58 if (plat->hcd_base == FDT_ADDR_T_NONE) {
59 debug("Can't get the XHCI register base address\n");
64 node = fdtdec_next_compatible_subnode(blob, dev_of_offset(dev),
65 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
67 debug("XHCI: Can't get device node for usb3-phy controller\n");
72 * Get the base address for usbphy from the device node
74 plat->phy_base = fdtdec_get_addr(blob, node, "reg");
75 if (plat->phy_base == FDT_ADDR_T_NONE) {
76 debug("Can't get the usbphy register address\n");
81 gpio_request_by_name(dev, "samsung,vbus-gpio", 0,
82 &plat->vbus_gpio, GPIOD_IS_OUT);
87 static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
91 clrbits_le32(&usb->usbphyctrl0,
92 HOST_CTRL0_FSEL_MASK |
93 HOST_CTRL0_COMMONON_N |
94 /* HOST Phy setting */
96 HOST_CTRL0_PHYSWRSTALL |
98 HOST_CTRL0_FORCESUSPEND |
99 HOST_CTRL0_FORCESLEEP);
101 setbits_le32(&usb->usbphyctrl0,
102 /* Setting up the ref freq */
104 /* HOST Phy setting */
105 HOST_CTRL0_LINKSWRST |
106 HOST_CTRL0_UTMISWRST);
108 clrbits_le32(&usb->usbphyctrl0,
109 HOST_CTRL0_LINKSWRST |
110 HOST_CTRL0_UTMISWRST);
112 /* HSIC Phy Setting */
113 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
114 HSIC_CTRL_FORCESLEEP |
117 clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
118 clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
120 hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
121 << HSIC_CTRL_REFCLKDIV_SHIFT)
122 | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
123 << HSIC_CTRL_REFCLKSEL_SHIFT)
124 | HSIC_CTRL_UTMISWRST);
126 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
127 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
131 clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
132 HSIC_CTRL_UTMISWRST);
134 clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
135 HSIC_CTRL_UTMISWRST);
139 /* EHCI Ctrl setting */
140 setbits_le32(&usb->ehcictrl,
141 EHCICTRL_ENAINCRXALIGN |
147 static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
149 writel(CLK_24MHZ, &usb->usbphyclk);
151 clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
152 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
153 PHYPWR_NORMAL_MASK_PHY0));
155 setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
157 clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
160 static void setup_usb_phy(struct exynos_usb_phy *usb)
162 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
164 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
166 if (cpu_is_exynos5())
167 exynos5_setup_usb_phy(usb);
168 else if (cpu_is_exynos4())
169 if (proid_is_exynos4412())
170 exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
174 static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
179 setbits_le32(&usb->usbphyctrl0,
180 HOST_CTRL0_PHYSWRST |
181 HOST_CTRL0_PHYSWRSTALL |
183 HOST_CTRL0_FORCESUSPEND |
184 HOST_CTRL0_FORCESLEEP);
187 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
188 HSIC_CTRL_FORCESLEEP |
192 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
193 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
196 static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
198 setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
199 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
200 PHYPWR_NORMAL_MASK_PHY0));
203 /* Reset the EHCI host controller. */
204 static void reset_usb_phy(struct exynos_usb_phy *usb)
206 if (cpu_is_exynos5())
207 exynos5_reset_usb_phy(usb);
208 else if (cpu_is_exynos4())
209 if (proid_is_exynos4412())
210 exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
213 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
216 static int ehci_usb_probe(struct udevice *dev)
218 struct exynos_ehci_plat *plat = dev_get_plat(dev);
219 struct exynos_ehci *ctx = dev_get_priv(dev);
220 struct ehci_hcor *hcor;
222 ctx->hcd = (struct ehci_hccr *)plat->hcd_base;
223 ctx->usb = (struct exynos_usb_phy *)plat->phy_base;
225 /* setup the Vbus gpio here */
226 if (dm_gpio_is_valid(&plat->vbus_gpio))
227 dm_gpio_set_value(&plat->vbus_gpio, 1);
229 setup_usb_phy(ctx->usb);
230 hcor = (struct ehci_hcor *)((uint32_t)ctx->hcd +
231 HC_LENGTH(ehci_readl(&ctx->hcd->cr_capbase)));
233 return ehci_register(dev, ctx->hcd, hcor, NULL, 0, USB_INIT_HOST);
236 static int ehci_usb_remove(struct udevice *dev)
238 struct exynos_ehci *ctx = dev_get_priv(dev);
241 ret = ehci_deregister(dev);
244 reset_usb_phy(ctx->usb);
249 static const struct udevice_id ehci_usb_ids[] = {
250 { .compatible = "samsung,exynos-ehci" },
254 U_BOOT_DRIVER(usb_ehci) = {
255 .name = "ehci_exynos",
257 .of_match = ehci_usb_ids,
258 .of_to_plat = ehci_usb_of_to_plat,
259 .probe = ehci_usb_probe,
260 .remove = ehci_usb_remove,
261 .ops = &ehci_usb_ops,
262 .priv_auto = sizeof(struct exynos_ehci),
263 .plat_auto = sizeof(struct exynos_ehci_plat),
264 .flags = DM_FLAG_ALLOC_PRIV_DMA,