kernel:Troika battery profile update
authorxuwei9 <xuwei9@lenovo.com>
Wed, 24 Apr 2019 06:02:57 +0000 (14:02 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Mon, 10 Jun 2019 03:25:17 +0000 (11:25 +0800)
Troika  battery profile update
for local buy battery

Change-Id: I13ad4fe4471814c79645eeeb6d3842814d2b3ea6
Signed-off-by: xuwei9 <xuwei9@mt.com>
Reviewed-on: https://gerrit.mot.com/1341251
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/power/supply/s2mu106_fuelgauge.c

index 64743670a581bc1102aee077fbbd7069d17a16b1..fc0a50bc49c36b21c05f3027f246d7cc5c617719 100755 (executable)
@@ -1499,16 +1499,18 @@ static const char *fg_get_mmi_battid(void)
 static int fg_get_serialnumber(struct s2mu106_fuelgauge_data *chip,
                                               struct device_node *np)
 {
-       const char *sn_buf, *df_sn, *dev_sn;
+       const char *sn_buf, *df_sn, *dev_sn,*sn_buf_local_buy;
        int rc;
        int battery_cell1 = 0;
        int battery_cell2 = 1;
        int battery_index = 0;
+       int battery_default_index = 0;
        bool battery_matched = false;
 
        dev_sn = NULL;
        df_sn = NULL;
        sn_buf = NULL;
+       sn_buf_local_buy = NULL;
        chip->battery_profile_index = 0;
 
        dev_sn = fg_get_mmi_battid();
@@ -1528,30 +1530,70 @@ static int fg_get_serialnumber(struct s2mu106_fuelgauge_data *chip,
        if (rc)
                pr_info("%s, No cell1 Serial Number defined", __func__);
        else {
-               if ((dev_sn && strnstr(dev_sn, sn_buf, 32)) || (df_sn && strnstr(df_sn, sn_buf, 32))) {
+               if (dev_sn && strnstr(dev_sn, sn_buf, 32) ) {
                                battery_matched = true;
                                battery_index = battery_cell1;
                }
+
+               if (df_sn && strnstr(df_sn, sn_buf, 32)) {
+                                battery_default_index = battery_cell1;
+                }
        }
 
+       rc = of_property_read_string(np, "serialnum_cell1_local_buy",
+                                     &sn_buf_local_buy);
+        if (rc)
+                pr_info("%s, No cell1 Serial local buy Number defined", __func__);
+        else {
+                if ((dev_sn && strnstr(dev_sn, sn_buf_local_buy, 32)) ) {
+                                battery_matched = true;
+                                battery_index = battery_cell1;
+                }
+
+                if ((df_sn && strnstr(df_sn, sn_buf_local_buy, 32))) {
+                                battery_default_index = battery_cell1;
+                }
+        }
+
        rc = of_property_read_string(np, "serialnum_cell2",
                                     &sn_buf);
        if (rc)
                pr_info("%s,No cell2 Serial Number defined", __func__);
        else {
-               if ((dev_sn && strnstr(dev_sn, sn_buf, 32)) || (df_sn && strnstr(df_sn, sn_buf, 32))) {
+               if ((dev_sn && strnstr(dev_sn, sn_buf, 32)) ) {
                                battery_matched = true;
                                battery_index = battery_cell2;
                }
+
+               if ((df_sn && strnstr(df_sn, sn_buf, 32))) {
+                                battery_default_index = battery_cell2;
+                }
        }
-       if (battery_matched)
-               pr_info("%s, battery matched index:%d", __func__, battery_index);
-       else
-               pr_info("%s, battery did not matched , use default index:%d", __func__, battery_index);         
 
-       chip->battery_profile_index = battery_index;
+       rc = of_property_read_string(np, "serialnum_cell2_local_buy",
+                                     &sn_buf_local_buy);
+        if (rc)
+                pr_info("%s,No cell2 local buy Serial Number defined", __func__);
+        else {
+                if ((dev_sn && strnstr(dev_sn, sn_buf_local_buy, 32)) ) {
+                                battery_matched = true;
+                                battery_index = battery_cell2;
+                }
+
+               if ((df_sn && strnstr(df_sn, sn_buf_local_buy, 32))) {
+                                battery_default_index = battery_cell2;
+                }
+        }
+
+       if (battery_matched){
+               pr_info("%s, battery matched index:%d", __func__, battery_index);
+               chip->battery_profile_index = battery_index;
+       } else {
+               pr_info("%s, battery did not matched , use default index:%d", __func__, battery_default_index);
+               chip->battery_profile_index = battery_default_index;
+       }
 
-       return battery_index;
+       return chip->battery_profile_index;
 }
 
 static void s2mu106_fuelgauge_select_table(struct s2mu106_fuelgauge_data *fuelgauge)