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

Commit 9063c86a authored by Kyle Yan's avatar Kyle Yan Committed by Runmin Wang
Browse files

soc: qcom: gladiator_hang: Add support for different ports



Different targets do not always have the same gladiator ports
and the offsets in registers can be different. This patch allows
user to specify different port configurations by using different
compatible strings in the DT.

Change-Id: I0687b1d15ba5b6aac22c526417c2d5828b9d3881
Signed-off-by: default avatarKyle Yan <kyan@codeaurora.org>
parent f7939ea3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ Writing 1 into pcio_enabled sysfs entry, enables gladiator hang
detection on PCIO port

Required properties:
- compatible : "qcom,gladiator-hang-detect"
- compatible : "qcom,gladiator-hang-detect" or "qcom,gladiator-hang-detect-v2"
- qcom, threshold-arr:
		Array of APCS_COMMON_GLADIATOR_HANG_THRESHOLD_n register
		address
+137 −100
Original line number Diff line number Diff line
@@ -20,26 +20,21 @@
#include <soc/qcom/scm.h>
#include <linux/platform_device.h>

#define ACE_OFFSET	0
#define IO_OFFSET	2
#define M1_OFFSET	3
#define M2_OFFSET	4
#define PCIO_OFFSET	5
#define ENABLE_MASK_BITS	0x1

#define _VAL(z)			(ENABLE_MASK_BITS << z##_OFFSET)
#define _VALUE(_val, z)		(_val<<(z##_OFFSET))
#define _VAL(z)			(ENABLE_MASK_BITS << z)
#define _VALUE(_val, z)		(_val<<(z))
#define _WRITE(x, y, z)		(((~(_VAL(z))) & y) | _VALUE(x, z))

#define NR_GLA_REG 6
#define MODULE_NAME	"gladiator_hang_detect"
#define MAX_THRES	0xFFFFFFFF
#define MAX_LEN_SYSFS 12

