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

Commit 5b57608e authored by Pratik Patel's avatar Pratik Patel Committed by Stephen Boyd
Browse files

cs: use device attributes instead of kobj attributes



In preparation for subsequent changes, switch to using device
attributes instead of kobj attributes. This fits well with the
implementation and makes it easy to support multiple instances
of the same device.

Change-Id: I3c3c58de9dba599bc44a57c2ddeb75100a4edf46
Signed-off-by: default avatarPratik Patel <pratikp@codeaurora.org>
parent fd7ca17b
Loading
Loading
Loading
Loading
+14 −17
Original line number Original line Diff line number Diff line
@@ -286,13 +286,16 @@ static struct miscdevice etb_misc = {
	.fops =		&etb_fops,
	.fops =		&etb_fops,
};
};


#define ETB_ATTR(__name)						\
static ssize_t etb_show_trigger_cntr(struct device *dev,
static struct kobj_attribute __name##_attr =				\
				     struct device_attribute *attr, char *buf)
	__ATTR(__name, S_IRUGO | S_IWUSR, __name##_show, __name##_store)
{
	unsigned long val = etb.trigger_cntr;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}


static ssize_t trigger_cntr_store(struct kobject *kobj,
static ssize_t etb_store_trigger_cntr(struct device *dev,
			struct kobj_attribute *attr,
				      struct device_attribute *attr,
			const char *buf, size_t n)
				      const char *buf, size_t size)
{
{
	unsigned long val;
	unsigned long val;


@@ -300,16 +303,10 @@ static ssize_t trigger_cntr_store(struct kobject *kobj,
		return -EINVAL;
		return -EINVAL;


	etb.trigger_cntr = val;
	etb.trigger_cntr = val;
	return n;
	return size;
}
static ssize_t trigger_cntr_show(struct kobject *kobj,
			struct kobj_attribute *attr,
			char *buf)
{
	unsigned long val = etb.trigger_cntr;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}
}
ETB_ATTR(trigger_cntr);
static DEVICE_ATTR(trigger_cntr, S_IRUGO | S_IWUSR, etb_show_trigger_cntr,
		   etb_store_trigger_cntr);


static int etb_sysfs_init(void)
static int etb_sysfs_init(void)
{
{
@@ -322,7 +319,7 @@ static int etb_sysfs_init(void)
		goto err_create;
		goto err_create;
	}
	}


	ret = sysfs_create_file(etb.kobj, &trigger_cntr_attr.attr);
	ret = sysfs_create_file(etb.kobj, &dev_attr_trigger_cntr.attr);
	if (ret) {
	if (ret) {
		dev_err(etb.dev, "failed to create ETB sysfs trigger_cntr"
		dev_err(etb.dev, "failed to create ETB sysfs trigger_cntr"
		" attribute\n");
		" attribute\n");
@@ -338,7 +335,7 @@ err_create:


static void etb_sysfs_exit(void)
static void etb_sysfs_exit(void)
{
{
	sysfs_remove_file(etb.kobj, &trigger_cntr_attr.attr);
	sysfs_remove_file(etb.kobj, &dev_attr_trigger_cntr.attr);
	kobject_put(etb.kobj);
	kobject_put(etb.kobj);
}
}


+528 −268

File changed.

Preview size limit exceeded, changes collapsed.

+14 −17
Original line number Original line Diff line number Diff line
@@ -122,13 +122,16 @@ void funnel_disable(uint8_t id, uint32_t port_mask)
	clk_disable_unprepare(funnel.clk);
	clk_disable_unprepare(funnel.clk);
}
}


#define FUNNEL_ATTR(__name)						\
static ssize_t funnel_show_priority(struct device *dev,
static struct kobj_attribute __name##_attr =				\
				    struct device_attribute *attr, char *buf)
	__ATTR(__name, S_IRUGO | S_IWUSR, __name##_show, __name##_store)
{
	unsigned long val = funnel.priority;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}


static ssize_t priority_store(struct kobject *kobj,
static ssize_t funnel_store_priority(struct device *dev,
			struct kobj_attribute *attr,
				     struct device_attribute *attr,
			const char *buf, size_t n)
				     const char *buf, size_t size)
{
{
	unsigned long val;
	unsigned long val;


@@ -136,16 +139,10 @@ static ssize_t priority_store(struct kobject *kobj,
		return -EINVAL;
		return -EINVAL;


	funnel.priority = val;
	funnel.priority = val;
	return n;
	return size;
}
static ssize_t priority_show(struct kobject *kobj,
			struct kobj_attribute *attr,
			char *buf)
{
	unsigned long val = funnel.priority;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}
}
FUNNEL_ATTR(priority);
static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, funnel_show_priority,
		   funnel_store_priority);


static int funnel_sysfs_init(void)
static int funnel_sysfs_init(void)
{
{
@@ -158,7 +155,7 @@ static int funnel_sysfs_init(void)
		goto err_create;
		goto err_create;
	}
	}


	ret = sysfs_create_file(funnel.kobj, &priority_attr.attr);
	ret = sysfs_create_file(funnel.kobj, &dev_attr_priority.attr);
	if (ret) {
	if (ret) {
		dev_err(funnel.dev, "failed to create FUNNEL sysfs priority"
		dev_err(funnel.dev, "failed to create FUNNEL sysfs priority"
		" attribute\n");
		" attribute\n");
@@ -174,7 +171,7 @@ err_create:


static void funnel_sysfs_exit(void)
static void funnel_sysfs_exit(void)
{
{
	sysfs_remove_file(funnel.kobj, &priority_attr.attr);
	sysfs_remove_file(funnel.kobj, &dev_attr_priority.attr);
	kobject_put(funnel.kobj);
	kobject_put(funnel.kobj);
}
}


+26 −28
Original line number Original line Diff line number Diff line
@@ -397,13 +397,16 @@ static struct miscdevice stm_misc = {
	.fops		= &stm_fops,
	.fops		= &stm_fops,
};
};


#define STM_ATTR(__name)						\
static ssize_t stm_show_enabled(struct device *dev,
static struct kobj_attribute __name##_attr =				\
				struct device_attribute *attr, char *buf)
	__ATTR(__name, S_IRUGO | S_IWUSR, __name##_show, __name##_store)
{
	unsigned long val = stm.enabled;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}


static ssize_t enabled_store(struct kobject *kobj,
static ssize_t stm_store_enabled(struct device *dev,
			struct kobj_attribute *attr,
				 struct device_attribute *attr,
			const char *buf, size_t n)
				const char *buf, size_t size)
{
{
	int ret = 0;
	int ret = 0;
	unsigned long val;
	unsigned long val;
@@ -418,20 +421,21 @@ static ssize_t enabled_store(struct kobject *kobj,


	if (ret)
	if (ret)
		return ret;
		return ret;
	return n;
	return size;
}
}
static ssize_t enabled_show(struct kobject *kobj,
static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, stm_show_enabled,
			struct kobj_attribute *attr,
		   stm_store_enabled);
			char *buf)

static ssize_t stm_show_entity(struct device *dev,
			       struct device_attribute *attr, char *buf)
{
{
	unsigned long val = stm.enabled;
	unsigned long val = stm.entity;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}
}
STM_ATTR(enabled);


static ssize_t entity_store(struct kobject *kobj,
static ssize_t stm_store_entity(struct device *dev,
			struct kobj_attribute *attr,
				struct device_attribute *attr,
			const char *buf, size_t n)
				const char *buf, size_t size)
{
{
	unsigned long val;
	unsigned long val;


@@ -439,16 +443,10 @@ static ssize_t entity_store(struct kobject *kobj,
		return -EINVAL;
		return -EINVAL;


	stm.entity = val;
	stm.entity = val;
	return n;
	return size;
}
static ssize_t entity_show(struct kobject *kobj,
			struct kobj_attribute *attr,
			char *buf)
{
	unsigned long val = stm.entity;
	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
}
}
STM_ATTR(entity);
static DEVICE_ATTR(entity, S_IRUGO | S_IWUSR, stm_show_entity,
		   stm_store_entity);


static int stm_sysfs_init(void)
static int stm_sysfs_init(void)
{
{
@@ -461,13 +459,13 @@ static int stm_sysfs_init(void)
		goto err_create;
		goto err_create;
	}
	}


	ret = sysfs_create_file(stm.kobj, &enabled_attr.attr);
	ret = sysfs_create_file(stm.kobj, &dev_attr_enabled.attr);
	if (ret) {
	if (ret) {
		dev_err(stm.dev, "failed to create STM sysfs enabled attr\n");
		dev_err(stm.dev, "failed to create STM sysfs enabled attr\n");
		goto err_file;
		goto err_file;
	}
	}


	if (sysfs_create_file(stm.kobj, &entity_attr.attr))
	if (sysfs_create_file(stm.kobj, &dev_attr_entity.attr))
		dev_err(stm.dev, "failed to create STM sysfs entity attr\n");
		dev_err(stm.dev, "failed to create STM sysfs entity attr\n");


	return 0;
	return 0;
@@ -479,8 +477,8 @@ err_create:


static void stm_sysfs_exit(void)
static void stm_sysfs_exit(void)
{
{
	sysfs_remove_file(stm.kobj, &entity_attr.attr);
	sysfs_remove_file(stm.kobj, &dev_attr_entity.attr);
	sysfs_remove_file(stm.kobj, &enabled_attr.attr);
	sysfs_remove_file(stm.kobj, &dev_attr_enabled.attr);
	kobject_put(stm.kobj);
	kobject_put(stm.kobj);
}
}