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