Commit | Line | Data |
---|---|---|
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 | ||
31 | static 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; |
751d17e2 | 36 | int report_val; |
73c6768b | 37 | |
7d3c192d SP |
38 | if (state) { |
39 | if (sensor_hub_device_open(st->hsdev)) | |
40 | return -EIO; | |
751d17e2 SP |
41 | state_val = |
42 | HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM; | |
43 | report_val = | |
44 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM; | |
45 | ||
46 | } else { | |
7d3c192d | 47 | sensor_hub_device_close(st->hsdev); |
751d17e2 SP |
48 | state_val = |
49 | HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM; | |
50 | report_val = | |
51 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM; | |
52 | } | |
7d3c192d | 53 | |
73c6768b | 54 | st->data_ready = state; |
751d17e2 SP |
55 | state_val += st->power_state.logical_minimum; |
56 | report_val += st->report_state.logical_minimum; | |
73c6768b | 57 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, |
58 | st->power_state.index, | |
59 | (s32)state_val); | |
60 | ||
61 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, | |
62 | st->report_state.index, | |
751d17e2 | 63 | (s32)report_val); |
73c6768b | 64 | |
65 | return 0; | |
66 | } | |
67 | ||
ec7f68e0 | 68 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) |
73c6768b | 69 | { |
ec7f68e0 SP |
70 | iio_trigger_unregister(attrb->trigger); |
71 | iio_trigger_free(attrb->trigger); | |
73c6768b | 72 | } |
73 | EXPORT_SYMBOL(hid_sensor_remove_trigger); | |
74 | ||
75 | static const struct iio_trigger_ops hid_sensor_trigger_ops = { | |
76 | .owner = THIS_MODULE, | |
77 | .set_trigger_state = &hid_sensor_data_rdy_trigger_set_state, | |
78 | }; | |
79 | ||
80 | int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, | |
e07c6d17 | 81 | struct hid_sensor_common *attrb) |
73c6768b | 82 | { |
83 | int ret; | |
84 | struct iio_trigger *trig; | |
85 | ||
86 | trig = iio_trigger_alloc("%s-dev%d", name, indio_dev->id); | |
87 | if (trig == NULL) { | |
88 | dev_err(&indio_dev->dev, "Trigger Allocate Failed\n"); | |
89 | ret = -ENOMEM; | |
90 | goto error_ret; | |
91 | } | |
92 | ||
93 | trig->dev.parent = indio_dev->dev.parent; | |
1e9663c6 | 94 | iio_trigger_set_drvdata(trig, attrb); |
73c6768b | 95 | trig->ops = &hid_sensor_trigger_ops; |
96 | ret = iio_trigger_register(trig); | |
97 | ||
98 | if (ret) { | |
99 | dev_err(&indio_dev->dev, "Trigger Register Failed\n"); | |
100 | goto error_free_trig; | |
101 | } | |
ec7f68e0 | 102 | indio_dev->trig = attrb->trigger = trig; |
73c6768b | 103 | |
104 | return ret; | |
105 | ||
106 | error_free_trig: | |
107 | iio_trigger_free(trig); | |
108 | error_ret: | |
109 | return ret; | |
110 | } | |
111 | EXPORT_SYMBOL(hid_sensor_setup_trigger); | |
112 | ||
113 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>"); | |
114 | MODULE_DESCRIPTION("HID Sensor trigger processing"); | |
115 | MODULE_LICENSE("GPL"); |