Lines Matching +full:fuel +full:- +full:gauge

1 // SPDX-License-Identifier: GPL-2.0+
55 #define TO_CUR_REG(x) ((x) / 100000 - 1)
124 ret = regmap_bulk_read(info->rn5t618->regmap, in rn5t618_battery_read_doublereg()
169 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_status()
173 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in rn5t618_battery_status()
176 val->intval = rn5t618_decode_status(v); in rn5t618_battery_status()
178 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in rn5t618_battery_status()
189 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_present()
195 val->intval = 0; in rn5t618_battery_present()
197 val->intval = 1; in rn5t618_battery_present()
212 val->intval = res * 2 * 2500 / 4095 * 1000; in rn5t618_battery_voltage_now()
228 val->intval = sign_extend32(res, 13) * 1000; in rn5t618_battery_current_now()
239 ret = regmap_read(info->rn5t618->regmap, RN5T618_SOC, &v); in rn5t618_battery_capacity()
243 val->intval = v; in rn5t618_battery_capacity()
258 val->intval = sign_extend32(res, 11) * 10 / 16; in rn5t618_battery_temp()
274 return -ENODATA; in rn5t618_battery_tte()
276 val->intval = res * 60; in rn5t618_battery_tte()
292 return -ENODATA; in rn5t618_battery_ttf()
294 val->intval = res * 60; in rn5t618_battery_ttf()
302 if (val->intval < CHG_MIN_CUR) in rn5t618_battery_set_current_limit()
303 return -EINVAL; in rn5t618_battery_set_current_limit()
305 if (val->intval >= CHG_MAX_CUR) in rn5t618_battery_set_current_limit()
306 return -EINVAL; in rn5t618_battery_set_current_limit()
308 return regmap_update_bits(info->rn5t618->regmap, in rn5t618_battery_set_current_limit()
310 0x1F, TO_CUR_REG(val->intval)); in rn5t618_battery_set_current_limit()
319 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGISET, in rn5t618_battery_get_current_limit()
324 val->intval = FROM_CUR_REG(regval); in rn5t618_battery_get_current_limit()
339 val->intval = res * 1000; in rn5t618_battery_charge_full()
354 val->intval = res * 1000; in rn5t618_battery_charge_now()
392 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in rn5t618_battery_get_property()
404 return -EINVAL; in rn5t618_battery_get_property()
420 return -EINVAL; in rn5t618_battery_set_property()
445 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_adp_get_property()
453 val->intval = online; in rn5t618_adp_get_property()
457 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
460 val->intval = rn5t618_decode_status(chgstate); in rn5t618_adp_get_property()
461 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_adp_get_property()
462 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
466 ret = regmap_read(info->rn5t618->regmap, in rn5t618_adp_get_property()
471 val->intval = FROM_CUR_REG(regval); in rn5t618_adp_get_property()
474 if (!info->channel_vadp) in rn5t618_adp_get_property()
475 return -ENODATA; in rn5t618_adp_get_property()
477 ret = iio_read_channel_processed_scale(info->channel_vadp, &val->intval, 1000); in rn5t618_adp_get_property()
483 return -EINVAL; in rn5t618_adp_get_property()
498 if (val->intval > ADP_MAX_CUR) in rn5t618_adp_set_property()
499 return -EINVAL; in rn5t618_adp_set_property()
501 if (val->intval < CHG_MIN_CUR) in rn5t618_adp_set_property()
502 return -EINVAL; in rn5t618_adp_set_property()
504 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET1, in rn5t618_adp_set_property()
505 TO_CUR_REG(val->intval)); in rn5t618_adp_set_property()
511 return -EINVAL; in rn5t618_adp_set_property()
534 ret = regmap_read(info->rn5t618->regmap, RN5T618_GCHGDET, &regval); in rc5t619_usb_get_type()
540 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in rc5t619_usb_get_type()
543 val->intval = POWER_SUPPLY_USB_TYPE_CDP; in rc5t619_usb_get_type()
546 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in rc5t619_usb_get_type()
549 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rc5t619_usb_get_type()
565 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_usb_get_property()
573 val->intval = online; in rn5t618_usb_get_property()
577 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
580 val->intval = rn5t618_decode_status(chgstate); in rn5t618_usb_get_property()
581 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_usb_get_property()
582 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
586 if (!online || (info->rn5t618->variant != RC5T619)) in rn5t618_usb_get_property()
587 return -ENODATA; in rn5t618_usb_get_property()
591 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGCTL1, in rn5t618_usb_get_property()
596 val->intval = 0; in rn5t618_usb_get_property()
598 ret = regmap_read(info->rn5t618->regmap, in rn5t618_usb_get_property()
604 val->intval = FROM_CUR_REG(regval); in rn5t618_usb_get_property()
608 if (!info->channel_vusb) in rn5t618_usb_get_property()
609 return -ENODATA; in rn5t618_usb_get_property()
611 ret = iio_read_channel_processed_scale(info->channel_vusb, &val->intval, 1000); in rn5t618_usb_get_property()
617 return -EINVAL; in rn5t618_usb_get_property()
632 if (val->intval > USB_MAX_CUR) in rn5t618_usb_set_property()
633 return -EINVAL; in rn5t618_usb_set_property()
635 if (val->intval < CHG_MIN_CUR) in rn5t618_usb_set_property()
636 return -EINVAL; in rn5t618_usb_set_property()
638 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET2, in rn5t618_usb_set_property()
639 0xE0 | TO_CUR_REG(val->intval)); in rn5t618_usb_set_property()
645 return -EINVAL; in rn5t618_usb_set_property()
663 .name = "rn5t618-battery",
673 .name = "rn5t618-adp",
683 .name = "rn5t618-usb",
701 regmap_read(info->rn5t618->regmap, RN5T618_CHGERR_IRR, &err); in rn5t618_charger_irq()
702 regmap_read(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, &ctrl); in rn5t618_charger_irq()
703 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, &stat1); in rn5t618_charger_irq()
704 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, &stat2); in rn5t618_charger_irq()
706 regmap_write(info->rn5t618->regmap, RN5T618_CHGERR_IRR, 0); in rn5t618_charger_irq()
707 regmap_write(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, 0); in rn5t618_charger_irq()
708 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, 0); in rn5t618_charger_irq()
709 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, 0); in rn5t618_charger_irq()
714 power_supply_changed(info->usb); in rn5t618_charger_irq()
715 power_supply_changed(info->adp); in rn5t618_charger_irq()
716 power_supply_changed(info->battery); in rn5t618_charger_irq()
728 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in rn5t618_power_probe()
730 return -ENOMEM; in rn5t618_power_probe()
732 info->pdev = pdev; in rn5t618_power_probe()
733 info->rn5t618 = dev_get_drvdata(pdev->dev.parent); in rn5t618_power_probe()
734 info->irq = -1; in rn5t618_power_probe()
738 info->channel_vusb = devm_iio_channel_get(&pdev->dev, "vusb"); in rn5t618_power_probe()
739 if (IS_ERR(info->channel_vusb)) { in rn5t618_power_probe()
740 if (PTR_ERR(info->channel_vusb) == -ENODEV) in rn5t618_power_probe()
741 return -EPROBE_DEFER; in rn5t618_power_probe()
742 return PTR_ERR(info->channel_vusb); in rn5t618_power_probe()
745 info->channel_vadp = devm_iio_channel_get(&pdev->dev, "vadp"); in rn5t618_power_probe()
746 if (IS_ERR(info->channel_vadp)) { in rn5t618_power_probe()
747 if (PTR_ERR(info->channel_vadp) == -ENODEV) in rn5t618_power_probe()
748 return -EPROBE_DEFER; in rn5t618_power_probe()
749 return PTR_ERR(info->channel_vadp); in rn5t618_power_probe()
752 ret = regmap_read(info->rn5t618->regmap, RN5T618_CONTROL, &v); in rn5t618_power_probe()
758 * readers disable the fuel gauge on shutdown. If a kernel in rn5t618_power_probe()
759 * without fuel gauge support is booted after that, the fuel in rn5t618_power_probe()
760 * gauge will get decalibrated. in rn5t618_power_probe()
762 dev_info(&pdev->dev, "Fuel gauge not enabled, enabling now\n"); in rn5t618_power_probe()
763 dev_info(&pdev->dev, "Expect imprecise results\n"); in rn5t618_power_probe()
764 regmap_update_bits(info->rn5t618->regmap, RN5T618_CONTROL, in rn5t618_power_probe()
769 info->battery = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
772 if (IS_ERR(info->battery)) { in rn5t618_power_probe()
773 ret = PTR_ERR(info->battery); in rn5t618_power_probe()
774 dev_err(&pdev->dev, "failed to register battery: %d\n", ret); in rn5t618_power_probe()
778 info->adp = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
781 if (IS_ERR(info->adp)) { in rn5t618_power_probe()
782 ret = PTR_ERR(info->adp); in rn5t618_power_probe()
783 dev_err(&pdev->dev, "failed to register adp: %d\n", ret); in rn5t618_power_probe()
787 info->usb = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
790 if (IS_ERR(info->usb)) { in rn5t618_power_probe()
791 ret = PTR_ERR(info->usb); in rn5t618_power_probe()
792 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); in rn5t618_power_probe()
796 if (info->rn5t618->irq_data) in rn5t618_power_probe()
797 info->irq = regmap_irq_get_virq(info->rn5t618->irq_data, in rn5t618_power_probe()
800 if (info->irq < 0) in rn5t618_power_probe()
801 info->irq = -1; in rn5t618_power_probe()
803 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in rn5t618_power_probe()
807 &pdev->dev); in rn5t618_power_probe()
810 dev_err(&pdev->dev, "request IRQ:%d fail\n", in rn5t618_power_probe()
811 info->irq); in rn5t618_power_probe()
812 info->irq = -1; in rn5t618_power_probe()
821 .name = "rn5t618-power",
827 MODULE_ALIAS("platform:rn5t618-power");