Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp329290rwb; Wed, 7 Dec 2022 18:56:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6pZQ0BBR+e8AUab/KAc0sMm+cOgscztnO68tT3/tP9hqWFtTcF0i/m43efbNdvMHRhcgD0 X-Received: by 2002:a17:902:7683:b0:186:9fc8:6672 with SMTP id m3-20020a170902768300b001869fc86672mr74843554pll.65.1670468210403; Wed, 07 Dec 2022 18:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670468210; cv=none; d=google.com; s=arc-20160816; b=NP3tvsnVvJYdfsdgM+tw3mbdf14WvVQoXeJJZvg0VVgL2FJVo2CTpcUGoi6/YaFrch /roE1S9BraIJR1oR+FWIBpOqOWmq124ZabCT49ucEMAVAAByGwBRvunH4LlLhgizCjCf OotN8kpLOqKtyg3n+JZwEKXPkxaqNLLi1WYK1yyoWhpFjTtm3WijDwIt2Gdlbq4Lrqc5 N+56VLvRqLhkj06svjDLbjZJm2fBLkc+qc/zppjqnS+4rTs/aXoORWK15J19AcynHcGf Ll83tF6avH/3LYrTYk/ipBzo6TJuMpmHRifl9iG5fbNpgthK1PdNj0mxVU89rM597kwv +yuw== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=SwslB3VPbnLWhTauQf3ujZ3C7cLlwRSqUDF8mp/fjWo=; b=n8/vLla+zfvG29A0MOxkY8Qg8Vb2uiWV0Zf0R+tNNxFHxwroXBNXJhh6cmNk2HfRgI +Yrts9KQ9flKvylyAFPC6XDgJC/yudDBkC1NSjuiCXmAlBH7OwFmIuM+XhVGpsD2IM6q 5+3mvFqqdFV6Z94sIcj/qYJGIyeFkaSkT4C7G/T1OP9f07aNJwKG6NnsmKFGyzBcGh8B 7gJaOkdqHW6dS2dYbNUGXWGduGzCLxZ499Y+atrb6gr47BWbZqa1uQY1rF5VYOj7mzmI Jmp1Zit20JU/Vu2uzZ7lsiStSj8ocf7FyPFLstwfHXZsFkUbcNya89T3JhWTbbCbRMw0 LVZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tkE30ABP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg14-20020a17090326ce00b00189a6834dbesi21038801plb.103.2022.12.07.18.56.41; Wed, 07 Dec 2022 18:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tkE30ABP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229851AbiLHCAy (ORCPT + 74 others); Wed, 7 Dec 2022 21:00:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiLHCAt (ORCPT ); Wed, 7 Dec 2022 21:00:49 -0500 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 17C3292A1A for ; Wed, 7 Dec 2022 18:00:49 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id r7-20020a25c107000000b006ff55ac0ee7so13524773ybf.15 for ; Wed, 07 Dec 2022 18:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SwslB3VPbnLWhTauQf3ujZ3C7cLlwRSqUDF8mp/fjWo=; b=tkE30ABPYDwrpXmTy+HkUzUMJXERWU6ZQFz3gFMwl8yr+YiAv6P3OhUsjDjPAbPfNV WDlE0t7mfl1cD+fjclyjXe/0oTcnX+fFBkYpMlybwN1Lf6ng/eoReAZeThptNZR0RlcQ Wf4jvzjgVD41pGChutjTpiyIVNECJEeijGGdYMDUEg+O/vIoNXmwW1PbF8e5gjaWqA5b +MKmVQdM0wWgrreDYUtHhek/MC4hisCXYkIRKE4S16gtBQA5ud1rOfyeXi3Avc5FzeUV n2Qj/gYZ01vVH/YzvB52SfJp+Vk+bdsodbfAio0huiO/R5YFGNm7TKVZ3ktyTYB5Qzzj ZT8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SwslB3VPbnLWhTauQf3ujZ3C7cLlwRSqUDF8mp/fjWo=; b=ts+VqeFJG9Fw4TkFQ0pu2VyQ3dD8Ul/S9bWfYzbteR9AZ8E0glQvf7+tlUH6Dv4+mD 0UY8HzxjToeSG02Oc/SiTD2kPRrbu25GK/GXVE24und9PNH6hDkB4ZFw70IQYBtS4L+S YRQeJYjX+9xfeXuNYzmW6eXoxM/AsabmJcnLiMp8EuTX9FM2a5gVwVteD2cnEVcc1LuO 8ttdnRyYX0g5Y2g4tDTorAtg8ypR1Plxv4ZpCw0ogCHd12ENEgG+nvPWkQ0qi8teJ0Dc K9ASFTr9RldgaO5ocQ0ap2D61/tO7TKvRFALS0SzOOTc0cQcPWoiTh7n8CDhn1J/Se65 jPeQ== X-Gm-Message-State: ANoB5pnBRkX1gtZkQlkOPLzUY3pgM/TiAsUkxOR2Ol3M2wNFL+xRrwle 55kl1dPva3FsV7MUxwCW9Q2Dj0Rp4eU= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:592e:36a9:5604:2233]) (user=badhri job=sendgmr) by 2002:a0d:e6c4:0:b0:3bc:7270:cb70 with SMTP id p187-20020a0de6c4000000b003bc7270cb70mr55637971ywe.83.1670464848383; Wed, 07 Dec 2022 18:00:48 -0800 (PST) Date: Wed, 7 Dec 2022 18:00:42 -0800 In-Reply-To: <20221208020043.374033-1-badhri@google.com> Mime-Version: 1.0 References: <20221208020043.374033-1-badhri@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221208020043.374033-2-badhri@google.com> Subject: [PATCH v5 2/3] usb: typec: tcpci: Add callback for evaluating contaminant presence 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 , Badhri Jagan Sridharan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change adds callback to evaluate presence of contaminant in the TCPCI layer. Signed-off-by: Badhri Jagan Sridharan --- Changes since v4: * None Changes since v3: * None Changes since v2: * Added tcpci_is_potential_contaminant to offload * disconnect_while_debounce logic --- drivers/usb/typec/tcpm/tcpci.c | 20 ++++++++++++++++++++ include/linux/usb/tcpci.h | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index fe781a38dc82..2aadf785970f 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -403,6 +403,24 @@ static void tcpci_frs_sourcing_vbus(struct tcpc_dev *dev) tcpci->data->frs_sourcing_vbus(tcpci, tcpci->data); } +static bool tcpci_is_potential_contaminant(struct tcpc_dev *dev, enum tcpm_state current_state) +{ + struct tcpci *tcpci = tcpc_to_tcpci(dev); + + if (tcpci->data->is_potential_contaminant) + return tcpci->data->is_potential_contaminant(tcpci, tcpci->data, current_state); + + return false; +} + +static void tcpci_check_contaminant(struct tcpc_dev *dev) +{ + struct tcpci *tcpci = tcpc_to_tcpci(dev); + + if (tcpci->data->check_contaminant) + tcpci->data->check_contaminant(tcpci, tcpci->data); +} + static int tcpci_set_bist_data(struct tcpc_dev *tcpc, bool enable) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -777,6 +795,8 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) tcpci->tcpc.enable_frs = tcpci_enable_frs; tcpci->tcpc.frs_sourcing_vbus = tcpci_frs_sourcing_vbus; tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable; + tcpci->tcpc.is_potential_contaminant = tcpci_is_potential_contaminant; + tcpci->tcpc.check_contaminant = tcpci_check_contaminant; if (tcpci->data->auto_discharge_disconnect) { tcpci->tcpc.enable_auto_vbus_discharge = tcpci_enable_auto_vbus_discharge; diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 17657451c762..548e85fdc7fa 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -188,6 +188,16 @@ struct tcpci; * Optional; The USB Communications Capable bit indicates if port * partner is capable of communication over the USB data lines * (e.g. D+/- or SS Tx/Rx). Called to notify the status of the bit. + * @check_contaminant: + * Optional; The callback is invoked when chiplevel drivers indicated + * that the USB port needs to be checked for contaminant presence. + * Chip level drivers are expected to check for contaminant and call + * tcpm_clean_port when the port is clean to put the port back into + * toggling state. + * @is_potential_contaminant: + * Optional; TCPM invokes the callback for every TCPM state machine + * transition. Chiplevel drivers can monitor the state machine + * transitions to flag for potential contaminant presence. */ struct tcpci_data { struct regmap *regmap; @@ -204,6 +214,9 @@ struct tcpci_data { void (*frs_sourcing_vbus)(struct tcpci *tcpci, struct tcpci_data *data); void (*set_partner_usb_comm_capable)(struct tcpci *tcpci, struct tcpci_data *data, bool capable); + void (*check_contaminant)(struct tcpci *tcpci, struct tcpci_data *data); + bool (*is_potential_contaminant)(struct tcpci *tcpci, struct tcpci_data *data, + enum tcpm_state current_state); }; struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data); -- 2.39.0.rc0.267.gcb52ba06e7-goog