blob: 9102f66d0111e8676ebd5be2ce1bc00dbdc4c8c5 [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
40#include <linux/usb/phy.h>
41#include "hw.h"
42
43#ifdef DWC2_LOG_WRITES
44static inline void do_write(u32 value, void *addr)
45{
46 writel(value, addr);
47 pr_info("INFO:: wrote %08x to %p\n", value, addr);
48}
49
50#undef writel
51#define writel(v, a) do_write(v, a)
52#endif
53
54/* Maximum number of Endpoints/HostChannels */
55#define MAX_EPS_CHANNELS 16
56
57struct dwc2_hsotg;
58struct dwc2_host_chan;
59
60/* Device States */
61enum dwc2_lx_state {
62 DWC2_L0, /* On state */
63 DWC2_L1, /* LPM sleep state */
64 DWC2_L2, /* USB suspend state */
65 DWC2_L3, /* Off state */
66};
67
68/**
69 * struct dwc2_core_params - Parameters for configuring the core
70 *
Matthijs Kooijman91121c12013-08-30 18:45:23 +020071 * @otg_cap: Specifies the OTG capabilities.
72 * 0 - HNP and SRP capable
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070073 * 1 - SRP Only capable
Matthijs Kooijman91121c12013-08-30 18:45:23 +020074 * 2 - No HNP/SRP capable (always available)
75 * Defaults to best available option (0, 1, then 2)
Paul Zimmerman725acc82013-08-11 12:50:17 -070076 * @otg_ver: OTG version supported
Matthijs Kooijman91121c12013-08-30 18:45:23 +020077 * 0 - 1.3 (default)
Paul Zimmerman725acc82013-08-11 12:50:17 -070078 * 1 - 2.0
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070079 * @dma_enable: Specifies whether to use slave or DMA mode for accessing
80 * the data FIFOs. The driver will automatically detect the
81 * value for this parameter if none is specified.
Matthijs Kooijman91121c12013-08-30 18:45:23 +020082 * 0 - Slave (always available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070083 * 1 - DMA (default, if available)
84 * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
85 * address DMA mode or descriptor DMA mode for accessing
86 * the data FIFOs. The driver will automatically detect the
87 * value for this if none is specified.
88 * 0 - Address DMA
89 * 1 - Descriptor DMA (default, if available)
90 * @speed: Specifies the maximum speed of operation in host and
91 * device mode. The actual speed depends on the speed of
92 * the attached device and the value of phy_type.
Matthijs Kooijman91121c12013-08-30 18:45:23 +020093 * 0 - High Speed
94 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070095 * 1 - Full Speed
Matthijs Kooijman91121c12013-08-30 18:45:23 +020096 * (default when phy_type is Full Speed)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -070097 * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
Matthijs Kooijman91121c12013-08-30 18:45:23 +020098 * 1 - Allow dynamic FIFO sizing (default, if available)
Paul Zimmerman725acc82013-08-11 12:50:17 -070099 * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
100 * are enabled
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700101 * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
102 * dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200103 * 16 to 32768
104 * Actual maximum value is autodetected and also
105 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700106 * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
107 * in host mode when dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200108 * 16 to 32768
109 * Actual maximum value is autodetected and also
110 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700111 * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
112 * host mode when dynamic FIFO sizing is enabled
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200113 * 16 to 32768
114 * Actual maximum value is autodetected and also
115 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700116 * @max_transfer_size: The maximum transfer size supported, in bytes
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200117 * 2047 to 65,535
118 * Actual maximum value is autodetected and also
119 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700120 * @max_packet_count: The maximum number of packets in a transfer
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200121 * 15 to 511
122 * Actual maximum value is autodetected and also
123 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700124 * @host_channels: The number of host channel registers to use
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200125 * 1 to 16
126 * Actual maximum value is autodetected and also
127 * the default.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700128 * @phy_type: Specifies the type of PHY interface to use. By default,
129 * the driver will automatically detect the phy_type.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200130 * 0 - Full Speed Phy
131 * 1 - UTMI+ Phy
132 * 2 - ULPI Phy
133 * Defaults to best available option (2, 1, then 0)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700134 * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
135 * is applicable for a phy_type of UTMI+ or ULPI. (For a
136 * ULPI phy_type, this parameter indicates the data width
137 * between the MAC and the ULPI Wrapper.) Also, this
138 * parameter is applicable only if the OTG_HSPHY_WIDTH cC
139 * parameter was set to "8 and 16 bits", meaning that the
140 * core has been configured to work at either data path
141 * width.
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200142 * 8 or 16 (default 16 if available)
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700143 * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
144 * data rate. This parameter is only applicable if phy_type
145 * is ULPI.
146 * 0 - single data rate ULPI interface with 8 bit wide
147 * data bus (default)
148 * 1 - double data rate ULPI interface with 4 bit wide
149 * data bus
150 * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
151 * external supply to drive the VBus
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200152 * 0 - Internal supply (default)
153 * 1 - External supply
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700154 * @i2c_enable: Specifies whether to use the I2Cinterface for a full
155 * speed PHY. This parameter is only applicable if phy_type
156 * is FS.
157 * 0 - No (default)
158 * 1 - Yes
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200159 * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
160 * 0 - No (default)
161 * 1 - Yes
Paul Zimmerman725acc82013-08-11 12:50:17 -0700162 * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
163 * when attached to a Full Speed or Low Speed device in
164 * host mode.
165 * 0 - Don't support low power mode (default)
166 * 1 - Support low power mode
167 * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200168 * when connected to a Low Speed device in host
169 * mode. This parameter is applicable only if
170 * host_support_fs_ls_low_power is enabled.
Paul Zimmerman725acc82013-08-11 12:50:17 -0700171 * 0 - 48 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200172 * (default when phy_type is UTMI+ or ULPI)
Paul Zimmerman725acc82013-08-11 12:50:17 -0700173 * 1 - 6 MHz
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200174 * (default when phy_type is Full Speed)
175 * @ts_dline: Enable Term Select Dline pulsing
176 * 0 - No (default)
177 * 1 - Yes
178 * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
179 * 0 - No (default for core < 2.92a)
180 * 1 - Yes (default for core >= 2.92a)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700181 * @ahbcfg: This field allows the default value of the GAHBCFG
182 * register to be overridden
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200183 * -1 - GAHBCFG value will be set to 0x06
184 * (INCR4, default)
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700185 * all others - GAHBCFG value will be overridden with
186 * this value
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200187 * Not all bits can be controlled like this, the
188 * bits defined by GAHBCFG_CTRL_MASK are controlled
189 * by the driver and are ignored in this
190 * configuration value.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700191 *
192 * The following parameters may be specified when starting the module. These
Matthijs Kooijman91121c12013-08-30 18:45:23 +0200193 * parameters define how the DWC_otg controller should be configured. A
194 * value of -1 (or any other out of range value) for any parameter means
195 * to read the value from hardware (if possible) or use the builtin
196 * default described above.
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700197 */
198struct dwc2_core_params {
Matthijs Kooijman8284f932013-04-11 18:43:47 +0200199 /*
200 * Don't add any non-int members here, this will break
201 * dwc2_set_all_params!
202 */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700203 int otg_cap;
204 int otg_ver;
205 int dma_enable;
206 int dma_desc_enable;
207 int speed;
208 int enable_dynamic_fifo;
209 int en_multiple_tx_fifo;
210 int host_rx_fifo_size;
211 int host_nperio_tx_fifo_size;
212 int host_perio_tx_fifo_size;
213 int max_transfer_size;
214 int max_packet_count;
215 int host_channels;
216 int phy_type;
217 int phy_utmi_width;
218 int phy_ulpi_ddr;
219 int phy_ulpi_ext_vbus;
220 int i2c_enable;
221 int ulpi_fs_ls;
222 int host_support_fs_ls_low_power;
223 int host_ls_low_power_phy_clk;
224 int ts_dline;
225 int reload_ctl;
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700226 int ahbcfg;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700227};
228
229/**
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200230 * struct dwc2_hw_params - Autodetected parameters.
231 *
232 * These parameters are the various parameters read from hardware
233 * registers during initialization. They typically contain the best
234 * supported or maximum value that can be configured in the
235 * corresponding dwc2_core_params value.
236 *
237 * The values that are not in dwc2_core_params are documented below.
238 *
239 * @op_mode Mode of Operation
240 * 0 - HNP- and SRP-Capable OTG (Host & Device)
241 * 1 - SRP-Capable OTG (Host & Device)
242 * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
243 * 3 - SRP-Capable Device
244 * 4 - Non-OTG Device
245 * 5 - SRP-Capable Host
246 * 6 - Non-OTG Host
247 * @arch Architecture
248 * 0 - Slave only
249 * 1 - External DMA
250 * 2 - Internal DMA
251 * @power_optimized Are power optimizations enabled?
252 * @num_dev_ep Number of device endpoints available
253 * @num_dev_perio_in_ep Number of device periodic IN endpoints
254 * avaialable
255 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
256 * Depth
257 * 0 to 30
258 * @host_perio_tx_q_depth
259 * Host Mode Periodic Request Queue Depth
260 * 2, 4 or 8
261 * @nperio_tx_q_depth
262 * Non-Periodic Request Queue Depth
263 * 2, 4 or 8
264 * @hs_phy_type High-speed PHY interface type
265 * 0 - High-speed interface not supported
266 * 1 - UTMI+
267 * 2 - ULPI
268 * 3 - UTMI+ and ULPI
269 * @fs_phy_type Full-speed PHY interface type
270 * 0 - Full speed interface not supported
271 * 1 - Dedicated full speed interface
272 * 2 - FS pins shared with UTMI+ pins
273 * 3 - FS pins shared with ULPI pins
274 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200275 * @utmi_phy_data_width UTMI+ PHY data width
276 * 0 - 8 bits
277 * 1 - 16 bits
278 * 2 - 8 or 16 bits
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200279 * @snpsid: Value from SNPSID register
280 */
281struct dwc2_hw_params {
282 unsigned op_mode:3;
283 unsigned arch:2;
284 unsigned dma_desc_enable:1;
285 unsigned enable_dynamic_fifo:1;
286 unsigned en_multiple_tx_fifo:1;
287 unsigned host_rx_fifo_size:16;
288 unsigned host_nperio_tx_fifo_size:16;
289 unsigned host_perio_tx_fifo_size:16;
290 unsigned nperio_tx_q_depth:3;
291 unsigned host_perio_tx_q_depth:3;
292 unsigned dev_token_q_depth:5;
293 unsigned max_transfer_size:26;
294 unsigned max_packet_count:11;
295 unsigned host_channels:4;
296 unsigned hs_phy_type:2;
297 unsigned fs_phy_type:2;
298 unsigned i2c_enable:1;
299 unsigned num_dev_ep:4;
300 unsigned num_dev_perio_in_ep:4;
301 unsigned total_fifo_size:16;
302 unsigned power_optimized:1;
Matthijs Kooijmande4a1932013-08-30 18:45:22 +0200303 unsigned utmi_phy_data_width:2;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200304 u32 snpsid;
305};
306
307/**
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700308 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
309 * and periodic schedules
310 *
311 * @dev: The struct device pointer
312 * @regs: Pointer to controller regs
313 * @core_params: Parameters that define how the core should be configured
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200314 * @hw_params: Parameters that were autodetected from the
315 * hardware registers
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700316 * @op_state: The operational State, during transitions (a_host=>
317 * a_peripheral and b_device=>b_host) this may not match
318 * the core, but allows the software to determine
319 * transitions
320 * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
321 * transfer are in process of being queued
322 * @srp_success: Stores status of SRP request in the case of a FS PHY
323 * with an I2C interface
324 * @wq_otg: Workqueue object used for handling of some interrupts
325 * @wf_otg: Work object for handling Connector ID Status Change
326 * interrupt
327 * @wkp_timer: Timer object for handling Wakeup Detected interrupt
328 * @lx_state: Lx state of connected device
329 * @flags: Flags for handling root port state changes
330 * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
331 * Transfers associated with these QHs are not currently
332 * assigned to a host channel.
333 * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
334 * Transfers associated with these QHs are currently
335 * assigned to a host channel.
336 * @non_periodic_qh_ptr: Pointer to next QH to process in the active
337 * non-periodic schedule
338 * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
339 * list of QHs for periodic transfers that are _not_
340 * scheduled for the next frame. Each QH in the list has an
341 * interval counter that determines when it needs to be
342 * scheduled for execution. This scheduling mechanism
343 * allows only a simple calculation for periodic bandwidth
344 * used (i.e. must assume that all periodic transfers may
345 * need to execute in the same frame). However, it greatly
346 * simplifies scheduling and should be sufficient for the
347 * vast majority of OTG hosts, which need to connect to a
348 * small number of peripherals at one time. Items move from
349 * this list to periodic_sched_ready when the QH interval
350 * counter is 0 at SOF.
351 * @periodic_sched_ready: List of periodic QHs that are ready for execution in
352 * the next frame, but have not yet been assigned to host
353 * channels. Items move from this list to
354 * periodic_sched_assigned as host channels become
355 * available during the current frame.
356 * @periodic_sched_assigned: List of periodic QHs to be executed in the next
357 * frame that are assigned to host channels. Items move
358 * from this list to periodic_sched_queued as the
359 * transactions for the QH are queued to the DWC_otg
360 * controller.
361 * @periodic_sched_queued: List of periodic QHs that have been queued for
362 * execution. Items move from this list to either
363 * periodic_sched_inactive or periodic_sched_ready when the
364 * channel associated with the transfer is released. If the
365 * interval for the QH is 1, the item moves to
366 * periodic_sched_ready because it must be rescheduled for
367 * the next frame. Otherwise, the item moves to
368 * periodic_sched_inactive.
369 * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
370 * This value is in microseconds per (micro)frame. The
371 * assumption is that all periodic transfers may occur in
372 * the same (micro)frame.
373 * @frame_number: Frame number read from the core at SOF. The value ranges
374 * from 0 to HFNUM_MAX_FRNUM.
375 * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
376 * SOF enable/disable.
377 * @free_hc_list: Free host channels in the controller. This is a list of
378 * struct dwc2_host_chan items.
379 * @periodic_channels: Number of host channels assigned to periodic transfers.
380 * Currently assuming that there is a dedicated host
381 * channel for each periodic transaction and at least one
382 * host channel is available for non-periodic transactions.
383 * @non_periodic_channels: Number of host channels assigned to non-periodic
384 * transfers
385 * @hc_ptr_array: Array of pointers to the host channel descriptors.
386 * Allows accessing a host channel descriptor given the
387 * host channel number. This is useful in interrupt
388 * handlers.
389 * @status_buf: Buffer used for data received during the status phase of
390 * a control transfer.
391 * @status_buf_dma: DMA address for status_buf
392 * @start_work: Delayed work for handling host A-cable connection
393 * @reset_work: Delayed work for handling a port reset
394 * @lock: Spinlock that protects all the driver data structures
395 * @priv: Stores a pointer to the struct usb_hcd
396 * @otg_port: OTG port number
397 * @frame_list: Frame list
398 * @frame_list_dma: Frame list DMA address
399 */
400struct dwc2_hsotg {
401 struct device *dev;
402 void __iomem *regs;
Matthijs Kooijman9badec22013-08-30 18:45:21 +0200403 /** Params detected from hardware */
404 struct dwc2_hw_params hw_params;
405 /** Params to actually use */
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700406 struct dwc2_core_params *core_params;
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700407 enum usb_otg_state op_state;
408
409 unsigned int queuing_high_bandwidth:1;
410 unsigned int srp_success:1;
411
412 struct workqueue_struct *wq_otg;
413 struct work_struct wf_otg;
414 struct timer_list wkp_timer;
415 enum dwc2_lx_state lx_state;
416
417 union dwc2_hcd_internal_flags {
418 u32 d32;
419 struct {
420 unsigned port_connect_status_change:1;
421 unsigned port_connect_status:1;
422 unsigned port_reset_change:1;
423 unsigned port_enable_change:1;
424 unsigned port_suspend_change:1;
425 unsigned port_over_current_change:1;
426 unsigned port_l1_change:1;
427 unsigned reserved:26;
428 } b;
429 } flags;
430
431 struct list_head non_periodic_sched_inactive;
432 struct list_head non_periodic_sched_active;
433 struct list_head *non_periodic_qh_ptr;
434 struct list_head periodic_sched_inactive;
435 struct list_head periodic_sched_ready;
436 struct list_head periodic_sched_assigned;
437 struct list_head periodic_sched_queued;
438 u16 periodic_usecs;
439 u16 frame_number;
440 u16 periodic_qh_count;
441
442#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
443#define FRAME_NUM_ARRAY_SIZE 1000
444 u16 last_frame_num;
445 u16 *frame_num_array;
446 u16 *last_frame_num_array;
447 int frame_num_idx;
448 int dumped_frame_num_array;
449#endif
450
451 struct list_head free_hc_list;
452 int periodic_channels;
453 int non_periodic_channels;
454 struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
455 u8 *status_buf;
456 dma_addr_t status_buf_dma;
457#define DWC2_HCD_STATUS_BUF_SIZE 64
458
459 struct delayed_work start_work;
460 struct delayed_work reset_work;
461 spinlock_t lock;
462 void *priv;
463 u8 otg_port;
464 u32 *frame_list;
465 dma_addr_t frame_list_dma;
466
467 /* DWC OTG HW Release versions */
468#define DWC2_CORE_REV_2_71a 0x4f54271a
469#define DWC2_CORE_REV_2_90a 0x4f54290a
470#define DWC2_CORE_REV_2_92a 0x4f54292a
471#define DWC2_CORE_REV_2_94a 0x4f54294a
472#define DWC2_CORE_REV_3_00a 0x4f54300a
473
474#ifdef DEBUG
475 u32 frrem_samples;
476 u64 frrem_accum;
477
478 u32 hfnum_7_samples_a;
479 u64 hfnum_7_frrem_accum_a;
480 u32 hfnum_0_samples_a;
481 u64 hfnum_0_frrem_accum_a;
482 u32 hfnum_other_samples_a;
483 u64 hfnum_other_frrem_accum_a;
484
485 u32 hfnum_7_samples_b;
486 u64 hfnum_7_frrem_accum_b;
487 u32 hfnum_0_samples_b;
488 u64 hfnum_0_frrem_accum_b;
489 u32 hfnum_other_samples_b;
490 u64 hfnum_other_frrem_accum_b;
491#endif
492};
493
494/* Reasons for halting a host channel */
495enum dwc2_halt_status {
496 DWC2_HC_XFER_NO_HALT_STATUS,
497 DWC2_HC_XFER_COMPLETE,
498 DWC2_HC_XFER_URB_COMPLETE,
499 DWC2_HC_XFER_ACK,
500 DWC2_HC_XFER_NAK,
501 DWC2_HC_XFER_NYET,
502 DWC2_HC_XFER_STALL,
503 DWC2_HC_XFER_XACT_ERR,
504 DWC2_HC_XFER_FRAME_OVERRUN,
505 DWC2_HC_XFER_BABBLE_ERR,
506 DWC2_HC_XFER_DATA_TOGGLE_ERR,
507 DWC2_HC_XFER_AHB_ERR,
508 DWC2_HC_XFER_PERIODIC_INCOMPLETE,
509 DWC2_HC_XFER_URB_DEQUEUE,
510};
511
512/*
513 * The following functions support initialization of the core driver component
514 * and the DWC_otg controller
515 */
516extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
517
518/*
519 * Host core Functions.
520 * The following functions support managing the DWC_otg controller in host
521 * mode.
522 */
523extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
524extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
525 enum dwc2_halt_status halt_status);
526extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
527 struct dwc2_host_chan *chan);
528extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
529 struct dwc2_host_chan *chan);
530extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
531 struct dwc2_host_chan *chan);
532extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
533 struct dwc2_host_chan *chan);
534extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
535 struct dwc2_host_chan *chan);
536extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
537extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
538
539extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
540extern int dwc2_check_core_status(struct dwc2_hsotg *hsotg);
541
542/*
543 * Common core Functions.
544 * The following functions support managing the DWC_otg controller in either
545 * device or host mode.
546 */
547extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
548extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
549extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
550
Matthijs Kooijman6706c722013-04-11 17:52:41 +0200551extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700552extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
553extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
554
555/* This function should be called on every hardware interrupt. */
556extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
557
558/* OTG Core Parameters */
559
560/*
561 * Specifies the OTG capabilities. The driver will automatically
562 * detect the value for this parameter if none is specified.
563 * 0 - HNP and SRP capable (default)
564 * 1 - SRP Only capable
565 * 2 - No HNP/SRP capable
566 */
567extern int dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
568#define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
569#define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
570#define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
571
572/*
573 * Specifies whether to use slave or DMA mode for accessing the data
574 * FIFOs. The driver will automatically detect the value for this
575 * parameter if none is specified.
576 * 0 - Slave
577 * 1 - DMA (default, if available)
578 */
579extern int dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
580
581/*
582 * When DMA mode is enabled specifies whether to use
583 * address DMA or DMA Descritor mode for accessing the data
584 * FIFOs in device mode. The driver will automatically detect
585 * the value for this parameter if none is specified.
586 * 0 - address DMA
587 * 1 - DMA Descriptor(default, if available)
588 */
589extern int dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
590
591/*
592 * Specifies the maximum speed of operation in host and device mode.
593 * The actual speed depends on the speed of the attached device and
594 * the value of phy_type. The actual speed depends on the speed of the
595 * attached device.
596 * 0 - High Speed (default)
597 * 1 - Full Speed
598 */
599extern int dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
600#define DWC2_SPEED_PARAM_HIGH 0
601#define DWC2_SPEED_PARAM_FULL 1
602
603/*
604 * Specifies whether low power mode is supported when attached
605 * to a Full Speed or Low Speed device in host mode.
606 *
607 * 0 - Don't support low power mode (default)
608 * 1 - Support low power mode
609 */
610extern int dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
611 int val);
612
613/*
614 * Specifies the PHY clock rate in low power mode when connected to a
615 * Low Speed device in host mode. This parameter is applicable only if
616 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
617 * then defaults to 6 MHZ otherwise 48 MHZ.
618 *
619 * 0 - 48 MHz
620 * 1 - 6 MHz
621 */
622extern int dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
623 int val);
624#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
625#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
626
627/*
628 * 0 - Use cC FIFO size parameters
629 * 1 - Allow dynamic FIFO sizing (default)
630 */
631extern int dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
632 int val);
633
634/*
635 * Number of 4-byte words in the Rx FIFO in host mode when dynamic
636 * FIFO sizing is enabled.
637 * 16 to 32768 (default 1024)
638 */
639extern int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
640
641/*
642 * Number of 4-byte words in the non-periodic Tx FIFO in host mode
643 * when Dynamic FIFO sizing is enabled in the core.
644 * 16 to 32768 (default 256)
645 */
646extern int dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
647 int val);
648
649/*
650 * Number of 4-byte words in the host periodic Tx FIFO when dynamic
651 * FIFO sizing is enabled.
652 * 16 to 32768 (default 256)
653 */
654extern int dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
655 int val);
656
657/*
658 * The maximum transfer size supported in bytes.
659 * 2047 to 65,535 (default 65,535)
660 */
661extern int dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
662
663/*
664 * The maximum number of packets in a transfer.
665 * 15 to 511 (default 511)
666 */
667extern int dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
668
669/*
670 * The number of host channel registers to use.
671 * 1 to 16 (default 11)
672 * Note: The FPGA configuration supports a maximum of 11 host channels.
673 */
674extern int dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
675
676/*
677 * Specifies the type of PHY interface to use. By default, the driver
678 * will automatically detect the phy_type.
679 *
680 * 0 - Full Speed PHY
681 * 1 - UTMI+ (default)
682 * 2 - ULPI
683 */
684extern int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
685#define DWC2_PHY_TYPE_PARAM_FS 0
686#define DWC2_PHY_TYPE_PARAM_UTMI 1
687#define DWC2_PHY_TYPE_PARAM_ULPI 2
688
689/*
690 * Specifies the UTMI+ Data Width. This parameter is
691 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
692 * PHY_TYPE, this parameter indicates the data width between
693 * the MAC and the ULPI Wrapper.) Also, this parameter is
694 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
695 * to "8 and 16 bits", meaning that the core has been
696 * configured to work at either data path width.
697 *
698 * 8 or 16 bits (default 16)
699 */
700extern int dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
701
702/*
703 * Specifies whether the ULPI operates at double or single
704 * data rate. This parameter is only applicable if PHY_TYPE is
705 * ULPI.
706 *
707 * 0 - single data rate ULPI interface with 8 bit wide data
708 * bus (default)
709 * 1 - double data rate ULPI interface with 4 bit wide data
710 * bus
711 */
712extern int dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
713
714/*
715 * Specifies whether to use the internal or external supply to
716 * drive the vbus with a ULPI phy.
717 */
718extern int dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
719#define DWC2_PHY_ULPI_INTERNAL_VBUS 0
720#define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
721
722/*
723 * Specifies whether to use the I2Cinterface for full speed PHY. This
724 * parameter is only applicable if PHY_TYPE is FS.
725 * 0 - No (default)
726 * 1 - Yes
727 */
728extern int dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
729
730extern int dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
731
732extern int dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
733
734/*
735 * Specifies whether dedicated transmit FIFOs are
736 * enabled for non periodic IN endpoints in device mode
737 * 0 - No
738 * 1 - Yes
739 */
740extern int dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
741 int val);
742
743extern int dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
744
Paul Zimmerman4d3190e2013-07-16 12:22:12 -0700745extern int dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
Paul Zimmerman56f5b1c2013-03-11 17:47:58 -0700746
747extern int dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
748
749/*
750 * Dump core registers and SPRAM
751 */
752extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
753extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
754extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
755
756/*
757 * Return OTG version - either 1.3 or 2.0
758 */
759extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
760
761#endif /* __DWC2_CORE_H__ */