upload tizen1.0 source
[kernel/linux-2.6.36.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 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/ioport.h>
28 #include <linux/types.h>
29 #include <linux/version.h>
30 #include <linux/errno.h>
31 #include <linux/delay.h>
32 #include <linux/sched.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/timer.h>
36 #include <linux/list.h>
37 #include <linux/interrupt.h>
38 #include <linux/proc_fs.h>
39 #include <linux/mm.h>
40 #include <linux/device.h>
41 #include <linux/dma-mapping.h>
42 #include <linux/io.h>
43
44 #include <asm/byteorder.h>
45 #include <asm/dma.h>
46 #include <asm/irq.h>
47 #include <asm/system.h>
48 #include <asm/unaligned.h>
49 #if 0
50 #include <asm/hardware.h>
51 #endif
52
53 #include <linux/usb/ch9.h>
54 #include <linux/usb/gadget.h>
55 #include <linux/host_notify.h>
56
57 /* Max packet size */
58 #if defined(CONFIG_USB_GADGET_S3C_FS)
59 #define EP0_FIFO_SIZE           8
60 #define EP_FIFO_SIZE            64
61 #define S3C_MAX_ENDPOINTS       5
62 #elif defined(CONFIG_USB_GADGET_S3C_HS) || defined(CONFIG_PLAT_S5P64XX)\
63         || defined(CONFIG_PLAT_S5PC11X) || defined(CONFIG_CPU_S5P6442)\
64         || defined(CONFIG_CPU_S5P6450) || defined(CONFIG_CPU_S5PV310)
65 #define EP0_FIFO_SIZE           64
66 #define EP_FIFO_SIZE            512
67 #define EP_FIFO_SIZE2           1024
68 #define S3C_MAX_ENDPOINTS       16
69 #define DED_TX_FIFO             1       /* Dedicated NPTx fifo for s5p6440 */
70 #else
71 #define EP0_FIFO_SIZE           64
72 #define EP_FIFO_SIZE            512
73 #define EP_FIFO_SIZE2           1024
74 #define S3C_MAX_ENDPOINTS       16
75 #endif
76
77 #define WAIT_FOR_SETUP          0
78 #define DATA_STATE_XMIT         1
79 #define DATA_STATE_NEED_ZLP     2
80 #define WAIT_FOR_OUT_STATUS     3
81 #define DATA_STATE_RECV         4
82 #define RegReadErr              5
83 #define FAIL_TO_SETUP           6
84
85 #define TEST_J_SEL              0x1
86 #define TEST_K_SEL              0x2
87 #define TEST_SE0_NAK_SEL        0x3
88 #define TEST_PACKET_SEL         0x4
89 #define TEST_FORCE_ENABLE_SEL   0x5
90
91
92 #define USE_USB_LDO_CONTROL     /* This definition is for LDO control. */
93 #include <linux/regulator/consumer.h>
94 /*
95  * ------------------------------------------------------------------------------------------
96  * Debugging macro and defines
97  */
98 /*#define CSY_DEBUG */
99 /* #define CSY_DEBUG2 */
100 #define CSY_DEBUG_ESS
101 /* #define CSY_MORE_DEBUG */
102
103 #ifdef CSY_DEBUG
104 #  ifdef CSY_MORE_DEBUG
105 #    define CSY_DBG(fmt, args...) printk(KERN_INFO "usb %s:%d "fmt, __func__, __LINE__, ##args)
106 #  else
107 #    define CSY_DBG(fmt, args...) printk(KERN_DEBUG "usb "fmt, ##args)
108 #  endif
109 #else /* DO NOT PRINT LOG */
110 #  define CSY_DBG(fmt, args...) do { } while (0)
111 #endif /* CSY_DEBUG */
112
113 #ifdef CSY_DEBUG2
114 #  ifdef CSY_MORE_DEBUG
115 #    define CSY_DBG2(fmt, args...) printk(KERN_INFO "usb %s:%d "fmt, __func__, __LINE__, ##args)
116 #  else
117 #    define CSY_DBG2(fmt, args...) printk(KERN_DEBUG "usb "fmt, ##args)
118 #  endif
119 #else /* DO NOT PRINT LOG */
120 #  define CSY_DBG2(fmt, args...) do { } while (0)
121 #endif /* CSY_DEBUG2 */
122
123 #ifdef CSY_DEBUG_ESS
124 #  ifdef CSY_MORE_DEBUG
125 #    define CSY_DBG_ESS(fmt, args...) printk(KERN_INFO "usb %s:%d "fmt, __func__, __LINE__, ##args)
126 #  else
127 #    define CSY_DBG_ESS(fmt, args...) printk(KERN_DEBUG "usb "fmt, ##args)
128 #  endif
129 #else /* DO NOT PRINT LOG */
130 #  define CSY_DBG_ESS(fmt, args...) do { } while (0)
131 #endif /* CSY_DEBUG_ESS */
132
133 #ifdef CSY_DEBUG
134 #undef DBG
135 #  define DBG(devvalue, fmt, args...) \
136         printk(KERN_INFO "usb %s:%d "fmt, __func__, __LINE__, ##args)
137 #endif
138
139 /* ************************************************************************* */
140 /* IO
141  */
142
143 typedef enum ep_type {
144         ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
145 } ep_type_t;
146
147 struct s3c_ep {
148         struct usb_ep ep;
149         struct s3c_udc *dev;
150
151         const struct usb_endpoint_descriptor *desc;
152         struct list_head queue;
153         unsigned long pio_irqs;
154
155         u8 stopped;
156         u8 bEndpointAddress;
157         u8 bmAttributes;
158
159         ep_type_t ep_type;
160         u32 fifo;
161 #ifdef CONFIG_USB_GADGET_S3C_FS
162         u32 csr1;
163         u32 csr2;
164 #endif
165 };
166
167 struct s3c_request {
168         struct usb_request req;
169         struct list_head queue;
170         unsigned char mapped;
171 };
172
173 struct s3c_udc {
174         struct usb_gadget gadget;
175         struct usb_gadget_driver *driver;
176 #if 0
177         struct device *dev;
178 #endif
179         struct platform_device *dev;
180         spinlock_t lock;
181 #ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
182         u16 status;
183         struct regulator *udc_vcc_d, *udc_vcc_a;
184         int udc_enabled;
185         atomic_t usb_status;
186         int     (*get_usb_mode)(void);
187         int     (*change_usb_mode)(int mode);
188         struct mutex            mutex;
189         struct host_notify_dev * ndev;
190 #endif
191         int ep0state;
192         struct s3c_ep ep[S3C_MAX_ENDPOINTS];
193
194         unsigned char usb_address;
195
196         unsigned req_pending:1, req_std:1, req_config:1;
197 };
198
199 extern struct s3c_udc *the_controller;
200
201 #define ep_is_in(EP)    (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN)
202
203 #define ep_index(EP)            ((EP)->bEndpointAddress&0xF)
204 #define ep_maxpacket(EP)        ((EP)->ep.maxpacket)
205
206 #endif