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 /**   OHCI 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_ohci.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_hcd_ohci_port_status_get                        PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*     This function will return the status for each port attached to the */
46 /*     root HUB.                                                          */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    hcd_ohci                              Pointer to OHCI controller    */
51 /*    port_index                            Port index                    */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    port_status                                                         */
56 /*                                                                        */
57 /*      Status of the root HUB port with the following format:            */
58 /*                                                                        */
59 /*               bit 0         device connection status                   */
60 /*                             if 0 : no device connected                 */
61 /*                             if 1 : device connected to the port        */
62 /*               bit 1         port enable status                         */
63 /*                             if 0 : port disabled                       */
64 /*                             if 1 : port enabled                        */
65 /*               bit 2         port suspend status                        */
66 /*                             if 0 : port is not suspended               */
67 /*                             if 1 : port is suspended                   */
68 /*               bit 3         port overcurrent status                    */
69 /*                             if 0 : port has no overcurrent condition   */
70 /*                             if 1 : port has overcurrent condition      */
71 /*               bit 4         port reset status                          */
72 /*                             if 0 : port is not in reset                */
73 /*                             if 1 : port is in reset                    */
74 /*               bit 5         port power status                          */
75 /*                             if 0 : port power is off                   */
76 /*                             if 1 : port power is on                    */
77 /*               bit 6-7       device attached speed                      */
78 /*                             if 00 : low speed device attached          */
79 /*                             if 01 : full speed device attached         */
80 /*                             if 10 : high speed device attached         */
81 /*                                                                        */
82 /*  CALLS                                                                 */
83 /*                                                                        */
84 /*    _ux_hcd_ohci_register_read            Read OHCI register            */
85 /*                                                                        */
86 /*  CALLED BY                                                             */
87 /*                                                                        */
88 /*    OHCI Controller Driver                                              */
89 /*                                                                        */
90 /*  RELEASE HISTORY                                                       */
91 /*                                                                        */
92 /*    DATE              NAME                      DESCRIPTION             */
93 /*                                                                        */
94 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
95 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
96 /*                                            resulting in version 6.1    */
97 /*                                                                        */
98 /**************************************************************************/
_ux_hcd_ohci_port_status_get(UX_HCD_OHCI * hcd_ohci,ULONG port_index)99 ULONG  _ux_hcd_ohci_port_status_get(UX_HCD_OHCI *hcd_ohci, ULONG port_index)
100 {
101 
102 ULONG       ohci_register_port_status;
103 ULONG       port_status;
104 
105 
106     /* Check to see if this port is valid on this controller */
107     if (hcd_ohci -> ux_hcd_ohci_nb_root_hubs < port_index)
108     {
109 
110         /* Error trap. */
111         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HCD, UX_PORT_INDEX_UNKNOWN);
112 
113         /* If trace is enabled, insert this event into the trace buffer.  */
114         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_PORT_INDEX_UNKNOWN, port_index, 0, 0, UX_TRACE_ERRORS, 0, 0)
115 
116         return(UX_PORT_INDEX_UNKNOWN);
117     }
118 
119     /* The port is valid, build the status mask for this port. This function
120        returns a controller agnostic bit field.  */
121     port_status =  0;
122     ohci_register_port_status =  _ux_hcd_ohci_register_read(hcd_ohci, OHCI_HC_RH_PORT_STATUS + port_index);
123 
124     /* Device Connection Status.  */
125     if (ohci_register_port_status & OHCI_HC_PS_CCS)
126         port_status |=  UX_PS_CCS;
127 
128     /* Port Enable Status */
129     if (ohci_register_port_status & OHCI_HC_PS_PES)
130         port_status |=  UX_PS_PES;
131 
132     /* Port Suspend Status */
133     if (ohci_register_port_status & OHCI_HC_PS_PSS)
134         port_status |=  UX_PS_PSS;
135 
136     /* Port Overcurrent Status */
137     if (ohci_register_port_status & OHCI_HC_PS_POCI)
138         port_status |=  UX_PS_POCI;
139 
140     /* Port Reset Status */
141     if (ohci_register_port_status & OHCI_HC_PS_PRS)
142         port_status |=  UX_PS_PRS;
143 
144     /* Port Power Status */
145     if (ohci_register_port_status & OHCI_HC_PS_PPS)
146         port_status |=  UX_PS_PPS;
147 
148     /* Port Device Attached speed. This field is valid only if the CCS bit is active.
149        On OHCI, only low speed or full speed are available.  */
150     if (ohci_register_port_status & OHCI_HC_PS_CCS)
151     {
152 
153         if (ohci_register_port_status & OHCI_HC_PS_LSDA)
154             port_status |=  UX_PS_DS_LS;
155         else
156             port_status |=  UX_PS_DS_FS;
157     }
158 
159     /* Return port status.  */
160     return(port_status);
161 }
162 
163