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
156 * struct bq2515x_device -
278 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_wake_up()
286 gpiod_set_value_cansleep(bq2515x->powerdown_gpio, 0); in bq2515x_wake_up()
288 gpiod_set_value_cansleep(bq2515x->reset_gpio, 0); in bq2515x_wake_up()
290 gpiod_set_value_cansleep(bq2515x->reset_gpio, 1); in bq2515x_wake_up()
292 return regmap_write(bq2515x->regmap, BQ2515X_ADC_READ_EN, in bq2515x_wake_up()
302 if (bq2515x->ac_detect_gpio) in bq2515x_update_ps_status()
303 val = gpiod_get_value_cansleep(bq2515x->ac_detect_gpio); in bq2515x_update_ps_status()
305 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_update_ps_status()
312 ret = bq2515x->mains_online != dc; in bq2515x_update_ps_status()
314 bq2515x->mains_online = dc; in bq2515x_update_ps_status()
323 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_CHARGERCTRL0, in bq2515x_disable_watchdog_timers()
328 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_disable_watchdog_timers()
339 if (!bq2515x->mains_online) in bq2515x_get_battery_voltage_now()
342 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_M, &vbat_msb); in bq2515x_get_battery_voltage_now()
346 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_L, &vbat_lsb); in bq2515x_get_battery_voltage_now()
367 if (!bq2515x->mains_online) in bq2515x_get_battery_current_now()
368 return -ENODATA; in bq2515x_get_battery_current_now()
370 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_M, &ichg_msb); in bq2515x_get_battery_current_now()
374 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_L, &ichg_lsb); in bq2515x_get_battery_current_now()
380 ret = regmap_read(bq2515x->regmap, BQ2515X_BUVLO, &buvlo); in bq2515x_get_battery_current_now()
390 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_get_battery_current_now()
397 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, in bq2515x_get_battery_current_now()
405 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_battery_current_now()
425 ce_pin = gpiod_get_value_cansleep(bq2515x->ce_gpio); in bq2515x_get_charge_disable()
427 ret = regmap_read(bq2515x->regmap, BQ2515X_ICCTRL2, &icctrl2); in bq2515x_get_charge_disable()
441 gpiod_set_value_cansleep(bq2515x->ce_gpio, val); in bq2515x_set_charge_disable()
443 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_set_charge_disable()
455 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, &ichg_reg_code); in bq2515x_get_const_charge_current()
459 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_const_charge_current()
480 return -EINVAL; in bq2515x_set_const_charge_current()
489 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_const_charge_current()
496 ret = regmap_write(bq2515x->regmap, BQ2515X_ICHG_CTRL, ichg_reg_code); in bq2515x_set_const_charge_current()
511 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_precharge_current()
535 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_set_precharge_current()
549 return -EINVAL; in bq2515x_set_precharge_current()
557 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_precharge_current()
575 if (!bq2515x->mains_online) { in bq2515x_charging_status()
576 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq2515x_charging_status()
580 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &status); in bq2515x_charging_status()
601 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &status); in bq2515x_charging_status()
622 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq2515x_charging_status()
624 val->intval = POWER_SUPPLY_STATUS_FULL; in bq2515x_charging_status()
626 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq2515x_charging_status()
636 ret = regmap_read(bq2515x->regmap, BQ2515X_VBAT_CTRL, &vbat_reg_code); in bq2515x_get_batt_reg()
648 return -EINVAL; in bq2515x_set_batt_reg()
650 vbat_reg_code = (val - BQ2515X_VBAT_BASE_VOLT) / BQ2515X_VBAT_STEP_UV; in bq2515x_set_batt_reg()
652 return regmap_write(bq2515x->regmap, BQ2515X_VBAT_CTRL, vbat_reg_code); in bq2515x_set_batt_reg()
660 ret = regmap_read(bq2515x->regmap, BQ2515X_ILIMCTRL, &ilimctrl); in bq2515x_get_ilim_lvl()
672 for (i = array_size - 1; i > 0; i--) { in bq2515x_set_ilim_lvl()
676 return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i); in bq2515x_set_ilim_lvl()
701 if (!bq2515x->mains_online) in bq2515x_charger_get_health()
704 ret = regmap_read(bq2515x->regmap, BQ2515X_FLAG3, &flag3); in bq2515x_charger_get_health()
708 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &stat1); in bq2515x_charger_get_health()
738 val->intval = health; in bq2515x_charger_get_health()
751 ret = bq2515x_set_batt_reg(bq2515x, val->intval); in bq2515x_mains_set_property()
755 ret = bq2515x_set_const_charge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
759 ret = bq2515x_set_ilim_lvl(bq2515x, val->intval); in bq2515x_mains_set_property()
763 ret = bq2515x_set_precharge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
767 return -EINVAL; in bq2515x_mains_set_property()
787 val->intval = ret; in bq2515x_mains_get_property()
794 val->intval = ret; in bq2515x_mains_get_property()
801 val->intval = ret; in bq2515x_mains_get_property()
805 val->intval = bq2515x->mains_online; in bq2515x_mains_get_property()
811 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; in bq2515x_mains_get_property()
818 val->intval = ret; in bq2515x_mains_get_property()
822 val->strval = bq2515x->model_name; in bq2515x_mains_get_property()
826 val->strval = BQ2515X_MANUFACTURER; in bq2515x_mains_get_property()
836 return -EINVAL; in bq2515x_mains_get_property()
856 ret = bq2515x->init_data.vbatreg; in bq2515x_battery_get_property()
859 val->intval = ret; in bq2515x_battery_get_property()
863 ret = bq2515x->init_data.ichg; in bq2515x_battery_get_property()
866 val->intval = ret; in bq2515x_battery_get_property()
873 val->intval = ret; in bq2515x_battery_get_property()
880 val->intval = ret; in bq2515x_battery_get_property()
884 return -EINVAL; in bq2515x_battery_get_property()
909 .name = "bq2515x-mains",
919 .name = "bq2515x-battery",
930 bq2515x->mains = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
933 if (IS_ERR(bq2515x->mains)) in bq2515x_power_supply_register()
934 return -EINVAL; in bq2515x_power_supply_register()
936 bq2515x->battery = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
939 if (IS_ERR(bq2515x->battery)) in bq2515x_power_supply_register()
940 return -EINVAL; in bq2515x_power_supply_register()
954 if (bq2515x->init_data.ilim) { in bq2515x_hw_init()
955 ret = bq2515x_set_ilim_lvl(bq2515x, bq2515x->init_data.ilim); in bq2515x_hw_init()
960 ret = power_supply_get_battery_info(bq2515x->mains, &bat_info); in bq2515x_hw_init()
962 dev_warn(bq2515x->dev, "battery info missing, default values will be applied\n"); in bq2515x_hw_init()
964 bq2515x->init_data.ichg = BQ2515X_DEFAULT_ICHG_UA; in bq2515x_hw_init()
966 bq2515x->init_data.vbatreg = BQ2515X_DEFAULT_VBAT_REG_UV; in bq2515x_hw_init()
968 bq2515x->init_data.iprechg = BQ2515X_DEFAULT_IPRECHARGE_UA; in bq2515x_hw_init()
971 bq2515x->init_data.ichg = in bq2515x_hw_init()
974 bq2515x->init_data.vbatreg = in bq2515x_hw_init()
977 bq2515x->init_data.iprechg = in bq2515x_hw_init()
982 bq2515x->init_data.ichg); in bq2515x_hw_init()
986 ret = bq2515x_set_batt_reg(bq2515x, bq2515x->init_data.vbatreg); in bq2515x_hw_init()
991 bq2515x->init_data.iprechg); in bq2515x_hw_init()
998 ret = device_property_read_u32(bq2515x->dev, in bq2515x_read_properties()
999 "input-current-limit-microamp", in bq2515x_read_properties()
1000 &bq2515x->init_data.ilim); in bq2515x_read_properties()
1002 switch (bq2515x->device_id) { in bq2515x_read_properties()
1004 bq2515x->init_data.ilim = BQ25150_DEFAULT_ILIM_UA; in bq2515x_read_properties()
1007 bq2515x->init_data.ilim = BQ25155_DEFAULT_ILIM_UA; in bq2515x_read_properties()
1012 bq2515x->ac_detect_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1013 "ac-detect", GPIOD_IN); in bq2515x_read_properties()
1014 if (IS_ERR(bq2515x->ac_detect_gpio)) { in bq2515x_read_properties()
1015 ret = PTR_ERR(bq2515x->ac_detect_gpio); in bq2515x_read_properties()
1016 dev_err(bq2515x->dev, "Failed to get ac detect"); in bq2515x_read_properties()
1020 bq2515x->reset_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1022 if (IS_ERR(bq2515x->reset_gpio)) { in bq2515x_read_properties()
1023 ret = PTR_ERR(bq2515x->reset_gpio); in bq2515x_read_properties()
1024 dev_err(bq2515x->dev, "Failed to get reset"); in bq2515x_read_properties()
1028 bq2515x->powerdown_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1030 if (IS_ERR(bq2515x->powerdown_gpio)) { in bq2515x_read_properties()
1031 ret = PTR_ERR(bq2515x->powerdown_gpio); in bq2515x_read_properties()
1032 dev_err(bq2515x->dev, "Failed to get powerdown"); in bq2515x_read_properties()
1036 bq2515x->ce_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1037 "charge-enable", in bq2515x_read_properties()
1039 if (IS_ERR(bq2515x->ce_gpio)) { in bq2515x_read_properties()
1040 ret = PTR_ERR(bq2515x->ce_gpio); in bq2515x_read_properties()
1041 dev_err(bq2515x->dev, "Failed to get ce"); in bq2515x_read_properties()
1084 struct device *dev = &client->dev; in bq2515x_probe()
1091 return -ENOMEM; in bq2515x_probe()
1093 bq2515x->dev = dev; in bq2515x_probe()
1095 strncpy(bq2515x->model_name, id->name, I2C_NAME_SIZE); in bq2515x_probe()
1097 bq2515x->device_id = id->driver_data; in bq2515x_probe()
1099 switch (bq2515x->device_id) { in bq2515x_probe()
1101 bq2515x->regmap = devm_regmap_init_i2c(client, in bq2515x_probe()
1105 bq2515x->regmap = devm_regmap_init_i2c(client, in bq2515x_probe()
1110 if (IS_ERR(bq2515x->regmap)) { in bq2515x_probe()
1112 return PTR_ERR(bq2515x->regmap); in bq2515x_probe()
1118 charger_cfg.of_node = dev->of_node; in bq2515x_probe()
1158 .name = "bq2515x-charger",
1167 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");