Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5349735pxb; Wed, 26 Jan 2022 09:58:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIwTtN8J/GrWMQ49DpQ4iVp8bJ6rJKEA+azWvfCRHYM9Ga/2B1Nm3XyFq3B52rJdaMM37/ X-Received: by 2002:a17:90b:b0d:: with SMTP id bf13mr9720198pjb.31.1643219886958; Wed, 26 Jan 2022 09:58:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643219886; cv=none; d=google.com; s=arc-20160816; b=zx25h5OeCamSzE6Xgt0Dx3PU4pzQg4rSZRK/BUpzzDi74c7uPKT5u6z+0f6jNdjjJC 0S1vZ+dq0vMkLz3OBDYXreTzguqwgdnF8uvbeMIkvviQihGL4AJVdp9R/W2gLFpn4PeB kBCMIbw7PaBS2epN/zNlplpoY9Yg7a8yL/jDv4diDjKdThIZMmZYNlySE/hk95lpZuKB VBZMVBzdM7yF1DZ8f1suX4UFzO9WivM/ZcKYP/Xq2xKk/pe3qvpOhJXxs9WHlN2hLxmP ILmpadqTeM68Kg0ju4ZPeSsxV32SkYxi4d7KtFs4nsXDkmc0MZfWWp8wf7NQ9ZhPgxGA KlIQ== 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 :dkim-signature; bh=QwxLJwmoqd07JuSH9SLqDQX7ullgrCcHXvI+bgIzrTE=; b=J38yEffWWHYx4k/8P6XLzhJ2FdMZlkvn/eKQhlR5V01XXZlj3+tYqa0BevIiyvP0RO cD5ps2s2mJkMUk6zIGoM0CEa9mgmwEedyqdroVPUP9XokORrJ22bMrAu24oFxIdcje6I Bg8aQuxfp9A9cuob7onWSsmkoEaehjKXXjVC4vzFv2LnSr6BWxfso2D/hALZssTAh6OP SD3tKP5+6kuBhuo5ASQjM6+/ha92C0OnODUZ/R6rJMavf8NJG/9ZWb6afa4PYK3Qez0S a3f+2yhaOoguqB8bF9uGleJLrWCYtKZfKtXC2z78FaN51jCIHK+WbCmMJw3TtOR+P2jn UFhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lDIeDFzJ; 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 x6si20243167pgi.290.2022.01.26.09.57.53; Wed, 26 Jan 2022 09:58:06 -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=20210112 header.b=lDIeDFzJ; 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 S237438AbiAZEEy (ORCPT + 99 others); Tue, 25 Jan 2022 23:04:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233631AbiAZEEw (ORCPT ); Tue, 25 Jan 2022 23:04:52 -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 4BEB2C06173B for ; Tue, 25 Jan 2022 20:04:52 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 2-20020a251302000000b006118f867dadso45843126ybt.12 for ; Tue, 25 Jan 2022 20:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=QwxLJwmoqd07JuSH9SLqDQX7ullgrCcHXvI+bgIzrTE=; b=lDIeDFzJ80jBeA928G8m+g6sPzt76PBYaMG4kwfZwWmpqXzoO8rlpE9Al9VBhO4d6K 0mA9KeVOktB41epEOvrl6JMuVxG2lq8gJ8H8nxYndsVVF0o+gS5LIz4wxOx0X0pjLZx6 JOdO/+j9TegK2nxxHZ/GFz1hmyUpaLIYsR82jrZmtSj1d+lly5ShCA/npI6LMrvsvjgo JnDaoUzy2D7OB2rCBrpWx0xeGdp2vvoA58MH6LLFzfv0gx/pDj/EYL39EuX4+f5ZTXBV XxUWb5Q/sBxQyYLbuuui8n+7Fvq80ccDM+LpRCTNZ4UGkxJ3M3bcS0J4i2MfSOoavJhB Mddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=QwxLJwmoqd07JuSH9SLqDQX7ullgrCcHXvI+bgIzrTE=; b=RLXuZuiQGkpM5WkoDfK+gWZ1UfDSHWoqN8LbNvNyz8MQ86k0wi6LdR7PcTqU3qfSij K1Newnb5Vb0bb7TuNFjY3RO+IVhyaal96CRBzwq2nZmDFhWF13Bb0JsKNKlLMCUPyX+F hzQ45T5ZNP0nSuFwybayMahz8md9jwgrzykOG/IYDKE88MVrmSbUAw9GQMg4h+JUeuDu bkJMbXvv2KhPXcIAhYw4y/rz3/OUm/LJAHY/yWOv0H9fjIofN7+DY+BeOCgXcFq/yQ8A oO3xwlsvQTjxRyvB70GA6X7QRwpWJM+7pYubDwkF4WR+HGGE1R1eSIxBhiAbUJ1zalpF oJSg== X-Gm-Message-State: AOAM5326W9JAgzbbWb7Kv96HCkwcSOZk5/xSNml8Q0BFsbGBMG1IoMy4 6ovc9s8CuJJ56CUSC4Pq6ovbwucz380= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:f4a7:8e16:f301:160]) (user=badhri job=sendgmr) by 2002:a25:8550:: with SMTP id f16mr32238494ybn.319.1643169891564; Tue, 25 Jan 2022 20:04:51 -0800 (PST) Date: Tue, 25 Jan 2022 20:04:46 -0800 Message-Id: <20220126040447.3186233-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog Subject: [PATCH v3 1/2] usb: typec: tcpm: Do not disconnect while receiving VBUS off 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 With some chargers, vbus might momentarily raise above VSAFE5V and fall back to 0V before tcpm gets to read port->tcpc->get_vbus. This will report a VBUS off event causing TCPM to transition to SNK_UNATTACHED where it should be waiting in either SNK_ATTACH_WAIT or SNK_DEBOUNCED state. This patch makes TCPM avoid vbus off events while in SNK_ATTACH_WAIT or SNK_DEBOUNCED state. Stub from the spec: "4.5.2.2.4.2 Exiting from AttachWait.SNK State A Sink shall transition to Unattached.SNK when the state of both the CC1 and CC2 pins is SNK.Open for at least tPDDebounce. A DRP shall transition to Unattached.SRC when the state of both the CC1 and CC2 pins is SNK.Open for at least tPDDebounce." [23.194131] CC1: 0 -> 0, CC2: 0 -> 5 [state SNK_UNATTACHED, polarity 0, connected] [23.201777] state change SNK_UNATTACHED -> SNK_ATTACH_WAIT [rev3 NONE_AMS] [23.209949] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS] [23.300579] VBUS off [23.300668] state change SNK_ATTACH_WAIT -> SNK_UNATTACHED [rev3 NONE_AMS] [23.301014] VBUS VSAFE0V [23.301111] Start toggling Fixes: f0690a25a140b8 ("staging: typec: USB Type-C Port Manager (tcpm)") Cc: stable@vger.kernel.org Signed-off-by: Badhri Jagan Sridharan Acked-by: Heikki Krogerus Reviewed-by: Guenter Roeck --- Changes since v1: - Fix typos stated by Guenter Roeck. Changes since v2: - Added reviewed/acked-by tags --- drivers/usb/typec/tcpm/tcpm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 59d4fa2443f2..3bf79f52bd34 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -5156,7 +5156,8 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port) case SNK_TRYWAIT_DEBOUNCE: break; case SNK_ATTACH_WAIT: - tcpm_set_state(port, SNK_UNATTACHED, 0); + case SNK_DEBOUNCED: + /* Do nothing, as TCPM is still waiting for vbus to reach VSAFE5V to connect */ break; case SNK_NEGOTIATE_CAPABILITIES: -- 2.35.0.rc0.227.g00780c9af4-goog