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

Commit 6c213874 authored by Siddartha Mohanadoss's avatar Siddartha Mohanadoss
Browse files

thermal: tsens: Read raw qtimer value



Read the raw qtimer value when starting the detection run
and when we receive a completion to correlate the timer
values with the last VDD minimization. In addition fix
overwriting TSENS_DEBUG_BUS_SEL field when writing from
0 through 0xf.

Change-Id: Id79d9f6c5d60a2771bc9f03a9cec58ce472aa5d6
Signed-off-by: default avatarSiddartha Mohanadoss <smohanad@codeaurora.org>
parent 3d3842ae
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <linux/of.h>
#include <linux/debugfs.h>
#include <linux/vmalloc.h>
#include <asm/arch_timer.h>

#define CREATE_TRACE_POINTS
#include <trace/trace_thermal.h>
@@ -719,6 +720,7 @@
#define TSENS_DEBUG_DECIDEGC		-400
#define TSENS_DEBUG_MIN_CYCLE		63000
#define TSENS_DEBUG_MAX_CYCLE		64000
#define TSENS_DEBUG_ID_MASK_1_4		0xffffffe1

static uint32_t tsens_sec_to_msec_value = 3000;
static uint32_t tsens_completion_timeout_hz = 2 * HZ;
@@ -830,6 +832,9 @@ struct tsens_tm_device {
	unsigned long long		crit_timestamp_last_run;
	unsigned long long		crit_timestamp_last_interrupt_handled;
	unsigned long long		crit_timestamp_last_poll_request;
	u64				qtimer_val_detection_start;
	u64				qtimer_val_last_detection_interrupt;
	u64				qtimer_val_last_polling_check;
	struct tsens_tm_device_sensor	sensor[0];
};

@@ -1883,6 +1888,7 @@ static void tsens_poll(struct work_struct *work)
	struct tsens_tm_device *tmdev = container_of(work,
		       struct tsens_tm_device, tsens_critical_poll_test.work);
	unsigned int reg_cntl, mask, rc = 0, debug_dump, i = 0, loop = 0;
	unsigned int debug_id = 0;
	uint32_t r1, r2, r3, r4, offset = 0;
	unsigned long temp, flags;
	unsigned int status, int_mask, int_mask_val;
@@ -1917,6 +1923,7 @@ static void tsens_poll(struct work_struct *work)
			(mask * TSENS_SN_ADDR_OFFSET)));

	tmdev->crit_timestamp_last_run = sched_clock();
	tmdev->qtimer_val_detection_start = arch_counter_get_cntpct();

	spin_lock_irqsave(&tmdev->tsens_crit_lock, flags);
	tmdev->crit_set = true;
@@ -1949,6 +1956,8 @@ static void tsens_poll(struct work_struct *work)
		spin_unlock_irqrestore(&tmdev->tsens_crit_lock, flags);

		tmdev->crit_timestamp_last_poll_request = sched_clock();
		tmdev->qtimer_val_last_polling_check =
						arch_counter_get_cntpct();
		if (status & TSENS_TM_SN_STATUS_CRITICAL_STATUS) {

			spin_lock_irqsave(&tmdev->tsens_crit_lock, flags);
@@ -1974,9 +1983,10 @@ static void tsens_poll(struct work_struct *work)

		loop = 0;
		i = 0;
		while (loop < TSENS_DEBUG_LOOP_COUNT_ID_0) {
			writel_relaxed((i << 1) | 1,
		debug_id = readl_relaxed(debug_id_addr);
		writel_relaxed((debug_id | (i << 1) | 1),
				TSENS_DEBUG_CONTROL(tmdev->tsens_addr));
		while (loop < TSENS_DEBUG_LOOP_COUNT_ID_0) {
			debug_dump = readl_relaxed(debug_data_addr);
			r1 = readl_relaxed(debug_data_addr);
			r2 = readl_relaxed(debug_data_addr);
@@ -1989,15 +1999,16 @@ static void tsens_poll(struct work_struct *work)

		for (i = TSENS_DBG_BUS_ID_1; i <= TSENS_DBG_BUS_ID_15; i++) {
			loop = 0;
			while (loop < TSENS_DEBUG_LOOP_COUNT) {
				writel_relaxed((i << 1) | 1,
			debug_id = readl_relaxed(debug_id_addr);
			debug_id = debug_id & TSENS_DEBUG_ID_MASK_1_4;
			writel_relaxed((debug_id | (i << 1) | 1),
					TSENS_DEBUG_CONTROL(tmdev->tsens_addr));
			while (loop < TSENS_DEBUG_LOOP_COUNT) {
				debug_dump = readl_relaxed(debug_data_addr);
				pr_err("bus-id:%d with value: 0x%x\n",
					i, debug_dump);
				loop++;
			}
			loop = 0;
		}

		pr_err("Start of TSENS TM dump\n");
@@ -2319,6 +2330,8 @@ static irqreturn_t tsens_tm_critical_irq_thread(int irq, void *data)
	}

	tm->crit_timestamp_last_interrupt_handled = sched_clock();
	tm->qtimer_val_last_detection_interrupt = arch_counter_get_cntpct();

	complete(&tm->tsens_rslt_completion);
	/* Mask critical interrupt */
	mb();