linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] set battery info on AXP20X and AXP22X from DT
@ 2017-05-11 13:42 Quentin Schulz
  2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Quentin Schulz @ 2017-05-11 13:42 UTC (permalink / raw)
  To: sre, robh+dt, mark.rutland, wens
  Cc: Quentin Schulz, linux-pm, devicetree, linux-kernel, liam,
	thomas.petazzoni, linux-sunxi

X-Powers AXP20X and AXP22X are capable of setting battery constant
charge current to limit the current supplied to the battery. The battery
driver already offers the ability to modify the constant charge current
via sysfs but the driver will probe with the default value of 1500mA.

They are also able to tell the system when to shut down due to the
supplied power being too low. This patch series adds the ability to set
this power threshold from the battery DT node.

The constant charge current is critical for batteries as if it is higher
than the supported constant charge current, it might
severly/irreversibly damages or kills the battery.

This patch series aims at offering the ability to set the maximal
supported constant charge current from Device Tree which will be used at
driver probing to set the default constant charge current, thus making
sure we stay out of the unsupported range as little time as possible
(the default constant current charge will still be 1500mA from powering
up the board to the driver probing unless the bootloader takes care of
it beforehand).

We still offer the user the ability to change the maximal constant
charge current from sysfs for those who would like to switch the battery
attached to their board, so they can set an appropriate constant current
charge and take advantage of higher constant current charge.

Quentin

Quentin Schulz (4):
  power: supply: axp20x_battery: add support for DT battery
  dt-bindings: power: battery: add constant-charge-current-max-microamp
    property
  power: supply: power_supply_core: add constant-charge-current optional
    property
  power: supply: axp20x_battery: add DT support for battery max constant
    charge current

 .../devicetree/bindings/power/supply/battery.txt   |  2 +
 drivers/power/supply/axp20x_battery.c              | 88 ++++++++++++++++++++--
 drivers/power/supply/power_supply_core.c           |  3 +
 include/linux/power_supply.h                       |  1 +
 4 files changed, 86 insertions(+), 8 deletions(-)

-- 
2.11.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery
  2017-05-11 13:42 [PATCH 0/4] set battery info on AXP20X and AXP22X from DT Quentin Schulz
@ 2017-05-11 13:42 ` Quentin Schulz
  2017-05-16  5:18   ` Chen-Yu Tsai
  2017-06-08 15:58   ` Sebastian Reichel
  2017-05-11 13:42 ` [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property Quentin Schulz
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Quentin Schulz @ 2017-05-11 13:42 UTC (permalink / raw)
  To: sre, robh+dt, mark.rutland, wens
  Cc: Quentin Schulz, linux-pm, devicetree, linux-kernel, liam,
	thomas.petazzoni, linux-sunxi

This adds support in X-Powers AXP20X and AXP22X battery driver for a
fixed battery in DT.

It will take the minimum supported voltage by the battery as defined in
the battery DT node and set the V_OFF register to this value, telling
the system to shut down if the supplied power is below this value.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
---
 drivers/power/supply/axp20x_battery.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index 5d29b2eab8fc..66f530541735 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -433,6 +433,7 @@ static int axp20x_power_probe(struct platform_device *pdev)
 {
 	struct axp20x_batt_ps *axp20x_batt;
 	struct power_supply_config psy_cfg = {};
+	struct power_supply_battery_info info;
 
 	if (!of_device_is_available(pdev->dev.of_node))
 		return -ENODEV;
@@ -484,6 +485,15 @@ static int axp20x_power_probe(struct platform_device *pdev)
 		return PTR_ERR(axp20x_batt->batt);
 	}
 
+	if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
+		int vmin = info.voltage_min_design_uv;
+
+		if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
+							      vmin))
+			dev_err(&pdev->dev,
+				"couldn't set voltage_min_design\n");
+	}
+
 	return 0;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property
  2017-05-11 13:42 [PATCH 0/4] set battery info on AXP20X and AXP22X from DT Quentin Schulz
  2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
