google_battery: add batt_vs thermal zone
batt_VS = batt_therm - W * (batt_curr)^2
Bug: 214310583
Signed-off-by: Wasb Liu <[email protected]>
Change-Id: If228760077f1df9a7cecd569630df13fc9ae9038
diff --git a/google_battery.c b/google_battery.c
index 96dfbaf..704cf17 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -376,6 +376,10 @@
/* thermal */
struct thermal_zone_device *tz_dev;
+ /* battery virtual sensor */
+ struct thermal_zone_device *batt_vs_tz;
+ int batt_vs_w;
+
/* Resistance */
struct batt_res res_state;
@@ -444,6 +448,35 @@
return 0;
}
+static int batt_vs_tz_get(struct thermal_zone_device *tzd, int *batt_vs)
+{
+ struct batt_drv *batt_drv = tzd->devdata;
+ int temp, rc;
+ unsigned int ibat;
+ unsigned long vs_tmp;
+
+ if (!batt_vs)
+ return -EINVAL;
+
+ temp = GPSY_GET_INT_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_TEMP, &rc) * 100;
+ if (rc)
+ return -EINVAL;
+
+ ibat = abs(GPSY_GET_INT_PROP(batt_drv->fg_psy, POWER_SUPPLY_PROP_CURRENT_AVG, &rc));
+ if (rc)
+ return -EINVAL;
+
+ vs_tmp = mul_u32_u32(ibat, ibat) * batt_drv->batt_vs_w / 1000000000000;
+
+ *batt_vs = temp - vs_tmp;
+
+ return 0;
+}
+
+static struct thermal_zone_device_ops batt_vs_tz_ops = {
+ .get_temp = batt_vs_tz_get,
+};
+
static int psy_changed(struct notifier_block *nb,
unsigned long action, void *data)
{
@@ -5401,6 +5434,9 @@
debugfs_create_file("chg_raw_profile", 0644, de, batt_drv,
&debug_chg_raw_profile_fops);
+ /* battery virtual sensor*/
+ debugfs_create_u32("batt_vs_w", 0600, de, &batt_drv->batt_vs_w);
+
return 0;
}
@@ -6480,6 +6516,7 @@
init_work.work);
struct device_node *node = batt_drv->device->of_node;
struct power_supply *fg_psy = batt_drv->fg_psy;
+ const char *batt_vs_tz_name = NULL;
int ret = 0;
batt_rl_reset(batt_drv);
@@ -6709,6 +6746,26 @@
if (!batt_drv->history)
pr_err("history not available\n");
+ /* battery virtual sensor */
+ ret = of_property_read_string(batt_drv->device->of_node,
+ "google,batt-vs-tz-name",
+ &batt_vs_tz_name);
+ if (ret == 0) {
+ batt_drv->batt_vs_tz =
+ thermal_zone_device_register(batt_vs_tz_name, 0, 0,
+ batt_drv, &batt_vs_tz_ops, NULL, 0, 0);
+ if (IS_ERR(batt_drv->batt_vs_tz)) {
+ pr_err("batt_vs tz register failed. err:%ld\n",
+ PTR_ERR(batt_drv->batt_vs_tz));
+ batt_drv->batt_vs_tz = NULL;
+ } else {
+ thermal_zone_device_update(batt_drv->batt_vs_tz, THERMAL_DEVICE_UP);
+ }
+ batt_drv->batt_vs_w = 88;
+
+ pr_info("google,batt-vs-tz-name is %s\n", batt_vs_tz_name);
+ }
+
/* debugfs */
(void)batt_init_fs(batt_drv);