1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   EHCI Controller Driver                                              */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 #include "ux_hcd_ehci.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_hcd_ehci_controller_disable                     PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function will disable the EHCI controller. The controller will */
45 /*    release all its resources (memory, IO ...). After this, the         */
46 /*    controller will not send SOF any longer.                            */
47 /*                                                                        */
48 /*    All transactions should have been completed, all classes should     */
49 /*    have been closed.                                                   */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    hcd_ehci                              Pointer to EHCI controller    */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    Completion Status                                                   */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _ux_hcd_ehci_register_read            Read EHCI register            */
62 /*    _ux_hcd_ehci_register_write           Write EHCI register           */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    EHCI Controller Driver                                              */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
73 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_ux_hcd_ehci_controller_disable(UX_HCD_EHCI * hcd_ehci)77 UINT  _ux_hcd_ehci_controller_disable(UX_HCD_EHCI *hcd_ehci)
78 {
79 
80 UX_HCD      *hcd;
81 ULONG       ehci_register;
82 
83 
84     /* Point to the generic portion of the host controller structure instance.  */
85     hcd =  hcd_ehci -> ux_hcd_ehci_hcd_owner;
86 
87     /* Stop the controller.  */
88     ehci_register =  _ux_hcd_ehci_register_read(hcd_ehci, EHCI_HCOR_USB_COMMAND);
89     ehci_register =  EHCI_HC_IO_HCRESET;
90     ehci_register &= ~EHCI_HC_IO_RS;
91     _ux_hcd_ehci_register_write(hcd_ehci, EHCI_HCOR_USB_COMMAND, ehci_register);
92 
93     /* Wait for the Stop signal to be acknowledged by the controller.  */
94     ehci_register =  0;
95     while ((ehci_register&EHCI_HC_STS_HC_HALTED) == 0)
96     {
97 
98         ehci_register =  _ux_hcd_ehci_register_read(hcd_ehci, EHCI_HCCR_HCS_PARAMS);
99     }
100 
101     /* Reflect the state of the controller in the main structure.  */
102     hcd -> ux_hcd_status =  UX_HCD_STATUS_HALTED;
103 
104     /* Return successful completion.  */
105     return(UX_SUCCESS);
106 }
107 
108