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