Lines Matching +full:lithium +full:- +full:ion
1 // SPDX-License-Identifier: GPL-2.0
4 // fuel-gauge systems for lithium-ion (Li+) batteries
158 return regmap_write(chip->regmap, MAX17040_CMD, chip->data.reset_val); in max17040_reset()
163 level = 32 - level * (chip->quirk_double_soc ? 2 : 1); in max17040_set_low_soc_alert()
164 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_low_soc_alert()
170 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, in max17040_set_soc_alert()
176 u16 mask = chip->data.rcomp_bytes == 2 ? in max17040_set_rcomp()
179 return regmap_update_bits(chip->regmap, MAX17040_CONFIG, mask, rcomp); in max17040_set_rcomp()
184 struct chip_data *d = &chip->data; in max17040_raw_vcell_to_uvolts()
186 return (vcell >> d->vcell_shift) * d->vcell_mul / d->vcell_div; in max17040_raw_vcell_to_uvolts()
194 regmap_read(chip->regmap, MAX17040_VCELL, &vcell); in max17040_get_vcell()
203 regmap_read(chip->regmap, MAX17040_SOC, &soc); in max17040_get_soc()
205 return soc >> (chip->quirk_double_soc ? 9 : 8); in max17040_get_soc()
213 ret = regmap_read(chip->regmap, MAX17040_VER, &version); in max17040_get_version()
225 struct device *dev = &chip->client->dev; in max17040_get_of_data()
231 chip->quirk_double_soc = device_property_read_bool(dev, in max17040_get_of_data()
232 "maxim,double-soc"); in max17040_get_of_data()
234 chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP; in max17040_get_of_data()
236 "maxim,alert-low-soc-level", in max17040_get_of_data()
237 &chip->low_soc_alert); in max17040_get_of_data()
239 if (chip->low_soc_alert <= 0 || in max17040_get_of_data()
240 chip->low_soc_alert > (chip->quirk_double_soc ? 16 : 32)) { in max17040_get_of_data()
241 dev_err(dev, "maxim,alert-low-soc-level out of bounds\n"); in max17040_get_of_data()
242 return -EINVAL; in max17040_get_of_data()
246 chip->rcomp = MAX17040_RCOMP_DEFAULT; in max17040_get_of_data()
247 if (rcomp_len == data->rcomp_bytes) { in max17040_get_of_data()
250 chip->rcomp = rcomp_len == 2 ? rcomp[0] << 8 | rcomp[1] : in max17040_get_of_data()
254 return -EINVAL; in max17040_get_of_data()
262 chip->soc = max17040_get_soc(chip); in max17040_check_changes()
267 queue_delayed_work(system_power_efficient_wq, &chip->work, in max17040_queue_work()
275 cancel_delayed_work_sync(&chip->work); in max17040_stop_work()
286 last_soc = chip->soc; in max17040_work()
290 if (last_soc != chip->soc) in max17040_work()
291 power_supply_changed(chip->battery); in max17040_work()
302 regmap_read(chip->regmap, MAX17040_STATUS, &data); in max17040_handle_soc_alert()
309 // soc change bit -- deassert to mark as handled in max17040_handle_soc_alert()
310 regmap_write(chip->regmap, MAX17040_STATUS, in max17040_handle_soc_alert()
321 if (!(chip->data.has_soc_alert && max17040_handle_soc_alert(chip))) in max17040_thread_handler()
322 dev_warn(&chip->client->dev, "IRQ: Alert battery low level\n"); in max17040_thread_handler()
328 power_supply_changed(chip->battery); in max17040_thread_handler()
331 max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_thread_handler()
338 struct i2c_client *client = chip->client; in max17040_enable_alert_irq()
341 ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, in max17040_enable_alert_irq()
343 chip->battery->desc->name, chip); in max17040_enable_alert_irq()
369 if ((val->intval < 1) || in max17040_set_property()
370 (val->intval > (chip->quirk_double_soc ? 16 : 32))) { in max17040_set_property()
371 ret = -EINVAL; in max17040_set_property()
374 ret = max17040_set_low_soc_alert(chip, val->intval); in max17040_set_property()
375 chip->low_soc_alert = val->intval; in max17040_set_property()
378 ret = -EINVAL; in max17040_set_property()
392 val->intval = max17040_get_online(chip); in max17040_get_property()
395 val->intval = max17040_get_vcell(chip); in max17040_get_property()
398 val->intval = max17040_get_soc(chip); in max17040_get_property()
401 val->intval = chip->low_soc_alert; in max17040_get_property()
404 return -EINVAL; in max17040_get_property()
436 struct i2c_adapter *adapter = client->adapter; in max17040_probe()
444 return -EIO; in max17040_probe()
446 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in max17040_probe()
448 return -ENOMEM; in max17040_probe()
450 chip->client = client; in max17040_probe()
451 chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap); in max17040_probe()
452 if (IS_ERR(chip->regmap)) in max17040_probe()
453 return PTR_ERR(chip->regmap); in max17040_probe()
454 chip_id = (enum chip_id) id->driver_data; in max17040_probe()
455 if (client->dev.of_node) { in max17040_probe()
459 chip_id = (uintptr_t)of_device_get_match_data(&client->dev); in max17040_probe()
461 chip->data = max17040_family[chip_id]; in max17040_probe()
466 chip->battery = devm_power_supply_register(&client->dev, in max17040_probe()
468 if (IS_ERR(chip->battery)) { in max17040_probe()
469 dev_err(&client->dev, "failed: power supply register\n"); in max17040_probe()
470 return PTR_ERR(chip->battery); in max17040_probe()
476 dev_dbg(&chip->client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", ret); in max17040_probe()
481 max17040_set_rcomp(chip, chip->rcomp); in max17040_probe()
484 if (client->irq && chip->data.has_low_soc_alert) { in max17040_probe()
485 ret = max17040_set_low_soc_alert(chip, chip->low_soc_alert); in max17040_probe()
487 dev_err(&client->dev, in max17040_probe()
495 if (client->irq && chip->data.has_soc_alert) { in max17040_probe()
498 dev_err(&client->dev, in max17040_probe()
505 INIT_DEFERRABLE_WORK(&chip->work, max17040_work); in max17040_probe()
506 ret = devm_add_action(&client->dev, max17040_stop_work, chip); in max17040_probe()
515 client->irq = 0; in max17040_probe()
516 dev_warn(&client->dev, in max17040_probe()
531 if (client->irq && chip->data.has_soc_alert) in max17040_suspend()
535 cancel_delayed_work(&chip->work); in max17040_suspend()
537 if (client->irq && device_may_wakeup(dev)) in max17040_suspend()
538 enable_irq_wake(client->irq); in max17040_suspend()
548 if (client->irq && device_may_wakeup(dev)) in max17040_resume()
549 disable_irq_wake(client->irq); in max17040_resume()
551 if (client->irq && chip->data.has_soc_alert) in max17040_resume()
572 { "max77836-battery", ID_MAX17043 },
586 { .compatible = "maxim,max77836-battery", .data = (void *) ID_MAX17043 },