aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorPaer-Olof Haakansson <par-olof.hakansson@stericsson.com>2012-02-22 13:07:51 -0500
committerLee Jones <lee.jones@linaro.org>2013-01-23 09:39:22 -0500
commit34c11a709e928090cf34ecd706f7d3170f4e5026 (patch)
tree63418834b4e102c8ebe4cafb8b878f2b357410e2 /drivers/power
parent97034a1e042d4316a83a3f68d61edf6c42e3f265 (diff)
u8500-charger: Delay for USB enumeration
If charging is started before USB enumeration of an Accessory Charger Adapter has finished, the AB8500 will generate a VBUS_ERROR. This in turn results in timeouts and delays the enumeration with around 15 seconds. This patch delays the charging and then ramps currents slowly to avoid VBUS errors. The delay allows the enumeration to have finished before charging is turned on. Signed-off-by: Martin Sjoblom <martin.w.sjoblom@stericsson.com> Signed-off-by: Lee Jones <lee.jones@linaro.org> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com> Tested-by: Jonas ABERG <jonas.aberg@stericsson.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/ab8500_charger.c432
1 files changed, 325 insertions, 107 deletions
diff --git a/drivers/power/ab8500_charger.c b/drivers/power/ab8500_charger.c
index 432f6bc48764..24b30b7ea5ca 100644
--- a/drivers/power/ab8500_charger.c
+++ b/drivers/power/ab8500_charger.c
@@ -55,6 +55,7 @@
55 55
56#define MAIN_CH_INPUT_CURR_SHIFT 4 56#define MAIN_CH_INPUT_CURR_SHIFT 4
57#define VBUS_IN_CURR_LIM_SHIFT 4 57#define VBUS_IN_CURR_LIM_SHIFT 4
58#define AUTO_VBUS_IN_CURR_LIM_SHIFT 4
58 59
59#define LED_INDICATOR_PWM_ENA 0x01 60#define LED_INDICATOR_PWM_ENA 0x01
60#define LED_INDICATOR_PWM_DIS 0x00 61#define LED_INDICATOR_PWM_DIS 0x00
@@ -88,14 +89,13 @@
88/* Step up/down delay in us */ 89/* Step up/down delay in us */
89#define STEP_UDELAY 1000 90#define STEP_UDELAY 1000
90 91
91/* Wait for enumeration before charging in ms */
92#define WAIT_FOR_USB_ENUMERATION 5 * 1000
93
94#define CHARGER_STATUS_POLL 10 /* in ms */ 92#define CHARGER_STATUS_POLL 10 /* in ms */
95 93
96#define CHG_WD_INTERVAL (60 * HZ) 94#define CHG_WD_INTERVAL (60 * HZ)
97 95
98#define AB8500_SW_CONTROL_FALLBACK 0x03 96#define AB8500_SW_CONTROL_FALLBACK 0x03
97/* Wait for enumeration before charing in us */
98#define WAIT_ACA_RID_ENUMERATION (5 * 1000)
99 99
100/* UsbLineStatus register - usb types */ 100/* UsbLineStatus register - usb types */
101enum ab8500_charger_link_status { 101enum ab8500_charger_link_status {
@@ -185,12 +185,14 @@ struct ab8500_charger_event_flags {
185 bool usbchargernotok; 185 bool usbchargernotok;
186 bool chgwdexp; 186 bool chgwdexp;
187 bool vbus_collapse; 187 bool vbus_collapse;
188 bool vbus_drop_end;
188}; 189};
189 190
190struct ab8500_charger_usb_state { 191struct ab8500_charger_usb_state {
191 bool usb_changed;
192 int usb_current; 192 int usb_current;
193 int usb_current_tmp;
193 enum ab8500_usb_state state; 194 enum ab8500_usb_state state;
195 enum ab8500_usb_state state_tmp;
194 spinlock_t usb_lock; 196 spinlock_t usb_lock;
195}; 197};
196 198
@@ -212,6 +214,10 @@ struct ab8500_charger_usb_state {
212 * @autopower Indicate if we should have automatic pwron after pwrloss 214 * @autopower Indicate if we should have automatic pwron after pwrloss
213 * @autopower_cfg platform specific power config support for "pwron after pwrloss" 215 * @autopower_cfg platform specific power config support for "pwron after pwrloss"
214 * @invalid_charger_detect_state State when forcing AB to use invalid charger 216 * @invalid_charger_detect_state State when forcing AB to use invalid charger
217 * @is_usb_host: Indicate if last detected USB type is host
218 * @is_aca_rid: Incicate if accessory is ACA type
219 * @current_stepping_sessions:
220 * Counter for current stepping sessions
215 * @parent: Pointer to the struct ab8500 221 * @parent: Pointer to the struct ab8500
216 * @gpadc: Pointer to the struct gpadc 222 * @gpadc: Pointer to the struct gpadc
217 * @bm: Platform specific battery management information 223 * @bm: Platform specific battery management information
@@ -223,12 +229,13 @@ struct ab8500_charger_usb_state {
223 * @usb: Structure that holds the USB charger properties 229 * @usb: Structure that holds the USB charger properties
224 * @regu: Pointer to the struct regulator 230 * @regu: Pointer to the struct regulator
225 * @charger_wq: Work queue for the IRQs and checking HW state 231 * @charger_wq: Work queue for the IRQs and checking HW state
232 * @usb_ipt_crnt_lock: Lock to protect VBUS input current setting from mutuals
233 * @pm_lock: Lock to prevent system to suspend
226 * @check_vbat_work Work for checking vbat threshold to adjust vbus current 234 * @check_vbat_work Work for checking vbat threshold to adjust vbus current
227 * @check_hw_failure_work: Work for checking HW state 235 * @check_hw_failure_work: Work for checking HW state
228 * @check_usbchgnotok_work: Work for checking USB charger not ok status 236 * @check_usbchgnotok_work: Work for checking USB charger not ok status
229 * @kick_wd_work: Work for kicking the charger watchdog in case 237 * @kick_wd_work: Work for kicking the charger watchdog in case
230 * of ABB rev 1.* due to the watchog logic bug 238 * of ABB rev 1.* due to the watchog logic bug
231 * @attach_work: Work for checking the usb enumeration
232 * @ac_charger_attached_work: Work for checking if AC charger is still 239 * @ac_charger_attached_work: Work for checking if AC charger is still
233 * connected 240 * connected
234 * @usb_charger_attached_work: Work for checking if USB charger is still 241 * @usb_charger_attached_work: Work for checking if USB charger is still
@@ -237,6 +244,8 @@ struct ab8500_charger_usb_state {
237 * @detect_usb_type_work: Work for detecting the USB type connected 244 * @detect_usb_type_work: Work for detecting the USB type connected
238 * @usb_link_status_work: Work for checking the new USB link status 245 * @usb_link_status_work: Work for checking the new USB link status
239 * @usb_state_changed_work: Work for checking USB state 246 * @usb_state_changed_work: Work for checking USB state
247 * @attach_work: Work for detecting USB type
248 * @vbus_drop_end_work: Work for detecting VBUS drop end
240 * @check_main_thermal_prot_work: 249 * @check_main_thermal_prot_work:
241 * Work for checking Main thermal status 250 * Work for checking Main thermal status
242 * @check_usb_thermal_prot_work: 251 * @check_usb_thermal_prot_work:
@@ -257,6 +266,9 @@ struct ab8500_charger {
257 bool autopower; 266 bool autopower;
258 bool autopower_cfg; 267 bool autopower_cfg;
259 int invalid_charger_detect_state; 268 int invalid_charger_detect_state;
269 bool is_usb_host;
270 int is_aca_rid;
271 atomic_t current_stepping_sessions;
260 struct ab8500 *parent; 272 struct ab8500 *parent;
261 struct ab8500_gpadc *gpadc; 273 struct ab8500_gpadc *gpadc;
262 struct abx500_bm_data *bm; 274 struct abx500_bm_data *bm;
@@ -268,17 +280,19 @@ struct ab8500_charger {
268 struct ab8500_charger_info usb; 280 struct ab8500_charger_info usb;
269 struct regulator *regu; 281 struct regulator *regu;
270 struct workqueue_struct *charger_wq; 282 struct workqueue_struct *charger_wq;
283 struct mutex usb_ipt_crnt_lock;
271 struct delayed_work check_vbat_work; 284 struct delayed_work check_vbat_work;
272 struct delayed_work check_hw_failure_work; 285 struct delayed_work check_hw_failure_work;
273 struct delayed_work check_usbchgnotok_work; 286 struct delayed_work check_usbchgnotok_work;
274 struct delayed_work kick_wd_work; 287 struct delayed_work kick_wd_work;
288 struct delayed_work usb_state_changed_work;
275 struct delayed_work attach_work; 289 struct delayed_work attach_work;
276 struct delayed_work ac_charger_attached_work; 290 struct delayed_work ac_charger_attached_work;
277 struct delayed_work usb_charger_attached_work; 291 struct delayed_work usb_charger_attached_work;
292 struct delayed_work vbus_drop_end_work;
278 struct work_struct ac_work; 293 struct work_struct ac_work;
279 struct work_struct detect_usb_type_work; 294 struct work_struct detect_usb_type_work;
280 struct work_struct usb_link_status_work; 295 struct work_struct usb_link_status_work;
281 struct work_struct usb_state_changed_work;
282 struct work_struct check_main_thermal_prot_work; 296 struct work_struct check_main_thermal_prot_work;
283 struct work_struct check_usb_thermal_prot_work; 297 struct work_struct check_usb_thermal_prot_work;
284 struct usb_phy *usb_phy; 298 struct usb_phy *usb_phy;
@@ -568,6 +582,7 @@ static int ab8500_charger_usb_cv(struct ab8500_charger *di)
568/** 582/**
569 * ab8500_charger_detect_chargers() - Detect the connected chargers 583 * ab8500_charger_detect_chargers() - Detect the connected chargers
570 * @di: pointer to the ab8500_charger structure 584 * @di: pointer to the ab8500_charger structure
585 * @probe: if probe, don't delay and wait for HW
571 * 586 *
572 * Returns the type of charger connected. 587 * Returns the type of charger connected.
573 * For USB it will not mean we can actually charge from it 588 * For USB it will not mean we can actually charge from it
@@ -581,7 +596,7 @@ static int ab8500_charger_usb_cv(struct ab8500_charger *di)
581 * USB_PW_CONN if the USB power supply is connected 596 * USB_PW_CONN if the USB power supply is connected
582 * AC_PW_CONN + USB_PW_CONN if USB and AC power supplies are both connected 597 * AC_PW_CONN + USB_PW_CONN if USB and AC power supplies are both connected
583 */ 598 */
584static int ab8500_charger_detect_chargers(struct ab8500_charger *di) 599static int ab8500_charger_detect_chargers(struct ab8500_charger *di, bool probe)
585{ 600{
586 int result = NO_PW_CONN; 601 int result = NO_PW_CONN;
587 int ret; 602 int ret;
@@ -599,13 +614,25 @@ static int ab8500_charger_detect_chargers(struct ab8500_charger *di)
599 result = AC_PW_CONN; 614 result = AC_PW_CONN;
600 615
601 /* Check for USB charger */ 616 /* Check for USB charger */
617
618 if (!probe) {
619 /*
620 * AB8500 says VBUS_DET_DBNC1 & VBUS_DET_DBNC100
621 * when disconnecting ACA even though no
622 * charger was connected. Try waiting a little
623 * longer than the 100 ms of VBUS_DET_DBNC100...
624 */
625 msleep(110);
626 }
602 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER, 627 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
603 AB8500_CH_USBCH_STAT1_REG, &val); 628 AB8500_CH_USBCH_STAT1_REG, &val);
604 if (ret < 0) { 629 if (ret < 0) {
605 dev_err(di->dev, "%s ab8500 read failed\n", __func__); 630 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
606 return ret; 631 return ret;
607 } 632 }
608 633 dev_dbg(di->dev,
634 "%s AB8500_CH_USBCH_STAT1_REG %x\n", __func__,
635 val);
609 if ((val & VBUS_DET_DBNC1) && (val & VBUS_DET_DBNC100)) 636 if ((val & VBUS_DET_DBNC1) && (val & VBUS_DET_DBNC100))
610 result |= USB_PW_CONN; 637 result |= USB_PW_CONN;
611 638
@@ -628,33 +655,47 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
628 655
629 di->usb_device_is_unrecognised = false; 656 di->usb_device_is_unrecognised = false;
630 657
658 /*
659 * Platform only supports USB 2.0.
660 * This means that charging current from USB source
661 * is maximum 500 mA. Every occurence of USB_STAT_*_HOST_*
662 * should set USB_CH_IP_CUR_LVL_0P5.
663 */
664
631 switch (link_status) { 665 switch (link_status) {
632 case USB_STAT_STD_HOST_NC: 666 case USB_STAT_STD_HOST_NC:
633 case USB_STAT_STD_HOST_C_NS: 667 case USB_STAT_STD_HOST_C_NS:
634 case USB_STAT_STD_HOST_C_S: 668 case USB_STAT_STD_HOST_C_S:
635 dev_dbg(di->dev, "USB Type - Standard host is " 669 dev_dbg(di->dev, "USB Type - Standard host is "
636 "detected through USB driver\n"); 670 "detected through USB driver\n");
637 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P09; 671 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
672 di->is_usb_host = true;
673 di->is_aca_rid = 0;
638 break; 674 break;
639 case USB_STAT_HOST_CHG_HS_CHIRP: 675 case USB_STAT_HOST_CHG_HS_CHIRP:
640 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5; 676 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
641 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 677 di->is_usb_host = true;
642 di->max_usb_in_curr); 678 di->is_aca_rid = 0;
643 break; 679 break;
644 case USB_STAT_HOST_CHG_HS: 680 case USB_STAT_HOST_CHG_HS:
681 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
682 di->is_usb_host = true;
683 di->is_aca_rid = 0;
684 break;
645 case USB_STAT_ACA_RID_C_HS: 685 case USB_STAT_ACA_RID_C_HS:
646 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P9; 686 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P9;
647 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 687 di->is_usb_host = false;
648 di->max_usb_in_curr); 688 di->is_aca_rid = 0;
649 break; 689 break;
650 case USB_STAT_ACA_RID_A: 690 case USB_STAT_ACA_RID_A:
651 /* 691 /*
652 * Dedicated charger level minus maximum current accessory 692 * Dedicated charger level minus maximum current accessory
653 * can consume (300mA). Closest level is 1100mA 693 * can consume (900mA). Closest level is 500mA
654 */ 694 */
655 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P1; 695 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n");
656 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 696 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
657 di->max_usb_in_curr); 697 di->is_usb_host = false;
698 di->is_aca_rid = 1;
658 break; 699 break;
659 case USB_STAT_ACA_RID_B: 700 case USB_STAT_ACA_RID_B:
660 /* 701 /*
@@ -664,14 +705,24 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,
664 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P3; 705 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P3;
665 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 706 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status,
666 di->max_usb_in_curr); 707 di->max_usb_in_curr);
708 di->is_usb_host = false;
709 di->is_aca_rid = 1;
667 break; 710 break;
668 case USB_STAT_HOST_CHG_NM: 711 case USB_STAT_HOST_CHG_NM:
712 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_0P5;
713 di->is_usb_host = true;
714 di->is_aca_rid = 0;
715 break;
669 case USB_STAT_DEDICATED_CHG: 716 case USB_STAT_DEDICATED_CHG:
670 case USB_STAT_ACA_RID_C_NM: 717 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5;
718 di->is_usb_host = false;
719 di->is_aca_rid = 0;
720 break;
671 case USB_STAT_ACA_RID_C_HS_CHIRP: 721 case USB_STAT_ACA_RID_C_HS_CHIRP:
722 case USB_STAT_ACA_RID_C_NM:
672 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5; 723 di->max_usb_in_curr = USB_CH_IP_CUR_LVL_1P5;
673 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 724 di->is_usb_host = false;
674 di->max_usb_in_curr); 725 di->is_aca_rid = 1;
675 break; 726 break;
676 case USB_STAT_NOT_CONFIGURED: 727 case USB_STAT_NOT_CONFIGURED:
677 if (di->vbus_detected) { 728 if (di->vbus_detected) {
@@ -788,6 +839,8 @@ static int ab8500_charger_detect_usb_type(struct ab8500_charger *di)
788 ret = abx500_get_register_interruptible(di->dev, 839 ret = abx500_get_register_interruptible(di->dev,
789 AB8500_INTERRUPT, AB8500_IT_SOURCE21_REG, 840 AB8500_INTERRUPT, AB8500_IT_SOURCE21_REG,
790 &val); 841 &val);
842 dev_dbg(di->dev, "%s AB8500_IT_SOURCE21_REG %x\n",
843 __func__, val);
791 if (ret < 0) { 844 if (ret < 0) {
792 dev_err(di->dev, "%s ab8500 read failed\n", __func__); 845 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
793 return ret; 846 return ret;
@@ -803,6 +856,8 @@ static int ab8500_charger_detect_usb_type(struct ab8500_charger *di)
803 dev_err(di->dev, "%s ab8500 read failed\n", __func__); 856 dev_err(di->dev, "%s ab8500 read failed\n", __func__);
804 return ret; 857 return ret;
805 } 858 }
859 dev_dbg(di->dev, "%s AB8500_USB_LINE_STAT_REG %x\n", __func__,
860 val);
806 /* 861 /*
807 * Until the IT source register is read the UsbLineStatus 862 * Until the IT source register is read the UsbLineStatus
808 * register is not updated, hence doing the same 863 * register is not updated, hence doing the same
@@ -1062,69 +1117,125 @@ static int ab8500_charger_get_usb_cur(struct ab8500_charger *di)
1062static int ab8500_charger_set_current(struct ab8500_charger *di, 1117static int ab8500_charger_set_current(struct ab8500_charger *di,
1063 int ich, int reg) 1118 int ich, int reg)
1064{ 1119{
1065 int ret, i; 1120 int ret = 0;
1066 int curr_index, prev_curr_index, shift_value; 1121 int auto_curr_index, curr_index, prev_curr_index, shift_value, i;
1067 u8 reg_value; 1122 u8 reg_value;
1123 u32 step_udelay;
1124 bool no_stepping = false;
1125
1126 atomic_inc(&di->current_stepping_sessions);
1127
1128 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1129 reg, &reg_value);
1130 if (ret < 0) {
1131 dev_err(di->dev, "%s read failed\n", __func__);
1132 goto exit_set_current;
1133 }
1068 1134
1069 switch (reg) { 1135 switch (reg) {
1070 case AB8500_MCH_IPT_CURLVL_REG: 1136 case AB8500_MCH_IPT_CURLVL_REG:
1071 shift_value = MAIN_CH_INPUT_CURR_SHIFT; 1137 shift_value = MAIN_CH_INPUT_CURR_SHIFT;
1138 prev_curr_index = (reg_value >> shift_value);
1072 curr_index = ab8500_current_to_regval(ich); 1139 curr_index = ab8500_current_to_regval(ich);
1140 step_udelay = STEP_UDELAY;
1141 if (!di->ac.charger_connected)
1142 no_stepping = true;
1073 break; 1143 break;
1074 case AB8500_USBCH_IPT_CRNTLVL_REG: 1144 case AB8500_USBCH_IPT_CRNTLVL_REG:
1075 shift_value = VBUS_IN_CURR_LIM_SHIFT; 1145 shift_value = VBUS_IN_CURR_LIM_SHIFT;
1146 prev_curr_index = (reg_value >> shift_value);
1076 curr_index = ab8500_vbus_in_curr_to_regval(ich); 1147 curr_index = ab8500_vbus_in_curr_to_regval(ich);
1148 step_udelay = STEP_UDELAY * 100;
1149
1150 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1151 AB8500_CH_USBCH_STAT2_REG, &reg_value);
1152 if (ret < 0) {
1153 dev_err(di->dev, "%s read failed\n", __func__);
1154 goto exit_set_current;
1155 }
1156 auto_curr_index =
1157 reg_value >> AUTO_VBUS_IN_CURR_LIM_SHIFT;
1158
1159 dev_dbg(di->dev, "%s Auto VBUS curr is %d mA\n",
1160 __func__,
1161 ab8500_charger_vbus_in_curr_map[auto_curr_index]);
1162
1163 prev_curr_index = min(prev_curr_index, auto_curr_index);
1164
1165 if (!di->usb.charger_connected)
1166 no_stepping = true;
1077 break; 1167 break;
1078 case AB8500_CH_OPT_CRNTLVL_REG: 1168 case AB8500_CH_OPT_CRNTLVL_REG:
1079 shift_value = 0; 1169 shift_value = 0;
1170 prev_curr_index = (reg_value >> shift_value);
1080 curr_index = ab8500_current_to_regval(ich); 1171 curr_index = ab8500_current_to_regval(ich);
1172 step_udelay = STEP_UDELAY;
1173 if (curr_index && (curr_index - prev_curr_index) > 1)
1174 step_udelay *= 100;
1175
1176 if (!di->usb.charger_connected && !di->ac.charger_connected)
1177 no_stepping = true;
1178
1081 break; 1179 break;
1082 default: 1180 default:
1083 dev_err(di->dev, "%s current register not valid\n", __func__); 1181 dev_err(di->dev, "%s current register not valid\n", __func__);
1084 return -ENXIO; 1182 ret = -ENXIO;
1183 goto exit_set_current;
1085 } 1184 }
1086 1185
1087 if (curr_index < 0) { 1186 if (curr_index < 0) {
1088 dev_err(di->dev, "requested current limit out-of-range\n"); 1187 dev_err(di->dev, "requested current limit out-of-range\n");
1089 return -ENXIO; 1188 ret = -ENXIO;
1090 } 1189 goto exit_set_current;
1091
1092 ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
1093 reg, &reg_value);
1094 if (ret < 0) {
1095 dev_err(di->dev, "%s read failed\n", __func__);
1096 return ret;
1097 } 1190 }
1098 prev_curr_index = (reg_value >> shift_value);
1099 1191
1100 /* only update current if it's been changed */ 1192 /* only update current if it's been changed */
1101 if (prev_curr_index == curr_index) 1193 if (prev_curr_index == curr_index) {
1102 return 0; 1194 dev_dbg(di->dev, "%s current not changed for reg: 0x%02x\n",
1195 __func__, reg);
1196 ret = 0;
1197 goto exit_set_current;
1198 }
1103 1199
1104 dev_dbg(di->dev, "%s set charger current: %d mA for reg: 0x%02x\n", 1200 dev_dbg(di->dev, "%s set charger current: %d mA for reg: 0x%02x\n",
1105 __func__, ich, reg); 1201 __func__, ich, reg);
1106 1202
1107 if (prev_curr_index > curr_index) { 1203 if (no_stepping) {
1204 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1205 reg, (u8)curr_index << shift_value);
1206 if (ret)
1207 dev_err(di->dev, "%s write failed\n", __func__);
1208 } else if (prev_curr_index > curr_index) {
1108 for (i = prev_curr_index - 1; i >= curr_index; i--) { 1209 for (i = prev_curr_index - 1; i >= curr_index; i--) {
1210 dev_dbg(di->dev, "curr change_1 to: %x for 0x%02x\n",
1211 (u8) i << shift_value, reg);
1109 ret = abx500_set_register_interruptible(di->dev, 1212 ret = abx500_set_register_interruptible(di->dev,
1110 AB8500_CHARGER, reg, (u8) i << shift_value); 1213 AB8500_CHARGER, reg, (u8)i << shift_value);
1111 if (ret) { 1214 if (ret) {
1112 dev_err(di->dev, "%s write failed\n", __func__); 1215 dev_err(di->dev, "%s write failed\n", __func__);
1113 return ret; 1216 goto exit_set_current;
1114 } 1217 }
1115 usleep_range(STEP_UDELAY, STEP_UDELAY * 2); 1218 if (i != curr_index)
1219 usleep_range(step_udelay, step_udelay * 2);
1116 } 1220 }
1117 } else { 1221 } else {
1118 for (i = prev_curr_index + 1; i <= curr_index; i++) { 1222 for (i = prev_curr_index + 1; i <= curr_index; i++) {
1223 dev_dbg(di->dev, "curr change_2 to: %x for 0x%02x\n",
1224 (u8)i << shift_value, reg);
1119 ret = abx500_set_register_interruptible(di->dev, 1225 ret = abx500_set_register_interruptible(di->dev,
1120 AB8500_CHARGER, reg, (u8) i << shift_value); 1226 AB8500_CHARGER, reg, (u8)i << shift_value);
1121 if (ret) { 1227 if (ret) {
1122 dev_err(di->dev, "%s write failed\n", __func__); 1228 dev_err(di->dev, "%s write failed\n", __func__);
1123 return ret; 1229 goto exit_set_current;
1124 } 1230 }
1125 usleep_range(STEP_UDELAY, STEP_UDELAY * 2); 1231 if (i != curr_index)
1232 usleep_range(step_udelay, step_udelay * 2);
1126 } 1233 }
1127 } 1234 }
1235
1236exit_set_current:
1237 atomic_dec(&di->current_stepping_sessions);
1238
1128 return ret; 1239 return ret;
1129} 1240}
1130 1241
@@ -1140,6 +1251,7 @@ static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di,
1140 int ich_in) 1251 int ich_in)
1141{ 1252{
1142 int min_value; 1253 int min_value;
1254 int ret;
1143 1255
1144 /* We should always use to lowest current limit */ 1256 /* We should always use to lowest current limit */
1145 min_value = min(di->bm->chg_params->usb_curr_max, ich_in); 1257 min_value = min(di->bm->chg_params->usb_curr_max, ich_in);
@@ -1157,8 +1269,14 @@ static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di,
1157 break; 1269 break;
1158 } 1270 }
1159 1271
1160 return ab8500_charger_set_current(di, min_value, 1272 dev_info(di->dev, "VBUS input current limit set to %d mA\n", min_value);
1273
1274 mutex_lock(&di->usb_ipt_crnt_lock);
1275 ret = ab8500_charger_set_current(di, min_value,
1161 AB8500_USBCH_IPT_CRNTLVL_REG); 1276 AB8500_USBCH_IPT_CRNTLVL_REG);
1277 mutex_unlock(&di->usb_ipt_crnt_lock);
1278
1279 return ret;
1162} 1280}
1163 1281
1164/** 1282/**
@@ -1469,25 +1587,13 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1469 dev_err(di->dev, "%s write failed\n", __func__); 1587 dev_err(di->dev, "%s write failed\n", __func__);
1470 return ret; 1588 return ret;
1471 } 1589 }
1472 /* USBChInputCurr: current that can be drawn from the usb */
1473 ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr);
1474 if (ret) {
1475 dev_err(di->dev, "setting USBChInputCurr failed\n");
1476 return ret;
1477 }
1478 /* ChOutputCurentLevel: protected output current */
1479 ret = ab8500_charger_set_output_curr(di, ich_out);
1480 if (ret) {
1481 dev_err(di->dev, "%s "
1482 "Failed to set ChOutputCurentLevel\n",
1483 __func__);
1484 return ret;
1485 }
1486 /* Check if VBAT overshoot control should be enabled */ 1590 /* Check if VBAT overshoot control should be enabled */
1487 if (!di->bm->enable_overshoot) 1591 if (!di->bm->enable_overshoot)
1488 overshoot = USB_CHG_NO_OVERSHOOT_ENA_N; 1592 overshoot = USB_CHG_NO_OVERSHOOT_ENA_N;
1489 1593
1490 /* Enable USB Charger */ 1594 /* Enable USB Charger */
1595 dev_dbg(di->dev,
1596 "Enabling USB with write to AB8500_USBCH_CTRL1_REG\n");
1491 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, 1597 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
1492 AB8500_USBCH_CTRL1_REG, USB_CH_ENA | overshoot); 1598 AB8500_USBCH_CTRL1_REG, USB_CH_ENA | overshoot);
1493 if (ret) { 1599 if (ret) {
@@ -1500,11 +1606,29 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1500 if (ret < 0) 1606 if (ret < 0)
1501 dev_err(di->dev, "failed to enable LED\n"); 1607 dev_err(di->dev, "failed to enable LED\n");
1502 1608
1609 di->usb.charger_online = 1;
1610
1611 /* USBChInputCurr: current that can be drawn from the usb */
1612 ret = ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr);
1613 if (ret) {
1614 dev_err(di->dev, "setting USBChInputCurr failed\n");
1615 return ret;
1616 }
1617
1618 /* ChOutputCurentLevel: protected output current */
1619 ret = ab8500_charger_set_output_curr(di, ich_out);
1620 if (ret) {
1621 dev_err(di->dev, "%s "
1622 "Failed to set ChOutputCurentLevel\n",
1623 __func__);
1624 return ret;
1625 }
1626
1503 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ); 1627 queue_delayed_work(di->charger_wq, &di->check_vbat_work, HZ);
1504 1628
1505 di->usb.charger_online = 1;
1506 } else { 1629 } else {
1507 /* Disable USB charging */ 1630 /* Disable USB charging */
1631 dev_dbg(di->dev, "%s Disabled USB charging\n", __func__);
1508 ret = abx500_set_register_interruptible(di->dev, 1632 ret = abx500_set_register_interruptible(di->dev,
1509 AB8500_CHARGER, 1633 AB8500_CHARGER,
1510 AB8500_USBCH_CTRL1_REG, 0); 1634 AB8500_USBCH_CTRL1_REG, 0);
@@ -1517,7 +1641,21 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
1517 ret = ab8500_charger_led_en(di, false); 1641 ret = ab8500_charger_led_en(di, false);
1518 if (ret < 0) 1642 if (ret < 0)
1519 dev_err(di->dev, "failed to disable LED\n"); 1643 dev_err(di->dev, "failed to disable LED\n");
1644 /* USBChInputCurr: current that can be drawn from the usb */
1645 ret = ab8500_charger_set_vbus_in_curr(di, 0);
1646 if (ret) {
1647 dev_err(di->dev, "setting USBChInputCurr failed\n");
1648 return ret;
1649 }
1520 1650
1651 /* ChOutputCurentLevel: protected output current */
1652 ret = ab8500_charger_set_output_curr(di, 0);
1653 if (ret) {
1654 dev_err(di->dev, "%s "
1655 "Failed to reset ChOutputCurentLevel\n",
1656 __func__);
1657 return ret;
1658 }
1521 di->usb.charger_online = 0; 1659 di->usb.charger_online = 0;
1522 di->usb.wd_expired = false; 1660 di->usb.wd_expired = false;
1523 1661
@@ -1800,7 +1938,7 @@ static void ab8500_charger_ac_work(struct work_struct *work)
1800 * synchronously, we have the check if the main charger is 1938 * synchronously, we have the check if the main charger is
1801 * connected by reading the status register 1939 * connected by reading the status register
1802 */ 1940 */
1803 ret = ab8500_charger_detect_chargers(di); 1941 ret = ab8500_charger_detect_chargers(di, false);
1804 if (ret < 0) 1942 if (ret < 0)
1805 return; 1943 return;
1806 1944
@@ -1911,16 +2049,18 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
1911 * synchronously, we have the check if is 2049 * synchronously, we have the check if is
1912 * connected by reading the status register 2050 * connected by reading the status register
1913 */ 2051 */
1914 ret = ab8500_charger_detect_chargers(di); 2052 ret = ab8500_charger_detect_chargers(di, false);
1915 if (ret < 0) 2053 if (ret < 0)
1916 return; 2054 return;
1917 2055
1918 if (!(ret & USB_PW_CONN)) { 2056 if (!(ret & USB_PW_CONN)) {
1919 di->vbus_detected = 0; 2057 dev_dbg(di->dev, "%s di->vbus_detected = false\n", __func__);
2058 di->vbus_detected = false;
1920 ab8500_charger_set_usb_connected(di, false); 2059 ab8500_charger_set_usb_connected(di, false);
1921 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2060 ab8500_power_supply_changed(di, &di->usb_chg.psy);
1922 } else { 2061 } else {
1923 di->vbus_detected = 1; 2062 dev_dbg(di->dev, "%s di->vbus_detected = true\n", __func__);
2063 di->vbus_detected = true;
1924 2064
1925 if (is_ab8500_1p1_or_earlier(di->parent)) { 2065 if (is_ab8500_1p1_or_earlier(di->parent)) {
1926 ret = ab8500_charger_detect_usb_type(di); 2066 ret = ab8500_charger_detect_usb_type(di);
@@ -1930,7 +2070,8 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
1930 &di->usb_chg.psy); 2070 &di->usb_chg.psy);
1931 } 2071 }
1932 } else { 2072 } else {
1933 /* For ABB cut2.0 and onwards we have an IRQ, 2073 /*
2074 * For ABB cut2.0 and onwards we have an IRQ,
1934 * USB_LINK_STATUS that will be triggered when the USB 2075 * USB_LINK_STATUS that will be triggered when the USB
1935 * link status changes. The exception is USB connected 2076 * link status changes. The exception is USB connected
1936 * during startup. Then we don't get a 2077 * during startup. Then we don't get a
@@ -1951,7 +2092,7 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work)
1951} 2092}
1952 2093
1953/** 2094/**
1954 * ab8500_charger_usb_link_attach_work() - delayd work to detect USB type 2095 * ab8500_charger_usb_link_attach_work() - work to detect USB type
1955 * @work: pointer to the work_struct structure 2096 * @work: pointer to the work_struct structure
1956 * 2097 *
1957 * Detect the type of USB plugged 2098 * Detect the type of USB plugged
@@ -1993,7 +2134,7 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
1993 * synchronously, we have the check if is 2134 * synchronously, we have the check if is
1994 * connected by reading the status register 2135 * connected by reading the status register
1995 */ 2136 */
1996 detected_chargers = ab8500_charger_detect_chargers(di); 2137 detected_chargers = ab8500_charger_detect_chargers(di, false);
1997 if (detected_chargers < 0) 2138 if (detected_chargers < 0)
1998 return; 2139 return;
1999 2140
@@ -2042,32 +2183,46 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work)
2042 } 2183 }
2043 2184
2044 if (!(detected_chargers & USB_PW_CONN)) { 2185 if (!(detected_chargers & USB_PW_CONN)) {
2045 di->vbus_detected = 0; 2186 di->vbus_detected = false;
2046 ab8500_charger_set_usb_connected(di, false); 2187 ab8500_charger_set_usb_connected(di, false);
2047 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2188 ab8500_power_supply_changed(di, &di->usb_chg.psy);
2048 return; 2189 return;
2049 } 2190 }
2050 2191
2051 di->vbus_detected = 1; 2192 dev_dbg(di->dev,"%s di->vbus_detected = true\n",__func__);
2193 di->vbus_detected = true;
2052 ret = ab8500_charger_read_usb_type(di); 2194 ret = ab8500_charger_read_usb_type(di);
2053 if (!ret) { 2195 if (ret) {
2054 if (di->usb_device_is_unrecognised) { 2196 if (ret == -ENXIO) {
2055 dev_dbg(di->dev, 2197 /* No valid charger type detected */
2056 "Potential Legacy Charger device. " 2198 ab8500_charger_set_usb_connected(di, false);
2057 "Delay work for %d msec for USB enum " 2199 ab8500_power_supply_changed(di, &di->usb_chg.psy);
2058 "to finish",
2059 WAIT_FOR_USB_ENUMERATION);
2060 queue_delayed_work(di->charger_wq,
2061 &di->attach_work,
2062 msecs_to_jiffies(WAIT_FOR_USB_ENUMERATION));
2063 } else {
2064 queue_delayed_work(di->charger_wq,
2065 &di->attach_work, 0);
2066 } 2200 }
2067 } else if (ret == -ENXIO) { 2201 return;
2068 /* No valid charger type detected */ 2202 }
2069 ab8500_charger_set_usb_connected(di, false); 2203
2070 ab8500_power_supply_changed(di, &di->usb_chg.psy); 2204 if (di->usb_device_is_unrecognised) {
2205 dev_dbg(di->dev,
2206 "Potential Legacy Charger device. "
2207 "Delay work for %d msec for USB enum "
2208 "to finish",
2209 WAIT_ACA_RID_ENUMERATION);
2210 queue_delayed_work(di->charger_wq,
2211 &di->attach_work,
2212 msecs_to_jiffies(WAIT_ACA_RID_ENUMERATION));
2213 } else if (di->is_aca_rid == 1) {
2214 /* Only wait once */
2215 di->is_aca_rid++;
2216 dev_dbg(di->dev,
2217 "%s Wait %d msec for USB enum to finish",
2218 __func__, WAIT_ACA_RID_ENUMERATION);
2219 queue_delayed_work(di->charger_wq,
2220 &di->attach_work,
2221 msecs_to_jiffies(WAIT_ACA_RID_ENUMERATION));
2222 } else {
2223 queue_delayed_work(di->charger_wq,
2224 &di->attach_work,
2225 0);
2071 } 2226 }
2072} 2227}
2073 2228
@@ -2077,24 +2232,20 @@ static void ab8500_charger_usb_state_changed_work(struct work_struct *work)
2077 unsigned long flags; 2232 unsigned long flags;
2078 2233
2079 struct ab8500_charger *di = container_of(work, 2234 struct ab8500_charger *di = container_of(work,
2080 struct ab8500_charger, usb_state_changed_work); 2235 struct ab8500_charger, usb_state_changed_work.work);
2081 2236
2082 if (!di->vbus_detected) 2237 if (!di->vbus_detected) {
2238 dev_dbg(di->dev,
2239 "%s !di->vbus_detected\n",
2240 __func__);
2083 return; 2241 return;
2242 }
2084 2243
2085 spin_lock_irqsave(&di->usb_state.usb_lock, flags); 2244 spin_lock_irqsave(&di->usb_state.usb_lock, flags);
2086 di->usb_state.usb_changed = false; 2245 di->usb_state.state = di->usb_state.state_tmp;
2246 di->usb_state.usb_current = di->usb_state.usb_current_tmp;
2087 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags); 2247 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags);
2088 2248
2089 /*
2090 * wait for some time until you get updates from the usb stack
2091 * and negotiations are completed
2092 */
2093 msleep(250);
2094
2095 if (di->usb_state.usb_changed)
2096 return;
2097
2098 dev_dbg(di->dev, "%s USB state: 0x%02x mA: %d\n", 2249 dev_dbg(di->dev, "%s USB state: 0x%02x mA: %d\n",
2099 __func__, di->usb_state.state, di->usb_state.usb_current); 2250 __func__, di->usb_state.state, di->usb_state.usb_current);
2100 2251
@@ -2336,6 +2487,21 @@ static irqreturn_t ab8500_charger_mainchthprotf_handler(int irq, void *_di)
2336 return IRQ_HANDLED; 2487 return IRQ_HANDLED;
2337} 2488}
2338 2489
2490static void ab8500_charger_vbus_drop_end_work(struct work_struct *work)
2491{
2492 struct ab8500_charger *di = container_of(work,
2493 struct ab8500_charger, vbus_drop_end_work.work);
2494
2495 di->flags.vbus_drop_end = false;
2496
2497 /* Reset the drop counter */
2498 abx500_set_register_interruptible(di->dev,
2499 AB8500_CHARGER, AB8500_CHARGER_CTRL, 0x01);
2500
2501 if (di->usb.charger_connected)
2502 ab8500_charger_set_vbus_in_curr(di, di->max_usb_in_curr);
2503}
2504
2339/** 2505/**
2340 * ab8500_charger_vbusdetf_handler() - VBUS falling detected 2506 * ab8500_charger_vbusdetf_handler() - VBUS falling detected
2341 * @irq: interrupt number 2507 * @irq: interrupt number
@@ -2347,6 +2513,7 @@ static irqreturn_t ab8500_charger_vbusdetf_handler(int irq, void *_di)
2347{ 2513{
2348 struct ab8500_charger *di = _di; 2514 struct ab8500_charger *di = _di;
2349 2515
2516 di->vbus_detected = false;
2350 dev_dbg(di->dev, "VBUS falling detected\n"); 2517 dev_dbg(di->dev, "VBUS falling detected\n");
2351 queue_work(di->charger_wq, &di->detect_usb_type_work); 2518 queue_work(di->charger_wq, &di->detect_usb_type_work);
2352 2519
@@ -2366,6 +2533,7 @@ static irqreturn_t ab8500_charger_vbusdetr_handler(int irq, void *_di)
2366 2533
2367 di->vbus_detected = true; 2534 di->vbus_detected = true;
2368 dev_dbg(di->dev, "VBUS rising detected\n"); 2535 dev_dbg(di->dev, "VBUS rising detected\n");
2536
2369 queue_work(di->charger_wq, &di->detect_usb_type_work); 2537 queue_work(di->charger_wq, &di->detect_usb_type_work);
2370 2538
2371 return IRQ_HANDLED; 2539 return IRQ_HANDLED;
@@ -2474,6 +2642,25 @@ static irqreturn_t ab8500_charger_chwdexp_handler(int irq, void *_di)
2474} 2642}
2475 2643
2476/** 2644/**
2645 * ab8500_charger_vbuschdropend_handler() - VBUS drop removed
2646 * @irq: interrupt number
2647 * @_di: pointer to the ab8500_charger structure
2648 *
2649 * Returns IRQ status(IRQ_HANDLED)
2650 */
2651static irqreturn_t ab8500_charger_vbuschdropend_handler(int irq, void *_di)
2652{
2653 struct ab8500_charger *di = _di;
2654
2655 dev_dbg(di->dev, "VBUS charger drop ended\n");
2656 di->flags.vbus_drop_end = true;
2657 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work,
2658 round_jiffies(30 * HZ));
2659
2660 return IRQ_HANDLED;
2661}
2662
2663/**
2477 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected 2664 * ab8500_charger_vbusovv_handler() - VBUS overvoltage detected
2478 * @irq: interrupt number 2665 * @irq: interrupt number
2479 * @_di: pointer to the ab8500_charger structure 2666 * @_di: pointer to the ab8500_charger structure
@@ -2743,6 +2930,20 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
2743 goto out; 2930 goto out;
2744 } 2931 }
2745 2932
2933 /* Set charger watchdog timeout */
2934 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER,
2935 AB8500_CH_WD_TIMER_REG, WD_TIMER);
2936 if (ret) {
2937 dev_err(di->dev, "failed to set charger watchdog timeout\n");
2938 goto out;
2939 }
2940
2941 ret = ab8500_charger_led_en(di, false);
2942 if (ret < 0) {
2943 dev_err(di->dev, "failed to disable LED\n");
2944 goto out;
2945 }
2946
2746 /* Backup battery voltage and current */ 2947 /* Backup battery voltage and current */
2747 ret = abx500_set_register_interruptible(di->dev, 2948 ret = abx500_set_register_interruptible(di->dev,
2748 AB8500_RTC, 2949 AB8500_RTC,
@@ -2782,6 +2983,7 @@ static struct ab8500_charger_interrupts ab8500_charger_irq[] = {
2782 {"USB_CHARGER_NOT_OKR", ab8500_charger_usbchargernotokr_handler}, 2983 {"USB_CHARGER_NOT_OKR", ab8500_charger_usbchargernotokr_handler},
2783 {"VBUS_OVV", ab8500_charger_vbusovv_handler}, 2984 {"VBUS_OVV", ab8500_charger_vbusovv_handler},
2784 {"CH_WD_EXP", ab8500_charger_chwdexp_handler}, 2985 {"CH_WD_EXP", ab8500_charger_chwdexp_handler},
2986 {"VBUS_CH_DROP_END", ab8500_charger_vbuschdropend_handler},
2785}; 2987};
2786 2988
2787static int ab8500_charger_usb_notifier_call(struct notifier_block *nb, 2989static int ab8500_charger_usb_notifier_call(struct notifier_block *nb,
@@ -2818,13 +3020,15 @@ static int ab8500_charger_usb_notifier_call(struct notifier_block *nb,
2818 __func__, bm_usb_state, mA); 3020 __func__, bm_usb_state, mA);
2819 3021
2820 spin_lock(&di->usb_state.usb_lock); 3022 spin_lock(&di->usb_state.usb_lock);
2821 di->usb_state.usb_changed = true; 3023 di->usb_state.state_tmp = bm_usb_state;
3024 di->usb_state.usb_current_tmp = mA;
2822 spin_unlock(&di->usb_state.usb_lock); 3025 spin_unlock(&di->usb_state.usb_lock);
2823 3026
2824 di->usb_state.state = bm_usb_state; 3027 /*
2825 di->usb_state.usb_current = mA; 3028 * wait for some time until you get updates from the usb stack
2826 3029 * and negotiations are completed
2827 queue_work(di->charger_wq, &di->usb_state_changed_work); 3030 */
3031 queue_delayed_work(di->charger_wq, &di->usb_state_changed_work, HZ/2);
2828 3032
2829 return NOTIFY_OK; 3033 return NOTIFY_OK;
2830} 3034}
@@ -2864,6 +3068,9 @@ static int ab8500_charger_resume(struct platform_device *pdev)
2864 &di->check_hw_failure_work, 0); 3068 &di->check_hw_failure_work, 0);
2865 } 3069 }
2866 3070
3071 if (di->flags.vbus_drop_end)
3072 queue_delayed_work(di->charger_wq, &di->vbus_drop_end_work, 0);
3073
2867 return 0; 3074 return 0;
2868} 3075}
2869 3076
@@ -2876,6 +3083,9 @@ static int ab8500_charger_suspend(struct platform_device *pdev,
2876 if (delayed_work_pending(&di->check_hw_failure_work)) 3083 if (delayed_work_pending(&di->check_hw_failure_work))
2877 cancel_delayed_work(&di->check_hw_failure_work); 3084 cancel_delayed_work(&di->check_hw_failure_work);
2878 3085
3086 if (delayed_work_pending(&di->vbus_drop_end_work))
3087 cancel_delayed_work(&di->vbus_drop_end_work);
3088
2879 flush_delayed_work(&di->attach_work); 3089 flush_delayed_work(&di->attach_work);
2880 flush_delayed_work(&di->usb_charger_attached_work); 3090 flush_delayed_work(&di->usb_charger_attached_work);
2881 flush_delayed_work(&di->ac_charger_attached_work); 3091 flush_delayed_work(&di->ac_charger_attached_work);
@@ -2887,6 +3097,9 @@ static int ab8500_charger_suspend(struct platform_device *pdev,
2887 flush_work(&di->ac_work); 3097 flush_work(&di->ac_work);
2888 flush_work(&di->detect_usb_type_work); 3098 flush_work(&di->detect_usb_type_work);
2889 3099
3100 if (atomic_read(&di->current_stepping_sessions))
3101 return -EAGAIN;
3102
2890 return 0; 3103 return 0;
2891} 3104}
2892#else 3105#else
@@ -2926,9 +3139,10 @@ static int ab8500_charger_remove(struct platform_device *pdev)
2926 flush_scheduled_work(); 3139 flush_scheduled_work();
2927 if(di->usb_chg.enabled) 3140 if(di->usb_chg.enabled)
2928 power_supply_unregister(&di->usb_chg.psy); 3141 power_supply_unregister(&di->usb_chg.psy);
3142#if !defined(CONFIG_CHARGER_PM2301)
2929 if(di->ac_chg.enabled) 3143 if(di->ac_chg.enabled)
2930 power_supply_unregister(&di->ac_chg.psy); 3144 power_supply_unregister(&di->ac_chg.psy);
2931 3145#endif
2932 platform_set_drvdata(pdev, NULL); 3146 platform_set_drvdata(pdev, NULL);
2933 3147
2934 return 0; 3148 return 0;
@@ -2976,6 +3190,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
2976 3190
2977 /* initialize lock */ 3191 /* initialize lock */
2978 spin_lock_init(&di->usb_state.usb_lock); 3192 spin_lock_init(&di->usb_state.usb_lock);
3193 mutex_init(&di->usb_ipt_crnt_lock);
2979 3194
2980 di->autopower = false; 3195 di->autopower = false;
2981 di->invalid_charger_detect_state = 0; 3196 di->invalid_charger_detect_state = 0;
@@ -3061,6 +3276,12 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3061 INIT_DELAYED_WORK(&di->attach_work, 3276 INIT_DELAYED_WORK(&di->attach_work,
3062 ab8500_charger_usb_link_attach_work); 3277 ab8500_charger_usb_link_attach_work);
3063 3278
3279 INIT_DELAYED_WORK(&di->usb_state_changed_work,
3280 ab8500_charger_usb_state_changed_work);
3281
3282 INIT_DELAYED_WORK(&di->vbus_drop_end_work,
3283 ab8500_charger_vbus_drop_end_work);
3284
3064 /* Init work for charger detection */ 3285 /* Init work for charger detection */
3065 INIT_WORK(&di->usb_link_status_work, 3286 INIT_WORK(&di->usb_link_status_work,
3066 ab8500_charger_usb_link_status_work); 3287 ab8500_charger_usb_link_status_work);
@@ -3068,9 +3289,6 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3068 INIT_WORK(&di->detect_usb_type_work, 3289 INIT_WORK(&di->detect_usb_type_work,
3069 ab8500_charger_detect_usb_type_work); 3290 ab8500_charger_detect_usb_type_work);
3070 3291
3071 INIT_WORK(&di->usb_state_changed_work,
3072 ab8500_charger_usb_state_changed_work);
3073
3074 /* Init work for checking HW status */ 3292 /* Init work for checking HW status */
3075 INIT_WORK(&di->check_main_thermal_prot_work, 3293 INIT_WORK(&di->check_main_thermal_prot_work,
3076 ab8500_charger_check_main_thermal_prot_work); 3294 ab8500_charger_check_main_thermal_prot_work);
@@ -3129,7 +3347,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3129 } 3347 }
3130 3348
3131 /* Identify the connected charger types during startup */ 3349 /* Identify the connected charger types during startup */
3132 charger_status = ab8500_charger_detect_chargers(di); 3350 charger_status = ab8500_charger_detect_chargers(di, true);
3133 if (charger_status & AC_PW_CONN) { 3351 if (charger_status & AC_PW_CONN) {
3134 di->ac.charger_connected = 1; 3352 di->ac.charger_connected = 1;
3135 di->ac_conn = true; 3353 di->ac_conn = true;
@@ -3164,7 +3382,7 @@ static int ab8500_charger_probe(struct platform_device *pdev)
3164 3382
3165 mutex_lock(&di->charger_attached_mutex); 3383 mutex_lock(&di->charger_attached_mutex);
3166 3384
3167 ch_stat = ab8500_charger_detect_chargers(di); 3385 ch_stat = ab8500_charger_detect_chargers(di, false);
3168 3386
3169 if ((ch_stat & AC_PW_CONN) == AC_PW_CONN) { 3387 if ((ch_stat & AC_PW_CONN) == AC_PW_CONN) {
3170 queue_delayed_work(di->charger_wq, 3388 queue_delayed_work(di->charger_wq,