OSDN Git Service

power: smb2: expose CHARGE_FULL/CYCLE_COUNT properties
authorAshay Jaiswal <ashayj@codeaurora.org>
Tue, 19 Jun 2018 18:56:22 +0000 (00:26 +0530)
committerAshay Jaiswal <ashayj@codeaurora.org>
Mon, 16 Jul 2018 10:57:13 +0000 (16:27 +0530)
Expose CHARGE_FULL/CYCLE_COUNT properties via "battery"
power_supply class.

While at it, create a common function to read properties
from "bms" power_supply_class.

Change-Id: I377ecea6e62c1eb8716982b79ec4c236c14bc2d5
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
drivers/power/supply/qcom/qpnp-smb2.c
drivers/power/supply/qcom/smb-lib.c
drivers/power/supply/qcom/smb-lib.h

index 8e57bf9..a7c206c 100644 (file)
@@ -945,6 +945,8 @@ static enum power_supply_property smb2_batt_props[] = {
        POWER_SUPPLY_PROP_DP_DM,
        POWER_SUPPLY_PROP_CHARGE_COUNTER,
        POWER_SUPPLY_PROP_FCC_STEPPER_ENABLE,
+       POWER_SUPPLY_PROP_CHARGE_FULL,
+       POWER_SUPPLY_PROP_CYCLE_COUNT,
 };
 
 static int smb2_batt_get_prop(struct power_supply *psy,
@@ -999,9 +1001,6 @@ static int smb2_batt_get_prop(struct power_supply *psy,
        case POWER_SUPPLY_PROP_SW_JEITA_ENABLED:
                val->intval = chg->sw_jeita_enabled;
                break;
-       case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-               rc = smblib_get_prop_batt_voltage_now(chg, val);
-               break;
        case POWER_SUPPLY_PROP_VOLTAGE_MAX:
                val->intval = get_client_vote(chg->fv_votable,
                                BATT_PROFILE_VOTER);
@@ -1013,9 +1012,6 @@ static int smb2_batt_get_prop(struct power_supply *psy,
                val->intval = get_client_vote_locked(chg->fv_votable,
                                QNOVO_VOTER);
                break;
-       case POWER_SUPPLY_PROP_CURRENT_NOW:
-               rc = smblib_get_prop_batt_current_now(chg, val);
-               break;
        case POWER_SUPPLY_PROP_CURRENT_QNOVO:
                val->intval = get_client_vote_locked(chg->fcc_votable,
                                QNOVO_VOTER);
@@ -1024,9 +1020,6 @@ static int smb2_batt_get_prop(struct power_supply *psy,
                val->intval = get_client_vote(chg->fcc_votable,
                                              BATT_PROFILE_VOTER);
                break;
-       case POWER_SUPPLY_PROP_TEMP:
-               rc = smblib_get_prop_batt_temp(chg, val);
-               break;
        case POWER_SUPPLY_PROP_TECHNOLOGY:
                val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
                break;
@@ -1051,7 +1044,12 @@ static int smb2_batt_get_prop(struct power_supply *psy,
                val->intval = 0;
                break;
        case POWER_SUPPLY_PROP_CHARGE_COUNTER:
-               rc = smblib_get_prop_batt_charge_counter(chg, val);
+       case POWER_SUPPLY_PROP_CHARGE_FULL:
+       case POWER_SUPPLY_PROP_CYCLE_COUNT:
+       case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+       case POWER_SUPPLY_PROP_CURRENT_NOW:
+       case POWER_SUPPLY_PROP_TEMP:
+               rc = smblib_get_prop_from_bms(chg, psp, val);
                break;
        case POWER_SUPPLY_PROP_FCC_STEPPER_ENABLE:
                val->intval = chg->fcc_stepper_mode;
index e96523a..81623c6 100644 (file)
@@ -1717,7 +1717,8 @@ int smblib_get_prop_batt_health(struct smb_charger *chg,
                   stat);
 
        if (stat & CHARGER_ERROR_STATUS_BAT_OV_BIT) {
-               rc = smblib_get_prop_batt_voltage_now(chg, &pval);
+               rc = smblib_get_prop_from_bms(chg,
+                               POWER_SUPPLY_PROP_VOLTAGE_NOW, &pval);
                if (!rc) {
                        /*
                         * If Vbatt is within 40mV above Vfloat, then don't
@@ -1775,45 +1776,6 @@ int smblib_get_prop_input_current_limited(struct smb_charger *chg,
        return 0;
 }
 
-int smblib_get_prop_batt_voltage_now(struct smb_charger *chg,
-                                    union power_supply_propval *val)
-{
-       int rc;
-
-       if (!chg->bms_psy)
-               return -EINVAL;
-
-       rc = power_supply_get_property(chg->bms_psy,
-                                      POWER_SUPPLY_PROP_VOLTAGE_NOW, val);
-       return rc;
-}
-
-int smblib_get_prop_batt_current_now(struct smb_charger *chg,
-                                    union power_supply_propval *val)
-{
-       int rc;
-
-       if (!chg->bms_psy)
-               return -EINVAL;
-
-       rc = power_supply_get_property(chg->bms_psy,
-                                      POWER_SUPPLY_PROP_CURRENT_NOW, val);
-       return rc;
-}
-
-int smblib_get_prop_batt_temp(struct smb_charger *chg,
-                             union power_supply_propval *val)
-{
-       int rc;
-
-       if (!chg->bms_psy)
-               return -EINVAL;
-
-       rc = power_supply_get_property(chg->bms_psy,
-                                      POWER_SUPPLY_PROP_TEMP, val);
-       return rc;
-}
-
 int smblib_get_prop_batt_charge_done(struct smb_charger *chg,
                                        union power_supply_propval *val)
 {
@@ -1849,16 +1811,17 @@ int smblib_get_prop_charge_qnovo_enable(struct smb_charger *chg,
        return 0;
 }
 
-int smblib_get_prop_batt_charge_counter(struct smb_charger *chg,
-                                    union power_supply_propval *val)
+int smblib_get_prop_from_bms(struct smb_charger *chg,
+                               enum power_supply_property psp,
+                               union power_supply_propval *val)
 {
        int rc;
 
        if (!chg->bms_psy)
                return -EINVAL;
 
-       rc = power_supply_get_property(chg->bms_psy,
-                                      POWER_SUPPLY_PROP_CHARGE_COUNTER, val);
+       rc = power_supply_get_property(chg->bms_psy, psp, val);
+
        return rc;
 }
 
index 4475ccc..5ca5e92 100644 (file)
@@ -434,14 +434,6 @@ int smblib_get_prop_system_temp_level(struct smb_charger *chg,
                                union power_supply_propval *val);
 int smblib_get_prop_input_current_limited(struct smb_charger *chg,
                                union power_supply_propval *val);
-int smblib_get_prop_batt_voltage_now(struct smb_charger *chg,
-                               union power_supply_propval *val);
-int smblib_get_prop_batt_current_now(struct smb_charger *chg,
-                               union power_supply_propval *val);
-int smblib_get_prop_batt_temp(struct smb_charger *chg,
-                               union power_supply_propval *val);
-int smblib_get_prop_batt_charge_counter(struct smb_charger *chg,
-                               union power_supply_propval *val);
 int smblib_set_prop_input_suspend(struct smb_charger *chg,
                                const union power_supply_propval *val);
 int smblib_set_prop_batt_capacity(struct smb_charger *chg,
@@ -529,6 +521,9 @@ int smblib_get_icl_current(struct smb_charger *chg, int *icl_ua);
 int smblib_get_charge_current(struct smb_charger *chg, int *total_current_ua);
 int smblib_get_prop_pr_swap_in_progress(struct smb_charger *chg,
                                union power_supply_propval *val);
+int smblib_get_prop_from_bms(struct smb_charger *chg,
+                               enum power_supply_property psp,
+                               union power_supply_propval *val);
 int smblib_set_prop_pr_swap_in_progress(struct smb_charger *chg,
                                const union power_supply_propval *val);
 void smblib_usb_typec_change(struct smb_charger *chg);