irqchip/s3c24xx: Mark init_eint as __maybe_unused
[linux/fpc-iii.git] / drivers / iio / common / st_sensors / st_sensors_trigger.c
blob3e907040c2c7a7712035376b019c462bd441ddb8
1 /*
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.
9 */
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)
24 int err;
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) {
29 err = -ENOMEM;
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,
36 NULL,
37 IRQF_TRIGGER_RISING,
38 sdata->trig->name,
39 sdata->trig);
40 if (err) {
41 dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");
42 goto request_irq_error;
45 iio_trigger_set_drvdata(sdata->trig, indio_dev);
46 sdata->trig->ops = trigger_ops;
47 sdata->trig->dev.parent = sdata->dev;
49 err = iio_trigger_register(sdata->trig);
50 if (err < 0) {
51 dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
52 goto iio_trigger_register_error;
54 indio_dev->trig = iio_trigger_get(sdata->trig);
56 return 0;
58 iio_trigger_register_error:
59 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
60 request_irq_error:
61 iio_trigger_free(sdata->trig);
62 iio_trigger_alloc_error:
63 return err;
65 EXPORT_SYMBOL(st_sensors_allocate_trigger);
67 void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
69 struct st_sensor_data *sdata = iio_priv(indio_dev);
71 iio_trigger_unregister(sdata->trig);
72 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
73 iio_trigger_free(sdata->trig);
75 EXPORT_SYMBOL(st_sensors_deallocate_trigger);
77 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
78 MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger");
79 MODULE_LICENSE("GPL v2");