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