From patchwork Wed Nov 14 09:07:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 151056 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5441715ljp; Wed, 14 Nov 2018 01:08:00 -0800 (PST) X-Google-Smtp-Source: AJdET5fFGLdJcG/mlF8kP9XUk5Izt+11CIVNI0qB6lNKjfGtNyTXJY7JzacnG77e1TawFDMdEWlk X-Received: by 2002:a17:902:5582:: with SMTP id g2-v6mr1109341pli.56.1542186480390; Wed, 14 Nov 2018 01:08:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542186480; cv=none; d=google.com; s=arc-20160816; b=Tybzj6or/woUb8QF46MHjkPZQ93xsmFrrVC/F7ynNwKfiJXfR6zmT75oOQl3iq/xSD O8C6RNzZWwNg+239mJ17CjA+J009PmONG7smSm8U2XWlL6GtRvMJLHFQmC5qAiDZ9PVe DIKTyOUodNTDZNrMkDEvw9wEE4etz1mzP88cT7NmNK41TKJL18K67Y4AtDfXTGKlC3Xf /RJo5mT1hYtHJ38dd6TaooNp347F5UZvN0Bfl1rveCyt7YmW8Vm3OOCuMN4zahL0KSaX 8811ZEEV6K4QruJcfbwgkWr9v0cGk/gpqZmQgR15rpqBCyeo/T/q4A0KIgFUoWZVHao5 GPxA== 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=pM4xo8EH7+FwIopWG51Di3D79VxY65IdP6hwSYGqO0I=; b=zJojcskbVk7wLgonnxnTmWn8pkQdtvYOnyIDBKZQ5E9Pv6JH+T/9jmnDjLswx4P7C/ TslKx7F/K4OOKYPzOPD0ewDxVDsbBz7XZgKjrskD9K6rYbi9yw/cn1yU4B+d7ZjG9/gr KpS3P+Eiy5s6yUNElPQ/r29MdvvXJyyBjysCgG3iqUhl6pnJ5q7iYm+AjWG66mPheIPr 3itGHeTH4gedPyar3K3lMrBsF1wirk6B1uKClQ0ZT39h9D47AbzIghyrccyFcmhZaUbO BysfcAGlmbrwofBD4aBBNiapkvXYeWDEwmIXE3A+XlggDXFqwqEsa75cUQIZ+8gViEK0 bTYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K7MtDXrg; 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 133-v6si23684172pfb.41.2018.11.14.01.08.00; Wed, 14 Nov 2018 01:08:00 -0800 (PST) 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=K7MtDXrg; 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 S1732234AbeKNTKT (ORCPT + 11 others); Wed, 14 Nov 2018 14:10:19 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34132 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732404AbeKNTKT (ORCPT ); Wed, 14 Nov 2018 14:10:19 -0500 Received: by mail-pf1-f196.google.com with SMTP id h3so1041343pfg.1 for ; Wed, 14 Nov 2018 01:07:57 -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=pM4xo8EH7+FwIopWG51Di3D79VxY65IdP6hwSYGqO0I=; b=K7MtDXrg1XRlZAecffDu2MzNpa1VDLB9fXSRB8vDJw5KyHvioYDjarzVXJlTrF9oqa veU3zPb4ithaS3sbFvKBqwAR/N27mZtvfmRGvpiHCqosUZlcDN8saJrRzX0s3aPWxGpI WE+pIAHTzb+YiCU9tHXnD1U94RjQtAN7ufFEg= 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=pM4xo8EH7+FwIopWG51Di3D79VxY65IdP6hwSYGqO0I=; b=foq56l6cyDubsIis4HXeLERzO0q/u3dMF6H0EJvBAa5TbUv19DdJVHi0TC9s8loxjS rsqcjEqkvOVBukVPr+oE+apycyZ9nhoFF78YtGVj0NTuf1rcRbVcFpLNfhfJnVLlybF0 W6Ol3bATQxSxWnQCz0V8nVT/i/2tBt3lR/0GaK/BlT8oFuzGQ6Q5ojU2dYgpsMmf2j4G mTbxxeVApflXH6kDVx6QQnKB1BuXP7S8moUzI2KeH/P7HYBUV/jz97md5i7l1FZEXFb/ CJSeFiAiDWD6MzdVHVAN1BJ7IyM+2Z/nzoz2UajPJB64gFpDFRNMUbxuE1fTf6lLy56Z 3nVg== X-Gm-Message-State: AGRZ1gIonuZL4yEzalhPTwB8AoSHdbU56VTYynzgmxMBCwCfrMCEN+pE gbEYCaL2AVI3WE1q9Pq74KFijA== X-Received: by 2002:a63:1204:: with SMTP id h4mr988699pgl.51.1542186477038; Wed, 14 Nov 2018 01:07:57 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id 127-v6sm25048814pfx.91.2018.11.14.01.07.53 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Nov 2018 01:07:56 -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 Subject: [PATCH 4/5] power: supply: sc27xx: Add suspend/resume interfaces Date: Wed, 14 Nov 2018 17:07:07 +0800 Message-Id: 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 From: Yuanjiang Yu Add fuel gauge platform suspend and resume interfaces. In suspend state, we should enable the low voltage and coulomb counter threshold interrupts to wake up system to calibrate the battery capacity in lower voltage stage. Signed-off-by: Yuanjiang Yu Signed-off-by: Baolin Wang --- drivers/power/supply/sc27xx_fuel_gauge.c | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) -- 1.7.9.5 diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index 962d0f8..8c52e29 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c @@ -789,6 +789,7 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) data->bat_present = !!ret; mutex_init(&data->lock); data->dev = &pdev->dev; + platform_set_drvdata(pdev, data); fgu_cfg.drv_data = data; fgu_cfg.of_node = np; @@ -846,6 +847,81 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_SLEEP +static int sc27xx_fgu_resume(struct device *dev) +{ + struct sc27xx_fgu_data *data = dev_get_drvdata(dev); + int ret; + + ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, + SC27XX_FGU_LOW_OVERLOAD_INT | + SC27XX_FGU_CLBCNT_DELTA_INT, 0); + if (ret) { + dev_err(data->dev, "failed to disable fgu interrupts\n"); + return ret; + } + + return 0; +} + +static int sc27xx_fgu_suspend(struct device *dev) +{ + struct sc27xx_fgu_data *data = dev_get_drvdata(dev); + int ret, status, ocv; + + ret = sc27xx_fgu_get_status(data, &status); + if (ret) + return ret; + + /* + * If we are charging, then no need to enable the FGU interrupts to + * adjust the battery capacity. + */ + if (status != POWER_SUPPLY_STATUS_NOT_CHARGING) + return 0; + + ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, + SC27XX_FGU_LOW_OVERLOAD_INT, + SC27XX_FGU_LOW_OVERLOAD_INT); + if (ret) { + dev_err(data->dev, "failed to enable low voltage interrupt\n"); + return ret; + } + + ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); + if (ret) + goto disable_int; + + /* + * If current OCV is less than the minimum voltage, we should enable the + * coulomb counter threshold interrupt to notify events to adjust the + * battery capacity. + */ + if (ocv < data->min_volt) { + ret = regmap_update_bits(data->regmap, + data->base + SC27XX_FGU_INT_EN, + SC27XX_FGU_CLBCNT_DELTA_INT, + SC27XX_FGU_CLBCNT_DELTA_INT); + if (ret) { + dev_err(data->dev, + "failed to enable coulomb threshold int\n"); + goto disable_int; + } + } + + return 0; + +disable_int: + regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, + SC27XX_FGU_LOW_OVERLOAD_INT, 0); + return ret; +} +#endif + +static const struct dev_pm_ops sc27xx_fgu_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(sc27xx_fgu_suspend, sc27xx_fgu_resume) +}; + static const struct of_device_id sc27xx_fgu_of_match[] = { { .compatible = "sprd,sc2731-fgu", }, { } @@ -856,6 +932,7 @@ static int sc27xx_fgu_probe(struct platform_device *pdev) .driver = { .name = "sc27xx-fgu", .of_match_table = sc27xx_fgu_of_match, + .pm = &sc27xx_fgu_pm_ops, } };