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);