From patchwork Wed May 28 21:46:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 4257471 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8FFCCBF90B for ; Wed, 28 May 2014 21:48:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9EED320170 for ; Wed, 28 May 2014 21:48:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3B1E20303 for ; Wed, 28 May 2014 21:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755551AbaE1Vr0 (ORCPT ); Wed, 28 May 2014 17:47:26 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:41021 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755214AbaE1VrY (ORCPT ); Wed, 28 May 2014 17:47:24 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s4SLkqHw011817; Wed, 28 May 2014 16:46:52 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4SLkpj9031895; Wed, 28 May 2014 16:46:52 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Wed, 28 May 2014 16:46:51 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4SLkp7Y015161; Wed, 28 May 2014 16:46:51 -0500 From: Nishanth Menon To: , CC: , , , , , , Nishanth Menon Subject: [PATCH V2 2/2] power: twl4030_charger: attempt to power off in case of critical events Date: Wed, 28 May 2014 16:46:50 -0500 Message-ID: <1401313610-14252-3-git-send-email-nm@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1401313610-14252-1-git-send-email-nm@ti.com> References: <1401313610-14252-1-git-send-email-nm@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Attempt to power off in case of critical events such as battery removal, over voltage events. There is no guarentee that we'd be in a safe scenario here, but the very least we can try to do is to power off the device to prevent damage to the system instead of just printing a message and hoping for the best. NOTE: twl4030 should attempt some form of recovery, but just depending on that is never a safe alternative. Signed-off-by: Nishanth Menon --- new patch. original attempt was: https://patchwork.kernel.org/patch/4002371/ NOTE: we dont have poweroff support yet enabled on LDP, but it just needs relevant dts entry. drivers/power/twl4030_charger.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c index 2598c58..ed0dbd2 100644 --- a/drivers/power/twl4030_charger.c +++ b/drivers/power/twl4030_charger.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #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,34 @@ 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) + orderly_poweroff(true); return IRQ_HANDLED; }