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

1 // SPDX-License-Identifier: GPL-2.0+
3 // max14577_charger.c - Battery charger driver for the Maxim 14577/77836
11 #include <linux/mfd/max14577-private.h>
49 struct regmap *rmap = chg->max14577->regmap; in max14577_get_charger_state()
55 * - CHGCTRL2/MBCHOSTEN == 1 in max14577_get_charger_state()
56 * - STATUS2/CGMBC == 1 in max14577_get_charger_state()
59 * - handle FULL after Top-off timer (EOC register may be off in max14577_get_charger_state()
61 * - handle properly dead-battery charging (respect timer) in max14577_get_charger_state()
62 * - handle timers (fast-charge and prequal) /MBCCHGERR/ in max14577_get_charger_state()
78 /* Charger or USB-cable is connected */ in max14577_get_charger_state()
94 * - POWER_SUPPLY_CHARGE_TYPE_NONE
95 * - POWER_SUPPLY_CHARGE_TYPE_FAST
105 * "When the battery is fully charged, the 30-minute (typ) in max14577_get_charge_type()
106 * top-off timer starts. The device continues to trickle in max14577_get_charge_type()
107 * charge the battery until the top-off timer runs out." in max14577_get_charge_type()
123 struct regmap *rmap = chg->max14577->regmap; in max14577_get_online()
133 chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); in max14577_get_online()
156 * - POWER_SUPPLY_HEALTH_DEAD
157 * - POWER_SUPPLY_HEALTH_OVERVOLTAGE
158 * - POWER_SUPPLY_HEALTH_GOOD
162 struct regmap *rmap = chg->max14577->regmap; in max14577_get_battery_health()
172 chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); in max14577_get_battery_health()
213 reg_data = hours - 3; in max14577_set_fast_charge_timer()
220 dev_err(chg->dev, "Wrong value for Fast-Charge Timer: %lu\n", in max14577_set_fast_charge_timer()
222 return -EINVAL; in max14577_set_fast_charge_timer()
226 return max14577_update_reg(chg->max14577->regmap, in max14577_set_fast_charge_timer()
231 unsigned int uvolt) in max14577_init_constant_voltage() argument
235 if (uvolt < MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN || in max14577_init_constant_voltage()
236 uvolt > MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) in max14577_init_constant_voltage()
237 return -EINVAL; in max14577_init_constant_voltage()
239 if (uvolt == 4200000) in max14577_init_constant_voltage()
241 else if (uvolt == MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) in max14577_init_constant_voltage()
243 else if (uvolt <= 4280000) { in max14577_init_constant_voltage()
244 unsigned int val = uvolt; in max14577_init_constant_voltage()
246 val -= MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN; in max14577_init_constant_voltage()
248 if (uvolt <= 4180000) in max14577_init_constant_voltage()
253 return -EINVAL; in max14577_init_constant_voltage()
257 return max14577_write_reg(chg->max14577->regmap, in max14577_init_constant_voltage()
267 switch (chg->max14577->dev_type) { in max14577_init_eoc()
270 return -EINVAL; /* Requested current is too low */ in max14577_init_eoc()
278 uamp = min(uamp, 100000U) - 50000U; in max14577_init_eoc()
286 return -EINVAL; /* Requested current is too low */ in max14577_init_eoc()
289 uamp -= MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN; in max14577_init_eoc()
296 return max14577_update_reg(chg->max14577->regmap, in max14577_init_eoc()
307 &maxim_charger_currents[chg->max14577->dev_type]; in max14577_init_fast_charge()
311 dev_err(chg->dev, "Wrong value for fast charge: %u\n", uamp); in max14577_init_fast_charge()
315 return max14577_update_reg(chg->max14577->regmap, in max14577_init_fast_charge()
328 struct regmap *rmap = chg->max14577->regmap; in max14577_charger_reg_init()
333 * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0) in max14577_charger_reg_init()
334 * Charger-Detection Enable, default on (set CHGDETEN to 1) in max14577_charger_reg_init()
343 * Wall-Adapter Rapid Charge, default on in max14577_charger_reg_init()
344 * Battery-Charger, default on in max14577_charger_reg_init()
354 ret = max14577_init_constant_voltage(chg, chg->pdata->constant_uvolt); in max14577_charger_reg_init()
358 ret = max14577_init_eoc(chg, chg->pdata->eoc_uamp); in max14577_charger_reg_init()
362 ret = max14577_init_fast_charge(chg, chg->pdata->fast_charge_uamp); in max14577_charger_reg_init()
371 /* Initialize Overvoltage-Protection Threshold */ in max14577_charger_reg_init()
372 switch (chg->pdata->ovp_uvolt) { in max14577_charger_reg_init()
379 reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000; in max14577_charger_reg_init()
382 dev_err(chg->dev, "Wrong value for OVP: %u\n", in max14577_charger_reg_init()
383 chg->pdata->ovp_uvolt); in max14577_charger_reg_init()
384 return -EINVAL; in max14577_charger_reg_init()
404 [MAXIM_DEVICE_TYPE_UNKNOWN] = "MAX14577-like",
419 ret = max14577_get_charger_state(chg, &val->intval); in max14577_charger_get_property()
422 ret = max14577_get_charge_type(chg, &val->intval); in max14577_charger_get_property()
425 ret = max14577_get_battery_health(chg, &val->intval); in max14577_charger_get_property()
428 ret = max14577_get_present(chg, &val->intval); in max14577_charger_get_property()
431 ret = max14577_get_online(chg, &val->intval); in max14577_charger_get_property()
435 val->strval = model_names[chg->max14577->dev_type]; in max14577_charger_get_property()
438 val->strval = manufacturer; in max14577_charger_get_property()
441 return -EINVAL; in max14577_charger_get_property()
448 .name = "max14577-charger",
460 struct device_node *np = pdev->dev.of_node; in max14577_charger_dt_init()
464 dev_err(&pdev->dev, "No charger OF node\n"); in max14577_charger_dt_init()
465 return ERR_PTR(-EINVAL); in max14577_charger_dt_init()
468 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in max14577_charger_dt_init()
470 return ERR_PTR(-ENOMEM); in max14577_charger_dt_init()
472 ret = of_property_read_u32(np, "maxim,constant-uvolt", in max14577_charger_dt_init()
473 &pdata->constant_uvolt); in max14577_charger_dt_init()
475 dev_err(&pdev->dev, "Cannot parse maxim,constant-uvolt field from DT\n"); in max14577_charger_dt_init()
479 ret = of_property_read_u32(np, "maxim,fast-charge-uamp", in max14577_charger_dt_init()
480 &pdata->fast_charge_uamp); in max14577_charger_dt_init()
482 dev_err(&pdev->dev, "Cannot parse maxim,fast-charge-uamp field from DT\n"); in max14577_charger_dt_init()
486 ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp); in max14577_charger_dt_init()
488 dev_err(&pdev->dev, "Cannot parse maxim,eoc-uamp field from DT\n"); in max14577_charger_dt_init()
492 ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt); in max14577_charger_dt_init()
494 dev_err(&pdev->dev, "Cannot parse maxim,ovp-uvolt field from DT\n"); in max14577_charger_dt_init()
516 ret = max14577_read_reg(chg->max14577->regmap, MAX14577_REG_CHGCTRL1, in show_fast_charge_timer()
563 struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); in max14577_charger_probe()
566 chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); in max14577_charger_probe()
568 return -ENOMEM; in max14577_charger_probe()
571 chg->dev = &pdev->dev; in max14577_charger_probe()
572 chg->max14577 = max14577; in max14577_charger_probe()
574 chg->pdata = max14577_charger_dt_init(pdev); in max14577_charger_probe()
575 if (IS_ERR_OR_NULL(chg->pdata)) in max14577_charger_probe()
576 return PTR_ERR(chg->pdata); in max14577_charger_probe()
582 ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); in max14577_charger_probe()
584 dev_err(&pdev->dev, "failed: create sysfs entry\n"); in max14577_charger_probe()
589 chg->charger = power_supply_register(&pdev->dev, &max14577_charger_desc, in max14577_charger_probe()
591 if (IS_ERR(chg->charger)) { in max14577_charger_probe()
592 dev_err(&pdev->dev, "failed: power supply register\n"); in max14577_charger_probe()
593 ret = PTR_ERR(chg->charger); in max14577_charger_probe()
604 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max14577_charger_probe()
613 device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); in max14577_charger_remove()
614 power_supply_unregister(chg->charger); in max14577_charger_remove()
620 { "max14577-charger", MAXIM_DEVICE_TYPE_MAX14577, },
621 { "max77836-charger", MAXIM_DEVICE_TYPE_MAX77836, },
627 { .compatible = "maxim,max14577-charger",
629 { .compatible = "maxim,max77836-charger",
637 .name = "max14577-charger",