Lines Matching +full:fuel +full:- +full:gauge
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DA9150 Fuel-Gauge Driver
22 #include <linux/devm-helpers.h>
99 da9150_read_qif(fg->da9150, read_addr, size, buf); in da9150_fg_read_attr()
121 da9150_write_qif(fg->da9150, write_addr, size, buf); in da9150_fg_write_attr()
130 mutex_lock(&fg->io_lock); in da9150_fg_read_sync_start()
150 dev_err(fg->dev, "Failed to perform QIF read sync!\n"); in da9150_fg_read_sync_start()
159 mutex_unlock(&fg->io_lock); in da9150_fg_read_sync_end()
181 mutex_lock(&fg->io_lock); in da9150_fg_write_attr_sync()
196 dev_err(fg->dev, "Timeout waiting for existing QIF sync!\n"); in da9150_fg_write_attr_sync()
197 mutex_unlock(&fg->io_lock); in da9150_fg_write_attr_sync()
214 mutex_unlock(&fg->io_lock); in da9150_fg_write_attr_sync()
218 dev_err(fg->dev, "Error performing QIF sync write for code %d\n", in da9150_fg_write_attr_sync()
226 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_SOC_PCT, in da9150_fg_capacity()
229 if (val->intval > 100) in da9150_fg_capacity()
230 val->intval = 100; in da9150_fg_capacity()
255 val->intval = (int) res; in da9150_fg_current_avg()
265 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_UAVG, in da9150_fg_voltage_avg()
268 res = (u64) (val->intval * 186ULL); in da9150_fg_voltage_avg()
270 val->intval = (int) res; in da9150_fg_voltage_avg()
278 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_FCC_MAH, in da9150_fg_charge_full()
281 val->intval = val->intval * 1000; in da9150_fg_charge_full()
293 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_NTCAVG, in da9150_fg_temp()
296 val->intval = (val->intval * 10) / 1048576; in da9150_fg_temp()
313 struct da9150_fg *fg = dev_get_drvdata(psy->dev.parent); in da9150_fg_get_prop()
333 ret = -EINVAL; in da9150_fg_get_prop()
346 if (val.intval != fg->soc) { in da9150_fg_soc_changed()
347 fg->soc = val.intval; in da9150_fg_soc_changed()
360 power_supply_changed(fg->battery); in da9150_fg_work()
362 schedule_delayed_work(&fg->work, msecs_to_jiffies(fg->interval)); in da9150_fg_work()
373 if (soc > fg->warn_soc) { in da9150_fg_soc_event_config()
377 fg->warn_soc + 1); in da9150_fg_soc_event_config()
378 } else if ((soc <= fg->warn_soc) && (soc > fg->crit_soc)) { in da9150_fg_soc_event_config()
385 fg->crit_soc + 1); in da9150_fg_soc_event_config()
389 fg->warn_soc); in da9150_fg_soc_event_config()
390 } else if (soc <= fg->crit_soc) { in da9150_fg_soc_event_config()
394 fg->crit_soc); in da9150_fg_soc_event_config()
420 struct device_node *fg_node = dev->of_node; in da9150_fg_dt_pdata()
427 of_property_read_u32(fg_node, "dlg,update-interval", in da9150_fg_dt_pdata()
428 &pdata->update_interval); in da9150_fg_dt_pdata()
429 of_property_read_u8(fg_node, "dlg,warn-soc-level", in da9150_fg_dt_pdata()
430 &pdata->warn_soc_lvl); in da9150_fg_dt_pdata()
431 of_property_read_u8(fg_node, "dlg,crit-soc-level", in da9150_fg_dt_pdata()
432 &pdata->crit_soc_lvl); in da9150_fg_dt_pdata()
438 .name = "da9150-fg",
447 struct device *dev = &pdev->dev; in da9150_fg_probe()
448 struct da9150 *da9150 = dev_get_drvdata(dev->parent); in da9150_fg_probe()
455 return -ENOMEM; in da9150_fg_probe()
458 fg->da9150 = da9150; in da9150_fg_probe()
459 fg->dev = dev; in da9150_fg_probe()
461 mutex_init(&fg->io_lock); in da9150_fg_probe()
467 fg->battery = devm_power_supply_register(dev, &fg_desc, NULL); in da9150_fg_probe()
468 if (IS_ERR(fg->battery)) { in da9150_fg_probe()
469 ret = PTR_ERR(fg->battery); in da9150_fg_probe()
478 if (dev->of_node) { in da9150_fg_probe()
480 dev->platform_data = fg_pdata; in da9150_fg_probe()
485 fg->interval = fg_pdata->update_interval; in da9150_fg_probe()
487 if (fg_pdata->warn_soc_lvl > 100) in da9150_fg_probe()
490 fg->warn_soc = fg_pdata->warn_soc_lvl; in da9150_fg_probe()
492 if ((fg_pdata->crit_soc_lvl > 100) || in da9150_fg_probe()
493 (fg_pdata->crit_soc_lvl >= fg_pdata->warn_soc_lvl)) in da9150_fg_probe()
496 fg->crit_soc = fg_pdata->crit_soc_lvl; in da9150_fg_probe()
508 if (fg->interval) { in da9150_fg_probe()
509 ret = devm_delayed_work_autocancel(dev, &fg->work, in da9150_fg_probe()
516 schedule_delayed_work(&fg->work, in da9150_fg_probe()
517 msecs_to_jiffies(fg->interval)); in da9150_fg_probe()
543 if (fg->interval) in da9150_fg_resume()
544 flush_delayed_work(&fg->work); in da9150_fg_resume()
551 .name = "da9150-fuel-gauge",
559 MODULE_DESCRIPTION("Fuel-Gauge Driver for DA9150");