Lines Matching +full:thermal +full:- +full:regulation +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0+
3 // max77693_charger.c - Battery charger driver for the Maxim 77693
13 #include <linux/mfd/max77693-common.h>
14 #include <linux/mfd/max77693-private.h>
16 #define MAX77693_CHARGER_NAME "max77693-charger"
88 * Top-off: trickle or fast? In top-off the current varies between in max77693_get_charge_type()
118 * - POWER_SUPPLY_HEALTH_DEAD
119 * - POWER_SUPPLY_HEALTH_GOOD
120 * - POWER_SUPPLY_HEALTH_OVERVOLTAGE
121 * - POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
122 * - POWER_SUPPLY_HEALTH_UNKNOWN
123 * - POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
202 * - CHGIN limit, which limits the input current from the external charger;
203 * - Fast charge current limit, which limits the current going to the battery.
261 struct regmap *regmap = chg->max77693->regmap; in max77693_charger_get_property()
266 ret = max77693_get_charger_state(regmap, &val->intval); in max77693_charger_get_property()
269 ret = max77693_get_charge_type(regmap, &val->intval); in max77693_charger_get_property()
272 ret = max77693_get_battery_health(regmap, &val->intval); in max77693_charger_get_property()
275 ret = max77693_get_present(regmap, &val->intval); in max77693_charger_get_property()
278 ret = max77693_get_online(regmap, &val->intval); in max77693_charger_get_property()
281 ret = max77693_get_input_current_limit(regmap, &val->intval); in max77693_charger_get_property()
284 ret = max77693_get_fast_charge_current(regmap, &val->intval); in max77693_charger_get_property()
287 val->strval = max77693_charger_model; in max77693_charger_get_property()
290 val->strval = max77693_charger_manufacturer; in max77693_charger_get_property()
293 return -EINVAL; in max77693_charger_get_property()
333 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_01, in fast_charge_timer_show()
343 val = 4 + (data - 1) * 2; in fast_charge_timer_show()
360 * 0x00 - disable in max77693_set_fast_charge_timer()
361 * 0x01 - 4h in max77693_set_fast_charge_timer()
362 * 0x02 - 6h in max77693_set_fast_charge_timer()
364 * 0x07 - 16h in max77693_set_fast_charge_timer()
369 data = (hours - 4) / 2 + 1; in max77693_set_fast_charge_timer()
376 return -EINVAL; in max77693_set_fast_charge_timer()
380 return regmap_update_bits(chg->max77693->regmap, in max77693_set_fast_charge_timer()
399 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, in top_off_threshold_current_show()
421 return -EINVAL; in max77693_set_top_off_threshold_current()
424 data = (uamp - 100000) / 25000; in max77693_set_top_off_threshold_current()
431 return regmap_update_bits(chg->max77693->regmap, in max77693_set_top_off_threshold_current()
450 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, in top_off_timer_show()
469 return -EINVAL; in max77693_set_top_off_timer()
474 return regmap_update_bits(chg->max77693->regmap, in max77693_set_top_off_timer()
496 * 0x00 - 3.650 V in max77693_set_constant_volt()
497 * 0x01 - 3.675 V in max77693_set_constant_volt()
499 * 0x1b - 4.325 V in max77693_set_constant_volt()
500 * 0x1c - 4.340 V in max77693_set_constant_volt()
501 * 0x1d - 4.350 V in max77693_set_constant_volt()
502 * 0x1e - 4.375 V in max77693_set_constant_volt()
503 * 0x1f - 4.400 V in max77693_set_constant_volt()
506 data = (uvolt - 3650000) / 25000; in max77693_set_constant_volt()
510 data = 0x1d + (uvolt - 4350000) / 25000; in max77693_set_constant_volt()
512 dev_err(chg->dev, "Wrong value for charging constant voltage\n"); in max77693_set_constant_volt()
513 return -EINVAL; in max77693_set_constant_volt()
518 dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt, in max77693_set_constant_volt()
521 return regmap_update_bits(chg->max77693->regmap, in max77693_set_constant_volt()
532 dev_err(chg->dev, "Wrong value for minimum system regulation voltage\n"); in max77693_set_min_system_volt()
533 return -EINVAL; in max77693_set_min_system_volt()
536 data = (uvolt - 3000000) / 100000; in max77693_set_min_system_volt()
540 dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n", in max77693_set_min_system_volt()
543 return regmap_update_bits(chg->max77693->regmap, in max77693_set_min_system_volt()
558 data = (cels - 70) / 15; in max77693_set_thermal_regulation_temp()
561 dev_err(chg->dev, "Wrong value for thermal regulation loop temperature\n"); in max77693_set_thermal_regulation_temp()
562 return -EINVAL; in max77693_set_thermal_regulation_temp()
567 dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n", in max77693_set_thermal_regulation_temp()
570 return regmap_update_bits(chg->max77693->regmap, in max77693_set_thermal_regulation_temp()
581 dev_err(chg->dev, "Wrong value for battery overcurrent\n"); in max77693_set_batttery_overcurrent()
582 return -EINVAL; in max77693_set_batttery_overcurrent()
586 data = ((uamp - 2000000) / 250000) + 1; in max77693_set_batttery_overcurrent()
592 dev_dbg(chg->dev, "Battery overcurrent: %u (0x%x)\n", uamp, data); in max77693_set_batttery_overcurrent()
594 return regmap_update_bits(chg->max77693->regmap, in max77693_set_batttery_overcurrent()
611 data = (uvolt - 4700000) / 100000; in max77693_set_charge_input_threshold_volt()
614 dev_err(chg->dev, "Wrong value for charge input voltage regulation threshold\n"); in max77693_set_charge_input_threshold_volt()
615 return -EINVAL; in max77693_set_charge_input_threshold_volt()
620 dev_dbg(chg->dev, "Charge input voltage regulation threshold: %u (0x%x)\n", in max77693_set_charge_input_threshold_volt()
623 return regmap_update_bits(chg->max77693->regmap, in max77693_set_charge_input_threshold_volt()
638 ret = regmap_update_bits(chg->max77693->regmap, in max77693_reg_init()
642 dev_err(chg->dev, "Error unlocking registers: %d\n", ret); in max77693_reg_init()
659 ret = max77693_set_constant_volt(chg, chg->constant_volt); in max77693_reg_init()
663 ret = max77693_set_min_system_volt(chg, chg->min_system_volt); in max77693_reg_init()
668 chg->thermal_regulation_temp); in max77693_reg_init()
672 ret = max77693_set_batttery_overcurrent(chg, chg->batttery_overcurrent); in max77693_reg_init()
677 chg->charge_input_threshold_volt); in max77693_reg_init()
683 struct device_node *np = dev->of_node; in max77693_dt_init()
687 return -EINVAL; in max77693_dt_init()
690 if (of_property_read_u32(np, "maxim,constant-microvolt", in max77693_dt_init()
691 &chg->constant_volt)) in max77693_dt_init()
692 chg->constant_volt = DEFAULT_CONSTANT_VOLT; in max77693_dt_init()
694 if (of_property_read_u32(np, "maxim,min-system-microvolt", in max77693_dt_init()
695 &chg->min_system_volt)) in max77693_dt_init()
696 chg->min_system_volt = DEFAULT_MIN_SYSTEM_VOLT; in max77693_dt_init()
698 if (of_property_read_u32(np, "maxim,thermal-regulation-celsius", in max77693_dt_init()
699 &chg->thermal_regulation_temp)) in max77693_dt_init()
700 chg->thermal_regulation_temp = DEFAULT_THERMAL_REGULATION_TEMP; in max77693_dt_init()
702 if (of_property_read_u32(np, "maxim,battery-overcurrent-microamp", in max77693_dt_init()
703 &chg->batttery_overcurrent)) in max77693_dt_init()
704 chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT; in max77693_dt_init()
706 if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt", in max77693_dt_init()
707 &chg->charge_input_threshold_volt)) in max77693_dt_init()
708 chg->charge_input_threshold_volt = in max77693_dt_init()
724 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); in max77693_charger_probe()
727 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); in max77693_charger_probe()
729 return -ENOMEM; in max77693_charger_probe()
732 chg->dev = &pdev->dev; in max77693_charger_probe()
733 chg->max77693 = max77693; in max77693_charger_probe()
735 ret = max77693_dt_init(&pdev->dev, chg); in max77693_charger_probe()
745 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_probe()
747 dev_err(&pdev->dev, "failed: create fast charge timer sysfs entry\n"); in max77693_charger_probe()
751 ret = device_create_file(&pdev->dev, in max77693_charger_probe()
754 dev_err(&pdev->dev, "failed: create top off current sysfs entry\n"); in max77693_charger_probe()
758 ret = device_create_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_probe()
760 dev_err(&pdev->dev, "failed: create top off timer sysfs entry\n"); in max77693_charger_probe()
764 chg->charger = devm_power_supply_register(&pdev->dev, in max77693_charger_probe()
767 if (IS_ERR(chg->charger)) { in max77693_charger_probe()
768 dev_err(&pdev->dev, "failed: power supply register\n"); in max77693_charger_probe()
769 ret = PTR_ERR(chg->charger); in max77693_charger_probe()
776 device_remove_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_probe()
777 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); in max77693_charger_probe()
778 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_probe()
785 device_remove_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_remove()
786 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); in max77693_charger_remove()
787 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_remove()
791 { "max77693-charger", 0, },
798 .name = "max77693-charger",