Lines Matching +full:enable +full:- +full:charge +full:- +full:control

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/devm-helpers.h>
77 int charge; /* Last charge register content */ member
85 return ((Q * (info->Qlsb / 10))) / 100; in convert_bin_to_uAh()
93 Q = (uAh * 100) / (info->Qlsb/10); in convert_uAh_to_bin()
104 msgs[0].addr = client->addr; in ltc294x_read_regs()
108 msgs[1].addr = client->addr; in ltc294x_read_regs()
113 ret = i2c_transfer(client->adapter, &msgs[0], 2); in ltc294x_read_regs()
115 dev_err(&client->dev, "ltc2941 read_reg(0x%x[%d]) failed: %pe\n", in ltc294x_read_regs()
120 dev_dbg(&client->dev, "%s (%#x, %d) -> %#x\n", in ltc294x_read_regs()
134 dev_err(&client->dev, "ltc2941 write_reg(0x%x[%d]) failed: %pe\n", in ltc294x_write_regs()
139 dev_dbg(&client->dev, "%s (%#x, %d) -> %#x\n", in ltc294x_write_regs()
149 u8 control; in ltc294x_reset() local
151 /* Read status and control registers */ in ltc294x_reset()
152 ret = ltc294x_read_regs(info->client, LTC294X_REG_CONTROL, &value, 1); in ltc294x_reset()
156 control = LTC294X_REG_CONTROL_PRESCALER_SET(prescaler_exp) | in ltc294x_reset()
159 switch (info->id) { in ltc294x_reset()
161 control |= LTC2942_REG_CONTROL_MODE_SCAN; in ltc294x_reset()
165 control |= LTC2943_REG_CONTROL_MODE_SCAN; in ltc294x_reset()
171 if (value != control) { in ltc294x_reset()
172 ret = ltc294x_write_regs(info->client, in ltc294x_reset()
173 LTC294X_REG_CONTROL, &control, 1); in ltc294x_reset()
187 ret = ltc294x_read_regs(info->client, reg, &datar[0], 2); in ltc294x_read_charge_register()
201 if (info->Qlsb < 0) in ltc294x_get_charge()
202 value -= 0xFFFF; in ltc294x_get_charge()
215 /* Direction depends on how sense+/- were connected */ in ltc294x_set_charge_now()
216 if (info->Qlsb < 0) in ltc294x_set_charge_now()
219 return -EINVAL; in ltc294x_set_charge_now()
221 /* Read control register */ in ltc294x_set_charge_now()
222 ret = ltc294x_read_regs(info->client, in ltc294x_set_charge_now()
228 ret = ltc294x_write_regs(info->client, in ltc294x_set_charge_now()
232 /* Set new charge value */ in ltc294x_set_charge_now()
235 ret = ltc294x_write_regs(info->client, in ltc294x_set_charge_now()
239 /* Enable analog section */ in ltc294x_set_charge_now()
242 ret = ltc294x_write_regs(info->client, in ltc294x_set_charge_now()
255 /* Direction depends on how sense+/- were connected */ in ltc294x_set_charge_thr()
256 if (info->Qlsb < 0) in ltc294x_set_charge_thr()
259 return -EINVAL; in ltc294x_set_charge_thr()
261 /* Set new charge value */ in ltc294x_set_charge_thr()
264 return ltc294x_write_regs(info->client, reg, &dataw[0], 2); in ltc294x_set_charge_thr()
274 value -= LTC294X_MID_SUPPLY; in ltc294x_get_charge_counter()
285 ret = ltc294x_read_regs(info->client, in ltc294x_get_voltage()
288 switch (info->id) { in ltc294x_get_voltage()
315 ret = ltc294x_read_regs(info->client, in ltc294x_get_current()
318 value -= 0x7FFF; in ltc294x_get_current()
319 if (info->id == LTC2944_ID) in ltc294x_get_current()
323 /* Value is in range -32k..+32k, r_sense is usually 10..50 mOhm, in ltc294x_get_current()
326 *val = 1000 * (value / (info->r_sense * 0x7FFF)); /* in uA */ in ltc294x_get_current()
337 if (info->id == LTC2942_ID) { in ltc294x_get_temperature()
339 value = 6000; /* Full-scale is 600 Kelvin */ in ltc294x_get_temperature()
342 value = 5100; /* Full-scale is 510 Kelvin */ in ltc294x_get_temperature()
344 ret = ltc294x_read_regs(info->client, reg, &datar[0], 2); in ltc294x_get_temperature()
347 *val = value / 0xFFFF - 2722; in ltc294x_get_temperature()
360 &val->intval); in ltc294x_get_property()
363 &val->intval); in ltc294x_get_property()
366 &val->intval); in ltc294x_get_property()
368 return ltc294x_get_charge_counter(info, &val->intval); in ltc294x_get_property()
370 return ltc294x_get_voltage(info, &val->intval); in ltc294x_get_property()
372 return ltc294x_get_current(info, &val->intval); in ltc294x_get_property()
374 return ltc294x_get_temperature(info, &val->intval); in ltc294x_get_property()
376 return -EINVAL; in ltc294x_get_property()
389 LTC294X_REG_CHARGE_THR_HIGH_MSB, val->intval); in ltc294x_set_property()
392 LTC294X_REG_CHARGE_THR_LOW_MSB, val->intval); in ltc294x_set_property()
394 return ltc294x_set_charge_now(info, val->intval); in ltc294x_set_property()
396 return -EPERM; in ltc294x_set_property()
415 int charge = ltc294x_read_charge_register(info, LTC294X_REG_ACC_CHARGE_MSB); in ltc294x_update() local
417 if (charge != info->charge) { in ltc294x_update()
418 info->charge = charge; in ltc294x_update()
419 power_supply_changed(info->supply); in ltc294x_update()
429 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ); in ltc294x_work()
452 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL); in ltc294x_i2c_probe()
454 return -ENOMEM; in ltc294x_i2c_probe()
458 np = of_node_get(client->dev.of_node); in ltc294x_i2c_probe()
460 info->id = (enum ltc294x_id) (uintptr_t) of_device_get_match_data( in ltc294x_i2c_probe()
461 &client->dev); in ltc294x_i2c_probe()
462 info->supply_desc.name = np->name; in ltc294x_i2c_probe()
465 * instead of the sense-. This results in reversed measurements. */ in ltc294x_i2c_probe()
466 ret = of_property_read_u32(np, "lltc,resistor-sense", &r_sense); in ltc294x_i2c_probe()
468 return dev_err_probe(&client->dev, ret, in ltc294x_i2c_probe()
469 "Could not find lltc,resistor-sense in devicetree\n"); in ltc294x_i2c_probe()
470 info->r_sense = r_sense; in ltc294x_i2c_probe()
472 ret = of_property_read_u32(np, "lltc,prescaler-exponent", in ltc294x_i2c_probe()
475 dev_warn(&client->dev, in ltc294x_i2c_probe()
476 "lltc,prescaler-exponent not in devicetree\n"); in ltc294x_i2c_probe()
480 if (info->id == LTC2943_ID) { in ltc294x_i2c_probe()
483 info->Qlsb = ((340 * 50000) / r_sense) >> in ltc294x_i2c_probe()
484 (12 - 2*prescaler_exp); in ltc294x_i2c_probe()
488 info->Qlsb = ((85 * 50000) / r_sense) >> in ltc294x_i2c_probe()
489 (7 - prescaler_exp); in ltc294x_i2c_probe()
493 if (info->id == LTC2941_ID || info->id == LTC2942_ID) { in ltc294x_i2c_probe()
496 return dev_err_probe(&client->dev, ret, in ltc294x_i2c_probe()
499 info->id = LTC2941_ID; in ltc294x_i2c_probe()
501 info->id = LTC2942_ID; in ltc294x_i2c_probe()
504 info->client = client; in ltc294x_i2c_probe()
505 info->supply_desc.type = POWER_SUPPLY_TYPE_BATTERY; in ltc294x_i2c_probe()
506 info->supply_desc.properties = ltc294x_properties; in ltc294x_i2c_probe()
507 switch (info->id) { in ltc294x_i2c_probe()
510 info->supply_desc.num_properties = in ltc294x_i2c_probe()
514 info->supply_desc.num_properties = in ltc294x_i2c_probe()
515 ARRAY_SIZE(ltc294x_properties) - 1; in ltc294x_i2c_probe()
519 info->supply_desc.num_properties = in ltc294x_i2c_probe()
520 ARRAY_SIZE(ltc294x_properties) - 3; in ltc294x_i2c_probe()
523 info->supply_desc.get_property = ltc294x_get_property; in ltc294x_i2c_probe()
524 info->supply_desc.set_property = ltc294x_set_property; in ltc294x_i2c_probe()
525 info->supply_desc.property_is_writeable = ltc294x_property_is_writeable; in ltc294x_i2c_probe()
526 info->supply_desc.external_power_changed = NULL; in ltc294x_i2c_probe()
530 ret = devm_delayed_work_autocancel(&client->dev, &info->work, in ltc294x_i2c_probe()
537 return dev_err_probe(&client->dev, ret, in ltc294x_i2c_probe()
540 info->supply = devm_power_supply_register(&client->dev, in ltc294x_i2c_probe()
541 &info->supply_desc, &psy_cfg); in ltc294x_i2c_probe()
542 if (IS_ERR(info->supply)) in ltc294x_i2c_probe()
543 return dev_err_probe(&client->dev, PTR_ERR(info->supply), in ltc294x_i2c_probe()
546 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ); in ltc294x_i2c_probe()
556 u8 control; in ltc294x_i2c_shutdown() local
559 if (info->id == LTC2941_ID) in ltc294x_i2c_shutdown()
562 /* Read control register */ in ltc294x_i2c_shutdown()
563 ret = ltc294x_read_regs(info->client, LTC294X_REG_CONTROL, &value, 1); in ltc294x_i2c_shutdown()
568 control = LTC294X_REG_CONTROL_ADC_DISABLE(value); in ltc294x_i2c_shutdown()
569 if (control != value) in ltc294x_i2c_shutdown()
570 ltc294x_write_regs(info->client, LTC294X_REG_CONTROL, in ltc294x_i2c_shutdown()
571 &control, 1); in ltc294x_i2c_shutdown()
581 cancel_delayed_work(&info->work); in ltc294x_suspend()
590 schedule_delayed_work(&info->work, LTC294X_WORK_DELAY * HZ); in ltc294x_resume()