Lines Matching +full:usb +full:- +full:charger
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2012
32 #include <linux/mfd/abx500/ab8500-bm.h>
38 /* End-of-charge criteria counter */
177 * struct abx500_charge_curr_maximization - Charger maximization parameters
178 * @original_iset: the non optimized/maximised charger current
182 * @condition_cnt: number of iterations needed before a new charger current
184 * @max_current: maximum charger current
185 * @wait_cnt: to avoid too fast current step down in case of charger
208 * struct abx500_chargalg - abx500 Charging algorithm device information
211 * @eoc_cnt: counter used to determine end-of_charge
219 * @chg_info: information about connected charger types
221 * @susp_status: current charger suspension status
223 * @curr_status: Current step status for over-current protection
230 * @chargalg_wd_work: work to kick the charger watchdog periodically
264 /*External charger prepare notifier*/
280 * abx500_chargalg_safety_timer_expired() - Expiration of the safety timer
283 * This function gets called when the safety timer for the charger
291 dev_err(di->dev, "Safety timer expired\n"); in abx500_chargalg_safety_timer_expired()
292 di->events.safety_timer_expired = true; in abx500_chargalg_safety_timer_expired()
295 queue_work(di->chargalg_wq, &di->chargalg_work); in abx500_chargalg_safety_timer_expired()
301 * abx500_chargalg_maintenance_timer_expired() - Expiration of
315 dev_dbg(di->dev, "Maintenance timer expired\n"); in abx500_chargalg_maintenance_timer_expired()
316 di->events.maintenance_timer_expired = true; in abx500_chargalg_maintenance_timer_expired()
319 queue_work(di->chargalg_wq, &di->chargalg_work); in abx500_chargalg_maintenance_timer_expired()
325 * abx500_chargalg_state_to() - Change charge state
333 dev_dbg(di->dev, in abx500_chargalg_state_to()
335 di->charge_state == state ? "NO" : "YES", in abx500_chargalg_state_to()
336 di->charge_state, in abx500_chargalg_state_to()
337 states[di->charge_state], in abx500_chargalg_state_to()
341 di->charge_state = state; in abx500_chargalg_state_to()
346 switch (di->charge_state) { in abx500_chargalg_check_charger_enable()
355 if (di->chg_info.charger_type & USB_CHG) { in abx500_chargalg_check_charger_enable()
356 return di->usb_chg->ops.check_enable(di->usb_chg, in abx500_chargalg_check_charger_enable()
357 di->bm->bat_type[di->bm->batt_id].normal_vol_lvl, in abx500_chargalg_check_charger_enable()
358 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); in abx500_chargalg_check_charger_enable()
359 } else if ((di->chg_info.charger_type & AC_CHG) && in abx500_chargalg_check_charger_enable()
360 !(di->ac_chg->external)) { in abx500_chargalg_check_charger_enable()
361 return di->ac_chg->ops.check_enable(di->ac_chg, in abx500_chargalg_check_charger_enable()
362 di->bm->bat_type[di->bm->batt_id].normal_vol_lvl, in abx500_chargalg_check_charger_enable()
363 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); in abx500_chargalg_check_charger_enable()
369 * abx500_chargalg_check_charger_connection() - Check charger connection change
372 * This function will check if there is a change in the charger connection
373 * and change charge state accordingly. AC has precedence over USB.
377 if (di->chg_info.conn_chg != di->chg_info.prev_conn_chg || in abx500_chargalg_check_charger_connection()
378 di->susp_status.suspended_change) { in abx500_chargalg_check_charger_connection()
380 * Charger state changed or suspension in abx500_chargalg_check_charger_connection()
383 if ((di->chg_info.conn_chg & AC_CHG) && in abx500_chargalg_check_charger_connection()
384 !di->susp_status.ac_suspended) { in abx500_chargalg_check_charger_connection()
385 dev_dbg(di->dev, "Charging source is AC\n"); in abx500_chargalg_check_charger_connection()
386 if (di->chg_info.charger_type != AC_CHG) { in abx500_chargalg_check_charger_connection()
387 di->chg_info.charger_type = AC_CHG; in abx500_chargalg_check_charger_connection()
390 } else if ((di->chg_info.conn_chg & USB_CHG) && in abx500_chargalg_check_charger_connection()
391 !di->susp_status.usb_suspended) { in abx500_chargalg_check_charger_connection()
392 dev_dbg(di->dev, "Charging source is USB\n"); in abx500_chargalg_check_charger_connection()
393 di->chg_info.charger_type = USB_CHG; in abx500_chargalg_check_charger_connection()
395 } else if (di->chg_info.conn_chg && in abx500_chargalg_check_charger_connection()
396 (di->susp_status.ac_suspended || in abx500_chargalg_check_charger_connection()
397 di->susp_status.usb_suspended)) { in abx500_chargalg_check_charger_connection()
398 dev_dbg(di->dev, "Charging is suspended\n"); in abx500_chargalg_check_charger_connection()
399 di->chg_info.charger_type = NO_CHG; in abx500_chargalg_check_charger_connection()
402 dev_dbg(di->dev, "Charging source is OFF\n"); in abx500_chargalg_check_charger_connection()
403 di->chg_info.charger_type = NO_CHG; in abx500_chargalg_check_charger_connection()
406 di->chg_info.prev_conn_chg = di->chg_info.conn_chg; in abx500_chargalg_check_charger_connection()
407 di->susp_status.suspended_change = false; in abx500_chargalg_check_charger_connection()
409 return di->chg_info.conn_chg; in abx500_chargalg_check_charger_connection()
413 * abx500_chargalg_check_current_step_status() - Check charging current
423 if (di->curr_status.curr_step_change) in abx500_chargalg_check_current_step_status()
425 di->curr_status.curr_step_change = false; in abx500_chargalg_check_current_step_status()
429 * abx500_chargalg_start_safety_timer() - Start charging safety timer
433 * There are different timers for AC and USB
437 /* Charger-dependent expiration time in hours*/ in abx500_chargalg_start_safety_timer()
440 switch (di->chg_info.charger_type) { in abx500_chargalg_start_safety_timer()
442 timer_expiration = di->bm->main_safety_tmr_h; in abx500_chargalg_start_safety_timer()
446 timer_expiration = di->bm->usb_safety_tmr_h; in abx500_chargalg_start_safety_timer()
450 dev_err(di->dev, "Unknown charger to charge from\n"); in abx500_chargalg_start_safety_timer()
454 di->events.safety_timer_expired = false; in abx500_chargalg_start_safety_timer()
455 hrtimer_set_expires_range(&di->safety_timer, in abx500_chargalg_start_safety_timer()
458 hrtimer_start_expires(&di->safety_timer, HRTIMER_MODE_REL); in abx500_chargalg_start_safety_timer()
462 * abx500_chargalg_stop_safety_timer() - Stop charging safety timer
469 if (hrtimer_try_to_cancel(&di->safety_timer) >= 0) in abx500_chargalg_stop_safety_timer()
470 di->events.safety_timer_expired = false; in abx500_chargalg_stop_safety_timer()
474 * abx500_chargalg_start_maintenance_timer() - Start charging maintenance timer
485 hrtimer_set_expires_range(&di->maintenance_timer, in abx500_chargalg_start_maintenance_timer()
488 di->events.maintenance_timer_expired = false; in abx500_chargalg_start_maintenance_timer()
489 hrtimer_start_expires(&di->maintenance_timer, HRTIMER_MODE_REL); in abx500_chargalg_start_maintenance_timer()
493 * abx500_chargalg_stop_maintenance_timer() - Stop maintenance timer
501 if (hrtimer_try_to_cancel(&di->maintenance_timer) >= 0) in abx500_chargalg_stop_maintenance_timer()
502 di->events.maintenance_timer_expired = false; in abx500_chargalg_stop_maintenance_timer()
506 * abx500_chargalg_kick_watchdog() - Kick charger watchdog
509 * The charger watchdog have to be kicked periodically whenever the charger is
514 /* Check if charger exists and kick watchdog if charging */ in abx500_chargalg_kick_watchdog()
515 if (di->ac_chg && di->ac_chg->ops.kick_wd && in abx500_chargalg_kick_watchdog()
516 di->chg_info.online_chg & AC_CHG) { in abx500_chargalg_kick_watchdog()
518 * If AB charger watchdog expired, pm2xxx charging in abx500_chargalg_kick_watchdog()
519 * gets disabled. To be safe, kick both AB charger watchdog in abx500_chargalg_kick_watchdog()
522 if (di->ac_chg->external && in abx500_chargalg_kick_watchdog()
523 di->usb_chg && di->usb_chg->ops.kick_wd) in abx500_chargalg_kick_watchdog()
524 di->usb_chg->ops.kick_wd(di->usb_chg); in abx500_chargalg_kick_watchdog()
526 return di->ac_chg->ops.kick_wd(di->ac_chg); in abx500_chargalg_kick_watchdog()
528 else if (di->usb_chg && di->usb_chg->ops.kick_wd && in abx500_chargalg_kick_watchdog()
529 di->chg_info.online_chg & USB_CHG) in abx500_chargalg_kick_watchdog()
530 return di->usb_chg->ops.kick_wd(di->usb_chg); in abx500_chargalg_kick_watchdog()
532 return -ENXIO; in abx500_chargalg_kick_watchdog()
536 * abx500_chargalg_ac_en() - Turn on/off the AC charger
538 * @enable: charger on/off
539 * @vset: requested charger output voltage
540 * @iset: requested charger output current
542 * The AC charger will be turned on/off with the requested charge voltage and
550 if (!di->ac_chg || !di->ac_chg->ops.enable) in abx500_chargalg_ac_en()
551 return -ENXIO; in abx500_chargalg_ac_en()
553 /* Select maximum of what both the charger and the battery supports */ in abx500_chargalg_ac_en()
554 if (di->ac_chg->max_out_volt) in abx500_chargalg_ac_en()
555 vset = min(vset, di->ac_chg->max_out_volt); in abx500_chargalg_ac_en()
556 if (di->ac_chg->max_out_curr) in abx500_chargalg_ac_en()
557 iset = min(iset, di->ac_chg->max_out_curr); in abx500_chargalg_ac_en()
559 di->chg_info.ac_iset = iset; in abx500_chargalg_ac_en()
560 di->chg_info.ac_vset = vset; in abx500_chargalg_ac_en()
562 /* Enable external charger */ in abx500_chargalg_ac_en()
563 if (enable && di->ac_chg->external && in abx500_chargalg_ac_en()
566 0, di->dev); in abx500_chargalg_ac_en()
570 return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset); in abx500_chargalg_ac_en()
574 * abx500_chargalg_usb_en() - Turn on/off the USB charger
576 * @enable: charger on/off
577 * @vset: requested charger output voltage
578 * @iset: requested charger output current
580 * The USB charger will be turned on/off with the requested charge voltage and
586 if (!di->usb_chg || !di->usb_chg->ops.enable) in abx500_chargalg_usb_en()
587 return -ENXIO; in abx500_chargalg_usb_en()
589 /* Select maximum of what both the charger and the battery supports */ in abx500_chargalg_usb_en()
590 if (di->usb_chg->max_out_volt) in abx500_chargalg_usb_en()
591 vset = min(vset, di->usb_chg->max_out_volt); in abx500_chargalg_usb_en()
592 if (di->usb_chg->max_out_curr) in abx500_chargalg_usb_en()
593 iset = min(iset, di->usb_chg->max_out_curr); in abx500_chargalg_usb_en()
595 di->chg_info.usb_iset = iset; in abx500_chargalg_usb_en()
596 di->chg_info.usb_vset = vset; in abx500_chargalg_usb_en()
598 return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset); in abx500_chargalg_usb_en()
602 * abx500_chargalg_update_chg_curr() - Update charger current
604 * @iset: requested charger output current
606 * The charger output current will be updated for the charger
612 /* Check if charger exists and update current if charging */ in abx500_chargalg_update_chg_curr()
613 if (di->ac_chg && di->ac_chg->ops.update_curr && in abx500_chargalg_update_chg_curr()
614 di->chg_info.charger_type & AC_CHG) { in abx500_chargalg_update_chg_curr()
616 * Select maximum of what both the charger in abx500_chargalg_update_chg_curr()
619 if (di->ac_chg->max_out_curr) in abx500_chargalg_update_chg_curr()
620 iset = min(iset, di->ac_chg->max_out_curr); in abx500_chargalg_update_chg_curr()
622 di->chg_info.ac_iset = iset; in abx500_chargalg_update_chg_curr()
624 return di->ac_chg->ops.update_curr(di->ac_chg, iset); in abx500_chargalg_update_chg_curr()
625 } else if (di->usb_chg && di->usb_chg->ops.update_curr && in abx500_chargalg_update_chg_curr()
626 di->chg_info.charger_type & USB_CHG) { in abx500_chargalg_update_chg_curr()
628 * Select maximum of what both the charger in abx500_chargalg_update_chg_curr()
631 if (di->usb_chg->max_out_curr) in abx500_chargalg_update_chg_curr()
632 iset = min(iset, di->usb_chg->max_out_curr); in abx500_chargalg_update_chg_curr()
634 di->chg_info.usb_iset = iset; in abx500_chargalg_update_chg_curr()
636 return di->usb_chg->ops.update_curr(di->usb_chg, iset); in abx500_chargalg_update_chg_curr()
639 return -ENXIO; in abx500_chargalg_update_chg_curr()
643 * abx500_chargalg_stop_charging() - Stop charging
656 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; in abx500_chargalg_stop_charging()
657 di->maintenance_chg = false; in abx500_chargalg_stop_charging()
658 cancel_delayed_work(&di->chargalg_wd_work); in abx500_chargalg_stop_charging()
659 power_supply_changed(di->chargalg_psy); in abx500_chargalg_stop_charging()
663 * abx500_chargalg_hold_charging() - Pauses charging
676 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; in abx500_chargalg_hold_charging()
677 di->maintenance_chg = false; in abx500_chargalg_hold_charging()
678 cancel_delayed_work(&di->chargalg_wd_work); in abx500_chargalg_hold_charging()
679 power_supply_changed(di->chargalg_psy); in abx500_chargalg_hold_charging()
683 * abx500_chargalg_start_charging() - Start the charger
685 * @vset: requested charger output voltage
686 * @iset: requested charger output current
688 * A charger will be enabled depending on the requested charger type that was
694 switch (di->chg_info.charger_type) { in abx500_chargalg_start_charging()
696 dev_dbg(di->dev, in abx500_chargalg_start_charging()
703 dev_dbg(di->dev, in abx500_chargalg_start_charging()
704 "USB parameters: Vset %d, Ich %d\n", vset, iset); in abx500_chargalg_start_charging()
710 dev_err(di->dev, "Unknown charger to charge from\n"); in abx500_chargalg_start_charging()
716 * abx500_chargalg_check_temp() - Check battery temperature ranges
724 if (di->batt_data.temp > (di->bm->temp_low + di->t_hyst_norm) && in abx500_chargalg_check_temp()
725 di->batt_data.temp < (di->bm->temp_high - di->t_hyst_norm)) { in abx500_chargalg_check_temp()
727 di->events.btemp_underover = false; in abx500_chargalg_check_temp()
728 di->events.btemp_lowhigh = false; in abx500_chargalg_check_temp()
729 di->t_hyst_norm = 0; in abx500_chargalg_check_temp()
730 di->t_hyst_lowhigh = 0; in abx500_chargalg_check_temp()
732 if (((di->batt_data.temp >= di->bm->temp_high) && in abx500_chargalg_check_temp()
733 (di->batt_data.temp < in abx500_chargalg_check_temp()
734 (di->bm->temp_over - di->t_hyst_lowhigh))) || in abx500_chargalg_check_temp()
735 ((di->batt_data.temp > in abx500_chargalg_check_temp()
736 (di->bm->temp_under + di->t_hyst_lowhigh)) && in abx500_chargalg_check_temp()
737 (di->batt_data.temp <= di->bm->temp_low))) { in abx500_chargalg_check_temp()
739 di->events.btemp_underover = false; in abx500_chargalg_check_temp()
740 di->events.btemp_lowhigh = true; in abx500_chargalg_check_temp()
741 di->t_hyst_norm = di->bm->temp_hysteresis; in abx500_chargalg_check_temp()
742 di->t_hyst_lowhigh = 0; in abx500_chargalg_check_temp()
743 } else if (di->batt_data.temp <= di->bm->temp_under || in abx500_chargalg_check_temp()
744 di->batt_data.temp >= di->bm->temp_over) { in abx500_chargalg_check_temp()
746 di->events.btemp_underover = true; in abx500_chargalg_check_temp()
747 di->events.btemp_lowhigh = false; in abx500_chargalg_check_temp()
748 di->t_hyst_norm = 0; in abx500_chargalg_check_temp()
749 di->t_hyst_lowhigh = di->bm->temp_hysteresis; in abx500_chargalg_check_temp()
752 dev_dbg(di->dev, "Within hysteresis limit temp: %d " in abx500_chargalg_check_temp()
754 di->batt_data.temp, di->t_hyst_lowhigh, in abx500_chargalg_check_temp()
755 di->t_hyst_norm); in abx500_chargalg_check_temp()
761 * abx500_chargalg_check_charger_voltage() - Check charger voltage
764 * Charger voltage is checked against maximum limit
768 if (di->chg_info.usb_volt > di->bm->chg_params->usb_volt_max) in abx500_chargalg_check_charger_voltage()
769 di->chg_info.usb_chg_ok = false; in abx500_chargalg_check_charger_voltage()
771 di->chg_info.usb_chg_ok = true; in abx500_chargalg_check_charger_voltage()
773 if (di->chg_info.ac_volt > di->bm->chg_params->ac_volt_max) in abx500_chargalg_check_charger_voltage()
774 di->chg_info.ac_chg_ok = false; in abx500_chargalg_check_charger_voltage()
776 di->chg_info.ac_chg_ok = true; in abx500_chargalg_check_charger_voltage()
781 * abx500_chargalg_end_of_charge() - Check if end-of-charge criteria is fulfilled
784 * End-of-charge criteria is fulfilled when the battery voltage is above a
790 if (di->charge_status == POWER_SUPPLY_STATUS_CHARGING && in abx500_chargalg_end_of_charge()
791 di->charge_state == STATE_NORMAL && in abx500_chargalg_end_of_charge()
792 !di->maintenance_chg && (di->batt_data.volt >= in abx500_chargalg_end_of_charge()
793 di->bm->bat_type[di->bm->batt_id].termination_vol || in abx500_chargalg_end_of_charge()
794 di->events.usb_cv_active || di->events.ac_cv_active) && in abx500_chargalg_end_of_charge()
795 di->batt_data.avg_curr < in abx500_chargalg_end_of_charge()
796 di->bm->bat_type[di->bm->batt_id].termination_curr && in abx500_chargalg_end_of_charge()
797 di->batt_data.avg_curr > 0) { in abx500_chargalg_end_of_charge()
798 if (++di->eoc_cnt >= EOC_COND_CNT) { in abx500_chargalg_end_of_charge()
799 di->eoc_cnt = 0; in abx500_chargalg_end_of_charge()
800 di->charge_status = POWER_SUPPLY_STATUS_FULL; in abx500_chargalg_end_of_charge()
801 di->maintenance_chg = true; in abx500_chargalg_end_of_charge()
802 dev_dbg(di->dev, "EOC reached!\n"); in abx500_chargalg_end_of_charge()
803 power_supply_changed(di->chargalg_psy); in abx500_chargalg_end_of_charge()
805 dev_dbg(di->dev, in abx500_chargalg_end_of_charge()
808 di->eoc_cnt, in abx500_chargalg_end_of_charge()
812 di->eoc_cnt = 0; in abx500_chargalg_end_of_charge()
818 di->ccm.original_iset = in init_maxim_chg_curr()
819 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl; in init_maxim_chg_curr()
820 di->ccm.current_iset = in init_maxim_chg_curr()
821 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl; in init_maxim_chg_curr()
822 di->ccm.test_delta_i = di->bm->maxi->charger_curr_step; in init_maxim_chg_curr()
823 di->ccm.max_current = di->bm->maxi->chg_curr; in init_maxim_chg_curr()
824 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; in init_maxim_chg_curr()
825 di->ccm.level = 0; in init_maxim_chg_curr()
829 * abx500_chargalg_chg_curr_maxim - increases the charger current to
833 * This maximization function is used to raise the charger current to get the
841 if (!di->bm->maxi->ena_maxi) in abx500_chargalg_chg_curr_maxim()
844 delta_i = di->ccm.original_iset - di->batt_data.inst_curr; in abx500_chargalg_chg_curr_maxim()
846 if (di->events.vbus_collapsed) { in abx500_chargalg_chg_curr_maxim()
847 dev_dbg(di->dev, "Charger voltage has collapsed %d\n", in abx500_chargalg_chg_curr_maxim()
848 di->ccm.wait_cnt); in abx500_chargalg_chg_curr_maxim()
849 if (di->ccm.wait_cnt == 0) { in abx500_chargalg_chg_curr_maxim()
850 dev_dbg(di->dev, "lowering current\n"); in abx500_chargalg_chg_curr_maxim()
851 di->ccm.wait_cnt++; in abx500_chargalg_chg_curr_maxim()
852 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; in abx500_chargalg_chg_curr_maxim()
853 di->ccm.max_current = in abx500_chargalg_chg_curr_maxim()
854 di->ccm.current_iset - di->ccm.test_delta_i; in abx500_chargalg_chg_curr_maxim()
855 di->ccm.current_iset = di->ccm.max_current; in abx500_chargalg_chg_curr_maxim()
856 di->ccm.level--; in abx500_chargalg_chg_curr_maxim()
859 dev_dbg(di->dev, "waiting\n"); in abx500_chargalg_chg_curr_maxim()
861 di->ccm.wait_cnt = (di->ccm.wait_cnt + 1) % 3; in abx500_chargalg_chg_curr_maxim()
866 di->ccm.wait_cnt = 0; in abx500_chargalg_chg_curr_maxim()
868 if ((di->batt_data.inst_curr > di->ccm.original_iset)) { in abx500_chargalg_chg_curr_maxim()
869 dev_dbg(di->dev, " Maximization Ibat (%dmA) too high" in abx500_chargalg_chg_curr_maxim()
871 di->batt_data.inst_curr, di->ccm.original_iset, in abx500_chargalg_chg_curr_maxim()
872 di->ccm.current_iset); in abx500_chargalg_chg_curr_maxim()
874 if (di->ccm.current_iset == di->ccm.original_iset) in abx500_chargalg_chg_curr_maxim()
877 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; in abx500_chargalg_chg_curr_maxim()
878 di->ccm.current_iset = di->ccm.original_iset; in abx500_chargalg_chg_curr_maxim()
879 di->ccm.level = 0; in abx500_chargalg_chg_curr_maxim()
884 if (delta_i > di->ccm.test_delta_i && in abx500_chargalg_chg_curr_maxim()
885 (di->ccm.current_iset + di->ccm.test_delta_i) < in abx500_chargalg_chg_curr_maxim()
886 di->ccm.max_current) { in abx500_chargalg_chg_curr_maxim()
887 if (di->ccm.condition_cnt-- == 0) { in abx500_chargalg_chg_curr_maxim()
889 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; in abx500_chargalg_chg_curr_maxim()
890 di->ccm.current_iset += di->ccm.test_delta_i; in abx500_chargalg_chg_curr_maxim()
891 di->ccm.level++; in abx500_chargalg_chg_curr_maxim()
892 dev_dbg(di->dev, " Maximization needed, increase" in abx500_chargalg_chg_curr_maxim()
895 di->ccm.test_delta_i, in abx500_chargalg_chg_curr_maxim()
896 di->ccm.current_iset, in abx500_chargalg_chg_curr_maxim()
897 di->ccm.original_iset, in abx500_chargalg_chg_curr_maxim()
898 di->ccm.level); in abx500_chargalg_chg_curr_maxim()
904 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; in abx500_chargalg_chg_curr_maxim()
918 di->ccm.current_iset); in handle_maxim_chg_curr()
920 dev_err(di->dev, "failed to set chg curr\n"); in handle_maxim_chg_curr()
924 di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); in handle_maxim_chg_curr()
926 dev_err(di->dev, "failed to set chg curr\n"); in handle_maxim_chg_curr()
940 const char **supplicants = (const char **)ext->supplied_to; in abx500_chargalg_get_ext_psy_data()
949 j = match_string(supplicants, ext->num_supplicants, psy->desc->name); in abx500_chargalg_get_ext_psy_data()
959 di->batt_data.percent = ret.intval; in abx500_chargalg_get_ext_psy_data()
964 for (j = 0; j < ext->desc->num_properties; j++) { in abx500_chargalg_get_ext_psy_data()
966 prop = ext->desc->properties[j]; in abx500_chargalg_get_ext_psy_data()
971 if (!di->ac_chg && in abx500_chargalg_get_ext_psy_data()
972 ext->desc->type == POWER_SUPPLY_TYPE_MAINS) in abx500_chargalg_get_ext_psy_data()
973 di->ac_chg = psy_to_ux500_charger(ext); in abx500_chargalg_get_ext_psy_data()
974 else if (!di->usb_chg && in abx500_chargalg_get_ext_psy_data()
975 ext->desc->type == POWER_SUPPLY_TYPE_USB) in abx500_chargalg_get_ext_psy_data()
976 di->usb_chg = psy_to_ux500_charger(ext); in abx500_chargalg_get_ext_psy_data()
982 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
986 di->events.batt_rem = false; in abx500_chargalg_get_ext_psy_data()
989 di->events.batt_rem = true; in abx500_chargalg_get_ext_psy_data()
994 (di->chg_info.conn_chg & AC_CHG)) { in abx500_chargalg_get_ext_psy_data()
995 di->chg_info.prev_conn_chg = in abx500_chargalg_get_ext_psy_data()
996 di->chg_info.conn_chg; in abx500_chargalg_get_ext_psy_data()
997 di->chg_info.conn_chg &= ~AC_CHG; in abx500_chargalg_get_ext_psy_data()
1001 !(di->chg_info.conn_chg & AC_CHG)) { in abx500_chargalg_get_ext_psy_data()
1002 di->chg_info.prev_conn_chg = in abx500_chargalg_get_ext_psy_data()
1003 di->chg_info.conn_chg; in abx500_chargalg_get_ext_psy_data()
1004 di->chg_info.conn_chg |= AC_CHG; in abx500_chargalg_get_ext_psy_data()
1008 /* USB disconnected */ in abx500_chargalg_get_ext_psy_data()
1010 (di->chg_info.conn_chg & USB_CHG)) { in abx500_chargalg_get_ext_psy_data()
1011 di->chg_info.prev_conn_chg = in abx500_chargalg_get_ext_psy_data()
1012 di->chg_info.conn_chg; in abx500_chargalg_get_ext_psy_data()
1013 di->chg_info.conn_chg &= ~USB_CHG; in abx500_chargalg_get_ext_psy_data()
1015 /* USB connected */ in abx500_chargalg_get_ext_psy_data()
1017 !(di->chg_info.conn_chg & USB_CHG)) { in abx500_chargalg_get_ext_psy_data()
1018 di->chg_info.prev_conn_chg = in abx500_chargalg_get_ext_psy_data()
1019 di->chg_info.conn_chg; in abx500_chargalg_get_ext_psy_data()
1020 di->chg_info.conn_chg |= USB_CHG; in abx500_chargalg_get_ext_psy_data()
1029 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1035 (di->chg_info.online_chg & AC_CHG)) { in abx500_chargalg_get_ext_psy_data()
1036 di->chg_info.prev_online_chg = in abx500_chargalg_get_ext_psy_data()
1037 di->chg_info.online_chg; in abx500_chargalg_get_ext_psy_data()
1038 di->chg_info.online_chg &= ~AC_CHG; in abx500_chargalg_get_ext_psy_data()
1042 !(di->chg_info.online_chg & AC_CHG)) { in abx500_chargalg_get_ext_psy_data()
1043 di->chg_info.prev_online_chg = in abx500_chargalg_get_ext_psy_data()
1044 di->chg_info.online_chg; in abx500_chargalg_get_ext_psy_data()
1045 di->chg_info.online_chg |= AC_CHG; in abx500_chargalg_get_ext_psy_data()
1046 queue_delayed_work(di->chargalg_wq, in abx500_chargalg_get_ext_psy_data()
1047 &di->chargalg_wd_work, 0); in abx500_chargalg_get_ext_psy_data()
1051 /* USB offline */ in abx500_chargalg_get_ext_psy_data()
1053 (di->chg_info.online_chg & USB_CHG)) { in abx500_chargalg_get_ext_psy_data()
1054 di->chg_info.prev_online_chg = in abx500_chargalg_get_ext_psy_data()
1055 di->chg_info.online_chg; in abx500_chargalg_get_ext_psy_data()
1056 di->chg_info.online_chg &= ~USB_CHG; in abx500_chargalg_get_ext_psy_data()
1058 /* USB online */ in abx500_chargalg_get_ext_psy_data()
1060 !(di->chg_info.online_chg & USB_CHG)) { in abx500_chargalg_get_ext_psy_data()
1061 di->chg_info.prev_online_chg = in abx500_chargalg_get_ext_psy_data()
1062 di->chg_info.online_chg; in abx500_chargalg_get_ext_psy_data()
1063 di->chg_info.online_chg |= USB_CHG; in abx500_chargalg_get_ext_psy_data()
1064 queue_delayed_work(di->chargalg_wq, in abx500_chargalg_get_ext_psy_data()
1065 &di->chargalg_wd_work, 0); in abx500_chargalg_get_ext_psy_data()
1074 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1080 di->events.mainextchnotok = true; in abx500_chargalg_get_ext_psy_data()
1081 di->events.main_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1082 di->events.main_ovv = false; in abx500_chargalg_get_ext_psy_data()
1083 di->events.ac_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1086 di->events.ac_wd_expired = true; in abx500_chargalg_get_ext_psy_data()
1087 di->events.mainextchnotok = false; in abx500_chargalg_get_ext_psy_data()
1088 di->events.main_ovv = false; in abx500_chargalg_get_ext_psy_data()
1089 di->events.main_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1093 di->events.main_thermal_prot = true; in abx500_chargalg_get_ext_psy_data()
1094 di->events.mainextchnotok = false; in abx500_chargalg_get_ext_psy_data()
1095 di->events.main_ovv = false; in abx500_chargalg_get_ext_psy_data()
1096 di->events.ac_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1099 di->events.main_ovv = true; in abx500_chargalg_get_ext_psy_data()
1100 di->events.mainextchnotok = false; in abx500_chargalg_get_ext_psy_data()
1101 di->events.main_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1102 di->events.ac_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1105 di->events.main_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1106 di->events.mainextchnotok = false; in abx500_chargalg_get_ext_psy_data()
1107 di->events.main_ovv = false; in abx500_chargalg_get_ext_psy_data()
1108 di->events.ac_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1118 di->events.usbchargernotok = true; in abx500_chargalg_get_ext_psy_data()
1119 di->events.usb_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1120 di->events.vbus_ovv = false; in abx500_chargalg_get_ext_psy_data()
1121 di->events.usb_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1124 di->events.usb_wd_expired = true; in abx500_chargalg_get_ext_psy_data()
1125 di->events.usbchargernotok = false; in abx500_chargalg_get_ext_psy_data()
1126 di->events.usb_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1127 di->events.vbus_ovv = false; in abx500_chargalg_get_ext_psy_data()
1131 di->events.usb_thermal_prot = true; in abx500_chargalg_get_ext_psy_data()
1132 di->events.usbchargernotok = false; in abx500_chargalg_get_ext_psy_data()
1133 di->events.vbus_ovv = false; in abx500_chargalg_get_ext_psy_data()
1134 di->events.usb_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1137 di->events.vbus_ovv = true; in abx500_chargalg_get_ext_psy_data()
1138 di->events.usbchargernotok = false; in abx500_chargalg_get_ext_psy_data()
1139 di->events.usb_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1140 di->events.usb_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1143 di->events.usbchargernotok = false; in abx500_chargalg_get_ext_psy_data()
1144 di->events.usb_thermal_prot = false; in abx500_chargalg_get_ext_psy_data()
1145 di->events.vbus_ovv = false; in abx500_chargalg_get_ext_psy_data()
1146 di->events.usb_wd_expired = false; in abx500_chargalg_get_ext_psy_data()
1157 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1159 di->batt_data.volt = ret.intval / 1000; in abx500_chargalg_get_ext_psy_data()
1162 di->chg_info.ac_volt = ret.intval / 1000; in abx500_chargalg_get_ext_psy_data()
1165 di->chg_info.usb_volt = ret.intval / 1000; in abx500_chargalg_get_ext_psy_data()
1173 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1178 di->events.ac_cv_active = true; in abx500_chargalg_get_ext_psy_data()
1180 di->events.ac_cv_active = false; in abx500_chargalg_get_ext_psy_data()
1187 di->events.usb_cv_active = true; in abx500_chargalg_get_ext_psy_data()
1189 di->events.usb_cv_active = false; in abx500_chargalg_get_ext_psy_data()
1198 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1201 di->events.batt_unknown = false; in abx500_chargalg_get_ext_psy_data()
1203 di->events.batt_unknown = true; in abx500_chargalg_get_ext_psy_data()
1212 di->batt_data.temp = ret.intval / 10; in abx500_chargalg_get_ext_psy_data()
1216 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1218 di->chg_info.ac_curr = in abx500_chargalg_get_ext_psy_data()
1222 di->chg_info.usb_curr = in abx500_chargalg_get_ext_psy_data()
1226 di->batt_data.inst_curr = ret.intval / 1000; in abx500_chargalg_get_ext_psy_data()
1234 switch (ext->desc->type) { in abx500_chargalg_get_ext_psy_data()
1236 di->batt_data.avg_curr = ret.intval / 1000; in abx500_chargalg_get_ext_psy_data()
1240 di->events.vbus_collapsed = true; in abx500_chargalg_get_ext_psy_data()
1242 di->events.vbus_collapsed = false; in abx500_chargalg_get_ext_psy_data()
1250 di->batt_data.percent = ret.intval; in abx500_chargalg_get_ext_psy_data()
1260 * abx500_chargalg_external_power_changed() - callback for power supply changes
1276 queue_work(di->chargalg_wq, &di->chargalg_work); in abx500_chargalg_external_power_changed()
1280 * abx500_chargalg_algorithm() - Main function for the algorithm
1295 di->chargalg_psy, abx500_chargalg_get_ext_psy_data); in abx500_chargalg_algorithm()
1304 if (is_ab8500(di->parent)) { in abx500_chargalg_algorithm()
1307 dev_err(di->dev, "Checking charger is enabled error" in abx500_chargalg_algorithm()
1312 * First check if we have a charger connected. in abx500_chargalg_algorithm()
1317 (di->events.batt_unknown && !di->bm->chg_unknown_bat)) { in abx500_chargalg_algorithm()
1318 if (di->charge_state != STATE_HANDHELD) { in abx500_chargalg_algorithm()
1319 di->events.safety_timer_expired = false; in abx500_chargalg_algorithm()
1325 else if (di->charge_state == STATE_SUSPENDED_INIT || in abx500_chargalg_algorithm()
1326 di->charge_state == STATE_SUSPENDED) { in abx500_chargalg_algorithm()
1331 else if (di->events.safety_timer_expired) { in abx500_chargalg_algorithm()
1332 if (di->charge_state != STATE_SAFETY_TIMER_EXPIRED) in abx500_chargalg_algorithm()
1342 else if (di->events.batt_rem) { in abx500_chargalg_algorithm()
1343 if (di->charge_state != STATE_BATT_REMOVED) in abx500_chargalg_algorithm()
1346 /* Main or USB charger not ok. */ in abx500_chargalg_algorithm()
1347 else if (di->events.mainextchnotok || di->events.usbchargernotok) { in abx500_chargalg_algorithm()
1349 * If vbus_collapsed is set, we have to lower the charger in abx500_chargalg_algorithm()
1352 if (di->charge_state != STATE_CHG_NOT_OK && in abx500_chargalg_algorithm()
1353 !di->events.vbus_collapsed) in abx500_chargalg_algorithm()
1357 else if (di->events.vbus_ovv || in abx500_chargalg_algorithm()
1358 di->events.main_ovv || in abx500_chargalg_algorithm()
1359 di->events.batt_ovv || in abx500_chargalg_algorithm()
1360 !di->chg_info.usb_chg_ok || in abx500_chargalg_algorithm()
1361 !di->chg_info.ac_chg_ok) { in abx500_chargalg_algorithm()
1362 if (di->charge_state != STATE_OVV_PROTECT) in abx500_chargalg_algorithm()
1365 /* USB Thermal, stop charging */ in abx500_chargalg_algorithm()
1366 else if (di->events.main_thermal_prot || in abx500_chargalg_algorithm()
1367 di->events.usb_thermal_prot) { in abx500_chargalg_algorithm()
1368 if (di->charge_state != STATE_HW_TEMP_PROTECT) in abx500_chargalg_algorithm()
1373 else if (di->events.btemp_underover) { in abx500_chargalg_algorithm()
1374 if (di->charge_state != STATE_TEMP_UNDEROVER) in abx500_chargalg_algorithm()
1379 else if (di->events.ac_wd_expired || in abx500_chargalg_algorithm()
1380 di->events.usb_wd_expired) { in abx500_chargalg_algorithm()
1381 if (di->charge_state != STATE_WD_EXPIRED) in abx500_chargalg_algorithm()
1385 else if (di->events.btemp_lowhigh) { in abx500_chargalg_algorithm()
1386 if (di->charge_state != STATE_TEMP_LOWHIGH) in abx500_chargalg_algorithm()
1390 dev_dbg(di->dev, in abx500_chargalg_algorithm()
1392 "State %s Active_chg %d Chg_status %d AC %d USB %d " in abx500_chargalg_algorithm()
1395 di->batt_data.volt, in abx500_chargalg_algorithm()
1396 di->batt_data.avg_curr, in abx500_chargalg_algorithm()
1397 di->batt_data.inst_curr, in abx500_chargalg_algorithm()
1398 di->batt_data.temp, in abx500_chargalg_algorithm()
1399 di->batt_data.percent, in abx500_chargalg_algorithm()
1400 di->maintenance_chg, in abx500_chargalg_algorithm()
1401 states[di->charge_state], in abx500_chargalg_algorithm()
1402 di->chg_info.charger_type, in abx500_chargalg_algorithm()
1403 di->charge_status, in abx500_chargalg_algorithm()
1404 di->chg_info.conn_chg & AC_CHG, in abx500_chargalg_algorithm()
1405 di->chg_info.conn_chg & USB_CHG, in abx500_chargalg_algorithm()
1406 di->chg_info.online_chg & AC_CHG, in abx500_chargalg_algorithm()
1407 di->chg_info.online_chg & USB_CHG, in abx500_chargalg_algorithm()
1408 di->events.ac_cv_active, in abx500_chargalg_algorithm()
1409 di->events.usb_cv_active, in abx500_chargalg_algorithm()
1410 di->chg_info.ac_curr, in abx500_chargalg_algorithm()
1411 di->chg_info.usb_curr, in abx500_chargalg_algorithm()
1412 di->chg_info.ac_vset, in abx500_chargalg_algorithm()
1413 di->chg_info.ac_iset, in abx500_chargalg_algorithm()
1414 di->chg_info.usb_vset, in abx500_chargalg_algorithm()
1415 di->chg_info.usb_iset); in abx500_chargalg_algorithm()
1417 switch (di->charge_state) { in abx500_chargalg_algorithm()
1420 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; in abx500_chargalg_algorithm()
1428 if (di->susp_status.ac_suspended) in abx500_chargalg_algorithm()
1430 if (di->susp_status.usb_suspended) in abx500_chargalg_algorithm()
1434 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; in abx500_chargalg_algorithm()
1435 di->maintenance_chg = false; in abx500_chargalg_algorithm()
1437 power_supply_changed(di->chargalg_psy); in abx500_chargalg_algorithm()
1450 if (!di->events.batt_rem) in abx500_chargalg_algorithm()
1460 if (!di->events.main_thermal_prot && in abx500_chargalg_algorithm()
1461 !di->events.usb_thermal_prot) in abx500_chargalg_algorithm()
1471 if (!di->events.vbus_ovv && in abx500_chargalg_algorithm()
1472 !di->events.main_ovv && in abx500_chargalg_algorithm()
1473 !di->events.batt_ovv && in abx500_chargalg_algorithm()
1474 di->chg_info.usb_chg_ok && in abx500_chargalg_algorithm()
1475 di->chg_info.ac_chg_ok) in abx500_chargalg_algorithm()
1485 if (!di->events.mainextchnotok && in abx500_chargalg_algorithm()
1486 !di->events.usbchargernotok) in abx500_chargalg_algorithm()
1496 /* We exit this state when charger is removed */ in abx500_chargalg_algorithm()
1500 if (di->curr_status.curr_step == CHARGALG_CURR_STEP_LOW) in abx500_chargalg_algorithm()
1503 curr_step_lvl = di->bm->bat_type[ in abx500_chargalg_algorithm()
1504 di->bm->batt_id].normal_cur_lvl in abx500_chargalg_algorithm()
1505 * di->curr_status.curr_step in abx500_chargalg_algorithm()
1508 di->bm->bat_type[di->bm->batt_id] in abx500_chargalg_algorithm()
1516 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; in abx500_chargalg_algorithm()
1517 di->eoc_cnt = 0; in abx500_chargalg_algorithm()
1518 di->maintenance_chg = false; in abx500_chargalg_algorithm()
1519 power_supply_changed(di->chargalg_psy); in abx500_chargalg_algorithm()
1525 if (di->charge_status == POWER_SUPPLY_STATUS_FULL && in abx500_chargalg_algorithm()
1526 di->maintenance_chg) { in abx500_chargalg_algorithm()
1527 if (di->bm->no_maintenance) in abx500_chargalg_algorithm()
1543 if (di->batt_data.percent <= in abx500_chargalg_algorithm()
1544 di->bm->bat_type[di->bm->batt_id]. in abx500_chargalg_algorithm()
1552 di->bm->bat_type[ in abx500_chargalg_algorithm()
1553 di->bm->batt_id].maint_a_chg_timer_h); in abx500_chargalg_algorithm()
1555 di->bm->bat_type[ in abx500_chargalg_algorithm()
1556 di->bm->batt_id].maint_a_vol_lvl, in abx500_chargalg_algorithm()
1557 di->bm->bat_type[ in abx500_chargalg_algorithm()
1558 di->bm->batt_id].maint_a_cur_lvl); in abx500_chargalg_algorithm()
1560 power_supply_changed(di->chargalg_psy); in abx500_chargalg_algorithm()
1564 if (di->events.maintenance_timer_expired) { in abx500_chargalg_algorithm()
1572 di->bm->bat_type[ in abx500_chargalg_algorithm()
1573 di->bm->batt_id].maint_b_chg_timer_h); in abx500_chargalg_algorithm()
1575 di->bm->bat_type[ in abx500_chargalg_algorithm()
1576 di->bm->batt_id].maint_b_vol_lvl, in abx500_chargalg_algorithm()
1577 di->bm->bat_type[ in abx500_chargalg_algorithm()
1578 di->bm->batt_id].maint_b_cur_lvl); in abx500_chargalg_algorithm()
1580 power_supply_changed(di->chargalg_psy); in abx500_chargalg_algorithm()
1584 if (di->events.maintenance_timer_expired) { in abx500_chargalg_algorithm()
1592 di->bm->bat_type[ in abx500_chargalg_algorithm()
1593 di->bm->batt_id].low_high_vol_lvl, in abx500_chargalg_algorithm()
1594 di->bm->bat_type[ in abx500_chargalg_algorithm()
1595 di->bm->batt_id].low_high_cur_lvl); in abx500_chargalg_algorithm()
1597 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; in abx500_chargalg_algorithm()
1599 power_supply_changed(di->chargalg_psy); in abx500_chargalg_algorithm()
1603 if (!di->events.btemp_lowhigh) in abx500_chargalg_algorithm()
1613 if (!di->events.ac_wd_expired && in abx500_chargalg_algorithm()
1614 !di->events.usb_wd_expired) in abx500_chargalg_algorithm()
1624 if (!di->events.btemp_underover) in abx500_chargalg_algorithm()
1630 if (di->charge_state == STATE_NORMAL_INIT || in abx500_chargalg_algorithm()
1631 di->charge_state == STATE_MAINTENANCE_A_INIT || in abx500_chargalg_algorithm()
1632 di->charge_state == STATE_MAINTENANCE_B_INIT) in abx500_chargalg_algorithm()
1633 queue_work(di->chargalg_wq, &di->chargalg_work); in abx500_chargalg_algorithm()
1637 * abx500_chargalg_periodic_work() - Periodic work for the algorithm
1650 * If a charger is connected then the battery has to be monitored in abx500_chargalg_periodic_work()
1653 if (di->chg_info.conn_chg) in abx500_chargalg_periodic_work()
1654 queue_delayed_work(di->chargalg_wq, in abx500_chargalg_periodic_work()
1655 &di->chargalg_periodic_work, in abx500_chargalg_periodic_work()
1656 di->bm->interval_charging * HZ); in abx500_chargalg_periodic_work()
1658 queue_delayed_work(di->chargalg_wq, in abx500_chargalg_periodic_work()
1659 &di->chargalg_periodic_work, in abx500_chargalg_periodic_work()
1660 di->bm->interval_not_charging * HZ); in abx500_chargalg_periodic_work()
1664 * abx500_chargalg_wd_work() - periodic work to kick the charger watchdog
1667 * Work queue function for kicking the charger watchdog
1675 dev_dbg(di->dev, "abx500_chargalg_wd_work\n"); in abx500_chargalg_wd_work()
1679 dev_err(di->dev, "failed to kick watchdog\n"); in abx500_chargalg_wd_work()
1681 queue_delayed_work(di->chargalg_wq, in abx500_chargalg_wd_work()
1682 &di->chargalg_wd_work, CHG_WD_INTERVAL); in abx500_chargalg_wd_work()
1686 * abx500_chargalg_work() - Work to run the charging algorithm instantly
1700 * abx500_chargalg_get_property() - get the chargalg properties
1719 val->intval = di->charge_status; in abx500_chargalg_get_property()
1722 if (di->events.batt_ovv) { in abx500_chargalg_get_property()
1723 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in abx500_chargalg_get_property()
1724 } else if (di->events.btemp_underover) { in abx500_chargalg_get_property()
1725 if (di->batt_data.temp <= di->bm->temp_under) in abx500_chargalg_get_property()
1726 val->intval = POWER_SUPPLY_HEALTH_COLD; in abx500_chargalg_get_property()
1728 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in abx500_chargalg_get_property()
1729 } else if (di->charge_state == STATE_SAFETY_TIMER_EXPIRED || in abx500_chargalg_get_property()
1730 di->charge_state == STATE_SAFETY_TIMER_EXPIRED_INIT) { in abx500_chargalg_get_property()
1731 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in abx500_chargalg_get_property()
1733 val->intval = POWER_SUPPLY_HEALTH_GOOD; in abx500_chargalg_get_property()
1737 return -EINVAL; in abx500_chargalg_get_property()
1747 return sprintf(buf, "%d\n", di->curr_status.curr_step); in abx500_chargalg_curr_step_show()
1760 di->curr_status.curr_step = param; in abx500_chargalg_curr_step_store()
1761 if (di->curr_status.curr_step >= CHARGALG_CURR_STEP_LOW && in abx500_chargalg_curr_step_store()
1762 di->curr_status.curr_step <= CHARGALG_CURR_STEP_HIGH) { in abx500_chargalg_curr_step_store()
1763 di->curr_status.curr_step_change = true; in abx500_chargalg_curr_step_store()
1764 queue_work(di->chargalg_wq, &di->chargalg_work); in abx500_chargalg_curr_step_store()
1766 dev_info(di->dev, "Wrong current step\n" in abx500_chargalg_curr_step_store()
1767 "Enter 0. Disable AC/USB Charging\n" in abx500_chargalg_curr_step_store()
1768 "1--100. Set AC/USB charging current step\n" in abx500_chargalg_curr_step_store()
1769 "100. Enable AC/USB Charging\n"); in abx500_chargalg_curr_step_store()
1779 di->susp_status.ac_suspended && in abx500_chargalg_en_show()
1780 di->susp_status.usb_suspended); in abx500_chargalg_en_show()
1798 di->susp_status.ac_suspended = true; in abx500_chargalg_en_store()
1799 di->susp_status.usb_suspended = true; in abx500_chargalg_en_store()
1800 di->susp_status.suspended_change = true; in abx500_chargalg_en_store()
1802 queue_work(di->chargalg_wq, in abx500_chargalg_en_store()
1803 &di->chargalg_work); in abx500_chargalg_en_store()
1807 di->susp_status.ac_suspended = false; in abx500_chargalg_en_store()
1808 di->susp_status.suspended_change = true; in abx500_chargalg_en_store()
1810 queue_work(di->chargalg_wq, in abx500_chargalg_en_store()
1811 &di->chargalg_work); in abx500_chargalg_en_store()
1814 /* Enable USB charging */ in abx500_chargalg_en_store()
1815 di->susp_status.usb_suspended = false; in abx500_chargalg_en_store()
1816 di->susp_status.suspended_change = true; in abx500_chargalg_en_store()
1818 queue_work(di->chargalg_wq, in abx500_chargalg_en_store()
1819 &di->chargalg_work); in abx500_chargalg_en_store()
1822 dev_info(di->dev, "Wrong input\n" in abx500_chargalg_en_store()
1823 "Enter 0. Disable AC/USB Charging\n" in abx500_chargalg_en_store()
1825 "2. Enable USB Charging\n"); in abx500_chargalg_en_store()
1847 if (!entry->show) in abx500_chargalg_sysfs_show()
1848 return -EIO; in abx500_chargalg_sysfs_show()
1850 return entry->show(di, buf); in abx500_chargalg_sysfs_show()
1862 if (!entry->store) in abx500_chargalg_sysfs_charger()
1863 return -EIO; in abx500_chargalg_sysfs_charger()
1865 return entry->store(di, buf, length); in abx500_chargalg_sysfs_charger()
1885 * abx500_chargalg_sysfs_exit() - de-init of sysfs entry
1892 kobject_del(&di->chargalg_kobject); in abx500_chargalg_sysfs_exit()
1896 * abx500_chargalg_sysfs_init() - init of sysfs entry
1906 ret = kobject_init_and_add(&di->chargalg_kobject, in abx500_chargalg_sysfs_init()
1910 dev_err(di->dev, "failed to create sysfs entry\n"); in abx500_chargalg_sysfs_init()
1921 /* Kick charger watchdog if charging (any charger online) */ in abx500_chargalg_resume()
1922 if (di->chg_info.online_chg) in abx500_chargalg_resume()
1923 queue_delayed_work(di->chargalg_wq, &di->chargalg_wd_work, 0); in abx500_chargalg_resume()
1929 queue_delayed_work(di->chargalg_wq, &di->chargalg_periodic_work, 0); in abx500_chargalg_resume()
1939 if (di->chg_info.online_chg) in abx500_chargalg_suspend()
1940 cancel_delayed_work_sync(&di->chargalg_wd_work); in abx500_chargalg_suspend()
1942 cancel_delayed_work_sync(&di->chargalg_periodic_work); in abx500_chargalg_suspend()
1958 hrtimer_cancel(&di->safety_timer); in abx500_chargalg_remove()
1959 hrtimer_cancel(&di->maintenance_timer); in abx500_chargalg_remove()
1961 cancel_delayed_work_sync(&di->chargalg_periodic_work); in abx500_chargalg_remove()
1962 cancel_delayed_work_sync(&di->chargalg_wd_work); in abx500_chargalg_remove()
1963 cancel_work_sync(&di->chargalg_work); in abx500_chargalg_remove()
1966 destroy_workqueue(di->chargalg_wq); in abx500_chargalg_remove()
1968 power_supply_unregister(di->chargalg_psy); in abx500_chargalg_remove()
1988 struct device_node *np = pdev->dev.of_node; in abx500_chargalg_probe()
1989 struct abx500_bm_data *plat = pdev->dev.platform_data; in abx500_chargalg_probe()
1994 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); in abx500_chargalg_probe()
1996 dev_err(&pdev->dev, "%s no mem for ab8500_chargalg\n", __func__); in abx500_chargalg_probe()
1997 return -ENOMEM; in abx500_chargalg_probe()
2001 dev_err(&pdev->dev, "no battery management data supplied\n"); in abx500_chargalg_probe()
2002 return -EINVAL; in abx500_chargalg_probe()
2004 di->bm = plat; in abx500_chargalg_probe()
2007 ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm); in abx500_chargalg_probe()
2009 dev_err(&pdev->dev, "failed to get battery information\n"); in abx500_chargalg_probe()
2015 di->dev = &pdev->dev; in abx500_chargalg_probe()
2016 di->parent = dev_get_drvdata(pdev->dev.parent); in abx500_chargalg_probe()
2023 hrtimer_init(&di->safety_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); in abx500_chargalg_probe()
2024 di->safety_timer.function = abx500_chargalg_safety_timer_expired; in abx500_chargalg_probe()
2027 hrtimer_init(&di->maintenance_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); in abx500_chargalg_probe()
2028 di->maintenance_timer.function = in abx500_chargalg_probe()
2032 di->chargalg_wq = alloc_ordered_workqueue("abx500_chargalg_wq", in abx500_chargalg_probe()
2034 if (di->chargalg_wq == NULL) { in abx500_chargalg_probe()
2035 dev_err(di->dev, "failed to create work queue\n"); in abx500_chargalg_probe()
2036 return -ENOMEM; in abx500_chargalg_probe()
2040 INIT_DEFERRABLE_WORK(&di->chargalg_periodic_work, in abx500_chargalg_probe()
2042 INIT_DEFERRABLE_WORK(&di->chargalg_wd_work, in abx500_chargalg_probe()
2046 INIT_WORK(&di->chargalg_work, abx500_chargalg_work); in abx500_chargalg_probe()
2048 /* To detect charger at startup */ in abx500_chargalg_probe()
2049 di->chg_info.prev_conn_chg = -1; in abx500_chargalg_probe()
2052 di->chargalg_psy = power_supply_register(di->dev, &abx500_chargalg_desc, in abx500_chargalg_probe()
2054 if (IS_ERR(di->chargalg_psy)) { in abx500_chargalg_probe()
2055 dev_err(di->dev, "failed to register chargalg psy\n"); in abx500_chargalg_probe()
2056 ret = PTR_ERR(di->chargalg_psy); in abx500_chargalg_probe()
2065 dev_err(di->dev, "failed to create sysfs entry\n"); in abx500_chargalg_probe()
2068 di->curr_status.curr_step = CHARGALG_CURR_STEP_HIGH; in abx500_chargalg_probe()
2071 queue_delayed_work(di->chargalg_wq, &di->chargalg_periodic_work, 0); in abx500_chargalg_probe()
2073 dev_info(di->dev, "probe success\n"); in abx500_chargalg_probe()
2077 power_supply_unregister(di->chargalg_psy); in abx500_chargalg_probe()
2079 destroy_workqueue(di->chargalg_wq); in abx500_chargalg_probe()
2084 { .compatible = "stericsson,ab8500-chargalg", },
2094 .name = "ab8500-chargalg",
2103 MODULE_ALIAS("platform:abx500-chargalg");