]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
iio: add info_mask_[shared_by_dir/shared_by_all]
authorJonathan Cameron <jic23@kernel.org>
Sun, 8 Sep 2013 13:57:00 +0000 (14:57 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sun, 15 Sep 2013 16:45:49 +0000 (17:45 +0100)
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>
drivers/iio/industrialio-core.c
include/linux/iio/iio.h

index d380c7278a26daa9f719202af9fb06e1e66093dc..24db1855dbab84398c884af99780ded81f5e184b 100644 (file)
@@ -551,6 +551,14 @@ int __iio_device_attr_init(struct device_attribute *dev_attr,
 
        if (chan->differential) { /* Differential can not have modifier */
                switch (shared_by) {
+               case IIO_SHARED_BY_ALL:
+                       name_format = kasprintf(GFP_KERNEL, "%s", full_postfix);
+                       break;
+               case IIO_SHARED_BY_DIR:
+                       name_format = kasprintf(GFP_KERNEL, "%s_%s",
+                                               iio_direction[chan->output],
+                                               full_postfix);
+                       break;
                case IIO_SHARED_BY_TYPE:
                        name_format
                                = kasprintf(GFP_KERNEL, "%s_%s-%s_%s",
@@ -578,6 +586,14 @@ int __iio_device_attr_init(struct device_attribute *dev_attr,
                }
        } else { /* Single ended */
                switch (shared_by) {
+               case IIO_SHARED_BY_ALL:
+                       name_format = kasprintf(GFP_KERNEL, "%s", full_postfix);
+                       break;
+               case IIO_SHARED_BY_DIR:
+                       name_format = kasprintf(GFP_KERNEL, "%s_%s",
+                                               iio_direction[chan->output],
+                                               full_postfix);
+                       break;
                case IIO_SHARED_BY_TYPE:
                        name_format
                                = kasprintf(GFP_KERNEL, "%s_%s_%s",
@@ -736,6 +752,20 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
                return ret;
        attrcount += ret;
 
+       ret = iio_device_add_info_mask_type(indio_dev, chan,
+                                           IIO_SHARED_BY_DIR,
+                                           &chan->info_mask_shared_by_dir);
+       if (ret < 0)
+               return ret;
+       attrcount += ret;
+
+       ret = iio_device_add_info_mask_type(indio_dev, chan,
+                                           IIO_SHARED_BY_ALL,
+                                           &chan->info_mask_shared_by_all);
+       if (ret < 0)
+               return ret;
+       attrcount += ret;
+
        if (chan->ext_info) {
                unsigned int i = 0;
                for (ext_info = chan->ext_info; ext_info->name; ext_info++) {
index 21de272f1eb68eeb11db116c08887031ca5f5d83..ac1cb8f1858c1f48bea30be9b51da3d577f2b01b 100644 (file)
@@ -41,7 +41,9 @@ enum iio_chan_info_enum {
 
 enum iio_shared_by {
        IIO_SEPARATE,
-       IIO_SHARED_BY_TYPE
+       IIO_SHARED_BY_TYPE,
+       IIO_SHARED_BY_DIR,
+       IIO_SHARED_BY_ALL
 };
 
 enum iio_endian {
@@ -156,6 +158,10 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
  *                     this channel.
  * @info_mask_shared_by_type: What information is to be exported that is shared
  *                     by all channels of the same type.
+ * @info_mask_shared_by_dir: What information is to be exported that is shared
+ *                     by all channels of the same direction.
+ * @info_mask_shared_by_all: What information is to be exported that is shared
+ *                     by all channels.
  * @event_mask:                What events can this channel produce.
  * @ext_info:          Array of extended info attributes for this channel.
  *                     The array is NULL terminated, the last element should
@@ -192,6 +198,8 @@ struct iio_chan_spec {
        } scan_type;
        long                    info_mask_separate;
        long                    info_mask_shared_by_type;
+       long                    info_mask_shared_by_dir;
+       long                    info_mask_shared_by_all;
        long                    event_mask;
        const struct iio_chan_spec_ext_info *ext_info;
        const char              *extend_name;
@@ -215,7 +223,9 @@ static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
        enum iio_chan_info_enum type)
 {
        return (chan->info_mask_separate & BIT(type)) |
-              (chan->info_mask_shared_by_type & BIT(type));
+               (chan->info_mask_shared_by_type & BIT(type)) |
+               (chan->info_mask_shared_by_dir & BIT(type)) |
+               (chan->info_mask_shared_by_all & BIT(type));
 }
 
 #define IIO_ST(si, rb, sb, sh)                                         \