44#include <console/console.h>
55#include <delay.h>
66#include <device/usbc_mux.h>
7+ #include <intelblocks/tcss.h>
8+ #include <timer.h>
79#include <types.h>
810
911#define CMD_USBC_MUX_INFO 23
@@ -46,7 +48,30 @@ static int system76_ec_get_mux_info(int port, struct usbc_mux_info *info)
4648 info -> hpd_irq = !!(flags & USBC_MUX_HPD_IRQ );
4749 info -> ufp = !!(flags & USBC_MUX_UFP );
4850 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+ }
5075
5176 printk (BIOS_SPEW , "%s: dp=%u, usb=%u\n" , __func__ , info -> dp , info -> usb );
5277 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)
6085static int system76_ec_wait_for_connection (long timeout_ms )
6186{
6287 // TODO
63- return 0 ;
88+ return 1 ;
6489}
6590
6691static int system76_ec_enter_dp_mode (int port )
6792{
6893 // TODO
69- return -1 ;
94+ return 0 ;
7095}
7196
7297static int system76_ec_wait_for_dp_mode_entry (int port , long timeout_ms )
7398{
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 ;
76112}
77113
78114static int system76_ec_wait_for_hpd (int port , long timeout_ms )
79115{
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 ;
82139}
83140
84141static const struct usbc_ops system76_ec_usbc_ops = {
0 commit comments