Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> |
| 4 | * Copyright (C) 2010 Freescale Semiconductor, Inc. |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <usb.h> |
| 9 | #include <errno.h> |
| 10 | #include <linux/compiler.h> |
Mateusz Kulikowski | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 11 | #include <usb/ehci-ci.h> |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/clock.h> |
Lukasz Majewski | dbc70f8 | 2019-04-04 12:26:52 +0200 | [diff] [blame] | 15 | #include <dm.h> |
| 16 | #include <power/regulator.h> |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 17 | |
| 18 | #include "ehci.h" |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 19 | |
| 20 | #define MX5_USBOTHER_REGS_OFFSET 0x800 |
| 21 | |
| 22 | |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 23 | #define MXC_OTG_OFFSET 0 |
| 24 | #define MXC_H1_OFFSET 0x200 |
| 25 | #define MXC_H2_OFFSET 0x400 |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 26 | #define MXC_H3_OFFSET 0x600 |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 27 | |
| 28 | #define MXC_USBCTRL_OFFSET 0 |
| 29 | #define MXC_USB_PHY_CTR_FUNC_OFFSET 0x8 |
| 30 | #define MXC_USB_PHY_CTR_FUNC2_OFFSET 0xc |
| 31 | #define MXC_USB_CTRL_1_OFFSET 0x10 |
| 32 | #define MXC_USBH2CTRL_OFFSET 0x14 |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 33 | #define MXC_USBH3CTRL_OFFSET 0x18 |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 34 | |
| 35 | /* USB_CTRL */ |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 36 | /* OTG wakeup intr enable */ |
| 37 | #define MXC_OTG_UCTRL_OWIE_BIT (1 << 27) |
| 38 | /* OTG power mask */ |
| 39 | #define MXC_OTG_UCTRL_OPM_BIT (1 << 24) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 40 | /* OTG power pin polarity */ |
| 41 | #define MXC_OTG_UCTRL_O_PWR_POL_BIT (1 << 24) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 42 | /* Host1 ULPI interrupt enable */ |
| 43 | #define MXC_H1_UCTRL_H1UIE_BIT (1 << 12) |
| 44 | /* HOST1 wakeup intr enable */ |
| 45 | #define MXC_H1_UCTRL_H1WIE_BIT (1 << 11) |
| 46 | /* HOST1 power mask */ |
| 47 | #define MXC_H1_UCTRL_H1PM_BIT (1 << 8) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 48 | /* HOST1 power pin polarity */ |
| 49 | #define MXC_H1_UCTRL_H1_PWR_POL_BIT (1 << 8) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 50 | |
| 51 | /* USB_PHY_CTRL_FUNC */ |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 52 | /* OTG Polarity of Overcurrent */ |
| 53 | #define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 54 | /* OTG Disable Overcurrent Event */ |
| 55 | #define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 56 | /* UH1 Polarity of Overcurrent */ |
| 57 | #define MXC_H1_OC_POL_BIT (1 << 6) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 58 | /* UH1 Disable Overcurrent Event */ |
| 59 | #define MXC_H1_OC_DIS_BIT (1 << 5) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 60 | /* OTG Power Pin Polarity */ |
| 61 | #define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 62 | |
| 63 | /* USBH2CTRL */ |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 64 | #define MXC_H2_UCTRL_H2_OC_POL_BIT (1 << 31) |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 65 | #define MXC_H2_UCTRL_H2_OC_DIS_BIT (1 << 30) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 66 | #define MXC_H2_UCTRL_H2UIE_BIT (1 << 8) |
| 67 | #define MXC_H2_UCTRL_H2WIE_BIT (1 << 7) |
| 68 | #define MXC_H2_UCTRL_H2PM_BIT (1 << 4) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 69 | #define MXC_H2_UCTRL_H2_PWR_POL_BIT (1 << 4) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 70 | |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 71 | /* USBH3CTRL */ |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 72 | #define MXC_H3_UCTRL_H3_OC_POL_BIT (1 << 31) |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 73 | #define MXC_H3_UCTRL_H3_OC_DIS_BIT (1 << 30) |
| 74 | #define MXC_H3_UCTRL_H3UIE_BIT (1 << 8) |
| 75 | #define MXC_H3_UCTRL_H3WIE_BIT (1 << 7) |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 76 | #define MXC_H3_UCTRL_H3_PWR_POL_BIT (1 << 4) |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 77 | |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 78 | /* USB_CTRL_1 */ |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 79 | #define MXC_USB_CTRL_UH1_EXT_CLK_EN (1 << 25) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 80 | |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 81 | int mxc_set_usbcontrol(int port, unsigned int flags) |
| 82 | { |
| 83 | unsigned int v; |
| 84 | void __iomem *usb_base = (void __iomem *)OTG_BASE_ADDR; |
| 85 | void __iomem *usbother_base; |
| 86 | int ret = 0; |
| 87 | |
| 88 | usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET; |
| 89 | |
| 90 | switch (port) { |
| 91 | case 0: /* OTG port */ |
| 92 | if (flags & MXC_EHCI_INTERNAL_PHY) { |
| 93 | v = __raw_readl(usbother_base + |
| 94 | MXC_USB_PHY_CTR_FUNC_OFFSET); |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 95 | if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW) |
| 96 | v |= MXC_OTG_PHYCTRL_OC_POL_BIT; |
| 97 | else |
| 98 | v &= ~MXC_OTG_PHYCTRL_OC_POL_BIT; |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 99 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 100 | /* OC/USBPWR is used */ |
| 101 | v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT; |
Benoît Thébaudeau | 2b2a415 | 2012-11-13 09:56:30 +0000 | [diff] [blame] | 102 | else |
| 103 | /* OC/USBPWR is not used */ |
| 104 | v |= MXC_OTG_PHYCTRL_OC_DIS_BIT; |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 105 | #ifdef CONFIG_MX51 |
| 106 | if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) |
| 107 | v |= MXC_OTG_PHYCTRL_PWR_POL_BIT; |
| 108 | else |
| 109 | v &= ~MXC_OTG_PHYCTRL_PWR_POL_BIT; |
| 110 | #endif |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 111 | __raw_writel(v, usbother_base + |
| 112 | MXC_USB_PHY_CTR_FUNC_OFFSET); |
| 113 | |
| 114 | v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET); |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 115 | #ifdef CONFIG_MX51 |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 116 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 117 | v &= ~MXC_OTG_UCTRL_OPM_BIT; |
Benoît Thébaudeau | b7647f3 | 2012-11-13 09:56:44 +0000 | [diff] [blame] | 118 | else |
| 119 | v |= MXC_OTG_UCTRL_OPM_BIT; |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 120 | #endif |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 121 | #ifdef CONFIG_MX53 |
| 122 | if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) |
| 123 | v |= MXC_OTG_UCTRL_O_PWR_POL_BIT; |
| 124 | else |
| 125 | v &= ~MXC_OTG_UCTRL_O_PWR_POL_BIT; |
| 126 | #endif |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 127 | __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET); |
| 128 | } |
| 129 | break; |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 130 | case 1: /* Host 1 ULPI */ |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 131 | #ifdef CONFIG_MX51 |
| 132 | /* The clock for the USBH1 ULPI port will come externally |
| 133 | from the PHY. */ |
| 134 | v = __raw_readl(usbother_base + MXC_USB_CTRL_1_OFFSET); |
| 135 | __raw_writel(v | MXC_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + |
| 136 | MXC_USB_CTRL_1_OFFSET); |
| 137 | #endif |
| 138 | |
| 139 | v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET); |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 140 | #ifdef CONFIG_MX51 |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 141 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 142 | v &= ~MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask unused */ |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 143 | else |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 144 | v |= MXC_H1_UCTRL_H1PM_BIT; /* H1 power mask used */ |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 145 | #endif |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 146 | #ifdef CONFIG_MX53 |
| 147 | if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) |
| 148 | v |= MXC_H1_UCTRL_H1_PWR_POL_BIT; |
| 149 | else |
| 150 | v &= ~MXC_H1_UCTRL_H1_PWR_POL_BIT; |
| 151 | #endif |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 152 | __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET); |
| 153 | |
| 154 | v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET); |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 155 | if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW) |
| 156 | v |= MXC_H1_OC_POL_BIT; |
| 157 | else |
| 158 | v &= ~MXC_H1_OC_POL_BIT; |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 159 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
| 160 | v &= ~MXC_H1_OC_DIS_BIT; /* OC is used */ |
| 161 | else |
| 162 | v |= MXC_H1_OC_DIS_BIT; /* OC is not used */ |
| 163 | __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET); |
| 164 | |
| 165 | break; |
| 166 | case 2: /* Host 2 ULPI */ |
| 167 | v = __raw_readl(usbother_base + MXC_USBH2CTRL_OFFSET); |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 168 | #ifdef CONFIG_MX51 |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 169 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 170 | v &= ~MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask unused */ |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 171 | else |
Benoît Thébaudeau | cb10972 | 2012-11-13 09:56:15 +0000 | [diff] [blame] | 172 | v |= MXC_H2_UCTRL_H2PM_BIT; /* H2 power mask used */ |
Benoît Thébaudeau | 46a53ab | 2012-11-13 09:56:59 +0000 | [diff] [blame] | 173 | #endif |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 174 | #ifdef CONFIG_MX53 |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 175 | if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW) |
| 176 | v |= MXC_H2_UCTRL_H2_OC_POL_BIT; |
| 177 | else |
| 178 | v &= ~MXC_H2_UCTRL_H2_OC_POL_BIT; |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 179 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
| 180 | v &= ~MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is used */ |
| 181 | else |
| 182 | v |= MXC_H2_UCTRL_H2_OC_DIS_BIT; /* OC is not used */ |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 183 | if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) |
| 184 | v |= MXC_H2_UCTRL_H2_PWR_POL_BIT; |
| 185 | else |
| 186 | v &= ~MXC_H2_UCTRL_H2_PWR_POL_BIT; |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 187 | #endif |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 188 | __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET); |
| 189 | break; |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 190 | #ifdef CONFIG_MX53 |
| 191 | case 3: /* Host 3 ULPI */ |
| 192 | v = __raw_readl(usbother_base + MXC_USBH3CTRL_OFFSET); |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 193 | if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW) |
| 194 | v |= MXC_H3_UCTRL_H3_OC_POL_BIT; |
| 195 | else |
| 196 | v &= ~MXC_H3_UCTRL_H3_OC_POL_BIT; |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 197 | if (flags & MXC_EHCI_POWER_PINS_ENABLED) |
| 198 | v &= ~MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is used */ |
| 199 | else |
| 200 | v |= MXC_H3_UCTRL_H3_OC_DIS_BIT; /* OC is not used */ |
Benoît Thébaudeau | 17971a9 | 2012-11-13 09:57:27 +0000 | [diff] [blame] | 201 | if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH) |
| 202 | v |= MXC_H3_UCTRL_H3_PWR_POL_BIT; |
| 203 | else |
| 204 | v &= ~MXC_H3_UCTRL_H3_PWR_POL_BIT; |
Benoît Thébaudeau | 284a459 | 2012-11-13 09:57:14 +0000 | [diff] [blame] | 205 | __raw_writel(v, usbother_base + MXC_USBH3CTRL_OFFSET); |
| 206 | break; |
| 207 | #endif |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return ret; |
| 211 | } |
| 212 | |
Benoît Thébaudeau | 98023c1 | 2012-11-13 09:58:35 +0000 | [diff] [blame] | 213 | int __weak board_ehci_hcd_init(int port) |
Marek Vasut | de09b79 | 2011-11-24 05:14:00 +0100 | [diff] [blame] | 214 | { |
Benoît Thébaudeau | 98023c1 | 2012-11-13 09:58:35 +0000 | [diff] [blame] | 215 | return 0; |
Marek Vasut | de09b79 | 2011-11-24 05:14:00 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Benoît Thébaudeau | 98023c1 | 2012-11-13 09:58:35 +0000 | [diff] [blame] | 218 | void __weak board_ehci_hcd_postinit(struct usb_ehci *ehci, int port) |
| 219 | { |
| 220 | } |
Marek Vasut | de09b79 | 2011-11-24 05:14:00 +0100 | [diff] [blame] | 221 | |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 222 | __weak void mx5_ehci_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, |
| 223 | uint32_t *reg) |
| 224 | { |
| 225 | mdelay(50); |
| 226 | } |
| 227 | |
Lukasz Majewski | dbc70f8 | 2019-04-04 12:26:52 +0200 | [diff] [blame] | 228 | #if !CONFIG_IS_ENABLED(DM_USB) |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 229 | static const struct ehci_ops mx5_ehci_ops = { |
| 230 | .powerup_fixup = mx5_ehci_powerup_fixup, |
| 231 | }; |
| 232 | |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 233 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 234 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 235 | { |
| 236 | struct usb_ehci *ehci; |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 237 | |
Simon Glass | dc9f3ed | 2015-03-25 12:22:27 -0600 | [diff] [blame] | 238 | /* The only user for this is efikamx-usb */ |
| 239 | ehci_set_controller_priv(index, NULL, &mx5_ehci_ops); |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 240 | set_usboh3_clk(); |
Fabio Estevam | 800cb81 | 2013-07-26 13:54:28 -0300 | [diff] [blame] | 241 | enable_usboh3_clk(true); |
Benoît Thébaudeau | f2f0038 | 2012-09-28 07:09:03 +0000 | [diff] [blame] | 242 | set_usb_phy_clk(); |
Fabio Estevam | 800cb81 | 2013-07-26 13:54:28 -0300 | [diff] [blame] | 243 | enable_usb_phy1_clk(true); |
| 244 | enable_usb_phy2_clk(true); |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 245 | mdelay(1); |
| 246 | |
Marek Vasut | de09b79 | 2011-11-24 05:14:00 +0100 | [diff] [blame] | 247 | /* Do board specific initialization */ |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 248 | board_ehci_hcd_init(CONFIG_MXC_USB_PORT); |
| 249 | |
| 250 | ehci = (struct usb_ehci *)(OTG_BASE_ADDR + |
| 251 | (0x200 * CONFIG_MXC_USB_PORT)); |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 252 | *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); |
| 253 | *hcor = (struct ehci_hcor *)((uint32_t)*hccr + |
| 254 | HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 255 | setbits_le32(&ehci->usbmode, CM_HOST); |
| 256 | |
| 257 | __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
| 258 | setbits_le32(&ehci->portsc, USB_EN); |
| 259 | |
| 260 | mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS); |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 261 | mdelay(10); |
| 262 | |
Marek Vasut | de09b79 | 2011-11-24 05:14:00 +0100 | [diff] [blame] | 263 | /* Do board specific post-initialization */ |
| 264 | board_ehci_hcd_postinit(ehci, CONFIG_MXC_USB_PORT); |
| 265 | |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 269 | int ehci_hcd_stop(int index) |
Wolfgang Grandegger | d17f2d2 | 2011-11-11 14:03:36 +0100 | [diff] [blame] | 270 | { |
| 271 | return 0; |
| 272 | } |
Lukasz Majewski | dbc70f8 | 2019-04-04 12:26:52 +0200 | [diff] [blame] | 273 | #else /* CONFIG_IS_ENABLED(DM_USB) */ |
| 274 | struct ehci_mx5_priv_data { |
| 275 | struct ehci_ctrl ctrl; |
| 276 | struct usb_ehci *ehci; |
| 277 | struct udevice *vbus_supply; |
| 278 | enum usb_init_type init_type; |
| 279 | int portnr; |
| 280 | }; |
| 281 | |
| 282 | static const struct ehci_ops mx5_ehci_ops = { |
| 283 | .powerup_fixup = mx5_ehci_powerup_fixup, |
| 284 | }; |
| 285 | |
| 286 | static int ehci_usb_ofdata_to_platdata(struct udevice *dev) |
| 287 | { |
| 288 | struct usb_platdata *plat = dev_get_platdata(dev); |
| 289 | const char *mode; |
| 290 | |
| 291 | mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "dr_mode", NULL); |
| 292 | if (mode) { |
| 293 | if (strcmp(mode, "peripheral") == 0) |
| 294 | plat->init_type = USB_INIT_DEVICE; |
| 295 | else if (strcmp(mode, "host") == 0) |
| 296 | plat->init_type = USB_INIT_HOST; |
| 297 | else |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int ehci_usb_probe(struct udevice *dev) |
| 305 | { |
| 306 | struct usb_platdata *plat = dev_get_platdata(dev); |
| 307 | struct usb_ehci *ehci = (struct usb_ehci *)devfdt_get_addr(dev); |
| 308 | struct ehci_mx5_priv_data *priv = dev_get_priv(dev); |
| 309 | enum usb_init_type type = plat->init_type; |
| 310 | struct ehci_hccr *hccr; |
| 311 | struct ehci_hcor *hcor; |
| 312 | int ret; |
| 313 | |
| 314 | set_usboh3_clk(); |
| 315 | enable_usboh3_clk(true); |
| 316 | set_usb_phy_clk(); |
| 317 | enable_usb_phy1_clk(true); |
| 318 | enable_usb_phy2_clk(true); |
| 319 | mdelay(1); |
| 320 | |
| 321 | priv->ehci = ehci; |
| 322 | priv->portnr = dev->seq; |
| 323 | priv->init_type = type; |
| 324 | |
| 325 | ret = device_get_supply_regulator(dev, "vbus-supply", |
| 326 | &priv->vbus_supply); |
| 327 | if (ret) |
| 328 | debug("%s: No vbus supply\n", dev->name); |
| 329 | |
| 330 | if (!ret && priv->vbus_supply) { |
| 331 | ret = regulator_set_enable(priv->vbus_supply, |
| 332 | (type == USB_INIT_DEVICE) ? |
| 333 | false : true); |
| 334 | if (ret) { |
| 335 | puts("Error enabling VBUS supply\n"); |
| 336 | return ret; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); |
| 341 | hcor = (struct ehci_hcor *)((uint32_t)hccr + |
| 342 | HC_LENGTH(ehci_readl(&(hccr)->cr_capbase))); |
| 343 | setbits_le32(&ehci->usbmode, CM_HOST); |
| 344 | |
| 345 | __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc); |
| 346 | setbits_le32(&ehci->portsc, USB_EN); |
| 347 | |
| 348 | mxc_set_usbcontrol(priv->portnr, CONFIG_MXC_USB_FLAGS); |
| 349 | mdelay(10); |
| 350 | |
| 351 | return ehci_register(dev, hccr, hcor, &mx5_ehci_ops, 0, |
| 352 | priv->init_type); |
| 353 | } |
| 354 | |
| 355 | static const struct udevice_id mx5_usb_ids[] = { |
| 356 | { .compatible = "fsl,imx53-usb" }, |
| 357 | { } |
| 358 | }; |
| 359 | |
| 360 | U_BOOT_DRIVER(usb_mx5) = { |
| 361 | .name = "ehci_mx5", |
| 362 | .id = UCLASS_USB, |
| 363 | .of_match = mx5_usb_ids, |
| 364 | .ofdata_to_platdata = ehci_usb_ofdata_to_platdata, |
| 365 | .probe = ehci_usb_probe, |
| 366 | .remove = ehci_deregister, |
| 367 | .ops = &ehci_usb_ops, |
| 368 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 369 | .priv_auto_alloc_size = sizeof(struct ehci_mx5_priv_data), |
| 370 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 371 | }; |
| 372 | #endif /* !CONFIG_IS_ENABLED(DM_USB) */ |