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

Commit 09b2ed6d authored by Manaf Meethalavalappu Pallikunhi's avatar Manaf Meethalavalappu Pallikunhi
Browse files

drivers: thermal: use zero C status as sensor value instead of min temp



The Zero C sensor reports TSENS controller min temperature as its
sensor value to the thermal framework. It requires a low trip
monitor governor in thermal framework to monitor cold
temperature condition.

Instead of min temp value, use TSENS Zero C interrupt status as
sensor value. It removes the need for cold trip monitoring
governor and uses the existing governors to monitor the cold trip
condition and trigger mitigation.

Change-Id: I8bc3a76c5868d679d5f057f8722306a5b8d3fc98
Signed-off-by: default avatarManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>
parent 4d5d2ccd
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -25,11 +25,11 @@ static int tsens_get_temp(void *data, int *temp)
	return tmdev->ops->get_temp(s, temp);
}

static int tsens_get_min_temp(void *data, int *temp)
static int tsens_get_zeroc_status(void *data, int *status)
{
	struct tsens_sensor *s = data;

	return tsens_2xxx_get_min_temp(s, temp);
	return tsens_2xxx_get_zeroc_status(s, status);
}

static int tsens_set_trip_temp(void *data, int low_temp, int high_temp)
@@ -108,7 +108,7 @@ static struct thermal_zone_of_device_ops tsens_tm_thermal_zone_ops = {
};

static struct thermal_zone_of_device_ops tsens_tm_min_thermal_zone_ops = {
	.get_temp = tsens_get_min_temp,
	.get_temp = tsens_get_zeroc_status,
};

static int get_device_tree_data(struct platform_device *pdev,
@@ -119,7 +119,7 @@ static int get_device_tree_data(struct platform_device *pdev,
	const struct tsens_data *data;
	int rc = 0;
	struct resource *res_tsens_mem;
	u32 min_temp_id;
	u32 zeroc_id;

	if (!of_match_node(tsens_table, of_node)) {
		pr_err("Need to read SoC specific fuse map\n");
@@ -195,10 +195,10 @@ static int get_device_tree_data(struct platform_device *pdev,
		}
	}

	if (!of_property_read_u32(of_node, "0C-sensor-num", &min_temp_id))
		tmdev->min_temp_sensor_id = (int)min_temp_id;
	if (!of_property_read_u32(of_node, "0C-sensor-num", &zeroc_id))
		tmdev->zeroc_sensor_id = (int)zeroc_id;
	else
		tmdev->min_temp_sensor_id = MIN_TEMP_DEF_OFFSET;
		tmdev->zeroc_sensor_id = MIN_TEMP_DEF_OFFSET;

	tmdev->tsens_reinit_wa =
		of_property_read_bool(of_node, "tsens-reinit-wa");
@@ -232,14 +232,14 @@ static int tsens_thermal_zone_register(struct tsens_device *tmdev)
		return -ENODEV;
	}

	if (tmdev->min_temp_sensor_id != MIN_TEMP_DEF_OFFSET) {
		tmdev->min_temp.tmdev = tmdev;
		tmdev->min_temp.hw_id = tmdev->min_temp_sensor_id;
		tmdev->min_temp.tzd =
	if (tmdev->zeroc_sensor_id != MIN_TEMP_DEF_OFFSET) {
		tmdev->zeroc.tmdev = tmdev;
		tmdev->zeroc.hw_id = tmdev->zeroc_sensor_id;
		tmdev->zeroc.tzd =
			devm_thermal_zone_of_sensor_register(
			&tmdev->pdev->dev, tmdev->min_temp_sensor_id,
			&tmdev->min_temp, &tsens_tm_min_thermal_zone_ops);
		if (IS_ERR(tmdev->min_temp.tzd))
			&tmdev->pdev->dev, tmdev->zeroc_sensor_id,
			&tmdev->zeroc, &tsens_tm_min_thermal_zone_ops);
		if (IS_ERR(tmdev->zeroc.tzd))
			pr_err("Error registering min temp sensor\n");
	}

@@ -275,8 +275,8 @@ static void tsens_therm_fwk_notify(struct work_struct *work)
				tmdev->sensor[i].tzd, temp);
		}
	}
	if (tmdev->min_temp_sensor_id != MIN_TEMP_DEF_OFFSET) {
		rc = tsens_get_temp(&tmdev->min_temp, &temp);
	if (tmdev->zeroc_sensor_id != MIN_TEMP_DEF_OFFSET) {
		rc = tsens_get_zeroc_status(&tmdev->zeroc, &temp);
		if (rc) {
			pr_err("%s: Error:%d reading temp sensor:%d\n",
				   __func__, rc, i);
@@ -284,7 +284,7 @@ static void tsens_therm_fwk_notify(struct work_struct *work)
		}
		TSENS_DBG(tmdev, "Calling trip_temp for sensor %d\n", i);
		of_thermal_handle_trip_temp(tmdev->dev,
			tmdev->min_temp.tzd, temp);
			tmdev->zeroc.tzd, temp);
	}
}

