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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
/* 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.
*/
/* Gingerbread board-specific configuration */
#include "common.h"
#include "cros_board_info.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/stm32gx.h"
#include "driver/tcpm/tcpci.h"
#include "driver/usb_mux/tusb1064.h"
#include "ec_version.h"
#include "gpio.h"
#include "hooks.h"
#include "mp4245.h"
#include "switch.h"
#include "system.h"
#include "task.h"
#include "timer.h"
#include "uart.h"
#include "usb_descriptor.h"
#include "usb_pd.h"
#include "usbc_ppc.h"
#include "usb_descriptor.h"
#include "usb_pd_dp_ufp.h"
#include "usb_pe_sm.h"
#include "usb_prl_sm.h"
#include "usb_tc_sm.h"
#include "util.h"
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
#define QUICHE_PD_DEBUG_LVL 1
#ifdef SECTION_IS_RW
#define CROS_EC_SECTION "RW"
#else
#define CROS_EC_SECTION "RO"
#endif
#ifdef SECTION_IS_RW
/*
* C1 port on gingerbread does not have a PPC. However, C0 port does have a PPC
* and therefore PPC related config options are defined. Defining a null driver
* here so that functions from usbc_ppc.c will correctly dereference to a NULL
* function pointer.
*/
const struct ppc_drv board_ppc_null_drv = {};
static int pd_dual_role_init[CONFIG_USB_PD_PORT_MAX_COUNT] = {
PD_DRP_TOGGLE_ON,
PD_DRP_FORCE_SOURCE,
};
static void ppc_interrupt(enum gpio_signal signal)
{
switch (signal) {
case GPIO_HOST_USBC_PPC_INT_ODL:
sn5s330_interrupt(USB_PD_PORT_HOST);
break;
default:
break;
}
}
static void tcpc_alert_event(enum gpio_signal s)
{
int port = -1;
switch (s) {
case GPIO_USBC_DP_MUX_ALERT_ODL:
port = USB_PD_PORT_DP;
break;
default:
return;
}
schedule_deferred_pd_interrupt(port);
}
void hpd_interrupt(enum gpio_signal signal)
{
usb_pd_hpd_edge_event(signal);
}
static void board_pwr_btn_interrupt(enum gpio_signal signal)
{
baseboard_power_button_evt(gpio_get_level(signal));
}
#endif /* SECTION_IS_RW */
#include "gpio_list.h" /* Must come after other header files. */
/*
* Table GPIO signals control both power rails and reset lines to various chips
* on the board. The order the signals are changed and the delay between GPIO
* signals is driven by USB/MST hub power sequencing requirements.
*/
const struct power_seq board_power_seq[] = {
{ GPIO_EN_AC_JACK, 1, 20 },
{ GPIO_EN_PP5000_A, 1, 31 },
{ GPIO_EN_PP3300_A, 1, 135 },
{ GPIO_EN_BB, 1, 30 },
{ GPIO_EN_PP1100_A, 1, 30 },
{ GPIO_EN_PP1000_A, 1, 20 },
{ GPIO_EN_PP1050_A, 1, 30 },
{ GPIO_EN_PP1200_A, 1, 20 },
{ GPIO_EN_PP5000_HSPORT, 1, 31 },
{ GPIO_EN_DP_SINK, 1, 80 },
{ GPIO_MST_LP_CTL_L, 1, 80 },
{ GPIO_MST_RST_L, 1, 41 },
{ GPIO_EC_HUB1_RESET_L, 1, 41 },
{ GPIO_EC_HUB2_RESET_L, 1, 33 },
{ GPIO_USBC_DP_PD_RST_L, 1, 100 },
{ GPIO_USBC_UF_RESET_L, 1, 33 },
{ GPIO_DEMUX_DUAL_DP_PD_N, 1, 100 },
{ GPIO_DEMUX_DUAL_DP_RESET_N, 1, 100 },
{ GPIO_DEMUX_DP_HDMI_PD_N, 1, 10 },
{ GPIO_DEMUX_DUAL_DP_MODE, 1, 10 },
{ GPIO_DEMUX_DP_HDMI_MODE, 1, 1 },
};
const size_t board_power_seq_count = ARRAY_SIZE(board_power_seq);
/*
* Define the strings used in our USB descriptors.
*/
const void *const usb_strings[] = {
[USB_STR_DESC] = usb_string_desc,
[USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
[USB_STR_PRODUCT] = USB_STRING_DESC("Gingerbread"),
[USB_STR_SERIALNO] = 0,
[USB_STR_VERSION] =
USB_STRING_DESC(CROS_EC_SECTION ":" CROS_EC_VERSION32),
[USB_STR_UPDATE_NAME] = USB_STRING_DESC("Firmware update"),
};
BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
#ifndef SECTION_IS_RW
/* USB-C PPC Configuration */
struct ppc_config_t ppc_chips[] = {
[USB_PD_PORT_HOST] = {
.i2c_port = I2C_PORT_I2C3,
.i2c_addr_flags = SN5S330_ADDR0_FLAGS,
},
};
#endif
#ifdef SECTION_IS_RW
/* TUSB1064 set mux board tuning for DP Rx path */
static int board_tusb1064_dp_rx_eq_set(const struct usb_mux *me,
mux_state_t mux_state)
{
int rv = EC_SUCCESS;
/* DP specific config */
if (mux_state & USB_PD_MUX_DP_ENABLED)
rv = tusb1064_set_dp_rx_eq(me, TUSB1064_DP_EQ_RX_8_9_DB);
return rv;
}
/*
* TCPCs: 2 USBC/PD ports
* port 0 -> host port -> STM32G4 UCPD
* port 1 -> user data/display port -> PS8805
*/
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
{
.bus_type = EC_BUS_TYPE_EMBEDDED,
.drv = &stm32gx_tcpm_drv,
},
{
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_I2C3,
.addr_flags = PS8XXX_I2C_ADDR2_FLAGS,
},
.drv = &ps8xxx_tcpm_drv,
},
};
const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
[USB_PD_PORT_HOST] = {
.usb_port = USB_PD_PORT_HOST,
.i2c_port = I2C_PORT_I2C1,
.i2c_addr_flags = TUSB1064_I2C_ADDR0_FLAGS,
.driver = &tusb1064_usb_mux_driver,
.board_set = &board_tusb1064_dp_rx_eq_set,
},
[USB_PD_PORT_DP] = {
.usb_port = USB_PD_PORT_DP,
.i2c_port = I2C_PORT_I2C3,
.i2c_addr_flags = PS8XXX_I2C_ADDR2_FLAGS,
.driver = &tcpci_tcpm_usb_mux_driver,
.hpd_update = &ps8xxx_tcpc_update_hpd_status,
},
};
/* USB-C PPC Configuration */
struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = {
[USB_PD_PORT_HOST] = { .i2c_port = I2C_PORT_I2C3,
.i2c_addr_flags = SN5S330_ADDR0_FLAGS,
.drv = &sn5s330_drv },
[USB_PD_PORT_DP] = { .drv = &board_ppc_null_drv },
};
unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
const struct hpd_to_pd_config_t hpd_config = {
.port = USB_PD_PORT_HOST,
.signal = GPIO_DDI_MST_IN_HPD,
};
void board_reset_pd_mcu(void)
{
cprints(CC_SYSTEM, "Resetting TCPCs...");
cflush();
/*
* Reset all TCPCs.
* C0 -> ucpd (on chip TCPC)
* C1 -> PS8805 TCPC -> USBC_DP_PD_RST_L
* C2 -> PS8803 TCPC -> USBC_UF_RESET_L
*/
gpio_set_level(GPIO_USBC_DP_PD_RST_L, 0);
gpio_set_level(GPIO_USBC_UF_RESET_L, 0);
msleep(PS8805_FW_INIT_DELAY_MS);
gpio_set_level(GPIO_USBC_DP_PD_RST_L, 1);
gpio_set_level(GPIO_USBC_UF_RESET_L, 1);
msleep(PS8805_FW_INIT_DELAY_MS);
}
/* Power Delivery and charging functions */
void board_enable_usbc_interrupts(void)
{
board_reset_pd_mcu();
/* Enable PPC interrupts. */
gpio_enable_interrupt(GPIO_HOST_USBC_PPC_INT_ODL);
/* Enable TCPC interrupts. */
gpio_enable_interrupt(GPIO_USBC_DP_MUX_ALERT_ODL);
/* Enable HPD interrupt */
gpio_enable_interrupt(GPIO_DDI_MST_IN_HPD);
}
/* Power Delivery and charging functions */
void board_disable_usbc_interrupts(void)
{
/* Disable PPC interrupts. */
gpio_disable_interrupt(GPIO_HOST_USBC_PPC_INT_ODL);
/* Disable TCPC interrupts. */
gpio_disable_interrupt(GPIO_USBC_DP_MUX_ALERT_ODL);
/* Disable HPD interrupt */
gpio_disable_interrupt(GPIO_DDI_MST_IN_HPD);
}
void board_tcpc_init(void)
{
board_reset_pd_mcu();
/* Enable board usbc interrupts */
board_enable_usbc_interrupts();
}
DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 2);
enum pd_dual_role_states board_tc_get_initial_drp_mode(int port)
{
return pd_dual_role_init[port];
}
int ppc_get_alert_status(int port)
{
if (port == USB_PD_PORT_HOST)
return gpio_get_level(GPIO_HOST_USBC_PPC_INT_ODL) == 0;
return 0;
}
uint16_t tcpc_get_alert_status(void)
{
uint16_t status = 0;
if (!gpio_get_level(GPIO_USBC_DP_MUX_ALERT_ODL) &&
gpio_get_level(GPIO_USBC_DP_PD_RST_L))
status |= PD_STATUS_TCPC_ALERT_1;
return status;
}
void board_overcurrent_event(int port, int is_overcurrented)
{
/* TODO: b/ - check correct operation for honeybuns */
}
int dock_get_mf_preference(void)
{
int rv;
uint32_t fw_config;
int mf = MF_OFF;
/*
* MF (multi function) preferece is indicated by bit 0 of the fw_config
* data field. If this data field does not exist, then default to 4 lane
* mode.
*/
rv = cbi_get_fw_config(&fw_config);
if (!rv)
mf = CBI_FW_MF_PREFERENCE(fw_config);
return mf;
}
static void board_usb_tc_connect(void)
{
int port = TASK_ID_TO_PD_PORT(task_get_current());
/*
* The EC needs to keep the USB hubs in reset until the host port is
* attached so that the USB-EP can be properly enumerated.
*/
if (port == USB_PD_PORT_HOST) {
gpio_set_level(GPIO_EC_HUB1_RESET_L, 1);
gpio_set_level(GPIO_EC_HUB2_RESET_L, 1);
}
}
DECLARE_HOOK(HOOK_USB_PD_CONNECT, board_usb_tc_connect, HOOK_PRIO_DEFAULT);
static void board_usb_tc_disconnect(void)
{
int port = TASK_ID_TO_PD_PORT(task_get_current());
/* Only the host port disconnect is relevant */
if (port == USB_PD_PORT_HOST) {
gpio_set_level(GPIO_EC_HUB1_RESET_L, 0);
gpio_set_level(GPIO_EC_HUB2_RESET_L, 0);
}
}
DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, board_usb_tc_disconnect,
HOOK_PRIO_DEFAULT);
#endif /* SECTION_IS_RW */
static void board_init(void)
{
#ifdef SECTION_IS_RW
/*
* Set current limit for USB 3.1 Gen 2 ports to 1.5 A. Note, this is
* also done in gpio.inc, but needs to be in RW for platforms which
* shipped with RO that set these 2 lines to the 900 mA level.
*/
gpio_set_level(GPIO_USB3_P3_CDP_EN, 1);
gpio_set_level(GPIO_USB3_P4_CDP_EN, 1);
#endif
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
static void board_debug_gpio_1_pulse(void)
{
gpio_set_level(GPIO_TRIGGER_1, 0);
}
DECLARE_DEFERRED(board_debug_gpio_1_pulse);
static void board_debug_gpio_2_pulse(void)
{
gpio_set_level(GPIO_TRIGGER_2, 0);
}
DECLARE_DEFERRED(board_debug_gpio_2_pulse);
void board_debug_gpio(enum debug_gpio trigger, int level, int pulse_usec)
{
switch (trigger) {
case TRIGGER_1:
gpio_set_level(GPIO_TRIGGER_1, level);
if (pulse_usec)
hook_call_deferred(&board_debug_gpio_1_pulse_data,
pulse_usec);
break;
case TRIGGER_2:
gpio_set_level(GPIO_TRIGGER_2, level);
if (pulse_usec)
hook_call_deferred(&board_debug_gpio_2_pulse_data,
pulse_usec);
break;
default:
CPRINTS("bad debug gpio selection");
break;
}
}
|