Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c785eca authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-fg-gen4: add support to register with thermal core framework



Add support to register FG driver to register with thermal core
framework so that the battery temperature can be monitored by any
thermal governor and userspace is one of them.

Change-Id: Ib828474cf464d78be4bf843b6b59a6adabe005cf
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent fa29e922
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -395,6 +395,7 @@ struct fg_memif {
};

struct fg_dev {
	struct thermal_zone_device	*tz_dev;
	struct device		*dev;
	struct pmic_revid_data	*pmic_rev_id;
	struct regmap		*regmap;
+31 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include <linux/of_batterydata.h>
#include <linux/platform_device.h>
#include <linux/qpnp/qpnp-revid.h>
#include <linux/thermal.h>
#include "fg-core.h"
#include "fg-reg.h"
#include "fg-alg.h"
@@ -681,6 +682,27 @@ static int fg_gen4_get_battery_temp(struct fg_dev *fg, int *val)
	return 0;
}

static int fg_gen4_tz_get_temp(void *data, int *temperature)
{
	struct fg_dev *fg = (struct fg_dev *)data;
	int rc, temp;

	if (!temperature)
		return -EINVAL;

	rc = fg_gen4_get_battery_temp(fg, &temp);
	if (rc < 0)
		return rc;

	/* Convert deciDegC to milliDegC */
	*temperature = temp * 100;
	return rc;
}

static struct thermal_zone_of_device_ops fg_gen4_tz_ops = {
	.get_temp = fg_gen4_tz_get_temp,
};

static int fg_gen4_get_debug_batt_id(struct fg_dev *fg, int *batt_id)
{
	int rc;
@@ -4976,6 +4998,15 @@ static int fg_gen4_probe(struct platform_device *pdev)
			msoc, volt_uv, batt_temp, fg->batt_id_ohms);
	}

	fg->tz_dev = thermal_zone_of_sensor_register(fg->dev, 0, fg,
							&fg_gen4_tz_ops);
	if (IS_ERR_OR_NULL(fg->tz_dev)) {
		rc = PTR_ERR(fg->tz_dev);
		fg->tz_dev = NULL;
		dev_dbg(fg->dev, "Couldn't register with thermal framework rc:%d\n",
			rc);
	}

	device_init_wakeup(fg->dev, true);
	if (!fg->battery_missing)
		schedule_delayed_work(&fg->profile_load_work, 0);