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 Diff line number Diff line
@@ -286,13 +286,16 @@ static struct miscdevice etb_misc = {
	.fops =		&etb_fops,
};

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

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

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

	etb.trigger_cntr = val;
	return n;
}
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);
	return size;
}
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)
{
@@ -322,7 +319,7 @@ static int etb_sysfs_init(void)
		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) {
		dev_err(etb.dev, "failed to create ETB sysfs trigger_cntr"
		" attribute\n");
@@ -338,7 +335,7 @@ err_create:

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);
}

+528 −268

File changed.

Preview size limit exceeded, changes collapsed.

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

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

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

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

	funnel.priority = val;
	return n;
}
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);
	return size;
}
FUNNEL_ATTR(priority);
static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, funnel_show_priority,
		   funnel_store_priority);

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

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

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);
}

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

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

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

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

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);
}
STM_ATTR(enabled);

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

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

	stm.entity = val;
	return n;
}
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);
	return size;
}
STM_ATTR(entity);
static DEVICE_ATTR(entity, S_IRUGO | S_IWUSR, stm_show_entity,
		   stm_store_entity);

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

	ret = sysfs_create_file(stm.kobj, &enabled_attr.attr);
	ret = sysfs_create_file(stm.kobj, &dev_attr_enabled.attr);
	if (ret) {
		dev_err(stm.dev, "failed to create STM sysfs enabled attr\n");
		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");

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

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