Lines Matching +full:use +full:- +full:ilim +full:- +full:pin

1 // SPDX-License-Identifier: GPL-2.0-or-later
211 ret = regmap_field_read(bq->rmap_fields[field_id], &val); in bq24257_field_read()
221 return regmap_field_write(bq->rmap_fields[field_id], val); in bq24257_field_write()
232 return idx - 1; in bq24257_find_idx()
266 * The "External ILIM" and "Production & Test" modes are not exposed in bq24257_get_input_current_limit()
273 return -ENODATA; in bq24257_get_input_current_limit()
275 val->intval = bq24257_iilimit_map[ret]; in bq24257_get_input_current_limit()
285 * while the charger auto-detection mechanism is active. In this in bq24257_set_input_current_limit()
286 * case we want to abort and go straight to the user-specified value. in bq24257_set_input_current_limit()
288 if (bq->iilimit_autoset_enable) in bq24257_set_input_current_limit()
289 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_set_input_current_limit()
292 bq24257_find_idx(val->intval, in bq24257_set_input_current_limit()
304 mutex_lock(&bq->lock); in bq24257_power_supply_get_property()
305 state = bq->state; in bq24257_power_supply_get_property()
306 mutex_unlock(&bq->lock); in bq24257_power_supply_get_property()
311 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq24257_power_supply_get_property()
313 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq24257_power_supply_get_property()
315 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq24257_power_supply_get_property()
317 val->intval = POWER_SUPPLY_STATUS_FULL; in bq24257_power_supply_get_property()
319 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in bq24257_power_supply_get_property()
323 val->strval = BQ24257_MANUFACTURER; in bq24257_power_supply_get_property()
327 val->strval = bq->info->name; in bq24257_power_supply_get_property()
331 val->intval = state.power_good; in bq24257_power_supply_get_property()
337 val->intval = POWER_SUPPLY_HEALTH_GOOD; in bq24257_power_supply_get_property()
342 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in bq24257_power_supply_get_property()
347 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in bq24257_power_supply_get_property()
351 val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; in bq24257_power_supply_get_property()
355 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in bq24257_power_supply_get_property()
362 val->intval = bq24257_ichg_map[bq->init_data.ichg]; in bq24257_power_supply_get_property()
366 val->intval = bq24257_ichg_map[BQ24257_ICHG_MAP_SIZE - 1]; in bq24257_power_supply_get_property()
370 val->intval = bq24257_vbat_map[bq->init_data.vbat]; in bq24257_power_supply_get_property()
374 val->intval = bq24257_vbat_map[BQ24257_VBAT_MAP_SIZE - 1]; in bq24257_power_supply_get_property()
378 val->intval = bq24257_iterm_map[bq->init_data.iterm]; in bq24257_power_supply_get_property()
385 return -EINVAL; in bq24257_power_supply_get_property()
401 return -EINVAL; in bq24257_power_supply_set_property()
425 state->status = ret; in bq24257_get_chip_state()
431 state->fault = ret; in bq24257_get_chip_state()
433 if (bq->pg) in bq24257_get_chip_state()
434 state->power_good = !gpiod_get_value_cansleep(bq->pg); in bq24257_get_chip_state()
437 * If we have a chip without a dedicated power-good GPIO or in bq24257_get_chip_state()
440 * fault - and not good otherwise. There is a possibility for in bq24257_get_chip_state()
444 switch (state->fault) { in bq24257_get_chip_state()
448 state->power_good = false; in bq24257_get_chip_state()
451 state->power_good = true; in bq24257_get_chip_state()
462 mutex_lock(&bq->lock); in bq24257_state_changed()
463 ret = (bq->state.status != new_state->status || in bq24257_state_changed()
464 bq->state.fault != new_state->fault || in bq24257_state_changed()
465 bq->state.power_good != new_state->power_good); in bq24257_state_changed()
466 mutex_unlock(&bq->lock); in bq24257_state_changed()
576 dev_dbg(bq->dev, "port/loop = %d/%d -> iilimit = %d\n", in bq24257_iilimit_autoset()
582 dev_err(bq->dev, "%s: Error communicating with the chip.\n", __func__); in bq24257_iilimit_autoset()
600 mutex_lock(&bq->lock); in bq24257_handle_state_change()
601 old_state = bq->state; in bq24257_handle_state_change()
602 mutex_unlock(&bq->lock); in bq24257_handle_state_change()
605 * Handle BQ2425x state changes observing whether the D+/D- based input in bq24257_handle_state_change()
608 if (!new_state->power_good) { in bq24257_handle_state_change()
609 dev_dbg(bq->dev, "Power removed\n"); in bq24257_handle_state_change()
610 if (bq->iilimit_autoset_enable) { in bq24257_handle_state_change()
611 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_handle_state_change()
613 /* activate D+/D- port detection algorithm */ in bq24257_handle_state_change()
622 ret = bq24257_field_write(bq, F_IILIMIT, bq->init_data.iilimit); in bq24257_handle_state_change()
626 dev_dbg(bq->dev, "Power inserted\n"); in bq24257_handle_state_change()
628 if (bq->iilimit_autoset_enable) in bq24257_handle_state_change()
630 schedule_delayed_work(&bq->iilimit_setup_work, in bq24257_handle_state_change()
632 } else if (new_state->fault == FAULT_NO_BAT) { in bq24257_handle_state_change()
633 dev_warn(bq->dev, "Battery removed\n"); in bq24257_handle_state_change()
634 } else if (new_state->fault == FAULT_TIMER) { in bq24257_handle_state_change()
635 dev_err(bq->dev, "Safety timer expired! Battery dead?\n"); in bq24257_handle_state_change()
641 dev_err(bq->dev, "%s: Error communicating with the chip.\n", __func__); in bq24257_handle_state_change()
657 dev_dbg(bq->dev, "irq(state changed): status/fault/pg = %d/%d/%d\n", in bq24257_irq_handler_thread()
662 mutex_lock(&bq->lock); in bq24257_irq_handler_thread()
663 bq->state = state; in bq24257_irq_handler_thread()
664 mutex_unlock(&bq->lock); in bq24257_irq_handler_thread()
666 power_supply_changed(bq->charger); in bq24257_irq_handler_thread()
681 {F_ICHG, bq->init_data.ichg}, in bq24257_hw_init()
682 {F_VBAT, bq->init_data.vbat}, in bq24257_hw_init()
683 {F_ITERM, bq->init_data.iterm}, in bq24257_hw_init()
684 {F_VOVP, bq->init_data.vovp}, in bq24257_hw_init()
685 {F_VINDPM, bq->init_data.vindpm}, in bq24257_hw_init()
708 mutex_lock(&bq->lock); in bq24257_hw_init()
709 bq->state = state; in bq24257_hw_init()
710 mutex_unlock(&bq->lock); in bq24257_hw_init()
712 if (!bq->iilimit_autoset_enable) { in bq24257_hw_init()
713 dev_dbg(bq->dev, "manually setting iilimit = %u\n", in bq24257_hw_init()
714 bq->init_data.iilimit); in bq24257_hw_init()
718 bq->init_data.iilimit); in bq24257_hw_init()
722 /* activate D+/D- detection algorithm */ in bq24257_hw_init()
745 "main-battery",
749 .name = "bq24257-charger",
765 return sysfs_emit(buf, "%u\n", bq24257_vovp_map[bq->init_data.vovp]); in bq24257_show_ovp_voltage()
775 return sysfs_emit(buf, "%u\n", bq24257_vindpm_map[bq->init_data.vindpm]); in bq24257_show_in_dpm_voltage()
786 if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq24257_sysfs_show_enable()
788 else if (strcmp(attr->attr.name, "sysoff_enable") == 0) in bq24257_sysfs_show_enable()
791 return -EINVAL; in bq24257_sysfs_show_enable()
810 return -EINVAL; in bq24257_sysfs_set_enable()
812 if (strcmp(attr->attr.name, "high_impedance_enable") == 0) in bq24257_sysfs_set_enable()
814 else if (strcmp(attr->attr.name, "sysoff_enable") == 0) in bq24257_sysfs_set_enable()
817 return -EINVAL; in bq24257_sysfs_set_enable()
850 bq->charger = devm_power_supply_register(bq->dev, in bq24257_power_supply_init()
854 return PTR_ERR_OR_ZERO(bq->charger); in bq24257_power_supply_init()
859 bq->pg = devm_gpiod_get_optional(bq->dev, BQ24257_PG_GPIO, GPIOD_IN); in bq24257_pg_gpio_probe()
861 if (PTR_ERR(bq->pg) == -EPROBE_DEFER) { in bq24257_pg_gpio_probe()
862 dev_info(bq->dev, "probe retry requested for PG pin\n"); in bq24257_pg_gpio_probe()
864 } else if (IS_ERR(bq->pg)) { in bq24257_pg_gpio_probe()
865 dev_err(bq->dev, "error probing PG pin\n"); in bq24257_pg_gpio_probe()
866 bq->pg = NULL; in bq24257_pg_gpio_probe()
870 if (bq->pg) in bq24257_pg_gpio_probe()
871 dev_dbg(bq->dev, "probed PG pin = %d\n", desc_to_gpio(bq->pg)); in bq24257_pg_gpio_probe()
880 ret = device_property_read_u32(bq->dev, "ti,charge-current", &property); in bq24257_fw_probe()
884 bq->init_data.ichg = bq24257_find_idx(property, bq24257_ichg_map, in bq24257_fw_probe()
887 ret = device_property_read_u32(bq->dev, "ti,battery-regulation-voltage", in bq24257_fw_probe()
892 bq->init_data.vbat = bq24257_find_idx(property, bq24257_vbat_map, in bq24257_fw_probe()
895 ret = device_property_read_u32(bq->dev, "ti,termination-current", in bq24257_fw_probe()
900 bq->init_data.iterm = bq24257_find_idx(property, bq24257_iterm_map, in bq24257_fw_probe()
903 /* Optional properties. If not provided use reasonable default. */ in bq24257_fw_probe()
904 ret = device_property_read_u32(bq->dev, "ti,current-limit", in bq24257_fw_probe()
907 bq->iilimit_autoset_enable = true; in bq24257_fw_probe()
914 bq->init_data.iilimit = IILIMIT_500; in bq24257_fw_probe()
916 bq->init_data.iilimit = in bq24257_fw_probe()
921 ret = device_property_read_u32(bq->dev, "ti,ovp-voltage", in bq24257_fw_probe()
924 bq->init_data.vovp = VOVP_6500; in bq24257_fw_probe()
926 bq->init_data.vovp = bq24257_find_idx(property, in bq24257_fw_probe()
930 ret = device_property_read_u32(bq->dev, "ti,in-dpm-voltage", in bq24257_fw_probe()
933 bq->init_data.vindpm = VINDPM_4360; in bq24257_fw_probe()
935 bq->init_data.vindpm = in bq24257_fw_probe()
945 struct i2c_adapter *adapter = client->adapter; in bq24257_probe()
946 struct device *dev = &client->dev; in bq24257_probe()
953 return -ENODEV; in bq24257_probe()
958 return -ENOMEM; in bq24257_probe()
960 bq->client = client; in bq24257_probe()
961 bq->dev = dev; in bq24257_probe()
963 bq->info = i2c_get_match_data(client); in bq24257_probe()
964 if (!bq->info) in bq24257_probe()
965 return dev_err_probe(dev, -ENODEV, "Failed to match device\n"); in bq24257_probe()
967 mutex_init(&bq->lock); in bq24257_probe()
969 bq->rmap = devm_regmap_init_i2c(client, &bq24257_regmap_config); in bq24257_probe()
970 if (IS_ERR(bq->rmap)) { in bq24257_probe()
972 return PTR_ERR(bq->rmap); in bq24257_probe()
978 bq->rmap_fields[i] = devm_regmap_field_alloc(dev, bq->rmap, in bq24257_probe()
980 if (IS_ERR(bq->rmap_fields[i])) { in bq24257_probe()
982 return PTR_ERR(bq->rmap_fields[i]); in bq24257_probe()
988 if (!dev->platform_data) { in bq24257_probe()
995 return -ENODEV; in bq24257_probe()
999 * The BQ24250 doesn't support the D+/D- based charger type detection in bq24257_probe()
1003 if (bq->info->chip == BQ24250) in bq24257_probe()
1004 bq->iilimit_autoset_enable = false; in bq24257_probe()
1006 if (bq->iilimit_autoset_enable) in bq24257_probe()
1007 INIT_DELAYED_WORK(&bq->iilimit_setup_work, in bq24257_probe()
1011 * The BQ24250 doesn't have a dedicated Power Good (PG) pin so let's in bq24257_probe()
1012 * not probe for it and instead use a SW-based approach to determine in bq24257_probe()
1013 * the PG state. We also use a SW-based approach for all other devices in bq24257_probe()
1014 * if the PG pin is either not defined or can't be probed. in bq24257_probe()
1016 if (bq->info->chip != BQ24250) in bq24257_probe()
1019 if (PTR_ERR(bq->pg) == -EPROBE_DEFER) in bq24257_probe()
1020 return PTR_ERR(bq->pg); in bq24257_probe()
1021 else if (!bq->pg) in bq24257_probe()
1022 dev_info(bq->dev, "using SW-based power-good detection\n"); in bq24257_probe()
1050 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq24257_probe()
1054 bq->info->name, bq); in bq24257_probe()
1056 dev_err(dev, "Failed to request IRQ #%d\n", client->irq); in bq24257_probe()
1067 if (bq->iilimit_autoset_enable) in bq24257_remove()
1068 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_remove()
1079 if (bq->iilimit_autoset_enable) in bq24257_suspend()
1080 cancel_delayed_work_sync(&bq->iilimit_setup_work); in bq24257_suspend()
1085 dev_err(bq->dev, "Cannot reset chip to standalone mode.\n"); in bq24257_suspend()
1095 ret = regcache_drop_region(bq->rmap, BQ24257_REG_1, BQ24257_REG_7); in bq24257_resume()
1105 dev_err(bq->dev, "Cannot init chip after resume.\n"); in bq24257_resume()
1110 power_supply_changed(bq->charger); in bq24257_resume()
1163 .name = "bq24257-charger",