2 * core.h - DesignWare HS OTG Controller common declarations
4 * Copyright (C) 2004-2013 Synopsys, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
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.
37 #ifndef __DWC2_CORE_H__
38 #define __DWC2_CORE_H__
40 #include <linux/phy/phy.h>
41 #include <linux/regulator/consumer.h>
42 #include <linux/usb/gadget.h>
43 #include <linux/usb/otg.h>
44 #include <linux/usb/phy.h>
47 #ifdef DWC2_LOG_WRITES
48 static inline void do_write(u32 value, void *addr)
51 pr_info("INFO:: wrote %08x to %p\n", value, addr);
55 #define writel(v, a) do_write(v, a)
58 /* Maximum number of Endpoints/HostChannels */
59 #define MAX_EPS_CHANNELS 16
61 /* s3c-hsotg declarations */
62 static const char * const s3c_hsotg_supply_names[] = {
63 "vusb_d", /* digital USB supply, 1.2V */
64 "vusb_a", /* analog USB supply, 1.1V */
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
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.
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
85 #define EP0_MPS_LIMIT 64
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
111 * @sent_zlp: Set if we've sent a zero-length packet.
112 * @total_data: The total number of data bytes done.
113 * @fifo_size: The size of the FIFO (for periodic IN endpoints)
114 * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
115 * @last_load: The offset of data for the last start of request.
116 * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
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.
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)
130 struct s3c_hsotg_ep {
132 struct list_head queue;
133 struct s3c_hsotg *parent;
134 struct s3c_hsotg_req *req;
135 struct dentry *debugfs;
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;
143 unsigned char dir_in;
146 unsigned char interval;
148 unsigned int halted:1;
149 unsigned int periodic:1;
150 unsigned int isochronous:1;
151 unsigned int sent_zlp:1;
157 * struct s3c_hsotg - driver state.
158 * @dev: The parent device supplied to the probe function
159 * @driver: USB gadget driver
160 * @phy: The otg phy transceiver structure for phy control.
161 * @uphy: The otg phy transceiver structure for old USB phy control.
162 * @plat: The platform specific configuration data. This can be removed once
163 * all SoCs support usb transceiver.
164 * @regs: The memory area mapped for accessing registers.
165 * @irq: The IRQ number we are using
166 * @supplies: Definition of USB power supplies
167 * @phyif: PHY interface width
168 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
169 * @num_of_eps: Number of available EPs (excluding EP0)
170 * @debug_root: root directrory for debugfs.
171 * @debug_file: main status file for debugfs.
172 * @debug_fifo: FIFO status file for debugfs.
173 * @ep0_reply: Request used for ep0 reply.
174 * @ep0_buff: Buffer for EP0 reply data, if needed.
175 * @ctrl_buff: Buffer for EP0 control requests.
176 * @ctrl_req: Request for EP0 control packets.
177 * @setup: NAK management for EP0 SETUP
178 * @last_rst: Time of last reset
179 * @eps: The endpoints being supplied to the gadget framework
183 struct usb_gadget_driver *driver;
185 struct usb_phy *uphy;
186 struct s3c_hsotg_plat *plat;
194 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)];
198 unsigned int dedicated_fifos:1;
199 unsigned char num_of_eps;
201 struct dentry *debug_root;
202 struct dentry *debug_file;
203 struct dentry *debug_fifo;
205 struct usb_request *ep0_reply;
206 struct usb_request *ctrl_req;
210 struct usb_gadget gadget;
212 unsigned long last_rst;
213 struct s3c_hsotg_ep *eps;
217 * struct s3c_hsotg_req - data transfer request
218 * @req: The USB gadget request
219 * @queue: The list of requests for the endpoint this is queued for.
220 * @in_progress: Has already had size/packets written to core
221 * @mapped: DMA buffer for this request has been mapped via dma_map_single().
223 struct s3c_hsotg_req {
224 struct usb_request req;
225 struct list_head queue;
226 unsigned char in_progress;
227 unsigned char mapped;
230 #define call_gadget(_hs, _entry) \
232 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
233 (_hs)->driver && (_hs)->driver->_entry) { \
234 spin_unlock(&_hs->lock); \
235 (_hs)->driver->_entry(&(_hs)->gadget); \
236 spin_lock(&_hs->lock); \
241 struct dwc2_host_chan;
245 DWC2_L0, /* On state */
246 DWC2_L1, /* LPM sleep state */
247 DWC2_L2, /* USB suspend state */
248 DWC2_L3, /* Off state */
252 * struct dwc2_core_params - Parameters for configuring the core
254 * @otg_cap: Specifies the OTG capabilities.
255 * 0 - HNP and SRP capable
256 * 1 - SRP Only capable
257 * 2 - No HNP/SRP capable (always available)
258 * Defaults to best available option (0, 1, then 2)
259 * @otg_ver: OTG version supported
262 * @dma_enable: Specifies whether to use slave or DMA mode for accessing
263 * the data FIFOs. The driver will automatically detect the
264 * value for this parameter if none is specified.
265 * 0 - Slave (always available)
266 * 1 - DMA (default, if available)
267 * @dma_desc_enable: When DMA mode is enabled, specifies whether to use
268 * address DMA mode or descriptor DMA mode for accessing
269 * the data FIFOs. The driver will automatically detect the
270 * value for this if none is specified.
272 * 1 - Descriptor DMA (default, if available)
273 * @speed: Specifies the maximum speed of operation in host and
274 * device mode. The actual speed depends on the speed of
275 * the attached device and the value of phy_type.
277 * (default when phy_type is UTMI+ or ULPI)
279 * (default when phy_type is Full Speed)
280 * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
281 * 1 - Allow dynamic FIFO sizing (default, if available)
282 * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
284 * @host_rx_fifo_size: Number of 4-byte words in the Rx FIFO in host mode when
285 * dynamic FIFO sizing is enabled
287 * Actual maximum value is autodetected and also
289 * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
290 * in host mode when dynamic FIFO sizing is enabled
292 * Actual maximum value is autodetected and also
294 * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
295 * host mode when dynamic FIFO sizing is enabled
297 * Actual maximum value is autodetected and also
299 * @max_transfer_size: The maximum transfer size supported, in bytes
301 * Actual maximum value is autodetected and also
303 * @max_packet_count: The maximum number of packets in a transfer
305 * Actual maximum value is autodetected and also
307 * @host_channels: The number of host channel registers to use
309 * Actual maximum value is autodetected and also
311 * @phy_type: Specifies the type of PHY interface to use. By default,
312 * the driver will automatically detect the phy_type.
316 * Defaults to best available option (2, 1, then 0)
317 * @phy_utmi_width: Specifies the UTMI+ Data Width (in bits). This parameter
318 * is applicable for a phy_type of UTMI+ or ULPI. (For a
319 * ULPI phy_type, this parameter indicates the data width
320 * between the MAC and the ULPI Wrapper.) Also, this
321 * parameter is applicable only if the OTG_HSPHY_WIDTH cC
322 * parameter was set to "8 and 16 bits", meaning that the
323 * core has been configured to work at either data path
325 * 8 or 16 (default 16 if available)
326 * @phy_ulpi_ddr: Specifies whether the ULPI operates at double or single
327 * data rate. This parameter is only applicable if phy_type
329 * 0 - single data rate ULPI interface with 8 bit wide
331 * 1 - double data rate ULPI interface with 4 bit wide
333 * @phy_ulpi_ext_vbus: For a ULPI phy, specifies whether to use the internal or
334 * external supply to drive the VBus
335 * 0 - Internal supply (default)
336 * 1 - External supply
337 * @i2c_enable: Specifies whether to use the I2Cinterface for a full
338 * speed PHY. This parameter is only applicable if phy_type
342 * @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
345 * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
346 * when attached to a Full Speed or Low Speed device in
348 * 0 - Don't support low power mode (default)
349 * 1 - Support low power mode
350 * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
351 * when connected to a Low Speed device in host
352 * mode. This parameter is applicable only if
353 * host_support_fs_ls_low_power is enabled.
355 * (default when phy_type is UTMI+ or ULPI)
357 * (default when phy_type is Full Speed)
358 * @ts_dline: Enable Term Select Dline pulsing
361 * @reload_ctl: Allow dynamic reloading of HFIR register during runtime
362 * 0 - No (default for core < 2.92a)
363 * 1 - Yes (default for core >= 2.92a)
364 * @ahbcfg: This field allows the default value of the GAHBCFG
365 * register to be overridden
366 * -1 - GAHBCFG value will be set to 0x06
368 * all others - GAHBCFG value will be overridden with
370 * Not all bits can be controlled like this, the
371 * bits defined by GAHBCFG_CTRL_MASK are controlled
372 * by the driver and are ignored in this
373 * configuration value.
374 * @uframe_sched: True to enable the microframe scheduler
376 * The following parameters may be specified when starting the module. These
377 * parameters define how the DWC_otg controller should be configured. A
378 * value of -1 (or any other out of range value) for any parameter means
379 * to read the value from hardware (if possible) or use the builtin
380 * default described above.
382 struct dwc2_core_params {
384 * Don't add any non-int members here, this will break
385 * dwc2_set_all_params!
392 int enable_dynamic_fifo;
393 int en_multiple_tx_fifo;
394 int host_rx_fifo_size;
395 int host_nperio_tx_fifo_size;
396 int host_perio_tx_fifo_size;
397 int max_transfer_size;
398 int max_packet_count;
403 int phy_ulpi_ext_vbus;
406 int host_support_fs_ls_low_power;
407 int host_ls_low_power_phy_clk;
415 * struct dwc2_hw_params - Autodetected parameters.
417 * These parameters are the various parameters read from hardware
418 * registers during initialization. They typically contain the best
419 * supported or maximum value that can be configured in the
420 * corresponding dwc2_core_params value.
422 * The values that are not in dwc2_core_params are documented below.
424 * @op_mode Mode of Operation
425 * 0 - HNP- and SRP-Capable OTG (Host & Device)
426 * 1 - SRP-Capable OTG (Host & Device)
427 * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
428 * 3 - SRP-Capable Device
430 * 5 - SRP-Capable Host
436 * @power_optimized Are power optimizations enabled?
437 * @num_dev_ep Number of device endpoints available
438 * @num_dev_perio_in_ep Number of device periodic IN endpoints
440 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
443 * @host_perio_tx_q_depth
444 * Host Mode Periodic Request Queue Depth
447 * Non-Periodic Request Queue Depth
449 * @hs_phy_type High-speed PHY interface type
450 * 0 - High-speed interface not supported
454 * @fs_phy_type Full-speed PHY interface type
455 * 0 - Full speed interface not supported
456 * 1 - Dedicated full speed interface
457 * 2 - FS pins shared with UTMI+ pins
458 * 3 - FS pins shared with ULPI pins
459 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
460 * @utmi_phy_data_width UTMI+ PHY data width
464 * @snpsid: Value from SNPSID register
466 struct dwc2_hw_params {
469 unsigned dma_desc_enable:1;
470 unsigned enable_dynamic_fifo:1;
471 unsigned en_multiple_tx_fifo:1;
472 unsigned host_rx_fifo_size:16;
473 unsigned host_nperio_tx_fifo_size:16;
474 unsigned host_perio_tx_fifo_size:16;
475 unsigned nperio_tx_q_depth:3;
476 unsigned host_perio_tx_q_depth:3;
477 unsigned dev_token_q_depth:5;
478 unsigned max_transfer_size:26;
479 unsigned max_packet_count:11;
480 unsigned host_channels:5;
481 unsigned hs_phy_type:2;
482 unsigned fs_phy_type:2;
483 unsigned i2c_enable:1;
484 unsigned num_dev_ep:4;
485 unsigned num_dev_perio_in_ep:4;
486 unsigned total_fifo_size:16;
487 unsigned power_optimized:1;
488 unsigned utmi_phy_data_width:2;
493 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
494 * and periodic schedules
496 * @dev: The struct device pointer
497 * @regs: Pointer to controller regs
498 * @core_params: Parameters that define how the core should be configured
499 * @hw_params: Parameters that were autodetected from the
501 * @op_state: The operational State, during transitions (a_host=>
502 * a_peripheral and b_device=>b_host) this may not match
503 * the core, but allows the software to determine
505 * @dr_mode: Requested mode of operation, one of following:
506 * - USB_DR_MODE_PERIPHERAL
509 * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
510 * transfer are in process of being queued
511 * @srp_success: Stores status of SRP request in the case of a FS PHY
512 * with an I2C interface
513 * @wq_otg: Workqueue object used for handling of some interrupts
514 * @wf_otg: Work object for handling Connector ID Status Change
516 * @wkp_timer: Timer object for handling Wakeup Detected interrupt
517 * @lx_state: Lx state of connected device
518 * @flags: Flags for handling root port state changes
519 * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
520 * Transfers associated with these QHs are not currently
521 * assigned to a host channel.
522 * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
523 * Transfers associated with these QHs are currently
524 * assigned to a host channel.
525 * @non_periodic_qh_ptr: Pointer to next QH to process in the active
526 * non-periodic schedule
527 * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
528 * list of QHs for periodic transfers that are _not_
529 * scheduled for the next frame. Each QH in the list has an
530 * interval counter that determines when it needs to be
531 * scheduled for execution. This scheduling mechanism
532 * allows only a simple calculation for periodic bandwidth
533 * used (i.e. must assume that all periodic transfers may
534 * need to execute in the same frame). However, it greatly
535 * simplifies scheduling and should be sufficient for the
536 * vast majority of OTG hosts, which need to connect to a
537 * small number of peripherals at one time. Items move from
538 * this list to periodic_sched_ready when the QH interval
539 * counter is 0 at SOF.
540 * @periodic_sched_ready: List of periodic QHs that are ready for execution in
541 * the next frame, but have not yet been assigned to host
542 * channels. Items move from this list to
543 * periodic_sched_assigned as host channels become
544 * available during the current frame.
545 * @periodic_sched_assigned: List of periodic QHs to be executed in the next
546 * frame that are assigned to host channels. Items move
547 * from this list to periodic_sched_queued as the
548 * transactions for the QH are queued to the DWC_otg
550 * @periodic_sched_queued: List of periodic QHs that have been queued for
551 * execution. Items move from this list to either
552 * periodic_sched_inactive or periodic_sched_ready when the
553 * channel associated with the transfer is released. If the
554 * interval for the QH is 1, the item moves to
555 * periodic_sched_ready because it must be rescheduled for
556 * the next frame. Otherwise, the item moves to
557 * periodic_sched_inactive.
558 * @periodic_usecs: Total bandwidth claimed so far for periodic transfers.
559 * This value is in microseconds per (micro)frame. The
560 * assumption is that all periodic transfers may occur in
561 * the same (micro)frame.
562 * @frame_usecs: Internal variable used by the microframe scheduler
563 * @frame_number: Frame number read from the core at SOF. The value ranges
564 * from 0 to HFNUM_MAX_FRNUM.
565 * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
566 * SOF enable/disable.
567 * @free_hc_list: Free host channels in the controller. This is a list of
568 * struct dwc2_host_chan items.
569 * @periodic_channels: Number of host channels assigned to periodic transfers.
570 * Currently assuming that there is a dedicated host
571 * channel for each periodic transaction and at least one
572 * host channel is available for non-periodic transactions.
573 * @non_periodic_channels: Number of host channels assigned to non-periodic
575 * @available_host_channels Number of host channels available for the microframe
577 * @hc_ptr_array: Array of pointers to the host channel descriptors.
578 * Allows accessing a host channel descriptor given the
579 * host channel number. This is useful in interrupt
581 * @status_buf: Buffer used for data received during the status phase of
582 * a control transfer.
583 * @status_buf_dma: DMA address for status_buf
584 * @start_work: Delayed work for handling host A-cable connection
585 * @reset_work: Delayed work for handling a port reset
586 * @lock: Spinlock that protects all the driver data structures
587 * @priv: Stores a pointer to the struct usb_hcd
588 * @otg_port: OTG port number
589 * @frame_list: Frame list
590 * @frame_list_dma: Frame list DMA address
595 /** Params detected from hardware */
596 struct dwc2_hw_params hw_params;
597 /** Params to actually use */
598 struct dwc2_core_params *core_params;
599 enum usb_otg_state op_state;
600 enum usb_dr_mode dr_mode;
602 unsigned int queuing_high_bandwidth:1;
603 unsigned int srp_success:1;
605 struct workqueue_struct *wq_otg;
606 struct work_struct wf_otg;
607 struct timer_list wkp_timer;
608 enum dwc2_lx_state lx_state;
610 union dwc2_hcd_internal_flags {
613 unsigned port_connect_status_change:1;
614 unsigned port_connect_status:1;
615 unsigned port_reset_change:1;
616 unsigned port_enable_change:1;
617 unsigned port_suspend_change:1;
618 unsigned port_over_current_change:1;
619 unsigned port_l1_change:1;
620 unsigned reserved:26;
624 struct list_head non_periodic_sched_inactive;
625 struct list_head non_periodic_sched_active;
626 struct list_head *non_periodic_qh_ptr;
627 struct list_head periodic_sched_inactive;
628 struct list_head periodic_sched_ready;
629 struct list_head periodic_sched_assigned;
630 struct list_head periodic_sched_queued;
634 u16 periodic_qh_count;
636 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
637 #define FRAME_NUM_ARRAY_SIZE 1000
639 u16 *frame_num_array;
640 u16 *last_frame_num_array;
642 int dumped_frame_num_array;
645 struct list_head free_hc_list;
646 int periodic_channels;
647 int non_periodic_channels;
648 int available_host_channels;
649 struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
651 dma_addr_t status_buf_dma;
652 #define DWC2_HCD_STATUS_BUF_SIZE 64
654 struct delayed_work start_work;
655 struct delayed_work reset_work;
660 dma_addr_t frame_list_dma;
662 /* DWC OTG HW Release versions */
663 #define DWC2_CORE_REV_2_71a 0x4f54271a
664 #define DWC2_CORE_REV_2_90a 0x4f54290a
665 #define DWC2_CORE_REV_2_92a 0x4f54292a
666 #define DWC2_CORE_REV_2_94a 0x4f54294a
667 #define DWC2_CORE_REV_3_00a 0x4f54300a
673 u32 hfnum_7_samples_a;
674 u64 hfnum_7_frrem_accum_a;
675 u32 hfnum_0_samples_a;
676 u64 hfnum_0_frrem_accum_a;
677 u32 hfnum_other_samples_a;
678 u64 hfnum_other_frrem_accum_a;
680 u32 hfnum_7_samples_b;
681 u64 hfnum_7_frrem_accum_b;
682 u32 hfnum_0_samples_b;
683 u64 hfnum_0_frrem_accum_b;
684 u32 hfnum_other_samples_b;
685 u64 hfnum_other_frrem_accum_b;
689 /* Reasons for halting a host channel */
690 enum dwc2_halt_status {
691 DWC2_HC_XFER_NO_HALT_STATUS,
692 DWC2_HC_XFER_COMPLETE,
693 DWC2_HC_XFER_URB_COMPLETE,
698 DWC2_HC_XFER_XACT_ERR,
699 DWC2_HC_XFER_FRAME_OVERRUN,
700 DWC2_HC_XFER_BABBLE_ERR,
701 DWC2_HC_XFER_DATA_TOGGLE_ERR,
702 DWC2_HC_XFER_AHB_ERR,
703 DWC2_HC_XFER_PERIODIC_INCOMPLETE,
704 DWC2_HC_XFER_URB_DEQUEUE,
708 * The following functions support initialization of the core driver component
709 * and the DWC_otg controller
711 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
714 * Host core Functions.
715 * The following functions support managing the DWC_otg controller in host
718 extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
719 extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
720 enum dwc2_halt_status halt_status);
721 extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
722 struct dwc2_host_chan *chan);
723 extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
724 struct dwc2_host_chan *chan);
725 extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
726 struct dwc2_host_chan *chan);
727 extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
728 struct dwc2_host_chan *chan);
729 extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
730 struct dwc2_host_chan *chan);
731 extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
732 extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
734 extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
735 extern bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg);
738 * Common core Functions.
739 * The following functions support managing the DWC_otg controller in either
740 * device or host mode.
742 extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
743 extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
744 extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
746 extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq);
747 extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
748 extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
750 /* This function should be called on every hardware interrupt. */
751 extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
753 /* OTG Core Parameters */
756 * Specifies the OTG capabilities. The driver will automatically
757 * detect the value for this parameter if none is specified.
758 * 0 - HNP and SRP capable (default)
759 * 1 - SRP Only capable
760 * 2 - No HNP/SRP capable
762 extern void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
763 #define DWC2_CAP_PARAM_HNP_SRP_CAPABLE 0
764 #define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE 1
765 #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
768 * Specifies whether to use slave or DMA mode for accessing the data
769 * FIFOs. The driver will automatically detect the value for this
770 * parameter if none is specified.
772 * 1 - DMA (default, if available)
774 extern void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
777 * When DMA mode is enabled specifies whether to use
778 * address DMA or DMA Descritor mode for accessing the data
779 * FIFOs in device mode. The driver will automatically detect
780 * the value for this parameter if none is specified.
782 * 1 - DMA Descriptor(default, if available)
784 extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
787 * Specifies the maximum speed of operation in host and device mode.
788 * The actual speed depends on the speed of the attached device and
789 * the value of phy_type. The actual speed depends on the speed of the
791 * 0 - High Speed (default)
794 extern void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
795 #define DWC2_SPEED_PARAM_HIGH 0
796 #define DWC2_SPEED_PARAM_FULL 1
799 * Specifies whether low power mode is supported when attached
800 * to a Full Speed or Low Speed device in host mode.
802 * 0 - Don't support low power mode (default)
803 * 1 - Support low power mode
805 extern void dwc2_set_param_host_support_fs_ls_low_power(
806 struct dwc2_hsotg *hsotg, int val);
809 * Specifies the PHY clock rate in low power mode when connected to a
810 * Low Speed device in host mode. This parameter is applicable only if
811 * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
812 * then defaults to 6 MHZ otherwise 48 MHZ.
817 extern void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
819 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
820 #define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
823 * 0 - Use cC FIFO size parameters
824 * 1 - Allow dynamic FIFO sizing (default)
826 extern void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
830 * Number of 4-byte words in the Rx FIFO in host mode when dynamic
831 * FIFO sizing is enabled.
832 * 16 to 32768 (default 1024)
834 extern void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
837 * Number of 4-byte words in the non-periodic Tx FIFO in host mode
838 * when Dynamic FIFO sizing is enabled in the core.
839 * 16 to 32768 (default 256)
841 extern void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
845 * Number of 4-byte words in the host periodic Tx FIFO when dynamic
846 * FIFO sizing is enabled.
847 * 16 to 32768 (default 256)
849 extern void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
853 * The maximum transfer size supported in bytes.
854 * 2047 to 65,535 (default 65,535)
856 extern void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
859 * The maximum number of packets in a transfer.
860 * 15 to 511 (default 511)
862 extern void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
865 * The number of host channel registers to use.
866 * 1 to 16 (default 11)
867 * Note: The FPGA configuration supports a maximum of 11 host channels.
869 extern void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
872 * Specifies the type of PHY interface to use. By default, the driver
873 * will automatically detect the phy_type.
876 * 1 - UTMI+ (default)
879 extern void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
880 #define DWC2_PHY_TYPE_PARAM_FS 0
881 #define DWC2_PHY_TYPE_PARAM_UTMI 1
882 #define DWC2_PHY_TYPE_PARAM_ULPI 2
885 * Specifies the UTMI+ Data Width. This parameter is
886 * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
887 * PHY_TYPE, this parameter indicates the data width between
888 * the MAC and the ULPI Wrapper.) Also, this parameter is
889 * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
890 * to "8 and 16 bits", meaning that the core has been
891 * configured to work at either data path width.
893 * 8 or 16 bits (default 16)
895 extern void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
898 * Specifies whether the ULPI operates at double or single
899 * data rate. This parameter is only applicable if PHY_TYPE is
902 * 0 - single data rate ULPI interface with 8 bit wide data
904 * 1 - double data rate ULPI interface with 4 bit wide data
907 extern void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
910 * Specifies whether to use the internal or external supply to
911 * drive the vbus with a ULPI phy.
913 extern void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
914 #define DWC2_PHY_ULPI_INTERNAL_VBUS 0
915 #define DWC2_PHY_ULPI_EXTERNAL_VBUS 1
918 * Specifies whether to use the I2Cinterface for full speed PHY. This
919 * parameter is only applicable if PHY_TYPE is FS.
923 extern void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
925 extern void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
927 extern void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
930 * Specifies whether dedicated transmit FIFOs are
931 * enabled for non periodic IN endpoints in device mode
935 extern void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
938 extern void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
940 extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val);
942 extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
945 * Dump core registers and SPRAM
947 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
948 extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
949 extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
952 * Return OTG version - either 1.3 or 2.0
954 extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
956 #endif /* __DWC2_CORE_H__ */