Merge "power: smb1360: Use the previous property value when suspended"

This commit is contained in:
Linux Build Service Account 2015-04-13 07:13:18 -07:00 committed by Gerrit - the friendly Code Review server
commit 594132c011
1 changed files with 54 additions and 7 deletions

View File

@ -354,6 +354,12 @@ struct smb1360_chip {
int otg_fet_enable_gpio;
/* status tracking */
int voltage_now;
int current_now;
int resistance_now;
int temp_now;
int soc_now;
int fcc_mah;
bool usb_present;
bool batt_present;
bool batt_hot;
@ -718,6 +724,11 @@ static int smb1360_enable_fg_access(struct smb1360_chip *chip)
return 0;
}
static inline bool is_device_suspended(struct smb1360_chip *chip)
{
return !chip->resume_completed;
}
static int smb1360_disable_fg_access(struct smb1360_chip *chip)
{
int rc;
@ -897,6 +908,9 @@ static int smb1360_get_prop_batt_status(struct smb1360_chip *chip)
int rc;
u8 reg = 0, chg_type;
if (is_device_suspended(chip))
return POWER_SUPPLY_STATUS_UNKNOWN;
if (chip->batt_full)
return POWER_SUPPLY_STATUS_FULL;
@ -925,6 +939,9 @@ static int smb1360_get_prop_charge_type(struct smb1360_chip *chip)
u8 reg = 0;
u8 chg_type;
if (is_device_suspended(chip))
return POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
rc = smb1360_read(chip, STATUS_3_REG, &reg);
if (rc) {
pr_err("Couldn't read STATUS_3_REG rc=%d\n", rc);
@ -975,6 +992,9 @@ static int smb1360_get_prop_batt_capacity(struct smb1360_chip *chip)
return 0;
}
if (is_device_suspended(chip))
return chip->soc_now;
rc = smb1360_read(chip, SHDW_FG_MSYS_SOC, &reg);
if (rc) {
pr_err("Failed to read FG_MSYS_SOC rc=%d\n", rc);
@ -989,7 +1009,9 @@ static int smb1360_get_prop_batt_capacity(struct smb1360_chip *chip)
pr_debug("msys_soc_reg=0x%02x, fg_soc=%d batt_full = %d\n", reg,
soc, chip->batt_full);
return chip->batt_full ? 100 : bound(soc, 0, 100);
chip->soc_now = (chip->batt_full ? 100 : bound(soc, 0, 100));
return chip->soc_now;
}
static int smb1360_get_prop_chg_full_design(struct smb1360_chip *chip)
@ -997,6 +1019,9 @@ static int smb1360_get_prop_chg_full_design(struct smb1360_chip *chip)
u8 reg[2];
int rc, fcc_mah = 0;
if (is_device_suspended(chip))
return chip->fcc_mah;
rc = smb1360_read_bytes(chip, SHDW_FG_CAPACITY, reg, 2);
if (rc) {
pr_err("Failed to read SHDW_FG_CAPACITY rc=%d\n", rc);
@ -1007,7 +1032,9 @@ static int smb1360_get_prop_chg_full_design(struct smb1360_chip *chip)
pr_debug("reg[0]=0x%02x reg[1]=0x%02x fcc_mah=%d\n",
reg[0], reg[1], fcc_mah);
return fcc_mah * 1000;
chip->fcc_mah = fcc_mah * 1000;
return chip->fcc_mah;
}
static int smb1360_get_prop_batt_temp(struct smb1360_chip *chip)
@ -1015,6 +1042,9 @@ static int smb1360_get_prop_batt_temp(struct smb1360_chip *chip)
u8 reg[2];
int rc, temp = 0;
if (is_device_suspended(chip))
return chip->temp_now;
rc = smb1360_read_bytes(chip, SHDW_FG_BATT_TEMP, reg, 2);
if (rc) {
pr_err("Failed to read SHDW_FG_BATT_TEMP rc=%d\n", rc);
@ -1028,7 +1058,9 @@ static int smb1360_get_prop_batt_temp(struct smb1360_chip *chip)
pr_debug("reg[0]=0x%02x reg[1]=0x%02x temperature=%d\n",
reg[0], reg[1], temp);
return temp;
chip->temp_now = temp;
return chip->temp_now;
}
static int smb1360_get_prop_voltage_now(struct smb1360_chip *chip)
@ -1036,6 +1068,9 @@ static int smb1360_get_prop_voltage_now(struct smb1360_chip *chip)
u8 reg[2];
int rc, temp = 0;
if (is_device_suspended(chip))
return chip->voltage_now;
rc = smb1360_read_bytes(chip, SHDW_FG_VTG_NOW, reg, 2);
if (rc) {
pr_err("Failed to read SHDW_FG_VTG_NOW rc=%d\n", rc);
@ -1048,7 +1083,9 @@ static int smb1360_get_prop_voltage_now(struct smb1360_chip *chip)
pr_debug("reg[0]=0x%02x reg[1]=0x%02x voltage=%d\n",
reg[0], reg[1], temp * 1000);
return temp * 1000;
chip->voltage_now = temp * 1000;
return chip->voltage_now;
}
static int smb1360_get_prop_batt_resistance(struct smb1360_chip *chip)
@ -1058,6 +1095,9 @@ static int smb1360_get_prop_batt_resistance(struct smb1360_chip *chip)
int rc;
int64_t resistance;
if (is_device_suspended(chip))
return chip->resistance_now;
rc = smb1360_read_bytes(chip, SHDW_FG_ESR_ACTUAL, reg, 2);
if (rc) {
pr_err("Failed to read FG_ESR_ACTUAL rc=%d\n", rc);
@ -1070,7 +1110,9 @@ static int smb1360_get_prop_batt_resistance(struct smb1360_chip *chip)
pr_debug("reg=0x%02x resistance=%lld\n", temp, resistance);
/* resistance in uohms */
return resistance;
chip->resistance_now = resistance;
return chip->resistance_now;
}
static int smb1360_get_prop_current_now(struct smb1360_chip *chip)
@ -1078,6 +1120,9 @@ static int smb1360_get_prop_current_now(struct smb1360_chip *chip)
u8 reg[2];
int rc, temp = 0;
if (is_device_suspended(chip))
return chip->current_now;
rc = smb1360_read_bytes(chip, SHDW_FG_CURR_NOW, reg, 2);
if (rc) {
pr_err("Failed to read SHDW_FG_CURR_NOW rc=%d\n", rc);
@ -1090,7 +1135,9 @@ static int smb1360_get_prop_current_now(struct smb1360_chip *chip)
pr_debug("reg[0]=0x%02x reg[1]=0x%02x current=%d\n",
reg[0], reg[1], temp * 1000);
return temp * 1000;
chip->current_now = temp * 1000;
return chip->current_now;
}
static int smb1360_set_minimum_usb_current(struct smb1360_chip *chip)
@ -4331,6 +4378,7 @@ static int smb1360_probe(struct i2c_client *client,
return -ENOMEM;
}
chip->resume_completed = true;
chip->client = client;
chip->dev = &client->dev;
chip->usb_psy = usb_psy;
@ -4358,7 +4406,6 @@ static int smb1360_probe(struct i2c_client *client,
device_init_wakeup(chip->dev, 1);
i2c_set_clientdata(client, chip);
chip->resume_completed = true;
mutex_init(&chip->irq_complete);
mutex_init(&chip->charging_disable_lock);
mutex_init(&chip->current_change_lock);