Skip to contentSkip to conversation

Add max77620 charging & low battery support

PATCH In review Mark Zhang 3 participants 10 messages Feb 12, 2019 – Feb 19, 2019

Subsystems (3)
lore
Share & tools
lore

Mark Zhang

author
#0 lore raw

v3 cover Add max77620 charging & low battery support

This patch set adds support for max77620 backup battery charging and low battery monitoring.

Changes in v3:
- Add unit suffix to backup battery charging dts properties
- Reduce/optimize the low battery monitoring dts properties

Changes in v2:
- Add devicetree binding documentation

Mark Zhang (4):
mfd: max77620: Add backup battery charger support
mfd: max77620: add documentation for backup battery charging
mfd: max77620: Add low battery monitor support
mfd: max77620: add documentation for low battery monitoring

 .../devicetree/bindings/mfd/max77620.txt      |  34 ++++++
 drivers/mfd/max77620.c                        | 115 +++++++++++++++++-
 2 files changed, 148 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.2
author
#1 lore raw

PATCH v3 1/4 mfd: max77620: Add backup battery charger support

Add PMIC configurations for backup battery charger, which is a constant voltage and constant current style charger with a series output resistance.

The max77620 register CNFGBBC(addr: 0x04) defines the parameters of backup battery charger. This patch adds support for it.

---
 drivers/mfd/max77620.c | 80 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
drivers/mfd/max77620.c +80 -0
index d8ddd1a6f304..494d98357f65 100644
@@ -398,6 +398,82 @@ static int max77620_initialise_fps(struct max77620_chip *chip)
 	return 0;
 }
 
+static int max77620_init_backup_battery_charging(struct max77620_chip *chip)
+{
+	struct device *dev = chip->dev;
+	struct device_node *np;
+	u32 pval;
+	u8 config;
+	int charging_current;
+	int charging_voltage;
+	int resistor;
+	int ret;
+
+	np = of_get_child_by_name(dev->of_node, "backup-battery");
+	if (!np) {
+		dev_info(dev, "Backup battery charging support disabled\n");
+		ret = regmap_update_bits(chip->rmap, MAX77620_REG_CNFGBBC,
+					 MAX77620_CNFGBBC_ENABLE, 0);
+		if (ret < 0)
+			dev_err(dev, "Failed to update CNFGBBC: %d\n", ret);
+		return ret;
+	}
+
+	ret = of_property_read_u32(np,
+			"maxim,charging-current-microamp", &pval);
+	charging_current = (!ret) ? pval : 50;
+
+	ret = of_property_read_u32(np,
+			"maxim,charging-voltage-microvolt", &pval);
+	charging_voltage = (!ret) ? pval : 2500000;
+	charging_voltage /= 1000;
+
+	ret = of_property_read_u32(np,
+			"maxim,output-resister-ohms", &pval);
+	resistor = (!ret) ? pval : 1000;
+
+	config = MAX77620_CNFGBBC_ENABLE;
+	if (charging_current <= 50)
+		config |= 0 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+	else if (charging_current <= 100)
+		config |= 3 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+	else if (charging_current <= 200)
+		config |= 0 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+	else if (charging_current <= 400)
+		config |= 3 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+	else if (charging_current <= 600)
+		config |= 1 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+	else
+		config |= 2 << MAX77620_CNFGBBC_CURRENT_SHIFT;
+
+	if (charging_current > 100)
+		config |= MAX77620_CNFGBBC_LOW_CURRENT_DISABLE;
+
+	if (charging_voltage <= 2500)
+		config |= 0 << MAX77620_CNFGBBC_VOLTAGE_SHIFT;
+	else if (charging_voltage <= 3000)
+		config |= 1 << MAX77620_CNFGBBC_VOLTAGE_SHIFT;
+	else if (charging_voltage <= 3300)
+		config |= 2 << MAX77620_CNFGBBC_VOLTAGE_SHIFT;
+	else
+		config |= 3 << MAX77620_CNFGBBC_VOLTAGE_SHIFT;
+
+	if (resistor <= 100)
+		config |= 0 << MAX77620_CNFGBBC_RESISTOR_SHIFT;
+	else if (resistor <= 1000)
+		config |= 1 << MAX77620_CNFGBBC_RESISTOR_SHIFT;
+	else if (resistor <= 3000)
+		config |= 2 << MAX77620_CNFGBBC_RESISTOR_SHIFT;
+	else if (resistor <= 6000)
+		config |= 3 << MAX77620_CNFGBBC_RESISTOR_SHIFT;
+
+	ret = regmap_write(chip->rmap, MAX77620_REG_CNFGBBC, config);
+	if (ret < 0)
+		dev_err(dev, "Reg 0x%02x write failed, %d\n",
+				MAX77620_REG_CNFGBBC, ret);
+	return ret;
+}
+
 static int max77620_read_es_version(struct max77620_chip *chip)
 {
 	unsigned int val;
@@ -483,6 +559,10 @@ static int max77620_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
+	ret = max77620_init_backup_battery_charging(chip);
+	if (ret < 0)
+		return ret;
+
 	ret =  devm_mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE,
 				    mfd_cells, n_mfd_cells, NULL, 0,
 				    regmap_irq_get_domain(chip->top_irq_data));
