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 | #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) |
| 60 | /** |
| 61 | * dwc2_backup_host_registers() - Backup controller host registers. |
| 62 | * When suspending usb bus, registers needs to be backuped |
| 63 | * if controller power is disabled once suspended. |
| 64 | * |
| 65 | * @hsotg: Programming view of the DWC_otg controller |
| 66 | */ |
| 67 | static int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) |
| 68 | { |
| 69 | struct dwc2_hregs_backup *hr; |
| 70 | int i; |
| 71 | |
| 72 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 73 | |
| 74 | /* Backup Host regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 75 | hr = &hsotg->hr_backup; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 76 | hr->hcfg = dwc2_readl(hsotg->regs + HCFG); |
| 77 | hr->haintmsk = dwc2_readl(hsotg->regs + HAINTMSK); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 78 | for (i = 0; i < hsotg->core_params->host_channels; ++i) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 79 | hr->hcintmsk[i] = dwc2_readl(hsotg->regs + HCINTMSK(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 80 | |
Gregory Herrero | cc047ce | 2015-09-22 15:16:37 +0200 | [diff] [blame] | 81 | hr->hprt0 = dwc2_read_hprt0(hsotg); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 82 | hr->hfir = dwc2_readl(hsotg->regs + HFIR); |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 83 | hr->valid = true; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * dwc2_restore_host_registers() - Restore controller host registers. |
| 90 | * When resuming usb bus, device registers needs to be restored |
| 91 | * if controller power were disabled. |
| 92 | * |
| 93 | * @hsotg: Programming view of the DWC_otg controller |
| 94 | */ |
| 95 | static int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) |
| 96 | { |
| 97 | struct dwc2_hregs_backup *hr; |
| 98 | int i; |
| 99 | |
| 100 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 101 | |
| 102 | /* Restore host regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 103 | hr = &hsotg->hr_backup; |
| 104 | if (!hr->valid) { |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 105 | dev_err(hsotg->dev, "%s: no host registers to restore\n", |
| 106 | __func__); |
| 107 | return -EINVAL; |
| 108 | } |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 109 | hr->valid = false; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 110 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 111 | dwc2_writel(hr->hcfg, hsotg->regs + HCFG); |
| 112 | dwc2_writel(hr->haintmsk, hsotg->regs + HAINTMSK); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 113 | |
| 114 | for (i = 0; i < hsotg->core_params->host_channels; ++i) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 115 | dwc2_writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 116 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 117 | dwc2_writel(hr->hprt0, hsotg->regs + HPRT0); |
| 118 | dwc2_writel(hr->hfir, hsotg->regs + HFIR); |
Gregory Herrero | 08c4ffc | 2015-09-22 15:16:45 +0200 | [diff] [blame] | 119 | hsotg->frame_number = 0; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | #else |
| 124 | static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) |
| 125 | { return 0; } |
| 126 | |
| 127 | static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) |
| 128 | { return 0; } |
| 129 | #endif |
| 130 | |
| 131 | #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ |
| 132 | IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) |
| 133 | /** |
| 134 | * dwc2_backup_device_registers() - Backup controller device registers. |
| 135 | * When suspending usb bus, registers needs to be backuped |
| 136 | * if controller power is disabled once suspended. |
| 137 | * |
| 138 | * @hsotg: Programming view of the DWC_otg controller |
| 139 | */ |
| 140 | static int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) |
| 141 | { |
| 142 | struct dwc2_dregs_backup *dr; |
| 143 | int i; |
| 144 | |
| 145 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 146 | |
| 147 | /* Backup dev regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 148 | dr = &hsotg->dr_backup; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 149 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 150 | dr->dcfg = dwc2_readl(hsotg->regs + DCFG); |
| 151 | dr->dctl = dwc2_readl(hsotg->regs + DCTL); |
| 152 | dr->daintmsk = dwc2_readl(hsotg->regs + DAINTMSK); |
| 153 | dr->diepmsk = dwc2_readl(hsotg->regs + DIEPMSK); |
| 154 | dr->doepmsk = dwc2_readl(hsotg->regs + DOEPMSK); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 155 | |
| 156 | for (i = 0; i < hsotg->num_of_eps; i++) { |
| 157 | /* Backup IN EPs */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 158 | dr->diepctl[i] = dwc2_readl(hsotg->regs + DIEPCTL(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 159 | |
| 160 | /* Ensure DATA PID is correctly configured */ |
| 161 | if (dr->diepctl[i] & DXEPCTL_DPID) |
| 162 | dr->diepctl[i] |= DXEPCTL_SETD1PID; |
| 163 | else |
| 164 | dr->diepctl[i] |= DXEPCTL_SETD0PID; |
| 165 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 166 | dr->dieptsiz[i] = dwc2_readl(hsotg->regs + DIEPTSIZ(i)); |
| 167 | dr->diepdma[i] = dwc2_readl(hsotg->regs + DIEPDMA(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 168 | |
| 169 | /* Backup OUT EPs */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 170 | dr->doepctl[i] = dwc2_readl(hsotg->regs + DOEPCTL(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 171 | |
| 172 | /* Ensure DATA PID is correctly configured */ |
| 173 | if (dr->doepctl[i] & DXEPCTL_DPID) |
| 174 | dr->doepctl[i] |= DXEPCTL_SETD1PID; |
| 175 | else |
| 176 | dr->doepctl[i] |= DXEPCTL_SETD0PID; |
| 177 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 178 | dr->doeptsiz[i] = dwc2_readl(hsotg->regs + DOEPTSIZ(i)); |
| 179 | dr->doepdma[i] = dwc2_readl(hsotg->regs + DOEPDMA(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 180 | } |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 181 | dr->valid = true; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * dwc2_restore_device_registers() - Restore controller device registers. |
| 187 | * When resuming usb bus, device registers needs to be restored |
| 188 | * if controller power were disabled. |
| 189 | * |
| 190 | * @hsotg: Programming view of the DWC_otg controller |
| 191 | */ |
| 192 | static int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg) |
| 193 | { |
| 194 | struct dwc2_dregs_backup *dr; |
| 195 | u32 dctl; |
| 196 | int i; |
| 197 | |
| 198 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 199 | |
| 200 | /* Restore dev regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 201 | dr = &hsotg->dr_backup; |
| 202 | if (!dr->valid) { |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 203 | dev_err(hsotg->dev, "%s: no device registers to restore\n", |
| 204 | __func__); |
| 205 | return -EINVAL; |
| 206 | } |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 207 | dr->valid = false; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 208 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 209 | dwc2_writel(dr->dcfg, hsotg->regs + DCFG); |
| 210 | dwc2_writel(dr->dctl, hsotg->regs + DCTL); |
| 211 | dwc2_writel(dr->daintmsk, hsotg->regs + DAINTMSK); |
| 212 | dwc2_writel(dr->diepmsk, hsotg->regs + DIEPMSK); |
| 213 | dwc2_writel(dr->doepmsk, hsotg->regs + DOEPMSK); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 214 | |
| 215 | for (i = 0; i < hsotg->num_of_eps; i++) { |
| 216 | /* Restore IN EPs */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 217 | dwc2_writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i)); |
| 218 | dwc2_writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i)); |
| 219 | dwc2_writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 220 | |
| 221 | /* Restore OUT EPs */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 222 | dwc2_writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i)); |
| 223 | dwc2_writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i)); |
| 224 | dwc2_writel(dr->doepdma[i], hsotg->regs + DOEPDMA(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* Set the Power-On Programming done bit */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 228 | dctl = dwc2_readl(hsotg->regs + DCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 229 | dctl |= DCTL_PWRONPRGDONE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 230 | dwc2_writel(dctl, hsotg->regs + DCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | #else |
| 235 | static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg) |
| 236 | { return 0; } |
| 237 | |
| 238 | static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg) |
| 239 | { return 0; } |
| 240 | #endif |
| 241 | |
| 242 | /** |
| 243 | * dwc2_backup_global_registers() - Backup global controller registers. |
| 244 | * When suspending usb bus, registers needs to be backuped |
| 245 | * if controller power is disabled once suspended. |
| 246 | * |
| 247 | * @hsotg: Programming view of the DWC_otg controller |
| 248 | */ |
| 249 | static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg) |
| 250 | { |
| 251 | struct dwc2_gregs_backup *gr; |
| 252 | int i; |
| 253 | |
| 254 | /* Backup global regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 255 | gr = &hsotg->gr_backup; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 256 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 257 | gr->gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
| 258 | gr->gintmsk = dwc2_readl(hsotg->regs + GINTMSK); |
| 259 | gr->gahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
| 260 | gr->gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 261 | gr->grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
| 262 | gr->gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 263 | gr->hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); |
| 264 | gr->gdfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 265 | for (i = 0; i < MAX_EPS_CHANNELS; i++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 266 | gr->dtxfsiz[i] = dwc2_readl(hsotg->regs + DPTXFSIZN(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 267 | |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 268 | gr->valid = true; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * dwc2_restore_global_registers() - Restore controller global registers. |
| 274 | * When resuming usb bus, device registers needs to be restored |
| 275 | * if controller power were disabled. |
| 276 | * |
| 277 | * @hsotg: Programming view of the DWC_otg controller |
| 278 | */ |
| 279 | static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg) |
| 280 | { |
| 281 | struct dwc2_gregs_backup *gr; |
| 282 | int i; |
| 283 | |
| 284 | dev_dbg(hsotg->dev, "%s\n", __func__); |
| 285 | |
| 286 | /* Restore global regs */ |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 287 | gr = &hsotg->gr_backup; |
| 288 | if (!gr->valid) { |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 289 | dev_err(hsotg->dev, "%s: no global registers to restore\n", |
| 290 | __func__); |
| 291 | return -EINVAL; |
| 292 | } |
Mian Yousaf Kaukab | cc1e204 | 2015-06-29 11:05:30 +0200 | [diff] [blame] | 293 | gr->valid = false; |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 294 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 295 | dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); |
| 296 | dwc2_writel(gr->gotgctl, hsotg->regs + GOTGCTL); |
| 297 | dwc2_writel(gr->gintmsk, hsotg->regs + GINTMSK); |
| 298 | dwc2_writel(gr->gusbcfg, hsotg->regs + GUSBCFG); |
| 299 | dwc2_writel(gr->gahbcfg, hsotg->regs + GAHBCFG); |
| 300 | dwc2_writel(gr->grxfsiz, hsotg->regs + GRXFSIZ); |
| 301 | dwc2_writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ); |
| 302 | dwc2_writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ); |
| 303 | dwc2_writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 304 | for (i = 0; i < MAX_EPS_CHANNELS; i++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 305 | dwc2_writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i)); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * dwc2_exit_hibernation() - Exit controller from Partial Power Down. |
| 312 | * |
| 313 | * @hsotg: Programming view of the DWC_otg controller |
| 314 | * @restore: Controller registers need to be restored |
| 315 | */ |
| 316 | int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore) |
| 317 | { |
| 318 | u32 pcgcctl; |
| 319 | int ret = 0; |
| 320 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 321 | if (!hsotg->core_params->hibernation) |
| 322 | return -ENOTSUPP; |
| 323 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 324 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 325 | pcgcctl &= ~PCGCTL_STOPPCLK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 326 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 327 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 328 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 329 | pcgcctl &= ~PCGCTL_PWRCLMP; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 330 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 331 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 332 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 333 | pcgcctl &= ~PCGCTL_RSTPDWNMODULE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 334 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 335 | |
| 336 | udelay(100); |
| 337 | if (restore) { |
| 338 | ret = dwc2_restore_global_registers(hsotg); |
| 339 | if (ret) { |
| 340 | dev_err(hsotg->dev, "%s: failed to restore registers\n", |
| 341 | __func__); |
| 342 | return ret; |
| 343 | } |
| 344 | if (dwc2_is_host_mode(hsotg)) { |
| 345 | ret = dwc2_restore_host_registers(hsotg); |
| 346 | if (ret) { |
| 347 | dev_err(hsotg->dev, "%s: failed to restore host registers\n", |
| 348 | __func__); |
| 349 | return ret; |
| 350 | } |
| 351 | } else { |
| 352 | ret = dwc2_restore_device_registers(hsotg); |
| 353 | if (ret) { |
| 354 | dev_err(hsotg->dev, "%s: failed to restore device registers\n", |
| 355 | __func__); |
| 356 | return ret; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * dwc2_enter_hibernation() - Put controller in Partial Power Down. |
| 366 | * |
| 367 | * @hsotg: Programming view of the DWC_otg controller |
| 368 | */ |
| 369 | int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg) |
| 370 | { |
| 371 | u32 pcgcctl; |
| 372 | int ret = 0; |
| 373 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 374 | if (!hsotg->core_params->hibernation) |
| 375 | return -ENOTSUPP; |
| 376 | |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 377 | /* Backup all registers */ |
| 378 | ret = dwc2_backup_global_registers(hsotg); |
| 379 | if (ret) { |
| 380 | dev_err(hsotg->dev, "%s: failed to backup global registers\n", |
| 381 | __func__); |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | if (dwc2_is_host_mode(hsotg)) { |
| 386 | ret = dwc2_backup_host_registers(hsotg); |
| 387 | if (ret) { |
| 388 | dev_err(hsotg->dev, "%s: failed to backup host registers\n", |
| 389 | __func__); |
| 390 | return ret; |
| 391 | } |
| 392 | } else { |
| 393 | ret = dwc2_backup_device_registers(hsotg); |
| 394 | if (ret) { |
| 395 | dev_err(hsotg->dev, "%s: failed to backup device registers\n", |
| 396 | __func__); |
| 397 | return ret; |
| 398 | } |
| 399 | } |
| 400 | |
Gregory Herrero | cad73da | 2015-09-22 15:16:49 +0200 | [diff] [blame] | 401 | /* |
| 402 | * Clear any pending interrupts since dwc2 will not be able to |
| 403 | * clear them after entering hibernation. |
| 404 | */ |
| 405 | dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); |
| 406 | |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 407 | /* Put the controller in low power state */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 408 | pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 409 | |
| 410 | pcgcctl |= PCGCTL_PWRCLMP; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 411 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 412 | ndelay(20); |
| 413 | |
| 414 | pcgcctl |= PCGCTL_RSTPDWNMODULE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 415 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 416 | ndelay(20); |
| 417 | |
| 418 | pcgcctl |= PCGCTL_STOPPCLK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 419 | dwc2_writel(pcgcctl, hsotg->regs + PCGCTL); |
Gregory Herrero | d17ee77 | 2015-04-29 22:09:01 +0200 | [diff] [blame] | 420 | |
| 421 | return ret; |
| 422 | } |
| 423 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 424 | /** |
| 425 | * dwc2_enable_common_interrupts() - Initializes the commmon interrupts, |
| 426 | * used in both device and host modes |
| 427 | * |
| 428 | * @hsotg: Programming view of the DWC_otg controller |
| 429 | */ |
| 430 | static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg) |
| 431 | { |
| 432 | u32 intmsk; |
| 433 | |
| 434 | /* Clear any pending OTG Interrupts */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 435 | dwc2_writel(0xffffffff, hsotg->regs + GOTGINT); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 436 | |
| 437 | /* Clear any pending interrupts */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 438 | dwc2_writel(0xffffffff, hsotg->regs + GINTSTS); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 439 | |
| 440 | /* Enable the interrupts in the GINTMSK */ |
| 441 | intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT; |
| 442 | |
| 443 | if (hsotg->core_params->dma_enable <= 0) |
| 444 | intmsk |= GINTSTS_RXFLVL; |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 445 | if (hsotg->core_params->external_id_pin_ctl <= 0) |
| 446 | intmsk |= GINTSTS_CONIDSTSCHNG; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 447 | |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 448 | intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 449 | GINTSTS_SESSREQINT; |
| 450 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 451 | dwc2_writel(intmsk, hsotg->regs + GINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /* |
| 455 | * Initializes the FSLSPClkSel field of the HCFG register depending on the |
| 456 | * PHY type |
| 457 | */ |
| 458 | static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg) |
| 459 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 460 | u32 hcfg, val; |
| 461 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 462 | if ((hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && |
| 463 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 464 | hsotg->core_params->ulpi_fs_ls > 0) || |
| 465 | hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { |
| 466 | /* Full speed PHY */ |
| 467 | val = HCFG_FSLSPCLKSEL_48_MHZ; |
| 468 | } else { |
| 469 | /* High speed PHY running at full speed or high speed */ |
| 470 | val = HCFG_FSLSPCLKSEL_30_60_MHZ; |
| 471 | } |
| 472 | |
| 473 | dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 474 | hcfg = dwc2_readl(hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 475 | hcfg &= ~HCFG_FSLSPCLKSEL_MASK; |
Matthijs Kooijman | f923463 | 2013-08-30 18:45:13 +0200 | [diff] [blame] | 476 | hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 477 | dwc2_writel(hcfg, hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Do core a soft reset of the core. Be careful with this because it |
| 482 | * resets all the internal state machines of the core. |
| 483 | */ |
Yunzhi Li | cebfdbf | 2015-12-17 11:14:26 -0800 | [diff] [blame] | 484 | int dwc2_core_reset(struct dwc2_hsotg *hsotg) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 485 | { |
| 486 | u32 greset; |
| 487 | int count = 0; |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 488 | u32 gusbcfg; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 489 | |
| 490 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 491 | |
| 492 | /* Wait for AHB master IDLE state */ |
| 493 | do { |
| 494 | usleep_range(20000, 40000); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 495 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 496 | if (++count > 50) { |
| 497 | dev_warn(hsotg->dev, |
| 498 | "%s() HANG! AHB Idle GRSTCTL=%0x\n", |
| 499 | __func__, greset); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 500 | return -EBUSY; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 501 | } |
| 502 | } while (!(greset & GRSTCTL_AHBIDLE)); |
| 503 | |
| 504 | /* Core Soft Reset */ |
| 505 | count = 0; |
| 506 | greset |= GRSTCTL_CSFTRST; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 507 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 508 | do { |
| 509 | usleep_range(20000, 40000); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 510 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 511 | if (++count > 50) { |
| 512 | dev_warn(hsotg->dev, |
| 513 | "%s() HANG! Soft Reset GRSTCTL=%0x\n", |
| 514 | __func__, greset); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 515 | return -EBUSY; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 516 | } |
| 517 | } while (greset & GRSTCTL_CSFTRST); |
| 518 | |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 519 | if (hsotg->dr_mode == USB_DR_MODE_HOST) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 520 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 521 | gusbcfg &= ~GUSBCFG_FORCEDEVMODE; |
| 522 | gusbcfg |= GUSBCFG_FORCEHOSTMODE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 523 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 524 | } else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 525 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 526 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; |
| 527 | gusbcfg |= GUSBCFG_FORCEDEVMODE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 528 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 529 | } else if (hsotg->dr_mode == USB_DR_MODE_OTG) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 530 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 531 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; |
| 532 | gusbcfg &= ~GUSBCFG_FORCEDEVMODE; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 533 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
Kever Yang | c0155b9 | 2014-08-06 09:01:50 +0800 | [diff] [blame] | 534 | } |
| 535 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 536 | /* |
| 537 | * NOTE: This long sleep is _very_ important, otherwise the core will |
| 538 | * not stay in host mode after a connector ID change! |
| 539 | */ |
| 540 | usleep_range(150000, 200000); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 541 | |
| 542 | return 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 545 | static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 546 | { |
| 547 | u32 usbcfg, i2cctl; |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 548 | int retval = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * core_init() is now called on every switch so only call the |
| 552 | * following for the first time through |
| 553 | */ |
| 554 | if (select_phy) { |
| 555 | dev_dbg(hsotg->dev, "FS PHY selected\n"); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 556 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 557 | usbcfg |= GUSBCFG_PHYSEL; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 558 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 559 | |
| 560 | /* Reset after a PHY select */ |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 561 | retval = dwc2_core_reset(hsotg); |
| 562 | if (retval) { |
| 563 | dev_err(hsotg->dev, "%s() Reset failed, aborting", |
| 564 | __func__); |
| 565 | return retval; |
| 566 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also |
| 571 | * do this on HNP Dev/Host mode switches (done in dev_init and |
| 572 | * host_init). |
| 573 | */ |
| 574 | if (dwc2_is_host_mode(hsotg)) |
| 575 | dwc2_init_fs_ls_pclk_sel(hsotg); |
| 576 | |
| 577 | if (hsotg->core_params->i2c_enable > 0) { |
| 578 | dev_dbg(hsotg->dev, "FS PHY enabling I2C\n"); |
| 579 | |
| 580 | /* Program GUSBCFG.OtgUtmiFsSel to I2C */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 581 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 582 | usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 583 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 584 | |
| 585 | /* Program GI2CCTL.I2CEn */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 586 | i2cctl = dwc2_readl(hsotg->regs + GI2CCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 587 | i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK; |
| 588 | i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT; |
| 589 | i2cctl &= ~GI2CCTL_I2CEN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 590 | dwc2_writel(i2cctl, hsotg->regs + GI2CCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 591 | i2cctl |= GI2CCTL_I2CEN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 592 | dwc2_writel(i2cctl, hsotg->regs + GI2CCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 593 | } |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 594 | |
| 595 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 598 | static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 599 | { |
| 600 | u32 usbcfg; |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 601 | int retval = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 602 | |
| 603 | if (!select_phy) |
Paul Zimmerman | a23666c | 2014-02-04 11:42:15 -0800 | [diff] [blame] | 604 | return 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 605 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 606 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 607 | |
| 608 | /* |
| 609 | * HS PHY parameters. These parameters are preserved during soft reset |
| 610 | * so only program the first time. Do a soft reset immediately after |
| 611 | * setting phyif. |
| 612 | */ |
| 613 | switch (hsotg->core_params->phy_type) { |
| 614 | case DWC2_PHY_TYPE_PARAM_ULPI: |
| 615 | /* ULPI interface */ |
| 616 | dev_dbg(hsotg->dev, "HS ULPI PHY selected\n"); |
| 617 | usbcfg |= GUSBCFG_ULPI_UTMI_SEL; |
| 618 | usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL); |
| 619 | if (hsotg->core_params->phy_ulpi_ddr > 0) |
| 620 | usbcfg |= GUSBCFG_DDRSEL; |
| 621 | break; |
| 622 | case DWC2_PHY_TYPE_PARAM_UTMI: |
| 623 | /* UTMI+ interface */ |
| 624 | dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n"); |
| 625 | usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16); |
| 626 | if (hsotg->core_params->phy_utmi_width == 16) |
| 627 | usbcfg |= GUSBCFG_PHYIF16; |
| 628 | break; |
| 629 | default: |
| 630 | dev_err(hsotg->dev, "FS PHY selected at HS!\n"); |
| 631 | break; |
| 632 | } |
| 633 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 634 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 635 | |
| 636 | /* Reset after setting the PHY parameters */ |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 637 | retval = dwc2_core_reset(hsotg); |
| 638 | if (retval) { |
| 639 | dev_err(hsotg->dev, "%s() Reset failed, aborting", |
| 640 | __func__); |
| 641 | return retval; |
| 642 | } |
| 643 | |
| 644 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 647 | static int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 648 | { |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 649 | u32 usbcfg; |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 650 | int retval = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 651 | |
| 652 | if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL && |
| 653 | hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { |
| 654 | /* If FS mode with FS PHY */ |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 655 | retval = dwc2_fs_phy_init(hsotg, select_phy); |
| 656 | if (retval) |
| 657 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 658 | } else { |
| 659 | /* High speed PHY */ |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 660 | retval = dwc2_hs_phy_init(hsotg, select_phy); |
| 661 | if (retval) |
| 662 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 665 | if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && |
| 666 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 667 | hsotg->core_params->ulpi_fs_ls > 0) { |
| 668 | dev_dbg(hsotg->dev, "Setting ULPI FSLS\n"); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 669 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 670 | usbcfg |= GUSBCFG_ULPI_FS_LS; |
| 671 | usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 672 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 673 | } else { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 674 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 675 | usbcfg &= ~GUSBCFG_ULPI_FS_LS; |
| 676 | usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 677 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 678 | } |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 679 | |
| 680 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) |
| 684 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 685 | u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 686 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 687 | switch (hsotg->hw_params.arch) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 688 | case GHWCFG2_EXT_DMA_ARCH: |
| 689 | dev_err(hsotg->dev, "External DMA Mode not supported\n"); |
| 690 | return -EINVAL; |
| 691 | |
| 692 | case GHWCFG2_INT_DMA_ARCH: |
| 693 | dev_dbg(hsotg->dev, "Internal DMA Mode\n"); |
Paul Zimmerman | 4d3190e | 2013-07-16 12:22:12 -0700 | [diff] [blame] | 694 | if (hsotg->core_params->ahbcfg != -1) { |
| 695 | ahbcfg &= GAHBCFG_CTRL_MASK; |
| 696 | ahbcfg |= hsotg->core_params->ahbcfg & |
| 697 | ~GAHBCFG_CTRL_MASK; |
| 698 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case GHWCFG2_SLAVE_ONLY_ARCH: |
| 702 | default: |
| 703 | dev_dbg(hsotg->dev, "Slave Only Mode\n"); |
| 704 | break; |
| 705 | } |
| 706 | |
| 707 | dev_dbg(hsotg->dev, "dma_enable:%d dma_desc_enable:%d\n", |
| 708 | hsotg->core_params->dma_enable, |
| 709 | hsotg->core_params->dma_desc_enable); |
| 710 | |
| 711 | if (hsotg->core_params->dma_enable > 0) { |
| 712 | if (hsotg->core_params->dma_desc_enable > 0) |
| 713 | dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n"); |
| 714 | else |
| 715 | dev_dbg(hsotg->dev, "Using Buffer DMA mode\n"); |
| 716 | } else { |
| 717 | dev_dbg(hsotg->dev, "Using Slave mode\n"); |
| 718 | hsotg->core_params->dma_desc_enable = 0; |
| 719 | } |
| 720 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 721 | if (hsotg->core_params->dma_enable > 0) |
| 722 | ahbcfg |= GAHBCFG_DMA_EN; |
| 723 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 724 | dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) |
| 730 | { |
| 731 | u32 usbcfg; |
| 732 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 733 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 734 | usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP); |
| 735 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 736 | switch (hsotg->hw_params.op_mode) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 737 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 738 | if (hsotg->core_params->otg_cap == |
| 739 | DWC2_CAP_PARAM_HNP_SRP_CAPABLE) |
| 740 | usbcfg |= GUSBCFG_HNPCAP; |
| 741 | if (hsotg->core_params->otg_cap != |
| 742 | DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) |
| 743 | usbcfg |= GUSBCFG_SRPCAP; |
| 744 | break; |
| 745 | |
| 746 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 747 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 748 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 749 | if (hsotg->core_params->otg_cap != |
| 750 | DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) |
| 751 | usbcfg |= GUSBCFG_SRPCAP; |
| 752 | break; |
| 753 | |
| 754 | case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE: |
| 755 | case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE: |
| 756 | case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST: |
| 757 | default: |
| 758 | break; |
| 759 | } |
| 760 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 761 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** |
| 765 | * dwc2_core_init() - Initializes the DWC_otg controller registers and |
| 766 | * prepares the core for device mode or host mode operation |
| 767 | * |
Douglas Anderson | 0fe239b | 2015-12-17 11:14:40 -0800 | [diff] [blame^] | 768 | * @hsotg: Programming view of the DWC_otg controller |
| 769 | * @initial_setup: If true then this is the first init for this instance. |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 770 | */ |
Douglas Anderson | 0fe239b | 2015-12-17 11:14:40 -0800 | [diff] [blame^] | 771 | int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 772 | { |
| 773 | u32 usbcfg, otgctl; |
| 774 | int retval; |
| 775 | |
| 776 | dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); |
| 777 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 778 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 779 | |
| 780 | /* Set ULPI External VBUS bit if needed */ |
| 781 | usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV; |
| 782 | if (hsotg->core_params->phy_ulpi_ext_vbus == |
| 783 | DWC2_PHY_ULPI_EXTERNAL_VBUS) |
| 784 | usbcfg |= GUSBCFG_ULPI_EXT_VBUS_DRV; |
| 785 | |
| 786 | /* Set external TS Dline pulsing bit if needed */ |
| 787 | usbcfg &= ~GUSBCFG_TERMSELDLPULSE; |
| 788 | if (hsotg->core_params->ts_dline > 0) |
| 789 | usbcfg |= GUSBCFG_TERMSELDLPULSE; |
| 790 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 791 | dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 792 | |
Douglas Anderson | 0fe239b | 2015-12-17 11:14:40 -0800 | [diff] [blame^] | 793 | /* |
| 794 | * Reset the Controller |
| 795 | * |
| 796 | * We only need to reset the controller if this is a re-init. |
| 797 | * For the first init we know for sure that earlier code reset us (it |
| 798 | * needed to in order to properly detect various parameters). |
| 799 | */ |
| 800 | if (!initial_setup) { |
| 801 | retval = dwc2_core_reset(hsotg); |
| 802 | if (retval) { |
| 803 | dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", |
| 804 | __func__); |
| 805 | return retval; |
| 806 | } |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 807 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 808 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 809 | /* |
| 810 | * This needs to happen in FS mode before any other programming occurs |
| 811 | */ |
Douglas Anderson | 0fe239b | 2015-12-17 11:14:40 -0800 | [diff] [blame^] | 812 | retval = dwc2_phy_init(hsotg, initial_setup); |
Julien DELACOU | beb7e59 | 2013-11-20 17:29:49 +0100 | [diff] [blame] | 813 | if (retval) |
| 814 | return retval; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 815 | |
| 816 | /* Program the GAHBCFG Register */ |
| 817 | retval = dwc2_gahbcfg_init(hsotg); |
| 818 | if (retval) |
| 819 | return retval; |
| 820 | |
| 821 | /* Program the GUSBCFG register */ |
| 822 | dwc2_gusbcfg_init(hsotg); |
| 823 | |
| 824 | /* Program the GOTGCTL register */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 825 | otgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 826 | otgctl &= ~GOTGCTL_OTGVER; |
| 827 | if (hsotg->core_params->otg_ver > 0) |
| 828 | otgctl |= GOTGCTL_OTGVER; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 829 | dwc2_writel(otgctl, hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 830 | dev_dbg(hsotg->dev, "OTG VER PARAM: %d\n", hsotg->core_params->otg_ver); |
| 831 | |
| 832 | /* Clear the SRP success bit for FS-I2c */ |
| 833 | hsotg->srp_success = 0; |
| 834 | |
| 835 | /* Enable common interrupts */ |
| 836 | dwc2_enable_common_interrupts(hsotg); |
| 837 | |
| 838 | /* |
Mickael Maison | 997f4f8 | 2014-12-23 17:39:45 +0100 | [diff] [blame] | 839 | * Do device or host initialization based on mode during PCD and |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 840 | * HCD initialization |
| 841 | */ |
| 842 | if (dwc2_is_host_mode(hsotg)) { |
| 843 | dev_dbg(hsotg->dev, "Host Mode\n"); |
| 844 | hsotg->op_state = OTG_STATE_A_HOST; |
| 845 | } else { |
| 846 | dev_dbg(hsotg->dev, "Device Mode\n"); |
| 847 | hsotg->op_state = OTG_STATE_B_PERIPHERAL; |
| 848 | } |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | /** |
| 854 | * dwc2_enable_host_interrupts() - Enables the Host mode interrupts |
| 855 | * |
| 856 | * @hsotg: Programming view of DWC_otg controller |
| 857 | */ |
| 858 | void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg) |
| 859 | { |
| 860 | u32 intmsk; |
| 861 | |
| 862 | dev_dbg(hsotg->dev, "%s()\n", __func__); |
| 863 | |
| 864 | /* Disable all interrupts */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 865 | dwc2_writel(0, hsotg->regs + GINTMSK); |
| 866 | dwc2_writel(0, hsotg->regs + HAINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 867 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 868 | /* Enable the common interrupts */ |
| 869 | dwc2_enable_common_interrupts(hsotg); |
| 870 | |
| 871 | /* Enable host mode interrupts without disturbing common interrupts */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 872 | intmsk = dwc2_readl(hsotg->regs + GINTMSK); |
Mian Yousaf Kaukab | 44e4a60 | 2015-10-12 11:23:27 +0200 | [diff] [blame] | 873 | intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 874 | dwc2_writel(intmsk, hsotg->regs + GINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /** |
| 878 | * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts |
| 879 | * |
| 880 | * @hsotg: Programming view of DWC_otg controller |
| 881 | */ |
| 882 | void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) |
| 883 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 884 | u32 intmsk = dwc2_readl(hsotg->regs + GINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 885 | |
| 886 | /* Disable host mode interrupts without disturbing common interrupts */ |
| 887 | intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT | |
Mian Yousaf Kaukab | 77dbf71 | 2015-09-22 15:16:47 +0200 | [diff] [blame] | 888 | GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP | GINTSTS_DISCONNINT); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 889 | dwc2_writel(intmsk, hsotg->regs + GINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Dinh Nguyen | 112fe8e | 2014-05-07 08:31:29 -0500 | [diff] [blame] | 892 | /* |
| 893 | * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size |
| 894 | * For system that have a total fifo depth that is smaller than the default |
| 895 | * RX + TX fifo size. |
| 896 | * |
| 897 | * @hsotg: Programming view of DWC_otg controller |
| 898 | */ |
| 899 | static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg) |
| 900 | { |
| 901 | struct dwc2_core_params *params = hsotg->core_params; |
| 902 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 903 | u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size; |
| 904 | |
| 905 | total_fifo_size = hw->total_fifo_size; |
| 906 | rxfsiz = params->host_rx_fifo_size; |
| 907 | nptxfsiz = params->host_nperio_tx_fifo_size; |
| 908 | ptxfsiz = params->host_perio_tx_fifo_size; |
| 909 | |
| 910 | /* |
| 911 | * Will use Method 2 defined in the DWC2 spec: minimum FIFO depth |
| 912 | * allocation with support for high bandwidth endpoints. Synopsys |
| 913 | * defines MPS(Max Packet size) for a periodic EP=1024, and for |
| 914 | * non-periodic as 512. |
| 915 | */ |
| 916 | if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) { |
| 917 | /* |
| 918 | * For Buffer DMA mode/Scatter Gather DMA mode |
| 919 | * 2 * ((Largest Packet size / 4) + 1 + 1) + n |
| 920 | * with n = number of host channel. |
| 921 | * 2 * ((1024/4) + 2) = 516 |
| 922 | */ |
| 923 | rxfsiz = 516 + hw->host_channels; |
| 924 | |
| 925 | /* |
| 926 | * min non-periodic tx fifo depth |
| 927 | * 2 * (largest non-periodic USB packet used / 4) |
| 928 | * 2 * (512/4) = 256 |
| 929 | */ |
| 930 | nptxfsiz = 256; |
| 931 | |
| 932 | /* |
| 933 | * min periodic tx fifo depth |
| 934 | * (largest packet size*MC)/4 |
| 935 | * (1024 * 3)/4 = 768 |
| 936 | */ |
| 937 | ptxfsiz = 768; |
| 938 | |
| 939 | params->host_rx_fifo_size = rxfsiz; |
| 940 | params->host_nperio_tx_fifo_size = nptxfsiz; |
| 941 | params->host_perio_tx_fifo_size = ptxfsiz; |
| 942 | } |
| 943 | |
| 944 | /* |
| 945 | * If the summation of RX, NPTX and PTX fifo sizes is still |
| 946 | * bigger than the total_fifo_size, then we have a problem. |
| 947 | * |
| 948 | * We won't be able to allocate as many endpoints. Right now, |
| 949 | * we're just printing an error message, but ideally this FIFO |
| 950 | * allocation algorithm would be improved in the future. |
| 951 | * |
| 952 | * FIXME improve this FIFO allocation algorithm. |
| 953 | */ |
| 954 | if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))) |
| 955 | dev_err(hsotg->dev, "invalid fifo sizes\n"); |
| 956 | } |
| 957 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 958 | static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) |
| 959 | { |
| 960 | struct dwc2_core_params *params = hsotg->core_params; |
Matthijs Kooijman | a1fc524 | 2013-08-30 18:45:20 +0200 | [diff] [blame] | 961 | u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 962 | |
Matthijs Kooijman | 1208605 | 2013-04-29 19:46:35 +0000 | [diff] [blame] | 963 | if (!params->enable_dynamic_fifo) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 964 | return; |
| 965 | |
Dinh Nguyen | 112fe8e | 2014-05-07 08:31:29 -0500 | [diff] [blame] | 966 | dwc2_calculate_dynamic_fifo(hsotg); |
| 967 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 968 | /* Rx FIFO */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 969 | grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
Matthijs Kooijman | a1fc524 | 2013-08-30 18:45:20 +0200 | [diff] [blame] | 970 | dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); |
| 971 | grxfsiz &= ~GRXFSIZ_DEPTH_MASK; |
| 972 | grxfsiz |= params->host_rx_fifo_size << |
| 973 | GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 974 | dwc2_writel(grxfsiz, hsotg->regs + GRXFSIZ); |
| 975 | dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", |
| 976 | dwc2_readl(hsotg->regs + GRXFSIZ)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 977 | |
| 978 | /* Non-periodic Tx FIFO */ |
| 979 | dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 980 | dwc2_readl(hsotg->regs + GNPTXFSIZ)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 981 | nptxfsiz = params->host_nperio_tx_fifo_size << |
| 982 | FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; |
| 983 | nptxfsiz |= params->host_rx_fifo_size << |
| 984 | FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 985 | dwc2_writel(nptxfsiz, hsotg->regs + GNPTXFSIZ); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 986 | dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 987 | dwc2_readl(hsotg->regs + GNPTXFSIZ)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 988 | |
| 989 | /* Periodic Tx FIFO */ |
| 990 | dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 991 | dwc2_readl(hsotg->regs + HPTXFSIZ)); |
Matthijs Kooijman | c35205a | 2013-08-30 18:45:18 +0200 | [diff] [blame] | 992 | hptxfsiz = params->host_perio_tx_fifo_size << |
| 993 | FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; |
| 994 | hptxfsiz |= (params->host_rx_fifo_size + |
| 995 | params->host_nperio_tx_fifo_size) << |
| 996 | FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 997 | dwc2_writel(hptxfsiz, hsotg->regs + HPTXFSIZ); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 998 | dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 999 | dwc2_readl(hsotg->regs + HPTXFSIZ)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1000 | |
| 1001 | if (hsotg->core_params->en_multiple_tx_fifo > 0 && |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1002 | hsotg->hw_params.snpsid <= DWC2_CORE_REV_2_94a) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1003 | /* |
| 1004 | * Global DFIFOCFG calculation for Host mode - |
| 1005 | * include RxFIFO, NPTXFIFO and HPTXFIFO |
| 1006 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1007 | dfifocfg = dwc2_readl(hsotg->regs + GDFIFOCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1008 | dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK; |
Matthijs Kooijman | 08b9f9d | 2013-08-30 18:45:19 +0200 | [diff] [blame] | 1009 | dfifocfg |= (params->host_rx_fifo_size + |
| 1010 | params->host_nperio_tx_fifo_size + |
| 1011 | params->host_perio_tx_fifo_size) << |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1012 | GDFIFOCFG_EPINFOBASE_SHIFT & |
| 1013 | GDFIFOCFG_EPINFOBASE_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1014 | dwc2_writel(dfifocfg, hsotg->regs + GDFIFOCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * dwc2_core_host_init() - Initializes the DWC_otg controller registers for |
| 1020 | * Host mode |
| 1021 | * |
| 1022 | * @hsotg: Programming view of DWC_otg controller |
| 1023 | * |
| 1024 | * This function flushes the Tx and Rx FIFOs and flushes any entries in the |
| 1025 | * request queues. Host channels are reset to ensure that they are ready for |
| 1026 | * performing transfers. |
| 1027 | */ |
| 1028 | void dwc2_core_host_init(struct dwc2_hsotg *hsotg) |
| 1029 | { |
| 1030 | u32 hcfg, hfir, otgctl; |
| 1031 | |
| 1032 | dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); |
| 1033 | |
| 1034 | /* Restart the Phy Clock */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1035 | dwc2_writel(0, hsotg->regs + PCGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1036 | |
| 1037 | /* Initialize Host Configuration Register */ |
| 1038 | dwc2_init_fs_ls_pclk_sel(hsotg); |
| 1039 | if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1040 | hcfg = dwc2_readl(hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1041 | hcfg |= HCFG_FSLSSUPP; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1042 | dwc2_writel(hcfg, hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | /* |
| 1046 | * This bit allows dynamic reloading of the HFIR register during |
Masanari Iida | 0dcde508 | 2013-09-13 23:34:36 +0900 | [diff] [blame] | 1047 | * runtime. This bit needs to be programmed during initial configuration |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1048 | * and its value must not be changed during runtime. |
| 1049 | */ |
| 1050 | if (hsotg->core_params->reload_ctl > 0) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1051 | hfir = dwc2_readl(hsotg->regs + HFIR); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1052 | hfir |= HFIR_RLDCTRL; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1053 | dwc2_writel(hfir, hsotg->regs + HFIR); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | if (hsotg->core_params->dma_desc_enable > 0) { |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 1057 | u32 op_mode = hsotg->hw_params.op_mode; |
| 1058 | if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || |
| 1059 | !hsotg->hw_params.dma_desc_enable || |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1060 | op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE || |
| 1061 | op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE || |
| 1062 | op_mode == GHWCFG2_OP_MODE_UNDEFINED) { |
| 1063 | dev_err(hsotg->dev, |
| 1064 | "Hardware does not support descriptor DMA mode -\n"); |
| 1065 | dev_err(hsotg->dev, |
| 1066 | "falling back to buffer DMA mode.\n"); |
| 1067 | hsotg->core_params->dma_desc_enable = 0; |
| 1068 | } else { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1069 | hcfg = dwc2_readl(hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1070 | hcfg |= HCFG_DESCDMA; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1071 | dwc2_writel(hcfg, hsotg->regs + HCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | /* Configure data FIFO sizes */ |
| 1076 | dwc2_config_fifos(hsotg); |
| 1077 | |
| 1078 | /* TODO - check this */ |
| 1079 | /* Clear Host Set HNP Enable in the OTG Control Register */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1080 | otgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1081 | otgctl &= ~GOTGCTL_HSTSETHNPEN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1082 | dwc2_writel(otgctl, hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1083 | |
| 1084 | /* Make sure the FIFOs are flushed */ |
| 1085 | dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); |
| 1086 | dwc2_flush_rx_fifo(hsotg); |
| 1087 | |
| 1088 | /* Clear Host Set HNP Enable in the OTG Control Register */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1089 | otgctl = dwc2_readl(hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1090 | otgctl &= ~GOTGCTL_HSTSETHNPEN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1091 | dwc2_writel(otgctl, hsotg->regs + GOTGCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1092 | |
| 1093 | if (hsotg->core_params->dma_desc_enable <= 0) { |
| 1094 | int num_channels, i; |
| 1095 | u32 hcchar; |
| 1096 | |
| 1097 | /* Flush out any leftover queued requests */ |
| 1098 | num_channels = hsotg->core_params->host_channels; |
| 1099 | for (i = 0; i < num_channels; i++) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1100 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1101 | hcchar &= ~HCCHAR_CHENA; |
| 1102 | hcchar |= HCCHAR_CHDIS; |
| 1103 | hcchar &= ~HCCHAR_EPDIR; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1104 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /* Halt all channels to put them into a known state */ |
| 1108 | for (i = 0; i < num_channels; i++) { |
| 1109 | int count = 0; |
| 1110 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1111 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1112 | hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS; |
| 1113 | hcchar &= ~HCCHAR_EPDIR; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1114 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(i)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1115 | dev_dbg(hsotg->dev, "%s: Halt channel %d\n", |
| 1116 | __func__, i); |
| 1117 | do { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1118 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(i)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1119 | if (++count > 1000) { |
| 1120 | dev_err(hsotg->dev, |
| 1121 | "Unable to clear enable on channel %d\n", |
| 1122 | i); |
| 1123 | break; |
| 1124 | } |
| 1125 | udelay(1); |
| 1126 | } while (hcchar & HCCHAR_CHENA); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | /* Turn on the vbus power */ |
| 1131 | dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); |
| 1132 | if (hsotg->op_state == OTG_STATE_A_HOST) { |
| 1133 | u32 hprt0 = dwc2_read_hprt0(hsotg); |
| 1134 | |
| 1135 | dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", |
| 1136 | !!(hprt0 & HPRT0_PWR)); |
| 1137 | if (!(hprt0 & HPRT0_PWR)) { |
| 1138 | hprt0 |= HPRT0_PWR; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1139 | dwc2_writel(hprt0, hsotg->regs + HPRT0); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | dwc2_enable_host_interrupts(hsotg); |
| 1144 | } |
| 1145 | |
| 1146 | static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg, |
| 1147 | struct dwc2_host_chan *chan) |
| 1148 | { |
| 1149 | u32 hcintmsk = HCINTMSK_CHHLTD; |
| 1150 | |
| 1151 | switch (chan->ep_type) { |
| 1152 | case USB_ENDPOINT_XFER_CONTROL: |
| 1153 | case USB_ENDPOINT_XFER_BULK: |
| 1154 | dev_vdbg(hsotg->dev, "control/bulk\n"); |
| 1155 | hcintmsk |= HCINTMSK_XFERCOMPL; |
| 1156 | hcintmsk |= HCINTMSK_STALL; |
| 1157 | hcintmsk |= HCINTMSK_XACTERR; |
| 1158 | hcintmsk |= HCINTMSK_DATATGLERR; |
| 1159 | if (chan->ep_is_in) { |
| 1160 | hcintmsk |= HCINTMSK_BBLERR; |
| 1161 | } else { |
| 1162 | hcintmsk |= HCINTMSK_NAK; |
| 1163 | hcintmsk |= HCINTMSK_NYET; |
| 1164 | if (chan->do_ping) |
| 1165 | hcintmsk |= HCINTMSK_ACK; |
| 1166 | } |
| 1167 | |
| 1168 | if (chan->do_split) { |
| 1169 | hcintmsk |= HCINTMSK_NAK; |
| 1170 | if (chan->complete_split) |
| 1171 | hcintmsk |= HCINTMSK_NYET; |
| 1172 | else |
| 1173 | hcintmsk |= HCINTMSK_ACK; |
| 1174 | } |
| 1175 | |
| 1176 | if (chan->error_state) |
| 1177 | hcintmsk |= HCINTMSK_ACK; |
| 1178 | break; |
| 1179 | |
| 1180 | case USB_ENDPOINT_XFER_INT: |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1181 | if (dbg_perio()) |
| 1182 | dev_vdbg(hsotg->dev, "intr\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1183 | hcintmsk |= HCINTMSK_XFERCOMPL; |
| 1184 | hcintmsk |= HCINTMSK_NAK; |
| 1185 | hcintmsk |= HCINTMSK_STALL; |
| 1186 | hcintmsk |= HCINTMSK_XACTERR; |
| 1187 | hcintmsk |= HCINTMSK_DATATGLERR; |
| 1188 | hcintmsk |= HCINTMSK_FRMOVRUN; |
| 1189 | |
| 1190 | if (chan->ep_is_in) |
| 1191 | hcintmsk |= HCINTMSK_BBLERR; |
| 1192 | if (chan->error_state) |
| 1193 | hcintmsk |= HCINTMSK_ACK; |
| 1194 | if (chan->do_split) { |
| 1195 | if (chan->complete_split) |
| 1196 | hcintmsk |= HCINTMSK_NYET; |
| 1197 | else |
| 1198 | hcintmsk |= HCINTMSK_ACK; |
| 1199 | } |
| 1200 | break; |
| 1201 | |
| 1202 | case USB_ENDPOINT_XFER_ISOC: |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1203 | if (dbg_perio()) |
| 1204 | dev_vdbg(hsotg->dev, "isoc\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1205 | hcintmsk |= HCINTMSK_XFERCOMPL; |
| 1206 | hcintmsk |= HCINTMSK_FRMOVRUN; |
| 1207 | hcintmsk |= HCINTMSK_ACK; |
| 1208 | |
| 1209 | if (chan->ep_is_in) { |
| 1210 | hcintmsk |= HCINTMSK_XACTERR; |
| 1211 | hcintmsk |= HCINTMSK_BBLERR; |
| 1212 | } |
| 1213 | break; |
| 1214 | default: |
| 1215 | dev_err(hsotg->dev, "## Unknown EP type ##\n"); |
| 1216 | break; |
| 1217 | } |
| 1218 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1219 | dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1220 | if (dbg_hc(chan)) |
| 1221 | dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg, |
| 1225 | struct dwc2_host_chan *chan) |
| 1226 | { |
| 1227 | u32 hcintmsk = HCINTMSK_CHHLTD; |
| 1228 | |
| 1229 | /* |
| 1230 | * For Descriptor DMA mode core halts the channel on AHB error. |
| 1231 | * Interrupt is not required. |
| 1232 | */ |
| 1233 | if (hsotg->core_params->dma_desc_enable <= 0) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1234 | if (dbg_hc(chan)) |
| 1235 | dev_vdbg(hsotg->dev, "desc DMA disabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1236 | hcintmsk |= HCINTMSK_AHBERR; |
| 1237 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1238 | if (dbg_hc(chan)) |
| 1239 | dev_vdbg(hsotg->dev, "desc DMA enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1240 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) |
| 1241 | hcintmsk |= HCINTMSK_XFERCOMPL; |
| 1242 | } |
| 1243 | |
| 1244 | if (chan->error_state && !chan->do_split && |
| 1245 | chan->ep_type != USB_ENDPOINT_XFER_ISOC) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1246 | if (dbg_hc(chan)) |
| 1247 | dev_vdbg(hsotg->dev, "setting ACK\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1248 | hcintmsk |= HCINTMSK_ACK; |
| 1249 | if (chan->ep_is_in) { |
| 1250 | hcintmsk |= HCINTMSK_DATATGLERR; |
| 1251 | if (chan->ep_type != USB_ENDPOINT_XFER_INT) |
| 1252 | hcintmsk |= HCINTMSK_NAK; |
| 1253 | } |
| 1254 | } |
| 1255 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1256 | dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1257 | if (dbg_hc(chan)) |
| 1258 | dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg, |
| 1262 | struct dwc2_host_chan *chan) |
| 1263 | { |
| 1264 | u32 intmsk; |
| 1265 | |
| 1266 | if (hsotg->core_params->dma_enable > 0) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1267 | if (dbg_hc(chan)) |
| 1268 | dev_vdbg(hsotg->dev, "DMA enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1269 | dwc2_hc_enable_dma_ints(hsotg, chan); |
| 1270 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1271 | if (dbg_hc(chan)) |
| 1272 | dev_vdbg(hsotg->dev, "DMA disabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1273 | dwc2_hc_enable_slave_ints(hsotg, chan); |
| 1274 | } |
| 1275 | |
| 1276 | /* Enable the top level host channel interrupt */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1277 | intmsk = dwc2_readl(hsotg->regs + HAINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1278 | intmsk |= 1 << chan->hc_num; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1279 | dwc2_writel(intmsk, hsotg->regs + HAINTMSK); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1280 | if (dbg_hc(chan)) |
| 1281 | dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1282 | |
| 1283 | /* Make sure host channel interrupts are enabled */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1284 | intmsk = dwc2_readl(hsotg->regs + GINTMSK); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1285 | intmsk |= GINTSTS_HCHINT; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1286 | dwc2_writel(intmsk, hsotg->regs + GINTMSK); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1287 | if (dbg_hc(chan)) |
| 1288 | dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * dwc2_hc_init() - Prepares a host channel for transferring packets to/from |
| 1293 | * a specific endpoint |
| 1294 | * |
| 1295 | * @hsotg: Programming view of DWC_otg controller |
| 1296 | * @chan: Information needed to initialize the host channel |
| 1297 | * |
| 1298 | * The HCCHARn register is set up with the characteristics specified in chan. |
| 1299 | * Host channel interrupts that may need to be serviced while this transfer is |
| 1300 | * in progress are enabled. |
| 1301 | */ |
| 1302 | void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) |
| 1303 | { |
| 1304 | u8 hc_num = chan->hc_num; |
| 1305 | u32 hcintmsk; |
| 1306 | u32 hcchar; |
| 1307 | u32 hcsplt = 0; |
| 1308 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1309 | if (dbg_hc(chan)) |
| 1310 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1311 | |
| 1312 | /* Clear old interrupt conditions for this host channel */ |
| 1313 | hcintmsk = 0xffffffff; |
| 1314 | hcintmsk &= ~HCINTMSK_RESERVED14_31; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1315 | dwc2_writel(hcintmsk, hsotg->regs + HCINT(hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1316 | |
| 1317 | /* Enable channel interrupts required for this transfer */ |
| 1318 | dwc2_hc_enable_ints(hsotg, chan); |
| 1319 | |
| 1320 | /* |
| 1321 | * Program the HCCHARn register with the endpoint characteristics for |
| 1322 | * the current transfer |
| 1323 | */ |
| 1324 | hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK; |
| 1325 | hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK; |
| 1326 | if (chan->ep_is_in) |
| 1327 | hcchar |= HCCHAR_EPDIR; |
| 1328 | if (chan->speed == USB_SPEED_LOW) |
| 1329 | hcchar |= HCCHAR_LSPDDEV; |
| 1330 | hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK; |
| 1331 | hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1332 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1333 | if (dbg_hc(chan)) { |
| 1334 | dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", |
| 1335 | hc_num, hcchar); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1336 | |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1337 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", |
| 1338 | __func__, hc_num); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1339 | dev_vdbg(hsotg->dev, " Dev Addr: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1340 | chan->dev_addr); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1341 | dev_vdbg(hsotg->dev, " Ep Num: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1342 | chan->ep_num); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1343 | dev_vdbg(hsotg->dev, " Is In: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1344 | chan->ep_is_in); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1345 | dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1346 | chan->speed == USB_SPEED_LOW); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1347 | dev_vdbg(hsotg->dev, " Ep Type: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1348 | chan->ep_type); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1349 | dev_vdbg(hsotg->dev, " Max Pkt: %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1350 | chan->max_packet); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1351 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1352 | |
| 1353 | /* Program the HCSPLT register for SPLITs */ |
| 1354 | if (chan->do_split) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1355 | if (dbg_hc(chan)) |
| 1356 | dev_vdbg(hsotg->dev, |
| 1357 | "Programming HC %d with split --> %s\n", |
| 1358 | hc_num, |
| 1359 | chan->complete_split ? "CSPLIT" : "SSPLIT"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1360 | if (chan->complete_split) |
| 1361 | hcsplt |= HCSPLT_COMPSPLT; |
| 1362 | hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT & |
| 1363 | HCSPLT_XACTPOS_MASK; |
| 1364 | hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT & |
| 1365 | HCSPLT_HUBADDR_MASK; |
| 1366 | hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT & |
| 1367 | HCSPLT_PRTADDR_MASK; |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1368 | if (dbg_hc(chan)) { |
| 1369 | dev_vdbg(hsotg->dev, " comp split %d\n", |
| 1370 | chan->complete_split); |
| 1371 | dev_vdbg(hsotg->dev, " xact pos %d\n", |
| 1372 | chan->xact_pos); |
| 1373 | dev_vdbg(hsotg->dev, " hub addr %d\n", |
| 1374 | chan->hub_addr); |
| 1375 | dev_vdbg(hsotg->dev, " hub port %d\n", |
| 1376 | chan->hub_port); |
| 1377 | dev_vdbg(hsotg->dev, " is_in %d\n", |
| 1378 | chan->ep_is_in); |
| 1379 | dev_vdbg(hsotg->dev, " Max Pkt %d\n", |
Matthijs Kooijman | 57bb8ae | 2013-08-30 18:45:17 +0200 | [diff] [blame] | 1380 | chan->max_packet); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1381 | dev_vdbg(hsotg->dev, " xferlen %d\n", |
| 1382 | chan->xfer_len); |
| 1383 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1386 | dwc2_writel(hcsplt, hsotg->regs + HCSPLT(hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /** |
| 1390 | * dwc2_hc_halt() - Attempts to halt a host channel |
| 1391 | * |
| 1392 | * @hsotg: Controller register interface |
| 1393 | * @chan: Host channel to halt |
| 1394 | * @halt_status: Reason for halting the channel |
| 1395 | * |
| 1396 | * This function should only be called in Slave mode or to abort a transfer in |
| 1397 | * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the |
| 1398 | * controller halts the channel when the transfer is complete or a condition |
| 1399 | * occurs that requires application intervention. |
| 1400 | * |
| 1401 | * In slave mode, checks for a free request queue entry, then sets the Channel |
| 1402 | * Enable and Channel Disable bits of the Host Channel Characteristics |
| 1403 | * register of the specified channel to intiate the halt. If there is no free |
| 1404 | * request queue entry, sets only the Channel Disable bit of the HCCHARn |
| 1405 | * register to flush requests for this channel. In the latter case, sets a |
| 1406 | * flag to indicate that the host channel needs to be halted when a request |
| 1407 | * queue slot is open. |
| 1408 | * |
| 1409 | * In DMA mode, always sets the Channel Enable and Channel Disable bits of the |
| 1410 | * HCCHARn register. The controller ensures there is space in the request |
| 1411 | * queue before submitting the halt request. |
| 1412 | * |
| 1413 | * Some time may elapse before the core flushes any posted requests for this |
| 1414 | * host channel and halts. The Channel Halted interrupt handler completes the |
| 1415 | * deactivation of the host channel. |
| 1416 | */ |
| 1417 | void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, |
| 1418 | enum dwc2_halt_status halt_status) |
| 1419 | { |
| 1420 | u32 nptxsts, hptxsts, hcchar; |
| 1421 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1422 | if (dbg_hc(chan)) |
| 1423 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1424 | if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS) |
| 1425 | dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); |
| 1426 | |
| 1427 | if (halt_status == DWC2_HC_XFER_URB_DEQUEUE || |
| 1428 | halt_status == DWC2_HC_XFER_AHB_ERR) { |
| 1429 | /* |
| 1430 | * Disable all channel interrupts except Ch Halted. The QTD |
| 1431 | * and QH state associated with this transfer has been cleared |
| 1432 | * (in the case of URB_DEQUEUE), so the channel needs to be |
| 1433 | * shut down carefully to prevent crashes. |
| 1434 | */ |
| 1435 | u32 hcintmsk = HCINTMSK_CHHLTD; |
| 1436 | |
| 1437 | dev_vdbg(hsotg->dev, "dequeue/error\n"); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1438 | dwc2_writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1439 | |
| 1440 | /* |
| 1441 | * Make sure no other interrupts besides halt are currently |
| 1442 | * pending. Handling another interrupt could cause a crash due |
| 1443 | * to the QTD and QH state. |
| 1444 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1445 | dwc2_writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1446 | |
| 1447 | /* |
| 1448 | * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR |
| 1449 | * even if the channel was already halted for some other |
| 1450 | * reason |
| 1451 | */ |
| 1452 | chan->halt_status = halt_status; |
| 1453 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1454 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1455 | if (!(hcchar & HCCHAR_CHENA)) { |
| 1456 | /* |
| 1457 | * The channel is either already halted or it hasn't |
| 1458 | * started yet. In DMA mode, the transfer may halt if |
| 1459 | * it finishes normally or a condition occurs that |
| 1460 | * requires driver intervention. Don't want to halt |
| 1461 | * the channel again. In either Slave or DMA mode, |
| 1462 | * it's possible that the transfer has been assigned |
| 1463 | * to a channel, but not started yet when an URB is |
| 1464 | * dequeued. Don't want to halt a channel that hasn't |
| 1465 | * started yet. |
| 1466 | */ |
| 1467 | return; |
| 1468 | } |
| 1469 | } |
| 1470 | if (chan->halt_pending) { |
| 1471 | /* |
| 1472 | * A halt has already been issued for this channel. This might |
| 1473 | * happen when a transfer is aborted by a higher level in |
| 1474 | * the stack. |
| 1475 | */ |
| 1476 | dev_vdbg(hsotg->dev, |
| 1477 | "*** %s: Channel %d, chan->halt_pending already set ***\n", |
| 1478 | __func__, chan->hc_num); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1482 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1483 | |
| 1484 | /* No need to set the bit in DDMA for disabling the channel */ |
| 1485 | /* TODO check it everywhere channel is disabled */ |
| 1486 | if (hsotg->core_params->dma_desc_enable <= 0) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1487 | if (dbg_hc(chan)) |
| 1488 | dev_vdbg(hsotg->dev, "desc DMA disabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1489 | hcchar |= HCCHAR_CHENA; |
| 1490 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1491 | if (dbg_hc(chan)) |
| 1492 | dev_dbg(hsotg->dev, "desc DMA enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1493 | } |
| 1494 | hcchar |= HCCHAR_CHDIS; |
| 1495 | |
| 1496 | if (hsotg->core_params->dma_enable <= 0) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1497 | if (dbg_hc(chan)) |
| 1498 | dev_vdbg(hsotg->dev, "DMA not enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1499 | hcchar |= HCCHAR_CHENA; |
| 1500 | |
| 1501 | /* Check for space in the request queue to issue the halt */ |
| 1502 | if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || |
| 1503 | chan->ep_type == USB_ENDPOINT_XFER_BULK) { |
| 1504 | dev_vdbg(hsotg->dev, "control/bulk\n"); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1505 | nptxsts = dwc2_readl(hsotg->regs + GNPTXSTS); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1506 | if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) { |
| 1507 | dev_vdbg(hsotg->dev, "Disabling channel\n"); |
| 1508 | hcchar &= ~HCCHAR_CHENA; |
| 1509 | } |
| 1510 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1511 | if (dbg_perio()) |
| 1512 | dev_vdbg(hsotg->dev, "isoc/intr\n"); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1513 | hptxsts = dwc2_readl(hsotg->regs + HPTXSTS); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1514 | if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 || |
| 1515 | hsotg->queuing_high_bandwidth) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1516 | if (dbg_perio()) |
| 1517 | dev_vdbg(hsotg->dev, "Disabling channel\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1518 | hcchar &= ~HCCHAR_CHENA; |
| 1519 | } |
| 1520 | } |
| 1521 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1522 | if (dbg_hc(chan)) |
| 1523 | dev_vdbg(hsotg->dev, "DMA enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1526 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1527 | chan->halt_status = halt_status; |
| 1528 | |
| 1529 | if (hcchar & HCCHAR_CHENA) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1530 | if (dbg_hc(chan)) |
| 1531 | dev_vdbg(hsotg->dev, "Channel enabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1532 | chan->halt_pending = 1; |
| 1533 | chan->halt_on_queue = 0; |
| 1534 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1535 | if (dbg_hc(chan)) |
| 1536 | dev_vdbg(hsotg->dev, "Channel disabled\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1537 | chan->halt_on_queue = 1; |
| 1538 | } |
| 1539 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1540 | if (dbg_hc(chan)) { |
| 1541 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, |
| 1542 | chan->hc_num); |
| 1543 | dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", |
| 1544 | hcchar); |
| 1545 | dev_vdbg(hsotg->dev, " halt_pending: %d\n", |
| 1546 | chan->halt_pending); |
| 1547 | dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", |
| 1548 | chan->halt_on_queue); |
| 1549 | dev_vdbg(hsotg->dev, " halt_status: %d\n", |
| 1550 | chan->halt_status); |
| 1551 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | /** |
| 1555 | * dwc2_hc_cleanup() - Clears the transfer state for a host channel |
| 1556 | * |
| 1557 | * @hsotg: Programming view of DWC_otg controller |
| 1558 | * @chan: Identifies the host channel to clean up |
| 1559 | * |
| 1560 | * This function is normally called after a transfer is done and the host |
| 1561 | * channel is being released |
| 1562 | */ |
| 1563 | void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) |
| 1564 | { |
| 1565 | u32 hcintmsk; |
| 1566 | |
| 1567 | chan->xfer_started = 0; |
| 1568 | |
| 1569 | /* |
| 1570 | * Clear channel interrupt enables and any unhandled channel interrupt |
| 1571 | * conditions |
| 1572 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1573 | dwc2_writel(0, hsotg->regs + HCINTMSK(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1574 | hcintmsk = 0xffffffff; |
| 1575 | hcintmsk &= ~HCINTMSK_RESERVED14_31; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1576 | dwc2_writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /** |
| 1580 | * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in |
| 1581 | * which frame a periodic transfer should occur |
| 1582 | * |
| 1583 | * @hsotg: Programming view of DWC_otg controller |
| 1584 | * @chan: Identifies the host channel to set up and its properties |
| 1585 | * @hcchar: Current value of the HCCHAR register for the specified host channel |
| 1586 | * |
| 1587 | * This function has no effect on non-periodic transfers |
| 1588 | */ |
| 1589 | static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, |
| 1590 | struct dwc2_host_chan *chan, u32 *hcchar) |
| 1591 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1592 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || |
| 1593 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1594 | /* 1 if _next_ frame is odd, 0 if it's even */ |
Paul Zimmerman | 81a5895 | 2013-06-24 11:34:23 -0700 | [diff] [blame] | 1595 | if (!(dwc2_hcd_get_frame_number(hsotg) & 0x1)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1596 | *hcchar |= HCCHAR_ODDFRM; |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | static void dwc2_set_pid_isoc(struct dwc2_host_chan *chan) |
| 1601 | { |
| 1602 | /* Set up the initial PID for the transfer */ |
| 1603 | if (chan->speed == USB_SPEED_HIGH) { |
| 1604 | if (chan->ep_is_in) { |
| 1605 | if (chan->multi_count == 1) |
| 1606 | chan->data_pid_start = DWC2_HC_PID_DATA0; |
| 1607 | else if (chan->multi_count == 2) |
| 1608 | chan->data_pid_start = DWC2_HC_PID_DATA1; |
| 1609 | else |
| 1610 | chan->data_pid_start = DWC2_HC_PID_DATA2; |
| 1611 | } else { |
| 1612 | if (chan->multi_count == 1) |
| 1613 | chan->data_pid_start = DWC2_HC_PID_DATA0; |
| 1614 | else |
| 1615 | chan->data_pid_start = DWC2_HC_PID_MDATA; |
| 1616 | } |
| 1617 | } else { |
| 1618 | chan->data_pid_start = DWC2_HC_PID_DATA0; |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /** |
| 1623 | * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with |
| 1624 | * the Host Channel |
| 1625 | * |
| 1626 | * @hsotg: Programming view of DWC_otg controller |
| 1627 | * @chan: Information needed to initialize the host channel |
| 1628 | * |
| 1629 | * This function should only be called in Slave mode. For a channel associated |
| 1630 | * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel |
| 1631 | * associated with a periodic EP, the periodic Tx FIFO is written. |
| 1632 | * |
| 1633 | * Upon return the xfer_buf and xfer_count fields in chan are incremented by |
| 1634 | * the number of bytes written to the Tx FIFO. |
| 1635 | */ |
| 1636 | static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, |
| 1637 | struct dwc2_host_chan *chan) |
| 1638 | { |
| 1639 | u32 i; |
| 1640 | u32 remaining_count; |
| 1641 | u32 byte_count; |
| 1642 | u32 dword_count; |
| 1643 | u32 __iomem *data_fifo; |
| 1644 | u32 *data_buf = (u32 *)chan->xfer_buf; |
| 1645 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1646 | if (dbg_hc(chan)) |
| 1647 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1648 | |
| 1649 | data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num)); |
| 1650 | |
| 1651 | remaining_count = chan->xfer_len - chan->xfer_count; |
| 1652 | if (remaining_count > chan->max_packet) |
| 1653 | byte_count = chan->max_packet; |
| 1654 | else |
| 1655 | byte_count = remaining_count; |
| 1656 | |
| 1657 | dword_count = (byte_count + 3) / 4; |
| 1658 | |
| 1659 | if (((unsigned long)data_buf & 0x3) == 0) { |
| 1660 | /* xfer_buf is DWORD aligned */ |
| 1661 | for (i = 0; i < dword_count; i++, data_buf++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1662 | dwc2_writel(*data_buf, data_fifo); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1663 | } else { |
| 1664 | /* xfer_buf is not DWORD aligned */ |
| 1665 | for (i = 0; i < dword_count; i++, data_buf++) { |
| 1666 | u32 data = data_buf[0] | data_buf[1] << 8 | |
| 1667 | data_buf[2] << 16 | data_buf[3] << 24; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1668 | dwc2_writel(data, data_fifo); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | chan->xfer_count += byte_count; |
| 1673 | chan->xfer_buf += byte_count; |
| 1674 | } |
| 1675 | |
| 1676 | /** |
| 1677 | * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host |
| 1678 | * channel and starts the transfer |
| 1679 | * |
| 1680 | * @hsotg: Programming view of DWC_otg controller |
| 1681 | * @chan: Information needed to initialize the host channel. The xfer_len value |
| 1682 | * may be reduced to accommodate the max widths of the XferSize and |
| 1683 | * PktCnt fields in the HCTSIZn register. The multi_count value may be |
| 1684 | * changed to reflect the final xfer_len value. |
| 1685 | * |
| 1686 | * This function may be called in either Slave mode or DMA mode. In Slave mode, |
| 1687 | * the caller must ensure that there is sufficient space in the request queue |
| 1688 | * and Tx Data FIFO. |
| 1689 | * |
| 1690 | * For an OUT transfer in Slave mode, it loads a data packet into the |
| 1691 | * appropriate FIFO. If necessary, additional data packets are loaded in the |
| 1692 | * Host ISR. |
| 1693 | * |
| 1694 | * For an IN transfer in Slave mode, a data packet is requested. The data |
| 1695 | * packets are unloaded from the Rx FIFO in the Host ISR. If necessary, |
| 1696 | * additional data packets are requested in the Host ISR. |
| 1697 | * |
| 1698 | * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ |
| 1699 | * register along with a packet count of 1 and the channel is enabled. This |
| 1700 | * causes a single PING transaction to occur. Other fields in HCTSIZ are |
| 1701 | * simply set to 0 since no data transfer occurs in this case. |
| 1702 | * |
| 1703 | * For a PING transfer in DMA mode, the HCTSIZ register is initialized with |
| 1704 | * all the information required to perform the subsequent data transfer. In |
| 1705 | * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the |
| 1706 | * controller performs the entire PING protocol, then starts the data |
| 1707 | * transfer. |
| 1708 | */ |
| 1709 | void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, |
| 1710 | struct dwc2_host_chan *chan) |
| 1711 | { |
| 1712 | u32 max_hc_xfer_size = hsotg->core_params->max_transfer_size; |
| 1713 | u16 max_hc_pkt_count = hsotg->core_params->max_packet_count; |
| 1714 | u32 hcchar; |
| 1715 | u32 hctsiz = 0; |
| 1716 | u16 num_packets; |
Douglas Anderson | 69b76cd | 2015-11-11 10:33:52 -0800 | [diff] [blame] | 1717 | u32 ec_mc; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1718 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1719 | if (dbg_hc(chan)) |
| 1720 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1721 | |
| 1722 | if (chan->do_ping) { |
| 1723 | if (hsotg->core_params->dma_enable <= 0) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1724 | if (dbg_hc(chan)) |
| 1725 | dev_vdbg(hsotg->dev, "ping, no DMA\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1726 | dwc2_hc_do_ping(hsotg, chan); |
| 1727 | chan->xfer_started = 1; |
| 1728 | return; |
| 1729 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1730 | if (dbg_hc(chan)) |
| 1731 | dev_vdbg(hsotg->dev, "ping, DMA\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1732 | hctsiz |= TSIZ_DOPNG; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (chan->do_split) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1737 | if (dbg_hc(chan)) |
| 1738 | dev_vdbg(hsotg->dev, "split\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1739 | num_packets = 1; |
| 1740 | |
| 1741 | if (chan->complete_split && !chan->ep_is_in) |
| 1742 | /* |
| 1743 | * For CSPLIT OUT Transfer, set the size to 0 so the |
| 1744 | * core doesn't expect any data written to the FIFO |
| 1745 | */ |
| 1746 | chan->xfer_len = 0; |
| 1747 | else if (chan->ep_is_in || chan->xfer_len > chan->max_packet) |
| 1748 | chan->xfer_len = chan->max_packet; |
| 1749 | else if (!chan->ep_is_in && chan->xfer_len > 188) |
| 1750 | chan->xfer_len = 188; |
| 1751 | |
| 1752 | hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & |
| 1753 | TSIZ_XFERSIZE_MASK; |
Douglas Anderson | 69b76cd | 2015-11-11 10:33:52 -0800 | [diff] [blame] | 1754 | |
| 1755 | /* For split set ec_mc for immediate retries */ |
| 1756 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || |
| 1757 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) |
| 1758 | ec_mc = 3; |
| 1759 | else |
| 1760 | ec_mc = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1761 | } else { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1762 | if (dbg_hc(chan)) |
| 1763 | dev_vdbg(hsotg->dev, "no split\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1764 | /* |
| 1765 | * Ensure that the transfer length and packet count will fit |
| 1766 | * in the widths allocated for them in the HCTSIZn register |
| 1767 | */ |
| 1768 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || |
| 1769 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { |
| 1770 | /* |
| 1771 | * Make sure the transfer size is no larger than one |
| 1772 | * (micro)frame's worth of data. (A check was done |
| 1773 | * when the periodic transfer was accepted to ensure |
| 1774 | * that a (micro)frame's worth of data can be |
| 1775 | * programmed into a channel.) |
| 1776 | */ |
| 1777 | u32 max_periodic_len = |
| 1778 | chan->multi_count * chan->max_packet; |
| 1779 | |
| 1780 | if (chan->xfer_len > max_periodic_len) |
| 1781 | chan->xfer_len = max_periodic_len; |
| 1782 | } else if (chan->xfer_len > max_hc_xfer_size) { |
| 1783 | /* |
| 1784 | * Make sure that xfer_len is a multiple of max packet |
| 1785 | * size |
| 1786 | */ |
| 1787 | chan->xfer_len = |
| 1788 | max_hc_xfer_size - chan->max_packet + 1; |
| 1789 | } |
| 1790 | |
| 1791 | if (chan->xfer_len > 0) { |
| 1792 | num_packets = (chan->xfer_len + chan->max_packet - 1) / |
| 1793 | chan->max_packet; |
| 1794 | if (num_packets > max_hc_pkt_count) { |
| 1795 | num_packets = max_hc_pkt_count; |
| 1796 | chan->xfer_len = num_packets * chan->max_packet; |
| 1797 | } |
| 1798 | } else { |
| 1799 | /* Need 1 packet for transfer length of 0 */ |
| 1800 | num_packets = 1; |
| 1801 | } |
| 1802 | |
| 1803 | if (chan->ep_is_in) |
| 1804 | /* |
| 1805 | * Always program an integral # of max packets for IN |
| 1806 | * transfers |
| 1807 | */ |
| 1808 | chan->xfer_len = num_packets * chan->max_packet; |
| 1809 | |
| 1810 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || |
| 1811 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) |
| 1812 | /* |
| 1813 | * Make sure that the multi_count field matches the |
| 1814 | * actual transfer length |
| 1815 | */ |
| 1816 | chan->multi_count = num_packets; |
| 1817 | |
| 1818 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) |
| 1819 | dwc2_set_pid_isoc(chan); |
| 1820 | |
| 1821 | hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & |
| 1822 | TSIZ_XFERSIZE_MASK; |
Douglas Anderson | 69b76cd | 2015-11-11 10:33:52 -0800 | [diff] [blame] | 1823 | |
| 1824 | /* The ec_mc gets the multi_count for non-split */ |
| 1825 | ec_mc = chan->multi_count; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | chan->start_pkt_count = num_packets; |
| 1829 | hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK; |
| 1830 | hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & |
| 1831 | TSIZ_SC_MC_PID_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1832 | dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1833 | if (dbg_hc(chan)) { |
| 1834 | dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", |
| 1835 | hctsiz, chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1836 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1837 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, |
| 1838 | chan->hc_num); |
| 1839 | dev_vdbg(hsotg->dev, " Xfer Size: %d\n", |
Matthijs Kooijman | d6ec53e | 2013-08-30 18:45:15 +0200 | [diff] [blame] | 1840 | (hctsiz & TSIZ_XFERSIZE_MASK) >> |
| 1841 | TSIZ_XFERSIZE_SHIFT); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1842 | dev_vdbg(hsotg->dev, " Num Pkts: %d\n", |
Matthijs Kooijman | d6ec53e | 2013-08-30 18:45:15 +0200 | [diff] [blame] | 1843 | (hctsiz & TSIZ_PKTCNT_MASK) >> |
| 1844 | TSIZ_PKTCNT_SHIFT); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1845 | dev_vdbg(hsotg->dev, " Start PID: %d\n", |
Matthijs Kooijman | d6ec53e | 2013-08-30 18:45:15 +0200 | [diff] [blame] | 1846 | (hctsiz & TSIZ_SC_MC_PID_MASK) >> |
| 1847 | TSIZ_SC_MC_PID_SHIFT); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1848 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1849 | |
| 1850 | if (hsotg->core_params->dma_enable > 0) { |
| 1851 | dma_addr_t dma_addr; |
| 1852 | |
| 1853 | if (chan->align_buf) { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1854 | if (dbg_hc(chan)) |
| 1855 | dev_vdbg(hsotg->dev, "align_buf\n"); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1856 | dma_addr = chan->align_buf; |
| 1857 | } else { |
| 1858 | dma_addr = chan->xfer_dma; |
| 1859 | } |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1860 | dwc2_writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1861 | if (dbg_hc(chan)) |
| 1862 | dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", |
| 1863 | (unsigned long)dma_addr, chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | /* Start the split */ |
| 1867 | if (chan->do_split) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1868 | u32 hcsplt = dwc2_readl(hsotg->regs + HCSPLT(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1869 | |
| 1870 | hcsplt |= HCSPLT_SPLTENA; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1871 | dwc2_writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1874 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1875 | hcchar &= ~HCCHAR_MULTICNT_MASK; |
Douglas Anderson | 69b76cd | 2015-11-11 10:33:52 -0800 | [diff] [blame] | 1876 | hcchar |= (ec_mc << HCCHAR_MULTICNT_SHIFT) & HCCHAR_MULTICNT_MASK; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1877 | dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); |
| 1878 | |
| 1879 | if (hcchar & HCCHAR_CHDIS) |
| 1880 | dev_warn(hsotg->dev, |
| 1881 | "%s: chdis set, channel %d, hcchar 0x%08x\n", |
| 1882 | __func__, chan->hc_num, hcchar); |
| 1883 | |
| 1884 | /* Set host channel enable after all other setup is complete */ |
| 1885 | hcchar |= HCCHAR_CHENA; |
| 1886 | hcchar &= ~HCCHAR_CHDIS; |
| 1887 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1888 | if (dbg_hc(chan)) |
| 1889 | dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", |
Matthijs Kooijman | d6ec53e | 2013-08-30 18:45:15 +0200 | [diff] [blame] | 1890 | (hcchar & HCCHAR_MULTICNT_MASK) >> |
| 1891 | HCCHAR_MULTICNT_SHIFT); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1892 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1893 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1894 | if (dbg_hc(chan)) |
| 1895 | dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, |
| 1896 | chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1897 | |
| 1898 | chan->xfer_started = 1; |
| 1899 | chan->requests++; |
| 1900 | |
| 1901 | if (hsotg->core_params->dma_enable <= 0 && |
| 1902 | !chan->ep_is_in && chan->xfer_len > 0) |
| 1903 | /* Load OUT packet into the appropriate Tx FIFO */ |
| 1904 | dwc2_hc_write_packet(hsotg, chan); |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a |
| 1909 | * host channel and starts the transfer in Descriptor DMA mode |
| 1910 | * |
| 1911 | * @hsotg: Programming view of DWC_otg controller |
| 1912 | * @chan: Information needed to initialize the host channel |
| 1913 | * |
| 1914 | * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set. |
| 1915 | * Sets PID and NTD values. For periodic transfers initializes SCHED_INFO field |
| 1916 | * with micro-frame bitmap. |
| 1917 | * |
| 1918 | * Initializes HCDMA register with descriptor list address and CTD value then |
| 1919 | * starts the transfer via enabling the channel. |
| 1920 | */ |
| 1921 | void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, |
| 1922 | struct dwc2_host_chan *chan) |
| 1923 | { |
| 1924 | u32 hcchar; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1925 | u32 hctsiz = 0; |
| 1926 | |
| 1927 | if (chan->do_ping) |
| 1928 | hctsiz |= TSIZ_DOPNG; |
| 1929 | |
| 1930 | if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) |
| 1931 | dwc2_set_pid_isoc(chan); |
| 1932 | |
| 1933 | /* Packet Count and Xfer Size are not used in Descriptor DMA mode */ |
| 1934 | hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & |
| 1935 | TSIZ_SC_MC_PID_MASK; |
| 1936 | |
| 1937 | /* 0 - 1 descriptor, 1 - 2 descriptors, etc */ |
| 1938 | hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK; |
| 1939 | |
| 1940 | /* Non-zero only for high-speed interrupt endpoints */ |
| 1941 | hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK; |
| 1942 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1943 | if (dbg_hc(chan)) { |
| 1944 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, |
| 1945 | chan->hc_num); |
| 1946 | dev_vdbg(hsotg->dev, " Start PID: %d\n", |
| 1947 | chan->data_pid_start); |
| 1948 | dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); |
| 1949 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1950 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1951 | dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1952 | |
Gregory Herrero | 95105a9 | 2015-11-20 11:49:29 +0100 | [diff] [blame] | 1953 | dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, |
| 1954 | chan->desc_list_sz, DMA_TO_DEVICE); |
| 1955 | |
Mian Yousaf Kaukab | e23b8a5 | 2015-11-20 11:49:30 +0100 | [diff] [blame] | 1956 | dwc2_writel(chan->desc_list_addr, hsotg->regs + HCDMA(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1957 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1958 | if (dbg_hc(chan)) |
Mian Yousaf Kaukab | e23b8a5 | 2015-11-20 11:49:30 +0100 | [diff] [blame] | 1959 | dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", |
| 1960 | &chan->desc_list_addr, chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1961 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1962 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1963 | hcchar &= ~HCCHAR_MULTICNT_MASK; |
| 1964 | hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & |
| 1965 | HCCHAR_MULTICNT_MASK; |
| 1966 | |
| 1967 | if (hcchar & HCCHAR_CHDIS) |
| 1968 | dev_warn(hsotg->dev, |
| 1969 | "%s: chdis set, channel %d, hcchar 0x%08x\n", |
| 1970 | __func__, chan->hc_num, hcchar); |
| 1971 | |
| 1972 | /* Set host channel enable after all other setup is complete */ |
| 1973 | hcchar |= HCCHAR_CHENA; |
| 1974 | hcchar &= ~HCCHAR_CHDIS; |
| 1975 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1976 | if (dbg_hc(chan)) |
| 1977 | dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", |
Matthijs Kooijman | d6ec53e | 2013-08-30 18:45:15 +0200 | [diff] [blame] | 1978 | (hcchar & HCCHAR_MULTICNT_MASK) >> |
| 1979 | HCCHAR_MULTICNT_SHIFT); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1980 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 1981 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 1982 | if (dbg_hc(chan)) |
| 1983 | dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, |
| 1984 | chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 1985 | |
| 1986 | chan->xfer_started = 1; |
| 1987 | chan->requests++; |
| 1988 | } |
| 1989 | |
| 1990 | /** |
| 1991 | * dwc2_hc_continue_transfer() - Continues a data transfer that was started by |
| 1992 | * a previous call to dwc2_hc_start_transfer() |
| 1993 | * |
| 1994 | * @hsotg: Programming view of DWC_otg controller |
| 1995 | * @chan: Information needed to initialize the host channel |
| 1996 | * |
| 1997 | * The caller must ensure there is sufficient space in the request queue and Tx |
| 1998 | * Data FIFO. This function should only be called in Slave mode. In DMA mode, |
| 1999 | * the controller acts autonomously to complete transfers programmed to a host |
| 2000 | * channel. |
| 2001 | * |
| 2002 | * For an OUT transfer, a new data packet is loaded into the appropriate FIFO |
| 2003 | * if there is any data remaining to be queued. For an IN transfer, another |
| 2004 | * data packet is always requested. For the SETUP phase of a control transfer, |
| 2005 | * this function does nothing. |
| 2006 | * |
| 2007 | * Return: 1 if a new request is queued, 0 if no more requests are required |
| 2008 | * for this transfer |
| 2009 | */ |
| 2010 | int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, |
| 2011 | struct dwc2_host_chan *chan) |
| 2012 | { |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 2013 | if (dbg_hc(chan)) |
| 2014 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, |
| 2015 | chan->hc_num); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2016 | |
| 2017 | if (chan->do_split) |
| 2018 | /* SPLITs always queue just once per channel */ |
| 2019 | return 0; |
| 2020 | |
| 2021 | if (chan->data_pid_start == DWC2_HC_PID_SETUP) |
| 2022 | /* SETUPs are queued only once since they can't be NAK'd */ |
| 2023 | return 0; |
| 2024 | |
| 2025 | if (chan->ep_is_in) { |
| 2026 | /* |
| 2027 | * Always queue another request for other IN transfers. If |
| 2028 | * back-to-back INs are issued and NAKs are received for both, |
| 2029 | * the driver may still be processing the first NAK when the |
| 2030 | * second NAK is received. When the interrupt handler clears |
| 2031 | * the NAK interrupt for the first NAK, the second NAK will |
| 2032 | * not be seen. So we can't depend on the NAK interrupt |
| 2033 | * handler to requeue a NAK'd request. Instead, IN requests |
| 2034 | * are issued each time this function is called. When the |
| 2035 | * transfer completes, the extra requests for the channel will |
| 2036 | * be flushed. |
| 2037 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2038 | u32 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2039 | |
| 2040 | dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); |
| 2041 | hcchar |= HCCHAR_CHENA; |
| 2042 | hcchar &= ~HCCHAR_CHDIS; |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 2043 | if (dbg_hc(chan)) |
| 2044 | dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", |
| 2045 | hcchar); |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2046 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2047 | chan->requests++; |
| 2048 | return 1; |
| 2049 | } |
| 2050 | |
| 2051 | /* OUT transfers */ |
| 2052 | |
| 2053 | if (chan->xfer_count < chan->xfer_len) { |
| 2054 | if (chan->ep_type == USB_ENDPOINT_XFER_INT || |
| 2055 | chan->ep_type == USB_ENDPOINT_XFER_ISOC) { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2056 | u32 hcchar = dwc2_readl(hsotg->regs + |
| 2057 | HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2058 | |
| 2059 | dwc2_hc_set_even_odd_frame(hsotg, chan, |
| 2060 | &hcchar); |
| 2061 | } |
| 2062 | |
| 2063 | /* Load OUT packet into the appropriate Tx FIFO */ |
| 2064 | dwc2_hc_write_packet(hsotg, chan); |
| 2065 | chan->requests++; |
| 2066 | return 1; |
| 2067 | } |
| 2068 | |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * dwc2_hc_do_ping() - Starts a PING transfer |
| 2074 | * |
| 2075 | * @hsotg: Programming view of DWC_otg controller |
| 2076 | * @chan: Information needed to initialize the host channel |
| 2077 | * |
| 2078 | * This function should only be called in Slave mode. The Do Ping bit is set in |
| 2079 | * the HCTSIZ register, then the channel is enabled. |
| 2080 | */ |
| 2081 | void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) |
| 2082 | { |
| 2083 | u32 hcchar; |
| 2084 | u32 hctsiz; |
| 2085 | |
Matthijs Kooijman | b49977a | 2013-04-10 09:55:50 +0200 | [diff] [blame] | 2086 | if (dbg_hc(chan)) |
| 2087 | dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, |
| 2088 | chan->hc_num); |
| 2089 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2090 | |
| 2091 | hctsiz = TSIZ_DOPNG; |
| 2092 | hctsiz |= 1 << TSIZ_PKTCNT_SHIFT; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2093 | dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2094 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2095 | hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2096 | hcchar |= HCCHAR_CHENA; |
| 2097 | hcchar &= ~HCCHAR_CHDIS; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2098 | dwc2_writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for |
| 2103 | * the HFIR register according to PHY type and speed |
| 2104 | * |
| 2105 | * @hsotg: Programming view of DWC_otg controller |
| 2106 | * |
| 2107 | * NOTE: The caller can modify the value of the HFIR register only after the |
| 2108 | * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort) |
| 2109 | * has been set |
| 2110 | */ |
| 2111 | u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) |
| 2112 | { |
| 2113 | u32 usbcfg; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2114 | u32 hprt0; |
| 2115 | int clock = 60; /* default value */ |
| 2116 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2117 | usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
| 2118 | hprt0 = dwc2_readl(hsotg->regs + HPRT0); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2119 | |
| 2120 | if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) && |
| 2121 | !(usbcfg & GUSBCFG_PHYIF16)) |
| 2122 | clock = 60; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2123 | if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type == |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2124 | GHWCFG2_FS_PHY_TYPE_SHARED_ULPI) |
| 2125 | clock = 48; |
| 2126 | if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && |
| 2127 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) |
| 2128 | clock = 30; |
| 2129 | if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && |
| 2130 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16)) |
| 2131 | clock = 60; |
| 2132 | if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && |
| 2133 | !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) |
| 2134 | clock = 48; |
| 2135 | if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) && |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2136 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2137 | clock = 48; |
Matthijs Kooijman | f923463 | 2013-08-30 18:45:13 +0200 | [diff] [blame] | 2138 | if ((usbcfg & GUSBCFG_PHYSEL) && |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2139 | hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2140 | clock = 48; |
| 2141 | |
Matthijs Kooijman | f923463 | 2013-08-30 18:45:13 +0200 | [diff] [blame] | 2142 | if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2143 | /* High speed case */ |
| 2144 | return 125 * clock; |
| 2145 | else |
| 2146 | /* FS/LS case */ |
| 2147 | return 1000 * clock; |
| 2148 | } |
| 2149 | |
| 2150 | /** |
| 2151 | * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination |
| 2152 | * buffer |
| 2153 | * |
| 2154 | * @core_if: Programming view of DWC_otg controller |
| 2155 | * @dest: Destination buffer for the packet |
| 2156 | * @bytes: Number of bytes to copy to the destination |
| 2157 | */ |
| 2158 | void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) |
| 2159 | { |
| 2160 | u32 __iomem *fifo = hsotg->regs + HCFIFO(0); |
| 2161 | u32 *data_buf = (u32 *)dest; |
| 2162 | int word_count = (bytes + 3) / 4; |
| 2163 | int i; |
| 2164 | |
| 2165 | /* |
| 2166 | * Todo: Account for the case where dest is not dword aligned. This |
| 2167 | * requires reading data from the FIFO into a u32 temp buffer, then |
| 2168 | * moving it into the data buffer. |
| 2169 | */ |
| 2170 | |
| 2171 | dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); |
| 2172 | |
| 2173 | for (i = 0; i < word_count; i++, data_buf++) |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2174 | *data_buf = dwc2_readl(fifo); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | /** |
| 2178 | * dwc2_dump_host_registers() - Prints the host registers |
| 2179 | * |
| 2180 | * @hsotg: Programming view of DWC_otg controller |
| 2181 | * |
| 2182 | * NOTE: This function will be removed once the peripheral controller code |
| 2183 | * is integrated and the driver is stable |
| 2184 | */ |
| 2185 | void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg) |
| 2186 | { |
| 2187 | #ifdef DEBUG |
| 2188 | u32 __iomem *addr; |
| 2189 | int i; |
| 2190 | |
| 2191 | dev_dbg(hsotg->dev, "Host Global Registers\n"); |
| 2192 | addr = hsotg->regs + HCFG; |
| 2193 | dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2194 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2195 | addr = hsotg->regs + HFIR; |
| 2196 | dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2197 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2198 | addr = hsotg->regs + HFNUM; |
| 2199 | dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2200 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2201 | addr = hsotg->regs + HPTXSTS; |
| 2202 | dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2203 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2204 | addr = hsotg->regs + HAINT; |
| 2205 | dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2206 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2207 | addr = hsotg->regs + HAINTMSK; |
| 2208 | dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2209 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2210 | if (hsotg->core_params->dma_desc_enable > 0) { |
| 2211 | addr = hsotg->regs + HFLBADDR; |
| 2212 | dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2213 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | addr = hsotg->regs + HPRT0; |
| 2217 | dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2218 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2219 | |
| 2220 | for (i = 0; i < hsotg->core_params->host_channels; i++) { |
| 2221 | dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i); |
| 2222 | addr = hsotg->regs + HCCHAR(i); |
| 2223 | dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2224 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2225 | addr = hsotg->regs + HCSPLT(i); |
| 2226 | dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2227 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2228 | addr = hsotg->regs + HCINT(i); |
| 2229 | dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2230 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2231 | addr = hsotg->regs + HCINTMSK(i); |
| 2232 | dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2233 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2234 | addr = hsotg->regs + HCTSIZ(i); |
| 2235 | dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2236 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2237 | addr = hsotg->regs + HCDMA(i); |
| 2238 | dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2239 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2240 | if (hsotg->core_params->dma_desc_enable > 0) { |
| 2241 | addr = hsotg->regs + HCDMAB(i); |
| 2242 | dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2243 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | #endif |
| 2247 | } |
| 2248 | |
| 2249 | /** |
| 2250 | * dwc2_dump_global_registers() - Prints the core global registers |
| 2251 | * |
| 2252 | * @hsotg: Programming view of DWC_otg controller |
| 2253 | * |
| 2254 | * NOTE: This function will be removed once the peripheral controller code |
| 2255 | * is integrated and the driver is stable |
| 2256 | */ |
| 2257 | void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) |
| 2258 | { |
| 2259 | #ifdef DEBUG |
| 2260 | u32 __iomem *addr; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2261 | |
| 2262 | dev_dbg(hsotg->dev, "Core Global Registers\n"); |
| 2263 | addr = hsotg->regs + GOTGCTL; |
| 2264 | dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2265 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2266 | addr = hsotg->regs + GOTGINT; |
| 2267 | dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2268 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2269 | addr = hsotg->regs + GAHBCFG; |
| 2270 | dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2271 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2272 | addr = hsotg->regs + GUSBCFG; |
| 2273 | dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2274 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2275 | addr = hsotg->regs + GRSTCTL; |
| 2276 | dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2277 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2278 | addr = hsotg->regs + GINTSTS; |
| 2279 | dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2280 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2281 | addr = hsotg->regs + GINTMSK; |
| 2282 | dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2283 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2284 | addr = hsotg->regs + GRXSTSR; |
| 2285 | dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2286 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2287 | addr = hsotg->regs + GRXFSIZ; |
| 2288 | dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2289 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2290 | addr = hsotg->regs + GNPTXFSIZ; |
| 2291 | dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2292 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2293 | addr = hsotg->regs + GNPTXSTS; |
| 2294 | dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2295 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2296 | addr = hsotg->regs + GI2CCTL; |
| 2297 | dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2298 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2299 | addr = hsotg->regs + GPVNDCTL; |
| 2300 | dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2301 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2302 | addr = hsotg->regs + GGPIO; |
| 2303 | dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2304 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2305 | addr = hsotg->regs + GUID; |
| 2306 | dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2307 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2308 | addr = hsotg->regs + GSNPSID; |
| 2309 | dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2310 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2311 | addr = hsotg->regs + GHWCFG1; |
| 2312 | dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2313 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2314 | addr = hsotg->regs + GHWCFG2; |
| 2315 | dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2316 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2317 | addr = hsotg->regs + GHWCFG3; |
| 2318 | dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2319 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2320 | addr = hsotg->regs + GHWCFG4; |
| 2321 | dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2322 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2323 | addr = hsotg->regs + GLPMCFG; |
| 2324 | dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2325 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2326 | addr = hsotg->regs + GPWRDN; |
| 2327 | dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2328 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2329 | addr = hsotg->regs + GDFIFOCFG; |
| 2330 | dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2331 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2332 | addr = hsotg->regs + HPTXFSIZ; |
| 2333 | dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2334 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2335 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2336 | addr = hsotg->regs + PCGCTL; |
| 2337 | dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2338 | (unsigned long)addr, dwc2_readl(addr)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2339 | #endif |
| 2340 | } |
| 2341 | |
| 2342 | /** |
| 2343 | * dwc2_flush_tx_fifo() - Flushes a Tx FIFO |
| 2344 | * |
| 2345 | * @hsotg: Programming view of DWC_otg controller |
| 2346 | * @num: Tx FIFO to flush |
| 2347 | */ |
| 2348 | void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num) |
| 2349 | { |
| 2350 | u32 greset; |
| 2351 | int count = 0; |
| 2352 | |
| 2353 | dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num); |
| 2354 | |
| 2355 | greset = GRSTCTL_TXFFLSH; |
| 2356 | greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2357 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2358 | |
| 2359 | do { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2360 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2361 | if (++count > 10000) { |
| 2362 | dev_warn(hsotg->dev, |
| 2363 | "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n", |
| 2364 | __func__, greset, |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2365 | dwc2_readl(hsotg->regs + GNPTXSTS)); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2366 | break; |
| 2367 | } |
| 2368 | udelay(1); |
| 2369 | } while (greset & GRSTCTL_TXFFLSH); |
| 2370 | |
| 2371 | /* Wait for at least 3 PHY Clocks */ |
| 2372 | udelay(1); |
| 2373 | } |
| 2374 | |
| 2375 | /** |
| 2376 | * dwc2_flush_rx_fifo() - Flushes the Rx FIFO |
| 2377 | * |
| 2378 | * @hsotg: Programming view of DWC_otg controller |
| 2379 | */ |
| 2380 | void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg) |
| 2381 | { |
| 2382 | u32 greset; |
| 2383 | int count = 0; |
| 2384 | |
| 2385 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 2386 | |
| 2387 | greset = GRSTCTL_RXFFLSH; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2388 | dwc2_writel(greset, hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2389 | |
| 2390 | do { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 2391 | greset = dwc2_readl(hsotg->regs + GRSTCTL); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2392 | if (++count > 10000) { |
| 2393 | dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n", |
| 2394 | __func__, greset); |
| 2395 | break; |
| 2396 | } |
| 2397 | udelay(1); |
| 2398 | } while (greset & GRSTCTL_RXFFLSH); |
| 2399 | |
| 2400 | /* Wait for at least 3 PHY Clocks */ |
| 2401 | udelay(1); |
| 2402 | } |
| 2403 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2404 | #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2405 | |
| 2406 | /* Parameter access functions */ |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2407 | void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2408 | { |
| 2409 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2410 | |
| 2411 | switch (val) { |
| 2412 | case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2413 | if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2414 | valid = 0; |
| 2415 | break; |
| 2416 | case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2417 | switch (hsotg->hw_params.op_mode) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2418 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 2419 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 2420 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 2421 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 2422 | break; |
| 2423 | default: |
| 2424 | valid = 0; |
| 2425 | break; |
| 2426 | } |
| 2427 | break; |
| 2428 | case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: |
| 2429 | /* always valid */ |
| 2430 | break; |
| 2431 | default: |
| 2432 | valid = 0; |
| 2433 | break; |
| 2434 | } |
| 2435 | |
| 2436 | if (!valid) { |
| 2437 | if (val >= 0) |
| 2438 | dev_err(hsotg->dev, |
| 2439 | "%d invalid for otg_cap parameter. Check HW configuration.\n", |
| 2440 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2441 | switch (hsotg->hw_params.op_mode) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2442 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 2443 | val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; |
| 2444 | break; |
| 2445 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 2446 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 2447 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 2448 | val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; |
| 2449 | break; |
| 2450 | default: |
| 2451 | val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 2452 | break; |
| 2453 | } |
| 2454 | dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | hsotg->core_params->otg_cap = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2460 | void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2461 | { |
| 2462 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2463 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2464 | if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2465 | valid = 0; |
| 2466 | if (val < 0) |
| 2467 | valid = 0; |
| 2468 | |
| 2469 | if (!valid) { |
| 2470 | if (val >= 0) |
| 2471 | dev_err(hsotg->dev, |
| 2472 | "%d invalid for dma_enable parameter. Check HW configuration.\n", |
| 2473 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2474 | val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2475 | dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | hsotg->core_params->dma_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2481 | 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] | 2482 | { |
| 2483 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2484 | |
| 2485 | if (val > 0 && (hsotg->core_params->dma_enable <= 0 || |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2486 | !hsotg->hw_params.dma_desc_enable)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2487 | valid = 0; |
| 2488 | if (val < 0) |
| 2489 | valid = 0; |
| 2490 | |
| 2491 | if (!valid) { |
| 2492 | if (val >= 0) |
| 2493 | dev_err(hsotg->dev, |
| 2494 | "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", |
| 2495 | val); |
| 2496 | val = (hsotg->core_params->dma_enable > 0 && |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2497 | hsotg->hw_params.dma_desc_enable); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2498 | dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | hsotg->core_params->dma_desc_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Mian Yousaf Kaukab | fbb9e22 | 2015-11-20 11:49:28 +0100 | [diff] [blame] | 2504 | void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val) |
| 2505 | { |
| 2506 | int valid = 1; |
| 2507 | |
| 2508 | if (val > 0 && (hsotg->core_params->dma_enable <= 0 || |
| 2509 | !hsotg->hw_params.dma_desc_enable)) |
| 2510 | valid = 0; |
| 2511 | if (val < 0) |
| 2512 | valid = 0; |
| 2513 | |
| 2514 | if (!valid) { |
| 2515 | if (val >= 0) |
| 2516 | dev_err(hsotg->dev, |
| 2517 | "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n", |
| 2518 | val); |
| 2519 | val = (hsotg->core_params->dma_enable > 0 && |
| 2520 | hsotg->hw_params.dma_desc_enable); |
| 2521 | } |
| 2522 | |
| 2523 | hsotg->core_params->dma_desc_fs_enable = val; |
| 2524 | dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val); |
| 2525 | } |
| 2526 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2527 | void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, |
| 2528 | int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2529 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2530 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2531 | if (val >= 0) { |
| 2532 | dev_err(hsotg->dev, |
| 2533 | "Wrong value for host_support_fs_low_power\n"); |
| 2534 | dev_err(hsotg->dev, |
| 2535 | "host_support_fs_low_power must be 0 or 1\n"); |
| 2536 | } |
| 2537 | val = 0; |
| 2538 | dev_dbg(hsotg->dev, |
| 2539 | "Setting host_support_fs_low_power to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | hsotg->core_params->host_support_fs_ls_low_power = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2545 | 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] | 2546 | { |
| 2547 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2548 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2549 | if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2550 | valid = 0; |
| 2551 | if (val < 0) |
| 2552 | valid = 0; |
| 2553 | |
| 2554 | if (!valid) { |
| 2555 | if (val >= 0) |
| 2556 | dev_err(hsotg->dev, |
| 2557 | "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", |
| 2558 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2559 | val = hsotg->hw_params.enable_dynamic_fifo; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2560 | dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | hsotg->core_params->enable_dynamic_fifo = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2566 | 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] | 2567 | { |
| 2568 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2569 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2570 | if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2571 | valid = 0; |
| 2572 | |
| 2573 | if (!valid) { |
| 2574 | if (val >= 0) |
| 2575 | dev_err(hsotg->dev, |
| 2576 | "%d invalid for host_rx_fifo_size. Check HW configuration.\n", |
| 2577 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2578 | val = hsotg->hw_params.host_rx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2579 | 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] | 2580 | } |
| 2581 | |
| 2582 | hsotg->core_params->host_rx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2585 | 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] | 2586 | { |
| 2587 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2588 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2589 | if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2590 | valid = 0; |
| 2591 | |
| 2592 | if (!valid) { |
| 2593 | if (val >= 0) |
| 2594 | dev_err(hsotg->dev, |
| 2595 | "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", |
| 2596 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2597 | val = hsotg->hw_params.host_nperio_tx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2598 | dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", |
| 2599 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | hsotg->core_params->host_nperio_tx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2605 | 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] | 2606 | { |
| 2607 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2608 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2609 | if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2610 | valid = 0; |
| 2611 | |
| 2612 | if (!valid) { |
| 2613 | if (val >= 0) |
| 2614 | dev_err(hsotg->dev, |
| 2615 | "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", |
| 2616 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2617 | val = hsotg->hw_params.host_perio_tx_fifo_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2618 | dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", |
| 2619 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | hsotg->core_params->host_perio_tx_fifo_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2625 | 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] | 2626 | { |
| 2627 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2628 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2629 | if (val < 2047 || val > hsotg->hw_params.max_transfer_size) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2630 | valid = 0; |
| 2631 | |
| 2632 | if (!valid) { |
| 2633 | if (val >= 0) |
| 2634 | dev_err(hsotg->dev, |
| 2635 | "%d invalid for max_transfer_size. Check HW configuration.\n", |
| 2636 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2637 | val = hsotg->hw_params.max_transfer_size; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2638 | dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | hsotg->core_params->max_transfer_size = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2644 | 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] | 2645 | { |
| 2646 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2647 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2648 | if (val < 15 || val > hsotg->hw_params.max_packet_count) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2649 | valid = 0; |
| 2650 | |
| 2651 | if (!valid) { |
| 2652 | if (val >= 0) |
| 2653 | dev_err(hsotg->dev, |
| 2654 | "%d invalid for max_packet_count. Check HW configuration.\n", |
| 2655 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2656 | val = hsotg->hw_params.max_packet_count; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2657 | dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | hsotg->core_params->max_packet_count = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2663 | void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2664 | { |
| 2665 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2666 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2667 | if (val < 1 || val > hsotg->hw_params.host_channels) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2668 | valid = 0; |
| 2669 | |
| 2670 | if (!valid) { |
| 2671 | if (val >= 0) |
| 2672 | dev_err(hsotg->dev, |
| 2673 | "%d invalid for host_channels. Check HW configuration.\n", |
| 2674 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2675 | val = hsotg->hw_params.host_channels; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2676 | dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | hsotg->core_params->host_channels = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2682 | void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2683 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2684 | int valid = 0; |
Luis Ortega Perez de Villar | 0464a3d | 2013-09-25 13:10:50 +0200 | [diff] [blame] | 2685 | u32 hs_phy_type, fs_phy_type; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2686 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2687 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS, |
| 2688 | DWC2_PHY_TYPE_PARAM_ULPI)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2689 | if (val >= 0) { |
| 2690 | dev_err(hsotg->dev, "Wrong value for phy_type\n"); |
| 2691 | dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n"); |
| 2692 | } |
| 2693 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2694 | valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2697 | hs_phy_type = hsotg->hw_params.hs_phy_type; |
| 2698 | fs_phy_type = hsotg->hw_params.fs_phy_type; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2699 | if (val == DWC2_PHY_TYPE_PARAM_UTMI && |
| 2700 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || |
| 2701 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 2702 | valid = 1; |
| 2703 | else if (val == DWC2_PHY_TYPE_PARAM_ULPI && |
| 2704 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI || |
| 2705 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 2706 | valid = 1; |
| 2707 | else if (val == DWC2_PHY_TYPE_PARAM_FS && |
| 2708 | fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) |
| 2709 | valid = 1; |
| 2710 | |
| 2711 | if (!valid) { |
| 2712 | if (val >= 0) |
| 2713 | dev_err(hsotg->dev, |
| 2714 | "%d invalid for phy_type. Check HW configuration.\n", |
| 2715 | val); |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 2716 | val = DWC2_PHY_TYPE_PARAM_FS; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2717 | if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { |
| 2718 | if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || |
| 2719 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) |
| 2720 | val = DWC2_PHY_TYPE_PARAM_UTMI; |
| 2721 | else |
| 2722 | val = DWC2_PHY_TYPE_PARAM_ULPI; |
| 2723 | } |
| 2724 | dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2725 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2726 | |
| 2727 | hsotg->core_params->phy_type = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg) |
| 2731 | { |
| 2732 | return hsotg->core_params->phy_type; |
| 2733 | } |
| 2734 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2735 | void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2736 | { |
| 2737 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2738 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2739 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2740 | if (val >= 0) { |
| 2741 | dev_err(hsotg->dev, "Wrong value for speed parameter\n"); |
| 2742 | dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n"); |
| 2743 | } |
| 2744 | valid = 0; |
| 2745 | } |
| 2746 | |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 2747 | if (val == DWC2_SPEED_PARAM_HIGH && |
| 2748 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2749 | valid = 0; |
| 2750 | |
| 2751 | if (!valid) { |
| 2752 | if (val >= 0) |
| 2753 | dev_err(hsotg->dev, |
| 2754 | "%d invalid for speed parameter. Check HW configuration.\n", |
| 2755 | val); |
| 2756 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? |
Matthijs Kooijman | 929aea0 | 2013-04-29 19:36:48 +0000 | [diff] [blame] | 2757 | DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2758 | dev_dbg(hsotg->dev, "Setting speed to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | hsotg->core_params->speed = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2764 | 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] | 2765 | { |
| 2766 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2767 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2768 | if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ, |
| 2769 | DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2770 | if (val >= 0) { |
| 2771 | dev_err(hsotg->dev, |
| 2772 | "Wrong value for host_ls_low_power_phy_clk parameter\n"); |
| 2773 | dev_err(hsotg->dev, |
| 2774 | "host_ls_low_power_phy_clk must be 0 or 1\n"); |
| 2775 | } |
| 2776 | valid = 0; |
| 2777 | } |
| 2778 | |
| 2779 | if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ && |
| 2780 | dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) |
| 2781 | valid = 0; |
| 2782 | |
| 2783 | if (!valid) { |
| 2784 | if (val >= 0) |
| 2785 | dev_err(hsotg->dev, |
| 2786 | "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n", |
| 2787 | val); |
| 2788 | val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS |
| 2789 | ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ |
| 2790 | : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ; |
| 2791 | dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n", |
| 2792 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | hsotg->core_params->host_ls_low_power_phy_clk = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2798 | 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] | 2799 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2800 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2801 | if (val >= 0) { |
| 2802 | dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n"); |
| 2803 | dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n"); |
| 2804 | } |
| 2805 | val = 0; |
| 2806 | dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | hsotg->core_params->phy_ulpi_ddr = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2812 | 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] | 2813 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2814 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2815 | if (val >= 0) { |
| 2816 | dev_err(hsotg->dev, |
| 2817 | "Wrong value for phy_ulpi_ext_vbus\n"); |
| 2818 | dev_err(hsotg->dev, |
| 2819 | "phy_ulpi_ext_vbus must be 0 or 1\n"); |
| 2820 | } |
| 2821 | val = 0; |
| 2822 | 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] | 2823 | } |
| 2824 | |
| 2825 | hsotg->core_params->phy_ulpi_ext_vbus = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2828 | 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] | 2829 | { |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 2830 | int valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2831 | |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 2832 | switch (hsotg->hw_params.utmi_phy_data_width) { |
| 2833 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: |
| 2834 | valid = (val == 8); |
| 2835 | break; |
| 2836 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: |
| 2837 | valid = (val == 16); |
| 2838 | break; |
| 2839 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: |
| 2840 | valid = (val == 8 || val == 16); |
| 2841 | break; |
| 2842 | } |
| 2843 | |
| 2844 | if (!valid) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2845 | if (val >= 0) { |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 2846 | dev_err(hsotg->dev, |
| 2847 | "%d invalid for phy_utmi_width. Check HW configuration.\n", |
| 2848 | val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2849 | } |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 2850 | val = (hsotg->hw_params.utmi_phy_data_width == |
| 2851 | GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2852 | dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | hsotg->core_params->phy_utmi_width = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2858 | 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] | 2859 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2860 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2861 | if (val >= 0) { |
| 2862 | dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n"); |
| 2863 | dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n"); |
| 2864 | } |
| 2865 | val = 0; |
| 2866 | dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | hsotg->core_params->ulpi_fs_ls = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2870 | } |
| 2871 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2872 | void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2873 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2874 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2875 | if (val >= 0) { |
| 2876 | dev_err(hsotg->dev, "Wrong value for ts_dline\n"); |
| 2877 | dev_err(hsotg->dev, "ts_dline must be 0 or 1\n"); |
| 2878 | } |
| 2879 | val = 0; |
| 2880 | dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
| 2883 | hsotg->core_params->ts_dline = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2886 | void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2887 | { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2888 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2889 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2890 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2891 | if (val >= 0) { |
| 2892 | dev_err(hsotg->dev, "Wrong value for i2c_enable\n"); |
| 2893 | dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n"); |
| 2894 | } |
| 2895 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2896 | valid = 0; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2899 | if (val == 1 && !(hsotg->hw_params.i2c_enable)) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2900 | valid = 0; |
| 2901 | |
| 2902 | if (!valid) { |
| 2903 | if (val >= 0) |
| 2904 | dev_err(hsotg->dev, |
| 2905 | "%d invalid for i2c_enable. Check HW configuration.\n", |
| 2906 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2907 | val = hsotg->hw_params.i2c_enable; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2908 | dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2909 | } |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2910 | |
| 2911 | hsotg->core_params->i2c_enable = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2914 | 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] | 2915 | { |
| 2916 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2917 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2918 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2919 | if (val >= 0) { |
| 2920 | dev_err(hsotg->dev, |
| 2921 | "Wrong value for en_multiple_tx_fifo,\n"); |
| 2922 | dev_err(hsotg->dev, |
| 2923 | "en_multiple_tx_fifo must be 0 or 1\n"); |
| 2924 | } |
| 2925 | valid = 0; |
| 2926 | } |
| 2927 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2928 | if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2929 | valid = 0; |
| 2930 | |
| 2931 | if (!valid) { |
| 2932 | if (val >= 0) |
| 2933 | dev_err(hsotg->dev, |
| 2934 | "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", |
| 2935 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2936 | val = hsotg->hw_params.en_multiple_tx_fifo; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2937 | 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] | 2938 | } |
| 2939 | |
| 2940 | hsotg->core_params->en_multiple_tx_fifo = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2943 | void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2944 | { |
| 2945 | int valid = 1; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2946 | |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2947 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2948 | if (val >= 0) { |
| 2949 | dev_err(hsotg->dev, |
| 2950 | "'%d' invalid for parameter reload_ctl\n", val); |
| 2951 | dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n"); |
| 2952 | } |
| 2953 | valid = 0; |
| 2954 | } |
| 2955 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2956 | if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2957 | valid = 0; |
| 2958 | |
| 2959 | if (!valid) { |
| 2960 | if (val >= 0) |
| 2961 | dev_err(hsotg->dev, |
| 2962 | "%d invalid for parameter reload_ctl. Check HW configuration.\n", |
| 2963 | val); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 2964 | val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2965 | dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | hsotg->core_params->reload_ctl = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2971 | void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2972 | { |
Paul Zimmerman | 4d3190e | 2013-07-16 12:22:12 -0700 | [diff] [blame] | 2973 | if (val != -1) |
| 2974 | hsotg->core_params->ahbcfg = val; |
| 2975 | else |
Matthijs Kooijman | f923463 | 2013-08-30 18:45:13 +0200 | [diff] [blame] | 2976 | hsotg->core_params->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << |
Luis Ortega Perez de Villar | 0464a3d | 2013-09-25 13:10:50 +0200 | [diff] [blame] | 2977 | GAHBCFG_HBSTLEN_SHIFT; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
Paul Zimmerman | 7218dae | 2013-11-22 16:43:48 -0800 | [diff] [blame] | 2980 | void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2981 | { |
Paul Zimmerman | 498f066 | 2013-11-22 16:43:47 -0800 | [diff] [blame] | 2982 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2983 | if (val >= 0) { |
| 2984 | dev_err(hsotg->dev, |
| 2985 | "'%d' invalid for parameter otg_ver\n", val); |
| 2986 | dev_err(hsotg->dev, |
| 2987 | "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n"); |
| 2988 | } |
| 2989 | val = 0; |
| 2990 | dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | hsotg->core_params->otg_ver = val; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Wei Yongjun | 49cf10c | 2013-11-28 10:27:59 +0800 | [diff] [blame] | 2996 | 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] | 2997 | { |
| 2998 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 2999 | if (val >= 0) { |
| 3000 | dev_err(hsotg->dev, |
| 3001 | "'%d' invalid for parameter uframe_sched\n", |
| 3002 | val); |
| 3003 | dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n"); |
| 3004 | } |
| 3005 | val = 1; |
| 3006 | dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val); |
| 3007 | } |
| 3008 | |
| 3009 | hsotg->core_params->uframe_sched = val; |
| 3010 | } |
| 3011 | |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 3012 | static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg, |
| 3013 | int val) |
| 3014 | { |
| 3015 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 3016 | if (val >= 0) { |
| 3017 | dev_err(hsotg->dev, |
| 3018 | "'%d' invalid for parameter external_id_pin_ctl\n", |
| 3019 | val); |
| 3020 | dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n"); |
| 3021 | } |
| 3022 | val = 0; |
| 3023 | dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val); |
| 3024 | } |
| 3025 | |
| 3026 | hsotg->core_params->external_id_pin_ctl = val; |
| 3027 | } |
| 3028 | |
Gregory Herrero | 285046a | 2015-04-29 22:09:19 +0200 | [diff] [blame] | 3029 | static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg, |
| 3030 | int val) |
| 3031 | { |
| 3032 | if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { |
| 3033 | if (val >= 0) { |
| 3034 | dev_err(hsotg->dev, |
| 3035 | "'%d' invalid for parameter hibernation\n", |
| 3036 | val); |
| 3037 | dev_err(hsotg->dev, "hibernation must be 0 or 1\n"); |
| 3038 | } |
| 3039 | val = 0; |
| 3040 | dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val); |
| 3041 | } |
| 3042 | |
| 3043 | hsotg->core_params->hibernation = val; |
| 3044 | } |
| 3045 | |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 3046 | /* |
| 3047 | * This function is called during module intialization to pass module parameters |
| 3048 | * for the DWC_otg core. |
| 3049 | */ |
| 3050 | void dwc2_set_parameters(struct dwc2_hsotg *hsotg, |
| 3051 | const struct dwc2_core_params *params) |
| 3052 | { |
| 3053 | dev_dbg(hsotg->dev, "%s()\n", __func__); |
| 3054 | |
| 3055 | dwc2_set_param_otg_cap(hsotg, params->otg_cap); |
| 3056 | dwc2_set_param_dma_enable(hsotg, params->dma_enable); |
| 3057 | dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); |
Mian Yousaf Kaukab | fbb9e22 | 2015-11-20 11:49:28 +0100 | [diff] [blame] | 3058 | 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] | 3059 | dwc2_set_param_host_support_fs_ls_low_power(hsotg, |
| 3060 | params->host_support_fs_ls_low_power); |
| 3061 | dwc2_set_param_enable_dynamic_fifo(hsotg, |
| 3062 | params->enable_dynamic_fifo); |
| 3063 | dwc2_set_param_host_rx_fifo_size(hsotg, |
| 3064 | params->host_rx_fifo_size); |
| 3065 | dwc2_set_param_host_nperio_tx_fifo_size(hsotg, |
| 3066 | params->host_nperio_tx_fifo_size); |
| 3067 | dwc2_set_param_host_perio_tx_fifo_size(hsotg, |
| 3068 | params->host_perio_tx_fifo_size); |
| 3069 | dwc2_set_param_max_transfer_size(hsotg, |
| 3070 | params->max_transfer_size); |
| 3071 | dwc2_set_param_max_packet_count(hsotg, |
| 3072 | params->max_packet_count); |
| 3073 | dwc2_set_param_host_channels(hsotg, params->host_channels); |
| 3074 | dwc2_set_param_phy_type(hsotg, params->phy_type); |
| 3075 | dwc2_set_param_speed(hsotg, params->speed); |
| 3076 | dwc2_set_param_host_ls_low_power_phy_clk(hsotg, |
| 3077 | params->host_ls_low_power_phy_clk); |
| 3078 | dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr); |
| 3079 | dwc2_set_param_phy_ulpi_ext_vbus(hsotg, |
| 3080 | params->phy_ulpi_ext_vbus); |
| 3081 | dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width); |
| 3082 | dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls); |
| 3083 | dwc2_set_param_ts_dline(hsotg, params->ts_dline); |
| 3084 | dwc2_set_param_i2c_enable(hsotg, params->i2c_enable); |
| 3085 | dwc2_set_param_en_multiple_tx_fifo(hsotg, |
| 3086 | params->en_multiple_tx_fifo); |
| 3087 | dwc2_set_param_reload_ctl(hsotg, params->reload_ctl); |
| 3088 | dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); |
| 3089 | dwc2_set_param_otg_ver(hsotg, params->otg_ver); |
| 3090 | dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); |
Gregory Herrero | a6d249d | 2015-04-29 22:09:04 +0200 | [diff] [blame] | 3091 | 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] | 3092 | dwc2_set_param_hibernation(hsotg, params->hibernation); |
Paul Zimmerman | e8576e6 | 2013-11-25 13:42:47 -0800 | [diff] [blame] | 3093 | } |
| 3094 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3095 | /** |
| 3096 | * During device initialization, read various hardware configuration |
| 3097 | * registers and interpret the contents. |
| 3098 | */ |
| 3099 | int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) |
| 3100 | { |
| 3101 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 3102 | unsigned width; |
| 3103 | u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; |
| 3104 | u32 hptxfsiz, grxfsiz, gnptxfsiz; |
| 3105 | u32 gusbcfg; |
| 3106 | |
| 3107 | /* |
| 3108 | * Attempt to ensure this device is really a DWC_otg Controller. |
| 3109 | * Read and verify the GSNPSID register contents. The value should be |
| 3110 | * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", |
| 3111 | * as in "OTG version 2.xx" or "OTG version 3.xx". |
| 3112 | */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3113 | hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3114 | if ((hw->snpsid & 0xfffff000) != 0x4f542000 && |
| 3115 | (hw->snpsid & 0xfffff000) != 0x4f543000) { |
| 3116 | dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", |
| 3117 | hw->snpsid); |
| 3118 | return -ENODEV; |
| 3119 | } |
| 3120 | |
| 3121 | dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", |
| 3122 | hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, |
| 3123 | hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); |
| 3124 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3125 | hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); |
| 3126 | hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); |
| 3127 | hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); |
| 3128 | hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); |
| 3129 | grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3130 | |
| 3131 | dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); |
| 3132 | dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); |
| 3133 | dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); |
| 3134 | dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3135 | dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); |
| 3136 | |
Doug Anderson | 2867c05 | 2014-08-07 12:48:11 -0700 | [diff] [blame] | 3137 | /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */ |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3138 | gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); |
Douglas Anderson | 9918246 | 2015-12-17 11:14:12 -0800 | [diff] [blame] | 3139 | if (!(gusbcfg & GUSBCFG_FORCEHOSTMODE)) { |
| 3140 | dwc2_writel(gusbcfg | GUSBCFG_FORCEHOSTMODE, |
| 3141 | hsotg->regs + GUSBCFG); |
| 3142 | usleep_range(100000, 150000); |
| 3143 | } |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3144 | |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3145 | gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 3146 | hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); |
Doug Anderson | 2867c05 | 2014-08-07 12:48:11 -0700 | [diff] [blame] | 3147 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3148 | dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); |
Douglas Anderson | 9918246 | 2015-12-17 11:14:12 -0800 | [diff] [blame] | 3149 | if (!(gusbcfg & GUSBCFG_FORCEHOSTMODE)) { |
| 3150 | dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); |
| 3151 | usleep_range(100000, 150000); |
| 3152 | } |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3153 | |
| 3154 | /* hwcfg2 */ |
| 3155 | hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> |
| 3156 | GHWCFG2_OP_MODE_SHIFT; |
| 3157 | hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> |
| 3158 | GHWCFG2_ARCHITECTURE_SHIFT; |
| 3159 | hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); |
| 3160 | hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> |
| 3161 | GHWCFG2_NUM_HOST_CHAN_SHIFT); |
| 3162 | hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> |
| 3163 | GHWCFG2_HS_PHY_TYPE_SHIFT; |
| 3164 | hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> |
| 3165 | GHWCFG2_FS_PHY_TYPE_SHIFT; |
| 3166 | hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> |
| 3167 | GHWCFG2_NUM_DEV_EP_SHIFT; |
| 3168 | hw->nperio_tx_q_depth = |
| 3169 | (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> |
| 3170 | GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; |
| 3171 | hw->host_perio_tx_q_depth = |
| 3172 | (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> |
| 3173 | GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; |
| 3174 | hw->dev_token_q_depth = |
| 3175 | (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> |
| 3176 | GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; |
| 3177 | |
| 3178 | /* hwcfg3 */ |
| 3179 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> |
| 3180 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; |
| 3181 | hw->max_transfer_size = (1 << (width + 11)) - 1; |
Paul Zimmerman | e8f8c14 | 2014-09-16 13:47:26 -0700 | [diff] [blame] | 3182 | /* |
| 3183 | * Clip max_transfer_size to 65535. dwc2_hc_setup_align_buf() allocates |
| 3184 | * coherent buffers with this size, and if it's too large we can |
| 3185 | * exhaust the coherent DMA pool. |
| 3186 | */ |
| 3187 | if (hw->max_transfer_size > 65535) |
| 3188 | hw->max_transfer_size = 65535; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3189 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> |
| 3190 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; |
| 3191 | hw->max_packet_count = (1 << (width + 4)) - 1; |
| 3192 | hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); |
| 3193 | hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> |
| 3194 | GHWCFG3_DFIFO_DEPTH_SHIFT; |
| 3195 | |
| 3196 | /* hwcfg4 */ |
| 3197 | hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); |
| 3198 | hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> |
| 3199 | GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; |
| 3200 | hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); |
| 3201 | hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 3202 | hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> |
| 3203 | GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3204 | |
| 3205 | /* fifo sizes */ |
| 3206 | hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> |
| 3207 | GRXFSIZ_DEPTH_SHIFT; |
| 3208 | hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 3209 | FIFOSIZE_DEPTH_SHIFT; |
| 3210 | hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 3211 | FIFOSIZE_DEPTH_SHIFT; |
| 3212 | |
| 3213 | dev_dbg(hsotg->dev, "Detected values from hardware:\n"); |
| 3214 | dev_dbg(hsotg->dev, " op_mode=%d\n", |
| 3215 | hw->op_mode); |
| 3216 | dev_dbg(hsotg->dev, " arch=%d\n", |
| 3217 | hw->arch); |
| 3218 | dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", |
| 3219 | hw->dma_desc_enable); |
| 3220 | dev_dbg(hsotg->dev, " power_optimized=%d\n", |
| 3221 | hw->power_optimized); |
| 3222 | dev_dbg(hsotg->dev, " i2c_enable=%d\n", |
| 3223 | hw->i2c_enable); |
| 3224 | dev_dbg(hsotg->dev, " hs_phy_type=%d\n", |
| 3225 | hw->hs_phy_type); |
| 3226 | dev_dbg(hsotg->dev, " fs_phy_type=%d\n", |
| 3227 | hw->fs_phy_type); |
Masanari Iida | 971bd8f | 2015-05-20 23:54:02 +0900 | [diff] [blame] | 3228 | dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n", |
Matthijs Kooijman | de4a193 | 2013-08-30 18:45:22 +0200 | [diff] [blame] | 3229 | hw->utmi_phy_data_width); |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3230 | dev_dbg(hsotg->dev, " num_dev_ep=%d\n", |
| 3231 | hw->num_dev_ep); |
| 3232 | dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", |
| 3233 | hw->num_dev_perio_in_ep); |
| 3234 | dev_dbg(hsotg->dev, " host_channels=%d\n", |
| 3235 | hw->host_channels); |
| 3236 | dev_dbg(hsotg->dev, " max_transfer_size=%d\n", |
| 3237 | hw->max_transfer_size); |
| 3238 | dev_dbg(hsotg->dev, " max_packet_count=%d\n", |
| 3239 | hw->max_packet_count); |
| 3240 | dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", |
| 3241 | hw->nperio_tx_q_depth); |
| 3242 | dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", |
| 3243 | hw->host_perio_tx_q_depth); |
| 3244 | dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", |
| 3245 | hw->dev_token_q_depth); |
| 3246 | dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", |
| 3247 | hw->enable_dynamic_fifo); |
| 3248 | dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", |
| 3249 | hw->en_multiple_tx_fifo); |
| 3250 | dev_dbg(hsotg->dev, " total_fifo_size=%d\n", |
| 3251 | hw->total_fifo_size); |
| 3252 | dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n", |
| 3253 | hw->host_rx_fifo_size); |
| 3254 | dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", |
| 3255 | hw->host_nperio_tx_fifo_size); |
| 3256 | dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", |
| 3257 | hw->host_perio_tx_fifo_size); |
| 3258 | dev_dbg(hsotg->dev, "\n"); |
| 3259 | |
| 3260 | return 0; |
| 3261 | } |
Mian Yousaf Kaukab | ecb176c | 2015-04-29 22:09:05 +0200 | [diff] [blame] | 3262 | |
| 3263 | /* |
| 3264 | * Sets all parameters to the given value. |
| 3265 | * |
| 3266 | * Assumes that the dwc2_core_params struct contains only integers. |
| 3267 | */ |
| 3268 | void dwc2_set_all_params(struct dwc2_core_params *params, int value) |
| 3269 | { |
| 3270 | int *p = (int *)params; |
| 3271 | size_t size = sizeof(*params) / sizeof(*p); |
| 3272 | int i; |
| 3273 | |
| 3274 | for (i = 0; i < size; i++) |
| 3275 | p[i] = value; |
| 3276 | } |
Mian Yousaf Kaukab | ecb176c | 2015-04-29 22:09:05 +0200 | [diff] [blame] | 3277 | |
Matthijs Kooijman | 9badec2 | 2013-08-30 18:45:21 +0200 | [diff] [blame] | 3278 | |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3279 | u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg) |
| 3280 | { |
Paul Zimmerman | b66a3f0 | 2013-11-22 16:43:50 -0800 | [diff] [blame] | 3281 | return hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 3284 | bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg) |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3285 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3286 | if (dwc2_readl(hsotg->regs + GSNPSID) == 0xffffffff) |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 3287 | return false; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3288 | else |
Paul Zimmerman | 057715f | 2013-11-22 16:43:51 -0800 | [diff] [blame] | 3289 | return true; |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | /** |
| 3293 | * dwc2_enable_global_interrupts() - Enables the controller's Global |
| 3294 | * Interrupt in the AHB Config register |
| 3295 | * |
| 3296 | * @hsotg: Programming view of DWC_otg controller |
| 3297 | */ |
| 3298 | void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg) |
| 3299 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3300 | u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3301 | |
| 3302 | ahbcfg |= GAHBCFG_GLBL_INTR_EN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3303 | dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | /** |
| 3307 | * dwc2_disable_global_interrupts() - Disables the controller's Global |
| 3308 | * Interrupt in the AHB Config register |
| 3309 | * |
| 3310 | * @hsotg: Programming view of DWC_otg controller |
| 3311 | */ |
| 3312 | void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg) |
| 3313 | { |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3314 | u32 ahbcfg = dwc2_readl(hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3315 | |
| 3316 | ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; |
Antti Seppälä | 95c8bc3 | 2015-08-20 21:41:07 +0300 | [diff] [blame] | 3317 | dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); |
Paul Zimmerman | 56f5b1c | 2013-03-11 17:47:58 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | MODULE_DESCRIPTION("DESIGNWARE HS OTG Core"); |
| 3321 | MODULE_AUTHOR("Synopsys, Inc."); |
| 3322 | MODULE_LICENSE("Dual BSD/GPL"); |