Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932125AbZGOQVR (ORCPT ); Wed, 15 Jul 2009 12:21:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932160AbZGOQVQ (ORCPT ); Wed, 15 Jul 2009 12:21:16 -0400 Received: from buzzloop.caiaq.de ([212.112.241.133]:43784 "EHLO buzzloop.caiaq.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932146AbZGOQVC (ORCPT ); Wed, 15 Jul 2009 12:21:02 -0400 From: Daniel Mack To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, Daniel Mack , Szabolcs Gyurko , Matt Reimer , Anton Vorontsov Subject: [PATCH 4/4] ds2760: handle full_active_uAh == 0 case correctly Date: Wed, 15 Jul 2009 18:20:41 +0200 Message-Id: <1247674841-9909-4-git-send-email-daniel@caiaq.de> X-Mailer: git-send-email 1.6.3.1 In-Reply-To: <1247674841-9909-3-git-send-email-daniel@caiaq.de> References: <1247674841-9909-1-git-send-email-daniel@caiaq.de> <1247674841-9909-2-git-send-email-daniel@caiaq.de> <1247674841-9909-3-git-send-email-daniel@caiaq.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1689 Lines: 43 In systems where the battery monitor is not part of the battery pack and is hence not bootstrapped with sane values, the full_active_uAh is likely to be zero. Handle that case by defaulting to the rated_capacity information which can be passed to the driver using the new module parameter. Signed-off-by: Daniel Mack Cc: Szabolcs Gyurko Cc: Matt Reimer Cc: Anton Vorontsov --- drivers/power/ds2760_battery.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c index ed0ea5e..2d0e5ed 100644 --- a/drivers/power/ds2760_battery.c +++ b/drivers/power/ds2760_battery.c @@ -172,8 +172,13 @@ static int ds2760_battery_read_status(struct ds2760_device_info *di) di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 | di->raw[DS2760_ACTIVE_FULL + 1]; - scale[0] = di->raw[DS2760_ACTIVE_FULL] << 8 | - di->raw[DS2760_ACTIVE_FULL + 1]; + /* If the full_active_uAh value is not given, fall back to the rated + * capacity. This is likely to happen when chips are not part of the + * battery pack and is therefore not bootstrapped. */ + if (di->full_active_uAh == 0) + di->full_active_uAh = di->rated_capacity / 1000L; + + scale[0] = di->full_active_uAh; for (i = 1; i < 5; i++) scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 2 + i]; -- 1.6.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/