Lines Matching +full:ilim +full:- +full:ma

1 // SPDX-License-Identifier: GPL-2.0-or-later
216 ret = regmap_field_read(bq->rmap_fields[field_id], &val); in bq24257_field_read()
226 return regmap_field_write(bq->rmap_fields[field_id], val); in bq24257_field_write()
237 return idx - 1; in bq24257_find_idx()
271 * The "External ILIM" and "Production & Test" modes are not exposed in bq24257_get_input_current_limit()
278 return -ENODATA; in bq24257_get_input_current_limit()
280 val->intval = bq24257_iilimit_map[ret]; in bq24257_get_input_current_limit()
290 * while the charger auto-detection mechanism is active. In this in bq24257_set_input_current_limit()
291 * case we want to abort and go straight to the user-specified value. in bq24257_set_input_current_limit()
293 if (bq->iilimit_autoset_enable) in bq24257_set_input_current_limit()
294 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_set_input_current_limit()
297 bq24257_find_idx(val->intval, in bq24257_set_input_current_limit()
309 mutex_lock(&bq->lock); in bq24257_power_supply_get_property()
310 state = bq->state; in bq24257_power_supply_get_property()
311 mutex_unlock(&bq->lock); in bq24257_power_supply_get_property()
316 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq24257_power_supply_get_property()
318 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq24257_power_supply_get_property()
320 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq24257_power_supply_get_property()
322 val->intval = POWER_SUPPLY_STATUS_FULL; in bq24257_power_supply_get_property()
324 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in bq24257_power_supply_get_property()
328 val->strval = BQ24257_MANUFACTURER; in bq24257_power_supply_get_property()
332 val->strval = bq2425x_chip_name[bq->chip]; in bq24257_power_supply_get_property()
336 val->intval = state.power_good; in bq24257_power_supply_get_property()
342 val->intval = POWER_SUPPLY_HEALTH_GOOD; in bq24257_power_supply_get_property()
347 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in bq24257_power_supply_get_property()
352 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in bq24257_power_supply_get_property()
356 val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; in bq24257_power_supply_get_property()
360 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in bq24257_power_supply_get_property()
367 val->intval = bq24257_ichg_map[bq->init_data.ichg]; in bq24257_power_supply_get_property()
371 val->intval = bq24257_ichg_map[BQ24257_ICHG_MAP_SIZE - 1]; in bq24257_power_supply_get_property()
375 val->intval = bq24257_vbat_map[bq->init_data.vbat]; in bq24257_power_supply_get_property()
379 val->intval = bq24257_vbat_map[BQ24257_VBAT_MAP_SIZE - 1]; in bq24257_power_supply_get_property()
383 val->intval = bq24257_iterm_map[bq->init_data.iterm]; in bq24257_power_supply_get_property()
390 return -EINVAL; in bq24257_power_supply_get_property()
406 return -EINVAL; in bq24257_power_supply_set_property()
430 state->status = ret; in bq24257_get_chip_state()
436 state->fault = ret; in bq24257_get_chip_state()
438 if (bq->pg) in bq24257_get_chip_state()
439 state->power_good = !gpiod_get_value_cansleep(bq->pg); in bq24257_get_chip_state()
442 * If we have a chip without a dedicated power-good GPIO or in bq24257_get_chip_state()
445 * fault - and not good otherwise. There is a possibility for in bq24257_get_chip_state()
449 switch (state->fault) { in bq24257_get_chip_state()
453 state->power_good = false; in bq24257_get_chip_state()
456 state->power_good = true; in bq24257_get_chip_state()
467 mutex_lock(&bq->lock); in bq24257_state_changed()
468 ret = (bq->state.status != new_state->status || in bq24257_state_changed()
469 bq->state.fault != new_state->fault || in bq24257_state_changed()
470 bq->state.power_good != new_state->power_good); in bq24257_state_changed()
471 mutex_unlock(&bq->lock); in bq24257_state_changed()
556 * All USB ports should be able to handle 500mA. If not, DPM will lower in bq24257_iilimit_autoset()
581 dev_dbg(bq->dev, "port/loop = %d/%d -> iilimit = %d\n", in bq24257_iilimit_autoset()
587 dev_err(bq->dev, "%s: Error communicating with the chip.\n", __func__); in bq24257_iilimit_autoset()
605 mutex_lock(&bq->lock); in bq24257_handle_state_change()
606 old_state = bq->state; in bq24257_handle_state_change()
607 mutex_unlock(&bq->lock); in bq24257_handle_state_change()
610 * Handle BQ2425x state changes observing whether the D+/D- based input in bq24257_handle_state_change()
613 if (!new_state->power_good) { in bq24257_handle_state_change()
614 dev_dbg(bq->dev, "Power removed\n"); in bq24257_handle_state_change()
615 if (bq->iilimit_autoset_enable) { in bq24257_handle_state_change()
616 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_handle_state_change()
618 /* activate D+/D- port detection algorithm */ in bq24257_handle_state_change()
627 ret = bq24257_field_write(bq, F_IILIMIT, bq->init_data.iilimit); in bq24257_handle_state_change()
631 dev_dbg(bq->dev, "Power inserted\n"); in bq24257_handle_state_change()
633 if (bq->iilimit_autoset_enable) in bq24257_handle_state_change()
635 schedule_delayed_work(&bq->iilimit_setup_work, in bq24257_handle_state_change()
637 } else if (new_state->fault == FAULT_NO_BAT) { in bq24257_handle_state_change()
638 dev_warn(bq->dev, "Battery removed\n"); in bq24257_handle_state_change()
639 } else if (new_state->fault == FAULT_TIMER) { in bq24257_handle_state_change()
640 dev_err(bq->dev, "Safety timer expired! Battery dead?\n"); in bq24257_handle_state_change()
646 dev_err(bq->dev, "%s: Error communicating with the chip.\n", __func__); in bq24257_handle_state_change()
662 dev_dbg(bq->dev, "irq(state changed): status/fault/pg = %d/%d/%d\n", in bq24257_irq_handler_thread()
667 mutex_lock(&bq->lock); in bq24257_irq_handler_thread()
668 bq->state = state; in bq24257_irq_handler_thread()
669 mutex_unlock(&bq->lock); in bq24257_irq_handler_thread()
671 power_supply_changed(bq->charger); in bq24257_irq_handler_thread()
686 {F_ICHG, bq->init_data.ichg}, in bq24257_hw_init()
687 {F_VBAT, bq->init_data.vbat}, in bq24257_hw_init()
688 {F_ITERM, bq->init_data.iterm}, in bq24257_hw_init()
689 {F_VOVP, bq->init_data.vovp}, in bq24257_hw_init()
690 {F_VINDPM, bq->init_data.vindpm}, in bq24257_hw_init()
713 mutex_lock(&bq->lock); in bq24257_hw_init()
714 bq->state = state; in bq24257_hw_init()
715 mutex_unlock(&bq->lock); in bq24257_hw_init()
717 if (!bq->iilimit_autoset_enable) { in bq24257_hw_init()
718 dev_dbg(bq->dev, "manually setting iilimit = %u\n", in bq24257_hw_init()
719 bq->init_data.iilimit); in bq24257_hw_init()
723 bq->init_data.iilimit); in bq24257_hw_init()
727 /* activate D+/D- detection algorithm */ in bq24257_hw_init()
750 "main-battery",
754 .name = "bq24257-charger",
771 bq24257_vovp_map[bq->init_data.vovp]); in bq24257_show_ovp_voltage()
782 bq24257_vindpm_map[bq->init_data.vindpm]); in bq24257_show_in_dpm_voltage()
793 if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq24257_sysfs_show_enable()
795 else if (strcmp(attr->attr.name, "sysoff_enable") == 0) in bq24257_sysfs_show_enable()
798 return -EINVAL; in bq24257_sysfs_show_enable()
817 return -EINVAL; in bq24257_sysfs_set_enable()
819 if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq24257_sysfs_set_enable()
821 else if (strcmp(attr->attr.name, "sysoff_enable") == 0) in bq24257_sysfs_set_enable()
824 return -EINVAL; in bq24257_sysfs_set_enable()
857 bq->charger = devm_power_supply_register(bq->dev, in bq24257_power_supply_init()
861 return PTR_ERR_OR_ZERO(bq->charger); in bq24257_power_supply_init()
866 bq->pg = devm_gpiod_get_optional(bq->dev, BQ24257_PG_GPIO, GPIOD_IN); in bq24257_pg_gpio_probe()
868 if (PTR_ERR(bq->pg) == -EPROBE_DEFER) { in bq24257_pg_gpio_probe()
869 dev_info(bq->dev, "probe retry requested for PG pin\n"); in bq24257_pg_gpio_probe()
871 } else if (IS_ERR(bq->pg)) { in bq24257_pg_gpio_probe()
872 dev_err(bq->dev, "error probing PG pin\n"); in bq24257_pg_gpio_probe()
873 bq->pg = NULL; in bq24257_pg_gpio_probe()
877 if (bq->pg) in bq24257_pg_gpio_probe()
878 dev_dbg(bq->dev, "probed PG pin = %d\n", desc_to_gpio(bq->pg)); in bq24257_pg_gpio_probe()
887 ret = device_property_read_u32(bq->dev, "ti,charge-current", &property); in bq24257_fw_probe()
891 bq->init_data.ichg = bq24257_find_idx(property, bq24257_ichg_map, in bq24257_fw_probe()
894 ret = device_property_read_u32(bq->dev, "ti,battery-regulation-voltage", in bq24257_fw_probe()
899 bq->init_data.vbat = bq24257_find_idx(property, bq24257_vbat_map, in bq24257_fw_probe()
902 ret = device_property_read_u32(bq->dev, "ti,termination-current", in bq24257_fw_probe()
907 bq->init_data.iterm = bq24257_find_idx(property, bq24257_iterm_map, in bq24257_fw_probe()
911 ret = device_property_read_u32(bq->dev, "ti,current-limit", in bq24257_fw_probe()
914 bq->iilimit_autoset_enable = true; in bq24257_fw_probe()
921 bq->init_data.iilimit = IILIMIT_500; in bq24257_fw_probe()
923 bq->init_data.iilimit = in bq24257_fw_probe()
928 ret = device_property_read_u32(bq->dev, "ti,ovp-voltage", in bq24257_fw_probe()
931 bq->init_data.vovp = VOVP_6500; in bq24257_fw_probe()
933 bq->init_data.vovp = bq24257_find_idx(property, in bq24257_fw_probe()
937 ret = device_property_read_u32(bq->dev, "ti,in-dpm-voltage", in bq24257_fw_probe()
940 bq->init_data.vindpm = VINDPM_4360; in bq24257_fw_probe()
942 bq->init_data.vindpm = in bq24257_fw_probe()
953 struct i2c_adapter *adapter = client->adapter; in bq24257_probe()
954 struct device *dev = &client->dev; in bq24257_probe()
962 return -ENODEV; in bq24257_probe()
967 return -ENOMEM; in bq24257_probe()
969 bq->client = client; in bq24257_probe()
970 bq->dev = dev; in bq24257_probe()
973 acpi_id = acpi_match_device(dev->driver->acpi_match_table, in bq24257_probe()
974 &client->dev); in bq24257_probe()
977 return -ENODEV; in bq24257_probe()
979 bq->chip = (enum bq2425x_chip)acpi_id->driver_data; in bq24257_probe()
981 bq->chip = (enum bq2425x_chip)id->driver_data; in bq24257_probe()
984 mutex_init(&bq->lock); in bq24257_probe()
986 bq->rmap = devm_regmap_init_i2c(client, &bq24257_regmap_config); in bq24257_probe()
987 if (IS_ERR(bq->rmap)) { in bq24257_probe()
989 return PTR_ERR(bq->rmap); in bq24257_probe()
995 bq->rmap_fields[i] = devm_regmap_field_alloc(dev, bq->rmap, in bq24257_probe()
997 if (IS_ERR(bq->rmap_fields[i])) { in bq24257_probe()
999 return PTR_ERR(bq->rmap_fields[i]); in bq24257_probe()
1005 if (!dev->platform_data) { in bq24257_probe()
1012 return -ENODEV; in bq24257_probe()
1016 * The BQ24250 doesn't support the D+/D- based charger type detection in bq24257_probe()
1020 if (bq->chip == BQ24250) in bq24257_probe()
1021 bq->iilimit_autoset_enable = false; in bq24257_probe()
1023 if (bq->iilimit_autoset_enable) in bq24257_probe()
1024 INIT_DELAYED_WORK(&bq->iilimit_setup_work, in bq24257_probe()
1029 * not probe for it and instead use a SW-based approach to determine in bq24257_probe()
1030 * the PG state. We also use a SW-based approach for all other devices in bq24257_probe()
1033 if (bq->chip != BQ24250) in bq24257_probe()
1036 if (PTR_ERR(bq->pg) == -EPROBE_DEFER) in bq24257_probe()
1037 return PTR_ERR(bq->pg); in bq24257_probe()
1038 else if (!bq->pg) in bq24257_probe()
1039 dev_info(bq->dev, "using SW-based power-good detection\n"); in bq24257_probe()
1067 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq24257_probe()
1071 bq2425x_chip_name[bq->chip], bq); in bq24257_probe()
1073 dev_err(dev, "Failed to request IRQ #%d\n", client->irq); in bq24257_probe()
1084 if (bq->iilimit_autoset_enable) in bq24257_remove()
1085 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_remove()
1096 if (bq->iilimit_autoset_enable) in bq24257_suspend()
1097 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_suspend()
1102 dev_err(bq->dev, "Cannot reset chip to standalone mode.\n"); in bq24257_suspend()
1112 ret = regcache_drop_region(bq->rmap, BQ24257_REG_1, BQ24257_REG_7); in bq24257_resume()
1122 dev_err(bq->dev, "Cannot init chip after resume.\n"); in bq24257_resume()
1127 power_supply_changed(bq->charger); in bq24257_resume()
1165 .name = "bq24257-charger",