Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 1 | /* |
| 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 Babic | 8627111 | 2011-03-14 15:43:56 +0100 | [diff] [blame] | 23 | #include <asm/arch/imx-regs.h> |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 24 | #include <usb/ehci-fsl.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | #include "ehci.h" |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 28 | |
| 29 | #define USBCTRL_OTGBASE_OFFSET 0x600 |
| 30 | |
Benoît Thébaudeau | 9fa3d09 | 2012-11-13 09:57:48 +0000 | [diff] [blame] | 31 | #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ébaudeau | fa88ddb | 2012-11-16 06:46:24 +0000 | [diff] [blame] | 40 | #define MX25_H1_PM_BIT (1 << 16) |
Benoît Thébaudeau | 9fa3d09 | 2012-11-13 09:57:48 +0000 | [diff] [blame] | 41 | #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 Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 46 | |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 47 | #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ébaudeau | 71a5c55 | 2012-11-13 09:58:12 +0000 | [diff] [blame] | 61 | #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ébaudeau | ed0a6fc | 2012-11-16 01:42:49 +0000 | [diff] [blame] | 70 | #define MX35_H1_PM_BIT (1 << 16) |
Benoît Thébaudeau | 71a5c55 | 2012-11-13 09:58:12 +0000 | [diff] [blame] | 71 | #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 Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 77 | static int mxc_set_usbcontrol(int port, unsigned int flags) |
| 78 | { |
| 79 | unsigned int v; |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 80 | |
Benoît Thébaudeau | 164738e | 2012-11-13 09:55:57 +0000 | [diff] [blame] | 81 | v = readl(IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET); |
Benoît Thébaudeau | 9fa3d09 | 2012-11-13 09:57:48 +0000 | [diff] [blame] | 82 | #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ébaudeau | 164738e | 2012-11-13 09:55:57 +0000 | [diff] [blame] | 88 | |
Benoît Thébaudeau | 9fa3d09 | 2012-11-13 09:57:48 +0000 | [diff] [blame] | 89 | 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ébaudeau | 164738e | 2012-11-13 09:55:57 +0000 | [diff] [blame] | 132 | 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ébaudeau | 71a5c55 | 2012-11-13 09:58:12 +0000 | [diff] [blame] | 166 | #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ébaudeau | 164738e | 2012-11-13 09:55:57 +0000 | [diff] [blame] | 215 | #else |
| 216 | #error MXC EHCI USB driver not supported on this platform |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 217 | #endif |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 218 | writel(v, IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET); |
Benoît Thébaudeau | 164738e | 2012-11-13 09:55:57 +0000 | [diff] [blame] | 219 | |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 220 | return 0; |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 223 | int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 224 | { |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 225 | struct usb_ehci *ehci; |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 226 | #ifdef CONFIG_MX31 |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 227 | struct clock_control_regs *sc_regs = |
| 228 | (struct clock_control_regs *)CCM_BASE; |
| 229 | |
Anatolij Gustschin | f55feaf | 2011-11-19 10:10:33 +0000 | [diff] [blame] | 230 | __raw_readl(&sc_regs->ccmr); |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 231 | __raw_writel(__raw_readl(&sc_regs->ccmr) | (1 << 9), &sc_regs->ccmr) ; |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 232 | #endif |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 233 | |
| 234 | udelay(80); |
| 235 | |
Matthias Weisser | dddb7c9 | 2011-07-06 00:28:30 +0000 | [diff] [blame] | 236 | ehci = (struct usb_ehci *)(IMX_USB_BASE + |
Benoît Thébaudeau | 34d33b6 | 2012-11-13 09:57:59 +0000 | [diff] [blame] | 237 | IMX_USB_PORT_OFFSET * CONFIG_MXC_USB_PORT); |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 238 | *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 Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 241 | setbits_le32(&ehci->usbmode, CM_HOST); |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 242 | __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 243 | mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS); |
Benoît Thébaudeau | 71a5c55 | 2012-11-13 09:58:12 +0000 | [diff] [blame] | 244 | #ifdef CONFIG_MX35 |
| 245 | /* Workaround for ENGcm11601 */ |
| 246 | __raw_writel(0, &ehci->sbuscfg); |
| 247 | #endif |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 248 | |
Stefano Babic | a2f9bff | 2010-10-18 10:23:05 +0200 | [diff] [blame] | 249 | udelay(10000); |
| 250 | |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * Destroy the appropriate control structures corresponding |
| 256 | * the the EHCI host controller. |
| 257 | */ |
Lucas Stach | 676ae06 | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 258 | int ehci_hcd_stop(int index) |
Stefano Babic | 5b59150 | 2010-10-06 09:00:01 +0200 | [diff] [blame] | 259 | { |
| 260 | return 0; |
| 261 | } |