From patchwork Thu Oct 31 12:22:42 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: 178168 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2760818ill; Thu, 31 Oct 2019 05:24:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi7uznvm6zL7r1Zy147ojQMs1in+dgDRNcx/2A54oletugsrk5OXoDLdmWcS7MuU7rLJwA X-Received: by 2002:a17:906:66ce:: with SMTP id k14mr3588701ejp.92.1572524657452; Thu, 31 Oct 2019 05:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572524657; cv=none; d=google.com; s=arc-20160816; b=XvNc/kdMsH6momd1qF2nYK42G4VqC4qUZxWyXPYdHE9CNAqwpufJjSA8V7PorgigJm 0q+bIYr+1SAe5jCzuo8ocViASJtoIH+HcFV7OBYQ5EmhIITJHOcsfLHzMP4/JrDk4TfV 9Ltapj7WeCD0u9DQ7Zsv3qUes/sCdYume2JZr0Z0WF6pBwR87Oe/Rzd/P3aijorYJwgJ 2y0Sm/vOWxfQJZGYpZ7LlT5Yf1k+IDwik2t+a7YGb6hGrgJQ4aFu1L8Fk7B4puDyRW4m OzgTJHOp3fYaK0pkPzJobqpy0zzxBDrXA04JvXRmkJJE7pJ/kuSZHvPWewyaVN7eTZ1S 68BA== 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=GXi+ce7YnMTMe5ScBH9wEkaWtGdafbe7tDP9N+FujF/PhL9oSxmnZ6TAmRMmupbeFh qD/t1aWAek0AKZDEbN0LzqndFI4SvZXaQWLtAmCKs6YvU2396pFa9EiKkPn6WPydoB4v A+GmLgbmQsHI/zYT0cAJrgQTcKcryNsy1/vItr9L3vH3sgwBBx8zuCi56YVpatesSzUI hl1PMWSss6ahzNqtGDNwx4YdzQ548uK+udLBqdgW4+VwjdcXcciXOWsuAmfapqbr4tu1 SkQh9LatJME/DLFY356fKmNRuX/J6RJqKSdw2hww37brMHatxO2SfKj/xWN8e6OfV4Wo GjLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ts249/eg"; 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 f54si3772755edb.255.2019.10.31.05.24.17; Thu, 31 Oct 2019 05:24:17 -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="Ts249/eg"; 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 S1727364AbfJaMXu (ORCPT + 8 others); Thu, 31 Oct 2019 08:23:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42278 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726728AbfJaMXu (ORCPT ); Thu, 31 Oct 2019 08:23:50 -0400 Received: by mail-pf1-f194.google.com with SMTP id 21so4260098pfj.9 for ; Thu, 31 Oct 2019 05:23:49 -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=Ts249/egnrhzEnpXd834uI2TsYDQGJUwwxIXs5mn5C+Q4KZiVMKkCBPTYzys4nYqgq xziLKywtITszSHspc6rib/y5uXeygD6cYUVj4k1TGPpDyI5VdC9JdZJ0SbRlx/uFMx4q yqlRwdLtYMNEnlDwSS1VfDuyr4zuEb8mmG8e7h0Wgw5lIlEcPX19EbMBKah2Bq53HI1v SpMA7AHFE02wNG4vvt+SB6TCGEo6ZUQT37b+DgdXeKv5sdSTpFjzx8+yEGB0RRSTa6IY 6+iwybqUmbH21IGe8G0TCqltT5PMjVbhBcYLhiGWYPZzW7Azs4ZcZ3XPJF+bWTIIKHEo FRIQ== 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=G7pV9/pVjEWbpwiXyHKlQzJGTsjCzaCbqZreu3UwT7/8FOht/Ombnj6r9vhWThAMYD 5hUgHd7zsGRA6q6DaFj3ofAEc/jf/HGjxxvdOh+AANdJWjlaaknR2YR9B9rU8aS8osEd G8MHsN8yPEWb2UpgSYl67s7ORpvomeQggj8+Q2OA93G6vj5sdf+DEXGIvalgCZste5iZ 70YNeL5u/xrANdqnC2cuGF9kXalcZjH7yHKNHq+c1zVJ/Adu60bhIp6bU8oEaRmBVIEI 3saoD8skLgpT7Oocyo3xp0KtxRhNxFXgjoPbCFD+Fdhv03r/KepjFtCt0ZM7QtC4CjLI gJvw== X-Gm-Message-State: APjAAAXBvtOCfCbQPbSDppjIIJ5uQmdoqnvfVq1c4S+tJsdZNW4mauQa PlJPU9K29mK5kM+8XOBNak0nxQ== X-Received: by 2002:a17:90a:8816:: with SMTP id s22mr2159357pjn.31.1572524628486; Thu, 31 Oct 2019 05:23:48 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id j25sm2983077pfi.113.2019.10.31.05.23.44 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Oct 2019 05:23:47 -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 v2 3/5] power: supply: sc27xx: Optimize the battery resistance with measuring temperature Date: Thu, 31 Oct 2019 20:22:42 +0800 Message-Id: <3dbd343189aa027c00148a5d8365661aa8b4c7ff.1572523415.git.baolin.wang@linaro.org> 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);