aboutsummaryrefslogtreecommitdiff
path: root/drivers/usb/fusb302/Platform_Linux/platform_helpers.h
blob: 130986205908009d465892c5a433be054bc40851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
 * fusb302 usb phy driver for type-c and PD
 *
 * Copyright (C) 2015, 2016 Fairchild Semiconductor Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Seee the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#ifndef __FUSB_PLATFORM_HELPERS_H_
#define __FUSB_PLATFORM_HELPERS_H_

#include "../core/PD_Types.h"                                                   // State Log states

#define INIT_DELAY_MS   500     // Time to wait before initializing the device, in ms
#define RETRIES_I2C 3           // Number of retries for I2C reads/writes

enum {
    DISABLE_VCONN,
    ENABLE_VCONN_CC1,
    ENABLE_VCONN_CC2,
};

/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************        GPIO Interface         ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*******************************************************************************
* Function:        fusb_InitializeGPIO
* Input:           none
* Return:          0 on success, error code otherwise
* Description:     Initializes the platform's GPIO
********************************************************************************/
FSC_S32 fusb_InitializeGPIO(void);

/*******************************************************************************
* Function:        fusb_GPIO_Set_VBus5v/Other
* Input:           set: true to set pin, false to clear
* Return:          none
* Description:     Sets or clears the VBus5V/Other gpio pin
********************************************************************************/
void fusb_GPIO_Set_VBus5v(FSC_BOOL set);
void fusb_GPIO_Set_VBusOther(FSC_BOOL set);

/*******************************************************************************
* Function:        fusb_GPIO_Get_VBus5v/Other/IntN
* Input:           none
* Return:          true if set, false if clear
* Description:     Returns the value of the GPIO pin
********************************************************************************/
FSC_BOOL fusb_GPIO_Get_VBus5v(void);
FSC_BOOL fusb_GPIO_Get_VBusOther(void);
FSC_BOOL fusb_GPIO_Get_IntN(void);

/*******************************************************************************
* Function:        fusb_Power_Vconn
* Input:           true: enable VCONN ; false: disable VCONN
* Return:          true if VCONN is power on, false otherwise
* Description:     Sets or clear the value of the VCONN GPIO pin
********************************************************************************/
FSC_BOOL fusb_Power_Vconn(FSC_BOOL set);

FSC_S32 fusb_battery_select_source_capability(u8 obj_cnt, doDataObject_t pd_data[7], int *device_max_ma);


#ifdef FSC_DEBUG
/*******************************************************************************
* Function:        fusb_GPIO_Set_SM_Toggle
* Input:           set - true to set high, false to set low
* Return:          none
* Description:     Sets or clears the GPIO pin
********************************************************************************/
void dbg_fusb_GPIO_Set_SM_Toggle(FSC_BOOL set);

/*******************************************************************************
* Function:        fusb_GPIO_Get_SM_Toggle
* Input:           none
* Return:          true if set, false if clear
* Description:     Returns the value of the GPIO pin
********************************************************************************/
FSC_BOOL dbg_fusb_GPIO_Get_SM_Toggle(void);
#endif  // FSC_DEBUG

/*******************************************************************************
* Function:        fusb_GPIO_Cleanup
* Input:           none
* Return:          none
* Description:     Frees any GPIO resources we may have claimed (eg. INT_N, VBus5V)
********************************************************************************/
void fusb_GPIO_Cleanup(void);


/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************         I2C Interface         ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*******************************************************************************
* Function:        fusb_I2C_WriteData
* Input:           address - Destination register for write data
*                  length - Number of data bytes to write
*                  data - Data to write to the register at address
* Return:          true on success, false otherwise
* Description:     Write an unsigned byte to the I2C peripheral.
*                  Blocking, with retries
********************************************************************************/
FSC_BOOL fusb_I2C_WriteData(FSC_U8 address, FSC_U8 length, FSC_U8* data);

