From patchwork Mon Jan 15 10:33:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 124501 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp624687lje; Mon, 15 Jan 2018 02:38:05 -0800 (PST) X-Google-Smtp-Source: ACJfBouNPteX/87U0WecJ//5tqOcMRS+pHwiNyIYL8tu8Mzp3eUA4p+p08DVO6e0POyXIkC/AlUH X-Received: by 10.98.74.133 with SMTP id c5mr19341852pfj.188.1516012685346; Mon, 15 Jan 2018 02:38:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516012685; cv=none; d=google.com; s=arc-20160816; b=grmQPPduPmHqf0eGSKmhYPOQUIC00SGMcILZ9yyMfc/8P6UY2lJ5SBPT6YVoP5/8TJ qoNeFBxJ6nPnNWcqYne9i3nCm+Pu5NBJT92IYGOSE8A+azHI5dCRgx1ClZW07DjW7UhX Z4STSz8Wq5XwM3ok5iz4LdfgyZzQHUvdSMLe5reHNicqnMArc+4ieUOXznyNjCSlVspG DlFfiVHa8lpbaB8EK4k6bEaokWTyGdUa6vEPEBPVzHLbXA4LNSavQhTu7/McCdQx5mgC pGrS+LJHKRfXYWoe8VVPeAVyK+qn1lPQrWguG3Y/MqqJ3nAAlK0ZMMJszNun94bOsL2W lDLg== 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 :arc-authentication-results; bh=xs0eQbGktTuM4vW6p+zBFFlqwVfPxj8JkGBhj43xH1c=; b=Eg/VeUKCQP4P9IExNwnwCyIFniPYEg3aY9zq/Gm4hMgfc/KzyyjcdKTNz5kl+vJ3Ul oHzhXlLEoxqkBI8u1xATE6nAxikBU7oKocALZ+1+vruNwNT2AHI/OUJtkb4QbtVMZB8R XU/1TiWg/IiqfG06Wi8Zb+639wo1WEI9yeBeel+7ZxX/6gSsKpbqZAKkgRccEIn9Lutu B8UePupdw7G0lL1v22yl0GwBrm8UnHThHoFynkw7WOCSyw0A2T3QTIalsnoYskyYGqPi 5qDS2Y05+X8AgrXzqIxk4MVig3sS+FYpCh+QlxSF45qeiswkfh8TFG6yv5i6e4XDnudv n/Mw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si13932899plz.285.2018.01.15.02.38.05; Mon, 15 Jan 2018 02:38:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754698AbeAOKiC (ORCPT + 11 others); Mon, 15 Jan 2018 05:38:02 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:43909 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755347AbeAOKfN (ORCPT ); Mon, 15 Jan 2018 05:35:13 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 96DAB20888; Mon, 15 Jan 2018 11:35:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 261F720889; Mon, 15 Jan 2018 11:34:53 +0100 (CET) From: Quentin Schulz To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, robh+dt@kernel.org, mark.rutland@arm.com, wens@csie.org, sre@kernel.org, linux@armlinux.org.uk, maxime.ripard@free-electrons.com, lee.jones@linaro.org Cc: linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@free-electrons.com, linux-sunxi@googlegroups.com, julian.calaby@gmail.com, Quentin Schulz Subject: [PATCH v3 12/16] power: supply: axp20x_battery: add support for AXP813 Date: Mon, 15 Jan 2018 11:33:46 +0100 Message-Id: <42b2e555083abbab43e48362175dc9c2eeeedf3c.1516012352.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.14.1 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 The X-Powers AXP813 PMIC has got some slight differences from AXP20X/AXP22X PMICs: - the maximum voltage supplied by the PMIC is 4.35 instead of 4.36/4.24 for AXP20X/AXP22X, - the constant charge current formula is different, It also has a bit to tell whether the battery percentage returned by the PMIC is valid. Signed-off-by: Quentin Schulz --- drivers/power/supply/axp20x_battery.c | 42 ++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+) -- git-series 0.9.1 diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index d73c78f..e75fa90 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -49,6 +49,8 @@ #define AXP22X_CHRG_CTRL1_TGT_4_22V (1 << 5) #define AXP22X_CHRG_CTRL1_TGT_4_24V (3 << 5) +#define AXP813_CHRG_CTRL1_TGT_4_35V (3 << 5) + #define AXP20X_CHRG_CTRL1_TGT_CURR GENMASK(3, 0) #define AXP20X_V_OFF_MASK GENMASK(2, 0) @@ -133,6 +135,35 @@ static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt, return 0; } +static int axp813_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt, + int *val) +{ + int ret, reg; + + ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, ®); + if (ret) + return ret; + + switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) { + case AXP20X_CHRG_CTRL1_TGT_4_1V: + *val = 4100000; + break; + case AXP20X_CHRG_CTRL1_TGT_4_15V: + *val = 4150000; + break; + case AXP20X_CHRG_CTRL1_TGT_4_2V: + *val = 4200000; + break; + case AXP813_CHRG_CTRL1_TGT_4_35V: + *val = 4350000; + break; + default: + return -EINVAL; + } + + return 0; +} + static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp, int *val) { @@ -491,6 +522,14 @@ struct axp_data axp221_data = { .set_max_voltage = axp22x_battery_set_max_voltage, }; +struct axp_data axp813_data = { + .ccc_scale = 200000, + .ccc_offset = 200000, + .has_fg_valid = true, + .get_max_voltage = axp813_battery_get_max_voltage, + .set_max_voltage = axp20x_battery_set_max_voltage, +}; + static const struct of_device_id axp20x_battery_ps_id[] = { { .compatible = "x-powers,axp209-battery-power-supply", @@ -498,6 +537,9 @@ static const struct of_device_id axp20x_battery_ps_id[] = { }, { .compatible = "x-powers,axp221-battery-power-supply", .data = (void *)&axp221_data, + }, { + .compatible = "x-powers,axp813-battery-power-supply", + .data = (void *)&axp813_data, }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, axp20x_battery_ps_id);