@ 2017-05-11 13:42 ` Quentin Schulz
  2017-05-15 20:14   ` Rob Herring
  2017-05-11 13:42 ` [PATCH 3/4] power: supply: power_supply_core: add constant-charge-current optional property Quentin Schulz
  2017-05-11 13:42 ` [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current Quentin Schulz
  3 siblings, 1 reply; 10+ messages in thread
From: Quentin Schulz @ 2017-05-11 13:42 UTC (permalink / raw)
  To: sre, robh+dt, mark.rutland, wens
  Cc: Quentin Schulz, linux-pm, devicetree, linux-kernel, liam,
	thomas.petazzoni, linux-sunxi

This adds the constant-charge-current-max-microamp property to the list
of optional properties of the battery.

The constant charge current is critical for batteries as they can't
handle all charge currents.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
---
 Documentation/devicetree/bindings/power/supply/battery.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/power/supply/battery.txt b/Documentation/devicetree/bindings/power/supply/battery.txt
index 63a7028d1434..12c1abc93a90 100644
--- a/Documentation/devicetree/bindings/power/supply/battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/battery.txt
@@ -12,6 +12,7 @@ Optional Properties:
  - voltage-min-design-microvolt: drained battery voltage
  - energy-full-design-microwatt-hours: battery design energy
  - charge-full-design-microamp-hours: battery design capacity
+ - constant-charge-current-max-microamp: battery maximum constant charge current
 
 Batteries must be referenced by chargers and/or fuel-gauges
 using a phandle. The phandle's property should be named
@@ -24,6 +25,7 @@ Example:
 		voltage-min-design-microvolt = <3200000>;
 		energy-full-design-microwatt-hours = <5290000>;
 		charge-full-design-microamp-hours = <1430000>;
+		constant-charge-current-max-microamp = <300000>;
 	};
 
 	charger: charger@11 {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] power: supply: power_supply_core: add constant-charge-current optional property
  2017-05-11 13:42 [PATCH 0/4] set battery info on AXP20X and AXP22X from DT Quentin Schulz
  2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
  2017-05-11 13:42 ` [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property Quentin Schulz
@ 2017-05-11 13:42 ` Quentin Schulz
  2017-05-11 13:42 ` [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current Quentin Schulz
  3 siblings, 0 replies; 10+ messages in thread
From: Quentin Schulz @ 2017-05-11 13:42 UTC (permalink / raw)
  To: sre, robh+dt, mark.rutland, wens
  Cc: Quentin Schulz, linux-pm, devicetree, linux-kernel, liam,
	thomas.petazzoni, linux-sunxi

This adds the constant-charge-current property to the list of optional
properties for the battery.

The constant charge current is critical for batteries as they can't
handle all charge currents.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
---
 drivers/power/supply/power_supply_core.c | 3 +++
 include/linux/power_supply.h             | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 5019bdee0f0b..23887739c95c 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -508,6 +508,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
 	info->energy_full_design_uwh = -EINVAL;
 	info->charge_full_design_uah = -EINVAL;
 	info->voltage_min_design_uv  = -EINVAL;
+	info->constant_charge_current_max_ua  = -EINVAL;
 
 	if (!psy->of_node) {
 		dev_warn(&psy->dev, "%s currently only supports devicetree\n",
@@ -537,6 +538,8 @@ int power_supply_get_battery_info(struct power_supply *psy,
 			     &info->charge_full_design_uah);
 	of_property_read_u32(battery_np, "voltage-min-design-microvolt",
 			     &info->voltage_min_design_uv);
+	of_property_read_u32(battery_np, "constant-charge-current-max-microamp",
+			     &info->constant_charge_current_max_ua);
 
 	return 0;
 }
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index e84f1d31d987..6f9c28187caf 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -301,6 +301,7 @@ struct power_supply_battery_info {
 	int energy_full_design_uwh;	/* microWatt-hours */
 	int charge_full_design_uah;	/* microAmp-hours */
 	int voltage_min_design_uv;	/* microVolts */
+	int constant_charge_current_max_ua;		/* microAmps */
 };
 
 extern struct atomic_notifier_head power_supply_notifier;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current
  2017-05-11 13:42 [PATCH 0/4] set battery info on AXP20X and AXP22X from DT Quentin Schulz
                   ` (2 preceding siblings ...)
  2017-05-11 13:42 ` [PATCH 3/4] power: supply: power_supply_core: add constant-charge-current optional property Quentin Schulz
@ 2017-05-11 13:42 ` Quentin Schulz
  2017-06-08 15:58   ` Sebastian Reichel
  3 siblings, 1 reply; 10+ messages in thread
From: Quentin Schulz @ 2017-05-11 13:42 UTC (permalink / raw)
  To: sre, robh+dt, mark.rutland, wens
  Cc: Quentin Schulz, linux-pm, devicetree, linux-kernel, liam,
	thomas.petazzoni, linux-sunxi

This adds the ability to set the maximum constant charge current,
supported by the battery, delivered by this battery power supply to the
battery.

The maximum constant charge current set in DT will also set the default
constant charge current supplied by this supply.

The actual user can modify the constant charge current within the range
of 0 to maximum constant charge current via sysfs.
The user can also modify the maximum constant charge current to widen
the range of possible constant charge current. While this seems quite
risky, a message is printed on the console to warn the user this might
damage the battery. The reason for letting the user change the maximum
constant charge current is for letting users change the battery and
thus, let them adjust the maximum constant charge current according to
what the battery can support.

Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
---
 drivers/power/supply/axp20x_battery.c | 78 +++++++++++++++++++++++++++++++----
 1 file changed, 70 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index 66f530541735..7494f0f0eadb 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -60,6 +60,8 @@ struct axp20x_batt_ps {
 	struct iio_channel *batt_chrg_i;
 	struct iio_channel *batt_dischrg_i;
 	struct iio_channel *batt_v;
+	/* Maximum constant charge current */
+	unsigned int max_ccc;
 	u8 axp_id;
 };
 
@@ -129,6 +131,14 @@ static void raw_to_constant_charge_current(struct axp20x_batt_ps *axp, int *val)
 		*val = *val * 150000 + 300000;
 }
 
+static void constant_charge_current_to_raw(struct axp20x_batt_ps *axp, int *val)
+{
+	if (axp->axp_id == AXP209_ID)
+		*val = (*val - 300000) / 100000;
+	else
+		*val = (*val - 300000) / 150000;
+}
+
 static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp,
 					      int *val)
 {
@@ -221,9 +231,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
-		val->intval = AXP20X_CHRG_CTRL1_TGT_CURR;
-		raw_to_constant_charge_current(axp20x_batt, &val->intval);
-
+		val->intval = axp20x_batt->max_ccc;
 		break;
 
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
@@ -340,10 +348,10 @@ static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
 static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
 					      int charge_current)
 {
-	if (axp_batt->axp_id == AXP209_ID)
-		charge_current = (charge_current - 300000) / 100000;
-	else
-		charge_current = (charge_current - 300000) / 150000;
+	if (charge_current > axp_batt->max_ccc)
+		return -EINVAL;
+
+	constant_charge_current_to_raw(axp_batt, &charge_current);
 
 	if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
 		return -EINVAL;
@@ -352,6 +360,36 @@ static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
 				  AXP20X_CHRG_CTRL1_TGT_CURR, charge_current);
 }
 
+static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp,
+						  int charge_current)
+{
+	bool lower_max = false;
+
+	constant_charge_current_to_raw(axp, &charge_current);
+
+	if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
+		return -EINVAL;
+
+	raw_to_constant_charge_current(axp, &charge_current);
+
+	if (charge_current > axp->max_ccc)
+		dev_warn(axp->dev,
+			 "Setting max constant charge current higher than previously defined. Note that increasing the constant charge current may damage your battery.\n");
+	else
+		lower_max = true;
+
+	axp->max_ccc = charge_current;
+
+	if (lower_max) {
+		int current_cc;
+
+		axp20x_get_constant_charge_current(axp, &current_cc);
+		if (current_cc > charge_current)
+			axp20x_set_constant_charge_current(axp, charge_current);
+	}
+
+	return 0;
+}
 static int axp20x_set_voltage_min_design(struct axp20x_batt_ps *axp_batt,
 					 int min_voltage)
 {
@@ -380,6 +418,9 @@ static int axp20x_battery_set_prop(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
 		return axp20x_set_constant_charge_current(axp20x_batt,
 							  val->intval);
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
+		return axp20x_set_max_constant_charge_current(axp20x_batt,
+							      val->intval);
 
 	default:
 		return -EINVAL;
@@ -405,7 +446,8 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy,
 {
 	return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
 	       psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ||
-	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT;
+	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
+	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
 }
 
 static const struct power_supply_desc axp20x_batt_ps_desc = {
@@ -487,13 +529,33 @@ static int axp20x_power_probe(struct platform_device *pdev)
 
 	if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
 		int vmin = info.voltage_min_design_uv;
+		int ccc = info.constant_charge_current_max_ua;
 
 		if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
 							      vmin))
 			dev_err(&pdev->dev,
 				"couldn't set voltage_min_design\n");
+
+		/* Set max to unverified value to be able to set CCC */
+		axp20x_batt->max_ccc = ccc;
+
+		if (ccc <= 0 || axp20x_set_constant_charge_current(axp20x_batt,
+								   ccc)) {
+			dev_err(&pdev->dev,
+				"couldn't set constant charge current from DT: fallback to minimum value\n");
+			ccc = 300000;
+			axp20x_batt->max_ccc = ccc;
+			axp20x_set_constant_charge_current(axp20x_batt, ccc);
+		}
 	}
 
+	/*
+	 * Update max CCC to a valid value if battery info is present or set it
+	 * to current register value by default.
+	 */
+	axp20x_get_constant_charge_current(axp20x_batt,
+					   &axp20x_batt->max_ccc);
+
 	return 0;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property
  2017-05-11 13:42 ` [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property Quentin Schulz
@ 2017-05-15 20:14   ` Rob Herring
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring @ 2017-05-15 20:14 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: sre, mark.rutland, wens, linux-pm, devicetree, linux-kernel,
	liam, thomas.petazzoni, linux-sunxi

On Thu, May 11, 2017 at 03:42:18PM +0200, Quentin Schulz wrote:
> This adds the constant-charge-current-max-microamp property to the list
> of optional properties of the battery.
> 
> The constant charge current is critical for batteries as they can't
> handle all charge currents.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> ---
>  Documentation/devicetree/bindings/power/supply/battery.txt | 2 ++
>  1 file changed, 2 insertions(+)

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery
  2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
@ 2017-05-16  5:18   ` Chen-Yu Tsai
  2017-05-16  6:33     ` Quentin Schulz
  2017-06-08 15:58   ` Sebastian Reichel
  1 sibling, 1 reply; 10+ messages in thread
From: Chen-Yu Tsai @ 2017-05-16  5:18 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: Sebastian Reichel, Rob Herring, Mark Rutland, Chen-Yu Tsai,
	open list:THERMAL, devicetree, linux-kernel, Liam Breck,
	Thomas Petazzoni, linux-sunxi

On Thu, May 11, 2017 at 9:42 PM, Quentin Schulz
<quentin.schulz@free-electrons.com> wrote:
> This adds support in X-Powers AXP20X and AXP22X battery driver for a
> fixed battery in DT.
>
> It will take the minimum supported voltage by the battery as defined in
> the battery DT node and set the V_OFF register to this value, telling
> the system to shut down if the supplied power is below this value.
>
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
> ---
>  drivers/power/supply/axp20x_battery.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index 5d29b2eab8fc..66f530541735 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
> @@ -433,6 +433,7 @@ static int axp20x_power_probe(struct platform_device *pdev)
>  {
>         struct axp20x_batt_ps *axp20x_batt;
>         struct power_supply_config psy_cfg = {};
> +       struct power_supply_battery_info info;
>
>         if (!of_device_is_available(pdev->dev.of_node))
>                 return -ENODEV;
> @@ -484,6 +485,15 @@ static int axp20x_power_probe(struct platform_device *pdev)
>                 return PTR_ERR(axp20x_batt->batt);
>         }
>
> +       if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {

This is not in -next. It would help if you mention any requisite patches.

ChenYu

> +               int vmin = info.voltage_min_design_uv;
> +
> +               if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
> +                                                             vmin))
> +                       dev_err(&pdev->dev,
> +                               "couldn't set voltage_min_design\n");
> +       }
> +
>         return 0;
>  }
>
> --
> 2.11.0
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery
  2017-05-16  5:18   ` Chen-Yu Tsai
@ 2017-05-16  6:33     ` Quentin Schulz
  0 siblings, 0 replies; 10+ messages in thread
