aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/common/hid-sensors/hid-sensor-trigger.c')
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-trigger.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 55dfd6288d18..cfb6588565ba 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -179,6 +179,10 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
179 int ret; 179 int ret;
180 180
181 atomic_set(&st->user_requested_state, state); 181 atomic_set(&st->user_requested_state, state);
182
183 if (atomic_add_unless(&st->runtime_pm_enable, 1, 1))
184 pm_runtime_enable(&st->pdev->dev);
185
182 if (state) 186 if (state)
183 ret = pm_runtime_get_sync(&st->pdev->dev); 187 ret = pm_runtime_get_sync(&st->pdev->dev);
184 else { 188 else {
@@ -221,7 +225,8 @@ static void hid_sensor_set_power_work(struct work_struct *work)
221 if (attrb->latency_ms > 0) 225 if (attrb->latency_ms > 0)
222 hid_sensor_set_report_latency(attrb, attrb->latency_ms); 226 hid_sensor_set_report_latency(attrb, attrb->latency_ms);
223 227
224 _hid_sensor_power_state(attrb, true); 228 if (atomic_read(&attrb->user_requested_state))
229 _hid_sensor_power_state(attrb, true);
225} 230}
226 231
227static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, 232static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
@@ -232,7 +237,9 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
232 237
233void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) 238void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
234{ 239{
235 pm_runtime_disable(&attrb->pdev->dev); 240 if (atomic_read(&attrb->runtime_pm_enable))
241 pm_runtime_disable(&attrb->pdev->dev);
242
236 pm_runtime_set_suspended(&attrb->pdev->dev); 243 pm_runtime_set_suspended(&attrb->pdev->dev);
237 pm_runtime_put_noidle(&attrb->pdev->dev); 244 pm_runtime_put_noidle(&attrb->pdev->dev);
238 245
@@ -282,7 +289,6 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
282 INIT_WORK(&attrb->work, hid_sensor_set_power_work); 289 INIT_WORK(&attrb->work, hid_sensor_set_power_work);
283 290
284 pm_suspend_ignore_children(&attrb->pdev->dev, true); 291 pm_suspend_ignore_children(&attrb->pdev->dev, true);
285 pm_runtime_enable(&attrb->pdev->dev);
286 /* Default to 3 seconds, but can be changed from sysfs */ 292 /* Default to 3 seconds, but can be changed from sysfs */
287 pm_runtime_set_autosuspend_delay(&attrb->pdev->dev, 293 pm_runtime_set_autosuspend_delay(&attrb->pdev->dev,
288 3000); 294 3000);