diff options
Diffstat (limited to 'drivers/of/of_batterydata.c')
-rw-r--r-- | drivers/of/of_batterydata.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/of/of_batterydata.c b/drivers/of/of_batterydata.c index 4410f270f557..64ff988cdfa8 100644 --- a/drivers/of/of_batterydata.c +++ b/drivers/of/of_batterydata.c @@ -20,6 +20,8 @@ #include <linux/batterydata-lib.h> #include <linux/power_supply.h> +#define SUPPORT_LENUK_BATTERY_ID_ALGO + static int of_batterydata_read_lut(const struct device_node *np, int max_cols, int max_rows, int *ncols, int *nrows, int *col_legend_data, int *row_legend_data, @@ -353,6 +355,32 @@ struct device_node *of_batterydata_get_best_profile( if (rc) continue; for (i = 0; i < batt_ids.num; i++) { +#ifdef SUPPORT_LENUK_BATTERY_ID_ALGO + if (((batt_id_kohm >= 1) && (batt_id_kohm < 20) && (batt_ids.kohm[i] == 9)) + || ((batt_id_kohm >= 20) && (batt_id_kohm < 80) && (batt_ids.kohm[i] == 50)) + || ((batt_id_kohm >= 80) && (batt_id_kohm < 120) && (batt_ids.kohm[i] == 100))) { + best_node = node; + best_id_kohm = batt_ids.kohm[i]; + in_range = false; + limit = 0; + best_delta = 0; + delta = 0; + break; + } else { + pr_info("using relaxed battery checks\n"); + if ((batt_ids.kohm[i] == 9) || + (batt_ids.kohm[i] == 50) || + (batt_ids.kohm[i] == 100)) { + best_node = node; + best_id_kohm = batt_ids.kohm[i]; + in_range = false; + limit = 0; + best_delta = 0; + delta = 0; + break; + } + } +#else delta = abs(batt_ids.kohm[i] - batt_id_kohm); limit = (batt_ids.kohm[i] * id_range_pct) / 100; in_range = (delta <= limit); @@ -367,6 +395,7 @@ struct device_node *of_batterydata_get_best_profile( best_delta = delta; best_id_kohm = batt_ids.kohm[i]; } +#endif } } } @@ -376,6 +405,10 @@ struct device_node *of_batterydata_get_best_profile( return best_node; } +#ifdef SUPPORT_LENUK_BATTERY_ID_ALGO + pr_info("profile id %d batt id %d", + best_id_kohm, batt_id_kohm); +#else /* check that profile id is in range of the measured batt_id */ if (abs(best_id_kohm - batt_id_kohm) > ((best_id_kohm * id_range_pct) / 100)) { @@ -383,6 +416,7 @@ struct device_node *of_batterydata_get_best_profile( best_id_kohm, batt_id_kohm, id_range_pct); return NULL; } +#endif rc = of_property_read_string(best_node, "qcom,battery-type", &battery_type); @@ -426,15 +460,40 @@ int of_batterydata_read_data(struct device_node *batterydata_container_node, if (rc) continue; for (i = 0; i < batt_ids.num; i++) { +#ifdef SUPPORT_LENUK_BATTERY_ID_ALGO + if (((batt_id_kohm >= 1) && (batt_id_kohm < 20) && (batt_ids.kohm[i] == 9)) + || ((batt_id_kohm >= 20) && (batt_id_kohm < 80) && (batt_ids.kohm[i] == 50)) + || ((batt_id_kohm >= 80) && (batt_id_kohm < 120) && (batt_ids.kohm[i] == 100))) { + best_node = node; + best_id_kohm = batt_ids.kohm[i]; + delta = 0; + break; + } else { + pr_info("using relaxed battery checks\n"); + if ((batt_ids.kohm[i] == 9) || + (batt_ids.kohm[i] == 50) || + (batt_ids.kohm[i] == 100)) { + best_node = node; + best_id_kohm = batt_ids.kohm[i]; + delta = 0; + break; + } + } +#else delta = abs(batt_ids.kohm[i] - batt_id_kohm); if (delta < best_delta || !best_node) { best_node = node; best_delta = delta; best_id_kohm = batt_ids.kohm[i]; } +#endif } } +#ifdef SUPPORT_LENUK_BATTERY_ID_ALGO + pr_info("profile id %d batt id %d", + best_id_kohm, batt_id_kohm); +#endif if (best_node == NULL) { pr_err("No battery data found\n"); return -ENODATA; |