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