blob: 56a2b1004b7f0c9a390e991c824a5a9c64bc825e [file] [log] [blame]
Channagoud Kadabi5f8f1c42015-03-25 14:35:05 -07001/* Copyright (c) 2013, 2015 The Linux Foundation. All rights reserved.
Amol Jadif3d5a892013-07-23 16:09:44 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28#ifndef _USB30_UDC_H
29#define _USB30_UDC_H
30
31#include <bits.h>
32#include <usb30_dwc.h>
33#include <usb30_wrapper.h>
34
35#define UDC_DESC_SIZE_CONFIGURATION 9
36#define UDC_DESC_SIZE_INTERFACE 9
37#define UDC_DESC_SIZE_ENDPOINT 7
38#define UDC_DESC_SIZE_ENDPOINT_COMP 6
39
40typedef enum
41{
Channagoud Kadabi363e7402015-06-16 11:44:20 -070042 UDC_DEFAULT_STATE,
43 UDC_ADDRESSED_STATE,
44 UDC_CONFIGURED_STATE,
45} usb_state_t;
46
47typedef enum
48{
49 ENDPOINT_HALT = 0,
50 FUNCTION_SUSPEND = 0,
51 U1_ENABLE = 48,
52 U2_ENABLE = 49,
53 LTM_ENABLE = 50,
54} udc_feature_select_t;
55
56typedef enum
57{
Amol Jadif3d5a892013-07-23 16:09:44 -070058 UDC_DESC_SPEC_20 = BIT(0),
59 UDC_DESC_SPEC_30 = BIT(1),
60} udc_desc_spec_t;
61
62typedef enum
63{
64 UDC_SPEED_LS,
65 UDC_SPEED_FS,
66 UDC_SPEED_HS,
67 UDC_SPEED_SS
68} udc_device_speed_t;
69
70typedef struct
71{
72 usb_wrapper_dev_t *wrapper_dev; /* store the wrapper device ptr */
73 dwc_dev_t *dwc; /* store the dwc device ptr */
74
75 struct udc_gadget *gadget; /* store the registered gadget. */
76 struct udc_descriptor *desc_list; /* linked list of all descriptors: device, config, string, language table, bos etc. */
77 struct udc_endpoint *ept_list; /* linked list of all eps */
78 uint32_t ept_alloc_table; /* keep track of which usb EPs are allocated. Initialized to assume EP0 In/OUT are already allocated.*/
79 uint32_t next_string_id; /* keeps track of string id for string descriptor */
80 void *ctrl_rx_buf; /* buffer pointer to receive ctrl data. */
81 void *ctrl_tx_buf; /* buffer pointer to send ctrl data. */
82
83
84 udc_device_speed_t speed; /* keeps track of usb connection speed. */
85 uint8_t config_selected; /* keeps track of the selected configuration */
86
87 struct udc_request *queued_req; /* pointer to the currently queued request. NULL indicates no request is queued. */
Channagoud Kadabi363e7402015-06-16 11:44:20 -070088 usb_state_t usb_state; /* USB state, default, addressed & configured */
Amol Jadif3d5a892013-07-23 16:09:44 -070089
90} udc_t;
91
92
93struct udc_descriptor {
94 struct udc_descriptor *next;
95 uint16_t tag; /* ((TYPE << 8) | NUM) */
96 uint16_t len; /* total length */
97 udc_desc_spec_t spec; /* bit map of spec that this desc complies with. */
98 uint8_t data[0]; /* descriptor contents. */
99};
100
101struct udc_endpoint {
102 struct udc_endpoint *next;
103 uint8_t num;
Channagoud Kadabi5f8f1c42015-03-25 14:35:05 -0700104 uint8_t type;
Amol Jadif3d5a892013-07-23 16:09:44 -0700105 uint8_t in;
106 uint16_t maxpkt;
107 uint32_t maxburst; /* max pkts that this ep can transfer before waiting for ack. */
108
109 dwc_trb_t *trb; /* pointer to buffer used for TRB chain */
110 uint32_t trb_count; /* size of TRB chain. */
111};
112
Channagoud Kadabi363e7402015-06-16 11:44:20 -0700113struct usb_qualifier_desc {
114 uint8_t bLength;
115 uint8_t bDescriptorType;
116 uint16_t bcdUSB;
117 uint8_t bDeviceClass;
118 uint8_t bDeviceSubClass;
119 uint8_t bDeviceProtocol;
120 uint8_t bMaxPacketSize0;
121 uint8_t bNumConfigurations;
122 uint8_t bReserved;
123}__PACKED;
124
Amol Jadi151f2a52013-10-07 12:39:11 -0700125struct udc_request *usb30_udc_request_alloc(void);
126struct udc_endpoint *usb30_udc_endpoint_alloc(unsigned type, unsigned maxpkt);
127void usb30_udc_request_free(struct udc_request *req);
128int usb30_udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
129int usb30_udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
130
131int usb30_udc_init(struct udc_device *devinfo);
132int usb30_udc_register_gadget(struct udc_gadget *gadget);
133int usb30_udc_start(void);
134int usb30_udc_stop(void);
Amol Jadif3d5a892013-07-23 16:09:44 -0700135#endif