|
4 | 4 | #include <console/console.h>
|
5 | 5 | #include <delay.h>
|
6 | 6 | #include <device/usbc_mux.h>
|
| 7 | +#include <timer.h> |
7 | 8 | #include <types.h>
|
8 | 9 |
|
9 | 10 | #define CMD_USBC_MUX_INFO 23
|
@@ -60,25 +61,57 @@ static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
|
60 | 61 | static int system76_ec_wait_for_connection(long timeout_ms)
|
61 | 62 | {
|
62 | 63 | // TODO
|
63 |
| - return 0; |
| 64 | + return 1; |
64 | 65 | }
|
65 | 66 |
|
66 | 67 | static int system76_ec_enter_dp_mode(int port)
|
67 | 68 | {
|
68 | 69 | // TODO
|
69 |
| - return -1; |
| 70 | + return 0; |
70 | 71 | }
|
71 | 72 |
|
72 | 73 | static int system76_ec_wait_for_dp_mode_entry(int port, long timeout_ms)
|
73 | 74 | {
|
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; |
76 | 88 | }
|
77 | 89 |
|
78 | 90 | static int system76_ec_wait_for_hpd(int port, long timeout_ms)
|
79 | 91 | {
|
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; |
82 | 115 | }
|
83 | 116 |
|
84 | 117 | static const struct usbc_ops system76_ec_usbc_ops = {
|
|
0 commit comments