iio: add resource managed triggered buffer init helpers
authorGregor Boirie <gregor.boirie@parrot.com>
Fri, 2 Sep 2016 18:47:55 +0000 (20:47 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 4 Sep 2016 14:42:46 +0000 (15:42 +0100)
Add resource managed devm_iio_triggered_buffer_setup() and
devm_iio_triggered_buffer_cleanup() to automatically clean up triggered
buffers setup by IIO drivers, thus leading to simplified IIO drivers code.

Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Documentation/driver-model/devres.txt
drivers/iio/buffer/industrialio-triggered-buffer.c
drivers/iio/industrialio-core.c
include/linux/iio/iio.h
include/linux/iio/triggered_buffer.h

index 6a2138a7c3ff65301ff1a4282834f13f420f0949..75bc5b8add2fe71128c285d11062c0361e525378 100644 (file)
@@ -266,6 +266,8 @@ IIO
   devm_iio_device_unregister()
   devm_iio_kfifo_allocate()
   devm_iio_kfifo_free()
+  devm_iio_triggered_buffer_setup()
+  devm_iio_triggered_buffer_cleanup()
   devm_iio_trigger_alloc()
   devm_iio_trigger_free()
   devm_iio_trigger_register()
index 4b2858ba1fd6c534e8a23bdcc4a6a5b9f813b56d..d3db1fce54d2ab762b3bee63fb572a67d60b3f72 100644 (file)
@@ -98,6 +98,48 @@ void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev)
 }
 EXPORT_SYMBOL(iio_triggered_buffer_cleanup);
 
+static void devm_iio_triggered_buffer_clean(struct device *dev, void *res)
+{
+       iio_triggered_buffer_cleanup(*(struct iio_dev **)res);
+}
+
+int devm_iio_triggered_buffer_setup(struct device *dev,
+                                   struct iio_dev *indio_dev,
+                                   irqreturn_t (*h)(int irq, void *p),
+                                   irqreturn_t (*thread)(int irq, void *p),
+                                   const struct iio_buffer_setup_ops *ops)
+{
+       struct iio_dev **ptr;
+       int ret;
+
+       ptr = devres_alloc(devm_iio_triggered_buffer_clean, sizeof(*ptr),
+                          GFP_KERNEL);
+       if (!ptr)
+               return -ENOMEM;
+
+       *ptr = indio_dev;
+
+       ret = iio_triggered_buffer_setup(indio_dev, h, thread, ops);
+       if (!ret)
+               devres_add(dev, ptr);
+       else
+               devres_free(ptr);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup);
+
+void devm_iio_triggered_buffer_cleanup(struct device *dev,
+                                      struct iio_dev *indio_dev)
+{
+       int rc;
+
+       rc = devres_release(dev, devm_iio_triggered_buffer_clean,
+                           devm_iio_device_match, indio_dev);
+       WARN_ON(rc);
+}
+EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_cleanup);
+
 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
 MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
 MODULE_LICENSE("GPL");
index f914d5d140e4014f5a31011c7783959fe8022755..0528a0c1b96438a3321308b204285d78d5e7a93f 100644 (file)
@@ -1309,7 +1309,7 @@ static void devm_iio_device_release(struct device *dev, void *res)
        iio_device_free(*(struct iio_dev **)res);
 }
 
-static int devm_iio_device_match(struct device *dev, void *res, void *data)
+int devm_iio_device_match(struct device *dev, void *res, void *data)
 {
        struct iio_dev **r = res;
        if (!r || !*r) {
@@ -1318,6 +1318,7 @@ static int devm_iio_device_match(struct device *dev, void *res, void *data)
        }
        return *r == data;
 }
+EXPORT_SYMBOL_GPL(devm_iio_device_match);
 
 /**
  * devm_iio_device_alloc - Resource-managed iio_device_alloc()
index 786952cd509fa78085f0bced5b9d61c79e891f4a..b4a0679e4a49a22584c4288ba6bf4e6aa4df4d4b 100644 (file)
@@ -644,6 +644,7 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv)
 }
 
 void iio_device_free(struct iio_dev *indio_dev);
+int devm_iio_device_match(struct device *dev, void *res, void *data);
 struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
 void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev);
 struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
index f72f70d5a97b2ae58b7ed769d0bb6984021d5d06..30145616773d303054fd257fbc8ccf85e863de35 100644 (file)
@@ -12,4 +12,12 @@ int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
        const struct iio_buffer_setup_ops *setup_ops);
 void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);
 
+int devm_iio_triggered_buffer_setup(struct device *dev,
+                                   struct iio_dev *indio_dev,
+                                   irqreturn_t (*h)(int irq, void *p),
+                                   irqreturn_t (*thread)(int irq, void *p),
+                                   const struct iio_buffer_setup_ops *ops);
+void devm_iio_triggered_buffer_cleanup(struct device *dev,
+                                      struct iio_dev *indio_dev);
+
 #endif