qcom_charger: smb-lib: support faking battery capacity
On debug setups where the battery is not present, we need a way to fake battery capacity instead of reporting some incorrect /non-existent value. Provide means for the userspace to setup a fake battery capacity. Change-Id: Iff3ee1009d9c3215433cc267f016ef9cf2a9bff2 Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
parent
e97b6a0e02
commit
52bf80303d
4 changed files with 29 additions and 2 deletions
|
@ -528,6 +528,9 @@ static int smb2_batt_set_prop(struct power_supply *psy,
|
||||||
case POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL:
|
case POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL:
|
||||||
rc = smblib_set_prop_system_temp_level(chg, val);
|
rc = smblib_set_prop_system_temp_level(chg, val);
|
||||||
break;
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY:
|
||||||
|
rc = smblib_set_prop_batt_capacity(chg, val);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -541,6 +544,7 @@ static int smb2_batt_prop_is_writeable(struct power_supply *psy,
|
||||||
switch (psp) {
|
switch (psp) {
|
||||||
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
||||||
case POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL:
|
case POWER_SUPPLY_PROP_SYSTEM_TEMP_LEVEL:
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -749,6 +749,11 @@ int smblib_get_prop_batt_capacity(struct smb_charger *chg,
|
||||||
{
|
{
|
||||||
int rc = -EINVAL;
|
int rc = -EINVAL;
|
||||||
|
|
||||||
|
if (chg->fake_capacity >= 0) {
|
||||||
|
val->intval = chg->fake_capacity;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (chg->bms_psy)
|
if (chg->bms_psy)
|
||||||
rc = power_supply_get_property(chg->bms_psy,
|
rc = power_supply_get_property(chg->bms_psy,
|
||||||
POWER_SUPPLY_PROP_CAPACITY, val);
|
POWER_SUPPLY_PROP_CAPACITY, val);
|
||||||
|
@ -903,6 +908,16 @@ int smblib_set_prop_input_suspend(struct smb_charger *chg,
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int smblib_set_prop_batt_capacity(struct smb_charger *chg,
|
||||||
|
const union power_supply_propval *val)
|
||||||
|
{
|
||||||
|
chg->fake_capacity = val->intval;
|
||||||
|
|
||||||
|
power_supply_changed(chg->batt_psy);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int smblib_set_prop_system_temp_level(struct smb_charger *chg,
|
int smblib_set_prop_system_temp_level(struct smb_charger *chg,
|
||||||
const union power_supply_propval *val)
|
const union power_supply_propval *val)
|
||||||
{
|
{
|
||||||
|
@ -1907,6 +1922,7 @@ int smblib_init(struct smb_charger *chg)
|
||||||
INIT_WORK(&chg->pl_detect_work, smblib_pl_detect_work);
|
INIT_WORK(&chg->pl_detect_work, smblib_pl_detect_work);
|
||||||
INIT_DELAYED_WORK(&chg->hvdcp_detect_work, smblib_hvdcp_detect_work);
|
INIT_DELAYED_WORK(&chg->hvdcp_detect_work, smblib_hvdcp_detect_work);
|
||||||
INIT_DELAYED_WORK(&chg->pl_taper_work, smblib_pl_taper_work);
|
INIT_DELAYED_WORK(&chg->pl_taper_work, smblib_pl_taper_work);
|
||||||
|
chg->fake_capacity = -EINVAL;
|
||||||
|
|
||||||
switch (chg->mode) {
|
switch (chg->mode) {
|
||||||
case PARALLEL_MASTER:
|
case PARALLEL_MASTER:
|
||||||
|
|
|
@ -138,6 +138,8 @@ struct smb_charger {
|
||||||
int system_temp_level;
|
int system_temp_level;
|
||||||
int thermal_levels;
|
int thermal_levels;
|
||||||
int *thermal_mitigation;
|
int *thermal_mitigation;
|
||||||
|
|
||||||
|
int fake_capacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);
|
int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);
|
||||||
|
@ -189,6 +191,8 @@ int smblib_get_prop_system_temp_level(struct smb_charger *chg,
|
||||||
|
|
||||||
int smblib_set_prop_input_suspend(struct smb_charger *chg,
|
int smblib_set_prop_input_suspend(struct smb_charger *chg,
|
||||||
const union power_supply_propval *val);
|
const union power_supply_propval *val);
|
||||||
|
int smblib_set_prop_batt_capacity(struct smb_charger *chg,
|
||||||
|
const union power_supply_propval *val);
|
||||||
int smblib_set_prop_system_temp_level(struct smb_charger *chg,
|
int smblib_set_prop_system_temp_level(struct smb_charger *chg,
|
||||||
const union power_supply_propval *val);
|
const union power_supply_propval *val);
|
||||||
|
|
||||||
|
|
|
@ -311,9 +311,11 @@ static int smb138x_batt_set_prop(struct power_supply *psy,
|
||||||
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
||||||
rc = smblib_set_prop_input_suspend(chg, val);
|
rc = smblib_set_prop_input_suspend(chg, val);
|
||||||
break;
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY:
|
||||||
|
rc = smblib_set_prop_batt_capacity(chg, val);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
pr_err("batt power supply set prop %d not supported\n",
|
pr_err("batt power supply set prop %d not supported\n", prop);
|
||||||
prop);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +327,7 @@ static int smb138x_batt_prop_is_writeable(struct power_supply *psy,
|
||||||
{
|
{
|
||||||
switch (prop) {
|
switch (prop) {
|
||||||
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
case POWER_SUPPLY_PROP_INPUT_SUSPEND:
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue