From patchwork Wed May 8 00:40:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angus Ainslie X-Patchwork-Id: 10934047 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 587231515 for ; Wed, 8 May 2019 00:41:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4896F28913 for ; Wed, 8 May 2019 00:41:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C96A289A6; Wed, 8 May 2019 00:41:25 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 D945F28913 for ; Wed, 8 May 2019 00:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbfEHAks (ORCPT ); Tue, 7 May 2019 20:40:48 -0400 Received: from node.akkea.ca ([192.155.83.177]:43474 "EHLO node.akkea.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726348AbfEHAks (ORCPT ); Tue, 7 May 2019 20:40:48 -0400 Received: from localhost (localhost [127.0.0.1]) by node.akkea.ca (Postfix) with ESMTP id 0A16C4E2050; Wed, 8 May 2019 00:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557276048; bh=FgMbez4kMW0wjlFdZNKQ9TjLWgAyTOJ4vTmDZ70BusA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=b8LO9ZO3BxdZwfMc4iyvuUDJSiR/CuuvhDm/DjCmADlr8peaqzk7QiSy6icxDSXeM x4T0DK+nRL/rEs84ZDTP/QfiZE5n/SC+Rp9gYna816JDkEoytZTdAaPIQTjLiWKLf4 1iS2PEH5pHFWEXh9Xdh5Jr7FTjHjhi3oWN46dCw4= 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 hTtW_R1dT7LI; Wed, 8 May 2019 00:40:47 +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 012F04E204B; Wed, 8 May 2019 00:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akkea.ca; s=mail; t=1557276047; bh=FgMbez4kMW0wjlFdZNKQ9TjLWgAyTOJ4vTmDZ70BusA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LeWSofyQZEzFkWf0+L0eN1obt5zQkeAYJCJ1RN0fWPpLGvUrtceOR4hBjma433FZK bkY6UQdArZXUpGp47RaSjrYV+iZZhZC3UOvc9H+dmpmpFn5F0UCP5n44mmUm1QsgCW vobaakV7bz3kjYfvJyQ2ERSd5BYjfb2duumaAKJw= From: "Angus Ainslie (Purism)" Cc: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Angus Ainslie (Purism)" Subject: [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Date: Tue, 7 May 2019 18:40:27 -0600 Message-Id: <20190508004027.16558-2-angus@akkea.ca> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190508004027.16558-1-angus@akkea.ca> References: <20190508004027.16558-1-angus@akkea.ca> To: unlisted-recipients:; (no To-header on input) 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 Show an error when the VBUS voltage is out of range. Signed-off-by: Angus Ainslie (Purism) --- drivers/usb/typec/tcpm/tcpci.c | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index a5746657b190..223941e11ef3 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -261,6 +261,26 @@ 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; + + scale = (vbus_reg >> 10) & 3; + if (scale == 3) + return -EIO; + + return (vbus_voltage << scale) * 25; +} + static int tcpci_get_vbus(struct tcpc_dev *tcpc) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -401,6 +421,7 @@ static int tcpci_init(struct tcpc_dev *tcpc) irqreturn_t tcpci_irq(struct tcpci *tcpci) { u16 status; + int ret; tcpci_read16(tcpci, TCPC_ALERT, &status); @@ -474,6 +495,20 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci) tcpci_write16(tcpci, TCPC_FAULT_STATUS, fault_status); } + if (status & (TCPC_ALERT_V_ALARM_LO | TCPC_ALERT_V_ALARM_HI)) { + ret = tcpci_get_vbus_voltage(&tcpci->tcpc); + + if (ret >= 0) { + if (status & TCPC_ALERT_V_ALARM_LO) + dev_err(tcpci->dev, "Low VBUS voltage %d mV\n", + ret); + + if (status & TCPC_ALERT_V_ALARM_HI) + dev_err(tcpci->dev, "High VBUS voltage %d mV\n", + ret); + } + } + return IRQ_HANDLED; } EXPORT_SYMBOL_GPL(tcpci_irq);