Lines Matching +full:charge +full:- +full:input +full:- +full:threshold +full:- +full:microvolt

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
148 * Took longer to charge than expected, charging suspended. in max77693_get_battery_health()
215 struct regmap *regmap = chg->max77693->regmap; in max77693_charger_get_property()
220 ret = max77693_get_charger_state(regmap, &val->intval); in max77693_charger_get_property()
223 ret = max77693_get_charge_type(regmap, &val->intval); in max77693_charger_get_property()
226 ret = max77693_get_battery_health(regmap, &val->intval); in max77693_charger_get_property()
229 ret = max77693_get_present(regmap, &val->intval); in max77693_charger_get_property()
232 ret = max77693_get_online(regmap, &val->intval); in max77693_charger_get_property()
235 val->strval = max77693_charger_model; in max77693_charger_get_property()
238 val->strval = max77693_charger_manufacturer; in max77693_charger_get_property()
241 return -EINVAL; in max77693_charger_get_property()
281 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_01, in fast_charge_timer_show()
291 val = 4 + (data - 1) * 2; in fast_charge_timer_show()
308 * 0x00 - disable in max77693_set_fast_charge_timer()
309 * 0x01 - 4h in max77693_set_fast_charge_timer()
310 * 0x02 - 6h in max77693_set_fast_charge_timer()
312 * 0x07 - 16h in max77693_set_fast_charge_timer()
317 data = (hours - 4) / 2 + 1; in max77693_set_fast_charge_timer()
324 return -EINVAL; in max77693_set_fast_charge_timer()
328 return regmap_update_bits(chg->max77693->regmap, in max77693_set_fast_charge_timer()
347 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, in top_off_threshold_current_show()
369 return -EINVAL; in max77693_set_top_off_threshold_current()
372 data = (uamp - 100000) / 25000; in max77693_set_top_off_threshold_current()
379 return regmap_update_bits(chg->max77693->regmap, in max77693_set_top_off_threshold_current()
398 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03, in top_off_timer_show()
417 return -EINVAL; in max77693_set_top_off_timer()
422 return regmap_update_bits(chg->max77693->regmap, in max77693_set_top_off_timer()
444 * 0x00 - 3.650 V in max77693_set_constant_volt()
445 * 0x01 - 3.675 V in max77693_set_constant_volt()
447 * 0x1b - 4.325 V in max77693_set_constant_volt()
448 * 0x1c - 4.340 V in max77693_set_constant_volt()
449 * 0x1d - 4.350 V in max77693_set_constant_volt()
450 * 0x1e - 4.375 V in max77693_set_constant_volt()
451 * 0x1f - 4.400 V in max77693_set_constant_volt()
454 data = (uvolt - 3650000) / 25000; in max77693_set_constant_volt()
458 data = 0x1d + (uvolt - 4350000) / 25000; in max77693_set_constant_volt()
460 dev_err(chg->dev, "Wrong value for charging constant voltage\n"); in max77693_set_constant_volt()
461 return -EINVAL; in max77693_set_constant_volt()
466 dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt, in max77693_set_constant_volt()
469 return regmap_update_bits(chg->max77693->regmap, in max77693_set_constant_volt()
480 dev_err(chg->dev, "Wrong value for minimum system regulation voltage\n"); in max77693_set_min_system_volt()
481 return -EINVAL; in max77693_set_min_system_volt()
484 data = (uvolt - 3000000) / 100000; in max77693_set_min_system_volt()
488 dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n", in max77693_set_min_system_volt()
491 return regmap_update_bits(chg->max77693->regmap, in max77693_set_min_system_volt()
506 data = (cels - 70) / 15; in max77693_set_thermal_regulation_temp()
509 dev_err(chg->dev, "Wrong value for thermal regulation loop temperature\n"); in max77693_set_thermal_regulation_temp()
510 return -EINVAL; in max77693_set_thermal_regulation_temp()
515 dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n", in max77693_set_thermal_regulation_temp()
518 return regmap_update_bits(chg->max77693->regmap, in max77693_set_thermal_regulation_temp()
529 dev_err(chg->dev, "Wrong value for battery overcurrent\n"); in max77693_set_batttery_overcurrent()
530 return -EINVAL; in max77693_set_batttery_overcurrent()
534 data = ((uamp - 2000000) / 250000) + 1; in max77693_set_batttery_overcurrent()
540 dev_dbg(chg->dev, "Battery overcurrent: %u (0x%x)\n", uamp, data); in max77693_set_batttery_overcurrent()
542 return regmap_update_bits(chg->max77693->regmap, in max77693_set_batttery_overcurrent()
559 data = (uvolt - 4700000) / 100000; in max77693_set_charge_input_threshold_volt()
562 dev_err(chg->dev, "Wrong value for charge input voltage regulation threshold\n"); in max77693_set_charge_input_threshold_volt()
563 return -EINVAL; in max77693_set_charge_input_threshold_volt()
568 dev_dbg(chg->dev, "Charge input voltage regulation threshold: %u (0x%x)\n", in max77693_set_charge_input_threshold_volt()
571 return regmap_update_bits(chg->max77693->regmap, in max77693_set_charge_input_threshold_volt()
586 ret = regmap_update_bits(chg->max77693->regmap, in max77693_reg_init()
590 dev_err(chg->dev, "Error unlocking registers: %d\n", ret); in max77693_reg_init()
607 ret = max77693_set_constant_volt(chg, chg->constant_volt); in max77693_reg_init()
611 ret = max77693_set_min_system_volt(chg, chg->min_system_volt); in max77693_reg_init()
616 chg->thermal_regulation_temp); in max77693_reg_init()
620 ret = max77693_set_batttery_overcurrent(chg, chg->batttery_overcurrent); in max77693_reg_init()
625 chg->charge_input_threshold_volt); in max77693_reg_init()
631 struct device_node *np = dev->of_node; in max77693_dt_init()
635 return -EINVAL; in max77693_dt_init()
638 if (of_property_read_u32(np, "maxim,constant-microvolt", in max77693_dt_init()
639 &chg->constant_volt)) in max77693_dt_init()
640 chg->constant_volt = DEFAULT_CONSTANT_VOLT; in max77693_dt_init()
642 if (of_property_read_u32(np, "maxim,min-system-microvolt", in max77693_dt_init()
643 &chg->min_system_volt)) in max77693_dt_init()
644 chg->min_system_volt = DEFAULT_MIN_SYSTEM_VOLT; in max77693_dt_init()
646 if (of_property_read_u32(np, "maxim,thermal-regulation-celsius", in max77693_dt_init()
647 &chg->thermal_regulation_temp)) in max77693_dt_init()
648 chg->thermal_regulation_temp = DEFAULT_THERMAL_REGULATION_TEMP; in max77693_dt_init()
650 if (of_property_read_u32(np, "maxim,battery-overcurrent-microamp", in max77693_dt_init()
651 &chg->batttery_overcurrent)) in max77693_dt_init()
652 chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT; in max77693_dt_init()
654 if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt", in max77693_dt_init()
655 &chg->charge_input_threshold_volt)) in max77693_dt_init()
656 chg->charge_input_threshold_volt = in max77693_dt_init()
672 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); in max77693_charger_probe()
675 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); in max77693_charger_probe()
677 return -ENOMEM; in max77693_charger_probe()
680 chg->dev = &pdev->dev; in max77693_charger_probe()
681 chg->max77693 = max77693; in max77693_charger_probe()
683 ret = max77693_dt_init(&pdev->dev, chg); in max77693_charger_probe()
693 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_probe()
695 dev_err(&pdev->dev, "failed: create fast charge timer sysfs entry\n"); in max77693_charger_probe()
699 ret = device_create_file(&pdev->dev, in max77693_charger_probe()
702 dev_err(&pdev->dev, "failed: create top off current sysfs entry\n"); in max77693_charger_probe()
706 ret = device_create_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_probe()
708 dev_err(&pdev->dev, "failed: create top off timer sysfs entry\n"); in max77693_charger_probe()
712 chg->charger = power_supply_register(&pdev->dev, in max77693_charger_probe()
715 if (IS_ERR(chg->charger)) { in max77693_charger_probe()
716 dev_err(&pdev->dev, "failed: power supply register\n"); in max77693_charger_probe()
717 ret = PTR_ERR(chg->charger); in max77693_charger_probe()
724 device_remove_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_probe()
725 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); in max77693_charger_probe()
726 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_probe()
735 device_remove_file(&pdev->dev, &dev_attr_top_off_timer); in max77693_charger_remove()
736 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current); in max77693_charger_remove()
737 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max77693_charger_remove()
739 power_supply_unregister(chg->charger); in max77693_charger_remove()
745 { "max77693-charger", 0, },
752 .name = "max77693-charger",