Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp723855lkv; Tue, 18 May 2021 18:22:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbK4AUcehlsPbWqG2Ps8jFbxGeN2BBQI4bNhhpfOB6L59JtGU+rkhFddmAxWJceaZOGgMz X-Received: by 2002:a05:6602:14c4:: with SMTP id b4mr6996780iow.82.1621387330857; Tue, 18 May 2021 18:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621387330; cv=none; d=google.com; s=arc-20160816; b=CM4IK+5DKQx7vWYBZui6pTOmhIGYd4/L9LIUSpcwCc2KEzUJiZlzdaIoSZWhe1Tt7s xAAxTdg6j3oA/4W/5u5xdUyWda/XYPThotI6tbOS6BDrBwoLvIFYNfujML1KcPMMTuVu NnYaSp+OsBYzwpYrGLBG4rkyQNOpX9XM8tzvwHNoiVmvjOsj0XXCPK+M25AHWp92TonG qWdSaL0PAogHdDQNaQOmH8P2MvwG/G+XPfEyodPdahg7LOfD4QFI8aq/cy0K/V262WJS mKURe8LIsO14Xu1OUQ5RLPggWbwSRhCbyrbLJ18X3IdTK6BI11xcAsnFMf0VRT8rLPsl sRfg== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=e5jSU7HtuQFmdUmn7z8sqk1SHR5Y9aJ3zA7f8ysFgoo=; b=r36c+ajSn1+Q/6yTzxLCf5mvRqqCUkM8ACVy6OwwxTjmzgZdFZN1qDXFUl7dL8D9dk ThvudhTPgsnx/W3CHQpSytNU4nxYTF+1IU+IpB5nAsQIesXEU+4PluK9IScQM42QUOI6 XCr98fa/+tCZvNH0FzDVeKVuZ5TM3rwDNdm3ALpCJZm+BWwVsxwoS9oOVZsqQ224QaoJ LFnBy+RCMjt52SuO/mOaUxft9OVETpaq7tBjWj/P/lF1eBLIV6tou42CYMNd8MBvOSRu Rs2I82KQo5dohM84dIBB4TOvgG6Ge/jPvSmfI+odIjahrZH2Kqheg/12qSR61g7NIz9T Q6vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=a6V5RUvZ; 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 b12si9763944iob.37.2021.05.18.18.21.58; Tue, 18 May 2021 18:22: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=@google.com header.s=20161025 header.b=a6V5RUvZ; 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 S233163AbhEQTWl (ORCPT + 99 others); Mon, 17 May 2021 15:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232880AbhEQTWi (ORCPT ); Mon, 17 May 2021 15:22:38 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D767CC06175F for ; Mon, 17 May 2021 12:21:21 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id 1-20020aed31010000b029019d1c685840so5924938qtg.3 for ; Mon, 17 May 2021 12:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=e5jSU7HtuQFmdUmn7z8sqk1SHR5Y9aJ3zA7f8ysFgoo=; b=a6V5RUvZ6IccV9YrF0jHKsuPfOCPHA3SFlNLpX+8DEumop8ybL8n/3Skg4aYL135ym ad0qTqt/YQjFI4TA9f4fd/0N1notRWg63wD13VaYHetS1FTbxAKGAhggsnxry8iCdMIb R+NYBrchalfkIgjMgtBkvO3FRsktjFFy1vXAEbCpHHSpKMZ2thfSS8yk40yCWjT64x/9 olZ587HXH56zdDANmNJQvL7UgoYwaL040P58iMjXH2n9Sf920yp4Qn1byxAda8jxMgTX XEeVygex5M0+Wf332Uo479i6nxzKYg366oxtIkKeK81qq4af9vQo/bPfbnkxO9zmwjEs vteA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=e5jSU7HtuQFmdUmn7z8sqk1SHR5Y9aJ3zA7f8ysFgoo=; b=UfghrumVogQ3LYfdnHEhUYglt1ERnuNQCMuzt/9IAUsdYhzLHBLoS7i7CXq+v1lte8 aQQLEgslva+B31/Nu+cc6GYV9NjRMKqS3Gl2WDPO4Evs2ytQbo6rC5GokS/anRoxMEnj f2ayCgvAdPq5Ouv0q+uqq3CYePPxlT89r+VAITOOceq7A2kOupyRa4QA30nL0afVg3Nc BYZWR0rA5MwAbh/OU6+37H3GvfPT9Q5lzaU7idoZl2j80DGwAOE/6KW6VPtUF3wxKEtw 7wlqY5lQlWnwFaqJ0+KmYHmeFJsp1bX7fkQgbasUBjDdciCZ03Vwi4IMDSl6b70LFE7E qfFg== X-Gm-Message-State: AOAM531YA0NQqmPVzU/sWONFUj6+idYXkwlnETZxD09gH088O6NbKuia 3n1zG02abp7EmUkOGVVAtU9d5ndaD+w= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:b562:7011:fe35:1c9e]) (user=badhri job=sendgmr) by 2002:ad4:4184:: with SMTP id e4mr1281838qvp.13.1621279281041; Mon, 17 May 2021 12:21:21 -0700 (PDT) Date: Mon, 17 May 2021 12:21:11 -0700 In-Reply-To: <20210517192112.40934-1-badhri@google.com> Message-Id: <20210517192112.40934-3-badhri@google.com> Mime-Version: 1.0 References: <20210517192112.40934-1-badhri@google.com> X-Mailer: git-send-email 2.31.1.751.gd2f1c929bd-goog Subject: [PATCH v2 3/4] usb: typec: tcpm: Move TCPC to APPLY_RC state during PR_SWAP 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 When vbus auto discharge is enabled, TCPCI based TCPC transitions into Attached.SNK/Attached.SRC state. During PR_SWAP, TCPCI based TCPC would disconnect when partner changes power roles. TCPC has to be moved APPLY RC state during PR_SWAP. This is done by ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and POWER_CONTROL.AutodischargeDisconnect is 0. Once the swap sequence is done, AutoDischargeDisconnect is re-enabled. Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") Signed-off-by: Badhri Jagan Sridharan --- Changes since v1: - Added additional check port->tcpc->apply_rc as suggested by Guenter Roeck --- drivers/usb/typec/tcpm/tcpm.c | 16 ++++++++++++++++ include/linux/usb/tcpm.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index b475d9b9d38d..3c2cade986c9 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -786,6 +786,19 @@ static int tcpm_enable_auto_vbus_discharge(struct tcpm_port *port, bool enable) return ret; } +static void tcpm_apply_rc(struct tcpm_port *port) +{ + /* + * TCPCI: Move to APPLY_RC state to prevent disconnect during PR_SWAP + * when Vbus auto discharge on disconnect is enabled. + */ + if (port->tcpc->enable_auto_vbus_discharge && port->tcpc->apply_rc) { + tcpm_log(port, "Apply_RC"); + port->tcpc->apply_rc(port->tcpc, port->cc_req, port->polarity); + tcpm_enable_auto_vbus_discharge(port, false); + } +} + /* * Determine RP value to set based on maximum current supported * by a port if configured as source. @@ -4428,6 +4441,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ready_state(port), 0); break; case PR_SWAP_START: + tcpm_apply_rc(port); if (port->pwr_role == TYPEC_SOURCE) tcpm_set_state(port, PR_SWAP_SRC_SNK_TRANSITION_OFF, PD_T_SRC_TRANSITION); @@ -4467,6 +4481,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON_PRS); break; case PR_SWAP_SRC_SNK_SINK_ON: + tcpm_enable_auto_vbus_discharge(port, true); /* Set the vbus disconnect threshold for implicit contract */ tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, VSAFE5V); tcpm_set_state(port, SNK_STARTUP, 0); @@ -4483,6 +4498,7 @@ static void run_state_machine(struct tcpm_port *port) PD_T_PS_SOURCE_OFF); break; case PR_SWAP_SNK_SRC_SOURCE_ON: + tcpm_enable_auto_vbus_discharge(port, true); tcpm_set_cc(port, tcpm_rp_cc(port)); tcpm_set_vbus(port, true); /* diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 42fcfbe10590..bffc8d3e14ad 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -66,6 +66,8 @@ enum tcpm_transmit_type { * For example, some tcpcs may include BC1.2 charger detection * and use that in this case. * @set_cc: Called to set value of CC pins + * @apply_rc: Optional; Needed to move TCPCI based chipset to APPLY_RC state + * as stated by the TCPCI specification. * @get_cc: Called to read current CC pin values * @set_polarity: * Called to set polarity @@ -120,6 +122,8 @@ struct tcpc_dev { int (*get_vbus)(struct tcpc_dev *dev); int (*get_current_limit)(struct tcpc_dev *dev); int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc); + int (*apply_rc)(struct tcpc_dev *dev, enum typec_cc_status cc, + enum typec_cc_polarity polarity); int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1, enum typec_cc_status *cc2); int (*set_polarity)(struct tcpc_dev *dev, -- 2.31.1.751.gd2f1c929bd-goog