Lines Matching +full:precharge +full:- +full:current +full:- +full:microamp
1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
147 * struct bq256xx_init_data -
148 * @ichg: fast charge current
149 * @iindpm: input current limit
151 * @iterm: termination current
152 * @iprechg: precharge current
154 * @ichg_max: maximum fast charge current
169 * struct bq256xx_state -
201 * struct bq256xx_device -
245 * struct bq256xx_chip_info -
270 * @bq256xx_max_ichg: maximum charge current in microamps
338 return i - 1; in bq256xx_array_parse()
340 if (val >= array[array_size - 1]) in bq256xx_array_parse()
341 return array_size - 1; in bq256xx_array_parse()
347 if (val > array[i - 1] && val < array[i]) { in bq256xx_array_parse()
349 return i - 1; in bq256xx_array_parse()
354 return -EINVAL; in bq256xx_array_parse()
363 bq->usb_event = val; in bq256xx_usb_notifier()
364 queue_work(system_power_efficient_wq, &bq->usb_work); in bq256xx_usb_notifier()
374 switch (bq->usb_event) { in bq256xx_usb_work()
378 power_supply_changed(bq->charger); in bq256xx_usb_work()
381 dev_err(bq->dev, "Error switching to charger mode.\n"); in bq256xx_usb_work()
430 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_0, in bq256xx_get_state()
435 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_STATUS_1, in bq256xx_get_state()
440 state->vbus_stat = charger_status_0 & BQ256XX_VBUS_STAT_MASK; in bq256xx_get_state()
441 state->chrg_stat = charger_status_0 & BQ256XX_CHRG_STAT_MASK; in bq256xx_get_state()
442 state->online = charger_status_0 & BQ256XX_PG_STAT_MASK; in bq256xx_get_state()
444 state->wdt_fault = charger_status_1 & BQ256XX_WDT_FAULT_MASK; in bq256xx_get_state()
445 state->bat_fault = charger_status_1 & BQ256XX_BAT_FAULT_MASK; in bq256xx_get_state()
446 state->chrg_fault = charger_status_1 & BQ256XX_CHRG_FAULT_MASK; in bq256xx_get_state()
447 state->ntc_fault = charger_status_1 & BQ256XX_NTC_FAULT_MASK; in bq256xx_get_state()
458 ret = regmap_read(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT, in bq256xx_get_ichg_curr()
474 ret = regmap_read(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT, in bq25618_619_get_ichg_curr()
484 return bq25618_619_ichg_values[ichg_reg_code - BQ25618_ICHG_THRESH]; in bq25618_619_get_ichg_curr()
490 int ichg_max = bq->init_data.ichg_max; in bq256xx_set_ichg_curr()
495 return regmap_update_bits(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT, in bq256xx_set_ichg_curr()
503 int ichg_max = bq->init_data.ichg_max; in bq25618_619_set_ichg_curr()
514 return regmap_update_bits(bq->regmap, BQ256XX_CHARGE_CURRENT_LIMIT, in bq25618_619_set_ichg_curr()
524 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25618_619_get_chrg_volt()
534 return ((vbatreg_reg_code - BQ2561X_VBATREG_THRESH) * in bq25618_619_get_chrg_volt()
547 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25611d_get_chrg_volt()
556 return ((vbatreg_reg_code - BQ2561X_VBATREG_THRESH) * in bq25611d_get_chrg_volt()
569 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq2560x_get_chrg_volt()
587 ret = regmap_read(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25601d_get_chrg_volt()
603 int vbatreg_max = bq->init_data.vbatreg_max; in bq25618_619_set_chrg_volt()
608 vbatreg_reg_code = ((vbatreg - in bq25618_619_set_chrg_volt()
616 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25618_619_set_chrg_volt()
625 int vbatreg_max = bq->init_data.vbatreg_max; in bq25611d_set_chrg_volt()
630 vbatreg_reg_code = ((vbatreg - in bq25611d_set_chrg_volt()
638 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25611d_set_chrg_volt()
646 int vbatreg_max = bq->init_data.vbatreg_max; in bq2560x_set_chrg_volt()
650 vbatreg_reg_code = (vbatreg - BQ2560X_VBATREG_OFFSET_uV) / in bq2560x_set_chrg_volt()
653 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq2560x_set_chrg_volt()
661 int vbatreg_max = bq->init_data.vbatreg_max; in bq25601d_set_chrg_volt()
665 vbatreg_reg_code = (vbatreg - BQ25601D_VBATREG_OFFSET_uV) / in bq25601d_set_chrg_volt()
668 return regmap_update_bits(bq->regmap, BQ256XX_BATTERY_VOLTAGE_LIMIT, in bq25601d_set_chrg_volt()
679 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq256xx_get_prechrg_curr()
698 iprechg_reg_code = ((iprechg - BQ256XX_IPRECHG_OFFSET_uA) / in bq256xx_set_prechrg_curr()
701 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq256xx_set_prechrg_curr()
711 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq25618_619_get_prechrg_curr()
730 iprechg_reg_code = ((iprechg - BQ25618_IPRECHG_OFFSET_uA) / in bq25618_619_set_prechrg_curr()
733 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq25618_619_set_prechrg_curr()
743 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq256xx_get_term_curr()
760 iterm_reg_code = (iterm - BQ256XX_ITERM_OFFSET_uA) / in bq256xx_set_term_curr()
763 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq256xx_set_term_curr()
773 ret = regmap_read(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq25618_619_get_term_curr()
790 iterm_reg_code = (iterm - BQ25618_ITERM_OFFSET_uA) / in bq25618_619_set_term_curr()
793 return regmap_update_bits(bq->regmap, BQ256XX_PRECHG_AND_TERM_CURR_LIM, in bq25618_619_set_term_curr()
803 ret = regmap_read(bq->regmap, BQ256XX_CHARGER_CONTROL_2, in bq256xx_get_input_volt_lim()
820 vindpm_reg_code = (vindpm - BQ256XX_VINDPM_OFFSET_uV) / in bq256xx_set_input_volt_lim()
823 return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_2, in bq256xx_set_input_volt_lim()
833 ret = regmap_read(bq->regmap, BQ256XX_INPUT_CURRENT_LIMIT, in bq256xx_get_input_curr_lim()
850 iindpm_reg_code = (iindpm - BQ256XX_IINDPM_OFFSET_uA) / in bq256xx_set_input_curr_lim()
853 return regmap_update_bits(bq->regmap, BQ256XX_INPUT_CURRENT_LIMIT, in bq256xx_set_input_curr_lim()
861 regmap_update_bits(bq->regmap, BQ256XX_PART_INFORMATION, in bq256xx_charger_reset()
864 if (!IS_ERR_OR_NULL(bq->usb2_phy)) in bq256xx_charger_reset()
865 usb_unregister_notifier(bq->usb2_phy, &bq->usb_nb); in bq256xx_charger_reset()
867 if (!IS_ERR_OR_NULL(bq->usb3_phy)) in bq256xx_charger_reset()
868 usb_unregister_notifier(bq->usb3_phy, &bq->usb_nb); in bq256xx_charger_reset()
876 int ret = -EINVAL; in bq256xx_set_charger_property()
880 ret = bq->chip_info->bq256xx_set_iindpm(bq, val->intval); in bq256xx_set_charger_property()
889 ret = bq->chip_info->bq256xx_set_vbatreg(bq, val->intval); in bq256xx_set_charger_property()
895 ret = bq->chip_info->bq256xx_set_ichg(bq, val->intval); in bq256xx_set_charger_property()
901 ret = bq->chip_info->bq256xx_set_iprechg(bq, val->intval); in bq256xx_set_charger_property()
907 ret = bq->chip_info->bq256xx_set_iterm(bq, val->intval); in bq256xx_set_charger_property()
913 ret = bq->chip_info->bq256xx_set_vindpm(bq, val->intval); in bq256xx_set_charger_property()
934 val->intval = bq->init_data.ichg_max; in bq256xx_get_battery_property()
938 val->intval = bq->init_data.vbatreg_max; in bq256xx_get_battery_property()
942 return -EINVAL; in bq256xx_get_battery_property()
956 mutex_lock(&bq->lock); in bq256xx_get_charger_property()
958 mutex_unlock(&bq->lock); in bq256xx_get_charger_property()
966 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq256xx_get_charger_property()
968 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq256xx_get_charger_property()
970 val->intval = POWER_SUPPLY_STATUS_FULL; in bq256xx_get_charger_property()
972 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq256xx_get_charger_property()
976 val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; in bq256xx_get_charger_property()
978 val->intval = in bq256xx_get_charger_property()
981 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in bq256xx_get_charger_property()
985 val->intval = in bq256xx_get_charger_property()
989 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in bq256xx_get_charger_property()
992 val->intval = in bq256xx_get_charger_property()
1001 val->intval = POWER_SUPPLY_HEALTH_WARM; in bq256xx_get_charger_property()
1004 val->intval = POWER_SUPPLY_HEALTH_COOL; in bq256xx_get_charger_property()
1007 val->intval = POWER_SUPPLY_HEALTH_COLD; in bq256xx_get_charger_property()
1010 val->intval = POWER_SUPPLY_HEALTH_HOT; in bq256xx_get_charger_property()
1013 val->intval = POWER_SUPPLY_HEALTH_GOOD; in bq256xx_get_charger_property()
1020 if (bq->chip_info->has_usb_detect) { in bq256xx_get_charger_property()
1023 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in bq256xx_get_charger_property()
1026 val->intval = POWER_SUPPLY_USB_TYPE_CDP; in bq256xx_get_charger_property()
1029 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in bq256xx_get_charger_property()
1032 val->intval = POWER_SUPPLY_USB_TYPE_ACA; in bq256xx_get_charger_property()
1035 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in bq256xx_get_charger_property()
1041 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in bq256xx_get_charger_property()
1044 val->intval = POWER_SUPPLY_USB_TYPE_ACA; in bq256xx_get_charger_property()
1047 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in bq256xx_get_charger_property()
1056 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in bq256xx_get_charger_property()
1059 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; in bq256xx_get_charger_property()
1062 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; in bq256xx_get_charger_property()
1065 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; in bq256xx_get_charger_property()
1068 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; in bq256xx_get_charger_property()
1073 val->strval = BQ256XX_MANUFACTURER; in bq256xx_get_charger_property()
1077 val->strval = bq->model_name; in bq256xx_get_charger_property()
1081 val->intval = state.online; in bq256xx_get_charger_property()
1085 ret = bq->chip_info->bq256xx_get_vindpm(bq); in bq256xx_get_charger_property()
1088 val->intval = ret; in bq256xx_get_charger_property()
1092 ret = bq->chip_info->bq256xx_get_iindpm(bq); in bq256xx_get_charger_property()
1095 val->intval = ret; in bq256xx_get_charger_property()
1099 ret = bq->chip_info->bq256xx_get_vbatreg(bq); in bq256xx_get_charger_property()
1102 val->intval = ret; in bq256xx_get_charger_property()
1106 ret = bq->chip_info->bq256xx_get_ichg(bq); in bq256xx_get_charger_property()
1109 val->intval = ret; in bq256xx_get_charger_property()
1113 ret = bq->chip_info->bq256xx_get_iprechg(bq); in bq256xx_get_charger_property()
1116 val->intval = ret; in bq256xx_get_charger_property()
1120 ret = bq->chip_info->bq256xx_get_iterm(bq); in bq256xx_get_charger_property()
1123 val->intval = ret; in bq256xx_get_charger_property()
1127 return -EINVAL; in bq256xx_get_charger_property()
1138 mutex_lock(&bq->lock); in bq256xx_state_changed()
1139 old_state = bq->state; in bq256xx_state_changed()
1140 mutex_unlock(&bq->lock); in bq256xx_state_changed()
1158 mutex_lock(&bq->lock); in bq256xx_irq_handler_thread()
1159 bq->state = state; in bq256xx_irq_handler_thread()
1160 mutex_unlock(&bq->lock); in bq256xx_irq_handler_thread()
1162 power_supply_changed(bq->charger); in bq256xx_irq_handler_thread()
1207 .name = "bq256xx-charger",
1219 .name = "bq256xx-battery",
1487 bq->charger = devm_power_supply_register(bq->dev, in bq256xx_power_supply_init()
1490 if (IS_ERR(bq->charger)) { in bq256xx_power_supply_init()
1492 return PTR_ERR(bq->charger); in bq256xx_power_supply_init()
1495 bq->battery = devm_power_supply_register(bq->dev, in bq256xx_power_supply_init()
1498 if (IS_ERR(bq->battery)) { in bq256xx_power_supply_init()
1500 return PTR_ERR(bq->battery); in bq256xx_power_supply_init()
1513 if (bq->watchdog_timer == bq256xx_watchdog_time[i]) { in bq256xx_hw_init()
1517 if (bq->watchdog_timer > bq256xx_watchdog_time[i] && in bq256xx_hw_init()
1518 bq->watchdog_timer < bq256xx_watchdog_time[i + 1]) in bq256xx_hw_init()
1521 ret = regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_1, in bq256xx_hw_init()
1525 ret = power_supply_get_battery_info(bq->charger, &bat_info); in bq256xx_hw_init()
1526 if (ret == -ENOMEM) in bq256xx_hw_init()
1530 dev_warn(bq->dev, "battery info missing, default values will be applied\n"); in bq256xx_hw_init()
1532 bat_info->constant_charge_current_max_ua = in bq256xx_hw_init()
1533 bq->chip_info->bq256xx_def_ichg; in bq256xx_hw_init()
1535 bat_info->constant_charge_voltage_max_uv = in bq256xx_hw_init()
1536 bq->chip_info->bq256xx_def_vbatreg; in bq256xx_hw_init()
1538 bat_info->precharge_current_ua = in bq256xx_hw_init()
1539 bq->chip_info->bq256xx_def_iprechg; in bq256xx_hw_init()
1541 bat_info->charge_term_current_ua = in bq256xx_hw_init()
1542 bq->chip_info->bq256xx_def_iterm; in bq256xx_hw_init()
1544 bq->init_data.ichg_max = in bq256xx_hw_init()
1545 bq->chip_info->bq256xx_max_ichg; in bq256xx_hw_init()
1547 bq->init_data.vbatreg_max = in bq256xx_hw_init()
1548 bq->chip_info->bq256xx_max_vbatreg; in bq256xx_hw_init()
1550 bq->init_data.ichg_max = in bq256xx_hw_init()
1551 bat_info->constant_charge_current_max_ua; in bq256xx_hw_init()
1553 bq->init_data.vbatreg_max = in bq256xx_hw_init()
1554 bat_info->constant_charge_voltage_max_uv; in bq256xx_hw_init()
1557 ret = bq->chip_info->bq256xx_set_vindpm(bq, bq->init_data.vindpm); in bq256xx_hw_init()
1561 ret = bq->chip_info->bq256xx_set_iindpm(bq, bq->init_data.iindpm); in bq256xx_hw_init()
1565 ret = bq->chip_info->bq256xx_set_ichg(bq, in bq256xx_hw_init()
1566 bat_info->constant_charge_current_max_ua); in bq256xx_hw_init()
1570 ret = bq->chip_info->bq256xx_set_iprechg(bq, in bq256xx_hw_init()
1571 bat_info->precharge_current_ua); in bq256xx_hw_init()
1575 ret = bq->chip_info->bq256xx_set_vbatreg(bq, in bq256xx_hw_init()
1576 bat_info->constant_charge_voltage_max_uv); in bq256xx_hw_init()
1580 ret = bq->chip_info->bq256xx_set_iterm(bq, in bq256xx_hw_init()
1581 bat_info->charge_term_current_ua); in bq256xx_hw_init()
1585 power_supply_put_battery_info(bq->charger, bat_info); in bq256xx_hw_init()
1595 psy_cfg->drv_data = bq; in bq256xx_parse_dt()
1596 psy_cfg->of_node = dev->of_node; in bq256xx_parse_dt()
1598 ret = device_property_read_u32(bq->dev, "ti,watchdog-timeout-ms", in bq256xx_parse_dt()
1599 &bq->watchdog_timer); in bq256xx_parse_dt()
1601 bq->watchdog_timer = BQ256XX_WATCHDOG_DIS; in bq256xx_parse_dt()
1603 if (bq->watchdog_timer > BQ256XX_WATCHDOG_MAX || in bq256xx_parse_dt()
1604 bq->watchdog_timer < BQ256XX_WATCHDOG_DIS) in bq256xx_parse_dt()
1605 return -EINVAL; in bq256xx_parse_dt()
1607 ret = device_property_read_u32(bq->dev, in bq256xx_parse_dt()
1608 "input-voltage-limit-microvolt", in bq256xx_parse_dt()
1609 &bq->init_data.vindpm); in bq256xx_parse_dt()
1611 bq->init_data.vindpm = bq->chip_info->bq256xx_def_vindpm; in bq256xx_parse_dt()
1613 ret = device_property_read_u32(bq->dev, in bq256xx_parse_dt()
1614 "input-current-limit-microamp", in bq256xx_parse_dt()
1615 &bq->init_data.iindpm); in bq256xx_parse_dt()
1617 bq->init_data.iindpm = bq->chip_info->bq256xx_def_iindpm; in bq256xx_parse_dt()
1625 struct device *dev = &client->dev; in bq256xx_probe()
1633 return -ENOMEM; in bq256xx_probe()
1635 bq->client = client; in bq256xx_probe()
1636 bq->dev = dev; in bq256xx_probe()
1637 bq->chip_info = &bq256xx_chip_info_tbl[id->driver_data]; in bq256xx_probe()
1639 mutex_init(&bq->lock); in bq256xx_probe()
1641 strncpy(bq->model_name, id->name, I2C_NAME_SIZE); in bq256xx_probe()
1643 bq->regmap = devm_regmap_init_i2c(client, in bq256xx_probe()
1644 bq->chip_info->bq256xx_regmap_config); in bq256xx_probe()
1646 if (IS_ERR(bq->regmap)) { in bq256xx_probe()
1648 return PTR_ERR(bq->regmap); in bq256xx_probe()
1664 bq->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in bq256xx_probe()
1665 if (!IS_ERR_OR_NULL(bq->usb2_phy)) { in bq256xx_probe()
1666 INIT_WORK(&bq->usb_work, bq256xx_usb_work); in bq256xx_probe()
1667 bq->usb_nb.notifier_call = bq256xx_usb_notifier; in bq256xx_probe()
1668 usb_register_notifier(bq->usb2_phy, &bq->usb_nb); in bq256xx_probe()
1671 bq->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); in bq256xx_probe()
1672 if (!IS_ERR_OR_NULL(bq->usb3_phy)) { in bq256xx_probe()
1673 INIT_WORK(&bq->usb_work, bq256xx_usb_work); in bq256xx_probe()
1674 bq->usb_nb.notifier_call = bq256xx_usb_notifier; in bq256xx_probe()
1675 usb_register_notifier(bq->usb3_phy, &bq->usb_nb); in bq256xx_probe()
1678 if (client->irq) { in bq256xx_probe()
1679 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq256xx_probe()
1683 dev_name(&client->dev), bq); in bq256xx_probe()
1743 .name = "bq256xx-charger",
1752 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");