usb: dwc_otg_310: support vbus controlled by both gpio and pmic
[firefly-linux-kernel-4.4.55.git] / drivers / usb / dwc_otg_310 / dwc_otg_pcd.h
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
3  * $Revision: #48 $
4  * $Date: 2012/08/10 $
5  * $Change: 2047372 $
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 "dwc_otg_os_dep.h"
38 #include "common_port/usb.h"
39 #include "dwc_otg_cil.h"
40 #include "dwc_otg_pcd_if.h"
41 struct cfiobject;
42
43 /**
44  * @file
45  *
46  * This file contains the structures, constants, and interfaces for
47  * the Perpherial Contoller Driver (PCD).
48  *
49  * The Peripheral Controller Driver (PCD) for Linux will implement the
50  * Gadget API, so that the existing Gadget drivers can be used. For
51  * the Mass Storage Function driver the File-backed USB Storage Gadget
52  * (FBS) driver will be used.  The FBS driver supports the
53  * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
54  * transports.
55  *
56  */
57
58 /** Invalid DMA Address */
59 #define DWC_DMA_ADDR_INVALID    (~(dwc_dma_t)0 & 0xFFFFFFFC)
60
61 /** Max Transfer size for any EP */
62 #define DDMA_MAX_TRANSFER_SIZE 65535
63
64 /**
65  * Get the pointer to the core_if from the pcd pointer.
66  */
67 #define GET_CORE_IF(_pcd) (_pcd->core_if)
68
69 /**
70  * States of EP0.
71  */
72 typedef enum ep0_state {
73         EP0_DISCONNECT,         /* no host */
74         EP0_IDLE,
75         EP0_IN_DATA_PHASE,
76         EP0_OUT_DATA_PHASE,
77         EP0_IN_STATUS_PHASE,
78         EP0_OUT_STATUS_PHASE,
79         EP0_STALL,
80 } ep0state_e;
81
82 /** Fordward declaration.*/
83 struct dwc_otg_pcd;
84
85 /** DWC_otg iso request structure.
86  *
87  */
88 typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
89
90 #ifdef DWC_UTE_PER_IO
91
92 /**
93  * This shall be the exact analogy of the same type structure defined in the
94  * usb_gadget.h. Each descriptor contains
95  */
96 struct dwc_iso_pkt_desc_port {
97         uint32_t offset;
98         uint32_t length;        /* expected length */
99         uint32_t actual_length;
100         uint32_t status;
101 };
102
103 struct dwc_iso_xreq_port {
104         /** transfer/submission flag */
105         uint32_t tr_sub_flags;
106         /** Start the request ASAP */
107 #define DWC_EREQ_TF_ASAP                0x00000002
108         /** Just enqueue the request w/o initiating a transfer */
109 #define DWC_EREQ_TF_ENQUEUE             0x00000004
110
111         /**
112         * count of ISO packets attached to this request - shall
113         * not exceed the pio_alloc_pkt_count
114         */
115         uint32_t pio_pkt_count;
116         /** count of ISO packets allocated for this request */
117         uint32_t pio_alloc_pkt_count;
118         /** number of ISO packet errors */
119         uint32_t error_count;
120         /** reserved for future extension */
121         uint32_t res;
122         /** Will be allocated and freed in the UTE gadget and based on the CFC value */
123         struct dwc_iso_pkt_desc_port *per_io_frame_descs;
124 };
125 #endif
126 /** DWC_otg request structure.
127  * This structure is a list of requests.
128  */
129 typedef struct dwc_otg_pcd_request {
130         void *priv;
131         void *buf;
132         dwc_dma_t dma;
133         uint32_t length;
134         uint32_t actual;
135         unsigned sent_zlp:1;
136     /**
137      * Used instead of original buffer if
138      * it(physical address) is not dword-aligned.
139      **/
140         uint8_t *dw_align_buf;
141         dwc_dma_t dw_align_buf_dma;
142
143          DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
144 #ifdef DWC_UTE_PER_IO
145         struct dwc_iso_xreq_port ext_req;
146         /* void *priv_ereq_nport; */
147 #endif
148 } dwc_otg_pcd_request_t;
149
150 DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
151
152 /**       PCD EP structure.
153  * This structure describes an EP, there is an array of EPs in the PCD
154  * structure.
155  */
156 typedef struct dwc_otg_pcd_ep {
157         /** USB EP Descriptor */
158         const usb_endpoint_descriptor_t *desc;
159
160         /** queue of dwc_otg_pcd_requests. */
161         struct req_list queue;
162         unsigned stopped:1;
163         unsigned disabling:1;
164         unsigned dma:1;
165         unsigned queue_sof:1;
166
167 #ifdef DWC_EN_ISOC
168         /** ISOC req handle passed */
169         void *iso_req_handle;
170 #endif /* _EN_ISOC_ */
171
172         /** DWC_otg ep data. */
173         dwc_ep_t dwc_ep;
174
175         /** Pointer to PCD */
176         struct dwc_otg_pcd *pcd;
177
178         void *priv;
179 } dwc_otg_pcd_ep_t;
180
181 /** DWC_otg PCD Structure.
182  * This structure encapsulates the data for the dwc_otg PCD.
183  */
184 struct dwc_otg_pcd {
185         const struct dwc_otg_pcd_function_ops *fops;
186         /** The DWC otg device pointer */
187         struct dwc_otg_device *otg_dev;
188         /** Core Interface */
189         dwc_otg_core_if_t *core_if;
190         /** State of EP0 */
191         ep0state_e ep0state;
192         /** EP0 Request is pending */
193         unsigned ep0_pending:1;
194         /** Indicates when SET CONFIGURATION Request is in process */
195         unsigned request_config:1;
196         /** The state of the Remote Wakeup Enable. */
197         unsigned remote_wakeup_enable:1;
198         /** The state of the B-Device HNP Enable. */
199         unsigned b_hnp_enable:1;
200         /** The state of A-Device HNP Support. */
201         unsigned a_hnp_support:1;
202         /** The state of the A-Device Alt HNP support. */
203         unsigned a_alt_hnp_support:1;
204         /** Count of pending Requests */
205         unsigned request_pending;
206
207         /** SETUP packet for EP0
208          * This structure is allocated as a DMA buffer on PCD initialization
209          * with enough space for up to 3 setup packets.
210          */
211         union {
212                 usb_device_request_t req;
213                 uint32_t d32[2];
214         } *setup_pkt;
215
216         dwc_dma_t setup_pkt_dma_handle;
217
218         /* Additional buffer and flag for CTRL_WR premature case */
219         uint8_t *backup_buf;
220         unsigned data_terminated;
221
222         /** 2-byte dma buffer used to return status from GET_STATUS */
223         uint16_t *status_buf;
224         dwc_dma_t status_buf_dma_handle;
225
226         /** EP0 */
227         dwc_otg_pcd_ep_t ep0;
228
229         /** Array of IN EPs. */
230         dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
231         /** Array of OUT EPs. */
232         dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
233         /** number of valid EPs in the above array. */
234         /** unsigned      num_eps : 4; */
235         dwc_spinlock_t *lock;
236
237         /** Tasklet to defer starting of TEST mode transmissions until
238          *      Status Phase has been completed.
239          */
240         dwc_tasklet_t *test_mode_tasklet;
241
242         /** Tasklet to delay starting of xfer in DMA mode */
243         dwc_tasklet_t *start_xfer_tasklet;
244
245         /** The test mode to enter when the tasklet is executed. */
246         unsigned test_mode;
247         /** The cfi_api structure that implements most of the CFI API
248          * and OTG specific core configuration functionality
249          */
250 #ifdef DWC_UTE_CFI
251         struct cfiobject *cfi;
252 #endif
253
254         /** otg phy may be suspend in device mode, 1:suspend, 0:normal */
255         uint8_t phy_suspend;
256         /** vbus status in device mode */
257         uint8_t vbus_status;
258         /** enable connect to PC in device mode */
259         uint8_t conn_en;
260         /** connect status used during enumeration */
261         int8_t conn_status;
262         /* otg check vbus work and connect work,used for power management */
263         struct delayed_work reconnect;
264         struct delayed_work check_vbus_work;
265         struct delayed_work check_id_work;
266         /** pervent device suspend while usb connected */
267         struct wake_lock wake_lock;
268
269 };
270
271 /* FIXME this functions should be static,
272  * and this prototypes should be removed */
273 extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t *ep);
274 extern void dwc_otg_request_done(dwc_otg_pcd_ep_t *ep,
275                                  dwc_otg_pcd_request_t *req, int32_t status);
276
277 void dwc_otg_iso_buffer_done(dwc_otg_pcd_t *pcd, dwc_otg_pcd_ep_t *ep,
278                              void *req_handle);
279
280 extern void do_test_mode(void *data);
281 extern void dwc_pcd_reset(dwc_otg_pcd_t *pcd);
282 extern void dwc_otg_pcd_start_check_vbus_work(dwc_otg_pcd_t *pcd);
283 #endif
284 #endif /* DWC_HOST_ONLY */