Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp997274pxu; Fri, 11 Dec 2020 21:59:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfj4g9Oe/VWIQWcrlFkf7AdgL0MgmLiJpVlGQNx1rUVQw4w9TSsRLA39XBaff0RJN8iL2P X-Received: by 2002:aa7:cb49:: with SMTP id w9mr15778514edt.357.1607752763115; Fri, 11 Dec 2020 21:59:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607752763; cv=none; d=google.com; s=arc-20160816; b=TCiorw2l2hKKFbW4RRTzSvM3K5UXVV2O9uOD+QmR88hPW2BW/vtelblqYwxzNyzdqX yDvqj+rtN8Adfvym4xYIOAAIYaopU9VNnHbFslb8GbdkGRG13VxA4Iw0pbGM6uWFuMZv SDYEnvTFXe+cH+uc9c8/mjwK8mC7dzrIzdmneQoJsPJhKUqZX7GiPkgmbciPYEQOvQ8V BoP0SRqOO8An4fbFhM6yPkMQB3j0FLLDxZDVGoSNmIEjSHUbFIqBzyw/KFEkKWgevqdv ckaFWOsx2vQCOPyOvuXX1MuIX/2/sJCRnlwHql9qsXHAuFEZ3dhO+TjQOndsyf8hLDHI T+tA== 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 :sender:dkim-signature; bh=m0DrwSxF5qR9n1iY7YgNaOh8SW09GUyz6Ol3J+mXr+U=; b=HfbRAlZJwGj9Ju8cDfHYa236Zx3vrohLMiBgOX05tZNvIzgYF1UgL6rQalAtn5PJPM M7u/nKZ7yRIx/NFMMT33a6jI+JrSpUisEOLkoX8AAb09V1COQf2xYQe3GJyVNU/n5YmY 4tKZI+AiXjRbbEvG1nbgFzEGRLRwjEmcLwJYVmM7PUQiGt/h+kanS7zPtDuLG+isUqaB bTwec0umtL77N0udPij5PzbUqyHH3IPF0QKkHaFSb9/TnAfJkfmNDpsi31vyd42NbFDC 8lKWJ4RmwRUnfT3OePtQRtjMlU+PkIwyQ4ws2l4VNmHH8qXoDFRAHWeKHPA6C+iOleSA 8KoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rtJ0RIZT; 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 r9si5997314ejb.246.2020.12.11.21.59.00; Fri, 11 Dec 2020 21:59:23 -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=20161025 header.b=rtJ0RIZT; 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 S2436798AbgLKHUU (ORCPT + 99 others); Fri, 11 Dec 2020 02:20:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436799AbgLKHTz (ORCPT ); Fri, 11 Dec 2020 02:19:55 -0500 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 789E2C0613D3 for ; Thu, 10 Dec 2020 23:19:15 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id v9so5872345qtw.12 for ; Thu, 10 Dec 2020 23:19:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=m0DrwSxF5qR9n1iY7YgNaOh8SW09GUyz6Ol3J+mXr+U=; b=rtJ0RIZTlwQdQWlSPxuR3vOa5DfGSmbjmTZcnqckvebY6+WfCZ28FM95LkWIcA5Aaa 950sW7+R45o33bmOBbsJgqO4sxOT/7S3YrKoD+UUL8kz0J/jgNwd0wJI8UZcl9RJ2ID4 nXRNSY6adSUV3NiysAv+DAuGWrzsHymlYt4OFKxWcgeAxLXSpVGPNXRF1cbNybigF1NO 2LKcreA78JhdpHN30Wl/spIwxHl7Kh7FuBnFdZ7b41k3UVj1D+RMiPmWck+iIOwKEWuL NnKp1XBcOEDmn5FZQ09tEECmisEOBjhPu13vjGfkHCEYExZ1CLMr8eMYV1e6nnP3BbDN 9+Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=m0DrwSxF5qR9n1iY7YgNaOh8SW09GUyz6Ol3J+mXr+U=; b=BolFtX5/3crNrTuri1QdkZc5+V66wb9Yb+sw79OlzTMEIPh2U4zwTGmgyml1N4xeCJ 1nAuj6Y1upqyQG+yMPz8ldbD4G8WtkZ1Fzd/MWyN0KvirHgVvAJJ8b2Rv+Da9q68QrqO F8tGjdVxLqESmEpl3Nxb2u+dlsPtP92XEH2qgr7LKfFTFWXrSXP6C4sf+aqHsPD1jQip r1lke7ORx5LVrEIwosx7Syp73GL3OkKb5okelLbFZcPOKpIeghwDh9y7SyoirQAeZhmS WnBz8L/86M2UXT9us2BOu7GMFy9pNE9Q1d9B781vF/J3sv2uR5NL1UWHkroKI6V6Y8/a i0PA== X-Gm-Message-State: AOAM5334eU79sPUrGmJX+h0HaQirJfpDx+1reAGHQ0+VhwEUoAJeYctD FtDRVaLdVTRwIsYXjRiU4HQFsXIfbqc= Sender: "badhri via sendgmr" X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:f292:1cff:fee0:66cf]) (user=badhri job=sendgmr) by 2002:a0c:c405:: with SMTP id r5mr14548293qvi.4.1607671154568; Thu, 10 Dec 2020 23:19:14 -0800 (PST) Date: Thu, 10 Dec 2020 23:19:11 -0800 Message-Id: <20201211071911.2205197-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog Subject: [PATCH v1] usb: typec: tcpm: Update vbus_vsafe0v on init From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@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 During init, vbus_vsafe0v does not get updated till the first connect as a sink. This causes TCPM to be stuck in SRC_ATTACH_WAIT state while booting with a sink (For instance: a headset) connected. [ 1.429168] Start toggling [ 1.439907] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected] [ 1.445242] CC1: 0 -> 0, CC2: 0 -> 0 [state TOGGLING, polarity 0, disconnected] [ 53.358528] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected] [ 53.358564] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS] Fix this by updating vbus_vsafe0v based on vbus_present status on boot. Signed-off-by: Badhri Jagan Sridharan --- drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index cedc6cf82d61..58a6302c549f 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4794,6 +4794,24 @@ static void tcpm_init(struct tcpm_port *port) if (port->vbus_present) port->vbus_never_low = true; + /* + * 1. When vbus_present is true, voltage on VBUS is already at VSAFE5V. + * So implicitly vbus_vsafe0v = false. + * + * 2. When vbus_present is false and TCPC does NOT support querying + * vsafe0v status, then, it's best to assume vbus is at VSAFE0V i.e. + * vbus_vsafe0v is true. + * + * 3. When vbus_present is false and TCPC does support querying vsafe0v, + * then, query tcpc for vsafe0v status. + */ + if (port->vbus_present) + port->vbus_vsafe0v = false; + else if (!port->tcpc->is_vbus_vsafe0v) + port->vbus_vsafe0v = true; + else + port->vbus_vsafe0v = port->tcpc->is_vbus_vsafe0v(port->tcpc); + tcpm_set_state(port, tcpm_default_state(port), 0); if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0) -- 2.29.2.576.ga3fc446d84-goog