xref: /linux/drivers/usb/musb/musb_gadget.h (revision a666e3e6098a9f56310e4ec2705f1dad124a34b5)
1550a7375SFelipe Balbi /*
2550a7375SFelipe Balbi  * MUSB OTG driver peripheral defines
3550a7375SFelipe Balbi  *
4550a7375SFelipe Balbi  * Copyright 2005 Mentor Graphics Corporation
5550a7375SFelipe Balbi  * Copyright (C) 2005-2006 by Texas Instruments
6550a7375SFelipe Balbi  * Copyright (C) 2006-2007 Nokia Corporation
7550a7375SFelipe Balbi  *
8550a7375SFelipe Balbi  * This program is free software; you can redistribute it and/or
9550a7375SFelipe Balbi  * modify it under the terms of the GNU General Public License
10550a7375SFelipe Balbi  * version 2 as published by the Free Software Foundation.
11550a7375SFelipe Balbi  *
12550a7375SFelipe Balbi  * This program is distributed in the hope that it will be useful, but
13550a7375SFelipe Balbi  * WITHOUT ANY WARRANTY; without even the implied warranty of
14550a7375SFelipe Balbi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15550a7375SFelipe Balbi  * General Public License for more details.
16550a7375SFelipe Balbi  *
17550a7375SFelipe Balbi  * You should have received a copy of the GNU General Public License
18550a7375SFelipe Balbi  * along with this program; if not, write to the Free Software
19550a7375SFelipe Balbi  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20550a7375SFelipe Balbi  * 02110-1301 USA
21550a7375SFelipe Balbi  *
22550a7375SFelipe Balbi  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
23550a7375SFelipe Balbi  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24550a7375SFelipe Balbi  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
25550a7375SFelipe Balbi  * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26550a7375SFelipe Balbi  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27550a7375SFelipe Balbi  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28550a7375SFelipe Balbi  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29550a7375SFelipe Balbi  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30550a7375SFelipe Balbi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31550a7375SFelipe Balbi  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32550a7375SFelipe Balbi  *
33550a7375SFelipe Balbi  */
34550a7375SFelipe Balbi 
35550a7375SFelipe Balbi #ifndef __MUSB_GADGET_H
36550a7375SFelipe Balbi #define __MUSB_GADGET_H
37550a7375SFelipe Balbi 
38550a7375SFelipe Balbi struct musb_request {
39550a7375SFelipe Balbi 	struct usb_request	request;
40550a7375SFelipe Balbi 	struct musb_ep		*ep;
41550a7375SFelipe Balbi 	struct musb		*musb;
42550a7375SFelipe Balbi 	u8 tx;			/* endpoint direction */
43550a7375SFelipe Balbi 	u8 epnum;
44550a7375SFelipe Balbi 	u8 mapped;
45550a7375SFelipe Balbi };
46550a7375SFelipe Balbi 
47550a7375SFelipe Balbi static inline struct musb_request *to_musb_request(struct usb_request *req)
48550a7375SFelipe Balbi {
49550a7375SFelipe Balbi 	return req ? container_of(req, struct musb_request, request) : NULL;
50550a7375SFelipe Balbi }
51550a7375SFelipe Balbi 
52550a7375SFelipe Balbi extern struct usb_request *
53550a7375SFelipe Balbi musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
54550a7375SFelipe Balbi extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
55550a7375SFelipe Balbi 
56550a7375SFelipe Balbi 
57550a7375SFelipe Balbi /*
58550a7375SFelipe Balbi  * struct musb_ep - peripheral side view of endpoint rx or tx side
59550a7375SFelipe Balbi  */
60550a7375SFelipe Balbi struct musb_ep {
61550a7375SFelipe Balbi 	/* stuff towards the head is basically write-once. */
62550a7375SFelipe Balbi 	struct usb_ep			end_point;
63550a7375SFelipe Balbi 	char				name[12];
64550a7375SFelipe Balbi 	struct musb_hw_ep		*hw_ep;
65550a7375SFelipe Balbi 	struct musb			*musb;
66550a7375SFelipe Balbi 	u8				current_epnum;
67550a7375SFelipe Balbi 
68550a7375SFelipe Balbi 	/* ... when enabled/disabled ... */
69550a7375SFelipe Balbi 	u8				type;
70550a7375SFelipe Balbi 	u8				is_in;
71550a7375SFelipe Balbi 	u16				packet_sz;
72550a7375SFelipe Balbi 	const struct usb_endpoint_descriptor	*desc;
73550a7375SFelipe Balbi 	struct dma_channel		*dma;
74550a7375SFelipe Balbi 
75550a7375SFelipe Balbi 	/* later things are modified based on usage */
76550a7375SFelipe Balbi 	struct list_head		req_list;
77550a7375SFelipe Balbi 
7847e97605SSergei Shtylyov 	u8				wedged;
7947e97605SSergei Shtylyov 
80550a7375SFelipe Balbi 	/* true if lock must be dropped but req_list may not be advanced */
81550a7375SFelipe Balbi 	u8				busy;
82550a7375SFelipe Balbi };
83550a7375SFelipe Balbi 
84550a7375SFelipe Balbi static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
85550a7375SFelipe Balbi {
86550a7375SFelipe Balbi 	return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
87550a7375SFelipe Balbi }
88550a7375SFelipe Balbi 
89550a7375SFelipe Balbi static inline struct usb_request *next_request(struct musb_ep *ep)
90550a7375SFelipe Balbi {
91550a7375SFelipe Balbi 	struct list_head	*queue = &ep->req_list;
92550a7375SFelipe Balbi 
93550a7375SFelipe Balbi 	if (list_empty(queue))
94550a7375SFelipe Balbi 		return NULL;
95550a7375SFelipe Balbi 	return container_of(queue->next, struct usb_request, list);
96550a7375SFelipe Balbi }
97550a7375SFelipe Balbi 
98550a7375SFelipe Balbi extern void musb_g_tx(struct musb *musb, u8 epnum);
99550a7375SFelipe Balbi extern void musb_g_rx(struct musb *musb, u8 epnum);
100550a7375SFelipe Balbi 
101550a7375SFelipe Balbi extern const struct usb_ep_ops musb_g_ep0_ops;
102550a7375SFelipe Balbi 
103550a7375SFelipe Balbi extern int musb_gadget_setup(struct musb *);
104550a7375SFelipe Balbi extern void musb_gadget_cleanup(struct musb *);
105550a7375SFelipe Balbi 
106550a7375SFelipe Balbi extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
107550a7375SFelipe Balbi 
108*a666e3e6SSergei Shtylyov extern void musb_ep_restart(struct musb *, struct musb_request *);
109*a666e3e6SSergei Shtylyov 
110550a7375SFelipe Balbi #endif		/* __MUSB_GADGET_H */
111