Lines Matching refs:di
348 static void ab8500_enable_disable_sw_fallback(struct ab8500_charger *di, in ab8500_enable_disable_sw_fallback() argument
357 dev_dbg(di->dev, "SW Fallback: %d\n", fallback); in ab8500_enable_disable_sw_fallback()
359 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
370 ret = abx500_get_register_interruptible(di->dev, bank, reg, &val); in ab8500_enable_disable_sw_fallback()
372 dev_err(di->dev, "%d read failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
376 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
378 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x2); in ab8500_enable_disable_sw_fallback()
380 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
391 ret = abx500_set_register_interruptible(di->dev, bank, reg, val); in ab8500_enable_disable_sw_fallback()
393 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
397 if (is_ab8500(di->parent)) { in ab8500_enable_disable_sw_fallback()
399 ret = abx500_set_register_interruptible(di->dev, 0x11, 0x00, 0x0); in ab8500_enable_disable_sw_fallback()
401 dev_err(di->dev, "%d write failed\n", __LINE__); in ab8500_enable_disable_sw_fallback()
413 static void ab8500_power_supply_changed(struct ab8500_charger *di, in ab8500_power_supply_changed() argument
424 if (di->autopower_cfg) { in ab8500_power_supply_changed()
425 if (!di->usb.charger_connected && in ab8500_power_supply_changed()
426 !di->ac.charger_connected && in ab8500_power_supply_changed()
427 di->autopower) { in ab8500_power_supply_changed()
428 di->autopower = false; in ab8500_power_supply_changed()
429 ab8500_enable_disable_sw_fallback(di, false); in ab8500_power_supply_changed()
430 } else if (!di->autopower && in ab8500_power_supply_changed()
431 (di->ac.charger_connected || in ab8500_power_supply_changed()
432 di->usb.charger_connected)) { in ab8500_power_supply_changed()
433 di->autopower = true; in ab8500_power_supply_changed()
434 ab8500_enable_disable_sw_fallback(di, true); in ab8500_power_supply_changed()
440 static void ab8500_charger_set_usb_connected(struct ab8500_charger *di, in ab8500_charger_set_usb_connected() argument
443 if (connected != di->usb.charger_connected) { in ab8500_charger_set_usb_connected()
444 dev_dbg(di->dev, "USB connected:%i\n", connected); in ab8500_charger_set_usb_connected()
445 di->usb.charger_connected = connected; in ab8500_charger_set_usb_connected()
448 di->flags.vbus_drop_end = false; in ab8500_charger_set_usb_connected()
455 if (di->usb_chg.psy) { in ab8500_charger_set_usb_connected()
456 sysfs_notify(&di->usb_chg.psy->dev.kobj, NULL, in ab8500_charger_set_usb_connected()
461 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
462 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
464 if (is_ab8500(di->parent)) in ab8500_charger_set_usb_connected()
465 queue_delayed_work(di->charger_wq, in ab8500_charger_set_usb_connected()
466 &di->usb_charger_attached_work, in ab8500_charger_set_usb_connected()
469 cancel_delayed_work_sync(&di->usb_charger_attached_work); in ab8500_charger_set_usb_connected()
470 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
471 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_set_usb_connected()
482 static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di) in ab8500_charger_get_ac_voltage() argument
487 if (di->ac.charger_connected) { in ab8500_charger_get_ac_voltage()
488 ret = iio_read_channel_processed(di->adc_main_charger_v, &vch); in ab8500_charger_get_ac_voltage()
490 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_ac_voltage()
503 static int ab8500_charger_ac_cv(struct ab8500_charger *di) in ab8500_charger_ac_cv() argument
509 if (di->ac.charger_online) { in ab8500_charger_ac_cv()
510 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_cv()
513 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_ac_cv()
533 static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di) in ab8500_charger_get_vbus_voltage() argument
538 if (di->usb.charger_connected) { in ab8500_charger_get_vbus_voltage()
539 ret = iio_read_channel_processed(di->adc_vbus_v, &vch); in ab8500_charger_get_vbus_voltage()
541 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_vbus_voltage()
555 static int ab8500_charger_get_usb_current(struct ab8500_charger *di) in ab8500_charger_get_usb_current() argument
560 if (di->usb.charger_online) { in ab8500_charger_get_usb_current()
561 ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich); in ab8500_charger_get_usb_current()
563 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_usb_current()
577 static int ab8500_charger_get_ac_current(struct ab8500_charger *di) in ab8500_charger_get_ac_current() argument
582 if (di->ac.charger_online) { in ab8500_charger_get_ac_current()
583 ret = iio_read_channel_processed(di->adc_main_charger_c, &ich); in ab8500_charger_get_ac_current()
585 dev_err(di->dev, "%s ADC conv failed,\n", __func__); in ab8500_charger_get_ac_current()
598 static int ab8500_charger_usb_cv(struct ab8500_charger *di) in ab8500_charger_usb_cv() argument
604 if (di->usb.charger_online) { in ab8500_charger_usb_cv()
605 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_cv()
608 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_usb_cv()
640 static int ab8500_charger_detect_chargers(struct ab8500_charger *di, bool probe) in ab8500_charger_detect_chargers() argument
647 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
650 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
668 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_detect_chargers()
671 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_chargers()
674 dev_dbg(di->dev, in ab8500_charger_detect_chargers()
692 static int ab8500_charger_max_usb_curr(struct ab8500_charger *di, in ab8500_charger_max_usb_curr() argument
697 di->usb_device_is_unrecognised = false; in ab8500_charger_max_usb_curr()
710 dev_dbg(di->dev, "USB Type - Standard host is " in ab8500_charger_max_usb_curr()
712 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
713 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
716 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
717 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
720 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
721 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
724 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P9; in ab8500_charger_max_usb_curr()
725 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
732 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n"); in ab8500_charger_max_usb_curr()
733 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
734 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
741 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P3; in ab8500_charger_max_usb_curr()
742 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
743 di->max_usb_in_curr.usb_type_max); in ab8500_charger_max_usb_curr()
744 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
747 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
748 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
751 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
752 di->is_aca_rid = 0; in ab8500_charger_max_usb_curr()
756 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5; in ab8500_charger_max_usb_curr()
757 di->is_aca_rid = 1; in ab8500_charger_max_usb_curr()
760 if (di->vbus_detected) { in ab8500_charger_max_usb_curr()
761 di->usb_device_is_unrecognised = true; in ab8500_charger_max_usb_curr()
762 dev_dbg(di->dev, "USB Type - Legacy charger.\n"); in ab8500_charger_max_usb_curr()
763 di->max_usb_in_curr.usb_type_max = in ab8500_charger_max_usb_curr()
769 dev_err(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
770 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
774 if (is_ab8500(di->parent)) { in ab8500_charger_max_usb_curr()
775 di->flags.vbus_collapse = true; in ab8500_charger_max_usb_curr()
776 dev_err(di->dev, "USB Type - USB_STAT_RESERVED " in ab8500_charger_max_usb_curr()
781 dev_dbg(di->dev, "USB Type - Charging not allowed\n"); in ab8500_charger_max_usb_curr()
782 di->max_usb_in_curr.usb_type_max = in ab8500_charger_max_usb_curr()
784 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
786 di->max_usb_in_curr.usb_type_max); in ab8500_charger_max_usb_curr()
794 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
795 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, in ab8500_charger_max_usb_curr()
796 di->max_usb_in_curr.usb_type_max); in ab8500_charger_max_usb_curr()
799 dev_err(di->dev, "USB Type invalid - try charging anyway\n"); in ab8500_charger_max_usb_curr()
800 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_max_usb_curr()
804 dev_err(di->dev, "USB Type - Unknown\n"); in ab8500_charger_max_usb_curr()
805 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_max_usb_curr()
810 di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max; in ab8500_charger_max_usb_curr()
811 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", in ab8500_charger_max_usb_curr()
812 link_status, di->max_usb_in_curr.set_max); in ab8500_charger_max_usb_curr()
824 static int ab8500_charger_read_usb_type(struct ab8500_charger *di) in ab8500_charger_read_usb_type() argument
829 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
832 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_read_usb_type()
835 if (is_ab8500(di->parent)) in ab8500_charger_read_usb_type()
836 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_read_usb_type()
839 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_read_usb_type()
842 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_read_usb_type()
847 if (is_ab8500(di->parent)) in ab8500_charger_read_usb_type()
851 ret = ab8500_charger_max_usb_curr(di, in ab8500_charger_read_usb_type()
864 static int ab8500_charger_detect_usb_type(struct ab8500_charger *di) in ab8500_charger_detect_usb_type() argument
876 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
879 dev_dbg(di->dev, "%s AB8500_IT_SOURCE21_REG %x\n", in ab8500_charger_detect_usb_type()
882 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
886 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
887 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
890 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_detect_usb_type()
893 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_detect_usb_type()
896 dev_dbg(di->dev, "%s AB8500_USB_LINE_STAT_REG %x\n", __func__, in ab8500_charger_detect_usb_type()
905 if (is_ab8500(di->parent)) in ab8500_charger_detect_usb_type()
914 ret = ab8500_charger_max_usb_curr(di, in ab8500_charger_detect_usb_type()
1026 static int ab8500_current_to_regval(struct ab8500_charger *di, int curr) in ab8500_current_to_regval() argument
1030 if (curr < di->bm->chg_output_curr[0]) in ab8500_current_to_regval()
1033 for (i = 0; i < di->bm->n_chg_out_curr; i++) { in ab8500_current_to_regval()
1034 if (curr < di->bm->chg_output_curr[i]) in ab8500_current_to_regval()
1039 i = di->bm->n_chg_out_curr - 1; in ab8500_current_to_regval()
1040 if (curr == di->bm->chg_output_curr[i]) in ab8500_current_to_regval()
1046 static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger *di, int curr) in ab8500_vbus_in_curr_to_regval() argument
1050 if (curr < di->bm->chg_input_curr[0]) in ab8500_vbus_in_curr_to_regval()
1053 for (i = 0; i < di->bm->n_chg_in_curr; i++) { in ab8500_vbus_in_curr_to_regval()
1054 if (curr < di->bm->chg_input_curr[i]) in ab8500_vbus_in_curr_to_regval()
1059 i = di->bm->n_chg_in_curr - 1; in ab8500_vbus_in_curr_to_regval()
1060 if (curr == di->bm->chg_input_curr[i]) in ab8500_vbus_in_curr_to_regval()
1075 static int ab8500_charger_get_usb_cur(struct ab8500_charger *di) in ab8500_charger_get_usb_cur() argument
1078 switch (di->usb_state.usb_current) { in ab8500_charger_get_usb_cur()
1080 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P09; in ab8500_charger_get_usb_cur()
1083 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P19; in ab8500_charger_get_usb_cur()
1086 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P29; in ab8500_charger_get_usb_cur()
1089 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P38; in ab8500_charger_get_usb_cur()
1092 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; in ab8500_charger_get_usb_cur()
1095 di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; in ab8500_charger_get_usb_cur()
1099 di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max; in ab8500_charger_get_usb_cur()
1112 static bool ab8500_charger_check_continue_stepping(struct ab8500_charger *di, in ab8500_charger_check_continue_stepping() argument
1116 return !di->flags.vbus_drop_end; in ab8500_charger_check_continue_stepping()
1134 static int ab8500_charger_set_current(struct ab8500_charger *di, in ab8500_charger_set_current() argument
1143 atomic_inc(&di->current_stepping_sessions); in ab8500_charger_set_current()
1145 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1148 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_set_current()
1156 curr_index = ab8500_current_to_regval(di, ich); in ab8500_charger_set_current()
1158 if (!di->ac.charger_connected) in ab8500_charger_set_current()
1164 curr_index = ab8500_vbus_in_curr_to_regval(di, ich); in ab8500_charger_set_current()
1167 if (!di->usb.charger_connected) in ab8500_charger_set_current()
1173 curr_index = ab8500_current_to_regval(di, ich); in ab8500_charger_set_current()
1178 if (!di->usb.charger_connected && !di->ac.charger_connected) in ab8500_charger_set_current()
1183 dev_err(di->dev, "%s current register not valid\n", __func__); in ab8500_charger_set_current()
1189 dev_err(di->dev, "requested current limit out-of-range\n"); in ab8500_charger_set_current()
1196 dev_dbg(di->dev, "%s current not changed for reg: 0x%02x\n", in ab8500_charger_set_current()
1202 dev_dbg(di->dev, "%s set charger current: %d mA for reg: 0x%02x\n", in ab8500_charger_set_current()
1206 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_set_current()
1209 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1212 dev_dbg(di->dev, "curr change_1 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1214 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1217 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1226 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n", in ab8500_charger_set_current()
1228 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_set_current()
1231 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_set_current()
1237 allow = ab8500_charger_check_continue_stepping(di, reg); in ab8500_charger_set_current()
1242 atomic_dec(&di->current_stepping_sessions); in ab8500_charger_set_current()
1255 static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di, in ab8500_charger_set_vbus_in_curr() argument
1262 min_value = min(di->bm->chg_params->usb_curr_max, ich_in); in ab8500_charger_set_vbus_in_curr()
1263 if (di->max_usb_in_curr.set_max > 0) in ab8500_charger_set_vbus_in_curr()
1264 min_value = min(di->max_usb_in_curr.set_max, min_value); in ab8500_charger_set_vbus_in_curr()
1266 if (di->usb_state.usb_current >= 0) in ab8500_charger_set_vbus_in_curr()
1267 min_value = min(di->usb_state.usb_current, min_value); in ab8500_charger_set_vbus_in_curr()
1271 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1275 if (di->vbat < VBAT_TRESH_IP_CUR_RED) in ab8500_charger_set_vbus_in_curr()
1282 dev_info(di->dev, "VBUS input current limit set to %d mA\n", min_value); in ab8500_charger_set_vbus_in_curr()
1284 mutex_lock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1285 ret = ab8500_charger_set_current(di, min_value, in ab8500_charger_set_vbus_in_curr()
1287 mutex_unlock(&di->usb_ipt_crnt_lock); in ab8500_charger_set_vbus_in_curr()
1300 static int ab8500_charger_set_main_in_curr(struct ab8500_charger *di, in ab8500_charger_set_main_in_curr() argument
1303 return ab8500_charger_set_current(di, ich_in, in ab8500_charger_set_main_in_curr()
1315 static int ab8500_charger_set_output_curr(struct ab8500_charger *di, in ab8500_charger_set_output_curr() argument
1318 return ab8500_charger_set_current(di, ich_out, in ab8500_charger_set_output_curr()
1330 static int ab8500_charger_led_en(struct ab8500_charger *di, int on) in ab8500_charger_led_en() argument
1336 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1340 dev_err(di->dev, "Power ON LED failed\n"); in ab8500_charger_led_en()
1344 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1348 dev_err(di->dev, "Set LED PWM duty cycle failed\n"); in ab8500_charger_led_en()
1353 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_led_en()
1357 dev_err(di->dev, "Power-off LED failed\n"); in ab8500_charger_led_en()
1384 struct ab8500_charger *di = to_ab8500_charger_ac_device_info(charger); in ab8500_charger_ac_en() local
1388 if (!di->ac.charger_connected) { in ab8500_charger_ac_en()
1389 dev_err(di->dev, "AC charger not connected\n"); in ab8500_charger_ac_en()
1394 dev_dbg(di->dev, "Enable AC: %dmV %dmA\n", vset, iset); in ab8500_charger_ac_en()
1406 if (!di->vddadc_en_ac) { in ab8500_charger_ac_en()
1407 ret = regulator_enable(di->regu); in ab8500_charger_ac_en()
1409 dev_warn(di->dev, in ab8500_charger_ac_en()
1412 di->vddadc_en_ac = true; in ab8500_charger_ac_en()
1417 curr_index = ab8500_current_to_regval(di, iset); in ab8500_charger_ac_en()
1418 input_curr_index = ab8500_current_to_regval(di, in ab8500_charger_ac_en()
1419 di->bm->chg_params->ac_curr_max); in ab8500_charger_ac_en()
1421 dev_err(di->dev, in ab8500_charger_ac_en()
1428 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1431 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1435 ret = ab8500_charger_set_main_in_curr(di, in ab8500_charger_ac_en()
1436 di->bm->chg_params->ac_curr_max); in ab8500_charger_ac_en()
1438 dev_err(di->dev, "%s Failed to set MainChInputCurr\n", in ab8500_charger_ac_en()
1443 ret = ab8500_charger_set_output_curr(di, iset); in ab8500_charger_ac_en()
1445 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1452 if (!di->bm->enable_overshoot) in ab8500_charger_ac_en()
1456 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_en()
1459 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_ac_en()
1464 ret = ab8500_charger_led_en(di, true); in ab8500_charger_ac_en()
1466 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_ac_en()
1468 di->ac.charger_online = 1; in ab8500_charger_ac_en()
1471 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_ac_en()
1482 if (di->ac_conn) { in ab8500_charger_ac_en()
1483 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_en()
1484 &di->kick_wd_work, in ab8500_charger_ac_en()
1495 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1499 dev_err(di->dev, in ab8500_charger_ac_en()
1504 ret = ab8500_charger_set_output_curr(di, 0); in ab8500_charger_ac_en()
1506 dev_err(di->dev, "%s " in ab8500_charger_ac_en()
1512 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_ac_en()
1516 dev_err(di->dev, in ab8500_charger_ac_en()
1522 ret = ab8500_charger_led_en(di, false); in ab8500_charger_ac_en()
1524 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_ac_en()
1526 di->ac.charger_online = 0; in ab8500_charger_ac_en()
1527 di->ac.wd_expired = false; in ab8500_charger_ac_en()
1530 if (di->vddadc_en_ac) { in ab8500_charger_ac_en()
1531 regulator_disable(di->regu); in ab8500_charger_ac_en()
1532 di->vddadc_en_ac = false; in ab8500_charger_ac_en()
1535 dev_dbg(di->dev, "%s Disabled AC charging\n", __func__); in ab8500_charger_ac_en()
1537 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_en()
1560 struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger); in ab8500_charger_usb_en() local
1564 if (!di->usb.charger_connected) { in ab8500_charger_usb_en()
1565 dev_err(di->dev, "USB charger not connected\n"); in ab8500_charger_usb_en()
1579 if (!di->vddadc_en_usb) { in ab8500_charger_usb_en()
1580 ret = regulator_enable(di->regu); in ab8500_charger_usb_en()
1582 dev_warn(di->dev, in ab8500_charger_usb_en()
1585 di->vddadc_en_usb = true; in ab8500_charger_usb_en()
1589 dev_dbg(di->dev, "Enable USB: %dmV %dmA\n", vset, ich_out); in ab8500_charger_usb_en()
1593 curr_index = ab8500_current_to_regval(di, ich_out); in ab8500_charger_usb_en()
1595 dev_err(di->dev, in ab8500_charger_usb_en()
1605 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1608 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1612 if (!di->bm->enable_overshoot) in ab8500_charger_usb_en()
1616 dev_dbg(di->dev, in ab8500_charger_usb_en()
1618 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_en()
1621 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_usb_en()
1626 ret = ab8500_charger_led_en(di, true); in ab8500_charger_usb_en()
1628 dev_err(di->dev, "failed to enable LED\n"); in ab8500_charger_usb_en()
1630 di->usb.charger_online = 1; in ab8500_charger_usb_en()
1633 ret = ab8500_charger_set_vbus_in_curr(di, in ab8500_charger_usb_en()
1634 di->max_usb_in_curr.usb_type_max); in ab8500_charger_usb_en()
1636 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1641 ret = ab8500_charger_set_output_curr(di, ich_out); in ab8500_charger_usb_en()
1643 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1649 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ); in ab8500_charger_usb_en()
1653 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1654 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_usb_en()
1658 dev_err(di->dev, in ab8500_charger_usb_en()
1663 ret = ab8500_charger_led_en(di, false); in ab8500_charger_usb_en()
1665 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_usb_en()
1667 ret = ab8500_charger_set_vbus_in_curr(di, 0); in ab8500_charger_usb_en()
1669 dev_err(di->dev, "setting USBChInputCurr failed\n"); in ab8500_charger_usb_en()
1674 ret = ab8500_charger_set_output_curr(di, 0); in ab8500_charger_usb_en()
1676 dev_err(di->dev, "%s " in ab8500_charger_usb_en()
1681 di->usb.charger_online = 0; in ab8500_charger_usb_en()
1682 di->usb.wd_expired = false; in ab8500_charger_usb_en()
1685 if (di->vddadc_en_usb) { in ab8500_charger_usb_en()
1686 regulator_disable(di->regu); in ab8500_charger_usb_en()
1687 di->vddadc_en_usb = false; in ab8500_charger_usb_en()
1690 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__); in ab8500_charger_usb_en()
1693 cancel_delayed_work(&di->check_vbat_work); in ab8500_charger_usb_en()
1696 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_en()
1739 struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger); in ab8500_charger_usb_check_enable() local
1741 if (!di->usb.charger_connected) in ab8500_charger_usb_check_enable()
1744 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_usb_check_enable()
1747 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1750 dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1); in ab8500_charger_usb_check_enable()
1753 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_usb_check_enable()
1755 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_check_enable()
1759 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_usb_check_enable()
1763 ret = ab8500_charger_usb_en(&di->usb_chg, true, vset, iset); in ab8500_charger_usb_check_enable()
1765 dev_err(di->dev, "Failed to enable VBUS charger %d\n", in ab8500_charger_usb_check_enable()
1788 struct ab8500_charger *di = to_ab8500_charger_ac_device_info(charger); in ab8500_charger_ac_check_enable() local
1790 if (!di->ac.charger_connected) in ab8500_charger_ac_check_enable()
1793 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_ac_check_enable()
1796 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1799 dev_dbg(di->dev, "AC charger ctrl: 0x%02x\n", mainch_ctrl1); in ab8500_charger_ac_check_enable()
1802 dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n"); in ab8500_charger_ac_check_enable()
1804 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_ac_check_enable()
1809 dev_err(di->dev, "ab8500 write failed %d\n", __LINE__); in ab8500_charger_ac_check_enable()
1813 ret = ab8500_charger_ac_en(&di->usb_chg, true, vset, iset); in ab8500_charger_ac_check_enable()
1815 dev_err(di->dev, "failed to enable AC charger %d\n", in ab8500_charger_ac_check_enable()
1833 struct ab8500_charger *di; in ab8500_charger_watchdog_kick() local
1836 di = to_ab8500_charger_ac_device_info(charger); in ab8500_charger_watchdog_kick()
1838 di = to_ab8500_charger_usb_device_info(charger); in ab8500_charger_watchdog_kick()
1842 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_watchdog_kick()
1845 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_watchdog_kick()
1861 struct ab8500_charger *di; in ab8500_charger_update_charger_current() local
1864 di = to_ab8500_charger_ac_device_info(charger); in ab8500_charger_update_charger_current()
1866 di = to_ab8500_charger_usb_device_info(charger); in ab8500_charger_update_charger_current()
1870 ret = ab8500_charger_set_output_curr(di, ich_out); in ab8500_charger_update_charger_current()
1872 dev_err(di->dev, "%s " in ab8500_charger_update_charger_current()
1879 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_update_charger_current()
1882 dev_err(di->dev, "%s write failed\n", __func__); in ab8500_charger_update_charger_current()
1894 struct ab8500_charger *di; in ab8500_charger_get_ext_psy_data() local
1902 di = to_ab8500_charger_usb_device_info(usb_chg); in ab8500_charger_get_ext_psy_data()
1921 di->vbat = ret.intval / 1000; in ab8500_charger_get_ext_psy_data()
1946 struct ab8500_charger *di = container_of(work, in ab8500_charger_check_vbat_work() local
1950 di->usb_chg.psy, ab8500_charger_get_ext_psy_data); in ab8500_charger_check_vbat_work()
1953 if (di->old_vbat == 0) in ab8500_charger_check_vbat_work()
1954 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1956 if (!((di->old_vbat <= VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1957 di->vbat <= VBAT_TRESH_IP_CUR_RED) || in ab8500_charger_check_vbat_work()
1958 (di->old_vbat > VBAT_TRESH_IP_CUR_RED && in ab8500_charger_check_vbat_work()
1959 di->vbat > VBAT_TRESH_IP_CUR_RED))) { in ab8500_charger_check_vbat_work()
1961 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d," in ab8500_charger_check_vbat_work()
1962 " old: %d\n", di->max_usb_in_curr.usb_type_max, in ab8500_charger_check_vbat_work()
1963 di->vbat, di->old_vbat); in ab8500_charger_check_vbat_work()
1964 ab8500_charger_set_vbus_in_curr(di, in ab8500_charger_check_vbat_work()
1965 di->max_usb_in_curr.usb_type_max); in ab8500_charger_check_vbat_work()
1966 power_supply_changed(di->usb_chg.psy); in ab8500_charger_check_vbat_work()
1969 di->old_vbat = di->vbat; in ab8500_charger_check_vbat_work()
1975 if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100) && in ab8500_charger_check_vbat_work()
1976 (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100))) in ab8500_charger_check_vbat_work()
1979 queue_delayed_work(di->charger_wq, &di->check_vbat_work, t * HZ); in ab8500_charger_check_vbat_work()
1993 struct ab8500_charger *di = container_of(work, in ab8500_charger_check_hw_failure_work() local
1997 if (di->flags.mainextchnotok) { in ab8500_charger_check_hw_failure_work()
1998 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2001 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2005 di->flags.mainextchnotok = false; in ab8500_charger_check_hw_failure_work()
2006 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_hw_failure_work()
2009 if (di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2010 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_hw_failure_work()
2014 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_hw_failure_work()
2018 di->flags.vbus_ovv = false; in ab8500_charger_check_hw_failure_work()
2019 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_hw_failure_work()
2023 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_check_hw_failure_work()
2024 queue_delayed_work(di->charger_wq, in ab8500_charger_check_hw_failure_work()
2025 &di->check_hw_failure_work, round_jiffies(HZ)); in ab8500_charger_check_hw_failure_work()
2047 struct ab8500_charger *di = container_of(work, in ab8500_charger_kick_watchdog_work() local
2050 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_kick_watchdog_work()
2053 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_kick_watchdog_work()
2056 queue_delayed_work(di->charger_wq, in ab8500_charger_kick_watchdog_work()
2057 &di->kick_wd_work, round_jiffies(WD_KICK_INTERVAL)); in ab8500_charger_kick_watchdog_work()
2070 struct ab8500_charger *di = container_of(work, in ab8500_charger_ac_work() local
2078 ret = ab8500_charger_detect_chargers(di, false); in ab8500_charger_ac_work()
2083 di->ac.charger_connected = 1; in ab8500_charger_ac_work()
2084 di->ac_conn = true; in ab8500_charger_ac_work()
2086 di->ac.charger_connected = 0; in ab8500_charger_ac_work()
2089 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_ac_work()
2090 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_ac_work()
2095 struct ab8500_charger *di = container_of(work, in ab8500_charger_usb_attached_work() local
2103 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_attached_work()
2108 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_usb_attached_work()
2117 ab8500_charger_usb_en(&di->usb_chg, 0, 0, 0); in ab8500_charger_usb_attached_work()
2119 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2120 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_usb_attached_work()
2125 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_attached_work()
2126 &di->usb_charger_attached_work, in ab8500_charger_usb_attached_work()
2133 struct ab8500_charger *di = container_of(work, in ab8500_charger_ac_attached_work() local
2142 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_ac_attached_work()
2147 dev_err(di->dev, "ab8500 read failed %d\n", __LINE__); in ab8500_charger_ac_attached_work()
2157 ab8500_charger_ac_en(&di->ac_chg, 0, 0, 0); in ab8500_charger_ac_attached_work()
2158 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_ac_attached_work()
2160 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2161 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_ac_attached_work()
2166 queue_delayed_work(di->charger_wq, in ab8500_charger_ac_attached_work()
2167 &di->ac_charger_attached_work, in ab8500_charger_ac_attached_work()
2181 struct ab8500_charger *di = container_of(work, in ab8500_charger_detect_usb_type_work() local
2189 ret = ab8500_charger_detect_chargers(di, false); in ab8500_charger_detect_usb_type_work()
2194 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__); in ab8500_charger_detect_usb_type_work()
2195 di->vbus_detected = false; in ab8500_charger_detect_usb_type_work()
2196 ab8500_charger_set_usb_connected(di, false); in ab8500_charger_detect_usb_type_work()
2197 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2199 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__); in ab8500_charger_detect_usb_type_work()
2200 di->vbus_detected = true; in ab8500_charger_detect_usb_type_work()
2202 if (is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_detect_usb_type_work()
2203 ret = ab8500_charger_detect_usb_type(di); in ab8500_charger_detect_usb_type_work()
2205 ab8500_charger_set_usb_connected(di, true); in ab8500_charger_detect_usb_type_work()
2206 ab8500_power_supply_changed(di, in ab8500_charger_detect_usb_type_work()
2207 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2217 if (di->vbus_detected_start) { in ab8500_charger_detect_usb_type_work()
2218 di->vbus_detected_start = false; in ab8500_charger_detect_usb_type_work()
2219 ret = ab8500_charger_detect_usb_type(di); in ab8500_charger_detect_usb_type_work()
2221 ab8500_charger_set_usb_connected(di, in ab8500_charger_detect_usb_type_work()
2223 ab8500_power_supply_changed(di, in ab8500_charger_detect_usb_type_work()
2224 di->usb_chg.psy); in ab8500_charger_detect_usb_type_work()
2239 struct ab8500_charger *di = in ab8500_charger_usb_link_attach_work() local
2244 if (!di->usb.charger_online) { in ab8500_charger_usb_link_attach_work()
2245 ret = ab8500_charger_set_vbus_in_curr(di, in ab8500_charger_usb_link_attach_work()
2246 di->max_usb_in_curr.usb_type_max); in ab8500_charger_usb_link_attach_work()
2251 ab8500_charger_set_usb_connected(di, true); in ab8500_charger_usb_link_attach_work()
2252 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_attach_work()
2268 struct ab8500_charger *di = container_of(work, in ab8500_charger_usb_link_status_work() local
2276 detected_chargers = ab8500_charger_detect_chargers(di, false); in ab8500_charger_usb_link_status_work()
2286 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2287 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2290 ret = abx500_get_register_interruptible(di->dev, AB8500_USB, in ab8500_charger_usb_link_status_work()
2294 dev_dbg(di->dev, "UsbLineStatus register = 0x%02x\n", val); in ab8500_charger_usb_link_status_work()
2296 dev_dbg(di->dev, "Error reading USB link status\n"); in ab8500_charger_usb_link_status_work()
2298 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2306 di->invalid_charger_detect_state == 0) { in ab8500_charger_usb_link_status_work()
2307 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2310 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2314 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2317 di->invalid_charger_detect_state = 1; in ab8500_charger_usb_link_status_work()
2322 if (di->invalid_charger_detect_state == 1) { in ab8500_charger_usb_link_status_work()
2323 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2326 abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2330 if (is_ab8500(di->parent)) in ab8500_charger_usb_link_status_work()
2331 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2335 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_usb_link_status_work()
2339 dev_dbg(di->dev, "USB link status= 0x%02x\n", in ab8500_charger_usb_link_status_work()
2341 di->invalid_charger_detect_state = 2; in ab8500_charger_usb_link_status_work()
2344 di->invalid_charger_detect_state = 0; in ab8500_charger_usb_link_status_work()
2348 di->vbus_detected = false; in ab8500_charger_usb_link_status_work()
2349 ab8500_charger_set_usb_connected(di, false); in ab8500_charger_usb_link_status_work()
2350 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2354 dev_dbg(di->dev,"%s di->vbus_detected = true\n",__func__); in ab8500_charger_usb_link_status_work()
2355 di->vbus_detected = true; in ab8500_charger_usb_link_status_work()
2356 ret = ab8500_charger_read_usb_type(di); in ab8500_charger_usb_link_status_work()
2360 ab8500_charger_set_usb_connected(di, false); in ab8500_charger_usb_link_status_work()
2361 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_link_status_work()
2366 if (di->usb_device_is_unrecognised) { in ab8500_charger_usb_link_status_work()
2367 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2372 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2373 &di->attach_work, in ab8500_charger_usb_link_status_work()
2375 } else if (di->is_aca_rid == 1) { in ab8500_charger_usb_link_status_work()
2377 di->is_aca_rid++; in ab8500_charger_usb_link_status_work()
2378 dev_dbg(di->dev, in ab8500_charger_usb_link_status_work()
2381 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2382 &di->attach_work, in ab8500_charger_usb_link_status_work()
2385 queue_delayed_work(di->charger_wq, in ab8500_charger_usb_link_status_work()
2386 &di->attach_work, in ab8500_charger_usb_link_status_work()
2396 struct ab8500_charger *di = container_of(work, in ab8500_charger_usb_state_changed_work() local
2399 if (!di->vbus_detected) { in ab8500_charger_usb_state_changed_work()
2400 dev_dbg(di->dev, in ab8500_charger_usb_state_changed_work()
2406 spin_lock_irqsave(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2407 di->usb_state.state = di->usb_state.state_tmp; in ab8500_charger_usb_state_changed_work()
2408 di->usb_state.usb_current = di->usb_state.usb_current_tmp; in ab8500_charger_usb_state_changed_work()
2409 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags); in ab8500_charger_usb_state_changed_work()
2411 dev_dbg(di->dev, "%s USB state: 0x%02x mA: %d\n", in ab8500_charger_usb_state_changed_work()
2412 __func__, di->usb_state.state, di->usb_state.usb_current); in ab8500_charger_usb_state_changed_work()
2414 switch (di->usb_state.state) { in ab8500_charger_usb_state_changed_work()
2419 ab8500_charger_set_usb_connected(di, false); in ab8500_charger_usb_state_changed_work()
2420 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2435 if (!ab8500_charger_get_usb_cur(di)) { in ab8500_charger_usb_state_changed_work()
2437 ret = ab8500_charger_set_vbus_in_curr(di, in ab8500_charger_usb_state_changed_work()
2438 di->max_usb_in_curr.usb_type_max); in ab8500_charger_usb_state_changed_work()
2442 ab8500_charger_set_usb_connected(di, true); in ab8500_charger_usb_state_changed_work()
2443 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_usb_state_changed_work()
2464 struct ab8500_charger *di = container_of(work, in ab8500_charger_check_usbchargernotok_work() local
2468 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usbchargernotok_work()
2471 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usbchargernotok_work()
2474 prev_status = di->flags.usbchargernotok; in ab8500_charger_check_usbchargernotok_work()
2477 di->flags.usbchargernotok = true; in ab8500_charger_check_usbchargernotok_work()
2479 queue_delayed_work(di->charger_wq, in ab8500_charger_check_usbchargernotok_work()
2480 &di->check_usbchgnotok_work, HZ); in ab8500_charger_check_usbchargernotok_work()
2482 di->flags.usbchargernotok = false; in ab8500_charger_check_usbchargernotok_work()
2483 di->flags.vbus_collapse = false; in ab8500_charger_check_usbchargernotok_work()
2486 if (prev_status != di->flags.usbchargernotok) in ab8500_charger_check_usbchargernotok_work()
2487 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usbchargernotok_work()
2502 struct ab8500_charger *di = container_of(work, in ab8500_charger_check_main_thermal_prot_work() local
2506 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_main_thermal_prot_work()
2509 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_main_thermal_prot_work()
2513 di->flags.main_thermal_prot = true; in ab8500_charger_check_main_thermal_prot_work()
2515 di->flags.main_thermal_prot = false; in ab8500_charger_check_main_thermal_prot_work()
2517 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_check_main_thermal_prot_work()
2532 struct ab8500_charger *di = container_of(work, in ab8500_charger_check_usb_thermal_prot_work() local
2536 ret = abx500_get_register_interruptible(di->dev, in ab8500_charger_check_usb_thermal_prot_work()
2539 dev_err(di->dev, "%s ab8500 read failed\n", __func__); in ab8500_charger_check_usb_thermal_prot_work()
2543 di->flags.usb_thermal_prot = true; in ab8500_charger_check_usb_thermal_prot_work()
2545 di->flags.usb_thermal_prot = false; in ab8500_charger_check_usb_thermal_prot_work()
2547 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_check_usb_thermal_prot_work()
2559 struct ab8500_charger *di = _di; in ab8500_charger_mainchunplugdet_handler() local
2561 dev_dbg(di->dev, "Main charger unplugged\n"); in ab8500_charger_mainchunplugdet_handler()
2562 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchunplugdet_handler()
2564 cancel_delayed_work_sync(&di->ac_charger_attached_work); in ab8500_charger_mainchunplugdet_handler()
2565 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2566 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchunplugdet_handler()
2580 struct ab8500_charger *di = _di; in ab8500_charger_mainchplugdet_handler() local
2582 dev_dbg(di->dev, "Main charger plugged\n"); in ab8500_charger_mainchplugdet_handler()
2583 queue_work(di->charger_wq, &di->ac_work); in ab8500_charger_mainchplugdet_handler()
2585 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2586 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_mainchplugdet_handler()
2588 if (is_ab8500(di->parent)) in ab8500_charger_mainchplugdet_handler()
2589 queue_delayed_work(di->charger_wq, in ab8500_charger_mainchplugdet_handler()
2590 &di->ac_charger_attached_work, in ab8500_charger_mainchplugdet_handler()
2604 struct ab8500_charger *di = _di; in ab8500_charger_mainextchnotok_handler() local
2606 dev_dbg(di->dev, "Main charger not ok\n"); in ab8500_charger_mainextchnotok_handler()
2607 di->flags.mainextchnotok = true; in ab8500_charger_mainextchnotok_handler()
2608 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_mainextchnotok_handler()
2611 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_mainextchnotok_handler()
2626 struct ab8500_charger *di = _di; in ab8500_charger_mainchthprotr_handler() local
2628 dev_dbg(di->dev, in ab8500_charger_mainchthprotr_handler()
2630 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotr_handler()
2645 struct ab8500_charger *di = _di; in ab8500_charger_mainchthprotf_handler() local
2647 dev_dbg(di->dev, in ab8500_charger_mainchthprotf_handler()
2649 queue_work(di->charger_wq, &di->check_main_thermal_prot_work); in ab8500_charger_mainchthprotf_handler()
2656 struct ab8500_charger *di = container_of(work, in ab8500_charger_vbus_drop_end_work() local
2661 di->flags.vbus_drop_end = false; in ab8500_charger_vbus_drop_end_work()
2664 abx500_set_register_interruptible(di->dev, in ab8500_charger_vbus_drop_end_work()
2667 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_vbus_drop_end_work()
2670 dev_err(di->dev, "%s read failed\n", __func__); in ab8500_charger_vbus_drop_end_work()
2674 curr = di->bm->chg_input_curr[ in ab8500_charger_vbus_drop_end_work()
2677 if (di->max_usb_in_curr.calculated_max != curr) { in ab8500_charger_vbus_drop_end_work()
2679 di->max_usb_in_curr.calculated_max = curr; in ab8500_charger_vbus_drop_end_work()
2680 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2682 di->max_usb_in_curr.calculated_max); in ab8500_charger_vbus_drop_end_work()
2688 di->max_usb_in_curr.set_max = in ab8500_charger_vbus_drop_end_work()
2689 di->max_usb_in_curr.calculated_max; in ab8500_charger_vbus_drop_end_work()
2690 dev_dbg(di->dev, in ab8500_charger_vbus_drop_end_work()
2692 di->max_usb_in_curr.set_max); in ab8500_charger_vbus_drop_end_work()
2695 if (di->usb.charger_connected) in ab8500_charger_vbus_drop_end_work()
2696 ab8500_charger_set_vbus_in_curr(di, in ab8500_charger_vbus_drop_end_work()
2697 di->max_usb_in_curr.usb_type_max); in ab8500_charger_vbus_drop_end_work()
2709 struct ab8500_charger *di = _di; in ab8500_charger_vbusdetf_handler() local
2711 di->vbus_detected = false; in ab8500_charger_vbusdetf_handler()
2712 dev_dbg(di->dev, "VBUS falling detected\n"); in ab8500_charger_vbusdetf_handler()
2713 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetf_handler()
2727 struct ab8500_charger *di = _di; in ab8500_charger_vbusdetr_handler() local
2729 di->vbus_detected = true; in ab8500_charger_vbusdetr_handler()
2730 dev_dbg(di->dev, "VBUS rising detected\n"); in ab8500_charger_vbusdetr_handler()
2732 queue_work(di->charger_wq, &di->detect_usb_type_work); in ab8500_charger_vbusdetr_handler()
2746 struct ab8500_charger *di = _di; in ab8500_charger_usblinkstatus_handler() local
2748 dev_dbg(di->dev, "USB link status changed\n"); in ab8500_charger_usblinkstatus_handler()
2750 queue_work(di->charger_wq, &di->usb_link_status_work); in ab8500_charger_usblinkstatus_handler()
2765 struct ab8500_charger *di = _di; in ab8500_charger_usbchthprotr_handler() local
2767 dev_dbg(di->dev, in ab8500_charger_usbchthprotr_handler()
2769 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotr_handler()
2784 struct ab8500_charger *di = _di; in ab8500_charger_usbchthprotf_handler() local
2786 dev_dbg(di->dev, in ab8500_charger_usbchthprotf_handler()
2788 queue_work(di->charger_wq, &di->check_usb_thermal_prot_work); in ab8500_charger_usbchthprotf_handler()
2802 struct ab8500_charger *di = _di; in ab8500_charger_usbchargernotokr_handler() local
2804 dev_dbg(di->dev, "Not allowed USB charger detected\n"); in ab8500_charger_usbchargernotokr_handler()
2805 queue_delayed_work(di->charger_wq, &di->check_usbchgnotok_work, 0); in ab8500_charger_usbchargernotokr_handler()
2819 struct ab8500_charger *di = _di; in ab8500_charger_chwdexp_handler() local
2821 dev_dbg(di->dev, "Charger watchdog expired\n"); in ab8500_charger_chwdexp_handler()
2827 if (di->ac.charger_online) { in ab8500_charger_chwdexp_handler()
2828 di->ac.wd_expired = true; in ab8500_charger_chwdexp_handler()
2829 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_chwdexp_handler()
2831 if (di->usb.charger_online) { in ab8500_charger_chwdexp_handler()
2832 di->usb.wd_expired = true; in ab8500_charger_chwdexp_handler()
2833 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_chwdexp_handler()
2848 struct ab8500_charger *di = _di; in ab8500_charger_vbuschdropend_handler() local
2850 dev_dbg(di->dev, "VBUS charger drop ended\n"); in ab8500_charger_vbuschdropend_handler()
2851 di->flags.vbus_drop_end = true; in ab8500_charger_vbuschdropend_handler()
2857 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, in ab8500_charger_vbuschdropend_handler()
2872 struct ab8500_charger *di = _di; in ab8500_charger_vbusovv_handler() local
2874 dev_dbg(di->dev, "VBUS overvoltage detected\n"); in ab8500_charger_vbusovv_handler()
2875 di->flags.vbus_ovv = true; in ab8500_charger_vbusovv_handler()
2876 ab8500_power_supply_changed(di, di->usb_chg.psy); in ab8500_charger_vbusovv_handler()
2879 queue_delayed_work(di->charger_wq, &di->check_hw_failure_work, 0); in ab8500_charger_vbusovv_handler()
2902 struct ab8500_charger *di; in ab8500_charger_ac_get_property() local
2905 di = to_ab8500_charger_ac_device_info(psy_to_ux500_charger(psy)); in ab8500_charger_ac_get_property()
2909 if (di->flags.mainextchnotok) in ab8500_charger_ac_get_property()
2911 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_ac_get_property()
2913 else if (di->flags.main_thermal_prot) in ab8500_charger_ac_get_property()
2919 val->intval = di->ac.charger_online; in ab8500_charger_ac_get_property()
2922 val->intval = di->ac.charger_connected; in ab8500_charger_ac_get_property()
2925 ret = ab8500_charger_get_ac_voltage(di); in ab8500_charger_ac_get_property()
2927 di->ac.charger_voltage = ret; in ab8500_charger_ac_get_property()
2929 val->intval = di->ac.charger_voltage * 1000; in ab8500_charger_ac_get_property()
2936 di->ac.cv_active = ab8500_charger_ac_cv(di); in ab8500_charger_ac_get_property()
2937 val->intval = di->ac.cv_active; in ab8500_charger_ac_get_property()
2940 ret = ab8500_charger_get_ac_current(di); in ab8500_charger_ac_get_property()
2942 di->ac.charger_current = ret; in ab8500_charger_ac_get_property()
2943 val->intval = di->ac.charger_current * 1000; in ab8500_charger_ac_get_property()
2969 struct ab8500_charger *di; in ab8500_charger_usb_get_property() local
2972 di = to_ab8500_charger_usb_device_info(psy_to_ux500_charger(psy)); in ab8500_charger_usb_get_property()
2976 if (di->flags.usbchargernotok) in ab8500_charger_usb_get_property()
2978 else if (di->ac.wd_expired || di->usb.wd_expired) in ab8500_charger_usb_get_property()
2980 else if (di->flags.usb_thermal_prot) in ab8500_charger_usb_get_property()
2982 else if (di->flags.vbus_ovv) in ab8500_charger_usb_get_property()
2988 val->intval = di->usb.charger_online; in ab8500_charger_usb_get_property()
2991 val->intval = di->usb.charger_connected; in ab8500_charger_usb_get_property()
2994 ret = ab8500_charger_get_vbus_voltage(di); in ab8500_charger_usb_get_property()
2996 di->usb.charger_voltage = ret; in ab8500_charger_usb_get_property()
2997 val->intval = di->usb.charger_voltage * 1000; in ab8500_charger_usb_get_property()
3004 di->usb.cv_active = ab8500_charger_usb_cv(di); in ab8500_charger_usb_get_property()
3005 val->intval = di->usb.cv_active; in ab8500_charger_usb_get_property()
3008 ret = ab8500_charger_get_usb_current(di); in ab8500_charger_usb_get_property()
3010 di->usb.charger_current = ret; in ab8500_charger_usb_get_property()
3011 val->intval = di->usb.charger_current * 1000; in ab8500_charger_usb_get_property()
3018 if (di->flags.vbus_collapse) in ab8500_charger_usb_get_property()
3036 static int ab8500_charger_init_hw_registers(struct ab8500_charger *di) in ab8500_charger_init_hw_registers() argument
3041 if (!is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_init_hw_registers()
3042 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3046 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3051 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3055 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3061 if (is_ab8505_2p0(di->parent)) in ab8500_charger_init_hw_registers()
3062 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3071 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3076 dev_err(di->dev, in ab8500_charger_init_hw_registers()
3082 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3085 dev_err(di->dev, "failed to enable main WD in OTP\n"); in ab8500_charger_init_hw_registers()
3090 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3094 dev_err(di->dev, "failed to enable main watchdog\n"); in ab8500_charger_init_hw_registers()
3107 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3112 dev_err(di->dev, "failed to kick main watchdog\n"); in ab8500_charger_init_hw_registers()
3117 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3121 dev_err(di->dev, "failed to disable main watchdog\n"); in ab8500_charger_init_hw_registers()
3126 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_init_hw_registers()
3129 dev_err(di->dev, "failed to set charger watchdog timeout\n"); in ab8500_charger_init_hw_registers()
3133 ret = ab8500_charger_led_en(di, false); in ab8500_charger_init_hw_registers()
3135 dev_err(di->dev, "failed to disable LED\n"); in ab8500_charger_init_hw_registers()
3139 ret = abx500_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3142 (di->bm->bkup_bat_v & 0x3) | di->bm->bkup_bat_i); in ab8500_charger_init_hw_registers()
3144 dev_err(di->dev, "failed to setup backup battery charging\n"); in ab8500_charger_init_hw_registers()
3149 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_init_hw_registers()
3153 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_init_hw_registers()
3184 struct ab8500_charger *di = in ab8500_charger_usb_notifier_call() local
3189 if (!di) in ab8500_charger_usb_notifier_call()
3193 dev_dbg(di->dev, "not a standard host, returning\n"); in ab8500_charger_usb_notifier_call()
3200 if ((di->usb_state.usb_current == 2) && (mA > 2)) in ab8500_charger_usb_notifier_call()
3211 dev_dbg(di->dev, "%s usb_state: 0x%02x mA: %d\n", in ab8500_charger_usb_notifier_call()
3214 spin_lock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3215 di->usb_state.state_tmp = bm_usb_state; in ab8500_charger_usb_notifier_call()
3216 di->usb_state.usb_current_tmp = mA; in ab8500_charger_usb_notifier_call()
3217 spin_unlock(&di->usb_state.usb_lock); in ab8500_charger_usb_notifier_call()
3223 queue_delayed_work(di->charger_wq, &di->usb_state_changed_work, HZ/2); in ab8500_charger_usb_notifier_call()
3232 struct ab8500_charger *di = platform_get_drvdata(pdev); in ab8500_charger_resume() local
3243 if (di->ac_conn && is_ab8500_1p1_or_earlier(di->parent)) { in ab8500_charger_resume()
3244 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, in ab8500_charger_resume()
3247 dev_err(di->dev, "Failed to kick WD!\n"); in ab8500_charger_resume()
3250 queue_delayed_work(di->charger_wq, &di->kick_wd_work, in ab8500_charger_resume()
3255 if (di->flags.mainextchnotok || di->flags.vbus_ovv) { in ab8500_charger_resume()
3256 queue_delayed_work(di->charger_wq, in ab8500_charger_resume()
3257 &di->check_hw_failure_work, 0); in ab8500_charger_resume()
3260 if (di->flags.vbus_drop_end) in ab8500_charger_resume()
3261 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, 0); in ab8500_charger_resume()
3269 struct ab8500_charger *di = platform_get_drvdata(pdev); in ab8500_charger_suspend() local
3272 cancel_delayed_work(&di->check_hw_failure_work); in ab8500_charger_suspend()
3273 cancel_delayed_work(&di->vbus_drop_end_work); in ab8500_charger_suspend()
3275 flush_delayed_work(&di->attach_work); in ab8500_charger_suspend()
3276 flush_delayed_work(&di->usb_charger_attached_work); in ab8500_charger_suspend()
3277 flush_delayed_work(&di->ac_charger_attached_work); in ab8500_charger_suspend()
3278 flush_delayed_work(&di->check_usbchgnotok_work); in ab8500_charger_suspend()
3279 flush_delayed_work(&di->check_vbat_work); in ab8500_charger_suspend()
3280 flush_delayed_work(&di->kick_wd_work); in ab8500_charger_suspend()
3282 flush_work(&di->usb_link_status_work); in ab8500_charger_suspend()
3283 flush_work(&di->ac_work); in ab8500_charger_suspend()
3284 flush_work(&di->detect_usb_type_work); in ab8500_charger_suspend()
3286 if (atomic_read(&di->current_stepping_sessions)) in ab8500_charger_suspend()
3302 struct ab8500_charger *di = platform_get_drvdata(pdev); in ab8500_charger_remove() local
3306 ab8500_charger_ac_en(&di->ac_chg, false, 0, 0); in ab8500_charger_remove()
3309 ab8500_charger_usb_en(&di->usb_chg, false, 0, 0); in ab8500_charger_remove()
3314 free_irq(irq, di); in ab8500_charger_remove()
3318 ret = abx500_mask_and_set_register_interruptible(di->dev, in ab8500_charger_remove()
3321 dev_err(di->dev, "%s mask and set failed\n", __func__); in ab8500_charger_remove()
3323 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_remove()
3324 usb_put_phy(di->usb_phy); in ab8500_charger_remove()
3327 destroy_workqueue(di->charger_wq); in ab8500_charger_remove()
3330 if (!di->ac_chg.enabled) in ab8500_charger_remove()
3335 if (di->usb_chg.enabled) in ab8500_charger_remove()
3336 power_supply_unregister(di->usb_chg.psy); in ab8500_charger_remove()
3338 if (di->ac_chg.enabled && !di->ac_chg.external) in ab8500_charger_remove()
3339 power_supply_unregister(di->ac_chg.psy); in ab8500_charger_remove()
3371 struct ab8500_charger *di; in ab8500_charger_probe() local
3374 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); in ab8500_charger_probe()
3375 if (!di) { in ab8500_charger_probe()
3384 di->bm = plat; in ab8500_charger_probe()
3387 ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm); in ab8500_charger_probe()
3392 di->autopower_cfg = of_property_read_bool(np, "autopower_cfg"); in ab8500_charger_probe()
3394 di->autopower_cfg = false; in ab8500_charger_probe()
3397 di->dev = &pdev->dev; in ab8500_charger_probe()
3398 di->parent = dev_get_drvdata(pdev->dev.parent); in ab8500_charger_probe()
3401 di->adc_main_charger_v = devm_iio_channel_get(&pdev->dev, in ab8500_charger_probe()
3403 if (IS_ERR(di->adc_main_charger_v)) { in ab8500_charger_probe()
3404 if (PTR_ERR(di->adc_main_charger_v) == -ENODEV) in ab8500_charger_probe()
3407 return PTR_ERR(di->adc_main_charger_v); in ab8500_charger_probe()
3409 di->adc_main_charger_c = devm_iio_channel_get(&pdev->dev, in ab8500_charger_probe()
3411 if (IS_ERR(di->adc_main_charger_c)) { in ab8500_charger_probe()
3412 if (PTR_ERR(di->adc_main_charger_c) == -ENODEV) in ab8500_charger_probe()
3415 return PTR_ERR(di->adc_main_charger_c); in ab8500_charger_probe()
3417 di->adc_vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); in ab8500_charger_probe()
3418 if (IS_ERR(di->adc_vbus_v)) { in ab8500_charger_probe()
3419 if (PTR_ERR(di->adc_vbus_v) == -ENODEV) in ab8500_charger_probe()
3422 return PTR_ERR(di->adc_vbus_v); in ab8500_charger_probe()
3424 di->adc_usb_charger_c = devm_iio_channel_get(&pdev->dev, in ab8500_charger_probe()
3426 if (IS_ERR(di->adc_usb_charger_c)) { in ab8500_charger_probe()
3427 if (PTR_ERR(di->adc_usb_charger_c) == -ENODEV) in ab8500_charger_probe()
3430 return PTR_ERR(di->adc_usb_charger_c); in ab8500_charger_probe()
3434 spin_lock_init(&di->usb_state.usb_lock); in ab8500_charger_probe()
3435 mutex_init(&di->usb_ipt_crnt_lock); in ab8500_charger_probe()
3437 di->autopower = false; in ab8500_charger_probe()
3438 di->invalid_charger_detect_state = 0; in ab8500_charger_probe()
3443 ac_psy_cfg.drv_data = &di->ac_chg; in ab8500_charger_probe()
3446 usb_psy_cfg.drv_data = &di->usb_chg; in ab8500_charger_probe()
3450 di->ac_chg.ops.enable = &ab8500_charger_ac_en; in ab8500_charger_probe()
3451 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable; in ab8500_charger_probe()
3452 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3453 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3454 di->ac_chg.max_out_volt = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3456 di->ac_chg.max_out_curr = in ab8500_charger_probe()
3457 di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1]; in ab8500_charger_probe()
3458 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3459 di->ac_chg.enabled = di->bm->ac_enabled; in ab8500_charger_probe()
3460 di->ac_chg.external = false; in ab8500_charger_probe()
3463 if (!di->ac_chg.enabled) in ab8500_charger_probe()
3469 di->usb_chg.ops.enable = &ab8500_charger_usb_en; in ab8500_charger_probe()
3470 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable; in ab8500_charger_probe()
3471 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; in ab8500_charger_probe()
3472 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current; in ab8500_charger_probe()
3473 di->usb_chg.max_out_volt = ab8500_charger_voltage_map[ in ab8500_charger_probe()
3475 di->usb_chg.max_out_curr = in ab8500_charger_probe()
3476 di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1]; in ab8500_charger_probe()
3477 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL; in ab8500_charger_probe()
3478 di->usb_chg.enabled = di->bm->usb_enabled; in ab8500_charger_probe()
3479 di->usb_chg.external = false; in ab8500_charger_probe()
3480 di->usb_state.usb_current = -1; in ab8500_charger_probe()
3483 di->charger_wq = alloc_ordered_workqueue("ab8500_charger_wq", in ab8500_charger_probe()
3485 if (di->charger_wq == NULL) { in ab8500_charger_probe()
3486 dev_err(di->dev, "failed to create work queue\n"); in ab8500_charger_probe()
3490 mutex_init(&di->charger_attached_mutex); in ab8500_charger_probe()
3493 INIT_DEFERRABLE_WORK(&di->check_hw_failure_work, in ab8500_charger_probe()
3495 INIT_DEFERRABLE_WORK(&di->check_usbchgnotok_work, in ab8500_charger_probe()
3498 INIT_DELAYED_WORK(&di->ac_charger_attached_work, in ab8500_charger_probe()
3500 INIT_DELAYED_WORK(&di->usb_charger_attached_work, in ab8500_charger_probe()
3512 INIT_DEFERRABLE_WORK(&di->kick_wd_work, in ab8500_charger_probe()
3515 INIT_DEFERRABLE_WORK(&di->check_vbat_work, in ab8500_charger_probe()
3518 INIT_DELAYED_WORK(&di->attach_work, in ab8500_charger_probe()
3521 INIT_DELAYED_WORK(&di->usb_state_changed_work, in ab8500_charger_probe()
3524 INIT_DELAYED_WORK(&di->vbus_drop_end_work, in ab8500_charger_probe()
3528 INIT_WORK(&di->usb_link_status_work, in ab8500_charger_probe()
3530 INIT_WORK(&di->ac_work, ab8500_charger_ac_work); in ab8500_charger_probe()
3531 INIT_WORK(&di->detect_usb_type_work, in ab8500_charger_probe()
3535 INIT_WORK(&di->check_main_thermal_prot_work, in ab8500_charger_probe()
3537 INIT_WORK(&di->check_usb_thermal_prot_work, in ab8500_charger_probe()
3545 di->regu = devm_regulator_get(di->dev, "vddadc"); in ab8500_charger_probe()
3546 if (IS_ERR(di->regu)) { in ab8500_charger_probe()
3547 ret = PTR_ERR(di->regu); in ab8500_charger_probe()
3548 dev_err(di->dev, "failed to get vddadc regulator\n"); in ab8500_charger_probe()
3554 ret = ab8500_charger_init_hw_registers(di); in ab8500_charger_probe()
3556 dev_err(di->dev, "failed to initialize ABB registers\n"); in ab8500_charger_probe()
3561 if (di->ac_chg.enabled) { in ab8500_charger_probe()
3562 di->ac_chg.psy = power_supply_register(di->dev, in ab8500_charger_probe()
3565 if (IS_ERR(di->ac_chg.psy)) { in ab8500_charger_probe()
3566 dev_err(di->dev, "failed to register AC charger\n"); in ab8500_charger_probe()
3567 ret = PTR_ERR(di->ac_chg.psy); in ab8500_charger_probe()
3573 if (di->usb_chg.enabled) { in ab8500_charger_probe()
3574 di->usb_chg.psy = power_supply_register(di->dev, in ab8500_charger_probe()
3577 if (IS_ERR(di->usb_chg.psy)) { in ab8500_charger_probe()
3578 dev_err(di->dev, "failed to register USB charger\n"); in ab8500_charger_probe()
3579 ret = PTR_ERR(di->usb_chg.psy); in ab8500_charger_probe()
3584 di->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); in ab8500_charger_probe()
3585 if (IS_ERR_OR_NULL(di->usb_phy)) { in ab8500_charger_probe()
3586 dev_err(di->dev, "failed to get usb transceiver\n"); in ab8500_charger_probe()
3590 di->nb.notifier_call = ab8500_charger_usb_notifier_call; in ab8500_charger_probe()
3591 ret = usb_register_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3593 dev_err(di->dev, "failed to register usb notifier\n"); in ab8500_charger_probe()
3598 charger_status = ab8500_charger_detect_chargers(di, true); in ab8500_charger_probe()
3600 di->ac.charger_connected = 1; in ab8500_charger_probe()
3601 di->ac_conn = true; in ab8500_charger_probe()
3602 ab8500_power_supply_changed(di, di->ac_chg.psy); in ab8500_charger_probe()
3603 sysfs_notify(&di->ac_chg.psy->dev.kobj, NULL, "present"); in ab8500_charger_probe()
3607 di->vbus_detected = true; in ab8500_charger_probe()
3608 di->vbus_detected_start = true; in ab8500_charger_probe()
3609 queue_work(di->charger_wq, in ab8500_charger_probe()
3610 &di->detect_usb_type_work); in ab8500_charger_probe()
3623 ab8500_charger_irq[i].name, di); in ab8500_charger_probe()
3626 dev_err(di->dev, "failed to request %s IRQ %d: %d\n" in ab8500_charger_probe()
3630 dev_dbg(di->dev, "Requested %s IRQ %d: %d\n", in ab8500_charger_probe()
3634 platform_set_drvdata(pdev, di); in ab8500_charger_probe()
3636 mutex_lock(&di->charger_attached_mutex); in ab8500_charger_probe()
3638 ch_stat = ab8500_charger_detect_chargers(di, false); in ab8500_charger_probe()
3641 if (is_ab8500(di->parent)) in ab8500_charger_probe()
3642 queue_delayed_work(di->charger_wq, in ab8500_charger_probe()
3643 &di->ac_charger_attached_work, in ab8500_charger_probe()
3647 if (is_ab8500(di->parent)) in ab8500_charger_probe()
3648 queue_delayed_work(di->charger_wq, in ab8500_charger_probe()
3649 &di->usb_charger_attached_work, in ab8500_charger_probe()
3653 mutex_unlock(&di->charger_attached_mutex); in ab8500_charger_probe()
3658 usb_unregister_notifier(di->usb_phy, &di->nb); in ab8500_charger_probe()
3663 free_irq(irq, di); in ab8500_charger_probe()
3666 usb_put_phy(di->usb_phy); in ab8500_charger_probe()
3668 if (di->usb_chg.enabled) in ab8500_charger_probe()
3669 power_supply_unregister(di->usb_chg.psy); in ab8500_charger_probe()
3671 if (di->ac_chg.enabled) in ab8500_charger_probe()
3672 power_supply_unregister(di->ac_chg.psy); in ab8500_charger_probe()
3674 destroy_workqueue(di->charger_wq); in ab8500_charger_probe()