google_battery: Add write permission for charging_speed

For debugging purpose

Bug: 209865753
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: I105ca8747ee6e7917460044a1d40b550563dc50d
diff --git a/google_battery.c b/google_battery.c
index fb25d6f..44557f2 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -434,6 +434,7 @@
 	/* CSI: charging speed */
 	struct gvotable_election *csi_status_votable;
 	struct gvotable_election *csi_type_votable;
+	int fake_charging_speed;
 	int charging_speed;
 	int nominal_demand;
 
@@ -2351,6 +2352,9 @@
 	if (is_disconnected)
 		return -1;
 
+	if (batt_drv->fake_charging_speed)
+		return batt_drv->fake_charging_speed;
+
 	/* Get average current via tiers. */
 	vbatt_idx = ttf_pwr_vtier_idx(&batt_drv->ttf_stats, soc);
 	ibatt = ttf_pwr_ibatt(&batt_drv->ce_data.tier_stats[vbatt_idx]);
@@ -5482,6 +5486,24 @@
 
 static const DEVICE_ATTR_RW(health_algo);
 
+static ssize_t charging_speed_store(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+	struct power_supply *psy = container_of(dev, struct power_supply, dev);
+	struct batt_drv *batt_drv = power_supply_get_drvdata(psy);
+	int value, ret;
+
+	ret = kstrtoint(buf, 0, &value);
+	if (ret < 0)
+		return ret;
+
+	pr_info("fake_charging_speed: %d -> %d\n", batt_drv->fake_charging_speed, value);
+	batt_drv->fake_charging_speed = value;
+
+	return count;
+}
+
 static ssize_t charging_speed_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
@@ -5491,7 +5513,7 @@
 	return scnprintf(buf, PAGE_SIZE, "%d\n", batt_drv->charging_speed);
 }
 
-static const DEVICE_ATTR_RO(charging_speed);
+static const DEVICE_ATTR_RW(charging_speed);
 
 static ssize_t power_metrics_polling_rate_store(struct device *dev,
 						struct device_attribute *attr,