Skip to content

Commit 35c74fe

Browse files
committed
[WIP] ec/system76/ec: Implement USB-C DP HPD
Change-Id: I0487b761a5a83b0a1897c92416d0d81219303341 Signed-off-by: Tim Crawford <[email protected]>
1 parent 31549b2 commit 35c74fe

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/ec/system76/ec/usbc_mux.c

+39-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <console/console.h>
55
#include <delay.h>
66
#include <device/usbc_mux.h>
7+
#include <timer.h>
78
#include <types.h>
89

910
#define CMD_USBC_MUX_INFO 23
@@ -60,25 +61,57 @@ static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
6061
static int system76_ec_wait_for_connection(long timeout_ms)
6162
{
6263
// TODO
63-
return 0;
64+
return 1;
6465
}
6566

6667
static int system76_ec_enter_dp_mode(int port)
6768
{
6869
// TODO
69-
return -1;
70+
return 0;
7071
}
7172

7273
static int system76_ec_wait_for_dp_mode_entry(int port, long timeout_ms)
7374
{
74-
// TODO
75-
return -1;
75+
struct usbc_mux_info info;
76+
77+
if (system76_ec_get_mux_info(port, &info) < 0) {
78+
printk(BIOS_WARNING, "%s: could not get usbc mux info\n", __func__);
79+
return -1;
80+
}
81+
82+
if (!info.dp) {
83+
printk(BIOS_WARNING, "DP mode not ready\n");
84+
return -1;
85+
}
86+
87+
return 0;
7688
}
7789

7890
static int system76_ec_wait_for_hpd(int port, long timeout_ms)
7991
{
80-
// TODO
81-
return -1;
92+
struct usbc_mux_info info;
93+
struct stopwatch sw;
94+
95+
stopwatch_init_msecs_expire(&sw, timeout_ms);
96+
while (1) {
97+
if (system76_ec_get_mux_info(port, &info) < 0) {
98+
printk(BIOS_WARNING, "%s: could not get usbc mux info\n", __func__);
99+
return -1;
100+
}
101+
102+
if (info.hpd_lvl)
103+
break;
104+
105+
if (stopwatch_expired(&sw)) {
106+
printk(BIOS_WARNING, "HPD not ready after %ldms\n", timeout_ms);
107+
return -1;
108+
}
109+
110+
mdelay(100);
111+
}
112+
113+
printk(BIOS_INFO, "HPD ready after %lldms\n", stopwatch_duration_msecs(&sw));
114+
return 0;
82115
}
83116

84117
static const struct usbc_ops system76_ec_usbc_ops = {

0 commit comments

Comments
 (0)