blob: 442113246cba6d2c9a791876087c7f715068edc9 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
John Youn323230e2016-11-03 17:55:50 -07002/*
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 Youn7de1deb2017-01-23 14:57:04 -080042static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg)
43{
44 struct dwc2_core_params *p = &hsotg->params;
John Youn323230e2016-11-03 17:55:50 -070045
John Youn7de1deb2017-01-23 14:57:04 -080046 p->host_rx_fifo_size = 774;
John Youn7de1deb2017-01-23 14:57:04 -080047 p->max_transfer_size = 65535;
48 p->max_packet_count = 511;
John Youn7de1deb2017-01-23 14:57:04 -080049 p->ahbcfg = 0x10;
John Youn7de1deb2017-01-23 14:57:04 -080050}
John Youn323230e2016-11-03 17:55:50 -070051
John Youn7de1deb2017-01-23 14:57:04 -080052static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
53{
54 struct dwc2_core_params *p = &hsotg->params;
John Youn323230e2016-11-03 17:55:50 -070055
John Youn7de1deb2017-01-23 14:57:04 -080056 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 Youn7de1deb2017-01-23 14:57:04 -080067 p->reload_ctl = false;
68 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
69 GAHBCFG_HBSTLEN_SHIFT;
Chen Yuca8b0332017-01-23 15:00:18 -080070 p->change_speed_quirk = true;
John Stultzd98c6242018-05-18 17:49:03 -070071 p->power_down = false;
John Youn7de1deb2017-01-23 14:57:04 -080072}
John Youn323230e2016-11-03 17:55:50 -070073
Marek Szyprowski35a60542018-11-20 16:38:15 +010074static 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 Youn7de1deb2017-01-23 14:57:04 -080081static 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;
SolidHalc2167652018-10-02 20:58:16 -050091 p->power_down = 0;
John Youn7de1deb2017-01-23 14:57:04 -080092}
93
94static 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
108static 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;
Martin Blumenstinglcc10ce02018-12-09 20:01:29 +0100121 p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
John Youn7de1deb2017-01-23 14:57:04 -0800122}
123
Neil Armstrongfc4e3262019-04-23 10:51:26 +0200124static void dwc2_set_amlogic_g12a_params(struct dwc2_hsotg *hsotg)
125{
126 struct dwc2_core_params *p = &hsotg->params;
127
128 p->lpm = false;
129 p->lpm_clock_gating = false;
130 p->besl = false;
131 p->hird_threshold_en = false;
132}
133
John Youn7de1deb2017-01-23 14:57:04 -0800134static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg)
135{
136 struct dwc2_core_params *p = &hsotg->params;
137
138 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
139}
John Youn323230e2016-11-03 17:55:50 -0700140
Bruno Herrerae35b1352017-01-31 23:25:43 -0200141static void dwc2_set_stm32f4x9_fsotg_params(struct dwc2_hsotg *hsotg)
142{
143 struct dwc2_core_params *p = &hsotg->params;
144
145 p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
146 p->speed = DWC2_SPEED_PARAM_FULL;
147 p->host_rx_fifo_size = 128;
148 p->host_nperio_tx_fifo_size = 96;
149 p->host_perio_tx_fifo_size = 96;
150 p->max_packet_count = 256;
151 p->phy_type = DWC2_PHY_TYPE_PARAM_FS;
152 p->i2c_enable = false;
Bruno Herrerae35b1352017-01-31 23:25:43 -0200153 p->activate_stm_fs_transceiver = true;
154}
155
Amelie Delaunay1a149e32018-03-01 11:05:35 +0100156static void dwc2_set_stm32f7_hsotg_params(struct dwc2_hsotg *hsotg)
Amelie Delaunayd8fae8b2017-08-17 11:33:01 +0200157{
158 struct dwc2_core_params *p = &hsotg->params;
159
160 p->host_rx_fifo_size = 622;
161 p->host_nperio_tx_fifo_size = 128;
162 p->host_perio_tx_fifo_size = 256;
163}
164
John Youn323230e2016-11-03 17:55:50 -0700165const struct of_device_id dwc2_of_match_table[] = {
John Youn7de1deb2017-01-23 14:57:04 -0800166 { .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params },
167 { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params },
168 { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params },
169 { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params },
170 { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params },
171 { .compatible = "snps,dwc2" },
Marek Szyprowski35a60542018-11-20 16:38:15 +0100172 { .compatible = "samsung,s3c6400-hsotg",
173 .data = dwc2_set_s3c6400_params },
Martin Blumenstingl55b644f2017-05-06 19:37:45 +0200174 { .compatible = "amlogic,meson8-usb",
175 .data = dwc2_set_amlogic_params },
John Youn7de1deb2017-01-23 14:57:04 -0800176 { .compatible = "amlogic,meson8b-usb",
177 .data = dwc2_set_amlogic_params },
178 { .compatible = "amlogic,meson-gxbb-usb",
179 .data = dwc2_set_amlogic_params },
Neil Armstrongfc4e3262019-04-23 10:51:26 +0200180 { .compatible = "amlogic,meson-g12a-usb",
181 .data = dwc2_set_amlogic_g12a_params },
John Youn7de1deb2017-01-23 14:57:04 -0800182 { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params },
Bruno Herrerae35b1352017-01-31 23:25:43 -0200183 { .compatible = "st,stm32f4x9-fsotg",
184 .data = dwc2_set_stm32f4x9_fsotg_params },
185 { .compatible = "st,stm32f4x9-hsotg" },
Amelie Delaunay1a149e32018-03-01 11:05:35 +0100186 { .compatible = "st,stm32f7-hsotg",
187 .data = dwc2_set_stm32f7_hsotg_params },
John Youn323230e2016-11-03 17:55:50 -0700188 {},
189};
190MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
191
John Youn245977c2017-01-23 14:55:14 -0800192static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg)
John Youn05ee7992016-11-03 17:56:05 -0700193{
John Youn245977c2017-01-23 14:55:14 -0800194 u8 val;
John Youn05ee7992016-11-03 17:56:05 -0700195
John Youn245977c2017-01-23 14:55:14 -0800196 switch (hsotg->hw_params.op_mode) {
197 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
198 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
John Youn05ee7992016-11-03 17:56:05 -0700199 break;
John Youn245977c2017-01-23 14:55:14 -0800200 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
201 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
202 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
203 val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
John Youn05ee7992016-11-03 17:56:05 -0700204 break;
205 default:
John Youn245977c2017-01-23 14:55:14 -0800206 val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
John Youn05ee7992016-11-03 17:56:05 -0700207 break;
John Youn323230e2016-11-03 17:55:50 -0700208 }
209
John Younbea8e862016-11-03 17:55:53 -0700210 hsotg->params.otg_cap = val;
John Youn323230e2016-11-03 17:55:50 -0700211}
212
John Youn245977c2017-01-23 14:55:14 -0800213static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg)
John Youn323230e2016-11-03 17:55:50 -0700214{
John Youn245977c2017-01-23 14:55:14 -0800215 int val;
216 u32 hs_phy_type = hsotg->hw_params.hs_phy_type;
John Youn323230e2016-11-03 17:55:50 -0700217
John Youn245977c2017-01-23 14:55:14 -0800218 val = DWC2_PHY_TYPE_PARAM_FS;
219 if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
220 if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
221 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
222 val = DWC2_PHY_TYPE_PARAM_UTMI;
223 else
224 val = DWC2_PHY_TYPE_PARAM_ULPI;
John Youn323230e2016-11-03 17:55:50 -0700225 }
226
John Youn245977c2017-01-23 14:55:14 -0800227 if (dwc2_is_fs_iot(hsotg))
228 hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS;
John Youn323230e2016-11-03 17:55:50 -0700229
John Younbea8e862016-11-03 17:55:53 -0700230 hsotg->params.phy_type = val;
John Youn323230e2016-11-03 17:55:50 -0700231}
232
John Youn245977c2017-01-23 14:55:14 -0800233static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg)
John Youn323230e2016-11-03 17:55:50 -0700234{
John Youn245977c2017-01-23 14:55:14 -0800235 int val;
John Youn323230e2016-11-03 17:55:50 -0700236
John Youn245977c2017-01-23 14:55:14 -0800237 val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ?
238 DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
John Youn323230e2016-11-03 17:55:50 -0700239
John Youn245977c2017-01-23 14:55:14 -0800240 if (dwc2_is_fs_iot(hsotg))
241 val = DWC2_SPEED_PARAM_FULL;
John Youn323230e2016-11-03 17:55:50 -0700242
John Youn245977c2017-01-23 14:55:14 -0800243 if (dwc2_is_hs_iot(hsotg))
244 val = DWC2_SPEED_PARAM_HIGH;
John Youn323230e2016-11-03 17:55:50 -0700245
John Younbea8e862016-11-03 17:55:53 -0700246 hsotg->params.speed = val;
John Youn323230e2016-11-03 17:55:50 -0700247}
248
John Youn245977c2017-01-23 14:55:14 -0800249static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
John Youn323230e2016-11-03 17:55:50 -0700250{
John Youn245977c2017-01-23 14:55:14 -0800251 int val;
John Youn323230e2016-11-03 17:55:50 -0700252
John Youn245977c2017-01-23 14:55:14 -0800253 val = (hsotg->hw_params.utmi_phy_data_width ==
254 GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
John Youn323230e2016-11-03 17:55:50 -0700255
John Younbea8e862016-11-03 17:55:53 -0700256 hsotg->params.phy_utmi_width = val;
John Youn323230e2016-11-03 17:55:50 -0700257}
258
John Youn05ee7992016-11-03 17:56:05 -0700259static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
260{
John Youn05ee7992016-11-03 17:56:05 -0700261 struct dwc2_core_params *p = &hsotg->params;
Sevak Arakelyanc138ecf2017-01-23 15:01:23 -0800262 int depth_average;
263 int fifo_count;
264 int i;
265
266 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
John Youn05ee7992016-11-03 17:56:05 -0700267
268 memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
Sevak Arakelyanc138ecf2017-01-23 15:01:23 -0800269 depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg);
270 for (i = 1; i <= fifo_count; i++)
271 p->g_tx_fifo_size[i] = depth_average;
John Youn9962b622016-11-09 19:27:40 -0800272}
273
John Youn03ea6d62018-02-16 14:12:28 +0400274static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
275{
276 int val;
277
278 if (hsotg->hw_params.hibernation)
279 val = 2;
280 else if (hsotg->hw_params.power_optimized)
281 val = 1;
282 else
283 val = 0;
284
285 hsotg->params.power_down = val;
286}
287
John Youn05ee7992016-11-03 17:56:05 -0700288/**
John Youn245977c2017-01-23 14:55:14 -0800289 * dwc2_set_default_params() - Set all core parameters to their
290 * auto-detected default values.
Grigor Tovmasyan6fb914d2018-05-16 12:04:24 +0400291 *
292 * @hsotg: Programming view of the DWC_otg controller
293 *
John Youn323230e2016-11-03 17:55:50 -0700294 */
John Youn245977c2017-01-23 14:55:14 -0800295static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
John Youn323230e2016-11-03 17:55:50 -0700296{
John Youn05ee7992016-11-03 17:56:05 -0700297 struct dwc2_hw_params *hw = &hsotg->hw_params;
298 struct dwc2_core_params *p = &hsotg->params;
John Youn6b66ce52016-11-03 17:56:12 -0700299 bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
John Youn323230e2016-11-03 17:55:50 -0700300
John Youn245977c2017-01-23 14:55:14 -0800301 dwc2_set_param_otg_cap(hsotg);
302 dwc2_set_param_phy_type(hsotg);
303 dwc2_set_param_speed(hsotg);
304 dwc2_set_param_phy_utmi_width(hsotg);
John Youn03ea6d62018-02-16 14:12:28 +0400305 dwc2_set_param_power_down(hsotg);
John Youn245977c2017-01-23 14:55:14 -0800306 p->phy_ulpi_ddr = false;
307 p->phy_ulpi_ext_vbus = false;
308
309 p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
310 p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
311 p->i2c_enable = hw->i2c_enable;
Razmik Karapetyan66e77a22018-01-24 17:40:29 +0400312 p->acg_enable = hw->acg_enable;
John Youn245977c2017-01-23 14:55:14 -0800313 p->ulpi_fs_ls = false;
314 p->ts_dline = false;
315 p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
316 p->uframe_sched = true;
317 p->external_id_pin_ctl = false;
Sevak Arakelyan6f80b6d2018-01-24 17:41:48 +0400318 p->lpm = true;
319 p->lpm_clock_gating = true;
320 p->besl = true;
321 p->hird_threshold_en = true;
322 p->hird_threshold = 4;
Grigor Tovmasyanb43ebc92018-05-05 12:17:58 +0400323 p->ipg_isoc_en = false;
Grigor Tovmasyanca531bc2018-08-29 20:59:34 +0400324 p->service_interval = false;
John Youn245977c2017-01-23 14:55:14 -0800325 p->max_packet_count = hw->max_packet_count;
326 p->max_transfer_size = hw->max_transfer_size;
Razmik Karapetyan1b52d2f2018-01-19 14:40:23 +0400327 p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT;
Grigor Tovmasyanf3a61e42018-08-29 21:01:31 +0400328 p->ref_clk_per = 33333;
329 p->sof_cnt_wkup_alert = 100;
John Youn245977c2017-01-23 14:55:14 -0800330
John Youn6b66ce52016-11-03 17:56:12 -0700331 if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
332 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
John Youn245977c2017-01-23 14:55:14 -0800333 p->host_dma = dma_capable;
334 p->dma_desc_enable = false;
335 p->dma_desc_fs_enable = false;
336 p->host_support_fs_ls_low_power = false;
337 p->host_ls_low_power_phy_clk = false;
338 p->host_channels = hw->host_channels;
339 p->host_rx_fifo_size = hw->rx_fifo_size;
340 p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size;
341 p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size;
John Youn6b66ce52016-11-03 17:56:12 -0700342 }
343
John Youn05ee7992016-11-03 17:56:05 -0700344 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
345 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
John Youn245977c2017-01-23 14:55:14 -0800346 p->g_dma = dma_capable;
347 p->g_dma_desc = hw->dma_desc_enable;
John Youn05ee7992016-11-03 17:56:05 -0700348
349 /*
350 * The values for g_rx_fifo_size (2048) and
351 * g_np_tx_fifo_size (1024) come from the legacy s3c
352 * gadget driver. These defaults have been hard-coded
353 * for some time so many platforms depend on these
354 * values. Leave them as defaults for now and only
355 * auto-detect if the hardware does not support the
356 * default.
357 */
John Youn245977c2017-01-23 14:55:14 -0800358 p->g_rx_fifo_size = 2048;
359 p->g_np_tx_fifo_size = 1024;
John Youn05ee7992016-11-03 17:56:05 -0700360 dwc2_set_param_tx_fifo_sizes(hsotg);
361 }
John Youn323230e2016-11-03 17:55:50 -0700362}
363
John Younf9f93cb2017-01-23 14:55:35 -0800364/**
365 * dwc2_get_device_properties() - Read in device properties.
366 *
Grigor Tovmasyan6fb914d2018-05-16 12:04:24 +0400367 * @hsotg: Programming view of the DWC_otg controller
368 *
John Younf9f93cb2017-01-23 14:55:35 -0800369 * Read in the device properties and adjust core parameters if needed.
370 */
371static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
372{
373 struct dwc2_core_params *p = &hsotg->params;
374 int num;
375
376 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
377 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
378 device_property_read_u32(hsotg->dev, "g-rx-fifo-size",
379 &p->g_rx_fifo_size);
380
381 device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size",
382 &p->g_np_tx_fifo_size);
383
384 num = device_property_read_u32_array(hsotg->dev,
385 "g-tx-fifo-size",
386 NULL, 0);
387
388 if (num > 0) {
389 num = min(num, 15);
390 memset(p->g_tx_fifo_size, 0,
391 sizeof(p->g_tx_fifo_size));
392 device_property_read_u32_array(hsotg->dev,
393 "g-tx-fifo-size",
394 &p->g_tx_fifo_size[1],
395 num);
396 }
397 }
Dinh Nguyenb11633c2017-10-16 08:57:18 -0500398
399 if (of_find_property(hsotg->dev->of_node, "disable-over-current", NULL))
400 p->oc_disable = true;
John Younf9f93cb2017-01-23 14:55:35 -0800401}
402
John Yound936e662017-01-23 14:56:43 -0800403static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
404{
405 int valid = 1;
406
407 switch (hsotg->params.otg_cap) {
408 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
409 if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
410 valid = 0;
411 break;
412 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
413 switch (hsotg->hw_params.op_mode) {
414 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
415 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
416 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
417 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
418 break;
419 default:
420 valid = 0;
421 break;
422 }
423 break;
424 case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
425 /* always valid */
426 break;
427 default:
428 valid = 0;
429 break;
430 }
431
432 if (!valid)
433 dwc2_set_param_otg_cap(hsotg);
434}
435
436static void dwc2_check_param_phy_type(struct dwc2_hsotg *hsotg)
437{
438 int valid = 0;
439 u32 hs_phy_type;
440 u32 fs_phy_type;
441
442 hs_phy_type = hsotg->hw_params.hs_phy_type;
443 fs_phy_type = hsotg->hw_params.fs_phy_type;
444
445 switch (hsotg->params.phy_type) {
446 case DWC2_PHY_TYPE_PARAM_FS:
447 if (fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
448 valid = 1;
449 break;
450 case DWC2_PHY_TYPE_PARAM_UTMI:
451 if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
452 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
453 valid = 1;
454 break;
455 case DWC2_PHY_TYPE_PARAM_ULPI:
456 if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
457 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
458 valid = 1;
459 break;
460 default:
461 break;
462 }
463
464 if (!valid)
465 dwc2_set_param_phy_type(hsotg);
466}
467
468static void dwc2_check_param_speed(struct dwc2_hsotg *hsotg)
469{
470 int valid = 1;
471 int phy_type = hsotg->params.phy_type;
472 int speed = hsotg->params.speed;
473
474 switch (speed) {
475 case DWC2_SPEED_PARAM_HIGH:
476 if ((hsotg->params.speed == DWC2_SPEED_PARAM_HIGH) &&
477 (phy_type == DWC2_PHY_TYPE_PARAM_FS))
478 valid = 0;
479 break;
480 case DWC2_SPEED_PARAM_FULL:
481 case DWC2_SPEED_PARAM_LOW:
482 break;
483 default:
484 valid = 0;
485 break;
486 }
487
488 if (!valid)
489 dwc2_set_param_speed(hsotg);
490}
491
492static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
493{
494 int valid = 0;
495 int param = hsotg->params.phy_utmi_width;
496 int width = hsotg->hw_params.utmi_phy_data_width;
497
498 switch (width) {
499 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
500 valid = (param == 8);
501 break;
502 case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
503 valid = (param == 16);
504 break;
505 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
506 valid = (param == 8 || param == 16);
507 break;
508 }
509
510 if (!valid)
511 dwc2_set_param_phy_utmi_width(hsotg);
512}
513
Vardan Mikayelyan631a2312018-02-16 14:07:05 +0400514static void dwc2_check_param_power_down(struct dwc2_hsotg *hsotg)
515{
516 int param = hsotg->params.power_down;
517
518 switch (param) {
519 case DWC2_POWER_DOWN_PARAM_NONE:
520 break;
521 case DWC2_POWER_DOWN_PARAM_PARTIAL:
522 if (hsotg->hw_params.power_optimized)
523 break;
524 dev_dbg(hsotg->dev,
525 "Partial power down isn't supported by HW\n");
526 param = DWC2_POWER_DOWN_PARAM_NONE;
527 break;
528 case DWC2_POWER_DOWN_PARAM_HIBERNATION:
529 if (hsotg->hw_params.hibernation)
530 break;
531 dev_dbg(hsotg->dev,
532 "Hibernation isn't supported by HW\n");
533 param = DWC2_POWER_DOWN_PARAM_NONE;
534 break;
535 default:
536 dev_err(hsotg->dev,
537 "%s: Invalid parameter power_down=%d\n",
538 __func__, param);
539 param = DWC2_POWER_DOWN_PARAM_NONE;
540 break;
541 }
542
543 hsotg->params.power_down = param;
544}
545
Sevak Arakelyan3c6aea72017-01-23 15:01:45 -0800546static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
547{
548 int fifo_count;
549 int fifo;
550 int min;
551 u32 total = 0;
552 u32 dptxfszn;
553
554 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
555 min = hsotg->hw_params.en_multiple_tx_fifo ? 16 : 4;
556
557 for (fifo = 1; fifo <= fifo_count; fifo++)
558 total += hsotg->params.g_tx_fifo_size[fifo];
559
560 if (total > dwc2_hsotg_tx_fifo_total_depth(hsotg) || !total) {
561 dev_warn(hsotg->dev, "%s: Invalid parameter g-tx-fifo-size, setting to default average\n",
562 __func__);
563 dwc2_set_param_tx_fifo_sizes(hsotg);
564 }
565
566 for (fifo = 1; fifo <= fifo_count; fifo++) {
Minas Harutyunyan92730832017-11-30 12:16:37 +0400567 dptxfszn = hsotg->hw_params.g_tx_fifo_size[fifo];
Sevak Arakelyan3c6aea72017-01-23 15:01:45 -0800568
569 if (hsotg->params.g_tx_fifo_size[fifo] < min ||
570 hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) {
571 dev_warn(hsotg->dev, "%s: Invalid parameter g_tx_fifo_size[%d]=%d\n",
572 __func__, fifo,
573 hsotg->params.g_tx_fifo_size[fifo]);
574 hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
575 }
576 }
577}
578
John Yound936e662017-01-23 14:56:43 -0800579#define CHECK_RANGE(_param, _min, _max, _def) do { \
Grigor Tovmasyan47265c02018-04-03 15:22:25 +0400580 if ((int)(hsotg->params._param) < (_min) || \
John Yound936e662017-01-23 14:56:43 -0800581 (hsotg->params._param) > (_max)) { \
582 dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
583 __func__, #_param, hsotg->params._param); \
584 hsotg->params._param = (_def); \
585 } \
586 } while (0)
587
588#define CHECK_BOOL(_param, _check) do { \
589 if (hsotg->params._param && !(_check)) { \
590 dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
591 __func__, #_param, hsotg->params._param); \
592 hsotg->params._param = false; \
593 } \
594 } while (0)
595
596static void dwc2_check_params(struct dwc2_hsotg *hsotg)
597{
598 struct dwc2_hw_params *hw = &hsotg->hw_params;
599 struct dwc2_core_params *p = &hsotg->params;
600 bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
601
602 dwc2_check_param_otg_cap(hsotg);
603 dwc2_check_param_phy_type(hsotg);
604 dwc2_check_param_speed(hsotg);
605 dwc2_check_param_phy_utmi_width(hsotg);
Vardan Mikayelyan631a2312018-02-16 14:07:05 +0400606 dwc2_check_param_power_down(hsotg);
John Yound936e662017-01-23 14:56:43 -0800607 CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo);
608 CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo);
609 CHECK_BOOL(i2c_enable, hw->i2c_enable);
Grigor Tovmasyanb43ebc92018-05-05 12:17:58 +0400610 CHECK_BOOL(ipg_isoc_en, hw->ipg_isoc_en);
Razmik Karapetyan66e77a22018-01-24 17:40:29 +0400611 CHECK_BOOL(acg_enable, hw->acg_enable);
John Yound936e662017-01-23 14:56:43 -0800612 CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a));
Sevak Arakelyan6f80b6d2018-01-24 17:41:48 +0400613 CHECK_BOOL(lpm, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_80a));
614 CHECK_BOOL(lpm, hw->lpm_mode);
615 CHECK_BOOL(lpm_clock_gating, hsotg->params.lpm);
616 CHECK_BOOL(besl, hsotg->params.lpm);
617 CHECK_BOOL(besl, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a));
618 CHECK_BOOL(hird_threshold_en, hsotg->params.lpm);
619 CHECK_RANGE(hird_threshold, 0, hsotg->params.besl ? 12 : 7, 0);
Grigor Tovmasyanca531bc2018-08-29 20:59:34 +0400620 CHECK_BOOL(service_interval, hw->service_interval_mode);
John Yound936e662017-01-23 14:56:43 -0800621 CHECK_RANGE(max_packet_count,
622 15, hw->max_packet_count,
623 hw->max_packet_count);
624 CHECK_RANGE(max_transfer_size,
625 2047, hw->max_transfer_size,
626 hw->max_transfer_size);
627
628 if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
629 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
630 CHECK_BOOL(host_dma, dma_capable);
631 CHECK_BOOL(dma_desc_enable, p->host_dma);
632 CHECK_BOOL(dma_desc_fs_enable, p->dma_desc_enable);
633 CHECK_BOOL(host_ls_low_power_phy_clk,
634 p->phy_type == DWC2_PHY_TYPE_PARAM_FS);
635 CHECK_RANGE(host_channels,
636 1, hw->host_channels,
637 hw->host_channels);
638 CHECK_RANGE(host_rx_fifo_size,
639 16, hw->rx_fifo_size,
640 hw->rx_fifo_size);
641 CHECK_RANGE(host_nperio_tx_fifo_size,
642 16, hw->host_nperio_tx_fifo_size,
643 hw->host_nperio_tx_fifo_size);
644 CHECK_RANGE(host_perio_tx_fifo_size,
645 16, hw->host_perio_tx_fifo_size,
646 hw->host_perio_tx_fifo_size);
647 }
648
649 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
650 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
651 CHECK_BOOL(g_dma, dma_capable);
652 CHECK_BOOL(g_dma_desc, (p->g_dma && hw->dma_desc_enable));
653 CHECK_RANGE(g_rx_fifo_size,
654 16, hw->rx_fifo_size,
655 hw->rx_fifo_size);
656 CHECK_RANGE(g_np_tx_fifo_size,
657 16, hw->dev_nperio_tx_fifo_size,
658 hw->dev_nperio_tx_fifo_size);
Sevak Arakelyan3c6aea72017-01-23 15:01:45 -0800659 dwc2_check_param_tx_fifo_sizes(hsotg);
John Yound936e662017-01-23 14:56:43 -0800660 }
661}
662
John Youn323230e2016-11-03 17:55:50 -0700663/*
664 * Gets host hardware parameters. Forces host mode if not currently in
665 * host mode. Should be called immediately after a core soft reset in
666 * order to get the reset values.
667 */
668static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
669{
670 struct dwc2_hw_params *hw = &hsotg->hw_params;
671 u32 gnptxfsiz;
672 u32 hptxfsiz;
John Youn323230e2016-11-03 17:55:50 -0700673
674 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
675 return;
676
Vardan Mikayelyan13b1f8e2018-02-16 12:56:03 +0400677 dwc2_force_mode(hsotg, true);
John Youn323230e2016-11-03 17:55:50 -0700678
Gevorg Sahakyanf25c42b2018-07-26 18:00:13 +0400679 gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ);
680 hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ);
John Youn323230e2016-11-03 17:55:50 -0700681
John Youn323230e2016-11-03 17:55:50 -0700682 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
683 FIFOSIZE_DEPTH_SHIFT;
684 hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
685 FIFOSIZE_DEPTH_SHIFT;
686}
687
688/*
689 * Gets device hardware parameters. Forces device mode if not
690 * currently in device mode. Should be called immediately after a core
691 * soft reset in order to get the reset values.
692 */
693static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
694{
695 struct dwc2_hw_params *hw = &hsotg->hw_params;
John Youn323230e2016-11-03 17:55:50 -0700696 u32 gnptxfsiz;
Minas Harutyunyan92730832017-11-30 12:16:37 +0400697 int fifo, fifo_count;
John Youn323230e2016-11-03 17:55:50 -0700698
699 if (hsotg->dr_mode == USB_DR_MODE_HOST)
700 return;
701
Vardan Mikayelyan13b1f8e2018-02-16 12:56:03 +0400702 dwc2_force_mode(hsotg, false);
John Youn323230e2016-11-03 17:55:50 -0700703
Gevorg Sahakyanf25c42b2018-07-26 18:00:13 +0400704 gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ);
John Youn323230e2016-11-03 17:55:50 -0700705
Minas Harutyunyan92730832017-11-30 12:16:37 +0400706 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
707
708 for (fifo = 1; fifo <= fifo_count; fifo++) {
709 hw->g_tx_fifo_size[fifo] =
Gevorg Sahakyanf25c42b2018-07-26 18:00:13 +0400710 (dwc2_readl(hsotg, DPTXFSIZN(fifo)) &
Minas Harutyunyan92730832017-11-30 12:16:37 +0400711 FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
712 }
713
John Youn323230e2016-11-03 17:55:50 -0700714 hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
715 FIFOSIZE_DEPTH_SHIFT;
716}
717
718/**
719 * During device initialization, read various hardware configuration
720 * registers and interpret the contents.
Grigor Tovmasyan6fb914d2018-05-16 12:04:24 +0400721 *
722 * @hsotg: Programming view of the DWC_otg controller
723 *
John Youn323230e2016-11-03 17:55:50 -0700724 */
725int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
726{
727 struct dwc2_hw_params *hw = &hsotg->hw_params;
728 unsigned int width;
729 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
730 u32 grxfsiz;
731
732 /*
733 * Attempt to ensure this device is really a DWC_otg Controller.
734 * Read and verify the GSNPSID register contents. The value should be
Gevorg Sahakyand14ccab2018-01-16 16:21:46 +0400735 * 0x45f4xxxx, 0x5531xxxx or 0x5532xxxx
John Youn323230e2016-11-03 17:55:50 -0700736 */
Gevorg Sahakyand14ccab2018-01-16 16:21:46 +0400737
Gevorg Sahakyanf25c42b2018-07-26 18:00:13 +0400738 hw->snpsid = dwc2_readl(hsotg, GSNPSID);
Gevorg Sahakyand14ccab2018-01-16 16:21:46 +0400739 if ((hw->snpsid & GSNPSID_ID_MASK) != DWC2_OTG_ID &&
740 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_FS_IOT_ID &&
741 (hw->snpsid & GSNPSID_ID_MASK) != DWC2_HS_IOT_ID) {
John Youn323230e2016-11-03 17:55:50 -0700742 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
743 hw->snpsid);
744 return -ENODEV;
745 }
746
747 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
748 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
749 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
750
Gevorg Sahakyanf25c42b2018-07-26 18:00:13 +0400751 hwcfg1 = dwc2_readl(hsotg, GHWCFG1);
752 hwcfg2 = dwc2_readl(hsotg, GHWCFG2);
753 hwcfg3 = dwc2_readl(hsotg, GHWCFG3);
754 hwcfg4 = dwc2_readl(hsotg, GHWCFG4);
755 grxfsiz = dwc2_readl(hsotg, GRXFSIZ);
John Youn323230e2016-11-03 17:55:50 -0700756
John Youn323230e2016-11-03 17:55:50 -0700757 /* hwcfg1 */
758 hw->dev_ep_dirs = hwcfg1;
759
760 /* hwcfg2 */
761 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
762 GHWCFG2_OP_MODE_SHIFT;
763 hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
764 GHWCFG2_ARCHITECTURE_SHIFT;
765 hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
766 hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
767 GHWCFG2_NUM_HOST_CHAN_SHIFT);
768 hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
769 GHWCFG2_HS_PHY_TYPE_SHIFT;
770 hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
771 GHWCFG2_FS_PHY_TYPE_SHIFT;
772 hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
773 GHWCFG2_NUM_DEV_EP_SHIFT;
774 hw->nperio_tx_q_depth =
775 (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
776 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
777 hw->host_perio_tx_q_depth =
778 (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
779 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
780 hw->dev_token_q_depth =
781 (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
782 GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
783
784 /* hwcfg3 */
785 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
786 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
787 hw->max_transfer_size = (1 << (width + 11)) - 1;
788 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
789 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
790 hw->max_packet_count = (1 << (width + 4)) - 1;
791 hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
792 hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
793 GHWCFG3_DFIFO_DEPTH_SHIFT;
Sevak Arakelyan6f80b6d2018-01-24 17:41:48 +0400794 hw->lpm_mode = !!(hwcfg3 & GHWCFG3_OTG_LPM_EN);
John Youn323230e2016-11-03 17:55:50 -0700795
796 /* hwcfg4 */
797 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
798 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
799 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
Minas Harutyunyan92730832017-11-30 12:16:37 +0400800 hw->num_dev_in_eps = (hwcfg4 & GHWCFG4_NUM_IN_EPS_MASK) >>
801 GHWCFG4_NUM_IN_EPS_SHIFT;
John Youn323230e2016-11-03 17:55:50 -0700802 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
803 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
Vardan Mikayelyan631a2312018-02-16 14:07:05 +0400804 hw->hibernation = !!(hwcfg4 & GHWCFG4_HIBER);
John Youn323230e2016-11-03 17:55:50 -0700805 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
806 GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
Razmik Karapetyan66e77a22018-01-24 17:40:29 +0400807 hw->acg_enable = !!(hwcfg4 & GHWCFG4_ACG_SUPPORTED);
Grigor Tovmasyanb43ebc92018-05-05 12:17:58 +0400808 hw->ipg_isoc_en = !!(hwcfg4 & GHWCFG4_IPG_ISOC_SUPPORTED);
Grigor Tovmasyanca531bc2018-08-29 20:59:34 +0400809 hw->service_interval_mode = !!(hwcfg4 &
810 GHWCFG4_SERVICE_INTERVAL_SUPPORTED);
John Youn323230e2016-11-03 17:55:50 -0700811
812 /* fifo sizes */
John Yound1531312016-11-03 17:56:02 -0700813 hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
John Youn323230e2016-11-03 17:55:50 -0700814 GRXFSIZ_DEPTH_SHIFT;
Minas Harutyunyan92730832017-11-30 12:16:37 +0400815 /*
816 * Host specific hardware parameters. Reading these parameters
817 * requires the controller to be in host mode. The mode will
818 * be forced, if necessary, to read these values.
819 */
820 dwc2_get_host_hwparams(hsotg);
821 dwc2_get_dev_hwparams(hsotg);
John Youn323230e2016-11-03 17:55:50 -0700822
John Youn323230e2016-11-03 17:55:50 -0700823 return 0;
824}
825
John Youn334bbd42016-11-03 17:55:55 -0700826int dwc2_init_params(struct dwc2_hsotg *hsotg)
827{
John Youn7de1deb2017-01-23 14:57:04 -0800828 const struct of_device_id *match;
829 void (*set_params)(void *data);
830
John Youn245977c2017-01-23 14:55:14 -0800831 dwc2_set_default_params(hsotg);
John Younf9f93cb2017-01-23 14:55:35 -0800832 dwc2_get_device_properties(hsotg);
John Youn334bbd42016-11-03 17:55:55 -0700833
John Youn7de1deb2017-01-23 14:57:04 -0800834 match = of_match_device(dwc2_of_match_table, hsotg->dev);
835 if (match && match->data) {
836 set_params = match->data;
837 set_params(hsotg);
838 }
839
John Yound936e662017-01-23 14:56:43 -0800840 dwc2_check_params(hsotg);
841
John Youn334bbd42016-11-03 17:55:55 -0700842 return 0;
843}