From patchwork Mon Oct 28 07:19:01 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: 177887 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3012974ill; Mon, 28 Oct 2019 00:20:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTUjBMvmgqjjmLQeZUdmpEKq+ll+5YyhUZAi2oCMbD13NgDGZNFCElTaAKFzovX7tUuhju X-Received: by 2002:a17:906:5859:: with SMTP id h25mr7422892ejs.2.1572247216254; Mon, 28 Oct 2019 00:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572247216; cv=none; d=google.com; s=arc-20160816; b=0p//DNHwHeABrqlwZm3pRsj63H3t4djUlnAaIX9DkMxRFdZ9OwjqRAz6Rr43KYhlGG iApBDycAEGQvnZ56T3/5EkpEVMzKPQ3Y50pn3I68/uKsc2KhyaMcHl/Xn7ajG5BHRchE liT07CU9MQQhKImZxgA74wLmcmphu192jEabQc4nlX+mu2DMbpXld9OWetg6Fv8YzhgZ R0ADVv49RejsHG8UvoGFp4Uu3etQ9NzdboaA/DOf5f6gYFOzhMMtelfntO54aSVk9ZDI 3tN7zdP2CKjuIesivG4Sk5iZ0pEGwBn33hkRrfMH09iVJ4lYPAOsZpLYu21HgKyDGrrC OEAQ== 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=HKtGe92TapQ2KIwqzwkswK8RAIuyaGxBvNdNmUU4dN4=; b=GcR8bwrY7SHJqKiQMHux46yXLyzzneMkkzCYvmQr0C2LB+Mt2bAE2aqetrRPPlggbn 9N5q9HS27P1zl22OXFn0+pZSXr2QqctSLP3h7apr0UDpPTTFIVgsk6XWRBR4WHT8may1 f6AmjGl5HLGXehCcY8j8j+2Tc9NUqrerf6Qi42nYQVryzOGBxINzv7WeaRkSZu4KZoNF Q3ZbPq031D0aULOc1cncPXszjO22Iv0J6cU0DabltEw8I8Q1/S8AuQ/LDdnxiqgaxbij F1RkZZrDl+drDiIuPIZXjpjrtyFuaOHSLMrDVuanAz+Yg3VK1a6a5wjKgtpjFNiwURV0 RN1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v6uDInPr; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 n14si5136309ejx.354.2019.10.28.00.20.15; Mon, 28 Oct 2019 00:20:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=v6uDInPr; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1732641AbfJ1HUL (ORCPT + 10 others); Mon, 28 Oct 2019 03:20:11 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41791 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732605AbfJ1HUK (ORCPT ); Mon, 28 Oct 2019 03:20:10 -0400 Received: by mail-pf1-f196.google.com with SMTP id p26so2148009pfq.8 for ; Mon, 28 Oct 2019 00:20:10 -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=HKtGe92TapQ2KIwqzwkswK8RAIuyaGxBvNdNmUU4dN4=; b=v6uDInPrs2q1qq4SFLLdTjpdDc3eS25cnyOgpZtsm/H1e6dUBVUjCnRTrIW9Je4DLe XqJz6uv+N5YdTtXGCsY5Nwk+YABBQWVqJRGdRpgtWscX0dTeHgTPJbLMsxO2Nn6Hjz3S dbBAmtfdRa2obhR4Db360QfEdyh2kQKCBrXYwvs4DQUeecLSmuAgCNg+8vDcZ+byWbxq kvfNWHa1AXgqxiYlqzAl/rAe0f36GBnVfL8P29Oh6h2SM/31I+Xd91PIcC63SXDmcHIo jZzak31XqYgXmaToPXOP0+62BYK/AyoRWAgahLk4g/uE6jWTpMz8/SETq2QRPAsWDrvB +2AQ== 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=HKtGe92TapQ2KIwqzwkswK8RAIuyaGxBvNdNmUU4dN4=; b=OfgSjXDeppjY9teCFBmzVlg/D7ZeZ89kyXWgUYCw3xXnSBnQG5DiNJHmn4Nc5+OTzH CADKamoG9bhnFVbVyaCIzOSjwEPkUgSJ0S2C/INXKjBh7gGcPmpBu/36LaOpbF0GnH6B rnQPdV68MW0IOVfhEnM+JMmdI+egv/r9Oc0haBks/TatXRggoljctLkZ4WxPko46nOng 8y9E7VNRIcHvFSkW1+U00zX1nIWxy5gBLfoIXWcSM9j+hHgQ1WBJ90//YTpLGTAhA32O LyeiHYRbDTQwYr3alyLHrSQCN8gSxas5crI5Ptl17r+RF1NaJziIJv5R6I2SOVtp9scf EX4w== X-Gm-Message-State: APjAAAUvkEBMD6RRjfwDpz7z3S3GuwkIjn2bT7Heb7uYTBjrSj7jyaA2 R9cHIy5xyl8c4eTUmNi9ln3Ipg== X-Received: by 2002:a62:108:: with SMTP id 8mr9220601pfb.53.1572247209947; Mon, 28 Oct 2019 00:20:09 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 13sm11504703pgq.72.2019.10.28.00.20.06 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Oct 2019 00:20:09 -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 5/5] power: supply: sc27xx: Calibrate the resistance of coulomb counter Date: Mon, 28 Oct 2019 15:19:01 +0800 Message-Id: <9c25e3ab9bdba2914b22cfe7495818740437ef27.1572245011.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There are some deviations between the real resistance and the ideal resistance of coulomb counter, which will affect the accuracy of the coulomb counter, thus calibrate the real resistance of coulomb counter to improve the accuracy. Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index 221b6fb..f363fa7 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -62,6 +62,8 @@ #define SC27XX_FGU_CUR_BASIC_ADC 8192 #define SC27XX_FGU_SAMPLE_HZ 2 +/* micro Ohms */ +#define SC27XX_FGU_IDEAL_RESISTANCE 20000 /* * struct sc27xx_fgu_data: describe the FGU device @@ -84,6 +86,7 @@ * @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 + * @calib_resist: the real resistance of coulomb counter chip in mOhm * @cap_table: capacity table with corresponding ocv * @resist_table: resistance percent table with corresponding temperature */ @@ -108,6 +111,7 @@ struct sc27xx_fgu_data { int resist_table_len; int cur_1000ma_adc; int vol_1000mv_adc; + int calib_resist; struct power_supply_battery_ocv_table *cap_table; struct power_supply_resistance_temp_table *resist_table; }; @@ -900,7 +904,9 @@ static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) */ cal_4200mv = (calib_data & 0x1ff) + 6963 - 4096 - 256; data->vol_1000mv_adc = DIV_ROUND_CLOSEST(cal_4200mv * 10, 42); - data->cur_1000ma_adc = data->vol_1000mv_adc * 4; + data->cur_1000ma_adc = + DIV_ROUND_CLOSEST(data->vol_1000mv_adc * 4 * data->calib_resist, + SC27XX_FGU_IDEAL_RESISTANCE); kfree(buf); return 0; @@ -1079,6 +1085,15 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) return ret; } + ret = device_property_read_u32(&pdev->dev, + "sprd,calib-resistance", + &data->calib_resist); + if (ret) { + dev_err(&pdev->dev, + "failed to get fgu calibration resistance\n"); + return ret; + } + data->channel = devm_iio_channel_get(dev, "bat-temp"); if (IS_ERR(data->channel)) { dev_err(dev, "failed to get IIO channel\n");