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);