* [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register @ 2019-05-08 0:40 Angus Ainslie (Purism) 2019-05-08 0:40 ` [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Angus Ainslie (Purism) 2019-05-08 1:47 ` [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Guenter Roeck 0 siblings, 2 replies; 4+ messages in thread From: Angus Ainslie (Purism) @ 2019-05-08 0:40 UTC (permalink / raw) Cc: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel, Angus Ainslie (Purism) I don't have a setup that I can test this code right now. I did test the tcpci_get_vbus_voltage and on my setup it is always 0. I don't currently have setup that I can adjust the vbus voltage to trigger the fault. Angus Ainslie (Purism) (1): usb: typec: tcpci: add functions to read the VBUS voltage drivers/usb/typec/tcpm/tcpci.c | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) -- 2.17.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage 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) 2019-05-08 1:59 ` Guenter Roeck 2019-05-08 1:47 ` [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Guenter Roeck 1 sibling, 1 reply; 4+ messages in thread From: Angus Ainslie (Purism) @ 2019-05-08 0:40 UTC (permalink / raw) Cc: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel, Angus Ainslie (Purism) 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage 2019-05-08 0:40 ` [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Angus Ainslie (Purism) @ 2019-05-08 1:59 ` Guenter Roeck 0 siblings, 0 replies; 4+ messages in thread From: Guenter Roeck @ 2019-05-08 1:59 UTC (permalink / raw) To: Angus Ainslie (Purism) Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel On 5/7/19 5:40 PM, Angus Ainslie (Purism) wrote: > 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); > + Extra empty line. > + 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); > + } This doesn't report anything if reading the VBUS voltage returns an error. Also, per TCPCI specification, you probably want to check POWER_CONTROL.VBUS_VOLTAGE Monitor to see if it is enabled in the first place. On a higher level, the driver doesn't currently set limits for low and high voltage alarms, and it doesn't enable those alarms. As such, I wonder if/how you can get those alerts. Can you clarify ? Thanks, Guenter > + } > + > return IRQ_HANDLED; > } > EXPORT_SYMBOL_GPL(tcpci_irq); > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register 2019-05-08 0:40 [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Angus Ainslie (Purism) 2019-05-08 0:40 ` [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Angus Ainslie (Purism) @ 2019-05-08 1:47 ` Guenter Roeck 1 sibling, 0 replies; 4+ messages in thread From: Guenter Roeck @ 2019-05-08 1:47 UTC (permalink / raw) To: Angus Ainslie (Purism) Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-usb, linux-kernel On 5/7/19 5:40 PM, Angus Ainslie (Purism) wrote: > I don't have a setup that I can test this code right now. > > I did test the tcpci_get_vbus_voltage and on my setup it is always 0. > Odd. PTN5110 is supposed to support it, though the datasheet is a bit vague about it. It may be disabled. Did you check the status of POWER_CONTROL.VBUS_VOLTAGEMonitor ? > I don't currently have setup that I can adjust the vbus voltage to > trigger the fault. > > Angus Ainslie (Purism) (1): > usb: typec: tcpci: add functions to read the VBUS voltage > > drivers/usb/typec/tcpm/tcpci.c | 35 ++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > In general, an introductory patch is only useful if there is more than one patch. Thanks, Guenter ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-05-08 1:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-05-08 0:40 [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Angus Ainslie (Purism) 2019-05-08 0:40 ` [PATCH 1/1] usb: typec: tcpci: add functions to read the VBUS voltage Angus Ainslie (Purism) 2019-05-08 1:59 ` Guenter Roeck 2019-05-08 1:47 ` [PATCH 0/1] usb: typec: tcpci: read the VBUS_VOLTAGE register Guenter Roeck
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®