From patchwork Tue Nov 21 20:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: RD Babiera X-Patchwork-Id: 167935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp901816vqb; Tue, 21 Nov 2023 12:39:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFn/uTCm43O88/MPOIYhmEPqEoF2kkyuSZRWE2DWAQ1e8xyHH81o0ZjBs7QuDAdaHm9zNVo X-Received: by 2002:a17:90b:1d0c:b0:283:2805:7c7a with SMTP id on12-20020a17090b1d0c00b0028328057c7amr368034pjb.43.1700599151689; Tue, 21 Nov 2023 12:39:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700599151; cv=none; d=google.com; s=arc-20160816; b=OaLObFxkUpmiVFCF1gVG6ecQ9I/HVSPU/54PQAg0wv0dQhYgg+JyNz4+3zWR9+v0Iv VQNDOBqoJMKwVbIuZSTYcaANz9PyfQbFwv47hAOTYcaypAfCBS8MjPm02m7/loZdbqA9 1nyU1H4CE5rPonDxokODAWsNb8ybo0Iw853r0bCyZfu6trMyXhOWyRhq4V5h5ps8tOdH 3aFy5fnUwCBorsC/mba0gAFnkMsq2ZS9bR8YV3REXb0sX0hEGwGkHs2/ZFIi32NUwQNC SMDxncwFwzA+AbYjrrvOoZz8z+N3eODGiTnGNaL1VerhKBgVEmFwLGSEMRpXMZdNFxaj o35w== 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=CpAN12hpYsjPqobveD3PUCYJQ9BmRdkXyaq+BHg4or4=; fh=Vcftd+eUXSziUq6y3xTINmOQUurVzRh9O/2Fk2FkWrY=; b=jc6T3drMrREe4YnkAkg/qEfLRAauaaSTAgT6N06PC1cGd73dJ/128lZIVvlCLS0iW8 m2MfXGq8ahU25W5haDQ9QUrLVFRaRboI+Pd2ctrfgJ9+d1nHJMmuc6l4XscCLMiFEWM9 BgXQpy+GAs2Dm5877Mx2QLPXn86JkEXxs1pzkq+uTKjhRfXgB3k/us0B39IbdTFj742f E33689Ad+wiy2IU9lGKKW+qpf7APsDXXYdL7YuidN1MG1GVwRYM92IOvXT21C0zQJW/X 6egMHwoVtnPWdDAxkPfdHraw/jdiZ5r6nLMwcxb324E6TWFqghwtqBgJsK2donBN50L4 Y5nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Uo6EHovU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id w13-20020a170902e88d00b001c72dbaf7b9si11567297plg.415.2023.11.21.12.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 12:39:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Uo6EHovU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 826F3802E8B9; Tue, 21 Nov 2023 12:38:59 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjKUUi5 (ORCPT + 99 others); Tue, 21 Nov 2023 15:38:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbjKUUiz (ORCPT ); Tue, 21 Nov 2023 15:38:55 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B87A110C for ; Tue, 21 Nov 2023 12:38:52 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5c16f262317so150500a12.1 for ; Tue, 21 Nov 2023 12:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700599132; x=1701203932; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CpAN12hpYsjPqobveD3PUCYJQ9BmRdkXyaq+BHg4or4=; b=Uo6EHovUftNEVYErarZkRDqT8W44EzyRkAdKEe7S77QX7TCT+lynVmWNGAbCf2XDx2 t9rzweGUwG98EMtDhckDVEK0GcQdLHA2bSFbyTFwTMne6l9QuwBTmjAFO6a8PMcCYExz 275F2elITKplfLLXCObzrqsbaldQBA5aNCgHECBGw6KVZQAA7EgBU4MCGnA/4mI3Gt8S suwBC1OKdzIWt31jnP73VBTiinuXOe0e0/WbxCJAF+0P+Or1wReNDpL0F5JjmMWbTWls NxMgTvvSmAkj1wZ3/1lvjh6DlvUgHEaKoATD1aGb29f/4m4eVRd3WiZB55xw3gkMoUxE leTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700599132; x=1701203932; 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=CpAN12hpYsjPqobveD3PUCYJQ9BmRdkXyaq+BHg4or4=; b=vsKxMp0uORBA7DaMpgb9QsNNz0b91WbYqdR+R2Vpmp35setd69MMxOvgpXhlV3dY1E shNu4C6GTD2i07kpBQhbtDbPfipiqijV6s/QigGqaFzHIrt4d1QImGEcjEzG1a+OtYgM MMyWXw10vsqKfYmCBrAZmnpvRDeOxdVO9UGngDpnu4yjwZXTKPPRtqbNkWcTjvPOzoGQ Q6E42qVNu1NOFL12s0atIv6tT6WUiFEUp3TKexkfA5VwNqH2Q130kc2kRv5u7W+cMhlJ 2/LNC3zn9j4DmsyFNNYcoDZCch3u3AV2kzivlaKGJ7JCLpMxoqfKAWcvRW2fA3AnYHmt kqrw== X-Gm-Message-State: AOJu0YzyK1aSPVtlBL3V8WW3f/oBS9UC5OqVx2lyGPklY46SS/I7+GMr 4wpg/o3l9LjP5rdV+zorVh+c+nkSYxrxFR4= X-Received: from rdbabiera.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:18a8]) (user=rdbabiera job=sendgmr) by 2002:a63:f517:0:b0:5bd:2714:1752 with SMTP id w23-20020a63f517000000b005bd27141752mr118281pgh.0.1700599132072; Tue, 21 Nov 2023 12:38:52 -0800 (PST) Date: Tue, 21 Nov 2023 20:38:47 +0000 In-Reply-To: <20231121203845.170234-4-rdbabiera@google.com> Mime-Version: 1.0 References: <20231121203845.170234-4-rdbabiera@google.com> X-Developer-Key: i=rdbabiera@google.com; a=openpgp; fpr=639A331F1A21D691815CE090416E17CA2BBBD5C8 X-Developer-Signature: v=1; a=openpgp-sha256; l=2288; i=rdbabiera@google.com; h=from:subject; bh=SxYaVtVD/g0CMGs47FWSPZQOsqfpWmahrF8ll25pSnM=; b=owGbwMvMwCFW0bfok0KS4TbG02pJDKmxoqH9gjdulPWq7J+/tnnNlaMzZ9XkM+prXutyLk3yv 3tv+ju1jlIWBjEOBlkxRRZd/zyDG1dSt8zhrDGGmcPKBDKEgYtTACbCNp3hvxf77fmFWnKbNwWy VGZJNH+uSAvz9nQyEgiXVdtUf+KbNyPD9No0Hd1JdUtat3xiTwns/VomWc+yy8quc3LWhJ1el16 yAAA= X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231121203845.170234-5-rdbabiera@google.com> Subject: [PATCH v1 1/2] usb: typec: tcpm: add tcpm_port_error_recovery symbol From: RD Babiera To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, badhri@google.com, RD Babiera X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 21 Nov 2023 12:39:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783207456054479489 X-GMAIL-MSGID: 1783207456054479489 Add tcpm_port_error_recovery symbol and corresponding event that runs in tcpm_pd_event handler to set the port to the ERROR_RECOVERY state. tcpci drivers can use the symbol to reset the port when tcpc faults affect port functionality. Signed-off-by: RD Babiera Reviewed-by: Heikki Krogerus Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ include/linux/usb/tcpm.h | 1 + 2 files changed, 15 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 058d5b853b57..2e553dc63619 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -251,6 +251,7 @@ enum frs_typec_current { #define TCPM_FRS_EVENT BIT(3) #define TCPM_SOURCING_VBUS BIT(4) #define TCPM_PORT_CLEAN BIT(5) +#define TCPM_PORT_ERROR BIT(6) #define LOG_BUFFER_ENTRIES 1024 #define LOG_BUFFER_ENTRY_SIZE 128 @@ -5477,6 +5478,10 @@ static void tcpm_pd_event_handler(struct kthread_work *work) tcpm_set_state(port, tcpm_default_state(port), 0); } } + if (events & TCPM_PORT_ERROR) { + tcpm_log(port, "port triggering error recovery"); + tcpm_set_state(port, ERROR_RECOVERY, 0); + } spin_lock(&port->pd_event_lock); } @@ -5544,6 +5549,15 @@ bool tcpm_port_is_toggling(struct tcpm_port *port) } EXPORT_SYMBOL_GPL(tcpm_port_is_toggling); +void tcpm_port_error_recovery(struct tcpm_port *port) +{ + spin_lock(&port->pd_event_lock); + port->pd_events |= TCPM_PORT_ERROR; + spin_unlock(&port->pd_event_lock); + kthread_queue_work(port->wq, &port->event_work); +} +EXPORT_SYMBOL_GPL(tcpm_port_error_recovery); + static void tcpm_enable_frs_work(struct kthread_work *work) { struct tcpm_port *port = container_of(work, struct tcpm_port, enable_frs); diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index ab7ca872950b..65fac5e1f317 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -173,5 +173,6 @@ void tcpm_pd_hard_reset(struct tcpm_port *port); void tcpm_tcpc_reset(struct tcpm_port *port); void tcpm_port_clean(struct tcpm_port *port); bool tcpm_port_is_toggling(struct tcpm_port *port); +void tcpm_port_error_recovery(struct tcpm_port *port); #endif /* __LINUX_USB_TCPM_H */ From patchwork Tue Nov 21 20:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: RD Babiera X-Patchwork-Id: 167936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp901902vqb; Tue, 21 Nov 2023 12:39:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXH3+Cj/qbPlKRaS/hxTu8q2XNkqYaD7mpAmwa7bNltQUDc6TEEmjffraWCPBYw909Emme X-Received: by 2002:a17:902:7244:b0:1cc:501b:1d13 with SMTP id c4-20020a170902724400b001cc501b1d13mr277017pll.40.1700599163382; Tue, 21 Nov 2023 12:39:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700599163; cv=none; d=google.com; s=arc-20160816; b=jf+iQ7dURCnm8qNTul+Ao5PkpJEIA9P6lUSQaklfYYvcmdNwegTOYoUbkc9YpoA0yI 5uqy0Ec5qWSU1lldXTOoXiRazkHpWqeXY6LpkEnwCF4/nTmQpT6G1Si5lqIHdIfWJbu7 HpkNBvGkop4CcHU6IjWBpQpjLPmbXg91zztnp+9ov8Q9FvZ5h1dCdsr2fbnr8LqLPKY0 NvxhseMHMpmLYANNQAG4ybqsqieM0oEB6lQ5UbDT4YnZFZhB850Z0w0cM+B2HeED9CG4 mqF/ZGZB6a4/XC1tcTrzyqauTnMAME5Ird12PaChrxfEBiD0eKmgjn3EDzyTELFWQk1k hFVQ== 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=KTDH53gNPxt291RajHzvpKvqzTC7KmzGzR+np8Bf7dA=; fh=Vcftd+eUXSziUq6y3xTINmOQUurVzRh9O/2Fk2FkWrY=; b=j47InheJakaTjOHyBzCN5tl9X17/dc36Y0oQgCGa19lbjw2EqcIJJR1GVhc8+LKbkS TPvMlYwPTzzcr0d7787rGNjF0nrsIasNeQCzZCb7fkw8/njfljt+7dlY8KsWTiqmzAsf 3LWEZONN1n0ntIPaytpqT1iidx2q7eAXOjMN8tJRLS4Zv9pIbLDt1iCid1nSeQmvSdsd gehGpu0k5Q3azqXYWjmrmf+EmKgPUHVM/kMA4iYQ9S233Z/tRziDL3r0DlhryOkx0edI FeXEnPBYfjYf2wcBeQff/ZHlmfXBNrOg7c48UbhZjYLQlXQbc1+D6ZPuZ1RgGZphx+SV eX6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z7K7PDAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id p7-20020a170902bd0700b001ce5ba27888si10537998pls.211.2023.11.21.12.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 12:39:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Z7K7PDAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D3B62802F650; Tue, 21 Nov 2023 12:39:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbjKUUjA (ORCPT + 99 others); Tue, 21 Nov 2023 15:39:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230348AbjKUUi6 (ORCPT ); Tue, 21 Nov 2023 15:38:58 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7F061A1 for ; Tue, 21 Nov 2023 12:38:54 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cb92becbf6so15210007b3.2 for ; Tue, 21 Nov 2023 12:38:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700599134; x=1701203934; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KTDH53gNPxt291RajHzvpKvqzTC7KmzGzR+np8Bf7dA=; b=Z7K7PDANHV6Bf+bXmSWanOr4PmWVB/0AUObrlFVN7X7zTPnpOj0zr1fDpz+ah9yytr 5yC36krdqXxvQ8Ajuc4HmJqNv8sDPu+dcs4vKAIL98d4u3TfCEuydFT4dqoLnChQ8iJb W5OZWAGySSTTz3E9lYXbeLfRMv0bx86O7offf/98PYuMbHS43qCR/86lirnbGJSv0wqW sSDbtUUN4ZvHAgL9mQNBMT4pRisKTfEafrcj5lrRJSAWF7vjBZLylpiX6aPyBckLBcoP tlSXRIDwnFHhiSbypgn6dNuk7DSPtgyaJhj2D4mVnvJ9lPIWN/BU0/DKJjCaWaF0il0a FjNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700599134; x=1701203934; 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=KTDH53gNPxt291RajHzvpKvqzTC7KmzGzR+np8Bf7dA=; b=if0/VWIvxWgWVA2uPwdivSCe9RTp65IjajvS59pUto668J/bsY3MbvJ8MwKP/0tblr S2bc+qL8ZoeY3+3mXUdxYhyKOhpMp/8NEv9FwLwfoD2qIQhD9XFCodGVLwx9h96G5bHM J7pJFz8vOdWq5E5TS3lzO7b1OmKaQ4PSY+K9yDWr4zQZWUUGewsnv+81jtF+rBbblWBP +DDgkPm3D2qUHs1BRmeoJRGV1EHoj8sOkRZQTZD9Ojd+jMYFmjbBQzjXeAuU85Wo4CPB kkor1IEUWpJBMAtq/lok+KHN88UF1ORSz7a0oJM7CmQuO8vECu1zn3MWnlG3foFA6vlj QfVg== X-Gm-Message-State: AOJu0Yz7XMOXoLnvMz94XMvhR27r1kyiIf+6/cDTKpjPxnUViW7FkV6z M5ReUUlCBvlGRe+X5qf125cCVr3d4TVA6Io= X-Received: from rdbabiera.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:18a8]) (user=rdbabiera job=sendgmr) by 2002:a81:4f17:0:b0:5cb:6eaf:9ece with SMTP id d23-20020a814f17000000b005cb6eaf9ecemr4057ywb.1.1700599134145; Tue, 21 Nov 2023 12:38:54 -0800 (PST) Date: Tue, 21 Nov 2023 20:38:48 +0000 In-Reply-To: <20231121203845.170234-4-rdbabiera@google.com> Mime-Version: 1.0 References: <20231121203845.170234-4-rdbabiera@google.com> X-Developer-Key: i=rdbabiera@google.com; a=openpgp; fpr=639A331F1A21D691815CE090416E17CA2BBBD5C8 X-Developer-Signature: v=1; a=openpgp-sha256; l=2847; i=rdbabiera@google.com; h=from:subject; bh=IjJhNlLnaEWlwoSGO/qly2CIqtjZgjikrPRbqBaNOy0=; b=owGbwMvMwCFW0bfok0KS4TbG02pJDKmxomFHbqyTqV5TLa0YPDcpapbecrb/xzWVLabPXCNYJ OAlK1bTUcrCIMbBICumyKLrn2dw40rqljmcNcYwc1iZQIYwcHEKwETcZzMyzJHo6XF461b8/Wyy w/3wkD9BGVOUbtzMXHFxvWLAbhW1RQy/mJY9PxvIc+z89gDmI0n1c/ybm5tuZUWVzFXp/y7tNce PGQA= X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231121203845.170234-6-rdbabiera@google.com> Subject: [PATCH v1 2/2] usb: typec: tcpci: add vconn over current fault handling to maxim_core From: RD Babiera To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, badhri@google.com, RD Babiera X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 21 Nov 2023 12:39:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783207467996526971 X-GMAIL-MSGID: 1783207467996526971 Add TCPC_FAULT_STATUS_VCONN_OC constant and corresponding mask definition. Maxim TCPC is capable of detecting VConn over current faults, so add fault to alert mask. When a Vconn over current fault is triggered, put the port in an error recovery state via tcpm_port_error_recovery. Signed-off-by: RD Babiera Reviewed-by: Heikki Krogerus Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 20 +++++++++++++++++++- include/linux/usb/tcpci.h | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index 9454b12a073c..7fb966fd639b 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -92,11 +92,16 @@ static void max_tcpci_init_regs(struct max_tcpci_chip *chip) return; } + /* Vconn Over Current Protection */ + ret = max_tcpci_write8(chip, TCPC_FAULT_STATUS_MASK, TCPC_FAULT_STATUS_MASK_VCONN_OC); + if (ret < 0) + return; + alert_mask = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_TX_FAILED | TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_RX_STATUS | TCPC_ALERT_CC_STATUS | TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | TCPC_ALERT_POWER_STATUS | /* Enable Extended alert for detecting Fast Role Swap Signal */ - TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS; + TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS | TCPC_ALERT_FAULT; ret = max_tcpci_write16(chip, TCPC_ALERT_MASK, alert_mask); if (ret < 0) { @@ -295,6 +300,19 @@ static irqreturn_t _max_tcpci_irq(struct max_tcpci_chip *chip, u16 status) } } + if (status & TCPC_ALERT_FAULT) { + ret = max_tcpci_read8(chip, TCPC_FAULT_STATUS, ®_status); + if (ret < 0) + return ret; + + ret = max_tcpci_write8(chip, TCPC_FAULT_STATUS, reg_status); + if (ret < 0) + return ret; + + if (reg_status & TCPC_FAULT_STATUS_VCONN_OC) + tcpm_port_error_recovery(chip->port); + } + if (status & TCPC_ALERT_EXTND) { ret = max_tcpci_read8(chip, TCPC_ALERT_EXTENDED, ®_status); if (ret < 0) diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 83376473ac76..467e8045e9f8 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -36,7 +36,9 @@ #define TCPC_ALERT_MASK 0x12 #define TCPC_POWER_STATUS_MASK 0x14 -#define TCPC_FAULT_STATUS_MASK 0x15 + +#define TCPC_FAULT_STATUS_MASK 0x15 +#define TCPC_FAULT_STATUS_MASK_VCONN_OC BIT(1) #define TCPC_EXTENDED_STATUS_MASK 0x16 #define TCPC_EXTENDED_STATUS_MASK_VSAFE0V BIT(0) @@ -104,6 +106,7 @@ #define TCPC_FAULT_STATUS 0x1f #define TCPC_FAULT_STATUS_ALL_REG_RST_TO_DEFAULT BIT(7) +#define TCPC_FAULT_STATUS_VCONN_OC BIT(1) #define TCPC_ALERT_EXTENDED 0x21