Lines Matching +full:sc +full:- +full:ovp +full:- +full:limit +full:- +full:microvolt

1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
24 bool ovp; member
280 ret = regmap_read(bq->regmap, BQ25980_BUSOCP, &busocp_reg_code); in bq25980_get_input_curr_lim()
289 return regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_set_hiz()
306 if (bq->state.bypass) in bq25980_set_input_curr_lim()
307 busocp = min(busocp, bq->chip_info->busocp_sc_max); in bq25980_set_input_curr_lim()
309 busocp = min(busocp, bq->chip_info->busocp_byp_max); in bq25980_set_input_curr_lim()
311 busocp_reg_code = (busocp - BQ25980_BUSOCP_OFFSET_uA) in bq25980_set_input_curr_lim()
314 ret = regmap_write(bq->regmap, BQ25980_BUSOCP, busocp_reg_code); in bq25980_set_input_curr_lim()
318 return regmap_write(bq->regmap, BQ25980_BUSOCP_ALM, busocp_reg_code); in bq25980_set_input_curr_lim()
328 if (bq->state.bypass) { in bq25980_get_input_volt_lim()
329 busovp_step = bq->chip_info->busovp_byp_step; in bq25980_get_input_volt_lim()
330 busovp_offset = bq->chip_info->busovp_byp_offset; in bq25980_get_input_volt_lim()
332 busovp_step = bq->chip_info->busovp_sc_step; in bq25980_get_input_volt_lim()
333 busovp_offset = bq->chip_info->busovp_sc_offset; in bq25980_get_input_volt_lim()
336 ret = regmap_read(bq->regmap, BQ25980_BUSOVP, &busovp_reg_code); in bq25980_get_input_volt_lim()
350 if (bq->state.bypass) { in bq25980_set_input_volt_lim()
351 busovp_step = bq->chip_info->busovp_byp_step; in bq25980_set_input_volt_lim()
352 busovp_offset = bq->chip_info->busovp_byp_offset; in bq25980_set_input_volt_lim()
353 if (busovp > bq->chip_info->busovp_byp_max) in bq25980_set_input_volt_lim()
354 busovp = bq->chip_info->busovp_byp_max; in bq25980_set_input_volt_lim()
355 else if (busovp < bq->chip_info->busovp_byp_min) in bq25980_set_input_volt_lim()
356 busovp = bq->chip_info->busovp_byp_min; in bq25980_set_input_volt_lim()
358 busovp_step = bq->chip_info->busovp_sc_step; in bq25980_set_input_volt_lim()
359 busovp_offset = bq->chip_info->busovp_sc_offset; in bq25980_set_input_volt_lim()
360 if (busovp > bq->chip_info->busovp_sc_max) in bq25980_set_input_volt_lim()
361 busovp = bq->chip_info->busovp_sc_max; in bq25980_set_input_volt_lim()
362 else if (busovp < bq->chip_info->busovp_sc_min) in bq25980_set_input_volt_lim()
363 busovp = bq->chip_info->busovp_sc_min; in bq25980_set_input_volt_lim()
366 busovp_reg_code = (busovp - busovp_offset) / busovp_step; in bq25980_set_input_volt_lim()
368 ret = regmap_write(bq->regmap, BQ25980_BUSOVP, busovp_reg_code); in bq25980_set_input_volt_lim()
372 return regmap_write(bq->regmap, BQ25980_BUSOVP_ALM, busovp_reg_code); in bq25980_set_input_volt_lim()
380 ret = regmap_read(bq->regmap, BQ25980_BATOCP, &batocp_reg_code); in bq25980_get_const_charge_curr()
394 batocp = min(batocp, bq->chip_info->batocp_max); in bq25980_set_const_charge_curr()
398 ret = regmap_update_bits(bq->regmap, BQ25980_BATOCP, in bq25980_set_const_charge_curr()
403 return regmap_update_bits(bq->regmap, BQ25980_BATOCP_ALM, in bq25980_set_const_charge_curr()
412 ret = regmap_read(bq->regmap, BQ25980_BATOVP, &batovp_reg_code); in bq25980_get_const_charge_volt()
416 return ((batovp_reg_code * bq->chip_info->batovp_step) + in bq25980_get_const_charge_volt()
417 bq->chip_info->batovp_offset); in bq25980_get_const_charge_volt()
425 if (batovp < bq->chip_info->batovp_min) in bq25980_set_const_charge_volt()
426 batovp = bq->chip_info->batovp_min; in bq25980_set_const_charge_volt()
428 if (batovp > bq->chip_info->batovp_max) in bq25980_set_const_charge_volt()
429 batovp = bq->chip_info->batovp_max; in bq25980_set_const_charge_volt()
431 batovp_reg_code = (batovp - bq->chip_info->batovp_offset) / in bq25980_set_const_charge_volt()
432 bq->chip_info->batovp_step; in bq25980_set_const_charge_volt()
434 ret = regmap_write(bq->regmap, BQ25980_BATOVP, batovp_reg_code); in bq25980_set_const_charge_volt()
438 return regmap_write(bq->regmap, BQ25980_BATOVP_ALM, batovp_reg_code); in bq25980_set_const_charge_volt()
446 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_set_bypass()
449 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_set_bypass()
454 bq->state.bypass = en_bypass; in bq25980_set_bypass()
456 return bq->state.bypass; in bq25980_set_bypass()
464 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_set_chg_en()
467 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_set_chg_en()
472 bq->state.ce = en_chg; in bq25980_set_chg_en()
483 ret = regmap_read(bq->regmap, BQ25980_IBUS_ADC_MSB, &ibus_adc_msb); in bq25980_get_adc_ibus()
487 ret = regmap_read(bq->regmap, BQ25980_IBUS_ADC_LSB, &ibus_adc_lsb); in bq25980_get_adc_ibus()
505 ret = regmap_read(bq->regmap, BQ25980_VBUS_ADC_MSB, &vbus_adc_msb); in bq25980_get_adc_vbus()
509 ret = regmap_read(bq->regmap, BQ25980_VBUS_ADC_LSB, &vbus_adc_lsb); in bq25980_get_adc_vbus()
524 ret = regmap_read(bq->regmap, BQ25980_IBAT_ADC_MSB, &ibat_adc_msb); in bq25980_get_ibat_adc()
528 ret = regmap_read(bq->regmap, BQ25980_IBAT_ADC_LSB, &ibat_adc_lsb); in bq25980_get_ibat_adc()
546 ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_MSB, &vsys_adc_msb); in bq25980_get_adc_vbat()
550 ret = regmap_read(bq->regmap, BQ25980_VBAT_ADC_LSB, &vsys_adc_lsb); in bq25980_get_adc_vbat()
570 ret = regmap_read(bq->regmap, BQ25980_STAT1, &stat1); in bq25980_get_state()
574 ret = regmap_read(bq->regmap, BQ25980_STAT2, &stat2); in bq25980_get_state()
578 ret = regmap_read(bq->regmap, BQ25980_STAT3, &stat3); in bq25980_get_state()
582 ret = regmap_read(bq->regmap, BQ25980_STAT4, &stat4); in bq25980_get_state()
586 ret = regmap_read(bq->regmap, BQ25980_CHRGR_CTRL_2, &chg_ctrl_2); in bq25980_get_state()
590 ret = regmap_read(bq->regmap, BQ25980_IBAT_ADC_MSB, &ibat_adc_msb); in bq25980_get_state()
594 state->dischg = ibat_adc_msb & BQ25980_ADC_POLARITY_BIT; in bq25980_get_state()
595 state->ovp = (stat1 & BQ25980_STAT1_OVP_MASK) | in bq25980_get_state()
597 state->ocp = (stat1 & BQ25980_STAT1_OCP_MASK) | in bq25980_get_state()
599 state->tflt = stat4 & BQ25980_STAT4_TFLT_MASK; in bq25980_get_state()
600 state->wdt = stat4 & BQ25980_WD_STAT; in bq25980_get_state()
601 state->online = stat3 & BQ25980_PRESENT_MASK; in bq25980_get_state()
602 state->ce = chg_ctrl_2 & BQ25980_CHG_EN; in bq25980_get_state()
603 state->hiz = chg_ctrl_2 & BQ25980_EN_HIZ; in bq25980_get_state()
604 state->bypass = chg_ctrl_2 & BQ25980_EN_BYPASS; in bq25980_get_state()
618 val->intval = bq->init_data.ichg_max; in bq25980_get_battery_property()
622 val->intval = bq->init_data.vreg_max; in bq25980_get_battery_property()
627 val->intval = ret; in bq25980_get_battery_property()
635 val->intval = ret; in bq25980_get_battery_property()
639 return -EINVAL; in bq25980_get_battery_property()
650 int ret = -EINVAL; in bq25980_set_charger_property()
654 ret = bq25980_set_input_curr_lim(bq, val->intval); in bq25980_set_charger_property()
660 ret = bq25980_set_input_volt_lim(bq, val->intval); in bq25980_set_charger_property()
666 ret = bq25980_set_bypass(bq, val->intval); in bq25980_set_charger_property()
672 ret = bq25980_set_chg_en(bq, val->intval); in bq25980_set_charger_property()
678 ret = bq25980_set_const_charge_curr(bq, val->intval); in bq25980_set_charger_property()
684 ret = bq25980_set_const_charge_volt(bq, val->intval); in bq25980_set_charger_property()
690 return -EINVAL; in bq25980_set_charger_property()
704 mutex_lock(&bq->lock); in bq25980_get_charger_property()
706 mutex_unlock(&bq->lock); in bq25980_get_charger_property()
712 val->strval = BQ25980_MANUFACTURER; in bq25980_get_charger_property()
715 val->strval = bq->model_name; in bq25980_get_charger_property()
718 val->intval = state.online; in bq25980_get_charger_property()
725 val->intval = ret; in bq25980_get_charger_property()
733 val->intval = ret; in bq25980_get_charger_property()
737 val->intval = POWER_SUPPLY_HEALTH_GOOD; in bq25980_get_charger_property()
740 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in bq25980_get_charger_property()
741 else if (state.ovp) in bq25980_get_charger_property()
742 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in bq25980_get_charger_property()
744 val->intval = POWER_SUPPLY_HEALTH_OVERCURRENT; in bq25980_get_charger_property()
746 val->intval = in bq25980_get_charger_property()
751 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in bq25980_get_charger_property()
754 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq25980_get_charger_property()
756 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq25980_get_charger_property()
758 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq25980_get_charger_property()
762 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; in bq25980_get_charger_property()
765 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in bq25980_get_charger_property()
767 val->intval = POWER_SUPPLY_CHARGE_TYPE_BYPASS; in bq25980_get_charger_property()
769 val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; in bq25980_get_charger_property()
777 val->intval = ret; in bq25980_get_charger_property()
785 val->intval = ret; in bq25980_get_charger_property()
793 val->intval = ret; in bq25980_get_charger_property()
801 val->intval = ret; in bq25980_get_charger_property()
805 return -EINVAL; in bq25980_get_charger_property()
816 mutex_lock(&bq->lock); in bq25980_state_changed()
817 old_state = bq->state; in bq25980_state_changed()
818 mutex_unlock(&bq->lock); in bq25980_state_changed()
820 return (old_state.dischg != new_state->dischg || in bq25980_state_changed()
821 old_state.ovp != new_state->ovp || in bq25980_state_changed()
822 old_state.ocp != new_state->ocp || in bq25980_state_changed()
823 old_state.online != new_state->online || in bq25980_state_changed()
824 old_state.wdt != new_state->wdt || in bq25980_state_changed()
825 old_state.tflt != new_state->tflt || in bq25980_state_changed()
826 old_state.ce != new_state->ce || in bq25980_state_changed()
827 old_state.hiz != new_state->hiz || in bq25980_state_changed()
828 old_state.bypass != new_state->bypass); in bq25980_state_changed()
844 mutex_lock(&bq->lock); in bq25980_irq_handler_thread()
845 bq->state = state; in bq25980_irq_handler_thread()
846 mutex_unlock(&bq->lock); in bq25980_irq_handler_thread()
848 power_supply_changed(bq->charger); in bq25980_irq_handler_thread()
877 "main-battery",
897 .name = "bq25980-charger",
907 .name = "bq25980-battery",
1060 .of_node = dev->of_node, }; in bq25980_power_supply_init()
1065 bq->charger = devm_power_supply_register(bq->dev, in bq25980_power_supply_init()
1068 if (IS_ERR(bq->charger)) in bq25980_power_supply_init()
1069 return -EINVAL; in bq25980_power_supply_init()
1071 bq->battery = devm_power_supply_register(bq->dev, in bq25980_power_supply_init()
1074 if (IS_ERR(bq->battery)) in bq25980_power_supply_init()
1075 return -EINVAL; in bq25980_power_supply_init()
1084 int wd_max_val = BQ25980_NUM_WD_VAL - 1; in bq25980_hw_init()
1090 if (bq->watchdog_timer) { in bq25980_hw_init()
1091 if (bq->watchdog_timer >= bq25980_watchdog_time[wd_max_val]) in bq25980_hw_init()
1095 if (bq->watchdog_timer > bq25980_watchdog_time[i] && in bq25980_hw_init()
1096 bq->watchdog_timer < bq25980_watchdog_time[i + 1]) { in bq25980_hw_init()
1104 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_3, in bq25980_hw_init()
1109 ret = power_supply_get_battery_info(bq->charger, &bat_info); in bq25980_hw_init()
1111 dev_warn(bq->dev, "battery info missing\n"); in bq25980_hw_init()
1112 return -EINVAL; in bq25980_hw_init()
1115 bq->init_data.ichg_max = bat_info->constant_charge_current_max_ua; in bq25980_hw_init()
1116 bq->init_data.vreg_max = bat_info->constant_charge_voltage_max_uv; in bq25980_hw_init()
1118 if (bq->state.bypass) { in bq25980_hw_init()
1119 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2, in bq25980_hw_init()
1124 curr_val = bq->init_data.bypass_ilim; in bq25980_hw_init()
1125 volt_val = bq->init_data.bypass_vlim; in bq25980_hw_init()
1127 curr_val = bq->init_data.sc_ilim; in bq25980_hw_init()
1128 volt_val = bq->init_data.sc_vlim; in bq25980_hw_init()
1139 return regmap_update_bits(bq->regmap, BQ25980_ADC_CONTROL1, in bq25980_hw_init()
1147 ret = device_property_read_u32(bq->dev, "ti,watchdog-timeout-ms", in bq25980_parse_dt()
1148 &bq->watchdog_timer); in bq25980_parse_dt()
1150 bq->watchdog_timer = BQ25980_WATCHDOG_MIN; in bq25980_parse_dt()
1152 if (bq->watchdog_timer > BQ25980_WATCHDOG_MAX || in bq25980_parse_dt()
1153 bq->watchdog_timer < BQ25980_WATCHDOG_MIN) in bq25980_parse_dt()
1154 return -EINVAL; in bq25980_parse_dt()
1156 ret = device_property_read_u32(bq->dev, in bq25980_parse_dt()
1157 "ti,sc-ovp-limit-microvolt", in bq25980_parse_dt()
1158 &bq->init_data.sc_vlim); in bq25980_parse_dt()
1160 bq->init_data.sc_vlim = bq->chip_info->busovp_sc_def; in bq25980_parse_dt()
1162 if (bq->init_data.sc_vlim > bq->chip_info->busovp_sc_max || in bq25980_parse_dt()
1163 bq->init_data.sc_vlim < bq->chip_info->busovp_sc_min) { in bq25980_parse_dt()
1164 dev_err(bq->dev, "SC ovp limit is out of range\n"); in bq25980_parse_dt()
1165 return -EINVAL; in bq25980_parse_dt()
1168 ret = device_property_read_u32(bq->dev, in bq25980_parse_dt()
1169 "ti,sc-ocp-limit-microamp", in bq25980_parse_dt()
1170 &bq->init_data.sc_ilim); in bq25980_parse_dt()
1172 bq->init_data.sc_ilim = bq->chip_info->busocp_def; in bq25980_parse_dt()
1174 if (bq->init_data.sc_ilim > bq->chip_info->busocp_sc_max || in bq25980_parse_dt()
1175 bq->init_data.sc_ilim < bq->chip_info->busocp_sc_min) { in bq25980_parse_dt()
1176 dev_err(bq->dev, "SC ocp limit is out of range\n"); in bq25980_parse_dt()
1177 return -EINVAL; in bq25980_parse_dt()
1180 ret = device_property_read_u32(bq->dev, in bq25980_parse_dt()
1181 "ti,bypass-ovp-limit-microvolt", in bq25980_parse_dt()
1182 &bq->init_data.bypass_vlim); in bq25980_parse_dt()
1184 bq->init_data.bypass_vlim = bq->chip_info->busovp_byp_def; in bq25980_parse_dt()
1186 if (bq->init_data.bypass_vlim > bq->chip_info->busovp_byp_max || in bq25980_parse_dt()
1187 bq->init_data.bypass_vlim < bq->chip_info->busovp_byp_min) { in bq25980_parse_dt()
1188 dev_err(bq->dev, "Bypass ovp limit is out of range\n"); in bq25980_parse_dt()
1189 return -EINVAL; in bq25980_parse_dt()
1192 ret = device_property_read_u32(bq->dev, in bq25980_parse_dt()
1193 "ti,bypass-ocp-limit-microamp", in bq25980_parse_dt()
1194 &bq->init_data.bypass_ilim); in bq25980_parse_dt()
1196 bq->init_data.bypass_ilim = bq->chip_info->busocp_def; in bq25980_parse_dt()
1198 if (bq->init_data.bypass_ilim > bq->chip_info->busocp_byp_max || in bq25980_parse_dt()
1199 bq->init_data.bypass_ilim < bq->chip_info->busocp_byp_min) { in bq25980_parse_dt()
1200 dev_err(bq->dev, "Bypass ocp limit is out of range\n"); in bq25980_parse_dt()
1201 return -EINVAL; in bq25980_parse_dt()
1205 bq->state.bypass = device_property_read_bool(bq->dev, in bq25980_parse_dt()
1206 "ti,bypass-enable"); in bq25980_parse_dt()
1213 struct device *dev = &client->dev; in bq25980_probe()
1219 return -ENOMEM; in bq25980_probe()
1221 bq->client = client; in bq25980_probe()
1222 bq->dev = dev; in bq25980_probe()
1224 mutex_init(&bq->lock); in bq25980_probe()
1226 strscpy(bq->model_name, id->name, sizeof(bq->model_name)); in bq25980_probe()
1227 bq->chip_info = &bq25980_chip_info_tbl[id->driver_data]; in bq25980_probe()
1229 bq->regmap = devm_regmap_init_i2c(client, in bq25980_probe()
1230 bq->chip_info->regmap_config); in bq25980_probe()
1231 if (IS_ERR(bq->regmap)) { in bq25980_probe()
1233 return PTR_ERR(bq->regmap); in bq25980_probe()
1244 if (client->irq) { in bq25980_probe()
1245 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq25980_probe()
1249 dev_name(&client->dev), bq); in bq25980_probe()
1287 .name = "bq25980-charger",
1296 MODULE_AUTHOR("Ricardo Rivera-Matos <r-rivera-matos@ti.com>");