From patchwork Thu Oct 30 12:43:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 5197491 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 90E279F318 for ; Thu, 30 Oct 2014 12:47:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A64B1201CD for ; Thu, 30 Oct 2014 12:47:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A973320172 for ; Thu, 30 Oct 2014 12:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759930AbaJ3Mq0 (ORCPT ); Thu, 30 Oct 2014 08:46:26 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:45008 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759938AbaJ3MnZ (ORCPT ); Thu, 30 Oct 2014 08:43:25 -0400 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NE9007M4CO92MA0@mailout3.samsung.com>; Thu, 30 Oct 2014 21:43:21 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.113]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 5E.18.19034.96232545; Thu, 30 Oct 2014 21:43:21 +0900 (KST) X-AuditID: cbfee691-f79b86d000004a5a-ad-54523269c912 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 5B.24.09430.96232545; Thu, 30 Oct 2014 21:43:21 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NE900852CO56T50@mmp1.samsung.com>; Thu, 30 Oct 2014 21:43:21 +0900 (KST) From: Jonghwa Lee To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org, pavel@ucw.cz, myungjoo.ham@samsung.com, cw00.choi@samsung.com, Jonghwa Lee Subject: [PATCH 04/10] power: charger-manager: Fix to use CHARGE_NOW/FULL property correctly. Date: Thu, 30 Oct 2014 21:43:10 +0900 Message-id: <1414672996-28355-5-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1414672996-28355-1-git-send-email-jonghwa3.lee@samsung.com> References: <1414672996-28355-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrILMWRmVeSWpSXmKPExsWyRsSkUDfTKCjE4PoDSYuDWzUtrn95zmox 6cl7ZouJKyczW3SefcJscXnXHDaLz71HGC1uN65gs7h76iibxendJQ5cHhP6PzF67Jx1l91j 8wotj02rOtk8+rasYvRYsfo7u8fnTXIB7FFcNimpOZllqUX6dglcGT+vn2Yu+KZccebgMaYG xkuyXYwcHBICJhJHTvB3MXICmWISF+6tZ+ti5OIQEljKKLGu5SAzRMJE4kLXX2aIxCJGiRfb mhkhnDYmiTc7D7GDVLEJ6Ej833cTzBYRUJDY3PuMFaSIWeAKo8TNxeuZQBLCAvESW7ZcAxvL IqAqcfjDJkYQm1fAQ6Lx7nQWiJMUJOZMsgEJcwp4Smy6MpMFxBYCKnmwq4sdZKaEwCF2iYVt e6HmCEh8m3wIqldWYtMBqKslJQ6uuMEygVF4ASPDKkbR1ILkguKk9CJTveLE3OLSvHS95Pzc TYzAmDj979nEHYz3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xLer4z7xgWZvexbD9EcVXX9hZrurVOa19bMf3j74Oc9ZWCQRvXHnHRuTx 4uV/RRjeTi78ZeDAmPH6zJWWJbU7DeyNVr0Q9Vm/PNDSzOWrv5SyJI9NNA/T8ajNnU0XY5TZ rR5e59ivYKbEUpyRaKjFXFScCAAWu1AVzwIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 The POWER_SUPPLY_CHARGE_NOW/FULL property reflects battery's charges in uAh unit, but charger-manager has been used it wrongly. This patch makes it to use those propeties correctly and change to be optional. Signed-off-by: Jonghwa Lee --- drivers/power/charger-manager.c | 85 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 57 deletions(-) diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 64fdaaf..687f109 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c @@ -796,35 +796,13 @@ static int charger_get_property(struct power_supply *psy, val->intval = 0; break; case POWER_SUPPLY_PROP_CHARGE_FULL: - if (is_full_charged(cm)) - val->intval = 1; - else - val->intval = 0; - ret = 0; - break; case POWER_SUPPLY_PROP_CHARGE_NOW: - if (is_charging(cm)) { - fuel_gauge = power_supply_get_by_name( - cm->desc->psy_fuel_gauge); - if (!fuel_gauge) { - ret = -ENODEV; - break; - } - - ret = fuel_gauge->get_property(fuel_gauge, - POWER_SUPPLY_PROP_CHARGE_NOW, - val); - if (ret) { - val->intval = 1; - ret = 0; - } else { - /* If CHARGE_NOW is supplied, use it */ - val->intval = (val->intval > 0) ? - val->intval : 1; - } - } else { - val->intval = 0; + fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge); + if (!fuel_gauge) { + ret = -ENODEV; + break; } + ret = fuel_gauge->get_property(fuel_gauge, psp, val); break; default: return -EINVAL; @@ -832,8 +810,7 @@ static int charger_get_property(struct power_supply *psy, return ret; } -#define NUM_CHARGER_PSY_OPTIONAL (4) -static enum power_supply_property default_charger_props[] = { +static enum power_supply_property cm_default_props[] = { /* Guaranteed to provide */ POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_HEALTH, @@ -841,20 +818,21 @@ static enum power_supply_property default_charger_props[] = { POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_ONLINE, - POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_TEMP, - /* - * Optional properties are: - * POWER_SUPPLY_PROP_CHARGE_NOW, - * POWER_SUPPLY_PROP_CURRENT_NOW, - */ }; +static enum power_supply_property cm_optional_props[] = { + POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, +}; + +#define CM_NUM_OF_PROPS \ + (ARRAY_SIZE(cm_default_props) + ARRAY_SIZE(cm_optional_props)) + static struct power_supply psy_default = { .name = "battery", .type = POWER_SUPPLY_TYPE_BATTERY, - .properties = default_charger_props, - .num_properties = ARRAY_SIZE(default_charger_props), .get_property = charger_get_property, .no_thermal = true, }; @@ -1484,29 +1462,22 @@ static int charger_manager_probe(struct platform_device *pdev) /* Allocate for psy properties because they may vary */ cm->charger_psy.properties = devm_kzalloc(&pdev->dev, sizeof(enum power_supply_property) - * (ARRAY_SIZE(default_charger_props) + - NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL); + * CM_NUM_OF_PROPS, GFP_KERNEL); if (!cm->charger_psy.properties) return -ENOMEM; - memcpy(cm->charger_psy.properties, default_charger_props, - sizeof(enum power_supply_property) * - ARRAY_SIZE(default_charger_props)); - cm->charger_psy.num_properties = psy_default.num_properties; - - /* Find which optional psy-properties are available */ - if (!fuel_gauge->get_property(fuel_gauge, - POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { - cm->charger_psy.properties[cm->charger_psy.num_properties] = - POWER_SUPPLY_PROP_CHARGE_NOW; - cm->charger_psy.num_properties++; - } - if (!fuel_gauge->get_property(fuel_gauge, - POWER_SUPPLY_PROP_CURRENT_NOW, - &val)) { - cm->charger_psy.properties[cm->charger_psy.num_properties] = - POWER_SUPPLY_PROP_CURRENT_NOW; - cm->charger_psy.num_properties++; + memcpy(cm->charger_psy.properties, cm_default_props, + sizeof(enum power_supply_property) * + ARRAY_SIZE(cm_default_props)); + cm->charger_psy.num_properties = ARRAY_SIZE(cm_default_props); + + /* Add available optional properties */ + for (i = 0; i < ARRAY_SIZE(cm_optional_props); i++) { + if (fuel_gauge->get_property(fuel_gauge, + cm_optional_props[i], &val)) + continue; + cm->charger_psy.properties[cm->charger_psy.num_properties++] = + cm_optional_props[i]; } if (desc->thermal_zone) {