Lines Matching +full:constant +full:- +full:uvolt

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
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;
266 ret = max77693_get_charger_state(regmap, &val->intval);
269 ret = max77693_get_charge_type(regmap, &val->intval);
272 ret = max77693_get_battery_health(regmap, &val->intval);
275 ret = max77693_get_present(regmap, &val->intval);
278 ret = max77693_get_online(regmap, &val->intval);
281 ret = max77693_get_input_current_limit(regmap, &val->intval);
284 ret = max77693_get_fast_charge_current(regmap, &val->intval);
287 val->strval = max77693_charger_model;
290 val->strval = max77693_charger_manufacturer;
293 return -EINVAL;
333 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_01,
343 val = 4 + (data - 1) * 2;
360 * 0x00 - disable
361 * 0x01 - 4h
362 * 0x02 - 6h
364 * 0x07 - 16h
369 data = (hours - 4) / 2 + 1;
376 return -EINVAL;
380 return regmap_update_bits(chg->max77693->regmap,
399 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03,
421 return -EINVAL;
424 data = (uamp - 100000) / 25000;
431 return regmap_update_bits(chg->max77693->regmap,
450 ret = regmap_read(chg->max77693->regmap, MAX77693_CHG_REG_CHG_CNFG_03,
469 return -EINVAL;
474 return regmap_update_bits(chg->max77693->regmap,
491 unsigned int uvolt)
496 * 0x00 - 3.650 V
497 * 0x01 - 3.675 V
499 * 0x1b - 4.325 V
500 * 0x1c - 4.340 V
501 * 0x1d - 4.350 V
502 * 0x1e - 4.375 V
503 * 0x1f - 4.400 V
505 if (uvolt >= 3650000 && uvolt < 4340000)
506 data = (uvolt - 3650000) / 25000;
507 else if (uvolt >= 4340000 && uvolt < 4350000)
509 else if (uvolt >= 4350000 && uvolt <= 4400000)
510 data = 0x1d + (uvolt - 4350000) / 25000;
512 dev_err(chg->dev, "Wrong value for charging constant voltage\n");
513 return -EINVAL;
518 dev_dbg(chg->dev, "Charging constant voltage: %u (0x%x)\n", uvolt,
521 return regmap_update_bits(chg->max77693->regmap,
527 unsigned int uvolt)
531 if (uvolt < 3000000 || uvolt > 3700000) {
532 dev_err(chg->dev, "Wrong value for minimum system regulation voltage\n");
533 return -EINVAL;
536 data = (uvolt - 3000000) / 100000;
540 dev_dbg(chg->dev, "Minimum system regulation voltage: %u (0x%x)\n",
541 uvolt, data);
543 return regmap_update_bits(chg->max77693->regmap,
558 data = (cels - 70) / 15;
561 dev_err(chg->dev, "Wrong value for thermal regulation loop temperature\n");
562 return -EINVAL;
567 dev_dbg(chg->dev, "Thermal regulation loop temperature: %u (0x%x)\n",
570 return regmap_update_bits(chg->max77693->regmap,
581 dev_err(chg->dev, "Wrong value for battery overcurrent\n");
582 return -EINVAL;
586 data = ((uamp - 2000000) / 250000) + 1;
592 dev_dbg(chg->dev, "Battery overcurrent: %u (0x%x)\n", uamp, data);
594 return regmap_update_bits(chg->max77693->regmap,
600 unsigned int uvolt)
604 switch (uvolt) {
611 data = ((uvolt - 4700000) / 100000) + 1;
614 dev_err(chg->dev, "Wrong value for charge input voltage regulation threshold\n");
615 return -EINVAL;
620 dev_dbg(chg->dev, "Charge input voltage regulation threshold: %u (0x%x)\n",
621 uvolt, data);
623 return regmap_update_bits(chg->max77693->regmap,
638 ret = regmap_update_bits(chg->max77693->regmap,
642 dev_err(chg->dev, "Error unlocking registers: %d\n", ret);
659 ret = max77693_set_constant_volt(chg, chg->constant_volt);
663 ret = max77693_set_min_system_volt(chg, chg->min_system_volt);
668 chg->thermal_regulation_temp);
672 ret = max77693_set_batttery_overcurrent(chg, chg->batttery_overcurrent);
677 chg->charge_input_threshold_volt);
683 struct device_node *np = dev->of_node;
687 return -EINVAL;
690 if (of_property_read_u32(np, "maxim,constant-microvolt",
691 &chg->constant_volt))
692 chg->constant_volt = DEFAULT_CONSTANT_VOLT;
694 if (of_property_read_u32(np, "maxim,min-system-microvolt",
695 &chg->min_system_volt))
696 chg->min_system_volt = DEFAULT_MIN_SYSTEM_VOLT;
698 if (of_property_read_u32(np, "maxim,thermal-regulation-celsius",
699 &chg->thermal_regulation_temp))
700 chg->thermal_regulation_temp = DEFAULT_THERMAL_REGULATION_TEMP;
702 if (of_property_read_u32(np, "maxim,battery-overcurrent-microamp",
703 &chg->batttery_overcurrent))
704 chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT;
706 if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt",
707 &chg->charge_input_threshold_volt))
708 chg->charge_input_threshold_volt =
724 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
727 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL);
729 return -ENOMEM;
732 chg->dev = &pdev->dev;
733 chg->max77693 = max77693;
735 ret = max77693_dt_init(&pdev->dev, chg);
745 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer);
747 dev_err(&pdev->dev, "failed: create fast charge timer sysfs entry\n");
751 ret = device_create_file(&pdev->dev,
754 dev_err(&pdev->dev, "failed: create top off current sysfs entry\n");
758 ret = device_create_file(&pdev->dev, &dev_attr_top_off_timer);
760 dev_err(&pdev->dev, "failed: create top off timer sysfs entry\n");
764 chg->charger = devm_power_supply_register(&pdev->dev,
767 if (IS_ERR(chg->charger)) {
768 dev_err(&pdev->dev, "failed: power supply register\n");
769 ret = PTR_ERR(chg->charger);
776 device_remove_file(&pdev->dev, &dev_attr_top_off_timer);
777 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current);
778 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
785 device_remove_file(&pdev->dev, &dev_attr_top_off_timer);
786 device_remove_file(&pdev->dev, &dev_attr_top_off_threshold_current);
787 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer);
791 { "max77693-charger", 0, },
798 .name = "max77693-charger",