power: pm8921-bms: use restart reason for usb detection

When the charger is not initialized it returns -EINVAL when asked
whether usb charger is plugged in. Use the restart reason to check
if we started with a charger insertion.

Change-Id: I2e8fcb4a15af3a66331a921d378bfd5d2dfe4533
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
choongryeol.lee 2012-10-10 16:25:38 -07:00 committed by Iliyan Malchev
parent 9309bccb81
commit 9843a708f3

View file

@ -350,13 +350,18 @@ static int pm_bms_masked_write(struct pm8921_bms_chip *chip, u16 addr,
return 0;
}
static int usb_chg_plugged_in(void)
static int usb_chg_plugged_in(struct pm8921_bms_chip *chip)
{
int val = pm8921_is_usb_chg_plugged_in();
/* treat as if usb is not present in case of error */
if (val == -EINVAL)
val = 0;
/* if the charger driver was not initialized, use the restart reason */
if (val == -EINVAL) {
if (pm8xxx_restart_reason(chip->dev->parent)
== PM8XXX_RESTART_CHG)
val = 1;
else
val = 0;
}
return val;
}
@ -959,7 +964,7 @@ int override_mode_simultaneous_battery_voltage_and_current(int *ibat_ua,
mutex_unlock(&the_chip->bms_output_lock);
usb_chg = usb_chg_plugged_in();
usb_chg = usb_chg_plugged_in(the_chip);
usb_chg |= wireless_chg_plugged_in();
convert_vbatt_raw_to_uv(the_chip, usb_chg, vbat_raw, vbat_uv);
@ -1001,7 +1006,7 @@ static int read_soc_params_raw(struct pm8921_bms_chip *chip,
pm_bms_unlock_output_data(chip);
mutex_unlock(&chip->bms_output_lock);
usb_chg = usb_chg_plugged_in();
usb_chg = usb_chg_plugged_in(chip);
usb_chg |= wireless_chg_plugged_in();
if (chip->prev_last_good_ocv_raw == 0) {
@ -2319,9 +2324,8 @@ static void calib_hkadc(struct pm8921_bms_chip *chip)
}
voltage = xoadc_reading_to_microvolt(result.adc_code);
usb_chg = usb_chg_plugged_in();
usb_chg = usb_chg_plugged_in(chip);
usb_chg |= wireless_chg_plugged_in();
pr_debug("result 0.625V = 0x%x, voltage = %duV adc_meas = %lld "
"usb_chg = %d\n",
result.adc_code, voltage, result.measurement,
@ -2808,9 +2812,8 @@ static void check_initial_ocv(struct pm8921_bms_chip *chip)
*/
ocv_uv = 0;
pm_bms_read_output_data(chip, LAST_GOOD_OCV_VALUE, &ocv_raw);
usb_chg = usb_chg_plugged_in();
usb_chg = usb_chg_plugged_in(chip);
usb_chg |= wireless_chg_plugged_in();
rc = convert_vbatt_raw_to_uv(chip, usb_chg, ocv_raw, &ocv_uv);
if (rc || ocv_uv == 0) {
rc = adc_based_ocv(chip, &ocv_uv);