Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp276687pxj; Wed, 16 Jun 2021 02:02:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznK4Xt1gYwSfj+F5GZjNOfoS78VJD1buOZTdM6xrQ6dPnAVJaeoy5a12U4Ve/vx6Z5oc/W X-Received: by 2002:a17:906:2419:: with SMTP id z25mr4165619eja.343.1623834147576; Wed, 16 Jun 2021 02:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623834147; cv=none; d=google.com; s=arc-20160816; b=nNLiWGej8CeUeS5DWsOSVMJhgBtkVJz+VTNOrzR2X0Zm+ZzWNCoMmsjXt0/fnGBx4/ /l+mx7z8EUvkM4gCixvpMWnAWrVK8sjiitkiCIr2zC9HrGSld0JB+Nmz0ZDSnJhV50cr fd/4oXtw+5oU/Ujh8KWPEC67/f/ZB5gLhLjlZ43kpSlIOlhy3VHnc/nsr4QyJic1cadV AKwq+dp6P3fWegOBkVPbt0SrKiZo5qFpy6sdmcsA67Z3P1YwMEk8+58jg+qoVbJfU8iB vLAul6K1S/F0nhpyYllf6q6N4Doey1e4mI+ha4XMFGQggDFNRlY9QChPKPV9teoXa3l6 lAWQ== 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=3M0UKlv9SOpLXUL9qCPgM2BG4Do5o9apkVkW/TG2GZY=; b=RVcaRjfjMABD0aWLGFpalle7xMrZgyKwsKXot6TLjrDMlLnT927b+P9PgMiDBn10CP hU1c0iHkBGrWvPs31ujcSjRJsS3MJjpqM7njuXeKYWthl8nlPue9wSJ5YrdMCwBD4MTa uOknMT5KrEkyaGHFrvaP/RO51pvW71xKUDyELSP39vnw1E2JuV93tKixa88jKKMiOVki +52qG9zsRnBNl1kDQGPKoqOmzig609l0HY3dmMpYjKXLsLm2Z/3uecVSsr+ekbOIMZjA OhUnt7mk/YGfuAVvhit9DK//RUVEYy+zuHQQzbINbsOS7pci0kHpo7lfXZmhIYR2uf1y PgeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XUUaWCKm; 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 30si1623647ejh.725.2021.06.16.02.02.04; Wed, 16 Jun 2021 02:02:27 -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=XUUaWCKm; 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 S231358AbhFPJDP (ORCPT + 99 others); Wed, 16 Jun 2021 05:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231336AbhFPJDP (ORCPT ); Wed, 16 Jun 2021 05:03:15 -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 63E18C061574 for ; Wed, 16 Jun 2021 02:01:09 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id r5-20020a2582850000b02905381b1b616eso1949895ybk.6 for ; Wed, 16 Jun 2021 02:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=3M0UKlv9SOpLXUL9qCPgM2BG4Do5o9apkVkW/TG2GZY=; b=XUUaWCKmiuW4vDogg4QoHBx8qvu2ygQ5gyuUydllq4h5NX0BZFN3ZgFb/opCPL9Haq JWmayPho/GZFgz9Da110xPx/UXrlBT/2W80DWm3Lb8pmJ0ODrvmwwwRmPVEF/2XuLb+E sJImWCIX0ilq5YpZFF1sRelBfRbtaOlp30NwzxS1BwxWOazp3oZGGxBKJR8F+/rrv6dy 2bsAvAVWCAXPDokwd7GHCN+4rRJLH4qOMXEan6oF8RrxSaTv0wm7OimbmFCtvHHvTWxY 9oEAshM/jUwG3Mfi4n7EluXJhOXsl4KY7JAIsTfypH9Et8TubFZwwLGdxGGKCcQPk0JR YNbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=3M0UKlv9SOpLXUL9qCPgM2BG4Do5o9apkVkW/TG2GZY=; b=A7U3E+XaS3ZyTbLV0rOptFS2HWr0oupkv1E535TjgHxxQZKCwzQnDbBVWXIvoYf81X iY2nNF1BNkqFiF4ErKJJsg1ixTvclxdi4cHrjAsqJeMRR3X2hWyM5fZ3Zzhm4uCB86J3 ESRljlhqKCvf8MIPTlbEhlwPTQTuBub1PZsIwMvK88TlSRk3zDlq0witOIbgegzEoXG1 mR+2StGz5Xch4sfpir5bpsFxy2J3FNWmQ3HCSORydycrsbPXYHfHNlCgl4jDOzRcia0r hq/1KBSpmwTPh6xaNcyKR50SnDa89c0tKT2MHngyx0C0pe+nJOVNmkAD0hn0hRpUu62O dd4Q== X-Gm-Message-State: AOAM5314YxmbIrdVj/H3VmmGgur3YfbSIkvrE1b9Y9Tmh08ZddR2S+JP +LK92kkPJ/cWw7NZJ8IZxFLOaXbHFkOe X-Received: from kyletso.ntc.corp.google.com ([2401:fa00:fc:202:490b:5c68:72a5:d6d7]) (user=kyletso job=sendgmr) by 2002:a25:9bc4:: with SMTP id w4mr4516910ybo.168.1623834067902; Wed, 16 Jun 2021 02:01:07 -0700 (PDT) Date: Wed, 16 Jun 2021 17:01:02 +0800 Message-Id: <20210616090102.1897674-1-kyletso@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v3] usb: typec: tcpm: Relax disconnect threshold during power negotiation From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the voltage is being decreased in power negotiation, the Source will set the power supply to operate at the new voltage level before sending PS_RDY. Relax the threshold before sending Request Message so that it will not race with Source which begins to adjust the voltage right after it sends Accept Message (PPS) or tSrcTransition (25~35ms) after it sends Accept Message (non-PPS). The real threshold will be set after Sink receives PS_RDY Message. Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") Cc: Badhri Jagan Sridharan Signed-off-by: Kyle Tso --- Changes in v3: - move the timing of setting threshold for Fixed RDO as I did for PPS in v2, i.e. move it to tcpm_pd_send_request. - add Cc: tag for Badhri - update the commit message for the above changes Changes in v2: - move the timing of setting threshold up to "before sending Request" for PPS power negotiation so that it won't race with the Source. - PPS: if it fails to send the Request, fallback to previous threshold - PPS: if the Source doesn't respond Accept, fallback to previous threshold - update the commit message for above changes drivers/usb/typec/tcpm/tcpm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 197556038ba4..b1d310ab84c4 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -2604,6 +2604,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, } else { next_state = SNK_WAIT_CAPABILITIES; } + + /* Threshold was relaxed before sending Request. Restore it back. */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, + port->pps_data.active, + port->supply_voltage); tcpm_set_state(port, next_state, 0); break; case SNK_NEGOTIATE_PPS_CAPABILITIES: @@ -2617,6 +2622,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, port->send_discover) port->vdm_sm_running = true; + /* Threshold was relaxed before sending Request. Restore it back. */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, + port->pps_data.active, + port->supply_voltage); + tcpm_set_state(port, SNK_READY, 0); break; case DR_SWAP_SEND: @@ -3336,6 +3346,12 @@ static int tcpm_pd_send_request(struct tcpm_port *port) if (ret < 0) return ret; + /* + * Relax the threshold as voltage will be adjusted after Accept Message plus tSrcTransition. + * It is safer to modify the threshold here. + */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, 0); + memset(&msg, 0, sizeof(msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role, @@ -3433,6 +3449,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port) if (ret < 0) return ret; + /* Relax the threshold as voltage will be adjusted right after Accept Message. */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, 0); + memset(&msg, 0, sizeof(msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role, @@ -4196,6 +4215,10 @@ static void run_state_machine(struct tcpm_port *port) port->hard_reset_count = 0; ret = tcpm_pd_send_request(port); if (ret < 0) { + /* Restore back to the original state */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, + port->pps_data.active, + port->supply_voltage); /* Let the Source send capabilities again. */ tcpm_set_state(port, SNK_WAIT_CAPABILITIES, 0); } else { @@ -4206,6 +4229,10 @@ static void run_state_machine(struct tcpm_port *port) case SNK_NEGOTIATE_PPS_CAPABILITIES: ret = tcpm_pd_send_pps_request(port); if (ret < 0) { + /* Restore back to the original state */ + tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_PD, + port->pps_data.active, + port->supply_voltage); port->pps_status = ret; /* * If this was called due to updates to sink -- 2.32.0.272.g935e593368-goog