Lines Matching +full:vddadc +full:- +full:supply

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
224 * @vddadc_en_ac: Indicate if VDD ADC supply is enabled because AC
226 * @vddadc_en_usb: Indicate if VDD ADC supply is enabled because USB
246 * @ac_chg: AC charger power supply
247 * @usb_chg: USB charger power supply
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
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()
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()
491 ret = iio_read_channel_processed_scale(di->adc_main_charger_v, in ab8500_charger_get_ac_voltage()
494 dev_err(di->dev, "%s ADC conv failed\n", __func__); in ab8500_charger_get_ac_voltage()
504 * ab8500_charger_ac_cv() - check if the main charger is in CV mode
515 if (di->ac.charger_online) { in ab8500_charger_ac_cv()
516 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_cv()
519 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_ac_cv()
533 * ab8500_charger_get_vbus_voltage() - get vbus voltage
544 if (di->usb.charger_connected) { in ab8500_charger_get_vbus_voltage()
546 ret = iio_read_channel_processed_scale(di->adc_vbus_v, in ab8500_charger_get_vbus_voltage()
549 dev_err(di->dev, "%s ADC conv failed\n", __func__); in ab8500_charger_get_vbus_voltage()
559 * ab8500_charger_get_usb_current() - get usb charger current
570 if (di->usb.charger_online) { in ab8500_charger_get_usb_current()
572 ret = iio_read_channel_processed_scale(di->adc_usb_charger_c, in ab8500_charger_get_usb_current()
575 dev_err(di->dev, "%s ADC conv failed\n", __func__); in ab8500_charger_get_usb_current()
585 * ab8500_charger_get_ac_current() - get ac charger current
596 if (di->ac.charger_online) { in ab8500_charger_get_ac_current()
598 ret = iio_read_channel_processed_scale(di->adc_main_charger_c, in ab8500_charger_get_ac_current()
601 dev_err(di->dev, "%s ADC conv failed\n", __func__); in ab8500_charger_get_ac_current()
611 * ab8500_charger_usb_cv() - check if the usb charger is in CV mode
622 if (di->usb.charger_online) { in ab8500_charger_usb_cv()
623 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_cv()
626 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_usb_cv()
642 * ab8500_charger_detect_chargers() - Detect the connected chargers
653 * NO_PW_CONN no power supply is connected
654 * AC_PW_CONN if the AC power supply is connected
655 * USB_PW_CONN if the USB power supply is connected
665 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
668 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
686 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
689 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
692 dev_dbg(di->dev, in ab8500_charger_detect_chargers()
702 * ab8500_charger_max_usb_curr() - get the max curr for the USB type
715 di->usb_device_is_unrecognised = false; in ab8500_charger_max_usb_curr()
728 dev_dbg(di->dev, "USB Type - Standard host is " in ab8500_charger_max_usb_curr()
730 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
731 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
734 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
735 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
738 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
739 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
742 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P9; in ab8500_charger_max_usb_curr()
743 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
750 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n"); in ab8500_charger_max_usb_curr()
751 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
752 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
759 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P3; in ab8500_charger_max_usb_curr()
760 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
761 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
762 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
765 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
766 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
769 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
770 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
774 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
775 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
778 if (di->vbus_detected) { in ab8500_charger_max_usb_curr()
779 di->usb_device_is_unrecognised = true; in ab8500_charger_max_usb_curr()
780 dev_dbg(di->dev, "USB Type - Legacy charger.\n"); in ab8500_charger_max_usb_curr()
781 di->max_usb_in_curr.usb_type_max_ua = in ab8500_charger_max_usb_curr()
787 dev_err(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
788 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
789 ret = -ENXIO; in ab8500_charger_max_usb_curr()
792 if (is_ab8500(di->parent)) { in ab8500_charger_max_usb_curr()
793 di->flags.vbus_collapse = true; in ab8500_charger_max_usb_curr()
794 dev_err(di->dev, "USB Type - USB_STAT_RESERVED " in ab8500_charger_max_usb_curr()
796 ret = -ENXIO; in ab8500_charger_max_usb_curr()
799 dev_dbg(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
800 di->max_usb_in_curr.usb_type_max_ua = in ab8500_charger_max_usb_curr()
802 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
804 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
805 ret = -ENXIO; in ab8500_charger_max_usb_curr()
812 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
813 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
814 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_max_usb_curr()
817 dev_err(di->dev, "USB Type invalid - try charging anyway\n"); in ab8500_charger_max_usb_curr()
818 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
822 dev_err(di->dev, "USB Type - Unknown\n"); in ab8500_charger_max_usb_curr()
823 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
824 ret = -ENXIO; in ab8500_charger_max_usb_curr()
828 di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; in ab8500_charger_max_usb_curr()
829 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
830 link_status, di->max_usb_in_curr.set_max_ua); in ab8500_charger_max_usb_curr()
836 * ab8500_charger_read_usb_type() - read the type of usb connected
847 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
850 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()
854 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_read_usb_type()
857 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
860 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_read_usb_type()
865 if (is_ab8500(di->parent)) in ab8500_charger_read_usb_type()
876 * ab8500_charger_detect_usb_type() - get the type of usb connected
894 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
897 dev_dbg(di->dev, "%s AB8500_IT_SOURCE21_REG %x\n", in ab8500_charger_detect_usb_type()
900 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
904 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
905 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
908 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
911 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
914 dev_dbg(di->dev, "%s AB8500_USB_LINE_STAT_REG %x\n", __func__, in ab8500_charger_detect_usb_type()
923 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
1033 return i - 1; in ab8500_voltage_to_regval()
1037 i = ARRAY_SIZE(ab8500_charger_voltage_map) - 1; in ab8500_voltage_to_regval()
1041 return -1; in ab8500_voltage_to_regval()
1065 return i - 1; in ab8500_current_to_regval()
1069 i = ARRAY_SIZE(ab8500_charge_output_curr_map) - 1; in ab8500_current_to_regval()
1073 return -1; in ab8500_current_to_regval()
1085 return i - 1; in ab8500_vbus_in_curr_to_regval()
1089 i = ARRAY_SIZE(ab8500_charge_input_curr_map) - 1; in ab8500_vbus_in_curr_to_regval()
1093 return -1; in ab8500_vbus_in_curr_to_regval()
1097 * ab8500_charger_get_usb_cur() - get usb current
1103 * to the register. Returns -1 if charging is not allowed
1108 switch (di->usb_state.usb_current_ua) { in ab8500_charger_get_usb_cur()
1110 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P09; in ab8500_charger_get_usb_cur()
1113 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P19; in ab8500_charger_get_usb_cur()
1116 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P29; in ab8500_charger_get_usb_cur()
1119 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P38; in ab8500_charger_get_usb_cur()
1122 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_get_usb_cur()
1125 di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_get_usb_cur()
1126 ret = -EPERM; in ab8500_charger_get_usb_cur()
1129 di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; in ab8500_charger_get_usb_cur()
1134 * ab8500_charger_check_continue_stepping() - Check to allow stepping
1146 return !di->flags.vbus_drop_end; in ab8500_charger_check_continue_stepping()
1152 * ab8500_charger_set_current() - set charger current
1161 * this charger current step-up/down here.
1173 atomic_inc(&di->current_stepping_sessions); in ab8500_charger_set_current()
1175 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1178 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_set_current()
1188 if (!di->ac.charger_connected) in ab8500_charger_set_current()
1197 if (!di->usb.charger_connected) in ab8500_charger_set_current()
1205 if (curr_index && (curr_index - prev_curr_index) > 1) in ab8500_charger_set_current()
1208 if (!di->usb.charger_connected && !di->ac.charger_connected) in ab8500_charger_set_current()
1213 dev_err(di->dev, "%s current register not valid\n", __func__); in ab8500_charger_set_current()
1214 ret = -ENXIO; in ab8500_charger_set_current()
1219 dev_err(di->dev, "requested current limit out-of-range\n"); in ab8500_charger_set_current()
1220 ret = -ENXIO; in ab8500_charger_set_current()
1226 dev_dbg(di->dev, "%s current not changed for reg: 0x%02x\n", in ab8500_charger_set_current()
1232 dev_dbg(di->dev, "%s set charger current: %d uA for reg: 0x%02x\n", in ab8500_charger_set_current()
1236 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1239 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1241 for (i = prev_curr_index - 1; i >= curr_index; i--) { in ab8500_charger_set_current()
1242 dev_dbg(di->dev, "curr change_1 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1244 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1247 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1256 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1258 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1261 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1272 atomic_dec(&di->current_stepping_sessions); in ab8500_charger_set_current()
1278 * ab8500_charger_set_vbus_in_curr() - set VBUS input current limit
1292 min_value = min(di->bm->chg_params->usb_curr_max_ua, ich_in_ua); in ab8500_charger_set_vbus_in_curr()
1293 if (di->max_usb_in_curr.set_max_ua > 0) in ab8500_charger_set_vbus_in_curr()
1294 min_value = min(di->max_usb_in_curr.set_max_ua, min_value); in ab8500_charger_set_vbus_in_curr()
1296 if (di->usb_state.usb_current_ua >= 0) in ab8500_charger_set_vbus_in_curr()
1297 min_value = min(di->usb_state.usb_current_ua, min_value); in ab8500_charger_set_vbus_in_curr()
1301 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1305 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1312 dev_info(di->dev, "VBUS input current limit set to %d uA\n", min_value); in ab8500_charger_set_vbus_in_curr()
1314 mutex_lock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1317 mutex_unlock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1323 * ab8500_charger_set_main_in_curr() - set main charger input current
1338 * ab8500_charger_set_output_curr() - set charger output current
1353 * ab8500_charger_led_en() - turn on/off chargign led
1366 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1370 dev_err(di->dev, "Power ON LED failed\n"); in ab8500_charger_led_en()
1374 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1378 dev_err(di->dev, "Set LED PWM duty cycle failed\n"); in ab8500_charger_led_en()
1383 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1387 dev_err(di->dev, "Power-off LED failed\n"); in ab8500_charger_led_en()
1396 * ab8500_charger_ac_en() - enable or disable ac charging
1418 if (!di->ac.charger_connected) { in ab8500_charger_ac_en()
1419 dev_err(di->dev, "AC charger not connected\n"); in ab8500_charger_ac_en()
1420 return -ENXIO; in ab8500_charger_ac_en()
1424 dev_dbg(di->dev, "Enable AC: %duV %duA\n", vset_uv, iset_ua); in ab8500_charger_ac_en()
1428 * will be triggered every time we enable the VDD ADC supply. in ab8500_charger_ac_en()
1430 * It can be avoided by having the supply on when in ab8500_charger_ac_en()
1431 * there is a charger enabled. Normally the VDD ADC supply in ab8500_charger_ac_en()
1436 if (!di->vddadc_en_ac) { in ab8500_charger_ac_en()
1437 ret = regulator_enable(di->regu); in ab8500_charger_ac_en()
1439 dev_warn(di->dev, in ab8500_charger_ac_en()
1442 di->vddadc_en_ac = true; in ab8500_charger_ac_en()
1449 di->bm->chg_params->ac_curr_max_ua); in ab8500_charger_ac_en()
1451 dev_err(di->dev, in ab8500_charger_ac_en()
1454 return -ENXIO; in ab8500_charger_ac_en()
1458 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1461 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1466 di->bm->chg_params->ac_curr_max_ua); in ab8500_charger_ac_en()
1468 dev_err(di->dev, "%s Failed to set MainChInputCurr\n", in ab8500_charger_ac_en()
1475 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1482 if (!di->bm->enable_overshoot) in ab8500_charger_ac_en()
1486 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1489 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1496 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_ac_en()
1498 di->ac.charger_online = 1; in ab8500_charger_ac_en()
1501 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_ac_en()
1512 if (di->ac_conn) { in ab8500_charger_ac_en()
1513 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_en()
1514 &di->kick_wd_work, in ab8500_charger_ac_en()
1525 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1529 dev_err(di->dev, in ab8500_charger_ac_en()
1536 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1542 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1546 dev_err(di->dev, in ab8500_charger_ac_en()
1554 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_ac_en()
1556 di->ac.charger_online = 0; in ab8500_charger_ac_en()
1557 di->ac.wd_expired = false; in ab8500_charger_ac_en()
1560 if (di->vddadc_en_ac) { in ab8500_charger_ac_en()
1561 regulator_disable(di->regu); in ab8500_charger_ac_en()
1562 di->vddadc_en_ac = false; in ab8500_charger_ac_en()
1565 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__); in ab8500_charger_ac_en()
1567 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_en()
1573 * ab8500_charger_usb_en() - enable usb charging
1594 if (!di->usb.charger_connected) { in ab8500_charger_usb_en()
1595 dev_err(di->dev, "USB charger not connected\n"); in ab8500_charger_usb_en()
1596 return -ENXIO; in ab8500_charger_usb_en()
1601 * will be triggered every time we enable the VDD ADC supply. in ab8500_charger_usb_en()
1603 * It can be avoided by having the supply on when in ab8500_charger_usb_en()
1604 * there is a charger enabled. Normally the VDD ADC supply in ab8500_charger_usb_en()
1609 if (!di->vddadc_en_usb) { in ab8500_charger_usb_en()
1610 ret = regulator_enable(di->regu); in ab8500_charger_usb_en()
1612 dev_warn(di->dev, in ab8500_charger_usb_en()
1615 di->vddadc_en_usb = true; in ab8500_charger_usb_en()
1619 dev_dbg(di->dev, "Enable USB: %d uV %d uA\n", vset_uv, ich_out_ua); in ab8500_charger_usb_en()
1625 dev_err(di->dev, in ab8500_charger_usb_en()
1628 return -ENXIO; in ab8500_charger_usb_en()
1635 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1638 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1642 if (!di->bm->enable_overshoot) in ab8500_charger_usb_en()
1646 dev_dbg(di->dev, in ab8500_charger_usb_en()
1648 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1651 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1658 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_usb_en()
1660 di->usb.charger_online = 1; in ab8500_charger_usb_en()
1664 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_en()
1666 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1673 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1679 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ); in ab8500_charger_usb_en()
1683 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1684 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_usb_en()
1688 dev_err(di->dev, in ab8500_charger_usb_en()
1695 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_usb_en()
1699 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1706 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1711 di->usb.charger_online = 0; in ab8500_charger_usb_en()
1712 di->usb.wd_expired = false; in ab8500_charger_usb_en()
1715 if (di->vddadc_en_usb) { in ab8500_charger_usb_en()
1716 regulator_disable(di->regu); in ab8500_charger_usb_en()
1717 di->vddadc_en_usb = false; in ab8500_charger_usb_en()
1720 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1723 cancel_delayed_work(&di->check_vbat_work); in ab8500_charger_usb_en()
1726 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_en()
1732 * ab8500_charger_usb_check_enable() - enable usb charging
1748 if (!di->usb.charger_connected) in ab8500_charger_usb_check_enable()
1751 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_check_enable()
1754 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1757 dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1); in ab8500_charger_usb_check_enable()
1760 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_usb_check_enable()
1762 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_check_enable()
1766 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1770 ret = ab8500_charger_usb_en(&di->usb_chg, true, vset_uv, iset_ua); in ab8500_charger_usb_check_enable()
1772 dev_err(di->dev, "Failed to enable VBUS charger %d\n", in ab8500_charger_usb_check_enable()
1781 * ab8500_charger_ac_check_enable() - enable usb charging
1797 if (!di->ac.charger_connected) in ab8500_charger_ac_check_enable()
1800 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_check_enable()
1803 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1806 dev_dbg(di->dev, "AC charger ctrl: 0x%02x\n", mainch_ctrl1); in ab8500_charger_ac_check_enable()
1809 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_ac_check_enable()
1811 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_ac_check_enable()
1816 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1820 ret = ab8500_charger_ac_en(&di->usb_chg, true, vset_uv, iset_ua); in ab8500_charger_ac_check_enable()
1822 dev_err(di->dev, "failed to enable AC charger %d\n", in ab8500_charger_ac_check_enable()
1831 * ab8500_charger_watchdog_kick() - kick charger watchdog
1842 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS) in ab8500_charger_watchdog_kick()
1844 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB) in ab8500_charger_watchdog_kick()
1847 return -ENXIO; in ab8500_charger_watchdog_kick()
1849 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_watchdog_kick()
1852 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_watchdog_kick()
1858 * ab8500_charger_update_charger_current() - update charger current
1871 if (charger->psy->desc->type == POWER_SUPPLY_TYPE_MAINS) in ab8500_charger_update_charger_current()
1873 else if (charger->psy->desc->type == POWER_SUPPLY_TYPE_USB) in ab8500_charger_update_charger_current()
1876 return -ENXIO; in ab8500_charger_update_charger_current()
1880 dev_err(di->dev, "%s " in ab8500_charger_update_charger_current()
1887 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_update_charger_current()
1890 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_update_charger_current()
1901 const char **supplicants = (const char **)ext->supplied_to; in ab8500_charger_get_ext_psy_data()
1908 psy = usb_chg->psy; in ab8500_charger_get_ext_psy_data()
1917 j = match_string(supplicants, ext->num_supplicants, psy->desc->name); in ab8500_charger_get_ext_psy_data()
1922 for (j = 0; j < ext->desc->num_properties; j++) { in ab8500_charger_get_ext_psy_data()
1924 prop = ext->desc->properties[j]; in ab8500_charger_get_ext_psy_data()
1931 switch (ext->desc->type) { in ab8500_charger_get_ext_psy_data()
1934 dev_dbg(di->dev, "get VBAT from %s\n", in ab8500_charger_get_ext_psy_data()
1935 dev_name(&ext->dev)); in ab8500_charger_get_ext_psy_data()
1936 di->vbat = ret.intval; in ab8500_charger_get_ext_psy_data()
1950 * ab8500_charger_check_vbat_work() - keep vbus current within spec
1964 power_supply_for_each_device(&di->usb_chg, ab8500_charger_get_ext_psy_data); in ab8500_charger_check_vbat_work()
1967 if (di->old_vbat == 0) in ab8500_charger_check_vbat_work()
1968 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1970 if (!((di->old_vbat <= VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1971 di->vbat <= VBAT_TRESH_IP_CUR_RED) || in ab8500_charger_check_vbat_work()
1972 (di->old_vbat > VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1973 di->vbat > VBAT_TRESH_IP_CUR_RED))) { in ab8500_charger_check_vbat_work()
1975 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d," in ab8500_charger_check_vbat_work()
1976 " old: %d\n", di->max_usb_in_curr.usb_type_max_ua, in ab8500_charger_check_vbat_work()
1977 di->vbat, di->old_vbat); in ab8500_charger_check_vbat_work()
1979 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_check_vbat_work()
1980 power_supply_changed(di->usb_chg.psy); in ab8500_charger_check_vbat_work()
1983 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1989 if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100000) && in ab8500_charger_check_vbat_work()
1990 (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100000))) in ab8500_charger_check_vbat_work()
1993 queue_delayed_work(di->charger_wq, &di->check_vbat_work, t * HZ); in ab8500_charger_check_vbat_work()
1997 * ab8500_charger_check_hw_failure_work() - check main charger failure
2011 if (di->flags.mainextchnotok) { in ab8500_charger_check_hw_failure_work()
2012 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2015 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2019 di->flags.mainextchnotok = false; in ab8500_charger_check_hw_failure_work()
2020 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_hw_failure_work()
2023 if (di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2024 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2028 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2032 di->flags.vbus_ovv = false; in ab8500_charger_check_hw_failure_work()
2033 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_hw_failure_work()
2037 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2038 queue_delayed_work(di->charger_wq, in ab8500_charger_check_hw_failure_work()
2039 &di->check_hw_failure_work, round_jiffies(HZ)); in ab8500_charger_check_hw_failure_work()
2044 * ab8500_charger_kick_watchdog_work() - kick the watchdog
2064 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_kick_watchdog_work()
2067 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_kick_watchdog_work()
2070 queue_delayed_work(di->charger_wq, in ab8500_charger_kick_watchdog_work()
2071 &di->kick_wd_work, round_jiffies(WD_KICK_INTERVAL)); in ab8500_charger_kick_watchdog_work()
2075 * ab8500_charger_ac_work() - work to get and set main charger status
2097 di->ac.charger_connected = 1; in ab8500_charger_ac_work()
2098 di->ac_conn = true; in ab8500_charger_ac_work()
2100 di->ac.charger_connected = 0; in ab8500_charger_ac_work()
2103 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_work()
2104 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_ac_work()
2117 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_attached_work()
2122 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_attached_work()
2131 ab8500_charger_usb_en(&di->usb_chg, 0, 0, 0); in ab8500_charger_usb_attached_work()
2133 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2134 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2139 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_attached_work()
2140 &di->usb_charger_attached_work, in ab8500_charger_usb_attached_work()
2156 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_ac_attached_work()
2161 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_attached_work()
2171 ab8500_charger_ac_en(&di->ac_chg, 0, 0, 0); in ab8500_charger_ac_attached_work()
2172 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_ac_attached_work()
2174 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2175 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2180 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_attached_work()
2181 &di->ac_charger_attached_work, in ab8500_charger_ac_attached_work()
2186 * ab8500_charger_detect_usb_type_work() - work to detect USB type
2208 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__); in ab8500_charger_detect_usb_type_work()
2209 di->vbus_detected = false; in ab8500_charger_detect_usb_type_work()
2211 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2213 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__); in ab8500_charger_detect_usb_type_work()
2214 di->vbus_detected = true; in ab8500_charger_detect_usb_type_work()
2216 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_detect_usb_type_work()
2221 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2231 if (di->vbus_detected_start) { in ab8500_charger_detect_usb_type_work()
2232 di->vbus_detected_start = false; in ab8500_charger_detect_usb_type_work()
2238 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2246 * ab8500_charger_usb_link_attach_work() - work to detect USB type
2258 if (!di->usb.charger_online) { in ab8500_charger_usb_link_attach_work()
2260 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_link_attach_work()
2266 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_attach_work()
2270 * ab8500_charger_usb_link_status_work() - work to detect USB type
2300 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2301 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2304 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2308 dev_dbg(di->dev, "UsbLineStatus register = 0x%02x\n", val); in ab8500_charger_usb_link_status_work()
2310 dev_dbg(di->dev, "Error reading USB link status\n"); in ab8500_charger_usb_link_status_work()
2312 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2320 di->invalid_charger_detect_state == 0) { in ab8500_charger_usb_link_status_work()
2321 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2324 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2328 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2331 di->invalid_charger_detect_state = 1; in ab8500_charger_usb_link_status_work()
2336 if (di->invalid_charger_detect_state == 1) { in ab8500_charger_usb_link_status_work()
2337 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2340 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2344 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2345 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2349 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2353 dev_dbg(di->dev, "USB link status= 0x%02x\n", in ab8500_charger_usb_link_status_work()
2355 di->invalid_charger_detect_state = 2; in ab8500_charger_usb_link_status_work()
2358 di->invalid_charger_detect_state = 0; in ab8500_charger_usb_link_status_work()
2362 di->vbus_detected = false; in ab8500_charger_usb_link_status_work()
2364 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2368 dev_dbg(di->dev,"%s di->vbus_detected = true\n",__func__); in ab8500_charger_usb_link_status_work()
2369 di->vbus_detected = true; in ab8500_charger_usb_link_status_work()
2372 if (ret == -ENXIO) { in ab8500_charger_usb_link_status_work()
2375 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2380 if (di->usb_device_is_unrecognised) { in ab8500_charger_usb_link_status_work()
2381 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2386 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2387 &di->attach_work, in ab8500_charger_usb_link_status_work()
2389 } else if (di->is_aca_rid == 1) { in ab8500_charger_usb_link_status_work()
2391 di->is_aca_rid++; in ab8500_charger_usb_link_status_work()
2392 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2395 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2396 &di->attach_work, in ab8500_charger_usb_link_status_work()
2399 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2400 &di->attach_work, in ab8500_charger_usb_link_status_work()
2413 if (!di->vbus_detected) { in ab8500_charger_usb_state_changed_work()
2414 dev_dbg(di->dev, in ab8500_charger_usb_state_changed_work()
2415 "%s !di->vbus_detected\n", in ab8500_charger_usb_state_changed_work()
2420 spin_lock_irqsave(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2421 di->usb_state.state = di->usb_state.state_tmp; in ab8500_charger_usb_state_changed_work()
2422 di->usb_state.usb_current_ua = di->usb_state.usb_current_tmp_ua; in ab8500_charger_usb_state_changed_work()
2423 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2425 dev_dbg(di->dev, "%s USB state: 0x%02x uA: %d\n", in ab8500_charger_usb_state_changed_work()
2426 __func__, di->usb_state.state, di->usb_state.usb_current_ua); in ab8500_charger_usb_state_changed_work()
2428 switch (di->usb_state.state) { in ab8500_charger_usb_state_changed_work()
2434 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2439 * when suspend->resume there should be delay in ab8500_charger_usb_state_changed_work()
2452 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_usb_state_changed_work()
2457 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2467 * ab8500_charger_check_usbchargernotok_work() - check USB chg not ok status
2482 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usbchargernotok_work()
2485 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usbchargernotok_work()
2488 prev_status = di->flags.usbchargernotok; in ab8500_charger_check_usbchargernotok_work()
2491 di->flags.usbchargernotok = true; in ab8500_charger_check_usbchargernotok_work()
2493 queue_delayed_work(di->charger_wq, in ab8500_charger_check_usbchargernotok_work()
2494 &di->check_usbchgnotok_work, HZ); in ab8500_charger_check_usbchargernotok_work()
2496 di->flags.usbchargernotok = false; in ab8500_charger_check_usbchargernotok_work()
2497 di->flags.vbus_collapse = false; in ab8500_charger_check_usbchargernotok_work()
2500 if (prev_status != di->flags.usbchargernotok) in ab8500_charger_check_usbchargernotok_work()
2501 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usbchargernotok_work()
2505 * ab8500_charger_check_main_thermal_prot_work() - check main thermal status
2520 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_main_thermal_prot_work()
2523 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_main_thermal_prot_work()
2527 di->flags.main_thermal_prot = true; in ab8500_charger_check_main_thermal_prot_work()
2529 di->flags.main_thermal_prot = false; in ab8500_charger_check_main_thermal_prot_work()
2531 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_main_thermal_prot_work()
2535 * ab8500_charger_check_usb_thermal_prot_work() - check usb thermal status
2550 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usb_thermal_prot_work()
2553 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usb_thermal_prot_work()
2557 di->flags.usb_thermal_prot = true; in ab8500_charger_check_usb_thermal_prot_work()
2559 di->flags.usb_thermal_prot = false; in ab8500_charger_check_usb_thermal_prot_work()
2561 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usb_thermal_prot_work()
2565 * ab8500_charger_mainchunplugdet_handler() - main charger unplugged
2575 dev_dbg(di->dev, "Main charger unplugged\n"); in ab8500_charger_mainchunplugdet_handler()
2576 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchunplugdet_handler()
2578 cancel_delayed_work_sync(&di->ac_charger_attached_work); in ab8500_charger_mainchunplugdet_handler()
2579 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2580 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2586 * ab8500_charger_mainchplugdet_handler() - main charger plugged
2596 dev_dbg(di->dev, "Main charger plugged\n"); in ab8500_charger_mainchplugdet_handler()
2597 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchplugdet_handler()
2599 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2600 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2602 if (is_ab8500(di->parent)) in ab8500_charger_mainchplugdet_handler()
2603 queue_delayed_work(di->charger_wq, in ab8500_charger_mainchplugdet_handler()
2604 &di->ac_charger_attached_work, in ab8500_charger_mainchplugdet_handler()
2610 * ab8500_charger_mainextchnotok_handler() - main charger not ok
2620 dev_dbg(di->dev, "Main charger not ok\n"); in ab8500_charger_mainextchnotok_handler()
2621 di->flags.mainextchnotok = true; in ab8500_charger_mainextchnotok_handler()
2622 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_mainextchnotok_handler()
2625 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_mainextchnotok_handler()
2631 * ab8500_charger_mainchthprotr_handler() - Die temp is above main charger
2642 dev_dbg(di->dev, in ab8500_charger_mainchthprotr_handler()
2644 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotr_handler()
2650 * ab8500_charger_mainchthprotf_handler() - Die temp is below main charger
2661 dev_dbg(di->dev, in ab8500_charger_mainchthprotf_handler()
2663 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotf_handler()
2675 di->flags.vbus_drop_end = false; in ab8500_charger_vbus_drop_end_work()
2678 abx500_set_register_interruptible(di->dev, in ab8500_charger_vbus_drop_end_work()
2681 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_vbus_drop_end_work()
2684 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_vbus_drop_end_work()
2691 if (di->max_usb_in_curr.calculated_max_ua != curr_ua) { in ab8500_charger_vbus_drop_end_work()
2693 di->max_usb_in_curr.calculated_max_ua = curr_ua; in ab8500_charger_vbus_drop_end_work()
2694 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2696 di->max_usb_in_curr.calculated_max_ua); in ab8500_charger_vbus_drop_end_work()
2702 di->max_usb_in_curr.set_max_ua = in ab8500_charger_vbus_drop_end_work()
2703 di->max_usb_in_curr.calculated_max_ua; in ab8500_charger_vbus_drop_end_work()
2704 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2706 di->max_usb_in_curr.set_max_ua); in ab8500_charger_vbus_drop_end_work()
2709 if (di->usb.charger_connected) in ab8500_charger_vbus_drop_end_work()
2711 di->max_usb_in_curr.usb_type_max_ua); in ab8500_charger_vbus_drop_end_work()
2715 * ab8500_charger_vbusdetf_handler() - VBUS falling detected
2725 di->vbus_detected = false; in ab8500_charger_vbusdetf_handler()
2726 dev_dbg(di->dev, "VBUS falling detected\n"); in ab8500_charger_vbusdetf_handler()
2727 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetf_handler()
2733 * ab8500_charger_vbusdetr_handler() - VBUS rising detected
2743 di->vbus_detected = true; in ab8500_charger_vbusdetr_handler()
2744 dev_dbg(di->dev, "VBUS rising detected\n"); in ab8500_charger_vbusdetr_handler()
2746 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetr_handler()
2752 * ab8500_charger_usblinkstatus_handler() - USB link status has changed
2762 dev_dbg(di->dev, "USB link status changed\n"); in ab8500_charger_usblinkstatus_handler()
2764 queue_work(di->charger_wq, &di->usb_link_status_work); in ab8500_charger_usblinkstatus_handler()
2770 * ab8500_charger_usbchthprotr_handler() - Die temp is above usb charger
2781 dev_dbg(di->dev, in ab8500_charger_usbchthprotr_handler()
2783 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotr_handler()
2789 * ab8500_charger_usbchthprotf_handler() - Die temp is below usb charger
2800 dev_dbg(di->dev, in ab8500_charger_usbchthprotf_handler()
2802 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotf_handler()
2808 * ab8500_charger_usbchargernotokr_handler() - USB charger not ok detected
2818 dev_dbg(di->dev, "Not allowed USB charger detected\n"); in ab8500_charger_usbchargernotokr_handler()
2819 queue_delayed_work(di->charger_wq, &di->check_usbchgnotok_work, 0); in ab8500_charger_usbchargernotokr_handler()
2825 * ab8500_charger_chwdexp_handler() - Charger watchdog expired
2835 dev_dbg(di->dev, "Charger watchdog expired\n"); in ab8500_charger_chwdexp_handler()
2841 if (di->ac.charger_online) { in ab8500_charger_chwdexp_handler()
2842 di->ac.wd_expired = true; in ab8500_charger_chwdexp_handler()
2843 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_chwdexp_handler()
2845 if (di->usb.charger_online) { in ab8500_charger_chwdexp_handler()
2846 di->usb.wd_expired = true; in ab8500_charger_chwdexp_handler()
2847 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_chwdexp_handler()
2854 * ab8500_charger_vbuschdropend_handler() - VBUS drop removed
2864 dev_dbg(di->dev, "VBUS charger drop ended\n"); in ab8500_charger_vbuschdropend_handler()
2865 di->flags.vbus_drop_end = true; in ab8500_charger_vbuschdropend_handler()
2871 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, in ab8500_charger_vbuschdropend_handler()
2878 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected
2888 dev_dbg(di->dev, "VBUS overvoltage detected\n"); in ab8500_charger_vbusovv_handler()
2889 di->flags.vbus_ovv = true; in ab8500_charger_vbusovv_handler()
2890 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_vbusovv_handler()
2893 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_vbusovv_handler()
2899 * ab8500_charger_ac_get_property() - get the ac/mains properties
2923 if (di->flags.mainextchnotok) in ab8500_charger_ac_get_property()
2924 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in ab8500_charger_ac_get_property()
2925 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_ac_get_property()
2926 val->intval = POWER_SUPPLY_HEALTH_DEAD; in ab8500_charger_ac_get_property()
2927 else if (di->flags.main_thermal_prot) in ab8500_charger_ac_get_property()
2928 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in ab8500_charger_ac_get_property()
2930 val->intval = POWER_SUPPLY_HEALTH_GOOD; in ab8500_charger_ac_get_property()
2933 val->intval = di->ac.charger_online; in ab8500_charger_ac_get_property()
2936 val->intval = di->ac.charger_connected; in ab8500_charger_ac_get_property()
2941 di->ac.charger_voltage_uv = ret; in ab8500_charger_ac_get_property()
2943 val->intval = di->ac.charger_voltage_uv; in ab8500_charger_ac_get_property()
2950 di->ac.cv_active = ab8500_charger_ac_cv(di); in ab8500_charger_ac_get_property()
2951 val->intval = di->ac.cv_active; in ab8500_charger_ac_get_property()
2956 di->ac.charger_current_ua = ret; in ab8500_charger_ac_get_property()
2957 val->intval = di->ac.charger_current_ua; in ab8500_charger_ac_get_property()
2960 return -EINVAL; in ab8500_charger_ac_get_property()
2966 * ab8500_charger_usb_get_property() - get the usb properties
2990 if (di->flags.usbchargernotok) in ab8500_charger_usb_get_property()
2991 val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; in ab8500_charger_usb_get_property()
2992 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_usb_get_property()
2993 val->intval = POWER_SUPPLY_HEALTH_DEAD; in ab8500_charger_usb_get_property()
2994 else if (di->flags.usb_thermal_prot) in ab8500_charger_usb_get_property()
2995 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; in ab8500_charger_usb_get_property()
2996 else if (di->flags.vbus_ovv) in ab8500_charger_usb_get_property()
2997 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; in ab8500_charger_usb_get_property()
2999 val->intval = POWER_SUPPLY_HEALTH_GOOD; in ab8500_charger_usb_get_property()
3002 val->intval = di->usb.charger_online; in ab8500_charger_usb_get_property()
3005 val->intval = di->usb.charger_connected; in ab8500_charger_usb_get_property()
3010 di->usb.charger_voltage_uv = ret; in ab8500_charger_usb_get_property()
3011 val->intval = di->usb.charger_voltage_uv; in ab8500_charger_usb_get_property()
3018 di->usb.cv_active = ab8500_charger_usb_cv(di); in ab8500_charger_usb_get_property()
3019 val->intval = di->usb.cv_active; in ab8500_charger_usb_get_property()
3024 di->usb.charger_current_ua = ret; in ab8500_charger_usb_get_property()
3025 val->intval = di->usb.charger_current_ua; in ab8500_charger_usb_get_property()
3032 if (di->flags.vbus_collapse) in ab8500_charger_usb_get_property()
3033 val->intval = 1; in ab8500_charger_usb_get_property()
3035 val->intval = 0; in ab8500_charger_usb_get_property()
3038 return -EINVAL; in ab8500_charger_usb_get_property()
3044 * ab8500_charger_init_hw_registers() - Set up charger related registers
3055 if (!is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_init_hw_registers()
3056 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3060 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3065 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3069 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3075 if (is_ab8505_2p0(di->parent)) in ab8500_charger_init_hw_registers()
3076 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3085 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3090 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3096 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3099 dev_err(di->dev, "failed to enable main WD in OTP\n"); in ab8500_charger_init_hw_registers()
3104 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3108 dev_err(di->dev, "failed to enable main watchdog\n"); in ab8500_charger_init_hw_registers()
3121 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3126 dev_err(di->dev, "failed to kick main watchdog\n"); in ab8500_charger_init_hw_registers()
3131 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3135 dev_err(di->dev, "failed to disable main watchdog\n"); in ab8500_charger_init_hw_registers()
3140 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_init_hw_registers()
3143 dev_err(di->dev, "failed to set charger watchdog timeout\n"); in ab8500_charger_init_hw_registers()
3149 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_init_hw_registers()
3153 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3156 (di->bm->bkup_bat_v & 0x3) | di->bm->bkup_bat_i); in ab8500_charger_init_hw_registers()
3158 dev_err(di->dev, "failed to setup backup battery charging\n"); in ab8500_charger_init_hw_registers()
3163 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3167 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_init_hw_registers()
3209 dev_dbg(di->dev, "not a standard host, returning\n"); in ab8500_charger_usb_notifier_call()
3216 if ((di->usb_state.usb_current_ua == 2000) && (mA > 2)) in ab8500_charger_usb_notifier_call()
3227 dev_dbg(di->dev, "%s usb_state: 0x%02x mA: %d\n", in ab8500_charger_usb_notifier_call()
3230 spin_lock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3231 di->usb_state.state_tmp = bm_usb_state; in ab8500_charger_usb_notifier_call()
3233 di->usb_state.usb_current_tmp_ua = mA * 1000; in ab8500_charger_usb_notifier_call()
3234 spin_unlock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3240 queue_delayed_work(di->charger_wq, &di->usb_state_changed_work, HZ/2); in ab8500_charger_usb_notifier_call()
3259 if (di->ac_conn && is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_resume()
3260 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_resume()
3263 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_resume()
3266 queue_delayed_work(di->charger_wq, &di->kick_wd_work, in ab8500_charger_resume()
3271 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_resume()
3272 queue_delayed_work(di->charger_wq, in ab8500_charger_resume()
3273 &di->check_hw_failure_work, 0); in ab8500_charger_resume()
3276 if (di->flags.vbus_drop_end) in ab8500_charger_resume()
3277 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, 0); in ab8500_charger_resume()
3287 cancel_delayed_work(&di->check_hw_failure_work); in ab8500_charger_suspend()
3288 cancel_delayed_work(&di->vbus_drop_end_work); in ab8500_charger_suspend()
3290 flush_delayed_work(&di->attach_work); in ab8500_charger_suspend()
3291 flush_delayed_work(&di->usb_charger_attached_work); in ab8500_charger_suspend()
3292 flush_delayed_work(&di->ac_charger_attached_work); in ab8500_charger_suspend()
3293 flush_delayed_work(&di->check_usbchgnotok_work); in ab8500_charger_suspend()
3294 flush_delayed_work(&di->check_vbat_work); in ab8500_charger_suspend()
3295 flush_delayed_work(&di->kick_wd_work); in ab8500_charger_suspend()
3297 flush_work(&di->usb_link_status_work); in ab8500_charger_suspend()
3298 flush_work(&di->ac_work); in ab8500_charger_suspend()
3299 flush_work(&di->detect_usb_type_work); in ab8500_charger_suspend()
3301 if (atomic_read(&di->current_stepping_sessions)) in ab8500_charger_suspend()
3302 return -EAGAIN; in ab8500_charger_suspend()
3336 di->charger_wq = alloc_ordered_workqueue("ab8500_charger_wq", in ab8500_charger_bind()
3338 if (di->charger_wq == NULL) { in ab8500_charger_bind()
3340 return -ENOMEM; in ab8500_charger_bind()
3346 if (is_ab8500(di->parent)) in ab8500_charger_bind()
3347 queue_delayed_work(di->charger_wq, in ab8500_charger_bind()
3348 &di->ac_charger_attached_work, in ab8500_charger_bind()
3352 if (is_ab8500(di->parent)) in ab8500_charger_bind()
3353 queue_delayed_work(di->charger_wq, in ab8500_charger_bind()
3354 &di->usb_charger_attached_work, in ab8500_charger_bind()
3356 di->vbus_detected = true; in ab8500_charger_bind()
3357 di->vbus_detected_start = true; in ab8500_charger_bind()
3358 queue_work(di->charger_wq, in ab8500_charger_bind()
3359 &di->detect_usb_type_work); in ab8500_charger_bind()
3365 destroy_workqueue(di->charger_wq); in ab8500_charger_bind()
3378 ab8500_charger_ac_en(&di->ac_chg, false, 0, 0); in ab8500_charger_unbind()
3381 ab8500_charger_usb_en(&di->usb_chg, false, 0, 0); in ab8500_charger_unbind()
3384 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_unbind()
3387 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_unbind()
3390 destroy_workqueue(di->charger_wq); in ab8500_charger_unbind()
3409 struct device *dev = &pdev->dev; in ab8500_charger_probe()
3410 struct device_node *np = dev->of_node; in ab8500_charger_probe()
3420 return -ENOMEM; in ab8500_charger_probe()
3422 di->bm = &ab8500_bm_data; in ab8500_charger_probe()
3424 di->autopower_cfg = of_property_read_bool(np, "autopower_cfg"); in ab8500_charger_probe()
3427 di->dev = dev; in ab8500_charger_probe()
3428 di->parent = dev_get_drvdata(pdev->dev.parent); in ab8500_charger_probe()
3431 if (!is_ab8505(di->parent)) { in ab8500_charger_probe()
3432 di->adc_main_charger_v = devm_iio_channel_get(dev, "main_charger_v"); in ab8500_charger_probe()
3433 if (IS_ERR(di->adc_main_charger_v)) { in ab8500_charger_probe()
3434 ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_v), in ab8500_charger_probe()
3438 di->adc_main_charger_c = devm_iio_channel_get(dev, "main_charger_c"); in ab8500_charger_probe()
3439 if (IS_ERR(di->adc_main_charger_c)) { in ab8500_charger_probe()
3440 ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_c), in ab8500_charger_probe()
3445 di->adc_vbus_v = devm_iio_channel_get(dev, "vbus_v"); in ab8500_charger_probe()
3446 if (IS_ERR(di->adc_vbus_v)) { in ab8500_charger_probe()
3447 ret = dev_err_probe(dev, PTR_ERR(di->adc_vbus_v), in ab8500_charger_probe()
3451 di->adc_usb_charger_c = devm_iio_channel_get(dev, "usb_charger_c"); in ab8500_charger_probe()
3452 if (IS_ERR(di->adc_usb_charger_c)) { in ab8500_charger_probe()
3453 ret = dev_err_probe(dev, PTR_ERR(di->adc_usb_charger_c), in ab8500_charger_probe()
3459 * VDD ADC supply needs to be enabled from this driver when there in ab8500_charger_probe()
3463 di->regu = devm_regulator_get(dev, "vddadc"); in ab8500_charger_probe()
3464 if (IS_ERR(di->regu)) { in ab8500_charger_probe()
3465 ret = PTR_ERR(di->regu); in ab8500_charger_probe()
3466 dev_err(dev, "failed to get vddadc regulator\n"); in ab8500_charger_probe()
3491 spin_lock_init(&di->usb_state.usb_lock); in ab8500_charger_probe()
3492 mutex_init(&di->usb_ipt_crnt_lock); in ab8500_charger_probe()
3494 di->autopower = false; in ab8500_charger_probe()
3495 di->invalid_charger_detect_state = 0; in ab8500_charger_probe()
3497 /* AC and USB supply config */ in ab8500_charger_probe()
3501 ac_psy_cfg.drv_data = &di->ac_chg; in ab8500_charger_probe()
3505 usb_psy_cfg.drv_data = &di->usb_chg; in ab8500_charger_probe()
3507 /* AC supply */ in ab8500_charger_probe()
3508 /* ux500_charger sub-class */ in ab8500_charger_probe()
3509 di->ac_chg.ops.enable = &ab8500_charger_ac_en; in ab8500_charger_probe()
3510 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable; in ab8500_charger_probe()
3511 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3512 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3513 di->ac_chg.max_out_volt_uv = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3514 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; in ab8500_charger_probe()
3515 di->ac_chg.max_out_curr_ua = in ab8500_charger_probe()
3516 ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; in ab8500_charger_probe()
3517 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3522 * TODO: if this should be opt-in, add DT properties for this. in ab8500_charger_probe()
3524 if (!is_ab8505(di->parent)) in ab8500_charger_probe()
3525 di->ac_chg.enabled = true; in ab8500_charger_probe()
3527 /* USB supply */ in ab8500_charger_probe()
3528 /* ux500_charger sub-class */ in ab8500_charger_probe()
3529 di->usb_chg.ops.enable = &ab8500_charger_usb_en; in ab8500_charger_probe()
3530 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable; in ab8500_charger_probe()
3531 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3532 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3533 di->usb_chg.max_out_volt_uv = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3534 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; in ab8500_charger_probe()
3535 di->usb_chg.max_out_curr_ua = in ab8500_charger_probe()
3536 ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; in ab8500_charger_probe()
3537 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3538 di->usb_state.usb_current_ua = -1; in ab8500_charger_probe()
3540 mutex_init(&di->charger_attached_mutex); in ab8500_charger_probe()
3543 INIT_DEFERRABLE_WORK(&di->check_hw_failure_work, in ab8500_charger_probe()
3545 INIT_DEFERRABLE_WORK(&di->check_usbchgnotok_work, in ab8500_charger_probe()
3548 INIT_DELAYED_WORK(&di->ac_charger_attached_work, in ab8500_charger_probe()
3550 INIT_DELAYED_WORK(&di->usb_charger_attached_work, in ab8500_charger_probe()
3562 INIT_DEFERRABLE_WORK(&di->kick_wd_work, in ab8500_charger_probe()
3565 INIT_DEFERRABLE_WORK(&di->check_vbat_work, in ab8500_charger_probe()
3568 INIT_DELAYED_WORK(&di->attach_work, in ab8500_charger_probe()
3571 INIT_DELAYED_WORK(&di->usb_state_changed_work, in ab8500_charger_probe()
3574 INIT_DELAYED_WORK(&di->vbus_drop_end_work, in ab8500_charger_probe()
3578 INIT_WORK(&di->usb_link_status_work, in ab8500_charger_probe()
3580 INIT_WORK(&di->ac_work, ab8500_charger_ac_work); in ab8500_charger_probe()
3581 INIT_WORK(&di->detect_usb_type_work, in ab8500_charger_probe()
3585 INIT_WORK(&di->check_main_thermal_prot_work, in ab8500_charger_probe()
3587 INIT_WORK(&di->check_usb_thermal_prot_work, in ab8500_charger_probe()
3599 if (di->ac_chg.enabled) { in ab8500_charger_probe()
3600 di->ac_chg.psy = devm_power_supply_register(dev, in ab8500_charger_probe()
3603 if (IS_ERR(di->ac_chg.psy)) { in ab8500_charger_probe()
3605 return PTR_ERR(di->ac_chg.psy); in ab8500_charger_probe()
3610 di->usb_chg.psy = devm_power_supply_register(dev, in ab8500_charger_probe()
3613 if (IS_ERR(di->usb_chg.psy)) { in ab8500_charger_probe()
3615 return PTR_ERR(di->usb_chg.psy); in ab8500_charger_probe()
3622 ret = ab8500_bm_of_probe(di->usb_chg.psy, di->bm); in ab8500_charger_probe()
3630 di->ac.charger_connected = 1; in ab8500_charger_probe()
3631 di->ac_conn = true; in ab8500_charger_probe()
3632 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_probe()
3633 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_probe()
3640 struct device_driver *drv = &ab8500_charger_component_drivers[i]->driver; in ab8500_charger_probe()
3652 ret = -ENODEV; in ab8500_charger_probe()
3661 di->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); in ab8500_charger_probe()
3662 if (IS_ERR_OR_NULL(di->usb_phy)) { in ab8500_charger_probe()
3664 ret = -EINVAL; in ab8500_charger_probe()
3667 di->nb.notifier_call = ab8500_charger_usb_notifier_call; in ab8500_charger_probe()
3668 ret = usb_register_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3674 ret = component_master_add_with_match(&pdev->dev, in ab8500_charger_probe()
3685 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3687 usb_put_phy(di->usb_phy); in ab8500_charger_probe()
3689 ab8500_bm_of_remove(di->usb_chg.psy, di->bm); in ab8500_charger_probe()
3697 component_master_del(&pdev->dev, &ab8500_charger_comp_ops); in ab8500_charger_remove()
3699 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_remove()
3700 ab8500_bm_of_remove(di->usb_chg.psy, di->bm); in ab8500_charger_remove()
3701 usb_put_phy(di->usb_phy); in ab8500_charger_remove()
3707 { .compatible = "stericsson,ab8500-charger", },
3716 .name = "ab8500-charger",
3753 MODULE_ALIAS("platform:ab8500-charger");