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

Commit 6039d341 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "thermal: tsens: Log threshold states"

parents e5ddf98b b99fa9ff
Loading
Loading
Loading
Loading
+62 −5
Original line number Diff line number Diff line
@@ -762,6 +762,17 @@ enum tsens_tm_trip_type {
#define TSENS_WRITABLE_TRIPS_MASK ((1 << TSENS_TRIP_NUM) - 1)
#define TSENS_TM_WRITABLE_TRIPS_MASK ((1 << TSENS_TM_TRIP_NUM) - 1)

struct tsens_thrshld_state {
	enum thermal_device_mode	high_th_state;
	enum thermal_device_mode	low_th_state;
	enum thermal_device_mode	crit_th_state;
	unsigned int			high_adc_code;
	unsigned int			low_adc_code;
	int				high_temp;
	int				low_temp;
	int				crit_temp;
};

struct tsens_tm_device_sensor {
	struct thermal_zone_device	*tz_dev;
	struct tsens_tm_device		*tm;
@@ -776,6 +787,11 @@ struct tsens_tm_device_sensor {
	int				calib_data_point1;
	int				calib_data_point2;
	uint32_t			slope_mul_tsens_factor;
	struct tsens_thrshld_state	debug_thr_state_copy;
	/* dbg_adc_code logs either the raw ADC code or temperature values in
	 * decidegC based on the controller settings.
	 */
	int				dbg_adc_code;
};

struct tsens_dbg_counter {
@@ -788,6 +804,7 @@ struct tsens_sensor_dbg_info {
	unsigned long			temp[10];
	uint32_t			idx;
	unsigned long long		time_stmp[10];
	int				adccode[10];
};

struct tsens_mtc_sysfs {
@@ -1410,6 +1427,8 @@ static int msm_tsens_get_temp(int sensor_client_id, unsigned long *temp)
		*temp = last_temp;
	}

	tmdev->sensor[sensor_hw_num].dbg_adc_code = last_temp;

	trace_tsens_read(*temp, sensor_client_id);

	return 0;
@@ -1438,6 +1457,8 @@ static int tsens_tz_get_temp(struct thermal_zone_device *thermal,
	tmdev->sensor_dbg_info[tm_sensor->sensor_hw_num].temp[idx%10] = *temp;
	tmdev->sensor_dbg_info[tm_sensor->sensor_hw_num].time_stmp[idx%10] =
					sched_clock();
	tmdev->sensor_dbg_info[tm_sensor->sensor_hw_num].adccode[idx%10] =
			tmdev->sensor[tm_sensor->sensor_hw_num].dbg_adc_code;
	idx++;
	tmdev->sensor_dbg_info[tm_sensor->sensor_hw_num].idx = idx;

@@ -1560,6 +1581,8 @@ static int tsens_tm_activate_trip_type(struct thermal_zone_device *thermal,
	mask = (tm_sensor->sensor_hw_num);
	switch (trip) {
	case TSENS_TM_TRIP_CRITICAL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
			debug_thr_state_copy.crit_th_state = mode;
		reg_cntl = readl_relaxed(TSENS_TM_CRITICAL_INT_MASK
							(tmdev->tsens_addr));
		if (mode == THERMAL_TRIP_ACTIVATION_DISABLED)
@@ -1572,6 +1595,8 @@ static int tsens_tm_activate_trip_type(struct thermal_zone_device *thermal,
				(tmdev->tsens_addr)));
		break;
	case TSENS_TM_TRIP_WARM:
		tmdev->sensor[tm_sensor->sensor_hw_num].
			debug_thr_state_copy.high_th_state = mode;
		reg_cntl = readl_relaxed(TSENS_TM_UPPER_LOWER_INT_MASK
						(tmdev->tsens_addr));
		if (mode == THERMAL_TRIP_ACTIVATION_DISABLED)
@@ -1586,6 +1611,8 @@ static int tsens_tm_activate_trip_type(struct thermal_zone_device *thermal,
				(tmdev->tsens_addr)));
		break;
	case TSENS_TM_TRIP_COOL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
			debug_thr_state_copy.low_th_state = mode;
		reg_cntl = readl_relaxed(TSENS_TM_UPPER_LOWER_INT_MASK
						(tmdev->tsens_addr));
		if (mode == THERMAL_TRIP_ACTIVATION_DISABLED)
@@ -1627,8 +1654,12 @@ static int tsens_tz_activate_trip_type(struct thermal_zone_device *thermal,
					(tmdev->tsens_addr) +
					(tm_sensor->sensor_hw_num *
					TSENS_SN_ADDR_OFFSET)));

	switch (trip) {
	case TSENS_TRIP_WARM:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.high_th_state = mode;

		code = (reg_cntl & TSENS_UPPER_THRESHOLD_MASK)
					>> TSENS_UPPER_THRESHOLD_SHIFT;
		mask = TSENS_UPPER_STATUS_CLR;
@@ -1637,6 +1668,9 @@ static int tsens_tz_activate_trip_type(struct thermal_zone_device *thermal,
			lo_code = (reg_cntl & TSENS_LOWER_THRESHOLD_MASK);
		break;
	case TSENS_TRIP_COOL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.low_th_state = mode;

		code = (reg_cntl & TSENS_LOWER_THRESHOLD_MASK);
		mask = TSENS_LOWER_STATUS_CLR;

@@ -1650,14 +1684,13 @@ static int tsens_tz_activate_trip_type(struct thermal_zone_device *thermal,

	if (mode == THERMAL_TRIP_ACTIVATION_DISABLED)
		writel_relaxed(reg_cntl | mask,
			(TSENS_S0_UPPER_LOWER_STATUS_CTRL_ADDR
						(tmdev->tsens_addr) +
		(TSENS_S0_UPPER_LOWER_STATUS_CTRL_ADDR(tmdev->tsens_addr) +
			(tm_sensor->sensor_hw_num * TSENS_SN_ADDR_OFFSET)));
	else {

	else
		writel_relaxed(reg_cntl & ~mask,
		(TSENS_S0_UPPER_LOWER_STATUS_CTRL_ADDR(tmdev->tsens_addr) +
		(tm_sensor->sensor_hw_num * TSENS_SN_ADDR_OFFSET)));
	}
	/* Enable the thresholds */
	mb();
	return 0;
@@ -1791,12 +1824,16 @@ static int tsens_tm_set_trip_temp(struct thermal_zone_device *thermal,
	spin_lock_irqsave(&tmdev->tsens_upp_low_lock, flags);
	switch (trip) {
	case TSENS_TM_TRIP_CRITICAL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.crit_temp = temp;
		temp &= TSENS_TM_SN_CRITICAL_THRESHOLD_MASK;
		writel_relaxed(temp,
			(TSENS_TM_SN_CRITICAL_THRESHOLD(tmdev->tsens_addr) +
			(tm_sensor->sensor_hw_num * TSENS_SN_ADDR_OFFSET)));
		break;
	case TSENS_TM_TRIP_WARM:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.high_temp = temp;
		reg_cntl = readl_relaxed((TSENS_TM_UPPER_LOWER_THRESHOLD
				(tmdev->tsens_addr)) +
				(tm_sensor->sensor_hw_num *
@@ -1809,6 +1846,8 @@ static int tsens_tm_set_trip_temp(struct thermal_zone_device *thermal,
			(tm_sensor->sensor_hw_num * TSENS_SN_ADDR_OFFSET)));
		break;
	case TSENS_TM_TRIP_COOL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.low_temp = temp;
		reg_cntl = readl_relaxed((TSENS_TM_UPPER_LOWER_THRESHOLD
				(tmdev->tsens_addr)) +
				(tm_sensor->sensor_hw_num *
@@ -1863,12 +1902,20 @@ static int tsens_tz_set_trip_temp(struct thermal_zone_device *thermal,
					TSENS_SN_ADDR_OFFSET));
	switch (trip) {
	case TSENS_TRIP_WARM:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.high_adc_code = code;
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.high_temp = temp;
		code <<= TSENS_UPPER_THRESHOLD_SHIFT;
		reg_cntl &= ~TSENS_UPPER_THRESHOLD_MASK;
		if (!(reg_cntl & TSENS_LOWER_STATUS_CLR))
			lo_code = (reg_cntl & TSENS_LOWER_THRESHOLD_MASK);
		break;
	case TSENS_TRIP_COOL:
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.low_adc_code = code;
		tmdev->sensor[tm_sensor->sensor_hw_num].
				debug_thr_state_copy.low_temp = temp;
		reg_cntl &= ~TSENS_LOWER_THRESHOLD_MASK;
		if (!(reg_cntl & TSENS_UPPER_STATUS_CLR))
			hi_code = (reg_cntl & TSENS_UPPER_THRESHOLD_MASK)
@@ -2313,6 +2360,8 @@ static irqreturn_t tsens_tm_critical_irq_thread(int irq, void *data)
				TSENS_TM_CRITICAL_INT_CLEAR(
					tm->tsens_addr));
			critical_thr = true;
			tm->sensor[i].debug_thr_state_copy.
					crit_th_state = THERMAL_DEVICE_DISABLED;
		}
		spin_unlock_irqrestore(&tm->tsens_crit_lock, flags);

@@ -2390,6 +2439,8 @@ static irqreturn_t tsens_tm_irq_thread(int irq, void *data)
				TSENS_TM_UPPER_LOWER_INT_CLEAR(
					tm->tsens_addr));
			upper_thr = true;
			tm->sensor[i].debug_thr_state_copy.
					high_th_state = THERMAL_DEVICE_DISABLED;
		}

		if ((status & TSENS_TM_SN_STATUS_LOWER_STATUS) &&
@@ -2409,6 +2460,8 @@ static irqreturn_t tsens_tm_irq_thread(int irq, void *data)
				TSENS_TM_UPPER_LOWER_INT_CLEAR(
					tm->tsens_addr));
			lower_thr = true;
			tm->sensor[i].debug_thr_state_copy.
					low_th_state = THERMAL_DEVICE_DISABLED;
		}
		spin_unlock_irqrestore(&tm->tsens_upp_low_lock, flags);

@@ -2462,7 +2515,7 @@ static irqreturn_t tsens_irq_thread(int irq, void *data)
	int sensor_sw_id = -EINVAL;
	uint32_t idx = 0;

	if ((tm->tsens_type == TSENS_TYPE2) |
	if ((tm->tsens_type == TSENS_TYPE2) ||
			(tm->tsens_type == TSENS_TYPE4))
		sensor_status_addr = TSENS2_SN_STATUS_ADDR(tm->tsens_addr);
	else
@@ -2485,12 +2538,16 @@ static irqreturn_t tsens_irq_thread(int irq, void *data)
				TSENS_S0_UPPER_LOWER_STATUS_CTRL_ADDR(
					tm->tsens_addr + addr_offset));
			upper_thr = true;
			tm->sensor[i].debug_thr_state_copy.
					high_th_state = THERMAL_DEVICE_DISABLED;
		}
		if (status & TSENS_SN_STATUS_LOWER_STATUS) {
			writel_relaxed(threshold | TSENS_LOWER_STATUS_CLR,
				TSENS_S0_UPPER_LOWER_STATUS_CTRL_ADDR(
					tm->tsens_addr + addr_offset));
			lower_thr = true;
			tm->sensor[i].debug_thr_state_copy.
					low_th_state = THERMAL_DEVICE_DISABLED;
		}
		if (upper_thr || lower_thr) {
			unsigned long temp;