hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/media/rc/gpio-ir-recv.c
....@@ -1,13 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2
- *
3
- * This program is free software; you can redistribute it and/or modify
4
- * it under the terms of the GNU General Public License version 2 and
5
- * only version 2 as published by the Free Software Foundation.
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
113 */
124
135 #include <linux/kernel.h>
....@@ -19,6 +11,8 @@
1911 #include <linux/of.h>
2012 #include <linux/of_gpio.h>
2113 #include <linux/platform_device.h>
14
+#include <linux/pm_runtime.h>
15
+#include <linux/pm_qos.h>
2216 #include <linux/irq.h>
2317 #include <media/rc-core.h>
2418
....@@ -28,16 +22,37 @@
2822 struct rc_dev *rcdev;
2923 struct gpio_desc *gpiod;
3024 int irq;
25
+ struct device *pmdev;
26
+ struct pm_qos_request qos;
3127 };
3228
3329 static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id)
3430 {
3531 int val;
3632 struct gpio_rc_dev *gpio_dev = dev_id;
33
+ struct device *pmdev = gpio_dev->pmdev;
34
+
35
+ /*
36
+ * For some cpuidle systems, not all:
37
+ * Respond to interrupt taking more latency when cpu in idle.
38
+ * Invoke asynchronous pm runtime get from interrupt context,
39
+ * this may introduce a millisecond delay to call resume callback,
40
+ * where to disable cpuilde.
41
+ *
42
+ * Two issues lead to fail to decode first frame, one is latency to
43
+ * respond to interrupt, another is delay introduced by async api.
44
+ */
45
+ if (pmdev)
46
+ pm_runtime_get(pmdev);
3747
3848 val = gpiod_get_value(gpio_dev->gpiod);
3949 if (val >= 0)
4050 ir_raw_event_store_edge(gpio_dev->rcdev, val == 1);
51
+
52
+ if (pmdev) {
53
+ pm_runtime_mark_last_busy(pmdev);
54
+ pm_runtime_put_autosuspend(pmdev);
55
+ }
4156
4257 return IRQ_HANDLED;
4358 }
....@@ -48,6 +63,7 @@
4863 struct device_node *np = dev->of_node;
4964 struct gpio_rc_dev *gpio_dev;
5065 struct rc_dev *rcdev;
66
+ u32 period = 0;
5167 int rc;
5268
5369 if (!np)
....@@ -91,6 +107,8 @@
91107 rcdev->map_name = RC_MAP_EMPTY;
92108
93109 gpio_dev->rcdev = rcdev;
110
+ if (of_property_read_bool(np, "wakeup-source"))
111
+ device_init_wakeup(dev, true);
94112
95113 rc = devm_rc_register_device(dev, rcdev);
96114 if (rc < 0) {
....@@ -98,11 +116,37 @@
98116 return rc;
99117 }
100118
119
+ of_property_read_u32(np, "linux,autosuspend-period", &period);
120
+ if (period) {
121
+ gpio_dev->pmdev = dev;
122
+ pm_runtime_set_autosuspend_delay(dev, period);
123
+ pm_runtime_use_autosuspend(dev);
124
+ pm_runtime_set_suspended(dev);
125
+ pm_runtime_enable(dev);
126
+ }
127
+
101128 platform_set_drvdata(pdev, gpio_dev);
102129
103130 return devm_request_irq(dev, gpio_dev->irq, gpio_ir_recv_irq,
104131 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
105132 "gpio-ir-recv-irq", gpio_dev);
133
+}
134
+
135
+static int gpio_ir_recv_remove(struct platform_device *pdev)
136
+{
137
+ struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
138
+ struct device *pmdev = gpio_dev->pmdev;
139
+
140
+ if (pmdev) {
141
+ pm_runtime_get_sync(pmdev);
142
+ cpu_latency_qos_remove_request(&gpio_dev->qos);
143
+
144
+ pm_runtime_disable(pmdev);
145
+ pm_runtime_put_noidle(pmdev);
146
+ pm_runtime_set_suspended(pmdev);
147
+ }
148
+
149
+ return 0;
106150 }
107151
108152 #ifdef CONFIG_PM
....@@ -130,9 +174,29 @@
130174 return 0;
131175 }
132176
177
+static int gpio_ir_recv_runtime_suspend(struct device *dev)
178
+{
179
+ struct gpio_rc_dev *gpio_dev = dev_get_drvdata(dev);
180
+
181
+ cpu_latency_qos_remove_request(&gpio_dev->qos);
182
+
183
+ return 0;
184
+}
185
+
186
+static int gpio_ir_recv_runtime_resume(struct device *dev)
187
+{
188
+ struct gpio_rc_dev *gpio_dev = dev_get_drvdata(dev);
189
+
190
+ cpu_latency_qos_add_request(&gpio_dev->qos, 0);
191
+
192
+ return 0;
193
+}
194
+
133195 static const struct dev_pm_ops gpio_ir_recv_pm_ops = {
134196 .suspend = gpio_ir_recv_suspend,
135197 .resume = gpio_ir_recv_resume,
198
+ .runtime_suspend = gpio_ir_recv_runtime_suspend,
199
+ .runtime_resume = gpio_ir_recv_runtime_resume,
136200 };
137201 #endif
138202
....@@ -144,6 +208,7 @@
144208
145209 static struct platform_driver gpio_ir_recv_driver = {
146210 .probe = gpio_ir_recv_probe,
211
+ .remove = gpio_ir_recv_remove,
147212 .driver = {
148213 .name = KBUILD_MODNAME,
149214 .of_match_table = of_match_ptr(gpio_ir_recv_of_match),