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: 10682225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF3D0139B for ; Wed, 14 Nov 2018 09:08:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C28472AF3D for ; Wed, 14 Nov 2018 09:08:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6B4D2AF46; Wed, 14 Nov 2018 09:08:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EE492AF3D for ; Wed, 14 Nov 2018 09:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732234AbeKNTKT (ORCPT ); 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-Google-Smtp-Source: AJdET5cJNV7IPnDyhU28H6D7jCTdXdaSAi42OMoFm4jW4HpXXYxzDcchu0+/4c+LAERMwEcW2NJXVA== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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, } };