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_controller_disable                     PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function will disable the EHCI controller. The controller will */
46 /*    release all its resources (memory, IO ...). After this, the         */
47 /*    controller will not send SOF any longer.                            */
48 /*                                                                        */
49 /*    All transactions should have been completed, all classes should     */
50 /*    have been closed.                                                   */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    hcd_ehci                              Pointer to EHCI controller    */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _ux_hcd_ehci_register_read            Read EHCI register            */
63 /*    _ux_hcd_ehci_register_write           Write EHCI register           */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    EHCI Controller Driver                                              */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_hcd_ehci_controller_disable(UX_HCD_EHCI * hcd_ehci)78 UINT  _ux_hcd_ehci_controller_disable(UX_HCD_EHCI *hcd_ehci)
79 {
80 
81 UX_HCD      *hcd;
82 ULONG       ehci_register;
83 
84 
85     /* Point to the generic portion of the host controller structure instance.  */
86     hcd =  hcd_ehci -> ux_hcd_ehci_hcd_owner;
87 
88     /* Stop the controller.  */
89     ehci_register =  _ux_hcd_ehci_register_read(hcd_ehci, EHCI_HCOR_USB_COMMAND);
90     ehci_register =  EHCI_HC_IO_HCRESET;
91     ehci_register &= ~EHCI_HC_IO_RS;
92     _ux_hcd_ehci_register_write(hcd_ehci, EHCI_HCOR_USB_COMMAND, ehci_register);
93 
94     /* Wait for the Stop signal to be acknowledged by the controller.  */
95     ehci_register =  0;
96     while ((ehci_register&EHCI_HC_STS_HC_HALTED) == 0)
97     {
98 
99         ehci_register =  _ux_hcd_ehci_register_read(hcd_ehci, EHCI_HCCR_HCS_PARAMS);
100     }
101 
102     /* Reflect the state of the controller in the main structure.  */
103     hcd -> ux_hcd_status =  UX_HCD_STATUS_HALTED;
104 
105     /* Return successful completion.  */
106     return(UX_SUCCESS);
107 }
108 
109