Lines Matching refs:bat

185 static int da9052_read_chgend_current(struct da9052_battery *bat,  in da9052_read_chgend_current()  argument
190 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) in da9052_read_chgend_current()
193 ret = da9052_reg_read(bat->da9052, DA9052_ICHG_END_REG); in da9052_read_chgend_current()
202 static int da9052_read_chg_current(struct da9052_battery *bat, int *current_mA) in da9052_read_chg_current() argument
206 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) in da9052_read_chg_current()
209 ret = da9052_reg_read(bat->da9052, DA9052_ICHG_AV_REG); in da9052_read_chg_current()
218 static int da9052_bat_check_status(struct da9052_battery *bat, int *status) in da9052_bat_check_status() argument
233 ret = da9052_group_read(bat->da9052, DA9052_STATUS_A_REG, 2, v); in da9052_bat_check_status()
249 bat->charger_type = DA9052_CHARGER; in da9052_bat_check_status()
255 ret = da9052_read_chg_current(bat, &chg_current); in da9052_bat_check_status()
258 ret = da9052_read_chgend_current(bat, &chg_end_current); in da9052_bat_check_status()
263 bat->status = POWER_SUPPLY_STATUS_CHARGING; in da9052_bat_check_status()
265 bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING; in da9052_bat_check_status()
270 bat->status = POWER_SUPPLY_STATUS_CHARGING; in da9052_bat_check_status()
273 bat->charger_type = DA9052_CHARGER; in da9052_bat_check_status()
274 bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING; in da9052_bat_check_status()
276 bat->charger_type = DA9052_NOCHARGER; in da9052_bat_check_status()
277 bat->status = POWER_SUPPLY_STATUS_DISCHARGING; in da9052_bat_check_status()
281 *status = bat->status; in da9052_bat_check_status()
285 static int da9052_bat_read_volt(struct da9052_battery *bat, int *volt_mV) in da9052_bat_read_volt() argument
289 volt = da9052_adc_manual_read(bat->da9052, DA9052_ADC_MAN_MUXSEL_VBAT); in da9052_bat_read_volt()
298 static int da9052_bat_check_presence(struct da9052_battery *bat, int *illegal) in da9052_bat_check_presence() argument
302 bat_temp = da9052_adc_read_temp(bat->da9052); in da9052_bat_check_presence()
353 static int da9052_bat_read_capacity(struct da9052_battery *bat, int *capacity) in da9052_bat_read_capacity() argument
366 ret = da9052_bat_read_volt(bat, &bat_voltage); in da9052_bat_read_capacity()
370 adc_temp = da9052_adc_read_temp(bat->da9052); in da9052_bat_read_capacity()
406 static int da9052_bat_check_health(struct da9052_battery *bat, int *health) in da9052_bat_check_health() argument
412 ret = da9052_bat_check_presence(bat, &bat_illegal); in da9052_bat_check_health()
417 bat->health = POWER_SUPPLY_HEALTH_UNKNOWN; in da9052_bat_check_health()
421 if (bat->health != POWER_SUPPLY_HEALTH_OVERHEAT) { in da9052_bat_check_health()
422 ret = da9052_bat_read_capacity(bat, &capacity); in da9052_bat_check_health()
426 bat->health = POWER_SUPPLY_HEALTH_DEAD; in da9052_bat_check_health()
428 bat->health = POWER_SUPPLY_HEALTH_GOOD; in da9052_bat_check_health()
431 *health = bat->health; in da9052_bat_check_health()
438 struct da9052_battery *bat = data; in da9052_bat_irq() local
441 virq = regmap_irq_get_virq(bat->da9052->irq_data, irq); in da9052_bat_irq()
445 bat->status = POWER_SUPPLY_STATUS_FULL; in da9052_bat_irq()
447 da9052_bat_check_status(bat, NULL); in da9052_bat_irq()
451 power_supply_changed(bat->psy); in da9052_bat_irq()
464 struct da9052_battery *bat = container_of(nb, struct da9052_battery, in da9052_USB_current_notifier() local
467 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) in da9052_USB_current_notifier()
470 ret = da9052_reg_read(bat->da9052, DA9052_CHGBUCK_REG); in da9052_USB_current_notifier()
474 if (bat->da9052->chip_id == DA9052) in da9052_USB_current_notifier()
488 return da9052_reg_update(bat->da9052, DA9052_ISET_REG, in da9052_USB_current_notifier()
498 struct da9052_battery *bat = power_supply_get_drvdata(psy); in da9052_bat_get_property() local
500 ret = da9052_bat_check_presence(bat, &illegal); in da9052_bat_get_property()
509 ret = da9052_bat_check_status(bat, &val->intval); in da9052_bat_get_property()
513 (bat->charger_type == DA9052_NOCHARGER) ? 0 : 1; in da9052_bat_get_property()
516 ret = da9052_bat_check_presence(bat, &val->intval); in da9052_bat_get_property()
519 ret = da9052_bat_check_health(bat, &val->intval); in da9052_bat_get_property()
525 ret = da9052_bat_read_volt(bat, &val->intval); in da9052_bat_get_property()
528 ret = da9052_read_chg_current(bat, &val->intval); in da9052_bat_get_property()
531 ret = da9052_bat_read_capacity(bat, &val->intval); in da9052_bat_get_property()
534 val->intval = da9052_adc_read_temp(bat->da9052); in da9052_bat_get_property()
588 struct da9052_battery *bat; in da9052_bat_probe() local
593 bat = devm_kzalloc(&pdev->dev, sizeof(struct da9052_battery), in da9052_bat_probe()
595 if (!bat) in da9052_bat_probe()
598 psy_cfg.drv_data = bat; in da9052_bat_probe()
600 bat->da9052 = dev_get_drvdata(pdev->dev.parent); in da9052_bat_probe()
601 bat->charger_type = DA9052_NOCHARGER; in da9052_bat_probe()
602 bat->status = POWER_SUPPLY_STATUS_UNKNOWN; in da9052_bat_probe()
603 bat->health = POWER_SUPPLY_HEALTH_UNKNOWN; in da9052_bat_probe()
604 bat->nb.notifier_call = da9052_USB_current_notifier; in da9052_bat_probe()
606 pdata = bat->da9052->dev->platform_data; in da9052_bat_probe()
613 ret = da9052_request_irq(bat->da9052, in da9052_bat_probe()
615 da9052_bat_irq, bat); in da9052_bat_probe()
618 dev_err(bat->da9052->dev, in da9052_bat_probe()
625 bat->psy = power_supply_register(&pdev->dev, &psy_desc, &psy_cfg); in da9052_bat_probe()
626 if (IS_ERR(bat->psy)) { in da9052_bat_probe()
627 ret = PTR_ERR(bat->psy); in da9052_bat_probe()
631 platform_set_drvdata(pdev, bat); in da9052_bat_probe()
636 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat); in da9052_bat_probe()
643 struct da9052_battery *bat = platform_get_drvdata(pdev); in da9052_bat_remove() local
646 da9052_free_irq(bat->da9052, da9052_bat_irq_bits[i], bat); in da9052_bat_remove()
648 power_supply_unregister(bat->psy); in da9052_bat_remove()