kernel:Troika battery profile update
authorxuwei9 <xuwei9@lenovo.com>
Wed, 24 Apr 2019 06:02:57 +0000 (14:02 +0800)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:58 +0000 (20:23 +0300)
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 4aba762dec8e2523338a248988971fb30747b550..3846f5603727718fca1556b1bd257bfccb88e8f3 100755 (executable)
@@ -1507,16 +1507,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();
@@ -1536,30 +1538,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)