Lines Matching +full:avg +full:- +full:input +full:- +full:current +full:- +full:regulation

1 // SPDX-License-Identifier: GPL-2.0-or-later
21 #define RT9455_DRIVER_NAME "rt9455-charger"
165 #define GET_MASK(fid) (BIT(rt9455_reg_fields[fid].msb + 1) - \
169 * Each array initialised below shows the possible real-world values for a
171 * ascending order. The index of each real-world value represents the value
180 * When the charger is in charge mode, REG02[7:2] represent battery regulation
263 for (i = 0; i < tbl_size - 1; i++) in rt9455_find_idx()
267 return (tbl_size - 1); in rt9455_find_idx()
277 ret = regmap_field_read(info->regmap_fields[field], &v); in rt9455_get_field_val()
281 v = (v >= tbl_size) ? (tbl_size - 1) : v; in rt9455_get_field_val()
293 return regmap_field_write(info->regmap_fields[field], idx); in rt9455_set_field_val()
298 struct device *dev = &info->client->dev; in rt9455_register_reset()
302 ret = regmap_field_write(info->regmap_fields[F_RST], 0x01); in rt9455_register_reset()
313 ret = regmap_field_read(info->regmap_fields[F_RST], &v); in rt9455_register_reset()
323 } while (--limit); in rt9455_register_reset()
326 return -EIO; in rt9455_register_reset()
348 "main-battery",
357 ret = regmap_field_read(info->regmap_fields[F_PWR_RDY], in rt9455_charger_get_status()
360 dev_err(&info->client->dev, "Failed to read PWR_RDY bit\n"); in rt9455_charger_get_status()
369 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in rt9455_charger_get_status()
373 ret = regmap_field_read(info->regmap_fields[F_STAT], &v); in rt9455_charger_get_status()
375 dev_err(&info->client->dev, "Failed to read STAT bits\n"); in rt9455_charger_get_status()
389 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rt9455_charger_get_status()
392 val->intval = POWER_SUPPLY_STATUS_CHARGING; in rt9455_charger_get_status()
395 val->intval = POWER_SUPPLY_STATUS_FULL; in rt9455_charger_get_status()
398 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in rt9455_charger_get_status()
406 struct device *dev = &info->client->dev; in rt9455_charger_get_health()
410 val->intval = POWER_SUPPLY_HEALTH_GOOD; in rt9455_charger_get_health()
412 ret = regmap_read(info->regmap, RT9455_REG_IRQ1, &v); in rt9455_charger_get_health()
419 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in rt9455_charger_get_health()
423 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in rt9455_charger_get_health()
427 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in rt9455_charger_get_health()
431 ret = regmap_read(info->regmap, RT9455_REG_IRQ2, &v); in rt9455_charger_get_health()
438 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in rt9455_charger_get_health()
442 val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; in rt9455_charger_get_health()
446 ret = regmap_read(info->regmap, RT9455_REG_IRQ3, &v); in rt9455_charger_get_health()
453 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in rt9455_charger_get_health()
457 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in rt9455_charger_get_health()
461 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in rt9455_charger_get_health()
465 val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; in rt9455_charger_get_health()
469 ret = regmap_field_read(info->regmap_fields[F_STAT], &v); in rt9455_charger_get_health()
476 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in rt9455_charger_get_health()
489 ret = regmap_field_read(info->regmap_fields[F_BATAB], &v); in rt9455_charger_get_battery_presence()
491 dev_err(&info->client->dev, "Failed to read BATAB bit\n"); in rt9455_charger_get_battery_presence()
499 val->intval = !v; in rt9455_charger_get_battery_presence()
510 ret = regmap_field_read(info->regmap_fields[F_PWR_RDY], &v); in rt9455_charger_get_online()
512 dev_err(&info->client->dev, "Failed to read PWR_RDY bit\n"); in rt9455_charger_get_online()
516 val->intval = (int)v; in rt9455_charger_get_online()
532 dev_err(&info->client->dev, "Failed to read ICHRG value\n"); in rt9455_charger_get_current()
536 val->intval = curr; in rt9455_charger_get_current()
544 int idx = ARRAY_SIZE(rt9455_ichrg_values) - 1; in rt9455_charger_get_current_max()
546 val->intval = rt9455_ichrg_values[idx]; in rt9455_charger_get_current_max()
562 dev_err(&info->client->dev, "Failed to read VOREG value\n"); in rt9455_charger_get_voltage()
566 val->intval = voltage; in rt9455_charger_get_voltage()
574 int idx = ARRAY_SIZE(rt9455_vmreg_values) - 1; in rt9455_charger_get_voltage_max()
576 val->intval = rt9455_vmreg_values[idx]; in rt9455_charger_get_voltage_max()
584 struct device *dev = &info->client->dev; in rt9455_charger_get_term_current()
605 val->intval = ichrg * ieoc_percentage / 100; in rt9455_charger_get_term_current()
634 val->intval = POWER_SUPPLY_SCOPE_SYSTEM; in rt9455_charger_get_property()
639 val->strval = RT9455_MODEL_NAME; in rt9455_charger_get_property()
642 val->strval = RT9455_MANUFACTURER; in rt9455_charger_get_property()
645 return -ENODATA; in rt9455_charger_get_property()
653 struct device *dev = &info->client->dev; in rt9455_hw_init()
663 ret = regmap_field_write(info->regmap_fields[F_TE], 1); in rt9455_hw_init()
670 ret = regmap_field_write(info->regmap_fields[F_TE_SHDN_EN], 1); in rt9455_hw_init()
680 ret = regmap_field_write(info->regmap_fields[F_BATD_EN], 1); in rt9455_hw_init()
697 ret = regmap_field_write(info->regmap_fields[F_TMR_EN], 0x00); in rt9455_hw_init()
703 /* Set ICHRG to value retrieved from device-specific data */ in rt9455_hw_init()
712 /* Set IEOC Percentage to value retrieved from device-specific data */ in rt9455_hw_init()
722 /* Set VOREG to value retrieved from device-specific data */ in rt9455_hw_init()
726 info->voreg); in rt9455_hw_init()
733 idx = ARRAY_SIZE(rt9455_vmreg_values) - 1; in rt9455_hw_init()
744 * Set MIVR to value retrieved from device-specific data. in rt9455_hw_init()
747 if (mivr == -1) in rt9455_hw_init()
759 * Set IAICR to value retrieved from device-specific data. in rt9455_hw_init()
762 if (iaicr == -1) in rt9455_hw_init()
777 ret = regmap_field_write(info->regmap_fields[F_IAICR_INT], 0x01); in rt9455_hw_init()
788 ret = regmap_field_write(info->regmap_fields[F_CHMIVRIM], 0x01); in rt9455_hw_init()
801 * regulation voltage. F_VOREG bits represent either battery regulation voltage
803 * regulation voltage and boost output voltage are read from DT/ACPI during
808 struct device *dev = &info->client->dev; in rt9455_set_boost_voltage_before_boost_mode()
814 info->boost_voltage); in rt9455_set_boost_voltage_before_boost_mode()
825 * Before setting the charger into charge mode, battery regulation voltage is
827 * regulation voltage. F_VOREG bits represent either battery regulation voltage
829 * regulation voltage and boost output voltage are read from DT/ACPI during
834 struct device *dev = &info->client->dev; in rt9455_set_voreg_before_charge_mode()
840 info->voreg); in rt9455_set_voreg_before_charge_mode()
854 struct device *dev = &info->client->dev; in rt9455_irq_handler_check_irq1_register()
859 ret = regmap_read(info->regmap, RT9455_REG_IRQ1, &irq1); in rt9455_irq_handler_check_irq1_register()
865 ret = regmap_read(info->regmap, RT9455_REG_MASK1, &mask1); in rt9455_irq_handler_check_irq1_register()
877 dev_err(dev, "Overvoltage input occurred\n"); in rt9455_irq_handler_check_irq1_register()
887 ret = regmap_field_write(info->regmap_fields[F_BATABM], in rt9455_irq_handler_check_irq1_register()
895 ret = regmap_read(info->regmap, RT9455_REG_MASK2, &mask2); in rt9455_irq_handler_check_irq1_register()
903 info->regmap_fields[F_CHTERMIM], 0x00); in rt9455_irq_handler_check_irq1_register()
912 info->regmap_fields[F_CHRCHGIM], 0x00); in rt9455_irq_handler_check_irq1_register()
923 cancel_delayed_work_sync(&info->max_charging_time_work); in rt9455_irq_handler_check_irq1_register()
931 &info->batt_presence_work, in rt9455_irq_handler_check_irq1_register()
948 struct device *dev = &info->client->dev; in rt9455_irq_handler_check_irq2_register()
952 ret = regmap_read(info->regmap, RT9455_REG_IRQ2, &irq2); in rt9455_irq_handler_check_irq2_register()
958 ret = regmap_read(info->regmap, RT9455_REG_MASK2, &mask2); in rt9455_irq_handler_check_irq2_register()
978 &info->pwr_rdy_work, in rt9455_irq_handler_check_irq2_register()
990 info->regmap_fields[F_CHTERMIM], 0x01); in rt9455_irq_handler_check_irq2_register()
1001 cancel_delayed_work_sync(&info->max_charging_time_work); in rt9455_irq_handler_check_irq2_register()
1007 ret = regmap_field_write(info->regmap_fields[F_CHG_EN], in rt9455_irq_handler_check_irq2_register()
1015 info->regmap_fields[F_CHTERMIM], 0x00); in rt9455_irq_handler_check_irq2_register()
1031 &info->max_charging_time_work, in rt9455_irq_handler_check_irq2_register()
1042 "Charger warning. Thermal regulation loop active\n"); in rt9455_irq_handler_check_irq2_register()
1047 "Charger warning. Input voltage MIVR loop active\n"); in rt9455_irq_handler_check_irq2_register()
1060 struct device *dev = &info->client->dev; in rt9455_irq_handler_check_irq3_register()
1064 ret = regmap_read(info->regmap, RT9455_REG_IRQ3, &irq3); in rt9455_irq_handler_check_irq3_register()
1070 ret = regmap_read(info->regmap, RT9455_REG_MASK3, &mask3); in rt9455_irq_handler_check_irq3_register()
1077 dev_err(dev, "Boost fault. Overvoltage input occurred\n"); in rt9455_irq_handler_check_irq3_register()
1100 ret = regmap_field_write(info->regmap_fields[F_OPA_MODE], in rt9455_irq_handler_check_irq3_register()
1124 dev = &info->client->dev; in rt9455_irq_handler_thread()
1126 if (irq != info->client->irq) { in rt9455_irq_handler_thread()
1131 ret = regmap_field_read(info->regmap_fields[F_STAT], &status); in rt9455_irq_handler_thread()
1175 if (info->charger) in rt9455_irq_handler_thread()
1176 power_supply_changed(info->charger); in rt9455_irq_handler_thread()
1186 struct device *dev = &info->client->dev; in rt9455_discover_charger()
1189 if (!dev->of_node && !ACPI_HANDLE(dev)) { in rt9455_discover_charger()
1191 return -EINVAL; in rt9455_discover_charger()
1197 ret = device_property_read_u32(dev, "richtek,output-charge-current", in rt9455_discover_charger()
1200 dev_err(dev, "Error: missing \"output-charge-current\" property\n"); in rt9455_discover_charger()
1204 ret = device_property_read_u32(dev, "richtek,end-of-charge-percentage", in rt9455_discover_charger()
1207 dev_err(dev, "Error: missing \"end-of-charge-percentage\" property\n"); in rt9455_discover_charger()
1212 "richtek,battery-regulation-voltage", in rt9455_discover_charger()
1213 &info->voreg); in rt9455_discover_charger()
1215 dev_err(dev, "Error: missing \"battery-regulation-voltage\" property\n"); in rt9455_discover_charger()
1219 ret = device_property_read_u32(dev, "richtek,boost-output-voltage", in rt9455_discover_charger()
1220 &info->boost_voltage); in rt9455_discover_charger()
1222 dev_err(dev, "Error: missing \"boost-output-voltage\" property\n"); in rt9455_discover_charger()
1230 device_property_read_u32(dev, "richtek,min-input-voltage-regulation", in rt9455_discover_charger()
1232 device_property_read_u32(dev, "richtek,avg-input-current-regulation", in rt9455_discover_charger()
1242 struct device *dev = &info->client->dev; in rt9455_usb_event_none()
1258 ret = regmap_field_write(info->regmap_fields[F_OPA_MODE], in rt9455_usb_event_none()
1268 ret = regmap_field_write(info->regmap_fields[F_IAICR], in rt9455_usb_event_none()
1282 struct device *dev = &info->client->dev; in rt9455_usb_event_vbus()
1298 ret = regmap_field_write(info->regmap_fields[F_OPA_MODE], in rt9455_usb_event_vbus()
1308 ret = regmap_field_write(info->regmap_fields[F_IAICR], in rt9455_usb_event_vbus()
1322 struct device *dev = &info->client->dev; in rt9455_usb_event_id()
1338 ret = regmap_field_write(info->regmap_fields[F_OPA_MODE], in rt9455_usb_event_id()
1348 ret = regmap_field_write(info->regmap_fields[F_IAICR], in rt9455_usb_event_id()
1362 struct device *dev = &info->client->dev; in rt9455_usb_event_charger()
1378 ret = regmap_field_write(info->regmap_fields[F_OPA_MODE], in rt9455_usb_event_charger()
1386 dev_dbg(dev, "USB_EVENT_CHARGER received, therefore IAICR is set to no current limit\n"); in rt9455_usb_event_charger()
1388 ret = regmap_field_write(info->regmap_fields[F_IAICR], in rt9455_usb_event_charger()
1403 struct device *dev = &info->client->dev; in rt9455_usb_event()
1411 ret = regmap_field_read(info->regmap_fields[F_OPA_MODE], in rt9455_usb_event()
1418 ret = regmap_field_read(info->regmap_fields[F_IAICR], in rt9455_usb_event()
1446 struct device *dev = &info->client->dev; in rt9455_pwr_rdy_work_callback()
1450 ret = regmap_field_read(info->regmap_fields[F_PWR_RDY], &pwr_rdy); in rt9455_pwr_rdy_work_callback()
1458 cancel_delayed_work_sync(&info->max_charging_time_work); in rt9455_pwr_rdy_work_callback()
1462 ret = regmap_field_write(info->regmap_fields[F_CHG_EN], in rt9455_pwr_rdy_work_callback()
1469 &info->max_charging_time_work, in rt9455_pwr_rdy_work_callback()
1477 power_supply_changed(info->charger); in rt9455_pwr_rdy_work_callback()
1484 struct device *dev = &info->client->dev; in rt9455_max_charging_time_work_callback()
1488 ret = regmap_field_write(info->regmap_fields[F_CHG_EN], in rt9455_max_charging_time_work_callback()
1498 struct device *dev = &info->client->dev; in rt9455_batt_presence_work_callback()
1502 ret = regmap_read(info->regmap, RT9455_REG_IRQ1, &irq1); in rt9455_batt_presence_work_callback()
1514 &info->batt_presence_work, in rt9455_batt_presence_work_callback()
1518 &info->max_charging_time_work, in rt9455_batt_presence_work_callback()
1521 ret = regmap_read(info->regmap, RT9455_REG_MASK1, &mask1); in rt9455_batt_presence_work_callback()
1528 ret = regmap_field_write(info->regmap_fields[F_BATABM], in rt9455_batt_presence_work_callback()
1537 power_supply_changed(info->charger); in rt9455_batt_presence_work_callback()
1585 struct i2c_adapter *adapter = client->adapter; in rt9455_probe()
1586 struct device *dev = &client->dev; in rt9455_probe()
1590 * Mandatory device-specific data values. Also, VOREG and boost output in rt9455_probe()
1595 /* Optional device-specific data values. */ in rt9455_probe()
1596 u32 mivr = -1, iaicr = -1; in rt9455_probe()
1601 return -ENODEV; in rt9455_probe()
1605 return -ENOMEM; in rt9455_probe()
1607 info->client = client; in rt9455_probe()
1610 info->regmap = devm_regmap_init_i2c(client, in rt9455_probe()
1612 if (IS_ERR(info->regmap)) { in rt9455_probe()
1614 return -EINVAL; in rt9455_probe()
1618 info->regmap_fields[i] = in rt9455_probe()
1619 devm_regmap_field_alloc(dev, info->regmap, in rt9455_probe()
1621 if (IS_ERR(info->regmap_fields[i])) { in rt9455_probe()
1624 return PTR_ERR(info->regmap_fields[i]); in rt9455_probe()
1636 info->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in rt9455_probe()
1637 if (IS_ERR(info->usb_phy)) { in rt9455_probe()
1640 info->nb.notifier_call = rt9455_usb_event; in rt9455_probe()
1641 ret = usb_register_notifier(info->usb_phy, &info->nb); in rt9455_probe()
1648 info->nb.notifier_call = NULL; in rt9455_probe()
1653 INIT_DEFERRABLE_WORK(&info->pwr_rdy_work, rt9455_pwr_rdy_work_callback); in rt9455_probe()
1654 INIT_DEFERRABLE_WORK(&info->max_charging_time_work, in rt9455_probe()
1656 INIT_DEFERRABLE_WORK(&info->batt_presence_work, in rt9455_probe()
1659 rt9455_charger_config.of_node = dev->of_node; in rt9455_probe()
1664 ret = devm_request_threaded_irq(dev, client->irq, NULL, in rt9455_probe()
1679 info->charger = devm_power_supply_register(dev, &rt9455_charger_desc, in rt9455_probe()
1681 if (IS_ERR(info->charger)) { in rt9455_probe()
1683 ret = PTR_ERR(info->charger); in rt9455_probe()
1691 if (info->nb.notifier_call) { in rt9455_probe()
1692 usb_unregister_notifier(info->usb_phy, &info->nb); in rt9455_probe()
1693 info->nb.notifier_call = NULL; in rt9455_probe()
1706 dev_err(&info->client->dev, "Failed to set charger to its default values\n"); in rt9455_remove()
1709 if (info->nb.notifier_call) in rt9455_remove()
1710 usb_unregister_notifier(info->usb_phy, &info->nb); in rt9455_remove()
1713 cancel_delayed_work_sync(&info->pwr_rdy_work); in rt9455_remove()
1714 cancel_delayed_work_sync(&info->max_charging_time_work); in rt9455_remove()
1715 cancel_delayed_work_sync(&info->batt_presence_work); in rt9455_remove()
1751 MODULE_AUTHOR("Anda-Maria Nicolae <anda-maria.nicolae@intel.com>");