xref: /linux/drivers/usb/musb/musb_gadget.h (revision 6814c73fdc46cc5d0ece070af507cb95666b3f6a)
1*6814c73fSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2550a7375SFelipe Balbi /*
3550a7375SFelipe Balbi  * MUSB OTG driver peripheral defines
4550a7375SFelipe Balbi  *
5550a7375SFelipe Balbi  * Copyright 2005 Mentor Graphics Corporation
6550a7375SFelipe Balbi  * Copyright (C) 2005-2006 by Texas Instruments
7550a7375SFelipe Balbi  * Copyright (C) 2006-2007 Nokia Corporation
8550a7375SFelipe Balbi  */
9550a7375SFelipe Balbi 
10550a7375SFelipe Balbi #ifndef __MUSB_GADGET_H
11550a7375SFelipe Balbi #define __MUSB_GADGET_H
12550a7375SFelipe Balbi 
13ad1adb89SFelipe Balbi #include <linux/list.h>
14ad1adb89SFelipe Balbi 
15b7b741eaSDaniel Mack #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
16c2a2759dSDaniel Mack extern irqreturn_t musb_g_ep0_irq(struct musb *);
17c2a2759dSDaniel Mack extern void musb_g_tx(struct musb *, u8);
18c2a2759dSDaniel Mack extern void musb_g_rx(struct musb *, u8);
19c2a2759dSDaniel Mack extern void musb_g_reset(struct musb *);
20c2a2759dSDaniel Mack extern void musb_g_suspend(struct musb *);
21c2a2759dSDaniel Mack extern void musb_g_resume(struct musb *);
22c2a2759dSDaniel Mack extern void musb_g_wakeup(struct musb *);
23c2a2759dSDaniel Mack extern void musb_g_disconnect(struct musb *);
24c2a2759dSDaniel Mack extern void musb_gadget_cleanup(struct musb *);
25c2a2759dSDaniel Mack extern int musb_gadget_setup(struct musb *);
26c2a2759dSDaniel Mack 
27b7b741eaSDaniel Mack #else
28b7b741eaSDaniel Mack static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
29b7b741eaSDaniel Mack {
30b7b741eaSDaniel Mack 	return 0;
31b7b741eaSDaniel Mack }
32b7b741eaSDaniel Mack 
33b7b741eaSDaniel Mack static inline void musb_g_tx(struct musb *musb, u8 epnum)	{}
34b7b741eaSDaniel Mack static inline void musb_g_rx(struct musb *musb, u8 epnum)	{}
35b7b741eaSDaniel Mack static inline void musb_g_reset(struct musb *musb)		{}
36b7b741eaSDaniel Mack static inline void musb_g_suspend(struct musb *musb)		{}
37b7b741eaSDaniel Mack static inline void musb_g_resume(struct musb *musb)		{}
38b7b741eaSDaniel Mack static inline void musb_g_wakeup(struct musb *musb)		{}
39b7b741eaSDaniel Mack static inline void musb_g_disconnect(struct musb *musb)		{}
40b7b741eaSDaniel Mack static inline void musb_gadget_cleanup(struct musb *musb)	{}
41b7b741eaSDaniel Mack static inline int musb_gadget_setup(struct musb *musb)
42b7b741eaSDaniel Mack {
43b7b741eaSDaniel Mack 	return 0;
44b7b741eaSDaniel Mack }
45b7b741eaSDaniel Mack #endif
46b7b741eaSDaniel Mack 
47c65bfa62SMian Yousaf Kaukab enum buffer_map_state {
48c65bfa62SMian Yousaf Kaukab 	UN_MAPPED = 0,
49c65bfa62SMian Yousaf Kaukab 	PRE_MAPPED,
50c65bfa62SMian Yousaf Kaukab 	MUSB_MAPPED
51c65bfa62SMian Yousaf Kaukab };
52c65bfa62SMian Yousaf Kaukab 
53550a7375SFelipe Balbi struct musb_request {
54550a7375SFelipe Balbi 	struct usb_request	request;
55ad1adb89SFelipe Balbi 	struct list_head	list;
56550a7375SFelipe Balbi 	struct musb_ep		*ep;
57550a7375SFelipe Balbi 	struct musb		*musb;
58550a7375SFelipe Balbi 	u8 tx;			/* endpoint direction */
59550a7375SFelipe Balbi 	u8 epnum;
60c65bfa62SMian Yousaf Kaukab 	enum buffer_map_state map_state;
61550a7375SFelipe Balbi };
62550a7375SFelipe Balbi 
638dca5107SBin Liu #define to_musb_request(r)	container_of((r), struct musb_request, request)
64550a7375SFelipe Balbi 
65550a7375SFelipe Balbi extern struct usb_request *
66550a7375SFelipe Balbi musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
67550a7375SFelipe Balbi extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
68550a7375SFelipe Balbi 
69550a7375SFelipe Balbi 
70550a7375SFelipe Balbi /*
71550a7375SFelipe Balbi  * struct musb_ep - peripheral side view of endpoint rx or tx side
72550a7375SFelipe Balbi  */
73550a7375SFelipe Balbi struct musb_ep {
74550a7375SFelipe Balbi 	/* stuff towards the head is basically write-once. */
75550a7375SFelipe Balbi 	struct usb_ep			end_point;
76550a7375SFelipe Balbi 	char				name[12];
77550a7375SFelipe Balbi 	struct musb_hw_ep		*hw_ep;
78550a7375SFelipe Balbi 	struct musb			*musb;
79550a7375SFelipe Balbi 	u8				current_epnum;
80550a7375SFelipe Balbi 
81550a7375SFelipe Balbi 	/* ... when enabled/disabled ... */
82550a7375SFelipe Balbi 	u8				type;
83550a7375SFelipe Balbi 	u8				is_in;
84550a7375SFelipe Balbi 	u16				packet_sz;
85550a7375SFelipe Balbi 	const struct usb_endpoint_descriptor	*desc;
86550a7375SFelipe Balbi 	struct dma_channel		*dma;
87550a7375SFelipe Balbi 
88550a7375SFelipe Balbi 	/* later things are modified based on usage */
89550a7375SFelipe Balbi 	struct list_head		req_list;
90550a7375SFelipe Balbi 
9147e97605SSergei Shtylyov 	u8				wedged;
9247e97605SSergei Shtylyov 
93550a7375SFelipe Balbi 	/* true if lock must be dropped but req_list may not be advanced */
94550a7375SFelipe Balbi 	u8				busy;
95f11d893dSMing Lei 
96f11d893dSMing Lei 	u8				hb_mult;
97550a7375SFelipe Balbi };
98550a7375SFelipe Balbi 
99ddf12f04SBin Liu #define to_musb_ep(ep)	container_of((ep), struct musb_ep, end_point)
100550a7375SFelipe Balbi 
101ad1adb89SFelipe Balbi static inline struct musb_request *next_request(struct musb_ep *ep)
102550a7375SFelipe Balbi {
103550a7375SFelipe Balbi 	struct list_head	*queue = &ep->req_list;
104550a7375SFelipe Balbi 
105550a7375SFelipe Balbi 	if (list_empty(queue))
106550a7375SFelipe Balbi 		return NULL;
107ad1adb89SFelipe Balbi 	return container_of(queue->next, struct musb_request, list);
108550a7375SFelipe Balbi }
109550a7375SFelipe Balbi 
110550a7375SFelipe Balbi extern const struct usb_ep_ops musb_g_ep0_ops;
111550a7375SFelipe Balbi 
112550a7375SFelipe Balbi extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
113550a7375SFelipe Balbi 
114a666e3e6SSergei Shtylyov extern void musb_ep_restart(struct musb *, struct musb_request *);
115a666e3e6SSergei Shtylyov 
116550a7375SFelipe Balbi #endif		/* __MUSB_GADGET_H */
117