Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2004-2016 Synopsys, Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions, and the following disclaimer, |
| 10 | * without modification. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The names of the above-listed copyright holders may not be used |
| 15 | * to endorse or promote products derived from this software without |
| 16 | * specific prior written permission. |
| 17 | * |
| 18 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 19 | * GNU General Public License ("GPL") as published by the Free Software |
| 20 | * Foundation; either version 2 of the License, or (at your option) any |
| 21 | * later version. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | */ |
| 35 | |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/of_device.h> |
| 39 | |
| 40 | #include "core.h" |
| 41 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 42 | static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg) |
| 43 | { |
| 44 | struct dwc2_core_params *p = &hsotg->params; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 45 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 46 | p->host_rx_fifo_size = 774; |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 47 | p->max_transfer_size = 65535; |
| 48 | p->max_packet_count = 511; |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 49 | p->ahbcfg = 0x10; |
| 50 | p->uframe_sched = false; |
| 51 | } |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 52 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 53 | static void dwc2_set_his_params(struct dwc2_hsotg *hsotg) |
| 54 | { |
| 55 | struct dwc2_core_params *p = &hsotg->params; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 56 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 57 | p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 58 | p->speed = DWC2_SPEED_PARAM_HIGH; |
| 59 | p->host_rx_fifo_size = 512; |
| 60 | p->host_nperio_tx_fifo_size = 512; |
| 61 | p->host_perio_tx_fifo_size = 512; |
| 62 | p->max_transfer_size = 65535; |
| 63 | p->max_packet_count = 511; |
| 64 | p->host_channels = 16; |
| 65 | p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI; |
| 66 | p->phy_utmi_width = 8; |
| 67 | p->i2c_enable = false; |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 68 | p->reload_ctl = false; |
| 69 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << |
| 70 | GAHBCFG_HBSTLEN_SHIFT; |
| 71 | p->uframe_sched = false; |
Chen Yu | ca8b033 | 2017-01-23 15:00:18 -0800 | [diff] [blame] | 72 | p->change_speed_quirk = true; |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 73 | } |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 74 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 75 | static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg) |
| 76 | { |
| 77 | struct dwc2_core_params *p = &hsotg->params; |
| 78 | |
| 79 | p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 80 | p->host_rx_fifo_size = 525; |
| 81 | p->host_nperio_tx_fifo_size = 128; |
| 82 | p->host_perio_tx_fifo_size = 256; |
| 83 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << |
| 84 | GAHBCFG_HBSTLEN_SHIFT; |
| 85 | } |
| 86 | |
| 87 | static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg) |
| 88 | { |
| 89 | struct dwc2_core_params *p = &hsotg->params; |
| 90 | |
| 91 | p->otg_cap = 2; |
| 92 | p->host_rx_fifo_size = 288; |
| 93 | p->host_nperio_tx_fifo_size = 128; |
| 94 | p->host_perio_tx_fifo_size = 96; |
| 95 | p->max_transfer_size = 65535; |
| 96 | p->max_packet_count = 511; |
| 97 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << |
| 98 | GAHBCFG_HBSTLEN_SHIFT; |
| 99 | } |
| 100 | |
| 101 | static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg) |
| 102 | { |
| 103 | struct dwc2_core_params *p = &hsotg->params; |
| 104 | |
| 105 | p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 106 | p->speed = DWC2_SPEED_PARAM_HIGH; |
| 107 | p->host_rx_fifo_size = 512; |
| 108 | p->host_nperio_tx_fifo_size = 500; |
| 109 | p->host_perio_tx_fifo_size = 500; |
| 110 | p->host_channels = 16; |
| 111 | p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI; |
| 112 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 << |
| 113 | GAHBCFG_HBSTLEN_SHIFT; |
| 114 | p->uframe_sched = false; |
| 115 | } |
| 116 | |
| 117 | static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg) |
| 118 | { |
| 119 | struct dwc2_core_params *p = &hsotg->params; |
| 120 | |
| 121 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT; |
| 122 | } |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 123 | |
Bruno Herrera | e35b135 | 2017-01-31 23:25:43 -0200 | [diff] [blame] | 124 | static void dwc2_set_stm32f4x9_fsotg_params(struct dwc2_hsotg *hsotg) |
| 125 | { |
| 126 | struct dwc2_core_params *p = &hsotg->params; |
| 127 | |
| 128 | p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
| 129 | p->speed = DWC2_SPEED_PARAM_FULL; |
| 130 | p->host_rx_fifo_size = 128; |
| 131 | p->host_nperio_tx_fifo_size = 96; |
| 132 | p->host_perio_tx_fifo_size = 96; |
| 133 | p->max_packet_count = 256; |
| 134 | p->phy_type = DWC2_PHY_TYPE_PARAM_FS; |
| 135 | p->i2c_enable = false; |
| 136 | p->uframe_sched = false; |
| 137 | p->activate_stm_fs_transceiver = true; |
| 138 | } |
| 139 | |
Amelie Delaunay | d8fae8b | 2017-08-17 11:33:01 +0200 | [diff] [blame] | 140 | static void dwc2_set_stm32f7xx_hsotg_params(struct dwc2_hsotg *hsotg) |
| 141 | { |
| 142 | struct dwc2_core_params *p = &hsotg->params; |
| 143 | |
| 144 | p->host_rx_fifo_size = 622; |
| 145 | p->host_nperio_tx_fifo_size = 128; |
| 146 | p->host_perio_tx_fifo_size = 256; |
| 147 | } |
| 148 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 149 | const struct of_device_id dwc2_of_match_table[] = { |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 150 | { .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params }, |
| 151 | { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params }, |
| 152 | { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params }, |
| 153 | { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params }, |
| 154 | { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params }, |
| 155 | { .compatible = "snps,dwc2" }, |
| 156 | { .compatible = "samsung,s3c6400-hsotg" }, |
Martin Blumenstingl | 55b644f | 2017-05-06 19:37:45 +0200 | [diff] [blame] | 157 | { .compatible = "amlogic,meson8-usb", |
| 158 | .data = dwc2_set_amlogic_params }, |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 159 | { .compatible = "amlogic,meson8b-usb", |
| 160 | .data = dwc2_set_amlogic_params }, |
| 161 | { .compatible = "amlogic,meson-gxbb-usb", |
| 162 | .data = dwc2_set_amlogic_params }, |
| 163 | { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params }, |
Bruno Herrera | e35b135 | 2017-01-31 23:25:43 -0200 | [diff] [blame] | 164 | { .compatible = "st,stm32f4x9-fsotg", |
| 165 | .data = dwc2_set_stm32f4x9_fsotg_params }, |
| 166 | { .compatible = "st,stm32f4x9-hsotg" }, |
Amelie Delaunay | d8fae8b | 2017-08-17 11:33:01 +0200 | [diff] [blame] | 167 | { .compatible = "st,stm32f7xx-hsotg", |
| 168 | .data = dwc2_set_stm32f7xx_hsotg_params }, |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 169 | {}, |
| 170 | }; |
| 171 | MODULE_DEVICE_TABLE(of, dwc2_of_match_table); |
| 172 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 173 | static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg) |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 174 | { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 175 | u8 val; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 176 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 177 | switch (hsotg->hw_params.op_mode) { |
| 178 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 179 | val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 180 | break; |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 181 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 182 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 183 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 184 | val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 185 | break; |
| 186 | default: |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 187 | val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 188 | break; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 189 | } |
| 190 | |
John Youn | bea8e86 | 2016-11-03 17:55:53 -0700 | [diff] [blame] | 191 | hsotg->params.otg_cap = val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 192 | } |
| 193 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 194 | static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg) |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 195 | { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 196 | int val; |
| 197 | u32 hs_phy_type = hsotg->hw_params.hs_phy_type; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 198 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 199 | val = DWC2_PHY_TYPE_PARAM_FS; |
| 200 | if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { |
| 201 | if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || |
| 202 | hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) |
| 203 | val = DWC2_PHY_TYPE_PARAM_UTMI; |
| 204 | else |
| 205 | val = DWC2_PHY_TYPE_PARAM_ULPI; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 206 | } |
| 207 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 208 | if (dwc2_is_fs_iot(hsotg)) |
| 209 | hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 210 | |
John Youn | bea8e86 | 2016-11-03 17:55:53 -0700 | [diff] [blame] | 211 | hsotg->params.phy_type = val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 212 | } |
| 213 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 214 | static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg) |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 215 | { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 216 | int val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 217 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 218 | val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ? |
| 219 | DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 220 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 221 | if (dwc2_is_fs_iot(hsotg)) |
| 222 | val = DWC2_SPEED_PARAM_FULL; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 223 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 224 | if (dwc2_is_hs_iot(hsotg)) |
| 225 | val = DWC2_SPEED_PARAM_HIGH; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 226 | |
John Youn | bea8e86 | 2016-11-03 17:55:53 -0700 | [diff] [blame] | 227 | hsotg->params.speed = val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 228 | } |
| 229 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 230 | static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg) |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 231 | { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 232 | int val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 233 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 234 | val = (hsotg->hw_params.utmi_phy_data_width == |
| 235 | GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 236 | |
John Youn | bea8e86 | 2016-11-03 17:55:53 -0700 | [diff] [blame] | 237 | hsotg->params.phy_utmi_width = val; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 238 | } |
| 239 | |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 240 | static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg) |
| 241 | { |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 242 | struct dwc2_core_params *p = &hsotg->params; |
Sevak Arakelyan | c138ecf | 2017-01-23 15:01:23 -0800 | [diff] [blame] | 243 | int depth_average; |
| 244 | int fifo_count; |
| 245 | int i; |
| 246 | |
| 247 | fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 248 | |
| 249 | memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size)); |
Sevak Arakelyan | c138ecf | 2017-01-23 15:01:23 -0800 | [diff] [blame] | 250 | depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg); |
| 251 | for (i = 1; i <= fifo_count; i++) |
| 252 | p->g_tx_fifo_size[i] = depth_average; |
John Youn | 9962b62 | 2016-11-09 19:27:40 -0800 | [diff] [blame] | 253 | } |
| 254 | |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 255 | /** |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 256 | * dwc2_set_default_params() - Set all core parameters to their |
| 257 | * auto-detected default values. |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 258 | */ |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 259 | static void dwc2_set_default_params(struct dwc2_hsotg *hsotg) |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 260 | { |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 261 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 262 | struct dwc2_core_params *p = &hsotg->params; |
John Youn | 6b66ce5 | 2016-11-03 17:56:12 -0700 | [diff] [blame] | 263 | bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 264 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 265 | dwc2_set_param_otg_cap(hsotg); |
| 266 | dwc2_set_param_phy_type(hsotg); |
| 267 | dwc2_set_param_speed(hsotg); |
| 268 | dwc2_set_param_phy_utmi_width(hsotg); |
| 269 | p->phy_ulpi_ddr = false; |
| 270 | p->phy_ulpi_ext_vbus = false; |
| 271 | |
| 272 | p->enable_dynamic_fifo = hw->enable_dynamic_fifo; |
| 273 | p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo; |
| 274 | p->i2c_enable = hw->i2c_enable; |
Razmik Karapetyan | 66e77a2 | 2018-01-24 17:40:29 +0400 | [diff] [blame] | 275 | p->acg_enable = hw->acg_enable; |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 276 | p->ulpi_fs_ls = false; |
| 277 | p->ts_dline = false; |
| 278 | p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a); |
| 279 | p->uframe_sched = true; |
| 280 | p->external_id_pin_ctl = false; |
Vardan Mikayelyan | 41ba9b9 | 2018-02-16 14:06:36 +0400 | [diff] [blame] | 281 | p->power_down = false; |
Sevak Arakelyan | 6f80b6d | 2018-01-24 17:41:48 +0400 | [diff] [blame] | 282 | p->lpm = true; |
| 283 | p->lpm_clock_gating = true; |
| 284 | p->besl = true; |
| 285 | p->hird_threshold_en = true; |
| 286 | p->hird_threshold = 4; |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 287 | p->max_packet_count = hw->max_packet_count; |
| 288 | p->max_transfer_size = hw->max_transfer_size; |
Razmik Karapetyan | 1b52d2f | 2018-01-19 14:40:23 +0400 | [diff] [blame] | 289 | p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT; |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 290 | |
John Youn | 6b66ce5 | 2016-11-03 17:56:12 -0700 | [diff] [blame] | 291 | if ((hsotg->dr_mode == USB_DR_MODE_HOST) || |
| 292 | (hsotg->dr_mode == USB_DR_MODE_OTG)) { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 293 | p->host_dma = dma_capable; |
| 294 | p->dma_desc_enable = false; |
| 295 | p->dma_desc_fs_enable = false; |
| 296 | p->host_support_fs_ls_low_power = false; |
| 297 | p->host_ls_low_power_phy_clk = false; |
| 298 | p->host_channels = hw->host_channels; |
| 299 | p->host_rx_fifo_size = hw->rx_fifo_size; |
| 300 | p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size; |
| 301 | p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size; |
John Youn | 6b66ce5 | 2016-11-03 17:56:12 -0700 | [diff] [blame] | 302 | } |
| 303 | |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 304 | if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || |
| 305 | (hsotg->dr_mode == USB_DR_MODE_OTG)) { |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 306 | p->g_dma = dma_capable; |
| 307 | p->g_dma_desc = hw->dma_desc_enable; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * The values for g_rx_fifo_size (2048) and |
| 311 | * g_np_tx_fifo_size (1024) come from the legacy s3c |
| 312 | * gadget driver. These defaults have been hard-coded |
| 313 | * for some time so many platforms depend on these |
| 314 | * values. Leave them as defaults for now and only |
| 315 | * auto-detect if the hardware does not support the |
| 316 | * default. |
| 317 | */ |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 318 | p->g_rx_fifo_size = 2048; |
| 319 | p->g_np_tx_fifo_size = 1024; |
John Youn | 05ee799 | 2016-11-03 17:56:05 -0700 | [diff] [blame] | 320 | dwc2_set_param_tx_fifo_sizes(hsotg); |
| 321 | } |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 322 | } |
| 323 | |
John Youn | f9f93cb | 2017-01-23 14:55:35 -0800 | [diff] [blame] | 324 | /** |
| 325 | * dwc2_get_device_properties() - Read in device properties. |
| 326 | * |
| 327 | * Read in the device properties and adjust core parameters if needed. |
| 328 | */ |
| 329 | static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg) |
| 330 | { |
| 331 | struct dwc2_core_params *p = &hsotg->params; |
| 332 | int num; |
| 333 | |
| 334 | if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || |
| 335 | (hsotg->dr_mode == USB_DR_MODE_OTG)) { |
| 336 | device_property_read_u32(hsotg->dev, "g-rx-fifo-size", |
| 337 | &p->g_rx_fifo_size); |
| 338 | |
| 339 | device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size", |
| 340 | &p->g_np_tx_fifo_size); |
| 341 | |
| 342 | num = device_property_read_u32_array(hsotg->dev, |
| 343 | "g-tx-fifo-size", |
| 344 | NULL, 0); |
| 345 | |
| 346 | if (num > 0) { |
| 347 | num = min(num, 15); |
| 348 | memset(p->g_tx_fifo_size, 0, |
| 349 | sizeof(p->g_tx_fifo_size)); |
| 350 | device_property_read_u32_array(hsotg->dev, |
| 351 | "g-tx-fifo-size", |
| 352 | &p->g_tx_fifo_size[1], |
| 353 | num); |
| 354 | } |
| 355 | } |
Dinh Nguyen | b11633c | 2017-10-16 08:57:18 -0500 | [diff] [blame] | 356 | |
| 357 | if (of_find_property(hsotg->dev->of_node, "disable-over-current", NULL)) |
| 358 | p->oc_disable = true; |
John Youn | f9f93cb | 2017-01-23 14:55:35 -0800 | [diff] [blame] | 359 | } |
| 360 | |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 361 | static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg) |
| 362 | { |
| 363 | int valid = 1; |
| 364 | |
| 365 | switch (hsotg->params.otg_cap) { |
| 366 | case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: |
| 367 | if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) |
| 368 | valid = 0; |
| 369 | break; |
| 370 | case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: |
| 371 | switch (hsotg->hw_params.op_mode) { |
| 372 | case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: |
| 373 | case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: |
| 374 | case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: |
| 375 | case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: |
| 376 | break; |
| 377 | default: |
| 378 | valid = 0; |
| 379 | break; |
| 380 | } |
| 381 | break; |
| 382 | case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: |
| 383 | /* always valid */ |
| 384 | break; |
| 385 | default: |
| 386 | valid = 0; |
| 387 | break; |
| 388 | } |
| 389 | |
| 390 | if (!valid) |
| 391 | dwc2_set_param_otg_cap(hsotg); |
| 392 | } |
| 393 | |
| 394 | static void dwc2_check_param_phy_type(struct dwc2_hsotg *hsotg) |
| 395 | { |
| 396 | int valid = 0; |
| 397 | u32 hs_phy_type; |
| 398 | u32 fs_phy_type; |
| 399 | |
| 400 | hs_phy_type = hsotg->hw_params.hs_phy_type; |
| 401 | fs_phy_type = hsotg->hw_params.fs_phy_type; |
| 402 | |
| 403 | switch (hsotg->params.phy_type) { |
| 404 | case DWC2_PHY_TYPE_PARAM_FS: |
| 405 | if (fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) |
| 406 | valid = 1; |
| 407 | break; |
| 408 | case DWC2_PHY_TYPE_PARAM_UTMI: |
| 409 | if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) || |
| 410 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 411 | valid = 1; |
| 412 | break; |
| 413 | case DWC2_PHY_TYPE_PARAM_ULPI: |
| 414 | if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) || |
| 415 | (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) |
| 416 | valid = 1; |
| 417 | break; |
| 418 | default: |
| 419 | break; |
| 420 | } |
| 421 | |
| 422 | if (!valid) |
| 423 | dwc2_set_param_phy_type(hsotg); |
| 424 | } |
| 425 | |
| 426 | static void dwc2_check_param_speed(struct dwc2_hsotg *hsotg) |
| 427 | { |
| 428 | int valid = 1; |
| 429 | int phy_type = hsotg->params.phy_type; |
| 430 | int speed = hsotg->params.speed; |
| 431 | |
| 432 | switch (speed) { |
| 433 | case DWC2_SPEED_PARAM_HIGH: |
| 434 | if ((hsotg->params.speed == DWC2_SPEED_PARAM_HIGH) && |
| 435 | (phy_type == DWC2_PHY_TYPE_PARAM_FS)) |
| 436 | valid = 0; |
| 437 | break; |
| 438 | case DWC2_SPEED_PARAM_FULL: |
| 439 | case DWC2_SPEED_PARAM_LOW: |
| 440 | break; |
| 441 | default: |
| 442 | valid = 0; |
| 443 | break; |
| 444 | } |
| 445 | |
| 446 | if (!valid) |
| 447 | dwc2_set_param_speed(hsotg); |
| 448 | } |
| 449 | |
| 450 | static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg) |
| 451 | { |
| 452 | int valid = 0; |
| 453 | int param = hsotg->params.phy_utmi_width; |
| 454 | int width = hsotg->hw_params.utmi_phy_data_width; |
| 455 | |
| 456 | switch (width) { |
| 457 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: |
| 458 | valid = (param == 8); |
| 459 | break; |
| 460 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: |
| 461 | valid = (param == 16); |
| 462 | break; |
| 463 | case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: |
| 464 | valid = (param == 8 || param == 16); |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | if (!valid) |
| 469 | dwc2_set_param_phy_utmi_width(hsotg); |
| 470 | } |
| 471 | |
Vardan Mikayelyan | 631a231 | 2018-02-16 14:07:05 +0400 | [diff] [blame^] | 472 | static void dwc2_check_param_power_down(struct dwc2_hsotg *hsotg) |
| 473 | { |
| 474 | int param = hsotg->params.power_down; |
| 475 | |
| 476 | switch (param) { |
| 477 | case DWC2_POWER_DOWN_PARAM_NONE: |
| 478 | break; |
| 479 | case DWC2_POWER_DOWN_PARAM_PARTIAL: |
| 480 | if (hsotg->hw_params.power_optimized) |
| 481 | break; |
| 482 | dev_dbg(hsotg->dev, |
| 483 | "Partial power down isn't supported by HW\n"); |
| 484 | param = DWC2_POWER_DOWN_PARAM_NONE; |
| 485 | break; |
| 486 | case DWC2_POWER_DOWN_PARAM_HIBERNATION: |
| 487 | if (hsotg->hw_params.hibernation) |
| 488 | break; |
| 489 | dev_dbg(hsotg->dev, |
| 490 | "Hibernation isn't supported by HW\n"); |
| 491 | param = DWC2_POWER_DOWN_PARAM_NONE; |
| 492 | break; |
| 493 | default: |
| 494 | dev_err(hsotg->dev, |
| 495 | "%s: Invalid parameter power_down=%d\n", |
| 496 | __func__, param); |
| 497 | param = DWC2_POWER_DOWN_PARAM_NONE; |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | hsotg->params.power_down = param; |
| 502 | } |
| 503 | |
Sevak Arakelyan | 3c6aea7 | 2017-01-23 15:01:45 -0800 | [diff] [blame] | 504 | static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg) |
| 505 | { |
| 506 | int fifo_count; |
| 507 | int fifo; |
| 508 | int min; |
| 509 | u32 total = 0; |
| 510 | u32 dptxfszn; |
| 511 | |
| 512 | fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); |
| 513 | min = hsotg->hw_params.en_multiple_tx_fifo ? 16 : 4; |
| 514 | |
| 515 | for (fifo = 1; fifo <= fifo_count; fifo++) |
| 516 | total += hsotg->params.g_tx_fifo_size[fifo]; |
| 517 | |
| 518 | if (total > dwc2_hsotg_tx_fifo_total_depth(hsotg) || !total) { |
| 519 | dev_warn(hsotg->dev, "%s: Invalid parameter g-tx-fifo-size, setting to default average\n", |
| 520 | __func__); |
| 521 | dwc2_set_param_tx_fifo_sizes(hsotg); |
| 522 | } |
| 523 | |
| 524 | for (fifo = 1; fifo <= fifo_count; fifo++) { |
Minas Harutyunyan | 9273083 | 2017-11-30 12:16:37 +0400 | [diff] [blame] | 525 | dptxfszn = hsotg->hw_params.g_tx_fifo_size[fifo]; |
Sevak Arakelyan | 3c6aea7 | 2017-01-23 15:01:45 -0800 | [diff] [blame] | 526 | |
| 527 | if (hsotg->params.g_tx_fifo_size[fifo] < min || |
| 528 | hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) { |
| 529 | dev_warn(hsotg->dev, "%s: Invalid parameter g_tx_fifo_size[%d]=%d\n", |
| 530 | __func__, fifo, |
| 531 | hsotg->params.g_tx_fifo_size[fifo]); |
| 532 | hsotg->params.g_tx_fifo_size[fifo] = dptxfszn; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 537 | #define CHECK_RANGE(_param, _min, _max, _def) do { \ |
| 538 | if ((hsotg->params._param) < (_min) || \ |
| 539 | (hsotg->params._param) > (_max)) { \ |
| 540 | dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \ |
| 541 | __func__, #_param, hsotg->params._param); \ |
| 542 | hsotg->params._param = (_def); \ |
| 543 | } \ |
| 544 | } while (0) |
| 545 | |
| 546 | #define CHECK_BOOL(_param, _check) do { \ |
| 547 | if (hsotg->params._param && !(_check)) { \ |
| 548 | dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \ |
| 549 | __func__, #_param, hsotg->params._param); \ |
| 550 | hsotg->params._param = false; \ |
| 551 | } \ |
| 552 | } while (0) |
| 553 | |
| 554 | static void dwc2_check_params(struct dwc2_hsotg *hsotg) |
| 555 | { |
| 556 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 557 | struct dwc2_core_params *p = &hsotg->params; |
| 558 | bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH); |
| 559 | |
| 560 | dwc2_check_param_otg_cap(hsotg); |
| 561 | dwc2_check_param_phy_type(hsotg); |
| 562 | dwc2_check_param_speed(hsotg); |
| 563 | dwc2_check_param_phy_utmi_width(hsotg); |
Vardan Mikayelyan | 631a231 | 2018-02-16 14:07:05 +0400 | [diff] [blame^] | 564 | dwc2_check_param_power_down(hsotg); |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 565 | CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo); |
| 566 | CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo); |
| 567 | CHECK_BOOL(i2c_enable, hw->i2c_enable); |
Razmik Karapetyan | 66e77a2 | 2018-01-24 17:40:29 +0400 | [diff] [blame] | 568 | CHECK_BOOL(acg_enable, hw->acg_enable); |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 569 | CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a)); |
Sevak Arakelyan | 6f80b6d | 2018-01-24 17:41:48 +0400 | [diff] [blame] | 570 | CHECK_BOOL(lpm, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_80a)); |
| 571 | CHECK_BOOL(lpm, hw->lpm_mode); |
| 572 | CHECK_BOOL(lpm_clock_gating, hsotg->params.lpm); |
| 573 | CHECK_BOOL(besl, hsotg->params.lpm); |
| 574 | CHECK_BOOL(besl, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a)); |
| 575 | CHECK_BOOL(hird_threshold_en, hsotg->params.lpm); |
| 576 | CHECK_RANGE(hird_threshold, 0, hsotg->params.besl ? 12 : 7, 0); |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 577 | CHECK_RANGE(max_packet_count, |
| 578 | 15, hw->max_packet_count, |
| 579 | hw->max_packet_count); |
| 580 | CHECK_RANGE(max_transfer_size, |
| 581 | 2047, hw->max_transfer_size, |
| 582 | hw->max_transfer_size); |
| 583 | |
| 584 | if ((hsotg->dr_mode == USB_DR_MODE_HOST) || |
| 585 | (hsotg->dr_mode == USB_DR_MODE_OTG)) { |
| 586 | CHECK_BOOL(host_dma, dma_capable); |
| 587 | CHECK_BOOL(dma_desc_enable, p->host_dma); |
| 588 | CHECK_BOOL(dma_desc_fs_enable, p->dma_desc_enable); |
| 589 | CHECK_BOOL(host_ls_low_power_phy_clk, |
| 590 | p->phy_type == DWC2_PHY_TYPE_PARAM_FS); |
| 591 | CHECK_RANGE(host_channels, |
| 592 | 1, hw->host_channels, |
| 593 | hw->host_channels); |
| 594 | CHECK_RANGE(host_rx_fifo_size, |
| 595 | 16, hw->rx_fifo_size, |
| 596 | hw->rx_fifo_size); |
| 597 | CHECK_RANGE(host_nperio_tx_fifo_size, |
| 598 | 16, hw->host_nperio_tx_fifo_size, |
| 599 | hw->host_nperio_tx_fifo_size); |
| 600 | CHECK_RANGE(host_perio_tx_fifo_size, |
| 601 | 16, hw->host_perio_tx_fifo_size, |
| 602 | hw->host_perio_tx_fifo_size); |
| 603 | } |
| 604 | |
| 605 | if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || |
| 606 | (hsotg->dr_mode == USB_DR_MODE_OTG)) { |
| 607 | CHECK_BOOL(g_dma, dma_capable); |
| 608 | CHECK_BOOL(g_dma_desc, (p->g_dma && hw->dma_desc_enable)); |
| 609 | CHECK_RANGE(g_rx_fifo_size, |
| 610 | 16, hw->rx_fifo_size, |
| 611 | hw->rx_fifo_size); |
| 612 | CHECK_RANGE(g_np_tx_fifo_size, |
| 613 | 16, hw->dev_nperio_tx_fifo_size, |
| 614 | hw->dev_nperio_tx_fifo_size); |
Sevak Arakelyan | 3c6aea7 | 2017-01-23 15:01:45 -0800 | [diff] [blame] | 615 | dwc2_check_param_tx_fifo_sizes(hsotg); |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 619 | /* |
| 620 | * Gets host hardware parameters. Forces host mode if not currently in |
| 621 | * host mode. Should be called immediately after a core soft reset in |
| 622 | * order to get the reset values. |
| 623 | */ |
| 624 | static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) |
| 625 | { |
| 626 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 627 | u32 gnptxfsiz; |
| 628 | u32 hptxfsiz; |
| 629 | bool forced; |
| 630 | |
| 631 | if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) |
| 632 | return; |
| 633 | |
| 634 | forced = dwc2_force_mode_if_needed(hsotg, true); |
| 635 | |
| 636 | gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
| 637 | hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 638 | |
| 639 | if (forced) |
| 640 | dwc2_clear_force_mode(hsotg); |
| 641 | |
| 642 | hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 643 | FIFOSIZE_DEPTH_SHIFT; |
| 644 | hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 645 | FIFOSIZE_DEPTH_SHIFT; |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * Gets device hardware parameters. Forces device mode if not |
| 650 | * currently in device mode. Should be called immediately after a core |
| 651 | * soft reset in order to get the reset values. |
| 652 | */ |
| 653 | static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) |
| 654 | { |
| 655 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 656 | bool forced; |
| 657 | u32 gnptxfsiz; |
Minas Harutyunyan | 9273083 | 2017-11-30 12:16:37 +0400 | [diff] [blame] | 658 | int fifo, fifo_count; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 659 | |
| 660 | if (hsotg->dr_mode == USB_DR_MODE_HOST) |
| 661 | return; |
| 662 | |
| 663 | forced = dwc2_force_mode_if_needed(hsotg, false); |
| 664 | |
| 665 | gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 666 | |
Minas Harutyunyan | 9273083 | 2017-11-30 12:16:37 +0400 | [diff] [blame] | 667 | fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); |
| 668 | |
| 669 | for (fifo = 1; fifo <= fifo_count; fifo++) { |
| 670 | hw->g_tx_fifo_size[fifo] = |
| 671 | (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) & |
| 672 | FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT; |
| 673 | } |
| 674 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 675 | if (forced) |
| 676 | dwc2_clear_force_mode(hsotg); |
| 677 | |
| 678 | hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> |
| 679 | FIFOSIZE_DEPTH_SHIFT; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * During device initialization, read various hardware configuration |
| 684 | * registers and interpret the contents. |
| 685 | */ |
| 686 | int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) |
| 687 | { |
| 688 | struct dwc2_hw_params *hw = &hsotg->hw_params; |
| 689 | unsigned int width; |
| 690 | u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; |
| 691 | u32 grxfsiz; |
| 692 | |
| 693 | /* |
| 694 | * Attempt to ensure this device is really a DWC_otg Controller. |
| 695 | * Read and verify the GSNPSID register contents. The value should be |
Gevorg Sahakyan | d14ccab | 2018-01-16 16:21:46 +0400 | [diff] [blame] | 696 | * 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 697 | */ |
Gevorg Sahakyan | d14ccab | 2018-01-16 16:21:46 +0400 | [diff] [blame] | 698 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 699 | hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); |
Gevorg Sahakyan | d14ccab | 2018-01-16 16:21:46 +0400 | [diff] [blame] | 700 | if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID && |
| 701 | (hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID && |
| 702 | (hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) { |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 703 | dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", |
| 704 | hw->snpsid); |
| 705 | return -ENODEV; |
| 706 | } |
| 707 | |
| 708 | dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", |
| 709 | hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, |
| 710 | hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); |
| 711 | |
| 712 | hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); |
| 713 | hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); |
| 714 | hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); |
| 715 | hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); |
| 716 | grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); |
| 717 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 718 | /* hwcfg1 */ |
| 719 | hw->dev_ep_dirs = hwcfg1; |
| 720 | |
| 721 | /* hwcfg2 */ |
| 722 | hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> |
| 723 | GHWCFG2_OP_MODE_SHIFT; |
| 724 | hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> |
| 725 | GHWCFG2_ARCHITECTURE_SHIFT; |
| 726 | hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); |
| 727 | hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> |
| 728 | GHWCFG2_NUM_HOST_CHAN_SHIFT); |
| 729 | hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> |
| 730 | GHWCFG2_HS_PHY_TYPE_SHIFT; |
| 731 | hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> |
| 732 | GHWCFG2_FS_PHY_TYPE_SHIFT; |
| 733 | hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> |
| 734 | GHWCFG2_NUM_DEV_EP_SHIFT; |
| 735 | hw->nperio_tx_q_depth = |
| 736 | (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> |
| 737 | GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; |
| 738 | hw->host_perio_tx_q_depth = |
| 739 | (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> |
| 740 | GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; |
| 741 | hw->dev_token_q_depth = |
| 742 | (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> |
| 743 | GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; |
| 744 | |
| 745 | /* hwcfg3 */ |
| 746 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> |
| 747 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; |
| 748 | hw->max_transfer_size = (1 << (width + 11)) - 1; |
| 749 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> |
| 750 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; |
| 751 | hw->max_packet_count = (1 << (width + 4)) - 1; |
| 752 | hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); |
| 753 | hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> |
| 754 | GHWCFG3_DFIFO_DEPTH_SHIFT; |
Sevak Arakelyan | 6f80b6d | 2018-01-24 17:41:48 +0400 | [diff] [blame] | 755 | hw->lpm_mode = !!(hwcfg3 & GHWCFG3_OTG_LPM_EN); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 756 | |
| 757 | /* hwcfg4 */ |
| 758 | hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); |
| 759 | hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> |
| 760 | GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; |
Minas Harutyunyan | 9273083 | 2017-11-30 12:16:37 +0400 | [diff] [blame] | 761 | hw->num_dev_in_eps = (hwcfg4 & GHWCFG4_NUM_IN_EPS_MASK) >> |
| 762 | GHWCFG4_NUM_IN_EPS_SHIFT; |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 763 | hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); |
| 764 | hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); |
Vardan Mikayelyan | 631a231 | 2018-02-16 14:07:05 +0400 | [diff] [blame^] | 765 | hw->hibernation = !!(hwcfg4 & GHWCFG4_HIBER); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 766 | hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> |
| 767 | GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; |
Razmik Karapetyan | 66e77a2 | 2018-01-24 17:40:29 +0400 | [diff] [blame] | 768 | hw->acg_enable = !!(hwcfg4 & GHWCFG4_ACG_SUPPORTED); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 769 | |
| 770 | /* fifo sizes */ |
John Youn | d153131 | 2016-11-03 17:56:02 -0700 | [diff] [blame] | 771 | hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 772 | GRXFSIZ_DEPTH_SHIFT; |
Minas Harutyunyan | 9273083 | 2017-11-30 12:16:37 +0400 | [diff] [blame] | 773 | /* |
| 774 | * Host specific hardware parameters. Reading these parameters |
| 775 | * requires the controller to be in host mode. The mode will |
| 776 | * be forced, if necessary, to read these values. |
| 777 | */ |
| 778 | dwc2_get_host_hwparams(hsotg); |
| 779 | dwc2_get_dev_hwparams(hsotg); |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 780 | |
John Youn | 323230e | 2016-11-03 17:55:50 -0700 | [diff] [blame] | 781 | return 0; |
| 782 | } |
| 783 | |
John Youn | 334bbd4 | 2016-11-03 17:55:55 -0700 | [diff] [blame] | 784 | int dwc2_init_params(struct dwc2_hsotg *hsotg) |
| 785 | { |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 786 | const struct of_device_id *match; |
| 787 | void (*set_params)(void *data); |
| 788 | |
John Youn | 245977c | 2017-01-23 14:55:14 -0800 | [diff] [blame] | 789 | dwc2_set_default_params(hsotg); |
John Youn | f9f93cb | 2017-01-23 14:55:35 -0800 | [diff] [blame] | 790 | dwc2_get_device_properties(hsotg); |
John Youn | 334bbd4 | 2016-11-03 17:55:55 -0700 | [diff] [blame] | 791 | |
John Youn | 7de1deb | 2017-01-23 14:57:04 -0800 | [diff] [blame] | 792 | match = of_match_device(dwc2_of_match_table, hsotg->dev); |
| 793 | if (match && match->data) { |
| 794 | set_params = match->data; |
| 795 | set_params(hsotg); |
| 796 | } |
| 797 | |
John Youn | d936e66 | 2017-01-23 14:56:43 -0800 | [diff] [blame] | 798 | dwc2_check_params(hsotg); |
| 799 | |
John Youn | 334bbd4 | 2016-11-03 17:55:55 -0700 | [diff] [blame] | 800 | return 0; |
| 801 | } |