Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2015 Cogent Embedded, Inc.
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/export.h>
0008 #include <linux/module.h>
0009 #include <linux/iio/iio.h>
0010 #include <linux/iio/triggered_event.h>
0011 #include <linux/iio/trigger_consumer.h>
0012 
0013 /**
0014  * iio_triggered_event_setup() - Setup pollfunc_event for triggered event
0015  * @indio_dev:  IIO device structure
0016  * @h:      Function which will be used as pollfunc_event top half
0017  * @thread: Function which will be used as pollfunc_event bottom half
0018  *
0019  * This function combines some common tasks which will normally be performed
0020  * when setting up a triggered event. It will allocate the pollfunc_event and
0021  * set mode to use it for triggered event.
0022  *
0023  * Before calling this function the indio_dev structure should already be
0024  * completely initialized, but not yet registered. In practice this means that
0025  * this function should be called right before iio_device_register().
0026  *
0027  * To free the resources allocated by this function call
0028  * iio_triggered_event_cleanup().
0029  */
0030 int iio_triggered_event_setup(struct iio_dev *indio_dev,
0031                   irqreturn_t (*h)(int irq, void *p),
0032                   irqreturn_t (*thread)(int irq, void *p))
0033 {
0034     indio_dev->pollfunc_event = iio_alloc_pollfunc(h,
0035                                thread,
0036                                IRQF_ONESHOT,
0037                                indio_dev,
0038                                "%s_consumer%d",
0039                                indio_dev->name,
0040                                iio_device_id(indio_dev));
0041     if (indio_dev->pollfunc_event == NULL)
0042         return -ENOMEM;
0043 
0044     /* Flag that events polling is possible */
0045     indio_dev->modes |= INDIO_EVENT_TRIGGERED;
0046 
0047     return 0;
0048 }
0049 EXPORT_SYMBOL(iio_triggered_event_setup);
0050 
0051 /**
0052  * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup()
0053  * @indio_dev: IIO device structure
0054  */
0055 void iio_triggered_event_cleanup(struct iio_dev *indio_dev)
0056 {
0057     indio_dev->modes &= ~INDIO_EVENT_TRIGGERED;
0058     iio_dealloc_pollfunc(indio_dev->pollfunc_event);
0059 }
0060 EXPORT_SYMBOL(iio_triggered_event_cleanup);
0061 
0062 MODULE_AUTHOR("Vladimir Barinov");
0063 MODULE_DESCRIPTION("IIO helper functions for setting up triggered events");
0064 MODULE_LICENSE("GPL");