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
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Type-C control logic source */
#include "tcpm/tcpm.h"
#include "usbc_ocp.h"
#include "usbc_ppc.h"
void typec_set_polarity(int port, enum tcpc_cc_polarity polarity)
{
tcpm_set_polarity(port, polarity);
if (IS_ENABLED(CONFIG_USBC_PPC_POLARITY))
ppc_set_polarity(port, polarity);
}
void typec_set_sbu(int port, bool enable)
{
if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
ppc_set_sbu(port, enable);
#ifdef CONFIG_USB_PD_TCPM_SBU
tcpc_set_sbu(port, enable);
#endif
}
__overridable void typec_set_source_current_limit(int port,
enum tcpc_rp_value rp)
{
if (IS_ENABLED(CONFIG_USBC_PPC))
ppc_set_vbus_source_current_limit(port, rp);
}
void typec_set_vconn(int port, bool enable)
{
if (!IS_ENABLED(CONFIG_USBC_VCONN))
return;
/*
* Check our OC event counter. If we've exceeded our threshold, then
* let's latch our source path off to prevent continuous cycling. When
* the PD state machine detects a disconnection on the CC lines, we will
* reset our OC event counter.
*/
if (IS_ENABLED(CONFIG_USBC_OCP) && enable &&
usbc_ocp_is_port_latched_off(port))
return;
/*
* Disable PPC Vconn first then TCPC in case the voltage feeds back
* to TCPC and damages.
*/
if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && !enable)
ppc_set_vconn(port, false);
/*
* Some TCPCs/PPC combinations can trigger OVP if the TCPC doesn't
* source VCONN. This happens if the TCPC will trip OVP with 5V, and the
* PPC doesn't isolate the TCPC from VCONN when sourcing. But, some PPCs
* which do isolate the TCPC can't handle 5V on its host-side CC pins,
* so the TCPC shouldn't source VCONN in those cases.
*
* In the first case, both TCPC and PPC will potentially source Vconn,
* but that should be okay since Vconn has "make before break"
* electrical requirements when swapping anyway.
*
* See b/72961003 and b/180973460
*/
tcpm_set_vconn(port, enable);
if (IS_ENABLED(CONFIG_USBC_PPC_VCONN) && enable)
ppc_set_vconn(port, true);
}
|