summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2017-02-11 01:25:21 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2017-02-11 01:25:21 -0800
commit713e5d786eb40a063e314acd5f04890478f55b2c (patch)
tree91f442948e72e58263e28516af5803c5135c54ba /drivers/power
parentebcc5b8ada7325aee6cec0f3e7b9154641fa6ff8 (diff)
parent8a3c043c63ba6893087954dc3325521d33e7d578 (diff)
Merge "qcom: qnovo: Update fcc and fv through batt psy"
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/power_supply_sysfs.c2
-rw-r--r--drivers/power/supply/qcom/battery.c36
-rw-r--r--drivers/power/supply/qcom/qpnp-qnovo.c80
-rw-r--r--drivers/power/supply/qcom/qpnp-smb2.c20
-rw-r--r--drivers/power/supply/qcom/smb-lib.c20
-rw-r--r--drivers/power/supply/qcom/smb-lib.h6
6 files changed, 104 insertions, 60 deletions
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index a9bb96df56c9..168119fcf7d1 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -263,6 +263,8 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(dp_dm),
POWER_SUPPLY_ATTR(input_current_limited),
POWER_SUPPLY_ATTR(input_current_now),
+ POWER_SUPPLY_ATTR(current_qnovo),
+ POWER_SUPPLY_ATTR(voltage_qnovo),
POWER_SUPPLY_ATTR(rerun_aicl),
POWER_SUPPLY_ATTR(cycle_count_id),
POWER_SUPPLY_ATTR(safety_timer_expired),
diff --git a/drivers/power/supply/qcom/battery.c b/drivers/power/supply/qcom/battery.c
index efa88c239379..6f083f1bbe80 100644
--- a/drivers/power/supply/qcom/battery.c
+++ b/drivers/power/supply/qcom/battery.c
@@ -298,6 +298,19 @@ static int pl_fcc_vote_callback(struct votable *votable, void *data,
if (!chip->main_psy)
return 0;
+ if (chip->batt_psy) {
+ rc = power_supply_get_property(chip->batt_psy,
+ POWER_SUPPLY_PROP_CURRENT_QNOVO,
+ &pval);
+ if (rc < 0) {
+ pr_err("Couldn't get qnovo fcc, rc=%d\n", rc);
+ return rc;
+ }
+
+ if (pval.intval != -EINVAL)
+ total_fcc_ua = pval.intval;
+ }
+
if (chip->pl_mode == POWER_SUPPLY_PARALLEL_NONE
|| get_effective_result_locked(chip->pl_disable_votable)) {
pval.intval = total_fcc_ua;
@@ -343,6 +356,7 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
struct pl_data *chip = data;
union power_supply_propval pval = {0, };
int rc = 0;
+ int effective_fv_uv = fv_uv;
if (fv_uv < 0)
return 0;
@@ -350,7 +364,21 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
if (!chip->main_psy)
return 0;
- pval.intval = fv_uv;
+ if (chip->batt_psy) {
+ rc = power_supply_get_property(chip->batt_psy,
+ POWER_SUPPLY_PROP_VOLTAGE_QNOVO,
+ &pval);
+ if (rc < 0) {
+ pr_err("Couldn't get qnovo fv, rc=%d\n", rc);
+ return rc;
+ }
+
+ if (pval.intval != -EINVAL)
+ effective_fv_uv = pval.intval;
+ }
+
+ pval.intval = effective_fv_uv;
+
rc = power_supply_set_property(chip->main_psy,
POWER_SUPPLY_PROP_VOLTAGE_MAX, &pval);
if (rc < 0) {
@@ -359,7 +387,7 @@ static int pl_fv_vote_callback(struct votable *votable, void *data,
}
if (chip->pl_mode != POWER_SUPPLY_PARALLEL_NONE) {
- pval.intval = fv_uv + PARALLEL_FLOAT_VOLTAGE_DELTA_UV;
+ pval.intval += PARALLEL_FLOAT_VOLTAGE_DELTA_UV;
rc = power_supply_set_property(chip->pl_psy,
POWER_SUPPLY_PROP_VOLTAGE_MAX, &pval);
if (rc < 0) {
@@ -514,9 +542,9 @@ static bool is_parallel_available(struct pl_data *chip)
return false;
}
/*
- * Note that pl_mode only be udpated to anything other than a _NONE
+ * Note that pl_mode will be updated to anything other than a _NONE
* only after pl_psy is found. IOW pl_mode != _NONE implies that
- * pl_psy is present and valid
+ * pl_psy is present and valid.
*/
chip->pl_mode = pval.intval;
vote(chip->pl_disable_votable, PARALLEL_PSY_VOTER, false, 0);
diff --git a/drivers/power/supply/qcom/qpnp-qnovo.c b/drivers/power/supply/qcom/qpnp-qnovo.c
index 8ae9e842bef2..d36db8d8f3f1 100644
--- a/drivers/power/supply/qcom/qpnp-qnovo.c
+++ b/drivers/power/supply/qcom/qpnp-qnovo.c
@@ -148,8 +148,6 @@ struct qnovo {
struct work_struct status_change_work;
int fv_uV_request;
int fcc_uA_request;
- struct votable *fcc_max_votable;
- struct votable *fv_votable;
};
static int debug_mask;
@@ -226,6 +224,50 @@ unlock:
return rc;
}
+static bool is_batt_available(struct qnovo *chip)
+{
+ if (!chip->batt_psy)
+ chip->batt_psy = power_supply_get_by_name("battery");
+
+ if (!chip->batt_psy)
+ return false;
+
+ return true;
+}
+
+static int qnovo_batt_psy_update(struct qnovo *chip, bool disable)
+{
+ union power_supply_propval pval = {0};
+ int rc = 0;
+
+ if (!is_batt_available(chip))
+ return -EINVAL;
+
+ if (chip->fv_uV_request != -EINVAL) {
+ pval.intval = disable ? -EINVAL : chip->fv_uV_request;
+ rc = power_supply_set_property(chip->batt_psy,
+ POWER_SUPPLY_PROP_VOLTAGE_QNOVO,
+ &pval);
+ if (rc < 0) {
+ pr_err("Couldn't set prop qnovo_fv rc = %d\n", rc);
+ return -EINVAL;
+ }
+ }
+
+ if (chip->fcc_uA_request != -EINVAL) {
+ pval.intval = disable ? -EINVAL : chip->fcc_uA_request;
+ rc = power_supply_set_property(chip->batt_psy,
+ POWER_SUPPLY_PROP_CURRENT_QNOVO,
+ &pval);
+ if (rc < 0) {
+ pr_err("Couldn't set prop qnovo_fcc rc = %d\n", rc);
+ return -EINVAL;
+ }
+ }
+
+ return rc;
+}
+
static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
const char *client)
{
@@ -233,15 +275,9 @@ static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
int rc = 0;
if (disable) {
- if (chip->fv_uV_request != -EINVAL) {
- if (chip->fv_votable)
- vote(chip->fv_votable, QNOVO_VOTER, false, 0);
- }
- if (chip->fcc_uA_request != -EINVAL) {
- if (chip->fcc_max_votable)
- vote(chip->fcc_max_votable, QNOVO_VOTER,
- false, 0);
- }
+ rc = qnovo_batt_psy_update(chip, true);
+ if (rc < 0)
+ return rc;
}
rc = qnovo_masked_write(chip, QNOVO_PTRAIN_EN, QNOVO_PTRAIN_EN_BIT,
@@ -253,20 +289,9 @@ static int qnovo_disable_cb(struct votable *votable, void *data, int disable,
}
if (!disable) {
- if (chip->fv_uV_request != -EINVAL) {
- if (!chip->fv_votable)
- chip->fv_votable = find_votable("FV");
- if (chip->fv_votable)
- vote(chip->fv_votable, QNOVO_VOTER,
- true, chip->fv_uV_request);
- }
- if (chip->fcc_uA_request != -EINVAL) {
- if (!chip->fcc_max_votable)
- chip->fcc_max_votable = find_votable("FCC_MAX");
- if (chip->fcc_max_votable)
- vote(chip->fcc_max_votable, QNOVO_VOTER,
- true, chip->fcc_uA_request);
- }
+ rc = qnovo_batt_psy_update(chip, false);
+ if (rc < 0)
+ return rc;
}
return rc;
@@ -979,10 +1004,7 @@ static ssize_t batt_prop_show(struct class *c, struct class_attribute *attr,
int prop = params[i].start_addr;
union power_supply_propval pval = {0};
- if (!chip->batt_psy)
- chip->batt_psy = power_supply_get_by_name("battery");
-
- if (!chip->batt_psy)
+ if (!is_batt_available(chip))
return -EINVAL;
rc = power_supply_get_property(chip->batt_psy, prop, &pval);
diff --git a/drivers/power/supply/qcom/qpnp-smb2.c b/drivers/power/supply/qcom/qpnp-smb2.c
index e8f7b4743152..983bf4f3e08d 100644
--- a/drivers/power/supply/qcom/qpnp-smb2.c
+++ b/drivers/power/supply/qcom/qpnp-smb2.c
@@ -836,7 +836,6 @@ static enum power_supply_property smb2_batt_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CURRENT_NOW,
- POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_STEP_CHARGING_ENABLED,
@@ -897,12 +896,14 @@ static int smb2_batt_get_prop(struct power_supply *psy,
case POWER_SUPPLY_PROP_VOLTAGE_MAX:
val->intval = get_client_vote(chg->fv_votable, DEFAULT_VOTER);
break;
+ case POWER_SUPPLY_PROP_VOLTAGE_QNOVO:
+ val->intval = chg->qnovo_fv_uv;
+ break;
case POWER_SUPPLY_PROP_CURRENT_NOW:
rc = smblib_get_prop_batt_current_now(chg, val);
break;
- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
- val->intval = get_client_vote(chg->fcc_max_votable,
- DEFAULT_VOTER);
+ case POWER_SUPPLY_PROP_CURRENT_QNOVO:
+ val->intval = chg->qnovo_fcc_ua;
break;
case POWER_SUPPLY_PROP_TEMP:
rc = smblib_get_prop_batt_temp(chg, val);
@@ -960,8 +961,13 @@ static int smb2_batt_set_prop(struct power_supply *psy,
case POWER_SUPPLY_PROP_VOLTAGE_MAX:
vote(chg->fv_votable, DEFAULT_VOTER, true, val->intval);
break;
- case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
- vote(chg->fcc_max_votable, DEFAULT_VOTER, true, val->intval);
+ case POWER_SUPPLY_PROP_VOLTAGE_QNOVO:
+ chg->qnovo_fv_uv = val->intval;
+ rc = rerun_election(chg->fv_votable);
+ break;
+ case POWER_SUPPLY_PROP_CURRENT_QNOVO:
+ chg->qnovo_fcc_ua = val->intval;
+ rc = rerun_election(chg->fcc_votable);
break;
case POWER_SUPPLY_PROP_SET_SHIP_MODE:
/* Not in ship mode as long as the device is active */
@@ -1377,7 +1383,7 @@ static int smb2_init_hw(struct smb2 *chip)
DEFAULT_VOTER, chip->dt.no_battery, 0);
vote(chg->dc_suspend_votable,
DEFAULT_VOTER, chip->dt.no_battery, 0);
- vote(chg->fcc_max_votable,
+ vote(chg->fcc_votable,
DEFAULT_VOTER, true, chip->dt.fcc_ua);
vote(chg->fv_votable,
DEFAULT_VOTER, true, chip->dt.fv_uv);
diff --git a/drivers/power/supply/qcom/smb-lib.c b/drivers/power/supply/qcom/smb-lib.c
index 1875c9d22a84..e440a9a561dd 100644
--- a/drivers/power/supply/qcom/smb-lib.c
+++ b/drivers/power/supply/qcom/smb-lib.c
@@ -766,14 +766,6 @@ static int smblib_dc_suspend_vote_callback(struct votable *votable, void *data,
return smblib_set_dc_suspend(chg, (bool)suspend);
}
-static int smblib_fcc_max_vote_callback(struct votable *votable, void *data,
- int fcc_ua, const char *client)
-{
- struct smb_charger *chg = data;
-
- return vote(chg->fcc_votable, FCC_MAX_RESULT_VOTER, true, fcc_ua);
-}
-
#define USBIN_25MA 25000
#define USBIN_100MA 100000
#define USBIN_150MA 150000
@@ -3759,14 +3751,6 @@ static int smblib_create_votables(struct smb_charger *chg)
return rc;
}
- chg->fcc_max_votable = create_votable("FCC_MAX", VOTE_MAX,
- smblib_fcc_max_vote_callback,
- chg);
- if (IS_ERR(chg->fcc_max_votable)) {
- rc = PTR_ERR(chg->fcc_max_votable);
- return rc;
- }
-
chg->usb_icl_votable = create_votable("USB_ICL", VOTE_MIN,
smblib_usb_icl_vote_callback,
chg);
@@ -3860,8 +3844,6 @@ static void smblib_destroy_votables(struct smb_charger *chg)
destroy_votable(chg->usb_suspend_votable);
if (chg->dc_suspend_votable)
destroy_votable(chg->dc_suspend_votable);
- if (chg->fcc_max_votable)
- destroy_votable(chg->fcc_max_votable);
if (chg->usb_icl_votable)
destroy_votable(chg->usb_icl_votable);
if (chg->dc_icl_votable)
@@ -3912,6 +3894,8 @@ int smblib_init(struct smb_charger *chg)
switch (chg->mode) {
case PARALLEL_MASTER:
+ chg->qnovo_fcc_ua = -EINVAL;
+ chg->qnovo_fv_uv = -EINVAL;
rc = smblib_create_votables(chg);
if (rc < 0) {
smblib_err(chg, "Couldn't create votables rc=%d\n",
diff --git a/drivers/power/supply/qcom/smb-lib.h b/drivers/power/supply/qcom/smb-lib.h
index b778d43dbec2..2d8e8835e937 100644
--- a/drivers/power/supply/qcom/smb-lib.h
+++ b/drivers/power/supply/qcom/smb-lib.h
@@ -40,7 +40,6 @@ enum print_reason {
#define CHG_STATE_VOTER "CHG_STATE_VOTER"
#define TYPEC_SRC_VOTER "TYPEC_SRC_VOTER"
#define TAPER_END_VOTER "TAPER_END_VOTER"
-#define FCC_MAX_RESULT_VOTER "FCC_MAX_RESULT_VOTER"
#define THERMAL_DAEMON_VOTER "THERMAL_DAEMON_VOTER"
#define CC_DETACHED_VOTER "CC_DETACHED_VOTER"
#define HVDCP_TIMEOUT_VOTER "HVDCP_TIMEOUT_VOTER"
@@ -202,7 +201,6 @@ struct smb_charger {
/* votables */
struct votable *usb_suspend_votable;
struct votable *dc_suspend_votable;
- struct votable *fcc_max_votable;
struct votable *fcc_votable;
struct votable *fv_votable;
struct votable *usb_icl_votable;
@@ -260,6 +258,10 @@ struct smb_charger {
bool usb_ever_removed;
int icl_reduction_ua;
+
+ /* qnovo */
+ int qnovo_fcc_ua;
+ int qnovo_fv_uv;
};
int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);