blob: 8633cab940c630df13c63f17fe6e0a106219dda6 [file] [log] [blame]
Stefano Babic5b591502010-10-06 09:00:01 +02001/*
2 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19
20#include <common.h>
21#include <usb.h>
22#include <asm/io.h>
Stefano Babic86271112011-03-14 15:43:56 +010023#include <asm/arch/imx-regs.h>
Stefano Babic5b591502010-10-06 09:00:01 +020024#include <usb/ehci-fsl.h>
25#include <errno.h>
26
27#include "ehci.h"
Stefano Babic5b591502010-10-06 09:00:01 +020028
29#define USBCTRL_OTGBASE_OFFSET 0x600
30
Benoît Thébaudeau9fa3d092012-11-13 09:57:48 +000031#define MX25_OTG_SIC_SHIFT 29
32#define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT)
33#define MX25_OTG_PM_BIT (1 << 24)
34#define MX25_OTG_PP_BIT (1 << 11)
35#define MX25_OTG_OCPOL_BIT (1 << 3)
36
37#define MX25_H1_SIC_SHIFT 21
38#define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT)
39#define MX25_H1_PP_BIT (1 << 18)
Benoît Thébaudeaufa88ddb2012-11-16 06:46:24 +000040#define MX25_H1_PM_BIT (1 << 16)
Benoît Thébaudeau9fa3d092012-11-13 09:57:48 +000041#define MX25_H1_IPPUE_UP_BIT (1 << 7)
42#define MX25_H1_IPPUE_DOWN_BIT (1 << 6)
43#define MX25_H1_TLL_BIT (1 << 5)
44#define MX25_H1_USBTE_BIT (1 << 4)
45#define MX25_H1_OCPOL_BIT (1 << 2)
Matthias Weisserdddb7c92011-07-06 00:28:30 +000046
Stefano Babic5b591502010-10-06 09:00:01 +020047#define MX31_OTG_SIC_SHIFT 29
48#define MX31_OTG_SIC_MASK (0x3 << MX31_OTG_SIC_SHIFT)
49#define MX31_OTG_PM_BIT (1 << 24)
50
51#define MX31_H2_SIC_SHIFT 21
52#define MX31_H2_SIC_MASK (0x3 << MX31_H2_SIC_SHIFT)
53#define MX31_H2_PM_BIT (1 << 16)
54#define MX31_H2_DT_BIT (1 << 5)
55
56#define MX31_H1_SIC_SHIFT 13
57#define MX31_H1_SIC_MASK (0x3 << MX31_H1_SIC_SHIFT)
58#define MX31_H1_PM_BIT (1 << 8)
59#define MX31_H1_DT_BIT (1 << 4)
60
Benoît Thébaudeau71a5c552012-11-13 09:58:12 +000061#define MX35_OTG_SIC_SHIFT 29
62#define MX35_OTG_SIC_MASK (0x3 << MX35_OTG_SIC_SHIFT)
63#define MX35_OTG_PM_BIT (1 << 24)
64#define MX35_OTG_PP_BIT (1 << 11)
65#define MX35_OTG_OCPOL_BIT (1 << 3)
66
67#define MX35_H1_SIC_SHIFT 21
68#define MX35_H1_SIC_MASK (0x3 << MX35_H1_SIC_SHIFT)
69#define MX35_H1_PP_BIT (1 << 18)
Benoît Thébaudeaued0a6fc2012-11-16 01:42:49 +000070#define MX35_H1_PM_BIT (1 << 16)
Benoît Thébaudeau71a5c552012-11-13 09:58:12 +000071#define MX35_H1_IPPUE_UP_BIT (1 << 7)
72#define MX35_H1_IPPUE_DOWN_BIT (1 << 6)
73#define MX35_H1_TLL_BIT (1 << 5)
74#define MX35_H1_USBTE_BIT (1 << 4)
75#define MX35_H1_OCPOL_BIT (1 << 2)
76
Stefano Babic5b591502010-10-06 09:00:01 +020077static int mxc_set_usbcontrol(int port, unsigned int flags)
78{
79 unsigned int v;
Matthias Weisserdddb7c92011-07-06 00:28:30 +000080
Benoît Thébaudeau164738e2012-11-13 09:55:57 +000081 v = readl(IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
Benoît Thébaudeau9fa3d092012-11-13 09:57:48 +000082#if defined(CONFIG_MX25)
83 switch (port) {
84 case 0: /* OTG port */
85 v &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PM_BIT | MX25_OTG_PP_BIT |
86 MX25_OTG_OCPOL_BIT);
87 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT;
Benoît Thébaudeau164738e2012-11-13 09:55:57 +000088
Benoît Thébaudeau9fa3d092012-11-13 09:57:48 +000089 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
90 v |= MX25_OTG_PM_BIT;
91
92 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
93 v |= MX25_OTG_PP_BIT;
94
95 if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW))
96 v |= MX25_OTG_OCPOL_BIT;
97
98 break;
99 case 1: /* H1 port */
100 v &= ~(MX25_H1_SIC_MASK | MX25_H1_PM_BIT | MX25_H1_PP_BIT |
101 MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT |
102 MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT |
103 MX25_H1_IPPUE_UP_BIT);
104 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT;
105
106 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
107 v |= MX25_H1_PM_BIT;
108
109 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
110 v |= MX25_H1_PP_BIT;
111
112 if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW))
113 v |= MX25_H1_OCPOL_BIT;
114
115 if (!(flags & MXC_EHCI_TTL_ENABLED))
116 v |= MX25_H1_TLL_BIT;
117
118 if (flags & MXC_EHCI_INTERNAL_PHY)
119 v |= MX25_H1_USBTE_BIT;
120
121 if (flags & MXC_EHCI_IPPUE_DOWN)
122 v |= MX25_H1_IPPUE_DOWN_BIT;
123
124 if (flags & MXC_EHCI_IPPUE_UP)
125 v |= MX25_H1_IPPUE_UP_BIT;
126
127 break;
128 default:
129 return -EINVAL;
130 }
131#elif defined(CONFIG_MX31)
Benoît Thébaudeau164738e2012-11-13 09:55:57 +0000132 switch (port) {
133 case 0: /* OTG port */
134 v &= ~(MX31_OTG_SIC_MASK | MX31_OTG_PM_BIT);
135 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_OTG_SIC_SHIFT;
136
137 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
138 v |= MX31_OTG_PM_BIT;
139
140 break;
141 case 1: /* H1 port */
142 v &= ~(MX31_H1_SIC_MASK | MX31_H1_PM_BIT | MX31_H1_DT_BIT);
143 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_H1_SIC_SHIFT;
144
145 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
146 v |= MX31_H1_PM_BIT;
147
148 if (!(flags & MXC_EHCI_TTL_ENABLED))
149 v |= MX31_H1_DT_BIT;
150
151 break;
152 case 2: /* H2 port */
153 v &= ~(MX31_H2_SIC_MASK | MX31_H2_PM_BIT | MX31_H2_DT_BIT);
154 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_H2_SIC_SHIFT;
155
156 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
157 v |= MX31_H2_PM_BIT;
158
159 if (!(flags & MXC_EHCI_TTL_ENABLED))
160 v |= MX31_H2_DT_BIT;
161
162 break;
163 default:
164 return -EINVAL;
165 }
Benoît Thébaudeau71a5c552012-11-13 09:58:12 +0000166#elif defined(CONFIG_MX35)
167 switch (port) {
168 case 0: /* OTG port */
169 v &= ~(MX35_OTG_SIC_MASK | MX35_OTG_PM_BIT | MX35_OTG_PP_BIT |
170 MX35_OTG_OCPOL_BIT);
171 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX35_OTG_SIC_SHIFT;
172
173 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
174 v |= MX35_OTG_PM_BIT;
175
176 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
177 v |= MX35_OTG_PP_BIT;
178
179 if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW))
180 v |= MX35_OTG_OCPOL_BIT;
181
182 break;
183 case 1: /* H1 port */
184 v &= ~(MX35_H1_SIC_MASK | MX35_H1_PM_BIT | MX35_H1_PP_BIT |
185 MX35_H1_OCPOL_BIT | MX35_H1_TLL_BIT |
186 MX35_H1_USBTE_BIT | MX35_H1_IPPUE_DOWN_BIT |
187 MX35_H1_IPPUE_UP_BIT);
188 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX35_H1_SIC_SHIFT;
189
190 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
191 v |= MX35_H1_PM_BIT;
192
193 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
194 v |= MX35_H1_PP_BIT;
195
196 if (!(flags & MXC_EHCI_OC_PIN_ACTIVE_LOW))
197 v |= MX35_H1_OCPOL_BIT;
198
199 if (!(flags & MXC_EHCI_TTL_ENABLED))
200 v |= MX35_H1_TLL_BIT;
201
202 if (flags & MXC_EHCI_INTERNAL_PHY)
203 v |= MX35_H1_USBTE_BIT;
204
205 if (flags & MXC_EHCI_IPPUE_DOWN)
206 v |= MX35_H1_IPPUE_DOWN_BIT;
207
208 if (flags & MXC_EHCI_IPPUE_UP)
209 v |= MX35_H1_IPPUE_UP_BIT;
210
211 break;
212 default:
213 return -EINVAL;
214 }
Benoît Thébaudeau164738e2012-11-13 09:55:57 +0000215#else
216#error MXC EHCI USB driver not supported on this platform
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000217#endif
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000218 writel(v, IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
Benoît Thébaudeau164738e2012-11-13 09:55:57 +0000219
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000220 return 0;
Stefano Babic5b591502010-10-06 09:00:01 +0200221}
222
Lucas Stach676ae062012-09-26 00:14:35 +0200223int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Stefano Babic5b591502010-10-06 09:00:01 +0200224{
Stefano Babic5b591502010-10-06 09:00:01 +0200225 struct usb_ehci *ehci;
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000226#ifdef CONFIG_MX31
Stefano Babic5b591502010-10-06 09:00:01 +0200227 struct clock_control_regs *sc_regs =
228 (struct clock_control_regs *)CCM_BASE;
229
Anatolij Gustschinf55feaf2011-11-19 10:10:33 +0000230 __raw_readl(&sc_regs->ccmr);
Stefano Babic5b591502010-10-06 09:00:01 +0200231 __raw_writel(__raw_readl(&sc_regs->ccmr) | (1 << 9), &sc_regs->ccmr) ;
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000232#endif
Stefano Babic5b591502010-10-06 09:00:01 +0200233
234 udelay(80);
235
Matthias Weisserdddb7c92011-07-06 00:28:30 +0000236 ehci = (struct usb_ehci *)(IMX_USB_BASE +
Benoît Thébaudeau34d33b62012-11-13 09:57:59 +0000237 IMX_USB_PORT_OFFSET * CONFIG_MXC_USB_PORT);
Lucas Stach676ae062012-09-26 00:14:35 +0200238 *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
239 *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
240 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Stefano Babic5b591502010-10-06 09:00:01 +0200241 setbits_le32(&ehci->usbmode, CM_HOST);
Stefano Babic5b591502010-10-06 09:00:01 +0200242 __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
Stefano Babic5b591502010-10-06 09:00:01 +0200243 mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
Benoît Thébaudeau71a5c552012-11-13 09:58:12 +0000244#ifdef CONFIG_MX35
245 /* Workaround for ENGcm11601 */
246 __raw_writel(0, &ehci->sbuscfg);
247#endif
Stefano Babic5b591502010-10-06 09:00:01 +0200248
Stefano Babica2f9bff2010-10-18 10:23:05 +0200249 udelay(10000);
250
Stefano Babic5b591502010-10-06 09:00:01 +0200251 return 0;
252}
253
254/*
255 * Destroy the appropriate control structures corresponding
256 * the the EHCI host controller.
257 */
Lucas Stach676ae062012-09-26 00:14:35 +0200258int ehci_hcd_stop(int index)
Stefano Babic5b591502010-10-06 09:00:01 +0200259{
260 return 0;
261}