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

Commit 6d726cc2 authored by Rama Krishna Phani A's avatar Rama Krishna Phani A
Browse files

thermal: tsens: Add MTC history support



Multi-Zone Temperature Control (MTC) provides an interface to
clients to enable or disable thresholds for supported zone of
sensors, get log of recent commands and get the history of the
pulse swallowing commands. Create sysfs nodes to access
MTC tsens.

Change-Id: Iea5321534f6b718b79d855be54df072f8a627db1
Signed-off-by: default avatarRama Krishna Phani A <rphani@codeaurora.org>
parent 77813844
Loading
Loading
Loading
Loading
+87 −0
Original line number Diff line number Diff line
@@ -128,6 +128,11 @@
#define TSENS_TM_MTC_ZONE0_HISTORY(n)		((n) + 0x1160)
#define TSENS_RESET_HISTORY_MASK	0x4
#define TSENS_RESET_HISTORY_SHIFT	2
#define TSENS_PS_RED_CMD_MASK	0x3ff00000
#define TSENS_PS_YELLOW_CMD_MASK	0x000ffc00
#define TSENS_PS_COOL_CMD_MASK	0x000003ff
#define TSENS_PS_YELLOW_CMD_SHIFT	0xa
#define TSENS_PS_RED_CMD_SHIFT	0x14
/* End TSENS_TM registers for 8996 */

#define TSENS_CTRL_ADDR(n)		(n)
@@ -784,6 +789,7 @@ struct tsens_mtc_sysfs {
	int zone_mtc;
	int th1;
	int th2;
	uint32_t zone_hist;
};

struct tsens_tm_device {
@@ -1163,9 +1169,56 @@ zonelog_store(struct device *dev, struct device_attribute *attr,
	return count;
}

static ssize_t
zonehist_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	int ret, zhist[TSENS_MTC_ZONE_HISTORY_SIZE];
	struct tsens_tm_device *tmdev = NULL;

	tmdev = tsens_controller_is_present();
	if (!tmdev) {
		pr_err("No TSENS controller present\n");
		return -EPROBE_DEFER;
	}

	ret = tsens_get_mtc_zone_history(tmdev->mtcsys.zone_hist , zhist);
	if (ret < 0) {
		pr_err("Invalid command line arguments\n");
		return -EINVAL;
	}

	return snprintf(buf, PAGE_SIZE,
		"Cool = %d\nYellow = %d\nRed = %d\n",
			zhist[0], zhist[1], zhist[2]);
}

static ssize_t
zonehist_store(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
{
	int ret;
	struct tsens_tm_device *tmdev = NULL;

	tmdev = tsens_controller_is_present();
	if (!tmdev) {
		pr_err("No TSENS controller present\n");
		return -EPROBE_DEFER;
	}

	ret = kstrtou32(buf, 0, &tmdev->mtcsys.zone_hist);
	if (ret < 0) {
		pr_err("Invalid command line arguments\n");
		return -EINVAL;
	}

	return count;
}


static struct device_attribute tsens_mtc_dev_attr[] = {
	__ATTR(zonemask, 0644, zonemask_show, zonemask_store),
	__ATTR(zonelog, 0644, zonelog_show, zonelog_store),
	__ATTR(zonehist, 0644, zonehist_show, zonehist_store),
};

static int create_tsens_mtc_sysfs(struct platform_device *pdev)
@@ -2131,6 +2184,40 @@ int tsens_get_mtc_zone_log(unsigned int zone , void *zone_log)
}
EXPORT_SYMBOL(tsens_get_mtc_zone_log);

