blob: d2115d2a3db28413effb890b288aaff3d80897ec [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
Antti Seppälä95c8bc32015-08-20 21:41:07 +030047static inline u32 dwc2_readl(const void __iomem *addr)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070048{
Antti Seppälä95c8bc32015-08-20 21:41:07 +030049 u32 value = __raw_readl(addr);
50
51 /* In order to preserve endianness __raw_* operation is used. Therefore
52 * a barrier is needed to ensure IO access is not re-ordered across
53 * reads or writes
54 */
55 mb();
56 return value;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070057}
58
Antti Seppälä95c8bc32015-08-20 21:41:07 +030059static inline void dwc2_writel(u32 value, void __iomem *addr)
60{
61 __raw_writel(value, addr);
62
63 /*
64 * In order to preserve endianness __raw_* operation is used. Therefore
65 * a barrier is needed to ensure IO access is not re-ordered across
66 * reads or writes
67 */
68 mb();
69#ifdef DWC2_LOG_WRITES
70 pr_info("INFO:: wrote %08x to %p\n", value, addr);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070071#endif
Antti Seppälä95c8bc32015-08-20 21:41:07 +030072}
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070073
74/* Maximum number of Endpoints/HostChannels */
75#define MAX_EPS_CHANNELS 16
76
Felipe Balbi1f91b4c2015-08-06 18:11:54 -050077/* dwc2-hsotg declarations */
78static const char * const dwc2_hsotg_supply_names[] = {
Dinh Nguyenf7c0b142014-04-14 14:13:35 -070079 "vusb_d", /* digital USB supply, 1.2V */
80 "vusb_a", /* analog USB supply, 1.1V */
81};
82
83/*
84 * EP0_MPS_LIMIT
85 *
86 * Unfortunately there seems to be a limit of the amount of data that can
87 * be transferred by IN transactions on EP0. This is either 127 bytes or 3
88 * packets (which practically means 1 packet and 63 bytes of data) when the
89 * MPS is set to 64.
90 *
91 * This means if we are wanting to move >127 bytes of data, we need to
92 * split the transactions up, but just doing one packet at a time does
93 * not work (this may be an implicit DATA0 PID on first packet of the
94 * transaction) and doing 2 packets is outside the controller's limits.
95 *
96 * If we try to lower the MPS size for EP0, then no transfers work properly
97 * for EP0, and the system will fail basic enumeration. As no cause for this
98 * has currently been found, we cannot support any large IN transfers for
99 * EP0.
100 */
101#define EP0_MPS_LIMIT 64
102
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600103struct dwc2_hsotg;
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500104struct dwc2_hsotg_req;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700105
106/**
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500107 * struct dwc2_hsotg_ep - driver endpoint definition.
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700108 * @ep: The gadget layer representation of the endpoint.
109 * @name: The driver generated name for the endpoint.
110 * @queue: Queue of requests for this endpoint.
111 * @parent: Reference back to the parent device structure.
112 * @req: The current request that the endpoint is processing. This is
113 * used to indicate an request has been loaded onto the endpoint
114 * and has yet to be completed (maybe due to data move, or simply
115 * awaiting an ack from the core all the data has been completed).
116 * @debugfs: File entry for debugfs file for this endpoint.
117 * @lock: State lock to protect contents of endpoint.
118 * @dir_in: Set to true if this endpoint is of the IN direction, which
119 * means that it is sending data to the Host.
120 * @index: The index for the endpoint registers.
121 * @mc: Multi Count - number of transactions per microframe
122 * @interval - Interval for periodic endpoints
123 * @name: The name array passed to the USB core.
124 * @halted: Set if the endpoint has been halted.
125 * @periodic: Set if this is a periodic ep, such as Interrupt
126 * @isochronous: Set if this is a isochronous ep
Mian Yousaf Kaukab8a20fa42015-01-09 13:39:03 +0100127 * @send_zlp: Set if we need to send a zero-length packet.
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700128 * @total_data: The total number of data bytes done.
129 * @fifo_size: The size of the FIFO (for periodic IN endpoints)
130 * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
131 * @last_load: The offset of data for the last start of request.
132 * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
133 *
134 * This is the driver's state for each registered enpoint, allowing it
135 * to keep track of transactions that need doing. Each endpoint has a
136 * lock to protect the state, to try and avoid using an overall lock
137 * for the host controller as much as possible.
138 *
139 * For periodic IN endpoints, we have fifo_size and fifo_load to try
140 * and keep track of the amount of data in the periodic FIFO for each
141 * of these as we don't have a status register that tells us how much
142 * is in each of them. (note, this may actually be useless information
143 * as in shared-fifo mode periodic in acts like a single-frame packet
144 * buffer than a fifo)
145 */
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500146struct dwc2_hsotg_ep {
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700147 struct usb_ep ep;
148 struct list_head queue;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600149 struct dwc2_hsotg *parent;
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500150 struct dwc2_hsotg_req *req;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700151 struct dentry *debugfs;
152
153 unsigned long total_data;
154 unsigned int size_loaded;
155 unsigned int last_load;
156 unsigned int fifo_load;
157 unsigned short fifo_size;
Robert Baldygab203d0a2014-09-09 10:44:56 +0200158 unsigned short fifo_index;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700159
160 unsigned char dir_in;
161 unsigned char index;
162 unsigned char mc;
163 unsigned char interval;
164
165 unsigned int halted:1;
166 unsigned int periodic:1;
167 unsigned int isochronous:1;
Mian Yousaf Kaukab8a20fa42015-01-09 13:39:03 +0100168 unsigned int send_zlp:1;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700169
170 char name[10];
171};
172
173/**
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500174 * struct dwc2_hsotg_req - data transfer request
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700175 * @req: The USB gadget request
176 * @queue: The list of requests for the endpoint this is queued for.
Mian Yousaf Kaukab7d24c1b2015-01-30 09:09:31 +0100177 * @saved_req_buf: variable to save req.buf when bounce buffers are used.
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700178 */
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500179struct dwc2_hsotg_req {
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700180 struct usb_request req;
181 struct list_head queue;
Mian Yousaf Kaukab7d24c1b2015-01-30 09:09:31 +0100182 void *saved_req_buf;
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700183};
184
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600185#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700186#define call_gadget(_hs, _entry) \
187do { \
188 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
189 (_hs)->driver && (_hs)->driver->_entry) { \
190 spin_unlock(&_hs->lock); \
191 (_hs)->driver->_entry(&(_hs)->gadget); \
192 spin_lock(&_hs->lock); \
193 } \
194} while (0)
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600195#else
196#define call_gadget(_hs, _entry) do {} while (0)
197#endif
Dinh Nguyenf7c0b142014-04-14 14:13:35 -0700198
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700199struct dwc2_hsotg;
200struct dwc2_host_chan;
201
202/* Device States */
203enum dwc2_lx_state {
204 DWC2_L0, /* On state */
205 DWC2_L1, /* LPM sleep state */
206 DWC2_L2, /* USB suspend state */
207 DWC2_L3, /* Off state */
208};
209
Gregory Herrero0a176272015-01-09 13:38:52 +0100210/*
211 * Gadget periodic tx fifo sizes as used by legacy driver
212 * EP0 is not included
213 */
214#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
215 768, 0, 0, 0, 0, 0, 0, 0}
216
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100217/* Gadget ep0 states */
218enum dwc2_ep0_state {
219 DWC2_EP0_SETUP,
220 DWC2_EP0_DATA_IN,
221 DWC2_EP0_DATA_OUT,
222 DWC2_EP0_STATUS_IN,
223 DWC2_EP0_STATUS_OUT,
224};
225
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700226/**
227 * struct dwc2_core_params - Parameters for configuring the core
228 *
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200229 * @otg_cap: Specifies the OTG capabilities.
230 * 0 - HNP and SRP capable
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700231 * 1 - SRP Only capable
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200232 * 2 - No HNP/SRP capable (always available)
233 * Defaults to best available option (0, 1, then 2)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700234 * @otg_ver: OTG version supported
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200235 * 0 - 1.3 (default)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700236 * 1 - 2.0
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700237 * @dma_enable: Specifies whether to use slave or DMA mode for accessing
238 * the data FIFOs. The driver will automatically detect the
239 * value for this parameter if none is specified.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200240 * 0 - Slave (always available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700241 * 1 - DMA (default, if available)
242 * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
243 * address DMA mode or descriptor DMA mode for accessing
244 * the data FIFOs. The driver will automatically detect the
245 * value for this if none is specified.
246 * 0 - Address DMA
247 * 1 - Descriptor DMA (default, if available)
248 * @speed: Specifies the maximum speed of operation in host and
249 * device mode. The actual speed depends on the speed of
250 * the attached device and the value of phy_type.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200251 * 0 - High Speed
252 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700253 * 1 - Full Speed
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200254 * (default when phy_type is Full Speed)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700255 * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200256 * 1 - Allow dynamic FIFO sizing (default, if available)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700257 * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
258 * are enabled
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700259 * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
260 * dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200261 * 16 to 32768
262 * Actual maximum value is autodetected and also
263 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700264 * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
265 * in host mode when dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200266 * 16 to 32768
267 * Actual maximum value is autodetected and also
268 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700269 * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
270 * host mode when dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200271 * 16 to 32768
272 * Actual maximum value is autodetected and also
273 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700274 * @max_transfer_size: The maximum transfer size supported, in bytes
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200275 * 2047 to 65,535
276 * Actual maximum value is autodetected and also
277 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700278 * @max_packet_count: The maximum number of packets in a transfer
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200279 * 15 to 511
280 * Actual maximum value is autodetected and also
281 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700282 * @host_channels: The number of host channel registers to use
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200283 * 1 to 16
284 * Actual maximum value is autodetected and also
285 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700286 * @phy_type: Specifies the type of PHY interface to use. By default,
287 * the driver will automatically detect the phy_type.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200288 * 0 - Full Speed Phy
289 * 1 - UTMI+ Phy
290 * 2 - ULPI Phy
291 * Defaults to best available option (2, 1, then 0)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700292 * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
293 * is applicable for a phy_type of UTMI+ or ULPI. (For a
294 * ULPI phy_type, this parameter indicates the data width
295 * between the MAC and the ULPI Wrapper.) Also, this
296 * parameter is applicable only if the OTG_HSPHY_WIDTH cC
297 * parameter was set to "8 and 16 bits", meaning that the
298 * core has been configured to work at either data path
299 * width.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200300 * 8 or 16 (default 16 if available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700301 * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
302 * data rate. This parameter is only applicable if phy_type
303 * is ULPI.
304 * 0 - single data rate ULPI interface with 8 bit wide
305 * data bus (default)
306 * 1 - double data rate ULPI interface with 4 bit wide
307 * data bus
308 * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
309 * external supply to drive the VBus
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200310 * 0 - Internal supply (default)
311 * 1 - External supply
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700312 * @i2c_enable: Specifies whether to use the I2Cinterface for a full
313 * speed PHY. This parameter is only applicable if phy_type
314 * is FS.
315 * 0 - No (default)
316 * 1 - Yes
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200317 * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
318 * 0 - No (default)
319 * 1 - Yes
Paul Zimmerman725acc82013-08-11 12:50:17 -0700320 * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
321 * when attached to a Full Speed or Low Speed device in
322 * host mode.
323 * 0 - Don't support low power mode (default)
324 * 1 - Support low power mode
325 * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200326 * when connected to a Low Speed device in host
327 * mode. This parameter is applicable only if
328 * host_support_fs_ls_low_power is enabled.
Paul Zimmerman725acc82013-08-11 12:50:17 -0700329 * 0 - 48 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200330 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700331 * 1 - 6 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200332 * (default when phy_type is Full Speed)
333 * @ts_dline: Enable Term Select Dline pulsing
334 * 0 - No (default)
335 * 1 - Yes
336 * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
337 * 0 - No (default for core < 2.92a)
338 * 1 - Yes (default for core >= 2.92a)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700339 * @ahbcfg: This field allows the default value of the GAHBCFG
340 * register to be overridden
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200341 * -1 - GAHBCFG value will be set to 0x06
342 * (INCR4, default)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700343 * all others - GAHBCFG value will be overridden with
344 * this value
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200345 * Not all bits can be controlled like this, the
346 * bits defined by GAHBCFG_CTRL_MASK are controlled
347 * by the driver and are ignored in this
348 * configuration value.
Dom Cobley20f2eb92013-09-23 14:23:34 -0700349 * @uframe_sched: True to enable the microframe scheduler
Gregory Herreroa6d249d2015-04-29 22:09:04 +0200350 * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
351 * Disable CONIDSTSCHNG controller interrupt in such
352 * case.
353 * 0 - No (default)
354 * 1 - Yes
Gregory Herrero285046a2015-04-29 22:09:19 +0200355 * @hibernation: Specifies whether the controller support hibernation.
356 * If hibernation is enabled, the controller will enter
357 * hibernation in both peripheral and host mode when
358 * needed.
359 * 0 - No (default)
360 * 1 - Yes
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700361 *
362 * The following parameters may be specified when starting the module. These
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200363 * parameters define how the DWC_otg controller should be configured. A
364 * value of -1 (or any other out of range value) for any parameter means
365 * to read the value from hardware (if possible) or use the builtin
366 * default described above.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700367 */
368struct dwc2_core_params {
Matthijs Kooijman8284f932013-04-11 18:43:47 +0200369 /*
370 * Don't add any non-int members here, this will break
371 * dwc2_set_all_params!
372 */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700373 int otg_cap;
374 int otg_ver;
375 int dma_enable;
376 int dma_desc_enable;
377 int speed;
378 int enable_dynamic_fifo;
379 int en_multiple_tx_fifo;
380 int host_rx_fifo_size;
381 int host_nperio_tx_fifo_size;
382 int host_perio_tx_fifo_size;
383 int max_transfer_size;
384 int max_packet_count;
385 int host_channels;
386 int phy_type;
387 int phy_utmi_width;
388 int phy_ulpi_ddr;
389 int phy_ulpi_ext_vbus;
390 int i2c_enable;
391 int ulpi_fs_ls;
392 int host_support_fs_ls_low_power;
393 int host_ls_low_power_phy_clk;
394 int ts_dline;
395 int reload_ctl;
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700396 int ahbcfg;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700397 int uframe_sched;
Gregory Herreroa6d249d2015-04-29 22:09:04 +0200398 int external_id_pin_ctl;
Gregory Herrero285046a2015-04-29 22:09:19 +0200399 int hibernation;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700400};
401
402/**
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200403 * struct dwc2_hw_params - Autodetected parameters.
404 *
405 * These parameters are the various parameters read from hardware
406 * registers during initialization. They typically contain the best
407 * supported or maximum value that can be configured in the
408 * corresponding dwc2_core_params value.
409 *
410 * The values that are not in dwc2_core_params are documented below.
411 *
412 * @op_mode Mode of Operation
413 * 0 - HNP- and SRP-Capable OTG (Host & Device)
414 * 1 - SRP-Capable OTG (Host & Device)
415 * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
416 * 3 - SRP-Capable Device
417 * 4 - Non-OTG Device
418 * 5 - SRP-Capable Host
419 * 6 - Non-OTG Host
420 * @arch Architecture
421 * 0 - Slave only
422 * 1 - External DMA
423 * 2 - Internal DMA
424 * @power_optimized Are power optimizations enabled?
425 * @num_dev_ep Number of device endpoints available
426 * @num_dev_perio_in_ep Number of device periodic IN endpoints
Mickael Maison997f4f82014-12-23 17:39:45 +0100427 * available
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200428 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
429 * Depth
430 * 0 to 30
431 * @host_perio_tx_q_depth
432 * Host Mode Periodic Request Queue Depth
433 * 2, 4 or 8
434 * @nperio_tx_q_depth
435 * Non-Periodic Request Queue Depth
436 * 2, 4 or 8
437 * @hs_phy_type High-speed PHY interface type
438 * 0 - High-speed interface not supported
439 * 1 - UTMI+
440 * 2 - ULPI
441 * 3 - UTMI+ and ULPI
442 * @fs_phy_type Full-speed PHY interface type
443 * 0 - Full speed interface not supported
444 * 1 - Dedicated full speed interface
445 * 2 - FS pins shared with UTMI+ pins
446 * 3 - FS pins shared with ULPI pins
447 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200448 * @utmi_phy_data_width UTMI+ PHY data width
449 * 0 - 8 bits
450 * 1 - 16 bits
451 * 2 - 8 or 16 bits
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200452 * @snpsid: Value from SNPSID register
453 */
454struct dwc2_hw_params {
455 unsigned op_mode:3;
456 unsigned arch:2;
457 unsigned dma_desc_enable:1;
458 unsigned enable_dynamic_fifo:1;
459 unsigned en_multiple_tx_fifo:1;
460 unsigned host_rx_fifo_size:16;
461 unsigned host_nperio_tx_fifo_size:16;
462 unsigned host_perio_tx_fifo_size:16;
463 unsigned nperio_tx_q_depth:3;
464 unsigned host_perio_tx_q_depth:3;
465 unsigned dev_token_q_depth:5;
466 unsigned max_transfer_size:26;
467 unsigned max_packet_count:11;
Matthijs Kooijman2d115542013-10-03 09:46:25 +0200468 unsigned host_channels:5;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200469 unsigned hs_phy_type:2;
470 unsigned fs_phy_type:2;
471 unsigned i2c_enable:1;
472 unsigned num_dev_ep:4;
473 unsigned num_dev_perio_in_ep:4;
474 unsigned total_fifo_size:16;
475 unsigned power_optimized:1;
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200476 unsigned utmi_phy_data_width:2;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200477 u32 snpsid;
478};
479
Mian Yousaf Kaukab3f950012015-01-09 13:38:44 +0100480/* Size of control and EP0 buffers */
481#define DWC2_CTRL_BUFF_SIZE 8
482
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200483/**
Gregory Herrerod17ee772015-04-29 22:09:01 +0200484 * struct dwc2_gregs_backup - Holds global registers state before entering partial
485 * power down
486 * @gotgctl: Backup of GOTGCTL register
487 * @gintmsk: Backup of GINTMSK register
488 * @gahbcfg: Backup of GAHBCFG register
489 * @gusbcfg: Backup of GUSBCFG register
490 * @grxfsiz: Backup of GRXFSIZ register
491 * @gnptxfsiz: Backup of GNPTXFSIZ register
492 * @gi2cctl: Backup of GI2CCTL register
493 * @hptxfsiz: Backup of HPTXFSIZ register
494 * @gdfifocfg: Backup of GDFIFOCFG register
495 * @dtxfsiz: Backup of DTXFSIZ registers for each endpoint
496 * @gpwrdn: Backup of GPWRDN register
497 */
498struct dwc2_gregs_backup {
499 u32 gotgctl;
500 u32 gintmsk;
501 u32 gahbcfg;
502 u32 gusbcfg;
503 u32 grxfsiz;
504 u32 gnptxfsiz;
505 u32 gi2cctl;
506 u32 hptxfsiz;
507 u32 pcgcctl;
508 u32 gdfifocfg;
509 u32 dtxfsiz[MAX_EPS_CHANNELS];
510 u32 gpwrdn;
Mian Yousaf Kaukabcc1e2042015-06-29 11:05:30 +0200511 bool valid;
Gregory Herrerod17ee772015-04-29 22:09:01 +0200512};
513
514/**
515 * struct dwc2_dregs_backup - Holds device registers state before entering partial
516 * power down
517 * @dcfg: Backup of DCFG register
518 * @dctl: Backup of DCTL register
519 * @daintmsk: Backup of DAINTMSK register
520 * @diepmsk: Backup of DIEPMSK register
521 * @doepmsk: Backup of DOEPMSK register
522 * @diepctl: Backup of DIEPCTL register
523 * @dieptsiz: Backup of DIEPTSIZ register
524 * @diepdma: Backup of DIEPDMA register
525 * @doepctl: Backup of DOEPCTL register
526 * @doeptsiz: Backup of DOEPTSIZ register
527 * @doepdma: Backup of DOEPDMA register
528 */
529struct dwc2_dregs_backup {
530 u32 dcfg;
531 u32 dctl;
532 u32 daintmsk;
533 u32 diepmsk;
534 u32 doepmsk;
535 u32 diepctl[MAX_EPS_CHANNELS];
536 u32 dieptsiz[MAX_EPS_CHANNELS];
537 u32 diepdma[MAX_EPS_CHANNELS];
538 u32 doepctl[MAX_EPS_CHANNELS];
539 u32 doeptsiz[MAX_EPS_CHANNELS];
540 u32 doepdma[MAX_EPS_CHANNELS];
Mian Yousaf Kaukabcc1e2042015-06-29 11:05:30 +0200541 bool valid;
Gregory Herrerod17ee772015-04-29 22:09:01 +0200542};
543
544/**
545 * struct dwc2_hregs_backup - Holds host registers state before entering partial
546 * power down
547 * @hcfg: Backup of HCFG register
548 * @haintmsk: Backup of HAINTMSK register
549 * @hcintmsk: Backup of HCINTMSK register
550 * @hptr0: Backup of HPTR0 register
551 * @hfir: Backup of HFIR register
552 */
553struct dwc2_hregs_backup {
554 u32 hcfg;
555 u32 haintmsk;
556 u32 hcintmsk[MAX_EPS_CHANNELS];
557 u32 hprt0;
558 u32 hfir;
Mian Yousaf Kaukabcc1e2042015-06-29 11:05:30 +0200559 bool valid;
Gregory Herrerod17ee772015-04-29 22:09:01 +0200560};
561
562/**
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700563 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
564 * and periodic schedules
565 *
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600566 * These are common for both host and peripheral modes:
567 *
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700568 * @dev: The struct device pointer
569 * @regs: Pointer to controller regs
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200570 * @hw_params: Parameters that were autodetected from the
571 * hardware registers
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600572 * @core_params: Parameters that define how the core should be configured
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700573 * @op_state: The operational State, during transitions (a_host=>
574 * a_peripheral and b_device=>b_host) this may not match
575 * the core, but allows the software to determine
576 * transitions
Kever Yangc0155b92014-08-06 09:01:50 +0800577 * @dr_mode: Requested mode of operation, one of following:
578 * - USB_DR_MODE_PERIPHERAL
579 * - USB_DR_MODE_HOST
580 * - USB_DR_MODE_OTG
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600581 * @lock: Spinlock that protects all the driver data structures
582 * @priv: Stores a pointer to the struct usb_hcd
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700583 * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
584 * transfer are in process of being queued
585 * @srp_success: Stores status of SRP request in the case of a FS PHY
586 * with an I2C interface
587 * @wq_otg: Workqueue object used for handling of some interrupts
588 * @wf_otg: Work object for handling Connector ID Status Change
589 * interrupt
590 * @wkp_timer: Timer object for handling Wakeup Detected interrupt
591 * @lx_state: Lx state of connected device
Gregory Herrerod17ee772015-04-29 22:09:01 +0200592 * @gregs_backup: Backup of global registers during suspend
593 * @dregs_backup: Backup of device registers during suspend
594 * @hregs_backup: Backup of host registers during suspend
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600595 *
596 * These are for host mode:
597 *
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700598 * @flags: Flags for handling root port state changes
599 * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
600 * Transfers associated with these QHs are not currently
601 * assigned to a host channel.
602 * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
603 * Transfers associated with these QHs are currently
604 * assigned to a host channel.
605 * @non_periodic_qh_ptr: Pointer to next QH to process in the active
606 * non-periodic schedule
607 * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
608 * list of QHs for periodic transfers that are _not_
609 * scheduled for the next frame. Each QH in the list has an
610 * interval counter that determines when it needs to be
611 * scheduled for execution. This scheduling mechanism
612 * allows only a simple calculation for periodic bandwidth
613 * used (i.e. must assume that all periodic transfers may
614 * need to execute in the same frame). However, it greatly
615 * simplifies scheduling and should be sufficient for the
616 * vast majority of OTG hosts, which need to connect to a
617 * small number of peripherals at one time. Items move from
618 * this list to periodic_sched_ready when the QH interval
619 * counter is 0 at SOF.
620 * @periodic_sched_ready: List of periodic QHs that are ready for execution in
621 * the next frame, but have not yet been assigned to host
622 * channels. Items move from this list to
623 * periodic_sched_assigned as host channels become
624 * available during the current frame.
625 * @periodic_sched_assigned: List of periodic QHs to be executed in the next
626 * frame that are assigned to host channels. Items move
627 * from this list to periodic_sched_queued as the
628 * transactions for the QH are queued to the DWC_otg
629 * controller.
630 * @periodic_sched_queued: List of periodic QHs that have been queued for
631 * execution. Items move from this list to either
632 * periodic_sched_inactive or periodic_sched_ready when the
633 * channel associated with the transfer is released. If the
634 * interval for the QH is 1, the item moves to
635 * periodic_sched_ready because it must be rescheduled for
636 * the next frame. Otherwise, the item moves to
637 * periodic_sched_inactive.
638 * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
639 * This value is in microseconds per (micro)frame. The
640 * assumption is that all periodic transfers may occur in
641 * the same (micro)frame.
Dom Cobley20f2eb92013-09-23 14:23:34 -0700642 * @frame_usecs: Internal variable used by the microframe scheduler
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700643 * @frame_number: Frame number read from the core at SOF. The value ranges
644 * from 0 to HFNUM_MAX_FRNUM.
645 * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
646 * SOF enable/disable.
647 * @free_hc_list: Free host channels in the controller. This is a list of
648 * struct dwc2_host_chan items.
649 * @periodic_channels: Number of host channels assigned to periodic transfers.
650 * Currently assuming that there is a dedicated host
651 * channel for each periodic transaction and at least one
652 * host channel is available for non-periodic transactions.
653 * @non_periodic_channels: Number of host channels assigned to non-periodic
654 * transfers
Dom Cobley20f2eb92013-09-23 14:23:34 -0700655 * @available_host_channels Number of host channels available for the microframe
656 * scheduler to use
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700657 * @hc_ptr_array: Array of pointers to the host channel descriptors.
658 * Allows accessing a host channel descriptor given the
659 * host channel number. This is useful in interrupt
660 * handlers.
661 * @status_buf: Buffer used for data received during the status phase of
662 * a control transfer.
663 * @status_buf_dma: DMA address for status_buf
664 * @start_work: Delayed work for handling host A-cable connection
665 * @reset_work: Delayed work for handling a port reset
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700666 * @otg_port: OTG port number
667 * @frame_list: Frame list
668 * @frame_list_dma: Frame list DMA address
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600669 *
670 * These are for peripheral mode:
671 *
672 * @driver: USB gadget driver
673 * @phy: The otg phy transceiver structure for phy control.
674 * @uphy: The otg phy transceiver structure for old USB phy control.
675 * @plat: The platform specific configuration data. This can be removed once
676 * all SoCs support usb transceiver.
677 * @supplies: Definition of USB power supplies
678 * @phyif: PHY interface width
679 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
680 * @num_of_eps: Number of available EPs (excluding EP0)
681 * @debug_root: Root directrory for debugfs.
682 * @debug_file: Main status file for debugfs.
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100683 * @debug_testmode: Testmode status file for debugfs.
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600684 * @debug_fifo: FIFO status file for debugfs.
685 * @ep0_reply: Request used for ep0 reply.
686 * @ep0_buff: Buffer for EP0 reply data, if needed.
687 * @ctrl_buff: Buffer for EP0 control requests.
688 * @ctrl_req: Request for EP0 control packets.
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100689 * @ep0_state: EP0 control transfers state
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100690 * @test_mode: USB test mode requested by the host
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600691 * @last_rst: Time of last reset
692 * @eps: The endpoints being supplied to the gadget framework
Gregory Herreroedd74be2015-01-09 13:38:48 +0100693 * @g_using_dma: Indicate if dma usage is enabled
Gregory Herrero0a176272015-01-09 13:38:52 +0100694 * @g_rx_fifo_sz: Contains rx fifo size value
695 * @g_np_g_tx_fifo_sz: Contains Non-Periodic tx fifo size value
696 * @g_tx_fifo_sz: Contains tx fifo size value per endpoints
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700697 */
698struct dwc2_hsotg {
699 struct device *dev;
700 void __iomem *regs;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200701 /** Params detected from hardware */
702 struct dwc2_hw_params hw_params;
703 /** Params to actually use */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700704 struct dwc2_core_params *core_params;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700705 enum usb_otg_state op_state;
Kever Yangc0155b92014-08-06 09:01:50 +0800706 enum usb_dr_mode dr_mode;
Marek Szyprowskie39af882015-03-10 13:41:10 +0100707 unsigned int hcd_enabled:1;
708 unsigned int gadget_enabled:1;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700709
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600710 struct phy *phy;
711 struct usb_phy *uphy;
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500712 struct regulator_bulk_data supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600713
714 spinlock_t lock;
Marek Szyprowski7ad80962014-11-21 15:14:48 +0100715 struct mutex init_mutex;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600716 void *priv;
717 int irq;
718 struct clk *clk;
719
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700720 unsigned int queuing_high_bandwidth:1;
721 unsigned int srp_success:1;
722
723 struct workqueue_struct *wq_otg;
724 struct work_struct wf_otg;
725 struct timer_list wkp_timer;
726 enum dwc2_lx_state lx_state;
Mian Yousaf Kaukabcc1e2042015-06-29 11:05:30 +0200727 struct dwc2_gregs_backup gr_backup;
728 struct dwc2_dregs_backup dr_backup;
729 struct dwc2_hregs_backup hr_backup;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700730
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600731 struct dentry *debug_root;
Mian Yousaf Kaukab563cf012015-04-29 22:09:00 +0200732 struct debugfs_regset32 *regset;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600733
734 /* DWC OTG HW Release versions */
735#define DWC2_CORE_REV_2_71a 0x4f54271a
736#define DWC2_CORE_REV_2_90a 0x4f54290a
737#define DWC2_CORE_REV_2_92a 0x4f54292a
738#define DWC2_CORE_REV_2_94a 0x4f54294a
739#define DWC2_CORE_REV_3_00a 0x4f54300a
740
741#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700742 union dwc2_hcd_internal_flags {
743 u32 d32;
744 struct {
745 unsigned port_connect_status_change:1;
746 unsigned port_connect_status:1;
747 unsigned port_reset_change:1;
748 unsigned port_enable_change:1;
749 unsigned port_suspend_change:1;
750 unsigned port_over_current_change:1;
751 unsigned port_l1_change:1;
Charles Manningfd4850c2014-10-02 15:36:20 +1300752 unsigned reserved:25;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700753 } b;
754 } flags;
755
756 struct list_head non_periodic_sched_inactive;
757 struct list_head non_periodic_sched_active;
758 struct list_head *non_periodic_qh_ptr;
759 struct list_head periodic_sched_inactive;
760 struct list_head periodic_sched_ready;
761 struct list_head periodic_sched_assigned;
762 struct list_head periodic_sched_queued;
763 u16 periodic_usecs;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700764 u16 frame_usecs[8];
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700765 u16 frame_number;
766 u16 periodic_qh_count;
Gregory Herrero734643d2015-09-22 15:16:39 +0200767 bool bus_suspended;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700768
769#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
770#define FRAME_NUM_ARRAY_SIZE 1000
771 u16 last_frame_num;
772 u16 *frame_num_array;
773 u16 *last_frame_num_array;
774 int frame_num_idx;
775 int dumped_frame_num_array;
776#endif
777
778 struct list_head free_hc_list;
779 int periodic_channels;
780 int non_periodic_channels;
Dom Cobley20f2eb92013-09-23 14:23:34 -0700781 int available_host_channels;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700782 struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
783 u8 *status_buf;
784 dma_addr_t status_buf_dma;
785#define DWC2_HCD_STATUS_BUF_SIZE 64
786
787 struct delayed_work start_work;
788 struct delayed_work reset_work;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700789 u8 otg_port;
790 u32 *frame_list;
791 dma_addr_t frame_list_dma;
792
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700793#ifdef DEBUG
794 u32 frrem_samples;
795 u64 frrem_accum;
796
797 u32 hfnum_7_samples_a;
798 u64 hfnum_7_frrem_accum_a;
799 u32 hfnum_0_samples_a;
800 u64 hfnum_0_frrem_accum_a;
801 u32 hfnum_other_samples_a;
802 u64 hfnum_other_frrem_accum_a;
803
804 u32 hfnum_7_samples_b;
805 u64 hfnum_7_frrem_accum_b;
806 u32 hfnum_0_samples_b;
807 u64 hfnum_0_frrem_accum_b;
808 u32 hfnum_other_samples_b;
809 u64 hfnum_other_frrem_accum_b;
810#endif
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600811#endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
812
813#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
814 /* Gadget structures */
815 struct usb_gadget_driver *driver;
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500816 struct dwc2_hsotg_plat *plat;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600817
818 u32 phyif;
819 int fifo_mem;
820 unsigned int dedicated_fifos:1;
821 unsigned char num_of_eps;
822 u32 fifo_map;
823
824 struct usb_request *ep0_reply;
825 struct usb_request *ctrl_req;
Mian Yousaf Kaukab3f950012015-01-09 13:38:44 +0100826 void *ep0_buff;
827 void *ctrl_buff;
Mian Yousaf Kaukabfe0b94a2015-01-09 13:38:58 +0100828 enum dwc2_ep0_state ep0_state;
Gregory Herrero9e14d0a2015-01-30 09:09:28 +0100829 u8 test_mode;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600830
831 struct usb_gadget gadget;
Marek Szyprowskidc6e69e2014-11-21 15:14:49 +0100832 unsigned int enabled:1;
Marek Szyprowski4ace06e2014-11-21 15:14:47 +0100833 unsigned int connected:1;
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600834 unsigned long last_rst;
Felipe Balbi1f91b4c2015-08-06 18:11:54 -0500835 struct dwc2_hsotg_ep *eps_in[MAX_EPS_CHANNELS];
836 struct dwc2_hsotg_ep *eps_out[MAX_EPS_CHANNELS];
Gregory Herreroedd74be2015-01-09 13:38:48 +0100837 u32 g_using_dma;
Gregory Herrero0a176272015-01-09 13:38:52 +0100838 u32 g_rx_fifo_sz;
839 u32 g_np_g_tx_fifo_sz;
840 u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
Dinh Nguyen941fcce2014-11-11 11:13:33 -0600841#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700842};
843
844/* Reasons for halting a host channel */
845enum dwc2_halt_status {
846 DWC2_HC_XFER_NO_HALT_STATUS,
847 DWC2_HC_XFER_COMPLETE,
848 DWC2_HC_XFER_URB_COMPLETE,
849 DWC2_HC_XFER_ACK,
850 DWC2_HC_XFER_NAK,
851 DWC2_HC_XFER_NYET,
852 DWC2_HC_XFER_STALL,
853 DWC2_HC_XFER_XACT_ERR,
854 DWC2_HC_XFER_FRAME_OVERRUN,
855 DWC2_HC_XFER_BABBLE_ERR,
856 DWC2_HC_XFER_DATA_TOGGLE_ERR,
857 DWC2_HC_XFER_AHB_ERR,
858 DWC2_HC_XFER_PERIODIC_INCOMPLETE,
859 DWC2_HC_XFER_URB_DEQUEUE,
860};
861
862/*
863 * The following functions support initialization of the core driver component
864 * and the DWC_otg controller
865 */
866extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
Gregory Herrerod17ee772015-04-29 22:09:01 +0200867extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg);
868extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700869
870/*
871 * Host core Functions.
872 * The following functions support managing the DWC_otg controller in host
873 * mode.
874 */
875extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
876extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
877 enum dwc2_halt_status halt_status);
878extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
879 struct dwc2_host_chan *chan);
880extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
881 struct dwc2_host_chan *chan);
882extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
883 struct dwc2_host_chan *chan);
884extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
885 struct dwc2_host_chan *chan);
886extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
887 struct dwc2_host_chan *chan);
888extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
889extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
890
891extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
Paul Zimmerman057715f2013-11-22 16:43:51 -0800892extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700893
894/*
895 * Common core Functions.
896 * The following functions support managing the DWC_otg controller in either
897 * device or host mode.
898 */
899extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
900extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
901extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
902
Matthijs Kooijman6706c722013-04-11 17:52:41 +0200903extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700904extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
905extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
906
907/* This function should be called on every hardware interrupt. */
908extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
909
910/* OTG Core Parameters */
911
912/*
913 * Specifies the OTG capabilities. The driver will automatically
914 * detect the value for this parameter if none is specified.
915 * 0 - HNP and SRP capable (default)
916 * 1 - SRP Only capable
917 * 2 - No HNP/SRP capable
918 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800919extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700920#define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
921#define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
922#define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
923
924/*
925 * Specifies whether to use slave or DMA mode for accessing the data
926 * FIFOs. The driver will automatically detect the value for this
927 * parameter if none is specified.
928 * 0 - Slave
929 * 1 - DMA (default, if available)
930 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800931extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700932
933/*
934 * When DMA mode is enabled specifies whether to use
935 * address DMA or DMA Descritor mode for accessing the data
936 * FIFOs in device mode. The driver will automatically detect
937 * the value for this parameter if none is specified.
938 * 0 - address DMA
939 * 1 - DMA Descriptor(default, if available)
940 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800941extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700942
943/*
944 * Specifies the maximum speed of operation in host and device mode.
945 * The actual speed depends on the speed of the attached device and
946 * the value of phy_type. The actual speed depends on the speed of the
947 * attached device.
948 * 0 - High Speed (default)
949 * 1 - Full Speed
950 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800951extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700952#define DWC2_SPEED_PARAM_HIGH 0
953#define DWC2_SPEED_PARAM_FULL 1
954
955/*
956 * Specifies whether low power mode is supported when attached
957 * to a Full Speed or Low Speed device in host mode.
958 *
959 * 0 - Don't support low power mode (default)
960 * 1 - Support low power mode
961 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800962extern void dwc2_set_param_host_support_fs_ls_low_power(
963 struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700964
965/*
966 * Specifies the PHY clock rate in low power mode when connected to a
967 * Low Speed device in host mode. This parameter is applicable only if
968 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
969 * then defaults to 6 MHZ otherwise 48 MHZ.
970 *
971 * 0 - 48 MHz
972 * 1 - 6 MHz
973 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800974extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
975 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700976#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
977#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
978
979/*
980 * 0 - Use cC FIFO size parameters
981 * 1 - Allow dynamic FIFO sizing (default)
982 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800983extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
984 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700985
986/*
987 * Number of 4-byte words in the Rx FIFO in host mode when dynamic
988 * FIFO sizing is enabled.
989 * 16 to 32768 (default 1024)
990 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800991extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700992
993/*
994 * Number of 4-byte words in the non-periodic Tx FIFO in host mode
995 * when Dynamic FIFO sizing is enabled in the core.
996 * 16 to 32768 (default 256)
997 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -0800998extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
999 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001000
1001/*
1002 * Number of 4-byte words in the host periodic Tx FIFO when dynamic
1003 * FIFO sizing is enabled.
1004 * 16 to 32768 (default 256)
1005 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001006extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
1007 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001008
1009/*
1010 * The maximum transfer size supported in bytes.
1011 * 2047 to 65,535 (default 65,535)
1012 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001013extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001014
1015/*
1016 * The maximum number of packets in a transfer.
1017 * 15 to 511 (default 511)
1018 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001019extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001020
1021/*
1022 * The number of host channel registers to use.
1023 * 1 to 16 (default 11)
1024 * Note: The FPGA configuration supports a maximum of 11 host channels.
1025 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001026extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001027
1028/*
1029 * Specifies the type of PHY interface to use. By default, the driver
1030 * will automatically detect the phy_type.
1031 *
1032 * 0 - Full Speed PHY
1033 * 1 - UTMI+ (default)
1034 * 2 - ULPI
1035 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001036extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001037#define DWC2_PHY_TYPE_PARAM_FS 0
1038#define DWC2_PHY_TYPE_PARAM_UTMI 1
1039#define DWC2_PHY_TYPE_PARAM_ULPI 2
1040
1041/*
1042 * Specifies the UTMI+ Data Width. This parameter is
1043 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
1044 * PHY_TYPE, this parameter indicates the data width between
1045 * the MAC and the ULPI Wrapper.) Also, this parameter is
1046 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
1047 * to "8 and 16 bits", meaning that the core has been
1048 * configured to work at either data path width.
1049 *
1050 * 8 or 16 bits (default 16)
1051 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001052extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001053
1054/*
1055 * Specifies whether the ULPI operates at double or single
1056 * data rate. This parameter is only applicable if PHY_TYPE is
1057 * ULPI.
1058 *
1059 * 0 - single data rate ULPI interface with 8 bit wide data
1060 * bus (default)
1061 * 1 - double data rate ULPI interface with 4 bit wide data
1062 * bus
1063 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001064extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001065
1066/*
1067 * Specifies whether to use the internal or external supply to
1068 * drive the vbus with a ULPI phy.
1069 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001070extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001071#define DWC2_PHY_ULPI_INTERNAL_VBUS 0
1072#define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
1073
1074/*
1075 * Specifies whether to use the I2Cinterface for full speed PHY. This
1076 * parameter is only applicable if PHY_TYPE is FS.
1077 * 0 - No (default)
1078 * 1 - Yes
1079 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001080extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001081
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001082extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001083
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001084extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001085
1086/*
1087 * Specifies whether dedicated transmit FIFOs are
1088 * enabled for non periodic IN endpoints in device mode
1089 * 0 - No
1090 * 1 - Yes
1091 */
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001092extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
1093 int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001094
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001095extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001096
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001097extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001098
Paul Zimmerman7218dae2013-11-22 16:43:48 -08001099extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001100
Mian Yousaf Kaukabecb176c2015-04-29 22:09:05 +02001101extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
1102 const struct dwc2_core_params *params);
1103
1104extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
1105
1106extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
1107
1108
1109
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001110/*
1111 * Dump core registers and SPRAM
1112 */
1113extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
1114extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
1115extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
1116
1117/*
1118 * Return OTG version - either 1.3 or 2.0
1119 */
1120extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
1121
Dinh Nguyen117777b2014-11-11 11:13:34 -06001122/* Gadget defines */
1123#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001124extern int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg);
1125extern int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2);
1126extern int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2);
Dinh Nguyen117777b2014-11-11 11:13:34 -06001127extern int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq);
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001128extern void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
Gregory Herrero643cc4d2015-01-30 09:09:32 +01001129 bool reset);
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001130extern void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg);
1131extern void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2);
1132extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
Gregory Herrerof81f46e2015-04-29 22:09:02 +02001133#define dwc2_is_device_connected(hsotg) (hsotg->connected)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001134#else
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001135static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001136{ return 0; }
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001137static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001138{ return 0; }
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001139static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001140{ return 0; }
1141static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
1142{ return 0; }
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001143static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
Gregory Herrero643cc4d2015-01-30 09:09:32 +01001144 bool reset) {}
Felipe Balbi1f91b4c2015-08-06 18:11:54 -05001145static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
1146static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
1147static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
Mian Yousaf Kaukabf91eea42015-04-29 22:08:59 +02001148 int testmode)
1149{ return 0; }
Gregory Herrerof81f46e2015-04-29 22:09:02 +02001150#define dwc2_is_device_connected(hsotg) (0)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001151#endif
1152
1153#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1154extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
1155extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
1156extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
1157#else
Dinh Nguyen117777b2014-11-11 11:13:34 -06001158static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1159{ return 0; }
1160static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
1161static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
1162static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
Mian Yousaf Kaukabecb176c2015-04-29 22:09:05 +02001163static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
Dinh Nguyen117777b2014-11-11 11:13:34 -06001164{ return 0; }
1165#endif
1166
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -07001167#endif /* __DWC2_CORE_H__ */