Lines Matching refs:bq
361 static int bq25890_field_read(struct bq25890_device *bq, in bq25890_field_read() argument
367 ret = regmap_field_read(bq->rmap_fields[field_id], &val); in bq25890_field_read()
374 static int bq25890_field_write(struct bq25890_device *bq, in bq25890_field_write() argument
377 return regmap_field_write(bq->rmap_fields[field_id], val); in bq25890_field_write()
454 static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq);
456 static int bq25890_get_vbus_voltage(struct bq25890_device *bq) in bq25890_get_vbus_voltage() argument
460 ret = bq25890_field_read(bq, F_VBUSV); in bq25890_get_vbus_voltage()
467 static void bq25890_update_state(struct bq25890_device *bq, in bq25890_update_state() argument
474 mutex_lock(&bq->lock); in bq25890_update_state()
476 __bq25890_handle_irq(bq); in bq25890_update_state()
477 *state = bq->state; in bq25890_update_state()
480 bq25890_field_write(bq, F_CONV_START, 1); in bq25890_update_state()
481 mutex_unlock(&bq->lock); in bq25890_update_state()
484 regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START], in bq25890_update_state()
492 struct bq25890_device *bq = power_supply_get_drvdata(psy); in bq25890_power_supply_get_property() local
496 bq25890_update_state(bq, psp, &state); in bq25890_power_supply_get_property()
532 val->strval = bq25890_chip_name[bq->chip_version]; in bq25890_power_supply_get_property()
553 val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM); in bq25890_power_supply_get_property()
557 val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM); in bq25890_power_supply_get_property()
561 ret = bq25890_field_read(bq, F_IINLIM); in bq25890_power_supply_get_property()
576 ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */ in bq25890_power_supply_get_property()
595 ret = bq25890_field_read(bq, F_ICHG); in bq25890_power_supply_get_property()
601 if (bq->state.ntc_fault == NTC_FAULT_COOL) { in bq25890_power_supply_get_property()
602 ret = bq25890_field_read(bq, F_JEITA_ISET); in bq25890_power_supply_get_property()
621 val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); in bq25890_power_supply_get_property()
632 ret = bq25890_field_read(bq, F_BATV); /* read measured value */ in bq25890_power_supply_get_property()
651 ret = bq25890_field_read(bq, F_VREG); in bq25890_power_supply_get_property()
666 val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); in bq25890_power_supply_get_property()
670 ret = bq25890_field_read(bq, F_TSPCT); in bq25890_power_supply_get_property()
689 struct bq25890_device *bq = power_supply_get_drvdata(psy); in bq25890_power_supply_set_property() local
696 maxval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); in bq25890_power_supply_set_property()
698 return bq25890_field_write(bq, F_ICHG, lval); in bq25890_power_supply_set_property()
700 maxval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); in bq25890_power_supply_set_property()
702 return bq25890_field_write(bq, F_VREG, lval); in bq25890_power_supply_set_property()
705 return bq25890_field_write(bq, F_IINLIM, lval); in bq25890_power_supply_set_property()
707 ret = bq25890_field_write(bq, F_EN_HIZ, !val->intval); in bq25890_power_supply_set_property()
709 bq->force_hiz = !val->intval; in bq25890_power_supply_set_property()
710 bq25890_update_state(bq, psp, &state); in bq25890_power_supply_set_property()
736 static int bq25890_charger_get_scaled_iinlim_regval(struct bq25890_device *bq, in bq25890_charger_get_scaled_iinlim_regval() argument
739 iinlim_ua = iinlim_ua * bq->iinlim_percentage / 100; in bq25890_charger_get_scaled_iinlim_regval()
746 struct bq25890_device *bq = power_supply_get_drvdata(psy); in bq25890_charger_external_power_changed() local
750 if (bq->chip_version != BQ25892) in bq25890_charger_external_power_changed()
761 input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 2000000); in bq25890_charger_external_power_changed()
762 if (bq->pump_express_vbus_max) { in bq25890_charger_external_power_changed()
764 &bq->pump_express_work, in bq25890_charger_external_power_changed()
770 input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 1500000); in bq25890_charger_external_power_changed()
774 input_current_limit = bq25890_charger_get_scaled_iinlim_regval(bq, 500000); in bq25890_charger_external_power_changed()
777 bq25890_field_write(bq, F_IINLIM, input_current_limit); in bq25890_charger_external_power_changed()
781 static int bq25890_get_chip_state(struct bq25890_device *bq, in bq25890_get_chip_state() argument
801 ret = bq25890_field_read(bq, state_fields[i].id); in bq25890_get_chip_state()
808 dev_dbg(bq->dev, "S:CHG/PG/HIZ/VSYS=%d/%d/%d/%d, F:CHG/BOOST/BAT/NTC=%d/%d/%d/%d\n", in bq25890_get_chip_state()
817 static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq) in __bq25890_handle_irq() argument
823 ret = bq25890_get_chip_state(bq, &new_state); in __bq25890_handle_irq()
827 if (!memcmp(&bq->state, &new_state, sizeof(new_state))) in __bq25890_handle_irq()
834 if (new_state.online && !bq->state.online && bq->force_hiz) { in __bq25890_handle_irq()
835 ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz); in __bq25890_handle_irq()
842 adc_conv_rate = bq->state.online && !bq->state.hiz; in __bq25890_handle_irq()
846 ret = bq25890_field_write(bq, F_CONV_RATE, new_adc_conv_rate); in __bq25890_handle_irq()
851 bq->state = new_state; in __bq25890_handle_irq()
852 power_supply_changed(bq->charger); in __bq25890_handle_irq()
856 dev_err(bq->dev, "Error communicating with the chip: %pe\n", in __bq25890_handle_irq()
863 struct bq25890_device *bq = private; in bq25890_irq_handler_thread() local
866 mutex_lock(&bq->lock); in bq25890_irq_handler_thread()
867 ret = __bq25890_handle_irq(bq); in bq25890_irq_handler_thread()
868 mutex_unlock(&bq->lock); in bq25890_irq_handler_thread()
873 static int bq25890_chip_reset(struct bq25890_device *bq) in bq25890_chip_reset() argument
878 ret = bq25890_field_write(bq, F_REG_RST, 1); in bq25890_chip_reset()
883 ret = bq25890_field_read(bq, F_REG_RST); in bq25890_chip_reset()
896 static int bq25890_rw_init_data(struct bq25890_device *bq) in bq25890_rw_init_data() argument
898 bool write = !bq->read_back_init_data; in bq25890_rw_init_data()
906 {F_ICHG, &bq->init_data.ichg}, in bq25890_rw_init_data()
907 {F_VREG, &bq->init_data.vreg}, in bq25890_rw_init_data()
908 {F_ITERM, &bq->init_data.iterm}, in bq25890_rw_init_data()
909 {F_IPRECHG, &bq->init_data.iprechg}, in bq25890_rw_init_data()
910 {F_SYSVMIN, &bq->init_data.sysvmin}, in bq25890_rw_init_data()
911 {F_BOOSTV, &bq->init_data.boostv}, in bq25890_rw_init_data()
912 {F_BOOSTI, &bq->init_data.boosti}, in bq25890_rw_init_data()
913 {F_BOOSTF, &bq->init_data.boostf}, in bq25890_rw_init_data()
914 {F_EN_ILIM, &bq->init_data.ilim_en}, in bq25890_rw_init_data()
915 {F_TREG, &bq->init_data.treg}, in bq25890_rw_init_data()
916 {F_BATCMP, &bq->init_data.rbatcomp}, in bq25890_rw_init_data()
917 {F_VCLAMP, &bq->init_data.vclamp}, in bq25890_rw_init_data()
922 ret = bq25890_field_write(bq, init_data[i].id, in bq25890_rw_init_data()
925 ret = bq25890_field_read(bq, init_data[i].id); in bq25890_rw_init_data()
930 dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); in bq25890_rw_init_data()
938 static int bq25890_hw_init(struct bq25890_device *bq) in bq25890_hw_init() argument
942 if (!bq->skip_reset) { in bq25890_hw_init()
943 ret = bq25890_chip_reset(bq); in bq25890_hw_init()
945 dev_dbg(bq->dev, "Reset failed %d\n", ret); in bq25890_hw_init()
954 ret = bq25890_field_write(bq, F_CHG_CFG, 1); in bq25890_hw_init()
956 dev_dbg(bq->dev, "Enabling charging failed %d\n", ret); in bq25890_hw_init()
962 ret = bq25890_field_write(bq, F_WD, 0); in bq25890_hw_init()
964 dev_dbg(bq->dev, "Disabling watchdog failed %d\n", ret); in bq25890_hw_init()
969 ret = bq25890_rw_init_data(bq); in bq25890_hw_init()
973 ret = bq25890_get_chip_state(bq, &bq->state); in bq25890_hw_init()
975 dev_dbg(bq->dev, "Get state failed %d\n", ret); in bq25890_hw_init()
980 ret = bq25890_field_write(bq, F_CONV_RATE, bq->state.online && !bq->state.hiz); in bq25890_hw_init()
982 dev_dbg(bq->dev, "Config ADC failed %d\n", ret); in bq25890_hw_init()
1022 static int bq25890_power_supply_init(struct bq25890_device *bq) in bq25890_power_supply_init() argument
1024 struct power_supply_config psy_cfg = { .drv_data = bq, }; in bq25890_power_supply_init()
1028 bq->id = idr_alloc(&bq25890_id, bq, 0, 0, GFP_KERNEL); in bq25890_power_supply_init()
1030 if (bq->id < 0) in bq25890_power_supply_init()
1031 return bq->id; in bq25890_power_supply_init()
1033 snprintf(bq->name, sizeof(bq->name), "bq25890-charger-%d", bq->id); in bq25890_power_supply_init()
1034 bq->desc = bq25890_power_supply_desc; in bq25890_power_supply_init()
1035 bq->desc.name = bq->name; in bq25890_power_supply_init()
1040 bq->charger = devm_power_supply_register(bq->dev, &bq->desc, &psy_cfg); in bq25890_power_supply_init()
1042 return PTR_ERR_OR_ZERO(bq->charger); in bq25890_power_supply_init()
1045 static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val) in bq25890_set_otg_cfg() argument
1049 ret = bq25890_field_write(bq, F_OTG_CFG, val); in bq25890_set_otg_cfg()
1051 dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret); in bq25890_set_otg_cfg()
1058 struct bq25890_device *bq = in bq25890_pump_express_work() local
1063 dev_dbg(bq->dev, "Start to request input voltage increasing\n"); in bq25890_pump_express_work()
1066 if (bq->secondary_chrg) { in bq25890_pump_express_work()
1068 power_supply_set_property(bq->secondary_chrg, POWER_SUPPLY_PROP_ONLINE, &value); in bq25890_pump_express_work()
1072 ret = bq25890_field_write(bq, F_PUMPX_EN, 1); in bq25890_pump_express_work()
1077 voltage = bq25890_get_vbus_voltage(bq); in bq25890_pump_express_work()
1080 dev_dbg(bq->dev, "input voltage = %d uV\n", voltage); in bq25890_pump_express_work()
1083 bq->pump_express_vbus_max) in bq25890_pump_express_work()
1086 ret = bq25890_field_write(bq, F_PUMPX_UP, 1); in bq25890_pump_express_work()
1091 ret = regmap_field_read_poll_timeout(bq->rmap_fields[F_PUMPX_UP], in bq25890_pump_express_work()
1100 bq25890_field_write(bq, F_PUMPX_EN, 0); in bq25890_pump_express_work()
1102 if (bq->secondary_chrg) { in bq25890_pump_express_work()
1104 power_supply_set_property(bq->secondary_chrg, POWER_SUPPLY_PROP_ONLINE, &value); in bq25890_pump_express_work()
1107 dev_info(bq->dev, "Hi-voltage charging requested, input voltage is %d mV\n", in bq25890_pump_express_work()
1110 power_supply_changed(bq->charger); in bq25890_pump_express_work()
1114 bq25890_field_write(bq, F_PUMPX_EN, 0); in bq25890_pump_express_work()
1115 dev_err(bq->dev, "Failed to request hi-voltage charging\n"); in bq25890_pump_express_work()
1121 struct bq25890_device *bq = in bq25890_usb_work() local
1124 switch (bq->usb_event) { in bq25890_usb_work()
1127 bq25890_set_otg_cfg(bq, 1); in bq25890_usb_work()
1132 ret = bq25890_set_otg_cfg(bq, 0); in bq25890_usb_work()
1134 power_supply_changed(bq->charger); in bq25890_usb_work()
1142 struct bq25890_device *bq = in bq25890_usb_notifier() local
1145 bq->usb_event = val; in bq25890_usb_notifier()
1146 queue_work(system_power_efficient_wq, &bq->usb_work); in bq25890_usb_notifier()
1154 struct bq25890_device *bq = rdev_get_drvdata(rdev); in bq25890_vbus_enable() local
1164 if (bq->secondary_chrg) in bq25890_vbus_enable()
1165 power_supply_set_property(bq->secondary_chrg, POWER_SUPPLY_PROP_ONLINE, &val); in bq25890_vbus_enable()
1167 return bq25890_set_otg_cfg(bq, 1); in bq25890_vbus_enable()
1172 struct bq25890_device *bq = rdev_get_drvdata(rdev); in bq25890_vbus_disable() local
1178 ret = bq25890_set_otg_cfg(bq, 0); in bq25890_vbus_disable()
1182 if (bq->secondary_chrg) in bq25890_vbus_disable()
1183 power_supply_set_property(bq->secondary_chrg, POWER_SUPPLY_PROP_ONLINE, &val); in bq25890_vbus_disable()
1190 struct bq25890_device *bq = rdev_get_drvdata(rdev); in bq25890_vbus_is_enabled() local
1192 return bq25890_field_read(bq, F_OTG_CFG); in bq25890_vbus_is_enabled()
1197 struct bq25890_device *bq = rdev_get_drvdata(rdev); in bq25890_vbus_get_voltage() local
1199 return bq25890_get_vbus_voltage(bq); in bq25890_vbus_get_voltage()
1204 struct bq25890_device *bq = rdev_get_drvdata(rdev); in bq25890_vsys_get_voltage() local
1208 ret = bq25890_field_read(bq, F_SYSV); /* read measured value */ in bq25890_vsys_get_voltage()
1243 static int bq25890_register_regulator(struct bq25890_device *bq) in bq25890_register_regulator() argument
1245 struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev); in bq25890_register_regulator()
1247 .dev = bq->dev, in bq25890_register_regulator()
1248 .driver_data = bq, in bq25890_register_regulator()
1255 reg = devm_regulator_register(bq->dev, &bq25890_vbus_desc, &cfg); in bq25890_register_regulator()
1257 return dev_err_probe(bq->dev, PTR_ERR(reg), in bq25890_register_regulator()
1263 reg = devm_regulator_register(bq->dev, &bq25890_vsys_desc, &cfg); in bq25890_register_regulator()
1265 return dev_err_probe(bq->dev, PTR_ERR(reg), in bq25890_register_regulator()
1273 bq25890_register_regulator(struct bq25890_device *bq) in bq25890_register_regulator() argument
1279 static int bq25890_get_chip_version(struct bq25890_device *bq) in bq25890_get_chip_version() argument
1283 id = bq25890_field_read(bq, F_PN); in bq25890_get_chip_version()
1285 dev_err(bq->dev, "Cannot read chip ID: %d\n", id); in bq25890_get_chip_version()
1289 rev = bq25890_field_read(bq, F_DEV_REV); in bq25890_get_chip_version()
1291 dev_err(bq->dev, "Cannot read chip revision: %d\n", rev); in bq25890_get_chip_version()
1297 bq->chip_version = BQ25890; in bq25890_get_chip_version()
1304 bq->chip_version = BQ25896; in bq25890_get_chip_version()
1307 bq->chip_version = BQ25892; in bq25890_get_chip_version()
1310 dev_err(bq->dev, in bq25890_get_chip_version()
1313 bq->chip_version = BQ25892; in bq25890_get_chip_version()
1318 bq->chip_version = BQ25895; in bq25890_get_chip_version()
1322 dev_err(bq->dev, "Unknown chip ID %d\n", id); in bq25890_get_chip_version()
1329 static int bq25890_irq_probe(struct bq25890_device *bq) in bq25890_irq_probe() argument
1333 irq = devm_gpiod_get(bq->dev, BQ25890_IRQ_PIN, GPIOD_IN); in bq25890_irq_probe()
1335 return dev_err_probe(bq->dev, PTR_ERR(irq), in bq25890_irq_probe()
1341 static int bq25890_fw_read_u32_props(struct bq25890_device *bq) in bq25890_fw_read_u32_props() argument
1346 struct bq25890_init_data *init = &bq->init_data; in bq25890_fw_read_u32_props()
1373 ret = device_property_read_u32(bq->dev, props[i].name, in bq25890_fw_read_u32_props()
1379 dev_err(bq->dev, "Unable to read property %d %s\n", ret, in bq25890_fw_read_u32_props()
1392 static int bq25890_fw_probe(struct bq25890_device *bq) in bq25890_fw_probe() argument
1395 struct bq25890_init_data *init = &bq->init_data; in bq25890_fw_probe()
1399 ret = device_property_read_string(bq->dev, "linux,secondary-charger-name", &str); in bq25890_fw_probe()
1401 bq->secondary_chrg = power_supply_get_by_name(str); in bq25890_fw_probe()
1402 if (!bq->secondary_chrg) in bq25890_fw_probe()
1407 device_property_read_u32(bq->dev, "linux,pump-express-vbus-max", in bq25890_fw_probe()
1408 &bq->pump_express_vbus_max); in bq25890_fw_probe()
1410 ret = device_property_read_u32(bq->dev, "linux,iinlim-percentage", &val); in bq25890_fw_probe()
1413 dev_err(bq->dev, "Error linux,iinlim-percentage %u > 100\n", val); in bq25890_fw_probe()
1416 bq->iinlim_percentage = val; in bq25890_fw_probe()
1418 bq->iinlim_percentage = 100; in bq25890_fw_probe()
1421 bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset"); in bq25890_fw_probe()
1422 bq->read_back_init_data = device_property_read_bool(bq->dev, in bq25890_fw_probe()
1424 if (bq->read_back_init_data) in bq25890_fw_probe()
1427 ret = bq25890_fw_read_u32_props(bq); in bq25890_fw_probe()
1431 init->ilim_en = device_property_read_bool(bq->dev, "ti,use-ilim-pin"); in bq25890_fw_probe()
1432 init->boostf = device_property_read_bool(bq->dev, "ti,boost-low-freq"); in bq25890_fw_probe()
1439 struct bq25890_device *bq = data; in bq25890_non_devm_cleanup() local
1441 cancel_delayed_work_sync(&bq->pump_express_work); in bq25890_non_devm_cleanup()
1443 if (bq->id >= 0) { in bq25890_non_devm_cleanup()
1445 idr_remove(&bq25890_id, bq->id); in bq25890_non_devm_cleanup()
1453 struct bq25890_device *bq; in bq25890_probe() local
1456 bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); in bq25890_probe()
1457 if (!bq) in bq25890_probe()
1460 bq->client = client; in bq25890_probe()
1461 bq->dev = dev; in bq25890_probe()
1462 bq->id = -1; in bq25890_probe()
1464 mutex_init(&bq->lock); in bq25890_probe()
1465 INIT_DELAYED_WORK(&bq->pump_express_work, bq25890_pump_express_work); in bq25890_probe()
1467 bq->rmap = devm_regmap_init_i2c(client, &bq25890_regmap_config); in bq25890_probe()
1468 if (IS_ERR(bq->rmap)) in bq25890_probe()
1469 return dev_err_probe(dev, PTR_ERR(bq->rmap), in bq25890_probe()
1472 ret = devm_regmap_field_bulk_alloc(dev, bq->rmap, bq->rmap_fields, in bq25890_probe()
1477 i2c_set_clientdata(client, bq); in bq25890_probe()
1479 ret = bq25890_get_chip_version(bq); in bq25890_probe()
1485 ret = bq25890_fw_probe(bq); in bq25890_probe()
1489 ret = bq25890_hw_init(bq); in bq25890_probe()
1496 client->irq = bq25890_irq_probe(bq); in bq25890_probe()
1504 bq->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in bq25890_probe()
1510 ret = devm_add_action_or_reset(dev, bq25890_non_devm_cleanup, bq); in bq25890_probe()
1514 ret = bq25890_register_regulator(bq); in bq25890_probe()
1518 ret = bq25890_power_supply_init(bq); in bq25890_probe()
1525 BQ25890_IRQ_PIN, bq); in bq25890_probe()
1529 if (!IS_ERR_OR_NULL(bq->usb_phy)) { in bq25890_probe()
1530 INIT_WORK(&bq->usb_work, bq25890_usb_work); in bq25890_probe()
1531 bq->usb_nb.notifier_call = bq25890_usb_notifier; in bq25890_probe()
1532 usb_register_notifier(bq->usb_phy, &bq->usb_nb); in bq25890_probe()
1540 struct bq25890_device *bq = i2c_get_clientdata(client); in bq25890_remove() local
1542 if (!IS_ERR_OR_NULL(bq->usb_phy)) { in bq25890_remove()
1543 usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); in bq25890_remove()
1544 cancel_work_sync(&bq->usb_work); in bq25890_remove()
1547 if (!bq->skip_reset) { in bq25890_remove()
1549 bq25890_chip_reset(bq); in bq25890_remove()
1555 struct bq25890_device *bq = i2c_get_clientdata(client); in bq25890_shutdown() local
1562 if (!IS_ERR_OR_NULL(bq->usb_phy)) in bq25890_shutdown()
1572 bq25890_set_otg_cfg(bq, 0); in bq25890_shutdown()
1578 struct bq25890_device *bq = dev_get_drvdata(dev); in bq25890_suspend() local
1584 return bq25890_field_write(bq, F_CONV_RATE, 0); in bq25890_suspend()
1590 struct bq25890_device *bq = dev_get_drvdata(dev); in bq25890_resume() local
1592 mutex_lock(&bq->lock); in bq25890_resume()
1594 ret = bq25890_get_chip_state(bq, &bq->state); in bq25890_resume()
1599 if (bq->state.online) { in bq25890_resume()
1600 ret = bq25890_field_write(bq, F_CONV_RATE, 1); in bq25890_resume()
1606 power_supply_changed(bq->charger); in bq25890_resume()
1609 mutex_unlock(&bq->lock); in bq25890_resume()