Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp622259rdb; Tue, 31 Oct 2023 18:28:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEH7tuAUIZh3Sybte680cKqruRqv3Z+yZeSTOtg4YOm3jH7Nr00o0gAF3pN6hrkS5wYr4VU X-Received: by 2002:a17:90a:3ea5:b0:280:c316:63e1 with SMTP id k34-20020a17090a3ea500b00280c31663e1mr141148pjc.41.1698802137232; Tue, 31 Oct 2023 18:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698802137; cv=none; d=google.com; s=arc-20160816; b=z8R1azZ8pjYuwP9x4M75aPmE+o6+0h70Y5n4PHHqZdnTsC/KgCge/WZWi3M8Knp4Vn z7JewAfxTWtuuSsKx6YV0V6oSJXqeyGPr7u2eR3rYbAmcQToOpRoy78zUdIKjUq4lKMK gO3RZ5fbs50ZVohP0zuy9QYE8mxwxcHa1C+dQ2XntCBFUJ7qVHi+D11Jb7gXFZSmRozM /wcCu/oiVqqji1lHL4k+odptUBEbzwFzzm20ImtA5WYoec2AVVjFWgHXj+MVO8Fjz8Nl 0Ifcn+fcm+R3qwQ0HjOPMYNBxu1nzKwAjQvXZrFC31IWdt/GQPziog0YarhPWBcS35AR mVlA== 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:message-id:mime-version:date :dkim-signature; bh=VxjREVhKIwNUHPrTEbniLZS6ji7rcCI9L7LUymPl9mk=; fh=9PK6N11PLsyzA3LsnqKYOrru3br2ainTfeyQbbmwvDY=; b=j+aZgp44eJe7zlV2jkVYDwhoP4JKOL8rGxLjoaJqntFvduEf9Egayolw0YSit9QsjR pZOA7TATTP8sYyu3AJ+OMcQKQmPr9v32Hnd1Q17waW0SNclVcUDSNDsFjD7PDo0cjm8x 0GVU6Ay1/uUf7Yfyau4iwonE8aRMceLj/u+RvXgM+O3DydIYtNXuEtIpvY38IoxfsMPW leQVX12n8atn0Vi7SutU0oPTU1xEqWNMU9JgRoMTAAGFkeUdHONeyzPiQquism5YCnSV Y/LO60cDUtiEoBCSkxqeLh3KzotggxRAMF2KFE2NisEKIFaZsmgCCMjwctHOZqeIXLFa 40pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cBl+Hb5H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id gz19-20020a17090b0ed300b00280072b397csi1907382pjb.30.2023.10.31.18.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 18:28:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cBl+Hb5H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5664D811F924; Tue, 31 Oct 2023 18:28:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345060AbjKAB2y (ORCPT + 99 others); Tue, 31 Oct 2023 21:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345135AbjKAB2w (ORCPT ); Tue, 31 Oct 2023 21:28:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4EBDF1 for ; Tue, 31 Oct 2023 18:28:49 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da2b8af7e89so4545055276.1 for ; Tue, 31 Oct 2023 18:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698802129; x=1699406929; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=VxjREVhKIwNUHPrTEbniLZS6ji7rcCI9L7LUymPl9mk=; b=cBl+Hb5H45g1Zs6aUOl/J0Z6Xf2sgzRwQ/ZCiOqF8NtuAId5Syl15yUc1yhXsZ7v69 nRS9vVfLU4Ziu/YQaa6koE9UAGFXA7Zw/0jUF/4bHmhADxwYMn7c7iX50FBxVPaA9lEt 9cTz+o/zgktS99MB2oxMDE3Op6XZENrCYemmJp1wqCjfnuQLS5PovYg4oVCLdDHyl6vE Ys8yUu57Bd2X70uwsGw9UHDks/MukaAtcbvhI6glrPExwaSLhhLnSncM0BVz4QDxU1Cs 1TdqH70uy2YjCzUMr0NOtfJXIMAFwGOX6VmDWNkLQQlzVIj/1wj2c0NPTZNjxvmqT4dC 7C8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698802129; x=1699406929; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VxjREVhKIwNUHPrTEbniLZS6ji7rcCI9L7LUymPl9mk=; b=qiRZ9mj7KJlLAvCMAbk8GRLSeeiI7f/WEiL81N0DPa1wPWfu7MxbODNhSwcTjqOpbr 5KwhMJ2vBfb9fCgLMOM5IrMluNBybmC6qF2vvbAQ2Kqoqqc4BUKTBQg/jRAL8UMn1odS t4MR6GqecjTF4P3sseaHc907xBRXC8u9u1X6/LiB+agzVq62WKvRRG2jQYX3vbLLLYTy b5aHHl42DfE4EM/+Hrit7OeumdrieTyetk/V+WL1B8udELCBJfOuSB/sXVeAAqfWds6/ SWT4q2Qh4PwqJOlsSvYZdVA9B7wPklOVYYX6/iJr9XWjk3B1M2BkxXsf/bO/rIP+lJu+ mYww== X-Gm-Message-State: AOJu0Yzz2z3fQBP87tlTRbO4rzvq/OKSPyEDVCBrFm6FOjgDufnUb9ZK ilvEin0L30yrXV+kvkBs3ZQmXd3pMt0= X-Received: from badhri.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:6442]) (user=badhri job=sendgmr) by 2002:a25:5c2:0:b0:d9a:68de:16a1 with SMTP id 185-20020a2505c2000000b00d9a68de16a1mr276149ybf.0.1698802128834; Tue, 31 Oct 2023 18:28:48 -0700 (PDT) Date: Wed, 1 Nov 2023 01:28:45 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231101012845.2701348-1-badhri@google.com> Subject: [PATCH v3] usb: typec: tcpm: Fix sink caps op current check From: Badhri Jagan Sridharan To: gregkh@linuxfoundation.org, linux@roeck-us.net, heikki.krogerus@linux.intel.com Cc: kyletso@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Badhri Jagan Sridharan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 31 Oct 2023 18:28:56 -0700 (PDT) TCPM checks for sink caps operational current even when PD is disabled. This incorrectly sets tcpm_set_charge() when PD is disabled. Check for sink caps only when PD is enabled. [ 97.572342] Start toggling [ 97.578949] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected] [ 99.571648] CC1: 0 -> 0, CC2: 0 -> 4 [state TOGGLING, polarity 0, connected] [ 99.571658] state change TOGGLING -> SNK_ATTACH_WAIT [rev3 NONE_AMS] [ 99.571673] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 170 ms [rev3 NONE_AMS] [ 99.741778] state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED [delayed 170 ms] [ 99.789283] CC1: 0 -> 0, CC2: 4 -> 5 [state SNK_DEBOUNCED, polarity 0, connected] [ 99.789306] state change SNK_DEBOUNCED -> SNK_DEBOUNCED [rev3 NONE_AMS] [ 99.903584] VBUS on [ 99.903591] state change SNK_DEBOUNCED -> SNK_ATTACHED [rev3 NONE_AMS] [ 99.903600] polarity 1 [ 99.910155] enable vbus discharge ret:0 [ 99.910160] Requesting mux state 1, usb-role 2, orientation 2 [ 99.946791] state change SNK_ATTACHED -> SNK_STARTUP [rev3 NONE_AMS] [ 99.946798] state change SNK_STARTUP -> SNK_DISCOVERY [rev3 NONE_AMS] [ 99.946800] Setting voltage/current limit 5000 mV 500 mA [ 99.946803] vbus=0 charge:=1 [ 100.027139] state change SNK_DISCOVERY -> SNK_READY [rev3 NONE_AMS] [ 100.027145] Setting voltage/current limit 5000 mV 3000 mA [ 100.466830] VBUS on Cc: stable@vger.kernel.org Fixes: 803b1c8a0cea ("usb: typec: tcpm: not sink vbus if operational current is 0mA") Signed-off-by: Badhri Jagan Sridharan --- Changes since v2: * Fix the "Fixes" tag * Refactor code based on Guenter Roeck's suggestion. Changes since v1: * Fix commit title and description to address comments from Guenter Roeck --- 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 058d5b853b57..afc791ab6d4f 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4273,7 +4273,8 @@ static void run_state_machine(struct tcpm_port *port) current_lim = PD_P_SNK_STDBY_MW / 5; tcpm_set_current_limit(port, current_lim, 5000); /* Not sink vbus if operational current is 0mA */ - tcpm_set_charge(port, !!pdo_max_current(port->snk_pdo[0])); + tcpm_set_charge(port, !port->pd_supported || + pdo_max_current(port->snk_pdo[0])); if (!port->pd_supported) tcpm_set_state(port, SNK_READY, 0); base-commit: c70793fb7632a153862ee9060e6d48131469a29c -- 2.42.0.820.g83a721a137-goog