summaryrefslogtreecommitdiff
path: root/board/chocodile_vpdmcu/vpd_api.h
blob: df50f9200621621f55e1eb14a96eccd1b60fd089 (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
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Vconn Power Device API module */

#ifndef __CROS_EC_VPD_API_H
#define __CROS_EC_VPD_API_H

#include "adc.h"
#include "gpio.h"
#include "usb_pd.h"

enum vpd_pin {
	PIN_ADC,
	PIN_CMP,
	PIN_GPO
};

enum vpd_gpo {
	GPO_HZ,
	GPO_HIGH,
	GPO_LOW
};

enum vpd_pwr {
	PWR_VCONN,
	PWR_VBUS,
};

enum vpd_cc {
	CT_OPEN,
	CT_CC1,
	CT_CC2
};

enum vpd_billboard {
	BB_NONE,
	BB_SRC,
	BB_SNK
};

/**
 * Set Charge-Through Rp or Rd on CC lines
 *
 * @param pull      Either TYPEC_CC_RP or TYPEC_CC_RD
 * @param rp_value  When pull is RP, set this to
 *                  TYPEC_RP_USB or TYPEC_RP_1A5. Ignored
 *                  for TYPEC_CC_RD
 */
void vpd_ct_set_pull(int pull, int rp_value);

/**
 * Get the status of the Charge-Through CC lines
 *
 * @param cc1  Either TYPEC_CC_VOLT_OPEN,
 *		      TYPEC_CC_VOLT_RA,
 *                    TYPEC_CC_VOLT_RD,
 *                    any other value is considered RP
 * @param cc2  Either TYPEC_CC_VOLT_OPEN,
 *		      TYPEC_CC_VOLT_RA,
 *		      TYPEC_CC_VOLT_RD,
 *		      any other value is considered RP
 */
void vpd_ct_get_cc(int *cc1, int *cc2);

/**
 * Set Host Rp or Rd on CC lines
 *
 * @param pull      Either TYPEC_CC_RP or TYPEC_CC_RD
 * @param rp_value  When pull is RP, set this to
 *                  TYPEC_RP_USB or TYPEC_RP_1A5. Ignored
 *                  for TYPEC_CC_RD
 */
void vpd_host_set_pull(int pull, int rp_value);

/**
 * Get the status of the Host CC line
 *
 * @param cc  Either TYPEC_CC_VOLT_SNK_DEF, TYPEC_CC_VOLT_SNK_1_5,
 *                    TYPEC_CC_VOLT_SNK_3_0, or TYPEC_CC_RD
 */
void vpd_host_get_cc(int *cc);

/**
 * Set RX Enable flag
 *
 * @param en  1 for enable, 0 for disable
 */
void vpd_rx_enable(int en);

/**
 * Configure the cc_rp3a0_rd_l pin as ADC, CMP, or GPO
 *
 * @param cfg  PIN_ADC, PIN_CMP, or PIN_GPO
 * @param en   When cfg is PIN_GPO, 1 sets pin high
 *             and 0 sets pin low. Else ignored
 */
void vpd_config_cc_rp3a0_rd_l(enum vpd_pin cfg, int en);

/**
 * Configure the cc1_rp3a0_rd_l pin as ADC, CMP, or GPO
 *
 * @param cfg  PIN_ADC, PIN_CMP, or PIN_GPO
 * @param en   When cfg is PIN_GPO, 1 sets pin high
 *             and 0 sets pin low. Else ignored
 */
void vpd_config_cc1_rp3a0_rd_l(enum vpd_pin cfg, int en);

/**
 * Configure the cc2_rp3a0_rd_l pin as ADC, CMP, or GPO
 *
 * @param cfg  PIN_ADC, PIN_CMP, or PIN_GPO
 * @param en   When cfg is PIN_GPO, 1 sets pin high
 *             and 0 sets pin low. Else ignored
 */
void vpd_config_cc2_rp3a0_rd_l(enum vpd_pin cfg, int en);

/**
 * Configure the cc1_rpusb_odh pin as ADC, CMP, or GPO
 *
 * @param cfg  PIN_ADC, PIN_CMP, or PIN_GPO
 * @param en   When cfg is PIN_GPO, 1 sets pin high
 *             and 0 sets pin low. Else ignored
 */
void vpd_config_cc1_rpusb_odh(enum vpd_pin cfg, int en);

/**
 * Configure the cc2_rpusb_odh pin as ADC, CMP, or GPO
 *
 * @param cfg  PIN_ADC, PIN_CMP, or PIN_GPO
 * @param en   When cfg is PIN_GPO, 1 sets pin high
 *             and 0 sets pin low. Else ignored
 */
void vpd_config_cc2_rpusb_odh(enum vpd_pin cfg, int en);

/**
 * Configure the cc_db_en_od pin to High-Impedance, low, or high
 *
 * @param val  GPO_HZ, GPO_HIGH, GPO_LOW
 */
void vpd_cc_db_en_od(enum vpd_gpo val);

/**
 * Configure the cc_rpusb_odh pin to High-Impedance, low, or high
 *
 * @param val  GPO_HZ, GPO_HIGH, GPO_LOW
 */
void vpd_cc_rpusb_odh(enum vpd_gpo val);

/**
 * Configure the cc_rp1a5_odh pin to High-Impedance, low, or high
 *
 * @param val  GPO_HZ, GPO_HIGH, GPO_LOW
 */
void vpd_cc_rp1a5_odh(enum vpd_gpo val);

/**
 * Configure the cc1_cc2_db_en_l pin to High-Impedance, low, or high
 *
 * @param val  GPO_HZ, GPO_HIGH, GPO_LOW
 */
void vpd_cc1_cc2_db_en_l(enum vpd_gpo val);

/**
 * Get status of host vbus
 *
 * @return 1 if host vbus is present, else 0
 */
int vpd_is_host_vbus_present(void);

/**
 * Get status of charge-through vbus
 *
 * @return 1 if charge-through vbus is present, else 0
 */
int vpd_is_ct_vbus_present(void);

/**
 * Get status of vconn
 *
 * @return 1 if vconn is present, else 0
 */
int vpd_is_vconn_present(void);

/**
 * Read Host VBUS voltage. Range from 22000mV to 3000mV
 *
 * @return vbus voltage
 */
int vpd_read_host_vbus(void);

/**
 * Read Host CC voltage.
 *
 * @return cc voltage
 */
int vpd_read_cc_host(void);

/**
 * Read voltage on cc_vpdmcu pin
 *
 * @return cc_vpdmcu voltage
 */
int vpd_read_cc_vpdmcu(void);

/**
 * Read charge-through VBUS voltage. Range from 22000mV to 3000mV
 *
 * @return charge-through vbus voltage
 */
int vpd_read_ct_vbus(void);

/**
 * Read VCONN Voltage. Range from 5500mV to 3000mV
 *
 * @return vconn voltage
 */
int vpd_read_vconn(void);

/**
 * Turn ON/OFF Red LED. Should be off when performing power
 * measurements.
 *
 * @param on 0 turns LED off, any other value turns it ON
 */
void vpd_red_led(int on);

/**
 * Turn ON/OFF Green LED. Should be off when performing power
 * measurements.
 *
 * @param on 0 turns LED off, any other value turns it ON
 */
void vpd_green_led(int on);

/**
 * Connects/Disconnects the Host VBUS to the Charge-Through VBUS.
 *
 * @param en 0 disconnectes the VBUS, any other value connects VBUS.
 */
void vpd_vbus_pass_en(int en);

/**
 * Preset Billboard device
 *
 * @param bb  BB_NONE no billboard presented,
 *            BB_SRC source connected but not in charge-through
 *            BB_SNK sink connected
 */
void vpd_present_billboard(enum vpd_billboard bb);

/**
 * Enables the MCU to host cc communication
 *
 * @param en 1 enabled, 0 disabled
 */
void vpd_mcu_cc_en(int en);

/**
 * Selects which supply to power the VPD from
 *
 * @param en PWR_VCONN or PWR_VBUS
 */
void vpd_vconn_pwr_sel_odl(enum vpd_pwr en);

/**
 * Controls if the Charge-Through's CC1, CC2, or neither is
 * connected to Host CC
 *
 * @param sel CT_OPEN neither, CT_CC1 cc1, CT_CC2 cc2
 */
void vpd_ct_cc_sel(enum vpd_cc sel);

#endif /* __CROS_EC_VPD_API_H */