Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3468740pxk; Mon, 28 Sep 2020 19:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYWJ/EtebQxric8G7TtrK0WboeZwc0cmtdBC1fGcniXwpaMLKhJdlDslXlnX1TRjRdkApr X-Received: by 2002:a17:907:408e:: with SMTP id nt22mr1654836ejb.169.1601347412555; Mon, 28 Sep 2020 19:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601347412; cv=none; d=google.com; s=arc-20160816; b=NY+uGXUYWVrlxyuNRcFsxyQKYOehry6mcsT9b5d24DoOE10EIVvvV2Qfazu13K6Q3K 6muywnmx8tihMwQPFHEjBuYrKv/Dg7162bTNgQ2oDRuexztLLSWHfqahx6qRKIOuNvQ3 Z+0at8OozdAkFh+YsCS5icYzEDtBBJtGgpN1gPNrnxIyLO0OQMOTnqouGcSOKhKcjnTj EkDL4SN33T1tSSArZ97ec5zkQxjvoGZyq39G263AJhfOrt4jU50UjGj0fldv1SuE4wez YlByHnrFfPQjcZPEIXwehgW0xKoiskOWba4RNsqiH3toF1EiZn5cWowaLExn0GLZF7BH uSMw== 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=x75HFZapwymuUzmD7TSk+DIPW4mnSh+u9U5hvOiIQ9E=; b=ovkGScuDwFPH8sd3kFwvxEirDwe4NrDYx3wXFaB1kbpdygQBsq9LWLdUFNi4oEBYxC /xz8NiPCb17O1IEELP+06BsH5WfRxG6TTzHiz5Y3tnUHKPuOAmzlGokXaoEk6H5Vxw9w QAAr515qzmV/pOHowfEhGJl4NbR+Vu1pxkp0abMEeLcoRj0qUhjNznPspL75G2ofu49f qWBR8lKmB/XfcXdAKNxUGyxWlZquy4Ly+bmI5JuQxZAZcIBHSgj6tGPdy32ka3felP+2 8TgNJcE33UvEbO4ii1EJjMXkdrLxPX6eZzwW/fXS5u7SjlVmR41WzNix1SRFaWSKvkOI CI4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=V2HGIAtr; 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 u2si2027887edy.251.2020.09.28.19.43.04; Mon, 28 Sep 2020 19:43:32 -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=V2HGIAtr; 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 S1727450AbgI2Cka (ORCPT + 99 others); Mon, 28 Sep 2020 22:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727435AbgI2Ck2 (ORCPT ); Mon, 28 Sep 2020 22:40:28 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 046C4C0613D9 for ; Mon, 28 Sep 2020 19:40:25 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id m13so2412809pfk.19 for ; Mon, 28 Sep 2020 19:40:25 -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=x75HFZapwymuUzmD7TSk+DIPW4mnSh+u9U5hvOiIQ9E=; b=V2HGIAtrM4/NiDd7cJAJDQWJfnMFj+h/XnxOrAkJeKV3ATi42p07OXaZKcR2UB81GC 2iM1rR/kf6fSEWdrIzTHLvrKEcucX/Nr3u71MNgzTbmR0DMf4F4GjM0nsYi9zfQU7Do5 uKDHitwlbeJWEYu+BPTg70TNx3EjZLcV1dZ8zmxIOSnWB3O73LlGHYKoVrPsyTESXIGr 0k/nXFCSYXT4TDEnNG61zxQ66YV9RZgqLwpqzSKvUSg0ohTbPmvxKeJS8tYjeWDXAqmq 32LeIqU3FMyKWK/4X+FSm5kkMitBdwk4BhcBjiIcYewHw6zQV4NvyB7b5kGWTvyTXkQS rl2Q== 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=x75HFZapwymuUzmD7TSk+DIPW4mnSh+u9U5hvOiIQ9E=; b=bc3GwiOVH7MPRlB2amuaplFWYUGQAf31TlJNrU0HzzQ2CQ7ewWMDkkzhxUWBw4FwV4 qDKv1Pgqs14Xc7L9X4CbKzZjbdUCyO6NianiVuewREHbuTgG7Ylt2XeuagEmByDyg3+W CRCHP6sKxrKRGDPnyKsg0Yi0v1GEFI5Ms7JQHw+NPtDlST0I4EZA1ealSzUJcToBcMdx JO9CvQsAdc+Otd88N7F3hQtEWMLjafHSohdLHY1p7+g363uldT9PiUXoLHqxZiT0k69Z llieuq0x+OSI0OsWmXFTCUl+vdADBzv93O1sRzO5oUvAN8ZrCJPMTZ9Im72f4Njm8dPd 1/Dg== X-Gm-Message-State: AOAM532SsceJ9Bc5Viw+dbFqLFX+8a973IVyF4S4Ep71ITiTz0k08O6t c1K3XWw49AubBd3RIcT1ZQE8VYjAFl4= 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:aa7:8612:0:b029:142:2501:3967 with SMTP id p18-20020aa786120000b029014225013967mr2139357pfn.44.1601347224432; Mon, 28 Sep 2020 19:40:24 -0700 (PDT) Date: Mon, 28 Sep 2020 19:39:56 -0700 In-Reply-To: <20200929024004.244992-1-badhri@google.com> Message-Id: <20200929024004.244992-8-badhri@google.com> Mime-Version: 1.0 References: <20200929024004.244992-1-badhri@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v9 07/15] 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. Changes since v8: - None. --- 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.709.gb0816b6eb0-goog