1 /* SPDX-License-Identifier: GPL-2.0 */
3 * MUSB OTG driver peripheral defines
5 * Copyright 2005 Mentor Graphics Corporation
6 * Copyright (C) 2005-2006 by Texas Instruments
7 * Copyright (C) 2006-2007 Nokia Corporation
10 #ifndef __MUSB_GADGET_H
11 #define __MUSB_GADGET_H
13 #include <linux/list.h>
15 #include <asm/byteorder.h>
16 #include <linux/errno.h>
17 #include <linux/usb/ch9.h>
18 #include <linux/usb/gadget.h>
21 enum buffer_map_state {
28 struct usb_request request;
29 struct list_head list;
32 u8 tx; /* endpoint direction */
34 enum buffer_map_state map_state;
37 static inline struct musb_request *to_musb_request(struct usb_request *req)
39 return req ? container_of(req, struct musb_request, request) : NULL;
42 extern struct usb_request *
43 musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
44 extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
48 * struct musb_ep - peripheral side view of endpoint rx or tx side
51 /* stuff towards the head is basically write-once. */
52 struct usb_ep end_point;
54 struct musb_hw_ep *hw_ep;
58 /* ... when enabled/disabled ... */
62 const struct usb_endpoint_descriptor *desc;
63 struct dma_channel *dma;
65 /* later things are modified based on usage */
66 struct list_head req_list;
70 /* true if lock must be dropped but req_list may not be advanced */
76 static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
78 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
81 static inline struct musb_request *next_request(struct musb_ep *ep)
83 struct list_head *queue = &ep->req_list;
85 if (list_empty(queue))
87 return container_of(queue->next, struct musb_request, list);
90 extern void musb_g_tx(struct musb *musb, u8 epnum);
91 extern void musb_g_rx(struct musb *musb, u8 epnum);
93 extern const struct usb_ep_ops musb_g_ep0_ops;
95 extern int musb_gadget_setup(struct musb *);
96 extern void musb_gadget_cleanup(struct musb *);
98 extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
100 extern void musb_ep_restart(struct musb *, struct musb_request *);
103 int musb_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver);
105 #endif /* __MUSB_GADGET_H */