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: 13463560 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Uo6EHovU" Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A371A91 for ; Tue, 21 Nov 2023 12:38:52 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5c16f262317so150499a12.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=hxQtfTNjMQVHWf1g3wYCzHDWViBvHyuCc2rh9D60FNcA+1qe1THSFoRine5DnJv8+G fXgLLtaURAUk807qyR3j/J3bjVQ5w5BuwzJhrR0L/h9ffCj2OFZk3AYrkMMoRPczAirr JFnKTrkesO0t05j8dJUyfJEtMuaquSr2Qc5/l447oqlT5z0hMXbxFBapG4zpT4mAECgu YOEO2iE+0QOhnc80SAFv3jyukML80icQcTSNfZ28Vta/my3+JX+WOr3O/jRycMxiyQjv vtRO3SoczS20YIyMBm/+zb8IcyPbZJyrSdSIizlodlYiLQNetkN/N7WKfwrNhDl6ICPl QQrA== X-Gm-Message-State: AOJu0YxYP6OVLllWrt4lvEX0/Ltu665PhEdFwXCuaQnV3mtddD0avWYH eVImCEzagn60AXBiTXRBbOrcet+xPfW95/E= X-Google-Smtp-Source: AGHT+IH4DRI5US3jLyCwko2wUpOC4NIcFReSx07F/9ry6Ea9M80zEa8rCpiyb+ZWubY1zT8Lu21bmavCJm7OdY8= 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> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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: 13463561 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z7K7PDAN" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE491A3 for ; Tue, 21 Nov 2023 12:38:54 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5c994880223so44959387b3.0 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=BjQf8+ka/ckkHHMcKlqThz9fN0ZSNh1ow68OS/5ezLTAn8gHVcakgxR9qY3cop3omG HL+l30aEqOxGQjrrCkmeEdlM8dN0UUv36SNRbONliYPwXqfMQA9+DkW50loHIw5+btDh MEUpHpJZ4fT0CfBLzg9HiyPjIAqgFI+qiDEdwKsNmANa0dp9MhXCE4yHBb11gqbQwbnC tvK+J+GL9mOkVGsOtk7cowBiphDUK8KnkCTYTD8gajnyiya2Snk2vboCeGN0uwf8OZax ixmW/qPPb8B1Ha24JOJNdWZXSAjrK1siTn1jMYFNSCy4rigdsDHNt3aljnyfHsXUyRS6 l4rw== X-Gm-Message-State: AOJu0YyUfp+uU8n3IYAcm0Q5KOz20AF125cmZBmXz0ljDH3gqnlMo9+B LSDqYhOzy5A8xAayv8sJ2wCcn87rz7ooBwU= X-Google-Smtp-Source: AGHT+IEuYXxq5fTtblMTOGg6wqwt7Qleq9KC2mq1Yx89nISOxEToDfF76cL1rRm7YiLf6M1UU3OjdRy25uvmwp8= 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> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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