blob: 60f1470860b7c1cbfaccfed519da647d6dbda93a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +01002/*
3 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
4 * Copyright (C) 2010 Freescale Semiconductor, Inc.
Wolfgang Grandeggerd17f2d22011-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 Kulikowski3add69e2016-03-31 23:12:23 +020011#include <usb/ehci-ci.h>
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010012#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/clock.h>
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010015
16#include "ehci.h"
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010017
18#define MX5_USBOTHER_REGS_OFFSET 0x800
19
20
Benoît Thébaudeaucb109722012-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ébaudeau284a4592012-11-13 09:57:14 +000024#define MXC_H3_OFFSET 0x600
Wolfgang Grandeggerd17f2d22011-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ébaudeau284a4592012-11-13 09:57:14 +000031#define MXC_USBH3CTRL_OFFSET 0x18
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010032
33/* USB_CTRL */
Benoît Thébaudeaucb109722012-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ébaudeau17971a92012-11-13 09:57:27 +000038/* OTG power pin polarity */
39#define MXC_OTG_UCTRL_O_PWR_POL_BIT (1 << 24)
Benoît Thébaudeaucb109722012-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ébaudeau17971a92012-11-13 09:57:27 +000046/* HOST1 power pin polarity */
47#define MXC_H1_UCTRL_H1_PWR_POL_BIT (1 << 8)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010048
49/* USB_PHY_CTRL_FUNC */
Benoît Thébaudeau17971a92012-11-13 09:57:27 +000050/* OTG Polarity of Overcurrent */
51#define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9)
Benoît Thébaudeaucb109722012-11-13 09:56:15 +000052/* OTG Disable Overcurrent Event */
53#define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8)
Benoît Thébaudeau17971a92012-11-13 09:57:27 +000054/* UH1 Polarity of Overcurrent */
55#define MXC_H1_OC_POL_BIT (1 << 6)
Benoît Thébaudeaucb109722012-11-13 09:56:15 +000056/* UH1 Disable Overcurrent Event */
57#define MXC_H1_OC_DIS_BIT (1 << 5)
Benoît Thébaudeau17971a92012-11-13 09:57:27 +000058/* OTG Power Pin Polarity */
59#define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010060
61/* USBH2CTRL */
Benoît Thébaudeau17971a92012-11-13 09:57:27 +000062#define MXC_H2_UCTRL_H2_OC_POL_BIT (1 << 31)
Benoît Thébaudeau284a4592012-11-13 09:57:14 +000063#define MXC_H2_UCTRL_H2_OC_DIS_BIT (1 << 30)
Benoît Thébaudeaucb109722012-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ébaudeau17971a92012-11-13 09:57:27 +000067#define MXC_H2_UCTRL_H2_PWR_POL_BIT (1 << 4)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010068
Benoît Thébaudeau284a4592012-11-13 09:57:14 +000069/* USBH3CTRL */
Benoît Thébaudeau17971a92012-11-13 09:57:27 +000070#define MXC_H3_UCTRL_H3_OC_POL_BIT (1 << 31)
Benoît Thébaudeau284a4592012-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ébaudeau17971a92012-11-13 09:57:27 +000074#define MXC_H3_UCTRL_H3_PWR_POL_BIT (1 << 4)
Benoît Thébaudeau284a4592012-11-13 09:57:14 +000075
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010076/* USB_CTRL_1 */
Benoît Thébaudeaucb109722012-11-13 09:56:15 +000077#define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010078
Wolfgang Grandeggerd17f2d22011-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ébaudeau17971a92012-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 Grandeggerd17f2d22011-11-11 14:03:36 +010097 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +010098 /* OC/USBPWR is used */
99 v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau2b2a4152012-11-13 09:56:30 +0000100 else
101 /* OC/USBPWR is not used */
102 v |= MXC_OTG_PHYCTRL_OC_DIS_BIT;
Benoît Thébaudeau17971a92012-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 Grandeggerd17f2d22011-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ébaudeau46a53ab2012-11-13 09:56:59 +0000113#ifdef CONFIG_MX51
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100114 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100115 v &= ~MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeaub7647f32012-11-13 09:56:44 +0000116 else
117 v |= MXC_OTG_UCTRL_OPM_BIT;
Benoît Thébaudeau46a53ab2012-11-13 09:56:59 +0000118#endif
Benoît Thébaudeau17971a92012-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 Grandeggerd17f2d22011-11-11 14:03:36 +0100125 __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
126 }
127 break;
Benoît Thébaudeaucb109722012-11-13 09:56:15 +0000128 case 1: /* Host 1 ULPI */
Wolfgang Grandeggerd17f2d22011-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ébaudeau46a53ab2012-11-13 09:56:59 +0000138#ifdef CONFIG_MX51
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100139 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaucb109722012-11-13 09:56:15 +0000140 v &= ~MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask unused */
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100141 else
Benoît Thébaudeaucb109722012-11-13 09:56:15 +0000142 v |= MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask used */
Benoît Thébaudeau46a53ab2012-11-13 09:56:59 +0000143#endif
Benoît Thébaudeau17971a92012-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 Grandeggerd17f2d22011-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ébaudeau17971a92012-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 Grandeggerd17f2d22011-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ébaudeau46a53ab2012-11-13 09:56:59 +0000166#ifdef CONFIG_MX51
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100167 if (flags & MXC_EHCI_POWER_PINS_ENABLED)
Benoît Thébaudeaucb109722012-11-13 09:56:15 +0000168 v &= ~MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask unused */
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100169 else
Benoît Thébaudeaucb109722012-11-13 09:56:15 +0000170 v |= MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask used */
Benoît Thébaudeau46a53ab2012-11-13 09:56:59 +0000171#endif
Benoît Thébaudeau284a4592012-11-13 09:57:14 +0000172#ifdef CONFIG_MX53
Benoît Thébaudeau17971a92012-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ébaudeau284a4592012-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ébaudeau17971a92012-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ébaudeau284a4592012-11-13 09:57:14 +0000185#endif
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100186 __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET);
187 break;
Benoît Thébaudeau284a4592012-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ébaudeau17971a92012-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ébaudeau284a4592012-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ébaudeau17971a92012-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ébaudeau284a4592012-11-13 09:57:14 +0000203 __raw_writel(v, usbother_base + MXC_USBH3CTRL_OFFSET);
204 break;
205#endif
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100206 }
207
208 return ret;
209}
210
Benoît Thébaudeau98023c12012-11-13 09:58:35 +0000211int __weak board_ehci_hcd_init(int port)
Marek Vasutde09b792011-11-24 05:14:00 +0100212{
Benoît Thébaudeau98023c12012-11-13 09:58:35 +0000213 return 0;
Marek Vasutde09b792011-11-24 05:14:00 +0100214}
215
Benoît Thébaudeau98023c12012-11-13 09:58:35 +0000216void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
217{
218}
Marek Vasutde09b792011-11-24 05:14:00 +0100219
Simon Glassdc9f3ed2015-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 Kisky7d6bbb92013-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 Grandeggerd17f2d22011-11-11 14:03:36 +0100232{
233 struct usb_ehci *ehci;
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100234
Simon Glassdc9f3ed2015-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 Grandeggerd17f2d22011-11-11 14:03:36 +0100237 set_usboh3_clk();
Fabio Estevam800cb812013-07-26 13:54:28 -0300238 enable_usboh3_clk(true);
Benoît Thébaudeauf2f00382012-09-28 07:09:03 +0000239 set_usb_phy_clk();
Fabio Estevam800cb812013-07-26 13:54:28 -0300240 enable_usb_phy1_clk(true);
241 enable_usb_phy2_clk(true);
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100242 mdelay(1);
243
Marek Vasutde09b792011-11-24 05:14:00 +0100244 /* Do board specific initialization */
Wolfgang Grandeggerd17f2d22011-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 Stach3494a4c2012-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 Grandeggerd17f2d22011-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 Grandeggerd17f2d22011-11-11 14:03:36 +0100258 mdelay(10);
259
Marek Vasutde09b792011-11-24 05:14:00 +0100260 /* Do board specific post-initialization */
261 board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT);
262
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100263 return 0;
264}
265
Lucas Stach3494a4c2012-09-26 00:14:35 +0200266int ehci_hcd_stop(int index)
Wolfgang Grandeggerd17f2d22011-11-11 14:03:36 +0100267{
268 return 0;
269}