aboutsummaryrefslogtreecommitdiff
path: root/drivers/usb/fusb302/core/fusb30X.h
blob: 45c2b7d6e322ff2c2b5e7b2d3e6cab8cbfc30b4d (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 * 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 _FUSB30X_H_
#define _FUSB30X_H_

#include "platform.h"

// 302 Device ID
#define VERSION_302A 0x08
#define VERSION_302B 0x09

// Convenience interfaces to I2C_WriteData() and I2C_ReadData()
FSC_BOOL DeviceWrite(FSC_U8 regAddr, FSC_U8 length, FSC_U8* data);
FSC_BOOL DeviceRead(FSC_U8 regAddr, FSC_U8 length, FSC_U8* data);

// FUSB300 I2C Configuration
#define FUSB300SlaveAddr   0x44
#define FUSB300AddrLength  1        // One byte address
#define FUSB300IncSize     1        // One byte increment

// FUSB300 Register Addresses
#define regDeviceID     0x01
#define regSwitches0    0x02
#define regSwitches1    0x03
#define regMeasure      0x04
#define regSlice        0x05
#define regControl0     0x06
#define regControl1     0x07
#define regControl2     0x08
#define regControl3     0x09
#define regMask         0x0A
#define regPower        0x0B
#define regReset        0x0C
#define regOCPreg       0x0D
#define regMaska        0x0E
#define regMaskb        0x0F
#define regControl4     0x10
#define regStatus0a     0x3C
#define regStatus1a     0x3D
#define regInterrupta   0x3E
#define regInterruptb   0x3F
#define regStatus0      0x40
#define regStatus1      0x41
#define regInterrupt    0x42
#define regFIFO         0x43

/* Note: MDAC values are actually (MDAC + 1) * 42/420mV *
 * Data sheet is incorrect                              */
#ifdef FPGA_BOARD
    #define SDAC_DEFAULT        0x29
    #define MDAC_0P210V         0x03
    #define MDAC_0P420V         0x07
    #define MDAC_0P798V         0x0F
    #define MDAC_1P596V         0x1E
    #define MDAC_2P058V         0x27
    #define MDAC_2P604V         0x31

    #define VBUS_MDAC_0P84V     0x00
#else
    #define SDAC_DEFAULT        0x1F
    #define MDAC_0P210V         0x04
    #define MDAC_0P420V         0x09
    #define MDAC_0P798V         0x12
    #define MDAC_1P596V         0x25
    #define MDAC_2P058V         0x30
    #define MDAC_2P604V         0x3D

    #define VBUS_MDAC_0P84V     0x01
    #define VBUS_MDAC_3P78      0x08
    #define VBUS_MDAC_4P20      0x09
    #define VBUS_MDAC_4P62      0x0A
    #define VBUS_MDAC_5P04      0x0B
    #define VBUS_MDAC_5P46      0x0C
    #define VBUS_MDAC_11P76     0x1B
#endif

typedef union {
    FSC_U8 byte;
    struct {
        unsigned REVISION_ID:2;
        unsigned PRODUCT_ID:2;
        unsigned VERSION_ID:4;
    };
} regDeviceID_t;

typedef union {
    FSC_U16 word;
    FSC_U8 byte[2] __PACKED;
    struct {
        // Switches0
        unsigned PDWN1:1;
        unsigned PDWN2:1;
        unsigned MEAS_CC1:1;
        unsigned MEAS_CC2:1;
        unsigned VCONN_CC1:1;
        unsigned VCONN_CC2:1;
        unsigned PU_EN1:1;
        unsigned PU_EN2:1;
        // Switches1
        unsigned TXCC1:1;
        unsigned TXCC2:1;
        unsigned AUTO_CRC:1;
        unsigned :1;
        unsigned DATAROLE:1;
        unsigned SPECREV:2;
        unsigned POWERROLE:1;
    };
} regSwitches_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned MDAC:6;
        unsigned MEAS_VBUS:1;
        unsigned :1;
    };
} regMeasure_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned SDAC:6;
        unsigned SDAC_HYS:2;
    };
} regSlice_t;

