Merge "qcom-charger: fg-util: add float decode function"

This commit is contained in:
Linux Build Service Account 2016-09-29 11:20:57 -07:00 committed by Gerrit - the friendly Code Review server
commit 2d26c815e5
5 changed files with 38 additions and 11 deletions

View file

@ -21,11 +21,13 @@ Charger specific properties:
Value type: <string>
Definition: "qcom,qpnp-smb2".
- qcom,suspend-input
- qcom,batteryless-platform
Usage: optional
Value type: <empty>
Definition: Boolean flag which indicates that the charger should not draw
current from any of its input sources (USB, DC).
Definition: Boolean flag which indicates that the platform does not have a
battery, and therefore charging should be disabled. In
addition battery properties will be faked such that the device
assumes normal operation.
- qcom,fcc-max-ua
Usage: optional

View file

@ -425,7 +425,7 @@
};
&pmicobalt_charger {
qcom,suspend-input;
qcom,batteryless-platform;
};
&pmicobalt_haptics {

View file

@ -252,4 +252,5 @@ extern int fg_ima_init(struct fg_chip *chip);
extern int fg_sram_debugfs_create(struct fg_chip *chip);
extern void fill_string(char *str, size_t str_len, u8 *buf, int buf_len);
extern int64_t twos_compliment_extend(int64_t val, int s_bit_pos);
extern s64 fg_float_decode(u16 val);
#endif

View file

@ -29,6 +29,26 @@ static struct fg_dbgfs dbgfs_data = {
},
};
#define EXPONENT_SHIFT 11
#define EXPONENT_OFFSET -9
#define MANTISSA_SIGN_BIT 10
#define MICRO_UNIT 1000000
s64 fg_float_decode(u16 val)
{
s8 exponent;
s32 mantissa;
/* mantissa bits are shifted out during sign extension */
exponent = ((s16)val >> EXPONENT_SHIFT) + EXPONENT_OFFSET;
/* exponent bits are shifted out during sign extension */
mantissa = sign_extend32(val, MANTISSA_SIGN_BIT) * MICRO_UNIT;
if (exponent < 0)
return (s64)mantissa >> -exponent;
return (s64)mantissa << exponent;
}
void fill_string(char *str, size_t str_len, u8 *buf, int buf_len)
{
int pos = 0;

View file

@ -197,7 +197,7 @@ static struct smb_params v1_params = {
#define STEP_CHARGING_MAX_STEPS 5
struct smb_dt_props {
bool suspend_input;
bool no_battery;
int fcc_ua;
int usb_icl_ua;
int dc_icl_ua;
@ -256,8 +256,8 @@ static int smb2_parse_dt(struct smb2 *chip)
if (rc < 0)
chg->step_chg_enabled = false;
chip->dt.suspend_input = of_property_read_bool(node,
"qcom,suspend-input");
chip->dt.no_battery = of_property_read_bool(node,
"qcom,batteryless-platform");
rc = of_property_read_u32(node,
"qcom,fcc-max-ua", &chip->dt.fcc_ua);
@ -602,8 +602,9 @@ static int smb2_batt_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
int rc;
struct smb_charger *chg = power_supply_get_drvdata(psy);
struct smb2 *chip = power_supply_get_drvdata(psy);
struct smb_charger *chg = &chip->chg;
int rc = 0;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
@ -929,6 +930,9 @@ static int smb2_init_hw(struct smb2 *chip)
struct smb_charger *chg = &chip->chg;
int rc;
if (chip->dt.no_battery)
chg->fake_capacity = 50;
if (chip->dt.fcc_ua < 0)
smblib_get_charge_param(chg, &chg->param.fcc, &chip->dt.fcc_ua);
@ -949,9 +953,9 @@ static int smb2_init_hw(struct smb2 *chip)
vote(chg->pl_disable_votable,
CHG_STATE_VOTER, true, 0);
vote(chg->usb_suspend_votable,
DEFAULT_VOTER, chip->dt.suspend_input, 0);
DEFAULT_VOTER, chip->dt.no_battery, 0);
vote(chg->dc_suspend_votable,
DEFAULT_VOTER, chip->dt.suspend_input, 0);
DEFAULT_VOTER, chip->dt.no_battery, 0);
vote(chg->fcc_max_votable,
DEFAULT_VOTER, true, chip->dt.fcc_ua);
vote(chg->fv_votable,