1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016,2019 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _USB_HOST_HUB_APP_H_
10 #define _USB_HOST_HUB_APP_H_
11 
12 #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
13 
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 
18 /*! @brief HUB reset times*/
19 #define USB_HOST_HUB_PORT_RESET_TIMES (1)
20 
21 #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
22 /*! @brief HUB Control tansaction retry times for remote wakeup*/
23 #define USB_HOST_HUB_REMOTE_WAKEUP_TIMES (3U)
24 #endif
25 
26 /*! @brief HUB application global structure */
27 typedef struct _usb_host_hub_global
28 {
29     usb_host_handle hostHandle;                            /*!< This HUB list belong to this host*/
30     usb_host_hub_instance_t *hubProcess;                   /*!< HUB in processing*/
31     usb_host_hub_instance_t *hubList;                      /*!< host's HUB list*/
32     osa_mutex_handle_t hubMutex;                           /*!< HUB mutex*/
33     uint32_t mutexBuffer[(OSA_MUTEX_HANDLE_SIZE + 3) / 4]; /*!< The mutex buffer. */
34 } usb_host_hub_global_t;
35 
36 /*! @brief HUB application status */
37 typedef enum _usb_host_hub_app_status
38 {
39     kHubRunIdle = 0,         /*!< Idle */
40     kHubRunInvalid,          /*!< Invalid state */
41     kHubRunWaitSetInterface, /*!< Wait callback of set interface */
42     kHubRunGetDescriptor7,   /*!< Get 7 bytes HUB descriptor */
43     kHubRunGetDescriptor,    /*!< Get all HUB descriptor */
44     kHubRunSetPortPower,     /*!< Set HUB's port power */
45     kHubRunGetStatusDone,    /*!< HUB status changed */
46     kHubRunClearDone,        /*!< clear HUB feature callback */
47 } usb_host_hub_app_status_t;
48 
49 /*! @brief HUB port application status */
50 typedef enum _usb_host_port_app_status
51 {
52     kPortRunIdle = 0,             /*!< Idle */
53     kPortRunInvalid,              /*!< Invalid state */
54     kPortRunWaitPortChange,       /*!< Wait port status change */
55     kPortRunCheckCPortConnection, /*!< Check C_PORT_CONNECTION */
56     kPortRunGetPortConnection,    /*!< Get port status data */
57     kPortRunCheckPortConnection,  /*!< Check PORT_CONNECTION   */
58     kPortRunWaitPortResetDone,    /*!< Wait port reset transfer done */
59     kPortRunWaitCPortReset,       /*!< Wait C_PORT_RESET */
60     KPortRunCheckCPortReset,      /*!< Check C_PORT_RESET */
61     kPortRunResetAgain,           /*!< Reset port again */
62     kPortRunPortAttached,         /*!< Device is attached on the port */
63     kPortRunCheckPortDetach,      /*!< Check port is detached */
64     kPortRunGetConnectionBit,     /*!< Get the port status data */
65     kPortRunCheckConnectionBit,   /*!< Check PORT_CONNECTION */
66 #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
67     kPortRunClearCPortSuspend, /*!< Clear C_PORT_SUSPEND */
68     kPortRunCheckPortSuspend,  /*!< Check PORT_SUSPEND */
69     kPortRunPortSuspended,     /*!< Port is suspended */
70 #endif
71 } usb_host_port_app_status_t;
72 
73 /*! @brief HUB data prime status */
74 typedef enum _usb_host_hub_prime_status
75 {
76     kPrimeNone = 0U,   /*!< Don't prime data*/
77     kPrimeHubControl,  /*!< Prime HUB control transfer*/
78     kPrimePortControl, /*!< Prime port control transfer*/
79     kPrimeInterrupt,   /*!< Prime interrupt transfer*/
80 } usb_host_hub_prime_status_t;
81 
82 /*******************************************************************************
83  * API
84  ******************************************************************************/
85 #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) || \
86  (defined(USB_HOST_CONFIG_COMPLIANCE_TEST) && (USB_HOST_CONFIG_COMPLIANCE_TEST > 0U)))
87 /*!
88  * @brief get device's hub device instance.
89  *
90  * @param parent_hub_no  device's parent hub instance.
91  *
92  * @return think time value.
93  */
94 usb_host_hub_instance_t *USB_HostHubGetHubDeviceHandle(usb_host_handle hostHandle, uint8_t parentHubNo);
95 #endif
96 
97 #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U))
98 /*!
99  * @brief Suspend the device.
100  *
101  * @param hostHandle  Host instance.
102  *
103  * @return kStatus_USB_Success or error codes.
104  *
105  */
106 usb_status_t USB_HostHubSuspendDevice(usb_host_handle hostHandle);
107 /*!
108  * @brief Resume the device.
109  *
110  * @param hostHandle  Host instance.
111  *
112  * @return kStatus_USB_Success or error codes.
113  *
114  */
115 usb_status_t USB_HostHubResumeDevice(usb_host_handle hostHandle);
116 /*!
117  * @brief get device's hub total think time.
118  *
119  * @param parent_hub_no  device's parent hub's address.
120  *
121  * @return think time value.
122  */
123 #endif
124 uint32_t USB_HostHubGetTotalThinkTime(usb_host_handle hostHandle, uint8_t parentHubNo);
125 /*!
126  * @brief get device's high-speed hub's address.
127  *
128  * @param parent_hub_no device's parent hub's address.
129  *
130  * @return hub number.
131  */
132 uint32_t USB_HostHubGetHsHubNumber(usb_host_handle hostHandle, uint8_t parentHubNo);
133 /*!
134  * @brief remove attached device. called by USB_HostRemoveDevice.
135  *
136  * @param hubNumber   the device attached hub.
137  * @param portNumber  the device attached port.
138  *
139  * @return kStatus_USB_Success or error codes.
140  */
141 usb_status_t USB_HostHubRemovePort(usb_host_handle hostHandle, uint8_t hubNumber, uint8_t portNumber);
142 /*!
143  * @brief host hub callback function.
144  *
145  * This function should be called in the host callback function.
146  *
147  * @param hostHandle             host handle.
148  * @param deviceHandle           device handle.
149  * @param configurationHandle attached device's configuration descriptor information.
150  * @param event_code           callback event code, please reference to enumeration host_event_t.
151  *
152  * @retval kStatus_USB_Success              The host is initialized successfully.
153  * @retval kStatus_USB_NotSupported         The configuration don't contain hub interface.
154  */
155 usb_status_t USB_HostHubDeviceEvent(usb_host_handle hostHandle,
156                                     usb_device_handle deviceHandle,
157                                     usb_host_configuration_handle configurationHandle,
158                                     uint32_t eventCode);
159 /*!
160  * @brief get device's high-speed hub's port number.
161  *
162  * @param parent_hub_no  device's parent hub's address.
163  * @param parent_port_no device's parent port no.
164  *
165  * @return port number.
166  */
167 uint32_t USB_HostHubGetHsHubPort(usb_host_handle hostHandle, uint8_t parentHubNo, uint8_t parentPortNo);
168 #endif /* USB_HOST_CONFIG_HUB */
169 
170 #endif /* _USB_HOST_HUB_APP_H_ */
171