[media] media: coda: Fix DT driver data pointer for i.MX27
[linux/fpc-iii.git] / drivers / iio / common / st_sensors / st_sensors_trigger.c
blob8fc3a97eb266e6302367653248017c3b6078a021
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 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);
48 if (err < 0) {
49 dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
50 goto iio_trigger_register_error;
52 indio_dev->trig = sdata->trig;
54 return 0;
56 iio_trigger_register_error:
57 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
58 request_irq_error:
59 iio_trigger_free(sdata->trig);
60 iio_trigger_alloc_error:
61 return err;
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");