Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2862122pxv; Mon, 12 Jul 2021 03:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKLQH/F36efCgBWd8k4cidEoJp4wYoLLw2H9Aq8wR4ujBc8BdcnQx/lOqhuvbiLTTuX37S X-Received: by 2002:a02:630e:: with SMTP id j14mr28187316jac.86.1626087095271; Mon, 12 Jul 2021 03:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626087095; cv=none; d=google.com; s=arc-20160816; b=e64+oi9+6ABasfLbV7HXXucYGUZ2FkUuKLdgZ/O6lIFejoEXXPQhWDceBZi6o0APRL yh/lKM/GTS4H91J8efo4l0zU/272GRgi0DT01PDoLS8VNgof1sH9OITIxPp4xWvIac1F MjMpnHwHmoPuSYHCwdajvqw/+iyFd8wOXyHejPHd2960DrJC7ISQGjTeKySrF9anrI7y lUrX7HXz2wD1+wOVVtDTFO03uXS6hZENoVvYdo6Wv0+jhrSI1xR1nwZkkGyB9y+ohtEX XkajGp2CBk9Cq5Y184jyIRwy5u4LzCSQgykvQQ4mz0qq+UwFH+RxB9wgeJWeFRwl0MX4 utEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2sy/mQy7U56z7JEdh0ZMF71HyCKIT2H2CySaAqrbQpo=; b=eEjg4zQkdsjjSiRE7S4MtfIQvjainLmA+OwQjtDGaCluia/p1CowBElm55RrSME1HG M7STYK/PqSV0HUqGpPjT3zK7ZFHfzFnsNQ32wZ/568a+lUgrGddGOshwIfzZd9EwQtCo cGb9OkFTlAtTxdV3mCKdMiOZGvxuZQ808ubqaycMlyy6hXzeXMo8JXDPmdOuhuRvXga1 KO4MUkIp1Msg9S9loCOuSrOFcYiYNLo4ctfDFYjLqjclo8DOYkjifGLzuDDp4TVup0P5 EQyO7dI47oXXSCQ0pZB0zPYO3muWI+5c/3flw3rkHatFqTQImu9Yn9diLnJgAUu+kTw4 nuQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=p9lEngCz; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si16830250jaj.117.2021.07.12.03.51.23; Mon, 12 Jul 2021 03:51:35 -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=@linuxfoundation.org header.s=korg header.b=p9lEngCz; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356084AbhGLIQJ (ORCPT + 99 others); Mon, 12 Jul 2021 04:16:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:48194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346435AbhGLHat (ORCPT ); Mon, 12 Jul 2021 03:30:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 57CB46052B; Mon, 12 Jul 2021 07:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626074881; bh=IkJbX/r2lzTKOCAl4XojxbvDNY5dBJqh0D2gDENf/G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p9lEngCzI3a5Sp5+oQMCi1ESDnQIgmNf4vQrCXgcjUIo8lTKwiYihQIrIeoAfJlAK FdkH+mCw5Dz61TxTHrKdse7E2zK8YN3+nS+k0JkLFmt63H8lELvy+t7zeP0uYmMc6e NtxEsgnifarDRfLLW07mO26yROY3W1vUhyuXnfUI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Badhri Jagan Sridharan , Heikki Krogerus , Kyle Tso Subject: [PATCH 5.13 028/800] usb: typec: tcpm: Relax disconnect threshold during power negotiation Date: Mon, 12 Jul 2021 08:00:51 +0200 Message-Id: <20210712060917.150951452@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060912.995381202@linuxfoundation.org> References: <20210712060912.995381202@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kyle Tso commit 2b537cf877eae6d2f2f102052290676e40b74a1d upstream. 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: stable Cc: Badhri Jagan Sridharan Reviewed-by: Badhri Jagan Sridharan Acked-by: Heikki Krogerus Signed-off-by: Kyle Tso Link: https://lore.kernel.org/r/20210616090102.1897674-1-kyletso@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/tcpm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2576,6 +2576,11 @@ static void tcpm_pd_ctrl_request(struct } 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: @@ -2589,6 +2594,11 @@ static void tcpm_pd_ctrl_request(struct 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: @@ -3308,6 +3318,12 @@ static int tcpm_pd_send_request(struct t 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, @@ -3405,6 +3421,9 @@ static int tcpm_pd_send_pps_request(stru 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, @@ -4186,6 +4205,10 @@ static void run_state_machine(struct tcp 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 { @@ -4196,6 +4219,10 @@ static void run_state_machine(struct tcp 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