diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/usb/gadget/pxa2xx_udc.h |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/usb/gadget/pxa2xx_udc.h')
-rw-r--r-- | drivers/usb/gadget/pxa2xx_udc.h | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h new file mode 100644 index 000000000000..1f3a7d999da7 --- /dev/null +++ b/drivers/usb/gadget/pxa2xx_udc.h | |||
@@ -0,0 +1,320 @@ | |||
1 | /* | ||
2 | * linux/drivers/usb/gadget/pxa2xx_udc.h | ||
3 | * Intel PXA2xx on-chip full speed USB device controller | ||
4 | * | ||
5 | * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix | ||
6 | * Copyright (C) 2003 David Brownell | ||
7 | * | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | ||
23 | |||
24 | #ifndef __LINUX_USB_GADGET_PXA2XX_H | ||
25 | #define __LINUX_USB_GADGET_PXA2XX_H | ||
26 | |||
27 | #include <linux/types.h> | ||
28 | |||
29 | /*-------------------------------------------------------------------------*/ | ||
30 | |||
31 | /* pxa2xx has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */ | ||
32 | #define UFNRH_SIR (1 << 7) /* SOF interrupt request */ | ||
33 | #define UFNRH_SIM (1 << 6) /* SOF interrupt mask */ | ||
34 | #define UFNRH_IPE14 (1 << 5) /* ISO packet error, ep14 */ | ||
35 | #define UFNRH_IPE9 (1 << 4) /* ISO packet error, ep9 */ | ||
36 | #define UFNRH_IPE4 (1 << 3) /* ISO packet error, ep4 */ | ||
37 | |||
38 | /* pxa255 has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */ | ||
39 | #define UDCCFR UDC_RES2 /* UDC Control Function Register */ | ||
40 | #define UDCCFR_AREN (1 << 7) /* ACK response enable (now) */ | ||
41 | #define UDCCFR_ACM (1 << 2) /* ACK control mode (wait for AREN) */ | ||
42 | |||
43 | /* latest pxa255 errata define new "must be one" bits in UDCCFR */ | ||
44 | #define UDCCFR_MB1 (0xff & ~(UDCCFR_AREN|UDCCFR_ACM)) | ||
45 | |||
46 | /*-------------------------------------------------------------------------*/ | ||
47 | |||
48 | struct pxa2xx_udc; | ||
49 | |||
50 | struct pxa2xx_ep { | ||
51 | struct usb_ep ep; | ||
52 | struct pxa2xx_udc *dev; | ||
53 | |||
54 | const struct usb_endpoint_descriptor *desc; | ||
55 | struct list_head queue; | ||
56 | unsigned long pio_irqs; | ||
57 | unsigned long dma_irqs; | ||
58 | short dma; | ||
59 | |||
60 | unsigned short fifo_size; | ||
61 | u8 bEndpointAddress; | ||
62 | u8 bmAttributes; | ||
63 | |||
64 | unsigned stopped : 1; | ||
65 | unsigned dma_fixup : 1; | ||
66 | |||
67 | /* UDCCS = UDC Control/Status for this EP | ||
68 | * UBCR = UDC Byte Count Remaining (contents of OUT fifo) | ||
69 | * UDDR = UDC Endpoint Data Register (the fifo) | ||
70 | * DRCM = DMA Request Channel Map | ||
71 | */ | ||
72 | volatile u32 *reg_udccs; | ||
73 | volatile u32 *reg_ubcr; | ||
74 | volatile u32 *reg_uddr; | ||
75 | #ifdef USE_DMA | ||
76 | volatile u32 *reg_drcmr; | ||
77 | #define drcmr(n) .reg_drcmr = & DRCMR ## n , | ||
78 | #else | ||
79 | #define drcmr(n) | ||
80 | #endif | ||
81 | }; | ||
82 | |||
83 | struct pxa2xx_request { | ||
84 | struct usb_request req; | ||
85 | struct list_head queue; | ||
86 | }; | ||
87 | |||
88 | enum ep0_state { | ||
89 | EP0_IDLE, | ||
90 | EP0_IN_DATA_PHASE, | ||
91 | EP0_OUT_DATA_PHASE, | ||
92 | EP0_END_XFER, | ||
93 | EP0_STALL, | ||
94 | }; | ||
95 | |||
96 | #define EP0_FIFO_SIZE ((unsigned)16) | ||
97 | #define BULK_FIFO_SIZE ((unsigned)64) | ||
98 | #define ISO_FIFO_SIZE ((unsigned)256) | ||
99 | #define INT_FIFO_SIZE ((unsigned)8) | ||
100 | |||
101 | struct udc_stats { | ||
102 | struct ep0stats { | ||
103 | unsigned long ops; | ||
104 | unsigned long bytes; | ||
105 | } read, write; | ||
106 | unsigned long irqs; | ||
107 | }; | ||
108 | |||
109 | #ifdef CONFIG_USB_PXA2XX_SMALL | ||
110 | /* when memory's tight, SMALL config saves code+data. */ | ||
111 | #undef USE_DMA | ||
112 | #define PXA_UDC_NUM_ENDPOINTS 3 | ||
113 | #endif | ||
114 | |||
115 | #ifndef PXA_UDC_NUM_ENDPOINTS | ||
116 | #define PXA_UDC_NUM_ENDPOINTS 16 | ||
117 | #endif | ||
118 | |||
119 | struct pxa2xx_udc { | ||
120 | struct usb_gadget gadget; | ||
121 | struct usb_gadget_driver *driver; | ||
122 | |||
123 | enum ep0_state ep0state; | ||
124 | struct udc_stats stats; | ||
125 | unsigned got_irq : 1, | ||
126 | vbus : 1, | ||
127 | pullup : 1, | ||
128 | has_cfr : 1, | ||
129 | req_pending : 1, | ||
130 | req_std : 1, | ||
131 | req_config : 1; | ||
132 | |||
133 | #define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200)) | ||
134 | struct timer_list timer; | ||
135 | |||
136 | struct device *dev; | ||
137 | struct pxa2xx_udc_mach_info *mach; | ||
138 | u64 dma_mask; | ||
139 | struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS]; | ||
140 | }; | ||
141 | |||
142 | /*-------------------------------------------------------------------------*/ | ||
143 | |||
144 | #ifdef CONFIG_ARCH_LUBBOCK | ||
145 | #include <asm/arch/lubbock.h> | ||
146 | /* lubbock can also report usb connect/disconnect irqs */ | ||
147 | |||
148 | #ifdef DEBUG | ||
149 | #define HEX_DISPLAY(n) if (machine_is_lubbock()) { LUB_HEXLED = (n); } | ||
150 | #endif | ||
151 | |||
152 | #endif | ||
153 | |||
154 | /*-------------------------------------------------------------------------*/ | ||
155 | |||
156 | /* LEDs are only for debug */ | ||
157 | #ifndef HEX_DISPLAY | ||
158 | #define HEX_DISPLAY(n) do {} while(0) | ||
159 | #endif | ||
160 | |||
161 | #ifdef DEBUG | ||
162 | #include <asm/leds.h> | ||
163 | |||
164 | #define LED_CONNECTED_ON leds_event(led_green_on) | ||
165 | #define LED_CONNECTED_OFF do { \ | ||
166 | leds_event(led_green_off); \ | ||
167 | HEX_DISPLAY(0); \ | ||
168 | } while(0) | ||
169 | #endif | ||
170 | |||
171 | #ifndef LED_CONNECTED_ON | ||
172 | #define LED_CONNECTED_ON do {} while(0) | ||
173 | #define LED_CONNECTED_OFF do {} while(0) | ||
174 | #endif | ||
175 | |||
176 | /*-------------------------------------------------------------------------*/ | ||
177 | |||
178 | static struct pxa2xx_udc *the_controller; | ||
179 | |||
180 | /* one GPIO should be used to detect host disconnect */ | ||
181 | static inline int is_usb_connected(void) | ||
182 | { | ||
183 | if (!the_controller->mach->udc_is_connected) | ||
184 | return 1; | ||
185 | return the_controller->mach->udc_is_connected(); | ||
186 | } | ||
187 | |||
188 | /* one GPIO should force the host to see this device (or not) */ | ||
189 | static inline void make_usb_disappear(void) | ||
190 | { | ||
191 | if (!the_controller->mach->udc_command) | ||
192 | return; | ||
193 | the_controller->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); | ||
194 | } | ||
195 | |||
196 | static inline void let_usb_appear(void) | ||
197 | { | ||
198 | if (!the_controller->mach->udc_command) | ||
199 | return; | ||
200 | the_controller->mach->udc_command(PXA2XX_UDC_CMD_CONNECT); | ||
201 | } | ||
202 | |||
203 | /*-------------------------------------------------------------------------*/ | ||
204 | |||
205 | /* | ||
206 | * Debugging support vanishes in non-debug builds. DBG_NORMAL should be | ||
207 | * mostly silent during normal use/testing, with no timing side-effects. | ||
208 | */ | ||
209 | #define DBG_NORMAL 1 /* error paths, device state transitions */ | ||
210 | #define DBG_VERBOSE 2 /* add some success path trace info */ | ||
211 | #define DBG_NOISY 3 /* ... even more: request level */ | ||
212 | #define DBG_VERY_NOISY 4 /* ... even more: packet level */ | ||
213 | |||
214 | #ifdef DEBUG | ||
215 | |||
216 | static const char *state_name[] = { | ||
217 | "EP0_IDLE", | ||
218 | "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE", | ||
219 | "EP0_END_XFER", "EP0_STALL" | ||
220 | }; | ||
221 | |||
222 | #define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff) | ||
223 | |||
224 | #ifdef VERBOSE | ||
225 | # define UDC_DEBUG DBG_VERBOSE | ||
226 | #else | ||
227 | # define UDC_DEBUG DBG_NORMAL | ||
228 | #endif | ||
229 | |||
230 | static void __attribute__ ((__unused__)) | ||
231 | dump_udccr(const char *label) | ||
232 | { | ||
233 | u32 udccr = UDCCR; | ||
234 | DMSG("%s %02X =%s%s%s%s%s%s%s%s\n", | ||
235 | label, udccr, | ||
236 | (udccr & UDCCR_REM) ? " rem" : "", | ||
237 | (udccr & UDCCR_RSTIR) ? " rstir" : "", | ||
238 | (udccr & UDCCR_SRM) ? " srm" : "", | ||
239 | (udccr & UDCCR_SUSIR) ? " susir" : "", | ||
240 | (udccr & UDCCR_RESIR) ? " resir" : "", | ||
241 | (udccr & UDCCR_RSM) ? " rsm" : "", | ||
242 | (udccr & UDCCR_UDA) ? " uda" : "", | ||
243 | (udccr & UDCCR_UDE) ? " ude" : ""); | ||
244 | } | ||
245 | |||
246 | static void __attribute__ ((__unused__)) | ||
247 | dump_udccs0(const char *label) | ||
248 | { | ||
249 | u32 udccs0 = UDCCS0; | ||
250 | |||
251 | DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n", | ||
252 | label, state_name[the_controller->ep0state], udccs0, | ||
253 | (udccs0 & UDCCS0_SA) ? " sa" : "", | ||
254 | (udccs0 & UDCCS0_RNE) ? " rne" : "", | ||
255 | (udccs0 & UDCCS0_FST) ? " fst" : "", | ||
256 | (udccs0 & UDCCS0_SST) ? " sst" : "", | ||
257 | (udccs0 & UDCCS0_DRWF) ? " dwrf" : "", | ||
258 | (udccs0 & UDCCS0_FTF) ? " ftf" : "", | ||
259 | (udccs0 & UDCCS0_IPR) ? " ipr" : "", | ||
260 | (udccs0 & UDCCS0_OPR) ? " opr" : ""); | ||
261 | } | ||
262 | |||
263 | static void __attribute__ ((__unused__)) | ||
264 | dump_state(struct pxa2xx_udc *dev) | ||
265 | { | ||
266 | u32 tmp; | ||
267 | unsigned i; | ||
268 | |||
269 | DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n", | ||
270 | is_usb_connected() ? "host " : "disconnected", | ||
271 | state_name[dev->ep0state], | ||
272 | UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL); | ||
273 | dump_udccr("udccr"); | ||
274 | if (dev->has_cfr) { | ||
275 | tmp = UDCCFR; | ||
276 | DMSG("udccfr %02X =%s%s\n", tmp, | ||
277 | (tmp & UDCCFR_AREN) ? " aren" : "", | ||
278 | (tmp & UDCCFR_ACM) ? " acm" : ""); | ||
279 | } | ||
280 | |||
281 | if (!dev->driver) { | ||
282 | DMSG("no gadget driver bound\n"); | ||
283 | return; | ||
284 | } else | ||
285 | DMSG("ep0 driver '%s'\n", dev->driver->driver.name); | ||
286 | |||
287 | if (!is_usb_connected()) | ||
288 | return; | ||
289 | |||
290 | dump_udccs0 ("udccs0"); | ||
291 | DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n", | ||
292 | dev->stats.write.bytes, dev->stats.write.ops, | ||
293 | dev->stats.read.bytes, dev->stats.read.ops); | ||
294 | |||
295 | for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) { | ||
296 | if (dev->ep [i].desc == 0) | ||
297 | continue; | ||
298 | DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | #else | ||
303 | |||
304 | #define DMSG(stuff...) do{}while(0) | ||
305 | |||
306 | #define dump_udccr(x) do{}while(0) | ||
307 | #define dump_udccs0(x) do{}while(0) | ||
308 | #define dump_state(x) do{}while(0) | ||
309 | |||
310 | #define UDC_DEBUG ((unsigned)0) | ||
311 | |||
312 | #endif | ||
313 | |||
314 | #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0) | ||
315 | |||
316 | #define WARN(stuff...) printk(KERN_WARNING "udc: " stuff) | ||
317 | #define INFO(stuff...) printk(KERN_INFO "udc: " stuff) | ||
318 | |||
319 | |||
320 | #endif /* __LINUX_USB_GADGET_PXA2XX_H */ | ||