Lines Matching +full:charging +full:- +full:algorithm
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) ST-Ericsson SA 2012
36 #include "ab8500-bm.h"
37 #include "ab8500-chargalg.h"
94 /* Lowest charger voltage is 3.39V -> 0x4E */
112 /* UsbLineStatus register - usb types */
174 * struct ab8500_charger_interrupts - ab8500 interrupts
218 * struct ab8500_charger - ab8500 Charger device information
359 dev_dbg(di->dev, "SW Fallback: %d\n", fallback); in ab8500_enable_disable_sw_fallback()
361 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
372 ret = abx500_get_register_interruptible(di->dev, bank, reg, &val); in ab8500_enable_disable_sw_fallback()
374 dev_err(di->dev, "%d read failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
378 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
380 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x2); in ab8500_enable_disable_sw_fallback()
382 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
393 ret = abx500_set_register_interruptible(di->dev, bank, reg, val); in ab8500_enable_disable_sw_fallback()
395 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
399 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
401 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x0); in ab8500_enable_disable_sw_fallback()
403 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
409 * ab8500_power_supply_changed - a wrapper with local extensions for
421 * other type of charging. in ab8500_power_supply_changed()
426 if (di->autopower_cfg) { in ab8500_power_supply_changed()
427 if (!di->usb.charger_connected && in ab8500_power_supply_changed()
428 !di->ac.charger_connected && in ab8500_power_supply_changed()
429 di->autopower) { in ab8500_power_supply_changed()
430 di->autopower = false; in ab8500_power_supply_changed()
432 } else if (!di->autopower && in ab8500_power_supply_changed()
433 (di->ac.charger_connected || in ab8500_power_supply_changed()
434 di->usb.charger_connected)) { in ab8500_power_supply_changed()
435 di->autopower = true; in ab8500_power_supply_changed()
445 if (connected != di->usb.charger_connected) { in ab8500_charger_set_usb_connected()
446 dev_dbg(di->dev, "USB connected:%i\n", connected); in ab8500_charger_set_usb_connected()
447 di->usb.charger_connected = connected; in ab8500_charger_set_usb_connected()
450 di->flags.vbus_drop_end = false; in ab8500_charger_set_usb_connected()
454 * USB charging and no psy has been created, but we still in ab8500_charger_set_usb_connected()
457 if (di->usb_chg.psy) { in ab8500_charger_set_usb_connected()
458 sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, in ab8500_charger_set_usb_connected()
463 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
464 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
466 if (is_ab8500(di->parent)) in ab8500_charger_set_usb_connected()
467 queue_delayed_work(di->charger_wq, in ab8500_charger_set_usb_connected()
468 &di->usb_charger_attached_work, in ab8500_charger_set_usb_connected()
471 cancel_delayed_work_sync(&di->usb_charger_attached_work); in ab8500_charger_set_usb_connected()
472 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
473 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
479 * ab8500_charger_get_ac_voltage() - get ac charger voltage
489 if (di->ac.charger_connected) { in ab8500_charger_get_ac_voltage()
490 ret = iio_read_channel_processed(di->adc_main_charger_v, &vch); in ab8500_charger_get_ac_voltage()
492 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_ac_voltage()
501 * ab8500_charger_ac_cv() - check if the main charger is in CV mode
512 if (di->ac.charger_online) { in ab8500_charger_ac_cv()
513 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_cv()
516 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_ac_cv()
530 * ab8500_charger_get_vbus_voltage() - get vbus voltage
541 if (di->usb.charger_connected) { in ab8500_charger_get_vbus_voltage()
542 ret = iio_read_channel_processed(di->adc_vbus_v, &vch); in ab8500_charger_get_vbus_voltage()
544 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_vbus_voltage()
553 * ab8500_charger_get_usb_current() - get usb charger current
564 if (di->usb.charger_online) { in ab8500_charger_get_usb_current()
565 ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich); in ab8500_charger_get_usb_current()
567 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_usb_current()
576 * ab8500_charger_get_ac_current() - get ac charger current
587 if (di->ac.charger_online) { in ab8500_charger_get_ac_current()
588 ret = iio_read_channel_processed(di->adc_main_charger_c, &ich); in ab8500_charger_get_ac_current()
590 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_ac_current()
599 * ab8500_charger_usb_cv() - check if the usb charger is in CV mode
610 if (di->usb.charger_online) { in ab8500_charger_usb_cv()
611 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_cv()
614 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_usb_cv()
630 * ab8500_charger_detect_chargers() - Detect the connected chargers
653 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
656 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
674 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
677 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
680 dev_dbg(di->dev, in ab8500_charger_detect_chargers()
690 * ab8500_charger_max_usb_curr() - get the max curr for the USB type
703 di->usb_device_is_unrecognised = false; in ab8500_charger_max_usb_curr()
707 * This means that charging current from USB source in ab8500_charger_max_usb_curr()
716 dev_dbg(di->dev, "USB Type - Standard host is " in ab8500_charger_max_usb_curr()
718 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
719 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
722 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
723 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
726 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
727 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
730 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P9; in ab8500_charger_max_usb_curr()
731 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
738 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n"); in ab8500_charger_max_usb_curr()
739 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
740 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
747 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P3; in ab8500_charger_max_usb_curr()
748 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
749 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
750 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
753 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
754 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
757 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
758 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
762 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
763 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
766 if (di->vbus_detected) { in ab8500_charger_max_usb_curr()
767 di->usb_device_is_unrecognised = true; in ab8500_charger_max_usb_curr()
768 dev_dbg(di->dev, "USB Type - Legacy charger.\n"); in ab8500_charger_max_usb_curr()
769 di->max_usb_in_curr.usb_type_max_ua = in ab8500_charger_max_usb_curr()
775 dev_err(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
776 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
777 ret = -ENXIO; in ab8500_charger_max_usb_curr()
780 if (is_ab8500(di->parent)) { in ab8500_charger_max_usb_curr()
781 di->flags.vbus_collapse = true; in ab8500_charger_max_usb_curr()
782 dev_err(di->dev, "USB Type - USB_STAT_RESERVED " in ab8500_charger_max_usb_curr()
784 ret = -ENXIO; in ab8500_charger_max_usb_curr()
787 dev_dbg(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
788 di->max_usb_in_curr.usb_type_max_ua = in ab8500_charger_max_usb_curr()
790 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
792 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
793 ret = -ENXIO; in ab8500_charger_max_usb_curr()
800 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
801 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
802 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
805 dev_err(di->dev, "USB Type invalid - try charging anyway\n"); in ab8500_charger_max_usb_curr()
806 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
810 dev_err(di->dev, "USB Type - Unknown\n"); in ab8500_charger_max_usb_curr()
811 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
812 ret = -ENXIO; in ab8500_charger_max_usb_curr()
816 di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; in ab8500_charger_max_usb_curr()
817 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
818 link_status, di->max_usb_in_curr.set_max_ua); in ab8500_charger_max_usb_curr()
824 * ab8500_charger_read_usb_type() - read the type of usb connected
835 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
838 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_read_usb_type()
841 if (is_ab8500(di->parent)) in ab8500_charger_read_usb_type()
842 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_read_usb_type()
845 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
848 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_read_usb_type()
853 if (is_ab8500(di->parent)) in ab8500_charger_read_usb_type()
864 * ab8500_charger_detect_usb_type() - get the type of usb connected
882 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
885 dev_dbg(di->dev, "%s AB8500_IT_SOURCE21_REG %x\n", in ab8500_charger_detect_usb_type()
888 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
892 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
893 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
896 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
899 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
902 dev_dbg(di->dev, "%s AB8500_USB_LINE_STAT_REG %x\n", __func__, in ab8500_charger_detect_usb_type()
911 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
1021 return i - 1; in ab8500_voltage_to_regval()
1025 i = ARRAY_SIZE(ab8500_charger_voltage_map) - 1; in ab8500_voltage_to_regval()
1029 return -1; in ab8500_voltage_to_regval()
1053 return i - 1; in ab8500_current_to_regval()
1057 i = ARRAY_SIZE(ab8500_charge_output_curr_map) - 1; in ab8500_current_to_regval()
1061 return -1; in ab8500_current_to_regval()
1073 return i - 1; in ab8500_vbus_in_curr_to_regval()
1077 i = ARRAY_SIZE(ab8500_charge_input_curr_map) - 1; in ab8500_vbus_in_curr_to_regval()
1081 return -1; in ab8500_vbus_in_curr_to_regval()
1085 * ab8500_charger_get_usb_cur() - get usb current
1091 * to the register. Returns -1 if charging is not allowed
1096 switch (di->usb_state.usb_current_ua) { in ab8500_charger_get_usb_cur()
1098 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P09; in ab8500_charger_get_usb_cur()
1101 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P19; in ab8500_charger_get_usb_cur()
1104 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P29; in ab8500_charger_get_usb_cur()
1107 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P38; in ab8500_charger_get_usb_cur()
1110 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_get_usb_cur()
1113 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_get_usb_cur()
1114 ret = -EPERM; in ab8500_charger_get_usb_cur()
1117 di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; in ab8500_charger_get_usb_cur()
1122 * ab8500_charger_check_continue_stepping() - Check to allow stepping
1134 return !di->flags.vbus_drop_end; in ab8500_charger_check_continue_stepping()
1140 * ab8500_charger_set_current() - set charger current
1148 * charging is started. Instead we need to implement
1149 * this charger current step-up/down here.
1161 atomic_inc(&di->current_stepping_sessions); in ab8500_charger_set_current()
1163 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1166 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_set_current()
1176 if (!di->ac.charger_connected) in ab8500_charger_set_current()
1185 if (!di->usb.charger_connected) in ab8500_charger_set_current()
1193 if (curr_index && (curr_index - prev_curr_index) > 1) in ab8500_charger_set_current()
1196 if (!di->usb.charger_connected && !di->ac.charger_connected) in ab8500_charger_set_current()
1201 dev_err(di->dev, "%s current register not valid\n", __func__); in ab8500_charger_set_current()
1202 ret = -ENXIO; in ab8500_charger_set_current()
1207 dev_err(di->dev, "requested current limit out-of-range\n"); in ab8500_charger_set_current()
1208 ret = -ENXIO; in ab8500_charger_set_current()
1214 dev_dbg(di->dev, "%s current not changed for reg: 0x%02x\n", in ab8500_charger_set_current()
1220 dev_dbg(di->dev, "%s set charger current: %d uA for reg: 0x%02x\n", in ab8500_charger_set_current()
1224 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1227 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1229 for (i = prev_curr_index - 1; i >= curr_index; i--) { in ab8500_charger_set_current()
1230 dev_dbg(di->dev, "curr change_1 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1232 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1235 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1244 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1246 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1249 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1260 atomic_dec(&di->current_stepping_sessions); in ab8500_charger_set_current()
1266 * ab8500_charger_set_vbus_in_curr() - set VBUS input current limit
1280 min_value = min(di->bm->chg_params->usb_curr_max_ua, ich_in_ua); in ab8500_charger_set_vbus_in_curr()
1281 if (di->max_usb_in_curr.set_max_ua > 0) in ab8500_charger_set_vbus_in_curr()
1282 min_value = min(di->max_usb_in_curr.set_max_ua, min_value); in ab8500_charger_set_vbus_in_curr()
1284 if (di->usb_state.usb_current_ua >= 0) in ab8500_charger_set_vbus_in_curr()
1285 min_value = min(di->usb_state.usb_current_ua, min_value); in ab8500_charger_set_vbus_in_curr()
1289 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1293 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1300 dev_info(di->dev, "VBUS input current limit set to %d uA\n", min_value); in ab8500_charger_set_vbus_in_curr()
1302 mutex_lock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1305 mutex_unlock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1311 * ab8500_charger_set_main_in_curr() - set main charger input current
1326 * ab8500_charger_set_output_curr() - set charger output current
1341 * ab8500_charger_led_en() - turn on/off chargign led
1345 * Power ON/OFF charging LED indication
1353 /* Power ON charging LED indicator, set LED current to 5mA */ in ab8500_charger_led_en()
1354 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1358 dev_err(di->dev, "Power ON LED failed\n"); in ab8500_charger_led_en()
1362 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1366 dev_err(di->dev, "Set LED PWM duty cycle failed\n"); in ab8500_charger_led_en()
1370 /* Power off charging LED indicator */ in ab8500_charger_led_en()
1371 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1375 dev_err(di->dev, "Power-off LED failed\n"); in ab8500_charger_led_en()
1384 * ab8500_charger_ac_en() - enable or disable ac charging
1387 * @vset_uv: charging voltage in microvolt
1388 * @iset_ua: charging current in microampere
1390 * Enable/Disable AC/Mains charging and turns on/off the charging led
1406 if (!di->ac.charger_connected) { in ab8500_charger_ac_en()
1407 dev_err(di->dev, "AC charger not connected\n"); in ab8500_charger_ac_en()
1408 return -ENXIO; in ab8500_charger_ac_en()
1411 /* Enable AC charging */ in ab8500_charger_ac_en()
1412 dev_dbg(di->dev, "Enable AC: %duV %duA\n", vset_uv, iset_ua); in ab8500_charger_ac_en()
1417 * This will turn off charging for a short while. in ab8500_charger_ac_en()
1424 if (!di->vddadc_en_ac) { in ab8500_charger_ac_en()
1425 ret = regulator_enable(di->regu); in ab8500_charger_ac_en()
1427 dev_warn(di->dev, in ab8500_charger_ac_en()
1430 di->vddadc_en_ac = true; in ab8500_charger_ac_en()
1437 di->bm->chg_params->ac_curr_max_ua); in ab8500_charger_ac_en()
1439 dev_err(di->dev, in ab8500_charger_ac_en()
1441 "charging not started\n"); in ab8500_charger_ac_en()
1442 return -ENXIO; in ab8500_charger_ac_en()
1445 /* ChVoltLevel: maximum battery charging voltage */ in ab8500_charger_ac_en()
1446 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1449 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1454 di->bm->chg_params->ac_curr_max_ua); in ab8500_charger_ac_en()
1456 dev_err(di->dev, "%s Failed to set MainChInputCurr\n", in ab8500_charger_ac_en()
1463 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1470 if (!di->bm->enable_overshoot) in ab8500_charger_ac_en()
1474 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1477 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1481 /* Power on charging LED indication */ in ab8500_charger_ac_en()
1484 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_ac_en()
1486 di->ac.charger_online = 1; in ab8500_charger_ac_en()
1488 /* Disable AC charging */ in ab8500_charger_ac_en()
1489 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_ac_en()
1496 * by the algorithm and the watchdog have to be kicked in ab8500_charger_ac_en()
1500 if (di->ac_conn) { in ab8500_charger_ac_en()
1501 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_en()
1502 &di->kick_wd_work, in ab8500_charger_ac_en()
1507 * We can't turn off charging completely in ab8500_charger_ac_en()
1509 * If we do, charging will not start again. in ab8500_charger_ac_en()
1513 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1517 dev_err(di->dev, in ab8500_charger_ac_en()
1524 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1530 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1534 dev_err(di->dev, in ab8500_charger_ac_en()
1542 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_ac_en()
1544 di->ac.charger_online = 0; in ab8500_charger_ac_en()
1545 di->ac.wd_expired = false; in ab8500_charger_ac_en()
1548 if (di->vddadc_en_ac) { in ab8500_charger_ac_en()
1549 regulator_disable(di->regu); in ab8500_charger_ac_en()
1550 di->vddadc_en_ac = false; in ab8500_charger_ac_en()
1553 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__); in ab8500_charger_ac_en()
1555 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_en()
1561 * ab8500_charger_usb_en() - enable usb charging
1564 * @vset_uv: charging voltage in microvolt
1567 * Enable/Disable USB charging and turns on/off the charging led respectively.
1582 if (!di->usb.charger_connected) { in ab8500_charger_usb_en()
1583 dev_err(di->dev, "USB charger not connected\n"); in ab8500_charger_usb_en()
1584 return -ENXIO; in ab8500_charger_usb_en()
1590 * This will turn off charging for a short while. in ab8500_charger_usb_en()
1597 if (!di->vddadc_en_usb) { in ab8500_charger_usb_en()
1598 ret = regulator_enable(di->regu); in ab8500_charger_usb_en()
1600 dev_warn(di->dev, in ab8500_charger_usb_en()
1603 di->vddadc_en_usb = true; in ab8500_charger_usb_en()
1606 /* Enable USB charging */ in ab8500_charger_usb_en()
1607 dev_dbg(di->dev, "Enable USB: %d uV %d uA\n", vset_uv, ich_out_ua); in ab8500_charger_usb_en()
1613 dev_err(di->dev, in ab8500_charger_usb_en()
1615 "charging not started\n"); in ab8500_charger_usb_en()
1616 return -ENXIO; in ab8500_charger_usb_en()
1623 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1626 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1630 if (!di->bm->enable_overshoot) in ab8500_charger_usb_en()
1634 dev_dbg(di->dev, in ab8500_charger_usb_en()
1636 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1639 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1643 /* If success power on charging LED indication */ in ab8500_charger_usb_en()
1646 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_usb_en()
1648 di->usb.charger_online = 1; in ab8500_charger_usb_en()
1652 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_en()
1654 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1661 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1667 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ); in ab8500_charger_usb_en()
1670 /* Disable USB charging */ in ab8500_charger_usb_en()
1671 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1672 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_usb_en()
1676 dev_err(di->dev, in ab8500_charger_usb_en()
1683 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_usb_en()
1687 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1694 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1699 di->usb.charger_online = 0; in ab8500_charger_usb_en()
1700 di->usb.wd_expired = false; in ab8500_charger_usb_en()
1703 if (di->vddadc_en_usb) { in ab8500_charger_usb_en()
1704 regulator_disable(di->regu); in ab8500_charger_usb_en()
1705 di->vddadc_en_usb = false; in ab8500_charger_usb_en()
1708 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1711 cancel_delayed_work(&di->check_vbat_work); in ab8500_charger_usb_en()
1714 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_en()
1720 * ab8500_charger_usb_check_enable() - enable usb charging
1722 * @vset_uv: charging voltage in microvolt
1736 if (!di->usb.charger_connected) in ab8500_charger_usb_check_enable()
1739 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_check_enable()
1742 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1745 dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1); in ab8500_charger_usb_check_enable()
1748 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_usb_check_enable()
1750 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_check_enable()
1754 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1758 ret = ab8500_charger_usb_en(&di->usb_chg, true, vset_uv, iset_ua); in ab8500_charger_usb_check_enable()
1760 dev_err(di->dev, "Failed to enable VBUS charger %d\n", in ab8500_charger_usb_check_enable()
1769 * ab8500_charger_ac_check_enable() - enable usb charging
1771 * @vset_uv: charging voltage in microvolt
1785 if (!di->ac.charger_connected) in ab8500_charger_ac_check_enable()
1788 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_check_enable()
1791 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1794 dev_dbg(di->dev, "AC charger ctrl: 0x%02x\n", mainch_ctrl1); in ab8500_charger_ac_check_enable()
1797 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_ac_check_enable()
1799 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_ac_check_enable()
1804 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1808 ret = ab8500_charger_ac_en(&di->usb_chg, true, vset_uv, iset_ua); in ab8500_charger_ac_check_enable()
1810 dev_err(di->dev, "failed to enable AC charger %d\n", in ab8500_charger_ac_check_enable()
1819 * ab8500_charger_watchdog_kick() - kick charger watchdog
1830 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS) in ab8500_charger_watchdog_kick()
1832 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB) in ab8500_charger_watchdog_kick()
1835 return -ENXIO; in ab8500_charger_watchdog_kick()
1837 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_watchdog_kick()
1840 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_watchdog_kick()
1846 * ab8500_charger_update_charger_current() - update charger current
1859 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS) in ab8500_charger_update_charger_current()
1861 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB) in ab8500_charger_update_charger_current()
1864 return -ENXIO; in ab8500_charger_update_charger_current()
1868 dev_err(di->dev, "%s " in ab8500_charger_update_charger_current()
1875 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_update_charger_current()
1878 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_update_charger_current()
1889 const char **supplicants = (const char **)ext->supplied_to; in ab8500_charger_get_ext_psy_data()
1896 psy = usb_chg->psy; in ab8500_charger_get_ext_psy_data()
1905 j = match_string(supplicants, ext->num_supplicants, psy->desc->name); in ab8500_charger_get_ext_psy_data()
1910 for (j = 0; j < ext->desc->num_properties; j++) { in ab8500_charger_get_ext_psy_data()
1912 prop = ext->desc->properties[j]; in ab8500_charger_get_ext_psy_data()
1919 switch (ext->desc->type) { in ab8500_charger_get_ext_psy_data()
1922 dev_dbg(di->dev, "get VBAT from %s\n", in ab8500_charger_get_ext_psy_data()
1923 dev_name(&ext->dev)); in ab8500_charger_get_ext_psy_data()
1924 di->vbat = ret.intval; in ab8500_charger_get_ext_psy_data()
1938 * ab8500_charger_check_vbat_work() - keep vbus current within spec
1942 * charger when charging with at some specific levels. This issue is only valid
1953 &di->usb_chg, ab8500_charger_get_ext_psy_data); in ab8500_charger_check_vbat_work()
1956 if (di->old_vbat == 0) in ab8500_charger_check_vbat_work()
1957 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1959 if (!((di->old_vbat <= VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1960 di->vbat <= VBAT_TRESH_IP_CUR_RED) || in ab8500_charger_check_vbat_work()
1961 (di->old_vbat > VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1962 di->vbat > VBAT_TRESH_IP_CUR_RED))) { in ab8500_charger_check_vbat_work()
1964 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d," in ab8500_charger_check_vbat_work()
1965 " old: %d\n", di->max_usb_in_curr.usb_type_max_ua, in ab8500_charger_check_vbat_work()
1966 di->vbat, di->old_vbat); in ab8500_charger_check_vbat_work()
1968 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_check_vbat_work()
1969 power_supply_changed(di->usb_chg.psy); in ab8500_charger_check_vbat_work()
1972 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1978 if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100000) && in ab8500_charger_check_vbat_work()
1979 (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100000))) in ab8500_charger_check_vbat_work()
1982 queue_delayed_work(di->charger_wq, &di->check_vbat_work, t * HZ); in ab8500_charger_check_vbat_work()
1986 * ab8500_charger_check_hw_failure_work() - check main charger failure
2000 if (di->flags.mainextchnotok) { in ab8500_charger_check_hw_failure_work()
2001 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2004 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2008 di->flags.mainextchnotok = false; in ab8500_charger_check_hw_failure_work()
2009 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_hw_failure_work()
2012 if (di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2013 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2017 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2021 di->flags.vbus_ovv = false; in ab8500_charger_check_hw_failure_work()
2022 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_hw_failure_work()
2026 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2027 queue_delayed_work(di->charger_wq, in ab8500_charger_check_hw_failure_work()
2028 &di->check_hw_failure_work, round_jiffies(HZ)); in ab8500_charger_check_hw_failure_work()
2033 * ab8500_charger_kick_watchdog_work() - kick the watchdog
2042 * a bug that is not handled by the algorithm and the
2053 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_kick_watchdog_work()
2056 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_kick_watchdog_work()
2059 queue_delayed_work(di->charger_wq, in ab8500_charger_kick_watchdog_work()
2060 &di->kick_wd_work, round_jiffies(WD_KICK_INTERVAL)); in ab8500_charger_kick_watchdog_work()
2064 * ab8500_charger_ac_work() - work to get and set main charger status
2086 di->ac.charger_connected = 1; in ab8500_charger_ac_work()
2087 di->ac_conn = true; in ab8500_charger_ac_work()
2089 di->ac.charger_connected = 0; in ab8500_charger_ac_work()
2092 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_work()
2093 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_ac_work()
2106 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_attached_work()
2111 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_attached_work()
2120 ab8500_charger_usb_en(&di->usb_chg, 0, 0, 0); in ab8500_charger_usb_attached_work()
2122 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2123 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2128 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_attached_work()
2129 &di->usb_charger_attached_work, in ab8500_charger_usb_attached_work()
2145 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_ac_attached_work()
2150 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_attached_work()
2160 ab8500_charger_ac_en(&di->ac_chg, 0, 0, 0); in ab8500_charger_ac_attached_work()
2161 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_ac_attached_work()
2163 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2164 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2169 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_attached_work()
2170 &di->ac_charger_attached_work, in ab8500_charger_ac_attached_work()
2175 * ab8500_charger_detect_usb_type_work() - work to detect USB type
2197 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__); in ab8500_charger_detect_usb_type_work()
2198 di->vbus_detected = false; in ab8500_charger_detect_usb_type_work()
2200 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2202 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__); in ab8500_charger_detect_usb_type_work()
2203 di->vbus_detected = true; in ab8500_charger_detect_usb_type_work()
2205 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_detect_usb_type_work()
2210 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2220 if (di->vbus_detected_start) { in ab8500_charger_detect_usb_type_work()
2221 di->vbus_detected_start = false; in ab8500_charger_detect_usb_type_work()
2227 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2235 * ab8500_charger_usb_link_attach_work() - work to detect USB type
2247 if (!di->usb.charger_online) { in ab8500_charger_usb_link_attach_work()
2249 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_link_attach_work()
2255 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_attach_work()
2259 * ab8500_charger_usb_link_status_work() - work to detect USB type
2286 * to start the charging process. but by jumping in ab8500_charger_usb_link_status_work()
2289 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2290 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2293 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2297 dev_dbg(di->dev, "UsbLineStatus register = 0x%02x\n", val); in ab8500_charger_usb_link_status_work()
2299 dev_dbg(di->dev, "Error reading USB link status\n"); in ab8500_charger_usb_link_status_work()
2301 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2309 di->invalid_charger_detect_state == 0) { in ab8500_charger_usb_link_status_work()
2310 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2313 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2317 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2320 di->invalid_charger_detect_state = 1; in ab8500_charger_usb_link_status_work()
2325 if (di->invalid_charger_detect_state == 1) { in ab8500_charger_usb_link_status_work()
2326 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2329 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2333 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2334 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2338 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2342 dev_dbg(di->dev, "USB link status= 0x%02x\n", in ab8500_charger_usb_link_status_work()
2344 di->invalid_charger_detect_state = 2; in ab8500_charger_usb_link_status_work()
2347 di->invalid_charger_detect_state = 0; in ab8500_charger_usb_link_status_work()
2351 di->vbus_detected = false; in ab8500_charger_usb_link_status_work()
2353 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2357 dev_dbg(di->dev,"%s di->vbus_detected = true\n",__func__); in ab8500_charger_usb_link_status_work()
2358 di->vbus_detected = true; in ab8500_charger_usb_link_status_work()
2361 if (ret == -ENXIO) { in ab8500_charger_usb_link_status_work()
2364 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2369 if (di->usb_device_is_unrecognised) { in ab8500_charger_usb_link_status_work()
2370 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2375 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2376 &di->attach_work, in ab8500_charger_usb_link_status_work()
2378 } else if (di->is_aca_rid == 1) { in ab8500_charger_usb_link_status_work()
2380 di->is_aca_rid++; in ab8500_charger_usb_link_status_work()
2381 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2384 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2385 &di->attach_work, in ab8500_charger_usb_link_status_work()
2388 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2389 &di->attach_work, in ab8500_charger_usb_link_status_work()
2402 if (!di->vbus_detected) { in ab8500_charger_usb_state_changed_work()
2403 dev_dbg(di->dev, in ab8500_charger_usb_state_changed_work()
2404 "%s !di->vbus_detected\n", in ab8500_charger_usb_state_changed_work()
2409 spin_lock_irqsave(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2410 di->usb_state.state = di->usb_state.state_tmp; in ab8500_charger_usb_state_changed_work()
2411 di->usb_state.usb_current_ua = di->usb_state.usb_current_tmp_ua; in ab8500_charger_usb_state_changed_work()
2412 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2414 dev_dbg(di->dev, "%s USB state: 0x%02x uA: %d\n", in ab8500_charger_usb_state_changed_work()
2415 __func__, di->usb_state.state, di->usb_state.usb_current_ua); in ab8500_charger_usb_state_changed_work()
2417 switch (di->usb_state.state) { in ab8500_charger_usb_state_changed_work()
2423 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2428 * when suspend->resume there should be delay in ab8500_charger_usb_state_changed_work()
2429 * of 1sec for enabling charging in ab8500_charger_usb_state_changed_work()
2435 * USB is configured, enable charging with the charging in ab8500_charger_usb_state_changed_work()
2441 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_state_changed_work()
2446 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2456 * ab8500_charger_check_usbchargernotok_work() - check USB chg not ok status
2471 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usbchargernotok_work()
2474 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usbchargernotok_work()
2477 prev_status = di->flags.usbchargernotok; in ab8500_charger_check_usbchargernotok_work()
2480 di->flags.usbchargernotok = true; in ab8500_charger_check_usbchargernotok_work()
2482 queue_delayed_work(di->charger_wq, in ab8500_charger_check_usbchargernotok_work()
2483 &di->check_usbchgnotok_work, HZ); in ab8500_charger_check_usbchargernotok_work()
2485 di->flags.usbchargernotok = false; in ab8500_charger_check_usbchargernotok_work()
2486 di->flags.vbus_collapse = false; in ab8500_charger_check_usbchargernotok_work()
2489 if (prev_status != di->flags.usbchargernotok) in ab8500_charger_check_usbchargernotok_work()
2490 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usbchargernotok_work()
2494 * ab8500_charger_check_main_thermal_prot_work() - check main thermal status
2509 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_main_thermal_prot_work()
2512 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_main_thermal_prot_work()
2516 di->flags.main_thermal_prot = true; in ab8500_charger_check_main_thermal_prot_work()
2518 di->flags.main_thermal_prot = false; in ab8500_charger_check_main_thermal_prot_work()
2520 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_main_thermal_prot_work()
2524 * ab8500_charger_check_usb_thermal_prot_work() - check usb thermal status
2539 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usb_thermal_prot_work()
2542 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usb_thermal_prot_work()
2546 di->flags.usb_thermal_prot = true; in ab8500_charger_check_usb_thermal_prot_work()
2548 di->flags.usb_thermal_prot = false; in ab8500_charger_check_usb_thermal_prot_work()
2550 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usb_thermal_prot_work()
2554 * ab8500_charger_mainchunplugdet_handler() - main charger unplugged
2564 dev_dbg(di->dev, "Main charger unplugged\n"); in ab8500_charger_mainchunplugdet_handler()
2565 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchunplugdet_handler()
2567 cancel_delayed_work_sync(&di->ac_charger_attached_work); in ab8500_charger_mainchunplugdet_handler()
2568 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2569 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2575 * ab8500_charger_mainchplugdet_handler() - main charger plugged
2585 dev_dbg(di->dev, "Main charger plugged\n"); in ab8500_charger_mainchplugdet_handler()
2586 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchplugdet_handler()
2588 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2589 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2591 if (is_ab8500(di->parent)) in ab8500_charger_mainchplugdet_handler()
2592 queue_delayed_work(di->charger_wq, in ab8500_charger_mainchplugdet_handler()
2593 &di->ac_charger_attached_work, in ab8500_charger_mainchplugdet_handler()
2599 * ab8500_charger_mainextchnotok_handler() - main charger not ok
2609 dev_dbg(di->dev, "Main charger not ok\n"); in ab8500_charger_mainextchnotok_handler()
2610 di->flags.mainextchnotok = true; in ab8500_charger_mainextchnotok_handler()
2611 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_mainextchnotok_handler()
2614 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_mainextchnotok_handler()
2620 * ab8500_charger_mainchthprotr_handler() - Die temp is above main charger
2631 dev_dbg(di->dev, in ab8500_charger_mainchthprotr_handler()
2633 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotr_handler()
2639 * ab8500_charger_mainchthprotf_handler() - Die temp is below main charger
2650 dev_dbg(di->dev, in ab8500_charger_mainchthprotf_handler()
2652 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotf_handler()
2664 di->flags.vbus_drop_end = false; in ab8500_charger_vbus_drop_end_work()
2667 abx500_set_register_interruptible(di->dev, in ab8500_charger_vbus_drop_end_work()
2670 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_vbus_drop_end_work()
2673 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_vbus_drop_end_work()
2680 if (di->max_usb_in_curr.calculated_max_ua != curr_ua) { in ab8500_charger_vbus_drop_end_work()
2682 di->max_usb_in_curr.calculated_max_ua = curr_ua; in ab8500_charger_vbus_drop_end_work()
2683 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2685 di->max_usb_in_curr.calculated_max_ua); in ab8500_charger_vbus_drop_end_work()
2691 di->max_usb_in_curr.set_max_ua = in ab8500_charger_vbus_drop_end_work()
2692 di->max_usb_in_curr.calculated_max_ua; in ab8500_charger_vbus_drop_end_work()
2693 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2695 di->max_usb_in_curr.set_max_ua); in ab8500_charger_vbus_drop_end_work()
2698 if (di->usb.charger_connected) in ab8500_charger_vbus_drop_end_work()
2700 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_vbus_drop_end_work()
2704 * ab8500_charger_vbusdetf_handler() - VBUS falling detected
2714 di->vbus_detected = false; in ab8500_charger_vbusdetf_handler()
2715 dev_dbg(di->dev, "VBUS falling detected\n"); in ab8500_charger_vbusdetf_handler()
2716 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetf_handler()
2722 * ab8500_charger_vbusdetr_handler() - VBUS rising detected
2732 di->vbus_detected = true; in ab8500_charger_vbusdetr_handler()
2733 dev_dbg(di->dev, "VBUS rising detected\n"); in ab8500_charger_vbusdetr_handler()
2735 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetr_handler()
2741 * ab8500_charger_usblinkstatus_handler() - USB link status has changed
2751 dev_dbg(di->dev, "USB link status changed\n"); in ab8500_charger_usblinkstatus_handler()
2753 queue_work(di->charger_wq, &di->usb_link_status_work); in ab8500_charger_usblinkstatus_handler()
2759 * ab8500_charger_usbchthprotr_handler() - Die temp is above usb charger
2770 dev_dbg(di->dev, in ab8500_charger_usbchthprotr_handler()
2772 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotr_handler()
2778 * ab8500_charger_usbchthprotf_handler() - Die temp is below usb charger
2789 dev_dbg(di->dev, in ab8500_charger_usbchthprotf_handler()
2791 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotf_handler()
2797 * ab8500_charger_usbchargernotokr_handler() - USB charger not ok detected
2807 dev_dbg(di->dev, "Not allowed USB charger detected\n"); in ab8500_charger_usbchargernotokr_handler()
2808 queue_delayed_work(di->charger_wq, &di->check_usbchgnotok_work, 0); in ab8500_charger_usbchargernotokr_handler()
2814 * ab8500_charger_chwdexp_handler() - Charger watchdog expired
2824 dev_dbg(di->dev, "Charger watchdog expired\n"); in ab8500_charger_chwdexp_handler()
2828 * needs to be restarted for charging to start again in ab8500_charger_chwdexp_handler()
2830 if (di->ac.charger_online) { in ab8500_charger_chwdexp_handler()
2831 di->ac.wd_expired = true; in ab8500_charger_chwdexp_handler()
2832 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_chwdexp_handler()
2834 if (di->usb.charger_online) { in ab8500_charger_chwdexp_handler()
2835 di->usb.wd_expired = true; in ab8500_charger_chwdexp_handler()
2836 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_chwdexp_handler()
2843 * ab8500_charger_vbuschdropend_handler() - VBUS drop removed
2853 dev_dbg(di->dev, "VBUS charger drop ended\n"); in ab8500_charger_vbuschdropend_handler()
2854 di->flags.vbus_drop_end = true; in ab8500_charger_vbuschdropend_handler()
2860 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, in ab8500_charger_vbuschdropend_handler()
2867 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected
2877 dev_dbg(di->dev, "VBUS overvoltage detected\n"); in ab8500_charger_vbusovv_handler()
2878 di->flags.vbus_ovv = true; in ab8500_charger_vbusovv_handler()
2879 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_vbusovv_handler()
2882 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_vbusovv_handler()
2888 * ab8500_charger_ac_get_property() - get the ac/mains properties
2896 * online: ac/mains charging is in progress or not
2912 if (di->flags.mainextchnotok) in ab8500_charger_ac_get_property()
2913 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in ab8500_charger_ac_get_property()
2914 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_ac_get_property()
2915 val->intval = POWER_SUPPLY_HEALTH_DEAD; in ab8500_charger_ac_get_property()
2916 else if (di->flags.main_thermal_prot) in ab8500_charger_ac_get_property()
2917 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in ab8500_charger_ac_get_property()
2919 val->intval = POWER_SUPPLY_HEALTH_GOOD; in ab8500_charger_ac_get_property()
2922 val->intval = di->ac.charger_online; in ab8500_charger_ac_get_property()
2925 val->intval = di->ac.charger_connected; in ab8500_charger_ac_get_property()
2930 di->ac.charger_voltage_uv = ret; in ab8500_charger_ac_get_property()
2932 val->intval = di->ac.charger_voltage_uv; in ab8500_charger_ac_get_property()
2939 di->ac.cv_active = ab8500_charger_ac_cv(di); in ab8500_charger_ac_get_property()
2940 val->intval = di->ac.cv_active; in ab8500_charger_ac_get_property()
2945 di->ac.charger_current_ua = ret; in ab8500_charger_ac_get_property()
2946 val->intval = di->ac.charger_current_ua; in ab8500_charger_ac_get_property()
2949 return -EINVAL; in ab8500_charger_ac_get_property()
2955 * ab8500_charger_usb_get_property() - get the usb properties
2963 * online: usb charging is in progress or not
2979 if (di->flags.usbchargernotok) in ab8500_charger_usb_get_property()
2980 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in ab8500_charger_usb_get_property()
2981 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_usb_get_property()
2982 val->intval = POWER_SUPPLY_HEALTH_DEAD; in ab8500_charger_usb_get_property()
2983 else if (di->flags.usb_thermal_prot) in ab8500_charger_usb_get_property()
2984 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in ab8500_charger_usb_get_property()
2985 else if (di->flags.vbus_ovv) in ab8500_charger_usb_get_property()
2986 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in ab8500_charger_usb_get_property()
2988 val->intval = POWER_SUPPLY_HEALTH_GOOD; in ab8500_charger_usb_get_property()
2991 val->intval = di->usb.charger_online; in ab8500_charger_usb_get_property()
2994 val->intval = di->usb.charger_connected; in ab8500_charger_usb_get_property()
2999 di->usb.charger_voltage_uv = ret; in ab8500_charger_usb_get_property()
3000 val->intval = di->usb.charger_voltage_uv; in ab8500_charger_usb_get_property()
3007 di->usb.cv_active = ab8500_charger_usb_cv(di); in ab8500_charger_usb_get_property()
3008 val->intval = di->usb.cv_active; in ab8500_charger_usb_get_property()
3013 di->usb.charger_current_ua = ret; in ab8500_charger_usb_get_property()
3014 val->intval = di->usb.charger_current_ua; in ab8500_charger_usb_get_property()
3021 if (di->flags.vbus_collapse) in ab8500_charger_usb_get_property()
3022 val->intval = 1; in ab8500_charger_usb_get_property()
3024 val->intval = 0; in ab8500_charger_usb_get_property()
3027 return -EINVAL; in ab8500_charger_usb_get_property()
3033 * ab8500_charger_init_hw_registers() - Set up charger related registers
3037 * charging of the backup battery
3044 if (!is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_init_hw_registers()
3045 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3049 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3054 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3058 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3064 if (is_ab8505_2p0(di->parent)) in ab8500_charger_init_hw_registers()
3065 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3074 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3079 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3085 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3088 dev_err(di->dev, "failed to enable main WD in OTP\n"); in ab8500_charger_init_hw_registers()
3093 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3097 dev_err(di->dev, "failed to enable main watchdog\n"); in ab8500_charger_init_hw_registers()
3110 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3115 dev_err(di->dev, "failed to kick main watchdog\n"); in ab8500_charger_init_hw_registers()
3120 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3124 dev_err(di->dev, "failed to disable main watchdog\n"); in ab8500_charger_init_hw_registers()
3129 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_init_hw_registers()
3132 dev_err(di->dev, "failed to set charger watchdog timeout\n"); in ab8500_charger_init_hw_registers()
3138 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_init_hw_registers()
3142 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3145 (di->bm->bkup_bat_v & 0x3) | di->bm->bkup_bat_i); in ab8500_charger_init_hw_registers()
3147 dev_err(di->dev, "failed to setup backup battery charging\n"); in ab8500_charger_init_hw_registers()
3151 /* Enable backup battery charging */ in ab8500_charger_init_hw_registers()
3152 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3156 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_init_hw_registers()
3198 dev_dbg(di->dev, "not a standard host, returning\n"); in ab8500_charger_usb_notifier_call()
3205 if ((di->usb_state.usb_current_ua == 2000) && (mA > 2)) in ab8500_charger_usb_notifier_call()
3216 dev_dbg(di->dev, "%s usb_state: 0x%02x mA: %d\n", in ab8500_charger_usb_notifier_call()
3219 spin_lock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3220 di->usb_state.state_tmp = bm_usb_state; in ab8500_charger_usb_notifier_call()
3222 di->usb_state.usb_current_tmp_ua = mA * 1000; in ab8500_charger_usb_notifier_call()
3223 spin_unlock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3229 queue_delayed_work(di->charger_wq, &di->usb_state_changed_work, HZ/2); in ab8500_charger_usb_notifier_call()
3244 * a bug that is not handled by the algorithm and the in ab8500_charger_resume()
3248 if (di->ac_conn && is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_resume()
3249 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_resume()
3252 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_resume()
3255 queue_delayed_work(di->charger_wq, &di->kick_wd_work, in ab8500_charger_resume()
3260 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_resume()
3261 queue_delayed_work(di->charger_wq, in ab8500_charger_resume()
3262 &di->check_hw_failure_work, 0); in ab8500_charger_resume()
3265 if (di->flags.vbus_drop_end) in ab8500_charger_resume()
3266 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, 0); in ab8500_charger_resume()
3276 cancel_delayed_work(&di->check_hw_failure_work); in ab8500_charger_suspend()
3277 cancel_delayed_work(&di->vbus_drop_end_work); in ab8500_charger_suspend()
3279 flush_delayed_work(&di->attach_work); in ab8500_charger_suspend()
3280 flush_delayed_work(&di->usb_charger_attached_work); in ab8500_charger_suspend()
3281 flush_delayed_work(&di->ac_charger_attached_work); in ab8500_charger_suspend()
3282 flush_delayed_work(&di->check_usbchgnotok_work); in ab8500_charger_suspend()
3283 flush_delayed_work(&di->check_vbat_work); in ab8500_charger_suspend()
3284 flush_delayed_work(&di->kick_wd_work); in ab8500_charger_suspend()
3286 flush_work(&di->usb_link_status_work); in ab8500_charger_suspend()
3287 flush_work(&di->ac_work); in ab8500_charger_suspend()
3288 flush_work(&di->detect_usb_type_work); in ab8500_charger_suspend()
3290 if (atomic_read(&di->current_stepping_sessions)) in ab8500_charger_suspend()
3291 return -EAGAIN; in ab8500_charger_suspend()
3325 di->charger_wq = alloc_ordered_workqueue("ab8500_charger_wq", in ab8500_charger_bind()
3327 if (di->charger_wq == NULL) { in ab8500_charger_bind()
3329 return -ENOMEM; in ab8500_charger_bind()
3335 if (is_ab8500(di->parent)) in ab8500_charger_bind()
3336 queue_delayed_work(di->charger_wq, in ab8500_charger_bind()
3337 &di->ac_charger_attached_work, in ab8500_charger_bind()
3341 if (is_ab8500(di->parent)) in ab8500_charger_bind()
3342 queue_delayed_work(di->charger_wq, in ab8500_charger_bind()
3343 &di->usb_charger_attached_work, in ab8500_charger_bind()
3345 di->vbus_detected = true; in ab8500_charger_bind()
3346 di->vbus_detected_start = true; in ab8500_charger_bind()
3347 queue_work(di->charger_wq, in ab8500_charger_bind()
3348 &di->detect_usb_type_work); in ab8500_charger_bind()
3354 destroy_workqueue(di->charger_wq); in ab8500_charger_bind()
3366 /* Disable AC charging */ in ab8500_charger_unbind()
3367 ab8500_charger_ac_en(&di->ac_chg, false, 0, 0); in ab8500_charger_unbind()
3369 /* Disable USB charging */ in ab8500_charger_unbind()
3370 ab8500_charger_usb_en(&di->usb_chg, false, 0, 0); in ab8500_charger_unbind()
3373 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_unbind()
3376 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_unbind()
3379 destroy_workqueue(di->charger_wq); in ab8500_charger_unbind()
3381 /* Unbind fg, btemp, algorithm */ in ab8500_charger_unbind()
3398 struct device *dev = &pdev->dev; in ab8500_charger_probe()
3399 struct device_node *np = dev->of_node; in ab8500_charger_probe()
3409 return -ENOMEM; in ab8500_charger_probe()
3411 di->bm = &ab8500_bm_data; in ab8500_charger_probe()
3413 di->autopower_cfg = of_property_read_bool(np, "autopower_cfg"); in ab8500_charger_probe()
3416 di->dev = dev; in ab8500_charger_probe()
3417 di->parent = dev_get_drvdata(pdev->dev.parent); in ab8500_charger_probe()
3420 if (!is_ab8505(di->parent)) { in ab8500_charger_probe()
3421 di->adc_main_charger_v = devm_iio_channel_get(dev, "main_charger_v"); in ab8500_charger_probe()
3422 if (IS_ERR(di->adc_main_charger_v)) { in ab8500_charger_probe()
3423 ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_v), in ab8500_charger_probe()
3427 di->adc_main_charger_c = devm_iio_channel_get(dev, "main_charger_c"); in ab8500_charger_probe()
3428 if (IS_ERR(di->adc_main_charger_c)) { in ab8500_charger_probe()
3429 ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_c), in ab8500_charger_probe()
3434 di->adc_vbus_v = devm_iio_channel_get(dev, "vbus_v"); in ab8500_charger_probe()
3435 if (IS_ERR(di->adc_vbus_v)) { in ab8500_charger_probe()
3436 ret = dev_err_probe(dev, PTR_ERR(di->adc_vbus_v), in ab8500_charger_probe()
3440 di->adc_usb_charger_c = devm_iio_channel_get(dev, "usb_charger_c"); in ab8500_charger_probe()
3441 if (IS_ERR(di->adc_usb_charger_c)) { in ab8500_charger_probe()
3442 ret = dev_err_probe(dev, PTR_ERR(di->adc_usb_charger_c), in ab8500_charger_probe()
3450 * interrupts during charging in ab8500_charger_probe()
3452 di->regu = devm_regulator_get(dev, "vddadc"); in ab8500_charger_probe()
3453 if (IS_ERR(di->regu)) { in ab8500_charger_probe()
3454 ret = PTR_ERR(di->regu); in ab8500_charger_probe()
3480 spin_lock_init(&di->usb_state.usb_lock); in ab8500_charger_probe()
3481 mutex_init(&di->usb_ipt_crnt_lock); in ab8500_charger_probe()
3483 di->autopower = false; in ab8500_charger_probe()
3484 di->invalid_charger_detect_state = 0; in ab8500_charger_probe()
3490 ac_psy_cfg.drv_data = &di->ac_chg; in ab8500_charger_probe()
3494 usb_psy_cfg.drv_data = &di->usb_chg; in ab8500_charger_probe()
3497 /* ux500_charger sub-class */ in ab8500_charger_probe()
3498 di->ac_chg.ops.enable = &ab8500_charger_ac_en; in ab8500_charger_probe()
3499 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable; in ab8500_charger_probe()
3500 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3501 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3502 di->ac_chg.max_out_volt_uv = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3503 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; in ab8500_charger_probe()
3504 di->ac_chg.max_out_curr_ua = in ab8500_charger_probe()
3505 ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; in ab8500_charger_probe()
3506 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3508 * The AB8505 only supports USB charging. If we are not the in ab8500_charger_probe()
3511 * TODO: if this should be opt-in, add DT properties for this. in ab8500_charger_probe()
3513 if (!is_ab8505(di->parent)) in ab8500_charger_probe()
3514 di->ac_chg.enabled = true; in ab8500_charger_probe()
3517 /* ux500_charger sub-class */ in ab8500_charger_probe()
3518 di->usb_chg.ops.enable = &ab8500_charger_usb_en; in ab8500_charger_probe()
3519 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable; in ab8500_charger_probe()
3520 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3521 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3522 di->usb_chg.max_out_volt_uv = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3523 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; in ab8500_charger_probe()
3524 di->usb_chg.max_out_curr_ua = in ab8500_charger_probe()
3525 ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; in ab8500_charger_probe()
3526 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3527 di->usb_state.usb_current_ua = -1; in ab8500_charger_probe()
3529 mutex_init(&di->charger_attached_mutex); in ab8500_charger_probe()
3532 INIT_DEFERRABLE_WORK(&di->check_hw_failure_work, in ab8500_charger_probe()
3534 INIT_DEFERRABLE_WORK(&di->check_usbchgnotok_work, in ab8500_charger_probe()
3537 INIT_DELAYED_WORK(&di->ac_charger_attached_work, in ab8500_charger_probe()
3539 INIT_DELAYED_WORK(&di->usb_charger_attached_work, in ab8500_charger_probe()
3547 * a bug that is not handled by the algorithm and the in ab8500_charger_probe()
3551 INIT_DEFERRABLE_WORK(&di->kick_wd_work, in ab8500_charger_probe()
3554 INIT_DEFERRABLE_WORK(&di->check_vbat_work, in ab8500_charger_probe()
3557 INIT_DELAYED_WORK(&di->attach_work, in ab8500_charger_probe()
3560 INIT_DELAYED_WORK(&di->usb_state_changed_work, in ab8500_charger_probe()
3563 INIT_DELAYED_WORK(&di->vbus_drop_end_work, in ab8500_charger_probe()
3567 INIT_WORK(&di->usb_link_status_work, in ab8500_charger_probe()
3569 INIT_WORK(&di->ac_work, ab8500_charger_ac_work); in ab8500_charger_probe()
3570 INIT_WORK(&di->detect_usb_type_work, in ab8500_charger_probe()
3574 INIT_WORK(&di->check_main_thermal_prot_work, in ab8500_charger_probe()
3576 INIT_WORK(&di->check_usb_thermal_prot_work, in ab8500_charger_probe()
3588 if (di->ac_chg.enabled) { in ab8500_charger_probe()
3589 di->ac_chg.psy = devm_power_supply_register(dev, in ab8500_charger_probe()
3592 if (IS_ERR(di->ac_chg.psy)) { in ab8500_charger_probe()
3594 return PTR_ERR(di->ac_chg.psy); in ab8500_charger_probe()
3599 di->usb_chg.psy = devm_power_supply_register(dev, in ab8500_charger_probe()
3602 if (IS_ERR(di->usb_chg.psy)) { in ab8500_charger_probe()
3604 return PTR_ERR(di->usb_chg.psy); in ab8500_charger_probe()
3611 ret = ab8500_bm_of_probe(di->usb_chg.psy, di->bm); in ab8500_charger_probe()
3619 di->ac.charger_connected = 1; in ab8500_charger_probe()
3620 di->ac_conn = true; in ab8500_charger_probe()
3621 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_probe()
3622 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_probe()
3629 struct device_driver *drv = &ab8500_charger_component_drivers[i]->driver; in ab8500_charger_probe()
3641 ret = -ENODEV; in ab8500_charger_probe()
3650 di->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); in ab8500_charger_probe()
3651 if (IS_ERR_OR_NULL(di->usb_phy)) { in ab8500_charger_probe()
3653 ret = -EINVAL; in ab8500_charger_probe()
3656 di->nb.notifier_call = ab8500_charger_usb_notifier_call; in ab8500_charger_probe()
3657 ret = usb_register_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3663 ret = component_master_add_with_match(&pdev->dev, in ab8500_charger_probe()
3674 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3676 usb_put_phy(di->usb_phy); in ab8500_charger_probe()
3678 ab8500_bm_of_remove(di->usb_chg.psy, di->bm); in ab8500_charger_probe()
3686 component_master_del(&pdev->dev, &ab8500_charger_comp_ops); in ab8500_charger_remove()
3688 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_remove()
3689 ab8500_bm_of_remove(di->usb_chg.psy, di->bm); in ab8500_charger_remove()
3690 usb_put_phy(di->usb_phy); in ab8500_charger_remove()
3698 { .compatible = "stericsson,ab8500-charger", },
3707 .name = "ab8500-charger",
3744 MODULE_ALIAS("platform:ab8500-charger");