Signature · 1 line
2.19.2
#2 lore raw

Re: [PATCH v3 1/4] mfd: max77620: Add backup battery charger support

Quoted 8 lines · Mark Zhang

Add PMIC configurations for backup battery charger, which is a constant voltage and constant current style charger with a series output resistance.

The max77620 register CNFGBBC(addr: 0x04) defines the parameters of backup battery charger. This patch adds support for it.

Quoted 6 lines
---
 drivers/mfd/max77620.c | 80 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

My previous review comments still apply.

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
author
#3 lore raw

PATCH v3 2/4 mfd: max77620: add documentation for backup battery charging

In reply to Mark Zhang

Adding documentation for 3 new backup battery charging dts properties:
- maxim,charging-current-microamp
- maxim,charging-voltage-microvolt
- maxim,output-resister-ohms

---
 .../devicetree/bindings/mfd/max77620.txt      | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/mfd/max77620.txt +20 -0
index 9c16d51cc15b..88825eaf2567 100644
@@ -122,6 +122,26 @@ For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
 
+Backup Battery:
+==============
+This sub-node configure charging backup battery of the device. Device has
+support of charging the backup battery. The subnode name is "backup-battery".
+The property for backup-battery child nodes as:
+Presence of this child node will enable the backup battery charging.
+
+Optional properties:
+	-maxim,charging-current-microamp: Charging current setting.
+			The device supports 50/100/200/400/600/800uA.
+			If this property is unavailable then it will
+			charge with 50uA.
+	-maxim,charging-voltage-microvolt: Charging Voltage Limit Setting.
+			Device supports 2500000/3000000/3300000/350000uV.
+			Default will be set to 2500mV. The voltage will be roundoff
+			to nearest lower side if other than above is configured.
+	-maxim,output-resister-ohms: Output resistor on Ohm.
+			Device supports 100/1000/3000/6000 Ohms.
+			Default will be set to 1000 Ohm.
+
 Example:
 --------
 #include <dt-bindings/mfd/max77620.h>
Signature · 1 line
2.19.2
#4 lore raw

Re: [PATCH v3 2/4] mfd: max77620: add documentation for backup battery charging

Quoted 6 lines · Mark Zhang

Adding documentation for 3 new backup battery charging dts properties:
- maxim,charging-current-microamp
- maxim,charging-voltage-microvolt
- maxim,output-resister-ohms

What's the difference between the 77620 and 77650 as there's patches on the list for the 77650 too. The properties are similar, but seems to be main vs. backup battery charger. We should have common properties for this.

Quoted 39 lines
---
 .../devicetree/bindings/mfd/max77620.txt      | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/mfd/max77620.txt +20 -1
index 9c16d51cc15b..88825eaf2567 100644
@@ -122,6 +122,26 @@ For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
 
+Backup Battery:
+==============
+This sub-node configure charging backup battery of the device. Device has
+support of charging the backup battery. The subnode name is "backup-battery".
+The property for backup-battery child nodes as:
+Presence of this child node will enable the backup battery charging.
+
+Optional properties:
+       -maxim,charging-current-microamp: Charging current setting.
+                       The device supports 50/100/200/400/600/800uA.
+                       If this property is unavailable then it will
+                       charge with 50uA.
+       -maxim,charging-voltage-microvolt: Charging Voltage Limit Setting.
+                       Device supports 2500000/3000000/3300000/350000uV.
+                       Default will be set to 2500mV. The voltage will be roundoff
+                       to nearest lower side if other than above is configured.
+       -maxim,output-resister-ohms: Output resistor on Ohm.
+                       Device supports 100/1000/3000/6000 Ohms.
+                       Default will be set to 1000 Ohm.
+
 Example:
 --------
 #include <dt-bindings/mfd/max77620.h>
--

2.19.2

author
#5 lore raw

Re: [PATCH v3 2/4] mfd: max77620: add documentation for backup battery charging

Quoted 8 lines · Rob Herring
Quoted 6 lines · Mark Zhang

Adding documentation for 3 new backup battery charging dts properties:
- maxim,charging-current-microamp
- maxim,charging-voltage-microvolt
- maxim,output-resister-ohms

Quoted 4 lines

