xref: /openbmc/linux/drivers/usb/dwc2/params.c (revision 6b66ce51e212da3efe293a99541d850708b65ed3)
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 
41323230efSJohn Youn static const struct dwc2_core_params params_hi6220 = {
42323230efSJohn Youn 	.otg_cap			= 2,	/* No HNP/SRP capable */
43323230efSJohn Youn 	.otg_ver			= 0,	/* 1.3 */
44323230efSJohn Youn 	.dma_desc_enable		= 0,
45323230efSJohn Youn 	.dma_desc_fs_enable		= 0,
46323230efSJohn Youn 	.speed				= 0,	/* High Speed */
47323230efSJohn Youn 	.enable_dynamic_fifo		= 1,
48323230efSJohn Youn 	.en_multiple_tx_fifo		= 1,
49323230efSJohn Youn 	.host_rx_fifo_size		= 512,
50323230efSJohn Youn 	.host_nperio_tx_fifo_size	= 512,
51323230efSJohn Youn 	.host_perio_tx_fifo_size	= 512,
52323230efSJohn Youn 	.max_transfer_size		= 65535,
53323230efSJohn Youn 	.max_packet_count		= 511,
54323230efSJohn Youn 	.host_channels			= 16,
55323230efSJohn Youn 	.phy_type			= 1,	/* UTMI */
56323230efSJohn Youn 	.phy_utmi_width			= 8,
57323230efSJohn Youn 	.phy_ulpi_ddr			= 0,	/* Single */
58323230efSJohn Youn 	.phy_ulpi_ext_vbus		= 0,
59323230efSJohn Youn 	.i2c_enable			= 0,
60323230efSJohn Youn 	.ulpi_fs_ls			= 0,
61323230efSJohn Youn 	.host_support_fs_ls_low_power	= 0,
62323230efSJohn Youn 	.host_ls_low_power_phy_clk	= 0,	/* 48 MHz */
63323230efSJohn Youn 	.ts_dline			= 0,
64323230efSJohn Youn 	.reload_ctl			= 0,
65323230efSJohn Youn 	.ahbcfg				= GAHBCFG_HBSTLEN_INCR16 <<
66323230efSJohn Youn 					  GAHBCFG_HBSTLEN_SHIFT,
67323230efSJohn Youn 	.uframe_sched			= 0,
68323230efSJohn Youn 	.external_id_pin_ctl		= -1,
69323230efSJohn Youn 	.hibernation			= -1,
70323230efSJohn Youn };
71323230efSJohn Youn 
72323230efSJohn Youn static const struct dwc2_core_params params_bcm2835 = {
73323230efSJohn Youn 	.otg_cap			= 0,	/* HNP/SRP capable */
74323230efSJohn Youn 	.otg_ver			= 0,	/* 1.3 */
75323230efSJohn Youn 	.dma_desc_enable		= 0,
76323230efSJohn Youn 	.dma_desc_fs_enable		= 0,
77323230efSJohn Youn 	.speed				= 0,	/* High Speed */
78323230efSJohn Youn 	.enable_dynamic_fifo		= 1,
79323230efSJohn Youn 	.en_multiple_tx_fifo		= 1,
80323230efSJohn Youn 	.host_rx_fifo_size		= 774,	/* 774 DWORDs */
81323230efSJohn Youn 	.host_nperio_tx_fifo_size	= 256,	/* 256 DWORDs */
82323230efSJohn Youn 	.host_perio_tx_fifo_size	= 512,	/* 512 DWORDs */
83323230efSJohn Youn 	.max_transfer_size		= 65535,
84323230efSJohn Youn 	.max_packet_count		= 511,
85323230efSJohn Youn 	.host_channels			= 8,
86323230efSJohn Youn 	.phy_type			= 1,	/* UTMI */
87323230efSJohn Youn 	.phy_utmi_width			= 8,	/* 8 bits */
88323230efSJohn Youn 	.phy_ulpi_ddr			= 0,	/* Single */
89323230efSJohn Youn 	.phy_ulpi_ext_vbus		= 0,
90323230efSJohn Youn 	.i2c_enable			= 0,
91323230efSJohn Youn 	.ulpi_fs_ls			= 0,
92323230efSJohn Youn 	.host_support_fs_ls_low_power	= 0,
93323230efSJohn Youn 	.host_ls_low_power_phy_clk	= 0,	/* 48 MHz */
94323230efSJohn Youn 	.ts_dline			= 0,
95323230efSJohn Youn 	.reload_ctl			= 0,
96323230efSJohn Youn 	.ahbcfg				= 0x10,
97323230efSJohn Youn 	.uframe_sched			= 0,
98323230efSJohn Youn 	.external_id_pin_ctl		= -1,
99323230efSJohn Youn 	.hibernation			= -1,
100323230efSJohn Youn };
101323230efSJohn Youn 
102323230efSJohn Youn static const struct dwc2_core_params params_rk3066 = {
103323230efSJohn Youn 	.otg_cap			= 2,	/* non-HNP/non-SRP */
104323230efSJohn Youn 	.otg_ver			= -1,
105323230efSJohn Youn 	.dma_desc_enable		= 0,
106323230efSJohn Youn 	.dma_desc_fs_enable		= 0,
107323230efSJohn Youn 	.speed				= -1,
108323230efSJohn Youn 	.enable_dynamic_fifo		= 1,
109323230efSJohn Youn 	.en_multiple_tx_fifo		= -1,
110323230efSJohn Youn 	.host_rx_fifo_size		= 525,	/* 525 DWORDs */
111323230efSJohn Youn 	.host_nperio_tx_fifo_size	= 128,	/* 128 DWORDs */
112323230efSJohn Youn 	.host_perio_tx_fifo_size	= 256,	/* 256 DWORDs */
113323230efSJohn Youn 	.max_transfer_size		= -1,
114323230efSJohn Youn 	.max_packet_count		= -1,
115323230efSJohn Youn 	.host_channels			= -1,
116323230efSJohn Youn 	.phy_type			= -1,
117323230efSJohn Youn 	.phy_utmi_width			= -1,
118323230efSJohn Youn 	.phy_ulpi_ddr			= -1,
119323230efSJohn Youn 	.phy_ulpi_ext_vbus		= -1,
120323230efSJohn Youn 	.i2c_enable			= -1,
121323230efSJohn Youn 	.ulpi_fs_ls			= -1,
122323230efSJohn Youn 	.host_support_fs_ls_low_power	= -1,
123323230efSJohn Youn 	.host_ls_low_power_phy_clk	= -1,
124323230efSJohn Youn 	.ts_dline			= -1,
125323230efSJohn Youn 	.reload_ctl			= -1,
126323230efSJohn Youn 	.ahbcfg				= GAHBCFG_HBSTLEN_INCR16 <<
127323230efSJohn Youn 					  GAHBCFG_HBSTLEN_SHIFT,
128323230efSJohn Youn 	.uframe_sched			= -1,
129323230efSJohn Youn 	.external_id_pin_ctl		= -1,
130323230efSJohn Youn 	.hibernation			= -1,
131323230efSJohn Youn };
132323230efSJohn Youn 
133323230efSJohn Youn static const struct dwc2_core_params params_ltq = {
134323230efSJohn Youn 	.otg_cap			= 2,	/* non-HNP/non-SRP */
135323230efSJohn Youn 	.otg_ver			= -1,
136323230efSJohn Youn 	.dma_desc_enable		= -1,
137323230efSJohn Youn 	.dma_desc_fs_enable		= -1,
138323230efSJohn Youn 	.speed				= -1,
139323230efSJohn Youn 	.enable_dynamic_fifo		= -1,
140323230efSJohn Youn 	.en_multiple_tx_fifo		= -1,
141323230efSJohn Youn 	.host_rx_fifo_size		= 288,	/* 288 DWORDs */
142323230efSJohn Youn 	.host_nperio_tx_fifo_size	= 128,	/* 128 DWORDs */
143323230efSJohn Youn 	.host_perio_tx_fifo_size	= 96,	/* 96 DWORDs */
144323230efSJohn Youn 	.max_transfer_size		= 65535,
145323230efSJohn Youn 	.max_packet_count		= 511,
146323230efSJohn Youn 	.host_channels			= -1,
147323230efSJohn Youn 	.phy_type			= -1,
148323230efSJohn Youn 	.phy_utmi_width			= -1,
149323230efSJohn Youn 	.phy_ulpi_ddr			= -1,
150323230efSJohn Youn 	.phy_ulpi_ext_vbus		= -1,
151323230efSJohn Youn 	.i2c_enable			= -1,
152323230efSJohn Youn 	.ulpi_fs_ls			= -1,
153323230efSJohn Youn 	.host_support_fs_ls_low_power	= -1,
154323230efSJohn Youn 	.host_ls_low_power_phy_clk	= -1,
155323230efSJohn Youn 	.ts_dline			= -1,
156323230efSJohn Youn 	.reload_ctl			= -1,
157323230efSJohn Youn 	.ahbcfg				= GAHBCFG_HBSTLEN_INCR16 <<
158323230efSJohn Youn 					  GAHBCFG_HBSTLEN_SHIFT,
159323230efSJohn Youn 	.uframe_sched			= -1,
160323230efSJohn Youn 	.external_id_pin_ctl		= -1,
161323230efSJohn Youn 	.hibernation			= -1,
162323230efSJohn Youn };
163323230efSJohn Youn 
164323230efSJohn Youn static const struct dwc2_core_params params_amlogic = {
165323230efSJohn Youn 	.otg_cap			= DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE,
166323230efSJohn Youn 	.otg_ver			= -1,
167323230efSJohn Youn 	.dma_desc_enable		= 0,
168323230efSJohn Youn 	.dma_desc_fs_enable		= 0,
169323230efSJohn Youn 	.speed				= DWC2_SPEED_PARAM_HIGH,
170323230efSJohn Youn 	.enable_dynamic_fifo		= 1,
171323230efSJohn Youn 	.en_multiple_tx_fifo		= -1,
172323230efSJohn Youn 	.host_rx_fifo_size		= 512,
173323230efSJohn Youn 	.host_nperio_tx_fifo_size	= 500,
174323230efSJohn Youn 	.host_perio_tx_fifo_size	= 500,
175323230efSJohn Youn 	.max_transfer_size		= -1,
176323230efSJohn Youn 	.max_packet_count		= -1,
177323230efSJohn Youn 	.host_channels			= 16,
178323230efSJohn Youn 	.phy_type			= DWC2_PHY_TYPE_PARAM_UTMI,
179323230efSJohn Youn 	.phy_utmi_width			= -1,
180323230efSJohn Youn 	.phy_ulpi_ddr			= -1,
181323230efSJohn Youn 	.phy_ulpi_ext_vbus		= -1,
182323230efSJohn Youn 	.i2c_enable			= -1,
183323230efSJohn Youn 	.ulpi_fs_ls			= -1,
184323230efSJohn Youn 	.host_support_fs_ls_low_power	= -1,
185323230efSJohn Youn 	.host_ls_low_power_phy_clk	= -1,
186323230efSJohn Youn 	.ts_dline			= -1,
187323230efSJohn Youn 	.reload_ctl			= 1,
188323230efSJohn Youn 	.ahbcfg				= GAHBCFG_HBSTLEN_INCR8 <<
189323230efSJohn Youn 					  GAHBCFG_HBSTLEN_SHIFT,
190323230efSJohn Youn 	.uframe_sched			= 0,
191323230efSJohn Youn 	.external_id_pin_ctl		= -1,
192323230efSJohn Youn 	.hibernation			= -1,
193323230efSJohn Youn };
194323230efSJohn Youn 
1950a7d0d7fSJohn Youn static const struct dwc2_core_params params_default = {
1960a7d0d7fSJohn Youn 	.otg_cap			= -1,
1970a7d0d7fSJohn Youn 	.otg_ver			= -1,
1980a7d0d7fSJohn Youn 
1990a7d0d7fSJohn Youn 	/*
2000a7d0d7fSJohn Youn 	 * Disable descriptor dma mode by default as the HW can support
2010a7d0d7fSJohn Youn 	 * it, but does not support it for SPLIT transactions.
2020a7d0d7fSJohn Youn 	 * Disable it for FS devices as well.
2030a7d0d7fSJohn Youn 	 */
2040a7d0d7fSJohn Youn 	.dma_desc_enable		= 0,
2050a7d0d7fSJohn Youn 	.dma_desc_fs_enable		= 0,
2060a7d0d7fSJohn Youn 
2070a7d0d7fSJohn Youn 	.speed				= -1,
2080a7d0d7fSJohn Youn 	.enable_dynamic_fifo		= -1,
2090a7d0d7fSJohn Youn 	.en_multiple_tx_fifo		= -1,
2100a7d0d7fSJohn Youn 	.host_rx_fifo_size		= -1,
2110a7d0d7fSJohn Youn 	.host_nperio_tx_fifo_size	= -1,
2120a7d0d7fSJohn Youn 	.host_perio_tx_fifo_size	= -1,
2130a7d0d7fSJohn Youn 	.max_transfer_size		= -1,
2140a7d0d7fSJohn Youn 	.max_packet_count		= -1,
2150a7d0d7fSJohn Youn 	.host_channels			= -1,
2160a7d0d7fSJohn Youn 	.phy_type			= -1,
2170a7d0d7fSJohn Youn 	.phy_utmi_width			= -1,
2180a7d0d7fSJohn Youn 	.phy_ulpi_ddr			= -1,
2190a7d0d7fSJohn Youn 	.phy_ulpi_ext_vbus		= -1,
2200a7d0d7fSJohn Youn 	.i2c_enable			= -1,
2210a7d0d7fSJohn Youn 	.ulpi_fs_ls			= -1,
2220a7d0d7fSJohn Youn 	.host_support_fs_ls_low_power	= -1,
2230a7d0d7fSJohn Youn 	.host_ls_low_power_phy_clk	= -1,
2240a7d0d7fSJohn Youn 	.ts_dline			= -1,
2250a7d0d7fSJohn Youn 	.reload_ctl			= -1,
2260a7d0d7fSJohn Youn 	.ahbcfg				= -1,
2270a7d0d7fSJohn Youn 	.uframe_sched			= -1,
2280a7d0d7fSJohn Youn 	.external_id_pin_ctl		= -1,
2290a7d0d7fSJohn Youn 	.hibernation			= -1,
2300a7d0d7fSJohn Youn };
2310a7d0d7fSJohn Youn 
232323230efSJohn Youn const struct of_device_id dwc2_of_match_table[] = {
233323230efSJohn Youn 	{ .compatible = "brcm,bcm2835-usb", .data = &params_bcm2835 },
234323230efSJohn Youn 	{ .compatible = "hisilicon,hi6220-usb", .data = &params_hi6220 },
235323230efSJohn Youn 	{ .compatible = "rockchip,rk3066-usb", .data = &params_rk3066 },
236323230efSJohn Youn 	{ .compatible = "lantiq,arx100-usb", .data = &params_ltq },
237323230efSJohn Youn 	{ .compatible = "lantiq,xrx200-usb", .data = &params_ltq },
238323230efSJohn Youn 	{ .compatible = "snps,dwc2", .data = NULL },
239323230efSJohn Youn 	{ .compatible = "samsung,s3c6400-hsotg", .data = NULL},
240323230efSJohn Youn 	{ .compatible = "amlogic,meson8b-usb", .data = &params_amlogic },
241323230efSJohn Youn 	{ .compatible = "amlogic,meson-gxbb-usb", .data = &params_amlogic },
242323230efSJohn Youn 	{},
243323230efSJohn Youn };
244323230efSJohn Youn MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
245323230efSJohn Youn 
24605ee799fSJohn Youn static void dwc2_get_device_property(struct dwc2_hsotg *hsotg,
24705ee799fSJohn Youn 				     char *property, u8 size, u64 *value)
24805ee799fSJohn Youn {
24905ee799fSJohn Youn 	u8 val8;
25005ee799fSJohn Youn 	u16 val16;
25105ee799fSJohn Youn 	u32 val32;
25205ee799fSJohn Youn 
25305ee799fSJohn Youn 	switch (size) {
25405ee799fSJohn Youn 	case 0:
25505ee799fSJohn Youn 		*value = device_property_read_bool(hsotg->dev, property);
25605ee799fSJohn Youn 		break;
25705ee799fSJohn Youn 	case 1:
25805ee799fSJohn Youn 		if (device_property_read_u8(hsotg->dev, property, &val8))
25905ee799fSJohn Youn 			return;
26005ee799fSJohn Youn 
26105ee799fSJohn Youn 		*value = val8;
26205ee799fSJohn Youn 		break;
26305ee799fSJohn Youn 	case 2:
26405ee799fSJohn Youn 		if (device_property_read_u16(hsotg->dev, property, &val16))
26505ee799fSJohn Youn 			return;
26605ee799fSJohn Youn 
26705ee799fSJohn Youn 		*value = val16;
26805ee799fSJohn Youn 		break;
26905ee799fSJohn Youn 	case 4:
27005ee799fSJohn Youn 		if (device_property_read_u32(hsotg->dev, property, &val32))
27105ee799fSJohn Youn 			return;
27205ee799fSJohn Youn 
27305ee799fSJohn Youn 		*value = val32;
27405ee799fSJohn Youn 		break;
27505ee799fSJohn Youn 	case 8:
27605ee799fSJohn Youn 		if (device_property_read_u64(hsotg->dev, property, value))
27705ee799fSJohn Youn 			return;
27805ee799fSJohn Youn 
27905ee799fSJohn Youn 		break;
28005ee799fSJohn Youn 	default:
28105ee799fSJohn Youn 		/*
28205ee799fSJohn Youn 		 * The size is checked by the only function that calls
28305ee799fSJohn Youn 		 * this so this should never happen.
28405ee799fSJohn Youn 		 */
28505ee799fSJohn Youn 		WARN_ON(1);
28605ee799fSJohn Youn 		return;
28705ee799fSJohn Youn 	}
28805ee799fSJohn Youn }
28905ee799fSJohn Youn 
29005ee799fSJohn Youn static void dwc2_set_core_param(void *param, u8 size, u64 value)
29105ee799fSJohn Youn {
29205ee799fSJohn Youn 	switch (size) {
29305ee799fSJohn Youn 	case 0:
29405ee799fSJohn Youn 		*((bool *)param) = !!value;
29505ee799fSJohn Youn 		break;
29605ee799fSJohn Youn 	case 1:
29705ee799fSJohn Youn 		*((u8 *)param) = (u8)value;
29805ee799fSJohn Youn 		break;
29905ee799fSJohn Youn 	case 2:
30005ee799fSJohn Youn 		*((u16 *)param) = (u16)value;
30105ee799fSJohn Youn 		break;
30205ee799fSJohn Youn 	case 4:
30305ee799fSJohn Youn 		*((u32 *)param) = (u32)value;
30405ee799fSJohn Youn 		break;
30505ee799fSJohn Youn 	case 8:
30605ee799fSJohn Youn 		*((u64 *)param) = (u64)value;
30705ee799fSJohn Youn 		break;
30805ee799fSJohn Youn 	default:
30905ee799fSJohn Youn 		/*
31005ee799fSJohn Youn 		 * The size is checked by the only function that calls
31105ee799fSJohn Youn 		 * this so this should never happen.
31205ee799fSJohn Youn 		 */
31305ee799fSJohn Youn 		WARN_ON(1);
31405ee799fSJohn Youn 		return;
31505ee799fSJohn Youn 	}
31605ee799fSJohn Youn }
31705ee799fSJohn Youn 
31805ee799fSJohn Youn /**
31905ee799fSJohn Youn  * dwc2_set_param() - Set a core parameter
32005ee799fSJohn Youn  *
32105ee799fSJohn Youn  * @hsotg: Programming view of the DWC_otg controller
32205ee799fSJohn Youn  * @param: Pointer to the parameter to set
32305ee799fSJohn Youn  * @lookup: True if the property should be looked up
32405ee799fSJohn Youn  * @property: The device property to read
32505ee799fSJohn Youn  * @legacy: The param value to set if @property is not available. This
32605ee799fSJohn Youn  *          will typically be the legacy value set in the static
32705ee799fSJohn Youn  *          params structure.
32805ee799fSJohn Youn  * @def: The default value
32905ee799fSJohn Youn  * @min: The minimum value
33005ee799fSJohn Youn  * @max: The maximum value
33105ee799fSJohn Youn  * @size: The size of the core parameter in bytes, or 0 for bool.
33205ee799fSJohn Youn  *
33305ee799fSJohn Youn  * This function looks up @property and sets the @param to that value.
33405ee799fSJohn Youn  * If the property doesn't exist it uses the passed-in @value. It will
33505ee799fSJohn Youn  * verify that the value falls between @min and @max. If it doesn't,
33605ee799fSJohn Youn  * it will output an error and set the parameter to either @def or,
33705ee799fSJohn Youn  * failing that, to @min.
33805ee799fSJohn Youn  *
33905ee799fSJohn Youn  * The @size is used to write to @param and to query the device
34005ee799fSJohn Youn  * properties so that this same function can be used with different
34105ee799fSJohn Youn  * types of parameters.
34205ee799fSJohn Youn  */
34305ee799fSJohn Youn static void dwc2_set_param(struct dwc2_hsotg *hsotg, void *param,
34405ee799fSJohn Youn 			   bool lookup, char *property, u64 legacy,
34505ee799fSJohn Youn 			   u64 def, u64 min, u64 max, u8 size)
34605ee799fSJohn Youn {
34705ee799fSJohn Youn 	u64 sizemax;
34805ee799fSJohn Youn 	u64 value;
34905ee799fSJohn Youn 
35005ee799fSJohn Youn 	if (WARN_ON(!hsotg || !param || !property))
35105ee799fSJohn Youn 		return;
35205ee799fSJohn Youn 
35305ee799fSJohn Youn 	if (WARN((size > 8) || ((size & (size - 1)) != 0),
35405ee799fSJohn Youn 		 "Invalid size %d for %s\n", size, property))
35505ee799fSJohn Youn 		return;
35605ee799fSJohn Youn 
35705ee799fSJohn Youn 	dev_vdbg(hsotg->dev, "%s: Setting %s: legacy=%llu, def=%llu, min=%llu, max=%llu, size=%d\n",
35805ee799fSJohn Youn 		 __func__, property, legacy, def, min, max, size);
35905ee799fSJohn Youn 
36005ee799fSJohn Youn 	sizemax = (1ULL << (size * 8)) - 1;
36105ee799fSJohn Youn 	value = legacy;
36205ee799fSJohn Youn 
36305ee799fSJohn Youn 	/* Override legacy settings. */
36405ee799fSJohn Youn 	if (lookup)
36505ee799fSJohn Youn 		dwc2_get_device_property(hsotg, property, size, &value);
36605ee799fSJohn Youn 
36705ee799fSJohn Youn 	/*
36805ee799fSJohn Youn 	 * While the value is not valid, try setting it to the default
36905ee799fSJohn Youn 	 * value, and failing that, set it to the minimum.
37005ee799fSJohn Youn 	 */
37105ee799fSJohn Youn 	while ((value < min) || (value > max)) {
37205ee799fSJohn Youn 		/* Print an error unless the value is set to auto. */
37305ee799fSJohn Youn 		if (value != sizemax)
37405ee799fSJohn Youn 			dev_err(hsotg->dev, "Invalid value %llu for param %s\n",
37505ee799fSJohn Youn 				value, property);
37605ee799fSJohn Youn 
37705ee799fSJohn Youn 		/*
37805ee799fSJohn Youn 		 * If we are already the default, just set it to the
37905ee799fSJohn Youn 		 * minimum.
38005ee799fSJohn Youn 		 */
38105ee799fSJohn Youn 		if (value == def) {
38205ee799fSJohn Youn 			dev_vdbg(hsotg->dev, "%s: setting value to min=%llu\n",
38305ee799fSJohn Youn 				 __func__, min);
38405ee799fSJohn Youn 			value = min;
38505ee799fSJohn Youn 			break;
38605ee799fSJohn Youn 		}
38705ee799fSJohn Youn 
38805ee799fSJohn Youn 		/* Try the default value */
38905ee799fSJohn Youn 		dev_vdbg(hsotg->dev, "%s: setting value to default=%llu\n",
39005ee799fSJohn Youn 			 __func__, def);
39105ee799fSJohn Youn 		value = def;
39205ee799fSJohn Youn 	}
39305ee799fSJohn Youn 
39405ee799fSJohn Youn 	dev_dbg(hsotg->dev, "Setting %s to %llu\n", property, value);
39505ee799fSJohn Youn 	dwc2_set_core_param(param, size, value);
39605ee799fSJohn Youn }
39705ee799fSJohn Youn 
39805ee799fSJohn Youn /**
39905ee799fSJohn Youn  * dwc2_set_param_u16() - Set a u16 parameter
40005ee799fSJohn Youn  *
40105ee799fSJohn Youn  * See dwc2_set_param().
40205ee799fSJohn Youn  */
40305ee799fSJohn Youn static void dwc2_set_param_u16(struct dwc2_hsotg *hsotg, u16 *param,
40405ee799fSJohn Youn 			       bool lookup, char *property, u16 legacy,
40505ee799fSJohn Youn 			       u16 def, u16 min, u16 max)
40605ee799fSJohn Youn {
40705ee799fSJohn Youn 	dwc2_set_param(hsotg, param, lookup, property,
40805ee799fSJohn Youn 		       legacy, def, min, max, 2);
40905ee799fSJohn Youn }
41005ee799fSJohn Youn 
41105ee799fSJohn Youn /**
41205ee799fSJohn Youn  * dwc2_set_param_bool() - Set a bool parameter
41305ee799fSJohn Youn  *
41405ee799fSJohn Youn  * See dwc2_set_param().
41505ee799fSJohn Youn  *
41605ee799fSJohn Youn  * Note: there is no 'legacy' argument here because there is no legacy
41705ee799fSJohn Youn  * source of bool params.
41805ee799fSJohn Youn  */
41905ee799fSJohn Youn static void dwc2_set_param_bool(struct dwc2_hsotg *hsotg, bool *param,
42005ee799fSJohn Youn 				bool lookup, char *property,
42105ee799fSJohn Youn 				bool def, bool min, bool max)
42205ee799fSJohn Youn {
42305ee799fSJohn Youn 	dwc2_set_param(hsotg, param, lookup, property,
42405ee799fSJohn Youn 		       def, def, min, max, 0);
42505ee799fSJohn Youn }
42605ee799fSJohn Youn 
427323230efSJohn Youn #define DWC2_OUT_OF_BOUNDS(a, b, c)	((a) < (b) || (a) > (c))
428323230efSJohn Youn 
429323230efSJohn Youn /* Parameter access functions */
430c1d286cfSJohn Youn static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
431323230efSJohn Youn {
432323230efSJohn Youn 	int valid = 1;
433323230efSJohn Youn 
434323230efSJohn Youn 	switch (val) {
435323230efSJohn Youn 	case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
436323230efSJohn Youn 		if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
437323230efSJohn Youn 			valid = 0;
438323230efSJohn Youn 		break;
439323230efSJohn Youn 	case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
440323230efSJohn Youn 		switch (hsotg->hw_params.op_mode) {
441323230efSJohn Youn 		case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
442323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
443323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
444323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
445323230efSJohn Youn 			break;
446323230efSJohn Youn 		default:
447323230efSJohn Youn 			valid = 0;
448323230efSJohn Youn 			break;
449323230efSJohn Youn 		}
450323230efSJohn Youn 		break;
451323230efSJohn Youn 	case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
452323230efSJohn Youn 		/* always valid */
453323230efSJohn Youn 		break;
454323230efSJohn Youn 	default:
455323230efSJohn Youn 		valid = 0;
456323230efSJohn Youn 		break;
457323230efSJohn Youn 	}
458323230efSJohn Youn 
459323230efSJohn Youn 	if (!valid) {
460323230efSJohn Youn 		if (val >= 0)
461323230efSJohn Youn 			dev_err(hsotg->dev,
462323230efSJohn Youn 				"%d invalid for otg_cap parameter. Check HW configuration.\n",
463323230efSJohn Youn 				val);
464323230efSJohn Youn 		switch (hsotg->hw_params.op_mode) {
465323230efSJohn Youn 		case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
466323230efSJohn Youn 			val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
467323230efSJohn Youn 			break;
468323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
469323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
470323230efSJohn Youn 		case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
471323230efSJohn Youn 			val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
472323230efSJohn Youn 			break;
473323230efSJohn Youn 		default:
474323230efSJohn Youn 			val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
475323230efSJohn Youn 			break;
476323230efSJohn Youn 		}
477323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val);
478323230efSJohn Youn 	}
479323230efSJohn Youn 
480bea8e86cSJohn Youn 	hsotg->params.otg_cap = val;
481323230efSJohn Youn }
482323230efSJohn Youn 
483c1d286cfSJohn Youn static void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
484323230efSJohn Youn {
485323230efSJohn Youn 	int valid = 1;
486323230efSJohn Youn 
487e7839f99SJohn Youn 	if (val > 0 && (hsotg->params.host_dma <= 0 ||
488323230efSJohn Youn 			!hsotg->hw_params.dma_desc_enable))
489323230efSJohn Youn 		valid = 0;
490323230efSJohn Youn 	if (val < 0)
491323230efSJohn Youn 		valid = 0;
492323230efSJohn Youn 
493323230efSJohn Youn 	if (!valid) {
494323230efSJohn Youn 		if (val >= 0)
495323230efSJohn Youn 			dev_err(hsotg->dev,
496323230efSJohn Youn 				"%d invalid for dma_desc_enable parameter. Check HW configuration.\n",
497323230efSJohn Youn 				val);
498e7839f99SJohn Youn 		val = (hsotg->params.host_dma > 0 &&
499323230efSJohn Youn 			hsotg->hw_params.dma_desc_enable);
500323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val);
501323230efSJohn Youn 	}
502323230efSJohn Youn 
503bea8e86cSJohn Youn 	hsotg->params.dma_desc_enable = val;
504323230efSJohn Youn }
505323230efSJohn Youn 
506c1d286cfSJohn Youn static void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val)
507323230efSJohn Youn {
508323230efSJohn Youn 	int valid = 1;
509323230efSJohn Youn 
510e7839f99SJohn Youn 	if (val > 0 && (hsotg->params.host_dma <= 0 ||
511323230efSJohn Youn 			!hsotg->hw_params.dma_desc_enable))
512323230efSJohn Youn 		valid = 0;
513323230efSJohn Youn 	if (val < 0)
514323230efSJohn Youn 		valid = 0;
515323230efSJohn Youn 
516323230efSJohn Youn 	if (!valid) {
517323230efSJohn Youn 		if (val >= 0)
518323230efSJohn Youn 			dev_err(hsotg->dev,
519323230efSJohn Youn 				"%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n",
520323230efSJohn Youn 				val);
521e7839f99SJohn Youn 		val = (hsotg->params.host_dma > 0 &&
522323230efSJohn Youn 			hsotg->hw_params.dma_desc_enable);
523323230efSJohn Youn 	}
524323230efSJohn Youn 
525bea8e86cSJohn Youn 	hsotg->params.dma_desc_fs_enable = val;
526323230efSJohn Youn 	dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val);
527323230efSJohn Youn }
528323230efSJohn Youn 
529c1d286cfSJohn Youn static void
530c1d286cfSJohn Youn dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
531323230efSJohn Youn 					    int val)
532323230efSJohn Youn {
533323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
534323230efSJohn Youn 		if (val >= 0) {
535323230efSJohn Youn 			dev_err(hsotg->dev,
536323230efSJohn Youn 				"Wrong value for host_support_fs_low_power\n");
537323230efSJohn Youn 			dev_err(hsotg->dev,
538323230efSJohn Youn 				"host_support_fs_low_power must be 0 or 1\n");
539323230efSJohn Youn 		}
540323230efSJohn Youn 		val = 0;
541323230efSJohn Youn 		dev_dbg(hsotg->dev,
542323230efSJohn Youn 			"Setting host_support_fs_low_power to %d\n", val);
543323230efSJohn Youn 	}
544323230efSJohn Youn 
545bea8e86cSJohn Youn 	hsotg->params.host_support_fs_ls_low_power = val;
546323230efSJohn Youn }
547323230efSJohn Youn 
548c1d286cfSJohn Youn static void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
549c1d286cfSJohn Youn 					       int val)
550323230efSJohn Youn {
551323230efSJohn Youn 	int valid = 1;
552323230efSJohn Youn 
553323230efSJohn Youn 	if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo)
554323230efSJohn Youn 		valid = 0;
555323230efSJohn Youn 	if (val < 0)
556323230efSJohn Youn 		valid = 0;
557323230efSJohn Youn 
558323230efSJohn Youn 	if (!valid) {
559323230efSJohn Youn 		if (val >= 0)
560323230efSJohn Youn 			dev_err(hsotg->dev,
561323230efSJohn Youn 				"%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n",
562323230efSJohn Youn 				val);
563323230efSJohn Youn 		val = hsotg->hw_params.enable_dynamic_fifo;
564323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val);
565323230efSJohn Youn 	}
566323230efSJohn Youn 
567bea8e86cSJohn Youn 	hsotg->params.enable_dynamic_fifo = val;
568323230efSJohn Youn }
569323230efSJohn Youn 
570c1d286cfSJohn Youn static void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
571323230efSJohn Youn {
572323230efSJohn Youn 	int valid = 1;
573323230efSJohn Youn 
574d1531319SJohn Youn 	if (val < 16 || val > hsotg->hw_params.rx_fifo_size)
575323230efSJohn Youn 		valid = 0;
576323230efSJohn Youn 
577323230efSJohn Youn 	if (!valid) {
578323230efSJohn Youn 		if (val >= 0)
579323230efSJohn Youn 			dev_err(hsotg->dev,
580323230efSJohn Youn 				"%d invalid for host_rx_fifo_size. Check HW configuration.\n",
581323230efSJohn Youn 				val);
582d1531319SJohn Youn 		val = hsotg->hw_params.rx_fifo_size;
583323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
584323230efSJohn Youn 	}
585323230efSJohn Youn 
586bea8e86cSJohn Youn 	hsotg->params.host_rx_fifo_size = val;
587323230efSJohn Youn }
588323230efSJohn Youn 
589c1d286cfSJohn Youn static void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
590c1d286cfSJohn Youn 						    int val)
591323230efSJohn Youn {
592323230efSJohn Youn 	int valid = 1;
593323230efSJohn Youn 
594323230efSJohn Youn 	if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size)
595323230efSJohn Youn 		valid = 0;
596323230efSJohn Youn 
597323230efSJohn Youn 	if (!valid) {
598323230efSJohn Youn 		if (val >= 0)
599323230efSJohn Youn 			dev_err(hsotg->dev,
600323230efSJohn Youn 				"%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
601323230efSJohn Youn 				val);
602323230efSJohn Youn 		val = hsotg->hw_params.host_nperio_tx_fifo_size;
603323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n",
604323230efSJohn Youn 			val);
605323230efSJohn Youn 	}
606323230efSJohn Youn 
607bea8e86cSJohn Youn 	hsotg->params.host_nperio_tx_fifo_size = val;
608323230efSJohn Youn }
609323230efSJohn Youn 
610c1d286cfSJohn Youn static void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
611c1d286cfSJohn Youn 						   int val)
612323230efSJohn Youn {
613323230efSJohn Youn 	int valid = 1;
614323230efSJohn Youn 
615323230efSJohn Youn 	if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size)
616323230efSJohn Youn 		valid = 0;
617323230efSJohn Youn 
618323230efSJohn Youn 	if (!valid) {
619323230efSJohn Youn 		if (val >= 0)
620323230efSJohn Youn 			dev_err(hsotg->dev,
621323230efSJohn Youn 				"%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
622323230efSJohn Youn 				val);
623323230efSJohn Youn 		val = hsotg->hw_params.host_perio_tx_fifo_size;
624323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n",
625323230efSJohn Youn 			val);
626323230efSJohn Youn 	}
627323230efSJohn Youn 
628bea8e86cSJohn Youn 	hsotg->params.host_perio_tx_fifo_size = val;
629323230efSJohn Youn }
630323230efSJohn Youn 
631c1d286cfSJohn Youn static void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
632323230efSJohn Youn {
633323230efSJohn Youn 	int valid = 1;
634323230efSJohn Youn 
635323230efSJohn Youn 	if (val < 2047 || val > hsotg->hw_params.max_transfer_size)
636323230efSJohn Youn 		valid = 0;
637323230efSJohn Youn 
638323230efSJohn Youn 	if (!valid) {
639323230efSJohn Youn 		if (val >= 0)
640323230efSJohn Youn 			dev_err(hsotg->dev,
641323230efSJohn Youn 				"%d invalid for max_transfer_size. Check HW configuration.\n",
642323230efSJohn Youn 				val);
643323230efSJohn Youn 		val = hsotg->hw_params.max_transfer_size;
644323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val);
645323230efSJohn Youn 	}
646323230efSJohn Youn 
647bea8e86cSJohn Youn 	hsotg->params.max_transfer_size = val;
648323230efSJohn Youn }
649323230efSJohn Youn 
650c1d286cfSJohn Youn static void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
651323230efSJohn Youn {
652323230efSJohn Youn 	int valid = 1;
653323230efSJohn Youn 
654323230efSJohn Youn 	if (val < 15 || val > hsotg->hw_params.max_packet_count)
655323230efSJohn Youn 		valid = 0;
656323230efSJohn Youn 
657323230efSJohn Youn 	if (!valid) {
658323230efSJohn Youn 		if (val >= 0)
659323230efSJohn Youn 			dev_err(hsotg->dev,
660323230efSJohn Youn 				"%d invalid for max_packet_count. Check HW configuration.\n",
661323230efSJohn Youn 				val);
662323230efSJohn Youn 		val = hsotg->hw_params.max_packet_count;
663323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val);
664323230efSJohn Youn 	}
665323230efSJohn Youn 
666bea8e86cSJohn Youn 	hsotg->params.max_packet_count = val;
667323230efSJohn Youn }
668323230efSJohn Youn 
669c1d286cfSJohn Youn static void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
670323230efSJohn Youn {
671323230efSJohn Youn 	int valid = 1;
672323230efSJohn Youn 
673323230efSJohn Youn 	if (val < 1 || val > hsotg->hw_params.host_channels)
674323230efSJohn Youn 		valid = 0;
675323230efSJohn Youn 
676323230efSJohn Youn 	if (!valid) {
677323230efSJohn Youn 		if (val >= 0)
678323230efSJohn Youn 			dev_err(hsotg->dev,
679323230efSJohn Youn 				"%d invalid for host_channels. Check HW configuration.\n",
680323230efSJohn Youn 				val);
681323230efSJohn Youn 		val = hsotg->hw_params.host_channels;
682323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val);
683323230efSJohn Youn 	}
684323230efSJohn Youn 
685bea8e86cSJohn Youn 	hsotg->params.host_channels = val;
686323230efSJohn Youn }
687323230efSJohn Youn 
688c1d286cfSJohn Youn static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
689323230efSJohn Youn {
690323230efSJohn Youn 	int valid = 0;
691323230efSJohn Youn 	u32 hs_phy_type, fs_phy_type;
692323230efSJohn Youn 
693323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS,
694323230efSJohn Youn 			       DWC2_PHY_TYPE_PARAM_ULPI)) {
695323230efSJohn Youn 		if (val >= 0) {
696323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for phy_type\n");
697323230efSJohn Youn 			dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n");
698323230efSJohn Youn 		}
699323230efSJohn Youn 
700323230efSJohn Youn 		valid = 0;
701323230efSJohn Youn 	}
702323230efSJohn Youn 
703323230efSJohn Youn 	hs_phy_type = hsotg->hw_params.hs_phy_type;
704323230efSJohn Youn 	fs_phy_type = hsotg->hw_params.fs_phy_type;
705323230efSJohn Youn 	if (val == DWC2_PHY_TYPE_PARAM_UTMI &&
706323230efSJohn Youn 	    (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
707323230efSJohn Youn 	     hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
708323230efSJohn Youn 		valid = 1;
709323230efSJohn Youn 	else if (val == DWC2_PHY_TYPE_PARAM_ULPI &&
710323230efSJohn Youn 		 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI ||
711323230efSJohn Youn 		  hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
712323230efSJohn Youn 		valid = 1;
713323230efSJohn Youn 	else if (val == DWC2_PHY_TYPE_PARAM_FS &&
714323230efSJohn Youn 		 fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
715323230efSJohn Youn 		valid = 1;
716323230efSJohn Youn 
717323230efSJohn Youn 	if (!valid) {
718323230efSJohn Youn 		if (val >= 0)
719323230efSJohn Youn 			dev_err(hsotg->dev,
720323230efSJohn Youn 				"%d invalid for phy_type. Check HW configuration.\n",
721323230efSJohn Youn 				val);
722323230efSJohn Youn 		val = DWC2_PHY_TYPE_PARAM_FS;
723323230efSJohn Youn 		if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
724323230efSJohn Youn 			if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
725323230efSJohn Youn 			    hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
726323230efSJohn Youn 				val = DWC2_PHY_TYPE_PARAM_UTMI;
727323230efSJohn Youn 			else
728323230efSJohn Youn 				val = DWC2_PHY_TYPE_PARAM_ULPI;
729323230efSJohn Youn 		}
730323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val);
731323230efSJohn Youn 	}
732323230efSJohn Youn 
733bea8e86cSJohn Youn 	hsotg->params.phy_type = val;
734323230efSJohn Youn }
735323230efSJohn Youn 
736323230efSJohn Youn static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg)
737323230efSJohn Youn {
738bea8e86cSJohn Youn 	return hsotg->params.phy_type;
739323230efSJohn Youn }
740323230efSJohn Youn 
741c1d286cfSJohn Youn static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val)
742323230efSJohn Youn {
743323230efSJohn Youn 	int valid = 1;
744323230efSJohn Youn 
745323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
746323230efSJohn Youn 		if (val >= 0) {
747323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for speed parameter\n");
748323230efSJohn Youn 			dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n");
749323230efSJohn Youn 		}
750323230efSJohn Youn 		valid = 0;
751323230efSJohn Youn 	}
752323230efSJohn Youn 
753323230efSJohn Youn 	if (val == DWC2_SPEED_PARAM_HIGH &&
754323230efSJohn Youn 	    dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
755323230efSJohn Youn 		valid = 0;
756323230efSJohn Youn 
757323230efSJohn Youn 	if (!valid) {
758323230efSJohn Youn 		if (val >= 0)
759323230efSJohn Youn 			dev_err(hsotg->dev,
760323230efSJohn Youn 				"%d invalid for speed parameter. Check HW configuration.\n",
761323230efSJohn Youn 				val);
762323230efSJohn Youn 		val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ?
763323230efSJohn Youn 				DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
764323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting speed to %d\n", val);
765323230efSJohn Youn 	}
766323230efSJohn Youn 
767bea8e86cSJohn Youn 	hsotg->params.speed = val;
768323230efSJohn Youn }
769323230efSJohn Youn 
770c1d286cfSJohn Youn static void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
771c1d286cfSJohn Youn 						     int val)
772323230efSJohn Youn {
773323230efSJohn Youn 	int valid = 1;
774323230efSJohn Youn 
775323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ,
776323230efSJohn Youn 			       DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) {
777323230efSJohn Youn 		if (val >= 0) {
778323230efSJohn Youn 			dev_err(hsotg->dev,
779323230efSJohn Youn 				"Wrong value for host_ls_low_power_phy_clk parameter\n");
780323230efSJohn Youn 			dev_err(hsotg->dev,
781323230efSJohn Youn 				"host_ls_low_power_phy_clk must be 0 or 1\n");
782323230efSJohn Youn 		}
783323230efSJohn Youn 		valid = 0;
784323230efSJohn Youn 	}
785323230efSJohn Youn 
786323230efSJohn Youn 	if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ &&
787323230efSJohn Youn 	    dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
788323230efSJohn Youn 		valid = 0;
789323230efSJohn Youn 
790323230efSJohn Youn 	if (!valid) {
791323230efSJohn Youn 		if (val >= 0)
792323230efSJohn Youn 			dev_err(hsotg->dev,
793323230efSJohn Youn 				"%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
794323230efSJohn Youn 				val);
795323230efSJohn Youn 		val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS
796323230efSJohn Youn 			? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ
797323230efSJohn Youn 			: DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
798323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n",
799323230efSJohn Youn 			val);
800323230efSJohn Youn 	}
801323230efSJohn Youn 
802bea8e86cSJohn Youn 	hsotg->params.host_ls_low_power_phy_clk = val;
803323230efSJohn Youn }
804323230efSJohn Youn 
805c1d286cfSJohn Youn static void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val)
806323230efSJohn Youn {
807323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
808323230efSJohn Youn 		if (val >= 0) {
809323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n");
810323230efSJohn Youn 			dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n");
811323230efSJohn Youn 		}
812323230efSJohn Youn 		val = 0;
813323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val);
814323230efSJohn Youn 	}
815323230efSJohn Youn 
816bea8e86cSJohn Youn 	hsotg->params.phy_ulpi_ddr = val;
817323230efSJohn Youn }
818323230efSJohn Youn 
819c1d286cfSJohn Youn static void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val)
820323230efSJohn Youn {
821323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
822323230efSJohn Youn 		if (val >= 0) {
823323230efSJohn Youn 			dev_err(hsotg->dev,
824323230efSJohn Youn 				"Wrong value for phy_ulpi_ext_vbus\n");
825323230efSJohn Youn 			dev_err(hsotg->dev,
826323230efSJohn Youn 				"phy_ulpi_ext_vbus must be 0 or 1\n");
827323230efSJohn Youn 		}
828323230efSJohn Youn 		val = 0;
829323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val);
830323230efSJohn Youn 	}
831323230efSJohn Youn 
832bea8e86cSJohn Youn 	hsotg->params.phy_ulpi_ext_vbus = val;
833323230efSJohn Youn }
834323230efSJohn Youn 
835c1d286cfSJohn Youn static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val)
836323230efSJohn Youn {
837323230efSJohn Youn 	int valid = 0;
838323230efSJohn Youn 
839323230efSJohn Youn 	switch (hsotg->hw_params.utmi_phy_data_width) {
840323230efSJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
841323230efSJohn Youn 		valid = (val == 8);
842323230efSJohn Youn 		break;
843323230efSJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
844323230efSJohn Youn 		valid = (val == 16);
845323230efSJohn Youn 		break;
846323230efSJohn Youn 	case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
847323230efSJohn Youn 		valid = (val == 8 || val == 16);
848323230efSJohn Youn 		break;
849323230efSJohn Youn 	}
850323230efSJohn Youn 
851323230efSJohn Youn 	if (!valid) {
852323230efSJohn Youn 		if (val >= 0) {
853323230efSJohn Youn 			dev_err(hsotg->dev,
854323230efSJohn Youn 				"%d invalid for phy_utmi_width. Check HW configuration.\n",
855323230efSJohn Youn 				val);
856323230efSJohn Youn 		}
857323230efSJohn Youn 		val = (hsotg->hw_params.utmi_phy_data_width ==
858323230efSJohn Youn 		       GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
859323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val);
860323230efSJohn Youn 	}
861323230efSJohn Youn 
862bea8e86cSJohn Youn 	hsotg->params.phy_utmi_width = val;
863323230efSJohn Youn }
864323230efSJohn Youn 
865c1d286cfSJohn Youn static void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val)
866323230efSJohn Youn {
867323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
868323230efSJohn Youn 		if (val >= 0) {
869323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n");
870323230efSJohn Youn 			dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n");
871323230efSJohn Youn 		}
872323230efSJohn Youn 		val = 0;
873323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val);
874323230efSJohn Youn 	}
875323230efSJohn Youn 
876bea8e86cSJohn Youn 	hsotg->params.ulpi_fs_ls = val;
877323230efSJohn Youn }
878323230efSJohn Youn 
879c1d286cfSJohn Youn static void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val)
880323230efSJohn Youn {
881323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
882323230efSJohn Youn 		if (val >= 0) {
883323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for ts_dline\n");
884323230efSJohn Youn 			dev_err(hsotg->dev, "ts_dline must be 0 or 1\n");
885323230efSJohn Youn 		}
886323230efSJohn Youn 		val = 0;
887323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val);
888323230efSJohn Youn 	}
889323230efSJohn Youn 
890bea8e86cSJohn Youn 	hsotg->params.ts_dline = val;
891323230efSJohn Youn }
892323230efSJohn Youn 
893c1d286cfSJohn Youn static void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
894323230efSJohn Youn {
895323230efSJohn Youn 	int valid = 1;
896323230efSJohn Youn 
897323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
898323230efSJohn Youn 		if (val >= 0) {
899323230efSJohn Youn 			dev_err(hsotg->dev, "Wrong value for i2c_enable\n");
900323230efSJohn Youn 			dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n");
901323230efSJohn Youn 		}
902323230efSJohn Youn 
903323230efSJohn Youn 		valid = 0;
904323230efSJohn Youn 	}
905323230efSJohn Youn 
906323230efSJohn Youn 	if (val == 1 && !(hsotg->hw_params.i2c_enable))
907323230efSJohn Youn 		valid = 0;
908323230efSJohn Youn 
909323230efSJohn Youn 	if (!valid) {
910323230efSJohn Youn 		if (val >= 0)
911323230efSJohn Youn 			dev_err(hsotg->dev,
912323230efSJohn Youn 				"%d invalid for i2c_enable. Check HW configuration.\n",
913323230efSJohn Youn 				val);
914323230efSJohn Youn 		val = hsotg->hw_params.i2c_enable;
915323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
916323230efSJohn Youn 	}
917323230efSJohn Youn 
918bea8e86cSJohn Youn 	hsotg->params.i2c_enable = val;
919323230efSJohn Youn }
920323230efSJohn Youn 
921c1d286cfSJohn Youn static void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
922c1d286cfSJohn Youn 					       int val)
923323230efSJohn Youn {
924323230efSJohn Youn 	int valid = 1;
925323230efSJohn Youn 
926323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
927323230efSJohn Youn 		if (val >= 0) {
928323230efSJohn Youn 			dev_err(hsotg->dev,
929323230efSJohn Youn 				"Wrong value for en_multiple_tx_fifo,\n");
930323230efSJohn Youn 			dev_err(hsotg->dev,
931323230efSJohn Youn 				"en_multiple_tx_fifo must be 0 or 1\n");
932323230efSJohn Youn 		}
933323230efSJohn Youn 		valid = 0;
934323230efSJohn Youn 	}
935323230efSJohn Youn 
936323230efSJohn Youn 	if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo)
937323230efSJohn Youn 		valid = 0;
938323230efSJohn Youn 
939323230efSJohn Youn 	if (!valid) {
940323230efSJohn Youn 		if (val >= 0)
941323230efSJohn Youn 			dev_err(hsotg->dev,
942323230efSJohn Youn 				"%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
943323230efSJohn Youn 				val);
944323230efSJohn Youn 		val = hsotg->hw_params.en_multiple_tx_fifo;
945323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val);
946323230efSJohn Youn 	}
947323230efSJohn Youn 
948bea8e86cSJohn Youn 	hsotg->params.en_multiple_tx_fifo = val;
949323230efSJohn Youn }
950323230efSJohn Youn 
951c1d286cfSJohn Youn static void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
952323230efSJohn Youn {
953323230efSJohn Youn 	int valid = 1;
954323230efSJohn Youn 
955323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
956323230efSJohn Youn 		if (val >= 0) {
957323230efSJohn Youn 			dev_err(hsotg->dev,
958323230efSJohn Youn 				"'%d' invalid for parameter reload_ctl\n", val);
959323230efSJohn Youn 			dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n");
960323230efSJohn Youn 		}
961323230efSJohn Youn 		valid = 0;
962323230efSJohn Youn 	}
963323230efSJohn Youn 
964323230efSJohn Youn 	if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a)
965323230efSJohn Youn 		valid = 0;
966323230efSJohn Youn 
967323230efSJohn Youn 	if (!valid) {
968323230efSJohn Youn 		if (val >= 0)
969323230efSJohn Youn 			dev_err(hsotg->dev,
970323230efSJohn Youn 				"%d invalid for parameter reload_ctl. Check HW configuration.\n",
971323230efSJohn Youn 				val);
972323230efSJohn Youn 		val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a;
973323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val);
974323230efSJohn Youn 	}
975323230efSJohn Youn 
976bea8e86cSJohn Youn 	hsotg->params.reload_ctl = val;
977323230efSJohn Youn }
978323230efSJohn Youn 
979c1d286cfSJohn Youn static void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)
980323230efSJohn Youn {
981323230efSJohn Youn 	if (val != -1)
982bea8e86cSJohn Youn 		hsotg->params.ahbcfg = val;
983323230efSJohn Youn 	else
984bea8e86cSJohn Youn 		hsotg->params.ahbcfg = GAHBCFG_HBSTLEN_INCR4 <<
985323230efSJohn Youn 						GAHBCFG_HBSTLEN_SHIFT;
986323230efSJohn Youn }
987323230efSJohn Youn 
988c1d286cfSJohn Youn static void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val)
989323230efSJohn Youn {
990323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
991323230efSJohn Youn 		if (val >= 0) {
992323230efSJohn Youn 			dev_err(hsotg->dev,
993323230efSJohn Youn 				"'%d' invalid for parameter otg_ver\n", val);
994323230efSJohn Youn 			dev_err(hsotg->dev,
995323230efSJohn Youn 				"otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n");
996323230efSJohn Youn 		}
997323230efSJohn Youn 		val = 0;
998323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val);
999323230efSJohn Youn 	}
1000323230efSJohn Youn 
1001bea8e86cSJohn Youn 	hsotg->params.otg_ver = val;
1002323230efSJohn Youn }
1003323230efSJohn Youn 
1004323230efSJohn Youn static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val)
1005323230efSJohn Youn {
1006323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
1007323230efSJohn Youn 		if (val >= 0) {
1008323230efSJohn Youn 			dev_err(hsotg->dev,
1009323230efSJohn Youn 				"'%d' invalid for parameter uframe_sched\n",
1010323230efSJohn Youn 				val);
1011323230efSJohn Youn 			dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n");
1012323230efSJohn Youn 		}
1013323230efSJohn Youn 		val = 1;
1014323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val);
1015323230efSJohn Youn 	}
1016323230efSJohn Youn 
1017bea8e86cSJohn Youn 	hsotg->params.uframe_sched = val;
1018323230efSJohn Youn }
1019323230efSJohn Youn 
1020323230efSJohn Youn static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg,
1021323230efSJohn Youn 					       int val)
1022323230efSJohn Youn {
1023323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
1024323230efSJohn Youn 		if (val >= 0) {
1025323230efSJohn Youn 			dev_err(hsotg->dev,
1026323230efSJohn Youn 				"'%d' invalid for parameter external_id_pin_ctl\n",
1027323230efSJohn Youn 				val);
1028323230efSJohn Youn 			dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n");
1029323230efSJohn Youn 		}
1030323230efSJohn Youn 		val = 0;
1031323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val);
1032323230efSJohn Youn 	}
1033323230efSJohn Youn 
1034bea8e86cSJohn Youn 	hsotg->params.external_id_pin_ctl = val;
1035323230efSJohn Youn }
1036323230efSJohn Youn 
1037323230efSJohn Youn static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg,
1038323230efSJohn Youn 				       int val)
1039323230efSJohn Youn {
1040323230efSJohn Youn 	if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
1041323230efSJohn Youn 		if (val >= 0) {
1042323230efSJohn Youn 			dev_err(hsotg->dev,
1043323230efSJohn Youn 				"'%d' invalid for parameter hibernation\n",
1044323230efSJohn Youn 				val);
1045323230efSJohn Youn 			dev_err(hsotg->dev, "hibernation must be 0 or 1\n");
1046323230efSJohn Youn 		}
1047323230efSJohn Youn 		val = 0;
1048323230efSJohn Youn 		dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val);
1049323230efSJohn Youn 	}
1050323230efSJohn Youn 
1051bea8e86cSJohn Youn 	hsotg->params.hibernation = val;
1052323230efSJohn Youn }
1053323230efSJohn Youn 
105405ee799fSJohn Youn static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
105505ee799fSJohn Youn {
105605ee799fSJohn Youn 	int i;
105705ee799fSJohn Youn 	int num;
105805ee799fSJohn Youn 	char *property = "g-tx-fifo-size";
105905ee799fSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
106005ee799fSJohn Youn 
106105ee799fSJohn Youn 	memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
106205ee799fSJohn Youn 
106305ee799fSJohn Youn 	/* Read tx fifo sizes */
106405ee799fSJohn Youn 	num = device_property_read_u32_array(hsotg->dev, property, NULL, 0);
106505ee799fSJohn Youn 
106605ee799fSJohn Youn 	if (num > 0) {
106705ee799fSJohn Youn 		device_property_read_u32_array(hsotg->dev, property,
106805ee799fSJohn Youn 					       &p->g_tx_fifo_size[1],
106905ee799fSJohn Youn 					       num);
107005ee799fSJohn Youn 	} else {
107105ee799fSJohn Youn 		u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE;
107205ee799fSJohn Youn 
107305ee799fSJohn Youn 		memcpy(&p->g_tx_fifo_size[1],
107405ee799fSJohn Youn 		       p_tx_fifo,
107505ee799fSJohn Youn 		       sizeof(p_tx_fifo));
107605ee799fSJohn Youn 
107705ee799fSJohn Youn 		num = ARRAY_SIZE(p_tx_fifo);
107805ee799fSJohn Youn 	}
107905ee799fSJohn Youn 
108005ee799fSJohn Youn 	for (i = 0; i < num; i++) {
108105ee799fSJohn Youn 		if ((i + 1) >= ARRAY_SIZE(p->g_tx_fifo_size))
108205ee799fSJohn Youn 			break;
108305ee799fSJohn Youn 
108405ee799fSJohn Youn 		dev_dbg(hsotg->dev, "Setting %s[%d] to %d\n",
108505ee799fSJohn Youn 			property, i + 1, p->g_tx_fifo_size[i + 1]);
108605ee799fSJohn Youn 	}
108705ee799fSJohn Youn }
108805ee799fSJohn Youn 
108905ee799fSJohn Youn /**
109005ee799fSJohn Youn  * dwc2_set_parameters() - Set all core parameters.
109105ee799fSJohn Youn  *
109205ee799fSJohn Youn  * @hsotg: Programming view of the DWC_otg controller
109305ee799fSJohn Youn  * @params: The parameters to set
1094323230efSJohn Youn  */
1095c1d286cfSJohn Youn static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1096323230efSJohn Youn 				const struct dwc2_core_params *params)
1097323230efSJohn Youn {
109805ee799fSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
109905ee799fSJohn Youn 	struct dwc2_core_params *p = &hsotg->params;
1100*6b66ce51SJohn Youn 	bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
1101323230efSJohn Youn 
1102323230efSJohn Youn 	dwc2_set_param_otg_cap(hsotg, params->otg_cap);
1103323230efSJohn Youn 	dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable);
1104323230efSJohn Youn 	dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable);
1105*6b66ce51SJohn Youn 
1106*6b66ce51SJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
1107*6b66ce51SJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
1108*6b66ce51SJohn Youn 		bool disable;
1109*6b66ce51SJohn Youn 
1110*6b66ce51SJohn Youn 		dev_dbg(hsotg->dev, "Setting HOST parameters\n");
1111*6b66ce51SJohn Youn 
1112*6b66ce51SJohn Youn 		disable = device_property_read_bool(hsotg->dev,
1113*6b66ce51SJohn Youn 						    "snps,host-dma-disable");
1114*6b66ce51SJohn Youn 
1115*6b66ce51SJohn Youn 		dwc2_set_param_bool(hsotg, &p->host_dma,
1116*6b66ce51SJohn Youn 				    false, "host-dma",
1117*6b66ce51SJohn Youn 				    !disable, false,
1118*6b66ce51SJohn Youn 				    dma_capable);
1119*6b66ce51SJohn Youn 	}
1120*6b66ce51SJohn Youn 
1121323230efSJohn Youn 	dwc2_set_param_host_support_fs_ls_low_power(hsotg,
1122323230efSJohn Youn 			params->host_support_fs_ls_low_power);
1123323230efSJohn Youn 	dwc2_set_param_enable_dynamic_fifo(hsotg,
1124323230efSJohn Youn 			params->enable_dynamic_fifo);
1125323230efSJohn Youn 	dwc2_set_param_host_rx_fifo_size(hsotg,
1126323230efSJohn Youn 			params->host_rx_fifo_size);
1127323230efSJohn Youn 	dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
1128323230efSJohn Youn 			params->host_nperio_tx_fifo_size);
1129323230efSJohn Youn 	dwc2_set_param_host_perio_tx_fifo_size(hsotg,
1130323230efSJohn Youn 			params->host_perio_tx_fifo_size);
1131323230efSJohn Youn 	dwc2_set_param_max_transfer_size(hsotg,
1132323230efSJohn Youn 			params->max_transfer_size);
1133323230efSJohn Youn 	dwc2_set_param_max_packet_count(hsotg,
1134323230efSJohn Youn 			params->max_packet_count);
1135323230efSJohn Youn 	dwc2_set_param_host_channels(hsotg, params->host_channels);
1136323230efSJohn Youn 	dwc2_set_param_phy_type(hsotg, params->phy_type);
1137323230efSJohn Youn 	dwc2_set_param_speed(hsotg, params->speed);
1138323230efSJohn Youn 	dwc2_set_param_host_ls_low_power_phy_clk(hsotg,
1139323230efSJohn Youn 			params->host_ls_low_power_phy_clk);
1140323230efSJohn Youn 	dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr);
1141323230efSJohn Youn 	dwc2_set_param_phy_ulpi_ext_vbus(hsotg,
1142323230efSJohn Youn 			params->phy_ulpi_ext_vbus);
1143323230efSJohn Youn 	dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width);
1144323230efSJohn Youn 	dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls);
1145323230efSJohn Youn 	dwc2_set_param_ts_dline(hsotg, params->ts_dline);
1146323230efSJohn Youn 	dwc2_set_param_i2c_enable(hsotg, params->i2c_enable);
1147323230efSJohn Youn 	dwc2_set_param_en_multiple_tx_fifo(hsotg,
1148323230efSJohn Youn 			params->en_multiple_tx_fifo);
1149323230efSJohn Youn 	dwc2_set_param_reload_ctl(hsotg, params->reload_ctl);
1150323230efSJohn Youn 	dwc2_set_param_ahbcfg(hsotg, params->ahbcfg);
1151323230efSJohn Youn 	dwc2_set_param_otg_ver(hsotg, params->otg_ver);
1152323230efSJohn Youn 	dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
1153323230efSJohn Youn 	dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
1154323230efSJohn Youn 	dwc2_set_param_hibernation(hsotg, params->hibernation);
115505ee799fSJohn Youn 
115605ee799fSJohn Youn 	/*
115705ee799fSJohn Youn 	 * Set devicetree-only parameters. These parameters do not
115805ee799fSJohn Youn 	 * take any values from @params.
115905ee799fSJohn Youn 	 */
116005ee799fSJohn Youn 	if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
116105ee799fSJohn Youn 	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
116205ee799fSJohn Youn 		dev_dbg(hsotg->dev, "Setting peripheral device properties\n");
116305ee799fSJohn Youn 
116405ee799fSJohn Youn 		dwc2_set_param_bool(hsotg, &p->g_dma, true, "g-use-dma",
116505ee799fSJohn Youn 				    false, false,
1166*6b66ce51SJohn Youn 				    dma_capable);
116705ee799fSJohn Youn 
116805ee799fSJohn Youn 		/*
116905ee799fSJohn Youn 		 * The values for g_rx_fifo_size (2048) and
117005ee799fSJohn Youn 		 * g_np_tx_fifo_size (1024) come from the legacy s3c
117105ee799fSJohn Youn 		 * gadget driver. These defaults have been hard-coded
117205ee799fSJohn Youn 		 * for some time so many platforms depend on these
117305ee799fSJohn Youn 		 * values. Leave them as defaults for now and only
117405ee799fSJohn Youn 		 * auto-detect if the hardware does not support the
117505ee799fSJohn Youn 		 * default.
117605ee799fSJohn Youn 		 */
117705ee799fSJohn Youn 		dwc2_set_param_u16(hsotg, &p->g_rx_fifo_size,
117805ee799fSJohn Youn 				   true, "g-rx-fifo-size", 2048,
117905ee799fSJohn Youn 				   hw->rx_fifo_size,
118005ee799fSJohn Youn 				   16, hw->rx_fifo_size);
118105ee799fSJohn Youn 
118205ee799fSJohn Youn 		dwc2_set_param_u16(hsotg, &p->g_np_tx_fifo_size,
118305ee799fSJohn Youn 				   true, "g-np-tx-fifo-size", 1024,
118405ee799fSJohn Youn 				   hw->dev_nperio_tx_fifo_size,
118505ee799fSJohn Youn 				   16, hw->dev_nperio_tx_fifo_size);
118605ee799fSJohn Youn 
118705ee799fSJohn Youn 		dwc2_set_param_tx_fifo_sizes(hsotg);
118805ee799fSJohn Youn 	}
1189323230efSJohn Youn }
1190323230efSJohn Youn 
1191323230efSJohn Youn /*
1192323230efSJohn Youn  * Gets host hardware parameters. Forces host mode if not currently in
1193323230efSJohn Youn  * host mode. Should be called immediately after a core soft reset in
1194323230efSJohn Youn  * order to get the reset values.
1195323230efSJohn Youn  */
1196323230efSJohn Youn static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
1197323230efSJohn Youn {
1198323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
1199323230efSJohn Youn 	u32 gnptxfsiz;
1200323230efSJohn Youn 	u32 hptxfsiz;
1201323230efSJohn Youn 	bool forced;
1202323230efSJohn Youn 
1203323230efSJohn Youn 	if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
1204323230efSJohn Youn 		return;
1205323230efSJohn Youn 
1206323230efSJohn Youn 	forced = dwc2_force_mode_if_needed(hsotg, true);
1207323230efSJohn Youn 
1208323230efSJohn Youn 	gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
1209323230efSJohn Youn 	hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
1210323230efSJohn Youn 	dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
1211323230efSJohn Youn 	dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz);
1212323230efSJohn Youn 
1213323230efSJohn Youn 	if (forced)
1214323230efSJohn Youn 		dwc2_clear_force_mode(hsotg);
1215323230efSJohn Youn 
1216323230efSJohn Youn 	hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
1217323230efSJohn Youn 				       FIFOSIZE_DEPTH_SHIFT;
1218323230efSJohn Youn 	hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
1219323230efSJohn Youn 				      FIFOSIZE_DEPTH_SHIFT;
1220323230efSJohn Youn }
1221323230efSJohn Youn 
1222323230efSJohn Youn /*
1223323230efSJohn Youn  * Gets device hardware parameters. Forces device mode if not
1224323230efSJohn Youn  * currently in device mode. Should be called immediately after a core
1225323230efSJohn Youn  * soft reset in order to get the reset values.
1226323230efSJohn Youn  */
1227323230efSJohn Youn static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
1228323230efSJohn Youn {
1229323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
1230323230efSJohn Youn 	bool forced;
1231323230efSJohn Youn 	u32 gnptxfsiz;
1232323230efSJohn Youn 
1233323230efSJohn Youn 	if (hsotg->dr_mode == USB_DR_MODE_HOST)
1234323230efSJohn Youn 		return;
1235323230efSJohn Youn 
1236323230efSJohn Youn 	forced = dwc2_force_mode_if_needed(hsotg, false);
1237323230efSJohn Youn 
1238323230efSJohn Youn 	gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
1239323230efSJohn Youn 	dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
1240323230efSJohn Youn 
1241323230efSJohn Youn 	if (forced)
1242323230efSJohn Youn 		dwc2_clear_force_mode(hsotg);
1243323230efSJohn Youn 
1244323230efSJohn Youn 	hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
1245323230efSJohn Youn 				       FIFOSIZE_DEPTH_SHIFT;
1246323230efSJohn Youn }
1247323230efSJohn Youn 
1248323230efSJohn Youn /**
1249323230efSJohn Youn  * During device initialization, read various hardware configuration
1250323230efSJohn Youn  * registers and interpret the contents.
1251323230efSJohn Youn  */
1252323230efSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
1253323230efSJohn Youn {
1254323230efSJohn Youn 	struct dwc2_hw_params *hw = &hsotg->hw_params;
1255323230efSJohn Youn 	unsigned int width;
1256323230efSJohn Youn 	u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
1257323230efSJohn Youn 	u32 grxfsiz;
1258323230efSJohn Youn 
1259323230efSJohn Youn 	/*
1260323230efSJohn Youn 	 * Attempt to ensure this device is really a DWC_otg Controller.
1261323230efSJohn Youn 	 * Read and verify the GSNPSID register contents. The value should be
1262323230efSJohn Youn 	 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
1263323230efSJohn Youn 	 * as in "OTG version 2.xx" or "OTG version 3.xx".
1264323230efSJohn Youn 	 */
1265323230efSJohn Youn 	hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID);
1266323230efSJohn Youn 	if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
1267323230efSJohn Youn 	    (hw->snpsid & 0xfffff000) != 0x4f543000) {
1268323230efSJohn Youn 		dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
1269323230efSJohn Youn 			hw->snpsid);
1270323230efSJohn Youn 		return -ENODEV;
1271323230efSJohn Youn 	}
1272323230efSJohn Youn 
1273323230efSJohn Youn 	dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
1274323230efSJohn Youn 		hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
1275323230efSJohn Youn 		hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
1276323230efSJohn Youn 
1277323230efSJohn Youn 	hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1);
1278323230efSJohn Youn 	hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
1279323230efSJohn Youn 	hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3);
1280323230efSJohn Youn 	hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4);
1281323230efSJohn Youn 	grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
1282323230efSJohn Youn 
1283323230efSJohn Youn 	dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1);
1284323230efSJohn Youn 	dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2);
1285323230efSJohn Youn 	dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3);
1286323230efSJohn Youn 	dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4);
1287323230efSJohn Youn 	dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz);
1288323230efSJohn Youn 
1289323230efSJohn Youn 	/*
1290323230efSJohn Youn 	 * Host specific hardware parameters. Reading these parameters
1291323230efSJohn Youn 	 * requires the controller to be in host mode. The mode will
1292323230efSJohn Youn 	 * be forced, if necessary, to read these values.
1293323230efSJohn Youn 	 */
1294323230efSJohn Youn 	dwc2_get_host_hwparams(hsotg);
1295323230efSJohn Youn 	dwc2_get_dev_hwparams(hsotg);
1296323230efSJohn Youn 
1297323230efSJohn Youn 	/* hwcfg1 */
1298323230efSJohn Youn 	hw->dev_ep_dirs = hwcfg1;
1299323230efSJohn Youn 
1300323230efSJohn Youn 	/* hwcfg2 */
1301323230efSJohn Youn 	hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
1302323230efSJohn Youn 		      GHWCFG2_OP_MODE_SHIFT;
1303323230efSJohn Youn 	hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
1304323230efSJohn Youn 		   GHWCFG2_ARCHITECTURE_SHIFT;
1305323230efSJohn Youn 	hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
1306323230efSJohn Youn 	hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
1307323230efSJohn Youn 				GHWCFG2_NUM_HOST_CHAN_SHIFT);
1308323230efSJohn Youn 	hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
1309323230efSJohn Youn 			  GHWCFG2_HS_PHY_TYPE_SHIFT;
1310323230efSJohn Youn 	hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
1311323230efSJohn Youn 			  GHWCFG2_FS_PHY_TYPE_SHIFT;
1312323230efSJohn Youn 	hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
1313323230efSJohn Youn 			 GHWCFG2_NUM_DEV_EP_SHIFT;
1314323230efSJohn Youn 	hw->nperio_tx_q_depth =
1315323230efSJohn Youn 		(hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
1316323230efSJohn Youn 		GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
1317323230efSJohn Youn 	hw->host_perio_tx_q_depth =
1318323230efSJohn Youn 		(hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
1319323230efSJohn Youn 		GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
1320323230efSJohn Youn 	hw->dev_token_q_depth =
1321323230efSJohn Youn 		(hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
1322323230efSJohn Youn 		GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
1323323230efSJohn Youn 
1324323230efSJohn Youn 	/* hwcfg3 */
1325323230efSJohn Youn 	width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
1326323230efSJohn Youn 		GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
1327323230efSJohn Youn 	hw->max_transfer_size = (1 << (width + 11)) - 1;
1328323230efSJohn Youn 	width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
1329323230efSJohn Youn 		GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
1330323230efSJohn Youn 	hw->max_packet_count = (1 << (width + 4)) - 1;
1331323230efSJohn Youn 	hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
1332323230efSJohn Youn 	hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
1333323230efSJohn Youn 			      GHWCFG3_DFIFO_DEPTH_SHIFT;
1334323230efSJohn Youn 
1335323230efSJohn Youn 	/* hwcfg4 */
1336323230efSJohn Youn 	hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
1337323230efSJohn Youn 	hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
1338323230efSJohn Youn 				  GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
1339323230efSJohn Youn 	hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
1340323230efSJohn Youn 	hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
1341323230efSJohn Youn 	hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
1342323230efSJohn Youn 				  GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
1343323230efSJohn Youn 
1344323230efSJohn Youn 	/* fifo sizes */
1345d1531319SJohn Youn 	hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
1346323230efSJohn Youn 				GRXFSIZ_DEPTH_SHIFT;
1347323230efSJohn Youn 
1348323230efSJohn Youn 	dev_dbg(hsotg->dev, "Detected values from hardware:\n");
1349323230efSJohn Youn 	dev_dbg(hsotg->dev, "  op_mode=%d\n",
1350323230efSJohn Youn 		hw->op_mode);
1351323230efSJohn Youn 	dev_dbg(hsotg->dev, "  arch=%d\n",
1352323230efSJohn Youn 		hw->arch);
1353323230efSJohn Youn 	dev_dbg(hsotg->dev, "  dma_desc_enable=%d\n",
1354323230efSJohn Youn 		hw->dma_desc_enable);
1355323230efSJohn Youn 	dev_dbg(hsotg->dev, "  power_optimized=%d\n",
1356323230efSJohn Youn 		hw->power_optimized);
1357323230efSJohn Youn 	dev_dbg(hsotg->dev, "  i2c_enable=%d\n",
1358323230efSJohn Youn 		hw->i2c_enable);
1359323230efSJohn Youn 	dev_dbg(hsotg->dev, "  hs_phy_type=%d\n",
1360323230efSJohn Youn 		hw->hs_phy_type);
1361323230efSJohn Youn 	dev_dbg(hsotg->dev, "  fs_phy_type=%d\n",
1362323230efSJohn Youn 		hw->fs_phy_type);
1363323230efSJohn Youn 	dev_dbg(hsotg->dev, "  utmi_phy_data_width=%d\n",
1364323230efSJohn Youn 		hw->utmi_phy_data_width);
1365323230efSJohn Youn 	dev_dbg(hsotg->dev, "  num_dev_ep=%d\n",
1366323230efSJohn Youn 		hw->num_dev_ep);
1367323230efSJohn Youn 	dev_dbg(hsotg->dev, "  num_dev_perio_in_ep=%d\n",
1368323230efSJohn Youn 		hw->num_dev_perio_in_ep);
1369323230efSJohn Youn 	dev_dbg(hsotg->dev, "  host_channels=%d\n",
1370323230efSJohn Youn 		hw->host_channels);
1371323230efSJohn Youn 	dev_dbg(hsotg->dev, "  max_transfer_size=%d\n",
1372323230efSJohn Youn 		hw->max_transfer_size);
1373323230efSJohn Youn 	dev_dbg(hsotg->dev, "  max_packet_count=%d\n",
1374323230efSJohn Youn 		hw->max_packet_count);
1375323230efSJohn Youn 	dev_dbg(hsotg->dev, "  nperio_tx_q_depth=0x%0x\n",
1376323230efSJohn Youn 		hw->nperio_tx_q_depth);
1377323230efSJohn Youn 	dev_dbg(hsotg->dev, "  host_perio_tx_q_depth=0x%0x\n",
1378323230efSJohn Youn 		hw->host_perio_tx_q_depth);
1379323230efSJohn Youn 	dev_dbg(hsotg->dev, "  dev_token_q_depth=0x%0x\n",
1380323230efSJohn Youn 		hw->dev_token_q_depth);
1381323230efSJohn Youn 	dev_dbg(hsotg->dev, "  enable_dynamic_fifo=%d\n",
1382323230efSJohn Youn 		hw->enable_dynamic_fifo);
1383323230efSJohn Youn 	dev_dbg(hsotg->dev, "  en_multiple_tx_fifo=%d\n",
1384323230efSJohn Youn 		hw->en_multiple_tx_fifo);
1385323230efSJohn Youn 	dev_dbg(hsotg->dev, "  total_fifo_size=%d\n",
1386323230efSJohn Youn 		hw->total_fifo_size);
1387d1531319SJohn Youn 	dev_dbg(hsotg->dev, "  rx_fifo_size=%d\n",
1388d1531319SJohn Youn 		hw->rx_fifo_size);
1389323230efSJohn Youn 	dev_dbg(hsotg->dev, "  host_nperio_tx_fifo_size=%d\n",
1390323230efSJohn Youn 		hw->host_nperio_tx_fifo_size);
1391323230efSJohn Youn 	dev_dbg(hsotg->dev, "  host_perio_tx_fifo_size=%d\n",
1392323230efSJohn Youn 		hw->host_perio_tx_fifo_size);
1393323230efSJohn Youn 	dev_dbg(hsotg->dev, "\n");
1394323230efSJohn Youn 
1395323230efSJohn Youn 	return 0;
1396323230efSJohn Youn }
1397323230efSJohn Youn 
1398334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg)
1399334bbd4eSJohn Youn {
1400334bbd4eSJohn Youn 	const struct of_device_id *match;
14010a7d0d7fSJohn Youn 	struct dwc2_core_params params;
1402334bbd4eSJohn Youn 
1403334bbd4eSJohn Youn 	match = of_match_device(dwc2_of_match_table, hsotg->dev);
14040a7d0d7fSJohn Youn 	if (match && match->data)
14050a7d0d7fSJohn Youn 		params = *((struct dwc2_core_params *)match->data);
14060a7d0d7fSJohn Youn 	else
14070a7d0d7fSJohn Youn 		params = params_default;
1408334bbd4eSJohn Youn 
14090a7d0d7fSJohn Youn 	dwc2_set_parameters(hsotg, &params);
1410334bbd4eSJohn Youn 
1411334bbd4eSJohn Youn 	return 0;
1412334bbd4eSJohn Youn }
1413