OSDN Git Service

of_batterydata: add fallback to generic node
authordianlujitao <dianlujitao@lineageos.org>
Sat, 22 Sep 2018 12:02:56 +0000 (20:02 +0800)
committerArian <arian.kulmer@web.de>
Tue, 19 Nov 2019 15:24:31 +0000 (16:24 +0100)
Change-Id: Ic8b1c163a20a787e3d485a8ec27eebb6b0c25d32

drivers/of/of_batterydata.c

index 4410f27..9237dfa 100644 (file)
@@ -1,4 +1,5 @@
 /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2018 XiaoMi, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -315,7 +316,11 @@ struct device_node *of_batterydata_get_best_profile(
                int batt_id_kohm, const char *batt_type)
 {
        struct batt_ids batt_ids;
+#ifdef CONFIG_MACH_XIAOMI_MSM8998
+       struct device_node *node, *best_node = NULL, *generic_node = NULL;
+#else
        struct device_node *node, *best_node = NULL;
+#endif
        const char *battery_type = NULL;
        int delta = 0, best_delta = 0, best_id_kohm = 0, id_range_pct,
                i = 0, rc = 0, limit = 0;
@@ -369,10 +374,23 @@ struct device_node *of_batterydata_get_best_profile(
                                }
                        }
                }
+#ifdef CONFIG_MACH_XIAOMI_MSM8998
+               rc = of_property_read_string(node, "qcom,battery-type",
+                                                       &battery_type);
+               if (!rc && strcmp(battery_type, "itech_3000mah") == 0)
+                               generic_node = node;
+#endif
        }
 
        if (best_node == NULL) {
+#ifdef CONFIG_MACH_XIAOMI_MSM8998
+               /* now that best_node is null, there is no need to
+                * check whether generic node is null. */
+               best_node = generic_node;
+               pr_err("No battery data found,use generic one\n");
+#else
                pr_err("No battery data found\n");
+#endif
                return best_node;
        }