Lines Matching +full:lithium +full:- +full:ion
1 // SPDX-License-Identifier: GPL-2.0
4 // fuel-gauge systems for lithium-ion (Li+) batteries
162 return regmap_write(chip->regmap, MAX17040_CMD, chip->data.reset_val); in max17040_reset()
167 level = 32 - level * (chip->quirk_double_soc ? 2 : 1); in max17040_set_low_soc_alert()
168 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_low_soc_alert()
174 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_soc_alert()
180 u16 mask = chip->data.rcomp_bytes == 2 ? in max17040_set_rcomp()
183 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, mask, rcomp); in max17040_set_rcomp()
188 struct chip_data *d = &chip->data; in max17040_raw_vcell_to_uvolts()
190 return (vcell >> d->vcell_shift) * d->vcell_mul / d->vcell_div; in max17040_raw_vcell_to_uvolts()
198 regmap_read(chip->regmap, MAX17040_VCELL, &vcell); in max17040_get_vcell()
207 regmap_read(chip->regmap, MAX17040_SOC, &soc); in max17040_get_soc()
209 return soc >> (chip->quirk_double_soc ? 9 : 8); in max17040_get_soc()
217 ret = regmap_read(chip->regmap, MAX17040_VER, &version); in max17040_get_version()
224 return chip->pdata && chip->pdata->battery_online ? in max17040_get_online()
225 chip->pdata->battery_online() : 1; in max17040_get_online()
230 if (!chip->pdata || !chip->pdata->charger_online in max17040_get_status()
231 || !chip->pdata->charger_enable) in max17040_get_status()
237 if (chip->pdata->charger_online()) in max17040_get_status()
238 if (chip->pdata->charger_enable()) in max17040_get_status()
248 struct device *dev = &chip->client->dev; in max17040_get_of_data()
254 chip->quirk_double_soc = device_property_read_bool(dev, in max17040_get_of_data()
255 "maxim,double-soc"); in max17040_get_of_data()
257 chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP; in max17040_get_of_data()
259 "maxim,alert-low-soc-level", in max17040_get_of_data()
260 &chip->low_soc_alert); in max17040_get_of_data()
262 if (chip->low_soc_alert <= 0 || in max17040_get_of_data()
263 chip->low_soc_alert > (chip->quirk_double_soc ? 16 : 32)) { in max17040_get_of_data()
264 dev_err(dev, "maxim,alert-low-soc-level out of bounds\n"); in max17040_get_of_data()
265 return -EINVAL; in max17040_get_of_data()
269 chip->rcomp = MAX17040_RCOMP_DEFAULT; in max17040_get_of_data()
270 if (rcomp_len == data->rcomp_bytes) { in max17040_get_of_data()
273 chip->rcomp = rcomp_len == 2 ? in max17040_get_of_data()
278 return -EINVAL; in max17040_get_of_data()
286 chip->soc = max17040_get_soc(chip); in max17040_check_changes()
287 chip->status = max17040_get_status(chip); in max17040_check_changes()
292 queue_delayed_work(system_power_efficient_wq, &chip->work, in max17040_queue_work()
300 cancel_delayed_work_sync(&chip->work); in max17040_stop_work()
311 last_soc = chip->soc; in max17040_work()
312 last_status = chip->status; in max17040_work()
316 if (last_soc != chip->soc || last_status != chip->status) in max17040_work()
317 power_supply_changed(chip->battery); in max17040_work()
328 regmap_read(chip->regmap, MAX17040_STATUS, &data); in max17040_handle_soc_alert()
335 // soc change bit -- deassert to mark as handled in max17040_handle_soc_alert()
336 regmap_write(chip->regmap, MAX17040_STATUS, in max17040_handle_soc_alert()
347 if (!(chip->data.has_soc_alert && max17040_handle_soc_alert(chip))) in max17040_thread_handler()
348 dev_warn(&chip->client->dev, "IRQ: Alert battery low level\n"); in max17040_thread_handler()
354 power_supply_changed(chip->battery); in max17040_thread_handler()
357 max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_thread_handler()
364 struct i2c_client *client = chip->client; in max17040_enable_alert_irq()
369 ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, in max17040_enable_alert_irq()
371 chip->battery->desc->name, chip); in max17040_enable_alert_irq()
397 if ((val->intval < 1) || in max17040_set_property()
398 (val->intval > (chip->quirk_double_soc ? 16 : 32))) { in max17040_set_property()
399 ret = -EINVAL; in max17040_set_property()
402 ret = max17040_set_low_soc_alert(chip, val->intval); in max17040_set_property()
403 chip->low_soc_alert = val->intval; in max17040_set_property()
406 ret = -EINVAL; in max17040_set_property()
420 val->intval = max17040_get_status(chip); in max17040_get_property()
423 val->intval = max17040_get_online(chip); in max17040_get_property()
426 val->intval = max17040_get_vcell(chip); in max17040_get_property()
429 val->intval = max17040_get_soc(chip); in max17040_get_property()
432 val->intval = chip->low_soc_alert; in max17040_get_property()
435 return -EINVAL; in max17040_get_property()
468 struct i2c_adapter *adapter = client->adapter; in max17040_probe()
476 return -EIO; in max17040_probe()
478 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in max17040_probe()
480 return -ENOMEM; in max17040_probe()
482 chip->client = client; in max17040_probe()
483 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap); in max17040_probe()
484 chip->pdata = client->dev.platform_data; in max17040_probe()
485 if (IS_ERR(chip->regmap)) in max17040_probe()
486 return PTR_ERR(chip->regmap); in max17040_probe()
487 chip_id = (enum chip_id) id->driver_data; in max17040_probe()
488 if (client->dev.of_node) { in max17040_probe()
493 of_device_get_match_data(&client->dev); in max17040_probe()
495 chip->data = max17040_family[chip_id]; in max17040_probe()
500 chip->battery = devm_power_supply_register(&client->dev, in max17040_probe()
502 if (IS_ERR(chip->battery)) { in max17040_probe()
503 dev_err(&client->dev, "failed: power supply register\n"); in max17040_probe()
504 return PTR_ERR(chip->battery); in max17040_probe()
510 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret); in max17040_probe()
515 max17040_set_rcomp(chip, chip->rcomp); in max17040_probe()
518 if (client->irq && chip->data.has_low_soc_alert) { in max17040_probe()
519 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_probe()
521 dev_err(&client->dev, in max17040_probe()
529 if (client->irq && chip->data.has_soc_alert) { in max17040_probe()
532 dev_err(&client->dev, in max17040_probe()
539 INIT_DEFERRABLE_WORK(&chip->work, max17040_work); in max17040_probe()
540 ret = devm_add_action(&client->dev, max17040_stop_work, chip); in max17040_probe()
549 client->irq = 0; in max17040_probe()
550 dev_warn(&client->dev, in max17040_probe()
565 if (client->irq && chip->data.has_soc_alert) in max17040_suspend()
569 cancel_delayed_work(&chip->work); in max17040_suspend()
571 if (client->irq && device_may_wakeup(dev)) in max17040_suspend()
572 enable_irq_wake(client->irq); in max17040_suspend()
582 if (client->irq && device_may_wakeup(dev)) in max17040_resume()
583 disable_irq_wake(client->irq); in max17040_resume()
585 if (client->irq && chip->data.has_soc_alert) in max17040_resume()
606 { "max77836-battery", ID_MAX17043 },
620 { .compatible = "maxim,max77836-battery", .data = (void *) ID_MAX17043 },