Lines Matching +full:soc +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DA9150 Fuel-Gauge Driver
23 #include <linux/devm-helpers.h>
85 int soc; member
100 da9150_read_qif(fg->da9150, read_addr, size, buf); in da9150_fg_read_attr()
122 da9150_write_qif(fg->da9150, write_addr, size, buf); in da9150_fg_write_attr()
131 mutex_lock(&fg->io_lock); in da9150_fg_read_sync_start()
151 dev_err(fg->dev, "Failed to perform QIF read sync!\n"); in da9150_fg_read_sync_start()
160 mutex_unlock(&fg->io_lock); in da9150_fg_read_sync_end()
182 mutex_lock(&fg->io_lock); in da9150_fg_write_attr_sync()
197 dev_err(fg->dev, "Timeout waiting for existing QIF sync!\n"); in da9150_fg_write_attr_sync()
198 mutex_unlock(&fg->io_lock); in da9150_fg_write_attr_sync()
215 mutex_unlock(&fg->io_lock); in da9150_fg_write_attr_sync()
219 dev_err(fg->dev, "Error performing QIF sync write for code %d\n", in da9150_fg_write_attr_sync()
227 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_SOC_PCT, in da9150_fg_capacity()
230 if (val->intval > 100) in da9150_fg_capacity()
231 val->intval = 100; in da9150_fg_capacity()
256 val->intval = (int) res; in da9150_fg_current_avg()
266 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_UAVG, in da9150_fg_voltage_avg()
269 res = (u64) (val->intval * 186ULL); in da9150_fg_voltage_avg()
271 val->intval = (int) res; in da9150_fg_voltage_avg()
279 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_FCC_MAH, in da9150_fg_charge_full()
282 val->intval = val->intval * 1000; in da9150_fg_charge_full()
294 val->intval = da9150_fg_read_attr_sync(fg, DA9150_QIF_NTCAVG, in da9150_fg_temp()
297 val->intval = (val->intval * 10) / 1048576; in da9150_fg_temp()
314 struct da9150_fg *fg = dev_get_drvdata(psy->dev.parent); in da9150_fg_get_prop()
334 ret = -EINVAL; in da9150_fg_get_prop()
341 /* Repeated SOC check */
347 if (val.intval != fg->soc) { in da9150_fg_soc_changed()
348 fg->soc = val.intval; in da9150_fg_soc_changed()
359 /* Report if SOC has changed */ in da9150_fg_work()
361 power_supply_changed(fg->battery); in da9150_fg_work()
363 schedule_delayed_work(&fg->work, msecs_to_jiffies(fg->interval)); in da9150_fg_work()
366 /* SOC level event configuration */
369 int soc; in da9150_fg_soc_event_config() local
371 soc = da9150_fg_read_attr_sync(fg, DA9150_QIF_SOC_PCT, in da9150_fg_soc_event_config()
374 if (soc > fg->warn_soc) { in da9150_fg_soc_event_config()
375 /* If SOC > warn level, set discharge warn level event */ in da9150_fg_soc_event_config()
378 fg->warn_soc + 1); in da9150_fg_soc_event_config()
379 } else if ((soc <= fg->warn_soc) && (soc > fg->crit_soc)) { in da9150_fg_soc_event_config()
381 * If SOC <= warn level, set discharge crit level event, in da9150_fg_soc_event_config()
382 * and set charge warn level event. in da9150_fg_soc_event_config()
386 fg->crit_soc + 1); in da9150_fg_soc_event_config()
390 fg->warn_soc); in da9150_fg_soc_event_config()
391 } else if (soc <= fg->crit_soc) { in da9150_fg_soc_event_config()
392 /* If SOC <= crit level, set charge crit level event */ in da9150_fg_soc_event_config()
395 fg->crit_soc); in da9150_fg_soc_event_config()
421 struct device_node *fg_node = dev->of_node; in da9150_fg_dt_pdata()
428 of_property_read_u32(fg_node, "dlg,update-interval", in da9150_fg_dt_pdata()
429 &pdata->update_interval); in da9150_fg_dt_pdata()
430 of_property_read_u8(fg_node, "dlg,warn-soc-level", in da9150_fg_dt_pdata()
431 &pdata->warn_soc_lvl); in da9150_fg_dt_pdata()
432 of_property_read_u8(fg_node, "dlg,crit-soc-level", in da9150_fg_dt_pdata()
433 &pdata->crit_soc_lvl); in da9150_fg_dt_pdata()
439 .name = "da9150-fg",
448 struct device *dev = &pdev->dev; in da9150_fg_probe()
449 struct da9150 *da9150 = dev_get_drvdata(dev->parent); in da9150_fg_probe()
456 return -ENOMEM; in da9150_fg_probe()
459 fg->da9150 = da9150; in da9150_fg_probe()
460 fg->dev = dev; in da9150_fg_probe()
462 mutex_init(&fg->io_lock); in da9150_fg_probe()
468 fg->battery = devm_power_supply_register(dev, &fg_desc, NULL); in da9150_fg_probe()
469 if (IS_ERR(fg->battery)) { in da9150_fg_probe()
470 ret = PTR_ERR(fg->battery); in da9150_fg_probe()
479 if (dev->of_node) { in da9150_fg_probe()
481 dev->platform_data = fg_pdata; in da9150_fg_probe()
486 fg->interval = fg_pdata->update_interval; in da9150_fg_probe()
488 if (fg_pdata->warn_soc_lvl > 100) in da9150_fg_probe()
489 dev_warn(dev, "Invalid SOC warning level provided, Ignoring"); in da9150_fg_probe()
491 fg->warn_soc = fg_pdata->warn_soc_lvl; in da9150_fg_probe()
493 if ((fg_pdata->crit_soc_lvl > 100) || in da9150_fg_probe()
494 (fg_pdata->crit_soc_lvl >= fg_pdata->warn_soc_lvl)) in da9150_fg_probe()
495 dev_warn(dev, "Invalid SOC critical level provided, Ignoring"); in da9150_fg_probe()
497 fg->crit_soc = fg_pdata->crit_soc_lvl; in da9150_fg_probe()
502 /* Configure initial SOC level events */ in da9150_fg_probe()
509 if (fg->interval) { in da9150_fg_probe()
510 ret = devm_delayed_work_autocancel(dev, &fg->work, in da9150_fg_probe()
517 schedule_delayed_work(&fg->work, in da9150_fg_probe()
518 msecs_to_jiffies(fg->interval)); in da9150_fg_probe()
541 * Trigger SOC check to happen now so as to indicate any value change in da9150_fg_resume()
544 if (fg->interval) in da9150_fg_resume()
545 flush_delayed_work(&fg->work); in da9150_fg_resume()
552 .name = "da9150-fuel-gauge",
560 MODULE_DESCRIPTION("Fuel-Gauge Driver for DA9150");