OSDN Git Service

qcom-charger: smb2: configure input from wipower
authorAbhijeet Dharmapurikar <adharmap@codeaurora.org>
Tue, 21 Jun 2016 21:20:24 +0000 (14:20 -0700)
committerAbhijeet Dharmapurikar <adharmap@codeaurora.org>
Wed, 20 Jul 2016 23:50:54 +0000 (16:50 -0700)
Wipower feeds to the DCIN input of the smb2 charger and relies on
input current configurations on six different voltage ranges for
optimal power draw.

Provide means to configure the current limits in them via a device
tree setting.

Change-Id: I81d1dc3ed1d588d67525b15120e7d8b947536099
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Documentation/devicetree/bindings/power/qcom-charger/qpnp-smb2.txt
drivers/power/qcom-charger/qpnp-smb2.c
drivers/power/qcom-charger/smb-lib.h
drivers/power/qcom-charger/smb-reg.h

index 58db2c2..368f0b8 100644 (file)
@@ -50,6 +50,12 @@ Charger specific properties:
   Value type: <u32>
   Definition: Specifies the DC input current limit in micro-amps.
 
+- qcom,wipower-max-uw
+  Usage:      optional
+  Value type: <u32>
+  Definition: Specifies the DC input power limit in micro-watts.
+               If the value is not present, 8W is used as default.
+
 =============================================
 Second Level Nodes - SMB2 Charger Peripherals
 =============================================