+4 −4
Original line number Diff line number Diff line
@@ -216,8 +216,8 @@ struct tsens_device {
	const struct tsens_data		*ctrl_data;
	struct tsens_mtc_sysfs  mtcsys;
	int				trdy_fail_ctr;
	struct tsens_sensor		min_temp;
	u8				min_temp_sensor_id;
	struct tsens_sensor		zeroc;
	u8				zeroc_sensor_id;
	struct workqueue_struct		*tsens_reinit_work;
	struct work_struct		therm_fwk_notify;
	bool				tsens_reinit_wa;
@@ -233,7 +233,7 @@ extern struct list_head tsens_device_list;
extern int calibrate_8937(struct tsens_device *tmdev);
extern int calibrate_405(struct tsens_device *tmdev);

extern int tsens_2xxx_get_min_temp(
		struct tsens_sensor *sensor, int *temp);
extern int tsens_2xxx_get_zeroc_status(
		struct tsens_sensor *sensor, int *status);

#endif /* __QCOM_TSENS_H__ */
+13 −71
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#define TSENS_TM_UPPER_LOWER_INT_MASK(n)	((n) + 0x10)
#define TSENS_TM_UPPER_INT_SET(n)		(1 << (n + 16))
#define TSENS_TM_SN_CRITICAL_THRESHOLD_MASK	0xfff
#define TSENS_TM_MIN_TEMP_VALID_BIT		BIT(16)
#define TSENS_TM_SN_STATUS_VALID_BIT		BIT(21)
#define TSENS_TM_SN_STATUS_CRITICAL_STATUS	BIT(19)
#define TSENS_TM_SN_STATUS_UPPER_STATUS		BIT(18)
@@ -61,7 +60,6 @@
#define TSENS_TM_TRDY_FIRST_ROUND_COMPLETE	BIT(3)
#define TSENS_TM_TRDY_FIRST_ROUND_COMPLETE_SHIFT	3
#define TSENS_TM_0C_INT_STATUS(n)	((n) + 0xe0)
#define TSENS_TM_MIN_TEMP(n)	((n) + 0xec)
#define TSENS_TM_0C_THRESHOLDS(n)		((n) + 0x1c)
#define TSENS_MAX_READ_FAIL			50

@@ -226,71 +224,19 @@ static int tsens2xxx_get_temp(struct tsens_sensor *sensor, int *temp)
	return 0;
}

