tizen 2.3.1 release
[platform/kernel/u-boot.git] / drivers / usb / gadget / s3c_udc.h
1 /*
2  * drivers/usb/gadget/s3c_udc.h
3  * Samsung S3C on-chip full/high speed USB device controllers
4  * Copyright (C) 2005 for Samsung Electronics 
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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, MA  02111-1307  USA
19  *
20  */
21  
22 #ifndef __S3C_USB_GADGET
23 #define __S3C_USB_GADGET
24
25
26 #include <linux/usb/ch9.h>
27 #include <linux/usb/gadget.h>
28 #include <linux/list.h>
29
30
31 #define __iomem
32
33 /*-------------------------------------------------------------------------*/
34
35 #define DMA_BUFFER_SIZE         (4096*4)        /* DMA bounce buffer size, 16K is enough even for mass storage */
36
37 // Max packet size
38 /*
39 #if defined(CONFIG_USB_GADGET_S3C_FS)
40 #define EP0_FIFO_SIZE           8
41 #define EP_FIFO_SIZE            64
42 #define S3C_MAX_ENDPOINTS       5
43 #elif defined(CONFIG_USB_GADGET_S3C_HS) || defined(CONFIG_PLAT_S5P64XX) || defined(CONFIG_PLAT_S5PC1XX) \
44         || defined(CONFIG_CPU_S5P6442)
45 */
46 #define EP0_FIFO_SIZE           64
47 #define EP_FIFO_SIZE            512
48 #define EP_FIFO_SIZE2           1024
49 #define S3C_MAX_ENDPOINTS       4 /* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */
50 #define S3C_MAX_HW_ENDPOINTS    16
51 /*
52 #else
53 #define EP0_FIFO_SIZE           64
54 #define EP_FIFO_SIZE            512
55 #define EP_FIFO_SIZE2           1024
56 #define S3C_MAX_ENDPOINTS       16
57 #endif
58 */
59 #define WAIT_FOR_SETUP          0
60 #define DATA_STATE_XMIT         1
61 #define DATA_STATE_NEED_ZLP     2
62 #define WAIT_FOR_OUT_STATUS     3
63 #define DATA_STATE_RECV         4
64 #define WAIT_FOR_COMPLETE       5
65 #define WAIT_FOR_OUT_COMPLETE   6
66 #define WAIT_FOR_IN_COMPLETE    7
67 #define WAIT_FOR_NULL_COMPLETE  8
68
69 #define TEST_J_SEL              0x1
70 #define TEST_K_SEL              0x2
71 #define TEST_SE0_NAK_SEL        0x3
72 #define TEST_PACKET_SEL         0x4
73 #define TEST_FORCE_ENABLE_SEL   0x5
74
75 /* ********************************************************************************************* */
76 /* IO
77  */
78
79 typedef enum ep_type {
80         ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
81 } ep_type_t;
82
83 struct s3c_ep {
84         struct usb_ep ep;
85         struct s3c_udc *dev;
86
87         const struct usb_endpoint_descriptor *desc;
88         struct list_head queue;
89         unsigned long pio_irqs;
90         int len;
91         void *dma_buf;
92
93         u8 stopped;
94         u8 bEndpointAddress;
95         u8 bmAttributes;
96
97         ep_type_t ep_type;
98         int fifo_num;
99 #ifdef CONFIG_USB_GADGET_S3C_FS
100         u32 csr1;
101         u32 csr2;
102 #endif
103 };
104
105 struct s3c_request {
106         struct usb_request req;
107         struct list_head queue;
108 };
109
110 struct s3c_udc {
111         struct usb_gadget gadget;
112         struct usb_gadget_driver *driver;
113         //struct device *dev;
114 //      struct platform_device *dev;
115         struct s3c_plat_otg_data *pdata;
116         spinlock_t lock;
117         void *dma_buf[S3C_MAX_ENDPOINTS+1];
118         dma_addr_t dma_addr[S3C_MAX_ENDPOINTS+1];
119
120         int ep0state;
121         struct s3c_ep ep[S3C_MAX_ENDPOINTS];
122
123         unsigned char usb_address;
124
125 //      struct regulator *regulator_a;
126 //      struct regulator *regulator_d;
127
128         unsigned req_pending:1, req_std:1, req_config:1;
129 };
130
131 extern struct s3c_udc *the_controller;
132
133 #define ep_is_in(EP)            (((EP)->bEndpointAddress&USB_DIR_IN)==USB_DIR_IN)
134 #define ep_index(EP)            ((EP)->bEndpointAddress&0xF)
135 #define ep_maxpacket(EP)        ((EP)->ep.maxpacket)
136
137
138
139 /*-------------------------------------------------------------------------*/
140
141 #define DEBUG
142 #ifdef DEBUG
143 #define DBG(stuff...)           printf("udc: " stuff)
144 #else
145 #define DBG(stuff...)           do{}while(0)
146 #endif
147
148 #ifdef VERBOSE
149 #define VDBG(x...)      printf(x)
150 //VDBG(x...) printf(__FUNCTION__ , x)
151 #else
152 #define VDBG(stuff...)  do{}while(0)
153 #endif
154
155 #ifdef PACKET_TRACE
156 #    define PACKET              VDBG
157 #else
158 #    define PACKET(stuff...)    do{}while(0)
159 #endif
160
161 #define ERR(stuff...)           printf("ERR udc: " stuff)
162 #define WARN(stuff...)          printf("WARNING udc: " stuff)
163 #define INFO(stuff...)          printf("INFO udc: " stuff)
164
165
166 #endif