iio: accel: bma220: Group IIO headers together
[linux-2.6-microblaze.git] / drivers / iio / accel / bma220_spi.c
index da8b36c..73927f9 100644 (file)
@@ -5,13 +5,14 @@
  * Copyright (c) 2016, Intel Corporation.
  */
 
-#include <linux/acpi.h>
 #include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
+#include <linux/spi/spi.h>
+
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
-#include <linux/spi/spi.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
@@ -30,7 +31,6 @@
 #define BMA220_SUSPEND_WAKE                    0x00
 
 #define BMA220_DEVICE_NAME                     "bma220"
-#define BMA220_SCALE_AVAILABLE                 "0.623 1.248 2.491 4.983"
 
 #define BMA220_ACCEL_CHANNEL(index, reg, axis) {                       \
        .type = IIO_ACCEL,                                              \
@@ -55,19 +55,8 @@ enum bma220_axis {
        AXIS_Z,
 };
 
-static IIO_CONST_ATTR(in_accel_scale_available, BMA220_SCALE_AVAILABLE);
-
-static struct attribute *bma220_attributes[] = {
-       &iio_const_attr_in_accel_scale_available.dev_attr.attr,
-       NULL,
-};
-
-static const struct attribute_group bma220_attribute_group = {
-       .attrs = bma220_attributes,
-};
-
-static const int bma220_scale_table[][4] = {
-       {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000}
+static const int bma220_scale_table[][2] = {
+       {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000},
 };
 
 struct bma220_data {
@@ -182,10 +171,26 @@ static int bma220_write_raw(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
+static int bma220_read_avail(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            const int **vals, int *type, int *length,
+                            long mask)
+{
+       switch (mask) {
+       case IIO_CHAN_INFO_SCALE:
+               *vals = (int *)bma220_scale_table;
+               *type = IIO_VAL_INT_PLUS_MICRO;
+               *length = ARRAY_SIZE(bma220_scale_table) * 2;
+               return IIO_AVAIL_LIST;
+       default:
+               return -EINVAL;
+       }
+}
+
 static const struct iio_info bma220_info = {
        .read_raw               = bma220_read_raw,
        .write_raw              = bma220_write_raw,
-       .attrs                  = &bma220_attribute_group,
+       .read_avail             = bma220_read_avail,
 };
 
 static int bma220_init(struct spi_device *spi)
@@ -198,10 +203,12 @@ static int bma220_init(struct spi_device *spi)
 
        /* Make sure the chip is powered on */
        ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_WAKE)
+               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
        if (ret < 0)
                return ret;
-       else if (ret == BMA220_SUSPEND_WAKE)
-               return bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_WAKE)
+               return -EBUSY;
 
        return 0;
 }
@@ -212,10 +219,12 @@ static int bma220_deinit(struct spi_device *spi)
 
        /* Make sure the chip is powered off */
        ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_SLEEP)
+               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
        if (ret < 0)
                return ret;
-       else if (ret == BMA220_SUSPEND_SLEEP)
-               return bma220_read_reg(spi, BMA220_REG_SUSPEND);
+       if (ret == BMA220_SUSPEND_SLEEP)
+               return -EBUSY;
 
        return 0;
 }
@@ -245,7 +254,7 @@ static int bma220_probe(struct spi_device *spi)
        indio_dev->available_scan_masks = bma220_accel_scan_masks;
 
        ret = bma220_init(data->spi_device);
-       if (ret < 0)
+       if (ret)
                return ret;
 
        ret = iio_triggered_buffer_setup(indio_dev, iio_pollfunc_store_time,
@@ -278,50 +287,40 @@ static int bma220_remove(struct spi_device *spi)
        return bma220_deinit(spi);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int bma220_suspend(struct device *dev)
+static __maybe_unused int bma220_suspend(struct device *dev)
 {
-       struct bma220_data *data =
-                       iio_priv(spi_get_drvdata(to_spi_device(dev)));
+       struct bma220_data *data = iio_priv(dev_get_drvdata(dev));
 
        /* The chip can be suspended/woken up by a simple register read. */
        return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
 }
 
-static int bma220_resume(struct device *dev)
+static __maybe_unused int bma220_resume(struct device *dev)
 {
-       struct bma220_data *data =
-                       iio_priv(spi_get_drvdata(to_spi_device(dev)));
+       struct bma220_data *data = iio_priv(dev_get_drvdata(dev));
 
        return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
 }
 
 static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume);
 
-#define BMA220_PM_OPS (&bma220_pm_ops)
-#else
-#define BMA220_PM_OPS NULL
-#endif
-
 static const struct spi_device_id bma220_spi_id[] = {
        {"bma220", 0},
        {}
 };
 
-#ifdef CONFIG_ACPI
 static const struct acpi_device_id bma220_acpi_id[] = {
        {"BMA0220", 0},
        {}
 };
 
 MODULE_DEVICE_TABLE(spi, bma220_spi_id);
-#endif
 
 static struct spi_driver bma220_driver = {
        .driver = {
                .name = "bma220_spi",
-               .pm = BMA220_PM_OPS,
-               .acpi_match_table = ACPI_PTR(bma220_acpi_id),
+               .pm = &bma220_pm_ops,
+               .acpi_match_table = bma220_acpi_id,
        },
        .probe =            bma220_probe,
        .remove =           bma220_remove,