Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp723708lkv; Tue, 18 May 2021 18:21:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKx4GCqkmKHKX5g59vuifGZP+eCK/YNEObyXhhtQ2f6M7W0T7gNEDhz4nbBu6qGzs6P9xW X-Received: by 2002:a05:6e02:1250:: with SMTP id j16mr5787435ilq.217.1621387316059; Tue, 18 May 2021 18:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621387316; cv=none; d=google.com; s=arc-20160816; b=uUtPxeFfHQ9AhU/FFEiLpVIz7vzLVtr3SNBVY5FJyDge8Y7PJcoKzcbXO86BOA96Ay 0DpuHd2EZdywVe+9eZL4p7iaVP9UOZzo+ec3ea4Z5kDYI3fIydfbwK9i+czobiEmsxqp xpqzdZdGZz1VmiXtPjpD/XZQJvpFlxrE6VLOnVY7e9iyJrTbOO/sV7MtGYCr3VClThzU m1zybqCADEwsQOJ8iqdZYlUcfbF9TbX0miAZwwCB3Ka6wF9AVWFF1nUG0i8YtGovsN03 Db9dKVSlrorgkBjB+tTV7GVTaKB7kTBxb/45i2bZFF8M1/fL3iK+bdAiE4RP9mJt0df2 E3ww== 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=3ZBMym5AurysGIW0Fwet/rBzMLRVIo4cf6ykZqhV7jo=; b=h8lrpLJzGLG2oRB62H40cY4jjOvxXbQjDF9T4AmxO4FLqD37HvdEEzEmCNtFtqDS2B TJmEcNYYjtuJZI+jTpXSSXy7GdpD0sggYmOvj8IWZBu/4KfMoSnNMa9rTGLQ/SMTrVp4 wirpUtyM90Z+na3Q+ohfUDt0wrQkxFITsyHUv+uRrEGnBwxshvSMLW9DoSK/miAMY4W9 XZzliCdDoyYFSe/lwkbPzxOVU1IG7kynsZorbhrSOOm2B+z5JglR+euvIplim1WoZGvD /+HlDhBbH1taqVe3V11LFdvxn3TXUZRKHT1h4IhOgy6IGkpv4V+MLvKOjEvMB2ipCyEm zOnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="pi/vYI0E"; 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 d9si12415279ils.122.2021.05.18.18.21.42; Tue, 18 May 2021 18:21:56 -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="pi/vYI0E"; 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 S232977AbhEQTWi (ORCPT + 99 others); Mon, 17 May 2021 15:22:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232859AbhEQTWh (ORCPT ); Mon, 17 May 2021 15:22:37 -0400 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 B8C69C06175F for ; Mon, 17 May 2021 12:21:19 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e138-20020a25e7900000b029050df4b648fcso4501680ybh.7 for ; Mon, 17 May 2021 12:21:19 -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=3ZBMym5AurysGIW0Fwet/rBzMLRVIo4cf6ykZqhV7jo=; b=pi/vYI0EukHl/lVCJaK0Iq2fyoHmEUVDnV76OUtJhXtlJy+WuSJk76gU9XhjKDa9fi cwX5G7wLwCZxkMAzC5MmPZg+/3p5X0/TvUbCiwiRLn05qet8zBXRB8FwSsBGGNJKmBej Mq8ub33YMLGwpj2ymL8PDTVMwhFvbC2xj8r0rD5WgG1oPDkyRn5K2RCovJ9MY+zv47Gt hV1ubrcLrh5vopQH8o3C5WnjqFSZi1PvLN9nW4cV6nnIlB/b8MvX0lufXlTHItTBKXdN ksHnkroxXaESg1+0ENKAYtujDUnun1p+BCgHFTBl4w+O7Cqiqw5rgnn6NUoO//cr8VcP GCag== 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=3ZBMym5AurysGIW0Fwet/rBzMLRVIo4cf6ykZqhV7jo=; b=ZX0F7/iCqkgQbeQ3q0K/7H844MTn+YgzANF3YktKfCtUMCspKrGuOUoxlKYzYbc23Z Q1+X7UREvm2lnV6vm82XFykowmAeR61Uekrd2qS/CkSeoSYDMTNXcRS5Fb+rkzck/qW7 XH8dBpbqtwK3DELR/K7Q2tXw9Gg5OmWqauiSJAS72Va2FKs+UcCgg5EOSB1qN4VqaVHO csY/ZR8KY5IEq8Mx+qenNOc+ahP6v9WglF6nnc3D72AS0pEAC/6uPVaoldr8PCyX805d KY0dsWs8xQJe3VsntDkC3FKwGXM8wqEw0mRpZBGM2prHSVYhvhjKA9wwFLl3TAg6tgb7 DinQ== X-Gm-Message-State: AOAM533enhaBt/a3FBBtLCyRH3EDiG9Go8XUpqitLnNkIgfUGcdMDT2K 0fmNFtfq1URDjLOVIlsDeWhXH7/Nmao= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:b562:7011:fe35:1c9e]) (user=badhri job=sendgmr) by 2002:a25:dc8:: with SMTP id 191mr2026244ybn.102.1621279278992; Mon, 17 May 2021 12:21:18 -0700 (PDT) Date: Mon, 17 May 2021 12:21:10 -0700 In-Reply-To: <20210517192112.40934-1-badhri@google.com> Message-Id: <20210517192112.40934-2-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 2/4] usb: typec: tcpm: Refactor logic to enable/disable auto vbus dicharge 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 The logic to enable vbus auto discharge on disconnect is used in more than one place. Since this is repetitive code, moving this into its own method. Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") Signed-off-by: Badhri Jagan Sridharan Reviewed-by: Guenter Roeck --- Changes since V1: - Added Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpm.c | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index b93c4c8d7b15..b475d9b9d38d 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -771,6 +771,21 @@ static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc) port->tcpc->set_cc(port->tcpc, cc); } +static int tcpm_enable_auto_vbus_discharge(struct tcpm_port *port, bool enable) +{ + int ret = 0; + + if (port->tcpc->enable_auto_vbus_discharge) { + ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); + tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable", + ret); + if (!ret) + port->auto_vbus_discharge_enabled = enable; + } + + return ret; +} + /* * Determine RP value to set based on maximum current supported * by a port if configured as source. @@ -3445,12 +3460,7 @@ static int tcpm_src_attach(struct tcpm_port *port) if (ret < 0) return ret; - if (port->tcpc->enable_auto_vbus_discharge) { - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); - if (!ret) - port->auto_vbus_discharge_enabled = true; - } + tcpm_enable_auto_vbus_discharge(port, true); ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port)); if (ret < 0) @@ -3527,14 +3537,7 @@ static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capab static void tcpm_reset_port(struct tcpm_port *port) { - int ret; - - if (port->tcpc->enable_auto_vbus_discharge) { - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, false); - tcpm_log_force(port, "Disable vbus discharge ret:%d", ret); - if (!ret) - port->auto_vbus_discharge_enabled = false; - } + tcpm_enable_auto_vbus_discharge(port, false); port->in_ams = false; port->ams = NONE_AMS; port->vdm_sm_running = false; @@ -3602,13 +3605,7 @@ static int tcpm_snk_attach(struct tcpm_port *port) if (ret < 0) return ret; - if (port->tcpc->enable_auto_vbus_discharge) { - tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, VSAFE5V); - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); - if (!ret) - port->auto_vbus_discharge_enabled = true; - } + tcpm_enable_auto_vbus_discharge(port, true); ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port)); if (ret < 0) -- 2.31.1.751.gd2f1c929bd-goog