root/src/linux/rt2880/linux-2.6.23/drivers/usb/dwc_otg/dwc_otg_hcd.h

Revision 12433, 21.4 kB (checked in by BrainSlayer, 5 months ago)

fixes usb issues with some devices

Line 
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
3  * $Revision: 1.3 $
4  * $Date: 2008-12-15 06:51:32 $
5  * $Change: 1064918 $
6  *
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.
10  *
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.
20  *
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
31  * DAMAGE.
32  * ========================================================================== */
33 #ifndef DWC_DEVICE_ONLY
34 #ifndef __DWC_HCD_H__
35 #define __DWC_HCD_H__
36
37 #include <linux/list.h>
38 #include <linux/usb.h>
39 #include <../drivers/usb/core/hcd.h>
40
41 struct lm_device;
42 struct dwc_otg_device;
43
44 #include "dwc_otg_cil.h"
45
46 /**
47  * @file
48  *
49  * This file contains the structures, constants, and interfaces for
50  * the Host Contoller Driver (HCD).
51  *
52  * The Host Controller Driver (HCD) is responsible for translating requests
53  * from the USB Driver into the appropriate actions on the DWC_otg controller.
54  * It isolates the USBD from the specifics of the controller by providing an
55  * API to the USBD.
56  */
57
58 /**
59  * Phases for control transfers.
60  */
61 typedef enum dwc_otg_control_phase {
62         DWC_OTG_CONTROL_SETUP,
63         DWC_OTG_CONTROL_DATA,
64         DWC_OTG_CONTROL_STATUS
65 } dwc_otg_control_phase_e;
66
67 /** Transaction types. */
68 typedef enum dwc_otg_transaction_type {
69         DWC_OTG_TRANSACTION_NONE,
70         DWC_OTG_TRANSACTION_PERIODIC,
71         DWC_OTG_TRANSACTION_NON_PERIODIC,
72         DWC_OTG_TRANSACTION_ALL
73 } dwc_otg_transaction_type_e;
74
75 /**
76  * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
77  * interrupt, or isochronous transfer. A single QTD is created for each URB
78  * (of one of these types) submitted to the HCD. The transfer associated with
79  * a QTD may require one or multiple transactions.
80  *
81  * A QTD is linked to a Queue Head, which is entered in either the
82  * non-periodic or periodic schedule for execution. When a QTD is chosen for
83  * execution, some or all of its transactions may be executed. After
84  * execution, the state of the QTD is updated. The QTD may be retired if all
85  * its transactions are complete or if an error occurred. Otherwise, it
86  * remains in the schedule so more transactions can be executed later.
87  */
88 typedef struct dwc_otg_qtd {
89         /**
90          * Determines the PID of the next data packet for the data phase of
91          * control transfers. Ignored for other transfer types.<br>
92          * One of the following values:
93          *      - DWC_OTG_HC_PID_DATA0
94          *      - DWC_OTG_HC_PID_DATA1
95          */
96         uint8_t                 data_toggle;
97
98         /** Current phase for control transfers (Setup, Data, or Status). */
99         dwc_otg_control_phase_e control_phase;
100
101         /** Keep track of the current split type
102          * for FS/LS endpoints on a HS Hub */
103         uint8_t                 complete_split;
104
105         /** How many bytes transferred during SSPLIT OUT */
106         uint32_t                ssplit_out_xfer_count;
107
108         /**
109          * Holds the number of bus errors that have occurred for a transaction
110          * within this transfer.
111          */
112         uint8_t                 error_count;
113
114         /**
115          * Index of the next frame descriptor for an isochronous transfer. A
116          * frame descriptor describes the buffer position and length of the
117          * data to be transferred in the next scheduled (micro)frame of an
118          * isochronous transfer. It also holds status for that transaction.
119          * The frame index starts at 0.
120          */
121         int                     isoc_frame_index;
122
123         /** Position of the ISOC split on full/low speed */
124         uint8_t                 isoc_split_pos;
125
126         /** Position of the ISOC split in the buffer for the current frame */
127         uint16_t                isoc_split_offset;
128
129         /** URB for this transfer */
130         struct urb              *urb;
131
132         /** This list of QTDs */
133         struct list_head        qtd_list_entry;
134
135 } dwc_otg_qtd_t;
136
137 /**
138  * A Queue Head (QH) holds the static characteristics of an endpoint and
139  * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
140  * be entered in either the non-periodic or periodic schedule.
141  */
142 typedef struct dwc_otg_qh {
143         /**
144          * Endpoint type.
145          * One of the following values:
146          *      - USB_ENDPOINT_XFER_CONTROL
147          *      - USB_ENDPOINT_XFER_ISOC
148          *      - USB_ENDPOINT_XFER_BULK
149          *      - USB_ENDPOINT_XFER_INT
150          */
151         uint8_t                 ep_type;
152         uint8_t                 ep_is_in;
153
154         /** wMaxPacketSize Field of Endpoint Descriptor. */
155         uint16_t                maxp;
156
157         /**
158          * Determines the PID of the next data packet for non-control
159          * transfers. Ignored for control transfers.<br>
160          * One of the following values:
161          *      - DWC_OTG_HC_PID_DATA0
162          *      - DWC_OTG_HC_PID_DATA1
163          */
164         uint8_t                 data_toggle;
165
166         /** Ping state if 1. */
167         uint8_t                 ping_state;
168
169         /**
170          * List of QTDs for this QH.
171          */
172         struct list_head        qtd_list;
173
174         /** Host channel currently processing transfers for this QH. */
175         dwc_hc_t                *channel;
176
177         /** QTD currently assigned to a host channel for this QH. */
178         dwc_otg_qtd_t           *qtd_in_process;
179
180         /** Full/low speed endpoint on high-speed hub requires split. */
181         uint8_t                 do_split;
182
183         /** @name Periodic schedule information */
184         /** @{ */
185
186         /** Bandwidth in microseconds per (micro)frame. */
187         uint8_t                 usecs;
188
189         /** Interval between transfers in (micro)frames. */
190         uint16_t                interval;
191
192         /**
193          * (micro)frame to initialize a periodic transfer. The transfer
194          * executes in the following (micro)frame.
195          */
196         uint16_t                sched_frame;
197
198         /** (micro)frame at which last start split was initialized. */
199         uint16_t                start_split_frame;
200
201         /** @} */
202
203         /** Entry for QH in either the periodic or non-periodic schedule. */
204         struct list_head        qh_list_entry;
205        
206         /* For non-dword aligned buffer support */
207         uint8_t                 *dw_align_buf;
208         dma_addr_t              dw_align_buf_dma;
209 } dwc_otg_qh_t;
210
211 /**
212  * This structure holds the state of the HCD, including the non-periodic and
213  * periodic schedules.
214  */
215 typedef struct dwc_otg_hcd {
216         /** The DWC otg device pointer */
217         struct dwc_otg_device   *otg_dev;
218
219         /** DWC OTG Core Interface Layer */
220         dwc_otg_core_if_t       *core_if;
221
222         /** Internal DWC HCD Flags */
223         volatile union dwc_otg_hcd_internal_flags {
224                 uint32_t d32;
225                 struct {
226                         unsigned port_connect_status_change : 1;
227                         unsigned port_connect_status : 1;
228                         unsigned port_reset_change : 1;
229                         unsigned port_enable_change : 1;
230                         unsigned port_suspend_change : 1;
231                         unsigned port_over_current_change : 1;
232                         unsigned reserved : 27;
233                 } b;
234         } flags;
235
236         /**
237          * Inactive items in the non-periodic schedule. This is a list of
238          * Queue Heads. Transfers associated with these Queue Heads are not
239          * currently assigned to a host channel.
240          */
241         struct list_head        non_periodic_sched_inactive;
242
243         /**
244          * Active items in the non-periodic schedule. This is a list of
245          * Queue Heads. Transfers associated with these Queue Heads are
246          * currently assigned to a host channel.
247          */
248         struct list_head        non_periodic_sched_active;
249
250         /**
251          * Pointer to the next Queue Head to process in the active
252          * non-periodic schedule.
253          */
254         struct list_head        *non_periodic_qh_ptr;
255
256         /**
257          * Inactive items in the periodic schedule. This is a list of QHs for
258          * periodic transfers that are _not_ scheduled for the next frame.
259          * Each QH in the list has an interval counter that determines when it
260          * needs to be scheduled for execution. This scheduling mechanism
261          * allows only a simple calculation for periodic bandwidth used (i.e.
262          * must assume that all periodic transfers may need to execute in the
263          * same frame). However, it greatly simplifies scheduling and should
264          * be sufficient for the vast majority of OTG hosts, which need to
265          * connect to a small number of peripherals at one time.
266          *
267          * Items move from this list to periodic_sched_ready when the QH
268          * interval counter is 0 at SOF.
269          */
270         struct list_head        periodic_sched_inactive;
271
272         /**
273          * List of periodic QHs that are ready for execution in the next
274          * frame, but have not yet been assigned to host channels.
275          *
276          * Items move from this list to periodic_sched_assigned as host
277          * channels become available during the current frame.
278          */
279         struct list_head        periodic_sched_ready;
280
281         /**
282          * List of periodic QHs to be executed in the next frame that are
283          * assigned to host channels.
284          *
285          * Items move from this list to periodic_sched_queued as the
286          * transactions for the QH are queued to the DWC_otg controller.
287          */
288         struct list_head        periodic_sched_assigned;
289
290         /**
291          * List of periodic QHs that have been queued for execution.
292          *
293          * Items move from this list to either periodic_sched_inactive or
294          * periodic_sched_ready when the channel associated with the transfer
295          * is released. If the interval for the QH is 1, the item moves to
296          * periodic_sched_ready because it must be rescheduled for the next
297          * frame. Otherwise, the item moves to periodic_sched_inactive.
298          */
299         struct list_head        periodic_sched_queued;
300
301         /**
302          * Total bandwidth claimed so far for periodic transfers. This value
303          * is in microseconds per (micro)frame. The assumption is that all
304          * periodic transfers may occur in the same (micro)frame.
305          */
306         uint16_t                periodic_usecs;
307
308         /**
309          * Frame number read from the core at SOF. The value ranges from 0 to
310          * DWC_HFNUM_MAX_FRNUM.
311          */
312         uint16_t                frame_number;
313
314         /**
315          * Free host channels in the controller. This is a list of
316          * dwc_hc_t items.
317          */
318         struct list_head        free_hc_list;
319
320         /**
321          * Number of host channels assigned to periodic transfers. Currently
322          * assuming that there is a dedicated host channel for each periodic
323          * transaction and at least one host channel available for
324          * non-periodic transactions.
325          */
326         int                     periodic_channels;
327
328         /**
329          * Number of host channels assigned to non-periodic transfers.
330          */
331         int                     non_periodic_channels;
332
333         /**
334          * Array of pointers to the host channel descriptors. Allows accessing
335          * a host channel descriptor given the host channel number. This is
336          * useful in interrupt handlers.
337          */
338         dwc_hc_t                *hc_ptr_array[MAX_EPS_CHANNELS];
339
340         /**
341          * Buffer to use for any data received during the status phase of a
342          * control transfer. Normally no data is transferred during the status
343          * phase. This buffer is used as a bit bucket.
344          */
345         uint8_t                 *status_buf;
346
347         /**
348          * DMA address for status_buf.
349          */
350         dma_addr_t              status_buf_dma;
351 #define DWC_OTG_HCD_STATUS_BUF_SIZE 64
352
353         /**
354          * Structure to allow starting the HCD in a non-interrupt context
355          * during an OTG role change.
356          */
357 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
358         struct work_struct      start_work;
359 #else
360         struct delayed_work     start_work;
361 #endif
362
363         /**
364          * Connection timer. An OTG host must display a message if the device
365          * does not connect. Started when the VBus power is turned on via
366          * sysfs attribute "buspower".
367          */
368         struct timer_list       conn_timer;
369
370         /* Tasket to do a reset */
371         struct tasklet_struct   *reset_tasklet;
372
373         /*  */
374         spinlock_t lock;
375
376 #ifdef DEBUG
377         uint32_t                frrem_samples;
378         uint64_t                frrem_accum;
379
380         uint32_t                hfnum_7_samples_a;
381         uint64_t                hfnum_7_frrem_accum_a;
382         uint32_t                hfnum_0_samples_a;
383         uint64_t                hfnum_0_frrem_accum_a;
384         uint32_t                hfnum_other_samples_a;
385         uint64_t                hfnum_other_frrem_accum_a;
386
387         uint32_t                hfnum_7_samples_b;
388         uint64_t                hfnum_7_frrem_accum_b;
389         uint32_t                hfnum_0_samples_b;
390         uint64_t                hfnum_0_frrem_accum_b;
391         uint32_t                hfnum_other_samples_b;
392         uint64_t                hfnum_other_frrem_accum_b;
393 #endif
394 } dwc_otg_hcd_t;
395
396 /** Gets the dwc_otg_hcd from a struct usb_hcd */
397 static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
398 {
399         return (dwc_otg_hcd_t *)(hcd->hcd_priv);
400 }
401
402 /** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
403 static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t *dwc_otg_hcd)
404 {
405         return container_of((void *)dwc_otg_hcd, struct usb_hcd, hcd_priv);
406 }
407
408 /** @name HCD Create/Destroy Functions */
409 /** @{ */
410 extern int dwc_otg_hcd_init(struct lm_device *lmdev);
411 extern void dwc_otg_hcd_remove(struct lm_device *lmdev);
412 /** @} */
413
414 /** @name Linux HC Driver API Functions */
415 /** @{ */
416
417 extern int dwc_otg_hcd_start(struct usb_hcd *hcd);
418 extern void dwc_otg_hcd_stop(struct usb_hcd *hcd);
419 extern int dwc_otg_hcd_get_frame_number(struct usb_hcd *hcd);
420 extern void dwc_otg_hcd_free(struct usb_hcd *hcd);
421 extern int dwc_otg_hcd_urb_enqueue(struct usb_hcd *hcd,
422                                    struct usb_host_endpoint *ep,
423                                    struct urb *urb,
424 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
425                                    int mem_flags
426 #else
427                                    gfp_t mem_flags
428 #endif
429                                   );
430 extern int dwc_otg_hcd_urb_dequeue(struct usb_hcd *hcd,
431 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
432                                    struct usb_host_endpoint *ep,
433 #endif
434                                    struct urb *urb);
435 extern void dwc_otg_hcd_endpoint_disable(struct usb_hcd *hcd,
436                                          struct usb_host_endpoint *ep);
437 extern irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd
438 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
439                                    , struct pt_regs *regs
440 #endif
441                                   );
442 extern int dwc_otg_hcd_hub_status_data(struct usb_hcd *hcd,
443                                        char *buf);
444 extern int dwc_otg_hcd_hub_control(struct usb_hcd *hcd,
445                                    u16 typeReq,
446                                    u16 wValue,
447                                    u16 wIndex,
448                                    char *buf,
449                                    u16 wLength);
450
451 /** @} */
452
453 /** @name Transaction Execution Functions */
454 /** @{ */
455 extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t *hcd);
456 extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t *hcd,
457                                            dwc_otg_transaction_type_e tr_type);
458 extern void dwc_otg_hcd_complete_urb(dwc_otg_hcd_t *_hcd, struct urb *urb,
459                                      int status);
460 /** @} */
461
462 /** @name Interrupt Handler Functions */
463 /** @{ */
464 extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t *dwc_otg_hcd);
465 extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t *dwc_otg_hcd);
466 extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *dwc_otg_hcd);
467 extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
468 extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *dwc_otg_hcd);
469 extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *dwc_otg_hcd);
470 extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t *dwc_otg_hcd);
471 extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *dwc_otg_hcd);
472 extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t *dwc_otg_hcd);
473 extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t *dwc_otg_hcd);
474 extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t *dwc_otg_hcd, uint32_t num);
475 extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t *dwc_otg_hcd);
476 extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *dwc_otg_hcd);
477 /** @} */
478
479
480 /** @name Schedule Queue Functions */
481 /** @{ */
482
483 /* Implemented in dwc_otg_hcd_queue.c */
484 extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t *hcd, struct urb *urb);
485 extern void dwc_otg_hcd_qh_init(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, struct urb *urb);
486 extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
487 extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
488 extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
489 extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, int sched_csplit);
490
491 /** Remove and free a QH */
492 static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t *hcd,
493                                                   dwc_otg_qh_t *qh)
494 {
495         dwc_otg_hcd_qh_remove(hcd, qh);
496         dwc_otg_hcd_qh_free(hcd, qh);
497 }
498
499 /** Allocates memory for a QH structure.
500  * @return Returns the memory allocate or NULL on error. */
501 static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(void)
502 {
503         return (dwc_otg_qh_t *) kmalloc(sizeof(dwc_otg_qh_t), GFP_KERNEL);
504 }
505
506 extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(struct urb *urb);
507 extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t *qtd, struct urb *urb);
508 extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *qtd, dwc_otg_hcd_t *dwc_otg_hcd);
509
510 /** Allocates memory for a QTD structure.
511  * @return Returns the memory allocate or NULL on error. */
512 static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(void)
513 {
514         return (dwc_otg_qtd_t *) kmalloc(sizeof(dwc_otg_qtd_t), GFP_KERNEL);
515 }
516
517 /** Frees the memory for a QTD structure.  QTD should already be removed from
518  * list.
519  * @param[in] qtd QTD to free.*/
520 static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t *qtd)
521 {
522         kfree(qtd);
523 }
524
525 /** Removes a QTD from list.
526  * @param[in] hcd HCD instance.
527  * @param[in] qtd QTD to remove from list. */
528 static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
529 {
530         unsigned long flags;
531         SPIN_LOCK_IRQSAVE(&hcd->lock, flags);
532         list_del(&qtd->qtd_list_entry);
533         SPIN_UNLOCK_IRQRESTORE(&hcd->lock, flags);
534 }
535
536 /** Remove and free a QTD */
537 static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t *hcd, dwc_otg_qtd_t *qtd)
538 {
539         dwc_otg_hcd_qtd_remove(hcd, qtd);
540         dwc_otg_hcd_qtd_free(qtd);
541 }
542
543 /** @} */
544
545
546 /** @name Internal Functions */
547 /** @{ */
548 dwc_otg_qh_t *dwc_urb_to_qh(struct urb *urb);
549 void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t *hcd);
550 void dwc_otg_hcd_dump_state(dwc_otg_hcd_t *hcd);
551 /** @} */
552
553 /** Gets the usb_host_endpoint associated with an URB. */
554 static inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
555 {
556         struct usb_device *dev = urb->dev;
557         int ep_num = usb_pipeendpoint(urb->pipe);
558
559         if (usb_pipein(urb->pipe))
560                 return dev->ep_in[ep_num];
561         else
562                 return dev->ep_out[ep_num];
563 }
564
565 /**
566  * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
567  * qualified with its direction (possible 32 endpoints per device).
568  */
569 #define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
570                                                      ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
571
572 /** Gets the QH that contains the list_head */
573 #define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
574
575 /** Gets the QTD that contains the list_head */
576 #define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
577
578 /** Check if QH is non-periodic  */
579 #define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == USB_ENDPOINT_XFER_BULK) || \
580                                      (_qh_ptr_->ep_type == USB_ENDPOINT_XFER_CONTROL))
581
582 /** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
583 #define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
584
585 /** Packet size for any kind of endpoint descriptor */
586 #define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
587
588 /**
589  * Returns true if _frame1 is less than or equal to _frame2. The comparison is
590  * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
591  * frame number when the max frame number is reached.
592  */
593 static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
594 {
595         return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
596                 (DWC_HFNUM_MAX_FRNUM >> 1);
597 }
598
599 /**
600  * Returns true if _frame1 is greater than _frame2. The comparison is done
601  * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
602  * number when the max frame number is reached.
603  */
604 static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
605 {
606         return (frame1 != frame2) &&
607                 (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
608                  (DWC_HFNUM_MAX_FRNUM >> 1));
609 }
610
611 /**
612  * Increments _frame by the amount specified by _inc. The addition is done
613  * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
614  */
615 static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
616 {
617         return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
618 }
619
620 static inline uint16_t dwc_full_frame_num(uint16_t frame)
621 {
622         return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
623 }
624
625 static inline uint16_t dwc_micro_frame_num(uint16_t frame)
626 {
627         return frame & 0x7;
628 }
629
630 #ifdef DEBUG
631 /**
632  * Macro to sample the remaining PHY clocks left in the current frame. This
633  * may be used during debugging to determine the average time it takes to
634  * execute sections of code. There are two possible sample points, "a" and
635  * "b", so the _letter argument must be one of these values.
636  *
637  * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
638  * example, "cat /sys/devices/lm0/hcd_frrem".
639  */
640 #define dwc_sample_frrem(_hcd, _qh, _letter) \
641 { \
642         hfnum_data_t hfnum; \
643         dwc_otg_qtd_t *qtd; \
644         qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
645         if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
646                 hfnum.d32 = dwc_read_reg32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
647                 switch (hfnum.b.frnum & 0x7) { \
648                 case 7: \
649                         _hcd->hfnum_7_samples_##_letter++; \
650                         _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
651                         break; \
652                 case 0: \
653                         _hcd->hfnum_0_samples_##_letter++; \
654                         _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
655                         break; \
656                 default: \
657                         _hcd->hfnum_other_samples_##_letter++; \
658                         _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
659                         break; \
660                 } \
661         } \
662 }
663 #else
664 #define dwc_sample_frrem(_hcd, _qh, _letter)
665 #endif
666 #endif
667 #endif /* DWC_DEVICE_ONLY */
Note: See TracBrowser for help on using the browser.