]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/usb/musb/musb_gadget.h
USB: add SPDX identifiers to all remaining files in drivers/usb/
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / musb / musb_gadget.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * MUSB OTG driver peripheral defines
4 *
5 * Copyright 2005 Mentor Graphics Corporation
6 * Copyright (C) 2005-2006 by Texas Instruments
7 * Copyright (C) 2006-2007 Nokia Corporation
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * 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., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
26 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36 #ifndef __MUSB_GADGET_H
37 #define __MUSB_GADGET_H
38
39 #include <linux/list.h>
40
41 #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
42 extern irqreturn_t musb_g_ep0_irq(struct musb *);
43 extern void musb_g_tx(struct musb *, u8);
44 extern void musb_g_rx(struct musb *, u8);
45 extern void musb_g_reset(struct musb *);
46 extern void musb_g_suspend(struct musb *);
47 extern void musb_g_resume(struct musb *);
48 extern void musb_g_wakeup(struct musb *);
49 extern void musb_g_disconnect(struct musb *);
50 extern void musb_gadget_cleanup(struct musb *);
51 extern int musb_gadget_setup(struct musb *);
52
53 #else
54 static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
55 {
56 return 0;
57 }
58
59 static inline void musb_g_tx(struct musb *musb, u8 epnum) {}
60 static inline void musb_g_rx(struct musb *musb, u8 epnum) {}
61 static inline void musb_g_reset(struct musb *musb) {}
62 static inline void musb_g_suspend(struct musb *musb) {}
63 static inline void musb_g_resume(struct musb *musb) {}
64 static inline void musb_g_wakeup(struct musb *musb) {}
65 static inline void musb_g_disconnect(struct musb *musb) {}
66 static inline void musb_gadget_cleanup(struct musb *musb) {}
67 static inline int musb_gadget_setup(struct musb *musb)
68 {
69 return 0;
70 }
71 #endif
72
73 enum buffer_map_state {
74 UN_MAPPED = 0,
75 PRE_MAPPED,
76 MUSB_MAPPED
77 };
78
79 struct musb_request {
80 struct usb_request request;
81 struct list_head list;
82 struct musb_ep *ep;
83 struct musb *musb;
84 u8 tx; /* endpoint direction */
85 u8 epnum;
86 enum buffer_map_state map_state;
87 };
88
89 static inline struct musb_request *to_musb_request(struct usb_request *req)
90 {
91 return req ? container_of(req, struct musb_request, request) : NULL;
92 }
93
94 extern struct usb_request *
95 musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
96 extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
97
98
99 /*
100 * struct musb_ep - peripheral side view of endpoint rx or tx side
101 */
102 struct musb_ep {
103 /* stuff towards the head is basically write-once. */
104 struct usb_ep end_point;
105 char name[12];
106 struct musb_hw_ep *hw_ep;
107 struct musb *musb;
108 u8 current_epnum;
109
110 /* ... when enabled/disabled ... */
111 u8 type;
112 u8 is_in;
113 u16 packet_sz;
114 const struct usb_endpoint_descriptor *desc;
115 struct dma_channel *dma;
116
117 /* later things are modified based on usage */
118 struct list_head req_list;
119
120 u8 wedged;
121
122 /* true if lock must be dropped but req_list may not be advanced */
123 u8 busy;
124
125 u8 hb_mult;
126 };
127
128 static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
129 {
130 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
131 }
132
133 static inline struct musb_request *next_request(struct musb_ep *ep)
134 {
135 struct list_head *queue = &ep->req_list;
136
137 if (list_empty(queue))
138 return NULL;
139 return container_of(queue->next, struct musb_request, list);
140 }
141
142 extern const struct usb_ep_ops musb_g_ep0_ops;
143
144 extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
145
146 extern void musb_ep_restart(struct musb *, struct musb_request *);
147
148 #endif /* __MUSB_GADGET_H */