Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5908185ybi; Wed, 31 Jul 2019 05:17:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUKeOKYKYpLPnyUwygdl/tsw2jiV0NpuFaPiBC8INf/CYK1RrqgdUeM43g24uHnv8h48XL X-Received: by 2002:a17:90a:5806:: with SMTP id h6mr2639014pji.126.1564575428587; Wed, 31 Jul 2019 05:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564575428; cv=none; d=google.com; s=arc-20160816; b=B5lbRm41PQPeRZzW+y6AAj4Ey6wceoi2wrmLmI4szaf8yBn1LZ7kyXZhpw2kogMqbm o/f/ZHrl8MV1MHW3oDYHpIC7qchw172QrBQxJmN5JmsO/xk05Vnu35SXSrEotv0Djb1u IBX7PM+ETfoEr/io0spJmB0YmQnhpFz+j+1TYdASCnRLQfSWgrIDYuLI97D+MkGOYc+L 6HNDyDa8DFctulvThP1pwONbCEno9uniRWg9mPsGHB8vX5ovCrIPxE/9lQvuUDr/p1bc bck8jOgeD3BSE3ICfPDUiGHqw1oh3grd4uVIkcsOGEflInD+sJRRfDl4e078FZXIQa9Q L/zw== 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=XF5mZ6TSVo4eSNdQwLP31itinD3L/9CCtkqFjn0djlU=; b=FgsHnNHtTNE4vr4SeKYzWLH67w+iFsMRFktY5vDOiCYlAzkPjAHK9vd8KRQ3uBVUXk sR+43yBuzesAe4yE8foSUW33TP0KAhoqzRC0ybzw7UozLuHSEzQXXLdombGER+PGKGUt pglbxaP1KoLlBsK6+Us3UBdBkOKbnaT6iziHQCfcEwl3q5eEPKwhW6IxDEJCDd18qCRQ b8XYdjGtBZtaoLzz6GGCyf67vXd+4IKCQGwv1Ls/P7Rr6obDRbnzjv5xxCZlBGBRFfst zJzkzV0twTi1x0BApo7EiiXZmAKef/CrB6OCfNn2mXptDPFpIsi9CSRJQkLYAbXJcux/ AgiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UHCfglol; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 d8si35193187pfr.182.2019.07.31.05.16.52; Wed, 31 Jul 2019 05:17:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=UHCfglol; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1729097AbfGaKBL (ORCPT + 99 others); Wed, 31 Jul 2019 06:01:11 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37793 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387723AbfGaKBG (ORCPT ); Wed, 31 Jul 2019 06:01:06 -0400 Received: by mail-pl1-f195.google.com with SMTP id b3so30290771plr.4 for ; Wed, 31 Jul 2019 03:01:05 -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=XF5mZ6TSVo4eSNdQwLP31itinD3L/9CCtkqFjn0djlU=; b=UHCfglolFc+DiKNqu28PP7eW3FZEIuVvD/ZAL0ARBydSmw5J1AvOi7RqECGvzy6OyG JjznumgXnMlrgA+kEdFEsntSef0+YnGvMTLpX+q4IecNPm57QuzzIsAAWnE3sBhklwoQ aYzQ3bw8+p+ZPNrOrSDamq+nkI+kJfTvuVAL4kdLH6lmo3FnsURjQaFVeGvWtuV/dx7M Oesx0zR11jotI5yl8mxyz374bO4ddYQKkHky0Sx447WMBTRl/sKaHqp16dEOPi1Tzgev 2vBnBHlc0ZsG6mTdF49WwAunGzn3pS9UeqSoQFADQK3GU6s/SIfyzE1ni8WGsDTjD2ek FFBg== 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=XF5mZ6TSVo4eSNdQwLP31itinD3L/9CCtkqFjn0djlU=; b=SqgLMFaVoEKXq8CGcvdq9Qqvs05KeWz/ye3Bs4anGpy583Zh0oWieaaSoeDv7oyLSa XYFMoaAYSBRDme6mAduO6RPEP1en0y8lhqMXrKGD53c2dLDrwdzpWWCEf67cW2LYfJgB NU3X2MDJTvuozZlSHx+H11CNrjb+u5GJH5ry5AbR1jtRW174hRxdMesL7JVSy9eE925i sWmknuUVrkm/Bk5XXOpRnxujwm6MbbphtrpSBrPEPh3uLL8Yjx9WnO8J+etY25Ptq1s9 B93GZm5xFRU/vPLSGd/qccdtJYio4eFwzYlwwkg9uboyHU6STU/0YVuCIAiAIT4AGuWQ F0Ww== X-Gm-Message-State: APjAAAVDfkK/l4DUPtA1yrz1SxNRb+ksAo6Dx+HstGIH09HUmlLcwAJx 5M2Nyn9k6Ig0FcRp+OAzlCCcgA== X-Received: by 2002:a17:902:a514:: with SMTP id s20mr113281631plq.162.1564567265611; Wed, 31 Jul 2019 03:01:05 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id m6sm68611352pfb.151.2019.07.31.03.01.03 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 03:01:05 -0700 (PDT) From: Baolin Wang To: sre@kernel.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, yuanjiang.yu@unisoc.com, baolin.wang@linaro.org, vincent.guittot@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] power: supply: sc27xx: Add POWER_SUPPLY_PROP_CALIBRATE attribute Date: Wed, 31 Jul 2019 18:00:28 +0800 Message-Id: <554dd7e2ef4f3c5247322d8b185607748144b1e6.1564566425.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yuanjiang Yu Add the 'POWER_SUPPLY_PROP_CALIBRATE' attribute to allow chareger manager to calibrate the battery capacity. Signed-off-by: Yuanjiang Yu Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index fa85f40..6363c48 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -111,6 +111,7 @@ struct sc27xx_fgu_data { 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, int int_mode); +static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap); static const char * const sc27xx_charger_supply_name[] = { "sc2731_charger", @@ -610,17 +611,25 @@ static int sc27xx_fgu_set_property(struct power_supply *psy, struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy); int ret; - if (psp != POWER_SUPPLY_PROP_CAPACITY) - return -EINVAL; - mutex_lock(&data->lock); - ret = sc27xx_fgu_save_last_cap(data, val->intval); + switch (psp) { + case POWER_SUPPLY_PROP_CAPACITY: + ret = sc27xx_fgu_save_last_cap(data, val->intval); + if (ret < 0) + dev_err(data->dev, "failed to save battery capacity\n"); + break; - mutex_unlock(&data->lock); + case POWER_SUPPLY_PROP_CALIBRATE: + sc27xx_fgu_adjust_cap(data, val->intval); + ret = 0; + break; - if (ret < 0) - dev_err(data->dev, "failed to save battery capacity\n"); + default: + ret = -EINVAL; + } + + mutex_unlock(&data->lock); return ret; } @@ -635,7 +644,8 @@ static void sc27xx_fgu_external_power_changed(struct power_supply *psy) static int sc27xx_fgu_property_is_writeable(struct power_supply *psy, enum power_supply_property psp) { - return psp == POWER_SUPPLY_PROP_CAPACITY; + return psp == POWER_SUPPLY_PROP_CAPACITY || + psp == POWER_SUPPLY_PROP_CALIBRATE; } static enum power_supply_property sc27xx_fgu_props[] = { @@ -651,6 +661,7 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, + POWER_SUPPLY_PROP_CALIBRATE, }; static const struct power_supply_desc sc27xx_fgu_desc = { -- 1.7.9.5