From patchwork Mon Sep 28 22:33:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Dannenberg X-Patchwork-Id: 7281341 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4BD13BEEA4 for ; Mon, 28 Sep 2015 22:35:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 65E8920737 for ; Mon, 28 Sep 2015 22:35:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A70020747 for ; Mon, 28 Sep 2015 22:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754030AbbI1WfA (ORCPT ); Mon, 28 Sep 2015 18:35:00 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:43721 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753755AbbI1We7 (ORCPT ); Mon, 28 Sep 2015 18:34:59 -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 t8SMYFOi010045; Mon, 28 Sep 2015 17:34:15 -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 t8SMYFbn021036; Mon, 28 Sep 2015 17:34:15 -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.224.2; Mon, 28 Sep 2015 17:34:15 -0500 Received: from beast.tx.rr.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t8SMY56B026609; Mon, 28 Sep 2015 17:34:12 -0500 From: Andreas Dannenberg To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Laurentiu Palcu , Krzysztof Kozlowski CC: Ramakrishna Pallala , , , , Andreas Dannenberg Subject: [PATCH v8 02/14] power: bq24257: Streamline input current limit setup Date: Mon, 28 Sep 2015 17:33:50 -0500 Message-ID: <1443479642-23712-3-git-send-email-dannenberg@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443479642-23712-1-git-send-email-dannenberg@ti.com> References: <1443479642-23712-1-git-send-email-dannenberg@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 The maximum amount of input current the charger should draw is dependent on the power supply and should only be (re-)configured when the power supply gets connected and disconnected. However the driver was also lowering the bq24257's input current limit setting to 500mA when the battery was removed and restored the previous setting according to the power supply capabilities when the battery was reconnected although these events are not impacting the amount of power that can be drawn from the supply. Furthermore, a re-configuration of the input current limit to 500mA when the battery gets disconnected is actually dangerous if the limit was set higher previously and the system draws more than 500mA in which case the system voltage would be reduced in order to maintain 500mA which could result in the system getting too low of a supply to maintain operation. Last but not least the mechanism itself used for battery re-connection detection did not work in corner cases such as when the device's input current loop becomes active and the bq24257 device clears its battery fault error resulting in incorrectly reporting that the battery got reconnected. This patches removes the impact the battery removal/insertion has on the input current limit configured for the bq24257 and simplifies the associated handler routine. Signed-off-by: Andreas Dannenberg --- drivers/power/bq24257_charger.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c index 69b53d0..d2d077c 100644 --- a/drivers/power/bq24257_charger.c +++ b/drivers/power/bq24257_charger.c @@ -448,14 +448,13 @@ static void bq24257_handle_state_change(struct bq24257_device *bq, { int ret; struct bq24257_state old_state; - bool reset_iilimit = false; - bool config_iilimit = false; mutex_lock(&bq->lock); old_state = bq->state; mutex_unlock(&bq->lock); - if (!new_state->power_good) { /* power removed */ + if (!new_state->power_good) { + dev_dbg(bq->dev, "Power removed\n"); cancel_delayed_work_sync(&bq->iilimit_setup_work); /* activate D+/D- port detection algorithm */ @@ -463,26 +462,20 @@ static void bq24257_handle_state_change(struct bq24257_device *bq, if (ret < 0) goto error; - reset_iilimit = true; - } else if (!old_state.power_good) { /* power inserted */ - config_iilimit = true; - } else if (new_state->fault == FAULT_NO_BAT) { /* battery removed */ - cancel_delayed_work_sync(&bq->iilimit_setup_work); - - reset_iilimit = true; - } else if (old_state.fault == FAULT_NO_BAT) { /* battery connected */ - config_iilimit = true; - } else if (new_state->fault == FAULT_TIMER) { /* safety timer expired */ - dev_err(bq->dev, "Safety timer expired! Battery dead?\n"); - } - - if (reset_iilimit) { + /* reset input current limit */ ret = bq24257_field_write(bq, F_IILIMIT, IILIMIT_500); if (ret < 0) goto error; - } else if (config_iilimit) { + } else if (!old_state.power_good) { + dev_dbg(bq->dev, "Power inserted\n"); + + /* configure input current limit */ schedule_delayed_work(&bq->iilimit_setup_work, msecs_to_jiffies(BQ24257_ILIM_SET_DELAY)); + } else if (new_state->fault == FAULT_NO_BAT) { + dev_warn(bq->dev, "Battery removed\n"); + } else if (new_state->fault == FAULT_TIMER) { + dev_err(bq->dev, "Safety timer expired! Battery dead?\n"); } return;