Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * MUSB OTG driver peripheral defines |
| 3 | * |
| 4 | * Copyright 2005 Mentor Graphics Corporation |
| 5 | * Copyright (C) 2005-2006 by Texas Instruments |
| 6 | * Copyright (C) 2006-2007 Nokia Corporation |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * 02110-1301 USA |
| 21 | * |
| 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. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #ifndef __MUSB_GADGET_H |
| 36 | #define __MUSB_GADGET_H |
| 37 | |
Felipe Balbi | ad1adb8 | 2011-02-16 12:40:05 +0200 | [diff] [blame] | 38 | #include <linux/list.h> |
| 39 | |
Daniel Mack | c2a2759 | 2013-04-10 21:55:41 +0200 | [diff] [blame^] | 40 | extern irqreturn_t musb_g_ep0_irq(struct musb *); |
| 41 | extern void musb_g_tx(struct musb *, u8); |
| 42 | extern void musb_g_rx(struct musb *, u8); |
| 43 | extern void musb_g_reset(struct musb *); |
| 44 | extern void musb_g_suspend(struct musb *); |
| 45 | extern void musb_g_resume(struct musb *); |
| 46 | extern void musb_g_wakeup(struct musb *); |
| 47 | extern void musb_g_disconnect(struct musb *); |
| 48 | extern void musb_gadget_cleanup(struct musb *); |
| 49 | extern int musb_gadget_setup(struct musb *); |
| 50 | |
Mian Yousaf Kaukab | c65bfa6 | 2011-01-04 12:47:02 +0100 | [diff] [blame] | 51 | enum buffer_map_state { |
| 52 | UN_MAPPED = 0, |
| 53 | PRE_MAPPED, |
| 54 | MUSB_MAPPED |
| 55 | }; |
| 56 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 57 | struct musb_request { |
| 58 | struct usb_request request; |
Felipe Balbi | ad1adb8 | 2011-02-16 12:40:05 +0200 | [diff] [blame] | 59 | struct list_head list; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 60 | struct musb_ep *ep; |
| 61 | struct musb *musb; |
| 62 | u8 tx; /* endpoint direction */ |
| 63 | u8 epnum; |
Mian Yousaf Kaukab | c65bfa6 | 2011-01-04 12:47:02 +0100 | [diff] [blame] | 64 | enum buffer_map_state map_state; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | static inline struct musb_request *to_musb_request(struct usb_request *req) |
| 68 | { |
| 69 | return req ? container_of(req, struct musb_request, request) : NULL; |
| 70 | } |
| 71 | |
| 72 | extern struct usb_request * |
| 73 | musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags); |
| 74 | extern void musb_free_request(struct usb_ep *ep, struct usb_request *req); |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | * struct musb_ep - peripheral side view of endpoint rx or tx side |
| 79 | */ |
| 80 | struct musb_ep { |
| 81 | /* stuff towards the head is basically write-once. */ |
| 82 | struct usb_ep end_point; |
| 83 | char name[12]; |
| 84 | struct musb_hw_ep *hw_ep; |
| 85 | struct musb *musb; |
| 86 | u8 current_epnum; |
| 87 | |
| 88 | /* ... when enabled/disabled ... */ |
| 89 | u8 type; |
| 90 | u8 is_in; |
| 91 | u16 packet_sz; |
| 92 | const struct usb_endpoint_descriptor *desc; |
| 93 | struct dma_channel *dma; |
| 94 | |
| 95 | /* later things are modified based on usage */ |
| 96 | struct list_head req_list; |
| 97 | |
Sergei Shtylyov | 47e9760 | 2009-11-18 22:51:51 +0300 | [diff] [blame] | 98 | u8 wedged; |
| 99 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 100 | /* true if lock must be dropped but req_list may not be advanced */ |
| 101 | u8 busy; |
Ming Lei | f11d893 | 2010-09-24 13:44:04 +0300 | [diff] [blame] | 102 | |
| 103 | u8 hb_mult; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static inline struct musb_ep *to_musb_ep(struct usb_ep *ep) |
| 107 | { |
| 108 | return ep ? container_of(ep, struct musb_ep, end_point) : NULL; |
| 109 | } |
| 110 | |
Felipe Balbi | ad1adb8 | 2011-02-16 12:40:05 +0200 | [diff] [blame] | 111 | static inline struct musb_request *next_request(struct musb_ep *ep) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 112 | { |
| 113 | struct list_head *queue = &ep->req_list; |
| 114 | |
| 115 | if (list_empty(queue)) |
| 116 | return NULL; |
Felipe Balbi | ad1adb8 | 2011-02-16 12:40:05 +0200 | [diff] [blame] | 117 | return container_of(queue->next, struct musb_request, list); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 118 | } |
| 119 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 120 | extern const struct usb_ep_ops musb_g_ep0_ops; |
| 121 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 122 | extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int); |
| 123 | |
Sergei Shtylyov | a666e3e | 2010-09-11 13:23:12 -0500 | [diff] [blame] | 124 | extern void musb_ep_restart(struct musb *, struct musb_request *); |
| 125 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 126 | #endif /* __MUSB_GADGET_H */ |