summaryrefslogtreecommitdiff
path: root/common/mock/usb_tc_sm_mock.c
blob: aea8076f0976e29d759a295daf162cd0be6f29a8 (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
/* Copyright 2020 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.
 */

/* Mock USB TC state machine */

#include "common.h"
#include "console.h"
#include "usb_tc_sm.h"
#include "mock/usb_tc_sm_mock.h"
#include "memory.h"

#ifndef CONFIG_COMMON_RUNTIME
#define cprints(format, args...)
#endif

struct mock_tc_port_t mock_tc_port[CONFIG_USB_PD_PORT_MAX_COUNT];

void mock_tc_port_reset(void)
{
	int port;

	for (port = 0 ; port < CONFIG_USB_PD_PORT_MAX_COUNT ; ++port) {
		mock_tc_port[port].rev = PD_REV30;
		mock_tc_port[port].pd_enable = 0;
		mock_tc_port[port].power_role = PD_ROLE_SINK;
		mock_tc_port[port].data_role = PD_ROLE_DISCONNECTED;
		mock_tc_port[port].msg_tx_id = 0;
		mock_tc_port[port].msg_rx_id = 0;
		mock_tc_port[port].sop = TCPC_TX_INVALID;
		mock_tc_port[port].lcl_rp = TYPEC_RP_RESERVED;
		mock_tc_port[port].attached_snk = 0;
		mock_tc_port[port].attached_src = 0;
	}
}

enum pd_cable_plug tc_get_cable_plug(int port)
{
	return PD_PLUG_FROM_DFP_UFP;
}

uint8_t tc_get_pd_enabled(int port)
{
	return mock_tc_port[port].pd_enable;
}

void typec_select_src_collision_rp(int port, enum tcpc_rp_value rp)
{
	mock_tc_port[port].lcl_rp = rp;
}

int tc_is_attached_src(int port)
{
	return mock_tc_port[port].attached_src;
}

int tc_is_attached_snk(int port)
{
	return mock_tc_port[port].attached_snk;
}

void tc_prs_snk_src_assert_rp(int port)
{
	mock_tc_port[port].attached_snk = 0;
	mock_tc_port[port].attached_src = 1;
}

void tc_prs_src_snk_assert_rd(int port)
{
	mock_tc_port[port].attached_snk = 1;
	mock_tc_port[port].attached_src = 0;
}

int typec_update_cc(int port)
{
	return EC_SUCCESS;
}

void tc_set_data_role(int port, enum pd_data_role role)
{
	mock_tc_port[port].data_role = role;
}

void tc_set_power_role(int port, enum pd_power_role role)
{
	mock_tc_port[port].power_role = role;
}

int tc_check_vconn_swap(int port)
{
	return 0;
}

void tc_ctvpd_detected(int port)
{}

int tc_is_vconn_src(int port)
{
	return 0;
}

void tc_hard_reset_request(int port)
{
	mock_tc_port_reset();
}

void tc_partner_dr_data(int port, int en)
{}

void tc_partner_dr_power(int port, int en)
{}

void tc_partner_unconstrainedpower(int port, int en)
{}

void tc_partner_usb_comm(int port, int en)
{}

void tc_pd_connection(int port, int en)
{}

void tc_pr_swap_complete(int port, bool success)
{}

void tc_src_power_off(int port)
{}

void tc_start_error_recovery(int port)
{}

void tc_snk_power_off(int port)
{}

void tc_request_power_swap(int port)
{
}