1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __USB_OTG_KHCI_H__ 10 #define __USB_OTG_KHCI_H__ 11 12 #include "usb_otg_config.h" 13 14 #if ((defined USB_OTG_CONFIG_KHCI) && (USB_OTG_CONFIG_KHCI)) 15 16 /******************************************************************************* 17 * Definitions 18 ******************************************************************************/ 19 20 /*! @brief restart to check the SRP when time exceeds the value */ 21 #define USB_OTG_TIME_SRP_TIME_OUT (2000U) 22 /*! @brief check BHNP flag for the max3353 periodically */ 23 #define USB_OTG_TIME_CHECK_BHNP_PERIODIC (20U) 24 /*! @brief check detach time */ 25 #define USB_OTG_TIME_CHECK_DETACH (300U) 26 27 /*! @brief KHCI check types */ 28 typedef enum _usb_otg_check_type 29 { 30 kOtg_CheckNone = 0x00U, /*!< default value */ 31 kOtg_CheckNonConn, /*!< check disconnection */ 32 kOtg_CheckConn, /*!< check connection */ 33 kOtg_CheckSrp, /*!< check SRP */ 34 kOtg_CheckSsendSe0Srp, /*!< check b_se0_srp and b_ssend_srp */ 35 kOtg_CheckIdleTimeOut, /*!< check idle time out */ 36 kOtg_CheckBHNP, /*!< check HNP */ 37 kOtg_CheckSuspend, /*!< check suspend */ 38 } usb_otg_check_type_t; 39 40 /*! @brief check the status on peripheral */ 41 typedef enum _usb_otg_peripheral_status_type 42 { 43 kPeripheral_StatusId = 0x01U, /*! id */ 44 kPeripheral_StatusSessVld = 0x02U, /*! b_sess_vld */ 45 kPeripheral_StatusVbusVld = 0x04U, /*! b_vbus_vld */ 46 kPeripheral_StatusHNPdetected = 0x08U, /*! detect HNP */ 47 kPeripheral_StatusAll = 0x10U, /*! all above status bits value */ 48 } usb_otg_peripheral_status_type_t; 49 50 /*! @brief The control types */ 51 typedef enum _usb_otg_peripheral_control 52 { 53 kPeripheral_ControlVbus, /*! control vbus */ 54 kPeripheral_ControlHNPCheckEnable, /*! start to check HNP */ 55 kPeripheral_ControlUpdateStatus, /*! notify the controller to update the newest status */ 56 } usb_otg_peripheral_control_t; 57 58 /*! @brief KHCI driver instance structure */ 59 typedef struct _usb_otg_khci 60 { 61 usb_otg_handle otgHandle; 62 USB_Type *usbRegBase; /*!< EHCI IP base address */ 63 volatile uint32_t lastState; /*!< The last state value, please referenct to #usb_otg_device_state_t */ 64 volatile uint32_t peripheralStatus; /*!< The peripheral status */ 65 volatile uint16_t lineStableTime; /*!< the duration for stable line */ 66 volatile uint16_t internalTimerValue; /*!< internal timer value */ 67 volatile uint16_t externalTimerValue; /*!< external timer value */ 68 69 /* b_ssend_srp Check */ 70 volatile uint16_t bssendsrpCheck; /*!< use to check b_ssend_srp */ 71 72 volatile uint16_t checkTime; /*!< use to check the status, please referenct to #usb_otg_check_type_t */ 73 volatile uint8_t checkType; /*!< use to check the status, please referenct to #usb_otg_check_type_t */ 74 75 volatile uint8_t 76 externalTimerEnable; /*!< 1 - the externalTimerValue is valid; 0 - the externalTimerValue is invalid */ 77 78 /* srp detect */ 79 volatile uint8_t checkSrpState; /*!< check SRP steps */ 80 81 volatile uint8_t se0State; /*!< line state se0 */ 82 volatile uint8_t jState; /*!< line state J */ 83 } usb_otg_khci_instance_t; 84 85 /******************************************************************************* 86 * API 87 ******************************************************************************/ 88 89 /*! 90 * @brief Initialize the USB OTG KHCI instance. 91 * 92 * This function initializes the USB OTG KHCI controller driver. 93 * 94 * @param controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t. 95 * @param otgHandle the OTG level handle. 96 * @param controllerHandle Return the controller instance handle. 97 * 98 * @retval kStatus_USB_Success The host is initialized successfully. 99 * @retval kStatus_USB_AllocFail Allocate memory failed. 100 * @retval kStatus_USB_Error Initialize fail 101 */ 102 usb_status_t USB_OtgKhciInit(uint8_t controllerId, 103 usb_otg_handle otgHandle, 104 usb_otg_controller_handle *controllerHandle); 105 106 /*! 107 * @brief de-initialize the USB OTG KHCI instance. 108 * 109 * This function de-initializes the USB OTG KHCI controller driver. 110 * 111 * @param controllerHandle Controller instance handle. 112 * 113 * @retval kStatus_USB_Success success. 114 * @retval other values Fail. 115 */ 116 usb_status_t USB_OtgKhciDeinit(usb_otg_controller_handle controllerHandle); 117 118 /*! 119 * @brief Control the USB OTG KHCI. 120 * 121 * This function controls the USB OTG KHCI controller to implement different functions. 122 * 123 * @param controllerHandle The controller instance handle. 124 * @param controlType The control type, please referenct to #usb_otg_control_t. 125 * @param controlValue1 The control value, it is 0 or 1 usually. 126 * @param controlValue2 It only be used in the kOtg_ControlRequestStatus control now. 127 * 128 * @retval kStatus_USB_Success success. 129 * @retval other values Fail. 130 */ 131 usb_status_t USB_OtgKhciControl(usb_otg_controller_handle controllerHandle, 132 uint32_t controlType, 133 uint32_t controlValue1, 134 uint32_t controlValue2); 135 136 #endif 137 138 #endif /* __USB_OTG_KHCI_H__ */ 139