blob: fabc662eb610b4acc83b838b0ee9dc9f0831be7b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05302/*
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +05303 * SAMSUNG EXYNOS USB HOST EHCI Controller
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05304 *
5 * Copyright (C) 2012 Samsung Electronics Co.Ltd
6 * Vivek Gautam <gautam.vivek@samsung.com>
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05307 */
8
9#include <common.h>
Simon Glassaae04d02015-03-25 12:22:44 -060010#include <dm.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000011#include <fdtdec.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090012#include <linux/libfdt.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000013#include <malloc.h>
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053014#include <usb.h>
15#include <asm/arch/cpu.h>
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +053016#include <asm/arch/ehci.h>
Rajeshwari Shinde71045da2012-05-14 05:52:02 +000017#include <asm/arch/system.h>
Rajeshwari Shindec48ac112012-05-14 05:52:03 +000018#include <asm/arch/power.h>
Julius Werner4a271cb2013-09-14 14:02:52 +053019#include <asm/gpio.h>
Masahiro Yamada5d97dff2016-09-21 11:28:57 +090020#include <linux/errno.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000021#include <linux/compat.h>
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053022#include "ehci.h"
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053023
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000024/* Declare global data pointer */
25DECLARE_GLOBAL_DATA_PTR;
26
Simon Glassaae04d02015-03-25 12:22:44 -060027struct exynos_ehci_platdata {
28 struct usb_platdata usb_plat;
29 fdt_addr_t hcd_base;
30 fdt_addr_t phy_base;
31 struct gpio_desc vbus_gpio;
32};
Simon Glassaae04d02015-03-25 12:22:44 -060033
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000034/**
35 * Contains pointers to register base addresses
36 * for the usb controller.
37 */
38struct exynos_ehci {
Simon Glassaae04d02015-03-25 12:22:44 -060039 struct ehci_ctrl ctrl;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000040 struct exynos_usb_phy *usb;
Vivek Gautam24a47752013-03-06 14:18:32 +053041 struct ehci_hccr *hcd;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000042};
43
Simon Glassaae04d02015-03-25 12:22:44 -060044static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
45{
46 struct exynos_ehci_platdata *plat = dev_get_platdata(dev);
47 const void *blob = gd->fdt_blob;
48 unsigned int node;
49 int depth;
50
51 /*
52 * Get the base address for XHCI controller from the device node
53 */
Simon Glassa821c4a2017-05-17 17:18:05 -060054 plat->hcd_base = devfdt_get_addr(dev);
Simon Glassaae04d02015-03-25 12:22:44 -060055 if (plat->hcd_base == FDT_ADDR_T_NONE) {
56 debug("Can't get the XHCI register base address\n");
57 return -ENXIO;
58 }
59
60 depth = 0;
Simon Glasse160f7d2017-01-17 16:52:55 -070061 node = fdtdec_next_compatible_subnode(blob, dev_of_offset(dev),
Simon Glassaae04d02015-03-25 12:22:44 -060062 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
63 if (node <= 0) {
64 debug("XHCI: Can't get device node for usb3-phy controller\n");
65 return -ENODEV;
66 }
67
68 /*
69 * Get the base address for usbphy from the device node
70 */
71 plat->phy_base = fdtdec_get_addr(blob, node, "reg");
72 if (plat->phy_base == FDT_ADDR_T_NONE) {
73 debug("Can't get the usbphy register address\n");
74 return -ENXIO;
75 }
76
77 /* Vbus gpio */
78 gpio_request_by_name(dev, "samsung,vbus-gpio", 0,
79 &plat->vbus_gpio, GPIOD_IS_OUT);
80
81 return 0;
82}
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000083
Suriyan Ramasami6a23c652014-10-29 09:22:43 -070084static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053085{
Inderpal Singh16f94802014-01-08 09:19:56 +053086 u32 hsic_ctrl;
87
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053088 clrbits_le32(&usb->usbphyctrl0,
89 HOST_CTRL0_FSEL_MASK |
90 HOST_CTRL0_COMMONON_N |
91 /* HOST Phy setting */
92 HOST_CTRL0_PHYSWRST |
93 HOST_CTRL0_PHYSWRSTALL |
94 HOST_CTRL0_SIDDQ |
95 HOST_CTRL0_FORCESUSPEND |
96 HOST_CTRL0_FORCESLEEP);
97
98 setbits_le32(&usb->usbphyctrl0,
99 /* Setting up the ref freq */
100 (CLK_24MHZ << 16) |
101 /* HOST Phy setting */
102 HOST_CTRL0_LINKSWRST |
103 HOST_CTRL0_UTMISWRST);
104 udelay(10);
105 clrbits_le32(&usb->usbphyctrl0,
106 HOST_CTRL0_LINKSWRST |
107 HOST_CTRL0_UTMISWRST);
Inderpal Singh16f94802014-01-08 09:19:56 +0530108
109 /* HSIC Phy Setting */
110 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
111 HSIC_CTRL_FORCESLEEP |
112 HSIC_CTRL_SIDDQ);
113
114 clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
115 clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
116
117 hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
118 << HSIC_CTRL_REFCLKDIV_SHIFT)
119 | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
120 << HSIC_CTRL_REFCLKSEL_SHIFT)
121 | HSIC_CTRL_UTMISWRST);
122
123 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
124 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
125
126 udelay(10);
127
128 clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
129 HSIC_CTRL_UTMISWRST);
130
131 clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
132 HSIC_CTRL_UTMISWRST);
133
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530134 udelay(20);
135
136 /* EHCI Ctrl setting */
137 setbits_le32(&usb->ehcictrl,
138 EHCICTRL_ENAINCRXALIGN |
139 EHCICTRL_ENAINCR4 |
140 EHCICTRL_ENAINCR8 |
141 EHCICTRL_ENAINCR16);
142}
143
Suriyan Ramasami6a23c652014-10-29 09:22:43 -0700144static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
145{
146 writel(CLK_24MHZ, &usb->usbphyclk);
147
148 clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
149 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
150 PHYPWR_NORMAL_MASK_PHY0));
151
152 setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
153 udelay(10);
154 clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
155}
156
157static void setup_usb_phy(struct exynos_usb_phy *usb)
158{
159 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
160
161 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
162
163 if (cpu_is_exynos5())
164 exynos5_setup_usb_phy(usb);
165 else if (cpu_is_exynos4())
166 if (proid_is_exynos4412())
167 exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
168 usb);
169}
170
171static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530172{
Inderpal Singh16f94802014-01-08 09:19:56 +0530173 u32 hsic_ctrl;
174
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530175 /* HOST_PHY reset */
176 setbits_le32(&usb->usbphyctrl0,
177 HOST_CTRL0_PHYSWRST |
178 HOST_CTRL0_PHYSWRSTALL |
179 HOST_CTRL0_SIDDQ |
180 HOST_CTRL0_FORCESUSPEND |
181 HOST_CTRL0_FORCESLEEP);
Rajeshwari Shindec48ac112012-05-14 05:52:03 +0000182
Inderpal Singh16f94802014-01-08 09:19:56 +0530183 /* HSIC Phy reset */
184 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
185 HSIC_CTRL_FORCESLEEP |
186 HSIC_CTRL_SIDDQ |
187 HSIC_CTRL_PHYSWRST);
188
189 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
190 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
Suriyan Ramasami6a23c652014-10-29 09:22:43 -0700191}
192
193static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
194{
195 setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
196 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
197 PHYPWR_NORMAL_MASK_PHY0));
198}
199
200/* Reset the EHCI host controller. */
201static void reset_usb_phy(struct exynos_usb_phy *usb)
202{
203 if (cpu_is_exynos5())
204 exynos5_reset_usb_phy(usb);
205 else if (cpu_is_exynos4())
206 if (proid_is_exynos4412())
207 exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
208 usb);
Inderpal Singh16f94802014-01-08 09:19:56 +0530209
Rajeshwari Shindec48ac112012-05-14 05:52:03 +0000210 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530211}
212
Simon Glassaae04d02015-03-25 12:22:44 -0600213static int ehci_usb_probe(struct udevice *dev)
214{
215 struct exynos_ehci_platdata *plat = dev_get_platdata(dev);
216 struct exynos_ehci *ctx = dev_get_priv(dev);
217 struct ehci_hcor *hcor;
218
219 ctx->hcd = (struct ehci_hccr *)plat->hcd_base;
220 ctx->usb = (struct exynos_usb_phy *)plat->phy_base;
Simon Glassaae04d02015-03-25 12:22:44 -0600221
222 /* setup the Vbus gpio here */
223 if (dm_gpio_is_valid(&plat->vbus_gpio))
224 dm_gpio_set_value(&plat->vbus_gpio, 1);
225
226 setup_usb_phy(ctx->usb);
Lukasz Majewski70cc4432015-12-10 16:32:25 +0100227 hcor = (struct ehci_hcor *)((uint32_t)ctx->hcd +
228 HC_LENGTH(ehci_readl(&ctx->hcd->cr_capbase)));
Simon Glassaae04d02015-03-25 12:22:44 -0600229
230 return ehci_register(dev, ctx->hcd, hcor, NULL, 0, USB_INIT_HOST);
231}
232
233static int ehci_usb_remove(struct udevice *dev)
234{
235 struct exynos_ehci *ctx = dev_get_priv(dev);
236 int ret;
237
238 ret = ehci_deregister(dev);
239 if (ret)
240 return ret;
241 reset_usb_phy(ctx->usb);
242
243 return 0;
244}
245
246static const struct udevice_id ehci_usb_ids[] = {
247 { .compatible = "samsung,exynos-ehci" },
248 { }
249};
250
251U_BOOT_DRIVER(usb_ehci) = {
252 .name = "ehci_exynos",
253 .id = UCLASS_USB,
254 .of_match = ehci_usb_ids,
255 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
256 .probe = ehci_usb_probe,
257 .remove = ehci_usb_remove,
258 .ops = &ehci_usb_ops,
259 .priv_auto_alloc_size = sizeof(struct exynos_ehci),
260 .platdata_auto_alloc_size = sizeof(struct exynos_ehci_platdata),
261 .flags = DM_FLAG_ALLOC_PRIV_DMA,
262};