gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / iio / industrialio-triggered-event.c
blob53da9ab17a62362aa3263fc757e08e8f5866675f
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2015 Cogent Embedded, Inc.
4 */
6 #include <linux/kernel.h>
7 #include <linux/export.h>
8 #include <linux/module.h>
9 #include <linux/iio/iio.h>
10 #include <linux/iio/triggered_event.h>
11 #include <linux/iio/trigger_consumer.h>
13 /**
14 * iio_triggered_event_setup() - Setup pollfunc_event for triggered event
15 * @indio_dev: IIO device structure
16 * @h: Function which will be used as pollfunc_event top half
17 * @thread: Function which will be used as pollfunc_event bottom half
19 * This function combines some common tasks which will normally be performed
20 * when setting up a triggered event. It will allocate the pollfunc_event and
21 * set mode to use it for triggered event.
23 * Before calling this function the indio_dev structure should already be
24 * completely initialized, but not yet registered. In practice this means that
25 * this function should be called right before iio_device_register().
27 * To free the resources allocated by this function call
28 * iio_triggered_event_cleanup().
30 int iio_triggered_event_setup(struct iio_dev *indio_dev,
31 irqreturn_t (*h)(int irq, void *p),
32 irqreturn_t (*thread)(int irq, void *p))
34 indio_dev->pollfunc_event = iio_alloc_pollfunc(h,
35 thread,
36 IRQF_ONESHOT,
37 indio_dev,
38 "%s_consumer%d",
39 indio_dev->name,
40 indio_dev->id);
41 if (indio_dev->pollfunc_event == NULL)
42 return -ENOMEM;
44 /* Flag that events polling is possible */
45 indio_dev->modes |= INDIO_EVENT_TRIGGERED;
47 return 0;
49 EXPORT_SYMBOL(iio_triggered_event_setup);
51 /**
52 * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup()
53 * @indio_dev: IIO device structure
55 void iio_triggered_event_cleanup(struct iio_dev *indio_dev)
57 indio_dev->modes &= ~INDIO_EVENT_TRIGGERED;
58 iio_dealloc_pollfunc(indio_dev->pollfunc_event);
60 EXPORT_SYMBOL(iio_triggered_event_cleanup);
62 MODULE_AUTHOR("Vladimir Barinov");
63 MODULE_DESCRIPTION("IIO helper functions for setting up triggered events");
64 MODULE_LICENSE("GPL");