Linux Audio

Check our new training course

Buildroot integration, development and maintenance

Need a Buildroot system for your embedded project?
Loading...
v6.9.4
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * Copyright (C) 2015 Cogent Embedded, Inc.
 
 
 
 
 
 4 */
 5
 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>
12
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
18 *
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.
22 *
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().
26 *
27 * To free the resources allocated by this function call
28 * iio_triggered_event_cleanup().
29 */
30int 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))
33{
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						       iio_device_id(indio_dev));
41	if (indio_dev->pollfunc_event == NULL)
42		return -ENOMEM;
43
44	/* Flag that events polling is possible */
45	indio_dev->modes |= INDIO_EVENT_TRIGGERED;
46
47	return 0;
48}
49EXPORT_SYMBOL(iio_triggered_event_setup);
50
51/**
52 * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup()
53 * @indio_dev: IIO device structure
54 */
55void iio_triggered_event_cleanup(struct iio_dev *indio_dev)
56{
57	indio_dev->modes &= ~INDIO_EVENT_TRIGGERED;
58	iio_dealloc_pollfunc(indio_dev->pollfunc_event);
59}
60EXPORT_SYMBOL(iio_triggered_event_cleanup);
61
62MODULE_AUTHOR("Vladimir Barinov");
63MODULE_DESCRIPTION("IIO helper functions for setting up triggered events");
64MODULE_LICENSE("GPL");
v4.6
 
 1/*
 2 * Copyright (C) 2015 Cogent Embedded, Inc.
 3 *
 4 * This program is free software; you can redistribute  it and/or modify it
 5 * under  the terms of  the GNU General  Public License as published by the
 6 * Free Software Foundation;  either version 2 of the  License, or (at your
 7 * option) any later version.
 8 */
 9
10#include <linux/kernel.h>
11#include <linux/export.h>
12#include <linux/module.h>
13#include <linux/iio/iio.h>
14#include <linux/iio/triggered_event.h>
15#include <linux/iio/trigger_consumer.h>
16
17/**
18 * iio_triggered_event_setup() - Setup pollfunc_event for triggered event
19 * @indio_dev:	IIO device structure
20 * @h:		Function which will be used as pollfunc_event top half
21 * @thread:	Function which will be used as pollfunc_event bottom half
22 *
23 * This function combines some common tasks which will normally be performed
24 * when setting up a triggered event. It will allocate the pollfunc_event and
25 * set mode to use it for triggered event.
26 *
27 * Before calling this function the indio_dev structure should already be
28 * completely initialized, but not yet registered. In practice this means that
29 * this function should be called right before iio_device_register().
30 *
31 * To free the resources allocated by this function call
32 * iio_triggered_event_cleanup().
33 */
34int iio_triggered_event_setup(struct iio_dev *indio_dev,
35			      irqreturn_t (*h)(int irq, void *p),
36			      irqreturn_t (*thread)(int irq, void *p))
37{
38	indio_dev->pollfunc_event = iio_alloc_pollfunc(h,
39						       thread,
40						       IRQF_ONESHOT,
41						       indio_dev,
42						       "%s_consumer%d",
43						       indio_dev->name,
44						       indio_dev->id);
45	if (indio_dev->pollfunc_event == NULL)
46		return -ENOMEM;
47
48	/* Flag that events polling is possible */
49	indio_dev->modes |= INDIO_EVENT_TRIGGERED;
50
51	return 0;
52}
53EXPORT_SYMBOL(iio_triggered_event_setup);
54
55/**
56 * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup()
57 * @indio_dev: IIO device structure
58 */
59void iio_triggered_event_cleanup(struct iio_dev *indio_dev)
60{
61	indio_dev->modes &= ~INDIO_EVENT_TRIGGERED;
62	iio_dealloc_pollfunc(indio_dev->pollfunc_event);
63}
64EXPORT_SYMBOL(iio_triggered_event_cleanup);
65
66MODULE_AUTHOR("Vladimir Barinov");
67MODULE_DESCRIPTION("IIO helper functions for setting up triggered events");
68MODULE_LICENSE("GPL");