power: bq28400: Return error on I2C failure when reading RSOC

Return non-zero Relative-State-Of-Charge (RSOC) when I2C fails.
The battery manager shuts down the device when battery capacity is 0%
(and DC is not on-line).
The battery interface to user space will return error on I2C failure.

Change-Id: I772166746f2c604dd3e10547a108654ee02497c7
Signed-off-by: Amir Samuelov <amirs@codeaurora.org>
diff --git a/drivers/power/bq28400_battery.c b/drivers/power/bq28400_battery.c
index 77e74fa..1852687 100644
--- a/drivers/power/bq28400_battery.c
+++ b/drivers/power/bq28400_battery.c
@@ -395,7 +395,7 @@
 
 /*
  * Return the battery Relative-State-Of-Charge 0..100 %
- * Or 0 if something fails.
+ * Or negative value if something fails.
  */
 static int bq28400_read_rsoc(struct i2c_client *client)
 {
@@ -404,8 +404,10 @@
 	/* This register is only 1 byte */
 	percentage = i2c_smbus_read_byte_data(client, SBS_RSOC);
 
-	if (percentage < 0)
-		return 0;
+	if (percentage < 0) {
+		pr_err("I2C failure when reading rsoc.\n");
+		return percentage;
+	}
 
 	pr_debug("percentage = %d.\n", percentage);
 
@@ -646,6 +648,8 @@
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
 		val->intval = bq28400_read_rsoc(client);
+		if (val->intval < 0)
+			ret = -EINVAL;
 		break;
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		/* Positive current indicates drawing */