@@ -80,9 +86,7 @@ pmicobalt_charger: qcom,qpnp-smb2 {
        #address-cells = <1>;
        #size-cells = <1>;
 
-       qcom,pmic-revid = <&pmicobalt_revid>;
        qcom,suspend-input;
-       qcom,disable-charging;
        dpdm-supply = <&qusb_phy0>;
 
        qcom,chgr@1000 {
index 7810ecb..ad00a98 100644 (file)
 #include "smb-lib.h"
 #include "pmic-voter.h"
 
-#define SMB2_DEFAULT_FCC_UA 3000000
-#define SMB2_DEFAULT_FV_UV 4350000
-#define SMB2_DEFAULT_ICL_UA 3000000
+#define SMB2_DEFAULT_FCC_UA    3000000
+#define SMB2_DEFAULT_FV_UV     4350000
+#define SMB2_DEFAULT_ICL_UA    3000000
+#define SMB2_DEFAULT_WPWR_UW   8000000
 
 static struct smb_params v1_params = {
-       .fcc            = {
+       .fcc                    = {
                .name   = "fast charge current",
                .reg    = FAST_CHARGE_CURRENT_CFG_REG,
                .min_u  = 0,
                .max_u  = 4500000,
                .step_u = 25000,
        },
-       .fv             = {
+       .fv                     = {
                .name   = "float voltage",
                .reg    = FLOAT_VOLTAGE_CFG_REG,
-               .min_u  = 3487500,
-               .max_u  = 4920000,
-               .step_u = 7500,
+               .min_u  = 2500000,
+               .max_u  = 5000000,
+               .step_u = 10000,
        },
-       .usb_icl        = {
+       .usb_icl                = {
                .name   = "usb input current limit",
                .reg    = USBIN_CURRENT_LIMIT_CFG_REG,
                .min_u  = 0,
-               .max_u  = 4800000,
+               .max_u  = 6000000,
                .step_u = 25000,
        },
-       .icl_stat       = {
+       .icl_stat               = {
                .name   = "input current limit status",
                .reg    = ICL_STATUS_REG,
                .min_u  = 0,
                .max_u  = 4800000,
                .step_u = 25000,
        },
-       .dc_icl         = {
+       .dc_icl                 = {
                .name   = "dc input current limit",
                .reg    = DCIN_CURRENT_LIMIT_CFG_REG,
                .min_u  = 0,
+               .max_u  = 6000000,
+               .step_u = 25000,
+       },
+       .dc_icl_pt_lv           = {
+               .name   = "dc icl PT <8V",
+               .reg    = ZIN_ICL_PT_REG,
+               .min_u  = 0,
+               .max_u  = 3000000,
+               .step_u = 25000,
+       },
+       .dc_icl_pt_hv           = {
+               .name   = "dc icl PT >8V",
+               .reg    = ZIN_ICL_PT_HV_REG,
+               .min_u  = 0,
+               .max_u  = 3000000,
+               .step_u = 25000,
+       },
+       .dc_icl_div2_lv         = {
+               .name   = "dc icl div2 <5.5V",
+               .reg    = ZIN_ICL_LV_REG,
+               .min_u  = 0,
+               .max_u  = 3000000,
+               .step_u = 25000,
+       },
+       .dc_icl_div2_mid_lv     = {
+               .name   = "dc icl div2 5.5-6.5V",
+               .reg    = ZIN_ICL_MID_LV_REG,
+               .min_u  = 0,
+               .max_u  = 3000000,
+               .step_u = 25000,
+       },
+       .dc_icl_div2_mid_hv     = {
+               .name   = "dc icl div2 6.5-8.0V",
+               .reg    = ZIN_ICL_MID_HV_REG,
+               .min_u  = 0,
+               .max_u  = 3000000,
+               .step_u = 25000,
+       },
+       .dc_icl_div2_hv         = {
+               .name   = "dc icl div2 >8.0V",
+               .reg    = ZIN_ICL_HV_REG,
+               .min_u  = 0,
                .max_u  = 3000000,
                .step_u = 25000,
        },
 };
 
 struct smb_dt_props {
-       bool suspend_input;
-       int fcc_ua;
-       int usb_icl_ua;
-       int dc_icl_ua;
-       int fv_uv;
+       bool    suspend_input;
+       int     fcc_ua;
+       int     usb_icl_ua;
+       int     dc_icl_ua;
+       int     fv_uv;
+       int     wipower_max_uw;
 };
 
 struct smb2 {
@@ -125,6 +169,11 @@ static int smb2_parse_dt(struct smb2 *chip)
        if (rc < 0)
                chip->dt.dc_icl_ua = SMB2_DEFAULT_ICL_UA;
 
+       rc = of_property_read_u32(node,
+                       "qcom,wipower-max-uw", &chip->dt.wipower_max_uw);
+       if (rc < 0)
+               chip->dt.wipower_max_uw = SMB2_DEFAULT_WPWR_UW;
+
        return 0;
 }
 
@@ -486,6 +535,57 @@ static int smb2_init_vconn_regulator(struct smb2 *chip)
 /***************************
  * HARDWARE INITIALIZATION *
  ***************************/
+static int smb2_config_wipower_input_power(struct smb2 *chip, int uw)
+{
+       int rc;
+       int ua;
+       struct smb_charger *chg = &chip->chg;
+       s64 nw = (s64)uw * 1000;
+
+       ua = div_s64(nw, ZIN_ICL_PT_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_pt_lv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_pt_lv rc = %d\n", rc);
+               return rc;
+       }
+
+       ua = div_s64(nw, ZIN_ICL_PT_HV_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_pt_hv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_pt_hv rc = %d\n", rc);
+               return rc;
+       }
+
+       ua = div_s64(nw, ZIN_ICL_LV_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_div2_lv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_div2_lv rc = %d\n", rc);
+               return rc;
+       }
+
+       ua = div_s64(nw, ZIN_ICL_MID_LV_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_div2_mid_lv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_div2_mid_lv rc = %d\n", rc);
+               return rc;
+       }
+
+       ua = div_s64(nw, ZIN_ICL_MID_HV_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_div2_mid_hv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_div2_mid_hv rc = %d\n", rc);
+               return rc;
+       }
+
+       ua = div_s64(nw, ZIN_ICL_HV_MAX_MV);
+       rc = smblib_set_charge_param(chg, &chg->param.dc_icl_div2_hv, ua);
+       if (rc < 0) {
+               pr_err("Couldn't configure dc_icl_div2_hv rc = %d\n", rc);
+               return rc;
+       }
+
+       return 0;
+}
 
 static int smb2_init_hw(struct smb2 *chip)
 {
@@ -582,6 +682,13 @@ static int smb2_init_hw(struct smb2 *chip)
                return rc;
        }
 
+       /* configure wipower watts */
+       rc = smb2_config_wipower_input_power(chip, chip->dt.wipower_max_uw);
+       if (rc < 0) {
+               dev_err(chg->dev, "Couldn't configure wipower rc=%d\n", rc);
+               return rc;
+       }
+
        return rc;
 }
 
index 8b3d00b..1ee4945 100644 (file)
@@ -62,6 +62,12 @@ struct smb_params {
        struct smb_chg_param    usb_icl;
        struct smb_chg_param    icl_stat;
        struct smb_chg_param    dc_icl;
+       struct smb_chg_param    dc_icl_pt_lv;
+       struct smb_chg_param    dc_icl_pt_hv;
+       struct smb_chg_param    dc_icl_div2_lv;
+       struct smb_chg_param    dc_icl_div2_mid_lv;
+       struct smb_chg_param    dc_icl_div2_mid_hv;
+       struct smb_chg_param    dc_icl_div2_hv;
 };
 
 struct parallel_params {
index f63e983..5af01c2 100644 (file)
@@ -719,6 +719,15 @@ enum {
 #define ZIN_ICL_MID_HV_REG                     (DCIN_BASE + 0x98)
 #define ZIN_ICL_MID_HV_MASK                    GENMASK(7, 0)
 
+enum {
+       ZIN_ICL_PT_MAX_MV = 8000,
+       ZIN_ICL_PT_HV_MAX_MV = 9000,
+       ZIN_ICL_LV_MAX_MV = 5500,
+       ZIN_ICL_MID_LV_MAX_MV = 6500,
+       ZIN_ICL_MID_HV_MAX_MV = 8000,
+       ZIN_ICL_HV_MAX_MV = 11000,
+};
+
 /* MISC Peripheral Registers */
 #define REVISION1_REG                          (MISC_BASE + 0x00)
 #define DIG_MINOR_MASK                         GENMASK(7, 0)