Merge branch 'master' of git://git.denx.de/u-boot
[kernel/u-boot.git] / arch / arm / cpu / armv7 / s5pc1xx / usb-hs-otg.h
1 /*
2  * (C) Copyright 2007
3  * Byungjae Lee, Samsung Erectronics, bjlee@samsung.com.
4  *      - only support for S3C6400
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA
20  */
21
22 #ifndef __USBD_HS_OTG_H__
23 #define __USBD_HS_OTG_H__
24
25 #include <asm/io.h>
26 #include <asm/byteorder.h>
27 #include <asm/arch/usb-hs-otg.h>
28
29 #define make_word_c(w) __constant_cpu_to_le16(w)
30 #define make_word(w)   __cpu_to_le16(w)
31
32 #define CONTROL_EP              0
33 #define BULK_IN_EP              1
34 #define BULK_OUT_EP             2
35 #define INTR_IN_EP              3
36
37 #define FS_CTRL_PKT_SIZE        8
38 #define FS_BULK_PKT_SIZE        64
39
40 #define HS_CTRL_PKT_SIZE        64
41 #define HS_BULK_PKT_SIZE        512
42
43 #define RX_FIFO_SIZE            512
44 #define NPTX_FIFO_START_ADDR    RX_FIFO_SIZE
45 #define NPTX_FIFO_SIZE          512
46 #define PTX_FIFO_SIZE           512
47
48 /* string descriptor */
49 #define LANGID_US_L             (0x09)
50 #define LANGID_US_H             (0x04)
51
52 /* Feature Selectors */
53 #define EP_STALL                0
54 #define DEVICE_REMOTE_WAKEUP    1
55 #define TEST_MODE               2
56
57 /* Test Mode Selector*/
58 #define TEST_J                  1
59 #define TEST_K                  2
60 #define TEST_SE0_NAK            3
61 #define TEST_PACKET             4
62 #define TEST_FORCE_ENABLE       5
63
64 #define OTG_DIEPCTL_IN          (OTG_DIEPCTL0 + 0x20 * BULK_IN_EP)
65 #define OTG_DIEPINT_IN          (OTG_DIEPINT0 + 0x20 * BULK_IN_EP)
66 #define OTG_DIEPTSIZ_IN         (OTG_DIEPTSIZ0 + 0x20 * BULK_IN_EP)
67 #define OTG_DIEPDMA_IN          (OTG_DIEPDMA0 + 0x20 * BULK_IN_EP)
68 #define OTG_DOEPCTL_OUT         (OTG_DOEPCTL0 + 0x20 * BULK_OUT_EP)
69 #define OTG_DOEPINT_OUT         (OTG_DOEPINT0 + 0x20 * BULK_OUT_EP)
70 #define OTG_DOEPTSIZ_OUT        (OTG_DOEPTSIZ0 + 0x20 * BULK_OUT_EP)
71 #define OTG_DOEPDMA_OUT         (OTG_DOEPDMA0 + 0x20 * BULK_OUT_EP)
72 #define OTG_IN_FIFO             (OTG_EP0_FIFO + 0x1000 * BULK_IN_EP)
73 #define OTG_OUT_FIFO            (OTG_EP0_FIFO + 0x1000 * BULK_OUT_EP)
74
75 typedef struct {
76         u8 bLength;
77         u8 bDescriptorType;
78         u8 bcdUSBL;
79         u8 bcdUSBH;
80         u8 bDeviceClass;
81         u8 bDeviceSubClass;
82         u8 bDeviceProtocol;
83         u8 bMaxPacketSize0;
84         u8 idVendorL;
85         u8 idVendorH;
86         u8 idProductL;
87         u8 idProductH;
88         u8 bcdDeviceL;
89         u8 bcdDeviceH;
90         u8 iManufacturer;
91         u8 iProduct;
92         u8 iSerialNumber;
93         u8 bNumConfigurations;
94 } __attribute__ ((packed)) device_desc_t;
95
96 typedef struct {
97         u8 bLength;
98         u8 bDescriptorType;
99         u8 wTotalLengthL;
100         u8 wTotalLengthH;
101         u8 bNumInterfaces;
102         u8 bConfigurationValue;
103         u8 iConfiguration;
104         u8 bmAttributes;
105         u8 maxPower;
106 } __attribute__ ((packed)) config_desc_t;
107
108 typedef struct {
109         u8 bLength;
110         u8 bDescriptorType;
111         u8 bInterfaceNumber;
112         u8 bAlternateSetting;
113         u8 bNumEndpoints;
114         u8 bInterfaceClass;
115         u8 bInterfaceSubClass;
116         u8 bInterfaceProtocol;
117         u8 iInterface;
118 } __attribute__ ((packed)) intf_desc_t;
119
120 typedef struct {
121         u8 bLength;
122         u8 bDescriptorType;
123         u8 bEndpointAddress;
124         u8 bmAttributes;
125         u8 wMaxPacketSizeL;
126         u8 wMaxPacketSizeH;
127         u8 bInterval;
128 } __attribute__ ((packed)) ep_desc_t;
129
130 typedef struct {
131         u8 bLength;
132         u8 bDescriptorType;
133    u16 bString[30];
134 } __attribute__ ((packed)) string_desc_t;
135
136 typedef struct {
137         u8 bmRequestType;
138         u8 bRequest;
139         u8 wValue_L;
140         u8 wValue_H;
141         u8 wIndex_L;
142         u8 wIndex_H;
143         u8 wLength_L;
144         u8 wLength_H;
145 } __attribute__ ((packed)) device_req_t;
146
147 typedef struct {
148         device_desc_t dev;
149         config_desc_t config;
150         intf_desc_t intf;
151         ep_desc_t ep1;
152         ep_desc_t ep2;
153         ep_desc_t ep3;
154         ep_desc_t ep4;
155 } __attribute__ ((packed)) descriptors_t;
156
157 typedef struct {
158         u8 Device;
159         u8 Interface;
160         u8 ep_ctrl;
161         u8 ep_in;
162         u8 ep_out;
163 } __attribute__ ((packed)) get_status_t;
164
165 typedef struct {
166         u8 AlternateSetting;
167 } __attribute__ ((packed)) get_intf_t;
168
169 typedef enum {
170         USB_CPU, USB_DMA
171 } USB_OPMODE;
172
173 typedef enum {
174         USB_HIGH, USB_FULL, USB_LOW
175 } USB_SPEED;
176
177 typedef enum {
178         EP_TYPE_CONTROL, EP_TYPE_ISOCHRONOUS, EP_TYPE_BULK, EP_TYPE_INTERRUPT
179 } EP_TYPE;
180
181 typedef struct {
182         descriptors_t desc;
183         device_req_t dev_req;
184
185         u32 ep0_state;
186         u32 ep0_substate;
187         USB_OPMODE op_mode;
188         USB_SPEED speed;
189         u32 ctrl_max_pktsize;
190         u32 bulkin_max_pktsize;
191         u32 bulkout_max_pktsize;
192         u32 dn_addr;
193         u32 dn_filesize;
194         u32 up_addr;
195         u32 up_size;
196         u8 *dn_ptr;
197         u8 *up_ptr;
198         u32 set_config;
199         u32 req_length;
200 } __attribute__ ((packed)) otg_dev_t;
201
202 enum DEV_REQUEST_DIRECTION {
203         HOST_TO_DEVICE = 0x00,
204         DEVICE_TO_HOST = 0x80
205 };
206
207 enum DEV_REQUEST_TYPE {
208         STANDARD_TYPE = 0x00,
209         CLASS_TYPE = 0x20,
210         VENDOR_TYPE = 0x40,
211         RESERVED_TYPE = 0x60
212 };
213
214 enum DEV_REQUEST_RECIPIENT {
215         DEVICE_RECIPIENT = 0,
216         INTERFACE_RECIPIENT = 1,
217         ENDPOINT_RECIPIENT = 2,
218         OTHER_RECIPIENT = 3
219 };
220
221 enum DESCRIPTOR_TYPE {
222         DEVICE_DESCRIPTOR = 1,
223         CONFIGURATION_DESCRIPTOR = 2,
224         STRING_DESCRIPTOR = 3,
225         INTERFACE_DESCRIPTOR = 4,
226         ENDPOINT_DESCRIPTOR = 5,
227         DEVICE_QUALIFIER = 6,
228         OTHER_SPEED_CONFIGURATION = 7,
229         INTERFACE_POWER = 8
230 };
231
232 enum CONFIG_ATTRIBUTES {
233         CONF_ATTR_DEFAULT = 0x80,
234         CONF_ATTR_REMOTE_WAKEUP = 0x20,
235         CONF_ATTR_SELFPOWERED = 0x40
236 };
237
238 enum ENDPOINT_ATTRIBUTES {
239         EP_ADDR_IN = 0x80,
240         EP_ADDR_OUT = 0x00,
241         EP_ATTR_CONTROL = 0x0,
242         EP_ATTR_ISOCHRONOUS = 0x1,
243         EP_ATTR_BULK = 0x2,
244         EP_ATTR_INTERRUPT = 0x3
245 };
246
247 enum STANDARD_REQUEST_CODE {
248         STANDARD_GET_STATUS = 0,
249         STANDARD_CLEAR_FEATURE = 1,
250         STANDARD_RESERVED_1 = 2,
251         STANDARD_SET_FEATURE = 3,
252         STANDARD_RESERVED_2 = 4,
253         STANDARD_SET_ADDRESS = 5,
254         STANDARD_GET_DESCRIPTOR = 6,
255         STANDARD_SET_DESCRIPTOR = 7,
256         STANDARD_GET_CONFIGURATION = 8,
257         STANDARD_SET_CONFIGURATION = 9,
258         STANDARD_GET_INTERFACE = 10,
259         STANDARD_SET_INTERFACE = 11,
260         STANDARD_SYNCH_FRAME = 12
261 };
262
263 int s5p_usbctl_init(void);
264 void s5p_udc_int_hndlr(void);
265 void s5p_usb_tx(char *tx_data, int tx_size);
266 int s5p_usb_detect_irq(void);
267 void s5p_usb_clear_irq(void);
268
269 /* in usbd-otg-hs.c */
270 extern unsigned int s5p_usbd_dn_addr;
271 extern unsigned int s5p_usbd_dn_cnt;
272 extern int s5p_got_header;
273 extern int s5p_receive_done;
274
275 #endif