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