xref: /openbmc/linux/drivers/usb/dwc2/params.c (revision c138ecfa6108edee17fabfa56285b00f66641659)
1323230efSJohn Youn /*
2323230efSJohn Youn  * Copyright (C) 2004-2016 Synopsys, Inc.
3323230efSJohn Youn  *
4323230efSJohn Youn  * Redistribution and use in source and binary forms, with or without
5323230efSJohn Youn  * modification, are permitted provided that the following conditions
6323230efSJohn Youn  * are met:
7323230efSJohn Youn  * 1. Redistributions of source code must retain the above copyright
8323230efSJohn Youn  *    notice, this list of conditions, and the following disclaimer,
9323230efSJohn Youn  *    without modification.
10323230efSJohn Youn  * 2. Redistributions in binary form must reproduce the above copyright
11323230efSJohn Youn  *    notice, this list of conditions and the following disclaimer in the
12323230efSJohn Youn  *    documentation and/or other materials provided with the distribution.
13323230efSJohn Youn  * 3. The names of the above-listed copyright holders may not be used
14323230efSJohn Youn  *    to endorse or promote products derived from this software without
15323230efSJohn Youn  *    specific prior written permission.
16323230efSJohn Youn  *
17323230efSJohn Youn  * ALTERNATIVELY, this software may be distributed under the terms of the
18323230efSJohn Youn  * GNU General Public License ("GPL") as published by the Free Software
19323230efSJohn Youn  * Foundation; either version 2 of the License, or (at your option) any
20323230efSJohn Youn  * later version.
21323230efSJohn Youn  *
22323230efSJohn Youn  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23323230efSJohn Youn  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24323230efSJohn Youn  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25323230efSJohn Youn  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26323230efSJohn Youn  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27323230efSJohn Youn  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28323230efSJohn Youn  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29323230efSJohn Youn  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30323230efSJohn Youn  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31323230efSJohn Youn  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32323230efSJohn Youn  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33323230efSJohn Youn  */
34323230efSJohn Youn 
35323230efSJohn Youn #include <linux/kernel.h>
36323230efSJohn Youn #include <linux/module.h>
37323230efSJohn Youn #include <linux/of_device.h>
38323230efSJohn Youn 
39323230efSJohn Youn #include "core.h"
40323230efSJohn Youn 
417de1debcSJohn Youn static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg)
427de1debcSJohn Youn {
437de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
44323230efSJohn Youn 
457de1debcSJohn Youn 	p->host_rx_fifo_size = 774;
467de1debcSJohn Youn 	p->max_transfer_size = 65535;
477de1debcSJohn Youn 	p->max_packet_count = 511;
487de1debcSJohn Youn 	p->ahbcfg = 0x10;
497de1debcSJohn Youn 	p->uframe_sched = false;
507de1debcSJohn Youn }
51323230efSJohn Youn 
527de1debcSJohn Youn static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
537de1debcSJohn Youn {
547de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
55323230efSJohn Youn 
567de1debcSJohn Youn 	p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
577de1debcSJohn Youn 	p->speed = DWC2_SPEED_PARAM_HIGH;
587de1debcSJohn Youn 	p->host_rx_fifo_size = 512;
597de1debcSJohn Youn 	p->host_nperio_tx_fifo_size = 512;
607de1debcSJohn Youn 	p->host_perio_tx_fifo_size = 512;
617de1debcSJohn Youn 	p->max_transfer_size = 65535;
627de1debcSJohn Youn 	p->max_packet_count = 511;
637de1debcSJohn Youn 	p->host_channels = 16;
647de1debcSJohn Youn 	p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
657de1debcSJohn Youn 	p->phy_utmi_width = 8;
667de1debcSJohn Youn 	p->i2c_enable = false;
677de1debcSJohn Youn 	p->reload_ctl = false;
687de1debcSJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
697de1debcSJohn Youn 		GAHBCFG_HBSTLEN_SHIFT;
707de1debcSJohn Youn 	p->uframe_sched = false;
71ca8b0332SChen Yu 	p->change_speed_quirk = true;
727de1debcSJohn Youn }
73323230efSJohn Youn 
747de1debcSJohn Youn static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg)
757de1debcSJohn Youn {
767de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
777de1debcSJohn Youn 
787de1debcSJohn Youn 	p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
797de1debcSJohn Youn 	p->host_rx_fifo_size = 525;
807de1debcSJohn Youn 	p->host_nperio_tx_fifo_size = 128;
817de1debcSJohn Youn 	p->host_perio_tx_fifo_size = 256;
827de1debcSJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
837de1debcSJohn Youn 		GAHBCFG_HBSTLEN_SHIFT;
847de1debcSJohn Youn }
857de1debcSJohn Youn 
867de1debcSJohn Youn static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)
877de1debcSJohn Youn {
887de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
897de1debcSJohn Youn 
907de1debcSJohn Youn 	p->otg_cap = 2;
917de1debcSJohn Youn 	p->host_rx_fifo_size = 288;
927de1debcSJohn Youn 	p->host_nperio_tx_fifo_size = 128;
937de1debcSJohn Youn 	p->host_perio_tx_fifo_size = 96;
947de1debcSJohn Youn 	p->max_transfer_size = 65535;
957de1debcSJohn Youn 	p->max_packet_count = 511;
967de1debcSJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
977de1debcSJohn Youn 		GAHBCFG_HBSTLEN_SHIFT;
987de1debcSJohn Youn }
997de1debcSJohn Youn 
1007de1debcSJohn Youn static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg)
1017de1debcSJohn Youn {
1027de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
1037de1debcSJohn Youn 
1047de1debcSJohn Youn 	p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
1057de1debcSJohn Youn 	p->speed = DWC2_SPEED_PARAM_HIGH;
1067de1debcSJohn Youn 	p->host_rx_fifo_size = 512;
1077de1debcSJohn Youn 	p->host_nperio_tx_fifo_size = 500;
1087de1debcSJohn Youn 	p->host_perio_tx_fifo_size = 500;
1097de1debcSJohn Youn 	p->host_channels = 16;
1107de1debcSJohn Youn 	p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
1117de1debcSJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 <<
1127de1debcSJohn Youn 		GAHBCFG_HBSTLEN_SHIFT;
1137de1debcSJohn Youn 	p->uframe_sched = false;
1147de1debcSJohn Youn }
1157de1debcSJohn Youn 
1167de1debcSJohn Youn static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg)
1177de1debcSJohn Youn {
1187de1debcSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
1197de1debcSJohn Youn 
1207de1debcSJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
1217de1debcSJohn Youn }
122323230efSJohn Youn 
123323230efSJohn Youn const struct of_device_id dwc2_of_match_table[] = {
1247de1debcSJohn Youn 	{ .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params },
1257de1debcSJohn Youn 	{ .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params  },
1267de1debcSJohn Youn 	{ .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params },
1277de1debcSJohn Youn 	{ .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params },
1287de1debcSJohn Youn 	{ .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params },
1297de1debcSJohn Youn 	{ .compatible = "snps,dwc2" },
1307de1debcSJohn Youn 	{ .compatible = "samsung,s3c6400-hsotg" },
1317de1debcSJohn Youn 	{ .compatible = "amlogic,meson8b-usb",
1327de1debcSJohn Youn 	  .data = dwc2_set_amlogic_params },
1337de1debcSJohn Youn 	{ .compatible = "amlogic,meson-gxbb-usb",
1347de1debcSJohn Youn 	  .data = dwc2_set_amlogic_params },
1357de1debcSJohn Youn 	{ .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params },
136323230efSJohn Youn 	{},
137323230efSJohn Youn };
138323230efSJohn Youn MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
139323230efSJohn Youn 
140245977c9SJohn Youn static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg)
14105ee799fSJohn Youn {
142245977c9SJohn Youn 	u8 val;
14305ee799fSJohn Youn 
144323230efSJohn Youn 	switch (hsotg->hw_params.op_mode) {
145323230efSJohn Youn 	case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
146323230efSJohn Youn 		val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
147323230efSJohn Youn 		break;
148323230efSJohn Youn 	case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
149323230efSJohn Youn 	case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
150323230efSJohn Youn 	case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
151323230efSJohn Youn 		val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
152323230efSJohn Youn 		break;
153323230efSJohn Youn 	default:
154323230efSJohn Youn 		val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
155323230efSJohn Youn 		break;
156323230efSJohn Youn 	}
157323230efSJohn Youn 
158bea8e86cSJohn Youn 	hsotg->params.otg_cap = val;
159323230efSJohn Youn }
160323230efSJohn Youn 
161245977c9SJohn Youn static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg)
162323230efSJohn Youn {
163245977c9SJohn Youn 	int val;
164245977c9SJohn Youn 	u32 hs_phy_type = hsotg->hw_params.hs_phy_type;
165323230efSJohn Youn 
166323230efSJohn Youn 	val = DWC2_PHY_TYPE_PARAM_FS;
167323230efSJohn Youn 	if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
168323230efSJohn Youn 		if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
169323230efSJohn Youn 		    hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
170323230efSJohn Youn 			val = DWC2_PHY_TYPE_PARAM_UTMI;
171323230efSJohn Youn 		else
172323230efSJohn Youn 			val = DWC2_PHY_TYPE_PARAM_ULPI;
173323230efSJohn Youn 	}
174245977c9SJohn Youn 
175245977c9SJohn Youn 	if (dwc2_is_fs_iot(hsotg))
176245977c9SJohn Youn 		hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS;
177323230efSJohn Youn 
178bea8e86cSJohn Youn 	hsotg->params.phy_type = val;
179323230efSJohn Youn }
180323230efSJohn Youn 
181245977c9SJohn Youn static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg)
182323230efSJohn Youn {
183245977c9SJohn Youn 	int val;
184323230efSJohn Youn 
185245977c9SJohn Youn 	val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ?
186323230efSJohn Youn 		DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
187245977c9SJohn Youn 
188245977c9SJohn Youn 	if (dwc2_is_fs_iot(hsotg))
189245977c9SJohn Youn 		val = DWC2_SPEED_PARAM_FULL;
190245977c9SJohn Youn 
191245977c9SJohn Youn 	if (dwc2_is_hs_iot(hsotg))
192245977c9SJohn Youn 		val = DWC2_SPEED_PARAM_HIGH;
193323230efSJohn Youn 
194bea8e86cSJohn Youn 	hsotg->params.speed = val;
195323230efSJohn Youn }
196323230efSJohn Youn 
197245977c9SJohn Youn static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
198323230efSJohn Youn {
199245977c9SJohn Youn 	int val;
200323230efSJohn Youn 
201323230efSJohn Youn 	val = (hsotg->hw_params.utmi_phy_data_width ==
202323230efSJohn Youn 	       GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
203323230efSJohn Youn 
204bea8e86cSJohn Youn 	hsotg->params.phy_utmi_width = val;
205323230efSJohn Youn }
206323230efSJohn Youn 
20705ee799fSJohn Youn static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
20805ee799fSJohn Youn {
20905ee799fSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
210*c138ecfaSSevak Arakelyan 	int depth_average;
211*c138ecfaSSevak Arakelyan 	int fifo_count;
212*c138ecfaSSevak Arakelyan 	int i;
213*c138ecfaSSevak Arakelyan 
214*c138ecfaSSevak Arakelyan 	fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
21505ee799fSJohn Youn 
216245977c9SJohn Youn 	memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
217*c138ecfaSSevak Arakelyan 	depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg);
218*c138ecfaSSevak Arakelyan 	for (i = 1; i <= fifo_count; i++)
219*c138ecfaSSevak Arakelyan 		p->g_tx_fifo_size[i] = depth_average;
2209962b62fSJohn Youn }
2219962b62fSJohn Youn 
22205ee799fSJohn Youn /**
223245977c9SJohn Youn  * dwc2_set_default_params() - Set all core parameters to their
224245977c9SJohn Youn  * auto-detected default values.
225323230efSJohn Youn  */
226245977c9SJohn Youn static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
227323230efSJohn Youn {
22805ee799fSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
22905ee799fSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
2306b66ce51SJohn Youn 	bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
231323230efSJohn Youn 
232245977c9SJohn Youn 	dwc2_set_param_otg_cap(hsotg);
233245977c9SJohn Youn 	dwc2_set_param_phy_type(hsotg);
234245977c9SJohn Youn 	dwc2_set_param_speed(hsotg);
235245977c9SJohn Youn 	dwc2_set_param_phy_utmi_width(hsotg);
236245977c9SJohn Youn 	p->phy_ulpi_ddr = false;
237245977c9SJohn Youn 	p->phy_ulpi_ext_vbus = false;
238245977c9SJohn Youn 
239245977c9SJohn Youn 	p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
240245977c9SJohn Youn 	p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
241245977c9SJohn Youn 	p->i2c_enable = hw->i2c_enable;
242245977c9SJohn Youn 	p->ulpi_fs_ls = false;
243245977c9SJohn Youn 	p->ts_dline = false;
244245977c9SJohn Youn 	p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
245245977c9SJohn Youn 	p->uframe_sched = true;
246245977c9SJohn Youn 	p->external_id_pin_ctl = false;
247245977c9SJohn Youn 	p->hibernation = false;
248245977c9SJohn Youn 	p->max_packet_count = hw->max_packet_count;
249245977c9SJohn Youn 	p->max_transfer_size = hw->max_transfer_size;
250245977c9SJohn Youn 	p->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << GAHBCFG_HBSTLEN_SHIFT;
251245977c9SJohn Youn 
2526b66ce51SJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
2536b66ce51SJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
254245977c9SJohn Youn 		p->host_dma = dma_capable;
255245977c9SJohn Youn 		p->dma_desc_enable = false;
256245977c9SJohn Youn 		p->dma_desc_fs_enable = false;
257245977c9SJohn Youn 		p->host_support_fs_ls_low_power = false;
258245977c9SJohn Youn 		p->host_ls_low_power_phy_clk = false;
259245977c9SJohn Youn 		p->host_channels = hw->host_channels;
260245977c9SJohn Youn 		p->host_rx_fifo_size = hw->rx_fifo_size;
261245977c9SJohn Youn 		p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size;
262245977c9SJohn Youn 		p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size;
2636b66ce51SJohn Youn 	}
2646b66ce51SJohn Youn 
26505ee799fSJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
26605ee799fSJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
267245977c9SJohn Youn 		p->g_dma = dma_capable;
268245977c9SJohn Youn 		p->g_dma_desc = hw->dma_desc_enable;
26905ee799fSJohn Youn 
27005ee799fSJohn Youn 		/*
27105ee799fSJohn Youn 		 * The values for g_rx_fifo_size (2048) and
27205ee799fSJohn Youn 		 * g_np_tx_fifo_size (1024) come from the legacy s3c
27305ee799fSJohn Youn 		 * gadget driver. These defaults have been hard-coded
27405ee799fSJohn Youn 		 * for some time so many platforms depend on these
27505ee799fSJohn Youn 		 * values. Leave them as defaults for now and only
27605ee799fSJohn Youn 		 * auto-detect if the hardware does not support the
27705ee799fSJohn Youn 		 * default.
27805ee799fSJohn Youn 		 */
279245977c9SJohn Youn 		p->g_rx_fifo_size = 2048;
280245977c9SJohn Youn 		p->g_np_tx_fifo_size = 1024;
28105ee799fSJohn Youn 		dwc2_set_param_tx_fifo_sizes(hsotg);
28205ee799fSJohn Youn 	}
283323230efSJohn Youn }
284323230efSJohn Youn 
285f9f93cbbSJohn Youn /**
286f9f93cbbSJohn Youn  * dwc2_get_device_properties() - Read in device properties.
287f9f93cbbSJohn Youn  *
288f9f93cbbSJohn Youn  * Read in the device properties and adjust core parameters if needed.
289f9f93cbbSJohn Youn  */
290f9f93cbbSJohn Youn static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
291f9f93cbbSJohn Youn {
292f9f93cbbSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
293f9f93cbbSJohn Youn 	int num;
294f9f93cbbSJohn Youn 
295f9f93cbbSJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
296f9f93cbbSJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
297f9f93cbbSJohn Youn 		device_property_read_u32(hsotg->dev, "g-rx-fifo-size",
298f9f93cbbSJohn Youn 					 &p->g_rx_fifo_size);
299f9f93cbbSJohn Youn 
300f9f93cbbSJohn Youn 		device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size",
301f9f93cbbSJohn Youn 					 &p->g_np_tx_fifo_size);
302f9f93cbbSJohn Youn 
303f9f93cbbSJohn Youn 		num = device_property_read_u32_array(hsotg->dev,
304f9f93cbbSJohn Youn 						     "g-tx-fifo-size",
305f9f93cbbSJohn Youn 						     NULL, 0);
306f9f93cbbSJohn Youn 
307f9f93cbbSJohn Youn 		if (num > 0) {
308f9f93cbbSJohn Youn 			num = min(num, 15);
309f9f93cbbSJohn Youn 			memset(p->g_tx_fifo_size, 0,
310f9f93cbbSJohn Youn 			       sizeof(p->g_tx_fifo_size));
311f9f93cbbSJohn Youn 			device_property_read_u32_array(hsotg->dev,
312f9f93cbbSJohn Youn 						       "g-tx-fifo-size",
313f9f93cbbSJohn Youn 						       &p->g_tx_fifo_size[1],
314f9f93cbbSJohn Youn 						       num);
315f9f93cbbSJohn Youn 		}
316f9f93cbbSJohn Youn 	}
317f9f93cbbSJohn Youn }
318f9f93cbbSJohn Youn 
319d936e666SJohn Youn static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
320d936e666SJohn Youn {
321d936e666SJohn Youn 	int valid = 1;
322d936e666SJohn Youn 
323d936e666SJohn Youn 	switch (hsotg->params.otg_cap) {
324d936e666SJohn Youn 	case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
325d936e666SJohn Youn 		if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
326d936e666SJohn Youn 			valid = 0;
327d936e666SJohn Youn 		break;
328d936e666SJohn Youn 	case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
329d936e666SJohn Youn 		switch (hsotg->hw_params.op_mode) {
330d936e666SJohn Youn 		case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
331d936e666SJohn Youn 		case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
332d936e666SJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
333d936e666SJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
334d936e666SJohn Youn 			break;
335d936e666SJohn Youn 		default:
336d936e666SJohn Youn 			valid = 0;
337d936e666SJohn Youn 			break;
338d936e666SJohn Youn 		}
339d936e666SJohn Youn 		break;
340d936e666SJohn Youn 	case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
341d936e666SJohn Youn 		/* always valid */
342d936e666SJohn Youn 		break;
343d936e666SJohn Youn 	default:
344d936e666SJohn Youn 		valid = 0;
345d936e666SJohn Youn 		break;
346d936e666SJohn Youn 	}
347d936e666SJohn Youn 
348d936e666SJohn Youn 	if (!valid)
349d936e666SJohn Youn 		dwc2_set_param_otg_cap(hsotg);
350d936e666SJohn Youn }
351d936e666SJohn Youn 
352d936e666SJohn Youn static void dwc2_check_param_phy_type(struct dwc2_hsotg *hsotg)
353d936e666SJohn Youn {
354d936e666SJohn Youn 	int valid = 0;
355d936e666SJohn Youn 	u32 hs_phy_type;
356d936e666SJohn Youn 	u32 fs_phy_type;
357d936e666SJohn Youn 
358d936e666SJohn Youn 	hs_phy_type = hsotg->hw_params.hs_phy_type;
359d936e666SJohn Youn 	fs_phy_type = hsotg->hw_params.fs_phy_type;
360d936e666SJohn Youn 
361d936e666SJohn Youn 	switch (hsotg->params.phy_type) {
362d936e666SJohn Youn 	case DWC2_PHY_TYPE_PARAM_FS:
363d936e666SJohn Youn 		if (fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
364d936e666SJohn Youn 			valid = 1;
365d936e666SJohn Youn 		break;
366d936e666SJohn Youn 	case DWC2_PHY_TYPE_PARAM_UTMI:
367d936e666SJohn Youn 		if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
368d936e666SJohn Youn 		    (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
369d936e666SJohn Youn 			valid = 1;
370d936e666SJohn Youn 		break;
371d936e666SJohn Youn 	case DWC2_PHY_TYPE_PARAM_ULPI:
372d936e666SJohn Youn 		if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
373d936e666SJohn Youn 		    (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
374d936e666SJohn Youn 			valid = 1;
375d936e666SJohn Youn 		break;
376d936e666SJohn Youn 	default:
377d936e666SJohn Youn 		break;
378d936e666SJohn Youn 	}
379d936e666SJohn Youn 
380d936e666SJohn Youn 	if (!valid)
381d936e666SJohn Youn 		dwc2_set_param_phy_type(hsotg);
382d936e666SJohn Youn }
383d936e666SJohn Youn 
384d936e666SJohn Youn static void dwc2_check_param_speed(struct dwc2_hsotg *hsotg)
385d936e666SJohn Youn {
386d936e666SJohn Youn 	int valid = 1;
387d936e666SJohn Youn 	int phy_type = hsotg->params.phy_type;
388d936e666SJohn Youn 	int speed = hsotg->params.speed;
389d936e666SJohn Youn 
390d936e666SJohn Youn 	switch (speed) {
391d936e666SJohn Youn 	case DWC2_SPEED_PARAM_HIGH:
392d936e666SJohn Youn 		if ((hsotg->params.speed == DWC2_SPEED_PARAM_HIGH) &&
393d936e666SJohn Youn 		    (phy_type == DWC2_PHY_TYPE_PARAM_FS))
394d936e666SJohn Youn 			valid = 0;
395d936e666SJohn Youn 		break;
396d936e666SJohn Youn 	case DWC2_SPEED_PARAM_FULL:
397d936e666SJohn Youn 	case DWC2_SPEED_PARAM_LOW:
398d936e666SJohn Youn 		break;
399d936e666SJohn Youn 	default:
400d936e666SJohn Youn 		valid = 0;
401d936e666SJohn Youn 		break;
402d936e666SJohn Youn 	}
403d936e666SJohn Youn 
404d936e666SJohn Youn 	if (!valid)
405d936e666SJohn Youn 		dwc2_set_param_speed(hsotg);
406d936e666SJohn Youn }
407d936e666SJohn Youn 
408d936e666SJohn Youn static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
409d936e666SJohn Youn {
410d936e666SJohn Youn 	int valid = 0;
411d936e666SJohn Youn 	int param = hsotg->params.phy_utmi_width;
412d936e666SJohn Youn 	int width = hsotg->hw_params.utmi_phy_data_width;
413d936e666SJohn Youn 
414d936e666SJohn Youn 	switch (width) {
415d936e666SJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
416d936e666SJohn Youn 		valid = (param == 8);
417d936e666SJohn Youn 		break;
418d936e666SJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
419d936e666SJohn Youn 		valid = (param == 16);
420d936e666SJohn Youn 		break;
421d936e666SJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
422d936e666SJohn Youn 		valid = (param == 8 || param == 16);
423d936e666SJohn Youn 		break;
424d936e666SJohn Youn 	}
425d936e666SJohn Youn 
426d936e666SJohn Youn 	if (!valid)
427d936e666SJohn Youn 		dwc2_set_param_phy_utmi_width(hsotg);
428d936e666SJohn Youn }
429d936e666SJohn Youn 
430d936e666SJohn Youn #define CHECK_RANGE(_param, _min, _max, _def) do {			\
431d936e666SJohn Youn 		if ((hsotg->params._param) < (_min) ||			\
432d936e666SJohn Youn 		    (hsotg->params._param) > (_max)) {			\
433d936e666SJohn Youn 			dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
434d936e666SJohn Youn 				 __func__, #_param, hsotg->params._param); \
435d936e666SJohn Youn 			hsotg->params._param = (_def);			\
436d936e666SJohn Youn 		}							\
437d936e666SJohn Youn 	} while (0)
438d936e666SJohn Youn 
439d936e666SJohn Youn #define CHECK_BOOL(_param, _check) do {					\
440d936e666SJohn Youn 		if (hsotg->params._param && !(_check)) {		\
441d936e666SJohn Youn 			dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
442d936e666SJohn Youn 				 __func__, #_param, hsotg->params._param); \
443d936e666SJohn Youn 			hsotg->params._param = false;			\
444d936e666SJohn Youn 		}							\
445d936e666SJohn Youn 	} while (0)
446d936e666SJohn Youn 
447d936e666SJohn Youn static void dwc2_check_params(struct dwc2_hsotg *hsotg)
448d936e666SJohn Youn {
449d936e666SJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
450d936e666SJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
451d936e666SJohn Youn 	bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
452d936e666SJohn Youn 
453d936e666SJohn Youn 	dwc2_check_param_otg_cap(hsotg);
454d936e666SJohn Youn 	dwc2_check_param_phy_type(hsotg);
455d936e666SJohn Youn 	dwc2_check_param_speed(hsotg);
456d936e666SJohn Youn 	dwc2_check_param_phy_utmi_width(hsotg);
457d936e666SJohn Youn 	CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo);
458d936e666SJohn Youn 	CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo);
459d936e666SJohn Youn 	CHECK_BOOL(i2c_enable, hw->i2c_enable);
460d936e666SJohn Youn 	CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a));
461d936e666SJohn Youn 	CHECK_RANGE(max_packet_count,
462d936e666SJohn Youn 		    15, hw->max_packet_count,
463d936e666SJohn Youn 		    hw->max_packet_count);
464d936e666SJohn Youn 	CHECK_RANGE(max_transfer_size,
465d936e666SJohn Youn 		    2047, hw->max_transfer_size,
466d936e666SJohn Youn 		    hw->max_transfer_size);
467d936e666SJohn Youn 
468d936e666SJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
469d936e666SJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
470d936e666SJohn Youn 		CHECK_BOOL(host_dma, dma_capable);
471d936e666SJohn Youn 		CHECK_BOOL(dma_desc_enable, p->host_dma);
472d936e666SJohn Youn 		CHECK_BOOL(dma_desc_fs_enable, p->dma_desc_enable);
473d936e666SJohn Youn 		CHECK_BOOL(host_ls_low_power_phy_clk,
474d936e666SJohn Youn 			   p->phy_type == DWC2_PHY_TYPE_PARAM_FS);
475d936e666SJohn Youn 		CHECK_RANGE(host_channels,
476d936e666SJohn Youn 			    1, hw->host_channels,
477d936e666SJohn Youn 			    hw->host_channels);
478d936e666SJohn Youn 		CHECK_RANGE(host_rx_fifo_size,
479d936e666SJohn Youn 			    16, hw->rx_fifo_size,
480d936e666SJohn Youn 			    hw->rx_fifo_size);
481d936e666SJohn Youn 		CHECK_RANGE(host_nperio_tx_fifo_size,
482d936e666SJohn Youn 			    16, hw->host_nperio_tx_fifo_size,
483d936e666SJohn Youn 			    hw->host_nperio_tx_fifo_size);
484d936e666SJohn Youn 		CHECK_RANGE(host_perio_tx_fifo_size,
485d936e666SJohn Youn 			    16, hw->host_perio_tx_fifo_size,
486d936e666SJohn Youn 			    hw->host_perio_tx_fifo_size);
487d936e666SJohn Youn 	}
488d936e666SJohn Youn 
489d936e666SJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
490d936e666SJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
491d936e666SJohn Youn 		CHECK_BOOL(g_dma, dma_capable);
492d936e666SJohn Youn 		CHECK_BOOL(g_dma_desc, (p->g_dma && hw->dma_desc_enable));
493d936e666SJohn Youn 		CHECK_RANGE(g_rx_fifo_size,
494d936e666SJohn Youn 			    16, hw->rx_fifo_size,
495d936e666SJohn Youn 			    hw->rx_fifo_size);
496d936e666SJohn Youn 		CHECK_RANGE(g_np_tx_fifo_size,
497d936e666SJohn Youn 			    16, hw->dev_nperio_tx_fifo_size,
498d936e666SJohn Youn 			    hw->dev_nperio_tx_fifo_size);
499d936e666SJohn Youn 	}
500d936e666SJohn Youn }
501d936e666SJohn Youn 
502323230efSJohn Youn /*
503323230efSJohn Youn  * Gets host hardware parameters. Forces host mode if not currently in
504323230efSJohn Youn  * host mode. Should be called immediately after a core soft reset in
505323230efSJohn Youn  * order to get the reset values.
506323230efSJohn Youn  */
507323230efSJohn Youn static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
508323230efSJohn Youn {
509323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
510323230efSJohn Youn 	u32 gnptxfsiz;
511323230efSJohn Youn 	u32 hptxfsiz;
512323230efSJohn Youn 	bool forced;
513323230efSJohn Youn 
514323230efSJohn Youn 	if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
515323230efSJohn Youn 		return;
516323230efSJohn Youn 
517323230efSJohn Youn 	forced = dwc2_force_mode_if_needed(hsotg, true);
518323230efSJohn Youn 
519323230efSJohn Youn 	gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
520323230efSJohn Youn 	hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
521323230efSJohn Youn 
522323230efSJohn Youn 	if (forced)
523323230efSJohn Youn 		dwc2_clear_force_mode(hsotg);
524323230efSJohn Youn 
525323230efSJohn Youn 	hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
526323230efSJohn Youn 				       FIFOSIZE_DEPTH_SHIFT;
527323230efSJohn Youn 	hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
528323230efSJohn Youn 				      FIFOSIZE_DEPTH_SHIFT;
529323230efSJohn Youn }
530323230efSJohn Youn 
531323230efSJohn Youn /*
532323230efSJohn Youn  * Gets device hardware parameters. Forces device mode if not
533323230efSJohn Youn  * currently in device mode. Should be called immediately after a core
534323230efSJohn Youn  * soft reset in order to get the reset values.
535323230efSJohn Youn  */
536323230efSJohn Youn static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
537323230efSJohn Youn {
538323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
539323230efSJohn Youn 	bool forced;
540323230efSJohn Youn 	u32 gnptxfsiz;
541323230efSJohn Youn 
542323230efSJohn Youn 	if (hsotg->dr_mode == USB_DR_MODE_HOST)
543323230efSJohn Youn 		return;
544323230efSJohn Youn 
545323230efSJohn Youn 	forced = dwc2_force_mode_if_needed(hsotg, false);
546323230efSJohn Youn 
547323230efSJohn Youn 	gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
548323230efSJohn Youn 
549323230efSJohn Youn 	if (forced)
550323230efSJohn Youn 		dwc2_clear_force_mode(hsotg);
551323230efSJohn Youn 
552323230efSJohn Youn 	hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
553323230efSJohn Youn 				       FIFOSIZE_DEPTH_SHIFT;
554323230efSJohn Youn }
555323230efSJohn Youn 
556323230efSJohn Youn /**
557323230efSJohn Youn  * During device initialization, read various hardware configuration
558323230efSJohn Youn  * registers and interpret the contents.
559323230efSJohn Youn  */
560323230efSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
561323230efSJohn Youn {
562323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
563323230efSJohn Youn 	unsigned int width;
564323230efSJohn Youn 	u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
565323230efSJohn Youn 	u32 grxfsiz;
566323230efSJohn Youn 
567323230efSJohn Youn 	/*
568323230efSJohn Youn 	 * Attempt to ensure this device is really a DWC_otg Controller.
569323230efSJohn Youn 	 * Read and verify the GSNPSID register contents. The value should be
570323230efSJohn Youn 	 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
571323230efSJohn Youn 	 * as in "OTG version 2.xx" or "OTG version 3.xx".
572323230efSJohn Youn 	 */
573323230efSJohn Youn 	hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID);
574323230efSJohn Youn 	if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
5751e6b98ebSVardan Mikayelyan 	    (hw->snpsid & 0xfffff000) != 0x4f543000 &&
5761e6b98ebSVardan Mikayelyan 	    (hw->snpsid & 0xffff0000) != 0x55310000 &&
5771e6b98ebSVardan Mikayelyan 	    (hw->snpsid & 0xffff0000) != 0x55320000) {
578323230efSJohn Youn 		dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
579323230efSJohn Youn 			hw->snpsid);
580323230efSJohn Youn 		return -ENODEV;
581323230efSJohn Youn 	}
582323230efSJohn Youn 
583323230efSJohn Youn 	dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
584323230efSJohn Youn 		hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
585323230efSJohn Youn 		hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
586323230efSJohn Youn 
587323230efSJohn Youn 	hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1);
588323230efSJohn Youn 	hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
589323230efSJohn Youn 	hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3);
590323230efSJohn Youn 	hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4);
591323230efSJohn Youn 	grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
592323230efSJohn Youn 
593323230efSJohn Youn 	/*
594323230efSJohn Youn 	 * Host specific hardware parameters. Reading these parameters
595323230efSJohn Youn 	 * requires the controller to be in host mode. The mode will
596323230efSJohn Youn 	 * be forced, if necessary, to read these values.
597323230efSJohn Youn 	 */
598323230efSJohn Youn 	dwc2_get_host_hwparams(hsotg);
599323230efSJohn Youn 	dwc2_get_dev_hwparams(hsotg);
600323230efSJohn Youn 
601323230efSJohn Youn 	/* hwcfg1 */
602323230efSJohn Youn 	hw->dev_ep_dirs = hwcfg1;
603323230efSJohn Youn 
604323230efSJohn Youn 	/* hwcfg2 */
605323230efSJohn Youn 	hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
606323230efSJohn Youn 		      GHWCFG2_OP_MODE_SHIFT;
607323230efSJohn Youn 	hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
608323230efSJohn Youn 		   GHWCFG2_ARCHITECTURE_SHIFT;
609323230efSJohn Youn 	hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
610323230efSJohn Youn 	hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
611323230efSJohn Youn 				GHWCFG2_NUM_HOST_CHAN_SHIFT);
612323230efSJohn Youn 	hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
613323230efSJohn Youn 			  GHWCFG2_HS_PHY_TYPE_SHIFT;
614323230efSJohn Youn 	hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
615323230efSJohn Youn 			  GHWCFG2_FS_PHY_TYPE_SHIFT;
616323230efSJohn Youn 	hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
617323230efSJohn Youn 			 GHWCFG2_NUM_DEV_EP_SHIFT;
618323230efSJohn Youn 	hw->nperio_tx_q_depth =
619323230efSJohn Youn 		(hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
620323230efSJohn Youn 		GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
621323230efSJohn Youn 	hw->host_perio_tx_q_depth =
622323230efSJohn Youn 		(hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
623323230efSJohn Youn 		GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
624323230efSJohn Youn 	hw->dev_token_q_depth =
625323230efSJohn Youn 		(hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
626323230efSJohn Youn 		GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
627323230efSJohn Youn 
628323230efSJohn Youn 	/* hwcfg3 */
629323230efSJohn Youn 	width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
630323230efSJohn Youn 		GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
631323230efSJohn Youn 	hw->max_transfer_size = (1 << (width + 11)) - 1;
632323230efSJohn Youn 	width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
633323230efSJohn Youn 		GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
634323230efSJohn Youn 	hw->max_packet_count = (1 << (width + 4)) - 1;
635323230efSJohn Youn 	hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
636323230efSJohn Youn 	hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
637323230efSJohn Youn 			      GHWCFG3_DFIFO_DEPTH_SHIFT;
638323230efSJohn Youn 
639323230efSJohn Youn 	/* hwcfg4 */
640323230efSJohn Youn 	hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
641323230efSJohn Youn 	hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
642323230efSJohn Youn 				  GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
643323230efSJohn Youn 	hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
644323230efSJohn Youn 	hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
645323230efSJohn Youn 	hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
646323230efSJohn Youn 				  GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
647323230efSJohn Youn 
648323230efSJohn Youn 	/* fifo sizes */
649d1531319SJohn Youn 	hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
650323230efSJohn Youn 				GRXFSIZ_DEPTH_SHIFT;
651323230efSJohn Youn 
652323230efSJohn Youn 	return 0;
653323230efSJohn Youn }
654323230efSJohn Youn 
655334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg)
656334bbd4eSJohn Youn {
6577de1debcSJohn Youn 	const struct of_device_id *match;
6587de1debcSJohn Youn 	void (*set_params)(void *data);
6597de1debcSJohn Youn 
660245977c9SJohn Youn 	dwc2_set_default_params(hsotg);
661f9f93cbbSJohn Youn 	dwc2_get_device_properties(hsotg);
662334bbd4eSJohn Youn 
6637de1debcSJohn Youn 	match = of_match_device(dwc2_of_match_table, hsotg->dev);
6647de1debcSJohn Youn 	if (match && match->data) {
6657de1debcSJohn Youn 		set_params = match->data;
6667de1debcSJohn Youn 		set_params(hsotg);
6677de1debcSJohn Youn 	}
6687de1debcSJohn Youn 
669d936e666SJohn Youn 	dwc2_check_params(hsotg);
670d936e666SJohn Youn 
671334bbd4eSJohn Youn 	return 0;
672334bbd4eSJohn Youn }
673