int tsens_2xxx_get_min_temp(struct tsens_sensor *sensor, int *temp)
int tsens_2xxx_get_zeroc_status(struct tsens_sensor *sensor, int *status)
{
	struct tsens_device *tmdev = NULL;
	unsigned int code;
	void __iomem *sensor_addr, *trdy;
	int last_temp = 0, last_temp2 = 0, last_temp3 = 0, valid_bit;
	void __iomem *addr;

	if (!sensor)
		return -EINVAL;

	tmdev = sensor->tmdev;
	trdy = TSENS_TM_TRDY(tmdev->tsens_tm_addr);

	valid_bit = TSENS_TM_MIN_TEMP_VALID_BIT;
	sensor_addr = TSENS_TM_MIN_TEMP(tmdev->tsens_tm_addr);

	code = readl_relaxed_no_log(trdy);
	if (!((code & TSENS_TM_TRDY_FIRST_ROUND_COMPLETE) >>
			TSENS_TM_TRDY_FIRST_ROUND_COMPLETE_SHIFT)) {
		pr_err("tsens device first round not complete0x%x, ctr is %d\n",
			code, tmdev->trdy_fail_ctr);
		tmdev->trdy_fail_ctr++;
		if (tmdev->trdy_fail_ctr >= TSENS_MAX_READ_FAIL) {
			if (tmdev->ops->dbg)
				tmdev->ops->dbg(tmdev, 0,
					TSENS_DBG_LOG_BUS_ID_DATA, NULL);
			BUG();
		}
		return -ENODATA;
	}
	addr = TSENS_TM_0C_INT_STATUS(tmdev->tsens_tm_addr);
	*status = readl_relaxed(addr);

	tmdev->trdy_fail_ctr = 0;

	code = readl_relaxed_no_log(sensor_addr);
	last_temp = code & TSENS_TM_SN_LAST_TEMP_MASK;
	if (code & valid_bit) {
		msm_tsens_convert_temp(last_temp, temp);
		goto dbg;
	}

	code = readl_relaxed_no_log(sensor_addr);
	last_temp2 = code & TSENS_TM_SN_LAST_TEMP_MASK;
	if (code & valid_bit) {
		last_temp = last_temp2;
		msm_tsens_convert_temp(last_temp, temp);
		goto dbg;
	}

	code = readl_relaxed_no_log(sensor_addr);
	last_temp3 = code & TSENS_TM_SN_LAST_TEMP_MASK;
	if (code & valid_bit) {
		last_temp = last_temp3;
		msm_tsens_convert_temp(last_temp, temp);
		goto dbg;
	}

	if (last_temp == last_temp2)
		last_temp = last_temp2;
	else if (last_temp2 == last_temp3)
		last_temp = last_temp3;

	msm_tsens_convert_temp(last_temp, temp);

dbg:
	TSENS_DBG(tmdev, "Min temp: %d\n", *temp);
	TSENS_DBG(tmdev, "ZeroC status: %d\n", *status);

	return 0;
}
@@ -667,7 +613,7 @@ static irqreturn_t tsens_tm_irq_thread(int irq, void *data)
	return IRQ_HANDLED;
}

static irqreturn_t tsens_tm_0C_irq_thread(int irq, void *data)
static irqreturn_t tsens_tm_zeroc_irq_thread(int irq, void *data)
{
	struct tsens_device *tm = data;
	int status, thrs, set_thr, reset_thr;
@@ -680,16 +626,12 @@ static irqreturn_t tsens_tm_0C_irq_thread(int irq, void *data)
	thrs = readl_relaxed(TSENS_TM_0C_THRESHOLDS(srot_addr));

	msm_tsens_convert_temp(thrs & TSENS_TM_0C_THR_MASK, &reset_thr);
	msm_tsens_convert_temp(
		((thrs >> TSENS_TM_0C_THR_OFFSET) &
				TSENS_TM_0C_THR_MASK), &set_thr);
	msm_tsens_convert_temp(((thrs >> TSENS_TM_0C_THR_OFFSET)
			& TSENS_TM_0C_THR_MASK), &set_thr);

	if (status)
		of_thermal_handle_trip_temp(tm->dev,
			tm->min_temp.tzd, set_thr);
	else
		of_thermal_handle_trip_temp(tm->dev,
			tm->min_temp.tzd, reset_thr);
	TSENS_DBG(tm, "Tsens ZeroC status: %d set_t:%d reset_t:%d\n",
		status, set_thr, reset_thr);
	of_thermal_handle_trip_temp(tm->dev, tm->zeroc.tzd, status);

	return IRQ_HANDLED;
}
@@ -778,7 +720,7 @@ static int tsens2xxx_hw_init(struct tsens_device *tmdev)
static const struct tsens_irqs tsens2xxx_irqs[] = {
	{ "tsens-upper-lower", tsens_tm_irq_thread},
	{ "tsens-critical", tsens_tm_critical_irq_thread},
	{ "tsens-0C", tsens_tm_0C_irq_thread},
	{ "tsens-0C", tsens_tm_zeroc_irq_thread},
};

static int tsens2xxx_register_interrupts(struct tsens_device *tmdev)
@@ -790,7 +732,7 @@ static int tsens2xxx_register_interrupts(struct tsens_device *tmdev)
	if (!tmdev)
		return -EINVAL;

	if (tmdev->min_temp_sensor_id != MIN_TEMP_DEF_OFFSET)
	if (tmdev->zeroc_sensor_id != MIN_TEMP_DEF_OFFSET)
		irq_no = ARRAY_SIZE(tsens2xxx_irqs);
	else
		irq_no = ARRAY_SIZE(tsens2xxx_irqs) - 1;