Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1 | /** |
| 2 | * core.c - DesignWare USB3 DRD Controller Core file |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 5 | * |
| 6 | * Authors: Felipe Balbi <balbi@ti.com>, |
| 7 | * Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 9 | * This program is free software: you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 of |
| 11 | * the License as published by the Free Software Foundation. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 12 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 17 | * |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 20 | */ |
| 21 | |
Felipe Balbi | fa0ea13 | 2014-09-19 15:51:11 -0500 | [diff] [blame] | 22 | #include <linux/version.h> |
Felipe Balbi | a72e658 | 2011-09-05 13:37:28 +0300 | [diff] [blame] | 23 | #include <linux/module.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/pm_runtime.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/ioport.h> |
| 31 | #include <linux/io.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/dma-mapping.h> |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 35 | #include <linux/of.h> |
Heikki Krogerus | 404905a | 2014-09-25 10:57:02 +0300 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Sekhar Nori | 6344475 | 2015-08-31 21:09:08 +0530 | [diff] [blame] | 37 | #include <linux/pinctrl/consumer.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 38 | |
| 39 | #include <linux/usb/ch9.h> |
| 40 | #include <linux/usb/gadget.h> |
Felipe Balbi | f7e846f | 2013-06-30 14:29:51 +0300 | [diff] [blame] | 41 | #include <linux/usb/of.h> |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 42 | #include <linux/usb/otg.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 43 | |
Felipe Balbi | 6462cbd | 2013-06-30 14:19:33 +0300 | [diff] [blame] | 44 | #include "platform_data.h" |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 45 | #include "core.h" |
| 46 | #include "gadget.h" |
| 47 | #include "io.h" |
| 48 | |
| 49 | #include "debug.h" |
| 50 | |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 51 | /* -------------------------------------------------------------------------- */ |
| 52 | |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 53 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) |
| 54 | { |
| 55 | u32 reg; |
| 56 | |
| 57 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 58 | reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); |
| 59 | reg |= DWC3_GCTL_PRTCAPDIR(mode); |
| 60 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 61 | } |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 62 | |
Felipe Balbi | cf6d867 | 2016-04-14 15:03:39 +0300 | [diff] [blame^] | 63 | u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type) |
| 64 | { |
| 65 | struct dwc3 *dwc = dep->dwc; |
| 66 | u32 reg; |
| 67 | |
| 68 | dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, |
| 69 | DWC3_GDBGFIFOSPACE_NUM(dep->number) | |
| 70 | DWC3_GDBGFIFOSPACE_TYPE(type)); |
| 71 | |
| 72 | reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); |
| 73 | |
| 74 | return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg); |
| 75 | } |
| 76 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 77 | /** |
| 78 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset |
| 79 | * @dwc: pointer to our context structure |
| 80 | */ |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 81 | static int dwc3_core_soft_reset(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 82 | { |
| 83 | u32 reg; |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 84 | int retries = 1000; |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 85 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 86 | |
Felipe Balbi | 51e1e7b | 2012-07-19 14:09:48 +0300 | [diff] [blame] | 87 | usb_phy_init(dwc->usb2_phy); |
| 88 | usb_phy_init(dwc->usb3_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 89 | ret = phy_init(dwc->usb2_generic_phy); |
| 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
| 93 | ret = phy_init(dwc->usb3_generic_phy); |
| 94 | if (ret < 0) { |
| 95 | phy_exit(dwc->usb2_generic_phy); |
| 96 | return ret; |
| 97 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 98 | |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 99 | /* |
| 100 | * We're resetting only the device side because, if we're in host mode, |
| 101 | * XHCI driver will reset the host block. If dwc3 was configured for |
| 102 | * host-only mode, then we can return early. |
| 103 | */ |
| 104 | if (dwc->dr_mode == USB_DR_MODE_HOST) |
| 105 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 106 | |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 107 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 108 | reg |= DWC3_DCTL_CSFTRST; |
| 109 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 110 | |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 111 | do { |
| 112 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 113 | if (!(reg & DWC3_DCTL_CSFTRST)) |
| 114 | return 0; |
Pratyush Anand | 45627ac | 2012-06-21 17:44:28 +0530 | [diff] [blame] | 115 | |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 116 | udelay(1); |
| 117 | } while (--retries); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 118 | |
Felipe Balbi | f59dcab | 2016-03-11 10:51:52 +0200 | [diff] [blame] | 119 | return -ETIMEDOUT; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 123 | * dwc3_soft_reset - Issue soft reset |
| 124 | * @dwc: Pointer to our controller context structure |
| 125 | */ |
| 126 | static int dwc3_soft_reset(struct dwc3 *dwc) |
| 127 | { |
| 128 | unsigned long timeout; |
| 129 | u32 reg; |
| 130 | |
| 131 | timeout = jiffies + msecs_to_jiffies(500); |
| 132 | dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); |
| 133 | do { |
| 134 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 135 | if (!(reg & DWC3_DCTL_CSFTRST)) |
| 136 | break; |
| 137 | |
| 138 | if (time_after(jiffies, timeout)) { |
| 139 | dev_err(dwc->dev, "Reset Timed Out\n"); |
| 140 | return -ETIMEDOUT; |
| 141 | } |
| 142 | |
| 143 | cpu_relax(); |
| 144 | } while (true); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 149 | /* |
| 150 | * dwc3_frame_length_adjustment - Adjusts frame length if required |
| 151 | * @dwc3: Pointer to our controller context structure |
| 152 | * @fladj: Value of GFLADJ_30MHZ to adjust frame length |
| 153 | */ |
| 154 | static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 fladj) |
| 155 | { |
| 156 | u32 reg; |
| 157 | u32 dft; |
| 158 | |
| 159 | if (dwc->revision < DWC3_REVISION_250A) |
| 160 | return; |
| 161 | |
| 162 | if (fladj == 0) |
| 163 | return; |
| 164 | |
| 165 | reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); |
| 166 | dft = reg & DWC3_GFLADJ_30MHZ_MASK; |
| 167 | if (!dev_WARN_ONCE(dwc->dev, dft == fladj, |
| 168 | "request value same as default, ignoring\n")) { |
| 169 | reg &= ~DWC3_GFLADJ_30MHZ_MASK; |
| 170 | reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | fladj; |
| 171 | dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); |
| 172 | } |
| 173 | } |
| 174 | |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 175 | /** |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 176 | * dwc3_free_one_event_buffer - Frees one event buffer |
| 177 | * @dwc: Pointer to our controller context structure |
| 178 | * @evt: Pointer to event buffer to be freed |
| 179 | */ |
| 180 | static void dwc3_free_one_event_buffer(struct dwc3 *dwc, |
| 181 | struct dwc3_event_buffer *evt) |
| 182 | { |
| 183 | dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 187 | * dwc3_alloc_one_event_buffer - Allocates one event buffer structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 188 | * @dwc: Pointer to our controller context structure |
| 189 | * @length: size of the event buffer |
| 190 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 191 | * Returns a pointer to the allocated event buffer structure on success |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 192 | * otherwise ERR_PTR(errno). |
| 193 | */ |
Felipe Balbi | 67d0b50 | 2013-02-22 16:31:07 +0200 | [diff] [blame] | 194 | static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, |
| 195 | unsigned length) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 196 | { |
| 197 | struct dwc3_event_buffer *evt; |
| 198 | |
Felipe Balbi | 380f0d2 | 2012-10-11 13:48:36 +0300 | [diff] [blame] | 199 | evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 200 | if (!evt) |
| 201 | return ERR_PTR(-ENOMEM); |
| 202 | |
| 203 | evt->dwc = dwc; |
| 204 | evt->length = length; |
| 205 | evt->buf = dma_alloc_coherent(dwc->dev, length, |
| 206 | &evt->dma, GFP_KERNEL); |
Felipe Balbi | e32672f | 2012-11-08 15:26:41 +0200 | [diff] [blame] | 207 | if (!evt->buf) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 208 | return ERR_PTR(-ENOMEM); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 209 | |
| 210 | return evt; |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * dwc3_free_event_buffers - frees all allocated event buffers |
| 215 | * @dwc: Pointer to our controller context structure |
| 216 | */ |
| 217 | static void dwc3_free_event_buffers(struct dwc3 *dwc) |
| 218 | { |
| 219 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 220 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 221 | evt = dwc->ev_buf; |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 222 | if (evt) |
| 223 | dwc3_free_one_event_buffer(dwc, evt); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 228 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 229 | * @length: size of event buffer |
| 230 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 231 | * Returns 0 on success otherwise negative errno. In the error case, dwc |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 232 | * may contain some buffers allocated but not all which were requested. |
| 233 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 234 | static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 235 | { |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 236 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 237 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 238 | evt = dwc3_alloc_one_event_buffer(dwc, length); |
| 239 | if (IS_ERR(evt)) { |
| 240 | dev_err(dwc->dev, "can't allocate event buffer\n"); |
| 241 | return PTR_ERR(evt); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 242 | } |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 243 | dwc->ev_buf = evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * dwc3_event_buffers_setup - setup our allocated event buffers |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 250 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 251 | * |
| 252 | * Returns 0 on success otherwise negative errno. |
| 253 | */ |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 254 | static int dwc3_event_buffers_setup(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 255 | { |
| 256 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 257 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 258 | evt = dwc->ev_buf; |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 259 | dwc3_trace(trace_dwc3_core, |
| 260 | "Event buf %p dma %08llx length %d\n", |
| 261 | evt->buf, (unsigned long long) evt->dma, |
| 262 | evt->length); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 263 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 264 | evt->lpos = 0; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 265 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 266 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), |
| 267 | lower_32_bits(evt->dma)); |
| 268 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), |
| 269 | upper_32_bits(evt->dma)); |
| 270 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), |
| 271 | DWC3_GEVNTSIZ_SIZE(evt->length)); |
| 272 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) |
| 278 | { |
| 279 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 280 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 281 | evt = dwc->ev_buf; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 282 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 283 | evt->lpos = 0; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 284 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 285 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); |
| 286 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); |
| 287 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK |
| 288 | | DWC3_GEVNTSIZ_SIZE(0)); |
| 289 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 290 | } |
| 291 | |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 292 | static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) |
| 293 | { |
| 294 | if (!dwc->has_hibernation) |
| 295 | return 0; |
| 296 | |
| 297 | if (!dwc->nr_scratch) |
| 298 | return 0; |
| 299 | |
| 300 | dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, |
| 301 | DWC3_SCRATCHBUF_SIZE, GFP_KERNEL); |
| 302 | if (!dwc->scratchbuf) |
| 303 | return -ENOMEM; |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) |
| 309 | { |
| 310 | dma_addr_t scratch_addr; |
| 311 | u32 param; |
| 312 | int ret; |
| 313 | |
| 314 | if (!dwc->has_hibernation) |
| 315 | return 0; |
| 316 | |
| 317 | if (!dwc->nr_scratch) |
| 318 | return 0; |
| 319 | |
| 320 | /* should never fall here */ |
| 321 | if (!WARN_ON(dwc->scratchbuf)) |
| 322 | return 0; |
| 323 | |
| 324 | scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf, |
| 325 | dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, |
| 326 | DMA_BIDIRECTIONAL); |
| 327 | if (dma_mapping_error(dwc->dev, scratch_addr)) { |
| 328 | dev_err(dwc->dev, "failed to map scratch buffer\n"); |
| 329 | ret = -EFAULT; |
| 330 | goto err0; |
| 331 | } |
| 332 | |
| 333 | dwc->scratch_addr = scratch_addr; |
| 334 | |
| 335 | param = lower_32_bits(scratch_addr); |
| 336 | |
| 337 | ret = dwc3_send_gadget_generic_command(dwc, |
| 338 | DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param); |
| 339 | if (ret < 0) |
| 340 | goto err1; |
| 341 | |
| 342 | param = upper_32_bits(scratch_addr); |
| 343 | |
| 344 | ret = dwc3_send_gadget_generic_command(dwc, |
| 345 | DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param); |
| 346 | if (ret < 0) |
| 347 | goto err1; |
| 348 | |
| 349 | return 0; |
| 350 | |
| 351 | err1: |
| 352 | dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * |
| 353 | DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); |
| 354 | |
| 355 | err0: |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | static void dwc3_free_scratch_buffers(struct dwc3 *dwc) |
| 360 | { |
| 361 | if (!dwc->has_hibernation) |
| 362 | return; |
| 363 | |
| 364 | if (!dwc->nr_scratch) |
| 365 | return; |
| 366 | |
| 367 | /* should never fall here */ |
| 368 | if (!WARN_ON(dwc->scratchbuf)) |
| 369 | return; |
| 370 | |
| 371 | dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * |
| 372 | DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); |
| 373 | kfree(dwc->scratchbuf); |
| 374 | } |
| 375 | |
Felipe Balbi | 789451f6 | 2011-05-05 15:53:10 +0300 | [diff] [blame] | 376 | static void dwc3_core_num_eps(struct dwc3 *dwc) |
| 377 | { |
| 378 | struct dwc3_hwparams *parms = &dwc->hwparams; |
| 379 | |
| 380 | dwc->num_in_eps = DWC3_NUM_IN_EPS(parms); |
| 381 | dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps; |
| 382 | |
Felipe Balbi | 7381528 | 2015-01-27 13:48:14 -0600 | [diff] [blame] | 383 | dwc3_trace(trace_dwc3_core, "found %d IN and %d OUT endpoints", |
Felipe Balbi | 789451f6 | 2011-05-05 15:53:10 +0300 | [diff] [blame] | 384 | dwc->num_in_eps, dwc->num_out_eps); |
| 385 | } |
| 386 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 387 | static void dwc3_cache_hwparams(struct dwc3 *dwc) |
Felipe Balbi | 26ceca9 | 2011-09-30 10:58:49 +0300 | [diff] [blame] | 388 | { |
| 389 | struct dwc3_hwparams *parms = &dwc->hwparams; |
| 390 | |
| 391 | parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); |
| 392 | parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); |
| 393 | parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); |
| 394 | parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); |
| 395 | parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); |
| 396 | parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); |
| 397 | parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); |
| 398 | parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); |
| 399 | parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); |
| 400 | } |
| 401 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 402 | /** |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 403 | * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core |
| 404 | * @dwc: Pointer to our controller context structure |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 405 | * |
| 406 | * Returns 0 on success. The USB PHY interfaces are configured but not |
| 407 | * initialized. The PHY interfaces and the PHYs get initialized together with |
| 408 | * the core in dwc3_core_init. |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 409 | */ |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 410 | static int dwc3_phy_setup(struct dwc3 *dwc) |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 411 | { |
| 412 | u32 reg; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 413 | int ret; |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 414 | |
| 415 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 416 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 417 | /* |
| 418 | * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY |
| 419 | * to '0' during coreConsultant configuration. So default value |
| 420 | * will be '0' when the core is reset. Application needs to set it |
| 421 | * to '1' after the core initialization is completed. |
| 422 | */ |
| 423 | if (dwc->revision > DWC3_REVISION_194A) |
| 424 | reg |= DWC3_GUSB3PIPECTL_SUSPHY; |
| 425 | |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 426 | if (dwc->u2ss_inp3_quirk) |
| 427 | reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK; |
| 428 | |
Rajesh Bhagat | e58dd35 | 2016-03-14 14:40:50 +0530 | [diff] [blame] | 429 | if (dwc->dis_rxdet_inp3_quirk) |
| 430 | reg |= DWC3_GUSB3PIPECTL_DISRXDETINP3; |
| 431 | |
Huang Rui | df31f5b | 2014-10-28 19:54:29 +0800 | [diff] [blame] | 432 | if (dwc->req_p1p2p3_quirk) |
| 433 | reg |= DWC3_GUSB3PIPECTL_REQP1P2P3; |
| 434 | |
Huang Rui | a2a1d0f | 2014-10-28 19:54:30 +0800 | [diff] [blame] | 435 | if (dwc->del_p1p2p3_quirk) |
| 436 | reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN; |
| 437 | |
Huang Rui | 41c06ff | 2014-10-28 19:54:31 +0800 | [diff] [blame] | 438 | if (dwc->del_phy_power_chg_quirk) |
| 439 | reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE; |
| 440 | |
Huang Rui | fb67afc | 2014-10-28 19:54:32 +0800 | [diff] [blame] | 441 | if (dwc->lfps_filter_quirk) |
| 442 | reg |= DWC3_GUSB3PIPECTL_LFPSFILT; |
| 443 | |
Huang Rui | 14f4ac5 | 2014-10-28 19:54:33 +0800 | [diff] [blame] | 444 | if (dwc->rx_detect_poll_quirk) |
| 445 | reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL; |
| 446 | |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 447 | if (dwc->tx_de_emphasis_quirk) |
| 448 | reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); |
| 449 | |
Felipe Balbi | cd72f89 | 2014-11-06 11:31:00 -0600 | [diff] [blame] | 450 | if (dwc->dis_u3_susphy_quirk) |
Huang Rui | 59acfa2 | 2014-10-31 11:11:13 +0800 | [diff] [blame] | 451 | reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; |
| 452 | |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 453 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 454 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 455 | reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); |
| 456 | |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 457 | /* Select the HS PHY interface */ |
| 458 | switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { |
| 459 | case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI: |
Felipe Balbi | 43cacb0 | 2015-07-01 22:03:09 -0500 | [diff] [blame] | 460 | if (dwc->hsphy_interface && |
| 461 | !strncmp(dwc->hsphy_interface, "utmi", 4)) { |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 462 | reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 463 | break; |
Felipe Balbi | 43cacb0 | 2015-07-01 22:03:09 -0500 | [diff] [blame] | 464 | } else if (dwc->hsphy_interface && |
| 465 | !strncmp(dwc->hsphy_interface, "ulpi", 4)) { |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 466 | reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 467 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 468 | } else { |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 469 | /* Relying on default value. */ |
| 470 | if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI)) |
| 471 | break; |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 472 | } |
| 473 | /* FALLTHROUGH */ |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 474 | case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI: |
| 475 | /* Making sure the interface and PHY are operational */ |
| 476 | ret = dwc3_soft_reset(dwc); |
| 477 | if (ret) |
| 478 | return ret; |
| 479 | |
| 480 | udelay(1); |
| 481 | |
| 482 | ret = dwc3_ulpi_init(dwc); |
| 483 | if (ret) |
| 484 | return ret; |
| 485 | /* FALLTHROUGH */ |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 486 | default: |
| 487 | break; |
| 488 | } |
| 489 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 490 | /* |
| 491 | * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to |
| 492 | * '0' during coreConsultant configuration. So default value will |
| 493 | * be '0' when the core is reset. Application needs to set it to |
| 494 | * '1' after the core initialization is completed. |
| 495 | */ |
| 496 | if (dwc->revision > DWC3_REVISION_194A) |
| 497 | reg |= DWC3_GUSB2PHYCFG_SUSPHY; |
| 498 | |
Felipe Balbi | cd72f89 | 2014-11-06 11:31:00 -0600 | [diff] [blame] | 499 | if (dwc->dis_u2_susphy_quirk) |
Huang Rui | 0effe0a | 2014-10-31 11:11:14 +0800 | [diff] [blame] | 500 | reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; |
| 501 | |
John Youn | ec791d1 | 2015-10-02 20:30:57 -0700 | [diff] [blame] | 502 | if (dwc->dis_enblslpm_quirk) |
| 503 | reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM; |
| 504 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 505 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 506 | |
| 507 | return 0; |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 511 | * dwc3_core_init - Low-level initialization of DWC3 Core |
| 512 | * @dwc: Pointer to our controller context structure |
| 513 | * |
| 514 | * Returns 0 on success otherwise negative errno. |
| 515 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 516 | static int dwc3_core_init(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 517 | { |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 518 | u32 hwparams4 = dwc->hwparams.hwparams4; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 519 | u32 reg; |
| 520 | int ret; |
| 521 | |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 522 | reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); |
| 523 | /* This should read as U3 followed by revision number */ |
John Youn | 690fb37 | 2015-09-04 19:15:10 -0700 | [diff] [blame] | 524 | if ((reg & DWC3_GSNPSID_MASK) == 0x55330000) { |
| 525 | /* Detected DWC_usb3 IP */ |
| 526 | dwc->revision = reg; |
| 527 | } else if ((reg & DWC3_GSNPSID_MASK) == 0x33310000) { |
| 528 | /* Detected DWC_usb31 IP */ |
| 529 | dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); |
| 530 | dwc->revision |= DWC3_REVISION_IS_DWC31; |
| 531 | } else { |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 532 | dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); |
| 533 | ret = -ENODEV; |
| 534 | goto err0; |
| 535 | } |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 536 | |
Felipe Balbi | fa0ea13 | 2014-09-19 15:51:11 -0500 | [diff] [blame] | 537 | /* |
| 538 | * Write Linux Version Code to our GUID register so it's easy to figure |
| 539 | * out which kernel version a bug was found. |
| 540 | */ |
| 541 | dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); |
| 542 | |
Paul Zimmerman | 0e1e5c4 | 2014-05-23 11:39:24 -0700 | [diff] [blame] | 543 | /* Handle USB2.0-only core configuration */ |
| 544 | if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == |
| 545 | DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { |
| 546 | if (dwc->maximum_speed == USB_SPEED_SUPER) |
| 547 | dwc->maximum_speed = USB_SPEED_HIGH; |
| 548 | } |
| 549 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 550 | /* issue device SoftReset too */ |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 551 | ret = dwc3_soft_reset(dwc); |
| 552 | if (ret) |
| 553 | goto err0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 554 | |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 555 | ret = dwc3_core_soft_reset(dwc); |
| 556 | if (ret) |
| 557 | goto err0; |
Pratyush Anand | 58a0f23 | 2012-06-21 17:44:29 +0530 | [diff] [blame] | 558 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 559 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
Paul Zimmerman | 3e87c42 | 2012-02-24 17:32:13 -0800 | [diff] [blame] | 560 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 561 | |
Sebastian Andrzej Siewior | 164d773 | 2011-11-24 11:22:05 +0100 | [diff] [blame] | 562 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 563 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: |
Felipe Balbi | 32a4a13 | 2014-02-25 14:00:13 -0600 | [diff] [blame] | 564 | /** |
| 565 | * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an |
| 566 | * issue which would cause xHCI compliance tests to fail. |
| 567 | * |
| 568 | * Because of that we cannot enable clock gating on such |
| 569 | * configurations. |
| 570 | * |
| 571 | * Refers to: |
| 572 | * |
| 573 | * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based |
| 574 | * SOF/ITP Mode Used |
| 575 | */ |
| 576 | if ((dwc->dr_mode == USB_DR_MODE_HOST || |
| 577 | dwc->dr_mode == USB_DR_MODE_OTG) && |
| 578 | (dwc->revision >= DWC3_REVISION_210A && |
| 579 | dwc->revision <= DWC3_REVISION_250A)) |
| 580 | reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC; |
| 581 | else |
| 582 | reg &= ~DWC3_GCTL_DSBLCLKGTNG; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 583 | break; |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 584 | case DWC3_GHWPARAMS1_EN_PWROPT_HIB: |
| 585 | /* enable hibernation here */ |
| 586 | dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); |
Huang Rui | 2eac399 | 2014-10-28 19:54:22 +0800 | [diff] [blame] | 587 | |
| 588 | /* |
| 589 | * REVISIT Enabling this bit so that host-mode hibernation |
| 590 | * will work. Device-mode hibernation is not yet implemented. |
| 591 | */ |
| 592 | reg |= DWC3_GCTL_GBLHIBERNATIONEN; |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 593 | break; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 594 | default: |
Felipe Balbi | 1407bf1 | 2015-11-16 16:06:37 -0600 | [diff] [blame] | 595 | dwc3_trace(trace_dwc3_core, "No power optimization available\n"); |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Huang Rui | 946bd57 | 2014-10-28 19:54:23 +0800 | [diff] [blame] | 598 | /* check if current dwc3 is on simulation board */ |
| 599 | if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { |
Felipe Balbi | 1407bf1 | 2015-11-16 16:06:37 -0600 | [diff] [blame] | 600 | dwc3_trace(trace_dwc3_core, |
| 601 | "running on FPGA platform\n"); |
Huang Rui | 946bd57 | 2014-10-28 19:54:23 +0800 | [diff] [blame] | 602 | dwc->is_fpga = true; |
| 603 | } |
| 604 | |
Huang Rui | 3b81221 | 2014-10-28 19:54:25 +0800 | [diff] [blame] | 605 | WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, |
| 606 | "disable_scramble cannot be used on non-FPGA builds\n"); |
| 607 | |
| 608 | if (dwc->disable_scramble_quirk && dwc->is_fpga) |
| 609 | reg |= DWC3_GCTL_DISSCRAMBLE; |
| 610 | else |
| 611 | reg &= ~DWC3_GCTL_DISSCRAMBLE; |
| 612 | |
Huang Rui | 9a5b2f3 | 2014-10-28 19:54:27 +0800 | [diff] [blame] | 613 | if (dwc->u2exit_lfps_quirk) |
| 614 | reg |= DWC3_GCTL_U2EXIT_LFPS; |
| 615 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 616 | /* |
| 617 | * WORKAROUND: DWC3 revisions <1.90a have a bug |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 618 | * where the device can fail to connect at SuperSpeed |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 619 | * and falls back to high-speed mode which causes |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 620 | * the device to enter a Connect/Disconnect loop |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 621 | */ |
| 622 | if (dwc->revision < DWC3_REVISION_190A) |
| 623 | reg |= DWC3_GCTL_U2RSTECN; |
| 624 | |
Felipe Balbi | 789451f6 | 2011-05-05 15:53:10 +0300 | [diff] [blame] | 625 | dwc3_core_num_eps(dwc); |
| 626 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 627 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 628 | |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 629 | ret = dwc3_alloc_scratch_buffers(dwc); |
| 630 | if (ret) |
| 631 | goto err1; |
| 632 | |
| 633 | ret = dwc3_setup_scratch_buffers(dwc); |
| 634 | if (ret) |
| 635 | goto err2; |
| 636 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 637 | return 0; |
| 638 | |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 639 | err2: |
| 640 | dwc3_free_scratch_buffers(dwc); |
| 641 | |
| 642 | err1: |
| 643 | usb_phy_shutdown(dwc->usb2_phy); |
| 644 | usb_phy_shutdown(dwc->usb3_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 645 | phy_exit(dwc->usb2_generic_phy); |
| 646 | phy_exit(dwc->usb3_generic_phy); |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 647 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 648 | err0: |
| 649 | return ret; |
| 650 | } |
| 651 | |
| 652 | static void dwc3_core_exit(struct dwc3 *dwc) |
| 653 | { |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 654 | dwc3_free_scratch_buffers(dwc); |
Vivek Gautam | 01b8daf | 2012-10-13 19:20:18 +0530 | [diff] [blame] | 655 | usb_phy_shutdown(dwc->usb2_phy); |
| 656 | usb_phy_shutdown(dwc->usb3_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 657 | phy_exit(dwc->usb2_generic_phy); |
| 658 | phy_exit(dwc->usb3_generic_phy); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 659 | } |
| 660 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 661 | static int dwc3_core_get_phy(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 662 | { |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 663 | struct device *dev = dwc->dev; |
Felipe Balbi | 941ea36 | 2013-07-31 09:21:25 +0300 | [diff] [blame] | 664 | struct device_node *node = dev->of_node; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 665 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 666 | |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 667 | if (node) { |
| 668 | dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); |
| 669 | dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); |
Felipe Balbi | bb67490 | 2013-08-14 13:21:23 -0500 | [diff] [blame] | 670 | } else { |
| 671 | dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
| 672 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 673 | } |
| 674 | |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 675 | if (IS_ERR(dwc->usb2_phy)) { |
| 676 | ret = PTR_ERR(dwc->usb2_phy); |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 677 | if (ret == -ENXIO || ret == -ENODEV) { |
| 678 | dwc->usb2_phy = NULL; |
| 679 | } else if (ret == -EPROBE_DEFER) { |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 680 | return ret; |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 681 | } else { |
| 682 | dev_err(dev, "no usb2 phy configured\n"); |
| 683 | return ret; |
| 684 | } |
Felipe Balbi | 51e1e7b | 2012-07-19 14:09:48 +0300 | [diff] [blame] | 685 | } |
| 686 | |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 687 | if (IS_ERR(dwc->usb3_phy)) { |
Ruchika Kharwar | 315955d7 | 2013-07-04 00:59:34 -0500 | [diff] [blame] | 688 | ret = PTR_ERR(dwc->usb3_phy); |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 689 | if (ret == -ENXIO || ret == -ENODEV) { |
| 690 | dwc->usb3_phy = NULL; |
| 691 | } else if (ret == -EPROBE_DEFER) { |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 692 | return ret; |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 693 | } else { |
| 694 | dev_err(dev, "no usb3 phy configured\n"); |
| 695 | return ret; |
| 696 | } |
Felipe Balbi | 51e1e7b | 2012-07-19 14:09:48 +0300 | [diff] [blame] | 697 | } |
| 698 | |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 699 | dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); |
| 700 | if (IS_ERR(dwc->usb2_generic_phy)) { |
| 701 | ret = PTR_ERR(dwc->usb2_generic_phy); |
| 702 | if (ret == -ENOSYS || ret == -ENODEV) { |
| 703 | dwc->usb2_generic_phy = NULL; |
| 704 | } else if (ret == -EPROBE_DEFER) { |
| 705 | return ret; |
| 706 | } else { |
| 707 | dev_err(dev, "no usb2 phy configured\n"); |
| 708 | return ret; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); |
| 713 | if (IS_ERR(dwc->usb3_generic_phy)) { |
| 714 | ret = PTR_ERR(dwc->usb3_generic_phy); |
| 715 | if (ret == -ENOSYS || ret == -ENODEV) { |
| 716 | dwc->usb3_generic_phy = NULL; |
| 717 | } else if (ret == -EPROBE_DEFER) { |
| 718 | return ret; |
| 719 | } else { |
| 720 | dev_err(dev, "no usb3 phy configured\n"); |
| 721 | return ret; |
| 722 | } |
| 723 | } |
| 724 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 728 | static int dwc3_core_init_mode(struct dwc3 *dwc) |
| 729 | { |
| 730 | struct device *dev = dwc->dev; |
| 731 | int ret; |
| 732 | |
| 733 | switch (dwc->dr_mode) { |
| 734 | case USB_DR_MODE_PERIPHERAL: |
| 735 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); |
| 736 | ret = dwc3_gadget_init(dwc); |
| 737 | if (ret) { |
| 738 | dev_err(dev, "failed to initialize gadget\n"); |
| 739 | return ret; |
| 740 | } |
| 741 | break; |
| 742 | case USB_DR_MODE_HOST: |
| 743 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); |
| 744 | ret = dwc3_host_init(dwc); |
| 745 | if (ret) { |
| 746 | dev_err(dev, "failed to initialize host\n"); |
| 747 | return ret; |
| 748 | } |
| 749 | break; |
| 750 | case USB_DR_MODE_OTG: |
| 751 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); |
| 752 | ret = dwc3_host_init(dwc); |
| 753 | if (ret) { |
| 754 | dev_err(dev, "failed to initialize host\n"); |
| 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | ret = dwc3_gadget_init(dwc); |
| 759 | if (ret) { |
| 760 | dev_err(dev, "failed to initialize gadget\n"); |
| 761 | return ret; |
| 762 | } |
| 763 | break; |
| 764 | default: |
| 765 | dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | static void dwc3_core_exit_mode(struct dwc3 *dwc) |
| 773 | { |
| 774 | switch (dwc->dr_mode) { |
| 775 | case USB_DR_MODE_PERIPHERAL: |
| 776 | dwc3_gadget_exit(dwc); |
| 777 | break; |
| 778 | case USB_DR_MODE_HOST: |
| 779 | dwc3_host_exit(dwc); |
| 780 | break; |
| 781 | case USB_DR_MODE_OTG: |
| 782 | dwc3_host_exit(dwc); |
| 783 | dwc3_gadget_exit(dwc); |
| 784 | break; |
| 785 | default: |
| 786 | /* do nothing */ |
| 787 | break; |
| 788 | } |
| 789 | } |
| 790 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 791 | #define DWC3_ALIGN_MASK (16 - 1) |
| 792 | |
| 793 | static int dwc3_probe(struct platform_device *pdev) |
| 794 | { |
| 795 | struct device *dev = &pdev->dev; |
| 796 | struct dwc3_platform_data *pdata = dev_get_platdata(dev); |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 797 | struct resource *res; |
| 798 | struct dwc3 *dwc; |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 799 | u8 lpm_nyet_threshold; |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 800 | u8 tx_de_emphasis; |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 801 | u8 hird_threshold; |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 802 | u32 fladj = 0; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 803 | |
Andy Shevchenko | b09e99e | 2014-05-15 15:53:32 +0300 | [diff] [blame] | 804 | int ret; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 805 | |
| 806 | void __iomem *regs; |
| 807 | void *mem; |
| 808 | |
| 809 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); |
Jingoo Han | 734d5a5 | 2014-07-17 12:45:11 +0900 | [diff] [blame] | 810 | if (!mem) |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 811 | return -ENOMEM; |
Jingoo Han | 734d5a5 | 2014-07-17 12:45:11 +0900 | [diff] [blame] | 812 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 813 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); |
| 814 | dwc->mem = mem; |
| 815 | dwc->dev = dev; |
| 816 | |
| 817 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 818 | if (!res) { |
| 819 | dev_err(dev, "missing IRQ\n"); |
| 820 | return -ENODEV; |
| 821 | } |
| 822 | dwc->xhci_resources[1].start = res->start; |
| 823 | dwc->xhci_resources[1].end = res->end; |
| 824 | dwc->xhci_resources[1].flags = res->flags; |
| 825 | dwc->xhci_resources[1].name = res->name; |
| 826 | |
| 827 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 828 | if (!res) { |
| 829 | dev_err(dev, "missing memory resource\n"); |
| 830 | return -ENODEV; |
| 831 | } |
| 832 | |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 833 | dwc->xhci_resources[0].start = res->start; |
| 834 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + |
| 835 | DWC3_XHCI_REGS_END; |
| 836 | dwc->xhci_resources[0].flags = res->flags; |
| 837 | dwc->xhci_resources[0].name = res->name; |
| 838 | |
| 839 | res->start += DWC3_GLOBALS_REGS_START; |
| 840 | |
| 841 | /* |
| 842 | * Request memory region but exclude xHCI regs, |
| 843 | * since it will be requested by the xhci-plat driver. |
| 844 | */ |
| 845 | regs = devm_ioremap_resource(dev, res); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 846 | if (IS_ERR(regs)) { |
| 847 | ret = PTR_ERR(regs); |
| 848 | goto err0; |
| 849 | } |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 850 | |
| 851 | dwc->regs = regs; |
| 852 | dwc->regs_size = resource_size(res); |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 853 | |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 854 | /* default to highest possible threshold */ |
| 855 | lpm_nyet_threshold = 0xff; |
| 856 | |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 857 | /* default to -3.5dB de-emphasis */ |
| 858 | tx_de_emphasis = 1; |
| 859 | |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 860 | /* |
| 861 | * default to assert utmi_sleep_n and use maximum allowed HIRD |
| 862 | * threshold value of 0b1100 |
| 863 | */ |
| 864 | hird_threshold = 12; |
| 865 | |
Heikki Krogerus | 63863b9 | 2015-09-21 11:14:32 +0300 | [diff] [blame] | 866 | dwc->maximum_speed = usb_get_maximum_speed(dev); |
Heikki Krogerus | 06e7114 | 2015-09-21 11:14:34 +0300 | [diff] [blame] | 867 | dwc->dr_mode = usb_get_dr_mode(dev); |
Heikki Krogerus | 63863b9 | 2015-09-21 11:14:32 +0300 | [diff] [blame] | 868 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 869 | dwc->has_lpm_erratum = device_property_read_bool(dev, |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 870 | "snps,has-lpm-erratum"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 871 | device_property_read_u8(dev, "snps,lpm-nyet-threshold", |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 872 | &lpm_nyet_threshold); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 873 | dwc->is_utmi_l1_suspend = device_property_read_bool(dev, |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 874 | "snps,is-utmi-l1-suspend"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 875 | device_property_read_u8(dev, "snps,hird-threshold", |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 876 | &hird_threshold); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 877 | dwc->usb3_lpm_capable = device_property_read_bool(dev, |
Robert Baldyga | eac68e8 | 2015-03-09 15:06:12 +0100 | [diff] [blame] | 878 | "snps,usb3_lpm_capable"); |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 879 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 880 | dwc->disable_scramble_quirk = device_property_read_bool(dev, |
Huang Rui | 3b81221 | 2014-10-28 19:54:25 +0800 | [diff] [blame] | 881 | "snps,disable_scramble_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 882 | dwc->u2exit_lfps_quirk = device_property_read_bool(dev, |
Huang Rui | 9a5b2f3 | 2014-10-28 19:54:27 +0800 | [diff] [blame] | 883 | "snps,u2exit_lfps_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 884 | dwc->u2ss_inp3_quirk = device_property_read_bool(dev, |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 885 | "snps,u2ss_inp3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 886 | dwc->req_p1p2p3_quirk = device_property_read_bool(dev, |
Huang Rui | df31f5b | 2014-10-28 19:54:29 +0800 | [diff] [blame] | 887 | "snps,req_p1p2p3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 888 | dwc->del_p1p2p3_quirk = device_property_read_bool(dev, |
Huang Rui | a2a1d0f | 2014-10-28 19:54:30 +0800 | [diff] [blame] | 889 | "snps,del_p1p2p3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 890 | dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, |
Huang Rui | 41c06ff | 2014-10-28 19:54:31 +0800 | [diff] [blame] | 891 | "snps,del_phy_power_chg_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 892 | dwc->lfps_filter_quirk = device_property_read_bool(dev, |
Huang Rui | fb67afc | 2014-10-28 19:54:32 +0800 | [diff] [blame] | 893 | "snps,lfps_filter_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 894 | dwc->rx_detect_poll_quirk = device_property_read_bool(dev, |
Huang Rui | 14f4ac5 | 2014-10-28 19:54:33 +0800 | [diff] [blame] | 895 | "snps,rx_detect_poll_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 896 | dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, |
Huang Rui | 59acfa2 | 2014-10-31 11:11:13 +0800 | [diff] [blame] | 897 | "snps,dis_u3_susphy_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 898 | dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, |
Huang Rui | 0effe0a | 2014-10-31 11:11:14 +0800 | [diff] [blame] | 899 | "snps,dis_u2_susphy_quirk"); |
John Youn | ec791d1 | 2015-10-02 20:30:57 -0700 | [diff] [blame] | 900 | dwc->dis_enblslpm_quirk = device_property_read_bool(dev, |
| 901 | "snps,dis_enblslpm_quirk"); |
Rajesh Bhagat | e58dd35 | 2016-03-14 14:40:50 +0530 | [diff] [blame] | 902 | dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, |
| 903 | "snps,dis_rxdet_inp3_quirk"); |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 904 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 905 | dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 906 | "snps,tx_de_emphasis_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 907 | device_property_read_u8(dev, "snps,tx_de_emphasis", |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 908 | &tx_de_emphasis); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 909 | device_property_read_string(dev, "snps,hsphy_interface", |
| 910 | &dwc->hsphy_interface); |
| 911 | device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", |
| 912 | &fladj); |
| 913 | |
| 914 | if (pdata) { |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 915 | dwc->maximum_speed = pdata->maximum_speed; |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 916 | dwc->has_lpm_erratum = pdata->has_lpm_erratum; |
| 917 | if (pdata->lpm_nyet_threshold) |
| 918 | lpm_nyet_threshold = pdata->lpm_nyet_threshold; |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 919 | dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend; |
| 920 | if (pdata->hird_threshold) |
| 921 | hird_threshold = pdata->hird_threshold; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 922 | |
Robert Baldyga | eac68e8 | 2015-03-09 15:06:12 +0100 | [diff] [blame] | 923 | dwc->usb3_lpm_capable = pdata->usb3_lpm_capable; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 924 | dwc->dr_mode = pdata->dr_mode; |
Huang Rui | 3b81221 | 2014-10-28 19:54:25 +0800 | [diff] [blame] | 925 | |
| 926 | dwc->disable_scramble_quirk = pdata->disable_scramble_quirk; |
Huang Rui | 9a5b2f3 | 2014-10-28 19:54:27 +0800 | [diff] [blame] | 927 | dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk; |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 928 | dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk; |
Huang Rui | df31f5b | 2014-10-28 19:54:29 +0800 | [diff] [blame] | 929 | dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk; |
Huang Rui | a2a1d0f | 2014-10-28 19:54:30 +0800 | [diff] [blame] | 930 | dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk; |
Huang Rui | 41c06ff | 2014-10-28 19:54:31 +0800 | [diff] [blame] | 931 | dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk; |
Huang Rui | fb67afc | 2014-10-28 19:54:32 +0800 | [diff] [blame] | 932 | dwc->lfps_filter_quirk = pdata->lfps_filter_quirk; |
Huang Rui | 14f4ac5 | 2014-10-28 19:54:33 +0800 | [diff] [blame] | 933 | dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk; |
Huang Rui | 59acfa2 | 2014-10-31 11:11:13 +0800 | [diff] [blame] | 934 | dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk; |
Huang Rui | 0effe0a | 2014-10-31 11:11:14 +0800 | [diff] [blame] | 935 | dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk; |
John Youn | ec791d1 | 2015-10-02 20:30:57 -0700 | [diff] [blame] | 936 | dwc->dis_enblslpm_quirk = pdata->dis_enblslpm_quirk; |
Rajesh Bhagat | e58dd35 | 2016-03-14 14:40:50 +0530 | [diff] [blame] | 937 | dwc->dis_rxdet_inp3_quirk = pdata->dis_rxdet_inp3_quirk; |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 938 | |
| 939 | dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk; |
| 940 | if (pdata->tx_de_emphasis) |
| 941 | tx_de_emphasis = pdata->tx_de_emphasis; |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 942 | |
| 943 | dwc->hsphy_interface = pdata->hsphy_interface; |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 944 | fladj = pdata->fladj_value; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 945 | } |
| 946 | |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 947 | dwc->lpm_nyet_threshold = lpm_nyet_threshold; |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 948 | dwc->tx_de_emphasis = tx_de_emphasis; |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 949 | |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 950 | dwc->hird_threshold = hird_threshold |
| 951 | | (dwc->is_utmi_l1_suspend << 4); |
| 952 | |
Heikki Krogerus | 6c89cce0 | 2015-05-13 15:26:45 +0300 | [diff] [blame] | 953 | platform_set_drvdata(pdev, dwc); |
Heikki Krogerus | 2917e71 | 2015-05-13 15:26:46 +0300 | [diff] [blame] | 954 | dwc3_cache_hwparams(dwc); |
Heikki Krogerus | 6c89cce0 | 2015-05-13 15:26:45 +0300 | [diff] [blame] | 955 | |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 956 | ret = dwc3_phy_setup(dwc); |
| 957 | if (ret) |
| 958 | goto err0; |
Heikki Krogerus | 45bb7de | 2015-05-13 15:26:48 +0300 | [diff] [blame] | 959 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 960 | ret = dwc3_core_get_phy(dwc); |
| 961 | if (ret) |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 962 | goto err0; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 963 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 964 | spin_lock_init(&dwc->lock); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 965 | |
Heikki Krogerus | 19bacdc | 2014-09-24 11:00:38 +0300 | [diff] [blame] | 966 | if (!dev->dma_mask) { |
| 967 | dev->dma_mask = dev->parent->dma_mask; |
| 968 | dev->dma_parms = dev->parent->dma_parms; |
| 969 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); |
| 970 | } |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 971 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 972 | pm_runtime_enable(dev); |
| 973 | pm_runtime_get_sync(dev); |
| 974 | pm_runtime_forbid(dev); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 975 | |
Felipe Balbi | 3921426 | 2012-10-11 13:54:36 +0300 | [diff] [blame] | 976 | ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); |
| 977 | if (ret) { |
| 978 | dev_err(dwc->dev, "failed to allocate event buffers\n"); |
| 979 | ret = -ENOMEM; |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 980 | goto err1; |
Felipe Balbi | 3921426 | 2012-10-11 13:54:36 +0300 | [diff] [blame] | 981 | } |
| 982 | |
Felipe Balbi | 32a4a13 | 2014-02-25 14:00:13 -0600 | [diff] [blame] | 983 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) |
| 984 | dwc->dr_mode = USB_DR_MODE_HOST; |
| 985 | else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) |
| 986 | dwc->dr_mode = USB_DR_MODE_PERIPHERAL; |
| 987 | |
| 988 | if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) |
| 989 | dwc->dr_mode = USB_DR_MODE_OTG; |
| 990 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 991 | ret = dwc3_core_init(dwc); |
| 992 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 993 | dev_err(dev, "failed to initialize core\n"); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 994 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 995 | } |
| 996 | |
John Youn | 77966eb | 2016-02-19 17:31:01 -0800 | [diff] [blame] | 997 | /* Check the maximum_speed parameter */ |
| 998 | switch (dwc->maximum_speed) { |
| 999 | case USB_SPEED_LOW: |
| 1000 | case USB_SPEED_FULL: |
| 1001 | case USB_SPEED_HIGH: |
| 1002 | case USB_SPEED_SUPER: |
| 1003 | case USB_SPEED_SUPER_PLUS: |
| 1004 | break; |
| 1005 | default: |
| 1006 | dev_err(dev, "invalid maximum_speed parameter %d\n", |
| 1007 | dwc->maximum_speed); |
| 1008 | /* fall through */ |
| 1009 | case USB_SPEED_UNKNOWN: |
| 1010 | /* default to superspeed */ |
John Youn | 2c7f1bd | 2016-02-05 17:08:59 -0800 | [diff] [blame] | 1011 | dwc->maximum_speed = USB_SPEED_SUPER; |
| 1012 | |
| 1013 | /* |
| 1014 | * default to superspeed plus if we are capable. |
| 1015 | */ |
| 1016 | if (dwc3_is_usb31(dwc) && |
| 1017 | (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == |
| 1018 | DWC3_GHWPARAMS3_SSPHY_IFC_GEN2)) |
| 1019 | dwc->maximum_speed = USB_SPEED_SUPER_PLUS; |
John Youn | 77966eb | 2016-02-19 17:31:01 -0800 | [diff] [blame] | 1020 | |
| 1021 | break; |
John Youn | 2c7f1bd | 2016-02-05 17:08:59 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 1024 | /* Adjust Frame Length */ |
| 1025 | dwc3_frame_length_adjustment(dwc, fladj); |
| 1026 | |
Kishon Vijay Abraham I | 3088f10 | 2013-11-25 15:31:21 +0530 | [diff] [blame] | 1027 | usb_phy_set_suspend(dwc->usb2_phy, 0); |
| 1028 | usb_phy_set_suspend(dwc->usb3_phy, 0); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1029 | ret = phy_power_on(dwc->usb2_generic_phy); |
| 1030 | if (ret < 0) |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1031 | goto err2; |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1032 | |
| 1033 | ret = phy_power_on(dwc->usb3_generic_phy); |
| 1034 | if (ret < 0) |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1035 | goto err3; |
Kishon Vijay Abraham I | 3088f10 | 2013-11-25 15:31:21 +0530 | [diff] [blame] | 1036 | |
Felipe Balbi | f122d33 | 2013-02-08 15:15:11 +0200 | [diff] [blame] | 1037 | ret = dwc3_event_buffers_setup(dwc); |
| 1038 | if (ret) { |
| 1039 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1040 | goto err4; |
Felipe Balbi | f122d33 | 2013-02-08 15:15:11 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 1043 | ret = dwc3_core_init_mode(dwc); |
| 1044 | if (ret) |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1045 | goto err5; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1046 | |
Du, Changbin | 4e9f311 | 2016-04-12 19:10:18 +0800 | [diff] [blame] | 1047 | dwc3_debugfs_init(dwc); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 1048 | pm_runtime_allow(dev); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1049 | |
| 1050 | return 0; |
| 1051 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1052 | err5: |
Felipe Balbi | f122d33 | 2013-02-08 15:15:11 +0200 | [diff] [blame] | 1053 | dwc3_event_buffers_cleanup(dwc); |
| 1054 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1055 | err4: |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1056 | phy_power_off(dwc->usb3_generic_phy); |
| 1057 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1058 | err3: |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1059 | phy_power_off(dwc->usb2_generic_phy); |
| 1060 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1061 | err2: |
Kishon Vijay Abraham I | 501fae5 | 2013-11-25 15:31:22 +0530 | [diff] [blame] | 1062 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
| 1063 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1064 | dwc3_core_exit(dwc); |
| 1065 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1066 | err1: |
Felipe Balbi | 3921426 | 2012-10-11 13:54:36 +0300 | [diff] [blame] | 1067 | dwc3_free_event_buffers(dwc); |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 1068 | dwc3_ulpi_exit(dwc); |
Felipe Balbi | 3921426 | 2012-10-11 13:54:36 +0300 | [diff] [blame] | 1069 | |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1070 | err0: |
| 1071 | /* |
| 1072 | * restore res->start back to its original value so that, in case the |
| 1073 | * probe is deferred, we don't end up getting error in request the |
| 1074 | * memory region the next time probe is called. |
| 1075 | */ |
| 1076 | res->start -= DWC3_GLOBALS_REGS_START; |
| 1077 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1078 | return ret; |
| 1079 | } |
| 1080 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 1081 | static int dwc3_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1082 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1083 | struct dwc3 *dwc = platform_get_drvdata(pdev); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1084 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1085 | |
| 1086 | /* |
| 1087 | * restore res->start back to its original value so that, in case the |
| 1088 | * probe is deferred, we don't end up getting error in request the |
| 1089 | * memory region the next time probe is called. |
| 1090 | */ |
| 1091 | res->start -= DWC3_GLOBALS_REGS_START; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1092 | |
Felipe Balbi | dc99f16 | 2014-09-03 16:13:37 -0500 | [diff] [blame] | 1093 | dwc3_debugfs_exit(dwc); |
| 1094 | dwc3_core_exit_mode(dwc); |
| 1095 | dwc3_event_buffers_cleanup(dwc); |
| 1096 | dwc3_free_event_buffers(dwc); |
| 1097 | |
Kishon Vijay Abraham I | 8ba007a | 2013-01-25 08:30:54 +0530 | [diff] [blame] | 1098 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
| 1099 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1100 | phy_power_off(dwc->usb2_generic_phy); |
| 1101 | phy_power_off(dwc->usb3_generic_phy); |
Kishon Vijay Abraham I | 8ba007a | 2013-01-25 08:30:54 +0530 | [diff] [blame] | 1102 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1103 | dwc3_core_exit(dwc); |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 1104 | dwc3_ulpi_exit(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1105 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1106 | pm_runtime_put_sync(&pdev->dev); |
| 1107 | pm_runtime_disable(&pdev->dev); |
| 1108 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1109 | return 0; |
| 1110 | } |
| 1111 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1112 | #ifdef CONFIG_PM_SLEEP |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1113 | static int dwc3_suspend(struct device *dev) |
| 1114 | { |
| 1115 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1116 | unsigned long flags; |
| 1117 | |
| 1118 | spin_lock_irqsave(&dwc->lock, flags); |
| 1119 | |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1120 | switch (dwc->dr_mode) { |
| 1121 | case USB_DR_MODE_PERIPHERAL: |
| 1122 | case USB_DR_MODE_OTG: |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1123 | dwc3_gadget_suspend(dwc); |
| 1124 | /* FALLTHROUGH */ |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1125 | case USB_DR_MODE_HOST: |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1126 | default: |
Felipe Balbi | 0b0231a | 2014-10-07 10:19:23 -0500 | [diff] [blame] | 1127 | dwc3_event_buffers_cleanup(dwc); |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1128 | break; |
| 1129 | } |
| 1130 | |
| 1131 | dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 1132 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 1133 | |
| 1134 | usb_phy_shutdown(dwc->usb3_phy); |
| 1135 | usb_phy_shutdown(dwc->usb2_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1136 | phy_exit(dwc->usb2_generic_phy); |
| 1137 | phy_exit(dwc->usb3_generic_phy); |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1138 | |
Sekhar Nori | 6344475 | 2015-08-31 21:09:08 +0530 | [diff] [blame] | 1139 | pinctrl_pm_select_sleep_state(dev); |
| 1140 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static int dwc3_resume(struct device *dev) |
| 1145 | { |
| 1146 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1147 | unsigned long flags; |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1148 | int ret; |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1149 | |
Sekhar Nori | 6344475 | 2015-08-31 21:09:08 +0530 | [diff] [blame] | 1150 | pinctrl_pm_select_default_state(dev); |
| 1151 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1152 | usb_phy_init(dwc->usb3_phy); |
| 1153 | usb_phy_init(dwc->usb2_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1154 | ret = phy_init(dwc->usb2_generic_phy); |
| 1155 | if (ret < 0) |
| 1156 | return ret; |
| 1157 | |
| 1158 | ret = phy_init(dwc->usb3_generic_phy); |
| 1159 | if (ret < 0) |
| 1160 | goto err_usb2phy_init; |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1161 | |
| 1162 | spin_lock_irqsave(&dwc->lock, flags); |
| 1163 | |
Felipe Balbi | 0b0231a | 2014-10-07 10:19:23 -0500 | [diff] [blame] | 1164 | dwc3_event_buffers_setup(dwc); |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1165 | dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); |
| 1166 | |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1167 | switch (dwc->dr_mode) { |
| 1168 | case USB_DR_MODE_PERIPHERAL: |
| 1169 | case USB_DR_MODE_OTG: |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1170 | dwc3_gadget_resume(dwc); |
| 1171 | /* FALLTHROUGH */ |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1172 | case USB_DR_MODE_HOST: |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1173 | default: |
| 1174 | /* do nothing */ |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 1179 | |
| 1180 | pm_runtime_disable(dev); |
| 1181 | pm_runtime_set_active(dev); |
| 1182 | pm_runtime_enable(dev); |
| 1183 | |
| 1184 | return 0; |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1185 | |
| 1186 | err_usb2phy_init: |
| 1187 | phy_exit(dwc->usb2_generic_phy); |
| 1188 | |
| 1189 | return ret; |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static const struct dev_pm_ops dwc3_dev_pm_ops = { |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1193 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) |
| 1194 | }; |
| 1195 | |
| 1196 | #define DWC3_PM_OPS &(dwc3_dev_pm_ops) |
| 1197 | #else |
| 1198 | #define DWC3_PM_OPS NULL |
| 1199 | #endif |
| 1200 | |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1201 | #ifdef CONFIG_OF |
| 1202 | static const struct of_device_id of_dwc3_match[] = { |
| 1203 | { |
Felipe Balbi | 22a5aa1 | 2013-07-02 21:20:24 +0300 | [diff] [blame] | 1204 | .compatible = "snps,dwc3" |
| 1205 | }, |
| 1206 | { |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1207 | .compatible = "synopsys,dwc3" |
| 1208 | }, |
| 1209 | { }, |
| 1210 | }; |
| 1211 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
| 1212 | #endif |
| 1213 | |
Heikki Krogerus | 404905a | 2014-09-25 10:57:02 +0300 | [diff] [blame] | 1214 | #ifdef CONFIG_ACPI |
| 1215 | |
| 1216 | #define ACPI_ID_INTEL_BSW "808622B7" |
| 1217 | |
| 1218 | static const struct acpi_device_id dwc3_acpi_match[] = { |
| 1219 | { ACPI_ID_INTEL_BSW, 0 }, |
| 1220 | { }, |
| 1221 | }; |
| 1222 | MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match); |
| 1223 | #endif |
| 1224 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1225 | static struct platform_driver dwc3_driver = { |
| 1226 | .probe = dwc3_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 1227 | .remove = dwc3_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1228 | .driver = { |
| 1229 | .name = "dwc3", |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1230 | .of_match_table = of_match_ptr(of_dwc3_match), |
Heikki Krogerus | 404905a | 2014-09-25 10:57:02 +0300 | [diff] [blame] | 1231 | .acpi_match_table = ACPI_PTR(dwc3_acpi_match), |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1232 | .pm = DWC3_PM_OPS, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1233 | }, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1234 | }; |
| 1235 | |
Tobias Klauser | b1116dc | 2012-02-28 12:57:20 +0100 | [diff] [blame] | 1236 | module_platform_driver(dwc3_driver); |
| 1237 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 1238 | MODULE_ALIAS("platform:dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1239 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 1240 | MODULE_LICENSE("GPL v2"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1241 | MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); |