linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4l-utils 1/2] keytable: load bpf protocol for unsupported protocols
@ 2019-05-26 21:09 Sean Young
  2019-05-26 21:09 ` [PATCH v4l-utils 2/2] keytable: add xbox-dvd protocol to match kernel Sean Young
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Young @ 2019-05-26 21:09 UTC (permalink / raw)
  To: linux-media

If there is no hardware decoder or kernel software decoder available
for a protocol, attempt to load a bpf protocol for this.

This opens the door for building the kernel without IR decoders (non
bpf ones) and just rely on bpf and hardware decoders. This requires
the bpf decoders to be written though, this still needs to be done.

Signed-off-by: Sean Young <sean@mess.org>
---
 utils/keytable/keytable.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 9384532b..daf82c0e 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -326,6 +326,10 @@ static bool compare_parameters(struct toml_table_t *a, struct toml_table_t *b)
 	int64_t avalue, bvalue;
 	const char *name, *raw;
 
+	if (a == NULL || b == NULL) {
+		return true;
+	}
+
 	while ((name = toml_key_in(a, i++)) != NULL) {
 		raw = toml_raw_in(a, name);
 		if (!raw)
@@ -1110,6 +1114,26 @@ static struct sysfs_names *find_device(char *name)
 	return names;
 }
 
+static enum sysfs_protocols create_bpf_for_unsupported(enum sysfs_protocols protocols, enum sysfs_protocols supported)
+{
+	const struct protocol_map_entry *pme;
+	struct bpf_protocol *b;
+
+	for (pme = protocol_map; pme->name; pme++) {
+		if (!(protocols & pme->sysfs_protocol) ||
+		    (supported & pme->sysfs_protocol))
+			continue;
+
+		b = malloc(sizeof(*b));
+		b->name = strdup(pme->name);
+		add_bpf_protocol(b);
+
+		protocols &= ~pme->sysfs_protocol;
+	}
+
+	return protocols;
+}
+
 static enum sysfs_protocols v1_get_hw_protocols(char *name)
 {
 	FILE *fp;
@@ -1466,13 +1490,13 @@ static int set_proto(struct rc_device *rc_dev)
 {
 	int rc = 0;
 
-	rc_dev->current &= rc_dev->supported;
-
 	if (rc_dev->version == VERSION_2) {
 		rc = v2_set_protocols(rc_dev);
 		return rc;
 	}
 
+	rc_dev->current &= rc_dev->supported;
+
 	if (rc_dev->type == SOFTWARE_DECODER) {
 		const struct protocol_map_entry *pme;
 
@@ -2215,7 +2239,8 @@ int main(int argc, char *argv[])
 		if (rc_dev.lirc_name)
 			clear_bpf(rc_dev.lirc_name);
 
-		rc_dev.current = ch_proto;
+		rc_dev.current = create_bpf_for_unsupported(ch_proto, rc_dev.supported);
+
 		if (set_proto(&rc_dev))
 			fprintf(stderr, _("Couldn't change the IR protocols\n"));
 		else {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v4l-utils 2/2] keytable: add xbox-dvd protocol to match kernel
  2019-05-26 21:09 [PATCH v4l-utils 1/2] keytable: load bpf protocol for unsupported protocols Sean Young
@ 2019-05-26 21:09 ` Sean Young
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Young @ 2019-05-26 21:09 UTC (permalink / raw)
  To: linux-media

Rename the bpf protocol to match. Now we can use the generated keymap
for the XBox DVD remote.

Signed-off-by: Sean Young <sean@mess.org>
---
 utils/common/ir-encode.c                      |  1 +
 utils/keytable/bpf_protocols/Makefile.am      |  2 +-
 .../bpf_protocols/{xbox.c => xbox-dvd.c}      |  2 +-
 utils/keytable/keytable.c                     |  4 ++-
 utils/keytable/rc_keymaps/xbox_dvd.toml       |  4 +--
 .../rc_keymaps_userspace/xbox_dvd.toml        | 31 -------------------
 6 files changed, 8 insertions(+), 36 deletions(-)
 rename utils/keytable/bpf_protocols/{xbox.c => xbox-dvd.c} (99%)
 delete mode 100644 utils/keytable/rc_keymaps_userspace/xbox_dvd.toml

diff --git a/utils/common/ir-encode.c b/utils/common/ir-encode.c
index 4bd1b694..93c88501 100644
--- a/utils/common/ir-encode.c
+++ b/utils/common/ir-encode.c
@@ -375,6 +375,7 @@ static const struct {
 	[RC_PROTO_RCMM12] = { "rc-mm-12", 0x0fff },
 	[RC_PROTO_RCMM24] = { "rc-mm-24", 0xffffff },
 	[RC_PROTO_RCMM32] = { "rc-mm-32", 0xffffffff },
+	[RC_PROTO_XBOX_DVD] = { "xbox-dvd", 0xfff },
 };
 
 static bool str_like(const char *a, const char *b)
