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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
/*
* Copyrights (C) 2017 Samsung Electronics, Inc.
* Copyrights (C) 2017 Maxim Integrated Products, Inc.
*
* 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 2 of the License, or
* (at your option) 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. See the
* GNU General Public License for more details.
*/
#ifndef __LINUX_MFD_MAX77705_H
#define __LINUX_MFD_MAX77705_H
#define MAX77705_CCPD_NAME "MAX77705"
#undef __CONST_FFS
#define __CONST_FFS(_x) \
((_x) & 0x0F ? \
((_x) & 0x03 ? ((_x) & 0x01 ? 0 : 1) : ((_x) & 0x04 ? 2 : 3)) : \
((_x) & 0x30 ? ((_x) & 0x10 ? 4 : 5) : ((_x) & 0x40 ? 6 : 7)))
#undef FFS
#define FFS(_x) \
((_x) ? __CONST_FFS(_x) : 0)
#undef BIT_RSVD
#define BIT_RSVD 0
#undef BITS
#define BITS(_end, _start) \
((BIT(_end) - BIT(_start)) + BIT(_end))
#undef __BITS_GET
#define __BITS_GET(_word, _mask, _shift) \
(((_word) & (_mask)) >> (_shift))
#undef BITS_GET
#define BITS_GET(_word, _bit) \
__BITS_GET(_word, _bit, FFS(_bit))
#undef __BITS_SET
#define __BITS_SET(_word, _mask, _shift, _val) \
(((_word) & ~(_mask)) | (((_val) << (_shift)) & (_mask)))
#undef BITS_SET
#define BITS_SET(_word, _bit, _val) \
__BITS_SET(_word, _bit, FFS(_bit), _val)
#undef BITS_MATCH
#define BITS_MATCH(_word, _bit) \
(((_word) & (_bit)) == (_bit))
/*
* Register address
*/
#define REG_UIC_HW_REV 0x00
#define REG_UIC_FW_REV 0x01
#define REG_UIC_INT 0x02
#define REG_CC_INT 0x03
#define REG_PD_INT 0x04
#define REG_VDM_INT 0x05
#define REG_USBC_STATUS1 0x06
#define REG_USBC_STATUS2 0x07
#define REG_BC_STATUS 0x08
#define REG_UIC_FW_MINOR 0x09
#define REG_CC_STATUS0 0x0A
#define REG_CC_STATUS1 0x0B
#define REG_PD_STATUS0 0x0C
#define REG_PD_STATUS1 0x0D
#define REG_UIC_INT_M 0x0E
#define REG_CC_INT_M 0x0F
#define REG_PD_INT_M 0x10
#define REG_VDM_INT_M 0x11
#define REG_OPCODE 0x21
#define REG_OPCODE_DATA 0x22
#define REG_OPCDE_RES 0x51
#define REG_END_DATA 0x41
/*
* REG_INT_M Initial values
*/
#define REG_UIC_INT_M_INIT 0x04
#define REG_CC_INT_M_INIT 0x20
#define REG_PD_INT_M_INIT 0x00
#define REG_VDM_INT_M_INIT 0xF0
/*
* REG_UIC_INT Interrupts
*/
#define BIT_APCmdResI BIT(7)
#define BIT_SYSMsgI BIT(6)
#define BIT_VBUSDetI BIT(5)
#define BIT_VbADCI BIT(4)
#define BIT_DCDTmoI BIT(3)
#define BIT_CHGTypI BIT(1)
#define BIT_UIDADCI BIT(0)
/*
* REG_CC_INT Interrupts
*/
#define BIT_VCONNOCPI BIT(7)
#define BIT_VSAFE0VI BIT(6)
#define BIT_AttachSrcErrI BIT(5)
#define BIT_VCONNSCI BIT(4)
#define BIT_CCPinStatI BIT(3)
#define BIT_CCIStatI BIT(2)
#define BIT_CCVcnStatI BIT(1)
#define BIT_CCStatI BIT(0)
/*
* REG_PD_INT Interrupts
*/
#define BIT_PDMsgI BIT(7)
#define BIT_DataRole BIT(5)
#define BIT_SSAccI BIT(1)
#define BIT_FCTIDI BIT(0)
/*
* REG_USBC_STATUS1
*/
#define BIT_VBADC BITS(7, 4)
#define BIT_UIDADC BITS(2, 0)
/*
* REG_USBC_STATUS2
*/
#define BIT_SYSMsg BITS(7, 0)
/*
* REG_BC_STATUS
*/
#define BIT_VBUSDet BIT(7)
#define BIT_PrChgTyp BITS(5, 3)
#define BIT_DCDTmo BIT(2)
#define BIT_ChgTyp BITS(1, 0)
/*
* REG_CC_STATUS1
*/
#define BIT_CCPinStat BITS(7, 6)
#define BIT_CCIStat BITS(5, 4)
#define BIT_CCVcnStat BIT(3)
#define BIT_CCStat BITS(2, 0)
/*
* REG_CC_STATUS2
*/
#define BIT_VCONNOCP BIT(5)
#define BIT_VCONNSC BIT(4)
#define BIT_VSAFE0V BIT(3)
#define BIT_AttachSrcErr BIT(2)
#define BIT_ConnStat BIT(1)
/*
* REG_PD_STATUS0
*/
#define BIT_PDMsg BITS(7, 0)
/*
* REG_PD_STATUS1
*/
#define BIT_PD_DataRole BIT(7)
#define BIT_PD_PSRDY BIT(4)
#define BIT_FCT_ID BITS(3, 0)
/*
* max77766 role
*/
enum max77705_data_role {
UFP = 0,
DFP,
};
enum max77705_power_role {
SNK = 0,
SRC,
};
enum max77705_vcon_role {
OFF = 0,
ON
};
/*
* F/W update
*/
#define FW_CMD_READ 0x3
#define FW_CMD_READ_SIZE 6 /* cmd(1) + len(1) + data(4) */
#define FW_CMD_WRITE 0x1
#define FW_CMD_WRITE_SIZE 36 /* cmd(1) + len(1) + data(34) */
#define FW_CMD_END 0x0
#define FW_HEADER_SIZE 8
#define FW_VERIFY_DATA_SIZE 3
#define FW_VERIFY_TRY_COUNT 10
#define FW_WAIT_TIMEOUT (1000 * 5) /* 5 sec */
#define I2C_SMBUS_BLOCK_HALF (I2C_SMBUS_BLOCK_MAX / 2)
struct max77705_fw_header {
u8 data0;
u8 data1;
u8 data2;
u8 data3;
u8 data4; /* FW version LSB */
u8 data5;
u8 data6;
u8 data7; /* FW version MSB */
};
enum {
FW_UPDATE_START = 0x00,
FW_UPDATE_WAIT_RESP_START,
FW_UPDATE_WAIT_RESP_STOP,
FW_UPDATE_DOING,
FW_UPDATE_END,
};
enum {
FW_UPDATE_FAIL = 0xF0,
FW_UPDATE_I2C_FAIL,
FW_UPDATE_TIMEOUT_FAIL,
FW_UPDATE_VERIFY_FAIL,
FW_UPDATE_CMD_FAIL,
FW_UPDATE_MAX_LENGTH_FAIL,
};
enum {
NO_DETERMINATION = 0,
CC1_ACTIVE,
CC2_ACTVIE,
AUDIO_ACCESSORY,
DEBUG_ACCESSORY,
ERROR,
DISABLED,
RFU,
};
enum {
NOT_IN_UFP_MODE = 0,
CCI_500mA,
CCI_1_5A,
CCI_3_0A,
CCI_SHORT,
};
/*
* All type of Interrupts
*/
enum {
AP_Command_respond = 7,
USBC_System_message = 6,
CHGIN_Voltage = 5,
CHGIN_Voltage_ADC = 4,
DCD_Timer = 3,
Charge_Type = 1,
UID_ADC = 0,
};
enum max77705_chg_type {
CHGTYP_NOTHING = 0,
CHGTYP_USB_SDP,
CHGTYP_CDP_T,
CHGTYP_DCP,
};
enum max77705_pr_chg_type {
Unknown = 0,
Samsung_2A,
Apple_05A,
Apple_1A,
Apple_2A,
Apple_12W,
DCP_3A,
RFU_CHG,
};
enum max77705_ccpd_device {
DEV_NONE = 0,
DEV_OTG,
DEV_USB,
DEV_CDP,
DEV_DCP,
DEV_APPLE500MA,
DEV_APPLE1A,
DEV_APPLE2A,
DEV_APPLE12W,
DEV_DCP3A,
DEV_HVDCP,
DEV_QC,
DEV_FCT_0,
DEV_FCT_1K,
DEV_FCT_255K,
DEV_FCT_301K,
DEV_FCT_523K,
DEV_FCT_619K,
DEV_FCT_OPEN,
DEV_PD_TA,
DEV_PD_AMA,
DEV_UNKNOWN,
};
enum max77705_uidadc {
UID_GND = 0,
UID_255Kohm = 3,
UID_301Kohm = 4,
UID_523Kohm = 5,
UID_619Kohm = 6,
UID_Open = 7,
};
enum max77705_fctid {
FCT_GND = 1,
FCT_1Kohm,
FCT_255Kohm,
FCT_301Kohm,
FCT_523Kohm,
FCT_619Kohm,
FCT_OPEN,
};
enum max77705_cc_pin_state {
cc_No_Connection = 0,
cc_SINK,
cc_SOURCE,
cc_Audio_Accessory,
cc_Debug_Accessory,
cc_Error,
cc_Disabled,
cc_RFU,
};
enum max77705_usbc_SYSMsg {
SYSERROR_NONE = 0x00,
/*Reserved = 0x01,*/
/*Reserved = 0x02,*/
SYSERROR_BOOT_WDT = 0x03,
SYSERROR_BOOT_SWRSTREQ = 0x04,
SYSMSG_BOOT_POR = 0x05,
SYSERROR_HV_NOVBUS = 0x10,
SYSERROR_HV_FMETHOD_RXPERR = 0x11,
SYSERROR_HV_FMETHOD_RXBUFOW = 0x12,
SYSERROR_HV_FMETHOD_RXTFR = 0x13,
SYSERROR_HV_FMETHOD_MPNACK = 0x14,
SYSERROR_HV_FMETHOD_RESET_FAIL = 0x15,
SYSMsg_AFC_Done = 0x20,
SYSERROR_SYSPOS = 0x30,
SYSERROR_APCMD_UNKNOWN = 0x31,
SYSERROR_APCMD_INPROGRESS = 0x32,
SYSERROR_APCMD_FAIL = 0x33,
SYSMSG_CCx_5V_SHORT = 0x61,
SYSMSG_SBUx_GND_SHORT = 0x62,
SYSMSG_SBUx_5V_SHORT = 0x63,
SYSMSG_SET_GRL = 0x64,
SYSERROR_FACTORY_RID0 = 0x70,
SYSERROR_POWER_NEGO = 0x80,
};
enum max77705_pdmsg {
Nothing_happened = 0x00,
Sink_PD_PSRdy_received = 0x01,
Sink_PD_Error_Recovery = 0x02,
Sink_PD_SenderResponseTimer_Timeout = 0x03,
Source_PD_PSRdy_Sent = 0x04,
Source_PD_Error_Recovery = 0x05,
Source_PD_SenderResponseTimer_Timeout = 0x06,
PD_DR_Swap_Request_Received = 0x07,
PD_PR_Swap_Request_Received = 0x08,
PD_VCONN_Swap_Request_Received = 0x09,
Received_PD_Message_in_illegal_state = 0x0A,
Samsung_Accessory_is_attached = 0x10,
VDM_Attention_message_Received = 0x11,
Rejcet_Received = 0x12,
Not_Supported_Received = 0x13,
Prswap_Snktosrc_Sent = 0x14,
Prswap_Srctosnk_Sent = 0x15,
HARDRESET_RECEIVED = 0x16,
Get_Vbus_turn_on = 0x17,
Get_Vbus_turn_off = 0x18,
HARDRESET_SENT = 0x19,
PRSWAP_SRCTOSWAP = 0x1A,
PRSWAP_SWAPTOSNK = 0X1B,
PRSWAP_SNKTOSWAP = 0x1C,
PRSWAP_SWAPTOSRC = 0x1D,
Sink_PD_Disabled = 0x20,
Source_PD_Disabled = 0x21,
Current_Cable_Connected = 0x22,
Get_Source_Capabilities_Extended_Received = 0x30,
Get_Status_Received = 0x31,
Get_Battery_Cap_Received = 0x32,
Get_Battery_Status_Received = 0x33,
Get_Manufacturer_Info_Received = 0x34,
Source_Capabilities_Extended_Received = 0x35,
Status_Received = 0x36,
Battery_Capabilities_Received = 0x37,
Batery_Status_Received = 0x38,
Manufacturer_Info_Received = 0x39,
VDM_NAK_Recevied = 0x40,
VDM_BUSY_Recevied = 0x41,
VDM_ACK_Recevied = 0x42,
VDM_REQ_Recevied = 0x43,
AFC_Sink_PD_Capabilities_Received = 0x50,
AFC_Sink_PD_PSRdy_Received = 0x51,
AFC_VDM_ResponseTimer_Timout = 0x52,
PDMSG_DP_DISCOVER_IDENTITY = 0x61,
PDMSG_DP_DISCOVER_SVID = 0x62,
PDMSG_DP_DISCOVER_MODES = 0x63,
PDMSG_DP_ENTER_MODE = 0x64,
PDMSG_DP_EXIT_MODE = 0x65,
PDMSG_DP_STATUS = 0x66,
PDMSG_DP_CONFIGURE = 0x67,
PDMSG_DP_ATTENTION = 0x68,
};
enum max77705_connstat {
DRY = 0x00,
WATER = 0x01,
};
/*
* External type definition
*/
#define MAX77705_AUTOIBUS_FW_AT_OFF 3
#define MAX77705_AUTOIBUS_FW_OFF 2
#define MAX77705_AUTOIBUS_AT_OFF 1
#define MAX77705_AUTOIBUS_ON 0
#define OPCODE_WAIT_TIMEOUT (3000) /* 3000ms */
#define OPCODE_WRITE_COMMAND 0x21
#define OPCODE_READ_COMMAND 0x51
#define OPCODE_SIZE 1
#define OPCODE_HEADER_SIZE 1
#define OPCODE_DATA_LENGTH 32
#define OPCODE_MAX_LENGTH (OPCODE_DATA_LENGTH + OPCODE_SIZE)
#define OPCODE_WRITE 0x21
#define OPCODE_WRITE_END 0x41
#define OPCODE_READ 0x51
#define OPCODE_WRITE_SEQ 0x1
#define OPCODE_READ_SEQ 0x2
#define OPCODE_RW_SEQ 0x3
#define OPCODE_PUSH_SEQ 0x4
#define OPCODE_UPDATE_SEQ 0x5
typedef enum {
OPCODE_BCCTRL1_R = 0x01,
OPCODE_BCCTRL1_W,
OPCODE_BCCTRL2_R,
OPCODE_BCCTRL2_W,
OPCODE_CTRL1_R = 0x05,
OPCODE_CTRL1_W,
OPCODE_CTRL2_R,
OPCODE_CTRL2_W,
OPCODE_CTRL3_R,
OPCODE_CTRL3_W,
OPCODE_CCCTRL1_R = 0x0B,
OPCODE_CCCTRL1_W,
OPCODE_CCCTRL2_R,
OPCODE_CCCTRL2_W,
OPCODE_CCCTRL3_R,
OPCODE_CCCTRL3_W,
OPCODE_HVCTRL_R = 0x11,
OPCODE_HVCTRL_W,
OPCODE_OPCODE_VCONN_ILIM_R = 0x13,
OPCODE_OPCODE_VCONN_ILIM_W,
OPCODE_CHGIN_ILIM_R = 0x15,
OPCODE_CHGIN_ILIM_W,
OPCODE_CHGIN_ILIM2_R,
OPCODE_CHGIN_ILIM2_W,
OPCODE_CTRLREG_INIT_R = 0x1A,
OPCODE_CTRLREG_INIT_W,
OPCODE_AFC_HV_W = 0x20,
OPCODE_AFC_RESULT_R,
OPCODE_QC2P0_SET = 0x22,
OPCODE_READ_SBU = 0x25,
OPCODE_CURRENT_SRCCAP = 0x30,
OPCODE_GET_SRCCAP = 0x31,
OPCODE_SRCCAP_REQUEST = 0x32,
OPCODE_SET_SRCCAP = 0x33,
OPCODE_SEND_GET_REQUEST = 0x34,
OPCODE_READ_RESPONSE_FOR_GET_REQUEST = 0x35,
OPCODE_SEND_GET_RESPONSE = 0x36,
OPCODE_SWAP_REQUEST = 0x37,
OPCODE_SWAP_REQUEST_RESPONSE = 0x38,
OPCODE_VDM_DISCOVER_IDENETITY_RESPONSE = 0x40,
OPCODE_VDM_DISCOVER_SET_VDM_REQ = 0x48,
OPCODE_VDM_DISCOVER_GET_VDM_RESP = 0x4b,
OPCODE_SEND_VDM_AFC3P0_COMMAND,
OPCODE_GET_PD_MESSAGE,
OPCODE_SAMSUNG_ACC_COMMAND_RECIEVED,
OPCODE_SAMSUNG_ACC_COMMAND_RESPOND,
OPCODE_SAMSUNG_SECURE_KEY_REVOCATION,
OPCODE_SAMSUNG_FW_AUTOIBUS = 0x57,
OPCODE_READ_SELFTEST = 0x59,
OPCODE_GRL_COMMAND = 0x70,
OPCODE_RAM_TEST_COMMAND = 0xD1,
OPCODE_NONE = 0xff,
} max77705_opcode_list;
typedef enum{
OPCODE_ID_VDM_DISCOVER_IDENTITY = 0x1,
OPCODE_ID_VDM_DISCOVER_SVIDS = 0x2,
OPCODE_ID_VDM_DISCOVER_MODES = 0x3,
OPCODE_ID_VDM_ENTER_MODE = 0x4,
OPCODE_ID_VDM_EXIT_MODE = 0x5,
OPCODE_ID_VDM_ATTENTION = 0x6,
OPCODE_ID_VDM_SVID_DP_STATUS = 0x10,
OPCODE_ID_VDM_SVID_DP_CONFIGURE = 0x11,
} max77705_vdm_list;
typedef enum {
OPCODE_WAIT_START = 0,
OPCODE_WAIT_END,
} max77705_opcode_wait_type;
typedef enum {
OPCODE_NOTI_START = 0x0,
OPCODE_NOTI_NONE = 0xff,
} max77705_opcode_noti_cmd;
/* SAMSUNG OPCODE */
#define REG_NONE 0xff
#define CCIC_IRQ_INIT_DETECT (-1)
#endif
|