blob: 6fdbf5724f4a6527757d8cec692c9a59c7529b6a [file] [log] [blame]
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05301/*
Rajeshwari Shindedad39d42012-05-21 16:38:03 +05302 * SAMSUNG EXYNOS USB HOST EHCI Controller
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05303 *
4 * Copyright (C) 2012 Samsung Electronics Co.Ltd
5 * Vivek Gautam <gautam.vivek@samsung.com>
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +05308 */
9
10#include <common.h>
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000011#include <fdtdec.h>
12#include <libfdt.h>
13#include <malloc.h>
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053014#include <usb.h>
15#include <asm/arch/cpu.h>
Rajeshwari Shindedad39d42012-05-21 16:38:03 +053016#include <asm/arch/ehci.h>
Rajeshwari Shinde84448072012-05-14 05:52:02 +000017#include <asm/arch/system.h>
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +000018#include <asm/arch/power.h>
Julius Wernerddcb9bd2013-09-14 14:02:52 +053019#include <asm/gpio.h>
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000020#include <asm-generic/errno.h>
21#include <linux/compat.h>
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053022#include "ehci.h"
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053023
Rajeshwari Shinde23fbde52013-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 Gautambab686c2013-03-06 14:18:32 +053033 struct ehci_hccr *hcd;
Julius Wernerddcb9bd2013-09-14 14:02:52 +053034 struct fdt_gpio_state vbus_gpio;
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000035};
36
Vivek Gautambab686c2013-03-06 14:18:32 +053037static struct exynos_ehci exynos;
38
Vivek Gautamfac8a762013-03-06 14:18:33 +053039#ifdef CONFIG_OF_CONTROL
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000040static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
41{
Vivek Gautambab686c2013-03-06 14:18:32 +053042 fdt_addr_t addr;
Rajeshwari Shinde23fbde52013-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 Gautambab686c2013-03-06 14:18:32 +053055 addr = fdtdec_get_addr(blob, node, "reg");
56 if (addr == FDT_ADDR_T_NONE) {
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000057 debug("Can't get the EHCI register address\n");
58 return -ENXIO;
59 }
60
Vivek Gautambab686c2013-03-06 14:18:32 +053061 exynos->hcd = (struct ehci_hccr *)addr;
62
Julius Wernerddcb9bd2013-09-14 14:02:52 +053063 /* Vbus gpio */
64 fdtdec_decode_gpio(blob, node, "samsung,vbus-gpio", &exynos->vbus_gpio);
65
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000066 depth = 0;
67 node = fdtdec_next_compatible_subnode(blob, node,
68 COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
69 if (node <= 0) {
70 debug("EHCI: Can't get device node for usb-phy controller\n");
71 return -ENODEV;
72 }
73
74 /*
75 * Get the base address for usbphy from the device node
76 */
77 exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
78 "reg");
79 if (exynos->usb == NULL) {
80 debug("Can't get the usbphy register address\n");
81 return -ENXIO;
82 }
83
84 return 0;
85}
Vivek Gautamfac8a762013-03-06 14:18:33 +053086#endif
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +000087
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -070088static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053089{
Inderpal Singh2eb65612014-01-08 09:19:56 +053090 u32 hsic_ctrl;
91
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +053092 clrbits_le32(&usb->usbphyctrl0,
93 HOST_CTRL0_FSEL_MASK |
94 HOST_CTRL0_COMMONON_N |
95 /* HOST Phy setting */
96 HOST_CTRL0_PHYSWRST |
97 HOST_CTRL0_PHYSWRSTALL |
98 HOST_CTRL0_SIDDQ |
99 HOST_CTRL0_FORCESUSPEND |
100 HOST_CTRL0_FORCESLEEP);
101
102 setbits_le32(&usb->usbphyctrl0,
103 /* Setting up the ref freq */
104 (CLK_24MHZ << 16) |
105 /* HOST Phy setting */
106 HOST_CTRL0_LINKSWRST |
107 HOST_CTRL0_UTMISWRST);
108 udelay(10);
109 clrbits_le32(&usb->usbphyctrl0,
110 HOST_CTRL0_LINKSWRST |
111 HOST_CTRL0_UTMISWRST);
Inderpal Singh2eb65612014-01-08 09:19:56 +0530112
113 /* HSIC Phy Setting */
114 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
115 HSIC_CTRL_FORCESLEEP |
116 HSIC_CTRL_SIDDQ);
117
118 clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
119 clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
120
121 hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
122 << HSIC_CTRL_REFCLKDIV_SHIFT)
123 | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
124 << HSIC_CTRL_REFCLKSEL_SHIFT)
125 | HSIC_CTRL_UTMISWRST);
126
127 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
128 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
129
130 udelay(10);
131
132 clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
133 HSIC_CTRL_UTMISWRST);
134
135 clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
136 HSIC_CTRL_UTMISWRST);
137
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530138 udelay(20);
139
140 /* EHCI Ctrl setting */
141 setbits_le32(&usb->ehcictrl,
142 EHCICTRL_ENAINCRXALIGN |
143 EHCICTRL_ENAINCR4 |
144 EHCICTRL_ENAINCR8 |
145 EHCICTRL_ENAINCR16);
146}
147
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -0700148static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
149{
150 writel(CLK_24MHZ, &usb->usbphyclk);
151
152 clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
153 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
154 PHYPWR_NORMAL_MASK_PHY0));
155
156 setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
157 udelay(10);
158 clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
159}
160
161static void setup_usb_phy(struct exynos_usb_phy *usb)
162{
163 set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
164
165 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
166
167 if (cpu_is_exynos5())
168 exynos5_setup_usb_phy(usb);
169 else if (cpu_is_exynos4())
170 if (proid_is_exynos4412())
171 exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
172 usb);
173}
174
175static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530176{
Inderpal Singh2eb65612014-01-08 09:19:56 +0530177 u32 hsic_ctrl;
178
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530179 /* HOST_PHY reset */
180 setbits_le32(&usb->usbphyctrl0,
181 HOST_CTRL0_PHYSWRST |
182 HOST_CTRL0_PHYSWRSTALL |
183 HOST_CTRL0_SIDDQ |
184 HOST_CTRL0_FORCESUSPEND |
185 HOST_CTRL0_FORCESLEEP);
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +0000186
Inderpal Singh2eb65612014-01-08 09:19:56 +0530187 /* HSIC Phy reset */
188 hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
189 HSIC_CTRL_FORCESLEEP |
190 HSIC_CTRL_SIDDQ |
191 HSIC_CTRL_PHYSWRST);
192
193 setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
194 setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
Suriyan Ramasami97f4ef62014-10-29 09:22:43 -0700195}
196
197static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
198{
199 setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
200 PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
201 PHYPWR_NORMAL_MASK_PHY0));
202}
203
204/* Reset the EHCI host controller. */
205static void reset_usb_phy(struct exynos_usb_phy *usb)
206{
207 if (cpu_is_exynos5())
208 exynos5_reset_usb_phy(usb);
209 else if (cpu_is_exynos4())
210 if (proid_is_exynos4412())
211 exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
212 usb);
Inderpal Singh2eb65612014-01-08 09:19:56 +0530213
Rajeshwari Shinde21965ac2012-05-14 05:52:03 +0000214 set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530215}
216
217/*
218 * EHCI-initialization
219 * Create the appropriate control structures to manage
220 * a new EHCI host controller.
221 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700222int ehci_hcd_init(int index, enum usb_init_type init,
223 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530224{
Vivek Gautambab686c2013-03-06 14:18:32 +0530225 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +0000226
Vivek Gautamfac8a762013-03-06 14:18:33 +0530227#ifdef CONFIG_OF_CONTROL
Vivek Gautambab686c2013-03-06 14:18:32 +0530228 if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
229 debug("Unable to parse device tree for ehci-exynos\n");
230 return -ENODEV;
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +0000231 }
Vivek Gautamfac8a762013-03-06 14:18:33 +0530232#else
233 ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
234 ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
235#endif
Rajeshwari Shinde23fbde52013-01-07 23:35:03 +0000236
Julius Wernerddcb9bd2013-09-14 14:02:52 +0530237#ifdef CONFIG_OF_CONTROL
238 /* setup the Vbus gpio here */
andrey.konovalov@linaro.org6baf21c2014-04-22 21:23:49 +0400239 if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
240 !fdtdec_setup_gpio(&ctx->vbus_gpio))
Julius Wernerddcb9bd2013-09-14 14:02:52 +0530241 gpio_direction_output(ctx->vbus_gpio.gpio, 1);
242#endif
243
Vivek Gautambab686c2013-03-06 14:18:32 +0530244 setup_usb_phy(ctx->usb);
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530245
Inderpal Singh3260bc82014-01-08 09:19:57 +0530246 board_usb_init(index, init);
247
Vivek Gautambab686c2013-03-06 14:18:32 +0530248 *hccr = ctx->hcd;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200249 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
250 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530251
252 debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
Lucas Stach3494a4c2012-09-26 00:14:35 +0200253 (uint32_t)*hccr, (uint32_t)*hcor,
254 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Rajeshwari Shinde9b4ae502012-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 Stach3494a4c2012-09-26 00:14:35 +0200263int ehci_hcd_stop(int index)
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530264{
Vivek Gautambab686c2013-03-06 14:18:32 +0530265 struct exynos_ehci *ctx = &exynos;
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530266
Vivek Gautambab686c2013-03-06 14:18:32 +0530267 reset_usb_phy(ctx->usb);
Rajeshwari Shinde9b4ae502012-05-02 19:18:51 +0530268
269 return 0;
270}