From patchwork Thu Aug 11 16:59:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9275667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2469760231 for ; Thu, 11 Aug 2016 17:01:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1240B28752 for ; Thu, 11 Aug 2016 17:01:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06B4728755; Thu, 11 Aug 2016 17:01:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C66128752 for ; Thu, 11 Aug 2016 17:01:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bXtKb-0003GK-27; Thu, 11 Aug 2016 16:59:45 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bXtKW-0003DW-TF for linux-arm-kernel@lists.infradead.org; Thu, 11 Aug 2016 16:59:41 +0000 Received: by mail-pf0-x242.google.com with SMTP id h186so62714pfg.2 for ; Thu, 11 Aug 2016 09:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/NsWvRCkF4dCPlP0pO2PzaZTqCWeLVdFNwGXBJOyKT8=; b=jIut75/N0yV2LPq7NXDwYtb7DrOFHK1xNC/w9yPtlbp1CPO3C4zoe5TGKOQh2yowtB hbGL6/rVpo6b9ln2zep50wkcacYue3Um011R51KZY+dXZLq9MgB2v5yblKhtl83kDOUG J5Sss7eMZvs6OL9zSN/vyt1lFeM1gEXTJWeA+7ZzqZD6gbXEhWRIPonWK1/Z5eBrd5ls CpWTBD543M7vAQGVU3bcjgRfDuRl1j+/STYlzyVrWCSwGQRZ0VuUzQagx4/FcyMpF3sc AVmLaWv1TL+ztXNjbMdlGhG6sX3ENaxNRhQZCUqiC3CZY2Oa7ijDm0+0jGd4h3+n8Ij/ QkEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/NsWvRCkF4dCPlP0pO2PzaZTqCWeLVdFNwGXBJOyKT8=; b=NSLxDV5aW7bXJ0XyqD5c7VhMEECu1hhqH7sh727naqAocXYRC58yfbXdmuyw2LORu1 jbSR11SOoo9UcJ1sbTQ5G47pcWf5WWpDyKV0W0MsGuT6gU/2rL+kRifun9YR4qOufvG1 gWGcE0XQuP1DIFCWuU8ob1qJLuJYlkQCkaYlShOxyWpxUf9pXtommDWDk9FQXAV8K2mV aEqh++df7aI3a0QklOAatyc4dHKr3pXjf64oqWs9mc1PGWHVOcpUjlzoYmtsbwHMYGLd TxtfwET+CrJ8Xzks7pdMy5BwIcuZlTPr5HOQRf+EImOexIY1mN4014eZT3Ic1pFSigGY N+LQ== X-Gm-Message-State: AEkooutPA0StoFLbTFYPTBqmclKZ/m3Q6Qu3VvPTbyT+4aCNC/65zJoWs9rIx+vDA4zO9Q== X-Received: by 10.98.80.220 with SMTP id g89mr18979709pfj.12.1470934759828; Thu, 11 Aug 2016 09:59:19 -0700 (PDT) Received: from jclayton-pc.columbia.uniwest.com (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id g21sm6631944pfj.88.2016.08.11.09.59.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 09:59:18 -0700 (PDT) From: Joshua Clayton To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse Subject: [PATCH 1/1] sbs-battery: add ability to get battery capacity Date: Thu, 11 Aug 2016 09:59:12 -0700 Message-Id: <1470934752-22719-1-git-send-email-stillcompiling@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160811_095941_021217_162E86F5 X-CRM114-Status: GOOD ( 14.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joshua Clayton , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Battery capacity level is a standard feature of sbs battery That can be used to tell what the remainig battery capacity is, and can tell if the battery has not been calibrated/initialized, which makes the capacity and charging/discharging percentages invalid. Signed-off-by: Joshua Clayton --- drivers/power/sbs-battery.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index 768b9fc..4f913b6 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c @@ -41,6 +41,7 @@ enum { REG_TIME_TO_EMPTY, REG_TIME_TO_FULL, REG_STATUS, + REG_CAPACITY_LEVEL, REG_CYCLE_COUNT, REG_SERIAL_NUMBER, REG_REMAINING_CAPACITY, @@ -68,6 +69,7 @@ enum sbs_battery_mode { #define MANUFACTURER_ACCESS_SLEEP 0x0011 /* battery status value bits */ +#define BATTERY_INITIALIZED 0x80 #define BATTERY_DISCHARGING 0x40 #define BATTERY_FULL_CHARGED 0x20 #define BATTERY_FULL_DISCHARGED 0x10 @@ -110,6 +112,8 @@ static const struct chip_data { SBS_DATA(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 0x13, 0, 65535), [REG_STATUS] = SBS_DATA(POWER_SUPPLY_PROP_STATUS, 0x16, 0, 65535), + [REG_CAPACITY_LEVEL] = + SBS_DATA(POWER_SUPPLY_PROP_CAPACITY_LEVEL, 0x16, 0, 65535), [REG_CYCLE_COUNT] = SBS_DATA(POWER_SUPPLY_PROP_CYCLE_COUNT, 0x17, 0, 65535), [REG_DESIGN_CAPACITY] = @@ -131,6 +135,7 @@ static const struct chip_data { static enum power_supply_property sbs_properties[] = { POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_CAPACITY_LEVEL, POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_TECHNOLOGY, @@ -377,8 +382,23 @@ static int sbs_get_battery_property(struct i2c_client *client, if (ret >= sbs_data[reg_offset].min_value && ret <= sbs_data[reg_offset].max_value) { val->intval = ret; - if (psp != POWER_SUPPLY_PROP_STATUS) + if (psp == POWER_SUPPLY_PROP_CAPACITY_LEVEL) { + if (!(ret & BATTERY_INITIALIZED)) + val->intval = + POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; + else if (ret & BATTERY_FULL_CHARGED) + val->intval = + POWER_SUPPLY_CAPACITY_LEVEL_FULL; + else if (ret & BATTERY_FULL_DISCHARGED) + val->intval = + POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; + else + val->intval = + POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; return 0; + } else if (psp != POWER_SUPPLY_PROP_STATUS) { + return 0; + } if (ret & BATTERY_FULL_CHARGED) val->intval = POWER_SUPPLY_STATUS_FULL; @@ -590,6 +610,7 @@ static int sbs_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_STATUS: + case POWER_SUPPLY_PROP_CAPACITY_LEVEL: case POWER_SUPPLY_PROP_CYCLE_COUNT: case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW: