Merge tag 'regulator-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[deliverable/linux.git] / drivers / iio / common / hid-sensors / hid-sensor-trigger.c
CommitLineData
73c6768b 1/*
2 * HID Sensors Driver
3 * Copyright (c) 2012, Intel Corporation.
4 *
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.
8 *
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.
13 *
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.
17 *
18 */
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>
73c6768b 29#include "hid-sensor-trigger.h"
30
31static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
32 bool state)
33{
1e9663c6 34 struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
73c6768b 35 int state_val;
36
7d3c192d
SP
37 if (state) {
38 if (sensor_hub_device_open(st->hsdev))
39 return -EIO;
40 } else
41 sensor_hub_device_close(st->hsdev);
42
73c6768b 43 state_val = state ? 1 : 0;
69bcd3bf
KS
44 if (IS_ENABLED(CONFIG_HID_SENSOR_ENUM_BASE_QUIRKS))
45 ++state_val;
73c6768b 46 st->data_ready = state;
47 sensor_hub_set_feature(st->hsdev, st->power_state.report_id,
48 st->power_state.index,
49 (s32)state_val);
50
51 sensor_hub_set_feature(st->hsdev, st->report_state.report_id,
52 st->report_state.index,
53 (s32)state_val);
54
55 return 0;
56}
57
58void hid_sensor_remove_trigger(struct iio_dev *indio_dev)
59{
60 iio_trigger_unregister(indio_dev->trig);
61 iio_trigger_free(indio_dev->trig);
f07b60b7 62 indio_dev->trig = NULL;
73c6768b 63}
64EXPORT_SYMBOL(hid_sensor_remove_trigger);
65
66static const struct iio_trigger_ops hid_sensor_trigger_ops = {
67 .owner = THIS_MODULE,
68 .set_trigger_state = &hid_sensor_data_rdy_trigger_set_state,
69};
70
71int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
e07c6d17 72 struct hid_sensor_common *attrb)
73c6768b 73{
74 int ret;
75 struct iio_trigger *trig;
76
77 trig = iio_trigger_alloc("%s-dev%d", name, indio_dev->id);
78 if (trig == NULL) {
79 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
80 ret = -ENOMEM;
81 goto error_ret;
82 }
83
84 trig->dev.parent = indio_dev->dev.parent;
1e9663c6 85 iio_trigger_set_drvdata(trig, attrb);
73c6768b 86 trig->ops = &hid_sensor_trigger_ops;
87 ret = iio_trigger_register(trig);
88
89 if (ret) {
90 dev_err(&indio_dev->dev, "Trigger Register Failed\n");
91 goto error_free_trig;
92 }
93 indio_dev->trig = trig;
94
95 return ret;
96
97error_free_trig:
98 iio_trigger_free(trig);
99error_ret:
100 return ret;
101}
102EXPORT_SYMBOL(hid_sensor_setup_trigger);
103
104MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
105MODULE_DESCRIPTION("HID Sensor trigger processing");
106MODULE_LICENSE("GPL");
This page took 0.138113 seconds and 5 git commands to generate.