Skip to content

Commit 2e4ebde

Browse files
amalonmchehab
authored andcommitted
[media] rc: rc-loopback: Add loopback of filter scancodes
Add the s_wakeup_filter callback to the rc-loopback driver, which instead of setting the filter just feeds the scancode back through the input device so that it can be verified. Signed-off-by: James Hogan <james@albanarts.com> Signed-off-by: Antti Seppälä <a.seppala@gmail.com> Cc: David Härdeman <david@hardeman.nu> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1 parent 0d830b2 commit 2e4ebde

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/media/rc/rc-loopback.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/device.h>
2727
#include <linux/module.h>
2828
#include <linux/sched.h>
29+
#include <linux/slab.h>
2930
#include <media/rc-core.h>
3031

3132
#define DRIVER_NAME "rc-loopback"
@@ -176,6 +177,39 @@ static int loop_set_carrier_report(struct rc_dev *dev, int enable)
176177
return 0;
177178
}
178179

180+
static int loop_set_wakeup_filter(struct rc_dev *dev,
181+
struct rc_scancode_filter *sc_filter)
182+
{
183+
static const unsigned int max = 512;
184+
struct ir_raw_event *raw;
185+
int ret;
186+
int i;
187+
188+
/* fine to disable filter */
189+
if (!sc_filter->mask)
190+
return 0;
191+
192+
/* encode the specified filter and loop it back */
193+
raw = kmalloc_array(max, sizeof(*raw), GFP_KERNEL);
194+
ret = ir_raw_encode_scancode(dev->enabled_wakeup_protocols, sc_filter,
195+
raw, max);
196+
/* still loop back the partial raw IR even if it's incomplete */
197+
if (ret == -ENOBUFS)
198+
ret = max;
199+
if (ret >= 0) {
200+
/* do the loopback */
201+
for (i = 0; i < ret; ++i)
202+
ir_raw_event_store(dev, &raw[i]);
203+
ir_raw_event_handle(dev);
204+
205+
ret = 0;
206+
}
207+
208+
kfree(raw);
209+
210+
return ret;
211+
}
212+
179213
static int __init loop_init(void)
180214
{
181215
struct rc_dev *rc;
@@ -195,6 +229,7 @@ static int __init loop_init(void)
195229
rc->map_name = RC_MAP_EMPTY;
196230
rc->priv = &loopdev;
197231
rc->driver_type = RC_DRIVER_IR_RAW;
232+
rc->encode_wakeup = true;
198233
rc->allowed_protocols = RC_BIT_ALL;
199234
rc->timeout = 100 * 1000 * 1000; /* 100 ms */
200235
rc->min_timeout = 1;
@@ -209,6 +244,7 @@ static int __init loop_init(void)
209244
rc->s_idle = loop_set_idle;
210245
rc->s_learning_mode = loop_set_learning_mode;
211246
rc->s_carrier_report = loop_set_carrier_report;
247+
rc->s_wakeup_filter = loop_set_wakeup_filter;
212248

213249
loopdev.txmask = RXMASK_REGULAR;
214250
loopdev.txcarrier = 36000;

0 commit comments

Comments
 (0)