Lines Matching +full:full +full:- +full:ohms
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Analog Devices (Linear Technology) LTC4162-L charger IC.
58 c_over_x_term = 8, /* battery is full */
93 if (info->cell_count) in ltc4162l_get_cell_count()
94 return info->cell_count; in ltc4162l_get_cell_count()
96 ret = regmap_read(info->regmap, LTC4162L_CHEM_CELLS_REG, &val); in ltc4162l_get_cell_count()
106 info->cell_count = val; in ltc4162l_get_cell_count()
134 ret = regmap_read(info->regmap, LTC4162L_CHARGER_STATE, ®val); in ltc4162l_get_status()
136 dev_err(&info->client->dev, "Failed to read CHARGER_STATE\n"); in ltc4162l_get_status()
140 val->intval = ltc4162l_state_decode(regval); in ltc4162l_get_status()
164 ret = regmap_read(info->regmap, LTC4162L_CHARGE_STATUS, ®val); in ltc4162l_get_charge_type()
168 val->intval = ltc4162l_charge_status_decode(regval); in ltc4162l_get_charge_type()
197 ret = regmap_read(info->regmap, LTC4162L_CHARGER_STATE, ®val); in ltc4162l_get_health()
201 val->intval = ltc4162l_state_to_health(regval); in ltc4162l_get_health()
212 ret = regmap_read(info->regmap, LTC4162L_SYSTEM_STATUS_REG, ®val); in ltc4162l_get_online()
217 val->intval = !!(regval & BIT(2)); in ltc4162l_get_online()
229 ret = regmap_read(info->regmap, reg, ®val); in ltc4162l_get_vbat()
237 val->intval = regval; in ltc4162l_get_vbat()
248 ret = regmap_read(info->regmap, LTC4162L_IBAT, ®val); in ltc4162l_get_ibat()
252 /* Signed 16-bit number, 1.466μV / RSNSB amperes/LSB. */ in ltc4162l_get_ibat()
254 val->intval = 100 * mult_frac(ret, 14660, (int)info->rsnsb); in ltc4162l_get_ibat()
266 ret = regmap_read(info->regmap, LTC4162L_VIN, ®val); in ltc4162l_get_input_voltage()
271 val->intval = regval * 1694; in ltc4162l_get_input_voltage()
282 ret = regmap_read(info->regmap, LTC4162L_IIN, ®val); in ltc4162l_get_input_current()
286 /* Signed 16-bit number, 1.466μV / RSNSI amperes/LSB. */ in ltc4162l_get_input_current()
289 ret /= info->rsnsi; in ltc4162l_get_input_current()
292 val->intval = ret; in ltc4162l_get_input_current()
304 ret = regmap_read(info->regmap, reg, ®val); in ltc4162l_get_icharge()
308 regval &= BIT(6) - 1; /* Only the lower 5 bits */ in ltc4162l_get_icharge()
312 val->intval = 10000u * mult_frac(regval, 100000u, info->rsnsb); in ltc4162l_get_icharge()
321 value = mult_frac(value, info->rsnsb, 100000u); in ltc4162l_set_icharge()
326 --value; in ltc4162l_set_icharge()
329 return -EINVAL; in ltc4162l_set_icharge()
331 return regmap_write(info->regmap, reg, value); in ltc4162l_set_icharge()
343 ret = regmap_read(info->regmap, reg, ®val); in ltc4162l_get_vcharge()
347 regval &= BIT(6) - 1; /* Only the lower 5 bits */ in ltc4162l_get_vcharge()
356 val->intval = voltage; in ltc4162l_get_vcharge()
368 return -EBUSY; /* Not available yet, try again later */ in ltc4162l_set_vcharge()
373 return -EINVAL; in ltc4162l_set_vcharge()
375 value -= 3812500; in ltc4162l_set_vcharge()
379 return -EINVAL; in ltc4162l_set_vcharge()
381 return regmap_write(info->regmap, reg, value); in ltc4162l_set_vcharge()
390 ret = regmap_read(info->regmap, LTC4162L_IIN_LIMIT_DAC, ®val); in ltc4162l_get_iin_limit_dac()
394 regval &= BIT(6) - 1; /* Only 6 bits */ in ltc4162l_get_iin_limit_dac()
399 regval /= info->rsnsi; in ltc4162l_get_iin_limit_dac()
400 val->intval = 100u * regval; in ltc4162l_get_iin_limit_dac()
410 regval = mult_frac(value, info->rsnsi, 50000u); in ltc4162l_set_iin_limit()
413 --regval; in ltc4162l_set_iin_limit()
417 return regmap_write(info->regmap, LTC4162L_IIN_LIMIT_TARGET, regval); in ltc4162l_set_iin_limit()
426 ret = regmap_read(info->regmap, LTC4162L_DIE_TEMPERATURE, ®val); in ltc4162l_get_die_temp()
430 /* die_temp × 0.0215°C/LSB - 264.4°C */ in ltc4162l_get_die_temp()
434 ret -= 26440; in ltc4162l_get_die_temp()
435 val->intval = ret; in ltc4162l_get_die_temp()
446 ret = regmap_read(info->regmap, LTC4162L_CHARGER_CONFIG_BITS, ®val); in ltc4162l_get_term_current()
452 val->intval = 0; in ltc4162l_get_term_current()
456 ret = regmap_read(info->regmap, LTC4162L_C_OVER_X_THRESHOLD, ®val); in ltc4162l_get_term_current()
462 regval /= info->rsnsb; in ltc4162l_get_term_current()
463 val->intval = 100 * regval; in ltc4162l_get_term_current()
476 return regmap_update_bits(info->regmap, in ltc4162l_set_term_current()
481 regval = mult_frac(value, info->rsnsb, 14660u); in ltc4162l_set_term_current()
484 ret = regmap_write(info->regmap, LTC4162L_C_OVER_X_THRESHOLD, regval); in ltc4162l_set_term_current()
489 return regmap_update_bits(info->regmap, LTC4162L_CHARGER_CONFIG_BITS, in ltc4162l_set_term_current()
510 ARRAY_SIZE(ltc4162l_charge_status_name) - 1]; in charge_status_show()
516 ret = regmap_read(info->regmap, LTC4162L_CHARGE_STATUS, ®val); in charge_status_show()
588 ret = regmap_read(info->regmap, LTC4162L_CONFIG_BITS_REG, ®val); in force_telemetry_show()
609 ret = regmap_update_bits(info->regmap, LTC4162L_CONFIG_BITS_REG, in force_telemetry_store()
627 ret = regmap_read(info->regmap, LTC4162L_ARM_SHIP_MODE, ®val); in arm_ship_mode_show()
649 ret = regmap_write(info->regmap, LTC4162L_ARM_SHIP_MODE, in arm_ship_mode_store()
717 return -EINVAL; in ltc4162l_get_property()
730 LTC4162L_CHARGE_CURRENT_SETTING, val->intval); in ltc4162l_set_property()
733 LTC4162L_VCHARGE_SETTING, val->intval); in ltc4162l_set_property()
735 return ltc4162l_set_iin_limit(info, val->intval); in ltc4162l_set_property()
737 return ltc4162l_set_term_current(info, val->intval); in ltc4162l_set_property()
739 return -EINVAL; in ltc4162l_set_property()
775 .name = "ltc4162-l",
800 /* all registers after this one are read-only status registers */ in ltc4162l_is_volatile_reg()
817 regmap_write(info->regmap, LTC4162L_LIMIT_ALERTS_REG, 0); in ltc4162l_clear_interrupts()
818 regmap_write(info->regmap, LTC4162L_CHARGER_STATE_ALERTS_REG, 0); in ltc4162l_clear_interrupts()
819 regmap_write(info->regmap, LTC4162L_CHARGE_STATUS_ALERTS_REG, 0); in ltc4162l_clear_interrupts()
824 struct i2c_adapter *adapter = client->adapter; in ltc4162l_probe()
825 struct device *dev = &client->dev; in ltc4162l_probe()
833 return -ENODEV; in ltc4162l_probe()
837 return -ENOMEM; in ltc4162l_probe()
839 info->client = client; in ltc4162l_probe()
842 info->regmap = devm_regmap_init_i2c(client, <c4162l_regmap_config); in ltc4162l_probe()
843 if (IS_ERR(info->regmap)) { in ltc4162l_probe()
845 return PTR_ERR(info->regmap); in ltc4162l_probe()
848 ret = device_property_read_u32(dev, "lltc,rsnsb-micro-ohms", in ltc4162l_probe()
849 &info->rsnsb); in ltc4162l_probe()
851 dev_err(dev, "Missing lltc,rsnsb-micro-ohms property\n"); in ltc4162l_probe()
854 if (!info->rsnsb) in ltc4162l_probe()
855 return -EINVAL; in ltc4162l_probe()
857 ret = device_property_read_u32(dev, "lltc,rsnsi-micro-ohms", in ltc4162l_probe()
858 &info->rsnsi); in ltc4162l_probe()
860 dev_err(dev, "Missing lltc,rsnsi-micro-ohms property\n"); in ltc4162l_probe()
863 if (!info->rsnsi) in ltc4162l_probe()
864 return -EINVAL; in ltc4162l_probe()
866 if (!device_property_read_u32(dev, "lltc,cell-count", &value)) in ltc4162l_probe()
867 info->cell_count = value; in ltc4162l_probe()
869 ltc4162l_config.of_node = dev->of_node; in ltc4162l_probe()
873 info->charger = devm_power_supply_register(dev, <c4162l_desc, in ltc4162l_probe()
875 if (IS_ERR(info->charger)) { in ltc4162l_probe()
877 return PTR_ERR(info->charger); in ltc4162l_probe()
881 regmap_write(info->regmap, LTC4162L_EN_LIMIT_ALERTS_REG, 0); in ltc4162l_probe()
884 regmap_write(info->regmap, LTC4162L_EN_CHARGER_STATE_ALERTS_REG, in ltc4162l_probe()
886 regmap_write(info->regmap, LTC4162L_EN_CHARGE_STATUS_ALERTS_REG, 0x1f); in ltc4162l_probe()
902 power_supply_changed(info->charger); in ltc4162l_alert()
906 { "ltc4162-l", 0 },
912 { .compatible = "lltc,ltc4162-l", },
922 .name = "ltc4162-l-charger",
930 MODULE_DESCRIPTION("LTC4162-L charger driver");