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

1 // SPDX-License-Identifier: GPL-2.0+
54 #define TO_CUR_REG(x) ((x) / 100000 - 1)
116 ret = regmap_bulk_read(info->rn5t618->regmap, in rn5t618_battery_read_doublereg()
161 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_status()
165 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in rn5t618_battery_status()
168 val->intval = rn5t618_decode_status(v); in rn5t618_battery_status()
170 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in rn5t618_battery_status()
181 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_present()
187 val->intval = 0; in rn5t618_battery_present()
189 val->intval = 1; in rn5t618_battery_present()
204 val->intval = res * 2 * 2500 / 4095 * 1000; in rn5t618_battery_voltage_now()
220 val->intval = sign_extend32(res, 13) * 1000; in rn5t618_battery_current_now()
231 ret = regmap_read(info->rn5t618->regmap, RN5T618_SOC, &v); in rn5t618_battery_capacity()
235 val->intval = v; in rn5t618_battery_capacity()
250 val->intval = sign_extend32(res, 11) * 10 / 16; in rn5t618_battery_temp()
266 return -ENODATA; in rn5t618_battery_tte()
268 val->intval = res * 60; in rn5t618_battery_tte()
284 return -ENODATA; in rn5t618_battery_ttf()
286 val->intval = res * 60; in rn5t618_battery_ttf()
294 if (val->intval < CHG_MIN_CUR) in rn5t618_battery_set_current_limit()
295 return -EINVAL; in rn5t618_battery_set_current_limit()
297 if (val->intval >= CHG_MAX_CUR) in rn5t618_battery_set_current_limit()
298 return -EINVAL; in rn5t618_battery_set_current_limit()
300 return regmap_update_bits(info->rn5t618->regmap, in rn5t618_battery_set_current_limit()
302 0x1F, TO_CUR_REG(val->intval)); in rn5t618_battery_set_current_limit()
311 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGISET, in rn5t618_battery_get_current_limit()
316 val->intval = FROM_CUR_REG(regval); in rn5t618_battery_get_current_limit()
331 val->intval = res * 1000; in rn5t618_battery_charge_full()
346 val->intval = res * 1000; in rn5t618_battery_charge_now()
384 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in rn5t618_battery_get_property()
396 return -EINVAL; in rn5t618_battery_get_property()
412 return -EINVAL; in rn5t618_battery_set_property()
437 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_adp_get_property()
445 val->intval = online; in rn5t618_adp_get_property()
449 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
452 val->intval = rn5t618_decode_status(chgstate); in rn5t618_adp_get_property()
453 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_adp_get_property()
454 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
458 ret = regmap_read(info->rn5t618->regmap, in rn5t618_adp_get_property()
463 val->intval = FROM_CUR_REG(regval); in rn5t618_adp_get_property()
466 if (!info->channel_vadp) in rn5t618_adp_get_property()
467 return -ENODATA; in rn5t618_adp_get_property()
469 ret = iio_read_channel_processed_scale(info->channel_vadp, &val->intval, 1000); in rn5t618_adp_get_property()
475 return -EINVAL; in rn5t618_adp_get_property()
490 if (val->intval > ADP_MAX_CUR) in rn5t618_adp_set_property()
491 return -EINVAL; in rn5t618_adp_set_property()
493 if (val->intval < CHG_MIN_CUR) in rn5t618_adp_set_property()
494 return -EINVAL; in rn5t618_adp_set_property()
496 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET1, in rn5t618_adp_set_property()
497 TO_CUR_REG(val->intval)); in rn5t618_adp_set_property()
503 return -EINVAL; in rn5t618_adp_set_property()
526 ret = regmap_read(info->rn5t618->regmap, RN5T618_GCHGDET, &regval); in rc5t619_usb_get_type()
532 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in rc5t619_usb_get_type()
535 val->intval = POWER_SUPPLY_USB_TYPE_CDP; in rc5t619_usb_get_type()
538 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in rc5t619_usb_get_type()
541 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rc5t619_usb_get_type()
557 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_usb_get_property()
565 val->intval = online; in rn5t618_usb_get_property()
569 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
572 val->intval = rn5t618_decode_status(chgstate); in rn5t618_usb_get_property()
573 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_usb_get_property()
574 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
578 if (!online || (info->rn5t618->variant != RC5T619)) in rn5t618_usb_get_property()
579 return -ENODATA; in rn5t618_usb_get_property()
583 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGCTL1, in rn5t618_usb_get_property()
588 val->intval = 0; in rn5t618_usb_get_property()
590 ret = regmap_read(info->rn5t618->regmap, in rn5t618_usb_get_property()
596 val->intval = FROM_CUR_REG(regval); in rn5t618_usb_get_property()
600 if (!info->channel_vusb) in rn5t618_usb_get_property()
601 return -ENODATA; in rn5t618_usb_get_property()
603 ret = iio_read_channel_processed_scale(info->channel_vusb, &val->intval, 1000); in rn5t618_usb_get_property()
609 return -EINVAL; in rn5t618_usb_get_property()
624 if (val->intval > USB_MAX_CUR) in rn5t618_usb_set_property()
625 return -EINVAL; in rn5t618_usb_set_property()
627 if (val->intval < CHG_MIN_CUR) in rn5t618_usb_set_property()
628 return -EINVAL; in rn5t618_usb_set_property()
630 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET2, in rn5t618_usb_set_property()
631 0xE0 | TO_CUR_REG(val->intval)); in rn5t618_usb_set_property()
637 return -EINVAL; in rn5t618_usb_set_property()
655 .name = "rn5t618-battery",
665 .name = "rn5t618-adp",
675 .name = "rn5t618-usb",
695 regmap_read(info->rn5t618->regmap, RN5T618_CHGERR_IRR, &err); in rn5t618_charger_irq()
696 regmap_read(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, &ctrl); in rn5t618_charger_irq()
697 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, &stat1); in rn5t618_charger_irq()
698 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, &stat2); in rn5t618_charger_irq()
700 regmap_write(info->rn5t618->regmap, RN5T618_CHGERR_IRR, 0); in rn5t618_charger_irq()
701 regmap_write(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, 0); in rn5t618_charger_irq()
702 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, 0); in rn5t618_charger_irq()
703 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, 0); in rn5t618_charger_irq()
708 power_supply_changed(info->usb); in rn5t618_charger_irq()
709 power_supply_changed(info->adp); in rn5t618_charger_irq()
710 power_supply_changed(info->battery); in rn5t618_charger_irq()
722 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in rn5t618_power_probe()
724 return -ENOMEM; in rn5t618_power_probe()
726 info->pdev = pdev; in rn5t618_power_probe()
727 info->rn5t618 = dev_get_drvdata(pdev->dev.parent); in rn5t618_power_probe()
728 info->irq = -1; in rn5t618_power_probe()
732 info->channel_vusb = devm_iio_channel_get(&pdev->dev, "vusb"); in rn5t618_power_probe()
733 if (IS_ERR(info->channel_vusb)) { in rn5t618_power_probe()
734 if (PTR_ERR(info->channel_vusb) == -ENODEV) in rn5t618_power_probe()
735 return -EPROBE_DEFER; in rn5t618_power_probe()
736 return PTR_ERR(info->channel_vusb); in rn5t618_power_probe()
739 info->channel_vadp = devm_iio_channel_get(&pdev->dev, "vadp"); in rn5t618_power_probe()
740 if (IS_ERR(info->channel_vadp)) { in rn5t618_power_probe()
741 if (PTR_ERR(info->channel_vadp) == -ENODEV) in rn5t618_power_probe()
742 return -EPROBE_DEFER; in rn5t618_power_probe()
743 return PTR_ERR(info->channel_vadp); in rn5t618_power_probe()
746 ret = regmap_read(info->rn5t618->regmap, RN5T618_CONTROL, &v); in rn5t618_power_probe()
752 * readers disable the fuel gauge on shutdown. If a kernel in rn5t618_power_probe()
753 * without fuel gauge support is booted after that, the fuel in rn5t618_power_probe()
754 * gauge will get decalibrated. in rn5t618_power_probe()
756 dev_info(&pdev->dev, "Fuel gauge not enabled, enabling now\n"); in rn5t618_power_probe()
757 dev_info(&pdev->dev, "Expect imprecise results\n"); in rn5t618_power_probe()
758 regmap_update_bits(info->rn5t618->regmap, RN5T618_CONTROL, in rn5t618_power_probe()
763 info->battery = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
766 if (IS_ERR(info->battery)) { in rn5t618_power_probe()
767 ret = PTR_ERR(info->battery); in rn5t618_power_probe()
768 dev_err(&pdev->dev, "failed to register battery: %d\n", ret); in rn5t618_power_probe()
772 info->adp = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
775 if (IS_ERR(info->adp)) { in rn5t618_power_probe()
776 ret = PTR_ERR(info->adp); in rn5t618_power_probe()
777 dev_err(&pdev->dev, "failed to register adp: %d\n", ret); in rn5t618_power_probe()
781 info->usb = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
784 if (IS_ERR(info->usb)) { in rn5t618_power_probe()
785 ret = PTR_ERR(info->usb); in rn5t618_power_probe()
786 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); in rn5t618_power_probe()
790 if (info->rn5t618->irq_data) in rn5t618_power_probe()
791 info->irq = regmap_irq_get_virq(info->rn5t618->irq_data, in rn5t618_power_probe()
794 if (info->irq < 0) in rn5t618_power_probe()
795 info->irq = -1; in rn5t618_power_probe()
797 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in rn5t618_power_probe()
801 &pdev->dev); in rn5t618_power_probe()
804 dev_err(&pdev->dev, "request IRQ:%d fail\n", in rn5t618_power_probe()
805 info->irq); in rn5t618_power_probe()
806 info->irq = -1; in rn5t618_power_probe()
815 .name = "rn5t618-power",
821 MODULE_ALIAS("platform:rn5t618-power");