Lines Matching +full:input +full:- +full:precharge +full:- +full:resistor +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0-or-later
85 u8 iprechg; /* precharge current */
92 u8 rbatcomp; /* IBAT sense resistor value */
262 * Most of the val -> idx conversions can be computed, given the minimum,
312 0, -10, -20, -30, -40, -60, -70, -80,
313 -90, -10, -120, -140, -150, -170, -190, -210,
357 ret = regmap_field_read(bq->rmap_fields[field_id], &val); in bq25890_field_read()
367 return regmap_field_write(bq->rmap_fields[field_id], val); in bq25890_field_write()
384 rtbl_size = (rtbl->max - rtbl->min) / rtbl->step + 1; in bq25890_find_idx()
387 idx < rtbl_size && (idx * rtbl->step + rtbl->min <= value); in bq25890_find_idx()
392 return idx - 1; in bq25890_find_idx()
406 return (rtbl->min + idx * rtbl->step); in bq25890_find_val()
466 mutex_lock(&bq->lock); in bq25890_power_supply_get_property()
469 state = bq->state; in bq25890_power_supply_get_property()
473 mutex_unlock(&bq->lock); in bq25890_power_supply_get_property()
476 regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START], in bq25890_power_supply_get_property()
482 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in bq25890_power_supply_get_property()
484 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in bq25890_power_supply_get_property()
487 val->intval = POWER_SUPPLY_STATUS_CHARGING; in bq25890_power_supply_get_property()
489 val->intval = POWER_SUPPLY_STATUS_FULL; in bq25890_power_supply_get_property()
491 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in bq25890_power_supply_get_property()
498 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in bq25890_power_supply_get_property()
500 val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; in bq25890_power_supply_get_property()
502 val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; in bq25890_power_supply_get_property()
504 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; in bq25890_power_supply_get_property()
508 val->strval = BQ25890_MANUFACTURER; in bq25890_power_supply_get_property()
512 val->strval = bq25890_chip_name[bq->chip_version]; in bq25890_power_supply_get_property()
516 val->intval = state.online; in bq25890_power_supply_get_property()
521 val->intval = POWER_SUPPLY_HEALTH_GOOD; in bq25890_power_supply_get_property()
523 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in bq25890_power_supply_get_property()
525 val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; in bq25890_power_supply_get_property()
527 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in bq25890_power_supply_get_property()
529 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in bq25890_power_supply_get_property()
533 val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); in bq25890_power_supply_get_property()
536 if (bq->state.ntc_fault == NTC_FAULT_COOL) { in bq25890_power_supply_get_property()
542 val->intval /= 5; in bq25890_power_supply_get_property()
544 val->intval /= 2; in bq25890_power_supply_get_property()
550 val->intval = 0; in bq25890_power_supply_get_property()
559 val->intval = 2304000 + ret * 20000; in bq25890_power_supply_get_property()
563 val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); in bq25890_power_supply_get_property()
567 val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM); in bq25890_power_supply_get_property()
571 val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM); in bq25890_power_supply_get_property()
579 val->intval = bq25890_find_val(ret, TBL_IINLIM); in bq25890_power_supply_get_property()
588 val->intval = 2304000 + ret * 20000; in bq25890_power_supply_get_property()
597 val->intval = ret * -50000; in bq25890_power_supply_get_property()
606 val->intval = bq25890_find_val(ret, TBL_TSPCT); in bq25890_power_supply_get_property()
610 return -EINVAL; in bq25890_power_supply_get_property()
625 lval = bq25890_find_idx(val->intval, TBL_IINLIM); in bq25890_power_supply_set_property()
628 return -EINVAL; in bq25890_power_supply_set_property()
643 /* On the BQ25892 try to get charger-type info from our supplier */
650 if (bq->chip_version != BQ25892) in bq25890_charger_external_power_changed()
653 ret = power_supply_get_property_from_supplier(bq->charger, in bq25890_charger_external_power_changed()
662 if (bq->pump_express_vbus_max) { in bq25890_charger_external_power_changed()
664 &bq->pump_express_work, in bq25890_charger_external_power_changed()
689 {F_CHG_STAT, &state->chrg_status}, in bq25890_get_chip_state()
690 {F_PG_STAT, &state->online}, in bq25890_get_chip_state()
691 {F_VSYS_STAT, &state->vsys_status}, in bq25890_get_chip_state()
692 {F_BOOST_FAULT, &state->boost_fault}, in bq25890_get_chip_state()
693 {F_BAT_FAULT, &state->bat_fault}, in bq25890_get_chip_state()
694 {F_CHG_FAULT, &state->chrg_fault}, in bq25890_get_chip_state()
695 {F_NTC_FAULT, &state->ntc_fault} in bq25890_get_chip_state()
706 dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT/NTC=%d/%d/%d/%d\n", in bq25890_get_chip_state()
707 state->chrg_status, state->online, state->vsys_status, in bq25890_get_chip_state()
708 state->chrg_fault, state->boost_fault, state->bat_fault, in bq25890_get_chip_state()
709 state->ntc_fault); in bq25890_get_chip_state()
723 if (!memcmp(&bq->state, &new_state, sizeof(new_state))) in __bq25890_handle_irq()
726 if (!new_state.online && bq->state.online) { /* power removed */ in __bq25890_handle_irq()
731 } else if (new_state.online && !bq->state.online) { /* power inserted */ in __bq25890_handle_irq()
738 bq->state = new_state; in __bq25890_handle_irq()
739 power_supply_changed(bq->charger); in __bq25890_handle_irq()
743 dev_err(bq->dev, "Error communicating with the chip: %pe\n", in __bq25890_handle_irq()
753 mutex_lock(&bq->lock); in bq25890_irq_handler_thread()
755 mutex_unlock(&bq->lock); in bq25890_irq_handler_thread()
775 } while (ret == 1 && --rst_check_counter); in bq25890_chip_reset()
778 return -ETIMEDOUT; in bq25890_chip_reset()
785 bool write = !bq->read_back_init_data; in bq25890_rw_init_data()
793 {F_ICHG, &bq->init_data.ichg}, in bq25890_rw_init_data()
794 {F_VREG, &bq->init_data.vreg}, in bq25890_rw_init_data()
795 {F_ITERM, &bq->init_data.iterm}, in bq25890_rw_init_data()
796 {F_IPRECHG, &bq->init_data.iprechg}, in bq25890_rw_init_data()
797 {F_SYSVMIN, &bq->init_data.sysvmin}, in bq25890_rw_init_data()
798 {F_BOOSTV, &bq->init_data.boostv}, in bq25890_rw_init_data()
799 {F_BOOSTI, &bq->init_data.boosti}, in bq25890_rw_init_data()
800 {F_BOOSTF, &bq->init_data.boostf}, in bq25890_rw_init_data()
801 {F_EN_ILIM, &bq->init_data.ilim_en}, in bq25890_rw_init_data()
802 {F_TREG, &bq->init_data.treg}, in bq25890_rw_init_data()
803 {F_BATCMP, &bq->init_data.rbatcomp}, in bq25890_rw_init_data()
804 {F_VCLAMP, &bq->init_data.vclamp}, in bq25890_rw_init_data()
817 dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); in bq25890_rw_init_data()
829 if (!bq->skip_reset) { in bq25890_hw_init()
832 dev_dbg(bq->dev, "Reset failed %d\n", ret); in bq25890_hw_init()
843 dev_dbg(bq->dev, "Enabling charging failed %d\n", ret); in bq25890_hw_init()
851 dev_dbg(bq->dev, "Disabling watchdog failed %d\n", ret); in bq25890_hw_init()
860 ret = bq25890_get_chip_state(bq, &bq->state); in bq25890_hw_init()
862 dev_dbg(bq->dev, "Get state failed %d\n", ret); in bq25890_hw_init()
867 ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online); in bq25890_hw_init()
869 dev_dbg(bq->dev, "Config ADC failed %d\n", ret); in bq25890_hw_init()
895 "main-battery",
899 .name = "bq25890-charger",
916 bq->charger = devm_power_supply_register(bq->dev, in bq25890_power_supply_init()
920 return PTR_ERR_OR_ZERO(bq->charger); in bq25890_power_supply_init()
929 dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret); in bq25890_set_otg_cfg()
940 dev_dbg(bq->dev, "Start to request input voltage increasing\n"); in bq25890_pump_express_work()
951 dev_dbg(bq->dev, "input voltage = %d uV\n", voltage); in bq25890_pump_express_work()
954 bq->pump_express_vbus_max) in bq25890_pump_express_work()
961 /* Note a single PUMPX up pulse-sequence takes 2.1s */ in bq25890_pump_express_work()
962 ret = regmap_field_read_poll_timeout(bq->rmap_fields[F_PUMPX_UP], in bq25890_pump_express_work()
973 dev_info(bq->dev, "Hi-voltage charging requested, input voltage is %d mV\n", in bq25890_pump_express_work()
979 dev_err(bq->dev, "Failed to request hi-voltage charging\n"); in bq25890_pump_express_work()
988 switch (bq->usb_event) { in bq25890_usb_work()
998 power_supply_changed(bq->charger); in bq25890_usb_work()
1009 bq->usb_event = val; in bq25890_usb_notifier()
1010 queue_work(system_power_efficient_wq, &bq->usb_work); in bq25890_usb_notifier()
1045 .of_match = "usb-otg-vbus",
1060 dev_err(bq->dev, "Cannot read chip ID: %d\n", id); in bq25890_get_chip_version()
1066 dev_err(bq->dev, "Cannot read chip revision: %d\n", rev); in bq25890_get_chip_version()
1072 bq->chip_version = BQ25890; in bq25890_get_chip_version()
1079 bq->chip_version = BQ25896; in bq25890_get_chip_version()
1082 bq->chip_version = BQ25892; in bq25890_get_chip_version()
1085 dev_err(bq->dev, in bq25890_get_chip_version()
1088 bq->chip_version = BQ25892; in bq25890_get_chip_version()
1093 bq->chip_version = BQ25895; in bq25890_get_chip_version()
1097 dev_err(bq->dev, "Unknown chip ID %d\n", id); in bq25890_get_chip_version()
1098 return -ENODEV; in bq25890_get_chip_version()
1108 irq = devm_gpiod_get(bq->dev, BQ25890_IRQ_PIN, GPIOD_IN); in bq25890_irq_probe()
1110 return dev_err_probe(bq->dev, PTR_ERR(irq), in bq25890_irq_probe()
1121 struct bq25890_init_data *init = &bq->init_data; in bq25890_fw_read_u32_props()
1129 {"ti,charge-current", false, TBL_ICHG, &init->ichg}, in bq25890_fw_read_u32_props()
1130 {"ti,battery-regulation-voltage", false, TBL_VREG, &init->vreg}, in bq25890_fw_read_u32_props()
1131 {"ti,termination-current", false, TBL_ITERM, &init->iterm}, in bq25890_fw_read_u32_props()
1132 {"ti,precharge-current", false, TBL_ITERM, &init->iprechg}, in bq25890_fw_read_u32_props()
1133 {"ti,minimum-sys-voltage", false, TBL_SYSVMIN, &init->sysvmin}, in bq25890_fw_read_u32_props()
1134 {"ti,boost-voltage", false, TBL_BOOSTV, &init->boostv}, in bq25890_fw_read_u32_props()
1135 {"ti,boost-max-current", false, TBL_BOOSTI, &init->boosti}, in bq25890_fw_read_u32_props()
1138 {"ti,thermal-regulation-threshold", true, TBL_TREG, &init->treg}, in bq25890_fw_read_u32_props()
1139 {"ti,ibatcomp-micro-ohms", true, TBL_RBATCOMP, &init->rbatcomp}, in bq25890_fw_read_u32_props()
1140 {"ti,ibatcomp-clamp-microvolt", true, TBL_VBATCOMP, &init->vclamp}, in bq25890_fw_read_u32_props()
1144 init->treg = 3; /* 120 degrees Celsius */ in bq25890_fw_read_u32_props()
1145 init->rbatcomp = init->vclamp = 0; /* IBAT compensation disabled */ in bq25890_fw_read_u32_props()
1148 ret = device_property_read_u32(bq->dev, props[i].name, in bq25890_fw_read_u32_props()
1154 dev_err(bq->dev, "Unable to read property %d %s\n", ret, in bq25890_fw_read_u32_props()
1170 struct bq25890_init_data *init = &bq->init_data; in bq25890_fw_probe()
1173 device_property_read_u32(bq->dev, "linux,pump-express-vbus-max", in bq25890_fw_probe()
1174 &bq->pump_express_vbus_max); in bq25890_fw_probe()
1176 bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset"); in bq25890_fw_probe()
1177 bq->read_back_init_data = device_property_read_bool(bq->dev, in bq25890_fw_probe()
1178 "linux,read-back-settings"); in bq25890_fw_probe()
1179 if (bq->read_back_init_data) in bq25890_fw_probe()
1186 init->ilim_en = device_property_read_bool(bq->dev, "ti,use-ilim-pin"); in bq25890_fw_probe()
1187 init->boostf = device_property_read_bool(bq->dev, "ti,boost-low-freq"); in bq25890_fw_probe()
1195 struct device *dev = &client->dev; in bq25890_probe()
1201 return -ENOMEM; in bq25890_probe()
1203 bq->client = client; in bq25890_probe()
1204 bq->dev = dev; in bq25890_probe()
1206 mutex_init(&bq->lock); in bq25890_probe()
1207 INIT_DELAYED_WORK(&bq->pump_express_work, bq25890_pump_express_work); in bq25890_probe()
1209 bq->rmap = devm_regmap_init_i2c(client, &bq25890_regmap_config); in bq25890_probe()
1210 if (IS_ERR(bq->rmap)) in bq25890_probe()
1211 return dev_err_probe(dev, PTR_ERR(bq->rmap), in bq25890_probe()
1214 ret = devm_regmap_field_bulk_alloc(dev, bq->rmap, bq->rmap_fields, in bq25890_probe()
1237 if (client->irq <= 0) in bq25890_probe()
1238 client->irq = bq25890_irq_probe(bq); in bq25890_probe()
1240 if (client->irq < 0) { in bq25890_probe()
1242 return client->irq; in bq25890_probe()
1246 bq->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in bq25890_probe()
1247 if (!IS_ERR_OR_NULL(bq->usb_phy)) { in bq25890_probe()
1248 INIT_WORK(&bq->usb_work, bq25890_usb_work); in bq25890_probe()
1249 bq->usb_nb.notifier_call = bq25890_usb_notifier; in bq25890_probe()
1250 usb_register_notifier(bq->usb_phy, &bq->usb_nb); in bq25890_probe()
1261 cfg.init_data = pdata->regulator_init_data; in bq25890_probe()
1275 ret = devm_request_threaded_irq(dev, client->irq, NULL, in bq25890_probe()
1285 if (!IS_ERR_OR_NULL(bq->usb_phy)) in bq25890_probe()
1286 usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); in bq25890_probe()
1295 if (!IS_ERR_OR_NULL(bq->usb_phy)) in bq25890_remove()
1296 usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); in bq25890_remove()
1298 if (!bq->skip_reset) { in bq25890_remove()
1310 * introduce a function change for boards using the usb-phy framework. in bq25890_shutdown()
1313 if (!IS_ERR_OR_NULL(bq->usb_phy)) in bq25890_shutdown()
1318 * Micro-USB or Type-C USB port. Leaving this on drains power and in bq25890_shutdown()
1319 * this avoids the PMIC on some device-models seeing this as Vbus in bq25890_shutdown()
1321 * power-up again. in bq25890_shutdown()
1343 mutex_lock(&bq->lock); in bq25890_resume()
1345 ret = bq25890_get_chip_state(bq, &bq->state); in bq25890_resume()
1349 /* Re-enable ADC only if charger is plugged in. */ in bq25890_resume()
1350 if (bq->state.online) { in bq25890_resume()
1357 power_supply_changed(bq->charger); in bq25890_resume()
1360 mutex_unlock(&bq->lock); in bq25890_resume()
1398 .name = "bq25890-charger",