hc
2023-11-20 2e7bd41e4e8ab3d1efdabd9e263a2f7fe79bff8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From 9b75e703df88db6b314acca4fd7d34919cdf2c0b Mon Sep 17 00:00:00 2001
From: Lin Huang <hl@rock-chips.com>
Date: Fri, 26 Apr 2019 17:33:18 +0800
Subject: [PATCH] Support usb3.0 adbd
 
Signed-off-by: Lin Huang <hl@rock-chips.com>
---
 core/adbd/functionfs.h       | 12 +++++++--
 core/adbd/usb_linux_client.c | 63 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 66 insertions(+), 9 deletions(-)
 
diff --git a/core/adbd/functionfs.h b/core/adbd/functionfs.h
index 53a3f30..42993f2 100644
--- a/core/adbd/functionfs.h
+++ b/core/adbd/functionfs.h
@@ -10,10 +10,18 @@
 
 enum {
     FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
-    FUNCTIONFS_STRINGS_MAGIC     = 2
+    FUNCTIONFS_STRINGS_MAGIC     = 2,
+    FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
 };
 
-
+enum functionfs_flags {
+    FUNCTIONFS_HAS_FS_DESC = 1,
+    FUNCTIONFS_HAS_HS_DESC = 2,
+    FUNCTIONFS_HAS_SS_DESC = 4,
+    FUNCTIONFS_HAS_MS_OS_DESC = 8,
+    FUNCTIONFS_VIRTUAL_ADDR = 16,
+    FUNCTIONFS_EVENTFD = 32,
+};
 
 /* Descriptor of an non-audio endpoint */
 struct usb_endpoint_descriptor_no_audio {
diff --git a/core/adbd/usb_linux_client.c b/core/adbd/usb_linux_client.c
index 0e4d200..a437ad1 100644
--- a/core/adbd/usb_linux_client.c
+++ b/core/adbd/usb_linux_client.c
@@ -33,6 +33,7 @@
 
 #define MAX_PACKET_SIZE_FS    64
 #define MAX_PACKET_SIZE_HS    512
+#define MAX_PACKET_SIZE_SS    1024
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 # define cpu_to_le16(x) (x)
@@ -63,19 +64,33 @@ struct usb_handle
 };
 
 static const struct {
-    struct usb_functionfs_descs_head header;
+    __le32 magic;
+    __le32 length;
+    __le32 flags;
+    __le32 fs_count;
+    __le32 hs_count;
+    __le32 ss_count;
     struct {
         struct usb_interface_descriptor intf;
         struct usb_endpoint_descriptor_no_audio source;
         struct usb_endpoint_descriptor_no_audio sink;
     } __attribute__((packed)) fs_descs, hs_descs;
+    struct {
+        struct usb_interface_descriptor intf;
+    struct usb_endpoint_descriptor_no_audio source;
+    struct usb_ss_ep_comp_descriptor source_comp;
+    struct usb_endpoint_descriptor_no_audio sink;
+    struct usb_ss_ep_comp_descriptor sink_comp;
+    } __attribute__((packed)) ss_descs;
 } __attribute__((packed)) descriptors = {
-    .header = {
-        .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC),
-        .length = cpu_to_le32(sizeof(descriptors)),
-        .fs_count = 3,
-        .hs_count = 3,
-    },
+    .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2),
+    .length = cpu_to_le32(sizeof(descriptors)),
+    .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC |
+                         FUNCTIONFS_HAS_HS_DESC |
+                         FUNCTIONFS_HAS_SS_DESC),
+    .fs_count = 3,
+    .hs_count = 3,
+    .ss_count = 5,
     .fs_descs = {
         .intf = {
             .bLength = sizeof(descriptors.fs_descs.intf),
@@ -128,6 +143,40 @@ static const struct {
             .wMaxPacketSize = MAX_PACKET_SIZE_HS,
         },
     },
+    .ss_descs = {
+        .intf = {
+            .bLength = sizeof(descriptors.ss_descs.intf),
+            .bDescriptorType = USB_DT_INTERFACE,
+            .bInterfaceNumber = 0,
+            .bNumEndpoints = 2,
+            .bInterfaceClass = ADB_CLASS,
+            .bInterfaceSubClass = ADB_SUBCLASS,
+            .bInterfaceProtocol = ADB_PROTOCOL,
+            .iInterface = 1, /* first string from the provided table */
+        },
+        .source = {
+            .bLength = sizeof(descriptors.ss_descs.source),
+            .bDescriptorType = USB_DT_ENDPOINT,
+            .bEndpointAddress = 1 | USB_DIR_OUT,
+            .bmAttributes = USB_ENDPOINT_XFER_BULK,
+            .wMaxPacketSize = MAX_PACKET_SIZE_SS,
+        },
+        .source_comp = {
+            .bLength = sizeof(descriptors.ss_descs.source_comp),
+            .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
+        },
+        .sink = {
+            .bLength = sizeof(descriptors.ss_descs.sink),
+            .bDescriptorType = USB_DT_ENDPOINT,
+            .bEndpointAddress = 2 | USB_DIR_IN,
+            .bmAttributes = USB_ENDPOINT_XFER_BULK,
+            .wMaxPacketSize = MAX_PACKET_SIZE_SS,
+        },
+        .sink_comp = {
+            .bLength = sizeof(descriptors.ss_descs.sink_comp),
+            .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
+        },
+    },
 };
 
 #define STR_INTERFACE_ "ADB Interface"
-- 
2.7.4