int tsens_get_mtc_zone_history(unsigned int zone , void *zone_hist)
{
	unsigned int i, reg_cntl, hist[TSENS_MTC_ZONE_HISTORY_SIZE];
	int *zhist = (int *)zone_hist;
	void __iomem *sensor_addr;
	struct tsens_tm_device *tmdev = NULL;

	if (zone > TSENS_NUM_MTC_ZONES_SUPPORT)
		return -EINVAL;

	tmdev = tsens_controller_is_present();
	if (!tmdev) {
		pr_err("No TSENS controller present\n");
		return -EPROBE_DEFER;
	}

	sensor_addr = TSENS_TM_MTC_ZONE0_HISTORY(tmdev->tsens_addr);
	reg_cntl = readl_relaxed((sensor_addr +
				(zone * TSENS_SN_ADDR_OFFSET)));

	hist[0] = (reg_cntl & TSENS_PS_COOL_CMD_MASK);
	hist[1] = (reg_cntl & TSENS_PS_YELLOW_CMD_MASK)
			  >> TSENS_PS_YELLOW_CMD_SHIFT;
	hist[2] = (reg_cntl & TSENS_PS_RED_CMD_MASK)
			  >> TSENS_PS_RED_CMD_SHIFT;
	for (i = 0; i < (TSENS_MTC_ZONE_HISTORY_SIZE); i++) {
		*(zhist+i) = hist[i];
		pr_debug("tsens : %d\n", hist[i]);
	}

	return 0;
}
EXPORT_SYMBOL(tsens_get_mtc_zone_history);

static struct thermal_zone_device_ops tsens_thermal_zone_ops = {
	.get_temp = tsens_tz_get_temp,
	.get_mode = tsens_tz_get_mode,
+34 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#define TSENS_NUM_MTC_ZONES_SUPPORT	3
#define TSENS_ZONEMASK_PARAMS		3
#define TSENS_ZONELOG_PARAMS		1
#define TSENS_MTC_ZONE_HISTORY_SIZE	3

struct tsens_device {
	uint32_t			sensor_num;
@@ -62,10 +63,41 @@ int tsens_get_hw_id_mapping(int sensor_sw_id, int *sensor_hw_num);
 * @tsens_num_sensors: Total number of sensor result to be stored.
 */
int tsens_get_max_sensor_num(uint32_t *tsens_num_sensors);
/**
 * tsens_set_mtc_zone_sw_mask() - Mask the MTC threshold level of a zone.
 *		SW can force the MTC to stop issuing throttling commands that
 *		correspond to each MTC threshold level by writing the
 *		corresponding bit in register at any time.
 * @zone: Zone ID.
 * @th1_enable : Value corresponding to the threshold level.
 * @th2_enable : Value corresponding to the threshold level.
 */
int tsens_set_mtc_zone_sw_mask(unsigned int zone , unsigned int th1_enable,
				unsigned int th2_enable);
/**
 * tsens_get_mtc_zone_log() - Get the log of last 6 commands sent to pulse
 *		swallower of a zone.
 * zone: Zone ID
 * @zone_log: Log commands result to be stored.
 */
int tsens_get_mtc_zone_log(unsigned int zone , void *zone_log);
/**
 * tsens_mtc_reset_history_counter() - Reset history of throttling commands
 *		sent to pulse swallower. Tsens controller issues clock
 *		throttling commands to Pulse swallower to perform HW
 *		based clock throttling. Reset the history counter of a zone.
 * @zone: Zone ID.
 */
int tsens_mtc_reset_history_counter(unsigned int zone);
/**
 * tsens_get_mtc_zone_history() - Get the history of throttling commands sent
 *		to pulse swallower. Tsens controller issues clock throttling
 *		commands to Pulse swallower to perform HW based clock
 *		throttling.
 * @zone: Zone ID
 * @zone_hist: Commands history result to be stored.
 */
int tsens_get_mtc_zone_history(unsigned int zone , void *zone_hist);
/**
 * tsens_get_temp() - Obtain the TSENS temperature for the respective sensor.
 *
@@ -100,6 +132,8 @@ static inline int tsens_mtc_reset_history_counter(unsigned int zone)
static inline int tsens_get_temp(struct tsens_device *dev,
						unsigned long *temp)
{ return -ENXIO; }
static inline int tsens_get_mtc_zone_history(unsigned int zone, void *zone_hist)
{ return -ENXIO; }
#endif

#endif /*MSM_TSENS_H */