blob: de28a697f634b030dcf25e9e038d17628ec5dc6f [file] [log] [blame]
Lukasz Dalek3c09a282012-10-02 17:04:32 +02001/*
2 * Intel PXA25x on-chip full speed USB device controller
3 *
4 * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
5 * Copyright (C) 2003 David Brownell
6 * Copyright (C) 2012 Lukasz Dalek <luk0104@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __LINUX_USB_GADGET_PXA25X_H
24#define __LINUX_USB_GADGET_PXA25X_H
25
26#include <linux/types.h>
27#include <asm/arch/regs-usb.h>
28
29/*
30 * Prefetching support - only ARMv5.
31 */
32
33#ifdef ARCH_HAS_PREFETCH
34static inline void prefetch(const void *ptr)
35{
36 __asm__ __volatile__(
37 "pld\t%a0"
38 :
39 : "p" (ptr)
40 : "cc");
41}
42
43#define prefetchw(ptr) prefetch(ptr)
44#endif /* ARCH_HAS_PREFETCH */
45
46/*-------------------------------------------------------------------------*/
47
48#define UDC_REGS ((struct pxa25x_udc_regs *)PXA25X_UDC_BASE)
49
50/*-------------------------------------------------------------------------*/
51
52struct pxa2xx_udc_mach_info {
53 int (*udc_is_connected)(void); /* do we see host? */
54 void (*udc_command)(int cmd);
55#define PXA2XX_UDC_CMD_CONNECT 0 /* let host see us */
56#define PXA2XX_UDC_CMD_DISCONNECT 1 /* so host won't see us */
57};
58
59struct pxa25x_udc;
60
61struct pxa25x_ep {
62 struct usb_ep ep;
63 struct pxa25x_udc *dev;
64
65 const struct usb_endpoint_descriptor *desc;
66 struct list_head queue;
67 unsigned long pio_irqs;
68
69 unsigned short fifo_size;
70 u8 bEndpointAddress;
71 u8 bmAttributes;
72
73 unsigned stopped:1;
74
75 /* UDCCS = UDC Control/Status for this EP
76 * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
77 * UDDR = UDC Endpoint Data Register (the fifo)
78 * DRCM = DMA Request Channel Map
79 */
80 u32 *reg_udccs;
81 u32 *reg_ubcr;
82 u32 *reg_uddr;
83};
84
85struct pxa25x_request {
86 struct usb_request req;
87 struct list_head queue;
88};
89
90enum ep0_state {
91 EP0_IDLE,
92 EP0_IN_DATA_PHASE,
93 EP0_OUT_DATA_PHASE,
94 EP0_END_XFER,
95 EP0_STALL,
96};
97
98#define EP0_FIFO_SIZE 16U
99#define BULK_FIFO_SIZE 64U
100#define ISO_FIFO_SIZE 256U
101#define INT_FIFO_SIZE 8U
102
103struct udc_stats {
104 struct ep0stats {
105 unsigned long ops;
106 unsigned long bytes;
107 } read, write;
108 unsigned long irqs;
109};
110
111#ifdef CONFIG_USB_PXA25X_SMALL
112/* when memory's tight, SMALL config saves code+data. */
113#define PXA_UDC_NUM_ENDPOINTS 3
114#endif
115
116#ifndef PXA_UDC_NUM_ENDPOINTS
117#define PXA_UDC_NUM_ENDPOINTS 16
118#endif
119
120struct pxa25x_watchdog {
121 unsigned running:1;
122 ulong period;
123 ulong base;
124 struct pxa25x_udc *udc;
125
126 void (*function)(struct pxa25x_udc *udc);
127};
128
129struct pxa25x_udc {
130 struct usb_gadget gadget;
131 struct usb_gadget_driver *driver;
132 struct pxa25x_udc_regs *regs;
133
134 enum ep0_state ep0state;
135 struct udc_stats stats;
136 unsigned got_irq:1,
137 pullup:1,
138 has_cfr:1,
139 req_pending:1,
140 req_std:1,
141 req_config:1,
142 active:1;
143
144 struct clk *clk;
145 struct pxa2xx_udc_mach_info *mach;
146 u64 dma_mask;
147 struct pxa25x_ep ep[PXA_UDC_NUM_ENDPOINTS];
148
149 struct pxa25x_watchdog watchdog;
150};
151
152/*-------------------------------------------------------------------------*/
153
154static struct pxa25x_udc *the_controller;
155
156/*-------------------------------------------------------------------------*/
157
158#ifndef DEBUG
159# define NOISY 0
160#endif
161
162#endif /* __LINUX_USB_GADGET_PXA25X_H */