blob: 63298bd233e02832b3ce7f32e0234eeeebeb81a0 [file] [log] [blame]
Nishad Kamdar6814c732020-04-04 16:19:55 +05301/* SPDX-License-Identifier: GPL-2.0 */
Felipe Balbi550a7372008-07-24 12:27:36 +03002/*
3 * MUSB OTG driver host defines
4 *
5 * Copyright 2005 Mentor Graphics Corporation
6 * Copyright (C) 2005-2006 by Texas Instruments
7 * Copyright (C) 2006-2007 Nokia Corporation
Felipe Balbi550a7372008-07-24 12:27:36 +03008 */
9
10#ifndef _MUSB_HOST_H
11#define _MUSB_HOST_H
12
Virupax Sadashivpetimath8e8a5512012-08-07 14:46:20 +053013#include <linux/scatterlist.h>
14
Felipe Balbi550a7372008-07-24 12:27:36 +030015/* stored in "usb_host_endpoint.hcpriv" for scheduled endpoints */
16struct musb_qh {
17 struct usb_host_endpoint *hep; /* usbcore info */
18 struct usb_device *dev;
19 struct musb_hw_ep *hw_ep; /* current binding */
20
21 struct list_head ring; /* of musb_qh */
22 /* struct musb_qh *next; */ /* for periodic tree */
Ajay Kumar Gupta23d15e02008-10-29 15:10:35 +020023 u8 mux; /* qh multiplexed to hw_ep */
Felipe Balbi550a7372008-07-24 12:27:36 +030024
25 unsigned offset; /* in urb->transfer_buffer */
26 unsigned segsize; /* current xfer fragment */
27
28 u8 type_reg; /* {rx,tx} type register */
29 u8 intv_reg; /* {rx,tx} interval register */
30 u8 addr_reg; /* device address register */
31 u8 h_addr_reg; /* hub address register */
32 u8 h_port_reg; /* hub port register */
33
34 u8 is_ready; /* safe to modify hw_ep */
35 u8 type; /* XFERTYPE_* */
36 u8 epnum;
Ajay Kumar Guptaa483d702009-04-03 16:16:17 -070037 u8 hb_mult; /* high bandwidth pkts per uf */
Felipe Balbi550a7372008-07-24 12:27:36 +030038 u16 maxpacket;
39 u16 frame; /* for periodic schedule */
40 unsigned iso_idx; /* in urb->iso_frame_desc[] */
Virupax Sadashivpetimath8e8a5512012-08-07 14:46:20 +053041 struct sg_mapping_iter sg_miter; /* for highmem in PIO mode */
Virupax Sadashivpetimathed74df12013-04-24 08:38:48 +020042 bool use_sg; /* to track urb using sglist */
Felipe Balbi550a7372008-07-24 12:27:36 +030043};
44
45/* map from control or bulk queue head to the first qh on that ring */
46static inline struct musb_qh *first_qh(struct list_head *q)
47{
48 if (list_empty(q))
49 return NULL;
50 return list_entry(q->next, struct musb_qh, ring);
51}
52
53
Daniel Mackb7b741e2013-04-10 21:55:46 +020054#if IS_ENABLED(CONFIG_USB_MUSB_HOST) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
55extern struct musb *hcd_to_musb(struct usb_hcd *);
Daniel Mackc2a27592013-04-10 21:55:41 +020056extern irqreturn_t musb_h_ep0_irq(struct musb *);
Daniel Mack74c2e932013-04-10 21:55:45 +020057extern int musb_host_alloc(struct musb *);
Daniel Mack2cc65fe2013-04-10 21:55:47 +020058extern int musb_host_setup(struct musb *, int);
59extern void musb_host_cleanup(struct musb *);
Daniel Mackc2a27592013-04-10 21:55:41 +020060extern void musb_host_tx(struct musb *, u8);
61extern void musb_host_rx(struct musb *, u8);
Felipe Balbi550a7372008-07-24 12:27:36 +030062extern void musb_root_disconnect(struct musb *musb);
Daniel Mack74c2e932013-04-10 21:55:45 +020063extern void musb_host_free(struct musb *);
Daniel Mack0b3eba42013-04-10 21:55:42 +020064extern void musb_host_resume_root_hub(struct musb *musb);
65extern void musb_host_poke_root_hub(struct musb *musb);
Daniel Glöcknerebc3dd62018-05-14 09:40:05 -050066extern int musb_port_suspend(struct musb *musb, bool do_suspend);
Daniel Mack869c5972013-11-26 13:31:14 +010067extern void musb_port_reset(struct musb *musb, bool do_reset);
Daniel Mack8ed1fb72013-12-18 20:23:46 +010068extern void musb_host_finish_resume(struct work_struct *work);
Daniel Mackb7b741e2013-04-10 21:55:46 +020069#else
70static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
71{
72 return NULL;
73}
74
75static inline irqreturn_t musb_h_ep0_irq(struct musb *musb)
76{
77 return 0;
78}
79
80static inline int musb_host_alloc(struct musb *musb)
81{
82 return 0;
83}
84
Daniel Mack2cc65fe2013-04-10 21:55:47 +020085static inline int musb_host_setup(struct musb *musb, int power_budget)
86{
87 return 0;
88}
89
90static inline void musb_host_cleanup(struct musb *musb) {}
Daniel Mackb7b741e2013-04-10 21:55:46 +020091static inline void musb_host_free(struct musb *musb) {}
92static inline void musb_host_tx(struct musb *musb, u8 epnum) {}
93static inline void musb_host_rx(struct musb *musb, u8 epnum) {}
94static inline void musb_root_disconnect(struct musb *musb) {}
95static inline void musb_host_resume_root_hub(struct musb *musb) {}
Daniel Mackb7b741e2013-04-10 21:55:46 +020096static inline void musb_host_poke_root_hub(struct musb *musb) {}
Daniel Glöcknerebc3dd62018-05-14 09:40:05 -050097static inline int musb_port_suspend(struct musb *musb, bool do_suspend)
98{
99 return 0;
100}
Daniel Mack071f58b2013-12-20 10:47:14 +0100101static inline void musb_port_reset(struct musb *musb, bool do_reset) {}
Daniel Mack8ed1fb72013-12-18 20:23:46 +0100102static inline void musb_host_finish_resume(struct work_struct *work) {}
Daniel Mackb7b741e2013-04-10 21:55:46 +0200103#endif
Felipe Balbi550a7372008-07-24 12:27:36 +0300104
105struct usb_hcd;
106
107extern int musb_hub_status_data(struct usb_hcd *hcd, char *buf);
108extern int musb_hub_control(struct usb_hcd *hcd,
109 u16 typeReq, u16 wValue, u16 wIndex,
110 char *buf, u16 wLength);
111
Felipe Balbi550a7372008-07-24 12:27:36 +0300112static inline struct urb *next_urb(struct musb_qh *qh)
113{
Felipe Balbi550a7372008-07-24 12:27:36 +0300114 struct list_head *queue;
115
116 if (!qh)
117 return NULL;
118 queue = &qh->hep->urb_list;
119 if (list_empty(queue))
120 return NULL;
121 return list_entry(queue->next, struct urb, urb_list);
Felipe Balbi550a7372008-07-24 12:27:36 +0300122}
123
124#endif /* _MUSB_HOST_H */