Commit e2414217 authored by Andrew Chew's avatar Andrew Chew Committed by Anton Vorontsov

tps65090-charger: Fix AC detect

The VACG interrupt was not being enabled.  Thus, interrupts were never
generated when AC status changes.  In addition, interrupts were never
cleared after taking and processing the interrupt.

Added the register offset for the INTR_MASK register, since this is needed
to unmask the VACG interrupt.

Enabled the VACG interrupt in tps65090_config_charger().

Cleared interrupts after processing, in tps65090_charger_isr().

Also removed unused variable "enable" in tps65090_enable_charging(), and
fixed a typo in one of the dev_err() prints.
Signed-off-by: default avatarAndrew Chew <achew@nvidia.com>
Tested-by: default avatarRhyland Klein <rklein@nvidia.com>
Acked-by: default avatarRhyland Klein <rklein@nvidia.com>
Signed-off-by: default avatarAnton Vorontsov <anton@enomsg.org>
parent 9d5e2a02
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/mfd/tps65090.h> #include <linux/mfd/tps65090.h>
#define TPS65090_REG_INTR_STS 0x00 #define TPS65090_REG_INTR_STS 0x00
#define TPS65090_REG_INTR_MASK 0x02
#define TPS65090_REG_CG_CTRL0 0x04 #define TPS65090_REG_CG_CTRL0 0x04
#define TPS65090_REG_CG_CTRL1 0x05 #define TPS65090_REG_CG_CTRL1 0x05
#define TPS65090_REG_CG_CTRL2 0x06 #define TPS65090_REG_CG_CTRL2 0x06
...@@ -67,8 +68,7 @@ static int tps65090_low_chrg_current(struct tps65090_charger *charger) ...@@ -67,8 +68,7 @@ static int tps65090_low_chrg_current(struct tps65090_charger *charger)
return 0; return 0;
} }
static int tps65090_enable_charging(struct tps65090_charger *charger, static int tps65090_enable_charging(struct tps65090_charger *charger)
uint8_t enable)
{ {
int ret; int ret;
uint8_t ctrl0 = 0; uint8_t ctrl0 = 0;
...@@ -84,7 +84,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger, ...@@ -84,7 +84,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger,
ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL0, ret = tps65090_write(charger->dev->parent, TPS65090_REG_CG_CTRL0,
(ctrl0 | TPS65090_CHARGER_ENABLE)); (ctrl0 | TPS65090_CHARGER_ENABLE));
if (ret < 0) { if (ret < 0) {
dev_err(charger->dev, "%s(): error reading in register 0x%x\n", dev_err(charger->dev, "%s(): error writing in register 0x%x\n",
__func__, TPS65090_REG_CG_CTRL0); __func__, TPS65090_REG_CG_CTRL0);
return ret; return ret;
} }
...@@ -93,6 +93,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger, ...@@ -93,6 +93,7 @@ static int tps65090_enable_charging(struct tps65090_charger *charger,
static int tps65090_config_charger(struct tps65090_charger *charger) static int tps65090_config_charger(struct tps65090_charger *charger)
{ {
uint8_t intrmask = 0;
int ret; int ret;
if (charger->pdata->enable_low_current_chrg) { if (charger->pdata->enable_low_current_chrg) {
...@@ -104,6 +105,23 @@ static int tps65090_config_charger(struct tps65090_charger *charger) ...@@ -104,6 +105,23 @@ static int tps65090_config_charger(struct tps65090_charger *charger)
} }
} }
/* Enable the VACG interrupt for AC power detect */
ret = tps65090_read(charger->dev->parent, TPS65090_REG_INTR_MASK,
&intrmask);
if (ret < 0) {
dev_err(charger->dev, "%s(): error reading in register 0x%x\n",
__func__, TPS65090_REG_INTR_MASK);
return ret;
}
ret = tps65090_write(charger->dev->parent, TPS65090_REG_INTR_MASK,
(intrmask | TPS65090_VACG));
if (ret < 0) {
dev_err(charger->dev, "%s(): error writing in register 0x%x\n",
__func__, TPS65090_REG_CG_CTRL0);
return ret;
}
return 0; return 0;
} }
...@@ -146,7 +164,7 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id) ...@@ -146,7 +164,7 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
} }
if (intrsts & TPS65090_VACG) { if (intrsts & TPS65090_VACG) {
ret = tps65090_enable_charging(charger, 1); ret = tps65090_enable_charging(charger);
if (ret < 0) if (ret < 0)
return IRQ_HANDLED; return IRQ_HANDLED;
charger->ac_online = 1; charger->ac_online = 1;
...@@ -154,6 +172,13 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id) ...@@ -154,6 +172,13 @@ static irqreturn_t tps65090_charger_isr(int irq, void *dev_id)
charger->ac_online = 0; charger->ac_online = 0;
} }
/* Clear interrupts. */
ret = tps65090_write(charger->dev->parent, TPS65090_REG_INTR_STS, 0x00);
if (ret < 0) {
dev_err(charger->dev, "%s(): Error in writing reg 0x%x\n",
__func__, TPS65090_REG_INTR_STS);
}
if (charger->prev_ac_online != charger->ac_online) if (charger->prev_ac_online != charger->ac_online)
power_supply_changed(&charger->ac); power_supply_changed(&charger->ac);
...@@ -270,7 +295,7 @@ static int tps65090_charger_probe(struct platform_device *pdev) ...@@ -270,7 +295,7 @@ static int tps65090_charger_probe(struct platform_device *pdev)
} }
if (status1 != 0) { if (status1 != 0) {
ret = tps65090_enable_charging(cdata, 1); ret = tps65090_enable_charging(cdata);
if (ret < 0) { if (ret < 0) {
dev_err(cdata->dev, "error enabling charger\n"); dev_err(cdata->dev, "error enabling charger\n");
goto fail_free_irq; goto fail_free_irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment