Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4586021imu; Tue, 15 Jan 2019 02:35:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN44KqVetLHhbpUfDJU3n+Z6QgHai/1XHLbYjVBz51udXCJ80D9L1YGsknyR0oQnKUCmMHsL X-Received: by 2002:a62:5d0c:: with SMTP id r12mr3442668pfb.0.1547548501097; Tue, 15 Jan 2019 02:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547548501; cv=none; d=google.com; s=arc-20160816; b=McmtJS7+Sphjh7z8oI3FHUoWZZzTPKpd6BebvMxw123oPPPNZYhRJWjMboXq69Qzzy 61jZFyP/P58u1p1zz91Abik0ZAflOr84dFQwDeSHn5+KE5Tqb2ZwRy9wdaQ2UliHu20g I2Tl6XtKn+fEfkzoBN+k49tgcORDaRCVulZwNKeJCpvFb393VKZfMoEzkAxHW+isodqm 8iLxNB5tBwA1xy9I3TBphFITyBMeMBbm68oGLWCJd4S/7BburB3PN/PBca7vOALVmWso o4eatdcWnuFlwEwxZ1EJpi2UiRM1NK9YBRLn6N/Q78BuCvWxKvwIw15OQoJ/9B2XOSjk 3UQQ== 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=gfsjcoK5+n5u8rdyVSCIiowp3BqnWBKCmYbY+r0pFqo=; b=vjKzlamStvsfqpmBH+koADjPSn2C8MHrRO31FCBfyHH9QfBrIPUSf/CMczjiYmX/cB cV4d5m7hKpn1dusF+uQiLvVpBErr8sy4mURem1dXf0/S9m4kLpwsrA6k6UhBt36iCC8k 3GDvJb67EJCGInkabuFziGWFSKkaprxLaZ0VBVXZWtvph8CsReqILKqBbrRTP8cstKrh STy9x5pg6R34zhugJh5b5Abrw1tVElZxU8jTDeqnKtVwm+m7qh++OeU4smAYIpwNz+Du BxxPIkyTqK385g/oqyWWG1J7+/fPMdu9cnrCuu3EEPWobeExYFkkXZr9GmiuPYcMhI0N kYXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Njalyeho; 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 j191si2817267pgd.31.2019.01.15.02.34.45; Tue, 15 Jan 2019 02:35:01 -0800 (PST) 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=Njalyeho; 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 S1728963AbfAOKde (ORCPT + 99 others); Tue, 15 Jan 2019 05:33:34 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:46299 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbfAOKdc (ORCPT ); Tue, 15 Jan 2019 05:33:32 -0500 Received: by mail-pl1-f195.google.com with SMTP id t13so1080275ply.13 for ; Tue, 15 Jan 2019 02:33:32 -0800 (PST) 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=gfsjcoK5+n5u8rdyVSCIiowp3BqnWBKCmYbY+r0pFqo=; b=NjalyehonmSD9f1XkR4NT52PJKvEiK+haOiYekDryzxm6wrHaHgYPGssUgy5RnbI+c 7E2jxPO/HlDbaNi8KYCw6/fEqL8aI7xmSFTo2CuSv0zZEg/RnPuiTfhPB05xN2TzxVwI 2+8U/2UEm/wbrBLy/cAYfcY9EC/97mPdi/ibU= 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=gfsjcoK5+n5u8rdyVSCIiowp3BqnWBKCmYbY+r0pFqo=; b=Y2FqEW3hCZcvxJX9tXUCLu1Svya5dgR0o/4PGseOTbNB5r45LXRUHa/SYpYPQ5Fd0G UkNfkGp9Ti1wV7Wn5AL3zATqgIqR3IAyFVtB6uSRTAyGRdHTtG2OtuoA+jlD3Mu+BUWB P8vNWA0sFduln/Wm4NRPpVfYMXxjPISz0V1/azYJI2Nt7UGAlL3h0rMpwUeRn3b4+/KJ pjI2uOZzatD0jyNeItXHffGQOq8NtS+0clpzO2pM/jEzPUKa6yD3b2xon8FpOwhSynlU H5qzXk/5iTqIwzB03vRx68Rwah16fpNtQgyYwrVRUw+BdqhPxtrnzWSI6ztKuIwj3jv8 lqzg== X-Gm-Message-State: AJcUukfrDvxVKSiAUxv4wlKWqgDba2Fp9gkXlZxpohz5q7I0hJeOspAb 1OpUX+/BRhrEuCsydz8Vh3z0gQ== X-Received: by 2002:a17:902:bd46:: with SMTP id b6mr3323046plx.231.1547548411565; Tue, 15 Jan 2019 02:33:31 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id d13sm5073957pfd.58.2019.01.15.02.33.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 02:33:30 -0800 (PST) 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, broonie@kernel.org, zhang.lyra@gmail.com, orsonzhai@gmail.com Subject: [PATCH 4/4] power: supply: sc27xx: Fix capacity saving function Date: Tue, 15 Jan 2019 18:32:37 +0800 Message-Id: <30327406bfd6aa0559e48b766c87c6845fe059af.1547544142.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> In-Reply-To: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> References: <76a12fe5d0cc670266100b0587b047714c9a8a83.1547544142.git.baolin.wang@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yuanjiang Yu We found sometimes we can not get the saving capacity to initialize the battery capacity, the reason is the user area registers are put on power always-on region, so we need delay some time to wait until values are updated successfully. Moreover we also should clear the USER_AREA_CLEAR register after setting the USER_AREA_SET register, otherwise we can not save the values in the USER_AREA_SET register. Signed-off-by: Yuanjiang Yu Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 64 +++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index ea1349f..24895cc 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -171,10 +171,37 @@ static int sc27xx_fgu_save_boot_mode(struct sc27xx_fgu_data *data, if (ret) return ret; + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + ret = regmap_update_bits(data->regmap, + data->base + SC27XX_FGU_USER_AREA_SET, + SC27XX_FGU_MODE_AREA_MASK, + boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); + if (ret) + return ret; + + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + /* + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to + * make the user area data available, otherwise we can not save the user + * area data. + */ return regmap_update_bits(data->regmap, - data->base + SC27XX_FGU_USER_AREA_SET, - SC27XX_FGU_MODE_AREA_MASK, - boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); + data->base + SC27XX_FGU_USER_AREA_CLEAR, + SC27XX_FGU_MODE_AREA_MASK, 0); } static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) @@ -188,9 +215,36 @@ static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) if (ret) return ret; + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + ret = regmap_update_bits(data->regmap, + data->base + SC27XX_FGU_USER_AREA_SET, + SC27XX_FGU_CAP_AREA_MASK, cap); + if (ret) + return ret; + + /* + * Since the user area registers are put on power always-on region, + * then these registers changing time will be a little long. Thus + * here we should delay 200us to wait until values are updated + * successfully according to the datasheet. + */ + udelay(200); + + /* + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to + * make the user area data available, otherwise we can not save the user + * area data. + */ return regmap_update_bits(data->regmap, - data->base + SC27XX_FGU_USER_AREA_SET, - SC27XX_FGU_CAP_AREA_MASK, cap); + data->base + SC27XX_FGU_USER_AREA_CLEAR, + SC27XX_FGU_CAP_AREA_MASK, 0); } static int sc27xx_fgu_read_last_cap(struct sc27xx_fgu_data *data, int *cap) -- 1.7.9.5