devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Oskari Lemmela <oskari@lemmela.net>
Cc: Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>, Chen-Yu Tsai <wens@csie.org>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Lee Jones <lee.jones@linaro.org>,
	Quentin Schulz <quentin.schulz@free-electrons.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 5/7] power: supply: add AC power supply driver for AXP813
Date: Sun, 21 Oct 2018 23:16:45 +0200	[thread overview]
Message-ID: <20181021211645.g7yrfudolmrtayb5@earth.universe> (raw)
In-Reply-To: <20181013080848.29894-6-oskari@lemmela.net>

[-- Attachment #1: Type: text/plain, Size: 5824 bytes --]

Hi,

On Sat, Oct 13, 2018 at 11:08:46AM +0300, Oskari Lemmela wrote:
> AXP813 and AXP803 PMICs can control input current and
> minimum voltage.
> 
> Both of these values are configurable.
> 
> Signed-off-by: Oskari Lemmela <oskari@lemmela.net>
> Reviewed-by: Quentin Schulz <quentin.schulz@bootlin.com>
> ---

Looks good to me apart from Chen-Yu Tsai's comments.

-- Sebastian

>  drivers/power/supply/axp20x_ac_power.c | 92 ++++++++++++++++++++++++++
>  include/linux/mfd/axp20x.h             |  1 +
>  2 files changed, 93 insertions(+)
> 
> diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c
> index 0771f951b11f..059a97d6e14c 100644
> --- a/drivers/power/supply/axp20x_ac_power.c
> +++ b/drivers/power/supply/axp20x_ac_power.c
> @@ -27,6 +27,16 @@
>  #define AXP20X_PWR_STATUS_ACIN_PRESENT	BIT(7)
>  #define AXP20X_PWR_STATUS_ACIN_AVAIL	BIT(6)
>  
> +#define AXP813_VHOLD_MASK		GENMASK(5, 3)
> +#define AXP813_VHOLD_UV_TO_BIT(x)	((((x) / 100000) - 40) << 3)
> +#define AXP813_VHOLD_REG_TO_UV(x)	\
> +	(((((x) & AXP813_VHOLD_MASK) >> 3) + 40) * 100000)
> +
> +#define AXP813_CURR_LIMIT_MASK		GENMASK(2, 0)
> +#define AXP813_CURR_LIMIT_UA_TO_BIT(x)	(((x) / 500000) - 3)
> +#define AXP813_CURR_LIMIT_REG_TO_UA(x)	\
> +	((((x) & AXP813_CURR_LIMIT_MASK) + 3) * 500000)
> +
>  #define DRVNAME "axp20x-ac-power-supply"
>  
>  struct axp20x_ac_power {
> @@ -102,6 +112,55 @@ static int axp20x_ac_power_get_property(struct power_supply *psy,
>  
>  		return 0;
>  
> +	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> +		ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg);
> +		if (ret)
> +			return ret;
> +
> +		val->intval = AXP813_VHOLD_REG_TO_UV(reg);
> +
> +		return 0;
> +
> +	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +		ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg);
> +		if (ret)
> +			return ret;
> +
> +		val->intval = AXP813_CURR_LIMIT_REG_TO_UA(reg);
> +
> +		return 0;
> +
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +static int axp813_ac_power_set_property(struct power_supply *psy,
> +					enum power_supply_property psp,
> +					const union power_supply_propval *val)
> +{
> +	struct axp20x_ac_power *power = power_supply_get_drvdata(psy);
> +
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> +		if (val->intval < 4000000 || val->intval > 4700000)
> +			return -EINVAL;
> +
> +		return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL,
> +					  AXP813_VHOLD_MASK,
> +					  AXP813_VHOLD_UV_TO_BIT(val->intval));
> +
> +	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +		if (val->intval < 1500000 || val->intval > 4000000)
> +			return -EINVAL;
> +
> +		return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL,
> +					  AXP813_CURR_LIMIT_MASK,
> +					  AXP813_CURR_LIMIT_UA_TO_BIT
> +					  (val->intval));
> +
>  	default:
>  		return -EINVAL;
>  	}
> @@ -109,6 +168,13 @@ static int axp20x_ac_power_get_property(struct power_supply *psy,
>  	return -EINVAL;
>  }
>  
> +static int axp813_ac_power_prop_writeable(struct power_supply *psy,
> +					  enum power_supply_property psp)
> +{
> +	return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
> +	       psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT;
> +}
> +
>  static enum power_supply_property axp20x_ac_power_properties[] = {
>  	POWER_SUPPLY_PROP_HEALTH,
>  	POWER_SUPPLY_PROP_PRESENT,
> @@ -123,6 +189,14 @@ static enum power_supply_property axp22x_ac_power_properties[] = {
>  	POWER_SUPPLY_PROP_ONLINE,
>  };
>  
> +static enum power_supply_property axp813_ac_power_properties[] = {
> +	POWER_SUPPLY_PROP_HEALTH,
> +	POWER_SUPPLY_PROP_PRESENT,
> +	POWER_SUPPLY_PROP_ONLINE,
> +	POWER_SUPPLY_PROP_VOLTAGE_MIN,
> +	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
> +};
> +
>  static const struct power_supply_desc axp20x_ac_power_desc = {
>  	.name = "axp20x-ac",
>  	.type = POWER_SUPPLY_TYPE_MAINS,
> @@ -139,6 +213,16 @@ static const struct power_supply_desc axp22x_ac_power_desc = {
>  	.get_property = axp20x_ac_power_get_property,
>  };
>  
> +static const struct power_supply_desc axp813_ac_power_desc = {
> +	.name = "axp813-ac",
> +	.type = POWER_SUPPLY_TYPE_MAINS,
> +	.properties = axp813_ac_power_properties,
> +	.num_properties = ARRAY_SIZE(axp813_ac_power_properties),
> +	.property_is_writeable = axp813_ac_power_prop_writeable,
> +	.get_property = axp20x_ac_power_get_property,
> +	.set_property = axp813_ac_power_set_property,
> +};
> +
>  struct axp_data {
>  	const struct power_supply_desc	*power_desc;
>  	bool				acin_adc;
> @@ -154,6 +238,11 @@ static const struct axp_data axp22x_data = {
>  	.acin_adc = false,
>  };
>  
> +static const struct axp_data axp813_data = {
> +	.power_desc = &axp813_ac_power_desc,
> +	.acin_adc = false,
> +};
> +
>  static int axp20x_ac_power_probe(struct platform_device *pdev)
>  {
>  	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
> @@ -234,6 +323,9 @@ static const struct of_device_id axp20x_ac_power_match[] = {
>  	}, {
>  		.compatible = "x-powers,axp221-ac-power-supply",
>  		.data = &axp22x_data,
> +	}, {
> +		.compatible = "x-powers,axp813-ac-power-supply",
> +		.data = &axp813_data,
>  	}, { /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, axp20x_ac_power_match);
> diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
> index 517e60eecbcb..2302b620d238 100644
> --- a/include/linux/mfd/axp20x.h
> +++ b/include/linux/mfd/axp20x.h
> @@ -266,6 +266,7 @@ enum axp20x_variants {
>  #define AXP288_RT_BATT_V_H		0xa0
>  #define AXP288_RT_BATT_V_L		0xa1
>  
> +#define AXP813_ACIN_PATH_CTRL		0x3a
>  #define AXP813_ADC_RATE			0x85
>  
>  /* Fuel Gauge */
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2018-10-21 21:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-13  8:08 [PATCH v4 0/7] AXP8x3 AC and battery power supply support Oskari Lemmela
2018-10-13  8:08 ` [PATCH v4 1/7] dt-bindings: power: supply: axp20x: add AXP813 AC power DT binding Oskari Lemmela
2018-10-16  4:08   ` Chen-Yu Tsai
2018-10-21 21:15   ` Sebastian Reichel
2018-10-13  8:08 ` [PATCH v4 2/7] ARM: dts: axp81x: add AC power supply subnode Oskari Lemmela
2018-10-16  4:08   ` Chen-Yu Tsai
2018-10-13  8:08 ` [PATCH v4 3/7] arm64: dts: allwinner: axp803: add AC and battery power supplies Oskari Lemmela
2018-10-16  4:11   ` Chen-Yu Tsai
2018-10-13  8:08 ` [PATCH v4 4/7] arm64: dts: allwinner: a64: sopine: enable " Oskari Lemmela
2018-10-16  4:14   ` Chen-Yu Tsai
2018-10-13  8:08 ` [PATCH v4 5/7] power: supply: add AC power supply driver for AXP813 Oskari Lemmela
2018-10-17  6:12   ` Chen-Yu Tsai
2018-10-21 21:16   ` Sebastian Reichel [this message]
2018-10-13  8:08 ` [PATCH v4 6/7] mfd: axp20x: Add AC power supply cell " Oskari Lemmela
2018-10-16  4:15   ` Chen-Yu Tsai
2018-10-13  8:08 ` [PATCH v4 7/7] mfd: axp20x: Add supported cells for AXP803 Oskari Lemmela
2018-10-16  4:17   ` Chen-Yu Tsai
2018-10-18  6:04 ` [PATCH v4 0/7] AXP8x3 AC and battery power supply support Vasily Khoruzhick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181021211645.g7yrfudolmrtayb5@earth.universe \
    --to=sre@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maxime.ripard@bootlin.com \
    --cc=oskari@lemmela.net \
    --cc=quentin.schulz@free-electrons.com \
    --cc=robh+dt@kernel.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).