1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** EHCI Controller Driver */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_hcd_ehci.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_hcd_ehci_entry PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function dispatch the HCD function internally to the EHCI */
46 /* controller. */
47 /* */
48 /* INPUT */
49 /* */
50 /* HCD Pointer to HCD */
51 /* function Requested function */
52 /* parameter Pointer to parameter(s) */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* Completion Status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _ux_hcd_ehci_asynchronous_endpoint_create Create endpoint */
61 /* _ux_hcd_ehci_asynchronous_endpoint_destroy Destroy endpoint */
62 /* _ux_hcd_ehci_controller_disable Disable controller */
63 /* _ux_hcd_ehci_done_queue_process Process done queue */
64 /* _ux_hcd_ehci_endpoint_reset Reset endpoint */
65 /* _ux_hcd_ehci_frame_number_get Get frame number */
66 /* _ux_hcd_ehci_frame_number_set Set frame number */
67 /* _ux_hcd_ehci_interrupt_endpoint_create Endpoint create */
68 /* _ux_hcd_ehci_interrupt_endpoint_destroy Endpoint destroy */
69 /* _ux_hcd_ehci_isochronous_endpoint_create Endpoint create */
70 /* _ux_hcd_ehci_isochronous_endpoint_destroy Endpoint destroy */
71 /* _ux_hcd_ehci_port_disable Disable port */
72 /* _ux_hcd_ehci_port_reset Reset port */
73 /* _ux_hcd_ehci_port_resume Resume port */
74 /* _ux_hcd_ehci_port_status_get Get port status */
75 /* _ux_hcd_ehci_port_suspend Suspend port */
76 /* _ux_hcd_ehci_power_down_port Power down port */
77 /* _ux_hcd_ehci_power_on_port Power on port */
78 /* _ux_hcd_ehci_request_transfer Request transfer */
79 /* _ux_hcd_ehci_transfer_abort Abort transfer */
80 /* */
81 /* CALLED BY */
82 /* */
83 /* EHCI Controller Driver */
84 /* */
85 /* RELEASE HISTORY */
86 /* */
87 /* DATE NAME DESCRIPTION */
88 /* */
89 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
90 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
91 /* resulting in version 6.1 */
92 /* */
93 /**************************************************************************/
_ux_hcd_ehci_entry(UX_HCD * hcd,UINT function,VOID * parameter)94 UINT _ux_hcd_ehci_entry(UX_HCD *hcd, UINT function, VOID *parameter)
95 {
96
97 UINT status;
98 UX_HCD_EHCI *hcd_ehci;
99
100
101 /* Check the status of the controller. */
102 if (hcd -> ux_hcd_status == UX_UNUSED)
103 {
104
105 /* Error trap. */
106 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_CONTROLLER_UNKNOWN);
107
108 /* If trace is enabled, insert this event into the trace buffer. */
109 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONTROLLER_UNKNOWN, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
110
111 return(UX_CONTROLLER_UNKNOWN);
112 }
113
114 /* Get the pointer to the EHCI HCD. */
115 hcd_ehci = (UX_HCD_EHCI *) hcd -> ux_hcd_controller_hardware;
116
117 /* Look at the function and route it. */
118 switch(function)
119 {
120
121 case UX_HCD_DISABLE_CONTROLLER:
122
123 status = _ux_hcd_ehci_controller_disable(hcd_ehci);
124 break;
125
126
127 case UX_HCD_GET_PORT_STATUS:
128 status = _ux_hcd_ehci_port_status_get(hcd_ehci, (ULONG) parameter);
129 break;
130
131
132 case UX_HCD_ENABLE_PORT:
133
134 status = UX_SUCCESS;
135 break;
136
137
138 case UX_HCD_DISABLE_PORT:
139
140 status = _ux_hcd_ehci_port_disable(hcd_ehci, (ULONG) parameter);
141 break;
142
143
144 case UX_HCD_POWER_ON_PORT:
145
146 status = _ux_hcd_ehci_power_on_port(hcd_ehci, (ULONG) parameter);
147 break;
148
149
150 case UX_HCD_POWER_DOWN_PORT:
151
152 status = _ux_hcd_ehci_power_down_port(hcd_ehci, (ULONG) parameter);
153 break;
154
155
156 case UX_HCD_SUSPEND_PORT:
157 status = _ux_hcd_ehci_port_suspend(hcd_ehci, (ULONG) parameter);
158 break;
159
160
161 case UX_HCD_RESUME_PORT:
162
163 status = _ux_hcd_ehci_port_resume(hcd_ehci, (UINT) parameter);
164 break;
165
166
167 case UX_HCD_RESET_PORT:
168
169 status = _ux_hcd_ehci_port_reset(hcd_ehci, (ULONG) parameter);
170 break;
171
172
173 case UX_HCD_GET_FRAME_NUMBER:
174
175 status = _ux_hcd_ehci_frame_number_get(hcd_ehci, (ULONG *) parameter);
176 break;
177
178
179 case UX_HCD_SET_FRAME_NUMBER:
180
181 _ux_hcd_ehci_frame_number_set(hcd_ehci, (ULONG) parameter);
182 status = UX_SUCCESS;
183 break;
184
185
186 case UX_HCD_TRANSFER_REQUEST:
187
188 status = _ux_hcd_ehci_request_transfer(hcd_ehci, (UX_TRANSFER *) parameter);
189 break;
190
191
192 case UX_HCD_TRANSFER_ABORT:
193
194 status = _ux_hcd_ehci_transfer_abort(hcd_ehci, (UX_TRANSFER *) parameter);
195 break;
196
197
198 case UX_HCD_CREATE_ENDPOINT:
199
200 switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
201 {
202
203 case UX_CONTROL_ENDPOINT:
204 case UX_BULK_ENDPOINT:
205 status = _ux_hcd_ehci_asynchronous_endpoint_create(hcd_ehci, (UX_ENDPOINT*) parameter);
206 break;
207
208 case UX_INTERRUPT_ENDPOINT:
209 status = _ux_hcd_ehci_interrupt_endpoint_create(hcd_ehci, (UX_ENDPOINT*) parameter);
210 break;
211
212 case UX_ISOCHRONOUS_ENDPOINT:
213 status = _ux_hcd_ehci_isochronous_endpoint_create(hcd_ehci, (UX_ENDPOINT*) parameter);
214 break;
215
216 }
217 break;
218
219
220 case UX_HCD_DESTROY_ENDPOINT:
221
222 switch ((((UX_ENDPOINT*) parameter) -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
223 {
224
225 case UX_CONTROL_ENDPOINT:
226 case UX_BULK_ENDPOINT:
227 status = _ux_hcd_ehci_asynchronous_endpoint_destroy(hcd_ehci, (UX_ENDPOINT*) parameter);
228 break;
229
230 case UX_INTERRUPT_ENDPOINT:
231 status = _ux_hcd_ehci_interrupt_endpoint_destroy(hcd_ehci, (UX_ENDPOINT*) parameter);
232 break;
233
234 case UX_ISOCHRONOUS_ENDPOINT:
235 status = _ux_hcd_ehci_isochronous_endpoint_destroy(hcd_ehci, (UX_ENDPOINT*) parameter);
236 break;
237
238 }
239 break;
240
241
242 case UX_HCD_RESET_ENDPOINT:
243
244 status = _ux_hcd_ehci_endpoint_reset(hcd_ehci, (UX_ENDPOINT*) parameter);
245 break;
246
247
248 case UX_HCD_PROCESS_DONE_QUEUE:
249
250 _ux_hcd_ehci_done_queue_process(hcd_ehci);
251 status = UX_SUCCESS;
252 break;
253
254
255 default:
256
257 /* Error trap. */
258 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_FUNCTION_NOT_SUPPORTED);
259
260 /* If trace is enabled, insert this event into the trace buffer. */
261 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
262
263 status = UX_FUNCTION_NOT_SUPPORTED;
264 break;
265 }
266
267 /* Return status to caller. */
268 return(status);
269 }
270
271