2019-02-12 06:46:37

by Mark Zhang

[permalink] [raw]
Subject: [PATCH v3 0/4] 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(-)

--
2.19.2



2019-02-12 06:44:51

by Mark Zhang

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

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

Signed-off-by: Mark Zhang <[email protected]>
---
.../devicetree/bindings/mfd/max77620.txt | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt b/Documentation/devicetree/bindings/mfd/max77620.txt
index 9c16d51cc15b..88825eaf2567 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -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


2019-02-12 06:44:55

by Mark Zhang

[permalink] [raw]
Subject: [PATCH v3 4/4] mfd: max77620: add documentation for low battery monitoring

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

Signed-off-by: Mark Zhang <[email protected]>
---
Documentation/devicetree/bindings/mfd/max77620.txt | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt b/Documentation/devicetree/bindings/mfd/max77620.txt
index 88825eaf2567..f5b298ccc929 100644
--- a/Documentation/devicetree/bindings/mfd/max77620.txt
+++ b/Documentation/devicetree/bindings/mfd/max77620.txt
@@ -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>
--
2.19.2


2019-02-12 06:45:03

by Mark Zhang

[permalink] [raw]
Subject: [PATCH v3 3/4] mfd: max77620: Add low battery monitor support

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

Signed-off-by: Laxman Dewangan <[email protected]>
Signed-off-by: Venkat Reddy Talla <[email protected]>
Signed-off-by: Mark Zhang <[email protected]>
---
drivers/mfd/max77620.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c
index 494d98357f65..6f0c85b2ca26 100644
--- a/drivers/mfd/max77620.c
+++ b/drivers/mfd/max77620.c
@@ -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) {
--
2.19.2


2019-02-12 06:47:14

by Mark Zhang

[permalink] [raw]
Subject: [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.

Signed-off-by: Laxman Dewangan <[email protected]>
Signed-off-by: Venkat Reddy Talla <[email protected]>
Signed-off-by: Mark Zhang <[email protected]>
---
drivers/mfd/max77620.c | 80 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)

diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c
index d8ddd1a6f304..494d98357f65 100644
--- a/drivers/mfd/max77620.c
+++ b/drivers/mfd/max77620.c
@@ -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));
--
2.19.2


2019-02-12 08:07:49

by Lee Jones

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

On Tue, 12 Feb 2019, Mark Zhang wrote:

> 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.
>
> Signed-off-by: Laxman Dewangan <[email protected]>
> Signed-off-by: Venkat Reddy Talla <[email protected]>
> Signed-off-by: Mark Zhang <[email protected]>
> ---
> drivers/mfd/max77620.c | 80 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 80 insertions(+)

My previous review comments still apply.

--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2019-02-18 19:15:18

by Rob Herring

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

On Tue, Feb 12, 2019 at 12:44 AM Mark Zhang <[email protected]> wrote:
>
> 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.

> Signed-off-by: Mark Zhang <[email protected]>
> ---
> .../devicetree/bindings/mfd/max77620.txt | 20 +++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt b/Documentation/devicetree/bindings/mfd/max77620.txt
> index 9c16d51cc15b..88825eaf2567 100644
> --- a/Documentation/devicetree/bindings/mfd/max77620.txt
> +++ b/Documentation/devicetree/bindings/mfd/max77620.txt
> @@ -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
>

2019-02-19 02:51:06

by Mark Zhang

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

On 2/19/2019 2:06 AM, Rob Herring wrote:
> On Tue, Feb 12, 2019 at 12:44 AM Mark Zhang <[email protected]> wrote:
>>
>> 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.

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

>
>> Signed-off-by: Mark Zhang <[email protected]>
>> ---
>> .../devicetree/bindings/mfd/max77620.txt | 20 +++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt b/Documentation/devicetree/bindings/mfd/max77620.txt
>> index 9c16d51cc15b..88825eaf2567 100644
>> --- a/Documentation/devicetree/bindings/mfd/max77620.txt
>> +++ b/Documentation/devicetree/bindings/mfd/max77620.txt
>> @@ -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
>>

2019-02-19 02:51:09

by Mark Zhang

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

On 2/19/2019 10:07 AM, Mark Zhang wrote:
> On 2/19/2019 2:06 AM, Rob Herring wrote:
>> On Tue, Feb 12, 2019 at 12:44 AM Mark Zhang <[email protected]> wrote:
>>>
>>> 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.
>
> 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

> 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
>
>>
>>> Signed-off-by: Mark Zhang <[email protected]>
>>> ---
>>> .../devicetree/bindings/mfd/max77620.txt | 20 +++++++++++++++++++
>>> 1 file changed, 20 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/mfd/max77620.txt b/Documentation/devicetree/bindings/mfd/max77620.txt
>>> index 9c16d51cc15b..88825eaf2567 100644
>>> --- a/Documentation/devicetree/bindings/mfd/max77620.txt
>>> +++ b/Documentation/devicetree/bindings/mfd/max77620.txt
>>> @@ -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
>>>

2019-02-19 15:21:06

by Rob Herring

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

On Mon, Feb 18, 2019 at 8:07 PM Mark Zhang <[email protected]> wrote:
>
> On 2/19/2019 2:06 AM, Rob Herring wrote:
> > On Tue, Feb 12, 2019 at 12:44 AM Mark Zhang <[email protected]> wrote:
> >>
> >> 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.
>
> 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.

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