struct hang_detect {
	phys_addr_t threshold[NR_GLA_REG];
	phys_addr_t *threshold;
	phys_addr_t config;
	int ACE_enable, IO_enable, M1_enable, M2_enable, PCIO_enable;
	int ACE_offset, IO_offset, M1_offset, M2_offset, PCIO_offset;
	uint32_t ACE_threshold, IO_threshold, M1_threshold, M2_threshold,
			 PCIO_threshold;
	struct kobject kobj;
@@ -68,116 +63,68 @@ struct gladiator_hang_attr {
static void set_threshold(int offset, struct hang_detect *hang_dev,
		int32_t threshold_val)
{
	switch (offset) {
	case ACE_OFFSET:
	if (offset == hang_dev->ACE_offset)
		hang_dev->ACE_threshold = threshold_val;
		break;
	case IO_OFFSET:
	else if (offset == hang_dev->IO_offset)
		hang_dev->IO_threshold = threshold_val;
		break;
	case M1_OFFSET:
	else if (offset == hang_dev->M1_offset)
		hang_dev->M1_threshold = threshold_val;
		break;
	case M2_OFFSET:
	else if (offset == hang_dev->M2_offset)
		hang_dev->M2_threshold = threshold_val;
		break;
	case PCIO_OFFSET:
	else if (offset == hang_dev->PCIO_offset)
		hang_dev->PCIO_threshold = threshold_val;
		break;
	}
}

static void get_threshold(int offset, struct hang_detect *hang_dev,
		uint32_t *reg_value)
{
	switch (offset) {
	case ACE_OFFSET:
	if (offset == hang_dev->ACE_offset)
		*reg_value = hang_dev->ACE_threshold;
	break;
	case IO_OFFSET:
	else if (offset == hang_dev->IO_offset)
		*reg_value = hang_dev->IO_threshold;
		break;
	case M1_OFFSET:
	else if (offset == hang_dev->M1_offset)
		*reg_value = hang_dev->M1_threshold;
		break;
	case M2_OFFSET:
	else if (offset == hang_dev->M2_offset)
		*reg_value = hang_dev->M2_threshold;
		break;
	case PCIO_OFFSET:
	else if (offset == hang_dev->PCIO_offset)
		*reg_value = hang_dev->PCIO_threshold;
		break;
	}
}

static void set_enable(int offset, struct hang_detect *hang_dev,
		int enabled)
{
	switch (offset) {
	case ACE_OFFSET:
	if (offset == hang_dev->ACE_offset)
		hang_dev->ACE_enable = enabled;
		break;
	case IO_OFFSET:
	else if (offset == hang_dev->IO_offset)
		hang_dev->IO_enable = enabled;
		break;
	case M1_OFFSET:
	else if (offset == hang_dev->M1_offset)
		hang_dev->M1_enable = enabled;
		break;
	case M2_OFFSET:
	else if (offset == hang_dev->M2_offset)
		hang_dev->M2_enable = enabled;
		break;
	case PCIO_OFFSET:
	else if (offset == hang_dev->PCIO_offset)
		hang_dev->PCIO_enable = enabled;
		break;
	}
}

static void get_enable(int offset, struct hang_detect *hang_dev,
		uint32_t *reg_value)
{
	switch (offset) {
	case ACE_OFFSET:
	if (offset == hang_dev->ACE_offset)
		*reg_value = hang_dev->ACE_enable;
		break;
	case IO_OFFSET:
	else if (offset == hang_dev->IO_offset)
		*reg_value = hang_dev->IO_enable;
		break;
	case M1_OFFSET:
	else if (offset == hang_dev->M1_offset)
		*reg_value = hang_dev->M1_enable;
		break;
	case M2_OFFSET:
	else if (offset == hang_dev->M2_offset)
		*reg_value = hang_dev->M2_enable;
		break;
	case PCIO_OFFSET:
	else if (offset == hang_dev->PCIO_offset)
		*reg_value = hang_dev->PCIO_enable;
		break;
	}
}

static void scm_enable_write(int offset, struct hang_detect *hang_dev,
		int enabled, uint32_t reg_value, int *ret)
{
	switch (offset) {
	case ACE_OFFSET:
		*ret = scm_io_write(hang_dev->config,
			_WRITE(enabled, reg_value, ACE));
		break;
	case IO_OFFSET:
	*ret = scm_io_write(hang_dev->config,
				_WRITE(enabled, reg_value, IO));
		break;
	case M1_OFFSET:
		*ret = scm_io_write(hang_dev->config,
				_WRITE(enabled, reg_value, M1));
		break;
	case M2_OFFSET:
		*ret = scm_io_write(hang_dev->config,
				_WRITE(enabled, reg_value, M2));
		break;
	case PCIO_OFFSET:
		*ret = scm_io_write(hang_dev->config,
				_WRITE(enabled, reg_value, PCIO));
		break;
	}
			_WRITE(enabled, reg_value, offset));
}

static int enable_check(const char *buf, int *enabled_pt)
@@ -303,13 +250,18 @@ static struct kobj_type gladiator_ktype = {
static ssize_t show_ace_threshold(struct kobject *kobj, struct attribute *attr,
				char *buf)
{
	return generic_threshold_show(kobj, attr, buf, ACE_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_show(kobj, attr, buf, hang_dev->ACE_offset);
}

static size_t store_ace_threshold(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t count)
{
	return generic_threshold_store(kobj, attr, buf, count, ACE_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_store(kobj, attr, buf, count,
					hang_dev->ACE_offset);
}
GLADIATOR_HANG_ATTR(ace_threshold, 0644, show_ace_threshold,
					store_ace_threshold);
@@ -317,13 +269,18 @@ GLADIATOR_HANG_ATTR(ace_threshold, 0644, show_ace_threshold,
static ssize_t show_io_threshold(struct kobject *kobj, struct attribute *attr,
				char *buf)
{
	return generic_threshold_show(kobj, attr, buf, IO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_show(kobj, attr, buf, hang_dev->IO_offset);
}

static size_t store_io_threshold(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t count)
{
	return generic_threshold_store(kobj, attr, buf, count, IO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_store(kobj, attr, buf, count,
					hang_dev->IO_offset);
}
GLADIATOR_HANG_ATTR(io_threshold, 0644, show_io_threshold,
					store_io_threshold);
@@ -331,13 +288,18 @@ GLADIATOR_HANG_ATTR(io_threshold, 0644, show_io_threshold,
static ssize_t show_m1_threshold(struct kobject *kobj, struct attribute *attr,
				char *buf)
{
	return generic_threshold_show(kobj, attr, buf, M1_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_show(kobj, attr, buf, hang_dev->M1_offset);
}

static size_t store_m1_threshold(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t count)
{
	return generic_threshold_store(kobj, attr, buf, count, M1_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_store(kobj, attr, buf, count,
					hang_dev->M1_offset);
}
GLADIATOR_HANG_ATTR(m1_threshold, 0644, show_m1_threshold,
					store_m1_threshold);
@@ -345,13 +307,18 @@ GLADIATOR_HANG_ATTR(m1_threshold, 0644, show_m1_threshold,
static ssize_t show_m2_threshold(struct kobject *kobj, struct attribute *attr,
				char *buf)
{
	return generic_threshold_show(kobj, attr, buf, M2_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_show(kobj, attr, buf, hang_dev->M2_offset);
}

static size_t store_m2_threshold(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t count)
{
	return generic_threshold_store(kobj, attr, buf, count, M2_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_store(kobj, attr, buf, count,
					hang_dev->M2_offset);
}
GLADIATOR_HANG_ATTR(m2_threshold, 0644, show_m2_threshold,
					store_m2_threshold);
@@ -359,13 +326,18 @@ GLADIATOR_HANG_ATTR(m2_threshold, 0644, show_m2_threshold,
static ssize_t show_pcio_threshold(struct kobject *kobj, struct attribute *attr,
				char *buf)
{
	return generic_threshold_show(kobj, attr, buf, PCIO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_show(kobj, attr, buf, hang_dev->PCIO_offset);
}

static size_t store_pcio_threshold(struct kobject *kobj, struct attribute *attr,
				const char *buf, size_t count)
{
	return generic_threshold_store(kobj, attr, buf, count, PCIO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_threshold_store(kobj, attr, buf, count,
					hang_dev->PCIO_offset);
}
GLADIATOR_HANG_ATTR(pcio_threshold, 0644, show_pcio_threshold,
					store_pcio_threshold);
@@ -373,13 +345,18 @@ GLADIATOR_HANG_ATTR(pcio_threshold, 0644, show_pcio_threshold,
static ssize_t show_ace_enable(struct kobject *kobj,
			struct attribute *attr, char *buf)
{
	return generic_enable_show(kobj, attr, buf, ACE_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_show(kobj, attr, buf, hang_dev->ACE_offset);
}

static size_t store_ace_enable(struct kobject *kobj,
			struct attribute *attr, const char *buf, size_t count)
{
	return generic_enable_store(kobj, attr, buf, count, ACE_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_store(kobj, attr, buf, count,
					hang_dev->ACE_offset);
}
GLADIATOR_HANG_ATTR(ace_enable, 0644, show_ace_enable,
		store_ace_enable);
@@ -387,13 +364,18 @@ GLADIATOR_HANG_ATTR(ace_enable, 0644, show_ace_enable,
static ssize_t show_io_enable(struct kobject *kobj,
			struct attribute *attr, char *buf)
{
	return generic_enable_show(kobj, attr, buf, IO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_show(kobj, attr, buf, hang_dev->IO_offset);
}

static size_t store_io_enable(struct kobject *kobj,
			struct attribute *attr, const char *buf, size_t count)
{
	return generic_enable_store(kobj, attr, buf, count, IO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_store(kobj, attr, buf, count,
					hang_dev->IO_offset);
}
GLADIATOR_HANG_ATTR(io_enable, 0644,
		show_io_enable, store_io_enable);
@@ -402,13 +384,18 @@ GLADIATOR_HANG_ATTR(io_enable, 0644,
static ssize_t show_m1_enable(struct kobject *kobj,
			struct attribute *attr, char *buf)
{
	return generic_enable_show(kobj, attr, buf, M1_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_show(kobj, attr, buf, hang_dev->M1_offset);
}

static size_t store_m1_enable(struct kobject *kobj,
			struct attribute *attr, const char *buf, size_t count)
{
	return generic_enable_store(kobj, attr, buf, count, M1_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_store(kobj, attr, buf, count,
					hang_dev->M1_offset);
}
GLADIATOR_HANG_ATTR(m1_enable, 0644,
		show_m1_enable, store_m1_enable);
@@ -416,13 +403,18 @@ GLADIATOR_HANG_ATTR(m1_enable, 0644,
static ssize_t show_m2_enable(struct kobject *kobj,
			struct attribute *attr, char *buf)
{
	return generic_enable_show(kobj, attr, buf, M2_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_show(kobj, attr, buf, hang_dev->M2_offset);
}

static size_t store_m2_enable(struct kobject *kobj,
			struct attribute *attr, const char *buf, size_t count)
{
	return generic_enable_store(kobj, attr, buf, count, M2_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_store(kobj, attr, buf, count,
					hang_dev->M2_offset);
}
GLADIATOR_HANG_ATTR(m2_enable, 0644,
		show_m2_enable, store_m2_enable);
@@ -430,13 +422,18 @@ GLADIATOR_HANG_ATTR(m2_enable, 0644,
static ssize_t show_pcio_enable(struct kobject *kobj,
			struct attribute *attr, char *buf)
{
	return generic_enable_show(kobj, attr, buf, PCIO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_show(kobj, attr, buf, hang_dev->PCIO_offset);
}

static size_t store_pcio_enable(struct kobject *kobj,
			struct attribute *attr, const char *buf, size_t count)
{
	return generic_enable_store(kobj, attr, buf, count, PCIO_OFFSET);
	struct hang_detect *hang_dev = to_gladiator_hang_dev(kobj);

	return generic_enable_store(kobj, attr, buf, count,
					hang_dev->PCIO_offset);
}
GLADIATOR_HANG_ATTR(pcio_enable, 0644,
		show_pcio_enable, store_pcio_enable);
@@ -455,12 +452,21 @@ static struct attribute *hang_attrs[] = {
	NULL
};

static struct attribute *hang_attrs_v2[] = {
	&hang_attr_ace_threshold.attr,
	&hang_attr_io_threshold.attr,
	&hang_attr_ace_enable.attr,
	&hang_attr_io_enable.attr,
	NULL
};

static struct attribute_group hang_attr_group = {
	.attrs = hang_attrs,
};

static const struct of_device_id msm_gladiator_hang_detect_table[] = {
	{ .compatible = "qcom,gladiator-hang-detect" },
	{ .compatible = "qcom,gladiator-hang-detect-v2" },
	{}
};

@@ -469,7 +475,9 @@ static int msm_gladiator_hang_detect_probe(struct platform_device *pdev)
	struct device_node *node = pdev->dev.of_node;
	struct hang_detect *hang_det = NULL;
	int i = 0, ret;
	u32 treg[NR_GLA_REG], creg;
	u32 NR_GLA_REG;
	u32 *treg;
	u32 creg;

	if (!pdev->dev.of_node)
		return -ENODEV;
@@ -482,6 +490,34 @@ static int msm_gladiator_hang_detect_probe(struct platform_device *pdev)
		return -ENOMEM;
	}

	if (of_device_is_compatible(node, "qcom,gladiator-hang-detect")) {
		hang_det->ACE_offset = 0;
		hang_det->IO_offset = 2;
		hang_det->M1_offset = 3;
		hang_det->M2_offset = 4;
		hang_det->PCIO_offset = 5;
		NR_GLA_REG = 6;
	} else if (of_device_is_compatible(node,
			"qcom,gladiator-hang-detect-v2")) {
		hang_det->ACE_offset = 0;
		hang_det->IO_offset = 1;
		NR_GLA_REG = 2;
		hang_attr_group.attrs = hang_attrs_v2;
	}

	hang_det->threshold = devm_kzalloc(&pdev->dev,
			sizeof(phys_addr_t)*NR_GLA_REG, GFP_KERNEL);

	if (!hang_det->threshold) {
		pr_err("Can't allocate hang_detect threshold memory\n");
		return -ENOMEM;
	}

	treg = devm_kzalloc(&pdev->dev, sizeof(u32)*NR_GLA_REG, GFP_KERNEL);

	if (!treg)
		return -ENOMEM;

	ret = of_property_read_u32_array(node, "qcom,threshold-arr",
			treg, NR_GLA_REG);
	if (ret) {
@@ -512,6 +548,7 @@ static int msm_gladiator_hang_detect_probe(struct platform_device *pdev)
		pr_err("%s:Error in creation sysfs_create_group\n", __func__);
		goto out_del_kobj;
	}

	mutex_init(&hang_det->lock);
	platform_set_drvdata(pdev, hang_det);
	return 0;