2 * STMicroelectronics sensors trigger library driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/iio/iio.h>
15 #include <linux/iio/trigger.h>
16 #include <linux/interrupt.h>
18 #include <linux/iio/common/st_sensors.h>
21 int st_sensors_allocate_trigger(struct iio_dev
*indio_dev
,
22 const struct iio_trigger_ops
*trigger_ops
)
25 struct st_sensor_data
*sdata
= iio_priv(indio_dev
);
27 sdata
->trig
= iio_trigger_alloc("%s-trigger", indio_dev
->name
);
28 if (sdata
->trig
== NULL
) {
30 dev_err(&indio_dev
->dev
, "failed to allocate iio trigger.\n");
31 goto iio_trigger_alloc_error
;
34 err
= request_threaded_irq(sdata
->get_irq_data_ready(indio_dev
),
35 iio_trigger_generic_data_rdy_poll
,
41 goto request_irq_error
;
43 iio_trigger_set_drvdata(sdata
->trig
, indio_dev
);
44 sdata
->trig
->ops
= trigger_ops
;
45 sdata
->trig
->dev
.parent
= sdata
->dev
;
47 err
= iio_trigger_register(sdata
->trig
);
49 dev_err(&indio_dev
->dev
, "failed to register iio trigger.\n");
50 goto iio_trigger_register_error
;
52 indio_dev
->trig
= sdata
->trig
;
56 iio_trigger_register_error
:
57 free_irq(sdata
->get_irq_data_ready(indio_dev
), sdata
->trig
);
59 iio_trigger_free(sdata
->trig
);
60 iio_trigger_alloc_error
:
63 EXPORT_SYMBOL(st_sensors_allocate_trigger
);
65 void st_sensors_deallocate_trigger(struct iio_dev
*indio_dev
)
67 struct st_sensor_data
*sdata
= iio_priv(indio_dev
);
69 iio_trigger_unregister(sdata
->trig
);
70 free_irq(sdata
->get_irq_data_ready(indio_dev
), sdata
->trig
);
71 iio_trigger_free(sdata
->trig
);
73 EXPORT_SYMBOL(st_sensors_deallocate_trigger
);
75 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
76 MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger");
77 MODULE_LICENSE("GPL v2");