tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / usb / gadget / dwc_otg / dwc_otg_pcd.h
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
3  * $Revision: #39 $
4  * $Date: 2008/12/16 $
5  * $Change: 1153731 $
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_HOST_ONLY
34 #if !defined(__DWC_PCD_H__)
35 #define __DWC_PCD_H__
36
37 #include "usb.h"
38 #include "dwc_otg_cil.h"
39 #include "dwc_otg_pcd_if.h"
40 struct cfiobject;
41
42 /**
43  * @file
44  *
45  * This file contains the structures, constants, and interfaces for
46  * the Perpherial Contoller Driver (PCD).
47  *
48  * The Peripheral Controller Driver (PCD) for Linux will implement the
49  * Gadget API, so that the existing Gadget drivers can be used.  For
50  * the Mass Storage Function driver the File-backed USB Storage Gadget
51  * (FBS) driver will be used.  The FBS driver supports the
52  * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
53  * transports.
54  *
55  */
56
57 /** Max Transfer size for any EP */
58 #define DDMA_MAX_TRANSFER_SIZE 65535
59
60 /** Max DMA Descriptor count for any EP */
61 #define MAX_DMA_DESC_CNT 64
62
63 /**
64  * Get the pointer to the core_if from the pcd pointer.
65  */
66 #define GET_CORE_IF( _pcd ) (_pcd->core_if)
67
68 /**
69  * States of EP0.
70  */
71 typedef enum ep0_state {
72         EP0_DISCONNECT,         /* no host */
73         EP0_IDLE,
74         EP0_IN_DATA_PHASE,
75         EP0_OUT_DATA_PHASE,
76         EP0_IN_STATUS_PHASE,
77         EP0_OUT_STATUS_PHASE,
78         EP0_STALL,
79 } ep0state_e;
80
81 /** Fordward declaration.*/
82 struct dwc_otg_pcd;
83
84 /** DWC_otg iso request structure.
85  *
86  */
87 typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
88
89 /** DWC_otg request structure.
90  * This structure is a list of requests.
91  */
92 typedef struct dwc_otg_pcd_request {
93         void *priv;
94         void *buf;
95         dwc_dma_t dma;
96         uint32_t length;
97         uint32_t actual;
98         unsigned sent_zlp:1;
99         unsigned mapped:1;
100          DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
101 } dwc_otg_pcd_request_t;
102
103 DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
104
105 /**       PCD EP structure.
106  * This structure describes an EP, there is an array of EPs in the PCD
107  * structure.
108  */
109 typedef struct dwc_otg_pcd_ep {
110         /** USB EP Descriptor */
111         const usb_endpoint_descriptor_t *desc;
112
113         /** queue of dwc_otg_pcd_requests. */
114         struct req_list queue;
115         unsigned stopped:1;
116         unsigned disabling:1;
117         unsigned dma:1;
118         unsigned queue_sof:1;
119
120 #ifdef DWC_EN_ISOC
121         /** ISOC req handle passed */
122         void *iso_req_handle;
123 #endif                          //_EN_ISOC_
124
125         /** DWC_otg ep data. */
126         dwc_ep_t dwc_ep;
127
128         /** Pointer to PCD */
129         struct dwc_otg_pcd *pcd;
130
131         void *priv;
132 } dwc_otg_pcd_ep_t;
133
134 /** DWC_otg PCD Structure.
135  * This structure encapsulates the data for the dwc_otg PCD.
136  */
137 struct dwc_otg_pcd {
138         const struct dwc_otg_pcd_function_ops *fops;
139         /** Core Interface */
140         dwc_otg_core_if_t *core_if;
141         /** State of EP0 */
142         ep0state_e ep0state;
143         /** EP0 Request is pending */
144         unsigned ep0_pending:1;
145         /** Indicates when SET CONFIGURATION Request is in process */
146         unsigned request_config:1;
147         /** The state of the Remote Wakeup Enable. */
148         unsigned remote_wakeup_enable:1;
149         /** The state of the B-Device HNP Enable. */
150         unsigned b_hnp_enable:1;
151         /** The state of A-Device HNP Support. */
152         unsigned a_hnp_support:1;
153         /** The state of the A-Device Alt HNP support. */
154         unsigned a_alt_hnp_support:1;
155         /** Count of pending Requests */
156         unsigned request_pending;
157
158         /** SETUP packet for EP0
159          * This structure is allocated as a DMA buffer on PCD initialization
160          * with enough space for up to 3 setup packets.
161          */
162         union {
163                 usb_device_request_t req;
164                 uint32_t d32[2];
165         } *setup_pkt;
166
167         dwc_dma_t setup_pkt_dma_handle;
168
169         /** 2-byte dma buffer used to return status from GET_STATUS */
170         uint16_t *status_buf;
171         dwc_dma_t status_buf_dma_handle;
172
173         /** EP0 */
174         dwc_otg_pcd_ep_t ep0;
175
176         /** Array of IN EPs. */
177         dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
178         /** Array of OUT EPs. */
179         dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
180         /** number of valid EPs in the above array. */
181 //        unsigned      num_eps : 4;
182         dwc_spinlock_t *lock;
183         /** Timer for SRP. If it expires before SRP is successful
184          * clear the SRP. */
185         dwc_timer_t *srp_timer;
186
187         /** Tasklet to defer starting of TEST mode transmissions until
188          *      Status Phase has been completed.
189          */
190         dwc_tasklet_t *test_mode_tasklet;
191
192         /** Tasklet to delay starting of xfer in DMA mode */
193         dwc_tasklet_t *start_xfer_tasklet;
194
195         /** The test mode to enter when the tasklet is executed. */
196         unsigned test_mode;
197         /** The cfi_api structure that implements most of the CFI API
198          * and OTG specific core configuration functionality 
199          */
200 #ifdef DWC_UTE_CFI
201         struct cfiobject *cfi;
202 #endif
203
204 };
205
206 //FIXME this functions should be static, and this prototypes should be removed
207 extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
208 extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
209                                  dwc_otg_pcd_request_t * req, int32_t status);
210
211 void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
212                              void *req_handle);
213
214 extern void do_test_mode(void *data);
215 #endif
216 #endif                          /* DWC_HOST_ONLY */