Received: by 2002:a05:6520:2586:b029:fa:41f3:c225 with SMTP id u6csp4269173lky; Tue, 15 Jun 2021 18:24:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXcqtGl8CweXU/MmmGE0S6AWFap4WIHGuAUtOlw4GGBZoElh7B5InV9g3uT+i6BDHWOW8J X-Received: by 2002:aa7:c68f:: with SMTP id n15mr1070525edq.145.1623806486035; Tue, 15 Jun 2021 18:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623806486; cv=none; d=google.com; s=arc-20160816; b=VCU7122qXa3oicctBP3CkY9EizE1uZs1p9mr7F6TrnS7ZvhnhEX4XOrt7Hbinrr5Mp OXT/3HpufkacgI6OI8O/c6wTJOf2AI8pc+dClVaoauEzGYynt+g1/b8rQGSjaj904N0+ Qi+lDkL4XKQhH90nMvf3UOwAsqmACEU8gp556icrBlxH4zIvDNPVS6nLDaKPIxEPDGJb rtX0qj1pDdOqN1nvhgifmWxWIovVS+kOoIBNBxahcA3i3GDLeI3G9PNF+iroWD+n5Z/E CcevL7gWYoXXeBDyf78o7oB+PN5tLjS9HzLlHCwGA2HHlhnl6hqeIpa2fyUPoO1rfGkj vs7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ArgsnqaZfbK1PmZFHo3aGB4ctcJO4bEDv0BIWr1Mhqo=; b=k9huzSDeMemJMq6ITzSJM3K4Gh3ZlvkD8tmN1qCig3R4IAspOq5d5XDtkEZqK0z4b2 l/OK4UQnPWJ6kufyuA9wiwWkLfPMHd3qva709WEGR5IRaiPBFufKCns45fJsQ7ctB5NS viCSAVrtVulj7kNa3HPJMen6nKJoJktWY7EeGh4wGmoMZsS7gx20EgZh3PmIxSBz0SRW RtUmwU0pvuK4LWjKRMbrDV7R2XF7X78j+ZciqDgduekkhWmhzHcKAModC5NAoa5zzGPW azZhICwY7YotpEHIElpk1y4gO2reVH91kRyFbSQiY1scXlZ7R6oTgkuGlzTsNLj+yp/U Da1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qM+dE4F9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b4si546000edr.197.2021.06.15.18.21.03; Tue, 15 Jun 2021 18:21:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qM+dE4F9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbhFPBTP (ORCPT + 99 others); Tue, 15 Jun 2021 21:19:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbhFPBTN (ORCPT ); Tue, 15 Jun 2021 21:19:13 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43C60C06175F for ; Tue, 15 Jun 2021 18:17:07 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id u20so646990qtx.1 for ; Tue, 15 Jun 2021 18:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ArgsnqaZfbK1PmZFHo3aGB4ctcJO4bEDv0BIWr1Mhqo=; b=qM+dE4F9/DjU/ahxr/CX4LfZaxeCQk+2hrHx0zpjXHeNrzNUMAaBq5JV+3PIzDlGEv 8T5f3bpmDhXjRL9R3rTq2wtJND8qHG2NurOY6x8aq39WQE3vVikqlFslgABThBVswD0e KPZd9tXgCkDVY53z+GQCsht4sGmUqVjGML7rOwWTc0slNSFsPVal72AXHGO39odAzi6y nT19fE5d14DjqScBxS91U6XO+Olob9UmFo7dpvRz7oEW7rZhM2USm7NEYTmA/m/4l9wO KxInis99dTPQlzEf9QGsyB7yKpjP0ppihqltIT0tGksbt0LrYKDNfLBi9zp76wmjcelH LSRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ArgsnqaZfbK1PmZFHo3aGB4ctcJO4bEDv0BIWr1Mhqo=; b=jlfbzOTQJWvy2bBxqlq3doZKhLuOeXdnePOt/RC5UcSjNvz9bYdsg6/soRUi83zSl6 TXFNmYAkYHi2V0UcTTNCKCGZ9PVtNZxDoY/hcLrU3zT1TVCsxPpSh7MkiT6xow5fcC7o TVjsPXEvyZM4gVygHlC1+EbkdfggCsQL35Adq7OegGj1vsuB4Dqg70rxIterkSwlOacO /YMYpEG2MXff5QOOFPT+XuuQlbSgbXOtc5GEyNTwH6WqQkVkZ5n2v9DDpJBRzMOcKNdg MEDiRkIG4shLVr2R1lVLidBYCo6Wt5I1WW03/qNYqhx0UzDLcHZM5n5kV1PGuVBPVtuQ 3WAw== X-Gm-Message-State: AOAM533xu32of6aJJpHXI/VKReWsarpfT5JAWZFPxl0IkTnx+NARz8Vf txfvw8d1Yqq5sEA4yIlJnXouKOBfhIewka/yUjWbYg== X-Received: by 2002:ac8:4e1b:: with SMTP id c27mr2576154qtw.22.1623806226037; Tue, 15 Jun 2021 18:17:06 -0700 (PDT) MIME-Version: 1.0 References: <20210615080817.1417169-1-kyletso@google.com> In-Reply-To: From: Kyle Tso Date: Wed, 16 Jun 2021 09:16:49 +0800 Message-ID: Subject: Re: [PATCH v2] usb: typec: tcpm: Relax disconnect threshold during power negotiation To: Badhri Jagan Sridharan Cc: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , USB , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 16, 2021 at 2:06 AM Badhri Jagan Sridharan wrote: > > On Tue, Jun 15, 2021 at 1:08 AM Kyle Tso wrote: > > > > If the voltage is being decreased in power negotiation, the Source will > > set the power supply to operate at the new voltage level before sending > > PS_RDY. For non-PPS negotiation, relax the disconnect threshold on Sink > > after receiving Accept Message to ensure the relaxed setting is enabled > > before the voltage collapse. For PPS, relax the threshold before > > sending Request Message so that it will not race with Source which > > begins to adjust the voltage right after it sends Accept Message. > > > > The real threshold will be set after Sink receives PS_RDY Message. > > > > Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") > > Cc: Badhri Jagan Sridharan > > Signed-off-by: Kyle Tso > > --- > > Changes since v1: > > - move the timing of setting threshold up to "before sending Request" > > for PPS power negotiation so that it won't race with the Source. > > - PPS: if it fails to send the Request, fallback to previous threshold > > - PPS: if the Source doesn't respond Accept, fallback to previous > > threshold > > - update the commit message for above changes > > > > drivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > > index 0db685d5d9c0..00f3fd7c05d6 100644 > > --- a/drivers/usb/typec/tcpm/tcpm.c > > +++ b/drivers/usb/typec/tcpm/tcpm.c > > @@ -2599,6 +2599,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, > > port->send_discover) > > port->vdm_sm_running = true; > > > > + /* Threshold was relaxed before sending Request. Restore it back. */ > > + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, > > + port->pps_data.active, > > + port->supply_voltage); > > + > > tcpm_set_state(port, SNK_READY, 0); > > break; > > case DR_SWAP_SEND: > > @@ -2646,6 +2651,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, > > switch (port->state) { > > case SNK_NEGOTIATE_CAPABILITIES: > > port->pps_data.active = false; > > + /* Voltage is going to be at new level. Relax the threshold here. */ > > + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, 0); > > tcpm_set_state(port, SNK_TRANSITION_SINK, 0); > > break; > > case SNK_NEGOTIATE_PPS_CAPABILITIES: > > @@ -3423,6 +3430,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port) > > if (ret < 0) > > return ret; > > > > + /* Relax the threshold as voltage will be adjusted right after Accept Message. */ > This makes sense. Shouldn't we have the same approach for > tcpm_pd_send_request as it's equally applicable for fixed RDO as well > ? > I don't think we need to do that because for the power negotiation using Fixed RDO, the voltage adjustment from Source side takes place after the time sending Accept Message plus tSrcTransition (25~35ms). So setting the threshold after the Sink gets Accept Message should be enough. thanks, Kyle > > + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, 0); > > + > > memset(&msg, 0, sizeof(msg)); > > msg.header = PD_HEADER_LE(PD_DATA_REQUEST, > > port->pwr_role, > > @@ -4196,6 +4206,10 @@ static void run_state_machine(struct tcpm_port *port) > > case SNK_NEGOTIATE_PPS_CAPABILITIES: > > ret = tcpm_pd_send_pps_request(port); > > if (ret < 0) { > > + /* Restore back to the original state */ > > + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, > > + port->pps_data.active, > > + port->supply_voltage); > > port->pps_status = ret; > > /* > > * If this was called due to updates to sink > > -- > > 2.32.0.272.g935e593368-goog > >