1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
33 #ifndef DWC_DEVICE_ONLY
37 #include "dwc_otg_os_dep.h"
39 #include "dwc_otg_hcd_if.h"
40 #include "dwc_otg_core_if.h"
42 #include "dwc_otg_cil.h"
43 #include "dwc_otg_fiq_fsm.h"
44 #include "dwc_otg_driver.h"
50 * This file contains the structures, constants, and interfaces for
51 * the Host Contoller Driver (HCD).
53 * The Host Controller Driver (HCD) is responsible for translating requests
54 * from the USB Driver into the appropriate actions on the DWC_otg controller.
55 * It isolates the USBD from the specifics of the controller by providing an
59 struct dwc_otg_hcd_pipe_info {
67 struct dwc_otg_hcd_iso_packet_desc {
70 uint32_t actual_length;
76 struct dwc_otg_hcd_urb {
78 struct dwc_otg_qtd *qtd;
84 uint32_t actual_length;
87 uint32_t packet_count;
90 struct dwc_otg_hcd_pipe_info pipe_info;
91 struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
94 static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
99 static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
102 return pipe->pipe_type;
105 static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
110 static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
113 return pipe->dev_addr;
116 static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
119 return (pipe->pipe_type == UE_ISOCHRONOUS);
122 static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
125 return (pipe->pipe_type == UE_INTERRUPT);
128 static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
131 return (pipe->pipe_type == UE_BULK);
134 static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
137 return (pipe->pipe_type == UE_CONTROL);
140 static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
142 return (pipe->pipe_dir == UE_DIR_IN);
145 static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
148 return (!dwc_otg_hcd_is_pipe_in(pipe));
151 static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
152 uint8_t devaddr, uint8_t ep_num,
153 uint8_t pipe_type, uint8_t pipe_dir,
156 pipe->dev_addr = devaddr;
157 pipe->ep_num = ep_num;
158 pipe->pipe_type = pipe_type;
159 pipe->pipe_dir = pipe_dir;
164 * Phases for control transfers.
166 typedef enum dwc_otg_control_phase {
167 DWC_OTG_CONTROL_SETUP,
168 DWC_OTG_CONTROL_DATA,
169 DWC_OTG_CONTROL_STATUS
170 } dwc_otg_control_phase_e;
172 /** Transaction types. */
173 typedef enum dwc_otg_transaction_type {
174 DWC_OTG_TRANSACTION_NONE = 0,
175 DWC_OTG_TRANSACTION_PERIODIC = 1,
176 DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
177 DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
178 } dwc_otg_transaction_type_e;
183 * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
184 * interrupt, or isochronous transfer. A single QTD is created for each URB
185 * (of one of these types) submitted to the HCD. The transfer associated with
186 * a QTD may require one or multiple transactions.
188 * A QTD is linked to a Queue Head, which is entered in either the
189 * non-periodic or periodic schedule for execution. When a QTD is chosen for
190 * execution, some or all of its transactions may be executed. After
191 * execution, the state of the QTD is updated. The QTD may be retired if all
192 * its transactions are complete or if an error occurred. Otherwise, it
193 * remains in the schedule so more transactions can be executed later.
195 typedef struct dwc_otg_qtd {
197 * Determines the PID of the next data packet for the data phase of
198 * control transfers. Ignored for other transfer types.<br>
199 * One of the following values:
200 * - DWC_OTG_HC_PID_DATA0
201 * - DWC_OTG_HC_PID_DATA1
205 /** Current phase for control transfers (Setup, Data, or Status). */
206 dwc_otg_control_phase_e control_phase;
208 /** Keep track of the current split type
209 * for FS/LS endpoints on a HS Hub */
210 uint8_t complete_split;
212 /** How many bytes transferred during SSPLIT OUT */
213 uint32_t ssplit_out_xfer_count;
216 * Holds the number of bus errors that have occurred for a transaction
217 * within this transfer.
222 * Index of the next frame descriptor for an isochronous transfer. A
223 * frame descriptor describes the buffer position and length of the
224 * data to be transferred in the next scheduled (micro)frame of an
225 * isochronous transfer. It also holds status for that transaction.
226 * The frame index starts at 0.
228 uint16_t isoc_frame_index;
230 /** Position of the ISOC split on full/low speed */
231 uint8_t isoc_split_pos;
233 /** Position of the ISOC split in the buffer for the current frame */
234 uint16_t isoc_split_offset;
236 /** URB for this transfer */
237 struct dwc_otg_hcd_urb *urb;
239 struct dwc_otg_qh *qh;
241 /** This list of QTDs */
242 DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
244 /** Indicates if this QTD is currently processed by HW. */
247 /** Number of DMA descriptors for this QTD */
251 * Last activated frame(packet) index.
252 * Used in Descriptor DMA mode only.
254 uint16_t isoc_frame_index_last;
258 DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
261 * A Queue Head (QH) holds the static characteristics of an endpoint and
262 * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
263 * be entered in either the non-periodic or periodic schedule.
265 typedef struct dwc_otg_qh {
268 * One of the following values:
277 /** wMaxPacketSize Field of Endpoint Descriptor. */
282 * One of the following values:
283 * - DWC_OTG_EP_SPEED_LOW
284 * - DWC_OTG_EP_SPEED_FULL
285 * - DWC_OTG_EP_SPEED_HIGH
290 * Determines the PID of the next data packet for non-control
291 * transfers. Ignored for control transfers.<br>
292 * One of the following values:
293 * - DWC_OTG_HC_PID_DATA0
294 * - DWC_OTG_HC_PID_DATA1
298 /** Ping state if 1. */
302 * List of QTDs for this QH.
304 struct dwc_otg_qtd_list qtd_list;
306 /** Host channel currently processing transfers for this QH. */
307 struct dwc_hc *channel;
309 /** Full/low speed endpoint on high-speed hub requires split. */
312 /** @name Periodic schedule information */
315 /** Bandwidth in microseconds per (micro)frame. */
318 /** Interval between transfers in (micro)frames. */
322 * (micro)frame to initialize a periodic transfer. The transfer
323 * executes in the following (micro)frame.
325 uint16_t sched_frame;
328 ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
332 /** (micro)frame at which last start split was initialized. */
333 uint16_t start_split_frame;
338 * Used instead of original buffer if
339 * it(physical address) is not dword-aligned.
341 uint8_t *dw_align_buf;
342 dwc_dma_t dw_align_buf_dma;
344 /** Entry for QH in either the periodic or non-periodic schedule. */
345 dwc_list_link_t qh_list_entry;
347 /** @name Descriptor DMA support */
350 /** Descriptor List. */
351 dwc_otg_host_dma_desc_t *desc_list;
353 /** Descriptor List physical address. */
354 dwc_dma_t desc_list_dma;
358 * Each element corresponds to a descriptor and indicates
359 * original XferSize size value for the descriptor.
363 /** Actual number of transfer descriptors in a list. */
366 /** First activated isochronous transfer descriptor index. */
368 /** Last activated isochronous transfer descriptor index. */
375 uint16_t frame_usecs[8];
380 DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
382 typedef struct urb_tq_entry {
384 DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
387 DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
390 * This structure holds the state of the HCD, including the non-periodic and
391 * periodic schedules.
394 /** The DWC otg device pointer */
395 struct dwc_otg_device *otg_dev;
396 /** DWC OTG Core Interface Layer */
397 dwc_otg_core_if_t *core_if;
399 /** Function HCD driver callbacks */
400 struct dwc_otg_hcd_function_ops *fops;
402 /** Internal DWC HCD Flags */
403 volatile union dwc_otg_hcd_internal_flags {
406 unsigned port_connect_status_change:1;
407 unsigned port_connect_status:1;
408 unsigned port_reset_change:1;
409 unsigned port_enable_change:1;
410 unsigned port_suspend_change:1;
411 unsigned port_over_current_change:1;
412 unsigned port_l1_change:1;
413 unsigned port_speed:2;
414 unsigned reserved:24;
419 * Inactive items in the non-periodic schedule. This is a list of
420 * Queue Heads. Transfers associated with these Queue Heads are not
421 * currently assigned to a host channel.
423 dwc_list_link_t non_periodic_sched_inactive;
426 * Active items in the non-periodic schedule. This is a list of
427 * Queue Heads. Transfers associated with these Queue Heads are
428 * currently assigned to a host channel.
430 dwc_list_link_t non_periodic_sched_active;
433 * Pointer to the next Queue Head to process in the active
434 * non-periodic schedule.
436 dwc_list_link_t *non_periodic_qh_ptr;
439 * Inactive items in the periodic schedule. This is a list of QHs for
440 * periodic transfers that are _not_ scheduled for the next frame.
441 * Each QH in the list has an interval counter that determines when it
442 * needs to be scheduled for execution. This scheduling mechanism
443 * allows only a simple calculation for periodic bandwidth used (i.e.
444 * must assume that all periodic transfers may need to execute in the
445 * same frame). However, it greatly simplifies scheduling and should
446 * be sufficient for the vast majority of OTG hosts, which need to
447 * connect to a small number of peripherals at one time.
449 * Items move from this list to periodic_sched_ready when the QH
450 * interval counter is 0 at SOF.
452 dwc_list_link_t periodic_sched_inactive;
455 * List of periodic QHs that are ready for execution in the next
456 * frame, but have not yet been assigned to host channels.
458 * Items move from this list to periodic_sched_assigned as host
459 * channels become available during the current frame.
461 dwc_list_link_t periodic_sched_ready;
464 * List of periodic QHs to be executed in the next frame that are
465 * assigned to host channels.
467 * Items move from this list to periodic_sched_queued as the
468 * transactions for the QH are queued to the DWC_otg controller.
470 dwc_list_link_t periodic_sched_assigned;
473 * List of periodic QHs that have been queued for execution.
475 * Items move from this list to either periodic_sched_inactive or
476 * periodic_sched_ready when the channel associated with the transfer
477 * is released. If the interval for the QH is 1, the item moves to
478 * periodic_sched_ready because it must be rescheduled for the next
479 * frame. Otherwise, the item moves to periodic_sched_inactive.
481 dwc_list_link_t periodic_sched_queued;
484 * Total bandwidth claimed so far for periodic transfers. This value
485 * is in microseconds per (micro)frame. The assumption is that all
486 * periodic transfers may occur in the same (micro)frame.
488 uint16_t periodic_usecs;
491 * Total bandwidth claimed so far for all periodic transfers
493 * This will include a mixture of HS and FS transfers.
494 * Units are microseconds per (micro)frame.
495 * We have a budget per frame and have to schedule
496 * transactions accordingly.
497 * Watch out for the fact that things are actually scheduled for the
500 uint16_t frame_usecs[8];
504 * Frame number read from the core at SOF. The value ranges from 0 to
505 * DWC_HFNUM_MAX_FRNUM.
507 uint16_t frame_number;
510 * Count of periodic QHs, if using several eps. For SOF enable/disable.
512 uint16_t periodic_qh_count;
515 * Free host channels in the controller. This is a list of
518 struct hc_list free_hc_list;
520 * Number of host channels assigned to periodic transfers. Currently
521 * assuming that there is a dedicated host channel for each periodic
522 * transaction and at least one host channel available for
523 * non-periodic transactions.
525 int periodic_channels; /* microframe_schedule==0 */
528 * Number of host channels assigned to non-periodic transfers.
530 int non_periodic_channels; /* microframe_schedule==0 */
533 * Number of host channels assigned to non-periodic transfers.
535 int available_host_channels;
538 * Array of pointers to the host channel descriptors. Allows accessing
539 * a host channel descriptor given the host channel number. This is
540 * useful in interrupt handlers.
542 struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
545 * Buffer to use for any data received during the status phase of a
546 * control transfer. Normally no data is transferred during the status
547 * phase. This buffer is used as a bit bucket.
552 * DMA address for status_buf.
554 dma_addr_t status_buf_dma;
555 #define DWC_OTG_HCD_STATUS_BUF_SIZE 64
558 * Connection timer. An OTG host must display a message if the device
559 * does not connect. Started when the VBus power is turned on via
560 * sysfs attribute "buspower".
562 dwc_timer_t *conn_timer;
564 /* Tasket to do a reset */
565 dwc_tasklet_t *reset_tasklet;
567 dwc_tasklet_t *completion_tasklet;
568 struct urb_list completed_urb_list;
571 dwc_spinlock_t *lock;
573 * Private data that could be used by OS wrapper.
580 uint32_t *frame_list;
582 /** Hub - Port assignment */
585 int hub_port_alloc[2048];
588 /** Frame List DMA address */
589 dma_addr_t frame_list_dma;
591 struct fiq_stack *fiq_stack;
592 struct fiq_state *fiq_state;
594 /** Virtual address for split transaction DMA bounce buffers */
595 struct fiq_dma_blob *fiq_dmab;
598 uint32_t frrem_samples;
599 uint64_t frrem_accum;
601 uint32_t hfnum_7_samples_a;
602 uint64_t hfnum_7_frrem_accum_a;
603 uint32_t hfnum_0_samples_a;
604 uint64_t hfnum_0_frrem_accum_a;
605 uint32_t hfnum_other_samples_a;
606 uint64_t hfnum_other_frrem_accum_a;
608 uint32_t hfnum_7_samples_b;
609 uint64_t hfnum_7_frrem_accum_b;
610 uint32_t hfnum_0_samples_b;
611 uint64_t hfnum_0_frrem_accum_b;
612 uint32_t hfnum_other_samples_b;
613 uint64_t hfnum_other_frrem_accum_b;
617 static inline struct device *dwc_otg_hcd_to_dev(struct dwc_otg_hcd *hcd)
619 return &hcd->otg_dev->os_dep.platformdev->dev;
622 /** @name Transaction Execution Functions */
624 extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
626 extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
627 dwc_otg_transaction_type_e tr_type);
629 int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
630 void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
632 extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
633 extern int fiq_fsm_transaction_suitable(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
634 extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
638 /** @name Interrupt Handler Functions */
640 extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
641 extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
642 extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
644 extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
646 extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
648 extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
650 extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
651 extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
653 extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
654 extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
655 extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
657 extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
658 extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
662 /** @name Schedule Queue Functions */
665 /* Implemented in dwc_otg_hcd_queue.c */
666 extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
667 dwc_otg_hcd_urb_t * urb, int atomic_alloc);
668 extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
669 extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
670 extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
671 extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
674 /** Remove and free a QH */
675 static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
678 dwc_irqflags_t flags;
679 DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
680 dwc_otg_hcd_qh_remove(hcd, qh);
681 DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
682 dwc_otg_hcd_qh_free(hcd, qh);
685 /** Allocates memory for a QH structure.
686 * @return Returns the memory allocate or NULL on error. */
687 static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
690 return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
692 return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
695 extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
697 extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
698 extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
699 dwc_otg_qh_t ** qh, int atomic_alloc);
701 /** Allocates memory for a QTD structure.
702 * @return Returns the memory allocate or NULL on error. */
703 static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
706 return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
708 return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
711 /** Frees the memory for a QTD structure. QTD should already be removed from
713 * @param qtd QTD to free.*/
714 static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
719 /** Removes a QTD from list.
720 * @param hcd HCD instance.
721 * @param qtd QTD to remove from list.
722 * @param qh QTD belongs to.
724 static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
728 DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
731 /** Remove and free a QTD
732 * Need to disable IRQ and hold hcd lock while calling this function out of
733 * interrupt servicing chain */
734 static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
738 dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
739 dwc_otg_hcd_qtd_free(qtd);
744 /** @name Descriptor DMA Supporting Functions */
747 extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
748 extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
750 dwc_otg_hc_regs_t * hc_regs,
751 dwc_otg_halt_status_e halt_status);
753 extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
754 extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
758 /** @name Internal Functions */
760 dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
763 #ifdef CONFIG_USB_DWC_OTG_LPM
764 extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
766 extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
769 /** Gets the QH that contains the list_head */
770 #define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
772 /** Gets the QTD that contains the list_head */
773 #define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
775 /** Check if QH is non-periodic */
776 #define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
777 (_qh_ptr_->ep_type == UE_CONTROL))
779 /** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
780 #define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
782 /** Packet size for any kind of endpoint descriptor */
783 #define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
786 * Returns true if _frame1 is less than or equal to _frame2. The comparison is
787 * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
788 * frame number when the max frame number is reached.
790 static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
792 return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
793 (DWC_HFNUM_MAX_FRNUM >> 1);
797 * Returns true if _frame1 is greater than _frame2. The comparison is done
798 * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
799 * number when the max frame number is reached.
801 static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
803 return (frame1 != frame2) &&
804 (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
805 (DWC_HFNUM_MAX_FRNUM >> 1));
809 * Increments _frame by the amount specified by _inc. The addition is done
810 * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
812 static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
814 return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
817 static inline uint16_t dwc_full_frame_num(uint16_t frame)
819 return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
822 static inline uint16_t dwc_micro_frame_num(uint16_t frame)
827 extern void init_hcd_usecs(dwc_otg_hcd_t *_hcd);
829 void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
830 dwc_otg_hc_regs_t * hc_regs,
831 dwc_otg_qtd_t * qtd);
835 * Macro to sample the remaining PHY clocks left in the current frame. This
836 * may be used during debugging to determine the average time it takes to
837 * execute sections of code. There are two possible sample points, "a" and
838 * "b", so the _letter argument must be one of these values.
840 * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
841 * example, "cat /sys/devices/lm0/hcd_frrem".
843 #define dwc_sample_frrem(_hcd, _qh, _letter) \
845 hfnum_data_t hfnum; \
846 dwc_otg_qtd_t *qtd; \
847 qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
848 if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
849 hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
850 switch (hfnum.b.frnum & 0x7) { \
852 _hcd->hfnum_7_samples_##_letter++; \
853 _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
856 _hcd->hfnum_0_samples_##_letter++; \
857 _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
860 _hcd->hfnum_other_samples_##_letter++; \
861 _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
867 #define dwc_sample_frrem(_hcd, _qh, _letter)
870 #endif /* DWC_DEVICE_ONLY */