Received: by 2002:a05:6520:2586:b029:fa:41f3:c225 with SMTP id u6csp4299578lky; Tue, 15 Jun 2021 19:12:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4GKP1AdO/p9DuxLRHUUKuQG9PqBs5L1t28O9d3CU3K7NdqCDcS2LOXLgCLDcejXZgqnyR X-Received: by 2002:a17:907:9801:: with SMTP id ji1mr2617935ejc.523.1623809565465; Tue, 15 Jun 2021 19:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623809565; cv=none; d=google.com; s=arc-20160816; b=NvFJmlQQ7HB97j49SKvFvf4Fqt2BC21ZPSEZOjWEYuT3pu8E91NMT7n9o9P/ThqgW9 rwmDu7OslaRfPyteU7AsqpkcVoUP3nQA7Ag9ef9oNkwfwfGv7rs2xc99mapHtySJuMaz 6rY7A3jF/QiBQFMiDJbQTU/KniPQhLvlNU7/hjANG6J/qSRM1f/4sd8nWlVAR9NNpHcQ JBa2p4J7vHZ5lvJmNudP41ecTd+YTUcO84ND12i4DPjHD0NpPLK2WzmHmK674XUPw9oi NxkROVzT6TAS27MHTMdPErD7gfY1bhyeHEUXeDAH5oHcSMyuHv4JSjIo+DPLOdgneF52 NTLQ== 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=y/w/qb9Mmcto0feWg3hHcwChOztbEZEtyAyt33Ggpnw=; b=ww1kWaX+GpwOLnwlrOucw6rrrY+PM9P1qYFJwPQ1sxYfv4tmRCOCP/luzHqCa7/WNp 1q1az/dKUaYLeWuLfFVBgmVkfgwyGgcBzyMte/o5rHoCsllAYgcJJ4F5biMPDHtHOJkN mbMPsp7dPj6OaDcBUYXPi/SzQBhCqDSj/tpU+5n/9lnUHznqCh1vmhPlJZpprECd52c+ 9N9QHVVuiQsMvH11CBs/c5jMlN2XFb9qy29pPXrL/jmPXFc97O6E3ulHoW9XpwKpEOM4 1jHrT1kkMhlTsgrv1f/QwBkLvVVkLb27nS9edqfhCLFv/gC6u7Qb+kFHnl6aT4zccl1M SFZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AhtG9GZy; 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 jx13si691022ejc.576.2021.06.15.19.12.23; Tue, 15 Jun 2021 19:12:45 -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=AhtG9GZy; 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 S231254AbhFPCM2 (ORCPT + 99 others); Tue, 15 Jun 2021 22:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbhFPCM1 (ORCPT ); Tue, 15 Jun 2021 22:12:27 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85E10C06175F for ; Tue, 15 Jun 2021 19:10:22 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id c9so1138447qkm.0 for ; Tue, 15 Jun 2021 19:10:22 -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=y/w/qb9Mmcto0feWg3hHcwChOztbEZEtyAyt33Ggpnw=; b=AhtG9GZyWbc/q1PGc9HjGVcAmV+41TtxHzj5t+3Ph52sRD/pGlCYW+sjvjtIBRcyaR wCew2MSr8r5xNYIaXdlWx9oxLahHZfapzWQiKYjBQ6fSBMSGM9h0/tvS8BHEsxZJUuIj UAT6KoFnPo7F6PD2Dj+qoxZHx44h01bdZB2msVwL65+hpE0vYPGKqBfV3OL6O/YuILgy RNTIGiIAEuTxVgwaM4vx6JfMuiXce0ZZficds5jppGNvxEhodMDwct9zId2GkUc2pKeB GqfqxE6g+d/e6kf1t+mtbbL70NgGCj+f8WdjOjloY4lnXkt1Xj8TwN4hvoE3LSSU0d8+ mXZA== 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=y/w/qb9Mmcto0feWg3hHcwChOztbEZEtyAyt33Ggpnw=; b=c+vmYKfSzI10bwYqGx8hoVvkyNaftOVWFrFxOxQdVqc1PeLwZMNinn37hsK+t5IoyU G/yTr/TsuTRLr1y0c7YdoCdV+UPEgSTaqi4CtBEPYT8T/QiYWc+BIPanrOIPRyfcMskH nctjVfiDK9j4o/Ij5agPpQNzrzpQ9wQYwK8OhQVSdy6kbYd9N87Xhrxj5dGno4VnPKd5 Ib/mswwWczs0OMPy10ahvT4zOS1eozlmRd/z89qbpom9DVZ0Rn+y8noyahP7o+hNFhCf gWoe7MmYtjAu/MhrQBMFQ9n7KWzf64fzZPwCf8DPSttlg34ZpQWTLZlRL5hdT4CL0YM0 B/5w== X-Gm-Message-State: AOAM5304n/+kAp1eHuIBbz6wMkwmxKSgFGcSGfhjb3P6zD6Z0VksDFDa Knc48CxWIjhILXVIrX+UsocvQ2AAQQ3KgfyhPWHkE643Qro= X-Received: by 2002:a37:8d82:: with SMTP id p124mr2779115qkd.212.1623809421219; Tue, 15 Jun 2021 19:10:21 -0700 (PDT) MIME-Version: 1.0 References: <20210615080817.1417169-1-kyletso@google.com> In-Reply-To: From: Kyle Tso Date: Wed, 16 Jun 2021 10:10:04 +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 9:16 AM Kyle Tso wrote: > > 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 > Ah, I know your concern here. So you were saying that the tSrcTransition may not be enough in some situations so it is better to do the similar thing for Fixed RDO? Yeah it makes sense. I will do it in v3. 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 > > >