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

Commit 63c6d6d9 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 04149f35
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ First Level Node - FG Gen4 device
	Definition: Should specify the phandle of PMIC revid module. This is
		    used to identify the PMIC subtype.

- #thermal-sensor-cells: Should be 0. See thermal.txt for the description.

- qcom,fg-cutoff-voltage
	Usage:      optional
	Value type: <u32>
@@ -423,6 +425,7 @@ pm8150b_fg: qpnp,fg {
	#address-cells = <1>;
	#size-cells = <1>;
	qcom,pmic-revid = <&pm8150b_revid>;
	#thermal-cells = <0>;
	status = "okay";

	qcom,fg-batt-soc@4000 {
@@ -487,3 +490,32 @@ pm8150b_fg: qpnp,fg {
	};

};

======================================
Example for thermal zone configuration
======================================

thermal_zones {
	pm8150b_fg {
		polling-delay-passive = <200>;
		polling-delay = <200>;
		thermal-governor = "user_space";
		thermal-sensors = <&pm8150b_fg>;

		pm8150b_fg_trip1: pm8150b-fg-trip1 {
			temperature = <40000>;
			hysteresis = <0>;
			type = "passive";
		};
		pm8150b_fg_trip2: pm8150b-fg-trip2 {
			temperature = <45000>;
			hysteresis = <0>;
			type = "passive";
		};
		pm8150b_fg_trip3: pm8150b-fg-trip3 {
			temperature = <55000>;
			hysteresis = <0>;
			type = "passive";
		};
	};
};
+1 −0
Original line number Diff line number Diff line
@@ -402,6 +402,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
@@ -19,6 +19,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"
@@ -659,6 +660,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;
@@ -4898,6 +4920,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);