/*******************************************************************************
* Function:        fusb_I2C_ReadData
* Input:           address - Source register for read data
*                  data - Output storage
* Return:          true on success, false otherwise
* Description:     Read an unsigned byte from the I2C peripheral.
*                  Blocking, with retries
********************************************************************************/
FSC_BOOL fusb_I2C_ReadData(FSC_U8 address, FSC_U8* data);

/*******************************************************************************
* Function:        fusb_I2C_ReadBlockData
* Input:           address - Source register for read data
*                  length - Number of sequential bytes to read
*                  data - Output buffer
* Return:          true on success, false otherwise
* Description:     Read a block of unsigned bytes from the I2C peripheral.
********************************************************************************/
FSC_BOOL fusb_I2C_ReadBlockData(FSC_U8 address, FSC_U8 length, FSC_U8* data);


/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************        Timer Interface        ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*******************************************************************************
* Function:        fusb_InitializeTimer
* Input:           none
* Return:          none
* Description:     Initializes and timers that the platform is responsible for
********************************************************************************/
void fusb_InitializeTimer(void);

/*******************************************************************************
* Function:        fusb_StartTimers
* Input:           none
* Return:          none
* Description:     Starts the timers
********************************************************************************/
void fusb_StartTimers(void);

/*******************************************************************************
* Function:        fusb_StopTimers
* Input:           none
* Return:          none
* Description:     Cancels any timers that may be running
********************************************************************************/
void fusb_StopTimers(void);

/*******************************************************************************
* Function:        fusb_Delay10us
* Input:           delay10us: Time to delay, in 10us increments
* Return:          none
* Description:     Delays the given amount of time
********************************************************************************/
void fusb_Delay10us(FSC_U32 delay10us);

#ifdef FSC_DEBUG
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************        SysFS Interface        ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*******************************************************************************
* Function:        fusb_Sysfs_Init
* Input:           none
* Return:          none
* Description:     Initializes the sysfs objects (used for user-space access)
********************************************************************************/
void fusb_Sysfs_Init(void);
#endif // FSC_DEBUG
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************        Driver Helpers         ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*******************************************************************************
* Function:        fusb_InitializeCore
* Input:           none
* Return:          none
* Description:     Calls core initialization functions
********************************************************************************/
void fusb_InitializeCore(void);

/*******************************************************************************
* Function:        fusb_IsDeviceValid
* Input:           none
* Return:          true if device is valid, false otherwise
* Description:     Verifies device contents via I2C read
********************************************************************************/
FSC_BOOL fusb_IsDeviceValid(void);

/*******************************************************************************
* Function:        fusb_InitChipData
* Input:           none
* Return:          none
* Description:     Initializes our driver chip struct data
********************************************************************************/
void fusb_InitChipData(void);

/*********************************************************************************************************************/
/*********************************************************************************************************************/
/********************************************       Threading Helpers       ******************************************/
/*********************************************************************************************************************/
/*********************************************************************************************************************/

#ifdef FSC_INTERRUPT_TRIGGERED

/*******************************************************************************
* Function:        fusb_EnableInterrupts
* Input:           none
* Return:          0 on success, error code on failure
* Description:     Initializaes and enables the INT_N interrupt.
*                  NOTE: The interrupt may be triggered at any point once this is called.
*                  NOTE: The Int_N GPIO must be intialized prior to using this function.
********************************************************************************/
FSC_S32 fusb_EnableInterrupts(void);

#else

/*******************************************************************************
* Function:        fusb_InitializeWorkers
* Input:           none
* Return:          none
* Description:     Initializes the driver's workers
********************************************************************************/
void fusb_InitializeWorkers(void);

/*******************************************************************************
* Function:        fusb_StopThreads
* Input:           none
* Return:          none
* Description:     Cancels the driver's workers
********************************************************************************/
void fusb_StopThreads(void);

/*******************************************************************************
* Function:        fusb_ScheduleWork
* Input:           none
* Return:          none
* Description:     Starts the first worker
********************************************************************************/
void fusb_ScheduleWork(void);

#endif  // FSC_INTERRUPT_TRIGGERED, else

#endif  // __FUSB_PLATFORM_HELPERS_H_