From: "Angus Ainslie (Purism)" <angus@akkea.ca>
To: unlisted-recipients:; (no To-header on input)
Cc: Guenter Roeck <linux@roeck-us.net>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Angus Ainslie (Purism)" <angus@akkea.ca>
Subject: [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage
Date: Tue, 7 May 2019 18:40:27 -0600 [thread overview]
Message-ID: <20190508004027.16558-2-angus@akkea.ca> (raw)
In-Reply-To: <20190508004027.16558-1-angus@akkea.ca>
Show an error when the VBUS voltage is out of range.
Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
---
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);
--
2.17.1
next prev parent reply other threads:[~2019-05-08 0:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-08 0:40 [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Angus Ainslie (Purism)
2019-05-08 0:40 ` Angus Ainslie (Purism) [this message]
2019-05-08 1:59 ` [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Guenter Roeck
2019-05-08 1:47 ` [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190508004027.16558-2-angus@akkea.ca \
--to=angus@akkea.ca \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).