blob: 60f1470860b7c1cbfaccfed519da647d6dbda93a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +01002/*
3 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
4 * Copyright (C) 2010 Freescale Semiconductor, Inc.
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +01005 */
6
7#include <common.h>
8#include <usb.h>
9#include <errno.h>
10#include <linux/compiler.h>
Mateusz Kulikowskie162c6b2016-03-31 23:12:23 +020011#include <usb/ehci-ci.h>
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010012#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/clock.h>
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010015
16#include "ehci.h"
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010017
18#define MX5_USBOTHER_REGS_OFFSET 0x800
19
20
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000021#define MXC_OTG_OFFSET 0
22#define MXC_H1_OFFSET 0x200
23#define MXC_H2_OFFSET 0x400
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000024#define MXC_H3_OFFSET 0x600
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010025
26#define MXC_USBCTRL_OFFSET 0
27#define MXC_USB_PHY_CTR_FUNC_OFFSET 0x8
28#define MXC_USB_PHY_CTR_FUNC2_OFFSET 0xc
29#define MXC_USB_CTRL_1_OFFSET 0x10
30#define MXC_USBH2CTRL_OFFSET 0x14
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000031#define MXC_USBH3CTRL_OFFSET 0x18
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010032
33/* USB_CTRL */
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000034/* OTG wakeup intr enable */
35#define MXC_OTG_UCTRL_OWIE_BIT (1 << 27)
36/* OTG power mask */
37#define MXC_OTG_UCTRL_OPM_BIT (1 << 24)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000038/* OTG power pin polarity */
39#define MXC_OTG_UCTRL_O_PWR_POL_BIT (1 << 24)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000040/* Host1 ULPI interrupt enable */
41#define MXC_H1_UCTRL_H1UIE_BIT (1 << 12)
42/* HOST1 wakeup intr enable */
43#define MXC_H1_UCTRL_H1WIE_BIT (1 << 11)
44/* HOST1 power mask */
45#define MXC_H1_UCTRL_H1PM_BIT (1 << 8)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000046/* HOST1 power pin polarity */
47#define MXC_H1_UCTRL_H1_PWR_POL_BIT (1 << 8)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010048
49/* USB_PHY_CTRL_FUNC */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000050/* OTG Polarity of Overcurrent */
51#define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000052/* OTG Disable Overcurrent Event */
53#define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000054/* UH1 Polarity of Overcurrent */
55#define MXC_H1_OC_POL_BIT (1 << 6)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000056/* UH1 Disable Overcurrent Event */
57#define MXC_H1_OC_DIS_BIT (1 << 5)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000058/* OTG Power Pin Polarity */
59#define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010060
61/* USBH2CTRL */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000062#define MXC_H2_UCTRL_H2_OC_POL_BIT (1 << 31)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000063#define MXC_H2_UCTRL_H2_OC_DIS_BIT (1 << 30)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000064#define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
65#define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
66#define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000067#define MXC_H2_UCTRL_H2_PWR_POL_BIT (1 << 4)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010068
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000069/* USBH3CTRL */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000070#define MXC_H3_UCTRL_H3_OC_POL_BIT (1 << 31)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000071#define MXC_H3_UCTRL_H3_OC_DIS_BIT (1 << 30)
72#define MXC_H3_UCTRL_H3UIE_BIT (1 << 8)
73#define MXC_H3_UCTRL_H3WIE_BIT (1 << 7)
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000074#define MXC_H3_UCTRL_H3_PWR_POL_BIT (1 << 4)
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +000075
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010076/* USB_CTRL_1 */
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +000077#define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010078
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010079int mxc_set_usbcontrol(int port, unsigned int flags)
80{
81 unsigned int v;
82 void __iomem *usb_base = (void __iomem *)OTG_BASE_ADDR;
83 void __iomem *usbother_base;
84 int ret = 0;
85
86 usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
87
88 switch (port) {
89 case 0: /* OTG port */
90 if (flags & MXC_EHCI_INTERNAL_PHY) {
91 v = __raw_readl(usbother_base +
92 MXC_USB_PHY_CTR_FUNC_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +000093 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
94 v |= MXC_OTG_PHYCTRL_OC_POL_BIT;
95 else
96 v &= ~MXC_OTG_PHYCTRL_OC_POL_BIT;
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010097 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +010098 /* OC/USBPWR is used */
99 v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau7d424322012-11-13 09:56:30 +0000100 else
101 /* OC/USBPWR is not used */
102 v |= MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000103#ifdef CONFIG_MX51
104 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
105 v |= MXC_OTG_PHYCTRL_PWR_POL_BIT;
106 else
107 v &= ~MXC_OTG_PHYCTRL_PWR_POL_BIT;
108#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100109 __raw_writel(v, usbother_base +
110 MXC_USB_PHY_CTR_FUNC_OFFSET);
111
112 v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000113#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100114 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100115 v &= ~MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeau394c00d2012-11-13 09:56:44 +0000116 else
117 v |= MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000118#endif
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000119#ifdef CONFIG_MX53
120 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
121 v |= MXC_OTG_UCTRL_O_PWR_POL_BIT;
122 else
123 v &= ~MXC_OTG_UCTRL_O_PWR_POL_BIT;
124#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100125 __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
126 }
127 break;
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000128 case 1: /* Host 1 ULPI */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100129#ifdef CONFIG_MX51
130 /* The clock for the USBH1 ULPI port will come externally
131 from the PHY. */
132 v = __raw_readl(usbother_base + MXC_USB_CTRL_1_OFFSET);
133 __raw_writel(v | MXC_USB_CTRL_UH1_EXT_CLK_EN, usbother_base +
134 MXC_USB_CTRL_1_OFFSET);
135#endif
136
137 v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000138#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100139 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000140 v &= ~MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask unused */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100141 else
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000142 v |= MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask used */
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000143#endif
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000144#ifdef CONFIG_MX53
145 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
146 v |= MXC_H1_UCTRL_H1_PWR_POL_BIT;
147 else
148 v &= ~MXC_H1_UCTRL_H1_PWR_POL_BIT;
149#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100150 __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
151
152 v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000153 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
154 v |= MXC_H1_OC_POL_BIT;
155 else
156 v &= ~MXC_H1_OC_POL_BIT;
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100157 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
158 v &= ~MXC_H1_OC_DIS_BIT; /* OC is used */
159 else
160 v |= MXC_H1_OC_DIS_BIT; /* OC is not used */
161 __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
162
163 break;
164 case 2: /* Host 2 ULPI */
165 v = __raw_readl(usbother_base + MXC_USBH2CTRL_OFFSET);
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000166#ifdef CONFIG_MX51
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100167 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000168 v &= ~MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask unused */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100169 else
Benoît Thébaudeaubdc52022012-11-13 09:56:15 +0000170 v |= MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask used */
Benoît Thébaudeau661052f2012-11-13 09:56:59 +0000171#endif
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000172#ifdef CONFIG_MX53
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000173 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
174 v |= MXC_H2_UCTRL_H2_OC_POL_BIT;
175 else
176 v &= ~MXC_H2_UCTRL_H2_OC_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000177 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
178 v &= ~MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is used */
179 else
180 v |= MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is not used */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000181 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
182 v |= MXC_H2_UCTRL_H2_PWR_POL_BIT;
183 else
184 v &= ~MXC_H2_UCTRL_H2_PWR_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000185#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100186 __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET);
187 break;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000188#ifdef CONFIG_MX53
189 case 3: /* Host 3 ULPI */
190 v = __raw_readl(usbother_base + MXC_USBH3CTRL_OFFSET);
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000191 if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
192 v |= MXC_H3_UCTRL_H3_OC_POL_BIT;
193 else
194 v &= ~MXC_H3_UCTRL_H3_OC_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000195 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
196 v &= ~MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is used */
197 else
198 v |= MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is not used */
Benoît Thébaudeau31ac2d02012-11-13 09:57:27 +0000199 if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
200 v |= MXC_H3_UCTRL_H3_PWR_POL_BIT;
201 else
202 v &= ~MXC_H3_UCTRL_H3_PWR_POL_BIT;
Benoît Thébaudeau2cfe0b82012-11-13 09:57:14 +0000203 __raw_writel(v, usbother_base + MXC_USBH3CTRL_OFFSET);
204 break;
205#endif
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100206 }
207
208 return ret;
209}
210
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000211int __weak board_ehci_hcd_init(int port)
Marek Vasut1b80f272011-11-24 05:14:00 +0100212{
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000213 return 0;
Marek Vasut1b80f272011-11-24 05:14:00 +0100214}
215
Benoît Thébaudeauf22e4fa2012-11-13 09:58:35 +0000216void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
217{
218}
Marek Vasut1b80f272011-11-24 05:14:00 +0100219
Simon Glassdeb85082015-03-25 12:22:27 -0600220__weak void mx5_ehci_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,
221 uint32_t *reg)
222{
223 mdelay(50);
224}
225
226static const struct ehci_ops mx5_ehci_ops = {
227 .powerup_fixup = mx5_ehci_powerup_fixup,
228};
229
Troy Kisky127efc42013-10-10 15:27:57 -0700230int ehci_hcd_init(int index, enum usb_init_type init,
231 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100232{
233 struct usb_ehci *ehci;
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100234
Simon Glassdeb85082015-03-25 12:22:27 -0600235 /* The only user for this is efikamx-usb */
236 ehci_set_controller_priv(index, NULL, &mx5_ehci_ops);
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100237 set_usboh3_clk();
Fabio Estevam76b6b192013-07-26 13:54:28 -0300238 enable_usboh3_clk(true);
Benoît Thébaudeau414e1662012-09-28 07:09:03 +0000239 set_usb_phy_clk();
Fabio Estevam76b6b192013-07-26 13:54:28 -0300240 enable_usb_phy1_clk(true);
241 enable_usb_phy2_clk(true);
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100242 mdelay(1);
243
Marek Vasut1b80f272011-11-24 05:14:00 +0100244 /* Do board specific initialization */
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100245 board_ehci_hcd_init(CONFIG_MXC_USB_PORT);
246
247 ehci = (struct usb_ehci *)(OTG_BASE_ADDR +
248 (0x200 * CONFIG_MXC_USB_PORT));
Lucas Stach676ae062012-09-26 00:14:35 +0200249 *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
250 *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
251 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100252 setbits_le32(&ehci->usbmode, CM_HOST);
253
254 __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
255 setbits_le32(&ehci->portsc, USB_EN);
256
257 mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100258 mdelay(10);
259
Marek Vasut1b80f272011-11-24 05:14:00 +0100260 /* Do board specific post-initialization */
261 board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT);
262
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100263 return 0;
264}
265
Lucas Stach676ae062012-09-26 00:14:35 +0200266int ehci_hcd_stop(int index)
Wolfgang Grandegger1ca56202011-11-11 14:03:36 +0100267{
268 return 0;
269}