blob: 719205ab09a2bbead027e3ca33aef18718b1109f [file] [log] [blame]
John Youn323230e2016-11-03 17:55:50 -07001/*
2 * Copyright (C) 2004-2016 Synopsys, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") as published by the Free Software
19 * Foundation; either version 2 of the License, or (at your option) any
20 * later version.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/of_device.h>
38
39#include "core.h"
40
41static const struct dwc2_core_params params_hi6220 = {
42 .otg_cap = 2, /* No HNP/SRP capable */
43 .otg_ver = 0, /* 1.3 */
44 .dma_enable = 1,
45 .dma_desc_enable = 0,
46 .dma_desc_fs_enable = 0,
47 .speed = 0, /* High Speed */
48 .enable_dynamic_fifo = 1,
49 .en_multiple_tx_fifo = 1,
50 .host_rx_fifo_size = 512,
51 .host_nperio_tx_fifo_size = 512,
52 .host_perio_tx_fifo_size = 512,
53 .max_transfer_size = 65535,
54 .max_packet_count = 511,
55 .host_channels = 16,
56 .phy_type = 1, /* UTMI */
57 .phy_utmi_width = 8,
58 .phy_ulpi_ddr = 0, /* Single */
59 .phy_ulpi_ext_vbus = 0,
60 .i2c_enable = 0,
61 .ulpi_fs_ls = 0,
62 .host_support_fs_ls_low_power = 0,
63 .host_ls_low_power_phy_clk = 0, /* 48 MHz */
64 .ts_dline = 0,
65 .reload_ctl = 0,
66 .ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
67 GAHBCFG_HBSTLEN_SHIFT,
68 .uframe_sched = 0,
69 .external_id_pin_ctl = -1,
70 .hibernation = -1,
71};
72
73static const struct dwc2_core_params params_bcm2835 = {
74 .otg_cap = 0, /* HNP/SRP capable */
75 .otg_ver = 0, /* 1.3 */
76 .dma_enable = 1,
77 .dma_desc_enable = 0,
78 .dma_desc_fs_enable = 0,
79 .speed = 0, /* High Speed */
80 .enable_dynamic_fifo = 1,
81 .en_multiple_tx_fifo = 1,
82 .host_rx_fifo_size = 774, /* 774 DWORDs */
83 .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */
84 .host_perio_tx_fifo_size = 512, /* 512 DWORDs */
85 .max_transfer_size = 65535,
86 .max_packet_count = 511,
87 .host_channels = 8,
88 .phy_type = 1, /* UTMI */
89 .phy_utmi_width = 8, /* 8 bits */
90 .phy_ulpi_ddr = 0, /* Single */
91 .phy_ulpi_ext_vbus = 0,
92 .i2c_enable = 0,
93 .ulpi_fs_ls = 0,
94 .host_support_fs_ls_low_power = 0,
95 .host_ls_low_power_phy_clk = 0, /* 48 MHz */
96 .ts_dline = 0,
97 .reload_ctl = 0,
98 .ahbcfg = 0x10,
99 .uframe_sched = 0,
100 .external_id_pin_ctl = -1,
101 .hibernation = -1,
102};
103
104static const struct dwc2_core_params params_rk3066 = {
105 .otg_cap = 2, /* non-HNP/non-SRP */
106 .otg_ver = -1,
107 .dma_enable = -1,
108 .dma_desc_enable = 0,
109 .dma_desc_fs_enable = 0,
110 .speed = -1,
111 .enable_dynamic_fifo = 1,
112 .en_multiple_tx_fifo = -1,
113 .host_rx_fifo_size = 525, /* 525 DWORDs */
114 .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */
115 .host_perio_tx_fifo_size = 256, /* 256 DWORDs */
116 .max_transfer_size = -1,
117 .max_packet_count = -1,
118 .host_channels = -1,
119 .phy_type = -1,
120 .phy_utmi_width = -1,
121 .phy_ulpi_ddr = -1,
122 .phy_ulpi_ext_vbus = -1,
123 .i2c_enable = -1,
124 .ulpi_fs_ls = -1,
125 .host_support_fs_ls_low_power = -1,
126 .host_ls_low_power_phy_clk = -1,
127 .ts_dline = -1,
128 .reload_ctl = -1,
129 .ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
130 GAHBCFG_HBSTLEN_SHIFT,
131 .uframe_sched = -1,
132 .external_id_pin_ctl = -1,
133 .hibernation = -1,
134};
135
136static const struct dwc2_core_params params_ltq = {
137 .otg_cap = 2, /* non-HNP/non-SRP */
138 .otg_ver = -1,
139 .dma_enable = -1,
140 .dma_desc_enable = -1,
141 .dma_desc_fs_enable = -1,
142 .speed = -1,
143 .enable_dynamic_fifo = -1,
144 .en_multiple_tx_fifo = -1,
145 .host_rx_fifo_size = 288, /* 288 DWORDs */
146 .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */
147 .host_perio_tx_fifo_size = 96, /* 96 DWORDs */
148 .max_transfer_size = 65535,
149 .max_packet_count = 511,
150 .host_channels = -1,
151 .phy_type = -1,
152 .phy_utmi_width = -1,
153 .phy_ulpi_ddr = -1,
154 .phy_ulpi_ext_vbus = -1,
155 .i2c_enable = -1,
156 .ulpi_fs_ls = -1,
157 .host_support_fs_ls_low_power = -1,
158 .host_ls_low_power_phy_clk = -1,
159 .ts_dline = -1,
160 .reload_ctl = -1,
161 .ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
162 GAHBCFG_HBSTLEN_SHIFT,
163 .uframe_sched = -1,
164 .external_id_pin_ctl = -1,
165 .hibernation = -1,
166};
167
168static const struct dwc2_core_params params_amlogic = {
169 .otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE,
170 .otg_ver = -1,
171 .dma_enable = 1,
172 .dma_desc_enable = 0,
173 .dma_desc_fs_enable = 0,
174 .speed = DWC2_SPEED_PARAM_HIGH,
175 .enable_dynamic_fifo = 1,
176 .en_multiple_tx_fifo = -1,
177 .host_rx_fifo_size = 512,
178 .host_nperio_tx_fifo_size = 500,
179 .host_perio_tx_fifo_size = 500,
180 .max_transfer_size = -1,
181 .max_packet_count = -1,
182 .host_channels = 16,
183 .phy_type = DWC2_PHY_TYPE_PARAM_UTMI,
184 .phy_utmi_width = -1,
185 .phy_ulpi_ddr = -1,
186 .phy_ulpi_ext_vbus = -1,
187 .i2c_enable = -1,
188 .ulpi_fs_ls = -1,
189 .host_support_fs_ls_low_power = -1,
190 .host_ls_low_power_phy_clk = -1,
191 .ts_dline = -1,
192 .reload_ctl = 1,
193 .ahbcfg = GAHBCFG_HBSTLEN_INCR8 <<
194 GAHBCFG_HBSTLEN_SHIFT,
195 .uframe_sched = 0,
196 .external_id_pin_ctl = -1,
197 .hibernation = -1,
198};
199
John Youn0a7d0d72016-11-03 17:55:57 -0700200static const struct dwc2_core_params params_default = {
201 .otg_cap = -1,
202 .otg_ver = -1,
203 .dma_enable = -1,
204
205 /*
206 * Disable descriptor dma mode by default as the HW can support
207 * it, but does not support it for SPLIT transactions.
208 * Disable it for FS devices as well.
209 */
210 .dma_desc_enable = 0,
211 .dma_desc_fs_enable = 0,
212
213 .speed = -1,
214 .enable_dynamic_fifo = -1,
215 .en_multiple_tx_fifo = -1,
216 .host_rx_fifo_size = -1,
217 .host_nperio_tx_fifo_size = -1,
218 .host_perio_tx_fifo_size = -1,
219 .max_transfer_size = -1,
220 .max_packet_count = -1,
221 .host_channels = -1,
222 .phy_type = -1,
223 .phy_utmi_width = -1,
224 .phy_ulpi_ddr = -1,
225 .phy_ulpi_ext_vbus = -1,
226 .i2c_enable = -1,
227 .ulpi_fs_ls = -1,
228 .host_support_fs_ls_low_power = -1,
229 .host_ls_low_power_phy_clk = -1,
230 .ts_dline = -1,
231 .reload_ctl = -1,
232 .ahbcfg = -1,
233 .uframe_sched = -1,
234 .external_id_pin_ctl = -1,
235 .hibernation = -1,
236};
237
John Youn323230e2016-11-03 17:55:50 -0700238const struct of_device_id dwc2_of_match_table[] = {
239 { .compatible = "brcm,bcm2835-usb", .data = &params_bcm2835 },
240 { .compatible = "hisilicon,hi6220-usb", .data = &params_hi6220 },
241 { .compatible = "rockchip,rk3066-usb", .data = &params_rk3066 },
242 { .compatible = "lantiq,arx100-usb", .data = &params_ltq },
243 { .compatible = "lantiq,xrx200-usb", .data = &params_ltq },
244 { .compatible = "snps,dwc2", .data = NULL },
245 { .compatible = "samsung,s3c6400-hsotg", .data = NULL},
246 { .compatible = "amlogic,meson8b-usb", .data = &params_amlogic },
247 { .compatible = "amlogic,meson-gxbb-usb", .data = &params_amlogic },
248 {},
249};
250MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
251
252#define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c))
253
254/* Parameter access functions */
John Younc1d286c2016-11-03 17:56:00 -0700255static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700256{
257 int valid = 1;
258
259 switch (val) {
260 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
261 if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
262 valid = 0;
263 break;
264 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
265 switch (hsotg->hw_params.op_mode) {
266 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
267 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
268 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
269 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
270 break;
271 default:
272 valid = 0;
273 break;
274 }
275 break;
276 case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
277 /* always valid */
278 break;
279 default:
280 valid = 0;
281 break;
282 }
283
284 if (!valid) {
285 if (val >= 0)
286 dev_err(hsotg->dev,
287 "%d invalid for otg_cap parameter. Check HW configuration.\n",
288 val);
289 switch (hsotg->hw_params.op_mode) {
290 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
291 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
292 break;
293 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
294 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
295 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
296 val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
297 break;
298 default:
299 val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
300 break;
301 }
302 dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val);
303 }
304
John Younbea8e862016-11-03 17:55:53 -0700305 hsotg->params.otg_cap = val;
John Youn323230e2016-11-03 17:55:50 -0700306}
307
John Younc1d286c2016-11-03 17:56:00 -0700308static void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700309{
310 int valid = 1;
311
312 if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH)
313 valid = 0;
314 if (val < 0)
315 valid = 0;
316
317 if (!valid) {
318 if (val >= 0)
319 dev_err(hsotg->dev,
320 "%d invalid for dma_enable parameter. Check HW configuration.\n",
321 val);
322 val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH;
323 dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val);
324 }
325
John Younbea8e862016-11-03 17:55:53 -0700326 hsotg->params.dma_enable = val;
John Youn323230e2016-11-03 17:55:50 -0700327}
328
John Younc1d286c2016-11-03 17:56:00 -0700329static void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700330{
331 int valid = 1;
332
John Younbea8e862016-11-03 17:55:53 -0700333 if (val > 0 && (hsotg->params.dma_enable <= 0 ||
John Youn323230e2016-11-03 17:55:50 -0700334 !hsotg->hw_params.dma_desc_enable))
335 valid = 0;
336 if (val < 0)
337 valid = 0;
338
339 if (!valid) {
340 if (val >= 0)
341 dev_err(hsotg->dev,
342 "%d invalid for dma_desc_enable parameter. Check HW configuration.\n",
343 val);
John Younbea8e862016-11-03 17:55:53 -0700344 val = (hsotg->params.dma_enable > 0 &&
John Youn323230e2016-11-03 17:55:50 -0700345 hsotg->hw_params.dma_desc_enable);
346 dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val);
347 }
348
John Younbea8e862016-11-03 17:55:53 -0700349 hsotg->params.dma_desc_enable = val;
John Youn323230e2016-11-03 17:55:50 -0700350}
351
John Younc1d286c2016-11-03 17:56:00 -0700352static void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700353{
354 int valid = 1;
355
John Younbea8e862016-11-03 17:55:53 -0700356 if (val > 0 && (hsotg->params.dma_enable <= 0 ||
John Youn323230e2016-11-03 17:55:50 -0700357 !hsotg->hw_params.dma_desc_enable))
358 valid = 0;
359 if (val < 0)
360 valid = 0;
361
362 if (!valid) {
363 if (val >= 0)
364 dev_err(hsotg->dev,
365 "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n",
366 val);
John Younbea8e862016-11-03 17:55:53 -0700367 val = (hsotg->params.dma_enable > 0 &&
John Youn323230e2016-11-03 17:55:50 -0700368 hsotg->hw_params.dma_desc_enable);
369 }
370
John Younbea8e862016-11-03 17:55:53 -0700371 hsotg->params.dma_desc_fs_enable = val;
John Youn323230e2016-11-03 17:55:50 -0700372 dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val);
373}
374
John Younc1d286c2016-11-03 17:56:00 -0700375static void
376dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
377 int val)
John Youn323230e2016-11-03 17:55:50 -0700378{
379 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
380 if (val >= 0) {
381 dev_err(hsotg->dev,
382 "Wrong value for host_support_fs_low_power\n");
383 dev_err(hsotg->dev,
384 "host_support_fs_low_power must be 0 or 1\n");
385 }
386 val = 0;
387 dev_dbg(hsotg->dev,
388 "Setting host_support_fs_low_power to %d\n", val);
389 }
390
John Younbea8e862016-11-03 17:55:53 -0700391 hsotg->params.host_support_fs_ls_low_power = val;
John Youn323230e2016-11-03 17:55:50 -0700392}
393
John Younc1d286c2016-11-03 17:56:00 -0700394static void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
395 int val)
John Youn323230e2016-11-03 17:55:50 -0700396{
397 int valid = 1;
398
399 if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo)
400 valid = 0;
401 if (val < 0)
402 valid = 0;
403
404 if (!valid) {
405 if (val >= 0)
406 dev_err(hsotg->dev,
407 "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n",
408 val);
409 val = hsotg->hw_params.enable_dynamic_fifo;
410 dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val);
411 }
412
John Younbea8e862016-11-03 17:55:53 -0700413 hsotg->params.enable_dynamic_fifo = val;
John Youn323230e2016-11-03 17:55:50 -0700414}
415
John Younc1d286c2016-11-03 17:56:00 -0700416static void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700417{
418 int valid = 1;
419
John Yound1531312016-11-03 17:56:02 -0700420 if (val < 16 || val > hsotg->hw_params.rx_fifo_size)
John Youn323230e2016-11-03 17:55:50 -0700421 valid = 0;
422
423 if (!valid) {
424 if (val >= 0)
425 dev_err(hsotg->dev,
426 "%d invalid for host_rx_fifo_size. Check HW configuration.\n",
427 val);
John Yound1531312016-11-03 17:56:02 -0700428 val = hsotg->hw_params.rx_fifo_size;
John Youn323230e2016-11-03 17:55:50 -0700429 dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
430 }
431
John Younbea8e862016-11-03 17:55:53 -0700432 hsotg->params.host_rx_fifo_size = val;
John Youn323230e2016-11-03 17:55:50 -0700433}
434
John Younc1d286c2016-11-03 17:56:00 -0700435static void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
436 int val)
John Youn323230e2016-11-03 17:55:50 -0700437{
438 int valid = 1;
439
440 if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size)
441 valid = 0;
442
443 if (!valid) {
444 if (val >= 0)
445 dev_err(hsotg->dev,
446 "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
447 val);
448 val = hsotg->hw_params.host_nperio_tx_fifo_size;
449 dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n",
450 val);
451 }
452
John Younbea8e862016-11-03 17:55:53 -0700453 hsotg->params.host_nperio_tx_fifo_size = val;
John Youn323230e2016-11-03 17:55:50 -0700454}
455
John Younc1d286c2016-11-03 17:56:00 -0700456static void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
457 int val)
John Youn323230e2016-11-03 17:55:50 -0700458{
459 int valid = 1;
460
461 if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size)
462 valid = 0;
463
464 if (!valid) {
465 if (val >= 0)
466 dev_err(hsotg->dev,
467 "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
468 val);
469 val = hsotg->hw_params.host_perio_tx_fifo_size;
470 dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n",
471 val);
472 }
473
John Younbea8e862016-11-03 17:55:53 -0700474 hsotg->params.host_perio_tx_fifo_size = val;
John Youn323230e2016-11-03 17:55:50 -0700475}
476
John Younc1d286c2016-11-03 17:56:00 -0700477static void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700478{
479 int valid = 1;
480
481 if (val < 2047 || val > hsotg->hw_params.max_transfer_size)
482 valid = 0;
483
484 if (!valid) {
485 if (val >= 0)
486 dev_err(hsotg->dev,
487 "%d invalid for max_transfer_size. Check HW configuration.\n",
488 val);
489 val = hsotg->hw_params.max_transfer_size;
490 dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val);
491 }
492
John Younbea8e862016-11-03 17:55:53 -0700493 hsotg->params.max_transfer_size = val;
John Youn323230e2016-11-03 17:55:50 -0700494}
495
John Younc1d286c2016-11-03 17:56:00 -0700496static void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700497{
498 int valid = 1;
499
500 if (val < 15 || val > hsotg->hw_params.max_packet_count)
501 valid = 0;
502
503 if (!valid) {
504 if (val >= 0)
505 dev_err(hsotg->dev,
506 "%d invalid for max_packet_count. Check HW configuration.\n",
507 val);
508 val = hsotg->hw_params.max_packet_count;
509 dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val);
510 }
511
John Younbea8e862016-11-03 17:55:53 -0700512 hsotg->params.max_packet_count = val;
John Youn323230e2016-11-03 17:55:50 -0700513}
514
John Younc1d286c2016-11-03 17:56:00 -0700515static void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700516{
517 int valid = 1;
518
519 if (val < 1 || val > hsotg->hw_params.host_channels)
520 valid = 0;
521
522 if (!valid) {
523 if (val >= 0)
524 dev_err(hsotg->dev,
525 "%d invalid for host_channels. Check HW configuration.\n",
526 val);
527 val = hsotg->hw_params.host_channels;
528 dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val);
529 }
530
John Younbea8e862016-11-03 17:55:53 -0700531 hsotg->params.host_channels = val;
John Youn323230e2016-11-03 17:55:50 -0700532}
533
John Younc1d286c2016-11-03 17:56:00 -0700534static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700535{
536 int valid = 0;
537 u32 hs_phy_type, fs_phy_type;
538
539 if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS,
540 DWC2_PHY_TYPE_PARAM_ULPI)) {
541 if (val >= 0) {
542 dev_err(hsotg->dev, "Wrong value for phy_type\n");
543 dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n");
544 }
545
546 valid = 0;
547 }
548
549 hs_phy_type = hsotg->hw_params.hs_phy_type;
550 fs_phy_type = hsotg->hw_params.fs_phy_type;
551 if (val == DWC2_PHY_TYPE_PARAM_UTMI &&
552 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
553 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
554 valid = 1;
555 else if (val == DWC2_PHY_TYPE_PARAM_ULPI &&
556 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI ||
557 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
558 valid = 1;
559 else if (val == DWC2_PHY_TYPE_PARAM_FS &&
560 fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
561 valid = 1;
562
563 if (!valid) {
564 if (val >= 0)
565 dev_err(hsotg->dev,
566 "%d invalid for phy_type. Check HW configuration.\n",
567 val);
568 val = DWC2_PHY_TYPE_PARAM_FS;
569 if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
570 if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
571 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
572 val = DWC2_PHY_TYPE_PARAM_UTMI;
573 else
574 val = DWC2_PHY_TYPE_PARAM_ULPI;
575 }
576 dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val);
577 }
578
John Younbea8e862016-11-03 17:55:53 -0700579 hsotg->params.phy_type = val;
John Youn323230e2016-11-03 17:55:50 -0700580}
581
582static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg)
583{
John Younbea8e862016-11-03 17:55:53 -0700584 return hsotg->params.phy_type;
John Youn323230e2016-11-03 17:55:50 -0700585}
586
John Younc1d286c2016-11-03 17:56:00 -0700587static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700588{
589 int valid = 1;
590
591 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
592 if (val >= 0) {
593 dev_err(hsotg->dev, "Wrong value for speed parameter\n");
594 dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n");
595 }
596 valid = 0;
597 }
598
599 if (val == DWC2_SPEED_PARAM_HIGH &&
600 dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
601 valid = 0;
602
603 if (!valid) {
604 if (val >= 0)
605 dev_err(hsotg->dev,
606 "%d invalid for speed parameter. Check HW configuration.\n",
607 val);
608 val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ?
609 DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
610 dev_dbg(hsotg->dev, "Setting speed to %d\n", val);
611 }
612
John Younbea8e862016-11-03 17:55:53 -0700613 hsotg->params.speed = val;
John Youn323230e2016-11-03 17:55:50 -0700614}
615
John Younc1d286c2016-11-03 17:56:00 -0700616static void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
617 int val)
John Youn323230e2016-11-03 17:55:50 -0700618{
619 int valid = 1;
620
621 if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ,
622 DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) {
623 if (val >= 0) {
624 dev_err(hsotg->dev,
625 "Wrong value for host_ls_low_power_phy_clk parameter\n");
626 dev_err(hsotg->dev,
627 "host_ls_low_power_phy_clk must be 0 or 1\n");
628 }
629 valid = 0;
630 }
631
632 if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ &&
633 dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
634 valid = 0;
635
636 if (!valid) {
637 if (val >= 0)
638 dev_err(hsotg->dev,
639 "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
640 val);
641 val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS
642 ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ
643 : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
644 dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n",
645 val);
646 }
647
John Younbea8e862016-11-03 17:55:53 -0700648 hsotg->params.host_ls_low_power_phy_clk = val;
John Youn323230e2016-11-03 17:55:50 -0700649}
650
John Younc1d286c2016-11-03 17:56:00 -0700651static void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700652{
653 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
654 if (val >= 0) {
655 dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n");
656 dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n");
657 }
658 val = 0;
659 dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val);
660 }
661
John Younbea8e862016-11-03 17:55:53 -0700662 hsotg->params.phy_ulpi_ddr = val;
John Youn323230e2016-11-03 17:55:50 -0700663}
664
John Younc1d286c2016-11-03 17:56:00 -0700665static void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700666{
667 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
668 if (val >= 0) {
669 dev_err(hsotg->dev,
670 "Wrong value for phy_ulpi_ext_vbus\n");
671 dev_err(hsotg->dev,
672 "phy_ulpi_ext_vbus must be 0 or 1\n");
673 }
674 val = 0;
675 dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val);
676 }
677
John Younbea8e862016-11-03 17:55:53 -0700678 hsotg->params.phy_ulpi_ext_vbus = val;
John Youn323230e2016-11-03 17:55:50 -0700679}
680
John Younc1d286c2016-11-03 17:56:00 -0700681static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700682{
683 int valid = 0;
684
685 switch (hsotg->hw_params.utmi_phy_data_width) {
686 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
687 valid = (val == 8);
688 break;
689 case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
690 valid = (val == 16);
691 break;
692 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
693 valid = (val == 8 || val == 16);
694 break;
695 }
696
697 if (!valid) {
698 if (val >= 0) {
699 dev_err(hsotg->dev,
700 "%d invalid for phy_utmi_width. Check HW configuration.\n",
701 val);
702 }
703 val = (hsotg->hw_params.utmi_phy_data_width ==
704 GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
705 dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val);
706 }
707
John Younbea8e862016-11-03 17:55:53 -0700708 hsotg->params.phy_utmi_width = val;
John Youn323230e2016-11-03 17:55:50 -0700709}
710
John Younc1d286c2016-11-03 17:56:00 -0700711static void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700712{
713 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
714 if (val >= 0) {
715 dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n");
716 dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n");
717 }
718 val = 0;
719 dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val);
720 }
721
John Younbea8e862016-11-03 17:55:53 -0700722 hsotg->params.ulpi_fs_ls = val;
John Youn323230e2016-11-03 17:55:50 -0700723}
724
John Younc1d286c2016-11-03 17:56:00 -0700725static void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700726{
727 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
728 if (val >= 0) {
729 dev_err(hsotg->dev, "Wrong value for ts_dline\n");
730 dev_err(hsotg->dev, "ts_dline must be 0 or 1\n");
731 }
732 val = 0;
733 dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val);
734 }
735
John Younbea8e862016-11-03 17:55:53 -0700736 hsotg->params.ts_dline = val;
John Youn323230e2016-11-03 17:55:50 -0700737}
738
John Younc1d286c2016-11-03 17:56:00 -0700739static void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700740{
741 int valid = 1;
742
743 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
744 if (val >= 0) {
745 dev_err(hsotg->dev, "Wrong value for i2c_enable\n");
746 dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n");
747 }
748
749 valid = 0;
750 }
751
752 if (val == 1 && !(hsotg->hw_params.i2c_enable))
753 valid = 0;
754
755 if (!valid) {
756 if (val >= 0)
757 dev_err(hsotg->dev,
758 "%d invalid for i2c_enable. Check HW configuration.\n",
759 val);
760 val = hsotg->hw_params.i2c_enable;
761 dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
762 }
763
John Younbea8e862016-11-03 17:55:53 -0700764 hsotg->params.i2c_enable = val;
John Youn323230e2016-11-03 17:55:50 -0700765}
766
John Younc1d286c2016-11-03 17:56:00 -0700767static void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
768 int val)
John Youn323230e2016-11-03 17:55:50 -0700769{
770 int valid = 1;
771
772 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
773 if (val >= 0) {
774 dev_err(hsotg->dev,
775 "Wrong value for en_multiple_tx_fifo,\n");
776 dev_err(hsotg->dev,
777 "en_multiple_tx_fifo must be 0 or 1\n");
778 }
779 valid = 0;
780 }
781
782 if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo)
783 valid = 0;
784
785 if (!valid) {
786 if (val >= 0)
787 dev_err(hsotg->dev,
788 "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
789 val);
790 val = hsotg->hw_params.en_multiple_tx_fifo;
791 dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val);
792 }
793
John Younbea8e862016-11-03 17:55:53 -0700794 hsotg->params.en_multiple_tx_fifo = val;
John Youn323230e2016-11-03 17:55:50 -0700795}
796
John Younc1d286c2016-11-03 17:56:00 -0700797static void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700798{
799 int valid = 1;
800
801 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
802 if (val >= 0) {
803 dev_err(hsotg->dev,
804 "'%d' invalid for parameter reload_ctl\n", val);
805 dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n");
806 }
807 valid = 0;
808 }
809
810 if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a)
811 valid = 0;
812
813 if (!valid) {
814 if (val >= 0)
815 dev_err(hsotg->dev,
816 "%d invalid for parameter reload_ctl. Check HW configuration.\n",
817 val);
818 val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a;
819 dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val);
820 }
821
John Younbea8e862016-11-03 17:55:53 -0700822 hsotg->params.reload_ctl = val;
John Youn323230e2016-11-03 17:55:50 -0700823}
824
John Younc1d286c2016-11-03 17:56:00 -0700825static void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700826{
827 if (val != -1)
John Younbea8e862016-11-03 17:55:53 -0700828 hsotg->params.ahbcfg = val;
John Youn323230e2016-11-03 17:55:50 -0700829 else
John Younbea8e862016-11-03 17:55:53 -0700830 hsotg->params.ahbcfg = GAHBCFG_HBSTLEN_INCR4 <<
John Youn323230e2016-11-03 17:55:50 -0700831 GAHBCFG_HBSTLEN_SHIFT;
832}
833
John Younc1d286c2016-11-03 17:56:00 -0700834static void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val)
John Youn323230e2016-11-03 17:55:50 -0700835{
836 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
837 if (val >= 0) {
838 dev_err(hsotg->dev,
839 "'%d' invalid for parameter otg_ver\n", val);
840 dev_err(hsotg->dev,
841 "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n");
842 }
843 val = 0;
844 dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val);
845 }
846
John Younbea8e862016-11-03 17:55:53 -0700847 hsotg->params.otg_ver = val;
John Youn323230e2016-11-03 17:55:50 -0700848}
849
850static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val)
851{
852 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
853 if (val >= 0) {
854 dev_err(hsotg->dev,
855 "'%d' invalid for parameter uframe_sched\n",
856 val);
857 dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n");
858 }
859 val = 1;
860 dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val);
861 }
862
John Younbea8e862016-11-03 17:55:53 -0700863 hsotg->params.uframe_sched = val;
John Youn323230e2016-11-03 17:55:50 -0700864}
865
866static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg,
867 int val)
868{
869 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
870 if (val >= 0) {
871 dev_err(hsotg->dev,
872 "'%d' invalid for parameter external_id_pin_ctl\n",
873 val);
874 dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n");
875 }
876 val = 0;
877 dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val);
878 }
879
John Younbea8e862016-11-03 17:55:53 -0700880 hsotg->params.external_id_pin_ctl = val;
John Youn323230e2016-11-03 17:55:50 -0700881}
882
883static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg,
884 int val)
885{
886 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
887 if (val >= 0) {
888 dev_err(hsotg->dev,
889 "'%d' invalid for parameter hibernation\n",
890 val);
891 dev_err(hsotg->dev, "hibernation must be 0 or 1\n");
892 }
893 val = 0;
894 dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val);
895 }
896
John Younbea8e862016-11-03 17:55:53 -0700897 hsotg->params.hibernation = val;
John Youn323230e2016-11-03 17:55:50 -0700898}
899
900/*
901 * This function is called during module intialization to pass module parameters
902 * for the DWC_otg core.
903 */
John Younc1d286c2016-11-03 17:56:00 -0700904static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
905 const struct dwc2_core_params *params)
John Youn323230e2016-11-03 17:55:50 -0700906{
907 dev_dbg(hsotg->dev, "%s()\n", __func__);
908
909 dwc2_set_param_otg_cap(hsotg, params->otg_cap);
910 dwc2_set_param_dma_enable(hsotg, params->dma_enable);
911 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable);
912 dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable);
913 dwc2_set_param_host_support_fs_ls_low_power(hsotg,
914 params->host_support_fs_ls_low_power);
915 dwc2_set_param_enable_dynamic_fifo(hsotg,
916 params->enable_dynamic_fifo);
917 dwc2_set_param_host_rx_fifo_size(hsotg,
918 params->host_rx_fifo_size);
919 dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
920 params->host_nperio_tx_fifo_size);
921 dwc2_set_param_host_perio_tx_fifo_size(hsotg,
922 params->host_perio_tx_fifo_size);
923 dwc2_set_param_max_transfer_size(hsotg,
924 params->max_transfer_size);
925 dwc2_set_param_max_packet_count(hsotg,
926 params->max_packet_count);
927 dwc2_set_param_host_channels(hsotg, params->host_channels);
928 dwc2_set_param_phy_type(hsotg, params->phy_type);
929 dwc2_set_param_speed(hsotg, params->speed);
930 dwc2_set_param_host_ls_low_power_phy_clk(hsotg,
931 params->host_ls_low_power_phy_clk);
932 dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr);
933 dwc2_set_param_phy_ulpi_ext_vbus(hsotg,
934 params->phy_ulpi_ext_vbus);
935 dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width);
936 dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls);
937 dwc2_set_param_ts_dline(hsotg, params->ts_dline);
938 dwc2_set_param_i2c_enable(hsotg, params->i2c_enable);
939 dwc2_set_param_en_multiple_tx_fifo(hsotg,
940 params->en_multiple_tx_fifo);
941 dwc2_set_param_reload_ctl(hsotg, params->reload_ctl);
942 dwc2_set_param_ahbcfg(hsotg, params->ahbcfg);
943 dwc2_set_param_otg_ver(hsotg, params->otg_ver);
944 dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
945 dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
946 dwc2_set_param_hibernation(hsotg, params->hibernation);
947}
948
949/*
950 * Gets host hardware parameters. Forces host mode if not currently in
951 * host mode. Should be called immediately after a core soft reset in
952 * order to get the reset values.
953 */
954static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
955{
956 struct dwc2_hw_params *hw = &hsotg->hw_params;
957 u32 gnptxfsiz;
958 u32 hptxfsiz;
959 bool forced;
960
961 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
962 return;
963
964 forced = dwc2_force_mode_if_needed(hsotg, true);
965
966 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
967 hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
968 dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
969 dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz);
970
971 if (forced)
972 dwc2_clear_force_mode(hsotg);
973
974 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
975 FIFOSIZE_DEPTH_SHIFT;
976 hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
977 FIFOSIZE_DEPTH_SHIFT;
978}
979
980/*
981 * Gets device hardware parameters. Forces device mode if not
982 * currently in device mode. Should be called immediately after a core
983 * soft reset in order to get the reset values.
984 */
985static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
986{
987 struct dwc2_hw_params *hw = &hsotg->hw_params;
988 bool forced;
989 u32 gnptxfsiz;
990
991 if (hsotg->dr_mode == USB_DR_MODE_HOST)
992 return;
993
994 forced = dwc2_force_mode_if_needed(hsotg, false);
995
996 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
997 dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
998
999 if (forced)
1000 dwc2_clear_force_mode(hsotg);
1001
1002 hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
1003 FIFOSIZE_DEPTH_SHIFT;
1004}
1005
1006/**
1007 * During device initialization, read various hardware configuration
1008 * registers and interpret the contents.
1009 */
1010int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
1011{
1012 struct dwc2_hw_params *hw = &hsotg->hw_params;
1013 unsigned int width;
1014 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
1015 u32 grxfsiz;
1016
1017 /*
1018 * Attempt to ensure this device is really a DWC_otg Controller.
1019 * Read and verify the GSNPSID register contents. The value should be
1020 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
1021 * as in "OTG version 2.xx" or "OTG version 3.xx".
1022 */
1023 hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID);
1024 if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
1025 (hw->snpsid & 0xfffff000) != 0x4f543000) {
1026 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
1027 hw->snpsid);
1028 return -ENODEV;
1029 }
1030
1031 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
1032 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
1033 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
1034
1035 hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1);
1036 hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
1037 hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3);
1038 hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4);
1039 grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
1040
1041 dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1);
1042 dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2);
1043 dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3);
1044 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4);
1045 dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz);
1046
1047 /*
1048 * Host specific hardware parameters. Reading these parameters
1049 * requires the controller to be in host mode. The mode will
1050 * be forced, if necessary, to read these values.
1051 */
1052 dwc2_get_host_hwparams(hsotg);
1053 dwc2_get_dev_hwparams(hsotg);
1054
1055 /* hwcfg1 */
1056 hw->dev_ep_dirs = hwcfg1;
1057
1058 /* hwcfg2 */
1059 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
1060 GHWCFG2_OP_MODE_SHIFT;
1061 hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
1062 GHWCFG2_ARCHITECTURE_SHIFT;
1063 hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
1064 hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
1065 GHWCFG2_NUM_HOST_CHAN_SHIFT);
1066 hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
1067 GHWCFG2_HS_PHY_TYPE_SHIFT;
1068 hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
1069 GHWCFG2_FS_PHY_TYPE_SHIFT;
1070 hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
1071 GHWCFG2_NUM_DEV_EP_SHIFT;
1072 hw->nperio_tx_q_depth =
1073 (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
1074 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
1075 hw->host_perio_tx_q_depth =
1076 (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
1077 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
1078 hw->dev_token_q_depth =
1079 (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
1080 GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
1081
1082 /* hwcfg3 */
1083 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
1084 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
1085 hw->max_transfer_size = (1 << (width + 11)) - 1;
1086 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
1087 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
1088 hw->max_packet_count = (1 << (width + 4)) - 1;
1089 hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
1090 hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
1091 GHWCFG3_DFIFO_DEPTH_SHIFT;
1092
1093 /* hwcfg4 */
1094 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
1095 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
1096 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
1097 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
1098 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
1099 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
1100 GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
1101
1102 /* fifo sizes */
John Yound1531312016-11-03 17:56:02 -07001103 hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
John Youn323230e2016-11-03 17:55:50 -07001104 GRXFSIZ_DEPTH_SHIFT;
1105
1106 dev_dbg(hsotg->dev, "Detected values from hardware:\n");
1107 dev_dbg(hsotg->dev, " op_mode=%d\n",
1108 hw->op_mode);
1109 dev_dbg(hsotg->dev, " arch=%d\n",
1110 hw->arch);
1111 dev_dbg(hsotg->dev, " dma_desc_enable=%d\n",
1112 hw->dma_desc_enable);
1113 dev_dbg(hsotg->dev, " power_optimized=%d\n",
1114 hw->power_optimized);
1115 dev_dbg(hsotg->dev, " i2c_enable=%d\n",
1116 hw->i2c_enable);
1117 dev_dbg(hsotg->dev, " hs_phy_type=%d\n",
1118 hw->hs_phy_type);
1119 dev_dbg(hsotg->dev, " fs_phy_type=%d\n",
1120 hw->fs_phy_type);
1121 dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n",
1122 hw->utmi_phy_data_width);
1123 dev_dbg(hsotg->dev, " num_dev_ep=%d\n",
1124 hw->num_dev_ep);
1125 dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n",
1126 hw->num_dev_perio_in_ep);
1127 dev_dbg(hsotg->dev, " host_channels=%d\n",
1128 hw->host_channels);
1129 dev_dbg(hsotg->dev, " max_transfer_size=%d\n",
1130 hw->max_transfer_size);
1131 dev_dbg(hsotg->dev, " max_packet_count=%d\n",
1132 hw->max_packet_count);
1133 dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n",
1134 hw->nperio_tx_q_depth);
1135 dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n",
1136 hw->host_perio_tx_q_depth);
1137 dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n",
1138 hw->dev_token_q_depth);
1139 dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n",
1140 hw->enable_dynamic_fifo);
1141 dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n",
1142 hw->en_multiple_tx_fifo);
1143 dev_dbg(hsotg->dev, " total_fifo_size=%d\n",
1144 hw->total_fifo_size);
John Yound1531312016-11-03 17:56:02 -07001145 dev_dbg(hsotg->dev, " rx_fifo_size=%d\n",
1146 hw->rx_fifo_size);
John Youn323230e2016-11-03 17:55:50 -07001147 dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n",
1148 hw->host_nperio_tx_fifo_size);
1149 dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n",
1150 hw->host_perio_tx_fifo_size);
1151 dev_dbg(hsotg->dev, "\n");
1152
1153 return 0;
1154}
1155
John Youn334bbd42016-11-03 17:55:55 -07001156int dwc2_init_params(struct dwc2_hsotg *hsotg)
1157{
1158 const struct of_device_id *match;
John Youn0a7d0d72016-11-03 17:55:57 -07001159 struct dwc2_core_params params;
John Youn334bbd42016-11-03 17:55:55 -07001160
1161 match = of_match_device(dwc2_of_match_table, hsotg->dev);
John Youn0a7d0d72016-11-03 17:55:57 -07001162 if (match && match->data)
1163 params = *((struct dwc2_core_params *)match->data);
1164 else
1165 params = params_default;
John Youn334bbd42016-11-03 17:55:55 -07001166
John Youn0a7d0d72016-11-03 17:55:57 -07001167 dwc2_set_parameters(hsotg, &params);
John Youn334bbd42016-11-03 17:55:55 -07001168
1169 return 0;
1170}