From: Quentin Schulz @ 2017-05-16  6:33 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Sebastian Reichel, Rob Herring, Mark Rutland, open list:THERMAL,
	devicetree, linux-kernel, Liam Breck, Thomas Petazzoni,
	linux-sunxi

Hi Chen-Yu,

On 16/05/2017 07:18, Chen-Yu Tsai wrote:
> On Thu, May 11, 2017 at 9:42 PM, Quentin Schulz
> <quentin.schulz@free-electrons.com> wrote:
>> This adds support in X-Powers AXP20X and AXP22X battery driver for a
>> fixed battery in DT.
>>
>> It will take the minimum supported voltage by the battery as defined in
>> the battery DT node and set the V_OFF register to this value, telling
>> the system to shut down if the supplied power is below this value.
>>
>> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
>> ---
>>  drivers/power/supply/axp20x_battery.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
>> index 5d29b2eab8fc..66f530541735 100644
>> --- a/drivers/power/supply/axp20x_battery.c
>> +++ b/drivers/power/supply/axp20x_battery.c
>> @@ -433,6 +433,7 @@ static int axp20x_power_probe(struct platform_device *pdev)
>>  {
>>         struct axp20x_batt_ps *axp20x_batt;
>>         struct power_supply_config psy_cfg = {};
>> +       struct power_supply_battery_info info;
>>
>>         if (!of_device_is_available(pdev->dev.of_node))
>>                 return -ENODEV;
>> @@ -484,6 +485,15 @@ static int axp20x_power_probe(struct platform_device *pdev)
>>                 return PTR_ERR(axp20x_batt->batt);
>>         }
>>
>> +       if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
> 
> This is not in -next. It would help if you mention any requisite patches.
> 

