power: pm8921-bms: fix converting vbatt readings to microvolt

The constants used in the calculation to convert vbatt raw readings
to microvolts are incorrect. All vbat readings go through a 1/3rd scaling
before going to xoadc. IOW the xoadc reads 1/3rd of vbatt.

Fix the constants to account for it.

While at it, convert to using a function instead of a macro - to avail
of automatic type checking from the compiler.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index d775881..cdf33e7 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -192,10 +192,15 @@
 	return 0;
 }
 
-#define V_PER_BIT_MUL_FACTOR	977
-#define V_PER_BIT_DIV_FACTOR	10
-#define CONV_READING(a)		(((a) * (int)V_PER_BIT_MUL_FACTOR)\
-				/V_PER_BIT_DIV_FACTOR)
+#define V_PER_BIT_MUL_FACTOR	293
+#define INTRINSIC_OFFSET	0x6000
+static int vbatt_to_microvolt(unsigned int a)
+{
+	if (a <= INTRINSIC_OFFSET)
+		return 0;
+
+	return (a - INTRINSIC_OFFSET) * V_PER_BIT_MUL_FACTOR;
+}
 
 #define CC_RESOLUTION_N_V1	1085069
 #define CC_RESOLUTION_D_V1	100000
@@ -262,7 +267,7 @@
 		pr_err("fail to read LAST_GOOD_OCV_VALUE rc = %d\n", rc);
 		return rc;
 	}
-	*result = CONV_READING(reading);
+	*result = vbatt_to_microvolt(reading);
 	pr_debug("raw = %04x ocv_microV = %u\n", reading, *result);
 	return 0;
 }
@@ -277,7 +282,7 @@
 		pr_err("fail to read VBATT_FOR_RBATT rc = %d\n", rc);
 		return rc;
 	}
-	*result = CONV_READING(reading);
+	*result = vbatt_to_microvolt(reading);
 	pr_debug("raw = %04x vbatt_for_r_microV = %u\n", reading, *result);
 	return 0;
 }
@@ -307,7 +312,7 @@
 		pr_err("fail to read OCV_FOR_RBATT rc = %d\n", rc);
 		return rc;
 	}
-	*result = CONV_READING(reading);
+	*result = vbatt_to_microvolt(reading);
 	pr_debug("read = %04x ocv_for_r_microV = %u\n", reading, *result);
 	return 0;
 }