srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 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> |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 25 | #include <linux/delay.h> |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 26 | #include <linux/hid-sensor-hub.h> |
| 27 | #include <linux/iio/iio.h> |
| 28 | #include <linux/iio/trigger.h> |
Srinivas Pandruvada | 138bc79 | 2017-04-07 19:22:06 -0700 | [diff] [blame] | 29 | #include <linux/iio/buffer.h> |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 30 | #include <linux/iio/sysfs.h> |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 31 | #include "hid-sensor-trigger.h" |
| 32 | |
Srinivas Pandruvada | 138bc79 | 2017-04-07 19:22:06 -0700 | [diff] [blame] | 33 | static ssize_t _hid_sensor_set_report_latency(struct device *dev, |
| 34 | struct device_attribute *attr, |
| 35 | const char *buf, size_t len) |
| 36 | { |
| 37 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 38 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
| 39 | int integer, fract, ret; |
| 40 | int latency; |
| 41 | |
| 42 | ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | |
| 46 | latency = integer * 1000 + fract / 1000; |
| 47 | ret = hid_sensor_set_report_latency(attrb, latency); |
| 48 | if (ret < 0) |
| 49 | return len; |
| 50 | |
| 51 | attrb->latency_ms = hid_sensor_get_report_latency(attrb); |
| 52 | |
| 53 | return len; |
| 54 | } |
| 55 | |
| 56 | static ssize_t _hid_sensor_get_report_latency(struct device *dev, |
| 57 | struct device_attribute *attr, |
| 58 | char *buf) |
| 59 | { |
| 60 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 61 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
| 62 | int latency; |
| 63 | |
| 64 | latency = hid_sensor_get_report_latency(attrb); |
| 65 | if (latency < 0) |
| 66 | return latency; |
| 67 | |
| 68 | return sprintf(buf, "%d.%06u\n", latency / 1000, (latency % 1000) * 1000); |
| 69 | } |
| 70 | |
| 71 | static ssize_t _hid_sensor_get_fifo_state(struct device *dev, |
| 72 | struct device_attribute *attr, |
| 73 | char *buf) |
| 74 | { |
| 75 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
| 76 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
| 77 | int latency; |
| 78 | |
| 79 | latency = hid_sensor_get_report_latency(attrb); |
| 80 | if (latency < 0) |
| 81 | return latency; |
| 82 | |
| 83 | return sprintf(buf, "%d\n", !!latency); |
| 84 | } |
| 85 | |
| 86 | static IIO_DEVICE_ATTR(hwfifo_timeout, 0644, |
| 87 | _hid_sensor_get_report_latency, |
| 88 | _hid_sensor_set_report_latency, 0); |
| 89 | static IIO_DEVICE_ATTR(hwfifo_enabled, 0444, |
| 90 | _hid_sensor_get_fifo_state, NULL, 0); |
| 91 | |
| 92 | static const struct attribute *hid_sensor_fifo_attributes[] = { |
| 93 | &iio_dev_attr_hwfifo_timeout.dev_attr.attr, |
| 94 | &iio_dev_attr_hwfifo_enabled.dev_attr.attr, |
| 95 | NULL, |
| 96 | }; |
| 97 | |
| 98 | static void hid_sensor_setup_batch_mode(struct iio_dev *indio_dev, |
| 99 | struct hid_sensor_common *st) |
| 100 | { |
| 101 | if (!hid_sensor_batch_mode_supported(st)) |
| 102 | return; |
| 103 | |
| 104 | iio_buffer_set_attrs(indio_dev->buffer, hid_sensor_fifo_attributes); |
| 105 | } |
| 106 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 107 | static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state) |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 108 | { |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 109 | int state_val; |
Srinivas Pandruvada | 751d17e | 2013-11-27 22:19:00 +0000 | [diff] [blame] | 110 | int report_val; |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 111 | s32 poll_value = 0; |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 112 | |
Srinivas Pandruvada | 7d3c192 | 2013-09-18 18:13:00 +0100 | [diff] [blame] | 113 | if (state) { |
| 114 | if (sensor_hub_device_open(st->hsdev)) |
| 115 | return -EIO; |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 116 | |
| 117 | atomic_inc(&st->data_ready); |
| 118 | |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 119 | state_val = hid_sensor_get_usage_index(st->hsdev, |
| 120 | st->power_state.report_id, |
| 121 | st->power_state.index, |
| 122 | HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM); |
| 123 | report_val = hid_sensor_get_usage_index(st->hsdev, |
| 124 | st->report_state.report_id, |
| 125 | st->report_state.index, |
| 126 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); |
Srinivas Pandruvada | 5d9854e | 2017-04-07 17:13:17 -0700 | [diff] [blame] | 127 | |
| 128 | poll_value = hid_sensor_read_poll_value(st); |
Srinivas Pandruvada | 751d17e | 2013-11-27 22:19:00 +0000 | [diff] [blame] | 129 | } else { |
Srinivas Pandruvada | 1e25aa9 | 2015-06-01 16:36:27 -0700 | [diff] [blame] | 130 | int val; |
| 131 | |
| 132 | val = atomic_dec_if_positive(&st->data_ready); |
| 133 | if (val < 0) |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 134 | return 0; |
Srinivas Pandruvada | 1e25aa9 | 2015-06-01 16:36:27 -0700 | [diff] [blame] | 135 | |
Srinivas Pandruvada | 751d17e | 2013-11-27 22:19:00 +0000 | [diff] [blame] | 136 | sensor_hub_device_close(st->hsdev); |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 137 | state_val = hid_sensor_get_usage_index(st->hsdev, |
| 138 | st->power_state.report_id, |
| 139 | st->power_state.index, |
| 140 | HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM); |
| 141 | report_val = hid_sensor_get_usage_index(st->hsdev, |
| 142 | st->report_state.report_id, |
| 143 | st->report_state.index, |
| 144 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); |
Srinivas Pandruvada | 751d17e | 2013-11-27 22:19:00 +0000 | [diff] [blame] | 145 | } |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 146 | |
| 147 | if (state_val >= 0) { |
| 148 | state_val += st->power_state.logical_minimum; |
| 149 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, |
Srinivas Pandruvada | 3950e03 | 2015-02-19 15:35:26 -0800 | [diff] [blame] | 150 | st->power_state.index, sizeof(state_val), |
| 151 | &state_val); |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 152 | } |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 153 | |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 154 | if (report_val >= 0) { |
| 155 | report_val += st->report_state.logical_minimum; |
| 156 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, |
Srinivas Pandruvada | 3950e03 | 2015-02-19 15:35:26 -0800 | [diff] [blame] | 157 | st->report_state.index, |
| 158 | sizeof(report_val), |
| 159 | &report_val); |
Srinivas Pandruvada | 1a214ae | 2014-01-23 18:50:22 -0800 | [diff] [blame] | 160 | } |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 161 | |
Srinivas Pandruvada | f1664ea | 2017-08-12 09:09:21 -0700 | [diff] [blame] | 162 | pr_debug("HID_SENSOR %s set power_state %d report_state %d\n", |
| 163 | st->pdev->name, state_val, report_val); |
| 164 | |
Archana Patni | c0a36f0 | 2014-05-19 12:19:00 +0100 | [diff] [blame] | 165 | sensor_hub_get_feature(st->hsdev, st->power_state.report_id, |
Srinivas Pandruvada | 6adc83f | 2015-02-19 15:35:25 -0800 | [diff] [blame] | 166 | st->power_state.index, |
| 167 | sizeof(state_val), &state_val); |
Srinivas Pandruvada | 5d9854e | 2017-04-07 17:13:17 -0700 | [diff] [blame] | 168 | if (state && poll_value) |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 169 | msleep_interruptible(poll_value * 2); |
| 170 | |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 171 | return 0; |
| 172 | } |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 173 | EXPORT_SYMBOL(hid_sensor_power_state); |
| 174 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 175 | int hid_sensor_power_state(struct hid_sensor_common *st, bool state) |
| 176 | { |
Srinivas Pandruvada | 1e25aa9 | 2015-06-01 16:36:27 -0700 | [diff] [blame] | 177 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 178 | #ifdef CONFIG_PM |
| 179 | int ret; |
| 180 | |
Srinivas Pandruvada | ad7532c | 2017-10-11 09:35:01 -0700 | [diff] [blame] | 181 | if (atomic_add_unless(&st->runtime_pm_enable, 1, 1)) |
| 182 | pm_runtime_enable(&st->pdev->dev); |
| 183 | |
Hans de Goede | 6f92253 | 2018-04-14 17:09:09 +0200 | [diff] [blame] | 184 | if (state) { |
| 185 | atomic_inc(&st->user_requested_state); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 186 | ret = pm_runtime_get_sync(&st->pdev->dev); |
Hans de Goede | 6f92253 | 2018-04-14 17:09:09 +0200 | [diff] [blame] | 187 | } else { |
| 188 | atomic_dec(&st->user_requested_state); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 189 | pm_runtime_mark_last_busy(&st->pdev->dev); |
Srinivas Pandruvada | f1664ea | 2017-08-12 09:09:21 -0700 | [diff] [blame] | 190 | pm_runtime_use_autosuspend(&st->pdev->dev); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 191 | ret = pm_runtime_put_autosuspend(&st->pdev->dev); |
| 192 | } |
| 193 | if (ret < 0) { |
| 194 | if (state) |
| 195 | pm_runtime_put_noidle(&st->pdev->dev); |
| 196 | return ret; |
| 197 | } |
| 198 | |
Slawomir Stepien | d23057e | 2016-04-14 21:36:40 +0200 | [diff] [blame] | 199 | return 0; |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 200 | #else |
Srinivas Pandruvada | 1e25aa9 | 2015-06-01 16:36:27 -0700 | [diff] [blame] | 201 | atomic_set(&st->user_requested_state, state); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 202 | return _hid_sensor_power_state(st, state); |
| 203 | #endif |
| 204 | } |
| 205 | |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 206 | static void hid_sensor_set_power_work(struct work_struct *work) |
| 207 | { |
| 208 | struct hid_sensor_common *attrb = container_of(work, |
| 209 | struct hid_sensor_common, |
| 210 | work); |
Srinivas Pandruvada | 5d9854e | 2017-04-07 17:13:17 -0700 | [diff] [blame] | 211 | |
| 212 | if (attrb->poll_interval >= 0) |
| 213 | sensor_hub_set_feature(attrb->hsdev, attrb->poll.report_id, |
| 214 | attrb->poll.index, |
| 215 | sizeof(attrb->poll_interval), |
| 216 | &attrb->poll_interval); |
| 217 | |
| 218 | if (attrb->raw_hystersis >= 0) |
| 219 | sensor_hub_set_feature(attrb->hsdev, |
| 220 | attrb->sensitivity.report_id, |
| 221 | attrb->sensitivity.index, |
| 222 | sizeof(attrb->raw_hystersis), |
| 223 | &attrb->raw_hystersis); |
| 224 | |
Srinivas Pandruvada | 138bc79 | 2017-04-07 19:22:06 -0700 | [diff] [blame] | 225 | if (attrb->latency_ms > 0) |
| 226 | hid_sensor_set_report_latency(attrb, attrb->latency_ms); |
| 227 | |
Srinivas Pandruvada | ad7532c | 2017-10-11 09:35:01 -0700 | [diff] [blame] | 228 | if (atomic_read(&attrb->user_requested_state)) |
| 229 | _hid_sensor_power_state(attrb, true); |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Srinivas Pandruvada | 56ff6be | 2014-04-19 00:22:00 +0100 | [diff] [blame] | 232 | static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, |
| 233 | bool state) |
| 234 | { |
| 235 | return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state); |
| 236 | } |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 237 | |
Srinivas Pandruvada | ec7f68e | 2013-10-30 22:48:00 +0000 | [diff] [blame] | 238 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 239 | { |
Srinivas Pandruvada | ad7532c | 2017-10-11 09:35:01 -0700 | [diff] [blame] | 240 | if (atomic_read(&attrb->runtime_pm_enable)) |
| 241 | pm_runtime_disable(&attrb->pdev->dev); |
| 242 | |
Srinivas Pandruvada | c94f580 | 2017-04-07 17:16:34 -0700 | [diff] [blame] | 243 | pm_runtime_set_suspended(&attrb->pdev->dev); |
| 244 | pm_runtime_put_noidle(&attrb->pdev->dev); |
| 245 | |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 246 | cancel_work_sync(&attrb->work); |
Srinivas Pandruvada | ec7f68e | 2013-10-30 22:48:00 +0000 | [diff] [blame] | 247 | iio_trigger_unregister(attrb->trigger); |
| 248 | iio_trigger_free(attrb->trigger); |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 249 | } |
| 250 | EXPORT_SYMBOL(hid_sensor_remove_trigger); |
| 251 | |
| 252 | static const struct iio_trigger_ops hid_sensor_trigger_ops = { |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 253 | .set_trigger_state = &hid_sensor_data_rdy_trigger_set_state, |
| 254 | }; |
| 255 | |
| 256 | int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, |
Alexander Holler | e07c6d1 | 2012-12-15 12:45:00 +0000 | [diff] [blame] | 257 | struct hid_sensor_common *attrb) |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 258 | { |
| 259 | int ret; |
| 260 | struct iio_trigger *trig; |
| 261 | |
| 262 | trig = iio_trigger_alloc("%s-dev%d", name, indio_dev->id); |
| 263 | if (trig == NULL) { |
| 264 | dev_err(&indio_dev->dev, "Trigger Allocate Failed\n"); |
| 265 | ret = -ENOMEM; |
| 266 | goto error_ret; |
| 267 | } |
| 268 | |
| 269 | trig->dev.parent = indio_dev->dev.parent; |
Lars-Peter Clausen | 1e9663c | 2013-03-25 08:58:00 +0000 | [diff] [blame] | 270 | iio_trigger_set_drvdata(trig, attrb); |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 271 | trig->ops = &hid_sensor_trigger_ops; |
| 272 | ret = iio_trigger_register(trig); |
| 273 | |
| 274 | if (ret) { |
| 275 | dev_err(&indio_dev->dev, "Trigger Register Failed\n"); |
| 276 | goto error_free_trig; |
| 277 | } |
Srinivas Pandruvada | 55a6f9d | 2014-08-22 21:48:00 +0100 | [diff] [blame] | 278 | attrb->trigger = trig; |
| 279 | indio_dev->trig = iio_trigger_get(trig); |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 280 | |
Srinivas Pandruvada | 138bc79 | 2017-04-07 19:22:06 -0700 | [diff] [blame] | 281 | hid_sensor_setup_batch_mode(indio_dev, attrb); |
| 282 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 283 | ret = pm_runtime_set_active(&indio_dev->dev); |
| 284 | if (ret) |
| 285 | goto error_unreg_trigger; |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 286 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 287 | iio_device_set_drvdata(indio_dev, attrb); |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 288 | |
| 289 | INIT_WORK(&attrb->work, hid_sensor_set_power_work); |
| 290 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 291 | pm_suspend_ignore_children(&attrb->pdev->dev, true); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 292 | /* Default to 3 seconds, but can be changed from sysfs */ |
| 293 | pm_runtime_set_autosuspend_delay(&attrb->pdev->dev, |
| 294 | 3000); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 295 | return ret; |
| 296 | error_unreg_trigger: |
| 297 | iio_trigger_unregister(trig); |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 298 | error_free_trig: |
| 299 | iio_trigger_free(trig); |
| 300 | error_ret: |
| 301 | return ret; |
| 302 | } |
| 303 | EXPORT_SYMBOL(hid_sensor_setup_trigger); |
| 304 | |
Arnd Bergmann | 2e1f44d | 2016-08-26 17:29:35 +0200 | [diff] [blame] | 305 | static int __maybe_unused hid_sensor_suspend(struct device *dev) |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 306 | { |
Wolfram Sang | ebbdcba | 2018-04-19 16:05:49 +0200 | [diff] [blame] | 307 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 308 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
| 309 | |
| 310 | return _hid_sensor_power_state(attrb, false); |
| 311 | } |
| 312 | |
Arnd Bergmann | 2e1f44d | 2016-08-26 17:29:35 +0200 | [diff] [blame] | 313 | static int __maybe_unused hid_sensor_resume(struct device *dev) |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 314 | { |
Wolfram Sang | ebbdcba | 2018-04-19 16:05:49 +0200 | [diff] [blame] | 315 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 316 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 317 | schedule_work(&attrb->work); |
| 318 | return 0; |
| 319 | } |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 320 | |
Arnd Bergmann | 2e1f44d | 2016-08-26 17:29:35 +0200 | [diff] [blame] | 321 | static int __maybe_unused hid_sensor_runtime_resume(struct device *dev) |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 322 | { |
Wolfram Sang | ebbdcba | 2018-04-19 16:05:49 +0200 | [diff] [blame] | 323 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 324 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 325 | return _hid_sensor_power_state(attrb, true); |
| 326 | } |
| 327 | |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 328 | const struct dev_pm_ops hid_sensor_pm_ops = { |
| 329 | SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) |
| 330 | SET_RUNTIME_PM_OPS(hid_sensor_suspend, |
Srinivas Pandruvada | 7f6cf74 | 2016-08-15 12:12:47 -0700 | [diff] [blame] | 331 | hid_sensor_runtime_resume, NULL) |
Srinivas Pandruvada | 2b89635 | 2015-01-07 10:55:53 -0800 | [diff] [blame] | 332 | }; |
| 333 | EXPORT_SYMBOL(hid_sensor_pm_ops); |
| 334 | |
srinivas pandruvada | 73c6768 | 2012-09-05 13:56:00 +0100 | [diff] [blame] | 335 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>"); |
| 336 | MODULE_DESCRIPTION("HID Sensor trigger processing"); |
| 337 | MODULE_LICENSE("GPL"); |