15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2323230efSJohn Youn /*
3323230efSJohn Youn * Copyright (C) 2004-2016 Synopsys, Inc.
4323230efSJohn Youn */
5323230efSJohn Youn
6323230efSJohn Youn #include <linux/kernel.h>
7323230efSJohn Youn #include <linux/module.h>
8323230efSJohn Youn #include <linux/of_device.h>
9f5c8a6cbSFabrice Gasnier #include <linux/usb/of.h>
10*e16d5f14SYinbo Zhu #include <linux/pci_ids.h>
11*e16d5f14SYinbo Zhu #include <linux/pci.h>
12323230efSJohn Youn
13323230efSJohn Youn #include "core.h"
14323230efSJohn Youn
15*e16d5f14SYinbo Zhu #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0
16*e16d5f14SYinbo Zhu #define PCI_DEVICE_ID_LOONGSON_DWC2 0x7a04
17*e16d5f14SYinbo Zhu
dwc2_set_bcm_params(struct dwc2_hsotg * hsotg)187de1debcSJohn Youn static void dwc2_set_bcm_params(struct dwc2_hsotg *hsotg)
197de1debcSJohn Youn {
207de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
21323230efSJohn Youn
227de1debcSJohn Youn p->host_rx_fifo_size = 774;
237de1debcSJohn Youn p->max_transfer_size = 65535;
247de1debcSJohn Youn p->max_packet_count = 511;
257de1debcSJohn Youn p->ahbcfg = 0x10;
267de1debcSJohn Youn }
27323230efSJohn Youn
dwc2_set_his_params(struct dwc2_hsotg * hsotg)287de1debcSJohn Youn static void dwc2_set_his_params(struct dwc2_hsotg *hsotg)
297de1debcSJohn Youn {
307de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
31323230efSJohn Youn
32f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
33f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
347de1debcSJohn Youn p->speed = DWC2_SPEED_PARAM_HIGH;
357de1debcSJohn Youn p->host_rx_fifo_size = 512;
367de1debcSJohn Youn p->host_nperio_tx_fifo_size = 512;
377de1debcSJohn Youn p->host_perio_tx_fifo_size = 512;
387de1debcSJohn Youn p->max_transfer_size = 65535;
397de1debcSJohn Youn p->max_packet_count = 511;
407de1debcSJohn Youn p->host_channels = 16;
417de1debcSJohn Youn p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
427de1debcSJohn Youn p->phy_utmi_width = 8;
437de1debcSJohn Youn p->i2c_enable = false;
447de1debcSJohn Youn p->reload_ctl = false;
457de1debcSJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
467de1debcSJohn Youn GAHBCFG_HBSTLEN_SHIFT;
47ca8b0332SChen Yu p->change_speed_quirk = true;
4807d9878fSJisheng Zhang p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
497de1debcSJohn Youn }
50323230efSJohn Youn
dwc2_set_jz4775_params(struct dwc2_hsotg * hsotg)51d712b725S周琰杰 (Zhou Yanjie) static void dwc2_set_jz4775_params(struct dwc2_hsotg *hsotg)
52d712b725S周琰杰 (Zhou Yanjie) {
53d712b725S周琰杰 (Zhou Yanjie) struct dwc2_core_params *p = &hsotg->params;
54d712b725S周琰杰 (Zhou Yanjie)
55d712b725S周琰杰 (Zhou Yanjie) p->otg_caps.hnp_support = false;
56d712b725S周琰杰 (Zhou Yanjie) p->speed = DWC2_SPEED_PARAM_HIGH;
57d712b725S周琰杰 (Zhou Yanjie) p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
58d712b725S周琰杰 (Zhou Yanjie) p->phy_utmi_width = 16;
59d712b725S周琰杰 (Zhou Yanjie) p->activate_ingenic_overcurrent_detection =
60d712b725S周琰杰 (Zhou Yanjie) !device_property_read_bool(hsotg->dev, "disable-over-current");
61d712b725S周琰杰 (Zhou Yanjie) }
62d712b725S周琰杰 (Zhou Yanjie)
dwc2_set_loongson_params(struct dwc2_hsotg * hsotg)63*e16d5f14SYinbo Zhu static void dwc2_set_loongson_params(struct dwc2_hsotg *hsotg)
64*e16d5f14SYinbo Zhu {
65*e16d5f14SYinbo Zhu struct dwc2_core_params *p = &hsotg->params;
66*e16d5f14SYinbo Zhu
67*e16d5f14SYinbo Zhu p->phy_utmi_width = 8;
68*e16d5f14SYinbo Zhu p->power_down = DWC2_POWER_DOWN_PARAM_PARTIAL;
69*e16d5f14SYinbo Zhu }
70*e16d5f14SYinbo Zhu
dwc2_set_x1600_params(struct dwc2_hsotg * hsotg)71d712b725S周琰杰 (Zhou Yanjie) static void dwc2_set_x1600_params(struct dwc2_hsotg *hsotg)
72d712b725S周琰杰 (Zhou Yanjie) {
73d712b725S周琰杰 (Zhou Yanjie) struct dwc2_core_params *p = &hsotg->params;
74d712b725S周琰杰 (Zhou Yanjie)
75d712b725S周琰杰 (Zhou Yanjie) p->otg_caps.hnp_support = false;
76d712b725S周琰杰 (Zhou Yanjie) p->speed = DWC2_SPEED_PARAM_HIGH;
77d712b725S周琰杰 (Zhou Yanjie) p->host_channels = 16;
78d712b725S周琰杰 (Zhou Yanjie) p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
79d712b725S周琰杰 (Zhou Yanjie) p->phy_utmi_width = 16;
80d712b725S周琰杰 (Zhou Yanjie) p->activate_ingenic_overcurrent_detection =
81d712b725S周琰杰 (Zhou Yanjie) !device_property_read_bool(hsotg->dev, "disable-over-current");
82d712b725S周琰杰 (Zhou Yanjie) }
83d712b725S周琰杰 (Zhou Yanjie)
dwc2_set_x2000_params(struct dwc2_hsotg * hsotg)84d712b725S周琰杰 (Zhou Yanjie) static void dwc2_set_x2000_params(struct dwc2_hsotg *hsotg)
85d712b725S周琰杰 (Zhou Yanjie) {
86d712b725S周琰杰 (Zhou Yanjie) struct dwc2_core_params *p = &hsotg->params;
87d712b725S周琰杰 (Zhou Yanjie)
88d712b725S周琰杰 (Zhou Yanjie) p->otg_caps.hnp_support = false;
89d712b725S周琰杰 (Zhou Yanjie) p->speed = DWC2_SPEED_PARAM_HIGH;
90d712b725S周琰杰 (Zhou Yanjie) p->host_rx_fifo_size = 1024;
91d712b725S周琰杰 (Zhou Yanjie) p->host_nperio_tx_fifo_size = 1024;
92d712b725S周琰杰 (Zhou Yanjie) p->host_perio_tx_fifo_size = 1024;
93d712b725S周琰杰 (Zhou Yanjie) p->host_channels = 16;
94d712b725S周琰杰 (Zhou Yanjie) p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
95d712b725S周琰杰 (Zhou Yanjie) p->phy_utmi_width = 16;
96d712b725S周琰杰 (Zhou Yanjie) p->activate_ingenic_overcurrent_detection =
97d712b725S周琰杰 (Zhou Yanjie) !device_property_read_bool(hsotg->dev, "disable-over-current");
98d712b725S周琰杰 (Zhou Yanjie) }
99d712b725S周琰杰 (Zhou Yanjie)
dwc2_set_s3c6400_params(struct dwc2_hsotg * hsotg)10035a60541SMarek Szyprowski static void dwc2_set_s3c6400_params(struct dwc2_hsotg *hsotg)
10135a60541SMarek Szyprowski {
10235a60541SMarek Szyprowski struct dwc2_core_params *p = &hsotg->params;
10335a60541SMarek Szyprowski
10407d9878fSJisheng Zhang p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
105c4a0f7a6SMarek Szyprowski p->no_clock_gating = true;
1061112cf4cSMarek Szyprowski p->phy_utmi_width = 8;
10735a60541SMarek Szyprowski }
10835a60541SMarek Szyprowski
dwc2_set_socfpga_agilex_params(struct dwc2_hsotg * hsotg)1093d8d3504SDinh Nguyen static void dwc2_set_socfpga_agilex_params(struct dwc2_hsotg *hsotg)
1103d8d3504SDinh Nguyen {
1113d8d3504SDinh Nguyen struct dwc2_core_params *p = &hsotg->params;
1123d8d3504SDinh Nguyen
1133d8d3504SDinh Nguyen p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
1143d8d3504SDinh Nguyen p->no_clock_gating = true;
1153d8d3504SDinh Nguyen }
1163d8d3504SDinh Nguyen
dwc2_set_rk_params(struct dwc2_hsotg * hsotg)1177de1debcSJohn Youn static void dwc2_set_rk_params(struct dwc2_hsotg *hsotg)
1187de1debcSJohn Youn {
1197de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
1207de1debcSJohn Youn
121f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
122f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
1237de1debcSJohn Youn p->host_rx_fifo_size = 525;
1247de1debcSJohn Youn p->host_nperio_tx_fifo_size = 128;
1257de1debcSJohn Youn p->host_perio_tx_fifo_size = 256;
1267de1debcSJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
1277de1debcSJohn Youn GAHBCFG_HBSTLEN_SHIFT;
12807d9878fSJisheng Zhang p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
12942a317d0SQuentin Schulz p->lpm = false;
13042a317d0SQuentin Schulz p->lpm_clock_gating = false;
13142a317d0SQuentin Schulz p->besl = false;
13242a317d0SQuentin Schulz p->hird_threshold_en = false;
1337de1debcSJohn Youn }
1347de1debcSJohn Youn
dwc2_set_ltq_params(struct dwc2_hsotg * hsotg)1357de1debcSJohn Youn static void dwc2_set_ltq_params(struct dwc2_hsotg *hsotg)
1367de1debcSJohn Youn {
1377de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
1387de1debcSJohn Youn
139f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
140f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
1417de1debcSJohn Youn p->host_rx_fifo_size = 288;
1427de1debcSJohn Youn p->host_nperio_tx_fifo_size = 128;
1437de1debcSJohn Youn p->host_perio_tx_fifo_size = 96;
1447de1debcSJohn Youn p->max_transfer_size = 65535;
1457de1debcSJohn Youn p->max_packet_count = 511;
1467de1debcSJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
1477de1debcSJohn Youn GAHBCFG_HBSTLEN_SHIFT;
1487de1debcSJohn Youn }
1497de1debcSJohn Youn
dwc2_set_amlogic_params(struct dwc2_hsotg * hsotg)1507de1debcSJohn Youn static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg)
1517de1debcSJohn Youn {
1527de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
1537de1debcSJohn Youn
154f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
155f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
1567de1debcSJohn Youn p->speed = DWC2_SPEED_PARAM_HIGH;
1577de1debcSJohn Youn p->host_rx_fifo_size = 512;
1587de1debcSJohn Youn p->host_nperio_tx_fifo_size = 500;
1597de1debcSJohn Youn p->host_perio_tx_fifo_size = 500;
1607de1debcSJohn Youn p->host_channels = 16;
1617de1debcSJohn Youn p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
1627de1debcSJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 <<
1637de1debcSJohn Youn GAHBCFG_HBSTLEN_SHIFT;
164cc10ce0cSMartin Blumenstingl p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
1657de1debcSJohn Youn }
1667de1debcSJohn Youn
dwc2_set_amlogic_g12a_params(struct dwc2_hsotg * hsotg)167fc4e326eSNeil Armstrong static void dwc2_set_amlogic_g12a_params(struct dwc2_hsotg *hsotg)
168fc4e326eSNeil Armstrong {
169fc4e326eSNeil Armstrong struct dwc2_core_params *p = &hsotg->params;
170fc4e326eSNeil Armstrong
171fc4e326eSNeil Armstrong p->lpm = false;
172fc4e326eSNeil Armstrong p->lpm_clock_gating = false;
173fc4e326eSNeil Armstrong p->besl = false;
174fc4e326eSNeil Armstrong p->hird_threshold_en = false;
175fc4e326eSNeil Armstrong }
176fc4e326eSNeil Armstrong
dwc2_set_amlogic_a1_params(struct dwc2_hsotg * hsotg)177be877fbfSDmitry Rokosov static void dwc2_set_amlogic_a1_params(struct dwc2_hsotg *hsotg)
178be877fbfSDmitry Rokosov {
179be877fbfSDmitry Rokosov struct dwc2_core_params *p = &hsotg->params;
180be877fbfSDmitry Rokosov
181be877fbfSDmitry Rokosov p->otg_caps.hnp_support = false;
182be877fbfSDmitry Rokosov p->otg_caps.srp_support = false;
183be877fbfSDmitry Rokosov p->speed = DWC2_SPEED_PARAM_HIGH;
184be877fbfSDmitry Rokosov p->host_rx_fifo_size = 192;
185be877fbfSDmitry Rokosov p->host_nperio_tx_fifo_size = 128;
186be877fbfSDmitry Rokosov p->host_perio_tx_fifo_size = 128;
187be877fbfSDmitry Rokosov p->phy_type = DWC2_PHY_TYPE_PARAM_UTMI;
188be877fbfSDmitry Rokosov p->phy_utmi_width = 8;
189be877fbfSDmitry Rokosov p->ahbcfg = GAHBCFG_HBSTLEN_INCR8 << GAHBCFG_HBSTLEN_SHIFT;
190be877fbfSDmitry Rokosov p->lpm = false;
191be877fbfSDmitry Rokosov p->lpm_clock_gating = false;
192be877fbfSDmitry Rokosov p->besl = false;
193be877fbfSDmitry Rokosov p->hird_threshold_en = false;
194be877fbfSDmitry Rokosov }
195be877fbfSDmitry Rokosov
dwc2_set_amcc_params(struct dwc2_hsotg * hsotg)1967de1debcSJohn Youn static void dwc2_set_amcc_params(struct dwc2_hsotg *hsotg)
1977de1debcSJohn Youn {
1987de1debcSJohn Youn struct dwc2_core_params *p = &hsotg->params;
1997de1debcSJohn Youn
2007de1debcSJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
2017de1debcSJohn Youn }
202323230efSJohn Youn
dwc2_set_stm32f4x9_fsotg_params(struct dwc2_hsotg * hsotg)203e35b1350SBruno Herrera static void dwc2_set_stm32f4x9_fsotg_params(struct dwc2_hsotg *hsotg)
204e35b1350SBruno Herrera {
205e35b1350SBruno Herrera struct dwc2_core_params *p = &hsotg->params;
206e35b1350SBruno Herrera
207f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
208f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
209e35b1350SBruno Herrera p->speed = DWC2_SPEED_PARAM_FULL;
210e35b1350SBruno Herrera p->host_rx_fifo_size = 128;
211e35b1350SBruno Herrera p->host_nperio_tx_fifo_size = 96;
212e35b1350SBruno Herrera p->host_perio_tx_fifo_size = 96;
213e35b1350SBruno Herrera p->max_packet_count = 256;
214e35b1350SBruno Herrera p->phy_type = DWC2_PHY_TYPE_PARAM_FS;
215e35b1350SBruno Herrera p->i2c_enable = false;
216e35b1350SBruno Herrera p->activate_stm_fs_transceiver = true;
217e35b1350SBruno Herrera }
218e35b1350SBruno Herrera
dwc2_set_stm32f7_hsotg_params(struct dwc2_hsotg * hsotg)2191a149e35SAmelie Delaunay static void dwc2_set_stm32f7_hsotg_params(struct dwc2_hsotg *hsotg)
220d8fae8b9SAmelie Delaunay {
221d8fae8b9SAmelie Delaunay struct dwc2_core_params *p = &hsotg->params;
222d8fae8b9SAmelie Delaunay
223d8fae8b9SAmelie Delaunay p->host_rx_fifo_size = 622;
224d8fae8b9SAmelie Delaunay p->host_nperio_tx_fifo_size = 128;
225d8fae8b9SAmelie Delaunay p->host_perio_tx_fifo_size = 256;
226d8fae8b9SAmelie Delaunay }
227d8fae8b9SAmelie Delaunay
dwc2_set_stm32mp15_fsotg_params(struct dwc2_hsotg * hsotg)228a415083aSAmelie Delaunay static void dwc2_set_stm32mp15_fsotg_params(struct dwc2_hsotg *hsotg)
229a415083aSAmelie Delaunay {
230a415083aSAmelie Delaunay struct dwc2_core_params *p = &hsotg->params;
231a415083aSAmelie Delaunay
232f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
233f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
2349e894ee3SFabrice Gasnier p->otg_caps.otg_rev = 0x200;
235a415083aSAmelie Delaunay p->speed = DWC2_SPEED_PARAM_FULL;
236a415083aSAmelie Delaunay p->host_rx_fifo_size = 128;
237a415083aSAmelie Delaunay p->host_nperio_tx_fifo_size = 96;
238a415083aSAmelie Delaunay p->host_perio_tx_fifo_size = 96;
239a415083aSAmelie Delaunay p->max_packet_count = 256;
240a415083aSAmelie Delaunay p->phy_type = DWC2_PHY_TYPE_PARAM_FS;
241a415083aSAmelie Delaunay p->i2c_enable = false;
242a415083aSAmelie Delaunay p->activate_stm_fs_transceiver = true;
243a415083aSAmelie Delaunay p->activate_stm_id_vb_detection = true;
2442979ee7aSAmelie Delaunay p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
245a415083aSAmelie Delaunay p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
246f228cb27SAmelie Delaunay p->host_support_fs_ls_low_power = true;
247f228cb27SAmelie Delaunay p->host_ls_low_power_phy_clk = true;
248a415083aSAmelie Delaunay }
249a415083aSAmelie Delaunay
dwc2_set_stm32mp15_hsotg_params(struct dwc2_hsotg * hsotg)250a415083aSAmelie Delaunay static void dwc2_set_stm32mp15_hsotg_params(struct dwc2_hsotg *hsotg)
251a415083aSAmelie Delaunay {
252a415083aSAmelie Delaunay struct dwc2_core_params *p = &hsotg->params;
253a415083aSAmelie Delaunay
254f5c8a6cbSFabrice Gasnier p->otg_caps.hnp_support = false;
255f5c8a6cbSFabrice Gasnier p->otg_caps.srp_support = false;
2569e894ee3SFabrice Gasnier p->otg_caps.otg_rev = 0x200;
257d58ba480SAmelie Delaunay p->activate_stm_id_vb_detection = !device_property_read_bool(hsotg->dev, "usb-role-switch");
258a415083aSAmelie Delaunay p->host_rx_fifo_size = 440;
259a415083aSAmelie Delaunay p->host_nperio_tx_fifo_size = 256;
260a415083aSAmelie Delaunay p->host_perio_tx_fifo_size = 256;
2612979ee7aSAmelie Delaunay p->ahbcfg = GAHBCFG_HBSTLEN_INCR16 << GAHBCFG_HBSTLEN_SHIFT;
262a415083aSAmelie Delaunay p->power_down = DWC2_POWER_DOWN_PARAM_NONE;
26353febc95SAmelie Delaunay p->lpm = false;
26453febc95SAmelie Delaunay p->lpm_clock_gating = false;
26553febc95SAmelie Delaunay p->besl = false;
26653febc95SAmelie Delaunay p->hird_threshold_en = false;
267a415083aSAmelie Delaunay }
268a415083aSAmelie Delaunay
269323230efSJohn Youn const struct of_device_id dwc2_of_match_table[] = {
2707de1debcSJohn Youn { .compatible = "brcm,bcm2835-usb", .data = dwc2_set_bcm_params },
2717de1debcSJohn Youn { .compatible = "hisilicon,hi6220-usb", .data = dwc2_set_his_params },
272d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,jz4775-otg", .data = dwc2_set_jz4775_params },
273d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,jz4780-otg", .data = dwc2_set_jz4775_params },
274d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,x1000-otg", .data = dwc2_set_jz4775_params },
275d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,x1600-otg", .data = dwc2_set_x1600_params },
276d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,x1700-otg", .data = dwc2_set_x1600_params },
277d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,x1830-otg", .data = dwc2_set_x1600_params },
278d712b725S周琰杰 (Zhou Yanjie) { .compatible = "ingenic,x2000-otg", .data = dwc2_set_x2000_params },
2797de1debcSJohn Youn { .compatible = "rockchip,rk3066-usb", .data = dwc2_set_rk_params },
2807de1debcSJohn Youn { .compatible = "lantiq,arx100-usb", .data = dwc2_set_ltq_params },
2817de1debcSJohn Youn { .compatible = "lantiq,xrx200-usb", .data = dwc2_set_ltq_params },
2827de1debcSJohn Youn { .compatible = "snps,dwc2" },
28335a60541SMarek Szyprowski { .compatible = "samsung,s3c6400-hsotg",
28435a60541SMarek Szyprowski .data = dwc2_set_s3c6400_params },
28555b644fdSMartin Blumenstingl { .compatible = "amlogic,meson8-usb",
28655b644fdSMartin Blumenstingl .data = dwc2_set_amlogic_params },
2877de1debcSJohn Youn { .compatible = "amlogic,meson8b-usb",
2887de1debcSJohn Youn .data = dwc2_set_amlogic_params },
2897de1debcSJohn Youn { .compatible = "amlogic,meson-gxbb-usb",
2907de1debcSJohn Youn .data = dwc2_set_amlogic_params },
291fc4e326eSNeil Armstrong { .compatible = "amlogic,meson-g12a-usb",
292fc4e326eSNeil Armstrong .data = dwc2_set_amlogic_g12a_params },
293be877fbfSDmitry Rokosov { .compatible = "amlogic,meson-a1-usb",
294be877fbfSDmitry Rokosov .data = dwc2_set_amlogic_a1_params },
2957de1debcSJohn Youn { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params },
2960abe3863SChristian Lamparter { .compatible = "apm,apm82181-dwc-otg", .data = dwc2_set_amcc_params },
297e35b1350SBruno Herrera { .compatible = "st,stm32f4x9-fsotg",
298e35b1350SBruno Herrera .data = dwc2_set_stm32f4x9_fsotg_params },
299e35b1350SBruno Herrera { .compatible = "st,stm32f4x9-hsotg" },
3001a149e35SAmelie Delaunay { .compatible = "st,stm32f7-hsotg",
3011a149e35SAmelie Delaunay .data = dwc2_set_stm32f7_hsotg_params },
302a415083aSAmelie Delaunay { .compatible = "st,stm32mp15-fsotg",
303a415083aSAmelie Delaunay .data = dwc2_set_stm32mp15_fsotg_params },
304a415083aSAmelie Delaunay { .compatible = "st,stm32mp15-hsotg",
305a415083aSAmelie Delaunay .data = dwc2_set_stm32mp15_hsotg_params },
3063d8d3504SDinh Nguyen { .compatible = "intel,socfpga-agilex-hsotg",
3073d8d3504SDinh Nguyen .data = dwc2_set_socfpga_agilex_params },
308323230efSJohn Youn {},
309323230efSJohn Youn };
310323230efSJohn Youn MODULE_DEVICE_TABLE(of, dwc2_of_match_table);
311323230efSJohn Youn
3122e5db2c0SJeremy Linton const struct acpi_device_id dwc2_acpi_match[] = {
3132e5db2c0SJeremy Linton { "BCM2848", (kernel_ulong_t)dwc2_set_bcm_params },
3142e5db2c0SJeremy Linton { },
3152e5db2c0SJeremy Linton };
3162e5db2c0SJeremy Linton MODULE_DEVICE_TABLE(acpi, dwc2_acpi_match);
3172e5db2c0SJeremy Linton
318*e16d5f14SYinbo Zhu const struct pci_device_id dwc2_pci_ids[] = {
319*e16d5f14SYinbo Zhu {
320*e16d5f14SYinbo Zhu PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
321*e16d5f14SYinbo Zhu },
322*e16d5f14SYinbo Zhu {
323*e16d5f14SYinbo Zhu PCI_DEVICE(PCI_VENDOR_ID_STMICRO,
324*e16d5f14SYinbo Zhu PCI_DEVICE_ID_STMICRO_USB_OTG),
325*e16d5f14SYinbo Zhu },
326*e16d5f14SYinbo Zhu {
327*e16d5f14SYinbo Zhu PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DWC2),
328*e16d5f14SYinbo Zhu .driver_data = (unsigned long)dwc2_set_loongson_params,
329*e16d5f14SYinbo Zhu },
330*e16d5f14SYinbo Zhu { /* end: all zeroes */ }
331*e16d5f14SYinbo Zhu };
332*e16d5f14SYinbo Zhu MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
333*e16d5f14SYinbo Zhu EXPORT_SYMBOL_GPL(dwc2_pci_ids);
334*e16d5f14SYinbo Zhu
dwc2_set_param_otg_cap(struct dwc2_hsotg * hsotg)335245977c9SJohn Youn static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg)
33605ee799fSJohn Youn {
337323230efSJohn Youn switch (hsotg->hw_params.op_mode) {
338323230efSJohn Youn case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
339f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.hnp_support = true;
340f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.srp_support = true;
341323230efSJohn Youn break;
342323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
343323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
344323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
345f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.hnp_support = false;
346f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.srp_support = true;
347323230efSJohn Youn break;
348323230efSJohn Youn default:
349f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.hnp_support = false;
350f5c8a6cbSFabrice Gasnier hsotg->params.otg_caps.srp_support = false;
351323230efSJohn Youn break;
352323230efSJohn Youn }
353323230efSJohn Youn }
354323230efSJohn Youn
dwc2_set_param_phy_type(struct dwc2_hsotg * hsotg)355245977c9SJohn Youn static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg)
356323230efSJohn Youn {
357245977c9SJohn Youn int val;
358245977c9SJohn Youn u32 hs_phy_type = hsotg->hw_params.hs_phy_type;
359323230efSJohn Youn
360323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_FS;
361323230efSJohn Youn if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
362323230efSJohn Youn if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
363323230efSJohn Youn hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
364323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_UTMI;
365323230efSJohn Youn else
366323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_ULPI;
367323230efSJohn Youn }
368245977c9SJohn Youn
369245977c9SJohn Youn if (dwc2_is_fs_iot(hsotg))
370245977c9SJohn Youn hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS;
371323230efSJohn Youn
372bea8e86cSJohn Youn hsotg->params.phy_type = val;
373323230efSJohn Youn }
374323230efSJohn Youn
dwc2_set_param_speed(struct dwc2_hsotg * hsotg)375245977c9SJohn Youn static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg)
376323230efSJohn Youn {
377245977c9SJohn Youn int val;
378323230efSJohn Youn
379245977c9SJohn Youn val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ?
380323230efSJohn Youn DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
381245977c9SJohn Youn
382245977c9SJohn Youn if (dwc2_is_fs_iot(hsotg))
383245977c9SJohn Youn val = DWC2_SPEED_PARAM_FULL;
384245977c9SJohn Youn
385245977c9SJohn Youn if (dwc2_is_hs_iot(hsotg))
386245977c9SJohn Youn val = DWC2_SPEED_PARAM_HIGH;
387323230efSJohn Youn
388bea8e86cSJohn Youn hsotg->params.speed = val;
389323230efSJohn Youn }
390323230efSJohn Youn
dwc2_set_param_phy_utmi_width(struct dwc2_hsotg * hsotg)391245977c9SJohn Youn static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
392323230efSJohn Youn {
393245977c9SJohn Youn int val;
394323230efSJohn Youn
395323230efSJohn Youn val = (hsotg->hw_params.utmi_phy_data_width ==
396323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
397323230efSJohn Youn
39842de8afcSJules Maselbas if (hsotg->phy) {
39942de8afcSJules Maselbas /*
40042de8afcSJules Maselbas * If using the generic PHY framework, check if the PHY bus
40142de8afcSJules Maselbas * width is 8-bit and set the phyif appropriately.
40242de8afcSJules Maselbas */
40342de8afcSJules Maselbas if (phy_get_bus_width(hsotg->phy) == 8)
40442de8afcSJules Maselbas val = 8;
40542de8afcSJules Maselbas }
40642de8afcSJules Maselbas
407bea8e86cSJohn Youn hsotg->params.phy_utmi_width = val;
408323230efSJohn Youn }
409323230efSJohn Youn
dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg * hsotg)41005ee799fSJohn Youn static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
41105ee799fSJohn Youn {
41205ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params;
413c138ecfaSSevak Arakelyan int depth_average;
414c138ecfaSSevak Arakelyan int fifo_count;
415c138ecfaSSevak Arakelyan int i;
416c138ecfaSSevak Arakelyan
417c138ecfaSSevak Arakelyan fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
41805ee799fSJohn Youn
419245977c9SJohn Youn memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
420c138ecfaSSevak Arakelyan depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg);
421c138ecfaSSevak Arakelyan for (i = 1; i <= fifo_count; i++)
422c138ecfaSSevak Arakelyan p->g_tx_fifo_size[i] = depth_average;
4239962b62fSJohn Youn }
4249962b62fSJohn Youn
dwc2_set_param_power_down(struct dwc2_hsotg * hsotg)42503ea6d6eSJohn Youn static void dwc2_set_param_power_down(struct dwc2_hsotg *hsotg)
42603ea6d6eSJohn Youn {
42703ea6d6eSJohn Youn int val;
42803ea6d6eSJohn Youn
42903ea6d6eSJohn Youn if (hsotg->hw_params.hibernation)
43007d9878fSJisheng Zhang val = DWC2_POWER_DOWN_PARAM_HIBERNATION;
43103ea6d6eSJohn Youn else if (hsotg->hw_params.power_optimized)
43207d9878fSJisheng Zhang val = DWC2_POWER_DOWN_PARAM_PARTIAL;
43303ea6d6eSJohn Youn else
43407d9878fSJisheng Zhang val = DWC2_POWER_DOWN_PARAM_NONE;
43503ea6d6eSJohn Youn
43603ea6d6eSJohn Youn hsotg->params.power_down = val;
43703ea6d6eSJohn Youn }
43803ea6d6eSJohn Youn
dwc2_set_param_lpm(struct dwc2_hsotg * hsotg)43928b5c129SMinas Harutyunyan static void dwc2_set_param_lpm(struct dwc2_hsotg *hsotg)
44028b5c129SMinas Harutyunyan {
44128b5c129SMinas Harutyunyan struct dwc2_core_params *p = &hsotg->params;
44228b5c129SMinas Harutyunyan
44328b5c129SMinas Harutyunyan p->lpm = hsotg->hw_params.lpm_mode;
44428b5c129SMinas Harutyunyan if (p->lpm) {
44528b5c129SMinas Harutyunyan p->lpm_clock_gating = true;
44628b5c129SMinas Harutyunyan p->besl = true;
44728b5c129SMinas Harutyunyan p->hird_threshold_en = true;
44828b5c129SMinas Harutyunyan p->hird_threshold = 4;
44928b5c129SMinas Harutyunyan } else {
45028b5c129SMinas Harutyunyan p->lpm_clock_gating = false;
45128b5c129SMinas Harutyunyan p->besl = false;
45228b5c129SMinas Harutyunyan p->hird_threshold_en = false;
45328b5c129SMinas Harutyunyan }
45428b5c129SMinas Harutyunyan }
45528b5c129SMinas Harutyunyan
45605ee799fSJohn Youn /**
457245977c9SJohn Youn * dwc2_set_default_params() - Set all core parameters to their
458245977c9SJohn Youn * auto-detected default values.
4596fb914d7SGrigor Tovmasyan *
4606fb914d7SGrigor Tovmasyan * @hsotg: Programming view of the DWC_otg controller
4616fb914d7SGrigor Tovmasyan *
462323230efSJohn Youn */
dwc2_set_default_params(struct dwc2_hsotg * hsotg)463245977c9SJohn Youn static void dwc2_set_default_params(struct dwc2_hsotg *hsotg)
464323230efSJohn Youn {
46505ee799fSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params;
46605ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params;
4676b66ce51SJohn Youn bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
468323230efSJohn Youn
469245977c9SJohn Youn dwc2_set_param_otg_cap(hsotg);
470245977c9SJohn Youn dwc2_set_param_phy_type(hsotg);
471245977c9SJohn Youn dwc2_set_param_speed(hsotg);
472245977c9SJohn Youn dwc2_set_param_phy_utmi_width(hsotg);
47303ea6d6eSJohn Youn dwc2_set_param_power_down(hsotg);
47428b5c129SMinas Harutyunyan dwc2_set_param_lpm(hsotg);
475245977c9SJohn Youn p->phy_ulpi_ddr = false;
476245977c9SJohn Youn p->phy_ulpi_ext_vbus = false;
477245977c9SJohn Youn
478245977c9SJohn Youn p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
479245977c9SJohn Youn p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
480245977c9SJohn Youn p->i2c_enable = hw->i2c_enable;
48166e77a24SRazmik Karapetyan p->acg_enable = hw->acg_enable;
482245977c9SJohn Youn p->ulpi_fs_ls = false;
483245977c9SJohn Youn p->ts_dline = false;
484245977c9SJohn Youn p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a);
485245977c9SJohn Youn p->uframe_sched = true;
486245977c9SJohn Youn p->external_id_pin_ctl = false;
487b43ebc96SGrigor Tovmasyan p->ipg_isoc_en = false;
488ca531bc2SGrigor Tovmasyan p->service_interval = false;
489245977c9SJohn Youn p->max_packet_count = hw->max_packet_count;
490245977c9SJohn Youn p->max_transfer_size = hw->max_transfer_size;
4911b52d2faSRazmik Karapetyan p->ahbcfg = GAHBCFG_HBSTLEN_INCR << GAHBCFG_HBSTLEN_SHIFT;
492f3a61e4eSGrigor Tovmasyan p->ref_clk_per = 33333;
493f3a61e4eSGrigor Tovmasyan p->sof_cnt_wkup_alert = 100;
494245977c9SJohn Youn
4956b66ce51SJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
4966b66ce51SJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) {
497245977c9SJohn Youn p->host_dma = dma_capable;
498245977c9SJohn Youn p->dma_desc_enable = false;
499245977c9SJohn Youn p->dma_desc_fs_enable = false;
500245977c9SJohn Youn p->host_support_fs_ls_low_power = false;
501245977c9SJohn Youn p->host_ls_low_power_phy_clk = false;
502245977c9SJohn Youn p->host_channels = hw->host_channels;
503245977c9SJohn Youn p->host_rx_fifo_size = hw->rx_fifo_size;
504245977c9SJohn Youn p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size;
505245977c9SJohn Youn p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size;
5066b66ce51SJohn Youn }
5076b66ce51SJohn Youn
50805ee799fSJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
50905ee799fSJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) {
510245977c9SJohn Youn p->g_dma = dma_capable;
511245977c9SJohn Youn p->g_dma_desc = hw->dma_desc_enable;
51205ee799fSJohn Youn
51305ee799fSJohn Youn /*
51405ee799fSJohn Youn * The values for g_rx_fifo_size (2048) and
51505ee799fSJohn Youn * g_np_tx_fifo_size (1024) come from the legacy s3c
51605ee799fSJohn Youn * gadget driver. These defaults have been hard-coded
51705ee799fSJohn Youn * for some time so many platforms depend on these
51805ee799fSJohn Youn * values. Leave them as defaults for now and only
51905ee799fSJohn Youn * auto-detect if the hardware does not support the
52005ee799fSJohn Youn * default.
52105ee799fSJohn Youn */
522245977c9SJohn Youn p->g_rx_fifo_size = 2048;
523245977c9SJohn Youn p->g_np_tx_fifo_size = 1024;
52405ee799fSJohn Youn dwc2_set_param_tx_fifo_sizes(hsotg);
52505ee799fSJohn Youn }
526323230efSJohn Youn }
527323230efSJohn Youn
528f9f93cbbSJohn Youn /**
529f9f93cbbSJohn Youn * dwc2_get_device_properties() - Read in device properties.
530f9f93cbbSJohn Youn *
5316fb914d7SGrigor Tovmasyan * @hsotg: Programming view of the DWC_otg controller
5326fb914d7SGrigor Tovmasyan *
533f9f93cbbSJohn Youn * Read in the device properties and adjust core parameters if needed.
534f9f93cbbSJohn Youn */
dwc2_get_device_properties(struct dwc2_hsotg * hsotg)535f9f93cbbSJohn Youn static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
536f9f93cbbSJohn Youn {
537f9f93cbbSJohn Youn struct dwc2_core_params *p = &hsotg->params;
538f9f93cbbSJohn Youn int num;
539f9f93cbbSJohn Youn
540f9f93cbbSJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
541f9f93cbbSJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) {
542f9f93cbbSJohn Youn device_property_read_u32(hsotg->dev, "g-rx-fifo-size",
543f9f93cbbSJohn Youn &p->g_rx_fifo_size);
544f9f93cbbSJohn Youn
545f9f93cbbSJohn Youn device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size",
546f9f93cbbSJohn Youn &p->g_np_tx_fifo_size);
547f9f93cbbSJohn Youn
54807e803ecSAndy Shevchenko num = device_property_count_u32(hsotg->dev, "g-tx-fifo-size");
549f9f93cbbSJohn Youn if (num > 0) {
550f9f93cbbSJohn Youn num = min(num, 15);
551f9f93cbbSJohn Youn memset(p->g_tx_fifo_size, 0,
552f9f93cbbSJohn Youn sizeof(p->g_tx_fifo_size));
553f9f93cbbSJohn Youn device_property_read_u32_array(hsotg->dev,
554f9f93cbbSJohn Youn "g-tx-fifo-size",
555f9f93cbbSJohn Youn &p->g_tx_fifo_size[1],
556f9f93cbbSJohn Youn num);
557f9f93cbbSJohn Youn }
558f5c8a6cbSFabrice Gasnier
559f5c8a6cbSFabrice Gasnier of_usb_update_otg_caps(hsotg->dev->of_node, &p->otg_caps);
560f9f93cbbSJohn Youn }
561b11633c4SDinh Nguyen
562f977caeaSRob Herring p->oc_disable = of_property_read_bool(hsotg->dev->of_node, "disable-over-current");
563f9f93cbbSJohn Youn }
564f9f93cbbSJohn Youn
dwc2_check_param_otg_cap(struct dwc2_hsotg * hsotg)565d936e666SJohn Youn static void dwc2_check_param_otg_cap(struct dwc2_hsotg *hsotg)
566d936e666SJohn Youn {
567d936e666SJohn Youn int valid = 1;
568d936e666SJohn Youn
569f5c8a6cbSFabrice Gasnier if (hsotg->params.otg_caps.hnp_support && hsotg->params.otg_caps.srp_support) {
570f5c8a6cbSFabrice Gasnier /* check HNP && SRP capable */
571d936e666SJohn Youn if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
572d936e666SJohn Youn valid = 0;
573f5c8a6cbSFabrice Gasnier } else if (!hsotg->params.otg_caps.hnp_support) {
574f5c8a6cbSFabrice Gasnier /* check SRP only capable */
575f5c8a6cbSFabrice Gasnier if (hsotg->params.otg_caps.srp_support) {
576d936e666SJohn Youn switch (hsotg->hw_params.op_mode) {
577d936e666SJohn Youn case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
578d936e666SJohn Youn case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
579d936e666SJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
580d936e666SJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
581d936e666SJohn Youn break;
582d936e666SJohn Youn default:
583d936e666SJohn Youn valid = 0;
584d936e666SJohn Youn break;
585d936e666SJohn Youn }
586f5c8a6cbSFabrice Gasnier }
587f5c8a6cbSFabrice Gasnier /* else: NO HNP && NO SRP capable: always valid */
588f5c8a6cbSFabrice Gasnier } else {
589d936e666SJohn Youn valid = 0;
590d936e666SJohn Youn }
591d936e666SJohn Youn
592d936e666SJohn Youn if (!valid)
593d936e666SJohn Youn dwc2_set_param_otg_cap(hsotg);
594d936e666SJohn Youn }
595d936e666SJohn Youn
dwc2_check_param_phy_type(struct dwc2_hsotg * hsotg)596d936e666SJohn Youn static void dwc2_check_param_phy_type(struct dwc2_hsotg *hsotg)
597d936e666SJohn Youn {
598d936e666SJohn Youn int valid = 0;
599d936e666SJohn Youn u32 hs_phy_type;
600d936e666SJohn Youn u32 fs_phy_type;
601d936e666SJohn Youn
602d936e666SJohn Youn hs_phy_type = hsotg->hw_params.hs_phy_type;
603d936e666SJohn Youn fs_phy_type = hsotg->hw_params.fs_phy_type;
604d936e666SJohn Youn
605d936e666SJohn Youn switch (hsotg->params.phy_type) {
606d936e666SJohn Youn case DWC2_PHY_TYPE_PARAM_FS:
607d936e666SJohn Youn if (fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
608d936e666SJohn Youn valid = 1;
609d936e666SJohn Youn break;
610d936e666SJohn Youn case DWC2_PHY_TYPE_PARAM_UTMI:
611d936e666SJohn Youn if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
612d936e666SJohn Youn (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
613d936e666SJohn Youn valid = 1;
614d936e666SJohn Youn break;
615d936e666SJohn Youn case DWC2_PHY_TYPE_PARAM_ULPI:
616d936e666SJohn Youn if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI) ||
617d936e666SJohn Youn (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
618d936e666SJohn Youn valid = 1;
619d936e666SJohn Youn break;
620d936e666SJohn Youn default:
621d936e666SJohn Youn break;
622d936e666SJohn Youn }
623d936e666SJohn Youn
624d936e666SJohn Youn if (!valid)
625d936e666SJohn Youn dwc2_set_param_phy_type(hsotg);
626d936e666SJohn Youn }
627d936e666SJohn Youn
dwc2_check_param_speed(struct dwc2_hsotg * hsotg)628d936e666SJohn Youn static void dwc2_check_param_speed(struct dwc2_hsotg *hsotg)
629d936e666SJohn Youn {
630d936e666SJohn Youn int valid = 1;
631d936e666SJohn Youn int phy_type = hsotg->params.phy_type;
632d936e666SJohn Youn int speed = hsotg->params.speed;
633d936e666SJohn Youn
634d936e666SJohn Youn switch (speed) {
635d936e666SJohn Youn case DWC2_SPEED_PARAM_HIGH:
636d936e666SJohn Youn if ((hsotg->params.speed == DWC2_SPEED_PARAM_HIGH) &&
637d936e666SJohn Youn (phy_type == DWC2_PHY_TYPE_PARAM_FS))
638d936e666SJohn Youn valid = 0;
639d936e666SJohn Youn break;
640d936e666SJohn Youn case DWC2_SPEED_PARAM_FULL:
641d936e666SJohn Youn case DWC2_SPEED_PARAM_LOW:
642d936e666SJohn Youn break;
643d936e666SJohn Youn default:
644d936e666SJohn Youn valid = 0;
645d936e666SJohn Youn break;
646d936e666SJohn Youn }
647d936e666SJohn Youn
648d936e666SJohn Youn if (!valid)
649d936e666SJohn Youn dwc2_set_param_speed(hsotg);
650d936e666SJohn Youn }
651d936e666SJohn Youn
dwc2_check_param_phy_utmi_width(struct dwc2_hsotg * hsotg)652d936e666SJohn Youn static void dwc2_check_param_phy_utmi_width(struct dwc2_hsotg *hsotg)
653d936e666SJohn Youn {
654d936e666SJohn Youn int valid = 0;
655d936e666SJohn Youn int param = hsotg->params.phy_utmi_width;
656d936e666SJohn Youn int width = hsotg->hw_params.utmi_phy_data_width;
657d936e666SJohn Youn
658d936e666SJohn Youn switch (width) {
659d936e666SJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
660d936e666SJohn Youn valid = (param == 8);
661d936e666SJohn Youn break;
662d936e666SJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
663d936e666SJohn Youn valid = (param == 16);
664d936e666SJohn Youn break;
665d936e666SJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
666d936e666SJohn Youn valid = (param == 8 || param == 16);
667d936e666SJohn Youn break;
668d936e666SJohn Youn }
669d936e666SJohn Youn
670d936e666SJohn Youn if (!valid)
671d936e666SJohn Youn dwc2_set_param_phy_utmi_width(hsotg);
672d936e666SJohn Youn }
673d936e666SJohn Youn
dwc2_check_param_power_down(struct dwc2_hsotg * hsotg)674631a2310SVardan Mikayelyan static void dwc2_check_param_power_down(struct dwc2_hsotg *hsotg)
675631a2310SVardan Mikayelyan {
676631a2310SVardan Mikayelyan int param = hsotg->params.power_down;
677631a2310SVardan Mikayelyan
678631a2310SVardan Mikayelyan switch (param) {
679631a2310SVardan Mikayelyan case DWC2_POWER_DOWN_PARAM_NONE:
680631a2310SVardan Mikayelyan break;
681631a2310SVardan Mikayelyan case DWC2_POWER_DOWN_PARAM_PARTIAL:
682631a2310SVardan Mikayelyan if (hsotg->hw_params.power_optimized)
683631a2310SVardan Mikayelyan break;
684631a2310SVardan Mikayelyan dev_dbg(hsotg->dev,
685631a2310SVardan Mikayelyan "Partial power down isn't supported by HW\n");
686631a2310SVardan Mikayelyan param = DWC2_POWER_DOWN_PARAM_NONE;
687631a2310SVardan Mikayelyan break;
688631a2310SVardan Mikayelyan case DWC2_POWER_DOWN_PARAM_HIBERNATION:
689631a2310SVardan Mikayelyan if (hsotg->hw_params.hibernation)
690631a2310SVardan Mikayelyan break;
691631a2310SVardan Mikayelyan dev_dbg(hsotg->dev,
692631a2310SVardan Mikayelyan "Hibernation isn't supported by HW\n");
693631a2310SVardan Mikayelyan param = DWC2_POWER_DOWN_PARAM_NONE;
694631a2310SVardan Mikayelyan break;
695631a2310SVardan Mikayelyan default:
696631a2310SVardan Mikayelyan dev_err(hsotg->dev,
697631a2310SVardan Mikayelyan "%s: Invalid parameter power_down=%d\n",
698631a2310SVardan Mikayelyan __func__, param);
699631a2310SVardan Mikayelyan param = DWC2_POWER_DOWN_PARAM_NONE;
700631a2310SVardan Mikayelyan break;
701631a2310SVardan Mikayelyan }
702631a2310SVardan Mikayelyan
703631a2310SVardan Mikayelyan hsotg->params.power_down = param;
704631a2310SVardan Mikayelyan }
705631a2310SVardan Mikayelyan
dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg * hsotg)7063c6aea73SSevak Arakelyan static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
7073c6aea73SSevak Arakelyan {
7083c6aea73SSevak Arakelyan int fifo_count;
7093c6aea73SSevak Arakelyan int fifo;
7103c6aea73SSevak Arakelyan int min;
7113c6aea73SSevak Arakelyan u32 total = 0;
7123c6aea73SSevak Arakelyan u32 dptxfszn;
7133c6aea73SSevak Arakelyan
7143c6aea73SSevak Arakelyan fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
7153c6aea73SSevak Arakelyan min = hsotg->hw_params.en_multiple_tx_fifo ? 16 : 4;
7163c6aea73SSevak Arakelyan
7173c6aea73SSevak Arakelyan for (fifo = 1; fifo <= fifo_count; fifo++)
7183c6aea73SSevak Arakelyan total += hsotg->params.g_tx_fifo_size[fifo];
7193c6aea73SSevak Arakelyan
7203c6aea73SSevak Arakelyan if (total > dwc2_hsotg_tx_fifo_total_depth(hsotg) || !total) {
7213c6aea73SSevak Arakelyan dev_warn(hsotg->dev, "%s: Invalid parameter g-tx-fifo-size, setting to default average\n",
7223c6aea73SSevak Arakelyan __func__);
7233c6aea73SSevak Arakelyan dwc2_set_param_tx_fifo_sizes(hsotg);
7243c6aea73SSevak Arakelyan }
7253c6aea73SSevak Arakelyan
7263c6aea73SSevak Arakelyan for (fifo = 1; fifo <= fifo_count; fifo++) {
7279273083aSMinas Harutyunyan dptxfszn = hsotg->hw_params.g_tx_fifo_size[fifo];
7283c6aea73SSevak Arakelyan
7293c6aea73SSevak Arakelyan if (hsotg->params.g_tx_fifo_size[fifo] < min ||
7303c6aea73SSevak Arakelyan hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) {
7313c6aea73SSevak Arakelyan dev_warn(hsotg->dev, "%s: Invalid parameter g_tx_fifo_size[%d]=%d\n",
7323c6aea73SSevak Arakelyan __func__, fifo,
7333c6aea73SSevak Arakelyan hsotg->params.g_tx_fifo_size[fifo]);
7343c6aea73SSevak Arakelyan hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
7353c6aea73SSevak Arakelyan }
7363c6aea73SSevak Arakelyan }
7373c6aea73SSevak Arakelyan }
7383c6aea73SSevak Arakelyan
739d936e666SJohn Youn #define CHECK_RANGE(_param, _min, _max, _def) do { \
74047265c06SGrigor Tovmasyan if ((int)(hsotg->params._param) < (_min) || \
741d936e666SJohn Youn (hsotg->params._param) > (_max)) { \
742d936e666SJohn Youn dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
743d936e666SJohn Youn __func__, #_param, hsotg->params._param); \
744d936e666SJohn Youn hsotg->params._param = (_def); \
745d936e666SJohn Youn } \
746d936e666SJohn Youn } while (0)
747d936e666SJohn Youn
748d936e666SJohn Youn #define CHECK_BOOL(_param, _check) do { \
749d936e666SJohn Youn if (hsotg->params._param && !(_check)) { \
750d936e666SJohn Youn dev_warn(hsotg->dev, "%s: Invalid parameter %s=%d\n", \
751d936e666SJohn Youn __func__, #_param, hsotg->params._param); \
752d936e666SJohn Youn hsotg->params._param = false; \
753d936e666SJohn Youn } \
754d936e666SJohn Youn } while (0)
755d936e666SJohn Youn
dwc2_check_params(struct dwc2_hsotg * hsotg)756d936e666SJohn Youn static void dwc2_check_params(struct dwc2_hsotg *hsotg)
757d936e666SJohn Youn {
758d936e666SJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params;
759d936e666SJohn Youn struct dwc2_core_params *p = &hsotg->params;
760d936e666SJohn Youn bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
761d936e666SJohn Youn
762d936e666SJohn Youn dwc2_check_param_otg_cap(hsotg);
763d936e666SJohn Youn dwc2_check_param_phy_type(hsotg);
764d936e666SJohn Youn dwc2_check_param_speed(hsotg);
765d936e666SJohn Youn dwc2_check_param_phy_utmi_width(hsotg);
766631a2310SVardan Mikayelyan dwc2_check_param_power_down(hsotg);
767d936e666SJohn Youn CHECK_BOOL(enable_dynamic_fifo, hw->enable_dynamic_fifo);
768d936e666SJohn Youn CHECK_BOOL(en_multiple_tx_fifo, hw->en_multiple_tx_fifo);
769d936e666SJohn Youn CHECK_BOOL(i2c_enable, hw->i2c_enable);
770b43ebc96SGrigor Tovmasyan CHECK_BOOL(ipg_isoc_en, hw->ipg_isoc_en);
77166e77a24SRazmik Karapetyan CHECK_BOOL(acg_enable, hw->acg_enable);
772d936e666SJohn Youn CHECK_BOOL(reload_ctl, (hsotg->hw_params.snpsid > DWC2_CORE_REV_2_92a));
7736f80b6deSSevak Arakelyan CHECK_BOOL(lpm, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_80a));
7746f80b6deSSevak Arakelyan CHECK_BOOL(lpm, hw->lpm_mode);
7756f80b6deSSevak Arakelyan CHECK_BOOL(lpm_clock_gating, hsotg->params.lpm);
7766f80b6deSSevak Arakelyan CHECK_BOOL(besl, hsotg->params.lpm);
7776f80b6deSSevak Arakelyan CHECK_BOOL(besl, (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a));
7786f80b6deSSevak Arakelyan CHECK_BOOL(hird_threshold_en, hsotg->params.lpm);
7796f80b6deSSevak Arakelyan CHECK_RANGE(hird_threshold, 0, hsotg->params.besl ? 12 : 7, 0);
780ca531bc2SGrigor Tovmasyan CHECK_BOOL(service_interval, hw->service_interval_mode);
781d936e666SJohn Youn CHECK_RANGE(max_packet_count,
782d936e666SJohn Youn 15, hw->max_packet_count,
783d936e666SJohn Youn hw->max_packet_count);
784d936e666SJohn Youn CHECK_RANGE(max_transfer_size,
785d936e666SJohn Youn 2047, hw->max_transfer_size,
786d936e666SJohn Youn hw->max_transfer_size);
787d936e666SJohn Youn
788d936e666SJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
789d936e666SJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) {
790d936e666SJohn Youn CHECK_BOOL(host_dma, dma_capable);
791d936e666SJohn Youn CHECK_BOOL(dma_desc_enable, p->host_dma);
792d936e666SJohn Youn CHECK_BOOL(dma_desc_fs_enable, p->dma_desc_enable);
793d936e666SJohn Youn CHECK_BOOL(host_ls_low_power_phy_clk,
794d936e666SJohn Youn p->phy_type == DWC2_PHY_TYPE_PARAM_FS);
795d936e666SJohn Youn CHECK_RANGE(host_channels,
796d936e666SJohn Youn 1, hw->host_channels,
797d936e666SJohn Youn hw->host_channels);
798d936e666SJohn Youn CHECK_RANGE(host_rx_fifo_size,
799d936e666SJohn Youn 16, hw->rx_fifo_size,
800d936e666SJohn Youn hw->rx_fifo_size);
801d936e666SJohn Youn CHECK_RANGE(host_nperio_tx_fifo_size,
802d936e666SJohn Youn 16, hw->host_nperio_tx_fifo_size,
803d936e666SJohn Youn hw->host_nperio_tx_fifo_size);
804d936e666SJohn Youn CHECK_RANGE(host_perio_tx_fifo_size,
805d936e666SJohn Youn 16, hw->host_perio_tx_fifo_size,
806d936e666SJohn Youn hw->host_perio_tx_fifo_size);
807d936e666SJohn Youn }
808d936e666SJohn Youn
809d936e666SJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) ||
810d936e666SJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) {
811d936e666SJohn Youn CHECK_BOOL(g_dma, dma_capable);
812d936e666SJohn Youn CHECK_BOOL(g_dma_desc, (p->g_dma && hw->dma_desc_enable));
813d936e666SJohn Youn CHECK_RANGE(g_rx_fifo_size,
814d936e666SJohn Youn 16, hw->rx_fifo_size,
815d936e666SJohn Youn hw->rx_fifo_size);
816d936e666SJohn Youn CHECK_RANGE(g_np_tx_fifo_size,
817d936e666SJohn Youn 16, hw->dev_nperio_tx_fifo_size,
818d936e666SJohn Youn hw->dev_nperio_tx_fifo_size);
8193c6aea73SSevak Arakelyan dwc2_check_param_tx_fifo_sizes(hsotg);
820d936e666SJohn Youn }
821d936e666SJohn Youn }
822d936e666SJohn Youn
823323230efSJohn Youn /*
824323230efSJohn Youn * Gets host hardware parameters. Forces host mode if not currently in
825323230efSJohn Youn * host mode. Should be called immediately after a core soft reset in
826323230efSJohn Youn * order to get the reset values.
827323230efSJohn Youn */
dwc2_get_host_hwparams(struct dwc2_hsotg * hsotg)828323230efSJohn Youn static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg)
829323230efSJohn Youn {
830323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params;
831323230efSJohn Youn u32 gnptxfsiz;
832323230efSJohn Youn u32 hptxfsiz;
833323230efSJohn Youn
834323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)
835323230efSJohn Youn return;
836323230efSJohn Youn
83713b1f8e2SVardan Mikayelyan dwc2_force_mode(hsotg, true);
838323230efSJohn Youn
839f25c42b8SGevorg Sahakyan gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ);
840f25c42b8SGevorg Sahakyan hptxfsiz = dwc2_readl(hsotg, HPTXFSIZ);
841323230efSJohn Youn
842323230efSJohn Youn hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
843323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT;
844323230efSJohn Youn hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
845323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT;
846323230efSJohn Youn }
847323230efSJohn Youn
848323230efSJohn Youn /*
849323230efSJohn Youn * Gets device hardware parameters. Forces device mode if not
850323230efSJohn Youn * currently in device mode. Should be called immediately after a core
851323230efSJohn Youn * soft reset in order to get the reset values.
852323230efSJohn Youn */
dwc2_get_dev_hwparams(struct dwc2_hsotg * hsotg)853323230efSJohn Youn static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
854323230efSJohn Youn {
855323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params;
856323230efSJohn Youn u32 gnptxfsiz;
8579273083aSMinas Harutyunyan int fifo, fifo_count;
858323230efSJohn Youn
859323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_HOST)
860323230efSJohn Youn return;
861323230efSJohn Youn
86213b1f8e2SVardan Mikayelyan dwc2_force_mode(hsotg, false);
863323230efSJohn Youn
864f25c42b8SGevorg Sahakyan gnptxfsiz = dwc2_readl(hsotg, GNPTXFSIZ);
865323230efSJohn Youn
8669273083aSMinas Harutyunyan fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
8679273083aSMinas Harutyunyan
8689273083aSMinas Harutyunyan for (fifo = 1; fifo <= fifo_count; fifo++) {
8699273083aSMinas Harutyunyan hw->g_tx_fifo_size[fifo] =
870f25c42b8SGevorg Sahakyan (dwc2_readl(hsotg, DPTXFSIZN(fifo)) &
8719273083aSMinas Harutyunyan FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
8729273083aSMinas Harutyunyan }
8739273083aSMinas Harutyunyan
874323230efSJohn Youn hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
875323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT;
876323230efSJohn Youn }
877323230efSJohn Youn
878323230efSJohn Youn /**
879bd37fbd5SLee Jones * dwc2_get_hwparams() - During device initialization, read various hardware
880bd37fbd5SLee Jones * configuration registers and interpret the contents.
8816fb914d7SGrigor Tovmasyan *
8826fb914d7SGrigor Tovmasyan * @hsotg: Programming view of the DWC_otg controller
8836fb914d7SGrigor Tovmasyan *
884323230efSJohn Youn */
dwc2_get_hwparams(struct dwc2_hsotg * hsotg)885323230efSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
886323230efSJohn Youn {
887323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params;
888323230efSJohn Youn unsigned int width;
889323230efSJohn Youn u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
890323230efSJohn Youn u32 grxfsiz;
891323230efSJohn Youn
892f25c42b8SGevorg Sahakyan hwcfg1 = dwc2_readl(hsotg, GHWCFG1);
893f25c42b8SGevorg Sahakyan hwcfg2 = dwc2_readl(hsotg, GHWCFG2);
894f25c42b8SGevorg Sahakyan hwcfg3 = dwc2_readl(hsotg, GHWCFG3);
895f25c42b8SGevorg Sahakyan hwcfg4 = dwc2_readl(hsotg, GHWCFG4);
896f25c42b8SGevorg Sahakyan grxfsiz = dwc2_readl(hsotg, GRXFSIZ);
897323230efSJohn Youn
898323230efSJohn Youn /* hwcfg1 */
899323230efSJohn Youn hw->dev_ep_dirs = hwcfg1;
900323230efSJohn Youn
901323230efSJohn Youn /* hwcfg2 */
902323230efSJohn Youn hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
903323230efSJohn Youn GHWCFG2_OP_MODE_SHIFT;
904323230efSJohn Youn hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
905323230efSJohn Youn GHWCFG2_ARCHITECTURE_SHIFT;
906323230efSJohn Youn hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
907323230efSJohn Youn hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
908323230efSJohn Youn GHWCFG2_NUM_HOST_CHAN_SHIFT);
909323230efSJohn Youn hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
910323230efSJohn Youn GHWCFG2_HS_PHY_TYPE_SHIFT;
911323230efSJohn Youn hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
912323230efSJohn Youn GHWCFG2_FS_PHY_TYPE_SHIFT;
913323230efSJohn Youn hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
914323230efSJohn Youn GHWCFG2_NUM_DEV_EP_SHIFT;
915323230efSJohn Youn hw->nperio_tx_q_depth =
916323230efSJohn Youn (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
917323230efSJohn Youn GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
918323230efSJohn Youn hw->host_perio_tx_q_depth =
919323230efSJohn Youn (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
920323230efSJohn Youn GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
921323230efSJohn Youn hw->dev_token_q_depth =
922323230efSJohn Youn (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
923323230efSJohn Youn GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
924323230efSJohn Youn
925323230efSJohn Youn /* hwcfg3 */
926323230efSJohn Youn width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
927323230efSJohn Youn GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
928323230efSJohn Youn hw->max_transfer_size = (1 << (width + 11)) - 1;
929323230efSJohn Youn width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
930323230efSJohn Youn GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
931323230efSJohn Youn hw->max_packet_count = (1 << (width + 4)) - 1;
932323230efSJohn Youn hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
933323230efSJohn Youn hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
934323230efSJohn Youn GHWCFG3_DFIFO_DEPTH_SHIFT;
9356f80b6deSSevak Arakelyan hw->lpm_mode = !!(hwcfg3 & GHWCFG3_OTG_LPM_EN);
936323230efSJohn Youn
937323230efSJohn Youn /* hwcfg4 */
938323230efSJohn Youn hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
939323230efSJohn Youn hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
940323230efSJohn Youn GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
9419273083aSMinas Harutyunyan hw->num_dev_in_eps = (hwcfg4 & GHWCFG4_NUM_IN_EPS_MASK) >>
9429273083aSMinas Harutyunyan GHWCFG4_NUM_IN_EPS_SHIFT;
943323230efSJohn Youn hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
944323230efSJohn Youn hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
945631a2310SVardan Mikayelyan hw->hibernation = !!(hwcfg4 & GHWCFG4_HIBER);
946323230efSJohn Youn hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
947323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
94866e77a24SRazmik Karapetyan hw->acg_enable = !!(hwcfg4 & GHWCFG4_ACG_SUPPORTED);
949b43ebc96SGrigor Tovmasyan hw->ipg_isoc_en = !!(hwcfg4 & GHWCFG4_IPG_ISOC_SUPPORTED);
950ca531bc2SGrigor Tovmasyan hw->service_interval_mode = !!(hwcfg4 &
951ca531bc2SGrigor Tovmasyan GHWCFG4_SERVICE_INTERVAL_SUPPORTED);
952323230efSJohn Youn
953323230efSJohn Youn /* fifo sizes */
954d1531319SJohn Youn hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
955323230efSJohn Youn GRXFSIZ_DEPTH_SHIFT;
9569273083aSMinas Harutyunyan /*
9579273083aSMinas Harutyunyan * Host specific hardware parameters. Reading these parameters
9589273083aSMinas Harutyunyan * requires the controller to be in host mode. The mode will
9599273083aSMinas Harutyunyan * be forced, if necessary, to read these values.
9609273083aSMinas Harutyunyan */
9619273083aSMinas Harutyunyan dwc2_get_host_hwparams(hsotg);
9629273083aSMinas Harutyunyan dwc2_get_dev_hwparams(hsotg);
963323230efSJohn Youn
964323230efSJohn Youn return 0;
965323230efSJohn Youn }
966323230efSJohn Youn
9672e5db2c0SJeremy Linton typedef void (*set_params_cb)(struct dwc2_hsotg *data);
9682e5db2c0SJeremy Linton
dwc2_init_params(struct dwc2_hsotg * hsotg)969334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg)
970334bbd4eSJohn Youn {
9717de1debcSJohn Youn const struct of_device_id *match;
9722e5db2c0SJeremy Linton set_params_cb set_params;
9737de1debcSJohn Youn
974245977c9SJohn Youn dwc2_set_default_params(hsotg);
975f9f93cbbSJohn Youn dwc2_get_device_properties(hsotg);
976334bbd4eSJohn Youn
9777de1debcSJohn Youn match = of_match_device(dwc2_of_match_table, hsotg->dev);
9787de1debcSJohn Youn if (match && match->data) {
9797de1debcSJohn Youn set_params = match->data;
9807de1debcSJohn Youn set_params(hsotg);
981*e16d5f14SYinbo Zhu } else if (!match) {
9822e5db2c0SJeremy Linton const struct acpi_device_id *amatch;
983*e16d5f14SYinbo Zhu const struct pci_device_id *pmatch = NULL;
9842e5db2c0SJeremy Linton
9852e5db2c0SJeremy Linton amatch = acpi_match_device(dwc2_acpi_match, hsotg->dev);
9862e5db2c0SJeremy Linton if (amatch && amatch->driver_data) {
9872e5db2c0SJeremy Linton set_params = (set_params_cb)amatch->driver_data;
9882e5db2c0SJeremy Linton set_params(hsotg);
989*e16d5f14SYinbo Zhu } else if (!amatch)
990*e16d5f14SYinbo Zhu pmatch = pci_match_id(dwc2_pci_ids, to_pci_dev(hsotg->dev->parent));
991*e16d5f14SYinbo Zhu
992*e16d5f14SYinbo Zhu if (pmatch && pmatch->driver_data) {
993*e16d5f14SYinbo Zhu set_params = (set_params_cb)pmatch->driver_data;
994*e16d5f14SYinbo Zhu set_params(hsotg);
9952e5db2c0SJeremy Linton }
9967de1debcSJohn Youn }
9977de1debcSJohn Youn
998d936e666SJohn Youn dwc2_check_params(hsotg);
999d936e666SJohn Youn
1000334bbd4eSJohn Youn return 0;
1001334bbd4eSJohn Youn }
1002