typedef union {
    FSC_U32 dword;
    FSC_U8 byte[4] __PACKED;
    struct {
        // Control0
        unsigned TX_START:1;
        unsigned AUTO_PRE:1;
        unsigned HOST_CUR:2;
        unsigned LOOPBACK:1;
        unsigned INT_MASK:1;
        unsigned TX_FLUSH:1;
        unsigned :1;
        // Control1
        unsigned ENSOP1:1;
        unsigned ENSOP2:1;
        unsigned RX_FLUSH:1;
        unsigned :1;
        unsigned BIST_MODE2:1;
        unsigned ENSOP1DP:1;
        unsigned ENSOP2DB:1;
        unsigned :1;
        // Control2
        unsigned TOGGLE:1;
        unsigned MODE:2;
        unsigned WAKE_EN:1;
        unsigned WAKE_SELF:1;
        unsigned TOG_RD_ONLY:1;
        unsigned :2;
        // Control3
        unsigned AUTO_RETRY:1;
        unsigned N_RETRIES:2;
        unsigned AUTO_SOFTRESET:1;
        unsigned AUTO_HARDRESET:1;
        unsigned BIST_TMODE:1;          // 302B Only
        unsigned SEND_HARDRESET:1;
        unsigned :1;
    };
} regControl_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned M_BC_LVL:1;
        unsigned M_COLLISION:1;
        unsigned M_WAKE:1;
        unsigned M_ALERT:1;
        unsigned M_CRC_CHK:1;
        unsigned M_COMP_CHNG:1;
        unsigned M_ACTIVITY:1;
        unsigned M_VBUSOK:1;
    };
} regMask_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned PWR:4;
        unsigned :4;
    };
} regPower_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned SW_RES:1;
        unsigned :7;
    };
} regReset_t;    

typedef union {
    FSC_U8 byte;
    struct {
        unsigned OCP_CUR:3;
        unsigned OCP_RANGE:1;
        unsigned :4;
    };
} regOCPreg_t;

typedef union {
    FSC_U16 word;
    FSC_U8 byte[2] __PACKED;
    struct {
        // Maska
        unsigned M_HARDRST:1;
        unsigned M_SOFTRST:1;
        unsigned M_TXSENT:1;
        unsigned M_HARDSENT:1;
        unsigned M_RETRYFAIL:1;
        unsigned M_SOFTFAIL:1;
        unsigned M_TOGDONE:1;
        unsigned M_OCP_TEMP:1;
        // Maskb
        unsigned M_GCRCSENT:1;
        unsigned :7;
    };
} regMaskAdv_t;

typedef union {
    FSC_U8 byte;
    struct {
        unsigned TOG_USRC_EXIT:1;
        unsigned :7;
    };
} regControl4_t;

typedef union {
    FSC_U8 byte[7] __PACKED;
    struct {
        FSC_U16  StatusAdv;
        FSC_U16  InterruptAdv;
        FSC_U16  Status;
        FSC_U8   Interrupt1;
    };
    struct {
        // Status0a
        unsigned HARDRST:1;
        unsigned SOFTRST:1;
        unsigned POWER23:2;
        unsigned RETRYFAIL:1;
        unsigned SOFTFAIL:1;
        unsigned TOGDONE:1;
        unsigned M_OCP_TEMP:1;
        // Status1a
        unsigned RXSOP:1;
        unsigned RXSOP1DB:1;
        unsigned RXSOP2DB:1;
        unsigned TOGSS:3;
        unsigned :2;
        // Interrupta
        unsigned I_HARDRST:1;
        unsigned I_SOFTRST:1;
        unsigned I_TXSENT:1;
        unsigned I_HARDSENT:1;
        unsigned I_RETRYFAIL:1;
        unsigned I_SOFTFAIL:1;
        unsigned I_TOGDONE:1;
        unsigned I_OCP_TEMP:1;
        // Interruptb
        unsigned I_GCRCSENT:1;
        unsigned :7;
        // Status0
        unsigned BC_LVL:2;
        unsigned WAKE:1;
        unsigned ALERT:1;
        unsigned CRC_CHK:1;
        unsigned COMP:1;
        unsigned ACTIVITY:1;
        unsigned VBUSOK:1;
        // Status1
        unsigned OCP:1;
        unsigned OVRTEMP:1;
        unsigned TX_FULL:1;
        unsigned TX_EMPTY:1;
        unsigned RX_FULL:1;
        unsigned RX_EMPTY:1;
        unsigned RXSOP1:1;          
        unsigned RXSOP2:1;
        // Interrupt
        unsigned I_BC_LVL:1;
        unsigned I_COLLISION:1;
        unsigned I_WAKE:1;
        unsigned I_ALERT:1;
        unsigned I_CRC_CHK:1;
        unsigned I_COMP_CHNG:1;
        unsigned I_ACTIVITY:1;
        unsigned I_VBUSOK:1;
    };
} regStatus_t;

typedef struct 
{
    regDeviceID_t   DeviceID;
    regSwitches_t   Switches;
    regSwitches_t   Switches_temp;
    regMeasure_t    Measure;
    regSlice_t      Slice;
    regControl_t    Control;
    regMask_t       Mask;
    regPower_t      Power;
    regReset_t      Reset;
    regOCPreg_t     OCPreg;
    regMaskAdv_t    MaskAdv;
    regControl4_t   Control4;
    regStatus_t     Status;
} DeviceReg_t;

#endif // _FUSB30X_H_