Commit 3e3d11b2 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: add reference to iio buffer on iio_dev_attr

This change adds a reference to a 'struct iio_buffer' object on the
iio_dev_attr object. This way, we can use the created iio_dev_attr objects
on per-buffer basis (since they're allocated anyway).

A minor downside of this change is that the number of parameters on
__iio_add_chan_devattr() grows by 1. This looks like it could do with a bit
of a re-think.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-14-alexandru.ardelean@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d9a62574
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/device.h> #include <linux/device.h>
struct iio_buffer;
struct iio_chan_spec; struct iio_chan_spec;
struct iio_dev; struct iio_dev;
...@@ -43,6 +44,7 @@ int __iio_add_chan_devattr(const char *postfix, ...@@ -43,6 +44,7 @@ int __iio_add_chan_devattr(const char *postfix,
u64 mask, u64 mask,
enum iio_shared_by shared_by, enum iio_shared_by shared_by,
struct device *dev, struct device *dev,
struct iio_buffer *buffer,
struct list_head *attr_list); struct list_head *attr_list);
void iio_free_chan_devattr_list(struct list_head *attr_list); void iio_free_chan_devattr_list(struct list_head *attr_list);
......
...@@ -447,6 +447,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -447,6 +447,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
0, 0,
IIO_SEPARATE, IIO_SEPARATE,
&indio_dev->dev, &indio_dev->dev,
buffer,
&buffer->scan_el_dev_attr_list); &buffer->scan_el_dev_attr_list);
if (ret) if (ret)
return ret; return ret;
...@@ -458,6 +459,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -458,6 +459,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
0, 0,
0, 0,
&indio_dev->dev, &indio_dev->dev,
buffer,
&buffer->scan_el_dev_attr_list); &buffer->scan_el_dev_attr_list);
if (ret) if (ret)
return ret; return ret;
...@@ -470,6 +472,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -470,6 +472,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
chan->scan_index, chan->scan_index,
0, 0,
&indio_dev->dev, &indio_dev->dev,
buffer,
&buffer->scan_el_dev_attr_list); &buffer->scan_el_dev_attr_list);
else else
ret = __iio_add_chan_devattr("en", ret = __iio_add_chan_devattr("en",
...@@ -479,6 +482,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -479,6 +482,7 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
chan->scan_index, chan->scan_index,
0, 0,
&indio_dev->dev, &indio_dev->dev,
buffer,
&buffer->scan_el_dev_attr_list); &buffer->scan_el_dev_attr_list);
if (ret) if (ret)
return ret; return ret;
......
...@@ -1116,6 +1116,7 @@ int __iio_add_chan_devattr(const char *postfix, ...@@ -1116,6 +1116,7 @@ int __iio_add_chan_devattr(const char *postfix,
u64 mask, u64 mask,
enum iio_shared_by shared_by, enum iio_shared_by shared_by,
struct device *dev, struct device *dev,
struct iio_buffer *buffer,
struct list_head *attr_list) struct list_head *attr_list)
{ {
int ret; int ret;
...@@ -1131,6 +1132,7 @@ int __iio_add_chan_devattr(const char *postfix, ...@@ -1131,6 +1132,7 @@ int __iio_add_chan_devattr(const char *postfix,
goto error_iio_dev_attr_free; goto error_iio_dev_attr_free;
iio_attr->c = chan; iio_attr->c = chan;
iio_attr->address = mask; iio_attr->address = mask;
iio_attr->buffer = buffer;
list_for_each_entry(t, attr_list, l) list_for_each_entry(t, attr_list, l)
if (strcmp(t->dev_attr.attr.name, if (strcmp(t->dev_attr.attr.name,
iio_attr->dev_attr.attr.name) == 0) { iio_attr->dev_attr.attr.name) == 0) {
...@@ -1167,6 +1169,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev, ...@@ -1167,6 +1169,7 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev,
0, 0,
IIO_SEPARATE, IIO_SEPARATE,
&indio_dev->dev, &indio_dev->dev,
NULL,
&iio_dev_opaque->channel_attr_list); &iio_dev_opaque->channel_attr_list);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1192,6 +1195,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, ...@@ -1192,6 +1195,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
i, i,
shared_by, shared_by,
&indio_dev->dev, &indio_dev->dev,
NULL,
&iio_dev_opaque->channel_attr_list); &iio_dev_opaque->channel_attr_list);
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
continue; continue;
...@@ -1228,6 +1232,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, ...@@ -1228,6 +1232,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev,
i, i,
shared_by, shared_by,
&indio_dev->dev, &indio_dev->dev,
NULL,
&iio_dev_opaque->channel_attr_list); &iio_dev_opaque->channel_attr_list);
kfree(avail_postfix); kfree(avail_postfix);
if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
...@@ -1324,6 +1329,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -1324,6 +1329,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
i, i,
ext_info->shared, ext_info->shared,
&indio_dev->dev, &indio_dev->dev,
NULL,
&iio_dev_opaque->channel_attr_list); &iio_dev_opaque->channel_attr_list);
i++; i++;
if (ret == -EBUSY && ext_info->shared) if (ret == -EBUSY && ext_info->shared)
......
...@@ -385,6 +385,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev, ...@@ -385,6 +385,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
ret = __iio_add_chan_devattr(postfix, chan, show, store, ret = __iio_add_chan_devattr(postfix, chan, show, store,
(i << 16) | spec_index, shared_by, &indio_dev->dev, (i << 16) | spec_index, shared_by, &indio_dev->dev,
NULL,
&iio_dev_opaque->event_interface->dev_attr_list); &iio_dev_opaque->event_interface->dev_attr_list);
kfree(postfix); kfree(postfix);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef _INDUSTRIAL_IO_SYSFS_H_ #ifndef _INDUSTRIAL_IO_SYSFS_H_
#define _INDUSTRIAL_IO_SYSFS_H_ #define _INDUSTRIAL_IO_SYSFS_H_
struct iio_buffer;
struct iio_chan_spec; struct iio_chan_spec;
/** /**
...@@ -17,12 +18,14 @@ struct iio_chan_spec; ...@@ -17,12 +18,14 @@ struct iio_chan_spec;
* @address: associated register address * @address: associated register address
* @l: list head for maintaining list of dynamically created attrs * @l: list head for maintaining list of dynamically created attrs
* @c: specification for the underlying channel * @c: specification for the underlying channel
* @buffer: the IIO buffer to which this attribute belongs to (if any)
*/ */
struct iio_dev_attr { struct iio_dev_attr {
struct device_attribute dev_attr; struct device_attribute dev_attr;
u64 address; u64 address;
struct list_head l; struct list_head l;
struct iio_chan_spec const *c; struct iio_chan_spec const *c;
struct iio_buffer *buffer;
}; };
#define to_iio_dev_attr(_dev_attr) \ #define to_iio_dev_attr(_dev_attr) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment