Home | History | Annotate | Line # | Download | only in dist
dwc2_core.h revision 1.5.12.1
      1 /*	$NetBSD: dwc2_core.h,v 1.5.12.1 2015/09/22 12:06:06 skrll Exp $	*/
      2 
      3 /*
      4  * core.h - DesignWare HS OTG Controller common declarations
      5  *
      6  * Copyright (C) 2004-2013 Synopsys, Inc.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions, and the following disclaimer,
     13  *    without modification.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. The names of the above-listed copyright holders may not be used
     18  *    to endorse or promote products derived from this software without
     19  *    specific prior written permission.
     20  *
     21  * ALTERNATIVELY, this software may be distributed under the terms of the
     22  * GNU General Public License ("GPL") as published by the Free Software
     23  * Foundation; either version 2 of the License, or (at your option) any
     24  * later version.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     27  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     28  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     33  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     36  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef __DWC2_CORE_H__
     40 #define __DWC2_CORE_H__
     41 
     42 #include <sys/stdint.h>
     43 #include <sys/workqueue.h>
     44 #include <sys/pool.h>
     45 #include <sys/queue.h>
     46 #include <sys/device.h>
     47 
     48 #include <machine/intr.h>
     49 #include <sys/bus.h>
     50 
     51 #include "dwc2_hw.h"
     52 
     53 /* Maximum number of Endpoints/HostChannels */
     54 #define MAX_EPS_CHANNELS	16
     55 
     56 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
     57 
     58 /* s3c-hsotg declarations */
     59 static const char * const s3c_hsotg_supply_names[] = {
     60 	"vusb_d",               /* digital USB supply, 1.2V */
     61 	"vusb_a",               /* analog USB supply, 1.1V */
     62 };
     63 
     64 /*
     65  * EP0_MPS_LIMIT
     66  *
     67  * Unfortunately there seems to be a limit of the amount of data that can
     68  * be transferred by IN transactions on EP0. This is either 127 bytes or 3
     69  * packets (which practically means 1 packet and 63 bytes of data) when the
     70  * MPS is set to 64.
     71  *
     72  * This means if we are wanting to move >127 bytes of data, we need to
     73  * split the transactions up, but just doing one packet at a time does
     74  * not work (this may be an implicit DATA0 PID on first packet of the
     75  * transaction) and doing 2 packets is outside the controller's limits.
     76  *
     77  * If we try to lower the MPS size for EP0, then no transfers work properly
     78  * for EP0, and the system will fail basic enumeration. As no cause for this
     79  * has currently been found, we cannot support any large IN transfers for
     80  * EP0.
     81  */
     82 #define EP0_MPS_LIMIT   64
     83 
     84 struct dwc2_hsotg;
     85 struct s3c_hsotg_req;
     86 
     87 /**
     88  * struct s3c_hsotg_ep - driver endpoint definition.
     89  * @ep: The gadget layer representation of the endpoint.
     90  * @name: The driver generated name for the endpoint.
     91  * @queue: Queue of requests for this endpoint.
     92  * @parent: Reference back to the parent device structure.
     93  * @req: The current request that the endpoint is processing. This is
     94  *       used to indicate an request has been loaded onto the endpoint
     95  *       and has yet to be completed (maybe due to data move, or simply
     96  *       awaiting an ack from the core all the data has been completed).
     97  * @debugfs: File entry for debugfs file for this endpoint.
     98  * @lock: State lock to protect contents of endpoint.
     99  * @dir_in: Set to true if this endpoint is of the IN direction, which
    100  *          means that it is sending data to the Host.
    101  * @index: The index for the endpoint registers.
    102  * @mc: Multi Count - number of transactions per microframe
    103  * @interval - Interval for periodic endpoints
    104  * @name: The name array passed to the USB core.
    105  * @halted: Set if the endpoint has been halted.
    106  * @periodic: Set if this is a periodic ep, such as Interrupt
    107  * @isochronous: Set if this is a isochronous ep
    108  * @send_zlp: Set if we need to send a zero-length packet.
    109  * @total_data: The total number of data bytes done.
    110  * @fifo_size: The size of the FIFO (for periodic IN endpoints)
    111  * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
    112  * @last_load: The offset of data for the last start of request.
    113  * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
    114  *
    115  * This is the driver's state for each registered enpoint, allowing it
    116  * to keep track of transactions that need doing. Each endpoint has a
    117  * lock to protect the state, to try and avoid using an overall lock
    118  * for the host controller as much as possible.
    119  *
    120  * For periodic IN endpoints, we have fifo_size and fifo_load to try
    121  * and keep track of the amount of data in the periodic FIFO for each
    122  * of these as we don't have a status register that tells us how much
    123  * is in each of them. (note, this may actually be useless information
    124  * as in shared-fifo mode periodic in acts like a single-frame packet
    125  * buffer than a fifo)
    126  */
    127 struct s3c_hsotg_ep {
    128 	struct usb_ep           ep;
    129 	struct list_head        queue;
    130 	struct dwc2_hsotg       *parent;
    131 	struct s3c_hsotg_req    *req;
    132 	struct dentry           *debugfs;
    133 
    134 	unsigned long           total_data;
    135 	unsigned int            size_loaded;
    136 	unsigned int            last_load;
    137 	unsigned int            fifo_load;
    138 	unsigned short          fifo_size;
    139 	unsigned short		fifo_index;
    140 
    141 	unsigned char           dir_in;
    142 	unsigned char           index;
    143 	unsigned char           mc;
    144 	unsigned char           interval;
    145 
    146 	unsigned int            halted:1;
    147 	unsigned int            periodic:1;
    148 	unsigned int            isochronous:1;
    149 	unsigned int            send_zlp:1;
    150 
    151 	char                    name[10];
    152 };
    153 
    154 /**
    155  * struct s3c_hsotg_req - data transfer request
    156  * @req: The USB gadget request
    157  * @queue: The list of requests for the endpoint this is queued for.
    158  * @saved_req_buf: variable to save req.buf when bounce buffers are used.
    159  */
    160 struct s3c_hsotg_req {
    161 	struct usb_request      req;
    162 	struct list_head        queue;
    163 	void *saved_req_buf;
    164 };
    165 
    166 #define call_gadget(_hs, _entry) \
    167 do { \
    168 	if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
    169 		(_hs)->driver && (_hs)->driver->_entry) { \
    170 		spin_unlock(&_hs->lock); \
    171 		(_hs)->driver->_entry(&(_hs)->gadget); \
    172 		spin_lock(&_hs->lock); \
    173 	} \
    174 } while (0)
    175 #else
    176 #define call_gadget(_hs, _entry)	do {} while (0)
    177 #endif
    178 
    179 struct dwc2_hsotg;
    180 struct dwc2_host_chan;
    181 
    182 /* Device States */
    183 enum dwc2_lx_state {
    184 	DWC2_L0,	/* On state */
    185 	DWC2_L1,	/* LPM sleep state */
    186 	DWC2_L2,	/* USB suspend state */
    187 	DWC2_L3,	/* Off state */
    188 };
    189 
    190 /*
    191  * Gadget periodic tx fifo sizes as used by legacy driver
    192  * EP0 is not included
    193  */
    194 #define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
    195 					   768, 0, 0, 0, 0, 0, 0, 0}
    196 
    197 /* Gadget ep0 states */
    198 enum dwc2_ep0_state {
    199 	DWC2_EP0_SETUP,
    200 	DWC2_EP0_DATA_IN,
    201 	DWC2_EP0_DATA_OUT,
    202 	DWC2_EP0_STATUS_IN,
    203 	DWC2_EP0_STATUS_OUT,
    204 };
    205 
    206 /**
    207  * struct dwc2_core_params - Parameters for configuring the core
    208  *
    209  * @otg_cap:            Specifies the OTG capabilities.
    210  *                       0 - HNP and SRP capable
    211  *                       1 - SRP Only capable
    212  *                       2 - No HNP/SRP capable (always available)
    213  *                      Defaults to best available option (0, 1, then 2)
    214  * @otg_ver:            OTG version supported
    215  *                       0 - 1.3 (default)
    216  *                       1 - 2.0
    217  * @dma_enable:         Specifies whether to use slave or DMA mode for accessing
    218  *                      the data FIFOs. The driver will automatically detect the
    219  *                      value for this parameter if none is specified.
    220  *                       0 - Slave (always available)
    221  *                       1 - DMA (default, if available)
    222  * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
    223  *                      address DMA mode or descriptor DMA mode for accessing
    224  *                      the data FIFOs. The driver will automatically detect the
    225  *                      value for this if none is specified.
    226  *                       0 - Address DMA
    227  *                       1 - Descriptor DMA (default, if available)
    228  * @speed:              Specifies the maximum speed of operation in host and
    229  *                      device mode. The actual speed depends on the speed of
    230  *                      the attached device and the value of phy_type.
    231  *                       0 - High Speed
    232  *                           (default when phy_type is UTMI+ or ULPI)
    233  *                       1 - Full Speed
    234  *                           (default when phy_type is Full Speed)
    235  * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
    236  *                       1 - Allow dynamic FIFO sizing (default, if available)
    237  * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
    238  *                      are enabled
    239  * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
    240  *                      dynamic FIFO sizing is enabled
    241  *                       16 to 32768
    242  *                      Actual maximum value is autodetected and also
    243  *                      the default.
    244  * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
    245  *                      in host mode when dynamic FIFO sizing is enabled
    246  *                       16 to 32768
    247  *                      Actual maximum value is autodetected and also
    248  *                      the default.
    249  * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
    250  *                      host mode when dynamic FIFO sizing is enabled
    251  *                       16 to 32768
    252  *                      Actual maximum value is autodetected and also
    253  *                      the default.
    254  * @max_transfer_size:  The maximum transfer size supported, in bytes
    255  *                       2047 to 65,535
    256  *                      Actual maximum value is autodetected and also
    257  *                      the default.
    258  * @max_packet_count:   The maximum number of packets in a transfer
    259  *                       15 to 511
    260  *                      Actual maximum value is autodetected and also
    261  *                      the default.
    262  * @host_channels:      The number of host channel registers to use
    263  *                       1 to 16
    264  *                      Actual maximum value is autodetected and also
    265  *                      the default.
    266  * @phy_type:           Specifies the type of PHY interface to use. By default,
    267  *                      the driver will automatically detect the phy_type.
    268  *                       0 - Full Speed Phy
    269  *                       1 - UTMI+ Phy
    270  *                       2 - ULPI Phy
    271  *                      Defaults to best available option (2, 1, then 0)
    272  * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
    273  *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
    274  *                      ULPI phy_type, this parameter indicates the data width
    275  *                      between the MAC and the ULPI Wrapper.) Also, this
    276  *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
    277  *                      parameter was set to "8 and 16 bits", meaning that the
    278  *                      core has been configured to work at either data path
    279  *                      width.
    280  *                       8 or 16 (default 16 if available)
    281  * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
    282  *                      data rate. This parameter is only applicable if phy_type
    283  *                      is ULPI.
    284  *                       0 - single data rate ULPI interface with 8 bit wide
    285  *                           data bus (default)
    286  *                       1 - double data rate ULPI interface with 4 bit wide
    287  *                           data bus
    288  * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
    289  *                      external supply to drive the VBus
    290  *                       0 - Internal supply (default)
    291  *                       1 - External supply
    292  * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
    293  *                      speed PHY. This parameter is only applicable if phy_type
    294  *                      is FS.
    295  *                       0 - No (default)
    296  *                       1 - Yes
    297  * @ulpi_fs_ls:         Make ULPI phy operate in FS/LS mode only
    298  *                       0 - No (default)
    299  *                       1 - Yes
    300  * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
    301  *                      when attached to a Full Speed or Low Speed device in
    302  *                      host mode.
    303  *                       0 - Don't support low power mode (default)
    304  *                       1 - Support low power mode
    305  * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
    306  *                      when connected to a Low Speed device in host
    307  *                      mode. This parameter is applicable only if
    308  *                      host_support_fs_ls_low_power is enabled.
    309  *                       0 - 48 MHz
    310  *                           (default when phy_type is UTMI+ or ULPI)
    311  *                       1 - 6 MHz
    312  *                           (default when phy_type is Full Speed)
    313  * @ts_dline:           Enable Term Select Dline pulsing
    314  *                       0 - No (default)
    315  *                       1 - Yes
    316  * @reload_ctl:         Allow dynamic reloading of HFIR register during runtime
    317  *                       0 - No (default for core < 2.92a)
    318  *                       1 - Yes (default for core >= 2.92a)
    319  * @ahbcfg:             This field allows the default value of the GAHBCFG
    320  *                      register to be overridden
    321  *                       -1         - GAHBCFG value will be set to 0x06
    322  *                                    (INCR4, default)
    323  *                       all others - GAHBCFG value will be overridden with
    324  *                                    this value
    325  *                      Not all bits can be controlled like this, the
    326  *                      bits defined by GAHBCFG_CTRL_MASK are controlled
    327  *                      by the driver and are ignored in this
    328  *                      configuration value.
    329  * @uframe_sched:       True to enable the microframe scheduler
    330  * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
    331  *                      Disable CONIDSTSCHNG controller interrupt in such
    332  *                      case.
    333  *                      0 - No (default)
    334  *                      1 - Yes
    335  * @hibernation:	Specifies whether the controller support hibernation.
    336  *			If hibernation is enabled, the controller will enter
    337  *			hibernation in both peripheral and host mode when
    338  *			needed.
    339  *			0 - No (default)
    340  *			1 - Yes
    341  *
    342  * The following parameters may be specified when starting the module. These
    343  * parameters define how the DWC_otg controller should be configured. A
    344  * value of -1 (or any other out of range value) for any parameter means
    345  * to read the value from hardware (if possible) or use the builtin
    346  * default described above.
    347  */
    348 struct dwc2_core_params {
    349 	/*
    350 	 * Don't add any non-int members here, this will break
    351 	 * dwc2_set_all_params!
    352 	 */
    353 	int otg_cap;
    354 	int otg_ver;
    355 	int dma_enable;
    356 	int dma_desc_enable;
    357 	int speed;
    358 	int enable_dynamic_fifo;
    359 	int en_multiple_tx_fifo;
    360 	int host_rx_fifo_size;
    361 	int host_nperio_tx_fifo_size;
    362 	int host_perio_tx_fifo_size;
    363 	int max_transfer_size;
    364 	int max_packet_count;
    365 	int host_channels;
    366 	int phy_type;
    367 	int phy_utmi_width;
    368 	int phy_ulpi_ddr;
    369 	int phy_ulpi_ext_vbus;
    370 	int i2c_enable;
    371 	int ulpi_fs_ls;
    372 	int host_support_fs_ls_low_power;
    373 	int host_ls_low_power_phy_clk;
    374 	int ts_dline;
    375 	int reload_ctl;
    376 	int ahbcfg;
    377 	int uframe_sched;
    378 	int external_id_pin_ctl;
    379 	int hibernation;
    380 };
    381 
    382 /**
    383  * struct dwc2_hw_params - Autodetected parameters.
    384  *
    385  * These parameters are the various parameters read from hardware
    386  * registers during initialization. They typically contain the best
    387  * supported or maximum value that can be configured in the
    388  * corresponding dwc2_core_params value.
    389  *
    390  * The values that are not in dwc2_core_params are documented below.
    391  *
    392  * @op_mode             Mode of Operation
    393  *                       0 - HNP- and SRP-Capable OTG (Host & Device)
    394  *                       1 - SRP-Capable OTG (Host & Device)
    395  *                       2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
    396  *                       3 - SRP-Capable Device
    397  *                       4 - Non-OTG Device
    398  *                       5 - SRP-Capable Host
    399  *                       6 - Non-OTG Host
    400  * @arch                Architecture
    401  *                       0 - Slave only
    402  *                       1 - External DMA
    403  *                       2 - Internal DMA
    404  * @power_optimized     Are power optimizations enabled?
    405  * @num_dev_ep          Number of device endpoints available
    406  * @num_dev_perio_in_ep Number of device periodic IN endpoints
    407  *                      available
    408  * @dev_token_q_depth   Device Mode IN Token Sequence Learning Queue
    409  *                      Depth
    410  *                       0 to 30
    411  * @host_perio_tx_q_depth
    412  *                      Host Mode Periodic Request Queue Depth
    413  *                       2, 4 or 8
    414  * @nperio_tx_q_depth
    415  *                      Non-Periodic Request Queue Depth
    416  *                       2, 4 or 8
    417  * @hs_phy_type         High-speed PHY interface type
    418  *                       0 - High-speed interface not supported
    419  *                       1 - UTMI+
    420  *                       2 - ULPI
    421  *                       3 - UTMI+ and ULPI
    422  * @fs_phy_type         Full-speed PHY interface type
    423  *                       0 - Full speed interface not supported
    424  *                       1 - Dedicated full speed interface
    425  *                       2 - FS pins shared with UTMI+ pins
    426  *                       3 - FS pins shared with ULPI pins
    427  * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
    428  * @utmi_phy_data_width UTMI+ PHY data width
    429  *                       0 - 8 bits
    430  *                       1 - 16 bits
    431  *                       2 - 8 or 16 bits
    432  * @snpsid:             Value from SNPSID register
    433  */
    434 struct dwc2_hw_params {
    435 	unsigned op_mode:3;
    436 	unsigned arch:2;
    437 	unsigned dma_desc_enable:1;
    438 	unsigned enable_dynamic_fifo:1;
    439 	unsigned en_multiple_tx_fifo:1;
    440 	unsigned host_rx_fifo_size:16;
    441 	unsigned host_nperio_tx_fifo_size:16;
    442 	unsigned host_perio_tx_fifo_size:16;
    443 	unsigned nperio_tx_q_depth:3;
    444 	unsigned host_perio_tx_q_depth:3;
    445 	unsigned dev_token_q_depth:5;
    446 	unsigned max_transfer_size:26;
    447 	unsigned max_packet_count:11;
    448 	unsigned host_channels:5;
    449 	unsigned hs_phy_type:2;
    450 	unsigned fs_phy_type:2;
    451 	unsigned i2c_enable:1;
    452 	unsigned num_dev_ep:4;
    453 	unsigned num_dev_perio_in_ep:4;
    454 	unsigned total_fifo_size:16;
    455 	unsigned power_optimized:1;
    456 	unsigned utmi_phy_data_width:2;
    457 	u32 snpsid;
    458 };
    459 
    460 /* Size of control and EP0 buffers */
    461 #define DWC2_CTRL_BUFF_SIZE 8
    462 
    463 /**
    464  * struct dwc2_gregs_backup - Holds global registers state before entering partial
    465  * power down
    466  * @gotgctl:		Backup of GOTGCTL register
    467  * @gintmsk:		Backup of GINTMSK register
    468  * @gahbcfg:		Backup of GAHBCFG register
    469  * @gusbcfg:		Backup of GUSBCFG register
    470  * @grxfsiz:		Backup of GRXFSIZ register
    471  * @gnptxfsiz:		Backup of GNPTXFSIZ register
    472  * @gi2cctl:		Backup of GI2CCTL register
    473  * @hptxfsiz:		Backup of HPTXFSIZ register
    474  * @gdfifocfg:		Backup of GDFIFOCFG register
    475  * @dtxfsiz:		Backup of DTXFSIZ registers for each endpoint
    476  * @gpwrdn:		Backup of GPWRDN register
    477  */
    478 struct dwc2_gregs_backup {
    479 	u32 gotgctl;
    480 	u32 gintmsk;
    481 	u32 gahbcfg;
    482 	u32 gusbcfg;
    483 	u32 grxfsiz;
    484 	u32 gnptxfsiz;
    485 	u32 gi2cctl;
    486 	u32 hptxfsiz;
    487 	u32 pcgcctl;
    488 	u32 gdfifocfg;
    489 	u32 dtxfsiz[MAX_EPS_CHANNELS];
    490 	u32 gpwrdn;
    491 	bool valid;
    492 };
    493 
    494 /**
    495  * struct  dwc2_dregs_backup - Holds device registers state before entering partial
    496  * power down
    497  * @dcfg:		Backup of DCFG register
    498  * @dctl:		Backup of DCTL register
    499  * @daintmsk:		Backup of DAINTMSK register
    500  * @diepmsk:		Backup of DIEPMSK register
    501  * @doepmsk:		Backup of DOEPMSK register
    502  * @diepctl:		Backup of DIEPCTL register
    503  * @dieptsiz:		Backup of DIEPTSIZ register
    504  * @diepdma:		Backup of DIEPDMA register
    505  * @doepctl:		Backup of DOEPCTL register
    506  * @doeptsiz:		Backup of DOEPTSIZ register
    507  * @doepdma:		Backup of DOEPDMA register
    508  */
    509 struct dwc2_dregs_backup {
    510 	u32 dcfg;
    511 	u32 dctl;
    512 	u32 daintmsk;
    513 	u32 diepmsk;
    514 	u32 doepmsk;
    515 	u32 diepctl[MAX_EPS_CHANNELS];
    516 	u32 dieptsiz[MAX_EPS_CHANNELS];
    517 	u32 diepdma[MAX_EPS_CHANNELS];
    518 	u32 doepctl[MAX_EPS_CHANNELS];
    519 	u32 doeptsiz[MAX_EPS_CHANNELS];
    520 	u32 doepdma[MAX_EPS_CHANNELS];
    521 	bool valid;
    522 };
    523 
    524 /**
    525  * struct  dwc2_hregs_backup - Holds host registers state before entering partial
    526  * power down
    527  * @hcfg:		Backup of HCFG register
    528  * @haintmsk:		Backup of HAINTMSK register
    529  * @hcintmsk:		Backup of HCINTMSK register
    530  * @hptr0:		Backup of HPTR0 register
    531  * @hfir:		Backup of HFIR register
    532  */
    533 struct dwc2_hregs_backup {
    534 	u32 hcfg;
    535 	u32 haintmsk;
    536 	u32 hcintmsk[MAX_EPS_CHANNELS];
    537 	u32 hprt0;
    538 	u32 hfir;
    539 	bool valid;
    540 };
    541 
    542 /**
    543  * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
    544  * and periodic schedules
    545  *
    546  * These are common for both host and peripheral modes:
    547  *
    548  * @dev:                The struct device pointer
    549  * @regs:		Pointer to controller regs
    550  * @hw_params:          Parameters that were autodetected from the
    551  *                      hardware registers
    552  * @core_params:	Parameters that define how the core should be configured
    553  * @op_state:           The operational State, during transitions (a_host=>
    554  *                      a_peripheral and b_device=>b_host) this may not match
    555  *                      the core, but allows the software to determine
    556  *                      transitions
    557  * @dr_mode:            Requested mode of operation, one of following:
    558  *                      - USB_DR_MODE_PERIPHERAL
    559  *                      - USB_DR_MODE_HOST
    560  *                      - USB_DR_MODE_OTG
    561  * @lock:		Spinlock that protects all the driver data structures
    562  * @priv:		Stores a pointer to the struct usb_hcd
    563  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
    564  *                      transfer are in process of being queued
    565  * @srp_success:        Stores status of SRP request in the case of a FS PHY
    566  *                      with an I2C interface
    567  * @wq_otg:             Workqueue object used for handling of some interrupts
    568  * @wf_otg:             Work object for handling Connector ID Status Change
    569  *                      interrupt
    570  * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
    571  * @lx_state:           Lx state of connected device
    572  * @gregs_backup: Backup of global registers during suspend
    573  * @dregs_backup: Backup of device registers during suspend
    574  * @hregs_backup: Backup of host registers during suspend
    575  *
    576  * These are for host mode:
    577  *
    578  * @flags:              Flags for handling root port state changes
    579  * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
    580  *                      Transfers associated with these QHs are not currently
    581  *                      assigned to a host channel.
    582  * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
    583  *                      Transfers associated with these QHs are currently
    584  *                      assigned to a host channel.
    585  * @non_periodic_qh_ptr: Pointer to next QH to process in the active
    586  *                      non-periodic schedule
    587  * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
    588  *                      list of QHs for periodic transfers that are _not_
    589  *                      scheduled for the next frame. Each QH in the list has an
    590  *                      interval counter that determines when it needs to be
    591  *                      scheduled for execution. This scheduling mechanism
    592  *                      allows only a simple calculation for periodic bandwidth
    593  *                      used (i.e. must assume that all periodic transfers may
    594  *                      need to execute in the same frame). However, it greatly
    595  *                      simplifies scheduling and should be sufficient for the
    596  *                      vast majority of OTG hosts, which need to connect to a
    597  *                      small number of peripherals at one time. Items move from
    598  *                      this list to periodic_sched_ready when the QH interval
    599  *                      counter is 0 at SOF.
    600  * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
    601  *                      the next frame, but have not yet been assigned to host
    602  *                      channels. Items move from this list to
    603  *                      periodic_sched_assigned as host channels become
    604  *                      available during the current frame.
    605  * @periodic_sched_assigned: List of periodic QHs to be executed in the next
    606  *                      frame that are assigned to host channels. Items move
    607  *                      from this list to periodic_sched_queued as the
    608  *                      transactions for the QH are queued to the DWC_otg
    609  *                      controller.
    610  * @periodic_sched_queued: List of periodic QHs that have been queued for
    611  *                      execution. Items move from this list to either
    612  *                      periodic_sched_inactive or periodic_sched_ready when the
    613  *                      channel associated with the transfer is released. If the
    614  *                      interval for the QH is 1, the item moves to
    615  *                      periodic_sched_ready because it must be rescheduled for
    616  *                      the next frame. Otherwise, the item moves to
    617  *                      periodic_sched_inactive.
    618  * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
    619  *                      This value is in microseconds per (micro)frame. The
    620  *                      assumption is that all periodic transfers may occur in
    621  *                      the same (micro)frame.
    622  * @frame_usecs:        Internal variable used by the microframe scheduler
    623  * @frame_number:       Frame number read from the core at SOF. The value ranges
    624  *                      from 0 to HFNUM_MAX_FRNUM.
    625  * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
    626  *                      SOF enable/disable.
    627  * @free_hc_list:       Free host channels in the controller. This is a list of
    628  *                      struct dwc2_host_chan items.
    629  * @periodic_channels:  Number of host channels assigned to periodic transfers.
    630  *                      Currently assuming that there is a dedicated host
    631  *                      channel for each periodic transaction and at least one
    632  *                      host channel is available for non-periodic transactions.
    633  * @non_periodic_channels: Number of host channels assigned to non-periodic
    634  *                      transfers
    635  * @available_host_channels Number of host channels available for the microframe
    636  *                      scheduler to use
    637  * @hc_ptr_array:       Array of pointers to the host channel descriptors.
    638  *                      Allows accessing a host channel descriptor given the
    639  *                      host channel number. This is useful in interrupt
    640  *                      handlers.
    641  * @status_buf:         Buffer used for data received during the status phase of
    642  *                      a control transfer.
    643  * @status_buf_dma:     DMA address for status_buf
    644  * @start_work:         Delayed work for handling host A-cable connection
    645  * @reset_work:         Delayed work for handling a port reset
    646  * @otg_port:           OTG port number
    647  * @frame_list:         Frame list
    648  * @frame_list_dma:     Frame list DMA address
    649  *
    650  * These are for peripheral mode:
    651  *
    652  * @driver:             USB gadget driver
    653  * @phy:                The otg phy transceiver structure for phy control.
    654  * @uphy:               The otg phy transceiver structure for old USB phy control.
    655  * @plat:               The platform specific configuration data. This can be removed once
    656  *                      all SoCs support usb transceiver.
    657  * @supplies:           Definition of USB power supplies
    658  * @phyif:              PHY interface width
    659  * @dedicated_fifos:    Set if the hardware has dedicated IN-EP fifos.
    660  * @num_of_eps:         Number of available EPs (excluding EP0)
    661  * @debug_root:         Root directrory for debugfs.
    662  * @debug_file:         Main status file for debugfs.
    663  * @debug_testmode:     Testmode status file for debugfs.
    664  * @debug_fifo:         FIFO status file for debugfs.
    665  * @ep0_reply:          Request used for ep0 reply.
    666  * @ep0_buff:           Buffer for EP0 reply data, if needed.
    667  * @ctrl_buff:          Buffer for EP0 control requests.
    668  * @ctrl_req:           Request for EP0 control packets.
    669  * @ep0_state:          EP0 control transfers state
    670  * @test_mode:          USB test mode requested by the host
    671  * @last_rst:           Time of last reset
    672  * @eps:                The endpoints being supplied to the gadget framework
    673  * @g_using_dma:          Indicate if dma usage is enabled
    674  * @g_rx_fifo_sz:         Contains rx fifo size value
    675  * @g_np_g_tx_fifo_sz:      Contains Non-Periodic tx fifo size value
    676  * @g_tx_fifo_sz:         Contains tx fifo size value per endpoints
    677  */
    678 struct dwc2_hsotg {
    679 	device_t dev;
    680 	struct dwc2_softc *hsotg_sc;
    681 	/** Params detected from hardware */
    682 	struct dwc2_hw_params hw_params;
    683 	/** Params to actually use */
    684 	struct dwc2_core_params *core_params;
    685 	enum usb_otg_state op_state;
    686 	enum usb_dr_mode dr_mode;
    687 	unsigned int hcd_enabled:1;
    688 	unsigned int gadget_enabled:1;
    689 
    690 	spinlock_t lock;
    691 	void *priv;
    692 	struct usb_phy *uphy;
    693 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
    694 	struct phy *phy;
    695 	struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)];
    696 
    697 	struct mutex init_mutex;
    698 	int     irq;
    699 	struct clk *clk;
    700 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
    701 
    702 	unsigned int queuing_high_bandwidth:1;
    703 	unsigned int srp_success:1;
    704 
    705 	struct workqueue *wq_otg;
    706 	struct work wf_otg;
    707 	struct callout wkp_timer;
    708 	enum dwc2_lx_state lx_state;
    709 	struct dwc2_gregs_backup gr_backup;
    710 	struct dwc2_dregs_backup dr_backup;
    711 	struct dwc2_hregs_backup hr_backup;
    712 
    713 	struct dentry *debug_root;
    714 	struct debugfs_regset32 *regset;
    715 
    716 	/* DWC OTG HW Release versions */
    717 #define DWC2_CORE_REV_2_71a	0x4f54271a
    718 #define DWC2_CORE_REV_2_90a	0x4f54290a
    719 #define DWC2_CORE_REV_2_92a	0x4f54292a
    720 #define DWC2_CORE_REV_2_94a	0x4f54294a
    721 #define DWC2_CORE_REV_3_00a	0x4f54300a
    722 
    723 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
    724 	union dwc2_hcd_internal_flags {
    725 		u32 d32;
    726 		struct {
    727 			unsigned port_connect_status_change:1;
    728 			unsigned port_connect_status:1;
    729 			unsigned port_reset_change:1;
    730 			unsigned port_enable_change:1;
    731 			unsigned port_suspend_change:1;
    732 			unsigned port_over_current_change:1;
    733 			unsigned port_l1_change:1;
    734 			unsigned reserved:25;
    735 		} b;
    736 	} flags;
    737 
    738 	struct list_head non_periodic_sched_inactive;
    739 	struct list_head non_periodic_sched_active;
    740 	struct list_head *non_periodic_qh_ptr;
    741 	struct list_head periodic_sched_inactive;
    742 	struct list_head periodic_sched_ready;
    743 	struct list_head periodic_sched_assigned;
    744 	struct list_head periodic_sched_queued;
    745 	u16 periodic_usecs;
    746 	u16 frame_usecs[8];
    747 	u16 frame_number;
    748 	u16 periodic_qh_count;
    749 
    750 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
    751 #define FRAME_NUM_ARRAY_SIZE 1000
    752 	u16 last_frame_num;
    753 	u16 *frame_num_array;
    754 	u16 *last_frame_num_array;
    755 	int frame_num_idx;
    756 	int dumped_frame_num_array;
    757 #endif
    758 
    759 	struct list_head free_hc_list;
    760 	int periodic_channels;
    761 	int non_periodic_channels;
    762 	int available_host_channels;
    763 	struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
    764 	usb_dma_t status_buf_usbdma;
    765 	u8 *status_buf;
    766 	dma_addr_t status_buf_dma;
    767 #define DWC2_HCD_STATUS_BUF_SIZE 64
    768 
    769 	struct delayed_work start_work;
    770 	struct delayed_work reset_work;
    771 	u8 otg_port;
    772 	usb_dma_t frame_list_usbdma;
    773 	u32 *frame_list;
    774 	dma_addr_t frame_list_dma;
    775 
    776 #ifdef DEBUG
    777 	u32 frrem_samples;
    778 	u64 frrem_accum;
    779 
    780 	u32 hfnum_7_samples_a;
    781 	u64 hfnum_7_frrem_accum_a;
    782 	u32 hfnum_0_samples_a;
    783 	u64 hfnum_0_frrem_accum_a;
    784 	u32 hfnum_other_samples_a;
    785 	u64 hfnum_other_frrem_accum_a;
    786 
    787 	u32 hfnum_7_samples_b;
    788 	u64 hfnum_7_frrem_accum_b;
    789 	u32 hfnum_0_samples_b;
    790 	u64 hfnum_0_frrem_accum_b;
    791 	u32 hfnum_other_samples_b;
    792 	u64 hfnum_other_frrem_accum_b;
    793 #endif
    794 #endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
    795 
    796 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
    797 	/* Gadget structures */
    798 	struct usb_gadget_driver *driver;
    799 	struct s3c_hsotg_plat *plat;
    800 
    801 	u32 phyif;
    802 	int fifo_mem;
    803 	unsigned int dedicated_fifos:1;
    804 	unsigned char num_of_eps;
    805 	u32 fifo_map;
    806 
    807 	struct usb_request *ep0_reply;
    808 	struct usb_request *ctrl_req;
    809 	void *ep0_buff;
    810 	void *ctrl_buff;
    811 	enum dwc2_ep0_state ep0_state;
    812 	u8 test_mode;
    813 
    814 	struct usb_gadget gadget;
    815 	unsigned int enabled:1;
    816 	unsigned int connected:1;
    817 	unsigned long last_rst;
    818 	struct s3c_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
    819 	struct s3c_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
    820 	u32 g_using_dma;
    821 	u32 g_rx_fifo_sz;
    822 	u32 g_np_g_tx_fifo_sz;
    823 	u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
    824 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
    825 };
    826 
    827 /* Reasons for halting a host channel */
    828 enum dwc2_halt_status {
    829 	DWC2_HC_XFER_NO_HALT_STATUS,
    830 	DWC2_HC_XFER_COMPLETE,
    831 	DWC2_HC_XFER_URB_COMPLETE,
    832 	DWC2_HC_XFER_ACK,
    833 	DWC2_HC_XFER_NAK,
    834 	DWC2_HC_XFER_NYET,
    835 	DWC2_HC_XFER_STALL,
    836 	DWC2_HC_XFER_XACT_ERR,
    837 	DWC2_HC_XFER_FRAME_OVERRUN,
    838 	DWC2_HC_XFER_BABBLE_ERR,
    839 	DWC2_HC_XFER_DATA_TOGGLE_ERR,
    840 	DWC2_HC_XFER_AHB_ERR,
    841 	DWC2_HC_XFER_PERIODIC_INCOMPLETE,
    842 	DWC2_HC_XFER_URB_DEQUEUE,
    843 };
    844 
    845 /*
    846  * The following functions support initialization of the core driver component
    847  * and the DWC_otg controller
    848  */
    849 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
    850 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
    851 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
    852 
    853 /*
    854  * Host core Functions.
    855  * The following functions support managing the DWC_otg controller in host
    856  * mode.
    857  */
    858 extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
    859 extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
    860 			 enum dwc2_halt_status halt_status);
    861 extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
    862 			    struct dwc2_host_chan *chan);
    863 extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
    864 				   struct dwc2_host_chan *chan);
    865 extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
    866 					struct dwc2_host_chan *chan);
    867 extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
    868 				     struct dwc2_host_chan *chan);
    869 extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
    870 			    struct dwc2_host_chan *chan);
    871 extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
    872 extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
    873 
    874 extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
    875 extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
    876 
    877 /*
    878  * Common core Functions.
    879  * The following functions support managing the DWC_otg controller in either
    880  * device or host mode.
    881  */
    882 extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
    883 extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
    884 extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
    885 
    886 extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy);
    887 extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
    888 extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
    889 
    890 /* This function should be called on every hardware interrupt. */
    891 extern irqreturn_t dwc2_handle_common_intr(void *dev);
    892 
    893 /* OTG Core Parameters */
    894 
    895 /*
    896  * Specifies the OTG capabilities. The driver will automatically
    897  * detect the value for this parameter if none is specified.
    898  * 0 - HNP and SRP capable (default)
    899  * 1 - SRP Only capable
    900  * 2 - No HNP/SRP capable
    901  */
    902 extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
    903 #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE		0
    904 #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE		1
    905 #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE	2
    906 
    907 /*
    908  * Specifies whether to use slave or DMA mode for accessing the data
    909  * FIFOs. The driver will automatically detect the value for this
    910  * parameter if none is specified.
    911  * 0 - Slave
    912  * 1 - DMA (default, if available)
    913  */
    914 extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
    915 
    916 /*
    917  * When DMA mode is enabled specifies whether to use
    918  * address DMA or DMA Descritor mode for accessing the data
    919  * FIFOs in device mode. The driver will automatically detect
    920  * the value for this parameter if none is specified.
    921  * 0 - address DMA
    922  * 1 - DMA Descriptor(default, if available)
    923  */
    924 extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
    925 
    926 /*
    927  * Specifies the maximum speed of operation in host and device mode.
    928  * The actual speed depends on the speed of the attached device and
    929  * the value of phy_type. The actual speed depends on the speed of the
    930  * attached device.
    931  * 0 - High Speed (default)
    932  * 1 - Full Speed
    933  */
    934 extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
    935 #define DWC2_SPEED_PARAM_HIGH	0
    936 #define DWC2_SPEED_PARAM_FULL	1
    937 
    938 /*
    939  * Specifies whether low power mode is supported when attached
    940  * to a Full Speed or Low Speed device in host mode.
    941  *
    942  * 0 - Don't support low power mode (default)
    943  * 1 - Support low power mode
    944  */
    945 extern void dwc2_set_param_host_support_fs_ls_low_power(
    946 		struct dwc2_hsotg *hsotg, int val);
    947 
    948 /*
    949  * Specifies the PHY clock rate in low power mode when connected to a
    950  * Low Speed device in host mode. This parameter is applicable only if
    951  * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
    952  * then defaults to 6 MHZ otherwise 48 MHZ.
    953  *
    954  * 0 - 48 MHz
    955  * 1 - 6 MHz
    956  */
    957 extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
    958 						     int val);
    959 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ	0
    960 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ	1
    961 
    962 /*
    963  * 0 - Use cC FIFO size parameters
    964  * 1 - Allow dynamic FIFO sizing (default)
    965  */
    966 extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
    967 					       int val);
    968 
    969 /*
    970  * Number of 4-byte words in the Rx FIFO in host mode when dynamic
    971  * FIFO sizing is enabled.
    972  * 16 to 32768 (default 1024)
    973  */
    974 extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
    975 
    976 /*
    977  * Number of 4-byte words in the non-periodic Tx FIFO in host mode
    978  * when Dynamic FIFO sizing is enabled in the core.
    979  * 16 to 32768 (default 256)
    980  */
    981 extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
    982 						    int val);
    983 
    984 /*
    985  * Number of 4-byte words in the host periodic Tx FIFO when dynamic
    986  * FIFO sizing is enabled.
    987  * 16 to 32768 (default 256)
    988  */
    989 extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
    990 						   int val);
    991 
    992 /*
    993  * The maximum transfer size supported in bytes.
    994  * 2047 to 65,535  (default 65,535)
    995  */
    996 extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
    997 
    998 /*
    999  * The maximum number of packets in a transfer.
   1000  * 15 to 511  (default 511)
   1001  */
   1002 extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
   1003 
   1004 /*
   1005  * The number of host channel registers to use.
   1006  * 1 to 16 (default 11)
   1007  * Note: The FPGA configuration supports a maximum of 11 host channels.
   1008  */
   1009 extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
   1010 
   1011 /*
   1012  * Specifies the type of PHY interface to use. By default, the driver
   1013  * will automatically detect the phy_type.
   1014  *
   1015  * 0 - Full Speed PHY
   1016  * 1 - UTMI+ (default)
   1017  * 2 - ULPI
   1018  */
   1019 extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
   1020 #define DWC2_PHY_TYPE_PARAM_FS		0
   1021 #define DWC2_PHY_TYPE_PARAM_UTMI	1
   1022 #define DWC2_PHY_TYPE_PARAM_ULPI	2
   1023 
   1024 /*
   1025  * Specifies the UTMI+ Data Width. This parameter is
   1026  * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
   1027  * PHY_TYPE, this parameter indicates the data width between
   1028  * the MAC and the ULPI Wrapper.) Also, this parameter is
   1029  * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
   1030  * to "8 and 16 bits", meaning that the core has been
   1031  * configured to work at either data path width.
   1032  *
   1033  * 8 or 16 bits (default 16)
   1034  */
   1035 extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
   1036 
   1037 /*
   1038  * Specifies whether the ULPI operates at double or single
   1039  * data rate. This parameter is only applicable if PHY_TYPE is
   1040  * ULPI.
   1041  *
   1042  * 0 - single data rate ULPI interface with 8 bit wide data
   1043  * bus (default)
   1044  * 1 - double data rate ULPI interface with 4 bit wide data
   1045  * bus
   1046  */
   1047 extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
   1048 
   1049 /*
   1050  * Specifies whether to use the internal or external supply to
   1051  * drive the vbus with a ULPI phy.
   1052  */
   1053 extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
   1054 #define DWC2_PHY_ULPI_INTERNAL_VBUS	0
   1055 #define DWC2_PHY_ULPI_EXTERNAL_VBUS	1
   1056 
   1057 /*
   1058  * Specifies whether to use the I2Cinterface for full speed PHY. This
   1059  * parameter is only applicable if PHY_TYPE is FS.
   1060  * 0 - No (default)
   1061  * 1 - Yes
   1062  */
   1063 extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
   1064 
   1065 extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
   1066 
   1067 extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
   1068 
   1069 /*
   1070  * Specifies whether dedicated transmit FIFOs are
   1071  * enabled for non periodic IN endpoints in device mode
   1072  * 0 - No
   1073  * 1 - Yes
   1074  */
   1075 extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
   1076 					       int val);
   1077 
   1078 extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
   1079 
   1080 extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
   1081 
   1082 extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
   1083 
   1084 extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
   1085 				const struct dwc2_core_params *params);
   1086 
   1087 extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
   1088 
   1089 extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
   1090 
   1091 
   1092 
   1093 /*
   1094  * Dump core registers and SPRAM
   1095  */
   1096 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
   1097 extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
   1098 extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
   1099 
   1100 /*
   1101  * Return OTG version - either 1.3 or 2.0
   1102  */
   1103 extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
   1104 
   1105 /* Gadget defines */
   1106 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
   1107 extern int s3c_hsotg_remove(struct dwc2_hsotg *hsotg);
   1108 extern int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2);
   1109 extern int s3c_hsotg_resume(struct dwc2_hsotg *dwc2);
   1110 extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
   1111 extern void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
   1112 		bool reset);
   1113 extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg);
   1114 extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2);
   1115 extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
   1116 #define dwc2_is_device_connected(hsotg) (hsotg->connected)
   1117 #else
   1118 static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2)
   1119 { return 0; }
   1120 static inline int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2)
   1121 { return 0; }
   1122 static inline int s3c_hsotg_resume(struct dwc2_hsotg *dwc2)
   1123 { return 0; }
   1124 static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
   1125 { return 0; }
   1126 static inline void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
   1127 		bool reset) {}
   1128 static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
   1129 static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
   1130 static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
   1131 							int testmode)
   1132 { return 0; }
   1133 #define dwc2_is_device_connected(hsotg) (0)
   1134 #endif
   1135 
   1136 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
   1137 extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
   1138 extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
   1139 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
   1140 #else
   1141 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
   1142 { return 0; }
   1143 static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
   1144 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
   1145 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
   1146 static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
   1147 { return 0; }
   1148 #endif
   1149 
   1150 #endif /* __DWC2_CORE_H__ */
   1151