staging: iio: push the main buffer chrdev down to the top level.
[deliverable/linux.git] / drivers / staging / iio / adc / max1363_core.c
index 98cebd26310f0f05321d2df5a4c8c49690b4fc4e..53b745143ae3da99be0c0deb81c6bb510f9681be 100644 (file)
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <linux/module.h>
 
 #include "../iio.h"
 #include "../sysfs.h"
-
 #include "../ring_generic.h"
-#include "adc.h"
+
 #include "max1363.h"
 
 #define MAX1363_MODE_SINGLE(_num, _mask) {                             \
@@ -255,7 +255,7 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
        switch (m) {
        case 0:
                ret = max1363_read_single_chan(indio_dev, chan, val, m);
-               if (ret)
+               if (ret < 0)
                        return ret;
                return IIO_VAL_INT;
        case (1 << IIO_CHAN_INFO_SCALE_SHARED):
@@ -592,10 +592,14 @@ static int max1363_write_thresh(struct iio_dev *indio_dev,
 }
 
 static const int max1363_event_codes[] = {
-       IIO_EVENT_CODE_IN_LOW_THRESH(3), IIO_EVENT_CODE_IN_HIGH_THRESH(3),
-       IIO_EVENT_CODE_IN_LOW_THRESH(2), IIO_EVENT_CODE_IN_HIGH_THRESH(2),
-       IIO_EVENT_CODE_IN_LOW_THRESH(1), IIO_EVENT_CODE_IN_HIGH_THRESH(1),
-       IIO_EVENT_CODE_IN_LOW_THRESH(0), IIO_EVENT_CODE_IN_HIGH_THRESH(0)
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 1, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 2, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 3, IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 0, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 1, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 2, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
+       IIO_UNMOD_EVENT_CODE(IIO_IN, 3, IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
 };
 
 static irqreturn_t max1363_event_handler(int irq, void *private)
@@ -823,6 +827,7 @@ static struct attribute *max1363_event_attributes[] = {
 
 static struct attribute_group max1363_event_attribute_group = {
        .attrs = max1363_event_attributes,
+       .name = "events",
 };
 
 #define MAX1363_EVENT_FUNCS                                            \
@@ -1255,12 +1260,15 @@ static int __devinit max1363_probe(struct i2c_client *client,
        struct regulator *reg;
 
        reg = regulator_get(&client->dev, "vcc");
-       if (!IS_ERR(reg)) {
-               ret = regulator_enable(reg);
-               if (ret)
-                       goto error_put_reg;
+       if (IS_ERR(reg)) {
+               ret = PTR_ERR(reg);
+               goto error_out;
        }
 
+       ret = regulator_enable(reg);
+       if (ret)
+               goto error_put_reg;
+
        indio_dev = iio_allocate_device(sizeof(struct max1363_state));
        if (indio_dev == NULL) {
                ret = -ENOMEM;
@@ -1289,9 +1297,12 @@ static int __devinit max1363_probe(struct i2c_client *client,
        /* Estabilish that the iio_dev is a child of the i2c device */
        indio_dev->dev.parent = &client->dev;
        indio_dev->name = id->name;
-
+       indio_dev->channels = st->chip_info->channels;
+       indio_dev->num_channels = st->chip_info->num_channels;
        indio_dev->info = st->chip_info->info;
        indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = st->chip_info->channels;
+       indio_dev->num_channels = st->chip_info->num_channels;
        ret = max1363_initial_setup(st);
        if (ret < 0)
                goto error_free_available_scan_masks;
@@ -1304,7 +1315,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
        if (ret)
                goto error_cleanup_ring;
        regdone = 1;
-       ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
+       ret = iio_ring_buffer_register_ex(indio_dev, 0,
                                          st->chip_info->channels,
                                          st->chip_info->num_channels);
        if (ret)
@@ -1323,8 +1334,9 @@ static int __devinit max1363_probe(struct i2c_client *client,
        }
 
        return 0;
+
 error_uninit_ring:
-       iio_ring_buffer_unregister(indio_dev->ring);
+       iio_ring_buffer_unregister(indio_dev);
 error_cleanup_ring:
        max1363_ring_cleanup(indio_dev);
 error_free_available_scan_masks:
@@ -1335,12 +1347,10 @@ error_free_device:
        else
                iio_device_unregister(indio_dev);
 error_disable_reg:
-       if (!IS_ERR(st->reg))
-               regulator_disable(st->reg);
+       regulator_disable(reg);
 error_put_reg:
-       if (!IS_ERR(st->reg))
-               regulator_put(st->reg);
-
+       regulator_put(reg);
+error_out:
        return ret;
 }
 
@@ -1352,7 +1362,7 @@ static int max1363_remove(struct i2c_client *client)
 
        if (client->irq)
                free_irq(st->client->irq, indio_dev);
-       iio_ring_buffer_unregister(indio_dev->ring);
+       iio_ring_buffer_unregister(indio_dev);
        max1363_ring_cleanup(indio_dev);
        kfree(indio_dev->available_scan_masks);
        if (!IS_ERR(reg)) {
This page took 0.028778 seconds and 5 git commands to generate.