Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/usb/usbd.h
1476 views
1
/*
2
* Enhanced & eXtensible USB Device (EDCI & XDCI) driver for Tegra X1
3
*
4
* Copyright (c) 2019-2021 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef _USB_H_
20
#define _USB_H_
21
22
#include <utils/types.h>
23
24
#define USB_TD_BUFFER_PAGE_SIZE 0x1000
25
#define USB_TD_BUFFER_MAX_SIZE (USB_TD_BUFFER_PAGE_SIZE * 4)
26
//#define USB_HW_BUFFER_5_PAGES 0x5000
27
#define USB_EP_BUFFER_1_TD (USB_TD_BUFFER_MAX_SIZE)
28
#define USB_EP_BUFFER_2_TD (USB_TD_BUFFER_MAX_SIZE * 2)
29
#define USB_EP_BUFFER_4_TD (USB_TD_BUFFER_MAX_SIZE * 4)
30
#define USB_EP_BUFFER_MAX_SIZE (USB_EP_BUFFER_4_TD)
31
#define USB_EP_BUFFER_ALIGN (USB_TD_BUFFER_PAGE_SIZE)
32
33
#define USB_XFER_START 0
34
#define USB_XFER_SYNCED_ENUM 1000000
35
#define USB_XFER_SYNCED_CMD 1000000
36
#define USB_XFER_SYNCED_DATA 2000000
37
#define USB_XFER_SYNCED_CLASS 5000000
38
#define USB_XFER_SYNCED -1
39
40
typedef enum _usb_hid_type
41
{
42
USB_HID_GAMEPAD,
43
USB_HID_TOUCHPAD
44
} usb_hid_type;
45
46
typedef enum _usb_gadget_type
47
{
48
USB_GADGET_UMS = 0,
49
USB_GADGET_HID_GAMEPAD = 1,
50
USB_GADGET_HID_TOUCHPAD = 2,
51
} usb_gadget_type;
52
53
typedef enum {
54
USB_DIR_OUT = 0,
55
USB_DIR_IN = 1,
56
} usb_dir_t;
57
58
typedef enum
59
{
60
XUSB_EP_CTRL_IN = 0, // EP0.
61
XUSB_EP_CTRL_OUT = 1, // EP0.
62
63
USB_EP_CTRL_OUT = 0, // EP0.
64
USB_EP_CTRL_IN = 1, // EP0.
65
66
USB_EP_BULK_OUT = 2, // EP1.
67
USB_EP_BULK_IN = 3, // EP1.
68
USB_EP_ALL = 0xFFFFFFFF
69
} usb_ep_t;
70
71
typedef enum
72
{
73
USB_EP_ADDR_CTRL_OUT = 0x00,
74
USB_EP_ADDR_CTRL_IN = 0x80,
75
USB_EP_ADDR_BULK_OUT = 0x01,
76
USB_EP_ADDR_BULK_IN = 0x81,
77
} usb_ep_addr_t;
78
79
typedef enum
80
{
81
USB_EP_CFG_CLEAR = 0,
82
USB_EP_CFG_RESET = 0,
83
USB_EP_CFG_STALL = 1
84
} usb_ep_cfg_t;
85
86
typedef enum {
87
USB_STATUS_EP_OK = 0,
88
USB_STATUS_EP_HALTED = 1,
89
90
USB_STATUS_DEV_SELF_POWERED = 1,
91
USB_STATUS_DEV_REMOTE_WAKE = 2,
92
} usb_set_clear_feature_req_t;
93
94
typedef enum {
95
USB_SETUP_RECIPIENT_DEVICE = 0,
96
USB_SETUP_RECIPIENT_INTERFACE = 1,
97
USB_SETUP_RECIPIENT_ENDPOINT = 2,
98
USB_SETUP_RECIPIENT_OTHER = 3,
99
100
USB_SETUP_TYPE_STANDARD = 0x00,
101
USB_SETUP_TYPE_CLASS = 0x20,
102
USB_SETUP_TYPE_VENDOR = 0x40,
103
USB_SETUP_TYPE_RESERVED = 0x60,
104
105
USB_SETUP_HOST_TO_DEVICE = 0x00,
106
USB_SETUP_DEVICE_TO_HOST = 0x80,
107
} usb_setup_req_type_t;
108
109
typedef enum {
110
USB_REQUEST_GET_STATUS = 0,
111
USB_REQUEST_CLEAR_FEATURE = 1,
112
USB_REQUEST_SET_FEATURE = 3,
113
USB_REQUEST_SET_ADDRESS = 5,
114
USB_REQUEST_GET_DESCRIPTOR = 6,
115
USB_REQUEST_SET_DESCRIPTOR = 7,
116
USB_REQUEST_GET_CONFIGURATION = 8,
117
USB_REQUEST_SET_CONFIGURATION = 9,
118
USB_REQUEST_GET_INTERFACE = 10,
119
USB_REQUEST_SET_INTERFACE = 11,
120
USB_REQUEST_SYNCH_FRAME = 12,
121
USB_REQUEST_SET_SEL = 13,
122
123
USB_REQUEST_GET_MS_DESCRIPTOR = 0x99,
124
125
USB_REQUEST_BULK_GET_MAX_LUN = 0xFE,
126
USB_REQUEST_BULK_RESET = 0xFF
127
} usb_standard_req_t;
128
129
typedef enum {
130
USB_FEATURE_ENDPOINT_HALT = 0,
131
USB_FEATURE_DEVICE_REMOTE_WAKEUP = 1,
132
USB_FEATURE_TEST_MODE = 2,
133
} usb_get_status_req_t;
134
135
typedef enum _usb_error_t
136
{
137
USB_RES_OK = 0,
138
USB_RES_BULK_RESET = 1,
139
140
USB_ERROR_USER_ABORT = 2,
141
USB_ERROR_TIMEOUT = 3,
142
USB_ERROR_INIT = 4,
143
USB_ERROR_XFER_ERROR = 5,
144
145
USB2_ERROR_XFER_EP_DISABLED = 28,
146
USB2_ERROR_XFER_NOT_ALIGNED = 29,
147
148
XUSB_ERROR_INVALID_EP = USB_ERROR_XFER_ERROR, // From 2.
149
XUSB_ERROR_XFER_BULK_IN_RESIDUE = 7,
150
XUSB_ERROR_INVALID_CYCLE = USB2_ERROR_XFER_EP_DISABLED, // From 8.
151
XUSB_ERROR_BABBLE_DETECTED = 50,
152
XUSB_ERROR_SEQ_NUM = 51,
153
XUSB_ERROR_XFER_DIR = 52,
154
XUSB_ERROR_PORT_CFG = 54
155
} usb_error_t;
156
157
typedef struct _usb_ctrl_setup_t
158
{
159
u8 bmRequestType;
160
u8 bRequest;
161
u16 wValue;
162
u16 wIndex;
163
u16 wLength;
164
} usb_ctrl_setup_t;
165
166
typedef struct _usb_ops_t
167
{
168
int (*usbd_flush_endpoint)(u32);
169
int (*usbd_set_ep_stall)(u32, int);
170
int (*usbd_handle_ep0_ctrl_setup)();
171
void (*usbd_end)(bool, bool);
172
int (*usb_device_init)();
173
int (*usb_device_enumerate)(usb_gadget_type gadget);
174
int (*usb_device_class_send_max_lun)(u8);
175
int (*usb_device_class_send_hid_report)();
176
177
int (*usb_device_ep1_out_read)(u8 *, u32, u32 *, u32);
178
int (*usb_device_ep1_out_read_big)(u8 *, u32, u32 *);
179
int (*usb_device_ep1_out_reading_finish)(u32 *, u32);
180
int (*usb_device_ep1_in_write)(u8 *, u32, u32 *, u32);
181
int (*usb_device_ep1_in_writing_finish)(u32 *, u32);
182
bool (*usb_device_get_suspended)();
183
bool (*usb_device_get_port_in_sleep)();
184
} usb_ops_t;
185
186
typedef struct _usb_ctxt_t
187
{
188
u32 type;
189
u32 partition;
190
u32 offset;
191
u32 sectors;
192
u32 ro;
193
void (*system_maintenance)(bool);
194
void *label;
195
void (*set_text)(void *, const char *);
196
} usb_ctxt_t;
197
198
void usb_device_get_ops(usb_ops_t *ops);
199
void xusb_device_get_ops(usb_ops_t *ops);
200
201
int usb_device_gadget_ums(usb_ctxt_t *usbs);
202
int usb_device_gadget_hid(usb_ctxt_t *usbs);
203
204
#endif
205