blob: f43c38da6178ebe5d45db800737f2fc9b208b88a [file] [log] [blame]
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +01001/*
2 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
3 * Copyright (C) 2010 Freescale Semiconductor, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16#include <common.h>
17#include <usb.h>
18#include <errno.h>
19#include <linux/compiler.h>
20#include <usb/ehci-fsl.h>
21#include <asm/io.h>
22#include <asm/arch/imx-regs.h>
23#include <asm/arch/clock.h>
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010024
25#include "ehci.h"
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010026
27#define MX5_USBOTHER_REGS_OFFSET 0x800
28
29
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000030#define MXC_OTG_OFFSET 0
31#define MXC_H1_OFFSET 0x200
32#define MXC_H2_OFFSET 0x400
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000033#define MXC_H3_OFFSET 0x600
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010034
35#define MXC_USBCTRL_OFFSET 0
36#define MXC_USB_PHY_CTR_FUNC_OFFSET 0x8
37#define MXC_USB_PHY_CTR_FUNC2_OFFSET 0xc
38#define MXC_USB_CTRL_1_OFFSET 0x10
39#define MXC_USBH2CTRL_OFFSET 0x14
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000040#define MXC_USBH3CTRL_OFFSET 0x18
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010041
42/* USB_CTRL */
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000043/* OTG wakeup intr enable */
44#define MXC_OTG_UCTRL_OWIE_BIT (1 << 27)
45/* OTG power mask */
46#define MXC_OTG_UCTRL_OPM_BIT (1 << 24)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000047/* OTG power pin polarity */
48#define MXC_OTG_UCTRL_O_PWR_POL_BIT (1 << 24)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000049/* Host1 ULPI interrupt enable */
50#define MXC_H1_UCTRL_H1UIE_BIT (1 << 12)
51/* HOST1 wakeup intr enable */
52#define MXC_H1_UCTRL_H1WIE_BIT (1 << 11)
53/* HOST1 power mask */
54#define MXC_H1_UCTRL_H1PM_BIT (1 << 8)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000055/* HOST1 power pin polarity */
56#define MXC_H1_UCTRL_H1_PWR_POL_BIT (1 << 8)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010057
58/* USB_PHY_CTRL_FUNC */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000059/* OTG Polarity of Overcurrent */
60#define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000061/* OTG Disable Overcurrent Event */
62#define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000063/* UH1 Polarity of Overcurrent */
64#define MXC_H1_OC_POL_BIT (1 << 6)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000065/* UH1 Disable Overcurrent Event */
66#define MXC_H1_OC_DIS_BIT (1 << 5)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000067/* OTG Power Pin Polarity */
68#define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010069
70/* USBH2CTRL */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000071#define MXC_H2_UCTRL_H2_OC_POL_BIT (1 << 31)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000072#define MXC_H2_UCTRL_H2_OC_DIS_BIT (1 << 30)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000073#define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
74#define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
75#define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000076#define MXC_H2_UCTRL_H2_PWR_POL_BIT (1 << 4)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010077
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000078/* USBH3CTRL */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000079#define MXC_H3_UCTRL_H3_OC_POL_BIT (1 << 31)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000080#define MXC_H3_UCTRL_H3_OC_DIS_BIT (1 << 30)
81#define MXC_H3_UCTRL_H3UIE_BIT (1 << 8)
82#define MXC_H3_UCTRL_H3WIE_BIT (1 << 7)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000083#define MXC_H3_UCTRL_H3_PWR_POL_BIT (1 << 4)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000084
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010085/* USB_CTRL_1 */
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000086#define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010087
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010088int mxc_set_usbcontrol(int port, unsigned int flags)
89{
90 unsigned int v;
91 void __iomem *usb_base = (void __iomem *)OTG_BASE_ADDR;
92 void __iomem *usbother_base;
93 int ret = 0;
94
95 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
96
97 switch (port) {
98 case 0: /* OTG port */
99 if (flags & MXC_EHCI_INTERNAL_PHY) {
100 v = __raw_readl(usbother_base +
101 MXC_USB_PHY_CTR_FUNC_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000102 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
103 v |= MXC_OTG_PHYCTRL_OC_POL_BIT;
104 else
105 v &= ~MXC_OTG_PHYCTRL_OC_POL_BIT;
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100106 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100107 /* OC/USBPWR is used */
108 v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau7d424322012-11-13 09:56:30 +0000109 else
110 /* OC/USBPWR is not used */
111 v |= MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000112#ifdef CONFIG_MX51
113 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
114 v |= MXC_OTG_PHYCTRL_PWR_POL_BIT;
115 else
116 v &= ~MXC_OTG_PHYCTRL_PWR_POL_BIT;
117#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100118 __raw_writel(v, usbother_base +
119 MXC_USB_PHY_CTR_FUNC_OFFSET);
120
121 v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000122#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100123 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100124 v &= ~MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeau394c00d2012-11-13 09:56:44 +0000125 else
126 v |= MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000127#endif
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000128#ifdef CONFIG_MX53
129 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
130 v |= MXC_OTG_UCTRL_O_PWR_POL_BIT;
131 else
132 v &= ~MXC_OTG_UCTRL_O_PWR_POL_BIT;
133#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100134 __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
135 }
136 break;
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000137 case 1: /* Host 1 ULPI */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100138#ifdef CONFIG_MX51
139 /* The clock for the USBH1 ULPI port will come externally
140 from the PHY. */
141 v = __raw_readl(usbother_base + MXC_USB_CTRL_1_OFFSET);
142 __raw_writel(v | MXC_USB_CTRL_UH1_EXT_CLK_EN, usbother_base +
143 MXC_USB_CTRL_1_OFFSET);
144#endif
145
146 v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000147#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100148 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000149 v &= ~MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask unused */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100150 else
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000151 v |= MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask used */
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000152#endif
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000153#ifdef CONFIG_MX53
154 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
155 v |= MXC_H1_UCTRL_H1_PWR_POL_BIT;
156 else
157 v &= ~MXC_H1_UCTRL_H1_PWR_POL_BIT;
158#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100159 __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
160
161 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000162 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
163 v |= MXC_H1_OC_POL_BIT;
164 else
165 v &= ~MXC_H1_OC_POL_BIT;
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100166 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
167 v &= ~MXC_H1_OC_DIS_BIT; /* OC is used */
168 else
169 v |= MXC_H1_OC_DIS_BIT; /* OC is not used */
170 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
171
172 break;
173 case 2: /* Host 2 ULPI */
174 v = __raw_readl(usbother_base + MXC_USBH2CTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000175#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100176 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000177 v &= ~MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask unused */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100178 else
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000179 v |= MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask used */
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000180#endif
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000181#ifdef CONFIG_MX53
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000182 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
183 v |= MXC_H2_UCTRL_H2_OC_POL_BIT;
184 else
185 v &= ~MXC_H2_UCTRL_H2_OC_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000186 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
187 v &= ~MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is used */
188 else
189 v |= MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is not used */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000190 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
191 v |= MXC_H2_UCTRL_H2_PWR_POL_BIT;
192 else
193 v &= ~MXC_H2_UCTRL_H2_PWR_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000194#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100195 __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET);
196 break;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000197#ifdef CONFIG_MX53
198 case 3: /* Host 3 ULPI */
199 v = __raw_readl(usbother_base + MXC_USBH3CTRL_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000200 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
201 v |= MXC_H3_UCTRL_H3_OC_POL_BIT;
202 else
203 v &= ~MXC_H3_UCTRL_H3_OC_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000204 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
205 v &= ~MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is used */
206 else
207 v |= MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is not used */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000208 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
209 v |= MXC_H3_UCTRL_H3_PWR_POL_BIT;
210 else
211 v &= ~MXC_H3_UCTRL_H3_PWR_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000212 __raw_writel(v, usbother_base + MXC_USBH3CTRL_OFFSET);
213 break;
214#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100215 }
216
217 return ret;
218}
219
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000220int __weak board_ehci_hcd_init(int port)
Marek Vasut1b80f272011-11-24 05:14:00 +0100221{
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000222 return 0;
Marek Vasut1b80f272011-11-24 05:14:00 +0100223}
224
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000225void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
226{
227}
Marek Vasut1b80f272011-11-24 05:14:00 +0100228
Lucas Stach676ae062012-09-26 00:14:35 +0200229int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100230{
231 struct usb_ehci *ehci;
232#ifdef CONFIG_MX53
233 struct clkctl *sc_regs = (struct clkctl *)CCM_BASE_ADDR;
234 u32 reg;
235
236 reg = __raw_readl(&sc_regs->cscmr1) & ~(1 << 26);
237 /* derive USB PHY clock multiplexer from PLL3 */
238 reg |= 1 << 26;
239 __raw_writel(reg, &sc_regs->cscmr1);
240#endif
241
242 set_usboh3_clk();
243 enable_usboh3_clk(1);
Benoît Thébaudeau414e1662012-09-28 07:09:03 +0000244 set_usb_phy_clk();
245 enable_usb_phy1_clk(1);
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100246 enable_usb_phy2_clk(1);
247 mdelay(1);
248
Marek Vasut1b80f272011-11-24 05:14:00 +0100249 /* Do board specific initialization */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100250 board_ehci_hcd_init(CONFIG_MXC_USB_PORT);
251
252 ehci = (struct usb_ehci *)(OTG_BASE_ADDR +
253 (0x200 * CONFIG_MXC_USB_PORT));
Lucas Stach676ae062012-09-26 00:14:35 +0200254 *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
255 *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
256 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100257 setbits_le32(&ehci->usbmode, CM_HOST);
258
259 __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
260 setbits_le32(&ehci->portsc, USB_EN);
261
262 mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100263 mdelay(10);
264
Marek Vasut1b80f272011-11-24 05:14:00 +0100265 /* Do board specific post-initialization */
266 board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT);
267
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100268 return 0;
269}
270
Lucas Stach676ae062012-09-26 00:14:35 +0200271int ehci_hcd_stop(int index)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100272{
273 return 0;
274}