What's the difference between the 77620 and 77650 as there's patches on the list for the 77650 too. The properties are similar, but seems to be main vs. backup battery charger. We should have common properties for this.

Rob, it's different. The RTC in max77620 is supplied from a backup battery and consumes 2.0uA (IBBATT) when no other power sources are available. So unlike max77620 battery charging, which provides features like:

static enum power_supply_property max77650_charger_properties[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_CHARGE_TYPE
};

For backup battery charging in max77620, what we can do is just setting those 3 parameters. We don't know whether it's charging, whether the backup battery is online, the percentage of the charging progress, and etc. That's why I mentioned before that it's not appropriate to create it as a power supply driver.

Mark

Quoted 40 lines
Quoted 40 lines
---
 .../devicetree/bindings/mfd/max77620.txt      | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/mfd/max77620.txt +20 -1
index 9c16d51cc15b..88825eaf2567 100644
@@ -122,6 +122,26 @@ For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
 
+Backup Battery:
+==============
+This sub-node configure charging backup battery of the device. Device has
+support of charging the backup battery. The subnode name is "backup-battery".
+The property for backup-battery child nodes as:
+Presence of this child node will enable the backup battery charging.
+
+Optional properties:
+       -maxim,charging-current-microamp: Charging current setting.
+                       The device supports 50/100/200/400/600/800uA.
+                       If this property is unavailable then it will
+                       charge with 50uA.
+       -maxim,charging-voltage-microvolt: Charging Voltage Limit Setting.
+                       Device supports 2500000/3000000/3300000/350000uV.
+                       Default will be set to 2500mV. The voltage will be roundoff
+                       to nearest lower side if other than above is configured.
+       -maxim,output-resister-ohms: Output resistor on Ohm.
+                       Device supports 100/1000/3000/6000 Ohms.
+                       Default will be set to 1000 Ohm.
+
 Example:
 --------
 #include <dt-bindings/mfd/max77620.h>
--

2.19.2

author
#6 lore raw

Re: [PATCH v3 2/4] mfd: max77620: add documentation for backup battery charging

Quoted 9 lines · Mark Zhang
Quoted 8 lines · Rob Herring
Quoted 6 lines · Mark Zhang

Adding documentation for 3 new backup battery charging dts properties:
- maxim,charging-current-microamp
- maxim,charging-voltage-microvolt
- maxim,output-resister-ohms

Quoted 8 lines
Quoted 4 lines

What's the difference between the 77620 and 77650 as there's patches on the list for the 77650 too. The properties are similar, but seems to be main vs. backup battery charger. We should have common properties for this.

Rob, it's different. The RTC in max77620 is supplied from a backup battery and consumes 2.0uA (IBBATT) when no other power sources are available. So unlike max77620 battery charging, which provides features

Oops... s/unlike max77620/unlike max77650.

Mark

Quoted 56 lines

like:

static enum power_supply_property max77650_charger_properties[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_CHARGE_TYPE
};

For backup battery charging in max77620, what we can do is just setting those 3 parameters. We don't know whether it's charging, whether the backup battery is online, the percentage of the charging progress, and etc. That's why I mentioned before that it's not appropriate to create it as a power supply driver.

Mark

Quoted 40 lines
Quoted 40 lines
---
 .../devicetree/bindings/mfd/max77620.txt      | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/devicetree/bindings/mfd/max77620.txt +20 -1
index 9c16d51cc15b..88825eaf2567 100644
@@ -122,6 +122,26 @@ For DT binding details of different sub modules like GPIO, pincontrol,
 regulator, power, please refer respective device-tree binding document
 under their respective sub-system directories.
 
+Backup Battery:
+==============
+This sub-node configure charging backup battery of the device. Device has
+support of charging the backup battery. The subnode name is "backup-battery".
+The property for backup-battery child nodes as:
+Presence of this child node will enable the backup battery charging.
+
+Optional properties:
+       -maxim,charging-current-microamp: Charging current setting.
+                       The device supports 50/100/200/400/600/800uA.
+                       If this property is unavailable then it will
+                       charge with 50uA.
+       -maxim,charging-voltage-microvolt: Charging Voltage Limit Setting.
+                       Device supports 2500000/3000000/3300000/350000uV.
+                       Default will be set to 2500mV. The voltage will be roundoff
+                       to nearest lower side if other than above is configured.
+       -maxim,output-resister-ohms: Output resistor on Ohm.
+                       Device supports 100/1000/3000/6000 Ohms.
+                       Default will be set to 1000 Ohm.
+
 Example:
 --------
 #include <dt-bindings/mfd/max77620.h>
--

2.19.2

#7 lore raw

Re: [PATCH v3 2/4] mfd: max77620: add documentation for backup battery charging