I started working on this when next-20170503 was the latest and forgot
to rebase before sending the patch series. It was actually in both
next-20170502 and 20170503 but not in more recent ones.

Liam told me in a private message he's soon sending a new version of his
patch series, so I'll be waiting for the patches to reappear in next.

Thanks,
Quentin

> ChenYu
> 
>> +               int vmin = info.voltage_min_design_uv;
>> +
>> +               if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
>> +                                                             vmin))
>> +                       dev_err(&pdev->dev,
>> +                               "couldn't set voltage_min_design\n");
>> +       }
>> +
>>         return 0;
>>  }
>>
>> --
>> 2.11.0
>>

-- 
Quentin Schulz, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery
  2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
  2017-05-16  5:18   ` Chen-Yu Tsai
@ 2017-06-08 15:58   ` Sebastian Reichel
  1 sibling, 0 replies; 10+ messages in thread
From: Sebastian Reichel @ 2017-06-08 15:58 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: robh+dt, mark.rutland, wens, linux-pm, devicetree, linux-kernel,
	liam, thomas.petazzoni, linux-sunxi

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

Hi,

On Thu, May 11, 2017 at 03:42:17PM +0200, Quentin Schulz wrote:
> This adds support in X-Powers AXP20X and AXP22X battery driver for a
> fixed battery in DT.
> 
> It will take the minimum supported voltage by the battery as defined in
> the battery DT node and set the V_OFF register to this value, telling
> the system to shut down if the supplied power is below this value.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>

