2 * Copyright (C) 2004-2016 Synopsys, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
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.
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/of_device.h>
41 static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg)
43 struct dwc2_core_params *p = &hsotg->params;
45 p->host_rx_fifo_size = 774;
46 p->max_transfer_size = 65535;
47 p->max_packet_count = 511;
49 p->uframe_sched = false;
52 static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
54 struct dwc2_core_params *p = &hsotg->params;
56 p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
57 p->speed = DWC2_SPEED_PARAM_HIGH;
58 p->host_rx_fifo_size = 512;
59 p->host_nperio_tx_fifo_size = 512;
60 p->host_perio_tx_fifo_size = 512;
61 p->max_transfer_size = 65535;
62 p->max_packet_count = 511;
63 p->host_channels = 16;
64 p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
65 p->phy_utmi_width = 8;
66 p->i2c_enable = false;
67 p->reload_ctl = false;
68 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
69 GAHBCFG_HBSTLEN_SHIFT;
70 p->uframe_sched = false;
71 p->change_speed_quirk = true;
74 static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg)
76 struct dwc2_core_params *p = &hsotg->params;
78 p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
79 p->host_rx_fifo_size = 525;
80 p->host_nperio_tx_fifo_size = 128;
81 p->host_perio_tx_fifo_size = 256;
82 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
83 GAHBCFG_HBSTLEN_SHIFT;
86 static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)
88 struct dwc2_core_params *p = &hsotg->params;
91 p->host_rx_fifo_size = 288;
92 p->host_nperio_tx_fifo_size = 128;
93 p->host_perio_tx_fifo_size = 96;
94 p->max_transfer_size = 65535;
95 p->max_packet_count = 511;
96 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
97 GAHBCFG_HBSTLEN_SHIFT;
100 static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg)
102 struct dwc2_core_params *p = &hsotg->params;
104 p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
105 p->speed = DWC2_SPEED_PARAM_HIGH;
106 p->host_rx_fifo_size = 512;
107 p->host_nperio_tx_fifo_size = 500;
108 p->host_perio_tx_fifo_size = 500;
109 p->host_channels = 16;
110 p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
111 p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 <<
112 GAHBCFG_HBSTLEN_SHIFT;
113 p->uframe_sched = false;
116 static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg)
118 struct dwc2_core_params *p = &hsotg->params;
120 p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
123 const struct of_device_id dwc2_of_match_table[] = {
124 { .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params },
125 { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params },
126 { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params },
127 { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params },
128 { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params },
129 { .compatible = "snps,dwc2" },
130 { .compatible = "samsung,s3c6400-hsotg" },
131 { .compatible = "amlogic,meson8b-usb",
132 .data = dwc2_set_amlogic_params },
133 { .compatible = "amlogic,meson-gxbb-usb",
134 .data = dwc2_set_amlogic_params },
135 { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params },
138 MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
140 static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg)
144 switch (hsotg->hw_params.op_mode) {
145 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
146 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
148 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
149 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
150 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
151 val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
154 val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
158 hsotg->params.otg_cap = val;
161 static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg)
164 u32 hs_phy_type = hsotg->hw_params.hs_phy_type;
166 val = DWC2_PHY_TYPE_PARAM_FS;
167 if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
168 if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
169 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
170 val = DWC2_PHY_TYPE_PARAM_UTMI;
172 val = DWC2_PHY_TYPE_PARAM_ULPI;
175 if (dwc2_is_fs_iot(hsotg))
176 hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS;
178 hsotg->params.phy_type = val;
181 static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg)
185 val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ?
186 DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
188 if (dwc2_is_fs_iot(hsotg))
189 val = DWC2_SPEED_PARAM_FULL;
191 if (dwc2_is_hs_iot(hsotg))
192 val = DWC2_SPEED_PARAM_HIGH;
194 hsotg->params.speed = val;
197 static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
201 val = (hsotg->hw_params.utmi_phy_data_width ==
202 GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
204 hsotg->params.phy_utmi_width = val;
207 static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
209 struct dwc2_core_params *p = &hsotg->params;
214 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
216 memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
217 depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg);
218 for (i = 1; i <= fifo_count; i++)
219 p->g_tx_fifo_size[i] = depth_average;
223 * dwc2_set_default_params() - Set all core parameters to their
224 * auto-detected default values.
226 static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
228 struct dwc2_hw_params *hw = &hsotg->hw_params;
229 struct dwc2_core_params *p = &hsotg->params;
230 bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
232 dwc2_set_param_otg_cap(hsotg);
233 dwc2_set_param_phy_type(hsotg);
234 dwc2_set_param_speed(hsotg);
235 dwc2_set_param_phy_utmi_width(hsotg);
236 p->phy_ulpi_ddr = false;
237 p->phy_ulpi_ext_vbus = false;
239 p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
240 p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
241 p->i2c_enable = hw->i2c_enable;
242 p->ulpi_fs_ls = false;
244 p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
245 p->uframe_sched = true;
246 p->external_id_pin_ctl = false;
247 p->hibernation = false;
248 p->max_packet_count = hw->max_packet_count;
249 p->max_transfer_size = hw->max_transfer_size;
250 p->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << GAHBCFG_HBSTLEN_SHIFT;
252 if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
253 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
254 p->host_dma = dma_capable;
255 p->dma_desc_enable = false;
256 p->dma_desc_fs_enable = false;
257 p->host_support_fs_ls_low_power = false;
258 p->host_ls_low_power_phy_clk = false;
259 p->host_channels = hw->host_channels;
260 p->host_rx_fifo_size = hw->rx_fifo_size;
261 p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size;
262 p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size;
265 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
266 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
267 p->g_dma = dma_capable;
268 p->g_dma_desc = hw->dma_desc_enable;
271 * The values for g_rx_fifo_size (2048) and
272 * g_np_tx_fifo_size (1024) come from the legacy s3c
273 * gadget driver. These defaults have been hard-coded
274 * for some time so many platforms depend on these
275 * values. Leave them as defaults for now and only
276 * auto-detect if the hardware does not support the
279 p->g_rx_fifo_size = 2048;
280 p->g_np_tx_fifo_size = 1024;
281 dwc2_set_param_tx_fifo_sizes(hsotg);
286 * dwc2_get_device_properties() - Read in device properties.
288 * Read in the device properties and adjust core parameters if needed.
290 static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
292 struct dwc2_core_params *p = &hsotg->params;
295 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
296 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
297 device_property_read_u32(hsotg->dev, "g-rx-fifo-size",
300 device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size",
301 &p->g_np_tx_fifo_size);
303 num = device_property_read_u32_array(hsotg->dev,
309 memset(p->g_tx_fifo_size, 0,
310 sizeof(p->g_tx_fifo_size));
311 device_property_read_u32_array(hsotg->dev,
313 &p->g_tx_fifo_size[1],
319 static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
323 switch (hsotg->params.otg_cap) {
324 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
325 if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
328 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
329 switch (hsotg->hw_params.op_mode) {
330 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
331 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
332 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
333 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
340 case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
349 dwc2_set_param_otg_cap(hsotg);
352 static void dwc2_check_param_phy_type(struct dwc2_hsotg *hsotg)
358 hs_phy_type = hsotg->hw_params.hs_phy_type;
359 fs_phy_type = hsotg->hw_params.fs_phy_type;
361 switch (hsotg->params.phy_type) {
362 case DWC2_PHY_TYPE_PARAM_FS:
363 if (fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
366 case DWC2_PHY_TYPE_PARAM_UTMI:
367 if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
368 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
371 case DWC2_PHY_TYPE_PARAM_ULPI:
372 if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
373 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
381 dwc2_set_param_phy_type(hsotg);
384 static void dwc2_check_param_speed(struct dwc2_hsotg *hsotg)
387 int phy_type = hsotg->params.phy_type;
388 int speed = hsotg->params.speed;
391 case DWC2_SPEED_PARAM_HIGH:
392 if ((hsotg->params.speed == DWC2_SPEED_PARAM_HIGH) &&
393 (phy_type == DWC2_PHY_TYPE_PARAM_FS))
396 case DWC2_SPEED_PARAM_FULL:
397 case DWC2_SPEED_PARAM_LOW:
405 dwc2_set_param_speed(hsotg);
408 static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
411 int param = hsotg->params.phy_utmi_width;
412 int width = hsotg->hw_params.utmi_phy_data_width;
415 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
416 valid = (param == 8);
418 case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
419 valid = (param == 16);
421 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
422 valid = (param == 8 || param == 16);
427 dwc2_set_param_phy_utmi_width(hsotg);
430 static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
438 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
439 min = hsotg->hw_params.en_multiple_tx_fifo ? 16 : 4;
441 for (fifo = 1; fifo <= fifo_count; fifo++)
442 total += hsotg->params.g_tx_fifo_size[fifo];
444 if (total > dwc2_hsotg_tx_fifo_total_depth(hsotg) || !total) {
445 dev_warn(hsotg->dev, "%s: Invalid parameter g-tx-fifo-size, setting to default average\n",
447 dwc2_set_param_tx_fifo_sizes(hsotg);
450 for (fifo = 1; fifo <= fifo_count; fifo++) {
451 dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
452 FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
454 if (hsotg->params.g_tx_fifo_size[fifo] < min ||
455 hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) {
456 dev_warn(hsotg->dev, "%s: Invalid parameter g_tx_fifo_size[%d]=%d\n",
458 hsotg->params.g_tx_fifo_size[fifo]);
459 hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
464 #define CHECK_RANGE(_param, _min, _max, _def) do { \
465 if ((hsotg->params._param) < (_min) || \
466 (hsotg->params._param) > (_max)) { \
467 dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
468 __func__, #_param, hsotg->params._param); \
469 hsotg->params._param = (_def); \
473 #define CHECK_BOOL(_param, _check) do { \
474 if (hsotg->params._param && !(_check)) { \
475 dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
476 __func__, #_param, hsotg->params._param); \
477 hsotg->params._param = false; \
481 static void dwc2_check_params(struct dwc2_hsotg *hsotg)
483 struct dwc2_hw_params *hw = &hsotg->hw_params;
484 struct dwc2_core_params *p = &hsotg->params;
485 bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
487 dwc2_check_param_otg_cap(hsotg);
488 dwc2_check_param_phy_type(hsotg);
489 dwc2_check_param_speed(hsotg);
490 dwc2_check_param_phy_utmi_width(hsotg);
491 CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo);
492 CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo);
493 CHECK_BOOL(i2c_enable, hw->i2c_enable);
494 CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a));
495 CHECK_RANGE(max_packet_count,
496 15, hw->max_packet_count,
497 hw->max_packet_count);
498 CHECK_RANGE(max_transfer_size,
499 2047, hw->max_transfer_size,
500 hw->max_transfer_size);
502 if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
503 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
504 CHECK_BOOL(host_dma, dma_capable);
505 CHECK_BOOL(dma_desc_enable, p->host_dma);
506 CHECK_BOOL(dma_desc_fs_enable, p->dma_desc_enable);
507 CHECK_BOOL(host_ls_low_power_phy_clk,
508 p->phy_type == DWC2_PHY_TYPE_PARAM_FS);
509 CHECK_RANGE(host_channels,
510 1, hw->host_channels,
512 CHECK_RANGE(host_rx_fifo_size,
513 16, hw->rx_fifo_size,
515 CHECK_RANGE(host_nperio_tx_fifo_size,
516 16, hw->host_nperio_tx_fifo_size,
517 hw->host_nperio_tx_fifo_size);
518 CHECK_RANGE(host_perio_tx_fifo_size,
519 16, hw->host_perio_tx_fifo_size,
520 hw->host_perio_tx_fifo_size);
523 if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
524 (hsotg->dr_mode == USB_DR_MODE_OTG)) {
525 CHECK_BOOL(g_dma, dma_capable);
526 CHECK_BOOL(g_dma_desc, (p->g_dma && hw->dma_desc_enable));
527 CHECK_RANGE(g_rx_fifo_size,
528 16, hw->rx_fifo_size,
530 CHECK_RANGE(g_np_tx_fifo_size,
531 16, hw->dev_nperio_tx_fifo_size,
532 hw->dev_nperio_tx_fifo_size);
533 dwc2_check_param_tx_fifo_sizes(hsotg);
538 * Gets host hardware parameters. Forces host mode if not currently in
539 * host mode. Should be called immediately after a core soft reset in
540 * order to get the reset values.
542 static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
544 struct dwc2_hw_params *hw = &hsotg->hw_params;
549 if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
552 forced = dwc2_force_mode_if_needed(hsotg, true);
554 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
555 hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ);
558 dwc2_clear_force_mode(hsotg);
560 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
561 FIFOSIZE_DEPTH_SHIFT;
562 hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
563 FIFOSIZE_DEPTH_SHIFT;
567 * Gets device hardware parameters. Forces device mode if not
568 * currently in device mode. Should be called immediately after a core
569 * soft reset in order to get the reset values.
571 static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
573 struct dwc2_hw_params *hw = &hsotg->hw_params;
577 if (hsotg->dr_mode == USB_DR_MODE_HOST)
580 forced = dwc2_force_mode_if_needed(hsotg, false);
582 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
585 dwc2_clear_force_mode(hsotg);
587 hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
588 FIFOSIZE_DEPTH_SHIFT;
592 * During device initialization, read various hardware configuration
593 * registers and interpret the contents.
595 int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
597 struct dwc2_hw_params *hw = &hsotg->hw_params;
599 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
603 * Attempt to ensure this device is really a DWC_otg Controller.
604 * Read and verify the GSNPSID register contents. The value should be
605 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
606 * as in "OTG version 2.xx" or "OTG version 3.xx".
608 hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID);
609 if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
610 (hw->snpsid & 0xfffff000) != 0x4f543000 &&
611 (hw->snpsid & 0xffff0000) != 0x55310000 &&
612 (hw->snpsid & 0xffff0000) != 0x55320000) {
613 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
618 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
619 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
620 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
622 hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1);
623 hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
624 hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3);
625 hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4);
626 grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
629 * Host specific hardware parameters. Reading these parameters
630 * requires the controller to be in host mode. The mode will
631 * be forced, if necessary, to read these values.
633 dwc2_get_host_hwparams(hsotg);
634 dwc2_get_dev_hwparams(hsotg);
637 hw->dev_ep_dirs = hwcfg1;
640 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
641 GHWCFG2_OP_MODE_SHIFT;
642 hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
643 GHWCFG2_ARCHITECTURE_SHIFT;
644 hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
645 hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
646 GHWCFG2_NUM_HOST_CHAN_SHIFT);
647 hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
648 GHWCFG2_HS_PHY_TYPE_SHIFT;
649 hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
650 GHWCFG2_FS_PHY_TYPE_SHIFT;
651 hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
652 GHWCFG2_NUM_DEV_EP_SHIFT;
653 hw->nperio_tx_q_depth =
654 (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
655 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
656 hw->host_perio_tx_q_depth =
657 (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
658 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
659 hw->dev_token_q_depth =
660 (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
661 GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
664 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
665 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
666 hw->max_transfer_size = (1 << (width + 11)) - 1;
667 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
668 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
669 hw->max_packet_count = (1 << (width + 4)) - 1;
670 hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
671 hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
672 GHWCFG3_DFIFO_DEPTH_SHIFT;
675 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
676 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
677 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
678 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
679 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
680 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
681 GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
684 hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
690 int dwc2_init_params(struct dwc2_hsotg *hsotg)
692 const struct of_device_id *match;
693 void (*set_params)(void *data);
695 dwc2_set_default_params(hsotg);
696 dwc2_get_device_properties(hsotg);
698 match = of_match_device(dwc2_of_match_table, hsotg->dev);
699 if (match && match->data) {
700 set_params = match->data;
704 dwc2_check_params(hsotg);