diff --git a/utils/keytable/bpf_protocols/Makefile.am b/utils/keytable/bpf_protocols/Makefile.am
index 123b64ec..bca3bdec 100644
--- a/utils/keytable/bpf_protocols/Makefile.am
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -10,7 +10,7 @@ CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
 %.o: %.c bpf_helpers.h
 	$(CLANG) $(CLANG_SYS_INCLUDES) -D__linux__ -I$(top_srcdir)/include -target bpf -O2 -c $<
 
-PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o xbox.o imon_rsc.o
+PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o xbox-dvd.o imon_rsc.o
 
 all: $(PROTOCOLS)
 
diff --git a/utils/keytable/bpf_protocols/xbox.c b/utils/keytable/bpf_protocols/xbox-dvd.c
similarity index 99%
rename from utils/keytable/bpf_protocols/xbox.c
rename to utils/keytable/bpf_protocols/xbox-dvd.c
index e48e0a79..91b7d02e 100644
--- a/utils/keytable/bpf_protocols/xbox.c
+++ b/utils/keytable/bpf_protocols/xbox-dvd.c
@@ -51,7 +51,7 @@ static inline int eq_margin(unsigned d1, unsigned d2)
 	return ((d1 > (d2 - BPF_PARAM(margin))) && (d1 < (d2 + BPF_PARAM(margin))));
 }
 
-SEC("xbox")
+SEC("xbox-dvd")
 int bpf_decoder(unsigned int *sample)
 {
 	unsigned int key = 0;
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index daf82c0e..bf5e2c6f 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -128,6 +128,7 @@ enum sysfs_protocols {
 	SYSFS_CEC		= (1 << 13),
 	SYSFS_IMON		= (1 << 14),
 	SYSFS_RCMM		= (1 << 15),
+	SYSFS_XBOX_DVD		= (1 << 16),
 	SYSFS_INVALID		= 0,
 };
 
@@ -163,6 +164,7 @@ const struct protocol_map_entry protocol_map[] = {
 	{ "cec",	NULL,		SYSFS_CEC	},
 	{ "imon",	NULL,		SYSFS_IMON	},
 	{ "rc-mm",	NULL,		SYSFS_RCMM	},
+	{ "xbox-dvd",	NULL,		SYSFS_XBOX_DVD	},
 	{ NULL,		NULL,		SYSFS_INVALID	},
 };
 
@@ -1621,7 +1623,7 @@ static void print_scancodes(const struct lirc_scancode *scancodes, unsigned coun
 {
 	unsigned i;
 
-	for (i=0; i< count; i++) {
+	for (i = 0; i < count; i++) {
 		const char *p = protocol_name(scancodes[i].rc_proto);
 
 		printf(_("%llu.%06llu: "),
diff --git a/utils/keytable/rc_keymaps/xbox_dvd.toml b/utils/keytable/rc_keymaps/xbox_dvd.toml
index 77863542..16f7bdd5 100644
--- a/utils/keytable/rc_keymaps/xbox_dvd.toml
+++ b/utils/keytable/rc_keymaps/xbox_dvd.toml
@@ -1,6 +1,6 @@
 [[protocols]]
-name = "XBox DVD"
-protocol = "xbox"
+name = "xbox_dvd"
+protocol = "xbox_dvd"
 [protocols.scancodes]
 0xa0b = "KEY_OK"
 0xaa6 = "KEY_UP"
diff --git a/utils/keytable/rc_keymaps_userspace/xbox_dvd.toml b/utils/keytable/rc_keymaps_userspace/xbox_dvd.toml
deleted file mode 100644
index 77863542..00000000
--- a/utils/keytable/rc_keymaps_userspace/xbox_dvd.toml
+++ /dev/null
@@ -1,31 +0,0 @@
-[[protocols]]
-name = "XBox DVD"
-protocol = "xbox"
-[protocols.scancodes]
-0xa0b = "KEY_OK"
-0xaa6 = "KEY_UP"
-0xaa7 = "KEY_DOWN"
-0xaa8 = "KEY_RIGHT"
-0xaa9 = "KEY_LEFT"
-0xac3 = "KEY_INFO"
-0xac6 = "KEY_9"
-0xac7 = "KEY_8"
-0xac8 = "KEY_7"
-0xac9 = "KEY_6"
-0xaca = "KEY_5"
-0xacb = "KEY_4"
-0xacc = "KEY_3"
-0xacd = "KEY_2"
-0xace = "KEY_1"
-0xacf = "KEY_0"
-0xad5 = "KEY_ANGLE"
-0xad8 = "KEY_BACK"
-0xadd = "KEY_PREVIOUSSONG"
-0xadf = "KEY_NEXTSONG"
-0xae0 = "KEY_STOP"
-0xae2 = "KEY_REWIND"
-0xae3 = "KEY_FASTFORWARD"
-0xae5 = "KEY_TITLE"
-0xae6 = "KEY_PAUSE"
-0xaea = "KEY_PLAY"
-0xaf7 = "KEY_MENU"
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-26 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26 21:09 [PATCH v4l-utils 1/2] keytable: load bpf protocol for unsupported protocols Sean Young
2019-05-26 21:09 ` [PATCH v4l-utils 2/2] keytable: add xbox-dvd protocol to match kernel Sean Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).