import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / xhci_test / mtk-usb-hcd.h
1 #ifndef __MTK_USB_HCD_H
2 #define __MTK_USB_HCD_H
3
4 #include <linux/types.h> /* size_t */
5 #include <linux/kernel.h> /* printk() */
6 #include <linux/fs.h> /* everything... */
7 #include <linux/errno.h> /* error codes */
8 #include <linux/types.h> /* size_t */
9 #include <linux/proc_fs.h>
10 #include <linux/fcntl.h> /* O_ACCMODE */
11 #include <linux/seq_file.h>
12 #include <linux/cdev.h>
13 //#include <linux/pci.h>
14
15 #include <asm/unaligned.h>
16
17 #include <linux/usb.h>
18 #include <linux/timer.h>
19 #include <linux/kernel.h>
20 //#include <linux/usb/hcd.h>
21 #include "xhci.h"
22
23 /*
24 * Hub request types
25 */
26
27 #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
28 #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
29
30
31 /*
32 * Descriptor types ... USB 2.0 spec table 9.5
33 */
34 #define USB_DT_DEVICE 0x01
35 #define USB_DT_CONFIG 0x02
36 #define USB_DT_STRING 0x03
37 #define USB_DT_INTERFACE 0x04
38 #define USB_DT_ENDPOINT 0x05
39 #define USB_DT_DEVICE_QUALIFIER 0x06
40 #define USB_DT_OTHER_SPEED_CONFIG 0x07
41 #define USB_DT_INTERFACE_POWER 0x08
42 /* these are from a minor usb 2.0 revision (ECN) */
43 #define USB_DT_OTG 0x09
44 #define USB_DT_DEBUG 0x0a
45 #define USB_DT_INTERFACE_ASSOCIATION 0x0b
46 /* these are from the Wireless USB spec */
47 #define USB_DT_SECURITY 0x0c
48 #define USB_DT_KEY 0x0d
49 #define USB_DT_ENCRYPTION_TYPE 0x0e
50 #define USB_DT_BOS 0x0f
51 #define USB_DT_DEVICE_CAPABILITY 0x10
52 #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
53 #define USB_DT_WIRE_ADAPTER 0x21
54 #define USB_DT_RPIPE 0x22
55 #define USB_DT_CS_RADIO_CONTROL 0x23
56 /* From the T10 UAS specification */
57 #define USB_DT_PIPE_USAGE 0x24
58 /* From the USB 3.0 spec */
59 #define USB_DT_SS_ENDPOINT_COMP 0x30
60
61 /* The following flags are used internally by usbcore and HCDs */
62 #define URB_DIR_IN 0x0200 /* Transfer from device to host */
63 #define URB_DIR_OUT 0
64 #define URB_DIR_MASK URB_DIR_IN
65
66 #define URB_DMA_MAP_SINGLE 0x00010000 /* Non-scatter-gather mapping */
67 #define URB_DMA_MAP_PAGE 0x00020000 /* HCD-unsupported S-G */
68 #define URB_DMA_MAP_SG 0x00040000 /* HCD-supported S-G */
69 #define URB_MAP_LOCAL 0x00080000 /* HCD-local-memory mapping */
70 #define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */
71 #define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */
72 #define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */
73
74 /*
75 * USB directions
76 *
77 * This bit flag is used in endpoint descriptors' bEndpointAddress field.
78 * It's also one of three fields in control requests bRequestType.
79 */
80 #define USB_DIR_OUT 0 /* to device */
81 #define USB_DIR_IN 0x80 /* to host */
82 #define USB_DIR_MASK 0x80 /* to host */
83
84 /*
85 * USB request types
86 */
87 #define USB_TYPE_STANDARD (0x00 << 5)
88 #define USB_TYPE_CLASS (0x01 << 5)
89 #define USB_TYPE_VENDOR (0x02 << 5)
90 #define USB_TYPE_RESERVED (0x03 << 5)
91
92 /*
93 * USB recipients
94 */
95 #define USB_RECIP_DEVICE 0x00
96 #define USB_RECIP_INTERFACE 0x01
97 #define USB_RECIP_ENDPOINT 0x02
98 #define USB_RECIP_OTHER 0x03
99
100
101
102
103 /*
104 * wPortStatus bit field
105 * See USB 2.0 spec Table 11-21
106 */
107 #define USB_PORT_STAT_CONNECTION 0x0001
108 #define USB_PORT_STAT_ENABLE 0x0002
109 #define USB_PORT_STAT_SUSPEND 0x0004
110 #define USB_PORT_STAT_OVERCURRENT 0x0008
111 #define USB_PORT_STAT_RESET 0x0010
112 #define USB_PORT_STAT_L1 0x0020
113 /* bits 6 to 7 are reserved */
114 #define USB_PORT_STAT_POWER 0x0100
115 #define USB_PORT_STAT_LOW_SPEED 0x0200
116 #define USB_PORT_STAT_HIGH_SPEED 0x0400
117 #define USB_PORT_STAT_TEST 0x0800
118 #define USB_PORT_STAT_INDICATOR 0x1000
119 /* bits 13 to 15 are reserved */
120 #define USB_PORT_STAT_SUPER_SPEED 0x8000 /* Linux-internal */
121
122 /*
123 * wPortChange bit field
124 * See USB 2.0 spec Table 11-22
125 * Bits 0 to 4 shown, bits 5 to 15 are reserved
126 */
127 #define USB_PORT_STAT_C_CONNECTION 0x0001
128 #define USB_PORT_STAT_C_ENABLE 0x0002
129 #define USB_PORT_STAT_C_SUSPEND 0x0004
130 #define USB_PORT_STAT_C_OVERCURRENT 0x0008
131 #define USB_PORT_STAT_C_RESET 0x0010
132 #define USB_PORT_STAT_C_L1 0x0020
133
134 /* Create various pipes... */
135 #define usb_sndctrlpipe(dev, endpoint) \
136 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
137 #define usb_rcvctrlpipe(dev, endpoint) \
138 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
139 #define usb_sndisocpipe(dev, endpoint) \
140 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
141 #define usb_rcvisocpipe(dev, endpoint) \
142 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
143 #define usb_sndbulkpipe(dev, endpoint) \
144 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
145 #define usb_rcvbulkpipe(dev, endpoint) \
146 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
147 #define usb_sndintpipe(dev, endpoint) \
148 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
149 #define usb_rcvintpipe(dev, endpoint) \
150 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
151
152 #define USB_DT_DEVICE_SIZE 18
153 #define USB_DT_CONFIG_SIZE 9
154 #define USB_DT_STATUS_SIZE 2
155 #define USB_DT_BOS_SIZE 5
156 #define USB_HUB_PORT_STATUS_SIZE 4
157 #define USB_DT_CONFIG_OTG_SIZE 23
158
159 /*
160 * Standard requests, for the bRequest field of a SETUP packet.
161 *
162 * These are qualified by the bRequestType field, so that for example
163 * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
164 * by a GET_STATUS request.
165 */
166 #define USB_REQ_GET_STATUS 0x00
167 #define USB_REQ_CLEAR_FEATURE 0x01
168 #define USB_REQ_SET_FEATURE 0x03
169 #define USB_REQ_SET_ADDRESS 0x05
170 #define USB_REQ_GET_DESCRIPTOR 0x06
171 #define USB_REQ_SET_DESCRIPTOR 0x07
172 #define USB_REQ_GET_CONFIGURATION 0x08
173 #define USB_REQ_SET_CONFIGURATION 0x09
174 #define USB_REQ_GET_INTERFACE 0x0A
175 #define USB_REQ_SET_INTERFACE 0x0B
176 #define USB_REQ_SYNCH_FRAME 0x0C
177 #define USB_REQ_SET_SEL 0x30
178
179 #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
180 #define USB_REQ_GET_ENCRYPTION 0x0E
181 #define USB_REQ_RPIPE_ABORT 0x0E
182 #define USB_REQ_SET_HANDSHAKE 0x0F
183 #define USB_REQ_RPIPE_RESET 0x0F
184 #define USB_REQ_GET_HANDSHAKE 0x10
185 #define USB_REQ_SET_CONNECTION 0x11
186 #define USB_REQ_SET_SECURITY_DATA 0x12
187 #define USB_REQ_GET_SECURITY_DATA 0x13
188 #define USB_REQ_SET_WUSB_DATA 0x14
189 #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
190 #define USB_REQ_LOOPBACK_DATA_READ 0x16
191 #define USB_REQ_SET_INTERFACE_DS 0x17
192
193 /*
194 * USB feature flags are written using USB_REQ_{CLEAR,SET}_FEATURE, and
195 * are read as a bit array returned by USB_REQ_GET_STATUS. (So there
196 * are at most sixteen features of each type.) Hubs may also support a
197 * new USB_REQ_TEST_AND_SET_FEATURE to put ports into L1 suspend.
198 */
199 #define USB_DEVICE_SELF_POWERED 0 /* (read only) */
200 #define USB_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */
201 #define USB_DEVICE_TEST_MODE 2 /* (wired high speed only) */
202 #define USB_DEVICE_BATTERY 2 /* (wireless) */
203 #define USB_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */
204 #define USB_DEVICE_WUSB_DEVICE 3 /* (wireless)*/
205 #define USB_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */
206 #define USB_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */
207 #define USB_DEVICE_DEBUG_MODE 6 /* (special devices only) */
208
209 #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */
210 #define USB_FUNCTION_SUSPEND 0
211 #define USB_U1_ENABLE 48
212 #define USB_U2_ENABLE 49
213 #define USB_LTM_ENABLE 50
214
215
216 int mtk_xhci_hcd_init(void);
217 void mtk_xhci_hcd_cleanup(void);
218 int mtk_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
219 void mtk_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb);
220 struct usb_device *mtk_usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1);
221 unsigned int mtktest_xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
222 struct usb_hcd *mtk_usb_create_hcd (const struct hc_driver *driver,
223 struct device *dev, const char *bus_name);
224 int mtk_usb_add_hcd(struct usb_hcd *hcd,
225 unsigned int irqnum, unsigned long irqflags);
226 void mtk_usb_remove_hcd(struct usb_hcd *hcd);
227
228 #endif