summaryrefslogtreecommitdiff
path: root/include/usb_pe_sm.h
blob: 3e53d17690abc095094a249d8d8aa0d1ecba087b (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
/* Copyright 2019 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* USB Policy Engine module */

#ifndef __CROS_EC_USB_PE_H
#define __CROS_EC_USB_PE_H

#include "usb_sm.h"

/* Policy Engine Receive and Transmit Errors */
enum pe_error {
	ERR_RCH_CHUNKED,
	ERR_RCH_MSG_REC,
	ERR_TCH_CHUNKED,
	ERR_TCH_XMIT,
};

/*
 * Device Policy Manager Requests.
 * NOTE: These are usually set by host commands from the AP.
 */
enum pe_dpm_request {
	DPM_REQUEST_DR_SWAP             = BIT(0),
	DPM_REQUEST_PR_SWAP             = BIT(1),
	DPM_REQUEST_VCONN_SWAP          = BIT(2),
	DPM_REQUEST_GOTO_MIN            = BIT(3),
	DPM_REQUEST_SRC_CAP_CHANGE      = BIT(4),
	DPM_REQUEST_GET_SNK_CAPS        = BIT(5),
	DPM_REQUEST_SEND_PING           = BIT(6),
	DPM_REQUEST_SOURCE_CAP          = BIT(7),
	DPM_REQUEST_NEW_POWER_LEVEL     = BIT(8),
	DPM_REQUEST_DISCOVER_IDENTITY   = BIT(9),
	DPM_REQUEST_EXIT_DP_MODE        = BIT(10),
	DPM_REQUEST_SVDM                = BIT(11),
};

/**
 * Runs the Policy Engine State Machine
 *
 * @param port USB-C port number
 * @param evt  system event, ie: PD_EVENT_RX
 * @param en   0 to disable the machine, 1 to enable the machine
 */
void pe_run(int port, int evt, int en);

/**
 * Informs the Policy Engine that a message was successfully sent
 *
 * @param port USB-C port number
 */
void pe_message_sent(int port);

/**
 * Informs the Policy Engine of an error.
 *
 * @param port USB-C port number
 * @param  e    error
 */
void pe_report_error(int port, enum pe_error e);

/**
 * Called by the Protocol Layer to informs the Policy Engine
 * that a message has been received.
 *
 * @param port USB-C port number
 */
void pe_message_received(int port);

/**
 * Informs the Policy Engine that a hard reset was received.
 *
 * @param port USB-C port number
 */
void pe_got_hard_reset(int port);

/**
 * Informs the Policy Engine that a soft reset was received.
 *
 * @param port USB-C port number
 */
void pe_got_soft_reset(int port);

/**
 * Informs the Policy Engine that a hard reset was sent.
 *
 * @param port USB-C port number
 */
void pe_hard_reset_sent(int port);

/**
 * Informs the Policy Engine that a Fast Role Swap signal was detected
 *
 * @param port USB-C port number
 */
void pe_got_frs_signal(int port);

/**
 * Exit DP mode
 *
 * @param port USB-C port number
 */
void pe_exit_dp_mode(int port);

/**
 * Get the id of the current Policy Engine state
 *
 * @param port USB-C port number
 */
enum pe_states pe_get_state_id(int port);

/**
 * Indicates if the Policy Engine State Machine is running.
 *
 * @param port USB-C port number
 * @return 1 if policy engine state machine is running, else 0
 */
int pe_is_running(int port);

/**
 * Informs the Policy Engine that the Power Supply is at it's default state
 *
 * @param port USB-C port number
 */
void pe_ps_reset_complete(int port);

/**
 * Informs the Policy Engine that a VCONN Swap has completed
 *
 * @param port USB-C port number
 */
void pe_vconn_swap_complete(int port);

/**
 * Instructs the Policy Engine to send a Vendor Defined Message
 *
 * @param port  USB-C port number
 * @param vid   Vendor ID
 * @param cmd   Vendor Defined Command
 * @param data  Vendor Defined Data
 * @param count Size of Vendor Defined Data in 32-bit objects
 */
void pe_send_vdm(int port, uint32_t vid, int cmd, const uint32_t *data,
				int count);

/**
 * Indicates if an explicit contract is in place
 *
 * @param port  USB-C port number
 * @return 1 if an explicit contract is in place, else 0
 */
int pe_is_explicit_contract(int port);

/**
 * Instruct the Policy Engine to perform a Device Policy Manager Request
 * This function is called from the Device Policy Manager and only has effect
 * if the current Policy Engine state is Src.Ready or Snk.Ready.
 *
 * @param port  USB-C port number
 * @param req   Device Policy Manager Request
 */
void pe_dpm_request(int port, enum pe_dpm_request req);

/*
 * Return true if port partner is dualrole capable
 *
 * @param port  USB-C port number
 */
int pd_is_port_partner_dualrole(int port);

#endif /* __CROS_EC_USB_PE_H */