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