From patchwork Sat Dec 10 18:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 32085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1467072wrr; Sat, 10 Dec 2022 11:36:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf7CXxjecv4gZhZlL25Owtw5NC5I0X7fFERTeqRvaqiv1y/HdPSmmZ3ZVpZS5ZjEc2o9eAmP X-Received: by 2002:a17:90a:d515:b0:219:c1e8:114d with SMTP id t21-20020a17090ad51500b00219c1e8114dmr10288020pju.26.1670700998123; Sat, 10 Dec 2022 11:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670700998; cv=none; d=google.com; s=arc-20160816; b=ftbK/i8CXayTq0Vpuo3Z2lUhsSVxJrqRA5deJc0PR47VQtzS4M6GFwP/csPS80U7oM G91bX2cTWb5AqBm19meyj2NCJGce4MRMgQ+wDhu8N4clOTyW4IygGmWfWM1WhKgp/rZt 2zHODdVa1lbeDsYWXocxHjP1FsB6xaWuqYfOxcfwSjn586KvCgQOi4xvb09oP/57JRXo hBaqylCBpqVcRJkQlpF4r5HSkRhRXFi+yjs/esE16bTrcY0LsZALPWgBgPaB1kIzCC1t ALjIiZhgIvFa0TywBCQKmg1OUUoDZCKhbznyuvolLPuHbmzyimQUagcuOJeLuKnEUsHu tCnA== 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=wDRNns46OiMIOfUacnaTaHtRPFcj4uoQbXwU5dGeZx4=; b=MlEJ56Sm7Oua+2GTG5sQyiyt8V3U6tGQg4u2e825EiC7uVRxMNnOwLT5WRDr9puHqe sQZr6RWAa3SU6o0pW14H+R1NCKa51Mm1IyTgX7nxwrC4vj7fiLKqE3gQ1ac1AOHi3CeE ZASJC5B4ip4lmxMGrdHhZPxI5IVsVHhY/iaTfKrCdpmC6awGH0iLK4NqB3PX/436yMzZ zA1PGVlusjXkfR19br12SE15R3e0Izdd0S+yXT9k+Q2xoiSqDxyyR5/5OBU0YvJoDU7N M/FIXm21vC8bonEpOHLUV46eQZ8OjmCN2tjInfLCwJW0V19omHD6Li2R9Azha5nFMnIz NVTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Q/TbfuyW"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk2-20020a17090b224200b00219ecd75b15si5829588pjb.4.2022.12.10.11.36.13; Sat, 10 Dec 2022 11:36:38 -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="Q/TbfuyW"; 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 S229822AbiLJSvk (ORCPT + 99 others); Sat, 10 Dec 2022 13:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbiLJSvh (ORCPT ); Sat, 10 Dec 2022 13:51:37 -0500 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 61AE313F2B for ; Sat, 10 Dec 2022 10:51:36 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id z17-20020a25e311000000b00719e04e59e1so5388679ybd.10 for ; Sat, 10 Dec 2022 10:51:36 -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=wDRNns46OiMIOfUacnaTaHtRPFcj4uoQbXwU5dGeZx4=; b=Q/TbfuyWo05MMVCw4NRFAc4qPu5GPWVq4HFwhVoP8VFml6PbhGhezYZGkPUX1fLS1a 51K7MP3HhoZgpjN4V8YRlkffjswYV+QduE7hkY1c8N3t2E2ZwcShQHPjo2OuaXtH+AaA fh4s0LYGJC+72OyT3AMLrs2H/vEuboXhFt6goPOQhawEc/RObDaw9cEORq1DERgbUUvM 6S7TIRN1P4QnTzrnGVfMCh9x5HY9yH98Tx8CFGXFwqkbLAVmPAmDo/78d+6xKg7GfOFa XSAbFuyzL1Dkv9qsAxtsnKU4PL1vqzLYpv1s7n/n7AK2cih9gla5C5c8F86Bok/hk8Ba 8Xvw== 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=wDRNns46OiMIOfUacnaTaHtRPFcj4uoQbXwU5dGeZx4=; b=eQ/M+pzHLjJbe3X0Gp8vJGrWKiU+8AqI4Pw6qTNCHQHCu8YZt35OQs513x10ZKIlmI T+by0TekXVuVk4bPlN9uXDXL6hMJ00XRfNcf0ADsnD0KJpbNUVCUGg8F4hayhWur1lJ5 FycOg1Q227NZIscWUUzSMHNFmyxEv+502l4VmPePTJzlpTDWCIz1u7jBvxmxW/UKi6CO NOn3njKh7acWNGHkNlBJO7003p+2CUeyxVTgYRWY0tppH6yQw7Gu4YV3D6iA23euNLXE 3EBI/saKNhAX0EejbaQMyRtyt33HwDXhn2O7a/ZGvbZ5qrYVAT2AC91QN1dEjAowrw77 5n1w== X-Gm-Message-State: ANoB5pny9kYa2IbBolA81u4Z0sGQCtoJTE6wIwm2DxNqtWDrGTSdyql5 k/g63m3LHqVBEYYL7XH6g+gSCatEzf8= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:bcc6:f018:88f8:a199]) (user=badhri job=sendgmr) by 2002:a05:690c:589:b0:3b5:1538:c19 with SMTP id bo9-20020a05690c058900b003b515380c19mr1019381ywb.210.1670698295609; Sat, 10 Dec 2022 10:51:35 -0800 (PST) Date: Sat, 10 Dec 2022 10:51:28 -0800 In-Reply-To: <20221210185129.1094531-1-badhri@google.com> Mime-Version: 1.0 References: <20221210185129.1094531-1-badhri@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Message-ID: <20221210185129.1094531-2-badhri@google.com> Subject: [PATCH v10 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 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=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751856969448688730?= X-GMAIL-MSGID: =?utf-8?q?1751856969448688730?= This change adds callback to evaluate presence of contaminant in the TCPCI layer. Signed-off-by: Badhri Jagan Sridharan --- Changes since v9: * Check for presence of low level check_contaminant before installing tcpc.check_contaminant. Changes since v7: * None. Skipped versions by mistake. Changes since v6: * Removed is_potential_contaminant callback Changes since v5: * None 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 | 11 +++++++++++ include/linux/usb/tcpci.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index fe781a38dc82..699539e1be06 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -403,6 +403,14 @@ static void tcpci_frs_sourcing_vbus(struct tcpc_dev *dev) tcpci->data->frs_sourcing_vbus(tcpci, tcpci->data); } +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); @@ -778,6 +786,9 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) tcpci->tcpc.frs_sourcing_vbus = tcpci_frs_sourcing_vbus; tcpci->tcpc.set_partner_usb_comm_capable = tcpci_set_partner_usb_comm_capable; + if (tcpci->data->check_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; tcpci->tcpc.set_auto_vbus_discharge_threshold = diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 17657451c762..85e95a3251d3 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -188,6 +188,12 @@ 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. */ struct tcpci_data { struct regmap *regmap; @@ -204,6 +210,7 @@ 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); }; struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data);