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 .dma_desc_enable = 0, 44323230efSJohn Youn .dma_desc_fs_enable = 0, 45323230efSJohn Youn .speed = 0, /* High Speed */ 46323230efSJohn Youn .enable_dynamic_fifo = 1, 47323230efSJohn Youn .en_multiple_tx_fifo = 1, 48323230efSJohn Youn .host_rx_fifo_size = 512, 49323230efSJohn Youn .host_nperio_tx_fifo_size = 512, 50323230efSJohn Youn .host_perio_tx_fifo_size = 512, 51323230efSJohn Youn .max_transfer_size = 65535, 52323230efSJohn Youn .max_packet_count = 511, 53323230efSJohn Youn .host_channels = 16, 54323230efSJohn Youn .phy_type = 1, /* UTMI */ 55323230efSJohn Youn .phy_utmi_width = 8, 56323230efSJohn Youn .phy_ulpi_ddr = 0, /* Single */ 57323230efSJohn Youn .phy_ulpi_ext_vbus = 0, 58323230efSJohn Youn .i2c_enable = 0, 59323230efSJohn Youn .ulpi_fs_ls = 0, 60323230efSJohn Youn .host_support_fs_ls_low_power = 0, 61323230efSJohn Youn .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 62323230efSJohn Youn .ts_dline = 0, 63323230efSJohn Youn .reload_ctl = 0, 64323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 65323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 66323230efSJohn Youn .uframe_sched = 0, 67323230efSJohn Youn .external_id_pin_ctl = -1, 68323230efSJohn Youn .hibernation = -1, 69323230efSJohn Youn }; 70323230efSJohn Youn 71323230efSJohn Youn static const struct dwc2_core_params params_bcm2835 = { 72323230efSJohn Youn .otg_cap = 0, /* HNP/SRP capable */ 73323230efSJohn Youn .dma_desc_enable = 0, 74323230efSJohn Youn .dma_desc_fs_enable = 0, 75323230efSJohn Youn .speed = 0, /* High Speed */ 76323230efSJohn Youn .enable_dynamic_fifo = 1, 77323230efSJohn Youn .en_multiple_tx_fifo = 1, 78323230efSJohn Youn .host_rx_fifo_size = 774, /* 774 DWORDs */ 79323230efSJohn Youn .host_nperio_tx_fifo_size = 256, /* 256 DWORDs */ 80323230efSJohn Youn .host_perio_tx_fifo_size = 512, /* 512 DWORDs */ 81323230efSJohn Youn .max_transfer_size = 65535, 82323230efSJohn Youn .max_packet_count = 511, 83323230efSJohn Youn .host_channels = 8, 84323230efSJohn Youn .phy_type = 1, /* UTMI */ 85323230efSJohn Youn .phy_utmi_width = 8, /* 8 bits */ 86323230efSJohn Youn .phy_ulpi_ddr = 0, /* Single */ 87323230efSJohn Youn .phy_ulpi_ext_vbus = 0, 88323230efSJohn Youn .i2c_enable = 0, 89323230efSJohn Youn .ulpi_fs_ls = 0, 90323230efSJohn Youn .host_support_fs_ls_low_power = 0, 91323230efSJohn Youn .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 92323230efSJohn Youn .ts_dline = 0, 93323230efSJohn Youn .reload_ctl = 0, 94323230efSJohn Youn .ahbcfg = 0x10, 95323230efSJohn Youn .uframe_sched = 0, 96323230efSJohn Youn .external_id_pin_ctl = -1, 97323230efSJohn Youn .hibernation = -1, 98323230efSJohn Youn }; 99323230efSJohn Youn 100323230efSJohn Youn static const struct dwc2_core_params params_rk3066 = { 101323230efSJohn Youn .otg_cap = 2, /* non-HNP/non-SRP */ 102323230efSJohn Youn .dma_desc_enable = 0, 103323230efSJohn Youn .dma_desc_fs_enable = 0, 104323230efSJohn Youn .speed = -1, 105323230efSJohn Youn .enable_dynamic_fifo = 1, 106323230efSJohn Youn .en_multiple_tx_fifo = -1, 107323230efSJohn Youn .host_rx_fifo_size = 525, /* 525 DWORDs */ 108323230efSJohn Youn .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ 109323230efSJohn Youn .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ 110323230efSJohn Youn .max_transfer_size = -1, 111323230efSJohn Youn .max_packet_count = -1, 112323230efSJohn Youn .host_channels = -1, 113323230efSJohn Youn .phy_type = -1, 114323230efSJohn Youn .phy_utmi_width = -1, 115323230efSJohn Youn .phy_ulpi_ddr = -1, 116323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 117323230efSJohn Youn .i2c_enable = -1, 118323230efSJohn Youn .ulpi_fs_ls = -1, 119323230efSJohn Youn .host_support_fs_ls_low_power = -1, 120323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 121323230efSJohn Youn .ts_dline = -1, 122323230efSJohn Youn .reload_ctl = -1, 123323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 124323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 125323230efSJohn Youn .uframe_sched = -1, 126323230efSJohn Youn .external_id_pin_ctl = -1, 127323230efSJohn Youn .hibernation = -1, 128323230efSJohn Youn }; 129323230efSJohn Youn 130323230efSJohn Youn static const struct dwc2_core_params params_ltq = { 131323230efSJohn Youn .otg_cap = 2, /* non-HNP/non-SRP */ 132323230efSJohn Youn .dma_desc_enable = -1, 133323230efSJohn Youn .dma_desc_fs_enable = -1, 134323230efSJohn Youn .speed = -1, 135323230efSJohn Youn .enable_dynamic_fifo = -1, 136323230efSJohn Youn .en_multiple_tx_fifo = -1, 137323230efSJohn Youn .host_rx_fifo_size = 288, /* 288 DWORDs */ 138323230efSJohn Youn .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ 139323230efSJohn Youn .host_perio_tx_fifo_size = 96, /* 96 DWORDs */ 140323230efSJohn Youn .max_transfer_size = 65535, 141323230efSJohn Youn .max_packet_count = 511, 142323230efSJohn Youn .host_channels = -1, 143323230efSJohn Youn .phy_type = -1, 144323230efSJohn Youn .phy_utmi_width = -1, 145323230efSJohn Youn .phy_ulpi_ddr = -1, 146323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 147323230efSJohn Youn .i2c_enable = -1, 148323230efSJohn Youn .ulpi_fs_ls = -1, 149323230efSJohn Youn .host_support_fs_ls_low_power = -1, 150323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 151323230efSJohn Youn .ts_dline = -1, 152323230efSJohn Youn .reload_ctl = -1, 153323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 154323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 155323230efSJohn Youn .uframe_sched = -1, 156323230efSJohn Youn .external_id_pin_ctl = -1, 157323230efSJohn Youn .hibernation = -1, 158323230efSJohn Youn }; 159323230efSJohn Youn 160323230efSJohn Youn static const struct dwc2_core_params params_amlogic = { 161323230efSJohn Youn .otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE, 162323230efSJohn Youn .dma_desc_enable = 0, 163323230efSJohn Youn .dma_desc_fs_enable = 0, 164323230efSJohn Youn .speed = DWC2_SPEED_PARAM_HIGH, 165323230efSJohn Youn .enable_dynamic_fifo = 1, 166323230efSJohn Youn .en_multiple_tx_fifo = -1, 167323230efSJohn Youn .host_rx_fifo_size = 512, 168323230efSJohn Youn .host_nperio_tx_fifo_size = 500, 169323230efSJohn Youn .host_perio_tx_fifo_size = 500, 170323230efSJohn Youn .max_transfer_size = -1, 171323230efSJohn Youn .max_packet_count = -1, 172323230efSJohn Youn .host_channels = 16, 173323230efSJohn Youn .phy_type = DWC2_PHY_TYPE_PARAM_UTMI, 174323230efSJohn Youn .phy_utmi_width = -1, 175323230efSJohn Youn .phy_ulpi_ddr = -1, 176323230efSJohn Youn .phy_ulpi_ext_vbus = -1, 177323230efSJohn Youn .i2c_enable = -1, 178323230efSJohn Youn .ulpi_fs_ls = -1, 179323230efSJohn Youn .host_support_fs_ls_low_power = -1, 180323230efSJohn Youn .host_ls_low_power_phy_clk = -1, 181323230efSJohn Youn .ts_dline = -1, 182323230efSJohn Youn .reload_ctl = 1, 183323230efSJohn Youn .ahbcfg = GAHBCFG_HBSTLEN_INCR8 << 184323230efSJohn Youn GAHBCFG_HBSTLEN_SHIFT, 185323230efSJohn Youn .uframe_sched = 0, 186323230efSJohn Youn .external_id_pin_ctl = -1, 187323230efSJohn Youn .hibernation = -1, 188323230efSJohn Youn }; 189323230efSJohn Youn 190323230efSJohn Youn const struct of_device_id dwc2_of_match_table[] = { 191323230efSJohn Youn { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, 192323230efSJohn Youn { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 }, 193323230efSJohn Youn { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, 194323230efSJohn Youn { .compatible = "lantiq,arx100-usb", .data = ¶ms_ltq }, 195323230efSJohn Youn { .compatible = "lantiq,xrx200-usb", .data = ¶ms_ltq }, 196323230efSJohn Youn { .compatible = "snps,dwc2", .data = NULL }, 197323230efSJohn Youn { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, 198323230efSJohn Youn { .compatible = "amlogic,meson8b-usb", .data = ¶ms_amlogic }, 199323230efSJohn Youn { .compatible = "amlogic,meson-gxbb-usb", .data = ¶ms_amlogic }, 2003922fb46SChristian Lamparter { .compatible = "amcc,dwc-otg", .data = NULL }, 201323230efSJohn Youn {}, 202323230efSJohn Youn }; 203323230efSJohn Youn MODULE_DEVICE_TABLE(of, dwc2_of_match_table); 204323230efSJohn Youn 205245977c9SJohn Youn static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg) 20605ee799fSJohn Youn { 207245977c9SJohn Youn u8 val; 20805ee799fSJohn Youn 209323230efSJohn Youn switch (hsotg->hw_params.op_mode) { 210323230efSJohn Youn case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 211323230efSJohn Youn val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; 212323230efSJohn Youn break; 213323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 214323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 215323230efSJohn Youn case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 216323230efSJohn Youn val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; 217323230efSJohn Youn break; 218323230efSJohn Youn default: 219323230efSJohn Youn val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; 220323230efSJohn Youn break; 221323230efSJohn Youn } 222323230efSJohn Youn 223bea8e86cSJohn Youn hsotg->params.otg_cap = val; 224323230efSJohn Youn } 225323230efSJohn Youn 226245977c9SJohn Youn static void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg) 227323230efSJohn Youn { 228245977c9SJohn Youn int val; 229245977c9SJohn Youn u32 hs_phy_type = hsotg->hw_params.hs_phy_type; 230323230efSJohn Youn 231323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_FS; 232323230efSJohn Youn if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { 233323230efSJohn Youn if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 234323230efSJohn Youn hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) 235323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_UTMI; 236323230efSJohn Youn else 237323230efSJohn Youn val = DWC2_PHY_TYPE_PARAM_ULPI; 238323230efSJohn Youn } 239245977c9SJohn Youn 240245977c9SJohn Youn if (dwc2_is_fs_iot(hsotg)) 241245977c9SJohn Youn hsotg->params.phy_type = DWC2_PHY_TYPE_PARAM_FS; 242323230efSJohn Youn 243bea8e86cSJohn Youn hsotg->params.phy_type = val; 244323230efSJohn Youn } 245323230efSJohn Youn 246245977c9SJohn Youn static void dwc2_set_param_speed(struct dwc2_hsotg *hsotg) 247323230efSJohn Youn { 248245977c9SJohn Youn int val; 249323230efSJohn Youn 250245977c9SJohn Youn val = hsotg->params.phy_type == DWC2_PHY_TYPE_PARAM_FS ? 251323230efSJohn Youn DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; 252245977c9SJohn Youn 253245977c9SJohn Youn if (dwc2_is_fs_iot(hsotg)) 254245977c9SJohn Youn val = DWC2_SPEED_PARAM_FULL; 255245977c9SJohn Youn 256245977c9SJohn Youn if (dwc2_is_hs_iot(hsotg)) 257245977c9SJohn Youn val = DWC2_SPEED_PARAM_HIGH; 258323230efSJohn Youn 259bea8e86cSJohn Youn hsotg->params.speed = val; 260323230efSJohn Youn } 261323230efSJohn Youn 262245977c9SJohn Youn static void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg) 263323230efSJohn Youn { 264245977c9SJohn Youn int val; 265323230efSJohn Youn 266323230efSJohn Youn val = (hsotg->hw_params.utmi_phy_data_width == 267323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; 268323230efSJohn Youn 269bea8e86cSJohn Youn hsotg->params.phy_utmi_width = val; 270323230efSJohn Youn } 271323230efSJohn Youn 27205ee799fSJohn Youn static void dwc2_set_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg) 27305ee799fSJohn Youn { 27405ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params; 27505ee799fSJohn Youn u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE; 27605ee799fSJohn Youn 277245977c9SJohn Youn memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size)); 27805ee799fSJohn Youn memcpy(&p->g_tx_fifo_size[1], 27905ee799fSJohn Youn p_tx_fifo, 28005ee799fSJohn Youn sizeof(p_tx_fifo)); 2819962b62fSJohn Youn } 2829962b62fSJohn Youn 28305ee799fSJohn Youn /** 284245977c9SJohn Youn * dwc2_set_default_params() - Set all core parameters to their 285245977c9SJohn Youn * auto-detected default values. 286323230efSJohn Youn */ 287245977c9SJohn Youn static void dwc2_set_default_params(struct dwc2_hsotg *hsotg) 288323230efSJohn Youn { 28905ee799fSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 29005ee799fSJohn Youn struct dwc2_core_params *p = &hsotg->params; 2916b66ce51SJohn Youn bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH); 292323230efSJohn Youn 293245977c9SJohn Youn dwc2_set_param_otg_cap(hsotg); 294245977c9SJohn Youn dwc2_set_param_phy_type(hsotg); 295245977c9SJohn Youn dwc2_set_param_speed(hsotg); 296245977c9SJohn Youn dwc2_set_param_phy_utmi_width(hsotg); 297245977c9SJohn Youn p->phy_ulpi_ddr = false; 298245977c9SJohn Youn p->phy_ulpi_ext_vbus = false; 299245977c9SJohn Youn 300245977c9SJohn Youn p->enable_dynamic_fifo = hw->enable_dynamic_fifo; 301245977c9SJohn Youn p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo; 302245977c9SJohn Youn p->i2c_enable = hw->i2c_enable; 303245977c9SJohn Youn p->ulpi_fs_ls = false; 304245977c9SJohn Youn p->ts_dline = false; 305245977c9SJohn Youn p->reload_ctl = (hw->snpsid >= DWC2_CORE_REV_2_92a); 306245977c9SJohn Youn p->uframe_sched = true; 307245977c9SJohn Youn p->external_id_pin_ctl = false; 308245977c9SJohn Youn p->hibernation = false; 309245977c9SJohn Youn p->max_packet_count = hw->max_packet_count; 310245977c9SJohn Youn p->max_transfer_size = hw->max_transfer_size; 311245977c9SJohn Youn p->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << GAHBCFG_HBSTLEN_SHIFT; 312245977c9SJohn Youn 3136b66ce51SJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_HOST) || 3146b66ce51SJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) { 315245977c9SJohn Youn p->host_dma = dma_capable; 316245977c9SJohn Youn p->dma_desc_enable = false; 317245977c9SJohn Youn p->dma_desc_fs_enable = false; 318245977c9SJohn Youn p->host_support_fs_ls_low_power = false; 319245977c9SJohn Youn p->host_ls_low_power_phy_clk = false; 320245977c9SJohn Youn p->host_channels = hw->host_channels; 321245977c9SJohn Youn p->host_rx_fifo_size = hw->rx_fifo_size; 322245977c9SJohn Youn p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size; 323245977c9SJohn Youn p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size; 3246b66ce51SJohn Youn } 3256b66ce51SJohn Youn 32605ee799fSJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || 32705ee799fSJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) { 328245977c9SJohn Youn p->g_dma = dma_capable; 329245977c9SJohn Youn p->g_dma_desc = hw->dma_desc_enable; 33005ee799fSJohn Youn 33105ee799fSJohn Youn /* 33205ee799fSJohn Youn * The values for g_rx_fifo_size (2048) and 33305ee799fSJohn Youn * g_np_tx_fifo_size (1024) come from the legacy s3c 33405ee799fSJohn Youn * gadget driver. These defaults have been hard-coded 33505ee799fSJohn Youn * for some time so many platforms depend on these 33605ee799fSJohn Youn * values. Leave them as defaults for now and only 33705ee799fSJohn Youn * auto-detect if the hardware does not support the 33805ee799fSJohn Youn * default. 33905ee799fSJohn Youn */ 340245977c9SJohn Youn p->g_rx_fifo_size = 2048; 341245977c9SJohn Youn p->g_np_tx_fifo_size = 1024; 34205ee799fSJohn Youn dwc2_set_param_tx_fifo_sizes(hsotg); 34305ee799fSJohn Youn } 344323230efSJohn Youn } 345323230efSJohn Youn 346*f9f93cbbSJohn Youn /** 347*f9f93cbbSJohn Youn * dwc2_get_device_properties() - Read in device properties. 348*f9f93cbbSJohn Youn * 349*f9f93cbbSJohn Youn * Read in the device properties and adjust core parameters if needed. 350*f9f93cbbSJohn Youn */ 351*f9f93cbbSJohn Youn static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg) 352*f9f93cbbSJohn Youn { 353*f9f93cbbSJohn Youn struct dwc2_core_params *p = &hsotg->params; 354*f9f93cbbSJohn Youn int num; 355*f9f93cbbSJohn Youn 356*f9f93cbbSJohn Youn if ((hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) || 357*f9f93cbbSJohn Youn (hsotg->dr_mode == USB_DR_MODE_OTG)) { 358*f9f93cbbSJohn Youn device_property_read_u32(hsotg->dev, "g-rx-fifo-size", 359*f9f93cbbSJohn Youn &p->g_rx_fifo_size); 360*f9f93cbbSJohn Youn 361*f9f93cbbSJohn Youn device_property_read_u32(hsotg->dev, "g-np-tx-fifo-size", 362*f9f93cbbSJohn Youn &p->g_np_tx_fifo_size); 363*f9f93cbbSJohn Youn 364*f9f93cbbSJohn Youn num = device_property_read_u32_array(hsotg->dev, 365*f9f93cbbSJohn Youn "g-tx-fifo-size", 366*f9f93cbbSJohn Youn NULL, 0); 367*f9f93cbbSJohn Youn 368*f9f93cbbSJohn Youn if (num > 0) { 369*f9f93cbbSJohn Youn num = min(num, 15); 370*f9f93cbbSJohn Youn memset(p->g_tx_fifo_size, 0, 371*f9f93cbbSJohn Youn sizeof(p->g_tx_fifo_size)); 372*f9f93cbbSJohn Youn device_property_read_u32_array(hsotg->dev, 373*f9f93cbbSJohn Youn "g-tx-fifo-size", 374*f9f93cbbSJohn Youn &p->g_tx_fifo_size[1], 375*f9f93cbbSJohn Youn num); 376*f9f93cbbSJohn Youn } 377*f9f93cbbSJohn Youn } 378*f9f93cbbSJohn Youn } 379*f9f93cbbSJohn Youn 380323230efSJohn Youn /* 381323230efSJohn Youn * Gets host hardware parameters. Forces host mode if not currently in 382323230efSJohn Youn * host mode. Should be called immediately after a core soft reset in 383323230efSJohn Youn * order to get the reset values. 384323230efSJohn Youn */ 385323230efSJohn Youn static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) 386323230efSJohn Youn { 387323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 388323230efSJohn Youn u32 gnptxfsiz; 389323230efSJohn Youn u32 hptxfsiz; 390323230efSJohn Youn bool forced; 391323230efSJohn Youn 392323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 393323230efSJohn Youn return; 394323230efSJohn Youn 395323230efSJohn Youn forced = dwc2_force_mode_if_needed(hsotg, true); 396323230efSJohn Youn 397323230efSJohn Youn gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 398323230efSJohn Youn hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 399323230efSJohn Youn dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 400323230efSJohn Youn dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 401323230efSJohn Youn 402323230efSJohn Youn if (forced) 403323230efSJohn Youn dwc2_clear_force_mode(hsotg); 404323230efSJohn Youn 405323230efSJohn Youn hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 406323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 407323230efSJohn Youn hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 408323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 409323230efSJohn Youn } 410323230efSJohn Youn 411323230efSJohn Youn /* 412323230efSJohn Youn * Gets device hardware parameters. Forces device mode if not 413323230efSJohn Youn * currently in device mode. Should be called immediately after a core 414323230efSJohn Youn * soft reset in order to get the reset values. 415323230efSJohn Youn */ 416323230efSJohn Youn static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) 417323230efSJohn Youn { 418323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 419323230efSJohn Youn bool forced; 420323230efSJohn Youn u32 gnptxfsiz; 421323230efSJohn Youn 422323230efSJohn Youn if (hsotg->dr_mode == USB_DR_MODE_HOST) 423323230efSJohn Youn return; 424323230efSJohn Youn 425323230efSJohn Youn forced = dwc2_force_mode_if_needed(hsotg, false); 426323230efSJohn Youn 427323230efSJohn Youn gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 428323230efSJohn Youn dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 429323230efSJohn Youn 430323230efSJohn Youn if (forced) 431323230efSJohn Youn dwc2_clear_force_mode(hsotg); 432323230efSJohn Youn 433323230efSJohn Youn hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 434323230efSJohn Youn FIFOSIZE_DEPTH_SHIFT; 435323230efSJohn Youn } 436323230efSJohn Youn 437323230efSJohn Youn /** 438323230efSJohn Youn * During device initialization, read various hardware configuration 439323230efSJohn Youn * registers and interpret the contents. 440323230efSJohn Youn */ 441323230efSJohn Youn int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) 442323230efSJohn Youn { 443323230efSJohn Youn struct dwc2_hw_params *hw = &hsotg->hw_params; 444323230efSJohn Youn unsigned int width; 445323230efSJohn Youn u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; 446323230efSJohn Youn u32 grxfsiz; 447323230efSJohn Youn 448323230efSJohn Youn /* 449323230efSJohn Youn * Attempt to ensure this device is really a DWC_otg Controller. 450323230efSJohn Youn * Read and verify the GSNPSID register contents. The value should be 451323230efSJohn Youn * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", 452323230efSJohn Youn * as in "OTG version 2.xx" or "OTG version 3.xx". 453323230efSJohn Youn */ 454323230efSJohn Youn hw->snpsid = dwc2_readl(hsotg->regs + GSNPSID); 455323230efSJohn Youn if ((hw->snpsid & 0xfffff000) != 0x4f542000 && 4561e6b98ebSVardan Mikayelyan (hw->snpsid & 0xfffff000) != 0x4f543000 && 4571e6b98ebSVardan Mikayelyan (hw->snpsid & 0xffff0000) != 0x55310000 && 4581e6b98ebSVardan Mikayelyan (hw->snpsid & 0xffff0000) != 0x55320000) { 459323230efSJohn Youn dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", 460323230efSJohn Youn hw->snpsid); 461323230efSJohn Youn return -ENODEV; 462323230efSJohn Youn } 463323230efSJohn Youn 464323230efSJohn Youn dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", 465323230efSJohn Youn hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 466323230efSJohn Youn hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 467323230efSJohn Youn 468323230efSJohn Youn hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); 469323230efSJohn Youn hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 470323230efSJohn Youn hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); 471323230efSJohn Youn hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 472323230efSJohn Youn grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 473323230efSJohn Youn 474323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); 475323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); 476323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); 477323230efSJohn Youn dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); 478323230efSJohn Youn dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); 479323230efSJohn Youn 480323230efSJohn Youn /* 481323230efSJohn Youn * Host specific hardware parameters. Reading these parameters 482323230efSJohn Youn * requires the controller to be in host mode. The mode will 483323230efSJohn Youn * be forced, if necessary, to read these values. 484323230efSJohn Youn */ 485323230efSJohn Youn dwc2_get_host_hwparams(hsotg); 486323230efSJohn Youn dwc2_get_dev_hwparams(hsotg); 487323230efSJohn Youn 488323230efSJohn Youn /* hwcfg1 */ 489323230efSJohn Youn hw->dev_ep_dirs = hwcfg1; 490323230efSJohn Youn 491323230efSJohn Youn /* hwcfg2 */ 492323230efSJohn Youn hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> 493323230efSJohn Youn GHWCFG2_OP_MODE_SHIFT; 494323230efSJohn Youn hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 495323230efSJohn Youn GHWCFG2_ARCHITECTURE_SHIFT; 496323230efSJohn Youn hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); 497323230efSJohn Youn hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> 498323230efSJohn Youn GHWCFG2_NUM_HOST_CHAN_SHIFT); 499323230efSJohn Youn hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> 500323230efSJohn Youn GHWCFG2_HS_PHY_TYPE_SHIFT; 501323230efSJohn Youn hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> 502323230efSJohn Youn GHWCFG2_FS_PHY_TYPE_SHIFT; 503323230efSJohn Youn hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> 504323230efSJohn Youn GHWCFG2_NUM_DEV_EP_SHIFT; 505323230efSJohn Youn hw->nperio_tx_q_depth = 506323230efSJohn Youn (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> 507323230efSJohn Youn GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; 508323230efSJohn Youn hw->host_perio_tx_q_depth = 509323230efSJohn Youn (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> 510323230efSJohn Youn GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; 511323230efSJohn Youn hw->dev_token_q_depth = 512323230efSJohn Youn (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> 513323230efSJohn Youn GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; 514323230efSJohn Youn 515323230efSJohn Youn /* hwcfg3 */ 516323230efSJohn Youn width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> 517323230efSJohn Youn GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; 518323230efSJohn Youn hw->max_transfer_size = (1 << (width + 11)) - 1; 519323230efSJohn Youn width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> 520323230efSJohn Youn GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; 521323230efSJohn Youn hw->max_packet_count = (1 << (width + 4)) - 1; 522323230efSJohn Youn hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); 523323230efSJohn Youn hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> 524323230efSJohn Youn GHWCFG3_DFIFO_DEPTH_SHIFT; 525323230efSJohn Youn 526323230efSJohn Youn /* hwcfg4 */ 527323230efSJohn Youn hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); 528323230efSJohn Youn hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> 529323230efSJohn Youn GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; 530323230efSJohn Youn hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); 531323230efSJohn Youn hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); 532323230efSJohn Youn hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> 533323230efSJohn Youn GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; 534323230efSJohn Youn 535323230efSJohn Youn /* fifo sizes */ 536d1531319SJohn Youn hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 537323230efSJohn Youn GRXFSIZ_DEPTH_SHIFT; 538323230efSJohn Youn 539323230efSJohn Youn dev_dbg(hsotg->dev, "Detected values from hardware:\n"); 540323230efSJohn Youn dev_dbg(hsotg->dev, " op_mode=%d\n", 541323230efSJohn Youn hw->op_mode); 542323230efSJohn Youn dev_dbg(hsotg->dev, " arch=%d\n", 543323230efSJohn Youn hw->arch); 544323230efSJohn Youn dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", 545323230efSJohn Youn hw->dma_desc_enable); 546323230efSJohn Youn dev_dbg(hsotg->dev, " power_optimized=%d\n", 547323230efSJohn Youn hw->power_optimized); 548323230efSJohn Youn dev_dbg(hsotg->dev, " i2c_enable=%d\n", 549323230efSJohn Youn hw->i2c_enable); 550323230efSJohn Youn dev_dbg(hsotg->dev, " hs_phy_type=%d\n", 551323230efSJohn Youn hw->hs_phy_type); 552323230efSJohn Youn dev_dbg(hsotg->dev, " fs_phy_type=%d\n", 553323230efSJohn Youn hw->fs_phy_type); 554323230efSJohn Youn dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n", 555323230efSJohn Youn hw->utmi_phy_data_width); 556323230efSJohn Youn dev_dbg(hsotg->dev, " num_dev_ep=%d\n", 557323230efSJohn Youn hw->num_dev_ep); 558323230efSJohn Youn dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", 559323230efSJohn Youn hw->num_dev_perio_in_ep); 560323230efSJohn Youn dev_dbg(hsotg->dev, " host_channels=%d\n", 561323230efSJohn Youn hw->host_channels); 562323230efSJohn Youn dev_dbg(hsotg->dev, " max_transfer_size=%d\n", 563323230efSJohn Youn hw->max_transfer_size); 564323230efSJohn Youn dev_dbg(hsotg->dev, " max_packet_count=%d\n", 565323230efSJohn Youn hw->max_packet_count); 566323230efSJohn Youn dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", 567323230efSJohn Youn hw->nperio_tx_q_depth); 568323230efSJohn Youn dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", 569323230efSJohn Youn hw->host_perio_tx_q_depth); 570323230efSJohn Youn dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", 571323230efSJohn Youn hw->dev_token_q_depth); 572323230efSJohn Youn dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", 573323230efSJohn Youn hw->enable_dynamic_fifo); 574323230efSJohn Youn dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", 575323230efSJohn Youn hw->en_multiple_tx_fifo); 576323230efSJohn Youn dev_dbg(hsotg->dev, " total_fifo_size=%d\n", 577323230efSJohn Youn hw->total_fifo_size); 578d1531319SJohn Youn dev_dbg(hsotg->dev, " rx_fifo_size=%d\n", 579d1531319SJohn Youn hw->rx_fifo_size); 580323230efSJohn Youn dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", 581323230efSJohn Youn hw->host_nperio_tx_fifo_size); 582323230efSJohn Youn dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", 583323230efSJohn Youn hw->host_perio_tx_fifo_size); 584323230efSJohn Youn dev_dbg(hsotg->dev, "\n"); 585323230efSJohn Youn 586323230efSJohn Youn return 0; 587323230efSJohn Youn } 588323230efSJohn Youn 589334bbd4eSJohn Youn int dwc2_init_params(struct dwc2_hsotg *hsotg) 590334bbd4eSJohn Youn { 591245977c9SJohn Youn dwc2_set_default_params(hsotg); 592*f9f93cbbSJohn Youn dwc2_get_device_properties(hsotg); 593334bbd4eSJohn Youn 594334bbd4eSJohn Youn return 0; 595334bbd4eSJohn Youn } 596