Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * MUSB OTG driver peripheral defines
0004  *
0005  * Copyright 2005 Mentor Graphics Corporation
0006  * Copyright (C) 2005-2006 by Texas Instruments
0007  * Copyright (C) 2006-2007 Nokia Corporation
0008  */
0009 
0010 #ifndef __MUSB_GADGET_H
0011 #define __MUSB_GADGET_H
0012 
0013 #include <linux/list.h>
0014 
0015 #if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
0016 extern irqreturn_t musb_g_ep0_irq(struct musb *);
0017 extern void musb_g_tx(struct musb *, u8);
0018 extern void musb_g_rx(struct musb *, u8);
0019 extern void musb_g_reset(struct musb *);
0020 extern void musb_g_suspend(struct musb *);
0021 extern void musb_g_resume(struct musb *);
0022 extern void musb_g_wakeup(struct musb *);
0023 extern void musb_g_disconnect(struct musb *);
0024 extern void musb_gadget_cleanup(struct musb *);
0025 extern int musb_gadget_setup(struct musb *);
0026 
0027 #else
0028 static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
0029 {
0030     return 0;
0031 }
0032 
0033 static inline void musb_g_tx(struct musb *musb, u8 epnum)   {}
0034 static inline void musb_g_rx(struct musb *musb, u8 epnum)   {}
0035 static inline void musb_g_reset(struct musb *musb)      {}
0036 static inline void musb_g_suspend(struct musb *musb)        {}
0037 static inline void musb_g_resume(struct musb *musb)     {}
0038 static inline void musb_g_wakeup(struct musb *musb)     {}
0039 static inline void musb_g_disconnect(struct musb *musb)     {}
0040 static inline void musb_gadget_cleanup(struct musb *musb)   {}
0041 static inline int musb_gadget_setup(struct musb *musb)
0042 {
0043     return 0;
0044 }
0045 #endif
0046 
0047 enum buffer_map_state {
0048     UN_MAPPED = 0,
0049     PRE_MAPPED,
0050     MUSB_MAPPED
0051 };
0052 
0053 struct musb_request {
0054     struct usb_request  request;
0055     struct list_head    list;
0056     struct musb_ep      *ep;
0057     struct musb     *musb;
0058     u8 tx;          /* endpoint direction */
0059     u8 epnum;
0060     enum buffer_map_state map_state;
0061 };
0062 
0063 #define to_musb_request(r)  container_of((r), struct musb_request, request)
0064 
0065 extern struct usb_request *
0066 musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
0067 extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
0068 
0069 
0070 /*
0071  * struct musb_ep - peripheral side view of endpoint rx or tx side
0072  */
0073 struct musb_ep {
0074     /* stuff towards the head is basically write-once. */
0075     struct usb_ep           end_point;
0076     char                name[12];
0077     struct musb_hw_ep       *hw_ep;
0078     struct musb         *musb;
0079     u8              current_epnum;
0080 
0081     /* ... when enabled/disabled ... */
0082     u8              type;
0083     u8              is_in;
0084     u16             packet_sz;
0085     const struct usb_endpoint_descriptor    *desc;
0086     struct dma_channel      *dma;
0087 
0088     /* later things are modified based on usage */
0089     struct list_head        req_list;
0090 
0091     u8              wedged;
0092 
0093     /* true if lock must be dropped but req_list may not be advanced */
0094     u8              busy;
0095 
0096     u8              hb_mult;
0097 };
0098 
0099 #define to_musb_ep(ep)  container_of((ep), struct musb_ep, end_point)
0100 
0101 static inline struct musb_request *next_request(struct musb_ep *ep)
0102 {
0103     struct list_head    *queue = &ep->req_list;
0104 
0105     if (list_empty(queue))
0106         return NULL;
0107     return container_of(queue->next, struct musb_request, list);
0108 }
0109 
0110 extern const struct usb_ep_ops musb_g_ep0_ops;
0111 
0112 extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
0113 
0114 extern void musb_ep_restart(struct musb *, struct musb_request *);
0115 
0116 #endif      /* __MUSB_GADGET_H */