4
4
#include <console/console.h>
5
5
#include <delay.h>
6
6
#include <device/usbc_mux.h>
7
+ #include <intelblocks/tcss.h>
8
+ #include <timer.h>
7
9
#include <types.h>
8
10
9
11
#define CMD_USBC_MUX_INFO 23
@@ -46,7 +48,30 @@ static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
46
48
info -> hpd_irq = !!(flags & USBC_MUX_HPD_IRQ );
47
49
info -> ufp = !!(flags & USBC_MUX_UFP );
48
50
info -> dbg_acc = !!(flags & USBC_MUX_DBG_ACC );
49
- info -> dp_pin_mode = pin_mode ;
51
+
52
+ switch (pin_mode ) {
53
+ case 1 :
54
+ info -> dp_pin_mode = MODE_DP_PIN_A ;
55
+ break ;
56
+ case 2 :
57
+ info -> dp_pin_mode = MODE_DP_PIN_B ;
58
+ break ;
59
+ case 3 :
60
+ info -> dp_pin_mode = MODE_DP_PIN_C ;
61
+ break ;
62
+ case 4 :
63
+ info -> dp_pin_mode = MODE_DP_PIN_D ;
64
+ break ;
65
+ case 5 :
66
+ info -> dp_pin_mode = MODE_DP_PIN_E ;
67
+ break ;
68
+ case 6 :
69
+ info -> dp_pin_mode = MODE_DP_PIN_F ;
70
+ break ;
71
+ default :
72
+ info -> dp_pin_mode = 0 ;
73
+ break ;
74
+ }
50
75
51
76
printk (BIOS_SPEW , "%s: dp=%u, usb=%u\n" , __func__ , info -> dp , info -> usb );
52
77
printk (BIOS_SPEW , "%s: cable=%u, polarity=%u\n" , __func__ , info -> cable , info -> polarity );
@@ -60,25 +85,57 @@ static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
60
85
static int system76_ec_wait_for_connection (long timeout_ms )
61
86
{
62
87
// TODO
63
- return 0 ;
88
+ return 1 ;
64
89
}
65
90
66
91
static int system76_ec_enter_dp_mode (int port )
67
92
{
68
93
// TODO
69
- return -1 ;
94
+ return 0 ;
70
95
}
71
96
72
97
static int system76_ec_wait_for_dp_mode_entry (int port , long timeout_ms )
73
98
{
74
- // TODO
75
- return -1 ;
99
+ struct usbc_mux_info info ;
100
+
101
+ if (system76_ec_get_mux_info (port , & info ) < 0 ) {
102
+ printk (BIOS_WARNING , "%s: could not get usbc mux info\n" , __func__ );
103
+ return -1 ;
104
+ }
105
+
106
+ if (!info .dp ) {
107
+ printk (BIOS_WARNING , "DP mode not ready\n" );
108
+ return -1 ;
109
+ }
110
+
111
+ return 0 ;
76
112
}
77
113
78
114
static int system76_ec_wait_for_hpd (int port , long timeout_ms )
79
115
{
80
- // TODO
81
- return -1 ;
116
+ struct usbc_mux_info info ;
117
+ struct stopwatch sw ;
118
+
119
+ stopwatch_init_msecs_expire (& sw , timeout_ms );
120
+ while (1 ) {
121
+ if (system76_ec_get_mux_info (port , & info ) < 0 ) {
122
+ printk (BIOS_WARNING , "%s: could not get usbc mux info\n" , __func__ );
123
+ return -1 ;
124
+ }
125
+
126
+ if (info .hpd_lvl )
127
+ break ;
128
+
129
+ if (stopwatch_expired (& sw )) {
130
+ printk (BIOS_WARNING , "HPD not ready after %ldms\n" , timeout_ms );
131
+ return -1 ;
132
+ }
133
+
134
+ mdelay (100 );
135
+ }
136
+
137
+ printk (BIOS_INFO , "HPD ready after %lldms\n" , stopwatch_duration_msecs (& sw ));
138
+ return 0 ;
82
139
}
83
140
84
141
static const struct usbc_ops system76_ec_usbc_ops = {
0 commit comments