Skip to contentSkip to conversation

Add JEITA properties and introduce the bq2515x charger

PATCH Superseded Dan Murphy 3 participants 6 messages May 19, 2020

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Dan Murphy

author
#0 lore raw

v7 cover Add JEITA properties and introduce the bq2515x charger

Hello,

This patchset adds additional health properties to the power_supply header. These additional properties are taken from the JEITA specification. This patchset also introduces the bq2515x family of charging ICs.

Dan Murphy (1):
power_supply: Add additional health properties to the header

Ricardo Rivera-Matos (2):
Add the bindings for the bq25150 and bq25155 500mA charging ICs from
Texas Instruments.
power: supply: bq25150 introduce the bq25150

 Documentation/ABI/testing/sysfs-class-power   |    2 +-
 .../bindings/power/supply/bq2515x.yaml        |  106 ++
 drivers/power/supply/Kconfig                  |   13 +
 drivers/power/supply/Makefile                 |    1 +
 drivers/power/supply/bq2515x_charger.c        | 1167 +++++++++++++++++
 drivers/power/supply/power_supply_sysfs.c     |    2 +-
 include/linux/power_supply.h                  |    3 +
 7 files changed, 1292 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq2515x.yaml
 create mode 100644 drivers/power/supply/bq2515x_charger.c
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v7 1/3 power_supply: Add additional health properties to the header

Add HEALTH_WARM, HEALTH_COOL and HEALTH_HOT to the health enum.

HEALTH_WARM, HEALTH_COOL, and HEALTH_HOT properties are taken from the JEITA spec.

---
 Documentation/ABI/testing/sysfs-class-power | 2 +-
 drivers/power/supply/power_supply_sysfs.c   | 2 +-
 include/linux/power_supply.h                | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-class-power +1 -1
index bf3b48f022dc..9f3fd01a9373 100644
@@ -190,7 +190,7 @@ Description:
 		Valid values: "Unknown", "Good", "Overheat", "Dead",
 			      "Over voltage", "Unspecified failure", "Cold",
 			      "Watchdog timer expire", "Safety timer expire",
-			      "Over current"
+			      "Over current", "Warm", "Cool", "Hot"
 
 What:		/sys/class/power_supply/<supply_name>/precharge_current
 Date:		June 2017
