hwmon: pm8xxx-adc-scale: Change scaling function

Modify the scaling function routines for Battery temperature
and all channels whose units return milli-volts for voltage.

The Charger driver requires the Units of Voltage and temperature
in uV and 0.1 DegC according to the framework where all voltages,
currents, chargers, energies, time and temperature are in uV, uA,
uAh, uWh, seconds and tenths of degree Celsius unless otherwise
stated. In accordance with the above expected units, the scaling
functions are modified for all voltage channels and the Batt Therm.

This change fixes the XO Therm temperature scaling routine,
PA Therm and Batt id to use the ratiometric calibration.
XO Therm and PA therm units are returned as milli-degree and
degree Centigrade respectively.

Accordingly, update the clients of xoadc to handle this change in
units.

CRs-Fixed: 315797
Change-Id: I6fa3b808062563fef3b0e70cc694e3132421f735
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index 74562bc..df2d556 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -552,11 +552,15 @@
 
 static int interpolate_fcc(struct pm8921_bms_chip *chip, int batt_temp)
 {
+	/* batt_temp is in tenths of degC - convert it to degC for lookups */
+	batt_temp = batt_temp/10;
 	return interpolate_single_lut(chip->fcc_temp_lut, batt_temp);
 }
 
 static int interpolate_fcc_adjusted(struct pm8921_bms_chip *chip, int batt_temp)
 {
+	/* batt_temp is in tenths of degC - convert it to degC for lookups */
+	batt_temp = batt_temp/10;
 	return interpolate_single_lut(chip->adjusted_fcc_temp_lut, batt_temp);
 }
 
@@ -672,6 +676,9 @@
 	int rows = chip->pc_temp_ocv_lut->rows;
 	int cols = chip->pc_temp_ocv_lut->cols;
 
+	/* batt_temp is in tenths of degC - convert it to degC for lookups */
+	batt_temp = batt_temp/10;
+
 	if (batt_temp < chip->pc_temp_ocv_lut->temp[0]) {
 		pr_debug("batt_temp %d < known temp range for pc\n", batt_temp);
 		batt_temp = chip->pc_temp_ocv_lut->temp[0];
@@ -854,13 +861,12 @@
 	pr_debug("mvolts phy = %lld meas = 0x%llx", result.physical,
 						result.measurement);
 	*uvolts = (int)result.physical;
-	*uvolts = *uvolts * 1000;
 	return 0;
 }
 
 static int adc_based_ocv(struct pm8921_bms_chip *chip, int *ocv)
 {
-	int vbatt, rbatt, ibatt, rc;
+	int vbatt, rbatt, ibatt_ua, rc;
 	struct pm8921_soc_params raw;
 
 	rc = get_battery_uvolts(chip, &vbatt);
@@ -869,7 +875,7 @@
 		return rc;
 	}
 
-	rc =  pm8921_bms_get_battery_current(&ibatt);
+	rc =  pm8921_bms_get_battery_current(&ibatt_ua);
 	if (rc) {
 		pr_err("failed to read batt current rc = %d\n", rc);
 		return rc;
@@ -880,7 +886,7 @@
 	rbatt = calculate_rbatt(the_chip, &raw);
 	if (rbatt < 0)
 		rbatt = (last_rbatt < 0) ? DEFAULT_RBATT_MOHMS : last_rbatt;
-	*ocv = vbatt + ibatt * rbatt;
+	*ocv = vbatt + (ibatt_ua * rbatt)/1000;
 	return 0;
 }
 
@@ -1138,7 +1144,7 @@
 		return;
 	}
 	voltage = calib_hkadc_convert_microvolt(result.adc_code);
-	pr_debug("result 0.625V = 0x%x, voltage = %duV adc_mead = %lld\n",
+	pr_debug("result 0.625V = 0x%x, voltage = %duV adc_meas = %lld\n",
 				result.adc_code, voltage, result.measurement);
 	/* check for valid range */
 	if (voltage > XOADC_MAX_0P625V)
@@ -1186,7 +1192,7 @@
 }
 EXPORT_SYMBOL(pm8921_bms_get_vsense_avg);
 
-int pm8921_bms_get_battery_current(int *result)
+int pm8921_bms_get_battery_current(int *result_ua)
 {
 	unsigned long flags;
 	int vsense;
@@ -1207,7 +1213,7 @@
 	spin_unlock_irqrestore(&the_chip->bms_output_lock, flags);
 	pr_debug("vsense=%d\n", vsense);
 	/* cast for signed division */
-	*result = vsense / (int)the_chip->r_sense;
+	*result_ua = vsense * 1000 / (int)the_chip->r_sense;
 
 	return 0;
 }