Skip to content

Commit c006ec8

Browse files
committed
iio: add info_mask_[shared_by_dir/shared_by_all]
These two additional info_mask bitmaps should allow all 'standard' numeric attributes to be handled using the read_raw and write_raw callbacks. Whilst this should reduce code, the more important element is that this makes these values easily accessible to in kernel users of IIO devices. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
1 parent 3704432 commit c006ec8

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎drivers/iio/industrialio-core.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ int __iio_device_attr_init(struct device_attribute *dev_attr,
551551

552552
if (chan->differential) { /* Differential can not have modifier */
553553
switch (shared_by) {
554+
case IIO_SHARED_BY_ALL:
555+
name_format = kasprintf(GFP_KERNEL, "%s", full_postfix);
556+
break;
557+
case IIO_SHARED_BY_DIR:
558+
name_format = kasprintf(GFP_KERNEL, "%s_%s",
559+
iio_direction[chan->output],
560+
full_postfix);
561+
break;
554562
case IIO_SHARED_BY_TYPE:
555563
name_format
556564
= kasprintf(GFP_KERNEL, "%s_%s-%s_%s",
@@ -578,6 +586,14 @@ int __iio_device_attr_init(struct device_attribute *dev_attr,
578586
}
579587
} else { /* Single ended */
580588
switch (shared_by) {
589+
case IIO_SHARED_BY_ALL:
590+
name_format = kasprintf(GFP_KERNEL, "%s", full_postfix);
591+
break;
592+
case IIO_SHARED_BY_DIR:
593+
name_format = kasprintf(GFP_KERNEL, "%s_%s",
594+
iio_direction[chan->output],
595+
full_postfix);
596+
break;
581597
case IIO_SHARED_BY_TYPE:
582598
name_format
583599
= kasprintf(GFP_KERNEL, "%s_%s_%s",
@@ -736,6 +752,20 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
736752
return ret;
737753
attrcount += ret;
738754

755+
ret = iio_device_add_info_mask_type(indio_dev, chan,
756+
IIO_SHARED_BY_DIR,
757+
&chan->info_mask_shared_by_dir);
758+
if (ret < 0)
759+
return ret;
760+
attrcount += ret;
761+
762+
ret = iio_device_add_info_mask_type(indio_dev, chan,
763+
IIO_SHARED_BY_ALL,
764+
&chan->info_mask_shared_by_all);
765+
if (ret < 0)
766+
return ret;
767+
attrcount += ret;
768+
739769
if (chan->ext_info) {
740770
unsigned int i = 0;
741771
for (ext_info = chan->ext_info; ext_info->name; ext_info++) {

‎include/linux/iio/iio.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ enum iio_chan_info_enum {
4141

4242
enum iio_shared_by {
4343
IIO_SEPARATE,
44-
IIO_SHARED_BY_TYPE
44+
IIO_SHARED_BY_TYPE,
45+
IIO_SHARED_BY_DIR,
46+
IIO_SHARED_BY_ALL
4547
};
4648

4749
enum iio_endian {
@@ -156,6 +158,10 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
156158
* this channel.
157159
* @info_mask_shared_by_type: What information is to be exported that is shared
158160
* by all channels of the same type.
161+
* @info_mask_shared_by_dir: What information is to be exported that is shared
162+
* by all channels of the same direction.
163+
* @info_mask_shared_by_all: What information is to be exported that is shared
164+
* by all channels.
159165
* @event_mask: What events can this channel produce.
160166
* @ext_info: Array of extended info attributes for this channel.
161167
* The array is NULL terminated, the last element should
@@ -192,6 +198,8 @@ struct iio_chan_spec {
192198
} scan_type;
193199
long info_mask_separate;
194200
long info_mask_shared_by_type;
201+
long info_mask_shared_by_dir;
202+
long info_mask_shared_by_all;
195203
long event_mask;
196204
const struct iio_chan_spec_ext_info *ext_info;
197205
const char *extend_name;
@@ -215,7 +223,9 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
215223
enum iio_chan_info_enum type)
216224
{
217225
return (chan->info_mask_separate & BIT(type)) |
218-
(chan->info_mask_shared_by_type & BIT(type));
226+
(chan->info_mask_shared_by_type & BIT(type)) |
227+
(chan->info_mask_shared_by_dir & BIT(type)) |
228+
(chan->info_mask_shared_by_all & BIT(type));
219229
}
220230

221231
#define IIO_ST(si, rb, sb, sh) \

0 commit comments

Comments
 (0)