[media] media: coda: Fix DT driver data pointer for i.MX27
[linux/fpc-iii.git] / drivers / iio / common / hid-sensors / hid-sensor-trigger.c
blob87419c41b991da24d8d284d33502c81f72c1c377
1 /*
2 * HID Sensors Driver
3 * Copyright (c) 2012, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <linux/device.h>
20 #include <linux/platform_device.h>
21 #include <linux/module.h>
22 #include <linux/interrupt.h>
23 #include <linux/irq.h>
24 #include <linux/slab.h>
25 #include <linux/hid-sensor-hub.h>
26 #include <linux/iio/iio.h>
27 #include <linux/iio/trigger.h>
28 #include <linux/iio/sysfs.h>
29 #include "hid-sensor-trigger.h"
31 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
32 bool state)
34 struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
35 int state_val;
37 state_val = state ? 1 : 0;
38 if (IS_ENABLED(CONFIG_HID_SENSOR_ENUM_BASE_QUIRKS))
39 ++state_val;
40 st->data_ready = state;
41 sensor_hub_set_feature(st->hsdev, st->power_state.report_id,
42 st->power_state.index,
43 (s32)state_val);
45 sensor_hub_set_feature(st->hsdev, st->report_state.report_id,
46 st->report_state.index,
47 (s32)state_val);
49 return 0;
52 void hid_sensor_remove_trigger(struct iio_dev *indio_dev)
54 iio_trigger_unregister(indio_dev->trig);
55 iio_trigger_free(indio_dev->trig);
56 indio_dev->trig = NULL;
58 EXPORT_SYMBOL(hid_sensor_remove_trigger);
60 static const struct iio_trigger_ops hid_sensor_trigger_ops = {
61 .owner = THIS_MODULE,
62 .set_trigger_state = &hid_sensor_data_rdy_trigger_set_state,
65 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
66 struct hid_sensor_common *attrb)
68 int ret;
69 struct iio_trigger *trig;
71 trig = iio_trigger_alloc("%s-dev%d", name, indio_dev->id);
72 if (trig == NULL) {
73 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
74 ret = -ENOMEM;
75 goto error_ret;
78 trig->dev.parent = indio_dev->dev.parent;
79 iio_trigger_set_drvdata(trig, attrb);
80 trig->ops = &hid_sensor_trigger_ops;
81 ret = iio_trigger_register(trig);
83 if (ret) {
84 dev_err(&indio_dev->dev, "Trigger Register Failed\n");
85 goto error_free_trig;
87 indio_dev->trig = trig;
89 return ret;
91 error_free_trig:
92 iio_trigger_free(trig);
93 error_ret:
94 return ret;
96 EXPORT_SYMBOL(hid_sensor_setup_trigger);
98 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
99 MODULE_DESCRIPTION("HID Sensor trigger processing");
100 MODULE_LICENSE("GPL");