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

1 // SPDX-License-Identifier: GPL-2.0+
54 #define TO_CUR_REG(x) ((x) / 100000 - 1)
123 ret = regmap_bulk_read(info->rn5t618->regmap, in rn5t618_battery_read_doublereg()
168 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_status()
172 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in rn5t618_battery_status()
175 val->intval = rn5t618_decode_status(v); in rn5t618_battery_status()
177 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in rn5t618_battery_status()
188 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &v); in rn5t618_battery_present()
194 val->intval = 0; in rn5t618_battery_present()
196 val->intval = 1; in rn5t618_battery_present()
211 val->intval = res * 2 * 2500 / 4095 * 1000; in rn5t618_battery_voltage_now()
227 val->intval = sign_extend32(res, 13) * 1000; in rn5t618_battery_current_now()
238 ret = regmap_read(info->rn5t618->regmap, RN5T618_SOC, &v); in rn5t618_battery_capacity()
242 val->intval = v; in rn5t618_battery_capacity()
257 val->intval = sign_extend32(res, 11) * 10 / 16; in rn5t618_battery_temp()
273 return -ENODATA; in rn5t618_battery_tte()
275 val->intval = res * 60; in rn5t618_battery_tte()
291 return -ENODATA; in rn5t618_battery_ttf()
293 val->intval = res * 60; in rn5t618_battery_ttf()
301 if (val->intval < CHG_MIN_CUR) in rn5t618_battery_set_current_limit()
302 return -EINVAL; in rn5t618_battery_set_current_limit()
304 if (val->intval >= CHG_MAX_CUR) in rn5t618_battery_set_current_limit()
305 return -EINVAL; in rn5t618_battery_set_current_limit()
307 return regmap_update_bits(info->rn5t618->regmap, in rn5t618_battery_set_current_limit()
309 0x1F, TO_CUR_REG(val->intval)); in rn5t618_battery_set_current_limit()
318 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGISET, in rn5t618_battery_get_current_limit()
323 val->intval = FROM_CUR_REG(regval); in rn5t618_battery_get_current_limit()
338 val->intval = res * 1000; in rn5t618_battery_charge_full()
353 val->intval = res * 1000; in rn5t618_battery_charge_now()
391 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in rn5t618_battery_get_property()
403 return -EINVAL; in rn5t618_battery_get_property()
419 return -EINVAL; in rn5t618_battery_set_property()
444 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_adp_get_property()
452 val->intval = online; in rn5t618_adp_get_property()
456 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
459 val->intval = rn5t618_decode_status(chgstate); in rn5t618_adp_get_property()
460 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_adp_get_property()
461 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_adp_get_property()
465 ret = regmap_read(info->rn5t618->regmap, in rn5t618_adp_get_property()
470 val->intval = FROM_CUR_REG(regval); in rn5t618_adp_get_property()
473 if (!info->channel_vadp) in rn5t618_adp_get_property()
474 return -ENODATA; in rn5t618_adp_get_property()
476 ret = iio_read_channel_processed_scale(info->channel_vadp, &val->intval, 1000); in rn5t618_adp_get_property()
482 return -EINVAL; in rn5t618_adp_get_property()
497 if (val->intval > ADP_MAX_CUR) in rn5t618_adp_set_property()
498 return -EINVAL; in rn5t618_adp_set_property()
500 if (val->intval < CHG_MIN_CUR) in rn5t618_adp_set_property()
501 return -EINVAL; in rn5t618_adp_set_property()
503 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET1, in rn5t618_adp_set_property()
504 TO_CUR_REG(val->intval)); in rn5t618_adp_set_property()
510 return -EINVAL; in rn5t618_adp_set_property()
533 ret = regmap_read(info->rn5t618->regmap, RN5T618_GCHGDET, &regval); in rc5t619_usb_get_type()
539 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in rc5t619_usb_get_type()
542 val->intval = POWER_SUPPLY_USB_TYPE_CDP; in rc5t619_usb_get_type()
545 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in rc5t619_usb_get_type()
548 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in rc5t619_usb_get_type()
564 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGSTATE, &chgstate); in rn5t618_usb_get_property()
572 val->intval = online; in rn5t618_usb_get_property()
576 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
579 val->intval = rn5t618_decode_status(chgstate); in rn5t618_usb_get_property()
580 if (val->intval != POWER_SUPPLY_STATUS_CHARGING) in rn5t618_usb_get_property()
581 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rn5t618_usb_get_property()
585 if (!online || (info->rn5t618->variant != RC5T619)) in rn5t618_usb_get_property()
586 return -ENODATA; in rn5t618_usb_get_property()
590 ret = regmap_read(info->rn5t618->regmap, RN5T618_CHGCTL1, in rn5t618_usb_get_property()
595 val->intval = 0; in rn5t618_usb_get_property()
597 ret = regmap_read(info->rn5t618->regmap, in rn5t618_usb_get_property()
603 val->intval = FROM_CUR_REG(regval); in rn5t618_usb_get_property()
607 if (!info->channel_vusb) in rn5t618_usb_get_property()
608 return -ENODATA; in rn5t618_usb_get_property()
610 ret = iio_read_channel_processed_scale(info->channel_vusb, &val->intval, 1000); in rn5t618_usb_get_property()
616 return -EINVAL; in rn5t618_usb_get_property()
631 if (val->intval > USB_MAX_CUR) in rn5t618_usb_set_property()
632 return -EINVAL; in rn5t618_usb_set_property()
634 if (val->intval < CHG_MIN_CUR) in rn5t618_usb_set_property()
635 return -EINVAL; in rn5t618_usb_set_property()
637 ret = regmap_write(info->rn5t618->regmap, RN5T618_REGISET2, in rn5t618_usb_set_property()
638 0xE0 | TO_CUR_REG(val->intval)); in rn5t618_usb_set_property()
644 return -EINVAL; in rn5t618_usb_set_property()
662 .name = "rn5t618-battery",
672 .name = "rn5t618-adp",
682 .name = "rn5t618-usb",
700 regmap_read(info->rn5t618->regmap, RN5T618_CHGERR_IRR, &err); in rn5t618_charger_irq()
701 regmap_read(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, &ctrl); in rn5t618_charger_irq()
702 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, &stat1); in rn5t618_charger_irq()
703 regmap_read(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, &stat2); in rn5t618_charger_irq()
705 regmap_write(info->rn5t618->regmap, RN5T618_CHGERR_IRR, 0); in rn5t618_charger_irq()
706 regmap_write(info->rn5t618->regmap, RN5T618_CHGCTRL_IRR, 0); in rn5t618_charger_irq()
707 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR1, 0); in rn5t618_charger_irq()
708 regmap_write(info->rn5t618->regmap, RN5T618_CHGSTAT_IRR2, 0); in rn5t618_charger_irq()
713 power_supply_changed(info->usb); in rn5t618_charger_irq()
714 power_supply_changed(info->adp); in rn5t618_charger_irq()
715 power_supply_changed(info->battery); in rn5t618_charger_irq()
727 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in rn5t618_power_probe()
729 return -ENOMEM; in rn5t618_power_probe()
731 info->pdev = pdev; in rn5t618_power_probe()
732 info->rn5t618 = dev_get_drvdata(pdev->dev.parent); in rn5t618_power_probe()
733 info->irq = -1; in rn5t618_power_probe()
737 info->channel_vusb = devm_iio_channel_get(&pdev->dev, "vusb"); in rn5t618_power_probe()
738 if (IS_ERR(info->channel_vusb)) { in rn5t618_power_probe()
739 if (PTR_ERR(info->channel_vusb) == -ENODEV) in rn5t618_power_probe()
740 return -EPROBE_DEFER; in rn5t618_power_probe()
741 return PTR_ERR(info->channel_vusb); in rn5t618_power_probe()
744 info->channel_vadp = devm_iio_channel_get(&pdev->dev, "vadp"); in rn5t618_power_probe()
745 if (IS_ERR(info->channel_vadp)) { in rn5t618_power_probe()
746 if (PTR_ERR(info->channel_vadp) == -ENODEV) in rn5t618_power_probe()
747 return -EPROBE_DEFER; in rn5t618_power_probe()
748 return PTR_ERR(info->channel_vadp); in rn5t618_power_probe()
751 ret = regmap_read(info->rn5t618->regmap, RN5T618_CONTROL, &v); in rn5t618_power_probe()
757 * readers disable the fuel gauge on shutdown. If a kernel in rn5t618_power_probe()
758 * without fuel gauge support is booted after that, the fuel in rn5t618_power_probe()
759 * gauge will get decalibrated. in rn5t618_power_probe()
761 dev_info(&pdev->dev, "Fuel gauge not enabled, enabling now\n"); in rn5t618_power_probe()
762 dev_info(&pdev->dev, "Expect imprecise results\n"); in rn5t618_power_probe()
763 regmap_update_bits(info->rn5t618->regmap, RN5T618_CONTROL, in rn5t618_power_probe()
768 info->battery = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
771 if (IS_ERR(info->battery)) { in rn5t618_power_probe()
772 ret = PTR_ERR(info->battery); in rn5t618_power_probe()
773 dev_err(&pdev->dev, "failed to register battery: %d\n", ret); in rn5t618_power_probe()
777 info->adp = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
780 if (IS_ERR(info->adp)) { in rn5t618_power_probe()
781 ret = PTR_ERR(info->adp); in rn5t618_power_probe()
782 dev_err(&pdev->dev, "failed to register adp: %d\n", ret); in rn5t618_power_probe()
786 info->usb = devm_power_supply_register(&pdev->dev, in rn5t618_power_probe()
789 if (IS_ERR(info->usb)) { in rn5t618_power_probe()
790 ret = PTR_ERR(info->usb); in rn5t618_power_probe()
791 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); in rn5t618_power_probe()
795 if (info->rn5t618->irq_data) in rn5t618_power_probe()
796 info->irq = regmap_irq_get_virq(info->rn5t618->irq_data, in rn5t618_power_probe()
799 if (info->irq < 0) in rn5t618_power_probe()
800 info->irq = -1; in rn5t618_power_probe()
802 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in rn5t618_power_probe()
806 &pdev->dev); in rn5t618_power_probe()
809 dev_err(&pdev->dev, "request IRQ:%d fail\n", in rn5t618_power_probe()
810 info->irq); in rn5t618_power_probe()
811 info->irq = -1; in rn5t618_power_probe()
820 .name = "rn5t618-power",
826 MODULE_ALIAS("platform:rn5t618-power");