Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1261028pxb; Thu, 4 Mar 2021 07:16:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwX6ZXViZOQ+xH7ne/PcRMxssKj0bz5MLqDKtzDWWVD8uLtgTxCaBpy8hQMvupOgB/W2MmA X-Received: by 2002:a17:906:4f96:: with SMTP id o22mr4655742eju.511.1614870994866; Thu, 04 Mar 2021 07:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614870994; cv=none; d=google.com; s=arc-20160816; b=jj8LJYj4y3O5CFQrkmQWFaHWEJ+uIckTszjw5bITDaUa4sJExSxjDMylG3xQ964n4U 6BWRS1SlS0ljFjaD4KM2TqoR5IA/aMBdgUGzNBxd5arCuE6rO3iUyG6fa8Akm0AVx0Po RwX5E5zGRg1z9Beks2kchmCXo9yJ4R6O8cKbI749IgwcvuFnDnY1OpU1VQTNiM+EYajV 2kqBegCOaug0lwqKZpxvcz0kNNWTl/gQL0IQqEfTtsEMMK1QFWqP3IJaFB+gpt8BdFCO Ve89UoZKf0PNwnqHCXlH580cVMqe2bGS3URbhXGL/i6wxgO3BdpWZLkHE6Kwoa7fre55 NVIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=6SYKOly+jweugIylMFB95EbkQpY3TPkXyF08BjG+EYk=; b=K6VMf5RQkwYnjAOWhvQNKe8MNHiJjQ1yJLClIWQwmN8vXnbvTItIj2iCgVdIN4K9oJ tEiklwilKJc7SVDEpuY7JcmwtFeXhkSjtTgMrF5Gw81v7RCd9p81F+Him3yFEp9uqnr8 91LAeu6eF8pqaQNVcEfRL+DJLia7arx77Mzh55pUO4bgXqTxpOeg+zipWEXpLFM0EreR Cjt/KQeOfQocJECTOEBDm6kJJI5R5AJfzYxtDTJn5F44ZTmUrnnw871V9CAYYnU7ND9h v09kP6szVYrZdK/rg5jmnMVRe62d+aC5BXQNKulpbCCRpfwD1NEjsEn4NtSiTq0X4g9/ Rn0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pir1oZAy; 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 gx7si9666482ejc.349.2021.03.04.07.16.11; Thu, 04 Mar 2021 07:16:34 -0800 (PST) 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=pir1oZAy; 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 S236035AbhCDHKV (ORCPT + 99 others); Thu, 4 Mar 2021 02:10:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236031AbhCDHKP (ORCPT ); Thu, 4 Mar 2021 02:10:15 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B72DCC061574 for ; Wed, 3 Mar 2021 23:09:35 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 131so2749764ybp.16 for ; Wed, 03 Mar 2021 23:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=6SYKOly+jweugIylMFB95EbkQpY3TPkXyF08BjG+EYk=; b=pir1oZAyUls7R39beNX8rUtSrLX+skRk3aAi9rhfDi6PNKwuxwKaRzM0Ya1ou874d+ IyYZK/KjNBF0Hnqi+7bLNQRLxdcBm8x9+sJ0tSrz+HNiBzSRrUrWYWufOi6eGzpqN7Jl d61BDFGS84Cbr8fIHfU9IxEkb8EUYDY1PXna0XKvZXmmauWLVeJjcxXr7xqT8/T7C7vK TFQf9LzKiVsBxALCf1XZcuAWWLzpATs1YEU0VgFkmA408cuHQMAb3yOOPTo9vWWSzpUs 8nxpwlmRGU+NNMnJbWz4fdykIPQjo5yOCdz+uCEGrxfALeSO7CpWEmA2S71q2pqDi1hq d96w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=6SYKOly+jweugIylMFB95EbkQpY3TPkXyF08BjG+EYk=; b=FFoiSkA5slVwnC1qIGXqIEE79MI6amfTMbqTed0x9QmpdKAj8fmjnvpTizMmnbMvoP iG9Y/ageC8Rgvj03ffDCw4X93Lr+GviPJjNQ2YfroZ06Wkng7BR1PJ83u8KGSLA6FQze o2u3YT9SUZEWNtNTWnteOfCoA8yr4aLiLH5E3n77iTWLL5yVoC0bNcqGl78cgx/mf10+ 2GGv44x6RtoYQWxSSM31HtEuzkuMQnOJqJ92doIzD42GjC0Uxv0/356QNsH8P30pH8BF XzKBb21FDOxag6gJtmjLFi7klx72nFFLvq94AtOYXsCgBO3f6kFAXOssszg7EDStNHwS 1BQw== X-Gm-Message-State: AOAM5314JfKHzaQkdQ+VYzbAQeVM8ZiDGZdwLEKt2+f8WWYaP1Hjcf0T qPLcUU8BJRJLiRgVs/mTiJPqmi+rxZE= Sender: "badhri via sendgmr" X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:543f:67ae:599c:e076]) (user=badhri job=sendgmr) by 2002:a25:c006:: with SMTP id c6mr4556819ybf.353.1614841775027; Wed, 03 Mar 2021 23:09:35 -0800 (PST) Date: Wed, 3 Mar 2021 23:09:31 -0800 Message-Id: <20210304070931.1947316-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v1] usb: typec: tcpci: Check ROLE_CONTROL while interpreting CC_STATUS From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , stable@vger.kernel.org, Badhri Jagan Sridharan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)") Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm/tcpci.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index a27deb0b5f03..027afd7dfdce 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -24,6 +24,15 @@ #define AUTO_DISCHARGE_PD_HEADROOM_MV 850 #define AUTO_DISCHARGE_PPS_HEADROOM_MV 1250 +#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; @@ -178,19 +187,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.1.766.gb4fecdf3b7-goog