staging:iio:adc:ad7291: fix channel mapping for event enables
authorMichael Hennerich <michael.hennerich@analog.com>
Fri, 2 Sep 2011 16:25:43 +0000 (17:25 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 6 Sep 2011 23:03:37 +0000 (16:03 -0700)
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/adc/ad7291.c

index 840353624a765481bbdaa2c5bff034c3950fbbc5..687509fcc9780eba7631f880297e7b1f9d5f82cf 100644 (file)
@@ -101,7 +101,7 @@ struct ad7291_chip_info {
        struct regulator        *reg;
        u16                     int_vref_mv;
        u16                     command;
-       u                     c_mask; /* Active voltage channels for events */
+       u16                     c_mask; /* Active voltage channels for events */
        struct mutex            state_lock;
 };
 
@@ -381,7 +381,7 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
        switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
        case IIO_VOLTAGE:
                if (chip->c_mask &
-                   (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))
+                   (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
                        return 1;
                else
                        return 0;
@@ -412,19 +412,19 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
 
        switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
        case IIO_VOLTAGE:
-               if ((!state) && (chip->c_mask &
-                              (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code))))
-                       chip->c_mask &=
-                               ~(1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
-               else if (state && (!(chip->c_mask &
-                               (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
-                       chip->c_mask |=
-                               (1 << IIO_EVENT_CODE_EXTRACT_NUM(event_code));
+               if ((!state) && (chip->c_mask & (1 << (15 -
+                               IIO_EVENT_CODE_EXTRACT_NUM(event_code)))))
+                       chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
+                                                       (event_code)));
+               else if (state && (!(chip->c_mask & (1 << (15 -
+                               IIO_EVENT_CODE_EXTRACT_NUM(event_code))))))
+                       chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_NUM
+                                                       (event_code)));
                else
                        break;
 
                regval &= ~AD7291_AUTOCYCLE;
-               regval |= ((u16)chip->c_mask << 8);
+               regval |= chip->c_mask;
                if (chip->c_mask) /* Enable autocycle? */
                        regval |= AD7291_AUTOCYCLE;
 
@@ -461,7 +461,7 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
                case IIO_VOLTAGE:
                        mutex_lock(&chip->state_lock);
                        /* If in autocycle mode drop through */
-                       if (chip->command & 0x1) {
+                       if (chip->command & AD7291_AUTOCYCLE) {
                                mutex_unlock(&chip->state_lock);
                                return -EBUSY;
                        }