xref: /openbmc/u-boot/drivers/usb/gadget/pxa25x_udc.h (revision ae485b54)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Intel PXA25x 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  * Copyright (C) 2012 Lukasz Dalek <luk0104@gmail.com>
8  */
9 
10 #ifndef __LINUX_USB_GADGET_PXA25X_H
11 #define __LINUX_USB_GADGET_PXA25X_H
12 
13 #include <linux/types.h>
14 #include <asm/arch/regs-usb.h>
15 
16 /*
17  * Prefetching support - only ARMv5.
18  */
19 
20 #ifdef ARCH_HAS_PREFETCH
21 static inline void prefetch(const void *ptr)
22 {
23 	__asm__ __volatile__(
24 		"pld\t%a0"
25 		:
26 		: "p" (ptr)
27 		: "cc");
28 }
29 
30 #define prefetchw(ptr)	prefetch(ptr)
31 #endif /* ARCH_HAS_PREFETCH */
32 
33 /*-------------------------------------------------------------------------*/
34 
35 #define UDC_REGS	((struct pxa25x_udc_regs *)PXA25X_UDC_BASE)
36 
37 /*-------------------------------------------------------------------------*/
38 
39 struct pxa2xx_udc_mach_info {
40 	int  (*udc_is_connected)(void);		/* do we see host? */
41 	void (*udc_command)(int cmd);
42 #define	PXA2XX_UDC_CMD_CONNECT		0	/* let host see us */
43 #define	PXA2XX_UDC_CMD_DISCONNECT	1	/* so host won't see us */
44 };
45 
46 struct pxa25x_udc;
47 
48 struct pxa25x_ep {
49 	struct usb_ep				ep;
50 	struct pxa25x_udc			*dev;
51 
52 	const struct usb_endpoint_descriptor	*desc;
53 	struct list_head			queue;
54 	unsigned long				pio_irqs;
55 
56 	unsigned short				fifo_size;
57 	u8					bEndpointAddress;
58 	u8					bmAttributes;
59 
60 	unsigned				stopped:1;
61 
62 	/* UDCCS = UDC Control/Status for this EP
63 	 * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
64 	 * UDDR = UDC Endpoint Data Register (the fifo)
65 	 * DRCM = DMA Request Channel Map
66 	 */
67 	u32					*reg_udccs;
68 	u32					*reg_ubcr;
69 	u32					*reg_uddr;
70 };
71 
72 struct pxa25x_request {
73 	struct usb_request			req;
74 	struct list_head			queue;
75 };
76 
77 enum ep0_state {
78 	EP0_IDLE,
79 	EP0_IN_DATA_PHASE,
80 	EP0_OUT_DATA_PHASE,
81 	EP0_END_XFER,
82 	EP0_STALL,
83 };
84 
85 #define EP0_FIFO_SIZE	16U
86 #define BULK_FIFO_SIZE	64U
87 #define ISO_FIFO_SIZE	256U
88 #define INT_FIFO_SIZE	8U
89 
90 struct udc_stats {
91 	struct ep0stats {
92 		unsigned long		ops;
93 		unsigned long		bytes;
94 	} read, write;
95 	unsigned long			irqs;
96 };
97 
98 #ifdef CONFIG_USB_PXA25X_SMALL
99 /* when memory's tight, SMALL config saves code+data.  */
100 #define	PXA_UDC_NUM_ENDPOINTS	3
101 #endif
102 
103 #ifndef	PXA_UDC_NUM_ENDPOINTS
104 #define	PXA_UDC_NUM_ENDPOINTS	16
105 #endif
106 
107 struct pxa25x_watchdog {
108 	unsigned				running:1;
109 	ulong					period;
110 	ulong					base;
111 	struct pxa25x_udc			*udc;
112 
113 	void (*function)(struct pxa25x_udc *udc);
114 };
115 
116 struct pxa25x_udc {
117 	struct usb_gadget			gadget;
118 	struct usb_gadget_driver		*driver;
119 	struct pxa25x_udc_regs			*regs;
120 
121 	enum ep0_state				ep0state;
122 	struct udc_stats			stats;
123 	unsigned				got_irq:1,
124 						pullup:1,
125 						has_cfr:1,
126 						req_pending:1,
127 						req_std:1,
128 						req_config:1,
129 						active:1;
130 
131 	struct clk				*clk;
132 	struct pxa2xx_udc_mach_info		*mach;
133 	u64					dma_mask;
134 	struct pxa25x_ep			ep[PXA_UDC_NUM_ENDPOINTS];
135 
136 	struct pxa25x_watchdog			watchdog;
137 };
138 
139 /*-------------------------------------------------------------------------*/
140 
141 static struct pxa25x_udc *the_controller;
142 
143 /*-------------------------------------------------------------------------*/
144 
145 #ifndef DEBUG
146 # define NOISY 0
147 #endif
148 
149 #endif /* __LINUX_USB_GADGET_PXA25X_H */
150