drivers/power/supply/power_supply_sysfs.c +1 -1
index f37ad4eae60b..d0d549611794 100644
@@ -61,7 +61,7 @@ static const char * const power_supply_charge_type_text[] = {
 static const char * const power_supply_health_text[] = {
 	"Unknown", "Good", "Overheat", "Dead", "Over voltage",
 	"Unspecified failure", "Cold", "Watchdog timer expire",
-	"Safety timer expire", "Over current"
+	"Safety timer expire", "Over current", "Warm", "Cool", "Hot"
 };
 
 static const char * const power_supply_technology_text[] = {
include/linux/power_supply.h +3 -0
index dcd5a71e6c67..8670e90c1d51 100644
@@ -61,6 +61,9 @@ enum {
 	POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
 	POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
 	POWER_SUPPLY_HEALTH_OVERCURRENT,
+	POWER_SUPPLY_HEALTH_WARM,
+	POWER_SUPPLY_HEALTH_COOL,
+	POWER_SUPPLY_HEALTH_HOT,
 };
 
 enum {
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v7 2/3 Add the bindings for the bq25150 and bq25155 500mA charging ICs from Texas Instruments.

In reply to Dan Murphy

From: Ricardo Rivera-Matos <[email protected]>

The BQ2515X family of devices are highly integrated battery management ICs that integrate the most common functions for wearable devices namely a charger, an output voltage rail, ADC for battery and system monitoring, and a push-button controller.

Datasheets:
http://www.ti.com/lit/ds/symlink/bq25150.pdf
http://www.ti.com/lit/ds/symlink/bq25155.pdf

---
 .../bindings/power/supply/bq2515x.yaml        | 106 ++++++++++++++++++
 1 file changed, 106 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/bq2515x.yaml
Documentation/devicetree/bindings/power/supply/bq2515x.yaml new file +106 -0
new file mode 100644
index 000000000000..83487957fc8c
@@ -0,0 +1,106 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2020 Texas Instruments Incorporated
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/power/supply/bq2515x.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: TI bq2515x 500-mA Linear charger family
+
+maintainers:
+  - Dan Murphy <[email protected]>
+  - Ricardo Rivera-Matos <[email protected]>
+
+description: |
+  The BQ2515x family is a highly integrated battery charge management IC that
+  integrates the most common functions for wearable devices, namely a charger,
+  an output voltage rail, ADC for battery and system monitoring, and
+  push-button controller.
+
+  Specifications about the charger can be found at:
+    http://www.ti.com/lit/ds/symlink/bq25150.pdf
+    http://www.ti.com/lit/ds/symlink/bq25155.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,bq25150
+      - ti,bq25155
+
+  reg:
+    maxItems: 1
+    description: I2C address of the charger.
+
+  ac-detect-gpios:
+    description: |
+       GPIO used for connecting the bq2515x device PG (AC Detect)
+       pin.  This pin should be used if possible as this is the
+       recommended way to obtain the charger's input PG state.
+       If this pin is not specified a software-based approach for PG
+       detection is used.
+
+  reset-gpios:
+    description: |
+       GPIO used for hardware reset.
+
+  low-power-gpios:
+    description: |
+       GPIO used for low power mode of IC.
+
+  charge-enable-gpios:
+    description: |
+       GPIO used to turn on and off charging.
+
+  constant-charge-current-max-microamp:
+    description: |
+       Maximum charging current in micro Amps.
+    minimum: 50000
+    maximum: 600000
+
+  precharge-current-max-microamp:
+    description: |
+       Maximum precharging current in micro Amps.
+    minimum: 1250
+    maximum: 77500
+
+  input-current-limit-microamp:
+    description: |
+       Maximum input current in micro Amps.
+    minimum: 50000
+    maximum: 500000
+
+  constant-charge-voltage-max-microvolt:
+    description: |
+       Maximum charging voltage in micro volts.
+    minimum: 3600000
+    maximum: 4600000
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    bat: battery {
+      compatible = "simple-battery";
+      constant-charge-current-max-microamp = <50000>;
+      precharge-current-microamp = <2500>;
+      constant-charge-voltage-max-microvolt = <4000000>;
+    };
+    #include <dt-bindings/gpio/gpio.h>
+    i2c0 {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      bq25150: charger@6b {
+        compatible = "ti,bq25150";
+        reg = <0x6b>;
+        monitored-battery = <&bat>;
+        input-current-limit-microamp = <100000>;
+
+        ac-detect-gpios = <&gpio1 28 GPIO_ACTIVE_HIGH>;
+        reset-gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>;
+        low-power-gpios = <&gpio0 15 GPIO_ACTIVE_HIGH>;
+        charge-enable-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
+      };
+    };
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH v7 3/3 power: supply: bq25150 introduce the bq25150

In reply to Dan Murphy

From: Ricardo Rivera-Matos <[email protected]>

Introduce the bq2515x family of chargers.

The BQ2515X family of devices are highly integrated battery management ICs that integrate the most common functions for wearable devices namely a charger, an output voltage rail, ADC for battery and system monitoring, and a push-button controller.

Datasheets:

	bq25150 - http://www.ti.com/lit/ds/symlink/bq25150.pdf
	bq25155 - http://www.ti.com/lit/ds/symlink/bq25155.pdf
---
 drivers/power/supply/Kconfig           |   13 +
 drivers/power/supply/Makefile          |    1 +
 drivers/power/supply/bq2515x_charger.c | 1167 ++++++++++++++++++++++++
 3 files changed, 1181 insertions(+)
 create mode 100644 drivers/power/supply/bq2515x_charger.c
drivers/power/supply/Kconfig +13 -0
index f3424fdce341..266193301e2d 100644
@@ -589,6 +589,19 @@ config CHARGER_BQ24735
 	help
 	  Say Y to enable support for the TI BQ24735 battery charger.
 
+config CHARGER_BQ2515X
+	tristate "TI BQ2515X battery charger family"
+	depends on I2C
+	depends on GPIOLIB || COMPILE_TEST
+	select REGMAP_I2C
+	help
+	  Say Y to enable support for the TI BQ2515X family of battery
+	  charging integrated circuits. The BQ2515X are highly integrated
+	  battery charge management ICs that integrate the most common
+	  functions for wearable devices, namely a charger, an output voltage
+	  rail, ADC for battery and system monitoring, and push-button
+	  controller.
+
 config CHARGER_BQ25890
 	tristate "TI BQ25890 battery charger driver"
 	depends on I2C
drivers/power/supply/Makefile +1 -0
index 6c7da920ea83..8fcc175a7e22 100644
@@ -80,6 +80,7 @@ obj-$(CONFIG_CHARGER_BQ2415X)	+= bq2415x_charger.o
 obj-$(CONFIG_CHARGER_BQ24190)	+= bq24190_charger.o
 obj-$(CONFIG_CHARGER_BQ24257)	+= bq24257_charger.o
 obj-$(CONFIG_CHARGER_BQ24735)	+= bq24735-charger.o
+obj-$(CONFIG_CHARGER_BQ2515X)	+= bq2515x_charger.o
 obj-$(CONFIG_CHARGER_BQ25890)	+= bq25890_charger.o
 obj-$(CONFIG_CHARGER_SMB347)	+= smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090)	+= tps65090-charger.o
drivers/power/supply/bq2515x_charger.c new file +1167 -0

1,167 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150

drivers/power/supply/bq2515x_charger.c line 663

Quoted 6 lines · Dan Murphy
drivers/power/supply/bq2515x_charger.c new file +6 -0
+static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val)
+{
+	int i;
+
+	if (val > BQ2515X_ILIM_MAX || val < BQ2515X_ILIM_MIN)
+		return -EINVAL;

Clamp to these limits, not reject. Or better, modify the below loop so it clamps to the highest or lowest value in bq2515x_ilim_lvl_values[], then drop these #defines.

drivers/power/supply/bq2515x_charger.c line 669

Quoted 6 lines
drivers/power/supply/bq2515x_charger.c new file +6 -0
+
+	for (i = 0; i < ARRAY_SIZE(bq2515x_ilim_lvl_values); i++) {
+		if (val == bq2515x_ilim_lvl_values[i])
+			break;
+
+		if (val > bq2515x_ilim_lvl_values[i - 1] &&

Index out of bounds for the i = 0 case.

drivers/power/supply/bq2515x_charger.c line 672

Quoted 3 lines
drivers/power/supply/bq2515x_charger.c new file +3 -0
+		    val < bq2515x_ilim_lvl_values[i]) {
+			if (val - bq2515x_ilim_lvl_values[i - 1] <
+			    bq2515x_ilim_lvl_values[i] - val) {

You are still missing the case where the value is closer to the [i] element, you check that it is between [i-1] and [i], but only chose [i-1] when it is closer to that than [i] but equal and greater case is missing.

Given this sets input current limits, would instead always rounding down be the safer option?

Andrew

Quoted 8 lines
drivers/power/supply/bq2515x_charger.c new file +8 -0
+				i = i - 1;
+				break;
+			}
+		}
+	}
+
+	return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i);
+}
#5 lore raw

