Lines Matching +full:precharge +full:- +full:current
1 // SPDX-License-Identifier: GPL-2.0-or-later
70 PRECHARGE, enumerator
134 MP2629_PROPS(PRECHARGE, 120000, 720000, 40000),
143 [PRECHARGE] = REG_FIELD(MP2629_REG_PRECHARGE, 4, 7),
148 "mp2629-batt-volt",
149 "mp2629-system-volt",
150 "mp2629-input-volt",
151 "mp2629-batt-current",
152 "mp2629-input-current",
162 ret = iio_read_channel_processed(charger->iiochan[ch], &chval); in mp2629_read_adc()
166 val->intval = chval * 1000; in mp2629_read_adc()
178 ret = regmap_field_read(charger->regmap_fields[fld], &rval); in mp2629_get_prop()
182 val->intval = rval * props[fld].step + props[fld].min; in mp2629_get_prop()
193 if (val->intval < props[fld].min || val->intval > props[fld].max) in mp2629_set_prop()
194 return -EINVAL; in mp2629_set_prop()
196 rval = (val->intval - props[fld].min) / props[fld].step; in mp2629_set_prop()
197 return regmap_field_write(charger->regmap_fields[fld], rval); in mp2629_set_prop()
214 val->intval = (vnow.intval * 100) / vlim.intval; in mp2629_get_battery_capacity()
215 val->intval = min(val->intval, MP2629_MAX_BATT_CAPACITY); in mp2629_get_battery_capacity()
224 struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent); in mp2629_charger_battery_get_prop()
238 val->intval = 4520000; in mp2629_charger_battery_get_prop()
242 val->intval = 4670000; in mp2629_charger_battery_get_prop()
254 ret = mp2629_get_prop(charger, PRECHARGE, val); in mp2629_charger_battery_get_prop()
266 if (!charger->fault) in mp2629_charger_battery_get_prop()
267 val->intval = POWER_SUPPLY_HEALTH_GOOD; in mp2629_charger_battery_get_prop()
268 if (MP2629_FAULT_BATTERY & charger->fault) in mp2629_charger_battery_get_prop()
269 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in mp2629_charger_battery_get_prop()
270 else if (MP2629_FAULT_THERMAL & charger->fault) in mp2629_charger_battery_get_prop()
271 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in mp2629_charger_battery_get_prop()
272 else if (MP2629_FAULT_INPUT & charger->fault) in mp2629_charger_battery_get_prop()
273 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in mp2629_charger_battery_get_prop()
277 ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval); in mp2629_charger_battery_get_prop()
284 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in mp2629_charger_battery_get_prop()
288 val->intval = POWER_SUPPLY_STATUS_CHARGING; in mp2629_charger_battery_get_prop()
291 val->intval = POWER_SUPPLY_STATUS_FULL; in mp2629_charger_battery_get_prop()
296 ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval); in mp2629_charger_battery_get_prop()
303 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in mp2629_charger_battery_get_prop()
306 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; in mp2629_charger_battery_get_prop()
309 val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; in mp2629_charger_battery_get_prop()
312 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; in mp2629_charger_battery_get_prop()
317 return -EINVAL; in mp2629_charger_battery_get_prop()
327 struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent); in mp2629_charger_battery_set_prop()
334 return mp2629_set_prop(charger, PRECHARGE, val); in mp2629_charger_battery_set_prop()
343 return -EINVAL; in mp2629_charger_battery_set_prop()
351 struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent); in mp2629_charger_usb_get_prop()
357 ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval); in mp2629_charger_usb_get_prop()
361 val->intval = !!(rval & MP2629_MASK_INPUT_TYPE); in mp2629_charger_usb_get_prop()
365 ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval); in mp2629_charger_usb_get_prop()
372 val->intval = POWER_SUPPLY_USB_TYPE_SDP; in mp2629_charger_usb_get_prop()
375 val->intval = POWER_SUPPLY_USB_TYPE_CDP; in mp2629_charger_usb_get_prop()
378 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in mp2629_charger_usb_get_prop()
381 val->intval = POWER_SUPPLY_USB_TYPE_PD_DRP; in mp2629_charger_usb_get_prop()
384 val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; in mp2629_charger_usb_get_prop()
406 return -EINVAL; in mp2629_charger_usb_get_prop()
416 struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent); in mp2629_charger_usb_set_prop()
426 return -EINVAL; in mp2629_charger_usb_set_prop()
452 mutex_lock(&charger->lock); in mp2629_irq_handler()
454 ret = regmap_read(charger->regmap, MP2629_REG_FAULT, &rval); in mp2629_irq_handler()
459 charger->fault = rval; in mp2629_irq_handler()
461 dev_err(charger->dev, "Battery fault OVP\n"); in mp2629_irq_handler()
463 dev_err(charger->dev, "Thermal shutdown fault\n"); in mp2629_irq_handler()
465 dev_err(charger->dev, "no input or input OVP\n"); in mp2629_irq_handler()
467 dev_err(charger->dev, "VIN overloaded\n"); in mp2629_irq_handler()
472 ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval); in mp2629_irq_handler()
477 power_supply_changed(charger->usb); in mp2629_irq_handler()
479 power_supply_changed(charger->battery); in mp2629_irq_handler()
482 mutex_unlock(&charger->lock); in mp2629_irq_handler()
513 struct mp2629_charger *charger = dev_get_drvdata(dev->parent); in batt_impedance_compensation_show()
517 ret = regmap_read(charger->regmap, MP2629_REG_IMPEDANCE_COMP, &rval); in batt_impedance_compensation_show()
530 struct mp2629_charger *charger = dev_get_drvdata(dev->parent); in batt_impedance_compensation_store()
539 return -ERANGE; in batt_impedance_compensation_store()
543 ret = regmap_update_bits(charger->regmap, MP2629_REG_IMPEDANCE_COMP, in batt_impedance_compensation_store()
563 regmap_update_bits(charger->regmap, MP2629_REG_CHARGE_CTRL, in mp2629_charger_disable()
569 struct device *dev = &pdev->dev; in mp2629_charger_probe()
570 struct mp2629_data *ddata = dev_get_drvdata(dev->parent); in mp2629_charger_probe()
577 return -ENOMEM; in mp2629_charger_probe()
579 charger->regmap = ddata->regmap; in mp2629_charger_probe()
580 charger->dev = dev; in mp2629_charger_probe()
583 irq = platform_get_irq(to_platform_device(dev->parent), 0); in mp2629_charger_probe()
588 charger->regmap_fields[i] = devm_regmap_field_alloc(dev, in mp2629_charger_probe()
589 charger->regmap, mp2629_reg_fields[i]); in mp2629_charger_probe()
590 if (IS_ERR(charger->regmap_fields[i])) { in mp2629_charger_probe()
592 return PTR_ERR(charger->regmap_fields[i]); in mp2629_charger_probe()
597 charger->iiochan[i] = devm_iio_channel_get(dev, in mp2629_charger_probe()
599 if (IS_ERR(charger->iiochan[i])) { in mp2629_charger_probe()
601 return PTR_ERR(charger->iiochan[i]); in mp2629_charger_probe()
609 charger->usb = devm_power_supply_register(dev, &mp2629_usb_desc, NULL); in mp2629_charger_probe()
610 if (IS_ERR(charger->usb)) { in mp2629_charger_probe()
612 return PTR_ERR(charger->usb); in mp2629_charger_probe()
617 charger->battery = devm_power_supply_register(dev, in mp2629_charger_probe()
619 if (IS_ERR(charger->battery)) { in mp2629_charger_probe()
621 return PTR_ERR(charger->battery); in mp2629_charger_probe()
624 ret = regmap_update_bits(charger->regmap, MP2629_REG_CHARGE_CTRL, in mp2629_charger_probe()
631 regmap_update_bits(charger->regmap, MP2629_REG_TIMER_CTRL, in mp2629_charger_probe()
634 mutex_init(&charger->lock); in mp2629_charger_probe()
638 "mp2629-charger", charger); in mp2629_charger_probe()
644 regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT, in mp2629_charger_probe()