Commit 16407a6a authored by Sean Young's avatar Sean Young Committed by Mauro Carvalho Chehab

media: lirc: document BPF IR decoding

This is just a start.
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 14e3cdbb
...@@ -20,6 +20,9 @@ data between userspace and kernelspace. Fundamentally, it is just a chardev ...@@ -20,6 +20,9 @@ data between userspace and kernelspace. Fundamentally, it is just a chardev
file_operations defined on it. With respect to transporting raw IR and file_operations defined on it. With respect to transporting raw IR and
decoded scancodes to and fro, the essential fops are read, write and ioctl. decoded scancodes to and fro, the essential fops are read, write and ioctl.
It is also possible to attach a BPF program to a LIRC device for decoding
raw IR into scancodes.
Example dmesg output upon a driver registering w/LIRC: Example dmesg output upon a driver registering w/LIRC:
.. code-block:: none .. code-block:: none
...@@ -34,6 +37,16 @@ What you should see for a chardev: ...@@ -34,6 +37,16 @@ What you should see for a chardev:
$ ls -l /dev/lirc* $ ls -l /dev/lirc*
crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0 crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0
Note that the package `v4l-utils <https://git.linuxtv.org/v4l-utils.git/>`_
contains tools for working with LIRC devices:
- ir-ctl: can receive raw IR and transmit IR, as well as query LIRC
device features.
- ir-keytable: can load keymaps; allows you to set IR kernel protocols; load
BPF IR decoders and test IR decoding. Some BPF IR decoders are also
provided.
.. _lirc_modes: .. _lirc_modes:
********** **********
...@@ -129,12 +142,28 @@ on the following table. ...@@ -129,12 +142,28 @@ on the following table.
This mode is used only for IR send. This mode is used only for IR send.
********************
************************** BPF based IR decoder
Remote Controller protocol ********************
**************************
The kernel has support for decoding the most common IR protocols, but there
An enum :c:type:`rc_proto` in the :ref:`lirc_header` lists all the are many protocols which are not supported. To support these, it is possible
supported IR protocols: to load an BPF program which does the decoding. This can only be done on
LIRC devices which support reading raw IR.
.. kernel-doc:: include/uapi/linux/lirc.h
First, using the `bpf(2)`_ syscall with the ``BPF_LOAD_PROG`` argument,
program must be loaded of type ``BPF_PROG_TYPE_LIRC_MODE2``. Once attached
to the LIRC device, this program will be called for each pulse, space or
timeout event on the LIRC device. The context for the BPF program is a
pointer to a unsigned int, which is a :ref:`LIRC_MODE_MODE2 <lirc-mode-mode2>`
value. When the program has decoded the scancode, it can be submitted using
the BPF functions ``bpf_rc_keydown()`` or ``bpf_rc_repeat()``. Mouse or pointer
movements can be reported using ``bpf_rc_pointer_rel()``.
Once you have the file descriptor for the ``BPF_PROG_TYPE_LIRC_MODE2`` BPF
program, it can be attached to the LIRC device using the `bpf(2)`_ syscall.
The target must be the file descriptor for the LIRC device, and the
attach type must be ``BPF_LIRC_MODE2``. No more than 64 BPF programs can be
attached to a single LIRC device at a time.
.. _bpf(2): http://man7.org/linux/man-pages/man2/bpf.2.html
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment