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