Lines Matching +full:pre +full:- +full:charge

1 // SPDX-License-Identifier: GPL-2.0
69 regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_stop_charge()
72 regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_stop_charge()
81 ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_start_charge()
87 return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_start_charge()
105 return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG5, in sc2731_charger_set_current_limit()
121 val = (cur - SC2731_CURRENT_PRECHG) / SC2731_CURRENT_STEP; in sc2731_charger_set_current()
123 /* Set pre-charge current as 450 mA */ in sc2731_charger_set_current()
124 ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_set_current()
130 return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG1, in sc2731_charger_set_current()
139 ret = regmap_read(info->regmap, SC2731_CHARGE_STATUS, &val); in sc2731_charger_get_status()
155 ret = regmap_read(info->regmap, info->base + SC2731_CHG_CFG1, &val); in sc2731_charger_get_current()
171 ret = regmap_read(info->regmap, info->base + SC2731_CHG_CFG5, &val); in sc2731_charger_get_current_limit()
195 return -EINVAL; in sc2731_charger_get_current_limit()
209 mutex_lock(&info->lock); in sc2731_charger_usb_set_property()
211 if (!info->charging) { in sc2731_charger_usb_set_property()
212 mutex_unlock(&info->lock); in sc2731_charger_usb_set_property()
213 return -ENODEV; in sc2731_charger_usb_set_property()
218 ret = sc2731_charger_set_current(info, val->intval / 1000); in sc2731_charger_usb_set_property()
220 dev_err(info->dev, "set charge current failed\n"); in sc2731_charger_usb_set_property()
225 val->intval / 1000); in sc2731_charger_usb_set_property()
227 dev_err(info->dev, "set input current limit failed\n"); in sc2731_charger_usb_set_property()
231 ret = -EINVAL; in sc2731_charger_usb_set_property()
234 mutex_unlock(&info->lock); in sc2731_charger_usb_set_property()
246 mutex_lock(&info->lock); in sc2731_charger_usb_get_property()
250 if (info->charging) in sc2731_charger_usb_get_property()
251 val->intval = sc2731_charger_get_status(info); in sc2731_charger_usb_get_property()
253 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in sc2731_charger_usb_get_property()
257 if (!info->charging) { in sc2731_charger_usb_get_property()
258 val->intval = 0; in sc2731_charger_usb_get_property()
264 val->intval = cur * 1000; in sc2731_charger_usb_get_property()
269 if (!info->charging) { in sc2731_charger_usb_get_property()
270 val->intval = 0; in sc2731_charger_usb_get_property()
276 val->intval = cur * 1000; in sc2731_charger_usb_get_property()
281 ret = -EINVAL; in sc2731_charger_usb_get_property()
285 mutex_unlock(&info->lock); in sc2731_charger_usb_get_property()
329 mutex_lock(&info->lock); in sc2731_charger_work()
331 if (info->limit > 0 && !info->charging) { in sc2731_charger_work()
332 /* set current limitation and start to charge */ in sc2731_charger_work()
333 ret = sc2731_charger_set_current_limit(info, info->limit); in sc2731_charger_work()
337 ret = sc2731_charger_set_current(info, info->limit); in sc2731_charger_work()
345 info->charging = true; in sc2731_charger_work()
346 } else if (!info->limit && info->charging) { in sc2731_charger_work()
348 info->charging = false; in sc2731_charger_work()
353 mutex_unlock(&info->lock); in sc2731_charger_work()
362 info->limit = limit; in sc2731_charger_usb_change()
364 schedule_work(&info->work); in sc2731_charger_usb_change()
376 ret = regmap_update_bits(info->regmap, SC2731_MODULE_EN1, in sc2731_charger_hw_init()
381 ret = power_supply_get_battery_info(info->psy_usb, &bat_info); in sc2731_charger_hw_init()
383 dev_warn(info->dev, "no battery information is supplied\n"); in sc2731_charger_hw_init()
387 * default charge termination current to 120 mA, and default in sc2731_charger_hw_init()
388 * charge termination voltage to 4.35V. in sc2731_charger_hw_init()
393 term_currrent = bat_info->charge_term_current_ua / 1000; in sc2731_charger_hw_init()
400 cur_val = ((term_currrent - 90) / 25) + 1; in sc2731_charger_hw_init()
402 term_voltage = bat_info->constant_charge_voltage_max_uv / 1000; in sc2731_charger_hw_init()
408 vol_val = (term_voltage - 4200) / 100; in sc2731_charger_hw_init()
412 power_supply_put_battery_info(info->psy_usb, bat_info); in sc2731_charger_hw_init()
415 /* Set charge termination current */ in sc2731_charger_hw_init()
416 ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG2, in sc2731_charger_hw_init()
421 /* Set charge termination voltage */ in sc2731_charger_hw_init()
422 ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0, in sc2731_charger_hw_init()
433 regmap_update_bits(info->regmap, SC2731_MODULE_EN1, SC2731_CHARGE_EN, 0); in sc2731_charger_hw_init()
443 * registering the notifier, we should start to charge with getting in sc2731_charger_detect_status()
444 * the charge current. in sc2731_charger_detect_status()
446 if (info->usb_phy->chg_state != USB_CHARGER_PRESENT) in sc2731_charger_detect_status()
449 usb_phy_get_charger_current(info->usb_phy, &min, &max); in sc2731_charger_detect_status()
450 info->limit = min; in sc2731_charger_detect_status()
452 schedule_work(&info->work); in sc2731_charger_detect_status()
457 struct device_node *np = pdev->dev.of_node; in sc2731_charger_probe()
462 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in sc2731_charger_probe()
464 return -ENOMEM; in sc2731_charger_probe()
466 mutex_init(&info->lock); in sc2731_charger_probe()
467 info->dev = &pdev->dev; in sc2731_charger_probe()
468 INIT_WORK(&info->work, sc2731_charger_work); in sc2731_charger_probe()
470 info->regmap = dev_get_regmap(pdev->dev.parent, NULL); in sc2731_charger_probe()
471 if (!info->regmap) { in sc2731_charger_probe()
472 dev_err(&pdev->dev, "failed to get charger regmap\n"); in sc2731_charger_probe()
473 return -ENODEV; in sc2731_charger_probe()
476 ret = of_property_read_u32(np, "reg", &info->base); in sc2731_charger_probe()
478 dev_err(&pdev->dev, "failed to get register address\n"); in sc2731_charger_probe()
479 return -ENODEV; in sc2731_charger_probe()
484 info->psy_usb = devm_power_supply_register(&pdev->dev, in sc2731_charger_probe()
487 if (IS_ERR(info->psy_usb)) { in sc2731_charger_probe()
488 dev_err(&pdev->dev, "failed to register power supply\n"); in sc2731_charger_probe()
489 return PTR_ERR(info->psy_usb); in sc2731_charger_probe()
496 info->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "phys", 0); in sc2731_charger_probe()
497 if (IS_ERR(info->usb_phy)) { in sc2731_charger_probe()
498 dev_err(&pdev->dev, "failed to find USB phy\n"); in sc2731_charger_probe()
499 return PTR_ERR(info->usb_phy); in sc2731_charger_probe()
502 info->usb_notify.notifier_call = sc2731_charger_usb_change; in sc2731_charger_probe()
503 ret = usb_register_notifier(info->usb_phy, &info->usb_notify); in sc2731_charger_probe()
505 dev_err(&pdev->dev, "failed to register notifier: %d\n", ret); in sc2731_charger_probe()
518 usb_unregister_notifier(info->usb_phy, &info->usb_notify); in sc2731_charger_remove()
522 { .compatible = "sprd,sc2731-charger", },
529 .name = "sc2731-charger",