1323230efSJohn Youn /* 2323230efSJohn Youn * Copyright (C) 2004-2016 Synopsys, Inc. 3323230efSJohn Youn * 4323230efSJohn Youn * Redistribution and use in source and binary forms, with or without 5323230efSJohn Youn * modification, are permitted provided that the following conditions 6323230efSJohn Youn * are met: 7323230efSJohn Youn * 1. Redistributions of source code must retain the above copyright 8323230efSJohn Youn * notice, this list of conditions, and the following disclaimer, 9323230efSJohn Youn * without modification. 10323230efSJohn Youn * 2. Redistributions in binary form must reproduce the above copyright 11323230efSJohn Youn * notice, this list of conditions and the following disclaimer in the 12323230efSJohn Youn * documentation and/or other materials provided with the distribution. 13323230efSJohn Youn * 3. The names of the above-listed copyright holders may not be used 14323230efSJohn Youn * to endorse or promote products derived from this software without 15323230efSJohn Youn * specific prior written permission. 16323230efSJohn Youn * 17323230efSJohn Youn * ALTERNATIVELY, this software may be distributed under the terms of the 18323230efSJohn Youn * GNU General Public License ("GPL") as published by the Free Software 19323230efSJohn Youn * Foundation; either version 2 of the License, or (at your option) any 20323230efSJohn Youn * later version. 21323230efSJohn Youn * 22323230efSJohn Youn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23323230efSJohn Youn * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24323230efSJohn Youn * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25323230efSJohn Youn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 26323230efSJohn Youn * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27323230efSJohn Youn * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28323230efSJohn Youn * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29323230efSJohn Youn * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30323230efSJohn Youn * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31323230efSJohn Youn * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32323230efSJohn Youn * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33323230efSJohn Youn */ 34323230efSJohn Youn 35323230efSJohn Youn #include <linux/kernel.h> 36323230efSJohn Youn #include <linux/module.h> 37323230efSJohn Youn #include <linux/of_device.h> 38323230efSJohn Youn 39323230efSJohn Youn #include "core.h" 40323230efSJohn Youn 41323230efSJohn Youn static const struct dwc2_core_params params_hi6220 = { 42323230efSJohn Youn .otg_cap = 2, /* No HNP/SRP capable */ 43323230efSJohn Youn .otg_ver = 0, /* 1.3 */ 44323230efSJohn Youn .dma_desc_enable = 0, 45323230efSJohn Youn .dma_desc_fs_enable = 0, 46323230efSJohn Youn .speed = 0, /* High Speed */ 47323230efSJohn Youn .enable_dynamic_fifo = 1, 48323230efSJohn Youn .en_multiple_tx_fifo = 1, 49323230efSJohn Youn .host_rx_fifo_size = 512, 50323230efSJohn Youn .host_nperio_tx_fifo_size = 512, 51323230efSJohn Youn .host_perio_tx_fifo_size = 512, 52323230efSJohn Youn .max_transfer_size = 65535, 53323230efSJohn Youn .max_packet_count = 511, 54323230efSJohn Youn .host_channels = 16, 55323230efSJohn Youn .phy_type = 1, /* UTMI */ 56323230efSJohn Youn .phy_utmi_width = 8, 57323230efSJohn Youn .phy_ulpi_ddr = 0, /* Single */ 58323230efSJohn Youn .phy_ulpi_ext_vbus = 0, 59323230efSJohn Youn .i2c_enable = 0, 60323230efSJohn Youn .ulpi_fs_ls = 0, 61323230efSJohn Youn .host_support_fs_ls_low_power = 0, 62323230efSJohn Youn .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 63323230efSJohn Youn .ts_dline = 0, 64323230efSJohn Youn .reload_ctl = 0, 65323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 66323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 67323230efSJohn Youn .uframe_sched = 0, 68323230efSJohn Youn .external_id_pin_ctl = -1, 69323230efSJohn Youn .hibernation = -1, 70323230efSJohn Youn }; 71323230efSJohn Youn 72323230efSJohn Youn static const struct dwc2_core_params params_bcm2835 = { 73323230efSJohn Youn .otg_cap = 0, /* HNP/SRP capable */ 74323230efSJohn Youn .otg_ver = 0, /* 1.3 */ 75323230efSJohn Youn .dma_desc_enable = 0, 76323230efSJohn Youn .dma_desc_fs_enable = 0, 77323230efSJohn Youn .speed = 0, /* High Speed */ 78323230efSJohn Youn .enable_dynamic_fifo = 1, 79323230efSJohn Youn .en_multiple_tx_fifo = 1, 80323230efSJohn Youn .host_rx_fifo_size = 774, /* 774 DWORDs */ 81323230efSJohn Youn .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */ 82323230efSJohn Youn .host_perio_tx_fifo_size = 512, /* 512 DWORDs */ 83323230efSJohn Youn .max_transfer_size = 65535, 84323230efSJohn Youn .max_packet_count = 511, 85323230efSJohn Youn .host_channels = 8, 86323230efSJohn Youn .phy_type = 1, /* UTMI */ 87323230efSJohn Youn .phy_utmi_width = 8, /* 8 bits */ 88323230efSJohn Youn .phy_ulpi_ddr = 0, /* Single */ 89323230efSJohn Youn .phy_ulpi_ext_vbus = 0, 90323230efSJohn Youn .i2c_enable = 0, 91323230efSJohn Youn .ulpi_fs_ls = 0, 92323230efSJohn Youn .host_support_fs_ls_low_power = 0, 93323230efSJohn Youn .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 94323230efSJohn Youn .ts_dline = 0, 95323230efSJohn Youn .reload_ctl = 0, 96323230efSJohn Youn .ahbcfg = 0x10, 97323230efSJohn Youn .uframe_sched = 0, 98323230efSJohn Youn .external_id_pin_ctl = -1, 99323230efSJohn Youn .hibernation = -1, 100323230efSJohn Youn }; 101323230efSJohn Youn 102323230efSJohn Youn static const struct dwc2_core_params params_rk3066 = { 103323230efSJohn Youn .otg_cap = 2, /* non-HNP/non-SRP */ 104323230efSJohn Youn .otg_ver = -1, 105323230efSJohn Youn .dma_desc_enable = 0, 106323230efSJohn Youn .dma_desc_fs_enable = 0, 107323230efSJohn Youn .speed = -1, 108323230efSJohn Youn .enable_dynamic_fifo = 1, 109323230efSJohn Youn .en_multiple_tx_fifo = -1, 110323230efSJohn Youn .host_rx_fifo_size = 525, /* 525 DWORDs */ 111323230efSJohn Youn .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ 112323230efSJohn Youn .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ 113323230efSJohn Youn .max_transfer_size = -1, 114323230efSJohn Youn .max_packet_count = -1, 115323230efSJohn Youn .host_channels = -1, 116323230efSJohn Youn .phy_type = -1, 117323230efSJohn Youn .phy_utmi_width = -1, 118323230efSJohn Youn .phy_ulpi_ddr = -1, 119323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 120323230efSJohn Youn .i2c_enable = -1, 121323230efSJohn Youn .ulpi_fs_ls = -1, 122323230efSJohn Youn .host_support_fs_ls_low_power = -1, 123323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 124323230efSJohn Youn .ts_dline = -1, 125323230efSJohn Youn .reload_ctl = -1, 126323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 127323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 128323230efSJohn Youn .uframe_sched = -1, 129323230efSJohn Youn .external_id_pin_ctl = -1, 130323230efSJohn Youn .hibernation = -1, 131323230efSJohn Youn }; 132323230efSJohn Youn 133323230efSJohn Youn static const struct dwc2_core_params params_ltq = { 134323230efSJohn Youn .otg_cap = 2, /* non-HNP/non-SRP */ 135323230efSJohn Youn .otg_ver = -1, 136323230efSJohn Youn .dma_desc_enable = -1, 137323230efSJohn Youn .dma_desc_fs_enable = -1, 138323230efSJohn Youn .speed = -1, 139323230efSJohn Youn .enable_dynamic_fifo = -1, 140323230efSJohn Youn .en_multiple_tx_fifo = -1, 141323230efSJohn Youn .host_rx_fifo_size = 288, /* 288 DWORDs */ 142323230efSJohn Youn .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ 143323230efSJohn Youn .host_perio_tx_fifo_size = 96, /* 96 DWORDs */ 144323230efSJohn Youn .max_transfer_size = 65535, 145323230efSJohn Youn .max_packet_count = 511, 146323230efSJohn Youn .host_channels = -1, 147323230efSJohn Youn .phy_type = -1, 148323230efSJohn Youn .phy_utmi_width = -1, 149323230efSJohn Youn .phy_ulpi_ddr = -1, 150323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 151323230efSJohn Youn .i2c_enable = -1, 152323230efSJohn Youn .ulpi_fs_ls = -1, 153323230efSJohn Youn .host_support_fs_ls_low_power = -1, 154323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 155323230efSJohn Youn .ts_dline = -1, 156323230efSJohn Youn .reload_ctl = -1, 157323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 158323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 159323230efSJohn Youn .uframe_sched = -1, 160323230efSJohn Youn .external_id_pin_ctl = -1, 161323230efSJohn Youn .hibernation = -1, 162323230efSJohn Youn }; 163323230efSJohn Youn 164323230efSJohn Youn static const struct dwc2_core_params params_amlogic = { 165323230efSJohn Youn .otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE, 166323230efSJohn Youn .otg_ver = -1, 167323230efSJohn Youn .dma_desc_enable = 0, 168323230efSJohn Youn .dma_desc_fs_enable = 0, 169323230efSJohn Youn .speed = DWC2_SPEED_PARAM_HIGH, 170323230efSJohn Youn .enable_dynamic_fifo = 1, 171323230efSJohn Youn .en_multiple_tx_fifo = -1, 172323230efSJohn Youn .host_rx_fifo_size = 512, 173323230efSJohn Youn .host_nperio_tx_fifo_size = 500, 174323230efSJohn Youn .host_perio_tx_fifo_size = 500, 175323230efSJohn Youn .max_transfer_size = -1, 176323230efSJohn Youn .max_packet_count = -1, 177323230efSJohn Youn .host_channels = 16, 178323230efSJohn Youn .phy_type = DWC2_PHY_TYPE_PARAM_UTMI, 179323230efSJohn Youn .phy_utmi_width = -1, 180323230efSJohn Youn .phy_ulpi_ddr = -1, 181323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 182323230efSJohn Youn .i2c_enable = -1, 183323230efSJohn Youn .ulpi_fs_ls = -1, 184323230efSJohn Youn .host_support_fs_ls_low_power = -1, 185323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 186323230efSJohn Youn .ts_dline = -1, 187323230efSJohn Youn .reload_ctl = 1, 188323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR8 << 189323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 190323230efSJohn Youn .uframe_sched = 0, 191323230efSJohn Youn .external_id_pin_ctl = -1, 192323230efSJohn Youn .hibernation = -1, 193323230efSJohn Youn }; 194323230efSJohn Youn 1950a7d0d7fSJohn Youn static const struct dwc2_core_params params_default = { 1960a7d0d7fSJohn Youn .otg_cap = -1, 1970a7d0d7fSJohn Youn .otg_ver = -1, 1980a7d0d7fSJohn Youn 1990a7d0d7fSJohn Youn /* 2000a7d0d7fSJohn Youn * Disable descriptor dma mode by default as the HW can support 2010a7d0d7fSJohn Youn * it, but does not support it for SPLIT transactions. 2020a7d0d7fSJohn Youn * Disable it for FS devices as well. 2030a7d0d7fSJohn Youn */ 2040a7d0d7fSJohn Youn .dma_desc_enable = 0, 2050a7d0d7fSJohn Youn .dma_desc_fs_enable = 0, 2060a7d0d7fSJohn Youn 2070a7d0d7fSJohn Youn .speed = -1, 2080a7d0d7fSJohn Youn .enable_dynamic_fifo = -1, 2090a7d0d7fSJohn Youn .en_multiple_tx_fifo = -1, 2100a7d0d7fSJohn Youn .host_rx_fifo_size = -1, 2110a7d0d7fSJohn Youn .host_nperio_tx_fifo_size = -1, 2120a7d0d7fSJohn Youn .host_perio_tx_fifo_size = -1, 2130a7d0d7fSJohn Youn .max_transfer_size = -1, 2140a7d0d7fSJohn Youn .max_packet_count = -1, 2150a7d0d7fSJohn Youn .host_channels = -1, 2160a7d0d7fSJohn Youn .phy_type = -1, 2170a7d0d7fSJohn Youn .phy_utmi_width = -1, 2180a7d0d7fSJohn Youn .phy_ulpi_ddr = -1, 2190a7d0d7fSJohn Youn .phy_ulpi_ext_vbus = -1, 2200a7d0d7fSJohn Youn .i2c_enable = -1, 2210a7d0d7fSJohn Youn .ulpi_fs_ls = -1, 2220a7d0d7fSJohn Youn .host_support_fs_ls_low_power = -1, 2230a7d0d7fSJohn Youn .host_ls_low_power_phy_clk = -1, 2240a7d0d7fSJohn Youn .ts_dline = -1, 2250a7d0d7fSJohn Youn .reload_ctl = -1, 2260a7d0d7fSJohn Youn .ahbcfg = -1, 2270a7d0d7fSJohn Youn .uframe_sched = -1, 2280a7d0d7fSJohn Youn .external_id_pin_ctl = -1, 2290a7d0d7fSJohn Youn .hibernation = -1, 2300a7d0d7fSJohn Youn }; 2310a7d0d7fSJohn Youn 232323230efSJohn Youn const struct of_device_id dwc2_of_match_table[] = { 233323230efSJohn Youn { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, 234323230efSJohn Youn { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 }, 235323230efSJohn Youn { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, 236323230efSJohn Youn { .compatible = "lantiq,arx100-usb", .data = ¶ms_ltq }, 237323230efSJohn Youn { .compatible = "lantiq,xrx200-usb", .data = ¶ms_ltq }, 238323230efSJohn Youn { .compatible = "snps,dwc2", .data = NULL }, 239323230efSJohn Youn { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, 240323230efSJohn Youn { .compatible = "amlogic,meson8b-usb", .data = ¶ms_amlogic }, 241323230efSJohn Youn { .compatible = "amlogic,meson-gxbb-usb", .data = ¶ms_amlogic }, 242*3922fb46SChristian Lamparter { .compatible = "amcc,dwc-otg", .data = NULL }, 243323230efSJohn Youn {}, 244323230efSJohn Youn }; 245323230efSJohn Youn MODULE_DEVICE_TABLE(of, dwc2_of_match_table); 246323230efSJohn Youn 24705ee799fSJohn Youn static void dwc2_get_device_property(struct dwc2_hsotg *hsotg, 24805ee799fSJohn Youn char *property, u8 size, u64 *value) 24905ee799fSJohn Youn { 25005ee799fSJohn Youn u8 val8; 25105ee799fSJohn Youn u16 val16; 25205ee799fSJohn Youn u32 val32; 25305ee799fSJohn Youn 25405ee799fSJohn Youn switch (size) { 25505ee799fSJohn Youn case 0: 25605ee799fSJohn Youn *value = device_property_read_bool(hsotg->dev, property); 25705ee799fSJohn Youn break; 25805ee799fSJohn Youn case 1: 25905ee799fSJohn Youn if (device_property_read_u8(hsotg->dev, property, &val8)) 26005ee799fSJohn Youn return; 26105ee799fSJohn Youn 26205ee799fSJohn Youn *value = val8; 26305ee799fSJohn Youn break; 26405ee799fSJohn Youn case 2: 26505ee799fSJohn Youn if (device_property_read_u16(hsotg->dev, property, &val16)) 26605ee799fSJohn Youn return; 26705ee799fSJohn Youn 26805ee799fSJohn Youn *value = val16; 26905ee799fSJohn Youn break; 27005ee799fSJohn Youn case 4: 27105ee799fSJohn Youn if (device_property_read_u32(hsotg->dev, property, &val32)) 27205ee799fSJohn Youn return; 27305ee799fSJohn Youn 27405ee799fSJohn Youn *value = val32; 27505ee799fSJohn Youn break; 27605ee799fSJohn Youn case 8: 27705ee799fSJohn Youn if (device_property_read_u64(hsotg->dev, property, value)) 27805ee799fSJohn Youn return; 27905ee799fSJohn Youn 28005ee799fSJohn Youn break; 28105ee799fSJohn Youn default: 28205ee799fSJohn Youn /* 28305ee799fSJohn Youn * The size is checked by the only function that calls 28405ee799fSJohn Youn * this so this should never happen. 28505ee799fSJohn Youn */ 28605ee799fSJohn Youn WARN_ON(1); 28705ee799fSJohn Youn return; 28805ee799fSJohn Youn } 28905ee799fSJohn Youn } 29005ee799fSJohn Youn 29105ee799fSJohn Youn static void dwc2_set_core_param(void *param, u8 size, u64 value) 29205ee799fSJohn Youn { 29305ee799fSJohn Youn switch (size) { 29405ee799fSJohn Youn case 0: 29505ee799fSJohn Youn *((bool *)param) = !!value; 29605ee799fSJohn Youn break; 29705ee799fSJohn Youn case 1: 29805ee799fSJohn Youn *((u8 *)param) = (u8)value; 29905ee799fSJohn Youn break; 30005ee799fSJohn Youn case 2: 30105ee799fSJohn Youn *((u16 *)param) = (u16)value; 30205ee799fSJohn Youn break; 30305ee799fSJohn Youn case 4: 30405ee799fSJohn Youn *((u32 *)param) = (u32)value; 30505ee799fSJohn Youn break; 30605ee799fSJohn Youn case 8: 30705ee799fSJohn Youn *((u64 *)param) = (u64)value; 30805ee799fSJohn Youn break; 30905ee799fSJohn Youn default: 31005ee799fSJohn Youn /* 31105ee799fSJohn Youn * The size is checked by the only function that calls 31205ee799fSJohn Youn * this so this should never happen. 31305ee799fSJohn Youn */ 31405ee799fSJohn Youn WARN_ON(1); 31505ee799fSJohn Youn return; 31605ee799fSJohn Youn } 31705ee799fSJohn Youn } 31805ee799fSJohn Youn 31905ee799fSJohn Youn /** 32005ee799fSJohn Youn * dwc2_set_param() - Set a core parameter 32105ee799fSJohn Youn * 32205ee799fSJohn Youn * @hsotg: Programming view of the DWC_otg controller 32305ee799fSJohn Youn * @param: Pointer to the parameter to set 32405ee799fSJohn Youn * @lookup: True if the property should be looked up 32505ee799fSJohn Youn * @property: The device property to read 32605ee799fSJohn Youn * @legacy: The param value to set if @property is not available. This 32705ee799fSJohn Youn * will typically be the legacy value set in the static 32805ee799fSJohn Youn * params structure. 32905ee799fSJohn Youn * @def: The default value 33005ee799fSJohn Youn * @min: The minimum value 33105ee799fSJohn Youn * @max: The maximum value 33205ee799fSJohn Youn * @size: The size of the core parameter in bytes, or 0 for bool. 33305ee799fSJohn Youn * 33405ee799fSJohn Youn * This function looks up @property and sets the @param to that value. 33505ee799fSJohn Youn * If the property doesn't exist it uses the passed-in @value. It will 33605ee799fSJohn Youn * verify that the value falls between @min and @max. If it doesn't, 33705ee799fSJohn Youn * it will output an error and set the parameter to either @def or, 33805ee799fSJohn Youn * failing that, to @min. 33905ee799fSJohn Youn * 34005ee799fSJohn Youn * The @size is used to write to @param and to query the device 34105ee799fSJohn Youn * properties so that this same function can be used with different 34205ee799fSJohn Youn * types of parameters. 34305ee799fSJohn Youn */ 34405ee799fSJohn Youn static void dwc2_set_param(struct dwc2_hsotg *hsotg, void *param, 34505ee799fSJohn Youn bool lookup, char *property, u64 legacy, 34605ee799fSJohn Youn u64 def, u64 min, u64 max, u8 size) 34705ee799fSJohn Youn { 34805ee799fSJohn Youn u64 sizemax; 34905ee799fSJohn Youn u64 value; 35005ee799fSJohn Youn 35105ee799fSJohn Youn if (WARN_ON(!hsotg || !param || !property)) 35205ee799fSJohn Youn return; 35305ee799fSJohn Youn 35405ee799fSJohn Youn if (WARN((size > 8) || ((size & (size - 1)) != 0), 35505ee799fSJohn Youn "Invalid size %d for %s\n", size, property)) 35605ee799fSJohn Youn return; 35705ee799fSJohn Youn 35805ee799fSJohn Youn dev_vdbg(hsotg->dev, "%s: Setting %s: legacy=%llu, def=%llu, min=%llu, max=%llu, size=%d\n", 35905ee799fSJohn Youn __func__, property, legacy, def, min, max, size); 36005ee799fSJohn Youn 36105ee799fSJohn Youn sizemax = (1ULL << (size * 8)) - 1; 36205ee799fSJohn Youn value = legacy; 36305ee799fSJohn Youn 36405ee799fSJohn Youn /* Override legacy settings. */ 36505ee799fSJohn Youn if (lookup) 36605ee799fSJohn Youn dwc2_get_device_property(hsotg, property, size, &value); 36705ee799fSJohn Youn 36805ee799fSJohn Youn /* 36905ee799fSJohn Youn * While the value is not valid, try setting it to the default 37005ee799fSJohn Youn * value, and failing that, set it to the minimum. 37105ee799fSJohn Youn */ 37205ee799fSJohn Youn while ((value < min) || (value > max)) { 37305ee799fSJohn Youn /* Print an error unless the value is set to auto. */ 37405ee799fSJohn Youn if (value != sizemax) 37505ee799fSJohn Youn dev_err(hsotg->dev, "Invalid value %llu for param %s\n", 37605ee799fSJohn Youn value, property); 37705ee799fSJohn Youn 37805ee799fSJohn Youn /* 37905ee799fSJohn Youn * If we are already the default, just set it to the 38005ee799fSJohn Youn * minimum. 38105ee799fSJohn Youn */ 38205ee799fSJohn Youn if (value == def) { 38305ee799fSJohn Youn dev_vdbg(hsotg->dev, "%s: setting value to min=%llu\n", 38405ee799fSJohn Youn __func__, min); 38505ee799fSJohn Youn value = min; 38605ee799fSJohn Youn break; 38705ee799fSJohn Youn } 38805ee799fSJohn Youn 38905ee799fSJohn Youn /* Try the default value */ 39005ee799fSJohn Youn dev_vdbg(hsotg->dev, "%s: setting value to default=%llu\n", 39105ee799fSJohn Youn __func__, def); 39205ee799fSJohn Youn value = def; 39305ee799fSJohn Youn } 39405ee799fSJohn Youn 39505ee799fSJohn Youn dev_dbg(hsotg->dev, "Setting %s to %llu\n", property, value); 39605ee799fSJohn Youn dwc2_set_core_param(param, size, value); 39705ee799fSJohn Youn } 39805ee799fSJohn Youn 39905ee799fSJohn Youn /** 40005ee799fSJohn Youn * dwc2_set_param_u16() - Set a u16 parameter 40105ee799fSJohn Youn * 40205ee799fSJohn Youn * See dwc2_set_param(). 40305ee799fSJohn Youn */ 40405ee799fSJohn Youn static void dwc2_set_param_u16(struct dwc2_hsotg *hsotg, u16 *param, 40505ee799fSJohn Youn bool lookup, char *property, u16 legacy, 40605ee799fSJohn Youn u16 def, u16 min, u16 max) 40705ee799fSJohn Youn { 40805ee799fSJohn Youn dwc2_set_param(hsotg, param, lookup, property, 40905ee799fSJohn Youn legacy, def, min, max, 2); 41005ee799fSJohn Youn } 41105ee799fSJohn Youn 41205ee799fSJohn Youn /** 41305ee799fSJohn Youn * dwc2_set_param_bool() - Set a bool parameter 41405ee799fSJohn Youn * 41505ee799fSJohn Youn * See dwc2_set_param(). 41605ee799fSJohn Youn * 41705ee799fSJohn Youn * Note: there is no 'legacy' argument here because there is no legacy 41805ee799fSJohn Youn * source of bool params. 41905ee799fSJohn Youn */ 42005ee799fSJohn Youn static void dwc2_set_param_bool(struct dwc2_hsotg *hsotg, bool *param, 42105ee799fSJohn Youn bool lookup, char *property, 42205ee799fSJohn Youn bool def, bool min, bool max) 42305ee799fSJohn Youn { 42405ee799fSJohn Youn dwc2_set_param(hsotg, param, lookup, property, 42505ee799fSJohn Youn def, def, min, max, 0); 42605ee799fSJohn Youn } 42705ee799fSJohn Youn 428323230efSJohn Youn #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c)) 429323230efSJohn Youn 430323230efSJohn Youn /* Parameter access functions */ 431c1d286cfSJohn Youn static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val) 432323230efSJohn Youn { 433323230efSJohn Youn int valid = 1; 434323230efSJohn Youn 435323230efSJohn Youn switch (val) { 436323230efSJohn Youn case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: 437323230efSJohn Youn if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) 438323230efSJohn Youn valid = 0; 439323230efSJohn Youn break; 440323230efSJohn Youn case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: 441323230efSJohn Youn switch (hsotg->hw_params.op_mode) { 442323230efSJohn Youn case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 443323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 444323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 445323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 446323230efSJohn Youn break; 447323230efSJohn Youn default: 448323230efSJohn Youn valid = 0; 449323230efSJohn Youn break; 450323230efSJohn Youn } 451323230efSJohn Youn break; 452323230efSJohn Youn case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: 453323230efSJohn Youn /* always valid */ 454323230efSJohn Youn break; 455323230efSJohn Youn default: 456323230efSJohn Youn valid = 0; 457323230efSJohn Youn break; 458323230efSJohn Youn } 459323230efSJohn Youn 460323230efSJohn Youn if (!valid) { 461323230efSJohn Youn if (val >= 0) 462323230efSJohn Youn dev_err(hsotg->dev, 463323230efSJohn Youn "%d invalid for otg_cap parameter. Check HW configuration.\n", 464323230efSJohn Youn val); 465323230efSJohn Youn switch (hsotg->hw_params.op_mode) { 466323230efSJohn Youn case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 467323230efSJohn Youn val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; 468323230efSJohn Youn break; 469323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 470323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 471323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 472323230efSJohn Youn val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; 473323230efSJohn Youn break; 474323230efSJohn Youn default: 475323230efSJohn Youn val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; 476323230efSJohn Youn break; 477323230efSJohn Youn } 478323230efSJohn Youn dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val); 479323230efSJohn Youn } 480323230efSJohn Youn 481bea8e86cSJohn Youn hsotg->params.otg_cap = val; 482323230efSJohn Youn } 483323230efSJohn Youn 484c1d286cfSJohn Youn static void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val) 485323230efSJohn Youn { 486323230efSJohn Youn int valid = 1; 487323230efSJohn Youn 488e7839f99SJohn Youn if (val > 0 && (hsotg->params.host_dma <= 0 || 489323230efSJohn Youn !hsotg->hw_params.dma_desc_enable)) 490323230efSJohn Youn valid = 0; 491323230efSJohn Youn if (val < 0) 492323230efSJohn Youn valid = 0; 493323230efSJohn Youn 494323230efSJohn Youn if (!valid) { 495323230efSJohn Youn if (val >= 0) 496323230efSJohn Youn dev_err(hsotg->dev, 497323230efSJohn Youn "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", 498323230efSJohn Youn val); 499e7839f99SJohn Youn val = (hsotg->params.host_dma > 0 && 500323230efSJohn Youn hsotg->hw_params.dma_desc_enable); 501323230efSJohn Youn dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); 502323230efSJohn Youn } 503323230efSJohn Youn 504bea8e86cSJohn Youn hsotg->params.dma_desc_enable = val; 505323230efSJohn Youn } 506323230efSJohn Youn 507c1d286cfSJohn Youn static void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val) 508323230efSJohn Youn { 509323230efSJohn Youn int valid = 1; 510323230efSJohn Youn 511e7839f99SJohn Youn if (val > 0 && (hsotg->params.host_dma <= 0 || 512323230efSJohn Youn !hsotg->hw_params.dma_desc_enable)) 513323230efSJohn Youn valid = 0; 514323230efSJohn Youn if (val < 0) 515323230efSJohn Youn valid = 0; 516323230efSJohn Youn 517323230efSJohn Youn if (!valid) { 518323230efSJohn Youn if (val >= 0) 519323230efSJohn Youn dev_err(hsotg->dev, 520323230efSJohn Youn "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n", 521323230efSJohn Youn val); 522e7839f99SJohn Youn val = (hsotg->params.host_dma > 0 && 523323230efSJohn Youn hsotg->hw_params.dma_desc_enable); 524323230efSJohn Youn } 525323230efSJohn Youn 526bea8e86cSJohn Youn hsotg->params.dma_desc_fs_enable = val; 527323230efSJohn Youn dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val); 528323230efSJohn Youn } 529323230efSJohn Youn 530c1d286cfSJohn Youn static void 531c1d286cfSJohn Youn dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, 532323230efSJohn Youn int val) 533323230efSJohn Youn { 534323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 535323230efSJohn Youn if (val >= 0) { 536323230efSJohn Youn dev_err(hsotg->dev, 537323230efSJohn Youn "Wrong value for host_support_fs_low_power\n"); 538323230efSJohn Youn dev_err(hsotg->dev, 539323230efSJohn Youn "host_support_fs_low_power must be 0 or 1\n"); 540323230efSJohn Youn } 541323230efSJohn Youn val = 0; 542323230efSJohn Youn dev_dbg(hsotg->dev, 543323230efSJohn Youn "Setting host_support_fs_low_power to %d\n", val); 544323230efSJohn Youn } 545323230efSJohn Youn 546bea8e86cSJohn Youn hsotg->params.host_support_fs_ls_low_power = val; 547323230efSJohn Youn } 548323230efSJohn Youn 549c1d286cfSJohn Youn static void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, 550c1d286cfSJohn Youn int val) 551323230efSJohn Youn { 552323230efSJohn Youn int valid = 1; 553323230efSJohn Youn 554323230efSJohn Youn if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo) 555323230efSJohn Youn valid = 0; 556323230efSJohn Youn if (val < 0) 557323230efSJohn Youn valid = 0; 558323230efSJohn Youn 559323230efSJohn Youn if (!valid) { 560323230efSJohn Youn if (val >= 0) 561323230efSJohn Youn dev_err(hsotg->dev, 562323230efSJohn Youn "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", 563323230efSJohn Youn val); 564323230efSJohn Youn val = hsotg->hw_params.enable_dynamic_fifo; 565323230efSJohn Youn dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); 566323230efSJohn Youn } 567323230efSJohn Youn 568bea8e86cSJohn Youn hsotg->params.enable_dynamic_fifo = val; 569323230efSJohn Youn } 570323230efSJohn Youn 571c1d286cfSJohn Youn static void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val) 572323230efSJohn Youn { 573323230efSJohn Youn int valid = 1; 574323230efSJohn Youn 575d1531319SJohn Youn if (val < 16 || val > hsotg->hw_params.rx_fifo_size) 576323230efSJohn Youn valid = 0; 577323230efSJohn Youn 578323230efSJohn Youn if (!valid) { 579323230efSJohn Youn if (val >= 0) 580323230efSJohn Youn dev_err(hsotg->dev, 581323230efSJohn Youn "%d invalid for host_rx_fifo_size. Check HW configuration.\n", 582323230efSJohn Youn val); 583d1531319SJohn Youn val = hsotg->hw_params.rx_fifo_size; 584323230efSJohn Youn dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val); 585323230efSJohn Youn } 586323230efSJohn Youn 587bea8e86cSJohn Youn hsotg->params.host_rx_fifo_size = val; 588323230efSJohn Youn } 589323230efSJohn Youn 590c1d286cfSJohn Youn static void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, 591c1d286cfSJohn Youn int val) 592323230efSJohn Youn { 593323230efSJohn Youn int valid = 1; 594323230efSJohn Youn 595323230efSJohn Youn if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size) 596323230efSJohn Youn valid = 0; 597323230efSJohn Youn 598323230efSJohn Youn if (!valid) { 599323230efSJohn Youn if (val >= 0) 600323230efSJohn Youn dev_err(hsotg->dev, 601323230efSJohn Youn "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", 602323230efSJohn Youn val); 603323230efSJohn Youn val = hsotg->hw_params.host_nperio_tx_fifo_size; 604323230efSJohn Youn dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", 605323230efSJohn Youn val); 606323230efSJohn Youn } 607323230efSJohn Youn 608bea8e86cSJohn Youn hsotg->params.host_nperio_tx_fifo_size = val; 609323230efSJohn Youn } 610323230efSJohn Youn 611c1d286cfSJohn Youn static void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, 612c1d286cfSJohn Youn int val) 613323230efSJohn Youn { 614323230efSJohn Youn int valid = 1; 615323230efSJohn Youn 616323230efSJohn Youn if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size) 617323230efSJohn Youn valid = 0; 618323230efSJohn Youn 619323230efSJohn Youn if (!valid) { 620323230efSJohn Youn if (val >= 0) 621323230efSJohn Youn dev_err(hsotg->dev, 622323230efSJohn Youn "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", 623323230efSJohn Youn val); 624323230efSJohn Youn val = hsotg->hw_params.host_perio_tx_fifo_size; 625323230efSJohn Youn dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", 626323230efSJohn Youn val); 627323230efSJohn Youn } 628323230efSJohn Youn 629bea8e86cSJohn Youn hsotg->params.host_perio_tx_fifo_size = val; 630323230efSJohn Youn } 631323230efSJohn Youn 632c1d286cfSJohn Youn static void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val) 633323230efSJohn Youn { 634323230efSJohn Youn int valid = 1; 635323230efSJohn Youn 636323230efSJohn Youn if (val < 2047 || val > hsotg->hw_params.max_transfer_size) 637323230efSJohn Youn valid = 0; 638323230efSJohn Youn 639323230efSJohn Youn if (!valid) { 640323230efSJohn Youn if (val >= 0) 641323230efSJohn Youn dev_err(hsotg->dev, 642323230efSJohn Youn "%d invalid for max_transfer_size. Check HW configuration.\n", 643323230efSJohn Youn val); 644323230efSJohn Youn val = hsotg->hw_params.max_transfer_size; 645323230efSJohn Youn dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); 646323230efSJohn Youn } 647323230efSJohn Youn 648bea8e86cSJohn Youn hsotg->params.max_transfer_size = val; 649323230efSJohn Youn } 650323230efSJohn Youn 651c1d286cfSJohn Youn static void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val) 652323230efSJohn Youn { 653323230efSJohn Youn int valid = 1; 654323230efSJohn Youn 655323230efSJohn Youn if (val < 15 || val > hsotg->hw_params.max_packet_count) 656323230efSJohn Youn valid = 0; 657323230efSJohn Youn 658323230efSJohn Youn if (!valid) { 659323230efSJohn Youn if (val >= 0) 660323230efSJohn Youn dev_err(hsotg->dev, 661323230efSJohn Youn "%d invalid for max_packet_count. Check HW configuration.\n", 662323230efSJohn Youn val); 663323230efSJohn Youn val = hsotg->hw_params.max_packet_count; 664323230efSJohn Youn dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); 665323230efSJohn Youn } 666323230efSJohn Youn 667bea8e86cSJohn Youn hsotg->params.max_packet_count = val; 668323230efSJohn Youn } 669323230efSJohn Youn 670c1d286cfSJohn Youn static void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val) 671323230efSJohn Youn { 672323230efSJohn Youn int valid = 1; 673323230efSJohn Youn 674323230efSJohn Youn if (val < 1 || val > hsotg->hw_params.host_channels) 675323230efSJohn Youn valid = 0; 676323230efSJohn Youn 677323230efSJohn Youn if (!valid) { 678323230efSJohn Youn if (val >= 0) 679323230efSJohn Youn dev_err(hsotg->dev, 680323230efSJohn Youn "%d invalid for host_channels. Check HW configuration.\n", 681323230efSJohn Youn val); 682323230efSJohn Youn val = hsotg->hw_params.host_channels; 683323230efSJohn Youn dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); 684323230efSJohn Youn } 685323230efSJohn Youn 686bea8e86cSJohn Youn hsotg->params.host_channels = val; 687323230efSJohn Youn } 688323230efSJohn Youn 689c1d286cfSJohn Youn static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) 690323230efSJohn Youn { 691323230efSJohn Youn int valid = 0; 692323230efSJohn Youn u32 hs_phy_type, fs_phy_type; 693323230efSJohn Youn 694323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS, 695323230efSJohn Youn DWC2_PHY_TYPE_PARAM_ULPI)) { 696323230efSJohn Youn if (val >= 0) { 697323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for phy_type\n"); 698323230efSJohn Youn dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n"); 699323230efSJohn Youn } 700323230efSJohn Youn 701323230efSJohn Youn valid = 0; 702323230efSJohn Youn } 703323230efSJohn Youn 704323230efSJohn Youn hs_phy_type = hsotg->hw_params.hs_phy_type; 705323230efSJohn Youn fs_phy_type = hsotg->hw_params.fs_phy_type; 706323230efSJohn Youn if (val == DWC2_PHY_TYPE_PARAM_UTMI && 707323230efSJohn Youn (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 708323230efSJohn Youn hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) 709323230efSJohn Youn valid = 1; 710323230efSJohn Youn else if (val == DWC2_PHY_TYPE_PARAM_ULPI && 711323230efSJohn Youn (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI || 712323230efSJohn Youn hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) 713323230efSJohn Youn valid = 1; 714323230efSJohn Youn else if (val == DWC2_PHY_TYPE_PARAM_FS && 715323230efSJohn Youn fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) 716323230efSJohn Youn valid = 1; 717323230efSJohn Youn 718323230efSJohn Youn if (!valid) { 719323230efSJohn Youn if (val >= 0) 720323230efSJohn Youn dev_err(hsotg->dev, 721323230efSJohn Youn "%d invalid for phy_type. Check HW configuration.\n", 722323230efSJohn Youn val); 723323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_FS; 724323230efSJohn Youn if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { 725323230efSJohn Youn if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 726323230efSJohn Youn hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) 727323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_UTMI; 728323230efSJohn Youn else 729323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_ULPI; 730323230efSJohn Youn } 731323230efSJohn Youn dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); 732323230efSJohn Youn } 733323230efSJohn Youn 734bea8e86cSJohn Youn hsotg->params.phy_type = val; 735323230efSJohn Youn } 736323230efSJohn Youn 737323230efSJohn Youn static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg) 738323230efSJohn Youn { 739bea8e86cSJohn Youn return hsotg->params.phy_type; 740323230efSJohn Youn } 741323230efSJohn Youn 742c1d286cfSJohn Youn static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) 743323230efSJohn Youn { 744323230efSJohn Youn int valid = 1; 745323230efSJohn Youn 74638e9002bSVardan Mikayelyan if (DWC2_OUT_OF_BOUNDS(val, 0, 2)) { 747323230efSJohn Youn if (val >= 0) { 748323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for speed parameter\n"); 74938e9002bSVardan Mikayelyan dev_err(hsotg->dev, "max_speed parameter must be 0, 1, or 2\n"); 750323230efSJohn Youn } 751323230efSJohn Youn valid = 0; 752323230efSJohn Youn } 753323230efSJohn Youn 75438e9002bSVardan Mikayelyan if (dwc2_is_hs_iot(hsotg) && 75538e9002bSVardan Mikayelyan val == DWC2_SPEED_PARAM_LOW) 75638e9002bSVardan Mikayelyan valid = 0; 75738e9002bSVardan Mikayelyan 758323230efSJohn Youn if (val == DWC2_SPEED_PARAM_HIGH && 759323230efSJohn Youn dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) 760323230efSJohn Youn valid = 0; 761323230efSJohn Youn 762323230efSJohn Youn if (!valid) { 763323230efSJohn Youn if (val >= 0) 764323230efSJohn Youn dev_err(hsotg->dev, 765323230efSJohn Youn "%d invalid for speed parameter. Check HW configuration.\n", 766323230efSJohn Youn val); 767323230efSJohn Youn val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? 768323230efSJohn Youn DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; 769323230efSJohn Youn dev_dbg(hsotg->dev, "Setting speed to %d\n", val); 770323230efSJohn Youn } 771323230efSJohn Youn 772bea8e86cSJohn Youn hsotg->params.speed = val; 773323230efSJohn Youn } 774323230efSJohn Youn 775c1d286cfSJohn Youn static void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, 776c1d286cfSJohn Youn int val) 777323230efSJohn Youn { 778323230efSJohn Youn int valid = 1; 779323230efSJohn Youn 780323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ, 781323230efSJohn Youn DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) { 782323230efSJohn Youn if (val >= 0) { 783323230efSJohn Youn dev_err(hsotg->dev, 784323230efSJohn Youn "Wrong value for host_ls_low_power_phy_clk parameter\n"); 785323230efSJohn Youn dev_err(hsotg->dev, 786323230efSJohn Youn "host_ls_low_power_phy_clk must be 0 or 1\n"); 787323230efSJohn Youn } 788323230efSJohn Youn valid = 0; 789323230efSJohn Youn } 790323230efSJohn Youn 791323230efSJohn Youn if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ && 792323230efSJohn Youn dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) 793323230efSJohn Youn valid = 0; 794323230efSJohn Youn 795323230efSJohn Youn if (!valid) { 796323230efSJohn Youn if (val >= 0) 797323230efSJohn Youn dev_err(hsotg->dev, 798323230efSJohn Youn "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n", 799323230efSJohn Youn val); 800323230efSJohn Youn val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS 801323230efSJohn Youn ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 802323230efSJohn Youn : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ; 803323230efSJohn Youn dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n", 804323230efSJohn Youn val); 805323230efSJohn Youn } 806323230efSJohn Youn 807bea8e86cSJohn Youn hsotg->params.host_ls_low_power_phy_clk = val; 808323230efSJohn Youn } 809323230efSJohn Youn 810c1d286cfSJohn Youn static void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val) 811323230efSJohn Youn { 812323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 813323230efSJohn Youn if (val >= 0) { 814323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n"); 815323230efSJohn Youn dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n"); 816323230efSJohn Youn } 817323230efSJohn Youn val = 0; 818323230efSJohn Youn dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val); 819323230efSJohn Youn } 820323230efSJohn Youn 821bea8e86cSJohn Youn hsotg->params.phy_ulpi_ddr = val; 822323230efSJohn Youn } 823323230efSJohn Youn 824c1d286cfSJohn Youn static void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val) 825323230efSJohn Youn { 826323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 827323230efSJohn Youn if (val >= 0) { 828323230efSJohn Youn dev_err(hsotg->dev, 829323230efSJohn Youn "Wrong value for phy_ulpi_ext_vbus\n"); 830323230efSJohn Youn dev_err(hsotg->dev, 831323230efSJohn Youn "phy_ulpi_ext_vbus must be 0 or 1\n"); 832323230efSJohn Youn } 833323230efSJohn Youn val = 0; 834323230efSJohn Youn dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val); 835323230efSJohn Youn } 836323230efSJohn Youn 837bea8e86cSJohn Youn hsotg->params.phy_ulpi_ext_vbus = val; 838323230efSJohn Youn } 839323230efSJohn Youn 840c1d286cfSJohn Youn static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val) 841323230efSJohn Youn { 842323230efSJohn Youn int valid = 0; 843323230efSJohn Youn 844323230efSJohn Youn switch (hsotg->hw_params.utmi_phy_data_width) { 845323230efSJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: 846323230efSJohn Youn valid = (val == 8); 847323230efSJohn Youn break; 848323230efSJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: 849323230efSJohn Youn valid = (val == 16); 850323230efSJohn Youn break; 851323230efSJohn Youn case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: 852323230efSJohn Youn valid = (val == 8 || val == 16); 853323230efSJohn Youn break; 854323230efSJohn Youn } 855323230efSJohn Youn 856323230efSJohn Youn if (!valid) { 857323230efSJohn Youn if (val >= 0) { 858323230efSJohn Youn dev_err(hsotg->dev, 859323230efSJohn Youn "%d invalid for phy_utmi_width. Check HW configuration.\n", 860323230efSJohn Youn val); 861323230efSJohn Youn } 862323230efSJohn Youn val = (hsotg->hw_params.utmi_phy_data_width == 863323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; 864323230efSJohn Youn dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val); 865323230efSJohn Youn } 866323230efSJohn Youn 867bea8e86cSJohn Youn hsotg->params.phy_utmi_width = val; 868323230efSJohn Youn } 869323230efSJohn Youn 870c1d286cfSJohn Youn static void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val) 871323230efSJohn Youn { 872323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 873323230efSJohn Youn if (val >= 0) { 874323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n"); 875323230efSJohn Youn dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n"); 876323230efSJohn Youn } 877323230efSJohn Youn val = 0; 878323230efSJohn Youn dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val); 879323230efSJohn Youn } 880323230efSJohn Youn 881bea8e86cSJohn Youn hsotg->params.ulpi_fs_ls = val; 882323230efSJohn Youn } 883323230efSJohn Youn 884c1d286cfSJohn Youn static void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val) 885323230efSJohn Youn { 886323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 887323230efSJohn Youn if (val >= 0) { 888323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for ts_dline\n"); 889323230efSJohn Youn dev_err(hsotg->dev, "ts_dline must be 0 or 1\n"); 890323230efSJohn Youn } 891323230efSJohn Youn val = 0; 892323230efSJohn Youn dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val); 893323230efSJohn Youn } 894323230efSJohn Youn 895bea8e86cSJohn Youn hsotg->params.ts_dline = val; 896323230efSJohn Youn } 897323230efSJohn Youn 898c1d286cfSJohn Youn static void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val) 899323230efSJohn Youn { 900323230efSJohn Youn int valid = 1; 901323230efSJohn Youn 902323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 903323230efSJohn Youn if (val >= 0) { 904323230efSJohn Youn dev_err(hsotg->dev, "Wrong value for i2c_enable\n"); 905323230efSJohn Youn dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n"); 906323230efSJohn Youn } 907323230efSJohn Youn 908323230efSJohn Youn valid = 0; 909323230efSJohn Youn } 910323230efSJohn Youn 911323230efSJohn Youn if (val == 1 && !(hsotg->hw_params.i2c_enable)) 912323230efSJohn Youn valid = 0; 913323230efSJohn Youn 914323230efSJohn Youn if (!valid) { 915323230efSJohn Youn if (val >= 0) 916323230efSJohn Youn dev_err(hsotg->dev, 917323230efSJohn Youn "%d invalid for i2c_enable. Check HW configuration.\n", 918323230efSJohn Youn val); 919323230efSJohn Youn val = hsotg->hw_params.i2c_enable; 920323230efSJohn Youn dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); 921323230efSJohn Youn } 922323230efSJohn Youn 923bea8e86cSJohn Youn hsotg->params.i2c_enable = val; 924323230efSJohn Youn } 925323230efSJohn Youn 926c1d286cfSJohn Youn static void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, 927c1d286cfSJohn Youn int val) 928323230efSJohn Youn { 929323230efSJohn Youn int valid = 1; 930323230efSJohn Youn 931323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 932323230efSJohn Youn if (val >= 0) { 933323230efSJohn Youn dev_err(hsotg->dev, 934323230efSJohn Youn "Wrong value for en_multiple_tx_fifo,\n"); 935323230efSJohn Youn dev_err(hsotg->dev, 936323230efSJohn Youn "en_multiple_tx_fifo must be 0 or 1\n"); 937323230efSJohn Youn } 938323230efSJohn Youn valid = 0; 939323230efSJohn Youn } 940323230efSJohn Youn 941323230efSJohn Youn if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo) 942323230efSJohn Youn valid = 0; 943323230efSJohn Youn 944323230efSJohn Youn if (!valid) { 945323230efSJohn Youn if (val >= 0) 946323230efSJohn Youn dev_err(hsotg->dev, 947323230efSJohn Youn "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", 948323230efSJohn Youn val); 949323230efSJohn Youn val = hsotg->hw_params.en_multiple_tx_fifo; 950323230efSJohn Youn dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val); 951323230efSJohn Youn } 952323230efSJohn Youn 953bea8e86cSJohn Youn hsotg->params.en_multiple_tx_fifo = val; 954323230efSJohn Youn } 955323230efSJohn Youn 956c1d286cfSJohn Youn static void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val) 957323230efSJohn Youn { 958323230efSJohn Youn int valid = 1; 959323230efSJohn Youn 960323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 961323230efSJohn Youn if (val >= 0) { 962323230efSJohn Youn dev_err(hsotg->dev, 963323230efSJohn Youn "'%d' invalid for parameter reload_ctl\n", val); 964323230efSJohn Youn dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n"); 965323230efSJohn Youn } 966323230efSJohn Youn valid = 0; 967323230efSJohn Youn } 968323230efSJohn Youn 969323230efSJohn Youn if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a) 970323230efSJohn Youn valid = 0; 971323230efSJohn Youn 972323230efSJohn Youn if (!valid) { 973323230efSJohn Youn if (val >= 0) 974323230efSJohn Youn dev_err(hsotg->dev, 975323230efSJohn Youn "%d invalid for parameter reload_ctl. Check HW configuration.\n", 976323230efSJohn Youn val); 977323230efSJohn Youn val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a; 978323230efSJohn Youn dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); 979323230efSJohn Youn } 980323230efSJohn Youn 981bea8e86cSJohn Youn hsotg->params.reload_ctl = val; 982323230efSJohn Youn } 983323230efSJohn Youn 984c1d286cfSJohn Youn static void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val) 985323230efSJohn Youn { 986323230efSJohn Youn if (val != -1) 987bea8e86cSJohn Youn hsotg->params.ahbcfg = val; 988323230efSJohn Youn else 989bea8e86cSJohn Youn hsotg->params.ahbcfg = GAHBCFG_HBSTLEN_INCR4 << 990323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT; 991323230efSJohn Youn } 992323230efSJohn Youn 993c1d286cfSJohn Youn static void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) 994323230efSJohn Youn { 995323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 996323230efSJohn Youn if (val >= 0) { 997323230efSJohn Youn dev_err(hsotg->dev, 998323230efSJohn Youn "'%d' invalid for parameter otg_ver\n", val); 999323230efSJohn Youn dev_err(hsotg->dev, 1000323230efSJohn Youn "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n"); 1001323230efSJohn Youn } 1002323230efSJohn Youn val = 0; 1003323230efSJohn Youn dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val); 1004323230efSJohn Youn } 1005323230efSJohn Youn 1006bea8e86cSJohn Youn hsotg->params.otg_ver = val; 1007323230efSJohn Youn } 1008323230efSJohn Youn 1009323230efSJohn Youn static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val) 1010323230efSJohn Youn { 1011323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 1012323230efSJohn Youn if (val >= 0) { 1013323230efSJohn Youn dev_err(hsotg->dev, 1014323230efSJohn Youn "'%d' invalid for parameter uframe_sched\n", 1015323230efSJohn Youn val); 1016323230efSJohn Youn dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n"); 1017323230efSJohn Youn } 1018323230efSJohn Youn val = 1; 1019323230efSJohn Youn dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val); 1020323230efSJohn Youn } 1021323230efSJohn Youn 1022bea8e86cSJohn Youn hsotg->params.uframe_sched = val; 1023323230efSJohn Youn } 1024323230efSJohn Youn 1025323230efSJohn Youn static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg, 1026323230efSJohn Youn int val) 1027323230efSJohn Youn { 1028323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 1029323230efSJohn Youn if (val >= 0) { 1030323230efSJohn Youn dev_err(hsotg->dev, 1031323230efSJohn Youn "'%d' invalid for parameter external_id_pin_ctl\n", 1032323230efSJohn Youn val); 1033323230efSJohn Youn dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n"); 1034323230efSJohn Youn } 1035323230efSJohn Youn val = 0; 1036323230efSJohn Youn dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val); 1037323230efSJohn Youn } 1038323230efSJohn Youn 1039bea8e86cSJohn Youn hsotg->params.external_id_pin_ctl = val; 1040323230efSJohn Youn } 1041323230efSJohn Youn 1042323230efSJohn Youn static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg, 1043323230efSJohn Youn int val) 1044323230efSJohn Youn { 1045323230efSJohn Youn if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 1046323230efSJohn Youn if (val >= 0) { 1047323230efSJohn Youn dev_err(hsotg->dev, 1048323230efSJohn Youn "'%d' invalid for parameter hibernation\n", 1049323230efSJohn Youn val); 1050323230efSJohn Youn dev_err(hsotg->dev, "hibernation must be 0 or 1\n"); 1051323230efSJohn Youn } 1052323230efSJohn Youn val = 0; 1053323230efSJohn Youn dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val); 1054323230efSJohn Youn } 1055323230efSJohn Youn 1056bea8e86cSJohn Youn hsotg->params.hibernation = val; 1057323230efSJohn Youn } 1058323230efSJohn Youn 105905ee799fSJohn Youn static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg) 106005ee799fSJohn Youn { 106105ee799fSJohn Youn int i; 106205ee799fSJohn Youn int num; 106305ee799fSJohn Youn char *property = "g-tx-fifo-size"; 106405ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params; 106505ee799fSJohn Youn 106605ee799fSJohn Youn memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size)); 106705ee799fSJohn Youn 106805ee799fSJohn Youn /* Read tx fifo sizes */ 106905ee799fSJohn Youn num = device_property_read_u32_array(hsotg->dev, property, NULL, 0); 107005ee799fSJohn Youn 107105ee799fSJohn Youn if (num > 0) { 107205ee799fSJohn Youn device_property_read_u32_array(hsotg->dev, property, 107305ee799fSJohn Youn &p->g_tx_fifo_size[1], 107405ee799fSJohn Youn num); 107505ee799fSJohn Youn } else { 107605ee799fSJohn Youn u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE; 107705ee799fSJohn Youn 107805ee799fSJohn Youn memcpy(&p->g_tx_fifo_size[1], 107905ee799fSJohn Youn p_tx_fifo, 108005ee799fSJohn Youn sizeof(p_tx_fifo)); 108105ee799fSJohn Youn 108205ee799fSJohn Youn num = ARRAY_SIZE(p_tx_fifo); 108305ee799fSJohn Youn } 108405ee799fSJohn Youn 108505ee799fSJohn Youn for (i = 0; i < num; i++) { 108605ee799fSJohn Youn if ((i + 1) >= ARRAY_SIZE(p->g_tx_fifo_size)) 108705ee799fSJohn Youn break; 108805ee799fSJohn Youn 108905ee799fSJohn Youn dev_dbg(hsotg->dev, "Setting %s[%d] to %d\n", 109005ee799fSJohn Youn property, i + 1, p->g_tx_fifo_size[i + 1]); 109105ee799fSJohn Youn } 109205ee799fSJohn Youn } 109305ee799fSJohn Youn 10949962b62fSJohn Youn static void dwc2_set_gadget_dma(struct dwc2_hsotg *hsotg) 10959962b62fSJohn Youn { 10969962b62fSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 10979962b62fSJohn Youn struct dwc2_core_params *p = &hsotg->params; 10989962b62fSJohn Youn bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH); 10999962b62fSJohn Youn 11009962b62fSJohn Youn /* Buffer DMA */ 11019962b62fSJohn Youn dwc2_set_param_bool(hsotg, &p->g_dma, 11029962b62fSJohn Youn false, "gadget-dma", 11039962b62fSJohn Youn true, false, 11049962b62fSJohn Youn dma_capable); 1105dec4b556SVahram Aharonyan 1106dec4b556SVahram Aharonyan /* DMA Descriptor */ 1107dec4b556SVahram Aharonyan dwc2_set_param_bool(hsotg, &p->g_dma_desc, false, 1108dec4b556SVahram Aharonyan "gadget-dma-desc", 1109dec4b556SVahram Aharonyan p->g_dma, false, 1110dec4b556SVahram Aharonyan !!hw->dma_desc_enable); 11119962b62fSJohn Youn } 11129962b62fSJohn Youn 111305ee799fSJohn Youn /** 111405ee799fSJohn Youn * dwc2_set_parameters() - Set all core parameters. 111505ee799fSJohn Youn * 111605ee799fSJohn Youn * @hsotg: Programming view of the DWC_otg controller 111705ee799fSJohn Youn * @params: The parameters to set 1118323230efSJohn Youn */ 1119c1d286cfSJohn Youn static void dwc2_set_parameters(struct dwc2_hsotg *hsotg, 1120323230efSJohn Youn const struct dwc2_core_params *params) 1121323230efSJohn Youn { 112205ee799fSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 112305ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params; 11246b66ce51SJohn Youn bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH); 1125323230efSJohn Youn 1126323230efSJohn Youn dwc2_set_param_otg_cap(hsotg, params->otg_cap); 11276b66ce51SJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_HOST) || 11286b66ce51SJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) { 11296b66ce51SJohn Youn dev_dbg(hsotg->dev, "Setting HOST parameters\n"); 11306b66ce51SJohn Youn 11316b66ce51SJohn Youn dwc2_set_param_bool(hsotg, &p->host_dma, 11326b66ce51SJohn Youn false, "host-dma", 11338ad07335SJohn Youn true, false, 11346b66ce51SJohn Youn dma_capable); 11356b66ce51SJohn Youn } 11364be0080cSChristian Lamparter dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 11374be0080cSChristian Lamparter dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); 11386b66ce51SJohn Youn 1139323230efSJohn Youn dwc2_set_param_host_support_fs_ls_low_power(hsotg, 1140323230efSJohn Youn params->host_support_fs_ls_low_power); 1141323230efSJohn Youn dwc2_set_param_enable_dynamic_fifo(hsotg, 1142323230efSJohn Youn params->enable_dynamic_fifo); 1143323230efSJohn Youn dwc2_set_param_host_rx_fifo_size(hsotg, 1144323230efSJohn Youn params->host_rx_fifo_size); 1145323230efSJohn Youn dwc2_set_param_host_nperio_tx_fifo_size(hsotg, 1146323230efSJohn Youn params->host_nperio_tx_fifo_size); 1147323230efSJohn Youn dwc2_set_param_host_perio_tx_fifo_size(hsotg, 1148323230efSJohn Youn params->host_perio_tx_fifo_size); 1149323230efSJohn Youn dwc2_set_param_max_transfer_size(hsotg, 1150323230efSJohn Youn params->max_transfer_size); 1151323230efSJohn Youn dwc2_set_param_max_packet_count(hsotg, 1152323230efSJohn Youn params->max_packet_count); 1153323230efSJohn Youn dwc2_set_param_host_channels(hsotg, params->host_channels); 1154323230efSJohn Youn dwc2_set_param_phy_type(hsotg, params->phy_type); 1155323230efSJohn Youn dwc2_set_param_speed(hsotg, params->speed); 1156323230efSJohn Youn dwc2_set_param_host_ls_low_power_phy_clk(hsotg, 1157323230efSJohn Youn params->host_ls_low_power_phy_clk); 1158323230efSJohn Youn dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr); 1159323230efSJohn Youn dwc2_set_param_phy_ulpi_ext_vbus(hsotg, 1160323230efSJohn Youn params->phy_ulpi_ext_vbus); 1161323230efSJohn Youn dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width); 1162323230efSJohn Youn dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls); 1163323230efSJohn Youn dwc2_set_param_ts_dline(hsotg, params->ts_dline); 1164323230efSJohn Youn dwc2_set_param_i2c_enable(hsotg, params->i2c_enable); 1165323230efSJohn Youn dwc2_set_param_en_multiple_tx_fifo(hsotg, 1166323230efSJohn Youn params->en_multiple_tx_fifo); 1167323230efSJohn Youn dwc2_set_param_reload_ctl(hsotg, params->reload_ctl); 1168323230efSJohn Youn dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); 1169323230efSJohn Youn dwc2_set_param_otg_ver(hsotg, params->otg_ver); 1170323230efSJohn Youn dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); 1171323230efSJohn Youn dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl); 1172323230efSJohn Youn dwc2_set_param_hibernation(hsotg, params->hibernation); 117305ee799fSJohn Youn 117405ee799fSJohn Youn /* 117505ee799fSJohn Youn * Set devicetree-only parameters. These parameters do not 117605ee799fSJohn Youn * take any values from @params. 117705ee799fSJohn Youn */ 117805ee799fSJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || 117905ee799fSJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) { 118005ee799fSJohn Youn dev_dbg(hsotg->dev, "Setting peripheral device properties\n"); 118105ee799fSJohn Youn 11829962b62fSJohn Youn dwc2_set_gadget_dma(hsotg); 118305ee799fSJohn Youn 118405ee799fSJohn Youn /* 118505ee799fSJohn Youn * The values for g_rx_fifo_size (2048) and 118605ee799fSJohn Youn * g_np_tx_fifo_size (1024) come from the legacy s3c 118705ee799fSJohn Youn * gadget driver. These defaults have been hard-coded 118805ee799fSJohn Youn * for some time so many platforms depend on these 118905ee799fSJohn Youn * values. Leave them as defaults for now and only 119005ee799fSJohn Youn * auto-detect if the hardware does not support the 119105ee799fSJohn Youn * default. 119205ee799fSJohn Youn */ 119305ee799fSJohn Youn dwc2_set_param_u16(hsotg, &p->g_rx_fifo_size, 119405ee799fSJohn Youn true, "g-rx-fifo-size", 2048, 119505ee799fSJohn Youn hw->rx_fifo_size, 119605ee799fSJohn Youn 16, hw->rx_fifo_size); 119705ee799fSJohn Youn 119805ee799fSJohn Youn dwc2_set_param_u16(hsotg, &p->g_np_tx_fifo_size, 119905ee799fSJohn Youn true, "g-np-tx-fifo-size", 1024, 120005ee799fSJohn Youn hw->dev_nperio_tx_fifo_size, 120105ee799fSJohn Youn 16, hw->dev_nperio_tx_fifo_size); 120205ee799fSJohn Youn 120305ee799fSJohn Youn dwc2_set_param_tx_fifo_sizes(hsotg); 120405ee799fSJohn Youn } 1205323230efSJohn Youn } 1206323230efSJohn Youn 1207323230efSJohn Youn /* 1208323230efSJohn Youn * Gets host hardware parameters. Forces host mode if not currently in 1209323230efSJohn Youn * host mode. Should be called immediately after a core soft reset in 1210323230efSJohn Youn * order to get the reset values. 1211323230efSJohn Youn */ 1212323230efSJohn Youn static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) 1213323230efSJohn Youn { 1214323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 1215323230efSJohn Youn u32 gnptxfsiz; 1216323230efSJohn Youn u32 hptxfsiz; 1217323230efSJohn Youn bool forced; 1218323230efSJohn Youn 1219323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 1220323230efSJohn Youn return; 1221323230efSJohn Youn 1222323230efSJohn Youn forced = dwc2_force_mode_if_needed(hsotg, true); 1223323230efSJohn Youn 1224323230efSJohn Youn gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 1225323230efSJohn Youn hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 1226323230efSJohn Youn dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 1227323230efSJohn Youn dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 1228323230efSJohn Youn 1229323230efSJohn Youn if (forced) 1230323230efSJohn Youn dwc2_clear_force_mode(hsotg); 1231323230efSJohn Youn 1232323230efSJohn Youn hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 1233323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 1234323230efSJohn Youn hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 1235323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 1236323230efSJohn Youn } 1237323230efSJohn Youn 1238323230efSJohn Youn /* 1239323230efSJohn Youn * Gets device hardware parameters. Forces device mode if not 1240323230efSJohn Youn * currently in device mode. Should be called immediately after a core 1241323230efSJohn Youn * soft reset in order to get the reset values. 1242323230efSJohn Youn */ 1243323230efSJohn Youn static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) 1244323230efSJohn Youn { 1245323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 1246323230efSJohn Youn bool forced; 1247323230efSJohn Youn u32 gnptxfsiz; 1248323230efSJohn Youn 1249323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_HOST) 1250323230efSJohn Youn return; 1251323230efSJohn Youn 1252323230efSJohn Youn forced = dwc2_force_mode_if_needed(hsotg, false); 1253323230efSJohn Youn 1254323230efSJohn Youn gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 1255323230efSJohn Youn dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 1256323230efSJohn Youn 1257323230efSJohn Youn if (forced) 1258323230efSJohn Youn dwc2_clear_force_mode(hsotg); 1259323230efSJohn Youn 1260323230efSJohn Youn hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 1261323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 1262323230efSJohn Youn } 1263323230efSJohn Youn 1264323230efSJohn Youn /** 1265323230efSJohn Youn * During device initialization, read various hardware configuration 1266323230efSJohn Youn * registers and interpret the contents. 1267323230efSJohn Youn */ 1268323230efSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) 1269323230efSJohn Youn { 1270323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 1271323230efSJohn Youn unsigned int width; 1272323230efSJohn Youn u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; 1273323230efSJohn Youn u32 grxfsiz; 1274323230efSJohn Youn 1275323230efSJohn Youn /* 1276323230efSJohn Youn * Attempt to ensure this device is really a DWC_otg Controller. 1277323230efSJohn Youn * Read and verify the GSNPSID register contents. The value should be 1278323230efSJohn Youn * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", 1279323230efSJohn Youn * as in "OTG version 2.xx" or "OTG version 3.xx". 1280323230efSJohn Youn */ 1281323230efSJohn Youn hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); 1282323230efSJohn Youn if ((hw->snpsid & 0xfffff000) != 0x4f542000 && 12831e6b98ebSVardan Mikayelyan (hw->snpsid & 0xfffff000) != 0x4f543000 && 12841e6b98ebSVardan Mikayelyan (hw->snpsid & 0xffff0000) != 0x55310000 && 12851e6b98ebSVardan Mikayelyan (hw->snpsid & 0xffff0000) != 0x55320000) { 1286323230efSJohn Youn dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", 1287323230efSJohn Youn hw->snpsid); 1288323230efSJohn Youn return -ENODEV; 1289323230efSJohn Youn } 1290323230efSJohn Youn 1291323230efSJohn Youn dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", 1292323230efSJohn Youn hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 1293323230efSJohn Youn hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 1294323230efSJohn Youn 1295323230efSJohn Youn hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); 1296323230efSJohn Youn hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 1297323230efSJohn Youn hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); 1298323230efSJohn Youn hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 1299323230efSJohn Youn grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 1300323230efSJohn Youn 1301323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); 1302323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); 1303323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); 1304323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); 1305323230efSJohn Youn dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); 1306323230efSJohn Youn 1307323230efSJohn Youn /* 1308323230efSJohn Youn * Host specific hardware parameters. Reading these parameters 1309323230efSJohn Youn * requires the controller to be in host mode. The mode will 1310323230efSJohn Youn * be forced, if necessary, to read these values. 1311323230efSJohn Youn */ 1312323230efSJohn Youn dwc2_get_host_hwparams(hsotg); 1313323230efSJohn Youn dwc2_get_dev_hwparams(hsotg); 1314323230efSJohn Youn 1315323230efSJohn Youn /* hwcfg1 */ 1316323230efSJohn Youn hw->dev_ep_dirs = hwcfg1; 1317323230efSJohn Youn 1318323230efSJohn Youn /* hwcfg2 */ 1319323230efSJohn Youn hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> 1320323230efSJohn Youn GHWCFG2_OP_MODE_SHIFT; 1321323230efSJohn Youn hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 1322323230efSJohn Youn GHWCFG2_ARCHITECTURE_SHIFT; 1323323230efSJohn Youn hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); 1324323230efSJohn Youn hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> 1325323230efSJohn Youn GHWCFG2_NUM_HOST_CHAN_SHIFT); 1326323230efSJohn Youn hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> 1327323230efSJohn Youn GHWCFG2_HS_PHY_TYPE_SHIFT; 1328323230efSJohn Youn hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> 1329323230efSJohn Youn GHWCFG2_FS_PHY_TYPE_SHIFT; 1330323230efSJohn Youn hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> 1331323230efSJohn Youn GHWCFG2_NUM_DEV_EP_SHIFT; 1332323230efSJohn Youn hw->nperio_tx_q_depth = 1333323230efSJohn Youn (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> 1334323230efSJohn Youn GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; 1335323230efSJohn Youn hw->host_perio_tx_q_depth = 1336323230efSJohn Youn (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> 1337323230efSJohn Youn GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; 1338323230efSJohn Youn hw->dev_token_q_depth = 1339323230efSJohn Youn (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> 1340323230efSJohn Youn GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; 1341323230efSJohn Youn 1342323230efSJohn Youn /* hwcfg3 */ 1343323230efSJohn Youn width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> 1344323230efSJohn Youn GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; 1345323230efSJohn Youn hw->max_transfer_size = (1 << (width + 11)) - 1; 1346323230efSJohn Youn width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> 1347323230efSJohn Youn GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; 1348323230efSJohn Youn hw->max_packet_count = (1 << (width + 4)) - 1; 1349323230efSJohn Youn hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); 1350323230efSJohn Youn hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> 1351323230efSJohn Youn GHWCFG3_DFIFO_DEPTH_SHIFT; 1352323230efSJohn Youn 1353323230efSJohn Youn /* hwcfg4 */ 1354323230efSJohn Youn hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); 1355323230efSJohn Youn hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> 1356323230efSJohn Youn GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; 1357323230efSJohn Youn hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); 1358323230efSJohn Youn hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); 1359323230efSJohn Youn hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> 1360323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; 1361323230efSJohn Youn 1362323230efSJohn Youn /* fifo sizes */ 1363d1531319SJohn Youn hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 1364323230efSJohn Youn GRXFSIZ_DEPTH_SHIFT; 1365323230efSJohn Youn 1366323230efSJohn Youn dev_dbg(hsotg->dev, "Detected values from hardware:\n"); 1367323230efSJohn Youn dev_dbg(hsotg->dev, " op_mode=%d\n", 1368323230efSJohn Youn hw->op_mode); 1369323230efSJohn Youn dev_dbg(hsotg->dev, " arch=%d\n", 1370323230efSJohn Youn hw->arch); 1371323230efSJohn Youn dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", 1372323230efSJohn Youn hw->dma_desc_enable); 1373323230efSJohn Youn dev_dbg(hsotg->dev, " power_optimized=%d\n", 1374323230efSJohn Youn hw->power_optimized); 1375323230efSJohn Youn dev_dbg(hsotg->dev, " i2c_enable=%d\n", 1376323230efSJohn Youn hw->i2c_enable); 1377323230efSJohn Youn dev_dbg(hsotg->dev, " hs_phy_type=%d\n", 1378323230efSJohn Youn hw->hs_phy_type); 1379323230efSJohn Youn dev_dbg(hsotg->dev, " fs_phy_type=%d\n", 1380323230efSJohn Youn hw->fs_phy_type); 1381323230efSJohn Youn dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n", 1382323230efSJohn Youn hw->utmi_phy_data_width); 1383323230efSJohn Youn dev_dbg(hsotg->dev, " num_dev_ep=%d\n", 1384323230efSJohn Youn hw->num_dev_ep); 1385323230efSJohn Youn dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", 1386323230efSJohn Youn hw->num_dev_perio_in_ep); 1387323230efSJohn Youn dev_dbg(hsotg->dev, " host_channels=%d\n", 1388323230efSJohn Youn hw->host_channels); 1389323230efSJohn Youn dev_dbg(hsotg->dev, " max_transfer_size=%d\n", 1390323230efSJohn Youn hw->max_transfer_size); 1391323230efSJohn Youn dev_dbg(hsotg->dev, " max_packet_count=%d\n", 1392323230efSJohn Youn hw->max_packet_count); 1393323230efSJohn Youn dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", 1394323230efSJohn Youn hw->nperio_tx_q_depth); 1395323230efSJohn Youn dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", 1396323230efSJohn Youn hw->host_perio_tx_q_depth); 1397323230efSJohn Youn dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", 1398323230efSJohn Youn hw->dev_token_q_depth); 1399323230efSJohn Youn dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", 1400323230efSJohn Youn hw->enable_dynamic_fifo); 1401323230efSJohn Youn dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", 1402323230efSJohn Youn hw->en_multiple_tx_fifo); 1403323230efSJohn Youn dev_dbg(hsotg->dev, " total_fifo_size=%d\n", 1404323230efSJohn Youn hw->total_fifo_size); 1405d1531319SJohn Youn dev_dbg(hsotg->dev, " rx_fifo_size=%d\n", 1406d1531319SJohn Youn hw->rx_fifo_size); 1407323230efSJohn Youn dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", 1408323230efSJohn Youn hw->host_nperio_tx_fifo_size); 1409323230efSJohn Youn dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", 1410323230efSJohn Youn hw->host_perio_tx_fifo_size); 1411323230efSJohn Youn dev_dbg(hsotg->dev, "\n"); 1412323230efSJohn Youn 1413323230efSJohn Youn return 0; 1414323230efSJohn Youn } 1415323230efSJohn Youn 1416334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg) 1417334bbd4eSJohn Youn { 1418334bbd4eSJohn Youn const struct of_device_id *match; 14190a7d0d7fSJohn Youn struct dwc2_core_params params; 1420334bbd4eSJohn Youn 1421334bbd4eSJohn Youn match = of_match_device(dwc2_of_match_table, hsotg->dev); 14220a7d0d7fSJohn Youn if (match && match->data) 14230a7d0d7fSJohn Youn params = *((struct dwc2_core_params *)match->data); 14240a7d0d7fSJohn Youn else 14250a7d0d7fSJohn Youn params = params_default; 1426334bbd4eSJohn Youn 14271e6b98ebSVardan Mikayelyan if (dwc2_is_fs_iot(hsotg)) { 14281e6b98ebSVardan Mikayelyan params.speed = DWC2_SPEED_PARAM_FULL; 14291e6b98ebSVardan Mikayelyan params.phy_type = DWC2_PHY_TYPE_PARAM_FS; 14301e6b98ebSVardan Mikayelyan } 14311e6b98ebSVardan Mikayelyan 14320a7d0d7fSJohn Youn dwc2_set_parameters(hsotg, ¶ms); 1433334bbd4eSJohn Youn 1434334bbd4eSJohn Youn return 0; 1435334bbd4eSJohn Youn } 1436