Lines Matching full:info
116 static int measure_vchg(struct pm860x_charger_info *info, int *data) in measure_vchg() argument
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()
134 static void set_vchg_threshold(struct pm860x_charger_info *info, in set_vchg_threshold() argument
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()
156 static void set_vbatt_threshold(struct pm860x_charger_info *info, in set_vbatt_threshold() argument
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()
179 static int start_precharge(struct pm860x_charger_info *info) in start_precharge() argument
183 dev_dbg(info->dev, "Start Pre-charging!\n"); in start_precharge()
184 set_vbatt_threshold(info, 0, 0); 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()
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()
212 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, in start_precharge()
218 static int start_fastcharge(struct pm860x_charger_info *info) in start_fastcharge() argument
222 dev_dbg(info->dev, "Start Fast-charging!\n"); 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()
262 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL1, 3, in start_fastcharge()
265 set_vchg_threshold(info, VCHG_NORMAL_LOW, VCHG_NORMAL_HIGH); in start_fastcharge()
270 static void stop_charge(struct pm860x_charger_info *info, int vbatt) in stop_charge() argument
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()
275 set_vbatt_threshold(info, CHARGE_THRESHOLD, 0); in stop_charge()
278 static void power_off_notification(struct pm860x_charger_info *info) in power_off_notification() argument
280 dev_dbg(info->dev, "Power-off notification!\n"); in power_off_notification()
283 static int set_charging_fsm(struct pm860x_charger_info *info) in set_charging_fsm() argument
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()
326 start_precharge(info); in set_charging_fsm()
328 info->state = FSM_DISCHARGE; in set_charging_fsm()
329 stop_charge(info, vbatt); in set_charging_fsm()
331 info->state = FSM_FASTCHARGE; in set_charging_fsm()
332 start_fastcharge(info); in set_charging_fsm()
336 power_off_notification(info); in set_charging_fsm()
338 info->state = FSM_DISCHARGE; in set_charging_fsm()
339 stop_charge(info, vbatt); 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()
347 start_fastcharge(info); in set_charging_fsm()
350 info->state = FSM_DISCHARGE; in set_charging_fsm()
351 stop_charge(info, vbatt); 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()
358 start_precharge(info); in set_charging_fsm()
361 info->state = FSM_DISCHARGE; in set_charging_fsm()
362 stop_charge(info, vbatt); 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()
369 start_precharge(info); in set_charging_fsm()
371 info->state = FSM_FASTCHARGE; in set_charging_fsm()
372 start_fastcharge(info); in set_charging_fsm()
376 power_off_notification(info); in set_charging_fsm()
377 else if (vbatt > CHARGE_THRESHOLD && info->online) in set_charging_fsm()
378 set_vbatt_threshold(info, CHARGE_THRESHOLD, 0); 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()
398 struct pm860x_charger_info *info = data; in pm860x_charger_handler() local
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()
418 set_charging_fsm(info); in pm860x_charger_handler()
420 power_supply_changed(info->usb); in pm860x_charger_handler()
428 struct pm860x_charger_info *info = data; in pm860x_temp_handler() local
441 mutex_lock(&info->lock); 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()
450 set_charging_fsm(info); in pm860x_temp_handler()
458 struct pm860x_charger_info *info = data; in pm860x_exception_handler() local
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()
465 set_charging_fsm(info); in pm860x_exception_handler()
471 struct pm860x_charger_info *info = data; in pm860x_done_handler() local
477 mutex_lock(&info->lock); 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()
516 set_charging_fsm(info); in pm860x_done_handler()
523 struct pm860x_charger_info *info = data; in pm860x_vbattery_handler() local
525 mutex_lock(&info->lock); in pm860x_vbattery_handler()
527 set_vbatt_threshold(info, 0, 0); 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()
536 set_charging_fsm(info); in pm860x_vbattery_handler()
543 struct pm860x_charger_info *info = data; in pm860x_vchg_handler() local
546 if (info->present) in pm860x_vchg_handler()
549 measure_vchg(info, &vchg); in pm860x_vchg_handler()
551 mutex_lock(&info->lock); in pm860x_vchg_handler()
552 if (!info->online) { 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()
570 set_vchg_threshold(info, VCHG_OVP_LOW, 0); in pm860x_vchg_handler()
571 info->allowed = 0; in pm860x_vchg_handler()
572 dev_dbg(info->dev, in pm860x_vchg_handler()
576 set_vchg_threshold(info, VCHG_NORMAL_LOW, in pm860x_vchg_handler()
578 info->allowed = 1; in pm860x_vchg_handler()
579 dev_dbg(info->dev, 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()
586 set_charging_fsm(info); in pm860x_vchg_handler()
595 struct pm860x_charger_info *info = power_supply_get_drvdata(psy); in pm860x_usb_get_prop() local
599 if (info->state == FSM_FASTCHARGE || in pm860x_usb_get_prop()
600 info->state == FSM_PRECHARGE) in pm860x_usb_get_prop()
606 val->intval = info->online; in pm860x_usb_get_prop()
619 static int pm860x_init_charger(struct pm860x_charger_info *info) in pm860x_init_charger() argument
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()
638 set_charging_fsm(info); in pm860x_init_charger()
667 struct pm860x_charger_info *info; in pm860x_charger_probe() local
673 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in pm860x_charger_probe()
674 if (!info) 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()
689 info->i2c_8606 = in pm860x_charger_probe()
691 if (!info->i2c_8606) { in pm860x_charger_probe()
695 info->dev = &pdev->dev; in pm860x_charger_probe()
698 set_vchg_threshold(info, VCHG_NORMAL_LOW, VCHG_OVP_LOW); in pm860x_charger_probe()
700 mutex_init(&info->lock); in pm860x_charger_probe()
701 platform_set_drvdata(pdev, info); in pm860x_charger_probe()
703 psy_cfg.drv_data = info; 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()
712 pm860x_init_charger(info); 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()
718 pm860x_irq_descs[i].name, info); in pm860x_charger_probe()
721 info->irq[i], ret); in pm860x_charger_probe()