Lines Matching +full:precharge +full:- +full:current +full:- +full:microamp
1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
137 * struct bq2515x_init_data -
138 * @ilim: input current limit
139 * @ichg: fast charge current
141 * @iprechg: precharge current
151 * struct bq2515x_info -
153 * @ilim: input current limit
161 * struct bq2515x_device -
283 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_wake_up()
291 gpiod_set_value_cansleep(bq2515x->powerdown_gpio, 0); in bq2515x_wake_up()
293 gpiod_set_value_cansleep(bq2515x->reset_gpio, 0); in bq2515x_wake_up()
295 gpiod_set_value_cansleep(bq2515x->reset_gpio, 1); in bq2515x_wake_up()
297 return regmap_write(bq2515x->regmap, BQ2515X_ADC_READ_EN, in bq2515x_wake_up()
307 if (bq2515x->ac_detect_gpio) in bq2515x_update_ps_status()
308 val = gpiod_get_value_cansleep(bq2515x->ac_detect_gpio); in bq2515x_update_ps_status()
310 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_update_ps_status()
317 ret = bq2515x->mains_online != dc; in bq2515x_update_ps_status()
319 bq2515x->mains_online = dc; in bq2515x_update_ps_status()
328 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_CHARGERCTRL0, in bq2515x_disable_watchdog_timers()
333 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_disable_watchdog_timers()
344 if (!bq2515x->mains_online) in bq2515x_get_battery_voltage_now()
347 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_M, &vbat_msb); in bq2515x_get_battery_voltage_now()
351 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_L, &vbat_lsb); in bq2515x_get_battery_voltage_now()
372 if (!bq2515x->mains_online) in bq2515x_get_battery_current_now()
373 return -ENODATA; in bq2515x_get_battery_current_now()
375 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_M, &ichg_msb); in bq2515x_get_battery_current_now()
379 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_L, &ichg_lsb); in bq2515x_get_battery_current_now()
385 ret = regmap_read(bq2515x->regmap, BQ2515X_BUVLO, &buvlo); in bq2515x_get_battery_current_now()
395 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_get_battery_current_now()
402 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, in bq2515x_get_battery_current_now()
410 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_battery_current_now()
430 ce_pin = gpiod_get_value_cansleep(bq2515x->ce_gpio); in bq2515x_get_charge_disable()
432 ret = regmap_read(bq2515x->regmap, BQ2515X_ICCTRL2, &icctrl2); in bq2515x_get_charge_disable()
446 gpiod_set_value_cansleep(bq2515x->ce_gpio, val); in bq2515x_set_charge_disable()
448 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_set_charge_disable()
460 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, &ichg_reg_code); in bq2515x_get_const_charge_current()
464 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_const_charge_current()
485 return -EINVAL; in bq2515x_set_const_charge_current()
494 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_const_charge_current()
501 ret = regmap_write(bq2515x->regmap, BQ2515X_ICHG_CTRL, ichg_reg_code); in bq2515x_set_const_charge_current()
516 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_precharge_current()
540 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_set_precharge_current()
554 return -EINVAL; in bq2515x_set_precharge_current()
562 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_precharge_current()
580 if (!bq2515x->mains_online) { in bq2515x_charging_status()
581 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq2515x_charging_status()
585 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &status); in bq2515x_charging_status()
606 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &status); in bq2515x_charging_status()
627 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq2515x_charging_status()
629 val->intval = POWER_SUPPLY_STATUS_FULL; in bq2515x_charging_status()
631 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq2515x_charging_status()
641 ret = regmap_read(bq2515x->regmap, BQ2515X_VBAT_CTRL, &vbat_reg_code); in bq2515x_get_batt_reg()
653 return -EINVAL; in bq2515x_set_batt_reg()
655 vbat_reg_code = (val - BQ2515X_VBAT_BASE_VOLT) / BQ2515X_VBAT_STEP_UV; in bq2515x_set_batt_reg()
657 return regmap_write(bq2515x->regmap, BQ2515X_VBAT_CTRL, vbat_reg_code); in bq2515x_set_batt_reg()
665 ret = regmap_read(bq2515x->regmap, BQ2515X_ILIMCTRL, &ilimctrl); in bq2515x_get_ilim_lvl()
677 for (i = array_size - 1; i > 0; i--) { in bq2515x_set_ilim_lvl()
681 return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i); in bq2515x_set_ilim_lvl()
706 if (!bq2515x->mains_online) in bq2515x_charger_get_health()
709 ret = regmap_read(bq2515x->regmap, BQ2515X_FLAG3, &flag3); in bq2515x_charger_get_health()
713 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &stat1); in bq2515x_charger_get_health()
743 val->intval = health; in bq2515x_charger_get_health()
756 ret = bq2515x_set_batt_reg(bq2515x, val->intval); in bq2515x_mains_set_property()
760 ret = bq2515x_set_const_charge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
764 ret = bq2515x_set_ilim_lvl(bq2515x, val->intval); in bq2515x_mains_set_property()
768 ret = bq2515x_set_precharge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
772 return -EINVAL; in bq2515x_mains_set_property()
792 val->intval = ret; in bq2515x_mains_get_property()
799 val->intval = ret; in bq2515x_mains_get_property()
806 val->intval = ret; in bq2515x_mains_get_property()
810 val->intval = bq2515x->mains_online; in bq2515x_mains_get_property()
816 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; in bq2515x_mains_get_property()
823 val->intval = ret; in bq2515x_mains_get_property()
827 val->strval = bq2515x->model_name; in bq2515x_mains_get_property()
831 val->strval = BQ2515X_MANUFACTURER; in bq2515x_mains_get_property()
841 return -EINVAL; in bq2515x_mains_get_property()
861 ret = bq2515x->init_data.vbatreg; in bq2515x_battery_get_property()
864 val->intval = ret; in bq2515x_battery_get_property()
868 ret = bq2515x->init_data.ichg; in bq2515x_battery_get_property()
871 val->intval = ret; in bq2515x_battery_get_property()
878 val->intval = ret; in bq2515x_battery_get_property()
885 val->intval = ret; in bq2515x_battery_get_property()
889 return -EINVAL; in bq2515x_battery_get_property()
914 .name = "bq2515x-mains",
924 .name = "bq2515x-battery",
935 bq2515x->mains = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
938 if (IS_ERR(bq2515x->mains)) in bq2515x_power_supply_register()
939 return -EINVAL; in bq2515x_power_supply_register()
941 bq2515x->battery = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
944 if (IS_ERR(bq2515x->battery)) in bq2515x_power_supply_register()
945 return -EINVAL; in bq2515x_power_supply_register()
959 if (bq2515x->init_data.ilim) { in bq2515x_hw_init()
960 ret = bq2515x_set_ilim_lvl(bq2515x, bq2515x->init_data.ilim); in bq2515x_hw_init()
965 ret = power_supply_get_battery_info(bq2515x->mains, &bat_info); in bq2515x_hw_init()
967 dev_warn(bq2515x->dev, "battery info missing, default values will be applied\n"); in bq2515x_hw_init()
969 bq2515x->init_data.ichg = BQ2515X_DEFAULT_ICHG_UA; in bq2515x_hw_init()
971 bq2515x->init_data.vbatreg = BQ2515X_DEFAULT_VBAT_REG_UV; in bq2515x_hw_init()
973 bq2515x->init_data.iprechg = BQ2515X_DEFAULT_IPRECHARGE_UA; in bq2515x_hw_init()
976 bq2515x->init_data.ichg = in bq2515x_hw_init()
977 bat_info->constant_charge_current_max_ua; in bq2515x_hw_init()
979 bq2515x->init_data.vbatreg = in bq2515x_hw_init()
980 bat_info->constant_charge_voltage_max_uv; in bq2515x_hw_init()
982 bq2515x->init_data.iprechg = in bq2515x_hw_init()
983 bat_info->precharge_current_ua; in bq2515x_hw_init()
987 bq2515x->init_data.ichg); in bq2515x_hw_init()
991 ret = bq2515x_set_batt_reg(bq2515x, bq2515x->init_data.vbatreg); in bq2515x_hw_init()
996 bq2515x->init_data.iprechg); in bq2515x_hw_init()
1003 ret = device_property_read_u32(bq2515x->dev, in bq2515x_read_properties()
1004 "input-current-limit-microamp", in bq2515x_read_properties()
1005 &bq2515x->init_data.ilim); in bq2515x_read_properties()
1007 bq2515x->init_data.ilim = bq2515x->info->ilim; in bq2515x_read_properties()
1009 bq2515x->ac_detect_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1010 "ac-detect", GPIOD_IN); in bq2515x_read_properties()
1011 if (IS_ERR(bq2515x->ac_detect_gpio)) { in bq2515x_read_properties()
1012 ret = PTR_ERR(bq2515x->ac_detect_gpio); in bq2515x_read_properties()
1013 dev_err(bq2515x->dev, "Failed to get ac detect"); in bq2515x_read_properties()
1017 bq2515x->reset_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1019 if (IS_ERR(bq2515x->reset_gpio)) { in bq2515x_read_properties()
1020 ret = PTR_ERR(bq2515x->reset_gpio); in bq2515x_read_properties()
1021 dev_err(bq2515x->dev, "Failed to get reset"); in bq2515x_read_properties()
1025 bq2515x->powerdown_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1027 if (IS_ERR(bq2515x->powerdown_gpio)) { in bq2515x_read_properties()
1028 ret = PTR_ERR(bq2515x->powerdown_gpio); in bq2515x_read_properties()
1029 dev_err(bq2515x->dev, "Failed to get powerdown"); in bq2515x_read_properties()
1033 bq2515x->ce_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1034 "charge-enable", in bq2515x_read_properties()
1036 if (IS_ERR(bq2515x->ce_gpio)) { in bq2515x_read_properties()
1037 ret = PTR_ERR(bq2515x->ce_gpio); in bq2515x_read_properties()
1038 dev_err(bq2515x->dev, "Failed to get ce"); in bq2515x_read_properties()
1081 struct device *dev = &client->dev; in bq2515x_probe()
1088 return -ENOMEM; in bq2515x_probe()
1090 bq2515x->dev = dev; in bq2515x_probe()
1092 strscpy(bq2515x->model_name, id->name, sizeof(bq2515x->model_name)); in bq2515x_probe()
1094 bq2515x->info = i2c_get_match_data(client); in bq2515x_probe()
1095 bq2515x->regmap = devm_regmap_init_i2c(client, in bq2515x_probe()
1096 bq2515x->info->regmap_config); in bq2515x_probe()
1097 if (IS_ERR(bq2515x->regmap)) { in bq2515x_probe()
1099 return PTR_ERR(bq2515x->regmap); in bq2515x_probe()
1105 charger_cfg.of_node = dev->of_node; in bq2515x_probe()
1155 .name = "bq2515x-charger",
1164 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");