summaryrefslogtreecommitdiff
path: root/baseboard/ite_evb/usb_pd_policy.c
blob: 71af9d2b1c83bc7d8a88cc4a2c8000ef328999db (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
/* Copyright 2020 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Shared USB-C policy for ite_evb baseboard */

#include "adc.h"
#include "config.h"
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "it83xx_pd.h"
#include "registers.h"
#include "system.h"
#include "task.h"
#include "timer.h"
#include "util.h"
#include "usb_mux.h"
#include "usb_pd_pdo.h"

#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ##args)
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ##args)

int pd_is_max_request_allowed(void)
{
	/* Max voltage request allowed */
	return 1;
}

int pd_snk_is_vbus_provided(int port)
{
	int mv = ADC_READ_ERROR;

	switch (port) {
	case USBPD_PORT_A:
		mv = adc_read_channel(ADC_VBUSSA);
		break;
	case USBPD_PORT_B:
		mv = adc_read_channel(ADC_VBUSSB);
		break;
	case USBPD_PORT_C:
		mv = adc_read_channel(ADC_VBUSSC);
		break;
	}

	return mv > PD_VBUS_PROVIDED_THRESHOLD;
}

int pd_set_power_supply_ready(int port)
{
	/* Provide VBUS */
	board_pd_vbus_ctrl(port, 1);
	/* Vbus provided or not */
	return !pd_snk_is_vbus_provided(port);
}

void pd_power_supply_reset(int port)
{
	/* Kill VBUS */
	board_pd_vbus_ctrl(port, 0);
}

__override int pd_check_data_swap(int port, enum pd_data_role data_role)
{
	/* Always allow data swap: we can be DFP or UFP for USB */
	return 1;
}

int pd_check_vconn_swap(int port)
{
	/*
	 * VCONN is provided directly by the battery(PPVAR_SYS)
	 * but use the same rules as power swap
	 */
	return pd_get_dual_role(port) == PD_DRP_TOGGLE_ON ? 1 : 0;
}

/* ----------------- Vendor Defined Messages ------------------ */
/*
 * We don't have mux on pd evb and not define CONFIG_USBC_SS_MUX,
 * so mux related functions do nothing then return.
 */
__override int svdm_enter_dp_mode(int port, uint32_t mode_caps)
{
	/*
	 * Do not enter dp mode, we let VDM enumeration stop after discover
	 * modes have done.
	 */
	return -1;
}

__override void svdm_dp_post_config(int port)
{
}

__override int svdm_dp_attention(int port, uint32_t *payload)
{
	/* Ack */
	return 1;
}

__override void svdm_exit_dp_mode(int port)
{
}

__override int pd_custom_vdm(int port, int cnt, uint32_t *payload,
			     uint32_t **rpayload)
{
	/* Return length 0, means nothing needn't tx */
	return 0;
}

__override int svdm_dp_config(int port, uint32_t *payload)
{
	/* Return length 0, means nothing needn't tx */
	return 0;
};