blob: f3c077d82e4d4c726ef99c32189f759571feb46e [file] [log] [blame]
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05301/*
Rajeshwari Shinde7590d3c2012-05-21 16:38:03 +05302 * SAMSUNG EXYNOS USB HOST EHCI Controller
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05303 *
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Vivek Gautam <gautam.vivek@samsung.com>
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +05308 */
9
10#include <common.h>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000011#include <fdtdec.h>
12#include <libfdt.h>
13#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>
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000020#include <asm-generic/errno.h>
21#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
27/**
28 * Contains pointers to register base addresses
29 * for the usb controller.
30 */
31struct exynos_ehci {
32 struct exynos_usb_phy *usb;
Vivek Gautam24a47752013-03-06 14:18:32 +053033 struct ehci_hccr *hcd;
Simon Glass46927e12015-01-05 20:05:39 -070034 struct gpio_desc vbus_gpio;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000035};
36
Vivek Gautam24a47752013-03-06 14:18:32 +053037static struct exynos_ehci exynos;
38
Vivek Gautamc74b0112013-03-06 14:18:33 +053039#ifdef CONFIG_OF_CONTROL
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000040static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
41{
Vivek Gautam24a47752013-03-06 14:18:32 +053042 fdt_addr_t addr;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000043 unsigned int node;
44 int depth;
45
46 node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI);
47 if (node <= 0) {
48 debug("EHCI: Can't get device node for ehci\n");
49 return -ENODEV;
50 }
51
52 /*
53 * Get the base address for EHCI controller from the device node
54 */
Vivek Gautam24a47752013-03-06 14:18:32 +053055 addr = fdtdec_get_addr(blob, node, "reg");
56 if (addr == FDT_ADDR_T_NONE) {
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000057 debug("Can't get the EHCI register address\n");
58 return -ENXIO;
59 }
60
Vivek Gautam24a47752013-03-06 14:18:32 +053061 exynos->hcd = (struct ehci_hccr *)addr;
62
Julius Werner4a271cb2013-09-14 14:02:52 +053063 /* Vbus gpio */
Simon Glass46927e12015-01-05 20:05:39 -070064 gpio_request_by_name_nodev(blob, node, "samsung,vbus-gpio", 0,
65 &exynos->vbus_gpio, GPIOD_IS_OUT);
Julius Werner4a271cb2013-09-14 14:02:52 +053066
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000067 depth = 0;
68 node = fdtdec_next_compatible_subnode(blob, node,
69 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
70 if (node <= 0) {
71 debug("EHCI: Can't get device node for usb-phy controller\n");
72 return -ENODEV;
73 }
74
75 /*
76 * Get the base address for usbphy from the device node
77 */
78 exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
79 "reg");
80 if (exynos->usb == NULL) {
81 debug("Can't get the usbphy register address\n");
82 return -ENXIO;
83 }
84
85 return 0;
86}
Vivek Gautamc74b0112013-03-06 14:18:33 +053087#endif
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +000088
Suriyan Ramasami6a23c652014-10-29 09:22:43 -070089static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053090{
Inderpal Singh16f94802014-01-08 09:19:56 +053091 u32 hsic_ctrl;
92
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +053093 clrbits_le32(&usb->usbphyctrl0,
94 HOST_CTRL0_FSEL_MASK |
95 HOST_CTRL0_COMMONON_N |
96 /* HOST Phy setting */
97 HOST_CTRL0_PHYSWRST |
98 HOST_CTRL0_PHYSWRSTALL |
99 HOST_CTRL0_SIDDQ |
100 HOST_CTRL0_FORCESUSPEND |
101 HOST_CTRL0_FORCESLEEP);
102
103 setbits_le32(&usb->usbphyctrl0,
104 /* Setting up the ref freq */
105 (CLK_24MHZ << 16) |
106 /* HOST Phy setting */
107 HOST_CTRL0_LINKSWRST |
108 HOST_CTRL0_UTMISWRST);
109 udelay(10);
110 clrbits_le32(&usb->usbphyctrl0,
111 HOST_CTRL0_LINKSWRST |
112 HOST_CTRL0_UTMISWRST);
Inderpal Singh16f94802014-01-08 09:19:56 +0530113
114 /* HSIC Phy Setting */
115 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
116 HSIC_CTRL_FORCESLEEP |
117 HSIC_CTRL_SIDDQ);
118
119 clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
120 clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
121
122 hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
123 << HSIC_CTRL_REFCLKDIV_SHIFT)
124 | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
125 << HSIC_CTRL_REFCLKSEL_SHIFT)
126 | HSIC_CTRL_UTMISWRST);
127
128 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
129 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
130
131 udelay(10);
132
133 clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
134 HSIC_CTRL_UTMISWRST);
135
136 clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
137 HSIC_CTRL_UTMISWRST);
138
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530139 udelay(20);
140
141 /* EHCI Ctrl setting */
142 setbits_le32(&usb->ehcictrl,
143 EHCICTRL_ENAINCRXALIGN |
144 EHCICTRL_ENAINCR4 |
145 EHCICTRL_ENAINCR8 |
146 EHCICTRL_ENAINCR16);
147}
148
Suriyan Ramasami6a23c652014-10-29 09:22:43 -0700149static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
150{
151 writel(CLK_24MHZ, &usb->usbphyclk);
152
153 clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
154 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
155 PHYPWR_NORMAL_MASK_PHY0));
156
157 setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
158 udelay(10);
159 clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
160}
161
162static void setup_usb_phy(struct exynos_usb_phy *usb)
163{
164 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
165
166 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
167
168 if (cpu_is_exynos5())
169 exynos5_setup_usb_phy(usb);
170 else if (cpu_is_exynos4())
171 if (proid_is_exynos4412())
172 exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
173 usb);
174}
175
176static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530177{
Inderpal Singh16f94802014-01-08 09:19:56 +0530178 u32 hsic_ctrl;
179
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530180 /* HOST_PHY reset */
181 setbits_le32(&usb->usbphyctrl0,
182 HOST_CTRL0_PHYSWRST |
183 HOST_CTRL0_PHYSWRSTALL |
184 HOST_CTRL0_SIDDQ |
185 HOST_CTRL0_FORCESUSPEND |
186 HOST_CTRL0_FORCESLEEP);
Rajeshwari Shindec48ac112012-05-14 05:52:03 +0000187
Inderpal Singh16f94802014-01-08 09:19:56 +0530188 /* HSIC Phy reset */
189 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
190 HSIC_CTRL_FORCESLEEP |
191 HSIC_CTRL_SIDDQ |
192 HSIC_CTRL_PHYSWRST);
193
194 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
195 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
Suriyan Ramasami6a23c652014-10-29 09:22:43 -0700196}
197
198static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
199{
200 setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
201 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
202 PHYPWR_NORMAL_MASK_PHY0));
203}
204
205/* Reset the EHCI host controller. */
206static void reset_usb_phy(struct exynos_usb_phy *usb)
207{
208 if (cpu_is_exynos5())
209 exynos5_reset_usb_phy(usb);
210 else if (cpu_is_exynos4())
211 if (proid_is_exynos4412())
212 exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
213 usb);
Inderpal Singh16f94802014-01-08 09:19:56 +0530214
Rajeshwari Shindec48ac112012-05-14 05:52:03 +0000215 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530216}
217
218/*
219 * EHCI-initialization
220 * Create the appropriate control structures to manage
221 * a new EHCI host controller.
222 */
Troy Kisky127efc42013-10-10 15:27:57 -0700223int ehci_hcd_init(int index, enum usb_init_type init,
224 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530225{
Vivek Gautam24a47752013-03-06 14:18:32 +0530226 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530227
Vivek Gautamc74b0112013-03-06 14:18:33 +0530228#ifdef CONFIG_OF_CONTROL
Vivek Gautam24a47752013-03-06 14:18:32 +0530229 if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
230 debug("Unable to parse device tree for ehci-exynos\n");
231 return -ENODEV;
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +0000232 }
Vivek Gautamc74b0112013-03-06 14:18:33 +0530233#else
234 ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
235 ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
236#endif
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530237
Julius Werner4a271cb2013-09-14 14:02:52 +0530238#ifdef CONFIG_OF_CONTROL
239 /* setup the Vbus gpio here */
Simon Glass46927e12015-01-05 20:05:39 -0700240 if (dm_gpio_is_valid(&ctx->vbus_gpio))
241 dm_gpio_set_value(&ctx->vbus_gpio, 1);
Julius Werner4a271cb2013-09-14 14:02:52 +0530242#endif
243
Vivek Gautam24a47752013-03-06 14:18:32 +0530244 setup_usb_phy(ctx->usb);
Rajeshwari Shindee18bf1f2013-01-07 23:35:03 +0000245
Inderpal Singh7da76512014-01-08 09:19:57 +0530246 board_usb_init(index, init);
247
Vivek Gautam24a47752013-03-06 14:18:32 +0530248 *hccr = ctx->hcd;
Lucas Stach676ae062012-09-26 00:14:35 +0200249 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
250 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530251
252 debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach676ae062012-09-26 00:14:35 +0200253 (uint32_t)*hccr, (uint32_t)*hcor,
254 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530255
256 return 0;
257}
258
259/*
260 * Destroy the appropriate control structures corresponding
261 * the EHCI host controller.
262 */
Lucas Stach676ae062012-09-26 00:14:35 +0200263int ehci_hcd_stop(int index)
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530264{
Vivek Gautam24a47752013-03-06 14:18:32 +0530265 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530266
Vivek Gautam24a47752013-03-06 14:18:32 +0530267 reset_usb_phy(ctx->usb);
Rajeshwari Shinde5f0ffea2012-05-02 19:18:51 +0530268
269 return 0;
270}