From patchwork Mon May 6 14:08:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angus Ainslie X-Patchwork-Id: 10931107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 155B11398 for ; Mon, 6 May 2019 14:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F25E728470 for ; Mon, 6 May 2019 14:08:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3C9028497; Mon, 6 May 2019 14:08:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E36F28470 for ; Mon, 6 May 2019 14:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726369AbfEFOIo (ORCPT ); Mon, 6 May 2019 10:08:44 -0400 Received: from node.akkea.ca ([192.155.83.177]:37922 "EHLO node.akkea.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbfEFOIn (ORCPT ); Mon, 6 May 2019 10:08:43 -0400 Received: from localhost (localhost [127.0.0.1]) by node.akkea.ca (Postfix) with ESMTP id 370734E2051; Mon, 6 May 2019 14:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151723; bh=BLB0iTG9i/WddnImNISlddzl33hPIw2AJtO7OrjPOZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RpAM+Yk7PPWWDRTO0UILYgWgRQgRzmQP3fc3o8YKLk/t8T1vvTEi5+Vfz5cc0bT7S maAxEdgaAXEQ1/vrbl75lpjSlS/Kelg7Ks20mxvNM5PmrJUydHN3Dm0AhQl4jBiH2n xpj8fnsFwEkpVwjU9ez/FKCyPYe70e7zi9BgHHU4= X-Virus-Scanned: Debian amavisd-new at mail.akkea.ca Received: from node.akkea.ca ([127.0.0.1]) by localhost (mail.akkea.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FGdMrYgHdczt; Mon, 6 May 2019 14:08:42 +0000 (UTC) Received: from localhost.localdomain (198-48-167-13.cpe.pppoe.ca [198.48.167.13]) by node.akkea.ca (Postfix) with ESMTPSA id 729A04E204D; Mon, 6 May 2019 14:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151722; bh=BLB0iTG9i/WddnImNISlddzl33hPIw2AJtO7OrjPOZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZopaZgRKnkWRjE0ctpSl8fj8l4NjsLlTqz3eHqmtOEhX8/NcCsjR+hq74JbIdL+P0 QNi8nEP/L//bSNVkwJDcaF+g1f2Ms76r+Q0fBnFXBH0wpOeKOoLGm9u+l86POnGt0R 5CmQPAPvgBOUCdB0lv0zP5jp9ObcRWz3NlFk20N0= From: "Angus Ainslie (Purism)" To: angus.ainslie@puri.sm Cc: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Angus Ainslie (Purism)" Subject: [PATCH 1/3] usb: typec: tcpm: Export the logging function so it can be used by tcpci Date: Mon, 6 May 2019 08:08:28 -0600 Message-Id: <20190506140830.25376-2-angus@akkea.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506140830.25376-1-angus@akkea.ca> References: <20190506140830.25376-1-angus@akkea.ca> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Give the rest of the tcpm stack access to the logging function. Signed-off-by: Angus Ainslie (Purism) --- drivers/usb/typec/tcpm/tcpm.c | 3 ++- include/linux/usb/tcpm.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index fba32d84e578..7c35cc1accae 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -465,7 +465,7 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) } __printf(2, 3) -static void tcpm_log(struct tcpm_port *port, const char *fmt, ...) +void tcpm_log(struct tcpm_port *port, const char *fmt, ...) { va_list args; @@ -479,6 +479,7 @@ static void tcpm_log(struct tcpm_port *port, const char *fmt, ...) _tcpm_log(port, fmt, args); va_end(args); } +EXPORT_SYMBOL_GPL(tcpm_log); __printf(2, 3) static void tcpm_log_force(struct tcpm_port *port, const char *fmt, ...) diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 36a15dcadc53..70bfffdf5760 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -169,4 +169,6 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port, void tcpm_pd_hard_reset(struct tcpm_port *port); void tcpm_tcpc_reset(struct tcpm_port *port); +void tcpm_log(struct tcpm_port *port, const char *fmt, ...); + #endif /* __LINUX_USB_TCPM_H */ From patchwork Mon May 6 14:08:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angus Ainslie X-Patchwork-Id: 10931111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BB35912 for ; Mon, 6 May 2019 14:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5928228485 for ; Mon, 6 May 2019 14:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DAB12853E; Mon, 6 May 2019 14:09:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE32028485 for ; Mon, 6 May 2019 14:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbfEFOIu (ORCPT ); Mon, 6 May 2019 10:08:50 -0400 Received: from node.akkea.ca ([192.155.83.177]:37944 "EHLO node.akkea.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbfEFOIo (ORCPT ); Mon, 6 May 2019 10:08:44 -0400 Received: from localhost (localhost [127.0.0.1]) by node.akkea.ca (Postfix) with ESMTP id CD4D04E2056; Mon, 6 May 2019 14:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151723; bh=RAeCpmhA4P7ycHXDF1WROtdWMKsl/rnfxBaRR1sAt80=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qCkWo8H5NajrrfbeYj+gCGJYumhZ9B4QyqSrkX/AmZ3hxg56nAKtfxDGKxWx5lD3e P7R+8Nqkmb2TkMcYWfPjIA3t9dOVH2tfS77Z4nAyvK3dILo29KSW/I+4p7qumOIEaZ axjskErkVKsD26d1W8gleN7azKge/5vm7ZuZtuwY= X-Virus-Scanned: Debian amavisd-new at mail.akkea.ca Received: from node.akkea.ca ([127.0.0.1]) by localhost (mail.akkea.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PAci3R7UHMmz; Mon, 6 May 2019 14:08:43 +0000 (UTC) Received: from localhost.localdomain (198-48-167-13.cpe.pppoe.ca [198.48.167.13]) by node.akkea.ca (Postfix) with ESMTPSA id 0F2044E204B; Mon, 6 May 2019 14:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151723; bh=RAeCpmhA4P7ycHXDF1WROtdWMKsl/rnfxBaRR1sAt80=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qCkWo8H5NajrrfbeYj+gCGJYumhZ9B4QyqSrkX/AmZ3hxg56nAKtfxDGKxWx5lD3e P7R+8Nqkmb2TkMcYWfPjIA3t9dOVH2tfS77Z4nAyvK3dILo29KSW/I+4p7qumOIEaZ axjskErkVKsD26d1W8gleN7azKge/5vm7ZuZtuwY= From: "Angus Ainslie (Purism)" To: angus.ainslie@puri.sm Cc: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Angus Ainslie (Purism)" Subject: [PATCH 2/3] usb: typec: tcpm: Add functions to read the VBUS voltage Date: Mon, 6 May 2019 08:08:29 -0600 Message-Id: <20190506140830.25376-3-angus@akkea.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506140830.25376-1-angus@akkea.ca> References: <20190506140830.25376-1-angus@akkea.ca> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Put some diagnostics in the tcpm log when there's an over or under voltage situation. Signed-off-by: Angus Ainslie (Purism) --- drivers/usb/typec/tcpm/tcpci.c | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index c1f7073a56de..c6e0e48b9a2a 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -261,6 +261,39 @@ static int tcpci_set_pd_rx(struct tcpc_dev *tcpc, bool enable) return 0; } +static int tcpci_get_vbus_voltage(struct tcpc_dev *tcpc) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + u16 vbus_reg; + unsigned int vbus_voltage; + int ret, scale; + + ret = tcpci_read16(tcpci, TCPC_VBUS_VOLTAGE, &vbus_reg); + if (ret < 0) + return ret; + + vbus_voltage = vbus_reg & 0x3f; + switch ((ret >> 10) & 3) { + case 0: + scale = 1; + break; + case 1: + scale = 2; + break; + case 2: + scale = 4; + break; + case 3: + tcpm_log(tcpci->port, "invalid VBUS scale"); + return -1; + } + + if (scale != 1) + vbus_voltage *= scale; + + return vbus_voltage; +} + static int tcpci_get_vbus(struct tcpc_dev *tcpc) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -463,6 +496,17 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci) else if (status & TCPC_ALERT_TX_FAILED) tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_FAILED); + if (status & (TCPC_ALERT_V_ALARM_LO | TCPC_ALERT_V_ALARM_HI)) { + int ret; + + ret = tcpci_get_vbus_voltage(&tcpci->tcpc); + + if (IS_ERR(ret)) + tcpm_log(tcpci->port, "Can't read VBUS voltage"); + else + tcpm_log(tcpci->port, "Invalid VBUS voltage %d", ret); + } + return IRQ_HANDLED; } EXPORT_SYMBOL_GPL(tcpci_irq); From patchwork Mon May 6 14:08:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angus Ainslie X-Patchwork-Id: 10931109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0A0A16C1 for ; Mon, 6 May 2019 14:08:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF91128485 for ; Mon, 6 May 2019 14:08:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3E5B2853E; Mon, 6 May 2019 14:08:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56CCA28485 for ; Mon, 6 May 2019 14:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbfEFOIu (ORCPT ); Mon, 6 May 2019 10:08:50 -0400 Received: from node.akkea.ca ([192.155.83.177]:37960 "EHLO node.akkea.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbfEFOIo (ORCPT ); Mon, 6 May 2019 10:08:44 -0400 Received: from localhost (localhost [127.0.0.1]) by node.akkea.ca (Postfix) with ESMTP id 652A94E205C; Mon, 6 May 2019 14:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151724; bh=5L50ih8c7g/WWgfz2+Mh7aRuaW5CJO7HyCJLX/kPSZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nkJjc5ShRAtkZrNCll3t5PK15MVsqDyzumClp6gNyxKMS2tuX3fPwgDwOg9k4b93j lbvof4ohXegv5Lv2OAabFx7yWqJaydXHMlcBRqlcraYrYfhqsdVl9jrNQUtbBNP0Xh RmldVNd6jKpvtOiJ7twRnJrQozyjJSSju7ZdJV6c= X-Virus-Scanned: Debian amavisd-new at mail.akkea.ca Received: from node.akkea.ca ([127.0.0.1]) by localhost (mail.akkea.ca [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mk2qd3Wofqff; Mon, 6 May 2019 14:08:44 +0000 (UTC) Received: from localhost.localdomain (198-48-167-13.cpe.pppoe.ca [198.48.167.13]) by node.akkea.ca (Postfix) with ESMTPSA id 9ED3B4E204D; Mon, 6 May 2019 14:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557151724; bh=5L50ih8c7g/WWgfz2+Mh7aRuaW5CJO7HyCJLX/kPSZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nkJjc5ShRAtkZrNCll3t5PK15MVsqDyzumClp6gNyxKMS2tuX3fPwgDwOg9k4b93j lbvof4ohXegv5Lv2OAabFx7yWqJaydXHMlcBRqlcraYrYfhqsdVl9jrNQUtbBNP0Xh RmldVNd6jKpvtOiJ7twRnJrQozyjJSSju7ZdJV6c= From: "Angus Ainslie (Purism)" To: angus.ainslie@puri.sm Cc: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Angus Ainslie (Purism)" Subject: [PATCH 3/3] usb: typec: tcpm: Clear the fault status register Date: Mon, 6 May 2019 08:08:30 -0600 Message-Id: <20190506140830.25376-4-angus@akkea.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506140830.25376-1-angus@akkea.ca> References: <20190506140830.25376-1-angus@akkea.ca> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the fault status register doesn't get cleared then the ptn5110 interrupt gets stuck on. As the fault register gets set everytime the ptn5110 powers on the interrupt is always stuck. Signed-off-by: Angus Ainslie (Purism) --- drivers/usb/typec/tcpm/tcpci.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index c6e0e48b9a2a..17a0ffe818c0 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -507,6 +507,18 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci) tcpm_log(tcpci->port, "Invalid VBUS voltage %d", ret); } + if (status & TCPC_ALERT_FAULT) { + u16 fault_status; + + tcpci_read16(tcpci, TCPC_FAULT_STATUS, &fault_status); + + tcpm_log(tcpci->port, "FAULT ALERT status 0x%x", + fault_status); + + /* clear the fault status */ + tcpci_write16(tcpci, TCPC_FAULT_STATUS, fault_status); + } + return IRQ_HANDLED; } EXPORT_SYMBOL_GPL(tcpci_irq);