blob: 1ce6e4ec9021bcb802c519af31bb19555159667d [file] [log] [blame]
Felipe Balbi550a7372008-07-24 12:27:36 +03001/*
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 Sadashivpetimath8e8a5512012-08-07 14:46:20 +053038#include <linux/scatterlist.h>
39
Daniel Mack74c2e932013-04-10 21:55:45 +020040#define musb_to_hcd(MUSB) ((MUSB)->hcd)
Felipe Balbi550a7372008-07-24 12:27:36 +030041
Felipe Balbi550a7372008-07-24 12:27:36 +030042/* stored in "usb_host_endpoint.hcpriv" for scheduled endpoints */
43struct musb_qh {
44 struct usb_host_endpoint *hep; /* usbcore info */
45 struct usb_device *dev;
46 struct musb_hw_ep *hw_ep; /* current binding */
47
48 struct list_head ring; /* of musb_qh */
49 /* struct musb_qh *next; */ /* for periodic tree */
Ajay Kumar Gupta23d15e02008-10-29 15:10:35 +020050 u8 mux; /* qh multiplexed to hw_ep */
Felipe Balbi550a7372008-07-24 12:27:36 +030051
52 unsigned offset; /* in urb->transfer_buffer */
53 unsigned segsize; /* current xfer fragment */
54
55 u8 type_reg; /* {rx,tx} type register */
56 u8 intv_reg; /* {rx,tx} interval register */
57 u8 addr_reg; /* device address register */
58 u8 h_addr_reg; /* hub address register */
59 u8 h_port_reg; /* hub port register */
60
61 u8 is_ready; /* safe to modify hw_ep */
62 u8 type; /* XFERTYPE_* */
63 u8 epnum;
Ajay Kumar Guptaa483d702009-04-03 16:16:17 -070064 u8 hb_mult; /* high bandwidth pkts per uf */
Felipe Balbi550a7372008-07-24 12:27:36 +030065 u16 maxpacket;
66 u16 frame; /* for periodic schedule */
67 unsigned iso_idx; /* in urb->iso_frame_desc[] */
Virupax Sadashivpetimath8e8a5512012-08-07 14:46:20 +053068 struct sg_mapping_iter sg_miter; /* for highmem in PIO mode */
Felipe Balbi550a7372008-07-24 12:27:36 +030069};
70
71/* map from control or bulk queue head to the first qh on that ring */
72static inline struct musb_qh *first_qh(struct list_head *q)
73{
74 if (list_empty(q))
75 return NULL;
76 return list_entry(q->next, struct musb_qh, ring);
77}
78
Daniel Mackb7b741e2013-04-10 21:55:46 +020079
80#if IS_ENABLED(CONFIG_USB_MUSB_HOST) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
81extern struct musb *hcd_to_musb(struct usb_hcd *);
Daniel Mackc2a27592013-04-10 21:55:41 +020082extern irqreturn_t musb_h_ep0_irq(struct musb *);
Daniel Mack74c2e932013-04-10 21:55:45 +020083extern int musb_host_alloc(struct musb *);
Daniel Mackc2a27592013-04-10 21:55:41 +020084extern void musb_host_tx(struct musb *, u8);
85extern void musb_host_rx(struct musb *, u8);
Felipe Balbi550a7372008-07-24 12:27:36 +030086extern void musb_root_disconnect(struct musb *musb);
Daniel Mack74c2e932013-04-10 21:55:45 +020087extern void musb_host_free(struct musb *);
88extern void musb_host_cleanup(struct musb *);
89extern void musb_host_tx(struct musb *, u8);
90extern void musb_host_rx(struct musb *, u8);
91extern void musb_root_disconnect(struct musb *musb);
Daniel Mack0b3eba42013-04-10 21:55:42 +020092extern void musb_host_resume_root_hub(struct musb *musb);
93extern void musb_host_poke_root_hub(struct musb *musb);
Daniel Mackb7b741e2013-04-10 21:55:46 +020094#else
95static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
96{
97 return NULL;
98}
99
100static inline irqreturn_t musb_h_ep0_irq(struct musb *musb)
101{
102 return 0;
103}
104
105static inline int musb_host_alloc(struct musb *musb)
106{
107 return 0;
108}
109
110static inline void musb_host_free(struct musb *musb) {}
111static inline void musb_host_tx(struct musb *musb, u8 epnum) {}
112static inline void musb_host_rx(struct musb *musb, u8 epnum) {}
113static inline void musb_root_disconnect(struct musb *musb) {}
114static inline void musb_host_resume_root_hub(struct musb *musb) {}
115static inline void musb_host_poll_rh_status(struct musb *musb) {}
116static inline void musb_host_poke_root_hub(struct musb *musb) {}
117#endif
Daniel Mack0b3eba42013-04-10 21:55:42 +0200118
Felipe Balbi550a7372008-07-24 12:27:36 +0300119struct usb_hcd;
120
121extern int musb_hub_status_data(struct usb_hcd *hcd, char *buf);
122extern int musb_hub_control(struct usb_hcd *hcd,
123 u16 typeReq, u16 wValue, u16 wIndex,
124 char *buf, u16 wLength);
125
Felipe Balbi550a7372008-07-24 12:27:36 +0300126static inline struct urb *next_urb(struct musb_qh *qh)
127{
Felipe Balbi550a7372008-07-24 12:27:36 +0300128 struct list_head *queue;
129
130 if (!qh)
131 return NULL;
132 queue = &qh->hep->urb_list;
133 if (list_empty(queue))
134 return NULL;
135 return list_entry(queue->next, struct urb, urb_list);
Felipe Balbi550a7372008-07-24 12:27:36 +0300136}
137
138#endif /* _MUSB_HOST_H */