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_OCI_H__
10 #define __USB_OTG_OCI_H__
11 
12 /*!
13  * @addtogroup usb_otg_controller_driver
14  * @{
15  */
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 
21 /* OTG state machine timer and time periodic */
22 /*! @brief a_wait_vrise_tmr in OTG spec, VBUS Rise Time, 100ms */
23 #define USB_OTG_TIMER_A_WAIT_VRISE_TMR (100U)
24 /*! @brief a_wait_vfall_tmr in OTG spec, Session end to VOTG_VBUS_LKG, 1sec */
25 #define USB_OTG_TIMER_A_WAIT_VFALL_TMR (1000U)
26 /*! @brief a_wait_bcon_tmr in OTG spec, Wait for B-Connect, 1.1sec ~ 30^15sec */
27 #define USB_OTG_TIMER_A_WAIT_BCON_TMR (2000U)
28 /*! @brief a_aidl_bdis_tmr in OTG spec, A-Idle to B-Disconnect, 200ms ~ infinity */
29 #define USB_OTG_TIMER_A_AIDL_BDIS_TMR (500U)
30 /*! @brief b_ase0_brst_tmr in OTG spec, A-SE0 to B-Reset, 155ms ~ 200ms */
31 #define USB_OTG_TIMER_B_ASE0_BRST_TMR (155U)
32 /*! @brief TB_DATA_PLS in OTG spec, Data-Line Pulse Time, 5ms ~ 10ms. generate the data pulse using this time value. */
33 #define USB_OTG_TIME_B_DATA_PLS (7U)
34 /*! @brief TB_DATA_PLS in OTG spec, Data-Line Pulse Time's minimum value */
35 #define USB_OTG_TIME_B_DATA_PLS_MIN (5U)
36 /*! @brief TB_DATA_PLS in OTG spec, Data-Line Pulse Time's maximum value */
37 #define USB_OTG_TIME_B_DATA_PLS_MAX (10U)
38 /*! @brief TA_BCON_LDB in OTG spec, B-Connect Long Debounce, 100ms ~ infinity */
39 #define USB_OTG_TIME_A_BCON_LDB (100U)
40 /*! @brief TA_BCON_SDB in OTG spec, B-Connect Short Debounce, 2.5us ~ infinity */
41 #define USB_OTG_TIME_A_BCON_SDB (1U)
42 /*! @brief TB_SSEND_SRP in OTG spec, Session end to SRP init, 1.5sec ~ infinity */
43 #define USB_OTG_TIME_B_SSEND_SRP (1500U)
44 /*! @brief TB_SE0_SRP in OTG spec, SE0 Time Before SRP, 1sec ~ infinity */
45 #define USB_OTG_TIME_B_SE0_SRP (1000U)
46 /*! @brief TB_AIDL_BDIS in OTG spec, A-Idle to B-Disconnect, 4ms ~ 150ms */
47 #define USB_OTG_TIME_B_AIDL_BDIS (100U)
48 /*! @brief TA_BIDL_ADIS in OTG spec, B-Idle to A-Disconnect,
49 Used by an A-device to determine when the B-device has finished being host, 155ms ~ 200ms */
50 #define USB_OTG_TIME_A_BIDL_ADIS (190U)
51 
52 /* self-defined constant time value */
53 /*! @brief wait another device initialize device stack before initializing the host stack */
54 #define USB_OTG_TIME_WAIT_DEVICE_INIT (200U)
55 /*! @brief delay this time before check idle in a_peripheral state, wait another device initialize host stack */
56 #define USB_OTG_TIME_WAIT_BHOST (1000U)
57 #define USB_OTG_MESSAGES_SIZE (sizeof(uint32_t) * (1U + (sizeof(usb_otg_msg_t) - 1U) / sizeof(uint32_t)))
58 /*! @brief The control types */
59 typedef enum _usb_otg_control
60 {
61     kOtg_ControlVbus,           /*! control vbus */
62     kOtg_ControlPullUp,         /*! pull dp/dm up */
63     kOtg_ControlPullDown,       /*! pull dp/dm down */
64     kOtg_ControlResume,         /*! do resume */
65     kOtg_ControlAdpPrb,         /*! probe adp */
66     kOtg_ControlDataPulse,      /*! generate data pulse */
67     kOtg_ControlHNPCheckEnable, /*! start to check HNP */
68     kOtg_ControlSetTimer,       /*! start timer */
69     kOtg_ControlCancelTimer,    /*! cancel timer */
70     kOtg_ControlRequestStatus,  /*! request the status values #usb_otg_status_type_t */
71     kOtg_ControlUpdateStatus,   /*! notify the controller to update the newest status */
72 } usb_otg_control_t;
73 
74 /*! @brief Pull up/down parameters */
75 typedef enum _usb_otg_pull_control
76 {
77     /*! pull DP line */
78     kOtg_PullDp = 0x01U,
79     /*! pull DM line */
80     kOtg_PullDm = 0x02U,
81 } usb_otg_pull_control_t;
82 
83 typedef struct _usb_otg_controller_interface
84 {
85     usb_status_t (*controllerInit)(
86         uint8_t controllerId,
87         usb_otg_handle upperLayerHandle,
88         usb_otg_controller_handle *controllerHandle); /*!< Init a controller instance function prototype*/
89     usb_status_t (*controllerDeinit)(
90         usb_otg_controller_handle controllerHandle); /*!< Deinit a controller instance function prototype*/
91     usb_status_t (*controllerControl)(usb_otg_controller_handle controllerHandle,
92                                       uint32_t controlType,
93                                       uint32_t controlValue1,
94                                       uint32_t controlValue2); /*!< Control a controller function prototype*/
95 } usb_otg_controller_interface_t;
96 
97 /*! @brief OTG stack task message */
98 typedef struct _usb_otg_msg
99 {
100     uint32_t otgStatusType;  /*!< The status types please reference to #usb_otg_status_type_t */
101     uint32_t otgStatusValue; /*!< The status values */
102 } usb_otg_msg_t;
103 
104 /*! @}*/
105 
106 /*!
107  * @addtogroup usb_otg_drv
108  * @{
109  */
110 
111 /*! @brief USB OTG instance structure */
112 typedef struct _usb_otg_instance
113 {
114     usb_otg_controller_handle controllerHandle; /*!< The low level controller handle */
115     usb_otg_callback_t otgCallback;             /*!< OTG callback function*/
116     void *otgCallbackParameter;                 /*!< OTG callback function parameter */
117     OSA_MSGQ_HANDLE_DEFINE(otgMsgHandleBuffer,
118                            USB_OTG_MSG_COUNT,
119                            (USB_OTG_MESSAGES_SIZE)); /*!< OTG task message queue handle */
120     osa_msgq_handle_t otgMsgHandle;
121     const usb_otg_controller_interface_t *controllerInterface; /*!< controller interface APIs */
122     uint32_t otgControllerStatus;                              /*!< please reference to #usb_otg_status_type_t */
123     uint8_t otgDeviceState;                                    /*!< please reference to #usb_otg_device_state_t */
124     volatile uint8_t hasTimeOutMsg;                            /*!< There is timer out message in the message queue */
125     volatile uint8_t hasUpdateMsg;                             /*!< There is update message in the message queue */
126     uint8_t cancelTime;                                        /*!< Don't process the timer out message */
127     uint8_t waitInit; /*!< Waiting the opposite side board's device stack or host stack initializing */
128     volatile uint8_t idChangeAsFalse;
129 } usb_otg_instance_t;
130 
131 /*! @}*/
132 
133 #endif /* __USB_OTG_OCI_H__ */
134