From 2a59d9e88ad8337296cff869466af1bc1f702242 Mon Sep 17 00:00:00 2001 From: Anirudh Ghayal Date: Fri, 2 Aug 2019 16:56:14 +0530 Subject: power: qpnp-qg: Update the function names for QG Update the QG profile handling function names by adding a prefix "qg_", this is to differentiate it from the generic battery profile function definitions. While at it, expose the linear_interpolate function for it to be usable in the QG driver. Change-Id: I58214402b2d79feb25209f5a1451d3f41edf181a Signed-off-by: Anirudh Ghayal --- drivers/power/supply/qcom/qg-battery-profile.c | 18 ++++++++------ drivers/power/supply/qcom/qg-profile-lib.c | 34 +++++++++++++------------- drivers/power/supply/qcom/qg-profile-lib.h | 11 +++++---- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/drivers/power/supply/qcom/qg-battery-profile.c b/drivers/power/supply/qcom/qg-battery-profile.c index beb6f519539e..744f26dc7930 100644 --- a/drivers/power/supply/qcom/qg-battery-profile.c +++ b/drivers/power/supply/qcom/qg-battery-profile.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2018 The Linux Foundation. All rights reserved. +/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * * 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 @@ -107,7 +107,8 @@ static long qg_battery_data_ioctl(struct file *file, unsigned int cmd, rc = -EINVAL; } else { /* OCV is passed as deci-uV - 10^-4 V */ - soc = interpolate_soc(&battery->profile[bp.table_index], + soc = qg_interpolate_soc( + &battery->profile[bp.table_index], bp.batt_temp, UV_TO_DECIUV(bp.ocv_uv)); soc = CAP(QG_MIN_SOC, QG_MAX_SOC, soc); rc = put_user(soc, &bp_user->soc); @@ -127,7 +128,7 @@ static long qg_battery_data_ioctl(struct file *file, unsigned int cmd, bp.table_index); rc = -EINVAL; } else { - ocv_uv = interpolate_var( + ocv_uv = qg_interpolate_var( &battery->profile[bp.table_index], bp.batt_temp, bp.soc); ocv_uv = DECIUV_TO_UV(ocv_uv); @@ -149,7 +150,7 @@ static long qg_battery_data_ioctl(struct file *file, unsigned int cmd, bp.table_index); rc = -EINVAL; } else { - fcc_mah = interpolate_single_row_lut( + fcc_mah = qg_interpolate_single_row_lut( &battery->profile[bp.table_index], bp.batt_temp, DEGC_SCALE); fcc_mah = CAP(QG_MIN_FCC_MAH, QG_MAX_FCC_MAH, fcc_mah); @@ -169,7 +170,8 @@ static long qg_battery_data_ioctl(struct file *file, unsigned int cmd, bp.table_index); rc = -EINVAL; } else { - var = interpolate_var(&battery->profile[bp.table_index], + var = qg_interpolate_var( + &battery->profile[bp.table_index], bp.batt_temp, bp.soc); var = CAP(QG_MIN_VAR, QG_MAX_VAR, var); rc = put_user(var, &bp_user->var); @@ -189,7 +191,7 @@ static long qg_battery_data_ioctl(struct file *file, unsigned int cmd, bp.table_index); rc = -EINVAL; } else { - slope = interpolate_slope( + slope = qg_interpolate_slope( &battery->profile[bp.table_index], bp.batt_temp, bp.soc); slope = CAP(QG_MIN_SLOPE, QG_MAX_SLOPE, slope); @@ -401,7 +403,7 @@ int lookup_soc_ocv(u32 *soc, u32 ocv_uv, int batt_temp, bool charging) if (!the_battery || !the_battery->profile_node) return -ENODEV; - *soc = interpolate_soc(&the_battery->profile[table_index], + *soc = qg_interpolate_soc(&the_battery->profile[table_index], batt_temp, UV_TO_DECIUV(ocv_uv)); *soc = CAP(0, 100, DIV_ROUND_CLOSEST(*soc, 100)); @@ -417,7 +419,7 @@ int qg_get_nominal_capacity(u32 *nom_cap_uah, int batt_temp, bool charging) if (!the_battery || !the_battery->profile_node) return -ENODEV; - fcc_mah = interpolate_single_row_lut( + fcc_mah = qg_interpolate_single_row_lut( &the_battery->profile[table_index], batt_temp, DEGC_SCALE); fcc_mah = CAP(QG_MIN_FCC_MAH, QG_MAX_FCC_MAH, fcc_mah); diff --git a/drivers/power/supply/qcom/qg-profile-lib.c b/drivers/power/supply/qcom/qg-profile-lib.c index 2af997ecac0e..c506fea51cdb 100644 --- a/drivers/power/supply/qcom/qg-profile-lib.c +++ b/drivers/power/supply/qcom/qg-profile-lib.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2018 The Linux Foundation. All rights reserved. +/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * * 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 @@ -16,7 +16,7 @@ #include "qg-profile-lib.h" #include "qg-defs.h" -static int linear_interpolate(int y0, int x0, int y1, int x1, int x) +int qg_linear_interpolate(int y0, int x0, int y1, int x1, int x) { if (y0 == y1 || x == x0) return y0; @@ -26,7 +26,7 @@ static int linear_interpolate(int y0, int x0, int y1, int x1, int x) return y0 + ((y1 - y0) * (x - x0) / (x1 - x0)); } -int interpolate_single_row_lut(struct profile_table_data *lut, +int qg_interpolate_single_row_lut(struct profile_table_data *lut, int x, int scale) { int i, result; @@ -52,7 +52,7 @@ int interpolate_single_row_lut(struct profile_table_data *lut, if (x == lut->col_entries[i] * scale) { result = lut->data[0][i]; } else { - result = linear_interpolate( + result = qg_linear_interpolate( lut->data[0][i-1], lut->col_entries[i-1] * scale, lut->data[0][i], @@ -63,7 +63,7 @@ int interpolate_single_row_lut(struct profile_table_data *lut, return result; } -int interpolate_soc(struct profile_table_data *lut, +int qg_interpolate_soc(struct profile_table_data *lut, int batt_temp, int ocv) { int i, j, soc_high, soc_low, soc; @@ -94,7 +94,7 @@ int interpolate_soc(struct profile_table_data *lut, if (ocv >= lut->data[i][j]) { if (ocv == lut->data[i][j]) return lut->row_entries[i]; - soc = linear_interpolate( + soc = qg_linear_interpolate( lut->row_entries[i], lut->data[i][j], lut->row_entries[i - 1], @@ -115,7 +115,7 @@ int interpolate_soc(struct profile_table_data *lut, for (i = 0; i < rows-1; i++) { if (soc_high == 0 && is_between(lut->data[i][j], lut->data[i+1][j], ocv)) { - soc_high = linear_interpolate( + soc_high = qg_linear_interpolate( lut->row_entries[i], lut->data[i][j], lut->row_entries[i + 1], @@ -125,7 +125,7 @@ int interpolate_soc(struct profile_table_data *lut, if (soc_low == 0 && is_between(lut->data[i][j-1], lut->data[i+1][j-1], ocv)) { - soc_low = linear_interpolate( + soc_low = qg_linear_interpolate( lut->row_entries[i], lut->data[i][j-1], lut->row_entries[i + 1], @@ -134,7 +134,7 @@ int interpolate_soc(struct profile_table_data *lut, } if (soc_high && soc_low) { - soc = linear_interpolate( + soc = qg_linear_interpolate( soc_low, lut->col_entries[j-1] * DEGC_SCALE, soc_high, @@ -155,7 +155,7 @@ int interpolate_soc(struct profile_table_data *lut, return 10000; } -int interpolate_var(struct profile_table_data *lut, +int qg_interpolate_var(struct profile_table_data *lut, int batt_temp, int soc) { int i, var1, var2, var, rows, cols; @@ -199,7 +199,7 @@ int interpolate_var(struct profile_table_data *lut, break; if (batt_temp == lut->col_entries[i] * DEGC_SCALE) { - var = linear_interpolate( + var = qg_linear_interpolate( lut->data[row1][i], lut->row_entries[row1], lut->data[row2][i], @@ -208,21 +208,21 @@ int interpolate_var(struct profile_table_data *lut, return var; } - var1 = linear_interpolate( + var1 = qg_linear_interpolate( lut->data[row1][i - 1], lut->col_entries[i - 1] * DEGC_SCALE, lut->data[row1][i], lut->col_entries[i] * DEGC_SCALE, batt_temp); - var2 = linear_interpolate( + var2 = qg_linear_interpolate( lut->data[row2][i - 1], lut->col_entries[i - 1] * DEGC_SCALE, lut->data[row2][i], lut->col_entries[i] * DEGC_SCALE, batt_temp); - var = linear_interpolate( + var = qg_linear_interpolate( var1, lut->row_entries[row1], var2, @@ -232,7 +232,7 @@ int interpolate_var(struct profile_table_data *lut, return var; } -int interpolate_slope(struct profile_table_data *lut, +int qg_interpolate_slope(struct profile_table_data *lut, int batt_temp, int soc) { int i, ocvrow1, ocvrow2, rows, cols; @@ -284,14 +284,14 @@ int interpolate_slope(struct profile_table_data *lut, lut->row_entries[row2]); return slope; } - ocvrow1 = linear_interpolate( + ocvrow1 = qg_linear_interpolate( lut->data[row1][i - 1], lut->col_entries[i - 1] * DEGC_SCALE, lut->data[row1][i], lut->col_entries[i] * DEGC_SCALE, batt_temp); - ocvrow2 = linear_interpolate( + ocvrow2 = qg_linear_interpolate( lut->data[row2][i - 1], lut->col_entries[i - 1] * DEGC_SCALE, lut->data[row2][i], diff --git a/drivers/power/supply/qcom/qg-profile-lib.h b/drivers/power/supply/qcom/qg-profile-lib.h index eb7263dd7395..48408e04ab42 100644 --- a/drivers/power/supply/qcom/qg-profile-lib.h +++ b/drivers/power/supply/qcom/qg-profile-lib.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2018 The Linux Foundation. All rights reserved. +/* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * * 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 @@ -22,13 +22,14 @@ struct profile_table_data { int **data; }; -int interpolate_single_row_lut(struct profile_table_data *lut, +int qg_linear_interpolate(int y0, int x0, int y1, int x1, int x); +int qg_interpolate_single_row_lut(struct profile_table_data *lut, int x, int scale); -int interpolate_soc(struct profile_table_data *lut, +int qg_interpolate_soc(struct profile_table_data *lut, int batt_temp, int ocv); -int interpolate_var(struct profile_table_data *lut, +int qg_interpolate_var(struct profile_table_data *lut, int batt_temp, int soc); -int interpolate_slope(struct profile_table_data *lut, +int qg_interpolate_slope(struct profile_table_data *lut, int batt_temp, int soc); #endif /*__QG_PROFILE_LIB_H__ */ -- cgit v1.2.3