diff options
Diffstat (limited to 'drivers/iio/common/hid-sensors/hid-sensor-trigger.c')
-rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 5b41f9d0d4f3..a3cce3a38300 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -122,6 +122,14 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) | |||
122 | #endif | 122 | #endif |
123 | } | 123 | } |
124 | 124 | ||
125 | static void hid_sensor_set_power_work(struct work_struct *work) | ||
126 | { | ||
127 | struct hid_sensor_common *attrb = container_of(work, | ||
128 | struct hid_sensor_common, | ||
129 | work); | ||
130 | _hid_sensor_power_state(attrb, true); | ||
131 | } | ||
132 | |||
125 | static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | 133 | static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, |
126 | bool state) | 134 | bool state) |
127 | { | 135 | { |
@@ -130,6 +138,7 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
130 | 138 | ||
131 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) | 139 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) |
132 | { | 140 | { |
141 | cancel_work_sync(&attrb->work); | ||
133 | iio_trigger_unregister(attrb->trigger); | 142 | iio_trigger_unregister(attrb->trigger); |
134 | iio_trigger_free(attrb->trigger); | 143 | iio_trigger_free(attrb->trigger); |
135 | } | 144 | } |
@@ -170,6 +179,9 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, | |||
170 | goto error_unreg_trigger; | 179 | goto error_unreg_trigger; |
171 | 180 | ||
172 | iio_device_set_drvdata(indio_dev, attrb); | 181 | iio_device_set_drvdata(indio_dev, attrb); |
182 | |||
183 | INIT_WORK(&attrb->work, hid_sensor_set_power_work); | ||
184 | |||
173 | pm_suspend_ignore_children(&attrb->pdev->dev, true); | 185 | pm_suspend_ignore_children(&attrb->pdev->dev, true); |
174 | pm_runtime_enable(&attrb->pdev->dev); | 186 | pm_runtime_enable(&attrb->pdev->dev); |
175 | /* Default to 3 seconds, but can be changed from sysfs */ | 187 | /* Default to 3 seconds, but can be changed from sysfs */ |
@@ -187,8 +199,7 @@ error_ret: | |||
187 | } | 199 | } |
188 | EXPORT_SYMBOL(hid_sensor_setup_trigger); | 200 | EXPORT_SYMBOL(hid_sensor_setup_trigger); |
189 | 201 | ||
190 | #ifdef CONFIG_PM | 202 | static int __maybe_unused hid_sensor_suspend(struct device *dev) |
191 | static int hid_sensor_suspend(struct device *dev) | ||
192 | { | 203 | { |
193 | struct platform_device *pdev = to_platform_device(dev); | 204 | struct platform_device *pdev = to_platform_device(dev); |
194 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | 205 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
@@ -197,21 +208,27 @@ static int hid_sensor_suspend(struct device *dev) | |||
197 | return _hid_sensor_power_state(attrb, false); | 208 | return _hid_sensor_power_state(attrb, false); |
198 | } | 209 | } |
199 | 210 | ||
200 | static int hid_sensor_resume(struct device *dev) | 211 | static int __maybe_unused hid_sensor_resume(struct device *dev) |
201 | { | 212 | { |
202 | struct platform_device *pdev = to_platform_device(dev); | 213 | struct platform_device *pdev = to_platform_device(dev); |
203 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | 214 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); |
204 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); | 215 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); |
216 | schedule_work(&attrb->work); | ||
217 | return 0; | ||
218 | } | ||
205 | 219 | ||
220 | static int __maybe_unused hid_sensor_runtime_resume(struct device *dev) | ||
221 | { | ||
222 | struct platform_device *pdev = to_platform_device(dev); | ||
223 | struct iio_dev *indio_dev = platform_get_drvdata(pdev); | ||
224 | struct hid_sensor_common *attrb = iio_device_get_drvdata(indio_dev); | ||
206 | return _hid_sensor_power_state(attrb, true); | 225 | return _hid_sensor_power_state(attrb, true); |
207 | } | 226 | } |
208 | 227 | ||
209 | #endif | ||
210 | |||
211 | const struct dev_pm_ops hid_sensor_pm_ops = { | 228 | const struct dev_pm_ops hid_sensor_pm_ops = { |
212 | SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) | 229 | SET_SYSTEM_SLEEP_PM_OPS(hid_sensor_suspend, hid_sensor_resume) |
213 | SET_RUNTIME_PM_OPS(hid_sensor_suspend, | 230 | SET_RUNTIME_PM_OPS(hid_sensor_suspend, |
214 | hid_sensor_resume, NULL) | 231 | hid_sensor_runtime_resume, NULL) |
215 | }; | 232 | }; |
216 | EXPORT_SYMBOL(hid_sensor_pm_ops); | 233 | EXPORT_SYMBOL(hid_sensor_pm_ops); |
217 | 234 | ||