mfd: max77620: Add backup battery charger support
Subsystems (2)
PATCH 1/2 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(+)
drivers/mfd/max77620.c +80 -0
@@ -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,backup-battery-charging-current" , &pval); + charging_current = (!ret) ? pval :50 ; + + ret =of_property_read_u32 (np, +"maxim,backup-battery-charging-voltage" , &pval); + charging_voltage = (!ret) ? pval :2500000 ; + charging_voltage /=1000 ; + + ret =of_property_read_u32 (np, +"maxim,backup-battery-output-resister" , &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
PATCH 2/2 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 | 57 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
drivers/mfd/max77620.c +56 -1
@@ -474,6 +474,57 @@ 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; +struct device_node *np; +bool pval; +u8 mask =0 ; +u8 val =0 ; +int ret; + + np =of_get_child_by_name (dev->of_node,"low-battery-monitor" ); +if (!np) { +dev_info (dev,"Low battery monitoring support disabled\n" ); +return 0 ; + } + + pval =of_property_read_bool (np,"maxim,low-battery-dac-enable" ); +if (pval) { + mask |=MAX77620_CNFGGLBL1_LBDAC_EN ; + val |=MAX77620_CNFGGLBL1_LBDAC_EN ; + } + + pval =of_property_read_bool (np,"maxim,low-battery-dac-disable" ); +if (pval) + mask |=MAX77620_CNFGGLBL1_LBDAC_EN ; + + pval =of_property_read_bool (np,"maxim,low-battery-shutdown-enable" ); +if (pval) { + mask |=MAX77620_CNFGGLBL1_MPPLD ; + val |=MAX77620_CNFGGLBL1_MPPLD ; + } + + pval =of_property_read_bool (np,"maxim,low-battery-shutdown-disable" ); +if (pval) + mask |=MAX77620_CNFGGLBL1_MPPLD ; + + pval =of_property_read_bool (np,"maxim,low-battery-reset-enable" ); +if (pval) { + mask |=MAX77620_CNFGGLBL1_LBRSTEN ; + val |=MAX77620_CNFGGLBL1_LBRSTEN ; + } + + pval =of_property_read_bool (np,"maxim,low-battery-reset-disable" ); +if (pval) + mask |=MAX77620_CNFGGLBL1_LBRSTEN ; + + 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 +614,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