1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016 NXP 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * o Redistributions of source code must retain the above copyright notice, this list 9 * of conditions and the following disclaimer. 10 * 11 * o Redistributions in binary form must reproduce the above copyright notice, this 12 * list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * o Neither the name of the copyright holder nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef __USB_DEVICE_EHCI_H__ 32 #define __USB_DEVICE_EHCI_H__ 33 34 #include <usb/include/usb_ehci.h> 35 36 /*! 37 * @addtogroup usb_device_controller_ehci_driver 38 * @{ 39 */ 40 41 /******************************************************************************* 42 * Definitions 43 ******************************************************************************/ 44 45 /*! @brief The maximum value of ISO type maximum packet size for HS in USB specification 2.0 */ 46 #define USB_DEVICE_MAX_HS_ISO_MAX_PACKET_SIZE (1024U) 47 48 /*! @brief The maximum value of interrupt type maximum packet size for HS in USB specification 2.0 */ 49 #define USB_DEVICE_MAX_HS_INTERUPT_MAX_PACKET_SIZE (1024U) 50 51 /*! @brief The maximum value of bulk type maximum packet size for HS in USB specification 2.0 */ 52 #define USB_DEVICE_MAX_HS_BULK_MAX_PACKET_SIZE (512U) 53 54 /*! @brief The maximum value of control type maximum packet size for HS in USB specification 2.0 */ 55 #define USB_DEVICE_MAX_HS_CONTROL_MAX_PACKET_SIZE (64U) 56 57 /*! @brief EHCI state structure */ 58 typedef struct _usb_device_ehci_state_struct 59 { 60 usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object is belonged to */ 61 USBHS_Type *registerBase; /*!< The base address of the register */ 62 #if (defined(USB_DEVICE_CONFIG_LOW_POWER_MODE) && (USB_DEVICE_CONFIG_LOW_POWER_MODE > 0U)) 63 USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */ 64 #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U)) 65 USBNC_Type *registerNcBase; /*!< The base address of the USBNC register */ 66 #endif 67 #endif 68 usb_device_ehci_qh_struct_t *qh; /*!< The QH structure base address */ 69 usb_device_ehci_dtd_struct_t *dtd; /*!< The DTD structure base address */ 70 usb_device_ehci_dtd_struct_t *dtdFree; /*!< The idle DTD list head */ 71 usb_device_ehci_dtd_struct_t 72 *dtdHard[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list head for each endpoint */ 73 usb_device_ehci_dtd_struct_t 74 *dtdTail[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list tail for each endpoint */ 75 int8_t dtdCount; /*!< The idle DTD node count */ 76 uint8_t endpointCount; /*!< The endpoint number of EHCI */ 77 uint8_t isResetting; /*!< Whether a PORT reset is occurring or not */ 78 uint8_t controllerId; /*!< Controller ID */ 79 uint8_t speed; /*!< Current speed of EHCI */ 80 uint8_t isSuspending; /*!< Is suspending of the PORT */ 81 } usb_device_ehci_state_struct_t; 82 83 #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) && \ 84 (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 85 typedef struct _usb_device_dcd_state_struct 86 { 87 usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object belongs to */ 88 USBHSDCD_Type *dcdRegisterBase; /*!< The base address of the dcd module */ 89 uint8_t controllerId; /*!< Controller ID */ 90 } usb_device_dcd_state_struct_t; 91 #endif 92 93 #if defined(__cplusplus) 94 extern "C" { 95 #endif 96 97 /*! 98 * @name USB device EHCI functions 99 * @{ 100 */ 101 102 /******************************************************************************* 103 * API 104 ******************************************************************************/ 105 106 /*! 107 * @brief Initializes the USB device EHCI instance. 108 * 109 * This function initializes the USB device EHCI module specified by the controllerId. 110 * 111 * @param[in] controllerId The controller ID of the USB IP. See the enumeration type usb_controller_index_t. 112 * @param[in] handle Pointer of the device handle used to identify the device object is belonged to. 113 * @param[out] ehciHandle An out parameter used to return the pointer of the device EHCI handle to the caller. 114 * 115 * @return A USB error code or kStatus_USB_Success. 116 */ 117 usb_status_t USB_DeviceEhciInit(uint8_t controllerId, 118 usb_device_handle handle, 119 usb_device_controller_handle *ehciHandle); 120 121 /*! 122 * @brief Deinitializes the USB device EHCI instance. 123 * 124 * This function deinitializes the USB device EHCI module. 125 * 126 * @param[in] ehciHandle Pointer of the device EHCI handle. 127 * 128 * @return A USB error code or kStatus_USB_Success. 129 */ 130 usb_status_t USB_DeviceEhciDeinit(usb_device_controller_handle ehciHandle); 131 132 /*! 133 * @brief Sends data through a specified endpoint. 134 * 135 * This function sends data through a specified endpoint. 136 * 137 * @param[in] ehciHandle Pointer of the device EHCI handle. 138 * @param[in] endpointAddress Endpoint index. 139 * @param[in] buffer The memory address to hold the data need to be sent. 140 * @param[in] length The data length to be sent. 141 * 142 * @return A USB error code or kStatus_USB_Success. 143 * 144 * @note The return value means whether the sending request is successful or not. The transfer completion is indicated 145 * by the 146 * corresponding callback function. 147 * Currently, only one transfer request can be supported for a specific endpoint. 148 * If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application 149 * should implement a queue in the application level. 150 * The subsequent transfer can begin only when the previous transfer is done (a notification is received through the 151 * endpoint 152 * callback). 153 */ 154 usb_status_t USB_DeviceEhciSend(usb_device_controller_handle ehciHandle, 155 uint8_t endpointAddress, 156 uint8_t *buffer, 157 uint32_t length); 158 159 /*! 160 * @brief Receive data through a specified endpoint. 161 * 162 * This function Receives data through a specified endpoint. 163 * 164 * @param[in] ehciHandle Pointer of the device EHCI handle. 165 * @param[in] endpointAddress Endpoint index. 166 * @param[in] buffer The memory address to save the received data. 167 * @param[in] length The data length want to be received. 168 * 169 * @return A USB error code or kStatus_USB_Success. 170 * 171 * @note The return value just means if the receiving request is successful or not; the transfer done is notified by the 172 * corresponding callback function. 173 * Currently, only one transfer request can be supported for one specific endpoint. 174 * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 175 * should implement a queue in the application level. 176 * The subsequent transfer could begin only when the previous transfer is done (get notification through the endpoint 177 * callback). 178 */ 179 usb_status_t USB_DeviceEhciRecv(usb_device_controller_handle ehciHandle, 180 uint8_t endpointAddress, 181 uint8_t *buffer, 182 uint32_t length); 183 184 /*! 185 * @brief Cancels the pending transfer in a specified endpoint. 186 * 187 * The function is used to cancel the pending transfer in a specified endpoint. 188 * 189 * @param[in] ehciHandle Pointer of the device EHCI handle. 190 * @param[in] ep Endpoint address, bit7 is the direction of endpoint, 1U - IN, 0U - OUT. 191 * 192 * @return A USB error code or kStatus_USB_Success. 193 */ 194 usb_status_t USB_DeviceEhciCancel(usb_device_controller_handle ehciHandle, uint8_t ep); 195 196 /*! 197 * @brief Controls the status of the selected item. 198 * 199 * The function is used to control the status of the selected item. 200 * 201 * @param[in] ehciHandle Pointer of the device EHCI handle. 202 * @param[in] type The selected item. See enumeration type usb_device_control_type_t. 203 * @param[in,out] param The parameter type is determined by the selected item. 204 * 205 * @return A USB error code or kStatus_USB_Success. 206 */ 207 usb_status_t USB_DeviceEhciControl(usb_device_controller_handle ehciHandle, 208 usb_device_control_type_t type, 209 void *param); 210 211 /*! @} */ 212 213 #if defined(__cplusplus) 214 } 215 #endif 216 217 /*! @} */ 218 219 #endif /* __USB_DEVICE_EHCI_H__ */ 220