blob: 1fb685e58d80f32f84e6dd8d0fc9b9522c94c877 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babicadf5b642010-10-06 09:00:01 +02002/*
3 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
Stefano Babicadf5b642010-10-06 09:00:01 +02004 */
5
6
7#include <common.h>
8#include <usb.h>
9#include <asm/io.h>
Stefano Babic78129d92011-03-14 15:43:56 +010010#include <asm/arch/imx-regs.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Mateusz Kulikowski3add69e2016-03-31 23:12:23 +020012#include <usb/ehci-ci.h>
Stefano Babicadf5b642010-10-06 09:00:01 +020013#include <errno.h>
14
15#include "ehci.h"
Stefano Babicadf5b642010-10-06 09:00:01 +020016
17#define USBCTRL_OTGBASE_OFFSET 0x600
18
Benoît Thébaudeaue617b3f2012-11-13 09:57:48 +000019#define MX25_OTG_SIC_SHIFT 29
20#define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT)
21#define MX25_OTG_PM_BIT (1 << 24)
22#define MX25_OTG_PP_BIT (1 << 11)
23#define MX25_OTG_OCPOL_BIT (1 << 3)
24
25#define MX25_H1_SIC_SHIFT 21
26#define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT)
27#define MX25_H1_PP_BIT (1 << 18)
Benoît Thébaudeau39eb82b2012-11-16 06:46:24 +000028#define MX25_H1_PM_BIT (1 << 16)
Benoît Thébaudeaue617b3f2012-11-13 09:57:48 +000029#define MX25_H1_IPPUE_UP_BIT (1 << 7)
30#define MX25_H1_IPPUE_DOWN_BIT (1 << 6)
31#define MX25_H1_TLL_BIT (1 << 5)
32#define MX25_H1_USBTE_BIT (1 << 4)
33#define MX25_H1_OCPOL_BIT (1 << 2)
Matthias Weisserdba1f9b2011-07-06 00:28:30 +000034
Stefano Babicadf5b642010-10-06 09:00:01 +020035#define MX31_OTG_SIC_SHIFT 29
36#define MX31_OTG_SIC_MASK (0x3 << MX31_OTG_SIC_SHIFT)
37#define MX31_OTG_PM_BIT (1 << 24)
38
39#define MX31_H2_SIC_SHIFT 21
40#define MX31_H2_SIC_MASK (0x3 << MX31_H2_SIC_SHIFT)
41#define MX31_H2_PM_BIT (1 << 16)
42#define MX31_H2_DT_BIT (1 << 5)
43
44#define MX31_H1_SIC_SHIFT 13
45#define MX31_H1_SIC_MASK (0x3 << MX31_H1_SIC_SHIFT)
46#define MX31_H1_PM_BIT (1 << 8)
47#define MX31_H1_DT_BIT (1 << 4)
48
Benoît Thébaudeauc44f54d2012-11-13 09:58:12 +000049#define MX35_OTG_SIC_SHIFT 29
50#define MX35_OTG_SIC_MASK (0x3 << MX35_OTG_SIC_SHIFT)
51#define MX35_OTG_PM_BIT (1 << 24)
52#define MX35_OTG_PP_BIT (1 << 11)
53#define MX35_OTG_OCPOL_BIT (1 << 3)
54
55#define MX35_H1_SIC_SHIFT 21
56#define MX35_H1_SIC_MASK (0x3 << MX35_H1_SIC_SHIFT)
57#define MX35_H1_PP_BIT (1 << 18)
Benoît Thébaudeaua1599d62012-11-16 01:42:49 +000058#define MX35_H1_PM_BIT (1 << 16)
Benoît Thébaudeauc44f54d2012-11-13 09:58:12 +000059#define MX35_H1_IPPUE_UP_BIT (1 << 7)
60#define MX35_H1_IPPUE_DOWN_BIT (1 << 6)
61#define MX35_H1_TLL_BIT (1 << 5)
62#define MX35_H1_USBTE_BIT (1 << 4)
63#define MX35_H1_OCPOL_BIT (1 << 2)
64
Stefano Babicadf5b642010-10-06 09:00:01 +020065static int mxc_set_usbcontrol(int port, unsigned int flags)
66{
67 unsigned int v;
Matthias Weisserdba1f9b2011-07-06 00:28:30 +000068
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000069 v = readl(IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
Tom Rinieac76b82021-09-09 07:54:50 -040070#if defined(CONFIG_MX31)
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000071 switch (port) {
72 case 0: /* OTG port */
73 v &= ~(MX31_OTG_SIC_MASK | MX31_OTG_PM_BIT);
74 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_OTG_SIC_SHIFT;
Stefano Babicadf5b642010-10-06 09:00:01 +020075
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000076 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
77 v |= MX31_OTG_PM_BIT;
Stefano Babicadf5b642010-10-06 09:00:01 +020078
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000079 break;
80 case 1: /* H1 port */
81 v &= ~(MX31_H1_SIC_MASK | MX31_H1_PM_BIT | MX31_H1_DT_BIT);
82 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_H1_SIC_SHIFT;
Stefano Babicadf5b642010-10-06 09:00:01 +020083
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000084 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
85 v |= MX31_H1_PM_BIT;
Stefano Babicadf5b642010-10-06 09:00:01 +020086
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000087 if (!(flags & MXC_EHCI_TTL_ENABLED))
88 v |= MX31_H1_DT_BIT;
Stefano Babicadf5b642010-10-06 09:00:01 +020089
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000090 break;
91 case 2: /* H2 port */
92 v &= ~(MX31_H2_SIC_MASK | MX31_H2_PM_BIT | MX31_H2_DT_BIT);
93 v |= (flags & MXC_EHCI_INTERFACE_MASK) << MX31_H2_SIC_SHIFT;
Stefano Babicadf5b642010-10-06 09:00:01 +020094
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000095 if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
96 v |= MX31_H2_PM_BIT;
Matthias Weisserdba1f9b2011-07-06 00:28:30 +000097
Benoît Thébaudeau12638de2012-11-13 09:55:57 +000098 if (!(flags & MXC_EHCI_TTL_ENABLED))
99 v |= MX31_H2_DT_BIT;
100
101 break;
102 default:
103 return -EINVAL;
104 }
105#else
106#error MXC EHCI USB driver not supported on this platform
107#endif
Matthias Weisserdba1f9b2011-07-06 00:28:30 +0000108 writel(v, IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
Benoît Thébaudeau12638de2012-11-13 09:55:57 +0000109
Matthias Weisserdba1f9b2011-07-06 00:28:30 +0000110 return 0;
Stefano Babicadf5b642010-10-06 09:00:01 +0200111}
112
Troy Kisky7d6bbb92013-10-10 15:27:57 -0700113int ehci_hcd_init(int index, enum usb_init_type init,
114 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Stefano Babicadf5b642010-10-06 09:00:01 +0200115{
Stefano Babicadf5b642010-10-06 09:00:01 +0200116 struct usb_ehci *ehci;
Matthias Weisserdba1f9b2011-07-06 00:28:30 +0000117#ifdef CONFIG_MX31
Stefano Babicadf5b642010-10-06 09:00:01 +0200118 struct clock_control_regs *sc_regs =
119 (struct clock_control_regs *)CCM_BASE;
120
Anatolij Gustschin93d79e82011-11-19 10:10:33 +0000121 __raw_readl(&sc_regs->ccmr);
Stefano Babicadf5b642010-10-06 09:00:01 +0200122 __raw_writel(__raw_readl(&sc_regs->ccmr) | (1 << 9), &sc_regs->ccmr) ;
Matthias Weisserdba1f9b2011-07-06 00:28:30 +0000123#endif
Stefano Babicadf5b642010-10-06 09:00:01 +0200124
125 udelay(80);
126
Matthias Weisserdba1f9b2011-07-06 00:28:30 +0000127 ehci = (struct usb_ehci *)(IMX_USB_BASE +
Benoît Thébaudeau27a23bb2012-11-13 09:57:59 +0000128 IMX_USB_PORT_OFFSET * CONFIG_MXC_USB_PORT);
Lucas Stach3494a4c2012-09-26 00:14:35 +0200129 *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
130 *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
131 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Stefano Babicadf5b642010-10-06 09:00:01 +0200132 setbits_le32(&ehci->usbmode, CM_HOST);
Stefano Babicadf5b642010-10-06 09:00:01 +0200133 __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
Stefano Babicadf5b642010-10-06 09:00:01 +0200134 mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
135
Stefano Babic5e6b1f62010-10-18 10:23:05 +0200136 udelay(10000);
137
Stefano Babicadf5b642010-10-06 09:00:01 +0200138 return 0;
139}
140
141/*
142 * Destroy the appropriate control structures corresponding
143 * the the EHCI host controller.
144 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200145int ehci_hcd_stop(int index)
Stefano Babicadf5b642010-10-06 09:00:01 +0200146{
147 return 0;
148}