Lines Matching +full:li +full:- +full:ion
1 // SPDX-License-Identifier: GPL-2.0
4 // fuel-gauge systems for lithium-ion (Li+) batteries
160 return regmap_write(chip->regmap, MAX17040_CMD, chip->data.reset_val); in max17040_reset()
165 level = 32 - level * (chip->quirk_double_soc ? 2 : 1); in max17040_set_low_soc_alert()
166 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_low_soc_alert()
172 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_soc_alert()
178 u16 mask = chip->data.rcomp_bytes == 2 ? in max17040_set_rcomp()
181 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, mask, rcomp); in max17040_set_rcomp()
186 struct chip_data *d = &chip->data; in max17040_raw_vcell_to_uvolts()
188 return (vcell >> d->vcell_shift) * d->vcell_mul / d->vcell_div; in max17040_raw_vcell_to_uvolts()
196 regmap_read(chip->regmap, MAX17040_VCELL, &vcell); in max17040_get_vcell()
205 regmap_read(chip->regmap, MAX17040_SOC, &soc); in max17040_get_soc()
207 return soc >> (chip->quirk_double_soc ? 9 : 8); in max17040_get_soc()
215 ret = regmap_read(chip->regmap, MAX17040_VER, &version); in max17040_get_version()
227 struct device *dev = &chip->client->dev; in max17040_get_of_data()
233 chip->quirk_double_soc = device_property_read_bool(dev, in max17040_get_of_data()
234 "maxim,double-soc"); in max17040_get_of_data()
236 chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP; in max17040_get_of_data()
238 "maxim,alert-low-soc-level", in max17040_get_of_data()
239 &chip->low_soc_alert); in max17040_get_of_data()
241 if (chip->low_soc_alert <= 0 || in max17040_get_of_data()
242 chip->low_soc_alert > (chip->quirk_double_soc ? 16 : 32)) { in max17040_get_of_data()
243 dev_err(dev, "maxim,alert-low-soc-level out of bounds\n"); in max17040_get_of_data()
244 return -EINVAL; in max17040_get_of_data()
248 chip->rcomp = MAX17040_RCOMP_DEFAULT; in max17040_get_of_data()
249 if (rcomp_len == data->rcomp_bytes) { in max17040_get_of_data()
252 chip->rcomp = rcomp_len == 2 ? rcomp[0] << 8 | rcomp[1] : in max17040_get_of_data()
256 return -EINVAL; in max17040_get_of_data()
264 chip->soc = max17040_get_soc(chip); in max17040_check_changes()
269 queue_delayed_work(system_power_efficient_wq, &chip->work, in max17040_queue_work()
277 cancel_delayed_work_sync(&chip->work); in max17040_stop_work()
288 last_soc = chip->soc; in max17040_work()
292 if (last_soc != chip->soc) in max17040_work()
293 power_supply_changed(chip->battery); in max17040_work()
304 regmap_read(chip->regmap, MAX17040_STATUS, &data); in max17040_handle_soc_alert()
311 // soc change bit -- deassert to mark as handled in max17040_handle_soc_alert()
312 regmap_write(chip->regmap, MAX17040_STATUS, in max17040_handle_soc_alert()
323 if (!(chip->data.has_soc_alert && max17040_handle_soc_alert(chip))) in max17040_thread_handler()
324 dev_warn(&chip->client->dev, "IRQ: Alert battery low level\n"); in max17040_thread_handler()
330 power_supply_changed(chip->battery); in max17040_thread_handler()
333 max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_thread_handler()
340 struct i2c_client *client = chip->client; in max17040_enable_alert_irq()
343 ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, in max17040_enable_alert_irq()
345 chip->battery->desc->name, chip); in max17040_enable_alert_irq()
371 if ((val->intval < 1) || in max17040_set_property()
372 (val->intval > (chip->quirk_double_soc ? 16 : 32))) { in max17040_set_property()
373 ret = -EINVAL; in max17040_set_property()
376 ret = max17040_set_low_soc_alert(chip, val->intval); in max17040_set_property()
377 chip->low_soc_alert = val->intval; in max17040_set_property()
380 ret = -EINVAL; in max17040_set_property()
395 val->intval = max17040_get_online(chip); in max17040_get_property()
398 val->intval = max17040_get_vcell(chip); in max17040_get_property()
401 val->intval = max17040_get_soc(chip); in max17040_get_property()
404 val->intval = chip->low_soc_alert; in max17040_get_property()
410 if (!chip->channel_temp) in max17040_get_property()
411 return -ENODATA; in max17040_get_property()
413 iio_read_channel_processed_scale(chip->channel_temp, in max17040_get_property()
414 &val->intval, 10); in max17040_get_property()
417 return -EINVAL; in max17040_get_property()
452 struct i2c_adapter *adapter = client->adapter; in max17040_probe()
460 return -EIO; in max17040_probe()
462 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in max17040_probe()
464 return -ENOMEM; in max17040_probe()
466 chip->client = client; in max17040_probe()
467 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap); in max17040_probe()
468 if (IS_ERR(chip->regmap)) in max17040_probe()
469 return PTR_ERR(chip->regmap); in max17040_probe()
470 chip_id = (enum chip_id) id->driver_data; in max17040_probe()
471 if (client->dev.of_node) { in max17040_probe()
475 chip_id = (uintptr_t)of_device_get_match_data(&client->dev); in max17040_probe()
477 chip->data = max17040_family[chip_id]; in max17040_probe()
483 chip->channel_temp = devm_iio_channel_get(&client->dev, "temp"); in max17040_probe()
484 if (IS_ERR(chip->channel_temp)) { in max17040_probe()
485 ret = PTR_ERR(chip->channel_temp); in max17040_probe()
486 if (ret != -ENODEV) in max17040_probe()
487 return dev_err_probe(&client->dev, PTR_ERR(chip->channel_temp), in max17040_probe()
490 chip->channel_temp = NULL; in max17040_probe()
493 chip->battery = devm_power_supply_register(&client->dev, in max17040_probe()
495 if (IS_ERR(chip->battery)) { in max17040_probe()
496 dev_err(&client->dev, "failed: power supply register\n"); in max17040_probe()
497 return PTR_ERR(chip->battery); in max17040_probe()
503 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret); in max17040_probe()
508 max17040_set_rcomp(chip, chip->rcomp); in max17040_probe()
511 if (client->irq && chip->data.has_low_soc_alert) { in max17040_probe()
512 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_probe()
514 dev_err(&client->dev, in max17040_probe()
522 if (client->irq && chip->data.has_soc_alert) { in max17040_probe()
525 dev_err(&client->dev, in max17040_probe()
532 INIT_DEFERRABLE_WORK(&chip->work, max17040_work); in max17040_probe()
533 ret = devm_add_action(&client->dev, max17040_stop_work, chip); in max17040_probe()
542 client->irq = 0; in max17040_probe()
543 dev_warn(&client->dev, in max17040_probe()
558 if (client->irq && chip->data.has_soc_alert) in max17040_suspend()
562 cancel_delayed_work(&chip->work); in max17040_suspend()
564 if (client->irq && device_may_wakeup(dev)) in max17040_suspend()
565 enable_irq_wake(client->irq); in max17040_suspend()
575 if (client->irq && device_may_wakeup(dev)) in max17040_resume()
576 disable_irq_wake(client->irq); in max17040_resume()
578 if (client->irq && chip->data.has_soc_alert) in max17040_resume()
599 { "max77836-battery", ID_MAX17043 },
613 { .compatible = "maxim,max77836-battery", .data = (void *) ID_MAX17043 },