In reply to Mark Zhang
Quoted 26 lines · Mark Zhang
Quoted 8 lines · Rob Herring
Quoted 6 lines · Mark Zhang

Adding documentation for 3 new backup battery charging dts properties:
- maxim,charging-current-microamp
- maxim,charging-voltage-microvolt
- maxim,output-resister-ohms

Quoted 4 lines

What's the difference between the 77620 and 77650 as there's patches on the list for the 77650 too. The properties are similar, but seems to be main vs. backup battery charger. We should have common properties for this.

Rob, it's different. The RTC in max77620 is supplied from a backup battery and consumes 2.0uA (IBBATT) when no other power sources are available. So unlike max77620 battery charging, which provides features like:

static enum power_supply_property max77650_charger_properties[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_CHARGE_TYPE
};

Quoted 5 lines

For backup battery charging in max77620, what we can do is just setting those 3 parameters. We don't know whether it's charging, whether the backup battery is online, the percentage of the charging progress, and etc. That's why I mentioned before that it's not appropriate to create it as a power supply driver.

Maybe so, but that's all outside the scope of the binding. Both bindings define charging current and voltage. And other vendor's chargers likely need the same parameters, too. So there's no reason to have different properties.

Rob

author
#8 lore raw

PATCH v3 3/4 mfd: max77620: Add low battery monitor support

In reply to Mark Zhang

This patch adds PMIC configurations for low-battery monitoring by handling max77620 register CNFGGLBL1.

---
 drivers/mfd/max77620.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
drivers/mfd/max77620.c +34 -1
index 494d98357f65..6f0c85b2ca26 100644
@@ -474,6 +474,35 @@ static int max77620_init_backup_battery_charging(struct max77620_chip *chip)
 	return ret;
 }
 
+static int max77620_init_low_battery_monitor(struct max77620_chip *chip)
+{
+	struct device *dev = chip->dev;
+	bool bval;
+	int ival;
+	u8 mask = 0;
+	u8 val = 0;
+	int ret;
+
+	mask |= MAX77620_CNFGGLBL1_LBDAC_EN;
+	bval = of_property_read_bool(dev->of_node,
+			"maxim,low-battery-dac-enable");
+	if (bval)
+		val |= MAX77620_CNFGGLBL1_LBDAC_EN;
+
+	mask |= MAX77620_CNFGGLBL1_LBRSTEN | MAX77620_CNFGGLBL1_MPPLD;
+	ival = of_property_match_string(dev->of_node,
+			"maxim,low-battery-mode", "shutdown");
+	if (ival < 0)
+		val |= MAX77620_CNFGGLBL1_LBRSTEN;
+	else
+		val |= MAX77620_CNFGGLBL1_MPPLD;
+
+	ret = regmap_update_bits(chip->rmap, MAX77620_REG_CNFGGLBL1, mask, val);
+	if (ret < 0)
+		dev_err(dev, "Reg CNFGGLBL1 update failed: %d\n", ret);
+	return ret;
+}
+
 static int max77620_read_es_version(struct max77620_chip *chip)
 {
 	unsigned int val;
@@ -563,7 +592,11 @@ static int max77620_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	ret =  devm_mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE,
+	ret = max77620_init_low_battery_monitor(chip);
+	if (ret < 0)
+		return ret;
+
+	ret = devm_mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE,
 				    mfd_cells, n_mfd_cells, NULL, 0,
 				    regmap_irq_get_domain(chip->top_irq_data));
 	if (ret < 0) {
Signature · 1 line
2.19.2
author
#9 lore raw

PATCH v3 4/4 mfd: max77620: add documentation for low battery monitoring

In reply to Mark Zhang

Adding documentation for low battery monitor properties:
- maxim,low-battery-dac-enable
- maxim,low-battery-mode

---
 Documentation/devicetree/bindings/mfd/max77620.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/mfd/max77620.txt +14 -0
index 88825eaf2567..f5b298ccc929 100644
@@ -142,6 +142,20 @@ Optional properties:
 			Device supports 100/1000/3000/6000 Ohms.
 			Default will be set to 1000 Ohm.
 
+Low-Battery Monitor:
+==================
+max77620 is able to monitor the main battery voltage and shutdown/reset the
+chip connected accordingly.
+
+Optional properties:
+	- maxim,low-battery-dac-enable: Enable low battery monitoring.
+			Low battery monitoring will be disabled if missing
+			this property.
+	- maxim,low-battery-mode: Shutdown or reset the chip.
+			The value of this property is "shutdown" which means
+			a global shutdown will be triggered. Any other values
+			or missing this property causes a chip reset.
+
 Example:
 --------
 #include <dt-bindings/mfd/max77620.h>
Signature · 1 line
2.19.2