blob: 7cb7a5cd6dc471eaa191a0057f9c778603a3dd9d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Ilya Yanok06bb9202012-11-06 13:48:21 +00002/*
3 * MUSB OTG driver peripheral defines
4 *
5 * Copyright 2005 Mentor Graphics Corporation
6 * Copyright (C) 2005-2006 by Texas Instruments
7 * Copyright (C) 2006-2007 Nokia Corporation
Ilya Yanok06bb9202012-11-06 13:48:21 +00008 */
9
10#ifndef __MUSB_GADGET_H
11#define __MUSB_GADGET_H
12
13#include <linux/list.h>
14#ifdef __UBOOT__
15#include <asm/byteorder.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Ilya Yanok06bb9202012-11-06 13:48:21 +000017#include <linux/usb/ch9.h>
18#include <linux/usb/gadget.h>
19#endif
20
21enum buffer_map_state {
22 UN_MAPPED = 0,
23 PRE_MAPPED,
24 MUSB_MAPPED
25};
26
27struct musb_request {
28 struct usb_request request;
29 struct list_head list;
30 struct musb_ep *ep;
31 struct musb *musb;
32 u8 tx; /* endpoint direction */
33 u8 epnum;
34 enum buffer_map_state map_state;
35};
36
37static inline struct musb_request *to_musb_request(struct usb_request *req)
38{
39 return req ? container_of(req, struct musb_request, request) : NULL;
40}
41
42extern struct usb_request *
43musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags);
44extern void musb_free_request(struct usb_ep *ep, struct usb_request *req);
45
46
47/*
48 * struct musb_ep - peripheral side view of endpoint rx or tx side
49 */
50struct musb_ep {
51 /* stuff towards the head is basically write-once. */
52 struct usb_ep end_point;
53 char name[12];
54 struct musb_hw_ep *hw_ep;
55 struct musb *musb;
56 u8 current_epnum;
57
58 /* ... when enabled/disabled ... */
59 u8 type;
60 u8 is_in;
61 u16 packet_sz;
62 const struct usb_endpoint_descriptor *desc;
63 struct dma_channel *dma;
64
65 /* later things are modified based on usage */
66 struct list_head req_list;
67
68 u8 wedged;
69
70 /* true if lock must be dropped but req_list may not be advanced */
71 u8 busy;
72
73 u8 hb_mult;
74};
75
76static inline struct musb_ep *to_musb_ep(struct usb_ep *ep)
77{
78 return ep ? container_of(ep, struct musb_ep, end_point) : NULL;
79}
80
81static inline struct musb_request *next_request(struct musb_ep *ep)
82{
83 struct list_head *queue = &ep->req_list;
84
85 if (list_empty(queue))
86 return NULL;
87 return container_of(queue->next, struct musb_request, list);
88}
89
90extern void musb_g_tx(struct musb *musb, u8 epnum);
91extern void musb_g_rx(struct musb *musb, u8 epnum);
92
93extern const struct usb_ep_ops musb_g_ep0_ops;
94
95extern int musb_gadget_setup(struct musb *);
96extern void musb_gadget_cleanup(struct musb *);
97
98extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
99
100extern void musb_ep_restart(struct musb *, struct musb_request *);
101
102#ifdef __UBOOT__
103int musb_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver);
104#endif
105#endif /* __MUSB_GADGET_H */