@@ -22,6 +22,7 @@
#include <linux/power_supply.h>
#include <linux/notifier.h>
#include <linux/usb/otg.h>
+#include <linux/reboot.h>
#include <linux/regulator/machine.h>
#define TWL4030_BCIMSTATEC 0x02
@@ -332,6 +333,7 @@ static irqreturn_t twl4030_bci_interrupt(int irq, void *arg)
struct twl4030_bci *bci = arg;
u8 irqs1, irqs2;
int ret;
+ bool power_off = false;
ret = twl_i2c_read_u8(TWL4030_MODULE_INTERRUPTS, &irqs1,
TWL4030_INTERRUPTS_BCIISR1A);
@@ -352,20 +354,38 @@ static irqreturn_t twl4030_bci_interrupt(int irq, void *arg)
}
/* various monitoring events, for now we just log them here */
- if (irqs1 & (TWL4030_TBATOR2 | TWL4030_TBATOR1))
+ if (irqs1 & (TWL4030_TBATOR2 | TWL4030_TBATOR1)) {
dev_warn(bci->dev, "battery temperature out of range\n");
+ power_off = true;
+ }
- if (irqs1 & TWL4030_BATSTS)
+ if (irqs1 & TWL4030_BATSTS) {
dev_crit(bci->dev, "battery disconnected\n");
+ power_off = true;
+ }
- if (irqs2 & TWL4030_VBATOV)
+ if (irqs2 & TWL4030_VBATOV) {
dev_crit(bci->dev, "VBAT overvoltage\n");
+ power_off = true;
+ }
- if (irqs2 & TWL4030_VBUSOV)
+ if (irqs2 & TWL4030_VBUSOV) {
dev_crit(bci->dev, "VBUS overvoltage\n");
+ power_off = true;
+ }
- if (irqs2 & TWL4030_ACCHGOV)
+ if (irqs2 & TWL4030_ACCHGOV) {
dev_crit(bci->dev, "Ac charger overvoltage\n");
+ power_off = true;
+ }
+
+ /* Try to shutdown the system */
+ if (power_off) {
+ /* Disable chargers before shutting off */
+ twl4030_charger_enable_ac(false);
+ twl4030_charger_enable_usb(bci, false);
+ orderly_poweroff(true);
+ }
return IRQ_HANDLED;
}