Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * MUSB OTG driver host 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_HOST_H |
| 36 | #define _MUSB_HOST_H |
| 37 | |
Virupax Sadashivpetimath | 8e8a551 | 2012-08-07 14:46:20 +0530 | [diff] [blame] | 38 | #include <linux/scatterlist.h> |
| 39 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 40 | /* stored in "usb_host_endpoint.hcpriv" for scheduled endpoints */ |
| 41 | struct musb_qh { |
| 42 | struct usb_host_endpoint *hep; /* usbcore info */ |
| 43 | struct usb_device *dev; |
| 44 | struct musb_hw_ep *hw_ep; /* current binding */ |
| 45 | |
| 46 | struct list_head ring; /* of musb_qh */ |
| 47 | /* struct musb_qh *next; */ /* for periodic tree */ |
Ajay Kumar Gupta | 23d15e0 | 2008-10-29 15:10:35 +0200 | [diff] [blame] | 48 | u8 mux; /* qh multiplexed to hw_ep */ |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 49 | |
| 50 | unsigned offset; /* in urb->transfer_buffer */ |
| 51 | unsigned segsize; /* current xfer fragment */ |
| 52 | |
| 53 | u8 type_reg; /* {rx,tx} type register */ |
| 54 | u8 intv_reg; /* {rx,tx} interval register */ |
| 55 | u8 addr_reg; /* device address register */ |
| 56 | u8 h_addr_reg; /* hub address register */ |
| 57 | u8 h_port_reg; /* hub port register */ |
| 58 | |
| 59 | u8 is_ready; /* safe to modify hw_ep */ |
| 60 | u8 type; /* XFERTYPE_* */ |
| 61 | u8 epnum; |
Ajay Kumar Gupta | a483d70 | 2009-04-03 16:16:17 -0700 | [diff] [blame] | 62 | u8 hb_mult; /* high bandwidth pkts per uf */ |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 63 | u16 maxpacket; |
| 64 | u16 frame; /* for periodic schedule */ |
| 65 | unsigned iso_idx; /* in urb->iso_frame_desc[] */ |
Virupax Sadashivpetimath | 8e8a551 | 2012-08-07 14:46:20 +0530 | [diff] [blame] | 66 | struct sg_mapping_iter sg_miter; /* for highmem in PIO mode */ |
Virupax Sadashivpetimath | ed74df1 | 2013-04-24 08:38:48 +0200 | [diff] [blame] | 67 | bool use_sg; /* to track urb using sglist */ |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /* map from control or bulk queue head to the first qh on that ring */ |
| 71 | static inline struct musb_qh *first_qh(struct list_head *q) |
| 72 | { |
| 73 | if (list_empty(q)) |
| 74 | return NULL; |
| 75 | return list_entry(q->next, struct musb_qh, ring); |
| 76 | } |
| 77 | |
| 78 | |
Daniel Mack | b7b741e | 2013-04-10 21:55:46 +0200 | [diff] [blame] | 79 | #if IS_ENABLED(CONFIG_USB_MUSB_HOST) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE) |
| 80 | extern struct musb *hcd_to_musb(struct usb_hcd *); |
Daniel Mack | c2a2759 | 2013-04-10 21:55:41 +0200 | [diff] [blame] | 81 | extern irqreturn_t musb_h_ep0_irq(struct musb *); |
Daniel Mack | 74c2e93 | 2013-04-10 21:55:45 +0200 | [diff] [blame] | 82 | extern int musb_host_alloc(struct musb *); |
Daniel Mack | 2cc65fe | 2013-04-10 21:55:47 +0200 | [diff] [blame] | 83 | extern int musb_host_setup(struct musb *, int); |
| 84 | extern void musb_host_cleanup(struct musb *); |
Daniel Mack | c2a2759 | 2013-04-10 21:55:41 +0200 | [diff] [blame] | 85 | extern void musb_host_tx(struct musb *, u8); |
| 86 | extern void musb_host_rx(struct musb *, u8); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 87 | extern void musb_root_disconnect(struct musb *musb); |
Daniel Mack | 74c2e93 | 2013-04-10 21:55:45 +0200 | [diff] [blame] | 88 | extern void musb_host_free(struct musb *); |
| 89 | extern void musb_host_cleanup(struct musb *); |
| 90 | extern void musb_host_tx(struct musb *, u8); |
| 91 | extern void musb_host_rx(struct musb *, u8); |
| 92 | extern void musb_root_disconnect(struct musb *musb); |
Daniel Mack | 0b3eba4 | 2013-04-10 21:55:42 +0200 | [diff] [blame] | 93 | extern void musb_host_resume_root_hub(struct musb *musb); |
| 94 | extern void musb_host_poke_root_hub(struct musb *musb); |
Daniel Mack | 94f7213 | 2013-11-25 22:26:41 +0100 | [diff] [blame] | 95 | extern void musb_port_suspend(struct musb *musb, bool do_suspend); |
Daniel Mack | 869c597 | 2013-11-26 13:31:14 +0100 | [diff] [blame] | 96 | extern void musb_port_reset(struct musb *musb, bool do_reset); |
Daniel Mack | 8ed1fb7 | 2013-12-18 20:23:46 +0100 | [diff] [blame] | 97 | extern void musb_host_finish_resume(struct work_struct *work); |
Daniel Mack | b7b741e | 2013-04-10 21:55:46 +0200 | [diff] [blame] | 98 | #else |
| 99 | static inline struct musb *hcd_to_musb(struct usb_hcd *hcd) |
| 100 | { |
| 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | static inline irqreturn_t musb_h_ep0_irq(struct musb *musb) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static inline int musb_host_alloc(struct musb *musb) |
| 110 | { |
| 111 | return 0; |
| 112 | } |
| 113 | |
Daniel Mack | 2cc65fe | 2013-04-10 21:55:47 +0200 | [diff] [blame] | 114 | static inline int musb_host_setup(struct musb *musb, int power_budget) |
| 115 | { |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static inline void musb_host_cleanup(struct musb *musb) {} |
Daniel Mack | b7b741e | 2013-04-10 21:55:46 +0200 | [diff] [blame] | 120 | static inline void musb_host_free(struct musb *musb) {} |
| 121 | static inline void musb_host_tx(struct musb *musb, u8 epnum) {} |
| 122 | static inline void musb_host_rx(struct musb *musb, u8 epnum) {} |
| 123 | static inline void musb_root_disconnect(struct musb *musb) {} |
| 124 | static inline void musb_host_resume_root_hub(struct musb *musb) {} |
| 125 | static inline void musb_host_poll_rh_status(struct musb *musb) {} |
| 126 | static inline void musb_host_poke_root_hub(struct musb *musb) {} |
Daniel Mack | 94f7213 | 2013-11-25 22:26:41 +0100 | [diff] [blame] | 127 | static inline void musb_port_suspend(struct musb *musb, bool do_suspend) {} |
Daniel Mack | 071f58b | 2013-12-20 10:47:14 +0100 | [diff] [blame] | 128 | static inline void musb_port_reset(struct musb *musb, bool do_reset) {} |
Daniel Mack | 8ed1fb7 | 2013-12-18 20:23:46 +0100 | [diff] [blame] | 129 | static inline void musb_host_finish_resume(struct work_struct *work) {} |
Daniel Mack | b7b741e | 2013-04-10 21:55:46 +0200 | [diff] [blame] | 130 | #endif |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 131 | |
| 132 | struct usb_hcd; |
| 133 | |
| 134 | extern int musb_hub_status_data(struct usb_hcd *hcd, char *buf); |
| 135 | extern int musb_hub_control(struct usb_hcd *hcd, |
| 136 | u16 typeReq, u16 wValue, u16 wIndex, |
| 137 | char *buf, u16 wLength); |
| 138 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 139 | static inline struct urb *next_urb(struct musb_qh *qh) |
| 140 | { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 141 | struct list_head *queue; |
| 142 | |
| 143 | if (!qh) |
| 144 | return NULL; |
| 145 | queue = &qh->hep->urb_list; |
| 146 | if (list_empty(queue)) |
| 147 | return NULL; |
| 148 | return list_entry(queue->next, struct urb, urb_list); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | #endif /* _MUSB_HOST_H */ |