power: pm8921-charger: implement CURRENT_NOW property

The pm8921 bms driver can provide instantaneous current. Use the
current now property of the power_supply class to expose this
feature.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index ac105cc..676b863 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -788,6 +788,24 @@
 }
 EXPORT_SYMBOL(pm8921_bms_get_vsense_avg);
 
+int pm8921_bms_get_battery_current(int *result)
+{
+	if (!the_chip) {
+		pr_err("called before initialization\n");
+		return -EINVAL;
+	}
+	if (the_chip->r_sense == 0) {
+		pr_err("r_sense is zero\n");
+		return -EINVAL;
+	}
+
+	read_vsense_avg(the_chip, result);
+	pr_debug("vsense=%d\n", *result);
+	*result = *result / the_chip->r_sense;
+	return 0;
+}
+EXPORT_SYMBOL(pm8921_bms_get_battery_current);
+
 int pm8921_bms_get_percent_charge(void)
 {
 	int batt_temp, rc;
@@ -1091,7 +1109,7 @@
 	}
 	return ret;
 }
-DEFINE_SIMPLE_ATTRIBUTE(reading_fops, get_reading, NULL, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(reading_fops, get_reading, NULL, "%lld\n");
 
 static int get_rt_status(void *data, u64 * val)
 {
diff --git a/drivers/power/pm8921-charger.c b/drivers/power/pm8921-charger.c
index 0e46b0b..d2cba64 100644
--- a/drivers/power/pm8921-charger.c
+++ b/drivers/power/pm8921-charger.c
@@ -517,6 +517,7 @@
 	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_CURRENT_NOW,
 };
 
 static int get_prop_battery_mvolts(struct pm8921_chg_chip *chip)
@@ -545,6 +546,19 @@
 	return percent_soc;
 }
 
+static int get_prop_batt_current(struct pm8921_chg_chip *chip)
+{
+	int result_ma, rc;
+
+	rc = pm8921_bms_get_battery_current(&result_ma);
+	if (rc) {
+		pr_err("unable to get batt current rc = %d\n", rc);
+		return rc;
+	} else {
+		return result_ma;
+	}
+}
+
 static int get_prop_batt_health(struct pm8921_chg_chip *chip)
 {
 	int temp;
@@ -638,6 +652,9 @@
 	case POWER_SUPPLY_PROP_CAPACITY:
 		val->intval = get_prop_batt_capacity(chip);
 		break;
+	case POWER_SUPPLY_PROP_CURRENT_NOW:
+		val->intval = get_prop_batt_current(chip);
+		break;
 	default:
 		return -EINVAL;
 	}
diff --git a/include/linux/mfd/pm8xxx/pm8921-bms.h b/include/linux/mfd/pm8xxx/pm8921-bms.h
index 5cd9952..1773dea 100644
--- a/include/linux/mfd/pm8xxx/pm8921-bms.h
+++ b/include/linux/mfd/pm8xxx/pm8921-bms.h
@@ -114,14 +114,31 @@
 /**
  * pm8921_bms_get_vsense_avg - return the voltage across the sense
  *				resitor in microvolts
- * @result:	The pointer where the voltage will be updated
+ * @result:	The pointer where the voltage will be updated. A -ve
+ *		result means that the current is flowing in
+ *		the battery - during battery charging
  *
  * RETURNS:	Error code if there was a problem reading vsense, Zero otherwise
  *		The result won't be updated in case of an error.
+ *
+ *
  */
 int pm8921_bms_get_vsense_avg(int *result);
 
 /**
+ * pm8921_bms_get_battery_current - return the battery current based on vsense
+ *				resitor in milliamperes
+ * @result:	The pointer where the voltage will be updated. A -ve
+ *		result means that the current is flowing in
+ *		the battery - during battery charging
+ *
+ * RETURNS:	Error code if there was a problem reading vsense, Zero otherwise
+ *		The result won't be updated in case of an error.
+ *
+ */
+int pm8921_bms_get_battery_current(int *result);
+
+/**
  * pm8921_bms_get_percent_charge - returns the current battery charge in percent
  *
  */
@@ -143,6 +160,10 @@
 {
 	return -ENXIO;
 }
+static inline int pm8921_bms_get_battery_current(int *result)
+{
+	return -ENXIO;
+}
 static inline int pm8921_bms_get_percent_charge(void)
 {
 	return -ENXIO;