Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3410041pxk; Mon, 21 Sep 2020 12:58:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKwZ5CjuhqtnZB51IWW1K6Z7IIwVWYr3UEf/zSNv4lxeT+jpYWT5FsyTQciWuv8cgFDMIt X-Received: by 2002:a17:906:2458:: with SMTP id a24mr1169296ejb.353.1600718322982; Mon, 21 Sep 2020 12:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600718322; cv=none; d=google.com; s=arc-20160816; b=jpEyYZxU1OHqvRC8rPdzveWrUU3prDkFIbHpoMiJCS9lQHU1qkm/HcyjkkwnsmpNK+ HZlUk6tNCUzYD/3lowg0nGTgCEmJU2jwfj9i33yyVJ98HwZlX19D9bSLsHLwRYegOKQE 49c/sEwldrDy8Skj4/R8OZlkHAmsj7HvMuElN14nitc5KgpNJ3w08oQoehax509VXdJd ZpQWZeVT50mkdYtDyPmhnDg16JhYNfI2VTQznsWZDAU4RG4inzeYhqGFv9/PZDsdlU03 EYdAa5Qz5+udpZog8aE2vxR6fpAWhaBQOrvhPK6AfPITsvEQUGgszgrL5CJQW88Mck6+ 6ANA== 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:sender:dkim-signature; bh=bm2T+CrCpRo3vv+J+7TT/LPjfYta6ghVQoeicKU+M4k=; b=kfHyvWra5HxV7DA9JH5fmy7Ki4dJs1g3rrmW8UXMgLJd24qudriF9KXu1oAcmUuURB tfUGYVbNXNjdgUcAHrPyG+xCYnGh9jVXadJlbrE1vah+BhcZ3xdQbCNz0BHt3MPO0fhi PP6xDyclUnyVLPouoZKhMl7QQEegWoPn9PgTAigDOggAXjrJCoJb70uSKuua2rEEqeb4 UGhSfXPeJf7/SJSm4aMLxIyL0+WN9Vu8om+xEB5yTxFwumNk8fX2UxieU9z2AdnyL2Lh jm3iz5Zn1C4oVR3hmHPl4SGaRN+0Rd1UBRRfhnWBj8/mTceo2/d8DFsSQs7h8DRjU/6B /L0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="n+ZIG19/"; 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 t12si9057413eji.422.2020.09.21.12.58.19; Mon, 21 Sep 2020 12:58:42 -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="n+ZIG19/"; 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 S1728405AbgIUT4i (ORCPT + 99 others); Mon, 21 Sep 2020 15:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728316AbgIUT4R (ORCPT ); Mon, 21 Sep 2020 15:56:17 -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 46948C0613D2 for ; Mon, 21 Sep 2020 12:56:17 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 140so12863813ybf.2 for ; Mon, 21 Sep 2020 12:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=bm2T+CrCpRo3vv+J+7TT/LPjfYta6ghVQoeicKU+M4k=; b=n+ZIG19/CrRbjvYH5MKj96POy8PjEe+b1pxFwzwz5ohqNcAkjQFC/wiyCLMFDauK5i 6qBQ50qbJ4Phb6YhXgRTpgDj3rW1e6qjQwK6/FS0TBRIrVD5qWTcCl9aMp+idI4j76EV 5+BjrE6V+FPGBFSLB+kahfzcLhSC/o+XiXs5r2hIKqfTMQ0ByMMBzqv4M8hOXp25wVC7 HupwBUauPOQh7pwWEI1ZRhimvyu7IywcDE9PfQKTxrDLECGgPI83R9PoBO5oqzO0hQLk 2dhDjdSOH6XtWhRuP0TQ6hsU6GYTEek0uyGTv8tk/xdVMw4gX1bMwevpz1OOvssgOC7x POjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bm2T+CrCpRo3vv+J+7TT/LPjfYta6ghVQoeicKU+M4k=; b=Jd+oBD37bQQjuLAVLtuiGR5Z6bqEuTzdYfgTSvOQlEr5gQ2nK4vkJOpuSL/geMBYsF tBErkR3vZKxwIRpygjqqKe/Aj6R9/qYR5n+RClyAQYsmWbOfNAaFer5P2k/Y0YPT4E0h a5SooxCfCf4Ss9s/D9+ngQLA7M6LDee+ph2RYVIWuWSi1J2ytEUbShe66SiGvukTcice LpM8GrFeVx06uPcrWMBoyaPis7n7qXO1ZGnCN7kRAKgZ+kM7rVgFWMfsBce+Ri5SJqSX pH+wrbtgDJn4TPSAUiwr4M1+dFHwuCcgqbEw5ycVBXe+KVp+81bVT7RKx+5ObKauqH9X Y8bA== X-Gm-Message-State: AOAM532I7S2I2dkKt/Pw+029AwbHgGnmJvnjY0tyoYOKkW2h8zHdUa3c J2zxt1w2WMsORjuir23mEAUt+PrUc0c= Sender: "badhri via sendgmr" X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:1:f292:1cff:fee0:66cf]) (user=badhri job=sendgmr) by 2002:a25:2f85:: with SMTP id v127mr2189523ybv.372.1600718176459; Mon, 21 Sep 2020 12:56:16 -0700 (PDT) Date: Mon, 21 Sep 2020 12:55:51 -0700 In-Reply-To: <20200921195555.1050731-1-badhri@google.com> Message-Id: <20200921195555.1050731-7-badhri@google.com> Mime-Version: 1.0 References: <20200921195555.1050731-1-badhri@google.com> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v8 07/11] usb: typec: tcpci: Implement callbacks for FRS From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Rob Herring , Lee Jones , Mark Brown , Maxime Ripard , Alexandre Belloni , Thierry Reding , Prashant Malani , Badhri Jagan Sridharan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement tcpc.enable_frs to enable TCPC to receive Fast role swap signal. Additionally set the sink disconnect threshold to 4v to prevent disconnect during Fast Role swap. Signed-off-by: Badhri Jagan Sridharan Reviewed-by: Heikki Krogerus --- Changes since v1: - Changing patch version to v6 to fix version number confusion. Changes since v6: - Rebase on usb-next. - Fixed formatting error. - Added Reviewed-by: Heikki. Changes since v7: - Rebase on usb-next. --- drivers/usb/typec/tcpm/tcpci.c | 17 +++++++++++++++++ drivers/usb/typec/tcpm/tcpci.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index d6a6fac82d48..f9f0af64da5f 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -268,6 +268,22 @@ static int tcpci_set_vconn(struct tcpc_dev *tcpc, bool enable) enable ? TCPC_POWER_CTRL_VCONN_ENABLE : 0); } +static int tcpci_enable_frs(struct tcpc_dev *dev, bool enable) +{ + struct tcpci *tcpci = tcpc_to_tcpci(dev); + int ret; + + /* To prevent disconnect during FRS, set disconnect threshold to 3.5V */ + ret = tcpci_write16(tcpci, TCPC_VBUS_SINK_DISCONNECT_THRESH, enable ? 0 : 0x8c); + if (ret < 0) + return ret; + + ret = regmap_update_bits(tcpci->regmap, TCPC_POWER_CTRL, TCPC_FAST_ROLE_SWAP_EN, enable ? + TCPC_FAST_ROLE_SWAP_EN : 0); + + return ret; +} + static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -611,6 +627,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) tcpci->tcpc.set_roles = tcpci_set_roles; tcpci->tcpc.pd_transmit = tcpci_pd_transmit; tcpci->tcpc.set_bist_data = tcpci_set_bist_data; + tcpci->tcpc.enable_frs = tcpci_enable_frs; err = tcpci_parse_config(tcpci); if (err < 0) diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h index 82f021a82456..5ef07a56d67a 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h @@ -16,6 +16,7 @@ #define TCPC_PD_INT_REV 0xa #define TCPC_ALERT 0x10 +#define TCPC_ALERT_EXTND BIT(14) #define TCPC_ALERT_EXTENDED_STATUS BIT(13) #define TCPC_ALERT_VBUS_DISCNCT BIT(11) #define TCPC_ALERT_RX_BUF_OVF BIT(10) @@ -37,6 +38,9 @@ #define TCPC_EXTENDED_STATUS_MASK 0x16 #define TCPC_EXTENDED_STATUS_MASK_VSAFE0V BIT(0) +#define TCPC_ALERT_EXTENDED_MASK 0x17 +#define TCPC_SINK_FAST_ROLE_SWAP BIT(0) + #define TCPC_CONFIG_STD_OUTPUT 0x18 #define TCPC_TCPC_CTRL 0x19 @@ -63,6 +67,7 @@ #define TCPC_POWER_CTRL 0x1c #define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0) +#define TCPC_FAST_ROLE_SWAP_EN BIT(7) #define TCPC_CC_STATUS 0x1d #define TCPC_CC_STATUS_TOGGLING BIT(5) @@ -74,11 +79,14 @@ #define TCPC_POWER_STATUS 0x1e #define TCPC_POWER_STATUS_UNINIT BIT(6) +#define TCPC_POWER_STATUS_SOURCING_VBUS BIT(4) #define TCPC_POWER_STATUS_VBUS_DET BIT(3) #define TCPC_POWER_STATUS_VBUS_PRES BIT(2) #define TCPC_FAULT_STATUS 0x1f +#define TCPC_ALERT_EXTENDED 0x21 + #define TCPC_COMMAND 0x23 #define TCPC_CMD_WAKE_I2C 0x11 #define TCPC_CMD_DISABLE_VBUS_DETECT 0x22 -- 2.28.0.681.g6f77f65b4e-goog