From patchwork Mon Oct 28 07:18:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 177884 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3012698ill; Mon, 28 Oct 2019 00:20:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQuYFrnfGN8j9pguXyTGO+dvuBb4pMAr2q3uwUAs1etBQVh1EEAlkc/cugzaT9Ms3XvEyU X-Received: by 2002:a05:6402:1614:: with SMTP id f20mr18111651edv.202.1572247201237; Mon, 28 Oct 2019 00:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572247201; cv=none; d=google.com; s=arc-20160816; b=oF4bUxtO7S+6JMhYs8kFk8DsOFAokZmaYEObG8ReY+UU0HVybEvzvvy9GJlSVKnMLc 2VWGuDXA2WJKuR5cwOcQJvL+WcGb7iNC29w2XPZJ0Lqz/ReG109TGWMU2bjDPHXp7IsS Y1or05XTNaSSgk2oG+UsyYuNI499QZIB5nplSvmWPSHxVWIx0cn6CDy8Yxnt5DWUg12Z vsOD+lpPisX4o2z9wH6Nev79Mt46znkbicRZ0cRoINtMK3cW8BJDRFrW4Qq4uv52BQ9U Kiayb6QG09Z0rrMEkYVsjRx+TN4rWYTSV50BIzS3ux1ouB5yzV7uZ+9//iwwZX63c8F6 aFqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=zQKRY2XE5oS+mi6BE44agpH5JNOXqmvzvanMV9EmHYs=; b=sucfSrLONTGUQOVS8rBdbpbqqkn9F+RTE/NxvVhTqBUNFJhvpExClbTw8dzJPPuU6v n2pCrbvxyedtmBCPZ4eKw3wtwV3j+t+bomgQp3oFUOXwvdo0F0xlRhRqMwnuqw2YRdtf GUy6QTWpmDMV/G6IPUxOerR15P89FBvKYrgh6Wura5YXSX2JPZCadWV4bIkz6QUZ9Zzz GDT3HjCrVAJalvZ/o2Zhi+8lGgq3Vs4O3cNJ/5aeOiQpJJlEGr0fpzERVouwDj9zHFTc 7QNeaga4+rVPhNsB6HnrEAyVvAbsto12tuEl8HvPLBzx1gNZ8VR3YFGoeQRUhAgxeYUu HDgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fm2GAqpv; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si5529473eju.251.2019.10.28.00.20.01; Mon, 28 Oct 2019 00:20:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fm2GAqpv; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732548AbfJ1HT7 (ORCPT + 8 others); Mon, 28 Oct 2019 03:19:59 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39857 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732514AbfJ1HT7 (ORCPT ); Mon, 28 Oct 2019 03:19:59 -0400 Received: by mail-pl1-f193.google.com with SMTP id t12so523988plo.6 for ; Mon, 28 Oct 2019 00:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=zQKRY2XE5oS+mi6BE44agpH5JNOXqmvzvanMV9EmHYs=; b=fm2GAqpvOV5+xOdAo3r0mmuXfnSQudliJYYK8fQmDxTzI5/A6qJcm4cFNtMt6kztOm LEZHSgqqIvCQzImsVgxaM52k5nBlExW9YWo98VQGVjqF2zzmrhFIgBsgconeYJH6Qo3C VOUk3K90fTM/4g9mYUqnSN3J9E/qTa4ERPQnuGuNs8WpJGU+wX7gRuHHnAuwqB+0XZ9u YFsSnfSzwhLA6UHhm24M9X1b3D1RELJx5tC2NgLdio/S+QPsiIfaaJKTaGFZklAVbZqk shg3n+kFoHcQ10KLL5GSbW9Xps5orYtPui3XQeo+GlHYFiS6PYd+0TGb8KMDMZeBbzr4 TzPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=zQKRY2XE5oS+mi6BE44agpH5JNOXqmvzvanMV9EmHYs=; b=C/P57CsH+hD+7TU4Arfp7tW50CkFLXc4PxkeP6kd5AAasdiisfqWsQ6E4CpVqfkvQm Uxen0kQWh2XQ3xIxC28M+QvRHZpdEHmku//LzXFE2Rxqyvmvb+hAKE3pqIAXCvpQu2xt UdRV3LSs0bwDPzE6/QqX++3xVTZT0JaSexzmNotcn/hEd6TW2sLpwrAdJqOAzRv/qhwi fLA1H533QQKBScsfn7z+4Z80mxQmXZLdpOG4Sfxc/QiFDZ0jEB1breGNIFzYRbVlxR8l b6a65TkFOlCWPwVkquU1InnJ6Gmu91YZihCxkWHDz9gzvVLNRC1KO/33QtJKqx1ZyA4k vTeg== X-Gm-Message-State: APjAAAVkmv057OCWK3dpPQJHlTW7Nrnf47NJWKbLNyjAb8+nGTiVbRW7 EKonwoAzdQ/0yOp1G5uRxtmT3A== X-Received: by 2002:a17:902:8b83:: with SMTP id ay3mr17436518plb.269.1572247198266; Mon, 28 Oct 2019 00:19:58 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 13sm11504703pgq.72.2019.10.28.00.19.54 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 00:19:57 -0700 (PDT) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, baolin.wang7@gmail.com, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 2/5] power: supply: core: Add battery internal resistance temperature table support Date: Mon, 28 Oct 2019 15:18:58 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Since the battery internal resistance can be changed with the temperature changes, thus add a resistance temperature table support to look up the accurate battery internal resistance in a certain temperature. Signed-off-by: Baolin Wang --- drivers/power/supply/power_supply_core.c | 67 +++++++++++++++++++++++++++++- include/linux/power_supply.h | 10 +++++ 2 files changed, 76 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 5c36c43..1a9a9fa 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -565,9 +565,11 @@ struct power_supply *devm_power_supply_get_by_phandle(struct device *dev, int power_supply_get_battery_info(struct power_supply *psy, struct power_supply_battery_info *info) { + struct power_supply_resistance_temp_table *resist_table; struct device_node *battery_np; const char *value; int err, len, index; + const __be32 *list; info->energy_full_design_uwh = -EINVAL; info->charge_full_design_uah = -EINVAL; @@ -578,6 +580,7 @@ int power_supply_get_battery_info(struct power_supply *psy, info->constant_charge_current_max_ua = -EINVAL; info->constant_charge_voltage_max_uv = -EINVAL; info->factory_internal_resistance_uohm = -EINVAL; + info->resist_table = NULL; for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) { info->ocv_table[index] = NULL; @@ -644,7 +647,6 @@ int power_supply_get_battery_info(struct power_supply *psy, for (index = 0; index < len; index++) { struct power_supply_battery_ocv_table *table; char *propname; - const __be32 *list; int i, tab_len, size; propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index); @@ -677,6 +679,26 @@ int power_supply_get_battery_info(struct power_supply *psy, } } + list = of_get_property(battery_np, "resistance-temp-table", &len); + if (!list || !len) + goto out_put_node; + + info->resist_table_size = len / (2 * sizeof(__be32)); + resist_table = info->resist_table = devm_kcalloc(&psy->dev, + info->resist_table_size, + sizeof(*resist_table), + GFP_KERNEL); + if (!info->resist_table) { + power_supply_put_battery_info(psy, info); + err = -ENOMEM; + goto out_put_node; + } + + for (index = 0; index < info->resist_table_size; index++) { + resist_table[index].temp = be32_to_cpu(*list++); + resist_table[index].resistance = be32_to_cpu(*list++); + } + out_put_node: of_node_put(battery_np); return err; @@ -692,10 +714,53 @@ void power_supply_put_battery_info(struct power_supply *psy, if (info->ocv_table[i]) devm_kfree(&psy->dev, info->ocv_table[i]); } + + if (info->resist_table) + devm_kfree(&psy->dev, info->resist_table); } EXPORT_SYMBOL_GPL(power_supply_put_battery_info); /** + * power_supply_temp2resist_simple() - find the battery internal resistance + * percent + * @table: Pointer to battery resistance temperature table + * @table_len: The table length + * @ocv: Current temperature + * + * This helper function is used to look up battery internal resistance percent + * according to current temperature value from the resistance temperature table, + * and the table must be ordered descending. Then the actual battery internal + * resistance = the ideal battery internal resistance * percent / 100. + * + * Return: the battery internal resistance percent + */ +int power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table, + int table_len, int temp) +{ + int i, resist; + + for (i = 0; i < table_len; i++) + if (temp > table[i].temp) + break; + + if (i > 0 && i < table_len) { + int tmp; + + tmp = (table[i - 1].resistance - table[i].resistance) * + (temp - table[i].temp); + tmp /= table[i - 1].temp - table[i].temp; + resist = tmp + table[i].resistance; + } else if (i == 0) { + resist = table[0].resistance; + } else { + resist = table[table_len - 1].resistance; + } + + return resist; +} +EXPORT_SYMBOL_GPL(power_supply_temp2resist_simple); + +/** * power_supply_ocv2cap_simple() - find the battery capacity * @table: Pointer to battery OCV lookup table * @table_len: OCV table length diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 28413f7..dcd5a71 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -325,6 +325,11 @@ struct power_supply_battery_ocv_table { int capacity; /* percent */ }; +struct power_supply_resistance_temp_table { + int temp; /* celsius */ + int resistance; /* internal resistance percent */ +}; + #define POWER_SUPPLY_OCV_TEMP_MAX 20 /* @@ -349,6 +354,8 @@ struct power_supply_battery_info { int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; + struct power_supply_resistance_temp_table *resist_table; + int resist_table_size; }; extern struct atomic_notifier_head power_supply_notifier; @@ -381,6 +388,9 @@ extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *ta int temp, int *table_len); extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info, int ocv, int temp); +extern int +power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table, + int table_len, int temp); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); extern int power_supply_set_input_current_limit_from_supplier( From patchwork Mon Oct 28 07:18:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 177885 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3012769ill; Mon, 28 Oct 2019 00:20:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyw26bxGOtANiNKAoyE7s81tRgR94le2aC/n0l0rmA465Qw9Q+VDY3O9vPjCRidvk0M4KxE X-Received: by 2002:a17:906:95d6:: with SMTP id n22mr15072364ejy.295.1572247205929; Mon, 28 Oct 2019 00:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572247205; cv=none; d=google.com; s=arc-20160816; b=klSdoGuLRSwwdu4tqktYMhyAudNc7YOhb52U9VzXn4M+swZGmvjh5qYEEHthRrfgwq tIkKFJtQarPqh5OtDWlsisDxYFsSFA9X2QsE6HWwyrkl7pZXdz7ISFSy5L5c8/nz9Xzs 0fiHfEJnKfg02xgTYtaAtGy0jYG4GmXKFr00sGfTteAwD/I8cg5dMxLvfPU0UTvaitsj aiKIqxBjnt5NO9pqjP4qEcvA0Mw06aXT7mdyUJtY4jM1LmZYM51GE74QSMW46i8tj/Tz e47ClZqOQpt2DHhPwAmAA9Ad5m7SkZGfN6g+xu5qNiV+tTJn32TqNbKsnYEppVu4P/w/ SqGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ipn4aXAOp87D2v3r9KdhlrkAx9KnL+jbYVkv6tX05Nc=; b=Ul1N0SxYSvUrCS6yCFg8o+8zncwJCldkWTmXCY69Q/bhYEf8ij25IuEIBd9u4G4t/o LHDya04WgX81tvYRIbpEv2NvRUUW7U5L8VdztMG4bPsEbhxYiQjnimc/b0W1ShAyQeZP 2ktuPjWxsfzWAG3uEEs5wZQkT6B+p7ifzOelyJdJdif2v7GwLNIg/w9Bjx0KLSsDgwFV PgG+QVPsHsFX+QQZqYADEEBDwHDrvdS97bULLVDagzvjJ6sLI3I9xtHrTEctSghp8nB4 i32O1TJS/BurUr04wVru4lYcEITTzXFyKGm4XNR6A9BOHWhegUmrDnHEZdtYUfIySQ6d XvTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H7ANTgpg; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5si4962030eja.353.2019.10.28.00.20.05; Mon, 28 Oct 2019 00:20:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H7ANTgpg; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732569AbfJ1HUE (ORCPT + 8 others); Mon, 28 Oct 2019 03:20:04 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42352 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732514AbfJ1HUC (ORCPT ); Mon, 28 Oct 2019 03:20:02 -0400 Received: by mail-pg1-f194.google.com with SMTP id f14so6283633pgi.9 for ; Mon, 28 Oct 2019 00:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ipn4aXAOp87D2v3r9KdhlrkAx9KnL+jbYVkv6tX05Nc=; b=H7ANTgpgwQ2+56L1vk0+gI3rNxCVOKam39g5rW/rxFArWeEN7xShdeud1+d5tj9sYT zIQeHuJdV1Lrm6P/tHiq/LJK/fJmt6fMPFh4FcD0bMWcXf1HVdxlg5m7eSqz+oW7EB2o HaJBqfCN2qoz0tVbDYTRIEa+2kA2Lq/Qkidt+66llOixVDJ8k3YK3NVMYE4CJFAyjuFq icvCAHsQbWSsbgrczubJZTzyDXX5YRAM2GtS5FH7mxhDU/vSdQAbmz8Zy8gKhAP9W71m xVIfVf2rJsZgtJsnFsVAQHRy4M9ThVbBpi9/JPuSPrNWQJLqTZ9DIH+1BPmKuydMRADC SVeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ipn4aXAOp87D2v3r9KdhlrkAx9KnL+jbYVkv6tX05Nc=; b=SLdF9V8Dui7AbpXQ75Bf3Hjhf1YkDkN2+rrp22g1ukYh/PHFZqDfxGmWuIYOr8gD9H nte0B8FcawtEHPzZy27oY+SWZ49XiXPuyLLmcHlJIvQXOokFJRHxaPVXD+kYfKSySxqk B3m8klfhECofGTuIyVbLr4NrbEqX9T8DWlurQ8wPgAgd0zGItltACrnltF2PViwW4BMB yQbXbsoLoUet3f9j239wvtel7MxpG0fVJ0aJOboEd7hazKRUw3+6tg23DE/7RND5gsOQ HplfcvR4yPHvzbf46P3mRjIPCYFMRHhD2kvelv0HK3w5gL1lQv444vVLVQBOMsFT+FWg 1Utw== X-Gm-Message-State: APjAAAWMvqnhY36mZzqKuuGBQ866mwHc5O9nJTMKzEWiItBe4t+YJBYu WgYWn0QE3lYixwTUvSLhJM+MFw== X-Received: by 2002:a63:ff54:: with SMTP id s20mr18562592pgk.398.1572247202088; Mon, 28 Oct 2019 00:20:02 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 13sm11504703pgq.72.2019.10.28.00.19.58 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 00:20:01 -0700 (PDT) From: Baolin Wang To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, baolin.wang7@gmail.com, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 3/5] power: supply: sc27xx: Optimize the battery resistance with measuring temperature Date: Mon, 28 Oct 2019 15:18:59 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Yuanjiang Yu Optimize the battery internal resistance in a certain temerature to get a accurate battery internal resistance. Signed-off-by: Yuanjiang Yu Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) -- 1.7.9.5 diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index bc8f5bd..221b6fb 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -81,9 +81,11 @@ * @max_volt: the maximum constant input voltage in millivolt * @min_volt: the minimum drained battery voltage in microvolt * @table_len: the capacity table length + * @resist_table_len: the resistance table length * @cur_1000ma_adc: ADC value corresponding to 1000 mA * @vol_1000mv_adc: ADC value corresponding to 1000 mV * @cap_table: capacity table with corresponding ocv + * @resist_table: resistance percent table with corresponding temperature */ struct sc27xx_fgu_data { struct regmap *regmap; @@ -103,15 +105,18 @@ struct sc27xx_fgu_data { int max_volt; int min_volt; int table_len; + int resist_table_len; int cur_1000ma_adc; int vol_1000mv_adc; struct power_supply_battery_ocv_table *cap_table; + struct power_supply_resistance_temp_table *resist_table; }; static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity); static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data, int cap, bool int_mode); static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap); +static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp); static const char * const sc27xx_charger_supply_name[] = { "sc2731_charger", @@ -434,7 +439,7 @@ static int sc27xx_fgu_get_current(struct sc27xx_fgu_data *data, int *val) static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val) { - int vol, cur, ret; + int vol, cur, ret, temp, resistance; ret = sc27xx_fgu_get_vbat_vol(data, &vol); if (ret) @@ -444,8 +449,19 @@ static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val) if (ret) return ret; + resistance = data->internal_resist; + if (data->resist_table_len > 0) { + ret = sc27xx_fgu_get_temp(data, &temp); + if (ret) + return ret; + + resistance = power_supply_temp2resist_simple(data->resist_table, + data->resist_table_len, temp); + resistance = data->internal_resist * resistance / 100; + } + /* Return the battery OCV in micro volts. */ - *val = vol * 1000 - cur * data->internal_resist; + *val = vol * 1000 - cur * resistance; return 0; } @@ -929,6 +945,18 @@ static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data *data) if (!data->alarm_cap) data->alarm_cap += 1; + data->resist_table_len = info.resist_table_size; + if (data->resist_table_len > 0) { + data->resist_table = devm_kmemdup(data->dev, info.resist_table, + data->resist_table_len * + sizeof(struct power_supply_resistance_temp_table), + GFP_KERNEL); + if (!data->resist_table) { + power_supply_put_battery_info(data->battery, &info); + return -ENOMEM; + } + } + power_supply_put_battery_info(data->battery, &info); ret = sc27xx_fgu_calibration(data);