Merge tag 'irqdomain-for-linus' of git://git.secretlab.ca/git/linux-2.6
[pandora-kernel.git] / drivers / iio / industrialio-core.c
index 52aa44a..1ddd886 100644 (file)
@@ -91,6 +91,7 @@ static const char * const iio_chan_info_postfix[] = {
        [IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
        [IIO_CHAN_INFO_FREQUENCY] = "frequency",
        [IIO_CHAN_INFO_PHASE] = "phase",
+       [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
 };
 
 const struct iio_chan_spec
@@ -227,15 +228,12 @@ static int iio_device_register_debugfs(struct iio_dev *indio_dev)
        if (indio_dev->info->debugfs_reg_access == NULL)
                return 0;
 
-       if (IS_ERR(iio_debugfs_dentry))
+       if (!iio_debugfs_dentry)
                return 0;
 
        indio_dev->debugfs_dentry =
                debugfs_create_dir(dev_name(&indio_dev->dev),
                                   iio_debugfs_dentry);
-       if (IS_ERR(indio_dev->debugfs_dentry))
-               return PTR_ERR(indio_dev->debugfs_dentry);
-
        if (indio_dev->debugfs_dentry == NULL) {
                dev_warn(indio_dev->dev.parent,
                         "Failed to create debugfs directory\n");
@@ -267,7 +265,7 @@ static ssize_t iio_read_channel_ext_info(struct device *dev,
                                     struct device_attribute *attr,
                                     char *buf)
 {
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
        const struct iio_chan_spec_ext_info *ext_info;
 
@@ -281,7 +279,7 @@ static ssize_t iio_write_channel_ext_info(struct device *dev,
                                     const char *buf,
                                         size_t len)
 {
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
        const struct iio_chan_spec_ext_info *ext_info;
 
@@ -295,29 +293,36 @@ static ssize_t iio_read_channel_info(struct device *dev,
                                     struct device_attribute *attr,
                                     char *buf)
 {
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
        int val, val2;
+       bool scale_db = false;
        int ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
                                            &val, &val2, this_attr->address);
 
        if (ret < 0)
                return ret;
 
-       if (ret == IIO_VAL_INT)
+       switch (ret) {
+       case IIO_VAL_INT:
                return sprintf(buf, "%d\n", val);
-       else if (ret == IIO_VAL_INT_PLUS_MICRO) {
+       case IIO_VAL_INT_PLUS_MICRO_DB:
+               scale_db = true;
+       case IIO_VAL_INT_PLUS_MICRO:
                if (val2 < 0)
-                       return sprintf(buf, "-%d.%06u\n", val, -val2);
+                       return sprintf(buf, "-%d.%06u%s\n", val, -val2,
+                               scale_db ? " dB" : "");
                else
-                       return sprintf(buf, "%d.%06u\n", val, val2);
-       } else if (ret == IIO_VAL_INT_PLUS_NANO) {
+                       return sprintf(buf, "%d.%06u%s\n", val, val2,
+                               scale_db ? " dB" : "");
+       case IIO_VAL_INT_PLUS_NANO:
                if (val2 < 0)
                        return sprintf(buf, "-%d.%09u\n", val, -val2);
                else
                        return sprintf(buf, "%d.%09u\n", val, val2);
-       } else
+       default:
                return 0;
+       }
 }
 
 static ssize_t iio_write_channel_info(struct device *dev,
@@ -325,7 +330,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
                                      const char *buf,
                                      size_t len)
 {
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
        int ret, integer = 0, fract = 0, fract_mult = 100000;
        bool integer_part = true, negative = false;
@@ -633,7 +638,7 @@ static ssize_t iio_show_dev_name(struct device *dev,
                                 struct device_attribute *attr,
                                 char *buf)
 {
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        return sprintf(buf, "%s\n", indio_dev->name);
 }
 
@@ -719,7 +724,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
 
 static void iio_dev_release(struct device *device)
 {
-       struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
+       struct iio_dev *indio_dev = dev_to_iio_dev(device);
        cdev_del(&indio_dev->chrdev);
        if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
                iio_device_unregister_trigger_consumer(indio_dev);