Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp310534pxj; Thu, 20 May 2021 09:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIKhaB2LH7V5ve0wKzZRMtQtqK4qyz4RdJ6xur4uerRs94V4ChGVCOQVHLeLuqDSt7BUPx X-Received: by 2002:a17:906:b10e:: with SMTP id u14mr5466089ejy.546.1621529410668; Thu, 20 May 2021 09:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621529410; cv=none; d=google.com; s=arc-20160816; b=Y4H8G00C+7h2osZUPRUwH0yN8XRCm3kxnuXHVDZarEYT6oD/m9z7xoZmzg5O6u9XZa R7Em6VVe5AzVjmdjGbe3kQPtY96Q1WZlvwM75zR4nB1MGFbrll8XESlsCQVQIdQ5lMjS fbvFuYC3p1/F6ICW+sXhgfJDfIZ/O6iAFebGJuWeHNn5f+dxCXiPB1mlo+XvQQ0T+LPn fMo7oAMWrjM3BtdrNKd4FMO9XipQFVWMdqMYF0Mi44/DG7ksFst+qxrNGDJeQByyzjcG XyMrFMI8rVgPisU+s28xkh5vf5Np48eGGwroRHhfmbaNy7pPIWNz9XV+NliE85mp0fPn 9+oA== 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=/qY4z3/CgxWegiWPLu2ebbqL4kr/oZOflOHhvgiQR9w=; b=rZELM0v0m50YIByrUSbBOmoegvhi8K2qnthlxkOI3gK+UUjXndDJXaRPWdgWpDtFbM KFjFaS820pY88CfjngeCSYUuLydLHc6QlUy2cJESpIEhIYA9wzyKYZ37sPXfYXBZOhF0 OtX6yhPg1lr4TI2tz6rXBXsq69lAFuQPizjlPHybiP1KDFUrlD4PJaKi4Y8/is53S25J bBeFXjW+2dFRxSI0I3Dn54C9Agk8JrbUI25bhHXxnJhnKTwBx9RYO1xtmlNjdXoslgQf yvc5nxhp8hQ0IZUkf1R2FoMHauOKnFPBQUlUg566001ovCpWiAUFovgc1z7PBY5xuXFO eWIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gdhdI3iB; 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 z15si3282948ejj.367.2021.05.20.09.49.44; Thu, 20 May 2021 09:50:10 -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=gdhdI3iB; 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 S234132AbhETJxA (ORCPT + 99 others); Thu, 20 May 2021 05:53:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233669AbhETJuk (ORCPT ); Thu, 20 May 2021 05:50:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FABB613BD; Thu, 20 May 2021 09:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503327; bh=O7VfkhCiGlU5X5WJLzZGSsRVxM/JkBFpbE/M0mCP1/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdhdI3iBclbSAmf0+hIfjhcg5zGttlWwP4qTrLnjrLhYVYwfvHivpFuov8sLDUPcn bYHJZzJe0BZiZMVoui3G2079ONOzKiKAuaZUznEQV4DV2BZKzE+UAnfUHuGbhFjmxE EHwWFhu5zMAtPrm8+Pbj3tR7T6YbRDOZIhjRUgKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heikki Krogerus , Badhri Jagan Sridharan , Sasha Levin Subject: [PATCH 4.19 171/425] usb: typec: tcpci: Check ROLE_CONTROL while interpreting CC_STATUS Date: Thu, 20 May 2021 11:19:00 +0200 Message-Id: <20210520092137.065397555@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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: Badhri Jagan Sridharan [ Upstream commit 19c234a14eafca78e0bc14ffb8be3891096ce147 ] While interpreting CC_STATUS, ROLE_CONTROL has to be read to make sure that CC1/CC2 is not forced presenting Rp/Rd. >From the TCPCI spec: 4.4.5.2 ROLE_CONTROL (Normative): The TCPM shall write B6 (DRP) = 0b and B3..0 (CC1/CC2) if it wishes to control the Rp/Rd directly instead of having the TCPC perform DRP toggling autonomously. When controlling Rp/Rd directly, the TCPM writes to B3..0 (CC1/CC2) each time it wishes to change the CC1/CC2 values. This control is used for TCPM-TCPC implementing Source or Sink only as well as when a connection has been detected via DRP toggling but the TCPM wishes to attempt Try.Src or Try.Snk. Table 4-22. CC_STATUS Register Definition: If (ROLE_CONTROL.CC1 = Rd) or ConnectResult=1) 00b: SNK.Open (Below maximum vRa) 01b: SNK.Default (Above minimum vRd-Connect) 10b: SNK.Power1.5 (Above minimum vRd-Connect) Detects Rp-1.5A 11b: SNK.Power3.0 (Above minimum vRd-Connect) Detects Rp-3.0A If (ROLE_CONTROL.CC2=Rd) or (ConnectResult=1) 00b: SNK.Open (Below maximum vRa) 01b: SNK.Default (Above minimum vRd-Connect) 10b: SNK.Power1.5 (Above minimum vRd-Connect) Detects Rp 1.5A 11b: SNK.Power3.0 (Above minimum vRd-Connect) Detects Rp 3.0A Fixes: 74e656d6b0551 ("staging: typec: Type-C Port Controller Interface driver (tcpci)") Acked-by: Heikki Krogerus Signed-off-by: Badhri Jagan Sridharan Link: https://lore.kernel.org/r/20210304070931.1947316-1-badhri@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/typec/tcpci.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c index dfae41fe1331..2c34add37708 100644 --- a/drivers/usb/typec/tcpci.c +++ b/drivers/usb/typec/tcpci.c @@ -20,6 +20,15 @@ #define PD_RETRY_COUNT 3 +#define tcpc_presenting_cc1_rd(reg) \ + (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ + (((reg) & (TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT)) == \ + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT))) +#define tcpc_presenting_cc2_rd(reg) \ + (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ + (((reg) & (TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT)) == \ + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT))) + struct tcpci { struct device *dev; @@ -168,19 +177,25 @@ static int tcpci_get_cc(struct tcpc_dev *tcpc, enum typec_cc_status *cc1, enum typec_cc_status *cc2) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); - unsigned int reg; + unsigned int reg, role_control; int ret; + ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, &role_control); + if (ret < 0) + return ret; + ret = regmap_read(tcpci->regmap, TCPC_CC_STATUS, ®); if (ret < 0) return ret; *cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) & TCPC_CC_STATUS_CC1_MASK, - reg & TCPC_CC_STATUS_TERM); + reg & TCPC_CC_STATUS_TERM || + tcpc_presenting_cc1_rd(role_control)); *cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) & TCPC_CC_STATUS_CC2_MASK, - reg & TCPC_CC_STATUS_TERM); + reg & TCPC_CC_STATUS_TERM || + tcpc_presenting_cc2_rd(role_control)); return 0; } -- 2.30.2