Re: [PATCHv3 1/1] Add ir-rcmm-driver

2018-12-07 Thread Sean Young
Hi Patrick,

On Fri, Dec 07, 2018 at 10:57:21AM +0100, Patrick LERDA wrote:
> Add support for RCMM infrared remote controls.
> 
> Signed-off-by: Patrick Lerda 

Other than the Signed-off-by this looks exactly like the v2 version;
did you see my other comments on the v2 patch?

Thanks

Sean

> ---
>  drivers/media/rc/Kconfig   |  10 ++
>  drivers/media/rc/Makefile  |   1 +
>  drivers/media/rc/ir-rcmm-decoder.c | 185 +
>  drivers/media/rc/rc-core-priv.h|   5 +
>  drivers/media/rc/rc-main.c |   3 +
>  include/media/rc-map.h |   6 +-
>  include/uapi/linux/lirc.h  |   1 +
>  tools/include/uapi/linux/lirc.h|   1 +
>  8 files changed, 210 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/media/rc/ir-rcmm-decoder.c
> 
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 1021c08a9ba4..b7e08324b874 100644
> --- a/drivers/media/rc/Kconfig
> +++ b/drivers/media/rc/Kconfig
> @@ -133,6 +133,16 @@ config IR_IMON_DECODER
>  remote control and you would like to use it with a raw IR
>  receiver, or if you wish to use an encoder to transmit this IR.
>  
> +config IR_RCMM_DECODER
> + tristate "Enable IR raw decoder for the RC-MM protocol"
> + depends on RC_CORE
> + select BITREVERSE
> + default y
> +
> + ---help---
> +Enable this option if you have IR with RC-MM protocol, and
> +if the IR is decoded in software
> +
>  endif #RC_DECODERS
>  
>  menuconfig RC_DEVICES
> diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> index e0340d043fe8..fc4058013234 100644
> --- a/drivers/media/rc/Makefile
> +++ b/drivers/media/rc/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
>  obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
>  obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
>  obj-$(CONFIG_IR_IMON_DECODER) += ir-imon-decoder.o
> +obj-$(CONFIG_IR_RCMM_DECODER) += ir-rcmm-decoder.o
>  
>  # stand-alone IR receivers/transmitters
>  obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
> diff --git a/drivers/media/rc/ir-rcmm-decoder.c 
> b/drivers/media/rc/ir-rcmm-decoder.c
> new file mode 100644
> index ..94d5b70f7a0f
> --- /dev/null
> +++ b/drivers/media/rc/ir-rcmm-decoder.c
> @@ -0,0 +1,185 @@
> +/* ir-rcmm-decoder.c - A decoder for the RCMM IR protocol
> + *
> + * Copyright (C) 2016 by Patrick Lerda
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation version 2 of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include "rc-core-priv.h"
> +#include 
> +#include 
> +
> +
> +#define RCMM_UNIT17  /* nanosecs */
> +#define RCMM_0_NBITS 64
> +#define RCMM_PREFIX_PULSE41  /* 16.6*2.5 */
> +#define RCMM_PULSE_027  /* 16.6*(1+2/3) */
> +#define RCMM_PULSE_144  /* 16.6*(2+2/3) */
> +#define RCMM_PULSE_261  /* 16.6*(3+2/3) */
> +#define RCMM_PULSE_378  /* 16.6*(4+2/3) */
> +#define RCMM_MODE_MASK  0x
> +
> +enum rcmm_state {
> + STATE_INACTIVE,
> + STATE_LOW,
> + STATE_BUMP,
> + STATE_VALUE,
> + STATE_FINISHED,
> +};
> +
> +static bool rcmm_mode(struct rcmm_dec *data)
> +{
> +return !((0x000c & data->bits) == 0x000c);
> +}
> +
> +/**
> + * ir_rcmm_decode() - Decode one RCMM pulse or space
> + * @dev: the struct rc_dev descriptor of the device
> + * @ev:  the struct ir_raw_event descriptor of the pulse/space
> + *
> + * This function returns -EINVAL if the pulse violates the state machine
> + */
> +static int ir_rcmm_decode(struct rc_dev *dev, struct ir_raw_event ev)
> +{
> + struct rcmm_dec *data = >raw->rcmm;
> + u32 scancode;
> + u8 toggle;
> +
> + if (!(dev->enabled_protocols & RC_PROTO_BIT_RCMM))
> + return 0;
> +
> + if (!is_timing_event(ev)) {
> + if (ev.reset)
> + data->state = STATE_INACTIVE;
> + return 0;
> + }
> +
> + if (ev.duration > RCMM_PULSE_3 + RCMM_UNIT)
> + goto out;
> +
> + switch (data->state) {
> +
> + case STATE_INACTIVE:
> + if (!ev.pulse)
> + break;
> +
> + /* Note: larger margin on first pulse since each RCMM_UNIT
> +is quite short and some hardware takes some time to
> +adjust to the signal */
> + if (!eq_margin(ev.duration, RCMM_PREFIX_PULSE, RCMM_UNIT/2))
> + break;
> +
> + data->state = 

[GIT PULL FOR v4.21] Two DVB patches

2018-12-06 Thread Sean Young
Hi Mauro,

Two small dvb fixes which would be nice to have in 4.21.

Thanks,
Sean

The following changes since commit 3c28b91380dd1183347d32d87d820818031ebecf:

  media: stkwebcam: Bugfix for wrong return values (2018-12-05 14:10:48 -0500)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.21d

for you to fetch changes up to 92ca069d61c96701c8660c114bbf8b772b4a33db:

  media: lmedm04: Move interrupt buffer to priv buffer. (2018-12-06 20:15:14 
+)


Malcolm Priestley (2):
  media: lmedm04: Add missing usb_free_urb to free interrupt urb.
  media: lmedm04: Move interrupt buffer to priv buffer.

 drivers/media/usb/dvb-usb-v2/lmedm04.c | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)


Re: [PATCH] [PATCHv2] Add ir-rcmm-driver

2018-12-06 Thread Sean Young
On Wed, Dec 05, 2018 at 01:29:33AM +0100, patrick9...@free.fr wrote:
> From: Patrick LERDA 
> 

We need a Signed-off-by: here.

https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

> ---
>  drivers/media/rc/Kconfig   |  10 ++
>  drivers/media/rc/Makefile  |   1 +
>  drivers/media/rc/ir-rcmm-decoder.c | 185 +
>  drivers/media/rc/rc-core-priv.h|   5 +
>  drivers/media/rc/rc-main.c |   3 +
>  include/media/rc-map.h |   6 +-
>  include/uapi/linux/lirc.h  |   1 +
>  tools/include/uapi/linux/lirc.h|   1 +
>  8 files changed, 210 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/media/rc/ir-rcmm-decoder.c
> 
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 1021c08a9ba4..b7e08324b874 100644
> --- a/drivers/media/rc/Kconfig
> +++ b/drivers/media/rc/Kconfig
> @@ -133,6 +133,16 @@ config IR_IMON_DECODER
>  remote control and you would like to use it with a raw IR
>  receiver, or if you wish to use an encoder to transmit this IR.
>  
> +config IR_RCMM_DECODER
> + tristate "Enable IR raw decoder for the RC-MM protocol"
> + depends on RC_CORE
> + select BITREVERSE

You're not using bitreverse, so don't depend on it.

> + default y
> +
> + ---help---
> +Enable this option if you have IR with RC-MM protocol, and
> +if the IR is decoded in software
> +
>  endif #RC_DECODERS
>  
>  menuconfig RC_DEVICES
> diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> index e0340d043fe8..fc4058013234 100644
> --- a/drivers/media/rc/Makefile
> +++ b/drivers/media/rc/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
>  obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
>  obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
>  obj-$(CONFIG_IR_IMON_DECODER) += ir-imon-decoder.o
> +obj-$(CONFIG_IR_RCMM_DECODER) += ir-rcmm-decoder.o
>  
>  # stand-alone IR receivers/transmitters
>  obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
> diff --git a/drivers/media/rc/ir-rcmm-decoder.c 
> b/drivers/media/rc/ir-rcmm-decoder.c
> new file mode 100644
> index ..94d5b70f7a0f
> --- /dev/null
> +++ b/drivers/media/rc/ir-rcmm-decoder.c
> @@ -0,0 +1,185 @@
> +/* ir-rcmm-decoder.c - A decoder for the RCMM IR protocol
> + *
> + * Copyright (C) 2016 by Patrick Lerda
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation version 2 of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.

Replace this with the SPDX-License-Identifier.

> + */
> +
> +#include "rc-core-priv.h"
> +#include 
> +#include 
> +
> +
> +#define RCMM_UNIT17  /* nanosecs */
> +#define RCMM_0_NBITS 64

Not used.

> +#define RCMM_PREFIX_PULSE41  /* 16.6*2.5 */
> +#define RCMM_PULSE_027  /* 16.6*(1+2/3) */
> +#define RCMM_PULSE_144  /* 16.6*(2+2/3) */
> +#define RCMM_PULSE_261  /* 16.6*(3+2/3) */
> +#define RCMM_PULSE_378  /* 16.6*(4+2/3) */
> +#define RCMM_MODE_MASK  0x

Not used.
> +
> +enum rcmm_state {
> + STATE_INACTIVE,
> + STATE_LOW,
> + STATE_BUMP,
> + STATE_VALUE,
> + STATE_FINISHED,
> +};
> +
> +static bool rcmm_mode(struct rcmm_dec *data)
> +{
> +return !((0x000c & data->bits) == 0x000c);
> +}
> +
> +/**
> + * ir_rcmm_decode() - Decode one RCMM pulse or space
> + * @dev: the struct rc_dev descriptor of the device
> + * @ev:  the struct ir_raw_event descriptor of the pulse/space
> + *
> + * This function returns -EINVAL if the pulse violates the state machine
> + */
> +static int ir_rcmm_decode(struct rc_dev *dev, struct ir_raw_event ev)
> +{
> + struct rcmm_dec *data = >raw->rcmm;
> + u32 scancode;
> + u8 toggle;
> +
> + if (!(dev->enabled_protocols & RC_PROTO_BIT_RCMM))
> + return 0;
> +
> + if (!is_timing_event(ev)) {
> + if (ev.reset)
> + data->state = STATE_INACTIVE;
> + return 0;
> + }
> +
> + if (ev.duration > RCMM_PULSE_3 + RCMM_UNIT)
> + goto out;
> +
> + switch (data->state) {
> +
> + case STATE_INACTIVE:
> + if (!ev.pulse)
> + break;
> +
> + /* Note: larger margin on first pulse since each RCMM_UNIT
> +is quite short and some hardware takes some time to
> +adjust to the signal */

Use:
 /*
  * Note:
  */
Type multiline comments 

Re: [PATCH] Add ir-rcmm-driver

2018-12-04 Thread Sean Young
On Tue, Dec 04, 2018 at 09:20:25PM +0100, patrick9...@free.fr wrote:
> From: Patrick LERDA 
> 
> ---
>  drivers/media/rc/Kconfig   |  10 ++
>  drivers/media/rc/Makefile  |   1 +
>  drivers/media/rc/ir-rcmm-decoder.c | 185 +
>  drivers/media/rc/rc-core-priv.h|   5 +
>  drivers/media/rc/rc-main.c |   3 +
>  include/media/rc-map.h |   6 +-
>  include/uapi/linux/lirc.h  |   1 +
>  tools/include/uapi/linux/lirc.h|   1 +
>  8 files changed, 210 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/media/rc/ir-rcmm-decoder.c

We have a rc-mm decoder written in BPF, see:

https://git.linuxtv.org/v4l-utils.git/tree/utils/keytable/bpf_protocols/rc_mm.c

This is in v4l-utils 1.16 and higher.

Any reason to have it in the kernel rather than in BPF?


Sean


> 
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 1021c08a9ba4..b7e08324b874 100644
> --- a/drivers/media/rc/Kconfig
> +++ b/drivers/media/rc/Kconfig
> @@ -133,6 +133,16 @@ config IR_IMON_DECODER
>  remote control and you would like to use it with a raw IR
>  receiver, or if you wish to use an encoder to transmit this IR.
>  
> +config IR_RCMM_DECODER
> + tristate "Enable IR raw decoder for the RC-MM protocol"
> + depends on RC_CORE
> + select BITREVERSE
> + default y
> +
> + ---help---
> +Enable this option if you have IR with RC-MM protocol, and
> +if the IR is decoded in software
> +
>  endif #RC_DECODERS
>  
>  menuconfig RC_DEVICES
> diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> index e0340d043fe8..fc4058013234 100644
> --- a/drivers/media/rc/Makefile
> +++ b/drivers/media/rc/Makefile
> @@ -16,6 +16,7 @@ obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
>  obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
>  obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
>  obj-$(CONFIG_IR_IMON_DECODER) += ir-imon-decoder.o
> +obj-$(CONFIG_IR_RCMM_DECODER) += ir-rcmm-decoder.o
>  
>  # stand-alone IR receivers/transmitters
>  obj-$(CONFIG_RC_ATI_REMOTE) += ati_remote.o
> diff --git a/drivers/media/rc/ir-rcmm-decoder.c 
> b/drivers/media/rc/ir-rcmm-decoder.c
> new file mode 100644
> index ..b05063f0a552
> --- /dev/null
> +++ b/drivers/media/rc/ir-rcmm-decoder.c
> @@ -0,0 +1,185 @@
> +/* ir-rcmm-decoder.c - A decoder for the RCMM IR protocol
> + *
> + * Copyright (C) 2016 by Patrick Lerda
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation version 2 of the License.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include "rc-core-priv.h"
> +#include 
> +#include 
> +
> +
> +#define RCMM_UNIT17  /* nanosecs */
> +#define RCMM_0_NBITS 64
> +#define RCMM_PREFIX_PULSE41  /* 16.6*2.5 */
> +#define RCMM_PULSE_027  /* 16.6*(1+2/3) */
> +#define RCMM_PULSE_144  /* 16.6*(2+2/3) */
> +#define RCMM_PULSE_261  /* 16.6*(3+2/3) */
> +#define RCMM_PULSE_378  /* 16.6*(4+2/3) */
> +#define RCMM_MODE_MASK  0x
> +
> +enum rcmm_state {
> + STATE_INACTIVE,
> + STATE_LOW,
> + STATE_BUMP,
> + STATE_VALUE,
> + STATE_FINISHED,
> +};
> +
> +static bool rcmm_mode(struct rcmm_dec *data)
> +{
> +return !((0x000c & data->bits) == 0x000c);
> +}
> +
> +/**
> + * ir_rcmm_decode() - Decode one RCMM pulse or space
> + * @dev: the struct rc_dev descriptor of the device
> + * @ev:  the struct ir_raw_event descriptor of the pulse/space
> + *
> + * This function returns -EINVAL if the pulse violates the state machine
> + */
> +static int ir_rcmm_decode(struct rc_dev *dev, struct ir_raw_event ev)
> +{
> + struct rcmm_dec *data = >raw->rcmm;
> + u32 scancode;
> + u8 toggle;
> +
> + if (!(dev->enabled_protocols & RC_PROTO_RCMM))
> + return 0;
> +
> + if (!is_timing_event(ev)) {
> + if (ev.reset)
> + data->state = STATE_INACTIVE;
> + return 0;
> + }
> +
> + if (ev.duration > RCMM_PULSE_3 + RCMM_UNIT)
> + goto out;
> +
> + switch (data->state) {
> +
> + case STATE_INACTIVE:
> + if (!ev.pulse)
> + break;
> +
> + /* Note: larger margin on first pulse since each RCMM_UNIT
> +is quite short and some hardware takes some time to
> +adjust to the signal */
> + if (!eq_margin(ev.duration, RCMM_PREFIX_PULSE, RCMM_UNIT/2))
> + break;
> 

[GIT PULL FOR v4.21] more dvb fixes

2018-12-04 Thread Sean Young
Hi Mauro,

I think these are the all the outstanding dvb patches for the kernel.

Thanks,

Sean

The following changes since commit 9b90dc85c718443a3e573a0ccf55900ff4fa73ae:

  media: seco-cec: add missing header file to fix build (2018-12-03 15:11:00 
-0500)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.21c

for you to fetch changes up to 669c1d49153a4db43320ba6dcae16a321f5f4ed4:

  media: usb: dvb-usb: remove old friio driver (2018-12-04 19:23:20 +)


Corentin Labbe (1):
  media: usb: dvb-usb: remove old friio driver

Malcolm Priestley (2):
  media: lmedm04: Move usb buffer to lme2510_state.
  media: lmedm04: use dvb_usbv2_generic_rw_locked

Nikita Gerasimov (1):
  media: rtl28xxu: add support for Sony CXD2837ER slave demod

Sean Young (1):
  media: dib7000p: Remove dead code

 drivers/media/dvb-frontends/dib7000p.c  |   7 +-
 drivers/media/usb/dvb-usb-v2/Kconfig|   1 +
 drivers/media/usb/dvb-usb-v2/lmedm04.c  |  73 +
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c |  40 ++-
 drivers/media/usb/dvb-usb-v2/rtl28xxu.h |   4 +-
 drivers/media/usb/dvb-usb/friio-fe.c| 440 ---
 drivers/media/usb/dvb-usb/friio.c   | 522 
 drivers/media/usb/dvb-usb/friio.h   |  99 --
 8 files changed, 60 insertions(+), 1126 deletions(-)
 delete mode 100644 drivers/media/usb/dvb-usb/friio-fe.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.c
 delete mode 100644 drivers/media/usb/dvb-usb/friio.h


Re: [PATCH 3/4] media: lmedm04: Move interrupt buffer to priv buffer.

2018-12-04 Thread Sean Young
On Thu, Nov 29, 2018 at 10:30:15PM +, Malcolm Priestley wrote:
> Interrupt is always present throught life time of
> there is no dma element move this buffer to private
> area of driver.
> 
> Signed-off-by: Malcolm Priestley 
> ---
>  drivers/media/usb/dvb-usb-v2/lmedm04.c | 26 +-
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c 
> b/drivers/media/usb/dvb-usb-v2/lmedm04.c
> index 8fb53b83c914..7b1aaed259db 100644
> --- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
> +++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
> @@ -134,7 +134,7 @@ struct lme2510_state {
>   u8 stream_on;
>   u8 pid_size;
>   u8 pid_off;
> - void *buffer;
> + u8 int_buffer[128];
>   struct urb *lme_urb;
>   u8 usb_buffer[64];
>   /* Frontend original calls */
> @@ -408,20 +408,14 @@ static int lme2510_int_read(struct dvb_usb_adapter 
> *adap)
>   if (lme_int->lme_urb == NULL)
>   return -ENOMEM;
>  
> - lme_int->buffer = usb_alloc_coherent(d->udev, 128, GFP_ATOMIC,
> - _int->lme_urb->transfer_dma);
> -

The buffer was allocated with usb_alloc_coherent, however now it is
allocated with kmalloc. 

> - if (lme_int->buffer == NULL)
> - return -ENOMEM;
> -
>   usb_fill_int_urb(lme_int->lme_urb,
> - d->udev,
> - usb_rcvintpipe(d->udev, 0xa),
> - lme_int->buffer,
> - 128,
> - lme2510_int_response,
> - adap,
> - 8);
> +  d->udev,
> +  usb_rcvintpipe(d->udev, 0xa),
> +  lme_int->int_buffer,
> +  sizeof(lme_int->int_buffer),
> +  lme2510_int_response,
> +  adap,
> +  8);
>  
>   /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
>   ep = usb_pipe_endpoint(d->udev, lme_int->lme_urb->pipe);

On line 408:
lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;

This requires usb_alloc_coherent().

> @@ -1245,11 +1239,9 @@ static void lme2510_exit(struct dvb_usb_device *d)
>   lme2510_kill_urb(>stream);
>   }
>  
> - if (st->lme_urb != NULL) {
> + if (st->lme_urb) {
>   usb_kill_urb(st->lme_urb);
>   usb_free_urb(st->lme_urb);
> - usb_free_coherent(d->udev, 128, st->buffer,
> -   st->lme_urb->transfer_dma);
>   info("Interrupt Service Stopped");
>   }
>  }
> -- 
> 2.19.1


Re: [PATCH 1/4] media: lmedm04: Add missing usb_free_urb to free, interrupt urb

2018-12-04 Thread Sean Young
On Thu, Nov 29, 2018 at 10:29:31PM +, Malcolm Priestley wrote:
> The interrupt urb is killed but never freed add the function
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Malcolm Priestley 
> ---
>  drivers/media/usb/dvb-usb-v2/lmedm04.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c 
> b/drivers/media/usb/dvb-usb-v2/lmedm04.c
> index f109c04f05ae..8b405e131439 100644
> --- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
> +++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
> @@ -1264,6 +1264,7 @@ static void *lme2510_exit_int(struct dvb_usb_device *d)
>  
>   if (st->lme_urb != NULL) {
>   usb_kill_urb(st->lme_urb);
> + usb_free_urb(st->lme_urb);

Now st->lme_urb is a stale pointer.

>   usb_free_coherent(d->udev, 128, st->buffer,
> st->lme_urb->transfer_dma);

And now you're following it.

>   info("Interrupt Service Stopped");
> -- 
> 2.19.1


Re: Astrometa DVB-T2 2018 update

2018-11-29 Thread Sean Young
On Mon, Nov 05, 2018 at 07:12:52PM +, Bob Goddard wrote:
> Enable Sony CXD2837ER slave demon on the Astrometa DVB-T2, known as the 2018 
> update.
> 
> Originally based on the patch by kapitanf at 
> https://github.com/torvalds/linux/pull/567, it was not quite right. This is 
> more correct, but probably still wrong. I'm not a kernel dev, but someone may 
> be better positioned to handle the niceties.

Before this patch can be accepted, we need a Signed-off-by: from the
original author, see:

https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html?highlight=signed%20off#sign-your-work-the-developer-s-certificate-of-origin

> 
> 
> 
> diff --git a/drivers/media/usb/dvb-usb-v2/Kconfig 
> b/drivers/media/usb/dvb-usb-v2/Kconfig
> index df4412245a8a..d44ddd5ee29e 100644
> --- a/drivers/media/usb/dvb-usb-v2/Kconfig
> +++ b/drivers/media/usb/dvb-usb-v2/Kconfig
> @@ -137,6 +137,7 @@ config DVB_USB_RTL28XXU
>   select DVB_RTL2832
>   select DVB_RTL2832_SDR if (MEDIA_SUBDRV_AUTOSELECT && MEDIA_SDR_SUPPORT)
>   select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT
> + select DVB_CXD2841ER if MEDIA_SUBDRV_AUTOSELECT
>   select MEDIA_TUNER_E4000 if MEDIA_SUBDRV_AUTOSELECT
>   select MEDIA_TUNER_FC0012 if MEDIA_SUBDRV_AUTOSELECT
>   select MEDIA_TUNER_FC0013 if MEDIA_SUBDRV_AUTOSELECT
> diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 
> b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
> index a970224a94bd..db4f4da43781 100644
> --- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
> +++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
> @@ -386,6 +386,7 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
>   struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
>   struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
>   struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
> + struct rtl28xxu_req req_cxd2837er = {0x68d8, CMD_I2C_RD, 1, buf};
>  
>   dev_dbg(>intf->dev, "\n");
>  
> @@ -567,6 +568,13 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
>   dev->slave_demod = SLAVE_DEMOD_MN88473;
>   goto demod_found;
>   }
> +
> + ret = rtl28xxu_ctrl_msg(d, _cxd2837er);
> + if (ret == 0 && buf[0] == 0x03) {
> + dev_dbg(>intf->dev, "CXD2837ER found");
> + dev->slave_demod = SLAVE_DEMOD_CXD2841ER;
> + goto demod_found;
> + }
>   }
>   if (dev->tuner == TUNER_RTL2832_SI2157) {
>   /* check Si2168 ID register; reg=c8 val=80 */
> @@ -988,6 +996,27 @@ static int rtl2832u_frontend_attach(struct 
> dvb_usb_adapter *adap)
>   goto err_slave_demod_failed;
>   }
>  
> + dev->i2c_client_slave_demod = client;
> + } else if (dev->slave_demod == SLAVE_DEMOD_CXD2841ER) {
> + struct cxd2841er_config cxd2837er_config = {};
> + cxd2837er_config.i2c_addr = 0xd8;
> + cxd2837er_config.xtal = SONY_XTAL_20500;
> + cxd2837er_config.flags = CXD2841ER_AUTO_IFHZ| 
> CXD2841ER_EARLY_TUNE |
> + CXD2841ER_NO_WAIT_LOCK | 
> CXD2841ER_NO_AGCNEG  |
> + CXD2841ER_TSBITS   | 
> CXD2841ER_TS_SERIAL;
> +
> + adap->fe[1] = dvb_attach( cxd2841er_attach_t_c, 
> _config, >i2c_adap );

Unneeded spaces around function arguments.

> + if (!adap->fe[1]) {
> + dev_err(>intf->dev, "CXD2837ER attach 
> failed!\n");
> + return -ENODEV;
> + }
> +
> + if (!try_module_get(client->dev.driver->owner)) {
> + i2c_unregister_device(client);
> + dev->slave_demod = SLAVE_DEMOD_NONE;
> + goto err_slave_demod_failed;
> + }
> +
>   dev->i2c_client_slave_demod = client;
>   } else {
>   struct si2168_config si2168_config = {};
> @@ -1046,10 +1075,14 @@ static int rtl28xxu_frontend_detach(struct 
> dvb_usb_adapter *adap)
>   dev_dbg(>intf->dev, "\n");
>  
>   /* remove I2C slave demod */
> - client = dev->i2c_client_slave_demod;
> - if (client) {
> - module_put(client->dev.driver->owner);
> - i2c_unregister_device(client);
> + if (dev->slave_demod == SLAVE_DEMOD_CXD2841ER) {
> + dev_info(>intf->dev,"Sony CXD2837ER detached 
> automatically.");

For one thing the reference count for the module was increased on attach,
so we should also decrease it on dettach. Why are we not unregistering
the i2c device?

> + } else {
> + client = dev->i2c_client_slave_demod;
> + if (client) {
> + module_put(client->dev.driver->owner);

[GIT PULL FOR v4.21] dvb fixes

2018-11-28 Thread Sean Young
Hi Mauro,

So I've gone through the outstanding DVB patches and picked up the easier
ones to deal with first. Please scrutinise.

Thanks,

Sean

The following changes since commit 708d75fe1c7c6e9abc5381b6fcc32b49830383d0:

  media: dvb-pll: don't re-validate tuner frequencies (2018-11-23 12:27:18 
-0500)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.21b

for you to fetch changes up to b2d148f755fc60840fbaec52388152896f8339be:

  media: sony-cxd2880: add optional vcc regulator to bindings (2018-11-27 
16:04:16 +)


Colin Ian King (1):
  media: dib0700: fix spelling mistake "Amplifyer" -> "Amplifier"

Hans Verkuil (1):
  media: dib0900: fix smatch warnings

Julia Lawall (1):
  media: mxl5xx: constify dvb_frontend_ops structure

Malcolm Priestley (1):
  media: dvb-usb-v2: Fix incorrect use of transfer_flags URB_FREE_BUFFER

Neil Armstrong (3):
  media: cxd2880-spi: fix probe when dvb_attach fails
  media: cxd2880-spi: Add optional vcc regulator
  media: sony-cxd2880: add optional vcc regulator to bindings

Sean Young (1):
  media: saa7134: rc-core maintains users count, no need to duplicate

Victor Toso (2):
  media: af9033: Remove duplicated switch statement
  media: dvb: Use WARM definition from identify_state()

zhong jiang (2):
  media: usb: Use kmemdup instead of duplicating its function.
  media: dvb-frontends: Use kmemdup instead of duplicating its function

 .../devicetree/bindings/media/spi/sony-cxd2880.txt |  4 ++
 drivers/media/dvb-frontends/af9033.c   | 12 +---
 drivers/media/dvb-frontends/dib0090.c  | 32 +-
 drivers/media/dvb-frontends/lgdt3306a.c|  6 +-
 drivers/media/dvb-frontends/mxl5xx.c   |  2 +-
 drivers/media/pci/saa7134/saa7134-core.c   |  8 +--
 drivers/media/pci/saa7134/saa7134-input.c  | 68 --
 drivers/media/pci/saa7134/saa7134.h|  9 ++-
 drivers/media/spi/cxd2880-spi.c| 17 ++
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c|  6 +-
 drivers/media/usb/dvb-usb-v2/gl861.c   |  3 +-
 drivers/media/usb/dvb-usb-v2/usb_urb.c |  5 +-
 drivers/media/usb/dvb-usb/dib0700_devices.c|  2 +-
 13 files changed, 66 insertions(+), 108 deletions(-)


Re: [PATCH dvb v1 4/4] media: dvb_frontend: remove __func__ from dev_dbg()

2018-11-27 Thread Sean Young
On Tue, Oct 30, 2018 at 05:14:51PM +0100, Victor Toso wrote:
> From: Victor Toso 
> 
> As dynamic debug can be instructed to add the function name to the
> debug output using +f switch, we can remove __func__ from all
> dev_dbg() calls. If not, a user that sets +f in dynamic debug would
> get duplicated function name.
> 
> Signed-off-by: Victor Toso 
> ---
>  drivers/media/dvb-core/dvb_frontend.c | 142 +-
>  1 file changed, 69 insertions(+), 73 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index 961207cf09eb..ab6d778aa641 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -251,7 +251,7 @@ static void dvb_frontend_add_event(struct dvb_frontend 
> *fe,
>   struct dvb_frontend_event *e;
>   int wp;
>  
> - dev_dbg(fe->dvb->device, "%s:\n", __func__);
> + dev_dbg(fe->dvb->device, "\n");

Again same as 3/4. Either make the debug useful or delete it.


Sean

>  
>   if ((status & FE_HAS_LOCK) && has_get_frontend(fe))
>   dtv_get_frontend(fe, c, >parameters_out);
> @@ -293,7 +293,7 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe,
>   struct dvb_frontend_private *fepriv = fe->frontend_priv;
>   struct dvb_fe_events *events = >events;
>  
> - dev_dbg(fe->dvb->device, "%s:\n", __func__);
> + dev_dbg(fe->dvb->device, "\n");
>  
>   if (events->overflow) {
>   events->overflow = 0;
> @@ -334,8 +334,8 @@ static void dvb_frontend_clear_events(struct dvb_frontend 
> *fe)
>  static void dvb_frontend_init(struct dvb_frontend *fe)
>  {
>   dev_dbg(fe->dvb->device,
> - "%s: initialising adapter %i frontend %i (%s)...\n",
> - __func__, fe->dvb->num, fe->id, fe->ops.info.name);
> + "initialising adapter %i frontend %i (%s)...\n",
> + fe->dvb->num, fe->id, fe->ops.info.name);
>  
>   if (fe->ops.init)
>   fe->ops.init(fe);
> @@ -362,7 +362,7 @@ static void dvb_frontend_swzigzag_update_delay(struct 
> dvb_frontend_private *fepr
>   int q2;
>   struct dvb_frontend *fe = fepriv->dvbdev->priv;
>  
> - dev_dbg(fe->dvb->device, "%s:\n", __func__);
> + dev_dbg(fe->dvb->device, "\n");
>  
>   if (locked)
>   (fepriv->quality) = (fepriv->quality * 220 + 36 * 256) / 256;
> @@ -458,8 +458,8 @@ static int dvb_frontend_swzigzag_autotune(struct 
> dvb_frontend *fe, int check_wra
>   }
>  
>   dev_dbg(fe->dvb->device,
> - "%s: drift:%i inversion:%i auto_step:%i auto_sub_step:%i 
> started_auto_step:%i\n",
> - __func__, fepriv->lnb_drift, fepriv->inversion,
> + "drift:%i inversion:%i auto_step:%i auto_sub_step:%i 
> started_auto_step:%i\n",
> + fepriv->lnb_drift, fepriv->inversion,
>   fepriv->auto_step, fepriv->auto_sub_step,
>   fepriv->started_auto_step);
>  
> @@ -661,7 +661,7 @@ static int dvb_frontend_thread(void *data)
>   bool re_tune = false;
>   bool semheld = false;
>  
> - dev_dbg(fe->dvb->device, "%s:\n", __func__);
> + dev_dbg(fe->dvb->device, "\n");
>  
>   fepriv->check_wrapped = 0;
>   fepriv->quality = 0;
> @@ -710,10 +710,10 @@ static int dvb_frontend_thread(void *data)
>   algo = fe->ops.get_frontend_algo(fe);
>   switch (algo) {
>   case DVBFE_ALGO_HW:
> - dev_dbg(fe->dvb->device, "%s: Frontend ALGO = 
> DVBFE_ALGO_HW\n", __func__);
> + dev_dbg(fe->dvb->device, "Frontend ALGO = 
> DVBFE_ALGO_HW\n");
>  
>   if (fepriv->state & FESTATE_RETUNE) {
> - dev_dbg(fe->dvb->device, "%s: Retune 
> requested, FESTATE_RETUNE\n", __func__);
> + dev_dbg(fe->dvb->device, "Retune 
> requested, FESTATE_RETUNE\n");
>   re_tune = true;
>   fepriv->state = FESTATE_TUNED;
>   } else {
> @@ -724,19 +724,21 @@ static int dvb_frontend_thread(void *data)
>   fe->ops.tune(fe, re_tune, 
> fepriv->tune_mode_flags, >delay, );
>  
>   if (s != fepriv->status && 
> !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
> - dev_dbg(fe->dvb->device, "%s: state 
> changed, adding current state\n", __func__);
> + dev_dbg(fe->dvb->device, "state 
> changed, adding current state\n");
>   dvb_frontend_add_event(fe, s);
>   fepriv->status = s;
>   }
>   break;
>   case DVBFE_ALGO_SW:
> - dev_dbg(fe->dvb->device, "%s: Frontend 

Re: [PATCH dvb v1 3/4] media: dvb-usb-v2: remove __func__ from dev_dbg()

2018-11-27 Thread Sean Young
On Tue, Oct 30, 2018 at 05:14:50PM +0100, Victor Toso wrote:
> From: Victor Toso 
> 
> As dynamic debug can be instructed to add the function name to the
> debug output using +f switch, we can remove __func__ from all
> dev_dbg() calls. If not, a user that sets +f in dynamic debug would
> get duplicated function name.
> 
> Signed-off-by: Victor Toso 
> ---
>  drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 105 ++--
>  drivers/media/usb/dvb-usb-v2/dvb_usb_urb.c  |   7 +-
>  2 files changed, 55 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c 
> b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
> index d55ef016d418..ad554668cc86 100644
> --- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
> +++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
> @@ -37,7 +37,7 @@ static int dvb_usbv2_download_firmware(struct 
> dvb_usb_device *d,
>  {
>   int ret;
>   const struct firmware *fw;
> - dev_dbg(>udev->dev, "%s:\n", __func__);
> + dev_dbg(>udev->dev, "\n");

How about "downloading firmware", or maybe deleting the line completely?

Without dynamic debug enabled, you end up with a pretty useless debug
message now. I think it would be better to convert these debug lines
to useful messages, rather than "executing this line of code". Some of
them should probably be deleted.

>  
>   if (!d->props->download_firmware) {
>   ret = -EINVAL;
> @@ -62,14 +62,14 @@ static int dvb_usbv2_download_firmware(struct 
> dvb_usb_device *d,
>  
>   return ret;
>  err:
> - dev_dbg(>udev->dev, "%s: failed=%d\n", __func__, ret);
> + dev_dbg(>udev->dev, "failed=%d\n", ret);

Again, just say what failed here. Ideally debug messages should be useful and
not just "hit this line of code".


Sean

>   return ret;
>  }
>  
>  static int dvb_usbv2_i2c_init(struct dvb_usb_device *d)
>  {
>   int ret;
> - dev_dbg(>udev->dev, "%s:\n", __func__);
> + dev_dbg(>udev->dev, "\n");
>  
>   if (!d->props->i2c_algo)
>   return 0;
> @@ -87,13 +87,13 @@ static int dvb_usbv2_i2c_init(struct dvb_usb_device *d)
>  
>   return 0;
>  err:
> - dev_dbg(>udev->dev, "%s: failed=%d\n", __func__, ret);
> + dev_dbg(>udev->dev, "failed=%d\n", ret);
>   return ret;
>  }
>  
>  static int dvb_usbv2_i2c_exit(struct dvb_usb_device *d)
>  {
> - dev_dbg(>udev->dev, "%s:\n", __func__);
> + dev_dbg(>udev->dev, "\n");
>  
>   if (d->i2c_adap.algo)
>   i2c_del_adapter(>i2c_adap);
> @@ -133,7 +133,7 @@ static int dvb_usbv2_remote_init(struct dvb_usb_device *d)
>  {
>   int ret;
>   struct rc_dev *dev;
> - dev_dbg(>udev->dev, "%s:\n", __func__);
> + dev_dbg(>udev->dev, "\n");
>  
>   if (dvb_usbv2_disable_rc_polling || !d->props->get_rc_config)
>   return 0;
> @@ -188,13 +188,13 @@ static int dvb_usbv2_remote_init(struct dvb_usb_device 
> *d)
>  
>   return 0;
>  err:
> - dev_dbg(>udev->dev, "%s: failed=%d\n", __func__, ret);
> + dev_dbg(>udev->dev, "failed=%d\n", ret);
>   return ret;
>  }
>  
>  static int dvb_usbv2_remote_exit(struct dvb_usb_device *d)
>  {
> - dev_dbg(>udev->dev, "%s:\n", __func__);
> + dev_dbg(>udev->dev, "\n");
>  
>   if (d->rc_dev) {
>   cancel_delayed_work_sync(>rc_query_work);
> @@ -232,7 +232,7 @@ static void dvb_usb_data_complete_raw(struct 
> usb_data_stream *stream, u8 *buf,
>  
>  static int dvb_usbv2_adapter_stream_init(struct dvb_usb_adapter *adap)
>  {
> - dev_dbg(_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
> + dev_dbg(_to_d(adap)->udev->dev, "adap=%d\n",
>   adap->id);
>  
>   adap->stream.udev = adap_to_d(adap)->udev;
> @@ -244,7 +244,7 @@ static int dvb_usbv2_adapter_stream_init(struct 
> dvb_usb_adapter *adap)
>  
>  static int dvb_usbv2_adapter_stream_exit(struct dvb_usb_adapter *adap)
>  {
> - dev_dbg(_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
> + dev_dbg(_to_d(adap)->udev->dev, "adap=%d\n",
>   adap->id);
>  
>   return usb_urb_exitv2(>stream);
> @@ -257,8 +257,8 @@ static int dvb_usb_start_feed(struct dvb_demux_feed 
> *dvbdmxfeed)
>   int ret = 0;
>   struct usb_data_stream_properties stream_props;
>   dev_dbg(>udev->dev,
> - "%s: adap=%d active_fe=%d feed_type=%d setting pid 
> [%s]: %04x (%04d) at index %d\n",
> - __func__, adap->id, adap->active_fe, dvbdmxfeed->type,
> + "adap=%d active_fe=%d feed_type=%d setting pid [%s]: 
> %04x (%04d) at index %d\n",
> + adap->id, adap->active_fe, dvbdmxfeed->type,
>   adap->pid_filtering ? "yes" : "no", dvbdmxfeed->pid,
>   dvbdmxfeed->pid, dvbdmxfeed->index);
>  
> @@ -334,7 +334,7 @@ static int dvb_usb_start_feed(struct dvb_demux_feed 
> *dvbdmxfeed)
>   }
>  
>   if (ret)
> - dev_dbg(>udev->dev, "%s: failed=%d\n", __func__, ret);
> + 

[PATCH] media: saa7134: rc-core maintains users count, no need to duplicate

2018-11-25 Thread Sean Young
This simplifies the code a little. Tested with suspend and resume.

Signed-off-by: Sean Young 
---
 drivers/media/pci/saa7134/saa7134-core.c  |  8 +--
 drivers/media/pci/saa7134/saa7134-input.c | 68 ---
 drivers/media/pci/saa7134/saa7134.h   |  9 ++-
 3 files changed, 18 insertions(+), 67 deletions(-)

diff --git a/drivers/media/pci/saa7134/saa7134-core.c 
b/drivers/media/pci/saa7134/saa7134-core.c
index 8984b1bf57a5..aa98ea49558c 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -1419,8 +1419,8 @@ static int saa7134_suspend(struct pci_dev *pci_dev , 
pm_message_t state)
del_timer(>vbi_q.timeout);
del_timer(>ts_q.timeout);
 
-   if (dev->remote)
-   saa7134_ir_stop(dev);
+   if (dev->remote && dev->remote->dev->users)
+   saa7134_ir_close(dev->remote->dev);
 
pci_save_state(pci_dev);
pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
@@ -1447,8 +1447,8 @@ static int saa7134_resume(struct pci_dev *pci_dev)
saa7134_videoport_init(dev);
if (card_has_mpeg(dev))
saa7134_ts_init_hw(dev);
-   if (dev->remote)
-   saa7134_ir_start(dev);
+   if (dev->remote && dev->remote->dev->users)
+   saa7134_ir_open(dev->remote->dev);
saa7134_hw_enable1(dev);
 
msleep(100);
diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index bc1ed7798d21..35884d5b8337 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -448,17 +448,10 @@ static void saa7134_input_timer(struct timer_list *t)
mod_timer(>timer, jiffies + msecs_to_jiffies(ir->polling));
 }
 
-static int __saa7134_ir_start(void *priv)
+int saa7134_ir_open(struct rc_dev *rc)
 {
-   struct saa7134_dev *dev = priv;
-   struct saa7134_card_ir *ir;
-
-   if (!dev || !dev->remote)
-   return -EINVAL;
-
-   ir  = dev->remote;
-   if (ir->running)
-   return 0;
+   struct saa7134_dev *dev = rc->priv;
+   struct saa7134_card_ir *ir = dev->remote;
 
/* Moved here from saa7134_input_init1() because the latter
 * is not called on device resume */
@@ -507,55 +500,15 @@ static int __saa7134_ir_start(void *priv)
return 0;
 }
 
-static void __saa7134_ir_stop(void *priv)
+void saa7134_ir_close(struct rc_dev *rc)
 {
-   struct saa7134_dev *dev = priv;
-   struct saa7134_card_ir *ir;
-
-   if (!dev || !dev->remote)
-   return;
-
-   ir  = dev->remote;
-   if (!ir->running)
-   return;
+   struct saa7134_dev *dev = rc->priv;
+   struct saa7134_card_ir *ir = dev->remote;
 
if (ir->polling)
del_timer_sync(>timer);
 
ir->running = false;
-
-   return;
-}
-
-int saa7134_ir_start(struct saa7134_dev *dev)
-{
-   if (dev->remote->users)
-   return __saa7134_ir_start(dev);
-
-   return 0;
-}
-
-void saa7134_ir_stop(struct saa7134_dev *dev)
-{
-   if (dev->remote->users)
-   __saa7134_ir_stop(dev);
-}
-
-static int saa7134_ir_open(struct rc_dev *rc)
-{
-   struct saa7134_dev *dev = rc->priv;
-
-   dev->remote->users++;
-   return __saa7134_ir_start(dev);
-}
-
-static void saa7134_ir_close(struct rc_dev *rc)
-{
-   struct saa7134_dev *dev = rc->priv;
-
-   dev->remote->users--;
-   if (!dev->remote->users)
-   __saa7134_ir_stop(dev);
 }
 
 int saa7134_input_init1(struct saa7134_dev *dev)
@@ -624,7 +577,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
mask_keycode = 0x0007C8;
mask_keydown = 0x10;
polling  = 50; // ms
-   /* GPIO stuff moved to __saa7134_ir_start() */
+   /* GPIO stuff moved to saa7134_ir_open() */
break;
case SAA7134_BOARD_AVERMEDIA_M135A:
ir_codes = RC_MAP_AVERMEDIA_M135A;
@@ -646,14 +599,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
mask_keycode = 0x02F200;
mask_keydown = 0x000400;
polling  = 50; // ms
-   /* GPIO stuff moved to __saa7134_ir_start() */
+   /* GPIO stuff moved to saa7134_ir_open() */
break;
case SAA7134_BOARD_AVERMEDIA_A16D:
ir_codes = RC_MAP_AVERMEDIA_A16D;
mask_keycode = 0x02F200;
mask_keydown = 0x000400;
polling  = 50; /* ms */
-   /* GPIO stuff moved to __saa7134_ir_start() */
+   /* GPIO stuff moved to saa7134_ir_open() */
break;
case SAA7134_BOARD_KWORLD_TERMINATOR:

[PATCH v4l-utils] keytable: do not install bpf protocols decoders with execute permission

2018-11-23 Thread Sean Young
The rpm packaging system will try to extract debug information, which
fails since there is no build id. This can be avoided by removing
the execute permission.

BPF relocatable files are executable anyway so this is the right
thing to do.

See:
https://github.com/rpm-software-management/rpm/pull/604

Signed-off-by: Sean Young 
---
 utils/keytable/bpf_protocols/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
index 1b90411b..d1f04cb4 100644
--- a/utils/keytable/bpf_protocols/Makefile.am
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -21,4 +21,4 @@ EXTRA_DIST = $(PROTOCOLS:%.o=%.c) bpf_helpers.h
 install-data-local:
$(install_sh) -d "$(DESTDIR)$(keytableuserdir)/protocols"
$(install_sh) -d "$(DESTDIR)$(keytablesystemdir)/protocols"
-   $(install_sh) $(PROTOCOLS) "$(DESTDIR)$(keytablesystemdir)/protocols"
+   $(install_sh) -m 0644 $(PROTOCOLS) 
"$(DESTDIR)$(keytablesystemdir)/protocols"
-- 
2.19.1



[PATCH v4l-utils] keytable: match every entry in rc_maps.cfg, not just the first

2018-11-16 Thread Sean Young
Signed-off-by: Sean Young 
---
 utils/keytable/keytable.c | 71 ---
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index e15440de..df9cfc49 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -634,14 +634,13 @@ static error_t parse_keyfile(char *fname, char **table)
return parse_plain_keyfile(fname, table);
 }
 
-struct cfgfile *nextcfg = 
-
 static error_t parse_cfgfile(char *fname)
 {
FILE *fin;
int line = 0;
char s[2048];
char *driver, *table, *filename;
+   struct cfgfile *nextcfg = 
 
if (debug)
fprintf(stderr, _("Parsing %s config file\n"), fname);
@@ -2142,55 +2141,57 @@ int main(int argc, char *argv[])
struct cfgfile *cur;
char *fname, *name;
int rc;
+   int matches = 0;
 
for (cur =  cur->next; cur = cur->next) {
if ((!rc_dev.drv_name || strcasecmp(cur->driver, 
rc_dev.drv_name)) && strcasecmp(cur->driver, "*"))
continue;
if ((!rc_dev.keytable_name || strcasecmp(cur->table, 
rc_dev.keytable_name)) && strcasecmp(cur->table, "*"))
continue;
-   break;
-   }
 
-   if (!cur->next) {
if (debug)
-   fprintf(stderr, _("Table for %s, %s not found. 
Keep as-is\n"),
-  rc_dev.drv_name, rc_dev.keytable_name);
-   return 0;
-   }
-   if (debug)
-   fprintf(stderr, _("Table for %s, %s is on %s file.\n"),
-   rc_dev.drv_name, rc_dev.keytable_name,
-   cur->fname);
-   if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && 
strchr(cur->fname, '/'))) {
-   fname = cur->fname;
-   rc = parse_keyfile(fname, );
-   if (rc < 0) {
-   fprintf(stderr, _("Can't load %s table\n"), 
fname);
-   return -1;
-   }
-   } else {
-   fname = malloc(strlen(cur->fname) + 
strlen(IR_KEYTABLE_USER_DIR) + 2);
-   strcpy(fname, IR_KEYTABLE_USER_DIR);
-   strcat(fname, "/");
-   strcat(fname, cur->fname);
-   rc = parse_keyfile(fname, );
-   if (rc != 0) {
-   fname = malloc(strlen(cur->fname) + 
strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
-   strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
+   fprintf(stderr, _("Table for %s, %s is on %s 
file.\n"),
+   rc_dev.drv_name, rc_dev.keytable_name,
+   cur->fname);
+   if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && 
strchr(cur->fname, '/'))) {
+   fname = cur->fname;
+   rc = parse_keyfile(fname, );
+   if (rc < 0) {
+   fprintf(stderr, _("Can't load %s 
table\n"), fname);
+   return -1;
+   }
+   } else {
+   fname = malloc(strlen(cur->fname) + 
strlen(IR_KEYTABLE_USER_DIR) + 2);
+   strcpy(fname, IR_KEYTABLE_USER_DIR);
strcat(fname, "/");
strcat(fname, cur->fname);
rc = parse_keyfile(fname, );
+   if (rc != 0) {
+   fname = malloc(strlen(cur->fname) + 
strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
+   strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
+   strcat(fname, "/");
+   strcat(fname, cur->fname);
+   rc = parse_keyfile(fname, );
+   }
+   if (rc != 0) {
+   fprintf(stderr, _("Can't load %s table 
from %s or %s\n"), cur->fname, IR_KEYTABLE_USER_DIR, IR_KEYTABLE_SYSTEM_DIR);
+   return -1;
+   }
}
-   if (rc != 0) {
-   fp

Re: TechnoTrend CT2-4500 remote not working

2018-11-14 Thread Sean Young
Martin,

On Wed, Nov 14, 2018 at 09:51:38PM +0100, martin.kono...@mknetz.de wrote:
> > It would be interesting to see what the device is sending. Please can you 
> > turn
> > on dynamic debug for ir-kbd-i2c.c:
> > 
> > echo "file ir-kbd-i2.c +p" > /sys/kernel/debug/dynamic_debug/control
> > 
> > Try the remote again and report what in the kernel messages.
> > 
> > Sean
> > 
> 
> I turned on dynamic debug and got the following messages in the kernel log:
> 
> [  837.160992] rc rc0: get_key_fusionhdtv: ff ff ff ff
> [  837.263927] rc rc0: ir_key_poll
> [  837.264528] rc rc0: get_key_fusionhdtv: ff ff ff ff
> [  837.367840] rc rc0: ir_key_poll
> [  837.368441] rc rc0: get_key_fusionhdtv: ff ff ff ff
> 
> Pressing a key on the remote did not change the pattern. I rechecked the
> connection of the IR receiver to the card but it was firmly plugged in.

Hmm, either the IR signal is not getting to the device, or this is not
where the IR is reported. I guess also the firmware could be incorrect
or out of date.

Certainly a logic analyser would help here to see if the signal is arriving,
and where it goes (e.g. directly to a gpio pin).

What's the output of the lspci -vvv? Maybe it's reported via gpio and not
i2c.

Thanks
Sean


Re: TechnoTrend CT2-4500 remote not working

2018-11-11 Thread Sean Young
On Sat, Nov 10, 2018 at 10:35:29PM +0100, martin.kono...@mknetz.de wrote:
> Hi all,
> 
> the remote on my TechnoTrend CT2-4500 is not working with kernel 4.18.
> The TV-card itself works fine:
> 
> cx25840 6-0044: loaded v4l-cx23885-avcore-01.fw firmware (16382 bytes)
> cx23885: cx23885_dvb_register() allocating 1 frontend(s)
> cx23885: cx23885[0]: cx23885 based dvb card
> i2c i2c-5: Added multiplexed i2c bus 12
> si2168 5-0064: Silicon Labs Si2168-B40 successfully identified
> si2168 5-0064: firmware version: B 4.0.2
> si2157 12-0060: Silicon Labs Si2147/2148/2157/2158 successfully attached
> dvbdev: DVB: registering new adapter (cx23885[0])
> cx23885 :17:00.0: DVB: registering adapter 0 frontend 0 (Silicon
> Labs Si2168)...
> sp2 4-0040: CIMaX SP2 successfully attached
> cx23885: Technotrend TT-budget CT2-4500 CI MAC address: bc:ea:2b:45:05:68
> cx23885: cx23885_dev_checkrevision() Hardware revision = 0xa5
> cx23885: cx23885[0]/0: found at :17:00.0, rev: 4, irq: 31, latency:
> 0, mmio: 0xfe00
> 
> 
> The remote is registered:
> 
> Registered IR keymap rc-fusionhdtv-mce
> rc rc0: FusionHDTV as
> /devices/pci:00/:00:01.2/:15:00.2/:16:00.0/:17:00.0/i2c-4/4-006b/rc/rc0
> input: FusionHDTV as
> /devices/pci:00/:00:01.2/:15:00.2/:16:00.0/:17:00.0/i2c-4/4-006b/rc/rc0/input18
> rc rc0: lirc_dev: driver ir_kbd_i2c registered at minor = 0, scancode
> receiver, no transmitter
> 
> ir-keytable reports:
> 
> Found /sys/class/rc/rc0/ (/dev/input/event15) with:
>   Name: FusionHDTV
>   Driver: ir_kbd_i2c, table: rc-fusionhdtv-mce
>   lirc device: /dev/lirc0
>   Supported protocols: unknown
>   Enabled protocols: unknown
>   bus: 24, vendor/product: :, version: 0x
>   Repeat delay = 500 ms, repeat period = 125 ms
> 
> Apparently, no protocols are reported.

It support a protocol, we don't know what it is, so it's called unknown.

> evtest on /dev/input/event15 reports no events.

That's a valid test. You can also use "ir-keytable -t".

> The error was reported before:
> 
> http://lirc.10951.n7.nabble.com/Problems-with-cx23885-IR-receiver-td10884.html
> 
> The remote is working, I verified it with a camera.

It would be interesting to see what the device is sending. Please can you turn
on dynamic debug for ir-kbd-i2c.c:

echo "file ir-kbd-i2.c +p" > /sys/kernel/debug/dynamic_debug/control

Try the remote again and report what in the kernel messages.

 
Sean


Re: [PATCH v4l-utils] Add missing linux/bpf_common.h

2018-11-09 Thread Sean Young
Hi Peter,

On Thu, Nov 08, 2018 at 10:13:38PM +0100, Peter Seiderer wrote:
> Thanks, works for the buildroot use case (disabling
> bpf support unconditionally)...
> 
> The reason to provide copies of the linux kernel headers in  v4l-utils
> is to be independent of old(-er) headers provided by toolchains?
> 
> If so a copy of bpf_common.h is still needed (and the fallback, for
> out of linux kernel usage, define for __NR_bpf in bpf.h enhanced for
> all supported archs)?

I have seen this problem on debian 7. Why do we care about compiling
on something that ancient?


Sean


[PATCH] keytable: fix BPF protocol compilation on mips

2018-11-07 Thread Sean Young
clang -idirafter /usr/local/include -idirafter
+/usr/lib/llvm-6.0/lib/clang/6.0.1/include -idirafter
+/usr/include/mips64el-linux-gnuabi64 -idirafter /usr/include
+-I../../../include -target bpf -O2 -c grundig.c
> In file included from grundig.c:5:
> In file included from ../../../include/linux/lirc.h:10:
> In file included from /usr/include/linux/types.h:9:
> In file included from /usr/include/linux/posix_types.h:36:
> In file included from
+/usr/include/mips64el-linux-gnuabi64/asm/posix_types.h:13:
> /usr/include/mips64el-linux-gnuabi64/asm/sgidefs.h:19:2: error: Use a Linux
+compiler or give up.
> #error Use a Linux compiler or give up.

This requires __linux__ to be defined.

Signed-off-by: Sean Young 
---
 utils/keytable/bpf_protocols/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
index 8887b897..ba79742c 100644
--- a/utils/keytable/bpf_protocols/Makefile.am
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -8,7 +8,7 @@ CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - &1 \
 | sed -n '/<...> search starts here:/,/End of search list./{ s| 
\(/.*\)|-idirafter \1|p }')
 
 %.o: %.c bpf_helpers.h
-   $(CLANG) $(CLANG_SYS_INCLUDES) -I$(top_srcdir)/include -target bpf -O2 
-c $<
+   $(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
 
-- 
2.17.2



Re: [PATCH v4l-utils] Add missing linux/bpf_common.h

2018-11-07 Thread Sean Young
Hi Peter,

On Tue, Nov 06, 2018 at 10:43:58PM +0100, Peter Seiderer wrote:
> On Tue, 6 Nov 2018 10:38:56 +0000, Sean Young  wrote:
> 
> > On Mon, Nov 05, 2018 at 09:30:47PM +0100, Peter Seiderer wrote:
> > > Copy from [1], needed by bpf.h.
> > >
> > > [1] 
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/bpf_common.h?h=v4.19
> >
> > So bpf.h does include this file, but we don't use anything from it in
> > v4l-utils.
> >
> 
> Maybe alternative fix is to remove the include (or not if your want
> the headers to be in sync with the kernel ones, but then they should
> be complete enough to be used for compile)?
> 
> > This include file is for the original BPF, which has been around for a
> > long time. So why is this include file missing, i.e. what problem are you
> > trying to solve?
> 
> A buildroot autobuild failure (see [1] for details) with older toolchains
> not providing this header...
> 
> >
> > Lastely, the file should be included in the sync-with-kernel target so
> > it does not get out of sync -- should it really be necessary to add the
> > file.
> 
> O.k, can do it on next patch iteration...
> 
> Regards,
> Peter
> 
> [1] http://lists.busybox.net/pipermail/buildroot/2018-November/234840.html

So here libelf was not detected, hence ir-keytable should have been built
without BPF support, but it is still including bpf.h despite it not
being used.

I've just sent a patch for better support for building without BPF,
see here:
https://patchwork.linuxtv.org/patch/52841/


Would you mind seeing if that works for you?


Thanks,

Sean


[PATCH v4l-utils] keytable: fix compilation warning

2018-11-07 Thread Sean Young
keytable.c: In function ‘parse_opt’:
keytable.c:835:7: warning: ‘param’ may be used uninitialized in this function 
[-Wuninitialized]

Signed-off-by: Sean Young 
---
 utils/keytable/keytable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 6fc22358..e15440de 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -832,7 +832,7 @@ static error_t parse_opt(int k, char *arg, struct 
argp_state *state)
do {
struct bpf_parameter *param;
 
-   if (!param) {
+   if (!p) {
argp_error(state, _("Missing parameter name: 
%s"), arg);
break;
}
-- 
2.17.2



[PATCH v2 v4l-utils] configure: build without BPF support in ir-keytable

2018-11-07 Thread Sean Young
It currently does not build on mips and some platforms do not have
BPF support yet (risc-v, for example).

Signed-off-by: Sean Young 
---
 configure.ac   | 17 +
 utils/keytable/Makefile.am |  7 ---
 utils/keytable/keytable.c  |  5 -
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 387f8539..5cc34c24 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,16 +173,12 @@ AM_CONDITIONAL([HAVE_X11], [test x$x11_pkgconfig = xyes])
 PKG_CHECK_MODULES([LIBELF], [libelf], [libelf_pkgconfig=yes], 
[libelf_pkgconfig=no])
 AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
-AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
 if test "x$libelf_pkgconfig" = "xyes"; then
   AC_CHECK_PROG([CLANG], clang, clang)
-  AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
 else
   AC_MSG_WARN(libelf library not available)
 fi
 
-AM_CONDITIONAL([BPF_PROTOCOLS], [test x$CLANG = xclang])
-
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
@@ -453,6 +449,14 @@ AC_ARG_ENABLE(gconv,
esac]
 )
 
+AC_ARG_ENABLE(bpf,
+  AS_HELP_STRING([--disable-bpf], [disable IR BPF decoders]),
+  [case "${enableval}" in
+yes | no ) ;;
+*) AC_MSG_ERROR(bad value ${enableval} for --enable-bpf) ;;
+   esac]
+)
+
 PKG_CHECK_MODULES([SDL2], [sdl2 SDL2_image], [sdl_pc=yes], [sdl_pc=no])
 AM_CONDITIONAL([HAVE_SDL], [test x$sdl_pc = xyes])
 
@@ -475,6 +479,7 @@ AM_CONDITIONAL([WITH_GCONV],[test x$enable_gconv = 
xyes -a x$enable_shar
 AM_CONDITIONAL([WITH_V4L2_CTL_LIBV4L], [test x${enable_v4l2_ctl_libv4l} != 
xno])
 AM_CONDITIONAL([WITH_V4L2_CTL_STREAM_TO], [test x${enable_v4l2_ctl_stream_to} 
!= xno])
 AM_CONDITIONAL([WITH_V4L2_COMPLIANCE_LIBV4L], [test 
x${enable_v4l2_compliance_libv4l} != xno])
+AM_CONDITIONAL([WITH_BPF],  [test x$enable_bpf != xno -a 
x$libelf_pkgconfig = xyes -a x$CLANG = xclang])
 
 # append -static to libtool compile and link command to enforce static libs
 AS_IF([test x$enable_libdvbv5 = xno], [AC_SUBST([ENFORCE_LIBDVBV5_STATIC], 
["-static"])])
@@ -505,6 +510,9 @@ AM_COND_IF([WITH_V4L_WRAPPERS], [USE_V4L_WRAPPERS="yes"], 
[USE_V4L_WRAPPERS="no"
 AM_COND_IF([WITH_GCONV], [USE_GCONV="yes"], [USE_GCONV="no"])
 AM_COND_IF([WITH_V4L2_CTL_LIBV4L], [USE_V4L2_CTL_LIBV4L="yes"], 
[USE_V4L2_CTL_LIBV4L="no"])
 AM_COND_IF([WITH_V4L2_COMPLIANCE_LIBV4L], [USE_V4L2_COMPLIANCE_LIBV4L="yes"], 
[USE_V4L2_COMPLIANCE_LIBV4L="no"])
+AM_COND_IF([WITH_BPF], [USE_BPF="yes"
+AC_DEFINE([HAVE_BPF], [1], [BPF IR decoder 
support enabled])],
+   [USE_BPF="no"])
 AS_IF([test "x$alsa_pkgconfig" = "xtrue"], [USE_ALSA="yes"], [USE_ALSA="no"])
 
 AC_OUTPUT
@@ -549,4 +557,5 @@ compile time options summary
 qvidcap: $USE_QVIDCAP
 v4l2-ctl uses libv4l   : $USE_V4L2_CTL_LIBV4L
 v4l2-compliance uses libv4l: $USE_V4L2_COMPLIANCE_LIBV4L
+BPF IR Decoders:   : $USE_BPF
 EOF
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index 90e4c8c8..ddbab0f7 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -6,14 +6,15 @@ udevrules_DATA = 70-infrared.rules
 
 ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
 
-if HAVE_LIBELF
+if WITH_BPF
 ir_keytable_SOURCES += bpf.c bpf_load.c bpf.h bpf_load.h
 endif
 
 ir_keytable_LDADD = @LIBINTL@
-ir_keytable_LDFLAGS = $(ARGP_LIBS) $(LIBELF_LIBS)
+ir_keytable_LDFLAGS = $(ARGP_LIBS)
 
-if BPF_PROTOCOLS
+if WITH_BPF
+ir_keytable_LDFLAGS += $(LIBELF_LIBS)
 SUBDIRS = bpf_protocols
 endif
 
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index a7ed436b..6fc22358 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -34,8 +34,11 @@
 #include "ir-encode.h"
 #include "parse.h"
 #include "toml.h"
+
+#ifdef HAVE_BPF
 #include "bpf.h"
 #include "bpf_load.h"
+#endif
 
 #ifdef ENABLE_NLS
 # define _(string) gettext(string)
@@ -1847,7 +1850,7 @@ static void device_info(int fd, char *prepend)
perror ("EVIOCGID");
 }
 
-#ifdef HAVE_LIBELF
+#ifdef HAVE_BPF
 #define MAX_PROGS 64
 static void attach_bpf(const char *lirc_name, const char *bpf_prog, struct 
toml_table_t *toml)
 {
-- 
2.17.2



[GIT PULL FOR v4.21] rc changes

2018-11-06 Thread Sean Young
Hi Mauro,

A new driver for the usb IR receiver for the original XBox, and a few
minor fixes.

Thanks,

Sean

The following changes since commit ef86eaf97acd6d82cd3fd40f997b1c8c4895a443:

  media: Rename vb2_m2m_request_queue -> v4l2_m2m_request_queue (2018-11-06 
05:24:22 -0500)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.21a

for you to fetch changes up to ca8dc4056dcff7c0cfcb0daaf0b630bcfa34c932:

  media: rc: ensure close() is called on rc_unregister_device (2018-11-06 
10:55:53 +)


Benjamin Valentin (1):
  media: rc: add driver for Xbox DVD Movie Playback Kit

Brad Love (1):
  mceusb: Include three Hauppauge USB dvb device with IR rx

Mauro Carvalho Chehab (1):
  media: rc: imon: replace strcpy() by strscpy()

Sean Young (6):
  media: rc: XBox DVD Remote uses 12 bits scancodes
  media: rc: imon_raw: use fls rather than loop per bit
  media: saa7134: rc device does not need 'saa7134 IR (' prefix
  media: saa7134: hvr1110 can decode rc6
  media: rc: cec devices do not have a lirc chardev
  media: rc: ensure close() is called on rc_unregister_device

 MAINTAINERS   |   6 +
 drivers/media/pci/saa7134/saa7134-input.c |  47 +
 drivers/media/pci/saa7134/saa7134.h   |   1 -
 drivers/media/rc/Kconfig  |  12 ++
 drivers/media/rc/Makefile |   1 +
 drivers/media/rc/imon.c   |   4 +-
 drivers/media/rc/imon_raw.c   |  47 +++--
 drivers/media/rc/keymaps/Makefile |   1 +
 drivers/media/rc/keymaps/rc-xbox-dvd.c|  63 ++
 drivers/media/rc/mceusb.c |   9 +
 drivers/media/rc/rc-main.c|   8 +-
 drivers/media/rc/xbox_remote.c| 306 ++
 include/media/rc-map.h|   1 +
 13 files changed, 435 insertions(+), 71 deletions(-)
 create mode 100644 drivers/media/rc/keymaps/rc-xbox-dvd.c
 create mode 100644 drivers/media/rc/xbox_remote.c


Re: [PATCH v4l-utils] Add missing linux/bpf_common.h

2018-11-06 Thread Sean Young
On Mon, Nov 05, 2018 at 09:30:47PM +0100, Peter Seiderer wrote:
> Copy from [1], needed by bpf.h.
> 
> [1] 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/bpf_common.h?h=v4.19

So bpf.h does include this file, but we don't use anything from it in
v4l-utils.

This include file is for the original BPF, which has been around for a
long time. So why is this include file missing, i.e. what problem are you
trying to solve?

Lastely, the file should be included in the sync-with-kernel target so
it does not get out of sync -- should it really be necessary to add the
file.


Sean

> 
> Signed-off-by: Peter Seiderer 
> ---
>  include/linux/bpf_common.h | 57 ++
>  1 file changed, 57 insertions(+)
>  create mode 100644 include/linux/bpf_common.h
> 
> diff --git a/include/linux/bpf_common.h b/include/linux/bpf_common.h
> new file mode 100644
> index ..ee97668b
> --- /dev/null
> +++ b/include/linux/bpf_common.h
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef _UAPI__LINUX_BPF_COMMON_H__
> +#define _UAPI__LINUX_BPF_COMMON_H__
> +
> +/* Instruction classes */
> +#define BPF_CLASS(code) ((code) & 0x07)
> +#define  BPF_LD  0x00
> +#define  BPF_LDX 0x01
> +#define  BPF_ST  0x02
> +#define  BPF_STX 0x03
> +#define  BPF_ALU 0x04
> +#define  BPF_JMP 0x05
> +#define  BPF_RET 0x06
> +#define  BPF_MISC0x07
> +
> +/* ld/ldx fields */
> +#define BPF_SIZE(code)  ((code) & 0x18)
> +#define  BPF_W   0x00 /* 32-bit */
> +#define  BPF_H   0x08 /* 16-bit */
> +#define  BPF_B   0x10 /*  8-bit */
> +/* eBPF  BPF_DW  0x1864-bit */
> +#define BPF_MODE(code)  ((code) & 0xe0)
> +#define  BPF_IMM 0x00
> +#define  BPF_ABS 0x20
> +#define  BPF_IND 0x40
> +#define  BPF_MEM 0x60
> +#define  BPF_LEN 0x80
> +#define  BPF_MSH 0xa0
> +
> +/* alu/jmp fields */
> +#define BPF_OP(code)((code) & 0xf0)
> +#define  BPF_ADD 0x00
> +#define  BPF_SUB 0x10
> +#define  BPF_MUL 0x20
> +#define  BPF_DIV 0x30
> +#define  BPF_OR  0x40
> +#define  BPF_AND 0x50
> +#define  BPF_LSH 0x60
> +#define  BPF_RSH 0x70
> +#define  BPF_NEG 0x80
> +#define  BPF_MOD 0x90
> +#define  BPF_XOR 0xa0
> +
> +#define  BPF_JA  0x00
> +#define  BPF_JEQ 0x10
> +#define  BPF_JGT 0x20
> +#define  BPF_JGE 0x30
> +#define  BPF_JSET0x40
> +#define BPF_SRC(code)   ((code) & 0x08)
> +#define  BPF_K   0x00
> +#define  BPF_X   0x08
> +
> +#ifndef BPF_MAXINSNS
> +#define BPF_MAXINSNS 4096
> +#endif
> +
> +#endif /* _UAPI__LINUX_BPF_COMMON_H__ */
> -- 
> 2.19.1


[PATCH] configure: build without BPF support in ir-keytable

2018-11-06 Thread Sean Young
It currently does not build on mips and some platforms do not have
BPF support yet (risc-v, for example).

Signed-off-by: Sean Young 
---
 configure.ac | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 387f8539..4100db06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -170,7 +170,14 @@ AC_SUBST([X11_CFLAGS])
 AC_SUBST([X11_LIBS])
 AM_CONDITIONAL([HAVE_X11], [test x$x11_pkgconfig = xyes])
 
-PKG_CHECK_MODULES([LIBELF], [libelf], [libelf_pkgconfig=yes], 
[libelf_pkgconfig=no])
+AC_ARG_WITH([bpf],
+AS_HELP_STRING([--without-bpf],
+  [Do not build with BPF IR decoder support]),
+[],
+[with_bpf=yes])
+
+AS_IF([test "x$with_bpf" != xno],
+  PKG_CHECK_MODULES([LIBELF], [libelf], [libelf_pkgconfig=yes], 
[libelf_pkgconfig=no]), [libelf_pkgconfig=no])
 AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
 AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
-- 
2.17.2



Re: [PATCH v2] Input: Add missing event codes for common IR remote buttons

2018-11-05 Thread Sean Young
On Sat, Nov 03, 2018 at 07:55:32AM -0700, Derek Kelly wrote:
> The following patch adds event codes for common buttons found on various
> provider and universal remote controls. They represent functions not
> covered by existing event codes. Once added, rc_keymaps can be updated
> accordingly where applicable.
> 
> v2 changes:
> Renamed KEY_SYSTEM to KEY_SYSTEM_MENU to avoid conflict with powerpc
> KEY_SYSTEM define.
> 
> Signed-off-by: Derek Kelly 

Reviewed-by: Sean Young 

There are many remotes with these buttons, this is a very useful addition.

Thanks,

Sean

> ---
>  include/uapi/linux/input-event-codes.h | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/uapi/linux/input-event-codes.h 
> b/include/uapi/linux/input-event-codes.h
> index 53fbae27b280..a15fd3c944d2 100644
> --- a/include/uapi/linux/input-event-codes.h
> +++ b/include/uapi/linux/input-event-codes.h
> @@ -689,6 +689,19 @@
>  #define BTN_TRIGGER_HAPPY39  0x2e6
>  #define BTN_TRIGGER_HAPPY40  0x2e7
>  
> +/* Remote control buttons found across provider & universal remotes */
> +#define KEY_LIVE_TV  0x2e8   /* Jump to live tv viewing */
> +#define KEY_OPTIONS  0x2e9   /* Jump to options */
> +#define KEY_INTERACTIVE  0x2ea   /* Jump to interactive 
> system/menu/item */
> +#define KEY_MIC_INPUT0x2eb   /* Trigger MIC 
> input/listen mode */
> +#define KEY_SCREEN_INPUT 0x2ec   /* Open on-screen input system 
> */
> +#define KEY_SYSTEM_MENU  0x2ed   /* Open systems 
> menu/display */
> +#define KEY_SERVICES 0x2ee   /* Access services */
> +#define KEY_DISPLAY_FORMAT   0x2ef   /* Cycle display formats */
> +#define KEY_PIP  0x2f0   /* Toggle 
> Picture-in-Picture on/off */
> +#define KEY_PIP_SWAP 0x2f1   /* Swap contents between main 
> view and PIP window */
> +#define KEY_PIP_POSITION 0x2f2   /* Cycle PIP window position */
> +
>  /* We avoid low common keys in module aliases so they don't get huge. */
>  #define KEY_MIN_INTERESTING  KEY_MUTE
>  #define KEY_MAX  0x2ff
> -- 
> 2.19.1


[PATCH] media: rc: ensure close() is called on rc_unregister_device

2018-11-05 Thread Sean Young
If userspace has an open file descriptor on the rc input device or lirc
device when rc_unregister_device() is called, then the rc close() is
never called.

This ensures that the receiver is turned off on the nuvoton-cir driver
during shutdown.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 552bbe82a160..8863da4204a3 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1950,6 +1950,8 @@ void rc_unregister_device(struct rc_dev *dev)
rc_free_rx_device(dev);
 
mutex_lock(>lock);
+   if (dev->users && dev->close)
+   dev->close(dev);
dev->registered = false;
mutex_unlock(>lock);
 
-- 
2.17.2



Re: [RFC] [PATCH] media: rc: Improve responsiveness of Xbox DVD Remote

2018-11-04 Thread Sean Young
On Sun, Nov 04, 2018 at 09:57:46PM +0100, Benjamin Valentin wrote:
> The Xbox DVD Remote feels somewhat sluggish, pressing a button
> repeatedly is sometimes interpreted as it being kept pressed down.
> 
> It seems like the RC subsystem is doing some incorrect heuristics when
> in fact the data that comes from the device is already pretty clean.
> 
> When looking at rc_keydown(), the timeout parameter for a keypress
> seems to be relevant here.
> 
> And indeed changing it from the default value of 12500 to something
> lower improves situation greatly.
> I'm not sure what the 'correct' value is here - even just setting it to
> 0 works fine and might even be the proper thing to do as the receiver
> dongle seems to do some filtering on it's own?

If a button is held down, then the remote will keep on repeating the same
message over and over again. When the button is released, then it stops
sending the message. We want to send the key up event when the button
is released, but not when held down. So, rc-core sets up up the keyup
timer for this, which is rearmed each a time an IR message is received.

There are two values involved here; one is how much time there is between
two IR messages when a key held down, this the protocol repeat period. This
is purely on IR protocol level.

The second is how long will it take (maximum) for the IR receiver to
deliver that message to rc-core, and that is the timeout you've modified
here. If the usb bus is highly contented there might some delay here
from one message to the next, for example. Or the IR receiver device might
do some of its own filtering.

So there is no protocol define for the xbox protocol, so we use
RC_PROTO_UNKNOWN for now. This has a default repeat period of 125ms. It
would be useful to know if this is wrong for this protocol. If it, we
should define a new protocol RC_PROTO_XBOX and give it the right
repeat period.

Using a raw IR receiver you measure this easily using:

ir-ctl -r -t 50

And then adding up all the pulse/spaces for each message, including the
long space between two IR messages.

For the IR receiver timeout, this is kind of hard to measure. raw IR
receivers tend to be worse here, because they rely on the IR timeout,
which is usually worse for the last IR message than any between IR messages.

Any IR receivers which do the the decoding themselves tend to deliver
the decoded scancode as soon as the final pulse is observed. A bit of
experimentation will suffice here.


Sean

> 
> ---
>  drivers/media/rc/xbox_remote.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/rc/xbox_remote.c b/drivers/media/rc/xbox_remote.c
> index 07ed9be24a60..496f1394216d 100644
> --- a/drivers/media/rc/xbox_remote.c
> +++ b/drivers/media/rc/xbox_remote.c
> @@ -157,6 +157,8 @@ static void xbox_remote_rc_init(struct xbox_remote 
> *xbox_remote)
>   rdev->device_name = xbox_remote->rc_name;
>   rdev->input_phys = xbox_remote->rc_phys;
>  
> + rdev->timeout = 1000;
> +
>   usb_to_input_id(xbox_remote->udev, >input_id);
>   rdev->dev.parent = _remote->interface->dev;
>  }


Re: [PATCH] media: rc: self test for IR encoders and decoders

2018-11-01 Thread Sean Young
Hi Shuah,

On Thu, Nov 01, 2018 at 08:59:39AM -0600, Shuah Khan wrote:
> On 10/16/2018 08:09 AM, Sean Young wrote:
> > ir-loopback can transmit IR on one rc device and check the correct
> > scancode and protocol is decoded on a different rc device. This can be
> > used to check IR transmission between two rc devices. Using rc-loopback,
> > we use it to check the IR encoders and decoders themselves.
> > 
> > No hardware is required for this test.
> > 
> > Signed-off-by: Sean Young 
> > Cc: Shuah Khan 
> 
> Hi Sean,
> 
> This looks good. I will get this into the next release. It will show
> up in linux-kselftest next after 4.20-rc1 comes out.

Great, thank you very much.

Regards,

Sean


Re: VIVID/VIMC and media fuzzing

2018-10-31 Thread Sean Young
On Wed, Oct 31, 2018 at 11:05:10AM +0100, Hans Verkuil wrote:
> CC-ing Sean Young: please see question at the end.
> 
> On 10/31/2018 10:46 AM, Hans Verkuil wrote:
> > On 10/30/2018 03:02 PM, Dmitry Vyukov wrote:
> >> Hello Helen and linux-media,
> >>
> >> I've attended your talk "Shifting Media App Development into High
> >> Gear" on OSS Summit last week and approached you with some questions
> >> if/how this can be used for kernel testing. Thanks, turn out to be a
> >> very useful talk!
> >>
> >> I am working on syzkaller/syzbot, continuous kernel fuzzing system:
> >> https://github.com/google/syzkaller
> >> https://github.com/google/syzkaller/blob/master/docs/syzbot.md
> >> https://syzkaller.appspot.com
> >>
> >> After simply enabling CONFIG_VIDEO_VIMC, CONFIG_VIDEO_VIM2M,
> >> CONFIG_VIDEO_VIVID, CONFIG_VIDEO_VICODEC syzbot has found 8 bugs in
> >> media subsystem in just 24 hours:
> >>
> >> KASAN: use-after-free Read in vb2_mmap
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/XGGH69jMWQ0/S8vfxgEmCgAJ
> >>
> >> KASAN: use-after-free Write in __vb2_cleanup_fileio
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/qKKhsZVPo3o/P6AB2of2CQAJ
> >>
> >> WARNING in __vb2_queue_cancel
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/S29GU_NtfPY/ZvAz8UDtCQAJ
> >>
> >> divide error in vivid_vid_cap_s_dv_timings
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/GwF5zGBCfyg/wnuWmW_sCQAJ
> > 
> > Should be fixed by https://patchwork.linuxtv.org/patch/52641/
> > 
> >>
> >> KASAN: use-after-free Read in wake_up_if_idle
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/aBWb_yV1kiI/sWQO63fkCQAJ
> >>
> >> KASAN: use-after-free Read in __vb2_perform_fileio
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/MdFCZHz0LUQ/qSK_bFbcCQAJ
> >>
> >> INFO: task hung in vivid_stop_generating_vid_cap
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/F_KFW6PVyTA/wTBeHLfTCQAJ
> >>
> >> KASAN: null-ptr-deref Write in kthread_stop
> >> https://groups.google.com/forum/#!msg/syzkaller-bugs/u0AGnYvSlf4/fUiyfA_TCQAJ
> > 
> > These last two should be fixed by https://patchwork.linuxtv.org/patch/52640/
> > 
> > Haven't figured out the others yet (hope to get back to that next week).
> > 
> >>
> >> Based on this I think if we put more effort into media fuzzing, it
> >> will be able to find dozens more.
> > 
> > Yeah, this is good stuff. Thank you for setting this up.
> > 
> >>
> >> syzkaller needs descriptions of kernel interfaces to efficiently cover
> >> a subsystem. For example, see:
> >> https://github.com/google/syzkaller/blob/master/sys/linux/uinput.txt
> >> Hopefully you can read it without much explanation, it basically
> >> states that there is that node in /dev and here are ioctls and other
> >> syscalls that are relevant for this device and here are types of
> >> arguments and layout of involved data structures.
> >>
> >> Turned we actually have such descriptions for /dev/video* and 
> >> /dev/v4l-subdev*:
> >> https://github.com/google/syzkaller/blob/master/sys/linux/video4linux.txt
> >> But we don't have anything for /dev/media*, fuzzer merely knows that
> >> it can open the device:
> >> https://github.com/google/syzkaller/blob/12b38f22c18c6109a5cc1c0238d015eef121b9b7/sys/linux/sys.txt#L479
> >> and then it will just blindly execute completely random workload on
> >> it, e.g. most likely it won't be able to come up with a proper complex
> >> structure layout for some ioctls. And I am actually not completely
> >> sure about completeness and coverage of video4linux.txt descriptions
> >> too as they were contributed by somebody interested in android
> >> testing.
> > 
> > A quick look suggests that it is based on the 4.9 videodev2.h, which ain't
> > too bad. There are some differences between the 4.20 videodev2.h and the
> > 4.9, but not too many.
> > 
> >>
> >> I wonder if somebody knowledgeable in /dev/media interface be willing
> >> to contribute additional descriptions?
> > 
> > We'll have to wait for 4.20-rc1 to be released since there are important
> > additions to the media API. I can probably come up with something, I'm
> > just not sure when I get around to it. Ping me in three weeks time if you
> > haven't heard from me.
> 
> W

Re: [PATCH] lirc.4: remove ioctls and feature bits which were never implemented

2018-10-29 Thread Sean Young
Hi Michael,

On Thu, Jul 12, 2018 at 02:21:18PM +0100, Sean Young wrote:
> On Thu, Jul 12, 2018 at 09:33:32AM -0300, Mauro Carvalho Chehab wrote:
> > Hi Michael/Alec,
> > 
> > Em Fri, 18 May 2018 16:25:29 +0100
> > Sean Young  escreveu:
> > 
> > > On Sun, May 06, 2018 at 12:34:53PM +0200, Michael Kerrisk (man-opages) 
> > > wrote:
> > > > [CCing original author of this page]
> > > > 
> > > > 
> > > > On 04/23/2018 12:26 PM, Sean Young wrote:  
> > > > > The lirc header file included ioctls and feature bits which were never
> > > > > implemented by any driver. They were removed in commit:
> > > > > 
> > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d55f09abe24b4dfadab246b6f217da547361cdb6
> > > > >   
> > > > 
> > > > Alec, does this patch look okay to you? 
> > 
> > Sean is the sub-maintainer responsible for the LIRC code at the
> > media subsystem. He knows more about the current implementation
> > than anyone else, as he's working hard to improve it, and got
> > rid of all legacy LIRC drivers from staging (either fixing them
> > or removing the few ones nobody uses anymore).
> > 
> > As part of his work, some ioctls got removed, in order to make
> > the LIRC interface to match the real implementation.
> >  
> > > Mauro, as Alec is not responding, would you be able to sign this off?
> > 
> > Most of the patch looks ok on my eyes. I noticed that some flags
> > still exists at include/uapi/linux/lirc.h:
> > 
> > LIRC_CAN_REC_RAW, LIRC_CAN_REC_PULSE, LIRC_CAN_SET_REC_FILTER
> > and LIRC_CAN_SEND_MODE2
> > 
> > Maybe instead of just removing, you would need to add some
> > explanation about them (or at the patch itself, explaining
> > why you're removing the descriptions for them).
> 
> Those flags do still exist in the header file, we decided to keep them
> so that code does not suddenly fail to build. These flags either never
> had implementations or only had out-of-tree implementations. So, I do
> not think they belong in the man page.
> 
> > > Alternatively, what can be done to progress this?
> > > 
> > > There is some new functionality in lirc which should be added to this man
> > > page too, so I have more to come (when I get round to writing it).
> > 
> > Yeah, making it reflect upstream sounds the right thing to do.
> 
> Absolutely, when kernel v4.18 is released there is more to add.

Ping, can this patch be merged please?

The lirc.4 man page is really out of date and misleading in parts. 


Sean


[PATCH] media: saa7134: hvr1110 can decode rc6

2018-10-28 Thread Sean Young
The function get_key_hvr1110 can only decode rc5, however this is a
standard hauppauge z8f0811 which can decode rc6 as well. Use
get_key_haup_xvr() instead.

Test on a HVR 1110.

Signed-off-by: Sean Young 
---
 drivers/media/pci/saa7134/saa7134-input.c | 43 +++
 1 file changed, 4 insertions(+), 39 deletions(-)

diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index 6e6d68964017..bc1ed7798d21 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -299,43 +299,6 @@ static int get_key_purpletv(struct IR_i2c *ir, enum 
rc_proto *protocol,
return 1;
 }
 
-static int get_key_hvr1110(struct IR_i2c *ir, enum rc_proto *protocol,
-  u32 *scancode, u8 *toggle)
-{
-   int rc;
-   unsigned char buf[5];
-
-   /* poll IR chip */
-   rc = i2c_master_recv(ir->c, buf, 5);
-   if (rc != 5) {
-   ir_dbg(ir, "read error\n");
-   if (rc < 0)
-   return rc;
-   return -EIO;
-   }
-
-   /* Check if some key were pressed */
-   if (!(buf[0] & 0x80))
-   return 0;
-
-   /*
-* buf[3] & 0x80 is always high.
-* buf[3] & 0x40 is a parity bit. A repeat event is marked
-* by preserving it into two separate readings
-* buf[4] bits 0 and 1, and buf[1] and buf[2] are always
-* zero.
-*
-* Note that the keymap which the hvr1110 uses is RC5.
-*
-* FIXME: start bits could maybe be used...?
-*/
-   *protocol = RC_PROTO_RC5;
-   *scancode = RC_SCANCODE_RC5(buf[3] & 0x1f, buf[4] >> 2);
-   *toggle = !!(buf[3] & 0x40);
-   return 1;
-}
-
-
 static int get_key_beholdm6xx(struct IR_i2c *ir, enum rc_proto *protocol,
  u32 *scancode, u8 *toggle)
 {
@@ -1029,9 +992,11 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
(1 == rc) ? "yes" : "no");
break;
case SAA7134_BOARD_HAUPPAUGE_HVR1110:
-   dev->init_data.name = "HVR 1110";
-   dev->init_data.get_key = get_key_hvr1110;
+   dev->init_data.name = saa7134_boards[dev->board].name;
dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
+   dev->init_data.type = RC_PROTO_BIT_RC5 |
+   RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32;
+   dev->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
info.addr = 0x71;
break;
case SAA7134_BOARD_BEHOLD_607FM_MK3:
-- 
2.17.2



[PATCH] media: saa7134: rc device does not need 'saa7134 IR (' prefix

2018-10-27 Thread Sean Young
Before this patch, the rc name is truncated to:

saa7134 IR (Hauppauge WinTV-HVR

Now it is:

Hauppauge WinTV-HVR1150 ATSC/QAM-Hybrid

Signed-off-by: Sean Young 
---
 drivers/media/pci/saa7134/saa7134-input.c | 4 +---
 drivers/media/pci/saa7134/saa7134.h   | 1 -
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index 999b2774b220..6e6d68964017 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -880,8 +880,6 @@ int saa7134_input_init1(struct saa7134_dev *dev)
ir->raw_decode   = raw_decode;
 
/* init input device */
-   snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
-saa7134_boards[dev->board].name);
snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
 pci_name(dev->pci));
 
@@ -893,7 +891,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
}
 
-   rc->device_name = ir->name;
+   rc->device_name = saa7134_boards[dev->board].name;
rc->input_phys = ir->phys;
rc->input_id.bustype = BUS_PCI;
rc->input_id.version = 1;
diff --git a/drivers/media/pci/saa7134/saa7134.h 
b/drivers/media/pci/saa7134/saa7134.h
index 480228456014..1c3f273f7dd2 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -123,7 +123,6 @@ struct saa7134_format {
 struct saa7134_card_ir {
struct rc_dev   *dev;
 
-   charname[32];
charphys[32];
unsignedusers;
 
-- 
2.17.2



[PATCH] media: v4l uapi docs: few minor corrections and typos

2018-10-26 Thread Sean Young
Signed-off-by: Sean Young 
---
 Documentation/media/uapi/v4l/app-pri.rst  |  2 +-
 Documentation/media/uapi/v4l/audio.rst|  2 +-
 Documentation/media/uapi/v4l/dev-capture.rst  |  2 +-
 Documentation/media/uapi/v4l/dev-teletext.rst |  2 +-
 Documentation/media/uapi/v4l/format.rst   |  2 +-
 Documentation/media/uapi/v4l/mmap.rst | 22 +--
 Documentation/media/uapi/v4l/open.rst |  2 +-
 Documentation/media/uapi/v4l/tuner.rst|  4 ++--
 Documentation/media/uapi/v4l/userp.rst|  8 +++
 Documentation/media/uapi/v4l/video.rst|  4 ++--
 10 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/Documentation/media/uapi/v4l/app-pri.rst 
b/Documentation/media/uapi/v4l/app-pri.rst
index a8c41a7ec396..e03929ebe899 100644
--- a/Documentation/media/uapi/v4l/app-pri.rst
+++ b/Documentation/media/uapi/v4l/app-pri.rst
@@ -8,7 +8,7 @@ Application Priority
 
 When multiple applications share a device it may be desirable to assign
 them different priorities. Contrary to the traditional "rm -rf /" school
-of thought a video recording application could for example block other
+of thought, a video recording application could for example block other
 applications from changing video controls or switching the current TV
 channel. Another objective is to permit low priority applications
 working in background, which can be preempted by user controlled
diff --git a/Documentation/media/uapi/v4l/audio.rst 
b/Documentation/media/uapi/v4l/audio.rst
index 5ec99a2809fe..725a61b59cb1 100644
--- a/Documentation/media/uapi/v4l/audio.rst
+++ b/Documentation/media/uapi/v4l/audio.rst
@@ -31,7 +31,7 @@ outputs applications can enumerate them with the
 :ref:`VIDIOC_ENUMAUDOUT ` ioctl, respectively.
 The struct :c:type:`v4l2_audio` returned by the
 :ref:`VIDIOC_ENUMAUDIO` ioctl also contains signal
-:status information applicable when the current audio input is queried.
+status information applicable when the current audio input is queried.
 
 The :ref:`VIDIOC_G_AUDIO ` and
 :ref:`VIDIOC_G_AUDOUT ` ioctls report the current
diff --git a/Documentation/media/uapi/v4l/dev-capture.rst 
b/Documentation/media/uapi/v4l/dev-capture.rst
index 4218742ab5d9..09949ac54be4 100644
--- a/Documentation/media/uapi/v4l/dev-capture.rst
+++ b/Documentation/media/uapi/v4l/dev-capture.rst
@@ -99,6 +99,6 @@ requests and always returns default parameters as 
:ref:`VIDIOC_G_FMT `
+A video capture device may support the :ref:`read() function `
 and/or streaming (:ref:`memory mapping ` or
 :ref:`user pointer `) I/O. See :ref:`io` for details.
diff --git a/Documentation/media/uapi/v4l/dev-teletext.rst 
b/Documentation/media/uapi/v4l/dev-teletext.rst
index 2648f6b37ea3..436c7393759a 100644
--- a/Documentation/media/uapi/v4l/dev-teletext.rst
+++ b/Documentation/media/uapi/v4l/dev-teletext.rst
@@ -10,7 +10,7 @@ This interface was aimed at devices receiving and 
demodulating Teletext
 data [:ref:`ets300706`, :ref:`itu653`], evaluating the Teletext
 packages and storing formatted pages in cache memory. Such devices are
 usually implemented as microcontrollers with serial interface
-(I:sup:`2`\ C) and could be found on old TV cards, dedicated Teletext
+(I\ :sup:`2`\ C) and could be found on old TV cards, dedicated Teletext
 decoding cards and home-brew devices connected to the PC parallel port.
 
 The Teletext API was designed by Martin Buck. It was defined in the
diff --git a/Documentation/media/uapi/v4l/format.rst 
b/Documentation/media/uapi/v4l/format.rst
index 3e3efb0e349e..dc8ccd8bf982 100644
--- a/Documentation/media/uapi/v4l/format.rst
+++ b/Documentation/media/uapi/v4l/format.rst
@@ -12,7 +12,7 @@ Data Format Negotiation
 
 Different devices exchange different kinds of data with applications,
 for example video images, raw or sliced VBI data, RDS datagrams. Even
-within one kind many different formats are possible, in particular an
+within one kind many different formats are possible, in particular there is an
 abundance of image formats. Although drivers must provide a default and
 the selection persists across closing and reopening a device,
 applications should always negotiate a data format before engaging in
diff --git a/Documentation/media/uapi/v4l/mmap.rst 
b/Documentation/media/uapi/v4l/mmap.rst
index 670596c1a4f7..0f0968799e69 100644
--- a/Documentation/media/uapi/v4l/mmap.rst
+++ b/Documentation/media/uapi/v4l/mmap.rst
@@ -231,17 +231,17 @@ up the output is started with :ref:`VIDIOC_STREAMON 
`.
 In the write loop, when the application runs out of free buffers, it
 must wait until an empty buffer can be dequeued and reused.
 
-To enqueue and dequeue a buffer applications use the :ref:`VIDIOC_QBUF`
-and :ref:`VIDIOC_DQBUF ` ioctl. The status of a buffer
-being mapped, enqueued, full or empty can be determined at any time
-using the :ref:`VIDIOC_QUERYBUF` ioctl. Two methods exist to suspend
-execution of the application until one or more buffers can be dequeued.
-By de

Re: [PATCH] media: rc: cec devices do not have a lirc chardev

2018-10-22 Thread Sean Young
On Mon, Oct 22, 2018 at 01:28:42PM +0100, Sean Young wrote:
> On Mon, Oct 22, 2018 at 12:30:29PM +0100, Hans Verkuil wrote:
> > On 10/22/2018 11:14 AM, Sean Young wrote:
> > > Would you be able to test the following patch please?
> > 
> > Sean,
> > 
> > I think you should be able to test this with the vivid driver. Load the 
> > vivid driver,
> > run:
> > 
> > cec-ctl --tv; cec-ctl -d1 --playback
> > 
> > Then:
> > 
> > cec-ctl -d1 -t0 --user-control-pressed ui-cmd=F5
> 
> Ah, thanks. That will help with testing/reproducing.
>  
> > That said, I tried this, but it doesn't crash for me, but perhaps I need to 
> > run
> > some RC command first...
> 
> Hmm I think those commands should be enough. It probably needs
> CONFIG_DEBUG_SPINLOCK to detect the uninitialized spinlock. I'm trying it now.

Yes, that turned out to work. With CONFIG_DEBUG_SPINLOCK on, it goes bang
every time. With the patch, the problem goes away.

Without CONFIG_DEBUG_SPINLOCK we're going into undefined behaviour, so 
Torbjorn you're only seeing the oops occassionally (and which is why it has
not been observed or reported before).

Thanks,

Sean


Re: [PATCH] media: rc: cec devices do not have a lirc chardev

2018-10-22 Thread Sean Young
On Mon, Oct 22, 2018 at 12:30:29PM +0100, Hans Verkuil wrote:
> On 10/22/2018 11:14 AM, Sean Young wrote:
> > On Mon, Oct 22, 2018 at 11:44:22AM +0200, Torbjorn Jansson wrote:
> >> On 2018-10-22 10:59, Sean Young wrote:
> >>> On Sat, Oct 20, 2018 at 11:12:16PM +0200, Hans Verkuil wrote:
> >>>> Hi Sean,
> >>>>
> >>>> Can you take a look at this, it appears to be an RC issue, see my 
> >>>> analysis below.
> >>>>
> >>>> On 10/20/2018 03:26 PM, Torbjorn Jansson wrote:
> >>>>> Hello
> >>>>>
> >>>>> i'm using the pulse8 usb cec adapter to control my tv.
> >>>>> i have a few scripts that poll the power status of my tv and after a 
> >>>>> while it stops working returning errors when trying to check if tv is 
> >>>>> on or off.
> >>>>> this i think matches a kernel oops i'm seeing that i suspect is related 
> >>>>> to this.
> >>>>>
> >>>>> i have sometimes been able to recover from this problem by completely 
> >>>>> cutting power to my tv and also unplugging the usb cec adapter.
> >>>>> i have a feeling that the tv is at least partly to blame for cec-ctl 
> >>>>> not working but in any case there shouldn't be a kernel oops.
> >>>>>
> >>>>>
> >>>>> also every now and then i see this in dmesg:
> >>>>> cec cec0: transmit: failed 05
> >>>>> cec cec0: transmit: failed 06
> >>>>> but that doesn't appear to do any harm as far as i can tell.
> >>>>>
> >>>>> any idea whats causing the oops?
> >>>>>
> >>>>> the ops:
> >>>>>
> >>>>> BUG: unable to handle kernel NULL pointer dereference at 
> >>>>> 0038
> >>>>> PGD 0 P4D 0
> >>>>> Oops:  [#1] SMP PTI
> >>>>> CPU: 9 PID: 27687 Comm: kworker/9:2 Tainted: P   OE 
> >>>>> 4.18.12-200.fc28.x86_64 #1
> >>>>> Hardware name: Supermicro C7X99-OCE-F/C7X99-OCE-F, BIOS 2.1a 06/15/2018
> >>>>> Workqueue: events pulse8_irq_work_handler [pulse8_cec]
> >>>>> RIP: 0010:ir_lirc_scancode_event+0x3d/0xb0 [rc_core]
> >>>>
> >>>> Huh. ir_lirc_scancode_event() calls 
> >>>> spin_lock_irqsave(>lirc_fh_lock, flags);
> >>>>
> >>>> The spinlock dev->lirc_fh_lock is initialized in ir_lirc_register(), 
> >>>> which is called
> >>>> from rc_register_device(), except when the protocol is CEC:
> >>>>
> >>>>  /* Ensure that the lirc kfifo is setup before we start the 
> >>>> thread */
> >>>>  if (dev->allowed_protocols != RC_PROTO_BIT_CEC) {
> >>>>  rc = ir_lirc_register(dev);
> >>>>  if (rc < 0)
> >>>>  goto out_rx;
> >>>>  }
> >>>>
> >>>> So it looks like ir_lirc_scancode_event() fails because 
> >>>> dev->lirc_fh_lock was never
> >>>> initialized.
> >>>>
> >>>> Could this be fall-out from the lirc changes you did not too long ago?
> >>>
> >>> Yes, this is broken. My bad, sorry. I think this must have been broken 
> >>> since
> >>> v4.16. I can write a patch but I don't have a patch but I'm on the train
> >>> to ELCE in Edinburgh now, with no hardware to test on.
> >>>
> >>>
> >>> Sean
> >>>
> >>
> >> the kernel oops have been happening for a while now.
> >> yesterday when i checked my logs i can see them at least back a couple of
> >> months when i was running 4.17
> >>
> >> also my scripts to poll status of my tv and turn it on/off works for a 
> >> while
> >> so it doesn't crash right away.
> >> maybe it only crashes when i send cec command to turn on/off tv and only
> >> polling for status is no problem.
> >>
> >>
> >> i think i have a separate issue too because i had problems even before the
> >> kernel oopses started.
> >> but i suspect this is caused by my tv locking up the cec bus because
> >> unplugging power to tv for a few minutes (i must wait or it will still be
> >> just as broken) and then back used to resolve the cec errors from my
> >> scripts.
> > 
> > 
> > Would you be able to test the following patch please?
> 
> Sean,
> 
> I think you should be able to test this with the vivid driver. Load the vivid 
> driver,
> run:
> 
> cec-ctl --tv; cec-ctl -d1 --playback
> 
> Then:
> 
> cec-ctl -d1 -t0 --user-control-pressed ui-cmd=F5

Ah, thanks. That will help with testing/reproducing.
 
> That said, I tried this, but it doesn't crash for me, but perhaps I need to 
> run
> some RC command first...

Hmm I think those commands should be enough. It probably needs
CONFIG_DEBUG_SPINLOCK to detect the uninitialized spinlock. I'm trying it now.

Thanks,

Sean


[PATCH] media: rc: cec devices do not have a lirc chardev

2018-10-22 Thread Sean Young
On Mon, Oct 22, 2018 at 11:44:22AM +0200, Torbjorn Jansson wrote:
> On 2018-10-22 10:59, Sean Young wrote:
> > On Sat, Oct 20, 2018 at 11:12:16PM +0200, Hans Verkuil wrote:
> > > Hi Sean,
> > > 
> > > Can you take a look at this, it appears to be an RC issue, see my 
> > > analysis below.
> > > 
> > > On 10/20/2018 03:26 PM, Torbjorn Jansson wrote:
> > > > Hello
> > > > 
> > > > i'm using the pulse8 usb cec adapter to control my tv.
> > > > i have a few scripts that poll the power status of my tv and after a 
> > > > while it stops working returning errors when trying to check if tv is 
> > > > on or off.
> > > > this i think matches a kernel oops i'm seeing that i suspect is related 
> > > > to this.
> > > > 
> > > > i have sometimes been able to recover from this problem by completely 
> > > > cutting power to my tv and also unplugging the usb cec adapter.
> > > > i have a feeling that the tv is at least partly to blame for cec-ctl 
> > > > not working but in any case there shouldn't be a kernel oops.
> > > > 
> > > > 
> > > > also every now and then i see this in dmesg:
> > > > cec cec0: transmit: failed 05
> > > > cec cec0: transmit: failed 06
> > > > but that doesn't appear to do any harm as far as i can tell.
> > > > 
> > > > any idea whats causing the oops?
> > > > 
> > > > the ops:
> > > > 
> > > > BUG: unable to handle kernel NULL pointer dereference at 
> > > > 0038
> > > > PGD 0 P4D 0
> > > > Oops:  [#1] SMP PTI
> > > > CPU: 9 PID: 27687 Comm: kworker/9:2 Tainted: P   OE 
> > > > 4.18.12-200.fc28.x86_64 #1
> > > > Hardware name: Supermicro C7X99-OCE-F/C7X99-OCE-F, BIOS 2.1a 06/15/2018
> > > > Workqueue: events pulse8_irq_work_handler [pulse8_cec]
> > > > RIP: 0010:ir_lirc_scancode_event+0x3d/0xb0 [rc_core]
> > > 
> > > Huh. ir_lirc_scancode_event() calls spin_lock_irqsave(>lirc_fh_lock, 
> > > flags);
> > > 
> > > The spinlock dev->lirc_fh_lock is initialized in ir_lirc_register(), 
> > > which is called
> > > from rc_register_device(), except when the protocol is CEC:
> > > 
> > >  /* Ensure that the lirc kfifo is setup before we start the 
> > > thread */
> > >  if (dev->allowed_protocols != RC_PROTO_BIT_CEC) {
> > >  rc = ir_lirc_register(dev);
> > >  if (rc < 0)
> > >  goto out_rx;
> > >  }
> > > 
> > > So it looks like ir_lirc_scancode_event() fails because dev->lirc_fh_lock 
> > > was never
> > > initialized.
> > > 
> > > Could this be fall-out from the lirc changes you did not too long ago?
> > 
> > Yes, this is broken. My bad, sorry. I think this must have been broken since
> > v4.16. I can write a patch but I don't have a patch but I'm on the train
> > to ELCE in Edinburgh now, with no hardware to test on.
> > 
> > 
> > Sean
> > 
> 
> the kernel oops have been happening for a while now.
> yesterday when i checked my logs i can see them at least back a couple of
> months when i was running 4.17
> 
> also my scripts to poll status of my tv and turn it on/off works for a while
> so it doesn't crash right away.
> maybe it only crashes when i send cec command to turn on/off tv and only
> polling for status is no problem.
> 
> 
> i think i have a separate issue too because i had problems even before the
> kernel oopses started.
> but i suspect this is caused by my tv locking up the cec bus because
> unplugging power to tv for a few minutes (i must wait or it will still be
> just as broken) and then back used to resolve the cec errors from my
> scripts.


Would you be able to test the following patch please?

Thanks,

Sean
---
>From 1b8b20b606b30c0e301c80e18af8d77194269bc1 Mon Sep 17 00:00:00 2001
From: Sean Young 
Date: Mon, 22 Oct 2018 10:01:50 +0100
Subject: [PATCH] media: rc: cec devices do not have a lirc chardev
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes an oops in ir_lirc_scancode_event().

BUG: unable to handle kernel NULL pointer dereference at 0038
PGD 0 P4D 0
Oops:  [#1] SMP PTI
CPU: 9 PID: 27687 Comm: kworker/9:2 Tainted: P   OE 
4.18.12-200.fc28.x86_64 #1
Hardware name: Supermicro C7X99-OCE-F/C7X99-OCE-F, BIOS 2.1a 06/15/2018
Workqueue: events

Re: cec kernel oops with pulse8 usb cec adapter

2018-10-22 Thread Sean Young
On Sat, Oct 20, 2018 at 11:12:16PM +0200, Hans Verkuil wrote:
> Hi Sean,
> 
> Can you take a look at this, it appears to be an RC issue, see my analysis 
> below.
> 
> On 10/20/2018 03:26 PM, Torbjorn Jansson wrote:
> > Hello
> > 
> > i'm using the pulse8 usb cec adapter to control my tv.
> > i have a few scripts that poll the power status of my tv and after a while 
> > it stops working returning errors when trying to check if tv is on or off.
> > this i think matches a kernel oops i'm seeing that i suspect is related to 
> > this.
> > 
> > i have sometimes been able to recover from this problem by completely 
> > cutting power to my tv and also unplugging the usb cec adapter.
> > i have a feeling that the tv is at least partly to blame for cec-ctl not 
> > working but in any case there shouldn't be a kernel oops.
> > 
> > 
> > also every now and then i see this in dmesg:
> > cec cec0: transmit: failed 05
> > cec cec0: transmit: failed 06
> > but that doesn't appear to do any harm as far as i can tell.
> > 
> > any idea whats causing the oops?
> > 
> > the ops:
> > 
> > BUG: unable to handle kernel NULL pointer dereference at 0038
> > PGD 0 P4D 0
> > Oops:  [#1] SMP PTI
> > CPU: 9 PID: 27687 Comm: kworker/9:2 Tainted: P   OE 
> > 4.18.12-200.fc28.x86_64 #1
> > Hardware name: Supermicro C7X99-OCE-F/C7X99-OCE-F, BIOS 2.1a 06/15/2018
> > Workqueue: events pulse8_irq_work_handler [pulse8_cec]
> > RIP: 0010:ir_lirc_scancode_event+0x3d/0xb0 [rc_core]
> 
> Huh. ir_lirc_scancode_event() calls spin_lock_irqsave(>lirc_fh_lock, 
> flags);
> 
> The spinlock dev->lirc_fh_lock is initialized in ir_lirc_register(), which is 
> called
> from rc_register_device(), except when the protocol is CEC:
> 
> /* Ensure that the lirc kfifo is setup before we start the thread */
> if (dev->allowed_protocols != RC_PROTO_BIT_CEC) {
> rc = ir_lirc_register(dev);
> if (rc < 0)
> goto out_rx;
> }
> 
> So it looks like ir_lirc_scancode_event() fails because dev->lirc_fh_lock was 
> never
> initialized.
> 
> Could this be fall-out from the lirc changes you did not too long ago?

Yes, this is broken. My bad, sorry. I think this must have been broken since
v4.16. I can write a patch but I don't have a patch but I'm on the train
to ELCE in Edinburgh now, with no hardware to test on.


Sean


[PATCH] media: rc: imon_raw: use fls rather than loop per bit

2018-10-18 Thread Sean Young
Previously, the code would loop for each of the 40 bits. Now it will
branch for each edge in the IR, which will be much less.

Signed-off-by: Sean Young 
---
 drivers/media/rc/imon_raw.c | 47 ++---
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/drivers/media/rc/imon_raw.c b/drivers/media/rc/imon_raw.c
index 7796098d9c30..25e56c5b13c0 100644
--- a/drivers/media/rc/imon_raw.c
+++ b/drivers/media/rc/imon_raw.c
@@ -14,51 +14,50 @@ struct imon {
struct device *dev;
struct urb *ir_urb;
struct rc_dev *rcdev;
-   u8 ir_buf[8];
+   u8 ir_buf[8] __aligned(__alignof__(u64));
char phys[64];
 };
 
 /*
- * ffs/find_next_bit() searches in the wrong direction, so open-code our own.
+ * The first 5 bytes of data represent IR pulse or space. Each bit, starting
+ * from highest bit in the first byte, represents 250µs of data. It is 1
+ * for space and 0 for pulse.
+ *
+ * The station sends 10 packets, and the 7th byte will be number 1 to 10, so
+ * when we receive 10 we assume all the data has arrived.
  */
-static inline int is_bit_set(const u8 *buf, int bit)
-{
-   return buf[bit / 8] & (0x80 >> (bit & 7));
-}
-
 static void imon_ir_data(struct imon *imon)
 {
struct ir_raw_event rawir = {};
-   int offset = 0, size = 5 * 8;
+   u64 d = be64_to_cpup((__be64 *)imon->ir_buf) >> 24;
+   int offset = 40;
int bit;
 
dev_dbg(imon->dev, "data: %*ph", 8, imon->ir_buf);
 
-   while (offset < size) {
-   bit = offset;
-   while (!is_bit_set(imon->ir_buf, bit) && bit < size)
-   bit++;
-   dev_dbg(imon->dev, "pulse: %d bits", bit - offset);
-   if (bit > offset) {
+   do {
+   bit = fls64(d & (BIT_ULL(offset) - 1));
+   if (bit < offset) {
+   dev_dbg(imon->dev, "pulse: %d bits", offset - bit);
rawir.pulse = true;
-   rawir.duration = (bit - offset) * BIT_DURATION;
+   rawir.duration = (offset - bit) * BIT_DURATION;
ir_raw_event_store_with_filter(imon->rcdev, );
-   }
 
-   if (bit >= size)
-   break;
+   if (bit == 0)
+   break;
 
-   offset = bit;
-   while (is_bit_set(imon->ir_buf, bit) && bit < size)
-   bit++;
-   dev_dbg(imon->dev, "space: %d bits", bit - offset);
+   offset = bit;
+   }
+
+   bit = fls64(~d & (BIT_ULL(offset) - 1));
+   dev_dbg(imon->dev, "space: %d bits", offset - bit);
 
rawir.pulse = false;
-   rawir.duration = (bit - offset) * BIT_DURATION;
+   rawir.duration = (offset - bit) * BIT_DURATION;
ir_raw_event_store_with_filter(imon->rcdev, );
 
offset = bit;
-   }
+   } while (offset > 0);
 
if (imon->ir_buf[7] == 0x0a) {
ir_raw_event_set_idle(imon->rcdev, true);
-- 
2.17.2



[PATCH] media: rc: XBox DVD Remote uses 12 bits scancodes

2018-10-18 Thread Sean Young
The xbox dvd remote sends 24 bits, the first 12 bits are repeated
and inverted so only 12 bits are used. The upper 4 bits can be read
at offset 3. Ensure we pass this to rc-core and update the keymap
accordingly.

Signed-off-by: Sean Young 
---
 drivers/media/rc/keymaps/rc-xbox-dvd.c | 58 +-
 drivers/media/rc/xbox_remote.c |  7 ++--
 2 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/drivers/media/rc/keymaps/rc-xbox-dvd.c 
b/drivers/media/rc/keymaps/rc-xbox-dvd.c
index 61da6706715c..af387244636b 100644
--- a/drivers/media/rc/keymaps/rc-xbox-dvd.c
+++ b/drivers/media/rc/keymaps/rc-xbox-dvd.c
@@ -7,35 +7,35 @@
 
 /* based on lircd.conf.xbox */
 static struct rc_map_table xbox_dvd[] = {
-   {0x0b, KEY_OK},
-   {0xa6, KEY_UP},
-   {0xa7, KEY_DOWN},
-   {0xa8, KEY_RIGHT},
-   {0xa9, KEY_LEFT},
-   {0xc3, KEY_INFO},
-
-   {0xc6, KEY_9},
-   {0xc7, KEY_8},
-   {0xc8, KEY_7},
-   {0xc9, KEY_6},
-   {0xca, KEY_5},
-   {0xcb, KEY_4},
-   {0xcc, KEY_3},
-   {0xcd, KEY_2},
-   {0xce, KEY_1},
-   {0xcf, KEY_0},
-
-   {0xd5, KEY_ANGLE},
-   {0xd8, KEY_BACK},
-   {0xdd, KEY_PREVIOUSSONG},
-   {0xdf, KEY_NEXTSONG},
-   {0xe0, KEY_STOP},
-   {0xe2, KEY_REWIND},
-   {0xe3, KEY_FASTFORWARD},
-   {0xe5, KEY_TITLE},
-   {0xe6, KEY_PAUSE},
-   {0xea, KEY_PLAY},
-   {0xf7, KEY_MENU},
+   {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},
 };
 
 static struct rc_map_list xbox_dvd_map = {
diff --git a/drivers/media/rc/xbox_remote.c b/drivers/media/rc/xbox_remote.c
index 141ef9253018..4d41e31369d2 100644
--- a/drivers/media/rc/xbox_remote.c
+++ b/drivers/media/rc/xbox_remote.c
@@ -55,7 +55,7 @@ struct xbox_remote {
struct usb_interface *interface;
 
struct urb *irq_urb;
-   unsigned char inbuf[DATA_BUFSIZE];
+   unsigned char inbuf[DATA_BUFSIZE] __aligned(sizeof(u16));
 
char rc_name[NAME_BUFSIZE];
char rc_phys[NAME_BUFSIZE];
@@ -95,7 +95,7 @@ static void xbox_remote_input_report(struct urb *urb)
 * data[0] = 0x00
 * data[1] = length - always 0x06
 * data[2] = the key code
-* data[3] = high part of key code? - always 0x0a
+* data[3] = high part of key code
 * data[4] = last_press_ms (low)
 * data[5] = last_press_ms (high)
 */
@@ -107,7 +107,8 @@ static void xbox_remote_input_report(struct urb *urb)
return;
}
 
-   rc_keydown(xbox_remote->rdev, RC_PROTO_UNKNOWN, data[2], 0);
+   rc_keydown(xbox_remote->rdev, RC_PROTO_UNKNOWN,
+  le16_to_cpup((__le16*)(data + 2)), 0);
 }
 
 /*
-- 
2.17.2



[PATCH v4l-utils] keytable: bpf decoder and keymap for XBox DVD Remote

2018-10-18 Thread Sean Young
This uses a modified nec protocol, where 24 bits are sent and the first
12 bits are inverted.

Signed-off-by: Sean Young 
---
 utils/keytable/bpf_protocols/Makefile.am  |   2 +-
 utils/keytable/bpf_protocols/xbox.c   | 129 ++
 .../rc_keymaps_userspace/xbox_dvd.toml|  31 +
 3 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/bpf_protocols/xbox.c
 create mode 100644 utils/keytable/rc_keymaps_userspace/xbox_dvd.toml

diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
index 8887b897..2d005b1f 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 - &1 \
 %.o: %.c bpf_helpers.h
$(CLANG) $(CLANG_SYS_INCLUDES) -I$(top_srcdir)/include -target bpf -O2 
-c $<
 
-PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o
+PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o 
xbox.o
 
 all: $(PROTOCOLS)
 
diff --git a/utils/keytable/bpf_protocols/xbox.c 
b/utils/keytable/bpf_protocols/xbox.c
new file mode 100644
index ..e48e0a79
--- /dev/null
+++ b/utils/keytable/bpf_protocols/xbox.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Copyright (C) 2018 Sean Young 
+
+#include 
+#include 
+
+#include "bpf_helpers.h"
+
+enum state {
+   STATE_INACTIVE,
+   STATE_HEADER_SPACE,
+   STATE_BITS_SPACE,
+   STATE_BITS_PULSE,
+   STATE_TRAILER,
+};
+
+struct decoder_state {
+   unsigned long bits;
+   enum state state;
+   unsigned int count;
+};
+
+struct bpf_map_def SEC("maps") decoder_state_map = {
+   .type = BPF_MAP_TYPE_ARRAY,
+   .key_size = sizeof(unsigned int),
+   .value_size = sizeof(struct decoder_state),
+   .max_entries = 1,
+};
+
+// These values can be overridden in the rc_keymap toml
+//
+// We abuse elf relocations. We cast the address of these variables to
+// an int, so that the compiler emits a mov immediate for the address
+// but uses it as an int. The bpf loader replaces the relocation with the
+// actual value (either overridden or taken from the data segment).
+int margin = 200;
+int header_pulse = 4000;
+int header_space = 3900;
+int bit_pulse = 550;
+int bit_0_space = 900;
+int bit_1_space = 1900;
+int trailer_pulse = 550;
+int bits = 24;
+int rc_protocol = 68;
+
+#define BPF_PARAM(x) (int)(&(x))
+
+static inline int eq_margin(unsigned d1, unsigned d2)
+{
+   return ((d1 > (d2 - BPF_PARAM(margin))) && (d1 < (d2 + 
BPF_PARAM(margin;
+}
+
+SEC("xbox")
+int bpf_decoder(unsigned int *sample)
+{
+   unsigned int key = 0;
+   struct decoder_state *s = bpf_map_lookup_elem(_state_map, );
+
+   if (!s)
+   return 0;
+
+   switch (*sample & LIRC_MODE2_MASK) {
+   case LIRC_MODE2_SPACE:
+   case LIRC_MODE2_PULSE:
+   case LIRC_MODE2_TIMEOUT:
+   break;
+   default:
+   // not a timing events
+   return 0;
+   }
+
+   int duration = LIRC_VALUE(*sample);
+   int pulse = LIRC_IS_PULSE(*sample);
+
+   switch (s->state) {
+   case STATE_HEADER_SPACE:
+   if (!pulse && eq_margin(BPF_PARAM(header_space), duration))
+   s->state = STATE_BITS_PULSE;
+   else
+   s->state = STATE_INACTIVE;
+   break;
+   case STATE_INACTIVE:
+   if (pulse && eq_margin(BPF_PARAM(header_pulse), duration)) {
+   s->bits = 0;
+   s->state = STATE_HEADER_SPACE;
+   s->count = 0;
+   }
+   break;
+   case STATE_BITS_PULSE:
+   if (pulse && eq_margin(BPF_PARAM(bit_pulse), duration))
+   s->state = STATE_BITS_SPACE;
+   else
+   s->state = STATE_INACTIVE;
+   break;
+   case STATE_BITS_SPACE:
+   if (pulse) {
+   s->state = STATE_INACTIVE;
+   break;
+   }
+
+   s->bits <<= 1;
+
+   if (eq_margin(BPF_PARAM(bit_1_space), duration))
+   s->bits |= 1;
+   else if (!eq_margin(BPF_PARAM(bit_0_space), duration)) {
+   s->state = STATE_INACTIVE;
+   break;
+   }
+
+   s->count++;
+   if (s->count == BPF_PARAM(bits))
+   s->state = STATE_TRAILER;
+   else
+   s->state = STATE_BITS_PULSE;
+   break;
+   case STATE_TRAILER:
+   if (pulse && eq_margin(BPF_PARAM(trailer_pulse), duration)) {
+   if ((

[PATCH] media: rc: self test for IR encoders and decoders

2018-10-16 Thread Sean Young
ir-loopback can transmit IR on one rc device and check the correct
scancode and protocol is decoded on a different rc device. This can be
used to check IR transmission between two rc devices. Using rc-loopback,
we use it to check the IR encoders and decoders themselves.

No hardware is required for this test.

Signed-off-by: Sean Young 
Cc: Shuah Khan 
---
 tools/testing/selftests/Makefile  |   1 +
 tools/testing/selftests/ir/.gitignore |   1 +
 tools/testing/selftests/ir/Makefile   |   5 +
 tools/testing/selftests/ir/ir_loopback.c  | 199 ++
 tools/testing/selftests/ir/ir_loopback.sh |  20 +++
 5 files changed, 226 insertions(+)
 create mode 100644 tools/testing/selftests/ir/.gitignore
 create mode 100644 tools/testing/selftests/ir/Makefile
 create mode 100644 tools/testing/selftests/ir/ir_loopback.c
 create mode 100755 tools/testing/selftests/ir/ir_loopback.sh

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index f1fe492c8e17..995034ea5546 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += futex
 TARGETS += gpio
 TARGETS += intel_pstate
 TARGETS += ipc
+TARGETS += ir
 TARGETS += kcmp
 TARGETS += kvm
 TARGETS += lib
diff --git a/tools/testing/selftests/ir/.gitignore 
b/tools/testing/selftests/ir/.gitignore
new file mode 100644
index ..070ea0c75fb8
--- /dev/null
+++ b/tools/testing/selftests/ir/.gitignore
@@ -0,0 +1 @@
+ir_loopback
diff --git a/tools/testing/selftests/ir/Makefile 
b/tools/testing/selftests/ir/Makefile
new file mode 100644
index ..f4ba8eb84b95
--- /dev/null
+++ b/tools/testing/selftests/ir/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+TEST_PROGS := ir_loopback.sh
+TEST_GEN_PROGS_EXTENDED := ir_loopback
+
+include ../lib.mk
diff --git a/tools/testing/selftests/ir/ir_loopback.c 
b/tools/testing/selftests/ir/ir_loopback.c
new file mode 100644
index ..858c19caf224
--- /dev/null
+++ b/tools/testing/selftests/ir/ir_loopback.c
@@ -0,0 +1,199 @@
+// SPDX-License-Identifier: GPL-2.0
+// test ir decoder
+//
+// Copyright (C) 2018 Sean Young 
+
+// When sending LIRC_MODE_SCANCODE, the IR will be encoded. rc-loopback
+// will send this IR to the receiver side, where we try to read the decoded
+// IR. Decoding happens in a separate kernel thread, so we will need to
+// wait until that is scheduled, hence we use poll to check for read
+// readiness.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../kselftest.h"
+
+#define TEST_SCANCODES 10
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+static const struct {
+   enum rc_proto proto;
+   const char *name;
+   unsigned int mask;
+   const char *decoder;
+} protocols[] = {
+   { RC_PROTO_RC5, "rc-5", 0x1f7f, "rc-5" },
+   { RC_PROTO_RC5X_20, "rc-5x-20", 0x1f7f3f, "rc-5" },
+   { RC_PROTO_RC5_SZ, "rc-5-sz", 0x2fff, "rc-5-sz" },
+   { RC_PROTO_JVC, "jvc", 0x, "jvc" },
+   { RC_PROTO_SONY12, "sony-12", 0x1f007f, "sony" },
+   { RC_PROTO_SONY15, "sony-15", 0xff007f, "sony" },
+   { RC_PROTO_SONY20, "sony-20", 0x1fff7f, "sony" },
+   { RC_PROTO_NEC, "nec", 0x, "nec" },
+   { RC_PROTO_NECX, "nec-x", 0xff, "nec" },
+   { RC_PROTO_NEC32, "nec-32", 0x, "nec" },
+   { RC_PROTO_SANYO, "sanyo", 0x1f, "sanyo" },
+   { RC_PROTO_RC6_0, "rc-6-0", 0x, "rc-6" },
+   { RC_PROTO_RC6_6A_20, "rc-6-6a-20", 0xf, "rc-6" },
+   { RC_PROTO_RC6_6A_24, "rc-6-6a-24", 0xff, "rc-6" },
+   { RC_PROTO_RC6_6A_32, "rc-6-6a-32", 0x, "rc-6" },
+   { RC_PROTO_RC6_MCE, "rc-6-mce", 0x7fff, "rc-6" },
+   { RC_PROTO_SHARP, "sharp", 0x1fff, "sharp" },
+};
+
+int lirc_open(const char *rc)
+{
+   struct dirent *dent;
+   char buf[100];
+   DIR *d;
+   int fd;
+
+   snprintf(buf, sizeof(buf), "/sys/class/rc/%s", rc);
+
+   d = opendir(buf);
+   if (!d)
+   ksft_exit_fail_msg("cannot open %s: %m\n", buf);
+
+   while ((dent = readdir(d)) != NULL) {
+   if (!strncmp(dent->d_name, "lirc", 4)) {
+   snprintf(buf, sizeof(buf), "/dev/%s", dent->d_name);
+   break;
+   }
+   }
+
+   if (!dent)
+   ksft_exit_fail_msg("cannot find lirc device for %s\n", rc);
+
+   closedir(d);
+
+   fd = open(buf, O_RDWR | O_NONBLOCK);
+   if

Re: [PATCHv2] media: rc: add driver for Xbox DVD Movie Playback Kit

2018-10-08 Thread Sean Young
Hi Benjamin,

Thanks for your driver, I have some comments below.

On Thu, Oct 04, 2018 at 01:52:54PM +0200, Benjamin Valentin wrote:
> The Xbox DVD Movie Playback Kit is a USB dongle with an IR remote for the
> Original Xbox.
> 
> Historically it has been supported by the out-of-tree lirc_xbox driver,
> but this one has fallen out of favour and was just dropped from popular
> Kodi (formerly XBMC) distributions.
> 
> This driver is heaviely based on the ati_remote driver where all the
> boilerplate was taken from - I was mostly just removing code.
> 
> Signed-off-by: Benjamin Valentin 
> ---
> Changes since v1:
> 
> I discovered some more dead code leftover from the ati_remote driver.
> I also removed the open_mutex which I think is not needed here since
> this driver, unlike ati_remote, doesn't register both a rc and an input
> device.
> This also allowed me to collapse some functions.
> 
>  MAINTAINERS|   6 +
>  drivers/media/rc/Kconfig   |  11 +
>  drivers/media/rc/Makefile  |   1 +
>  drivers/media/rc/keymaps/Makefile  |   1 +
>  drivers/media/rc/keymaps/rc-xbox-dvd.c |  63 +
>  drivers/media/rc/xbox_remote.c | 342 +
>  include/media/rc-map.h |   1 +
>  7 files changed, 425 insertions(+)
>  create mode 100644 drivers/media/rc/keymaps/rc-xbox-dvd.c
>  create mode 100644 drivers/media/rc/xbox_remote.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 22065048d89d..712a51a1a955 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -15973,6 +15973,12 @@ T:   git 
> git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/vdso
>  S:   Maintained
>  F:   arch/x86/entry/vdso/
>  
> +XBOX DVD IR REMOTE
> +M:   Benjamin Valentin 
> +S:   Maintained
> +F:   drivers/media/rc/xbox_remote.c
> +F:   drivers/media/rc/keymaps/rc-xbox-dvd.c
> +
>  XC2028/3028 TUNER DRIVER
>  M:   Mauro Carvalho Chehab 
>  L:   linux-media@vger.kernel.org
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 1021c08a9ba4..05489294ebbc 100644
> --- a/drivers/media/rc/Kconfig
> +++ b/drivers/media/rc/Kconfig
> @@ -493,6 +493,17 @@ config IR_TANGO
>  The HW decoder supports NEC, RC-5, RC-6 IR protocols.
>  When compiled as a module, look for tango-ir.
>  
> +config CONFIG_RC_XBOX_DVD

The config option should not include the leading CONFIG_ in Kconfig,
so this is broken.

> + tristate "Xbox DVD Movie Playback Kit"
> + depends on RC_CORE

I think you need:

depends on USB_ARCH_HAS_HCD

As well here.

> + select USB
> + help
> +Say Y here if you want to use the Xbox DVD Movie Playback Kit.
> +These are IR remotes with USB receivers for the Original Xbox (2001).
> +
> +To compile this driver as a module, choose M here: the module will be
> +called xbox_remote.
> +
>  config IR_ZX
>   tristate "ZTE ZX IR remote control"
>   depends on RC_CORE
> diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> index e0340d043fe8..92c163816849 100644
> --- a/drivers/media/rc/Makefile
> +++ b/drivers/media/rc/Makefile
> @@ -48,3 +48,4 @@ obj-$(CONFIG_IR_SIR) += sir_ir.o
>  obj-$(CONFIG_IR_MTK) += mtk-cir.o
>  obj-$(CONFIG_IR_ZX) += zx-irdec.o
>  obj-$(CONFIG_IR_TANGO) += tango-ir.o
> +obj-$(CONFIG_RC_XBOX_DVD) += xbox_remote.o
> diff --git a/drivers/media/rc/keymaps/Makefile 
> b/drivers/media/rc/keymaps/Makefile
> index d6b913a3032d..5b1399af6b3a 100644
> --- a/drivers/media/rc/keymaps/Makefile
> +++ b/drivers/media/rc/keymaps/Makefile
> @@ -116,4 +116,5 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
>   rc-winfast.o \
>   rc-winfast-usbii-deluxe.o \
>   rc-su3000.o \
> + rc-xbox-dvd.o \
>   rc-zx-irdec.o
> diff --git a/drivers/media/rc/keymaps/rc-xbox-dvd.c 
> b/drivers/media/rc/keymaps/rc-xbox-dvd.c
> new file mode 100644
> index ..61da6706715c
> --- /dev/null
> +++ b/drivers/media/rc/keymaps/rc-xbox-dvd.c
> @@ -0,0 +1,63 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +// Keytable for Xbox DVD remote
> +// Copyright (c) 2018 by Benjamin Valentin 
> +
> +#include 
> +#include 
> +
> +/* based on lircd.conf.xbox */
> +static struct rc_map_table xbox_dvd[] = {
> + {0x0b, KEY_OK},
> + {0xa6, KEY_UP},
> + {0xa7, KEY_DOWN},
> + {0xa8, KEY_RIGHT},
> + {0xa9, KEY_LEFT},
> + {0xc3, KEY_INFO},
> +
> + {0xc6, KEY_9},
> + {0xc7, KEY_8},
> + {0xc8, KEY_7},
> + {0xc9, KEY_6},
> + {0xca, KEY_5},
> + {0xcb, KEY_4},
> + {0xcc, KEY_3},
> + {0xcd, KEY_2},
> + {0xce, KEY_1},
> + {0xcf, KEY_0},
> +
> + {0xd5, KEY_ANGLE},
> + {0xd8, KEY_BACK},
> + {0xdd, KEY_PREVIOUSSONG},
> + {0xdf, KEY_NEXTSONG},
> + {0xe0, KEY_STOP},
> + {0xe2, KEY_REWIND},
> + {0xe3, KEY_FASTFORWARD},
> + {0xe5, KEY_TITLE},
> + {0xe6, KEY_PAUSE},
> + {0xea, 

Re: [PATCH] media: cec: name for RC passthrough device does not need 'RC for'

2018-10-05 Thread Sean Young
On Fri, Oct 05, 2018 at 09:37:11AM +0200, Hans Verkuil wrote:
> On 10/05/2018 12:21 AM, Sean Young wrote:
> > An RC device is does not need to be called 'RC for'. Simply the name
> > will suffice.
> > 
> > Signed-off-by: Sean Young 
> 
> Reviewed-by: Hans Verkuil 
> 
> OK if I take this patch? I have a cec pull request upcoming anyway.

Please do, thank you.

Sean


Re: [PATCH 2/2] media: rc: self test for IR encoders and decoders

2018-10-04 Thread Sean Young
Hi Shuah,

On Thu, Oct 04, 2018 at 02:13:51PM -0600, Shuah Khan wrote:
> Hi Sean,
> 
> Thanks for the patch. I just happened to see this when Mauro sent it to me.
> Doesn't look like linux-ksefltest and I weren't on the patch?

This is true, and that is an oversight on my behalf.

Thank you for your review -- I agree with all your points and thanks for the
helpful tips as well. I will fix for v2.

Thanks again,

Sean

> 
> On 07/17/2018 03:33 PM, Sean Young (by way of Mauro Carvalho Chehab 
> ) wrote:
> > ir-loopback can transmit IR on one rc device and check the correct
> > scancode and protocol is decoded on a different rc device. This can be
> > used to check IR transmission between two rc devices. Using rc-loopback,
> > we use it to check the IR encoders and decoders themselves.
> > 
> > Signed-off-by: Sean Young 
> > ---
> >  tools/testing/selftests/Makefile  |   1 +
> >  tools/testing/selftests/ir/.gitignore |   1 +
> >  tools/testing/selftests/ir/Makefile   |  19 ++
> >  tools/testing/selftests/ir/config |  12 ++
> >  tools/testing/selftests/ir/ir-loopback.c  | 209 ++
> >  tools/testing/selftests/ir/ir-loopback.sh |  28 +++
> >  6 files changed, 270 insertions(+)
> >  create mode 100644 tools/testing/selftests/ir/.gitignore
> >  create mode 100644 tools/testing/selftests/ir/Makefile
> >  create mode 100644 tools/testing/selftests/ir/config
> >  create mode 100644 tools/testing/selftests/ir/ir-loopback.c
> >  create mode 100755 tools/testing/selftests/ir/ir-loopback.sh
> 
> Why not add to the existing media directory? ../selftests/media_tests?
> 
> > 
> > diff --git a/tools/testing/selftests/Makefile 
> > b/tools/testing/selftests/Makefile
> > index f1fe492c8e17..995034ea5546 100644
> > --- a/tools/testing/selftests/Makefile
> > +++ b/tools/testing/selftests/Makefile
> > @@ -15,6 +15,7 @@ TARGETS += futex
> >  TARGETS += gpio
> >  TARGETS += intel_pstate
> >  TARGETS += ipc
> > +TARGETS += ir
> 
> Does this test depend on any hardware being present in the system?
> 
> >  TARGETS += kcmp
> >  TARGETS += kvm
> >  TARGETS += lib
> > diff --git a/tools/testing/selftests/ir/.gitignore 
> > b/tools/testing/selftests/ir/.gitignore
> > new file mode 100644
> > index ..87bf2989b678
> > --- /dev/null
> > +++ b/tools/testing/selftests/ir/.gitignore
> > @@ -0,0 +1 @@
> > +ir-loopback
> > diff --git a/tools/testing/selftests/ir/Makefile 
> > b/tools/testing/selftests/ir/Makefile
> > new file mode 100644
> > index ..501b464e56b5
> > --- /dev/null
> > +++ b/tools/testing/selftests/ir/Makefile
> > @@ -0,0 +1,19 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +uname_M := $(shell uname -m 2>/dev/null || echo not)
> > +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
> > +ifeq ($(ARCH),i386)
> > +ARCH := x86
> > +   CFLAGS := -DCONFIG_X86_32 -D__i386__
> > +endif
> > +ifeq ($(ARCH),x86_64)
> > +   ARCH := x86
> > +   CFLAGS := -DCONFIG_X86_64 -D__x86_64__
> > +endif
> > +
> > +CFLAGS += -I../../../../usr/include/
> > +
> > +TEST_PROGS := ir-loopback.sh
> > +
> > +TEST_GEN_PROGS := ir-loopback
> 
> Looks like ir-loopback get run from ir-loopback.sh. TEST_GEN_PROGS_EXTENDED
> is the right variable to use in this case.
> 
> TEST_GEN_PROGS_EXTENDED := ir-loopback
> 
> > +
> > +include ../lib.mk
> > diff --git a/tools/testing/selftests/ir/config 
> > b/tools/testing/selftests/ir/config
> > new file mode 100644
> > index ..78e041e9319e
> > --- /dev/null
> > +++ b/tools/testing/selftests/ir/config
> > @@ -0,0 +1,12 @@
> > +CONFIG_RC_CORE=y
> > +CONFIG_RC_LOOPBACK=y
> > +CONFIG_IR_NEC_DECODER=m
> > +CONFIG_IR_RC5_DECODER=m
> > +CONFIG_IR_RC6_DECODER=m
> > +CONFIG_IR_JVC_DECODER=m
> > +CONFIG_IR_SONY_DECODER=m
> > +CONFIG_IR_SANYO_DECODER=m
> > +CONFIG_IR_SHARP_DECODER=m
> > +CONFIG_IR_MCE_KBD_DECODER=m
> > +CONFIG_IR_XMP_DECODER=m
> > +CONFIG_IR_IMON_DECODER=m
> > diff --git a/tools/testing/selftests/ir/ir-loopback.c 
> > b/tools/testing/selftests/ir/ir-loopback.c
> > new file mode 100644
> > index ..95b6f0f2f1f5
> > --- /dev/null
> > +++ b/tools/testing/selftests/ir/ir-loopback.c
> > @@ -0,0 +1,209 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +// test ir decoder
> > +//
> > +// Copyright (C) 2018 Sean Young 
> > +
> > +// When sending LIRC_MODE_SCANCODE, the IR will 

[PATCH] media: cec: name for RC passthrough device does not need 'RC for'

2018-10-04 Thread Sean Young
An RC device is does not need to be called 'RC for'. Simply the name
will suffice.

Signed-off-by: Sean Young 
---
 drivers/media/cec/cec-core.c | 6 ++
 include/media/cec.h  | 2 --
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c
index 74596f089ec9..e4edc930d4ed 100644
--- a/drivers/media/cec/cec-core.c
+++ b/drivers/media/cec/cec-core.c
@@ -307,12 +307,10 @@ struct cec_adapter *cec_allocate_adapter(const struct 
cec_adap_ops *ops,
return ERR_PTR(-ENOMEM);
}
 
-   snprintf(adap->device_name, sizeof(adap->device_name),
-"RC for %s", name);
snprintf(adap->input_phys, sizeof(adap->input_phys),
-"%s/input0", name);
+"%s/input0", adap->name);
 
-   adap->rc->device_name = adap->device_name;
+   adap->rc->device_name = adap->name;
adap->rc->input_phys = adap->input_phys;
adap->rc->input_id.bustype = BUS_CEC;
adap->rc->input_id.vendor = 0;
diff --git a/include/media/cec.h b/include/media/cec.h
index 9f382f0c2970..73ed28b076ce 100644
--- a/include/media/cec.h
+++ b/include/media/cec.h
@@ -198,9 +198,7 @@ struct cec_adapter {
u16 phys_addrs[15];
u32 sequence;
 
-   char device_name[32];
char input_phys[32];
-   char input_drv[32];
 };
 
 static inline void *cec_get_drvdata(const struct cec_adapter *adap)
-- 
2.17.1



[GIT PULL FOR v4.20] Additional RC fixes

2018-10-04 Thread Sean Young
Hi Mauro,

Here are some additional fixes for v4.20. By enabling the rel/keys bits
when the RC input device is registered, we can re-use the same input
device for imon/mce_kbd protocol mouse movements and keys.

Note that all these patches depend on each other; the second depends on the
first, and the third depends on the first two.

Tested with real imon and mce keyboard.

Thanks,

Sean

The following changes since commit 5f108da55c6a928d0305163731bca2ac94ab233b:

  media: smiapp: Remove unused loop (2018-10-03 11:59:10 -0400)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.20b

for you to fetch changes up to a810925a2795daa204f1ff2e659e026acc4459b5:

  media: rc: mce_kbd: input events via rc-core's input device (2018-10-04 
15:05:37 +0100)


Sean Young (3):
  media: rc: some events are dropped by userspace
  media: rc: imon: report mouse events using rc-core's input device
  media: rc: mce_kbd: input events via rc-core's input device

 drivers/media/rc/ir-imon-decoder.c| 62 ++--
 drivers/media/rc/ir-mce_kbd-decoder.c | 77 +++
 drivers/media/rc/rc-core-priv.h   |  5 ---
 drivers/media/rc/rc-main.c| 20 -
 4 files changed, 26 insertions(+), 138 deletions(-)


[RFP] Media Summit: rc-core status update

2018-09-24 Thread Sean Young
A 10 minute status update on rc-core, present and future. I'll give a
brief presentation and leave some time for discussion.

Thanks

Sean


[PATCH 1/4] media: rc: some events are dropped by userspace

2018-09-18 Thread Sean Young
libevdev (which is used by libinput) gets a list of keycodes from the
input device on creation. Any events with keycodes which are not in this
list are silently dropped. So, set all keycodes on device creation since
we do not know which will be used if the keymap changes.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index ca68e1d2b2f9..97086fbbed41 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -289,20 +289,9 @@ static unsigned int ir_update_mapping(struct rc_dev *dev,
old_keycode == KEY_RESERVED ? "New" : "Replacing",
rc_map->scan[index].scancode, new_keycode);
rc_map->scan[index].keycode = new_keycode;
-   __set_bit(new_keycode, dev->input_dev->keybit);
}
 
if (old_keycode != KEY_RESERVED) {
-   /* A previous mapping was updated... */
-   __clear_bit(old_keycode, dev->input_dev->keybit);
-   /* ... but another scancode might use the same keycode */
-   for (i = 0; i < rc_map->len; i++) {
-   if (rc_map->scan[i].keycode == old_keycode) {
-   __set_bit(old_keycode, dev->input_dev->keybit);
-   break;
-   }
-   }
-
/* Possibly shrink the keytable, failure is not a problem */
ir_resize_table(dev, rc_map, GFP_ATOMIC);
}
@@ -1759,6 +1748,8 @@ static int rc_prepare_rx_device(struct rc_dev *dev)
set_bit(EV_REP, dev->input_dev->evbit);
set_bit(EV_MSC, dev->input_dev->evbit);
set_bit(MSC_SCAN, dev->input_dev->mscbit);
+   bitmap_fill(dev->input_dev->keybit, KEY_CNT);
+
if (dev->open)
dev->input_dev->open = ir_open;
if (dev->close)
-- 
2.17.1



[PATCH 3/4] media: rc: mce_kbd: input events via rc-core's input device

2018-09-18 Thread Sean Young
There is no need to create another input device.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-mce_kbd-decoder.c | 77 +--
 drivers/media/rc/rc-core-priv.h   |  3 --
 2 files changed, 14 insertions(+), 66 deletions(-)

diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index 64ea42927669..67f1c179c713 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -129,13 +129,14 @@ static void mce_kbd_rx_timeout(struct timer_list *t)
if (time_is_before_eq_jiffies(raw->mce_kbd.rx_timeout.expires)) {
for (i = 0; i < 7; i++) {
maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START + i];
-   input_report_key(raw->mce_kbd.idev, maskcode, 0);
+   input_report_key(raw->dev->input_dev, maskcode, 0);
}
 
for (i = 0; i < MCIR2_MASK_KEYS_START; i++)
-   input_report_key(raw->mce_kbd.idev, kbd_keycodes[i], 0);
+   input_report_key(raw->dev->input_dev, kbd_keycodes[i],
+0);
 
-   input_sync(raw->mce_kbd.idev);
+   input_sync(raw->dev->input_dev);
}
spin_unlock_irqrestore(>mce_kbd.keylock, flags);
 }
@@ -154,7 +155,6 @@ static enum mce_kbd_mode mce_kbd_mode(struct mce_kbd_dec 
*data)
 
 static void ir_mce_kbd_process_keyboard_data(struct rc_dev *dev, u32 scancode)
 {
-   struct mce_kbd_dec *data = >raw->mce_kbd;
u8 keydata1  = (scancode >> 8) & 0xff;
u8 keydata2  = (scancode >> 16) & 0xff;
u8 shiftmask = scancode & 0xff;
@@ -170,23 +170,22 @@ static void ir_mce_kbd_process_keyboard_data(struct 
rc_dev *dev, u32 scancode)
keystate = 1;
else
keystate = 0;
-   input_report_key(data->idev, maskcode, keystate);
+   input_report_key(dev->input_dev, maskcode, keystate);
}
 
if (keydata1)
-   input_report_key(data->idev, kbd_keycodes[keydata1], 1);
+   input_report_key(dev->input_dev, kbd_keycodes[keydata1], 1);
if (keydata2)
-   input_report_key(data->idev, kbd_keycodes[keydata2], 1);
+   input_report_key(dev->input_dev, kbd_keycodes[keydata2], 1);
 
if (!keydata1 && !keydata2) {
for (i = 0; i < MCIR2_MASK_KEYS_START; i++)
-   input_report_key(data->idev, kbd_keycodes[i], 0);
+   input_report_key(dev->input_dev, kbd_keycodes[i], 0);
}
 }
 
 static void ir_mce_kbd_process_mouse_data(struct rc_dev *dev, u32 scancode)
 {
-   struct mce_kbd_dec *data = >raw->mce_kbd;
/* raw mouse coordinates */
u8 xdata = (scancode >> 7) & 0x7f;
u8 ydata = (scancode >> 14) & 0x7f;
@@ -208,11 +207,11 @@ static void ir_mce_kbd_process_mouse_data(struct rc_dev 
*dev, u32 scancode)
dev_dbg(>dev, "mouse: x = %d, y = %d, btns = %s%s\n",
x, y, left ? "L" : "", right ? "R" : "");
 
-   input_report_rel(data->idev, REL_X, x);
-   input_report_rel(data->idev, REL_Y, y);
+   input_report_rel(dev->input_dev, REL_X, x);
+   input_report_rel(dev->input_dev, REL_Y, y);
 
-   input_report_key(data->idev, BTN_LEFT, left);
-   input_report_key(data->idev, BTN_RIGHT, right);
+   input_report_key(dev->input_dev, BTN_LEFT, left);
+   input_report_key(dev->input_dev, BTN_RIGHT, right);
 }
 
 /**
@@ -355,8 +354,8 @@ static int ir_mce_kbd_decode(struct rc_dev *dev, struct 
ir_raw_event ev)
lsc.scancode = scancode;
ir_lirc_scancode_event(dev, );
data->state = STATE_INACTIVE;
-   input_event(data->idev, EV_MSC, MSC_SCAN, scancode);
-   input_sync(data->idev);
+   input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
+   input_sync(dev->input_dev);
return 0;
}
 
@@ -370,66 +369,18 @@ static int ir_mce_kbd_decode(struct rc_dev *dev, struct 
ir_raw_event ev)
 static int ir_mce_kbd_register(struct rc_dev *dev)
 {
struct mce_kbd_dec *mce_kbd = >raw->mce_kbd;
-   struct input_dev *idev;
-   int i, ret;
-
-   idev = input_allocate_device();
-   if (!idev)
-   return -ENOMEM;
-
-   snprintf(mce_kbd->name, sizeof(mce_kbd->name),
-"MCE IR Keyboard/Mouse (%s)", dev->driver_name);
-   strlcat(mce_kbd->phys, "/input0", sizeof(mce_kbd->phys));
-
-   idev->name = mce_kbd->name;
-   idev->phys = mce_kbd->phys;
-
-   /* Keyboard bits */
-   

[PATCH 2/4] media: rc: imon: report mouse events using rc-core's input device

2018-09-18 Thread Sean Young
There is no need to create another input device.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-imon-decoder.c | 62 ++
 drivers/media/rc/rc-core-priv.h|  2 -
 drivers/media/rc/rc-main.c |  6 +++
 3 files changed, 10 insertions(+), 60 deletions(-)

diff --git a/drivers/media/rc/ir-imon-decoder.c 
b/drivers/media/rc/ir-imon-decoder.c
index 67c1b0c15aae..a0efe2605393 100644
--- a/drivers/media/rc/ir-imon-decoder.c
+++ b/drivers/media/rc/ir-imon-decoder.c
@@ -70,24 +70,13 @@ static void ir_imon_decode_scancode(struct rc_dev *dev)
}
 
if (!imon->stick_keyboard) {
-   struct lirc_scancode lsc = {
-   .scancode = imon->bits,
-   .rc_proto = RC_PROTO_IMON,
-   };
+   input_report_rel(dev->input_dev, REL_X, rel_x);
+   input_report_rel(dev->input_dev, REL_Y, rel_y);
 
-   ir_lirc_scancode_event(dev, );
-
-   input_event(imon->idev, EV_MSC, MSC_SCAN, imon->bits);
-
-   input_report_rel(imon->idev, REL_X, rel_x);
-   input_report_rel(imon->idev, REL_Y, rel_y);
-
-   input_report_key(imon->idev, BTN_LEFT,
+   input_report_key(dev->input_dev, BTN_LEFT,
 (imon->bits & 0x0001) != 0);
-   input_report_key(imon->idev, BTN_RIGHT,
+   input_report_key(dev->input_dev, BTN_RIGHT,
 (imon->bits & 0x0004) != 0);
-   input_sync(imon->idev);
-   return;
}
}
 
@@ -243,62 +232,19 @@ static int ir_imon_encode(enum rc_proto protocol, u32 
scancode,
 
 static int ir_imon_register(struct rc_dev *dev)
 {
-   struct input_dev *idev;
struct imon_dec *imon = >raw->imon;
-   int ret;
-
-   idev = input_allocate_device();
-   if (!idev)
-   return -ENOMEM;
-
-   snprintf(imon->name, sizeof(imon->name),
-"iMON PAD Stick (%s)", dev->device_name);
-   idev->name = imon->name;
-   idev->phys = dev->input_phys;
-
-   /* Mouse bits */
-   set_bit(EV_REL, idev->evbit);
-   set_bit(EV_KEY, idev->evbit);
-   set_bit(REL_X, idev->relbit);
-   set_bit(REL_Y, idev->relbit);
-   set_bit(BTN_LEFT, idev->keybit);
-   set_bit(BTN_RIGHT, idev->keybit);
-
-   /* Report scancodes too */
-   set_bit(EV_MSC, idev->evbit);
-   set_bit(MSC_SCAN, idev->mscbit);
-
-   input_set_drvdata(idev, imon);
-
-   ret = input_register_device(idev);
-   if (ret < 0) {
-   input_free_device(idev);
-   return -EIO;
-   }
 
-   imon->idev = idev;
imon->stick_keyboard = false;
 
return 0;
 }
 
-static int ir_imon_unregister(struct rc_dev *dev)
-{
-   struct imon_dec *imon = >raw->imon;
-
-   input_unregister_device(imon->idev);
-   imon->idev = NULL;
-
-   return 0;
-}
-
 static struct ir_raw_handler imon_handler = {
.protocols  = RC_PROTO_BIT_IMON,
.decode = ir_imon_decode,
.encode = ir_imon_encode,
.carrier= 38000,
.raw_register   = ir_imon_register,
-   .raw_unregister = ir_imon_unregister,
.min_timeout= IMON_UNIT * IMON_BITS * 2,
 };
 
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index e847bdad5c51..c2a8084f0a13 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -133,8 +133,6 @@ struct ir_raw_event_ctrl {
int last_chk;
unsigned int bits;
bool stick_keyboard;
-   struct input_dev *idev;
-   char name[64];
} imon;
 };
 
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 97086fbbed41..821e36e320b7 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1744,12 +1744,18 @@ static int rc_prepare_rx_device(struct rc_dev *dev)
dev->enabled_protocols = rc_proto;
}
 
+   /* Keyboard events */
set_bit(EV_KEY, dev->input_dev->evbit);
set_bit(EV_REP, dev->input_dev->evbit);
set_bit(EV_MSC, dev->input_dev->evbit);
set_bit(MSC_SCAN, dev->input_dev->mscbit);
bitmap_fill(dev->input_dev->keybit, KEY_CNT);
 
+   /* Pointer/mouse events */
+   set_bit(EV_REL, dev->input_dev->evbit);
+   set_bit(REL_X, dev->input_dev->relbit);
+   set_bit(REL_Y, dev->input_dev->relbit);
+
if (dev->open)
dev->input_dev->open = ir_open;
if (dev->close)
-- 
2.17.1



[PATCH v4l-utils 1/2] keytable: keymap for Network Dish

2018-09-15 Thread Sean Young
BPF keymap, see:
https://www.mythtv.org/wiki/DISHNetworkLIRCConfiguration

Cc: VDR User 
Signed-off-by: Sean Young 
---
 .../rc_keymaps_userspace/dish_network.toml| 62 +++
 1 file changed, 62 insertions(+)
 create mode 100644 utils/keytable/rc_keymaps_userspace/dish_network.toml

diff --git a/utils/keytable/rc_keymaps_userspace/dish_network.toml 
b/utils/keytable/rc_keymaps_userspace/dish_network.toml
new file mode 100644
index ..9614edae
--- /dev/null
+++ b/utils/keytable/rc_keymaps_userspace/dish_network.toml
@@ -0,0 +1,62 @@
+# See https://www.mythtv.org/wiki/DISHNetworkLIRCConfiguration
+[[protocols]]
+name = 'Dish Network'
+protocol = 'pulse_distance'
+trailer_pulse = 450
+header_optional = 1
+header_pulse = 525
+header_space = 6045
+bits = 16
+bit_pulse = 440
+bit_1_space = 1645
+bit_0_space = 2780
+[protocols.scancodes]
+0x0400 = 'KEY_SAT'
+0xa801 = 'KEY_TV'
+0xac02 = 'KEY_DVD'
+0xb003 = 'KEY_AUX'
+0x0800 = 'KEY_POWER'
+0x2c00 = 'KEY_MENU'
+0x5c00 = 'KEY_SWITCHVIDEOMODE' # Input
+0x3c10 = 'KEY_PAGEUP'
+0x1c10 = 'KEY_PAGEDOWN'
+0x5000 = 'KEY_EPG'
+0x6800 = 'KEY_UP'
+0x7000 = 'KEY_LEFT'
+0x4000 = 'KEY_SELECT'
+0x6000 = 'KEY_RIGHT'
+0x7800 = 'KEY_DOWN'
+0x6c00 = 'KEY_LAST'
+0x = 'KEY_INFO'
+0xb400 = 'KEY_SEARCH'
+0x5800 = 'KEY_TV' # View Live TV
+0x4800 = 'KEY_CANCEL'
+0x4c00 = 'KEY_RED'
+0xd400 = 'KEY_GREEN'
+0x8800 = 'KEY_YELLOW'
+0x8c00 = 'KEY_BLUE'
+0xd810 = 'KEY_PREVIOUS'
+0xe410 = 'KEY_PVR'
+0xdc10 = 'KEY_NEXT'
+0xc410 = 'KEY_REWIND'
+0x8000 = 'KEY_PAUSE'
+0xc810 = 'KEY_FASTFORWARD'
+0x8400 = 'KEY_STOP'
+0x7c00 = 'KEY_RECORD'
+0x0c10 = 'KEY_PLAY'
+0x1000 = 'KEY_NUMERIC_1'
+0x1400 = 'KEY_NUMERIC_2'
+0x1800 = 'KEY_NUMERIC_3'
+0x2000 = 'KEY_NUMERIC_4'
+0x2400 = 'KEY_NUMERIC_5'
+0x2800 = 'KEY_NUMERIC_6'
+0x3000 = 'KEY_NUMERIC_7'
+0x3400 = 'KEY_NUMERIC_8'
+0x3800 = 'KEY_NUMERIC_9'
+0x4400 = 'KEY_NUMERIC_0'
+0x9400 = 'KEY_NUMERIC_STAR'
+0x9800 = 'KEY_NUMERIC_POUND'
+0xf410 = 'KEY_AB'
+0xe810 = 'KEY_VIDEO' # PIP (Picture-in-picture)
+0xec10 = 'KEY_SCREEN' # Position
+0xd010 = 'KEY_MEDIA' # Dish
-- 
2.17.1



[PATCH v4l-utils 2/2] keytable: keymap for Windows Remote Keyboard for MCE

2018-09-15 Thread Sean Young
This keymap differs from rc6_mce in that it also enables the mce_kbd
protocol.

Signed-off-by: Sean Young 
---
 .../rc_keymaps_userspace/mce_keyboard.toml| 75 +++
 1 file changed, 75 insertions(+)
 create mode 100644 utils/keytable/rc_keymaps_userspace/mce_keyboard.toml

diff --git a/utils/keytable/rc_keymaps_userspace/mce_keyboard.toml 
b/utils/keytable/rc_keymaps_userspace/mce_keyboard.toml
new file mode 100644
index ..ed69c2f4
--- /dev/null
+++ b/utils/keytable/rc_keymaps_userspace/mce_keyboard.toml
@@ -0,0 +1,75 @@
+# Microsoft Remote Keyboard for Windows Media Center Edition
+# The keyboard uses both rc-6 and mce_kbd protocols. The mce_kbd protocol
+# is used for the standard keyboard keys (e.g. qwerty, return etc) and the
+# other keys like "messager", volume up etc are sent using rc-6 (mce variant).
+[[protocols]]
+name = "rc6_mce"
+protocol = "rc6"
+variant = "rc6_mce"
+[protocols.scancodes]
+0x800f0400 = "KEY_NUMERIC_0"
+0x800f0401 = "KEY_NUMERIC_1"
+0x800f0402 = "KEY_NUMERIC_2"
+0x800f0403 = "KEY_NUMERIC_3"
+0x800f0404 = "KEY_NUMERIC_4"
+0x800f0405 = "KEY_NUMERIC_5"
+0x800f0406 = "KEY_NUMERIC_6"
+0x800f0407 = "KEY_NUMERIC_7"
+0x800f0408 = "KEY_NUMERIC_8"
+0x800f0409 = "KEY_NUMERIC_9"
+0x800f040a = "KEY_DELETE"
+0x800f040b = "KEY_ENTER"
+0x800f040c = "KEY_SLEEP"
+0x800f040d = "KEY_MEDIA"
+0x800f040e = "KEY_MUTE"
+0x800f040f = "KEY_INFO"
+0x800f0410 = "KEY_VOLUMEUP"
+0x800f0411 = "KEY_VOLUMEDOWN"
+0x800f0412 = "KEY_CHANNELUP"
+0x800f0413 = "KEY_CHANNELDOWN"
+0x800f0414 = "KEY_FASTFORWARD"
+0x800f0415 = "KEY_REWIND"
+0x800f0416 = "KEY_PLAY"
+0x800f0417 = "KEY_RECORD"
+0x800f0418 = "KEY_PAUSE"
+0x800f0419 = "KEY_STOP"
+0x800f041a = "KEY_NEXT"
+0x800f041b = "KEY_PREVIOUS"
+0x800f041c = "KEY_NUMERIC_POUND"
+0x800f041d = "KEY_NUMERIC_STAR"
+0x800f041e = "KEY_UP"
+0x800f041f = "KEY_DOWN"
+0x800f0420 = "KEY_LEFT"
+0x800f0421 = "KEY_RIGHT"
+0x800f0422 = "KEY_OK"
+0x800f0423 = "KEY_EXIT"
+0x800f0424 = "KEY_DVD"
+0x800f0425 = "KEY_TUNER"
+0x800f0426 = "KEY_EPG"
+0x800f0427 = "KEY_ZOOM"
+0x800f0432 = "KEY_MODE"
+0x800f0433 = "KEY_PRESENTATION"
+0x800f0434 = "KEY_EJECTCD"
+0x800f043a = "KEY_BRIGHTNESSUP"
+0x800f0446 = "KEY_TV"
+0x800f0447 = "KEY_AUDIO"
+0x800f0448 = "KEY_PVR"
+0x800f0449 = "KEY_CAMERA"
+0x800f044a = "KEY_VIDEO"
+0x800f044c = "KEY_LANGUAGE"
+0x800f044d = "KEY_TITLE"
+0x800f044e = "KEY_PRINT"
+0x800f0450 = "KEY_RADIO"
+0x800f045a = "KEY_SUBTITLE"
+0x800f045b = "KEY_RED"
+0x800f045c = "KEY_GREEN"
+0x800f045d = "KEY_YELLOW"
+0x800f045e = "KEY_BLUE"
+0x800f0465 = "KEY_POWER2"
+0x800f0469 = "KEY_MESSENGER"
+0x800f046e = "KEY_PLAYPAUSE"
+0x800f046f = "KEY_PLAYER"
+0x800f0480 = "KEY_BRIGHTNESSDOWN"
+0x800f0481 = "KEY_PLAYPAUSE"
+[[protocols]]
+protocol = "mce_kbd"
-- 
2.17.1



Re: [PATCH v3 1/2] media: dt-bindings: bind nokia,n900-ir to generic pwm-ir-tx driver

2018-09-10 Thread Sean Young
On Fri, Aug 31, 2018 at 11:07:23AM +0300, Sakari Ailus wrote:
> Hi Sean,
> 
> On Fri, Jul 13, 2018 at 01:22:29PM +0100, Sean Young wrote:
> > The generic pwm-ir-tx driver should work for the Nokia n900.
> > 
> > Compile tested only.
> > 
> > Cc: Rob Herring 
> > Cc: Ivaylo Dimitrov 
> > Cc: Pali Rohár 
> > Cc: Pavel Machek 
> > Cc: Timo Kokkonen 
> > Cc: Tony Lindgren 
> > Signed-off-by: Sean Young 
> > ---
> >  arch/arm/boot/dts/omap3-n900.dts | 2 +-
> >  drivers/media/rc/pwm-ir-tx.c | 1 +
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/boot/dts/omap3-n900.dts 
> > b/arch/arm/boot/dts/omap3-n900.dts
> > index 182a53991c90..fd12dea15799 100644
> > --- a/arch/arm/boot/dts/omap3-n900.dts
> > +++ b/arch/arm/boot/dts/omap3-n900.dts
> > @@ -154,7 +154,7 @@
> > };
> >  
> > ir: n900-ir {
> > -   compatible = "nokia,n900-ir";
> > +   compatible = "nokia,n900-ir", "pwm-ir-tx";
> > pwms = < 0 26316 0>; /* 38000 Hz */
> > };
> >  
> > diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
> > index 27d0f5837a76..272947b430c8 100644
> > --- a/drivers/media/rc/pwm-ir-tx.c
> > +++ b/drivers/media/rc/pwm-ir-tx.c
> > @@ -30,6 +30,7 @@ struct pwm_ir {
> >  };
> >  
> >  static const struct of_device_id pwm_ir_of_match[] = {
> > +   { .compatible = "nokia,n900-ir" },
> 
> Is this change needed as well? I suppose you could add it later if there's
> a need to e.g. do something differently for the N900 IR transmitter.

This is to ensure compatibility of a new kernel with an old board dtb. 

> It'd be nice if someone tested it, too...

That would be nice, but I don't have the hardware and so far I there has
been noone willing/able to test it.


Sean


[GIT PULL FOR v4.20] RC changes

2018-08-29 Thread Sean Young
Hi Mauro,

This includes a change which depends on gcc 4.6, since mainline now
requires it. Also this removes the ir-rx51 for the Nokia N900, since
this is covered by the generic pwm-ir-tx driver.

Please pull. Thanks!

Sean


The following changes since commit 5b394b2ddf0347bef56e50c69a58773c94343ff3:

  Linux 4.19-rc1 (2018-08-26 14:11:59 -0700)

are available in the Git repository at:

  git://git.linuxtv.org/syoung/media_tree.git for-v4.20a

for you to fetch changes up to ee0364e9752bf2768389db4e8dc9e478e263bd7f:

  media: rc: ir-rc6-decoder: enable toggle bit for Kathrein RCU-676 remote 
(2018-08-28 23:27:55 +0100)


Matthias Reichl (1):
  media: rc: ir-rc6-decoder: enable toggle bit for Kathrein RCU-676 remote

Sean Young (5):
  media: dt-bindings: bind nokia, n900-ir to generic pwm-ir-tx driver
  media: rc: remove ir-rx51 in favour of generic pwm-ir-tx
  media: rc: nec keymaps should specify the nec variant they use
  media: rc: self test for IR encoders and decoders
  media: rc: Remove init_ir_raw_event and DEFINE_IR_RAW_EVENT macros

 arch/arm/boot/dts/omap3-n900.dts  |   2 +-
 arch/arm/configs/omap2plus_defconfig  |   1 -
 drivers/hid/hid-picolcd_cir.c |   3 +-
 drivers/media/common/siano/smsir.c|   8 +-
 drivers/media/i2c/cx25840/cx25840-ir.c|   6 +-
 drivers/media/pci/cx23885/cx23888-ir.c|   6 +-
 drivers/media/pci/cx88/cx88-input.c   |   3 +-
 drivers/media/rc/Kconfig  |  10 -
 drivers/media/rc/Makefile |   1 -
 drivers/media/rc/ene_ir.c |  12 +-
 drivers/media/rc/fintek-cir.c |   3 +-
 drivers/media/rc/igorplugusb.c|   2 +-
 drivers/media/rc/iguanair.c   |   4 +-
 drivers/media/rc/imon_raw.c   |   2 +-
 drivers/media/rc/ir-hix5hd2.c |   2 +-
 drivers/media/rc/ir-rc6-decoder.c |   9 +-
 drivers/media/rc/ir-rx51.c| 305 --
 drivers/media/rc/ite-cir.c|   5 +-
 drivers/media/rc/keymaps/rc-behold.c  |   2 +-
 drivers/media/rc/keymaps/rc-delock-61959.c|   2 +-
 drivers/media/rc/keymaps/rc-imon-rsc.c|   2 +-
 drivers/media/rc/keymaps/rc-it913x-v1.c   |   2 +-
 drivers/media/rc/keymaps/rc-it913x-v2.c   |   2 +-
 drivers/media/rc/keymaps/rc-msi-digivox-iii.c |   2 +-
 drivers/media/rc/keymaps/rc-pixelview-002t.c  |   2 +-
 drivers/media/rc/keymaps/rc-pixelview-mk12.c  |   2 +-
 drivers/media/rc/keymaps/rc-reddo.c   |   2 +-
 drivers/media/rc/keymaps/rc-terratec-slim.c   |   2 +-
 drivers/media/rc/keymaps/rc-tivo.c|   2 +-
 drivers/media/rc/keymaps/rc-total-media-in-hand.c |   2 +-
 drivers/media/rc/mceusb.c |  15 +-
 drivers/media/rc/meson-ir.c   |   2 +-
 drivers/media/rc/mtk-cir.c|   2 +-
 drivers/media/rc/nuvoton-cir.c|   2 +-
 drivers/media/rc/pwm-ir-tx.c  |   1 +
 drivers/media/rc/rc-core-priv.h   |   7 +-
 drivers/media/rc/rc-ir-raw.c  |  12 +-
 drivers/media/rc/rc-loopback.c|   2 +-
 drivers/media/rc/redrat3.c|  10 +-
 drivers/media/rc/serial_ir.c  |  10 +-
 drivers/media/rc/sir_ir.c |   2 +-
 drivers/media/rc/st_rc.c  |   5 +-
 drivers/media/rc/streamzap.c  |  12 +-
 drivers/media/rc/sunxi-cir.c  |   2 +-
 drivers/media/rc/ttusbir.c|   4 +-
 drivers/media/rc/winbond-cir.c|  12 +-
 drivers/media/usb/au0828/au0828-input.c   |   5 +-
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c   |   4 +-
 include/media/rc-core.h   |  11 +-
 tools/testing/selftests/Makefile  |   1 +
 tools/testing/selftests/ir/.gitignore |   1 +
 tools/testing/selftests/ir/Makefile   |  19 ++
 tools/testing/selftests/ir/config |  12 +
 tools/testing/selftests/ir/ir-loopback.c  | 211 +++
 tools/testing/selftests/ir/ir-loopback.sh |  28 ++
 55 files changed, 367 insertions(+), 433 deletions(-)
 delete mode 100644 drivers/media/rc/ir-rx51.c
 create mode 100644 tools/testing/selftests/ir/.gitignore
 create mode 100644 tools/testing/selftests/ir/Makefile
 create mode 100644 tools/testing/selftests/ir/config
 create mode 100644 tools/testing/selftests/ir/ir-loopback.c
 create mode 100755 tools/testing/selftests/ir/ir-loopback.sh


[PATCH] media: rc: Remove init_ir_raw_event and DEFINE_IR_RAW_EVENT macros

2018-08-27 Thread Sean Young
This can be done with c99 initializers, which makes the code cleaner
and more transparent. It does require gcc 4.6, because of this bug
in earlier versions:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676

Since commit cafa0010cd51 ("Raise the minimum required gcc version to
4.6"), this is the case.

Signed-off-by: Sean Young 
---
 drivers/hid/hid-picolcd_cir.c   |  3 +--
 drivers/media/common/siano/smsir.c  |  8 
 drivers/media/i2c/cx25840/cx25840-ir.c  |  6 ++
 drivers/media/pci/cx23885/cx23888-ir.c  |  6 ++
 drivers/media/pci/cx88/cx88-input.c |  3 +--
 drivers/media/rc/ene_ir.c   | 12 ++--
 drivers/media/rc/fintek-cir.c   |  3 +--
 drivers/media/rc/igorplugusb.c  |  2 +-
 drivers/media/rc/iguanair.c |  4 +---
 drivers/media/rc/imon_raw.c |  2 +-
 drivers/media/rc/ir-hix5hd2.c   |  2 +-
 drivers/media/rc/ite-cir.c  |  5 +
 drivers/media/rc/mceusb.c   | 15 ---
 drivers/media/rc/meson-ir.c |  2 +-
 drivers/media/rc/mtk-cir.c  |  2 +-
 drivers/media/rc/nuvoton-cir.c  |  2 +-
 drivers/media/rc/rc-core-priv.h |  7 ---
 drivers/media/rc/rc-ir-raw.c| 12 ++--
 drivers/media/rc/rc-loopback.c  |  2 +-
 drivers/media/rc/redrat3.c  | 10 +-
 drivers/media/rc/serial_ir.c| 10 +-
 drivers/media/rc/sir_ir.c   |  2 +-
 drivers/media/rc/st_rc.c|  5 ++---
 drivers/media/rc/streamzap.c| 12 ++--
 drivers/media/rc/sunxi-cir.c|  2 +-
 drivers/media/rc/ttusbir.c  |  4 +---
 drivers/media/rc/winbond-cir.c  | 12 ++--
 drivers/media/usb/au0828/au0828-input.c |  5 +
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c |  4 +---
 include/media/rc-core.h | 11 +--
 30 files changed, 74 insertions(+), 101 deletions(-)

diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
index 32747b7f917e..bf6f29ca3315 100644
--- a/drivers/hid/hid-picolcd_cir.c
+++ b/drivers/hid/hid-picolcd_cir.c
@@ -45,7 +45,7 @@ int picolcd_raw_cir(struct picolcd_data *data,
 {
unsigned long flags;
int i, w, sz;
-   DEFINE_IR_RAW_EVENT(rawir);
+   struct ir_raw_event rawir = {};
 
/* ignore if rc_dev is NULL or status is shunned */
spin_lock_irqsave(>lock, flags);
@@ -67,7 +67,6 @@ int picolcd_raw_cir(struct picolcd_data *data,
 */
sz = size > 0 ? min((int)raw_data[0], size-1) : 0;
for (i = 0; i+1 < sz; i += 2) {
-   init_ir_raw_event();
w = (raw_data[i] << 8) | (raw_data[i+1]);
rawir.pulse = !!(w & 0x8000);
rawir.duration = US_TO_NS(rawir.pulse ? (65536 - w) : w);
diff --git a/drivers/media/common/siano/smsir.c 
b/drivers/media/common/siano/smsir.c
index 56db0a944421..1c2324f0e05a 100644
--- a/drivers/media/common/siano/smsir.c
+++ b/drivers/media/common/siano/smsir.c
@@ -26,10 +26,10 @@ void sms_ir_event(struct smscore_device_t *coredev, const 
char *buf, int len)
const s32 *samples = (const void *)buf;
 
for (i = 0; i < len >> 2; i++) {
-   DEFINE_IR_RAW_EVENT(ev);
-
-   ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
-   ev.pulse = (samples[i] > 0) ? false : true;
+   struct ir_raw_event ev = {
+   .duration = abs(samples[i]) * 1000, /* Convert to ns */
+   .pulse = (samples[i] > 0) ? false : true
+   };
 
ir_raw_event_store(coredev->ir.dev, );
}
diff --git a/drivers/media/i2c/cx25840/cx25840-ir.c 
b/drivers/media/i2c/cx25840/cx25840-ir.c
index ad7f66c7aac8..69cdc09981af 100644
--- a/drivers/media/i2c/cx25840/cx25840-ir.c
+++ b/drivers/media/i2c/cx25840/cx25840-ir.c
@@ -701,10 +701,8 @@ static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 
*buf, size_t count,
if (v > IR_MAX_DURATION)
v = IR_MAX_DURATION;
 
-   init_ir_raw_event(>ir_core_data);
-   p->ir_core_data.pulse = u;
-   p->ir_core_data.duration = v;
-   p->ir_core_data.timeout = w;
+   p->ir_core_data = (struct ir_raw_event)
+   { .pulse = u, .duration = v, .timeout = w };
 
v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns  %s  %s\n",
 v, u ? "mark" : "space", w ? "(timed out)" : "");
diff --git a/drivers/media/pci/cx23885/cx23888-ir.c 
b/drivers/media/pci/cx23885/cx23888-ir.c
index 00329f668b59..1d775c90df51 100644
--- a/drivers/media/pci/cx23885/cx23888-ir.c
+++ b/drivers/media/pci/cx23885/cx23888-ir.c
@@ -696,10 +696,8 @@ static int cx23888_ir_rx_read(struct v4l2_subde

[PATCH 1/2] Remove unnecessary if

2018-08-15 Thread Sean Young
Signed-off-by: Sean Young 
---
 utils/ir-ctl/ir-ctl.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/utils/ir-ctl/ir-ctl.c b/utils/ir-ctl/ir-ctl.c
index 59555a13..ddd93068 100644
--- a/utils/ir-ctl/ir-ctl.c
+++ b/utils/ir-ctl/ir-ctl.c
@@ -175,19 +175,17 @@ static bool strtoscancode(const char *p, unsigned *ret)
 static unsigned parse_emitters(char *p)
 {
unsigned emit = 0;
-   const char *sep = " ,;:";
+   static const char *sep = " ,;:";
char *saveptr, *q;
 
q = strtok_r(p, sep, );
while (q) {
-   if (*q) {
-   char *endptr;
-   long e = strtol(q, , 10);
-   if ((endptr && *endptr) || e <= 0 || e > 32)
-   return 0;
+   char *endptr;
+   long e = strtol(q, , 10);
+   if ((endptr && *endptr) || e <= 0 || e > 32)
+   return 0;
 
-   emit |= 1 << (e - 1);
-   }
+   emit |= 1 << (e - 1);
q = strtok_r(NULL, sep, );
}
 
@@ -200,7 +198,7 @@ static struct file *read_file(struct arguments *args, const 
char *fname)
int lineno = 0, lastspace = 0;
char line[1024];
int len = 0;
-   const char *whitespace = " \n\r\t";
+   static const char *whitespace = " \n\r\t";
struct file *f;
 
FILE *input = fopen(fname, "r");
-- 
2.17.1



[PATCH 2/2] ir-ctl: different drivers have different default timeouts

2018-08-15 Thread Sean Young
A driver might not support setting the timeout either, in addition,
if a device does not support measuring the carrier, or has no wideband
receiver, this command will also produce an error.

Signed-off-by: Sean Young 
---
 utils/ir-ctl/ir-ctl.1.in | 4 
 1 file changed, 4 deletions(-)

diff --git a/utils/ir-ctl/ir-ctl.1.in b/utils/ir-ctl/ir-ctl.1.in
index f42d8da0..2a148c70 100644
--- a/utils/ir-ctl/ir-ctl.1.in
+++ b/utils/ir-ctl/ir-ctl.1.in
@@ -224,10 +224,6 @@ To send the pulse and space file \fBplay\fR on emitter 3:
 To send the rc-5 hauppauge '1' scancode:
 .br
\fBir\-ctl \-S rc5:0x1e01
-.PP
-To restore the IR receiver on /dev/lirc2 to the default state:
-.br
-   \fBir\-ctl \-Mn \-\-timeout 125000 \-\-device=/dev/lirc2\fR
 .SH BUGS
 Report bugs to \fBLinux Media Mailing List \fR
 .SH COPYRIGHT
-- 
2.17.1



Re: [PATCH v3 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx

2018-08-13 Thread Sean Young
On Fri, Jul 13, 2018 at 05:38:25PM +0300, Ivaylo Dimitrov wrote:
> Hi,
> 
> On 13.07.2018 15:22, Sean Young wrote:
> > The ir-rx51 is a pwm-based TX driver specific to the N900. This can be
> > handled entirely by the generic pwm-ir-tx driver.
> > 
> > Note that the suspend code in the ir-rx51 driver is unnecessary, since
> > during transmit, the process is not in interruptable sleep. The process
> > is not put to sleep until the transmit completes.
> > 
> > Compile tested only.
> > 
> 
> I would like to see this being tested on a real HW, however I am on a
> holiday for the next week so won't be able to test till I am back.
> 
> @Pali - do you have n900 with fremantle, upstream kernel and pierogi to test
> pwm-ir-tx on it?

It would be nice to have this verified on real hardware, if possible. If
not, I would like to merge this anyway. If there are any problems we can
always later patch any problem in pwm-ir-tx for the n900.


Sean


[PATCH v4 2/6] keytable: add bpf protocols

2018-08-07 Thread Sean Young
Add a few BPF protocols and infrastructure for building them.

Signed-off-by: Sean Young 
---
 configure.ac  |   4 +
 utils/keytable/Makefile.am|   4 +
 utils/keytable/bpf_protocols/Makefile.am  |  21 ++
 utils/keytable/bpf_protocols/bpf_helpers.h| 315 ++
 utils/keytable/bpf_protocols/grundig.c| 126 +++
 utils/keytable/bpf_protocols/manchester.c | 171 ++
 utils/keytable/bpf_protocols/pulse_distance.c | 156 +
 utils/keytable/bpf_protocols/pulse_length.c   | 152 +
 utils/keytable/bpf_protocols/rc_mm.c  | 139 
 v4l-utils.spec.in |   2 +-
 10 files changed, 1089 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/bpf_protocols/Makefile.am
 create mode 100644 utils/keytable/bpf_protocols/bpf_helpers.h
 create mode 100644 utils/keytable/bpf_protocols/grundig.c
 create mode 100644 utils/keytable/bpf_protocols/manchester.c
 create mode 100644 utils/keytable/bpf_protocols/pulse_distance.c
 create mode 100644 utils/keytable/bpf_protocols/pulse_length.c
 create mode 100644 utils/keytable/bpf_protocols/rc_mm.c

diff --git a/configure.ac b/configure.ac
index 08f5a4c5..10f8628b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_CONFIG_FILES([Makefile
utils/libmedia_dev/Makefile
utils/dvb/Makefile
utils/keytable/Makefile
+   utils/keytable/bpf_protocols/Makefile
utils/ir-ctl/Makefile
utils/cx18-ctl/Makefile
utils/ivtv-ctl/Makefile
@@ -172,11 +173,14 @@ AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
 AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
 if test "x$libelf_pkgconfig" = "xyes"; then
+  AC_CHECK_PROG([CLANG], clang, clang)
   AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
 else
   AC_MSG_WARN(libelf library not available)
 fi
 
+AM_CONDITIONAL([BPF_PROTOCOLS], [test x$CLANG = xclang])
+
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index ad251915..b500e2f2 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -13,6 +13,10 @@ endif
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS) $(LIBELF_LIBS)
 
+if BPF_PROTOCOLS
+SUBDIRS = bpf_protocols
+endif
+
 EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace 
gen_keytables.pl ir-keytable.1 rc_maps.cfg
 
 # custom target
diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
new file mode 100644
index ..5e4b3d67
--- /dev/null
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -0,0 +1,21 @@
+# Get Clang's default includes on this system, as opposed to those seen by
+# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - &1 \
+| sed -n '/<...> search starts here:/,/End of search list./{ s| 
\(/.*\)|-idirafter \1|p }')
+
+%.o: %.c
+   $(CLANG) $(CLANG_SYS_INCLUDES) -I$(top_srcdir)/include -target bpf -O2 
-c $<
+
+PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o
+
+all: $(PROTOCOLS)
+
+# custom target
+install-data-local:
+   $(install_sh) -d "$(DESTDIR)$(keytableuserdir)/protocols"
+   $(install_sh) -d "$(DESTDIR)$(keytablesystemdir)/protocols"
+   $(install_sh) $(PROTOCOLS) "$(DESTDIR)$(keytablesystemdir)/protocols"
diff --git a/utils/keytable/bpf_protocols/bpf_helpers.h 
b/utils/keytable/bpf_protocols/bpf_helpers.h
new file mode 100644
index ..8c1b8a23
--- /dev/null
+++ b/utils/keytable/bpf_protocols/bpf_helpers.h
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __BPF_HELPERS_H
+#define __BPF_HELPERS_H
+
+/* helper macro to place programs, maps, license in
+ * different sections in elf_bpf file. Section names
+ * are interpreted by elf_bpf loader
+ */
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+/* helper functions called from eBPF programs written in C */
+static void *(*bpf_map_lookup_elem)(void *map, void *key) =
+(void *) BPF_FUNC_map_lookup_elem;
+static int (*bpf_map_update_elem)(void *map, void *key, void *value,
+   unsigned long long flags) =
+(void *) BPF_FUNC_map_update_elem;
+static int (*bpf_map_delete_elem)(void *map, void *key) =
+(void *) BPF_FUNC_map_delete_elem;
+static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
+(void *) BPF_FUNC_probe_read;
+static unsigned long long (*bpf_ktime_get_ns)(void) =
+(void *) BPF_FUNC_ktime_g

[PATCH v4 0/6] Add BPF decoders to ir-keytable

2018-08-07 Thread Sean Young
Once kernel v4.18 is released with IR BPF decoding, this can be merged
to v4l-utils.

The idea is that IR decoders can be written in C, compiled to BPF relocatable
object file. Any global variables can overriden, so we can supports lots
of variants of similiar protocols (just like in the lircd.conf file).

The existing rc_keymap file format can't be used for variables, so I've
converted the format to toml. An alternative would be to use the existing
lircd.conf file format, but it's a very awkward file to parse in C and it
contains many features which are irrelevant to us.

We use libelf to load the bpf relocatable object file.

After loading our example grundig keymap with bpf decoder, the output of
ir-keytable is:

Found /sys/class/rc/rc0/ (/dev/input/event8) with:
Name: Winbond CIR
Driver: winbond-cir, table: rc-rc6-mce
LIRC device: /dev/lirc0
Attached BPF protocols: grundig
Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo 
mce_kbd rc-6 sharp xmp imon
Enabled protocols: lirc
bus: 25, vendor/product: 10ad:00f1, version: 0x0004
Repeat delay = 500 ms, repeat period = 125 ms

Alternatively, you simply specify the path to the object file on the command
line:

$ ir-keytable -e header_pulse=9000,header_space=4500 -p ./pulse_distance.o

Derek, please note that you can now convert the dish lircd.conf to toml
and load the keymap; it should just work. It would be great to have your
feedback, thank you.

Changes since v4:
 - Various improvments to ir-keytable man page
 - Fixed bug in manchester BPF decoder
 - Fixed bug in lircd2toml wrt toggle_bit

Sean Young (6):
  keytable: add support for BPF based protocols
  keytable: add bpf protocols
  keytable: add toml keymap reader
  keytable: convert keymaps to new toml format
  ir-keytable: add tool to aid migration from lircd
  keytable: improve man page wording

 Makefile.am|4 +-
 configure.ac   |   15 +
 contrib/Makefile.am|3 +-
 contrib/lircd2toml.py  |  527 
 include/linux/bpf.h| 2669 
 utils/keytable/Makefile.am |   13 +-
 utils/keytable/bpf.c   |  515 
 utils/keytable/bpf.h   |  110 +
 utils/keytable/bpf_load.c  |  472 
 utils/keytable/bpf_load.h  |   43 +
 utils/keytable/bpf_protocols/Makefile.am   |   21 +
 utils/keytable/bpf_protocols/bpf_helpers.h |  315 +++
 utils/keytable/bpf_protocols/grundig.c |  126 +
 utils/keytable/bpf_protocols/manchester.c  |  171 ++
 utils/keytable/bpf_protocols/pulse_distance.c  |  156 ++
 utils/keytable/bpf_protocols/pulse_length.c|  152 ++
 utils/keytable/bpf_protocols/rc_mm.c   |  139 +
 utils/keytable/gen_keytables.pl|   33 +-
 utils/keytable/ir-keytable.1.in|   98 +-
 utils/keytable/keytable.c  |  532 +++-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci|   45 -
 utils/keytable/rc_keymaps/adstech_dvb_t_pci.toml   |   48 +
 utils/keytable/rc_keymaps/af9005   |   37 -
 utils/keytable/rc_keymaps/af9005.toml  |   40 +
 utils/keytable/rc_keymaps/alink_dtu_m  |   19 -
 utils/keytable/rc_keymaps/alink_dtu_m.toml |   23 +
 utils/keytable/rc_keymaps/allwinner_ba10_tv_box|   15 -
 utils/keytable/rc_keymaps/allwinner_i12_a20_tv_box |   28 -
 utils/keytable/rc_keymaps/anysee   |   45 -
 utils/keytable/rc_keymaps/anysee.toml  |   49 +
 utils/keytable/rc_keymaps/apac_viewcomp|   32 -
 utils/keytable/rc_keymaps/apac_viewcomp.toml   |   35 +
 utils/keytable/rc_keymaps/astrometa_t2hybrid   |   22 -
 utils/keytable/rc_keymaps/astrometa_t2hybrid.toml  |   26 +
 utils/keytable/rc_keymaps/asus_pc39|   40 -
 utils/keytable/rc_keymaps/asus_pc39.toml   |   44 +
 utils/keytable/rc_keymaps/asus_ps3_100 |   42 -
 utils/keytable/rc_keymaps/asus_ps3_100.toml|   46 +
 utils/keytable/rc_keymaps/ati_tv_wonder_hd_600 |   25 -
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600.toml  |   28 +
 utils/keytable/rc_keymaps/ati_x10  |   49 -
 utils/keytable/rc_keymaps/ati_x10.toml |   52 +
 utils/keytable/rc_keymaps/avermedia|   37 -
 utils/keytable/rc_keymaps/avermedia.toml   |   40 +
 utils/keytable/rc_keymaps/avermedia_a16d   |   35 -
 utils/keytable/rc_keymaps/avermedia_a16d.toml  |   38 +
 utils/keytable/rc_keymaps/avermedia_cardbus|   55 -
 utils/keytable/rc_keymaps/avermedia_cardbus.toml   |   58 +
 utils/keytable/rc_keymaps/avermedia_dvbt   |   35 -
 utils/keytable/rc_keymaps/avermedia_dvbt.toml

[PATCH v4 5/6] ir-keytable: add tool to aid migration from lircd

2018-08-07 Thread Sean Young
This python script is written to help users translate their lircd.conf
remote definition to ir-keytable toml format. The tool does not cover
every possible lircd.conf, but the majority should work.

./lircd2toml.py PD-202.lircd.conf -o PD-202.toml

Signed-off-by: Sean Young 
---
 contrib/Makefile.am   |   3 +-
 contrib/lircd2toml.py | 527 ++
 2 files changed, 529 insertions(+), 1 deletion(-)
 create mode 100755 contrib/lircd2toml.py

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index d41dc539..db572c54 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -25,4 +25,5 @@ EXTRA_DIST = \
cobalt-ctl \
parsers \
pci_traffic \
-   v4l_rec.pl
+   v4l_rec.pl \
+   lircd2toml.py
diff --git a/contrib/lircd2toml.py b/contrib/lircd2toml.py
new file mode 100755
index ..f9408ecc
--- /dev/null
+++ b/contrib/lircd2toml.py
@@ -0,0 +1,527 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2018 Sean Young 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 2 of the License.
+#
+
+import sys
+import os
+import math
+import argparse
+
+class LircdParser:
+def __init__(self, filename, encoding):
+self.lineno=0
+self.filename=filename
+self.encoding=encoding
+
+def getline(self):
+while True:
+self.lineno += 1
+line = ""
+try:
+line = self.fh.readline();
+except IOError as e:
+self.error("reading file failed: {}".format(e))
+except UnicodeDecodeError as e:
+self.error("decoding file failed: {}".format(e))
+if line == "":
+return None
+line = line.strip()
+if len(line) == 0 or line[0] == '#':
+continue
+return line
+
+def warning(self, msg):
+print("{}:remote {}: warning: {}".format(self.filename, self.lineno, 
msg), file=sys.stderr)
+
+def error(self, msg):
+print("{}:remote {}: error: {}".format(self.filename, self.lineno, 
msg), file=sys.stderr)
+
+def parse(self):
+remotes = []
+try:
+self.fh=open(self.filename, encoding=self.encoding)
+except IOError as e:
+print("{}: error: {}".format(self.filename, e), file=sys.stderr)
+return remotes
+
+while True:
+line = self.getline()
+if line == None:
+break
+a = line.split(maxsplit=2)
+if a[0] != 'begin' or a[1] != 'remote':
+self.error("expected 'begin remote', got '{} {}'".format(a[0], 
a[1]))
+return None
+if len(a) > 2 and a[2][0] != '#':
+self.error("unexpected {}".format(a[2]))
+return None
+
+remote = self.read_remote()
+if remote == None:
+return None
+
+remotes.append(remote)
+
+return remotes
+
+def read_remote(self):
+remote = {}
+while True:
+line = self.getline()
+if line == None:
+self.error("unexpected end of file")
+return None
+
+a = line.split()
+if len(a) < 2:
+self.error("expecting at least two keywords")
+return None
+
+if a[0] in ['name', 'driver', 'serial_mode']:
+remote[a[0]] = line.split(maxsplit=2)[1]
+elif a[0] in ['flags']:
+flags = []
+s=line.split(maxsplit=2)[1]
+for f in s.split(sep='|'):
+flags.append(f.strip().lower())
+remote[ 'flags' ] = flags
+elif a[0] == 'begin':
+if a[1] == 'codes':
+codes = self.read_codes()
+if codes == None:
+return None
+remote['codes'] = codes
+elif a[1] == 'raw_codes':
+codes = self.read_raw_codes()
+if codes == None:
+return None
+remote['raw_codes'] = codes
+else:
+self.error("{} unexpected".format(a[1]))
+elif a[0] == 'end':
+return remote
+else:
+k = a.pop(0)
+vals = []
+for v in a:
+if v[0] == '#':
+break
+vals.append(int(v, 0))
+remote[k] = vals
+
+def read_codes(self):
+codes = {}
+while True:
+line = self.getline()
+if 

[PATCH v4 6/6] keytable: improve man page wording

2018-08-07 Thread Sean Young
ir should be replaced with rc.

Signed-off-by: Sean Young 
---
 utils/keytable/ir-keytable.1.in | 86 ++---
 1 file changed, 47 insertions(+), 39 deletions(-)

diff --git a/utils/keytable/ir-keytable.1.in b/utils/keytable/ir-keytable.1.in
index 60f9dfe9..ffd2d705 100644
--- a/utils/keytable/ir-keytable.1.in
+++ b/utils/keytable/ir-keytable.1.in
@@ -4,83 +4,91 @@ ir\-keytable \- a swiss\-knife tool to handle Remote 
Controllers.
 .SH SYNOPSIS
 .B ir\-keytable
 [\fIOPTION\fR]... \fI\-\-device\fR [\fI/dev/input/event* device\fR]
-.br 
+.br
 .B ir\-keytable
-[\fIOPTION\fR]... \fI\-\-sysdev\fR [\fIir class (f. ex. rc0)\fR]
-.br 
+[\fIOPTION\fR]... \fI\-\-sysdev\fR [\fIrc class (f. ex. rc0)\fR]
+.br
 .B ir\-keytable
 [\fIOPTION\fR]... [\fIfor using the rc0 sysdev\fR]
 .SH DESCRIPTION
 ir\-keytable is a tool that lists the Remote Controller devices, allows one to
-get/set IR keycode/scancode tables, test events generated by IR, and to
-adjust other Remote Controller options.
-.PP 
+get/set rc keycode/scancode tables, set protocol decoder, test events
+generated by a rc device, and to adjust other Remote Controller options.
+.PP
 Note: You need to have read permissions on /dev/input for most of the
 options to work.
 .SH OPTIONS
-.TP 
+.TP
 \fB\-a\fR, \fB\-\-auto\-load\fR=\fICFGFILE\fR
-Auto\-load a table, based on a configuration file. Only works with sysdev.
-.TP 
+Auto\-load a table, based on a configuration file. Only works with
+\fB\-\-sysdev\fR.
+.TP
 \fB\-c\fR, \fB\-\-clear\fR
-clears the old table
-.TP 
+Clears the scancode to keycode mappings.
+.TP
 \fB\-d\fR, \fB\-\-device\fR=\fIDEV\fR
-ir device to control
+Use specified input device.
 .TP
 \fB\-D\fR, \fB\-\-delay\fR=\fIDELAY\fR
-Sets the delay before repeating a keystroke
-.TP 
+Sets the delay before repeating a keystroke.
+.TP
 \fB\-k\fR, \fB\-\-set\-key\fR=\fISCANKEY\fR
-Change scan/key pairs
-.TP 
+Set scancode to keycode mapping.
+.TP
 \fB\-p\fR, \fB\-\-protocol\fR=\fIPROTOCOL\fR
-Comma seperated list of protocols to enabled (the other ones will be 
disabled). Alternatively, this is the path to a BPF protocol to be loaded.
+Comma seperated list of kernel protocols or BPF protocol to enable. All
+other protocols are disabled.
 .TP
 \fB\-e\fR, \fB\-\-parameter\fR=\fIPARAMETER\fR
-Commma seperated list of parameters for the BPF protocol
+Commma seperated list of parameters for the BPF protocol.
 .TP
 \fB\-P\fR, \fB\-\-period\fR\=\fiPERIOD\fR
-Sets the period to repeat a keystroke
-.TP 
+Sets the period to repeat a keystroke.
+.TP
 \fB\-r\fR, \fB\-\-read\fR
-reads the current scancode/keycode table
-.TP 
+Read and show the current scancode to keycode mapping.
+.TP
 \fB\-s\fR, \fB\-\-sysdev\fR=\fISYSDEV\fR
-ir class device to control
-.TP 
+rc device to control
+.TP
 \fB\-t\fR, \fB\-\-test\fR
-test if IR is generating events
-.TP 
+test if the rc device is generating events
+.TP
 \fB\-v\fR, \fB\-\-verbose\fR
-enables debug messages
-.TP 
+Enables debug messages.
+.TP
 \fB\-w\fR, \fB\-\-write\fR=\fITABLE\fR
-write (adds) the scancodes to the device scancode/keycode table from the
-specified \fITABLE\fR file
-.TP 
+Reads the protocols and scancode to keycode mapping from the \fITABLE\fR file,
+and enables those on the rc device.
+.TP
 \fB\-?\fR, \fB\-\-help\fR
 Prints the help message
-.TP 
+.TP
 \fB\-\-usage\fR
 Give a short usage message
-.TP 
+.TP
 \fB\-V\fR, \fB\-\-version\fR
 print the v4l2\-utils version
-.PP 
+.PP
 Mandatory or optional arguments to long options are also mandatory or optional
 for any corresponding short options. Options can be combined together.
 .SS The options arguments are:
 .IP \fIDEV\fR
 the /dev/input/event* device to control
 .IP \fISYSDEV\fR
-the ir class as found at /sys/class/rc
+the rc class as found at /sys/class/rc
 .IP \fITABLE\fR
-a file wit a set of scancode=keycode value pairs
+a toml file with a list of protocols and scancode to keycode mappings.
 .IP \fISCANKEY\fR
 a set of scancode1=keycode1,scancode2=keycode2.. value pairs
 .IP \fIPROTOCOL\fR
-Comma separated list of protocols to be enabled (case insensitive). Supported 
kernel protocols are: NEC, RC-5, RC-6, JVC, SONY, SANYO, LIRC, RC-5-SZ, SHARP, 
MCE-KBD, XMP, IMON, other, all. There are also BPF protocols: manchester, 
rc_mm, pulse_distance, grundig. Alternatively, this can be the path to a BPF 
protocol file to be loaded.
+Comma separated list of kernel protocols to be enabled (case insensitive).
+Supported kernel protocols are: \fBnec\fR, \fBrc\-5\fR, \fBrc\-6\fR, \fBjvc\fR,
+\fBsony\fR, \fBsanyo\fR, \fBrc\-5\-sz\fR, \fBsharp\fR, \fBmce\-kbd\fR,
+\fBxmp\fR, \fBimon\fR, \fBother\fR, \fBall\fR. It can also be a BPF protocol,
+e.g. \fBmanchester\fR, \fBrc_mm\fR, \fBpulse_distance\fR, \fBpulse_length\fR.
+If it does not match any of these, it is taken to be the path of BPF decoder
+to be loaded.
 .IP \fIPARAMETERS\fR
 Comma seperated list of parameters for the BPF protocol being loaded. They 
have the format of name=value

[PATCH v4 3/6] keytable: add toml keymap reader

2018-08-07 Thread Sean Young
We would like to define BPF based IR protocols from rc_keymaps. We will
need per-protocol parameters, so we need a more flexible format than
the existing plain-text format.

At some point in the future it would nice to change rc-core keycode
mapping to protocol + 64 bit scancode -> keycode, rather the existing
32 bit scancode -> keycode. In order to make this possible, we want
the scancodes to be specified for their protocol, in case multiple
protocols are selected.

Signed-off-by: Sean Young 
---
 utils/keytable/Makefile.am |2 +-
 utils/keytable/bpf_load.c  |   21 +-
 utils/keytable/bpf_load.h  |2 +-
 utils/keytable/keytable.c  |  222 +-
 utils/keytable/toml.c  | 1903 
 utils/keytable/toml.h  |  110 +++
 6 files changed, 2250 insertions(+), 10 deletions(-)
 create mode 100644 utils/keytable/toml.c
 create mode 100644 utils/keytable/toml.h

diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index b500e2f2..90e4c8c8 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -4,7 +4,7 @@ sysconf_DATA = rc_maps.cfg
 keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
 
-ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h
+ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
 
 if HAVE_LIBELF
 ir_keytable_SOURCES += bpf.c bpf_load.c bpf.h bpf_load.h
diff --git a/utils/keytable/bpf_load.c b/utils/keytable/bpf_load.c
index 5e9040a7..6f8a27b0 100644
--- a/utils/keytable/bpf_load.c
+++ b/utils/keytable/bpf_load.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include "toml.h"
 #include "bpf.h"
 #include "bpf_load.h"
 
@@ -43,6 +44,7 @@ struct bpf_file {
Elf_Data *data;
int strtabidx;
Elf_Data *symbols;
+   struct toml_table_t *toml;
 };
 
 static int load_and_attach(int lirc_fd, struct bpf_file *bpf_file, const char 
*name, struct bpf_insn *prog, int size)
@@ -184,6 +186,21 @@ static int parse_relo_and_apply(struct bpf_file *bpf_file, 
GElf_Shdr *shdr,
 
if (!bpf_param(sym_name, )) {
// done
+   } else if (bpf_file->toml &&
+  (raw = toml_raw_in(bpf_file->toml, 
sym_name)) != NULL) {
+   int64_t val64;
+
+   if (toml_rtoi(raw, )) {
+   printf(_("variable %s not a integer: 
%s\n"), sym_name, raw);
+   return 1;
+   }
+
+   if (value < INT_MIN && value > UINT_MAX) {
+   printf(_("variable %s out of range: 
%s\n"), sym_name, raw);
+   return 1;
+   }
+
+   value = val64;
} else if (sym.st_shndx == bpf_file->dataidx) {
int32_t *p = (bpf_file->data->d_buf + 
sym.st_value);
value = *p;
@@ -324,9 +341,9 @@ static int load_elf_maps_section(struct bpf_file *bpf_file)
return nr_maps;
 }
 
-int load_bpf_file(const char *path, int lirc_fd)
+int load_bpf_file(const char *path, int lirc_fd, struct toml_table_t *toml)
 {
-   struct bpf_file bpf_file = {};
+   struct bpf_file bpf_file = { .toml = toml };
int fd, i, ret;
Elf *elf;
GElf_Ehdr ehdr;
diff --git a/utils/keytable/bpf_load.h b/utils/keytable/bpf_load.h
index ec9763e4..2775607f 100644
--- a/utils/keytable/bpf_load.h
+++ b/utils/keytable/bpf_load.h
@@ -36,7 +36,7 @@ struct bpf_map_data {
  *
  * returns zero on success
  */
-int load_bpf_file(const char *path, int lirc_fd);
+int load_bpf_file(const char *path, int lirc_fd, struct toml_table_t *toml);
 
 int bpf_param(const char *name, int *val);
 
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index d058c856..9cec8694 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -33,6 +33,7 @@
 
 #include "ir-encode.h"
 #include "parse.h"
+#include "toml.h"
 #include "bpf.h"
 #include "bpf_load.h"
 
@@ -206,7 +207,7 @@ static void write_sysfs_protocols(enum sysfs_protocols 
protocols, FILE *fp, cons
}
 }
 
-static int parse_code(char *string)
+static int parse_code(const char *string)
 {
struct parse_event *p;
 
@@ -276,6 +277,7 @@ static enum sysfs_protocols ch_proto = 0;
 
 struct bpf_protocol {
struct bpf_protocol *next;
+   struct toml_table_t *toml;
char *name;
 };
 
@@ -315,7 +317,57 @@ struct rc_device {
enum sysfs_protocols supported, current; /* Current and supported IR 
protocols */
 };
 
-static error_t parse_keyfile(char *fname, char **table)
+static bool co

Re: [PATCH] media: rc: read out of bounds if bpf reports high protocol number

2018-07-31 Thread Sean Young
Hi Hias,

On Mon, Jul 30, 2018 at 09:20:18PM +0200, Matthias Reichl wrote:
> On Sat, Jul 28, 2018 at 10:11:15AM +0100, Sean Young wrote:
> > The repeat period is read from a static array. If a keydown event is
> > reported from bpf with a high protocol number, we read out of bounds. This
> > is unlikely to end up with a reasonable repeat period at the best of times,
> > in which case no timely key up event is generated.
> > 
> > Signed-off-by: Sean Young 
> > ---
> >  drivers/media/rc/rc-main.c | 12 ++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
> > index 2e222d9ee01f..a24850be1f4f 100644
> > --- a/drivers/media/rc/rc-main.c
> > +++ b/drivers/media/rc/rc-main.c
> > @@ -679,6 +679,14 @@ static void ir_timer_repeat(struct timer_list *t)
> > spin_unlock_irqrestore(>keylock, flags);
> >  }
> >  
> > +unsigned int repeat_period(int protocol)
> > +{
> > +   if (protocol >= ARRAY_SIZE(protocols))
> > +   return 100;
> 
> 100 seems a bit arbitrarily chosen to me. Wouldn't it be better to
> (re-)use eg protocols[RC_PROTO_UNKNOWN].repeat_period here?

That's a good idea! I think the patch is already on its way to be merged,
but we can patch this later.

What we really need is a way to set the repeat period and minimum timeout
for a bpf protocol.


Sean


[GIT FIXES FOR v4.18] out of bounds memory read

2018-07-29 Thread Sean Young
Hi Mauro,

Please pull this fix for v4.18, if possible.

Thanks,

Sean

The following changes since commit 92cab799bbc6fa1fca84bd1692285a5f926c17e9:

  media: bpf: ensure bpf program is freed on detach (2018-07-26 08:39:18 -0400)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.18g

for you to fetch changes up to 0922465cba37c45c1db0786b7fa1ea822bd647a5:

  media: rc: read out of bounds if bpf reports high protocol number (2018-07-29 
16:31:45 +0100)


Sean Young (1):
  media: rc: read out of bounds if bpf reports high protocol number

 drivers/media/rc/rc-main.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)


Re: [PATCH v3 0/5] Add BPF decoders to ir-keytable

2018-07-28 Thread Sean Young
Hi Hias,

On Sat, Jul 21, 2018 at 08:13:27PM +0200, Matthias Reichl wrote:
> Hi Sean,
> 
> thanks a lot, this is a really nice new feature!

Thank you for testing it and finding all those issues, it has become much
better from your testing.

> On Fri, Jul 13, 2018 at 03:30:06PM +0100, Sean Young wrote:
> > Once kernel v4.18 is released with IR BPF decoding, this can be merged
> > to v4l-utils.
> > 
> > The idea is that IR decoders can be written in C, compiled to BPF 
> > relocatable
> > object file. Any global variables can overriden, so we can supports lots
> > of variants of similiar protocols (just like in the lircd.conf file).
> > 
> > The existing rc_keymap file format can't be used for variables, so I've
> > converted the format to toml. An alternative would be to use the existing
> > lircd.conf file format, but it's a very awkward file to parse in C and it
> > contains many features which are irrelevant to us.
> > 
> > We use libelf to load the bpf relocatable object file.
> > 
> > After loading our example grundig keymap with bpf decoder, the output of
> > ir-keytable is:
> > 
> > Found /sys/class/rc/rc0/ (/dev/input/event8) with:
> > Name: Winbond CIR
> > Driver: winbond-cir, table: rc-rc6-mce
> > LIRC device: /dev/lirc0
> > Attached BPF protocols: grundig
> > Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo 
> > mce_kbd rc-6 sharp xmp imon
> > Enabled protocols: lirc
> > bus: 25, vendor/product: 10ad:00f1, version: 0x0004
> > Repeat delay = 500 ms, repeat period = 125 ms
> > 
> > Alternatively, you simply specify the path to the object file on the command
> > line:
> > 
> > $ ir-keytable -e header_pulse=9000,header_space=4500 -p ./pulse_distance.o
> > 
> > Derek, please note that you can now convert the dish lircd.conf to toml
> > and load the keymap; it should just work. It would be great to have your
> > feedback, thank you.
> 
> I did a few tests with one of my RC-5 remotes, this lircd.conf file
> https://github.com/PiSupply/JustBoom/blob/master/LIRC/lircd.conf
> and kernel 4.18-rc5 on RPi2, with the 32bit ARM kernel and
> gpio-ir-recv, and on LePotato / aarch64 with meson-ir.
> 
> lircd2toml.py did a really good job on converting it, the only
> thing missing was the toggle_bit.

Right, there was a bug in lirc2html.py. I've added a fix to my bpf branch:

https://git.linuxtv.org/syoung/v4l-utils.git/log/?h=bpf

> When testing the converted toml (with "toggle_bit = 11" added
> and the obvious volume keycode fixes) I noticed a couple of issues:
> 
> Buttons seem to be "stuck". The scancode is decoded, key_down
> event is generated, but after release the key_down events repeat
> indefinitely - with the built-in rc-5 decoder this works fine.
> 
> root@upstream:/home/hias/ir-test# ir-keytable -c -w justboom.toml -t
> Old keytable cleared
> Wrote 12 keycode(s) to driver
> Protocols changed to
> Loaded BPF protocol manchester
> Testing events. Please, press CTRL-C to abort.
> 29.065820: lirc protocol(66): scancode = 0x141b
> 29.065890: event type EV_MSC(0x04): scancode = 0x141b
> 29.065890: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 29.065890: event type EV_SYN(0x00).
> 29.570059: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 29.570059: event type EV_SYN(0x00).
> 29.710062: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 29.710062: event type EV_SYN(0x00).
> 29.850057: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 29.850057: event type EV_SYN(0x00).
> 29.990057: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 29.990057: event type EV_SYN(0x00).
> 30.130055: event type EV_KEY(0x01) key_down: KEY_DOWN(0x006c)
> 30.130055: event type EV_SYN(0x00).
> ...

Thanks, I had not seen this yet either. There is a fix here:

https://www.mail-archive.com/linux-media@vger.kernel.org/msg133813.html

> Even scancodes, eg KEY_UP / scancode 0x141a, aren't decoded at
> all, only odd scancodes work. My guess is the manchester decoder
> could have a problem when the last bit is zero and the message
> doesn't end with a pulse, but a (rather long) timeout.

Yep, yet another bug! I'v added a fix here:

https://git.linuxtv.org/syoung/v4l-utils.git/log/?h=bpf

> (Re-)loading a bpf decoder only works 8 times. The 9th attempt
> gives an error message.
> 
> # for i in `seq 1 9` ; do ir-keytable -p manchester ; done
> Protocols changed to
> Loaded BPF protocol manchester
> Protocols changed to
> Loaded BPF protocol manchester
> Protocols changed to
> Loaded BPF protocol manchester
> Protocols changed to
> Loaded BPF

[PATCH] media: rc: read out of bounds if bpf reports high protocol number

2018-07-28 Thread Sean Young
The repeat period is read from a static array. If a keydown event is
reported from bpf with a high protocol number, we read out of bounds. This
is unlikely to end up with a reasonable repeat period at the best of times,
in which case no timely key up event is generated.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 2e222d9ee01f..a24850be1f4f 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -679,6 +679,14 @@ static void ir_timer_repeat(struct timer_list *t)
spin_unlock_irqrestore(>keylock, flags);
 }
 
+unsigned int repeat_period(int protocol)
+{
+   if (protocol >= ARRAY_SIZE(protocols))
+   return 100;
+
+   return protocols[protocol].repeat_period;
+}
+
 /**
  * rc_repeat() - signals that a key is still pressed
  * @dev:   the struct rc_dev descriptor of the device
@@ -691,7 +699,7 @@ void rc_repeat(struct rc_dev *dev)
 {
unsigned long flags;
unsigned int timeout = nsecs_to_jiffies(dev->timeout) +
-   msecs_to_jiffies(protocols[dev->last_protocol].repeat_period);
+   msecs_to_jiffies(repeat_period(dev->last_protocol));
struct lirc_scancode sc = {
.scancode = dev->last_scancode, .rc_proto = dev->last_protocol,
.keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED,
@@ -803,7 +811,7 @@ void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, 
u32 scancode,
 
if (dev->keypressed) {
dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) +
-   msecs_to_jiffies(protocols[protocol].repeat_period);
+   msecs_to_jiffies(repeat_period(protocol));
mod_timer(>timer_keyup, dev->keyup_jiffies);
}
spin_unlock_irqrestore(>keylock, flags);
-- 
2.17.1



Re: Logspam with "two consecutive events of type space" on gpio-ir-recv and meson-ir

2018-07-25 Thread Sean Young
Hi Hias,

On Sat, Jul 21, 2018 at 09:04:21PM +0200, Matthias Reichl wrote:
> Hi Sean,
> 
> I noticed that on 4.18-rc5 I get dmesg logspam with
> "rc rc0: two consecutive events of type space" on gpio-ir-recv
> and meson-ir - mceusb seems to be fine (haven't tested with
> other IR receivers yet).
> 
> With the default, short IR timeout I get these messages on each
> IR message, which is rather spammy on longer button presses:
> 
> [ 1988.053215] rc rc0: two consecutive events of type space
> [ 1988.173189] rc rc0: two consecutive events of type space
> [ 1988.283188] rc rc0: two consecutive events of type space
> [ 1988.403185] rc rc0: two consecutive events of type space
> [ 1988.513193] rc rc0: two consecutive events of type space
> [ 1988.623190] rc rc0: two consecutive events of type space
> [ 1988.743190] rc rc0: two consecutive events of type space
> [ 1988.853193] rc rc0: two consecutive events of type space
> [ 1988.973193] rc rc0: two consecutive events of type space
> [ 1989.083193] rc rc0: two consecutive events of type space
> [ 1989.193196] rc rc0: two consecutive events of type space
> [ 1989.313216] rc rc0: two consecutive events of type space
> [ 1989.423197] rc rc0: two consecutive events of type space
> ...
> 
> With a longer timeout (eg 125ms and testing with a RC-5 remote) I get
> these messages once per button press.
> 
> Eg on 2 shorter button presses:
> # ir-keytable -t
> Testing events. Please, press CTRL-C to abort.
> 2045.990064: lirc protocol(rc5): scancode = 0x101b
> 2045.990123: event type EV_MSC(0x04): scancode = 0x101b
> 2045.990123: event type EV_SYN(0x00).
> 2046.100077: lirc protocol(rc5): scancode = 0x101b
> 2046.100126: event type EV_MSC(0x04): scancode = 0x101b
> 2046.100126: event type EV_SYN(0x00).
> 2046.230075: lirc protocol(rc5): scancode = 0x101b
> 2046.230118: event type EV_MSC(0x04): scancode = 0x101b
> 2046.230118: event type EV_SYN(0x00).
> 2050.970078: lirc protocol(rc5): scancode = 0x101b toggle=1
> 2050.970137: event type EV_MSC(0x04): scancode = 0x101b
> 2050.970137: event type EV_SYN(0x00).
> 2051.080071: lirc protocol(rc5): scancode = 0x101b toggle=1
> 2051.080119: event type EV_MSC(0x04): scancode = 0x101b
> 2051.080119: event type EV_SYN(0x00).
> 2051.210056: lirc protocol(rc5): scancode = 0x101b toggle=1
> 2051.210099: event type EV_MSC(0x04): scancode = 0x101b
> 2051.210099: event type EV_SYN(0x00).
> 
> I get this in dmesg:
> [ 2045.933635] rc rc0: two consecutive events of type space
> [ 2050.923689] rc rc0: two consecutive events of type space
> 
> So it looks like that might be a timeout-related issue with
> these 2 drivers.

This does not have a proper fix yet, however we have a workaround
here:

https://git.linuxtv.org/media_tree.git/commit/?h=fixes=0ca54b29054151b7a52cbb8904732280afe5a302


Sean


[PATCH v4l-utils] ir-ctl: make nec32 scancode encoding match kernel

2018-07-17 Thread Sean Young
For the nec32 encoding, the kernel swaps in the "inverted" and normal
address and command. This might not be the most logical scheme.

Signed-off-by: Sean Young 
---
 utils/common/ir-encode.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/utils/common/ir-encode.c b/utils/common/ir-encode.c
index c7e319eb..ccc75032 100644
--- a/utils/common/ir-encode.c
+++ b/utils/common/ir-encode.c
@@ -64,15 +64,10 @@ static int nec_encode(enum rc_proto proto, unsigned 
scancode, unsigned *buf)
add_byte(~scancode);
break;
case RC_PROTO_NEC32:
-   /*
-* At the time of writing kernel software nec decoder
-* reverses the bit order so it will not match. Hardware
-* decoders do not have this issue.
-*/
-   add_byte(scancode >> 24);
add_byte(scancode >> 16);
-   add_byte(scancode >> 8);
+   add_byte(scancode >> 24);
add_byte(scancode);
+   add_byte(scancode >> 8);
break;
}
 
-- 
2.11.0



[PATCH 2/2] media: rc: self test for IR encoders and decoders

2018-07-17 Thread Sean Young
ir-loopback can transmit IR on one rc device and check the correct
scancode and protocol is decoded on a different rc device. This can be
used to check IR transmission between two rc devices. Using rc-loopback,
we use it to check the IR encoders and decoders themselves.

Signed-off-by: Sean Young 
---
 tools/testing/selftests/Makefile  |   1 +
 tools/testing/selftests/ir/.gitignore |   1 +
 tools/testing/selftests/ir/Makefile   |  19 ++
 tools/testing/selftests/ir/config |  12 ++
 tools/testing/selftests/ir/ir-loopback.c  | 209 ++
 tools/testing/selftests/ir/ir-loopback.sh |  28 +++
 6 files changed, 270 insertions(+)
 create mode 100644 tools/testing/selftests/ir/.gitignore
 create mode 100644 tools/testing/selftests/ir/Makefile
 create mode 100644 tools/testing/selftests/ir/config
 create mode 100644 tools/testing/selftests/ir/ir-loopback.c
 create mode 100755 tools/testing/selftests/ir/ir-loopback.sh

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index f1fe492c8e17..995034ea5546 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -15,6 +15,7 @@ TARGETS += futex
 TARGETS += gpio
 TARGETS += intel_pstate
 TARGETS += ipc
+TARGETS += ir
 TARGETS += kcmp
 TARGETS += kvm
 TARGETS += lib
diff --git a/tools/testing/selftests/ir/.gitignore 
b/tools/testing/selftests/ir/.gitignore
new file mode 100644
index ..87bf2989b678
--- /dev/null
+++ b/tools/testing/selftests/ir/.gitignore
@@ -0,0 +1 @@
+ir-loopback
diff --git a/tools/testing/selftests/ir/Makefile 
b/tools/testing/selftests/ir/Makefile
new file mode 100644
index ..501b464e56b5
--- /dev/null
+++ b/tools/testing/selftests/ir/Makefile
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0
+uname_M := $(shell uname -m 2>/dev/null || echo not)
+ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
+ifeq ($(ARCH),i386)
+ARCH := x86
+   CFLAGS := -DCONFIG_X86_32 -D__i386__
+endif
+ifeq ($(ARCH),x86_64)
+   ARCH := x86
+   CFLAGS := -DCONFIG_X86_64 -D__x86_64__
+endif
+
+CFLAGS += -I../../../../usr/include/
+
+TEST_PROGS := ir-loopback.sh
+
+TEST_GEN_PROGS := ir-loopback
+
+include ../lib.mk
diff --git a/tools/testing/selftests/ir/config 
b/tools/testing/selftests/ir/config
new file mode 100644
index ..78e041e9319e
--- /dev/null
+++ b/tools/testing/selftests/ir/config
@@ -0,0 +1,12 @@
+CONFIG_RC_CORE=y
+CONFIG_RC_LOOPBACK=y
+CONFIG_IR_NEC_DECODER=m
+CONFIG_IR_RC5_DECODER=m
+CONFIG_IR_RC6_DECODER=m
+CONFIG_IR_JVC_DECODER=m
+CONFIG_IR_SONY_DECODER=m
+CONFIG_IR_SANYO_DECODER=m
+CONFIG_IR_SHARP_DECODER=m
+CONFIG_IR_MCE_KBD_DECODER=m
+CONFIG_IR_XMP_DECODER=m
+CONFIG_IR_IMON_DECODER=m
diff --git a/tools/testing/selftests/ir/ir-loopback.c 
b/tools/testing/selftests/ir/ir-loopback.c
new file mode 100644
index ..95b6f0f2f1f5
--- /dev/null
+++ b/tools/testing/selftests/ir/ir-loopback.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0
+// test ir decoder
+//
+// Copyright (C) 2018 Sean Young 
+
+// When sending LIRC_MODE_SCANCODE, the IR will be encoded. rc-loopback
+// will send this IR to the receiver side, where we try to read the decoded
+// IR. Decoding happens in a separate kernel thread, so we will need to
+// wait until that is scheduled, hence we use poll to check for read
+// readiness.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TEST_SCANCODES 10
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+static const struct {
+   enum rc_proto proto;
+   const char *name;
+   unsigned int mask;
+   const char *decoder;
+} protocols[] = {
+   { RC_PROTO_RC5, "rc-5", 0x1f7f, "rc-5" },
+   { RC_PROTO_RC5X_20, "rc-5x-20", 0x1f7f3f, "rc-5" },
+   { RC_PROTO_RC5_SZ, "rc-5-sz", 0x2fff, "rc-5-sz" },
+   { RC_PROTO_JVC, "jvc", 0x, "jvc" },
+   { RC_PROTO_SONY12, "sony-12", 0x1f007f, "sony" },
+   { RC_PROTO_SONY15, "sony-15", 0xff007f, "sony" },
+   { RC_PROTO_SONY20, "sony-20", 0x1fff7f, "sony" },
+   { RC_PROTO_NEC, "nec", 0x, "nec" },
+   { RC_PROTO_NECX, "nec-x", 0xff, "nec" },
+   { RC_PROTO_NEC32, "nec-32", 0x, "nec" },
+   { RC_PROTO_SANYO, "sanyo", 0x1f, "sanyo" },
+   { RC_PROTO_RC6_0, "rc-6-0", 0x, "rc-6" },
+   { RC_PROTO_RC6_6A_20, "rc-6-6a-20", 0xf, "rc-6" },
+   { RC_PROTO_RC6_6A_24, "rc-6-6a-24", 0xff, "rc-6" },
+   { RC_PROTO_RC6_6A_32, "rc-6-6a-32", 0x, "rc-6" },
+   { RC_PROTO_RC6_MCE, "rc-6-mc

[PATCH 1/2] media: rc: nec keymaps should specify the nec variant they use

2018-07-17 Thread Sean Young
The rc_proto field should list the exact variant used by the remote. This
does not change the decoder used, but helps with using keymaps for
transmit purposes.

Signed-off-by: Sean Young 
---
 drivers/media/rc/keymaps/rc-behold.c  | 2 +-
 drivers/media/rc/keymaps/rc-delock-61959.c| 2 +-
 drivers/media/rc/keymaps/rc-imon-rsc.c| 2 +-
 drivers/media/rc/keymaps/rc-it913x-v1.c   | 2 +-
 drivers/media/rc/keymaps/rc-it913x-v2.c   | 2 +-
 drivers/media/rc/keymaps/rc-msi-digivox-iii.c | 2 +-
 drivers/media/rc/keymaps/rc-pixelview-002t.c  | 2 +-
 drivers/media/rc/keymaps/rc-pixelview-mk12.c  | 2 +-
 drivers/media/rc/keymaps/rc-reddo.c   | 2 +-
 drivers/media/rc/keymaps/rc-terratec-slim.c   | 2 +-
 drivers/media/rc/keymaps/rc-tivo.c| 2 +-
 drivers/media/rc/keymaps/rc-total-media-in-hand.c | 2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/media/rc/keymaps/rc-behold.c 
b/drivers/media/rc/keymaps/rc-behold.c
index 9b1b57e3c875..e1b2c8e26883 100644
--- a/drivers/media/rc/keymaps/rc-behold.c
+++ b/drivers/media/rc/keymaps/rc-behold.c
@@ -115,7 +115,7 @@ static struct rc_map_list behold_map = {
.map = {
.scan = behold,
.size = ARRAY_SIZE(behold),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_BEHOLD,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-delock-61959.c 
b/drivers/media/rc/keymaps/rc-delock-61959.c
index 62de69d78d92..da21d6d6d79f 100644
--- a/drivers/media/rc/keymaps/rc-delock-61959.c
+++ b/drivers/media/rc/keymaps/rc-delock-61959.c
@@ -60,7 +60,7 @@ static struct rc_map_list delock_61959_map = {
.map = {
.scan = delock_61959,
.size = ARRAY_SIZE(delock_61959),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_DELOCK_61959,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-imon-rsc.c 
b/drivers/media/rc/keymaps/rc-imon-rsc.c
index 83e4564aaa22..6f7ee4859682 100644
--- a/drivers/media/rc/keymaps/rc-imon-rsc.c
+++ b/drivers/media/rc/keymaps/rc-imon-rsc.c
@@ -59,7 +59,7 @@ static struct rc_map_list imon_rsc_map = {
.map = {
.scan = imon_rsc,
.size = ARRAY_SIZE(imon_rsc),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_IMON_RSC,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-it913x-v1.c 
b/drivers/media/rc/keymaps/rc-it913x-v1.c
index 908d14848ae8..f1b5c52953ad 100644
--- a/drivers/media/rc/keymaps/rc-it913x-v1.c
+++ b/drivers/media/rc/keymaps/rc-it913x-v1.c
@@ -73,7 +73,7 @@ static struct rc_map_list it913x_v1_map = {
.map = {
.scan = it913x_v1_rc,
.size = ARRAY_SIZE(it913x_v1_rc),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_IT913X_V1,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-it913x-v2.c 
b/drivers/media/rc/keymaps/rc-it913x-v2.c
index 05ab7fa4f90b..be5dfb4fae46 100644
--- a/drivers/media/rc/keymaps/rc-it913x-v2.c
+++ b/drivers/media/rc/keymaps/rc-it913x-v2.c
@@ -72,7 +72,7 @@ static struct rc_map_list it913x_v2_map = {
.map = {
.scan = it913x_v2_rc,
.size = ARRAY_SIZE(it913x_v2_rc),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_IT913X_V2,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-msi-digivox-iii.c 
b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
index 8fec0c1dcb12..d50e741c73b7 100644
--- a/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
+++ b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
@@ -64,7 +64,7 @@ static struct rc_map_list msi_digivox_iii_map = {
.map = {
.scan = msi_digivox_iii,
.size = ARRAY_SIZE(msi_digivox_iii),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_MSI_DIGIVOX_III,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-pixelview-002t.c 
b/drivers/media/rc/keymaps/rc-pixelview-002t.c
index 4ed85f61d0ee..c0550e09f255 100644
--- a/drivers/media/rc/keymaps/rc-pixelview-002t.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-002t.c
@@ -51,7 +51,7 @@ static struct rc_map_list pixelview_map = {
.map = {
.scan = pixelview_002t,
.size = ARRAY_SIZE(pixelview_002t),
-   .rc_proto = RC_PROTO_NEC,
+   .rc_proto = RC_PROTO_NECX,
.name = RC_MAP_PIXELVIEW_002T,
}
 };
diff --git a/drivers/media/rc/keymaps/rc-pixelview-mk12.c 
b/drivers/media/rc/keymaps/rc-pixelview-mk12.c
index 6ded64b732a5..864c8ea5d8e3 100644
--- a/drivers/media/rc

[PATCH v3 5/5] ir-keytable: add tool to aid migration from lircd

2018-07-13 Thread Sean Young
This python script is written to help users translate their lircd.conf
remote definition to ir-keytable toml format. The tool does not cover
every possible lircd.conf, but the majority should work.

./lircd2toml.py PD-202.lircd.conf -o PD-202.toml

Signed-off-by: Sean Young 
---
 contrib/Makefile.am   |   3 +-
 contrib/lircd2toml.py | 527 ++
 2 files changed, 529 insertions(+), 1 deletion(-)
 create mode 100755 contrib/lircd2toml.py

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index d41dc539..db572c54 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -25,4 +25,5 @@ EXTRA_DIST = \
cobalt-ctl \
parsers \
pci_traffic \
-   v4l_rec.pl
+   v4l_rec.pl \
+   lircd2toml.py
diff --git a/contrib/lircd2toml.py b/contrib/lircd2toml.py
new file mode 100755
index ..15cca3dd
--- /dev/null
+++ b/contrib/lircd2toml.py
@@ -0,0 +1,527 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2018 Sean Young 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 2 of the License.
+#
+
+import sys
+import os
+import math
+import argparse
+
+class LircdParser:
+def __init__(self, filename, encoding):
+self.lineno=0
+self.filename=filename
+self.encoding=encoding
+
+def getline(self):
+while True:
+self.lineno += 1
+line = ""
+try:
+line = self.fh.readline();
+except IOError as e:
+self.error("reading file failed: {}".format(e))
+except UnicodeDecodeError as e:
+self.error("decoding file failed: {}".format(e))
+if line == "":
+return None
+line = line.strip()
+if len(line) == 0 or line[0] == '#':
+continue
+return line
+
+def warning(self, msg):
+print("{}:remote {}: warning: {}".format(self.filename, self.lineno, 
msg), file=sys.stderr)
+
+def error(self, msg):
+print("{}:remote {}: error: {}".format(self.filename, self.lineno, 
msg), file=sys.stderr)
+
+def parse(self):
+remotes = []
+try:
+self.fh=open(self.filename, encoding=self.encoding)
+except IOError as e:
+print("{}: error: {}".format(self.filename, e), file=sys.stderr)
+return remotes
+
+while True:
+line = self.getline()
+if line == None:
+break
+a = line.split(maxsplit=2)
+if a[0] != 'begin' or a[1] != 'remote':
+self.error("expected 'begin remote', got '{} {}'".format(a[0], 
a[1]))
+return None
+if len(a) > 2 and a[2][0] != '#':
+self.error("unexpected {}".format(a[2]))
+return None
+
+remote = self.read_remote()
+if remote == None:
+return None
+
+remotes.append(remote)
+
+return remotes
+
+def read_remote(self):
+remote = {}
+while True:
+line = self.getline()
+if line == None:
+self.error("unexpected end of file")
+return None
+
+a = line.split()
+if len(a) < 2:
+self.error("expecting at least two keywords")
+return None
+
+if a[0] in ['name', 'driver', 'serial_mode']:
+remote[a[0]] = line.split(maxsplit=2)[1]
+elif a[0] in ['flags']:
+flags = []
+s=line.split(maxsplit=2)[1]
+for f in s.split(sep='|'):
+flags.append(f.strip().lower())
+remote[ 'flags' ] = flags
+elif a[0] == 'begin':
+if a[1] == 'codes':
+codes = self.read_codes()
+if codes == None:
+return None
+remote['codes'] = codes
+elif a[1] == 'raw_codes':
+codes = self.read_raw_codes()
+if codes == None:
+return None
+remote['raw_codes'] = codes
+else:
+self.error("{} unexpected".format(a[1]))
+elif a[0] == 'end':
+return remote
+else:
+k = a.pop(0)
+vals = []
+for v in a:
+if v[0] == '#':
+break
+vals.append(int(v, 0))
+remote[k] = vals
+
+def read_codes(self):
+codes = {}
+while True:
+line = self.getline()
+if line == None:
+  

[PATCH v3 2/5] keytable: add bpf protocols

2018-07-13 Thread Sean Young
Add a few BPF protocols and infrastructure for building them.

Signed-off-by: Sean Young 
---
 configure.ac  |   4 +
 utils/keytable/Makefile.am|   4 +
 utils/keytable/bpf_protocols/Makefile.am  |  21 ++
 utils/keytable/bpf_protocols/bpf_helpers.h| 315 ++
 utils/keytable/bpf_protocols/grundig.c| 126 +++
 utils/keytable/bpf_protocols/manchester.c | 167 ++
 utils/keytable/bpf_protocols/pulse_distance.c | 156 +
 utils/keytable/bpf_protocols/pulse_length.c   | 152 +
 utils/keytable/bpf_protocols/rc_mm.c  | 139 
 v4l-utils.spec.in |   2 +-
 10 files changed, 1085 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/bpf_protocols/Makefile.am
 create mode 100644 utils/keytable/bpf_protocols/bpf_helpers.h
 create mode 100644 utils/keytable/bpf_protocols/grundig.c
 create mode 100644 utils/keytable/bpf_protocols/manchester.c
 create mode 100644 utils/keytable/bpf_protocols/pulse_distance.c
 create mode 100644 utils/keytable/bpf_protocols/pulse_length.c
 create mode 100644 utils/keytable/bpf_protocols/rc_mm.c

diff --git a/configure.ac b/configure.ac
index 08f5a4c5..10f8628b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_CONFIG_FILES([Makefile
utils/libmedia_dev/Makefile
utils/dvb/Makefile
utils/keytable/Makefile
+   utils/keytable/bpf_protocols/Makefile
utils/ir-ctl/Makefile
utils/cx18-ctl/Makefile
utils/ivtv-ctl/Makefile
@@ -172,11 +173,14 @@ AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
 AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
 if test "x$libelf_pkgconfig" = "xyes"; then
+  AC_CHECK_PROG([CLANG], clang, clang)
   AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
 else
   AC_MSG_WARN(libelf library not available)
 fi
 
+AM_CONDITIONAL([BPF_PROTOCOLS], [test x$CLANG = xclang])
+
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index ad251915..b500e2f2 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -13,6 +13,10 @@ endif
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS) $(LIBELF_LIBS)
 
+if BPF_PROTOCOLS
+SUBDIRS = bpf_protocols
+endif
+
 EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace 
gen_keytables.pl ir-keytable.1 rc_maps.cfg
 
 # custom target
diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
new file mode 100644
index ..5e4b3d67
--- /dev/null
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -0,0 +1,21 @@
+# Get Clang's default includes on this system, as opposed to those seen by
+# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - &1 \
+| sed -n '/<...> search starts here:/,/End of search list./{ s| 
\(/.*\)|-idirafter \1|p }')
+
+%.o: %.c
+   $(CLANG) $(CLANG_SYS_INCLUDES) -I$(top_srcdir)/include -target bpf -O2 
-c $<
+
+PROTOCOLS = grundig.o pulse_distance.o pulse_length.o rc_mm.o manchester.o
+
+all: $(PROTOCOLS)
+
+# custom target
+install-data-local:
+   $(install_sh) -d "$(DESTDIR)$(keytableuserdir)/protocols"
+   $(install_sh) -d "$(DESTDIR)$(keytablesystemdir)/protocols"
+   $(install_sh) $(PROTOCOLS) "$(DESTDIR)$(keytablesystemdir)/protocols"
diff --git a/utils/keytable/bpf_protocols/bpf_helpers.h 
b/utils/keytable/bpf_protocols/bpf_helpers.h
new file mode 100644
index ..8c1b8a23
--- /dev/null
+++ b/utils/keytable/bpf_protocols/bpf_helpers.h
@@ -0,0 +1,315 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __BPF_HELPERS_H
+#define __BPF_HELPERS_H
+
+/* helper macro to place programs, maps, license in
+ * different sections in elf_bpf file. Section names
+ * are interpreted by elf_bpf loader
+ */
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+/* helper functions called from eBPF programs written in C */
+static void *(*bpf_map_lookup_elem)(void *map, void *key) =
+(void *) BPF_FUNC_map_lookup_elem;
+static int (*bpf_map_update_elem)(void *map, void *key, void *value,
+   unsigned long long flags) =
+(void *) BPF_FUNC_map_update_elem;
+static int (*bpf_map_delete_elem)(void *map, void *key) =
+(void *) BPF_FUNC_map_delete_elem;
+static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
+(void *) BPF_FUNC_probe_read;
+static unsigned long long (*bpf_ktime_get_ns)(void) =
+(void *) BPF_FUNC_ktime_get_ns;
+static int (*bpf_trace_pri

[PATCH v3 0/5] Add BPF decoders to ir-keytable

2018-07-13 Thread Sean Young
Once kernel v4.18 is released with IR BPF decoding, this can be merged
to v4l-utils.

The idea is that IR decoders can be written in C, compiled to BPF relocatable
object file. Any global variables can overriden, so we can supports lots
of variants of similiar protocols (just like in the lircd.conf file).

The existing rc_keymap file format can't be used for variables, so I've
converted the format to toml. An alternative would be to use the existing
lircd.conf file format, but it's a very awkward file to parse in C and it
contains many features which are irrelevant to us.

We use libelf to load the bpf relocatable object file.

After loading our example grundig keymap with bpf decoder, the output of
ir-keytable is:

Found /sys/class/rc/rc0/ (/dev/input/event8) with:
Name: Winbond CIR
Driver: winbond-cir, table: rc-rc6-mce
LIRC device: /dev/lirc0
Attached BPF protocols: grundig
Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo 
mce_kbd rc-6 sharp xmp imon
Enabled protocols: lirc
bus: 25, vendor/product: 10ad:00f1, version: 0x0004
Repeat delay = 500 ms, repeat period = 125 ms

Alternatively, you simply specify the path to the object file on the command
line:

$ ir-keytable -e header_pulse=9000,header_space=4500 -p ./pulse_distance.o

Derek, please note that you can now convert the dish lircd.conf to toml
and load the keymap; it should just work. It would be great to have your
feedback, thank you.

Changes since v3:
 - lots of fixes
 - Wrote python script to convert lircd.conf to toml file

Changes since v2:
 - bpf parameters can be specified on the command line
 - bpf decoders can be loaded by path without keymap

Sean Young (5):
  keytable: add support for BPF based protocols
  keytable: add bpf protocols
  keytable: add toml keymap reader
  keytable: convert keymaps to new toml format
  ir-keytable: add tool to aid migration from lircd

 Makefile.am   |4 +-
 configure.ac  |   15 +
 contrib/Makefile.am   |3 +-
 contrib/lircd2toml.py |  527 
 include/linux/bpf.h   | 2669 +
 utils/keytable/Makefile.am|   13 +-
 utils/keytable/bpf.c  |  515 
 utils/keytable/bpf.h  |  110 +
 utils/keytable/bpf_load.c |  472 +++
 utils/keytable/bpf_load.h |   43 +
 utils/keytable/bpf_protocols/Makefile.am  |   21 +
 utils/keytable/bpf_protocols/bpf_helpers.h|  315 ++
 utils/keytable/bpf_protocols/grundig.c|  126 +
 utils/keytable/bpf_protocols/manchester.c |  167 ++
 utils/keytable/bpf_protocols/pulse_distance.c |  156 +
 utils/keytable/bpf_protocols/pulse_length.c   |  152 +
 utils/keytable/bpf_protocols/rc_mm.c  |  139 +
 utils/keytable/gen_keytables.pl   |   33 +-
 utils/keytable/ir-keytable.1.in   |   18 +-
 utils/keytable/keytable.c |  532 +++-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci   |   45 -
 .../rc_keymaps/adstech_dvb_t_pci.toml |   48 +
 utils/keytable/rc_keymaps/af9005  |   37 -
 utils/keytable/rc_keymaps/af9005.toml |   40 +
 utils/keytable/rc_keymaps/alink_dtu_m |   19 -
 utils/keytable/rc_keymaps/alink_dtu_m.toml|   23 +
 .../keytable/rc_keymaps/allwinner_ba10_tv_box |   15 -
 .../rc_keymaps/allwinner_i12_a20_tv_box   |   28 -
 utils/keytable/rc_keymaps/anysee  |   45 -
 utils/keytable/rc_keymaps/anysee.toml |   49 +
 utils/keytable/rc_keymaps/apac_viewcomp   |   32 -
 utils/keytable/rc_keymaps/apac_viewcomp.toml  |   35 +
 utils/keytable/rc_keymaps/astrometa_t2hybrid  |   22 -
 .../rc_keymaps/astrometa_t2hybrid.toml|   26 +
 utils/keytable/rc_keymaps/asus_pc39   |   40 -
 utils/keytable/rc_keymaps/asus_pc39.toml  |   44 +
 utils/keytable/rc_keymaps/asus_ps3_100|   42 -
 utils/keytable/rc_keymaps/asus_ps3_100.toml   |   46 +
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |   25 -
 .../rc_keymaps/ati_tv_wonder_hd_600.toml  |   28 +
 utils/keytable/rc_keymaps/ati_x10 |   49 -
 utils/keytable/rc_keymaps/ati_x10.toml|   52 +
 utils/keytable/rc_keymaps/avermedia   |   37 -
 utils/keytable/rc_keymaps/avermedia.toml  |   40 +
 utils/keytable/rc_keymaps/avermedia_a16d  |   35 -
 utils/keytable/rc_keymaps/avermedia_a16d.toml |   38 +
 utils/keytable/rc_keymaps/avermedia_cardbus   |   55 -
 .../rc_keymaps/avermedia_cardbus.toml |   58 +
 utils/keytable/rc_keymaps/avermedia_dvbt  |   35 -
 utils/keytable/rc_keymaps/avermedia_dvbt.toml |   38 +
 utils/keytable/rc_keymaps/avermedia_m135a |   81 -
 .../keytable/rc_keymaps/avermedia_m135a.toml  |   85 +
 .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |   45 -
 .../rc_keymaps/avermedia_m733a_rm_k6.toml

[PATCH v3 4/5] keytable: convert keymaps to new toml format

2018-07-13 Thread Sean Young
Convert all the existing keymaps to toml, so that only one format is used.

Include the protocol variant as well. This will be useful in the future if
we want to use rc keymaps for transmitting IR.

Signed-off-by: Sean Young 
---
 utils/keytable/gen_keytables.pl   |  33 ++-
 utils/keytable/ir-keytable.1.in   |   4 +-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci   |  45 ---
 .../rc_keymaps/adstech_dvb_t_pci.toml |  48 
 utils/keytable/rc_keymaps/af9005  |  37 ---
 utils/keytable/rc_keymaps/af9005.toml |  40 +++
 utils/keytable/rc_keymaps/alink_dtu_m |  19 --
 utils/keytable/rc_keymaps/alink_dtu_m.toml|  23 ++
 .../keytable/rc_keymaps/allwinner_ba10_tv_box |  15 -
 .../rc_keymaps/allwinner_i12_a20_tv_box   |  28 --
 utils/keytable/rc_keymaps/anysee  |  45 ---
 utils/keytable/rc_keymaps/anysee.toml |  49 
 utils/keytable/rc_keymaps/apac_viewcomp   |  32 ---
 utils/keytable/rc_keymaps/apac_viewcomp.toml  |  35 +++
 utils/keytable/rc_keymaps/astrometa_t2hybrid  |  22 --
 .../rc_keymaps/astrometa_t2hybrid.toml|  26 ++
 utils/keytable/rc_keymaps/asus_pc39   |  40 ---
 utils/keytable/rc_keymaps/asus_pc39.toml  |  44 +++
 utils/keytable/rc_keymaps/asus_ps3_100|  42 ---
 utils/keytable/rc_keymaps/asus_ps3_100.toml   |  46 +++
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |  25 --
 .../rc_keymaps/ati_tv_wonder_hd_600.toml  |  28 ++
 utils/keytable/rc_keymaps/ati_x10 |  49 
 utils/keytable/rc_keymaps/ati_x10.toml|  52 
 utils/keytable/rc_keymaps/avermedia   |  37 ---
 utils/keytable/rc_keymaps/avermedia.toml  |  40 +++
 utils/keytable/rc_keymaps/avermedia_a16d  |  35 ---
 utils/keytable/rc_keymaps/avermedia_a16d.toml |  38 +++
 utils/keytable/rc_keymaps/avermedia_cardbus   |  55 
 .../rc_keymaps/avermedia_cardbus.toml |  58 
 utils/keytable/rc_keymaps/avermedia_dvbt  |  35 ---
 utils/keytable/rc_keymaps/avermedia_dvbt.toml |  38 +++
 utils/keytable/rc_keymaps/avermedia_m135a |  81 --
 .../keytable/rc_keymaps/avermedia_m135a.toml  |  85 ++
 .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |  45 ---
 .../rc_keymaps/avermedia_m733a_rm_k6.toml |  49 
 utils/keytable/rc_keymaps/avermedia_rm_ks |  28 --
 .../keytable/rc_keymaps/avermedia_rm_ks.toml  |  32 +++
 utils/keytable/rc_keymaps/avertv_303  |  37 ---
 utils/keytable/rc_keymaps/avertv_303.toml |  40 +++
 utils/keytable/rc_keymaps/az6027  |   3 -
 utils/keytable/rc_keymaps/az6027.toml |   6 +
 utils/keytable/rc_keymaps/azurewave_ad_tu700  |  54 
 .../rc_keymaps/azurewave_ad_tu700.toml|  58 
 utils/keytable/rc_keymaps/behold  |  35 ---
 utils/keytable/rc_keymaps/behold.toml |  39 +++
 utils/keytable/rc_keymaps/behold_columbus |  29 --
 .../keytable/rc_keymaps/behold_columbus.toml  |  32 +++
 utils/keytable/rc_keymaps/budget_ci_old   |  46 ---
 utils/keytable/rc_keymaps/budget_ci_old.toml  |  49 
 utils/keytable/rc_keymaps/cec |  98 ---
 utils/keytable/rc_keymaps/cec.toml| 101 +++
 utils/keytable/rc_keymaps/cinergy |  37 ---
 utils/keytable/rc_keymaps/cinergy.toml|  40 +++
 utils/keytable/rc_keymaps/cinergy_1400|  38 ---
 utils/keytable/rc_keymaps/cinergy_1400.toml   |  41 +++
 utils/keytable/rc_keymaps/cinergyt2   |  38 ---
 utils/keytable/rc_keymaps/cinergyt2.toml  |  41 +++
 utils/keytable/rc_keymaps/d680_dmb|  36 ---
 utils/keytable/rc_keymaps/d680_dmb.toml   |  39 +++
 utils/keytable/rc_keymaps/delock_61959|  33 ---
 utils/keytable/rc_keymaps/delock_61959.toml   |  37 +++
 utils/keytable/rc_keymaps/dib0700_nec |  71 -
 utils/keytable/rc_keymaps/dib0700_nec.toml|  75 +
 utils/keytable/rc_keymaps/dib0700_rc5 | 181 
 utils/keytable/rc_keymaps/dib0700_rc5.toml| 185 
 utils/keytable/rc_keymaps/dibusb  | 112 
 utils/keytable/rc_keymaps/dibusb.toml | 115 
 utils/keytable/rc_keymaps/digitalnow_tinytwin |  50 
 .../rc_keymaps/digitalnow_tinytwin.toml   |  54 
 utils/keytable/rc_keymaps/digittrade  |  29 --
 utils/keytable/rc_keymaps/digittrade.toml |  33 +++
 utils/keytable/rc_keymaps/digitv  |  56 
 utils/keytable/rc_keymaps/digitv.toml |  59 
 utils/keytable/rc_keymaps/dm1105_nec  |  32 ---
 utils/keytable/rc_keymaps/dm1105_nec.toml |  35 +++
 utils/keytable/rc_keymaps/dntv_live_dvb_t |  33 ---
 .../keytable/rc_keymaps/dntv_live_dvb_t.toml  |  36 +++
 utils/keytable/rc_keymaps/dntv_live_dvbt_pro  |  54 
 .../rc_keymaps/dntv_live_dvbt_pro.toml|  57 
 utils/keytable/rc_keymaps/dtt200u |  19 --
 utils/keytable/rc_keymaps/dtt200u.toml|  23 ++
 utils/keytable/rc_keymaps/dvbsky

[PATCH v3 3/5] keytable: add toml keymap reader

2018-07-13 Thread Sean Young
We would like to define BPF based IR protocols from rc_keymaps. We will
need per-protocol parameters, so we need a more flexible format than
the existing plain-text format.

At some point in the future it would nice to change rc-core keycode
mapping to protocol + 64 bit scancode -> keycode, rather the existing
32 bit scancode -> keycode. In order to make this possible, we want
the scancodes to be specified for their protocol, in case multiple
protocols are selected.

Signed-off-by: Sean Young 
---
 utils/keytable/Makefile.am |2 +-
 utils/keytable/bpf_load.c  |   21 +-
 utils/keytable/bpf_load.h  |2 +-
 utils/keytable/keytable.c  |  222 -
 utils/keytable/toml.c  | 1903 
 utils/keytable/toml.h  |  110 +++
 6 files changed, 2250 insertions(+), 10 deletions(-)
 create mode 100644 utils/keytable/toml.c
 create mode 100644 utils/keytable/toml.h

diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index b500e2f2..90e4c8c8 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -4,7 +4,7 @@ sysconf_DATA = rc_maps.cfg
 keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
 
-ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h
+ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
 
 if HAVE_LIBELF
 ir_keytable_SOURCES += bpf.c bpf_load.c bpf.h bpf_load.h
diff --git a/utils/keytable/bpf_load.c b/utils/keytable/bpf_load.c
index 5e9040a7..6f8a27b0 100644
--- a/utils/keytable/bpf_load.c
+++ b/utils/keytable/bpf_load.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include "toml.h"
 #include "bpf.h"
 #include "bpf_load.h"
 
@@ -43,6 +44,7 @@ struct bpf_file {
Elf_Data *data;
int strtabidx;
Elf_Data *symbols;
+   struct toml_table_t *toml;
 };
 
 static int load_and_attach(int lirc_fd, struct bpf_file *bpf_file, const char 
*name, struct bpf_insn *prog, int size)
@@ -184,6 +186,21 @@ static int parse_relo_and_apply(struct bpf_file *bpf_file, 
GElf_Shdr *shdr,
 
if (!bpf_param(sym_name, )) {
// done
+   } else if (bpf_file->toml &&
+  (raw = toml_raw_in(bpf_file->toml, 
sym_name)) != NULL) {
+   int64_t val64;
+
+   if (toml_rtoi(raw, )) {
+   printf(_("variable %s not a integer: 
%s\n"), sym_name, raw);
+   return 1;
+   }
+
+   if (value < INT_MIN && value > UINT_MAX) {
+   printf(_("variable %s out of range: 
%s\n"), sym_name, raw);
+   return 1;
+   }
+
+   value = val64;
} else if (sym.st_shndx == bpf_file->dataidx) {
int32_t *p = (bpf_file->data->d_buf + 
sym.st_value);
value = *p;
@@ -324,9 +341,9 @@ static int load_elf_maps_section(struct bpf_file *bpf_file)
return nr_maps;
 }
 
-int load_bpf_file(const char *path, int lirc_fd)
+int load_bpf_file(const char *path, int lirc_fd, struct toml_table_t *toml)
 {
-   struct bpf_file bpf_file = {};
+   struct bpf_file bpf_file = { .toml = toml };
int fd, i, ret;
Elf *elf;
GElf_Ehdr ehdr;
diff --git a/utils/keytable/bpf_load.h b/utils/keytable/bpf_load.h
index ec9763e4..2775607f 100644
--- a/utils/keytable/bpf_load.h
+++ b/utils/keytable/bpf_load.h
@@ -36,7 +36,7 @@ struct bpf_map_data {
  *
  * returns zero on success
  */
-int load_bpf_file(const char *path, int lirc_fd);
+int load_bpf_file(const char *path, int lirc_fd, struct toml_table_t *toml);
 
 int bpf_param(const char *name, int *val);
 
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index d058c856..9cec8694 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -33,6 +33,7 @@
 
 #include "ir-encode.h"
 #include "parse.h"
+#include "toml.h"
 #include "bpf.h"
 #include "bpf_load.h"
 
@@ -206,7 +207,7 @@ static void write_sysfs_protocols(enum sysfs_protocols 
protocols, FILE *fp, cons
}
 }
 
-static int parse_code(char *string)
+static int parse_code(const char *string)
 {
struct parse_event *p;
 
@@ -276,6 +277,7 @@ static enum sysfs_protocols ch_proto = 0;
 
 struct bpf_protocol {
struct bpf_protocol *next;
+   struct toml_table_t *toml;
char *name;
 };
 
@@ -315,7 +317,57 @@ struct rc_device {
enum sysfs_protocols supported, current; /* Current and supported IR 
protocols */
 };
 
-static error_t parse_keyfile(char *fname, char **table)
+static bool compare_

Re: [PATCH v2 1/2] media: dt-bindings: bind nokia,n900-ir to generic pwm-ir-tx driver

2018-07-13 Thread Sean Young
On Fri, Jul 13, 2018 at 01:13:20PM +0200, Pavel Machek wrote:
> Hi!
> 
> > Signed-off-by: Sean Young 
> > ---
> >  .../devicetree/bindings/media/nokia,n900-ir   | 20 ---
> >  arch/arm/boot/dts/omap3-n900.dts  |  2 +-
> >  drivers/media/rc/pwm-ir-tx.c  |  1 +
> >  3 files changed, 2 insertions(+), 21 deletions(-)
> >  delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-ir
> > 
> > diff --git a/Documentation/devicetree/bindings/media/nokia,n900-ir 
> > b/Documentation/devicetree/bindings/media/nokia,n900-ir
> > deleted file mode 100644
> > index 13a18ce37dd1..
> > --- a/Documentation/devicetree/bindings/media/nokia,n900-ir
> > +++ /dev/null
> > @@ -1,20 +0,0 @@
> > -Device-Tree bindings for LIRC TX driver for Nokia N900(RX51)
> > -
> > -Required properties:
> > -   - compatible: should be "nokia,n900-ir".
> > -   - pwms: specifies PWM used for IR signal transmission.
> > -
> > -Example node:
> > -
> > -   pwm9: dmtimer-pwm@9 {
> > -   compatible = "ti,omap-dmtimer-pwm";
> > -   ti,timers = <>;
> > -   ti,clock-source = <0x00>; /* timer_sys_ck */
> > -   #pwm-cells = <3>;
> > -   };
> > -
> > -   ir: n900-ir {
> > -   compatible = "nokia,n900-ir";
> > -
> > -   pwms = < 0 26316 0>; /* 38000 Hz */
> > -   };
> 
> Removing documentation is bad idea, I guess. The binding still exists
> and new kernels should still support it.

I've sent out a v3 correcting this.

Thank you for the review!


Sean


[PATCH v3 1/2] media: dt-bindings: bind nokia,n900-ir to generic pwm-ir-tx driver

2018-07-13 Thread Sean Young
The generic pwm-ir-tx driver should work for the Nokia n900.

Compile tested only.

Cc: Rob Herring 
Cc: Ivaylo Dimitrov 
Cc: Pali Rohár 
Cc: Pavel Machek 
Cc: Timo Kokkonen 
Cc: Tony Lindgren 
Signed-off-by: Sean Young 
---
 arch/arm/boot/dts/omap3-n900.dts | 2 +-
 drivers/media/rc/pwm-ir-tx.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
index 182a53991c90..fd12dea15799 100644
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -154,7 +154,7 @@
};
 
ir: n900-ir {
-   compatible = "nokia,n900-ir";
+   compatible = "nokia,n900-ir", "pwm-ir-tx";
pwms = < 0 26316 0>; /* 38000 Hz */
};
 
diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
index 27d0f5837a76..272947b430c8 100644
--- a/drivers/media/rc/pwm-ir-tx.c
+++ b/drivers/media/rc/pwm-ir-tx.c
@@ -30,6 +30,7 @@ struct pwm_ir {
 };
 
 static const struct of_device_id pwm_ir_of_match[] = {
+   { .compatible = "nokia,n900-ir" },
{ .compatible = "pwm-ir-tx", },
{ },
 };
-- 
2.17.1



[PATCH v3 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx

2018-07-13 Thread Sean Young
The ir-rx51 is a pwm-based TX driver specific to the N900. This can be
handled entirely by the generic pwm-ir-tx driver.

Note that the suspend code in the ir-rx51 driver is unnecessary, since
during transmit, the process is not in interruptable sleep. The process
is not put to sleep until the transmit completes.

Compile tested only.

Cc: Ivaylo Dimitrov 
Cc: Pali Rohár 
Cc: Pavel Machek 
Cc: Timo Kokkonen 
Cc: Tony Lindgren 
Signed-off-by: Sean Young 
---
 arch/arm/configs/omap2plus_defconfig |   1 -
 drivers/media/rc/Kconfig |  10 -
 drivers/media/rc/Makefile|   1 -
 drivers/media/rc/ir-rx51.c   | 305 ---
 4 files changed, 317 deletions(-)
 delete mode 100644 drivers/media/rc/ir-rx51.c

diff --git a/arch/arm/configs/omap2plus_defconfig 
b/arch/arm/configs/omap2plus_defconfig
index 6491419b1dad..1ce489a250e0 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -325,7 +325,6 @@ CONFIG_RC_CORE=m
 CONFIG_LIRC=y
 CONFIG_RC_DEVICES=y
 CONFIG_IR_SPI=m
-CONFIG_IR_RX51=m
 CONFIG_IR_GPIO_TX=m
 CONFIG_IR_PWM_TX=m
 CONFIG_MEDIA_SUPPORT=m
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 1021c08a9ba4..3817127bd240 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -377,16 +377,6 @@ config IR_TTUSBIR
   To compile this driver as a module, choose M here: the module will
   be called ttusbir.
 
-config IR_RX51
-   tristate "Nokia N900 IR transmitter diode"
-   depends on (OMAP_DM_TIMER && PWM_OMAP_DMTIMER && ARCH_OMAP2PLUS || 
COMPILE_TEST) && RC_CORE
-   ---help---
-  Say Y or M here if you want to enable support for the IR
-  transmitter diode built in the Nokia N900 (RX51) device.
-
-  The driver uses omap DM timers for generating the carrier
-  wave and pulses.
-
 source "drivers/media/rc/img-ir/Kconfig"
 
 config RC_LOOPBACK
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index e0340d043fe8..124a823555bc 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -29,7 +29,6 @@ obj-$(CONFIG_IR_MESON) += meson-ir.o
 obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
 obj-$(CONFIG_IR_ENE) += ene_ir.o
 obj-$(CONFIG_IR_REDRAT3) += redrat3.o
-obj-$(CONFIG_IR_RX51) += ir-rx51.o
 obj-$(CONFIG_IR_SPI) += ir-spi.o
 obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
 obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o
diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
deleted file mode 100644
index 8a93f7468622..
--- a/drivers/media/rc/ir-rx51.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- *  Copyright (C) 2008 Nokia Corporation
- *
- *  Based on lirc_serial.c
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#define WBUF_LEN 256
-
-struct ir_rx51 {
-   struct rc_dev *rcdev;
-   struct pwm_device *pwm;
-   struct hrtimer timer;
-   struct device*dev;
-   wait_queue_head_t wqueue;
-
-   unsigned intfreq;   /* carrier frequency */
-   unsigned intduty_cycle; /* carrier duty cycle */
-   int wbuf[WBUF_LEN];
-   int wbuf_index;
-   unsigned long   device_is_open;
-};
-
-static inline void ir_rx51_on(struct ir_rx51 *ir_rx51)
-{
-   pwm_enable(ir_rx51->pwm);
-}
-
-static inline void ir_rx51_off(struct ir_rx51 *ir_rx51)
-{
-   pwm_disable(ir_rx51->pwm);
-}
-
-static int init_timing_params(struct ir_rx51 *ir_rx51)
-{
-   struct pwm_device *pwm = ir_rx51->pwm;
-   int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
-
-   duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100);
-
-   pwm_config(pwm, duty, period);
-
-   return 0;
-}
-
-static enum hrtimer_restart ir_rx51_timer_cb(struct hrtimer *timer)
-{
-   struct ir_rx51 *ir_rx51 = container_of(timer, struct ir_rx51, timer);
-   ktime_t now;
-
-   if (ir_rx51->wbuf_index < 0) {
-   dev_err_ratelimited(ir_rx51->dev,
-   "BUG wbuf_index has value of %i\n",
-   ir_rx51->wbuf_index);
-   goto end;
-   }
-
-   /*
-* If we happen to hit an odd latency spike, loop through the
-* pulses until we catch up.
-*/
-   do {
-   u64 ns;
-

[PATCH v2 1/2] media: dt-bindings: bind nokia,n900-ir to generic pwm-ir-tx driver

2018-07-13 Thread Sean Young
The generic pwm-ir-tx driver should work for the Nokia n900.

Compile tested only.

Cc: Rob Herring 
Cc: Ivaylo Dimitrov 
Cc: Pali Rohár 
Cc: Pavel Machek 
Cc: Timo Kokkonen 
Cc: Tony Lindgren 
Signed-off-by: Sean Young 
---
 .../devicetree/bindings/media/nokia,n900-ir   | 20 ---
 arch/arm/boot/dts/omap3-n900.dts  |  2 +-
 drivers/media/rc/pwm-ir-tx.c  |  1 +
 3 files changed, 2 insertions(+), 21 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/media/nokia,n900-ir

diff --git a/Documentation/devicetree/bindings/media/nokia,n900-ir 
b/Documentation/devicetree/bindings/media/nokia,n900-ir
deleted file mode 100644
index 13a18ce37dd1..
--- a/Documentation/devicetree/bindings/media/nokia,n900-ir
+++ /dev/null
@@ -1,20 +0,0 @@
-Device-Tree bindings for LIRC TX driver for Nokia N900(RX51)
-
-Required properties:
-   - compatible: should be "nokia,n900-ir".
-   - pwms: specifies PWM used for IR signal transmission.
-
-Example node:
-
-   pwm9: dmtimer-pwm@9 {
-   compatible = "ti,omap-dmtimer-pwm";
-   ti,timers = <>;
-   ti,clock-source = <0x00>; /* timer_sys_ck */
-   #pwm-cells = <3>;
-   };
-
-   ir: n900-ir {
-   compatible = "nokia,n900-ir";
-
-   pwms = < 0 26316 0>; /* 38000 Hz */
-   };
diff --git a/arch/arm/boot/dts/omap3-n900.dts b/arch/arm/boot/dts/omap3-n900.dts
index 182a53991c90..fd12dea15799 100644
--- a/arch/arm/boot/dts/omap3-n900.dts
+++ b/arch/arm/boot/dts/omap3-n900.dts
@@ -154,7 +154,7 @@
};
 
ir: n900-ir {
-   compatible = "nokia,n900-ir";
+   compatible = "nokia,n900-ir", "pwm-ir-tx";
pwms = < 0 26316 0>; /* 38000 Hz */
};
 
diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
index 27d0f5837a76..272947b430c8 100644
--- a/drivers/media/rc/pwm-ir-tx.c
+++ b/drivers/media/rc/pwm-ir-tx.c
@@ -30,6 +30,7 @@ struct pwm_ir {
 };
 
 static const struct of_device_id pwm_ir_of_match[] = {
+   { .compatible = "nokia,n900-ir" },
{ .compatible = "pwm-ir-tx", },
{ },
 };
-- 
2.17.1



[PATCH v2 2/2] media: rc: remove ir-rx51 in favour of generic pwm-ir-tx

2018-07-13 Thread Sean Young
The ir-rx51 is a pwm-based TX driver specific to the n900. This can be
handled entirely by the generic pwm-ir-tx driver.

Note that the suspend code in the ir-rx51 driver is unnecessary, since
during transmit, the current process is not in interruptable sleep. The
process is not put to sleep until the transmit completes.

Compile tested only.

Cc: Ivaylo Dimitrov 
Cc: Pali Rohár 
Cc: Pavel Machek 
Cc: Timo Kokkonen 
Cc: Tony Lindgren 
Signed-off-by: Sean Young 
---
 arch/arm/configs/omap2plus_defconfig |   1 -
 drivers/media/rc/Kconfig |  10 -
 drivers/media/rc/Makefile|   1 -
 drivers/media/rc/ir-rx51.c   | 305 ---
 4 files changed, 317 deletions(-)
 delete mode 100644 drivers/media/rc/ir-rx51.c

diff --git a/arch/arm/configs/omap2plus_defconfig 
b/arch/arm/configs/omap2plus_defconfig
index 6491419b1dad..1ce489a250e0 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -325,7 +325,6 @@ CONFIG_RC_CORE=m
 CONFIG_LIRC=y
 CONFIG_RC_DEVICES=y
 CONFIG_IR_SPI=m
-CONFIG_IR_RX51=m
 CONFIG_IR_GPIO_TX=m
 CONFIG_IR_PWM_TX=m
 CONFIG_MEDIA_SUPPORT=m
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 1021c08a9ba4..3817127bd240 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -377,16 +377,6 @@ config IR_TTUSBIR
   To compile this driver as a module, choose M here: the module will
   be called ttusbir.
 
-config IR_RX51
-   tristate "Nokia N900 IR transmitter diode"
-   depends on (OMAP_DM_TIMER && PWM_OMAP_DMTIMER && ARCH_OMAP2PLUS || 
COMPILE_TEST) && RC_CORE
-   ---help---
-  Say Y or M here if you want to enable support for the IR
-  transmitter diode built in the Nokia N900 (RX51) device.
-
-  The driver uses omap DM timers for generating the carrier
-  wave and pulses.
-
 source "drivers/media/rc/img-ir/Kconfig"
 
 config RC_LOOPBACK
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index e0340d043fe8..124a823555bc 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -29,7 +29,6 @@ obj-$(CONFIG_IR_MESON) += meson-ir.o
 obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
 obj-$(CONFIG_IR_ENE) += ene_ir.o
 obj-$(CONFIG_IR_REDRAT3) += redrat3.o
-obj-$(CONFIG_IR_RX51) += ir-rx51.o
 obj-$(CONFIG_IR_SPI) += ir-spi.o
 obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
 obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o
diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
deleted file mode 100644
index 8a93f7468622..
--- a/drivers/media/rc/ir-rx51.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- *  Copyright (C) 2008 Nokia Corporation
- *
- *  Based on lirc_serial.c
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- */
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#define WBUF_LEN 256
-
-struct ir_rx51 {
-   struct rc_dev *rcdev;
-   struct pwm_device *pwm;
-   struct hrtimer timer;
-   struct device*dev;
-   wait_queue_head_t wqueue;
-
-   unsigned intfreq;   /* carrier frequency */
-   unsigned intduty_cycle; /* carrier duty cycle */
-   int wbuf[WBUF_LEN];
-   int wbuf_index;
-   unsigned long   device_is_open;
-};
-
-static inline void ir_rx51_on(struct ir_rx51 *ir_rx51)
-{
-   pwm_enable(ir_rx51->pwm);
-}
-
-static inline void ir_rx51_off(struct ir_rx51 *ir_rx51)
-{
-   pwm_disable(ir_rx51->pwm);
-}
-
-static int init_timing_params(struct ir_rx51 *ir_rx51)
-{
-   struct pwm_device *pwm = ir_rx51->pwm;
-   int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
-
-   duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100);
-
-   pwm_config(pwm, duty, period);
-
-   return 0;
-}
-
-static enum hrtimer_restart ir_rx51_timer_cb(struct hrtimer *timer)
-{
-   struct ir_rx51 *ir_rx51 = container_of(timer, struct ir_rx51, timer);
-   ktime_t now;
-
-   if (ir_rx51->wbuf_index < 0) {
-   dev_err_ratelimited(ir_rx51->dev,
-   "BUG wbuf_index has value of %i\n",
-   ir_rx51->wbuf_index);
-   goto end;
-   }
-
-   /*
-* If we happen to hit an odd latency spike, loop through the
-* pulses until we catch up.
-*/
-   d

Re: [PATCH] lirc.4: remove ioctls and feature bits which were never implemented

2018-07-12 Thread Sean Young
On Thu, Jul 12, 2018 at 09:33:32AM -0300, Mauro Carvalho Chehab wrote:
> Hi Michael/Alec,
> 
> Em Fri, 18 May 2018 16:25:29 +0100
> Sean Young  escreveu:
> 
> > On Sun, May 06, 2018 at 12:34:53PM +0200, Michael Kerrisk (man-opages) 
> > wrote:
> > > [CCing original author of this page]
> > > 
> > > 
> > > On 04/23/2018 12:26 PM, Sean Young wrote:  
> > > > The lirc header file included ioctls and feature bits which were never
> > > > implemented by any driver. They were removed in commit:
> > > > 
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d55f09abe24b4dfadab246b6f217da547361cdb6
> > > >   
> > > 
> > > Alec, does this patch look okay to you? 
> 
> Sean is the sub-maintainer responsible for the LIRC code at the
> media subsystem. He knows more about the current implementation
> than anyone else, as he's working hard to improve it, and got
> rid of all legacy LIRC drivers from staging (either fixing them
> or removing the few ones nobody uses anymore).
> 
> As part of his work, some ioctls got removed, in order to make
> the LIRC interface to match the real implementation.
>  
> > Mauro, as Alec is not responding, would you be able to sign this off?
> 
> Most of the patch looks ok on my eyes. I noticed that some flags
> still exists at include/uapi/linux/lirc.h:
> 
>   LIRC_CAN_REC_RAW, LIRC_CAN_REC_PULSE, LIRC_CAN_SET_REC_FILTER
>   and LIRC_CAN_SEND_MODE2
> 
> Maybe instead of just removing, you would need to add some
> explanation about them (or at the patch itself, explaining
> why you're removing the descriptions for them).

Those flags do still exist in the header file, we decided to keep them
so that code does not suddenly fail to build. These flags either never
had implementations or only had out-of-tree implementations. So, I do
not think they belong in the man page.

> > Alternatively, what can be done to progress this?
> > 
> > There is some new functionality in lirc which should be added to this man
> > page too, so I have more to come (when I get round to writing it).
> 
> Yeah, making it reflect upstream sounds the right thing to do.

Absolutely, when kernel v4.18 is released there is more to add.


Sean


[GIT FIXES FOR v4.18] leaking bpf programs after detach

2018-07-04 Thread Sean Young
Hi Mauro,

With the syscall bpf(BPF_PROG_ATTACH), a bpf program can be attached to a
lirc device; that should increase the refcount so that the program is not
freed. However, when we detach the bpf program, we don't decrease the
refcount, so the bpf program will never be freed.

Tested with kasan and ubsan. The list of bpf programs can be using the
bpftool (in the kernel tree), command line "bpftool prog list".

Thanks,

Sean

The following changes since commit 0ca54b29054151b7a52cbb8904732280afe5a302:

  media: rc: be less noisy when driver misbehaves (2018-06-27 10:03:45 -0400)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.18f

for you to fetch changes up to ff003645581b1ee4a0ac80fefdc262a5933b7007:

  media: bpf: ensure bpf program is freed on detach (2018-07-04 20:48:29 +0100)

----
Sean Young (1):
  media: bpf: ensure bpf program is freed on detach

 drivers/media/rc/bpf-lirc.c | 1 +
 1 file changed, 1 insertion(+)


[PATCH] media: bpf: ensure bpf program is freed on detach

2018-07-04 Thread Sean Young
Currently we are leaking bpf programs when they are detached from the
lirc device; the refcount never reaches zero.

Signed-off-by: Sean Young 
---
 drivers/media/rc/bpf-lirc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/rc/bpf-lirc.c b/drivers/media/rc/bpf-lirc.c
index fcfab6635f9c..81b150e5dfdb 100644
--- a/drivers/media/rc/bpf-lirc.c
+++ b/drivers/media/rc/bpf-lirc.c
@@ -174,6 +174,7 @@ static int lirc_bpf_detach(struct rc_dev *rcdev, struct 
bpf_prog *prog)
 
rcu_assign_pointer(raw->progs, new_array);
bpf_prog_array_free(old_array);
+   bpf_prog_put(prog);
 unlock:
mutex_unlock(_raw_handler_lock);
return ret;
-- 
2.17.1



[GIT FIXES FOR v4.18] meson-ir produces too many warnings

2018-06-27 Thread Sean Young
Hi Mauro,

The meson-ir drivers produces a lot of errors since v4.18. Simply make
this dev_warn_once().

Thanks,
Sean

The following changes since commit e88f5e9ebd54bdf75c9833e3d9add7c2c0d39b0b:

  media: uvcvideo: Prevent setting unavailable flags (2018-06-05 08:53:17 -0400)

are available in the Git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.18e

for you to fetch changes up to 97983eed9c07ffd94429527a5e41facde4811fbc:

  media: rc: be less noisy when driver misbehaves (2018-06-27 10:51:42 +0100)


Sean Young (1):
  media: rc: be less noisy when driver misbehaves

 drivers/media/rc/rc-ir-raw.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)


Re: [1/3] media: rc: drivers should produce alternate pulse and space timing events

2018-06-26 Thread Sean Young
On Tue, Jun 26, 2018 at 04:39:51PM +0200, Jerome Brunet wrote:
> On Tue, 2018-06-26 at 15:37 +0100, Sean Young wrote:
> > On Tue, Jun 19, 2018 at 04:09:20PM +0200, Jerome Brunet wrote:
> > > On Tue, 2018-06-19 at 13:57 +0100, Sean Young wrote:
> > > > On Tue, Jun 19, 2018 at 02:08:12PM +0200, Jerome Brunet wrote:
> > > > > On Sat, 2018-05-12 at 11:55 +0100, Sean Young wrote:
> > > > > > Report an error if this is not the case or any problem with the 
> > > > > > generated
> > > > > > raw events.
> > > > > 
> > > > > Hi,
> > > > > 
> > > > > Since the inclusion of this patch, every 3 to 15 seconds, I get the 
> > > > > following
> > > > > message: 
> > > > > 
> > > > >  "rc rc0: two consecutive events of type space"
> > > > > 
> > > > > on the console of amlogic s400 platform 
> > > > > (arch/arm64/boot/dts/amlogic/meson-axg-
> > > > > s400.dts). I don't know much about ir protocol and surely there is 
> > > > > something
> > > > > worth investigating in the related driver, but ...
> > > > > 
> > > > > > 
> > > > > > Signed-off-by: Sean Young 
> > > > > > ---
> > > > > >  drivers/media/rc/rc-ir-raw.c | 19 +++
> > > > > >  1 file changed, 15 insertions(+), 4 deletions(-)
> > > > > > 
> > > > > > diff --git a/drivers/media/rc/rc-ir-raw.c 
> > > > > > b/drivers/media/rc/rc-ir-raw.c
> > > > > > index 2e50104ae138..49c56da9bc67 100644
> > > > > > --- a/drivers/media/rc/rc-ir-raw.c
> > > > > > +++ b/drivers/media/rc/rc-ir-raw.c
> > > > > > @@ -22,16 +22,27 @@ static int ir_raw_event_thread(void *data)
> > > > > >  {
> > > > > > struct ir_raw_event ev;
> > > > > > struct ir_raw_handler *handler;
> > > > > > -   struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl 
> > > > > > *)data;
> > > > > > +   struct ir_raw_event_ctrl *raw = data;
> > > > > > +   struct rc_dev *dev = raw->dev;
> > > > > >  
> > > > > > while (1) {
> > > > > > mutex_lock(_raw_handler_lock);
> > > > > > while (kfifo_out(>kfifo, , 1)) {
> > > > > > +   if (is_timing_event(ev)) {
> > > > > > +   if (ev.duration == 0)
> > > > > > +   dev_err(>dev, "nonsensical 
> > > > > > timing event of duration 0");
> > > > > > +   if (is_timing_event(raw->prev_ev) &&
> > > > > > +   !is_transition(, >prev_ev))
> > > > > > +   dev_err(>dev, "two 
> > > > > > consecutive events of type %s",
> > > > > > +       TO_STR(ev.pulse));
> > > > > > +   if (raw->prev_ev.reset && ev.pulse == 0)
> > > > > > +   dev_err(>dev, "timing 
> > > > > > event after reset should be pulse");
> > > > > > +   }
> > > > > 
> > > > > ... considering that we continue the processing as if nothing 
> > > > > happened, is it
> > > > > really an error ? 
> > > > > 
> > > > > Could we consider something less invasive ? like dev_dbg() or 
> > > > > dev_warn_once() ?
> > > > 
> > > > Maybe it should be dev_warn(). The fact that it is not dev_warn_once() 
> > > > means
> > > > that we now know this occurs regularly.
> > > 
> > > It seems weird to report this over and over again.
> > > 
> > > > 
> > > > Would you mind testing the following patch please?
> > > > 
> > > > Thanks
> > > > 
> > > > Sean
> > > > 
> > > > From 6a44fbe4738d230b9cf378777e7e9a93e5fda726 Mon Sep 17 00:00:00 2001
> > > > From: Sean Young 
> > > > Date: Tue, 19 Jun 2018 13:50:36 +0100
> > > > Subject: [PATCH] media: rc: meson: rc rc0: two consecutive events of

Re: [1/3] media: rc: drivers should produce alternate pulse and space timing events

2018-06-26 Thread Sean Young
On Tue, Jun 19, 2018 at 04:09:20PM +0200, Jerome Brunet wrote:
> On Tue, 2018-06-19 at 13:57 +0100, Sean Young wrote:
> > On Tue, Jun 19, 2018 at 02:08:12PM +0200, Jerome Brunet wrote:
> > > On Sat, 2018-05-12 at 11:55 +0100, Sean Young wrote:
> > > > Report an error if this is not the case or any problem with the 
> > > > generated
> > > > raw events.
> > > 
> > > Hi,
> > > 
> > > Since the inclusion of this patch, every 3 to 15 seconds, I get the 
> > > following
> > > message: 
> > > 
> > >  "rc rc0: two consecutive events of type space"
> > > 
> > > on the console of amlogic s400 platform 
> > > (arch/arm64/boot/dts/amlogic/meson-axg-
> > > s400.dts). I don't know much about ir protocol and surely there is 
> > > something
> > > worth investigating in the related driver, but ...
> > > 
> > > > 
> > > > Signed-off-by: Sean Young 
> > > > ---
> > > >  drivers/media/rc/rc-ir-raw.c | 19 +++
> > > >  1 file changed, 15 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
> > > > index 2e50104ae138..49c56da9bc67 100644
> > > > --- a/drivers/media/rc/rc-ir-raw.c
> > > > +++ b/drivers/media/rc/rc-ir-raw.c
> > > > @@ -22,16 +22,27 @@ static int ir_raw_event_thread(void *data)
> > > >  {
> > > > struct ir_raw_event ev;
> > > > struct ir_raw_handler *handler;
> > > > -   struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl 
> > > > *)data;
> > > > +   struct ir_raw_event_ctrl *raw = data;
> > > > +   struct rc_dev *dev = raw->dev;
> > > >  
> > > > while (1) {
> > > > mutex_lock(_raw_handler_lock);
> > > > while (kfifo_out(>kfifo, , 1)) {
> > > > +   if (is_timing_event(ev)) {
> > > > +   if (ev.duration == 0)
> > > > +   dev_err(>dev, "nonsensical 
> > > > timing event of duration 0");
> > > > +   if (is_timing_event(raw->prev_ev) &&
> > > > +   !is_transition(, >prev_ev))
> > > > +   dev_err(>dev, "two 
> > > > consecutive events of type %s",
> > > > +   TO_STR(ev.pulse));
> > > > +   if (raw->prev_ev.reset && ev.pulse == 0)
> > > > +   dev_err(>dev, "timing 
> > > > event after reset should be pulse");
> > > > +   }
> > > 
> > > ... considering that we continue the processing as if nothing happened, 
> > > is it
> > > really an error ? 
> > > 
> > > Could we consider something less invasive ? like dev_dbg() or 
> > > dev_warn_once() ?
> > 
> > Maybe it should be dev_warn(). The fact that it is not dev_warn_once() means
> > that we now know this occurs regularly.
> 
> It seems weird to report this over and over again.
> 
> > 
> > Would you mind testing the following patch please?
> > 
> > Thanks
> > 
> > Sean
> > 
> > From 6a44fbe4738d230b9cf378777e7e9a93e5fda726 Mon Sep 17 00:00:00 2001
> > From: Sean Young 
> > Date: Tue, 19 Jun 2018 13:50:36 +0100
> > Subject: [PATCH] media: rc: meson: rc rc0: two consecutive events of type
> >  space
> > 
> > The meson generates one edge per interrupt. The duration is encoded in 12
> > bits of 10 microseconds, so it can only encoding a maximum of 40
> > milliseconds. As a result, it can produce multiple space events.
> > 
> > Signed-off-by: Sean Young 
> > ---
> >  drivers/media/rc/meson-ir.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
> > index f449b35d25e7..9747426719b2 100644
> > --- a/drivers/media/rc/meson-ir.c
> > +++ b/drivers/media/rc/meson-ir.c
> > @@ -97,7 +97,8 @@ static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
> > status = readl_relaxed(ir->reg + IR_DEC_STATUS);
> > rawir.pulse = !!(status & STATUS_IR_DEC_IN);
> >  
> > -   ir_raw_event_store_with_timeout(ir->rc, );
> > +   if (ir_raw_event_store_with_filter(ir->rc, ))
> > +   ir_raw_event_handle(ir->rc);
> >  
> > spin_unlock(>lock);
> >  
> 
> Solve the problem on meson. Thx
> Feel free to add this submitting the patch

Actually this patch is broken. ir_raw_event_store_with_timeout() generates
IR timeouts, but ir_raw_event_store_with_filter() does not.

So this will need some rethinking. I think we need a 
ir_raw_event_store_with_timeout_with_filter() but that is getting silly now.

Maybe filter should be a boolean property of an rc device and happen
transparently. I'll write something like that when I get some time.


Sean


[RFC PATCH v2 1/4] keytable: add toml keymap reader

2018-06-24 Thread Sean Young
We would like to add BPF based IR decoding in a later commit. BPF
based IR decoding will have per-protocol parameters, so we need a more
flexible format.

At some point in the future it would nice to change rc-core keycode
mapping to protocol + 64 bit scancode -> keycode, rather the existing
32 bit scancode -> keycode. In order to make this possible, we want
the scancodes to be specified for their protocol, in case multiple
protocols are selected.

Signed-off-by: Sean Young 
---
 utils/keytable/Makefile.am |2 +-
 utils/keytable/keytable.c  |  174 +++-
 utils/keytable/toml.c  | 1903 
 utils/keytable/toml.h  |  110 +++
 4 files changed, 2185 insertions(+), 4 deletions(-)
 create mode 100644 utils/keytable/toml.c
 create mode 100644 utils/keytable/toml.h

diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index 904aa96b..0bd7045f 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -4,7 +4,7 @@ sysconf_DATA = rc_maps.cfg
 keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
 
-ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h
+ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS)
 
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 482fcf86..c6304b04 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -33,6 +33,7 @@
 
 #include "ir-encode.h"
 #include "parse.h"
+#include "toml.h"
 
 #ifdef ENABLE_NLS
 # define _(string) gettext(string)
@@ -200,7 +201,7 @@ static void write_sysfs_protocols(enum sysfs_protocols 
protocols, FILE *fp, cons
}
 }
 
-static int parse_code(char *string)
+static int parse_code(const char *string)
 {
struct parse_event *p;
 
@@ -291,7 +292,7 @@ struct rc_device {
enum sysfs_protocols supported, current; /* Current and supported IR 
protocols */
 };
 
-static error_t parse_keyfile(char *fname, char **table)
+static error_t parse_plain_keyfile(char *fname, char **table)
 {
FILE *fin;
int value, line = 0;
@@ -301,7 +302,7 @@ static error_t parse_keyfile(char *fname, char **table)
*table = NULL;
 
if (debug)
-   fprintf(stderr, _("Parsing %s keycode file\n"), fname);
+   fprintf(stderr, _("Parsing %s keycode file as plain text\n"), 
fname);
 
fin = fopen(fname, "r");
if (!fin) {
@@ -397,7 +398,174 @@ err_einval:
fprintf(stderr, _("Invalid parameter on line %d of %s\n"),
line, fname);
return EINVAL;
+}
+
+static error_t parse_toml_protocol(struct toml_table_t *root, const char *p)
+{
+   struct toml_table_t *proot, *scancodes;
+   enum sysfs_protocols protocol;
+   const char *raw;
+   int i = 0;
+
+   protocol = parse_sysfs_protocol(p, false);
+   if (protocol == SYSFS_INVALID) {
+   fprintf(stderr, _("Protocol `%s' not known\n"), p);
+   return EINVAL;
+   }
+
+   ch_proto |= protocol;
+
+   proot = toml_table_in(root, p);
+   if (!proot) {
+   if (debug)
+   fprintf(stderr, _("No [%s] section"), p);
+   return 0;
+   }
+
+   scancodes = toml_table_in(proot, "scancodes");
+   if (!proot) {
+   if (debug)
+   fprintf(stderr, _("No [%s.scancodes] section"), p);
+   return 0;
+   }
+
+   for (;;) {
+   struct keytable_entry *ke;
+   const char *scancode;
+   char *keycode;
+   int value;
+
+   scancode = toml_key_in(scancodes, i++);
+   if (!scancode)
+   break;
+
+   raw = toml_raw_in(scancodes, scancode);
+   if (!raw) {
+   fprintf(stderr, _("Invalid value `%s'\n"), scancode);
+   return EINVAL;
+   }
+
+   if (toml_rtos(raw, )) {
+   fprintf(stderr, _("Bad value `%s' for keycode\n"),
+   keycode);
+   return EINVAL;
+   }
+
+   if (debug)
+   fprintf(stderr, _("parsing %s=%s:"), scancode, keycode);
+
+   value = parse_code(keycode);
+   if (debug)
+   fprintf(stderr, _("\tvalue=%d\n"), value);
+
+   if (value == -1) {
+   value = strtol(keycode, NULL, 0);
+   if (errno)
+   perror(_("value"));
+   }
+   free(keycode);
+
+   ke = calloc(1, sizeof(*ke));
+   if (!ke) {
+   perror("parse_

[RFC PATCH v2 2/4] keytable: convert keymaps to new toml format

2018-06-24 Thread Sean Young
We will be added new BPF based keymaps which require the toml format.
Convert all the existing keymaps to toml, so that only one format is used.

Include the protocol variant as well. This will be useful in the future if
we want to use rc keymaps for transmitting IR.

Signed-off-by: Sean Young 
---
 utils/keytable/gen_keytables.pl   |  33 ++-
 utils/keytable/ir-keytable.1.in   |   4 +-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci   |  45 ---
 .../rc_keymaps/adstech_dvb_t_pci.toml |  47 +++
 utils/keytable/rc_keymaps/af9005  |  37 ---
 utils/keytable/rc_keymaps/af9005.toml |  39 +++
 utils/keytable/rc_keymaps/alink_dtu_m |  19 --
 utils/keytable/rc_keymaps/alink_dtu_m.toml|  23 ++
 .../keytable/rc_keymaps/allwinner_ba10_tv_box |  15 -
 .../rc_keymaps/allwinner_i12_a20_tv_box   |  28 --
 utils/keytable/rc_keymaps/anysee  |  45 ---
 utils/keytable/rc_keymaps/anysee.toml |  49 
 utils/keytable/rc_keymaps/apac_viewcomp   |  32 ---
 utils/keytable/rc_keymaps/apac_viewcomp.toml  |  34 +++
 utils/keytable/rc_keymaps/astrometa_t2hybrid  |  22 --
 .../rc_keymaps/astrometa_t2hybrid.toml|  26 ++
 utils/keytable/rc_keymaps/asus_pc39   |  40 ---
 utils/keytable/rc_keymaps/asus_pc39.toml  |  44 +++
 utils/keytable/rc_keymaps/asus_ps3_100|  42 ---
 utils/keytable/rc_keymaps/asus_ps3_100.toml   |  46 +++
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |  25 --
 .../rc_keymaps/ati_tv_wonder_hd_600.toml  |  27 ++
 utils/keytable/rc_keymaps/ati_x10 |  49 
 utils/keytable/rc_keymaps/ati_x10.toml|  51 
 utils/keytable/rc_keymaps/avermedia   |  37 ---
 utils/keytable/rc_keymaps/avermedia.toml  |  39 +++
 utils/keytable/rc_keymaps/avermedia_a16d  |  35 ---
 utils/keytable/rc_keymaps/avermedia_a16d.toml |  37 +++
 utils/keytable/rc_keymaps/avermedia_cardbus   |  55 
 .../rc_keymaps/avermedia_cardbus.toml |  57 
 utils/keytable/rc_keymaps/avermedia_dvbt  |  35 ---
 utils/keytable/rc_keymaps/avermedia_dvbt.toml |  37 +++
 utils/keytable/rc_keymaps/avermedia_m135a |  81 --
 .../keytable/rc_keymaps/avermedia_m135a.toml  |  85 ++
 .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |  45 ---
 .../rc_keymaps/avermedia_m733a_rm_k6.toml |  49 
 utils/keytable/rc_keymaps/avermedia_rm_ks |  28 --
 .../keytable/rc_keymaps/avermedia_rm_ks.toml  |  32 +++
 utils/keytable/rc_keymaps/avertv_303  |  37 ---
 utils/keytable/rc_keymaps/avertv_303.toml |  39 +++
 utils/keytable/rc_keymaps/az6027  |   3 -
 utils/keytable/rc_keymaps/az6027.toml |   5 +
 utils/keytable/rc_keymaps/azurewave_ad_tu700  |  54 
 .../rc_keymaps/azurewave_ad_tu700.toml|  58 
 utils/keytable/rc_keymaps/behold  |  35 ---
 utils/keytable/rc_keymaps/behold.toml |  39 +++
 utils/keytable/rc_keymaps/behold_columbus |  29 --
 .../keytable/rc_keymaps/behold_columbus.toml  |  31 ++
 utils/keytable/rc_keymaps/budget_ci_old   |  46 ---
 utils/keytable/rc_keymaps/budget_ci_old.toml  |  48 
 utils/keytable/rc_keymaps/cec |  98 ---
 utils/keytable/rc_keymaps/cec.toml| 100 +++
 utils/keytable/rc_keymaps/cinergy |  37 ---
 utils/keytable/rc_keymaps/cinergy.toml|  39 +++
 utils/keytable/rc_keymaps/cinergy_1400|  38 ---
 utils/keytable/rc_keymaps/cinergy_1400.toml   |  40 +++
 utils/keytable/rc_keymaps/cinergyt2   |  38 ---
 utils/keytable/rc_keymaps/cinergyt2.toml  |  40 +++
 utils/keytable/rc_keymaps/d680_dmb|  36 ---
 utils/keytable/rc_keymaps/d680_dmb.toml   |  38 +++
 utils/keytable/rc_keymaps/delock_61959|  33 ---
 utils/keytable/rc_keymaps/delock_61959.toml   |  37 +++
 utils/keytable/rc_keymaps/dib0700_nec |  71 -
 utils/keytable/rc_keymaps/dib0700_nec.toml|  75 +
 utils/keytable/rc_keymaps/dib0700_rc5 | 181 
 utils/keytable/rc_keymaps/dib0700_rc5.toml| 185 
 utils/keytable/rc_keymaps/dibusb  | 112 
 utils/keytable/rc_keymaps/dibusb.toml | 114 
 utils/keytable/rc_keymaps/digitalnow_tinytwin |  50 
 .../rc_keymaps/digitalnow_tinytwin.toml   |  54 
 utils/keytable/rc_keymaps/digittrade  |  29 --
 utils/keytable/rc_keymaps/digittrade.toml |  33 +++
 utils/keytable/rc_keymaps/digitv  |  56 
 utils/keytable/rc_keymaps/digitv.toml |  58 
 utils/keytable/rc_keymaps/dm1105_nec  |  32 ---
 utils/keytable/rc_keymaps/dm1105_nec.toml |  34 +++
 utils/keytable/rc_keymaps/dntv_live_dvb_t |  33 ---
 .../keytable/rc_keymaps/dntv_live_dvb_t.toml  |  35 +++
 utils/keytable/rc_keymaps/dntv_live_dvbt_pro  |  54 
 .../rc_keymaps/dntv_live_dvbt_pro.toml|  56 
 utils/keytable/rc_keymaps/dtt200u |  19 --
 utils/keytable/rc_keymaps/dtt200u.toml

[RFC PATCH v2 4/4] keytable: add bpf protocols

2018-06-24 Thread Sean Young
Add grundig decoder and infrastructure for build bpf protocols.

Signed-off-by: Sean Young 
---
 configure.ac  |   4 +
 utils/keytable/Makefile.am|   4 +
 utils/keytable/bpf_protocols/Makefile.am  |  21 ++
 utils/keytable/bpf_protocols/bpf_helpers.h| 302 ++
 utils/keytable/bpf_protocols/grundig.c| 130 
 utils/keytable/bpf_protocols/manchester.c | 179 +++
 utils/keytable/bpf_protocols/pulse_distance.c | 133 
 utils/keytable/bpf_protocols/rc_mm.c  | 144 +
 utils/keytable/rc_keymaps_bpf/RP75_LCD.toml   |  45 +++
 v4l-utils.spec.in |   2 +-
 10 files changed, 963 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/bpf_protocols/Makefile.am
 create mode 100644 utils/keytable/bpf_protocols/bpf_helpers.h
 create mode 100644 utils/keytable/bpf_protocols/grundig.c
 create mode 100644 utils/keytable/bpf_protocols/manchester.c
 create mode 100644 utils/keytable/bpf_protocols/pulse_distance.c
 create mode 100644 utils/keytable/bpf_protocols/rc_mm.c
 create mode 100644 utils/keytable/rc_keymaps_bpf/RP75_LCD.toml

diff --git a/configure.ac b/configure.ac
index 1f48913c..58c89e74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_CONFIG_FILES([Makefile
utils/libmedia_dev/Makefile
utils/dvb/Makefile
utils/keytable/Makefile
+   utils/keytable/bpf_protocols/Makefile
utils/ir-ctl/Makefile
utils/cx18-ctl/Makefile
utils/ivtv-ctl/Makefile
@@ -172,11 +173,14 @@ AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
 AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
 if test "x$libelf_pkgconfig" = "xyes"; then
+   AC_CHECK_PROG([CLANG], clang, clang)
AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
 else
AC_MSG_WARN(libelf library not available)
 fi
 
+AM_CONDITIONAL([BPF_PROTOCOLS], [test x$CLANG = xclang])
+
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index df2b2231..90e4c8c8 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -13,6 +13,10 @@ endif
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS) $(LIBELF_LIBS)
 
+if BPF_PROTOCOLS
+SUBDIRS = bpf_protocols
+endif
+
 EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace 
gen_keytables.pl ir-keytable.1 rc_maps.cfg
 
 # custom target
diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
new file mode 100644
index ..6ab2966e
--- /dev/null
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -0,0 +1,21 @@
+# Get Clang's default includes on this system, as opposed to those seen by
+# '-target bpf'. This fixes "missing" files on some architectures/distros,
+# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
+#
+# Use '-idirafter': Don't interfere with include mechanics except where the
+# build would have failed anyways.
+CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - &1 \
+| sed -n '/<...> search starts here:/,/End of search list./{ s| 
\(/.*\)|-idirafter \1|p }')
+
+%.o: %.c
+   $(CLANG) $(CLANG_SYS_INCLUDES) -I$(top_srcdir)/include -target bpf -O2 
-c $<
+
+PROTOCOLS = grundig.o pulse_distance.o rc_mm.o manchester.o
+
+all: $(PROTOCOLS)
+
+# custom target
+install-data-local:
+   $(install_sh) -d "$(DESTDIR)$(keytableuserdir)/protocols"
+   $(install_sh) -d "$(DESTDIR)$(keytablesystemdir)/protocols"
+   $(install_sh) $(PROTOCOLS) "$(DESTDIR)$(keytablesysstemdir)/protocols"
diff --git a/utils/keytable/bpf_protocols/bpf_helpers.h 
b/utils/keytable/bpf_protocols/bpf_helpers.h
new file mode 100644
index ..a6864827
--- /dev/null
+++ b/utils/keytable/bpf_protocols/bpf_helpers.h
@@ -0,0 +1,302 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __BPF_HELPERS_H
+#define __BPF_HELPERS_H
+
+/* helper macro to place programs, maps, license in
+ * different sections in elf_bpf file. Section names
+ * are interpreted by elf_bpf loader
+ */
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+/* helper functions called from eBPF programs written in C */
+static void *(*bpf_map_lookup_elem)(void *map, void *key) =
+   (void *) BPF_FUNC_map_lookup_elem;
+static int (*bpf_map_update_elem)(void *map, void *key, void *value,
+ unsigned long long flags) =
+   (void *) BPF_FUNC_map_update_elem;
+static int (*bpf_map_delete_elem)(void *map, void *key) =
+   (void *) BPF_FUNC_map_delete_elem;
+static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
+   (void *) BPF_FUNC_probe_read;
+static unsigned long long (*bpf_ktime_get_ns)(void) =
+   (void *) B

[RFC PATCH v2 0/4] Add BPF decoders to ir-keytable

2018-06-24 Thread Sean Young
This is not ready for merging yet, however while I finish this work I would
like some feedback and ideas.

The idea is that IR decoders can be written in C, compiled to BPF relocatable
object file. Any global variables can overriden, so we can supports lots
of variants of similiar protocols (just like in the lircd.conf file).

The existing rc_keymap file format can't be used for variables, so I've
converted the format to toml. An alternative would be to use the existing
lircd.conf file format, but it's a very awkward file to parse in C and it
contains many features which are irrelevant to us.

We use libelf to load the bpf relocatable object file.

After loading our example grundig keymap with bpf decoder, the output of
ir-keytable is:

Found /sys/class/rc/rc0/ (/dev/input/event8) with:
Name: Winbond CIR
Driver: winbond-cir, table: rc-rc6-mce
lirc device: /dev/lirc0
Attached bpf protocols: grundig
Supported protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 s
+harp xmp imon
Enabled protocols: lirc
bus: 25, vendor/product: 10ad:00f1, version: 0x0004
Repeat delay = 500 ms, repeat period = 125 ms

Alternatively, you simply specify the path to the object file on the comand
line:

$ ir-keytable -e header_pulse=9000,header_space=4500 -p 
./bpf_decoders/pulse_distance.o


Steps to complete this work:
 - Write more IR decoders
 - More rc_keymaps
 - More testing
 - lircd.conf to toml converter script (python/perl?)

Changes since v2:
 - bpf parameters can be specified on the command line
 - bpf decoders can be loaded by path without keymap
Sean Young (4):
  keytable: add toml keymap reader
  keytable: convert keymaps to new toml format
  keytable: add support for BPF based decoders
  keytable: add bpf protocols

 Makefile.am   |4 +-
 configure.ac  |   15 +
 include/linux/bpf.h   | 2644 +
 utils/keytable/Makefile.am|   13 +-
 utils/keytable/bpf.c  |  515 
 utils/keytable/bpf.h  |  110 +
 utils/keytable/bpf_load.c |  469 +++
 utils/keytable/bpf_load.h |   43 +
 utils/keytable/bpf_protocols/Makefile.am  |   21 +
 utils/keytable/bpf_protocols/bpf_helpers.h|  302 ++
 utils/keytable/bpf_protocols/grundig.c|  130 +
 utils/keytable/bpf_protocols/manchester.c |  179 ++
 utils/keytable/bpf_protocols/pulse_distance.c |  133 +
 utils/keytable/bpf_protocols/rc_mm.c  |  144 +
 utils/keytable/gen_keytables.pl   |   33 +-
 utils/keytable/ir-keytable.1.in   |4 +-
 utils/keytable/keytable.c |  485 ++-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci   |   45 -
 .../rc_keymaps/adstech_dvb_t_pci.toml |   47 +
 utils/keytable/rc_keymaps/af9005  |   37 -
 utils/keytable/rc_keymaps/af9005.toml |   39 +
 utils/keytable/rc_keymaps/alink_dtu_m |   19 -
 utils/keytable/rc_keymaps/alink_dtu_m.toml|   23 +
 .../keytable/rc_keymaps/allwinner_ba10_tv_box |   15 -
 .../rc_keymaps/allwinner_i12_a20_tv_box   |   28 -
 utils/keytable/rc_keymaps/anysee  |   45 -
 utils/keytable/rc_keymaps/anysee.toml |   49 +
 utils/keytable/rc_keymaps/apac_viewcomp   |   32 -
 utils/keytable/rc_keymaps/apac_viewcomp.toml  |   34 +
 utils/keytable/rc_keymaps/astrometa_t2hybrid  |   22 -
 .../rc_keymaps/astrometa_t2hybrid.toml|   26 +
 utils/keytable/rc_keymaps/asus_pc39   |   40 -
 utils/keytable/rc_keymaps/asus_pc39.toml  |   44 +
 utils/keytable/rc_keymaps/asus_ps3_100|   42 -
 utils/keytable/rc_keymaps/asus_ps3_100.toml   |   46 +
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |   25 -
 .../rc_keymaps/ati_tv_wonder_hd_600.toml  |   27 +
 utils/keytable/rc_keymaps/ati_x10 |   49 -
 utils/keytable/rc_keymaps/ati_x10.toml|   51 +
 utils/keytable/rc_keymaps/avermedia   |   37 -
 utils/keytable/rc_keymaps/avermedia.toml  |   39 +
 utils/keytable/rc_keymaps/avermedia_a16d  |   35 -
 utils/keytable/rc_keymaps/avermedia_a16d.toml |   37 +
 utils/keytable/rc_keymaps/avermedia_cardbus   |   55 -
 .../rc_keymaps/avermedia_cardbus.toml |   57 +
 utils/keytable/rc_keymaps/avermedia_dvbt  |   35 -
 utils/keytable/rc_keymaps/avermedia_dvbt.toml |   37 +
 utils/keytable/rc_keymaps/avermedia_m135a |   81 -
 .../keytable/rc_keymaps/avermedia_m135a.toml  |   85 +
 .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |   45 -
 .../rc_keymaps/avermedia_m733a_rm_k6.toml |   49 +
 utils/keytable/rc_keymaps/avermedia_rm_ks |   28 -
 .../keytable/rc_keymaps/avermedia_rm_ks.toml  |   32 +
 utils/keytable/rc_keymaps/avertv_303  |   37 -
 utils/keytable/rc_keymaps/avertv_303.toml |   39 +
 utils/keytable/rc_keymaps/az6027  |3 -
 utils/keytable/rc_keymaps

Re: [1/3] media: rc: drivers should produce alternate pulse and space timing events

2018-06-19 Thread Sean Young
On Tue, Jun 19, 2018 at 02:08:12PM +0200, Jerome Brunet wrote:
> On Sat, 2018-05-12 at 11:55 +0100, Sean Young wrote:
> > Report an error if this is not the case or any problem with the generated
> > raw events.
> 
> Hi,
> 
> Since the inclusion of this patch, every 3 to 15 seconds, I get the following
> message: 
> 
>  "rc rc0: two consecutive events of type space"
> 
> on the console of amlogic s400 platform 
> (arch/arm64/boot/dts/amlogic/meson-axg-
> s400.dts). I don't know much about ir protocol and surely there is something
> worth investigating in the related driver, but ...
> 
> > 
> > Signed-off-by: Sean Young 
> > ---
> >  drivers/media/rc/rc-ir-raw.c | 19 +++
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
> > index 2e50104ae138..49c56da9bc67 100644
> > --- a/drivers/media/rc/rc-ir-raw.c
> > +++ b/drivers/media/rc/rc-ir-raw.c
> > @@ -22,16 +22,27 @@ static int ir_raw_event_thread(void *data)
> >  {
> > struct ir_raw_event ev;
> > struct ir_raw_handler *handler;
> > -   struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
> > +   struct ir_raw_event_ctrl *raw = data;
> > +   struct rc_dev *dev = raw->dev;
> >  
> > while (1) {
> > mutex_lock(_raw_handler_lock);
> > while (kfifo_out(>kfifo, , 1)) {
> > +   if (is_timing_event(ev)) {
> > +   if (ev.duration == 0)
> > +   dev_err(>dev, "nonsensical timing 
> > event of duration 0");
> > +   if (is_timing_event(raw->prev_ev) &&
> > +   !is_transition(, >prev_ev))
> > +   dev_err(>dev, "two consecutive 
> > events of type %s",
> > +   TO_STR(ev.pulse));
> > +   if (raw->prev_ev.reset && ev.pulse == 0)
> > +   dev_err(>dev, "timing event after 
> > reset should be pulse");
> > +   }
> 
> ... considering that we continue the processing as if nothing happened, is it
> really an error ? 
> 
> Could we consider something less invasive ? like dev_dbg() or dev_warn_once() 
> ?

Maybe it should be dev_warn(). The fact that it is not dev_warn_once() means
that we now know this occurs regularly.

Would you mind testing the following patch please?

Thanks

Sean

>From 6a44fbe4738d230b9cf378777e7e9a93e5fda726 Mon Sep 17 00:00:00 2001
From: Sean Young 
Date: Tue, 19 Jun 2018 13:50:36 +0100
Subject: [PATCH] media: rc: meson: rc rc0: two consecutive events of type
 space

The meson generates one edge per interrupt. The duration is encoded in 12
bits of 10 microseconds, so it can only encoding a maximum of 40
milliseconds. As a result, it can produce multiple space events.

Signed-off-by: Sean Young 
---
 drivers/media/rc/meson-ir.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
index f449b35d25e7..9747426719b2 100644
--- a/drivers/media/rc/meson-ir.c
+++ b/drivers/media/rc/meson-ir.c
@@ -97,7 +97,8 @@ static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
status = readl_relaxed(ir->reg + IR_DEC_STATUS);
rawir.pulse = !!(status & STATUS_IR_DEC_IN);
 
-   ir_raw_event_store_with_timeout(ir->rc, );
+   if (ir_raw_event_store_with_filter(ir->rc, ))
+   ir_raw_event_handle(ir->rc);
 
spin_unlock(>lock);
 
-- 
2.17.1



Re: [PATCH] lirc.4: remove ioctls and feature bits which were never implemented

2018-06-06 Thread Sean Young
Hi Alec,

On Sat, May 19, 2018 at 08:38:11AM +0200, Alec Leamas wrote:
> On 18/05/18 17:25, Sean Young wrote:
> > On Sun, May 06, 2018 at 12:34:53PM +0200, Michael Kerrisk (man-opages) 
> > wrote:
> >> [CCing original author of this page]
> >>
> >>
> >> On 04/23/2018 12:26 PM, Sean Young wrote:
> >>> The lirc header file included ioctls and feature bits which were never
> >>> implemented by any driver. They were removed in commit:
> >>>
> >>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d55f09abe24b4dfadab246b6f217da547361cdb6
> >>
> >> Alec, does this patch look okay to you?
> 
> Yes, sorry, must have missed your message. These ioctl are used to
> exist, but are no more and should be removed.

Alec, you didn't reply to the list.

Can this be merged please?

Thanks,

Sean


Re: [RFC PATCH v1 0/4] Add BPF decoders to ir-keytable

2018-06-02 Thread Sean Young
On Sat, Jun 02, 2018 at 01:37:54PM +0100, Sean Young wrote:
> This is not ready for merging yet, however while I finish this work I would
> like some feedback and ideas.
> 
> The idea is that IR decoders can be written in C, compiled to BPF relocatable
> object file. Any global variables can overriden, so we can supports lots
> of variants of similiar protocols (just like in the lircd.conf file).
> 
> The existing rc_keymap file format can't be used for variables, so I've
> converted the format to toml. An alternative would be to use the existing
> lircd.conf file format, but it's a very awkward file to parse in C and it
> contains many features which are irrelevant to us.
> 
> We use libelf to load the bpf relocatable object file.
> 
> After loading our example grundig keymap with bpf decoder, the output of
> ir-keytable is:
> 
> Found /sys/class/rc/rc0/ (/dev/input/event8) with:
>   Name: Winbond CIR
>   Driver: winbond-cir, table: rc-rc6-mce
>   lirc device: /dev/lirc0
>   Attached bpf protocols: grundig
>   Supported protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 
> sharp xmp imon 
>   Enabled protocols: lirc
>   bus: 25, vendor/product: 10ad:00f1, version: 0x0004
>   Repeat delay = 500 ms, repeat period = 125 ms
> 
> 
> Steps to complete this work:
>  - Write more IR decoders
>  - More rc_keymaps
>  - More testing
>  - lircd.conf to toml converter script (python/perl?)
> 
> Sean Young (4):
>   keytable: add toml keymap reader
>   keytable: convert keymaps to new toml format

This commit has not made it to the list yet, I guess because it is so large.

Here it is:

https://git.linuxtv.org/syoung/v4l-utils.git/commit/?id=8e0522c73d832f086958e6cd7774a3e37bbab6bf


>   keytable: add support for BPF based decoders
>   keytable: add bpf protocols
> 
>  Makefile.am   |4 +-
>  configure.ac  |   16 +
>  include/linux/bpf.h   | 2644 +
>  utils/keytable/Makefile.am|   13 +-
>  utils/keytable/bpf.c  |  515 
>  utils/keytable/bpf.h  |  110 +
>  utils/keytable/bpf_load.c |  457 +++
>  utils/keytable/bpf_load.h |   41 +
>  utils/keytable/bpf_protocols/Makefile.am  |   14 +
>  utils/keytable/bpf_protocols/bpf_helpers.h|  302 ++
>  utils/keytable/bpf_protocols/grundig.c|  113 +
>  utils/keytable/gen_keytables.pl   |   33 +-
>  utils/keytable/ir-keytable.1.in   |4 +-
>  utils/keytable/keytable.c |  370 ++-
>  utils/keytable/rc_keymaps/adstech_dvb_t_pci   |   45 -
>  .../rc_keymaps/adstech_dvb_t_pci.toml |   47 +
>  utils/keytable/rc_keymaps/af9005  |   37 -
>  utils/keytable/rc_keymaps/af9005.toml |   39 +
>  utils/keytable/rc_keymaps/alink_dtu_m |   19 -
>  utils/keytable/rc_keymaps/alink_dtu_m.toml|   23 +
>  .../keytable/rc_keymaps/allwinner_ba10_tv_box |   15 -
>  .../rc_keymaps/allwinner_i12_a20_tv_box   |   28 -
>  utils/keytable/rc_keymaps/anysee  |   45 -
>  utils/keytable/rc_keymaps/anysee.toml |   49 +
>  utils/keytable/rc_keymaps/apac_viewcomp   |   32 -
>  utils/keytable/rc_keymaps/apac_viewcomp.toml  |   34 +
>  utils/keytable/rc_keymaps/astrometa_t2hybrid  |   22 -
>  .../rc_keymaps/astrometa_t2hybrid.toml|   26 +
>  utils/keytable/rc_keymaps/asus_pc39   |   40 -
>  utils/keytable/rc_keymaps/asus_pc39.toml  |   44 +
>  utils/keytable/rc_keymaps/asus_ps3_100|   42 -
>  utils/keytable/rc_keymaps/asus_ps3_100.toml   |   46 +
>  .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |   25 -
>  .../rc_keymaps/ati_tv_wonder_hd_600.toml  |   27 +
>  utils/keytable/rc_keymaps/ati_x10 |   49 -
>  utils/keytable/rc_keymaps/ati_x10.toml|   51 +
>  utils/keytable/rc_keymaps/avermedia   |   37 -
>  utils/keytable/rc_keymaps/avermedia.toml  |   39 +
>  utils/keytable/rc_keymaps/avermedia_a16d  |   35 -
>  utils/keytable/rc_keymaps/avermedia_a16d.toml |   37 +
>  utils/keytable/rc_keymaps/avermedia_cardbus   |   55 -
>  .../rc_keymaps/avermedia_cardbus.toml |   57 +
>  utils/keytable/rc_keymaps/avermedia_dvbt  |   35 -
>  utils/keytable/rc_keymaps/avermedia_dvbt.toml |   37 +
>  utils/keytable/rc_keymaps/avermedia_m135a |   81 -
>  .../keytable/rc_keymaps/avermedia_m135a.toml  |   85 +
>  .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |   45 -
>  .../rc_keymaps/avermedia_m733a_rm_k6.toml |   49 +
>  utils/keytable/rc_keymaps/avermedia_rm_ks |   28 -
>  .../keytable/rc_keymap

[RFC PATCH v1 0/4] Add BPF decoders to ir-keytable

2018-06-02 Thread Sean Young
This is not ready for merging yet, however while I finish this work I would
like some feedback and ideas.

The idea is that IR decoders can be written in C, compiled to BPF relocatable
object file. Any global variables can overriden, so we can supports lots
of variants of similiar protocols (just like in the lircd.conf file).

The existing rc_keymap file format can't be used for variables, so I've
converted the format to toml. An alternative would be to use the existing
lircd.conf file format, but it's a very awkward file to parse in C and it
contains many features which are irrelevant to us.

We use libelf to load the bpf relocatable object file.

After loading our example grundig keymap with bpf decoder, the output of
ir-keytable is:

Found /sys/class/rc/rc0/ (/dev/input/event8) with:
Name: Winbond CIR
Driver: winbond-cir, table: rc-rc6-mce
lirc device: /dev/lirc0
Attached bpf protocols: grundig
Supported protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 
sharp xmp imon 
Enabled protocols: lirc
bus: 25, vendor/product: 10ad:00f1, version: 0x0004
Repeat delay = 500 ms, repeat period = 125 ms


Steps to complete this work:
 - Write more IR decoders
 - More rc_keymaps
 - More testing
 - lircd.conf to toml converter script (python/perl?)

Sean Young (4):
  keytable: add toml keymap reader
  keytable: convert keymaps to new toml format
  keytable: add support for BPF based decoders
  keytable: add bpf protocols

 Makefile.am   |4 +-
 configure.ac  |   16 +
 include/linux/bpf.h   | 2644 +
 utils/keytable/Makefile.am|   13 +-
 utils/keytable/bpf.c  |  515 
 utils/keytable/bpf.h  |  110 +
 utils/keytable/bpf_load.c |  457 +++
 utils/keytable/bpf_load.h |   41 +
 utils/keytable/bpf_protocols/Makefile.am  |   14 +
 utils/keytable/bpf_protocols/bpf_helpers.h|  302 ++
 utils/keytable/bpf_protocols/grundig.c|  113 +
 utils/keytable/gen_keytables.pl   |   33 +-
 utils/keytable/ir-keytable.1.in   |4 +-
 utils/keytable/keytable.c |  370 ++-
 utils/keytable/rc_keymaps/adstech_dvb_t_pci   |   45 -
 .../rc_keymaps/adstech_dvb_t_pci.toml |   47 +
 utils/keytable/rc_keymaps/af9005  |   37 -
 utils/keytable/rc_keymaps/af9005.toml |   39 +
 utils/keytable/rc_keymaps/alink_dtu_m |   19 -
 utils/keytable/rc_keymaps/alink_dtu_m.toml|   23 +
 .../keytable/rc_keymaps/allwinner_ba10_tv_box |   15 -
 .../rc_keymaps/allwinner_i12_a20_tv_box   |   28 -
 utils/keytable/rc_keymaps/anysee  |   45 -
 utils/keytable/rc_keymaps/anysee.toml |   49 +
 utils/keytable/rc_keymaps/apac_viewcomp   |   32 -
 utils/keytable/rc_keymaps/apac_viewcomp.toml  |   34 +
 utils/keytable/rc_keymaps/astrometa_t2hybrid  |   22 -
 .../rc_keymaps/astrometa_t2hybrid.toml|   26 +
 utils/keytable/rc_keymaps/asus_pc39   |   40 -
 utils/keytable/rc_keymaps/asus_pc39.toml  |   44 +
 utils/keytable/rc_keymaps/asus_ps3_100|   42 -
 utils/keytable/rc_keymaps/asus_ps3_100.toml   |   46 +
 .../keytable/rc_keymaps/ati_tv_wonder_hd_600  |   25 -
 .../rc_keymaps/ati_tv_wonder_hd_600.toml  |   27 +
 utils/keytable/rc_keymaps/ati_x10 |   49 -
 utils/keytable/rc_keymaps/ati_x10.toml|   51 +
 utils/keytable/rc_keymaps/avermedia   |   37 -
 utils/keytable/rc_keymaps/avermedia.toml  |   39 +
 utils/keytable/rc_keymaps/avermedia_a16d  |   35 -
 utils/keytable/rc_keymaps/avermedia_a16d.toml |   37 +
 utils/keytable/rc_keymaps/avermedia_cardbus   |   55 -
 .../rc_keymaps/avermedia_cardbus.toml |   57 +
 utils/keytable/rc_keymaps/avermedia_dvbt  |   35 -
 utils/keytable/rc_keymaps/avermedia_dvbt.toml |   37 +
 utils/keytable/rc_keymaps/avermedia_m135a |   81 -
 .../keytable/rc_keymaps/avermedia_m135a.toml  |   85 +
 .../keytable/rc_keymaps/avermedia_m733a_rm_k6 |   45 -
 .../rc_keymaps/avermedia_m733a_rm_k6.toml |   49 +
 utils/keytable/rc_keymaps/avermedia_rm_ks |   28 -
 .../keytable/rc_keymaps/avermedia_rm_ks.toml  |   32 +
 utils/keytable/rc_keymaps/avertv_303  |   37 -
 utils/keytable/rc_keymaps/avertv_303.toml |   39 +
 utils/keytable/rc_keymaps/az6027  |3 -
 utils/keytable/rc_keymaps/az6027.toml |5 +
 utils/keytable/rc_keymaps/azurewave_ad_tu700  |   54 -
 .../rc_keymaps/azurewave_ad_tu700.toml|   58 +
 utils/keytable/rc_keymaps/behold  |   35 -
 utils/keytable/rc_keymaps/behold.toml |   39 +
 utils/keytable/rc_keymaps/behold_columbus |   29 -
 .../keytable/rc_keymaps/behold_columbus.toml  |   31 +
 utils/keytable/rc_keymaps/budget_ci_old   |   46 -
 utils/keytable/rc_keymaps/budget_ci_old.toml

[RFC PATCH v1 3/4] keytable: add support for BPF based decoders

2018-06-02 Thread Sean Young
We use a modified version of samples/bpf/bpf_load.c from linux kernel
tree to load elf based BPF decoders, clear them on '-c' and show the
program ids when no commands are given.

Any global int variables can be overrided from toml. They are patched to
be immediate loads.

Signed-off-by: Sean Young 
---
 Makefile.am|4 +-
 configure.ac   |   11 +
 include/linux/bpf.h| 2644 
 utils/keytable/Makefile.am |7 +-
 utils/keytable/bpf.c   |  515 +++
 utils/keytable/bpf.h   |  110 ++
 utils/keytable/bpf_load.c  |  457 +++
 utils/keytable/bpf_load.h  |   41 +
 utils/keytable/keytable.c  |  208 ++-
 v4l-utils.spec.in  |2 +-
 10 files changed, 3989 insertions(+), 10 deletions(-)
 create mode 100644 include/linux/bpf.h
 create mode 100644 utils/keytable/bpf.c
 create mode 100644 utils/keytable/bpf.h
 create mode 100644 utils/keytable/bpf_load.c
 create mode 100644 utils/keytable/bpf_load.h

diff --git a/Makefile.am b/Makefile.am
index fc8f2f34..38e17bab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,7 +25,8 @@ sync-with-kernel:
  ! -f $(KERNEL_DIR)/usr/include/linux/ivtv.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/frontend.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h -o \
- ! -f $(KERNEL_DIR)/usr/include/linux/lirc.h ]; then \
+ ! -f $(KERNEL_DIR)/usr/include/linux/lirc.h -o \
+ ! -f $(KERNEL_DIR)/usr/include/linux/bpf.h ]; then \
  echo "Error you must set KERNEL_DIR to point to an extracted kernel 
source dir"; \
  echo "and run 'make headers_install' in \$$KERNEL_DIR."; \
  exit 1; \
@@ -43,6 +44,7 @@ sync-with-kernel:
cp $(top_srcdir)/include/linux/dvb/frontend.h 
$(top_srcdir)/lib/include/libdvbv5/dvb-frontend.h
cp -a $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h 
$(top_srcdir)/include/linux/dvb
cp -a $(KERNEL_DIR)/usr/include/linux/lirc.h $(top_srcdir)/include/linux
+   cp -a $(KERNEL_DIR)/usr/include/linux/bpf.h $(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c 
$(top_srcdir)/utils/common
cp -a $(KERNEL_DIR)/drivers/media/common/v4l2-tpg/v4l2-tpg-colors.c 
$(top_srcdir)/utils/common
cp -a $(KERNEL_DIR)/include/media/tpg/v4l2-tpg* 
$(top_srcdir)/utils/common
diff --git a/configure.ac b/configure.ac
index dc1e9cbf..1f48913c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -167,6 +167,16 @@ AC_SUBST([X11_CFLAGS])
 AC_SUBST([X11_LIBS])
 AM_CONDITIONAL([HAVE_X11], [test x$x11_pkgconfig = xyes])
 
+PKG_CHECK_MODULES([LIBELF], [libelf], [libelf_pkgconfig=yes], 
[libelf_pkgconfig=no])
+AC_SUBST([LIBELF_CFLAGS])
+AC_SUBST([LIBELF_LIBS])
+AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
+if test "x$libelf_pkgconfig" = "xyes"; then
+   AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
+else
+   AC_MSG_WARN(libelf library not available)
+fi
+
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
@@ -497,6 +507,7 @@ compile time options summary
 X11: $x11_pkgconfig
 GL : $gl_pkgconfig
 glu: $glu_pkgconfig
+libelf: $libelf_pkgconfig
 libjpeg: $have_jpeg
 libudev: $have_libudev
 pthread: $have_pthread
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
new file mode 100644
index ..64ac0f7a
--- /dev/null
+++ b/include/linux/bpf.h
@@ -0,0 +1,2644 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ */
+#ifndef _UAPI__LINUX_BPF_H__
+#define _UAPI__LINUX_BPF_H__
+
+#include 
+#include 
+
+/* Extended instruction set based on top of classic BPF */
+
+/* instruction classes */
+#define BPF_ALU64  0x07/* alu mode in double word width */
+
+/* ld/ldx fields */
+#define BPF_DW 0x18/* double word (64-bit) */
+#define BPF_XADD   0xc0/* exclusive add */
+
+/* alu/jmp fields */
+#define BPF_MOV0xb0/* mov reg to reg */
+#define BPF_ARSH   0xc0/* sign extending arithmetic shift right */
+
+/* change endianness of a register */
+#define BPF_END0xd0/* flags for endianness conversion: */
+#define BPF_TO_LE  0x00/* convert to little-endian */
+#define BPF_TO_BE  0x08/* convert to big-endian */
+#define BPF_FROM_LEBPF_TO_LE
+#define BPF_FROM_BEBPF_TO_BE
+
+/* jmp encodings */
+#define BPF_JNE

[RFC PATCH v1 4/4] keytable: add bpf protocols

2018-06-02 Thread Sean Young
Add grundig decoder and infrastructure for build bpf protocols.

Signed-off-by: Sean Young 
---
 configure.ac|   5 +
 utils/keytable/Makefile.am  |   4 +
 utils/keytable/bpf_protocols/Makefile.am|  14 +
 utils/keytable/bpf_protocols/bpf_helpers.h  | 302 
 utils/keytable/bpf_protocols/grundig.c  | 113 
 utils/keytable/rc_keymaps_bpf/RP75_LCD.toml |  45 +++
 v4l-utils.spec.in   |   2 +-
 7 files changed, 484 insertions(+), 1 deletion(-)
 create mode 100644 utils/keytable/bpf_protocols/Makefile.am
 create mode 100644 utils/keytable/bpf_protocols/bpf_helpers.h
 create mode 100644 utils/keytable/bpf_protocols/grundig.c
 create mode 100644 utils/keytable/rc_keymaps_bpf/RP75_LCD.toml

diff --git a/configure.ac b/configure.ac
index 1f48913c..8872a483 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_CONFIG_FILES([Makefile
utils/libmedia_dev/Makefile
utils/dvb/Makefile
utils/keytable/Makefile
+   utils/keytable/bpf_protocols/Makefile
utils/ir-ctl/Makefile
utils/cx18-ctl/Makefile
utils/ivtv-ctl/Makefile
@@ -172,11 +173,15 @@ AC_SUBST([LIBELF_CFLAGS])
 AC_SUBST([LIBELF_LIBS])
 AM_CONDITIONAL([HAVE_LIBELF], [test x$libelf_pkgconfig = xyes])
 if test "x$libelf_pkgconfig" = "xyes"; then
+   AC_CHECK_PROG([CLANG], clang, clang)
+   AC_CHECK_PROG([LLC], llc, llc)
AC_DEFINE([HAVE_LIBELF], [1], [libelf library is present])
 else
AC_MSG_WARN(libelf library not available)
 fi
 
+AM_CONDITIONAL([BPF_PROTOCOLS], [test x$CLANG = xclang -a x$LLC = xllc])
+
 AS_IF([test "x$x11_pkgconfig" = xyes],
   [PKG_CHECK_MODULES(GL, [gl], [gl_pkgconfig=yes], [gl_pkgconfig=no])], 
[gl_pkgconfig=no])
 AC_SUBST([GL_CFLAGS])
diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index df2b2231..90e4c8c8 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -13,6 +13,10 @@ endif
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS) $(LIBELF_LIBS)
 
+if BPF_PROTOCOLS
+SUBDIRS = bpf_protocols
+endif
+
 EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace 
gen_keytables.pl ir-keytable.1 rc_maps.cfg
 
 # custom target
diff --git a/utils/keytable/bpf_protocols/Makefile.am 
b/utils/keytable/bpf_protocols/Makefile.am
new file mode 100644
index ..aa748900
--- /dev/null
+++ b/utils/keytable/bpf_protocols/Makefile.am
@@ -0,0 +1,14 @@
+
+NOSTDINC=-nostdinc -isystem $(shell $(CLANG) -print-file-name=include)
+
+%.o: %.c
+   $(CLANG) -I../../../include $(NOSTDINC) -I/usr/include -target bpf -O2 
-emit-llvm -c $< -o - | $(LLC) -march=bpf -filetype=obj -o $@
+
+PROTOCOLS = grundig.o
+
+all: $(PROTOCOLS)
+
+# custom target
+install-data-local:
+   $(install_sh) -d "$(DESTDIR)$(keytableuserdir)/protocols"
+   $(install_sh) $(PROTOCOLS) "$(DESTDIR)$(keytableuserdir)/protocols"
diff --git a/utils/keytable/bpf_protocols/bpf_helpers.h 
b/utils/keytable/bpf_protocols/bpf_helpers.h
new file mode 100644
index ..a6864827
--- /dev/null
+++ b/utils/keytable/bpf_protocols/bpf_helpers.h
@@ -0,0 +1,302 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __BPF_HELPERS_H
+#define __BPF_HELPERS_H
+
+/* helper macro to place programs, maps, license in
+ * different sections in elf_bpf file. Section names
+ * are interpreted by elf_bpf loader
+ */
+#define SEC(NAME) __attribute__((section(NAME), used))
+
+/* helper functions called from eBPF programs written in C */
+static void *(*bpf_map_lookup_elem)(void *map, void *key) =
+   (void *) BPF_FUNC_map_lookup_elem;
+static int (*bpf_map_update_elem)(void *map, void *key, void *value,
+ unsigned long long flags) =
+   (void *) BPF_FUNC_map_update_elem;
+static int (*bpf_map_delete_elem)(void *map, void *key) =
+   (void *) BPF_FUNC_map_delete_elem;
+static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) =
+   (void *) BPF_FUNC_probe_read;
+static unsigned long long (*bpf_ktime_get_ns)(void) =
+   (void *) BPF_FUNC_ktime_get_ns;
+static int (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
+   (void *) BPF_FUNC_trace_printk;
+static void (*bpf_tail_call)(void *ctx, void *map, int index) =
+   (void *) BPF_FUNC_tail_call;
+static unsigned long long (*bpf_get_smp_processor_id)(void) =
+   (void *) BPF_FUNC_get_smp_processor_id;
+static unsigned long long (*bpf_get_current_pid_tgid)(void) =
+   (void *) BPF_FUNC_get_current_pid_tgid;
+static unsigned long long (*bpf_get_current_uid_gid)(void) =
+   (void *) BPF_FUNC_get_current_uid_gid;
+static int (*bpf_get_current_comm)(void *buf, int buf_size) =
+   (void *) BPF_FUNC_get_current_comm;
+static unsigned long long (*bpf_perf_event_read)(void *map,
+unsigned long long flags) =
+   (void *) BPF_FUNC_perf_event_read;
+st

[RFC PATCH v1 1/4] keytable: add toml keymap reader

2018-06-02 Thread Sean Young
We would like to add BPF based IR decoding in a later commit. BPF
based IR decoding will have per-protocol parameters, so we need a more
flexible format.

At some point in the future it would nice to change rc-core keycode
mapping to protocol + 64 bit scancode -> keycode, rather the existing
32 bit scancode -> keycode. In order to make this possible, we want
the scancodes to be specified for their protocol, in case multiple
protocols are selected.

Signed-off-by: Sean Young 
---
 utils/keytable/Makefile.am |2 +-
 utils/keytable/keytable.c  |  174 +++-
 utils/keytable/toml.c  | 1903 
 utils/keytable/toml.h  |  110 +++
 4 files changed, 2185 insertions(+), 4 deletions(-)
 create mode 100644 utils/keytable/toml.c
 create mode 100644 utils/keytable/toml.h

diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
index 904aa96b..0bd7045f 100644
--- a/utils/keytable/Makefile.am
+++ b/utils/keytable/Makefile.am
@@ -4,7 +4,7 @@ sysconf_DATA = rc_maps.cfg
 keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
 
-ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h
+ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
 ir_keytable_LDADD = @LIBINTL@
 ir_keytable_LDFLAGS = $(ARGP_LIBS)
 
diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c
index 482fcf86..c6304b04 100644
--- a/utils/keytable/keytable.c
+++ b/utils/keytable/keytable.c
@@ -33,6 +33,7 @@
 
 #include "ir-encode.h"
 #include "parse.h"
+#include "toml.h"
 
 #ifdef ENABLE_NLS
 # define _(string) gettext(string)
@@ -200,7 +201,7 @@ static void write_sysfs_protocols(enum sysfs_protocols 
protocols, FILE *fp, cons
}
 }
 
-static int parse_code(char *string)
+static int parse_code(const char *string)
 {
struct parse_event *p;
 
@@ -291,7 +292,7 @@ struct rc_device {
enum sysfs_protocols supported, current; /* Current and supported IR 
protocols */
 };
 
-static error_t parse_keyfile(char *fname, char **table)
+static error_t parse_plain_keyfile(char *fname, char **table)
 {
FILE *fin;
int value, line = 0;
@@ -301,7 +302,7 @@ static error_t parse_keyfile(char *fname, char **table)
*table = NULL;
 
if (debug)
-   fprintf(stderr, _("Parsing %s keycode file\n"), fname);
+   fprintf(stderr, _("Parsing %s keycode file as plain text\n"), 
fname);
 
fin = fopen(fname, "r");
if (!fin) {
@@ -397,7 +398,174 @@ err_einval:
fprintf(stderr, _("Invalid parameter on line %d of %s\n"),
line, fname);
return EINVAL;
+}
+
+static error_t parse_toml_protocol(struct toml_table_t *root, const char *p)
+{
+   struct toml_table_t *proot, *scancodes;
+   enum sysfs_protocols protocol;
+   const char *raw;
+   int i = 0;
+
+   protocol = parse_sysfs_protocol(p, false);
+   if (protocol == SYSFS_INVALID) {
+   fprintf(stderr, _("Protocol `%s' not known\n"), p);
+   return EINVAL;
+   }
+
+   ch_proto |= protocol;
+
+   proot = toml_table_in(root, p);
+   if (!proot) {
+   if (debug)
+   fprintf(stderr, _("No [%s] section"), p);
+   return 0;
+   }
+
+   scancodes = toml_table_in(proot, "scancodes");
+   if (!proot) {
+   if (debug)
+   fprintf(stderr, _("No [%s.scancodes] section"), p);
+   return 0;
+   }
+
+   for (;;) {
+   struct keytable_entry *ke;
+   const char *scancode;
+   char *keycode;
+   int value;
+
+   scancode = toml_key_in(scancodes, i++);
+   if (!scancode)
+   break;
+
+   raw = toml_raw_in(scancodes, scancode);
+   if (!raw) {
+   fprintf(stderr, _("Invalid value `%s'\n"), scancode);
+   return EINVAL;
+   }
+
+   if (toml_rtos(raw, )) {
+   fprintf(stderr, _("Bad value `%s' for keycode\n"),
+   keycode);
+   return EINVAL;
+   }
+
+   if (debug)
+   fprintf(stderr, _("parsing %s=%s:"), scancode, keycode);
+
+   value = parse_code(keycode);
+   if (debug)
+   fprintf(stderr, _("\tvalue=%d\n"), value);
+
+   if (value == -1) {
+   value = strtol(keycode, NULL, 0);
+   if (errno)
+   perror(_("value"));
+   }
+   free(keycode);
+
+   ke = calloc(1, sizeof(*ke));
+   if (!ke) {
+   perror("parse_

[PATCH v5 1/3] bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not found

2018-05-27 Thread Sean Young
This makes is it possible for bpf prog detach to return -ENOENT.

Acked-by: Yonghong Song <y...@fb.com>
Signed-off-by: Sean Young <s...@mess.org>
---
 kernel/bpf/core.c| 11 +--
 kernel/trace/bpf_trace.c |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index b574dddc05b8..527587de8a67 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1616,6 +1616,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu 
*old_array,
int new_prog_cnt, carry_prog_cnt = 0;
struct bpf_prog **existing_prog;
struct bpf_prog_array *array;
+   bool found_exclude = false;
int new_prog_idx = 0;
 
/* Figure out how many existing progs we need to carry over to
@@ -1624,14 +1625,20 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu 
*old_array,
if (old_array) {
existing_prog = old_array->progs;
for (; *existing_prog; existing_prog++) {
-   if (*existing_prog != exclude_prog &&
-   *existing_prog != _bpf_prog.prog)
+   if (*existing_prog == exclude_prog) {
+   found_exclude = true;
+   continue;
+   }
+   if (*existing_prog != _bpf_prog.prog)
carry_prog_cnt++;
if (*existing_prog == include_prog)
return -EEXIST;
}
}
 
+   if (exclude_prog && !found_exclude)
+   return -ENOENT;
+
/* How many progs (not NULL) will be in the new array? */
new_prog_cnt = carry_prog_cnt;
if (include_prog)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 81fdf2fc94ac..af1486d9a0ed 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1006,6 +1006,8 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
 
old_array = event->tp_event->prog_array;
ret = bpf_prog_array_copy(old_array, event->prog, NULL, _array);
+   if (ret == -ENOENT)
+   goto unlock;
if (ret < 0) {
bpf_prog_array_delete_safe(old_array, event->prog);
} else {
-- 
2.17.0



[PATCH v5 0/3] IR decoding using BPF

2018-05-27 Thread Sean Young
The kernel IR decoders (drivers/media/rc/ir-*-decoder.c) support the most
widely used IR protocols, but there are many protocols which are not
supported[1]. For example, the lirc-remotes[2] repo has over 2700 remotes,
many of which are not supported by rc-core. There is a "long tail" of
unsupported IR protocols, for which lircd is need to decode the IR .

IR encoding is done in such a way that some simple circuit can decode it;
therefore, bpf is ideal.

In order to support all these protocols, here we have bpf based IR decoding.
The idea is that user-space can define a decoder in bpf, attach it to
the rc device through the lirc chardev.

Separate work is underway to extend ir-keytable to have an extensive library
of bpf-based decoders, and a much expanded library of rc keymaps.

Another future application would be to compile IRP[3] to a IR BPF program, and
so support virtually every remote without having to write a decoder for each.
It might also be possible to support non-button devices such as analog
directional pads or air conditioning remote controls and decode the target
temperature in bpf, and pass that to an input device.

Thanks,

Sean Young

[1] http://www.hifi-remote.com/wiki/index.php?title=DecodeIR
[2] https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/
[3] http://www.hifi-remote.com/wiki/index.php?title=IRP_Notation

Changes since v4:
 - Renamed rc_dev_bpf_{attach,detach,query} to lirc_bpf_{attach,detach,query}
 - Fixed error path in lirc_bpf_query
 - Rebased on bpf-next

Changes since v3:
 - Implemented review comments from Quentin Monnet and Y Song (thanks!)
 - More helpful and better formatted bpf helper documentation
 - Changed back to bpf_prog_array rather than open-coded implementation
 - scancodes can be 64 bit
 - bpf gets passed values in microseconds, not nanoseconds.
   microseconds is more than than enough (IR receivers support carriers upto
   70kHz, at which point a single period is already 14 microseconds). Also,
   this makes it much more consistent with lirc mode2.
 - Since it looks much more like lirc mode2, rename the program type to
   BPF_PROG_TYPE_LIRC_MODE2.
 - Rebased on bpf-next

Changes since v2:
 - Fixed locking issues
 - Improved self-test to cover more cases
 - Rebased on bpf-next again

Changes since v1:
 - Code review comments from Y Song <ys114...@gmail.com> and
   Randy Dunlap <rdun...@infradead.org>
 - Re-wrote sample bpf to be selftest
 - Renamed RAWIR_DECODER -> RAWIR_EVENT (Kconfig, context, bpf prog type)
 - Rebase on bpf-next
 - Introduced bpf_rawir_event context structure with simpler access checking


Sean Young (3):
  bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not
found
  media: rc: introduce BPF_PROG_LIRC_MODE2
  bpf: add selftest for lirc_mode2 type program

 drivers/media/rc/Kconfig  |  13 +
 drivers/media/rc/Makefile |   1 +
 drivers/media/rc/bpf-lirc.c   | 313 ++
 drivers/media/rc/lirc_dev.c   |  30 ++
 drivers/media/rc/rc-core-priv.h   |  21 ++
 drivers/media/rc/rc-ir-raw.c  |  12 +-
 include/linux/bpf_lirc.h  |  29 ++
 include/linux/bpf_types.h |   3 +
 include/uapi/linux/bpf.h  |  53 ++-
 kernel/bpf/core.c |  11 +-
 kernel/bpf/syscall.c  |   7 +
 kernel/trace/bpf_trace.c  |   2 +
 tools/bpf/bpftool/prog.c  |   1 +
 tools/include/uapi/linux/bpf.h|  53 ++-
 tools/include/uapi/linux/lirc.h   | 217 
 tools/lib/bpf/libbpf.c|   1 +
 tools/testing/selftests/bpf/.gitignore|   1 +
 tools/testing/selftests/bpf/Makefile  |   7 +-
 tools/testing/selftests/bpf/bpf_helpers.h |   5 +
 .../testing/selftests/bpf/test_lirc_mode2.sh  |  28 ++
 .../selftests/bpf/test_lirc_mode2_kern.c  |  23 ++
 .../selftests/bpf/test_lirc_mode2_user.c  | 149 +
 22 files changed, 971 insertions(+), 9 deletions(-)
 create mode 100644 drivers/media/rc/bpf-lirc.c
 create mode 100644 include/linux/bpf_lirc.h
 create mode 100644 tools/include/uapi/linux/lirc.h
 create mode 100755 tools/testing/selftests/bpf/test_lirc_mode2.sh
 create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_kern.c
 create mode 100644 tools/testing/selftests/bpf/test_lirc_mode2_user.c

-- 
2.17.0



  1   2   3   4   5   6   7   8   9   10   >