Thanks, queued.

-- Sebastian

>  drivers/power/supply/axp20x_battery.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index 5d29b2eab8fc..66f530541735 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
> @@ -433,6 +433,7 @@ static int axp20x_power_probe(struct platform_device *pdev)
>  {
>  	struct axp20x_batt_ps *axp20x_batt;
>  	struct power_supply_config psy_cfg = {};
> +	struct power_supply_battery_info info;
>  
>  	if (!of_device_is_available(pdev->dev.of_node))
>  		return -ENODEV;
> @@ -484,6 +485,15 @@ static int axp20x_power_probe(struct platform_device *pdev)
>  		return PTR_ERR(axp20x_batt->batt);
>  	}
>  
> +	if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
> +		int vmin = info.voltage_min_design_uv;
> +
> +		if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
> +							      vmin))
> +			dev_err(&pdev->dev,
> +				"couldn't set voltage_min_design\n");
> +	}
> +
>  	return 0;
>  }
>  
> -- 
> 2.11.0
> 

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current
  2017-05-11 13:42 ` [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current Quentin Schulz
@ 2017-06-08 15:58   ` Sebastian Reichel
  0 siblings, 0 replies; 10+ messages in thread
From: Sebastian Reichel @ 2017-06-08 15:58 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: robh+dt, mark.rutland, wens, linux-pm, devicetree, linux-kernel,
	liam, thomas.petazzoni, linux-sunxi

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

