Lines Matching +full:output +full:- +full:charge +full:- +full:current

1 // SPDX-License-Identifier: GPL-2.0+
27 * The Total Accumulated Charge registers store the total accumulated
28 * charge delivered from the VS source to a portable device. The total
88 /* Current Limit Register */
129 ret = regmap_read(info->regmap, UCS1002_REG_OTHER_STATUS, &reg); in ucs1002_get_online()
133 val->intval = !!(reg & F_CHG_ACT); in ucs1002_get_online()
144 * For Total Accumulated Charge Middle Low Byte register, addr in ucs1002_get_charge()
153 * For Total Accumulated Charge Low Byte register, addr 04h, in ucs1002_get_charge()
186 ret = regmap_bulk_read(info->regmap, UCS1002_REG_TOTAL_ACC_CHARGE, in ucs1002_get_charge()
192 val->intval = 0; in ucs1002_get_charge()
195 val->intval += bit_weights_uAh[i]; in ucs1002_get_charge()
204 * The Current Measurement register stores the measured in ucs1002_get_current()
205 * current value delivered to the portable device. The range in ucs1002_get_current()
215 ret = regmap_read(info->regmap, UCS1002_REG_CURRENT_MEASUREMENT, &reg); in ucs1002_get_current()
220 val->intval = 0; in ucs1002_get_current()
223 val->intval += bit_weights_uA[i]; in ucs1002_get_current()
229 * The Current Limit register stores the maximum current used by the
242 if (info->output_disable) { in ucs1002_get_max_current()
243 val->intval = 0; in ucs1002_get_max_current()
247 ret = regmap_read(info->regmap, UCS1002_REG_ILIMIT, &reg); in ucs1002_get_max_current()
251 val->intval = ucs1002_current_limit_uA[reg & UCS1002_ILIM_SW_MASK]; in ucs1002_get_max_current()
262 info->output_disable = true; in ucs1002_set_max_current()
263 regulator_disable_regmap(info->rdev); in ucs1002_set_max_current()
273 return -EINVAL; in ucs1002_set_max_current()
275 ret = regmap_write(info->regmap, UCS1002_REG_ILIMIT, idx); in ucs1002_set_max_current()
279 * Any current limit setting exceeding the one set via ILIM in ucs1002_set_max_current()
283 ret = regmap_read(info->regmap, UCS1002_REG_ILIMIT, &reg); in ucs1002_set_max_current()
288 return -EINVAL; in ucs1002_set_max_current()
290 info->output_disable = false; in ucs1002_set_max_current()
292 if (info->rdev && info->rdev->use_count && in ucs1002_set_max_current()
293 !regulator_is_enabled_regmap(info->rdev)) in ucs1002_set_max_current()
294 regulator_enable_regmap(info->rdev); in ucs1002_set_max_current()
312 return -EINVAL; in ucs1002_set_usb_type()
328 return -EINVAL; in ucs1002_set_usb_type()
331 return regmap_update_bits(info->regmap, UCS1002_REG_SWITCH_CFG, in ucs1002_set_usb_type()
342 ret = regmap_read(info->regmap, UCS1002_REG_PIN_STATUS, &reg); in ucs1002_get_usb_type()
364 val->intval = type; in ucs1002_get_usb_type()
387 return val->intval = info->health; in ucs1002_get_property()
389 val->intval = info->present; in ucs1002_get_property()
392 val->strval = UCS1002_MANUFACTURER; in ucs1002_get_property()
395 return -EINVAL; in ucs1002_get_property()
407 return ucs1002_set_max_current(info, val->intval); in ucs1002_set_property()
409 return ucs1002_set_usb_type(info, val->intval); in ucs1002_set_property()
411 return -EINVAL; in ucs1002_set_property()
446 ret = regmap_read(info->regmap, UCS1002_REG_INTERRUPT_STATUS, &reg); in ucs1002_health_poll()
451 if ((reg & F_ERR) && info->health != POWER_SUPPLY_HEALTH_GOOD) { in ucs1002_health_poll()
452 schedule_delayed_work(&info->health_poll, in ucs1002_health_poll()
458 info->health = POWER_SUPPLY_HEALTH_OVERHEAT; in ucs1002_health_poll()
460 info->health = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in ucs1002_health_poll()
462 info->health = POWER_SUPPLY_HEALTH_OVERCURRENT; in ucs1002_health_poll()
464 info->health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in ucs1002_health_poll()
466 info->health = POWER_SUPPLY_HEALTH_GOOD; in ucs1002_health_poll()
468 sysfs_notify(&info->charger->dev.kobj, NULL, "health"); in ucs1002_health_poll()
477 present = info->present; in ucs1002_charger_irq()
479 ret = regmap_read(info->regmap, UCS1002_REG_OTHER_STATUS, &regval); in ucs1002_charger_irq()
484 info->present = regval & F_ADET_PIN; in ucs1002_charger_irq()
487 if (present != info->present) in ucs1002_charger_irq()
488 power_supply_changed(info->charger); in ucs1002_charger_irq()
497 mod_delayed_work(system_wq, &info->health_poll, 0); in ucs1002_alert_irq()
507 * If the output is disabled due to 0 maximum current, just pretend the in ucs1002_regulator_enable()
509 * a non-zero maximum current budget. in ucs1002_regulator_enable()
511 if (info->output_disable) in ucs1002_regulator_enable()
524 .name = "ucs1002-vbus",
538 struct device *dev = &client->dev; in ucs1002_probe()
551 return -ENOMEM; in ucs1002_probe()
553 info->regmap = devm_regmap_init_i2c(client, &regmap_config); in ucs1002_probe()
554 ret = PTR_ERR_OR_ZERO(info->regmap); in ucs1002_probe()
560 info->client = client; in ucs1002_probe()
562 irq_a_det = of_irq_get_byname(dev->of_node, "a_det"); in ucs1002_probe()
563 irq_alert = of_irq_get_byname(dev->of_node, "alert"); in ucs1002_probe()
565 charger_config.of_node = dev->of_node; in ucs1002_probe()
568 ret = regmap_read(info->regmap, UCS1002_REG_PRODUCT_ID, &regval); in ucs1002_probe()
578 return -ENODEV; in ucs1002_probe()
581 /* Enable charge rationing by default */ in ucs1002_probe()
582 ret = regmap_update_bits(info->regmap, UCS1002_REG_GENERAL_CFG, in ucs1002_probe()
593 ret = regmap_update_bits(info->regmap, UCS1002_REG_SWITCH_CFG, in ucs1002_probe()
601 * Be safe and set initial current limit to 500mA in ucs1002_probe()
605 dev_err(dev, "Failed to set max current default: %d\n", ret); in ucs1002_probe()
609 info->charger = devm_power_supply_register(dev, &ucs1002_charger_desc, in ucs1002_probe()
611 ret = PTR_ERR_OR_ZERO(info->charger); in ucs1002_probe()
617 ret = regmap_read(info->regmap, UCS1002_REG_PIN_STATUS, &regval); in ucs1002_probe()
623 info->regulator_descriptor = in ucs1002_probe()
627 if (!info->regulator_descriptor) in ucs1002_probe()
628 return -ENOMEM; in ucs1002_probe()
630 info->regulator_descriptor->enable_is_inverted = !(regval & F_SEL_PIN); in ucs1002_probe()
633 regulator_config.of_node = dev->of_node; in ucs1002_probe()
634 regulator_config.regmap = info->regmap; in ucs1002_probe()
637 info->rdev = devm_regulator_register(dev, info->regulator_descriptor, in ucs1002_probe()
639 ret = PTR_ERR_OR_ZERO(info->rdev); in ucs1002_probe()
645 info->health = POWER_SUPPLY_HEALTH_GOOD; in ucs1002_probe()
646 INIT_DELAYED_WORK(&info->health_poll, ucs1002_health_poll); in ucs1002_probe()
652 "ucs1002-a_det", info); in ucs1002_probe()
662 0,"ucs1002-alert", info); in ucs1002_probe()