2 * MUSB OTG driver peripheral defines
4 * Copyright 2005 Mentor Graphics Corporation
5 * Copyright (C) 2005-2006 by Texas Instruments
6 * Copyright (C) 2006-2007 Nokia Corporation
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
25 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef __MUSB_GADGET_H
36 #define __MUSB_GADGET_H
38 #include <linux/list.h>
40 #include <asm/byteorder.h>
41 #include <asm/errno.h>
42 #include <linux/usb/ch9.h>
43 #include <linux/usb/gadget.h>
46 enum buffer_map_state {
53 struct usb_request request;
54 struct list_head list;
57 u8 tx; /* endpoint direction */
59 enum buffer_map_state map_state;
62 static inline struct musb_request *to_musb_request(struct usb_request *req)
64 return req ? container_of(req, struct musb_request, request) : NULL;
67 extern struct usb_request *
68 musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
69 extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
73 * struct musb_ep - peripheral side view of endpoint rx or tx side
76 /* stuff towards the head is basically write-once. */
77 struct usb_ep end_point;
79 struct musb_hw_ep *hw_ep;
83 /* ... when enabled/disabled ... */
87 const struct usb_endpoint_descriptor *desc;
88 struct dma_channel *dma;
90 /* later things are modified based on usage */
91 struct list_head req_list;
95 /* true if lock must be dropped but req_list may not be advanced */
101 static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
103 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
106 static inline struct musb_request *next_request(struct musb_ep *ep)
108 struct list_head *queue = &ep->req_list;
110 if (list_empty(queue))
112 return container_of(queue->next, struct musb_request, list);
115 extern void musb_g_tx(struct musb *musb, u8 epnum);
116 extern void musb_g_rx(struct musb *musb, u8 epnum);
118 extern const struct usb_ep_ops musb_g_ep0_ops;
120 extern int musb_gadget_setup(struct musb *);
121 extern void musb_gadget_cleanup(struct musb *);
123 extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
125 extern void musb_ep_restart(struct musb *, struct musb_request *);
128 int musb_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver);
130 #endif /* __MUSB_GADGET_H */