Hi,

On Thu, May 11, 2017 at 03:42:20PM +0200, Quentin Schulz wrote:
> This adds the ability to set the maximum constant charge current,
> supported by the battery, delivered by this battery power supply to the
> battery.
> 
> The maximum constant charge current set in DT will also set the default
> constant charge current supplied by this supply.
> 
> The actual user can modify the constant charge current within the range
> of 0 to maximum constant charge current via sysfs.
> The user can also modify the maximum constant charge current to widen
> the range of possible constant charge current. While this seems quite
> risky, a message is printed on the console to warn the user this might
> damage the battery. The reason for letting the user change the maximum
> constant charge current is for letting users change the battery and
> thus, let them adjust the maximum constant charge current according to
> what the battery can support.
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>

Thanks, queued.

-- Sebastian

> ---
>  drivers/power/supply/axp20x_battery.c | 78 +++++++++++++++++++++++++++++++----
>  1 file changed, 70 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index 66f530541735..7494f0f0eadb 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
> @@ -60,6 +60,8 @@ struct axp20x_batt_ps {
>  	struct iio_channel *batt_chrg_i;
>  	struct iio_channel *batt_dischrg_i;
>  	struct iio_channel *batt_v;
> +	/* Maximum constant charge current */
> +	unsigned int max_ccc;
>  	u8 axp_id;
>  };
>  
> @@ -129,6 +131,14 @@ static void raw_to_constant_charge_current(struct axp20x_batt_ps *axp, int *val)
>  		*val = *val * 150000 + 300000;
>  }
>  
> +static void constant_charge_current_to_raw(struct axp20x_batt_ps *axp, int *val)
> +{
> +	if (axp->axp_id == AXP209_ID)
> +		*val = (*val - 300000) / 100000;
> +	else
> +		*val = (*val - 300000) / 150000;
> +}
> +
>  static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp,
>  					      int *val)
>  {
> @@ -221,9 +231,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
>  		break;
>  
>  	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
> -		val->intval = AXP20X_CHRG_CTRL1_TGT_CURR;
> -		raw_to_constant_charge_current(axp20x_batt, &val->intval);
> -
> +		val->intval = axp20x_batt->max_ccc;
>  		break;
>  
>  	case POWER_SUPPLY_PROP_CURRENT_NOW:
> @@ -340,10 +348,10 @@ static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
>  static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
>  					      int charge_current)
>  {
> -	if (axp_batt->axp_id == AXP209_ID)
> -		charge_current = (charge_current - 300000) / 100000;
> -	else
> -		charge_current = (charge_current - 300000) / 150000;
> +	if (charge_current > axp_batt->max_ccc)
> +		return -EINVAL;
> +
> +	constant_charge_current_to_raw(axp_batt, &charge_current);
>  
>  	if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
>  		return -EINVAL;
> @@ -352,6 +360,36 @@ static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
>  				  AXP20X_CHRG_CTRL1_TGT_CURR, charge_current);
>  }
>  
> +static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp,
> +						  int charge_current)
> +{
> +	bool lower_max = false;
> +
> +	constant_charge_current_to_raw(axp, &charge_current);
> +
> +	if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
> +		return -EINVAL;
> +
> +	raw_to_constant_charge_current(axp, &charge_current);
> +
> +	if (charge_current > axp->max_ccc)
> +		dev_warn(axp->dev,
> +			 "Setting max constant charge current higher than previously defined. Note that increasing the constant charge current may damage your battery.\n");
> +	else
> +		lower_max = true;
> +
> +	axp->max_ccc = charge_current;
> +
> +	if (lower_max) {
> +		int current_cc;
> +
> +		axp20x_get_constant_charge_current(axp, &current_cc);
> +		if (current_cc > charge_current)
> +			axp20x_set_constant_charge_current(axp, charge_current);
> +	}
> +
> +	return 0;
> +}
>  static int axp20x_set_voltage_min_design(struct axp20x_batt_ps *axp_batt,
>  					 int min_voltage)
>  {
> @@ -380,6 +418,9 @@ static int axp20x_battery_set_prop(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
>  		return axp20x_set_constant_charge_current(axp20x_batt,
>  							  val->intval);
> +	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
> +		return axp20x_set_max_constant_charge_current(axp20x_batt,
> +							      val->intval);
>  
>  	default:
>  		return -EINVAL;
> @@ -405,7 +446,8 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy,
>  {
>  	return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
>  	       psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ||
> -	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT;
> +	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
> +	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
>  }
>  
>  static const struct power_supply_desc axp20x_batt_ps_desc = {
> @@ -487,13 +529,33 @@ static int axp20x_power_probe(struct platform_device *pdev)
>  
>  	if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
>  		int vmin = info.voltage_min_design_uv;
> +		int ccc = info.constant_charge_current_max_ua;
>  
>  		if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
>  							      vmin))
>  			dev_err(&pdev->dev,
>  				"couldn't set voltage_min_design\n");
> +
> +		/* Set max to unverified value to be able to set CCC */
> +		axp20x_batt->max_ccc = ccc;
> +
> +		if (ccc <= 0 || axp20x_set_constant_charge_current(axp20x_batt,
> +								   ccc)) {
> +			dev_err(&pdev->dev,
> +				"couldn't set constant charge current from DT: fallback to minimum value\n");
> +			ccc = 300000;
> +			axp20x_batt->max_ccc = ccc;
> +			axp20x_set_constant_charge_current(axp20x_batt, ccc);
> +		}
>  	}
>  
> +	/*
> +	 * Update max CCC to a valid value if battery info is present or set it
> +	 * to current register value by default.
> +	 */
> +	axp20x_get_constant_charge_current(axp20x_batt,
> +					   &axp20x_batt->max_ccc);
> +
>  	return 0;
>  }
>  
> -- 
> 2.11.0
> 

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-06-08 15:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 13:42 [PATCH 0/4] set battery info on AXP20X and AXP22X from DT Quentin Schulz
2017-05-11 13:42 ` [PATCH 1/4] power: supply: axp20x_battery: add support for DT battery Quentin Schulz
2017-05-16  5:18   ` Chen-Yu Tsai
2017-05-16  6:33     ` Quentin Schulz
2017-06-08 15:58   ` Sebastian Reichel
2017-05-11 13:42 ` [PATCH 2/4] dt-bindings: power: battery: add constant-charge-current-max-microamp property Quentin Schulz
2017-05-15 20:14   ` Rob Herring
2017-05-11 13:42 ` [PATCH 3/4] power: supply: power_supply_core: add constant-charge-current optional property Quentin Schulz
2017-05-11 13:42 ` [PATCH 4/4] power: supply: axp20x_battery: add DT support for battery max constant charge current Quentin Schulz
2017-06-08 15:58   ` Sebastian Reichel

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).