Re: [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150

Quoted 27 lines · Andrew F. Davis

drivers/power/supply/bq2515x_charger.c line 663

Quoted 6 lines · Dan Murphy
drivers/power/supply/bq2515x_charger.c new file +6 -0
+static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val)
+{
+	int i;
+
+	if (val > BQ2515X_ILIM_MAX || val < BQ2515X_ILIM_MIN)
+		return -EINVAL;

Clamp to these limits, not reject. Or better, modify the below loop so it clamps to the highest or lowest value in bq2515x_ilim_lvl_values[], then drop these #defines.

drivers/power/supply/bq2515x_charger.c line 669

Quoted 6 lines
drivers/power/supply/bq2515x_charger.c new file +6 -0
+
+	for (i = 0; i < ARRAY_SIZE(bq2515x_ilim_lvl_values); i++) {
+		if (val == bq2515x_ilim_lvl_values[i])
+			break;
+
+		if (val > bq2515x_ilim_lvl_values[i - 1] &&

Index out of bounds for the i = 0 case.

drivers/power/supply/bq2515x_charger.c line 672

Quoted 3 lines
drivers/power/supply/bq2515x_charger.c new file +3 -0
+		    val < bq2515x_ilim_lvl_values[i]) {
+			if (val - bq2515x_ilim_lvl_values[i - 1] <
+			    bq2515x_ilim_lvl_values[i] - val) {

You are still missing the case where the value is closer to the [i] element, you check that it is between [i-1] and [i], but only chose [i-1] when it is closer to that than [i] but equal and greater case is missing.

Quoted 4 lines

Given this sets input current limits, would instead always rounding down be the safer option?

Andrew

ACK. I am going to rewrite that altogether.

Quoted 9 lines
Quoted 9 lines
drivers/power/supply/bq2515x_charger.c new file +8 -0
+				i = i - 1;
+				break;
+			}
+		}
+	}
+
+	return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i);
+}