Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * core.c - DesignWare HS OTG Controller common routines |
| 3 | * |
| 4 | * Copyright (C) 2004-2013 Synopsys, Inc. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions, and the following disclaimer, |
| 11 | * without modification. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The names of the above-listed copyright holders may not be used |
| 16 | * to endorse or promote products derived from this software without |
| 17 | * specific prior written permission. |
| 18 | * |
| 19 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 20 | * GNU General Public License ("GPL") as published by the Free Software |
| 21 | * Foundation; either version 2 of the License, or (at your option) any |
| 22 | * later version. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 26 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * The Core code provides basic services for accessing and managing the |
| 39 | * DWC_otg hardware. These services are used by both the Host Controller |
| 40 | * Driver and the Peripheral Controller Driver. |
| 41 | */ |
| 42 | #include <linux/kernel.h> |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/moduleparam.h> |
| 45 | #include <linux/spinlock.h> |
| 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/dma-mapping.h> |
| 48 | #include <linux/delay.h> |
| 49 | #include <linux/io.h> |
| 50 | #include <linux/slab.h> |
| 51 | #include <linux/usb.h> |
| 52 | |
| 53 | #include <linux/usb/hcd.h> |
| 54 | #include <linux/usb/ch11.h> |
| 55 | |
| 56 | #include "core.h" |
| 57 | #include "hcd.h" |
| 58 | |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 59 | /** |
| 60 | * dwc2_backup_global_registers() - Backup global controller registers. |
| 61 | * When suspending usb bus, registers needs to be backuped |
| 62 | * if controller power is disabled once suspended. |
| 63 | * |
| 64 | * @hsotg: Programming view of the DWC_otg controller |
| 65 | */ |
| 66 | static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg) |
| 67 | { |
| 68 | struct dwc2_gregs_backup *gr; |
| 69 | int i; |
| 70 | |
| 71 | /* Backup global regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 72 | gr = &hsotg->gr_backup; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 73 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 74 | gr->gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
| 75 | gr->gintmsk = dwc2_readl(hsotg->regs + GINTMSK); |
| 76 | gr->gahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
| 77 | gr->gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 78 | gr->grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
| 79 | gr->gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 80 | gr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); |
| 81 | gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 82 | for (i = 0; i < MAX_EPS_CHANNELS; i++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 83 | gr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 84 | |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 85 | gr->valid = true; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * dwc2_restore_global_registers() - Restore controller global registers. |
| 91 | * When resuming usb bus, device registers needs to be restored |
| 92 | * if controller power were disabled. |
| 93 | * |
| 94 | * @hsotg: Programming view of the DWC_otg controller |
| 95 | */ |
| 96 | static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg) |
| 97 | { |
| 98 | struct dwc2_gregs_backup *gr; |
| 99 | int i; |
| 100 | |
| 101 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 102 | |
| 103 | /* Restore global regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 104 | gr = &hsotg->gr_backup; |
| 105 | if (!gr->valid) { |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 106 | dev_err(hsotg->dev, "%s: no global registers to restore\n", |
| 107 | __func__); |
| 108 | return -EINVAL; |
| 109 | } |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 110 | gr->valid = false; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 111 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 112 | dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); |
| 113 | dwc2_writel(gr->gotgctl, hsotg->regs + GOTGCTL); |
| 114 | dwc2_writel(gr->gintmsk, hsotg->regs + GINTMSK); |
| 115 | dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); |
| 116 | dwc2_writel(gr->gahbcfg, hsotg->regs + GAHBCFG); |
| 117 | dwc2_writel(gr->grxfsiz, hsotg->regs + GRXFSIZ); |
| 118 | dwc2_writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ); |
| 119 | dwc2_writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ); |
| 120 | dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 121 | for (i = 0; i < MAX_EPS_CHANNELS; i++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 122 | dwc2_writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * dwc2_exit_hibernation() - Exit controller from Partial Power Down. |
| 129 | * |
| 130 | * @hsotg: Programming view of the DWC_otg controller |
| 131 | * @restore: Controller registers need to be restored |
| 132 | */ |
| 133 | int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore) |
| 134 | { |
| 135 | u32 pcgcctl; |
| 136 | int ret = 0; |
| 137 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 138 | if (!hsotg->core_params->hibernation) |
| 139 | return -ENOTSUPP; |
| 140 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 141 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 142 | pcgcctl &= ~PCGCTL_STOPPCLK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 143 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 144 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 145 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 146 | pcgcctl &= ~PCGCTL_PWRCLMP; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 147 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 148 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 149 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 150 | pcgcctl &= ~PCGCTL_RSTPDWNMODULE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 151 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 152 | |
| 153 | udelay(100); |
| 154 | if (restore) { |
| 155 | ret = dwc2_restore_global_registers(hsotg); |
| 156 | if (ret) { |
| 157 | dev_err(hsotg->dev, "%s: failed to restore registers\n", |
| 158 | __func__); |
| 159 | return ret; |
| 160 | } |
| 161 | if (dwc2_is_host_mode(hsotg)) { |
| 162 | ret = dwc2_restore_host_registers(hsotg); |
| 163 | if (ret) { |
| 164 | dev_err(hsotg->dev, "%s: failed to restore host registers\n", |
| 165 | __func__); |
| 166 | return ret; |
| 167 | } |
| 168 | } else { |
| 169 | ret = dwc2_restore_device_registers(hsotg); |
| 170 | if (ret) { |
| 171 | dev_err(hsotg->dev, "%s: failed to restore device registers\n", |
| 172 | __func__); |
| 173 | return ret; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return ret; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * dwc2_enter_hibernation() - Put controller in Partial Power Down. |
| 183 | * |
| 184 | * @hsotg: Programming view of the DWC_otg controller |
| 185 | */ |
| 186 | int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg) |
| 187 | { |
| 188 | u32 pcgcctl; |
| 189 | int ret = 0; |
| 190 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 191 | if (!hsotg->core_params->hibernation) |
| 192 | return -ENOTSUPP; |
| 193 | |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 194 | /* Backup all registers */ |
| 195 | ret = dwc2_backup_global_registers(hsotg); |
| 196 | if (ret) { |
| 197 | dev_err(hsotg->dev, "%s: failed to backup global registers\n", |
| 198 | __func__); |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | if (dwc2_is_host_mode(hsotg)) { |
| 203 | ret = dwc2_backup_host_registers(hsotg); |
| 204 | if (ret) { |
| 205 | dev_err(hsotg->dev, "%s: failed to backup host registers\n", |
| 206 | __func__); |
| 207 | return ret; |
| 208 | } |
| 209 | } else { |
| 210 | ret = dwc2_backup_device_registers(hsotg); |
| 211 | if (ret) { |
| 212 | dev_err(hsotg->dev, "%s: failed to backup device registers\n", |
| 213 | __func__); |
| 214 | return ret; |
| 215 | } |
| 216 | } |
| 217 | |
Gregory Herrero | cad73da | 2015-09-22 15:16:49 +0200 | [diff] [blame] | 218 | /* |
| 219 | * Clear any pending interrupts since dwc2 will not be able to |
| 220 | * clear them after entering hibernation. |
| 221 | */ |
| 222 | dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); |
| 223 | |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 224 | /* Put the controller in low power state */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 225 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 226 | |
| 227 | pcgcctl |= PCGCTL_PWRCLMP; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 228 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 229 | ndelay(20); |
| 230 | |
| 231 | pcgcctl |= PCGCTL_RSTPDWNMODULE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 232 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 233 | ndelay(20); |
| 234 | |
| 235 | pcgcctl |= PCGCTL_STOPPCLK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 236 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
John Youn | fef6bc3 | 2016-09-07 19:39:40 -0700 | [diff] [blame^] | 241 | /** |
| 242 | * dwc2_wait_for_mode() - Waits for the controller mode. |
| 243 | * @hsotg: Programming view of the DWC_otg controller. |
| 244 | * @host_mode: If true, waits for host mode, otherwise device mode. |
| 245 | */ |
| 246 | static void dwc2_wait_for_mode(struct dwc2_hsotg *hsotg, |
| 247 | bool host_mode) |
| 248 | { |
| 249 | ktime_t start; |
| 250 | ktime_t end; |
| 251 | unsigned int timeout = 110; |
| 252 | |
| 253 | dev_vdbg(hsotg->dev, "Waiting for %s mode\n", |
| 254 | host_mode ? "host" : "device"); |
| 255 | |
| 256 | start = ktime_get(); |
| 257 | |
| 258 | while (1) { |
| 259 | s64 ms; |
| 260 | |
| 261 | if (dwc2_is_host_mode(hsotg) == host_mode) { |
| 262 | dev_vdbg(hsotg->dev, "%s mode set\n", |
| 263 | host_mode ? "Host" : "Device"); |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | end = ktime_get(); |
| 268 | ms = ktime_to_ms(ktime_sub(end, start)); |
| 269 | |
| 270 | if (ms >= (s64)timeout) { |
| 271 | dev_warn(hsotg->dev, "%s: Couldn't set %s mode\n", |
| 272 | __func__, host_mode ? "host" : "device"); |
| 273 | break; |
| 274 | } |
| 275 | |
| 276 | usleep_range(1000, 2000); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce |
| 282 | * filter is enabled. |
| 283 | */ |
| 284 | static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg) |
| 285 | { |
| 286 | u32 gsnpsid; |
| 287 | u32 ghwcfg4; |
| 288 | |
| 289 | if (!dwc2_hw_is_otg(hsotg)) |
| 290 | return false; |
| 291 | |
| 292 | /* Check if core configuration includes the IDDIG filter. */ |
| 293 | ghwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); |
| 294 | if (!(ghwcfg4 & GHWCFG4_IDDIG_FILT_EN)) |
| 295 | return false; |
| 296 | |
| 297 | /* |
| 298 | * Check if the IDDIG debounce filter is bypassed. Available |
| 299 | * in core version >= 3.10a. |
| 300 | */ |
| 301 | gsnpsid = dwc2_readl(hsotg->regs + GSNPSID); |
| 302 | if (gsnpsid >= DWC2_CORE_REV_3_10a) { |
| 303 | u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
| 304 | |
| 305 | if (gotgctl & GOTGCTL_DBNCE_FLTR_BYPASS) |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | return true; |
| 310 | } |
| 311 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 312 | /* |
| 313 | * Do core a soft reset of the core. Be careful with this because it |
| 314 | * resets all the internal state machines of the core. |
| 315 | */ |
John Youn | b5d308a | 2015-12-17 11:16:03 -0800 | [diff] [blame] | 316 | int dwc2_core_reset(struct dwc2_hsotg *hsotg) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 317 | { |
| 318 | u32 greset; |
| 319 | int count = 0; |
John Youn | fef6bc3 | 2016-09-07 19:39:40 -0700 | [diff] [blame^] | 320 | bool wait_for_host_mode = false; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 321 | |
| 322 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 323 | |
John Youn | fef6bc3 | 2016-09-07 19:39:40 -0700 | [diff] [blame^] | 324 | /* |
| 325 | * If the current mode is host, either due to the force mode |
| 326 | * bit being set (which persists after core reset) or the |
| 327 | * connector id pin, a core soft reset will temporarily reset |
| 328 | * the mode to device. A delay from the IDDIG debounce filter |
| 329 | * will occur before going back to host mode. |
| 330 | * |
| 331 | * Determine whether we will go back into host mode after a |
| 332 | * reset and account for this delay after the reset. |
| 333 | */ |
| 334 | if (dwc2_iddig_filter_enabled(hsotg)) { |
| 335 | u32 gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
| 336 | u32 gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 337 | |
| 338 | if (!(gotgctl & GOTGCTL_CONID_B) || |
| 339 | (gusbcfg & GUSBCFG_FORCEHOSTMODE)) { |
| 340 | wait_for_host_mode = true; |
| 341 | } |
| 342 | } |
| 343 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 344 | /* Core Soft Reset */ |
John Youn | b8ccc59 | 2015-12-17 11:15:35 -0800 | [diff] [blame] | 345 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 346 | greset |= GRSTCTL_CSFTRST; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 347 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 348 | do { |
Yunzhi Li | 20bde64 | 2015-12-17 11:15:08 -0800 | [diff] [blame] | 349 | udelay(1); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 350 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 351 | if (++count > 50) { |
| 352 | dev_warn(hsotg->dev, |
| 353 | "%s() HANG! Soft Reset GRSTCTL=%0x\n", |
| 354 | __func__, greset); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 355 | return -EBUSY; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 356 | } |
| 357 | } while (greset & GRSTCTL_CSFTRST); |
| 358 | |
John Youn | b8ccc59 | 2015-12-17 11:15:35 -0800 | [diff] [blame] | 359 | /* Wait for AHB master IDLE state */ |
| 360 | count = 0; |
| 361 | do { |
| 362 | udelay(1); |
| 363 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
| 364 | if (++count > 50) { |
| 365 | dev_warn(hsotg->dev, |
| 366 | "%s() HANG! AHB Idle GRSTCTL=%0x\n", |
| 367 | __func__, greset); |
| 368 | return -EBUSY; |
| 369 | } |
| 370 | } while (!(greset & GRSTCTL_AHBIDLE)); |
| 371 | |
John Youn | fef6bc3 | 2016-09-07 19:39:40 -0700 | [diff] [blame^] | 372 | if (wait_for_host_mode) |
| 373 | dwc2_wait_for_mode(hsotg, true); |
| 374 | |
John Youn | b5d308a | 2015-12-17 11:16:03 -0800 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 379 | * Force the mode of the controller. |
| 380 | * |
| 381 | * Forcing the mode is needed for two cases: |
| 382 | * |
| 383 | * 1) If the dr_mode is set to either HOST or PERIPHERAL we force the |
| 384 | * controller to stay in a particular mode regardless of ID pin |
| 385 | * changes. We do this usually after a core reset. |
| 386 | * |
| 387 | * 2) During probe we want to read reset values of the hw |
| 388 | * configuration registers that are only available in either host or |
| 389 | * device mode. We may need to force the mode if the current mode does |
| 390 | * not allow us to access the register in the mode that we want. |
| 391 | * |
| 392 | * In either case it only makes sense to force the mode if the |
| 393 | * controller hardware is OTG capable. |
| 394 | * |
| 395 | * Checks are done in this function to determine whether doing a force |
| 396 | * would be valid or not. |
| 397 | * |
| 398 | * If a force is done, it requires a 25ms delay to take effect. |
| 399 | * |
| 400 | * Returns true if the mode was forced. |
| 401 | */ |
| 402 | static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host) |
| 403 | { |
| 404 | u32 gusbcfg; |
| 405 | u32 set; |
| 406 | u32 clear; |
| 407 | |
| 408 | dev_dbg(hsotg->dev, "Forcing mode to %s\n", host ? "host" : "device"); |
| 409 | |
| 410 | /* |
| 411 | * Force mode has no effect if the hardware is not OTG. |
| 412 | */ |
| 413 | if (!dwc2_hw_is_otg(hsotg)) |
| 414 | return false; |
| 415 | |
| 416 | /* |
| 417 | * If dr_mode is either peripheral or host only, there is no |
| 418 | * need to ever force the mode to the opposite mode. |
| 419 | */ |
| 420 | if (WARN_ON(host && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)) |
| 421 | return false; |
| 422 | |
| 423 | if (WARN_ON(!host && hsotg->dr_mode == USB_DR_MODE_HOST)) |
| 424 | return false; |
| 425 | |
| 426 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 427 | |
| 428 | set = host ? GUSBCFG_FORCEHOSTMODE : GUSBCFG_FORCEDEVMODE; |
| 429 | clear = host ? GUSBCFG_FORCEDEVMODE : GUSBCFG_FORCEHOSTMODE; |
| 430 | |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 431 | gusbcfg &= ~clear; |
| 432 | gusbcfg |= set; |
| 433 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
| 434 | |
| 435 | msleep(25); |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Clears the force mode bits. |
| 441 | */ |
| 442 | static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg) |
| 443 | { |
| 444 | u32 gusbcfg; |
| 445 | |
| 446 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 447 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; |
| 448 | gusbcfg &= ~GUSBCFG_FORCEDEVMODE; |
| 449 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
| 450 | |
| 451 | /* |
| 452 | * NOTE: This long sleep is _very_ important, otherwise the core will |
| 453 | * not stay in host mode after a connector ID change! |
| 454 | */ |
John Youn | 97e4638 | 2015-12-17 11:18:13 -0800 | [diff] [blame] | 455 | msleep(25); |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Sets or clears force mode based on the dr_mode parameter. |
| 460 | */ |
| 461 | void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) |
| 462 | { |
| 463 | switch (hsotg->dr_mode) { |
| 464 | case USB_DR_MODE_HOST: |
| 465 | dwc2_force_mode(hsotg, true); |
| 466 | break; |
| 467 | case USB_DR_MODE_PERIPHERAL: |
| 468 | dwc2_force_mode(hsotg, false); |
| 469 | break; |
| 470 | case USB_DR_MODE_OTG: |
| 471 | dwc2_clear_force_mode(hsotg); |
| 472 | break; |
| 473 | default: |
| 474 | dev_warn(hsotg->dev, "%s() Invalid dr_mode=%d\n", |
| 475 | __func__, hsotg->dr_mode); |
| 476 | break; |
| 477 | } |
John Youn | bd84f4a | 2016-02-15 15:30:20 -0800 | [diff] [blame] | 478 | |
| 479 | /* |
| 480 | * NOTE: This is required for some rockchip soc based |
| 481 | * platforms. |
| 482 | */ |
| 483 | msleep(50); |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* |
John Youn | b5d308a | 2015-12-17 11:16:03 -0800 | [diff] [blame] | 487 | * Do core a soft reset of the core. Be careful with this because it |
| 488 | * resets all the internal state machines of the core. |
| 489 | * |
| 490 | * Additionally this will apply force mode as per the hsotg->dr_mode |
| 491 | * parameter. |
| 492 | */ |
| 493 | int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg) |
| 494 | { |
| 495 | int retval; |
John Youn | b5d308a | 2015-12-17 11:16:03 -0800 | [diff] [blame] | 496 | |
| 497 | retval = dwc2_core_reset(hsotg); |
| 498 | if (retval) |
| 499 | return retval; |
| 500 | |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 501 | dwc2_force_dr_mode(hsotg); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 502 | return 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 505 | /** |
| 506 | * dwc2_dump_host_registers() - Prints the host registers |
| 507 | * |
| 508 | * @hsotg: Programming view of DWC_otg controller |
| 509 | * |
| 510 | * NOTE: This function will be removed once the peripheral controller code |
| 511 | * is integrated and the driver is stable |
| 512 | */ |
| 513 | void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg) |
| 514 | { |
| 515 | #ifdef DEBUG |
| 516 | u32 __iomem *addr; |
| 517 | int i; |
| 518 | |
| 519 | dev_dbg(hsotg->dev, "Host Global Registers\n"); |
| 520 | addr = hsotg->regs + HCFG; |
| 521 | dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 522 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 523 | addr = hsotg->regs + HFIR; |
| 524 | dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 525 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 526 | addr = hsotg->regs + HFNUM; |
| 527 | dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 528 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 529 | addr = hsotg->regs + HPTXSTS; |
| 530 | dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 531 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 532 | addr = hsotg->regs + HAINT; |
| 533 | dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 534 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 535 | addr = hsotg->regs + HAINTMSK; |
| 536 | dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 537 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 538 | if (hsotg->core_params->dma_desc_enable > 0) { |
| 539 | addr = hsotg->regs + HFLBADDR; |
| 540 | dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 541 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | addr = hsotg->regs + HPRT0; |
| 545 | dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 546 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 547 | |
| 548 | for (i = 0; i < hsotg->core_params->host_channels; i++) { |
| 549 | dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i); |
| 550 | addr = hsotg->regs + HCCHAR(i); |
| 551 | dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 552 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 553 | addr = hsotg->regs + HCSPLT(i); |
| 554 | dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 555 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 556 | addr = hsotg->regs + HCINT(i); |
| 557 | dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 558 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 559 | addr = hsotg->regs + HCINTMSK(i); |
| 560 | dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 561 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 562 | addr = hsotg->regs + HCTSIZ(i); |
| 563 | dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 564 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 565 | addr = hsotg->regs + HCDMA(i); |
| 566 | dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 567 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 568 | if (hsotg->core_params->dma_desc_enable > 0) { |
| 569 | addr = hsotg->regs + HCDMAB(i); |
| 570 | dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 571 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | #endif |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * dwc2_dump_global_registers() - Prints the core global registers |
| 579 | * |
| 580 | * @hsotg: Programming view of DWC_otg controller |
| 581 | * |
| 582 | * NOTE: This function will be removed once the peripheral controller code |
| 583 | * is integrated and the driver is stable |
| 584 | */ |
| 585 | void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) |
| 586 | { |
| 587 | #ifdef DEBUG |
| 588 | u32 __iomem *addr; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 589 | |
| 590 | dev_dbg(hsotg->dev, "Core Global Registers\n"); |
| 591 | addr = hsotg->regs + GOTGCTL; |
| 592 | dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 593 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 594 | addr = hsotg->regs + GOTGINT; |
| 595 | dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 596 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 597 | addr = hsotg->regs + GAHBCFG; |
| 598 | dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 599 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 600 | addr = hsotg->regs + GUSBCFG; |
| 601 | dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 602 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 603 | addr = hsotg->regs + GRSTCTL; |
| 604 | dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 605 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 606 | addr = hsotg->regs + GINTSTS; |
| 607 | dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 608 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 609 | addr = hsotg->regs + GINTMSK; |
| 610 | dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 611 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 612 | addr = hsotg->regs + GRXSTSR; |
| 613 | dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 614 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 615 | addr = hsotg->regs + GRXFSIZ; |
| 616 | dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 617 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 618 | addr = hsotg->regs + GNPTXFSIZ; |
| 619 | dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 620 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 621 | addr = hsotg->regs + GNPTXSTS; |
| 622 | dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 623 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 624 | addr = hsotg->regs + GI2CCTL; |
| 625 | dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 626 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 627 | addr = hsotg->regs + GPVNDCTL; |
| 628 | dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 629 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 630 | addr = hsotg->regs + GGPIO; |
| 631 | dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 632 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 633 | addr = hsotg->regs + GUID; |
| 634 | dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 635 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 636 | addr = hsotg->regs + GSNPSID; |
| 637 | dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 638 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 639 | addr = hsotg->regs + GHWCFG1; |
| 640 | dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 641 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 642 | addr = hsotg->regs + GHWCFG2; |
| 643 | dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 644 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 645 | addr = hsotg->regs + GHWCFG3; |
| 646 | dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 647 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 648 | addr = hsotg->regs + GHWCFG4; |
| 649 | dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 650 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 651 | addr = hsotg->regs + GLPMCFG; |
| 652 | dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 653 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 654 | addr = hsotg->regs + GPWRDN; |
| 655 | dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 656 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 657 | addr = hsotg->regs + GDFIFOCFG; |
| 658 | dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 659 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 660 | addr = hsotg->regs + HPTXFSIZ; |
| 661 | dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 662 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 663 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 664 | addr = hsotg->regs + PCGCTL; |
| 665 | dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 666 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 667 | #endif |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * dwc2_flush_tx_fifo() - Flushes a Tx FIFO |
| 672 | * |
| 673 | * @hsotg: Programming view of DWC_otg controller |
| 674 | * @num: Tx FIFO to flush |
| 675 | */ |
| 676 | void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num) |
| 677 | { |
| 678 | u32 greset; |
| 679 | int count = 0; |
| 680 | |
| 681 | dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num); |
| 682 | |
| 683 | greset = GRSTCTL_TXFFLSH; |
| 684 | greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 685 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 686 | |
| 687 | do { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 688 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 689 | if (++count > 10000) { |
| 690 | dev_warn(hsotg->dev, |
| 691 | "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n", |
| 692 | __func__, greset, |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 693 | dwc2_readl(hsotg->regs + GNPTXSTS)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 694 | break; |
| 695 | } |
| 696 | udelay(1); |
| 697 | } while (greset & GRSTCTL_TXFFLSH); |
| 698 | |
| 699 | /* Wait for at least 3 PHY Clocks */ |
| 700 | udelay(1); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * dwc2_flush_rx_fifo() - Flushes the Rx FIFO |
| 705 | * |
| 706 | * @hsotg: Programming view of DWC_otg controller |
| 707 | */ |
| 708 | void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg) |
| 709 | { |
| 710 | u32 greset; |
| 711 | int count = 0; |
| 712 | |
| 713 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 714 | |
| 715 | greset = GRSTCTL_RXFFLSH; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 716 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 717 | |
| 718 | do { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 719 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 720 | if (++count > 10000) { |
| 721 | dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n", |
| 722 | __func__, greset); |
| 723 | break; |
| 724 | } |
| 725 | udelay(1); |
| 726 | } while (greset & GRSTCTL_RXFFLSH); |
| 727 | |
| 728 | /* Wait for at least 3 PHY Clocks */ |
| 729 | udelay(1); |
| 730 | } |
| 731 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 732 | #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 733 | |
| 734 | /* Parameter access functions */ |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 735 | void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 736 | { |
| 737 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 738 | |
| 739 | switch (val) { |
| 740 | case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 741 | if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 742 | valid = 0; |
| 743 | break; |
| 744 | case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 745 | switch (hsotg->hw_params.op_mode) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 746 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 747 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 748 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 749 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 750 | break; |
| 751 | default: |
| 752 | valid = 0; |
| 753 | break; |
| 754 | } |
| 755 | break; |
| 756 | case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: |
| 757 | /* always valid */ |
| 758 | break; |
| 759 | default: |
| 760 | valid = 0; |
| 761 | break; |
| 762 | } |
| 763 | |
| 764 | if (!valid) { |
| 765 | if (val >= 0) |
| 766 | dev_err(hsotg->dev, |
| 767 | "%d invalid for otg_cap parameter. Check HW configuration.\n", |
| 768 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 769 | switch (hsotg->hw_params.op_mode) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 770 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 771 | val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; |
| 772 | break; |
| 773 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 774 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 775 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 776 | val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; |
| 777 | break; |
| 778 | default: |
| 779 | val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 780 | break; |
| 781 | } |
| 782 | dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | hsotg->core_params->otg_cap = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 788 | void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 789 | { |
| 790 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 791 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 792 | if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 793 | valid = 0; |
| 794 | if (val < 0) |
| 795 | valid = 0; |
| 796 | |
| 797 | if (!valid) { |
| 798 | if (val >= 0) |
| 799 | dev_err(hsotg->dev, |
| 800 | "%d invalid for dma_enable parameter. Check HW configuration.\n", |
| 801 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 802 | val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 803 | dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | hsotg->core_params->dma_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 809 | void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 810 | { |
| 811 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 812 | |
| 813 | if (val > 0 && (hsotg->core_params->dma_enable <= 0 || |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 814 | !hsotg->hw_params.dma_desc_enable)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 815 | valid = 0; |
| 816 | if (val < 0) |
| 817 | valid = 0; |
| 818 | |
| 819 | if (!valid) { |
| 820 | if (val >= 0) |
| 821 | dev_err(hsotg->dev, |
| 822 | "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", |
| 823 | val); |
| 824 | val = (hsotg->core_params->dma_enable > 0 && |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 825 | hsotg->hw_params.dma_desc_enable); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 826 | dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | hsotg->core_params->dma_desc_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Mian Yousaf Kaukab | fbb9e22 | 2015-11-20 11:49:28 +0100 | [diff] [blame] | 832 | void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val) |
| 833 | { |
| 834 | int valid = 1; |
| 835 | |
| 836 | if (val > 0 && (hsotg->core_params->dma_enable <= 0 || |
| 837 | !hsotg->hw_params.dma_desc_enable)) |
| 838 | valid = 0; |
| 839 | if (val < 0) |
| 840 | valid = 0; |
| 841 | |
| 842 | if (!valid) { |
| 843 | if (val >= 0) |
| 844 | dev_err(hsotg->dev, |
| 845 | "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n", |
| 846 | val); |
| 847 | val = (hsotg->core_params->dma_enable > 0 && |
| 848 | hsotg->hw_params.dma_desc_enable); |
| 849 | } |
| 850 | |
| 851 | hsotg->core_params->dma_desc_fs_enable = val; |
| 852 | dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val); |
| 853 | } |
| 854 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 855 | void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, |
| 856 | int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 857 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 858 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 859 | if (val >= 0) { |
| 860 | dev_err(hsotg->dev, |
| 861 | "Wrong value for host_support_fs_low_power\n"); |
| 862 | dev_err(hsotg->dev, |
| 863 | "host_support_fs_low_power must be 0 or 1\n"); |
| 864 | } |
| 865 | val = 0; |
| 866 | dev_dbg(hsotg->dev, |
| 867 | "Setting host_support_fs_low_power to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | hsotg->core_params->host_support_fs_ls_low_power = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 873 | void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 874 | { |
| 875 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 876 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 877 | if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 878 | valid = 0; |
| 879 | if (val < 0) |
| 880 | valid = 0; |
| 881 | |
| 882 | if (!valid) { |
| 883 | if (val >= 0) |
| 884 | dev_err(hsotg->dev, |
| 885 | "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", |
| 886 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 887 | val = hsotg->hw_params.enable_dynamic_fifo; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 888 | dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | hsotg->core_params->enable_dynamic_fifo = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 894 | void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 895 | { |
| 896 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 897 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 898 | if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 899 | valid = 0; |
| 900 | |
| 901 | if (!valid) { |
| 902 | if (val >= 0) |
| 903 | dev_err(hsotg->dev, |
| 904 | "%d invalid for host_rx_fifo_size. Check HW configuration.\n", |
| 905 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 906 | val = hsotg->hw_params.host_rx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 907 | dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | hsotg->core_params->host_rx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 913 | void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 914 | { |
| 915 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 916 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 917 | if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 918 | valid = 0; |
| 919 | |
| 920 | if (!valid) { |
| 921 | if (val >= 0) |
| 922 | dev_err(hsotg->dev, |
| 923 | "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", |
| 924 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 925 | val = hsotg->hw_params.host_nperio_tx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 926 | dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", |
| 927 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | hsotg->core_params->host_nperio_tx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 933 | void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 934 | { |
| 935 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 936 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 937 | if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 938 | valid = 0; |
| 939 | |
| 940 | if (!valid) { |
| 941 | if (val >= 0) |
| 942 | dev_err(hsotg->dev, |
| 943 | "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", |
| 944 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 945 | val = hsotg->hw_params.host_perio_tx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 946 | dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", |
| 947 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | hsotg->core_params->host_perio_tx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 953 | void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 954 | { |
| 955 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 956 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 957 | if (val < 2047 || val > hsotg->hw_params.max_transfer_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 958 | valid = 0; |
| 959 | |
| 960 | if (!valid) { |
| 961 | if (val >= 0) |
| 962 | dev_err(hsotg->dev, |
| 963 | "%d invalid for max_transfer_size. Check HW configuration.\n", |
| 964 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 965 | val = hsotg->hw_params.max_transfer_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 966 | dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | hsotg->core_params->max_transfer_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 972 | void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 973 | { |
| 974 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 975 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 976 | if (val < 15 || val > hsotg->hw_params.max_packet_count) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 977 | valid = 0; |
| 978 | |
| 979 | if (!valid) { |
| 980 | if (val >= 0) |
| 981 | dev_err(hsotg->dev, |
| 982 | "%d invalid for max_packet_count. Check HW configuration.\n", |
| 983 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 984 | val = hsotg->hw_params.max_packet_count; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 985 | dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | hsotg->core_params->max_packet_count = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 991 | void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 992 | { |
| 993 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 994 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 995 | if (val < 1 || val > hsotg->hw_params.host_channels) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 996 | valid = 0; |
| 997 | |
| 998 | if (!valid) { |
| 999 | if (val >= 0) |
| 1000 | dev_err(hsotg->dev, |
| 1001 | "%d invalid for host_channels. Check HW configuration.\n", |
| 1002 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1003 | val = hsotg->hw_params.host_channels; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1004 | dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | hsotg->core_params->host_channels = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1010 | void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1011 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1012 | int valid = 0; |
Luis Ortega Perez de Villar | 0464a3d | 2013-09-25 13:10:50 +0200 | [diff] [blame] | 1013 | u32 hs_phy_type, fs_phy_type; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1014 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1015 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS, |
| 1016 | DWC2_PHY_TYPE_PARAM_ULPI)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1017 | if (val >= 0) { |
| 1018 | dev_err(hsotg->dev, "Wrong value for phy_type\n"); |
| 1019 | dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n"); |
| 1020 | } |
| 1021 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1022 | valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1025 | hs_phy_type = hsotg->hw_params.hs_phy_type; |
| 1026 | fs_phy_type = hsotg->hw_params.fs_phy_type; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1027 | if (val == DWC2_PHY_TYPE_PARAM_UTMI && |
| 1028 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || |
| 1029 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 1030 | valid = 1; |
| 1031 | else if (val == DWC2_PHY_TYPE_PARAM_ULPI && |
| 1032 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI || |
| 1033 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 1034 | valid = 1; |
| 1035 | else if (val == DWC2_PHY_TYPE_PARAM_FS && |
| 1036 | fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) |
| 1037 | valid = 1; |
| 1038 | |
| 1039 | if (!valid) { |
| 1040 | if (val >= 0) |
| 1041 | dev_err(hsotg->dev, |
| 1042 | "%d invalid for phy_type. Check HW configuration.\n", |
| 1043 | val); |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 1044 | val = DWC2_PHY_TYPE_PARAM_FS; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1045 | if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { |
| 1046 | if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || |
| 1047 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) |
| 1048 | val = DWC2_PHY_TYPE_PARAM_UTMI; |
| 1049 | else |
| 1050 | val = DWC2_PHY_TYPE_PARAM_ULPI; |
| 1051 | } |
| 1052 | dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1053 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1054 | |
| 1055 | hsotg->core_params->phy_type = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg) |
| 1059 | { |
| 1060 | return hsotg->core_params->phy_type; |
| 1061 | } |
| 1062 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1063 | void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1064 | { |
| 1065 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1066 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1067 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1068 | if (val >= 0) { |
| 1069 | dev_err(hsotg->dev, "Wrong value for speed parameter\n"); |
| 1070 | dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n"); |
| 1071 | } |
| 1072 | valid = 0; |
| 1073 | } |
| 1074 | |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 1075 | if (val == DWC2_SPEED_PARAM_HIGH && |
| 1076 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1077 | valid = 0; |
| 1078 | |
| 1079 | if (!valid) { |
| 1080 | if (val >= 0) |
| 1081 | dev_err(hsotg->dev, |
| 1082 | "%d invalid for speed parameter. Check HW configuration.\n", |
| 1083 | val); |
| 1084 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 1085 | DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1086 | dev_dbg(hsotg->dev, "Setting speed to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | hsotg->core_params->speed = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1092 | void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1093 | { |
| 1094 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1095 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1096 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ, |
| 1097 | DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1098 | if (val >= 0) { |
| 1099 | dev_err(hsotg->dev, |
| 1100 | "Wrong value for host_ls_low_power_phy_clk parameter\n"); |
| 1101 | dev_err(hsotg->dev, |
| 1102 | "host_ls_low_power_phy_clk must be 0 or 1\n"); |
| 1103 | } |
| 1104 | valid = 0; |
| 1105 | } |
| 1106 | |
| 1107 | if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ && |
| 1108 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) |
| 1109 | valid = 0; |
| 1110 | |
| 1111 | if (!valid) { |
| 1112 | if (val >= 0) |
| 1113 | dev_err(hsotg->dev, |
| 1114 | "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n", |
| 1115 | val); |
| 1116 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS |
| 1117 | ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ |
| 1118 | : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ; |
| 1119 | dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n", |
| 1120 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | hsotg->core_params->host_ls_low_power_phy_clk = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1126 | void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1127 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1128 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1129 | if (val >= 0) { |
| 1130 | dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n"); |
| 1131 | dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n"); |
| 1132 | } |
| 1133 | val = 0; |
| 1134 | dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | hsotg->core_params->phy_ulpi_ddr = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1140 | void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1141 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1142 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1143 | if (val >= 0) { |
| 1144 | dev_err(hsotg->dev, |
| 1145 | "Wrong value for phy_ulpi_ext_vbus\n"); |
| 1146 | dev_err(hsotg->dev, |
| 1147 | "phy_ulpi_ext_vbus must be 0 or 1\n"); |
| 1148 | } |
| 1149 | val = 0; |
| 1150 | dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | hsotg->core_params->phy_ulpi_ext_vbus = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1156 | void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1157 | { |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1158 | int valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1159 | |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1160 | switch (hsotg->hw_params.utmi_phy_data_width) { |
| 1161 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: |
| 1162 | valid = (val == 8); |
| 1163 | break; |
| 1164 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: |
| 1165 | valid = (val == 16); |
| 1166 | break; |
| 1167 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: |
| 1168 | valid = (val == 8 || val == 16); |
| 1169 | break; |
| 1170 | } |
| 1171 | |
| 1172 | if (!valid) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1173 | if (val >= 0) { |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1174 | dev_err(hsotg->dev, |
| 1175 | "%d invalid for phy_utmi_width. Check HW configuration.\n", |
| 1176 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1177 | } |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1178 | val = (hsotg->hw_params.utmi_phy_data_width == |
| 1179 | GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1180 | dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | hsotg->core_params->phy_utmi_width = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1186 | void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1187 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1188 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1189 | if (val >= 0) { |
| 1190 | dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n"); |
| 1191 | dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n"); |
| 1192 | } |
| 1193 | val = 0; |
| 1194 | dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | hsotg->core_params->ulpi_fs_ls = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1200 | void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1201 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1202 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1203 | if (val >= 0) { |
| 1204 | dev_err(hsotg->dev, "Wrong value for ts_dline\n"); |
| 1205 | dev_err(hsotg->dev, "ts_dline must be 0 or 1\n"); |
| 1206 | } |
| 1207 | val = 0; |
| 1208 | dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | hsotg->core_params->ts_dline = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1214 | void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1215 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1216 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1217 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1218 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1219 | if (val >= 0) { |
| 1220 | dev_err(hsotg->dev, "Wrong value for i2c_enable\n"); |
| 1221 | dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n"); |
| 1222 | } |
| 1223 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1224 | valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1227 | if (val == 1 && !(hsotg->hw_params.i2c_enable)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1228 | valid = 0; |
| 1229 | |
| 1230 | if (!valid) { |
| 1231 | if (val >= 0) |
| 1232 | dev_err(hsotg->dev, |
| 1233 | "%d invalid for i2c_enable. Check HW configuration.\n", |
| 1234 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1235 | val = hsotg->hw_params.i2c_enable; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1236 | dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1237 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1238 | |
| 1239 | hsotg->core_params->i2c_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1242 | void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1243 | { |
| 1244 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1245 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1246 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1247 | if (val >= 0) { |
| 1248 | dev_err(hsotg->dev, |
| 1249 | "Wrong value for en_multiple_tx_fifo,\n"); |
| 1250 | dev_err(hsotg->dev, |
| 1251 | "en_multiple_tx_fifo must be 0 or 1\n"); |
| 1252 | } |
| 1253 | valid = 0; |
| 1254 | } |
| 1255 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1256 | if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1257 | valid = 0; |
| 1258 | |
| 1259 | if (!valid) { |
| 1260 | if (val >= 0) |
| 1261 | dev_err(hsotg->dev, |
| 1262 | "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", |
| 1263 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1264 | val = hsotg->hw_params.en_multiple_tx_fifo; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1265 | dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | hsotg->core_params->en_multiple_tx_fifo = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1271 | void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1272 | { |
| 1273 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1274 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1275 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1276 | if (val >= 0) { |
| 1277 | dev_err(hsotg->dev, |
| 1278 | "'%d' invalid for parameter reload_ctl\n", val); |
| 1279 | dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n"); |
| 1280 | } |
| 1281 | valid = 0; |
| 1282 | } |
| 1283 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1284 | if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1285 | valid = 0; |
| 1286 | |
| 1287 | if (!valid) { |
| 1288 | if (val >= 0) |
| 1289 | dev_err(hsotg->dev, |
| 1290 | "%d invalid for parameter reload_ctl. Check HW configuration.\n", |
| 1291 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1292 | val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1293 | dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | hsotg->core_params->reload_ctl = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1299 | void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1300 | { |
Paul Zimmerman | 4d3190e | 2013-07-16 12:22:12 -0700 | [diff] [blame] | 1301 | if (val != -1) |
| 1302 | hsotg->core_params->ahbcfg = val; |
| 1303 | else |
Matthijs Kooijman | f923463 | 2013-08-30 18:45:13 +0200 | [diff] [blame] | 1304 | hsotg->core_params->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << |
Luis Ortega Perez de Villar | 0464a3d | 2013-09-25 13:10:50 +0200 | [diff] [blame] | 1305 | GAHBCFG_HBSTLEN_SHIFT; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 1308 | void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1309 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 1310 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1311 | if (val >= 0) { |
| 1312 | dev_err(hsotg->dev, |
| 1313 | "'%d' invalid for parameter otg_ver\n", val); |
| 1314 | dev_err(hsotg->dev, |
| 1315 | "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n"); |
| 1316 | } |
| 1317 | val = 0; |
| 1318 | dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | hsotg->core_params->otg_ver = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Wei Yongjun | 49cf10c | 2013-11-28 10:27:59 +0800 | [diff] [blame] | 1324 | static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 1325 | { |
| 1326 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 1327 | if (val >= 0) { |
| 1328 | dev_err(hsotg->dev, |
| 1329 | "'%d' invalid for parameter uframe_sched\n", |
| 1330 | val); |
| 1331 | dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n"); |
| 1332 | } |
| 1333 | val = 1; |
| 1334 | dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val); |
| 1335 | } |
| 1336 | |
| 1337 | hsotg->core_params->uframe_sched = val; |
| 1338 | } |
| 1339 | |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 1340 | static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg, |
| 1341 | int val) |
| 1342 | { |
| 1343 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 1344 | if (val >= 0) { |
| 1345 | dev_err(hsotg->dev, |
| 1346 | "'%d' invalid for parameter external_id_pin_ctl\n", |
| 1347 | val); |
| 1348 | dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n"); |
| 1349 | } |
| 1350 | val = 0; |
| 1351 | dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val); |
| 1352 | } |
| 1353 | |
| 1354 | hsotg->core_params->external_id_pin_ctl = val; |
| 1355 | } |
| 1356 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 1357 | static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg, |
| 1358 | int val) |
| 1359 | { |
| 1360 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 1361 | if (val >= 0) { |
| 1362 | dev_err(hsotg->dev, |
| 1363 | "'%d' invalid for parameter hibernation\n", |
| 1364 | val); |
| 1365 | dev_err(hsotg->dev, "hibernation must be 0 or 1\n"); |
| 1366 | } |
| 1367 | val = 0; |
| 1368 | dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val); |
| 1369 | } |
| 1370 | |
| 1371 | hsotg->core_params->hibernation = val; |
| 1372 | } |
| 1373 | |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 1374 | /* |
| 1375 | * This function is called during module intialization to pass module parameters |
| 1376 | * for the DWC_otg core. |
| 1377 | */ |
| 1378 | void dwc2_set_parameters(struct dwc2_hsotg *hsotg, |
| 1379 | const struct dwc2_core_params *params) |
| 1380 | { |
| 1381 | dev_dbg(hsotg->dev, "%s()\n", __func__); |
| 1382 | |
| 1383 | dwc2_set_param_otg_cap(hsotg, params->otg_cap); |
| 1384 | dwc2_set_param_dma_enable(hsotg, params->dma_enable); |
| 1385 | dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); |
Mian Yousaf Kaukab | fbb9e22 | 2015-11-20 11:49:28 +0100 | [diff] [blame] | 1386 | dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 1387 | dwc2_set_param_host_support_fs_ls_low_power(hsotg, |
| 1388 | params->host_support_fs_ls_low_power); |
| 1389 | dwc2_set_param_enable_dynamic_fifo(hsotg, |
| 1390 | params->enable_dynamic_fifo); |
| 1391 | dwc2_set_param_host_rx_fifo_size(hsotg, |
| 1392 | params->host_rx_fifo_size); |
| 1393 | dwc2_set_param_host_nperio_tx_fifo_size(hsotg, |
| 1394 | params->host_nperio_tx_fifo_size); |
| 1395 | dwc2_set_param_host_perio_tx_fifo_size(hsotg, |
| 1396 | params->host_perio_tx_fifo_size); |
| 1397 | dwc2_set_param_max_transfer_size(hsotg, |
| 1398 | params->max_transfer_size); |
| 1399 | dwc2_set_param_max_packet_count(hsotg, |
| 1400 | params->max_packet_count); |
| 1401 | dwc2_set_param_host_channels(hsotg, params->host_channels); |
| 1402 | dwc2_set_param_phy_type(hsotg, params->phy_type); |
| 1403 | dwc2_set_param_speed(hsotg, params->speed); |
| 1404 | dwc2_set_param_host_ls_low_power_phy_clk(hsotg, |
| 1405 | params->host_ls_low_power_phy_clk); |
| 1406 | dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr); |
| 1407 | dwc2_set_param_phy_ulpi_ext_vbus(hsotg, |
| 1408 | params->phy_ulpi_ext_vbus); |
| 1409 | dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width); |
| 1410 | dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls); |
| 1411 | dwc2_set_param_ts_dline(hsotg, params->ts_dline); |
| 1412 | dwc2_set_param_i2c_enable(hsotg, params->i2c_enable); |
| 1413 | dwc2_set_param_en_multiple_tx_fifo(hsotg, |
| 1414 | params->en_multiple_tx_fifo); |
| 1415 | dwc2_set_param_reload_ctl(hsotg, params->reload_ctl); |
| 1416 | dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); |
| 1417 | dwc2_set_param_otg_ver(hsotg, params->otg_ver); |
| 1418 | dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 1419 | dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl); |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 1420 | dwc2_set_param_hibernation(hsotg, params->hibernation); |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 1421 | } |
| 1422 | |
John Youn | 09c9698 | 2015-12-17 11:17:12 -0800 | [diff] [blame] | 1423 | /* |
| 1424 | * Forces either host or device mode if the controller is not |
| 1425 | * currently in that mode. |
| 1426 | * |
| 1427 | * Returns true if the mode was forced. |
| 1428 | */ |
| 1429 | static bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host) |
| 1430 | { |
| 1431 | if (host && dwc2_is_host_mode(hsotg)) |
| 1432 | return false; |
| 1433 | else if (!host && dwc2_is_device_mode(hsotg)) |
| 1434 | return false; |
| 1435 | |
| 1436 | return dwc2_force_mode(hsotg, host); |
| 1437 | } |
| 1438 | |
John Youn | 55e1040 | 2015-12-17 11:17:31 -0800 | [diff] [blame] | 1439 | /* |
| 1440 | * Gets host hardware parameters. Forces host mode if not currently in |
| 1441 | * host mode. Should be called immediately after a core soft reset in |
| 1442 | * order to get the reset values. |
| 1443 | */ |
| 1444 | static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) |
| 1445 | { |
| 1446 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 1447 | u32 gnptxfsiz; |
| 1448 | u32 hptxfsiz; |
| 1449 | bool forced; |
| 1450 | |
| 1451 | if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) |
| 1452 | return; |
| 1453 | |
| 1454 | forced = dwc2_force_mode_if_needed(hsotg, true); |
| 1455 | |
| 1456 | gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 1457 | hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); |
| 1458 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); |
| 1459 | dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); |
| 1460 | |
| 1461 | if (forced) |
| 1462 | dwc2_clear_force_mode(hsotg); |
| 1463 | |
| 1464 | hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 1465 | FIFOSIZE_DEPTH_SHIFT; |
| 1466 | hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 1467 | FIFOSIZE_DEPTH_SHIFT; |
| 1468 | } |
| 1469 | |
| 1470 | /* |
| 1471 | * Gets device hardware parameters. Forces device mode if not |
| 1472 | * currently in device mode. Should be called immediately after a core |
| 1473 | * soft reset in order to get the reset values. |
| 1474 | */ |
| 1475 | static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) |
| 1476 | { |
| 1477 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 1478 | bool forced; |
| 1479 | u32 gnptxfsiz; |
| 1480 | |
| 1481 | if (hsotg->dr_mode == USB_DR_MODE_HOST) |
| 1482 | return; |
| 1483 | |
| 1484 | forced = dwc2_force_mode_if_needed(hsotg, false); |
| 1485 | |
| 1486 | gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 1487 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); |
| 1488 | |
| 1489 | if (forced) |
| 1490 | dwc2_clear_force_mode(hsotg); |
| 1491 | |
| 1492 | hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 1493 | FIFOSIZE_DEPTH_SHIFT; |
| 1494 | } |
| 1495 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1496 | /** |
| 1497 | * During device initialization, read various hardware configuration |
| 1498 | * registers and interpret the contents. |
| 1499 | */ |
| 1500 | int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) |
| 1501 | { |
| 1502 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 1503 | unsigned width; |
| 1504 | u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; |
John Youn | 55e1040 | 2015-12-17 11:17:31 -0800 | [diff] [blame] | 1505 | u32 grxfsiz; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1506 | |
| 1507 | /* |
| 1508 | * Attempt to ensure this device is really a DWC_otg Controller. |
| 1509 | * Read and verify the GSNPSID register contents. The value should be |
| 1510 | * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", |
| 1511 | * as in "OTG version 2.xx" or "OTG version 3.xx". |
| 1512 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1513 | hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1514 | if ((hw->snpsid & 0xfffff000) != 0x4f542000 && |
| 1515 | (hw->snpsid & 0xfffff000) != 0x4f543000) { |
| 1516 | dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", |
| 1517 | hw->snpsid); |
| 1518 | return -ENODEV; |
| 1519 | } |
| 1520 | |
| 1521 | dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", |
| 1522 | hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, |
| 1523 | hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); |
| 1524 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1525 | hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); |
| 1526 | hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); |
| 1527 | hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); |
| 1528 | hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); |
| 1529 | grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1530 | |
| 1531 | dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); |
| 1532 | dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); |
| 1533 | dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); |
| 1534 | dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1535 | dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); |
| 1536 | |
John Youn | 55e1040 | 2015-12-17 11:17:31 -0800 | [diff] [blame] | 1537 | /* |
| 1538 | * Host specific hardware parameters. Reading these parameters |
| 1539 | * requires the controller to be in host mode. The mode will |
| 1540 | * be forced, if necessary, to read these values. |
| 1541 | */ |
| 1542 | dwc2_get_host_hwparams(hsotg); |
| 1543 | dwc2_get_dev_hwparams(hsotg); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1544 | |
John Youn | 55e1040 | 2015-12-17 11:17:31 -0800 | [diff] [blame] | 1545 | /* hwcfg1 */ |
| 1546 | hw->dev_ep_dirs = hwcfg1; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1547 | |
| 1548 | /* hwcfg2 */ |
| 1549 | hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> |
| 1550 | GHWCFG2_OP_MODE_SHIFT; |
| 1551 | hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> |
| 1552 | GHWCFG2_ARCHITECTURE_SHIFT; |
| 1553 | hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); |
| 1554 | hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> |
| 1555 | GHWCFG2_NUM_HOST_CHAN_SHIFT); |
| 1556 | hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> |
| 1557 | GHWCFG2_HS_PHY_TYPE_SHIFT; |
| 1558 | hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> |
| 1559 | GHWCFG2_FS_PHY_TYPE_SHIFT; |
| 1560 | hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> |
| 1561 | GHWCFG2_NUM_DEV_EP_SHIFT; |
| 1562 | hw->nperio_tx_q_depth = |
| 1563 | (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> |
| 1564 | GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; |
| 1565 | hw->host_perio_tx_q_depth = |
| 1566 | (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> |
| 1567 | GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; |
| 1568 | hw->dev_token_q_depth = |
| 1569 | (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> |
| 1570 | GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; |
| 1571 | |
| 1572 | /* hwcfg3 */ |
| 1573 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> |
| 1574 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; |
| 1575 | hw->max_transfer_size = (1 << (width + 11)) - 1; |
| 1576 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> |
| 1577 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; |
| 1578 | hw->max_packet_count = (1 << (width + 4)) - 1; |
| 1579 | hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); |
| 1580 | hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> |
| 1581 | GHWCFG3_DFIFO_DEPTH_SHIFT; |
| 1582 | |
| 1583 | /* hwcfg4 */ |
| 1584 | hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); |
| 1585 | hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> |
| 1586 | GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; |
| 1587 | hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); |
| 1588 | hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1589 | hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> |
| 1590 | GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1591 | |
| 1592 | /* fifo sizes */ |
| 1593 | hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> |
| 1594 | GRXFSIZ_DEPTH_SHIFT; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1595 | |
| 1596 | dev_dbg(hsotg->dev, "Detected values from hardware:\n"); |
| 1597 | dev_dbg(hsotg->dev, " op_mode=%d\n", |
| 1598 | hw->op_mode); |
| 1599 | dev_dbg(hsotg->dev, " arch=%d\n", |
| 1600 | hw->arch); |
| 1601 | dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", |
| 1602 | hw->dma_desc_enable); |
| 1603 | dev_dbg(hsotg->dev, " power_optimized=%d\n", |
| 1604 | hw->power_optimized); |
| 1605 | dev_dbg(hsotg->dev, " i2c_enable=%d\n", |
| 1606 | hw->i2c_enable); |
| 1607 | dev_dbg(hsotg->dev, " hs_phy_type=%d\n", |
| 1608 | hw->hs_phy_type); |
| 1609 | dev_dbg(hsotg->dev, " fs_phy_type=%d\n", |
| 1610 | hw->fs_phy_type); |
Masanari Iida | 971bd8f | 2015-05-20 23:54:02 +0900 | [diff] [blame] | 1611 | dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n", |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 1612 | hw->utmi_phy_data_width); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1613 | dev_dbg(hsotg->dev, " num_dev_ep=%d\n", |
| 1614 | hw->num_dev_ep); |
| 1615 | dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", |
| 1616 | hw->num_dev_perio_in_ep); |
| 1617 | dev_dbg(hsotg->dev, " host_channels=%d\n", |
| 1618 | hw->host_channels); |
| 1619 | dev_dbg(hsotg->dev, " max_transfer_size=%d\n", |
| 1620 | hw->max_transfer_size); |
| 1621 | dev_dbg(hsotg->dev, " max_packet_count=%d\n", |
| 1622 | hw->max_packet_count); |
| 1623 | dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", |
| 1624 | hw->nperio_tx_q_depth); |
| 1625 | dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", |
| 1626 | hw->host_perio_tx_q_depth); |
| 1627 | dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", |
| 1628 | hw->dev_token_q_depth); |
| 1629 | dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", |
| 1630 | hw->enable_dynamic_fifo); |
| 1631 | dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", |
| 1632 | hw->en_multiple_tx_fifo); |
| 1633 | dev_dbg(hsotg->dev, " total_fifo_size=%d\n", |
| 1634 | hw->total_fifo_size); |
| 1635 | dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n", |
| 1636 | hw->host_rx_fifo_size); |
| 1637 | dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", |
| 1638 | hw->host_nperio_tx_fifo_size); |
| 1639 | dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", |
| 1640 | hw->host_perio_tx_fifo_size); |
| 1641 | dev_dbg(hsotg->dev, "\n"); |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
Mian Yousaf Kaukab | ecb176c | 2015-04-29 22:09:05 +0200 | [diff] [blame] | 1645 | |
| 1646 | /* |
| 1647 | * Sets all parameters to the given value. |
| 1648 | * |
| 1649 | * Assumes that the dwc2_core_params struct contains only integers. |
| 1650 | */ |
| 1651 | void dwc2_set_all_params(struct dwc2_core_params *params, int value) |
| 1652 | { |
| 1653 | int *p = (int *)params; |
| 1654 | size_t size = sizeof(*params) / sizeof(*p); |
| 1655 | int i; |
| 1656 | |
| 1657 | for (i = 0; i < size; i++) |
| 1658 | p[i] = value; |
| 1659 | } |
Mian Yousaf Kaukab | ecb176c | 2015-04-29 22:09:05 +0200 | [diff] [blame] | 1660 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1661 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1662 | u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg) |
| 1663 | { |
Paul Zimmerman | b66a3f0 | 2013-11-22 16:43:50 -0800 | [diff] [blame] | 1664 | return hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 1667 | bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1668 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1669 | if (dwc2_readl(hsotg->regs + GSNPSID) == 0xffffffff) |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 1670 | return false; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1671 | else |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 1672 | return true; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * dwc2_enable_global_interrupts() - Enables the controller's Global |
| 1677 | * Interrupt in the AHB Config register |
| 1678 | * |
| 1679 | * @hsotg: Programming view of DWC_otg controller |
| 1680 | */ |
| 1681 | void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg) |
| 1682 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1683 | u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1684 | |
| 1685 | ahbcfg |= GAHBCFG_GLBL_INTR_EN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1686 | dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | /** |
| 1690 | * dwc2_disable_global_interrupts() - Disables the controller's Global |
| 1691 | * Interrupt in the AHB Config register |
| 1692 | * |
| 1693 | * @hsotg: Programming view of DWC_otg controller |
| 1694 | */ |
| 1695 | void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg) |
| 1696 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1697 | u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1698 | |
| 1699 | ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1700 | dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
John Youn | 6bea962 | 2015-12-17 11:16:17 -0800 | [diff] [blame] | 1703 | /* Returns the controller's GHWCFG2.OTG_MODE. */ |
| 1704 | unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg) |
| 1705 | { |
| 1706 | u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); |
| 1707 | |
| 1708 | return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >> |
| 1709 | GHWCFG2_OP_MODE_SHIFT; |
| 1710 | } |
| 1711 | |
| 1712 | /* Returns true if the controller is capable of DRD. */ |
| 1713 | bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg) |
| 1714 | { |
| 1715 | unsigned op_mode = dwc2_op_mode(hsotg); |
| 1716 | |
| 1717 | return (op_mode == GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) || |
| 1718 | (op_mode == GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE) || |
| 1719 | (op_mode == GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE); |
| 1720 | } |
| 1721 | |
| 1722 | /* Returns true if the controller is host-only. */ |
| 1723 | bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg) |
| 1724 | { |
| 1725 | unsigned op_mode = dwc2_op_mode(hsotg); |
| 1726 | |
| 1727 | return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) || |
| 1728 | (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST); |
| 1729 | } |
| 1730 | |
| 1731 | /* Returns true if the controller is device-only. */ |
| 1732 | bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg) |
| 1733 | { |
| 1734 | unsigned op_mode = dwc2_op_mode(hsotg); |
| 1735 | |
| 1736 | return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) || |
| 1737 | (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE); |
| 1738 | } |
| 1739 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1740 | MODULE_DESCRIPTION("DESIGNWARE HS OTG Core"); |
| 1741 | MODULE_AUTHOR("Synopsys, Inc."); |
| 1742 | MODULE_LICENSE("Dual BSD/GPL"); |