Revert "Don't measure CC lines twice" This reverts commit 248085cfe30a7dcf2ae819173604a0ae869c5612. It appears that my M1 mini running some ancient firmware insist on requiring the double checking, and displays the following syndrome: P0: S: DISCONNECTED P0: Poll: cc1=2 cc2=0 P0: Connected: cc1=1 cc2=2 P0: Polarity: CC2 (flipped) The first read of the CC lines reports something that is completely wrong, while the second one behaves correctly. My other machines don't behave like this at all. Until the problem is undertood, let's go back to the original code. Signed-off-by: Marc Zyngier <maz@kernel.org>
diff --git a/vdmtool.c b/vdmtool.c index 18344d7..91411e0 100644 --- a/vdmtool.c +++ b/vdmtool.c
@@ -32,7 +32,6 @@ bool vdm_escape; bool cc_line; uint8_t serial_pin_set; - uint8_t version; }; static struct vdm_context vdm_contexts[CONFIG_USB_PD_PORT_COUNT]; @@ -88,16 +87,16 @@ fusb302_tcpm_transmit(PORT(cxt), TCPC_TX_SOP_DEBUG_PRIME_PRIME, hdr, &x); } -static void evt_dfpconnect(struct vdm_context *cxt, int16_t cc1, int16_t cc2) +static void evt_dfpconnect(struct vdm_context *cxt) { - int ms = 200; - + int16_t cc1 = -1, cc2 = -1; + fusb302_tcpm_get_cc(PORT(cxt), &cc1, &cc2); cprintf(cxt, "Connected: cc1=%d cc2=%d\n", cc1, cc2); + if (cc1 < 2 && cc2 < 2) { + cprintf(cxt, "Nope.\n"); + return; + } - /* The original FUSB302 needs a bit longer... */ - if ((cxt->version & 0xf0) < 0x90) - ms += 300; - sleep_ms(ms); fusb302_tcpm_set_vconn(PORT(cxt), 0); fusb302_pd_reset(PORT(cxt)); @@ -579,7 +578,8 @@ fusb302_tcpm_get_cc(PORT(cxt), &cc1, &cc2); dprintf(cxt, "Poll: cc1=%d cc2=%d\n", (int)cc1, (int)cc2); if (cc1 >= 2 || cc2 >= 2) { - evt_dfpconnect(cxt, cc1, cc2); + sleep_ms(500); + evt_dfpconnect(cxt); } else { vbus_off(cxt); } @@ -685,8 +685,6 @@ cprintf(cxt, "Device ID: %c_rev%c (0x%x)\n", 'A' + ((reg >> 4) & 0x7), 'A' + (reg & 3), reg); - cxt->version = reg & 0xff; - cprintf(cxt, "Init\n"); fusb302_tcpm_init(PORT(cxt));