Lines Matching +full:precharge +full:- +full:current
1 // SPDX-License-Identifier: GPL-2.0-only
86 /* over-temperature on PM8606 setting */
90 /* over-voltage protect on vchg setting mv */
113 "battery-monitor",
121 ret = pm860x_bulk_read(info->i2c, PM8607_VCHG_MEAS1, 2, buf); in measure_vchg()
129 dev_dbg(info->dev, "%s, vchg: %d mv\n", __func__, *data); in measure_vchg()
144 pm860x_reg_write(info->i2c, PM8607_VCHG_LOWTH, data); in set_vchg_threshold()
145 dev_dbg(info->dev, "VCHG_LOWTH:%dmv, 0x%x\n", min, data); in set_vchg_threshold()
151 pm860x_reg_write(info->i2c, PM8607_VCHG_HIGHTH, data); in set_vchg_threshold()
152 dev_dbg(info->dev, "VCHG_HIGHTH:%dmv, 0x%x\n", max, data); in set_vchg_threshold()
166 pm860x_reg_write(info->i2c, PM8607_VBAT_LOWTH, data); in set_vbatt_threshold()
167 dev_dbg(info->dev, "VBAT Min:%dmv, LOWTH:0x%x\n", min, data); in set_vbatt_threshold()
173 pm860x_reg_write(info->i2c, PM8607_VBAT_HIGHTH, data); in set_vbatt_threshold()
174 dev_dbg(info->dev, "VBAT Max:%dmv, HIGHTH:0x%x\n", max, data); in set_vbatt_threshold()
183 dev_dbg(info->dev, "Start Pre-charging!\n"); in start_precharge()
186 ret = pm860x_reg_write(info->i2c_8606, PM8606_PREREGULATORA, in start_precharge()
191 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, in start_precharge()
196 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL3, (0xf << 4), in start_precharge()
200 /* set precharge current, termination voltage, IBAT & TBAT monitor */ in start_precharge()
201 ret = pm860x_reg_write(info->i2c, PM8607_CHG_CTRL4, in start_precharge()
206 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL7, in start_precharge()
211 /* trigger precharge */ in start_precharge()
212 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, in start_precharge()
222 dev_dbg(info->dev, "Start Fast-charging!\n"); in start_fastcharge()
224 /* set fastcharge termination current & voltage, disable charging */ in start_fastcharge()
225 ret = pm860x_reg_write(info->i2c, PM8607_CHG_CTRL1, in start_fastcharge()
230 ret = pm860x_reg_write(info->i2c_8606, PM8606_PREREGULATORA, in start_fastcharge()
234 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL2, 0x1f, in start_fastcharge()
239 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL3, (0xf << 4), in start_fastcharge()
244 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL4, in start_fastcharge()
249 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL6, in start_fastcharge()
256 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL7, in start_fastcharge()
261 /* launch fast-charge */ in start_fastcharge()
262 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, in start_fastcharge()
272 dev_dbg(info->dev, "Stop charging!\n"); in stop_charge()
273 pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, CC1_MODE_OFF); in stop_charge()
274 if (vbatt > CHARGE_THRESHOLD && info->online) in stop_charge()
280 dev_dbg(info->dev, "Power-off notification!\n"); in power_off_notification()
287 unsigned char fsm_state[][16] = { "init", "discharge", "precharge", in set_charging_fsm()
295 return -EINVAL; in set_charging_fsm()
311 mutex_lock(&info->lock); in set_charging_fsm()
312 info->present = data.intval; in set_charging_fsm()
314 dev_dbg(info->dev, "Entering FSM:%s, Charger:%s, Battery:%s, " in set_charging_fsm()
316 &fsm_state[info->state][0], in set_charging_fsm()
317 (info->online) ? "online" : "N/A", in set_charging_fsm()
318 (info->present) ? "present" : "N/A", info->allowed); in set_charging_fsm()
319 dev_dbg(info->dev, "set_charging_fsm:vbatt:%d(mV)\n", vbatt); in set_charging_fsm()
321 switch (info->state) { in set_charging_fsm()
323 if (info->online && info->present && info->allowed) { in set_charging_fsm()
325 info->state = FSM_PRECHARGE; in set_charging_fsm()
328 info->state = FSM_DISCHARGE; in set_charging_fsm()
331 info->state = FSM_FASTCHARGE; in set_charging_fsm()
338 info->state = FSM_DISCHARGE; in set_charging_fsm()
344 if (info->online && info->present && info->allowed) { in set_charging_fsm()
346 info->state = FSM_FASTCHARGE; in set_charging_fsm()
350 info->state = FSM_DISCHARGE; in set_charging_fsm()
355 if (info->online && info->present && info->allowed) { in set_charging_fsm()
357 info->state = FSM_PRECHARGE; in set_charging_fsm()
361 info->state = FSM_DISCHARGE; in set_charging_fsm()
366 if (info->online && info->present && info->allowed) { in set_charging_fsm()
368 info->state = FSM_PRECHARGE; in set_charging_fsm()
371 info->state = FSM_FASTCHARGE; in set_charging_fsm()
377 else if (vbatt > CHARGE_THRESHOLD && info->online) in set_charging_fsm()
382 dev_warn(info->dev, "FSM meets wrong state:%d\n", in set_charging_fsm()
383 info->state); in set_charging_fsm()
386 dev_dbg(info->dev, in set_charging_fsm()
388 &fsm_state[info->state][0], in set_charging_fsm()
389 (info->online) ? "online" : "N/A", in set_charging_fsm()
390 (info->present) ? "present" : "N/A", info->allowed); in set_charging_fsm()
391 mutex_unlock(&info->lock); in set_charging_fsm()
401 mutex_lock(&info->lock); in pm860x_charger_handler()
402 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); in pm860x_charger_handler()
404 mutex_unlock(&info->lock); in pm860x_charger_handler()
408 info->online = 1; in pm860x_charger_handler()
409 info->allowed = 1; in pm860x_charger_handler()
411 info->online = 0; in pm860x_charger_handler()
412 info->allowed = 0; in pm860x_charger_handler()
414 mutex_unlock(&info->lock); in pm860x_charger_handler()
415 dev_dbg(info->dev, "%s, Charger:%s, Allowed:%d\n", __func__, in pm860x_charger_handler()
416 (info->online) ? "online" : "N/A", info->allowed); in pm860x_charger_handler()
420 power_supply_changed(info->usb); in pm860x_charger_handler()
441 mutex_lock(&info->lock); in pm860x_temp_handler()
442 /* Temperature < -10 C or >40 C, Will not allow charge */ in pm860x_temp_handler()
443 if (value < -10 || value > 40) in pm860x_temp_handler()
444 info->allowed = 0; in pm860x_temp_handler()
446 info->allowed = 1; in pm860x_temp_handler()
447 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed); in pm860x_temp_handler()
448 mutex_unlock(&info->lock); in pm860x_temp_handler()
460 mutex_lock(&info->lock); in pm860x_exception_handler()
461 info->allowed = 0; in pm860x_exception_handler()
462 mutex_unlock(&info->lock); in pm860x_exception_handler()
463 dev_dbg(info->dev, "%s, irq: %d\n", __func__, irq); in pm860x_exception_handler()
477 mutex_lock(&info->lock); in pm860x_done_handler()
478 /* pre-charge done, will transimit to fast-charge stage */ in pm860x_done_handler()
479 if (info->state == FSM_PRECHARGE) { in pm860x_done_handler()
480 info->allowed = 1; in pm860x_done_handler()
488 info->allowed = 0; in pm860x_done_handler()
499 * plug in/out usb, So we can not rely on info->online, we in pm860x_done_handler()
504 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); in pm860x_done_handler()
514 mutex_unlock(&info->lock); in pm860x_done_handler()
515 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed); in pm860x_done_handler()
525 mutex_lock(&info->lock); in pm860x_vbattery_handler()
529 if (info->present && info->online) in pm860x_vbattery_handler()
530 info->allowed = 1; in pm860x_vbattery_handler()
532 info->allowed = 0; in pm860x_vbattery_handler()
533 mutex_unlock(&info->lock); in pm860x_vbattery_handler()
534 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed); in pm860x_vbattery_handler()
546 if (info->present) in pm860x_vchg_handler()
551 mutex_lock(&info->lock); in pm860x_vchg_handler()
552 if (!info->online) { in pm860x_vchg_handler()
554 /* check if over-temp on pm8606 or not */ in pm860x_vchg_handler()
555 status = pm860x_reg_read(info->i2c_8606, PM8606_FLAGS); in pm860x_vchg_handler()
558 pm860x_set_bits(info->i2c_8606, PM8606_FLAGS, in pm860x_vchg_handler()
560 pm860x_set_bits(info->i2c_8606, in pm860x_vchg_handler()
564 dev_dbg(info->dev, in pm860x_vchg_handler()
565 "%s, pm8606 over-temp occurred\n", __func__); in pm860x_vchg_handler()
571 info->allowed = 0; in pm860x_vchg_handler()
572 dev_dbg(info->dev, in pm860x_vchg_handler()
573 "%s,pm8607 over-vchg occurred,vchg = %dmv\n", in pm860x_vchg_handler()
578 info->allowed = 1; in pm860x_vchg_handler()
579 dev_dbg(info->dev, in pm860x_vchg_handler()
580 "%s,pm8607 over-vchg recover,vchg = %dmv\n", in pm860x_vchg_handler()
583 mutex_unlock(&info->lock); in pm860x_vchg_handler()
585 dev_dbg(info->dev, "%s, Allowed: %d\n", __func__, info->allowed); in pm860x_vchg_handler()
599 if (info->state == FSM_FASTCHARGE || in pm860x_usb_get_prop()
600 info->state == FSM_PRECHARGE) in pm860x_usb_get_prop()
601 val->intval = POWER_SUPPLY_STATUS_CHARGING; in pm860x_usb_get_prop()
603 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in pm860x_usb_get_prop()
606 val->intval = info->online; in pm860x_usb_get_prop()
609 return -ENODEV; in pm860x_usb_get_prop()
623 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); in pm860x_init_charger()
627 mutex_lock(&info->lock); in pm860x_init_charger()
628 info->state = FSM_INIT; in pm860x_init_charger()
630 info->online = 1; in pm860x_init_charger()
631 info->allowed = 1; in pm860x_init_charger()
633 info->online = 0; in pm860x_init_charger()
634 info->allowed = 0; in pm860x_init_charger()
636 mutex_unlock(&info->lock); in pm860x_init_charger()
665 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); in pm860x_charger_probe()
673 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in pm860x_charger_probe()
675 return -ENOMEM; in pm860x_charger_probe()
677 count = pdev->num_resources; in pm860x_charger_probe()
679 info->irq[j] = platform_get_irq(pdev, i); in pm860x_charger_probe()
680 if (info->irq[j] < 0) in pm860x_charger_probe()
684 info->irq_nums = j; in pm860x_charger_probe()
686 info->chip = chip; in pm860x_charger_probe()
687 info->i2c = in pm860x_charger_probe()
688 (chip->id == CHIP_PM8607) ? chip->client : chip->companion; in pm860x_charger_probe()
689 info->i2c_8606 = in pm860x_charger_probe()
690 (chip->id == CHIP_PM8607) ? chip->companion : chip->client; in pm860x_charger_probe()
691 if (!info->i2c_8606) { in pm860x_charger_probe()
692 dev_err(&pdev->dev, "Missed I2C address of 88PM8606!\n"); in pm860x_charger_probe()
693 return -EINVAL; in pm860x_charger_probe()
695 info->dev = &pdev->dev; in pm860x_charger_probe()
700 mutex_init(&info->lock); in pm860x_charger_probe()
706 info->usb = devm_power_supply_register(&pdev->dev, &pm860x_charger_desc, in pm860x_charger_probe()
708 if (IS_ERR(info->usb)) { in pm860x_charger_probe()
709 return PTR_ERR(info->usb); in pm860x_charger_probe()
714 for (i = 0; i < ARRAY_SIZE(info->irq); i++) { in pm860x_charger_probe()
715 ret = devm_request_threaded_irq(&pdev->dev, info->irq[i], NULL, in pm860x_charger_probe()
720 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", in pm860x_charger_probe()
721 info->irq[i], ret); in pm860x_charger_probe()
730 .name = "88pm860x-charger",