Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp44480pxj; Wed, 16 Jun 2021 19:49:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKmok4KdNc72AcCqnvMMQc9vD7F3EPA7vo7vhZ8/WdKj6AeZcOrVsbTS1h+qv7Pf4JlFw2 X-Received: by 2002:a17:906:dbd8:: with SMTP id yc24mr2654993ejb.55.1623898194859; Wed, 16 Jun 2021 19:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623898194; cv=none; d=google.com; s=arc-20160816; b=qViZZrx759Vqr3on1y8neqUjhRRe5dxjM/J2mKcEpu9litnkljYyeq1BlW6V/5nDH7 21EZlZZ7dwj08If2W42khIXWvQotBmMLHCfSO2uW6k1+3hbyZvgwW4gBQYu+X91jRfCl 7EX36NYbnotZ0MRx/1qZa7MbUvWeWM0G6nTiet6AYMcQYobLZgGPEj8UcJjUuLbOJt9S QyExgRD27qFdvFTHn7gs8utZ9x40EldtlPmAoJBisyYqcI5wM9somh0f/0mGzO0uqUlp pkMANwMJ7Rtd1ZXTW6xr7BUcamAAJU/Y/GusDG76VVsL5kf+ukzbJlrMML4lCQXxBlwd 6n1Q== 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=T4XUxb4X2jLRPJlgce1PUKbINkwgcyiSSmfRX55y3ro=; b=RQHDTcRmhZpOQcpqN1H8D8tEZoyaaBTkZhJsD7Ia6SpCbUzgT1FZOJecLsdKijHuAZ 9ocWhnvmcPOPsn+rRIOzFNrqhb8rvl04GMgRN+8TIWNNW1m1sJq1bnxfVpvPSXLd4kgZ E7pNMYgycIZuA4OIquz/gWaljGXbwHCyN4jCnasuquBTuMWYriqw11Bfi+Hd4rilsAW5 EqU2C5QztvwQErXb3b+CZVxgX84mIC6mXK+5xhfngGpYqYw/shhtBp8QqcZaPJ0UNQ6f oQ4k7rwbPtQ5dDN7vlkdKUdjy+c6P5XzroqzQs0bbNZgj3rk2OFdCLHE18Wo4/2NyPLU EsLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZDqLAxpd; 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 y4si3963075edi.355.2021.06.16.19.49.32; Wed, 16 Jun 2021 19:49:54 -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=ZDqLAxpd; 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 S232248AbhFQBww (ORCPT + 99 others); Wed, 16 Jun 2021 21:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232211AbhFQBwu (ORCPT ); Wed, 16 Jun 2021 21:52:50 -0400 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDE9C06175F for ; Wed, 16 Jun 2021 18:50:41 -0700 (PDT) Received: by mail-vs1-xe2f.google.com with SMTP id z15so2112655vsn.13 for ; Wed, 16 Jun 2021 18:50:41 -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=T4XUxb4X2jLRPJlgce1PUKbINkwgcyiSSmfRX55y3ro=; b=ZDqLAxpdz8/XV2AShxA4hfhKJV6WvaHUe4qsWjZdsv/gMVWoSKok+fdhKeN4I8JL4O kX/XUGFzirvnJh5Jq/pCF2iuO+ak1c9xhNX+IkVHJ4wVYp+SyWw5m2FAHLi2/bD+uct8 MCw64kpOCcECw23Q3M0if1oB10ZCg/meJmwtYYK3qw71+Ax7POPbK87WEZpf+APmcG+W M4NtUgY1Bqh51pFcFOIFPzcvlwW/CjO88AGScnXBdSxEGC1dmT6kK1lcJG6AYkxwIkkL SK7E0JkeykUc44twXYWmE1HMmyJqNuYeSGnbo/AjmenNeLKQJtjITPLbB/OlpxMqZqvL SD/A== 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=T4XUxb4X2jLRPJlgce1PUKbINkwgcyiSSmfRX55y3ro=; b=Jqvm4eEws/DHT/6UrK+2E3qTzG2szP2OqskLjkmixkYwGTNoQKD00YsUHVKF95z6t6 2fmFW20Zzppq+KZaFFGkmEho+LTDvx0HWRwJbmYOOi8Lla2QdD0GEFqg6w2F0BX7PHm7 z2Wpxp/CNoetqi334d4E6cxo/PYTjIA7QnsO8HZVpzswolJnRSGcM1QZJ1V6HygQC2Yk m3Yz9M7TGMt2eCtAE+hyTki8FORamvsTtTCOYTneUjmvsLDn9NrkIs0plJdM6YmQpRHu 9++T5Gumsb5xI1meOjBP+eg8DRzeiCrTrJXbGgc1RUjbMKy8SUr80rXKuK+kK9kbLFUW zHiQ== X-Gm-Message-State: AOAM533DIAwXAQkdQ11eRQUi6AvE29uwQiHTvsBPDX3XDBXRb/+Hwxol MfwjRCOLG3W1ArBrfI12LUgi+R0FwHilK/WvKXlymQ== X-Received: by 2002:a05:6102:2378:: with SMTP id o24mr2460396vsa.12.1623894639745; Wed, 16 Jun 2021 18:50:39 -0700 (PDT) MIME-Version: 1.0 References: <20210616090102.1897674-1-kyletso@google.com> In-Reply-To: From: Badhri Jagan Sridharan Date: Wed, 16 Jun 2021 18:50:02 -0700 Message-ID: Subject: Re: [PATCH v3] usb: typec: tcpm: Relax disconnect threshold during power negotiation To: Heikki Krogerus Cc: Kyle Tso , Guenter Roeck , 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 6:42 AM Heikki Krogerus wrote: > > On Wed, Jun 16, 2021 at 05:01:02PM +0800, 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. 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 (PPS) or tSrcTransition (25~35ms) after it sends > > Accept Message (non-PPS). > > > > 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 > > Acked-by: Heikki Krogerus Reviewed-by: Badhri Jagan Sridharan > > > --- > > Changes in v3: > > - move the timing of setting threshold for Fixed RDO as I did for PPS in > > v2, i.e. move it to tcpm_pd_send_request. > > - add Cc: tag for Badhri > > - update the commit message for the above changes > > > > Changes in v2: > > - 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 | 27 +++++++++++++++++++++++++++ > > 1 file changed, 27 insertions(+) > > > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > > index 197556038ba4..b1d310ab84c4 100644 > > --- a/drivers/usb/typec/tcpm/tcpm.c > > +++ b/drivers/usb/typec/tcpm/tcpm.c > > @@ -2604,6 +2604,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, > > } else { > > next_state = SNK_WAIT_CAPABILITIES; > > } > > + > > + /* 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, next_state, 0); > > break; > > case SNK_NEGOTIATE_PPS_CAPABILITIES: > > @@ -2617,6 +2622,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: > > @@ -3336,6 +3346,12 @@ static int tcpm_pd_send_request(struct tcpm_port *port) > > if (ret < 0) > > return ret; > > > > + /* > > + * Relax the threshold as voltage will be adjusted after Accept Message plus tSrcTransition. > > + * It is safer to modify the threshold here. > > + */ > > + 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, > > @@ -3433,6 +3449,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. */ > > + 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 +4215,10 @@ static void run_state_machine(struct tcpm_port *port) > > port->hard_reset_count = 0; > > ret = tcpm_pd_send_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); > > /* Let the Source send capabilities again. */ > > tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0); > > } else { > > @@ -4206,6 +4229,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 > > -- > heikki