blob: b0ee9511dc92ac6b5425ce3694513d73be079979 [file] [log] [blame]
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001/*
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
Dinh Nguyenf7c0b142014-04-14 14:13:35 -070040#include <linux/phy/phy.h>
41#include <linux/regulator/consumer.h>
42#include <linux/usb/gadget.h>
43#include <linux/usb/otg.h>
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070044#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
Dinh Nguyenf7c0b142014-04-14 14:13:35 -070061/* 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
Dinh Nguyen941fcce2014-11-11 11:13:33 -060087struct dwc2_hsotg;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -070088struct 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
Mian Yousaf Kaukab8a20fa42015-01-09 13:39:03 +0100111 * @send_zlp: Set if we need to send a zero-length packet.
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700112 * @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;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600133 struct dwc2_hsotg *parent;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700134 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;
Robert Baldygab203d0a2014-09-09 10:44:56 +0200142 unsigned short fifo_index;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700143
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;
Mian Yousaf Kaukab8a20fa42015-01-09 13:39:03 +0100152 unsigned int send_zlp:1;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700153
154 char name[10];
155};
156
157/**
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700158 * 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.
Mian Yousaf Kaukab7d24c1b2015-01-30 09:09:31 +0100161 * @saved_req_buf: variable to save req.buf when bounce buffers are used.
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700162 */
163struct s3c_hsotg_req {
164 struct usb_request req;
165 struct list_head queue;
Mian Yousaf Kaukab7d24c1b2015-01-30 09:09:31 +0100166 void *saved_req_buf;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700167};
168
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600169#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700170#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)
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600179#else
180#define call_gadget(_hs, _entry) do {} while (0)
181#endif
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700182
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700183struct 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
Gregory Herrero0a176272015-01-09 13:38:52 +0100194/*
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
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100201/* 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
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700210/**
211 * struct dwc2_core_params - Parameters for configuring the core
212 *
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200213 * @otg_cap: Specifies the OTG capabilities.
214 * 0 - HNP and SRP capable
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700215 * 1 - SRP Only capable
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200216 * 2 - No HNP/SRP capable (always available)
217 * Defaults to best available option (0, 1, then 2)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700218 * @otg_ver: OTG version supported
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200219 * 0 - 1.3 (default)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700220 * 1 - 2.0
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700221 * @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.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200224 * 0 - Slave (always available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700225 * 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.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200235 * 0 - High Speed
236 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700237 * 1 - Full Speed
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200238 * (default when phy_type is Full Speed)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700239 * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200240 * 1 - Allow dynamic FIFO sizing (default, if available)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700241 * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
242 * are enabled
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700243 * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
244 * dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200245 * 16 to 32768
246 * Actual maximum value is autodetected and also
247 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700248 * @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
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200250 * 16 to 32768
251 * Actual maximum value is autodetected and also
252 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700253 * @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
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200255 * 16 to 32768
256 * Actual maximum value is autodetected and also
257 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700258 * @max_transfer_size: The maximum transfer size supported, in bytes
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200259 * 2047 to 65,535
260 * Actual maximum value is autodetected and also
261 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700262 * @max_packet_count: The maximum number of packets in a transfer
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200263 * 15 to 511
264 * Actual maximum value is autodetected and also
265 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700266 * @host_channels: The number of host channel registers to use
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200267 * 1 to 16
268 * Actual maximum value is autodetected and also
269 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700270 * @phy_type: Specifies the type of PHY interface to use. By default,
271 * the driver will automatically detect the phy_type.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200272 * 0 - Full Speed Phy
273 * 1 - UTMI+ Phy
274 * 2 - ULPI Phy
275 * Defaults to best available option (2, 1, then 0)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700276 * @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.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200284 * 8 or 16 (default 16 if available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700285 * @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
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200294 * 0 - Internal supply (default)
295 * 1 - External supply
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700296 * @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
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200301 * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
302 * 0 - No (default)
303 * 1 - Yes
Paul Zimmerman725acc82013-08-11 12:50:17 -0700304 * @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
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200310 * 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.
Paul Zimmerman725acc82013-08-11 12:50:17 -0700313 * 0 - 48 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200314 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700315 * 1 - 6 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200316 * (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)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700323 * @ahbcfg: This field allows the default value of the GAHBCFG
324 * register to be overridden
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200325 * -1 - GAHBCFG value will be set to 0x06
326 * (INCR4, default)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700327 * all others - GAHBCFG value will be overridden with
328 * this value
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200329 * 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.
Dom Cobley20f2eb92013-09-23 14:23:34 -0700333 * @uframe_sched: True to enable the microframe scheduler
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700334 *
335 * The following parameters may be specified when starting the module. These
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200336 * parameters define how the DWC_otg controller should be configured. A
337 * value of -1 (or any other out of range value) for any parameter means
338 * to read the value from hardware (if possible) or use the builtin
339 * default described above.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700340 */
341struct dwc2_core_params {
Matthijs Kooijman8284f932013-04-11 18:43:47 +0200342 /*
343 * Don't add any non-int members here, this will break
344 * dwc2_set_all_params!
345 */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700346 int otg_cap;
347 int otg_ver;
348 int dma_enable;
349 int dma_desc_enable;
350 int speed;
351 int enable_dynamic_fifo;
352 int en_multiple_tx_fifo;
353 int host_rx_fifo_size;
354 int host_nperio_tx_fifo_size;
355 int host_perio_tx_fifo_size;
356 int max_transfer_size;
357 int max_packet_count;
358 int host_channels;
359 int phy_type;
360 int phy_utmi_width;
361 int phy_ulpi_ddr;
362 int phy_ulpi_ext_vbus;
363 int i2c_enable;
364 int ulpi_fs_ls;
365 int host_support_fs_ls_low_power;
366 int host_ls_low_power_phy_clk;
367 int ts_dline;
368 int reload_ctl;
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700369 int ahbcfg;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700370 int uframe_sched;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700371};
372
373/**
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200374 * struct dwc2_hw_params - Autodetected parameters.
375 *
376 * These parameters are the various parameters read from hardware
377 * registers during initialization. They typically contain the best
378 * supported or maximum value that can be configured in the
379 * corresponding dwc2_core_params value.
380 *
381 * The values that are not in dwc2_core_params are documented below.
382 *
383 * @op_mode Mode of Operation
384 * 0 - HNP- and SRP-Capable OTG (Host & Device)
385 * 1 - SRP-Capable OTG (Host & Device)
386 * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
387 * 3 - SRP-Capable Device
388 * 4 - Non-OTG Device
389 * 5 - SRP-Capable Host
390 * 6 - Non-OTG Host
391 * @arch Architecture
392 * 0 - Slave only
393 * 1 - External DMA
394 * 2 - Internal DMA
395 * @power_optimized Are power optimizations enabled?
396 * @num_dev_ep Number of device endpoints available
397 * @num_dev_perio_in_ep Number of device periodic IN endpoints
Mickael Maison997f4f82014-12-23 17:39:45 +0100398 * available
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200399 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
400 * Depth
401 * 0 to 30
402 * @host_perio_tx_q_depth
403 * Host Mode Periodic Request Queue Depth
404 * 2, 4 or 8
405 * @nperio_tx_q_depth
406 * Non-Periodic Request Queue Depth
407 * 2, 4 or 8
408 * @hs_phy_type High-speed PHY interface type
409 * 0 - High-speed interface not supported
410 * 1 - UTMI+
411 * 2 - ULPI
412 * 3 - UTMI+ and ULPI
413 * @fs_phy_type Full-speed PHY interface type
414 * 0 - Full speed interface not supported
415 * 1 - Dedicated full speed interface
416 * 2 - FS pins shared with UTMI+ pins
417 * 3 - FS pins shared with ULPI pins
418 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200419 * @utmi_phy_data_width UTMI+ PHY data width
420 * 0 - 8 bits
421 * 1 - 16 bits
422 * 2 - 8 or 16 bits
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200423 * @snpsid: Value from SNPSID register
424 */
425struct dwc2_hw_params {
426 unsigned op_mode:3;
427 unsigned arch:2;
428 unsigned dma_desc_enable:1;
429 unsigned enable_dynamic_fifo:1;
430 unsigned en_multiple_tx_fifo:1;
431 unsigned host_rx_fifo_size:16;
432 unsigned host_nperio_tx_fifo_size:16;
433 unsigned host_perio_tx_fifo_size:16;
434 unsigned nperio_tx_q_depth:3;
435 unsigned host_perio_tx_q_depth:3;
436 unsigned dev_token_q_depth:5;
437 unsigned max_transfer_size:26;
438 unsigned max_packet_count:11;
Matthijs Kooijman2d115542013-10-03 09:46:25 +0200439 unsigned host_channels:5;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200440 unsigned hs_phy_type:2;
441 unsigned fs_phy_type:2;
442 unsigned i2c_enable:1;
443 unsigned num_dev_ep:4;
444 unsigned num_dev_perio_in_ep:4;
445 unsigned total_fifo_size:16;
446 unsigned power_optimized:1;
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200447 unsigned utmi_phy_data_width:2;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200448 u32 snpsid;
449};
450
Mian Yousaf Kaukab3f950012015-01-09 13:38:44 +0100451/* Size of control and EP0 buffers */
452#define DWC2_CTRL_BUFF_SIZE 8
453
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200454/**
Gregory Herrerod17ee772015-04-29 22:09:01 +0200455 * struct dwc2_gregs_backup - Holds global registers state before entering partial
456 * power down
457 * @gotgctl: Backup of GOTGCTL register
458 * @gintmsk: Backup of GINTMSK register
459 * @gahbcfg: Backup of GAHBCFG register
460 * @gusbcfg: Backup of GUSBCFG register
461 * @grxfsiz: Backup of GRXFSIZ register
462 * @gnptxfsiz: Backup of GNPTXFSIZ register
463 * @gi2cctl: Backup of GI2CCTL register
464 * @hptxfsiz: Backup of HPTXFSIZ register
465 * @gdfifocfg: Backup of GDFIFOCFG register
466 * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
467 * @gpwrdn: Backup of GPWRDN register
468 */
469struct dwc2_gregs_backup {
470 u32 gotgctl;
471 u32 gintmsk;
472 u32 gahbcfg;
473 u32 gusbcfg;
474 u32 grxfsiz;
475 u32 gnptxfsiz;
476 u32 gi2cctl;
477 u32 hptxfsiz;
478 u32 pcgcctl;
479 u32 gdfifocfg;
480 u32 dtxfsiz[MAX_EPS_CHANNELS];
481 u32 gpwrdn;
482};
483
484/**
485 * struct dwc2_dregs_backup - Holds device registers state before entering partial
486 * power down
487 * @dcfg: Backup of DCFG register
488 * @dctl: Backup of DCTL register
489 * @daintmsk: Backup of DAINTMSK register
490 * @diepmsk: Backup of DIEPMSK register
491 * @doepmsk: Backup of DOEPMSK register
492 * @diepctl: Backup of DIEPCTL register
493 * @dieptsiz: Backup of DIEPTSIZ register
494 * @diepdma: Backup of DIEPDMA register
495 * @doepctl: Backup of DOEPCTL register
496 * @doeptsiz: Backup of DOEPTSIZ register
497 * @doepdma: Backup of DOEPDMA register
498 */
499struct dwc2_dregs_backup {
500 u32 dcfg;
501 u32 dctl;
502 u32 daintmsk;
503 u32 diepmsk;
504 u32 doepmsk;
505 u32 diepctl[MAX_EPS_CHANNELS];
506 u32 dieptsiz[MAX_EPS_CHANNELS];
507 u32 diepdma[MAX_EPS_CHANNELS];
508 u32 doepctl[MAX_EPS_CHANNELS];
509 u32 doeptsiz[MAX_EPS_CHANNELS];
510 u32 doepdma[MAX_EPS_CHANNELS];
511};
512
513/**
514 * struct dwc2_hregs_backup - Holds host registers state before entering partial
515 * power down
516 * @hcfg: Backup of HCFG register
517 * @haintmsk: Backup of HAINTMSK register
518 * @hcintmsk: Backup of HCINTMSK register
519 * @hptr0: Backup of HPTR0 register
520 * @hfir: Backup of HFIR register
521 */
522struct dwc2_hregs_backup {
523 u32 hcfg;
524 u32 haintmsk;
525 u32 hcintmsk[MAX_EPS_CHANNELS];
526 u32 hprt0;
527 u32 hfir;
528};
529
530/**
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700531 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
532 * and periodic schedules
533 *
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600534 * These are common for both host and peripheral modes:
535 *
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700536 * @dev: The struct device pointer
537 * @regs: Pointer to controller regs
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200538 * @hw_params: Parameters that were autodetected from the
539 * hardware registers
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600540 * @core_params: Parameters that define how the core should be configured
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700541 * @op_state: The operational State, during transitions (a_host=>
542 * a_peripheral and b_device=>b_host) this may not match
543 * the core, but allows the software to determine
544 * transitions
Kever Yangc0155b92014-08-06 09:01:50 +0800545 * @dr_mode: Requested mode of operation, one of following:
546 * - USB_DR_MODE_PERIPHERAL
547 * - USB_DR_MODE_HOST
548 * - USB_DR_MODE_OTG
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600549 * @lock: Spinlock that protects all the driver data structures
550 * @priv: Stores a pointer to the struct usb_hcd
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700551 * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
552 * transfer are in process of being queued
553 * @srp_success: Stores status of SRP request in the case of a FS PHY
554 * with an I2C interface
555 * @wq_otg: Workqueue object used for handling of some interrupts
556 * @wf_otg: Work object for handling Connector ID Status Change
557 * interrupt
558 * @wkp_timer: Timer object for handling Wakeup Detected interrupt
559 * @lx_state: Lx state of connected device
Gregory Herrerod17ee772015-04-29 22:09:01 +0200560 * @gregs_backup: Backup of global registers during suspend
561 * @dregs_backup: Backup of device registers during suspend
562 * @hregs_backup: Backup of host registers during suspend
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600563 *
564 * These are for host mode:
565 *
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700566 * @flags: Flags for handling root port state changes
567 * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
568 * Transfers associated with these QHs are not currently
569 * assigned to a host channel.
570 * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
571 * Transfers associated with these QHs are currently
572 * assigned to a host channel.
573 * @non_periodic_qh_ptr: Pointer to next QH to process in the active
574 * non-periodic schedule
575 * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
576 * list of QHs for periodic transfers that are _not_
577 * scheduled for the next frame. Each QH in the list has an
578 * interval counter that determines when it needs to be
579 * scheduled for execution. This scheduling mechanism
580 * allows only a simple calculation for periodic bandwidth
581 * used (i.e. must assume that all periodic transfers may
582 * need to execute in the same frame). However, it greatly
583 * simplifies scheduling and should be sufficient for the
584 * vast majority of OTG hosts, which need to connect to a
585 * small number of peripherals at one time. Items move from
586 * this list to periodic_sched_ready when the QH interval
587 * counter is 0 at SOF.
588 * @periodic_sched_ready: List of periodic QHs that are ready for execution in
589 * the next frame, but have not yet been assigned to host
590 * channels. Items move from this list to
591 * periodic_sched_assigned as host channels become
592 * available during the current frame.
593 * @periodic_sched_assigned: List of periodic QHs to be executed in the next
594 * frame that are assigned to host channels. Items move
595 * from this list to periodic_sched_queued as the
596 * transactions for the QH are queued to the DWC_otg
597 * controller.
598 * @periodic_sched_queued: List of periodic QHs that have been queued for
599 * execution. Items move from this list to either
600 * periodic_sched_inactive or periodic_sched_ready when the
601 * channel associated with the transfer is released. If the
602 * interval for the QH is 1, the item moves to
603 * periodic_sched_ready because it must be rescheduled for
604 * the next frame. Otherwise, the item moves to
605 * periodic_sched_inactive.
606 * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
607 * This value is in microseconds per (micro)frame. The
608 * assumption is that all periodic transfers may occur in
609 * the same (micro)frame.
Dom Cobley20f2eb92013-09-23 14:23:34 -0700610 * @frame_usecs: Internal variable used by the microframe scheduler
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700611 * @frame_number: Frame number read from the core at SOF. The value ranges
612 * from 0 to HFNUM_MAX_FRNUM.
613 * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
614 * SOF enable/disable.
615 * @free_hc_list: Free host channels in the controller. This is a list of
616 * struct dwc2_host_chan items.
617 * @periodic_channels: Number of host channels assigned to periodic transfers.
618 * Currently assuming that there is a dedicated host
619 * channel for each periodic transaction and at least one
620 * host channel is available for non-periodic transactions.
621 * @non_periodic_channels: Number of host channels assigned to non-periodic
622 * transfers
Dom Cobley20f2eb92013-09-23 14:23:34 -0700623 * @available_host_channels Number of host channels available for the microframe
624 * scheduler to use
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700625 * @hc_ptr_array: Array of pointers to the host channel descriptors.
626 * Allows accessing a host channel descriptor given the
627 * host channel number. This is useful in interrupt
628 * handlers.
629 * @status_buf: Buffer used for data received during the status phase of
630 * a control transfer.
631 * @status_buf_dma: DMA address for status_buf
632 * @start_work: Delayed work for handling host A-cable connection
633 * @reset_work: Delayed work for handling a port reset
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700634 * @otg_port: OTG port number
635 * @frame_list: Frame list
636 * @frame_list_dma: Frame list DMA address
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600637 *
638 * These are for peripheral mode:
639 *
640 * @driver: USB gadget driver
641 * @phy: The otg phy transceiver structure for phy control.
642 * @uphy: The otg phy transceiver structure for old USB phy control.
643 * @plat: The platform specific configuration data. This can be removed once
644 * all SoCs support usb transceiver.
645 * @supplies: Definition of USB power supplies
646 * @phyif: PHY interface width
647 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
648 * @num_of_eps: Number of available EPs (excluding EP0)
649 * @debug_root: Root directrory for debugfs.
650 * @debug_file: Main status file for debugfs.
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100651 * @debug_testmode: Testmode status file for debugfs.
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600652 * @debug_fifo: FIFO status file for debugfs.
653 * @ep0_reply: Request used for ep0 reply.
654 * @ep0_buff: Buffer for EP0 reply data, if needed.
655 * @ctrl_buff: Buffer for EP0 control requests.
656 * @ctrl_req: Request for EP0 control packets.
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100657 * @ep0_state: EP0 control transfers state
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100658 * @test_mode: USB test mode requested by the host
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600659 * @last_rst: Time of last reset
660 * @eps: The endpoints being supplied to the gadget framework
Gregory Herreroedd74be2015-01-09 13:38:48 +0100661 * @g_using_dma: Indicate if dma usage is enabled
Gregory Herrero0a176272015-01-09 13:38:52 +0100662 * @g_rx_fifo_sz: Contains rx fifo size value
663 * @g_np_g_tx_fifo_sz: Contains Non-Periodic tx fifo size value
664 * @g_tx_fifo_sz: Contains tx fifo size value per endpoints
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700665 */
666struct dwc2_hsotg {
667 struct device *dev;
668 void __iomem *regs;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200669 /** Params detected from hardware */
670 struct dwc2_hw_params hw_params;
671 /** Params to actually use */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700672 struct dwc2_core_params *core_params;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700673 enum usb_otg_state op_state;
Kever Yangc0155b92014-08-06 09:01:50 +0800674 enum usb_dr_mode dr_mode;
Marek Szyprowskie39af882015-03-10 13:41:10 +0100675 unsigned int hcd_enabled:1;
676 unsigned int gadget_enabled:1;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700677
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600678 struct phy *phy;
679 struct usb_phy *uphy;
680 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)];
681
682 spinlock_t lock;
Marek Szyprowski7ad80962014-11-21 15:14:48 +0100683 struct mutex init_mutex;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600684 void *priv;
685 int irq;
686 struct clk *clk;
687
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700688 unsigned int queuing_high_bandwidth:1;
689 unsigned int srp_success:1;
690
691 struct workqueue_struct *wq_otg;
692 struct work_struct wf_otg;
693 struct timer_list wkp_timer;
694 enum dwc2_lx_state lx_state;
Gregory Herrerod17ee772015-04-29 22:09:01 +0200695 struct dwc2_gregs_backup *gr_backup;
696 struct dwc2_dregs_backup *dr_backup;
697 struct dwc2_hregs_backup *hr_backup;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700698
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600699 struct dentry *debug_root;
Mian Yousaf Kaukab563cf012015-04-29 22:09:00 +0200700 struct debugfs_regset32 *regset;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600701
702 /* DWC OTG HW Release versions */
703#define DWC2_CORE_REV_2_71a 0x4f54271a
704#define DWC2_CORE_REV_2_90a 0x4f54290a
705#define DWC2_CORE_REV_2_92a 0x4f54292a
706#define DWC2_CORE_REV_2_94a 0x4f54294a
707#define DWC2_CORE_REV_3_00a 0x4f54300a
708
709#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700710 union dwc2_hcd_internal_flags {
711 u32 d32;
712 struct {
713 unsigned port_connect_status_change:1;
714 unsigned port_connect_status:1;
715 unsigned port_reset_change:1;
716 unsigned port_enable_change:1;
717 unsigned port_suspend_change:1;
718 unsigned port_over_current_change:1;
719 unsigned port_l1_change:1;
Charles Manningfd4850c2014-10-02 15:36:20 +1300720 unsigned reserved:25;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700721 } b;
722 } flags;
723
724 struct list_head non_periodic_sched_inactive;
725 struct list_head non_periodic_sched_active;
726 struct list_head *non_periodic_qh_ptr;
727 struct list_head periodic_sched_inactive;
728 struct list_head periodic_sched_ready;
729 struct list_head periodic_sched_assigned;
730 struct list_head periodic_sched_queued;
731 u16 periodic_usecs;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700732 u16 frame_usecs[8];
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700733 u16 frame_number;
734 u16 periodic_qh_count;
735
736#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
737#define FRAME_NUM_ARRAY_SIZE 1000
738 u16 last_frame_num;
739 u16 *frame_num_array;
740 u16 *last_frame_num_array;
741 int frame_num_idx;
742 int dumped_frame_num_array;
743#endif
744
745 struct list_head free_hc_list;
746 int periodic_channels;
747 int non_periodic_channels;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700748 int available_host_channels;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700749 struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
750 u8 *status_buf;
751 dma_addr_t status_buf_dma;
752#define DWC2_HCD_STATUS_BUF_SIZE 64
753
754 struct delayed_work start_work;
755 struct delayed_work reset_work;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700756 u8 otg_port;
757 u32 *frame_list;
758 dma_addr_t frame_list_dma;
759
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700760#ifdef DEBUG
761 u32 frrem_samples;
762 u64 frrem_accum;
763
764 u32 hfnum_7_samples_a;
765 u64 hfnum_7_frrem_accum_a;
766 u32 hfnum_0_samples_a;
767 u64 hfnum_0_frrem_accum_a;
768 u32 hfnum_other_samples_a;
769 u64 hfnum_other_frrem_accum_a;
770
771 u32 hfnum_7_samples_b;
772 u64 hfnum_7_frrem_accum_b;
773 u32 hfnum_0_samples_b;
774 u64 hfnum_0_frrem_accum_b;
775 u32 hfnum_other_samples_b;
776 u64 hfnum_other_frrem_accum_b;
777#endif
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600778#endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
779
780#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
781 /* Gadget structures */
782 struct usb_gadget_driver *driver;
783 struct s3c_hsotg_plat *plat;
784
785 u32 phyif;
786 int fifo_mem;
787 unsigned int dedicated_fifos:1;
788 unsigned char num_of_eps;
789 u32 fifo_map;
790
791 struct usb_request *ep0_reply;
792 struct usb_request *ctrl_req;
Mian Yousaf Kaukab3f950012015-01-09 13:38:44 +0100793 void *ep0_buff;
794 void *ctrl_buff;
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100795 enum dwc2_ep0_state ep0_state;
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100796 u8 test_mode;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600797
798 struct usb_gadget gadget;
Marek Szyprowskidc6e69e2014-11-21 15:14:49 +0100799 unsigned int enabled:1;
Marek Szyprowski4ace06e2014-11-21 15:14:47 +0100800 unsigned int connected:1;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600801 unsigned long last_rst;
Mian Yousaf Kaukabc6f5c052015-01-09 13:38:50 +0100802 struct s3c_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
803 struct s3c_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
Gregory Herreroedd74be2015-01-09 13:38:48 +0100804 u32 g_using_dma;
Gregory Herrero0a176272015-01-09 13:38:52 +0100805 u32 g_rx_fifo_sz;
806 u32 g_np_g_tx_fifo_sz;
807 u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600808#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700809};
810
811/* Reasons for halting a host channel */
812enum dwc2_halt_status {
813 DWC2_HC_XFER_NO_HALT_STATUS,
814 DWC2_HC_XFER_COMPLETE,
815 DWC2_HC_XFER_URB_COMPLETE,
816 DWC2_HC_XFER_ACK,
817 DWC2_HC_XFER_NAK,
818 DWC2_HC_XFER_NYET,
819 DWC2_HC_XFER_STALL,
820 DWC2_HC_XFER_XACT_ERR,
821 DWC2_HC_XFER_FRAME_OVERRUN,
822 DWC2_HC_XFER_BABBLE_ERR,
823 DWC2_HC_XFER_DATA_TOGGLE_ERR,
824 DWC2_HC_XFER_AHB_ERR,
825 DWC2_HC_XFER_PERIODIC_INCOMPLETE,
826 DWC2_HC_XFER_URB_DEQUEUE,
827};
828
829/*
830 * The following functions support initialization of the core driver component
831 * and the DWC_otg controller
832 */
833extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
Gregory Herrerod17ee772015-04-29 22:09:01 +0200834extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
835extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700836
837/*
838 * Host core Functions.
839 * The following functions support managing the DWC_otg controller in host
840 * mode.
841 */
842extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
843extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
844 enum dwc2_halt_status halt_status);
845extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
846 struct dwc2_host_chan *chan);
847extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
848 struct dwc2_host_chan *chan);
849extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
850 struct dwc2_host_chan *chan);
851extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
852 struct dwc2_host_chan *chan);
853extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
854 struct dwc2_host_chan *chan);
855extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
856extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
857
858extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
Paul Zimmerman057715f2013-11-22 16:43:51 -0800859extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700860
861/*
862 * Common core Functions.
863 * The following functions support managing the DWC_otg controller in either
864 * device or host mode.
865 */
866extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
867extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
868extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
869
Matthijs Kooijman6706c722013-04-11 17:52:41 +0200870extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700871extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
872extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
873
874/* This function should be called on every hardware interrupt. */
875extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
876
877/* OTG Core Parameters */
878
879/*
880 * Specifies the OTG capabilities. The driver will automatically
881 * detect the value for this parameter if none is specified.
882 * 0 - HNP and SRP capable (default)
883 * 1 - SRP Only capable
884 * 2 - No HNP/SRP capable
885 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800886extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700887#define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
888#define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
889#define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
890
891/*
892 * Specifies whether to use slave or DMA mode for accessing the data
893 * FIFOs. The driver will automatically detect the value for this
894 * parameter if none is specified.
895 * 0 - Slave
896 * 1 - DMA (default, if available)
897 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800898extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700899
900/*
901 * When DMA mode is enabled specifies whether to use
902 * address DMA or DMA Descritor mode for accessing the data
903 * FIFOs in device mode. The driver will automatically detect
904 * the value for this parameter if none is specified.
905 * 0 - address DMA
906 * 1 - DMA Descriptor(default, if available)
907 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800908extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700909
910/*
911 * Specifies the maximum speed of operation in host and device mode.
912 * The actual speed depends on the speed of the attached device and
913 * the value of phy_type. The actual speed depends on the speed of the
914 * attached device.
915 * 0 - High Speed (default)
916 * 1 - Full Speed
917 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800918extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700919#define DWC2_SPEED_PARAM_HIGH 0
920#define DWC2_SPEED_PARAM_FULL 1
921
922/*
923 * Specifies whether low power mode is supported when attached
924 * to a Full Speed or Low Speed device in host mode.
925 *
926 * 0 - Don't support low power mode (default)
927 * 1 - Support low power mode
928 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800929extern void dwc2_set_param_host_support_fs_ls_low_power(
930 struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700931
932/*
933 * Specifies the PHY clock rate in low power mode when connected to a
934 * Low Speed device in host mode. This parameter is applicable only if
935 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
936 * then defaults to 6 MHZ otherwise 48 MHZ.
937 *
938 * 0 - 48 MHz
939 * 1 - 6 MHz
940 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800941extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
942 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700943#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
944#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
945
946/*
947 * 0 - Use cC FIFO size parameters
948 * 1 - Allow dynamic FIFO sizing (default)
949 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800950extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
951 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700952
953/*
954 * Number of 4-byte words in the Rx FIFO in host mode when dynamic
955 * FIFO sizing is enabled.
956 * 16 to 32768 (default 1024)
957 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800958extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700959
960/*
961 * Number of 4-byte words in the non-periodic Tx FIFO in host mode
962 * when Dynamic FIFO sizing is enabled in the core.
963 * 16 to 32768 (default 256)
964 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800965extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
966 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700967
968/*
969 * Number of 4-byte words in the host periodic Tx FIFO when dynamic
970 * FIFO sizing is enabled.
971 * 16 to 32768 (default 256)
972 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800973extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
974 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700975
976/*
977 * The maximum transfer size supported in bytes.
978 * 2047 to 65,535 (default 65,535)
979 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800980extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700981
982/*
983 * The maximum number of packets in a transfer.
984 * 15 to 511 (default 511)
985 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800986extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700987
988/*
989 * The number of host channel registers to use.
990 * 1 to 16 (default 11)
991 * Note: The FPGA configuration supports a maximum of 11 host channels.
992 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800993extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700994
995/*
996 * Specifies the type of PHY interface to use. By default, the driver
997 * will automatically detect the phy_type.
998 *
999 * 0 - Full Speed PHY
1000 * 1 - UTMI+ (default)
1001 * 2 - ULPI
1002 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001003extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001004#define DWC2_PHY_TYPE_PARAM_FS 0
1005#define DWC2_PHY_TYPE_PARAM_UTMI 1
1006#define DWC2_PHY_TYPE_PARAM_ULPI 2
1007
1008/*
1009 * Specifies the UTMI+ Data Width. This parameter is
1010 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
1011 * PHY_TYPE, this parameter indicates the data width between
1012 * the MAC and the ULPI Wrapper.) Also, this parameter is
1013 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
1014 * to "8 and 16 bits", meaning that the core has been
1015 * configured to work at either data path width.
1016 *
1017 * 8 or 16 bits (default 16)
1018 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001019extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001020
1021/*
1022 * Specifies whether the ULPI operates at double or single
1023 * data rate. This parameter is only applicable if PHY_TYPE is
1024 * ULPI.
1025 *
1026 * 0 - single data rate ULPI interface with 8 bit wide data
1027 * bus (default)
1028 * 1 - double data rate ULPI interface with 4 bit wide data
1029 * bus
1030 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001031extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001032
1033/*
1034 * Specifies whether to use the internal or external supply to
1035 * drive the vbus with a ULPI phy.
1036 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001037extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001038#define DWC2_PHY_ULPI_INTERNAL_VBUS 0
1039#define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
1040
1041/*
1042 * Specifies whether to use the I2Cinterface for full speed PHY. This
1043 * parameter is only applicable if PHY_TYPE is FS.
1044 * 0 - No (default)
1045 * 1 - Yes
1046 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001047extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001048
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001049extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001050
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001051extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001052
1053/*
1054 * Specifies whether dedicated transmit FIFOs are
1055 * enabled for non periodic IN endpoints in device mode
1056 * 0 - No
1057 * 1 - Yes
1058 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001059extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
1060 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001061
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001062extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001063
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001064extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001065
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001066extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001067
1068/*
1069 * Dump core registers and SPRAM
1070 */
1071extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
1072extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
1073extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1074
1075/*
1076 * Return OTG version - either 1.3 or 2.0
1077 */
1078extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
1079
Dinh Nguyen117777b2014-11-11 11:13:34 -06001080/* Gadget defines */
1081#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1082extern int s3c_hsotg_remove(struct dwc2_hsotg *hsotg);
1083extern int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2);
1084extern int s3c_hsotg_resume(struct dwc2_hsotg *dwc2);
1085extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
Gregory Herrero643cc4d2015-01-30 09:09:32 +01001086extern void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1087 bool reset);
Dinh Nguyen510ffaa2014-11-11 11:13:36 -06001088extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg);
Marek Szyprowski4ace06e2014-11-21 15:14:47 +01001089extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2);
Mian Yousaf Kaukabf91eea42015-04-29 22:08:59 +02001090extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
Dinh Nguyen117777b2014-11-11 11:13:34 -06001091#else
1092static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2)
1093{ return 0; }
1094static inline int s3c_hsotg_suspend(struct dwc2_hsotg *dwc2)
1095{ return 0; }
1096static inline int s3c_hsotg_resume(struct dwc2_hsotg *dwc2)
1097{ return 0; }
1098static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
1099{ return 0; }
Gregory Herrero643cc4d2015-01-30 09:09:32 +01001100static inline void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
1101 bool reset) {}
Dinh Nguyen510ffaa2014-11-11 11:13:36 -06001102static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
Marek Szyprowski4ace06e2014-11-21 15:14:47 +01001103static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
Mian Yousaf Kaukabf91eea42015-04-29 22:08:59 +02001104static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1105 int testmode)
1106{ return 0; }
Dinh Nguyen117777b2014-11-11 11:13:34 -06001107#endif
1108
1109#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1110extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
1111extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
1112extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
1113#else
1114static inline void dwc2_set_all_params(struct dwc2_core_params *params, int value) {}
1115static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1116{ return 0; }
1117static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
1118static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1119static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
1120static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
1121 const struct dwc2_core_params *params)
1122{ return 0; }
1123#endif
1124
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001125#endif /* __DWC2_CORE_H__ */