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> |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 38 | #include <linux/irq.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 39 | |
| 40 | #include <linux/usb/ch9.h> |
| 41 | #include <linux/usb/gadget.h> |
Felipe Balbi | f7e846f | 2013-06-30 14:29:51 +0300 | [diff] [blame] | 42 | #include <linux/usb/of.h> |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 43 | #include <linux/usb/otg.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 44 | |
| 45 | #include "core.h" |
| 46 | #include "gadget.h" |
| 47 | #include "io.h" |
| 48 | |
| 49 | #include "debug.h" |
| 50 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 51 | #define DWC3_DEFAULT_AUTOSUSPEND_DELAY 5000 /* ms */ |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 52 | |
Mayank Rana | 861da2b | 2016-07-13 13:47:57 -0700 | [diff] [blame^] | 53 | static int count; |
| 54 | static struct dwc3 *dwc3_instance[DWC_CTRL_COUNT]; |
| 55 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 56 | void dwc3_usb3_phy_suspend(struct dwc3 *dwc, int suspend) |
| 57 | { |
| 58 | u32 reg; |
| 59 | |
| 60 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 61 | |
| 62 | if (suspend) |
| 63 | reg |= DWC3_GUSB3PIPECTL_SUSPHY; |
| 64 | else |
| 65 | reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; |
| 66 | |
| 67 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 68 | } |
| 69 | |
Thinh Nguyen | 9d6173e | 2016-09-06 19:22:03 -0700 | [diff] [blame] | 70 | /** |
| 71 | * dwc3_get_dr_mode - Validates and sets dr_mode |
| 72 | * @dwc: pointer to our context structure |
| 73 | */ |
| 74 | static int dwc3_get_dr_mode(struct dwc3 *dwc) |
| 75 | { |
| 76 | enum usb_dr_mode mode; |
| 77 | struct device *dev = dwc->dev; |
| 78 | unsigned int hw_mode; |
| 79 | |
Thinh Nguyen | 9d6173e | 2016-09-06 19:22:03 -0700 | [diff] [blame] | 80 | |
Mayank Rana | fb9cd93 | 2016-11-03 23:26:38 -0700 | [diff] [blame] | 81 | dwc->is_drd = 0; |
Thinh Nguyen | 9d6173e | 2016-09-06 19:22:03 -0700 | [diff] [blame] | 82 | mode = dwc->dr_mode; |
| 83 | hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0); |
| 84 | |
| 85 | switch (hw_mode) { |
| 86 | case DWC3_GHWPARAMS0_MODE_GADGET: |
| 87 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) { |
| 88 | dev_err(dev, |
| 89 | "Controller does not support host mode.\n"); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | mode = USB_DR_MODE_PERIPHERAL; |
| 93 | break; |
| 94 | case DWC3_GHWPARAMS0_MODE_HOST: |
| 95 | if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) { |
| 96 | dev_err(dev, |
| 97 | "Controller does not support device mode.\n"); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | mode = USB_DR_MODE_HOST; |
| 101 | break; |
| 102 | default: |
| 103 | if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) |
| 104 | mode = USB_DR_MODE_HOST; |
| 105 | else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) |
| 106 | mode = USB_DR_MODE_PERIPHERAL; |
| 107 | } |
| 108 | |
| 109 | if (mode != dwc->dr_mode) { |
| 110 | dev_warn(dev, |
| 111 | "Configuration mismatch. dr_mode forced to %s\n", |
| 112 | mode == USB_DR_MODE_HOST ? "host" : "gadget"); |
| 113 | |
| 114 | dwc->dr_mode = mode; |
| 115 | } |
| 116 | |
Mayank Rana | fb9cd93 | 2016-11-03 23:26:38 -0700 | [diff] [blame] | 117 | if (dwc->dr_mode == USB_DR_MODE_OTG) |
| 118 | dwc->is_drd = 1; |
| 119 | |
Thinh Nguyen | 9d6173e | 2016-09-06 19:22:03 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 123 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) |
| 124 | { |
| 125 | u32 reg; |
| 126 | |
| 127 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 128 | reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); |
| 129 | reg |= DWC3_GCTL_PRTCAPDIR(mode); |
| 130 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Set this bit so that device attempts three more times at SS, even |
| 134 | * if it failed previously to operate in SS mode. |
| 135 | */ |
| 136 | reg |= DWC3_GCTL_U2RSTECN; |
| 137 | reg &= ~(DWC3_GCTL_SOFITPSYNC); |
| 138 | reg &= ~(DWC3_GCTL_PWRDNSCALEMASK); |
| 139 | reg |= DWC3_GCTL_PWRDNSCALE(2); |
| 140 | reg |= DWC3_GCTL_U2EXIT_LFPS; |
| 141 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 142 | |
| 143 | if (mode == DWC3_GCTL_PRTCAP_OTG || mode == DWC3_GCTL_PRTCAP_HOST) { |
| 144 | /* |
| 145 | * Allow ITP generated off of ref clk based counter instead |
| 146 | * of UTMI/ULPI clk based counter, when superspeed only is |
| 147 | * active so that UTMI/ULPI PHY can be suspened. |
| 148 | * |
| 149 | * Starting with revision 2.50A, GFLADJ_REFCLK_LPM_SEL is used |
| 150 | * instead. |
| 151 | */ |
| 152 | if (dwc->revision < DWC3_REVISION_250A) { |
| 153 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 154 | reg |= DWC3_GCTL_SOFITPSYNC; |
| 155 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 156 | } else { |
| 157 | reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); |
| 158 | reg |= DWC3_GFLADJ_REFCLK_LPM_SEL; |
| 159 | dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); |
| 160 | } |
| 161 | } |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 162 | } |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 163 | |
Felipe Balbi | cf6d867 | 2016-04-14 15:03:39 +0300 | [diff] [blame] | 164 | u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type) |
| 165 | { |
| 166 | struct dwc3 *dwc = dep->dwc; |
| 167 | u32 reg; |
| 168 | |
| 169 | dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE, |
| 170 | DWC3_GDBGFIFOSPACE_NUM(dep->number) | |
| 171 | DWC3_GDBGFIFOSPACE_TYPE(type)); |
| 172 | |
| 173 | reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE); |
| 174 | |
| 175 | return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg); |
| 176 | } |
| 177 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 178 | /** |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 179 | * Peforms initialization of HS and SS PHYs. |
| 180 | * If used as a part of POR or init sequence it is recommended |
| 181 | * that we should perform hard reset of the PHYs prior to invoking |
| 182 | * this function. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 183 | * @dwc: pointer to our context structure |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 184 | */ |
| 185 | static int dwc3_init_usb_phys(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 186 | { |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 187 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 188 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 189 | /* Bring up PHYs */ |
| 190 | ret = usb_phy_init(dwc->usb2_phy); |
| 191 | if (ret) { |
| 192 | pr_err("%s: usb_phy_init(dwc->usb2_phy) returned %d\n", |
| 193 | __func__, ret); |
| 194 | return ret; |
| 195 | } |
| 196 | |
Hemant Kumar | de1df69 | 2016-04-26 19:36:48 -0700 | [diff] [blame] | 197 | if (dwc->maximum_speed == USB_SPEED_HIGH) |
| 198 | goto generic_phy_init; |
| 199 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 200 | ret = usb_phy_init(dwc->usb3_phy); |
| 201 | if (ret == -EBUSY) { |
| 202 | /* |
| 203 | * Setting Max speed as high when USB3 PHY initialiation |
| 204 | * is failing and USB superspeed can't be supported. |
| 205 | */ |
| 206 | dwc->maximum_speed = USB_SPEED_HIGH; |
| 207 | } else if (ret) { |
| 208 | pr_err("%s: usb_phy_init(dwc->usb3_phy) returned %d\n", |
| 209 | __func__, ret); |
| 210 | return ret; |
| 211 | } |
Hemant Kumar | de1df69 | 2016-04-26 19:36:48 -0700 | [diff] [blame] | 212 | |
| 213 | generic_phy_init: |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 214 | ret = phy_init(dwc->usb2_generic_phy); |
| 215 | if (ret < 0) |
| 216 | return ret; |
| 217 | |
| 218 | ret = phy_init(dwc->usb3_generic_phy); |
| 219 | if (ret < 0) { |
| 220 | phy_exit(dwc->usb2_generic_phy); |
| 221 | return ret; |
| 222 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 223 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 224 | return 0; |
| 225 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 226 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 227 | /** |
| 228 | * dwc3_core_reset - Issues core soft reset and PHY reset |
| 229 | * @dwc: pointer to our context structure |
| 230 | */ |
| 231 | static int dwc3_core_reset(struct dwc3 *dwc) |
| 232 | { |
| 233 | int ret; |
Mayank Rana | f8ebb7f | 2016-09-08 11:09:37 -0700 | [diff] [blame] | 234 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 235 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 236 | /* Reset PHYs */ |
| 237 | usb_phy_reset(dwc->usb2_phy); |
Hemant Kumar | de1df69 | 2016-04-26 19:36:48 -0700 | [diff] [blame] | 238 | |
| 239 | if (dwc->maximum_speed == USB_SPEED_SUPER) |
| 240 | usb_phy_reset(dwc->usb3_phy); |
Pratyush Anand | 45627ac | 2012-06-21 17:44:28 +0530 | [diff] [blame] | 241 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 242 | /* Initialize PHYs */ |
| 243 | ret = dwc3_init_usb_phys(dwc); |
| 244 | if (ret) { |
| 245 | pr_err("%s: dwc3_init_phys returned %d\n", |
| 246 | __func__, ret); |
| 247 | return ret; |
| 248 | } |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 249 | |
Mayank Rana | f8ebb7f | 2016-09-08 11:09:37 -0700 | [diff] [blame] | 250 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 251 | reg &= ~DWC3_GUSB3PIPECTL_DELAYP1TRANS; |
| 252 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 253 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 254 | dwc3_notify_event(dwc, DWC3_CONTROLLER_RESET_EVENT); |
| 255 | |
| 256 | dwc3_notify_event(dwc, DWC3_CONTROLLER_POST_RESET_EVENT); |
| 257 | |
| 258 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 262 | * dwc3_soft_reset - Issue soft reset |
| 263 | * @dwc: Pointer to our controller context structure |
| 264 | */ |
| 265 | static int dwc3_soft_reset(struct dwc3 *dwc) |
| 266 | { |
| 267 | unsigned long timeout; |
| 268 | u32 reg; |
| 269 | |
| 270 | timeout = jiffies + msecs_to_jiffies(500); |
| 271 | dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); |
| 272 | do { |
| 273 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 274 | if (!(reg & DWC3_DCTL_CSFTRST)) |
| 275 | break; |
| 276 | |
| 277 | if (time_after(jiffies, timeout)) { |
| 278 | dev_err(dwc->dev, "Reset Timed Out\n"); |
| 279 | return -ETIMEDOUT; |
| 280 | } |
| 281 | |
| 282 | cpu_relax(); |
| 283 | } while (true); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 288 | /* |
| 289 | * dwc3_frame_length_adjustment - Adjusts frame length if required |
| 290 | * @dwc3: Pointer to our controller context structure |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 291 | */ |
Felipe Balbi | bcdb327 | 2016-05-16 10:42:23 +0300 | [diff] [blame] | 292 | static void dwc3_frame_length_adjustment(struct dwc3 *dwc) |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 293 | { |
| 294 | u32 reg; |
| 295 | u32 dft; |
| 296 | |
| 297 | if (dwc->revision < DWC3_REVISION_250A) |
| 298 | return; |
| 299 | |
Felipe Balbi | bcdb327 | 2016-05-16 10:42:23 +0300 | [diff] [blame] | 300 | if (dwc->fladj == 0) |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 301 | return; |
| 302 | |
| 303 | reg = dwc3_readl(dwc->regs, DWC3_GFLADJ); |
| 304 | dft = reg & DWC3_GFLADJ_30MHZ_MASK; |
Felipe Balbi | bcdb327 | 2016-05-16 10:42:23 +0300 | [diff] [blame] | 305 | if (!dev_WARN_ONCE(dwc->dev, dft == dwc->fladj, |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 306 | "request value same as default, ignoring\n")) { |
| 307 | reg &= ~DWC3_GFLADJ_30MHZ_MASK; |
Felipe Balbi | bcdb327 | 2016-05-16 10:42:23 +0300 | [diff] [blame] | 308 | reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj; |
Nikhil Badola | db2be4e | 2015-09-04 10:15:58 +0530 | [diff] [blame] | 309 | dwc3_writel(dwc->regs, DWC3_GFLADJ, reg); |
| 310 | } |
| 311 | } |
| 312 | |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 313 | /** |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 314 | * dwc3_free_one_event_buffer - Frees one event buffer |
| 315 | * @dwc: Pointer to our controller context structure |
| 316 | * @evt: Pointer to event buffer to be freed |
| 317 | */ |
| 318 | static void dwc3_free_one_event_buffer(struct dwc3 *dwc, |
| 319 | struct dwc3_event_buffer *evt) |
| 320 | { |
| 321 | dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /** |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 325 | * dwc3_alloc_one_event_buffer - Allocates one event buffer structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 326 | * @dwc: Pointer to our controller context structure |
| 327 | * @length: size of the event buffer |
| 328 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 329 | * Returns a pointer to the allocated event buffer structure on success |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 330 | * otherwise ERR_PTR(errno). |
| 331 | */ |
Felipe Balbi | 67d0b50 | 2013-02-22 16:31:07 +0200 | [diff] [blame] | 332 | static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, |
| 333 | unsigned length) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 334 | { |
| 335 | struct dwc3_event_buffer *evt; |
| 336 | |
Felipe Balbi | 380f0d2 | 2012-10-11 13:48:36 +0300 | [diff] [blame] | 337 | evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 338 | if (!evt) |
| 339 | return ERR_PTR(-ENOMEM); |
| 340 | |
| 341 | evt->dwc = dwc; |
| 342 | evt->length = length; |
| 343 | evt->buf = dma_alloc_coherent(dwc->dev, length, |
| 344 | &evt->dma, GFP_KERNEL); |
Felipe Balbi | e32672f | 2012-11-08 15:26:41 +0200 | [diff] [blame] | 345 | if (!evt->buf) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 346 | return ERR_PTR(-ENOMEM); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 347 | |
| 348 | return evt; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * dwc3_free_event_buffers - frees all allocated event buffers |
| 353 | * @dwc: Pointer to our controller context structure |
| 354 | */ |
| 355 | static void dwc3_free_event_buffers(struct dwc3 *dwc) |
| 356 | { |
| 357 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 358 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 359 | evt = dwc->ev_buf; |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 360 | if (evt) |
| 361 | dwc3_free_one_event_buffer(dwc, evt); |
Mayank Rana | f4918d3 | 2016-12-15 13:35:55 -0800 | [diff] [blame] | 362 | |
| 363 | /* free GSI related event buffers */ |
| 364 | dwc3_notify_event(dwc, DWC3_GSI_EVT_BUF_FREE); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
| 368 | * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 369 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 370 | * @length: size of event buffer |
| 371 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 372 | * Returns 0 on success otherwise negative errno. In the error case, dwc |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 373 | * may contain some buffers allocated but not all which were requested. |
| 374 | */ |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 375 | static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 376 | { |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 377 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 378 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 379 | evt = dwc3_alloc_one_event_buffer(dwc, length); |
| 380 | if (IS_ERR(evt)) { |
| 381 | dev_err(dwc->dev, "can't allocate event buffer\n"); |
| 382 | return PTR_ERR(evt); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 383 | } |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 384 | dwc->ev_buf = evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 385 | |
Mayank Rana | f4918d3 | 2016-12-15 13:35:55 -0800 | [diff] [blame] | 386 | /* alloc GSI related event buffers */ |
| 387 | dwc3_notify_event(dwc, DWC3_GSI_EVT_BUF_ALLOC); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * dwc3_event_buffers_setup - setup our allocated event buffers |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 393 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 394 | * |
| 395 | * Returns 0 on success otherwise negative errno. |
| 396 | */ |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 397 | int dwc3_event_buffers_setup(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 398 | { |
| 399 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 400 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 401 | evt = dwc->ev_buf; |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 402 | dwc3_trace(trace_dwc3_core, |
| 403 | "Event buf %p dma %08llx length %d\n", |
| 404 | evt->buf, (unsigned long long) evt->dma, |
| 405 | evt->length); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 406 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 407 | evt->lpos = 0; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 408 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 409 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), |
| 410 | lower_32_bits(evt->dma)); |
| 411 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), |
| 412 | upper_32_bits(evt->dma)); |
| 413 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), |
| 414 | DWC3_GEVNTSIZ_SIZE(evt->length)); |
| 415 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 416 | |
Mayank Rana | f4918d3 | 2016-12-15 13:35:55 -0800 | [diff] [blame] | 417 | /* setup GSI related event buffers */ |
| 418 | dwc3_notify_event(dwc, DWC3_GSI_EVT_BUF_SETUP); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) |
| 423 | { |
| 424 | struct dwc3_event_buffer *evt; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 425 | |
Felipe Balbi | 696c8b1 | 2016-03-30 09:37:03 +0300 | [diff] [blame] | 426 | evt = dwc->ev_buf; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 427 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 428 | evt->lpos = 0; |
Paul Zimmerman | 7acd85e | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 429 | |
Felipe Balbi | 660e9bd | 2016-03-30 09:26:24 +0300 | [diff] [blame] | 430 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0); |
| 431 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0); |
| 432 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK |
| 433 | | DWC3_GEVNTSIZ_SIZE(0)); |
| 434 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0); |
Mayank Rana | f4918d3 | 2016-12-15 13:35:55 -0800 | [diff] [blame] | 435 | |
| 436 | /* cleanup GSI related event buffers */ |
| 437 | dwc3_notify_event(dwc, DWC3_GSI_EVT_BUF_CLEANUP); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 438 | } |
| 439 | |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 440 | static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc) |
| 441 | { |
| 442 | if (!dwc->has_hibernation) |
| 443 | return 0; |
| 444 | |
| 445 | if (!dwc->nr_scratch) |
| 446 | return 0; |
| 447 | |
| 448 | dwc->scratchbuf = kmalloc_array(dwc->nr_scratch, |
| 449 | DWC3_SCRATCHBUF_SIZE, GFP_KERNEL); |
| 450 | if (!dwc->scratchbuf) |
| 451 | return -ENOMEM; |
| 452 | |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) |
| 457 | { |
| 458 | dma_addr_t scratch_addr; |
| 459 | u32 param; |
| 460 | int ret; |
| 461 | |
| 462 | if (!dwc->has_hibernation) |
| 463 | return 0; |
| 464 | |
| 465 | if (!dwc->nr_scratch) |
| 466 | return 0; |
| 467 | |
| 468 | /* should never fall here */ |
| 469 | if (!WARN_ON(dwc->scratchbuf)) |
| 470 | return 0; |
| 471 | |
| 472 | scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf, |
| 473 | dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, |
| 474 | DMA_BIDIRECTIONAL); |
| 475 | if (dma_mapping_error(dwc->dev, scratch_addr)) { |
| 476 | dev_err(dwc->dev, "failed to map scratch buffer\n"); |
| 477 | ret = -EFAULT; |
| 478 | goto err0; |
| 479 | } |
| 480 | |
| 481 | dwc->scratch_addr = scratch_addr; |
| 482 | |
| 483 | param = lower_32_bits(scratch_addr); |
| 484 | |
| 485 | ret = dwc3_send_gadget_generic_command(dwc, |
| 486 | DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param); |
| 487 | if (ret < 0) |
| 488 | goto err1; |
| 489 | |
| 490 | param = upper_32_bits(scratch_addr); |
| 491 | |
| 492 | ret = dwc3_send_gadget_generic_command(dwc, |
| 493 | DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param); |
| 494 | if (ret < 0) |
| 495 | goto err1; |
| 496 | |
| 497 | return 0; |
| 498 | |
| 499 | err1: |
| 500 | dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * |
| 501 | DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); |
| 502 | |
| 503 | err0: |
| 504 | return ret; |
| 505 | } |
| 506 | |
| 507 | static void dwc3_free_scratch_buffers(struct dwc3 *dwc) |
| 508 | { |
| 509 | if (!dwc->has_hibernation) |
| 510 | return; |
| 511 | |
| 512 | if (!dwc->nr_scratch) |
| 513 | return; |
| 514 | |
| 515 | /* should never fall here */ |
| 516 | if (!WARN_ON(dwc->scratchbuf)) |
| 517 | return; |
| 518 | |
| 519 | dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * |
| 520 | DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); |
| 521 | kfree(dwc->scratchbuf); |
| 522 | } |
| 523 | |
Felipe Balbi | 789451f6 | 2011-05-05 15:53:10 +0300 | [diff] [blame] | 524 | static void dwc3_core_num_eps(struct dwc3 *dwc) |
| 525 | { |
| 526 | struct dwc3_hwparams *parms = &dwc->hwparams; |
| 527 | |
| 528 | dwc->num_in_eps = DWC3_NUM_IN_EPS(parms); |
| 529 | dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps; |
| 530 | |
Felipe Balbi | 7381528 | 2015-01-27 13:48:14 -0600 | [diff] [blame] | 531 | dwc3_trace(trace_dwc3_core, "found %d IN and %d OUT endpoints", |
Felipe Balbi | 789451f6 | 2011-05-05 15:53:10 +0300 | [diff] [blame] | 532 | dwc->num_in_eps, dwc->num_out_eps); |
| 533 | } |
| 534 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 535 | static void dwc3_cache_hwparams(struct dwc3 *dwc) |
Felipe Balbi | 26ceca9 | 2011-09-30 10:58:49 +0300 | [diff] [blame] | 536 | { |
| 537 | struct dwc3_hwparams *parms = &dwc->hwparams; |
| 538 | |
| 539 | parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); |
| 540 | parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); |
| 541 | parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); |
| 542 | parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); |
| 543 | parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); |
| 544 | parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); |
| 545 | parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); |
| 546 | parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); |
| 547 | parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); |
| 548 | } |
| 549 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 550 | /** |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 551 | * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core |
| 552 | * @dwc: Pointer to our controller context structure |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 553 | * |
| 554 | * Returns 0 on success. The USB PHY interfaces are configured but not |
| 555 | * initialized. The PHY interfaces and the PHYs get initialized together with |
| 556 | * the core in dwc3_core_init. |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 557 | */ |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 558 | static int dwc3_phy_setup(struct dwc3 *dwc) |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 559 | { |
| 560 | u32 reg; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 561 | int ret; |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 562 | |
| 563 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 564 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 565 | /* |
| 566 | * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY |
| 567 | * to '0' during coreConsultant configuration. So default value |
| 568 | * will be '0' when the core is reset. Application needs to set it |
| 569 | * to '1' after the core initialization is completed. |
| 570 | */ |
| 571 | if (dwc->revision > DWC3_REVISION_194A) |
| 572 | reg |= DWC3_GUSB3PIPECTL_SUSPHY; |
| 573 | |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 574 | if (dwc->u2ss_inp3_quirk) |
| 575 | reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK; |
| 576 | |
Rajesh Bhagat | e58dd35 | 2016-03-14 14:40:50 +0530 | [diff] [blame] | 577 | if (dwc->dis_rxdet_inp3_quirk) |
| 578 | reg |= DWC3_GUSB3PIPECTL_DISRXDETINP3; |
| 579 | |
Huang Rui | df31f5b | 2014-10-28 19:54:29 +0800 | [diff] [blame] | 580 | if (dwc->req_p1p2p3_quirk) |
| 581 | reg |= DWC3_GUSB3PIPECTL_REQP1P2P3; |
| 582 | |
Huang Rui | a2a1d0f | 2014-10-28 19:54:30 +0800 | [diff] [blame] | 583 | if (dwc->del_p1p2p3_quirk) |
| 584 | reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN; |
| 585 | |
Huang Rui | 41c06ff | 2014-10-28 19:54:31 +0800 | [diff] [blame] | 586 | if (dwc->del_phy_power_chg_quirk) |
| 587 | reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE; |
| 588 | |
Huang Rui | fb67afc | 2014-10-28 19:54:32 +0800 | [diff] [blame] | 589 | if (dwc->lfps_filter_quirk) |
| 590 | reg |= DWC3_GUSB3PIPECTL_LFPSFILT; |
| 591 | |
Huang Rui | 14f4ac5 | 2014-10-28 19:54:33 +0800 | [diff] [blame] | 592 | if (dwc->rx_detect_poll_quirk) |
| 593 | reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL; |
| 594 | |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 595 | if (dwc->tx_de_emphasis_quirk) |
| 596 | reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis); |
| 597 | |
Felipe Balbi | cd72f89 | 2014-11-06 11:31:00 -0600 | [diff] [blame] | 598 | if (dwc->dis_u3_susphy_quirk) |
Huang Rui | 59acfa2 | 2014-10-31 11:11:13 +0800 | [diff] [blame] | 599 | reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; |
| 600 | |
William Wu | 00fe081 | 2016-08-16 22:44:39 +0800 | [diff] [blame] | 601 | if (dwc->dis_del_phy_power_chg_quirk) |
| 602 | reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE; |
| 603 | |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 604 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 605 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 606 | reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); |
| 607 | |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 608 | /* Select the HS PHY interface */ |
| 609 | switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) { |
| 610 | case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI: |
Felipe Balbi | 43cacb0 | 2015-07-01 22:03:09 -0500 | [diff] [blame] | 611 | if (dwc->hsphy_interface && |
| 612 | !strncmp(dwc->hsphy_interface, "utmi", 4)) { |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 613 | reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 614 | break; |
Felipe Balbi | 43cacb0 | 2015-07-01 22:03:09 -0500 | [diff] [blame] | 615 | } else if (dwc->hsphy_interface && |
| 616 | !strncmp(dwc->hsphy_interface, "ulpi", 4)) { |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 617 | reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI; |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 618 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 619 | } else { |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 620 | /* Relying on default value. */ |
| 621 | if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI)) |
| 622 | break; |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 623 | } |
| 624 | /* FALLTHROUGH */ |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 625 | case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI: |
| 626 | /* Making sure the interface and PHY are operational */ |
| 627 | ret = dwc3_soft_reset(dwc); |
| 628 | if (ret) |
| 629 | return ret; |
| 630 | |
| 631 | udelay(1); |
| 632 | |
| 633 | ret = dwc3_ulpi_init(dwc); |
| 634 | if (ret) |
| 635 | return ret; |
| 636 | /* FALLTHROUGH */ |
Heikki Krogerus | 3e10a2c | 2015-05-13 15:26:49 +0300 | [diff] [blame] | 637 | default: |
| 638 | break; |
| 639 | } |
| 640 | |
William Wu | 32f2ed8 | 2016-08-16 22:44:38 +0800 | [diff] [blame] | 641 | switch (dwc->hsphy_mode) { |
| 642 | case USBPHY_INTERFACE_MODE_UTMI: |
| 643 | reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | |
| 644 | DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); |
| 645 | reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) | |
| 646 | DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT); |
| 647 | break; |
| 648 | case USBPHY_INTERFACE_MODE_UTMIW: |
| 649 | reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK | |
| 650 | DWC3_GUSB2PHYCFG_USBTRDTIM_MASK); |
| 651 | reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) | |
| 652 | DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT); |
| 653 | break; |
| 654 | default: |
| 655 | break; |
| 656 | } |
| 657 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 658 | /* |
| 659 | * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to |
| 660 | * '0' during coreConsultant configuration. So default value will |
| 661 | * be '0' when the core is reset. Application needs to set it to |
| 662 | * '1' after the core initialization is completed. |
| 663 | */ |
| 664 | if (dwc->revision > DWC3_REVISION_194A) |
| 665 | reg |= DWC3_GUSB2PHYCFG_SUSPHY; |
| 666 | |
Felipe Balbi | cd72f89 | 2014-11-06 11:31:00 -0600 | [diff] [blame] | 667 | if (dwc->dis_u2_susphy_quirk) |
Huang Rui | 0effe0a | 2014-10-31 11:11:14 +0800 | [diff] [blame] | 668 | reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; |
| 669 | |
John Youn | ec791d1 | 2015-10-02 20:30:57 -0700 | [diff] [blame] | 670 | if (dwc->dis_enblslpm_quirk) |
| 671 | reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM; |
| 672 | |
William Wu | 16199f3 | 2016-08-16 22:44:37 +0800 | [diff] [blame] | 673 | if (dwc->dis_u2_freeclk_exists_quirk) |
| 674 | reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS; |
| 675 | |
Huang Rui | 2164a47 | 2014-10-28 19:54:35 +0800 | [diff] [blame] | 676 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 677 | |
| 678 | return 0; |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 679 | } |
| 680 | |
Felipe Balbi | c499ff7 | 2016-05-16 10:49:01 +0300 | [diff] [blame] | 681 | static void dwc3_core_exit(struct dwc3 *dwc) |
| 682 | { |
| 683 | dwc3_event_buffers_cleanup(dwc); |
| 684 | |
| 685 | usb_phy_shutdown(dwc->usb2_phy); |
| 686 | usb_phy_shutdown(dwc->usb3_phy); |
| 687 | phy_exit(dwc->usb2_generic_phy); |
| 688 | phy_exit(dwc->usb3_generic_phy); |
| 689 | |
| 690 | usb_phy_set_suspend(dwc->usb2_phy, 1); |
| 691 | usb_phy_set_suspend(dwc->usb3_phy, 1); |
| 692 | phy_power_off(dwc->usb2_generic_phy); |
| 693 | phy_power_off(dwc->usb3_generic_phy); |
| 694 | } |
| 695 | |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 696 | /** |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 697 | * dwc3_core_init - Low-level initialization of DWC3 Core |
| 698 | * @dwc: Pointer to our controller context structure |
| 699 | * |
| 700 | * Returns 0 on success otherwise negative errno. |
| 701 | */ |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 702 | int dwc3_core_init(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 703 | { |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 704 | u32 hwparams4 = dwc->hwparams.hwparams4; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 705 | u32 reg; |
| 706 | int ret; |
| 707 | |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 708 | reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); |
| 709 | /* This should read as U3 followed by revision number */ |
John Youn | 690fb37 | 2015-09-04 19:15:10 -0700 | [diff] [blame] | 710 | if ((reg & DWC3_GSNPSID_MASK) == 0x55330000) { |
| 711 | /* Detected DWC_usb3 IP */ |
| 712 | dwc->revision = reg; |
| 713 | } else if ((reg & DWC3_GSNPSID_MASK) == 0x33310000) { |
| 714 | /* Detected DWC_usb31 IP */ |
| 715 | dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER); |
| 716 | dwc->revision |= DWC3_REVISION_IS_DWC31; |
| 717 | } else { |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 718 | dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); |
| 719 | ret = -ENODEV; |
| 720 | goto err0; |
| 721 | } |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 722 | |
Felipe Balbi | fa0ea13 | 2014-09-19 15:51:11 -0500 | [diff] [blame] | 723 | /* |
| 724 | * Write Linux Version Code to our GUID register so it's easy to figure |
| 725 | * out which kernel version a bug was found. |
| 726 | */ |
| 727 | dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); |
| 728 | |
Paul Zimmerman | 0e1e5c4 | 2014-05-23 11:39:24 -0700 | [diff] [blame] | 729 | /* Handle USB2.0-only core configuration */ |
| 730 | if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == |
| 731 | DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { |
| 732 | if (dwc->maximum_speed == USB_SPEED_SUPER) |
| 733 | dwc->maximum_speed = USB_SPEED_HIGH; |
| 734 | } |
| 735 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 736 | /* issue device SoftReset too */ |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 737 | ret = dwc3_core_reset(dwc); |
Heikki Krogerus | c5cc74e | 2015-05-13 15:26:47 +0300 | [diff] [blame] | 738 | if (ret) |
| 739 | goto err0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 740 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 741 | /* issue device SoftReset too */ |
| 742 | ret = dwc3_soft_reset(dwc); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 743 | if (ret) |
| 744 | goto err0; |
Pratyush Anand | 58a0f23 | 2012-06-21 17:44:29 +0530 | [diff] [blame] | 745 | |
Felipe Balbi | c499ff7 | 2016-05-16 10:49:01 +0300 | [diff] [blame] | 746 | ret = dwc3_phy_setup(dwc); |
| 747 | if (ret) |
| 748 | goto err0; |
| 749 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 750 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
Paul Zimmerman | 3e87c42 | 2012-02-24 17:32:13 -0800 | [diff] [blame] | 751 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 752 | |
Sebastian Andrzej Siewior | 164d773 | 2011-11-24 11:22:05 +0100 | [diff] [blame] | 753 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 754 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: |
Felipe Balbi | 32a4a13 | 2014-02-25 14:00:13 -0600 | [diff] [blame] | 755 | /** |
| 756 | * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an |
| 757 | * issue which would cause xHCI compliance tests to fail. |
| 758 | * |
| 759 | * Because of that we cannot enable clock gating on such |
| 760 | * configurations. |
| 761 | * |
| 762 | * Refers to: |
| 763 | * |
| 764 | * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based |
| 765 | * SOF/ITP Mode Used |
| 766 | */ |
| 767 | if ((dwc->dr_mode == USB_DR_MODE_HOST || |
| 768 | dwc->dr_mode == USB_DR_MODE_OTG) && |
| 769 | (dwc->revision >= DWC3_REVISION_210A && |
| 770 | dwc->revision <= DWC3_REVISION_250A)) |
| 771 | reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC; |
| 772 | else |
| 773 | reg &= ~DWC3_GCTL_DSBLCLKGTNG; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 774 | break; |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 775 | case DWC3_GHWPARAMS1_EN_PWROPT_HIB: |
| 776 | /* enable hibernation here */ |
| 777 | dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4); |
Huang Rui | 2eac399 | 2014-10-28 19:54:22 +0800 | [diff] [blame] | 778 | |
| 779 | /* |
| 780 | * REVISIT Enabling this bit so that host-mode hibernation |
| 781 | * will work. Device-mode hibernation is not yet implemented. |
| 782 | */ |
| 783 | reg |= DWC3_GCTL_GBLHIBERNATIONEN; |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 784 | break; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 785 | default: |
Felipe Balbi | 1407bf1 | 2015-11-16 16:06:37 -0600 | [diff] [blame] | 786 | dwc3_trace(trace_dwc3_core, "No power optimization available\n"); |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Huang Rui | 946bd57 | 2014-10-28 19:54:23 +0800 | [diff] [blame] | 789 | /* check if current dwc3 is on simulation board */ |
| 790 | if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { |
Felipe Balbi | 1407bf1 | 2015-11-16 16:06:37 -0600 | [diff] [blame] | 791 | dwc3_trace(trace_dwc3_core, |
| 792 | "running on FPGA platform\n"); |
Huang Rui | 946bd57 | 2014-10-28 19:54:23 +0800 | [diff] [blame] | 793 | dwc->is_fpga = true; |
| 794 | } |
| 795 | |
Huang Rui | 3b81221 | 2014-10-28 19:54:25 +0800 | [diff] [blame] | 796 | WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga, |
| 797 | "disable_scramble cannot be used on non-FPGA builds\n"); |
| 798 | |
| 799 | if (dwc->disable_scramble_quirk && dwc->is_fpga) |
| 800 | reg |= DWC3_GCTL_DISSCRAMBLE; |
| 801 | else |
| 802 | reg &= ~DWC3_GCTL_DISSCRAMBLE; |
| 803 | |
Huang Rui | 9a5b2f3 | 2014-10-28 19:54:27 +0800 | [diff] [blame] | 804 | if (dwc->u2exit_lfps_quirk) |
| 805 | reg |= DWC3_GCTL_U2EXIT_LFPS; |
| 806 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 807 | /* |
| 808 | * WORKAROUND: DWC3 revisions <1.90a have a bug |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 809 | * where the device can fail to connect at SuperSpeed |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 810 | * and falls back to high-speed mode which causes |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 811 | * the device to enter a Connect/Disconnect loop |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 812 | */ |
| 813 | if (dwc->revision < DWC3_REVISION_190A) |
| 814 | reg |= DWC3_GCTL_U2RSTECN; |
| 815 | |
Mayank Rana | fb9cd93 | 2016-11-03 23:26:38 -0700 | [diff] [blame] | 816 | ret = dwc3_get_dr_mode(dwc); |
| 817 | if (ret) |
| 818 | goto err0; |
| 819 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 820 | dwc3_core_num_eps(dwc); |
| 821 | |
| 822 | /* |
| 823 | * Disable clock gating to work around a known HW bug that causes the |
| 824 | * internal RAM clock to get stuck when entering low power modes. |
| 825 | */ |
| 826 | if (dwc->disable_clk_gating) { |
| 827 | dev_dbg(dwc->dev, "Disabling controller clock gating.\n"); |
| 828 | reg |= DWC3_GCTL_DSBLCLKGTNG; |
| 829 | } |
| 830 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 831 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 832 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 833 | ret = dwc3_alloc_scratch_buffers(dwc); |
| 834 | if (ret) |
| 835 | goto err1; |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 836 | |
| 837 | ret = dwc3_setup_scratch_buffers(dwc); |
| 838 | if (ret) |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 839 | goto err2; |
Felipe Balbi | c499ff7 | 2016-05-16 10:49:01 +0300 | [diff] [blame] | 840 | |
| 841 | /* Adjust Frame Length */ |
| 842 | dwc3_frame_length_adjustment(dwc); |
| 843 | |
| 844 | usb_phy_set_suspend(dwc->usb2_phy, 0); |
| 845 | usb_phy_set_suspend(dwc->usb3_phy, 0); |
| 846 | ret = phy_power_on(dwc->usb2_generic_phy); |
| 847 | if (ret < 0) |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 848 | goto err2; |
| 849 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 850 | /* |
| 851 | * clear Elastic buffer mode in GUSBPIPE_CTRL(0) register, otherwise |
| 852 | * it results in high link errors and could cause SS mode transfer |
| 853 | * failure. |
| 854 | */ |
| 855 | if (!dwc->nominal_elastic_buffer) { |
| 856 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 857 | reg &= ~DWC3_GUSB3PIPECTL_ELASTIC_BUF_MODE; |
| 858 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
Felipe Balbi | c499ff7 | 2016-05-16 10:49:01 +0300 | [diff] [blame] | 859 | } |
| 860 | |
Baolin Wang | 00af623 | 2016-07-15 17:13:27 +0800 | [diff] [blame] | 861 | switch (dwc->dr_mode) { |
| 862 | case USB_DR_MODE_PERIPHERAL: |
| 863 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); |
| 864 | break; |
| 865 | case USB_DR_MODE_HOST: |
| 866 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); |
| 867 | break; |
| 868 | case USB_DR_MODE_OTG: |
| 869 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); |
| 870 | break; |
| 871 | default: |
| 872 | dev_warn(dwc->dev, "Unsupported mode %d\n", dwc->dr_mode); |
| 873 | break; |
| 874 | } |
| 875 | |
John Youn | 06281d4 | 2016-08-22 15:39:13 -0700 | [diff] [blame] | 876 | /* |
| 877 | * ENDXFER polling is available on version 3.10a and later of |
| 878 | * the DWC_usb3 controller. It is NOT available in the |
| 879 | * DWC_usb31 controller. |
| 880 | */ |
| 881 | if (!dwc3_is_usb31(dwc) && dwc->revision >= DWC3_REVISION_310A) { |
| 882 | reg = dwc3_readl(dwc->regs, DWC3_GUCTL2); |
| 883 | reg |= DWC3_GUCTL2_RST_ACTBITLATER; |
| 884 | dwc3_writel(dwc->regs, DWC3_GUCTL2, reg); |
| 885 | } |
| 886 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 887 | return 0; |
| 888 | |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 889 | err2: |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 890 | dwc3_free_scratch_buffers(dwc); |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 891 | err1: |
| 892 | usb_phy_shutdown(dwc->usb2_phy); |
| 893 | usb_phy_shutdown(dwc->usb3_phy); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 894 | phy_exit(dwc->usb2_generic_phy); |
| 895 | phy_exit(dwc->usb3_generic_phy); |
Felipe Balbi | 0ffcaf3 | 2013-12-19 13:04:28 -0600 | [diff] [blame] | 896 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 897 | err0: |
| 898 | return ret; |
| 899 | } |
| 900 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 901 | static int dwc3_core_get_phy(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 902 | { |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 903 | struct device *dev = dwc->dev; |
Felipe Balbi | 941ea36 | 2013-07-31 09:21:25 +0300 | [diff] [blame] | 904 | struct device_node *node = dev->of_node; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 905 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 906 | |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 907 | if (node) { |
| 908 | dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); |
| 909 | 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] | 910 | } else { |
| 911 | dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
| 912 | 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] | 913 | } |
| 914 | |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 915 | if (IS_ERR(dwc->usb2_phy)) { |
| 916 | ret = PTR_ERR(dwc->usb2_phy); |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 917 | if (ret == -ENXIO || ret == -ENODEV) { |
| 918 | dwc->usb2_phy = NULL; |
| 919 | } else if (ret == -EPROBE_DEFER) { |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 920 | return ret; |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 921 | } else { |
| 922 | dev_err(dev, "no usb2 phy configured\n"); |
| 923 | return ret; |
| 924 | } |
Felipe Balbi | 51e1e7b | 2012-07-19 14:09:48 +0300 | [diff] [blame] | 925 | } |
| 926 | |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 927 | if (IS_ERR(dwc->usb3_phy)) { |
Ruchika Kharwar | 315955d7 | 2013-07-04 00:59:34 -0500 | [diff] [blame] | 928 | ret = PTR_ERR(dwc->usb3_phy); |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 929 | if (ret == -ENXIO || ret == -ENODEV) { |
| 930 | dwc->usb3_phy = NULL; |
| 931 | } else if (ret == -EPROBE_DEFER) { |
Felipe Balbi | d105e7f | 2013-03-15 10:52:08 +0200 | [diff] [blame] | 932 | return ret; |
Kishon Vijay Abraham I | 122f06e | 2014-03-03 17:08:10 +0530 | [diff] [blame] | 933 | } else { |
| 934 | dev_err(dev, "no usb3 phy configured\n"); |
| 935 | return ret; |
| 936 | } |
Felipe Balbi | 51e1e7b | 2012-07-19 14:09:48 +0300 | [diff] [blame] | 937 | } |
| 938 | |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 939 | dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy"); |
| 940 | if (IS_ERR(dwc->usb2_generic_phy)) { |
| 941 | ret = PTR_ERR(dwc->usb2_generic_phy); |
| 942 | if (ret == -ENOSYS || ret == -ENODEV) { |
| 943 | dwc->usb2_generic_phy = NULL; |
| 944 | } else if (ret == -EPROBE_DEFER) { |
| 945 | return ret; |
| 946 | } else { |
| 947 | dev_err(dev, "no usb2 phy configured\n"); |
| 948 | return ret; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy"); |
| 953 | if (IS_ERR(dwc->usb3_generic_phy)) { |
| 954 | ret = PTR_ERR(dwc->usb3_generic_phy); |
| 955 | if (ret == -ENOSYS || ret == -ENODEV) { |
| 956 | dwc->usb3_generic_phy = NULL; |
| 957 | } else if (ret == -EPROBE_DEFER) { |
| 958 | return ret; |
| 959 | } else { |
| 960 | dev_err(dev, "no usb3 phy configured\n"); |
| 961 | return ret; |
| 962 | } |
| 963 | } |
| 964 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 965 | return 0; |
| 966 | } |
| 967 | |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 968 | static int dwc3_core_init_mode(struct dwc3 *dwc) |
| 969 | { |
| 970 | struct device *dev = dwc->dev; |
| 971 | int ret; |
| 972 | |
| 973 | switch (dwc->dr_mode) { |
| 974 | case USB_DR_MODE_PERIPHERAL: |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 975 | ret = dwc3_gadget_init(dwc); |
| 976 | if (ret) { |
Roger Quadros | 9522def | 2016-06-10 14:48:38 +0300 | [diff] [blame] | 977 | if (ret != -EPROBE_DEFER) |
| 978 | dev_err(dev, "failed to initialize gadget\n"); |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 979 | return ret; |
| 980 | } |
| 981 | break; |
| 982 | case USB_DR_MODE_HOST: |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 983 | ret = dwc3_host_init(dwc); |
| 984 | if (ret) { |
Roger Quadros | 9522def | 2016-06-10 14:48:38 +0300 | [diff] [blame] | 985 | if (ret != -EPROBE_DEFER) |
| 986 | dev_err(dev, "failed to initialize host\n"); |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 987 | return ret; |
| 988 | } |
| 989 | break; |
| 990 | case USB_DR_MODE_OTG: |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 991 | ret = dwc3_host_init(dwc); |
| 992 | if (ret) { |
Roger Quadros | 9522def | 2016-06-10 14:48:38 +0300 | [diff] [blame] | 993 | if (ret != -EPROBE_DEFER) |
| 994 | dev_err(dev, "failed to initialize host\n"); |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 995 | return ret; |
| 996 | } |
| 997 | |
| 998 | ret = dwc3_gadget_init(dwc); |
| 999 | if (ret) { |
Roger Quadros | 9522def | 2016-06-10 14:48:38 +0300 | [diff] [blame] | 1000 | if (ret != -EPROBE_DEFER) |
| 1001 | dev_err(dev, "failed to initialize gadget\n"); |
Felipe Balbi | 5f94adf | 2014-04-16 15:13:45 -0500 | [diff] [blame] | 1002 | return ret; |
| 1003 | } |
| 1004 | break; |
| 1005 | default: |
| 1006 | dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); |
| 1007 | return -EINVAL; |
| 1008 | } |
| 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static void dwc3_core_exit_mode(struct dwc3 *dwc) |
| 1014 | { |
| 1015 | switch (dwc->dr_mode) { |
| 1016 | case USB_DR_MODE_PERIPHERAL: |
| 1017 | dwc3_gadget_exit(dwc); |
| 1018 | break; |
| 1019 | case USB_DR_MODE_HOST: |
| 1020 | dwc3_host_exit(dwc); |
| 1021 | break; |
| 1022 | case USB_DR_MODE_OTG: |
| 1023 | dwc3_host_exit(dwc); |
| 1024 | dwc3_gadget_exit(dwc); |
| 1025 | break; |
| 1026 | default: |
| 1027 | /* do nothing */ |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
| 1031 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1032 | /* XHCI reset, resets other CORE registers as well, re-init those */ |
| 1033 | void dwc3_post_host_reset_core_init(struct dwc3 *dwc) |
| 1034 | { |
| 1035 | dwc3_core_init(dwc); |
| 1036 | dwc3_gadget_restart(dwc); |
| 1037 | } |
| 1038 | |
| 1039 | static void (*notify_event)(struct dwc3 *, unsigned int); |
| 1040 | void dwc3_set_notifier(void (*notify)(struct dwc3 *, unsigned int)) |
| 1041 | { |
| 1042 | notify_event = notify; |
| 1043 | } |
| 1044 | EXPORT_SYMBOL(dwc3_set_notifier); |
| 1045 | |
| 1046 | int dwc3_notify_event(struct dwc3 *dwc, unsigned int event) |
| 1047 | { |
| 1048 | int ret = 0; |
| 1049 | |
| 1050 | if (dwc->notify_event) |
| 1051 | dwc->notify_event(dwc, event); |
| 1052 | else |
| 1053 | ret = -ENODEV; |
| 1054 | |
| 1055 | return ret; |
| 1056 | } |
| 1057 | EXPORT_SYMBOL(dwc3_notify_event); |
| 1058 | |
| 1059 | int dwc3_core_pre_init(struct dwc3 *dwc) |
| 1060 | { |
| 1061 | int ret; |
| 1062 | |
| 1063 | dwc3_cache_hwparams(dwc); |
| 1064 | |
| 1065 | ret = dwc3_phy_setup(dwc); |
| 1066 | if (ret) |
| 1067 | goto err0; |
| 1068 | |
| 1069 | if (!dwc->ev_buf) { |
| 1070 | ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); |
| 1071 | if (ret) { |
| 1072 | dev_err(dwc->dev, "failed to allocate event buffers\n"); |
| 1073 | ret = -ENOMEM; |
| 1074 | goto err1; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | ret = dwc3_core_init(dwc); |
| 1079 | if (ret) { |
| 1080 | dev_err(dwc->dev, "failed to initialize core\n"); |
| 1081 | goto err2; |
| 1082 | } |
| 1083 | |
| 1084 | ret = phy_power_on(dwc->usb2_generic_phy); |
| 1085 | if (ret < 0) |
| 1086 | goto err3; |
| 1087 | |
| 1088 | ret = phy_power_on(dwc->usb3_generic_phy); |
| 1089 | if (ret < 0) |
| 1090 | goto err4; |
| 1091 | |
| 1092 | ret = dwc3_event_buffers_setup(dwc); |
| 1093 | if (ret) { |
| 1094 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
| 1095 | goto err5; |
| 1096 | } |
| 1097 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1098 | return ret; |
| 1099 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1100 | err5: |
| 1101 | phy_power_off(dwc->usb3_generic_phy); |
| 1102 | err4: |
| 1103 | phy_power_off(dwc->usb2_generic_phy); |
| 1104 | err3: |
| 1105 | dwc3_core_exit(dwc); |
| 1106 | err2: |
| 1107 | dwc3_free_event_buffers(dwc); |
| 1108 | err1: |
| 1109 | dwc3_ulpi_exit(dwc); |
| 1110 | err0: |
| 1111 | return ret; |
| 1112 | } |
| 1113 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1114 | #define DWC3_ALIGN_MASK (16 - 1) |
| 1115 | |
| 1116 | static int dwc3_probe(struct platform_device *pdev) |
| 1117 | { |
| 1118 | struct device *dev = &pdev->dev; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1119 | struct resource *res; |
| 1120 | struct dwc3 *dwc; |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1121 | u8 lpm_nyet_threshold; |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1122 | u8 tx_de_emphasis; |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 1123 | u8 hird_threshold; |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1124 | int irq; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1125 | |
Andy Shevchenko | b09e99e | 2014-05-15 15:53:32 +0300 | [diff] [blame] | 1126 | int ret; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1127 | |
| 1128 | void __iomem *regs; |
| 1129 | void *mem; |
| 1130 | |
Mayank Rana | 861da2b | 2016-07-13 13:47:57 -0700 | [diff] [blame^] | 1131 | if (count >= DWC_CTRL_COUNT) { |
| 1132 | dev_err(dev, "Err dwc instance %d >= %d available\n", |
| 1133 | count, DWC_CTRL_COUNT); |
| 1134 | ret = -EINVAL; |
| 1135 | return ret; |
| 1136 | } |
| 1137 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1138 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); |
Jingoo Han | 734d5a5 | 2014-07-17 12:45:11 +0900 | [diff] [blame] | 1139 | if (!mem) |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1140 | return -ENOMEM; |
Jingoo Han | 734d5a5 | 2014-07-17 12:45:11 +0900 | [diff] [blame] | 1141 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1142 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); |
| 1143 | dwc->mem = mem; |
| 1144 | dwc->dev = dev; |
| 1145 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1146 | dwc->notify_event = notify_event; |
| 1147 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1148 | if (!res) { |
| 1149 | dev_err(dev, "missing IRQ\n"); |
| 1150 | return -ENODEV; |
| 1151 | } |
| 1152 | dwc->xhci_resources[1].start = res->start; |
| 1153 | dwc->xhci_resources[1].end = res->end; |
| 1154 | dwc->xhci_resources[1].flags = res->flags; |
| 1155 | dwc->xhci_resources[1].name = res->name; |
| 1156 | |
| 1157 | irq = platform_get_irq(to_platform_device(dwc->dev), 0); |
| 1158 | |
| 1159 | /* will be enabled in dwc3_msm_resume() */ |
| 1160 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 1161 | ret = devm_request_threaded_irq(dev, irq, NULL, dwc3_interrupt, |
| 1162 | IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc); |
| 1163 | if (ret) { |
| 1164 | dev_err(dwc->dev, "failed to request irq #%d --> %d\n", |
| 1165 | irq, ret); |
| 1166 | return -ENODEV; |
| 1167 | } |
| 1168 | |
| 1169 | dwc->irq = irq; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1170 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1171 | if (!res) { |
| 1172 | dev_err(dev, "missing memory resource\n"); |
| 1173 | return -ENODEV; |
| 1174 | } |
| 1175 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1176 | dwc->reg_phys = res->start; |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 1177 | dwc->xhci_resources[0].start = res->start; |
| 1178 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + |
| 1179 | DWC3_XHCI_REGS_END; |
| 1180 | dwc->xhci_resources[0].flags = res->flags; |
| 1181 | dwc->xhci_resources[0].name = res->name; |
| 1182 | |
| 1183 | res->start += DWC3_GLOBALS_REGS_START; |
| 1184 | |
| 1185 | /* |
| 1186 | * Request memory region but exclude xHCI regs, |
| 1187 | * since it will be requested by the xhci-plat driver. |
| 1188 | */ |
| 1189 | regs = devm_ioremap_resource(dev, res); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1190 | if (IS_ERR(regs)) { |
| 1191 | ret = PTR_ERR(regs); |
| 1192 | goto err0; |
| 1193 | } |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 1194 | |
| 1195 | dwc->regs = regs; |
| 1196 | dwc->regs_size = resource_size(res); |
Vivek Gautam | f32a5e2 | 2014-06-04 14:34:52 +0530 | [diff] [blame] | 1197 | |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1198 | /* default to highest possible threshold */ |
| 1199 | lpm_nyet_threshold = 0xff; |
| 1200 | |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1201 | /* default to -3.5dB de-emphasis */ |
| 1202 | tx_de_emphasis = 1; |
| 1203 | |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 1204 | /* |
| 1205 | * default to assert utmi_sleep_n and use maximum allowed HIRD |
| 1206 | * threshold value of 0b1100 |
| 1207 | */ |
| 1208 | hird_threshold = 12; |
| 1209 | |
Heikki Krogerus | 63863b9 | 2015-09-21 11:14:32 +0300 | [diff] [blame] | 1210 | dwc->maximum_speed = usb_get_maximum_speed(dev); |
Heikki Krogerus | 06e7114 | 2015-09-21 11:14:34 +0300 | [diff] [blame] | 1211 | dwc->dr_mode = usb_get_dr_mode(dev); |
Mayank Rana | fb9cd93 | 2016-11-03 23:26:38 -0700 | [diff] [blame] | 1212 | |
| 1213 | if (dwc->dr_mode == USB_DR_MODE_UNKNOWN) { |
| 1214 | dwc->dr_mode = USB_DR_MODE_OTG; |
| 1215 | dwc->is_drd = 1; |
| 1216 | } |
| 1217 | |
William Wu | 32f2ed8 | 2016-08-16 22:44:38 +0800 | [diff] [blame] | 1218 | dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); |
Heikki Krogerus | 63863b9 | 2015-09-21 11:14:32 +0300 | [diff] [blame] | 1219 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1220 | dwc->has_lpm_erratum = device_property_read_bool(dev, |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1221 | "snps,has-lpm-erratum"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1222 | device_property_read_u8(dev, "snps,lpm-nyet-threshold", |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1223 | &lpm_nyet_threshold); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1224 | dwc->is_utmi_l1_suspend = device_property_read_bool(dev, |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 1225 | "snps,is-utmi-l1-suspend"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1226 | device_property_read_u8(dev, "snps,hird-threshold", |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 1227 | &hird_threshold); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1228 | dwc->usb3_lpm_capable = device_property_read_bool(dev, |
Robert Baldyga | eac68e8 | 2015-03-09 15:06:12 +0100 | [diff] [blame] | 1229 | "snps,usb3_lpm_capable"); |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1230 | |
Mayank Rana | a8e4de6 | 2016-12-13 17:11:15 -0800 | [diff] [blame] | 1231 | dwc->needs_fifo_resize = device_property_read_bool(dev, |
| 1232 | "tx-fifo-resize"); |
| 1233 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1234 | dwc->disable_scramble_quirk = device_property_read_bool(dev, |
Huang Rui | 3b81221 | 2014-10-28 19:54:25 +0800 | [diff] [blame] | 1235 | "snps,disable_scramble_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1236 | dwc->u2exit_lfps_quirk = device_property_read_bool(dev, |
Huang Rui | 9a5b2f3 | 2014-10-28 19:54:27 +0800 | [diff] [blame] | 1237 | "snps,u2exit_lfps_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1238 | dwc->u2ss_inp3_quirk = device_property_read_bool(dev, |
Huang Rui | b5a65c4 | 2014-10-28 19:54:28 +0800 | [diff] [blame] | 1239 | "snps,u2ss_inp3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1240 | dwc->req_p1p2p3_quirk = device_property_read_bool(dev, |
Huang Rui | df31f5b | 2014-10-28 19:54:29 +0800 | [diff] [blame] | 1241 | "snps,req_p1p2p3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1242 | dwc->del_p1p2p3_quirk = device_property_read_bool(dev, |
Huang Rui | a2a1d0f | 2014-10-28 19:54:30 +0800 | [diff] [blame] | 1243 | "snps,del_p1p2p3_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1244 | dwc->del_phy_power_chg_quirk = device_property_read_bool(dev, |
Huang Rui | 41c06ff | 2014-10-28 19:54:31 +0800 | [diff] [blame] | 1245 | "snps,del_phy_power_chg_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1246 | dwc->lfps_filter_quirk = device_property_read_bool(dev, |
Huang Rui | fb67afc | 2014-10-28 19:54:32 +0800 | [diff] [blame] | 1247 | "snps,lfps_filter_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1248 | dwc->rx_detect_poll_quirk = device_property_read_bool(dev, |
Huang Rui | 14f4ac5 | 2014-10-28 19:54:33 +0800 | [diff] [blame] | 1249 | "snps,rx_detect_poll_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1250 | dwc->dis_u3_susphy_quirk = device_property_read_bool(dev, |
Huang Rui | 59acfa2 | 2014-10-31 11:11:13 +0800 | [diff] [blame] | 1251 | "snps,dis_u3_susphy_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1252 | dwc->dis_u2_susphy_quirk = device_property_read_bool(dev, |
Huang Rui | 0effe0a | 2014-10-31 11:11:14 +0800 | [diff] [blame] | 1253 | "snps,dis_u2_susphy_quirk"); |
John Youn | ec791d1 | 2015-10-02 20:30:57 -0700 | [diff] [blame] | 1254 | dwc->dis_enblslpm_quirk = device_property_read_bool(dev, |
| 1255 | "snps,dis_enblslpm_quirk"); |
Rajesh Bhagat | e58dd35 | 2016-03-14 14:40:50 +0530 | [diff] [blame] | 1256 | dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev, |
| 1257 | "snps,dis_rxdet_inp3_quirk"); |
William Wu | 16199f3 | 2016-08-16 22:44:37 +0800 | [diff] [blame] | 1258 | dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev, |
| 1259 | "snps,dis-u2-freeclk-exists-quirk"); |
William Wu | 00fe081 | 2016-08-16 22:44:39 +0800 | [diff] [blame] | 1260 | dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev, |
| 1261 | "snps,dis-del-phy-power-chg-quirk"); |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1262 | |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1263 | dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1264 | "snps,tx_de_emphasis_quirk"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1265 | device_property_read_u8(dev, "snps,tx_de_emphasis", |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1266 | &tx_de_emphasis); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1267 | device_property_read_string(dev, "snps,hsphy_interface", |
| 1268 | &dwc->hsphy_interface); |
| 1269 | device_property_read_u32(dev, "snps,quirk-frame-length-adjustment", |
Felipe Balbi | bcdb327 | 2016-05-16 10:42:23 +0300 | [diff] [blame] | 1270 | &dwc->fladj); |
Mayank Rana | 00b0398 | 2015-06-10 11:43:09 -0700 | [diff] [blame] | 1271 | dwc->disable_clk_gating = device_property_read_bool(dev, |
| 1272 | "snps,disable-clk-gating"); |
Heikki Krogerus | 3d12891 | 2015-09-21 11:14:35 +0300 | [diff] [blame] | 1273 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1274 | if (dwc->enable_bus_suspend) { |
| 1275 | pm_runtime_set_autosuspend_delay(dev, 500); |
| 1276 | pm_runtime_use_autosuspend(dev); |
| 1277 | } |
| 1278 | |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1279 | dwc->lpm_nyet_threshold = lpm_nyet_threshold; |
Huang Rui | 6b6a0c9 | 2014-10-31 11:11:12 +0800 | [diff] [blame] | 1280 | dwc->tx_de_emphasis = tx_de_emphasis; |
Huang Rui | 80caf7d | 2014-10-28 19:54:26 +0800 | [diff] [blame] | 1281 | |
Huang Rui | 460d098 | 2014-10-31 11:11:18 +0800 | [diff] [blame] | 1282 | dwc->hird_threshold = hird_threshold |
| 1283 | | (dwc->is_utmi_l1_suspend << 4); |
| 1284 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1285 | init_waitqueue_head(&dwc->wait_linkstate); |
Heikki Krogerus | 6c89cce0 | 2015-05-13 15:26:45 +0300 | [diff] [blame] | 1286 | platform_set_drvdata(pdev, dwc); |
| 1287 | |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1288 | ret = dwc3_core_get_phy(dwc); |
| 1289 | if (ret) |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1290 | goto err0; |
Felipe Balbi | 3c9f94a | 2014-04-16 15:08:29 -0500 | [diff] [blame] | 1291 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1292 | spin_lock_init(&dwc->lock); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1293 | |
Heikki Krogerus | 19bacdc | 2014-09-24 11:00:38 +0300 | [diff] [blame] | 1294 | if (!dev->dma_mask) { |
| 1295 | dev->dma_mask = dev->parent->dma_mask; |
| 1296 | dev->dma_parms = dev->parent->dma_parms; |
| 1297 | dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); |
| 1298 | } |
Kishon Vijay Abraham I | ddff14f | 2013-03-07 18:51:43 +0530 | [diff] [blame] | 1299 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1300 | pm_runtime_no_callbacks(dev); |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1301 | pm_runtime_set_active(dev); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 1302 | pm_runtime_enable(dev); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 1303 | pm_runtime_forbid(dev); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1304 | |
John Youn | 77966eb | 2016-02-19 17:31:01 -0800 | [diff] [blame] | 1305 | /* Check the maximum_speed parameter */ |
| 1306 | switch (dwc->maximum_speed) { |
| 1307 | case USB_SPEED_LOW: |
| 1308 | case USB_SPEED_FULL: |
| 1309 | case USB_SPEED_HIGH: |
| 1310 | case USB_SPEED_SUPER: |
| 1311 | case USB_SPEED_SUPER_PLUS: |
| 1312 | break; |
| 1313 | default: |
| 1314 | dev_err(dev, "invalid maximum_speed parameter %d\n", |
| 1315 | dwc->maximum_speed); |
| 1316 | /* fall through */ |
| 1317 | case USB_SPEED_UNKNOWN: |
| 1318 | /* default to superspeed */ |
John Youn | 2c7f1bd | 2016-02-05 17:08:59 -0800 | [diff] [blame] | 1319 | dwc->maximum_speed = USB_SPEED_SUPER; |
| 1320 | |
| 1321 | /* |
| 1322 | * default to superspeed plus if we are capable. |
| 1323 | */ |
| 1324 | if (dwc3_is_usb31(dwc) && |
| 1325 | (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == |
| 1326 | DWC3_GHWPARAMS3_SSPHY_IFC_GEN2)) |
| 1327 | dwc->maximum_speed = USB_SPEED_SUPER_PLUS; |
John Youn | 77966eb | 2016-02-19 17:31:01 -0800 | [diff] [blame] | 1328 | |
| 1329 | break; |
John Youn | 2c7f1bd | 2016-02-05 17:08:59 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1332 | /* Adjust Frame Length */ |
| 1333 | dwc3_frame_length_adjustment(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1334 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1335 | /* Hardcode number of eps */ |
| 1336 | dwc->num_in_eps = 16; |
| 1337 | dwc->num_out_eps = 16; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1338 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1339 | ret = dwc3_core_init_mode(dwc); |
| 1340 | if (ret) |
Kyle Yan | 65be4a5 | 2016-10-31 15:05:00 -0700 | [diff] [blame] | 1341 | goto err0; |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1342 | |
| 1343 | ret = dwc3_debugfs_init(dwc); |
| 1344 | if (ret) { |
| 1345 | dev_err(dev, "failed to initialize debugfs\n"); |
Kyle Yan | 65be4a5 | 2016-10-31 15:05:00 -0700 | [diff] [blame] | 1346 | goto err_core_init; |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Mayank Rana | 861da2b | 2016-07-13 13:47:57 -0700 | [diff] [blame^] | 1349 | dwc->dwc_ipc_log_ctxt = ipc_log_context_create(NUM_LOG_PAGES, |
| 1350 | dev_name(dwc->dev), 0); |
| 1351 | if (!dwc->dwc_ipc_log_ctxt) |
| 1352 | dev_err(dwc->dev, "Error getting ipc_log_ctxt\n"); |
| 1353 | |
| 1354 | dwc3_instance[count] = dwc; |
| 1355 | dwc->index = count; |
| 1356 | count++; |
| 1357 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1358 | pm_runtime_allow(dev); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1359 | return 0; |
| 1360 | |
Kyle Yan | 65be4a5 | 2016-10-31 15:05:00 -0700 | [diff] [blame] | 1361 | err_core_init: |
| 1362 | dwc3_core_exit_mode(dwc); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1363 | err0: |
| 1364 | /* |
| 1365 | * restore res->start back to its original value so that, in case the |
| 1366 | * probe is deferred, we don't end up getting error in request the |
| 1367 | * memory region the next time probe is called. |
| 1368 | */ |
| 1369 | res->start -= DWC3_GLOBALS_REGS_START; |
| 1370 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1371 | return ret; |
| 1372 | } |
| 1373 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 1374 | static int dwc3_remove(struct platform_device *pdev) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1375 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1376 | struct dwc3 *dwc = platform_get_drvdata(pdev); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1377 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1378 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1379 | pm_runtime_get_sync(&pdev->dev); |
Felipe Balbi | 3da1f6e | 2014-09-02 15:19:43 -0500 | [diff] [blame] | 1380 | /* |
| 1381 | * restore res->start back to its original value so that, in case the |
| 1382 | * probe is deferred, we don't end up getting error in request the |
| 1383 | * memory region the next time probe is called. |
| 1384 | */ |
| 1385 | res->start -= DWC3_GLOBALS_REGS_START; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1386 | |
Felipe Balbi | dc99f16 | 2014-09-03 16:13:37 -0500 | [diff] [blame] | 1387 | dwc3_debugfs_exit(dwc); |
| 1388 | dwc3_core_exit_mode(dwc); |
Kishon Vijay Abraham I | 8ba007a | 2013-01-25 08:30:54 +0530 | [diff] [blame] | 1389 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1390 | dwc3_core_exit(dwc); |
Heikki Krogerus | 88bc9d1 | 2015-05-13 15:26:51 +0300 | [diff] [blame] | 1391 | dwc3_ulpi_exit(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1392 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1393 | pm_runtime_put_sync(&pdev->dev); |
| 1394 | pm_runtime_allow(&pdev->dev); |
| 1395 | pm_runtime_disable(&pdev->dev); |
| 1396 | |
Felipe Balbi | c499ff7 | 2016-05-16 10:49:01 +0300 | [diff] [blame] | 1397 | dwc3_free_event_buffers(dwc); |
| 1398 | dwc3_free_scratch_buffers(dwc); |
| 1399 | |
Mayank Rana | 861da2b | 2016-07-13 13:47:57 -0700 | [diff] [blame^] | 1400 | ipc_log_context_destroy(dwc->dwc_ipc_log_ctxt); |
| 1401 | dwc->dwc_ipc_log_ctxt = NULL; |
| 1402 | count--; |
| 1403 | dwc3_instance[dwc->index] = NULL; |
| 1404 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1405 | return 0; |
| 1406 | } |
| 1407 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1408 | #ifdef CONFIG_PM |
| 1409 | static int dwc3_suspend_common(struct dwc3 *dwc) |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1410 | { |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1411 | unsigned long flags; |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1412 | |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1413 | switch (dwc->dr_mode) { |
| 1414 | case USB_DR_MODE_PERIPHERAL: |
| 1415 | case USB_DR_MODE_OTG: |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1416 | spin_lock_irqsave(&dwc->lock, flags); |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1417 | dwc3_gadget_suspend(dwc); |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1418 | spin_unlock_irqrestore(&dwc->lock, flags); |
Felipe Balbi | 51f5d49 | 2016-05-16 10:52:58 +0300 | [diff] [blame] | 1419 | break; |
Ruchika Kharwar | a45c82b8 | 2013-07-06 07:52:49 -0500 | [diff] [blame] | 1420 | case USB_DR_MODE_HOST: |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1421 | default: |
Felipe Balbi | 51f5d49 | 2016-05-16 10:52:58 +0300 | [diff] [blame] | 1422 | /* do nothing */ |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | |
Felipe Balbi | 51f5d49 | 2016-05-16 10:52:58 +0300 | [diff] [blame] | 1426 | dwc3_core_exit(dwc); |
Felipe Balbi | 5c4ad318 | 2016-04-11 17:12:34 +0300 | [diff] [blame] | 1427 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | static int dwc3_resume_common(struct dwc3 *dwc) |
| 1432 | { |
| 1433 | unsigned long flags; |
| 1434 | int ret; |
| 1435 | |
| 1436 | ret = dwc3_core_init(dwc); |
| 1437 | if (ret) |
| 1438 | return ret; |
| 1439 | |
| 1440 | switch (dwc->dr_mode) { |
| 1441 | case USB_DR_MODE_PERIPHERAL: |
| 1442 | case USB_DR_MODE_OTG: |
| 1443 | spin_lock_irqsave(&dwc->lock, flags); |
| 1444 | dwc3_gadget_resume(dwc); |
| 1445 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 1446 | /* FALLTHROUGH */ |
| 1447 | case USB_DR_MODE_HOST: |
| 1448 | default: |
| 1449 | /* do nothing */ |
| 1450 | break; |
| 1451 | } |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
| 1455 | |
| 1456 | static int dwc3_runtime_checks(struct dwc3 *dwc) |
| 1457 | { |
| 1458 | switch (dwc->dr_mode) { |
| 1459 | case USB_DR_MODE_PERIPHERAL: |
| 1460 | case USB_DR_MODE_OTG: |
| 1461 | if (dwc->connected) |
| 1462 | return -EBUSY; |
| 1463 | break; |
| 1464 | case USB_DR_MODE_HOST: |
| 1465 | default: |
| 1466 | /* do nothing */ |
| 1467 | break; |
| 1468 | } |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | static int dwc3_runtime_suspend(struct device *dev) |
| 1474 | { |
| 1475 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1476 | int ret; |
| 1477 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1478 | /* Check if platform glue driver handling PM, if not then handle here */ |
| 1479 | if (!dwc3_notify_event(dwc, DWC3_CORE_PM_RESUME_EVENT)) |
| 1480 | return 0; |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1481 | |
| 1482 | ret = dwc3_suspend_common(dwc); |
| 1483 | if (ret) |
| 1484 | return ret; |
| 1485 | |
| 1486 | device_init_wakeup(dev, true); |
| 1487 | |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
| 1491 | static int dwc3_runtime_resume(struct device *dev) |
| 1492 | { |
| 1493 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1494 | int ret; |
| 1495 | |
Mayank Rana | a99689a | 2016-08-10 17:39:47 -0700 | [diff] [blame] | 1496 | /* Check if platform glue driver handling PM, if not then handle here */ |
| 1497 | if (!dwc3_notify_event(dwc, DWC3_CORE_PM_RESUME_EVENT)) |
| 1498 | return 0; |
| 1499 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1500 | device_init_wakeup(dev, false); |
| 1501 | |
| 1502 | ret = dwc3_resume_common(dwc); |
| 1503 | if (ret) |
| 1504 | return ret; |
| 1505 | |
| 1506 | switch (dwc->dr_mode) { |
| 1507 | case USB_DR_MODE_PERIPHERAL: |
| 1508 | case USB_DR_MODE_OTG: |
| 1509 | dwc3_gadget_process_pending_events(dwc); |
| 1510 | break; |
| 1511 | case USB_DR_MODE_HOST: |
| 1512 | default: |
| 1513 | /* do nothing */ |
| 1514 | break; |
| 1515 | } |
| 1516 | |
| 1517 | pm_runtime_mark_last_busy(dev); |
Felipe Balbi | b74c2d8 | 2016-07-28 13:07:07 +0300 | [diff] [blame] | 1518 | pm_runtime_put(dev); |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1519 | |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | static int dwc3_runtime_idle(struct device *dev) |
| 1524 | { |
| 1525 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1526 | |
| 1527 | switch (dwc->dr_mode) { |
| 1528 | case USB_DR_MODE_PERIPHERAL: |
| 1529 | case USB_DR_MODE_OTG: |
| 1530 | if (dwc3_runtime_checks(dwc)) |
| 1531 | return -EBUSY; |
| 1532 | break; |
| 1533 | case USB_DR_MODE_HOST: |
| 1534 | default: |
| 1535 | /* do nothing */ |
| 1536 | break; |
| 1537 | } |
| 1538 | |
| 1539 | pm_runtime_mark_last_busy(dev); |
| 1540 | pm_runtime_autosuspend(dev); |
| 1541 | |
| 1542 | return 0; |
| 1543 | } |
| 1544 | #endif /* CONFIG_PM */ |
| 1545 | |
| 1546 | #ifdef CONFIG_PM_SLEEP |
| 1547 | static int dwc3_suspend(struct device *dev) |
| 1548 | { |
| 1549 | struct dwc3 *dwc = dev_get_drvdata(dev); |
| 1550 | int ret; |
| 1551 | |
| 1552 | ret = dwc3_suspend_common(dwc); |
| 1553 | if (ret) |
| 1554 | return ret; |
| 1555 | |
Sekhar Nori | 6344475 | 2015-08-31 21:09:08 +0530 | [diff] [blame] | 1556 | pinctrl_pm_select_sleep_state(dev); |
| 1557 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static int dwc3_resume(struct device *dev) |
| 1562 | { |
| 1563 | struct dwc3 *dwc = dev_get_drvdata(dev); |
Kishon Vijay Abraham I | 5730348 | 2014-03-03 17:08:11 +0530 | [diff] [blame] | 1564 | int ret; |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1565 | |
Sekhar Nori | 6344475 | 2015-08-31 21:09:08 +0530 | [diff] [blame] | 1566 | pinctrl_pm_select_default_state(dev); |
| 1567 | |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1568 | ret = dwc3_resume_common(dwc); |
Felipe Balbi | 51f5d49 | 2016-05-16 10:52:58 +0300 | [diff] [blame] | 1569 | if (ret) |
Felipe Balbi | 5c4ad318 | 2016-04-11 17:12:34 +0300 | [diff] [blame] | 1570 | return ret; |
| 1571 | |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1572 | pm_runtime_disable(dev); |
| 1573 | pm_runtime_set_active(dev); |
| 1574 | pm_runtime_enable(dev); |
| 1575 | |
| 1576 | return 0; |
| 1577 | } |
Felipe Balbi | 7f370ed | 2016-05-09 15:27:01 +0300 | [diff] [blame] | 1578 | #endif /* CONFIG_PM_SLEEP */ |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1579 | |
| 1580 | static const struct dev_pm_ops dwc3_dev_pm_ops = { |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1581 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) |
Felipe Balbi | fc8bb91 | 2016-05-16 13:14:48 +0300 | [diff] [blame] | 1582 | SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, |
| 1583 | dwc3_runtime_idle) |
Felipe Balbi | 7415f17 | 2012-04-30 14:56:33 +0300 | [diff] [blame] | 1584 | }; |
| 1585 | |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1586 | #ifdef CONFIG_OF |
| 1587 | static const struct of_device_id of_dwc3_match[] = { |
| 1588 | { |
Felipe Balbi | 22a5aa1 | 2013-07-02 21:20:24 +0300 | [diff] [blame] | 1589 | .compatible = "snps,dwc3" |
| 1590 | }, |
| 1591 | { |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1592 | .compatible = "synopsys,dwc3" |
| 1593 | }, |
| 1594 | { }, |
| 1595 | }; |
| 1596 | MODULE_DEVICE_TABLE(of, of_dwc3_match); |
| 1597 | #endif |
| 1598 | |
Heikki Krogerus | 404905a | 2014-09-25 10:57:02 +0300 | [diff] [blame] | 1599 | #ifdef CONFIG_ACPI |
| 1600 | |
| 1601 | #define ACPI_ID_INTEL_BSW "808622B7" |
| 1602 | |
| 1603 | static const struct acpi_device_id dwc3_acpi_match[] = { |
| 1604 | { ACPI_ID_INTEL_BSW, 0 }, |
| 1605 | { }, |
| 1606 | }; |
| 1607 | MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match); |
| 1608 | #endif |
| 1609 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1610 | static struct platform_driver dwc3_driver = { |
| 1611 | .probe = dwc3_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 1612 | .remove = dwc3_remove, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1613 | .driver = { |
| 1614 | .name = "dwc3", |
Kishon Vijay Abraham I | 5088b6f | 2013-01-25 16:36:53 +0530 | [diff] [blame] | 1615 | .of_match_table = of_match_ptr(of_dwc3_match), |
Heikki Krogerus | 404905a | 2014-09-25 10:57:02 +0300 | [diff] [blame] | 1616 | .acpi_match_table = ACPI_PTR(dwc3_acpi_match), |
Felipe Balbi | 7f370ed | 2016-05-09 15:27:01 +0300 | [diff] [blame] | 1617 | .pm = &dwc3_dev_pm_ops, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1618 | }, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1619 | }; |
| 1620 | |
Tobias Klauser | b1116dc | 2012-02-28 12:57:20 +0100 | [diff] [blame] | 1621 | module_platform_driver(dwc3_driver); |
| 1622 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 1623 | MODULE_ALIAS("platform:dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1624 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
Felipe Balbi | 5945f78 | 2013-06-30 14:15:11 +0300 | [diff] [blame] | 1625 | MODULE_LICENSE("GPL v2"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1626 | MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); |