blob: c1cdd4b0889aead5fad8c4e19f5a4c21bf2c3ce6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05302/*
Rajeshwari Shindedad39d42012-05-21 16:38:03 +05303 * SAMSUNG EXYNOS USB HOST EHCI Controller
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05304 *
5 * Copyright (C) 2012 Samsung Electronics Co.Ltd
6 * Vivek Gautam <gautam.vivek@samsung.com>
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05307 */
8
9#include <common.h>
Simon Glass2b8ceec2015-03-25 12:22:44 -060010#include <dm.h>
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000011#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000016#include <malloc.h>
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053017#include <usb.h>
18#include <asm/arch/cpu.h>
Rajeshwari Shindedad39d42012-05-21 16:38:03 +053019#include <asm/arch/ehci.h>
Rajeshwari Shinde84448072012-05-14 05:52:02 +000020#include <asm/arch/system.h>
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +000021#include <asm/arch/power.h>
Julius Wernerddcb9bd2013-09-14 14:02:52 +053022#include <asm/gpio.h>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090023#include <linux/errno.h>
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000024#include <linux/compat.h>
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053025#include "ehci.h"
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053026
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000027/* Declare global data pointer */
28DECLARE_GLOBAL_DATA_PTR;
29
Simon Glassb75b15b2020-12-03 16:55:23 -070030struct exynos_ehci_plat {
31 struct usb_plat usb_plat;
Simon Glass2b8ceec2015-03-25 12:22:44 -060032 fdt_addr_t hcd_base;
33 fdt_addr_t phy_base;
34 struct gpio_desc vbus_gpio;
35};
Simon Glass2b8ceec2015-03-25 12:22:44 -060036
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000037/**
38 * Contains pointers to register base addresses
39 * for the usb controller.
40 */
41struct exynos_ehci {
Simon Glass2b8ceec2015-03-25 12:22:44 -060042 struct ehci_ctrl ctrl;
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000043 struct exynos_usb_phy *usb;
Vivek Gautambab686c2013-03-06 14:18:32 +053044 struct ehci_hccr *hcd;
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000045};
46
Simon Glassaad29ae2020-12-03 16:55:21 -070047static int ehci_usb_of_to_plat(struct udevice *dev)
Simon Glass2b8ceec2015-03-25 12:22:44 -060048{
Simon Glassb75b15b2020-12-03 16:55:23 -070049 struct exynos_ehci_plat *plat = dev_get_plat(dev);
Simon Glass2b8ceec2015-03-25 12:22:44 -060050 const void *blob = gd->fdt_blob;
51 unsigned int node;
52 int depth;
53
54 /*
55 * Get the base address for XHCI controller from the device node
56 */
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +090057 plat->hcd_base = dev_read_addr(dev);
Simon Glass2b8ceec2015-03-25 12:22:44 -060058 if (plat->hcd_base == FDT_ADDR_T_NONE) {
59 debug("Can't get the XHCI register base address\n");
60 return -ENXIO;
61 }
62
63 depth = 0;
Simon Glassdd79d6e2017-01-17 16:52:55 -070064 node = fdtdec_next_compatible_subnode(blob, dev_of_offset(dev),
Simon Glass2b8ceec2015-03-25 12:22:44 -060065 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
66 if (node <= 0) {
67 debug("XHCI: Can't get device node for usb3-phy controller\n");
68 return -ENODEV;
69 }
70
71 /*
72 * Get the base address for usbphy from the device node
73 */
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");
77 return -ENXIO;
78 }
79
80 /* Vbus gpio */
81 gpio_request_by_name(dev, "samsung,vbus-gpio", 0,
82 &plat->vbus_gpio, GPIOD_IS_OUT);
83
84 return 0;
85}
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000086
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -070087static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053088{
Inderpal Singh2eb65612014-01-08 09:19:56 +053089 u32 hsic_ctrl;
90
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053091 clrbits_le32(&usb->usbphyctrl0,
92 HOST_CTRL0_FSEL_MASK |
93 HOST_CTRL0_COMMONON_N |
94 /* HOST Phy setting */
95 HOST_CTRL0_PHYSWRST |
96 HOST_CTRL0_PHYSWRSTALL |
97 HOST_CTRL0_SIDDQ |
98 HOST_CTRL0_FORCESUSPEND |
99 HOST_CTRL0_FORCESLEEP);
100
101 setbits_le32(&usb->usbphyctrl0,
102 /* Setting up the ref freq */
103 (CLK_24MHZ << 16) |
104 /* HOST Phy setting */
105 HOST_CTRL0_LINKSWRST |
106 HOST_CTRL0_UTMISWRST);
107 udelay(10);
108 clrbits_le32(&usb->usbphyctrl0,
109 HOST_CTRL0_LINKSWRST |
110 HOST_CTRL0_UTMISWRST);
Inderpal Singh2eb65612014-01-08 09:19:56 +0530111
112 /* HSIC Phy Setting */
113 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
114 HSIC_CTRL_FORCESLEEP |
115 HSIC_CTRL_SIDDQ);
116
117 clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
118 clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
119
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);
125
126 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
127 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
128
129 udelay(10);
130
131 clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
132 HSIC_CTRL_UTMISWRST);
133
134 clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
135 HSIC_CTRL_UTMISWRST);
136
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530137 udelay(20);
138
139 /* EHCI Ctrl setting */
140 setbits_le32(&usb->ehcictrl,
141 EHCICTRL_ENAINCRXALIGN |
142 EHCICTRL_ENAINCR4 |
143 EHCICTRL_ENAINCR8 |
144 EHCICTRL_ENAINCR16);
145}
146
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -0700147static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
148{
149 writel(CLK_24MHZ, &usb->usbphyclk);
150
151 clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
152 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
153 PHYPWR_NORMAL_MASK_PHY0));
154
155 setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
156 udelay(10);
157 clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
158}
159
160static void setup_usb_phy(struct exynos_usb_phy *usb)
161{
162 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
163
164 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
165
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 *)
171 usb);
172}
173
174static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530175{
Inderpal Singh2eb65612014-01-08 09:19:56 +0530176 u32 hsic_ctrl;
177
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530178 /* HOST_PHY reset */
179 setbits_le32(&usb->usbphyctrl0,
180 HOST_CTRL0_PHYSWRST |
181 HOST_CTRL0_PHYSWRSTALL |
182 HOST_CTRL0_SIDDQ |
183 HOST_CTRL0_FORCESUSPEND |
184 HOST_CTRL0_FORCESLEEP);
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +0000185
Inderpal Singh2eb65612014-01-08 09:19:56 +0530186 /* HSIC Phy reset */
187 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
188 HSIC_CTRL_FORCESLEEP |
189 HSIC_CTRL_SIDDQ |
190 HSIC_CTRL_PHYSWRST);
191
192 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
193 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -0700194}
195
196static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
197{
198 setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
199 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
200 PHYPWR_NORMAL_MASK_PHY0));
201}
202
203/* Reset the EHCI host controller. */
204static void reset_usb_phy(struct exynos_usb_phy *usb)
205{
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 *)
211 usb);
Inderpal Singh2eb65612014-01-08 09:19:56 +0530212
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +0000213 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530214}
Simon Glass2b8ceec2015-03-25 12:22:44 -0600215
Simon Glass2b8ceec2015-03-25 12:22:44 -0600216static int ehci_usb_probe(struct udevice *dev)
217{
Simon Glassb75b15b2020-12-03 16:55:23 -0700218 struct exynos_ehci_plat *plat = dev_get_plat(dev);
Simon Glass2b8ceec2015-03-25 12:22:44 -0600219 struct exynos_ehci *ctx = dev_get_priv(dev);
220 struct ehci_hcor *hcor;
221
222 ctx->hcd = (struct ehci_hccr *)plat->hcd_base;
223 ctx->usb = (struct exynos_usb_phy *)plat->phy_base;
Simon Glass2b8ceec2015-03-25 12:22:44 -0600224
225 /* setup the Vbus gpio here */
226 if (dm_gpio_is_valid(&plat->vbus_gpio))
227 dm_gpio_set_value(&plat->vbus_gpio, 1);
228
229 setup_usb_phy(ctx->usb);
Lukasz Majewskia9f74bb2015-12-10 16:32:25 +0100230 hcor = (struct ehci_hcor *)((uint32_t)ctx->hcd +
231 HC_LENGTH(ehci_readl(&ctx->hcd->cr_capbase)));
Simon Glass2b8ceec2015-03-25 12:22:44 -0600232
233 return ehci_register(dev, ctx->hcd, hcor, NULL, 0, USB_INIT_HOST);
234}
235
236static int ehci_usb_remove(struct udevice *dev)
237{
238 struct exynos_ehci *ctx = dev_get_priv(dev);
239 int ret;
240
241 ret = ehci_deregister(dev);
242 if (ret)
243 return ret;
244 reset_usb_phy(ctx->usb);
245
246 return 0;
247}
248
249static const struct udevice_id ehci_usb_ids[] = {
250 { .compatible = "samsung,exynos-ehci" },
251 { }
252};
253
254U_BOOT_DRIVER(usb_ehci) = {
255 .name = "ehci_exynos",
256 .id = UCLASS_USB,
257 .of_match = ehci_usb_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700258 .of_to_plat = ehci_usb_of_to_plat,
Simon Glass2b8ceec2015-03-25 12:22:44 -0600259 .probe = ehci_usb_probe,
260 .remove = ehci_usb_remove,
261 .ops = &ehci_usb_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700262 .priv_auto = sizeof(struct exynos_ehci),
Simon Glassb75b15b2020-12-03 16:55:23 -0700263 .plat_auto = sizeof(struct exynos_ehci_plat),
Simon Glass2b8ceec2015-03-25 12:22:44 -0600264 .flags = DM_FLAG_ALLOC_PRIV_DMA,
265};